The following warnings occurred:
Warning [2] Undefined array key "threadviews_countguests" - Line: 745 - File: showthread.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php 745 errorHandler->error_callback
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/inc/functions_post.php 830 postParser->parse_message
/showthread.php 916 build_postbit
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/inc/functions_post.php 861 postParser->parse_message
/showthread.php 916 build_postbit
Warning [2] Undefined property: MyLanguage::$thread_modes - Line: 46 - File: showthread.php(1650) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php(1650) : eval()'d code 46 errorHandler->error_callback
/showthread.php 1650 eval




Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function menu_data not returning ALL menu items
#10
here's the undated function to allow XML
I've added in pubdate and changed the names to match what they are in pages XML files.



Code:
function menu_data($id = null,$xml=false) {
        $menu_extract = '';
        global $PRETTYURLS;
        global $SITEURL;
        
        $path = "data/pages";
        $dir_handle = @opendir($path) or die("Unable to open $path");
        $filenames = array();
        while ($filename = readdir($dir_handle)) {
            $filenames[] = $filename;
        }
        
        $count="0";
        $pagesArray = array();
        if (count($filenames) != 0) {
            foreach ($filenames as $file) {
                if ($file == "." || $file == ".." || is_dir("data/pages/".$file) || $file == ".htaccess"  ) {
                    // not a page data file
                } else {
                    $thisfile = @file_get_contents('data/pages/'.$file);
                    $data = simplexml_load_string($thisfile);
                    if ($data->private != 'Y') {
                        $pagesArray[$count]['menuStatus'] = $data->menuStatus;
                        $pagesArray[$count]['menuOrder'] = $data->menuOrder;
                        $pagesArray[$count]['menu'] = $data->menu;
                        $pagesArray[$count]['parent'] = $data->parent;
                        $pagesArray[$count]['title'] = $data->title;
                        $pagesArray[$count]['url'] = $data->url;
                        $pagesArray[$count]['private'] = $data->private;
                        $count++;
                    }
                }
            }
        }
        
        $pagesSorted = subval_sort($pagesArray,'menuOrder');
        if (count($pagesSorted) != 0) {
            $count = 0;
            if (!$xml){
            foreach ($pagesSorted as $page) {
                    $text = (string)$page['menu'];
                    $pri = (string)$page['menuOrder'];
                    $parent = (string)$page['parent'];
                    $title = (string)$page['title'];
                    $slug = (string)$page['url'];
                    $menuStatus = (string)$page['menuStatus'];
                    $private = (string)$page['private'];
                    
                    if ($PRETTYURLS == '1') {
                        if ($parent != '') {$parent = tsl($parent); }
                        if ($slug == 'index' ) { $slug = ''; }
                        $url = $SITEURL . @$parent . $slug;
                    } else {
                        $url = $SITEURL .'index.php?id='.$slug;
                    }
                    
                    $specific = array("slug"=>$slug,"url"=>$url,"parent_slug"=>$parent,"title"=>$title,"menu_priority"=>$pri,"menu_text"=>$text,"menu_status"=>$menuStatus,"private"=>$private);
                    
                    if ($id == $slug) {
                        return $specific;
                        exit;
                    } else {
                        $menu_extract[] = $specific;
                    }
                
            }
            return $menu_extract;
            } else {
            $xml = '<?xml version="1.0" encoding="UTF-8"?><channel>';    
            foreach ($pagesSorted as $page) {
                    $text = $page['menu'];
                    $pri = $page['menuOrder'];
                    $parent = $page['parent'];
                    $title = $page['title'];
                    $slug = $page['url'];
                    $pubdate = $page['pubDate'];
                    $menuStatus = $page['menuStatus'];
                    $private = $page['private'];
                    if ($PRETTYURLS == '1') {
                        if ($parent != '') {$parent = tsl($parent); }
                        if ($slug == 'index' ) { $slug = ''; }
                        $url = $SITEURL . @$parent . $slug;
                    } else {
                        $url = $SITEURL .'index.php?id='.$slug;
                    }
                    
                    $xml.="<item>";
                    $xml.="<slug><![CDATA[".$slug."]]></slug>";
                    $xml.="<pubdate><![CDATA[".$pubdate."]]></pubdate>";
                    $xml.="<url><![CDATA[".$url."]]></url>";
                    $xml.="<parent><![CDATA[".$parent."]]></parent>";
                    $xml.="<title><![CDATA[".$title."]]></title>";
                    $xml.="<menuOrder><![CDATA[".$pri."]]></menuOrder>";
                    $xml.="<menu><![CDATA[".$text."]]></menu>";
                    $xml.="<menuStatus><![CDATA[".$menuStatus."]]></menuStatus>";
                    $xml.="<private><![CDATA[".$private."]]></private>";
                    $xml.="</item>";
                    
            }
            $xml.="</channel>";
            return $xml;
            }
        }
        
        closedir($dir_handle);
    }

use in your template as:

Code:
$pages=simplexml_load_string(menu_data('',true));

// to get a list of menu items sorted by menuOrder
    $components = subval_sort($pages->xpath("//*[menuStatus='Y']"),'menuOrder');
        foreach ($components as $item){
       echo $item->menu;   // style as you require.
       }
My Github Repos: Github
Website: DigiMute
Reply


Messages In This Thread
Function menu_data not returning ALL menu items - by n00dles101 - 2009-08-25, 09:28:01



Users browsing this thread: 1 Guest(s)