Beispiel #1
0
 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();
 }
Beispiel #2
0
 private function setManageVariables(View $view)
 {
     $view->isSuperUser = Piwik::hasUserSuperUserAccess();
     $mobileMessagingAPI = API::getInstance();
     $view->delegatedManagement = $mobileMessagingAPI->getDelegatedManagement();
     $view->credentialSupplied = $mobileMessagingAPI->areSMSAPICredentialProvided();
     $view->accountManagedByCurrentUser = $view->isSuperUser || $view->delegatedManagement;
     $view->strHelpAddPhone = $this->translator->translate('MobileMessaging_Settings_PhoneNumbers_HelpAdd', array($this->translator->translate('General_Settings'), $this->translator->translate('MobileMessaging_SettingsMenu')));
     $view->creditLeft = 0;
     $currentProvider = '';
     if ($view->credentialSupplied && $view->accountManagedByCurrentUser) {
         $currentProvider = $mobileMessagingAPI->getSMSProvider();
         $view->creditLeft = $mobileMessagingAPI->getCreditLeft();
     }
     $view->delegateManagementOptions = array(array('key' => '0', 'value' => Piwik::translate('General_No'), 'description' => Piwik::translate('General_Default') . '. ' . Piwik::translate('MobileMessaging_Settings_LetUsersManageAPICredential_No_Help')), array('key' => '1', 'value' => Piwik::translate('General_Yes'), 'description' => Piwik::translate('MobileMessaging_Settings_LetUsersManageAPICredential_Yes_Help')));
     $providers = array();
     $providerOptions = array();
     foreach (SMSProvider::findAvailableSmsProviders() as $provider) {
         if (empty($currentProvider)) {
             $currentProvider = $provider->getId();
         }
         $providers[$provider->getId()] = $provider->getDescription();
         $providerOptions[$provider->getId()] = $provider->getId();
     }
     $view->provider = $currentProvider;
     $view->smsProviders = $providers;
     $view->smsProviderOptions = $providerOptions;
     $defaultCountry = Common::getCountry(LanguagesManager::getLanguageCodeForCurrentUser(), true, IP::getIpFromHeader());
     $view->defaultCallingCode = '';
     // construct the list of countries from the lang files
     $countries = array(array('key' => '', 'value' => ''));
     foreach ($this->regionDataProvider->getCountryList() as $countryCode => $continentCode) {
         if (isset(CountryCallingCodes::$countryCallingCodes[$countryCode])) {
             if ($countryCode == $defaultCountry) {
                 $view->defaultCallingCode = CountryCallingCodes::$countryCallingCodes[$countryCode];
             }
             $countries[] = array('key' => CountryCallingCodes::$countryCallingCodes[$countryCode], 'value' => \Piwik\Plugins\UserCountry\countryTranslate($countryCode));
         }
     }
     $view->countries = $countries;
     $view->phoneNumbers = $mobileMessagingAPI->getPhoneNumbers();
     $this->setBasicVariablesView($view);
 }
