getSystemConfig() public static method

public static getSystemConfig ( boolean $forceReload = false ) : mixed | null | Zend_Config
$forceReload boolean
return mixed | null | Zend_Config
Example #1
0
 public function addLanguage($languageToAdd)
 {
     // Check if language is not already added
     if (in_array($languageToAdd, Tool::getValidLanguages())) {
         $result = false;
     } else {
         // Read all the documents from the first language
         $availableLanguages = Tool::getValidLanguages();
         $firstLanguageDocument = \Pimcore\Model\Document::getByPath('/' . reset($availableLanguages));
         \Zend_Registry::set('SEI18N_add', 1);
         // Add the language main folder
         $document = Page::create(1, array('key' => $languageToAdd, "userOwner" => 1, "userModification" => 1, "published" => true, "controller" => 'default', "action" => 'go-to-first-child'));
         $document->setProperty('language', 'text', $languageToAdd);
         // Set the language to this folder and let it inherit to the child pages
         $document->setProperty('isLanguageRoot', 'text', 1, false, false);
         // Set as language root document
         $document->save();
         // Add Link to other languages
         $t = new Keys();
         $t->insert(array("document_id" => $document->getId(), "language" => $languageToAdd, "sourcePath" => $firstLanguageDocument->getFullPath()));
         // Lets add all the docs
         $this->addDocuments($firstLanguageDocument->getId(), $languageToAdd);
         \Zend_Registry::set('SEI18N_add', 0);
         $oldConfig = Config::getSystemConfig();
         $settings = $oldConfig->toArray();
         $languages = explode(',', $settings['general']['validLanguages']);
         $languages[] = $languageToAdd;
         $settings['general']['validLanguages'] = implode(',', $languages);
         $config = new \Zend_Config($settings, true);
         $writer = new \Zend_Config_Writer_Xml(array("config" => $config, "filename" => PIMCORE_CONFIGURATION_SYSTEM));
         $writer->write();
         $result = true;
     }
     return $result;
 }
Example #2
0
 /**
  * @throws \Exception
  */
 public function init()
 {
     $conf = Config::getSystemConfig();
     if (!$conf->webservice->enabled) {
         throw new \Exception("Webservice API isn't enabled");
     }
     if (!$this->getParam("apikey") && $_COOKIE["pimcore_admin_sid"]) {
         $user = Authentication::authenticateSession();
         if (!$user instanceof User) {
             throw new \Exception("User is not valid");
         }
     } else {
         if (!$this->getParam("apikey")) {
             throw new \Exception("API key missing");
         } else {
             $apikey = $this->getParam("apikey");
             $userList = new User\Listing();
             $userList->setCondition("apiKey = ? AND type = ? AND active = 1", array($apikey, "user"));
             $users = $userList->load();
             if (!is_array($users) or count($users) !== 1) {
                 throw new \Exception("API key error.");
             }
             if (!$users[0]->getApiKey()) {
                 throw new \Exception("Couldn't get API key for user.");
             }
             $user = $users[0];
         }
     }
     \Zend_Registry::set("pimcore_admin_user", $user);
     parent::init();
 }
 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));
     });
 }
Example #4
0
 /**
  * @param \Zend_Controller_Request_Abstract $request
  * @throws mixed
  */
 protected function _handleError(\Zend_Controller_Request_Abstract $request)
 {
     // remove zend error handler
     $front = \Zend_Controller_Front::getInstance();
     $front->unregisterPlugin("Zend_Controller_Plugin_ErrorHandler");
     $response = $this->getResponse();
     if ($response->isException() && !$this->_isInsideErrorHandlerLoop) {
         // get errorpage
         try {
             // enable error handler
             $front->setParam('noErrorHandler', false);
             $errorPath = Config::getSystemConfig()->documents->error_pages->default;
             if (Site::isSiteRequest()) {
                 $site = Site::getCurrentSite();
                 $errorPath = $site->getErrorDocument();
             }
             if (empty($errorPath)) {
                 $errorPath = "/";
             }
             $document = Document::getByPath($errorPath);
             if (!$document instanceof Document\Page) {
                 // default is home
                 $document = Document::getById(1);
             }
             if ($document instanceof Document\Page) {
                 $params = Tool::getRoutingDefaults();
                 if ($module = $document->getModule()) {
                     $params["module"] = $module;
                 }
                 if ($controller = $document->getController()) {
                     $params["controller"] = $controller;
                     $params["action"] = "index";
                 }
                 if ($action = $document->getAction()) {
                     $params["action"] = $action;
                 }
                 $this->setErrorHandler($params);
                 $request->setParam("document", $document);
                 \Zend_Registry::set("pimcore_error_document", $document);
                 // ensure that a viewRenderer exists, and is enabled
                 if (!\Zend_Controller_Action_HelperBroker::hasHelper("viewRenderer")) {
                     $viewRenderer = new \Pimcore\Controller\Action\Helper\ViewRenderer();
                     \Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
                 }
                 $viewRenderer = \Zend_Controller_Action_HelperBroker::getExistingHelper("viewRenderer");
                 $viewRenderer->setNoRender(false);
                 if ($viewRenderer->view === null) {
                     $viewRenderer->initView(PIMCORE_WEBSITE_PATH . "/views");
                 }
             }
         } catch (\Exception $e) {
             \Logger::emergency("error page not found");
         }
     }
     // call default ZF error handler
     parent::_handleError($request);
 }
Example #5
0
 public function setSystemInstanceIdentifier()
 {
     $instanceIdentifier = \Pimcore\Config::getSystemConfig()->general->instanceIdentifier;
     if (!$instanceIdentifier) {
         throw new \Exception("No instance identifier set in system config!");
     }
     $this->setInstanceIdentifier($instanceIdentifier);
     return $this;
 }
Example #6
0
    /**
     *
     */
    public function dispatchLoopShutdown()
    {
        $config = \Pimcore\Config::getSystemConfig();
        if (!$config->general->show_cookie_notice || !Tool::useFrontendOutputFilters($this->getRequest()) || !Tool::isHtmlResponse($this->getResponse())) {
            return;
        }
        $template = file_get_contents(__DIR__ . "/EuCookieLawNotice/template.html");
        # cleanup code
        $template = preg_replace('/[\\r\\n\\t]+/', ' ', $template);
        #remove new lines, spaces, tabs
        $template = preg_replace('/>[\\s]+</', '><', $template);
        #remove new lines, spaces, tabs
        $template = preg_replace('/[\\s]+/', ' ', $template);
        #remove new lines, spaces, tabs
        $translations = $this->getTranslations();
        foreach ($translations as $key => &$value) {
            $value = htmlentities($value, ENT_COMPAT, "UTF-8");
            $template = str_replace("%" . $key . "%", $value, $template);
        }
        $linkContent = "";
        if (array_key_exists("linkTarget", $translations)) {
            $linkContent = '<a href="' . $translations["linkTarget"] . '" data-content="' . $translations["linkText"] . '"></a>';
        }
        $template = str_replace("%link%", $linkContent, $template);
        $templateCode = \Zend_Json::encode($template);
        $code = '
            <script>
                (function () {
                    var ls = window["localStorage"];
                    if(ls && !ls.getItem("pc-cookie-accepted")) {

                        var code = ' . $templateCode . ';
                        var ci = window.setInterval(function () {
                            if(document.body) {
                                clearInterval(ci);
                                document.body.insertAdjacentHTML("beforeend", code);

                                document.getElementById("pc-button").onclick = function () {
                                    document.getElementById("pc-cookie-notice").style.display = "none";
                                    ls.setItem("pc-cookie-accepted", "true");
                                };
                            }
                        }, 100);
                    }
                })();
            </script>
        ';
        $body = $this->getResponse()->getBody();
        // search for the end <head> tag, and insert the google analytics code before
        // this method is much faster than using simple_html_dom and uses less memory
        $headEndPosition = stripos($body, "</head>");
        if ($headEndPosition !== false) {
            $body = substr_replace($body, $code . "</head>", $headEndPosition, 7);
        }
        $this->getResponse()->setBody($body);
    }
Example #7
0
 /**
  * @param $name
  * @param bool $throwException
  * @return bool|mixed|string
  * @throws \Exception
  */
 public static function getExecutable($name, $throwException = false)
 {
     if (isset(self::$executableCache[$name])) {
         return self::$executableCache[$name];
     }
     $pathVariable = Config::getSystemConfig()->general->path_variable;
     $paths = [];
     if ($pathVariable) {
         $paths = explode(":", $pathVariable);
     }
     array_unshift($paths, "");
     // allow custom setup routines for certain programs
     $customSetupMethod = "setup" . ucfirst($name);
     if (method_exists(__CLASS__, $customSetupMethod)) {
         self::$customSetupMethod();
     }
     // allow custom check routines for certain programs
     $customCheckMethod = "check" . ucfirst($name);
     if (!method_exists(__CLASS__, $customCheckMethod)) {
         $customCheckMethod = "checkDummy";
     }
     foreach ($paths as $path) {
         foreach (["--help", "-h", "-help"] as $option) {
             try {
                 $path = rtrim($path, "/\\ ");
                 if ($path) {
                     $executablePath = $path . DIRECTORY_SEPARATOR . $name;
                 } else {
                     $executablePath = $name;
                 }
                 $process = new Process($executablePath . " " . $option);
                 $process->run();
                 if ($process->isSuccessful() || self::$customCheckMethod($process)) {
                     if (empty($path) && self::getSystemEnvironment() == "unix") {
                         // get the full qualified path, seems to solve a lot of problems :)
                         // if not using the full path, timeout, nohup and nice will fail
                         $fullQualifiedPath = shell_exec("which " . $executablePath);
                         $fullQualifiedPath = trim($fullQualifiedPath);
                         if ($fullQualifiedPath) {
                             $executablePath = $fullQualifiedPath;
                         }
                     }
                     self::$executableCache[$name] = $executablePath;
                     return $executablePath;
                 }
             } catch (\Exception $e) {
             }
         }
     }
     self::$executableCache[$name] = false;
     if ($throwException) {
         throw new \Exception("No '{$name}' executable found, please install the application or add it to the PATH (in system settings or to your PATH environment variable");
     }
     return false;
 }
Example #8
0
 public function adminerAction()
 {
     $conf = \Pimcore\Config::getSystemConfig()->database->params;
     if (empty($_SERVER["QUERY_STRING"])) {
         $this->redirect("/admin/external_adminer/adminer/?username="******"&db=" . $conf->dbname);
         exit;
     }
     chdir($this->adminerHome . "adminer");
     include $this->adminerHome . "adminer/index.php";
     $this->removeViewRenderer();
 }
 private function getErrorDocument()
 {
     $config = Config::getSystemConfig();
     $errorDocPath = $config->documents->error_pages->default;
     if (Site::isSiteRequest()) {
         $site = Site::getCurrentSite();
         $errorDocPath = $site->getErrorDocument();
     }
     $errorDoc = Document::getByPath($errorDocPath);
     \Zend_Registry::set("pimcore_error_document", $errorDoc);
     return $errorDoc;
 }
