function &createTemplate($option, $isAdmin = false, $useCache = false) { global $mainframe; $bodyHtml = ''; $files = null; jimport('joomla.template.template'); $tmpl = new JTemplate(); // load the wrapper and common templates $tmpl->readTemplatesFromFile('page.html'); $tmpl->applyInputFilter('ShortModifiers'); // load the stock templates if (is_array($files)) { foreach ($files as $file) { $tmpl->readTemplatesFromInput($file); } } // TODO: Do the protocol better $tmpl->addVar('form', 'formAction', basename(str_replace(array('"', '<', '>', "'"), '', $_SERVER["PHP_SELF"]))); $tmpl->addVar('form', 'formName', 'adminForm'); $tmpl->setRoot(dirname(__FILE__) . '/tmpl'); $tmpl->setNamespace('mos'); if ($bodyHtml) { $tmpl->setAttribute('body', 'src', $bodyHtml); } return $tmpl; }
/** * Create a template object * * @access private * @param array An array of support template files to load * @return object JTemplate * @since 1.5 */ function &_createTemplate($files = array()) { jimport('joomla.template.template'); $conf =& JFactory::getConfig(); $tmpl = new JTemplate(); // patTemplate if ($conf->getValue('config.caching')) { $tmpl->enableTemplateCache('File', JPATH_BASE . DS . 'cache' . DS); } $tmpl->setNamespace('jtmpl'); // load the wrapper and common templates $tmpl->readTemplatesFromFile('page.html'); $tmpl->applyInputFilter('ShortModifiers'); // load the stock templates if (is_array($files)) { foreach ($files as $file) { $tmpl->readTemplatesFromInput($file); } } $tmpl->addGlobalVar('option', $GLOBALS['option']); $tmpl->addGlobalVar('self', str_replace(array('"', '<', '>', "'"), '', $_SERVER["PHP_SELF"])); $tmpl->addGlobalVar('uri_query', $_SERVER['QUERY_STRING']); $tmpl->addGlobalVar('REQUEST_URI', JRequest::getURI()); if (isset($GLOBALS['Itemid'])) { $tmpl->addGlobalVar('itemid', $GLOBALS['Itemid']); } return $tmpl; }
/** * Save the configuration information * * @return boolean True if successful * @access public * @since 1.5 */ function saveConfig() { global $mainframe; $vars =& $this->getVars(); $lang =& JFactory::getLanguage(); // Import authentication library jimport('joomla.user.helper'); // Set some needed variables $vars['siteUrl'] = JURI::root(); $vars['secret'] = JUserHelper::genRandomPassword(16); $vars['offline'] = JText::_('STDOFFLINEMSG'); $vars['errormsg'] = JText::_('STDERRORMSG'); $vars['metadesc'] = JText::_('STDMETADESC'); $vars['metakeys'] = JText::_('STDMETAKEYS'); $vars['tmp_path'] = JPATH_ROOT . DS . 'tmp'; $vars['log_path'] = JPATH_ROOT . DS . 'logs'; // set default language $forced = $mainframe->getLocalise(); if (empty($forced['lang'])) { $vars['deflang'] = 'en-GB'; $vars['bclang'] = 'english'; } else { $vars['deflang'] = $forced['lang']; $vars['bclang'] = $lang->getBackwardLang(); } if (empty($forced['helpurl'])) { $vars['helpurl'] = 'http://help.joomla.org'; } else { $vars['helpurl'] = $forced['helpurl']; } // If FTP has not been enabled, set the value to 0 if (!isset($vars['ftpEnable'])) { $vars['ftpEnable'] = 0; } /* * Trim the last slash from the FTP root, as the FTP root usually replaces JPATH_ROOT. * If the path had a trailing slash, this would lead to double slashes, like "/joomla//configuration.php" */ if (isset($vars['ftpRoot'])) { $vars['ftpRoot'] = rtrim($vars['ftpRoot'], '/'); } switch ($vars['DBtype']) { case 'mssql': $vars['ZERO_DATE'] = '1/01/1990'; break; default: $vars['ZERO_DATE'] = '0000-00-00 00:00:00'; break; } JInstallationHelper::createAdminUser($vars); /** * Write the configuration file */ jimport('joomla.template.template'); $tmpl = new JTemplate(); $tmpl->applyInputFilter('ShortModifiers'); // load the wrapper and common templates $tmpl->setRoot(JPATH_BASE . DS . 'template' . DS . 'tmpl'); $tmpl->readTemplatesFromFile('configuration.html'); $tmpl->addVars('configuration', $vars, 'var_'); if (empty($vars['ftpSavePass'])) { $tmpl->addVar('configuration', 'var_ftpuser', ''); $tmpl->addVar('configuration', 'var_ftppassword', ''); } $buffer = $tmpl->getParsedTemplate('configuration'); $path = JPATH_CONFIGURATION . DS . 'configuration.php'; if (file_exists($path)) { $canWrite = is_writable($path); } else { $canWrite = is_writable(JPATH_CONFIGURATION . DS); } /* * If the file exists but isn't writable OR if the file doesn't exist and the parent directory * is not writable we need to use FTP */ $ftpFlag = false; if (file_exists($path) && !is_writable($path) || !file_exists($path) && !is_writable(dirname($path) . '/')) { $ftpFlag = true; } // Check for safe mode if (ini_get('safe_mode')) { $ftpFlag = true; } // Enable/Disable override if (!isset($vars['ftpEnable']) || $vars['ftpEnable'] != 1) { $ftpFlag = false; } if ($ftpFlag == true) { // Connect the FTP client jimport('joomla.client.ftp'); jimport('joomla.filesystem.path'); $ftp =& JFTP::getInstance($vars['ftpHost'], $vars['ftpPort']); $ftp->login($vars['ftpUser'], $vars['ftpPassword']); // Translate path for the FTP account $file = JPath::clean(str_replace(JPATH_CONFIGURATION, $vars['ftpRoot'], $path), '/'); // Use FTP write buffer to file if (!$ftp->write($file, $buffer)) { $this->setData('buffer', $buffer); return false; } $ftp->quit(); } else { if ($canWrite) { file_put_contents($path, $buffer); } else { $this->setData('buffer', $buffer); return true; } } return true; }