public function dispatchLoopShutdown() { if (!Tool::isHtmlResponse($this->getResponse())) { return; } if (!Tool::useFrontendOutputFilters($this->getRequest()) && !$this->getRequest()->getParam("pimcore_preview")) { return; } if (\Pimcore::inDebugMode()) { return; } if ($this->enabled) { include_once "simple_html_dom.php"; $body = $this->getResponse()->getBody(); $html = str_get_html($body); if ($html) { $html = $this->searchForScriptSrcAndReplace($html); $html = $this->searchForInlineScriptAndReplace($html); $body = $html->save(); $html->clear(); unset($html); } $this->getResponse()->setBody($body); } }
/** * @return string */ public function getHref() { $this->updatePathFromInternal(); $url = $this->data['path']; if ($this->data['internalType'] == 'object') { $objectInfo = explode('::', $url); if (count($objectInfo) == 2) { $path = FALSE; $cmdEv = \Pimcore::getEventManager()->trigger('toolbox.url.objectFrontendUrl', null, array('className' => $objectInfo[0], 'path' => $objectInfo[1])); if ($cmdEv->stopped()) { $path = $cmdEv->last(); if (!empty($path)) { $path = \Toolbox\Tools\GlobalLink::parse($path); } } return $path; } else { return FALSE; } } if (strlen($this->data['parameters']) > 0) { $url .= "?" . str_replace("?", "", $this->getParameters()); } if (strlen($this->data['anchor']) > 0) { $url .= "#" . str_replace("#", "", $this->getAnchor()); } return $url; }
/** * */ public function __wakeup() { $options = $this->getOptions(); if (\Pimcore::inAdmin() || empty($options)) { $this->configureOptions(); } }
protected function execute(InputInterface $input, OutputInterface $output) { $validJobs = array(); if ($input->getOption("job")) { $validJobs = explode(",", $input->getOption("job")); } // create manager $manager = Schedule\Manager\Factory::getManager("maintenance.pid"); $manager->setValidJobs($validJobs); $manager->setForce((bool) $input->getOption("force")); // register scheduled tasks $manager->registerJob(new Schedule\Maintenance\Job("scheduledtasks", new Schedule\Task\Executor(), "execute")); $manager->registerJob(new Schedule\Maintenance\Job("logmaintenance", new \Pimcore\Log\Maintenance(), "mail")); $manager->registerJob(new Schedule\Maintenance\Job("cleanuplogfiles", new \Pimcore\Log\Maintenance(), "cleanupLogFiles")); $manager->registerJob(new Schedule\Maintenance\Job("httperrorlog", new \Pimcore\Log\Maintenance(), "httpErrorLogCleanup")); $manager->registerJob(new Schedule\Maintenance\Job("usagestatistics", new \Pimcore\Log\Maintenance(), "usageStatistics")); $manager->registerJob(new Schedule\Maintenance\Job("checkErrorLogsDb", new \Pimcore\Log\Maintenance(), "checkErrorLogsDb")); $manager->registerJob(new Schedule\Maintenance\Job("archiveLogEntries", new \Pimcore\Log\Maintenance(), "archiveLogEntries")); $manager->registerJob(new Schedule\Maintenance\Job("sanitycheck", "\\Pimcore\\Model\\Element\\Service", "runSanityCheck")); $manager->registerJob(new Schedule\Maintenance\Job("versioncleanup", new \Pimcore\Model\Version(), "maintenanceCleanUp")); $manager->registerJob(new Schedule\Maintenance\Job("versioncompress", new \Pimcore\Model\Version(), "maintenanceCompress")); $manager->registerJob(new Schedule\Maintenance\Job("redirectcleanup", "\\Pimcore\\Model\\Redirect", "maintenanceCleanUp")); $manager->registerJob(new Schedule\Maintenance\Job("cleanupbrokenviews", "\\Pimcore\\Db", "cleanupBrokenViews")); $manager->registerJob(new Schedule\Maintenance\Job("downloadmaxminddb", "\\Pimcore\\Update", "updateMaxmindDb")); $manager->registerJob(new Schedule\Maintenance\Job("cleanupcache", "\\Pimcore\\Model\\Cache", "maintenance")); $manager->registerJob(new Schedule\Maintenance\Job("tmpstorecleanup", "\\Pimcore\\Model\\Tool\\TmpStore", "cleanup")); $manager->registerJob(new Schedule\Maintenance\Job("imageoptimize", "\\Pimcore\\Model\\Asset\\Image\\Thumbnail\\Processor", "processOptimizeQueue")); \Pimcore::getEventManager()->trigger("system.maintenance", $manager); $manager->run(); \Logger::info("All maintenance-jobs finished!"); }
/** * @param string $method * @param array $args * @return mixed */ public function callResourceMethod($method, $args) { $capture = false; if (Pimcore::inAdmin()) { $methodsToCheck = array("query", "update", "delete", "insert"); if (in_array($method, $methodsToCheck)) { $capture = true; Pimcore_Resource::startCapturingDefinitionModifications($method, $args); } } //HACK - do not execute transaction methods when //Zend_Registry::set('explicit_transactions', true) was set earlier in code $transactionMethodsToCheck = array('beginTransaction', 'rollBack', 'commit'); try { $explicitTransactions = Zend_Registry::get('explicit_transactions'); } catch (Exception $e) { $explicitTransactions = false; } if (!$explicitTransactions || !in_array($method, $transactionMethodsToCheck)) { $r = call_user_func_array(array($this->getResource(), $method), $args); } if (Pimcore::inAdmin() && $capture) { Pimcore_Resource::stopCapturingDefinitionModifications(); } return $r; }
public function dispatchLoopShutdown() { if (!Tool::isHtmlResponse($this->getResponse())) { return; } if (\Pimcore::inDebugMode()) { return; } if (!Tool::useFrontendOutputFilters($this->getRequest()) && !$this->getRequest()->getParam("pimcore_preview")) { return; } if ($this->enabled) { include_once "simple_html_dom.php"; $body = $this->getResponse()->getBody(); $html = str_get_html($body); if ($html) { $styles = $html->find("link[rel=stylesheet], style[type=text/css]"); $stylesheetContent = ""; foreach ($styles as $style) { if ($style->tag == "style") { $stylesheetContent .= $style->innertext; } else { $source = $style->href; $path = ""; if (is_file(PIMCORE_ASSET_DIRECTORY . $source)) { $path = PIMCORE_ASSET_DIRECTORY . $source; } else { if (is_file(PIMCORE_DOCUMENT_ROOT . $source)) { $path = PIMCORE_DOCUMENT_ROOT . $source; } } if (!empty($path) && is_file("file://" . $path)) { $content = file_get_contents($path); $content = $this->correctReferences($source, $content); if ($style->media && $style->media != "all") { $content = "@media " . $style->media . " {" . $content . "}"; } $stylesheetContent .= $content; $style->outertext = ""; } } } if (strlen($stylesheetContent) > 1) { $stylesheetPath = PIMCORE_TEMPORARY_DIRECTORY . "/minified_css_" . md5($stylesheetContent) . ".css"; if (!is_file($stylesheetPath)) { $stylesheetContent = \Minify_CSS::minify($stylesheetContent); // put minified contents into one single file file_put_contents($stylesheetPath, $stylesheetContent); chmod($stylesheetPath, 0766); } $head = $html->find("head", 0); $head->innertext = $head->innertext . "\n" . '<link rel="stylesheet" type="text/css" href="' . str_replace(PIMCORE_DOCUMENT_ROOT, "", $stylesheetPath) . '" />' . "\n"; } $body = $html->save(); $html->clear(); unset($html); $this->getResponse()->setBody($body); } } }
public function getDataByIdAction() { // check for lock if (Element\Editlock::isLocked($this->getParam("id"), "document")) { $this->_helper->json(["editlock" => Element\Editlock::getByElement($this->getParam("id"), "document")]); } Element\Editlock::lock($this->getParam("id"), "document"); $link = Document\Hardlink::getById($this->getParam("id")); $link = clone $link; $link->idPath = Element\Service::getIdPath($link); $link->userPermissions = $link->getUserPermissions(); $link->setLocked($link->isLocked()); $link->setParent(null); if ($link->getSourceDocument()) { $link->sourcePath = $link->getSourceDocument()->getRealFullPath(); } $this->addTranslationsData($link); $this->minimizeProperties($link); //Hook for modifying return value - e.g. for changing permissions based on object data //data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values $returnValueContainer = new \Pimcore\Model\Tool\Admin\EventDataContainer(object2array($link)); \Pimcore::getEventManager()->trigger("admin.document.get.preSendData", $this, ["document" => $link, "returnValueContainer" => $returnValueContainer]); if ($link->isAllowed("view")) { $this->_helper->json($returnValueContainer->getData()); } $this->_helper->json(false); }
/** * @throws \Zend_EventManager_Exception_InvalidArgumentException */ public function attachEvents() { self::getInstall()->attachEvents(); \Pimcore::getEventManager()->attach('coreshop.payment.getProvider', function ($e) { return $this; }); }
public function getDataByIdAction() { // check for lock if (Element\Editlock::isLocked($this->getParam("id"), "document")) { $this->_helper->json(["editlock" => Element\Editlock::getByElement($this->getParam("id"), "document")]); } Element\Editlock::lock($this->getParam("id"), "document"); $email = Document\Newsletter::getById($this->getParam("id")); $email = clone $email; $email = $this->getLatestVersion($email); $versions = Element\Service::getSafeVersionInfo($email->getVersions()); $email->setVersions(array_splice($versions, 0, 1)); $email->idPath = Element\Service::getIdPath($email); $email->userPermissions = $email->getUserPermissions(); $email->setLocked($email->isLocked()); $email->setParent(null); // unset useless data $email->setElements(null); $email->childs = null; $this->addTranslationsData($email); $this->minimizeProperties($email); //Hook for modifying return value - e.g. for changing permissions based on object data //data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values $returnValueContainer = new \Pimcore\Model\Tool\Admin\EventDataContainer(object2array($email)); \Pimcore::getEventManager()->trigger("admin.document.get.preSendData", $this, ["document" => $email, "returnValueContainer" => $returnValueContainer]); if ($email->isAllowed("view")) { $this->_helper->json($returnValueContainer->getData()); } $this->_helper->json(false); }
public function init() { // Disable plugin if the allowed domain is not yet set $settingDomain = WebsiteSetting::getByName("subdomainAdmin"); if (!is_object($settingDomain) || $settingDomain->getData() == "") { return; } // Create temporary request object - not available yet in front controller $currentUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; $request = new \Zend_Controller_Request_Http($currentUrl); // Disable main domain setting to allow admin access on another domain $conf = Config::getSystemConfig(); $mainDomain = $conf->general->domain; if (Tool::isRequestToAdminBackend($request) && Tool::isDomainAllowedToAdminBackend($request)) { $confArr = $conf->toArray(); $mainDomain = $confArr['general']['domain']; $confArr['general']['domain'] = ""; Config::setSystemConfig(new \Zend_Config($confArr)); } // Register plugin \Pimcore::getEventManager()->attach("system.startup", function ($event) use(&$mainDomain) { $front = \Zend_Controller_Front::getInstance(); $frontControllerPlugin = new FrontControllerPlugin(); $front->registerPlugin($frontControllerPlugin); // Restore main domain $conf = Config::getSystemConfig(); $confArr = $conf->toArray(); $confArr['general']['domain'] = $mainDomain; Config::setSystemConfig(new \Zend_Config($confArr)); }); }
public function getDataByIdAction() { // check for lock if (\Pimcore\Model\Element\Editlock::isLocked($this->getParam("id"), "document")) { $this->_helper->json(["editlock" => \Pimcore\Model\Element\Editlock::getByElement($this->getParam("id"), "document")]); } \Pimcore\Model\Element\Editlock::lock($this->getParam("id"), "document"); $page = Document\Printpage::getById($this->getParam("id")); $page = $this->getLatestVersion($page); $page->getVersions(); $page->getScheduledTasks(); $page->idPath = Service::getIdPath($page); $page->userPermissions = $page->getUserPermissions(); $page->setLocked($page->isLocked()); if ($page->getContentMasterDocument()) { $page->contentMasterDocumentPath = $page->getContentMasterDocument()->getRealFullPath(); } $this->addTranslationsData($page); // unset useless data $page->setElements(null); $page->childs = null; // cleanup properties $this->minimizeProperties($page); //Hook for modifying return value - e.g. for changing permissions based on object data //data need to wrapped into a container in order to pass parameter to event listeners by reference so that they can change the values $returnValueContainer = new \Pimcore\Model\Tool\Admin\EventDataContainer(object2array($page)); \Pimcore::getEventManager()->trigger("admin.document.get.preSendData", $this, ["document" => $page, "returnValueContainer" => $returnValueContainer]); if ($page->isAllowed("view")) { $this->_helper->json($returnValueContainer->getData()); } $this->_helper->json(false); }
public function init() { parent::init(); // set language try { $locale = Zend_Registry::get("Zend_Locale"); $this->setLanguage($locale->getLanguage()); } catch (Exception $e) { if ($this->_getParam("language")) { $this->setLanguage($this->_getParam("language")); } else { $config = Pimcore_Config::getSystemConfig(); $this->setLanguage($config->general->language); } } try { Zend_Registry::get("pimcore_admin_initialized"); $this->setUser(Zend_Registry::get("pimcore_admin_user")); } catch (Exception $e) { // general definitions Document::setHideUnpublished(false); Object_Abstract::setHideUnpublished(false); Object_Abstract::setGetInheritedValues(false); Pimcore::setAdminMode(); // init translations self::initTranslations($this); // init zend action helpers Zend_Controller_Action_HelperBroker::addPrefix('Pimcore_Controller_Action_Helper'); // authenticate user, first try to authenticate with session information $user = Pimcore_Tool_Authentication::authenticateSession(); if ($user instanceof User) { $this->setUser($user); if ($this->getUser()->getLanguage()) { $this->setLanguage($this->getUser()->getLanguage()); } } else { // try to authenticate with digest, but this is only allowed for WebDAV if ($this->_getParam("module") == "admin" && $this->_getParam("controller") == "asset" && $this->_getParam("action") == "webdav") { $user = Pimcore_Tool_Authentication::authenticateDigest(); if ($user instanceof User) { $this->setUser($user); return; } } } // send a auth header for the client (is covered by the ajax object in javascript) if (!$this->getUser() instanceof User) { $this->getResponse()->setHeader("X-Pimcore-Auth", "required"); } // redirect to the login-page if the user isn't authenticated if (!$this->getUser() instanceof User && !($this->_getParam("module") == "admin" && $this->_getParam("controller") == "login")) { $this->_redirect("/admin/login"); $this->getResponse()->sendResponse(); exit; } Zend_Registry::set("pimcore_admin_user", $this->getUser()); Zend_Registry::set("pimcore_admin_initialized", true); } }
/** * @throws \Zend_EventManager_Exception_InvalidArgumentException */ public function attachEvents() { self::getInstall()->attachEvents(); $shopProvider = new Provider(); \Pimcore::getEventManager()->attach("coreshop.payment.getProvider", function ($e) use($shopProvider) { return $shopProvider; }); }
/** * Constructor. * * @param string $name The name of the application * @param string $version The version of the application * * @api */ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') { parent::__construct('Pimcore CLI', Version::getVersion()); // init default autoload namespaces $this->initDefaultAutoloadNamespaces(); // allow to register commands here (e.g. through plugins) \Pimcore::getEventManager()->trigger('system.console.init', $this); }
/** * @throws \Zend_EventManager_Exception_InvalidArgumentException */ public function init() { // attach event-listener foreach (["asset", "object", "document", "object.class"] as $type) { \Pimcore::getEventManager()->attach($type . ".postAdd", array($this, "createUuid")); \Pimcore::getEventManager()->attach($type . ".postDelete", array($this, "deleteUuid")); } }
/** * @throws \Zend_EventManager_Exception_InvalidArgumentException */ public function attachEvents() { self::getInstall()->attachEvents(); \Pimcore::getEventManager()->attach("coreshop.payment.getProvider", function ($e) { //$cart = $e->getParam("cart"); return $this; }); }
/** * @throws \Zend_EventManager_Exception_InvalidArgumentException */ public function init() { // attach event-listener foreach (["asset", "object", "document"] as $type) { \Pimcore::getEventManager()->attach($type . ".postAdd", array($this, "postAddElement")); \Pimcore::getEventManager()->attach($type . ".postUpdate", array($this, "postUpdateElement")); \Pimcore::getEventManager()->attach($type . ".preDelete", array($this, "preDeleteElement")); } }
/** * @return User */ protected function init() { //loads select list options $options = $this->getOptions(); if (\Pimcore::inAdmin() || empty($options)) { $this->configureOptions(); } return $this; }
/** * Get name - Name * @return string */ public function getName() { $preValue = $this->preGetValue("name"); if ($preValue !== null && !\Pimcore::inAdmin()) { return $preValue; } $data = $this->name; return $data; }
/** * @throws \Zend_EventManager_Exception_InvalidArgumentException */ public function init() { parent::init(); \Pimcore::getEventManager()->attach('system.maintenance', array($this, 'maintenanceJob')); \Pimcore::getEventManager()->attach('system.console.init', function (\Zend_EventManager_Event $e) { $application = $e->getTarget(); $application->add(new \LuceneSearch\Console\Command\FrontendCrawlCommand()); }); }
/** * Get name - Name * @return string */ public function getName($language = null) { $data = $this->getLocalizedfields()->getLocalizedValue("name", $language); $preValue = $this->preGetValue("name"); if ($preValue !== null && !\Pimcore::inAdmin()) { return $preValue; } return $data; }
/** * Get priceRule - Price Rule * @return CoreShop\Model\PriceRule */ public function getPriceRule() { $preValue = $this->preGetValue("priceRule"); if ($preValue !== null && !\Pimcore::inAdmin()) { return $preValue; } $data = $this->priceRule; return $data; }
/** * @return \Pimcore\Model\Object\Fieldcollection */ public function getFooterobjectdata() { $preValue = $this->preGetValue("footerobjectdata"); if ($preValue !== null && !\Pimcore::inAdmin()) { return $preValue; } $data = $this->getClass()->getFieldDefinition("footerobjectdata")->preGetData($this); return $data; }
/** * @param $data * @return static */ public static function __set_state($data) { $obj = parent::__set_state($data); $options = $obj->getOptions(); if (\Pimcore::inAdmin() || empty($options)) { $obj->configureOptions(); } return $obj; }
/** * @return \Pimcore\Model\Object\Fieldcollection */ public function getTokenSettings() { $preValue = $this->preGetValue("tokenSettings"); if ($preValue !== null && !\Pimcore::inAdmin()) { return $preValue; } $data = $this->getClass()->getFieldDefinition("tokenSettings")->preGetData($this); return $data; }
/** * Constructor. * * @param string $name The name of the application * @param string $version The version of the application * * @api */ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') { parent::__construct('Pimcore CLI', Version::getVersion()); foreach ($this->defaultAutoloadNamespaces as $namespace => $directory) { $this->addAutoloadNamespace($namespace, $directory); } // allow to register commands here (e.g. through plugins) \Pimcore::getEventManager()->trigger('system.console.init', $this); }
protected function execute(InputInterface $input, OutputInterface $output) { // get all thumbnails $dir = Asset\Image\Thumbnail\Config::getWorkingDir(); $thumbnails = array(); $files = scandir($dir); foreach ($files as $file) { if (strpos($file, ".xml")) { $thumbnails[] = str_replace(".xml", "", $file); } } $allowedThumbs = array(); if ($input->getOption("thumbnails")) { $allowedThumbs = explode(",", $input->getOption("thumbnails")); } // get only images $conditions = array("type = 'image'"); if ($input->getOption("parent")) { $parent = Asset::getById($input->getOption("parent")); if ($parent instanceof Asset\Folder) { $conditions[] = "path LIKE '" . $parent->getFullPath() . "/%'"; } else { $this->writeError($input->getOption("parent") . " is not a valid asset folder ID!"); exit; } } $list = new Asset\Listing(); $list->setCondition(implode(" AND ", $conditions)); $total = $list->getTotalCount(); $perLoop = 10; for ($i = 0; $i < ceil($total / $perLoop); $i++) { $list->setLimit($perLoop); $list->setOffset($i * $perLoop); $images = $list->load(); foreach ($images as $image) { foreach ($thumbnails as $thumbnail) { if (empty($allowedThumbs) && !$input->getOption("system") || in_array($thumbnail, $allowedThumbs)) { if ($input->getOption("force")) { $image->clearThumbnail($thumbnail); } $this->output->writeln("generating thumbnail for image: " . $image->getFullpath() . " | " . $image->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage())); $this->output->writeln("generated thumbnail: " . $image->getThumbnail($thumbnail)); } } if ($input->getOption("system")) { $thumbnail = Asset\Image\Thumbnail\Config::getPreviewConfig(); if ($input->getOption("force")) { $image->clearThumbnail($thumbnail->getName()); } $this->output->writeln("generating thumbnail for image: " . $image->getFullpath() . " | " . $image->getId() . " | Thumbnail: System Preview (tree) : " . formatBytes(memory_get_usage())); $this->output->writeln("generated thumbnail: " . $image->getThumbnail($thumbnail)); } } \Pimcore::collectGarbage(); } }
/** * Init Plugin. */ public function init() { parent::init(); \Pimcore::getEventManager()->attach('system.console.init', function (\Zend_EventManager_Event $e) { /** @var \Pimcore\Console\Application $application */ $application = $e->getTarget(); // add a namespace to autoload commands from $application->addAutoloadNamespace('Manager\\Console', PIMCORE_PLUGINS_PATH . '/Manager/lib/Manager/Console'); }); }
/** * Init Plugin. * * @throws \Zend_EventManager_Exception_InvalidArgumentException */ public function init() { parent::init(); \Pimcore::getEventManager()->attach('system.startup', function (\Zend_EventManager_Event $e) { $frontController = $e->getTarget(); if ($frontController instanceof \Zend_Controller_Front) { $frontController->registerPlugin(new Controller\Plugin\GatewayRouter()); } }); }
/** * @param string $script */ public function includeTemplateFile($script) { $showTemplatePaths = isset($_REQUEST["pimcore_show_template_paths"]); if ($showTemplatePaths && \Pimcore::inDebugMode()) { echo "\n<!-- start template inclusion: " . $script . " -->\n"; } include $script; if ($showTemplatePaths && \Pimcore::inDebugMode()) { echo "\n<!-- finished template inclusion: " . $script . " -->\n"; } }