Skip to content

Commit

Permalink
migrate plugin from angularjs to vuejs
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed Jun 6, 2023
1 parent 7cddd92 commit 1468151
Show file tree
Hide file tree
Showing 39 changed files with 1,941 additions and 739 deletions.
5 changes: 4 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ config/test.php export-ignore
tests/ export-ignore
.gitignore export-ignore
.gitattributes export-ignore
.travis.yml export-ignore
.travis.yml export-ignore

# + generated code: exclude and suppress in diffs
vue/dist/** linguist-generated
55 changes: 42 additions & 13 deletions API.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Plugins\ReferrersManager;

use Piwik\Piwik;

class API extends \Piwik\Plugin\API
{
/** @var Model */
Expand Down Expand Up @@ -91,25 +93,32 @@ public function getSocialLogos()
* @param string $charset
* @return bool
*/
public function addSearchEngine($name, $host, $parameters = '', $backlink = '', $charset = '')
{
public function addSearchEngine(
string $name,
string $host,
$parameters = '',
string $backlink = '',
string $charset = ''
) {
Piwik::checkUserHasSuperUserAccess();

if (empty($host) || empty($name)) {
return false;
}

if (!empty($parameters)) {
$parameters = explode(',', $parameters);
} else {
$parameters = array();
$parameters = [];
}

$engines = $this->model->getUserDefinedSearchEngines();
$engines[$host] = array(
'name' => $name,
'params' => $parameters,
$engines[$host] = [
'name' => $name,
'params' => $parameters,
'backlink' => $backlink,
'chartset' => $charset
);
'charsets' => explode(',', $charset),
];
$this->model->setUserDefinedSearchEngines($engines);
return true;
}
Expand All @@ -120,8 +129,10 @@ public function addSearchEngine($name, $host, $parameters = '', $backlink = '',
* @param string $host
* @return bool
*/
public function removeSearchEngine($host)
public function removeSearchEngine(string $host)
{
Piwik::checkUserHasSuperUserAccess();

if (empty($host)) {
return false;
}
Expand All @@ -144,13 +155,14 @@ public function removeSearchEngine($host)
* @param string $host
* @return bool
*/
public function addSocial($name, $host)
public function addSocial(string $name, string $host)
{
Piwik::checkUserHasSuperUserAccess();

if (empty($host) || empty($name)) {
return false;
}


$socials = $this->model->getUserDefinedSocials();
$socials[$host] = $name;
$this->model->setUserDefinedSocials($socials);
Expand All @@ -159,11 +171,14 @@ public function addSocial($name, $host)

/**
* Removes a user defined social network
*
* @param $host
* @return bool
*/
public function removeSocial($host)
public function removeSocial(string $host)
{
Piwik::checkUserHasSuperUserAccess();

if (empty($host)) {
return false;
}
Expand All @@ -178,4 +193,18 @@ public function removeSocial($host)
$this->model->setUserDefinedSocials($socials);
return true;
}

/**
* Sets if default socials should be used or not
*
* @param bool $state
* @return bool
*/
public function setDefaultSocialsDisabled(bool $state = false): bool
{
Piwik::checkUserHasSuperUserAccess();

Model::getInstance()->setDefaultSocialsDisabled((bool)$state);
return true;
}
}
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
## Changelog

__5.0.0__

* Migrate AngularJS components to Vue.js
* Compatibility with Matomo 5

__4.0.4__

* Minor code improvements
* Translation updates

__4.0.3__

* Small UI/UX improvements
* Translation updates
*

__4.0.2__

* Translation updates
Expand Down
32 changes: 10 additions & 22 deletions Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\ReferrersManager;

use Piwik\Common;
use Piwik\DataTable\Renderer\Json;
use Piwik\Piwik;
use Piwik\Plugin\ControllerAdmin;
use Piwik\Request;
use Piwik\View;

/**
Expand All @@ -21,6 +21,7 @@ class Controller extends ControllerAdmin
{
/**
* Index action
*
* @return string
*/
public function index()
Expand All @@ -35,19 +36,6 @@ public function index()
return $view->render();
}

/**
* Sets if default socials should be used or not
*/
public function setDefaultSocialsDisabled()
{
Piwik::checkUserHasSuperUserAccess();

$state = Common::getRequestVar('state', 0, 'int');
Model::getInstance()->setDefaultSocialsDisabled((bool) $state);
Json::sendHeaderJSON();
return 1;
}

/**
* Ajax action to check an url for search engine information that can be extracted
*
Expand All @@ -57,13 +45,13 @@ public function checkUrl()
{
Piwik::checkUserHasSuperUserAccess();

$urlToCheck = trim(Common::unsanitizeInputValue(Common::getRequestVar('url', null, 'string')));
$urlToCheck = trim(Request::fromRequest()->getStringParameter('url', ''));

Json::sendHeaderJSON();
return json_encode([
'searchengine' => Model::getInstance()->detectSearchEngine($urlToCheck),
'social' => Model::getInstance()->detectSocial($urlToCheck)
]);
'searchengine' => Model::getInstance()->detectSearchEngine($urlToCheck),
'social' => Model::getInstance()->detectSocial($urlToCheck),
]);
}

public function refresh()
Expand All @@ -72,11 +60,11 @@ public function refresh()

Json::sendHeaderJSON();

$type = Common::getRequestVar('type', '', 'string');
$type = Request::fromRequest()->getStringParameter('type', '');

if ($type == 'socials') {
if ($type === 'socials') {
Model::getInstance()->clearSocialCache();
} else if ($type == 'searchengines') {
} else if ($type === 'searchengines') {
Model::getInstance()->clearSearchEngineCache();
}

Expand Down
16 changes: 8 additions & 8 deletions Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public static function getInstance()
}

/**
* Returns if Piwik's built-in social list is used or not
* Returns if Matomo's built-in social list is used or not
*
* @return false|string
* @return bool
*/
public function areDefaultSocialsDisabled()
{
return Option::get(self::OPTION_KEY_DISABLE_DEFAULT_SOCIALS);
return !!Option::get(self::OPTION_KEY_DISABLE_DEFAULT_SOCIALS);
}

/**
* Sets if Piwik's built-in social list should be used or not
* Sets if Matomo's built-in social list should be used or not
*
* @param bool $disabled
*/
Expand Down Expand Up @@ -145,7 +145,7 @@ public function clearSearchEngineCache()
}

/**
* Wrapper method to Piwiks internal method to return search engine data
* Wrapper method to Matomo's internal method to return search engine data
* @return array
*/
public function getSearchEngines()
Expand All @@ -154,7 +154,7 @@ public function getSearchEngines()
}

