fix labels and text editors for Quest creation

This commit is contained in:
oliver 2016-01-15 12:33:07 +01:00
commit 476c18b6a9
4278 changed files with 1196345 additions and 0 deletions

View file

@ -0,0 +1,269 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Menu;
use Piwik\Common;
use Piwik\Plugins\SitesManager\API;
use Piwik\Singleton;
/**
* Base class for classes that manage one of Piwik's menus.
*
* There are three menus in Piwik, the main menu, the top menu and the admin menu.
* Each menu has a class that manages the menu's content. Each class invokes
* a different event to allow plugins to add new menu items.
*
* @static \Piwik\Menu\MenuAbstract getInstance()
*/
abstract class MenuAbstract extends Singleton
{
protected $menu = null;
protected $menuEntries = array();
protected $menuEntriesToRemove = array();
protected $edits = array();
protected $renames = array();
protected $orderingApplied = false;
/**
* Builds the menu, applies edits, renames
* and orders the entries.
*
* @return Array
*/
public function getMenu()
{
$this->buildMenu();
$this->applyEdits();
$this->applyRenames();
$this->applyRemoves();
$this->applyOrdering();
return $this->menu;
}
/**
* Adds a new entry to the menu.
*
* @param string $menuName The menu's category name. Can be a translation token.
* @param string $subMenuName The menu item's name. Can be a translation token.
* @param string|array $url The URL the admin menu entry should link to, or an array of query parameters
* that can be used to build the URL.
* @param boolean $displayedForCurrentUser Whether this menu entry should be displayed for the
* current user. If false, the entry will not be added.
* @param int $order The order hint.
* @param false|string $tooltip An optional tooltip to display.
* @api
*/
public function add($menuName, $subMenuName, $url, $displayedForCurrentUser = true, $order = 50, $tooltip = false)
{
if (!$displayedForCurrentUser) {
return;
}
// make sure the idSite value used is numeric (hack-y fix for #3426)
if (!is_numeric(Common::getRequestVar('idSite', false))) {
$idSites = API::getInstance()->getSitesIdWithAtLeastViewAccess();
$url['idSite'] = reset($idSites);
}
$this->menuEntries[] = array(
$menuName,
$subMenuName,
$url,
$order,
$tooltip
);
}
public function remove($menuName, $subMenuName = false)
{
$this->menuEntriesToRemove[] = array(
$menuName,
$subMenuName
);
}
/**
* Builds a single menu item
*
* @param string $menuName
* @param string $subMenuName
* @param string $url
* @param int $order
* @param bool|string $tooltip Tooltip to display.
*/
private function buildMenuItem($menuName, $subMenuName, $url, $order = 50, $tooltip = false)
{
if (!isset($this->menu[$menuName]) || empty($subMenuName)) {
$this->menu[$menuName]['_url'] = $url;
if (empty($subMenuName)) {
$this->menu[$menuName]['_order'] = $order;
}
$this->menu[$menuName]['_name'] = $menuName;
$this->menu[$menuName]['_hasSubmenu'] = false;
$this->menu[$menuName]['_tooltip'] = $tooltip;
}
if (!empty($subMenuName)) {
$this->menu[$menuName][$subMenuName]['_url'] = $url;
$this->menu[$menuName][$subMenuName]['_order'] = $order;
$this->menu[$menuName][$subMenuName]['_name'] = $subMenuName;
$this->menu[$menuName]['_hasSubmenu'] = true;
$this->menu[$menuName]['_tooltip'] = $tooltip;
}
}
/**
* Builds the menu from the $this->menuEntries variable.
*/
private function buildMenu()
{
foreach ($this->menuEntries as $menuEntry) {
$this->buildMenuItem($menuEntry[0], $menuEntry[1], $menuEntry[2], $menuEntry[3], $menuEntry[4]);
}
}
/**
* Renames a single menu entry.
*
* @param $mainMenuOriginal
* @param $subMenuOriginal
* @param $mainMenuRenamed
* @param $subMenuRenamed
*/
public function rename($mainMenuOriginal, $subMenuOriginal, $mainMenuRenamed, $subMenuRenamed)
{
$this->renames[] = array($mainMenuOriginal, $subMenuOriginal,
$mainMenuRenamed, $subMenuRenamed);
}
/**
* Edits a URL of an existing menu entry.
*
* @param $mainMenuToEdit
* @param $subMenuToEdit
* @param $newUrl
*/
public function editUrl($mainMenuToEdit, $subMenuToEdit, $newUrl)
{
$this->edits[] = array($mainMenuToEdit, $subMenuToEdit, $newUrl);
}
/**
* Applies all edits to the menu.
*/
private function applyEdits()
{
foreach ($this->edits as $edit) {
$mainMenuToEdit = $edit[0];
$subMenuToEdit = $edit[1];
$newUrl = $edit[2];
if ($subMenuToEdit === null) {
$menuDataToEdit = @$this->menu[$mainMenuToEdit];
} else {
$menuDataToEdit = @$this->menu[$mainMenuToEdit][$subMenuToEdit];
}
if (empty($menuDataToEdit)) {
$this->buildMenuItem($mainMenuToEdit, $subMenuToEdit, $newUrl);
} else {
$menuDataToEdit['_url'] = $newUrl;
}
}
}
private function applyRemoves()
{
foreach($this->menuEntriesToRemove as $menuToDelete) {
if(empty($menuToDelete[1])) {
// Delete Main Menu
if(isset($this->menu[$menuToDelete[0]])) {
unset($this->menu[$menuToDelete[0]]);
}
} else {
// Delete Sub Menu
if(isset($this->menu[$menuToDelete[0]][$menuToDelete[1]])) {
unset($this->menu[$menuToDelete[0]][$menuToDelete[1]]);
}
}
}
}
/**
* Applies renames to the menu.
*/
private function applyRenames()
{
foreach ($this->renames as $rename) {
$mainMenuOriginal = $rename[0];
$subMenuOriginal = $rename[1];
$mainMenuRenamed = $rename[2];
$subMenuRenamed = $rename[3];
// Are we changing a submenu?
if (!empty($subMenuOriginal)) {
if (isset($this->menu[$mainMenuOriginal][$subMenuOriginal])) {
$save = $this->menu[$mainMenuOriginal][$subMenuOriginal];
$save['_name'] = $subMenuRenamed;
unset($this->menu[$mainMenuOriginal][$subMenuOriginal]);
$this->menu[$mainMenuRenamed][$subMenuRenamed] = $save;
}
} // Changing a first-level element
else if (isset($this->menu[$mainMenuOriginal])) {
$save = $this->menu[$mainMenuOriginal];
$save['_name'] = $mainMenuRenamed;
unset($this->menu[$mainMenuOriginal]);
$this->menu[$mainMenuRenamed] = $save;
}
}
}
/**
* Orders the menu according to their order.
*/
private function applyOrdering()
{
if (empty($this->menu)
|| $this->orderingApplied
) {
return;
}
uasort($this->menu, array($this, 'menuCompare'));
foreach ($this->menu as $key => &$element) {
if (is_null($element)) {
unset($this->menu[$key]);
} else if ($element['_hasSubmenu']) {
uasort($element, array($this, 'menuCompare'));
}
}
$this->orderingApplied = true;
}
/**
* Compares two menu entries. Used for ordering.
*
* @param array $itemOne
* @param array $itemTwo
* @return boolean
*/
protected function menuCompare($itemOne, $itemTwo)
{
if (!is_array($itemOne) || !is_array($itemTwo)
|| !isset($itemOne['_order']) || !isset($itemTwo['_order'])
) {
return 0;
}
if ($itemOne['_order'] == $itemTwo['_order']) {
return strcmp($itemOne['_name'], $itemTwo['_name']);
}
return ($itemOne['_order'] < $itemTwo['_order']) ? -1 : 1;
}
}

