Skip to content

Commit

Permalink
Confirmed Matomo 4 compliance.
Browse files Browse the repository at this point in the history
  • Loading branch information
KZeni committed Nov 25, 2020
1 parent 45f9bac commit 4a019de
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 122 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.4

- Confirmed Matomo 4 compliance.

## 1.0.3

- Better scoped the widget styles.
Expand All @@ -14,4 +18,4 @@

## 1.0

- Initial Release.
- Initial Release.
167 changes: 81 additions & 86 deletions Widgets/GetTwitterFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,69 +28,68 @@
*/
class getTwitterFeed extends Widget
{

/**
* @var SettingsProvider
*/
/**
* @var SettingsProvider
*/
private $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('TwitterFeedWidgetByAmperage_Social');

/**
* 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('TwitterFeedWidgetByAmperage_TwitterFeed');

/**
* 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'));
*/

/**
* 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();
*/
}

/**
* 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 {

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('TwitterFeedWidgetByAmperage_Social');

/**
* 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('TwitterFeedWidgetByAmperage_TwitterFeed');

/**
* 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'));
*/

/**
* 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();
*/
}

/**
* 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 {
$output = '<div class="widget-body">';

$twitter_username = '';
Expand All @@ -100,35 +99,31 @@ public function render(){
$settings = $this->settingsProvider->getMeasurableSettings('TwitterFeedWidgetByAmperage', $idSite);
$twitter_username = $settings->twitterFeedUsernameSetting->getValue();

if($twitter_username == ''){
$output.= '<p>You first need to configure the Twitter Feed Username in your <a href="index.php?module=SitesManager&action=index#TwitterFeedWidgetByAmperage">measurable (website/app) settings</a>.</p>';
}else{ // Twitter Feed Username has been provided

$output.= '<a class="twitter-timeline" data-height="400" data-theme="light" href="https://twitter.com/'.$twitter_username.'?ref_src=twsrc%5Etfw">Tweets by '.$twitter_username.'</a>';
if ($twitter_username == '') {
$output .= '<p>You first need to configure the Twitter Feed Username in your <a href="index.php?module=SitesManager&action=index#TwitterFeedWidgetByAmperage">measurable (website/app) settings</a>.</p>';
} else {
// Twitter Feed Username has been provided

$output.= '<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>';
$output .= '<a class="twitter-timeline" data-height="400" data-theme="light" href="https://twitter.com/' . $twitter_username . '?ref_src=twsrc%5Etfw">Tweets by ' . $twitter_username . '</a>';

$output.= '<p><a href="https://analytics.twitter.com/user/'.$twitter_username.'/home" target="_blank" class="more">View More Twitter Insights &amp; Stats</a></p>';
$output .= '<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>';

$output .= '<p><a href="https://analytics.twitter.com/user/' . $twitter_username . '/home" target="_blank" class="more">View More Twitter Insights &amp; Stats</a></p>';
}

$output.= '</div>';
$output .= '</div>';
return $output;

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

} 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', ['', '']) . ' - ' . $e->getMessage() . '</div>';
}
}
63 changes: 28 additions & 35 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
{
"name": "TwitterFeedWidgetByAmperage",
"description": "Show Twitter Feed as a configurable widget.",
"version": "1.0.3",
"theme": false,
"keywords": [
"amperage",
"twitter",
"social",
"widget",
"twitter feed",
"dashboard"
],
"license": "GPL v3+",
"homepage": "https://www.amperagemarketing.com",
"require": {
"piwik": ">=3.3.0-stable,<4.0.0-b1"
},
"support": {
"email": "[email protected]",
"issues": "https://github.com/AMPERAGE-Marketing/Matomo-Twitter-Feed-Widget/issues",
"wiki": "https://github.com/AMPERAGE-Marketing/Matomo-Twitter-Feed-Widget/wiki",
"source": "https://github.com/AMPERAGE-Marketing/Matomo-Twitter-Feed-Widget"
},
"authors": [
{
"name": "Amperage Marketing & Fundraising",
"email": "[email protected]",
"homepage": "http://www.amperagemarketing.com"
},
{
"name": "Kurt Zenisek",
"email": "[email protected]",
"homepage": "http://kzeni.com"
}
]
"name": "TwitterFeedWidgetByAmperage",
"description": "Show Twitter Feed as a configurable widget.",
"version": "1.0.4",
"theme": false,
"keywords": ["amperage", "twitter", "social", "widget", "twitter feed", "dashboard"],
"license": "GPL v3+",
"homepage": "https://www.amperagemarketing.com",
"require": {
"piwik": ">=3.3.0-stable,<5.0.0-b1"
},
"support": {
"email": "[email protected]",
"issues": "https://github.com/AMPERAGE-Marketing/Matomo-Twitter-Feed-Widget/issues",
"wiki": "https://github.com/AMPERAGE-Marketing/Matomo-Twitter-Feed-Widget/wiki",
"source": "https://github.com/AMPERAGE-Marketing/Matomo-Twitter-Feed-Widget"
},
"authors": [
{
"name": "Amperage Marketing & Fundraising",
"email": "[email protected]",
"homepage": "http://www.amperagemarketing.com"
},
{
"name": "Kurt Zenisek",
"email": "[email protected]",
"homepage": "http://kzeni.com"
}
]
}

0 comments on commit 4a019de

Please sign in to comment.