sendHeader() public static method

Sets outgoing header.
public static sendHeader ( string $header, boolean $replace = true )
$header string The header.
$replace boolean Whether to replace existing or not.
示例#1
0
 /**
  * Return the base.less compiled to css
  *
  * @return string
  */
 public function getUpdaterJs()
 {
     Common::sendHeader('Content-Type: application/javascript; charset=UTF-8');
     Common::sendHeader('Cache-Control: max-age=' . 60 * 60);
     $files = array('libs/bower_components/jquery/dist/jquery.min.js', 'libs/bower_components/jquery-ui/ui/minified/jquery-ui.min.js', 'libs/bower_components/materialize/dist/js/materialize.min.js', 'plugins/Morpheus/javascripts/piwikHelper.js', 'plugins/CoreHome/javascripts/donate.js', 'plugins/CoreUpdater/javascripts/updateLayout.js', 'libs/bower_components/angular/angular.min.js', 'libs/bower_components/angular-sanitize/angular-sanitize.js', 'libs/bower_components/angular-animate/angular-animate.js', 'libs/bower_components/angular-cookies/angular-cookies.js', 'libs/bower_components/ngDialog/js/ngDialog.min.js', 'plugins/CoreHome/angularjs/common/services/service.module.js', 'plugins/CoreHome/angularjs/common/filters/filter.module.js', 'plugins/CoreHome/angularjs/common/filters/translate.js', 'plugins/CoreHome/angularjs/common/directives/directive.module.js', 'plugins/CoreHome/angularjs/common/directives/focus-anywhere-but-here.js', 'plugins/CoreHome/angularjs/piwikApp.config.js', 'plugins/CoreHome/angularjs/piwikApp.js', 'plugins/Installation/javascripts/installation.js');
     return AssetManager::compileCustomJs($files);
 }
示例#2
0
文件: Piwik.php 项目: GovanifY/piwik
 /**
  * Display the message in a nice red font with a nice icon
  * ... and dies
  *
  * @param string $message
  */
 public static function exitWithErrorMessage($message)
 {
     Common::sendHeader('Content-Type: text/html; charset=utf-8');
     $output = "<style>a{color:red;}</style>\n" . "<div style='color:red;font-family:Georgia;font-size:120%'>" . "<p><img src='plugins/Morpheus/images/error_medium.png' style='vertical-align:middle; float:left;padding:20px' />" . $message . "</p></div>";
     print $output;
     exit;
 }
示例#3
0
文件: Piwik.php 项目: diosmosis/piwik
 /**
  * Display the message in a nice red font with a nice icon
  * ... and dies
  *
  * @param string $message
  */
 public static function exitWithErrorMessage($message)
 {
     Common::sendHeader('Content-Type: text/html; charset=utf-8');
     $message = str_replace("\n", "<br/>", $message);
     $output = "<html><body>" . "<style>a{color:red;}</style>\n" . "<div style='color:red;font-size:120%; width:100%;margin: 30px;'>" . " <div style='width: 50px; float: left;'><img src='plugins/Morpheus/images/error_medium.png' /></div>" . "  <div style='margin-left: 70px; min-width: 950px;'>" . $message . "  </div>" . " </div>" . "</div>" . "</body></html>";
     print $output;
     exit;
 }
示例#4
0
 public function sendHeader()
 {
     if ($this->isJsonp()) {
         Common::sendHeader('Content-Type: application/javascript; charset=utf-8');
     } else {
         Renderer\Json::sendHeaderJSON();
     }
     ProxyHttp::overrideCacheControlHeaders();
 }
 public static function formatScreenMessage(&$message, $level, $tag, $datetime, $log)
 {
     if ($message instanceof \Exception) {
         Common::sendHeader('Content-Type: text/html; charset=utf-8');
         $outputFormat = strtolower(Common::getRequestVar('format', 'html', 'string'));
         $response = new ResponseBuilder($outputFormat);
         $message = $response->getResponseException(new \Exception($message->getMessage()));
     }
 }
示例#6
0
 /**
  * Creates a new instance of a class using a string ID.
  *
  * @param string $classId The ID of the class.
  * @return BaseFactory
  * @throws Exception if $classId is invalid.
  */
 public static function factory($classId)
 {
     $className = static::getClassNameFromClassId($classId);
     if (!class_exists($className)) {
         Common::sendHeader('Content-Type: text/plain; charset=utf-8');
         throw new Exception(static::getInvalidClassIdExceptionMessage($classId));
     }
     return new $className();
 }
 public function sendResponseToBrowserDirectly()
 {
     while (ob_get_level() > 1) {
         ob_end_flush();
     }
     Common::sendHeader("Connection: close\r\n", true);
     Common::sendHeader("Content-Encoding: none\r\n", true);
     Common::sendHeader('Content-Length: ' . ob_get_length(), true);
     ob_end_flush();
     flush();
 }
