Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Child menu plugin
#78
added some changes to code
[/php]

added ability to omit parent and use custom tags (ul/li instead of div/p) using in-php settings, I've also added default blank values for childmenu and chilpmenuparent, because I kept getting an error when it was creating the cache.
Code:
    $includeParent = false;
    $tagLineItem = "li";
    $tagLineholder = "ul";
    $childmenu= '';
    $childmenuparent= '';

PHP Code:
<?php
/*
Plugin Name: Child Menu
Description: Prints parent title, children and siblings titles as a cached menu on parent and child pages.
Version: 1.8
Author: Erik
Author URI: http://www.fohlin.net/getsimple-child-menu-plugin
*/

// get correct id for plugin
$thisfile basename(__FILE__'.php'); // This gets the correct ID for the plugin.

// register plugin
register_plugin(
    
$thisfile,    // ID of plugin, should be filename minus php
    
'Child Menu',    # Title of plugin
    
'1.8',    // Version of plugin
    
'Erik',    // Author of plugin
    
'http://www.fohlin.net/getsimple-child-menu-plugin',    // Author URL
    
'Prints parent title, children and siblings titles as a cached menu on parent and child pages.',    // Plugin Description
    
'template',    // Page type of plugin
    
'go_child_menu'    // Function that displays content
);

// activate actions
//add_action('content-top','go_child_menu'); //Can be used if you need an action.
add_action('changedata-save','clear_child_menu_cache'); 

