[ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: admin.templates.php 5015 2006-09-11 23:59:27Z friesengeist $ 4 * @package Joomla 5 * @subpackage Templates 6 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved. 7 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant 9 * to the GNU General Public License, and as distributed it includes or 10 * is derivative of works licensed under the GNU General Public License or 11 * other free or open source software licenses. 12 * See COPYRIGHT.php for copyright notices and details. 13 */ 14 15 // no direct access 16 defined( '_VALID_MOS' ) or die( 'Restricted access' ); 17 18 // ensure user has access to this function 19 if (!$acl->acl_check( 'administration', 'manage', 'users', $GLOBALS['my']->usertype, 'components', 'com_templates' )) { 20 mosRedirect( 'index2.php', _NOT_AUTH ); 21 } 22 23 require_once( $mainframe->getPath( 'admin_html' ) ); 24 require_once ( $mosConfig_absolute_path .'/administrator/components/com_templates/admin.templates.class.php' ); 25 // XML library 26 require_once ( $mosConfig_absolute_path .'/includes/domit/xml_domit_lite_include.php' ); 27 28 $client = strval( mosGetParam( $_REQUEST, 'client', '' ) ); 29 30 $cid = mosGetParam( $_REQUEST, 'cid', array(0) ); 31 if (!is_array( $cid )) { 32 $cid = array(0); 33 } 34 if (get_magic_quotes_gpc()) { 35 $cid[0] = stripslashes( $cid[0] ); 36 } 37 38 switch ($task) { 39 case 'new': 40 mosRedirect ( 'index2.php?option=com_installer&element=template&client='. $client ); 41 break; 42 43 case 'edit_source': 44 editTemplateSource( $cid[0], $option, $client ); 45 break; 46 47 case 'save_source': 48 saveTemplateSource( $option, $client ); 49 break; 50 51 case 'edit_css': 52 editTemplateCSS( $cid[0], $option, $client ); 53 break; 54 55 case 'save_css': 56 saveTemplateCSS( $option, $client ); 57 break; 58 59 case 'remove': 60 removeTemplate( $cid[0], $option, $client ); 61 break; 62 63 case 'publish': 64 defaultTemplate( $cid[0], $option, $client ); 65 break; 66 67 case 'default': 68 defaultTemplate( $cid[0], $option, $client ); 69 break; 70 71 case 'assign': 72 assignTemplate( $cid[0], $option, $client ); 73 break; 74 75 case 'save_assign': 76 saveTemplateAssign( $option, $client ); 77 break; 78 79 case 'cancel': 80 mosRedirect( 'index2.php?option='. $option .'&client='. $client ); 81 break; 82 83 case 'positions': 84 editPositions( $option ); 85 break; 86 87 case 'save_positions': 88 savePositions( $option ); 89 break; 90 91 default: 92 viewTemplates( $option, $client ); 93 break; 94 } 95 96 97 /** 98 * Compiles a list of installed, version 4.5+ templates 99 * 100 * Based on xml files found. If no xml file found the template 101 * is ignored 102 */ 103 function viewTemplates( $option, $client ) { 104 global $database, $mainframe; 105 global $mosConfig_absolute_path, $mosConfig_list_limit; 106 107 $limit = $mainframe->getUserStateFromRequest( 'viewlistlimit', 'limit', $mosConfig_list_limit ); 108 $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ); 109 110 if ($client == 'admin') { 111 $templateBaseDir = mosPathName( $mosConfig_absolute_path . '/administrator/templates' ); 112 } else { 113 $templateBaseDir = mosPathName( $mosConfig_absolute_path . '/templates' ); 114 } 115 116 $rows = array(); 117 // Read the template dir to find templates 118 $templateDirs = mosReadDirectory($templateBaseDir); 119 120 $id = intval( $client == 'admin' ); 121 122 if ($client=='admin') { 123 $query = "SELECT template" 124 . "\n FROM #__templates_menu" 125 . "\n WHERE client_id = 1" 126 . "\n AND menuid = 0" 127 ; 128 $database->setQuery( $query ); 129 } else { 130 $query = "SELECT template" 131 . "\n FROM #__templates_menu" 132 . "\n WHERE client_id = 0" 133 . "\n AND menuid = 0" 134 ; 135 $database->setQuery( $query ); 136 } 137 $cur_template = $database->loadResult(); 138 139 $rowid = 0; 140 // Check that the directory contains an xml file 141 foreach($templateDirs as $templateDir) { 142 $dirName = mosPathName($templateBaseDir . $templateDir); 143 $xmlFilesInDir = mosReadDirectory($dirName,'.xml$'); 144 145 foreach($xmlFilesInDir as $xmlfile) { 146 // Read the file to see if it's a valid template XML file 147 $xmlDoc = new DOMIT_Lite_Document(); 148 $xmlDoc->resolveErrors( true ); 149 if (!$xmlDoc->loadXML( $dirName . $xmlfile, false, true )) { 150 continue; 151 } 152 153 $root = &$xmlDoc->documentElement; 154 155 if ($root->getTagName() != 'mosinstall') { 156 continue; 157 } 158 if ($root->getAttribute( 'type' ) != 'template') { 159 continue; 160 } 161 162 $row = new StdClass(); 163 $row->id = $rowid; 164 $row->directory = $templateDir; 165 $element = &$root->getElementsByPath('name', 1 ); 166 $row->name = $element->getText(); 167 168 $element = &$root->getElementsByPath('creationDate', 1); 169 $row->creationdate = $element ? $element->getText() : 'Unknown'; 170 171 $element = &$root->getElementsByPath('author', 1); 172 $row->author = $element ? $element->getText() : 'Unknown'; 173 174 $element = &$root->getElementsByPath('copyright', 1); 175 $row->copyright = $element ? $element->getText() : ''; 176 177 $element = &$root->getElementsByPath('authorEmail', 1); 178 $row->authorEmail = $element ? $element->getText() : ''; 179 180 $element = &$root->getElementsByPath('authorUrl', 1); 181 $row->authorUrl = $element ? $element->getText() : ''; 182 183 $element = &$root->getElementsByPath('version', 1); 184 $row->version = $element ? $element->getText() : ''; 185 186 // Get info from db 187 if ($cur_template == $templateDir) { 188 $row->published = 1; 189 } else { 190 $row->published = 0; 191 } 192 193 $row->checked_out = 0; 194 $row->mosname = strtolower( str_replace( ' ', '_', $row->name ) ); 195 196 // check if template is assigned 197 $query = "SELECT COUNT(*)" 198 . "\n FROM #__templates_menu" 199 . "\n WHERE client_id = 0" 200 . "\n AND template = " . $database->Quote( $row->directory ) 201 . "\n AND menuid != 0" 202 ; 203 $database->setQuery( $query ); 204 $row->assigned = $database->loadResult() ? 1 : 0; 205 206 $rows[] = $row; 207 $rowid++; 208 } 209 } 210 211 require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' ); 212 $pageNav = new mosPageNav( count( $rows ), $limitstart, $limit ); 213 214 $rows = array_slice( $rows, $pageNav->limitstart, $pageNav->limit ); 215 216 HTML_templates::showTemplates( $rows, $pageNav, $option, $client ); 217 } 218 219 220 /** 221 * Publish, or make current, the selected template 222 */ 223 function defaultTemplate( $p_tname, $option, $client ) { 224 global $database; 225 226 if ($client=='admin') { 227 $query = "DELETE FROM #__templates_menu" 228 . "\n WHERE client_id = 1" 229 . "\n AND menuid = 0" 230 ; 231 $database->setQuery( $query ); 232 $database->query(); 233 234 $query = "INSERT INTO #__templates_menu" 235 . "\n SET client_id = 1, template = " . $database->Quote( $p_tname ) . ", menuid = 0" 236 ; 237 $database->setQuery( $query ); 238 $database->query(); 239 } else { 240 $query = "DELETE FROM #__templates_menu" 241 . "\n WHERE client_id = 0" 242 . "\n AND menuid = 0" 243 ; 244 $database->setQuery( $query ); 245 $database->query(); 246 247 $query = "INSERT INTO #__templates_menu" 248 . "\n SET client_id = 0, template = " . $database->Quote( $p_tname ) . ", menuid = 0" 249 ; 250 $database->setQuery( $query ); 251 $database->query(); 252 253 $_SESSION['cur_template'] = $p_tname; 254 } 255 256 mosRedirect('index2.php?option='. $option .'&client='. $client); 257 } 258 259 /** 260 * Remove the selected template 261 */ 262 function removeTemplate( $cid, $option, $client ) { 263 global $database; 264 265 $client_id = $client=='admin' ? 1 : 0; 266 267 $query = "SELECT template" 268 . "\n FROM #__templates_menu" 269 . "\n WHERE client_id = " . (int) $client_id 270 . "\n AND menuid = 0" 271 ; 272 $database->setQuery( $query ); 273 $cur_template = $database->loadResult(); 274 275 if ($cur_template == $cid) { 276 mosErrorAlert( "You can not delete template in use" ); 277 } 278 279 // Un-assign 280 $query = "DELETE FROM #__templates_menu" 281 . "\n WHERE template = " . $database->Quote( $cid ) 282 . "\n AND client_id = " . (int) $client_id 283 . "\n AND menuid != 0" 284 ; 285 $database->setQuery( $query ); 286 $database->query(); 287 288 mosRedirect( 'index2.php?option=com_installer&element=template&client='. $client .'&task=remove&cid[]='. $cid ); 289 } 290 291 function editTemplateSource( $p_tname, $option, $client ) { 292 global $mosConfig_absolute_path; 293 294 if ( $client == 'admin' ) { 295 $file = $mosConfig_absolute_path .'/administrator/templates/'. $p_tname .'/index.php'; 296 } else { 297 $file = $mosConfig_absolute_path .'/templates/'. $p_tname .'/index.php'; 298 } 299 300 if ( $fp = fopen( $file, 'r' ) ) { 301 $content = fread( $fp, filesize( $file ) ); 302 $content = htmlspecialchars( $content ); 303 304 HTML_templates::editTemplateSource( $p_tname, $content, $option, $client ); 305 } else { 306 mosRedirect( 'index2.php?option='. $option .'&client='. $client, 'Operation Failed: Could not open'. $file ); 307 } 308 } 309 310 311 function saveTemplateSource( $option, $client ) { 312 global $mosConfig_absolute_path; 313 314 $template = strval( mosGetParam( $_POST, 'template', '' ) ); 315 $filecontent = mosGetParam( $_POST, 'filecontent', '', _MOS_ALLOWHTML ); 316 317 if ( !$template ) { 318 mosRedirect( 'index2.php?option='. $option .'&client='. $client, 'Operation failed: No template specified.' ); 319 } 320 if ( !$filecontent ) { 321 mosRedirect( 'index2.php?option='. $option .'&client='. $client, 'Operation failed: Content empty.' ); 322 } 323 324 if ( $client == 'admin' ) { 325 $file = $mosConfig_absolute_path .'/administrator/templates/'. $template .'/index.php'; 326 } else { 327 $file = $mosConfig_absolute_path .'/templates/'. $template .'/index.php'; 328 } 329 330 $enable_write = mosGetParam($_POST,'enable_write',0); 331 $oldperms = fileperms($file); 332 333 if ($enable_write) @chmod($file, $oldperms | 0222); 334 335 clearstatcache(); 336 if ( is_writable( $file ) == false ) { 337 mosRedirect( 'index2.php?option='. $option , 'Operation failed: '. $file .' is not writable.' ); 338 } 339 340 if ( $fp = fopen ($file, 'w' ) ) { 341 fputs( $fp, stripslashes( $filecontent ), strlen( $filecontent ) ); 342 fclose( $fp ); 343 if ($enable_write) { 344 @chmod($file, $oldperms); 345 } else { 346 if (mosGetParam($_POST,'disable_write',0)) 347 @chmod($file, $oldperms & 0777555); 348 } // if 349 mosRedirect( 'index2.php?option='. $option .'&client='. $client ); 350 } else { 351 if ($enable_write) @chmod($file, $oldperms); 352 mosRedirect( 'index2.php?option='. $option .'&client='. $client, 'Operation failed: Failed to open file for writing.' ); 353 } 354 355 } 356 357 function editTemplateCSS( $p_tname, $option, $client ) { 358 global $mosConfig_absolute_path; 359 360 if ( $client == 'admin' ) { 361 $file = $mosConfig_absolute_path .'/administrator/templates/'. $p_tname .'/css/template_css.css'; 362 } else { 363 $file = $mosConfig_absolute_path .'/templates/'. $p_tname .'/css/template_css.css'; 364 } 365 366 if ($fp = fopen( $file, 'r' )) { 367 $content = fread( $fp, filesize( $file ) ); 368 $content = htmlspecialchars( $content ); 369 370 HTML_templates::editCSSSource( $p_tname, $content, $option, $client ); 371 } else { 372 mosRedirect( 'index2.php?option='. $option .'&client='. $client, 'Operation Failed: Could not open'. $file ); 373 } 374 } 375 376 377 function saveTemplateCSS( $option, $client ) { 378 global $mosConfig_absolute_path; 379 380 $template = strval( mosGetParam( $_POST, 'template', '' ) ); 381 $filecontent = mosGetParam( $_POST, 'filecontent', '', _MOS_ALLOWHTML ); 382 383 if ( !$template ) { 384 mosRedirect( 'index2.php?option='. $option .'&client='. $client, 'Operation failed: No template specified.' ); 385 } 386 387 if ( !$filecontent ) { 388 mosRedirect( 'index2.php?option='. $option .'&client='. $client, 'Operation failed: Content empty.' ); 389 } 390 391 if ( $client == 'admin' ) { 392 $file = $mosConfig_absolute_path .'/administrator/templates/'. $template .'/css/template_css.css'; 393 } else { 394 $file = $mosConfig_absolute_path .'/templates/'. $template .'/css/template_css.css'; 395 } 396 397 $enable_write = mosGetParam($_POST,'enable_write',0); 398 $oldperms = fileperms($file); 399 400 if ($enable_write) { 401 @chmod($file, $oldperms | 0222); 402 } 403 404 clearstatcache(); 405 if ( is_writable( $file ) == false ) { 406 mosRedirect( 'index2.php?option='. $option .'&client='. $client, 'Operation failed: The file is not writable.' ); 407 } 408 409 if ($fp = fopen ($file, 'w')) { 410 fputs( $fp, stripslashes( $filecontent ) ); 411 fclose( $fp ); 412 if ($enable_write) { 413 @chmod($file, $oldperms); 414 } else { 415 if (mosGetParam($_POST,'disable_write',0)) 416 @chmod($file, $oldperms & 0777555); 417 } // if 418 mosRedirect( 'index2.php?option='. $option ); 419 } else { 420 if ($enable_write) @chmod($file, $oldperms); 421 mosRedirect( 'index2.php?option='. $option .'&client='. $client, 'Operation failed: Failed to open file for writing.' ); 422 } 423 424 } 425 426 427 function assignTemplate( $p_tname, $option, $client ) { 428 global $database; 429 430 // get selected pages for $menulist 431 if ( $p_tname ) { 432 433 $query = "SELECT menuid AS value" 434 . "\n FROM #__templates_menu" 435 . "\n WHERE client_id = 0" 436 . "\n AND template = " . $database->Quote( $p_tname ) 437 ; 438 $database->setQuery( $query ); 439 $lookup = $database->loadObjectList(); 440 } 441 442 // build the html select list 443 $menulist = mosAdminMenus::MenuLinks( $lookup, 0, 1 ); 444 445 HTML_templates::assignTemplate( $p_tname, $menulist, $option, $client ); 446 } 447 448 449 function saveTemplateAssign( $option, $client ) { 450 global $database; 451 452 $menus = josGetArrayInts( 'selections' ); 453 454 $template = stripslashes( strval( mosGetParam( $_POST, 'template', '' ) ) ); 455 456 $query = "DELETE FROM #__templates_menu" 457 . "\n WHERE client_id = 0" 458 . "\n AND template = " . $database->Quote( $template ) 459 . "\n AND menuid != 0" 460 ; 461 $database->setQuery( $query ); 462 $database->query(); 463 464 if ( !in_array( '', $menus ) ) { 465 foreach ( $menus as $menuid ){ 466 $menuid = (int) $menuid; 467 468 // If 'None' is not in array 469 if ( $menuid != -999 ) { 470 // check if there is already a template assigned to this menu item 471 $query = "DELETE FROM #__templates_menu" 472 . "\n WHERE client_id = 0" 473 . "\n AND menuid = " . (int) $menuid 474 ; 475 $database->setQuery( $query ); 476 $database->query(); 477 478 $query = "INSERT INTO #__templates_menu" 479 . "\n SET client_id = 0, template = " . $database->Quote( $template ) . ", menuid = " . (int) $menuid 480 ; 481 $database->setQuery( $query ); 482 $database->query(); 483 } 484 } 485 } 486 487 mosRedirect( 'index2.php?option='. $option .'&client='. $client ); 488 } 489 490 491 /** 492 */ 493 function editPositions( $option ) { 494 global $database; 495 496 $query = "SELECT *" 497 . "\n FROM #__template_positions" 498 ; 499 $database->setQuery( $query ); 500 $positions = $database->loadObjectList(); 501 502 HTML_templates::editPositions( $positions, $option ); 503 } 504 505 /** 506 */ 507 function savePositions( $option ) { 508 global $database; 509 510 $positions = mosGetParam( $_POST, 'position', array() ); 511 $descriptions = mosGetParam( $_POST, 'description', array() ); 512 513 $query = "DELETE FROM #__template_positions"; 514 $database->setQuery( $query ); 515 $database->query(); 516 517 foreach ($positions as $id=>$position) { 518 $position = trim( $position ); 519 if (get_magic_quotes_gpc()) { 520 $position = stripslashes( $position ); 521 } 522 $description = stripslashes( strval( mosGetParam( $descriptions, $id, '' ) ) ); 523 if ($position != '') { 524 $query = "INSERT INTO #__template_positions" 525 . "\n VALUES ( " . (int) $id . ", " . $database->Quote( $position ) . ", " . $database->Quote( $description ) . " )" 526 ; 527 $database->setQuery( $query ); 528 $database->query(); 529 } 530 } 531 mosRedirect( 'index2.php?option='. $option .'&task=positions', 'Positions saved' ); 532 } 533 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 14:43:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |