Пример #1
0
 /**
  * Create navigation
  * Generate an unordered list of links. Adds "current" CSS class to current item.
  * 
  * @param array $items
  * @param array $settings Options array
  * @return string List HTML
  */
 function create($items = array(), $settings = array(), $toOutput = false)
 {
     $settings = am($this->_defaultOptions, $settings);
     // Begin list
     $ulAttr = '';
     if (!empty($settings['id'])) {
         $ulAttr .= " id=\"{$settings['id']}\"";
     }
     if (!empty($settings['class'])) {
         $ulAttr .= " class=\"{$settings['class']}\"";
     }
     $html = str_replace('%attr%', $ulAttr, $settings['before']);
     // List nodes
     foreach ($items as $name => $url) {
         $isCurrent = false;
         if (is_int($name)) {
             $name = $url;
             $url = '/' . low($url);
             $url = $this->Html->url($url);
         } else {
             if (is_string($url)) {
                 $url = $this->Html->url($url);
                 if ($this->params['action'] === 'index') {
                 }
                 $isCurrent = $this->here === $url;
             } else {
                 if (is_array($url)) {
                     $keys = array('controller', 'action');
                     if (isset($url['controller']) && (!isset($url['action']) || $url['action'] === 'index')) {
                         // We can decide by comparing controllers
                         $isCurrent = $url['controller'] === $this->params['controller'];
                     } else {
                         if (isset($url['controller']) and isset($url['action'])) {
                             $isCurrent = $url['controller'] === $this->params['controller'] && $url['action'] === $this->params['action'];
                         }
                     }
                     // This is basically a hack to get a nice url in form of wf/controller-name/ instead of wf/controller-name/index
                     if (!isset($url['action']) || $url['action'] === 'wf_index') {
                         $url = '/' . Configure::read('Wildflower.prefix') . '/' . str_replace('wild_', '', $url['controller']);
                     }
                     $url = $this->Html->url($url);
                 }
             }
         }
         $liAttr = '';
         $slug = WildflowerAppHelper::slug(low($name));
         $cssClasses = array();
         if (!empty($settings['id'])) {
             $cssClasses[] = "{$settings['id']}-{$slug}";
         } else {
             if (!empty($settings['class'])) {
                 $firstClass = array_shift(explode(' ', $settings['class']));
                 $cssClasses[] = "{$firstClass}-{$slug}";
             }
         }
         $itemTemplate = $settings['itemTemplate'];
         if ($isCurrent) {
             $cssClasses[] = $settings['activeCssClass'];
             $itemTemplate = $settings['activeItemTemplate'];
         }
         $cssClasses = implode(' ', $cssClasses);
         $liAttr = " class=\"{$cssClasses}\"";
         // Translation
         $name = __($name, true);
         $html .= str_replace(array('%attr%', '%url%', '%name%'), array($liAttr, $url, $name), $itemTemplate);
         $html .= "\n";
     }
     $html .= $settings['after'];
     $html .= "\n";
     if ($toOutput) {
         $this->_toOutput .= $toOutput;
         return null;
     }
     return $html;
 }
Пример #2
0
 /**
  * Generate a slug for the given string using specified settings.
  *
  * @param string $string    String.
  * @param array $settings   Settings to use (looks for 'separator' and 'length')
  *
  * @return string   Slug for given string.
  */
 private function _getSlug($string, $settings)
 {
     return WildflowerAppHelper::slug($string, $settings['separator']);
 }