sitemap

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
hkj

sitemap

Post by hkj »

Hi All,

I find that the existing sitemap tag plugin has weird representation when one content element is set 'not show in menu' but the children as 'show in menu'. The depth becomes incorrect that the output sitemap may not be well appeared. I made a simple modification to handle it. Here it is:

Filename: /plugins/function.sitemap.php

Code: Select all

...
function smarty_cms_function_sitemap($params, &$smarty) {

        global $gCms;

        $allcontent = ContentManager::GetAllContent();

        # defining variables
        $menu = "";
        $last_level = 0;
        $count = 0;
        $in_hr = 0;
// Line added by joeli
$notshow_hier = '';

        /* LeisureLarry - Begin */
        $add_elements = isset($params["add_elements"]) ? $params["add_elements"] : 0 ;
        $add_element = explode(",", $add_elements);
        /* LeisureLarry - End */

        foreach ($allcontent as $onecontent)
        {
// Start added by joeli
if ($notshow_hier != '') {
	if (strpos($onecontent->mHierarchy, $notshow_hier) !== 0) {
		$notshow_hier = '';
	} else {
		continue;
	}
}
// End added by joeli

                #Handy little trick to figure out how deep in the tree we are
                #Remember, content comes to use in order of how it should be displayed in the tree already
                $depth = count(split('\.', $onecontent->Hierarchy()));

                #If hierarchy starts with the start_element (if it's set), then continue on
                if (isset($params['start_element']))
                {
                        if (!(strpos($onecontent->Hierarchy(), $params['start_element']) !== FALSE && strpos($onecontent->Hierarchy(), $params['start_element']) == 0))
                        {
                                if(($onecontent->Alias() == $params['start_element']))
                                {

                                        $params['start_element'] = $onecontent->Hierarchy();
                                        $depth = count(split('\.', $onecontent->Hierarchy()));
                                        continue;
                                }
                                else
                                {
                                        continue;
                                }
                        }
                }
                #Now check to make sure we're not too many levels deep if number_of_levels is set
                if (isset($params['number_of_levels']))
                {
                        $number_of_levels = $params['number_of_levels'] - 1;
                        $base_level = 1;

                        #Is start_element set?  If so, reset the base_level to it's level
                        if (isset($params['start_element']))
                        {
                                $base_level = count(split('\.', $params['start_element'])) + 1;
                        }
                        #If this element's level is more than base_level + number_of_levels, then scratch it
                        if ($base_level + $number_of_levels < $depth)
                        {
                                continue;
                        }
                }

                //Not active?  Toss it.
                if (!$onecontent->Active())
                {
					continue;
                }

                //It's a separator or section header?  Toss it.
                if (!$onecontent->HasUsableLink())
                {
					continue;
                }

                //Not shown in menu?  Toss it.
                if (!$onecontent->ShowInMenu())
                {
                        /* LeisureLarry - parameter show */
                        //If param showall, display also content not shown in menu.
                        if (((isset($params['showall']) && $params['showall'] == 1)) or
                        ($add_elements && in_array($onecontent->Alias(),$add_element)))
                        {
                        }
// Start modified by joeli
                        else {
	                        $notshow_hier = $onecontent->mHierarchy;
	                        continue;
                        }
// End modified by joeli
                }
...
Feel free to let me know if I have any missing points.
Joe
User avatar
Elijah Lofgren
Power Poster
Power Poster
Posts: 811
Joined: Mon Apr 24, 2006 1:01 am
Location: Deatsville, AL

Re: sitemap

Post by Elijah Lofgren »

Thanks for the patch!  :)
Applied in lastest SVN: http://viewsvn.cmsmadesimple.org/viewsv ... w=rev&nbsp; ;)
Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. :)
Post Reply

Return to “Tips and Tricks”