// functions
function clear_child_menu_cache() 
{
    
$cachepath GSDATAOTHERPATH.'child_menu_cache/';
    if (
is_dir($cachepath))
    {
        
$dir_handle = @opendir($cachepath) or exit('Unable to open ...getsimple/data/other/child_menu_cache folder');
        
$filenames = array();
        
        while (
$filename readdir($dir_handle))
        {
            
$filenames[] = $filename;
        }
        
        if (
count($filenames) != 0)
        {
            foreach (
$filenames as $file
            {
                if (!(
$file == '.' || $file == '..' || is_dir($cachepath.$file) || $file == '.htaccess'))
                {
                    
unlink($cachepath.$file) or exit('Unable to clean up ...getsimple/data/other/child_menu_cache folder');
                }
            }
        }
    }
}


function 
go_child_menu() 
{
    
$includeParent false;
    
$tagLineItem "li";
    
$tagLineholder "ul";
    
$childmenu'';
    
$childmenuparent'';

    
$active_page=return_page_slug();
    
$cashepath GSDATAOTHERPATH.'child_menu_cache/'.$active_page.'.cache';
    
    if (
is_file($cashepath)) //We have a cashed file, use it.
    
{
        echo 
file_get_contents($cashepath);
    }
    else 
//We do not have a cached file, create a new one.
    
{
        global 
$PRETTYURLS;
        
$dir_handle = @opendir(GSDATAPAGESPATH) or exit('Unable to open ...getsimple/data/pages folder');
        
        
$active_parent=return_parent();
        if (
strlen($active_parent)==0)
        {
            
$active_parent=return_page_slug();
        }
    
        
$filenames = array();
        
        while (
$filename readdir($dir_handle))
        {
            
$filenames[] = $filename;
        }
        
        if (
count($filenames) != 0)
        {
            
sort($filenames); //Sort according to page Slug/URL
            
$childmenuarray = array();
            
$childmenusortarray = array();
            
$slugsortorder 21;
            
            
//Loop through all pages
            
foreach ($filenames as $file
            {
                if (!(
$file == '.' || $file == '..' || is_dir(GSDATAPAGESPATH.$file) || $file == '.htaccess'))
                {
                    
$thisfile file_get_contents(GSDATAPAGESPATH.$file);
                    
$XMLdata simplexml_load_string($thisfile);
                    
                    
//If parent.
                    
if ($XMLdata->private != 'Y' and strcmp($XMLdata->url,$active_parent)==and $includeParent == true)
                    {
                        
//Check if current page
                        
if (strcmp($XMLdata->url,$active_page)==0)
                        {
                            
$current=' class="current"';
                        }
                        else
                        {
                            
$current='';
                        }
                        
                        
//Store the parent page data
                        
if ($PRETTYURLS==1)
                        {
                            if (
strlen($XMLdata->menu)>0)
                            {
                                
$childmenuparent='<p id="parent"'.$current.'><a href="'.$XMLdata->url.'">'.stripslashes(htmlspecialchars_decode($XMLdata->menu)).'</a></p>';
                            }
                            else
                            {
                                
$childmenuparent='<p id="parent"'.$current.'><a href="'.$XMLdata->url.'">'.stripslashes(htmlspecialchars_decode($XMLdata->title)).'</a></p>';
                            }
                        }
                        else
                        {
                            if (
strlen($XMLdata->menu)>0)
                            {
                                
$childmenuparent='<p id="parent"'.$current.'><a href="index.php?id='.$XMLdata->url.'">'.stripslashes(htmlspecialchars_decode($XMLdata->menu)).'</a></p>';
                            }
                            else
                            {
                                
$childmenuparent='<p id="parent"'.$current.'><a href="index.php?id='.$XMLdata->url.'">'.stripslashes(htmlspecialchars_decode($XMLdata->title)).'</a></p>';
                            }
                        }
                    }
                    elseif (
$XMLdata->private != 'Y' and strcmp($XMLdata->parent,$active_parent)==0//If child.
                    
{
                        
//Build the menu order sorting array
                        
if ($XMLdata->menuOrder>0)
                        {
                            
$childmenusortarray[]=$XMLdata->menuOrder;
                        }
                        else
                        {
                            
$childmenusortarray[]=$slugsortorder//Default to top
                        
}
                        
$slugsortorder++;
                        
                        
//Check if current page
                        
if (strcmp($XMLdata->url,$active_page)==0)
                        {
                            
$current=' class="current"';
                        }
                        else
                        {
                            
$current='';
                        }
                        
                        
//Build the child menu array
                        
if ($PRETTYURLS==1)
                        {
                            if (
strlen($XMLdata->menu)>0)
                            {
                                
$childmenuarray[]='<'.$tagLineItem.$current.'><a href="'.$XMLdata->url.'">'.stripslashes(htmlspecialchars_decode($XMLdata->menu)).'</a></'.$tagLineItem.'>';
                            }
                            else
                            {
                                
$childmenuarray[]='<'.$tagLineItem.$current.'><a href="'.$XMLdata->url.'">'.stripslashes(htmlspecialchars_decode($XMLdata->title)).'</a></'.$tagLineItem.'>';
                            }
                        }
                        else
                        {
                            if (
strlen($XMLdata->menu)>0)
                            {
                                
$childmenuarray[]='<'.$tagLineItem.$current.'><a href="index.php?id='.$XMLdata->url.'">'.stripslashes(htmlspecialchars_decode($XMLdata->menu)).'</a></'.$tagLineItem.'>';
                            }
                            else
                            {
                                
$childmenuarray[]='<'.$tagLineItem.$current.'><a href="index.php?id='.$XMLdata->url.'">'.stripslashes(htmlspecialchars_decode($XMLdata->title)).'</a></'.$tagLineItem.'>';
                            }
                        }
                    }
                }
            }
            
            
//Sort the child menu numerically according to menu order
            
array_multisort($childmenusortarray,SORT_ASC,SORT_NUMERIC,$childmenuarray);
            foreach (
$childmenuarray as $childmenuitem
            {
                
$childmenu=$childmenu.$childmenuitem;
            }
            
            if (
strlen($childmenu)>0)
            {
                
$thismenu='<'.$tagLineholder.' id="child_menu">'.$childmenuparent.$childmenu.'</'.$tagLineholder.'>';
                echo 
'<!-- un-cached -->'.$thismenu;
            }
            else
            {
                
$thismenu=''//$thismenu='<div id="child_menu"></div>'; //If you want the child menu div even if there is no child menu.
            
}
            
            
//Check if cache folder exists.
            
if (is_dir(GSDATAOTHERPATH.'child_menu_cache')==false)
            {
                
mkdir(GSDATAOTHERPATH.'child_menu_cache'0755) or exit('Unable to create ...getsimple/data/other/child_menu_cache folder');
            }
            
            
//Save cached child menu file.
            
$fp = @fopen($cashepath'w') or exit('Unable to save ...getsimple/data/other/child_menu_cache/'.$active_page);
            
fwrite($fp$thismenu);
            
fclose($fp);
        }
    }
}

?>
Reply


Messages In This Thread
Child menu plugin - by erka - 2010-08-11, 21:41:54
RE: Child menu plugin - by ZhuJo - 2013-01-15, 23:14:00
RE: Child menu plugin - by mvlcek - 2013-01-15, 23:57:50
RE: Child menu plugin - by ZhuJo - 2013-01-22, 22:52:32
RE: Child menu plugin - by scorche - 2013-03-27, 05:55:17
RE: Child menu plugin - by TeeJay - 2013-03-29, 20:00:09
RE: Child menu plugin - by Carlos - 2013-03-29, 20:38:35
RE: Child menu plugin - by TeeJay - 2013-03-29, 20:42:44
RE: Child menu plugin - by Carlos - 2013-03-29, 20:55:27
RE: Child menu plugin - by TeeJay - 2013-03-29, 21:01:50
RE: Child menu plugin - by ShawnPConroy - 2013-07-13, 11:19:44
RE: Child menu plugin - by dedos - 2013-09-12, 01:04:36
RE: Child menu plugin - by itsjustme - 2016-06-02, 21:15:47
RE: Child menu plugin - by mdique - 2013-11-12, 13:22:49
RE: Child menu plugin - by Timbow - 2013-11-12, 20:12:34
RE: Child menu plugin - by R.Muetterlein - 2014-07-02, 20:49:21
RE: Child menu plugin - by djman9 - 2016-12-09, 07:40:39
RE: Child menu plugin - by Carlos - 2016-12-10, 19:59:56
RE: Child menu plugin - by Artur - 2016-12-09, 08:49:43
RE: Child menu plugin - by indyana - 2017-01-08, 04:40:52
RE: Child menu plugin - by Domi - 2020-06-30, 17:59:59
Child menu plugin - by Carlos - 2010-08-12, 00:08:57
Child menu plugin - by Oleg06 - 2010-08-12, 01:35:05
Child menu plugin - by erka - 2010-08-12, 05:10:06
Child menu plugin - by Stew_822 - 2010-08-17, 13:10:02
Child menu plugin - by erka - 2010-08-17, 21:41:01
Child menu plugin - by Stew_822 - 2010-08-19, 07:15:14
Child menu plugin - by Johonwayni - 2010-08-19, 17:42:02
Child menu plugin - by erka - 2010-08-20, 20:12:58
Child menu plugin - by kjemperud - 2010-11-06, 11:04:31
Child menu plugin - by erka - 2010-11-18, 20:08:48
Child menu plugin - by Oleg06 - 2010-11-18, 20:12:29
Child menu plugin - by erka - 2010-11-18, 20:31:51
Child menu plugin - by erka - 2010-11-18, 20:55:57
Child menu plugin - by arthur_a_keen - 2010-11-24, 00:04:47
Child menu plugin - by Oleg06 - 2010-11-24, 01:05:28
Child menu plugin - by arthur_a_keen - 2010-11-24, 02:11:33
Child menu plugin - by Oleg06 - 2010-11-24, 03:59:09
Child menu plugin - by arthur_a_keen - 2010-11-24, 04:43:38
Child menu plugin - by Oleg06 - 2010-11-24, 06:03:48
Child menu plugin - by arthur_a_keen - 2010-11-24, 07:01:52
Child menu plugin - by Oleg06 - 2010-11-24, 20:09:24
Child menu plugin - by arthur_a_keen - 2010-11-24, 20:18:20
Child menu plugin - by Oleg06 - 2010-11-24, 22:30:58
Child menu plugin - by arthur_a_keen - 2010-11-24, 23:44:15
Child menu plugin - by Oleg06 - 2010-11-25, 05:22:32
Child menu plugin - by erka - 2010-11-27, 01:38:05
Child menu plugin - by Oleg06 - 2010-11-27, 03:48:01
Child menu plugin - by arthur_a_keen - 2010-11-27, 18:32:23
Child menu plugin - by El-Cherubin - 2010-12-02, 02:49:42
Child menu plugin - by Oleg06 - 2010-12-02, 03:03:45
Child menu plugin - by paisit - 2011-01-09, 12:41:30
Child menu plugin - by madvic - 2011-01-26, 06:14:39
Child menu plugin - by erka - 2011-01-26, 08:19:17
Child menu plugin - by mvlcek - 2011-01-26, 09:01:34
Child menu plugin - by tvon - 2011-01-26, 13:02:54
Child menu plugin - by erka - 2011-01-27, 03:48:25
Child menu plugin - by erka - 2011-01-27, 07:40:13
Child menu plugin - by madvic - 2011-01-27, 23:56:31
Child menu plugin - by erka - 2011-02-02, 20:56:52
Child menu plugin - by madvic - 2011-02-08, 02:16:14
Child menu plugin - by quite_me - 2011-03-23, 18:17:51
Child menu plugin - by J-Gamer - 2011-09-08, 00:50:07
Child menu plugin - by tommy - 2011-09-27, 01:09:15
Child menu plugin - by Oleg06 - 2011-09-27, 01:44:01
Child menu plugin - by tommy - 2011-09-28, 17:20:05
Child menu plugin - by mvlcek - 2011-09-29, 00:09:10
Child menu plugin - by tommy - 2011-10-02, 16:25:25
Child menu plugin - by erka - 2011-10-12, 07:20:05
Child menu plugin - by erka - 2011-10-12, 07:23:03
Child menu plugin - by erka - 2011-10-12, 07:25:44
Child menu plugin - by MrKireefd - 2012-01-11, 03:30:08
Child menu plugin - by cuirassier - 2012-01-12, 17:15:00
Child menu plugin - by erka - 2012-01-16, 02:55:23
Child menu plugin - by erka - 2012-01-16, 03:03:32
Child menu plugin - by Dominic - 2012-02-01, 12:36:18
Child menu plugin - by Dominic - 2012-02-02, 15:13:09
Child menu plugin - by mvlcek - 2012-02-02, 16:31:40
Child menu plugin - by Dominic - 2012-02-03, 14:24:59
Child menu plugin - by mvlcek - 2012-02-03, 17:07:58
Child menu plugin - by Dominic - 2012-02-04, 02:15:57
Child menu plugin - by cuirassier - 2012-03-01, 22:32:19
Child menu plugin - by yojoe - 2012-03-02, 06:55:26
Child menu plugin - by cuirassier - 2012-03-02, 20:24:27
Child menu plugin - by iggy - 2012-05-21, 19:46:26
Child menu plugin - by alex_d - 2012-05-30, 23:49:19
Child menu plugin - by mvlcek - 2012-05-31, 01:17:50
Child menu plugin - by alex_d - 2012-05-31, 20:03:32
Child menu plugin - by gsnewbie - 2012-06-14, 03:53:02
Child menu plugin - by erka - 2012-06-19, 16:33:17
Child menu plugin - by gsnewbie - 2012-06-21, 04:30:26
Child menu plugin - by Riianna - 2012-08-13, 21:13:04
Child menu plugin - by mvlcek - 2012-08-13, 21:16:39



Users browsing this thread: 1 Guest(s)