Exemple #1
0
 /**
  * Get the state variables pertaining to the FTP connection
  * 
  * @staticvar  \stdClass  $statevars
  * 
  * @return  \stdClass  A stdClass object with the variables
  */
 public function getStateVariables()
 {
     static $statevars = null;
     if (is_null($statevars)) {
         $statevars = new stdClass();
         $vars = array('hostname', 'port', 'username', 'password', 'directory');
         foreach ($vars as $v) {
             $value = $this->getState($v, null, 'raw');
             $statevars->{$v} = $value;
             switch ($v) {
                 case 'hostname':
                     if (empty($statevars->{$v})) {
                         $uri = AUri::getInstance();
                         $statevars->{$v} = $uri->getHost();
                     }
                     break;
                 case 'port':
                     $statevars->{$v} = (int) $statevars->{$v};
                     if ($statevars->{$v} <= 0 || $statevars->{$v} >= 65536) {
                         $statevars->{$v} = 21;
                     }
                     break;
             }
         }
     }
     return $statevars;
 }
 public function onBeforeMain()
 {
     if ($this->input->get('layout') != 'init') {
         return true;
     }
     // Assign the results of the various checks
     $this->reqSettings = $this->getModel()->getRequired();
     $this->reqMet = $this->getModel()->isRequiredMet();
     $this->recommendedSettings = $this->getModel()->getRecommended();
     $this->extraInfo = $this->getModel()->getExtraInfo();
     $this->joomlaVersion = ASession::getInstance()->get('jversion');
     // Am I restoring to a different site?
     $this->restoringToDifferentHost = false;
     if (isset($this->extraInfo['host'])) {
         $uri = AUri::getInstance();
         $this->restoringToDifferentHost = $this->extraInfo['host']['current'] != $uri->getHost();
     }
     // Am I restoring to a different PHP version?
     $this->restoringToDifferentPHP = false;
     if (isset($this->extraInfo['php_version'])) {
         $parts = explode('.', $this->extraInfo['php_version']['current']);
         $sourceVersion = $parts[0] . '.' . $parts[1];
         $parts = explode('.', PHP_VERSION);
         $targetVersion = $parts[0] . '.' . $parts[1];
         $this->restoringToDifferentPHP = $sourceVersion != $targetVersion;
     }
     // If I am restoring to a different host blank out the database
     // connection information to prevent unpleasant situations, like a user
     // "accidentally" overwriting his original site's database...
     if ($this->restoringToDifferentHost && !ASession::getInstance()->get('main.resetdbinfo', false)) {
         $this->getModel()->resetDatabaseConnectionInformation();
     }
     return true;
 }
Exemple #3
0
 public function onBeforeMain()
 {
     if ($this->input->get('layout') != 'init') {
         return true;
     }
     /** @var AngieModelBaseMain $model */
     $model = $this->getModel();
     /** @var ASession $session */
     $session = $this->container->session;
     // Assign the results of the various checks
     $this->reqSettings = $model->getRequired();
     $this->reqMet = $model->isRequiredMet();
     $this->recommendedSettings = $model->getRecommended();
     $this->extraInfo = $model->getExtraInfo();
     $this->joomlaVersion = $session->get('jversion');
     $this->version = $session->get('version');
     // Am I restoring to a different site?
     $this->restoringToDifferentHost = false;
     if (isset($this->extraInfo['host'])) {
         $uri = AUri::getInstance();
         $this->restoringToDifferentHost = $this->extraInfo['host']['current'] != $uri->getHost();
     }
     // If I am restoring to a different host blank out the database
     // connection information to prevent unpleasant situations, like a user
     // "accidentally" overwriting his original site's database...
     if ($this->restoringToDifferentHost && !$session->get('main.resetdbinfo', false)) {
         $model->resetDatabaseConnectionInformation();
     }
     return true;
 }
