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.= '

View Latest Custom Report

'; + if (isset($report_url) && $report_url !== '') { + $output .= '

View Latest Custom Report

'; } - 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.'

'; + if ($debug_siteurl) { + $output .= '

Site URL: ' . $siteurl . '

'; } // Set your expires times for several minutes into the future. // An expires time excessively far in the future will not be honored by the Mozscape API. $expires = time() + 300; // Put each parameter on a new line. - $stringToSign = $api_key."\n".$expires; + $stringToSign = $api_key . "\n" . $expires; // Get the "raw" or binary output of the hmac hash. $binarySignature = hash_hmac('sha1', $stringToSign, $secret, true); // Base64-encode it and then url-encode that. @@ -164,144 +167,141 @@ public function render(){ $cols = "141421025689597"; // Put it all together and you get your request URL. // This example uses the Mozscape URL Metrics API. - $requestUrl = "https://lsapi.seomoz.com/linkscape/url-metrics/".urlencode($siteurl)."?Cols=".$cols."&AccessID=".$api_key."&Expires=".$expires."&Signature=".$urlSafeSignature; + $requestUrl = "https://lsapi.seomoz.com/linkscape/url-metrics/" . urlencode($siteurl) . "?Cols=" . $cols . "&AccessID=" . $api_key . "&Expires=" . $expires . "&Signature=" . $urlSafeSignature; $content = $this->amp_get_contents($requestUrl); - $content = json_decode($content,true); - if($debug_api){ - echo '
';print_r($content);echo '
'; + $content = json_decode($content, true); + if ($debug_api) { + echo '
';
+					print_r($content);
+					echo '
'; } - $output.= '
'; - if(isset($content['ut']) && $content['ut'] !== ''){ - $output.= '
Homepage Title
'.$content['ut'].'
'; + $output .= '
'; + if (isset($content['ut']) && $content['ut'] !== '') { + $output .= '
Homepage Title
' . $content['ut'] . '
'; } - if(isset($content['uu'])){ - $output.= '
Canonical URL
'.$content['uu'].'
'; + if (isset($content['uu'])) { + $output .= '
Canonical URL
' . $content['uu'] . '
'; } - if(isset($content['ufq'])){ - $output.= '
Subdomain
'.$content['ufq'].'
'; + if (isset($content['ufq'])) { + $output .= '
Subdomain
' . $content['ufq'] . '
'; } - if(isset($content['upl'])){ - $output.= '
Root Domain
'.$content['upl'].'
'; + if (isset($content['upl'])) { + $output .= '
Root Domain
' . $content['upl'] . '
'; } - if(isset($content['upa'])){ - $output.= '
Homepage Authority
'.number_format($content['upa']).' / 100
'; + if (isset($content['upa'])) { + $output .= '
Homepage Authority
' . number_format($content['upa']) . ' / 100
'; } - if(isset($content['pda'])){ - $output.= '
Domain Authority
'.number_format($content['pda']).' / 100
'; + if (isset($content['pda'])) { + $output .= '
Domain Authority
' . number_format($content['pda']) . ' / 100
'; } - if(isset($content['ueid'])){ - $output.= '
Homepage External Equity Links
'.number_format($content['ueid']).'
'; + if (isset($content['ueid'])) { + $output .= '
Homepage External Equity Links
' . number_format($content['ueid']) . '
'; } - if(isset($content['feid'])){ - $output.= '
Subdomain External Links
'.number_format($content['feid']).'
'; + if (isset($content['feid'])) { + $output .= '
Subdomain External Links
' . number_format($content['feid']) . '
'; } - if(isset($content['peid'])){ - $output.= '
Root Domain External Links
'.number_format($content['peid']).'
'; + if (isset($content['peid'])) { + $output .= '
Root Domain External Links
' . number_format($content['peid']) . '
'; } - if(isset($content['ujid'])){ - $output.= '
Equity Links
'.number_format($content['ujid']).'
'; + if (isset($content['ujid'])) { + $output .= '
Equity Links
' . number_format($content['ujid']) . '
'; } - if(isset($content['uifq'])){ - $output.= '
Subdomains Linking
'.number_format($content['uifq']).'
'; + if (isset($content['uifq'])) { + $output .= '
Subdomains Linking
' . number_format($content['uifq']) . '
'; } - if(isset($content['uipl'])){ - $output.= '
Root Domains Linking
'.number_format($content['uipl']).'
'; + if (isset($content['uipl'])) { + $output .= '
Root Domains Linking
' . number_format($content['uipl']) . '
'; } - if(isset($content['fid'])){ - $output.= '
Subdomain, Subdomains Linking
'.number_format($content['fid']).'
'; + if (isset($content['fid'])) { + $output .= '
Subdomain, Subdomains Linking
' . number_format($content['fid']) . '
'; } - if(isset($content['pid'])){ - $output.= '
Root Domain, Root Domains Linking
'.number_format($content['pid']).'
'; + if (isset($content['pid'])) { + $output .= '
Root Domain, Root Domains Linking
' . number_format($content['pid']) . '
'; } - if(isset($content['umrp'])){ - $output.= '
MozRank: Homepage
'.number_format(round($content['umrp'],1)).' / 10
'; + if (isset($content['umrp'])) { + $output .= '
MozRank: Homepage
' . number_format(round($content['umrp'], 1)) . ' / 10
'; } - if(isset($content['fmrp'])){ - $output.= '
MozRank: Subdomain
'.number_format(round($content['fmrp'],1)).' / 10
'; + if (isset($content['fmrp'])) { + $output .= '
MozRank: Subdomain
' . number_format(round($content['fmrp'], 1)) . ' / 10
'; } - if(isset($content['pmrp'])){ - $output.= '
MozRank: Root Domain
'.number_format(round($content['pmrp'],1)).' / 10
'; + if (isset($content['pmrp'])) { + $output .= '
MozRank: Root Domain
' . number_format(round($content['pmrp'], 1)) . ' / 10
'; } - if(isset($content['utrp'])){ - $output.= '
MozTrust: Homepage
'.number_format(round($content['utrp'],1)).' / 10
'; + if (isset($content['utrp'])) { + $output .= '
MozTrust: Homepage
' . number_format(round($content['utrp'], 1)) . ' / 10
'; } - if(isset($content['ftrp'])){ - $output.= '
MozTrust: Subdomain
'.number_format(round($content['ftrp'],1)).' / 10
'; + if (isset($content['ftrp'])) { + $output .= '
MozTrust: Subdomain
' . number_format(round($content['ftrp'], 1)) . ' / 10
'; } - if(isset($content['ptrp'])){ - $output.= '
MozTrust: Root Domain
'.number_format(round($content['ptrp'],1)).' / 10
'; + if (isset($content['ptrp'])) { + $output .= '
MozTrust: Root Domain
' . number_format(round($content['ptrp'], 1)) . ' / 10
'; } - if(isset($content['uemrp'])){ - $output.= '
MozRank: Homepage External Equity
'.number_format(round($content['uemrp'],1)).' / 10
'; + if (isset($content['uemrp'])) { + $output .= '
MozRank: Homepage External Equity
' . number_format(round($content['uemrp'], 1)) . ' / 10
'; } - if(isset($content['fejp'])){ - $output.= '
MozRank: Subdomain, External Equity
'.number_format(round($content['fejp'],1)).' / 10
'; + if (isset($content['fejp'])) { + $output .= '
MozRank: Subdomain, External Equity
' . number_format(round($content['fejp'], 1)) . ' / 10
'; } - if(isset($content['pejp'])){ - $output.= '
MozRank: Root Domain, External Equity
'.number_format(round($content['pejp'],1)).' / 10
'; + if (isset($content['pejp'])) { + $output .= '
MozRank: Root Domain, External Equity
' . number_format(round($content['pejp'], 1)) . ' / 10
'; } - if(isset($content['pjp'])){ - $output.= '
MozRank: Subdomain Combined
'.number_format(round($content['pjp'],1)).' / 10
'; + if (isset($content['pjp'])) { + $output .= '
MozRank: Subdomain Combined
' . number_format(round($content['pjp'], 1)) . ' / 10
'; } - if(isset($content['fjp'])){ - $output.= '
MozRank: Root Domain Combined
'.number_format(round($content['fjp'],1)).' / 10
'; + if (isset($content['fjp'])) { + $output .= '
MozRank: Root Domain Combined
' . number_format(round($content['fjp'], 1)) . ' / 10
'; } - if(isset($content['fspsc'])){ - $output.= '
Subdomain Spam Score
'.number_format($content['fspsc']).'
'; + if (isset($content['fspsc'])) { + $output .= '
Subdomain Spam Score
' . number_format($content['fspsc']) . '
'; } - if(isset($content['us'])){ - $output.= '
HTTP Status Code
'.$content['us'].'
'; + if (isset($content['us'])) { + $output .= '
HTTP Status Code
' . $content['us'] . '
'; } - if(isset($content['uid'])){ - $output.= '
Links to Homepage
'.number_format($content['uid']).'
'; + if (isset($content['uid'])) { + $output .= '
Links to Homepage
' . number_format($content['uid']) . '
'; } - if(isset($content['fuid'])){ - $output.= '
Links to Subdomain
'.number_format($content['fuid']).'
'; + if (isset($content['fuid'])) { + $output .= '
Links to Subdomain
' . number_format($content['fuid']) . '
'; } - if(isset($content['puid'])){ - $output.= '
Links to Root Domain
'.number_format($content['puid']).'
'; + if (isset($content['puid'])) { + $output .= '
Links to Root Domain
' . number_format($content['puid']) . '
'; } - if(isset($content['fipl'])){ - $output.= '
Root Domains Linking to Subdomain
'.number_format($content['fipl']).'
'; + if (isset($content['fipl'])) { + $output .= '
Root Domains Linking to Subdomain
' . number_format($content['fipl']) . '
'; } - if(isset($content['ued'])){ - $output.= '
External links
'.number_format($content['ued']).'
'; + if (isset($content['ued'])) { + $output .= '
External links
' . number_format($content['ued']) . '
'; } - if(isset($content['fed'])){ - $output.= '
External links to subdomain
'.number_format($content['fed']).'
'; + if (isset($content['fed'])) { + $output .= '
External links to subdomain
' . number_format($content['fed']) . '
'; } - if(isset($content['ped'])){ - $output.= '
External links to root domain
'.number_format($content['ped']).'
'; + if (isset($content['ped'])) { + $output .= '
External links to root domain
' . number_format($content['ped']) . '
'; } - if(isset($content['pib'])){ - $output.= '
Linking C Blocks
'.number_format($content['pib']).'
'; + if (isset($content['pib'])) { + $output .= '
Linking C Blocks
' . number_format($content['pib']) . '
'; } - if(isset($content['ulc'])){ - $output.= '
Time last crawled
'.number_format($content['ulc']).'
'; + if (isset($content['ulc'])) { + $output .= '
Time last crawled
' . number_format($content['ulc']) . '
'; } - $output.= '
'; - $output.= '

Show More Info

'; - + $output .= '
'; + $output .= '

Show More Info

'; } - $output.= ''; + $output .= ''; return $output; + } catch (\Exception $e) { + return $this->error($e); + } + } - } catch (\Exception $e) { - return $this->error($e); - } - } - - /** - * @param \Exception $e - * @return string - */ - private function error($e) - { - return '
' - . Piwik::translate('General_ErrorRequest', array('', '')) - . ' - ' . $e->getMessage() . '
'; - } - -} \ No newline at end of file + /** + * @param \Exception $e + * @return string + */ + private function error($e) + { + return '
' . Piwik::translate('General_ErrorRequest', ['', '']) . ' - ' . $e->getMessage() . '
'; + } +} diff --git a/plugin.json b/plugin.json index 32b6a4a..d6218ad 100644 --- a/plugin.json +++ b/plugin.json @@ -1,38 +1,30 @@ { - "name": "MozWidgetByAmperage", - "version": "1.1.3", - "description": "Show Moz.com info for the current site as a dashboard widget. Also links to the latest Moz Pro Campaign Custom Report, if available.", - "theme": false, - "keywords": [ - "amperage", - "moz", - "seomoz", - "widget", - "seo", - "search", - "dashboard" - ], - "license": "GPL v3+", - "homepage": "https://www.amperagemarketing.com", - "require": { - "piwik": ">=3.2.1-stable,<4.0.0-b1" - }, - "support": { - "email": "kzeni1@gmail.com", - "issues": "https://github.com/AMPERAGE-Marketing/Matomo-Moz-Widget/issues", - "wiki": "https://github.com/AMPERAGE-Marketing/Matomo-Moz-Widget/wiki", - "source": "https://github.com/AMPERAGE-Marketing/Matomo-Moz-Widget" - }, - "authors": [ - { - "name": "Amperage Marketing & Fundraising", - "email": "digital@amperagemarketing.com", - "homepage": "http://www.amperagemarketing.com" - }, - { - "name": "Kurt Zenisek", - "email": "kzeni1@gmail.com", - "homepage": "http://kzeni.com" - } - ] -} \ No newline at end of file + "name": "MozWidgetByAmperage", + "version": "1.1.4", + "description": "Show Moz.com info for the current site as a dashboard widget. Also links to the latest Moz Pro Campaign Custom Report, if available.", + "theme": false, + "keywords": ["amperage", "moz", "seomoz", "widget", "seo", "search", "dashboard"], + "license": "GPL v3+", + "homepage": "https://www.amperagemarketing.com", + "require": { + "piwik": ">=3.2.1-stable,<5.0.0-b1" + }, + "support": { + "email": "kzeni1@gmail.com", + "issues": "https://github.com/AMPERAGE-Marketing/Matomo-Moz-Widget/issues", + "wiki": "https://github.com/AMPERAGE-Marketing/Matomo-Moz-Widget/wiki", + "source": "https://github.com/AMPERAGE-Marketing/Matomo-Moz-Widget" + }, + "authors": [ + { + "name": "Amperage Marketing & Fundraising", + "email": "digital@amperagemarketing.com", + "homepage": "http://www.amperagemarketing.com" + }, + { + "name": "Kurt Zenisek", + "email": "kzeni1@gmail.com", + "homepage": "http://kzeni.com" + } + ] +}