本文整理汇总了PHP中Pimcore\Tool类的典型用法代码示例。如果您正苦于以下问题:PHP Tool类的具体用法?PHP Tool怎么用?PHP Tool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dispatchLoopShutdown
/**
*
*/
public function dispatchLoopShutdown()
{
if (!Tool::isHtmlResponse($this->getResponse())) {
return;
}
$siteKey = \Pimcore\Tool\Frontend::getSiteKey();
$reportConfig = \Pimcore\Config::getReportConfig();
if ($this->enabled && isset($reportConfig->tagmanager->sites->{$siteKey}->containerId)) {
$containerId = $reportConfig->tagmanager->sites->{$siteKey}->containerId;
if ($containerId) {
$code = <<<CODE
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id={$containerId}"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','{$containerId}');</script>
<!-- End Google Tag Manager -->
CODE;
$body = $this->getResponse()->getBody();
// insert code after the opening <body> tag
$body = preg_replace("@<body(>|.*?[^?]>)@", "<body\$1\n\n" . $code, $body);
$this->getResponse()->setBody($body);
}
}
}
示例2: dispatchLoopShutdown
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);
}
}
示例3: dispatchLoopShutdown
/**
*
*/
public function dispatchLoopShutdown()
{
if (!Tool::isHtmlResponse($this->getResponse())) {
return;
}
if (!Tool::useFrontendOutputFilters($this->getRequest()) && !$this->getRequest()->getParam("pimcore_preview")) {
return;
}
if (isset($_COOKIE["pimcore_admin_sid"])) {
try {
// we should not start a session here as this can break the functionality of the site if
// the website itself uses sessions, so we include the code, and check asynchronously if the user is logged in
// this is done by the embedded script
$body = $this->getResponse()->getBody();
$document = $this->getRequest()->getParam("document");
if ($document instanceof Model\Document && !Model\Staticroute::getCurrentRoute()) {
$documentId = $document->getId();
}
if (!isset($documentId) || !$documentId) {
$documentId = "null";
}
$code = '<script type="text/javascript" src="/admin/admin-button/script?documentId=' . $documentId . '"></script>';
// 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
$bodyEndPosition = stripos($body, "</body>");
if ($bodyEndPosition !== false) {
$body = substr_replace($body, $code . "\n\n</body>\n", $bodyEndPosition, 7);
}
$this->getResponse()->setBody($body);
} catch (\Exception $e) {
\Logger::error($e);
}
}
}
示例4: __construct
public function __construct()
{
$this->logger = Logging::getInstance();
$this->client = \Pimcore\Tool::getHttpClient();
$overrideConfig = new \Zend_Config(array("maxredirects" => 5));
$this->client->setConfig($overrideConfig);
}
示例5: addLanguage
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;
}
示例6: checkConfig
/**
* checks configuration and if specified classes exist
*
* @param $config
* @throws OnlineShop_Framework_Exception_InvalidConfigException
*/
protected function checkConfig($config)
{
$tempCart = null;
if (empty($config->cart->class)) {
throw new OnlineShop_Framework_Exception_InvalidConfigException("No Cart class defined.");
} else {
if (Tool::classExists($config->cart->class)) {
$tempCart = new $config->cart->class($config->cart);
if (!$tempCart instanceof OnlineShop_Framework_ICart) {
throw new OnlineShop_Framework_Exception_InvalidConfigException("Cart class " . $config->cart->class . " does not implement OnlineShop_Framework_ICart.");
}
} else {
throw new OnlineShop_Framework_Exception_InvalidConfigException("Cart class " . $config->cart->class . " not found.");
}
}
if (empty($config->pricecalculator->class)) {
throw new OnlineShop_Framework_Exception_InvalidConfigException("No pricecalculator class defined.");
} else {
if (Tool::classExists($config->pricecalculator->class)) {
$tempCalc = new $config->pricecalculator->class($config->pricecalculator->config, $tempCart);
if (!$tempCalc instanceof OnlineShop_Framework_ICartPriceCalculator) {
throw new OnlineShop_Framework_Exception_InvalidConfigException("Cart class " . $config->pricecalculator->class . " does not implement OnlineShop_Framework_ICartPriceCalculator.");
}
} else {
throw new OnlineShop_Framework_Exception_InvalidConfigException("pricecalculator class " . $config->pricecalculator->class . " not found.");
}
}
}
示例7: dispatchLoopShutdown
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);
}
}
}
示例8: map
/**
* @param $object
* @param $apiclass
* @param $type
* @param null $options
* @return array|string
* @throws \Exception
*/
public static function map($object, $apiclass, $type, $options = null)
{
if ($object instanceof \Zend_Date) {
$object = $object->toString();
} else {
if (is_object($object)) {
if (Tool::classExists($apiclass)) {
$new = new $apiclass();
if (method_exists($new, "map")) {
$new->map($object, $options);
$object = $new;
}
} else {
throw new \Exception("Webservice\\Data\\Mapper: Cannot map [ {$apiclass} ] - class does not exist");
}
} else {
if (is_array($object)) {
$tmpArray = array();
foreach ($object as $v) {
$className = self::findWebserviceClass($v, $type);
$tmpArray[] = self::map($v, $className, $type);
}
$object = $tmpArray;
}
}
}
return $object;
}
示例9: getSystemConfig
/**
* @param bool $forceReload
* @return mixed|null|\Zend_Config
* @throws \Zend_Exception
*/
public static function getSystemConfig($forceReload = false)
{
$config = null;
if (\Zend_Registry::isRegistered("pimcore_config_system") && !$forceReload) {
$config = \Zend_Registry::get("pimcore_config_system");
} else {
try {
$file = self::locateConfigFile("system.php");
if (file_exists($file)) {
$config = new \Zend_Config(include $file);
} else {
throw new \Exception($file . " doesn't exist");
}
self::setSystemConfig($config);
} catch (\Exception $e) {
$file = self::locateConfigFile("system.php");
\Logger::emergency("Cannot find system configuration, should be located at: " . $file);
if (is_file($file)) {
$m = "Your system.php located at " . $file . " is invalid, please check and correct it manually!";
Tool::exitWithError($m);
}
}
}
return $config;
}
示例10: getInstance
/**
* @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;
}
示例11: storeLanguage
private function storeLanguage()
{
if ($this->mySessionSite->Locale) {
\Zend_Registry::set("Zend_Locale", $this->mySessionSite->Locale);
}
if ($this->_getParam("lg")) {
$locale = new \Zend_Locale($this->_getParam("lg"));
\Zend_Registry::set("Zend_Locale", $locale);
}
if (\Zend_Registry::isRegistered("Zend_Locale") and $this->mySessionSite->Locale) {
//init forcée à french à reprendre
$locale = \Zend_Registry::get("Zend_Locale");
} else {
$locale = new \Zend_Locale("fr_FR");
\Zend_Registry::set("Zend_Locale", $locale);
}
$this->mySessionSite->Locale = $locale;
$this->view->language = $this->language = $locale->getLanguage();
$languages = \Pimcore\Tool::getValidLanguages();
$languageOptions = array();
foreach ($languages as $short) {
if (!empty($short)) {
$languageOptions[] = array("language" => $short, "display" => \Zend_Locale::getTranslation($short == "fr_FR" ? "fr" : $short, 'Language', $locale));
$validLanguages[] = $short;
}
}
$this->view->languageOptions = $languageOptions;
$this->view->isAjax = $this->isAjax();
}
示例12: createClassMappings
/**
* @static
* @return array
*/
public static function createClassMappings()
{
$modelsDir = PIMCORE_PATH . "/models/";
$files = rscandir($modelsDir);
$includePatterns = array("/Webservice\\/Data/");
foreach ($files as $file) {
if (is_file($file)) {
$file = str_replace($modelsDir, "", $file);
$file = str_replace(".php", "", $file);
$class = str_replace(DIRECTORY_SEPARATOR, "_", $file);
if (\Pimcore\Tool::classExists($class)) {
$match = false;
foreach ($includePatterns as $pattern) {
if (preg_match($pattern, $file)) {
$match = true;
break;
}
}
if (strpos($file, "Webservice" . DIRECTORY_SEPARATOR . "Data") !== false) {
$match = true;
}
if (!$match) {
continue;
}
$classMap[str_replace("\\Pimcore\\Model\\Webservice\\Data\\", "", $class)] = $class;
}
}
}
return $classMap;
}
示例13: routeStartup
/**
* @param \Zend_Controller_Request_Abstract $request
*/
public function routeStartup(\Zend_Controller_Request_Abstract $request)
{
$maintenance = false;
$file = \Pimcore\Tool\Admin::getMaintenanceModeFile();
if (is_file($file)) {
$conf = (include $file);
if (isset($conf["sessionId"])) {
if ($conf["sessionId"] != $_COOKIE["pimcore_admin_sid"]) {
$maintenance = true;
}
} else {
@unlink($file);
}
}
// do not activate the maintenance for the server itself
// this is to avoid problems with monitoring agents
$serverIps = ["127.0.0.1"];
if ($maintenance && !in_array(\Pimcore\Tool::getClientIp(), $serverIps)) {
header("HTTP/1.1 503 Service Temporarily Unavailable", 503);
$file = PIMCORE_PATH . "/static/html/maintenance.html";
$customFile = PIMCORE_CUSTOM_CONFIGURATION_DIRECTORY . "/maintenance.html";
if (file_exists($customFile)) {
$file = $customFile;
}
echo file_get_contents($file);
exit;
}
}
示例14: determineResourceClass
/**
* determineResourceClass
*
* @param $className
*/
protected function determineResourceClass($className)
{
if (Tool::classExists($className)) {
return $className;
}
return parent::determineResourceClass($className);
}
示例15: send
/**
* @param null $options
* @return bool|void
* @throws \Exception
* @throws \Zend_Http_Client_Exception
*/
public function send($options = null)
{
$sourceFile = $this->getSourceFile();
$destinationFile = $this->getDestinationFile();
if (!$sourceFile) {
throw new \Exception("No sourceFile provided.");
}
if (!$destinationFile) {
throw new \Exception("No destinationFile provided.");
}
if (is_array($options)) {
if ($options['overwrite'] == false && file_exists($destinationFile)) {
throw new \Exception("Destination file : '" . $destinationFile . "' already exists.");
}
}
if (!$this->getHttpClient()) {
$httpClient = \Pimcore\Tool::getHttpClient(null, ['timeout' => 3600 * 60]);
} else {
$httpClient = $this->getHttpClient();
}
$httpClient->setUri($this->getSourceFile());
$response = $httpClient->request();
if ($response->isSuccessful()) {
$data = $response->getBody();
File::mkdir(dirname($destinationFile));
$result = File::put($destinationFile, $data);
if ($result === false) {
throw new \Exception("Couldn't write destination file:" . $destinationFile);
}
} else {
throw new \Exception("Couldn't download file:" . $sourceFile);
}
return true;
}