Source for file admin.templates.php
Documentation is available at admin.templates.php
* @copyright Refer to copyright.php
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @author Mambo Foundation Inc see README.php
/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
// ensure user has access to this function
if (!$acl->acl_check( 'administration', 'manage', 'users', $GLOBALS['my']->usertype, 'components', 'com_templates' )) {
mosRedirect( 'index2.php', T_('You are not authorized to view this resource.') );
require_once( $mainframe->getPath( 'admin_html' ) );
require_once( $mosConfig_absolute_path .
'/administrator/components/com_templates/admin.templates.class.php' );
mosRedirect ( 'index2.php?option=com_installer&element=template&client='.
$client );
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client );
* Compiles a list of installed, version 4.5+ templates
* Based on xml files found. If no xml file found the template
global $database, $mainframe;
global $mosConfig_absolute_path, $mosConfig_list_limit;
$limit =
$mainframe->getUserStateFromRequest( 'viewlistlimit', 'limit', $mosConfig_list_limit );
$limitstart =
$mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 );
if ($client ==
'admin') {
$templateBaseDir =
mosPathName( $mosConfig_absolute_path .
'/administrator/templates' );
$templateBaseDir =
mosPathName( $mosConfig_absolute_path .
'/templates' );
// Read the template dir to find templates
$id =
intval( $client ==
'admin' );
$database->setQuery( "SELECT template FROM #__templates_menu WHERE client_id='1' AND menuid='0'" );
$database->setQuery( "SELECT template FROM #__templates_menu WHERE client_id='0' AND menuid='0'" );
$cur_template =
$database->loadResult();
// Check that the directory contains an xml file
foreach($templateDirs as $templateDir) {
$dirName =
mosPathName($templateBaseDir .
$templateDir);
foreach($xmlFilesInDir as $xmlfile) {
// Read the file to see if it's a valid template XML file
if ($parser->getType() !=
'template') continue;
$row->directory =
$templateDir;
$row->creationdate =
$parser->getCreationDate('template');
$row->name =
$parser->getName('template');
$row->author =
$parser->getAuthor('template');
$row->copyright =
$parser->getCopyright('template');
$row->authorEmail =
$parser->getAuthorEmail('template');
$row->authorUrl =
$parser->getAuthorUrl('template');
$row->version =
$parser->getVersion('template');
$element = &$xmlDoc->getElementsByPath('name', 1 );
$row->name = $element->getText();
$element = &$xmlDoc->getElementsByPath('creationDate', 1);
$row->creationdate = $element ? $element->getText() : 'Unknown';
$element = &$xmlDoc->getElementsByPath('author', 1);
$row->author = $element ? $element->getText() : 'Unknown';
$element = &$xmlDoc->getElementsByPath('copyright', 1);
$row->copyright = $element ? $element->getText() : '';
$element = &$xmlDoc->getElementsByPath('authorEmail', 1);
$row->authorEmail = $element ? $element->getText() : '';
$element = &$xmlDoc->getElementsByPath('authorUrl', 1);
$row->authorUrl = $element ? $element->getText() : '';
$element = &$xmlDoc->getElementsByPath('version', 1);
$row->version = $element ? $element->getText() : '';
if ($cur_template ==
$templateDir) {
// check if template is assigned
$database->setQuery( "SELECT count(*) FROM #__templates_menu WHERE client_id='0' AND template='$row->directory' AND menuid<>'0'" );
$row->assigned =
$database->loadResult() ?
1 :
0;
require_once( $GLOBALS['mosConfig_absolute_path'] .
'/administrator/includes/pageNavigation.php' );
$rows =
array_slice( $rows, $pageNav->limitstart, $pageNav->limit );
* Publish, or make current, the selected template
$database->setQuery("DELETE FROM #__templates_menu WHERE client_id='1' AND menuid='0'");
$database->setQuery("INSERT INTO #__templates_menu SET client_id='1', template='$p_tname', menuid='0'");
$database->setQuery("DELETE FROM #__templates_menu WHERE client_id='0' AND menuid='0'");
$database->setQuery("INSERT INTO #__templates_menu SET client_id='0', template='$p_tname', menuid='0'");
$_SESSION['cur_template'] =
$p_tname;
mosRedirect('index2.php?option='.
$option .
'&client='.
$client);
* Remove the selected template
$client_id =
$client==
'admin' ?
1 :
0;
$database->setQuery("SELECT template FROM #__templates_menu WHERE client_id='$client_id' AND menuid='0'");
$cur_template =
$database->loadResult();
if ($cur_template ==
$cid) {
echo
"<script>alert('".
T_('You can not delete template in use.').
"'); window.history.go(-1); </script>\n";
$database->setQuery( "DELETE FROM #__templates_menu WHERE template='$cid' AND client_id='$client_id' AND menuid<>'0'" );
mosRedirect( 'index2.php?option=com_installer&element=template&client='.
$client .
'&task=remove&cid[]='.
$cid );
global $mosConfig_absolute_path;
if ( $client ==
'admin' ) {
$file =
$mosConfig_absolute_path .
'/administrator/templates/'.
$p_tname .
'/index.php';
$file =
$mosConfig_absolute_path .
'/templates/'.
$p_tname .
'/index.php';
if ( $fp =
fopen( $file, 'r' ) ) {
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client, sprintf(T_('Operation Failed: Could not open %s' ), $file) );
global $mosConfig_absolute_path;
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client, T_('Operation failed: No template specified.') );
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client, T_('Operation failed: Content empty.') );
if ( $client ==
'admin' ) {
$file =
$mosConfig_absolute_path .
'/administrator/templates/'.
$template .
'/index.php';
$file =
$mosConfig_absolute_path .
'/templates/'.
$template .
'/index.php';
if ($enable_write) @chmod($file, $oldperms |
0222);
mosRedirect( 'index2.php?option='.
$option , sprintf(T_('Operation failed: %s is not writable.'), $file) );
if ( $fp =
fopen ($file, 'w' ) ) {
@chmod($file, $oldperms);
@chmod($file, $oldperms & 0777555);
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client );
if ($enable_write) @chmod($file, $oldperms);
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client, T_('Operation failed: Failed to open file for writing.') );
global $mosConfig_absolute_path;
if ( $client ==
'admin' ) {
$file =
$mosConfig_absolute_path .
'/administrator/templates/'.
$p_tname .
'/css/template_css.css';
$file =
$mosConfig_absolute_path .
'/templates/'.
$p_tname .
'/css/template_css.css';
if ($fp =
fopen( $file, 'r' )) {
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client, sprintf(T_('Operation Failed: Could not open %s' ), $file) );
global $mosConfig_absolute_path;
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client, T_('Operation failed: No template specified.') );
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client, T_('Operation failed: Content empty.') );
if ( $client ==
'admin' ) {
$file =
$mosConfig_absolute_path .
'/administrator/templates/'.
$template .
'/css/template_css.css';
$file =
$mosConfig_absolute_path .
'/templates/'.
$template .
'/css/template_css.css';
if ($enable_write) @chmod($file, $oldperms |
0222);
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client, T_('Operation failed: The file is not writable.') );
if ($fp =
fopen ($file, 'w')) {
@chmod($file, $oldperms);
@chmod($file, $oldperms & 0777555);
if ($enable_write) @chmod($file, $oldperms);
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client, T_('Operation failed: Failed to open file for writing.') );
// get selected pages for $menulist
$database->setQuery( "SELECT menuid AS value FROM #__templates_menu WHERE client_id='0' AND template='$p_tname'" );
$lookup =
$database->loadObjectList();
// build the html select list
$database->setQuery( "DELETE FROM #__templates_menu WHERE client_id='0' AND template='$template' AND menuid<>'0'" );
foreach ( $menus as $menuid ){
// If 'None' is not in array
// check if there is already a template assigned to this menu item
$database->setQuery( "DELETE FROM #__templates_menu WHERE client_id='0' AND menuid='$menuid'" );
$database->setQuery( "INSERT INTO #__templates_menu SET client_id='0', template='$template', menuid='$menuid'" );
mosRedirect( 'index2.php?option='.
$option .
'&client='.
$client );
$database->setQuery( "SELECT * FROM #__template_positions" );
$positions =
$database->loadObjectList();
$positions =
mosGetParam( $_POST, 'position', array() );
$descriptions =
mosGetParam( $_POST, 'description', array() );
$query =
'DELETE FROM #__template_positions';
$database->setQuery( $query );
foreach ($positions as $id=>
$position) {
$position =
trim( $database->getEscaped( $position ) );
$query =
"INSERT INTO #__template_positions"
.
"\nVALUES ($id,'$position','$description')";
$database->setQuery( $query );
mosRedirect( 'index2.php?option='.
$option .
'&task=positions', T_('Positions saved') );
Documentation generated on Mon, 05 May 2008 16:16:24 +0400 by phpDocumentor 1.4.0