Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/ProxyHttp.php7
-rw-r--r--js/index.php31
-rw-r--r--js/tracker.php46
-rw-r--r--libs/upgradephp/upgrade.php2
-rw-r--r--tests/PHPUnit/Core/JsProxyTest.php23
-rw-r--r--tests/PHPUnit/Core/ServeStaticFileTest.php3
6 files changed, 75 insertions, 37 deletions
diff --git a/core/ProxyHttp.php b/core/ProxyHttp.php
index c500b40fdf..573164e60b 100644
--- a/core/ProxyHttp.php
+++ b/core/ProxyHttp.php
@@ -60,9 +60,11 @@ class ProxyHttp
* of the file will be served.
* @param int|false $byteEnd The ending byte in the file to serve. If false, the data from $byteStart to the
* end of the file will be served.
+ * @param string $compressedFileSuffix A suffix to append to the compressed file's name. Used to differentiate
+ * between different parts of the same file.
*/
public static function serverStaticFile($file, $contentType, $expireFarFutureDays = 100, $byteStart = false,
- $byteEnd = false)
+ $byteEnd = false, $compressedFileSuffix = false)
{
// if the file cannot be found return HTTP status code '404'
if (!file_exists($file)) {
@@ -102,7 +104,8 @@ class ProxyHttp
$compressed = false;
$encoding = '';
- $compressedFileLocation = AssetManager::getInstance()->getAssetDirectory() . '/' . basename($file);
+ $compressedFileLocation = AssetManager::getInstance()->getAssetDirectory() . '/' . basename($file)
+ . $compressedFileSuffix;
$phpOutputCompressionEnabled = self::isPhpOutputCompressed();
if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && !$phpOutputCompressionEnabled) {
diff --git a/js/index.php b/js/index.php
index 4eece69c7b..b51408b428 100644
--- a/js/index.php
+++ b/js/index.php
@@ -5,33 +5,6 @@
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
-use Piwik\ProxyHttp;
+define("PIWIK_KEEP_JS_TRACKER_COMMENT", 1);
-/**
- * Tracker proxy
- */
-if($_SERVER['REQUEST_METHOD'] == 'POST' || !empty($_SERVER['QUERY_STRING'])) {
- include '../piwik.php';
- exit;
-}
-
-/**
- * piwik.js proxy
- *
- * @see core/Piwik.php
- */
-define('PIWIK_INCLUDE_PATH', '..');
-define('PIWIK_DOCUMENT_ROOT', '..');
-define('PIWIK_USER_PATH', '..');
-
-require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php';
-require_once PIWIK_INCLUDE_PATH . '/core/Loader.php';
-
-$file = '../piwik.js';
-
-
-$daysExpireFarFuture = 10;
-
-ProxyHttp::serverStaticFile($file, "application/javascript; charset=UTF-8", $daysExpireFarFuture);
-
-exit;
+require_once __DIR__ . '/tracker.php'; \ No newline at end of file
diff --git a/js/tracker.php b/js/tracker.php
new file mode 100644
index 0000000000..55b8782f65
--- /dev/null
+++ b/js/tracker.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+use Piwik\ProxyHttp;
+
+/**
+ * Tracker proxy
+ */
+if($_SERVER['REQUEST_METHOD'] == 'POST' || !empty($_SERVER['QUERY_STRING'])) {
+ include '../piwik.php';
+ exit;
+}
+
+/**
+ * piwik.js proxy
+ *
+ * @see core/Piwik.php
+ */
+define('PIWIK_INCLUDE_PATH', '..');
+define('PIWIK_DOCUMENT_ROOT', '..');
+define('PIWIK_USER_PATH', '..');
+
+require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php';
+require_once PIWIK_INCLUDE_PATH . '/core/Loader.php';
+
+$file = '../piwik.js';
+
+$daysExpireFarFuture = 10;
+
+$compressFileSuffix = false;
+$byteStart = $byteEnd = false;
+if (!defined("PIWIK_KEEP_JS_TRACKER_COMMENT")
+ || !PIWIK_KEEP_JS_TRACKER_COMMENT
+) {
+ $byteStart = 369; // length of comment header in bytes
+ $compressFileSuffix = '.nocomment';
+}
+
+ProxyHttp::serverStaticFile($file, "application/javascript; charset=UTF-8", $daysExpireFarFuture, $byteStart, $byteEnd,
+ $compressFileSuffix);
+
+exit; \ No newline at end of file
diff --git a/libs/upgradephp/upgrade.php b/libs/upgradephp/upgrade.php
index 7d23172470..0108f72d7a 100644
--- a/libs/upgradephp/upgrade.php
+++ b/libs/upgradephp/upgrade.php
@@ -638,7 +638,7 @@ function _readfile($filename, $byteStart, $byteEnd, $useIncludePath = false, $co
}
fclose($handle);
- return $count;
+ return $byteEnd - $byteStart;
}
return false;
}
diff --git a/tests/PHPUnit/Core/JsProxyTest.php b/tests/PHPUnit/Core/JsProxyTest.php
index ff43f4b2f7..44c5bf9481 100644
--- a/tests/PHPUnit/Core/JsProxyTest.php
+++ b/tests/PHPUnit/Core/JsProxyTest.php
@@ -13,10 +13,29 @@ class Test_Piwik_JsProxy extends PHPUnit_Framework_TestCase
$responseInfo = curl_getinfo($curlHandle);
curl_close($curlHandle);
- $this->assertEquals($responseInfo["http_code"], 200, 'Ok response');
+ $this->assertEquals(200, $responseInfo["http_code"], 'Ok response');
$piwik_js = file_get_contents(PIWIK_PATH_TEST_TO_ROOT . '/piwik.js');
- $this->assertEquals($fullResponse, $piwik_js, 'script content');
+ $this->assertEquals($piwik_js, $fullResponse, 'script content');
+ }
+
+ /**
+ * @group Core
+ */
+ function testPiwikJsNoComment()
+ {
+ $curlHandle = curl_init();
+ curl_setopt($curlHandle, CURLOPT_URL, $this->getStaticSrvUrl() . '/js/tracker.php');
+ curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
+ $fullResponse = curl_exec($curlHandle);
+ $responseInfo = curl_getinfo($curlHandle);
+ curl_close($curlHandle);
+
+ $this->assertEquals(200, $responseInfo["http_code"], 'Ok response');
+
+ $piwikJs = file_get_contents(PIWIK_PATH_TEST_TO_ROOT . '/piwik.js');
+ $piwikNoCommentJs = substr($piwikJs, strpos($piwikJs, "*/\n") + 3);
+ $this->assertEquals($piwikNoCommentJs, $fullResponse, 'script content (if comment shows, $byteStart value in /js/tracker.php)');
}
/**
diff --git a/tests/PHPUnit/Core/ServeStaticFileTest.php b/tests/PHPUnit/Core/ServeStaticFileTest.php
index 42aab636d4..c6dfbd02f9 100644
--- a/tests/PHPUnit/Core/ServeStaticFileTest.php
+++ b/tests/PHPUnit/Core/ServeStaticFileTest.php
@@ -43,9 +43,6 @@ define("PARTIAL_BYTE_START", 1204);
define("PARTIAL_BYTE_END", 14724);
// If the static file server has not been requested, the standard unit test case class is defined
-/**
- * @group ServeStaticFileTest
- */
class Test_Piwik_ServeStaticFile extends PHPUnit_Framework_TestCase
{
public function tearDown()