function run($request)
 {
     if (isset($_GET['folderID'])) {
         $folderID = $_GET['folderID'];
     } else {
         $folderID = null;
     }
     echo Filesystem::sync($folderID);
 }
 function run($request)
 {
     if (isset($_GET['folderID'])) {
         $folderID = $_GET['folderID'];
     } else {
         $folderID = null;
     }
     echo Filesystem::sync($folderID, !$request->getVar('skipSyncLinkTracking')) . "\n";
 }
 protected function importMedia($item, $page)
 {
     $source = $item->getSource();
     $params = $this->importer->getParams();
     $folder = $params['AssetsPath'];
     $baseURL = $params['BaseUrl'];
     if ($folder) {
         $folderId = Folder::find_or_make($folder)->ID;
     }
     // Find the src attribute of every img element.
     $pattern = '/<img [^>]*src="([^"]*)/';
     if (!preg_match_all($pattern, $page->Content, $matches)) {
         return;
     }
     // Loop through all the matches to ([^"]*), which captures the filename
     foreach ($matches[1] as $match) {
         $imageURL = $match;
         // Don't pull in absolute links unless they're on the same location. Note that this will skip over any
         // files served from a subdomain like static.mysite.com.
         if (substr($match, 0, strlen($baseURL)) != $baseURL) {
             if (strpos($match, '://') !== false) {
                 continue;
             }
             $imageURL = Controller::join_links($baseURL, $match);
         }
         $name = basename($match);
         $path = Controller::join_links(ASSETS_PATH, $folder, $name);
         $link = Controller::join_links(ASSETS_DIR, $folder, $name);
         if (!file_exists($path)) {
             if (!($contents = @file_get_contents($imageURL))) {
                 continue;
             }
             file_put_contents($path, $contents);
         }
         $page->Content = str_replace("\"{$match}\"", "\"{$link}\"", $page->Content);
     }
     Filesystem::sync($folderId);
     $page->write();
 }
Exemplo n.º 4
0
 public function sync()
 {
     echo Filesystem::sync();
 }
Exemplo n.º 5
0
 /**
  * Can be queried with an ajax request to trigger the filesystem sync. It returns a FormResponse status message
  * to display in the CMS
  */
 public function doSync()
 {
     $message = Filesystem::sync();
     $this->response->addHeader('X-Status', rawurlencode($message));
     return;
 }
