function onAfterInit()
 {
     if (in_array(Director::get_environment_type(), Config::inst()->get('FartScrollExtension', 'environmentTypes'))) {
         Requirements::javascript('http://code.onion.com/fartscroll.js');
         Requirements::customScript('fartscroll(' . Config::inst()->get('FartScrollExtension', 'speed') . ');', 'Fart');
     }
 }
 /**
  * Provides a front-end utility menu with administrative functions and developer tools
  * Relies on SilverStripeNavigator
  * 
  * @return string
  */
 public function BetterNavigator()
 {
     $isDev = Director::isDev();
     if ($isDev || Permission::check('CMS_ACCESS_CMSMain') || Permission::check('VIEW_DRAFT_CONTENT')) {
         if ($this->owner && $this->owner->dataRecord) {
             //Get SilverStripeNavigator links & stage info (CMS/Stage/Live/Archive)
             $nav = array();
             $navigator = new SilverStripeNavigator($this->owner->dataRecord);
             $items = $navigator->getItems();
             foreach ($items as $item) {
                 $nav[$item->getName()] = array('Link' => $item->getLink(), 'Active' => $item->isActive());
             }
             //Is the logged in member nominated as a developer?
             $member = Member::currentUser();
             $devs = Config::inst()->get('BetterNavigator', 'developers');
             $isDeveloper = $member && is_array($devs) ? in_array($member->Email, $devs) : false;
             //Add other data for template
             $nav = array_merge($nav, array('Member' => $member, 'Stage' => Versioned::current_stage(), 'LoginLink' => Config::inst()->get('Security', 'login_url'), 'Mode' => Director::get_environment_type(), 'IsDeveloper' => $isDeveloper));
             //Merge with page data, send to template and render
             $nav = new ArrayData($nav);
             $page = $this->owner->customise($nav);
             return $page->renderWith('BetterNavigator');
         }
     }
     return false;
 }
 /**
  * Determines whether this environment should compile meta-languages
  *
  * @return bool
  */
 protected static function should_compile()
 {
     $config = Config::inst()->forClass("MetaLanguages");
     if (!$config->enable_compiling) {
         return false;
     }
     return in_array(Director::get_environment_type(), $config->environments) || in_array($_SERVER['HTTP_HOST'], $config->environments);
 }
Esempio n. 4
0
 /**
  * Get the payment environment.
  * The environment is retrieved from the config yaml file.
  * If no environment is specified, assume SilverStripe's environment.
  */
 public static function get_environment()
 {
     if (Config::inst()->get('PaymentGateway', 'environment')) {
         return Config::inst()->get('PaymentGateway', 'environment');
     } else {
         return Director::get_environment_type();
     }
 }
 function setUp()
 {
     parent::setUp();
     TestDataController::$data_dir = 'testdata/tests';
     $this->envType = Director::get_environment_type();
     Director::set_environment_type('test');
     TestDataController::$quiet = true;
 }
Esempio n. 6
0
 function setUp()
 {
     parent::setUp();
     $this->orig['ErrorPage_staticfilepath'] = ErrorPage::get_static_filepath();
     $this->tmpAssetsPath = sprintf('%s/_tmp_assets_%s', TEMP_FOLDER, rand());
     Filesystem::makeFolder($this->tmpAssetsPath . '/ErrorPageTest');
     ErrorPage::set_static_filepath($this->tmpAssetsPath . '/ErrorPageTest');
     $this->orig['Director_environmenttype'] = Director::get_environment_type();
     Director::set_environment_type('live');
 }
 /**
  * @return DataObject
  */
 public function ContactInformations()
 {
     // 	checks for the active environment type, to load minified css and js files if in live mode
     if (Director::get_environment_type() == "dev" || Director::get_environment_type() == "test") {
         Requirements::css("widget_Contact/css/contactwidget.css");
     } else {
         Requirements::css("widget_Contact/css/contactwidget.min.css");
     }
     return SiteConfig::get()->First();
 }
 /**
  * (non-PHPdoc)
  * @see sapphire/core/control/ContentController#init()
  */
 public function init()
 {
     parent::init();
     // 	checks for the active environment type, to load minified css and js files if in live mode
     if (Director::get_environment_type() == "dev" || Director::get_environment_type() == "test") {
         Requirements::css("imprintpage/css/imprint.css");
     } else {
         Requirements::css("imprintpage/css/imprint.min.css");
     }
 }
 /**
  * @param \Session $session
  * @return void
  */
 public function doBootstrap(Session $session)
 {
     if ($this->container === null) {
         require_once HEYSTACK_BASE_PATH . '/config/container.php';
         $containerClassName = 'HeystackServiceContainer' . \Director::get_environment_type();
         $this->container = new $containerClassName();
     }
     \Injector::inst()->setObjectCreator(new HeystackInjectionCreator($this->container));
     $this->container->get(Services::BACKEND_SESSION)->setSession($session);
     $this->eventDispatcher = $this->container->get(Services::EVENT_DISPATCHER);
 }
 function canView()
 {
     if (self::$trusted_envs && !in_array(Director::get_environment_type(), self::$trusted_envs)) {
         return false;
     }
     if (self::$trusted_ips && !in_array($_SERVER['REMOTE_ADDR'], self::$trusted_ips)) {
         return false;
     }
     if (!self::$activated) {
         return false;
     }
     return parent::canView();
 }
 /**
  * Provides a front-end utility menu with administrative functions and developer tools
  * Relies on SilverStripeNavigator
  *
  * @return string
  */
 public function BetterNavigator()
 {
     // Make sure this is a page
     if (!($this->owner && $this->owner->dataRecord && $this->owner->dataRecord instanceof SiteTree && $this->owner->dataRecord->ID > 0)) {
         return false;
     }
     // Only show navigator to appropriate users
     $isDev = Director::isDev();
     $canViewDraft = Permission::check('VIEW_DRAFT_CONTENT') || Permission::check('CMS_ACCESS_CMSMain');
     if ($isDev || $canViewDraft) {
         // Get SilverStripeNavigator links & stage info (CMS/Stage/Live/Archive)
         $nav = array();
         $viewing = '';
         $navigator = new SilverStripeNavigator($this->owner->dataRecord);
         $items = $navigator->getItems();
         foreach ($items as $item) {
             $name = $item->getName();
             $active = $item->isActive();
             $nav[$name] = array('Link' => $item->getLink(), 'Active' => $active);
             if ($active) {
                 if ($name == 'LiveLink') {
                     $viewing = 'Live';
                 }
                 if ($name == 'StageLink') {
                     $viewing = 'Draft';
                 }
                 if ($name == 'ArchiveLink') {
                     $viewing = 'Archived';
                 }
             }
         }
         // Only show edit link if user has permission to edit this page
         $editLink = $this->owner->dataRecord->canEdit() && Permission::check('CMS_ACCESS_CMSMain') || $isDev ? $nav['CMSLink']['Link'] : false;
         // Is the logged in member nominated as a developer?
         $member = Member::currentUser();
         $devs = Config::inst()->get('BetterNavigator', 'developers');
         $identifierField = Member::config()->unique_identifier_field;
         $isDeveloper = $member && is_array($devs) ? in_array($member->{$identifierField}, $devs) : false;
         // Add other data for template
         $backURL = '?BackURL=' . urlencode($this->owner->Link());
         $bNData = array_merge($nav, array('Member' => $member, 'Stage' => Versioned::current_stage(), 'Viewing' => $viewing, 'LoginLink' => Config::inst()->get('Security', 'login_url') . $backURL, 'LogoutLink' => 'Security/logout' . $backURL, 'EditLink' => $editLink, 'Mode' => Director::get_environment_type(), 'IsDeveloper' => $isDeveloper));
         // Merge with page data, send to template and render
         $bNData = new ArrayData($bNData);
         $page = $this->owner->customise(array('BetterNavigator' => $bNData));
         return $page->renderWith('BetterNavigator');
     }
     return false;
 }
 /**
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return void
  * @throws \Exception
  */
 protected function execute(Input\InputInterface $input, Output\OutputInterface $output)
 {
     if ($input->getOption('dev-build')) {
         $output->writeln('Building database');
         $databaseAdmin = new \DatabaseAdmin();
         $databaseAdmin->doBuild(true);
         $output->writeln('Database built');
     }
     // Get mode
     if ($input->getOption('mode')) {
         $mode = $input->getOption('mode');
     } else {
         $mode = \Director::get_environment_type();
     }
     $container = $this->createContainer();
     $this->loadConfig($container, $mode);
     $output->writeln($this->dumpContainer($container, $mode, $input->getOption('debug')));
 }
 /**
  * Initialises the selected SSPAuthenticator class for SimpleSAMLphp authentication
  * @return SSPAuthenticator Active session for authentication
  */
 private static function init_authenticator()
 {
     $authenticators = SSPSecurity::config()->authenticators;
     if (!$authenticators || !is_array($authenticators)) {
         user_error("Expected array of authentication sources in SSPSecurity::authenticators", E_USER_ERROR);
     }
     $auth_source = '';
     //If set, override authentication sources in config
     if (isset($_GET['as'])) {
         $auth_source = $_GET['as'];
     } else {
         $default_auth = SSPSecurity::config()->default_authenticator;
         $env = Director::get_environment_type();
         if (is_string($default_auth)) {
             $auth_source = $default_auth;
         } else {
             if (is_array($default_auth) && array_key_exists($env, $default_auth)) {
                 $auth_source = $default_auth[$env];
             }
         }
     }
     //If no auth_source is found, default to the first authentication source
     if (empty($auth_source)) {
         $auth_source = key($authenticators);
     }
     if (!array_key_exists($auth_source, $authenticators)) {
         user_error("'{$auth_source}' does not exist in SSPSecurity::authenticators", E_USER_ERROR);
     }
     $class = $authenticators[$auth_source];
     if (!class_exists($class)) {
         user_error("{$class} does not exist", E_USER_ERROR);
     }
     if (!is_subclass_of($class, 'SSPAuthenticator')) {
         user_error("{$class} does not extend from SSPAuthenticator", E_USER_ERROR);
     }
     return self::create_authenticator($class, $auth_source);
 }
Esempio n. 14
0
 public function databaseError($msg, $errorLevel = E_USER_ERROR)
 {
     // try to extract and format query
     if (preg_match('/Couldn\'t run query: ([^\\|]*)\\|\\s*(.*)/', $msg, $matches)) {
         $formatter = new SQLFormatter();
         $msg = "Couldn't run query: \n" . $formatter->formatPlain($matches[1]) . "\n\n" . $matches[2];
     }
     $connect_errno = $this->dbConn->connect_errno;
     $errno = $this->dbConn->errno;
     $sqlstate = $this->dbConn->sqlstate;
     $error = $this->dbConn->error;
     $connect_error = $msg;
     $msg = sprintf('connect_errno : %s - errno : %s - sqlstate : %s - error : %s - connect_error : %s', $connect_errno, $errno, $sqlstate, $error, $connect_error);
     SS_Log::log($msg, SS_Log::ERR);
     if (Director::get_environment_type() === "live") {
         ob_clean();
         $maintenance_page = file_get_contents(Director::baseFolder() . '/maintenance/index.html');
         echo $maintenance_page;
         header("HTTP/1.0 502 Bad Gateway");
         exit;
     } else {
         user_error($msg);
     }
 }
 /**
  * Display information when default route is viewed
  * Default routes is /dev/healthcheck
  */
 public function index()
 {
     $data = array('Title' => 'Health check', 'Content' => 'Health check content...', 'Environment' => Director::get_environment_type(), 'Mailer' => Email::mailer()->class, 'AdminEmail' => Config::inst()->get('Email', 'admin_email'), 'SendAllEmailsTo' => Config::inst()->get('Email', 'send_all_emails_to'), 'Nofollow' => $this->getRobotsMetaTag(), 'Logging' => $this->getLogWriters(), 'SiteMap' => $this->hasSiteMap(), 'LastCommit' => $this->getLastCommit());
     $this->extend('updateIndexData', $data);
     return $this->customise($data)->renderWith(array("HealthCheck"));
 }
 static function GoogleMapAPIKey()
 {
     global $googlemap_api_keys;
     $environment = Director::get_environment_type();
     $api_key = null;
     if (isset($googlemap_api_keys["{$environment}"])) {
         $api_key = $googlemap_api_keys["{$environment}"];
     }
     return $api_key;
 }
Esempio n. 17
0
 /**
  * Set the LastActive time when {@link Order} first created.
  * 
  * (non-PHPdoc)
  * @see DataObject::onBeforeWrite()
  */
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->ID) {
         $this->LastActive = SS_Datetime::now()->getValue();
     }
     //Set the base currency
     if (!$this->BaseCurrency || !$this->BaseCurrencySymbol) {
         $shopConfig = ShopConfig::current_shop_config();
         $this->BaseCurrency = $shopConfig->BaseCurrency;
         $this->BaseCurrencySymbol = $shopConfig->BaseCurrencySymbol;
     }
     //If orders do not exist set the first ID
     if (!Order::get()->count() && true && is_numeric(self::$first_id) && self::$first_id > 0) {
         $this->ID = self::$first_id;
     }
     //Set environment order was placed in
     $this->Env = Director::get_environment_type();
     //Update paid status
     $this->PaymentStatus = $this->getPaid() ? 'Paid' : 'Unpaid';
 }
Esempio n. 18
0
    public function testRenderWithSourceFileComments()
    {
        $origType = Director::get_environment_type();
        Director::set_environment_type('dev');
        SSViewer::set_source_file_comments(true);
        $view = new SSViewer(array('SSViewerTestCommentsFullSource'));
        $data = new ArrayData(array());
        $result = $view->process($data);
        $expected = '<!doctype html>
<html><!-- template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsFullSource.ss -->
	<head></head>
	<body></body>
<!-- end template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsFullSource.ss --></html>
';
        $this->assertEquals($result, $expected);
        $view = new SSViewer(array('SSViewerTestCommentsPartialSource'));
        $data = new ArrayData(array());
        $result = $view->process($data);
        $expected = '<!-- template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsPartialSource.ss -->' . '<div class=\'typography\'></div><!-- end template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsPartialSource.ss -->';
        $this->assertEquals($result, $expected);
        $view = new SSViewer(array('SSViewerTestCommentsWithInclude'));
        $data = new ArrayData(array());
        $result = $view->process($data);
        $expected = '<!-- template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsWithInclude.ss -->' . '<div class=\'typography\'><!-- include \'SSViewerTestCommentsInclude\' --><!-- template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsInclude.ss -->Included<!-- end template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsInclude.ss -->' . '<!-- end include \'SSViewerTestCommentsInclude\' --></div><!-- end template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsWithInclude.ss -->';
        $this->assertEquals($result, $expected);
        SSViewer::set_source_file_comments(false);
        Director::set_environment_type($origType);
    }
Esempio n. 19
0
<?php

use Heystack\Core\Console\Command\GenerateContainer;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
$containerName = 'HeystackServiceContainer' . Director::get_environment_type();
$containerFile = HEYSTACK_BASE_PATH . "/cache/{$containerName}.php";
if (!file_exists($containerFile)) {
    (new GenerateContainer())->run(new ArrayInput([]), new NullOutput());
}
require_once $containerFile;
Esempio n. 20
0
	/**
	 * Get the current environment type from Director.
	 * 
	 * @return string
	 */
	public function EnvironmentType() {
		return Director::get_environment_type();
	}
 /**
  * Gets the combined configuration of all LeafAndMain subclasses required by the client app.
  *
  * @return array
  *
  * WARNING: Experimental API
  */
 public function getCombinedClientConfig()
 {
     $combinedClientConfig = ['sections' => []];
     $cmsClassNames = CMSMenu::get_cms_classes('LeftAndMain', true, CMSMenu::URL_PRIORITY);
     foreach ($cmsClassNames as $className) {
         $combinedClientConfig['sections'][$className] = Injector::inst()->get($className)->getClientConfig();
     }
     // Pass in base url (absolute and relative)
     $combinedClientConfig['baseUrl'] = Director::baseURL();
     $combinedClientConfig['absoluteBaseUrl'] = Director::absoluteBaseURL();
     $combinedClientConfig['adminUrl'] = AdminRootController::admin_url();
     // Get "global" CSRF token for use in JavaScript
     $token = SecurityToken::inst();
     $combinedClientConfig[$token->getName()] = $token->getValue();
     // Set env
     $combinedClientConfig['environment'] = Director::get_environment_type();
     $combinedClientConfig['debugging'] = $this->config()->client_debugging;
     return Convert::raw2json($combinedClientConfig);
 }