| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: controller.php 21042 2011-03-31 15:58:17Z dextercowley $ 4 * @package Joomla 5 * @subpackage Templates 6 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant to the 9 * GNU General Public License, and as distributed it includes or is derivative 10 * of works licensed under the GNU General Public License or other free or open 11 * source software licenses. See COPYRIGHT.php for copyright notices and 12 * details. 13 */ 14 15 /** 16 * @package Joomla 17 * @subpackage Templates 18 */ 19 class TemplatesController 20 { 21 /** 22 * Compiles a list of installed, version 4.5+ templates 23 * 24 * Based on xml files found. If no xml file found the template 25 * is ignored 26 */ 27 function viewTemplates() 28 { 29 global $mainframe, $option; 30 31 // Initialize some variables 32 $db =& JFactory::getDBO(); 33 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 34 35 // Initialize the pagination variables 36 $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int'); 37 $limitstart = $mainframe->getUserStateFromRequest($option.'.'.$client->id.'.limitstart', 'limitstart', 0, 'int'); 38 39 $select[] = JHTML::_('select.option', '0', JText::_('Site')); 40 $select[] = JHTML::_('select.option', '1', JText::_('Administrator')); 41 $lists['client'] = JHTML::_('select.genericlist', $select, 'client', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $client->id); 42 43 $tBaseDir = $client->path.DS.'templates'; 44 45 //get template xml file info 46 $rows = array(); 47 $rows = TemplatesHelper::parseXMLTemplateFiles($tBaseDir); 48 49 // set dynamic template information 50 for($i = 0; $i < count($rows); $i++) { 51 $rows[$i]->assigned = TemplatesHelper::isTemplateAssigned($rows[$i]->directory); 52 $rows[$i]->published = TemplatesHelper::isTemplateDefault($rows[$i]->directory, $client->id); 53 } 54 55 jimport('joomla.html.pagination'); 56 $page = new JPagination(count($rows), $limitstart, $limit); 57 58 $rows = array_slice($rows, $page->limitstart, $page->limit); 59 60 require_once (JPATH_COMPONENT.DS.'admin.templates.html.php'); 61 TemplatesView::showTemplates($rows, $lists, $page, $option, $client); 62 } 63 64 /** 65 * Show the template with module position in an iframe 66 */ 67 function previewTemplate() 68 { 69 $template = JRequest::getVar('id', '', 'method', 'cmd'); 70 $option = JRequest::getCmd('option'); 71 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 72 73 if (!$template) 74 { 75 return JError::raiseWarning( 500, JText::_('Template not specified') ); 76 } 77 78 // Set FTP credentials, if given 79 jimport('joomla.client.helper'); 80 JClientHelper::setCredentialsFromRequest('ftp'); 81 82 require_once (JPATH_COMPONENT.DS.'admin.templates.html.php'); 83 TemplatesView::previewTemplate($template, true, $client, $option); 84 } 85 86 /** 87 * Publish, or make current, the selected template 88 */ 89 function publishTemplate() 90 { 91 global $mainframe; 92 93 // Check for request forgeries 94 JRequest::checkToken() or jexit( 'Invalid Token' ); 95 96 // Initialize some variables 97 $db = & JFactory::getDBO(); 98 $cid = JRequest::getVar('cid', array(), 'method', 'array'); 99 $cid = array(JFilterInput::clean(@$cid[0], 'cmd')); 100 $option = JRequest::getCmd('option'); 101 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 102 103 if ($cid[0]) 104 { 105 $query = 'DELETE FROM #__templates_menu' . 106 ' WHERE client_id = '.(int) $client->id . 107 ' AND (menuid = 0 OR template = '.$db->Quote($cid[0]).')'; 108 $db->setQuery($query); 109 $db->query(); 110 111 $query = 'INSERT INTO #__templates_menu' . 112 ' SET client_id = '.(int) $client->id .', template = '.$db->Quote($cid[0]).', menuid = 0'; 113 $db->setQuery($query); 114 $db->query(); 115 } 116 117 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id); 118 } 119 120 function editTemplate() 121 { 122 jimport('joomla.filesystem.path'); 123 124 // Initialize some variables 125 $db = & JFactory::getDBO(); 126 $cid = JRequest::getVar('cid', array(), 'method', 'array'); 127 $cid = array(JFilterInput::clean(@$cid[0], 'cmd')); 128 $template = $cid[0]; 129 $option = JRequest::getCmd('option'); 130 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 131 132 if (!$cid[0]) { 133 return JError::raiseWarning( 500, JText::_('Template not specified') ); 134 } 135 136 $tBaseDir = JPath::clean($client->path.DS.'templates'); 137 138 if (!is_dir( $tBaseDir . DS . $template )) { 139 return JError::raiseWarning( 500, JText::_('Template not found') ); 140 } 141 $lang =& JFactory::getLanguage(); 142 $lang->load( 'tpl_'.$template, JPATH_ADMINISTRATOR ); 143 144 $ini = $client->path.DS.'templates'.DS.$template.DS.'params.ini'; 145 $xml = $client->path.DS.'templates'.DS.$template.DS.'templateDetails.xml'; 146 $row = TemplatesHelper::parseXMLTemplateFile($tBaseDir, $template); 147 148 jimport('joomla.filesystem.file'); 149 // Read the ini file 150 if (JFile::exists($ini)) { 151 $content = JFile::read($ini); 152 } else { 153 $content = null; 154 } 155 156 $params = new JParameter($content, $xml, 'template'); 157 158 $assigned = TemplatesHelper::isTemplateAssigned($row->directory); 159 $default = TemplatesHelper::isTemplateDefault($row->directory, $client->id); 160 161 if($client->id == '1') { 162 $lists['selections'] = JText::_('Cannot assign an administrator template'); 163 } else { 164 $lists['selections'] = TemplatesHelper::createMenuList($template); 165 } 166 167 if ($default) { 168 $row->pages = 'all'; 169 } elseif (!$assigned) { 170 $row->pages = 'none'; 171 } else { 172 $row->pages = null; 173 } 174 175 // Set FTP credentials, if given 176 jimport('joomla.client.helper'); 177 $ftp =& JClientHelper::setCredentialsFromRequest('ftp'); 178 179 require_once (JPATH_COMPONENT.DS.'admin.templates.html.php'); 180 TemplatesView::editTemplate($row, $lists, $params, $option, $client, $ftp, $template); 181 } 182 183 function saveTemplate() 184 { 185 global $mainframe; 186 187 // Check for request forgeries 188 JRequest::checkToken() or jexit( 'Invalid Token' ); 189 190 // Initialize some variables 191 $db = & JFactory::getDBO(); 192 193 $template = JRequest::getVar('id', '', 'method', 'cmd'); 194 $option = JRequest::getVar('option', '', '', 'cmd'); 195 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 196 $menus = JRequest::getVar('selections', array(), 'post', 'array'); 197 $params = JRequest::getVar('params', array(), 'post', 'array'); 198 $default = JRequest::getBool('default'); 199 JArrayHelper::toInteger($menus); 200 201 if (!$template) { 202 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id, JText::_('Operation Failed').': '.JText::_('No template specified.')); 203 } 204 205 // Set FTP credentials, if given 206 jimport('joomla.client.helper'); 207 JClientHelper::setCredentialsFromRequest('ftp'); 208 $ftp = JClientHelper::getCredentials('ftp'); 209 210 $file = $client->path.DS.'templates'.DS.$template.DS.'params.ini'; 211 212 jimport('joomla.filesystem.file'); 213 if (JFile::exists($file) && count($params)) 214 { 215 $registry = new JRegistry(); 216 $registry->loadArray($params); 217 $txt = $registry->toString(); 218 219 // Try to make the params file writeable 220 if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0755')) { 221 JError::raiseNotice('SOME_ERROR_CODE', JText::_('Could not make the template parameter file writable')); 222 } 223 224 $return = JFile::write($file, $txt); 225 226 // Try to make the params file unwriteable 227 if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0644')) { 228 JError::raiseNotice('SOME_ERROR_CODE', JText::_('Could not make the template parameter file unwritable')); 229 } 230 231 if (!$return) { 232 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id, JText::_('Operation Failed').': '.JText::sprintf('Failed to open file for writing.', $file)); 233 } 234 } 235 236 // Reset all existing assignments 237 $query = 'DELETE FROM #__templates_menu' . 238 ' WHERE client_id = 0' . 239 ' AND template = '.$db->Quote( $template ); 240 $db->setQuery($query); 241 $db->query(); 242 243 if ($default) { 244 $menus = array( 0 ); 245 } 246 247 foreach ($menus as $menuid) 248 { 249 // If 'None' is not in array 250 if ((int) $menuid >= 0) 251 { 252 // check if there is already a template assigned to this menu item 253 $query = 'DELETE FROM #__templates_menu' . 254 ' WHERE client_id = 0' . 255 ' AND menuid = '.(int) $menuid; 256 $db->setQuery($query); 257 $db->query(); 258 259 $query = 'INSERT INTO #__templates_menu' . 260 ' SET client_id = 0, template = '. $db->Quote( $template ) .', menuid = '.(int) $menuid; 261 $db->setQuery($query); 262 $db->query(); 263 } 264 } 265 266 $task = JRequest::getCmd('task'); 267 if($task == 'apply') { 268 $mainframe->redirect('index.php?option='.$option.'&task=edit&cid[]='.$template.'&client='.$client->id); 269 } else { 270 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id); 271 } 272 } 273 274 function cancelTemplate() 275 { 276 global $mainframe; 277 278 // Initialize some variables 279 $option = JRequest::getCmd('option'); 280 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 281 282 // Set FTP credentials, if given 283 jimport('joomla.client.helper'); 284 JClientHelper::setCredentialsFromRequest('ftp'); 285 286 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id); 287 } 288 289 function editTemplateSource() 290 { 291 global $mainframe; 292 293 // Initialize some variables 294 $option = JRequest::getCmd('option'); 295 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 296 $template = JRequest::getVar('id', '', 'method', 'cmd'); 297 $file = $client->path.DS.'templates'.DS.$template.DS.'index.php'; 298 299 // Read the source file 300 jimport('joomla.filesystem.file'); 301 $content = JFile::read($file); 302 303 if ($content !== false) 304 { 305 // Set FTP credentials, if given 306 jimport('joomla.client.helper'); 307 $ftp =& JClientHelper::setCredentialsFromRequest('ftp'); 308 309 $content = htmlspecialchars($content, ENT_COMPAT, 'UTF-8'); 310 require_once (JPATH_COMPONENT.DS.'admin.templates.html.php'); 311 TemplatesView::editTemplateSource($template, $content, $option, $client, $ftp); 312 } else { 313 $msg = JText::sprintf('Operation Failed Could not open', $file); 314 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id, $msg); 315 } 316 } 317 318 function saveTemplateSource() 319 { 320 global $mainframe; 321 322 // Check for request forgeries 323 JRequest::checkToken() or jexit( 'Invalid Token' ); 324 325 // Initialize some variables 326 $option = JRequest::getCmd('option'); 327 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 328 $template = JRequest::getVar('id', '', 'method', 'cmd'); 329 $filecontent = JRequest::getVar('filecontent', '', 'post', 'string', JREQUEST_ALLOWRAW); 330 331 if (!$template) { 332 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id, JText::_('Operation Failed').': '.JText::_('No template specified.')); 333 } 334 335 if (!$filecontent) { 336 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id, JText::_('Operation Failed').': '.JText::_('Content empty.')); 337 } 338 339 // Set FTP credentials, if given 340 jimport('joomla.client.helper'); 341 JClientHelper::setCredentialsFromRequest('ftp'); 342 $ftp = JClientHelper::getCredentials('ftp'); 343 344 $file = $client->path.DS.'templates'.DS.$template.DS.'index.php'; 345 346 // Try to make the template file writeable 347 if (!$ftp['enabled'] && !JPath::setPermissions($file, '0755')) { 348 JError::raiseNotice('SOME_ERROR_CODE', JText::_('Could not make the template file writable')); 349 } 350 351 jimport('joomla.filesystem.file'); 352 $return = JFile::write($file, $filecontent); 353 354 // Try to make the template file unwriteable 355 if (!$ftp['enabled'] && !JPath::setPermissions($file, '0644')) { 356 JError::raiseNotice('SOME_ERROR_CODE', JText::_('Could not make the template file unwritable')); 357 } 358 359 if ($return) 360 { 361 $task = JRequest::getCmd('task'); 362 switch($task) 363 { 364 case 'apply_source': 365 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id.'&task=edit_source&id='.$template, JText::_('Template source saved')); 366 break; 367 368 case 'save_source': 369 default: 370 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id.'&task=edit&cid[]='.$template, JText::_('Template source saved')); 371 break; 372 } 373 } 374 else { 375 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id, JText::_('Operation Failed').': '.JText::sprintf('Failed to open file for writing.', $file)); 376 } 377 } 378 379 function chooseTemplateCSS() 380 { 381 global $mainframe; 382 383 // Initialize some variables 384 $option = JRequest::getCmd('option'); 385 $template = JRequest::getVar('id', '', 'method', 'cmd'); 386 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 387 388 // Determine template CSS directory 389 $dir = $client->path.DS.'templates'.DS.$template.DS.'css'; 390 391 // List template .css files 392 jimport('joomla.filesystem.folder'); 393 $files = JFolder::files($dir, '\.css$', false, false); 394 395 // Set FTP credentials, if given 396 jimport('joomla.client.helper'); 397 JClientHelper::setCredentialsFromRequest('ftp'); 398 399 require_once (JPATH_COMPONENT.DS.'admin.templates.html.php'); 400 TemplatesView::chooseCSSFiles($template, $dir, $files, $option, $client); 401 } 402 403 function editTemplateCSS() 404 { 405 global $mainframe; 406 407 // Initialize some variables 408 $option = JRequest::getCmd('option'); 409 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 410 $template = JRequest::getVar('id', '', 'method', 'cmd'); 411 $filename = JRequest::getVar('filename', '', 'method', 'cmd'); 412 413 jimport('joomla.filesystem.file'); 414 415 if (JFile::getExt($filename) !== 'css') { 416 $msg = JText::_('Wrong file type given, only CSS files can be edited.'); 417 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id.'&task=choose_css&id='.$template, $msg, 'error'); 418 } 419 420 $content = JFile::read($client->path.DS.'templates'.DS.$template.DS.'css'.DS.$filename); 421 422 if ($content !== false) 423 { 424 // Set FTP credentials, if given 425 jimport('joomla.client.helper'); 426 $ftp =& JClientHelper::setCredentialsFromRequest('ftp'); 427 428 $content = htmlspecialchars($content, ENT_COMPAT, 'UTF-8'); 429 require_once (JPATH_COMPONENT.DS.'admin.templates.html.php'); 430 TemplatesView::editCSSSource($template, $filename, $content, $option, $client, $ftp); 431 } 432 else 433 { 434 $msg = JText::sprintf('Operation Failed Could not open', $client->path.$filename); 435 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id, $msg); 436 } 437 } 438 439 function saveTemplateCSS() 440 { 441 global $mainframe; 442 443 // Check for request forgeries 444 JRequest::checkToken() or jexit( 'Invalid Token' ); 445 446 // Initialize some variables 447 $option = JRequest::getCmd('option'); 448 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 449 $template = JRequest::getVar('id', '', 'post', 'cmd'); 450 $filename = JRequest::getVar('filename', '', 'post', 'cmd'); 451 $filecontent = JRequest::getVar('filecontent', '', 'post', 'string', JREQUEST_ALLOWRAW); 452 453 if (!$template) { 454 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id, JText::_('Operation Failed').': '.JText::_('No template specified.')); 455 } 456 457 if (!$filecontent) { 458 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id, JText::_('Operation Failed').': '.JText::_('Content empty.')); 459 } 460 461 // Set FTP credentials, if given 462 jimport('joomla.client.helper'); 463 JClientHelper::setCredentialsFromRequest('ftp'); 464 $ftp = JClientHelper::getCredentials('ftp'); 465 466 $file = $client->path.DS.'templates'.DS.$template.DS.'css'.DS.$filename; 467 468 // Try to make the css file writeable 469 if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0755')) { 470 JError::raiseNotice('SOME_ERROR_CODE', JText::_('Could not make the css file writable')); 471 } 472 473 jimport('joomla.filesystem.file'); 474 $return = JFile::write($file, $filecontent); 475 476 // Try to make the css file unwriteable 477 if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0644')) { 478 JError::raiseNotice('SOME_ERROR_CODE', JText::_('Could not make the css file unwritable')); 479 } 480 481 if ($return) 482 { 483 $task = JRequest::getCmd('task'); 484 switch($task) 485 { 486 case 'apply_css': 487 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id.'&task=edit_css&id='.$template.'&filename='.$filename, JText::_('File Saved')); 488 break; 489 490 case 'save_css': 491 default: 492 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id.'&task=edit&cid[]='.$template, JText::_('File Saved')); 493 break; 494 } 495 } 496 else { 497 $mainframe->redirect('index.php?option='.$option.'&client='.$client->id.'&id='.$template.'&task=choose_css', JText::_('Operation Failed').': '.JText::sprintf('Failed to open file for writing.', $file)); 498 } 499 } 500 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |