コード例 #1
0
ファイル: model.php プロジェクト: kumarsivarajan/jaderp
 /**
  * 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;
 }
コード例 #2
0
ファイル: model.php プロジェクト: raeldc/com_learn
	/**
	 * 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 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'], '/');
		}

		JInstallationHelper::createAdminUser($vars);

		/**
		 * Write the configuration file
		 */
		$configuration[] = '<?php';
		$configuration[] = 'class JConfig';
		$configuration[] = '{';
		$configuration[] = "\t".'/* Site Settings */';
		$configuration[] = "\t".'var $offline = \'0\';';
		$configuration[] = "\t".'var $offline_message = \''.$vars['offline'].'\';';
		$configuration[] = "\t".'var $sitename = \''.$vars['siteName'].'\';';
		$configuration[] = "\t".'var $editor = \'tinymce\';';
		$configuration[] = "\t".'var $list_limit = \'20\';';
		$configuration[] = "\t".'/* Debug Settings */';
		$configuration[] = "\t".'var $debug = \'0\';';
		$configuration[] = "\t".'var $debug_lang = \'0\';';
		$configuration[] = "\t".'/* Database Settings */';
		$configuration[] = "\t".'var $dbtype = \'mysqli\';';
		$configuration[] = "\t".'var $host = \''.$vars['DBhostname'].'\';';
		$configuration[] = "\t".'var $user = \''.$vars['DBuserName'].'\';';
		$configuration[] = "\t".'var $password = \''.$vars['DBpassword'].'\';';
		$configuration[] = "\t".'var $db = \''.$vars['DBname'].'\';';
		$configuration[] = "\t".'var $dbprefix = \''.$vars['DBPrefix'].'\';';
		$configuration[] = "\t".'/* Server Settings */';
		$configuration[] = "\t".'var $live_site = \'\';';
		$configuration[] = "\t".'var $secret = \''.$vars['secret'].'\';';
		$configuration[] = "\t".'var $gzip = \'0\';';
		$configuration[] = "\t".'var $error_reporting = \'-1\';';
		$configuration[] = "\t".'var $ftp_host = \''.$vars['ftpHost'].'\';';
		$configuration[] = "\t".'var $ftp_port = \''.$vars['ftpRoot'].'\';';
		$configuration[] = "\t".'var $ftp_user = \''.$vars['ftpUser'].'\';';
		$configuration[] = "\t".'var $ftp_pass = \''.$vars['ftpPassword'].'\';';
		$configuration[] = "\t".'var $ftp_root = \''.$vars['ftpRoot'].'\';';
		$configuration[] = "\t".'var $ftp_enable = \''.$vars['ftpEnable'].'\';';
		$configuration[] = "\t".'var $force_ssl = \'0\';';
		$configuration[] = "\t".'/* Locale Settings */';
		$configuration[] = "\t".'var $offset = \'0\';';
		$configuration[] = "\t".'var $offset_user = \'0\';';
		$configuration[] = "\t".'/* Mail Settings */';
		$configuration[] = "\t".'var $mailer = \'mail\';';
		$configuration[] = "\t".'var $mailfrom = \''.$vars['adminEmail'].'\';';
		$configuration[] = "\t".'var $fromname = \''.$vars['siteName'].'\';';
		$configuration[] = "\t".'var $sendmail = \'/usr/sbin/sendmail\';';
		$configuration[] = "\t".'var $smtpauth = \'0\';';
		$configuration[] = "\t".'var $smtpsecure = \'none\';';
		$configuration[] = "\t".'var $smtpport = \'25\';';
		$configuration[] = "\t".'var $smtpuser = \'\';';
		$configuration[] = "\t".'var $smtppass = \'\';';
		$configuration[] = "\t".'var $smtphost = \'localhost\';';
		$configuration[] = "\t".'/* Cache Settings */';
		$configuration[] = "\t".'var $caching = \'0\';';
		$configuration[] = "\t".'var $cachetime = \'15\';';
		$configuration[] = "\t".'var $cache_handler = \'file\';';
		$configuration[] = "\t".'/* SEO Settings */';
		$configuration[] = "\t".'var $sef           = \'1\';';
		$configuration[] = "\t".'var $sef_rewrite   = \'0\';';
		$configuration[] = "\t".'var $sef_suffix    = \'1\';';
		$configuration[] = "\t".'/* Feed Settings */';
		$configuration[] = "\t".'var $feed_limit   = \'10\';';
		$configuration[] = "\t".'var $log_path = \''.$vars['log_path'].'\';';
		$configuration[] = "\t".'var $tmp_path = \''.$vars['tmp_path'].'\';';
		$configuration[] = "\t".'/* Session Setting */';
		$configuration[] = "\t".'var $lifetime = \'15\';';
		$configuration[] = "\t".'var $session_handler = \'database\';';
		$configuration[] = '}';		 
		
		$buffer = implode(PHP_EOL, $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;
	}