diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/API/Renderer/Json.php | 15 | ||||
-rw-r--r-- | plugins/API/Renderer/Json2.php | 20 | ||||
-rw-r--r-- | plugins/API/tests/Unit/JsonRendererTest.php | 6 | ||||
-rw-r--r-- | plugins/CoreAdminHome/Controller.php | 2 | ||||
-rw-r--r-- | plugins/CoreHome/angularjs/common/services/piwik-api.js | 2 | ||||
-rw-r--r-- | plugins/CoreHome/angularjs/common/services/piwik-api.spec.js | 10 | ||||
-rw-r--r-- | plugins/Feedback/templates/index.twig | 2 | ||||
-rw-r--r-- | plugins/ProfessionalServices/ProfessionalServices.php | 2 |
8 files changed, 34 insertions, 25 deletions
diff --git a/plugins/API/Renderer/Json.php b/plugins/API/Renderer/Json.php index 1f7591370b..34b82b9c8a 100644 --- a/plugins/API/Renderer/Json.php +++ b/plugins/API/Renderer/Json.php @@ -16,6 +16,8 @@ use Piwik\ProxyHttp; /** * API output renderer for JSON. + * NOTE: This is the old JSON format. It includes bugs that are fixed in the JSON2 API output format. + * Please use json2 format instead of this. * * @deprecated */ @@ -57,18 +59,7 @@ class Json extends ApiRenderer $result = $jsonRenderer->render(); return $this->applyJsonpIfNeeded($result); } - - $result = $this->renderDataTable($array); - - // if $array is a simple associative array, remove the JSON root array that is added by renderDataTable - if (!empty($array) - && Piwik::isAssociativeArray($array) - && !Piwik::isMultiDimensionalArray($array) - ) { - $result = substr($result, 1, strlen($result) - 2); - } - - return $result; + return $this->renderDataTable($array); } public function sendHeader() diff --git a/plugins/API/Renderer/Json2.php b/plugins/API/Renderer/Json2.php index bd27810fb8..23f6effe0b 100644 --- a/plugins/API/Renderer/Json2.php +++ b/plugins/API/Renderer/Json2.php @@ -11,8 +11,24 @@ namespace Piwik\Plugins\API\Renderer; use Piwik\Piwik; /** - * Left here for Backward compatibility in Piwik 3.X+ for all users who correctly used format=json2 during Piwik 2.X + * Correct API output renderer for JSON. Includes bug fixes for bugs in the old JSON API + * format. */ class Json2 extends Json { -}
\ No newline at end of file + public function renderArray($array) + { + $result = parent::renderArray($array); + + // if $array is a simple associative array, remove the JSON root array that is added by renderDataTable + if (!empty($array) + && Piwik::isAssociativeArray($array) + && !Piwik::isMultiDimensionalArray($array) + ) { + $result = substr($result, 1, strlen($result) - 2); + } + + return $result; + } +} + diff --git a/plugins/API/tests/Unit/JsonRendererTest.php b/plugins/API/tests/Unit/JsonRendererTest.php index ea7f5d69d4..d71d7068ef 100644 --- a/plugins/API/tests/Unit/JsonRendererTest.php +++ b/plugins/API/tests/Unit/JsonRendererTest.php @@ -356,14 +356,14 @@ class JsonRendererTest extends \PHPUnit_Framework_TestCase $this->assertNoJsonError($actual); } - public function test_json_renderArray_ShouldConvertSingleDimensionalAssociativeArray() + public function test_oldJson_renderArray_ShouldConvertSingleDimensionalAssociativeArray() { $input = array( "firstElement" => "isFirst", "secondElement" => "isSecond" ); - $expected = '{"firstElement":"isFirst","secondElement":"isSecond"}'; + $expected = '[{"firstElement":"isFirst","secondElement":"isSecond"}]'; $oldJsonBuilder = new Json($input); $actual = $oldJsonBuilder->renderArray($input); @@ -373,7 +373,7 @@ class JsonRendererTest extends \PHPUnit_Framework_TestCase private function makeBuilder($request) { - return new Json($request); + return new Json2($request); } private function assertNoJsonError($response) diff --git a/plugins/CoreAdminHome/Controller.php b/plugins/CoreAdminHome/Controller.php index 3531623eef..7621aa1f78 100644 --- a/plugins/CoreAdminHome/Controller.php +++ b/plugins/CoreAdminHome/Controller.php @@ -114,7 +114,7 @@ class Controller extends ControllerAdmin return ''; } - $response = new ResponseBuilder('json'); + $response = new ResponseBuilder('json2'); try { $this->checkTokenInUrl(); diff --git a/plugins/CoreHome/angularjs/common/services/piwik-api.js b/plugins/CoreHome/angularjs/common/services/piwik-api.js index ab6ee9c30d..ab546a7693 100644 --- a/plugins/CoreHome/angularjs/common/services/piwik-api.js +++ b/plugins/CoreHome/angularjs/common/services/piwik-api.js @@ -249,7 +249,7 @@ var hasBlockedContent = false; getParams.module = getParams.module || 'API'; if (!getParams.format) { - getParams.format = 'JSON'; + getParams.format = 'JSON2'; } addParams(getParams); diff --git a/plugins/CoreHome/angularjs/common/services/piwik-api.spec.js b/plugins/CoreHome/angularjs/common/services/piwik-api.spec.js index a51067ea46..1faf387ea3 100644 --- a/plugins/CoreHome/angularjs/common/services/piwik-api.spec.js +++ b/plugins/CoreHome/angularjs/common/services/piwik-api.spec.js @@ -55,7 +55,7 @@ piwikApi.fetch({ method: "SomePlugin.action" }).then(function (response) { - expect(response).to.equal("Request url: index.php?date=&format=JSON&idSite=1&method=SomePlugin.action&module=API&period=day"); + expect(response).to.equal("Request url: index.php?date=&format=JSON2&idSite=1&method=SomePlugin.action&module=API&period=day"); done(); }).catch(function (ex) { @@ -115,7 +115,7 @@ piwikApi.fetch({ method: "SomePlugin.action" }).then(function (response) { - expect(response).to.equal("Request url: index.php?date=&format=JSON&idSite=1&method=SomePlugin.action&module=API&period=day"); + expect(response).to.equal("Request url: index.php?date=&format=JSON2&idSite=1&method=SomePlugin.action&module=API&period=day"); request1Done = true; @@ -127,7 +127,7 @@ piwikApi.fetch({ method: "SomeOtherPlugin.action" }).then(function (response) { - expect(response).to.equal("Request url: index.php?date=&format=JSON&idSite=1&method=SomeOtherPlugin.action&module=API&period=day"); + expect(response).to.equal("Request url: index.php?date=&format=JSON2&idSite=1&method=SomeOtherPlugin.action&module=API&period=day"); request2Done = true; @@ -160,7 +160,7 @@ piwikApi.fetch({ method: "SomeOtherPlugin.action" }).then(function (response) { - expect(response).to.equal("Request url: index.php?date=&format=JSON&idSite=1&method=SomeOtherPlugin.action&module=API&period=day"); + expect(response).to.equal("Request url: index.php?date=&format=JSON2&idSite=1&method=SomeOtherPlugin.action&module=API&period=day"); request2Done = true; @@ -216,7 +216,7 @@ method: "SomeOtherPlugin.action" } ]).then(function (response) { - var restOfExpected = "index.php?date=&format=JSON&idSite=1&method=API.getBulkRequest&" + + var restOfExpected = "index.php?date=&format=JSON2&idSite=1&method=API.getBulkRequest&" + "module=API&period=day - urls%5B%5D=%3Fmethod%3DSomePlugin.action%26param%3D" + "value&urls%5B%5D=%3Fmethod%3DSomeOtherPlugin.action&token_auth=100bf5eeeed1468f3f9d93750044d3dd"; diff --git a/plugins/Feedback/templates/index.twig b/plugins/Feedback/templates/index.twig index 274b136cd9..b729b6b96f 100644 --- a/plugins/Feedback/templates/index.twig +++ b/plugins/Feedback/templates/index.twig @@ -59,6 +59,8 @@ <p>Grow your business, understand your audience better and increase your sales and conversions with a premium plugin for Piwik: <p> • <a rel='noreferrer' target='_blank' href='https://piwik.org/recommends/ab-testing-learn-more/'>A/B Testing Platform for Piwik Analytics</a>. </p> + <p> • <a rel='noreferrer' target='_blank' href='https://plugins.piwik.org/Funnels'>Conversion Funnels</a>. + </p> <p> • <a rel='noreferrer' target='_blank' href='https://piwik.org/recommends/media-analytics-website/'>Powerful Video Analytics and Audio Analytics</a>. </p> <p> • <a rel='noreferrer' target='_blank' href='https://piwik.org/recommends/activity-log/'>Audit log of user activities happening in your Piwik</a>. diff --git a/plugins/ProfessionalServices/ProfessionalServices.php b/plugins/ProfessionalServices/ProfessionalServices.php index dab1c2af2d..2dd0811b6b 100644 --- a/plugins/ProfessionalServices/ProfessionalServices.php +++ b/plugins/ProfessionalServices/ProfessionalServices.php @@ -65,7 +65,7 @@ class ProfessionalServices extends \Piwik\Plugin $out .= ' <p style="margin-top:3em" class=" alert-info alert">Did you know? - With <a target="_blank" rel="noreferrer" href="https://piwik.org/recommends/ab-testing-learn-more/">A/B Testing for Piwik</a> you can immediately increase conversions and sales by creating different versions of a page to see which grows your business. + With <a target="_blank" rel="noreferrer" href="https://piwik.org/recommends/ab-testing-learn-more/">A/B Testing for Piwik</a> you can immediately increase conversions and sales by creating different versions of a page to see which one grows your business. </p> '; } |