[ Index ] |
|
Code source de CMS made simple 1.0.5 |
1 <?php 2 3 # CMS - CMS Made Simple 4 # 5 # (c)2004 by Ted Kulp (wishy@users.sf.net) 6 # 7 # This project's homepage is: http://cmsmadesimple.sf.net 8 # 9 # This program is free software; you can redistribute it and/or modify 10 # it under the terms of the GNU General Public License as published by 11 # the Free Software Foundation; either version 2 of the License, or 12 # (at your option) any later version. 13 # 14 # This program is distributed in the hope that it will be useful, 15 # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 # GNU General Public License for more details. 18 # You should have received a copy of the GNU General Public License 19 # along with this program; if not, write to the Free Software 20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 22 function smarty_cms_function_sitemap($params, &$smarty) 23 { 24 25 global $gCms; 26 27 $contentops =& $gCms->GetContentOperations(); 28 $allcontent = $contentops->GetAllContent(); 29 30 // define variables 31 $menu = ''; 32 $last_level = 0; 33 $first_level= 0; 34 $count = 0; 35 $in_hr = 0; 36 $no_end = false; 37 38 $add_elements = isset($params['add_elements']) ? $params['add_elements'] : 0; 39 $add_element = explode(',', $add_elements); 40 41 foreach ($allcontent as $onecontent) 42 { 43 // Handy little trick to figure out how deep in the tree we are 44 // Remember, content comes to use in order of how it should be displayed in the tree already 45 $depth = count(split('\.', $onecontent->Hierarchy())); 46 47 // If hierarchy starts with the start_element (if it's set), then continue on 48 if (isset($params['start_element'])) 49 { 50 if ( 51 ! ( 52 strpos($onecontent->Hierarchy(), $params['start_element']) !== FALSE 53 && 54 strpos($onecontent->Hierarchy(), $params['start_element']) == 0 55 ) 56 ) 57 { 58 if(($onecontent->Alias() == $params['start_element'])) 59 { 60 $params['start_element'] = $onecontent->Hierarchy(); 61 $depth = count(split('\.', $onecontent->Hierarchy())); 62 $first_level = $depth; 63 continue; 64 } 65 else 66 { 67 continue; 68 } 69 } 70 } 71 // Now check to make sure we're not too many levels deep if number_of_levels is set 72 if (isset($params['number_of_levels'])) 73 { 74 $number_of_levels = $params['number_of_levels'] - 1; 75 $base_level = 1; 76 77 // Is start_element set? If so, reset the base_level to it's level 78 if (isset($params['start_element'])) 79 { 80 $base_level = count(split('\.', $params['start_element'])) + 1; 81 } 82 83 // If this element's level is more than base_level + number_of_levels, then scratch it 84 if ($base_level + $number_of_levels < $depth) 85 { 86 continue; 87 } 88 } 89 90 // Not active or separator? Toss it. 91 if (! $onecontent->Active() || ! $onecontent->MenuText()) 92 { 93 continue; 94 } 95 96 // Not shown in menu? Toss it. 97 if (! $onecontent->ShowInMenu()) 98 { 99 // If param showall, display also content not shown in menu. 100 if ( 101 ((isset($params['showall']) && $params['showall'] == 1)) 102 || 103 ($add_elements && in_array($onecontent->Alias(), $add_element)) 104 ) 105 { 106 107 } 108 else continue; 109 } 110 111 if ($depth < $last_level) 112 { 113 for ($i = $depth; $i < $last_level; $i++) 114 { 115 $menu .= "</li>\n</ul>\n"; 116 } 117 if ($depth > 0) 118 { 119 $menu .= "</li>\n"; 120 } 121 } 122 if ($depth == $last_level) 123 { 124 $menu .= "</li>\n"; 125 } 126 if ($depth > $last_level) 127 { 128 if ((isset($params['class']) && $params['class'] != '') && ($count == 0)) 129 { 130 $menu .= '<ul class="' . $params['class'] . '">' . "\n"; 131 } 132 else 133 { 134 $menu .= "\n<ul>\n"; 135 } 136 } 137 if ( 138 ! ( 139 (isset($params['relative']) && $params['relative'] == 1) 140 && 141 ( 142 isset($gCms->variables['content_id']) 143 && 144 $onecontent->Id() == $gCms->variables['content_id'] 145 ) 146 ) 147 ) 148 // we are not going to show current page if relative it's enabled - we'll show only his childs 149 { 150 $menu .= '<li>'; 151 152 if ((isset($params['delimiter']) && $params['delimiter'] != '') && ($depth > 1)) 153 { 154 $ddepth = (split('\.', $onecontent->Hierarchy())); 155 if ( 156 ($ddepth[sizeof($ddepth) - 1] > 1) 157 || 158 (isset($params['initial']) && $params['initial'] == '1') 159 ) 160 { 161 $menu .= $params['delimiter']; 162 } 163 } 164 165 // No link if section header. 166 if ($onecontent->HasUsableLink()) 167 { 168 $menu .= '<a href="' . $onecontent->GetURL() . '"'; 169 if (isset($gCms->variables['content_id']) && $onecontent->Id() == $gCms->variables['content_id']) 170 { 171 $menu .= ' class="currentpage"'; 172 } 173 if ($onecontent->GetPropertyValue('target') != '') 174 { 175 $menu .= ' target="' . $onecontent->GetPropertyValue('target') . '"'; 176 } 177 $menu .= '>' . my_htmlentities($onecontent->MenuText()) . '</a>'; 178 } 179 else 180 { 181 $menu .= my_htmlentities($onecontent->MenuText()); 182 } 183 } 184 else 185 { 186 if (! $onecontent->HasChildren()) 187 { 188 $no_end = true; 189 } 190 else 191 { 192 $menu .= '<li>'; 193 } 194 } 195 196 $last_level = $depth; 197 $count++; 198 } 199 200 for ($i = $first_level; $i < $last_level; $i++) 201 { 202 if ($no_end != true) 203 { 204 $menu .= '</li>'; 205 } 206 $menu .= "\n</ul>"; 207 } 208 209 210 return $menu; 211 212 } 213 214 function smarty_cms_help_function_sitemap() 215 { 216 ?> 217 <h3>What does this do?</h3> 218 <p>Prints out a sitemap.</p> 219 <h3>How do I use it?</h3> 220 <p>Just insert the tag into your template/page like: <code>{sitemap}</code></p> 221 <h3>What parameters does it take?</h3> 222 <p> 223 <ul> 224 <li><em>(optional)</em> <tt>class</tt> - A css_class for the ul-tag which includes the complete sitemap.</li> 225 <li><em>(optional)</em> <tt>start_element</tt> - The hierarchy of your element (ie : 1.2 or 3.5.1 for example). This parameter sets the root of the menu. You can use the page alias instead of hierarchy.</li> 226 <li><em>(optional)</em> <tt>number_of_levels</tt> - An integer, the number of levels you want to show in your menu. Should be set to 2 using a delimiter.</li> 227 <li><em>(optional)</em> <tt>delimiter</tt> - Text to separate entries not on depth 1 of the sitemap (i.e. 1.1, 1.2). This is helpful for showing entries on depth 2 beside each other (using css display:inline).</li> 228 <li><em>(optional)</em> <tt>initial 1/0</tt> - If set to 1, begin also the first entries not on depth 1 with a delimiter (i.e. 1.1, 2.1).</li> 229 <li><em>(optional)</em> <tt>relative 1/0</tt> - We are not going to show current page (with the sitemap) - we'll show only his childs.</li> 230 <li><em>(optional)</em> <tt>showall 1/0</tt> - We are going to show all pages if showall is enabled, else we'll only show pages with active menu entries.</li> 231 <li><em>(optional)</em> <tt>add_elements</tt> - A comma separated list of alias names which will be added to the shown pages with active menu entries (showall not enabled).</li> 232 </ul> 233 </p> 234 <?php 235 } 236 237 function smarty_cms_about_function_sitemap() 238 { 239 ?> 240 <p>Author: Marcus Deglos <<a href="mailto:md@zioncore.com">md@zioncore.com</a>></p> 241 <p>Version: 1.23</p> 242 <p> 243 Change History:<br /> 244 1.23 - Section headers and separators are shown, but without link (Simon van der Linden)<br /> 245 1.22 - Modified to use the new parameters class, delimiter, initial und add_elements (LeisureLarry)<br /> 246 1.21 - Changed help to show the existing parameters relative and showall (LeisureLarry)<br /> 247 1.2 - Modified to support alias instead of hierarchy and minor output improvement (intersol).<br /> 248 1.1 - Modified to use new content rewrite (wishy) 249 </p> 250 <?php 251 } 252 253 # vim:ts=4 sw=4 noet 254 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Tue Apr 3 18:50:37 2007 | par Balluche grâce à PHPXref 0.7 |