Exemple #1
0
 function check_parent_another($menu)
 {
     global $page;
     $title = common::Parents($page->gp_index, $menu);
     if (array_key_exists(0, $title)) {
         return $title[0];
     } else {
         return false;
     }
 }
Exemple #2
0
 function IsProtected($index)
 {
     global $gp_menu;
     if (isset($this->config['pages'][$index])) {
         $this->is_protected = true;
         return 1;
     }
     $parents = common::Parents($index, $gp_menu);
     foreach ($parents as $parent_index) {
         if (isset($this->config['pages'][$parent_index])) {
             $this->is_protected = true;
             $this->parent_protected = true;
             return 2;
         }
     }
     return false;
 }
Exemple #3
0
 /**
  * Traverse the main menu upwards looking for a configuration setting for $var
  * Start at the title represented by $checkId
  * Set $value to the configuration setting if a parent page has the configuration setting
  *
  * @return bool
  */
 static function ParentConfig($checkId, $var, &$value)
 {
     global $gp_titles, $gp_menu;
     $parents = common::Parents($checkId, $gp_menu);
     foreach ($parents as $parent_index) {
         if (!empty($gp_titles[$parent_index][$var])) {
             $value = $gp_titles[$parent_index][$var];
             return true;
         }
     }
     return false;
 }
Exemple #4
0
 /**
  * Output a navigation menu
  * @static
  */
 static function OutputMenu($menu, $start_level, $source_menu = false)
 {
     global $page, $gp_menu, $gp_titles, $GP_MENU_LINKS, $GP_MENU_CLASS, $GP_MENU_CLASSES;
     //source menu
     if ($source_menu === false) {
         $source_menu =& $gp_menu;
     }
     self::PrepMenuOutput();
     $clean_attributes = array('attr' => '', 'class' => array(), 'id' => '');
     $clean_attributes_a = array('href' => '', 'attr' => '', 'value' => '', 'title' => '', 'class' => array());
     // opening ul
     $attributes_ul = $clean_attributes;
     $attributes_ul['class']['menu_top'] = $GP_MENU_CLASSES['menu_top'];
     if (self::$edit_area_id) {
         $attributes_ul['id'] = self::$edit_area_id;
         $attributes_ul['class']['editable_area'] = 'editable_area';
     }
     if (!count($menu)) {
         //$attributes_ul['class']['empty_menu'] = 'empty_menu';
         //self::FormatMenuElement('div',$attributes_ul).'</div>'; //an empty <ul> is not valid xhtml
         return;
     }
     $prev_level = $start_level;
     $page_title_full = common::GetUrl($page->title);
     $open = false;
     $li_count = array();
     //get parent page
     $parent_page = false;
     $parents = common::Parents($page->gp_index, $source_menu);
     if (count($parents)) {
         $parent_page = $parents[0];
     }
     //output
     self::FormatMenuElement('ul', $attributes_ul);
     $menu = array_keys($menu);
     foreach ($menu as $menu_index => $menu_key) {
         $menu_info = $source_menu[$menu_key];
         $this_level = $menu_info['level'];
         //the next entry
         $next_info = false;
         $next_index = $menu_index + 1;
         if (array_key_exists($next_index, $menu)) {
             $next_index = $menu[$next_index];
             $next_info = $source_menu[$next_index];
         }
         $attributes_a = $clean_attributes_a;
         $attributes_li = $attributes_ul = $clean_attributes;
         //ordered or "indexed" classes
         if ($page->menu_css_ordered) {
             for ($i = $prev_level; $i > $this_level; $i--) {
                 unset($li_count[$i]);
             }
             if (!isset($li_count[$this_level])) {
                 $li_count[$this_level] = 0;
             } else {
                 $li_count[$this_level]++;
             }
             if (!empty($GP_MENU_CLASSES['li_'])) {
                 $attributes_li['class']['li_'] = $GP_MENU_CLASSES['li_'] . $li_count[$this_level];
             }
         }
         if ($page->menu_css_indexed && !empty($GP_MENU_CLASSES['li_title_'])) {
             $attributes_li['class']['li_title_'] = $GP_MENU_CLASSES['li_title_'] . $menu_key;
         }
         //selected classes
         if ($this_level < $next_info['level']) {
             $attributes_a['class']['haschildren'] = $GP_MENU_CLASSES['haschildren'];
             $attributes_li['class']['haschildren_li'] = $GP_MENU_CLASSES['haschildren_li'];
         }
         if (isset($menu_info['url']) && ($menu_info['url'] == $page->title || $menu_info['url'] == $page_title_full)) {
             $attributes_a['class']['selected'] = $GP_MENU_CLASSES['selected'];
             $attributes_li['class']['selected_li'] = $GP_MENU_CLASSES['selected_li'];
         } elseif ($menu_key == $page->gp_index) {
             $attributes_a['class']['selected'] = $GP_MENU_CLASSES['selected'];
             $attributes_li['class']['selected_li'] = $GP_MENU_CLASSES['selected_li'];
         } elseif (in_array($menu_key, $parents)) {
             $attributes_a['class']['childselected'] = $GP_MENU_CLASSES['childselected'];
             $attributes_li['class']['childselected_li'] = $GP_MENU_CLASSES['childselected_li'];
         }
         //current is a child of the previous
         if ($this_level > $prev_level) {
             if ($menu_index === 0) {
                 //only needed if the menu starts below the start_level
                 self::FormatMenuElement('li', $attributes_li);
             }
             if (!empty($GP_MENU_CLASSES['child_ul'])) {
                 $attributes_ul['class'][] = $GP_MENU_CLASSES['child_ul'];
             }
             if ($this_level > $prev_level) {
                 $open_loops = $this_level - $prev_level;
                 for ($i = 0; $i < $open_loops; $i++) {
                     self::FormatMenuElement('ul', $attributes_ul);
                     if ($i < $open_loops - 1) {
                         echo '<li>';
                     }
                     $prev_level++;
                     $attributes_ul = $clean_attributes;
                 }
             }
             //current is higher than the previous
         } elseif ($this_level < $prev_level) {
             while ($this_level < $prev_level) {
                 echo '</li></ul>';
                 $prev_level--;
             }
             if ($open) {
                 echo '</li>';
             }
         } elseif ($open) {
             echo '</li>';
         }
         //external
         if (isset($menu_info['url'])) {
             if (empty($menu_info['title_attr'])) {
                 $menu_info['title_attr'] = strip_tags($menu_info['label']);
             }
             $attributes_a['href'] = $menu_info['url'];
             $attributes_a['value'] = $menu_info['label'];
             $attributes_a['title'] = $menu_info['title_attr'];
             if (isset($menu_info['new_win'])) {
                 $attributes_a['target'] = '_blank';
             }
             //internal link
         } else {
             $title = common::IndexToTitle($menu_key);
             $attributes_a['href'] = common::GetUrl($title);
             $attributes_a['value'] = common::GetLabel($title);
             $attributes_a['title'] = common::GetBrowserTitle($title);
             //get valid rel attr
             if (!empty($gp_titles[$menu_key]['rel'])) {
                 $rel = explode(',', $gp_titles[$menu_key]['rel']);
                 $attributes_a['rel'] = array_intersect(array('alternate', 'author', 'bookmark', 'help', 'icon', 'license', 'next', 'nofollow', 'noreferrer', 'prefetch', 'prev', 'search', 'stylesheet', 'tag'), $rel);
             }
         }
         self::FormatMenuElement('li', $attributes_li);
         self::FormatMenuElement('a', $attributes_a);
         $prev_level = $this_level;
         $open = true;
     }
     while ($start_level <= $prev_level) {
         echo '</li></ul>';
         $prev_level--;
     }
 }
