예제 #1
0
 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;
 }
예제 #2
0
파일: API.php 프로젝트: a4tunado/piwik
 private function widgetExists($widget)
 {
     if (empty($widget->parameters)) {
         return false;
     }
     $module = $widget->parameters->module;
     $action = $widget->parameters->action;
     return WidgetsList::isDefined($module, $action);
 }
예제 #3
0
 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();
 }
예제 #4
0
 /**
  * @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'));
 }
예제 #5
0
 /**
  * @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;
 }