示例#8
0
 public function handle()
 {
     // allow Piwik to serve data to all domains
     if (in_array("*", $this->domains)) {
         Common::sendHeader('Access-Control-Allow-Origin: *');
         return;
     }
     // specifically allow if it is one of the whitelisted CORS domains
     if (!empty($_SERVER['HTTP_ORIGIN'])) {
         $origin = $_SERVER['HTTP_ORIGIN'];
         if (in_array($origin, $this->domains, true)) {
             Common::sendHeader('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
         }
     }
 }
 /**
  * Checks for DoNotTrack headers and if found, sets `$exclude` to `true`.
  */
 public function checkHeaderInTracker(&$exclude)
 {
     if ($exclude) {
         Common::printDebug("Visit is already excluded, no need to check DoNotTrack support.");
         return;
     }
     $exclude = $this->isDoNotTrackFound();
     if ($exclude) {
         $trackingCookie = IgnoreCookie::getTrackingCookie();
         $trackingCookie->delete();
         // this is an optional supplement to the site's tracking status resource at:
         //     /.well-known/dnt
         // per Tracking Preference Expression (draft)
         Common::sendHeader('Tk: 1');
     }
 }
示例#10
0
 /**
  * Checks for DoNotTrack headers and if found, sets `$exclude` to `true`.
  */
 public function checkHeaderInTracker(&$exclude)
 {
     if ($exclude) {
         Common::printDebug("Visit is already excluded, no need to check DoNotTrack support.");
         return;
     }
     $exclude = $this->isDoNotTrackFound();
     if ($exclude) {
         IgnoreCookie::deleteThirdPartyCookieUIDIfExists();
         // this is an optional supplement to the site's tracking status resource at:
         //     /.well-known/dnt
         // per Tracking Preference Expression
         //Tracking Perference Expression has been updated to require Tk: N rather than Tk: 1
         Common::sendHeader('Tk: N');
     }
 }
示例#11
0
    /**
     * Outputs the data.
     *
     * @return string  html
     */
    public function render()
    {
        // set response headers
        @Common::sendHeader('Content-Type: text/html; charset=UTF-8');
        @Common::sendHeader('Pragma: ');
        @Common::sendHeader('Expires: ');
        @Common::sendHeader('Cache-Control: must-revalidate');
        @Common::sendHeader('X-Frame-Options: deny');
        $error = htmlspecialchars($this->error, ENT_QUOTES, 'UTF-8');
        $messages = htmlspecialchars(serialize($this->feedbackMessages), ENT_QUOTES, 'UTF-8');
        $tokenAuth = $this->tokenAuth;
        $httpsFail = (int) $this->httpsFail;
        // use a heredoc instead of an external file
        echo <<<END_OF_TEMPLATE
<!DOCTYPE html>
<html>
 <head>
  <meta name="robots" content="noindex,nofollow">
  <meta charset="utf-8">
  <title></title>
 </head>
 <body>
  <form name="myform" method="post" action="?module=CoreUpdater&amp;action=oneClickResults">
   <input type="hidden" name="token_auth" value="{$tokenAuth}" />
   <input type="hidden" name="error" value="{$error}" />
   <input type="hidden" name="messages" value="{$messages}" />
   <input type="hidden" name="httpsFail" value="{$httpsFail}" />
   <noscript>
    <button type="submit">Continue</button>
   </noscript>
  </form>
  <script type="text/javascript">
   document.myform.submit();
  </script>
 </body>
</html>
END_OF_TEMPLATE;
    }
示例#12
0
 /**
  * Prints out the CSS for installer/updater
  *
  * During installation and update process, we load a minimal Less file.
  * At this point Piwik may not be setup yet to write files in tmp/assets/
  * so in this case we compile and return the string on every request.
  */
 public function getBaseCss()
 {
     Common::sendHeader('Content-Type: text/css');
     return AssetManager::getInstance()->getCompiledBaseCss()->getContent();
 }
示例#13
0
文件: View.php 项目: diosmosis/piwik
 /**
  * Renders the current view. Also sends the stored 'Content-Type' HTML header.
  * See {@link setContentType()}.
  *
  * @return string Generated template.
  */
 public function render()
 {
     try {
         $this->currentModule = Piwik::getModule();
         $this->currentAction = Piwik::getAction();
         $this->url = Common::sanitizeInputValue(Url::getCurrentUrl());
         $this->token_auth = Piwik::getCurrentUserTokenAuth();
         $this->userHasSomeAdminAccess = Piwik::isUserHasSomeAdminAccess();
         $this->userIsAnonymous = Piwik::isUserIsAnonymous();
         $this->userIsSuperUser = Piwik::hasUserSuperUserAccess();
         $this->latest_version_available = UpdateCheck::isNewestVersionAvailable();
         $this->disableLink = Common::getRequestVar('disableLink', 0, 'int');
         $this->isWidget = Common::getRequestVar('widget', 0, 'int');
         $piwikAds = StaticContainer::get('Piwik\\ProfessionalServices\\Advertising');
         $this->areAdsForProfessionalServicesEnabled = $piwikAds->areAdsForProfessionalServicesEnabled();
         if (Development::isEnabled()) {
             $cacheBuster = rand(0, 10000);
         } else {
             $cacheBuster = UIAssetCacheBuster::getInstance()->piwikVersionBasedCacheBuster();
         }
         $this->cacheBuster = $cacheBuster;
         $this->loginModule = Piwik::getLoginPluginName();
         $user = APIUsersManager::getInstance()->getUser($this->userLogin);
         $this->userAlias = $user['alias'];
     } catch (Exception $e) {
         Log::debug($e);
         // can fail, for example at installation (no plugin loaded yet)
     }
     ProxyHttp::overrideCacheControlHeaders('no-store');
     Common::sendHeader('Content-Type: ' . $this->contentType);
     // always sending this header, sometimes empty, to ensure that Dashboard embed loads
     // - when calling sendHeader() multiple times, the last one prevails
     Common::sendHeader('X-Frame-Options: ' . (string) $this->xFrameOptions);
     return $this->renderTwigTemplate();
 }
示例#14
0
 public function sendHeader()
 {
     if ($this->shouldSerialize()) {
         Common::sendHeader('Content-Type: text/plain; charset=utf-8');
     }
 }
示例#15
0
文件: Json.php 项目: bossrabbit/piwik
 public static function sendHeaderJSON()
 {
     Common::sendHeader('Content-Type: application/json; charset=utf-8');
 }
示例#16
0
文件: Php.php 项目: diosmosis/piwik
 public function sendHeader()
 {
     Common::sendHeader('Content-Type: text/plain; charset=utf-8');
 }
示例#17
0
 public function sendHeader()
 {
     Common::sendHeader("Content-Type: application/vnd.ms-excel", true);
     ProxyHttp::overrideCacheControlHeaders();
 }
示例#18
0
 public function sendHeader()
 {
     Common::sendHeader('Content-Type: text/html; charset=utf-8', true);
 }
示例#19
0
 /**
  * Sends the http headers for csv file
  */
 protected function renderHeader()
 {
     $fileName = 'Piwik ' . Piwik::translate('General_Export');
     $period = Common::getRequestVar('period', false);
     $date = Common::getRequestVar('date', false);
     if ($period || $date) {
         if ($period == 'range') {
             $period = new Range($period, $date);
         } else {
             if (strpos($date, ',') !== false) {
                 $period = new Range('range', $date);
             } else {
                 $period = Period\Factory::build($period, Date::factory($date));
             }
         }
         $prettyDate = $period->getLocalizedLongString();
         $meta = $this->getApiMetaData();
         $fileName .= ' _ ' . $meta['name'] . ' _ ' . $prettyDate . '.csv';
     }
     // silent fail otherwise unit tests fail
     Common::sendHeader('Content-Disposition: attachment; filename="' . $fileName . '"', true);
     ProxyHttp::overrideCacheControlHeaders();
 }
示例#20
0
文件: Tracker.php 项目: Abine/piwik
 protected function outputTransparentGif()
 {
     if (isset($GLOBALS['PIWIK_TRACKER_DEBUG']) && $GLOBALS['PIWIK_TRACKER_DEBUG']) {
         return;
     }
     if (strlen($this->getOutputBuffer()) > 0) {
         // If there was an error during tracker, return so errors can be flushed
         return;
     }
     $transGifBase64 = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
     Common::sendHeader('Content-Type: image/gif');
     $this->outputAccessControlHeaders();
     print base64_decode($transGifBase64);
 }
示例#21
0
 function DisplayTopKeywords($url = "", $api)
 {
     // Do not spend more than 1 second fetching the data
     @ini_set("default_socket_timeout", $timeout = 1);
     // Get the Keywords data
     $url = empty($url) ? "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] : $url;
     $api = $api . "&url=" . urlencode($url);
     $keywords = @json_decode(file_get_contents($api), $assoc = true);
     Common::sendHeader('Content-Type: text/html; charset=utf-8', true);
     if ($keywords === false || isset($keywords["result"])) {
         // DEBUG ONLY: uncomment for troubleshooting an empty output (the URL output reveals the token_auth)
         //echo "Error while fetching the <a href=\'".$api."\'>Top Keywords from Piwik</a>";
         return;
     }
     // Display the list in HTML
     $url = htmlspecialchars($url, ENT_QUOTES);
     $output = "<h2>Top Keywords for <a href=\\'{$url}\\'>{$url}</a></h2><ul>";
     foreach ($keywords as $keyword) {
         $output .= "<li>" . $keyword . "</li>";
     }
     if (empty($keywords)) {
         $output .= "Nothing yet...";
     }
     $output .= "</ul>";
     echo $output;
 }
示例#22
0
 private function outputTransparentGif()
 {
     $transGifBase64 = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
     Common::sendHeader('Content-Type: image/gif');
     echo base64_decode($transGifBase64);
 }
 public static function dieWithHtmlErrorPage(Exception $exception)
 {
     Common::sendHeader('Content-Type: text/html; charset=utf-8');
     echo self::getErrorResponse($exception);
     exit(1);
 }
示例#24
0
 /**
  * Start an Overlay session: Redirect to the tracked website. The Piwik
  * tracker will recognize this referrer and start the session.
  */
 public function startOverlaySession()
 {
     $idSite = Common::getRequestVar('idSite', 0, 'int');
     Piwik::checkUserHasViewAccess($idSite);
     $view = new View('@Overlay/startOverlaySession');
     $sitesManager = APISitesManager::getInstance();
     $site = $sitesManager->getSiteFromId($idSite);
     $urls = $sitesManager->getSiteUrlsFromId($idSite);
     $view->isHttps = ProxyHttp::isHttps();
     $view->knownUrls = json_encode($urls);
     $view->mainUrl = $site['main_url'];
     $this->outputCORSHeaders();
     Common::sendHeader('Content-Type: text/html; charset=UTF-8');
     return $view->render();
 }
示例#25
0
 private static function sendPlainHeader()
 {
     Common::sendHeader('Content-Type: text/plain; charset=utf-8');
 }
示例#26
0
文件: Url.php 项目: mgou-net/piwik
 private static function redirectToUrlNoExit($url)
 {
     if (UrlHelper::isLookLikeUrl($url) || strpos($url, 'index.php') === 0) {
         Common::sendResponseCode(302);
         Common::sendHeader("Location: {$url}");
     } else {
         echo "Invalid URL to redirect to.";
     }
     if (Common::isPhpCliMode()) {
         throw new Exception("If you were using a browser, Piwik would redirect you to this URL: {$url} \n\n");
     }
 }
示例#27
0
 /**
  * Sends the given response code if supported.
  *
  * @param int $code  Eg 204
  *
  * @throws Exception
  */
 public static function sendResponseCode($code)
 {
     $messages = array(200 => 'Ok', 204 => 'No Response', 301 => 'Moved Permanently', 302 => 'Found', 304 => 'Not Modified', 400 => 'Bad Request', 401 => 'Unauthorized', 403 => 'Forbidden', 404 => 'Not Found', 500 => 'Internal Server Error', 503 => 'Service Unavailable');
     if (!array_key_exists($code, $messages)) {
         throw new Exception('Response code not supported: ' . $code);
     }
     if (strpos(PHP_SAPI, '-fcgi') === false) {
         $key = 'HTTP/1.1';
         if (array_key_exists('SERVER_PROTOCOL', $_SERVER) && strlen($_SERVER['SERVER_PROTOCOL']) < 15 && strlen($_SERVER['SERVER_PROTOCOL']) > 1) {
             $key = $_SERVER['SERVER_PROTOCOL'];
         }
     } else {
         // FastCGI
         $key = 'Status:';
     }
     $message = $messages[$code];
     Common::sendHeader($key . ' ' . $code . ' ' . $message);
 }
示例#28
0
文件: Tsv.php 项目: piwik/piwik
 public function renderSuccess($message)
 {
     Common::sendHeader("Content-Disposition: attachment; filename=piwik-report-export.csv");
     return "message\t" . $message;
 }
示例#29
0
 public function sendHeader($type = "xml")
 {
     Common::sendHeader('Content-Type: text/' . $type . '; charset=utf-8');
 }
示例#30
0
function geoipUpdateError($message)
{
    Log::error($message);
    Common::sendHeader('HTTP/1.1 500 Internal Server Error', $replace = true, $responseCode = 500);
    exit;
}