diff options
author | Matthieu Aubry <matt@piwik.org> | 2015-09-14 07:06:58 +0300 |
---|---|---|
committer | Matthieu Aubry <matt@piwik.org> | 2015-09-14 07:06:58 +0300 |
commit | 9065d941faa2b0302322d3231408b15cd5cb29b0 (patch) | |
tree | 96832759a25bd3a5dfb071d656a64c87bcf4f4f8 /plugins/MobileMessaging | |
parent | de12df8ac93be2f374ad2e198ff3388f655b9d40 (diff) | |
parent | 036725577e3a157461f04303f6d9b10b275ecad7 (diff) |
Merge pull request #8773 from piwik/development_smsprovider
Mobile Messaging: adds SMS provider for development
Diffstat (limited to 'plugins/MobileMessaging')
-rw-r--r-- | plugins/MobileMessaging/Controller.php | 2 | ||||
-rw-r--r-- | plugins/MobileMessaging/SMSProvider.php | 23 | ||||
-rw-r--r-- | plugins/MobileMessaging/SMSProvider/Development.php | 40 |
3 files changed, 61 insertions, 4 deletions
diff --git a/plugins/MobileMessaging/Controller.php b/plugins/MobileMessaging/Controller.php index 5a906d3ba1..2bb6f8d5f5 100644 --- a/plugins/MobileMessaging/Controller.php +++ b/plugins/MobileMessaging/Controller.php @@ -94,7 +94,7 @@ class Controller extends ControllerAdmin $view->creditLeft = $mobileMessagingAPI->getCreditLeft(); } - $view->smsProviders = SMSProvider::$availableSMSProviders; + $view->smsProviders = SMSProvider::getAvailableSMSProviders(); // construct the list of countries from the lang files $countries = array(); diff --git a/plugins/MobileMessaging/SMSProvider.php b/plugins/MobileMessaging/SMSProvider.php index c9212971e2..5003f0030a 100644 --- a/plugins/MobileMessaging/SMSProvider.php +++ b/plugins/MobileMessaging/SMSProvider.php @@ -9,6 +9,7 @@ namespace Piwik\Plugins\MobileMessaging; use Exception; +use Piwik\Development; use Piwik\Piwik; use Piwik\BaseFactory; @@ -23,7 +24,7 @@ abstract class SMSProvider extends BaseFactory const MAX_UCS2_CHARS_IN_ONE_UNIQUE_SMS = 70; const MAX_UCS2_CHARS_IN_ONE_CONCATENATED_SMS = 67; - public static $availableSMSProviders = array( + protected static $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!) @@ -46,11 +47,27 @@ abstract class SMSProvider extends BaseFactory protected static function getInvalidClassIdExceptionMessage($id) { return Piwik::translate('MobileMessaging_Exception_UnknownProvider', - array($id, implode(', ', array_keys(self::$availableSMSProviders))) + array($id, implode(', ', array_keys(self::getAvailableSMSProviders()))) ); } /** + * Returns all available SMS Providers + * + * @return array + */ + public static function getAvailableSMSProviders() + { + $smsProviders = self::$availableSMSProviders; + + if (Development::isEnabled()) { + $smsProviders['Development'] = 'Development SMS Provider<br />All sent SMS will be displayed as Notification'; + } + + return $smsProviders; + } + + /** * Return the SMSProvider associated to the provider name $providerName * * @throws Exception If the provider is unknown @@ -65,7 +82,7 @@ abstract class SMSProvider extends BaseFactory throw new Exception( Piwik::translate( 'MobileMessaging_Exception_UnknownProvider', - array($providerName, implode(', ', array_keys(self::$availableSMSProviders))) + array($providerName, implode(', ', array_keys(self::getAvailableSMSProviders()))) ) ); } diff --git a/plugins/MobileMessaging/SMSProvider/Development.php b/plugins/MobileMessaging/SMSProvider/Development.php new file mode 100644 index 0000000000..ef6cbe951d --- /dev/null +++ b/plugins/MobileMessaging/SMSProvider/Development.php @@ -0,0 +1,40 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\MobileMessaging\SMSProvider; + +use Piwik\Notification; +use Piwik\Plugins\MobileMessaging\SMSProvider; + +/** + * Used for development only + * + */ +class Development extends SMSProvider +{ + + public function verifyCredential($apiKey) + { + return true; + } + + public function sendSMS($apiKey, $smsText, $phoneNumber, $from) + { + $message = sprintf('An SMS was sent:<br />From: %s<br />To: %s<br />Message: %s', $from, $phoneNumber, $smsText); + + $notification = new Notification($message); + $notification->raw = true; + $notification->context = Notification::CONTEXT_INFO; + Notification\Manager::notify('StubbedSMSProvider'.preg_replace('/[^a-z0-9]/', '', $phoneNumber), $notification); + } + + public function getCreditLeft($apiKey) + { + return 'Balance: 42'; + } +} |