/**
* Returns all search engine informations known to piwik
* Returns all search engine information known to Matomo
*
* @return array
*/
Expand Down Expand Up @@ -201,7 +201,7 @@ public function getSearchEngineLogos()
}

/**
* Wrapper method to Piwiks internal method to return search engine data
* Wrapper method to Matomo' internal method to return search engine data
* @return array
*/
public function getSocials()
Expand All @@ -210,7 +210,7 @@ public function getSocials()
}

/**
* Returns all social informations known to piwik
* Returns all social informations known to Matomo
*
* @return array
*/
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ Note: You can find the configuration panel for this plugin within the global adm

### Requirements

[Matomo](https://github.com/matomo-org/matomo) 4.0.0-b1 or higher is required.
[Matomo](https://github.com/matomo-org/matomo) 5.0.0-b1 or higher is required.

### Features

- Shows a list of all search engines and social networks defined in Matomo core.
- Abillity to manage custom search engines and social networks
- Abillity to disable/enable Matomo's default social network list
- Ability to manage custom search engines and social networks
- Ability to disable/enable Matomo's default social network list

## Support

Please direct any feedback to [[email protected]](mailto:matomo@piwik.org)
Please direct any feedback to [[email protected]](mailto:matomo@matomo.org)

## Contribute

Expand Down
13 changes: 0 additions & 13 deletions ReferrersManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,11 @@ public function registerEvents()
return array(
'Referrer.addSearchEngineUrls' => 'addSearchEngineUrls',
'Referrer.addSocialUrls' => 'addSocialUrls',
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
);
}

/**
* Adds required JS files
* @param $jsFiles
*/
public function getJsFiles(&$jsFiles)
{
$jsFiles[] = "plugins/ReferrersManager/javascripts/checkreferrerurl.controller.js";
$jsFiles[] = "plugins/ReferrersManager/javascripts/searchengines.controller.js";
$jsFiles[] = "plugins/ReferrersManager/javascripts/socials.controller.js";
$jsFiles[] = "plugins/ReferrersManager/javascripts/referrersmanager-tabs.directive.js";
}

/**
* Adds required CSS files
* @param $stylesheets
Expand Down
2 changes: 1 addition & 1 deletion config/test.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

return array(
'Piwik\Plugins\ReferrersManager\Model' => DI\autowire('Piwik\Plugins\ReferrersManager\tests\Mocks\Model'),
'Piwik\Plugins\ReferrersManager\Model' => \Piwik\DI::autowire('Piwik\Plugins\ReferrersManager\tests\Mocks\Model'),
);
Loading

0 comments on commit 1468151

Please sign in to comment.