[ Index ] |
|
Code source de CMS made simple 1.0.5 |
1 <?php 2 #CMS - CMS Made Simple 3 #(c)2004 by Ted Kulp (wishy@users.sf.net) 4 #This project's homepage is: http://cmsmadesimple.sf.net 5 # 6 #This program is free software; you can redistribute it and/or modify 7 #it under the terms of the GNU General Public License as published by 8 #the Free Software Foundation; either version 2 of the License, or 9 #(at your option) any later version. 10 # 11 #This program is distributed in the hope that it will be useful, 12 #but WITHOUT ANY WARRANTY; without even the implied warranty of 13 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 #GNU General Public License for more details. 15 #You should have received a copy of the GNU General Public License 16 #along with this program; if not, write to the Free Software 17 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 # 19 #$Id: News.module.php 2114 2005-11-04 21:51:13Z wishy $ 20 21 class MenuManager extends CMSModule 22 { 23 function GetName() 24 { 25 return 'MenuManager'; 26 } 27 28 function GetFriendlyName() 29 { 30 return $this->Lang('menumanager'); 31 } 32 33 function IsPluginModule() 34 { 35 return true; 36 } 37 38 function HasAdmin() 39 { 40 return true; 41 } 42 43 function VisibleToAdminUser() 44 { 45 return $this->CheckPermission('Manage Menu'); 46 } 47 48 function Uninstall() 49 { 50 // remove the permissions 51 $this->RemovePermission('Manage Menu'); 52 } 53 54 function GetVersion() 55 { 56 return '1.2'; 57 } 58 59 function MinimumCMSVersion() 60 { 61 return '0.12'; 62 } 63 64 function GetAdminDescription() 65 { 66 return $this->Lang('description'); 67 } 68 69 function GetAdminSection() 70 { 71 return 'layout'; 72 } 73 74 function SetParameters() 75 { 76 $this->CreateParameter('collapse', '1', $this->lang('help_collapse')); 77 $this->CreateParameter('items', 'contact,home', $this->lang('help_items')); 78 $this->CreateParameter('number_of_levels', '1', $this->lang('help_number_of_levels')); 79 $this->CreateParameter('show_all', '0', $this->lang('help_show_all')); 80 $this->CreateParameter('show_root_siblings', '1', $this->lang('help_show_root_siblings')); 81 $this->CreateParameter('start_level', '2', $this->lang('help_start_level')); 82 $this->CreateParameter('start_element', '1.2', $this->lang('help_start_element')); 83 $this->CreateParameter('start_page', 'home', $this->lang('help_start_page')); 84 $this->CreateParameter('template', 'bulletmenu.tpl', $this->lang('help_template')); 85 } 86 87 /** 88 * Recursive function to go through all nodes and put them into a list 89 */ 90 function GetChildNodes(&$parentnode, &$nodelist, &$gCms, &$prevdepth, &$count, &$params, $origdepth, &$showparents) 91 { 92 if (isset($params['show_all'])) 93 { 94 $show_all = $params['show_all']; 95 } 96 else 97 { 98 $show_all = 0; 99 } 100 if (isset($parentnode)) 101 { 102 $children =& $parentnode->getChildren(); 103 if (isset($children) && count($children)) 104 { 105 reset($children); 106 while (list($key) = each($children)) 107 { 108 $onechild =& $children[$key]; 109 $content =& $onechild->GetContent(); 110 if ($content != NULL && $content->Active() && ($content->ShowInMenu() || ($show_all == 1))) 111 { 112 $newnode =& $this->FillNode($content, $onechild, $nodelist, $gCms, $count, $prevdepth, $origdepth); 113 //Ok, this one is nasty... 114 //First part checks to see if number_of_levels is set and whether the current depth is deeper than the set number_of_levels depth (opposite logic, actually) 115 //Second part checks to see if showparents is set... if so, then it checks to see if this hierarchy position is one of them 116 //If either of these things occurs, then try to show the children of this node 117 if (!(isset($params['number_of_levels']) && $newnode->depth > ($params['number_of_levels']) - ($origdepth)) && (count($showparents) == 0 || (count($showparents) > 0 && in_array($content->Hierarchy() . '.', $showparents)))) 118 { 119 $this->GetChildNodes($onechild, $nodelist, $gCms, $prevdepth, $count, $params, $origdepth, $showparents); 120 } 121 } 122 } 123 } 124 } 125 } 126 127 function & FillNode(&$content, &$node, &$nodelist, &$gCms, &$count, &$prevdepth, $origdepth) 128 { 129 $onenode = new stdClass(); 130 $onenode->id = $content->Id(); 131 $onenode->url = $content->GetURL(); 132 $onenode->accesskey = $content->AccessKey(); 133 $onenode->type = strtolower($content->Type()); 134 $onenode->tabindex = $content->TabIndex(); 135 $onenode->titleattribute = $content->TitleAttribute(); 136 $onenode->hierarchy = $content->Hierarchy(); 137 $onenode->depth = count(explode('.', $content->Hierarchy())) - ($origdepth - 1); 138 $onenode->prevdepth = $prevdepth - ($origdepth - 1); 139 if ($onenode->prevdepth == 0) 140 $onenode->prevdepth = 1; 141 if (isset($node)) 142 $onenode->haschildren = $node->HasChildren(); 143 else 144 $onenode->haschildren = false; 145 $prevdepth = $onenode->depth + ($origdepth - 1); 146 $onenode->menutext = my_htmlentities($content->MenuText()); 147 $onenode->target = ''; 148 if ($content->HasProperty('target')) 149 $onenode->target = $content->GetPropertyValue('target'); 150 $onenode->index = $count; 151 $onenode->alias = $content->Alias(); 152 $onenode->parent = false; 153 $count++; 154 155 if (isset($gCms->variables['content_id']) && $onenode->id == $gCms->variables['content_id']) 156 $onenode->current = true; 157 else 158 { 159 $onenode->current = false; 160 //So, it's not current. Lets check to see if it's a direct parent 161 if (isset($gCms->variables["friendly_position"])) 162 { 163 if (strstr($gCms->variables["friendly_position"] . '.', $content->Hierarchy() . '.') == $gCms->variables["friendly_position"] . '.') 164 { 165 $onenode->parent = true; 166 } 167 } 168 } 169 170 $nodelist[] = $onenode; 171 172 return $onenode; 173 } 174 175 function nthPos($str, $needles, $n=1) 176 { 177 // Found at: http://us2.php.net/manual/en/function.strpos.php 178 // csaba at alum dot mit dot edu 179 // finds the nth occurrence of any of $needles' characters in $str 180 // returns -1 if not found; $n<0 => count backwards from end 181 // e.g. $str = "c:\\winapps\\morph\\photos\\Party\\Phoebe.jpg"; 182 // substr($str, nthPos($str, "/\\:", -2)) => \Party\Phoebe.jpg 183 // substr($str, nthPos($str, "/\\:", 4)) => \photos\Party\Phoebe.jpg 184 $pos = -1; 185 $size = strlen($str); 186 if ($reverse=($n<0)) { $n=-$n; $str = strrev($str); } 187 while ($n--) 188 { 189 $bestNewPos = $size; 190 for ($i=strlen($needles)-1;$i>=0;$i--) 191 { 192 $newPos = strpos($str, $needles[$i], $pos+1); 193 if ($newPos===false) $needles = substr($needles,0,$i) . substr($needles,$i+1); 194 else $bestNewPos = min($bestNewPos,$newPos); 195 } 196 if (($pos=$bestNewPos)==$size) return -1; 197 } 198 return $reverse ? $size-1-$pos : $pos; 199 } 200 201 function GetHelp($lang='en_US') 202 { 203 return $this->Lang('help'); 204 } 205 206 function GetAuthor() 207 { 208 return 'Ted Kulp'; 209 } 210 211 function GetAuthorEmail() 212 { 213 return 'ted@cmsmadesimple.org'; 214 } 215 216 function GetChangeLog() 217 { 218 return $this->Lang('changelog'); 219 } 220 221 function GetMenuTemplate($tpl_name) 222 { 223 $data = false; 224 if (endswith($tpl_name, '.tpl')) 225 { 226 global $gCms; 227 // template file, we're gonna have to get it from 228 // the filesystem, 229 $fn = $gCms->config['root_path'].DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR; 230 $fn .= $this->GetName().DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR; 231 $fn .= $tpl_name; 232 if( file_exists( $fn ) ) 233 { 234 $data = file_get_contents($fn); 235 } 236 } 237 else 238 { 239 $data = $this->GetTemplate($tpl_name); 240 } 241 242 return $data; 243 } 244 245 function SetMenuTemplate( $tpl_name, $content ) 246 { 247 if (endswith($tpl_name, '.tpl')) 248 { 249 return false; 250 } 251 252 $this->SetTemplate( $tpl_name, $content ); 253 return true; 254 } 255 } 256 257 # vim:ts=4 sw=4 noet 258 ?>
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 |