示例#1
0
 /**
  * Parse the segments of a URL.
  *
  * @param   array &$segments The segments of the URL to parse.
  *
  * @return  array  The URL attributes to be used by the application.
  *
  * @since   3.3
  */
 public function parse(&$segments)
 {
     // Get the active menu item.
     $app = JFactory::getApplication();
     $menu = $app->getMenu();
     $item = $menu->getActive();
     if (isset($item->query['controller']) && $item->query['controller'] == 'rest') {
         return array();
     }
     $options = One_Routing::getOptionsForAlias(implode('/', $segments));
     //    echo '<pre>';
     //    print_r($options);
     //    echo '</pre>';
     if ($options !== null) {
         $vars = array();
         $vars['scheme'] = $options['schemeName'];
         $vars['task'] = $options['options']['task'];
         $vars['view'] = $options['options']['view'];
         // check and find the alias or id field
         if ($options['useId'] && null !== $options['aliasField']) {
             $regularAlias = $segments[count($segments) - 1];
             $altAlias = preg_replace('/:/', '-', $regularAlias, 1);
             $schemeQuery = One_Repository::selectQuery($options['schemeName']);
             if ($regularAlias == $altAlias) {
                 $schemeQuery->where($options['aliasField'], 'eq', $regularAlias);
             } else {
                 $queryOr = $schemeQuery->addOr();
                 $queryOr->where($options['aliasField'], 'eq', $regularAlias);
                 $queryOr->where($options['aliasField'], 'eq', $altAlias);
             }
             $results = $schemeQuery->execute();
             if (0 < count($results)) {
                 $idAttr = $schemeQuery->getScheme()->getIdentityAttribute()->getName();
                 $vars['id'] = $results[0]->{$idAttr};
             }
             unset($vars['aliasfield']);
         } else {
             if ($options['useId']) {
                 $vars['id'] = $segments[count($segments) - 1];
             }
         }
         //      echo '<pre>';
         //      print_r($vars);
         //      echo '</pre>';
         return $vars;
     }
     /**
      * Since we have no clear routing, we can only work on the standard interpretation. Only change is that we
      * can use the current menu's scheme if that is a com_one menu item.
      */
     $menu_options = array();
     if (($menu = JSite::getMenu()->getActive()) && $menu->component == 'com_one') {
         $menuscheme = $menu->query['scheme'];
         array_unshift($segments, $menuscheme);
     }
     $vars = array();
     $count = count($segments);
     switch ($count) {
         case 4:
             // format : SCHEME / TASK / VIEW / ID
             $vars['scheme'] = str_replace('-', ':', $segments[$count - 4]);
             $vars['task'] = $segments[$count - 3];
             $vars['view'] = $segments[$count - 2];
             $parts = explode(',', $segments[$count - 1]);
             $vars['id'] = $parts[count($parts) - 1];
             break;
         case 3:
             // format : SCHEME / detail / ID
             // format : SCHEME / list / VIEW
             // format : SCHEME / calendar* / VIEW
             // format : SCHEME / view / VIEW
             $vars['scheme'] = str_replace('-', ':', $segments[$count - 3]);
             $vars['task'] = $segments[$count - 2];
             $parts = explode(',', $segments[$count - 1]);
             if (preg_match('/calendar(Day|Month|Week)?/', $vars['task']) > 0) {
                 $vars['view'] = $segments[$count - 1];
             } else {
                 if (count($parts) > 1) {
                     if ($vars['task'] == 'detail' && preg_match('/^(month|week|day)$/', $params->get('view')) > 0) {
                         $vars['view'] = 'detail';
                     }
                     $parts = explode(',', $segments[$count - 1]);
                     $vars['id'] = $parts[count($parts) - 1];
                 } else {
                     if ($vars['task'] == 'detail') {
                         $vars['view'] = 'detail';
                         $vars['id'] = $parts[count($parts) - 1];
                     } else {
                         if ($vars['task'] == 'edit') {
                             $vars['view'] = $parts[count($parts) - 1];
                             $vars['id'] = 0;
                         } else {
                             $vars['view'] = $segments[$count - 1];
                         }
                     }
                 }
             }
             break;
         case 2:
             $vars['scheme'] = str_replace('-', ':', $segments[$count - 2]);
             $vars['task'] = $segments[$count - 1];
             break;
         case 1:
             $vars['scheme'] = str_replace('-', ':', $segments[$count - 1]);
             $vars['task'] = 'list';
             break;
         default:
     }
     return $vars;
 }
示例#2
0
 public static function fetchAllRoutings()
 {
     if (!self::$_schemesFetched) {
         $schemeNames = One::meta('schemes');
         foreach ($schemeNames as $schemeName) {
             One_Repository::getScheme($schemeName);
         }
         self::$_schemesFetched = true;
     }
 }
示例#3
0
文件: xml.php 项目: pdelbar/onethree
 /**
  * Set routings for the scheme when present
  *
  * @param One_Scheme $scheme
  * @param DOMXPath $xpath
  * @param DOMElement $meta
  */
 protected static function setRoutings(One_Scheme $scheme, DOMXPath $xpath, DOMElement $meta)
 {
     $routings = $xpath->query($meta->getNodePath() . '/routings/routing');
     for ($i = 0; $i < $routings->length; $i++) {
         $routingSpec = $routings->item($i);
         $spec = array();
         for ($j = 0; $j < $routingSpec->attributes->length; $j++) {
             $attr = $routingSpec->attributes->item($j);
             $spec[strtolower($attr->name)] = $attr->value;
         }
         if (isset($spec['alias'])) {
             $alias = $spec['alias'];
             unset($spec['alias']);
             $useId = false;
             if (isset($spec['useid'])) {
                 if (in_array(trim($spec['useid']), array('true', '1', 'yes'))) {
                     $useId = true;
                 }
                 unset($spec['useid']);
             }
             One_Routing::addAlias($scheme, $alias, $spec, $useId);
         }
     }
 }