Beispiel #3
0
 /**
  * Returns an array describing a visitor using her last visits (uses a maximum of 100).
  *
  * @param int $idSite Site ID
  * @param bool|false|string $visitorId The ID of the visitor whose profile to retrieve.
  * @param bool|false|string $segment
  * @param bool $checkForLatLong If true, hasLatLong will appear in the output and be true if
  *                              one of the first 100 visits has a latitude/longitude.
  * @return array
  */
 public function getVisitorProfile($idSite, $visitorId = false, $segment = false, $checkForLatLong = false)
 {
     Piwik::checkUserHasViewAccess($idSite);
     if ($visitorId === false) {
         $visitorId = $this->getMostRecentVisitorId($idSite, $segment);
     }
     $newSegment = ($segment === false ? '' : $segment . ';') . 'visitorId==' . $visitorId;
     $visits = $this->loadLastVisitorDetailsFromDatabase($idSite, $period = false, $date = false, $newSegment, $numVisitorsToFetch = self::VISITOR_PROFILE_MAX_VISITS_TO_AGGREGATE, $overrideVisitorId = false, $minTimestamp = false);
     $this->addFilterToCleanVisitors($visits, $idSite, $flat = false, $doNotFetchActions = false, $filterNow = true);
     if ($visits->getRowsCount() == 0) {
         return array();
     }
     $isEcommerceEnabled = Site::isEcommerceEnabledFor($idSite);
     $result = array();
     $result['totalVisits'] = 0;
     $result['totalVisitDuration'] = 0;
     $result['totalActions'] = 0;
     $result['totalSearches'] = 0;
     $result['totalPageViews'] = 0;
     $result['totalGoalConversions'] = 0;
     $result['totalConversionsByGoal'] = array();
     if ($isEcommerceEnabled) {
         $result['totalEcommerceConversions'] = 0;
         $result['totalEcommerceRevenue'] = 0;
         $result['totalEcommerceItems'] = 0;
         $result['totalAbandonedCarts'] = 0;
         $result['totalAbandonedCartsRevenue'] = 0;
         $result['totalAbandonedCartsItems'] = 0;
     }
     $countries = array();
     $continents = array();
     $cities = array();
     $siteSearchKeywords = array();
     $pageGenerationTimeTotal = 0;
     // aggregate all requested visits info for total_* info
     foreach ($visits->getRows() as $visit) {
         ++$result['totalVisits'];
         $result['totalVisitDuration'] += $visit->getColumn('visitDuration');
         $result['totalActions'] += $visit->getColumn('actions');
         $result['totalGoalConversions'] += $visit->getColumn('goalConversions');
         // individual goal conversions are stored in action details
         foreach ($visit->getColumn('actionDetails') as $action) {
             if ($action['type'] == 'goal') {
                 // handle goal conversion
                 $idGoal = $action['goalId'];
                 $idGoalKey = 'idgoal=' . $idGoal;
                 if (!isset($result['totalConversionsByGoal'][$idGoalKey])) {
                     $result['totalConversionsByGoal'][$idGoalKey] = 0;
                 }
                 ++$result['totalConversionsByGoal'][$idGoalKey];
                 if (!empty($action['revenue'])) {
                     if (!isset($result['totalRevenueByGoal'][$idGoalKey])) {
                         $result['totalRevenueByGoal'][$idGoalKey] = 0;
                     }
                     $result['totalRevenueByGoal'][$idGoalKey] += $action['revenue'];
                 }
             } else {
                 if ($action['type'] == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER && $isEcommerceEnabled) {
                     ++$result['totalEcommerceConversions'];
                     $result['totalEcommerceRevenue'] += $action['revenue'];
                     $result['totalEcommerceItems'] += $action['items'];
                 } else {
                     if ($action['type'] == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART && $isEcommerceEnabled) {
                         ++$result['totalAbandonedCarts'];
                         $result['totalAbandonedCartsRevenue'] += $action['revenue'];
                         $result['totalAbandonedCartsItems'] += $action['items'];
                     }
                 }
             }
             if (isset($action['siteSearchKeyword'])) {
                 $keyword = $action['siteSearchKeyword'];
                 if (!isset($siteSearchKeywords[$keyword])) {
                     $siteSearchKeywords[$keyword] = 0;
                     ++$result['totalSearches'];
                 }
                 ++$siteSearchKeywords[$keyword];
             }
             if (isset($action['generationTime'])) {
                 $pageGenerationTimeTotal += $action['generationTime'];
                 ++$result['totalPageViews'];
             }
         }
         $countryCode = $visit->getColumn('countryCode');
         if (!isset($countries[$countryCode])) {
             $countries[$countryCode] = 0;
         }
         ++$countries[$countryCode];
         $continentCode = $visit->getColumn('continentCode');
         if (!isset($continents[$continentCode])) {
             $continents[$continentCode] = 0;
         }
         ++$continents[$continentCode];
         if ($countryCode && !array_key_exists($countryCode, $cities)) {
             $cities[$countryCode] = array();
         }
         $city = $visit->getColumn('city');
         if (!empty($city)) {
             $cities[$countryCode][] = $city;
         }
     }
     // sort countries/continents/search keywords by visit/action
     asort($countries);
     asort($continents);
     arsort($siteSearchKeywords);
     // transform country/continents/search keywords into something that will look good in XML
     $result['countries'] = $result['continents'] = $result['searches'] = array();
     foreach ($countries as $countryCode => $nbVisits) {
         $countryInfo = array('country' => $countryCode, 'nb_visits' => $nbVisits, 'flag' => \Piwik\Plugins\UserCountry\getFlagFromCode($countryCode), 'prettyName' => \Piwik\Plugins\UserCountry\countryTranslate($countryCode));
         if (!empty($cities[$countryCode])) {
             $countryInfo['cities'] = array_unique($cities[$countryCode]);
         }
         $result['countries'][] = $countryInfo;
     }
     foreach ($continents as $continentCode => $nbVisits) {
         $result['continents'][] = array('continent' => $continentCode, 'nb_visits' => $nbVisits, 'prettyName' => \Piwik\Plugins\UserCountry\continentTranslate($continentCode));
     }
     foreach ($siteSearchKeywords as $keyword => $searchCount) {
         $result['searches'][] = array('keyword' => $keyword, 'searches' => $searchCount);
     }
     if ($result['totalPageViews']) {
         $result['averagePageGenerationTime'] = round($pageGenerationTimeTotal / $result['totalPageViews'], $precision = 2);
     }
     $result['totalVisitDurationPretty'] = MetricsFormatter::getPrettyTimeFromSeconds($result['totalVisitDuration']);
     // use requested visits for first/last visit info
     $rows = $visits->getRows();
     $result['firstVisit'] = $this->getVisitorProfileVisitSummary(end($rows));
     $result['lastVisit'] = $this->getVisitorProfileVisitSummary(reset($rows));
     // check if requested visits have lat/long
     if ($checkForLatLong) {
         $result['hasLatLong'] = false;
         foreach ($rows as $visit) {
             if ($visit->getColumn('latitude') !== false) {
                 // realtime map only checks for latitude
                 $result['hasLatLong'] = true;
                 break;
             }
         }
     }
     // save count of visits we queries
     $result['visitsAggregated'] = count($rows);
     // use N most recent visits for last_visits
     $visits->deleteRowsOffset(self::VISITOR_PROFILE_MAX_VISITS_TO_SHOW);
     $result['lastVisits'] = $visits;
     // use the right date format for the pretty server date
     $timezone = Site::getTimezoneFor($idSite);
     foreach ($result['lastVisits']->getRows() as $visit) {
         $dateTimeVisitFirstAction = Date::factory($visit->getColumn('firstActionTimestamp'), $timezone);
         $datePretty = $dateTimeVisitFirstAction->getLocalized(self::VISITOR_PROFILE_DATE_FORMAT);
         $visit->setColumn('serverDatePrettyFirstAction', $datePretty);
         $dateTimePretty = $datePretty . ' ' . $visit->getColumn('serverTimePrettyFirstAction');
         $visit->setColumn('serverDateTimePrettyFirstAction', $dateTimePretty);
     }
     $result['userId'] = $visit->getColumn('userId');
     // get visitor IDs that are adjacent to this one in log_visit
     // TODO: make sure order of visitor ids is not changed if a returning visitor visits while the user is
     //       looking at the popup.
     $latestVisitTime = reset($rows)->getColumn('lastActionDateTime');
     $result['nextVisitorId'] = $this->getAdjacentVisitorId($idSite, $visitorId, $latestVisitTime, $segment, $getNext = true);
     $result['previousVisitorId'] = $this->getAdjacentVisitorId($idSite, $visitorId, $latestVisitTime, $segment, $getNext = false);
     /**
      * Triggered in the Live.getVisitorProfile API method. Plugins can use this event
      * to discover and add extra data to visitor profiles.
      *
      * For example, if an email address is found in a custom variable, a plugin could load the
      * gravatar for the email and add it to the visitor profile, causing it to display in the
      * visitor profile popup.
      *
      * The following visitor profile elements can be set to augment the visitor profile popup:
      *
      * - **visitorAvatar**: A URL to an image to display in the top left corner of the popup.
      * - **visitorDescription**: Text to be used as the tooltip of the avatar image.
      *
      * @param array &$visitorProfile The unaugmented visitor profile info.
      */
     Piwik::postEvent('Live.getExtraVisitorDetails', array(&$result));
     return $result;
 }
Beispiel #4
0
 function getCountryName()
 {
     return \Piwik\Plugins\UserCountry\countryTranslate($this->getCountryCode());
 }
Beispiel #5
0
 private function handleGeoLocationCountries()
 {
     // sort by visit/action
     asort($this->countries);
     // transform country/continents/search keywords into something that will look good in XML
     $this->profile['countries'] = $this->profile['continents'] = $this->profile['searches'] = array();
     foreach ($this->countries as $countryCode => $nbVisits) {
         $countryInfo = array('country' => $countryCode, 'nb_visits' => $nbVisits, 'flag' => \Piwik\Plugins\UserCountry\getFlagFromCode($countryCode), 'prettyName' => \Piwik\Plugins\UserCountry\countryTranslate($countryCode));
         if (!empty($this->cities[$countryCode])) {
             $countryInfo['cities'] = array_unique($this->cities[$countryCode]);
         }
         $this->profile['countries'][] = $countryInfo;
     }
 }