コード例 #1
0
 public function getSelector()
 {
     $view = new View('@SegmentEditor/getSelector');
     $idSite = Common::getRequestVar('idSite');
     $this->setGeneralVariablesView($view);
     $segments = APIMetadata::getInstance()->getSegmentsMetadata($idSite);
     $segmentsByCategory = $customVariablesSegments = array();
     foreach ($segments as $segment) {
         if ($segment['category'] == Piwik::translate('General_Visit') && ($segment['type'] == 'metric' && $segment['segment'] != 'visitIp')) {
             $metricsLabel = Piwik::translate('General_Metrics');
             $metricsLabel[0] = strtolower($metricsLabel[0]);
             $segment['category'] .= ' (' . $metricsLabel . ')';
         }
         $segmentsByCategory[$segment['category']][] = $segment;
     }
     uksort($segmentsByCategory, array($this, 'sortSegmentCategories'));
     $view->segmentsByCategory = $segmentsByCategory;
     $savedSegments = API::getInstance()->getAll($idSite);
     foreach ($savedSegments as &$savedSegment) {
         $savedSegment['name'] = Common::sanitizeInputValue($savedSegment['name']);
     }
     $view->savedSegmentsJson = Common::json_encode($savedSegments);
     $view->authorizedToCreateSegments = !Piwik::isUserIsAnonymous();
     $view->segmentTranslations = Common::json_encode($this->getTranslations());
     $out = $view->render();
     return $out;
 }
コード例 #2
0
 /**
  * Constructor.
  */
 public function __construct($idSite = false)
 {
     parent::__construct();
     $this->jsClass = "SegmentSelectorControl";
     $this->cssIdentifier = "segmentEditorPanel";
     $this->cssClass = "piwikTopControl";
     $this->idSite = $idSite ?: Common::getRequestVar('idSite', false, 'int');
     $this->selectedSegment = Common::getRequestVar('segment', false, 'string');
     $segments = APIMetadata::getInstance()->getSegmentsMetadata($this->idSite);
     $segmentsByCategory = $customVariablesSegments = array();
     foreach ($segments as $segment) {
         if ($segment['category'] == Piwik::translate('General_Visit') && ($segment['type'] == 'metric' && $segment['segment'] != 'visitIp')) {
             $metricsLabel = Piwik::translate('General_Metrics');
             $metricsLabel[0] = strtolower($metricsLabel[0]);
             $segment['category'] .= ' (' . $metricsLabel . ')';
         }
         $segmentsByCategory[$segment['category']][] = $segment;
     }
     uksort($segmentsByCategory, array($this, 'sortSegmentCategories'));
     $this->createRealTimeSegmentsIsEnabled = Config::getInstance()->General['enable_create_realtime_segments'];
     $this->segmentsByCategory = $segmentsByCategory;
     $this->nameOfCurrentSegment = '';
     $this->isSegmentNotAppliedBecauseBrowserArchivingIsDisabled = 0;
     $this->availableSegments = API::getInstance()->getAll($this->idSite);
     foreach ($this->availableSegments as &$savedSegment) {
         $savedSegment['name'] = Common::sanitizeInputValue($savedSegment['name']);
         if (!empty($this->selectedSegment) && $this->selectedSegment == $savedSegment['definition']) {
             $this->nameOfCurrentSegment = $savedSegment['name'];
             $this->isSegmentNotAppliedBecauseBrowserArchivingIsDisabled = $this->wouldApplySegment($savedSegment) ? 0 : 1;
         }
     }
     $this->authorizedToCreateSegments = SegmentEditorAPI::getInstance()->isUserCanAddNewSegment($this->idSite);
     $this->isUserAnonymous = Piwik::isUserIsAnonymous();
     $this->segmentTranslations = $this->getTranslations();
 }
コード例 #3
0
 public function getKnownSegmentsToArchiveForSite(&$segments, $idSite)
 {
     $segmentToAutoArchive = API::getInstance()->getAll($idSite, $returnAutoArchived = true);
     foreach ($segmentToAutoArchive as $segmentInfo) {
         $segments[] = $segmentInfo['definition'];
     }
     $segments = array_unique($segments);
 }