Example #10
0
 /**
  * @param \Zend_Controller_Request_Abstract $request
  * @return bool|void
  */
 public function routeStartup(\Zend_Controller_Request_Abstract $request)
 {
     $this->conf = \Pimcore\Config::getSystemConfig();
     if ($request->getParam('disable_less_compiler') || $_COOKIE["disable_less_compiler"]) {
         return $this->disable();
     }
     if (!$this->conf->outputfilters) {
         return $this->disable();
     }
     if (!$this->conf->outputfilters->less) {
         return $this->disable();
     }
 }
Example #11
0
 /**
  * @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;
 }
Example #12
0
 public static function getInstance()
 {
     if (!self::$instance) {
         if (\Pimcore\Tool::classExists("\\Elements\\Logging\\Log")) {
             $logger = new \Elements\Logging\Log();
             $logger->addWriter(new \Elements\Logging\Writer\LogWriterDb(\Zend_Log::DEBUG));
             $logger->addWriter(new \Zend_Log_Writer_Stream(PIMCORE_WEBSITE_PATH . "/var/log/trustedshop.log"));
             $systemConfig = \Pimcore\Config::getSystemConfig();
             $debugAddresses = explode(',', $systemConfig->email->debug->emailaddresses);
             $logger->addWriter(new \Elements\Logging\Writer\LogWriterMail($debugAddresses, "TrustedShop-Importer", "", \Zend_Log::ERR));
             self::$instance = $logger;
         }
     }
     return self::$instance;
 }
Example #13
0
 /**
  * @param $id
  * @param bool $create
  * @param bool $returnIdIfEmpty
  * @param null $language
  * @return array
  * @throws \Exception
  * @throws \Zend_Exception
  */
 public static function getByKeyLocalized($id, $create = false, $returnIdIfEmpty = false, $language = null)
 {
     if ($user = Tool\Admin::getCurrentUser()) {
         $language = $user->getLanguage();
     } elseif ($user = Tool\Authentication::authenticateSession()) {
         $language = $user->getLanguage();
     } elseif (\Zend_Registry::isRegistered("Zend_Locale")) {
         $language = (string) \Zend_Registry::get("Zend_Locale");
     }
     if (!in_array($language, Tool\Admin::getLanguages())) {
         $config = \Pimcore\Config::getSystemConfig();
         $language = $config->general->language;
     }
     return self::getByKey($id, $create, $returnIdIfEmpty)->getTranslation($language);
 }
Example #14
0
 /**
  *
  */
 protected function update()
 {
     $oldPath = $this->getDao()->getCurrentFullPath();
     parent::update();
     $config = \Pimcore\Config::getSystemConfig();
     if ($oldPath && $config->documents->createredirectwhenmoved && $oldPath != $this->getFullPath()) {
         // create redirect for old path
         $redirect = new Redirect();
         $redirect->setTarget($this->getId());
         $redirect->setSource("@" . $oldPath . "/?@");
         $redirect->setStatusCode(301);
         $redirect->setExpiry(time() + 86400 * 60);
         // this entry is removed automatically after 60 days
         $redirect->save();
     }
 }
Example #15
0
 /**
  * @return bool
  */
 public static function getWkhtmltoimageBinary()
 {
     if (Config::getSystemConfig()->documents->wkhtmltoimage) {
         if (@is_executable(Config::getSystemConfig()->documents->wkhtmltoimage)) {
             return (string) Config::getSystemConfig()->documents->wkhtmltoimage;
         } else {
             \Logger::critical("wkhtmltoimage binary: " . Config::getSystemConfig()->documents->wkhtmltoimage . " is not executable");
         }
     }
     $paths = array("/usr/bin/wkhtmltoimage-amd64", "/usr/local/bin/wkhtmltoimage-amd64", "/bin/wkhtmltoimage-amd64", "/usr/bin/wkhtmltoimage", "/usr/local/bin/wkhtmltoimage", "/bin/wkhtmltoimage", realpath(PIMCORE_DOCUMENT_ROOT . "/../wkhtmltox/wkhtmltoimage.exe"));
     foreach ($paths as $path) {
         if (@is_executable($path)) {
             return $path;
         }
     }
     return false;
 }
 /**
  * @return mixed
  * @throws \Exception
  */
 public static function getPhpCli()
 {
     if (Config::getSystemConfig()->general->php_cli) {
         if (@is_executable(Config::getSystemConfig()->general->php_cli)) {
             return (string) Config::getSystemConfig()->general->php_cli;
         } else {
             \Logger::critical("PHP-CLI binary: " . Config::getSystemConfig()->general->php_cli . " is not executable");
         }
     }
     $paths = array("/usr/bin/php", "/usr/local/bin/php", "/usr/local/zend/bin/php", "/bin/php", realpath(PIMCORE_DOCUMENT_ROOT . "/../php/php.exe"));
     foreach ($paths as $path) {
         if (@is_executable($path)) {
             return $path;
         }
     }
     throw new \Exception("No php executable found, please configure the correct path in the system settings");
 }
