Files
@ f43d1a4680a9
Branch filter:
Location: hot67beta/administrator/components/com_installer/models/templates.php
f43d1a4680a9
4.8 KiB
text/x-php
menubar 0 to 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | <?php
/**
* @version $Id: templates.php 10710 2008-08-21 10:08:12Z eddieajau $
* @package Joomla
* @subpackage Menus
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant to the
* GNU General Public License, and as distributed it includes or is derivative
* of works licensed under the GNU General Public License or other free or open
* source software licenses. See COPYRIGHT.php for copyright notices and
* details.
*/
// Import library dependencies
require_once(dirname(__FILE__).DS.'extension.php');
jimport( 'joomla.filesystem.folder' );
/**
* Extension Manager Templates Model
*
* @package Joomla
* @subpackage Installer
* @since 1.5
*/
class InstallerModelTemplates extends InstallerModel
{
/**
* Extension Type
* @var string
*/
var $_type = 'template';
/**
* Overridden constructor
* @access protected
*/
function __construct()
{
global $mainframe;
// Call the parent constructor
parent::__construct();
// Set state variables from the request
$this->setState('filter.string', $mainframe->getUserStateFromRequest( "com_installer.templates.string", 'filter', '', 'string' ));
$this->setState('filter.client', $mainframe->getUserStateFromRequest( "com_installer.templates.client", 'client', -1, 'int' ));
}
function _loadItems()
{
global $mainframe, $option;
$db = &JFactory::getDBO();
if ($this->_state->get('filter.client') < 0) {
$client = 'all';
// Get the site templates
$templateDirs = JFolder::folders(JPATH_SITE.DS.'templates');
for ($i=0; $i < count($templateDirs); $i++) {
$template = new stdClass();
$template->folder = $templateDirs[$i];
$template->client = 0;
$template->baseDir = JPATH_SITE.DS.'templates';
if ($this->_state->get('filter.string')) {
if (strpos($template->folder, $this->_state->get('filter.string')) !== false) {
$templates[] = $template;
}
} else {
$templates[] = $template;
}
}
// Get the admin templates
$templateDirs = JFolder::folders(JPATH_ADMINISTRATOR.DS.'templates');
for ($i=0; $i < count($templateDirs); $i++) {
$template = new stdClass();
$template->folder = $templateDirs[$i];
$template->client = 1;
$template->baseDir = JPATH_ADMINISTRATOR.DS.'templates';
if ($this->_state->get('filter.string')) {
if (strpos($template->folder, $this->_state->get('filter.string')) !== false) {
$templates[] = $template;
}
} else {
$templates[] = $template;
}
}
} else {
$clientInfo =& JApplicationHelper::getClientInfo($this->_state->get('filter.client'));
$client = $clientInfo->name;
$templateDirs = JFolder::folders($clientInfo->path.DS.'templates');
for ($i=0; $i < count($templateDirs); $i++) {
$template = new stdClass();
$template->folder = $templateDirs[$i];
$template->client = $clientInfo->id;
$template->baseDir = $clientInfo->path.DS.'templates';
if ($this->_state->get('filter.string')) {
if (strpos($template->folder, $this->_state->get('filter.string')) !== false) {
$templates[] = $template;
}
} else {
$templates[] = $template;
}
}
}
// Get a list of the currently active templates
$query = 'SELECT template' .
' FROM #__templates_menu' .
' WHERE 1';
$db->setQuery($query);
$activeList = $db->loadResultArray();
$rows = array();
$rowid = 0;
// Check that the directory contains an xml file
foreach($templates as $template)
{
$dirName = $template->baseDir .DS. $template->folder;
$xmlFilesInDir = JFolder::files($dirName,'.xml$');
foreach($xmlFilesInDir as $xmlfile)
{
$data = JApplicationHelper::parseXMLInstallFile($dirName . DS. $xmlfile);
$row = new StdClass();
$row->id = $rowid;
$row->client_id = $template->client;
$row->directory = $template->folder;
$row->baseDir = $template->baseDir;
// Is the template active?
if (in_array($row->directory, $activeList)) {
$row->active = true;
} else {
$row->active = false;
}
if ($data) {
foreach($data as $key => $value) {
$row->$key = $value;
}
}
$row->checked_out = 0;
$row->jname = JString::strtolower( str_replace( ' ', '_', $row->name ) );
$rows[] = $row;
$rowid++;
}
}
$this->setState('pagination.total', count($rows));
// if the offset is greater than the total, then can the offset
if($this->_state->get('pagination.offset') > $this->_state->get('pagination.total')) {
$this->setState('pagination.offset',0);
}
if($this->_state->get('pagination.limit') > 0) {
$this->_items = array_slice( $rows, $this->_state->get('pagination.offset'), $this->_state->get('pagination.limit') );
} else {
$this->_items = $rows;
}
}
}
|