Exemple #4
0
 /**
  * Gets the basic site parameters
  *
  * @return  array
  */
 protected function getSiteParamsVars()
 {
     $siteurl = str_replace('/installation/', '', AUri::root());
     $homeurl = str_replace('/installation/', '', AUri::root());
     $ret = array('blogname' => $this->getState('blogname', $this->configModel->get('blogname', 'Restored website')), 'blogdescription' => $this->getState('blogdescription', $this->configModel->get('blogdescription', 'Restored website')), 'dbcharset' => $this->getState('dbcharset', $this->configModel->get('dbcharset', 'utf_8')), 'dbcollation' => $this->getState('dbcollation', $this->configModel->get('dbcollation', '')), 'homeurl' => $this->getState('homeurl', $homeurl), 'siteurl' => $this->getState('siteurl', $siteurl));
     require_once APATH_INSTALLATION . '/angie/helpers/setup.php';
     $ret['homeurl'] = AngieHelperSetup::cleanLiveSite($ret['homeurl']);
     $ret['siteurl'] = AngieHelperSetup::cleanLiveSite($ret['siteurl']);
     $this->configModel->set('siteurl', $ret['siteurl']);
     $this->configModel->set('homeurl', $ret['homeurl']);
     // Special handling: if we were told to downgrade data from utf8mb4 to utf8 and the dbcharset or dbcollation
     // contains utf8mb4 we have to downgrade that too to utf8.
     /** @var AngieModelDatabase $dbModel */
     $dbModel = AModel::getTmpInstance('Database', 'AngieModel');
     $allDbIni = $dbModel->getDatabasesIni();
     $dbNames = $dbModel->getDatabaseNames();
     $firstDb = array_shift($dbNames);
     $dbIni = $allDbIni[$firstDb];
     $dbOptions = array('driver' => $dbIni['dbtype'], 'database' => $dbIni['dbname'], 'select' => 0, 'host' => $dbIni['dbhost'], 'user' => $dbIni['dbuser'], 'password' => $dbIni['dbpass'], 'prefix' => $dbIni['prefix']);
     $db = ADatabaseDriver::getInstance($dbOptions);
     $downgradeUtf8 = $dbIni['utf8tables'] && (!$dbIni['utf8mb4'] || $dbIni['utf8mb4'] && !$db->supportsUtf8mb4());
     if ($downgradeUtf8) {
         $ret['dbcharset'] = str_replace('utf8mb4', 'utf8', $ret['dbcharset']);
         $ret['dbcollation'] = str_replace('utf8mb4', 'utf8', $ret['dbcollation']);
         $this->configModel->set('dbcharset', $ret['dbcharset']);
         $this->configModel->set('dbcollation', $ret['dbcollation']);
     }
     return $ret;
 }
Exemple #5
0
 /**
  * Gets the basic site parameters
  *
  * @return  array
  */
 protected function getSiteParamsVars()
 {
     $siteurl = str_replace('/installation/', '', AUri::root());
     $ret = array('sitename' => $this->getState('sitename', $this->configModel->get('sitename', 'Restored website')), 'siteurl' => $this->getState('siteurl', $siteurl));
     require_once APATH_INSTALLATION . '/angie/helpers/setup.php';
     $ret['siteurl'] = AngieHelperSetup::cleanLiveSite($ret['siteurl']);
     $this->configModel->set('siteurl', $ret['siteurl']);
     return $ret;
 }
Exemple #6
0
 /**
  * Gets the basic site parameters
  *
  * @return  array
  */
 protected function getSiteParamsVars()
 {
     // Do I have a www_root coming from UNiTE? If so, use it
     $wwwroot = $this->input->get('livesite', AUri::root());
     $wwwroot = str_replace('/installation/', '', $wwwroot);
     // Create the host from the wwwroot - This regex is not optimal, but let's use the same used by Moodle
     preg_match('|^[a-z]+://([a-zA-Z0-9-.]+)|i', $wwwroot, $matches);
     $wwwhost = $matches[1];
     $ret = array('fullname' => $this->getState('fullname', $this->configModel->get('fullname', 'Restored Moodle')), 'shortname' => $this->getState('shortname', $this->configModel->get('shortname', 'Moodle')), 'wwwroot' => $this->getState('wwwroot', $wwwroot), 'dataroot' => $this->getState('dataroot', $this->configModel->get('dataroot', '')), 'chat_host' => $this->getState('chat_host', $this->configModel->get('chat_host', $wwwhost)), 'chat_ip' => $this->getState('chat_ip', $this->configModel->get('chat_ip', isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '')));
     require_once APATH_INSTALLATION . '/angie/helpers/setup.php';
     $ret['wwwroot'] = AngieHelperSetup::cleanLiveSite($ret['wwwroot']);
     $this->configModel->set('wwwroot', $ret['wwwroot']);
     return $ret;
 }
Exemple #7
0
 public function onBeforeMain()
 {
     try {
         $stuff = $this->getModel()->getListingAndCrumbs();
         $uri = clone AUri::getInstance();
         $queryParts = $uri->getQuery(true);
         unset($queryParts['directory']);
         $uri->setQuery($queryParts);
         $this->ftppath = $stuff['path'];
         $this->crumbs = $stuff['crumbs'];
         $this->directories = $stuff['directories'];
         $this->badFTP = false;
         $this->ftpError = '';
         $this->baseURL = $uri->toString();
     } catch (Exception $exc) {
         $this->badFTP = true;
         $this->ftpError = $exc->getMessage();
     }
     return true;
 }
