crit() public static method

public static crit ( $m, $context = [] )
Beispiel #1
0
 /**
  * @param null $adapter
  * @return null|Adapter\GD|Adapter\Imagick
  * @throws \Exception
  */
 public static function getInstance($adapter = null)
 {
     // use the default adapter if set manually (!= null) and no specify adapter is given
     if (!$adapter && self::$defaultAdapter) {
         $adapter = self::$defaultAdapter;
     }
     try {
         if ($adapter) {
             $adapterClass = "\\Pimcore\\Image\\Adapter\\" . $adapter;
             if (Tool::classExists($adapterClass)) {
                 return new $adapterClass();
             } else {
                 if (Tool::classExists($adapter)) {
                     return new $adapter();
                 } else {
                     throw new \Exception("Image-transform adapter `" . $adapter . "´ does not exist.");
                 }
             }
         } else {
             if (extension_loaded("imagick")) {
                 return new Adapter\Imagick();
             } else {
                 return new Adapter\GD();
             }
         }
     } catch (\Exception $e) {
         \Logger::crit("Unable to load image extensions: " . $e->getMessage());
         throw $e;
     }
     return null;
 }
Beispiel #2
0
 /**
  * @return null|Adapter\GD|Adapter\Imagick
  * @throws \Exception
  */
 public static function create()
 {
     try {
         if (extension_loaded("imagick")) {
             return new Adapter\Imagick();
         } else {
             return new Adapter\GD();
         }
     } catch (\Exception $e) {
         Logger::crit("Unable to load image extensions: " . $e->getMessage());
         throw $e;
     }
 }
Beispiel #3
0
 /**
  * @param null $adapter
  * @return bool|null|Document
  * @throws \Exception
  */
 public static function getInstance($adapter = null)
 {
     try {
         if ($adapter) {
             $adapterClass = "\\Pimcore\\Document\\Adapter\\" . $adapter;
             if (Tool::classExists($adapterClass)) {
                 return new $adapterClass();
             } else {
                 throw new \Exception("document-transcode adapter `" . $adapter . "´ does not exist.");
             }
         } else {
             if ($adapter = self::getDefaultAdapter()) {
                 return $adapter;
             }
         }
     } catch (\Exception $e) {
         \Logger::crit("Unable to load document adapter: " . $e->getMessage());
         throw $e;
     }
     return null;
 }
Beispiel #4
0
 /**
  * @param $element
  * @return $this
  */
 public function setDataFromElement($element)
 {
     $this->data = null;
     $this->id = new Data\Id($element);
     $this->fullPath = $element->getRealFullPath();
     $this->creationDate = $element->getCreationDate();
     $this->modificationDate = $element->getModificationDate();
     $this->userModification = $element->getUserModification();
     $this->userOwner = $element->getUserOwner();
     $this->type = $element->getType();
     if ($element instanceof Object\Concrete) {
         $this->subtype = $element->getClassName();
     } else {
         $this->subtype = $this->type;
     }
     $this->properties = "";
     $properties = $element->getProperties();
     if (is_array($properties)) {
         foreach ($properties as $nextProperty) {
             $pData = (string) $nextProperty->getData();
             if ($nextProperty->getName() == "bool") {
                 $pData = $pData ? "true" : "false";
             }
             $this->properties .= $nextProperty->getName() . ":" . $pData . " ";
         }
     }
     $this->data = "";
     if ($element instanceof Document) {
         if ($element instanceof Document\Folder) {
             $this->data = $element->getKey();
             $this->published = true;
         } elseif ($element instanceof Document\Link) {
             $this->published = $element->isPublished();
             $this->data = $element->getTitle() . " " . $element->getHref();
         } elseif ($element instanceof Document\PageSnippet) {
             $this->published = $element->isPublished();
             $elements = $element->getElements();
             if (is_array($elements) && !empty($elements)) {
                 foreach ($elements as $tag) {
                     if ($tag instanceof Document\Tag\TagInterface) {
                         ob_start();
                         $this->data .= strip_tags($tag->frontend()) . " ";
                         $this->data .= ob_get_clean();
                     }
                 }
             }
             if ($element instanceof Document\Page) {
                 $this->published = $element->isPublished();
                 $this->data .= " " . $element->getTitle() . " " . $element->getDescription() . " " . $element->getPrettyUrl();
             }
         }
     } elseif ($element instanceof Asset) {
         $this->data = $element->getFilename();
         $elementMetadata = $element->getMetadata();
         if (is_array($elementMetadata)) {
             foreach ($elementMetadata as $md) {
                 if (is_scalar($md['data'])) {
                     $this->data .= " " . $md["name"] . ":" . $md["data"];
                 }
             }
         }
         if ($element instanceof Asset\Document && \Pimcore\Document::isAvailable()) {
             if (\Pimcore\Document::isFileTypeSupported($element->getFilename())) {
                 try {
                     $contentText = $element->getText();
                     $contentText = Encoding::toUTF8($contentText);
                     $contentText = str_replace(["\r\n", "\r", "\n", "\t", "\f"], " ", $contentText);
                     $contentText = preg_replace("/[ ]+/", " ", $contentText);
                     $this->data .= " " . $contentText;
                 } catch (\Exception $e) {
                     Logger::error($e);
                 }
             }
         } elseif ($element instanceof Asset\Text) {
             try {
                 $contentText = $element->getData();
                 $contentText = Encoding::toUTF8($contentText);
                 $this->data .= " " . $contentText;
             } catch (\Exception $e) {
                 Logger::error($e);
             }
         } elseif ($element instanceof Asset\Image) {
             try {
                 $metaData = array_merge($element->getEXIFData(), $element->getIPTCData());
                 foreach ($metaData as $key => $value) {
                     $this->data .= " " . $key . " : " . $value;
                 }
             } catch (\Exception $e) {
                 Logger::error($e);
             }
         }
         $this->published = true;
     } elseif ($element instanceof Object\AbstractObject) {
         if ($element instanceof Object\Concrete) {
             $getInheritedValues = Object\AbstractObject::doGetInheritedValues();
             Object\AbstractObject::setGetInheritedValues(true);
             $this->published = $element->isPublished();
             foreach ($element->getClass()->getFieldDefinitions() as $key => $value) {
                 $this->data .= $value->getDataForSearchIndex($element) . " ";
             }
             Object\AbstractObject::setGetInheritedValues($getInheritedValues);
         } elseif ($element instanceof Object\Folder) {
             $this->data = $element->getKey();
             $this->published = true;
         }
     } else {
         Logger::crit("Search\\Backend\\Data received an unknown element!");
     }
     if ($element instanceof Element\ElementInterface) {
         $this->data = "ID: " . $element->getId() . "  \nPath: " . $this->getFullPath() . "  \n" . $this->cleanupData($this->data);
     }
     return $this;
 }
Beispiel #5
0
 protected function protect()
 {
     $user = $this->getParam("username");
     $data = $this->readLogFile();
     $matchesIpOnly = 0;
     $matchesUserOnly = 0;
     $matchesUserIp = 0;
     foreach ($data as $login) {
         $matchIp = false;
         $matchUser = false;
         if ($login[0] > time() - 300) {
             if ($user && $login[2] == $user) {
                 $matchesUserOnly++;
                 $matchUser = true;
             }
             if ($login[1] == Tool::getAnonymizedClientIp()) {
                 $matchesIpOnly++;
                 $matchIp = true;
             }
             if ($matchIp && $matchUser) {
                 $matchesUserIp++;
             }
         }
     }
     if ($matchesIpOnly > 49 || $matchesUserOnly > 9 || $matchesUserIp > 4) {
         $m = "Security Alert: Too many login attempts , please wait 5 minutes and try again.";
         Logger::crit($m);
         die($m);
     }
 }
Beispiel #6
0
 /**
  * @param array $additionalTags
  */
 public function clearDependentCache($additionalTags = [])
 {
     try {
         $tags = ["object_" . $this->getId(), "object_properties", "output"];
         $tags = array_merge($tags, $additionalTags);
         Cache::clearTags($tags);
     } catch (\Exception $e) {
         Logger::crit($e);
     }
 }
Beispiel #7
0
 /**
  * @return void
  */
 public function clearDependentCache()
 {
     // this is mostly called in Redirect\Dao not here
     try {
         \Pimcore\Cache::clearTag("redirect");
     } catch (\Exception $e) {
         Logger::crit($e);
     }
 }
Beispiel #8
0
 /**
  *
  */
 public static function init()
 {
     if (!self::$instance instanceof \Zend_Cache_Core) {
         // check for custom cache configuration
         $customCacheFile = PIMCORE_CONFIGURATION_DIRECTORY . "/cache.xml";
         if (is_file($customCacheFile)) {
             $config = self::getDefaultConfig();
             try {
                 $conf = new \Zend_Config_Xml($customCacheFile);
                 if ($conf->frontend) {
                     $config["frontendType"] = (string) $conf->frontend->type;
                     $config["customFrontendNaming"] = (bool) $conf->frontend->custom;
                     if ($conf->frontend->options && method_exists($conf->frontend->options, "toArray")) {
                         $config["frontendConfig"] = $conf->frontend->options->toArray();
                     }
                 }
                 if ($conf->backend) {
                     $config["backendType"] = (string) $conf->backend->type;
                     $config["customBackendNaming"] = (bool) $conf->backend->custom;
                     if ($conf->backend->options && method_exists($conf->backend->options, "toArray")) {
                         $config["backendConfig"] = $conf->backend->options->toArray();
                     }
                 }
                 if (isset($config["frontendConfig"]["lifetime"])) {
                     self::$defaultLifetime = $config["frontendConfig"]["lifetime"];
                 }
                 $config = self::normalizeConfig($config);
                 // here you can use the cache backend you like
                 try {
                     self::$instance = self::initializeCache($config);
                 } catch (\Exception $e) {
                     \Logger::crit("can't initialize cache with the given configuration " . $e->getMessage());
                 }
             } catch (\Exception $e) {
                 \Logger::crit($e);
                 \Logger::crit("Error while reading cache configuration, using the default file backend");
             }
         }
     }
     // return default cache if cache cannot be initialized
     if (!self::$instance instanceof \Zend_Cache_Core) {
         self::$instance = self::getDefaultCache();
     }
     self::$instance->setLifetime(self::$defaultLifetime);
     self::$instance->setOption("automatic_serialization", true);
     self::$instance->setOption("automatic_cleaning_factor", 0);
     // init the write lock once (from other processes etc.)
     if (self::$writeLockTimestamp === null) {
         self::$writeLockTimestamp = 0;
         // set the write lock to 0, otherwise infinite loop (self::hasWriteLock() calls self::getInstance())
         self::hasWriteLock();
     }
     self::setZendFrameworkCaches(self::$instance);
 }
Beispiel #9
0
 /**
  *
  */
 public static function init()
 {
     if (!self::$instance instanceof \Zend_Cache_Core) {
         // check for custom cache configuration
         $customConfigFile = \Pimcore\Config::locateConfigFile("cache.php");
         if (is_file($customConfigFile)) {
             $config = self::getDefaultConfig();
             $conf = (include $customConfigFile);
             if (is_array($conf)) {
                 if (isset($conf["frontend"])) {
                     $config["frontendType"] = $conf["frontend"]["type"];
                     $config["customFrontendNaming"] = $conf["frontend"]["custom"];
                     if (isset($conf["frontend"]["options"])) {
                         $config["frontendConfig"] = $conf["frontend"]["options"];
                     }
                 }
                 if (isset($conf["backend"])) {
                     $config["backendType"] = $conf["backend"]["type"];
                     $config["customBackendNaming"] = $conf["backend"]["custom"];
                     if (isset($conf["backend"]["options"])) {
                         $config["backendConfig"] = $conf["backend"]["options"];
                     }
                 }
                 if (isset($config["frontendConfig"]["lifetime"])) {
                     self::$defaultLifetime = $config["frontendConfig"]["lifetime"];
                 }
                 $config = self::normalizeConfig($config);
                 // here you can use the cache backend you like
                 try {
                     self::$instance = self::initializeCache($config);
                 } catch (\Exception $e) {
                     Logger::crit("can't initialize cache with the given configuration " . $e->getMessage());
                 }
             } else {
                 Logger::crit("Error while reading cache configuration, using the default database backend");
             }
         }
     }
     // return default cache if cache cannot be initialized
     if (!self::$instance instanceof \Zend_Cache_Core) {
         self::$instance = self::getDefaultCache();
     }
     self::$instance->setLifetime(self::$defaultLifetime);
     self::$instance->setOption("automatic_serialization", true);
     self::$instance->setOption("automatic_cleaning_factor", 0);
     // init the write lock once (from other processes etc.)
     if (self::$writeLockTimestamp === null) {
         self::$writeLockTimestamp = 0;
         // set the write lock to 0, otherwise infinite loop (self::hasWriteLock() calls self::getInstance())
         self::hasWriteLock();
     }
     self::setZendFrameworkCaches(self::$instance);
 }
 /**
  *  install function
  * @return string $message statusmessage to display in frontend
  */
 public static function install()
 {
     try {
         $install = new Install();
         $install->installConfigFile();
         $install->installProperties();
         $install->createDirectories();
         $install->createRedirect();
     } catch (\Exception $e) {
         \Pimcore\Logger::crit($e);
         return self::getTranslate()->_('lucenesearch_install_failed');
     }
     if (Configuration::get('frontend.enabled')) {
         self::forceCrawlerStartOnNextMaintenance('frontend');
     }
     return self::getTranslate()->_('lucenesearch_install_successfully');
 }