lostyazilim
tr.link

AltoRouter ve Php Hook sistemiyle çalışırken yapamadığım işlem

2 Mesajlar 622 Okunma
acebozum
tr.link

ismail03 ismail03 WM Aracı Kullanıcı
  • Üyelik 28.11.2013
  • Yaş/Cinsiyet 30 / E
  • Meslek Ameliyathane Hemşiresi
  • Konum Afyon
  • Ad Soyad I** Ç**
  • Mesajlar 2633
  • Beğeniler 344 / 487
  • Ticaret 12, (%100)

class OptionsAltoRouter extends AltoRouter {
public function match($requestUrl = null, $requestMethod = null){
$originalRequestMethod = $requestMethod;
if($requestMethod == 'OPTIONS'){
$requestMethod = $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'];
}
if($match = parent::match($requestUrl, $requestMethod)){
$match['request_method'] = $originalRequestMethod;
}
return $match;
}
}
class AltoRouter {

protected $routes = array();
protected $action='';
protected $namedRoutes = array();
protected $basePath = '';
protected $actionType=array(
'',
'sayfa',
'haber',
'etkinlik',
'404',
'etiket',
'fotogaleri',
'videogaleri',
'galeri',
'video',
'rss',
);
protected $matchTypes = array(
'i' => '[0-9]++',
'a' => '[0-9A-Za-z]++',
'h' => '[0-9A-Fa-f]++',
'*' => '.+?',
'**' => '.++',
'' => '[^/\.]++'
);
function yonlendir($w)
{
$a=((substr($w,-2))=="//" ? substr($w,0,-1):$w);
header("Location:".$a);
}
/**
* Create router in one call from config.
*
* @param array $routes
* @param string $basePath
* @param array $matchTypes
*/
public function __construct( $routes = array(), $basePath = '', $matchTypes = array() ) {
$this->addRoutes($routes);
$this->setBasePath($basePath);
$this->addMatchTypes($matchTypes);
}

/**
* Add multiple routes at once from array in the following format:
*
* $routes = array(
* array($method, $route, $target, $name)
* );
*
* @param array $routes
* @return void
* @author Koen Punt
*/
function addAction(array $action){

$this->actionType=array_unique(array_merge($this->actionType,$action));
}
function getAction(){
$action=(!empty($this->action) ? $this->action:"");
if(in_array($action,$this->actionType)){
return $action;
}
return ;
}
function isAction(){
$action=(!empty($this->action) ? $this->action:"");
if(in_array($action,$this->actionType)){
return true;
}
return false;
}
function multigetAction(array $get,$type){
$action=(!empty($this->action) ? $this->action:"");
$last=null;
if(is_array($get)){
foreach($get as $val){
if(in_array($val,$this->actionType)){
if($val==$action)
$last=$action;
}
}
}
return $last;


}
function method1(){
return $this->action;
}

function setAction($action){
$this->action=$action;
}
function getAllAction(){
return $this->actionType;
}
public function addRoutes($routes){
if(!is_array($routes) && !$routes instanceof Traversable) {
throw new \Exception('Routes should be an array or an instance of Traversable');
}
foreach($routes as $route) {
call_user_func_array(array($this, 'map'), $route);
}
}
/**
* Set the base path.
* Useful if you are running your application from a subdirectory.
*/
public function setBasePath($basePath) {
$this->basePath = $basePath;
}

/**
* Add named match types. It uses array_merge so keys can be overwritten.
*
* @param array $matchTypes The key is the name and the value is the regex.
*/
public function addMatchTypes($matchTypes) {
$this->matchTypes = array_merge($this->matchTypes, $matchTypes);
}

/**
* Map a route to a target
*
* @param string $method One of 4 HTTP Methods, or a pipe-separated list of multiple HTTP Methods (GET|POST|PUT|DELETE)
* @param string $route The route regex, custom regex must start with an @. You can use multiple pre-set regex filters, like [i:id]
* @param mixed $target The target where this route should point to. Can be anything.
* @param string $name Optional name of this route. Supply if you want to reverse route this url in your application.
*/
public function map($method, $route, $target, $name = null,$action=null) {

$this->routes[] = array($method, $route, $target, $name,$action);

if($name) {
if(isset($this->namedRoutes[$name])) {
throw new \Exception("Can not redeclare route '{$name}'");
} else {
$this->namedRoutes[$name] = $route;
}

}

return;
}

/**
* Reversed routing
*
* Generate the URL for a named route. Replace regexes with supplied parameters
*
* @param string $routeName The name of the route.
* @param array @params Associative array of parameters to replace placeholders with.
* @return string The URL of the route with named parameters in place.
*/
public function generate($routeName, array $params = array()) {

// Check if named route exists
if(!isset($this->namedRoutes[$routeName])) {
throw new \Exception("Route '{$routeName}' does not exist.");
}

// Replace named parameters
$route = $this->namedRoutes[$routeName];

// prepend base path to route url again
$url = $this->basePath . $route;

if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {

foreach($matches as $match) {
list($block, $pre, $type, $param, $optional) = $match;

if ($pre) {
$block = substr($block, 1);
}

if(isset($params[$param])) {
$url = str_replace($block, $params[$param], $url);
} elseif ($optional) {
$url = str_replace($pre . $block, '', $url);
}
}


}

return $url;
}


/**
* Match a given Request Url against stored routes
* @param string $requestUrl
* @param string $requestMethod
* @return array|boolean Array with route information on success, false on failure (no match).
*/
public function match($requestUrl = null, $requestMethod = null) {
$params = array();
$match = false;
// set Request Url if it isn't passed as parameter
if($requestUrl === null) {
$requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
}

// strip base path from request url
$requestUrl = substr($requestUrl, strlen($this->basePath));

// Strip query string (?a=b) from Request Url
if (($strpos = strpos($requestUrl, '?')) !== false) {
$requestUrl = substr($requestUrl, 0, $strpos);
}

// set Request Method if it isn't passed as a parameter
if($requestMethod === null) {
$requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
}

// Force request_order to be GP
// http://www.mail-archive.com/internals @lists.php.net/msg33119.html
$_REQUEST = array_merge($_GET, $_POST);

foreach($this->routes as $handler) {
list($method, $_route, $target, $name,$action) = $handler;

$methods = explode('|', $method);
$method_match = false;

// Check if request method matches. If not, abandon early. (CHEAP)
foreach($methods as $method) {
if (strcasecmp($requestMethod, $method) === 0) {
$method_match = true;
break;
}
}

// Method did not match, continue to next route.
if(!$method_match) continue;

// Check for a wildcard (matches all)
if ($_route === '*') {
$match = true;
} elseif (isset($_route[0]) && $_route[0] === '@') {
$match = preg_match('`' . substr($_route, 1) . '`u', $requestUrl, $params);
} else {
$route = null;
$regex = false;
$j = 0;
$n = isset($_route[0]) ? $_route[0] : null;
$i = 0;

// Find the longest non-regex substring and match it against the URI
while (true) {
if (!isset($_route[$i])) {
break;
} elseif (false === $regex) {
$c = $n;
$regex = $c === '[' || $c === '(' || $c === '.';
if (false === $regex && false !== isset($_route[$i+1])) {
$n = $_route[$i + 1];
$regex = $n === '?' || $n === '+' || $n === '*' || $n === '{';
}
if (false === $regex && $c !== '/' && (!isset($requestUrl[$j]) || $c !== $requestUrl[$j])) {
continue 2;
}
$j++;
}
$route .= $_route[$i++];
}

$regex = $this->compileRoute($route);
$match = preg_match($regex, $requestUrl, $params);
}

if(($match == true || $match > 0)) {

if($params) {
foreach($params as $key => $value) {
if(is_numeric($key)) unset($params[$key]);
}
}
$this->action=$action;

return array(
'target' => $target,
'params' => $params,
"action"=>$action,
'name' => $name
);
}
}
return false;
}
/**
* Compile the regex for a given route (EXPENSIVE)
*/
private function compileRoute($route) {
if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {

$matchTypes = $this->matchTypes;
foreach($matches as $match) {
list($block, $pre, $type, $param, $optional) = $match;

if (isset($matchTypes[$type])) {
$type = $matchTypes[$type];
}
if ($pre === '.') {
$pre = '\.';
}

//Older versions of PCRE require the 'P' in (?P)
$pattern = '(?:'
. ($pre !== '' ? $pre : null)
. '('
. ($param !== '' ? "?P<$param>" : null)
. $type
. '))'
. ($optional !== '' ? '?' : null);

$route = str_replace($block, $pattern, $route);
}

}
return "`^$route$`u";
}
}