Exemple #8
0
 /**
  * Gets the basic site parameters
  *
  * @return  array
  */
 protected function getSiteParamsVars()
 {
     $db = $this->getDatabase();
     $query = $db->getQuery(true)->select($db->qn('config_value'))->from($db->qn('#__config'))->where($db->qn('config_name') . ' = ' . $db->q('sitename'));
     try {
         $sitename = $db->setQuery($query)->loadResult();
     } catch (Exception $e) {
         $sitename = 'Restored website';
     }
     $query = $db->getQuery(true)->select($db->qn('config_value'))->from($db->qn('#__config'))->where($db->qn('config_name') . ' = ' . $db->q('site_desc'));
     try {
         $sitedescr = $db->setQuery($query)->loadResult();
     } catch (Exception $e) {
         $sitedescr = 'Restored website description';
     }
     $siteurl = str_replace('/installation/', '', AUri::root());
     $ret = array('sitename' => $this->getState('sitename', $sitename), 'sitedescr' => $this->getState('sitedescr', $sitedescr), 'siteurl' => $this->getState('siteurl', $siteurl));
     require_once APATH_INSTALLATION . '/angie/helpers/setup.php';
     $ret['siteurl'] = AngieHelperSetup::cleanLiveSite($ret['siteurl']);
     return $ret;
 }
Exemple #9
0
 /**
  * Method to reset class static members for testing and other various issues.
  *
  * @return  void
  */
 public static function reset()
 {
     self::$instances = array();
     self::$base = array();
     self::$root = array();
     self::$current = '';
 }
Exemple #10
0
 /**
  * Renames the directory containing the old host name to the new one
  *
  * @param   string  $directory  Absolute path to the slave directory with the old hostname
  * @param   string  $host       Force the host to a specific domain. This is used when we're restoring using UNiTE
  *
  * @return  string
  */
 public function updateSlaveDirectory($directory, $host = 'SERVER')
 {
     // No need to continue if the directory is not valid
     if (!is_dir($directory)) {
         return $directory;
     }
     // First of all, let's get the old hostname
     /** @var AngieModelDrupal8Main $mainModel */
     $mainModel = AModel::getAnInstance('Main', 'AngieModel', array(), $this->container);
     $extraInfo = $mainModel->getExtraInfo();
     // No host information? Well, let's stop here
     if (!isset($extraInfo['host']) || !$extraInfo['host']) {
         return $directory;
     }
     $uri = AUri::getInstance($host);
     $oldHost = $extraInfo['host']['current'];
     $newHost = $uri->getHost();
     // If the old host name is not inside the folder name, there's no point in continuing
     if (strpos($directory, $oldHost) === false) {
         return $directory;
     }
     // Can't fetch the new host? Let's stop here
     if (!$newHost) {
         return $directory;
     }
     $newDirectory = str_replace($oldHost, $newHost, $directory);
     if (!rename($directory, $newDirectory)) {
         return $directory;
     }
     // Ok, I have successfully renamed the folder, now I have to update the Configuration model
     // since it stores all the values using the folder name
     $oldNamespace = basename($directory);
     $newNamespace = basename($newDirectory);
     /** @var AngieModelDrupal8Configuration $configModel */
     $configModel = $this->configModel;
     $configVars = $configModel->getConfigvars();
     if (isset($configVars[$oldNamespace])) {
         // Let's migrate all the values. Old values are still set, but we can live with that
         foreach ($configVars[$oldNamespace] as $key => $value) {
             $configModel->set($key, $value, $newNamespace);
         }
     }
     // Finally register the association between the old namespace with the new one
     // it will be useful if we have a multi database installation, see AngieModelDrupal7Configuration::getDatabase()
     $configModel->set('hostMapping', array($newNamespace => $oldNamespace), 'default');
     return $newDirectory;
 }
Exemple #11
0
/**
 * @package angi4j
 * @copyright Copyright (C) 2009-2016 Nicholas K. Dionysopoulos. All rights reserved.
 * @author Nicholas K. Dionysopoulos - http://www.dionysopoulos.me
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL v3 or later
 *
 * Akeeba Next Generation Installer For Joomla!
 */
