Skip to content

Commit

Permalink
Cleanup and phpdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Valair committed Oct 22, 2019
1 parent b462911 commit 9dae4fc
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
use Piwik\Piwik;
use Piwik\Plugin\Menu as MatomoMenu;

/**
* WAI Portal menu provider.
*/
class Menu extends MatomoMenu
{
/**
* Configure analytics items menu.
*
* @param MenuTop $menu the menu reference
*/
public function configureTopMenu(MenuTop $menu)
{
// Intercept menu configuration to remove unwanted icons
Expand Down
20 changes: 16 additions & 4 deletions SystemSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,35 @@
namespace Piwik\Plugins\WAIPortal;

use Piwik\Piwik;
use Piwik\Settings\Setting;
use Piwik\Settings\FieldConfig;
use Piwik\Settings\Plugin\SystemSettings as BaseSystemSettings;
use Piwik\Validators\NotEmpty;

/**
* Defines Settings for WAIPortal.
* System Settings for WAIPortal Theme.
*/
class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
class SystemSettings extends BaseSystemSettings
{
/** @var Setting */
/**
* WAI Portal URL setting.
*
* @var string the URL
*/
public $waiUrl;

/**
* Define system settings.
*/
protected function init()
{
$this->waiUrl = $this->createDescriptionSetting();
}

/**
* Create WAI Portal URL setting.
*
* @return \Piwik\Settings\Plugin\SystemSetting the configured setting
*/
private function createDescriptionSetting()
{
$default = 'https://localhost';
Expand Down
61 changes: 61 additions & 0 deletions WAIPortal.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,51 @@
use Piwik\Plugins\CoreAdminHome\CustomLogo;
use Piwik\View;

/**
* WAI Portal theme plugin.
*/
class WAIPortal extends Plugin
{
/**
* The base plugin path.
*
* @var string the path
*/
const PLUGIN_PATH = 'plugins/WAIPortal';

/**
* Socials list
*
* @var mixed the list
*/
private $socials;

/**
* Footer list
*
* @var mixed the list
*/
private $footerLinks;

/**
* WAIPortal constructor.
* @param string|bool $pluginName A plugin name to force. If not supplied, it is set
* to the last part of the class name.
* @throws \Exception If plugin metadata is defined in both the getInformation() method
* and the **plugin.json** file.
*/
public function __construct($pluginName = false)
{
parent::__construct($pluginName);
$this->socials = json_decode(@file_get_contents(self::PLUGIN_PATH . '/data/socials.json'), true);
$this->footerLinks = json_decode(@file_get_contents(self::PLUGIN_PATH . '/data/footer_links.json'), true);
}

/**
* Register observer to events.
*
* @return array the list of events with associated observer
*/
public function registerEvents() {
return array(
'Template.beforeTopBar' => 'handleAddTopBar',
Expand All @@ -39,6 +69,14 @@ public function registerEvents() {
);
}

/**
* Handle "before adding top bar" event.
*
* @param string $outstring the HTML string to modify
* @param string $page the current location
* @param string|null $userLogin the current user login
* @param string|null $topMenu the top menu
*/
public function handleAddTopBar(&$outstring, $page, $userLogin = null, $topMenu = null)
{
if ('login' === $page) {
Expand All @@ -48,6 +86,11 @@ public function handleAddTopBar(&$outstring, $page, $userLogin = null, $topMenu
}
}

/**
* Handle "add header" event.
*
* @param string $outstring the HTML string to modify
*/
public function handleTemplateHeader(&$outstring)
{
$view = new View('@WAIPortal/itHeader');
Expand All @@ -57,6 +100,11 @@ public function handleTemplateHeader(&$outstring)
$outstring .= $view->render();
}

/**
* Handle "add page page footer" event.
*
* @param string $outstring the HTML string to modify
*/
public function handleTemplatePageFooter(&$outstring)
{
$view = new View('@WAIPortal/itFooter');
Expand All @@ -68,6 +116,13 @@ public function handleTemplatePageFooter(&$outstring)
$outstring .= $view->render();
}

/**
* Handle "add navigation bar to login page" event.
*
* @param string $outstring the HTML string to modify
* @param string $position "top" to signal initial inserting before default content,
* "bottom" ti signal inserting after default content
*/
public function handleLoginNav(&$outstring, $position)
{
if ('bottom' === $position) {
Expand All @@ -79,13 +134,19 @@ public function handleLoginNav(&$outstring, $position)
$outstring .= '<div class="hide">';
}

/**
* Manage plugin activation.
*/
public function activate() {
@copy(PIWIK_DOCUMENT_ROOT . '/plugins/WAIPortal/images/logo.png', PIWIK_DOCUMENT_ROOT . '/' . CustomLogo::getPathUserLogo());
@copy(PIWIK_DOCUMENT_ROOT . '/plugins/WAIPortal/svg/logo.svg', PIWIK_DOCUMENT_ROOT . '/' . CustomLogo::getPathUserSvgLogo());
@copy(PIWIK_DOCUMENT_ROOT . '/plugins/WAIPortal/icons/favicon-32x32.png', PIWIK_DOCUMENT_ROOT . '/' . CustomLogo::getPathUserFavicon());
Option::set('branding_use_custom_logo', '1', true);
}

/**
* Manage plugin deactivation.
*/
public function deactivate() {
Filesystem::remove(PIWIK_DOCUMENT_ROOT . '/' . CustomLogo::getPathUserLogo());
Filesystem::remove(PIWIK_DOCUMENT_ROOT . '/' .CustomLogo::getPathUserSvgLogo());
Expand Down

0 comments on commit 9dae4fc

Please sign in to comment.