diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ac4762..e35dedc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.1.4 + +- Confirmed Matomo 4 compliance. + ## 1.1.3 - Better scoped the widget styles. @@ -24,4 +28,4 @@ ## 1.0 -- Initial Release. \ No newline at end of file +- Initial Release. diff --git a/Widgets/GetMozInfo.php b/Widgets/GetMozInfo.php index af96ffd..baea012 100644 --- a/Widgets/GetMozInfo.php +++ b/Widgets/GetMozInfo.php @@ -26,62 +26,64 @@ * To configure a widget simply call the corresponding methods as described in the API-Reference: * http://developer.piwik.org/api-reference/Piwik/Plugin\Widget */ -class GetMozInfo extends Widget{ - - /** - * @var SettingsProvider - */ +class GetMozInfo extends Widget +{ + /** + * @var SettingsProvider + */ private $settingsProvider; - public function __construct(SettingsProvider $settingsProvider) - { - $this->settingsProvider = $settingsProvider; - } + public function __construct(SettingsProvider $settingsProvider) + { + $this->settingsProvider = $settingsProvider; + } - public static function configure(WidgetConfig $config){ - /** - * Set the category the widget belongs to. You can reuse any existing widget category or define - * your own category. - */ - $config->setCategoryId('SEO'); + public static function configure(WidgetConfig $config) + { + /** + * Set the category the widget belongs to. You can reuse any existing widget category or define + * your own category. + */ + $config->setCategoryId('SEO'); - /** - * Set the subcategory the widget belongs to. If a subcategory is set, the widget will be shown in the UI. - */ - // $config->setSubcategoryId('General_Overview'); + /** + * Set the subcategory the widget belongs to. If a subcategory is set, the widget will be shown in the UI. + */ + // $config->setSubcategoryId('General_Overview'); - /** - * Set the name of the widget belongs to. - */ - $config->setName('MozWidgetByAmperage_MozCom'); + /** + * Set the name of the widget belongs to. + */ + $config->setName('MozWidgetByAmperage_MozCom'); - /** - * Set the order of the widget. The lower the number, the earlier the widget will be listed within a category. - */ - $config->setOrder(50); + /** + * Set the order of the widget. The lower the number, the earlier the widget will be listed within a category. + */ + $config->setOrder(50); - /** - * Optionally set URL parameters that will be used when this widget is requested. - * $config->setParameters(array('myparam' => 'myvalue')); - */ + /** + * Optionally set URL parameters that will be used when this widget is requested. + * $config->setParameters(array('myparam' => 'myvalue')); + */ - /** - * Define whether a widget is enabled or not. For instance some widgets might not be available to every user or - * might depend on a setting (such as Ecommerce) of a site. In such a case you can perform any checks and then - * set `true` or `false`. If your widget is only available to users having super user access you can do the - * following: - * - * $config->setIsEnabled(\Piwik\Piwik::hasUserSuperUserAccess()); - * or - * if (!\Piwik\Piwik::hasUserSuperUserAccess()) - * $config->disable(); - */ - } + /** + * Define whether a widget is enabled or not. For instance some widgets might not be available to every user or + * might depend on a setting (such as Ecommerce) of a site. In such a case you can perform any checks and then + * set `true` or `false`. If your widget is only available to users having super user access you can do the + * following: + * + * $config->setIsEnabled(\Piwik\Piwik::hasUserSuperUserAccess()); + * or + * if (!\Piwik\Piwik::hasUserSuperUserAccess()) + * $config->disable(); + */ + } - public function amp_get_contents($url){ - if(ini_get('allow_url_fopen')){ + public function amp_get_contents($url) + { + if (ini_get('allow_url_fopen')) { return file_get_contents($url); - }else{ + } else { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); @@ -90,19 +92,19 @@ public function amp_get_contents($url){ curl_close($curl); return $output; } - } - - /** - * This method renders the widget. It's on you how to generate the content of the widget. - * As long as you return a string everything is fine. You can use for instance a "Piwik\View" to render a - * twig template. In such a case don't forget to create a twig template (eg. myViewTemplate.twig) in the - * "templates" directory of your plugin. - * - * @return string - */ - public function render(){ - try { + } + /** + * This method renders the widget. It's on you how to generate the content of the widget. + * As long as you return a string everything is fine. You can use for instance a "Piwik\View" to render a + * twig template. In such a case don't forget to create a twig template (eg. myViewTemplate.twig) in the + * "templates" directory of your plugin. + * + * @return string + */ + public function render() + { + try { $debug_help = false; // Toggle whether the Moz API helper text should be shown $debug_siteurl = false; // Toggle the site URL being checked for at Moz $debug_api = false; // Toggle whether the raw Moz API results should be shown @@ -122,13 +124,14 @@ public function render(){ $idSite = Common::getRequestVar('idSite'); $measurableSettings = $this->settingsProvider->getMeasurableSettings('MozWidgetByAmperage', $idSite); $report_url = $measurableSettings->mozCustomReportURLSetting->getValue(); - if(isset($report_url) && $report_url !== ''){ - $output.= '
'; + if (isset($report_url) && $report_url !== '') { + $output .= ''; } - if($api_key == '' || $secret == ''){ - $output.= 'You first need to configure the Moz.com API Keys in your user settings.
'; - }else{ // API Keys have been provided + if ($api_key == '' || $secret == '') { + $output .= 'You first need to configure the Moz.com API Keys in your user settings.
'; + } else { + // API Keys have been provided // Get the site's URL from Piwik $idSite = Common::getRequestVar('idSite'); @@ -140,21 +143,21 @@ public function render(){ if (empty($siteurlurl) || !UrlHelper::isLookLikeUrl($siteurl)) { $siteurl = $site->getMainUrl(); } - $siteurl = str_replace('https://','',str_replace('http://','',$siteurl)); // Strip both http:// and https:// from the URL being checked + $siteurl = str_replace('https://', '', str_replace('http://', '', $siteurl)); // Strip both http:// and https:// from the URL being checked - if($debug_help){ - $output.= 'This is where the Moz API data should be shown (documented at https://moz.com/products/api)
'; + if ($debug_help) { + $output .= 'This is where the Moz API data should be shown (documented at https://moz.com/products/api)
'; } - if($debug_siteurl){ - $output.= 'Site URL: '.$siteurl.'
Site URL: ' . $siteurl . '
';print_r($content);echo ''; + $content = json_decode($content, true); + if ($debug_api) { + echo '
'; + print_r($content); + echo ''; } - $output.= '