defined('_AKEEBA') or die;
/** @var $this AView */
$document = $this->container->application->getDocument();
$document->addScript('angie/js/json.js');
$document->addScript('angie/js/ajax.js');
$document->addScript('platform/js/setup.js');
$url = 'index.php';
$hashUrl = AUri::base() . 'platform/newhash.php';
$document->addScriptDeclaration(<<<JS
var akeebaAjax = null;
var hashUrl    = '{$hashUrl}';
\$(document).ready(function(){
\takeebaAjax = new akeebaAjaxConnector('{$url}');
});
JS
);
$this->loadHelper('select');
echo $this->loadAnyTemplate('steps/buttons');
echo $this->loadAnyTemplate('steps/steps', array('helpurl' => 'https://www.akeebabackup.com/documentation/solo/angie-drupal-setup.html'));
$key = str_replace('.', '_', $this->input->getCmd('substep', 'default'));
// The modal window is displayed only when we have a multi site environment and we have to change the settings.php
// file multiple times
?>
Exemple #12
0
 /**
  * Internal method to get the default replacements for multisite's URLs
  *
  * @param   AngieModelWordpressConfiguration $config The configuration model
  *
  * @return  array  Any replacements to add
  */
 private function getDefaultReplacementsForMultisite($config)
 {
     $replacements = array();
     $db = $this->getDbo();
     if (!$this->isMultisite($db)) {
         return $replacements;
     }
     // These values are stored inside the session, after the setup step
     $old_url = $config->get('oldurl');
     $new_url = $config->get('homeurl');
     // If the URL didn't change do nothing
     if ($old_url == $new_url) {
         return $replacements;
     }
     // Get the old and new base domain and base path
     $oldUri = new AUri($old_url);
     $newUri = new AUri($new_url);
     $newDomain = $this->removeSubdomain($newUri->getHost());
     $oldDomain = $config->get('domain_current_site', $oldUri->getHost());
     $newPath = $newUri->getPath();
     $oldPath = $config->get('path_current_site', $oldUri->getPath());
     // If the old and new domain are subdomains of the same root domain (e.g. abc.example.com and xyz.example.com),
     // or a subdomain and a root domain (e.g. example.com and abc.example.com) we MUST NOT do domain replacement
     $replaceSubdomains = $this->removeSubdomain($newDomain) != $this->removeSubdomain($oldDomain);
     // If the old and new paths are the same we MUST NOT do path replacement
     $replacePaths = $oldPath != $newPath;
     // Get the multisites information
     $multiSites = $this->getMultisiteMap($db);
     // Get other information
     $mainBlogId = $config->get('blog_id_current_site', 1);
     $useSubdomains = $config->get('subdomain_install', 0);
     // Do I have to replace the domain?
     if ($oldDomain != $newDomain) {
         $replacements[$oldDomain] = $newUri->getHost();
     }
     // Maybe I have to do... nothing?
     if ($useSubdomains && !$replaceSubdomains) {
         return $replacements;
     }
     if (!$useSubdomains) {
         if (!$replacePaths) {
             return $replacements;
         }
     }
     // Loop for each multisite
     foreach ($multiSites as $blogId => $info) {
         // Skip the first site, it is the same as the main site
         if ($blogId == $mainBlogId) {
             continue;
         }
         // Multisites using subdomains?
         if ($useSubdomains) {
             // Extract the subdomain
             $subdomain = substr($info['domain'], 0, -strlen($oldDomain));
             // Add a replacement for this domain
             $replacements[$info['domain']] = $subdomain . $newDomain;
             continue;
         }
         // Multisites using subdirectories. Let's check if I have to extract the old path.
         $path = strpos($info['path'], $oldPath) === 0 ? substr($info['path'], strlen($oldPath)) : $info['path'];
         // Construct the new path and add it to the list of replacements
         $path = trim($path, '/');
         $newMSPath = $newPath . '/' . $path;
         $newMSPath = trim($newMSPath, '/');
         $replacements[$info['path']] = '/' . $newMSPath;
     }
     // Important! We have to change subdomains BEFORE the main domain. And for this, we need to reverse the
     // replacements table. If you're wondering why: old domain example.com, new domain www.example.net. This
     // makes blog1.example.com => blog1.www.example.net instead of blog1.example.net (note the extra www). Oops!
     $replacements = array_reverse($replacements);
     return $replacements;
 }
