/** * @param InputInterface $input * @param OutputInterface $output * @return array * @throws \RuntimeException */ protected function getCategory(InputInterface $input, OutputInterface $output) { $validate = function ($category) { if (empty($category)) { throw new \InvalidArgumentException('Please enter the name of the category your widget should belong to'); } return $category; }; $category = $input->getOption('category'); $categories = array(); foreach (Widgets::getAllWidgets() as $widget) { if ($widget->getCategory()) { $categories[] = Piwik::translate($widget->getCategory()); } } $categories = array_values(array_unique($categories)); if (empty($category)) { $dialog = $this->getHelperSet()->get('dialog'); $category = $dialog->askAndValidate($output, 'Enter the widget category, for instance "Visitor" (you can reuse any existing category or define a new one): ', $validate, false, null, $categories); } else { $validate($category); } $translationKey = Translate::findTranslationKeyForTranslation($category); if (!empty($translationKey)) { return $translationKey; } $category = ucfirst($category); return $category; }
public function renderWidget($widgetModule = null, $widgetAction = null) { Piwik::checkUserHasSomeViewAccess(); $widget = PluginWidgets::factory($widgetModule, $widgetAction); if (!empty($widget)) { return $widget->{$widgetAction}(); } throw new Exception(Piwik::translate('General_ExceptionWidgetNotFound')); }
private function createWidgetController($module, $action, array &$parameters) { $widget = Widgets::factory($module, $action); if (!$widget) { return null; } $parameters['widget'] = $widget; $parameters['method'] = $action; return array($this->createCoreHomeController(), 'renderWidget'); }
protected function getExistingCategories() { $categories = array(); foreach (Widgets::getAllWidgets() as $widget) { if ($widget->getCategory()) { $categories[] = Piwik::translate($widget->getCategory()); } } $categories = array_values(array_unique($categories)); return $categories; }
protected function makeController($module, $action, &$parameters) { $controllerClassName = $this->getClassNameController($module); // TRY TO FIND ACTION IN CONTROLLER if (class_exists($controllerClassName)) { $class = $this->getClassNameController($module); /** @var $controller Controller */ $controller = new $class(); $controllerAction = $action; if ($controllerAction === false) { $controllerAction = $controller->getDefaultAction(); } if (is_callable(array($controller, $controllerAction))) { return array($controller, $controllerAction); } if ($action === false) { $this->triggerControllerActionNotFoundError($module, $controllerAction); } } // TRY TO FIND ACTION IN WIDGET $widget = Widgets::factory($module, $action); if (!empty($widget)) { $parameters['widgetModule'] = $module; $parameters['widgetMethod'] = $action; return array(new CoreHomeController(), 'renderWidget'); } // TRY TO FIND ACTION IN REPORT $report = Report::factory($module, $action); if (!empty($report)) { $parameters['reportModule'] = $module; $parameters['reportAction'] = $action; return array(new CoreHomeController(), 'renderReportWidget'); } if (!empty($action) && 'menu' === substr($action, 0, 4)) { $reportAction = lcfirst(substr($action, 4)); // menuGetPageUrls => getPageUrls $report = Report::factory($module, $reportAction); if (!empty($report)) { $parameters['reportModule'] = $module; $parameters['reportAction'] = $reportAction; return array(new CoreHomeController(), 'renderReportMenu'); } } $this->triggerControllerActionNotFoundError($module, $action); }
private static function addWidgets() { if (!self::$hookCalled) { self::$hookCalled = true; /** * @ignore * @deprecated */ Piwik::postEvent('WidgetsList.addWidgets'); $widgetsList = self::getInstance(); foreach (Report::getAllReports() as $report) { if ($report->isEnabled()) { $report->configureWidget($widgetsList); } } $widgetContainers = Widgets::getAllWidgets(); foreach ($widgetContainers as $widgetContainer) { $widgets = $widgetContainer->getWidgets(); foreach ($widgets as $widget) { $widgetsList->add($widget['category'], $widget['name'], $widget['module'], $widget['method'], $widget['params']); } } foreach ($widgetContainers as $widgetContainer) { $widgetContainer->configureWidgetsList($widgetsList); } } }