Example #17
0
 /**
  * @return mixed
  * @throws \Exception
  */
 public static function getFfmpegCli()
 {
     $ffmpegPath = \Pimcore\Config::getSystemConfig()->assets->ffmpeg;
     if ($ffmpegPath) {
         if (@is_executable($ffmpegPath)) {
             return $ffmpegPath;
         } else {
             \Logger::critical("FFMPEG binary: " . $ffmpegPath . " is not executable");
         }
     }
     $paths = array("/usr/local/bin/ffmpeg", "/usr/bin/ffmpeg", "/bin/ffmpeg", realpath(PIMCORE_DOCUMENT_ROOT . "/../ffmpeg/bin/ffmpeg.exe"));
     foreach ($paths as $path) {
         if (@is_executable($path)) {
             return $path;
         }
     }
     throw new \Exception("No ffmpeg executable found, please configure the correct path in the system settings");
 }
Example #18
0
 /**
  * @return mixed
  * @throws \Exception
  */
 public static function getLibreOfficeCli()
 {
     $loPath = Config::getSystemConfig()->assets->libreoffice;
     if ($loPath) {
         if (@is_executable($loPath)) {
             return $loPath;
         } else {
             \Logger::critical("LibreOffice binary: " . $loPath . " is not executable");
         }
     }
     $paths = array("/usr/local/bin/soffice", "/usr/bin/soffice", "/bin/soffice");
     foreach ($paths as $path) {
         if (@is_executable($path)) {
             return $path;
         }
     }
     throw new \Exception("No LibreOffice executable found, please configure the correct path in the system settings");
 }
Example #19
0
 /**
  * @param Model\Tool\Newsletter\Config $newsletter
  * @param Object\Concrete $object
  */
 public static function sendMail($newsletter, $object, $emailAddress = null, $hostUrl = null)
 {
     $params = ["gender" => $object->getGender(), 'firstname' => $object->getFirstname(), 'lastname' => $object->getLastname(), "email" => $object->getEmail(), 'token' => $object->getProperty("token"), "object" => $object];
     $mail = new Mail();
     $mail->setIgnoreDebugMode(true);
     if (\Pimcore\Config::getSystemConfig()->newsletter->usespecific) {
         $mail->init("newsletter");
     }
     if (!Tool::getHostUrl() && $hostUrl) {
         $mail->setHostUrl($hostUrl);
     }
     if ($emailAddress) {
         $mail->addTo($emailAddress);
     } else {
         $mail->addTo($object->getEmail());
     }
     $mail->setDocument(Document::getById($newsletter->getDocument()));
     $mail->setParams($params);
     // render the document and rewrite the links (if analytics is enabled)
     if ($newsletter->getGoogleAnalytics()) {
         if ($content = $mail->getBodyHtmlRendered()) {
             include_once "simple_html_dom.php";
             $html = str_get_html($content);
             if ($html) {
                 $links = $html->find("a");
                 foreach ($links as $link) {
                     if (preg_match("/^(mailto)/", trim(strtolower($link->href)))) {
                         continue;
                     }
                     $glue = "?";
                     if (strpos($link->href, "?")) {
                         $glue = "&";
                     }
                     $link->href = $link->href . $glue . "utm_source=Newsletter&utm_medium=Email&utm_campaign=" . $newsletter->getName();
                 }
                 $content = $html->save();
                 $html->clear();
                 unset($html);
             }
             $mail->setBodyHtml($content);
         }
     }
     $mail->send();
 }
Example #20
0
 /**
  * @return mixed
  * @throws \Exception
  */
 public static function getPdftotextCli()
 {
     // check the system-config for a path
     $configPath = Config::getSystemConfig()->assets->pdftotext;
     if ($configPath) {
         if (@is_executable($configPath)) {
             return $configPath;
         } else {
             \Logger::critical("Binary: " . $configPath . " is not executable");
         }
     }
     $paths = array("/usr/local/bin/pdftotext", "/usr/bin/pdftotext", "/bin/pdftotext");
     foreach ($paths as $path) {
         if (@is_executable($path)) {
             return $path;
         }
     }
     throw new \Exception("No pdftotext executable found, please configure the correct path in the system settings");
 }
Example #21
0
 public function init()
 {
     parent::init();
     $config = Pimcore\Config::getSystemConfig();
     $this->validLanguages = explode(",", $config->general->validLanguages);
     $this->view->headTitle()->setSeparator(" " . "|" . " ");
     if (\Zend_Registry::isRegistered("Zend_Locale")) {
         $locale = \Zend_Registry::get("Zend_Locale");
     } else {
         $locale = new \Zend_Locale();
         if (!in_array($locale->getLanguage(), $this->validLanguages)) {
             $locale = new \Zend_Locale("en_EN");
         }
         \Zend_Registry::set("Zend_Locale", $locale);
     }
     $this->view->language = $locale->getLanguage();
     $this->language = $locale->getLanguage();
     $this->view->addHelperPath(PIMCORE_WEBSITE_PATH . '/lib/Website/Helper/View', 'Website\\Helper\\View');
     $this->addScriptAndCss();
     $this->enableLayout();
 }
Example #22
0
 /**
  * @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);
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function init()
 {
     parent::init();
     $environment = Config::getSystemConfig()->get("general")->get("environment");
     // Set up dependency injection container
     $builder = new ContainerBuilder();
     $builder->useAnnotations(true);
     // Configure the container
     $builder->addDefinitions(PIMCORE_WEBSITE_PATH . "/config/container.php");
     if ($environment !== "local") {
         // Use whatever cache Pimcore has configured (if it has one configured) to cache object
         // definitions in the container
         $builder->setDefinitionCache(new PimcoreCache());
     } else {
         // For development, or debugging we don't want to cache the container
         $builder->setDefinitionCache(new ArrayCache());
     }
     $environmentConfigFile = DefinitionFileLocator::getPath($environment);
     $parametersFile = ParametersFileLocator::getPath();
     if (file_exists($environmentConfigFile)) {
         $builder->addDefinitions($environmentConfigFile);
     }
     if (file_exists($parametersFile)) {
         $builder->addDefinitions($parametersFile);
     }
     $container = $builder->build();
     /** @var \Zend_Controller_Dispatcher_Interface $currentDispatcher */
     $currentDispatcher = \Zend_Controller_Front::getInstance()->getDispatcher();
     $dispatcher = new Dispatcher();
     $dispatcher->setContainer($container);
     $dispatcher->setControllerDirectory($currentDispatcher->getControllerDirectory());
     $dispatcher->setDefaultModule($currentDispatcher->getDefaultModule());
     $dispatcher->setDefaultAction($currentDispatcher->getDefaultAction());
     $dispatcher->setDefaultControllerName($currentDispatcher->getDefaultControllerName());
     \Zend_Controller_Front::getInstance()->setDispatcher($dispatcher);
 }
Example #24
0
 /**
  * @return array
  */
 protected function getTables()
 {
     $db = Db::get();
     if ($mysqlTables = $this->options['mysql-tables']) {
         $specificTables = explode(',', $mysqlTables);
         $databaseName = (string) \Pimcore\Config::getSystemConfig()->database->params->dbname;
         $query = "SHOW FULL TABLES where `Tables_in_" . $databaseName . "` IN(" . implode(',', wrapArrayElements($specificTables)) . ')';
     } else {
         $query = "SHOW FULL TABLES";
     }
     $tables = $db->fetchAll($query);
     return $tables;
 }
Example #25
0
 public function getAction()
 {
     if (intval($this->getParam("id")) < 1) {
         $this->_helper->json(["success" => false]);
     }
     $user = User::getById(intval($this->getParam("id")));
     if ($user->isAdmin() && !$this->getUser()->isAdmin()) {
         throw new \Exception("Only admin users are allowed to modify admin users");
     }
     // workspaces
     $types = ["asset", "document", "object"];
     foreach ($types as $type) {
         $workspaces = $user->{"getWorkspaces" . ucfirst($type)}();
         foreach ($workspaces as $workspace) {
             $el = Element\Service::getElementById($type, $workspace->getCid());
             if ($el) {
                 // direct injection => not nice but in this case ok ;-)
                 $workspace->path = $el->getRealFullPath();
             }
         }
     }
     // object <=> user dependencies
     $userObjects = Object\Service::getObjectsReferencingUser($user->getId());
     $userObjectData = [];
     foreach ($userObjects as $o) {
         $hasHidden = false;
         if ($o->isAllowed("list")) {
             $userObjectData[] = ["path" => $o->getRealFullPath(), "id" => $o->getId(), "subtype" => $o->getClass()->getName()];
         } else {
             $hasHidden = true;
         }
     }
     // get available permissions
     $availableUserPermissionsList = new User\Permission\Definition\Listing();
     $availableUserPermissions = $availableUserPermissionsList->load();
     // get available roles
     $roles = [];
     $list = new User\Role\Listing();
     $list->setCondition("`type` = ?", ["role"]);
     $list->load();
     $roles = [];
     if (is_array($list->getItems())) {
         foreach ($list->getItems() as $role) {
             $roles[] = [$role->getId(), $role->getName()];
         }
     }
     // unset confidential informations
     $userData = object2array($user);
     $contentLanguages = Tool\Admin::reorderWebsiteLanguages($user, Tool::getValidLanguages());
     $userData["contentLanguages"] = $contentLanguages;
     unset($userData["password"]);
     $availablePerspectives = \Pimcore\Config::getAvailablePerspectives(null);
     $conf = \Pimcore\Config::getSystemConfig();
     $this->_helper->json(["success" => true, "wsenabled" => $conf->webservice->enabled, "user" => $userData, "roles" => $roles, "permissions" => $user->generatePermissionList(), "availablePermissions" => $availableUserPermissions, "availablePerspectives" => $availablePerspectives, "objectDependencies" => ["hasHidden" => $hasHidden, "dependencies" => $userObjectData]]);
 }
Example #26
0
 /**
  * @return string
  */
 public static function getRGBColorProfile()
 {
     if (!self::$RGBColorProfile) {
         $path = Config::getSystemConfig()->assets->icc_rgb_profile;
         if (!$path || !file_exists($path)) {
             $path = __DIR__ . "/../icc-profiles/sRGB_IEC61966-2-1_black_scaled.icc";
             // default profile
         }
         if (file_exists($path)) {
             self::$RGBColorProfile = file_get_contents($path);
         }
     }
     return self::$RGBColorProfile;
 }
    /**
     * @param \Zend_Controller_Request_Abstract $request
     */
    public function postDispatch(\Zend_Controller_Request_Abstract $request)
    {
        $conf = Config::getSystemConfig();
        // add scripts to editmode
        if (\Pimcore\Tool\Admin::isExtJS6()) {
            $editmodeLibraries = array("/pimcore/static6/js/pimcore/namespace.js", "/pimcore/static6/js/lib/prototype-light.js", "/pimcore/static6/js/lib/jquery.min.js", "/pimcore/static6/js/lib/ext/ext-all.js", "/pimcore/static6/js/lib/ckeditor/ckeditor.js");
            $editmodeScripts = array("/pimcore/static6/js/pimcore/functions.js", "/pimcore/static6/js/pimcore/element/tag/imagehotspotmarkereditor.js", "/pimcore/static6/js/pimcore/element/tag/imagecropper.js", "/pimcore/static6/js/pimcore/document/edit/helper.js", "/pimcore/static6/js/pimcore/document/edit/dnd.js", "/pimcore/static6/js/pimcore/document/tag.js", "/pimcore/static6/js/pimcore/document/tags/block.js", "/pimcore/static6/js/pimcore/document/tags/date.js", "/pimcore/static6/js/pimcore/document/tags/href.js", "/pimcore/static6/js/pimcore/document/tags/multihref.js", "/pimcore/static6/js/pimcore/document/tags/checkbox.js", "/pimcore/static6/js/pimcore/document/tags/image.js", "/pimcore/static6/js/pimcore/document/tags/input.js", "/pimcore/static6/js/pimcore/document/tags/link.js", "/pimcore/static6/js/pimcore/document/tags/select.js", "/pimcore/static6/js/pimcore/document/tags/snippet.js", "/pimcore/static6/js/pimcore/document/tags/textarea.js", "/pimcore/static6/js/pimcore/document/tags/numeric.js", "/pimcore/static6/js/pimcore/document/tags/wysiwyg.js", "/pimcore/static6/js/pimcore/document/tags/renderlet.js", "/pimcore/static6/js/pimcore/document/tags/table.js", "/pimcore/static6/js/pimcore/document/tags/video.js", "/pimcore/static6/js/pimcore/document/tags/multiselect.js", "/pimcore/static6/js/pimcore/document/tags/areablock.js", "/pimcore/static6/js/pimcore/document/tags/area.js", "/pimcore/static6/js/pimcore/document/tags/pdf.js", "/pimcore/static6/js/pimcore/document/edit/helper.js");
            $editmodeStylesheets = array("/pimcore/static6/css/icons.css", "/pimcore/static6/css/editmode.css?_dc=" . time());
        } else {
            $editmodeLibraries = array("/pimcore/static/js/pimcore/namespace.js", "/pimcore/static/js/lib/prototype-light.js", "/pimcore/static/js/lib/jquery.min.js", "/pimcore/static/js/lib/ext/adapter/jquery/ext-jquery-adapter-debug.js", "/pimcore/static/js/lib/ext/ext-all-debug.js", "/pimcore/static/js/lib/ext-plugins/ux/Spinner.js", "/pimcore/static/js/lib/ext-plugins/ux/SpinnerField.js", "/pimcore/static/js/lib/ext-plugins/ux/MultiSelect.js", "/pimcore/static/js/lib/ext-plugins/GridRowOrder/roworder.js", "/pimcore/static/js/lib/ckeditor/ckeditor.js", "/pimcore/static/js/pimcore/libfixes.js");
            $editmodeScripts = array("/pimcore/static/js/pimcore/functions.js", "/pimcore/static/js/pimcore/element/tag/imagehotspotmarkereditor.js", "/pimcore/static/js/pimcore/element/tag/imagecropper.js", "/pimcore/static/js/pimcore/document/edit/helper.js", "/pimcore/static/js/pimcore/document/edit/dnd.js", "/pimcore/static/js/pimcore/document/tag.js", "/pimcore/static/js/pimcore/document/tags/block.js", "/pimcore/static/js/pimcore/document/tags/date.js", "/pimcore/static/js/pimcore/document/tags/href.js", "/pimcore/static/js/pimcore/document/tags/multihref.js", "/pimcore/static/js/pimcore/document/tags/checkbox.js", "/pimcore/static/js/pimcore/document/tags/image.js", "/pimcore/static/js/pimcore/document/tags/input.js", "/pimcore/static/js/pimcore/document/tags/link.js", "/pimcore/static/js/pimcore/document/tags/select.js", "/pimcore/static/js/pimcore/document/tags/snippet.js", "/pimcore/static/js/pimcore/document/tags/textarea.js", "/pimcore/static/js/pimcore/document/tags/numeric.js", "/pimcore/static/js/pimcore/document/tags/wysiwyg.js", "/pimcore/static/js/pimcore/document/tags/renderlet.js", "/pimcore/static/js/pimcore/document/tags/table.js", "/pimcore/static/js/pimcore/document/tags/video.js", "/pimcore/static/js/pimcore/document/tags/multiselect.js", "/pimcore/static/js/pimcore/document/tags/areablock.js", "/pimcore/static/js/pimcore/document/tags/area.js", "/pimcore/static/js/pimcore/document/tags/pdf.js", "/pimcore/static/js/pimcore/document/edit/helper.js");
            $editmodeStylesheets = array("/pimcore/static/css/icons.css", "/pimcore/static/css/editmode.css?asd=" . time());
        }
        //add plugin editmode JS and CSS
        try {
            $pluginConfigs = ExtensionManager::getPluginConfigs();
            $jsPaths = array();
            $cssPaths = array();
            if (!empty($pluginConfigs)) {
                //registering plugins
                foreach ($pluginConfigs as $p) {
                    $pluginJsPaths = array();
                    if (array_key_exists("pluginDocumentEditmodeJsPaths", $p['plugin']) && is_array($p['plugin']['pluginDocumentEditmodeJsPaths']) && isset($p['plugin']['pluginDocumentEditmodeJsPaths']['path'])) {
                        if (is_array($p['plugin']['pluginDocumentEditmodeJsPaths']['path'])) {
                            $pluginJsPaths = $p['plugin']['pluginDocumentEditmodeJsPaths']['path'];
                        } else {
                            if ($p['plugin']['pluginDocumentEditmodeJsPaths']['path'] != null) {
                                $pluginJsPaths[] = $p['plugin']['pluginDocumentEditmodeJsPaths']['path'];
                            }
                        }
                    }
                    //manipulate path for frontend
                    if (is_array($pluginJsPaths) and count($pluginJsPaths) > 0) {
                        for ($i = 0; $i < count($pluginJsPaths); $i++) {
                            if (is_file(PIMCORE_PLUGINS_PATH . $pluginJsPaths[$i])) {
                                $jsPaths[] = "/plugins" . $pluginJsPaths[$i];
                            }
                        }
                    }
                    $pluginCssPaths = array();
                    if (array_key_exists("pluginDocumentEditmodeCssPaths", $p['plugin']) && is_array($p['plugin']['pluginDocumentEditmodeCssPaths']) && isset($p['plugin']['pluginDocumentEditmodeCssPaths']['path'])) {
                        if (is_array($p['plugin']['pluginDocumentEditmodeCssPaths']['path'])) {
                            $pluginCssPaths = $p['plugin']['pluginDocumentEditmodeCssPaths']['path'];
                        } else {
                            if ($p['plugin']['pluginDocumentEditmodeCssPaths']['path'] != null) {
                                $pluginCssPaths[] = $p['plugin']['pluginDocumentEditmodeCssPaths']['path'];
                            }
                        }
                    }
                    //manipulate path for frontend
                    if (is_array($pluginCssPaths) and count($pluginCssPaths) > 0) {
                        for ($i = 0; $i < count($pluginCssPaths); $i++) {
                            if (is_file(PIMCORE_PLUGINS_PATH . $pluginCssPaths[$i])) {
                                $cssPaths[] = "/plugins" . $pluginCssPaths[$i];
                            }
                        }
                    }
                }
            }
            $editmodeScripts = array_merge($editmodeScripts, $jsPaths);
            $editmodeStylesheets = array_merge($editmodeStylesheets, $cssPaths);
        } catch (\Exception $e) {
            \Logger::alert("there is a problem with the plugin configuration");
            \Logger::alert($e);
        }
        $editmodeHeadHtml = "\n\n\n<!-- pimcore editmode -->\n";
        // include stylesheets
        foreach ($editmodeStylesheets as $sheet) {
            $editmodeHeadHtml .= '<link rel="stylesheet" type="text/css" href="' . $sheet . '?_dc=' . Version::$revision . '" />';
            $editmodeHeadHtml .= "\n";
        }
        $editmodeHeadHtml .= "\n\n";
        $editmodeHeadHtml .= '<script type="text/javascript">var jQueryPreviouslyLoaded = (typeof jQuery == "undefined") ? false : true;</script>' . "\n";
        // include script libraries
        foreach ($editmodeLibraries as $script) {
            $editmodeHeadHtml .= '<script type="text/javascript" src="' . $script . '?_dc=' . Version::$revision . '"></script>';
            $editmodeHeadHtml .= "\n";
        }
        // combine the pimcore scripts in non-devmode
        if ($conf->general->devmode) {
            foreach ($editmodeScripts as $script) {
                $editmodeHeadHtml .= '<script type="text/javascript" src="' . $script . '?_dc=' . Version::$revision . '"></script>';
                $editmodeHeadHtml .= "\n";
            }
        } else {
            $scriptContents = "";
            foreach ($editmodeScripts as $scriptUrl) {
                $scriptContents .= file_get_contents(PIMCORE_DOCUMENT_ROOT . $scriptUrl) . "\n\n\n";
            }
            $editmodeHeadHtml .= '<script type="text/javascript" src="' . \Pimcore\Tool\Admin::getMinimizedScriptPath($scriptContents) . '?_dc=' . Version::$revision . '"></script>' . "\n";
        }
        $user = \Pimcore\Tool\Authentication::authenticateSession();
        $lang = $user->getLanguage();
        $editmodeHeadHtml .= '<script type="text/javascript" src="/admin/misc/json-translations-system/language/' . $lang . '/?_dc=' . Version::$revision . '"></script>' . "\n";
        $editmodeHeadHtml .= '<script type="text/javascript" src="/admin/misc/json-translations-admin/language/' . $lang . '/?_dc=' . Version::$revision . '"></script>' . "\n";
        $editmodeHeadHtml .= "\n\n";
        // set var for editable configurations which is filled by Document\Tag::admin()
        $editmodeHeadHtml .= '<script type="text/javascript">
            var editableConfigurations = new Array();
            var pimcore_document_id = ' . $request->getParam("document")->getId() . ';

            if(jQueryPreviouslyLoaded) {
                jQuery.noConflict( true );
            }
        </script>';
        $editmodeHeadHtml .= "\n\n<!-- /pimcore editmode -->\n\n\n";
        // add scripts in html header for pages in editmode
        if ($this->controller->editmode && Document\Service::isValidType($this->controller->document->getType())) {
            //ckogler
            include_once "simple_html_dom.php";
            $body = $this->getResponse()->getBody();
            $html = str_get_html($body);
            if ($html) {
                $htmlElement = $html->find("html", 0);
                $head = $html->find("head", 0);
                $bodyElement = $html->find("body", 0);
                // if there's no head and no body, create a wrapper including these elements
                // add html headers for snippets in editmode, so there is no problem with javascript
                if (!$head && !$bodyElement && !$htmlElement) {
                    $body = "<!DOCTYPE html>\n<html>\n<head></head><body>" . $body . "</body></html>";
                    $html = str_get_html($body);
                    // get them again with the updated html markup
                    $htmlElement = $html->find("html", 0);
                    $head = $html->find("head", 0);
                    $bodyElement = $html->find("body", 0);
                }
                if ($head && $bodyElement && $htmlElement) {
                    $head->innertext = $head->innertext . "\n\n" . $editmodeHeadHtml;
                    $bodyElement->onunload = "pimcoreOnUnload();";
                    if (\Pimcore\Tool\Admin::isExtJS6()) {
                        $bodyElement->innertext = $bodyElement->innertext . "\n\n" . '<script type="text/javascript" src="/pimcore/static6/js/pimcore/document/edit/startup.js?_dc=' . Version::$revision . '"></script>' . "\n\n";
                    } else {
                        $bodyElement->innertext = $bodyElement->innertext . "\n\n" . '<script type="text/javascript" src="/pimcore/static/js/pimcore/document/edit/startup.js?_dc=' . Version::$revision . '"></script>' . "\n\n";
                    }
                    $body = $html->save();
                    $this->getResponse()->setBody($body);
                } else {
                    $this->getResponse()->setBody('<div style="font-size:30px; font-family: Arial; font-weight:bold; color:red; text-align: center; margin: 40px 0">You have to define a &lt;html&gt;, &lt;head&gt;, &lt;body&gt;<br />HTML-tag in your view/layout markup!</div>');
                }
                $html->clear();
                unset($html);
            }
        }
        // IE compatibility
        //$this->getResponse()->setHeader("X-UA-Compatible", "IE=8; IE=9", true);
    }