View file

@ -0,0 +1,113 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Menu;
use Piwik\Piwik;
/**
* Contains menu entries for the Admin menu. Plugins can subscribe to the
* {@hook Menu.Admin.addItems} event to add new pages to the admin menu.
*
* **Example**
*
* // add a new page in an observer to Menu.Admin.addItems
* public function addAdminMenuItem()
* {
* MenuAdmin::getInstance()->add(
* 'MyPlugin_MyTranslatedAdminMenuCategory',
* 'MyPlugin_MyTranslatedAdminPageName',
* array('module' => 'MyPlugin', 'action' => 'index'),
* Piwik::isUserHasSomeAdminAccess(),
* $order = 2
* );
* }
*
* @method static \Piwik\Menu\MenuAdmin getInstance()
*/
class MenuAdmin extends MenuAbstract
{
/**
* Adds a new AdminMenu entry under the 'Settings' category.
*
* @param string $adminMenuName The name of the admin menu entry. Can be a translation token.
* @param string|array $url The URL the admin menu entry should link to, or an array of query parameters
* that can be used to build the URL.
* @param boolean $displayedForCurrentUser Whether this menu entry should be displayed for the
* current user. If false, the entry will not be added.
* @param int $order The order hint.
* @api
*/
public static function addEntry($adminMenuName, $url, $displayedForCurrentUser = true, $order = 20)
{
self::getInstance()->add('General_Settings', $adminMenuName, $url, $displayedForCurrentUser, $order);
}
/**
* Triggers the Menu.MenuAdmin.addItems hook and returns the admin menu.
*
* @return Array
*/
public function getMenu()
{
if (!$this->menu) {
/**
* Triggered when collecting all available admin menu items. Subscribe to this event if you want
* to add one or more items to the Piwik admin menu.
*
* Menu items should be added via the {@link add()} method.
*
* **Example**
*
* use Piwik\Menu\MenuAdmin;
*
* public function addMenuItems()
* {
* MenuAdmin::getInstance()->add(
* 'MenuName',
* 'SubmenuName',
* array('module' => 'MyPlugin', 'action' => 'index'),
* $showOnlyIf = Piwik::hasUserSuperUserAccess(),
* $order = 6
* );
* }
*/
Piwik::postEvent('Menu.Admin.addItems');
}
return parent::getMenu();
}
/**
* Returns the current AdminMenu name
*
* @return boolean
*/
public function getCurrentAdminMenuName()
{
$menu = MenuAdmin::getInstance()->getMenu();
$currentModule = Piwik::getModule();
$currentAction = Piwik::getAction();
foreach ($menu as $submenu) {
foreach ($submenu as $subMenuName => $parameters) {
if (strpos($subMenuName, '_') !== 0 &&
$parameters['_url']['module'] == $currentModule
&& $parameters['_url']['action'] == $currentAction
) {
return $subMenuName;
}
}
}
return false;
}
public static function removeEntry($menuName, $subMenuName = false)
{
MenuAdmin::getInstance()->remove($menuName, $subMenuName);
}
}

