private function _extract($archive, $destination, $options) { // Initialise variables. $this->_data = null; $this->_metadata = null; if (!extension_loaded('zlib')) { $this->set('error.message', MText::_('MLIB_FILESYSTEM_ZIP_NOT_SUPPORTED')); return false; } if (!($this->_data = MFile::read($archive))) { $this->set('error.message', MText::_('MLIB_FILESYSTEM_ZIP_UNABLE_TO_READ')); return false; } if (!$this->_readZipInfo($this->_data)) { $this->set('error.message', MText::_('MLIB_FILESYSTEM_ZIP_INFO_FAILED')); return false; } for ($i = 0, $n = count($this->_metadata); $i < $n; $i++) { $lastPathCharacter = substr($this->_metadata[$i]['name'], -1, 1); if ($lastPathCharacter !== '/' && $lastPathCharacter !== '\\') { $buffer = $this->_getFileData($i); $path = MPath::clean($destination . '/' . $this->_metadata[$i]['name']); // Make sure the destination folder exists if (!MFolder::create(dirname($path))) { $this->set('error.message', MText::_('MLIB_FILESYSTEM_ZIP_UNABLE_TO_CREATE_DESTINATION')); return false; } if (MFile::write($path, $buffer) === false) { $this->set('error.message', MText::_('MLIB_FILESYSTEM_ZIP_UNABLE_TO_WRITE_ENTRY')); return false; } } } return true; }
public static function getInstance($type, $prefix = 'MTable', $config = array()) { // Sanitize and prepare the table class name. $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type); $tableClass = $prefix . ucfirst($type); // Only try to load the class if it doesn't already exist. if (!class_exists($tableClass)) { // Search for the class file in the MTable include paths. mimport('framework.filesystem.path'); MTable::addIncludePath(MPATH_MIWI . '/proxy/database/table'); if ($path = MPath::find(MTable::addIncludePath(), strtolower($type) . '.php')) { // Import the class file. include_once $path; // If we were unable to load the proper class, raise a warning and return false. if (!class_exists($tableClass)) { MError::raiseWarning(0, MText::sprintf('MLIB_DATABASE_ERROR_CLASS_NOT_FOUND_IN_FILE', $tableClass)); return false; } } else { // If we were unable to find the class file in the MTable include paths, raise a warning and return false. MError::raiseWarning(0, MText::sprintf('MLIB_DATABASE_ERROR_NOT_SUPPORTED_FILE_NOT_FOUND', $type)); return false; } } // If a database object was passed in the configuration array use it, otherwise get the global one from MFactory. $db = isset($config['dbo']) ? $config['dbo'] : MFactory::getDbo(); // Instantiate a new table class and return it. return new $tableClass($db); }
public function extract($archive, $destination, $options = array()) { // Initialise variables. $this->_data = null; $this->_metadata = null; if (!($this->_data = MFile::read($archive))) { $this->set('error.message', 'Unable to read archive'); return MError::raiseWarning(100, $this->get('error.message')); } if (!$this->_getTarInfo($this->_data)) { return MError::raiseWarning(100, $this->get('error.message')); } for ($i = 0, $n = count($this->_metadata); $i < $n; $i++) { $type = strtolower($this->_metadata[$i]['type']); if ($type == 'file' || $type == 'unix file') { $buffer = $this->_metadata[$i]['data']; $path = MPath::clean($destination . '/' . $this->_metadata[$i]['name']); // Make sure the destination folder exists if (!MFolder::create(dirname($path))) { $this->set('error.message', 'Unable to create destination'); return MError::raiseWarning(100, $this->get('error.message')); } if (MFile::write($path, $buffer) === false) { $this->set('error.message', 'Unable to write entry'); return MError::raiseWarning(100, $this->get('error.message')); } } } return true; }
/** * Set jQuery UI CSS Framework. * Path is {root}/css/ui/{interface} * This is a simple wrapper to {@link MParams::setInterface($value)}. * @param string $value */ public static function setInterface($value) { if ((is_string($value) || is_int($value)) && array_key_exists($value, MParams::getAvailableInterfaces()) && MPath::interfaceExists($value)) { MParams::setInterface($value); } else { Yii::log(W3::t('system', 'Incorrect parameter in method call: {method}.', array('{method}' => __METHOD__ . '(' . var_export($value, true) . ')')), 'notice', 'w3'); } }
public static function addIncludePath($path = '') { static $paths; if (!isset($paths)) { $paths = array(); } if (!empty($path) && !in_array($path, $paths)) { mimport('framework.filesystem.path'); array_unshift($paths, MPath::clean($path)); } return $paths; }
/** * Initialize css. */ public static function css() { $cs = Yii::app()->getClientScript(); // main css $cs->registerCssFile(Yii::app()->request->baseUrl . '/static/css/main.css'); // 960 css $cs->registerCssFile(Yii::app()->request->baseUrl . '/static/css/960.css'); // all jquery plugins css //$cs->registerCssFile(Yii::app()->request->baseUrl.'/static/css/jquery-1.3.x.plugins.css'); // jquery-ui if (MParams::getRegisterJqueryUI() && MPath::interfaceExists(MParams::getInterface())) { $cs->registerCssFile(Yii::app()->request->baseUrl . '/static/css/ui/' . MParams::getInterface() . '/jquery-ui-' . MParams::jqueryUIVersion . '.custom.css'); } // use this css if you want to globally redefine jquery-ui css framework classes $redefineJqueryUI = dirname(Yii::app()->basePath) . DIRECTORY_SEPARATOR . 'static' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'ui.css'; if (file_exists($redefineJqueryUI) && filesize($redefineJqueryUI) !== 0) { $cs->registerCssFile(Yii::app()->request->baseUrl . '/static/css/ui.css'); } }
protected static function loadClass($entity, $type) { if (strpos($type, '.')) { list($prefix, $type) = explode('.', $type); } else { $prefix = 'M'; } $class = MString::ucfirst($prefix, '_') . 'Form' . MString::ucfirst($entity, '_') . MString::ucfirst($type, '_'); if (class_exists($class)) { return $class; } // Get the field search path array. $paths = MFormHelper::addPath($entity); // If the type is complex, add the base type to the paths. if ($pos = strpos($type, '_')) { // Add the complex type prefix to the paths. for ($i = 0, $n = count($paths); $i < $n; $i++) { // Derive the new path. $path = $paths[$i] . '/' . strtolower(substr($type, 0, $pos)); // If the path does not exist, add it. if (!in_array($path, $paths)) { $paths[] = $path; } } // Break off the end of the complex type. $type = substr($type, $pos + 1); } // Try to find the class file. $type = strtolower($type) . '.php'; foreach ($paths as $path) { if ($file = MPath::find($path, $type)) { require_once $file; if (class_exists($class)) { break; } } } // Check for all if the class exists. return class_exists($class) ? $class : false; }
public static function getInstance($type, $prefix = '', $config = array()) { $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type); $modelClass = $prefix . ucfirst($type); if (!class_exists($modelClass)) { mimport('framework.filesystem.path'); $path = MPath::find(self::addIncludePath(null, $prefix), self::_createFileName('model', array('name' => $type))); if (!$path) { $path = MPath::find(self::addIncludePath(null, ''), self::_createFileName('model', array('name' => $type))); } if ($path) { require_once $path; if (!class_exists($modelClass)) { MError::raiseWarning(0, MText::sprintf('MLIB_APPLICATION_ERROR_MODELCLASS_NOT_FOUND', $modelClass)); return false; } } else { return false; } } return new $modelClass($config); }
$colNames = "''"; } /*end if count columns*/ $colModel = ''; if (count($columnsModel)) { $n = 0; foreach ($columnsModel as $row) { $colModel .= ($n === 0 ? '' : ',') . "\n {"; $i = 0; foreach ($row as $k => $v) { $colModel .= ($i === 0 ? '' : ',') . $k . ':' . (is_string($v) ? "'" . $v . "'" : ($v === true ? 'true' : ($v === false ? 'false' : $v))); $i++; } $colModel .= "}"; $n++; } /*end foreach row*/ } else { $colModel = "\n {name:'colModel',width:99}"; } /*end if count columnsModel*/ Yii::app()->getClientScript()->registerScript('grid[' . $gridId . ']', "\njQuery('#" . $gridId . "').removeClass('w3-hidden');\njQuery('#" . $gridPagerId . "').removeClass('w3-hidden');\njQuery('#" . $gridId . "').jqGrid({\n url:'" . $url . "',\n datatype: '" . $datatype . "',\n mtype: '" . $mtype . "',\n colNames: [" . $colNames . "],\n colModel: [" . $colModel . "],\n pager: '#" . $gridPagerId . "',\n rowNum: " . $rowNum . ",\n rowList: " . $rowList . ",\n sortname: '" . $sortname . "',\n sortorder: '" . $sortorder . "',\n viewrecords: " . ($viewrecords === false ? 'false' : 'true') . "," . ($displayTitlebar ? "\n caption: '" . $title . "'," : '') . "\n height: " . $height . ",\n gridComplete: function(){" . ($displaySGrid === true ? "\n if(jQuery('#" . $sGridWrapperId . "').css('display') != 'none')\n jQuery('#" . $sGridWrapperId . "').hide();" : '') . "\n },\n loadComplete: function(){" . ($displaySGrid === true && $hasLinkIcon === true ? ' ' . MClientScript::registerScript('linkIcon', array('box' => 'w3-ig'), true) . ($registerGridLinkIcon ? ' ' . MClientScript::registerScript('gridLinkIcon', array('controllerId' => $controllerId, 'gridId' => $gridId), true) : '') : '') . "\n }\n});\njQuery('#" . $gridId . "').jqGrid('navGrid','#" . $gridPagerId . "',{edit:false,add:false,del:false});"); /* gridComplete is called after most of the grid changes * loadComplete is called only after data is loaded*/ Yii::app()->getClientScript()->registerCssFile(Yii::app()->request->baseUrl . '/static/css/jqgrid/ui.jqgrid.css'); Yii::app()->getClientScript()->registerScriptFile(Yii::app()->request->baseUrl . '/static/js/jqgrid/i18n/grid.locale-' . (MPath::jqGridLocaleExists(Yii::app()->language) ? Yii::app()->language : 'en') . '.js', CClientScript::POS_BEGIN); Yii::app()->getClientScript()->registerScriptFile(Yii::app()->request->baseUrl . '/static/js/jqgrid/jquery.jqGrid.min.js', CClientScript::POS_BEGIN); } /*end if displayGrid*/
public static function extract($archivename, $extractdir) { mimport('framework.filesystem.file'); mimport('framework.filesystem.folder'); $untar = false; $result = false; $ext = MFile::getExt(strtolower($archivename)); // Check if a tar is embedded...gzip/bzip2 can just be plain files! if (MFile::getExt(MFile::stripExt(strtolower($archivename))) == 'tar') { $untar = true; } switch ($ext) { case 'zip': $adapter = MArchive::getAdapter('zip'); if ($adapter) { $result = $adapter->extract($archivename, $extractdir); } break; case 'tar': $adapter = MArchive::getAdapter('tar'); if ($adapter) { $result = $adapter->extract($archivename, $extractdir); } break; case 'tgz': // This format is a tarball gzip'd $untar = true; case 'gz': case 'gzip': // This may just be an individual file (e.g. sql script) $adapter = MArchive::getAdapter('gzip'); if ($adapter) { $config = MFactory::getConfig(); $tmpfname = $config->get('tmp_path') . '/' . uniqid('gzip'); $gzresult = $adapter->extract($archivename, $tmpfname); if ($gzresult instanceof Exception) { @unlink($tmpfname); return false; } if ($untar) { // Try to untar the file $tadapter = MArchive::getAdapter('tar'); if ($tadapter) { $result = $tadapter->extract($tmpfname, $extractdir); } } else { $path = MPath::clean($extractdir); MFolder::create($path); $result = MFile::copy($tmpfname, $path . '/' . MFile::stripExt(MFile::getName(strtolower($archivename))), null, 1); } @unlink($tmpfname); } break; case 'tbz2': // This format is a tarball bzip2'd $untar = true; case 'bz2': case 'bzip2': // This may just be an individual file (e.g. sql script) $adapter = MArchive::getAdapter('bzip2'); if ($adapter) { $config = MFactory::getConfig(); $tmpfname = $config->get('tmp_path') . '/' . uniqid('bzip2'); $bzresult = $adapter->extract($archivename, $tmpfname); if ($bzresult instanceof Exception) { @unlink($tmpfname); return false; } if ($untar) { // Try to untar the file $tadapter = MArchive::getAdapter('tar'); if ($tadapter) { $result = $tadapter->extract($tmpfname, $extractdir); } } else { $path = MPath::clean($extractdir); MFolder::create($path); $result = MFile::copy($tmpfname, $path . '/' . MFile::stripExt(MFile::getName(strtolower($archivename))), null, 1); } @unlink($tmpfname); } break; default: MError::raiseWarning(10, MText::_('MLIB_FILESYSTEM_UNKNOWNARCHIVETYPE')); return false; break; } if (!$result || $result instanceof Exception) { return false; } return true; }
protected function createView($name, $prefix = '', $type = '', $config = array()) { // Clean the view name $viewName = preg_replace('/[^A-Z0-9_]/i', '', $name); $classPrefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix); $viewType = preg_replace('/[^A-Z0-9_]/i', '', $type); // Build the view class name $viewClass = $classPrefix . $viewName; if (!class_exists($viewClass)) { mimport('framework.filesystem.path'); $path = MPath::find($this->paths['view'], $this->createFileName('view', array('name' => $viewName, 'type' => $viewType))); if ($path) { require_once $path; if (!class_exists($viewClass)) { MError::raiseError(500, MText::sprintf('MLIB_APPLICATION_ERROR_VIEW_CLASS_NOT_FOUND', $viewClass, $path)); return null; } } else { return null; } } return new $viewClass($config); }
public static function listFolderTree($path, $filter, $maxLevel = 3, $level = 0, $parent = 0) { $dirs = array(); if ($level == 0) { $GLOBALS['_MFolder_folder_tree_index'] = 0; } if ($level < $maxLevel) { $folders = self::folders($path, $filter); // First path, index foldernames foreach ($folders as $name) { $id = ++$GLOBALS['_MFolder_folder_tree_index']; $fullName = MPath::clean($path . '/' . $name); $dirs[] = array('id' => $id, 'parent' => $parent, 'name' => $name, 'fullname' => $fullName, 'relname' => str_replace(MPATH_ROOT, '', $fullName)); $dirs2 = self::listFolderTree($fullName, $filter, $maxLevel, $level + 1, $id); $dirs = array_merge($dirs, $dirs2); } } return $dirs; }
/** * jQuery UI CSS Framework. * Path is {root}/css/ui/{interface} * @param string $value */ public static function setInterface($value) { $availableInterfaces = self::getAvailableInterfaces(); if ($value === self::_default) { if (MPath::interfaceExists(self::$coreDefaultData['interface'])) { $value = self::$coreDefaultData['interface']; } else { self::log(array('method' => __METHOD__, 'value' => $value, 'append' => self::$coreDefaultData['interface'])); return false; } } else { if (!is_string($value) && !is_int($value) || !array_key_exists($value, $availableInterfaces) || !MPath::interfaceExists($value)) { $append = W3::t('system', 'Available interfaces: {availableInterfaces}.', array('{availableInterfaces}' => var_export($availableInterfaces, true))); self::log(array('method' => __METHOD__, 'value' => $value, 'append' => $append)); $value = self::$coreDefaultData['interface']; // set the wrong value to default } } self::$coreData['interface'] = $value; }
public static function check($path, $ds = DIRECTORY_SEPARATOR) { if (strpos($path, '..') !== false) { MError::raiseError(20, 'MPath::check Use of relative paths not permitted'); mexit(); } $path = MPath::clean($path); if (MPATH_ROOT != '' && strpos($path, MPath::clean(MPATH_ROOT)) !== 0) { // Don't translate //MError::raiseError(20, 'MPath::check Snooping out of bounds @ ' . $path); //mexit(); } return $path; }
protected function getInput() { // Get the client id. $clientId = $this->element['client_id']; if (is_null($clientId) && $this->form instanceof MForm) { $clientId = $this->form->getValue('client_id'); } $clientId = (int) $clientId; $client = MApplicationHelper::getClientInfo($clientId); // Get the module. $module = (string) $this->element['module']; if (empty($module) && $this->form instanceof MForm) { $module = $this->form->getValue('module'); } $module = preg_replace('#\\W#', '', $module); // Get the template. $template = (string) $this->element['template']; $template = preg_replace('#\\W#', '', $template); // Get the style. if ($this->form instanceof MForm) { $template_style_id = $this->form->getValue('template_style_id'); } $template_style_id = preg_replace('#\\W#', '', $template_style_id); // If an extension and view are present build the options. if ($module && $client) { // Load language file $lang = MFactory::getLanguage(); $lang->load($module . '.sys', $client->path, null, false, false) || $lang->load($module . '.sys', $client->path . '/modules/' . $module, null, false, false) || $lang->load($module . '.sys', $client->path, $lang->getDefault(), false, false) || $lang->load($module . '.sys', $client->path . '/modules/' . $module, $lang->getDefault(), false, false); // Get the database object and a new query object. $db = MFactory::getDBO(); $query = $db->getQuery(true); // Build the query. $query->select('element, name'); $query->from('#__extensions as e'); $query->where('e.client_id = ' . (int) $clientId); $query->where('e.type = ' . $db->quote('template')); $query->where('e.enabled = 1'); if ($template) { $query->where('e.element = ' . $db->quote($template)); } if ($template_style_id) { $query->join('LEFT', '#__template_styles as s on s.template=e.element'); $query->where('s.id=' . (int) $template_style_id); } // Set the query and load the templates. $db->setQuery($query); $templates = $db->loadObjectList('element'); // Check for a database error. if ($db->getErrorNum()) { MError::raiseWarning(500, $db->getErrorMsg()); } // Build the search paths for module layouts. $module_path = MPath::clean($client->path . '/modules/' . $module . '/tmpl'); // Prepare array of component layouts $module_layouts = array(); // Prepare the grouped list $groups = array(); // Add the layout options from the module path. if (is_dir($module_path) && ($module_layouts = MFolder::files($module_path, '^[^_]*\\.php$'))) { // Create the group for the module $groups['_'] = array(); $groups['_']['id'] = $this->id . '__'; $groups['_']['text'] = MText::sprintf('MOPTION_FROM_MODULE'); $groups['_']['items'] = array(); foreach ($module_layouts as $file) { // Add an option to the module group $value = MFile::stripExt($file); $text = $lang->hasKey($key = strtoupper($module . '_LAYOUT_' . $value)) ? MText::_($key) : $value; $groups['_']['items'][] = MHtml::_('select.option', '_:' . $value, $text); } } // Loop on all templates if ($templates) { foreach ($templates as $template) { // Load language file $lang->load('tpl_' . $template->element . '.sys', $client->path, null, false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path, $lang->getDefault(), false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, $lang->getDefault(), false, false); $template_path = MPath::clean($client->path . '/templates/' . $template->element . '/html/' . $module); // Add the layout options from the template path. if (is_dir($template_path) && ($files = MFolder::files($template_path, '^[^_]*\\.php$'))) { foreach ($files as $i => $file) { // Remove layout that already exist in component ones if (in_array($file, $module_layouts)) { unset($files[$i]); } } if (count($files)) { // Create the group for the template $groups[$template->element] = array(); $groups[$template->element]['id'] = $this->id . '_' . $template->element; $groups[$template->element]['text'] = MText::sprintf('MOPTION_FROM_TEMPLATE', $template->name); $groups[$template->element]['items'] = array(); foreach ($files as $file) { // Add an option to the template group $value = MFile::stripExt($file); $text = $lang->hasKey($key = strtoupper('TPL_' . $template->element . '_' . $module . '_LAYOUT_' . $value)) ? MText::_($key) : $value; $groups[$template->element]['items'][] = MHtml::_('select.option', $template->element . ':' . $value, $text); } } } } } // Compute attributes for the grouped list $attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; // Prepare HTML code $html = array(); // Compute the current selected values $selected = array($this->value); // Add a grouped list $html[] = MHtml::_('select.groupedlist', $groups, $this->name, array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected)); return implode($html); } else { return ''; } }
public static function exists($file) { return is_file(MPath::clean($file)); }
public function loadHelper($hlp = null) { // Clean the file name $file = preg_replace('/[^A-Z0-9_\\.-]/i', '', $hlp); // Load the template script mimport('framework.filesystem.path'); $helper = MPath::find($this->_path['helper'], $this->_createFileName('helper', array('name' => $file))); if ($helper != false) { // Include the requested template filename in the local scope include_once $helper; } }
public function postflight($type, $parent) { if (MFolder::copy(MPath::clean(MPATH_WP_PLG . '/miwosql/languages'), MPath::clean(MPATH_WP_CNT . '/miwi/languages'), null, true)) { MFolder::delete(MPath::clean(MPATH_WP_PLG . '/miwosql/languages')); } }
public function loadButtonType($type, $new = false) { $signature = md5($type); if (isset($this->_buttons[$signature]) && $new === false) { return $this->_buttons[$signature]; } if (!class_exists('MButton')) { MError::raiseWarning('SOME_ERROR_CODE', MText::_('MLIB_HTML_BUTTON_BASE_CLASS')); return false; } $buttonClass = 'MButton' . $type; if (!class_exists($buttonClass)) { if (isset($this->_buttonPath)) { $dirs = $this->_buttonPath; } else { $dirs = array(); } $file = MFilterInput::getInstance()->clean(str_replace('_', DIRECTORY_SEPARATOR, strtolower($type)) . '.php', 'path'); mimport('framework.filesystem.path'); if ($buttonFile = MPath::find($dirs, $file)) { include_once $buttonFile; } else { MError::raiseWarning('SOME_ERROR_CODE', MText::sprintf('MLIB_HTML_BUTTON_NO_LOAD', $buttonClass, $buttonFile)); return false; } } if (!class_exists($buttonClass)) { //return MError::raiseError('SOME_ERROR_CODE', "Module file $buttonFile does not contain class $buttonClass."); return false; } $this->_buttons[$signature] = new $buttonClass($this); return $this->_buttons[$signature]; }
public function loadFile($file, $reset = true, $xpath = false) { // Check to see if the path is an absolute path. if (!is_file($file)) { // Not an absolute path so let's attempt to find one using MPath. $file = MPath::find(self::addFormPath(), strtolower($file) . '.xml'); // If unable to find the file return false. if (!$file) { return false; } } // Attempt to load the XML file. $xml = MFactory::getXML($file, true); return $this->load($xml, $reset, $xpath); }
protected function getInput() { // Initialize variables. // Get the client id. $clientId = $this->element['client_id']; if (is_null($clientId) && $this->form instanceof MForm) { $clientId = $this->form->getValue('client_id'); } $clientId = (int) $clientId; $client = MApplicationHelper::getClientInfo($clientId); // Get the extension. $extn = (string) $this->element['extension']; if (empty($extn) && $this->form instanceof MForm) { $extn = $this->form->getValue('extension'); } $extn = preg_replace('#\\W#', '', $extn); // Get the template. $template = (string) $this->element['template']; $template = preg_replace('#\\W#', '', $template); // Get the style. if ($this->form instanceof MForm) { $template_style_id = $this->form->getValue('template_style_id'); } $template_style_id = preg_replace('#\\W#', '', $template_style_id); // Get the view. $view = (string) $this->element['view']; $view = preg_replace('#\\W#', '', $view); // If a template, extension and view are present build the options. if ($extn && $view && $client) { // Load language file $lang = MFactory::getLanguage(); $lang->load($extn . '.sys', MPATH_ADMINISTRATOR, null, false, false) || $lang->load($extn . '.sys', MPATH_ADMINISTRATOR . '/components/' . $extn, null, false, false) || $lang->load($extn . '.sys', MPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load($extn . '.sys', MPATH_ADMINISTRATOR . '/components/' . $extn, $lang->getDefault(), false, false); // Get the database object and a new query object. $db = MFactory::getDBO(); $query = $db->getQuery(true); // Build the query. $query->select('e.element, e.name'); $query->from('#__extensions as e'); $query->where('e.client_id = ' . (int) $clientId); $query->where('e.type = ' . $db->quote('template')); $query->where('e.enabled = 1'); if ($template) { $query->where('e.element = ' . $db->quote($template)); } if ($template_style_id) { $query->join('LEFT', '#__template_styles as s on s.template=e.element'); $query->where('s.id=' . (int) $template_style_id); } // Set the query and load the templates. $db->setQuery($query); $templates = $db->loadObjectList('element'); // Check for a database error. if ($db->getErrorNum()) { MError::raiseWarning(500, $db->getErrorMsg()); } // Build the search paths for component layouts. $component_path = MPath::clean($client->path . '/components/' . $extn . '/views/' . $view . '/tmpl'); // Prepare array of component layouts $component_layouts = array(); // Prepare the grouped list $groups = array(); // Add a Use Global option if useglobal="true" in XML file if ($this->element['useglobal'] == 'true') { $groups[MText::_('MOPTION_FROM_STANDARD')]['items'][] = MHtml::_('select.option', '', MText::_('MGLOBAL_USE_GLOBAL')); } // Add the layout options from the component path. if (is_dir($component_path) && ($component_layouts = MFolder::files($component_path, '^[^_]*\\.xml$', false, true))) { // Create the group for the component $groups['_'] = array(); $groups['_']['id'] = $this->id . '__'; $groups['_']['text'] = MText::sprintf('MOPTION_FROM_COMPONENT'); $groups['_']['items'] = array(); foreach ($component_layouts as $i => $file) { // Attempt to load the XML file. if (!($xml = simplexml_load_file($file))) { unset($component_layouts[$i]); continue; } // Get the help data from the XML file if present. if (!($menu = $xml->xpath('layout[1]'))) { unset($component_layouts[$i]); continue; } $menu = $menu[0]; // Add an option to the component group $value = MFile::stripext(MFile::getName($file)); $component_layouts[$i] = $value; $text = isset($menu['option']) ? MText::_($menu['option']) : (isset($menu['title']) ? MText::_($menu['title']) : $value); $groups['_']['items'][] = MHtml::_('select.option', '_:' . $value, $text); } } // Loop on all templates if ($templates) { foreach ($templates as $template) { // Load language file $lang->load('tpl_' . $template->element . '.sys', $client->path, null, false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path, $lang->getDefault(), false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, $lang->getDefault(), false, false); $template_path = MPath::clean($client->path . '/templates/' . $template->element . '/html/' . $extn . '/' . $view); // Add the layout options from the template path. if (is_dir($template_path) && ($files = MFolder::files($template_path, '^[^_]*\\.php$', false, true))) { // Files with corresponding XML files are alternate menu items, not alternate layout files // so we need to exclude these files from the list. $xml_files = MFolder::files($template_path, '^[^_]*\\.xml$', false, true); for ($j = 0, $count = count($xml_files); $j < $count; $j++) { $xml_files[$j] = MFile::stripext(MFile::getName($xml_files[$j])); } foreach ($files as $i => $file) { // Remove layout files that exist in the component folder or that have XML files if (in_array(MFile::stripext(MFile::getName($file)), $component_layouts) || in_array(MFile::stripext(MFile::getName($file)), $xml_files)) { unset($files[$i]); } } if (count($files)) { // Create the group for the template $groups[$template->name] = array(); $groups[$template->name]['id'] = $this->id . '_' . $template->element; $groups[$template->name]['text'] = MText::sprintf('MOPTION_FROM_TEMPLATE', $template->name); $groups[$template->name]['items'] = array(); foreach ($files as $file) { // Add an option to the template group $value = MFile::stripext(MFile::getName($file)); $text = $lang->hasKey($key = strtoupper('TPL_' . $template->name . '_' . $extn . '_' . $view . '_LAYOUT_' . $value)) ? MText::_($key) : $value; $groups[$template->name]['items'][] = MHtml::_('select.option', $template->element . ':' . $value, $text); } } } } } // Compute attributes for the grouped list $attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; // Prepare HTML code $html = array(); // Compute the current selected values $selected = array($this->value); // Add a grouped list $html[] = MHtml::_('select.groupedlist', $groups, $this->name, array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected)); return implode($html); } else { return ''; } }
public static function setAllTempImageFolders($path = null) { if (!empty($path)) { $a = false; $arr = Yii::app()->params['storeImages']; foreach ($arr as $params => $value) { if ($params == $path) { $a = true; break; } } if ($a === true) { $param = Yii::app()->params['storeImages'][$path]; if (isset($param) && !empty($param)) { $tempdir = Yii::getPathOfAlias($param); } } else { echo 'error, wrong param'; return false; } } else { $tempdir = Yii::getPathOfAlias(Yii::app()->params['storeImages']['thumbPath']); } MPath::setPermissions($tempdir, null, Yii::app()->params['storeImages']['dirMode']); // without octdec becose it will set in MPath }
public static function addIncludePath($path = '') { // Force path to array settype($path, 'array'); // Loop through the path directories foreach ($path as $dir) { if (!empty($dir) && !in_array($dir, MHtml::$includePaths)) { mimport('joomla.filesystem.path'); array_unshift(MHtml::$includePaths, MPath::clean($dir)); } } return MHtml::$includePaths; }