From cfab30a42caeb822357998c69c4d28d2161b6233 Mon Sep 17 00:00:00 2001 From: Thomas Steur <thomas.steur@gmail.com> Date: Thu, 28 Jan 2016 23:13:56 +0000 Subject: [PATCH] fixes #9650 new widget showing piwik pro blog --- config/global.ini.php | 1 + core/PiwikPro/Advertising.php | 1 + core/WidgetsList.php | 2 +- plugins/CoreHome/Widgets.php | 2 +- plugins/ExampleRssWidget/Widgets.php | 2 +- plugins/PiwikPro/PiwikPro.php | 13 ++++ plugins/PiwikPro/Widgets.php | 60 +++++++++++++++++++ plugins/PiwikPro/lang/en.json | 5 ++ plugins/PiwikPro/plugin.json | 5 ++ plugins/Widgetize/tests/System/WidgetTest.php | 22 +++++++ tests/PHPUnit/Integration/WidgetsListTest.php | 2 +- 11 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 plugins/PiwikPro/PiwikPro.php create mode 100644 plugins/PiwikPro/Widgets.php create mode 100644 plugins/PiwikPro/lang/en.json create mode 100644 plugins/PiwikPro/plugin.json diff --git a/config/global.ini.php b/config/global.ini.php index 88dfe74664..fd9ef2d649 100644 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -795,6 +795,7 @@ Plugins[] = Resolution Plugins[] = DevicePlugins Plugins[] = Heartbeat Plugins[] = Intl +Plugins[] = PiwikPro [PluginsInstalled] PluginsInstalled[] = Diagnostics diff --git a/core/PiwikPro/Advertising.php b/core/PiwikPro/Advertising.php index f17011ee7c..dcb94c6fc1 100644 --- a/core/PiwikPro/Advertising.php +++ b/core/PiwikPro/Advertising.php @@ -15,6 +15,7 @@ use Piwik\Config; * links for differnt landing pages etc. * * @api + * @since 2.16.0 */ class Advertising { diff --git a/core/WidgetsList.php b/core/WidgetsList.php index e91a0f2b38..8380d7a1ee 100644 --- a/core/WidgetsList.php +++ b/core/WidgetsList.php @@ -147,7 +147,7 @@ class WidgetsList extends Singleton 'Goals_Goals', 'Goals_Ecommerce', '_others_', - 'Example Widgets', + 'About Piwik', 'ExamplePlugin_exampleWidgets', ); diff --git a/plugins/CoreHome/Widgets.php b/plugins/CoreHome/Widgets.php index 17d888bd35..1a2c945bff 100644 --- a/plugins/CoreHome/Widgets.php +++ b/plugins/CoreHome/Widgets.php @@ -15,7 +15,7 @@ use Piwik\View; class Widgets extends \Piwik\Plugin\Widgets { - protected $category = 'Example Widgets'; + protected $category = 'About Piwik'; /** * @var Translator diff --git a/plugins/ExampleRssWidget/Widgets.php b/plugins/ExampleRssWidget/Widgets.php index 5fc0667fa8..e0d67cdd9f 100644 --- a/plugins/ExampleRssWidget/Widgets.php +++ b/plugins/ExampleRssWidget/Widgets.php @@ -12,7 +12,7 @@ use Piwik\Piwik; class Widgets extends \Piwik\Plugin\Widgets { - protected $category = 'Example Widgets'; + protected $category = 'About Piwik'; protected function init() { diff --git a/plugins/PiwikPro/PiwikPro.php b/plugins/PiwikPro/PiwikPro.php new file mode 100644 index 0000000000..1bb25a9482 --- /dev/null +++ b/plugins/PiwikPro/PiwikPro.php @@ -0,0 +1,13 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\PiwikPro; + +class PiwikPro extends \Piwik\Plugin +{ +} diff --git a/plugins/PiwikPro/Widgets.php b/plugins/PiwikPro/Widgets.php new file mode 100644 index 0000000000..89308240e7 --- /dev/null +++ b/plugins/PiwikPro/Widgets.php @@ -0,0 +1,60 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\PiwikPro; + +use Piwik\Piwik; +use Piwik\PiwikPro\Advertising; +use Piwik\Plugins\ExampleRssWidget\RssRenderer; + +class Widgets extends \Piwik\Plugin\Widgets +{ + protected $category = 'About Piwik'; + + /** + * @var Advertising + */ + private $advertising; + + public function __construct(Advertising $advertising) + { + $this->advertising = $advertising; + } + + protected function init() + { + if ($this->advertising->arePiwikProAdsEnabled()) { + $this->addWidget('PiwikPro_WidgetBlogTitle', 'rssPiwikPro'); + } + } + + public function rssPiwikPro() + { + try { + $rss = new RssRenderer('https://piwik.pro/feed/'); + $rss->showDescription(true); + + return $rss->get(); + + } catch (\Exception $e) { + + return $this->error($e); + } + } + + /** + * @param \Exception $e + * @return string + */ + private function error($e) + { + return '<div class="pk-emptyDataTable">' + . Piwik::translate('General_ErrorRequest', array('', '')) + . ' - ' . $e->getMessage() . '</div>'; + } +} diff --git a/plugins/PiwikPro/lang/en.json b/plugins/PiwikPro/lang/en.json new file mode 100644 index 0000000000..cafc7b4add --- /dev/null +++ b/plugins/PiwikPro/lang/en.json @@ -0,0 +1,5 @@ +{ + "PiwikPro": { + "WidgetBlogTitle": "Piwik PRO Blog" + } +} \ No newline at end of file diff --git a/plugins/PiwikPro/plugin.json b/plugins/PiwikPro/plugin.json new file mode 100644 index 0000000000..f7a302dafb --- /dev/null +++ b/plugins/PiwikPro/plugin.json @@ -0,0 +1,5 @@ +{ + "name": "PiwikPro", + "description": "Provides widgets to follow Piwik PRO blog and to see info about their products.", + "theme": false +} \ No newline at end of file diff --git a/plugins/Widgetize/tests/System/WidgetTest.php b/plugins/Widgetize/tests/System/WidgetTest.php index d2d6ec3260..4573b708b1 100644 --- a/plugins/Widgetize/tests/System/WidgetTest.php +++ b/plugins/Widgetize/tests/System/WidgetTest.php @@ -13,6 +13,7 @@ use Piwik\Http\ControllerResolver; use Piwik\Piwik; use Piwik\Plugins\Goals; use Piwik\Plugins\Widgetize\tests\Fixtures\WidgetizeFixture; +use Piwik\Tests\Framework\Mock\PiwikPro\Advertising; use Piwik\Tests\Framework\TestCase\SystemTestCase; use Piwik\WidgetsList; @@ -835,9 +836,30 @@ class WidgetTest extends SystemTestCase 'action' => 'rssChangelog', ), ), + array ( + 'name' => 'Piwik PRO Blog', + 'uniqueId' => 'widgetPiwikProrssPiwikPro', + 'parameters' => + array ( + 'module' => 'PiwikPro', + 'action' => 'rssPiwikPro', + ), + ) ); } + /** + * Use this method to return custom container configuration that you want to apply for the tests. + * This configuration will override Fixture config. + * + * @return array + */ + public static function provideContainerConfigBeforeClass() + { + return array( + 'Piwik\PiwikPro\Advertising' => new Advertising() + ); + } } diff --git a/tests/PHPUnit/Integration/WidgetsListTest.php b/tests/PHPUnit/Integration/WidgetsListTest.php index f741f813f3..80a77e5a93 100644 --- a/tests/PHPUnit/Integration/WidgetsListTest.php +++ b/tests/PHPUnit/Integration/WidgetsListTest.php @@ -46,7 +46,7 @@ class WidgetsListTest extends IntegrationTestCase 'Referrers_Referrers' => 7, 'Goals_Goals' => 1, 'SEO' => 2, - 'Example Widgets' => 4, + 'About Piwik' => 5, 'DevicesDetection_DevicesDetection' => 8, 'Insights_WidgetCategory' => 2 ); -- GitLab