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); } }
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); } } }
/** * @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"; } }
/** * @param bool $raw * @param bool $writeOnly * @return Wrapper|\Zend_Db_Adapter_Abstract * @throws \Exception * @throws \Zend_Db_Profiler_Exception */ public static function getConnection($raw = false, $writeOnly = false) { // just return the wrapper (for compatibility reasons) // the wrapper itself get's then the connection using $raw = true if (!$raw) { return new Wrapper(); } $charset = "UTF8"; // explicit set charset for connection (to the adapter) $config = Config::getSystemConfig()->database->toArray(); // write only handling if ($writeOnly && isset($config["writeOnly"])) { // overwrite params with write only configuration $config["params"] = $config["writeOnly"]["params"]; } else { if ($writeOnly) { throw new \Exception("writeOnly connection is requested but not configured"); } } $config["params"]["charset"] = $charset; try { $db = \Zend_Db::factory($config["adapter"], $config["params"]); $db->query("SET NAMES " . $charset); } catch (\Exception $e) { \Logger::emerg($e); \Pimcore\Tool::exitWithError("Database Error! See debug.log for details"); } // try to set innodb as default storage-engine try { $db->query("SET storage_engine=InnoDB;"); } catch (\Exception $e) { \Logger::warn($e); } // try to set mysql mode try { $db->query("SET sql_mode = '';"); } catch (\Exception $e) { \Logger::warn($e); } $connectionId = $db->fetchOne("SELECT CONNECTION_ID()"); // enable the db-profiler if the devmode is on and there is no custom profiler set (eg. in system.xml) if (PIMCORE_DEVMODE && !$db->getProfiler()->getEnabled() || array_key_exists("pimcore_log", $_REQUEST) && \Pimcore::inDebugMode()) { $profiler = new \Pimcore\Db\Profiler('All DB Queries'); $profiler->setEnabled(true); $profiler->setConnectionId($connectionId); $db->setProfiler($profiler); } \Logger::debug(get_class($db) . ": Successfully established connection to MySQL-Server, Process-ID: " . $connectionId); return $db; }
/** * @throws \Zend_Controller_Router_Exception */ public function init() { // this is only executed once per request (first request) if (self::$isInitial) { \Pimcore::getEventManager()->trigger("frontend.controller.preInit", $this); } parent::init(); // log exceptions if handled by error_handler $this->checkForErrors(); // general definitions if (self::$isInitial) { \Pimcore::unsetAdminMode(); Document::setHideUnpublished(true); Object\AbstractObject::setHideUnpublished(true); Object\AbstractObject::setGetInheritedValues(true); Object\Localizedfield::setGetFallbackValues(true); } // assign variables $this->view->controller = $this; // init website config $config = Config::getWebsiteConfig(); $this->config = $config; $this->view->config = $config; $document = $this->getParam("document"); if (!$document instanceof Document) { \Zend_Registry::set("pimcore_editmode", false); $this->editmode = false; $this->view->editmode = false; self::$isInitial = false; // check for a locale first, and set it if available if ($this->getParam("pimcore_parentDocument")) { // this is a special exception for renderlets in editmode (ajax request), because they depend on the locale of the parent document // otherwise there'll be notices like: Notice: 'No translation for the language 'XX' available.' if ($parentDocument = Document::getById($this->getParam("pimcore_parentDocument"))) { if ($parentDocument->getProperty("language")) { $this->setLocaleFromDocument($parentDocument->getProperty("language")); } } } // no document available, continue, ... return; } else { $this->setDocument($document); // register global locale if the document has the system property "language" if ($this->getDocument()->getProperty("language")) { $this->setLocaleFromDocument($this->getDocument()->getProperty("language")); } if (self::$isInitial) { // append meta-data to the headMeta() view helper, if it is a document-request if (!Model\Staticroute::getCurrentRoute() && $this->getDocument() instanceof Document\Page) { if (is_array($this->getDocument()->getMetaData())) { foreach ($this->getDocument()->getMetaData() as $meta) { // only name if (!empty($meta["idName"]) && !empty($meta["idValue"]) && !empty($meta["contentValue"])) { $method = "append" . ucfirst($meta["idName"]); $this->view->headMeta()->{$method}($meta["idValue"], $meta["contentValue"]); } } } } } } // this is only executed once per request (first request) if (self::$isInitial) { // contains the logged in user if necessary $user = null; // default is to set the editmode to false, is enabled later if necessary \Zend_Registry::set("pimcore_editmode", false); if (Tool::isFrontentRequestByAdmin()) { $this->disableBrowserCache(); // start admin session & get logged in user $user = Authentication::authenticateSession(); } if (\Pimcore::inDebugMode()) { $this->disableBrowserCache(); } if (!$this->document->isPublished()) { if (Tool::isFrontentRequestByAdmin()) { if (!$user) { throw new \Zend_Controller_Router_Exception("access denied for " . $this->document->getFullPath()); } } else { throw new \Zend_Controller_Router_Exception("access denied for " . $this->document->getFullPath()); } } // logged in users only if ($user) { // set the user to registry so that it is available via \Pimcore\Tool\Admin::getCurrentUser(); \Zend_Registry::set("pimcore_admin_user", $user); // document editmode if ($this->getParam("pimcore_editmode")) { \Zend_Registry::set("pimcore_editmode", true); // check if there is the document in the session $docKey = "document_" . $this->getDocument()->getId(); $docSession = Session::getReadOnly("pimcore_documents"); if ($docSession->{$docKey}) { // if there is a document in the session use it $this->setDocument($docSession->{$docKey}); } else { // set the latest available version for editmode if there is no doc in the session $latestVersion = $this->getDocument()->getLatestVersion(); if ($latestVersion) { $latestDoc = $latestVersion->loadData(); if ($latestDoc instanceof Document\PageSnippet) { $this->setDocument($latestDoc); } } } // register editmode plugin $front = \Zend_Controller_Front::getInstance(); $front->registerPlugin(new \Pimcore\Controller\Plugin\Frontend\Editmode($this), 1000); } // document preview if ($this->getParam("pimcore_preview")) { // get document from session $docKey = "document_" . $this->getParam("document")->getId(); $docSession = Session::getReadOnly("pimcore_documents"); if ($docSession->{$docKey}) { $this->setDocument($docSession->{$docKey}); } } // object preview if ($this->getParam("pimcore_object_preview")) { $key = "object_" . $this->getParam("pimcore_object_preview"); $session = Session::getReadOnly("pimcore_objects"); if ($session->{$key}) { $object = $session->{$key}; // add the object to the registry so every call to Object::getById() will return this object instead of the real one \Zend_Registry::set("object_" . $object->getId(), $object); } } // for version preview if ($this->getParam("pimcore_version")) { // only get version data at the first call || because of embedded Snippets ... if (!\Zend_Registry::isRegistered("pimcore_version_active")) { $version = Model\Version::getById($this->getParam("pimcore_version")); $this->setDocument($version->getData()); \Zend_Registry::set("pimcore_version_active", true); } } } // for public versions if ($this->getParam("v")) { try { $version = Model\Version::getById($this->getParam("v")); if ($version->getPublic()) { $this->setDocument($version->getData()); } } catch (\Exception $e) { } } // check for persona if ($this->getDocument() instanceof Document\Page) { $this->getDocument()->setUsePersona(null); // reset because of preview and editmode (saved in session) if ($this->getParam("_ptp") && self::$isInitial) { $this->getDocument()->setUsePersona($this->getParam("_ptp")); } } // check if document is a wrapped hardlink, if this is the case send a rel=canonical header to the source document if ($this->getDocument() instanceof Document\Hardlink\Wrapper\WrapperInterface) { // get the cononical (source) document $hardlinkCanonicalSourceDocument = Document::getById($this->getDocument()->getId()); $request = $this->getRequest(); if (\Pimcore\Tool\Frontend::isDocumentInCurrentSite($hardlinkCanonicalSourceDocument)) { $this->getResponse()->setHeader("Link", '<' . $request->getScheme() . "://" . $request->getHttpHost() . $hardlinkCanonicalSourceDocument->getFullPath() . '>; rel="canonical"'); } } \Pimcore::getEventManager()->trigger("frontend.controller.postInit", $this); } // set some parameters $this->editmode = \Zend_Registry::get("pimcore_editmode"); $this->view->editmode = \Zend_Registry::get("pimcore_editmode"); self::$isInitial = false; }
/** * @param \Zend_Controller_Request_Abstract $request * @return bool|void */ public function routeStartup(\Zend_Controller_Request_Abstract $request) { $requestUri = $request->getRequestUri(); $excludePatterns = array(); // only enable GET method if (!$request->isGet()) { return $this->disable(); } // disable the output-cache if browser wants the most recent version // unfortunately only Chrome + Firefox if not using SSL if (!$request->isSecure()) { if (isset($_SERVER["HTTP_CACHE_CONTROL"]) && $_SERVER["HTTP_CACHE_CONTROL"] == "no-cache") { return $this->disable("HTTP Header Cache-Control: no-cache was sent"); } if (isset($_SERVER["HTTP_PRAGMA"]) && $_SERVER["HTTP_PRAGMA"] == "no-cache") { return $this->disable("HTTP Header Pragma: no-cache was sent"); } } try { $conf = \Pimcore\Config::getSystemConfig(); if ($conf->cache) { $conf = $conf->cache; if (!$conf->enabled) { return $this->disable(); } if (\Pimcore::inDebugMode()) { return $this->disable("in debug mode"); } if ($conf->lifetime) { $this->setLifetime((int) $conf->lifetime); } if ($conf->excludePatterns) { $confExcludePatterns = explode(",", $conf->excludePatterns); if (!empty($confExcludePatterns)) { $excludePatterns = $confExcludePatterns; } } if ($conf->excludeCookie) { $cookies = explode(",", strval($conf->excludeCookie)); foreach ($cookies as $cookie) { if (!empty($cookie) && isset($_COOKIE[trim($cookie)])) { return $this->disable("exclude cookie in system-settings matches"); } } } // output-cache is always disabled when logged in at the admin ui if (isset($_COOKIE["pimcore_admin_sid"])) { return $this->disable("backend user is logged in"); } } else { return $this->disable(); } } catch (\Exception $e) { \Logger::error($e); return $this->disable("ERROR: Exception (see debug.log)"); } foreach ($excludePatterns as $pattern) { if (@preg_match($pattern, $requestUri)) { return $this->disable("exclude path pattern in system-settings matches"); } } $deviceDetector = Tool\DeviceDetector::getInstance(); $device = $deviceDetector->getDevice(); $deviceDetector->setWasUsed(false); $this->defaultCacheKey = "output_" . md5($request->getHttpHost() . $requestUri); $cacheKeys = [$this->defaultCacheKey . "_" . $device, $this->defaultCacheKey]; $cacheItem = null; foreach ($cacheKeys as $cacheKey) { $cacheItem = CacheManager::load($cacheKey, true); if ($cacheItem) { break; } } if (is_array($cacheItem) && !empty($cacheItem)) { header("X-Pimcore-Output-Cache-Tag: " . $cacheKey, true, 200); header("X-Pimcore-Output-Cache-Date: " . $cacheItem["date"]); foreach ($cacheItem["rawHeaders"] as $header) { header($header); } foreach ($cacheItem["headers"] as $header) { header($header['name'] . ': ' . $header['value'], $header['replace']); } echo $cacheItem["content"]; exit; } else { // set headers to tell the client to not cache the contents // this can/will be overwritten in $this->dispatchLoopShutdown() if the cache is enabled $date = new \Zend_Date(1); $this->getResponse()->setHeader("Expires", $date->get(\Zend_Date::RFC_1123), true); $this->getResponse()->setHeader("Cache-Control", "max-age=0, no-cache", true); } }
/** * @see Document\Tag\TagInterface::frontend * @return string */ public function frontend() { if ($this->getView() instanceof \Zend_View) { try { if ($this->snippet instanceof Document\Snippet) { $params = $this->options; $params["document"] = $this->snippet; if ($this->snippet->isPublished()) { // check if output-cache is enabled, if so, we're also using the cache here $cacheKey = null; if ($cacheConfig = \Pimcore\Tool\Frontend::isOutputCacheEnabled()) { // cleanup params to avoid serializing Element\ElementInterface objects $cacheParams = $params; array_walk($cacheParams, function (&$value, $key) { if ($value instanceof Model\Element\ElementInterface) { $value = $value->getId(); } }); $cacheKey = "tag_snippet__" . md5(serialize($cacheParams)); if ($content = Cache::load($cacheKey)) { return $content; } } $content = $this->getView()->action($this->snippet->getAction(), $this->snippet->getController(), $this->snippet->getModule(), $params); // write contents to the cache, if output-cache is enabled if ($cacheConfig) { Cache::save($content, $cacheKey, ["output", "output_inline"], $cacheConfig["lifetime"]); } return $content; } return ""; } } catch (\Exception $e) { if (\Pimcore::inDebugMode()) { return "ERROR: " . $e->getMessage() . " (for details see debug.log)"; } \Logger::error($e); } } else { return null; } }
/** * @see Document\Tag\TagInterface::frontend * @return string */ public function frontend() { if (!$this->options["controller"] && !$this->options["action"]) { $this->options["controller"] = Config::getSystemConfig()->documents->default_controller; $this->options["action"] = Config::getSystemConfig()->documents->default_action; } $document = null; if ($this->o instanceof Document) { $document = $this->o; } if (method_exists($this->o, "isPublished")) { if (!$this->o->isPublished()) { return ""; } } if ($this->o instanceof Element\ElementInterface) { $blockparams = array("action", "controller", "module", "template"); $params = array("template" => isset($this->options["template"]) ? $this->options["template"] : null, "object" => $this->o, "element" => $this->o, "document" => $document, "id" => $this->id, "type" => $this->type, "subtype" => $this->subtype, "pimcore_request_source" => "renderlet", "disableBlockClearing" => true); foreach ($this->options as $key => $value) { if (!array_key_exists($key, $params) && !in_array($key, $blockparams)) { $params[$key] = $value; } } if ($this->getView() != null) { try { $content = $this->getView()->action($this->options["action"], $this->options["controller"], isset($this->options["module"]) ? $this->options["module"] : null, $params); // we need to add a component id to all first level html containers $componentId = 'document:' . $this->getDocumentId() . '.type:tag-renderlet.name:' . $this->type . "-" . $this->subtype . "-" . $this->id; $content = \Pimcore\Tool\Frontend::addComponentIdToHtml($content, $componentId); return $content; } catch (\Exception $e) { if (\Pimcore::inDebugMode()) { return "ERROR: " . $e->getMessage() . " (for details see debug.log)"; } \Logger::error($e); } } } }
?> ", maintenance_active: <?php echo $this->maintenance_enabled; ?> , maintenance_mode: <?php echo \Pimcore\Tool\Admin::isInMaintenanceMode() ? "true" : "false"; ?> , mail: <?php echo $this->mail_settings_complete; ?> , debug: <?php echo \Pimcore::inDebugMode() ? "true" : "false"; ?> , devmode: <?php echo PIMCORE_DEVMODE ? "true" : "false"; ?> , google_analytics_enabled: <?php echo \Zend_Json::encode((bool) \Pimcore\Google\Analytics::isConfigured()); ?> , google_webmastertools_enabled: <?php echo \Zend_Json::encode((bool) \Pimcore\Google\Webmastertools::isConfigured()); ?> , customviews: <?php
/** * Checks if Output Cache is enabled in Pimcore. * * @return bool */ protected function isEnabled() { if ($this->config->cache) { $this->config = $this->config->cache; if (!$this->config->enabled) { return false; } if (\Pimcore::inDebugMode()) { return false; } } return true; }
<?php $image = $this->image($this->name, array("thumbnail" => "contentImage", "class" => "img-responsive")); if ($this->editmode) { echo $image; } else { if (Pimcore::inDebugMode()) { if ($image && $image->getImage() instanceof Asset_Image) { ?> <img data-width="<?php echo $image->getImage()->getWidth(); ?> " data-height="<?php echo $image->getImage()->getHeight(); ?> " data-text="<?php echo $image->getImage()->getAlt(); ?> "/> <?php } else { ?> <img src="debug"/> <?php } } else { echo $image; } }
/** * direct output to the frontend * * @return string */ public function __toString() { $return = ""; try { if ($this->editmode) { $return = $this->admin(); } else { $return = $this->frontend(); } } catch (\Exception $e) { if (\Pimcore::inDebugMode()) { // the __toString method isn't allowed to throw exceptions $return = '<b style="color:#f00">' . $e->getMessage() . '</b><br/>' . $e->getTraceAsString(); } \Logger::error("to string not possible - " . $e->getMessage()); } if (is_string($return) || is_numeric($return)) { // we have to cast to string, because int/float is not auto-converted and throws an exception return (string) $return; } return ''; }
/** * Checks if the debug mode is enabled in "Settings" -> "System" -> "Debug" * If the debug mode is enabled, all emails will be sent to the debug email addresses given the system settings * and the debug information is appended * * @return void */ protected function checkDebugMode() { if (Pimcore::inDebugMode()) { if (empty(self::$debugEmailAddresses)) { throw new Exception('No valid debug email address given in "Settings" -> "System" -> "Email Settings"'); } if ($this->preventDebugInformationAppending != true) { //adding the debug information to the html email $html = $this->getBodyHtml(); if ($html instanceof Zend_Mime_Part) { $rawHtml = $html->getRawContent(); $debugInformation = Pimcore_Helper_Mail::getDebugInformation('html', $this); $debugInformationStyling = Pimcore_Helper_Mail::getDebugInformationCssStyle(); $rawHtml = preg_replace("!(</\\s*body\\s*>)!is", "{$debugInformation}\\1", $rawHtml); $rawHtml = preg_replace("!(<\\s*head\\s*>)!is", "\\1{$debugInformationStyling}", $rawHtml); $this->setBodyHtml($rawHtml); } $text = $this->getBodyText(); if ($text instanceof Zend_Mime_Part) { $rawText = $text->getRawContent(); $debugInformation = Pimcore_Helper_Mail::getDebugInformation('text', $this); $rawText .= $debugInformation; $this->setBodyText($rawText); } //setting debug subject $subject = $this->getSubject(); $this->clearSubject(); $this->setSubject('Debug email: ' . $subject); } $this->clearRecipients(); $this->addTo(self::$debugEmailAddresses); } }
/** * @see Document\Tag\TagInterface::frontend * @return string */ public function frontend() { if (!$this->options["controller"] && !$this->options["action"]) { $this->options["controller"] = Config::getSystemConfig()->documents->default_controller; $this->options["action"] = Config::getSystemConfig()->documents->default_action; } $document = null; if ($this->o instanceof Document) { $document = $this->o; } if (method_exists($this->o, "isPublished")) { if (!$this->o->isPublished()) { return ""; } } if ($this->o instanceof Element\ElementInterface) { $blockparams = ["action", "controller", "module", "template"]; $params = ["template" => isset($this->options["template"]) ? $this->options["template"] : null, "object" => $this->o, "element" => $this->o, "document" => $document, "id" => $this->id, "type" => $this->type, "subtype" => $this->subtype, "pimcore_request_source" => "renderlet", "disableBlockClearing" => true]; foreach ($this->options as $key => $value) { if (!array_key_exists($key, $params) && !in_array($key, $blockparams)) { $params[$key] = $value; } } if ($this->getView() != null) { try { $content = $this->getView()->action($this->options["action"], $this->options["controller"], isset($this->options["module"]) ? $this->options["module"] : null, $params); return $content; } catch (\Exception $e) { if (\Pimcore::inDebugMode()) { return "ERROR: " . $e->getMessage() . " (for details see debug.log)"; } Logger::error($e); } } } }
/** * @throws \Doctrine\ORM\ORMException */ protected function _loadOnce() { if (!\Zend_Registry::isRegistered('doctrine.em')) { $isDevMode = \Pimcore::inDebugMode(); $pluginConfig = $this->_loadConfiguration(); $doctrineConfig = $pluginConfig['doctrine']; //Connection Settings if (!empty($doctrineConfig['connection'])) { $dbParams = $doctrineConfig['connection']['orm_default']; } else { $config = Config::getSystemConfig()->toArray(); $params = $config['database']['params']; // the connection configuration $dbParams = ['driver' => strtolower($config['database']['adapter']), 'user' => $params['username'], 'password' => $params['password'], 'dbname' => $params['dbname']]; } //Table Prefix $evm = new EventManager(); if (!empty($doctrineConfig['table_prefix'])) { $tablePrefix = new TablePrefix($doctrineConfig['table_prefix']); $evm->addEventListener(Events::loadClassMetadata, $tablePrefix); } //Entity Paths $paths = ['website/models/Website/Entity/']; if (is_array($doctrineConfig['paths'])) { $paths = $doctrineConfig['paths']; } $setup = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, null, null, false); $em = EntityManager::create($dbParams, $setup, $evm); $em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); \Zend_Registry::set('doctrine.em', $em); } }
/** * @return string * @throws \Zend_Exception */ public function getHtmlData() { if (empty($this->scriptQueue)) { return FALSE; } $scriptQueue = $this->scriptQueue; if (empty($scriptQueue)) { return FALSE; } $htmlData = array('header' => '', 'footer' => ''); $appendData = array(); foreach ($scriptQueue as $scriptPosition => $scripts) { if (empty($scripts)) { continue; } $assetDependencyWatcher = new AssetDependency(); //for every script name foreach ($scripts as $scriptName => &$details) { $p = $details['params']; if ($p['showInFrontEnd'] === FALSE && $this->isFrontEnd || $p['showInBackend'] === FALSE && $this->isBackEnd) { continue; } $deps = array(); foreach ($details['dependencies'] as $depFile) { $deps[] = $depFile . '-' . $details['fileType']; } unset($details['dependencies']); $assetDependencyWatcher->add($scriptName, $details, $deps); } foreach ($assetDependencyWatcher->sort() as $dependency) { $appendData[$scriptPosition][] = $dependency; } } foreach ($appendData as $scriptPosition => $scripts) { if (!\Pimcore::inDebugMode() && $this->isFrontEnd) { $htmlData[$scriptPosition] = $this->getCompressedHtml($scripts, $scriptPosition); } else { $htmlData[$scriptPosition] = $this->getUncompressedHtml($scripts); } } return $htmlData; }
/** * direct output to the frontend * * @return string */ public function __toString() { try { if ($this->editmode) { $return = $this->admin(); } else { $return = $this->frontend(); } } catch (\Exception $e) { if (\Pimcore::inDebugMode()) { // the __toString method isn't allowed to throw exceptions $return = '<b style="color:#f00">' . $e->getMessage() . '</b><br/>' . $e->getTraceAsString(); } \Logger::error("to string not possible - " . $e->getMessage()); } if (is_string($return)) { return $return; } return ''; }
public function getErrorCode($message = "") { $width = $this->getWidth(); if (strpos($this->getWidth(), "%") === false) { $width = $this->getWidth() - 1 . "px"; } // only display error message in debug mode if (!\Pimcore::inDebugMode()) { $message = ""; } $code = ' <div id="pimcore_pdf_' . $this->getName() . '" class="pimcore_tag_pdf"> <div class="pimcore_tag_video_error" style="text-align:center; width: ' . $width . '; height: ' . ($this->getHeight() - 1) . 'px; border:1px solid #000; background: url(/pimcore/static/img/filetype-not-supported.png) no-repeat center center #fff;"> ' . $message . ' </div> </div>'; return $code; }
/** * adds a PDF page to lucene index and mysql table for search result sumaries * @param string $url * @param string $language * @param string $host * @return bool */ protected function addPdfToIndex($url, $language, $host) { $pdftotextBin = FALSE; try { $pdftotextBin = \Pimcore\Document\Adapter\Ghostscript::getPdftotextCli(); } catch (\Exception $e) { $pdftotextBin = FALSE; } if ($pdftotextBin === FALSE) { return FALSE; } $textFileTmp = uniqid('t2p-'); $tmpFile = PIMCORE_TEMPORARY_DIRECTORY . '/' . $textFileTmp . '.txt'; $tmpPdfFile = PIMCORE_TEMPORARY_DIRECTORY . '/' . $textFileTmp . '.pdf'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $data = curl_exec($ch); $result = file_put_contents($tmpPdfFile, $data); curl_close($ch); $verboseCommand = \Pimcore::inDebugMode() ? '' : '-q '; try { $cmnd = $verboseCommand . $tmpPdfFile . ' ' . $tmpFile; exec($pdftotextBin . ' ' . $cmnd); } catch (\Exception $e) { \Pimcore\Logger::debug($e->getMessage()); } if (is_file($tmpFile)) { $fileContent = file_get_contents($tmpFile); try { $doc = new \Zend_Search_Lucene_Document(); $text = preg_replace("/\r|\n/", ' ', $fileContent); $text = preg_replace('/[^\\p{Latin}\\d ]/u', "", $text); $text = preg_replace('/\\n[\\s]*/', "\n", $text); // remove all leading blanks] $doc->addField(\Zend_Search_Lucene_Field::Text('title', basename($url)), 'utf-8'); $doc->addField(\Zend_Search_Lucene_Field::Text('content', $text, 'utf-8')); $doc->addField(\Zend_Search_Lucene_Field::Keyword('url', $url)); $doc->addField(\Zend_Search_Lucene_Field::Keyword('host', $host)); $doc->addField(\Zend_Search_Lucene_Field::Keyword('restrictionGroup_default', TRUE)); $doc->addField(\Zend_Search_Lucene_Field::Keyword('lang', $language)); //no add document to lucene index! $this->addDocumentToIndex($doc); } catch (\Exception $e) { \Pimcore\Logger::debug($e->getMessage()); } @unlink($tmpFile); @unlink($tmpPdfFile); } return TRUE; }