public function removeDisabledPluginFromLayout($layout) { $layoutObject = $this->decodeLayout($layout); // if the json decoding works (ie. new Json format) // we will only return the widgets that are from enabled plugins if (is_array($layoutObject)) { $layoutObject = (object) array('config' => array('layout' => '33-33-33'), 'columns' => $layoutObject); } if (empty($layoutObject) || empty($layoutObject->columns)) { $layoutObject = (object) array('config' => array('layout' => '33-33-33'), 'columns' => array()); } foreach ($layoutObject->columns as &$row) { if (!is_array($row)) { $row = array(); continue; } foreach ($row as $widgetId => $widget) { if (isset($widget->parameters->module)) { $controllerName = $widget->parameters->module; $controllerAction = $widget->parameters->action; if (!WidgetsList::isDefined($controllerName, $controllerAction)) { unset($row[$widgetId]); } } else { unset($row[$widgetId]); } } } $layout = $this->encodeLayout($layoutObject); return $layout; }
private function widgetExists($widget) { if (empty($widget->parameters)) { return false; } $module = $widget->parameters->module; $action = $widget->parameters->action; return WidgetsList::isDefined($module, $action); }
public function testIsDefined() { // setup the access layer FakeAccess::$superUser = true; Translate::loadAllTranslations(); Fixture::createWebsite('2009-01-04 00:11:42', true); $_GET['idSite'] = 1; WidgetsList::_reset(); WidgetsList::add('Actions', 'Pages', 'Actions', 'getPageUrls'); $this->assertTrue(WidgetsList::isDefined('Actions', 'getPageUrls')); $this->assertFalse(WidgetsList::isDefined('Actions', 'inValiD')); Translate::reset(); }
/** * @group Core */ public function testIsDefined() { // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Access::setSingletonInstance($pseudoMockAccess); \Piwik\Translate::loadEnglishTranslation(); Fixture::createWebsite('2009-01-04 00:11:42', true); $_GET['idSite'] = 1; WidgetsList::_reset(); WidgetsList::add('Actions', 'Pages', 'Actions', 'getPageUrls'); $this->assertTrue(WidgetsList::isDefined('Actions', 'getPageUrls')); $this->assertFalse(WidgetsList::isDefined('Actions', 'inValiD')); }
/** * @ignore * @return Widgets|null */ public static function factory($module, $action) { if (empty($module) || empty($action)) { return; } $pluginManager = PluginManager::getInstance(); try { if (!$pluginManager->isPluginActivated($module)) { return; } $plugin = $pluginManager->getLoadedPlugin($module); } catch (\Exception $e) { // we are not allowed to use possible widgets, plugin is not active return; } /** @var Widgets $widgetContainer */ $widgetContainer = $plugin->findComponent('Widgets', 'Piwik\\Plugin\\Widgets'); if (empty($widgetContainer)) { // plugin does not define any widgets, we cannot do anything return; } if (!is_callable(array($widgetContainer, $action))) { // widget does not implement such a method, we cannot do anything return; } // the widget class implements such an action, but we have to check whether it is actually exposed and whether // it was maybe disabled by another plugin, this is only possible by checking the widgetslist, unfortunately if (!WidgetsList::isDefined($module, $action)) { return; } return $widgetContainer; }