Example #28
0
 /**
  * @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);
     }
 }
Example #29
0
 /**
      * old version incl. combining and using simple_dom_html
      *
      *
      *public static function processHtmlLEGACY ($body) {
         $html = str_get_html($body);
 
         if(!$html) {
             return $body;
         }
 
         $styles = $html->find("link[rel=stylesheet/less]");
 
         $stylesheetContents = array();
         $processedPaths = array();
 
         foreach ($styles as $style) {
 
             $media = $style->media;
             if(!$media) {
                 $media = "all";
             }
 
             $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;
             }
 
             // add the same file only one time
             if(in_array($path, $processedPaths)) {
                 continue;
             }
 
             if (is_file("file:/".$path)) {
 
                 $compiledContent = self::compile($path, $source);
 
                 $stylesheetContents[$media] .= $compiledContent . "\n";
                 $style->outertext = "";
 
                 $processedPaths[] = $path;
             }
         }
 
         // put compiled contents into single files, grouped by their media type
         if(count($stylesheetContents) > 0) {
             $head = $html->find("head",0);
             foreach ($stylesheetContents as $media => $content) {
                 $stylesheetPath = PIMCORE_TEMPORARY_DIRECTORY."/less_".md5($content).".css";
 
                 if(!is_file($stylesheetPath)) {
                     file_put_contents($stylesheetPath, $content);
                     @chmod($stylesheetPath, 0766);
                 }
 
                 $head->innertext = $head->innertext . "\n" . '<link rel="stylesheet" media="' . $media . '" type="text/css" href="' . str_replace(PIMCORE_DOCUMENT_ROOT,"",$stylesheetPath) . '" />'."\n";
             }
         }
 
         $body = $html->save();
 
         return $body;
     }*/
 public static function compile($path, $source = null)
 {
     $conf = \Pimcore\Config::getSystemConfig();
     $compiledContent = "";
     // check if the file is already compiled in the cache
     //$cacheKey = "less_file_" . md5_file($path);
     //if($contents = Pimcore_Model_Cache::load($cacheKey)) {
     //    return $contents;
     //}
     // use the original less compiler if configured
     if ($conf->outputfilters->lesscpath) {
         $output = array();
         exec($conf->outputfilters->lesscpath . " " . $path, $output);
         $compiledContent = implode(" ", $output);
         // add a comment to the css so that we know it's compiled by lessc
         if (!empty($compiledContent)) {
             $compiledContent = "\n\n/**** compiled with lessc (node.js) ****/\n\n" . $compiledContent;
         }
     }
     // use php implementation of lessc if it doesn't work
     if (empty($compiledContent)) {
         include_once "lessc.inc.php";
         $less = new \lessc();
         $less->importDir = dirname($path);
         $compiledContent = $less->parse(file_get_contents($path));
         // add a comment to the css so that we know it's compiled by lessphp
         $compiledContent = "\n\n/**** compiled with lessphp ****/\n\n" . $compiledContent;
     }
     if ($source) {
         // correct references inside the css
         $compiledContent = self::correctReferences($source, $compiledContent);
     }
     // put the compiled contents into the cache
     //Pimcore_Model_Cache::save($compiledContent, $cacheKey, array("less"));
     return $compiledContent;
 }
Example #30
0
 /**
  * @throws \Zend_Json_Exception
  */
 public function translateAction()
 {
     $conf = Config::getSystemConfig();
     $key = $conf->services->translate->apikey;
     $locale = new \Zend_Locale($this->getParam("language"));
     $language = $locale->getLanguage();
     $supportedTypes = array("input", "textarea", "wysiwyg");
     $data = \Zend_Json::decode($this->getParam("data"));
     foreach ($data as &$d) {
         if (in_array($d["type"], $supportedTypes)) {
             $response = Tool::getHttpData("https://www.googleapis.com/language/translate/v2?key=" . $key . "&q=" . urlencode($d["data"]) . "&target=" . $language);
             $tData = \Zend_Json::decode($response);
             if ($tData["data"]["translations"][0]["translatedText"]) {
                 $d["data"] = $tData["data"]["translations"][0]["translatedText"];
             }
         }
     }
     $this->getRequest()->setParam("data", \Zend_Json::encode($data));
     $this->saveToSessionAction();
 }