コード例 #4
0
ファイル: ApiTest.php プロジェクト: diosmosis/piwik
 /**
  * @return bool|int
  */
 protected function createSegments()
 {
     $this->setAdminUser();
     $this->api->add('segment 1', 'visitCount<2', $idSite = 1, $autoArchive = true, $enableAllUsers = false);
     $this->api->add('segment 2', 'countryCode==fr', $idSite = 2, $autoArchive = false, $enableAllUsers = false);
     $this->api->add('segment 3', 'visitCount<2', $idSite = 1, $autoArchive = true, $enableAllUsers = false);
     $this->setSuperUser();
     $this->api->add('segment 4', 'countryCode!=fr', $idSite = false, $autoArchive = false, $enableAllUsers = false);
     $this->api->add('segment 5', 'countryCode!=fr', $idSite = 1, $autoArchive = false, $enableAllUsers = true);
     $this->api->add('segment 6', 'visitCount<2', $idSite = 2, $autoArchive = true, $enableAllUsers = true);
     $this->setAdminUser();
     $this->api->add('segment 7', 'visitCount<2', $idSite = 1, $autoArchive = true, $enableAllUsers = false);
     $this->setAnotherAdminUser();
     $this->api->add('segment 8', 'visitCount<2', $idSite = 1, $autoArchive = true, $enableAllUsers = false);
     $this->setAnotherSuperUser();
     $this->api->add('segment 9', 'countryCode!=fr', $idSite = false, $autoArchive = false, $enableAllUsers = true);
 }
コード例 #5
0
ファイル: Controller.php プロジェクト: carriercomm/piwik
 public function index()
 {
     $view = new View('@ScheduledReports/index');
     $this->setGeneralVariablesView($view);
     $view->countWebsites = count(APISitesManager::getInstance()->getSitesIdWithAtLeastViewAccess());
     // get report types
     $reportTypes = API::getReportTypes();
     $view->reportTypes = $reportTypes;
     $view->defaultReportType = self::DEFAULT_REPORT_TYPE;
     $view->defaultReportFormat = ScheduledReports::DEFAULT_REPORT_FORMAT;
     $view->displayFormats = ScheduledReports::getDisplayFormats();
     $reportsByCategoryByType = array();
     $reportFormatsByReportType = array();
     $allowMultipleReportsByReportType = array();
     foreach ($reportTypes as $reportType => $reportTypeIcon) {
         // get report formats
         $reportFormatsByReportType[$reportType] = API::getReportFormats($reportType);
         $allowMultipleReportsByReportType[$reportType] = API::allowMultipleReports($reportType);
         // get report metadata
         $reportsByCategory = array();
         $availableReportMetadata = API::getReportMetadata($this->idSite, $reportType);
         foreach ($availableReportMetadata as $reportMetadata) {
             $reportsByCategory[$reportMetadata['category']][] = $reportMetadata;
         }
         $reportsByCategoryByType[$reportType] = $reportsByCategory;
     }
     $view->reportsByCategoryByReportType = $reportsByCategoryByType;
     $view->reportFormatsByReportType = $reportFormatsByReportType;
     $view->allowMultipleReportsByReportType = $allowMultipleReportsByReportType;
     $reports = array();
     $reportsById = array();
     if (!Piwik::isUserIsAnonymous()) {
         $reports = API::getInstance()->getReports($this->idSite, $period = false, $idReport = false, $ifSuperUserReturnOnlySuperUserReports = true);
         foreach ($reports as &$report) {
             $report['recipients'] = API::getReportRecipients($report);
             $reportsById[$report['idreport']] = $report;
         }
     }
     $view->reports = $reports;
     $view->reportsJSON = Common::json_encode($reportsById);
     $view->downloadOutputType = API::OUTPUT_INLINE;
     $view->periods = ScheduledReports::getPeriodToFrequency();
     $view->defaultPeriod = ScheduledReports::DEFAULT_PERIOD;
     $view->defaultHour = ScheduledReports::DEFAULT_HOUR;
     $view->language = LanguagesManager::getLanguageCodeForCurrentUser();
     $view->segmentEditorActivated = false;
     if (API::isSegmentEditorActivated()) {
         $savedSegmentsById = array();
         foreach (APISegmentEditor::getInstance()->getAll($this->idSite) as $savedSegment) {
             $savedSegmentsById[$savedSegment['idsegment']] = $savedSegment['name'];
         }
         $view->savedSegmentsById = $savedSegmentsById;
         $view->segmentEditorActivated = true;
     }
     return $view->render();
 }
 public function test_getServerVisitCustomVariables_shouldReturnSystemReport()
 {
     FakeAccess::clearAccess($superUser = true);
     for ($i = 1; $i < 15; $i++) {
         if (!Fixture::siteCreated($i)) {
             Fixture::createWebsite('2014-01-01 00:00:00');
         }
     }
     for ($i = 1; $i < 9; $i++) {
         UsersApi::getInstance()->addUser($login = '******' . $i, 'password0815', "lorem{$i}@piwik.org");
     }
     for ($i = 1; $i < 5; $i++) {
         SegmentApi::getInstance()->add('Segment' . $i, 'pageUrl%3D@inde');
     }
     $customVars = array(array('id' => 1, 'name' => 'Piwik Version', 'value' => '2.14.3'), array('id' => 2, 'name' => 'PHP Version', 'value' => '5.5.27'), array('id' => 3, 'name' => 'Num Users', 'value' => 8), array('id' => 4, 'name' => 'Num Websites', 'value' => 14), array('id' => 5, 'name' => 'Num Segments', 'value' => 4), array('id' => 6, 'name' => 'MySQL Version', 'value' => Db::get()->getServerVersion()));
     $this->assertSame($customVars, $this->customVars->getServerVisitCustomVariables());
 }