View file

@ -0,0 +1,91 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Menu;
use Piwik\Piwik;
/**
* Contains menu entries for the Main menu (the menu displayed under the Piwik logo).
* Plugins can subscribe to the {@hook Menu.Reporting.addItems} event to add new pages to
* the main menu.
*
* **Example**
*
* // add a new page in an observer to Menu.Admin.addItems
* public function addMainMenuItem()
* {
* MenuMain::getInstance()->add(
* 'MyPlugin_MyTranslatedMenuCategory',
* 'MyPlugin_MyTranslatedMenuName',
* array('module' => 'MyPlugin', 'action' => 'index'),
* Piwik::isUserHasSomeAdminAccess(),
* $order = 2
* );
* }
*
* @api
* @method static \Piwik\Menu\MenuMain getInstance()
*/
class MenuMain extends MenuAbstract
{
/**
* Returns if the URL was found in the menu.
*
* @param string $url
* @return boolean
*/
public function isUrlFound($url)
{
$menu = MenuMain::getInstance()->getMenu();
foreach ($menu as $subMenus) {
foreach ($subMenus as $subMenuName => $menuUrl) {
if (strpos($subMenuName, '_') !== 0 && $menuUrl['_url'] == $url) {
return true;
}
}
}
return false;
}
/**
* Triggers the Menu.Reporting.addItems hook and returns the menu.
*
* @return Array
*/
public function getMenu()
{
// We trigger the Event only once!
if (!$this->menu) {
/**
* Triggered when collecting all available reporting menu items. Subscribe to this event if you
* want to add one or more items to the Piwik reporting menu.
*
* Menu items should be added via the {@link add()} method.
*
* **Example**
*
* use Piwik\Menu\Main;
*
* public function addMenuItems()
* {
* Main::getInstance()->add(
* 'CustomMenuName',
* 'CustomSubmenuName',
* array('module' => 'MyPlugin', 'action' => 'index'),
* $showOnlyIf = Piwik::hasUserSuperUserAccess(),
* $order = 6
* );
* }
*/
Piwik::postEvent('Menu.Reporting.addItems');
}
return parent::getMenu();
}
}

