Create Clockworksms plugin; Implement in several mail sending calls - refs #7225
parent
535f4e7859
commit
bea2ed0253
@ -0,0 +1,22 @@ |
||||
# Changelog |
||||
|
||||
## 1.0 (July 19th, 2012) |
||||
|
||||
* Initial release. [JI/MS] |
||||
|
||||
### 1.1 (August 21st, 2012) |
||||
|
||||
* Added /get_key functionality to translate a legacy Mediaburst username and password into a new Clockwork API key. [JI] |
||||
* Deprecated `checkCredit()` and replaced with `checkBalance()` [JI] |
||||
|
||||
### 1.2 (September 7th, 2012) |
||||
|
||||
* Added various new Wordpress classes, including the Clockwork_Plugin class for writing plugins based on Clockwork. [JI] |
||||
|
||||
### 1.3 (September 18th, 2012) |
||||
|
||||
* Added `is_valid_msisdn()` method. [JI] |
||||
|
||||
#### 1.3.1 (November 13th, 2012) |
||||
|
||||
* Updated `is_valid_msisdn()` method to handle 9-digit phone numbers, e.g. Norway. [JI] |
@ -0,0 +1,11 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/* bbb parameters that will be registered in the course settings */ |
||||
|
||||
require_once __DIR__ . '/../../main/inc/global.inc.php'; |
||||
require_once api_get_path(LIBRARY_PATH).'plugin.class.php'; |
||||
|
||||
require_once 'lib/clockworksms.lib.php'; |
||||
require_once 'lib/clockworksms_api.php'; |
||||
require_once 'lib/clockworksms_plugin.class.php'; |
@ -0,0 +1,3 @@ |
||||
<?php |
||||
|
||||
?> |
@ -0,0 +1 @@ |
||||
{{ content }} |
@ -0,0 +1,12 @@ |
||||
<?php |
||||
/** |
||||
* This script is included by main/admin/settings.lib.php and generally |
||||
* includes things to execute in the main database (settings_current table) |
||||
* @package chamilo.plugin.bigbluebutton |
||||
*/ |
||||
/** |
||||
* Initialization |
||||
*/ |
||||
|
||||
require_once dirname(__FILE__).'/config.php'; |
||||
ClockworksmsPlugin::create()->install(); |
@ -0,0 +1,102 @@ |
||||
<?php |
||||
|
||||
$strings['plugin_title'] = "SMS Sending"; |
||||
$strings['plugin_comment'] = "When enabled and an email sent successfully, a text message is sent to the user."; |
||||
|
||||
$strings['api_key'] = "Clockwork SMS key"; |
||||
$strings['api_key_help'] = "This is the Clockwork SMS server security key. <a target='_blank' href='http://www.clockworksms.com/platforms/chamilo/'>Click here</a> to get it."; |
||||
|
||||
$strings['tool_enable'] = "Enable SMS sending"; |
||||
$strings['tool_enable_help'] = "Choose if you want to enable SMS sending tool. |
||||
Once enabled, they will be sent along with an email the selected SMS message types to the users who had filled their mobile phone number field in their profile<br />"; |
||||
|
||||
$strings['type'] = "Send SMS when"; |
||||
$strings['mobile_phone_number'] = "Mobile Phone (include country dialing code only)"; |
||||
|
||||
$strings['messageWelcomeXLoginXPasswordX'] = "A user is added to the platform"; |
||||
$strings['messageXNewFileSharedCourseXByX'] = "A file is added to dropbox"; |
||||
$strings['messageXAccountApprovedConnectX'] = "An account is approved"; |
||||
$strings['messageXNewCourseXBeenCreatedX'] = "A new course is created"; |
||||
$strings['messageXNewUserXSubscribedCourseX'] = "A user is subscribed to a course"; |
||||
$strings['messageXNewCourseSuggestedTeacherX'] = "A new course is suggested"; |
||||
$strings['messageXCourseOpeningRequestCodeXRegistered'] = "A new course opening request is registered"; |
||||
$strings['messageXCourseOpeningRequestCourseCodeXApproved'] = "A new course opening request is approved"; |
||||
$strings['messageXRequestOpenCourseCodeXReject'] = "A new course opening request is rejected"; |
||||
$strings['messageXCourseOpeningRequestCourseCodeX'] = "Additional information is required for a new course opening request"; |
||||
$strings['messageXBeenSubscribedCourseX'] = "A user is added to the course but not registered to it yet"; |
||||
$strings['messageXAssignmentBeenCreatedCourseX'] = "Homework is created"; |
||||
$strings['messageXAccountCreatedUpdatedLoginXPasswordX'] = "A user account is created or updated"; |
||||
$strings['messageXPasswordUpdatedLoginXPasswordX'] = "A user password is updated"; |
||||
$strings['messageXRequestedPasswordChange'] = "A user requests a password change"; |
||||
$strings['messageXReceivedNewPersonalMessages'] = "New personal messages are received in user's inbox or forum"; |
||||
$strings['messageXNewUserXPendingApproval'] = "A new user registration is pending for approval"; |
||||
$strings['messageXXPostedForumXCourseX'] = "A user posts in forum"; |
||||
$strings['messageXXXCheckEmailConnectMoreInfo'] = "An announcement is sent"; |
||||
$strings['messageXXStudentXAnsweredTestX'] = "A student solves an exercise"; |
||||
$strings['messageXXStudentXAnsweredTestXOpenQuestion'] = "A student solves an open question"; |
||||
$strings['messageXXStudentXAnsweredTestXVoiceQuestion'] = "A student solves a voice question"; |
||||
$strings['messageXXAnswerOpenQuestionTestXReviewed'] = "An open question answer is reviewed"; |
||||
$strings['messageXXNewThreadXStartedForumX'] = "A new thread is started in forum"; |
||||
$strings['messageXXNewAnswerPostedXForumX'] = "A new answer is posted in forum"; |
||||
$strings['messageXXNewSystemAnnouncementAdded'] = "A new system announcement is added and the user does not want to send a test email"; |
||||
$strings['messageXTestXNewSystemAnnouncementAdded'] = "A new system announcement is added and the user wants to send a test email"; |
||||
$strings['messageXXSystemAnnouncementUpdate'] = "A new system announcement is updated and the user does not want to send a test email"; |
||||
$strings['messageXTestXSystemAnnouncementUpdate'] = "A new system announcement is updated and the user wants to send a test email"; |
||||
$strings['messageXUserXUploadedAssignmentXCourseXStudentSubmitsPaper'] = "An assignment is uploaded and there is no current session (this will be sent only to coaches)"; |
||||
$strings['messageXUserXUploadedAssignmentXCheckXStudentSubmitsPaper'] = "An assignment is uploaded (this will be sent only to teachers)"; |
||||
$strings['messageXUserXUploadedAssignmentXCourseX'] = "... and there is no current session (this will be sent only to coaches)"; |
||||
$strings['messageXUserXUploadedAssignmentXCheckX'] = "... (this will be sent only to teachers)"; |
||||
$strings['messageXSubscribedSessionX'] = "A session is created or updated and new users are subscribed"; |
||||
$strings['messageXSubscribedSessionXCSV'] = "New users are subscribed to a session importing a CSV file"; |
||||
$strings['messageXUserXSuggestedBeFriends'] = "A friendship invitation is received"; |
||||
$strings['messageXUserXAnsweredInboxMessage'] = "A message reply is received in inbox"; |
||||
$strings['messageXBeenInvitedJoinGroupX'] = "A group join invitation is received"; |
||||
$strings['messageXMessagesSentEditedGroupXEdited'] = "A group topic message is updated"; |
||||
$strings['messageXMessagesSentEditedGroupXAdded'] = "A group topic message is added"; |
||||
$strings['messageXBeenInvitedCompleteSurveyXCourseX'] = "A new survey is created"; |
||||
$strings['messageXReminderAssignmentXCourseXDue'] = "A reminder is sent to students who have not uploaded their assignment yet"; |
||||
$strings['messageXUserDetailsModified'] = "User details have been updated"; |
||||
|
||||
$strings['WelcomeXLoginXPasswordX'] = "Welcome to %s. Here are your user account details: login: %s, password: %s"; |
||||
$strings['XNewFileSharedCourseXByX'] = "%s: A new file has been shared with you in course %s by %s"; |
||||
$strings['XAccountApprovedConnectX'] = "%s: Your account has been approved by an administrator. You can now connect to %s"; |
||||
$strings['XNewCourseXBeenCreatedX'] = "%s: A new course (%s) has been created by %s"; |
||||
$strings['XNewUserXSubscribedCourseX'] = "%s: A new user (%s) has just subscribed to your course (%s)"; |
||||
$strings['XNewCourseSuggestedTeacherX'] = "%s: A new course has been suggested by teacher (%s). Please connect to the admin page to review it"; |
||||
$strings['XCourseOpeningRequestCodeXRegistered'] = "%s: Your course opening request (code %s) has been registered. You will be informed when it is approved"; |
||||
$strings['XCourseOpeningRequestCourseCodeXApproved'] = "%s: Your course opening request for course code %s has been approved. Connect to your portal to use it"; |
||||
$strings['XRequestOpenCourseCodeXReject'] = "%s: We are sorry to inform you that your request to open course code %s has been rejected"; |
||||
$strings['XCourseOpeningRequestCourseCodeX'] = "%s: Your course opening request for course code %s requires more information. Check e-mail for more info"; |
||||
$strings['XBeenSubscribedCourseX'] = "%s: You have been subscribed to course %s"; |
||||
$strings['XAssignmentBeenCreatedCourseX'] = "%s: A new assignment has been created in course %s. Please connect for more info"; |
||||
$strings['XAccountCreatedUpdatedLoginXPasswordX'] = "%s: Your account has been created or updated. You can now login as %s, password: %s"; |
||||
$strings['XPasswordUpdatedLoginXPasswordX'] = "%s: Your password has been updated. You can now login as %s, password: %s"; |
||||
$strings['XRequestedPasswordChange'] = "%s: You have requested a password change. Please check your e-mail for more information"; |
||||
$strings['XReceivedNewPersonalMessages'] = "%s: You have received new personal messages in your inbox or in the forum. Please check your e-mail for more info"; |
||||
$strings['XNewUserXPendingApproval'] = "%s: A new user (%s) registration is pending your approval. Please connect to the admin panel to review"; |
||||
$strings['XXPostedForumXCourseX'] = "%s: %s just posted on forum %s in course %s"; |
||||
$strings['XXXCheckEmailConnectMoreInfo'] = "%s: %s: %s. Check your e-mail or connect for more info"; |
||||
$strings['XXStudentXAnsweredTestX'] = "%s: %s: Student %s has just answered test %s"; |
||||
$strings['XXStudentXAnsweredTestXOpenQuestion'] = "%s: %s: Student %s answered test %s's open question. Please connect to review"; |
||||
$strings['XXStudentXAnsweredTestXVoiceQuestion'] = "%s: %s: Student %s answered test %s's voice question. Please connect to review"; |
||||
$strings['XXAnswerOpenQuestionTestXReviewed'] = "%s: %s: Your answer to an open question in test %s has been reviewed"; |
||||
$strings['XXNewThreadXStartedForumX'] = "%s: %s: A new thread (%s) has been started in forum %s"; |
||||
$strings['XXNewAnswerPostedXForumX'] = "%s: %s: A new answer has been posted to (%s) in forum %s"; |
||||
$strings['XXNewSystemAnnouncementAdded'] = "%s: %s"; |
||||
$strings['XTestXNewSystemAnnouncementAdded'] = "%s (test): %s"; |
||||
$strings['XXSystemAnnouncementUpdate'] = "%s: %s (update)"; |
||||
$strings['XTestXSystemAnnouncementUpdate'] = "%s (test): %s"; |
||||
$strings['XUserXUploadedAssignmentXCourseXStudentSubmitsPaper'] = "%s: User %s uploaded assignment %s in course %s"; |
||||
$strings['XUserXUploadedAssignmentXCheckXStudentSubmitsPaper'] = "%s: User %s uploaded assignment %s. Check %s"; |
||||
$strings['XUserXUploadedAssignmentXCourseX'] = "%s: User %s uploaded assignment %s in course %s"; |
||||
$strings['XUserXUploadedAssignmentXCheckX'] = "%s: User %s uploaded assignment %s. Check %s"; |
||||
$strings['XSubscribedSessionX'] = "%s: You have been subscribed to session %s"; |
||||
$strings['XSubscribedSessionXCSV'] = "%s: You have been subscribed to session %s"; |
||||
$strings['XUserXSuggestedBeFriends'] = "%s: User %s suggested you should be friends. Check your inbox or e-mail for details"; |
||||
$strings['XUserXAnsweredInboxMessage'] = "%s: User %s just answered your Inbox message"; |
||||
$strings['XBeenInvitedJoinGroupX'] = "%s: you have been invited to join group %s. Check your Inbox for details"; |
||||
$strings['XMessagesSentEditedGroupXEdited'] = "%s: Messages sent or edited in group %s. Check your Inbox for details"; |
||||
$strings['XMessagesSentEditedGroupXAdded'] = "%s: Messages sent or edited in group %s. Check your Inbox for details"; |
||||
$strings['XBeenInvitedCompleteSurveyXCourseX'] = "%s: You have been invited to complete survey %s in course %s"; |
||||
$strings['XReminderAssignmentXCourseXDue'] = "%s: This is a simple reminder that your assignment (%s) in course %s is still due"; |
||||
$strings['XUserDetailsModified'] = "%s: Your user details have been modified. Please check your e-mail for more information"; |
@ -0,0 +1,49 @@ |
||||
<?php /* License: see /license.txt */ |
||||
//Needed in order to show the plugin title |
||||
/*$strings['plugin_title'] = "Vidéoconférence"; |
||||
$strings['plugin_comment'] = "Ajoutez un espace de vidéoconférences aux cours de Chamilo avec BigBlueButton (BBB)"; |
||||
|
||||
$strings['Videoconference'] = "Vidéoconférence"; |
||||
$strings['MeetingOpened'] = "Session ouverte"; |
||||
$strings['MeetingClosed'] = "Session fermée"; |
||||
$strings['MeetingClosedComment'] = "Si vous avez demandé l'enregistrement des sessions de conférence, cet enregistrement apparaîtra dans la liste ci-dessous dans quelques instants."; |
||||
$strings['CloseMeeting'] = "Fermer la session"; |
||||
|
||||
$strings['VideoConferenceXCourseX'] = "Vidéoconférence #%s, cours %s"; |
||||
$strings['VideoConferenceAddedToTheCalendar'] = "Vidéoconférence ajoutée au calendrier"; |
||||
$strings['VideoConferenceAddedToTheLinkTool'] = "Vidéoconférence ajoutée comme lien. Vous pouvez éditer et publier le lien sur la page principale du cours depuis l'outil liens."; |
||||
|
||||
$strings['GoToTheVideoConference'] = "Entrer dans la salle de conférence"; |
||||
|
||||
$strings['Records'] = "Enregistrement"; |
||||
$strings['Meeting'] = "Salle de conférence"; |
||||
|
||||
$strings['ViewRecord'] = "Voir l'enregistrement"; |
||||
$strings['CopyToLinkTool'] = "Ajouter comme lien du cours"; |
||||
|
||||
$strings['EnterConference'] = "Entrer dans la salle de conférence"; |
||||
$strings['RecordList'] = "Liste des enregistrements"; |
||||
$strings['ServerIsNotRunning'] = "Le serveur de vidéoconférence ne fonctionne pas"; |
||||
$strings['ServerIsNotConfigured'] = "Le serveur de vidéoconférence n'est pas configuré correctement"; |
||||
|
||||
$strings['XUsersOnLine'] = "%s utilisateurs dans la salle"; |
||||
|
||||
$strings['host'] = 'Hôte de BigBlueButton'; |
||||
$strings['host_help'] = "C'est le nom du serveur où le serveur de vidéoconférence a été habilité. Cela peut être localhost, une adresse IP (du genre 192.168.13.54) ou un nom de domaine (du genre ma.video.com)."; |
||||
|
||||
$strings['salt'] = 'Clef BigBlueButton'; |
||||
$strings['salt_help'] = "C'est la clef de sécurité de votre serveur BigBlueButton (appelée 'salt' en anglais) qui permet à votre serveur de vérifier l'identité de votre installation de Chamilo et ainsi l'autoriser à se connecter. Veuillez vous référer à la documentation de BigBlueButton pour la localiser, ou utilisez la commande 'bbb-conf --salt' si vous disposez d'un accès en ligne de commande au serveur de vidéoconférence."; |
||||
|
||||
$strings['tool_enable'] = 'Outil de vidéoconférence BigBlueButton activé'; |
||||
$strings['tool_enable_help'] = "Choisissez si vous souhaitez activer l'outil de vidéoconférence BigBlueButton. |
||||
Une fois activé, il apparaîtra comme un outil additionnel sur toutes les pages principales de cours, et les enseignants pourront démarrer une conférence à n'importe quel moment. Les étudiants ne pourront pas lancer de nouvelle session de conférence, seulement se joindre à une session existante. Si vous ne disposez pas d'un serveur de vidéoconférence BigBlueButton, veuillez <a target=\"_blank\" href=\"http://bigbluebutton.org/\">en installer un</a> avant de poursuivre, ou demander un devis à l'un des fournisseurs officiels de Chamilo. BigBlueButton est un outil de logiciel libre (et gratuit), mais son installation pourrait présenter une certaine complexité et demander des compétences qui ne sont peut-être pas à la portée de tous. Vous pouvez l'installer vous-même à partir de la documentation (disponible publiquement) de BigBlueButton, ou recherchez un soutien professionnel. Ce soutien pourrait générer certains coûts (au moins le temps de la personne qui vous assiste dans l'opération). Dans le plus pur esprit du logiciel libre, nous vous fournissons les outils pour simplifier votre travail dans la mesure de nos possibilités, et nous vous recommandons des professionnels (les fournisseurs officiels de Chamilo) pour vous venir en aide au cas où ceux-ci seraient insuffisants.<br />"; |
||||
|
||||
$strings['big_blue_button_welcome_message'] = 'Message de bienvenue de BigBlueButton'; |
||||
$strings['big_blue_button_record_and_store'] = 'Enregistrer les sessions de vidéoconférence'; |
||||
|
||||
$strings['plugin_tool_bbb'] = 'Vidéo'; |
||||
|
||||
$strings['ThereAreNotRecordingsForTheMeetings'] = 'Aucun enregistrement disponible'; |
||||
$strings['NoRecording'] = "Pas d'enregistrement"; |
||||
|
||||
$strings['ClickToContinue'] = 'Cliquez pour continuer';*/ |
@ -0,0 +1,102 @@ |
||||
<?php
|
||||
|
||||
$strings['plugin_title'] = "Envío de SMS"; |
||||
$strings['plugin_comment'] = "Ofrece la posibilidad de enviar SMS a celulares cuando se envían e-mails de notificación."; |
||||
|
||||
$strings['api_key'] = "Clave Clockwork SMS"; |
||||
$strings['api_key_help'] = "Ésta es la clave de seguridad de su servidor Clockwork SMS. Para obtenerla, <a target='_blank' href='http://www.clockworksms.com/platforms/chamilo/'>haga click aquí</a>"; |
||||
|
||||
$strings['tool_enable'] = "Activar envío de SMS"; |
||||
$strings['tool_enable_help'] = "Escoja si desea activar la herramienta de envío de mensajes a celulares Clockwork SMS. |
||||
Una vez activada, se enviarán, simultaneamente con los correos, los tipos mensajes SMS seleccionados a los usuarios que hayan especificado un número de celular en su perfil.<br />"; |
||||
|
||||
$strings['sms_types'] = "Enviar un SMS cuando"; |
||||
$strings['mobile_phone_number'] = "Celular (incluya sólo el código de llamada del país)"; |
||||
|
||||
$strings['messageWelcomeXLoginXPasswordX'] = "Se añada un usuario a la plataforma"; |
||||
$strings['messageXNewFileSharedCourseXByX'] = "Un archivo se añada a dropbox"; |
||||
$strings['messageXAccountApprovedConnectX'] = "Se apruebe una cuenta de usuario"; |
||||
$strings['messageXNewCourseXBeenCreatedX'] = "Se cree un curso nuevo"; |
||||
$strings['messageXNewUserXSubscribedCourseX'] = "Un usuario se suscriba a un curso"; |
||||
$strings['messageXNewCourseSuggestedTeacherX'] = "Un profesor sugiera un curso nuevo"; |
||||
$strings['messageXCourseOpeningRequestCodeXRegistered'] = "Se registre una solicitud de apertura de curso"; |
||||
$strings['messageXCourseOpeningRequestCourseCodeXApproved'] = "Se apruebe una solicitud de apertura de curso"; |
||||
$strings['messageXRequestOpenCourseCodeXReject'] = "Se rechace una solicitud de apertura de curso"; |
||||
$strings['messageXCourseOpeningRequestCourseCodeX'] = "Se requiera más información de una solicitud de apertura de curso"; |
||||
$strings['messageXBeenSubscribedCourseX'] = "Se le suscriba a un curso a un usuario que aún no está registrado"; |
||||
$strings['messageXAssignmentBeenCreatedCourseX'] = "Se cree una nueva tarea en un curso"; |
||||
$strings['messageXAccountCreatedUpdatedLoginXPasswordX'] = "Se cree o actualice una cuenta de usuario"; |
||||
$strings['messageXPasswordUpdatedLoginXPasswordX'] = "Se actualice la contraseña de un usuario"; |
||||
$strings['messageXRequestedPasswordChange'] = "Un usuario solicite un cambio de contraseña"; |
||||
$strings['messageXReceivedNewPersonalMessages'] = "Se reciban mensajes personales nuevos en la bandeja de entrada o en el foro"; |
||||
$strings['messageXNewUserXPendingApproval'] = "Una inscripción de un nuevo usuario esté pendiente de aprobación"; |
||||
$strings['messageXXPostedForumXCourseX'] = "Un usuario escriba en el foro"; |
||||
$strings['messageXXXCheckEmailConnectMoreInfo'] = "Se envíe una notificación"; |
||||
$strings['messageXXStudentXAnsweredTestX'] = "Un estudiante resuelva un ejercicio de un examen"; |
||||
$strings['messageXXStudentXAnsweredTestXOpenQuestion'] = "Un estudiante conteste a una pregunta abierta de un examen"; |
||||
$strings['messageXXStudentXAnsweredTestXVoiceQuestion'] = "Un estudiante conteste a una pregunta de voz de un examen"; |
||||
$strings['messageXXAnswerOpenQuestionTestXReviewed'] = "Se revise una pregunta abierta de un examen"; |
||||
$strings['messageXXNewThreadXStartedForumX'] = "Se cree un hilo nuevo en el foro"; |
||||
$strings['messageXXNewAnswerPostedXForumX'] = "Se escriba una respuesta nueva en el foro"; |
||||
$strings['messageXXNewSystemAnnouncementAdded'] = "Se añada una notificación y el usuario no desee enviar un examen por correo electrónico"; |
||||
$strings['messageXTestXNewSystemAnnouncementAdded'] = "Se añada una notificación y el usuario desee enviar un examen por correo electrónico"; |
||||
$strings['messageXXSystemAnnouncementUpdate'] = "Se actualice una notificación y el usuario no desee enviar un examen por correo electrónico"; |
||||
$strings['messageXTestXSystemAnnouncementUpdate'] = "Se actualice una notificación y el usuario desee enviar un examen por correo electrónico"; |
||||
$strings['messageXUserXUploadedAssignmentXCourseXStudentSubmitsPaper'] = "Un estudiante suba su tarea y no exista una sesión (se enviará sólo a coordinadores)"; |
||||
$strings['messageXUserXUploadedAssignmentXCheckXStudentSubmitsPaper'] = "Un estudiante suba su tarea (se enviará sólo a profesores)"; |
||||
$strings['messageXUserXUploadedAssignmentXCourseX'] = "... y no exista una sesión (se enviará sólo a coordinadores)"; |
||||
$strings['messageXUserXUploadedAssignmentXCheckX'] = "... (se enviará sólo a profesores)"; |
||||
$strings['messageXSubscribedSessionX'] = "Se cree o edite una sesión nueva y se suscriban a usuarios nuevos"; |
||||
$strings['messageXSubscribedSessionXCSV'] = "Se suscriban a usuarios nuevos desde un archivo CSV"; |
||||
$strings['messageXUserXSuggestedBeFriends'] = "Se reciba una invitación de amistad"; |
||||
$strings['messageXUserXAnsweredInboxMessage'] = "Se reciba la contestación a un mensaje en la bandeja de entrada"; |
||||
$strings['messageXBeenInvitedJoinGroupX'] = "Se reciba una invitación para unirse a un grupo"; |
||||
$strings['messageXMessagesSentEditedGroupXEdited'] = "Se actualice un mensaje en un tema de grupo"; |
||||
$strings['messageXMessagesSentEditedGroupXAdded'] = "Se añada un mensaje en un tema de grupo"; |
||||
$strings['messageXBeenInvitedCompleteSurveyXCourseX'] = "Se cree una encuesta nueva"; |
||||
$strings['messageXReminderAssignmentXCourseXDue'] = "Se envíe un recordatorio a los estudiantes que no hayan enviado su tarea"; |
||||
$strings['messageXUserDetailsModified'] = "Se actualice información de un usuario"; |
||||
|
||||
$strings['WelcomeXLoginXPasswordX'] = "Bienvenido a %s. Éstos son sus datos de acceso: usuario: %s, contraseña: %s"; |
||||
$strings['XNewFileSharedCourseXByX'] = "%s: Un nuevo archivo ha sido compartido contigo en el curso %s por %s"; |
||||
$strings['XAccountApprovedConnectX'] = "%s: Su cuenta ha sido aprobada por un administrador. Ya puede conectarse a %s"; |
||||
$strings['XNewCourseXBeenCreatedX'] = "%s: Un nuevo curso (%s) ha sido creado por %s"; |
||||
$strings['XNewUserXSubscribedCourseX'] = "%s: Un nuevo usuario (%s) se ha suscrito a su curso (%s)"; |
||||
$strings['XNewCourseSuggestedTeacherX'] = "%s: Un nuevo curso ha sido sugerido por el profesor (%s). Por favor, conéctese a la página de administración para revisarlo"; |
||||
$strings['XCourseOpeningRequestCodeXRegistered'] = "%s: Su solicitud de apertura de curso (código %s) ha sido registrada. Será informado cuando ésta sea aprobada"; |
||||
$strings['XCourseOpeningRequestCourseCodeXApproved'] = "%s: Su solicitud de apertura de curso para el código de curso %s ha sido aprobada. Conéctese a su portal para usarlo"; |
||||
$strings['XRequestOpenCourseCodeXReject'] = "%s: Lamentamos informarle que su solicitud de apertura de curso para el código de curso %s ha sido rechazada"; |
||||
$strings['XCourseOpeningRequestCourseCodeX'] = "%s: Su solicitud de apertura de curso para el código de curso %s requiere más información. Compruebe su e-mail para más información"; |
||||
$strings['XBeenSubscribedCourseX'] = "%s: Ha sido suscrito al curso %s"; |
||||
$strings['XAssignmentBeenCreatedCourseX'] = "%s: Una nueva tarea ha sido creada en el curso %s. Por favor, conéctese para más información"; |
||||
$strings['XAccountCreatedUpdatedLoginXPasswordX'] = "%s: Su cuenta ha sido creada o actualizada. Ya puede conectarse como %s, contraseña: %s"; |
||||
$strings['XPasswordUpdatedLoginXPasswordX'] = "%s: Su contraseña ha sido actualizada. Ya puede conectarse como %s, contraseña: %s"; |
||||
$strings['XRequestedPasswordChange'] = "%s: Ha solicitado un cambio de contraseña. Por favor, compruebe su e-mail para más información"; |
||||
$strings['XReceivedNewPersonalMessages'] = "%s: Ha recibido mensajes personales nuevos en su bandeja de entrada o en el foro. Por favor, compruebe su e-mail para más información"; |
||||
$strings['XNewUserXPendingApproval'] = "%s: Una inscripción de un nuevo usuario (%s) está pendiente de su aprobación. Por favor, conéctese al panel de administración para revisarla"; |
||||
$strings['XXPostedForumXCourseX'] = "%s: %s acaba de escribir en el foro %s del curso %s"; |
||||
$strings['XXXCheckEmailConnectMoreInfo'] = "%s: %s: %s. Compruebe su e-mail o conéctese para más información"; |
||||
$strings['XXStudentXAnsweredTestX'] = "%s: %s: El estudiante %s acaba de contestar al test %s"; |
||||
$strings['XXStudentXAnsweredTestXOpenQuestion'] = "%s: %s: El estudiante %s contestó a la pregunta abierta del test %s. Por favor, conéctese para revisarla"; |
||||
$strings['XXStudentXAnsweredTestXVoiceQuestion'] = "%s: %s: El estudiante %s contestó a la pregunta de voz del test %s. Por favor, conéctese para revisarla"; |
||||
$strings['XXAnswerOpenQuestionTestXReviewed'] = "%s: %s: Su respuesta a la pregunta abierta en el test %s ha sido revisada."; |
||||
$strings['XXNewThreadXStartedForumX'] = "%s: %s: Se ha comenzado un nuevo hilo (%s) en el foro %s"; |
||||
$strings['XXNewAnswerPostedXForumX'] = "%s: %s: Se ha escrito una nueva respuesta a (%s) en el foro %s"; |
||||
$strings['XXNewSystemAnnouncementAdded'] = "%s: %s"; |
||||
$strings['XTestXNewSystemAnnouncementAdded'] = "%s (prueba): %s"; |
||||
$strings['XXSystemAnnouncementUpdate'] = "%s: %s (actualización)"; |
||||
$strings['XTestXSystemAnnouncementUpdate'] = "%s (prueba): %s"; |
||||
$strings['XUserXUploadedAssignmentXCourseXStudentSubmitsPaper'] = "%s: El usuario %s subió la tarea %s al curso %s"; |
||||
$strings['XUserXUploadedAssignmentXCheckXStudentSubmitsPaper'] = "%s: El usuario %s subió la tarea %s. Compruébelo en %s"; |
||||
$strings['XUserXUploadedAssignmentXCourseX'] = "%s: El usuario %s subió la tarea %s al curso %s"; |
||||
$strings['XUserXUploadedAssignmentXCheckX'] = "%s: El usuario %s subió la tarea %s. Compruébelo en %s"; |
||||
$strings['XSubscribedSessionX'] = "%s: Ha sido suscrito a la sesión %s"; |
||||
$strings['XSubscribedSessionXCSV'] = "%s: Ha sido suscrito a la sesión %s"; |
||||
$strings['XUserXSuggestedBeFriends'] = "%s: El usuario %s le sugirió que podrían ser amigos. Compruebe su bandeja de entrada o su e-mail para más detalles"; |
||||
$strings['XUserXAnsweredInboxMessage'] = "%s: El usuario acaba de contestar a su mensaje de la bandeja de entrada"; |
||||
$strings['XBeenInvitedJoinGroupX'] = "%s: Ha sido invitado a unirse al grupo %s. Compruebe su bandeja de entrada para más detalles"; |
||||
$strings['XMessagesSentEditedGroupXEdited'] = "%s: Hay mensajes enviados o editados en el grupo %s. Compruebe su bandeja de entrada para más detalles"; |
||||
$strings['XMessagesSentEditedGroupXAdded'] = "%s: Hay mensajes enviados o editados en el grupo %s. Compruebe su bandeja de entrada para más detalles"; |
||||
$strings['XBeenInvitedCompleteSurveyXCourseX'] = "%s: Ha sido invitado a completar la encuesta %s del curso %s"; |
||||
$strings['XReminderAssignmentXCourseXDue'] = "%s: Se le recuerda que su tarea (%s) del curso %s aún está pendiente"; |
||||
$strings['XUserDetailsModified'] = "%s: Su información de usuario ha sido modificada. Compruebe su e-mail para más información"; |
@ -0,0 +1,608 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class clockworksms |
||||
* This script initiates a video conference session, calling the Clockworksms |
||||
* API |
||||
* @package chamilo.plugin.clockworksms |
||||
* |
||||
* Clockworksms-Chamilo connector class |
||||
*/ |
||||
|
||||
class Clockworksms |
||||
{ |
||||
public $apiKey; |
||||
public $api; |
||||
public $plugin_enabled = false; |
||||
|
||||
/** |
||||
* |
||||
* Constructor (generates a connection to the API) |
||||
* @param string $apiKey |
||||
*/ |
||||
public function __construct($apiKey = null) |
||||
{ |
||||
$plugin = ClockworksmsPlugin::create(); |
||||
$clockworksms_plugin = $plugin->get('tool_enable'); |
||||
if (empty($apiKey)) { |
||||
$clockworksmsApiKey = $plugin->get('api_key'); |
||||
} else { |
||||
$clockworksmsApiKey = $apiKey; |
||||
} |
||||
$this->table = Database::get_main_table('user_field_values'); |
||||
if ($clockworksms_plugin == true) { |
||||
$this->apiKey = $clockworksmsApiKey; |
||||
// Setting Clockworksms api |
||||
define('CONFIG_SECURITY_API_KEY', $this->apiKey); |
||||
if (!empty(trim(CONFIG_SECURITY_API_KEY))) { |
||||
$this->api = new Clockwork(CONFIG_SECURITY_API_KEY); |
||||
} |
||||
else { |
||||
$this->api = new Clockwork(' '); |
||||
$recipient_name = api_get_person_name(api_get_setting('administratorName'), |
||||
api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS); |
||||
$email_form = get_setting('emailAdministrator'); |
||||
$emailsubject = 'Clockworksms error'; |
||||
$emailbody = 'Key cannot be blank'; |
||||
$sender_name = $recipient_name; |
||||
$email_admin = $email_form; |
||||
api_mail_html($recipient_name, $email_form, $emailsubject, $emailbody, $sender_name, $email_admin); |
||||
} |
||||
$this->plugin_enabled = true; |
||||
} |
||||
} |
||||
|
||||
private function getMobilePhoneNumberById($userId) |
||||
{ |
||||
require_once api_get_path(LIBRARY_PATH).'extra_field.lib.php'; |
||||
$mobilePhoneNumberExtraField = (new ExtraField('user'))->get_handler_field_info_by_field_variable('mobile_phone_number'); |
||||
require_once api_get_path(LIBRARY_PATH).'extra_field_value.lib.php'; |
||||
$mobilePhoneNumberExtraFieldValue = (new ExtraFieldValue('user'))->get_values_by_handler_and_field_id($userId, $mobilePhoneNumberExtraField['id']); |
||||
return $mobilePhoneNumberExtraFieldValue['field_value']; |
||||
} |
||||
|
||||
public function send($additionalParameters) |
||||
{ |
||||
if (!empty(trim(CONFIG_SECURITY_API_KEY))) { |
||||
$message = array( |
||||
"to" => array_key_exists("mobilePhoneNumber",$additionalParameters) ? |
||||
$additionalParameters['mobilePhoneNumber'] : |
||||
$this->getMobilePhoneNumberById($additionalParameters['userId']), |
||||
"message" => $this->getSms($additionalParameters) |
||||
); |
||||
|
||||
if (!empty($message['message'])) { |
||||
$result = $this->api->send($message); |
||||
|
||||
// Check if the send was successful |
||||
/*if( $result["success"] ) { |
||||
echo "Message sent - ID: " . $result["id"]; |
||||
} else { |
||||
echo "Message failed - Error: " . $result["error_message"]; |
||||
}*/ |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
public function buildSms($plugin, $tpl, $templateName, $messageKey, $parameters = null) |
||||
{ |
||||
if (empty(Database::select('selected_value', 'settings_current', array( |
||||
'where'=> array('variable = ?' => array('clockworksms_message'.$messageKey)))))) { |
||||
$tpl->assign('message', ''); |
||||
} |
||||
else { |
||||
$templatePath = 'clockworksms/sms_templates/'; |
||||
$content = $tpl->fetch($templatePath.$templateName); |
||||
$message = $plugin->get_lang($messageKey); |
||||
if ($parameters !== null) { |
||||
$message = vsprintf($message, $parameters); |
||||
} |
||||
$tpl->assign('message', $message); |
||||
} |
||||
return $tpl->params['message']; |
||||
} |
||||
|
||||
public function getSms($additionalParameters) |
||||
{ |
||||
$plugin = ClockworksmsPlugin::create(); |
||||
$tool_name = $plugin->get_lang('plugin_title'); |
||||
$tpl = new Template($tool_name); |
||||
|
||||
switch (constant('ClockworksmsPlugin::'.$additionalParameters['smsType'])) { |
||||
case ClockworksmsPlugin::WELCOME_LOGIN_PASSWORD: |
||||
$userInfo = api_get_user_info($additionalParameters['userId']); |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'welcome_login_password.tpl', |
||||
'WelcomeXLoginXPasswordX', |
||||
array( |
||||
api_get_setting('siteName'), |
||||
$userInfo['username'], |
||||
$additionalParameters['password'] |
||||
) |
||||
); |
||||
break; |
||||
case ClockworksmsPlugin::NEW_FILE_SHARED_COURSE_BY: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'new_file_shared_course_by.tpl', |
||||
'XNewFileSharedCourseXByX', |
||||
array( |
||||
api_get_setting('siteName'), |
||||
$additionalParameters['courseTitle'], |
||||
$additionalParameters['userUsername'] |
||||
) |
||||
); |
||||
break; |
||||
case ClockworksmsPlugin::ACCOUNT_APPROVED_CONNECT: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'account_approved_connect.tpl', |
||||
'XAccountApprovedConnectX', |
||||
array( |
||||
api_get_setting('siteName'), |
||||
$tpl->params['_p']['web'] |
||||
) |
||||
); |
||||
break; |
||||
case ClockworksmsPlugin::NEW_COURSE_BEEN_CREATED: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'new_course_been_created.tpl', |
||||
'XNewCourseXBeenCreatedX', |
||||
array( |
||||
api_get_setting('siteName'), |
||||
$additionalParameters['courseName'], |
||||
$additionalParameters['creatorUsername'] |
||||
) |
||||
); |
||||
break; |
||||
case ClockworksmsPlugin::NEW_USER_SUBSCRIBED_COURSE: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'new_user_subscribed_course.tpl', |
||||
'XNewUserXSubscribedCourseX', |
||||
array( |
||||
api_get_setting('siteName'), |
||||
$additionalParameters['userUsername'], |
||||
$additionalParameters['courseCode'] |
||||
) |
||||
); |
||||
break; |
||||
case ClockworksmsPlugin::NEW_COURSE_SUGGESTED_TEACHER: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'new_course_suggested_teacher.tpl', |
||||
'XNewCourseSuggestedTeacherX', |
||||
array( |
||||
api_get_setting('siteName'), |
||||
$additionalParameters['userUsername'] |
||||
) |
||||
); |
||||
break; |
||||
case ClockworksmsPlugin::COURSE_OPENING_REQUEST_CODE_REGISTERED: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'course_opening_request_code_registered.tpl', |
||||
'XCourseOpeningRequestCodeXRegistered', |
||||
array( |
||||
api_get_setting('siteName'), |
||||
$additionalParameters['courseCode'] |
||||
) |
||||
); |
||||
break; |
||||
case ClockworksmsPlugin::COURSE_OPENING_REQUEST_COURSE_CODE_APPROVED: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'course_opening_request_course_code_approved.tpl', |
||||
'XCourseOpeningRequestCourseCodeXApproved', |
||||
array( |
||||
api_get_setting('siteName'), |
||||
$additionalParameters['courseCode'] |
||||
) |
||||
); |
||||
break; |
||||
case ClockworksmsPlugin::REQUEST_OPEN_COURSE_CODE_REJECTED: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'request_open_course_code_rejected.tpl', |
||||
'XRequestOpenCourseCodeXReject', |
||||
array( |
||||
api_get_setting('siteName'), |
||||
$additionalParameters['courseCode'] |
||||
) |
||||
); |
||||
break; |
||||
case ClockworksmsPlugin::COURSE_OPENING_REQUEST_COURSE_CODE: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'course_opening_request_course_code.tpl', |
||||
'XCourseOpeningRequestCourseCodeX', |
||||
array( |
||||
api_get_setting('siteName'), |
||||
$additionalParameters['courseCode'] |
||||
) |
||||
); |
||||
break; |
||||
case ClockworksmsPlugin::BEEN_SUBSCRIBED_COURSE: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'been_subscribed_course.tpl', |
||||
'XBeenSubscribedCourseX', |
||||
array( |
||||
api_get_setting('siteName'), |
||||
$additionalParameters['courseTitle'] |
||||
) |
||||
); |
||||
break; |
||||
case ClockworksmsPlugin::ASSIGNMENT_BEEN_CREATED_COURSE: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'assignment_been_created_course.tpl', |
||||
'XAssignmentBeenCreatedCourseX', |
||||
array( |
||||
api_get_setting('siteName'), |
||||
$additionalParameters['courseTitle'] |
||||
) |
||||
); |
||||
break; |
||||
/*case ClockworksmsPlugin::ACCOUNT_CREATED_UPDATED_LOGIN_PASSWORD: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'account_created_updated_login_password.tpl', |
||||
'XAccountCreatedUpdatedLoginXPasswordX', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::PASSWORD_UPDATED_LOGIN_PASSWORD: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'password_updated_login_password.tpl', |
||||
'XPasswordUpdatedLoginXPasswordX', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::REQUESTED_PASSWORD_CHANGE: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'requested_password_change.tpl', |
||||
'XPasswordUpdatedLoginXPasswordX', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::RECEIVED_NEW_PERSONAL_MESSAGES: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'received_new_personal_messages.tpl', |
||||
'XReceivedNewPersonalMessages', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::NEW_USER_PENDING_APPROVAL: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'new_user_pending_approval.tpl', |
||||
'XNewUserXPendingApproval', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::POSTED_FORUM_COURSE: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'posted_forum_course.tpl', |
||||
'XXPostedForumXCourseX', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::CHECK_EMAIL_CONNECT_MORE_INFO: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'check_email_connect_more_info.tpl', |
||||
'XXXCheckEmailConnectMoreInfo', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::STUDENT_ANSWERED_TEST: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'student_answered_test.tpl', |
||||
'XXStudentXAnsweredTestX', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::STUDENT_ANSWERED_TEST_OPEN_QUESTION: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'student_answered_test_open_question.tpl', |
||||
'XXStudentXAnsweredTestXOpenQuestion', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::STUDENT_ANSWERED_TEST_VOICE_QUESTION: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'student_answered_test_voice_question.tpl', |
||||
'XXStudentXAnsweredTestXVoiceQuestion', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::ANSWER_OPEN_QUESTION_TEST_REVIEWED: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'answer_open_question_test_reviewed.tpl', |
||||
'XXAnswerOpenQuestionTestXReviewed', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::NEW_THREAD_STARTED_FORUM: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'new_thread_started_forum.tpl', |
||||
'XXNewThreadXStartedForumX', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::NEW_ANSWER_POSTED_FORUM: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'new_answer_posted_forum.tpl', |
||||
'XXNewAnswerPostedXForumX', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::NEW_SYSTEM_ANNOUNCEMENT_ADDED: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'new_system_announcement_added.tpl', |
||||
'XXNewSystemAnnouncementAdded', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::TEST_NEW_SYSTEM_ANNOUNCEMENT_ADDED: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'test_new_system_announcement_added.tpl', |
||||
'XTestXNewSystemAnnouncementAdded', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::SYSTEM_ANNOUNCEMENT_UPDATE: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'system_announcement_update.tpl', |
||||
'XXSystemAnnouncementUpdate', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::TEST_SYSTEM_ANNOUNCEMENT_UPDATE: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'test_system_announcement_update.tpl', |
||||
'XXSystemAnnouncementUpdate', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::USER_UPLOADED_ASSIGNMENT_COURSE_STUDENT_SUBMITS_PAPER: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'user_uploaded_assignment_course_student_submits_paper.tpl', |
||||
'XUserXUploadedAssignmentXCourseXStudentSubmitsPaper', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::USER_UPLOADED_ASSIGNMENT_CHECK_STUDENT_SUBMITS_PAPER: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'user_uploaded_assignment_check_student_submits_paper.tpl', |
||||
'XUserXUploadedAssignmentXCheckXStudentSubmitsPaper', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::USER_UPLOADED_ASSIGNMENT_COURSE: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'user_uploaded_assignment_course.tpl', |
||||
'XUserXUploadedAssignmentXCourseX', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::USER_UPLOADED_ASSIGNMENT_CHECK: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'user_uploaded_assignment_check.tpl', |
||||
'XUserXUploadedAssignmentXCheckX', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::SUBSCRIBED_SESSION: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'subscribed_session.tpl', |
||||
'XSubscribedSessionX', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::SUBSCRIBED_SESSION_CSV: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'subscribed_session_csv.tpl', |
||||
'XSubscribedSessionXCSV', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::USER_SUGGESTED_BE_FRIENDS: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'user_suggested_be_friends.tpl', |
||||
'XUserXSuggestedBeFriends', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::USER_ANSWERED_INBOX_MESSAGE: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'user_answered_inbox_message.tpl', |
||||
'XUserXAnsweredInboxMessage', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::BEEN_INVITED_JOIN_GROUP: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'been_invited_join_group.tpl', |
||||
'XBeenInvitedJoinGroupX', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::MESSAGES_SENT_EDITED_GROUP_EDITED: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'messages_sent_edited_group_edited.tpl', |
||||
'XMessagesSentEditedGroupXEdited', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::MESSAGES_SENT_EDITED_GROUP_ADDED: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'messages_sent_edited_group_added.tpl', |
||||
'XMessagesSentEditedGroupXAdded', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::BEEN_INVITED_COMPLETE_SURVEY_COURSE: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'been_invited_complete_survey_course.tpl', |
||||
'XBeenInvitedCompleteSurveyXCourseX', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::REMINDER_ASSIGNMENT_COURSE_DUE: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'reminder_assignment_course_due.tpl', |
||||
'XReminderAssignmentXCourseXDue', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
/*case ClockworksmsPlugin::USER_DETAILS_MODIFIED: |
||||
return $this->buildSms( |
||||
$plugin, |
||||
$tpl, |
||||
'user_details_modified.tpl', |
||||
'XUserDetailsModified', |
||||
array( |
||||
api_get_setting('siteName') |
||||
) |
||||
); |
||||
break;*/ |
||||
default: |
||||
return ''; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,643 @@ |
||||
<?php |
||||
/** |
||||
* Clockwork PHP API |
||||
* |
||||
* @package Clockwork |
||||
* @copyright Mediaburst Ltd 2012 |
||||
* @license ISC |
||||
* @link http://www.clockworksms.com |
||||
* @version 1.3.0 |
||||
*/ |
||||
|
||||
if ( !class_exists('ClockworkException') ) { |
||||
require_once('exception.php'); |
||||
} |
||||
|
||||
/** |
||||
* Main Clockwork API Class |
||||
* |
||||
* @package Clockwork |
||||
* @since 1.0 |
||||
*/ |
||||
class Clockwork { |
||||
|
||||
/* |
||||
* Version of this class |
||||
*/ |
||||
const VERSION = '1.3.1'; |
||||
|
||||
/** |
||||
* All Clockwork API calls start with BASE_URL |
||||
* @author Martin Steel |
||||
*/ |
||||
const API_BASE_URL = 'api.clockworksms.com/xml/'; |
||||
|
||||
/** |
||||
* string to append to API_BASE_URL to check authentication |
||||
* @author Martin Steel |
||||
*/ |
||||
const API_AUTH_METHOD = 'authenticate'; |
||||
|
||||
/** |
||||
* string to append to API_BASE_URL for sending SMS |
||||
* @author Martin Steel |
||||
*/ |
||||
const API_SMS_METHOD = 'sms'; |
||||
|
||||
/** |
||||
* string to append to API_BASE_URL for checking message credit |
||||
* @author Martin Steel |
||||
*/ |
||||
const API_CREDIT_METHOD = 'credit'; |
||||
|
||||
/** |
||||
* string to append to API_BASE_URL for checking account balance |
||||
* @author Martin Steel |
||||
*/ |
||||
const API_BALANCE_METHOD = 'balance'; |
||||
|
||||
/** |
||||
* Clockwork API Key |
||||
* |
||||
* @var string |
||||
* @author Martin Steel |
||||
*/ |
||||
public $key; |
||||
|
||||
/** |
||||
* Use SSL when making HTTP requests |
||||
* |
||||
* If this is not set, SSL will be used where PHP supports it |
||||
* |
||||
* @var bool |
||||
* @author Martin Steel |
||||
*/ |
||||
public $ssl; |
||||
|
||||
/** |
||||
* Proxy server hostname (Optional) |
||||
* |
||||
* @var string |
||||
* @author Martin Steel |
||||
*/ |
||||
public $proxy_host; |
||||
|
||||
/** |
||||
* Proxy server port (Optional) |
||||
* |
||||
* @var integer |
||||
* @author Martin Steel |
||||
*/ |
||||
public $proxy_port; |
||||
|
||||
/** |
||||
* From address used on text messages |
||||
* |
||||
* @var string (11 characters or 12 numbers) |
||||
* @author Martin Steel |
||||
*/ |
||||
public $from; |
||||
|
||||
/** |
||||
* Allow long SMS messages (Cost up to 3 credits) |
||||
* |
||||
* @var bool |
||||
* @author Martin Steel |
||||
*/ |
||||
public $long; |
||||
|
||||
/** |
||||
* Truncate message text if it is too long |
||||
* |
||||
* @var bool |
||||
* @author Martin Steel |
||||
*/ |
||||
public $truncate; |
||||
|
||||
/** |
||||
* Enables various logging of messages when true. |
||||
* |
||||
* @var bool |
||||
* @author Martin Steel |
||||
*/ |
||||
public $log; |
||||
|
||||
/** |
||||
* What Clockwork should do if you send an invalid character |
||||
* |
||||
* Possible values: |
||||
* 'error' - Return an error (Messasge is not sent) |
||||
* 'remove' - Remove the invalid character(s) |
||||
* 'replace' - Replace invalid characters where possible, remove others |
||||
* @author Martin Steel |
||||
*/ |
||||
public $invalid_char_action; |
||||
|
||||
/** |
||||
* Create a new instance of the Clockwork wrapper |
||||
* |
||||
* @param string key Your Clockwork API Key |
||||
* @param array options Optional parameters for sending SMS |
||||
* @author Martin Steel |
||||
*/ |
||||
public function __construct($key, array $options = array()) { |
||||
if (empty($key)) { |
||||
throw new ClockworkException("Key can't be blank"); |
||||
} else { |
||||
$this->key = $key; |
||||
} |
||||
|
||||
$this->ssl = (array_key_exists('ssl', $options)) ? $options['ssl'] : null; |
||||
$this->proxy_host = (array_key_exists('proxy_host', $options)) ? $options['proxy_host'] : null; |
||||
$this->proxy_port = (array_key_exists('proxy_port', $options)) ? $options['proxy_port'] : null; |
||||
$this->from = (array_key_exists('from', $options)) ? $options['from'] : null; |
||||
$this->long = (array_key_exists('long', $options)) ? $options['long'] : null; |
||||
$this->truncate = (array_key_exists('truncate', $options)) ? $options['truncate'] : null; |
||||
$this->invalid_char_action = (array_key_exists('invalid_char_action', $options)) ? $options['invalid_char_action'] : null; |
||||
$this->log = (array_key_exists('log', $options)) ? $options['log'] : false; |
||||
} |
||||
|
||||
/** |
||||
* Send some text messages |
||||
* |
||||
* |
||||
* @author Martin Steel |
||||
*/ |
||||
public function send(array $sms) { |
||||
if (!is_array($sms)) { |
||||
throw new ClockworkException("sms parameter must be an array"); |
||||
} |
||||
$single_message = $this->is_assoc($sms); |
||||
|
||||
if ($single_message) { |
||||
$sms = array($sms); |
||||
} |
||||
|
||||
$req_doc = new DOMDocument('1.0', 'UTF-8'); |
||||
$root = $req_doc->createElement('Message'); |
||||
$req_doc->appendChild($root); |
||||
|
||||
$user_node = $req_doc->createElement('Key'); |
||||
$user_node->appendChild($req_doc->createTextNode($this->key)); |
||||
$root->appendChild($user_node); |
||||
|
||||
for ($i = 0; $i < count($sms); $i++) { |
||||
$single = $sms[$i]; |
||||
|
||||
$sms_node = $req_doc->createElement('SMS'); |
||||
|
||||
// Phone number |
||||
$sms_node->appendChild($req_doc->createElement('To', $single['to'])); |
||||
|
||||
// Message text |
||||
$content_node = $req_doc->createElement('Content'); |
||||
$content_node->appendChild($req_doc->createTextNode($single['message'])); |
||||
$sms_node->appendChild($content_node); |
||||
|
||||
// From |
||||
if (array_key_exists('from', $single) || isset($this->from)) { |
||||
$from_node = $req_doc->createElement('From'); |
||||
$from_node->appendChild($req_doc->createTextNode(array_key_exists('from', $single) ? $single['from'] : $this->from)); |
||||
$sms_node->appendChild($from_node); |
||||
} |
||||
|
||||
// Client ID |
||||
if (array_key_exists('client_id', $single)) { |
||||
$client_id_node = $req_doc->createElement('ClientID'); |
||||
$client_id_node->appendChild($req_doc->createTextNode($single['client_id'])); |
||||
$sms_node->appendChild($client_id_node); |
||||
} |
||||
|
||||
// Long |
||||
if (array_key_exists('long', $single) || isset($this->long)) { |
||||
$long = array_key_exists('long', $single) ? $single['long'] : $this->long; |
||||
$long_node = $req_doc->createElement('Long'); |
||||
$long_node->appendChild($req_doc->createTextNode($long ? 1 : 0)); |
||||
$sms_node->appendChild($long_node); |
||||
} |
||||
|
||||
// Truncate |
||||
if (array_key_exists('truncate', $single) || isset($this->truncate)) { |
||||
$truncate = array_key_exists('truncate', $single) ? $single['truncate'] : $this->truncate; |
||||
$trunc_node = $req_doc->createElement('Truncate'); |
||||
$trunc_node->appendChild($req_doc->createTextNode($truncate ? 1 : 0)); |
||||
$sms_node->appendChild($trunc_node); |
||||
} |
||||
|
||||
// Invalid Char Action |
||||
if (array_key_exists('invalid_char_action', $single) || isset($this->invalid_char_action)) { |
||||
$action = array_key_exists('invalid_char_action', $single) ? $single['invalid_char_action'] : $this->invalid_char_action; |
||||
switch (strtolower($action)) { |
||||
case 'error': |
||||
$sms_node->appendChild($req_doc->createElement('InvalidCharAction', 1)); |
||||
break; |
||||
case 'remove': |
||||
$sms_node->appendChild($req_doc->createElement('InvalidCharAction', 2)); |
||||
break; |
||||
case 'replace': |
||||
$sms_node->appendChild($req_doc->createElement('InvalidCharAction', 3)); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
|
||||
// Wrapper ID |
||||
$sms_node->appendChild($req_doc->createElement('WrapperID', $i)); |
||||
|
||||
$root->appendChild($sms_node); |
||||
} |
||||
|
||||
$req_xml = $req_doc->saveXML(); |
||||
|
||||
$resp_xml = $this->postToClockwork(self::API_SMS_METHOD, $req_xml); |
||||
$resp_doc = new DOMDocument(); |
||||
$resp_doc->loadXML($resp_xml); |
||||
|
||||
$response = array(); |
||||
$err_no = null; |
||||
$err_desc = null; |
||||
|
||||
foreach($resp_doc->documentElement->childNodes AS $doc_child) { |
||||
switch(strtolower($doc_child->nodeName)) { |
||||
case 'sms_resp': |
||||
$resp = array(); |
||||
$wrapper_id = null; |
||||
foreach($doc_child->childNodes AS $resp_node) { |
||||
switch(strtolower($resp_node->nodeName)) { |
||||
case 'messageid': |
||||
$resp['id'] = $resp_node->nodeValue; |
||||
break; |
||||
case 'errno': |
||||
$resp['error_code'] = $resp_node->nodeValue; |
||||
break; |
||||
case 'errdesc': |
||||
$resp['error_message'] = $resp_node->nodeValue; |
||||
break; |
||||
case 'wrapperid': |
||||
$wrapper_id = $resp_node->nodeValue; |
||||
break; |
||||
} |
||||
} |
||||
if( array_key_exists('error_code', $resp ) ) |
||||
{ |
||||
$resp['success'] = 0; |
||||
} else { |
||||
$resp['success'] = 1; |
||||
} |
||||
$resp['sms'] = $sms[$wrapper_id]; |
||||
array_push($response, $resp); |
||||
break; |
||||
case 'errno': |
||||
$err_no = $doc_child->nodeValue; |
||||
break; |
||||
case 'errdesc': |
||||
$err_desc = $doc_child->nodeValue; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
if (isset($err_no)) { |
||||
throw new ClockworkException($err_desc, $err_no); |
||||
} |
||||
|
||||
if ($single_message) { |
||||
return $response[0]; |
||||
} else { |
||||
return $response; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Check how many SMS credits you have available |
||||
* |
||||
* @return integer SMS credits remaining |
||||
* @deprecated Use checkBalance() instead |
||||
* @author Martin Steel |
||||
*/ |
||||
public function checkCredit() { |
||||
// Create XML doc for request |
||||
$req_doc = new DOMDocument('1.0', 'UTF-8'); |
||||
$root = $req_doc->createElement('Credit'); |
||||
$req_doc->appendChild($root); |
||||
$root->appendChild($req_doc->createElement('Key', $this->key)); |
||||
$req_xml = $req_doc->saveXML(); |
||||
|
||||
// POST XML to Clockwork |
||||
$resp_xml = $this->postToClockwork(self::API_CREDIT_METHOD, $req_xml); |
||||
|
||||
// Create XML doc for response |
||||
$resp_doc = new DOMDocument(); |
||||
$resp_doc->loadXML($resp_xml); |
||||
|
||||
// Parse the response to find credit value |
||||
$credit; |
||||
$err_no = null; |
||||
$err_desc = null; |
||||
|
||||
foreach ($resp_doc->documentElement->childNodes AS $doc_child) { |
||||
switch ($doc_child->nodeName) { |
||||
case "Credit": |
||||
$credit = $doc_child->nodeValue; |
||||
break; |
||||
case "ErrNo": |
||||
$err_no = $doc_child->nodeValue; |
||||
break; |
||||
case "ErrDesc": |
||||
$err_desc = $doc_child->nodeValue; |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
|
||||
if (isset($err_no)) { |
||||
throw new ClockworkException($err_desc, $err_no); |
||||
} |
||||
return $credit; |
||||
} |
||||
|
||||
/** |
||||
* Check your account balance |
||||
* |
||||
* @return array Array of account balance: |
||||
* @author Martin Steel |
||||
*/ |
||||
public function checkBalance() { |
||||
// Create XML doc for request |
||||
$req_doc = new DOMDocument('1.0', 'UTF-8'); |
||||
$root = $req_doc->createElement('Balance'); |
||||
$req_doc->appendChild($root); |
||||
$root->appendChild($req_doc->createElement('Key', $this->key)); |
||||
$req_xml = $req_doc->saveXML(); |
||||
|
||||
// POST XML to Clockwork |
||||
$resp_xml = $this->postToClockwork(self::API_BALANCE_METHOD, $req_xml); |
||||
|
||||
// Create XML doc for response |
||||
$resp_doc = new DOMDocument(); |
||||
$resp_doc->loadXML($resp_xml); |
||||
|
||||
// Parse the response to find balance value |
||||
$balance = null; |
||||
$err_no = null; |
||||
$err_desc = null; |
||||
|
||||
foreach ($resp_doc->documentElement->childNodes as $doc_child) { |
||||
switch ($doc_child->nodeName) { |
||||
case "Balance": |
||||
$balance = number_format(floatval($doc_child->nodeValue), 2); |
||||
break; |
||||
case "Currency": |
||||
foreach ($doc_child->childNodes as $resp_node) { |
||||
switch ($resp_node->tagName) { |
||||
case "Symbol": |
||||
$symbol = $resp_node->nodeValue; |
||||
break; |
||||
case "Code": |
||||
$code = $resp_node->nodeValue; |
||||
break; |
||||
} |
||||
} |
||||
break; |
||||
case "ErrNo": |
||||
$err_no = $doc_child->nodeValue; |
||||
break; |
||||
case "ErrDesc": |
||||
$err_desc = $doc_child->nodeValue; |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
|
||||
if (isset($err_no)) { |
||||
throw new ClockworkException($err_desc, $err_no); |
||||
} |
||||
|
||||
return array( 'symbol' => $symbol, 'balance' => $balance, 'code' => $code ); |
||||
} |
||||
|
||||
/** |
||||
* Check whether the API Key is valid |
||||
* |
||||
* @return bool True indicates a valid key |
||||
* @author Martin Steel |
||||
*/ |
||||
public function checkKey() { |
||||
// Create XML doc for request |
||||
$req_doc = new DOMDocument('1.0', 'UTF-8'); |
||||
$root = $req_doc->createElement('Authenticate'); |
||||
$req_doc->appendChild($root); |
||||
$root->appendChild($req_doc->createElement('Key', $this->key)); |
||||
$req_xml = $req_doc->saveXML(); |
||||
|
||||
// POST XML to Clockwork |
||||
$resp_xml = $this->postToClockwork(self::API_AUTH_METHOD, $req_xml); |
||||
|
||||
// Create XML doc for response |
||||
$resp_doc = new DOMDocument(); |
||||
$resp_doc->loadXML($resp_xml); |
||||
|
||||
// Parse the response to see if authenticated |
||||
$cust_id; |
||||
$err_no = null; |
||||
$err_desc = null; |
||||
|
||||
foreach ($resp_doc->documentElement->childNodes AS $doc_child) { |
||||
switch ($doc_child->nodeName) { |
||||
case "CustID": |
||||
$cust_id = $doc_child->nodeValue; |
||||
break; |
||||
case "ErrNo": |
||||
$err_no = $doc_child->nodeValue; |
||||
break; |
||||
case "ErrDesc": |
||||
$err_desc = $doc_child->nodeValue; |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
|
||||
if (isset($err_no)) { |
||||
throw new ClockworkException($err_desc, $err_no); |
||||
} |
||||
return isset($cust_id); |
||||
} |
||||
|
||||
/** |
||||
* Make an HTTP POST to Clockwork |
||||
* |
||||
* @param string method Clockwork method to call (sms/credit) |
||||
* @param string data Content of HTTP POST |
||||
* |
||||
* @return string Response from Clockwork |
||||
* @author Martin Steel |
||||
*/ |
||||
protected function postToClockwork($method, $data) { |
||||
if ($this->log) { |
||||
$this->logXML("API $method Request XML", $data); |
||||
} |
||||
|
||||
if( isset( $this->ssl ) ) { |
||||
$ssl = $this->ssl; |
||||
} else { |
||||
$ssl = $this->sslSupport(); |
||||
} |
||||
|
||||
$url = $ssl ? 'https://' : 'http://'; |
||||
$url .= self::API_BASE_URL . $method; |
||||
|
||||
$response = $this->xmlPost($url, $data); |
||||
|
||||
if ($this->log) { |
||||
$this->logXML("API $method Response XML", $response); |
||||
} |
||||
|
||||
return $response; |
||||
} |
||||
|
||||
/** |
||||
* Make a HTTP POST |
||||
* |
||||
* cURL will be used if available, otherwise tries the PHP stream functions |
||||
* |
||||
* @param string url URL to send to |
||||
* @param string data Data to POST |
||||
* @return string Response returned by server |
||||
* @author Martin Steel |
||||
*/ |
||||
protected function xmlPost($url, $data) { |
||||
if(extension_loaded('curl')) { |
||||
$ch = curl_init($url); |
||||
curl_setopt($ch, CURLOPT_POST, 1); |
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); |
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Clockwork PHP Wrapper/1.0' . self::VERSION); |
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
||||
if (isset($this->proxy_host) && isset($this->proxy_port)) { |
||||
curl_setopt($ch, CURLOPT_PROXY, $this->proxy_host); |
||||
curl_setopt($ch, CURLOPT_PROXYPORT, $this->proxy_port); |
||||
} |
||||
|
||||
$response = curl_exec($ch); |
||||
$info = curl_getinfo($ch); |
||||
|
||||
if ($response === false || $info['http_code'] != 200) { |
||||
throw new Exception('HTTP Error calling Clockwork API - HTTP Status: ' . $info['http_code'] . ' - cURL Erorr: ' . curl_error($ch)); |
||||
} elseif (curl_errno($ch) > 0) { |
||||
throw new Exception('HTTP Error calling Clockwork API - cURL Error: ' . curl_error($ch)); |
||||
} |
||||
|
||||
curl_close($ch); |
||||
|
||||
return $response; |
||||
} elseif (function_exists('stream_get_contents')) { |
||||
// Enable error Track Errors |
||||
$track = ini_get('track_errors'); |
||||
ini_set('track_errors',true); |
||||
|
||||
$params = array('http' => array( |
||||
'method' => 'POST', |
||||
'header' => "Content-Type: text/xml\r\nUser-Agent: mediaburst PHP Wrapper/" . self::VERSION . "\r\n", |
||||
'content' => $data |
||||
)); |
||||
|
||||
if (isset($this->proxy_host) && isset($this->proxy_port)) { |
||||
$params['http']['proxy'] = 'tcp://'.$this->proxy_host . ':' . $this->proxy_port; |
||||
$params['http']['request_fulluri'] = True; |
||||
} |
||||
|
||||
$ctx = stream_context_create($params); |
||||
$fp = @fopen($url, 'rb', false, $ctx); |
||||
if (!$fp) { |
||||
ini_set('track_errors',$track); |
||||
throw new Exception("HTTP Error calling Clockwork API - fopen Error: $php_errormsg"); |
||||
} |
||||
$response = @stream_get_contents($fp); |
||||
if ($response === false) { |
||||
ini_set('track_errors',$track); |
||||
throw new Exception("HTTP Error calling Clockwork API - stream Error: $php_errormsg"); |
||||
} |
||||
ini_set('track_errors',$track); |
||||
return $response; |
||||
} else { |
||||
throw new Exception("Clockwork requires PHP5 with cURL or HTTP stream support"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Does the server/HTTP wrapper support SSL |
||||
* |
||||
* This is a best guess effort, some servers have weird setups where even |
||||
* though cURL is compiled with SSL support is still fails to make |
||||
* any requests. |
||||
* |
||||
* @return bool True if SSL is supported |
||||
* @author Martin Steel |
||||
*/ |
||||
protected function sslSupport() { |
||||
$ssl = false; |
||||
// See if PHP is compiled with cURL |
||||
if (extension_loaded('curl')) { |
||||
$version = curl_version(); |
||||
$ssl = ($version['features'] & CURL_VERSION_SSL) ? true : false; |
||||
} elseif (extension_loaded('openssl')) { |
||||
$ssl = true; |
||||
} |
||||
return $ssl; |
||||
} |
||||
|
||||
/** |
||||
* Log some XML, tidily if possible, in the PHP error log |
||||
* |
||||
* @param string log_msg The log message to prepend to the XML |
||||
* @param string xml An XML formatted string |
||||
* |
||||
* @return void |
||||
* @author Martin Steel |
||||
*/ |
||||
protected function logXML($log_msg, $xml) { |
||||
// Tidy if possible |
||||
if (class_exists('tidy')) { |
||||
$tidy = new tidy; |
||||
$config = array( |
||||
'indent' => true, |
||||
'input-xml' => true, |
||||
'output-xml' => true, |
||||
'wrap' => 200 |
||||
); |
||||
$tidy->parseString($xml, $config, 'utf8'); |
||||
$tidy->cleanRepair(); |
||||
$xml = $tidy; |
||||
} |
||||
// Output |
||||
error_log("Clockwork $log_msg: $xml"); |
||||
} |
||||
|
||||
/** |
||||
* Check if an array is associative |
||||
* |
||||
* @param array $array Array to check |
||||
* @return bool |
||||
* @author Martin Steel |
||||
*/ |
||||
protected function is_assoc($array) { |
||||
return (bool)count(array_filter(array_keys($array), 'is_string')); |
||||
} |
||||
|
||||
/** |
||||
* Check if a number is a valid MSISDN |
||||
* |
||||
* @param string $val Value to check |
||||
* @return bool True if valid MSISDN |
||||
* @author James Inman |
||||
* @since 1.3.0 |
||||
* @todo Take an optional country code and check that the number starts with it |
||||
*/ |
||||
public static function is_valid_msisdn($val) { |
||||
return preg_match( '/^[1-9][0-9]{7,12}$/', $val ); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,153 @@ |
||||
<?php |
||||
/** |
||||
* Class ClockworksmsPlugin |
||||
*/ |
||||
class ClockworksmsPlugin extends Plugin |
||||
{ |
||||
const WELCOME_LOGIN_PASSWORD = 0; |
||||
const NEW_FILE_SHARED_COURSE_BY = 1; |
||||
const ACCOUNT_APPROVED_CONNECT = 2; |
||||
const NEW_COURSE_BEEN_CREATED = 3; |
||||
const NEW_USER_SUBSCRIBED_COURSE = 4; |
||||
const NEW_COURSE_SUGGESTED_TEACHER = 5; |
||||
const COURSE_OPENING_REQUEST_CODE_REGISTERED = 6; |
||||
const COURSE_OPENING_REQUEST_COURSE_CODE_APPROVED = 7; |
||||
const REQUEST_OPEN_COURSE_CODE_REJECTED = 8; |
||||
const COURSE_OPENING_REQUEST_COURSE_CODE = 9; |
||||
const BEEN_SUBSCRIBED_COURSE = 10; |
||||
const ASSIGNMENT_BEEN_CREATED_COURSE = 11; |
||||
const ACCOUNT_CREATED_UPDATED_LOGIN_PASSWORD = 12; |
||||
const PASSWORD_UPDATED_LOGIN_PASSWORD = 13; |
||||
const REQUESTED_PASSWORD_CHANGE = 14; |
||||
const RECEIVED_NEW_PERSONAL_MESSAGES = 15; |
||||
const NEW_USER_PENDING_APPROVAL = 16; |
||||
const POSTED_FORUM_COURSE = 17; |
||||
const CHECK_EMAIL_CONNECT_MORE_INFO = 18; |
||||
const STUDENT_ANSWERED_TEST = 19; |
||||
const STUDENT_ANSWERED_TEST_OPEN_QUESTION = 20; |
||||
const STUDENT_ANSWERED_TEST_VOICE_QUESTION = 21; |
||||
const ANSWER_OPEN_QUESTION_TEST_REVIEWED = 22; |
||||
const NEW_THREAD_STARTED_FORUM = 23; |
||||
const NEW_ANSWER_POSTED_FORUM = 24; |
||||
const NEW_SYSTEM_ANNOUNCEMENT_ADDED = 25; |
||||
const TEST_NEW_SYSTEM_ANNOUNCEMENT_ADDED = 26; |
||||
const SYSTEM_ANNOUNCEMENT_UPDATE = 27; |
||||
const TEST_SYSTEM_ANNOUNCEMENT_UPDATE = 28; |
||||
const USER_UPLOADED_ASSIGNMENT_COURSE_STUDENT_SUBMITS_PAPER = 29; |
||||
const USER_UPLOADED_ASSIGNMENT_CHECK_STUDENT_SUBMITS_PAPER = 30; |
||||
const USER_UPLOADED_ASSIGNMENT_COURSE = 31; |
||||
const USER_UPLOADED_ASSIGNMENT_CHECK = 32; |
||||
const SUBSCRIBED_SESSION = 33; |
||||
const SUBSCRIBED_SESSION_CSV = 34; |
||||
const USER_SUGGESTED_BE_FRIENDS = 35; |
||||
const USER_ANSWERED_INBOX_MESSAGE = 36; |
||||
const BEEN_INVITED_JOIN_GROUP = 37; |
||||
const MESSAGES_SENT_EDITED_GROUP_EDITED = 38; |
||||
const MESSAGES_SENT_EDITED_GROUP_ADDED = 39; |
||||
const BEEN_INVITED_COMPLETE_SURVEY_COURSE = 40; |
||||
const REMINDER_ASSIGNMENT_COURSE_DUE = 41; |
||||
const USER_DETAILS_MODIFIED = 42; |
||||
|
||||
public $isCoursePlugin = true; |
||||
public $isMailPlugin = true; |
||||
|
||||
static function create() |
||||
{ |
||||
static $result = null; |
||||
return $result ? $result : $result = new self(); |
||||
} |
||||
|
||||
protected function __construct() |
||||
{ |
||||
$fields = array('tool_enable' => 'boolean', 'api_key' => 'text'); |
||||
$smsTypeOptions = $this->getSmsTypeOptions(); |
||||
foreach ($smsTypeOptions as $smsTypeOption) { |
||||
$fields[$smsTypeOption] = 'checkbox'; |
||||
} |
||||
parent::__construct('0.1', 'Imanol Losada', $fields); |
||||
} |
||||
|
||||
private function addMobilePhoneNumberField() |
||||
{ |
||||
if (empty(Database::select('mobile_phone_number', 'user_field'))) { |
||||
require_once api_get_path(LIBRARY_PATH).'extra_field.lib.php'; |
||||
$extraField = new Extrafield('user'); |
||||
$extraField->save(array( |
||||
'field_type' => 1, |
||||
'field_variable' => 'mobile_phone_number', |
||||
'field_display_text' => $this->get_lang('mobile_phone_number'), |
||||
'field_default_value' => null, |
||||
'field_order' => 2, |
||||
'field_visible' => 1, |
||||
'field_changeable' => 1, |
||||
'field_filter' => null |
||||
)); |
||||
} |
||||
} |
||||
|
||||
private function getSmsTypeOptions() |
||||
{ |
||||
return array( |
||||
'messageWelcomeXLoginXPasswordX', |
||||
'messageXNewFileSharedCourseXByX', |
||||
'messageXAccountApprovedConnectX', |
||||
'messageXNewCourseXBeenCreatedX', |
||||
'messageXNewUserXSubscribedCourseX', |
||||
'messageXNewCourseSuggestedTeacherX', |
||||
'messageXCourseOpeningRequestCodeXRegistered', |
||||
'messageXCourseOpeningRequestCourseCodeXApproved', |
||||
'messageXRequestOpenCourseCodeXReject', |
||||
'messageXCourseOpeningRequestCourseCodeX', |
||||
'messageXBeenSubscribedCourseX', |
||||
'messageXAssignmentBeenCreatedCourseX', |
||||
'messageXAccountCreatedUpdatedLoginXPasswordX', |
||||
'messageXPasswordUpdatedLoginXPasswordX', |
||||
'messageXRequestedPasswordChange', |
||||
'messageXReceivedNewPersonalMessages', |
||||
'messageXNewUserXPendingApproval', |
||||
'messageXXPostedForumXCourseX', |
||||
'messageXXXCheckEmailConnectMoreInfo', |
||||
'messageXXStudentXAnsweredTestX', |
||||
'messageXXStudentXAnsweredTestXOpenQuestion', |
||||
'messageXXStudentXAnsweredTestXVoiceQuestion', |
||||
'messageXXAnswerOpenQuestionTestXReviewed', |
||||
'messageXXNewThreadXStartedForumX', |
||||
'messageXXNewAnswerPostedXForumX', |
||||
'messageXXNewSystemAnnouncementAdded', |
||||
'messageXTestXNewSystemAnnouncementAdded', |
||||
'messageXXSystemAnnouncementUpdate', |
||||
'messageXTestXSystemAnnouncementUpdate', |
||||
'messageXUserXUploadedAssignmentXCourseXStudentSubmitsPaper', |
||||
'messageXUserXUploadedAssignmentXCheckXStudentSubmitsPaper', |
||||
'messageXUserXUploadedAssignmentXCourseX', |
||||
'messageXUserXUploadedAssignmentXCheckX', |
||||
'messageXSubscribedSessionX', |
||||
'messageXSubscribedSessionXCSV', |
||||
'messageXUserXSuggestedBeFriends', |
||||
'messageXUserXAnsweredInboxMessage', |
||||
'messageXBeenInvitedJoinGroupX', |
||||
'messageXMessagesSentEditedGroupXEdited', |
||||
'messageXMessagesSentEditedGroupXAdded', |
||||
'messageXBeenInvitedCompleteSurveyXCourseX', |
||||
'messageXReminderAssignmentXCourseXDue', |
||||
'messageXUserDetailsModified' |
||||
); |
||||
} |
||||
|
||||
public function install() |
||||
{ |
||||
$this->addMobilePhoneNumberField(); |
||||
|
||||
//Installing course settings |
||||
//$this->install_course_fields_in_all_courses(); |
||||
} |
||||
|
||||
public function uninstall() |
||||
{ |
||||
$t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); |
||||
$sql = "DELETE FROM $t_settings WHERE subkey = 'clockworksms'"; |
||||
Database::query($sql); |
||||
//Deleting course settings |
||||
//$this->uninstall_course_fields_in_all_courses($this->course_settings); |
||||
} |
||||
} |
@ -0,0 +1,27 @@ |
||||
<?php |
||||
/** |
||||
* Clockwork PHP API |
||||
* |
||||
* @package Clockwork |
||||
* @copyright Mediaburst Ltd 2012 |
||||
* @license ISC |
||||
* @link http://www.clockworksms.com |
||||
*/ |
||||
|
||||
/* |
||||
* ClockworkException |
||||
* |
||||
* The Clockwork wrapper class will throw these if a general error |
||||
* occurs with your request, for example, an invalid API key. |
||||
* |
||||
* @package Clockwork |
||||
* @subpackage Exception |
||||
* @since 1.0 |
||||
*/ |
||||
class ClockworkException extends Exception { |
||||
|
||||
public function __construct( $message, $code = 0 ) { |
||||
// make sure everything is assigned properly |
||||
parent::__construct( $message, $code ); |
||||
} |
||||
} |
@ -0,0 +1,13 @@ |
||||
Copyright (c) 2011 - 2012, Mediaburst Ltd <hello@mediaburst.co.uk> |
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
||||
purpose with or without fee is hereby granted, provided that the above |
||||
copyright notice and this permission notice appear in all copies. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
@ -0,0 +1,5 @@ |
||||
<?php |
||||
|
||||
require_once dirname(__FILE__).'/config.php'; |
||||
|
||||
$plugin_info = ClockworksmsPlugin::create()->get_info(); |
@ -0,0 +1,253 @@ |
||||
# Clockwork SMS API Wrapper for PHP |
||||
|
||||
This wrapper lets you interact with Clockwork without the hassle of having to create any XML or make HTTP calls. |
||||
|
||||
## What's Clockwork? |
||||
|
||||
[Clockwork][2] is Mediaburst's SMS API. |
||||
|
||||
### Prerequisites |
||||
|
||||
* A [Clockwork][2] account |
||||
|
||||
## Usage |
||||
|
||||
Require the Clockwork library: |
||||
|
||||
```php |
||||
require 'class-Clockwork.php'; |
||||
``` |
||||
|
||||
### Sending a message |
||||
|
||||
```php |
||||
$clockwork = new Clockwork( $API_KEY ); |
||||
$message = array( 'to' => '441234567891', 'message' => 'This is a test!' ); |
||||
$result = $clockwork->send( $message ); |
||||
``` |
||||
|
||||
### Sending multiple messages |
||||
|
||||
We recommend you use batch sizes of 500 messages or fewer. By limiting the batch size it prevents any timeouts when sending. |
||||
|
||||
```php |
||||
$clockwork = new Clockwork( $API_KEY ); |
||||
$messages = array( |
||||
array( 'to' => '441234567891', 'message' => 'This is a test!' ), |
||||
array( 'to' => '441234567892', 'message' => 'This is a test 2!' ) |
||||
); |
||||
$results = $clockwork->send( $messages ); |
||||
``` |
||||
|
||||
### Handling the response |
||||
|
||||
The responses come back as arrays, these contain the unique Clockwork message ID, whether the message worked (`success`), and the original SMS so you can update your database. |
||||
|
||||
Array |
||||
( |
||||
[id] => VE_164732148 |
||||
[success] => 1 |
||||
[sms] => Array |
||||
( |
||||
[to] => 441234567891 |
||||
[message] => This is a test! |
||||
) |
||||
|
||||
) |
||||
|
||||
If you send multiple SMS messages in a single send, you'll get back an array of results, one per SMS. |
||||
|
||||
The result will look something like this: |
||||
|
||||
Array |
||||
( |
||||
[0] => Array |
||||
( |
||||
[id] => VI_143228951 |
||||
[success] => 1 |
||||
[sms] => Array |
||||
( |
||||
[to] => 441234567891 |
||||
[message] => This is a test! |
||||
) |
||||
|
||||
) |
||||
|
||||
[1] => Array |
||||
( |
||||
[id] => VI_143228952 |
||||
[success] => 1 |
||||
[sms] => Array |
||||
( |
||||
[to] => 441234567892 |
||||
[message] => This is a test 2! |
||||
) |
||||
|
||||
) |
||||
|
||||
) |
||||
|
||||
If a message fails, the reason for failure will be set in `error_code` and `error_message`. |
||||
|
||||
For example, if you send to invalid phone number "abc": |
||||
|
||||
Array |
||||
( |
||||
[error_code] => 10 |
||||
[error_message] => Invalid 'To' Parameter |
||||
[success] => 0 |
||||
[sms] => Array |
||||
( |
||||
[to] => abc |
||||
[message] => This is a test! |
||||
) |
||||
|
||||
) |
||||
|
||||
### Checking your balance |
||||
|
||||
Check your available SMS balance: |
||||
|
||||
```php |
||||
$clockwork = new Clockwork( $API_KEY ); |
||||
$clockwork->checkBalance(); |
||||
``` |
||||
|
||||
This will return: |
||||
|
||||
Array |
||||
( |
||||
[symbol] => £ |
||||
[balance] => 351.91 |
||||
[code] => GBP |
||||
) |
||||
|
||||
### Handling Errors |
||||
|
||||
The Clockwork wrapper will throw a `ClockworkException` if the entire call failed. |
||||
|
||||
```php |
||||
try |
||||
{ |
||||
$clockwork = new Clockwork( 'invalid_key' ); |
||||
$message = array( 'to' => 'abc', 'message' => 'This is a test!' ); |
||||
$result = $clockwork->send( $message ); |
||||
} |
||||
catch( ClockworkException $e ) |
||||
{ |
||||
print $e->getMessage(); |
||||
// Invalid API Key |
||||
} |
||||
``` |
||||
|
||||
### Advanced Usage |
||||
|
||||
This class has a few additional features that some users may find useful, if these are not set your account defaults will be used. |
||||
|
||||
### Optional Parameters |
||||
|
||||
See the [Clockwork Documentation](http://www.clockworksms.com/doc/clever-stuff/xml-interface/send-sms/) for full details on these options. |
||||
|
||||
* $from [string] |
||||
|
||||
The from address displayed on a phone when they receive a message |
||||
|
||||
* $long [boolean] |
||||
|
||||
Enable long SMS. A standard text can contain 160 characters, a long SMS supports up to 459. |
||||
|
||||
* $truncate [nullable boolean] |
||||
|
||||
Truncate the message payload if it is too long, if this is set to false, the message will fail if it is too long. |
||||
|
||||
* $invalid_char_action [string] |
||||
|
||||
What to do if the message contains an invalid character. Possible values are |
||||
* error - Fail the message |
||||
* remove - Remove the invalid characters then send |
||||
* replace - Replace some common invalid characters such as replacing curved quotes with straight quotes |
||||
|
||||
* $ssl [boolean, default: true] |
||||
|
||||
Use SSL when making an HTTP request to the Clockwork API |
||||
|
||||
|
||||
### Setting Options |
||||
|
||||
#### Global Options |
||||
|
||||
Options set on the API object will apply to all SMS messages unless specifically overridden. |
||||
|
||||
In this example both messages will be sent from Clockwork: |
||||
|
||||
```php |
||||
$options = array( 'from' => 'Clockwork' ); |
||||
$clockwork = new Clockwork( $API_KEY, $options ); |
||||
$messages = array( |
||||
array( 'to' => '441234567891', 'message' => 'This is a test!' ), |
||||
array( 'to' => '441234567892', 'message' => 'This is a test 2!' ) |
||||
); |
||||
$results = $clockwork->send( $messages ); |
||||
``` |
||||
|
||||
#### Per-message Options |
||||
|
||||
Set option values individually on each message. |
||||
|
||||
In this example, one message will be from Clockwork and the other from 84433: |
||||
|
||||
```php |
||||
$clockwork = new Clockwork( $API_KEY, $options ); |
||||
$messages = array( |
||||
array( 'to' => '441234567891', 'message' => 'This is a test!', 'from' => 'Clockwork' ), |
||||
array( 'to' => '441234567892', 'message' => 'This is a test 2!', 'from' => '84433' ) |
||||
); |
||||
$results = $clockwork->send( $messages ); |
||||
``` |
||||
|
||||
### SSL Errors |
||||
|
||||
Due to the huge variety of PHP setups out there a small proportion of users may get PHP errors when making API calls due to their SSL configuration. |
||||
|
||||
The errors will generally look something like this: |
||||
|
||||
``` |
||||
Fatal error: |
||||
Uncaught exception 'Exception' with message 'HTTP Error calling Clockwork API |
||||
HTTP Status: 0 |
||||
cURL Erorr: SSL certificate problem, verify that the CA cert is OK. |
||||
Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed' |
||||
``` |
||||
|
||||
If you're seeing this error there are two fixes available, the first is easy, simply disable SSL on Clockwork calls. Alternatively you can setup your PHP install with the correct root certificates. |
||||
|
||||
#### Disable SSL on Clockwork calls |
||||
|
||||
```php |
||||
$options = array( 'ssl' => false ); |
||||
$clockwork = new Clockwork( $API_KEY, $options ); |
||||
``` |
||||
|
||||
#### Setup SSL root certificates on your server |
||||
|
||||
This is much more complicated as it depends on your setup, however there are many guides available online. |
||||
Try a search term like "windows php curl root certificates" or "ubuntu update root certificates". |
||||
|
||||
|
||||
# License |
||||
|
||||
This project is licensed under the ISC open-source license. |
||||
|
||||
A copy of this license can be found in license.txt. |
||||
|
||||
# Contributing |
||||
|
||||
If you have any feedback on this wrapper drop us an email to [hello@clockworksms.com][1]. |
||||
|
||||
The project is hosted on GitHub at [https://github.com/mediaburst/clockwork-php][3]. |
||||
If you would like to contribute a bug fix or improvement please fork the project |
||||
and submit a pull request. |
||||
|
||||
[1]: mailto:hello@clockworksms.com |
||||
[2]: http://www.clockworksms.com/ |
||||
[3]: https://github.com/mediaburst/clockwork-php |
@ -0,0 +1,253 @@ |
||||
# Clockwork SMS API Wrapper for PHP |
||||
|
||||
This wrapper lets you interact with Clockwork without the hassle of having to create any XML or make HTTP calls. |
||||
|
||||
## What's Clockwork? |
||||
|
||||
[Clockwork][2] is Mediaburst's SMS API. |
||||
|
||||
### Prerequisites |
||||
|
||||
* A [Clockwork][2] account |
||||
|
||||
## Usage |
||||
|
||||
Require the Clockwork library: |
||||
|
||||
```php |
||||
require 'class-Clockwork.php'; |
||||
``` |
||||
|
||||
### Sending a message |
||||
|
||||
```php |
||||
$clockwork = new Clockwork( $API_KEY ); |
||||
$message = array( 'to' => '441234567891', 'message' => 'This is a test!' ); |
||||
$result = $clockwork->send( $message ); |
||||
``` |
||||
|
||||
### Sending multiple messages |
||||
|
||||
We recommend you use batch sizes of 500 messages or fewer. By limiting the batch size it prevents any timeouts when sending. |
||||
|
||||
```php |
||||
$clockwork = new Clockwork( $API_KEY ); |
||||
$messages = array( |
||||
array( 'to' => '441234567891', 'message' => 'This is a test!' ), |
||||
array( 'to' => '441234567892', 'message' => 'This is a test 2!' ) |
||||
); |
||||
$results = $clockwork->send( $messages ); |
||||
``` |
||||
|
||||
### Handling the response |
||||
|
||||
The responses come back as arrays, these contain the unique Clockwork message ID, whether the message worked (`success`), and the original SMS so you can update your database. |
||||
|
||||
Array |
||||
( |
||||
[id] => VE_164732148 |
||||
[success] => 1 |
||||
[sms] => Array |
||||
( |
||||
[to] => 441234567891 |
||||
[message] => This is a test! |
||||
) |
||||
|
||||
) |
||||
|
||||
If you send multiple SMS messages in a single send, you'll get back an array of results, one per SMS. |
||||
|
||||
The result will look something like this: |
||||
|
||||
Array |
||||
( |
||||
[0] => Array |
||||
( |
||||
[id] => VI_143228951 |
||||
[success] => 1 |
||||
[sms] => Array |
||||
( |
||||
[to] => 441234567891 |
||||
[message] => This is a test! |
||||
) |
||||
|
||||
) |
||||
|
||||
[1] => Array |
||||
( |
||||
[id] => VI_143228952 |
||||
[success] => 1 |
||||
[sms] => Array |
||||
( |
||||
[to] => 441234567892 |
||||
[message] => This is a test 2! |
||||
) |
||||
|
||||
) |
||||
|
||||
) |
||||
|
||||
If a message fails, the reason for failure will be set in `error_code` and `error_message`. |
||||
|
||||
For example, if you send to invalid phone number "abc": |
||||
|
||||
Array |
||||
( |
||||
[error_code] => 10 |
||||
[error_message] => Invalid 'To' Parameter |
||||
[success] => 0 |
||||
[sms] => Array |
||||
( |
||||
[to] => abc |
||||
[message] => This is a test! |
||||
) |
||||
|
||||
) |
||||
|
||||
### Checking your balance |
||||
|
||||
Check your available SMS balance: |
||||
|
||||
```php |
||||
$clockwork = new Clockwork( $API_KEY ); |
||||
$clockwork->checkBalance(); |
||||
``` |
||||
|
||||
This will return: |
||||
|
||||
Array |
||||
( |
||||
[symbol] => £ |
||||
[balance] => 351.91 |
||||
[code] => GBP |
||||
) |
||||
|
||||
### Handling Errors |
||||
|
||||
The Clockwork wrapper will throw a `ClockworkException` if the entire call failed. |
||||
|
||||
```php |
||||
try |
||||
{ |
||||
$clockwork = new Clockwork( 'invalid_key' ); |
||||
$message = array( 'to' => 'abc', 'message' => 'This is a test!' ); |
||||
$result = $clockwork->send( $message ); |
||||
} |
||||
catch( ClockworkException $e ) |
||||
{ |
||||
print $e->getMessage(); |
||||
// Invalid API Key |
||||
} |
||||
``` |
||||
|
||||
### Advanced Usage |
||||
|
||||
This class has a few additional features that some users may find useful, if these are not set your account defaults will be used. |
||||
|
||||
### Optional Parameters |
||||
|
||||
See the [Clockwork Documentation](http://www.clockworksms.com/doc/clever-stuff/xml-interface/send-sms/) for full details on these options. |
||||
|
||||
* $from [string] |
||||
|
||||
The from address displayed on a phone when they receive a message |
||||
|
||||
* $long [boolean] |
||||
|
||||
Enable long SMS. A standard text can contain 160 characters, a long SMS supports up to 459. |
||||
|
||||
* $truncate [nullable boolean] |
||||
|
||||
Truncate the message payload if it is too long, if this is set to false, the message will fail if it is too long. |
||||
|
||||
* $invalid_char_action [string] |
||||
|
||||
What to do if the message contains an invalid character. Possible values are |
||||
* error - Fail the message |
||||
* remove - Remove the invalid characters then send |
||||
* replace - Replace some common invalid characters such as replacing curved quotes with straight quotes |
||||
|
||||
* $ssl [boolean, default: true] |
||||
|
||||
Use SSL when making an HTTP request to the Clockwork API |
||||
|
||||
|
||||
### Setting Options |
||||
|
||||
#### Global Options |
||||
|
||||
Options set on the API object will apply to all SMS messages unless specifically overridden. |
||||
|
||||
In this example both messages will be sent from Clockwork: |
||||
|
||||
```php |
||||
$options = array( 'from' => 'Clockwork' ); |
||||
$clockwork = new Clockwork( $API_KEY, $options ); |
||||
$messages = array( |
||||
array( 'to' => '441234567891', 'message' => 'This is a test!' ), |
||||
array( 'to' => '441234567892', 'message' => 'This is a test 2!' ) |
||||
); |
||||
$results = $clockwork->send( $messages ); |
||||
``` |
||||
|
||||
#### Per-message Options |
||||
|
||||
Set option values individually on each message. |
||||
|
||||
In this example, one message will be from Clockwork and the other from 84433: |
||||
|
||||
```php |
||||
$clockwork = new Clockwork( $API_KEY, $options ); |
||||
$messages = array( |
||||
array( 'to' => '441234567891', 'message' => 'This is a test!', 'from' => 'Clockwork' ), |
||||
array( 'to' => '441234567892', 'message' => 'This is a test 2!', 'from' => '84433' ) |
||||
); |
||||
$results = $clockwork->send( $messages ); |
||||
``` |
||||
|
||||
### SSL Errors |
||||
|
||||
Due to the huge variety of PHP setups out there a small proportion of users may get PHP errors when making API calls due to their SSL configuration. |
||||
|
||||
The errors will generally look something like this: |
||||
|
||||
``` |
||||
Fatal error: |
||||
Uncaught exception 'Exception' with message 'HTTP Error calling Clockwork API |
||||
HTTP Status: 0 |
||||
cURL Erorr: SSL certificate problem, verify that the CA cert is OK. |
||||
Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed' |
||||
``` |
||||
|
||||
If you're seeing this error there are two fixes available, the first is easy, simply disable SSL on Clockwork calls. Alternatively you can setup your PHP install with the correct root certificates. |
||||
|
||||
#### Disable SSL on Clockwork calls |
||||
|
||||
```php |
||||
$options = array( 'ssl' => false ); |
||||
$clockwork = new Clockwork( $API_KEY, $options ); |
||||
``` |
||||
|
||||
#### Setup SSL root certificates on your server |
||||
|
||||
This is much more complicated as it depends on your setup, however there are many guides available online. |
||||
Try a search term like "windows php curl root certificates" or "ubuntu update root certificates". |
||||
|
||||
|
||||
# License |
||||
|
||||
This project is licensed under the ISC open-source license. |
||||
|
||||
A copy of this license can be found in license.txt. |
||||
|
||||
# Contributing |
||||
|
||||
If you have any feedback on this wrapper drop us an email to [hello@clockworksms.com][1]. |
||||
|
||||
The project is hosted on GitHub at [https://github.com/mediaburst/clockwork-php][3]. |
||||
If you would like to contribute a bug fix or improvement please fork the project |
||||
and submit a pull request. |
||||
|
||||
[1]: mailto:hello@clockworksms.com |
||||
[2]: http://www.clockworksms.com/ |
||||
[3]: https://github.com/mediaburst/clockwork-php |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1 @@ |
||||
{{ message }} |
@ -0,0 +1,13 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* This script is included by main/admin/settings.lib.php when unselecting a plugin |
||||
* and is meant to remove things installed by the install.php script in both |
||||
* the global database and the courses tables |
||||
* @package chamilo.plugin.clockworksms |
||||
*/ |
||||
/** |
||||
* Queries |
||||
*/ |
||||
require_once dirname(__FILE__).'/config.php'; |
||||
ClockworksmsPlugin::create()->uninstall(); |
Loading…
Reference in new issue