diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-03-28 03:42:39 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-03-28 03:42:40 +0400 |
commit | ae4b03163792f0b6e933933e5d37df87dc3fd566 (patch) | |
tree | d1d7510a9728f587d3d63ebd03e4ecf3d904838b /plugins/Proxy | |
parent | 158c2150f5f2e13ece459b8d131244c11b763997 (diff) |
Mass conversion of all files to the newly agreed coding standard: PSR 1/2
Converting Piwik core source files, PHP, JS, TPL, CSS
More info: http://piwik.org/participate/coding-standards/
Diffstat (limited to 'plugins/Proxy')
-rw-r--r-- | plugins/Proxy/Controller.php | 313 | ||||
-rw-r--r-- | plugins/Proxy/Proxy.php | 38 | ||||
-rw-r--r-- | plugins/Proxy/templates/exportImage.tpl | 19 |
3 files changed, 180 insertions, 190 deletions
diff --git a/plugins/Proxy/Controller.php b/plugins/Proxy/Controller.php index 5681f6db0d..12e8435703 100644 --- a/plugins/Proxy/Controller.php +++ b/plugins/Proxy/Controller.php @@ -1,10 +1,10 @@ <?php /** * Piwik - Open source web analytics - * + * * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * + * * @category Piwik_Plugins * @package Piwik_Proxy */ @@ -15,167 +15,156 @@ * @package Piwik_Proxy */ class Piwik_Proxy_Controller extends Piwik_Controller -{ - const TRANSPARENT_PNG_PIXEL = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII='; - - /** - * Display the "Export Image" window. - * - * @deprecated 1.5.1 - * - * @param string $imageData Base-64 encoded image data (via $_POST) - */ - static public function exportImageWindow() - { - Piwik::checkUserHasSomeViewAccess(); - - $view = Piwik_View::factory('exportImage'); - $view->imageData = 'data:image/png;base64,'. Piwik_Common::getRequestVar('imageData', self::TRANSPARENT_PNG_PIXEL, 'string', $_POST); - echo $view->render(); - } - - function exportImage() - { - self::exportImageWindow(); - } - - /** - * Output binary image from base-64 encoded data. - * - * @deprecated 1.5.1 - * - * @param string $imageData Base-64 encoded image data (via $_POST) - */ - static public function outputBinaryImage() - { - Piwik::checkUserHasSomeViewAccess(); - - $rawData = Piwik_Common::getRequestVar('imageData', '', 'string', $_POST); - - // returns false if any illegal characters in input - $data = base64_decode($rawData); - if($data !== false) - { - // check for PNG header - if(Piwik_Common::substr($data, 0, 8) === "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a") - { - header('Content-Type: image/png'); - - // more robust validation (if available) - if(function_exists('imagecreatefromstring')) - { - // validate image data - $imgResource = @imagecreatefromstring($data); - if($imgResource !== false) - { - // output image and clean-up - imagepng($imgResource); - imagedestroy($imgResource); - exit; - } - } - else - { - echo $data; - exit; - } - } - } - - Piwik::setHttpStatus('400 Bad Request'); - exit; - } - - function outputImage() - { - self::outputBinaryImage(); - } - - /** - * Output the merged CSS file. - * This method is called when the asset manager is enabled. - * - * @see core/AssetManager.php - */ - public function getCss() - { - $cssMergedFile = Piwik_AssetManager::getMergedCssFileLocation(); - Piwik::serveStaticFile($cssMergedFile, "text/css"); - } - - /** - * Output the merged JavaScript file. - * This method is called when the asset manager is enabled. - * - * @see core/AssetManager.php - */ - public function getJs() - { - $jsMergedFile = Piwik_AssetManager::getMergedJsFileLocation(); - Piwik::serveStaticFile($jsMergedFile, "application/javascript; charset=UTF-8"); - } - - /** - * Output redirection page instead of linking directly to avoid - * exposing the referrer on the Piwik demo. - * - * @param string $url (via $_GET) - */ - public function redirect() - { - $url = Piwik_Common::getRequestVar('url', '', 'string', $_GET); - - // validate referrer - $referrer = Piwik_Url::getReferer(); - if(empty($referrer) || !Piwik_Url::isLocalUrl($referrer)) - { - die('Invalid Referer detected - This means that your web browser is not sending the "Referer URL" which is +{ + const TRANSPARENT_PNG_PIXEL = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII='; + + /** + * Display the "Export Image" window. + * + * @deprecated 1.5.1 + * + * @param string $imageData Base-64 encoded image data (via $_POST) + */ + static public function exportImageWindow() + { + Piwik::checkUserHasSomeViewAccess(); + + $view = Piwik_View::factory('exportImage'); + $view->imageData = 'data:image/png;base64,' . Piwik_Common::getRequestVar('imageData', self::TRANSPARENT_PNG_PIXEL, 'string', $_POST); + echo $view->render(); + } + + function exportImage() + { + self::exportImageWindow(); + } + + /** + * Output binary image from base-64 encoded data. + * + * @deprecated 1.5.1 + * + * @param string $imageData Base-64 encoded image data (via $_POST) + */ + static public function outputBinaryImage() + { + Piwik::checkUserHasSomeViewAccess(); + + $rawData = Piwik_Common::getRequestVar('imageData', '', 'string', $_POST); + + // returns false if any illegal characters in input + $data = base64_decode($rawData); + if ($data !== false) { + // check for PNG header + if (Piwik_Common::substr($data, 0, 8) === "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a") { + header('Content-Type: image/png'); + + // more robust validation (if available) + if (function_exists('imagecreatefromstring')) { + // validate image data + $imgResource = @imagecreatefromstring($data); + if ($imgResource !== false) { + // output image and clean-up + imagepng($imgResource); + imagedestroy($imgResource); + exit; + } + } else { + echo $data; + exit; + } + } + } + + Piwik::setHttpStatus('400 Bad Request'); + exit; + } + + function outputImage() + { + self::outputBinaryImage(); + } + + /** + * Output the merged CSS file. + * This method is called when the asset manager is enabled. + * + * @see core/AssetManager.php + */ + public function getCss() + { + $cssMergedFile = Piwik_AssetManager::getMergedCssFileLocation(); + Piwik::serveStaticFile($cssMergedFile, "text/css"); + } + + /** + * Output the merged JavaScript file. + * This method is called when the asset manager is enabled. + * + * @see core/AssetManager.php + */ + public function getJs() + { + $jsMergedFile = Piwik_AssetManager::getMergedJsFileLocation(); + Piwik::serveStaticFile($jsMergedFile, "application/javascript; charset=UTF-8"); + } + + /** + * Output redirection page instead of linking directly to avoid + * exposing the referrer on the Piwik demo. + * + * @param string $url (via $_GET) + */ + public function redirect() + { + $url = Piwik_Common::getRequestVar('url', '', 'string', $_GET); + + // validate referrer + $referrer = Piwik_Url::getReferer(); + if (empty($referrer) || !Piwik_Url::isLocalUrl($referrer)) { + die('Invalid Referer detected - This means that your web browser is not sending the "Referer URL" which is required to proceed with the redirect. Verify your browser settings and add-ons, to check why your browser is not sending this referer. - <br/><br/>You can access the page at: '. $url); - } - - // mask visits to *.piwik.org - if (!self::isPiwikUrl($url)) - { - Piwik::checkUserHasSomeViewAccess(); - } - if(!Piwik_Common::isLookLikeUrl($url)) - { - die('Please check the &url= parameter: it should to be a valid URL'); - } - @header('Content-Type: text/html; charset=utf-8'); - echo '<html><head><meta http-equiv="refresh" content="0;url=' . $url . '" /></head></html>'; - - exit; - } - - /** - * Validate URL against *.piwik.org domains - * - * @param string $url - * @return bool True if valid; false otherwise - */ - static public function isPiwikUrl($url) - { - // guard for IE6 meta refresh parsing weakness (OSVDB 19029) - if(strpos($url, ';') !== false - || strpos($url, ';') !== false) - { - return false; - } - if(preg_match('~^http://(qa\.|demo\.|dev\.|forum\.)?piwik.org([#?/]|$)~', $url)) - { - return true; - } - - // Allow clockworksms domain - if(strpos($url, 'http://www.clockworksms.com/') === 0) - { - return true; - } - - return false; - } + <br/><br/>You can access the page at: ' . $url); + } + + // mask visits to *.piwik.org + if (!self::isPiwikUrl($url)) { + Piwik::checkUserHasSomeViewAccess(); + } + if (!Piwik_Common::isLookLikeUrl($url)) { + die('Please check the &url= parameter: it should to be a valid URL'); + } + @header('Content-Type: text/html; charset=utf-8'); + echo '<html><head><meta http-equiv="refresh" content="0;url=' . $url . '" /></head></html>'; + + exit; + } + + /** + * Validate URL against *.piwik.org domains + * + * @param string $url + * @return bool True if valid; false otherwise + */ + static public function isPiwikUrl($url) + { + // guard for IE6 meta refresh parsing weakness (OSVDB 19029) + if (strpos($url, ';') !== false + || strpos($url, ';') !== false + ) { + return false; + } + if (preg_match('~^http://(qa\.|demo\.|dev\.|forum\.)?piwik.org([#?/]|$)~', $url)) { + return true; + } + + // Allow clockworksms domain + if (strpos($url, 'http://www.clockworksms.com/') === 0) { + return true; + } + + return false; + } } diff --git a/plugins/Proxy/Proxy.php b/plugins/Proxy/Proxy.php index 619c388644..c669215411 100644 --- a/plugins/Proxy/Proxy.php +++ b/plugins/Proxy/Proxy.php @@ -1,10 +1,10 @@ <?php /** * Piwik - Open source web analytics - * + * * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * + * * @category Piwik_Plugins * @package Piwik_Proxy */ @@ -16,21 +16,21 @@ */ class Piwik_Proxy extends Piwik_Plugin { - /** - * Return information about this plugin. - * - * @see Piwik_Plugin - * - * @return array - */ - public function getInformation() - { - return array( - 'description' => 'Proxy services', - 'author' => 'Piwik', - 'author_homepage' => 'http://piwik.org/', - 'version' => Piwik_Version::VERSION, - 'translationAvailable' => false, - ); - } + /** + * Return information about this plugin. + * + * @see Piwik_Plugin + * + * @return array + */ + public function getInformation() + { + return array( + 'description' => 'Proxy services', + 'author' => 'Piwik', + 'author_homepage' => 'http://piwik.org/', + 'version' => Piwik_Version::VERSION, + 'translationAvailable' => false, + ); + } } diff --git a/plugins/Proxy/templates/exportImage.tpl b/plugins/Proxy/templates/exportImage.tpl index 037b0b8fd8..451b5dedb6 100644 --- a/plugins/Proxy/templates/exportImage.tpl +++ b/plugins/Proxy/templates/exportImage.tpl @@ -1,12 +1,13 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" /> + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" /> <html xmlns="http://www.w3.org/1999/xhtml"> - <head> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> - <title>{'General_ExportAsImage_js'|translate}</title> - </head> - <body> - <img title="Piwik Graph" src="{$imageData}" /><br /><br /> - <p>{'General_SaveImageOnYourComputer_js'|translate}</p> - </body> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> + <title>{'General_ExportAsImage_js'|translate}</title> +</head> +<body> +<img title="Piwik Graph" src="{$imageData}"/><br/><br/> + +<p>{'General_SaveImageOnYourComputer_js'|translate}</p> +</body> </html> |