Skip to content
Extraits de code Groupes Projets
Valider 03672557 rédigé par sgiehl's avatar sgiehl
Parcourir les fichiers

adds SMS Provider for development, that shows all sent SMS as Piwik notifications

parent d64d68b5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -94,7 +94,7 @@ class Controller extends ControllerAdmin ...@@ -94,7 +94,7 @@ class Controller extends ControllerAdmin
$view->creditLeft = $mobileMessagingAPI->getCreditLeft(); $view->creditLeft = $mobileMessagingAPI->getCreditLeft();
} }
$view->smsProviders = SMSProvider::$availableSMSProviders; $view->smsProviders = SMSProvider::getAvailableSMSProviders();
// construct the list of countries from the lang files // construct the list of countries from the lang files
$countries = array(); $countries = array();
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
namespace Piwik\Plugins\MobileMessaging; namespace Piwik\Plugins\MobileMessaging;
use Exception; use Exception;
use Piwik\Development;
use Piwik\Piwik; use Piwik\Piwik;
use Piwik\BaseFactory; use Piwik\BaseFactory;
...@@ -23,7 +24,7 @@ abstract class SMSProvider extends 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_UNIQUE_SMS = 70;
const MAX_UCS2_CHARS_IN_ONE_CONCATENATED_SMS = 67; 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/> '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> <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> 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,10 +47,26 @@ abstract class SMSProvider extends BaseFactory ...@@ -46,10 +47,26 @@ abstract class SMSProvider extends BaseFactory
protected static function getInvalidClassIdExceptionMessage($id) protected static function getInvalidClassIdExceptionMessage($id)
{ {
return Piwik::translate('MobileMessaging_Exception_UnknownProvider', 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 * Return the SMSProvider associated to the provider name $providerName
* *
...@@ -65,7 +82,7 @@ abstract class SMSProvider extends BaseFactory ...@@ -65,7 +82,7 @@ abstract class SMSProvider extends BaseFactory
throw new Exception( throw new Exception(
Piwik::translate( Piwik::translate(
'MobileMessaging_Exception_UnknownProvider', 'MobileMessaging_Exception_UnknownProvider',
array($providerName, implode(', ', array_keys(self::$availableSMSProviders))) array($providerName, implode(', ', array_keys(self::getAvailableSMSProviders())))
) )
); );
} }
......
<?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';
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter