public static function saveCachedEnvironmentObject()
 {
     if (!file_exists(Config::get('concrete.cache.directory') . '/' . Config::get('concrete.cache.environment.file'))) {
         $env = new Environment();
         $env->getOverrides();
         @file_put_contents(Config::get('concrete.cache.directory') . '/' . Config::get('concrete.cache.environment.file'), serialize($env));
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $db = \Database::connection();
     $em = $db->getEntityManager();
     $cacheDriver = $em->getConfiguration()->getMetadataCacheImpl();
     $cacheDriver->flushAll();
     $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $schemas = [];
     /**
      * @var $sm MySqlSchemaManager
      */
     $sm = $db->getSchemaManager();
     $dbSchema = $sm->createSchema();
     // core xml tables
     $schemas[] = Schema::getCoreXMLSchema();
     // core entities
     $sm = new DatabaseStructureManager($em);
     $entities = $sm->getMetadatas();
     $schemas[] = $tool->getSchemaFromMetadata($entities);
     // core, application and package block types
     $env = Environment::get();
     $list = new BlockTypeList();
     $list->includeInternalBlockTypes();
     foreach ($list->get() as $bt) {
         $r = $env->getRecord(DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . '/' . FILENAME_BLOCK_DB, $bt->getPackageHandle());
         if ($r->exists()) {
             $parser = Schema::getSchemaParser(simplexml_load_file($r->file));
             $parser->setIgnoreExistingTables(false);
             $schemas[] = $parser->parse($db);
         }
     }
     // packages
     $packages = Package::getInstalledList();
     foreach ($packages as $pkg) {
         $xmlFile = $pkg->getPackagePath() . '/' . FILENAME_BLOCK_DB;
         if (file_exists($xmlFile)) {
             $parser = Schema::getSchemaParser(simplexml_load_file($xmlFile));
             $parser->setIgnoreExistingTables(false);
             $schemas[] = $parser->parse($db);
         }
     }
     // Finalize output.
     $comparator = new \Doctrine\DBAL\Schema\Comparator();
     $saveQueries = array();
     foreach ($schemas as $schema) {
         $schemaDiff = $comparator->compare($dbSchema, $schema);
         $saveQueries = array_merge($saveQueries, $schemaDiff->toSaveSql($db->getDatabasePlatform()));
     }
     $saveQueries = $this->filterQueries($saveQueries);
     if (count($saveQueries)) {
         $output->writeln(t2('%s query found', '%s queries found', count($saveQueries)));
         $i = 1;
         foreach ($saveQueries as $query) {
             $output->writeln(sprintf('%s: %s', $i, $query));
             $i++;
         }
     } else {
         $output->writeln(t('No differences found between schema and database.'));
     }
 }
 public function getLocation()
 {
     $r = Environment::get();
     $record = false;
     foreach ($this->locations as $location) {
         $record = $r->getRecord($location[0], $location[1]);
         if ($record->exists()) {
             return $record;
         }
     }
     // Return the final record even if the file doesn't exist
     return $record;
 }
Beispiel #4
0
 /**
  * Given a path to a single page, this command uses the CURRENT controller and renders
  * the contents of the single page within this request. The current controller is not
  * replaced, and has already fired (since it is meant to be called from within a view() or
  * similar method).
  *
  * @param @string
  */
 public function render($path)
 {
     $view = $this->getViewObject();
     $env = Environment::get();
     $path = trim($path, '/');
     $a = $path . '/' . FILENAME_COLLECTION_VIEW;
     $b = $path . '.php';
     $r = $env->getRecord(DIRNAME_PAGES . '/' . $a);
     if ($r->exists()) {
         $view->renderSinglePageByFilename($a);
     } else {
         $view->renderSinglePageByFilename($b);
     }
 }
 public function register()
 {
     $singletons = array('helper/concrete/asset_library' => '\\Concrete\\Core\\Application\\Service\\FileManager', 'helper/concrete/file_manager' => '\\Concrete\\Core\\Application\\Service\\FileManager', 'helper/concrete/composer' => '\\Concrete\\Core\\Application\\Service\\Composer', 'helper/concrete/dashboard' => '\\Concrete\\Core\\Application\\Service\\Dashboard', 'helper/concrete/dashboard/sitemap' => '\\Concrete\\Core\\Application\\Service\\Dashboard\\Sitemap', 'helper/concrete/ui' => '\\Concrete\\Core\\Application\\Service\\UserInterface', 'helper/concrete/ui/menu' => '\\Concrete\\Core\\Application\\Service\\UserInterface\\Menu', 'helper/concrete/ui/help' => '\\Concrete\\Core\\Application\\Service\\UserInterface\\Help', 'helper/concrete/upgrade' => '\\Concrete\\Core\\Application\\Service\\Upgrade', 'helper/concrete/urls' => '\\Concrete\\Core\\Application\\Service\\Urls', 'helper/concrete/user' => '\\Concrete\\Core\\Application\\Service\\User', 'helper/concrete/validation' => '\\Concrete\\Core\\Application\\Service\\Validation', 'helper/rating' => '\\Concrete\\Attribute\\Rating\\Service', 'helper/pagination' => '\\Concrete\\Core\\Legacy\\Pagination', 'help' => '\\Concrete\\Core\\Application\\Service\\UserInterface\\Help', 'help/core' => '\\Concrete\\Core\\Application\\Service\\UserInterface\\Help\\CoreManager', 'help/dashboard' => '\\Concrete\\Core\\Application\\Service\\UserInterface\\Help\\DashboardManager', 'help/block_type' => '\\Concrete\\Core\\Application\\Service\\UserInterface\\Help\\BlockTypeManager', 'help/panel' => '\\Concrete\\Core\\Application\\Service\\UserInterface\\Help\\PanelManager');
     $this->app->singleton('Concrete\\Core\\Block\\Menu\\Manager');
     foreach ($singletons as $key => $value) {
         $this->app->singleton($key, $value);
     }
     $this->app->bind('error', 'Concrete\\Core\\Error\\ErrorList\\ErrorList');
     $this->app->bindShared('environment', function ($app) {
         $env = Environment::get();
         return $env;
     });
     /*
      * @deprecated
      */
     $this->app->singleton('helper/concrete/avatar', '\\Concrete\\Core\\Legacy\\Avatar');
 }
Beispiel #6
0
 public function __construct()
 {
     $loc = Localization::getInstance();
     $loc->pushActiveContext('system');
     try {
         $app = Facade::getFacadeApplication();
         $config = $app->make('config');
         $maxExecutionTime = ini_get('max_execution_time');
         @set_time_limit(5);
         $this->installed = (bool) $app->isInstalled();
         $this->webRootDirectory = DIR_BASE;
         $this->coreRootDirectory = DIR_BASE_CORE;
         $versions = ['Core Version - ' . $config->get('concrete.version')];
         if ($this->installed) {
             $versions[] = 'Version Installed - ' . $config->get('concrete.version_installed');
         }
         $versions[] = 'Database Version - ' . $config->get('concrete.version_db');
         $this->coreVersions = implode("\n", $versions);
         $packages = [];
         if ($this->installed) {
             foreach (PackageList::get()->getPackages() as $p) {
                 if ($p->isPackageInstalled()) {
                     $packages[] = $p->getPackageName() . ' (' . $p->getPackageVersion() . ')';
                 }
             }
         }
         natcasesort($packages);
         $this->packages = implode(', ', $packages);
         $overrides = Environment::get()->getOverrideList();
         if (empty($overrides)) {
             $this->overrides = '';
         } else {
             $this->overrides = implode(', ', $overrides);
         }
         $cache = [sprintf('Block Cache - %s', $config->get('concrete.cache.blocks') ? 'On' : 'Off'), sprintf('Overrides Cache - %s', $config->get('concrete.cache.overrides') ? 'On' : 'Off'), sprintf('Full Page Caching - %s', $config->get('concrete.cache.pages') == 'blocks' ? 'On - If blocks on the particular page allow it.' : ($config->get('concrete.cache.pages') == 'all' ? 'On - In all cases.' : 'Off'))];
         if ($config->get('concrete.cache.full_page_lifetime')) {
             $cache[] = sprintf("Full Page Cache Lifetime - %s", $config->get('concrete.cache.full_page_lifetime') == 'default' ? sprintf('Every %s (default setting).', $app->make('helper/date')->describeInterval($config->get('concrete.cache.lifetime'))) : ($config->get('concrete.cache.full_page_lifetime') == 'forever' ? 'Only when manually removed or the cache is cleared.' : sprintf('Every %s minutes.', $config->get('concrete.cache.full_page_lifetime_value'))));
         }
         $this->cache = implode("\n", $cache);
         $this->serverSoftware = \Request::getInstance()->server->get('SERVER_SOFTWARE', '');
         $this->serverAPI = PHP_SAPI;
         $this->phpVersion = PHP_VERSION;
         if (function_exists('get_loaded_extensions')) {
             $extensions = @get_loaded_extensions();
         } else {
             $extensions = false;
         }
         if (is_array($extensions)) {
             natcasesort($extensions);
             $this->phpExtensions = implode(', ', $extensions);
         } else {
             $this->phpExtensions = false;
         }
         ob_start();
         phpinfo();
         $buffer = ob_get_clean();
         $phpinfo = [];
         if ($app->isRunThroughCommandLineInterface()) {
             $section = null;
             foreach (preg_split('/[\\r\\n]+/', $buffer) as $line) {
                 $chunks = array_map('trim', explode('=>', $line));
                 switch (count($chunks)) {
                     case 1:
                         if ($chunks[0] === '') {
                             continue;
                         }
                         $section = $chunks[0];
                         break;
                     case 2:
                         if ($section !== null) {
                             $phpinfo[$section][$chunks[0]] = $chunks[1];
                         }
                         break;
                     default:
                         if ($section !== null) {
                             $phpinfo[$section][$chunks[0]] = [$chunks[1], $chunks[2]];
                         }
                         break;
                 }
             }
         } else {
             $section = 'phpinfo';
             $phpinfo[$section] = [];
             if (preg_match_all('#(?:<h2>(?:<a name=".*?">)?(.*?)(?:</a>)?</h2>)|(?:<tr(?: class=".*?")?><t[hd](?: class=".*?")?>(.*?)\\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\\s*</t[hd]>)?)?</tr>)#s', $buffer, $matches, PREG_SET_ORDER)) {
                 foreach ($matches as $match) {
                     if ($match[1] !== null && $match[1] !== '') {
                         $section = $match[1];
                         $phpinfo[$section] = [];
                     } elseif (isset($match[3])) {
                         $phpinfo[$section][$match[2]] = isset($match[4]) ? [$match[3], $match[4]] : $match[3];
                     } else {
                         $phpinfo[$section][] = $match[2];
                     }
                 }
             }
         }
         $phpSettings = ["max_execution_time - {$maxExecutionTime}"];
         foreach ($phpinfo as $name => $section) {
             foreach ($section as $key => $val) {
                 if (preg_match('/.*max_execution_time*/', $key)) {
                     continue;
                 }
                 if (strpos($key, 'limit') === false && strpos($key, 'safe') === false && strpos($key, 'max') === false) {
                     continue;
                 }
                 if (is_array($val)) {
                     $phpSettings[] = "{$key} - {$val[0]}";
                 } elseif (is_string($key)) {
                     $phpSettings[] = "{$key} - {$val}";
                 } else {
                     $phpSettings[] = $val;
                 }
             }
         }
         $this->phpSettings = implode("\n", $phpSettings);
         $loc->popActiveContext();
     } catch (\Exception $x) {
         $loc->popActiveContext();
         throw $x;
     }
 }
 /**
  * Returns an asset path relative to the theme directory.
  * If the second argument is given, it is used as the
  * theme handle for which the path is returned. If the
  * theme handle is not defined, the current theme is
  * used instead.
  *
  * @param \Less_Tree $urlTree
  * @param \Less_Tree|null $themeTree
  *
  * @return \Less_Tree
  */
 public function themeAssetPath($urlTree, $themeTree = null)
 {
     $url = $urlTree->value;
     $theme = is_object($themeTree) ? $themeTree->value : null;
     if ($url[0] != '/') {
         $url = '/' . $url;
     }
     if (empty($theme)) {
         $theme = $this->getCurrentTheme();
     } else {
         $to = Theme::getByHandle($theme);
         if (!is_object($to)) {
             throw new \Exception(t("Invalid theme-asset-url: %s, %s. A theme does not exist with handle: %s.", $url, $theme, $theme));
         }
         $theme = $to;
     }
     // Default to theme URL
     $env = Environment::get();
     $themeUrl = $env->getURL(DIRNAME_THEMES . '/' . $theme->getThemeHandle(), $theme->getPackageHandle());
     $urlTree->value = $themeUrl . $url;
     return $urlTree;
 }
 /**
  * Given the current update object, sends information to concrete5.org to determine updatability
  * @return \Concrete\Core\Updater\ApplicationUpdateDiagnostic
  */
 public function getDiagnosticObject()
 {
     $request = new Request();
     $request->setUri(Config::get('concrete.updates.services.inspect_update'));
     $request->setMethod('POST');
     $request->getPost()->set('current_version', Config::get('concrete.version_installed'));
     $request->getPost()->set('requested_version', $this->getVersion());
     $request->getPost()->set('site_url', (string) \Core::getApplicationURL());
     $mi = Marketplace::getInstance();
     if ($mi->isConnected() && !$mi->hasConnectionError()) {
         $config = \Core::make('config/database');
         $request->getPost()->set('marketplace_token', $config->get('concrete.marketplace.token'));
         $list = Package::getInstalledList();
         $packages = array();
         foreach ($list as $pkg) {
             $packages[] = array('version' => $pkg->getPackageVersion(), 'handle' => $pkg->getPackageHandle());
         }
         $request->getPost()->set('packages', $packages);
     }
     $overrides = id(Environment::get())->getOverrideList();
     $request->getPost()->set('overrides', $overrides);
     $client = new Client();
     $client->setMethod('POST');
     $response = $client->send($request);
     $body = $response->getBody();
     $diagnostic = DiagnosticFactory::getFromJSON($body);
     return $diagnostic;
 }
 public function hasSearchForm()
 {
     $env = Environment::get();
     $rec = $env->getRecord(DIRNAME_ELEMENTS . '/export/search/' . $this->itemType->getHandle() . '.php', 'migration_tool');
     return $rec->exists();
 }
Beispiel #10
0
 public function setUp()
 {
     parent::setUp();
     $env = \Concrete\Core\Foundation\Environment::get();
     $env->clearOverrideCache();
 }
Beispiel #11
0
 public function get_environment_info()
 {
     $activeLocale = Localization::activeLocale();
     if ($activeLocale != 'en_US') {
         Localization::changeLocale('en_US');
     }
     $maxExecutionTime = ini_get('max_execution_time');
     set_time_limit(5);
     $environmentMessage = "# concrete5 Version\n";
     $environmentMessage .= "Core Version - " . \Config::get('concrete.version') . "\n";
     $environmentMessage .= "Version Installed - " . \Config::get('concrete.version_installed') . "\n";
     $environmentMessage .= "Database Version - " . \Config::get('concrete.version_db') . "\n\n";
     $environmentMessage .= "# concrete5 Packages\n";
     $pla = PackageList::get();
     $pl = $pla->getPackages();
     $packages = array();
     foreach ($pl as $p) {
         if ($p->isPackageInstalled()) {
             $packages[] = $p->getPackageName() . ' (' . $p->getPackageVersion() . ')';
         }
     }
     if (count($packages) > 0) {
         natcasesort($packages);
         $environmentMessage .= implode(', ', $packages);
         $environmentMessage .= ".\n";
     } else {
         $environmentMessage .= "None\n";
     }
     $environmentMessage .= "\n";
     // overrides
     $environmentMessage .= "# concrete5 Overrides\n";
     $env = Environment::get();
     $overrides = $env->getOverrideList();
     if (count($overrides) > 0) {
         $environmentMessage .= implode(', ', $overrides);
         $environmentMessage .= "\n";
     } else {
         $environmentMessage .= "None\n";
     }
     $environmentMessage .= "\n";
     print $environmentMessage;
     // cache
     $environmentMessage = "# concrete5 Cache Settings\n";
     $environmentMessage .= sprintf("Block Cache - %s\n", Config::get('concrete.cache.blocks') ? 'On' : 'Off');
     $environmentMessage .= sprintf("Overrides Cache - %s\n", Config::get('concrete.cache.overrides') ? 'On' : 'Off');
     $environmentMessage .= sprintf("Full Page Caching - %s\n", Config::get('concrete.cache.pages') == 'blocks' ? 'On - If blocks on the particular page allow it.' : (Config::get('concrete.cache.pages') == 'all' ? 'On - In all cases.' : 'Off'));
     if (Config::get('concrete.cache.full_page_lifetime')) {
         $environmentMessage .= sprintf("Full Page Cache Lifetime - %s\n", Config::get('concrete.cache.full_page_lifetime') == 'default' ? sprintf('Every %s (default setting).', Core::make('helper/date')->describeInterval(Config::get('concrete.cache.lifetime'))) : (Config::get('concrete.cache.full_page_lifetime') == 'forever' ? 'Only when manually removed or the cache is cleared.' : sprintf('Every %s minutes.', Config::get('concrete.cache.full_page_lifetime_value'))));
     }
     $environmentMessage .= "\n";
     print $environmentMessage;
     $environmentMessage = "# Server Software\n" . $_SERVER['SERVER_SOFTWARE'] . "\n\n";
     $environmentMessage .= "# Server API\n" . php_sapi_name() . "\n\n";
     $environmentMessage .= "# PHP Version\n" . PHP_VERSION . "\n\n";
     $environmentMessage .= "# PHP Extensions\n";
     if (function_exists('get_loaded_extensions')) {
         $gle = @get_loaded_extensions();
         natcasesort($gle);
         $environmentMessage .= implode(', ', $gle);
         $environmentMessage .= ".\n";
     } else {
         $environmentMessage .= "Unable to determine\n";
     }
     print $environmentMessage;
     ob_start();
     phpinfo();
     $section = 'phpinfo';
     $phpinfo = array($section => array());
     if (preg_match_all('#(?:<h2>(?:<a name=".*?">)?(.*?)(?:</a>)?</h2>)|(?:<tr(?: class=".*?")?><t[hd](?: class=".*?")?>(.*?)\\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\\s*</t[hd]>)?)?</tr>)#s', ob_get_clean(), $matches, PREG_SET_ORDER)) {
         foreach ($matches as $match) {
             if (strlen($match[1])) {
                 $section = $match[1];
                 $phpinfo[$section] = array();
             } elseif (isset($match[3])) {
                 $phpinfo[$section][$match[2]] = isset($match[4]) ? array($match[3], $match[4]) : $match[3];
             } else {
                 $phpinfo[$section][] = $match[2];
             }
         }
     }
     $environmentMessage = "\n# PHP Settings\n";
     $environmentMessage .= "max_execution_time - {$maxExecutionTime}\n";
     foreach ($phpinfo as $name => $section) {
         foreach ($section as $key => $val) {
             if (preg_match('/.*max_execution_time*/', $key)) {
                 continue;
             }
             if (!preg_match('/.*limit.*/', $key) && !preg_match('/.*safe.*/', $key) && !preg_match('/.*max.*/', $key)) {
                 continue;
             }
             if (is_array($val)) {
                 $environmentMessage .= "{$key} - {$val['0']}\n";
             } elseif (is_string($key)) {
                 $environmentMessage .= "{$key} - {$val}\n";
             } else {
                 $environmentMessage .= "{$val}\n";
             }
         }
     }
     print $environmentMessage;
     exit;
 }
Beispiel #12
0
 /**
  * Return the class file that this BlockType uses.
  *
  * @return string
  */
 public static function getBlockTypeMappedClass($btHandle, $pkgHandle = false)
 {
     $env = Environment::get();
     $txt = Core::make('helper/text');
     $r = $env->getRecord(DIRNAME_BLOCKS . '/' . $btHandle . '/' . FILENAME_CONTROLLER);
     // Replace $pkgHandle if overridden via environment
     $r->pkgHandle and $pkgHandle = $r->pkgHandle;
     $prefix = $r->override ? true : $pkgHandle;
     $class = core_class('Block\\' . $txt->camelcase($btHandle) . '\\Controller', $prefix);
     if (class_exists($class)) {
         return $class;
     }
 }
Beispiel #13
0
 public function getOverrideList()
 {
     return parent::getOverrideList();
 }
 /**
  * Returns an asset path relative to the theme directory.
  * The given arguments array needs to contain 1-2 values
  * in it as follows:
  *
  * 1. The first item in the array needs to be the relative
  *    URL for which we want the full path for.
  * 2. The second item in the array can either be left out
  *    or when defined, represent the theme handle.
  *
  * If the second argument is given, it is used as the
  * theme handle for which the path is returned. If the
  * theme handle is not defined, the current theme is
  * used instead.
  *
  * @param array $args
  *
  * @return string
  */
 public function themeAssetPath(array $args)
 {
     list($url, $theme) = $args;
     $url = $this->extractStringFromArgument($url);
     $theme = $this->extractStringFromArgument($theme);
     if ($url[0] != '/') {
         $url = '/' . $url;
     }
     if (empty($theme)) {
         $theme = $this->getCurrentTheme();
     } else {
         $to = Theme::getByHandle($theme);
         if (!is_object($to)) {
             throw new \Exception(t("Invalid theme-asset-url: %s, %s. A theme does not exist with handle: %s.", $url, $theme, $theme));
         }
         $theme = $to;
     }
     // Default to theme URL
     $env = Environment::get();
     $themeUrl = $env->getURL(DIRNAME_THEMES . '/' . $theme->getThemeHandle(), $theme->getPackageHandle());
     return $themeUrl . $url;
 }
Beispiel #15
0
 public function getFullPath($path, $dirName = null)
 {
     if ($path[0] == '@') {
         if (($pos = strpos($path, '/')) !== false) {
             $location = substr($path, 1, $pos);
             $subpath = substr($path, $pos + 1);
             $locationPath = '';
             if ($location == 'core') {
                 $locationPath = DIR_BASE_CORE;
             } elseif ($location == 'app') {
                 $locationPath = DIR_APPLICATION;
             } elseif ($location == 'package') {
                 if (($pos = strpos($subpath, '/')) !== false) {
                     $pkgHandle = substr($subpath, 0, $pos);
                     $subpath = substr($subpath, $pos + 1);
                     $locationPath = DIR_PACKAGES . '/' . $pkgHandle;
                 } else {
                     throw new Exception(t("Invalid path: %s. Package not defined.", $path));
                 }
             } elseif ($location == 'theme') {
                 if (($pos = strpos($subpath, '/')) !== false) {
                     $themeHandle = substr($subpath, 0, $pos);
                     $subpath = substr($subpath, $pos + 1);
                     if (is_object($th = Theme::getByHandle($themeHandle))) {
                         $env = Environment::get();
                         $locationPath = $env->getPath(DIRNAME_THEMES . '/' . $themeHandle, $th->getPackageHandle());
                     } else {
                         throw new Exception(t("Invalid theme in path: %s. Theme '%s' does not exist."));
                     }
                 } else {
                     throw new Exception(t("Invalid path: %s. Theme not defined.", $path));
                 }
             } else {
                 throw new Exception(t("Invalid path: %s. Unknown location: %s.", $path, $location));
             }
             if (!empty($locationPath)) {
                 return $locationPath . '/' . $dirName . '/' . $subpath;
             }
         } else {
             // This is an assetic alias, e.g. "@jquery".
             return $path;
         }
     } elseif ($path[0] == '/' || preg_match('#[a-z]:[/\\\\]#i', $path)) {
         return $path;
     }
     // Theme specific CSS (default)
     return $this->themeBasePath . '/' . $dirName . '/' . $path;
 }