Exemple #13
0
 public function updatehtaccess()
 {
     // Let's build the stack of possible files
     $files = array(APATH_ROOT . '/.htaccess', APATH_ROOT . '/htaccess.bak');
     // Do I want to give more importance to .bak file first?
     if ($this->input->getInt('bak_first', 0)) {
         rsort($files);
     }
     $fileName = false;
     foreach ($files as $file) {
         // Did I found what I'm looking for?
         if (file_exists($file)) {
             $fileName = $file;
             break;
         }
     }
     // No file? Let's stop here
     if (!$fileName) {
         return true;
     }
     // Get the site's URL
     /** @var AngieModelWordpressConfiguration $config */
     $config = AModel::getAnInstance('Configuration', 'AngieModel', array(), $this->container);
     $new_url = $config->get('siteurl');
     $homeurl = $config->get('homeurl');
     $newURI = new AUri($new_url);
     $path = $newURI->getPath();
     // Load the .htaccess in memory
     $contents = @file_get_contents($fileName);
     if ($contents === false) {
         return false;
     }
     // Explode its lines
     $lines = explode("\n", $contents);
     $contents = '';
     $inSection = null;
     foreach ($lines as $line) {
         // Fix naughty Windows users' doing
         $line = rtrim($line, "\r");
         // If we are not inside the WordPress section look for the BEGIN signature
         if (is_null($inSection)) {
             if (strpos($line, '# BEGIN WordPress') === 0) {
                 $inSection = true;
             }
         } elseif ($inSection) {
             if (strpos($line, '# END WordPress') === 0) {
                 $inSection = false;
             } elseif (strpos($line, 'RewriteBase ') === 0) {
                 $line = "RewriteBase {$path}";
                 // If the site is hosted on the domain's root
                 if (empty($path)) {
                     $line = "RewriteBase /";
                 }
             } elseif (strpos($line, 'RewriteRule .') === 0) {
                 $line = 'RewriteRule . ' . $path . '/index.php [L]';
             }
         }
         // Add the line
         $contents .= "{$line}\n";
     }
     // Write the new .htaccess
     $fileName = APATH_ROOT . '/.htaccess';
     file_put_contents($fileName, $contents);
     // If the homeurl and siteurl don't match, copy the .htaccess file and index.php in the correct directory
     if ($new_url != $homeurl) {
         $homeUri = new AUri($homeurl);
         $homePath = $homeUri->getPath();
         if (strpos($path, $homePath) !== 0) {
             // I have no clue where to put the files so I'll do nothing at all :s
             return true;
         }
         // $homePath is WITHOUT /wordpress_dir (/foobar); $path is the one WITH /wordpress_dir (/foobar/wordpress_dir)
         $homePath = ltrim($homePath, '/\\');
         $path = ltrim($path, '/\\');
         $homeParts = explode('/', $homePath);
         $siteParts = explode('/', $path);
         $numHomeParts = count($homeParts);
         $siteParts = array_slice($siteParts, $numHomeParts);
         // Relative path from HOME to SITE (WP) root
         $relPath = implode('/', $siteParts);
         // How many directories above the root (where we are restoring) is our site's root
         $levelsUp = count($siteParts);
         // Determine the path where the index.php and .htaccess files will be written to
         $targetPath = APATH_ROOT . str_repeat('/..', $levelsUp);
         $targetPath = realpath($targetPath) ? realpath($targetPath) : $targetPath;
         // Copy the files
         if (!@copy(APATH_ROOT . '/.htaccess', $targetPath . '/.htaccess')) {
             return false;
         }
         if (!@copy(APATH_ROOT . '/index.php', $targetPath . '/index.php')) {
             return false;
         }
         // Edit the index.php file
         $fileName = $targetPath . '/index.php';
         $fileContents = @file($fileName);
         if (empty($fileContents)) {
             return false;
         }
         foreach ($fileContents as $index => $line) {
             $line = trim($line);
             if (strstr($line, 'wp-blog-header.php') && strpos($line, 'require') === 0) {
                 $line = "require( dirname( __FILE__ ) . '/{$relPath}/wp-blog-header.php' );";
             }
             $fileContents[$index] = $line;
         }
         $fileContents = implode("\n", $fileContents);
         @file_put_contents($fileName, $fileContents);
     }
     return true;
 }
