diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-03-28 03:42:39 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-03-28 03:42:40 +0400 |
commit | ae4b03163792f0b6e933933e5d37df87dc3fd566 (patch) | |
tree | d1d7510a9728f587d3d63ebd03e4ecf3d904838b /plugins/MobileMessaging | |
parent | 158c2150f5f2e13ece459b8d131244c11b763997 (diff) |
Mass conversion of all files to the newly agreed coding standard: PSR 1/2
Converting Piwik core source files, PHP, JS, TPL, CSS
More info: http://piwik.org/participate/coding-standards/
Diffstat (limited to 'plugins/MobileMessaging')
-rw-r--r-- | plugins/MobileMessaging/API.php | 893 | ||||
-rw-r--r-- | plugins/MobileMessaging/Controller.php | 91 | ||||
-rw-r--r-- | plugins/MobileMessaging/CountryCallingCodes.php | 486 | ||||
-rw-r--r-- | plugins/MobileMessaging/GSMCharset.php | 276 | ||||
-rw-r--r-- | plugins/MobileMessaging/MobileMessaging.php | 621 | ||||
-rw-r--r-- | plugins/MobileMessaging/ReportRenderer/Exception.php | 90 | ||||
-rw-r--r-- | plugins/MobileMessaging/ReportRenderer/Sms.php | 198 | ||||
-rw-r--r-- | plugins/MobileMessaging/SMSProvider.php | 283 | ||||
-rw-r--r-- | plugins/MobileMessaging/SMSProvider/Clockwork.php | 163 | ||||
-rw-r--r-- | plugins/MobileMessaging/SMSProvider/StubbedProvider.php | 24 | ||||
-rw-r--r-- | plugins/MobileMessaging/scripts/MobileMessagingSettings.js | 337 | ||||
-rw-r--r-- | plugins/MobileMessaging/templates/ReportParameters.tpl | 105 | ||||
-rw-r--r-- | plugins/MobileMessaging/templates/SMSReport.tpl | 138 | ||||
-rw-r--r-- | plugins/MobileMessaging/templates/Settings.tpl | 347 |
14 files changed, 1999 insertions, 2053 deletions
diff --git a/plugins/MobileMessaging/API.php b/plugins/MobileMessaging/API.php index df212a662f..ae80979245 100644 --- a/plugins/MobileMessaging/API.php +++ b/plugins/MobileMessaging/API.php @@ -19,459 +19,442 @@ */ class Piwik_MobileMessaging_API { - const VERIFICATION_CODE_LENGTH = 5; - const SMS_FROM = 'Piwik'; - - static private $instance = null; - - /** - * @return Piwik_MobileMessaging_API - */ - static public function getInstance() - { - if (self::$instance == null) - { - self::$instance = new self; - } - return self::$instance; - } - - /** - * @return Piwik_MobileMessaging_SMSProvider - */ - static private function getSMSProviderInstance($provider) - { - return Piwik_MobileMessaging_SMSProvider::factory($provider); - } - - /** - * determine if SMS API credential are available for the current user - * - * @return bool true if SMS API credential are available for the current user - */ - public function areSMSAPICredentialProvided() - { - Piwik::checkUserHasSomeViewAccess(); - - $credential = $this->getSMSAPICredential(); - return isset($credential[Piwik_MobileMessaging::API_KEY_OPTION]); - } - - private function getSMSAPICredential() - { - $settings = $this->getCredentialManagerSettings(); - return array( - Piwik_MobileMessaging::PROVIDER_OPTION => - isset($settings[Piwik_MobileMessaging::PROVIDER_OPTION]) ? $settings[Piwik_MobileMessaging::PROVIDER_OPTION] : null, - Piwik_MobileMessaging::API_KEY_OPTION => - isset($settings[Piwik_MobileMessaging::API_KEY_OPTION]) ? $settings[Piwik_MobileMessaging::API_KEY_OPTION] : null, - ); - } - - /** - * return the SMS API Provider for the current user - * - * @return string SMS API Provider - */ - public function getSMSProvider() - { - $this->checkCredentialManagementRights(); - $credential = $this->getSMSAPICredential(); - return $credential[Piwik_MobileMessaging::PROVIDER_OPTION]; - } - - /** - * set the SMS API credential - * - * @param string $provider SMS API provider - * @param string $apiKey API Key - * - * @return bool true if SMS API credential were validated and saved, false otherwise - */ - public function setSMSAPICredential($provider, $apiKey) - { - $this->checkCredentialManagementRights(); - - $smsProviderInstance = self::getSMSProviderInstance($provider); - $smsProviderInstance->verifyCredential($apiKey); - - $settings = $this->getCredentialManagerSettings(); - - $settings[Piwik_MobileMessaging::PROVIDER_OPTION] = $provider; - $settings[Piwik_MobileMessaging::API_KEY_OPTION] = $apiKey; - - $this->setCredentialManagerSettings($settings); - - return true; - } - - /** - * add phone number - * - * @param string $phoneNumber - * - * @return bool true - */ - public function addPhoneNumber($phoneNumber) - { - Piwik::checkUserIsNotAnonymous(); - - $phoneNumber = self::sanitizePhoneNumber($phoneNumber); - - $verificationCode = ""; - for($i = 0; $i < self::VERIFICATION_CODE_LENGTH; $i++) - { - $verificationCode .= mt_rand(0,9); - } - - $smsText = Piwik_Translate( - 'MobileMessaging_VerificationText', - array( - $verificationCode, - Piwik_Translate('UserSettings_SubmenuSettings'), - Piwik_Translate('MobileMessaging_SettingsMenu') - ) - ); - - $this->sendSMS($smsText, $phoneNumber, self::SMS_FROM); - - $phoneNumbers = $this->retrievePhoneNumbers(); - $phoneNumbers[$phoneNumber] = $verificationCode; - $this->savePhoneNumbers($phoneNumbers); - - $this->increaseCount(Piwik_MobileMessaging::PHONE_NUMBER_VALIDATION_REQUEST_COUNT_OPTION, $phoneNumber); - - return true; - } - - /** - * sanitize phone number - * - * @param string $phoneNumber - * - * @return string sanitized phone number - */ - public static function sanitizePhoneNumber($phoneNumber) - { - return str_replace(' ', '', $phoneNumber); - } - - /** - * send a SMS - * - * @param string $phoneNumber - * @return bool true - * @ignore - */ - public function sendSMS($content, $phoneNumber, $from) - { - Piwik::checkUserIsNotAnonymous(); - - $credential = $this->getSMSAPICredential(); - $SMSProvider = self::getSMSProviderInstance($credential[Piwik_MobileMessaging::PROVIDER_OPTION]); - $SMSProvider->sendSMS( - $credential[Piwik_MobileMessaging::API_KEY_OPTION], - $content, - $phoneNumber, - $from - ); - - $this->increaseCount(Piwik_MobileMessaging::SMS_SENT_COUNT_OPTION, $phoneNumber); - - return true; - } - - /** - * get remaining credit - * - * @return string remaining credit - */ - public function getCreditLeft() - { - $this->checkCredentialManagementRights(); - - $credential = $this->getSMSAPICredential(); - $SMSProvider = self::getSMSProviderInstance($credential[Piwik_MobileMessaging::PROVIDER_OPTION]); - return $SMSProvider->getCreditLeft( - $credential[Piwik_MobileMessaging::API_KEY_OPTION] - ); - } - - /** - * remove phone number - * - * @param string $phoneNumber - * - * @return bool true - */ - public function removePhoneNumber($phoneNumber) - { - Piwik::checkUserIsNotAnonymous(); - - $phoneNumbers = $this->retrievePhoneNumbers(); - unset($phoneNumbers[$phoneNumber]); - $this->savePhoneNumbers($phoneNumbers); - - // remove phone number from reports - $pdfReportsAPIInstance = Piwik_PDFReports_API::getInstance(); - $reports = $pdfReportsAPIInstance->getReports( - $idSite = false, - $period = false, - $idReport = false, - $ifSuperUserReturnOnlySuperUserReports = $this->getDelegatedManagement() - ); - - foreach($reports as $report) - { - if ($report['type'] == Piwik_MobileMessaging::MOBILE_TYPE) - { - $reportParameters = $report['parameters']; - $reportPhoneNumbers = $reportParameters[Piwik_MobileMessaging::PHONE_NUMBERS_PARAMETER]; - $updatedPhoneNumbers = array(); - foreach($reportPhoneNumbers as $reportPhoneNumber) - { - if($reportPhoneNumber != $phoneNumber) - { - $updatedPhoneNumbers[] = $reportPhoneNumber; - } - } - - if(count($updatedPhoneNumbers) != count($reportPhoneNumbers)) - { - $reportParameters[Piwik_MobileMessaging::PHONE_NUMBERS_PARAMETER] = $updatedPhoneNumbers; - - // note: reports can end up without any recipients - $pdfReportsAPIInstance->updateReport( - $report['idreport'], - $report['idsite'], - $report['description'], - $report['period'], - $report['type'], - $report['format'], - $report['reports'], - $reportParameters - ); - } - } - } - - return true; - } - - private function retrievePhoneNumbers() - { - $settings = $this->getCurrentUserSettings(); - - $phoneNumbers = array(); - if(isset($settings[Piwik_MobileMessaging::PHONE_NUMBERS_OPTION])) - { - $phoneNumbers = $settings[Piwik_MobileMessaging::PHONE_NUMBERS_OPTION]; - } - - return $phoneNumbers; - } - - private function savePhoneNumbers($phoneNumbers) - { - $settings = $this->getCurrentUserSettings(); - - $settings[Piwik_MobileMessaging::PHONE_NUMBERS_OPTION] = $phoneNumbers; - - $this->setCurrentUserSettings($settings); - } - - private function increaseCount($option, $phoneNumber) - { - $settings = $this->getCurrentUserSettings(); - - $counts = array(); - if(isset($settings[$option])) - { - $counts = $settings[$option]; - } - - $countToUpdate = 0; - if(isset($counts[$phoneNumber])) - { - $countToUpdate = $counts[$phoneNumber]; - } - - $counts[$phoneNumber] = $countToUpdate + 1; - - $settings[$option] = $counts; - - $this->setCurrentUserSettings($settings); - } - - /** - * validate phone number - * - * @param string $phoneNumber - * @param string $verificationCode - * - * @return bool true if validation code is correct, false otherwise - */ - public function validatePhoneNumber($phoneNumber, $verificationCode) - { - Piwik::checkUserIsNotAnonymous(); - - $phoneNumbers = $this->retrievePhoneNumbers(); - - if(isset($phoneNumbers[$phoneNumber])) - { - if($verificationCode == $phoneNumbers[$phoneNumber]) { - - $phoneNumbers[$phoneNumber] = null; - $this->savePhoneNumbers($phoneNumbers); - return true; - } - } - - return false; - } - - /** - * get phone number list - * - * @return array $phoneNumber => $isValidated - * @ignore - */ - public function getPhoneNumbers() - { - Piwik::checkUserIsNotAnonymous(); - - $rawPhoneNumbers = $this->retrievePhoneNumbers(); - - $phoneNumbers = array(); - foreach($rawPhoneNumbers as $phoneNumber => $verificationCode) - { - $phoneNumbers[$phoneNumber] = self::isActivated($verificationCode); - } - - return $phoneNumbers; - } - - /** - * get activated phone number list - * - * @return array $phoneNumber - * @ignore - */ - public function getActivatedPhoneNumbers() - { - Piwik::checkUserIsNotAnonymous(); - - $phoneNumbers = $this->retrievePhoneNumbers(); - - $activatedPhoneNumbers = array(); - foreach($phoneNumbers as $phoneNumber => $verificationCode) - { - if(self::isActivated($verificationCode)) - { - $activatedPhoneNumbers[] = $phoneNumber; - } - } - - return $activatedPhoneNumbers; - } - - private static function isActivated($verificationCode) - { - return $verificationCode === null; - } - - /** - * delete the SMS API credential - * - * @return bool true - */ - public function deleteSMSAPICredential() - { - $this->checkCredentialManagementRights(); - - $settings = $this->getCredentialManagerSettings(); - - $settings[Piwik_MobileMessaging::API_KEY_OPTION] = null; - - $this->setCredentialManagerSettings($settings); - - return true; - } - - private function checkCredentialManagementRights() - { - $this->getDelegatedManagement() ? Piwik::checkUserIsNotAnonymous() : Piwik::checkUserIsSuperUser(); - } - - private function setUserSettings($user, $settings) - { - Piwik_SetOption( - $user . Piwik_MobileMessaging::USER_SETTINGS_POSTFIX_OPTION, - Piwik_Common::json_encode($settings) - ); - } - - private function setCurrentUserSettings($settings) - { - $this->setUserSettings(Piwik::getCurrentUserLogin(), $settings); - } - - private function setCredentialManagerSettings($settings) - { - $this->setUserSettings($this->getCredentialManagerLogin(), $settings); - } - - private function getCredentialManagerLogin() - { - return $this->getDelegatedManagement() ? Piwik::getCurrentUserLogin() : Piwik::getSuperUserLogin(); - } - - private function getUserSettings($user) - { - $optionIndex = $user . Piwik_MobileMessaging::USER_SETTINGS_POSTFIX_OPTION; - $userSettings = Piwik_GetOption($optionIndex); - - if(empty($userSettings)) - { - $userSettings = array(); - } - else - { - $userSettings = Piwik_Common::json_decode($userSettings, true); - } - - return $userSettings; - } - - private function getCredentialManagerSettings() - { - return $this->getUserSettings($this->getCredentialManagerLogin()); - } - - private function getCurrentUserSettings() - { - return $this->getUserSettings(Piwik::getCurrentUserLogin()); - } - - /** - * Specify if normal users can manage their own SMS API credential - * - * @param bool $delegatedManagement false if SMS API credential only manageable by super admin, true otherwise - */ - public function setDelegatedManagement($delegatedManagement) - { - Piwik::checkUserIsSuperUser(); - Piwik_SetOption(Piwik_MobileMessaging::DELEGATED_MANAGEMENT_OPTION, $delegatedManagement); - } - - /** - * Determine if normal users can manage their own SMS API credential - * - * @return bool false if SMS API credential only manageable by super admin, true otherwise - */ - public function getDelegatedManagement() - { - Piwik::checkUserHasSomeViewAccess(); - return Piwik_GetOption(Piwik_MobileMessaging::DELEGATED_MANAGEMENT_OPTION) == 'true'; - } + const VERIFICATION_CODE_LENGTH = 5; + const SMS_FROM = 'Piwik'; + + static private $instance = null; + + /** + * @return Piwik_MobileMessaging_API + */ + static public function getInstance() + { + if (self::$instance == null) { + self::$instance = new self; + } + return self::$instance; + } + + /** + * @return Piwik_MobileMessaging_SMSProvider + */ + static private function getSMSProviderInstance($provider) + { + return Piwik_MobileMessaging_SMSProvider::factory($provider); + } + + /** + * determine if SMS API credential are available for the current user + * + * @return bool true if SMS API credential are available for the current user + */ + public function areSMSAPICredentialProvided() + { + Piwik::checkUserHasSomeViewAccess(); + + $credential = $this->getSMSAPICredential(); + return isset($credential[Piwik_MobileMessaging::API_KEY_OPTION]); + } + + private function getSMSAPICredential() + { + $settings = $this->getCredentialManagerSettings(); + return array( + Piwik_MobileMessaging::PROVIDER_OPTION => + isset($settings[Piwik_MobileMessaging::PROVIDER_OPTION]) ? $settings[Piwik_MobileMessaging::PROVIDER_OPTION] : null, + Piwik_MobileMessaging::API_KEY_OPTION => + isset($settings[Piwik_MobileMessaging::API_KEY_OPTION]) ? $settings[Piwik_MobileMessaging::API_KEY_OPTION] : null, + ); + } + + /** + * return the SMS API Provider for the current user + * + * @return string SMS API Provider + */ + public function getSMSProvider() + { + $this->checkCredentialManagementRights(); + $credential = $this->getSMSAPICredential(); + return $credential[Piwik_MobileMessaging::PROVIDER_OPTION]; + } + + /** + * set the SMS API credential + * + * @param string $provider SMS API provider + * @param string $apiKey API Key + * + * @return bool true if SMS API credential were validated and saved, false otherwise + */ + public function setSMSAPICredential($provider, $apiKey) + { + $this->checkCredentialManagementRights(); + + $smsProviderInstance = self::getSMSProviderInstance($provider); + $smsProviderInstance->verifyCredential($apiKey); + + $settings = $this->getCredentialManagerSettings(); + + $settings[Piwik_MobileMessaging::PROVIDER_OPTION] = $provider; + $settings[Piwik_MobileMessaging::API_KEY_OPTION] = $apiKey; + + $this->setCredentialManagerSettings($settings); + + return true; + } + + /** + * add phone number + * + * @param string $phoneNumber + * + * @return bool true + */ + public function addPhoneNumber($phoneNumber) + { + Piwik::checkUserIsNotAnonymous(); + + $phoneNumber = self::sanitizePhoneNumber($phoneNumber); + + $verificationCode = ""; + for ($i = 0; $i < self::VERIFICATION_CODE_LENGTH; $i++) { + $verificationCode .= mt_rand(0, 9); + } + + $smsText = Piwik_Translate( + 'MobileMessaging_VerificationText', + array( + $verificationCode, + Piwik_Translate('UserSettings_SubmenuSettings'), + Piwik_Translate('MobileMessaging_SettingsMenu') + ) + ); + + $this->sendSMS($smsText, $phoneNumber, self::SMS_FROM); + + $phoneNumbers = $this->retrievePhoneNumbers(); + $phoneNumbers[$phoneNumber] = $verificationCode; + $this->savePhoneNumbers($phoneNumbers); + + $this->increaseCount(Piwik_MobileMessaging::PHONE_NUMBER_VALIDATION_REQUEST_COUNT_OPTION, $phoneNumber); + + return true; + } + + /** + * sanitize phone number + * + * @param string $phoneNumber + * + * @return string sanitized phone number + */ + public static function sanitizePhoneNumber($phoneNumber) + { + return str_replace(' ', '', $phoneNumber); + } + + /** + * send a SMS + * + * @param string $phoneNumber + * @return bool true + * @ignore + */ + public function sendSMS($content, $phoneNumber, $from) + { + Piwik::checkUserIsNotAnonymous(); + + $credential = $this->getSMSAPICredential(); + $SMSProvider = self::getSMSProviderInstance($credential[Piwik_MobileMessaging::PROVIDER_OPTION]); + $SMSProvider->sendSMS( + $credential[Piwik_MobileMessaging::API_KEY_OPTION], + $content, + $phoneNumber, + $from + ); + + $this->increaseCount(Piwik_MobileMessaging::SMS_SENT_COUNT_OPTION, $phoneNumber); + + return true; + } + + /** + * get remaining credit + * + * @return string remaining credit + */ + public function getCreditLeft() + { + $this->checkCredentialManagementRights(); + + $credential = $this->getSMSAPICredential(); + $SMSProvider = self::getSMSProviderInstance($credential[Piwik_MobileMessaging::PROVIDER_OPTION]); + return $SMSProvider->getCreditLeft( + $credential[Piwik_MobileMessaging::API_KEY_OPTION] + ); + } + + /** + * remove phone number + * + * @param string $phoneNumber + * + * @return bool true + */ + public function removePhoneNumber($phoneNumber) + { + Piwik::checkUserIsNotAnonymous(); + + $phoneNumbers = $this->retrievePhoneNumbers(); + unset($phoneNumbers[$phoneNumber]); + $this->savePhoneNumbers($phoneNumbers); + + // remove phone number from reports + $pdfReportsAPIInstance = Piwik_PDFReports_API::getInstance(); + $reports = $pdfReportsAPIInstance->getReports( + $idSite = false, + $period = false, + $idReport = false, + $ifSuperUserReturnOnlySuperUserReports = $this->getDelegatedManagement() + ); + + foreach ($reports as $report) { + if ($report['type'] == Piwik_MobileMessaging::MOBILE_TYPE) { + $reportParameters = $report['parameters']; + $reportPhoneNumbers = $reportParameters[Piwik_MobileMessaging::PHONE_NUMBERS_PARAMETER]; + $updatedPhoneNumbers = array(); + foreach ($reportPhoneNumbers as $reportPhoneNumber) { + if ($reportPhoneNumber != $phoneNumber) { + $updatedPhoneNumbers[] = $reportPhoneNumber; + } + } + + if (count($updatedPhoneNumbers) != count($reportPhoneNumbers)) { + $reportParameters[Piwik_MobileMessaging::PHONE_NUMBERS_PARAMETER] = $updatedPhoneNumbers; + + // note: reports can end up without any recipients + $pdfReportsAPIInstance->updateReport( + $report['idreport'], + $report['idsite'], + $report['description'], + $report['period'], + $report['type'], + $report['format'], + $report['reports'], + $reportParameters + ); + } + } + } + + return true; + } + + private function retrievePhoneNumbers() + { + $settings = $this->getCurrentUserSettings(); + + $phoneNumbers = array(); + if (isset($settings[Piwik_MobileMessaging::PHONE_NUMBERS_OPTION])) { + $phoneNumbers = $settings[Piwik_MobileMessaging::PHONE_NUMBERS_OPTION]; + } + + return $phoneNumbers; + } + + private function savePhoneNumbers($phoneNumbers) + { + $settings = $this->getCurrentUserSettings(); + + $settings[Piwik_MobileMessaging::PHONE_NUMBERS_OPTION] = $phoneNumbers; + + $this->setCurrentUserSettings($settings); + } + + private function increaseCount($option, $phoneNumber) + { + $settings = $this->getCurrentUserSettings(); + + $counts = array(); + if (isset($settings[$option])) { + $counts = $settings[$option]; + } + + $countToUpdate = 0; + if (isset($counts[$phoneNumber])) { + $countToUpdate = $counts[$phoneNumber]; + } + + $counts[$phoneNumber] = $countToUpdate + 1; + + $settings[$option] = $counts; + + $this->setCurrentUserSettings($settings); + } + + /** + * validate phone number + * + * @param string $phoneNumber + * @param string $verificationCode + * + * @return bool true if validation code is correct, false otherwise + */ + public function validatePhoneNumber($phoneNumber, $verificationCode) + { + Piwik::checkUserIsNotAnonymous(); + + $phoneNumbers = $this->retrievePhoneNumbers(); + + if (isset($phoneNumbers[$phoneNumber])) { + if ($verificationCode == $phoneNumbers[$phoneNumber]) { + + $phoneNumbers[$phoneNumber] = null; + $this->savePhoneNumbers($phoneNumbers); + return true; + } + } + + return false; + } + + /** + * get phone number list + * + * @return array $phoneNumber => $isValidated + * @ignore + */ + public function getPhoneNumbers() + { + Piwik::checkUserIsNotAnonymous(); + + $rawPhoneNumbers = $this->retrievePhoneNumbers(); + + $phoneNumbers = array(); + foreach ($rawPhoneNumbers as $phoneNumber => $verificationCode) { + $phoneNumbers[$phoneNumber] = self::isActivated($verificationCode); + } + + return $phoneNumbers; + } + + /** + * get activated phone number list + * + * @return array $phoneNumber + * @ignore + */ + public function getActivatedPhoneNumbers() + { + Piwik::checkUserIsNotAnonymous(); + + $phoneNumbers = $this->retrievePhoneNumbers(); + + $activatedPhoneNumbers = array(); + foreach ($phoneNumbers as $phoneNumber => $verificationCode) { + if (self::isActivated($verificationCode)) { + $activatedPhoneNumbers[] = $phoneNumber; + } + } + + return $activatedPhoneNumbers; + } + + private static function isActivated($verificationCode) + { + return $verificationCode === null; + } + + /** + * delete the SMS API credential + * + * @return bool true + */ + public function deleteSMSAPICredential() + { + $this->checkCredentialManagementRights(); + + $settings = $this->getCredentialManagerSettings(); + + $settings[Piwik_MobileMessaging::API_KEY_OPTION] = null; + + $this->setCredentialManagerSettings($settings); + + return true; + } + + private function checkCredentialManagementRights() + { + $this->getDelegatedManagement() ? Piwik::checkUserIsNotAnonymous() : Piwik::checkUserIsSuperUser(); + } + + private function setUserSettings($user, $settings) + { + Piwik_SetOption( + $user . Piwik_MobileMessaging::USER_SETTINGS_POSTFIX_OPTION, + Piwik_Common::json_encode($settings) + ); + } + + private function setCurrentUserSettings($settings) + { + $this->setUserSettings(Piwik::getCurrentUserLogin(), $settings); + } + + private function setCredentialManagerSettings($settings) + { + $this->setUserSettings($this->getCredentialManagerLogin(), $settings); + } + + private function getCredentialManagerLogin() + { + return $this->getDelegatedManagement() ? Piwik::getCurrentUserLogin() : Piwik::getSuperUserLogin(); + } + + private function getUserSettings($user) + { + $optionIndex = $user . Piwik_MobileMessaging::USER_SETTINGS_POSTFIX_OPTION; + $userSettings = Piwik_GetOption($optionIndex); + + if (empty($userSettings)) { + $userSettings = array(); + } else { + $userSettings = Piwik_Common::json_decode($userSettings, true); + } + + return $userSettings; + } + + private function getCredentialManagerSettings() + { + return $this->getUserSettings($this->getCredentialManagerLogin()); + } + + private function getCurrentUserSettings() + { + return $this->getUserSettings(Piwik::getCurrentUserLogin()); + } + + /** + * Specify if normal users can manage their own SMS API credential + * + * @param bool $delegatedManagement false if SMS API credential only manageable by super admin, true otherwise + */ + public function setDelegatedManagement($delegatedManagement) + { + Piwik::checkUserIsSuperUser(); + Piwik_SetOption(Piwik_MobileMessaging::DELEGATED_MANAGEMENT_OPTION, $delegatedManagement); + } + + /** + * Determine if normal users can manage their own SMS API credential + * + * @return bool false if SMS API credential only manageable by super admin, true otherwise + */ + public function getDelegatedManagement() + { + Piwik::checkUserHasSomeViewAccess(); + return Piwik_GetOption(Piwik_MobileMessaging::DELEGATED_MANAGEMENT_OPTION) == 'true'; + } } diff --git a/plugins/MobileMessaging/Controller.php b/plugins/MobileMessaging/Controller.php index 11efa0817c..ee027c4505 100644 --- a/plugins/MobileMessaging/Controller.php +++ b/plugins/MobileMessaging/Controller.php @@ -17,60 +17,57 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/functions.php'; */ class Piwik_MobileMessaging_Controller extends Piwik_Controller_Admin { - /* - * Mobile Messaging Settings tab : - * - set delegated management - * - provide & validate SMS API credential - * - add & activate phone numbers - * - check remaining credits - */ - function index() - { - Piwik::checkUserIsNotAnonymous(); + /* + * Mobile Messaging Settings tab : + * - set delegated management + * - provide & validate SMS API credential + * - add & activate phone numbers + * - check remaining credits + */ + function index() + { + Piwik::checkUserIsNotAnonymous(); - $view = Piwik_View::factory('Settings'); + $view = Piwik_View::factory('Settings'); - $view->isSuperUser = Piwik::isUserIsSuperUser(); + $view->isSuperUser = Piwik::isUserIsSuperUser(); - $mobileMessagingAPI = Piwik_MobileMessaging_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('UserSettings_SubmenuSettings'), Piwik_Translate('MobileMessaging_SettingsMenu') ) ); - if($view->credentialSupplied && $view->accountManagedByCurrentUser) - { - $view->provider = $mobileMessagingAPI->getSMSProvider(); - $view->creditLeft = $mobileMessagingAPI->getCreditLeft(); - } + $mobileMessagingAPI = Piwik_MobileMessaging_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('UserSettings_SubmenuSettings'), Piwik_Translate('MobileMessaging_SettingsMenu'))); + if ($view->credentialSupplied && $view->accountManagedByCurrentUser) { + $view->provider = $mobileMessagingAPI->getSMSProvider(); + $view->creditLeft = $mobileMessagingAPI->getCreditLeft(); + } - $view->smsProviders = Piwik_MobileMessaging_SMSProvider::$availableSMSProviders; + $view->smsProviders = Piwik_MobileMessaging_SMSProvider::$availableSMSProviders; - // construct the list of countries from the lang files - $countries = array(); - foreach(Piwik_Common::getCountriesList() as $countryCode => $continentCode) - { - if(isset(Piwik_MobileMessaging_CountryCallingCodes::$countryCallingCodes[$countryCode])) - { - $countries[$countryCode] = - array( - 'countryName' => Piwik_CountryTranslate($countryCode), - 'countryCallingCode' => Piwik_MobileMessaging_CountryCallingCodes::$countryCallingCodes[$countryCode], - ); - } - } - $view->countries = $countries; + // construct the list of countries from the lang files + $countries = array(); + foreach (Piwik_Common::getCountriesList() as $countryCode => $continentCode) { + if (isset(Piwik_MobileMessaging_CountryCallingCodes::$countryCallingCodes[$countryCode])) { + $countries[$countryCode] = + array( + 'countryName' => Piwik_CountryTranslate($countryCode), + 'countryCallingCode' => Piwik_MobileMessaging_CountryCallingCodes::$countryCallingCodes[$countryCode], + ); + } + } + $view->countries = $countries; - $view->defaultCountry = Piwik_Common::getCountry( - Piwik_LanguagesManager::getLanguageCodeForCurrentUser(), - true, - Piwik_IP::getIpFromHeader() - ); + $view->defaultCountry = Piwik_Common::getCountry( + Piwik_LanguagesManager::getLanguageCodeForCurrentUser(), + true, + Piwik_IP::getIpFromHeader() + ); - $view->phoneNumbers = $mobileMessagingAPI->getPhoneNumbers(); + $view->phoneNumbers = $mobileMessagingAPI->getPhoneNumbers(); - $this->setBasicVariablesView($view); + $this->setBasicVariablesView($view); - $view->menu = Piwik_GetAdminMenu(); - echo $view->render(); - } + $view->menu = Piwik_GetAdminMenu(); + echo $view->render(); + } } diff --git a/plugins/MobileMessaging/CountryCallingCodes.php b/plugins/MobileMessaging/CountryCallingCodes.php index a6c72bc86f..b1097220f8 100644 --- a/plugins/MobileMessaging/CountryCallingCodes.php +++ b/plugins/MobileMessaging/CountryCallingCodes.php @@ -15,257 +15,257 @@ */ class Piwik_MobileMessaging_CountryCallingCodes { - // list taken from core/DataFiles/Countries.php - public static $countryCallingCodes = array( - 'ad' => '376', - 'ae' => '971', - 'af' => '93', - 'ag' => '1268', // @wikipedia original value: 1 268 - 'ai' => '1264', // @wikipedia original value: 1 264 - 'al' => '355', - 'am' => '374', - 'ao' => '244', + // list taken from core/DataFiles/Countries.php + public static $countryCallingCodes = array( + 'ad' => '376', + 'ae' => '971', + 'af' => '93', + 'ag' => '1268', // @wikipedia original value: 1 268 + 'ai' => '1264', // @wikipedia original value: 1 264 + 'al' => '355', + 'am' => '374', + 'ao' => '244', // 'aq' => 'MISSING CODE', // @wikipedia In Antarctica dialing is dependent on the parent country of each base - 'ar' => '54', - 'as' => '1684', // @wikipedia original value: 1 684 - 'at' => '43', - 'au' => '61', - 'aw' => '297', - 'ax' => '358', - 'az' => '994', - 'ba' => '387', - 'bb' => '1246', // @wikipedia original value: 1 246 - 'bd' => '880', - 'be' => '32', - 'bf' => '226', - 'bg' => '359', - 'bh' => '973', - 'bi' => '257', - 'bj' => '229', - 'bl' => '590', - 'bm' => '1441', // @wikipedia original value: 1 441 - 'bn' => '673', - 'bo' => '591', - 'bq' => '5997', // @wikipedia original value: 599 7 - 'br' => '55', - 'bs' => '1242', // @wikipedia original value: 1 242 - 'bt' => '975', + 'ar' => '54', + 'as' => '1684', // @wikipedia original value: 1 684 + 'at' => '43', + 'au' => '61', + 'aw' => '297', + 'ax' => '358', + 'az' => '994', + 'ba' => '387', + 'bb' => '1246', // @wikipedia original value: 1 246 + 'bd' => '880', + 'be' => '32', + 'bf' => '226', + 'bg' => '359', + 'bh' => '973', + 'bi' => '257', + 'bj' => '229', + 'bl' => '590', + 'bm' => '1441', // @wikipedia original value: 1 441 + 'bn' => '673', + 'bo' => '591', + 'bq' => '5997', // @wikipedia original value: 599 7 + 'br' => '55', + 'bs' => '1242', // @wikipedia original value: 1 242 + 'bt' => '975', // 'bv' => 'MISSING CODE', - 'bw' => '267', - 'by' => '375', - 'bz' => '501', - 'ca' => '1', - 'cc' => '61', - 'cd' => '243', - 'cf' => '236', - 'cg' => '242', - 'ch' => '41', - 'ci' => '225', - 'ck' => '682', - 'cl' => '56', - 'cm' => '237', - 'cn' => '86', - 'co' => '57', - 'cr' => '506', - 'cu' => '53', - 'cv' => '238', - 'cw' => '5999', // @wikipedia original value: 599 9 - 'cx' => '61', - 'cy' => '357', - 'cz' => '420', - 'de' => '49', - 'dj' => '253', - 'dk' => '45', - 'dm' => '1767', // @wikipedia original value: 1 767 + 'bw' => '267', + 'by' => '375', + 'bz' => '501', + 'ca' => '1', + 'cc' => '61', + 'cd' => '243', + 'cf' => '236', + 'cg' => '242', + 'ch' => '41', + 'ci' => '225', + 'ck' => '682', + 'cl' => '56', + 'cm' => '237', + 'cn' => '86', + 'co' => '57', + 'cr' => '506', + 'cu' => '53', + 'cv' => '238', + 'cw' => '5999', // @wikipedia original value: 599 9 + 'cx' => '61', + 'cy' => '357', + 'cz' => '420', + 'de' => '49', + 'dj' => '253', + 'dk' => '45', + 'dm' => '1767', // @wikipedia original value: 1 767 // 'do' => 'MISSING CODE', // @wikipedia original values: 1 809, 1 829, 1 849 - 'dz' => '213', - 'ec' => '593', - 'ee' => '372', - 'eg' => '20', - 'eh' => '212', - 'er' => '291', - 'es' => '34', - 'et' => '251', - 'fi' => '358', - 'fj' => '679', - 'fk' => '500', - 'fm' => '691', - 'fo' => '298', - 'fr' => '33', - 'ga' => '241', - 'gb' => '44', - 'gd' => '1473', // @wikipedia original value: 1 473 - 'ge' => '995', - 'gf' => '594', - 'gg' => '44', - 'gh' => '233', - 'gi' => '350', - 'gl' => '299', - 'gm' => '220', - 'gn' => '224', - 'gp' => '590', - 'gq' => '240', - 'gr' => '30', - 'gs' => '500', - 'gt' => '502', - 'gu' => '1671', // @wikipedia original value: 1 671 - 'gw' => '245', - 'gy' => '592', - 'hk' => '852', + 'dz' => '213', + 'ec' => '593', + 'ee' => '372', + 'eg' => '20', + 'eh' => '212', + 'er' => '291', + 'es' => '34', + 'et' => '251', + 'fi' => '358', + 'fj' => '679', + 'fk' => '500', + 'fm' => '691', + 'fo' => '298', + 'fr' => '33', + 'ga' => '241', + 'gb' => '44', + 'gd' => '1473', // @wikipedia original value: 1 473 + 'ge' => '995', + 'gf' => '594', + 'gg' => '44', + 'gh' => '233', + 'gi' => '350', + 'gl' => '299', + 'gm' => '220', + 'gn' => '224', + 'gp' => '590', + 'gq' => '240', + 'gr' => '30', + 'gs' => '500', + 'gt' => '502', + 'gu' => '1671', // @wikipedia original value: 1 671 + 'gw' => '245', + 'gy' => '592', + 'hk' => '852', // 'hm' => 'MISSING CODE', - 'hn' => '504', - 'hr' => '385', - 'ht' => '509', - 'hu' => '36', - 'id' => '62', - 'ie' => '353', - 'il' => '972', - 'im' => '44', - 'in' => '91', - 'io' => '246', - 'iq' => '964', - 'ir' => '98', - 'is' => '354', - 'it' => '39', - 'je' => '44', - 'jm' => '1876', // @wikipedia original value: 1 876 - 'jo' => '962', - 'jp' => '81', - 'ke' => '254', - 'kg' => '996', - 'kh' => '855', - 'ki' => '686', - 'km' => '269', - 'kn' => '1869', // @wikipedia original value: 1 869 - 'kp' => '850', - 'kr' => '82', - 'kw' => '965', - 'ky' => '1345', // @wikipedia original value: 1 345 + 'hn' => '504', + 'hr' => '385', + 'ht' => '509', + 'hu' => '36', + 'id' => '62', + 'ie' => '353', + 'il' => '972', + 'im' => '44', + 'in' => '91', + 'io' => '246', + 'iq' => '964', + 'ir' => '98', + 'is' => '354', + 'it' => '39', + 'je' => '44', + 'jm' => '1876', // @wikipedia original value: 1 876 + 'jo' => '962', + 'jp' => '81', + 'ke' => '254', + 'kg' => '996', + 'kh' => '855', + 'ki' => '686', + 'km' => '269', + 'kn' => '1869', // @wikipedia original value: 1 869 + 'kp' => '850', + 'kr' => '82', + 'kw' => '965', + 'ky' => '1345', // @wikipedia original value: 1 345 // 'kz' => 'MISSING CODE', // @wikipedia original values: 7 6, 7 7 - 'la' => '856', - 'lb' => '961', - 'lc' => '1758', // @wikipedia original value: 1 758 - 'li' => '423', - 'lk' => '94', - 'lr' => '231', - 'ls' => '266', - 'lt' => '370', - 'lu' => '352', - 'lv' => '371', - 'ly' => '218', - 'ma' => '212', - 'mc' => '377', - 'md' => '373', - 'me' => '382', - 'mf' => '590', - 'mg' => '261', - 'mh' => '692', - 'mk' => '389', - 'ml' => '223', - 'mm' => '95', - 'mn' => '976', - 'mo' => '853', - 'mp' => '1670', // @wikipedia original value: 1 670 - 'mq' => '596', - 'mr' => '222', - 'ms' => '1664', // @wikipedia original value: 1 664 - 'mt' => '356', - 'mu' => '230', - 'mv' => '960', - 'mw' => '265', - 'mx' => '52', - 'my' => '60', - 'mz' => '258', - 'na' => '264', - 'nc' => '687', - 'ne' => '227', - 'nf' => '672', - 'ng' => '234', - 'ni' => '505', - 'nl' => '31', - 'no' => '47', - 'np' => '977', - 'nr' => '674', - 'nu' => '683', - 'nz' => '64', - 'om' => '968', - 'pa' => '507', - 'pe' => '51', - 'pf' => '689', - 'pg' => '675', - 'ph' => '63', - 'pk' => '92', - 'pl' => '48', - 'pm' => '508', - 'pn' => '672', + 'la' => '856', + 'lb' => '961', + 'lc' => '1758', // @wikipedia original value: 1 758 + 'li' => '423', + 'lk' => '94', + 'lr' => '231', + 'ls' => '266', + 'lt' => '370', + 'lu' => '352', + 'lv' => '371', + 'ly' => '218', + 'ma' => '212', + 'mc' => '377', + 'md' => '373', + 'me' => '382', + 'mf' => '590', + 'mg' => '261', + 'mh' => '692', + 'mk' => '389', + 'ml' => '223', + 'mm' => '95', + 'mn' => '976', + 'mo' => '853', + 'mp' => '1670', // @wikipedia original value: 1 670 + 'mq' => '596', + 'mr' => '222', + 'ms' => '1664', // @wikipedia original value: 1 664 + 'mt' => '356', + 'mu' => '230', + 'mv' => '960', + 'mw' => '265', + 'mx' => '52', + 'my' => '60', + 'mz' => '258', + 'na' => '264', + 'nc' => '687', + 'ne' => '227', + 'nf' => '672', + 'ng' => '234', + 'ni' => '505', + 'nl' => '31', + 'no' => '47', + 'np' => '977', + 'nr' => '674', + 'nu' => '683', + 'nz' => '64', + 'om' => '968', + 'pa' => '507', + 'pe' => '51', + 'pf' => '689', + 'pg' => '675', + 'ph' => '63', + 'pk' => '92', + 'pl' => '48', + 'pm' => '508', + 'pn' => '672', // 'pr' => 'MISSING CODE', // @wikipedia original values: 1 787, 1 939 - 'ps' => '970', - 'pt' => '351', - 'pw' => '680', - 'py' => '595', - 'qa' => '974', - 're' => '262', - 'ro' => '40', - 'rs' => '381', - 'ru' => '7', - 'rw' => '250', - 'sa' => '966', - 'sb' => '677', - 'sc' => '248', - 'sd' => '249', - 'se' => '46', - 'sg' => '65', - 'sh' => '290', - 'si' => '386', - 'sj' => '47', - 'sk' => '421', - 'sl' => '232', - 'sm' => '378', - 'sn' => '221', - 'so' => '252', - 'sr' => '597', - 'ss' => '211', - 'st' => '239', - 'sv' => '503', - 'sx' => '1721', //@wikipedia original value: 1 721 - 'sy' => '963', - 'sz' => '268', - 'tc' => '1649', // @wikipedia original value: 1 649 - 'td' => '235', + 'ps' => '970', + 'pt' => '351', + 'pw' => '680', + 'py' => '595', + 'qa' => '974', + 're' => '262', + 'ro' => '40', + 'rs' => '381', + 'ru' => '7', + 'rw' => '250', + 'sa' => '966', + 'sb' => '677', + 'sc' => '248', + 'sd' => '249', + 'se' => '46', + 'sg' => '65', + 'sh' => '290', + 'si' => '386', + 'sj' => '47', + 'sk' => '421', + 'sl' => '232', + 'sm' => '378', + 'sn' => '221', + 'so' => '252', + 'sr' => '597', + 'ss' => '211', + 'st' => '239', + 'sv' => '503', + 'sx' => '1721', //@wikipedia original value: 1 721 + 'sy' => '963', + 'sz' => '268', + 'tc' => '1649', // @wikipedia original value: 1 649 + 'td' => '235', // 'tf' => 'MISSING CODE', - 'tg' => '228', - 'th' => '66', + 'tg' => '228', + 'th' => '66', // 'ti' => 'MISSING CODE', - 'tj' => '992', - 'tk' => '690', - 'tl' => '670', - 'tm' => '993', - 'tn' => '216', - 'to' => '676', - 'tr' => '90', - 'tt' => '1868', // @wikipedia original value: 1 868 - 'tv' => '688', - 'tw' => '886', - 'tz' => '255', - 'ua' => '380', - 'ug' => '256', + 'tj' => '992', + 'tk' => '690', + 'tl' => '670', + 'tm' => '993', + 'tn' => '216', + 'to' => '676', + 'tr' => '90', + 'tt' => '1868', // @wikipedia original value: 1 868 + 'tv' => '688', + 'tw' => '886', + 'tz' => '255', + 'ua' => '380', + 'ug' => '256', // 'um' => 'MISSING CODE', - 'us' => '1', - 'uy' => '598', - 'uz' => '998', + 'us' => '1', + 'uy' => '598', + 'uz' => '998', // 'va' => 'MISSING CODE', // @wikipedia original values: 39 066, assigned 379 - 'vc' => '1784', // @wikipedia original value: 1 784 - 've' => '58', - 'vg' => '1284', // @wikipedia original value: 1 284 - 'vi' => '1340', // @wikipedia original value: 1 340 - 'vn' => '84', - 'vu' => '678', - 'wf' => '681', - 'ws' => '685', - 'ye' => '967', - 'yt' => '262', - 'za' => '27', - 'zm' => '260', - 'zw' => '263' - ); + 'vc' => '1784', // @wikipedia original value: 1 784 + 've' => '58', + 'vg' => '1284', // @wikipedia original value: 1 284 + 'vi' => '1340', // @wikipedia original value: 1 340 + 'vn' => '84', + 'vu' => '678', + 'wf' => '681', + 'ws' => '685', + 'ye' => '967', + 'yt' => '262', + 'za' => '27', + 'zm' => '260', + 'zw' => '263' + ); } diff --git a/plugins/MobileMessaging/GSMCharset.php b/plugins/MobileMessaging/GSMCharset.php index 22278facb2..4d58c96580 100644 --- a/plugins/MobileMessaging/GSMCharset.php +++ b/plugins/MobileMessaging/GSMCharset.php @@ -16,144 +16,144 @@ */ class Piwik_MobileMessaging_GSMCharset { - public static $GSMCharset = array( + public static $GSMCharset = array( - // Standard GSM Characters, weight = 1 - '@' => 1, - '£' => 1, - '$' => 1, - '¥' => 1, - 'è' => 1, - 'é' => 1, - 'ù' => 1, - 'ì' => 1, - 'ò' => 1, - 'Ç' => 1, - 'Ø' => 1, - 'ø' => 1, - 'Å' => 1, - 'å' => 1, - '∆' => 1, - '_' => 1, - 'Φ' => 1, - 'Γ' => 1, - 'Λ' => 1, - 'Ω' => 1, - 'Π' => 1, - 'Ψ' => 1, - 'Σ' => 1, - 'Θ' => 1, - 'Ξ' => 1, - 'Æ' => 1, - 'æ' => 1, - 'ß' => 1, - 'É' => 1, - ' ' => 1, - '!' => 1, - '"' => 1, - '#' => 1, - '¤' => 1, - '%' => 1, - '&' => 1, - '\'' => 1, - '(' => 1, - ')' => 1, - '*' => 1, - '+' => 1, - ',' => 1, - '-' => 1, - '.' => 1, - '/' => 1, - '0' => 1, - '1' => 1, - '2' => 1, - '3' => 1, - '4' => 1, - '5' => 1, - '6' => 1, - '7' => 1, - '8' => 1, - '9' => 1, - ':' => 1, - ';' => 1, - '<' => 1, - '=' => 1, - '>' => 1, - '?' => 1, - '¡' => 1, - 'A' => 1, - 'B' => 1, - 'C' => 1, - 'D' => 1, - 'E' => 1, - 'F' => 1, - 'G' => 1, - 'H' => 1, - 'I' => 1, - 'J' => 1, - 'K' => 1, - 'L' => 1, - 'M' => 1, - 'N' => 1, - 'O' => 1, - 'P' => 1, - 'Q' => 1, - 'R' => 1, - 'S' => 1, - 'T' => 1, - 'U' => 1, - 'V' => 1, - 'W' => 1, - 'X' => 1, - 'Y' => 1, - 'Z' => 1, - 'Ä' => 1, - 'Ö' => 1, - 'Ñ' => 1, - 'Ü' => 1, - '§' => 1, - '¿' => 1, - 'a' => 1, - 'b' => 1, - 'c' => 1, - 'd' => 1, - 'e' => 1, - 'f' => 1, - 'g' => 1, - 'h' => 1, - 'i' => 1, - 'j' => 1, - 'k' => 1, - 'l' => 1, - 'm' => 1, - 'n' => 1, - 'o' => 1, - 'p' => 1, - 'q' => 1, - 'r' => 1, - 's' => 1, - 't' => 1, - 'u' => 1, - 'v' => 1, - 'w' => 1, - 'x' => 1, - 'y' => 1, - 'z' => 1, - 'ä' => 1, - 'ö' => 1, - 'ñ' => 1, - 'ü' => 1, - 'à ' => 1, + // Standard GSM Characters, weight = 1 + '@' => 1, + '£' => 1, + '$' => 1, + '¥' => 1, + 'è' => 1, + 'é' => 1, + 'ù' => 1, + 'ì' => 1, + 'ò' => 1, + 'Ç' => 1, + 'Ø' => 1, + 'ø' => 1, + 'Å' => 1, + 'å' => 1, + '∆' => 1, + '_' => 1, + 'Φ' => 1, + 'Γ' => 1, + 'Λ' => 1, + 'Ω' => 1, + 'Π' => 1, + 'Ψ' => 1, + 'Σ' => 1, + 'Θ' => 1, + 'Ξ' => 1, + 'Æ' => 1, + 'æ' => 1, + 'ß' => 1, + 'É' => 1, + ' ' => 1, + '!' => 1, + '"' => 1, + '#' => 1, + '¤' => 1, + '%' => 1, + '&' => 1, + '\'' => 1, + '(' => 1, + ')' => 1, + '*' => 1, + '+' => 1, + ',' => 1, + '-' => 1, + '.' => 1, + '/' => 1, + '0' => 1, + '1' => 1, + '2' => 1, + '3' => 1, + '4' => 1, + '5' => 1, + '6' => 1, + '7' => 1, + '8' => 1, + '9' => 1, + ':' => 1, + ';' => 1, + '<' => 1, + '=' => 1, + '>' => 1, + '?' => 1, + '¡' => 1, + 'A' => 1, + 'B' => 1, + 'C' => 1, + 'D' => 1, + 'E' => 1, + 'F' => 1, + 'G' => 1, + 'H' => 1, + 'I' => 1, + 'J' => 1, + 'K' => 1, + 'L' => 1, + 'M' => 1, + 'N' => 1, + 'O' => 1, + 'P' => 1, + 'Q' => 1, + 'R' => 1, + 'S' => 1, + 'T' => 1, + 'U' => 1, + 'V' => 1, + 'W' => 1, + 'X' => 1, + 'Y' => 1, + 'Z' => 1, + 'Ä' => 1, + 'Ö' => 1, + 'Ñ' => 1, + 'Ü' => 1, + '§' => 1, + '¿' => 1, + 'a' => 1, + 'b' => 1, + 'c' => 1, + 'd' => 1, + 'e' => 1, + 'f' => 1, + 'g' => 1, + 'h' => 1, + 'i' => 1, + 'j' => 1, + 'k' => 1, + 'l' => 1, + 'm' => 1, + 'n' => 1, + 'o' => 1, + 'p' => 1, + 'q' => 1, + 'r' => 1, + 's' => 1, + 't' => 1, + 'u' => 1, + 'v' => 1, + 'w' => 1, + 'x' => 1, + 'y' => 1, + 'z' => 1, + 'ä' => 1, + 'ö' => 1, + 'ñ' => 1, + 'ü' => 1, + 'à ' => 1, - // Extended GSM Characters, weight = 2 - '^' => 2, - '{' => 2, - '}' => 2, - '\\' => 2, - '[' => 2, - '~' => 2, - ']' => 2, - '|' => 2, - '€' => 2, - ); + // Extended GSM Characters, weight = 2 + '^' => 2, + '{' => 2, + '}' => 2, + '\\' => 2, + '[' => 2, + '~' => 2, + ']' => 2, + '|' => 2, + '€' => 2, + ); } diff --git a/plugins/MobileMessaging/MobileMessaging.php b/plugins/MobileMessaging/MobileMessaging.php index e090411562..62028ba3e4 100644 --- a/plugins/MobileMessaging/MobileMessaging.php +++ b/plugins/MobileMessaging/MobileMessaging.php @@ -1,10 +1,10 @@ <?php /** * Piwik - Open source web analytics - * + * * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * + * * @category Piwik_Plugins * @package Piwik_MobileMessaging */ @@ -15,324 +15,301 @@ */ class Piwik_MobileMessaging extends Piwik_Plugin { - const DELEGATED_MANAGEMENT_OPTION = 'MobileMessaging_DelegatedManagement'; - const PROVIDER_OPTION = 'Provider'; - const API_KEY_OPTION = 'APIKey'; - const PHONE_NUMBERS_OPTION = 'PhoneNumbers'; - const PHONE_NUMBER_VALIDATION_REQUEST_COUNT_OPTION = 'PhoneNumberValidationRequestCount'; - const SMS_SENT_COUNT_OPTION = 'SMSSentCount'; - const DELEGATED_MANAGEMENT_OPTION_DEFAULT = 'false'; - const USER_SETTINGS_POSTFIX_OPTION = '_MobileMessagingSettings'; - - const PHONE_NUMBERS_PARAMETER = 'phoneNumbers'; - - const MOBILE_TYPE = 'mobile'; - const SMS_FORMAT = 'sms'; - - static private $availableParameters = array( - self::PHONE_NUMBERS_PARAMETER => true, - ); - - static private $managedReportTypes = array( - self::MOBILE_TYPE => 'plugins/MobileMessaging/images/phone.png' - ); - - static private $managedReportFormats = array( - self::SMS_FORMAT => 'plugins/MobileMessaging/images/phone.png' - ); - - static private $availableReports = array( - array( - 'module' => 'MultiSites', - 'action' => 'getAll', - ), - array( - 'module' => 'MultiSites', - 'action' => 'getOne', - ), - ); - - /** - * Return information about this plugin. - * - * @see Piwik_Plugin - * - * @return array - */ - public function getInformation() - { - return array( - 'name' => 'Mobile Messaging Plugin', - 'description' => Piwik_Translate('MobileMessaging_PluginDescription'), - 'homepage' => 'http://piwik.org/', - 'author' => 'Piwik', - 'author_homepage' => 'http://piwik.org/', - 'license' => 'GPL v3 or later', - 'license_homepage' => 'http://www.gnu.org/licenses/gpl.html', - 'version' => Piwik_Version::VERSION, - ); - } - - function getListHooksRegistered() - { - return array( - 'AdminMenu.add' => 'addMenu', - 'AssetManager.getJsFiles' => 'getJsFiles', - 'PDFReports.getReportParameters' => 'getReportParameters', - 'PDFReports.validateReportParameters' => 'validateReportParameters', - 'PDFReports.getReportMetadata' => 'getReportMetadata', - 'PDFReports.getReportTypes' => 'getReportTypes', - 'PDFReports.getReportFormats' => 'getReportFormats', - 'PDFReports.getRendererInstance' => 'getRendererInstance', - 'PDFReports.getReportRecipients' => 'getReportRecipients', - 'PDFReports.allowMultipleReports' => 'allowMultipleReports', - 'PDFReports.sendReport' => 'sendReport', - 'template_reportParametersPDFReports' => 'template_reportParametersPDFReports', - ); - } - - function addMenu() - { - Piwik_AddAdminMenu( - 'MobileMessaging_SettingsMenu', - array('module' => 'MobileMessaging', 'action' => 'index'), - true - ); - } - - /** - * Get JavaScript files - * - * @param Piwik_Event_Notification $notification notification object - */ - function getJsFiles( $notification ) - { - $jsFiles = &$notification->getNotificationObject(); - - $jsFiles[] = "plugins/MobileMessaging/scripts/MobileMessagingSettings.js"; - } - - /** - * @param Piwik_Event_Notification $notification notification object - */ - function validateReportParameters( $notification ) - { - if(self::manageEvent($notification)) - { - $parameters = &$notification->getNotificationObject(); - - // phone number validation - $availablePhoneNumbers = Piwik_MobileMessaging_API::getInstance()->getActivatedPhoneNumbers(); - - $phoneNumbers = $parameters[self::PHONE_NUMBERS_PARAMETER]; - foreach($phoneNumbers as $key => $phoneNumber) - { - //when a wrong phone number is supplied we silently discard it - if(!in_array($phoneNumber, $availablePhoneNumbers)) - { - unset($phoneNumbers[$key]); - } - } - - // 'unset' seems to transform the array to an associative array - $parameters[self::PHONE_NUMBERS_PARAMETER] = array_values($phoneNumbers); - } - } - - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getReportMetadata( $notification ) - { - if(self::manageEvent($notification)) - { - $availableReportMetadata = &$notification->getNotificationObject(); - - $notificationInfo = $notification->getNotificationInfo(); - $idSite = $notificationInfo[Piwik_PDFReports_API::ID_SITE_INFO_KEY]; - - foreach(self::$availableReports as $availableReport) - { - $reportMetadata = Piwik_API_API::getInstance()->getMetadata( - $idSite, - $availableReport['module'], - $availableReport['action'] - ); - - if($reportMetadata != null) - { - $reportMetadata = reset($reportMetadata); - $availableReportMetadata[] = $reportMetadata; - } - } - } - } - - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getReportTypes( $notification ) - { - $reportTypes = &$notification->getNotificationObject(); - $reportTypes = array_merge($reportTypes, self::$managedReportTypes); - } - - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getReportFormats( $notification ) - { - if(self::manageEvent($notification)) - { - $reportFormats = &$notification->getNotificationObject(); - $reportFormats = array_merge($reportFormats, self::$managedReportFormats); - } - } - - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getReportParameters( $notification ) - { - if(self::manageEvent($notification)) - { - $availableParameters = &$notification->getNotificationObject(); - $availableParameters = self::$availableParameters; - } - } - - /** - * @param Piwik_Event_Notification $notification notification object - */ - function getRendererInstance( $notification ) - { - if(self::manageEvent($notification)) - { - $reportRenderer = &$notification->getNotificationObject(); - - if(Piwik_PluginsManager::getInstance()->isPluginActivated('MultiSites')) - { - $reportRenderer = new Piwik_MobileMessaging_ReportRenderer_Sms(); - } - else - { - $reportRenderer = new Piwik_MobileMessaging_ReportRenderer_Exception( - Piwik_Translate('MobileMessaging_MultiSites_Must_Be_Activated') - ); - } - } - } - - /** - * @param Piwik_Event_Notification $notification notification object - */ - function allowMultipleReports( $notification ) - { - if(self::manageEvent($notification)) - { - $allowMultipleReports = &$notification->getNotificationObject(); - $allowMultipleReports = false; - } - } - - function getReportRecipients( $notification ) - { - if(self::manageEvent($notification)) - { - $recipients = &$notification->getNotificationObject(); - $notificationInfo = $notification->getNotificationInfo(); - - $report = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]; - $recipients = $report['parameters'][self::PHONE_NUMBERS_PARAMETER]; - } - } - - /** - * @param Piwik_Event_Notification $notification notification object - */ - function sendReport( $notification ) - { - if(self::manageEvent($notification)) - { - $notificationInfo = $notification->getNotificationInfo(); - $report = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]; - $contents = $notificationInfo[Piwik_PDFReports_API::REPORT_CONTENT_KEY]; - - $parameters = $report['parameters']; - $phoneNumbers = $parameters[self::PHONE_NUMBERS_PARAMETER]; - - if(in_array('MultiSites_getAll', $report['reports'])) - { - $from = Piwik_Translate('General_Reports'); - } - else - { - $from = $notificationInfo[Piwik_PDFReports_API::WEBSITE_NAME_KEY]; - } - - $mobileMessagingAPI = Piwik_MobileMessaging_API::getInstance(); - foreach($phoneNumbers as $phoneNumber) - { - $mobileMessagingAPI->sendSMS( - $contents, - $phoneNumber, - $from - ); - } - } - } - - /** - * @param Piwik_Event_Notification $notification notification object - */ - static public function template_reportParametersPDFReports($notification) - { - if(Piwik::isUserIsAnonymous()) - { - return; - } - - $out =& $notification->getNotificationObject(); - $view = Piwik_View::factory('ReportParameters'); - $view->reportType = self::MOBILE_TYPE; - $view->phoneNumbers = Piwik_MobileMessaging_API::getInstance()->getActivatedPhoneNumbers(); - $out .= $view->render(); - } - - private static function manageEvent($notification) - { - $notificationInfo = $notification->getNotificationInfo(); - return in_array($notificationInfo[Piwik_PDFReports_API::REPORT_TYPE_INFO_KEY], array_keys(self::$managedReportTypes)); - } - - function install() - { - $delegatedManagement = Piwik_GetOption(self::DELEGATED_MANAGEMENT_OPTION); - if (empty($delegatedManagement)) - { - Piwik_SetOption(self::DELEGATED_MANAGEMENT_OPTION, self::DELEGATED_MANAGEMENT_OPTION_DEFAULT); - } - } - - function deactivate() - { - // delete all mobile reports - $pdfReportsAPIInstance = Piwik_PDFReports_API::getInstance(); - $reports = $pdfReportsAPIInstance->getReports(); - - foreach($reports as $report) - { - if ($report['type'] == Piwik_MobileMessaging::MOBILE_TYPE) - { - $pdfReportsAPIInstance->deleteReport($report['idreport']); - } - } - } - - public function uninstall() - { - // currently the UI does not allow to delete a plugin - // when it becomes available, all the MobileMessaging settings (API credentials, phone numbers, etc..) should be removed from the option table - return; - } + const DELEGATED_MANAGEMENT_OPTION = 'MobileMessaging_DelegatedManagement'; + const PROVIDER_OPTION = 'Provider'; + const API_KEY_OPTION = 'APIKey'; + const PHONE_NUMBERS_OPTION = 'PhoneNumbers'; + const PHONE_NUMBER_VALIDATION_REQUEST_COUNT_OPTION = 'PhoneNumberValidationRequestCount'; + const SMS_SENT_COUNT_OPTION = 'SMSSentCount'; + const DELEGATED_MANAGEMENT_OPTION_DEFAULT = 'false'; + const USER_SETTINGS_POSTFIX_OPTION = '_MobileMessagingSettings'; + + const PHONE_NUMBERS_PARAMETER = 'phoneNumbers'; + + const MOBILE_TYPE = 'mobile'; + const SMS_FORMAT = 'sms'; + + static private $availableParameters = array( + self::PHONE_NUMBERS_PARAMETER => true, + ); + + static private $managedReportTypes = array( + self::MOBILE_TYPE => 'plugins/MobileMessaging/images/phone.png' + ); + + static private $managedReportFormats = array( + self::SMS_FORMAT => 'plugins/MobileMessaging/images/phone.png' + ); + + static private $availableReports = array( + array( + 'module' => 'MultiSites', + 'action' => 'getAll', + ), + array( + 'module' => 'MultiSites', + 'action' => 'getOne', + ), + ); + + /** + * Return information about this plugin. + * + * @see Piwik_Plugin + * + * @return array + */ + public function getInformation() + { + return array( + 'name' => 'Mobile Messaging Plugin', + 'description' => Piwik_Translate('MobileMessaging_PluginDescription'), + 'homepage' => 'http://piwik.org/', + 'author' => 'Piwik', + 'author_homepage' => 'http://piwik.org/', + 'license' => 'GPL v3 or later', + 'license_homepage' => 'http://www.gnu.org/licenses/gpl.html', + 'version' => Piwik_Version::VERSION, + ); + } + + function getListHooksRegistered() + { + return array( + 'AdminMenu.add' => 'addMenu', + 'AssetManager.getJsFiles' => 'getJsFiles', + 'PDFReports.getReportParameters' => 'getReportParameters', + 'PDFReports.validateReportParameters' => 'validateReportParameters', + 'PDFReports.getReportMetadata' => 'getReportMetadata', + 'PDFReports.getReportTypes' => 'getReportTypes', + 'PDFReports.getReportFormats' => 'getReportFormats', + 'PDFReports.getRendererInstance' => 'getRendererInstance', + 'PDFReports.getReportRecipients' => 'getReportRecipients', + 'PDFReports.allowMultipleReports' => 'allowMultipleReports', + 'PDFReports.sendReport' => 'sendReport', + 'template_reportParametersPDFReports' => 'template_reportParametersPDFReports', + ); + } + + function addMenu() + { + Piwik_AddAdminMenu( + 'MobileMessaging_SettingsMenu', + array('module' => 'MobileMessaging', 'action' => 'index'), + true + ); + } + + /** + * Get JavaScript files + * + * @param Piwik_Event_Notification $notification notification object + */ + function getJsFiles($notification) + { + $jsFiles = & $notification->getNotificationObject(); + + $jsFiles[] = "plugins/MobileMessaging/scripts/MobileMessagingSettings.js"; + } + + /** + * @param Piwik_Event_Notification $notification notification object + */ + function validateReportParameters($notification) + { + if (self::manageEvent($notification)) { + $parameters = & $notification->getNotificationObject(); + + // phone number validation + $availablePhoneNumbers = Piwik_MobileMessaging_API::getInstance()->getActivatedPhoneNumbers(); + + $phoneNumbers = $parameters[self::PHONE_NUMBERS_PARAMETER]; + foreach ($phoneNumbers as $key => $phoneNumber) { + //when a wrong phone number is supplied we silently discard it + if (!in_array($phoneNumber, $availablePhoneNumbers)) { + unset($phoneNumbers[$key]); + } + } + + // 'unset' seems to transform the array to an associative array + $parameters[self::PHONE_NUMBERS_PARAMETER] = array_values($phoneNumbers); + } + } + + /** + * @param Piwik_Event_Notification $notification notification object + */ + function getReportMetadata($notification) + { + if (self::manageEvent($notification)) { + $availableReportMetadata = & $notification->getNotificationObject(); + + $notificationInfo = $notification->getNotificationInfo(); + $idSite = $notificationInfo[Piwik_PDFReports_API::ID_SITE_INFO_KEY]; + + foreach (self::$availableReports as $availableReport) { + $reportMetadata = Piwik_API_API::getInstance()->getMetadata( + $idSite, + $availableReport['module'], + $availableReport['action'] + ); + + if ($reportMetadata != null) { + $reportMetadata = reset($reportMetadata); + $availableReportMetadata[] = $reportMetadata; + } + } + } + } + + /** + * @param Piwik_Event_Notification $notification notification object + */ + function getReportTypes($notification) + { + $reportTypes = & $notification->getNotificationObject(); + $reportTypes = array_merge($reportTypes, self::$managedReportTypes); + } + + /** + * @param Piwik_Event_Notification $notification notification object + */ + function getReportFormats($notification) + { + if (self::manageEvent($notification)) { + $reportFormats = & $notification->getNotificationObject(); + $reportFormats = array_merge($reportFormats, self::$managedReportFormats); + } + } + + /** + * @param Piwik_Event_Notification $notification notification object + */ + function getReportParameters($notification) + { + if (self::manageEvent($notification)) { + $availableParameters = & $notification->getNotificationObject(); + $availableParameters = self::$availableParameters; + } + } + + /** + * @param Piwik_Event_Notification $notification notification object + */ + function getRendererInstance($notification) + { + if (self::manageEvent($notification)) { + $reportRenderer = & $notification->getNotificationObject(); + + if (Piwik_PluginsManager::getInstance()->isPluginActivated('MultiSites')) { + $reportRenderer = new Piwik_MobileMessaging_ReportRenderer_Sms(); + } else { + $reportRenderer = new Piwik_MobileMessaging_ReportRenderer_Exception( + Piwik_Translate('MobileMessaging_MultiSites_Must_Be_Activated') + ); + } + } + } + + /** + * @param Piwik_Event_Notification $notification notification object + */ + function allowMultipleReports($notification) + { + if (self::manageEvent($notification)) { + $allowMultipleReports = & $notification->getNotificationObject(); + $allowMultipleReports = false; + } + } + + function getReportRecipients($notification) + { + if (self::manageEvent($notification)) { + $recipients = & $notification->getNotificationObject(); + $notificationInfo = $notification->getNotificationInfo(); + + $report = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]; + $recipients = $report['parameters'][self::PHONE_NUMBERS_PARAMETER]; + } + } + + /** + * @param Piwik_Event_Notification $notification notification object + */ + function sendReport($notification) + { + if (self::manageEvent($notification)) { + $notificationInfo = $notification->getNotificationInfo(); + $report = $notificationInfo[Piwik_PDFReports_API::REPORT_KEY]; + $contents = $notificationInfo[Piwik_PDFReports_API::REPORT_CONTENT_KEY]; + + $parameters = $report['parameters']; + $phoneNumbers = $parameters[self::PHONE_NUMBERS_PARAMETER]; + + if (in_array('MultiSites_getAll', $report['reports'])) { + $from = Piwik_Translate('General_Reports'); + } else { + $from = $notificationInfo[Piwik_PDFReports_API::WEBSITE_NAME_KEY]; + } + + $mobileMessagingAPI = Piwik_MobileMessaging_API::getInstance(); + foreach ($phoneNumbers as $phoneNumber) { + $mobileMessagingAPI->sendSMS( + $contents, + $phoneNumber, + $from + ); + } + } + } + + /** + * @param Piwik_Event_Notification $notification notification object + */ + static public function template_reportParametersPDFReports($notification) + { + if (Piwik::isUserIsAnonymous()) { + return; + } + + $out =& $notification->getNotificationObject(); + $view = Piwik_View::factory('ReportParameters'); + $view->reportType = self::MOBILE_TYPE; + $view->phoneNumbers = Piwik_MobileMessaging_API::getInstance()->getActivatedPhoneNumbers(); + $out .= $view->render(); + } + + private static function manageEvent($notification) + { + $notificationInfo = $notification->getNotificationInfo(); + return in_array($notificationInfo[Piwik_PDFReports_API::REPORT_TYPE_INFO_KEY], array_keys(self::$managedReportTypes)); + } + + function install() + { + $delegatedManagement = Piwik_GetOption(self::DELEGATED_MANAGEMENT_OPTION); + if (empty($delegatedManagement)) { + Piwik_SetOption(self::DELEGATED_MANAGEMENT_OPTION, self::DELEGATED_MANAGEMENT_OPTION_DEFAULT); + } + } + + function deactivate() + { + // delete all mobile reports + $pdfReportsAPIInstance = Piwik_PDFReports_API::getInstance(); + $reports = $pdfReportsAPIInstance->getReports(); + + foreach ($reports as $report) { + if ($report['type'] == Piwik_MobileMessaging::MOBILE_TYPE) { + $pdfReportsAPIInstance->deleteReport($report['idreport']); + } + } + } + + public function uninstall() + { + // currently the UI does not allow to delete a plugin + // when it becomes available, all the MobileMessaging settings (API credentials, phone numbers, etc..) should be removed from the option table + return; + } } diff --git a/plugins/MobileMessaging/ReportRenderer/Exception.php b/plugins/MobileMessaging/ReportRenderer/Exception.php index af2352150a..a1eac80d8f 100644 --- a/plugins/MobileMessaging/ReportRenderer/Exception.php +++ b/plugins/MobileMessaging/ReportRenderer/Exception.php @@ -15,57 +15,57 @@ */ class Piwik_MobileMessaging_ReportRenderer_Exception extends Piwik_ReportRenderer { - private $rendering = ""; + private $rendering = ""; - function __construct($exception) - { - $this->rendering = $exception; - } + function __construct($exception) + { + $this->rendering = $exception; + } - public function setLocale($locale) - { - // nothing to do - } + public function setLocale($locale) + { + // nothing to do + } - public function sendToDisk($filename) - { - return Piwik_ReportRenderer::writeFile( - $filename, - Piwik_MobileMessaging_ReportRenderer_Sms::SMS_FILE_EXTENSION, - $this->rendering - ); - } + public function sendToDisk($filename) + { + return Piwik_ReportRenderer::writeFile( + $filename, + Piwik_MobileMessaging_ReportRenderer_Sms::SMS_FILE_EXTENSION, + $this->rendering + ); + } - public function sendToBrowserDownload($filename) - { - Piwik_ReportRenderer::sendToBrowser( - $filename, - Piwik_MobileMessaging_ReportRenderer_Sms::SMS_FILE_EXTENSION, - Piwik_MobileMessaging_ReportRenderer_Sms::SMS_CONTENT_TYPE, - $this->rendering - ); - } + public function sendToBrowserDownload($filename) + { + Piwik_ReportRenderer::sendToBrowser( + $filename, + Piwik_MobileMessaging_ReportRenderer_Sms::SMS_FILE_EXTENSION, + Piwik_MobileMessaging_ReportRenderer_Sms::SMS_CONTENT_TYPE, + $this->rendering + ); + } - public function sendToBrowserInline($filename) - { - Piwik_ReportRenderer::inlineToBrowser( - Piwik_MobileMessaging_ReportRenderer_Sms::SMS_CONTENT_TYPE, - $this->rendering - ); - } + public function sendToBrowserInline($filename) + { + Piwik_ReportRenderer::inlineToBrowser( + Piwik_MobileMessaging_ReportRenderer_Sms::SMS_CONTENT_TYPE, + $this->rendering + ); + } - public function getRenderedReport() - { - return $this->rendering; - } + public function getRenderedReport() + { + return $this->rendering; + } - public function renderFrontPage($websiteName, $prettyDate, $description, $reportMetadata) - { - // nothing to do - } + public function renderFrontPage($websiteName, $prettyDate, $description, $reportMetadata) + { + // nothing to do + } - public function renderReport($processedReport) - { - // nothing to do - } + public function renderReport($processedReport) + { + // nothing to do + } } diff --git a/plugins/MobileMessaging/ReportRenderer/Sms.php b/plugins/MobileMessaging/ReportRenderer/Sms.php index 47186f3ff6..96f2999d9f 100644 --- a/plugins/MobileMessaging/ReportRenderer/Sms.php +++ b/plugins/MobileMessaging/ReportRenderer/Sms.php @@ -16,65 +16,64 @@ */ class Piwik_MobileMessaging_ReportRenderer_Sms extends Piwik_ReportRenderer { - const FLOAT_REGEXP = '/[-+]?[0-9]*[\.,]?[0-9]+/'; - const SMS_CONTENT_TYPE = 'text/plain'; - const SMS_FILE_EXTENSION = 'sms'; - - private $rendering = ""; - - public function setLocale($locale) - { - // nothing to do - } - - public function sendToDisk($filename) - { - return Piwik_ReportRenderer::writeFile($filename, self::SMS_FILE_EXTENSION, $this->rendering); - } - - public function sendToBrowserDownload($filename) - { - Piwik_ReportRenderer::sendToBrowser($filename, self::SMS_FILE_EXTENSION, self::SMS_CONTENT_TYPE, $this->rendering); - } - - public function sendToBrowserInline($filename) - { - Piwik_ReportRenderer::inlineToBrowser(self::SMS_CONTENT_TYPE, $this->rendering); - } - - public function getRenderedReport() - { - return $this->rendering; - } - - public function renderFrontPage($websiteName, $prettyDate, $description, $reportMetadata) - { - // nothing to do - } - - public function renderReport($processedReport) - { - $isGoalPluginEnabled = Piwik_Common::isGoalPluginEnabled(); - $prettyDate = $processedReport['prettyDate']; - $reportData = $processedReport['reportData']; - - $evolutionMetrics = array(); - $multiSitesAPIMetrics = Piwik_MultiSites_API::getApiMetrics($enhanced = true); - foreach($multiSitesAPIMetrics as $metricSettings) - { - $evolutionMetrics[] = $metricSettings[Piwik_MultiSites_API::METRIC_EVOLUTION_COL_NAME_KEY]; - } - - // no decimal for all metrics to shorten SMS content (keeps the monetary sign for revenue metrics) - $reportData->filter( - 'ColumnCallbackReplace', - array( - array_merge(array_keys($multiSitesAPIMetrics),$evolutionMetrics), - create_function ( - '$value', - ' - return preg_replace_callback ( - "'.self::FLOAT_REGEXP.'", + const FLOAT_REGEXP = '/[-+]?[0-9]*[\.,]?[0-9]+/'; + const SMS_CONTENT_TYPE = 'text/plain'; + const SMS_FILE_EXTENSION = 'sms'; + + private $rendering = ""; + + public function setLocale($locale) + { + // nothing to do + } + + public function sendToDisk($filename) + { + return Piwik_ReportRenderer::writeFile($filename, self::SMS_FILE_EXTENSION, $this->rendering); + } + + public function sendToBrowserDownload($filename) + { + Piwik_ReportRenderer::sendToBrowser($filename, self::SMS_FILE_EXTENSION, self::SMS_CONTENT_TYPE, $this->rendering); + } + + public function sendToBrowserInline($filename) + { + Piwik_ReportRenderer::inlineToBrowser(self::SMS_CONTENT_TYPE, $this->rendering); + } + + public function getRenderedReport() + { + return $this->rendering; + } + + public function renderFrontPage($websiteName, $prettyDate, $description, $reportMetadata) + { + // nothing to do + } + + public function renderReport($processedReport) + { + $isGoalPluginEnabled = Piwik_Common::isGoalPluginEnabled(); + $prettyDate = $processedReport['prettyDate']; + $reportData = $processedReport['reportData']; + + $evolutionMetrics = array(); + $multiSitesAPIMetrics = Piwik_MultiSites_API::getApiMetrics($enhanced = true); + foreach ($multiSitesAPIMetrics as $metricSettings) { + $evolutionMetrics[] = $metricSettings[Piwik_MultiSites_API::METRIC_EVOLUTION_COL_NAME_KEY]; + } + + // no decimal for all metrics to shorten SMS content (keeps the monetary sign for revenue metrics) + $reportData->filter( + 'ColumnCallbackReplace', + array( + array_merge(array_keys($multiSitesAPIMetrics), $evolutionMetrics), + create_function( + '$value', + ' + return preg_replace_callback ( + "' . self::FLOAT_REGEXP . '", create_function ( \'$matches\', \'return round($matches[0]);\' @@ -82,47 +81,46 @@ class Piwik_MobileMessaging_ReportRenderer_Sms extends Piwik_ReportRenderer $value ); ' - ) - ) - ); - - // evolution metrics formatting : - // - remove monetary, percentage and white spaces to shorten SMS content - // (this is also needed to be able to test $value != 0 and see if there is an evolution at all in SMSReport.tpl) - // - adds a plus sign - $reportData->filter( - 'ColumnCallbackReplace', - array( - $evolutionMetrics, - create_function ( - '$value', - ' - $matched = preg_match("'.self::FLOAT_REGEXP.'", $value, $matches); + ) + ) + ); + + // evolution metrics formatting : + // - remove monetary, percentage and white spaces to shorten SMS content + // (this is also needed to be able to test $value != 0 and see if there is an evolution at all in SMSReport.tpl) + // - adds a plus sign + $reportData->filter( + 'ColumnCallbackReplace', + array( + $evolutionMetrics, + create_function( + '$value', + ' + $matched = preg_match("' . self::FLOAT_REGEXP . '", $value, $matches); return $matched ? sprintf("%+d",$matches[0]) : $value; ' - ) - ) - ); - - $dataRows = $reportData->getRows(); - $reportMetadata = $processedReport['reportMetadata']; - $reportRowsMetadata = $reportMetadata->getRows(); - - $siteHasECommerce = array(); - foreach($reportRowsMetadata as $rowMetadata) - { - $idSite = $rowMetadata->getColumn('idsite'); - $siteHasECommerce[$idSite] = Piwik_Site::isEcommerceEnabledFor($idSite); - } - - $smarty = new Piwik_Smarty(); - $smarty->assign("isGoalPluginEnabled", $isGoalPluginEnabled); - $smarty->assign("reportRows", $dataRows); - $smarty->assign("reportRowsMetadata", $reportRowsMetadata); - $smarty->assign("prettyDate", $prettyDate); - $smarty->assign("siteHasECommerce", $siteHasECommerce); - $smarty->assign("displaySiteName", $processedReport['metadata']['action'] == 'getAll'); - - $this->rendering .= $smarty->fetch(PIWIK_USER_PATH . '/plugins/MobileMessaging/templates/SMSReport.tpl'); - } + ) + ) + ); + + $dataRows = $reportData->getRows(); + $reportMetadata = $processedReport['reportMetadata']; + $reportRowsMetadata = $reportMetadata->getRows(); + + $siteHasECommerce = array(); + foreach ($reportRowsMetadata as $rowMetadata) { + $idSite = $rowMetadata->getColumn('idsite'); + $siteHasECommerce[$idSite] = Piwik_Site::isEcommerceEnabledFor($idSite); + } + + $smarty = new Piwik_Smarty(); + $smarty->assign("isGoalPluginEnabled", $isGoalPluginEnabled); + $smarty->assign("reportRows", $dataRows); + $smarty->assign("reportRowsMetadata", $reportRowsMetadata); + $smarty->assign("prettyDate", $prettyDate); + $smarty->assign("siteHasECommerce", $siteHasECommerce); + $smarty->assign("displaySiteName", $processedReport['metadata']['action'] == 'getAll'); + + $this->rendering .= $smarty->fetch(PIWIK_USER_PATH . '/plugins/MobileMessaging/templates/SMSReport.tpl'); + } } diff --git a/plugins/MobileMessaging/SMSProvider.php b/plugins/MobileMessaging/SMSProvider.php index 12bd7f0933..9f17311349 100644 --- a/plugins/MobileMessaging/SMSProvider.php +++ b/plugins/MobileMessaging/SMSProvider.php @@ -17,13 +17,13 @@ */ abstract class Piwik_MobileMessaging_SMSProvider { - const MAX_GSM_CHARS_IN_ONE_UNIQUE_SMS = 160; - const MAX_GSM_CHARS_IN_ONE_CONCATENATED_SMS = 153; - const MAX_UCS2_CHARS_IN_ONE_UNIQUE_SMS = 70; - const MAX_UCS2_CHARS_IN_ONE_CONCATENATED_SMS = 67; + const MAX_GSM_CHARS_IN_ONE_UNIQUE_SMS = 160; + const MAX_GSM_CHARS_IN_ONE_CONCATENATED_SMS = 153; + const MAX_UCS2_CHARS_IN_ONE_UNIQUE_SMS = 70; + const MAX_UCS2_CHARS_IN_ONE_CONCATENATED_SMS = 67; - static public $availableSMSProviders = array( - 'Clockwork' => 'You can use <a target="_blank" href="?module=Proxy&action=redirect&url=http://www.clockworksms.com/platforms/piwik/"><img src="plugins/MobileMessaging/images/Clockwork.png"/></a> to send SMS Reports from Piwik.<br/> + static public $availableSMSProviders = array( + 'Clockwork' => 'You can use <a target="_blank" href="?module=Proxy&action=redirect&url=http://www.clockworksms.com/platforms/piwik/"><img src="plugins/MobileMessaging/images/Clockwork.png"/></a> to send SMS Reports from Piwik.<br/> <ul> <li> First, <a target="_blank" href="?module=Proxy&action=redirect&url=http://www.clockworksms.com/platforms/piwik/">get an API Key from Clockwork</a> (Signup is free!) </li><li> Enter your Clockwork API Key on this page. </li> @@ -35,141 +35,138 @@ abstract class Piwik_MobileMessaging_SMSProvider </li> </ul> ', - ); - - /** - * Return the SMSProvider associated to the provider name $providerName - * - * @throws exception If the provider is unknown - * @param string $providerName - * @return Piwik_MobileMessaging_SMSProvider - */ - static public function factory($providerName) - { - $className = 'Piwik_MobileMessaging_SMSProvider_' . $providerName; - - try { - Piwik_Loader::loadClass($className); - return new $className; - } catch(Exception $e) { - throw new Exception( - Piwik_TranslateException( - 'MobileMessaging_Exception_UnknownProvider', - array($providerName, implode(', ', array_keys(self::$availableSMSProviders))) - ) - ); - } - } - - /** - * Assert whether a given String contains UCS2 characters - * - * @param string $string - * @return bool true if $string contains UCS2 characters - */ - static public function containsUCS2Characters($string) - { - $GSMCharsetAsString = implode(array_keys(Piwik_MobileMessaging_GSMCharset::$GSMCharset)); - - foreach(self::mb_str_split($string) as $char) - { - if(mb_strpos($GSMCharsetAsString, $char) === false) { - return true; - } - } - - return false; - } - - /** - * Truncate $string and append $appendedString at the end if $string can not fit the - * the $maximumNumberOfConcatenatedSMS. - * - * @param string $string String to truncate - * @param int $maximumNumberOfConcatenatedSMS - * @param string $appendedString - * @return string original $string or truncated $string appended with $appendedString - */ - static public function truncate($string, $maximumNumberOfConcatenatedSMS, $appendedString = 'MobileMessaging_SMS_Content_Too_Long') - { - $appendedString = Piwik_Translate($appendedString); - - $smsContentContainsUCS2Chars = self::containsUCS2Characters($string); - $maxCharsAllowed = self::maxCharsAllowed($maximumNumberOfConcatenatedSMS, $smsContentContainsUCS2Chars); - $sizeOfSMSContent = self::sizeOfSMSContent($string, $smsContentContainsUCS2Chars); - - if($sizeOfSMSContent <= $maxCharsAllowed) return $string; - - $smsContentContainsUCS2Chars = $smsContentContainsUCS2Chars || self::containsUCS2Characters($appendedString); - $maxCharsAllowed = self::maxCharsAllowed($maximumNumberOfConcatenatedSMS, $smsContentContainsUCS2Chars); - $sizeOfSMSContent = self::sizeOfSMSContent($string . $appendedString, $smsContentContainsUCS2Chars); - - $sizeToTruncate = $sizeOfSMSContent - $maxCharsAllowed; - - $subStrToTruncate = ''; - $subStrSize = 0; - $reversedStringChars = array_reverse(self::mb_str_split($string)); - for($i = 0; $subStrSize < $sizeToTruncate; $i++) - { - $subStrToTruncate = $reversedStringChars[$i] . $subStrToTruncate; - $subStrSize = self::sizeOfSMSContent($subStrToTruncate, $smsContentContainsUCS2Chars); - } - - return preg_replace('/' . preg_quote($subStrToTruncate) . '$/', $appendedString, $string); - } - - static private function mb_str_split($string) - { - return preg_split('//u',$string, -1, PREG_SPLIT_NO_EMPTY); - } - - static private function sizeOfSMSContent($smsContent, $containsUCS2Chars) - { - if($containsUCS2Chars) return mb_strlen($smsContent, 'UTF-8'); - - $sizeOfSMSContent = 0; - foreach(self::mb_str_split($smsContent) as $char) - { - $sizeOfSMSContent += Piwik_MobileMessaging_GSMCharset::$GSMCharset[$char]; - } - return $sizeOfSMSContent; - } - - static private function maxCharsAllowed($maximumNumberOfConcatenatedSMS, $containsUCS2Chars) - { - $maxCharsInOneUniqueSMS = $containsUCS2Chars ? self::MAX_UCS2_CHARS_IN_ONE_UNIQUE_SMS : self::MAX_GSM_CHARS_IN_ONE_UNIQUE_SMS; - $maxCharsInOneConcatenatedSMS = $containsUCS2Chars ? self::MAX_UCS2_CHARS_IN_ONE_CONCATENATED_SMS : self::MAX_GSM_CHARS_IN_ONE_CONCATENATED_SMS; - - $uniqueSMS = $maximumNumberOfConcatenatedSMS == 1; - - return $uniqueSMS ? - $maxCharsInOneUniqueSMS : - $maxCharsInOneConcatenatedSMS * $maximumNumberOfConcatenatedSMS; - } - - /** - * verify the SMS API credential - * - * @param string $apiKey API Key - * @return bool true if SMS API credential are valid, false otherwise - */ - abstract public function verifyCredential($apiKey); - - /** - * get remaining credits - * - * @param string $apiKey API Key - * @return string remaining credits - */ - abstract public function getCreditLeft($apiKey); - - /** - * send SMS - * - * @param string $apiKey - * @param string $smsText - * @param string $phoneNumber - * @return bool true - */ - abstract public function sendSMS($apiKey, $smsText, $phoneNumber, $from); + ); + + /** + * Return the SMSProvider associated to the provider name $providerName + * + * @throws exception If the provider is unknown + * @param string $providerName + * @return Piwik_MobileMessaging_SMSProvider + */ + static public function factory($providerName) + { + $className = 'Piwik_MobileMessaging_SMSProvider_' . $providerName; + + try { + Piwik_Loader::loadClass($className); + return new $className; + } catch (Exception $e) { + throw new Exception( + Piwik_TranslateException( + 'MobileMessaging_Exception_UnknownProvider', + array($providerName, implode(', ', array_keys(self::$availableSMSProviders))) + ) + ); + } + } + + /** + * Assert whether a given String contains UCS2 characters + * + * @param string $string + * @return bool true if $string contains UCS2 characters + */ + static public function containsUCS2Characters($string) + { + $GSMCharsetAsString = implode(array_keys(Piwik_MobileMessaging_GSMCharset::$GSMCharset)); + + foreach (self::mb_str_split($string) as $char) { + if (mb_strpos($GSMCharsetAsString, $char) === false) { + return true; + } + } + + return false; + } + + /** + * Truncate $string and append $appendedString at the end if $string can not fit the + * the $maximumNumberOfConcatenatedSMS. + * + * @param string $string String to truncate + * @param int $maximumNumberOfConcatenatedSMS + * @param string $appendedString + * @return string original $string or truncated $string appended with $appendedString + */ + static public function truncate($string, $maximumNumberOfConcatenatedSMS, $appendedString = 'MobileMessaging_SMS_Content_Too_Long') + { + $appendedString = Piwik_Translate($appendedString); + + $smsContentContainsUCS2Chars = self::containsUCS2Characters($string); + $maxCharsAllowed = self::maxCharsAllowed($maximumNumberOfConcatenatedSMS, $smsContentContainsUCS2Chars); + $sizeOfSMSContent = self::sizeOfSMSContent($string, $smsContentContainsUCS2Chars); + + if ($sizeOfSMSContent <= $maxCharsAllowed) return $string; + + $smsContentContainsUCS2Chars = $smsContentContainsUCS2Chars || self::containsUCS2Characters($appendedString); + $maxCharsAllowed = self::maxCharsAllowed($maximumNumberOfConcatenatedSMS, $smsContentContainsUCS2Chars); + $sizeOfSMSContent = self::sizeOfSMSContent($string . $appendedString, $smsContentContainsUCS2Chars); + + $sizeToTruncate = $sizeOfSMSContent - $maxCharsAllowed; + + $subStrToTruncate = ''; + $subStrSize = 0; + $reversedStringChars = array_reverse(self::mb_str_split($string)); + for ($i = 0; $subStrSize < $sizeToTruncate; $i++) { + $subStrToTruncate = $reversedStringChars[$i] . $subStrToTruncate; + $subStrSize = self::sizeOfSMSContent($subStrToTruncate, $smsContentContainsUCS2Chars); + } + + return preg_replace('/' . preg_quote($subStrToTruncate) . '$/', $appendedString, $string); + } + + static private function mb_str_split($string) + { + return preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY); + } + + static private function sizeOfSMSContent($smsContent, $containsUCS2Chars) + { + if ($containsUCS2Chars) return mb_strlen($smsContent, 'UTF-8'); + + $sizeOfSMSContent = 0; + foreach (self::mb_str_split($smsContent) as $char) { + $sizeOfSMSContent += Piwik_MobileMessaging_GSMCharset::$GSMCharset[$char]; + } + return $sizeOfSMSContent; + } + + static private function maxCharsAllowed($maximumNumberOfConcatenatedSMS, $containsUCS2Chars) + { + $maxCharsInOneUniqueSMS = $containsUCS2Chars ? self::MAX_UCS2_CHARS_IN_ONE_UNIQUE_SMS : self::MAX_GSM_CHARS_IN_ONE_UNIQUE_SMS; + $maxCharsInOneConcatenatedSMS = $containsUCS2Chars ? self::MAX_UCS2_CHARS_IN_ONE_CONCATENATED_SMS : self::MAX_GSM_CHARS_IN_ONE_CONCATENATED_SMS; + + $uniqueSMS = $maximumNumberOfConcatenatedSMS == 1; + + return $uniqueSMS ? + $maxCharsInOneUniqueSMS : + $maxCharsInOneConcatenatedSMS * $maximumNumberOfConcatenatedSMS; + } + + /** + * verify the SMS API credential + * + * @param string $apiKey API Key + * @return bool true if SMS API credential are valid, false otherwise + */ + abstract public function verifyCredential($apiKey); + + /** + * get remaining credits + * + * @param string $apiKey API Key + * @return string remaining credits + */ + abstract public function getCreditLeft($apiKey); + + /** + * send SMS + * + * @param string $apiKey + * @param string $smsText + * @param string $phoneNumber + * @return bool true + */ + abstract public function sendSMS($apiKey, $smsText, $phoneNumber, $from); } diff --git a/plugins/MobileMessaging/SMSProvider/Clockwork.php b/plugins/MobileMessaging/SMSProvider/Clockwork.php index dfb7854fd3..b7a50dfe02 100644 --- a/plugins/MobileMessaging/SMSProvider/Clockwork.php +++ b/plugins/MobileMessaging/SMSProvider/Clockwork.php @@ -16,86 +16,85 @@ require_once PIWIK_INCLUDE_PATH . "/plugins/MobileMessaging/APIException.php"; */ class Piwik_MobileMessaging_SMSProvider_Clockwork extends Piwik_MobileMessaging_SMSProvider { - const SOCKET_TIMEOUT = 15; - - const BASE_API_URL = 'https://api.mediaburst.co.uk/http'; - const CHECK_CREDIT_RESOURCE = '/credit.aspx'; - const SEND_SMS_RESOURCE = '/send.aspx'; - - const ERROR_STRING = 'Error'; - - const MAXIMUM_FROM_LENGTH = 11; - const MAXIMUM_CONCATENATED_SMS = 3; - - public function verifyCredential($apiKey) - { - $this->getCreditLeft($apiKey); - - return true; - } - - public function sendSMS($apiKey, $smsText, $phoneNumber, $from) - { - $from = substr($from, 0, self::MAXIMUM_FROM_LENGTH); - - $smsText = self::truncate($smsText, self::MAXIMUM_CONCATENATED_SMS); - - $additionalParameters = array( - 'To' => str_replace('+','', $phoneNumber), - 'Content' => $smsText, - 'From' => $from, - 'Long' => 1, - 'MsgType' => self::containsUCS2Characters($smsText) ? 'UCS2' : 'TEXT', - ); - - $this->issueApiCall( - $apiKey, - self::SEND_SMS_RESOURCE, - $additionalParameters - ); - } - - private function issueApiCall($apiKey, $resource, $additionalParameters = array()) - { - $accountParameters = array( - 'Key' => $apiKey, - ); - - $parameters = array_merge($accountParameters, $additionalParameters); - - $url = self::BASE_API_URL - . $resource - . '?' . http_build_query($parameters, '', '&'); - - $timeout = self::SOCKET_TIMEOUT; - - $result = Piwik_Http::sendHttpRequestBy( - Piwik_Http::getTransportMethod(), - $url, - $timeout, - $userAgent = null, - $destinationPath = null, - $file = null, - $followDepth = 0, - $acceptLanguage = false, - $acceptInvalidSslCertificate = true - ); - - if(strpos($result, self::ERROR_STRING) !== false) - { - throw new Piwik_MobileMessaging_APIException( - 'Clockwork API returned the following error message : ' . $result - ); - } - - return $result; - } - - public function getCreditLeft($apiKey) - { - return $this->issueApiCall( - $apiKey, - self::CHECK_CREDIT_RESOURCE - ); - } + const SOCKET_TIMEOUT = 15; + + const BASE_API_URL = 'https://api.mediaburst.co.uk/http'; + const CHECK_CREDIT_RESOURCE = '/credit.aspx'; + const SEND_SMS_RESOURCE = '/send.aspx'; + + const ERROR_STRING = 'Error'; + + const MAXIMUM_FROM_LENGTH = 11; + const MAXIMUM_CONCATENATED_SMS = 3; + + public function verifyCredential($apiKey) + { + $this->getCreditLeft($apiKey); + + return true; + } + + public function sendSMS($apiKey, $smsText, $phoneNumber, $from) + { + $from = substr($from, 0, self::MAXIMUM_FROM_LENGTH); + + $smsText = self::truncate($smsText, self::MAXIMUM_CONCATENATED_SMS); + + $additionalParameters = array( + 'To' => str_replace('+', '', $phoneNumber), + 'Content' => $smsText, + 'From' => $from, + 'Long' => 1, + 'MsgType' => self::containsUCS2Characters($smsText) ? 'UCS2' : 'TEXT', + ); + + $this->issueApiCall( + $apiKey, + self::SEND_SMS_RESOURCE, + $additionalParameters + ); + } + + private function issueApiCall($apiKey, $resource, $additionalParameters = array()) + { + $accountParameters = array( + 'Key' => $apiKey, + ); + + $parameters = array_merge($accountParameters, $additionalParameters); + + $url = self::BASE_API_URL + . $resource + . '?' . http_build_query($parameters, '', '&'); + + $timeout = self::SOCKET_TIMEOUT; + + $result = Piwik_Http::sendHttpRequestBy( + Piwik_Http::getTransportMethod(), + $url, + $timeout, + $userAgent = null, + $destinationPath = null, + $file = null, + $followDepth = 0, + $acceptLanguage = false, + $acceptInvalidSslCertificate = true + ); + + if (strpos($result, self::ERROR_STRING) !== false) { + throw new Piwik_MobileMessaging_APIException( + 'Clockwork API returned the following error message : ' . $result + ); + } + + return $result; + } + + public function getCreditLeft($apiKey) + { + return $this->issueApiCall( + $apiKey, + self::CHECK_CREDIT_RESOURCE + ); + } } diff --git a/plugins/MobileMessaging/SMSProvider/StubbedProvider.php b/plugins/MobileMessaging/SMSProvider/StubbedProvider.php index 57f89e73d2..8402eefc51 100644 --- a/plugins/MobileMessaging/SMSProvider/StubbedProvider.php +++ b/plugins/MobileMessaging/SMSProvider/StubbedProvider.php @@ -17,18 +17,18 @@ class Piwik_MobileMessaging_SMSProvider_StubbedProvider extends Piwik_MobileMessaging_SMSProvider { - public function verifyCredential($apiKey) - { - return true; - } + public function verifyCredential($apiKey) + { + return true; + } - public function sendSMS($apiKey, $smsText, $phoneNumber, $from) - { - // nothing to do - } + public function sendSMS($apiKey, $smsText, $phoneNumber, $from) + { + // nothing to do + } - public function getCreditLeft($apiKey) - { - return 1; - } + public function getCreditLeft($apiKey) + { + return 1; + } }
\ No newline at end of file diff --git a/plugins/MobileMessaging/scripts/MobileMessagingSettings.js b/plugins/MobileMessaging/scripts/MobileMessagingSettings.js index 840578a1c1..207d4c725d 100644 --- a/plugins/MobileMessaging/scripts/MobileMessagingSettings.js +++ b/plugins/MobileMessaging/scripts/MobileMessagingSettings.js @@ -8,103 +8,93 @@ // TODO when UI stabilized, factorize ajax boiler plate accros MobileMessagingSettings javascript functions var MobileMessagingSettings = MobileMessagingSettings || (function () { - /************************************************************ - * Private data - ************************************************************/ - var - delegatedManagementSelector = 'input[name=delegatedManagement]', - apiAccountSubmitSelector = '#apiAccountSubmit', - addPhoneNumberSubmitSelector = '#addPhoneNumberSubmit', - providersSelector = '#smsProviders', - providerDescriptionsSelector = '.providerDescription', - apiKeySelector = '#apiKey', - countriesSelector = '#countries', - countryCallingCodeSelector = '#countryCallingCode', - newPhoneNumberSelector = '#newPhoneNumber', - suspiciousPhoneNumberSelector = '#suspiciousPhoneNumber', - validatePhoneNumberSubmitSelector = '.validatePhoneNumberSubmit', - formDescriptionSelector = '.form-description', - removePhoneNumberSubmitSelector = '.removePhoneNumberSubmit', - verificationCodeSelector = '.verificationCode', - phoneNumberSelector = '.phoneNumber', - deleteAcountSelector = '#deleteAccount', - confirmDeleteAccountSelector = '#confirmDeleteAccount', - accountFormSelector = '#accountForm', - displayAccountFormSelector = '#displayAccountForm', - phoneNumberActivatedSelector = '#phoneNumberActivated', - invalidActivationCodeMsgSelector = '#invalidActivationCode', - ajaxErrorsSelector = '#ajaxErrorMobileMessagingSettings', - invalidVerificationCodeAjaxErrorSelector = '#invalidVerificationCodeAjaxError', - ajaxLoadingSelector = '#ajaxLoadingMobileMessagingSettings'; - - /************************************************************ - * Private methods - ************************************************************/ - - function initUIEvents() { - - $(delegatedManagementSelector).change(updateDelegatedManagement); - $(apiAccountSubmitSelector).click(updateApiAccount); - $(deleteAcountSelector).click(confirmDeleteApiAccount); - $(displayAccountFormSelector).click(displayAccountForm); - $(addPhoneNumberSubmitSelector).click(addPhoneNumber); - $(newPhoneNumberSelector).keyup(updateSuspiciousPhoneNumberMessage); - $(validatePhoneNumberSubmitSelector).click(validatePhoneNumber); - $(removePhoneNumberSubmitSelector).click(removePhoneNumber); - $(countryCallingCodeSelector).keyup(updateCountry); - $(countriesSelector).change(updateCountryCallingCode); - updateCountryCallingCode(); - $(providersSelector).change(updateProviderDescription); - updateProviderDescription(); - } - - function updateCountry() - { - var countryCallingCode = $(countryCallingCodeSelector).val(); - if(countryCallingCode != null && countryCallingCode != '') - { - var countryToSelect = $(countriesSelector + ' option[value='+countryCallingCode+']'); - if(countryToSelect.size() > 0) - { - countryToSelect.attr('selected', 'selected'); - } - else - { - $(countriesSelector + ' option:selected').removeAttr('selected'); - } - } - } - - function displayAccountForm() - { - $(accountFormSelector).show(); - } - - function validatePhoneNumber(event) - { - var phoneNumberContainer = $(event.target).parent(); - var verificationCodeContainer = phoneNumberContainer.find(verificationCodeSelector); - var verificationCode = verificationCodeContainer.val(); - var phoneNumber = phoneNumberContainer.find(phoneNumberSelector).html(); - - if(verificationCode != null && verificationCode != '') - { - var success = - function(response) - { - $(phoneNumberActivatedSelector).hide(); - if(!response.value) - { - $(invalidVerificationCodeAjaxErrorSelector).html($(invalidActivationCodeMsgSelector).html()).fadeIn(); - } - else - { - $(phoneNumberActivatedSelector).show(); - $(verificationCodeContainer).remove(); - $(phoneNumberContainer).find(validatePhoneNumberSubmitSelector).remove(); - $(phoneNumberContainer).find(formDescriptionSelector).remove(); - } - }; + /************************************************************ + * Private data + ************************************************************/ + var + delegatedManagementSelector = 'input[name=delegatedManagement]', + apiAccountSubmitSelector = '#apiAccountSubmit', + addPhoneNumberSubmitSelector = '#addPhoneNumberSubmit', + providersSelector = '#smsProviders', + providerDescriptionsSelector = '.providerDescription', + apiKeySelector = '#apiKey', + countriesSelector = '#countries', + countryCallingCodeSelector = '#countryCallingCode', + newPhoneNumberSelector = '#newPhoneNumber', + suspiciousPhoneNumberSelector = '#suspiciousPhoneNumber', + validatePhoneNumberSubmitSelector = '.validatePhoneNumberSubmit', + formDescriptionSelector = '.form-description', + removePhoneNumberSubmitSelector = '.removePhoneNumberSubmit', + verificationCodeSelector = '.verificationCode', + phoneNumberSelector = '.phoneNumber', + deleteAcountSelector = '#deleteAccount', + confirmDeleteAccountSelector = '#confirmDeleteAccount', + accountFormSelector = '#accountForm', + displayAccountFormSelector = '#displayAccountForm', + phoneNumberActivatedSelector = '#phoneNumberActivated', + invalidActivationCodeMsgSelector = '#invalidActivationCode', + ajaxErrorsSelector = '#ajaxErrorMobileMessagingSettings', + invalidVerificationCodeAjaxErrorSelector = '#invalidVerificationCodeAjaxError', + ajaxLoadingSelector = '#ajaxLoadingMobileMessagingSettings'; + + /************************************************************ + * Private methods + ************************************************************/ + + function initUIEvents() { + + $(delegatedManagementSelector).change(updateDelegatedManagement); + $(apiAccountSubmitSelector).click(updateApiAccount); + $(deleteAcountSelector).click(confirmDeleteApiAccount); + $(displayAccountFormSelector).click(displayAccountForm); + $(addPhoneNumberSubmitSelector).click(addPhoneNumber); + $(newPhoneNumberSelector).keyup(updateSuspiciousPhoneNumberMessage); + $(validatePhoneNumberSubmitSelector).click(validatePhoneNumber); + $(removePhoneNumberSubmitSelector).click(removePhoneNumber); + $(countryCallingCodeSelector).keyup(updateCountry); + $(countriesSelector).change(updateCountryCallingCode); + updateCountryCallingCode(); + $(providersSelector).change(updateProviderDescription); + updateProviderDescription(); + } + + function updateCountry() { + var countryCallingCode = $(countryCallingCodeSelector).val(); + if (countryCallingCode != null && countryCallingCode != '') { + var countryToSelect = $(countriesSelector + ' option[value=' + countryCallingCode + ']'); + if (countryToSelect.size() > 0) { + countryToSelect.attr('selected', 'selected'); + } + else { + $(countriesSelector + ' option:selected').removeAttr('selected'); + } + } + } + + function displayAccountForm() { + $(accountFormSelector).show(); + } + + function validatePhoneNumber(event) { + var phoneNumberContainer = $(event.target).parent(); + var verificationCodeContainer = phoneNumberContainer.find(verificationCodeSelector); + var verificationCode = verificationCodeContainer.val(); + var phoneNumber = phoneNumberContainer.find(phoneNumberSelector).html(); + + if (verificationCode != null && verificationCode != '') { + var success = + function (response) { + $(phoneNumberActivatedSelector).hide(); + if (!response.value) { + $(invalidVerificationCodeAjaxErrorSelector).html($(invalidActivationCodeMsgSelector).html()).fadeIn(); + } + else { + $(phoneNumberActivatedSelector).show(); + $(verificationCodeContainer).remove(); + $(phoneNumberContainer).find(validatePhoneNumberSubmitSelector).remove(); + $(phoneNumberContainer).find(formDescriptionSelector).remove(); + } + }; var ajaxHandler = new ajaxHelper(); ajaxHandler.addParams({ @@ -117,13 +107,12 @@ var MobileMessagingSettings = MobileMessagingSettings || (function () { ajaxHandler.setLoadingElement(ajaxLoadingSelector); ajaxHandler.setErrorElement(invalidVerificationCodeAjaxErrorSelector); ajaxHandler.send(true); - } - } + } + } - function removePhoneNumber(event) - { - var phoneNumberContainer = $(event.target).parent(); - var phoneNumber = phoneNumberContainer.find(phoneNumberSelector).html(); + function removePhoneNumber(event) { + var phoneNumberContainer = $(event.target).parent(); + var phoneNumber = phoneNumberContainer.find(phoneNumberSelector).html(); var ajaxHandler = new ajaxHelper(); ajaxHandler.addParams({ @@ -136,32 +125,27 @@ var MobileMessagingSettings = MobileMessagingSettings || (function () { ajaxHandler.setLoadingElement(ajaxLoadingSelector); ajaxHandler.setErrorElement(ajaxErrorsSelector); ajaxHandler.send(true); - } - - function updateSuspiciousPhoneNumberMessage() - { - var newPhoneNumber = $(newPhoneNumberSelector).val(); - - // check if number starts with 0 - if($.trim(newPhoneNumber).lastIndexOf('0', 0) === 0) - { - $(suspiciousPhoneNumberSelector).show(); - } - else - { - $(suspiciousPhoneNumberSelector).hide(); - } - } - - function addPhoneNumber() - { - var newPhoneNumber = $(newPhoneNumberSelector).val(); - var countryCallingCode = $(countryCallingCodeSelector).val(); - - var phoneNumber = '+' + countryCallingCode + newPhoneNumber; - - if(newPhoneNumber != null && newPhoneNumber != '') - { + } + + function updateSuspiciousPhoneNumberMessage() { + var newPhoneNumber = $(newPhoneNumberSelector).val(); + + // check if number starts with 0 + if ($.trim(newPhoneNumber).lastIndexOf('0', 0) === 0) { + $(suspiciousPhoneNumberSelector).show(); + } + else { + $(suspiciousPhoneNumberSelector).hide(); + } + } + + function addPhoneNumber() { + var newPhoneNumber = $(newPhoneNumberSelector).val(); + var countryCallingCode = $(countryCallingCodeSelector).val(); + + var phoneNumber = '+' + countryCallingCode + newPhoneNumber; + + if (newPhoneNumber != null && newPhoneNumber != '') { var ajaxHandler = new ajaxHelper(); ajaxHandler.addParams({ module: 'API', @@ -173,30 +157,27 @@ var MobileMessagingSettings = MobileMessagingSettings || (function () { ajaxHandler.setLoadingElement(ajaxLoadingSelector); ajaxHandler.setErrorElement(ajaxErrorsSelector); ajaxHandler.send(true); - } - } - - function updateCountryCallingCode() - { - $(countryCallingCodeSelector).val($(countriesSelector + ' option:selected').val()); - } - - function updateProviderDescription() - { - $(providerDescriptionsSelector).hide(); - $('#' + $(providersSelector + ' option:selected').val() + providerDescriptionsSelector).show(); - } - - function updateDelegatedManagement() { - setDelegatedManagement(getDelegatedManagement()); - } - - function confirmDeleteApiAccount() - { - piwikHelper.modalConfirm(confirmDeleteAccountSelector, {yes: deleteApiAccount}); - } - - function deleteApiAccount() { + } + } + + function updateCountryCallingCode() { + $(countryCallingCodeSelector).val($(countriesSelector + ' option:selected').val()); + } + + function updateProviderDescription() { + $(providerDescriptionsSelector).hide(); + $('#' + $(providersSelector + ' option:selected').val() + providerDescriptionsSelector).show(); + } + + function updateDelegatedManagement() { + setDelegatedManagement(getDelegatedManagement()); + } + + function confirmDeleteApiAccount() { + piwikHelper.modalConfirm(confirmDeleteAccountSelector, {yes: deleteApiAccount}); + } + + function deleteApiAccount() { var ajaxHandler = new ajaxHelper(); ajaxHandler.addParams({ module: 'API', @@ -207,14 +188,14 @@ var MobileMessagingSettings = MobileMessagingSettings || (function () { ajaxHandler.setLoadingElement(ajaxLoadingSelector); ajaxHandler.setErrorElement(ajaxErrorsSelector); ajaxHandler.send(true); - } + } - function updateApiAccount() { + function updateApiAccount() { - var provider = $(providersSelector + ' option:selected').val(); - var apiKey = $(apiKeySelector).val(); + var provider = $(providersSelector + ' option:selected').val(); + var apiKey = $(apiKeySelector).val(); - if(apiKey != '') { + if (apiKey != '') { var ajaxHandler = new ajaxHelper(); ajaxHandler.addParams({ module: 'API', @@ -226,10 +207,10 @@ var MobileMessagingSettings = MobileMessagingSettings || (function () { ajaxHandler.setLoadingElement(ajaxLoadingSelector); ajaxHandler.setErrorElement(ajaxErrorsSelector); ajaxHandler.send(true); - } - } + } + } - function setDelegatedManagement(delegatedManagement) { + function setDelegatedManagement(delegatedManagement) { var ajaxHandler = new ajaxHelper(); ajaxHandler.addParams({ module: 'API', @@ -241,28 +222,28 @@ var MobileMessagingSettings = MobileMessagingSettings || (function () { ajaxHandler.setLoadingElement(ajaxLoadingSelector); ajaxHandler.setErrorElement(ajaxErrorsSelector); ajaxHandler.send(true); - } + } - function getDelegatedManagement() { - return $(delegatedManagementSelector + ':checked').val(); - } + function getDelegatedManagement() { + return $(delegatedManagementSelector + ':checked').val(); + } - /************************************************************ - * Public data and methods - ************************************************************/ + /************************************************************ + * Public data and methods + ************************************************************/ - return { + return { - /* - * Initialize UI events - */ - initUIEvents: function () { - initUIEvents(); - } - }; + /* + * Initialize UI events + */ + initUIEvents: function () { + initUIEvents(); + } + }; }()); -$(document).ready( function() { - MobileMessagingSettings.initUIEvents(); +$(document).ready(function () { + MobileMessagingSettings.initUIEvents(); }); diff --git a/plugins/MobileMessaging/templates/ReportParameters.tpl b/plugins/MobileMessaging/templates/ReportParameters.tpl index dceecaf490..24a6154667 100644 --- a/plugins/MobileMessaging/templates/ReportParameters.tpl +++ b/plugins/MobileMessaging/templates/ReportParameters.tpl @@ -1,64 +1,71 @@ <script> - $(function() {ldelim} - resetReportParametersFunctions ['{$reportType}'] = - function () {ldelim} + $(function () {ldelim} + resetReportParametersFunctions ['{$reportType}'] = + function () {ldelim} - var reportParameters = {ldelim} - 'phoneNumbers' : [], - {rdelim}; + var reportParameters = {ldelim} + 'phoneNumbers': [], + {rdelim}; - updateReportParametersFunctions['{$reportType}'](reportParameters); - {rdelim}; + updateReportParametersFunctions['{$reportType}'](reportParameters); + {rdelim + }; - updateReportParametersFunctions['{$reportType}'] = - function (reportParameters) {ldelim} + updateReportParametersFunctions['{$reportType}'] = + function (reportParameters) {ldelim} - if(reportParameters == null) return; + if (reportParameters == null) return; - $('[name=phoneNumbers]').removeProp('checked'); - $(reportParameters.phoneNumbers).each(function(index, phoneNumber) {ldelim} - $('#\\'+phoneNumber).prop('checked','checked'); - {rdelim}); - {rdelim}; + $('[name=phoneNumbers]').removeProp('checked'); + $(reportParameters.phoneNumbers).each(function (index, phoneNumber) {ldelim} + $('#\\' + phoneNumber).prop('checked', 'checked'); + {rdelim + }); + {rdelim + }; - getReportParametersFunctions['{$reportType}'] = - function () {ldelim} + getReportParametersFunctions['{$reportType}'] = + function () {ldelim} - var parameters = Object(); + var parameters = Object(); - var selectedPhoneNumbers = - $.map( - $('[name=phoneNumbers]:checked'), - function (phoneNumber) {ldelim} - return $(phoneNumber).attr('id'); - {rdelim} - ); + var selectedPhoneNumbers = + $.map( + $('[name=phoneNumbers]:checked'), + function (phoneNumber) {ldelim} + return $(phoneNumber).attr('id'); + {rdelim + } + ); - // returning [''] when no phone numbers are selected avoids the "please provide a value for 'parameters'" error message - parameters.phoneNumbers = - selectedPhoneNumbers.length > 0 ? selectedPhoneNumbers : ['']; + // returning [''] when no phone numbers are selected avoids the "please provide a value for 'parameters'" error message + parameters.phoneNumbers = + selectedPhoneNumbers.length > 0 ? selectedPhoneNumbers : ['']; - return parameters; - {rdelim}; - {rdelim}); + return parameters; + {rdelim + }; + {rdelim + }); </script> <tr class='{$reportType}'> - <td class="first"> - {'MobileMessaging_MobileReport_PhoneNumbers'|translate} - </td> - <td> - {if $phoneNumbers|@count eq 0} - <div class="entityInlineHelp"> - {'MobileMessaging_MobileReport_NoPhoneNumbers'|translate} - {else} - {foreach from=$phoneNumbers item=phoneNumber} - <label><input name='phoneNumbers' type='checkbox' id='{$phoneNumber}'/>{$phoneNumber}</label><br/> - {/foreach} - <div class="entityInlineHelp"> - {'MobileMessaging_MobileReport_AdditionalPhoneNumbers'|translate} - {/if} - <a href='{url module="MobileMessaging" updated=null}'>{'MobileMessaging_MobileReport_MobileMessagingSettingsLink'|translate}</a> - </div> - </td> + <td class="first"> + {'MobileMessaging_MobileReport_PhoneNumbers'|translate} + </td> + <td> + {if $phoneNumbers|@count eq 0} + <div class="entityInlineHelp"> + {'MobileMessaging_MobileReport_NoPhoneNumbers'|translate} + {else} + {foreach from=$phoneNumbers item=phoneNumber} + <label><input name='phoneNumbers' type='checkbox' id='{$phoneNumber}'/>{$phoneNumber}</label> + <br/> + {/foreach} + <div class="entityInlineHelp"> + {'MobileMessaging_MobileReport_AdditionalPhoneNumbers'|translate} + {/if} + <a href='{url module="MobileMessaging" updated=null}'>{'MobileMessaging_MobileReport_MobileMessagingSettingsLink'|translate}</a> + </div> + </td> </tr> diff --git a/plugins/MobileMessaging/templates/SMSReport.tpl b/plugins/MobileMessaging/templates/SMSReport.tpl index 2084ce426f..c74ea165c4 100644 --- a/plugins/MobileMessaging/templates/SMSReport.tpl +++ b/plugins/MobileMessaging/templates/SMSReport.tpl @@ -1,71 +1,71 @@ {strip} - {$prettyDate}.{literal} {/literal} - - {if empty($reportRows)} - {'CoreHome_ThereIsNoDataForThisReport'|translate} - {/if} - - {foreach name=reportRows from=$reportRows item=row key=rowId} - - {assign var=rowMetrics value=$row->getColumns()} - {assign var=rowMetadata value=$reportRowsMetadata[$rowId]->getColumns()} - - {if $displaySiteName} - {$rowMetrics.label}:{literal} {/literal} - {/if} - - {*visits*} - {$rowMetrics.nb_visits} {'General_ColumnNbVisits'|translate} - {if $rowMetrics.visits_evolution != 0} - {literal} {/literal}({$rowMetrics.visits_evolution}%) - {/if} - - {if $rowMetrics.nb_visits != 0} - - {*actions*} - ,{literal} {/literal} - {$rowMetrics.nb_actions} {'General_ColumnNbActions'|translate} - {if $rowMetrics.actions_evolution != 0} - {literal} {/literal}({$rowMetrics.actions_evolution}%) - {/if} - - {if $isGoalPluginEnabled} - - {*goal metrics*} - {if $rowMetrics.nb_conversions != 0} - - ,{literal} {/literal} - {'Goals_ColumnRevenue'|translate}:{literal} {/literal}{$rowMetrics.revenue} - {if $rowMetrics.revenue_evolution != 0} - {literal} {/literal}({$rowMetrics.revenue_evolution}%) - {/if} - - ,{literal} {/literal} - {$rowMetrics.nb_conversions} {'Goals_GoalConversions'|translate} - {if $rowMetrics.nb_conversions_evolution != 0} - {literal} {/literal}({$rowMetrics.nb_conversions_evolution}%) - {/if} - {/if} - - {*eCommerce metrics*} - {if $siteHasECommerce[$rowMetadata.idsite]} - - ,{literal} {/literal} - {'General_ProductRevenue'|translate}:{literal} {/literal}{$rowMetrics.ecommerce_revenue} - {if $rowMetrics.ecommerce_revenue_evolution != 0} - {literal} {/literal}({$rowMetrics.ecommerce_revenue_evolution}%) - {/if} - - ,{literal} {/literal} - {$rowMetrics.orders} {'General_EcommerceOrders'|translate} - {if $rowMetrics.orders_evolution != 0} - {literal} {/literal}({$rowMetrics.orders_evolution}%) - {/if} - {/if} - {/if} - - {/if} - - {if !$smarty.foreach.reportRows.last}.{literal} {/literal}{/if} - {/foreach} + {$prettyDate}.{literal} {/literal} + + {if empty($reportRows)} + {'CoreHome_ThereIsNoDataForThisReport'|translate} + {/if} + + {foreach name=reportRows from=$reportRows item=row key=rowId} + + {assign var=rowMetrics value=$row->getColumns()} + {assign var=rowMetadata value=$reportRowsMetadata[$rowId]->getColumns()} + + {if $displaySiteName} + {$rowMetrics.label}:{literal} {/literal} + {/if} + + {*visits*} + {$rowMetrics.nb_visits} {'General_ColumnNbVisits'|translate} + {if $rowMetrics.visits_evolution != 0} + {literal} {/literal}({$rowMetrics.visits_evolution}%) + {/if} + + {if $rowMetrics.nb_visits != 0} + + {*actions*} + ,{literal} {/literal} + {$rowMetrics.nb_actions} {'General_ColumnNbActions'|translate} + {if $rowMetrics.actions_evolution != 0} + {literal} {/literal}({$rowMetrics.actions_evolution}%) + {/if} + + {if $isGoalPluginEnabled} + + {*goal metrics*} + {if $rowMetrics.nb_conversions != 0} + + ,{literal} {/literal} + {'Goals_ColumnRevenue'|translate}:{literal} {/literal}{$rowMetrics.revenue} + {if $rowMetrics.revenue_evolution != 0} + {literal} {/literal}({$rowMetrics.revenue_evolution}%) + {/if} + + ,{literal} {/literal} + {$rowMetrics.nb_conversions} {'Goals_GoalConversions'|translate} + {if $rowMetrics.nb_conversions_evolution != 0} + {literal} {/literal}({$rowMetrics.nb_conversions_evolution}%) + {/if} + {/if} + + {*eCommerce metrics*} + {if $siteHasECommerce[$rowMetadata.idsite]} + + ,{literal} {/literal} + {'General_ProductRevenue'|translate}:{literal} {/literal}{$rowMetrics.ecommerce_revenue} + {if $rowMetrics.ecommerce_revenue_evolution != 0} + {literal} {/literal}({$rowMetrics.ecommerce_revenue_evolution}%) + {/if} + + ,{literal} {/literal} + {$rowMetrics.orders} {'General_EcommerceOrders'|translate} + {if $rowMetrics.orders_evolution != 0} + {literal} {/literal}({$rowMetrics.orders_evolution}%) + {/if} + {/if} + {/if} + + {/if} + + {if !$smarty.foreach.reportRows.last}.{literal} {/literal}{/if} + {/foreach} {/strip} diff --git a/plugins/MobileMessaging/templates/Settings.tpl b/plugins/MobileMessaging/templates/Settings.tpl index 77809a0186..547e637eb8 100644 --- a/plugins/MobileMessaging/templates/Settings.tpl +++ b/plugins/MobileMessaging/templates/Settings.tpl @@ -2,194 +2,201 @@ {loadJavascriptTranslations plugins='MobileMessaging'} {literal} -<style>#accountForm ul { - list-style: circle; - margin-left: 17px; - line-height: 1.5em; -} -.providerDescription { - border: 2px dashed #C5BDAD; - border-radius: 16px 16px 16px 16px; - margin-left: 24px; - padding: 11px; - width: 600px; -} -</style> + <style>#accountForm ul { + list-style: circle; + margin-left: 17px; + line-height: 1.5em; + } + + .providerDescription { + border: 2px dashed #C5BDAD; + border-radius: 16px 16px 16px 16px; + margin-left: 24px; + padding: 11px; + width: 600px; + } + </style> {/literal} {if $accountManagedByCurrentUser} -<h2>{'MobileMessaging_Settings_SMSAPIAccount'|translate}</h2> - {if $credentialSupplied} - {'MobileMessaging_Settings_CredentialProvided'|translate:$provider} - {$creditLeft} - <br/> - {'MobileMessaging_Settings_UpdateOrDeleteAccount'|translate:"<a id='displayAccountForm'>":"</a>":"<a id='deleteAccount'>":"</a>"} - {else} - {'MobileMessaging_Settings_PleaseSignUp'|translate} - {/if} - - <div id='accountForm' {if $credentialSupplied}style='display: none;'{/if}> - <br/> - {'MobileMessaging_Settings_SMSProvider'|translate} - <select id='smsProviders'> - {foreach from=$smsProviders key=smsProvider item=description} - <option value='{$smsProvider}'> - {$smsProvider} - </option> - {/foreach} - </select> - - {'MobileMessaging_Settings_APIKey'|translate} - <input size='25' id='apiKey'/> - - <input type='submit' value='{'General_Save'|translate}' id='apiAccountSubmit' class='submit' /> - - {foreach from=$smsProviders key=smsProvider item=description} - <div class='providerDescription' id='{$smsProvider}'> - {$description} - </div> - {/foreach} - - </div> + <h2>{'MobileMessaging_Settings_SMSAPIAccount'|translate}</h2> + {if $credentialSupplied} + {'MobileMessaging_Settings_CredentialProvided'|translate:$provider} + {$creditLeft} + <br/> + {'MobileMessaging_Settings_UpdateOrDeleteAccount'|translate:"<a id='displayAccountForm'>":"</a>":"<a id='deleteAccount'>":"</a>"} + {else} + {'MobileMessaging_Settings_PleaseSignUp'|translate} + {/if} + <div id='accountForm' {if $credentialSupplied}style='display: none;'{/if}> + <br/> + {'MobileMessaging_Settings_SMSProvider'|translate} + <select id='smsProviders'> + {foreach from=$smsProviders key=smsProvider item=description} + <option value='{$smsProvider}'> + {$smsProvider} + </option> + {/foreach} + </select> + + {'MobileMessaging_Settings_APIKey'|translate} + <input size='25' id='apiKey'/> + + <input type='submit' value='{'General_Save'|translate}' id='apiAccountSubmit' class='submit'/> + + {foreach from=$smsProviders key=smsProvider item=description} + <div class='providerDescription' id='{$smsProvider}'> + {$description} + </div> + {/foreach} + + </div> {/if} {ajaxErrorDiv id=ajaxErrorMobileMessagingSettings} <h2>{'MobileMessaging_Settings_PhoneNumbers'|translate}</h2> {if !$credentialSupplied} - {if $accountManagedByCurrentUser} - {'MobileMessaging_Settings_CredentialNotProvided'|translate} - {else} - {'MobileMessaging_Settings_CredentialNotProvidedByAdmin'|translate} - {/if} + {if $accountManagedByCurrentUser} + {'MobileMessaging_Settings_CredentialNotProvided'|translate} + {else} + {'MobileMessaging_Settings_CredentialNotProvidedByAdmin'|translate} + {/if} {else} - {'MobileMessaging_Settings_PhoneNumbers_Help'|translate}<br/><br/> - - <table style="width:900px;" class="adminTable"> - <tbody><tr> - <td style="width:480px"> - <strong>{'MobileMessaging_Settings_PhoneNumbers_Add'|translate}</strong><br/><br/> + {'MobileMessaging_Settings_PhoneNumbers_Help'|translate} + <br/> + <br/> + <table style="width:900px;" class="adminTable"> + <tbody> + <tr> + <td style="width:480px"> + <strong>{'MobileMessaging_Settings_PhoneNumbers_Add'|translate}</strong><br/><br/> <span id='suspiciousPhoneNumber' style='display:none;'> {'MobileMessaging_Settings_SuspiciousPhoneNumber'|translate:'54184032'}<br/><br/> </span> - - + <input id='countryCallingCode' size='4' maxlength='4'/> - <input id='newPhoneNumber'/> - <input - type='submit' - value='{'MobileMessaging_Settings_AddPhoneNumber'|translate}' - id='addPhoneNumberSubmit' - /> - - <br/> + + + <input id='countryCallingCode' size='4' maxlength='4'/> + <input id='newPhoneNumber'/> + <input + type='submit' + value='{'MobileMessaging_Settings_AddPhoneNumber'|translate}' + id='addPhoneNumberSubmit' + /> + + <br/> <span style=' font-size: 11px;'><span class="form-description">{'MobileMessaging_Settings_CountryCode'|translate}</span> <span class="form-description" style="margin-left:50px">{'MobileMessaging_Settings_PhoneNumber'|translate}</span></span> - <br/><br/> - - {'MobileMessaging_Settings_PhoneNumbers_CountryCode_Help'|translate} - - <select id='countries'> - <option value=''> </option> {* this is a trick to avoid selecting the first country when no default could be found *} - {foreach from=$countries key=countryCode item=country} - <option - value='{$country.countryCallingCode}' - {if $defaultCountry==$countryCode} selected='selected' {/if} - > - {$country.countryName|truncate:15:'...'} - </option> - {/foreach} - </select> - - </td> - <td style="width:220px"> - {$strHelpAddPhone|inlineHelp} - - </td></tr> - <tr><td colspan="2"> - - {if $phoneNumbers|@count gt 0} - <br/> - <br/> - <strong>{'MobileMessaging_Settings_ManagePhoneNumbers'|translate}</strong><br/><br/> - {/if} - - {ajaxErrorDiv id=invalidVerificationCodeAjaxError} - - <div id='phoneNumberActivated' class="ajaxSuccess" style="display:none;"> - {'MobileMessaging_Settings_PhoneActivated'|translate} - </div> - - <div id='invalidActivationCode' style="display:none;"> - {'MobileMessaging_Settings_InvalidActivationCode'|translate} - </div> - - <ul> - {foreach from=$phoneNumbers key=phoneNumber item=validated} - <li> - <span class='phoneNumber'>{$phoneNumber}</span> - {if !$validated} - <input class='verificationCode'/> - <input - type='submit' - value='{'MobileMessaging_Settings_ValidatePhoneNumber'|translate}' - class='validatePhoneNumberSubmit' - /> - {/if} - <input - type='submit' - value='{'MobileMessaging_Settings_RemovePhoneNumber'|translate}' - class='removePhoneNumberSubmit' - /> - {if !$validated} - <br/> - <span class='form-description'>{'MobileMessaging_Settings_VerificationCodeJustSent'|translate}</span> - {/if} - <br/> - <br/> - </li> - {/foreach} - </ul> - - </td> - </tr> - </tbody></table> + <br/><br/> + + {'MobileMessaging_Settings_PhoneNumbers_CountryCode_Help'|translate} + + <select id='countries'> + <option value=''> </option> {* this is a trick to avoid selecting the first country when no default could be found *} + {foreach from=$countries key=countryCode item=country} + <option + value='{$country.countryCallingCode}' + {if $defaultCountry==$countryCode} selected='selected' {/if} + > + {$country.countryName|truncate:15:'...'} + </option> + {/foreach} + </select> + + </td> + <td style="width:220px"> + {$strHelpAddPhone|inlineHelp} + + </td> + </tr> + <tr> + <td colspan="2"> + + {if $phoneNumbers|@count gt 0} + <br/> + <br/> + <strong>{'MobileMessaging_Settings_ManagePhoneNumbers'|translate}</strong> + <br/> + <br/> + {/if} + + {ajaxErrorDiv id=invalidVerificationCodeAjaxError} + + <div id='phoneNumberActivated' class="ajaxSuccess" style="display:none;"> + {'MobileMessaging_Settings_PhoneActivated'|translate} + </div> + + <div id='invalidActivationCode' style="display:none;"> + {'MobileMessaging_Settings_InvalidActivationCode'|translate} + </div> + + <ul> + {foreach from=$phoneNumbers key=phoneNumber item=validated} + <li> + <span class='phoneNumber'>{$phoneNumber}</span> + {if !$validated} + <input class='verificationCode'/> + <input + type='submit' + value='{'MobileMessaging_Settings_ValidatePhoneNumber'|translate}' + class='validatePhoneNumberSubmit' + /> + {/if} + <input + type='submit' + value='{'MobileMessaging_Settings_RemovePhoneNumber'|translate}' + class='removePhoneNumberSubmit' + /> + {if !$validated} + <br/> + <span class='form-description'>{'MobileMessaging_Settings_VerificationCodeJustSent'|translate}</span> + {/if} + <br/> + <br/> + </li> + {/foreach} + </ul> + + </td> + </tr> + </tbody> + </table> {/if} {if $isSuperUser} - <h2>{'MobileMessaging_Settings_SuperAdmin'|translate}</h2> - - <table class='adminTable' style='width:650px;'> - <tr> - <td style='width:400px'>{'MobileMessaging_Settings_LetUsersManageAPICredential'|translate}</td> - <td style='width:250px'> - <fieldset> - <label> - <input - type='radio' - value='false' - name='delegatedManagement' {if !$delegatedManagement} checked='checked'{/if} /> - {'General_No'|translate} - <br/> - <span class='form-description'>({'General_Default'|translate}) {'MobileMessaging_Settings_LetUsersManageAPICredential_No_Help'|translate}</span> - </label> - <br/> - <br/> - <label> - <input - type='radio' - value='true' - name='delegatedManagement' {if $delegatedManagement} checked='checked'{/if} /> - {'General_Yes'|translate} - <br/> - <span class='form-description'>{'MobileMessaging_Settings_LetUsersManageAPICredential_Yes_Help'|translate}</span> - </label> - - </fieldset> - </tr> - </table> + <h2>{'MobileMessaging_Settings_SuperAdmin'|translate}</h2> + <table class='adminTable' style='width:650px;'> + <tr> + <td style='width:400px'>{'MobileMessaging_Settings_LetUsersManageAPICredential'|translate}</td> + <td style='width:250px'> + <fieldset> + <label> + <input + type='radio' + value='false' + name='delegatedManagement' {if !$delegatedManagement} checked='checked'{/if} /> + {'General_No'|translate} + <br/> + <span class='form-description'>({'General_Default'|translate} + ) {'MobileMessaging_Settings_LetUsersManageAPICredential_No_Help'|translate}</span> + </label> + <br/> + <br/> + <label> + <input + type='radio' + value='true' + name='delegatedManagement' {if $delegatedManagement} checked='checked'{/if} /> + {'General_Yes'|translate} + <br/> + <span class='form-description'>{'MobileMessaging_Settings_LetUsersManageAPICredential_Yes_Help'|translate}</span> + </label> + + </fieldset> + </tr> + </table> {/if} {ajaxLoadingDiv id=ajaxLoadingMobileMessagingSettings} @@ -197,8 +204,8 @@ {include file='CoreAdminHome/templates/footer.tpl'} <div class='ui-confirm' id='confirmDeleteAccount'> - <h2>{'MobileMessaging_Settings_DeleteAccountConfirm'|translate}</h2> - <input role='yes' type='button' value='{'General_Yes'|translate}' /> - <input role='no' type='button' value='{'General_No'|translate}' /> + <h2>{'MobileMessaging_Settings_DeleteAccountConfirm'|translate}</h2> + <input role='yes' type='button' value='{'General_Yes'|translate}'/> + <input role='no' type='button' value='{'General_No'|translate}'/> </div> |