コード例 #7
0
 /**
  * Constructor.
  */
 public function __construct($idSite = false)
 {
     parent::__construct();
     $this->jsClass = "SegmentSelectorControl";
     $this->cssIdentifier = "segmentEditorPanel";
     $this->cssClass = "piwikTopControl borderedControl piwikSelector";
     $this->idSite = $idSite ?: Common::getRequestVar('idSite', false, 'int');
     $this->selectedSegment = Common::getRequestVar('segment', false, 'string');
     $formatter = StaticContainer::get('Piwik\\Plugins\\SegmentEditor\\SegmentFormatter');
     $this->segmentDescription = $formatter->getHumanReadable(Request::getRawSegmentFromRequest(), $this->idSite);
     $this->isAddingSegmentsForAllWebsitesEnabled = SegmentEditor::isAddingSegmentsForAllWebsitesEnabled();
     $segments = APIMetadata::getInstance()->getSegmentsMetadata($this->idSite);
     $visitTitle = Piwik::translate('General_Visit');
     $segmentsByCategory = array();
     foreach ($segments as $segment) {
         if ($segment['category'] == $visitTitle && ($segment['type'] == 'metric' && $segment['segment'] != 'visitIp')) {
             $metricsLabel = Piwik::translate('General_Metrics');
             $metricsLabel[0] = Common::mb_strtolower($metricsLabel[0]);
             $segment['category'] .= ' (' . $metricsLabel . ')';
         }
         $segmentsByCategory[$segment['category']][] = $segment;
     }
     $this->createRealTimeSegmentsIsEnabled = Config::getInstance()->General['enable_create_realtime_segments'];
     $this->segmentsByCategory = $segmentsByCategory;
     $this->nameOfCurrentSegment = '';
     $this->isSegmentNotAppliedBecauseBrowserArchivingIsDisabled = 0;
     $this->availableSegments = API::getInstance()->getAll($this->idSite);
     foreach ($this->availableSegments as &$savedSegment) {
         $savedSegment['name'] = Common::sanitizeInputValue($savedSegment['name']);
         if (!empty($this->selectedSegment) && $this->selectedSegment == $savedSegment['definition']) {
             $this->nameOfCurrentSegment = $savedSegment['name'];
             $this->isSegmentNotAppliedBecauseBrowserArchivingIsDisabled = $this->wouldApplySegment($savedSegment) ? 0 : 1;
         }
     }
     $this->authorizedToCreateSegments = SegmentEditorAPI::getInstance()->isUserCanAddNewSegment($this->idSite);
     $this->isUserAnonymous = Piwik::isUserIsAnonymous();
     $this->segmentTranslations = $this->getTranslations();
     $this->segmentProcessedOnRequest = Rules::isBrowserArchivingAvailableForSegments();
     $this->hideSegmentDefinitionChangeMessage = UsersManagerAPI::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), 'hideSegmentDefinitionChangeMessage');
 }
コード例 #8
0
 /**
  * @group Plugins
  */
 public function test_deleteSegment()
 {
     $idSegment1 = API::getInstance()->add('name 1', 'searches==0', $idSite = 1, $autoArchive = 1, $enabledAllUsers = 1);
     $idSegment2 = API::getInstance()->add('name 2', 'searches>1,visitIp!=127.0.0.1', $idSite = 1, $autoArchive = 1, $enabledAllUsers = 1);
     $deleted = API::getInstance()->delete($idSegment2);
     $this->assertTrue($deleted);
     try {
         API::getInstance()->get($idSegment2);
         $this->fail("getting deleted segment should have failed");
     } catch (Exception $e) {
         // expected
     }
     // and this should work
     API::getInstance()->get($idSegment1);
 }
コード例 #9
0
 public function createSegments()
 {
     Db::exec("TRUNCATE TABLE " . Common::prefixTable('segment'));
     $segmentName = self::makeXssContent('segment');
     $segmentDefinition = "browserCode==FF";
     APISegmentEditor::getInstance()->add($segmentName, $segmentDefinition, $idSite = 1, $autoArchive = true, $enabledAllUsers = true);
     // create two more segments
     APISegmentEditor::getInstance()->add("From Europe", "continentCode==eur", $idSite = 1, $autoArchive = false, $enabledAllUsers = true);
     APISegmentEditor::getInstance()->add("Multiple actions", "actions>=2", $idSite = 1, $autoArchive = false, $enabledAllUsers = true);
 }