Exemple #14
0
 /**
  * Internal method to get the default replacements for the main site URL
  *
  * @param   AngieModelBaseConfiguration $config The configuration model
  *
  * @return  array  Any replacements to add
  */
 private function getDefaultReplacementsForMainSite($config)
 {
     $replacements = array();
     // These values are stored inside the session, after the setup step
     $old_url = $config->get('old_live_site');
     $new_url = $config->get('live_site');
     if ($old_url == $new_url) {
         return $replacements;
     }
     // Replace the absolute URL to the site
     $replacements[$old_url] = $new_url;
     // If the relative path to the site is different, replace it too.
     $oldUri = new AUri($old_url);
     $newUri = new AUri($new_url);
     $oldPath = $oldUri->getPath();
     $newPath = $newUri->getPath();
     if ($oldPath != $newPath) {
         $replacements[$oldPath] = $newPath;
         return $replacements;
     }
     return $replacements;
 }
Exemple #15
0
 /**
  * Writes the new config params inside the wp-config file and the database.
  *
  * @param   string  $file
  *
  * @return bool
  */
 public function writeConfig($file)
 {
     // First of all I'll save the options stored inside the db. In this way, even if
     // the configuration file write fails, the user has only to manually update the
     // config file and he's ready to go.
     $name = $this->get('dbtype');
     $options = array('database' => $this->get('dbname'), 'select' => 1, 'host' => $this->get('dbhost'), 'user' => $this->get('dbuser'), 'password' => $this->get('dbpass'), 'prefix' => $this->get('dbprefix'));
     $db = ADatabaseFactory::getInstance()->getDriver($name, $options);
     // If supplied in the request (ie restoring using UNiTE) let's use that URL
     $livesite = $this->get('livesite', '');
     if (!$livesite) {
         $livesite = AUri::root();
     }
     $url = str_replace('/installation', '', $livesite);
     // The URL must end with a slash
     $url = rtrim($url, '/') . '/';
     $query = $db->getQuery(true)->update($db->qn('#__core_config_data'))->set($db->qn('value') . ' = ' . $db->q($url))->where($db->qn('path') . ' = ' . $db->q('web/unsecure/base_url'));
     $db->setQuery($query)->execute();
     $query = $db->getQuery(true)->update($db->qn('#__core_config_data'))->set($db->qn('value') . ' = ' . $db->q($url))->where($db->qn('path') . ' = ' . $db->q('web/secure/base_url'));
     $db->setQuery($query)->execute();
     $new_config = $this->getFileContents($file);
     if (!file_put_contents($file, $new_config)) {
         return false;
     }
     return true;
 }
