public function configureView(ViewDataTable $view) { $view->config->title = $this->name; $view->config->show_search = false; $view->config->show_exclude_low_population = false; $view->config->addTranslation('label', Piwik::translate("UserSettings_OperatingSystemFamily")); }
public function configureAdminMenu(MenuAdmin $menu) { $hasSuperUserAcess = Piwik::hasUserSuperUserAccess(); $isAnonymous = Piwik::isUserIsAnonymous(); $isMarketplaceEnabled = CorePluginsAdmin::isMarketplaceEnabled(); $pluginsUpdateMessage = ''; $themesUpdateMessage = ''; if ($hasSuperUserAcess && $isMarketplaceEnabled) { $marketplace = new Marketplace(); $pluginsHavingUpdate = $marketplace->getPluginsHavingUpdate($themesOnly = false); $themesHavingUpdate = $marketplace->getPluginsHavingUpdate($themesOnly = true); if (!empty($pluginsHavingUpdate)) { $pluginsUpdateMessage = sprintf(' (%d)', count($pluginsHavingUpdate)); } if (!empty($themesHavingUpdate)) { $themesUpdateMessage = sprintf(' (%d)', count($themesHavingUpdate)); } } $menu->add('CorePluginsAdmin_MenuPlatform', null, "", !$isAnonymous, $order = 7); $menu->add('CorePluginsAdmin_MenuPlatform', Piwik::translate('General_Plugins') . $pluginsUpdateMessage, array('module' => 'CorePluginsAdmin', 'action' => 'plugins', 'activated' => ''), $hasSuperUserAcess, $order = 1); $menu->add('CorePluginsAdmin_MenuPlatform', Piwik::translate('CorePluginsAdmin_Themes') . $themesUpdateMessage, array('module' => 'CorePluginsAdmin', 'action' => 'themes', 'activated' => ''), $hasSuperUserAcess, $order = 3); if ($isMarketplaceEnabled) { $menu->add('CorePluginsAdmin_MenuPlatform', 'CorePluginsAdmin_Marketplace', array('module' => 'CorePluginsAdmin', 'action' => 'extend', 'activated' => ''), !$isAnonymous, $order = 5); } }
public function setupTestEnvironment($environment) { Piwik::addAction("MySQLMetadataProvider.createDao", function (&$dao) { require_once dirname(__FILE__) . "/tests/Mocks/MockDataAccess.php"; $dao = new Mocks\MockDataAccess(); }); }
protected function retrieveFileLocations() { if (!empty($this->plugins)) { /** * Triggered when gathering the list of all JavaScript files needed by Piwik * and its plugins. * * Plugins that have their own JavaScript should use this event to make those * files load in the browser. * * JavaScript files should be placed within a **javascripts** subdirectory in your * plugin's root directory. * * _Note: While you are developing your plugin you should enable the config setting * `[Development] disable_merged_assets` so JavaScript files will be reloaded immediately * after every change._ * * **Example** * * public function getJsFiles(&$jsFiles) * { * $jsFiles[] = "plugins/MyPlugin/javascripts/myfile.js"; * $jsFiles[] = "plugins/MyPlugin/javascripts/anotherone.js"; * } * * @param string[] $jsFiles The JavaScript files to load. */ Piwik::postEvent('AssetManager.getJavaScriptFiles', array(&$this->fileLocations), null, $this->plugins); } $this->addThemeFiles(); }
function init() { HTML_QuickForm2_Factory::registerRule('checkValidFilename', 'Piwik\\Plugins\\Installation\\FormDatabaseSetup_Rule_checkValidFilename'); $checkUserPrivilegesClass = 'Piwik\\Plugins\\Installation\\Rule_checkUserPrivileges'; HTML_QuickForm2_Factory::registerRule('checkUserPrivileges', $checkUserPrivilegesClass); $availableAdapters = Adapter::getAdapters(); $adapters = array(); foreach ($availableAdapters as $adapter => $port) { $adapters[$adapter] = $adapter; } $types = array('InnoDB' => 'InnoDB'); $this->addElement('text', 'host')->setLabel(Piwik::translate('Installation_DatabaseSetupServer'))->addRule('required', Piwik::translate('General_Required', Piwik::translate('Installation_DatabaseSetupServer'))); $user = $this->addElement('text', 'username')->setLabel(Piwik::translate('Installation_DatabaseSetupLogin')); $user->addRule('required', Piwik::translate('General_Required', Piwik::translate('Installation_DatabaseSetupLogin'))); $requiredPrivileges = Rule_checkUserPrivileges::getRequiredPrivilegesPretty(); $user->addRule('checkUserPrivileges', Piwik::translate('Installation_InsufficientPrivilegesMain', $requiredPrivileges . '<br/><br/>') . Piwik::translate('Installation_InsufficientPrivilegesHelp')); $this->addElement('password', 'password')->setLabel(Piwik::translate('General_Password')); $item = $this->addElement('text', 'dbname')->setLabel(Piwik::translate('Installation_DatabaseSetupDatabaseName')); $item->addRule('required', Piwik::translate('General_Required', Piwik::translate('Installation_DatabaseSetupDatabaseName'))); $item->addRule('checkValidFilename', Piwik::translate('General_NotValid', Piwik::translate('Installation_DatabaseSetupDatabaseName'))); $this->addElement('text', 'tables_prefix')->setLabel(Piwik::translate('Installation_DatabaseSetupTablePrefix'))->addRule('checkValidFilename', Piwik::translate('General_NotValid', Piwik::translate('Installation_DatabaseSetupTablePrefix'))); $this->addElement('select', 'adapter')->setLabel(Piwik::translate('Installation_DatabaseSetupAdapter'))->loadOptions($adapters)->addRule('required', Piwik::translate('General_Required', Piwik::translate('Installation_DatabaseSetupAdapter'))); $this->addElement('select', 'type')->setLabel(Piwik::translate('Installation_DatabaseSetupDatabaseEngine'))->loadOptions($types)->addRule('required', Piwik::translate('General_Required', Piwik::translate('Installation_DatabaseSetupDatabaseEngine'))); $this->addElement('submit', 'submit', array('value' => Piwik::translate('General_Next') . ' »', 'class' => 'submit')); // default values $this->addDataSource(new HTML_QuickForm2_DataSource_Array(array('host' => '127.0.0.1', 'tables_prefix' => 'piwik_'))); }
static function update($schema = 'Myisam') { // force regeneration of cache files following #648 Piwik::setUserIsSuperUser(); $allSiteIds = API::getInstance()->getAllSitesId(); Cache::regenerateCacheWebsiteAttributes($allSiteIds); }
/** * Constructor. */ public function __construct() { Piwik::postTestEvent("MySQLMetadataProvider.createDao", array(&$this->dataAccess)); if ($this->dataAccess === null) { $this->dataAccess = new MySQLMetadataDataAccess(); } }
public function registerWidgets() { if (PluginManager::getInstance()->isPluginActivated('UserCountry')) { WidgetsList::add('General_Visitors', Piwik::translate('UserCountryMap_VisitorMap'), 'UserCountryMap', 'visitorMap'); WidgetsList::add('Live!', Piwik::translate('UserCountryMap_RealTimeMap'), 'UserCountryMap', 'realtimeMap'); } }
protected function unprefixColumns(&$columns) { $columns = Piwik::getArrayFromApiParameter($columns); foreach ($columns as &$column) { $column = str_replace(self::COLUMN_SUFFIX, "", $column); } }
public function configureView(ViewDataTable $view) { $this->addBaseDisplayProperties($view); $this->addPresentationFilters($view); $view->config->title = $this->name; $view->config->addTranslation('label', Piwik::translate('Intl_PeriodYear')); }
public function setUp() { parent::setUp(); $self = $this; Piwik::addAction('API.Request.dispatch.end', function (&$return, $extra) use($self) { if ($extra['module'] !== 'Events') { return; } /** @var DataTable $return*/ // we make sure processed result is the same at any time foreach ($return as &$value) { $value->setColumn('sum_event_value', '2'); $value->setColumn('max_event_value', '2'); $value->setColumn('min_event_value', '2'); $value->setColumn('sum_daily_nb_uniq_visitors', '2'); $value->setColumn('avg_event_value', '2'); if ($value->isSubtableLoaded()) { $subtable = $value->getSubtable(); foreach ($subtable->getRows() as $row) { $row->setColumn('sum_event_value', '2'); $row->setColumn('max_event_value', '2'); $row->setColumn('min_event_value', '2'); $row->setColumn('sum_daily_nb_uniq_visitors', '2'); $row->setColumn('avg_event_value', '2'); } } } }); }
/** * DataTable filter callback that returns the HTML prefix for a label in the * 'getAll' report based on the row's referrer type. * * @param int $referrerType The referrer type. * @return string */ public function setGetAllHtmlPrefix($referrerType) { // get singular label for referrer type $indexTranslation = ''; switch ($referrerType) { case Common::REFERRER_TYPE_DIRECT_ENTRY: $indexTranslation = 'Referrers_DirectEntry'; break; case Common::REFERRER_TYPE_SEARCH_ENGINE: $indexTranslation = 'General_ColumnKeyword'; break; case Common::REFERRER_TYPE_WEBSITE: $indexTranslation = 'Referrers_ColumnWebsite'; break; case Common::REFERRER_TYPE_CAMPAIGN: $indexTranslation = 'Referrers_ColumnCampaign'; break; default: // case of newsletter, partners, before Piwik 0.2.25 $indexTranslation = 'General_Others'; break; } $label = strtolower(Piwik::translate($indexTranslation)); // return html that displays it as grey & italic return '<span class="datatable-label-category"><em>(' . $label . ')</em></span>'; }
protected function retrieveFileLocations() { /** * Triggered when gathering the list of all stylesheets (CSS and LESS) needed by * Piwik and its plugins. * * Plugins that have stylesheets should use this event to make those stylesheets * load. * * Stylesheets should be placed within a **stylesheets** subdirectory in your plugin's * root directory. * * **Example** * * public function getStylesheetFiles(&$stylesheets) * { * $stylesheets[] = "plugins/MyPlugin/stylesheets/myfile.less"; * $stylesheets[] = "plugins/MyPlugin/stylesheets/myotherfile.css"; * } * * @param string[] &$stylesheets The list of stylesheet paths. */ Piwik::postEvent('AssetManager.getStylesheetFiles', array(&$this->fileLocations)); $this->addThemeFiles(); }
public function configureAdminMenu(MenuAdmin $menu) { if (Piwik::isUserHasSomeAdminAccess()) { $menu->addManageItem('UsersManager_MenuUsers', array('module' => 'UsersManager', 'action' => 'index'), $order = 2); $menu->addManageItem('UsersManager_MenuUserSettings', array('module' => 'UsersManager', 'action' => 'userSettings'), $order = 3); } }
protected function configureSegmentsFor($segmentNameSuffix) { $numCustomVariables = CustomVariables::getNumUsableCustomVariables(); $segment = new Segment(); $segment->setType('dimension'); $segment->setSegment('customVariable' . $segmentNameSuffix); $segment->setName($this->getName() . ' (' . Piwik::translate('CustomVariables_ScopeVisit') . ')'); $segment->setUnionOfSegments($this->getSegmentColumns('customVariable' . $segmentNameSuffix, $numCustomVariables)); $this->addSegment($segment); $segment = new Segment(); $segment->setType('dimension'); $segment->setSegment('customVariablePage' . $segmentNameSuffix); $segment->setName($this->getName() . ' (' . Piwik::translate('CustomVariables_ScopePage') . ')'); $segment->setUnionOfSegments($this->getSegmentColumns('customVariablePage' . $segmentNameSuffix, $numCustomVariables)); $this->addSegment($segment); $segmentSuffix = 'v'; if (strtolower($segmentNameSuffix) === 'name') { $segmentSuffix = 'k'; } for ($i = 1; $i <= $numCustomVariables; $i++) { $segment = new Segment(); $segment->setSegment('customVariable' . $segmentNameSuffix . $i); $segment->setSqlSegment('log_visit.custom_var_' . $segmentSuffix . $i); $segment->setName(Piwik::translate('CustomVariables_ColumnCustomVariable' . $segmentNameSuffix) . ' ' . $i . ' (' . Piwik::translate('CustomVariables_ScopeVisit') . ')'); $this->addSegment($segment); $segment = new Segment(); $segment->setSegment('customVariablePage' . $segmentNameSuffix . $i); $segment->setSqlSegment('log_link_visit_action.custom_var_' . $segmentSuffix . $i); $segment->setName(Piwik::translate('CustomVariables_ColumnCustomVariable' . $segmentNameSuffix) . ' ' . $i . ' (' . Piwik::translate('CustomVariables_ScopePage') . ')'); $this->addSegment($segment); } }
public static function configure(WidgetConfig $config) { $config->setCategoryId('About Piwik'); $config->setName('Installation_SystemCheck'); $config->setOrder(16); $config->setIsEnabled(Piwik::hasUserSuperUserAccess()); }
function getTopMenuTranslationKey() { // if MobileMessaging is not activated, display 'Email reports' if (!\Piwik\Plugin\Manager::getInstance()->isPluginActivated('MobileMessaging')) { return self::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY; } if (Piwik::isUserIsAnonymous()) { return self::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY; } try { $reports = API::getInstance()->getReports(); $reportCount = count($reports); // if there are no reports and the mobile account is // - not configured: display 'Email reports' // - configured: display 'Email & SMS reports' if ($reportCount == 0) { return APIMobileMessaging::getInstance()->areSMSAPICredentialProvided() ? self::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY : self::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY; } } catch (\Exception $e) { return self::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY; } $anyMobileReport = false; foreach ($reports as $report) { if ($report['type'] == MobileMessaging::MOBILE_TYPE) { $anyMobileReport = true; break; } } // if there is at least one sms report, display 'Email & SMS reports' if ($anyMobileReport) { return self::MOBILE_MESSAGING_TOP_MENU_TRANSLATION_KEY; } return self::PDF_REPORTS_TOP_MENU_TRANSLATION_KEY; }
protected function getMetricsDocumentation() { $metrics = parent::getMetricsDocumentation(); $metrics['nb_visits'] = Piwik::translate('General_ColumnUniquePageviewsDocumentation'); $metrics['bounce_rate'] = Piwik::translate('General_ColumnPageBounceRateDocumentation'); return $metrics; }
public function getProvider() { if (isset($this->details['location_provider'])) { return $this->details['location_provider']; } return Piwik::translate('General_Unknown'); }
/** * @return array */ protected function getFooterMessageExplanationMissingMetrics() { $metrics = sprintf("'%s', '%s' %s '%s'", Piwik::translate('General_ColumnNbVisits'), Piwik::translate('General_ColumnNbUniqVisitors'), Piwik::translate('General_And'), Piwik::translate('General_ColumnNbUsers')); $messageStart = Piwik::translate('CustomVariables_MetricsAreOnlyAvailableForVisitScope', array($metrics, "'visit'")); $messageEnd = Piwik::translate('CustomVariables_MetricsNotAvailableForPageScope', array("'page'", '\'-\'')); return $messageStart . ' ' . $messageEnd; }
public static function getDatabaseConfig($dbConfig = null) { $config = Config::getInstance(); if (is_null($dbConfig)) { $dbConfig = $config->database; } /** * Triggered before a database connection is established. * * This event can be used to change the settings used to establish a connection. * * @param array *$dbInfos Reference to an array containing database connection info, * including: * * - **host**: The host name or IP address to the MySQL database. * - **username**: The username to use when connecting to the * database. * - **password**: The password to use when connecting to the * database. * - **dbname**: The name of the Piwik MySQL database. * - **port**: The MySQL database port to use. * - **adapter**: either `'PDO\MYSQL'` or `'MYSQLI'` * - **type**: The MySQL engine to use, for instance 'InnoDB' */ Piwik::postEvent('Db.getDatabaseConfig', array(&$dbConfig)); $dbConfig['profiler'] = @$config->Debug['enable_sql_profiler']; return $dbConfig; }
protected function getNumeric($idSite, $period, $date, $segment, $toFetch) { Piwik::checkUserHasViewAccess($idSite); $archive = Archive::build($idSite, $period, $date, $segment); $dataTable = $archive->getDataTableFromNumeric($toFetch); return $dataTable; }
/** * @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; }
/** * @param $strPeriod * @throws \Exception */ private static function throwExceptionInvalidPeriod($strPeriod) { $periods = self::getPeriodsEnabledForAPI(); $periods = implode(", ", $periods); $message = Piwik::translate('General_ExceptionInvalidPeriod', array($strPeriod, $periods)); throw new Exception($message); }
protected function init() { parent::init(); $this->name = Piwik::translate('ExampleReportName'); $this->dimension = new ExitPageUrl(); $this->documentation = Piwik::translate('ExampleReportDocumentation'); // This defines in which order your report appears in the mobile app, in the menu and in the list of widgets $this->order = 999; // By default standard metrics are defined but you can customize them by defining an array of metric names // $this->metrics = array('nb_visits', 'nb_hits'); // Uncomment the next line if your report does not contain any processed metrics, otherwise default // processed metrics will be assigned // $this->processedMetrics = array(); // Uncomment the next line if your report defines goal metrics // $this->hasGoalMetrics = true; // Uncomment the next line if your report should be able to load subtables. You can define any action here // $this->actionToLoadSubTables = $this->action; // Uncomment the next line if your report always returns a constant count of rows, for instance always // 24 rows for 1-24hours // $this->constantRowsCount = true; // If a menu title is specified, the report will be displayed in the menu // $this->menuTitle = 'ExampleReportName'; // If a widget title is specified, the report will be displayed in the list of widgets and the report can be // exported as a widget // $this->widgetTitle = 'ExampleReportName'; }
/** * Returns a list of available command classnames. * * @return string[] */ private function getAvailableCommands() { $commands = $this->getDefaultPiwikCommands(); $detected = PluginManager::getInstance()->findMultipleComponents('Commands', 'Piwik\\Plugin\\ConsoleCommand'); $commands = array_merge($commands, $detected); /** * Triggered to filter / restrict console commands. Plugins that want to restrict commands * should subscribe to this event and remove commands from the existing list. * * **Example** * * public function filterConsoleCommands(&$commands) * { * $key = array_search('Piwik\Plugins\MyPlugin\Commands\MyCommand', $commands); * if (false !== $key) { * unset($commands[$key]); * } * } * * @param array &$commands An array containing a list of command class names. */ Piwik::postEvent('Console.filterCommands', array(&$commands)); $commands = array_values(array_unique($commands)); return $commands; }
public function getRowEvolution($idSite, $period, $date, $apiModule, $apiAction, $label = false, $segment = false, $column = false, $language = false, $idGoal = false, $legendAppendMetric = true, $labelUseAbsoluteUrl = true) { // validation of requested $period & $date if ($period == 'range') { // load days in the range $period = 'day'; } if (!Period::isMultiplePeriod($date, $period)) { throw new Exception("Row evolutions can not be processed with this combination of \\'date\\' and \\'period\\' parameters."); } $label = ResponseBuilder::unsanitizeLabelParameter($label); $labels = Piwik::getArrayFromApiParameter($label); $metadata = $this->getRowEvolutionMetaData($idSite, $period, $date, $apiModule, $apiAction, $language, $idGoal); $dataTable = $this->loadRowEvolutionDataFromAPI($metadata, $idSite, $period, $date, $apiModule, $apiAction, $labels, $segment, $idGoal); if (empty($labels)) { $labels = $this->getLabelsFromDataTable($dataTable, $labels); $dataTable = $this->enrichRowAddMetadataLabelIndex($labels, $dataTable); } if (count($labels) != 1) { $data = $this->getMultiRowEvolution($dataTable, $metadata, $apiModule, $apiAction, $labels, $column, $legendAppendMetric, $labelUseAbsoluteUrl); } else { $data = $this->getSingleRowEvolution($idSite, $dataTable, $metadata, $apiModule, $apiAction, $labels[0], $labelUseAbsoluteUrl); } return $data; }
public function index() { Piwik::checkUserIsNotAnonymous(); $view = new View('@MobileMessaging/index'); $view->isSuperUser = Piwik::hasUserSuperUserAccess(); $mobileMessagingAPI = API::getInstance(); $view->delegatedManagement = $mobileMessagingAPI->getDelegatedManagement(); $view->credentialSupplied = $mobileMessagingAPI->areSMSAPICredentialProvided(); $view->accountManagedByCurrentUser = $view->isSuperUser || $view->delegatedManagement; $view->strHelpAddPhone = Piwik::translate('MobileMessaging_Settings_PhoneNumbers_HelpAdd', array(Piwik::translate('General_Settings'), Piwik::translate('MobileMessaging_SettingsMenu'))); if ($view->credentialSupplied && $view->accountManagedByCurrentUser) { $view->provider = $mobileMessagingAPI->getSMSProvider(); $view->creditLeft = $mobileMessagingAPI->getCreditLeft(); } $view->smsProviders = SMSProvider::$availableSMSProviders; // construct the list of countries from the lang files $countries = array(); foreach (Common::getCountriesList() as $countryCode => $continentCode) { if (isset(CountryCallingCodes::$countryCallingCodes[$countryCode])) { $countries[$countryCode] = array('countryName' => \Piwik\Plugins\UserCountry\countryTranslate($countryCode), 'countryCallingCode' => CountryCallingCodes::$countryCallingCodes[$countryCode]); } } $view->countries = $countries; $view->defaultCountry = Common::getCountry(LanguagesManager::getLanguageCodeForCurrentUser(), true, IP::getIpFromHeader()); $view->phoneNumbers = $mobileMessagingAPI->getPhoneNumbers(); $this->setBasicVariablesView($view); return $view->render(); }
public function configureTopMenu(MenuTop $menu) { if (Piwik::isUserIsAnonymous() || !SettingsPiwik::isPiwikInstalled()) { $langManager = new LanguagesManager(); $menu->addHtml('LanguageSelector', $langManager->getLanguagesSelector(), true, $order = 30, false); } }
public function configureView(ViewDataTable $view) { $view->config->title = $this->name; $view->config->show_search = false; $view->config->show_exclude_low_population = false; $view->config->addTranslation('label', Piwik::translate("DevicesDetection_dataTableLabelSystemVersion")); }