getHostUrl() public static method

Returns the host URL
public static getHostUrl ( string $useProtocol = null ) : string
$useProtocol string use a specific protocol
return string
Exemplo n.º 1
0
 /**
  * @return mixed|null
  * @throws \Exception
  */
 public static function getConfiguration()
 {
     $config = null;
     $configFile = \Pimcore\Config::locateConfigFile("hybridauth.php");
     if (is_file($configFile)) {
         $config = (include $configFile);
         $config["base_url"] = \Pimcore\Tool::getHostUrl() . "/hybridauth/endpoint";
     } else {
         throw new \Exception("HybridAuth configuration not found. Please place it into this file: {$configFile}");
     }
     return $config;
 }
Exemplo n.º 2
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();
 }
Exemplo n.º 3
0
 public function __construct($config)
 {
     foreach ($config as $key => $value) {
         if (property_exists($this, $key)) {
             $setter = "set" . ucfirst($key);
             if (method_exists($this, $setter)) {
                 $this->{$setter}($value);
             }
         }
     }
     $requiredParameters = array("securitySender", "userLogin", "userPwd", "transactionChannel");
     foreach ($requiredParameters as $req) {
         if (!isset($this->{$req})) {
             throw new \Exception("missing required parameter '{$req}'");
         }
     }
     if (substr($this->frontendResponseUrl, 0, 1) == "/") {
         $serverUrl = Tool::getHostUrl();
         $this->setFrontendResponseUrl($serverUrl . $this->frontendResponseUrl);
     }
 }
Exemplo n.º 4
0
 public function getHtml5Code($urls = array(), $thumbnail = null)
 {
     $code = "";
     $video = $this->getVideoAsset();
     if ($video) {
         $duration = ceil($video->getDuration());
         $durationParts = array("T");
         // hours
         if ($duration / 3600 >= 1) {
             $hours = floor($duration / 3600);
             $durationParts[] = $hours . "H";
             $duration = $duration - $hours * 3600;
         }
         // minutes
         if ($duration / 60 >= 1) {
             $minutes = floor($duration / 60);
             $durationParts[] = $minutes . "M";
             $duration = $duration - $minutes * 60;
         }
         $durationParts[] = $duration . "S";
         $durationString = implode("", $durationParts);
         $code .= '<div id="pimcore_video_' . $this->getName() . '" class="pimcore_tag_video" itemprop="video" itemscope itemtype="http://schema.org/VideoObject">' . "\n";
         $code .= '<meta itemprop="name" content="' . $this->getTitle() . '" />' . "\n";
         $code .= '<meta itemprop="description" content="' . $this->getDescription() . '" />' . "\n";
         $code .= '<meta itemprop="duration" content="' . $durationString . '" />' . "\n";
         $code .= '<meta itemprop="contentURL" content="' . Tool::getHostUrl() . $urls["mp4"] . '" />' . "\n";
         if ($thumbnail) {
             $code .= '<meta itemprop="thumbnailURL" content="' . Tool::getHostUrl() . $thumbnail . '" />' . "\n";
         }
         // default attributes
         $attributesString = "";
         $attributes = array("width" => $this->getWidth(), "height" => $this->getHeight(), "poster" => $thumbnail, "controls" => "controls", "class" => "pimcore_video");
         if (array_key_exists("attributes", $this->getOptions())) {
             $attributes = array_merge($attributes, $this->getOptions()["attributes"]);
         }
         foreach ($attributes as $key => $value) {
             $attributesString .= " " . $key;
             if (!empty($value)) {
                 $quoteChar = '"';
                 if (strpos($value, '"')) {
                     $quoteChar = "'";
                 }
                 $attributesString .= '=' . $quoteChar . $value . $quoteChar;
             }
         }
         $code .= '<video' . $attributesString . '>' . "\n";
         $urls = array_reverse($urls);
         // use webm as the preferred format
         foreach ($urls as $type => $url) {
             $code .= '<source type="video/' . $type . '" src="' . $url . '" />' . "\n";
         }
         $code .= '</video>' . "\n";
         $code .= '</div>' . "\n";
     }
     return $code;
 }
Exemplo n.º 5
0
 /**
  * @param mixed $level
  * @param string $message
  * @param array $context
  * @return null
  */
 public function log($level, $message, array $context = [])
 {
     if (!isset($context["component"])) {
         $context["component"] = $this->component;
     }
     if (!isset($context["fileObject"]) && $this->fileObject) {
         $context["fileObject"] = $this->fileObject;
     }
     if (isset($context["fileObject"])) {
         if (is_string($context["fileObject"])) {
             $context["fileObject"] = \Pimcore\Tool::getHostUrl() . "/" . str_replace(PIMCORE_DOCUMENT_ROOT, '', $context["fileObject"]);
         } else {
             $context["fileObject"] = \Pimcore\Tool::getHostUrl() . "/" . str_replace(PIMCORE_DOCUMENT_ROOT, '', $context["fileObject"]->getFilename());
         }
     }
     $relatedObject = null;
     if (isset($context["relatedObject"])) {
         $relatedObject = $context["relatedObject"];
     }
     if (!$relatedObject && $this->relatedObject) {
         $relatedObject = $this->relatedObject;
     }
     if ($relatedObject) {
         if ($relatedObject instanceof \Pimcore\Model\Object\AbstractObject or $relatedObject instanceof \Pimcore\Model\Document or $relatedObject instanceof \Pimcore\Model\Asset) {
             $relatedObject = $relatedObject->getId();
         }
         if (is_numeric($relatedObject)) {
             $context["relatedObject"] = $relatedObject;
             $context["relatedObjectType"] = $this->relatedObjectType;
         }
     }
     $context['source'] = $this->resolveLoggingSource();
     foreach ($this->loggers as $logger) {
         if ($logger instanceof \Psr\Log\LoggerInterface) {
             $logger->log($level, $message, $context);
         } elseif ($logger instanceof \Zend_Log) {
             // zf compatibility
             $zendLoggerPsr3Mapping = array_flip(Logger::getZendLoggerPsr3Mapping());
             $prio = $zendLoggerPsr3Mapping[$level];
             $logger->log($message, $prio, $context);
         }
     }
     return null;
 }
Exemplo n.º 6
0
 public function getHtml5Code($urls = [], $thumbnail = null)
 {
     $code = "";
     $video = $this->getVideoAsset();
     if ($video) {
         $duration = ceil($video->getDuration());
         $durationParts = ["PT"];
         // hours
         if ($duration / 3600 >= 1) {
             $hours = floor($duration / 3600);
             $durationParts[] = $hours . "H";
             $duration = $duration - $hours * 3600;
         }
         // minutes
         if ($duration / 60 >= 1) {
             $minutes = floor($duration / 60);
             $durationParts[] = $minutes . "M";
             $duration = $duration - $minutes * 60;
         }
         $durationParts[] = $duration . "S";
         $durationString = implode("", $durationParts);
         $code .= '<div id="pimcore_video_' . $this->getName() . '" class="pimcore_tag_video">' . "\n";
         $uploadDate = new \DateTime();
         $uploadDate->setTimestamp($video->getCreationDate());
         $jsonLd = ["@context" => "http://schema.org", "@type" => "VideoObject", "name" => $this->getTitle(), "description" => $this->getDescription(), "uploadDate" => $uploadDate->format(\DateTime::ISO8601), "duration" => $durationString, "contentUrl" => Tool::getHostUrl() . $urls["mp4"]];
         if ($thumbnail && !preg_match("@https?://@", $thumbnail)) {
             $jsonLd["thumbnailUrl"] = Tool::getHostUrl() . $thumbnail;
         }
         $code .= "\n\n<script type=\"application/ld+json\">\n" . json_encode($jsonLd) . "\n</script>\n\n";
         // default attributes
         $attributesString = "";
         $attributes = ["width" => $this->getWidth(), "height" => $this->getHeight(), "poster" => $thumbnail, "controls" => "controls", "class" => "pimcore_video"];
         if (array_key_exists("attributes", $this->getOptions())) {
             $attributes = array_merge($attributes, $this->getOptions()["attributes"]);
         }
         if (isset($this->getOptions()["removeAttributes"]) && is_array($this->getOptions()["removeAttributes"])) {
             foreach ($this->getOptions()["removeAttributes"] as $attribute) {
                 unset($attributes[$attribute]);
             }
         }
         foreach ($attributes as $key => $value) {
             $attributesString .= " " . $key;
             if (!empty($value)) {
                 $quoteChar = '"';
                 if (strpos($value, '"')) {
                     $quoteChar = "'";
                 }
                 $attributesString .= '=' . $quoteChar . $value . $quoteChar;
             }
         }
         $code .= '<video' . $attributesString . '>' . "\n";
         foreach ($urls as $type => $url) {
             $code .= '<source type="video/' . $type . '" src="' . $url . '" />' . "\n";
         }
         $code .= '</video>' . "\n";
         $code .= '</div>' . "\n";
     }
     return $code;
 }
Exemplo n.º 7
0
 /**
  * @param $path
  * @param null $document
  * @return array
  * @throws \Exception
  */
 public static function getNormalizedFileInfo($path, $document = null)
 {
     if ($document && $document instanceof Model\Document == false) {
         throw new \Exception('$document has to be an instance of Document');
     }
     $fileInfo = array();
     $hostUrl = Tool::getHostUrl();
     if ($path[0] != '/') {
         $fileInfo['fileUrl'] = $hostUrl . $document . "/{$path}";
         //relative eg. ../file.css
     } else {
         $fileInfo['fileUrl'] = $hostUrl . $path;
     }
     $fileInfo['fileExtension'] = substr($path, strrpos($path, '.') + 1);
     $netUrl = new \Net_URL2($fileInfo['fileUrl']);
     $fileInfo['fileUrlNormalized'] = $netUrl->getNormalizedURL();
     $fileInfo['filePathNormalized'] = PIMCORE_DOCUMENT_ROOT . str_replace($hostUrl, '', $fileInfo['fileUrlNormalized']);
     return $fileInfo;
 }
Exemplo n.º 8
0
 public function sendAction()
 {
     $document = Document\Newsletter::getById($this->getParam("id"));
     if (Tool\TmpStore::get($document->getTmpStoreId())) {
         throw new Exception("newsletter sending already in progress, need to finish first.");
     }
     $document = Document\Newsletter::getById($this->getParam("id"));
     Tool\TmpStore::add($document->getTmpStoreId(), ['documentId' => $document->getId(), 'addressSourceAdapterName' => $this->getParam("addressAdapterName"), 'adapterParams' => json_decode($this->getParam("adapterParams"), true), 'inProgress' => false, 'progress' => 0], 'newsletter');
     \Pimcore\Tool\Console::runPhpScriptInBackground(realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php"), "internal:newsletter-document-send " . escapeshellarg($document->getTmpStoreId()) . " " . escapeshellarg(\Pimcore\Tool::getHostUrl()), PIMCORE_LOG_DIRECTORY . DIRECTORY_SEPARATOR . "newsletter-sending-output.log");
     $this->_helper->json(["success" => true]);
 }
 public function sendAction()
 {
     $letter = Newsletter\Config::getByName($this->getParam("name"));
     if ($letter) {
         $cmd = Tool\Console::getPhpCli() . " " . realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php") . " internal:newsletter-send " . escapeshellarg($letter->getName()) . " " . escapeshellarg(Tool::getHostUrl());
         Tool\Console::execInBackground($cmd, PIMCORE_LOG_DIRECTORY . "/newsletter--" . $letter->getName() . ".log");
     }
     $this->_helper->json(array("success" => true));
 }
 public function generateScreenshotAction()
 {
     $success = false;
     if ($this->getParam("id")) {
         $doc = Document::getById($this->getParam("id"));
         $url = Tool::getHostUrl() . $doc->getRealFullPath() . "?pimcore_preview=true";
         $config = \Pimcore\Config::getSystemConfig();
         if ($config->general->http_auth) {
             $username = $config->general->http_auth->username;
             $password = $config->general->http_auth->password;
             if ($username && $password) {
                 $url = str_replace("://", "://" . $username . ":" . $password . "@", $url);
             }
         }
         $tmpFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/screenshot_tmp_" . $doc->getId() . ".png";
         $file = PIMCORE_TEMPORARY_DIRECTORY . "/document-page-previews/document-page-screenshot-" . $doc->getId() . ".jpg";
         $dir = dirname($file);
         if (!is_dir($dir)) {
             File::mkdir($dir);
         }
         try {
             if (\Pimcore\Image\HtmlToImage::convert($url, $tmpFile)) {
                 $im = \Pimcore\Image::getInstance();
                 $im->load($tmpFile);
                 $im->scaleByWidth(400);
                 $im->save($file, "jpeg", 85);
                 unlink($tmpFile);
                 $success = true;
             }
         } catch (\Exception $e) {
             \Logger::error($e);
         }
     }
     $this->_helper->json(array("success" => $success));
 }
Exemplo n.º 11
0
 public function checkErrorLogsDb()
 {
     $db = \Pimcore\Db::get();
     $conf = Config::getSystemConfig();
     $config = $conf->applicationlog;
     if ($config->mail_notification->send_log_summary) {
         $receivers = preg_split("/,|;/", $config->mail_notification->mail_receiver);
         array_walk($receivers, function (&$value) {
             $value = trim($value);
         });
         $logLevel = (int) $config->mail_notification->filter_priority;
         $query = "SELECT * FROM " . \Pimcore\Log\Handler\ApplicationLoggerDb::TABLE_NAME . " WHERE maintenanceChecked IS NULL AND priority <= {$logLevel} order by id desc";
         $rows = $db->fetchAll($query);
         $limit = 100;
         $rowsProcessed = 0;
         $rowCount = count($rows);
         if ($rowCount) {
             while ($rowsProcessed < $rowCount) {
                 $entries = [];
                 if ($rowCount <= $limit) {
                     $entries = $rows;
                 } else {
                     for ($i = $rowsProcessed; $i < $rowCount && count($entries) < $limit; $i++) {
                         $entries[] = $rows[$i];
                     }
                 }
                 $rowsProcessed += count($entries);
                 $html = var_export($entries, true);
                 $html = "<pre>{$html}</pre>";
                 $mail = new \Pimcore\Mail();
                 $mail->setIgnoreDebugMode(true);
                 $mail->setBodyHtml($html);
                 $mail->addTo($receivers);
                 $mail->setSubject('Error Log ' . \Pimcore\Tool::getHostUrl());
                 $mail->send();
             }
         }
     }
     // flag them as checked, regardless if email notifications are enabled or not
     // otherwise, when activating email notifications, you'll receive all log-messages from the past and not
     // since the point when you enabled the notifications
     $db->query("UPDATE " . \Pimcore\Log\Handler\ApplicationLoggerDb::TABLE_NAME . " set maintenanceChecked = 1");
 }
Exemplo n.º 12
0
 public function sendAction()
 {
     $letter = Newsletter\Config::getByName($this->getParam("name"));
     if ($letter) {
         Tool\Console::runPhpScriptInBackground(realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php"), "internal:newsletter-send " . escapeshellarg($letter->getName()) . " " . escapeshellarg(Tool::getHostUrl()));
     }
     $this->_helper->json(["success" => true]);
 }
Exemplo n.º 13
0
 /**
  * Checks for a suitable redirect
  * @throws Exception
  * @param bool $override
  * @return void
  */
 protected function checkForRedirect($override = false)
 {
     // not for admin requests
     if (Tool::isFrontentRequestByAdmin()) {
         return;
     }
     try {
         $front = \Zend_Controller_Front::getInstance();
         $config = Config::getSystemConfig();
         // get current site if available
         $sourceSite = null;
         if (Site::isSiteRequest()) {
             $sourceSite = Site::getCurrentSite();
         }
         $cacheKey = "system_route_redirect";
         if (empty($this->redirects) && !($this->redirects = Cache::load($cacheKey))) {
             $list = new Redirect\Listing();
             $list->setCondition("active = 1");
             $list->setOrder("DESC");
             $list->setOrderKey("priority");
             $this->redirects = $list->load();
             Cache::save($this->redirects, $cacheKey, ["system", "redirect", "route"], null, 998);
         }
         $requestScheme = Tool::getRequestScheme();
         $matchRequestUri = $_SERVER["REQUEST_URI"];
         $matchUrl = Tool::getHostUrl() . $matchRequestUri;
         foreach ($this->redirects as $redirect) {
             $matchAgainst = $matchRequestUri;
             if ($redirect->getSourceEntireUrl()) {
                 $matchAgainst = $matchUrl;
             }
             // if override is true the priority has to be 99 which means that overriding is ok
             if (!$override || $override && $redirect->getPriority() == 99) {
                 if (@preg_match($redirect->getSource(), $matchAgainst, $matches)) {
                     // check for a site
                     if ($sourceSite) {
                         if ($sourceSite->getId() != $redirect->getSourceSite()) {
                             continue;
                         }
                     }
                     array_shift($matches);
                     $target = $redirect->getTarget();
                     if (is_numeric($target)) {
                         $d = Document::getById($target);
                         if ($d instanceof Document\Page || $d instanceof Document\Link || $d instanceof Document\Hardlink) {
                             $target = $d->getFullPath();
                         } else {
                             \Logger::error("Target of redirect no found (Document-ID: " . $target . ")!");
                             continue;
                         }
                     }
                     // support for pcre backreferences
                     $url = replace_pcre_backreferences($target, $matches);
                     if ($redirect->getTargetSite() && !preg_match("@http(s)?://@i", $url)) {
                         try {
                             $targetSite = Site::getById($redirect->getTargetSite());
                             // if the target site is specified and and the target-path is starting at root (not absolute to site)
                             // the root-path will be replaced so that the page can be shown
                             $url = preg_replace("@^" . $targetSite->getRootPath() . "/@", "/", $url);
                             $url = $requestScheme . "://" . $targetSite->getMainDomain() . $url;
                         } catch (\Exception $e) {
                             \Logger::error("Site with ID " . $redirect->getTargetSite() . " not found.");
                             continue;
                         }
                     } elseif (!preg_match("@http(s)?://@i", $url) && $config->general->domain && $redirect->getSourceEntireUrl()) {
                         // prepend the host and scheme to avoid infinite loops when using "domain" redirects
                         $url = ($front->getRequest()->isSecure() ? "https" : "http") . "://" . $config->general->domain . $url;
                     }
                     // pass-through parameters if specified
                     $queryString = $_SERVER["QUERY_STRING"];
                     if ($redirect->getPassThroughParameters() && !empty($queryString)) {
                         $glue = "?";
                         if (strpos($url, "?")) {
                             $glue = "&";
                         }
                         $url .= $glue;
                         $url .= $queryString;
                     }
                     header($redirect->getHttpStatus());
                     header("Location: " . $url, true, $redirect->getStatusCode());
                     // log all redirects to the redirect log
                     \Pimcore\Log\Simple::log("redirect", Tool::getAnonymizedClientIp() . " \t Custom-Redirect ID: " . $redirect->getId() . " , Source: " . $_SERVER["REQUEST_URI"] . " -> " . $url);
                     exit;
                 }
             }
         }
     } catch (\Exception $e) {
         // no suitable route found
     }
 }