Exemple #16
0
 /**
  * Constructor
  *
  * @param   array $config A named configuration array for object construction.<br/>
  *                          name: the name (optional) of the view (defaults to the view class name suffix).<br/>
  *                          escape: the name (optional) of the function to use for escaping strings<br/>
  *                          base_path: the parent path (optional) of the views directory (defaults to the component folder)<br/>
  *                          template_plath: the path (optional) of the layout directory (defaults to base_path + /views/ + view name<br/>
  *                          helper_path: the path (optional) of the helper files (defaults to base_path + /helpers/)<br/>
  *                          layout: the layout (optional) to use to display the view<br/>
  *
  * @param   \AContainer $container
  *
  * @throws \AExceptionApp
  * @throws \Exception
  */
 public function __construct($config = array(), AContainer $container = null)
 {
     if (is_null($container)) {
         $container = AApplication::getInstance()->getContainer();
     }
     $this->container = $container;
     $this->input = $this->container->input;
     // Get the component name
     if (array_key_exists('option', $config)) {
         if ($config['option']) {
             $component = $config['option'];
         }
     }
     $config['option'] = $component;
     // Get the view name
     $view = $this->input->getCmd('view', '');
     if (array_key_exists('view', $config)) {
         if ($config['view']) {
             $view = $config['view'];
         }
     }
     $config['view'] = $view;
     // Set the component and the view to the input array
     $this->input->set('option', $config['option']);
     $this->input->set('view', $config['view']);
     // Set the view name
     if (array_key_exists('name', $config)) {
         $this->_name = $config['name'];
     } else {
         $this->_name = $config['view'];
     }
     $this->input->set('view', $this->_name);
     $config['input'] = $this->input;
     $config['name'] = $this->_name;
     $config['view'] = $this->_name;
     // Set a base path for use by the view
     if (array_key_exists('base_path', $config)) {
         $this->_basePath = $config['base_path'];
     } else {
         $this->_basePath = APATH_INSTALLATION . '/' . $config['option'];
     }
     // Set the default template search path
     if (array_key_exists('template_path', $config)) {
         // User-defined dirs
         $this->_setPath('template', $config['template_path']);
     } else {
         $this->_setPath('template', $this->_basePath . '/views/' . $this->getName() . '/tmpl');
     }
     // Set the default helper search path
     if (array_key_exists('helper_path', $config)) {
         // User-defined dirs
         $this->_setPath('helper', $config['helper_path']);
     } else {
         $this->_setPath('helper', $this->_basePath . '/helpers');
     }
     // Set the layout
     if (array_key_exists('layout', $config)) {
         $this->setLayout($config['layout']);
     } else {
         $this->setLayout('default');
     }
     $this->config = $config;
     $app = $this->container->application;
     $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $component);
     $fallback = APATH_THEMES . '/' . $app->getTemplate() . '/html/' . $component . '/' . $this->getName();
     $this->_addPath('template', $fallback);
     $this->baseurl = AUri::base(true);
 }
 /**
  * Redirect to another URL.
  *
  * Optionally enqueues a message in the system message queue (which will be displayed
  * the next time a page is loaded) using the enqueueMessage method. If the headers have
  * not been sent the redirect will be accomplished using a "301 Moved Permanently"
  * code in the header pointing to the new location. If the headers have already been
  * sent this will be accomplished using a JavaScript statement.
  *
  * @param   string   $url      The URL to redirect to. Can only be http/https URL
  * @param   string   $msg      An optional message to display on redirect.
  * @param   string   $msgType  An optional message type. Defaults to message.
  * @param   boolean  $moved    True if the page is 301 Permanently Moved, otherwise 303 See Other is assumed.
  *
  * @return  void  Calls exit().
  *
  * @see     AApplication::enqueueMessage()
  */
 public function redirect($url, $msg = '', $msgType = 'info', $moved = false)
 {
     // Check for relative internal links.
     if (preg_match('#^index\\.php#', $url)) {
         $url = AUri::base() . $url;
     }
     // Strip out any line breaks.
     $url = preg_split("/[\r\n]/", $url);
     $url = $url[0];
     /*
      * If we don't start with a http we need to fix this before we proceed.
      * We could validly start with something else (e.g. ftp), though this would
      * be unlikely and isn't supported by this API.
      */
     if (!preg_match('#^http#i', $url)) {
         $uri = AURI::getInstance();
         $prefix = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
         if ($url[0] == '/') {
             // We just need the prefix since we have a path relative to the root.
             $url = $prefix . $url;
         } else {
             // It's relative to where we are now, so lets add that.
             $parts = explode('/', $uri->toString(array('path')));
             array_pop($parts);
             $path = implode('/', $parts) . '/';
             $url = $prefix . $path . $url;
         }
     }
     // If the message exists, enqueue it.
     if (trim($msg)) {
         $this->enqueueMessage($msg, $msgType);
     }
     // Persist messages if they exist.
     if (count($this->messageQueue)) {
         $this->session->set('application.queue', $this->messageQueue);
         $this->session->saveData();
     }
     // If the headers have been sent, then we cannot send an additional location header
     // so we will output a javascript redirect statement.
     if (headers_sent()) {
         echo "<script>document.location.href='" . htmlspecialchars($url) . "';</script>\n";
     } else {
         header($moved ? 'HTTP/1.1 301 Moved Permanently' : 'HTTP/1.1 303 See other');
         header('Location: ' . $url);
         header('Content-Type: text/html; charset=utf-8');
     }
     $this->close();
 }
Exemple #18
0
	</div>

	<div id="success-dialog" class="modal hide fade">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal" aria-hidden="true" id="success-btn-modalclose">&times;</button>
			<h3><?php 
echo AText::_('FINALISE_HEADER_SUCCESS');
?>
</h3>
		</div>
		<div class="modal-body">
			<p>
				<?php 
echo AText::sprintf('FINALISE_LBL_SUCCESS', 'https://www.akeebabackup.com/documentation/troubleshooter/prbasicts.html');
?>
			</p>
			<a class="btn btn-success" href="<?php 
echo AUri::base() . '../index.php';
?>
">
				<span class="icon-white icon-forward"></span>
				<?php 
echo AText::_('FINALISE_BTN_VISITFRONTEND');
?>
			</a>
		</div>
	</div>