View file

@ -0,0 +1,121 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Menu;
use Piwik\Piwik;
/**
* Contains menu entries for the Top menu (the menu at the very top of the page).
* Plugins can subscribe to the {@hook Menu.Top.addItems} event to add new pages to
* the top menu.
*
* **Example**
*
* // add a new page in an observer to Menu.Admin.addItems
* public function addTopMenuItem()
* {
* MenuTop::getInstance()->add(
* 'MyPlugin_MyTranslatedMenuCategory',
* 'MyPlugin_MyTranslatedMenuName',
* array('module' => 'MyPlugin', 'action' => 'index'),
* Piwik::isUserHasSomeAdminAccess(),
* $order = 2
* );
* }
*
* @method static \Piwik\Menu\MenuTop getInstance()
*/
class MenuTop extends MenuAbstract
{
/**
* Adds a new entry to the TopMenu.
*
* @param string $topMenuName The menu item name. Can be a translation token.
* @param string|array $url The URL the admin menu entry should link to, or an array of query parameters
* that can be used to build the URL. If `$isHTML` is true, this can be a string with
* HTML that is simply embedded.
* @param boolean $displayedForCurrentUser Whether this menu entry should be displayed for the
* current user. If false, the entry will not be added.
* @param int $order The order hint.
* @param bool $isHTML Whether `$url` is an HTML string or a URL that will be rendered as a link.
* @param bool|string $tooltip Optional tooltip to display.
* @api
*/
public static function addEntry($topMenuName, $url, $displayedForCurrentUser = true, $order = 10, $isHTML = false, $tooltip = false)
{
if ($isHTML) {
MenuTop::getInstance()->addHtml($topMenuName, $url, $displayedForCurrentUser, $order, $tooltip);
} else {
MenuTop::getInstance()->add($topMenuName, null, $url, $displayedForCurrentUser, $order, $tooltip);
}
}
public static function removeEntry($menuName, $subMenuName = false)
{
MenuTop::getInstance()->remove($menuName, $subMenuName);
}
/**
* Directly adds a menu entry containing html.
*
* @param string $menuName
* @param string $data
* @param boolean $displayedForCurrentUser
* @param int $order
* @param string $tooltip Tooltip to display.
*/
public function addHtml($menuName, $data, $displayedForCurrentUser, $order, $tooltip)
{
if ($displayedForCurrentUser) {
if (!isset($this->menu[$menuName])) {
$this->menu[$menuName]['_html'] = $data;
$this->menu[$menuName]['_order'] = $order;
$this->menu[$menuName]['_hasSubmenu'] = false;
$this->menu[$menuName]['_tooltip'] = $tooltip;
}
}
}
/**
* Triggers the Menu.Top.addItems hook and returns the menu.
*
* @return Array
*/
public function getMenu()
{
if (!$this->menu) {
/**
* Triggered when collecting all available menu items that are be displayed on the very top of every
* page, next to the login/logout links.
*
* Subscribe to this event if you want to add one or more items to the top menu.
*
* Menu items should be added via the {@link addEntry()} method.
*
* **Example**
*
* use Piwik\Menu\MenuTop;
*
* public function addMenuItems()
* {
* MenuTop::addEntry(
* 'TopMenuName',
* array('module' => 'MyPlugin', 'action' => 'index'),
* $showOnlyIf = Piwik::hasUserSuperUserAccess(),
* $order = 6
* );
* }
*/
Piwik::postEvent('Menu.Top.addItems');
}
return parent::getMenu();
}
}