Altotouter'i bu şekilde güncelledim burada ek bir parametre(action) tanımladım parametre geçerliyse sayfayı yüklesin değilse hata versin bu olayıda yaptım ancak yazdığım sistemde tema yüklenmeden önce yüklenen eklentiler bu action parametresine erişememekte

load.php


include_once("sistem/db.php");
include_once("sistem/dbhelper.php");
include_once("sistem/plugin.php");
include_once("sistem/helper.php");
include_once("sistem/kanca.php");
include_once("sistem/router.php");
global $rota;
$rota=new Altorouter();
global $kanca;
$kanca=new KancaSistemi();
aktifEklentileriYukle();

index.php

include_once("load.php");
$rota->map('GET', '/', function(){
include_once("site/ana.site.php");
exit();
},'ana.site');
$rota->map('GET', '/haber-[*:haber]', function($haber){
global $rota;
temaYukle("haber.site.php");
exit();
},'haber.site',"haber");
$rota->map("GET","/sayfa-[*:page]", function($page){
global $rota;
include_once("site/sayfa.site.php");
exit();
},'page.site','sayfa');
$rota->map("GET","/galeriler", function(){
global $rota;
include_once("site/galeri.site.php");
exit();
},'galeriler.site','fotogaleri');

mantıken doğru ama ben action parametresini tema dosyası yüklendikten sonra alıp işleyebilmem lazım(İzin yönetimi eklentisi için veya başlığı sayfaya göre düzenleyebilme durumu örnek olabilir)
Sorunu anlayan ve çözüm önerisi verebilecek olan var mı?
yada yazdığım içeriği ingilizce halini (İngilizce biliyorum ancak tam ifade edemiyebilirim) hazırlamamda yardımcı olabilecek var mı?
 

 

elektronikssl
webimgo

ismail03 ismail03 WM Aracı Kullanıcı
  • Üyelik 28.11.2013
  • Yaş/Cinsiyet 30 / E
  • Meslek Ameliyathane Hemşiresi
  • Konum Afyon
  • Ad Soyad I** Ç**
  • Mesajlar 2633
  • Beğeniler 344 / 487
  • Ticaret 12, (%100)
Sorunu çözdüm. :)
 

 

Site Ayarları
  • Tema Seçeneği
  • Site Sesleri
  • Bildirimler
  • Özel Mesaj Al