Exemple #5
0
 /**
  * Output a navigation menu
  * @static
  */
 function OutputMenu($menu, $start_level, $source_menu = false)
 {
     global $page, $GP_MENU_LINKS, $GP_MENU_CLASS, $gp_menu, $gp_titles;
     if ($source_menu === false) {
         $source_menu =& $gp_menu;
     }
     $search = array('{$href_text}', '{$attr}', '{$label}', '{$title}');
     $replace = array();
     if (count($menu) == 0) {
         echo '<div class="emtpy_menu"></div>';
         //an empty <ul> is not valid xhtml
         gpOutput::ResetMenuGlobals();
         return;
     }
     //$GP_MENU_LINKS = '<a href="{$href_text}" {$attr}><span class="sub-t">{$label}</span></a>';
     //<a href="/rocky/index.php/Misson_&amp;_Principles" title="Misson &amp; Principles" >Misson &amp; Principles</a>
     $link_format = '<a href="{$href_text}" title="{$title}"{$attr}>{$label}</a>';
     if (!empty($GP_MENU_LINKS)) {
         $link_format = $GP_MENU_LINKS;
     }
     $result = array();
     $prev_level = $start_level;
     $page_title_full = common::GetUrl($page->title);
     $source_keys = array_keys($source_menu);
     $source_values = array_values($source_menu);
     $open = false;
     $li_count = array();
     //get parent page
     $parent_page = false;
     $parents = common::Parents($page->gp_index, $source_menu);
     if (count($parents)) {
         $parent_page = $parents[0];
     }
     $class = 'menu_top';
     if (!empty($GP_MENU_CLASS)) {
         $class = $GP_MENU_CLASS;
     }
     $result[] = '<ul class="' . $class . '">';
     foreach ($source_keys as $source_index => $menu_key) {
         $attr = $class = $attr_li = $class_li = '';
         $menu_info = $source_values[$source_index];
         $this_level = $menu_info['level'];
         //the next entry
         $next_info = false;
         if (isset($source_values[$source_index + 1])) {
             $next_info = $source_values[$source_index + 1];
         }
         //create link if in $menu
         if (isset($menu[$menu_key])) {
             //ordered or "indexed" classes
             if ($page->menu_css_ordered) {
                 for ($i = $prev_level; $i > $this_level; $i--) {
                     unset($li_count[$i]);
                 }
                 if (!isset($li_count[$this_level])) {
                     $li_count[$this_level] = 0;
                 } else {
                     $li_count[$this_level]++;
                 }
                 $class_li = 'li_' . $li_count[$this_level];
             }
             if ($page->menu_css_indexed) {
                 $class_li .= ' li_title_' . $menu_key;
             }
             //selected classes
             if ($this_level < $next_info['level']) {
                 $class .= ' haschildren';
             }
             if (isset($menu_info['url']) && ($menu_info['url'] == $page->title || $menu_info['url'] == $page_title_full)) {
                 $class .= ' selected';
                 $class_li .= ' selected_li';
             } elseif ($menu_key == $page->gp_index) {
                 $class .= ' selected';
                 $class_li .= ' selected_li';
             } elseif (in_array($menu_key, $parents)) {
                 $class .= ' childselected';
                 $class_li .= ' childselected_li';
             }
             if (!empty($class)) {
                 $attr = ' class="' . trim($class) . '"';
             }
             if (!empty($class_li)) {
                 $attr_li = ' class="' . trim($class_li) . '"';
             }
             //current is a child of the previous
             if ($this_level > $prev_level) {
                 if (!$open) {
                     $result[] = '<li' . $attr_li . '>';
                     //only needed if the menu starts below the start_level
                 }
                 while ($this_level > $prev_level) {
                     $result[] = '<ul>';
                     $result[] = '<li>';
                     $prev_level++;
                 }
                 array_pop($result);
                 //remove the last <li>
                 //current is higher than the previous
             } elseif ($this_level < $prev_level) {
                 while ($this_level < $prev_level) {
                     $result[] = '</li>';
                     $result[] = '</ul>';
                     $prev_level--;
                 }
                 if ($open) {
                     $result[] = '</li>';
                 }
             } elseif ($open) {
                 $result[] = '</li>';
             }
             $replace = array();
             //external
             if (isset($menu_info['url'])) {
                 if (empty($menu_info['title_attr'])) {
                     $menu_info['title_attr'] = strip_tags($menu_info['label']);
                 }
                 if (isset($menu_info['new_win'])) {
                     $attr .= ' target="_blank"';
                 }
                 $replace[] = $menu_info['url'];
                 $replace[] = $attr;
                 $replace[] = $menu_info['label'];
                 $replace[] = $menu_info['title_attr'];
                 //internal link
             } else {
                 if (!empty($gp_titles[$menu_key]['rel'])) {
                     $attr .= ' rel="' . $gp_titles[$menu_key]['rel'] . '"';
                 }
                 $title = common::IndexToTitle($menu_key);
                 $replace[] = common::GetUrl($title);
                 $replace[] = $attr;
                 $replace[] = common::GetLabel($title);
                 $replace[] = common::GetBrowserTitle($title);
             }
             $result[] = '<li' . $attr_li . '>' . str_replace($search, $replace, $link_format);
             $prev_level = $this_level;
             $open = true;
         }
     }
     while ($start_level <= $prev_level) {
         $result[] = '</li>';
         $result[] = '</ul>';
         $prev_level--;
     }
     //$test = implode("\n",$result);
     //$test = htmlspecialchars($test);
     //echo nl2br($test);
     //echo '<hr/>';
     echo implode('', $result);
     //don't separate by spaces so css inline can be more functional
     gpOutput::ResetMenuGlobals();
     return;
 }
 /**
  * Get the css class representing the current page's visibility
  *
  */
 function VisibilityClass($class, $index)
 {
     global $gp_menu, $gp_titles;
     if (isset($gp_titles[$index]['vis'])) {
         $class .= ' private-list';
         return $class;
     }
     $parents = common::Parents($index, $gp_menu);
     foreach ($parents as $parent_index) {
         if (isset($gp_titles[$parent_index]['vis'])) {
             $class .= ' private-inherited';
             break;
         }
     }
     return $class;
 }