/** * @param bool $arrayKeys * * @return array|mixed */ private static function getActiveBricks($arrayKeys = TRUE) { $areaElements = ExtensionManager::getBrickConfigs(); /** * @var String $areaElementName * @var \Zend_Config_Xml $areaElementData */ foreach ($areaElements as $areaElementName => $areaElementData) { if (!ExtensionManager::isEnabled('brick', $areaElementName)) { unset($areaElements[$areaElementName]); continue; } } if ($arrayKeys === TRUE) { return array_keys($areaElements); } return $areaElements; }
public function getExtensionsAction() { $configurations = array(); // plugins $pluginConfigs = ExtensionManager::getPluginConfigs(); foreach ($pluginConfigs as $config) { $className = $config["plugin"]["pluginClassName"]; $updateable = false; $revisionFile = PIMCORE_PLUGINS_PATH . "/" . $config["plugin"]["pluginName"] . "/.pimcore_extension_revision"; if (is_file($revisionFile)) { $updateable = true; } if (!empty($className)) { $isEnabled = ExtensionManager::isEnabled("plugin", $config["plugin"]["pluginName"]); $plugin = array("id" => $config["plugin"]["pluginName"], "type" => "plugin", "name" => $config["plugin"]["pluginNiceName"], "description" => $config["plugin"]["pluginDescription"], "installed" => $isEnabled ? $className::isInstalled() : null, "active" => $isEnabled, "configuration" => $config["plugin"]["pluginIframeSrc"], "updateable" => $updateable, "version" => $config["plugin"]["pluginVersion"]); if ($config["plugin"]["pluginXmlEditorFile"] && is_readable(PIMCORE_DOCUMENT_ROOT . $config["plugin"]["pluginXmlEditorFile"])) { $plugin['xmlEditorFile'] = $config["plugin"]["pluginXmlEditorFile"]; } $configurations[] = $plugin; } } // bricks $brickConfigs = ExtensionManager::getBrickConfigs(); // get repo state of bricks foreach ($brickConfigs as $id => $config) { $updateable = false; $revisionFile = PIMCORE_WEBSITE_VAR . "/areas/" . $id . "/.pimcore_extension_revision"; if (is_file($revisionFile)) { $updateable = true; } $isEnabled = ExtensionManager::isEnabled("brick", $id); $brick = array("id" => $id, "type" => "brick", "name" => $config->name, "description" => $config->description, "installed" => true, "active" => $isEnabled, "updateable" => $updateable, "version" => $config->version); $configurations[] = $brick; } $this->_helper->json(array("extensions" => $configurations)); }
/** * @static * @throws Exception|\Zend_Controller_Router_Exception */ public static function run() { self::setSystemRequirements(); // detect frontend (website) $frontend = Tool::isFrontend(); // enable the output-buffer, why? see in self::outputBufferStart() //if($frontend) { self::outputBufferStart(); //} self::initAutoloader(); self::initConfiguration(); self::setupFramework(); // config is loaded now init the real logger self::initLogger(); // initialize cache Cache::init(); // load plugins and modules (=core plugins) self::initModules(); self::initPlugins(); // init front controller $front = \Zend_Controller_Front::getInstance(); $conf = Config::getSystemConfig(); if (!$conf) { // redirect to installer if configuration isn't present if (!preg_match("/^\\/install.*/", $_SERVER["REQUEST_URI"])) { header("Location: /install/"); exit; } } if (self::inDebugMode() && $frontend && !$conf->general->disable_whoops && !defined("HHVM_VERSION")) { $whoops = new \Whoops\Run(); $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler()); $jsonErrorHandler = new \Whoops\Handler\JsonResponseHandler(); $jsonErrorHandler->onlyForAjaxRequests(true); $whoops->pushHandler($jsonErrorHandler); $whoops->register(); // add event handler before Pimcore::shutdown() to ensure fatal errors are handled by Whoops self::getEventManager()->attach("system.shutdown", array($whoops, "handleShutdown"), 10000); } $front->registerPlugin(new Controller\Plugin\ErrorHandler(), 1); $front->registerPlugin(new Controller\Plugin\Maintenance(), 2); // register general pimcore plugins for frontend if ($frontend) { $front->registerPlugin(new Controller\Plugin\Thumbnail(), 795); $front->registerPlugin(new Controller\Plugin\Less(), 799); $front->registerPlugin(new Controller\Plugin\AdminButton(), 806); } if (Tool::useFrontendOutputFilters(new \Zend_Controller_Request_Http())) { $front->registerPlugin(new Controller\Plugin\HybridAuth(), 792); $front->registerPlugin(new Controller\Plugin\QrCode(), 793); $front->registerPlugin(new Controller\Plugin\CommonFilesFilter(), 794); $front->registerPlugin(new Controller\Plugin\WysiwygAttributes(), 796); $front->registerPlugin(new Controller\Plugin\Webmastertools(), 797); $front->registerPlugin(new Controller\Plugin\Analytics(), 798); $front->registerPlugin(new Controller\Plugin\TagManagement(), 804); $front->registerPlugin(new Controller\Plugin\Targeting(), 805); $front->registerPlugin(new Controller\Plugin\EuCookieLawNotice(), 807); $front->registerPlugin(new Controller\Plugin\HttpErrorLog(), 850); $front->registerPlugin(new Controller\Plugin\Cache(), 901); // for caching } self::initControllerFront($front); // set router $router = $front->getRouter(); $routeAdmin = new \Zend_Controller_Router_Route('admin/:controller/:action/*', array('module' => 'admin', "controller" => "index", "action" => "index")); $routeInstall = new \Zend_Controller_Router_Route('install/:controller/:action/*', array('module' => 'install', "controller" => "index", "action" => "index")); $routeUpdate = new \Zend_Controller_Router_Route('admin/update/:controller/:action/*', array('module' => 'update', "controller" => "index", "action" => "index")); $routePlugins = new \Zend_Controller_Router_Route('admin/plugin/:controller/:action/*', array('module' => 'pluginadmin', "controller" => "index", "action" => "index")); $routeExtensions = new \Zend_Controller_Router_Route('admin/extensionmanager/:controller/:action/*', array('module' => 'extensionmanager', "controller" => "index", "action" => "index")); $routeReports = new \Zend_Controller_Router_Route('admin/reports/:controller/:action/*', array('module' => 'reports', "controller" => "index", "action" => "index")); $routePlugin = new \Zend_Controller_Router_Route('plugin/:module/:controller/:action/*', array("controller" => "index", "action" => "index")); $routeWebservice = new \Zend_Controller_Router_Route('webservice/:controller/:action/*', array("module" => "webservice", "controller" => "index", "action" => "index")); $routeSearchAdmin = new \Zend_Controller_Router_Route('admin/search/:controller/:action/*', array("module" => "searchadmin", "controller" => "index", "action" => "index")); // website route => custom router which check for a suitable document $routeFrontend = new Controller\Router\Route\Frontend(); $router->addRoute('default', $routeFrontend); // only do this if not frontend => performance issue if (!$frontend) { $router->addRoute("install", $routeInstall); $router->addRoute('plugin', $routePlugin); $router->addRoute('admin', $routeAdmin); $router->addRoute('update', $routeUpdate); $router->addRoute('plugins', $routePlugins); $router->addRoute('extensionmanager', $routeExtensions); $router->addRoute('reports', $routeReports); $router->addRoute('searchadmin', $routeSearchAdmin); if ($conf instanceof \Zend_Config and $conf->webservice and $conf->webservice->enabled) { $router->addRoute('webservice', $routeWebservice); } // check if this request routes into a plugin, if so check if the plugin is enabled if (preg_match("@^/plugin/([^/]+)/.*@", $_SERVER["REQUEST_URI"], $matches)) { $pluginName = $matches[1]; if (!Pimcore\ExtensionManager::isEnabled("plugin", $pluginName)) { \Pimcore\Tool::exitWithError("Plugin is disabled. To use this plugin please enable it in the extension manager!"); } } // force the main (default) domain for "admin" requests if ($conf->general->domain && $conf->general->domain != Tool::getHostname()) { $url = ($_SERVER['HTTPS'] == "on" ? "https" : "http") . "://" . $conf->general->domain . $_SERVER["REQUEST_URI"]; header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $url, true, 301); exit; } } // check if webdav is configured and add router if ($conf instanceof \Zend_Config) { if ($conf->assets->webdav->hostname) { $routeWebdav = new \Zend_Controller_Router_Route_Hostname($conf->assets->webdav->hostname, array("module" => "admin", 'controller' => 'asset', 'action' => 'webdav')); $router->addRoute('webdav', $routeWebdav); } } $front->setRouter($router); self::getEventManager()->trigger("system.startup", $front); // throw exceptions also when in preview or in editmode (documents) to see it immediately when there's a problem with this page $throwExceptions = false; if (Tool::isFrontentRequestByAdmin()) { $user = \Pimcore\Tool\Authentication::authenticateSession(); if ($user instanceof User) { $throwExceptions = true; } } // run dispatcher // this is also standard for /admin/ requests -> error handling is done in Pimcore_Controller_Action_Admin if (!PIMCORE_DEBUG && !$throwExceptions && !PIMCORE_DEVMODE) { @ini_set("display_errors", "Off"); @ini_set("display_startup_errors", "Off"); $front->dispatch(); } else { @ini_set("display_errors", "On"); @ini_set("display_startup_errors", "On"); $front->throwExceptions(true); try { $front->dispatch(); } catch (\Zend_Controller_Router_Exception $e) { if (!headers_sent()) { header("HTTP/1.0 404 Not Found"); } \Logger::err($e); throw new \Zend_Controller_Router_Exception("No route, document, custom route or redirect is matching the request: " . $_SERVER["REQUEST_URI"] . " | \n" . "Specific ERROR: " . $e->getMessage()); } catch (\Exception $e) { if (!headers_sent()) { header("HTTP/1.0 500 Internal Server Error"); } throw $e; } } }
/** * */ public static function initPlugins() { // add plugin include paths $autoloader = \Zend_Loader_Autoloader::getInstance(); try { $pluginConfigs = ExtensionManager::getPluginConfigs(); if (!empty($pluginConfigs)) { $includePaths = array(get_include_path()); //adding plugin include paths and namespaces if (count($pluginConfigs) > 0) { foreach ($pluginConfigs as $p) { if (!ExtensionManager::isEnabled("plugin", $p["plugin"]["pluginName"])) { continue; } if (is_array($p['plugin']['pluginIncludePaths']['path'])) { foreach ($p['plugin']['pluginIncludePaths']['path'] as $path) { $includePaths[] = PIMCORE_PLUGINS_PATH . $path; } } else { if ($p['plugin']['pluginIncludePaths']['path'] != null) { $includePaths[] = PIMCORE_PLUGINS_PATH . $p['plugin']['pluginIncludePaths']['path']; } } if (is_array($p['plugin']['pluginNamespaces']['namespace'])) { foreach ($p['plugin']['pluginNamespaces']['namespace'] as $namespace) { $autoloader->registerNamespace($namespace); } } else { if ($p['plugin']['pluginNamespaces']['namespace'] != null) { $autoloader->registerNamespace($p['plugin']['pluginNamespaces']['namespace']); } } } } set_include_path(implode(PATH_SEPARATOR, $includePaths)); $broker = \Pimcore\API\Plugin\Broker::getInstance(); //registering plugins foreach ($pluginConfigs as $p) { if (!ExtensionManager::isEnabled("plugin", $p["plugin"]["pluginName"])) { continue; } $jsPaths = array(); $isExtJs5 = \Pimcore\Tool\Admin::isExtJS5(); if ($isExtJs5 && is_array($p['plugin']['pluginJsPaths-extjs5']) && isset($p['plugin']['pluginJsPaths-extjs5']['path']) && is_array($p['plugin']['pluginJsPaths-extjs5']['path'])) { $jsPaths = $p['plugin']['pluginJsPaths-extjs5']['path']; } else { if ($isExtJs5 && is_array($p['plugin']['pluginJsPaths-extjs5']) && $p['plugin']['pluginJsPaths-extjs5']['path'] != null) { $jsPaths[0] = $p['plugin']['pluginJsPaths-extjs5']['path']; } else { if (is_array($p['plugin']['pluginJsPaths']) && isset($p['plugin']['pluginJsPaths']['path']) && is_array($p['plugin']['pluginJsPaths']['path'])) { $jsPaths = $p['plugin']['pluginJsPaths']['path']; } else { if (is_array($p['plugin']['pluginJsPaths']) && $p['plugin']['pluginJsPaths']['path'] != null) { $jsPaths[0] = $p['plugin']['pluginJsPaths']['path']; } } } } //manipulate path for frontend if (is_array($jsPaths) and count($jsPaths) > 0) { for ($i = 0; $i < count($jsPaths); $i++) { if (is_file(PIMCORE_PLUGINS_PATH . $jsPaths[$i])) { $jsPaths[$i] = "/plugins" . $jsPaths[$i]; } } } $cssPaths = array(); if ($isExtJs5 && is_array($p['plugin']['pluginCssPaths-extjs5']) && isset($p['plugin']['pluginCssPaths-extjs5']['path']) && is_array($p['plugin']['pluginCssPaths-extjs5']['path'])) { $cssPaths = $p['plugin']['pluginCssPaths-extjs5']['path']; } else { if ($isExtJs5 && is_array($p['plugin']['pluginCssPaths-extjs5']) && $p['plugin']['pluginCssPaths-extjs5']['path'] != null) { $cssPaths[0] = $p['plugin']['pluginCssPaths-extjs5']['path']; } else { if (is_array($p['plugin']['pluginCssPaths']) && isset($p['plugin']['pluginCssPaths']['path']) && is_array($p['plugin']['pluginCssPaths']['path'])) { $cssPaths = $p['plugin']['pluginCssPaths']['path']; } else { if (is_array($p['plugin']['pluginCssPaths']) && $p['plugin']['pluginCssPaths']['path'] != null) { $cssPaths[0] = $p['plugin']['pluginCssPaths']['path']; } } } } //manipulate path for frontend if (is_array($cssPaths) and count($cssPaths) > 0) { for ($i = 0; $i < count($cssPaths); $i++) { if (is_file(PIMCORE_PLUGINS_PATH . $cssPaths[$i])) { $cssPaths[$i] = "/plugins" . $cssPaths[$i]; } } } try { $className = $p['plugin']['pluginClassName']; if (!empty($className) && Tool::classExists($className)) { $plugin = new $className($jsPaths, $cssPaths); if ($plugin instanceof \Pimcore\API\Plugin\AbstractPlugin) { $broker->registerPlugin($plugin); } } } catch (\Exception $e) { \Logger::err("Could not instantiate and register plugin [" . $p['plugin']['pluginClassName'] . "]"); } } \Zend_Registry::set("Pimcore_API_Plugin_Broker", $broker); } } catch (\Exception $e) { \Logger::alert("there is a problem with the plugin configuration"); \Logger::alert($e); } }
/** * @see Model\Document\Tag\TagInterface::frontend */ public function frontend() { $count = 0; $options = $this->getOptions(); // don't show disabled bricks if (!ExtensionManager::isEnabled("brick", $options["type"]) && $options['dontCheckEnabled'] != true) { return; } $this->setupStaticEnvironment(); $suffixes = \Zend_Registry::get("pimcore_tag_block_current"); $suffixes[] = $this->getName(); \Zend_Registry::set("pimcore_tag_block_current", $suffixes); $this->current = $count; // create info object and assign it to the view $info = null; try { $info = new Area\Info(); $info->setTag($this); $info->setId($options["type"]); $info->setIndex($count); $info->setPath(str_replace(PIMCORE_DOCUMENT_ROOT, "", ExtensionManager::getPathForExtension($options["type"], "brick"))); $info->setConfig(ExtensionManager::getBrickConfig($options["type"])); } catch (\Exception $e) { $info = null; } $suffixes = \Zend_Registry::get("pimcore_tag_block_numeration"); $suffixes[] = 1; \Zend_Registry::set("pimcore_tag_block_numeration", $suffixes); if ($this->getView() instanceof \Zend_View) { $this->getView()->brick = $info; $areas = $this->getAreaDirs(); $view = $areas[$options["type"]] . "/view.php"; $action = $areas[$options["type"]] . "/action.php"; $edit = $areas[$options["type"]] . "/edit.php"; $options = $this->getOptions(); $params = array(); if (is_array($options["params"]) && array_key_exists($options["type"], $options["params"])) { if (is_array($options["params"][$options["type"]])) { $params = $options["params"][$options["type"]]; } } // assign parameters to view foreach ($params as $key => $value) { $this->getView()->assign($key, $value); } // check for action file if (is_file($action)) { include_once $action; $actionClassFound = true; $actionClassname = "\\Pimcore\\Model\\Document\\Tag\\Area\\" . ucfirst($options["type"]); if (!Tool::classExists($actionClassname, false)) { // also check the legacy prefixed class name, as this is used by some plugins $actionClassname = "\\Document_Tag_Area_" . ucfirst($options["type"]); if (!Tool::classExists($actionClassname, false)) { $actionClassFound = false; } } if ($actionClassFound) { $actionObject = new $actionClassname(); if ($actionObject instanceof Area\AbstractArea) { $actionObject->setView($this->getView()); $areaConfig = new \Zend_Config_Xml($areas[$options["type"]] . "/area.xml"); $actionObject->setConfig($areaConfig); // params $params = array_merge($this->view->getAllParams(), $params); $actionObject->setParams($params); if ($info) { $actionObject->setBrick($info); } if (method_exists($actionObject, "action")) { $actionObject->action(); } $this->getView()->assign('actionObject', $actionObject); } } } if (is_file($view)) { $editmode = $this->getView()->editmode; if (method_exists($actionObject, "getBrickHtmlTagOpen")) { echo $actionObject->getBrickHtmlTagOpen($this); } else { echo '<div class="pimcore_area_' . $options["type"] . ' pimcore_area_content">'; } if (is_file($edit) && $editmode) { echo '<div class="pimcore_area_edit_button"></div>'; // forces the editmode in view.php independent if there's an edit.php or not if (!array_key_exists("forceEditInView", $params) || !$params["forceEditInView"]) { $this->getView()->editmode = false; } } $this->getView()->template($view); if (is_file($edit) && $editmode) { $this->getView()->editmode = true; echo '<div class="pimcore_area_editmode pimcore_area_editmode_hidden">'; $this->getView()->template($edit); echo '</div>'; } if (method_exists($actionObject, "getBrickHtmlTagClose")) { echo $actionObject->getBrickHtmlTagClose($this); } else { echo '</div>'; } if (is_object($actionObject) && method_exists($actionObject, "postRenderAction")) { $actionObject->postRenderAction(); } } } $suffixes = \Zend_Registry::get("pimcore_tag_block_numeration"); array_pop($suffixes); \Zend_Registry::set("pimcore_tag_block_numeration", $suffixes); $suffixes = \Zend_Registry::get("pimcore_tag_block_current"); array_pop($suffixes); \Zend_Registry::set("pimcore_tag_block_current", $suffixes); }
/** * @param $name * @return bool */ public function isBrickEnabled($name) { if ($this->isCustomAreaPath()) { return true; } return ExtensionManager::isEnabled("brick", $name); }
/** * @param null $customPath * @return array|mixed */ public static function getBrickDirectories($customPath = null) { $cacheKey = "brick_directories"; if ($customPath) { $cacheKey .= "_" . crc32($customPath); } $areas = []; try { $areas = \Zend_Registry::get($cacheKey); } catch (\Exception $e) { if ($customPath) { $areaRepositories = [$customPath]; } else { $areaRepositories = [PIMCORE_WEBSITE_PATH . "/views/areas", PIMCORE_WEBSITE_VAR . "/areas"]; } // include area repositories from active plugins $configs = ExtensionManager::getPluginConfigs(); foreach ($configs as $config) { $className = $config["plugin"]["pluginClassName"]; if (!empty($className)) { $isEnabled = ExtensionManager::isEnabled("plugin", $config["plugin"]["pluginName"]); $areaDir = PIMCORE_PLUGINS_PATH . "/" . $config["plugin"]["pluginName"] . "/views/areas"; if ($isEnabled && file_exists($areaDir)) { $areaRepositories[] = $areaDir; } } } // get directories foreach ($areaRepositories as $respository) { if (is_dir($respository) && is_readable($respository)) { $blockDirs = scandir($respository); foreach ($blockDirs as $blockDir) { if (is_dir($respository . "/" . $blockDir)) { if (is_file($respository . "/" . $blockDir . "/area.xml")) { $areas[$blockDir] = $respository . "/" . $blockDir; } } } } } \Zend_Registry::set($cacheKey, $areas); } return $areas; }