[ Index ] |
|
Code source de CMS made simple 1.0.5 |
1 <?php 2 #CMS - CMS Made Simple 3 #(c)2004 by Ted Kulp (tedkulp@users.sf.net) 4 #This project's homepage is: http://cmsmadesimple.org 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: class.admintheme.inc.php 3753 2007-01-16 19:33:28Z dittmann $ 20 21 /** 22 * Class for Admin Theme 23 * 24 * @package CMS 25 */ 26 class AdminTheme 27 { 28 29 /** 30 * CMS handle 31 */ 32 var $cms; 33 34 /** 35 * Title 36 */ 37 var $title; 38 39 /** 40 * Subtitle, for use in breadcrumb trails 41 */ 42 var $subtitle; 43 44 /** 45 * Url 46 */ 47 var $url; 48 49 /** 50 * Script 51 */ 52 var $script; 53 54 /** 55 * Query String, for use in breadcrumb trails 56 */ 57 var $query; 58 59 /** 60 * Aggregation of modules by section 61 */ 62 var $modulesBySection; 63 64 /** 65 * count of modules in each section 66 */ 67 var $sectionCount; 68 69 /** 70 * Aggregate Permissions 71 */ 72 var $perms; 73 74 /** 75 * Recent Page List 76 */ 77 var $recent; 78 79 /** 80 * Current Active User 81 */ 82 var $user; 83 84 /** 85 * Admin Section Menu cache 86 */ 87 var $menuItems; 88 89 /** 90 * Admin Section Image cache 91 */ 92 var $imageLink; 93 94 /** 95 * Theme Name 96 */ 97 var $themeName; 98 99 /** 100 * Breadcrumbs Array 101 */ 102 var $breadcrumbs; 103 104 /** 105 * Generic constructor. Runs the SetInitialValues fuction. 106 */ 107 function AdminTheme($cms, $userid, $themeName) 108 { 109 $this->SetInitialValues($cms, $userid, $themeName); 110 } 111 112 /** 113 * Sets object to some sane initial values 114 */ 115 function SetInitialValues($cms, $userid, $themeName) 116 { 117 $this->title = ''; 118 $this->subtitle = ''; 119 $this->cms = $cms; 120 $this->url = $_SERVER['SCRIPT_NAME']; 121 $this->query = (isset($_SERVER['QUERY_STRING'])?$_SERVER['QUERY_STRING']:''); 122 if ($this->query == '' && isset($_POST['module']) && $_POST['module'] != '') 123 { 124 $this->query = 'module='.$_POST['module']; 125 } 126 $this->userid = $userid; 127 $this->themeName = $themeName; 128 $this->perms = array(); 129 $this->recent = array(); 130 $this->menuItems = array(); 131 $this->breadcrumbs = array(); 132 $this->imageLink = array(); 133 $this->modulesBySection = array(); 134 $this->sectionCount = array(); 135 $this->SetModuleAdminInterfaces(); 136 $this->SetAggregatePermissions(); 137 if (strpos( $this->url, '/' ) === false) 138 { 139 $this->script = $this->url; 140 } 141 else 142 { 143 $toam_tmp = explode('/',$this->url); 144 $toam_tmp2 = array_pop($toam_tmp); 145 $this->script = $toam_tmp2; 146 //$this->script = array_pop(@explode('/',$this->url)); 147 } 148 149 } 150 151 /** 152 * Send admin page HTTP headers. 153 * 154 * @param alreadySentCharset boolean have we already sent character encoding? 155 * @param encoding string what encoding should we set? 156 * 157 */ 158 function SendHeaders($alreadySentCharset, $encoding) 159 { 160 // Date in the past 161 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 162 163 // always modified 164 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 165 166 // HTTP/1.1 167 header("Cache-Control: no-store, no-cache, must-revalidate"); 168 header("Cache-Control: post-check=0, pre-check=0", false); 169 170 // HTTP/1.0 171 header("Pragma: no-cache"); 172 173 // Language shizzle 174 if (! $alreadySentCharset) 175 { 176 header("Content-Type: text/html; charset=$encoding"); 177 } 178 } 179 180 /** 181 * MenuListSectionModules 182 * This method reformats module information for display in menus. When passed the 183 * name of the admin section, it returns an array of associations: 184 * array['module-name']['url'] is the link to that module, and 185 * array['module-name']['description'] is the language-specific short description of 186 * the module. 187 * 188 * @param section - section to display 189 */ 190 function MenuListSectionModules($section) 191 { 192 $modList = array(); 193 if (isset($this->sectionCount[$section]) && $this->sectionCount[$section] > 0) 194 { 195 # Sort modules by name 196 $names = array(); 197 foreach($this->modulesBySection[$section] as $key => $row) 198 { 199 $names[$key] = $this->modulesBySection[$section][$key]['name']; 200 } 201 array_multisort($names, SORT_ASC, $this->modulesBySection[$section]); 202 203 foreach($this->modulesBySection[$section] as $sectionModule) 204 { 205 $modList[$sectionModule['key']]['url'] = "moduleinterface.php?module=". 206 $sectionModule['key']; 207 $modList[$sectionModule['key']]['description'] = $sectionModule['description']; 208 $modList[$sectionModule['key']]['name'] = $sectionModule['name']; 209 } 210 } 211 return $modList; 212 } 213 214 /** 215 * SetModuleAdminInterfaces 216 * 217 * This function sets up data structures to place modules in the proper Admin sections 218 * for display on section pages and menus. 219 * 220 */ 221 function SetModuleAdminInterfaces() 222 { 223 # Are there any modules with an admin interface? 224 $cmsmodules = $this->cms->modules; 225 reset($cmsmodules); 226 while (list($key) = each($cmsmodules)) 227 { 228 $value =& $cmsmodules[$key]; 229 if (isset($cmsmodules[$key]['object']) 230 && $cmsmodules[$key]['installed'] == true 231 && $cmsmodules[$key]['active'] == true 232 && $cmsmodules[$key]['object']->HasAdmin() 233 && $cmsmodules[$key]['object']->VisibleToAdminUser()) 234 { 235 $section = $cmsmodules[$key]['object']->GetAdminSection(); 236 if (! isset($this->sectionCount[$section])) 237 { 238 $this->sectionCount[$section] = 0; 239 } 240 $this->modulesBySection[$section][$this->sectionCount[$section]]['key'] = $key; 241 if ($cmsmodules[$key]['object']->GetFriendlyName() != '') 242 { 243 $this->modulesBySection[$section][$this->sectionCount[$section]]['name'] = 244 $cmsmodules[$key]['object']->GetFriendlyName(); 245 } 246 else 247 { 248 $this->modulesBySection[$section][$this->sectionCount[$section]]['name'] = $key; 249 } 250 if ($cmsmodules[$key]['object']->GetAdminDescription() != '') 251 { 252 $this->modulesBySection[$section][$this->sectionCount[$section]]['description'] = 253 $cmsmodules[$key]['object']->GetAdminDescription(); 254 } 255 else 256 { 257 $this->modulesBySection[$section][$this->sectionCount[$section]]['description'] = ""; 258 } 259 $this->sectionCount[$section]++; 260 } 261 } 262 } 263 264 /** 265 * SetAggregatePermissions 266 * 267 * This function gathers disparate permissions to come up with the visibility of 268 * various admin sections, e.g., if there is any content-related operation for 269 * which a user has permissions, the aggregate content permission is granted, so 270 * that menu item is visible. 271 * 272 */ 273 function SetAggregatePermissions() 274 { 275 # Content Permissions 276 $this->perms['htmlPerms'] = check_permission($this->userid, 'Add Global Content Blocks') | 277 check_permission($this->userid, 'Modify Global Content Blocks') | 278 check_permission($this->userid, 'Delete Global Content Blocks'); 279 280 global $gCms; 281 $gcbops =& $gCms->GetGlobalContentOperations(); 282 283 $thisUserBlobs = $gcbops->AuthorBlobs($this->userid); 284 if (count($thisUserBlobs) > 0) 285 { 286 $this->perms['htmlPerms'] = true; 287 } 288 $this->perms['pagePerms'] = ( 289 check_permission($this->userid, 'Modify Any Page') || 290 check_permission($this->userid, 'Add Pages') || 291 check_permission($this->userid, 'Remove Pages') || 292 check_permission($this->userid, 'Modify Page Structure') 293 ); 294 $thisUserPages = author_pages($this->userid); 295 if (count($thisUserPages) > 0) 296 { 297 $this->perms['pagePerms'] = true; 298 } 299 $this->perms['contentPerms'] = $this->perms['pagePerms'] | $this->perms['htmlPerms'] | 300 (isset($this->sectionCount['content']) && $this->sectionCount['content'] > 0); 301 302 # layout 303 304 $this->perms['templatePerms'] = check_permission($this->userid, 'Add Templates') | 305 check_permission($this->userid, 'Modify Templates') | 306 check_permission($this->userid, 'Remove Templates'); 307 $this->perms['cssPerms'] = check_permission($this->userid, 'Add Stylesheets') | 308 check_permission($this->userid, 'Modify Stylesheets') | 309 check_permission($this->userid, 'Remove Stylesheets'); 310 $this->perms['cssAssocPerms'] = check_permission($this->userid, 'Add Stylesheet Assoc') | 311 check_permission($this->userid, 'Modify Stylesheet Assoc') | 312 check_permission($this->userid, 'Remove Stylesheet Assoc'); 313 $this->perms['layoutPerms'] = $this->perms['templatePerms'] | 314 $this->perms['cssPerms'] | $this->perms['cssAssocPerms'] | 315 (isset($this->sectionCount['layout']) && $this->sectionCount['layout'] > 0); 316 317 # file / image 318 $this->perms['filePerms'] = check_permission($this->userid, 'Modify Files') | 319 (isset($this->sectionCount['files']) && $this->sectionCount['files'] > 0); 320 321 # user/group 322 $this->perms['userPerms'] = check_permission($this->userid, 'Add Users') | 323 check_permission($this->userid, 'Modify Users') | 324 check_permission($this->userid, 'Remove Users'); 325 $this->perms['groupPerms'] = check_permission($this->userid, 'Add Groups') | 326 check_permission($this->userid, 'Modify Groups') | 327 check_permission($this->userid, 'Remove Groups'); 328 $this->perms['groupPermPerms'] = check_permission($this->userid, 'Modify Permissions'); 329 $this->perms['groupMemberPerms'] = check_permission($this->userid, 'Modify Group Assignments'); 330 $this->perms['usersGroupsPerms'] = $this->perms['userPerms'] | 331 $this->perms['groupPerms'] | 332 $this->perms['groupPermPerms'] | 333 $this->perms['groupMemberPerms'] | 334 (isset($this->sectionCount['usersgroups']) && 335 $this->sectionCount['usersgroups'] > 0); 336 337 # admin 338 $this->perms['sitePrefPerms'] = check_permission($this->userid, 'Modify Site Preferences') | 339 (isset($this->sectionCount['preferences']) && $this->sectionCount['preferences'] > 0); 340 $this->perms['adminPerms'] = $this->perms['sitePrefPerms'] | 341 (isset($this->sectionCount['admin']) && $this->sectionCount['admin'] > 0); 342 $this->perms['siteAdminPerms'] = $this->perms['sitePrefPerms'] | 343 $this->perms['adminPerms'] | 344 (isset($this->sectionCount['admin']) && 345 $this->sectionCount['admin'] > 0); 346 347 348 # extensions 349 $this->perms['codeBlockPerms'] = check_permission($this->userid, 'Modify User-defined Tags'); 350 $this->perms['modulePerms'] = check_permission($this->userid, 'Modify Modules'); 351 $this->perms['eventPerms'] = check_permission($this->userid, 'Modify Events'); 352 $this->perms['extensionsPerms'] = $this->perms['codeBlockPerms'] | 353 $this->perms['modulePerms'] | 354 $this->perms['eventPerms'] | 355 (isset($this->sectionCount['extensions']) && $this->sectionCount['extensions'] > 0); 356 } 357 358 /** 359 * HasPerm 360 * 361 * Check if the user has one of the aggregate permissions 362 * 363 * @param permission the permission to check. 364 */ 365 function HasPerm($permission) 366 { 367 if (isset($this->perms[$permission]) && $this->perms[$permission]) 368 { 369 return true; 370 } 371 else 372 { 373 return false; 374 } 375 } 376 377 378 /** 379 * LoadRecentPages 380 * This method loads a list of recently-accessed pages from the database. 381 * This list is stored in this object's variable "recent" as an array of 382 * associations. See ../lib/classes/class.recentpage.inc.php for more 383 * information on the array's format. 384 * 385 */ 386 function LoadRecentPages() 387 { 388 require_once ("../lib/classes/class.recentpage.inc.php"); 389 $this->recent = RecentPageOperations::LoadRecentPages($this->userid); 390 } 391 392 /** 393 * AddAsRecentPage 394 * Adds this page to the list of recently-visited pages. It attempts to 395 * filter out top-level pages, and to avoid adding the same page multiple times. 396 * 397 */ 398 function AddAsRecentPage() 399 { 400 if (count($this->recent) < 1) 401 { 402 $this->LoadRecentPages(); 403 } 404 405 $addToRecent = true; 406 foreach ($this->recent as $thisPage) 407 { 408 if ($thisPage->url == $this->url) 409 { 410 $addToRecent = false; 411 } 412 if ($thisPage->title == $this->title) 413 { 414 $addToRecent = false; 415 } 416 } 417 if (preg_match('/moduleinterface/', $this->url)) 418 { 419 if (! preg_match('/module=/', $this->url)) 420 { 421 $addToRecent = false; 422 } 423 } 424 if ($addToRecent) 425 { 426 $rp = new RecentPage(); 427 $rp->setValues($this->title, $this->url, $this->userid); 428 $rp->Save(); 429 $this->recent = array_reverse($this->recent); 430 $this->recent[] = $rp; 431 if (count($this->recent) > 5) 432 { 433 array_shift($this->recent); 434 } 435 $this->recent = array_reverse($this->recent); 436 $rp->PurgeOldPages($this->userid,5); 437 } 438 } 439 440 /** 441 * DoBookmarks 442 * Setup method for displaying admin bookmarks. 443 */ 444 function DoBookmarks() 445 { 446 global $gCms; 447 $bookops =& $gCms->GetBookmarkOperations(); 448 $marks = array_reverse($bookops->LoadBookmarks($this->userid)); 449 $tmpMark = new Bookmark(); 450 $tmpMark->title = lang('addbookmark'); 451 $tmpMark->url = 'makebookmark.php?title='. urlencode($this->title); 452 $marks[] = $tmpMark; 453 $marks = array_reverse($marks); 454 $tmpMark = new Bookmark(); 455 $tmpMark->title = lang('managebookmarks'); 456 $tmpMark->url = 'listbookmarks.php'; 457 $marks[] = $tmpMark; 458 $this->DisplayBookmarks($marks); 459 } 460 461 462 /** 463 * DoBookmarks 464 * Method for displaying admin bookmarks (shortcuts) & help links. 465 */ 466 function ShowShortcuts() 467 { 468 if (get_preference($this->userid, 'bookmarks')) { 469 echo '<div class="itemmenucontainer shortcuts" style="float:left;">'; 470 echo '<div class="itemoverflow">'; 471 echo '<h2>'.lang('bookmarks').'</h2>'; 472 echo '<p><a href="listbookmarks.php">'.lang('managebookmarks').'</a></p>'; 473 global $gCms; 474 $bookops =& $gCms->GetBookmarkOperations(); 475 $marks = array_reverse($bookops->LoadBookmarks($this->userid)); 476 $marks = array_reverse($marks); 477 if (FALSE == empty($marks)) 478 { 479 echo '<h3 style="margin:0">'.lang('user_created').'</h3>'; 480 echo '<ul style="margin:0">'; 481 foreach($marks as $mark) 482 { 483 echo "<li><a href=\"". $mark->url."\">".$mark->title."</a></li>\n"; 484 } 485 echo "</ul>\n"; 486 } 487 echo '<h3 style="margin:0;">'.lang('help').'</h3>'; 488 echo '<ul style="margin:0;">'; 489 echo '<li><a href="http://forum.cmsmadesimple.org/">'.lang('forums').'</a></li>'; 490 echo '<li><a href="http://wiki.cmsmadesimple.org/">'.lang('wiki').'</a></li>'; 491 echo '<li><a href="http://cmsmadesimple.org/main/support/IRC">'.lang('irc').'</a></li>'; 492 echo '<li><a href="http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel/Extensions/Modules">'.lang('module_help').'</a></li>'; 493 echo '</ul>'; 494 echo '</div>'; 495 echo '</div>'; 496 } 497 } 498 499 500 /** 501 * DisplayBookmarks 502 * Output bookmark data. Over-ride this to alter display of Bookmark information. 503 * Bookmark objects contain two useful fields: title and url 504 * 505 * 506 * @param marks - this is an array of Bookmark Objects 507 */ 508 function DisplayBookmarks($marks) 509 { 510 //echo "<div id=\"BookmarkCallout\">"; 511 echo '<div class="tab-content"><h2 class="tab">'.lang('bookmarks').'</h2>'; 512 echo "<p class=\"DashboardCalloutTitle\">"; 513 echo lang('bookmarks'); 514 echo "</p>\n"; 515 516 echo "<ul>"; 517 foreach($marks as $mark) 518 { 519 echo "<li><a href=\"". $mark->url."\">".$mark->title."</a></li>\n"; 520 } 521 echo "</ul>\n"; 522 echo "</div>\n"; 523 } 524 525 526 527 528 /** 529 * StartRighthandColumn 530 * Override this for different behavior or special functionality 531 * for the righthand column. Usual use would be a div open tag. 532 */ 533 function StartRighthandColumn() 534 { 535 echo '<div class="rightcol">'; 536 echo "\n"; 537 echo '<div id="admin-tab-container">'; 538 } 539 540 /** 541 * EndRighthandColumn 542 * Override this for different behavior or special functionality 543 * for the righthand column. Usual use would be a div close tag. 544 */ 545 function EndRighthandColumn() 546 { 547 echo "</div>\n</div>\n"; 548 } 549 550 551 552 /** 553 * DoRecentPages 554 * Setup method for displaying recent pages. 555 */ 556 function DoRecentPages() 557 { 558 if (count($this->recent) < 1) 559 { 560 $this->LoadRecentPages(); 561 } 562 $this->DisplayRecentPages(); 563 } 564 565 /** 566 * DisplayRecentPages 567 * Output Recent Page data. Over-ride this to alter display of Recent Pages information. 568 * Recent page information is available in $this->recent, which is an array of RecentPage 569 * objects. 570 * RecentPage objects contain two useful fields: title and url 571 * 572 */ 573 function DisplayRecentPages() 574 { 575 //echo "<div id=\"RecentPageCallout\">\n"; 576 echo '<div class="tab-content"><h2 class="tab">'.lang('recentpages').'</h2>'; 577 echo "<p class=\"DashboardCalloutTitle\">".lang('recentpages')."</p>\n"; 578 echo "<ul>"; 579 foreach($this->recent as $pg) 580 { 581 echo "<li><a href=\"". $pg->url."\">".$pg->title."</a></li>\n"; 582 } 583 echo "</ul>\n"; 584 echo "</div>\n"; 585 } 586 587 /** 588 * OutputHeaderJavascript 589 * This method can be used to dump out any javascript you'd like into the 590 * Admin page header. In fact, it can be used to put just about anything into 591 * the page header. It's recommended that you leave or copy the javascript 592 * below into your own method if you override this -- it's used by the dropdown 593 * menu in IE. 594 */ 595 function OutputHeaderJavascript() 596 { 597 ?> 598 <script type="text/javascript"> 599 <!-- Needed for correct display in IE only --> 600 <!-- 601 cssHover = function() { 602 var sfEls = document.getElementById("nav").getElementsByTagName("LI"); 603 for (var i=0; i<sfEls.length; i++) { 604 sfEls[i].onmouseover=function() { 605 this.className+=" cssHover"; 606 } 607 sfEls[i].onmouseout=function() { 608 this.className=this.className.replace(new RegExp(" cssHover\\b"), ""); 609 } 610 } 611 } 612 if (window.attachEvent) window.attachEvent("onload", cssHover); 613 --> 614 </script> 615 <?php 616 echo "<script type=\"text/javascript\" src=\""; 617 echo $this->cms->config['root_url']; 618 echo "/lib/dynamic_tabs/tabs.js\"></script>\n"; 619 } 620 621 /** 622 * OutputFooterJavascript 623 * This method can be used to dump out any javascript you'd like into the 624 * Admin page footer. 625 * It's recommended that you leave or copy the javascript below into your 626 * own method if you override this -- it's used by bookmarks/recent pages tabs. 627 */ 628 function OutputFooterJavascript() 629 { 630 echo "<script type=\"text/javascript\">BuildTabs('admin-tab-container','admin-tab-header','admin-tab-list');ActivateTab(0,'admin-tab-container','admin-tab-list');</script>"; 631 } 632 633 /** 634 * FixSpaces 635 * This method converts spaces into a non-breaking space HTML entity. 636 * It's used for making menus that work nicely 637 * 638 * @param str string to have its spaces converted 639 */ 640 function FixSpaces($str) 641 { 642 return preg_replace('/\s+/'," ",$str); 643 } 644 /** 645 * UnFixSpaces 646 * This method converts non-breaking space HTML entities into char(20)s. 647 * 648 * @param str string to have its spaces converted 649 */ 650 function UnFixSpaces($str) 651 { 652 return preg_replace('/ /'," ",$str); 653 } 654 655 /** 656 * PopulateAdminNavigation 657 * This method populates a big array containing the Navigation Taxonomy 658 * for the admin section. This array is then used to create menus and 659 * section main pages. It uses aggregate permissions to hide sections for which 660 * the user doesn't have permissions, and highlights the current section so 661 * menus can show the user where they are. 662 * 663 * @param subtitle any info to add to the page title 664 * 665 */ 666 function PopulateAdminNavigation($subtitle='') 667 { 668 if (count($this->menuItems) > 0) 669 { 670 // we have already created the list 671 return; 672 } 673 $this->subtitle = $subtitle; 674 675 $this->menuItems = array( 676 // base main menu --------------------------------------------------------- 677 'main'=>array('url'=>'index.php','parent'=>-1, 678 'title'=>$this->FixSpaces(lang('main')), 679 'description'=>'','show_in_menu'=>true), 680 // base content menu --------------------------------------------------------- 681 'content'=>array('url'=>'topcontent.php','parent'=>-1, 682 'title'=>$this->FixSpaces(lang('content')), 683 'description'=>lang('contentdescription'),'show_in_menu'=>$this->HasPerm('contentPerms')), 684 'pages'=>array('url'=>'listcontent.php','parent'=>'content', 685 'title'=>$this->FixSpaces(lang('pages')), 686 'description'=>lang('pagesdescription'),'show_in_menu'=>$this->HasPerm('pagePerms')), 687 'addcontent'=>array('url'=>'addcontent.php','parent'=>'pages', 688 'title'=>$this->FixSpaces(lang('addcontent')), 689 'description'=>lang('addcontent'),'show_in_menu'=>false), 690 'editpage'=>array('url'=>'editcontent.php','parent'=>'pages', 691 'title'=>$this->FixSpaces(lang('editpage')), 692 'description'=>lang('editpage'),'show_in_menu'=>false), 693 'files'=>array('url'=>'files.php','parent'=>'content', 694 'title'=>$this->FixSpaces(lang('filemanager')), 695 'description'=>lang('filemanagerdescription'),'show_in_menu'=>$this->HasPerm('filePerms')), 696 'images'=>array('url'=>'imagefiles.php','parent'=>'content', 697 'title'=>$this->FixSpaces(lang('imagemanager')), 698 'description'=>lang('imagemanagerdescription'),'show_in_menu'=>$this->HasPerm('filePerms')), 699 'blobs'=>array('url'=>'listhtmlblobs.php','parent'=>'content', 700 'title'=>$this->FixSpaces(lang('htmlblobs')), 701 'description'=>lang('htmlblobdescription'),'show_in_menu'=>$this->HasPerm('htmlPerms')), 702 'addhtmlblob'=>array('url'=>'addhtmlblob.php','parent'=>'blobs', 703 'title'=>$this->FixSpaces(lang('addhtmlblob')), 704 'description'=>lang('addhtmlblob'),'show_in_menu'=>false), 705 'edithtmlblob'=>array('url'=>'edithtmlblob.php','parent'=>'blobs', 706 'title'=>$this->FixSpaces(lang('edithtmlblob')), 707 'description'=>lang('edithtmlblob'),'show_in_menu'=>false), 708 // base layout menu --------------------------------------------------------- 709 'layout'=>array('url'=>'toplayout.php','parent'=>-1, 710 'title'=>$this->FixSpaces(lang('layout')), 711 'description'=>lang('layoutdescription'),'show_in_menu'=>$this->HasPerm('layoutPerms')), 712 'template'=>array('url'=>'listtemplates.php','parent'=>'layout', 713 'title'=>$this->FixSpaces(lang('templates')), 714 'description'=>lang('templatesdescription'),'show_in_menu'=>$this->HasPerm('templatePerms')), 715 'addtemplate'=>array('url'=>'addtemplate.php','parent'=>'template', 716 'title'=>$this->FixSpaces(lang('addtemplate')), 717 'description'=>lang('addtemplate'),'show_in_menu'=>false), 718 'edittemplate'=>array('url'=>'edittemplate.php','parent'=>'template', 719 'title'=>$this->FixSpaces(lang('edittemplate')), 720 'description'=>lang('edittemplate'),'show_in_menu'=>false), 721 'currentassociations'=>array('url'=>'listcssassoc.php','parent'=>'template', 722 'title'=>$this->FixSpaces(lang('currentassociations')), 723 'description'=>lang('currentassociations'),'show_in_menu'=>false), 724 'copytemplate'=>array('url'=>'copyemplate.php','parent'=>'template', 725 'title'=>$this->FixSpaces(lang('copytemplate')), 726 'description'=>lang('copytemplate'),'show_in_menu'=>false), 727 'stylesheets'=>array('url'=>'listcss.php','parent'=>'layout', 728 'title'=>$this->FixSpaces(lang('stylesheets')), 729 'description'=>lang('stylesheetsdescription'), 730 'show_in_menu'=>($this->HasPerm('cssPerms') || $this->HasPerm('cssAssocPerms'))), 731 'addcss'=>array('url'=>'addcss.php','parent'=>'stylesheets', 732 'title'=>$this->FixSpaces(lang('addstylesheet')), 733 'description'=>lang('addstylesheet'),'show_in_menu'=>false), 734 'editcss'=>array('url'=>'editcss.php','parent'=>'stylesheets', 735 'title'=>$this->FixSpaces(lang('editcss')), 736 'description'=>lang('editcss'),'show_in_menu'=>false), 737 'templatecss'=>array('url'=>'templatecss.php','parent'=>'stylesheets', 738 'title'=>$this->FixSpaces(lang('templatecss')), 739 'description'=>lang('templatecss'),'show_in_menu'=>false), 740 // base user/groups menu --------------------------------------------------------- 741 'usersgroups'=>array('url'=>'topusers.php','parent'=>-1, 742 'title'=>$this->FixSpaces(lang('usersgroups')), 743 'description'=>lang('usersgroupsdescription'),'show_in_menu'=>$this->HasPerm('usersGroupsPerms')), 744 'users'=>array('url'=>'listusers.php','parent'=>'usersgroups', 745 'title'=>$this->FixSpaces(lang('users')), 746 'description'=>lang('usersdescription'),'show_in_menu'=>$this->HasPerm('userPerms')), 747 'adduser'=>array('url'=>'adduser.php','parent'=>'users', 748 'title'=>$this->FixSpaces(lang('adduser')), 749 'description'=>lang('adduser'),'show_in_menu'=>false), 750 'edituser'=>array('url'=>'edituser.php','parent'=>'users', 751 'title'=>$this->FixSpaces(lang('edituser')), 752 'description'=>lang('edituser'),'show_in_menu'=>false), 753 'groups'=>array('url'=>'listgroups.php','parent'=>'usersgroups', 754 'title'=>$this->FixSpaces(lang('groups')), 755 'description'=>lang('groupsdescription'),'show_in_menu'=>$this->HasPerm('groupPerms')), 756 'addgroup'=>array('url'=>'addgroup.php','parent'=>'groups', 757 'title'=>$this->FixSpaces(lang('addgroup')), 758 'description'=>lang('addgroup'),'show_in_menu'=>false), 759 'editgroup'=>array('url'=>'editgroup.php','parent'=>'groups', 760 'title'=>$this->FixSpaces(lang('editgroup')), 761 'description'=>lang('editgroup'),'show_in_menu'=>false), 762 'groupmembers'=>array('url'=>'changegroupassign.php','parent'=>'usersgroups', 763 'title'=>$this->FixSpaces(lang('groupassignments')), 764 'description'=>lang('groupassignmentdescription'),'show_in_menu'=>$this->HasPerm('groupMemberPerms')), 765 'groupperms'=>array('url'=>'changegroupperm.php','parent'=>'usersgroups', 766 'title'=>$this->FixSpaces(lang('groupperms')), 767 'description'=>lang('grouppermsdescription'),'show_in_menu'=>$this->HasPerm('groupPermPerms')), 768 // base extensions menu --------------------------------------------------------- 769 'extensions'=>array('url'=>'topextensions.php','parent'=>-1, 770 'title'=>$this->FixSpaces(lang('extensions')), 771 'description'=>lang('extensionsdescription'),'show_in_menu'=>$this->HasPerm('extensionsPerms')), 772 'modules'=>array('url'=>'listmodules.php','parent'=>'extensions', 773 'title'=>$this->FixSpaces(lang('modules')), 774 'description'=>lang('moduledescription'),'show_in_menu'=>$this->HasPerm('modulePerms')), 775 'tags'=>array('url'=>'listtags.php','parent'=>'extensions', 776 'title'=>$this->FixSpaces(lang('tags')), 777 'description'=>lang('tagdescription'),'show_in_menu'=>true), 778 'eventhandlers'=>array('url'=>'eventhandlers.php','parent'=>'extensions', 779 'title'=>$this->FixSpaces(lang('eventhandlers')), 780 'description'=>lang('eventhandlerdescription'),'show_in_menu'=>$this->HasPerm('eventPerms')), 781 'editeventhandler'=>array('url'=>'editevent.php','parent'=>'eventhandlers', 782 'title'=>$this->FixSpaces(lang('editeventhandler')), 783 'description'=>lang('editeventshandler'),'show_in_menu'=>false), 784 'usertags'=>array('url'=>'listusertags.php','parent'=>'extensions', 785 'title'=>$this->FixSpaces(lang('usertags')), 786 'description'=>lang('usertagdescription'),'show_in_menu'=>$this->HasPerm('codeBlockPerms')), 787 'addusertag'=>array('url'=>'adduserplugin.php','parent'=>'usertags', 788 'title'=>$this->FixSpaces(lang('addusertag')), 789 'description'=>lang('addusertag'),'show_in_menu'=>false), 790 'editusertag'=>array('url'=>'edituserplugin.php','parent'=>'usertags', 791 'title'=>$this->FixSpaces(lang('editusertag')), 792 'description'=>lang('editusertag'),'show_in_menu'=>false), 793 // base admin menu --------------------------------------------------------- 794 'siteadmin'=>array('url'=>'topadmin.php','parent'=>-1, 795 'title'=>$this->FixSpaces(lang('admin')), 796 'description'=>lang('admindescription'),'show_in_menu'=>$this->HasPerm('siteAdminPerms')), 797 'siteprefs'=>array('url'=>'siteprefs.php','parent'=>'siteadmin', 798 'title'=>$this->FixSpaces(lang('globalconfig')), 799 'description'=>lang('preferencesdescription'),'show_in_menu'=>$this->HasPerm('sitePrefPerms')), 800 'adminlog'=>array('url'=>'adminlog.php','parent'=>'siteadmin', 801 'title'=>$this->FixSpaces(lang('adminlog')), 802 'description'=>lang('adminlogdescription'),'show_in_menu'=>$this->HasPerm('adminPerms')), 803 // base my prefs menu --------------------------------------------------------- 804 'myprefs'=>array('url'=>'topmyprefs.php','parent'=>-1, 805 'title'=>$this->FixSpaces(lang('myprefs')), 806 'description'=>lang('myprefsdescription'),'show_in_menu'=>true), 807 'myaccount'=>array('url'=>'edituser.php','parent'=>'myprefs', 808 'title'=>$this->FixSpaces(lang('myaccount')), 809 'description'=>lang('myaccountdescription'),'show_in_menu'=>true), 810 'preferences'=>array('url'=>'editprefs.php','parent'=>'myprefs', 811 'title'=>$this->FixSpaces(lang('adminprefs')), 812 'description'=>lang('adminprefsdescription'),'show_in_menu'=>true), 813 'managebookmarks'=>array('url'=>'listbookmarks.php','parent'=>'myprefs', 814 'title'=>$this->FixSpaces(lang('managebookmarks')), 815 'description'=>lang('managebookmarksdescription'),'show_in_menu'=>true), 816 'addbookmark'=>array('url'=>'addbookmark.php','parent'=>'myprefs', 817 'title'=>$this->FixSpaces(lang('addbookmark')), 818 'description'=>lang('addbookmark'),'show_in_menu'=>false), 819 'editbookmark'=>array('url'=>'editbookmark.php','parent'=>'myprefs', 820 'title'=>$this->FixSpaces(lang('editbookmark')), 821 'description'=>lang('editbookmark'),'show_in_menu'=>false), 822 // base view site menu --------------------------------------------------------- 823 'viewsite'=>array('url'=>'../','parent'=>-1, 824 'title'=>$this->FixSpaces(lang('viewsite')), 825 'description'=>'','show_in_menu'=>true, 'target'=>'_blank'), 826 // base logout menu --------------------------------------------------------- 827 'logout'=>array('url'=>'logout.php','parent'=>-1, 828 'title'=>$this->FixSpaces(lang('logout')), 829 'description'=>'','show_in_menu'=>true), 830 ); 831 832 // add in all of the 'system' modules todo 833 global $gCms; 834 foreach ($this->menuItems as $sectionKey=>$sectionArray) 835 { 836 $tmpArray = $this->MenuListSectionModules($sectionKey); 837 $first = true; 838 foreach ($tmpArray as $thisKey=>$thisVal) 839 { 840 $thisModuleKey = $thisKey; 841 $counter = 0; 842 843 // don't clobber existing keys 844 if (array_key_exists($thisModuleKey,$this->menuItems)) 845 { 846 while (array_key_exists($thisModuleKey,$this->menuItems)) 847 { 848 $thisModuleKey = $thisKey.$counter; 849 $counter++; 850 } 851 } 852 853 // if it's not a system module... 854 if (array_search($thisModuleKey, $gCms->cmssystemmodules) !== FALSE) 855 { 856 $this->menuItems[$thisModuleKey]=array('url'=>$thisVal['url'], 857 'parent'=>$sectionKey, 858 'title'=>$this->FixSpaces($thisVal['name']), 859 'description'=>$thisVal['description'], 860 'show_in_menu'=>true); 861 862 // Commenting out this code ensures that the module is thought of as (built in) 863 // if ($first) 864 // { 865 // $this->menuItems[$thisModuleKey]['firstmodule'] = 1; 866 // $first = false; 867 // } 868 // else 869 // { 870 // $this->menuItems[$thisModuleKey]['module'] = 1; 871 // } 872 } 873 } 874 } 875 876 // add in all of the modules 877 foreach ($this->menuItems as $sectionKey=>$sectionArray) 878 { 879 $tmpArray = $this->MenuListSectionModules($sectionKey); 880 $first = true; 881 foreach ($tmpArray as $thisKey=>$thisVal) 882 { 883 $thisModuleKey = $thisKey; 884 $counter = 0; 885 886 // don't clobber existing keys 887 if (array_key_exists($thisModuleKey,$this->menuItems)) 888 { 889 while (array_key_exists($thisModuleKey,$this->menuItems)) 890 { 891 $thisModuleKey = $thisKey.$counter; 892 $counter++; 893 } 894 if( $counter > 0 ) 895 { 896 continue; 897 } 898 } 899 $this->menuItems[$thisModuleKey]=array('url'=>$thisVal['url'], 900 'parent'=>$sectionKey, 901 'title'=>$this->FixSpaces($thisVal['name']), 902 'description'=>$thisVal['description'], 903 'show_in_menu'=>true); 904 if ($first) 905 { 906 $this->menuItems[$thisModuleKey]['firstmodule'] = 1; 907 $first = false; 908 } 909 else 910 { 911 $this->menuItems[$thisModuleKey]['module'] = 1; 912 } 913 } 914 } 915 916 // resolve the tree to be doubly-linked, 917 // and make sure the selections are selected 918 foreach ($this->menuItems as $sectionKey=>$sectionArray) 919 { 920 // link the children to the parents; a little clumsy since we can't 921 // assume php5-style references in a foreach. 922 $this->menuItems[$sectionKey]['children'] = array(); 923 foreach ($this->menuItems as $subsectionKey=>$subsectionArray) 924 { 925 if ($subsectionArray['parent'] == $sectionKey) 926 { 927 $this->menuItems[$sectionKey]['children'][] = $subsectionKey; 928 } 929 } 930 // set selected 931 if ($this->script == 'moduleinterface.php') 932 { 933 $a = preg_match('/(module|mact)=([^&,]+)/',$this->query,$matches); 934 if ($a > 0 && $matches[2] == $sectionKey) 935 { 936 $this->menuItems[$sectionKey]['selected'] = true; 937 $this->title .= $sectionArray['title']; 938 if ($sectionArray['parent'] != -1) 939 { 940 $parent = $sectionArray['parent']; 941 while ($parent != -1) 942 { 943 $this->menuItems[$parent]['selected'] = true; 944 $parent = $this->menuItems[$parent]['parent']; 945 } 946 } 947 } 948 else 949 { 950 $this->menuItems[$sectionKey]['selected'] = false; 951 } 952 } 953 else if ($sectionArray['url'] == $this->script) 954 { 955 $this->menuItems[$sectionKey]['selected'] = true; 956 $this->title .= $sectionArray['title']; 957 if ($sectionArray['parent'] != -1) 958 { 959 $parent = $sectionArray['parent']; 960 while ($parent != -1) 961 { 962 $this->menuItems[$parent]['selected'] = true; 963 $parent = $this->menuItems[$parent]['parent']; 964 } 965 } 966 } 967 else 968 { 969 $this->menuItems[$sectionKey]['selected'] = false; 970 } 971 } 972 // fix subtitle, if any 973 if ($subtitle != '') 974 { 975 $this->title .= ': '.$subtitle; 976 } 977 // generate breadcrumb array 978 979 $count = 0; 980 foreach ($this->menuItems as $key=>$menuItem) 981 { 982 if ($menuItem['selected']) 983 { 984 $this->breadcrumbs[] = array('title'=>$menuItem['title'], 'url'=>$menuItem['url']); 985 $count++; 986 } 987 } 988 if ($count > 0) 989 { 990 // and fix up the last breadcrumb... 991 if ($this->query != '' && strpos($this->breadcrumbs[$count-1]['url'],'?') === false) 992 { 993 $this->query = preg_replace('/\&/','&',$this->query); 994 $this->breadcrumbs[$count-1]['url'] .= '?'.$this->query; 995 } 996 if ($this->subtitle != '') 997 { 998 $this->breadcrumbs[$count-1]['title'] .= ': '.$this->subtitle; 999 } 1000 } 1001 } 1002 1003 /** 1004 * BackUrl 1005 * "Back" Url - link to the next-to-last item in the breadcrumbs 1006 * for the back button. 1007 */ 1008 function BackUrl() 1009 { 1010 $count = count($this->breadcrumbs) - 2; 1011 if ($count > -1) 1012 { 1013 return $this->breadcrumbs[$count]['url']; 1014 } 1015 else 1016 { 1017 return ''; 1018 } 1019 } 1020 1021 /** 1022 * DoTopMenu 1023 * Setup function for displaying the top menu. 1024 * 1025 */ 1026 function DoTopMenu() 1027 { 1028 $this->DisplayTopMenu(); 1029 } 1030 1031 /** 1032 * DisplaySectionPages 1033 * Shows admin section pages in the specified section, wrapped in a 1034 * MainMenuItem div. This is used in the top-level section pages. 1035 * 1036 * You can override this if you want to change the 1037 * way it is shown. 1038 * 1039 * @param section - section to display 1040 */ 1041 function DisplaySectionPages($section) 1042 { 1043 if (count($this->menuItems) < 1) 1044 { 1045 // menu should be initialized before this gets called. 1046 // TODO: try to do initialization. 1047 // Problem: current page selection, url, etc? 1048 return -1; 1049 } 1050 1051 foreach ($this->menuItems[$section]['children'] as $thisChild) 1052 { 1053 $thisItem = $this->menuItems[$thisChild]; 1054 if (! $thisItem['show_in_menu'] || strlen($thisItem['url']) < 1) 1055 { 1056 continue; 1057 } 1058 1059 echo "<div class=\"MainMenuItem\">\n"; 1060 echo "<a href=\"".$thisItem['url']."\""; 1061 if (array_key_exists('target', $thisItem)) 1062 { 1063 echo " target=" . $thisItem['target']; 1064 } 1065 if ($thisItem['selected']) 1066 { 1067 echo " class=\"selected\""; 1068 } 1069 echo ">".$thisItem['title']."</a>\n"; 1070 if (isset($thisItem['description']) && strlen($thisItem['description']) > 0) 1071 { 1072 echo "<span class=\"description\">"; 1073 echo $thisItem['description']; 1074 echo "</span>\n"; 1075 } 1076 echo "</div>\n"; 1077 } 1078 } 1079 1080 /** 1081 * HasDisplayableChildren 1082 * This method returns a boolean, based upon whether the section in question 1083 * has displayable children. 1084 * 1085 * @param section - section to test 1086 */ 1087 function HasDisplayableChildren($section) 1088 { 1089 $displayableChildren=false; 1090 foreach($this->menuItems[$section]['children'] as $thisChild) 1091 { 1092 $thisItem = $this->menuItems[$thisChild]; 1093 if ($thisItem['show_in_menu']) 1094 { 1095 $displayableChildren = true; 1096 } 1097 } 1098 return $displayableChildren; 1099 } 1100 1101 /** 1102 * TopParent 1103 * This method returns the menu node that is the top-level parent of the node you pass 1104 * to it. 1105 * 1106 * @param section - section (menu tag) to find top-level parent 1107 */ 1108 function TopParent($section) 1109 { 1110 $next = $section; 1111 $node = $this->menuItems[$next]; 1112 while ($node['parent'] != -1) 1113 { 1114 $next = $node['parent']; 1115 $node = $this->menuItems[$next]; 1116 } 1117 return $next; 1118 } 1119 1120 1121 /** 1122 * ListSectionPages 1123 * This method presents a nice, human-readable list of admin pages and 1124 * modules that are in the specified admin section. 1125 * 1126 * 1127 * @param section - section to display 1128 */ 1129 function ListSectionPages($section) 1130 { 1131 if (! isset($this->menuItems[$section]['children']) || count($this->menuItems[$section]['children']) < 1) 1132 { 1133 return; 1134 } 1135 1136 if ($this->HasDisplayableChildren($section)) 1137 { 1138 echo " ".lang('subitems').": "; 1139 $count = 0; 1140 foreach($this->menuItems[$section]['children'] as $thisChild) 1141 { 1142 $thisItem = $this->menuItems[$thisChild]; 1143 if (! $thisItem['show_in_menu'] || strlen($thisItem['url']) < 1) 1144 { 1145 continue; 1146 } 1147 if ($count++ > 0) 1148 { 1149 echo ", "; 1150 } 1151 echo "<a href=\"".$thisItem['url']; 1152 echo "\">".$thisItem['title']."</a>"; 1153 } 1154 } 1155 } 1156 1157 1158 1159 /** 1160 * DisplayAllSectionPages 1161 * 1162 * Shows all admin section pages and modules. This is used to display the 1163 * admin "main" page. 1164 * 1165 */ 1166 function DisplayAllSectionPages() 1167 { 1168 if (count($this->menuItems) < 1) 1169 { 1170 // menu should be initialized before this gets called. 1171 // TODO: try to do initialization. 1172 // Problem: current page selection, url, etc? 1173 return -1; 1174 } 1175 foreach ($this->menuItems as $thisSection=>$menuItem) 1176 { 1177 if ($menuItem['parent'] != -1) 1178 { 1179 continue; 1180 } 1181 if (! $menuItem['show_in_menu']) 1182 { 1183 continue; 1184 } 1185 echo "<div class=\"MainMenuItem\">\n"; 1186 echo "<a href=\"".$menuItem['url']."\""; 1187 if (array_key_exists('target', $menuItem)) 1188 { 1189 echo " target=" . $menuItem['target']; 1190 } 1191 if ($menuItem['selected']) 1192 { 1193 echo " class=\"selected\""; 1194 } 1195 echo ">".$menuItem['title']."</a>\n"; 1196 echo "<span class=\"description\">"; 1197 if (isset($menuItem['description']) && strlen($menuItem['description']) > 0) 1198 { 1199 echo $menuItem['description']; 1200 } 1201 $this->ListSectionPages($thisSection); 1202 echo "</span>\n"; 1203 echo "</div>\n"; 1204 } 1205 } 1206 1207 1208 1209 function renderMenuSection($section, $depth, $maxdepth) 1210 { 1211 if ($maxdepth > 0 && $depth> $maxdepth) 1212 { 1213 return; 1214 } 1215 if (! $this->menuItems[$section]['show_in_menu']) 1216 { 1217 return; 1218 } 1219 if (strlen($this->menuItems[$section]['url']) < 1) 1220 { 1221 echo "<li>".$this->menuItems[$section]['title']."</li>"; 1222 return; 1223 } 1224 echo "<li><a href=\""; 1225 echo $this->menuItems[$section]['url']; 1226 echo "\""; 1227 if (array_key_exists('target', $this->menuItems[$section])) 1228 { 1229 echo " target=" . $this->menuItems[$section]['target']; 1230 } 1231 if ($this->menuItems[$section]['selected']) 1232 { 1233 echo " class=\"selected\""; 1234 } 1235 echo ">"; 1236 echo $this->menuItems[$section]['title']; 1237 echo "</a>"; 1238 if ($this->HasDisplayableChildren($section)) 1239 { 1240 echo "<ul>"; 1241 foreach ($this->menuItems[$section]['children'] as $child) 1242 { 1243 $this->renderMenuSection($child, $depth+1, $maxdepth); 1244 } 1245 echo "</ul>"; 1246 } 1247 echo "</li>"; 1248 return; 1249 } 1250 1251 1252 /** 1253 * DisplayTopMenu 1254 * Output Top Menu data. Over-ride this to alter display of the top menu. 1255 * 1256 * @param menuItems an array of associated items; each element has a section, title, 1257 * url, and selection where title and url are strings, and selection is a boolean 1258 * to indicate this is the current selection. You can use the "section" to trap for 1259 * javascript links, etc. 1260 * 1261 * Cruftily written to only support a depth of two levels 1262 * 1263 */ 1264 function DisplayTopMenu() 1265 { 1266 echo "<div id=\"TopMenu\"><ul id=\"nav\">\n"; 1267 foreach ($this->menuItems as $key=>$menuItem) 1268 { 1269 if ($menuItem['parent'] == -1) 1270 { 1271 $this->renderMenuSection($key, 0, -1); 1272 } 1273 } 1274 echo "</ul></div>\n"; 1275 } 1276 1277 /** 1278 * DisplayFooter 1279 * Displays an end-of-page footer. 1280 */ 1281 function DisplayFooter() 1282 { 1283 ?> 1284 <div id="Footer"> 1285 <a href="http://www.cmsmadesimple.org">CMS Made Simple</a> is Free Software released under the GNU/GPL License 1286 </div> 1287 <?php 1288 } 1289 1290 1291 /** 1292 * DisplayDocType 1293 * If you rewrite the admin section to output pure, beautiful, unadulterated XHTML, you can 1294 * change the body tag so that it proudly proclaims that there is none of the evil transitional 1295 * cruft. 1296 */ 1297 function DisplayDocType() 1298 { 1299 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; 1300 } 1301 1302 /** 1303 * DisplayHTMLStartTag 1304 * Outputs the html open tag. Override at your own risk :) 1305 */ 1306 function DisplayHTMLStartTag() 1307 { 1308 echo $this->cms->nls['direction'] == 'rtl' ? "<html dir=\"rtl\"\n>" : "<html>\n"; 1309 } 1310 1311 /** 1312 * DisplayHTMLHeader 1313 * This method outputs the HEAD section of the html page in the admin section. 1314 */ 1315 function DisplayHTMLHeader($showielink = false, $addt = '') 1316 { 1317 global $gCms; 1318 $config =& $gCms->GetConfig(); 1319 ?><head> 1320 <meta name="Generator" content="CMS Made Simple - Copyright (C) 2004-6 Ted Kulp. All rights reserved." /> 1321 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 1322 <meta name="robots" content="noindex, nofollow" /> 1323 <title><?php echo $this->title ?></title> 1324 <link rel="stylesheet" type="text/css" href="style.php" /> 1325 <?php 1326 if ($showielink) { 1327 ?> 1328 <!--[if IE]> 1329 <link rel="stylesheet" type="text/css" href="style.php?ie=1" /> 1330 <![endif]--> 1331 <?php 1332 } 1333 ?> 1334 <!-- THIS IS WHERE HEADER STUFF SHOULD GO --> 1335 <?php $this->OutputHeaderJavascript(); ?> 1336 <?php echo $addt ?> 1337 <base href="<?php echo $config['root_url'] . '/' . $config['admin_dir'] . '/'; ?>" /> 1338 </head> 1339 <?php 1340 } 1341 1342 /** 1343 * DisplayBodyTag 1344 * Outputs the admin page body tag. Leave in the funny text if you want this 1345 * to work properly. 1346 */ 1347 function DisplayBodyTag() 1348 { 1349 echo "<body##BODYSUBMITSTUFFGOESHERE##>\n"; 1350 } 1351 1352 1353 /** 1354 * DisplayMainDivStart 1355 * 1356 * Used to output the start of the main div that contains the admin page content 1357 */ 1358 function DisplayMainDivStart() 1359 { 1360 echo "<div id=\"MainContent\">\n"; 1361 } 1362 1363 1364 /** 1365 * DisplayMainDivEnd 1366 * 1367 * Used to output the end of the main div that contains the admin page content 1368 */ 1369 function DisplayMainDivEnd() 1370 { 1371 echo '<div class="clearb"></div>'; 1372 echo "</div><!-- end MainContent -->\n"; 1373 } 1374 1375 1376 /** 1377 * DisplaySectionMenuDivStart 1378 * Outputs the open div tag for the main section pages. 1379 */ 1380 function DisplaySectionMenuDivStart() 1381 { 1382 echo "<div class=\"MainMenu\">\n"; 1383 } 1384 1385 1386 /** 1387 * DisplaySectionMenuDivEnd 1388 * Outputs the close div tag for the main section pages. 1389 */ 1390 function DisplaySectionMenuDivEnd() 1391 { 1392 echo "</div>\n"; 1393 } 1394 1395 1396 /** 1397 * DisplayDashboardCallout 1398 * Outputs warning if the install directory is still there. 1399 * 1400 * @param file file or dir to check for 1401 * @param message to display if it does exist 1402 */ 1403 function DisplayDashboardCallout($file, $message = '') 1404 { 1405 if ($message == '') 1406 $message = lang('installdirwarning'); 1407 echo "<div class=\"DashboardCallout\">\n"; 1408 if (file_exists($file)) 1409 { 1410 echo '<p>'.$message.'</p>'; 1411 } 1412 echo "</div> <!-- end DashboardCallout -->\n"; 1413 } 1414 1415 /** 1416 * DisplayImage will display the themed version of an image (if it exists), 1417 * or the version from the default theme otherwise. 1418 * @param imageName - name of image 1419 * @param alt - alt text 1420 * @param width 1421 * @param height 1422 */ 1423 function DisplayImage($imageName, $alt='', $width='', $height='', $class='') 1424 { 1425 if (! isset($this->imageLink[$imageName])) 1426 { 1427 if (strpos($imageName,'/') !== false) 1428 { 1429 $imagePath = substr($imageName,0,strrpos($imageName,'/')+1); 1430 $imageName = substr($imageName,strrpos($imageName,'/')+1); 1431 } 1432 else 1433 { 1434 $imagePath = ''; 1435 } 1436 1437 if (file_exists(dirname($this->cms->config['root_path'] . '/' . $this->cms->config['admin_dir'] . 1438 '/themes/' . $this->themeName . '/images/' . $imagePath . $imageName) . '/'. $imageName)) 1439 { 1440 $this->imageLink[$imageName] = 'themes/' . 1441 $this->themeName . '/images/' . $imagePath . $imageName; 1442 } 1443 else 1444 { 1445 $this->imageLink[$imageName] = 'themes/default/images/' . $imagePath . $imageName; 1446 } 1447 } 1448 1449 $retStr = '<img src="'.$this->imageLink[$imageName].'"'; 1450 if ($class != '') 1451 { 1452 $retStr .= ' class="'.$class.'"'; 1453 } 1454 if ($width != '') 1455 { 1456 $retStr .= ' width="'.$width.'"'; 1457 } 1458 if ($height != '') 1459 { 1460 $retStr .= ' height="'.$height.'"'; 1461 } 1462 if ($alt != '') 1463 { 1464 $retStr .= ' alt="'.$alt.'" title="'.$alt.'"'; 1465 } 1466 $retStr .= ' />'; 1467 return $retStr; 1468 } 1469 1470 1471 /** 1472 * ShowHeader 1473 * Outputs the page header title along with a help link to that section in the wiki. 1474 * 1475 * @param title_name - page heading title 1476 * @param extra_lang_param - extra parameters to pass to lang() (I don't think this parm is needed) 1477 * @param link_text - Override the text to use for the help link. 1478 * @param module_help_type - FALSE if this is not a module, 'both' if link to 1479 * both the wiki and module help and 'builtin' if link to to the builtin help 1480 */ 1481 function ShowHeader($title_name, $extra_lang_param=array(), $link_text = '', $module_help_type = FALSE) 1482 { 1483 $cms = $this->cms; 1484 $config = $cms->GetConfig(); 1485 $header = '<div class="pageheader">'; 1486 if (FALSE != $module_help_type) 1487 { 1488 $header .= $title_name; 1489 } 1490 else 1491 { 1492 $header .= lang($title_name, $extra_lang_param); 1493 } 1494 if (FALSE == empty($this->breadcrumbs)) 1495 { 1496 $wikiUrl = $config['wiki_url']; 1497 // Include English translation of titles. (Can't find better way to get them) 1498 $dirname = dirname(__FILE__); 1499 include($dirname.'/../../'.$this->cms->config['admin_dir'].'/lang/en_US/admin.inc.php'); 1500 foreach ($this->breadcrumbs AS $key => $value) 1501 { 1502 $title = $value['title']; 1503 // If this is a module and the last part of the breadcrumbs 1504 if (FALSE != $module_help_type && TRUE == empty($this->breadcrumbs[$key + 1])) 1505 { 1506 $help_title = $title; 1507 if (FALSE == empty($_GET['module'])) 1508 { 1509 $module_name = $_GET['module']; 1510 } 1511 else 1512 { 1513 $module_name = substr($_REQUEST['mact'], 0, strpos($_REQUEST['mact'], ',')); 1514 } 1515 // Turn ModuleName into _Module_Name 1516 $moduleName = preg_replace('/([A-Z])/', "_$1", $module_name); 1517 $moduleName = preg_replace('/_([A-Z])_/', "$1", $moduleName); 1518 if ($moduleName{0} == '_') 1519 { 1520 $moduleName = substr($moduleName, 1); 1521 } 1522 $wikiUrl .= '/'.$moduleName; 1523 } else { 1524 // Remove colon and following (I.E. Turn "Edit Page: Title" into "Edit Page") 1525 $colonLocation = strrchr($title, ':'); 1526 if ($colonLocation !== false) 1527 { 1528 $title = substr($title,0,strpos($title,':')); 1529 } 1530 // Get the key of the title so we can use the en_US version for the URL 1531 $title_key = $this->_ArraySearchRecursive($title, $this->menuItems); 1532 $wikiUrl .= '/'.$lang['admin'][$title_key[0]]; 1533 $help_title = $title; 1534 } 1535 } 1536 if (FALSE == get_preference($this->userid, 'hide_help_links')) { 1537 // Clean up URL 1538 $wikiUrl = str_replace(' ', '_', $wikiUrl); 1539 $wikiUrl = str_replace('&', 'and', $wikiUrl); 1540 // Make link to go the translated version of page if lang is not en_US 1541 /* Disabled as suggested by westis 1542 $lang = get_preference($this->cms->variables['user_id'], 'default_cms_language'); 1543 if ($lang != 'en_US') { 1544 $wikiUrl .= '/'.substr($lang, 0, 2); 1545 } 1546 */ 1547 if (FALSE == empty($link_text)) 1548 { 1549 $help_title = $link_text; 1550 } 1551 else 1552 { 1553 $help_title = lang('help_external'); 1554 } 1555 $image_help = $this->DisplayImage('icons/system/info.gif', lang('help'),'','','systemicon'); 1556 $image_help_external = $this->DisplayImage('icons/system/info-external.gif', lang('help'),'','','systemicon'); 1557 if ('both' == $module_help_type) 1558 { 1559 $module_help_link = $config['root_url'].'/'.$config['admin_dir'].'/listmodules.php?action=showmodulehelp&module='.$module_name; 1560 $header .= '<span class="helptext"><a href="'.$module_help_link.'">'.$image_help.'</a> <a href="'.$module_help_link.'">'.lang('help').'</a> | '; 1561 $header .= '<a href="'.$wikiUrl.'" target="_blank">'.$image_help_external.'</a> <a href="'.$wikiUrl.'" target="_blank">'.lang('wikihelp').'</a> ('.lang('new_window').')</span>'; 1562 } 1563 else 1564 { 1565 $header .= '<span class="helptext"><a href="'.$wikiUrl.'" target="_blank">'.$image_help_external.'</a> <a href="'.$wikiUrl.'" target="_blank">'.lang('help').'</a> ('.lang('new_window').')</span>'; 1566 } 1567 } 1568 } 1569 $header .= '</div>'; 1570 return $header; 1571 } 1572 1573 1574 /** 1575 * _ArraySearchRecursive 1576 * recursively descend an arbitrarily deep multidimensional 1577 * array, stopping at the first occurence of scalar $needle. 1578 * return the path to $needle as an array (list) of keys 1579 * if not found, return null. 1580 * (will infinitely recurse on self-referential structures) 1581 * From: http://us3.php.net/function.array-search 1582 */ 1583 function _ArraySearchRecursive($needle, $haystack) 1584 { 1585 $path = NULL; 1586 $keys = array_keys($haystack); 1587 while (!$path && (list($toss,$k)=each($keys))) { 1588 $v = $haystack[$k]; 1589 if (is_scalar($v)) { 1590 if ($v===$needle) { 1591 $path = array($k); 1592 } 1593 } elseif (is_array($v)) { 1594 if ($path=$this->_ArraySearchRecursive( $needle, $v )) { 1595 array_unshift($path,$k); 1596 } 1597 } 1598 } 1599 return $path; 1600 } 1601 1602 1603 /** 1604 * ShowError 1605 * Outputs supplied errors with a link to the wiki for troublshooting. 1606 * 1607 * @param errors - array or string of 1 or more errors to be shown 1608 * @param get_var - Name of the _GET variable that contains the 1609 * name of the message lang string 1610 */ 1611 function ShowErrors($errors, $get_var = '') 1612 { 1613 global $gCms; 1614 $config =& $gCms->GetConfig(); 1615 $wikiUrl = $config['wiki_url']; 1616 1617 if (FALSE == empty($_REQUEST['module']) || FALSE == empty($_REQUEST['mact'])) 1618 { 1619 if (FALSE == empty($_REQUEST['module'])) 1620 { 1621 $wikiUrl .= '/'.$_REQUEST['module']; 1622 } 1623 else 1624 { 1625 $wikiUrl .= '/'.substr($_REQUEST['mact'], 0, strpos($_REQUEST['mact'], ',')); 1626 } 1627 } 1628 $wikiUrl .= '/Troubleshooting'; 1629 $image_error = $this->DisplayImage('icons/system/stop.gif', lang('error'),'','','systemicon'); 1630 $output = '<div class="pageerrorcontainer"'; 1631 if (FALSE == empty($get_var)) 1632 { 1633 if (FALSE == empty($_GET[$get_var])) 1634 { 1635 $errors = cleanValue(lang(cleanValue($_GET[$get_var]))); 1636 } 1637 else 1638 { 1639 $errors = ''; 1640 $output .= ' style="display:none;"'; 1641 } 1642 } 1643 $output .= '><div class="pageoverflow">'; 1644 if (FALSE != is_array($errors)) 1645 { 1646 $output .= '<ul class="pageerror">'; 1647 foreach ($errors as $oneerror) 1648 { 1649 $output .= '<li>'.$oneerror.'</li>'; 1650 } 1651 $output .= '</ul>'; 1652 } 1653 else 1654 { 1655 $output .= $image_error.' '.$errors; 1656 } 1657 $output .= ' <a href="'.$wikiUrl.'" target="_blank">'.lang('troubleshooting').'</a></div></div>'; 1658 1659 return $output; 1660 } 1661 1662 /** 1663 * ShowMessage 1664 * Outputs a page status message 1665 * 1666 * @param message - Message to be shown 1667 * @param get_var - Name of the _GET variable that contains the 1668 * name of the message lang string 1669 */ 1670 function ShowMessage($message, $get_var = '') 1671 { 1672 $image_done = $this->DisplayImage('icons/system/accept.gif', lang('success'), '','','systemicon'); 1673 $output = '<div class="pagemcontainer"'; 1674 if (FALSE == empty($get_var)) 1675 { 1676 if (FALSE == empty($_GET[$get_var])) 1677 { 1678 $message = lang(cleanValue($_GET[$get_var])); 1679 } 1680 else 1681 { 1682 $message = ''; 1683 $output .= ' style="display:none;"'; 1684 } 1685 } 1686 $output .= '><p class="pagemessage">'.$image_done.' '.$message.'</p></div>'; 1687 return $output; 1688 } 1689 1690 function &GetThemeObject() 1691 { 1692 global $gCms; 1693 $config =& $gCms->GetConfig(); 1694 $themeName = get_preference(get_userid(), 'admintheme', 'default'); 1695 $themeObjectName = $themeName."Theme"; 1696 $userid = get_userid(); 1697 1698 if (file_exists(dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.$config['admin_dir']."/themes/$themeName}/$themeObjectName}.php")) 1699 { 1700 include(dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.$config['admin_dir']."/themes/$themeName}/$themeObjectName}.php"); 1701 $themeObject = new $themeObjectName($gCms, $userid, $themeName); 1702 } 1703 else 1704 { 1705 $themeObject = new AdminTheme($gCms, $userid, $themeName); 1706 } 1707 1708 $gCms->variables['admintheme']=&$themeObject; 1709 1710 return $themeObject; 1711 1712 } 1713 1714 } 1715 1716 # vim:ts=4 sw=4 noet 1717 ?>
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 |