</div>

 /**
  * Creates the string that will be put inside the new configuration file.
  * This is a separate function so we can show the content if we're unable to write to the filesystem
  * and ask the user to manually do that.
  */
 public function getFileContents($file = null)
 {
     if (!$file) {
         $file = APATH_ROOT . '/wp-config.php';
     }
     $new_config = '';
     $old_config = file_get_contents($file);
     // Check if the file is UTF encoded with BOM. We have to remove it or we will get a white page
     // Sadly several editors are setting the flag automatically; since they are not visible, the user has
     // no easy method to remove them
     $bom = pack("CCC", 0xef, 0xbb, 0xbf);
     if (strncmp($old_config, $bom, 3) === 0) {
         // Let's strip out any BOM char
         $old_config = substr($old_config, 3);
     }
     $lines = explode("\n", $old_config);
     foreach ($lines as $line) {
         $line = trim($line);
         $matches = array();
         // Skip commented lines. However it will get the line between a multiline comment, but that's not a problem
         if (strpos($line, '#') === 0 || strpos($line, '//') === 0 || strpos($line, '/*') === 0) {
             // simply do nothing, we will add the line later
         } elseif (strpos($line, 'define(') !== false) {
             preg_match('#define\\(["\'](.*?)["\']\\,#', $line, $matches);
             if (isset($matches[1])) {
                 $key = $matches[1];
                 switch (strtoupper($key)) {
                     case 'DB_NAME':
                         $value = $this->get('dbname');
                         $line = "define('" . $key . "', '" . $value . "');";
                         break;
                     case 'DB_USER':
                         $value = $this->get('dbuser');
                         $line = "define('" . $key . "', '" . $value . "');";
                         break;
                     case 'DB_PASSWORD':
                         $value = $this->get('dbpass');
                         $value = addcslashes($value, "'\\");
                         $line = "define('" . $key . "', '" . $value . "');";
                         break;
                     case 'DB_HOST':
                         $value = $this->get('dbhost');
                         $line = "define('" . $key . "', '" . $value . "');";
                         break;
                     case 'DB_CHARSET':
                         $value = $this->get('dbcharset');
                         $line = "define('" . $key . "', '" . $value . "');";
                         break;
                     case 'DB_COLLATE':
                         $value = $this->get('dbcollate', 'utf8_general_ci');
                         $line = "define('" . $key . "', '" . $value . "');";
                         break;
                     case 'AUTH_KEY':
                         $value = $this->get('auth_key');
                         $line = "define('" . $key . "', '" . $value . "');";
                         break;
                     case 'SECURE_AUTH_KEY':
                         $value = $this->get('secure_auth_key');
                         $line = "define('" . $key . "', '" . $value . "');";
                         break;
                     case 'LOGGED_IN_KEY':
                         $value = $this->get('logged_in_key');
                         $line = "define('" . $key . "', '" . $value . "');";
                         break;
                     case 'NONCE_KEY':
                         $value = $this->get('nonce_key');
                         $line = "define('" . $key . "', '" . $value . "');";
                         break;
                     case 'AUTH_SALT':
                         $value = $this->get('auth_salt');
                         $line = "define('" . $key . "', '" . $value . "');";
                         break;
                     case 'SECURE_AUTH_SALT':
                         $value = $this->get('secure_auth_salt');
                         $line = "define('" . $key . "', '" . $value . "');";
                         break;
                     case 'LOGGED_IN_SALT':
                         $value = $this->get('logged_in_salt');
                         $line = "define('" . $key . "', '" . $value . "');";
                         break;
                     case 'NONCE_SALT':
                         $value = $this->get('nonce_salt');
                         $line = "define('" . $key . "', '" . $value . "');";
                         break;
                         // Multisite variable - Main site's domain
                     // Multisite variable - Main site's domain
                     case 'DOMAIN_CURRENT_SITE':
                         $new_url = $this->get('homeurl');
                         $newUri = new AUri($new_url);
                         $newDomain = $newUri->getHost();
                         $line = "define('" . $key . "', '" . $newDomain . "');";
                         break;
                         // Multisite variable - Main site's path
                     // Multisite variable - Main site's path
                     case 'PATH_CURRENT_SITE':
                         $new_url = $this->get('homeurl');
                         $newUri = new AUri($new_url);
                         $newPath = $newUri->getPath();
                         $newPath = trim($newPath, '/');
                         $newPath = '/' . $newPath . '/';
                         $line = "define('" . $key . "', '" . $newPath . "');";
                         break;
                         // I think users shouldn't change the WPLANG define, since they will have
                         // to add several files, it's not automatic
                     // I think users shouldn't change the WPLANG define, since they will have
                     // to add several files, it's not automatic
                     default:
                         // Do nothing, it's a variable we're not interested in
                         break;
                 }
             }
         } elseif (strpos($line, '$table_prefix') === 0) {
             $line = '$table_prefix = ' . "'" . $this->get('dbprefix') . "';";
         }
         $new_config .= $line . "\n";
     }
     return $new_config;
 }