2009-08-25, 04:32:13
bnowell,
This function is still a work in progress. Only a preliminary version is in 1.5. Below is the revised code.. replace your's with it and let me know if you get a better result.
This function is still a work in progress. Only a preliminary version is in 1.5. Below is the revised code.. replace your's with it and let me know if you get a better result.
Code:
function menu_data($id = null) {
$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;
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;
}
closedir($dir_handle);
}