Exemplo n.º 1
0
 /**
  * Assemble system URL 
  * Examples:
  * <?php
  * $router->assemble('/'); // index page URL e.g. / or /site_folder/
  * $router->assemble('news/view/item?id=1'); // depends on current news config, possible return value is /news/1
  * $router->assemble('*', 'id=1'); // use current request info - /module/controller/action?id=1
  * $router->assemble('* /* /newaction'); // (NO EMPTY SPACES) change only current action - /module/controller/newaction
  * $newsItem = array('news_id' => 1, 'news_sef' => 'My Title', ...); // as retrieved from DB
  * $router->assemble('news/view/item', $newsItem); // All unused key=>values will be removed and NOT appended as GET vars
  * 
  * @param string $route
  * @param array $params
  * @param array $options {@see eRouter::$_defaultAssembleOptions}
  */
 public function assemble($route, $params = array(), $options = array())
 {
     // TODO - url options
     $request = eFront::instance()->getRequest();
     if (is_string($options)) {
         parse_str($options, $options);
     }
     $options = array_merge($this->_defaultAssembleOptions, $options);
     $base = ($options['full'] ? SITEURLBASE : '') . $request->getBasePath();
     $anc = '';
     if (is_string($params)) {
         parse_str($params, $params);
     }
     if (isset($params['#'])) {
         $anc = '#' . $params['#'];
         usnet($params['#']);
     }
     // Config independent - Deny parameter keys, useful for directly denying sensitive data e.g. password db fields
     if (isset($options['deny'])) {
         $list = array_map('trim', explode(',', $options['deny']));
         foreach ($list as $value) {
             unset($params[$value]);
         }
         unset($list);
     }
     // Config independent - allow parameter keys, useful to directly allow data (and not to rely on config allowVars) e.g. when retrieved from db
     if (isset($options['allow'])) {
         $list = array_map('trim', explode(',', $options['allow']));
         $_params = $params;
         $params = array();
         foreach ($list as $value) {
             if (isset($_params[$value])) {
                 $params[$value] = $_params[$value];
             }
         }
         unset($list, $_params);
     }
     # Optional convenient masks for creating system URL's
     if ($route === '/' || empty($route)) {
         if ($params) {
             $params = $this->createPathInfo($params, $options);
             return $base . '?' . $params;
         }
         return $base;
     } elseif (strpos($route, '?') !== false) {
         $tmp = explode('?', $route, 2);
         $route = $tmp[0];
         parse_str($tmp[1], $params);
         unset($tmp);
     }
     if ($route === '*') {
         $route = $route = explode('/', $request->getRoute());
     } elseif (strpos($route, '*') !== false) {
         $route = explode('/', $route, 3);
         if ($route[0] === '*') {
             $route[0] = $request->getModule();
         }
         if (isset($route[1]) && $route[1] === '*') {
             $route[1] = $request->getController();
         }
     } else {
         $route = explode('/', $route, 3);
     }
     // we don't know anything about this route, just build it blind
     if (!$this->isModule($route[0])) {
         if ($params) {
             $params = $this->createPathInfo($params, $options);
             return $base . implode('/', $route) . '?' . $params;
         }
         return $base . implode('/', $route);
     }
     # fill in index when needed - XXX not needed, may be removed soon
     switch (count($route)) {
         case 1:
             $route[1] = 'index';
             $route[2] = 'index';
             break;
         case 2:
             $route[2] = 'index';
             break;
     }
     # aliases
     $module = $route[0];
     $config = $this->getConfig($module);
     $alias = $this->hasAlias($module, vartrue($options['lan'], null)) ? $this->getAliasFromModule($module, vartrue($options['lan'], null)) : $module;
     $route[0] = $alias;
     if ($options['encode']) {
         $alias = rawurlencode($alias);
     }
     $format = isset($config['format']) && $config['format'] ? $config['format'] : self::FORMAT_GET;
     $urlSuffix = '';
     // Fix base url for legacy links
     if (vartrue($config['noSingleEntry'])) {
         $base = $options['full'] ? SITEURL : e_HTTP;
     } elseif (self::FORMAT_GET !== $config['format']) {
         $urlSuffix = $this->urlSuffix;
         if (isset($config['urlSuffix'])) {
             $urlSuffix = $config['urlSuffix'];
         }
     }
     // Create by config callback
     if (vartrue($config['selfCreate'])) {
         $tmp = $this->configCallback($module, 'create', array(array($route[1], $route[2]), $params, $options), $config['location']);
         if (empty($tmp)) {
             return '#not-found';
         }
         if (is_array($tmp)) {
             $route = $tmp[0];
             $params = $tmp[1];
             if ($options['encode']) {
                 $route = array_map('rawurlencode', $route);
             }
             $route = implode('/', $route);
             if (!$route) {
                 $urlSuffix = '';
                 if (!$this->isMainModule($module)) {
                     $route = $alias;
                 }
             } elseif (!$this->isMainModule($module)) {
                 $route = $alias . '/' . $route;
             }
         } else {
             // relative url returned
             return $base . $tmp . $anc;
         }
         unset($tmp);
         if ($format === self::FORMAT_GET) {
             $params[$this->routeVar] = $route;
             $route = '';
         }
         if ($params) {
             $params = $this->createPathInfo($params, $options);
             return $base . $route . $urlSuffix . '?' . $params . $anc;
         }
         return $base . $route . $urlSuffix . $anc;
     }
     // System URL create routine
     $rules = $this->getRules($module);
     if ($format !== self::FORMAT_GET && !empty($rules)) {
         foreach ($rules as $k => $rule) {
             if (($url = $rule->createUrl($this, array($route[1], $route[2]), $params, $options)) !== false) {
                 return $base . rtrim(($this->isMainModule($module) ? '' : $alias . '/') . $url, '/') . $anc;
             }
         }
     }
     // default - module/controller/action
     if ($this->isMainModule($module)) {
         unset($route[0]);
     }
     if ($route[2] == 'index') {
         unset($route[2]);
         if ($route[1] == 'index') {
             unset($route[1]);
         }
     }
     # Modify params if required
     if ($params) {
         if (varset($config['mapVars'])) {
             foreach ($config['mapVars'] as $srcKey => $dstKey) {
                 if (isset($params[$srcKey])) {
                     $params[$dstKey] = $params[$srcKey];
                     unset($params[$srcKey]);
                 }
             }
         }
         // false means - no vars are allowed, nothing to preserve here
         if (varset($config['allowVars']) === false) {
             $params = array();
         } elseif (empty($config['allowVars']) && !empty($config['mapVars'])) {
             $params = array_unique(array_values($config['mapVars']));
         }
         // disallow everything but valid URL parameters
         if (!empty($config['allowVars'])) {
             $copy = $params;
             $params = array();
             foreach ($config['allowVars'] as $key) {
                 if (isset($copy[$key])) {
                     $params[$key] = $copy[$key];
                 }
             }
             unset($copy);
         }
         if ($format === self::FORMAT_GET) {
             $urlSuffix = '';
             $copy = $params;
             $params = array();
             $params[$this->routeVar] = implode('/', $route);
             foreach ($copy as $key => $value) {
                 $params[$key] = $value;
             }
             unset($copy);
             $route = array();
         }
         $params = $this->createPathInfo($params, $options);
         $route = implode('/', $route);
         if (!$route || $route == $alias) {
             $urlSuffix = '';
         }
         return $base . $route . $urlSuffix . '?' . $params . $anc;
     }
     $route = implode('/', $route);
     if (!$route || $route == $alias) {
         $urlSuffix = '';
     }
     return $format === self::FORMAT_GET ? $base . '?' . $this->routeVar . '=' . $route . $anc : $base . $route . $urlSuffix . $anc;
 }
Exemplo n.º 2
0
 public function remove()
 {
     $this->cur->previous->next = $this->cur->next;
     $this->cur->next->previous = $this->cur->previous;
     usnet($this->cur);
     $this->cur = $this->next();
 }
 function unset_coverpage()
 {
     usnet($this->coverpage);
     $this->coverpage['status'] = false;
 }