Exemplo n.º 6
0
    public function install($config)
    {
        ?>
		<html>
		<head>
			<meta charset="utf-8"/>
			<title>Installing SilverStripe...</title>
			<link rel="stylesheet" type="text/css" href="<?php 
        echo FRAMEWORK_NAME;
        ?>
/dev/install/css/install.css"/>
			<script src="<?php 
        echo FRAMEWORK_NAME;
        ?>
/thirdparty/jquery/jquery.js"></script>
		</head>
		<body>
		<div class="install-header">
			<div class="inner">
				<div class="brand">
					<span class="logo"></span>

					<h1>SilverStripe</h1>
				</div>
			</div>
		</div>

		<div id="Navigation">&nbsp;</div>
		<div class="clear"><!-- --></div>

		<div class="main">
			<div class="inner">
				<h2>Installing SilverStripe...</h2>

				<p>I am now running through the installation steps (this should take about 30 seconds)</p>

				<p>If you receive a fatal error, refresh this page to continue the installation</p>
				<ul>
<?php 
        $webserver = $this->findWebserver();
        $isIIS = $this->isIIS();
        $isApache = $this->isApache();
        flush();
        if (isset($config['stats'])) {
            if (file_exists(FRAMEWORK_NAME . '/silverstripe_version')) {
                $silverstripe_version = file_get_contents(FRAMEWORK_NAME . '/silverstripe_version');
            } else {
                $silverstripe_version = "unknown";
            }
            $phpVersion = urlencode(phpversion());
            $encWebserver = urlencode($webserver);
            $dbType = $config['db']['type'];
            // Try to determine the database version from the helper
            $databaseVersion = $config['db']['type'];
            $helper = $this->getDatabaseConfigurationHelper($dbType);
            if ($helper && method_exists($helper, 'getDatabaseVersion')) {
                $versionConfig = $config['db'][$dbType];
                $versionConfig['type'] = $dbType;
                $databaseVersion = urlencode($dbType . ': ' . $helper->getDatabaseVersion($versionConfig));
            }
            $url = "http://ss2stat.silverstripe.com/Installation/add?SilverStripe={$silverstripe_version}&PHP={$phpVersion}&Database={$databaseVersion}&WebServer={$encWebserver}";
            if (isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {
                $url .= '&ID=' . $_SESSION['StatsID'];
            }
            @($_SESSION['StatsID'] = file_get_contents($url));
        }
        if (file_exists('mysite/_config.php')) {
            // Truncate the contents of _config instead of deleting it - we can't re-create it because Windows handles permissions slightly
            // differently to UNIX based filesystems - it takes the permissions from the parent directory instead of retaining them
            $fh = fopen('mysite/_config.php', 'wb');
            fclose($fh);
        }
        // Escape user input for safe insertion into PHP file
        $theme = isset($_POST['template']) ? addcslashes($_POST['template'], "\\'") : 'simple';
        $locale = isset($_POST['locale']) ? addcslashes($_POST['locale'], "\\'") : 'en_US';
        $type = addcslashes($config['db']['type'], "\\'");
        $dbConfig = $config['db'][$type];
        $dbConfig = array_map(create_function('$v', 'return addcslashes($v, "\\\'");'), $dbConfig);
        if (!isset($dbConfig['path'])) {
            $dbConfig['path'] = '';
        }
        if (!$dbConfig) {
            echo "<p style=\"color: red\">Bad config submitted</p><pre>";
            print_r($config);
            echo "</pre>";
            die;
        }
        // Write the config file
        global $usingEnv;
        if ($usingEnv) {
            $this->statusMessage("Setting up 'mysite/_config.php' for use with _ss_environment.php...");
            $this->writeToFile("mysite/_config.php", <<<PHP
<?php

global \$project;
\$project = 'mysite';

global \$database;
\$database = '{$dbConfig['database']}';

require_once('conf/ConfigureFromEnv.php');

// Set the site locale
i18n::set_locale('{$locale}');

PHP
);
        } else {
            $this->statusMessage("Setting up 'mysite/_config.php'...");
            // Create databaseConfig
            $lines = array($lines[] = "\t'type' => '{$type}'");
            foreach ($dbConfig as $key => $value) {
                $lines[] = "\t'{$key}' => '{$value}'";
            }
            $databaseConfigContent = implode(",\n", $lines);
            $this->writeToFile("mysite/_config.php", <<<PHP
<?php

global \$project;
\$project = 'mysite';

global \$databaseConfig;
\$databaseConfig = array(
{$databaseConfigContent}
);

// Set the site locale
i18n::set_locale('{$locale}');

PHP
);
        }
        $this->statusMessage("Setting up 'mysite/_config/config.yml'");
        $this->writeToFile("mysite/_config/config.yml", <<<YML
---
Name: mysite
After:
  - 'framework/*'
  - 'cms/*'
---
# YAML configuration for SilverStripe
# See http://doc.silverstripe.org/framework/en/topics/configuration
# Caution: Indentation through two spaces, not tabs
SSViewer:
  theme: '{$theme}'
YML
);
        if (!$this->checkModuleExists('cms')) {
            $this->writeToFile("mysite/code/RootURLController.php", <<<PHP
<?php

class RootURLController extends Controller {

\tpublic function index() {
\t\techo "<html>Your site is now set up. Start adding controllers to mysite to get started.</html>";
\t}

}
PHP
);
        }
        // Write the appropriate web server configuration file for rewriting support
        if ($this->hasRewritingCapability()) {
            if ($isApache) {
                $this->statusMessage("Setting up '.htaccess' file...");
                $this->createHtaccess();
            } elseif ($isIIS) {
                $this->statusMessage("Setting up 'web.config' file...");
                $this->createWebConfig();
            }
        }
        // Load the SilverStripe runtime
        $_SERVER['SCRIPT_FILENAME'] = dirname(realpath($_SERVER['SCRIPT_FILENAME'])) . '/' . FRAMEWORK_NAME . '/main.php';
        chdir(FRAMEWORK_NAME);
        // Rebuild the manifest
        $_GET['flush'] = true;
        // Show errors as if you're in development mode
        $_SESSION['isDev'] = 1;
        $this->statusMessage("Building database schema...");
        require_once 'core/Core.php';
        // Build database
        $con = new Controller();
        $con->pushCurrent();
        global $databaseConfig;
        DB::connect($databaseConfig);
        $dbAdmin = new DatabaseAdmin();
        $dbAdmin->init();
        $dbAdmin->doBuild(true);
        // Create default administrator user and group in database
        // (not using Security::setDefaultAdmin())
        $adminMember = Security::findAnAdministrator();
        $adminMember->Email = $config['admin']['username'];
        $adminMember->Password = $config['admin']['password'];
        $adminMember->PasswordEncryption = Security::config()->encryption_algorithm;
        try {
            $this->statusMessage('Creating default CMS admin account...');
            $adminMember->write();
        } catch (Exception $e) {
            $this->statusMessage(sprintf('Warning: Default CMS admin account could not be created (error: %s)', $e->getMessage()));
        }
        // Syncing filesystem (so /assets/Uploads is available instantly, see ticket #2266)
        // show a warning if there was a problem doing so
        try {
            $this->statusMessage('Creating initial filesystem assets...');
            Filesystem::sync();
        } catch (Exception $e) {
            $this->statusMessage(sprintf('Warning: Creating initial filesystem assets failed (error: %s)', $e->getMessage()));
        }
        $_SESSION['username'] = $config['admin']['username'];
        $_SESSION['password'] = $config['admin']['password'];
        if (!$this->errors) {
            if (isset($_SERVER['HTTP_HOST']) && $this->hasRewritingCapability()) {
                $this->statusMessage("Checking that friendly URLs work...");
                $this->checkRewrite();
            } else {
                require_once 'core/startup/ParameterConfirmationToken.php';
                $token = new ParameterConfirmationToken('flush');
                $params = http_build_query($token->params());
                $destinationURL = 'index.php/' . ($this->checkModuleExists('cms') ? "home/successfullyinstalled?{$params}" : "?{$params}");
                echo <<<HTML
\t\t\t\t<li>SilverStripe successfully installed; I am now redirecting you to your SilverStripe site...</li>
\t\t\t\t<script>
\t\t\t\t\tsetTimeout(function() {
\t\t\t\t\t\twindow.location = "{$destinationURL}";
\t\t\t\t\t}, 2000);
\t\t\t\t</script>
\t\t\t\t<noscript>
\t\t\t\t<li><a href="{$destinationURL}">Click here to access your site.</a></li>
\t\t\t\t</noscript>
HTML;
            }
        }
        return $this->errors;
    }
 protected function importMedia($item, $page)
 {
     $source = $item->getSource();
     $params = $this->importer->getParams();
     $folder = $params['AssetsPath'];
     $content = $item->Content;
     if ($folder) {
         $folderId = Folder::find_or_make($folder)->ID;
     }
     $url = trim(preg_replace('~^[a-z]+://~', null, $source->BaseUrl), '/');
     $pattern = sprintf('~[a-z]+://%s/wp-content/uploads/[^"]+~', $url);
     if (!preg_match_all($pattern, $page->Content, $matches)) {
         return;
     }
     foreach ($matches[0] as $match) {
         if (!($contents = @file_get_contents($match))) {
             continue;
         }
         $name = basename($match);
         $path = Controller::join_links(ASSETS_PATH, $folder, $name);
         $link = Controller::join_links(ASSETS_DIR, $folder, $name);
         file_put_contents($path, $contents);
         $page->Content = str_replace($match, $link, $page->Content);
     }
     Filesystem::sync($folderId);
     $page->write();
 }
 public function run($request = null)
 {
     Filesystem::sync();
 }
 public function fire()
 {
     $this->info(Filesystem::sync());
 }
    function install($config)
    {
        if (isset($_SERVER['HTTP_HOST'])) {
            ?>
<html>
	<head>
		<title>Installing SilverStripe...</title>
		<link rel="stylesheet" type="text/css" href="themes/blackcandy/css/layout.css" />
		<link rel="stylesheet" type="text/css" href="themes/blackcandy/css/typography.css" />
		<link rel="stylesheet" type="text/css" href="themes/blackcandy/css/form.css" />
		<link rel="stylesheet" type="text/css" href="sapphire/dev/install/install.css" />
		<script src="sapphire/thirdparty/jquery/jquery.js"></script>
	</head>
	<body>
		<div id="BgContainer">
			<div id="Container">
				<div id="Header">
					<h1>SilverStripe CMS Installation</h1>
				</div>

				<div id="Navigation">&nbsp;</div>
				<div class="clear"><!-- --></div>

				<div id="Layout">
					<div class="typography">
						<h1>Installing SilverStripe...</h1>
						<p>I am now running through the installation steps (this should take about 30 seconds)</p>
						<p>If you receive a fatal error, refresh this page to continue the installation</p>
						<ul>
<?php 
        } else {
            echo "SILVERSTRIPE COMMAND-LINE INSTALLATION\n\n";
        }
        $webserver = $this->findWebserver();
        $isIIS = $this->isIIS();
        $isApache = $this->isApache();
        flush();
        if (isset($config['stats'])) {
            if (file_exists('sapphire/silverstripe_version')) {
                $sapphireVersionFile = file_get_contents('sapphire/silverstripe_version');
                if (strstr($sapphireVersionFile, "/sapphire/trunk")) {
                    $silverstripe_version = "trunk";
                } else {
                    preg_match("/sapphire\\/(?:(?:branches)|(?:tags))(?:\\/rc)?\\/([A-Za-z0-9._-]+)\\/silverstripe_version/", $sapphireVersionFile, $matches);
                    $silverstripe_version = $matches[1];
                }
            } else {
                $silverstripe_version = "unknown";
            }
            $phpVersion = urlencode(phpversion());
            $encWebserver = urlencode($webserver);
            $dbType = $config['db']['type'];
            // Try to determine the database version from the helper
            $databaseVersion = $config['db']['type'];
            $helper = $this->getDatabaseConfigurationHelper($dbType);
            if ($helper && method_exists($helper, 'getDatabaseVersion')) {
                $databaseVersion = urlencode($dbType . ': ' . $helper->getDatabaseVersion($config['db'][$dbType]));
            }
            $url = "http://ss2stat.silverstripe.com/Installation/add?SilverStripe={$silverstripe_version}&PHP={$phpVersion}&Database={$databaseVersion}&WebServer={$encWebserver}";
            if (isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {
                $url .= '&ID=' . $_SESSION['StatsID'];
            }
            @($_SESSION['StatsID'] = file_get_contents($url));
        }
        if (file_exists('mysite/_config.php')) {
            // Truncate the contents of _config instead of deleting it - we can't re-create it because Windows handles permissions slightly
            // differently to UNIX based filesystems - it takes the permissions from the parent directory instead of retaining them
            $fh = fopen('mysite/_config.php', 'wb');
            fclose($fh);
        }
        $theme = isset($_POST['template']) ? $_POST['template'] : 'blackcandy';
        $locale = isset($_POST['locale']) ? $_POST['locale'] : 'en_US';
        $type = $config['db']['type'];
        $dbConfig = $config['db'][$type];
        if (!$dbConfig) {
            echo "<p style=\"color: red\">Bad config submitted</p><pre>";
            print_r($config);
            echo "</pre>";
            die;
        }
        // Write the config file
        global $usingEnv;
        if ($usingEnv) {
            $this->statusMessage("Setting up 'mysite/_config.php' for use with _ss_environment.php...");
            $this->writeToFile("mysite/_config.php", <<<PHP
<?php

global \$project;
\$project = 'mysite';

global \$database;
\$database = '{$dbConfig['database']}';

require_once('conf/ConfigureFromEnv.php');

MySQLDatabase::set_connection_charset('utf8');

// This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.org/themes/
SSViewer::set_theme('{$theme}');

// Set the site locale
i18n::set_locale('{$locale}');

// enable nested URLs for this site (e.g. page/sub-page/)
SiteTree::enable_nested_urls();
PHP
);
        } else {
            $this->statusMessage("Setting up 'mysite/_config.php'...");
            $escapedPassword = addslashes($dbConfig['password']);
            $this->writeToFile("mysite/_config.php", <<<PHP
<?php

global \$project;
\$project = 'mysite';

global \$databaseConfig;
\$databaseConfig = array(
\t"type" => '{$type}',
\t"server" => '{$dbConfig['server']}', 
\t"username" => '{$dbConfig['username']}', 
\t"password" => '{$escapedPassword}', 
\t"database" => '{$dbConfig['database']}',
\t"path" => '{$dbConfig['path']}',
);

// Sites running on the following servers will be
// run in development mode. See
// http://doc.silverstripe.org/doku.php?id=configuration
// for a description of what dev mode does.
Director::set_dev_servers(array(
\t'localhost',
\t'127.0.0.1'
));

MySQLDatabase::set_connection_charset('utf8');

// This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.org/themes/
SSViewer::set_theme('{$theme}');

// Set the site locale
i18n::set_locale('{$locale}');

// enable nested URLs for this site (e.g. page/sub-page/)
SiteTree::enable_nested_urls();
PHP
);
        }
        // Write the appropriate web server configuration file for rewriting support
        if ($this->hasRewritingCapability()) {
            if ($isApache) {
                $this->statusMessage("Setting up '.htaccess' file...");
                $this->createHtaccess();
            } elseif ($isIIS) {
                $this->statusMessage("Setting up 'web.config' file...");
                $this->createWebConfig();
            }
        }
        // Load the sapphire runtime
        $_SERVER['SCRIPT_FILENAME'] = dirname(realpath($_SERVER['SCRIPT_FILENAME'])) . '/sapphire/main.php';
        chdir('sapphire');
        // Rebuild the manifest
        $_GET['flush'] = true;
        // Show errors as if you're in development mode
        $_SESSION['isDev'] = 1;
        require_once 'core/Core.php';
        $this->statusMessage("Building database schema...");
        // Build database
        $con = new Controller();
        $con->pushCurrent();
        global $databaseConfig;
        DB::connect($databaseConfig);
        $dbAdmin = new DatabaseAdmin();
        $dbAdmin->init();
        $dbAdmin->doBuild(true);
        // Create default administrator user and group in database
        // (not using Security::setDefaultAdmin())
        $adminMember = Security::findAnAdministrator();
        $adminMember->Email = $config['admin']['username'];
        $adminMember->Password = $config['admin']['password'];
        $adminMember->PasswordEncryption = Security::get_password_encryption_algorithm();
        // @todo Exception thrown if database with admin already exists with same Email
        try {
            $adminMember->write();
        } catch (Exception $e) {
        }
        // Syncing filesystem (so /assets/Uploads is available instantly, see ticket #2266)
        Filesystem::sync();
        $_SESSION['username'] = $config['admin']['username'];
        $_SESSION['password'] = $config['admin']['password'];
        if (!$this->errors) {
            if (isset($_SERVER['HTTP_HOST']) && $this->hasRewritingCapability()) {
                $this->statusMessage("Checking that friendly URLs work...");
                $this->checkRewrite();
            } else {
                echo <<<HTML
\t\t\t\t<li>SilverStripe successfully installed; I am now redirecting you to your SilverStripe site...</li>
\t\t\t\t<script>
\t\t\t\t\tsetTimeout(function() {
\t\t\t\t\t\twindow.location = "index.php/home/successfullyinstalled?flush=1";
\t\t\t\t\t}, 2000);
\t\t\t\t</script>
\t\t\t\t<noscript>
\t\t\t\t<li><a href="index.php/home/successfullyinstalled?flush=1">Click here to access your site.</li>
\t\t\t\t</noscript>
HTML;
            }
        }
        return $this->errors;
    }
 public function run($request)
 {
     $dbAdmin = DatabaseAdmin::create();
     increase_time_limit_to(600);
     SS_ClassLoader::instance()->getManifest()->regenerate();
     $dbAdmin->clearAllData();
     $dbAdmin->doBuild(true);
     // Build again for good measure
     $dbAdmin->doBuild(true, false);
     //Move images to assets/Uploads/
     $assetsDir = Director::baseFolder() . '/assets/Uploads';
     $imagesDir = Director::baseFolder() . '/swipestripe-builder/images';
     foreach (new DirectoryIterator($assetsDir) as $fileInfo) {
         if (!$fileInfo->isDot()) {
             @unlink($fileInfo->getPathname());
         }
     }
     Filesystem::sync();
     foreach (new DirectoryIterator($imagesDir) as $fileInfo) {
         if ($fileInfo->isFile()) {
             copy($fileInfo->getPathname(), $assetsDir . '/' . $fileInfo->getFilename());
         }
     }
     //Build DB
     $fixture = Injector::inst()->create('YamlFixture', self::$fixture_file);
     $fixture->writeInto($this->getFixtureFactory());
     //Update the shop config
     $config = ShopConfig::current_shop_config();
     $config->BaseCurrency = 'NZD';
     $config->BaseCurrencySymbol = '$';
     $config->EmailSignature = '';
     $config->ReceiptSubject = 'Your order details from SwipeStripe demo site';
     $config->ReceiptBody = '';
     $config->ReceiptFrom = '*****@*****.**';
     $config->NotificationSubject = 'New order on SwipeStripe demo site';
     $config->NotificationBody = '';
     $config->NotificationTo = '*****@*****.**';
     $config->write();
     // Populate flat fee shipping rates
     $this->createShippingRates();
     // Populate tax rates
     $this->createTaxRates();
     // Populate exchange rates
     $this->createExchangeRates();
     // Populate coupon codes
     $this->createCouponCodes();
     // Product categories
     $this->createProductCategories();
     // Product images
     $this->createProductImages();
     // Clear product meta
     $products = Product::get();
     if ($products && $products->exists()) {
         foreach ($products as $product) {
             $product->ExtraMeta = '';
             $product->doPublish();
         }
     }
     // Create home page
     if (class_exists('HomePage')) {
         $page = Page::get()->where("\"URLSegment\" = 'home'")->first();
         $page->ClassName = 'HomePage';
         $page->doPublish();
     }
 }
Exemplo n.º 12
0
	function install($config) {
?>
<html>
	<head>
		<title>Installing SilverStripe...</title>
		<link rel="stylesheet" type="text/css" href="<?php echo FRAMEWORK_NAME; ?>/dev/install/css/install.css" />
		<script src="<?php echo FRAMEWORK_NAME; ?>/thirdparty/jquery/jquery.js"></script>
	</head>
	<body>
		<div class="install-header">
			<div class="inner">
				<div class="brand">
					<span class="logo"></span>
					<h1>SilverStripe</h1>
				</div>
			</div>	
		</div>

		<div id="Navigation">&nbsp;</div>
		<div class="clear"><!-- --></div>

		<div class="main">
			<div class="inner">
				<h2>Installing SilverStripe...</h2>
				<p>I am now running through the installation steps (this should take about 30 seconds)</p>
				<p>If you receive a fatal error, refresh this page to continue the installation</p>
				<ul>
<?php

		$webserver = $this->findWebserver();
		$isIIS = $this->isIIS();
		$isApache = $this->isApache();

		flush();

		if(isset($config['stats'])) {
			if(file_exists(FRAMEWORK_NAME . '/silverstripe_version')) {
				$silverstripe_version = file_get_contents(FRAMEWORK_NAME . '/silverstripe_version');
			} else {
				$silverstripe_version = "unknown";
			}

			$phpVersion = urlencode(phpversion());
			$encWebserver = urlencode($webserver);
			$dbType = $config['db']['type'];

			// Try to determine the database version from the helper
			$databaseVersion = $config['db']['type'];
			$helper = $this->getDatabaseConfigurationHelper($dbType);
			if($helper && method_exists($helper, 'getDatabaseVersion')) {
				$databaseVersion = urlencode($dbType . ': ' . $helper->getDatabaseVersion($config['db'][$dbType]));
			}

			$url = "http://ss2stat.silverstripe.com/Installation/add?SilverStripe=$silverstripe_version&PHP=$phpVersion&Database=$databaseVersion&WebServer=$encWebserver";

			if(isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {
				$url .= '&ID=' . $_SESSION['StatsID'];
			}

			@$_SESSION['StatsID'] = file_get_contents($url);
		}

		if(file_exists('mysite/_config.php')) {
			// Truncate the contents of _config instead of deleting it - we can't re-create it because Windows handles permissions slightly
			// differently to UNIX based filesystems - it takes the permissions from the parent directory instead of retaining them
			$fh = fopen('mysite/_config.php', 'wb');
			fclose($fh);
		}
		$theme = isset($_POST['template']) ? $_POST['template'] : 'simple';
		$locale = isset($_POST['locale']) ? $_POST['locale'] : 'en_US';
		$type = $config['db']['type'];
		$dbConfig = $config['db'][$type];
		if(!isset($dbConfig['path'])) $dbConfig['path'] = '';
		if(!$dbConfig) {
			echo "<p style=\"color: red\">Bad config submitted</p><pre>";
			print_r($config);
			echo "</pre>";
			die();
		}

		// Write the config file
		global $usingEnv;
		if($usingEnv) {

			$this->statusMessage("Setting up 'mysite/_config.php' for use with _ss_environment.php...");
			$this->writeToFile("mysite/_config.php", <<<PHP
<?php

global \$project;
\$project = 'mysite';

global \$database;
\$database = '{$dbConfig['database']}';

require_once('conf/ConfigureFromEnv.php');

MySQLDatabase::set_connection_charset('utf8');

// Set the current theme. More themes can be downloaded from
// http://www.silverstripe.org/themes/
SSViewer::set_theme('$theme');

// Set the site locale
i18n::set_locale('$locale');

// Enable nested URLs for this site (e.g. page/sub-page/)
if (class_exists('SiteTree')) SiteTree::enable_nested_urls();
PHP
			);

		} else {
			$this->statusMessage("Setting up 'mysite/_config.php'...");
			$escapedPassword = addslashes($dbConfig['password']);
			$this->writeToFile("mysite/_config.php", <<<PHP
<?php

global \$project;
\$project = 'mysite';

global \$databaseConfig;
\$databaseConfig = array(
	"type" => '{$type}',
	"server" => '{$dbConfig['server']}',
	"username" => '{$dbConfig['username']}',
	"password" => '{$escapedPassword}',
	"database" => '{$dbConfig['database']}',
	"path" => '{$dbConfig['path']}',
);

MySQLDatabase::set_connection_charset('utf8');

// Set the current theme. More themes can be downloaded from
// http://www.silverstripe.org/themes/
SSViewer::set_theme('$theme');

// Set the site locale
i18n::set_locale('$locale');

// Enable nested URLs for this site (e.g. page/sub-page/)
if (class_exists('SiteTree')) SiteTree::enable_nested_urls();
PHP
			);
		}

		if (!$this->checkModuleExists('cms')) {
			$this->writeToFile("mysite/code/RootURLController.php", <<<PHP
<?php

class RootURLController extends Controller {

	function index() {
		echo "<html>Your site is now set up. Start adding controllers to mysite to get started.</html>";
	}

}
PHP
			);
		}

		// Write the appropriate web server configuration file for rewriting support
		if($this->hasRewritingCapability()) {
			if($isApache) {
				$this->statusMessage("Setting up '.htaccess' file...");
				$this->createHtaccess();
			} elseif($isIIS) {
				$this->statusMessage("Setting up 'web.config' file...");
				$this->createWebConfig();
			}
		}

		// Load the SilverStripe runtime
		$_SERVER['SCRIPT_FILENAME'] = dirname(realpath($_SERVER['SCRIPT_FILENAME'])) . '/' . FRAMEWORK_NAME . '/main.php';
		chdir(FRAMEWORK_NAME);

		// Rebuild the manifest
		$_GET['flush'] = true;
		// Show errors as if you're in development mode
		$_SESSION['isDev'] = 1;

		$this->statusMessage("Building database schema...");

		require_once 'core/Core.php';

		// Build database
		$con = new Controller();
		$con->pushCurrent();

		global $databaseConfig;
		DB::connect($databaseConfig);

		$dbAdmin = new DatabaseAdmin();
		$dbAdmin->init();

		$dbAdmin->doBuild(true);

		// Create default administrator user and group in database
		// (not using Security::setDefaultAdmin())
		$adminMember = Security::findAnAdministrator();
		$adminMember->Email = $config['admin']['username'];
		$adminMember->Password = $config['admin']['password'];
		$adminMember->PasswordEncryption = Security::get_password_encryption_algorithm();

		try {
			$this->statusMessage('Creating default CMS admin account...');
			$adminMember->write();
		} catch(Exception $e) {
			$this->statusMessage(
				sprintf('Warning: Default CMS admin account could not be created (error: %s)', $e->getMessage())
			);
		}

		// Syncing filesystem (so /assets/Uploads is available instantly, see ticket #2266)
		// show a warning if there was a problem doing so
		try {
			$this->statusMessage('Creating initial filesystem assets...');
			Filesystem::sync();
		} catch(Exception $e) {
			$this->statusMessage(
				sprintf('Warning: Creating initial filesystem assets failed (error: %s)', $e->getMessage())
			);
		}

		$_SESSION['username'] = $config['admin']['username'];
		$_SESSION['password'] = $config['admin']['password'];

		if(!$this->errors) {
			if(isset($_SERVER['HTTP_HOST']) && $this->hasRewritingCapability()) {
				$this->statusMessage("Checking that friendly URLs work...");
				$this->checkRewrite();
			} else {
				$destinationURL = 'index.php/' .
					($this->checkModuleExists('cms') ? 'home/successfullyinstalled?flush=1' : '?flush=1');

				echo <<<HTML
				<li>SilverStripe successfully installed; I am now redirecting you to your SilverStripe site...</li>
				<script>
					setTimeout(function() {
						window.location = "$destinationURL";
					}, 2000);
				</script>
				<noscript>
				<li><a href="$destinationURL">Click here to access your site.</li>
				</noscript>
HTML;
			}
		}

		return $this->errors;
	}
 function generateOptimizedJPEG(array $options = [])
 {
     if (($image = $this->Image()) && ($parentFolder = $image->Parent())) {
         $maxHeight = $options['maxHeight'];
         $maxWidth = $options['maxWidth'];
         $quality = $options['quality'];
         $subfolder = $options['subfolder'];
         $tmpDir = sys_get_temp_dir();
         $qualityBefore = Config::inst()->get('GDBackend', 'default_quality');
         Config::inst()->update('GDBackend', 'default_quality', 100);
         $folderPath = substr($parentFolder->getRelativePath() . $subfolder, strlen(ASSETS_DIR));
         $folder = Folder::find_or_make($folderPath);
         $resizedImage = $image->FitMax($maxWidth, $maxHeight);
         $destDir = $folder->getFullPath();
         $destFile = $destDir . $image->Name;
         $command = $this->config()->get('jpegOptimCommand') . " --strip-all -m" . $quality . " -o --stdout '" . $resizedImage->getFullPath() . "' > '{$destFile}'";
         $tmpFile = $tmpDir . $image->Name;
         shell_exec($command);
         Filesystem::sync($folder->ID);
         Config::inst()->update('GDBackend', 'default_quality', $qualityBefore);
     } else {
         // no image attached
         return null;
     }
 }
Exemplo n.º 14
0
 function index()
 {
     Filesystem::sync();
     return array();
 }
Exemplo n.º 15
0
 function doSync($data, $form)
 {
     return Filesystem::sync();
 }