コード例 #10
0
 private function setupSegments()
 {
     if (!$this->addSegments) {
         return;
     }
     if ($this->segments === null) {
         $this->segments = $this->getDefaultSegments();
     }
     foreach ($this->segments as $segmentName => $info) {
         $idSite = false;
         if (isset($info['idSite'])) {
             $idSite = $info['idSite'];
         }
         $autoArchive = true;
         if (isset($info['autoArchive'])) {
             $autoArchive = $info['autoArchive'];
         }
         $enabledAllUsers = true;
         if (isset($info['enabledAllUsers'])) {
             $enabledAllUsers = $info['enabledAllUsers'];
         }
         APISegmentEditor::getInstance()->add($segmentName, $info['definition'], $idSite, $autoArchive, $enabledAllUsers);
     }
 }
コード例 #11
0
ファイル: CronArchiveTest.php プロジェクト: hichnik/piwik
    public function test_output()
    {
        \Piwik\Tests\Framework\Mock\FakeCliMulti::$specifiedResults = array('/method=API.get/' => serialize(array(array('nb_visits' => 1))));
        Fixture::createWebsite('2014-12-12 00:01:02');
        SegmentAPI::getInstance()->add('foo', 'actions>=2', 1, true, true);
        SegmentAPI::getInstance()->add('burr', 'actions>=4', 1, true, true);
        $logger = new FakeLogger();
        $archiver = new CronArchive(null, $logger);
        $archiver->shouldArchiveAllSites = true;
        $archiver->shouldArchiveAllPeriodsSince = true;
        $archiver->segmentsToForce = array('actions>=2;browserCode=FF', 'actions>=2');
        $archiver->init();
        $archiver->run();
        $expected = <<<LOG
---------------------------
INIT
Running Piwik %s as Super User
---------------------------
NOTES
- If you execute this script at least once per hour (or more often) in a crontab, you may disable 'Browser trigger archiving' in Piwik UI > Settings > General Settings.
  See the doc at: http://piwik.org/docs/setup-auto-archiving/
- Reports for today will be processed at most every %s seconds. You can change this value in Piwik UI > Settings > General Settings.
- Reports for the current week/month/year will be refreshed at most every %s seconds.
- Will process all 1 websites
- Limiting segment archiving to following segments:
  * actions>=2;browserCode=FF
  * actions>=2
---------------------------
START
Starting Piwik reports archiving...
Will pre-process for website id = 1, day period
- pre-processing all visits
- skipping segment archiving for 'actions>=4'.
- pre-processing segment 1/1 actions>=2
Archived website id = 1, period = day, 1 segments, 0 visits in last %s days, 0 visits today, Time elapsed: %s
Will pre-process for website id = 1, week period
- pre-processing all visits
- skipping segment archiving for 'actions>=4'.
- pre-processing segment 1/1 actions>=2
Archived website id = 1, period = week, 1 segments, 1 visits in last %s weeks, 1 visits this week, Time elapsed: %s
Will pre-process for website id = 1, month period
- pre-processing all visits
- skipping segment archiving for 'actions>=4'.
- pre-processing segment 1/1 actions>=2
Archived website id = 1, period = month, 1 segments, 1 visits in last %s months, 1 visits this month, Time elapsed: %s
Will pre-process for website id = 1, year period
- pre-processing all visits
- skipping segment archiving for 'actions>=4'.
- pre-processing segment 1/1 actions>=2
Archived website id = 1, period = year, 1 segments, 1 visits in last %s years, 1 visits this year, Time elapsed: %s
Archived website id = 1, %s API requests, Time elapsed: %s [1/1 done]
Done archiving!
---------------------------
SUMMARY
Total visits for today across archived websites: 1
Archived today's reports for 1 websites
Archived week/month/year for 1 websites
Skipped 0 websites: no new visit since the last script execution
Skipped 0 websites day archiving: existing daily reports are less than 150 seconds old
Skipped 0 websites week/month/year archiving: existing periods reports are less than 3600 seconds old
Total API requests: %s
done: 1/1 100%, 1 vtoday, 1 wtoday, 1 wperiods, %s req, %s ms, no error
Time elapsed: %s

LOG;
        $this->assertStringMatchesFormat($expected, $logger->output);
    }
コード例 #12
0
ファイル: API.php プロジェクト: carriercomm/piwik
 /**
  * @ignore
  */
 public static function getSegment($idSegment)
 {
     if (self::isSegmentEditorActivated() && !empty($idSegment)) {
         $segment = APISegmentEditor::getInstance()->get($idSegment);
         if ($segment) {
             return $segment;
         }
     }
     return null;
 }