From e92bc4049ccbbd4b692626773170d70156cbebca Mon Sep 17 00:00:00 2001 From: Deepak Srivastava Date: Fri, 22 Aug 2014 18:16:35 +0100 Subject: [PATCH] pull clickatell extension out of core (to veda repo) --- .../clickatell.civix.php | 155 ------ .../org.civicrm.sms.clickatell/clickatell.php | 115 ----- .../org.civicrm.sms.clickatell/info.xml | 25 - .../org_civicrm_sms_clickatell.php | 465 ------------------ 4 files changed, 760 deletions(-) delete mode 100644 tools/extensions/org.civicrm.sms.clickatell/clickatell.civix.php delete mode 100644 tools/extensions/org.civicrm.sms.clickatell/clickatell.php delete mode 100644 tools/extensions/org.civicrm.sms.clickatell/info.xml delete mode 100644 tools/extensions/org.civicrm.sms.clickatell/org_civicrm_sms_clickatell.php diff --git a/tools/extensions/org.civicrm.sms.clickatell/clickatell.civix.php b/tools/extensions/org.civicrm.sms.clickatell/clickatell.civix.php deleted file mode 100644 index d68aadb024..0000000000 --- a/tools/extensions/org.civicrm.sms.clickatell/clickatell.civix.php +++ /dev/null @@ -1,155 +0,0 @@ -template_dir ) ) { - array_unshift( $template->template_dir, $extDir ); - } else { - $template->template_dir = array( $extDir, $template->template_dir ); - } - - $include_path = $extRoot . PATH_SEPARATOR . get_include_path( ); - set_include_path( $include_path ); -} - -/** - * (Delegated) Implementation of hook_civicrm_xmlMenu - * - * @param $files array(string) - */ -function _clickatell_civix_civicrm_xmlMenu(&$files) { - foreach (glob(__DIR__ . '/xml/Menu/*.xml') as $file) { - $files[] = $file; - } -} - -/** - * Implementation of hook_civicrm_install - */ -function _clickatell_civix_civicrm_install() { - _clickatell_civix_civicrm_config(); - if ($upgrader = _clickatell_civix_upgrader()) { - return $upgrader->onInstall(); - } -} - -/** - * Implementation of hook_civicrm_uninstall - */ -function _clickatell_civix_civicrm_uninstall() { - _clickatell_civix_civicrm_config(); - if ($upgrader = _clickatell_civix_upgrader()) { - return $upgrader->onUninstall(); - } -} - -/** - * (Delegated) Implementation of hook_civicrm_enable - */ -function _clickatell_civix_civicrm_enable() { - _clickatell_civix_civicrm_config(); - if ($upgrader = _clickatell_civix_upgrader()) { - if (is_callable(array($upgrader, 'onEnable'))) { - return $upgrader->onEnable(); - } - } -} - -/** - * (Delegated) Implementation of hook_civicrm_disable - */ -function _clickatell_civix_civicrm_disable() { - _clickatell_civix_civicrm_config(); - if ($upgrader = _clickatell_civix_upgrader()) { - if (is_callable(array($upgrader, 'onDisable'))) { - return $upgrader->onDisable(); - } - } -} - -/** - * (Delegated) Implementation of hook_civicrm_upgrade - * - * @param $op string, the type of operation being performed; 'check' or 'enqueue' - * @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks - * - * @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending) - * for 'enqueue', returns void - */ -function _clickatell_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) { - if ($upgrader = _clickatell_civix_upgrader()) { - return $upgrader->onUpgrade($op, $queue); - } -} - -/** - * @return null - */ -function _clickatell_civix_upgrader() { - if (!file_exists(__DIR__.'/CRM/Clickatell/Upgrader.php')) { - return NULL; - } else { - return CRM_Clickatell_Upgrader_Base::instance(); - } -} - -/** - * Search directory tree for files which match a glob pattern - * - * @param $dir string, base dir - * @param $pattern string, glob pattern, eg "*.txt" - * @return array(string) - */ -function _clickatell_civix_find_files($dir, $pattern) { - $todos = array($dir); - $result = array(); - while (!empty($todos)) { - $subdir = array_shift($todos); - foreach (glob("$subdir/$pattern") as $match) { - if (!is_dir($match)) { - $result[] = $match; - } - } - if ($dh = opendir($subdir)) { - while (FALSE !== ($entry = readdir($dh))) { - $path = $subdir . DIRECTORY_SEPARATOR . $entry; - if ($entry == '.' || $entry == '..') { - } elseif (is_dir($path)) { - $todos[] = $path; - } - } - closedir($dh); - } - } - return $result; -} -/** - * (Delegated) Implementation of hook_civicrm_managed - * - * Find any *.mgd.php files, merge their content, and return. - */ -function _clickatell_civix_civicrm_managed(&$entities) { - $mgdFiles = _clickatell_civix_find_files(__DIR__, '*.mgd.php'); - foreach ($mgdFiles as $file) { - $es = include $file; - foreach ($es as $e) { - if (empty($e['module'])) { - $e['module'] = 'org.civicrm.sms.clickatell'; - } - $entities[] = $e; - } - } -} diff --git a/tools/extensions/org.civicrm.sms.clickatell/clickatell.php b/tools/extensions/org.civicrm.sms.clickatell/clickatell.php deleted file mode 100644 index 1ee37b1b85..0000000000 --- a/tools/extensions/org.civicrm.sms.clickatell/clickatell.php +++ /dev/null @@ -1,115 +0,0 @@ - $groupID, - 'label' => 'Clickatell', - 'value' => 'org.civicrm.sms.clickatell', - 'name' => 'clickatell', - 'is_default' => 1, - 'is_active' => 1, - 'version' => 3,); - require_once 'api/api.php'; - civicrm_api( 'option_value','create', $params ); - - return _clickatell_civix_civicrm_install(); -} - -/** - * Implementation of hook_civicrm_uninstall - */ -function clickatell_civicrm_uninstall() { - $optionID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue','clickatell','id','name'); - if ($optionID) - CRM_Core_BAO_OptionValue::del($optionID); - - $filter = array('name' => 'org.civicrm.sms.clickatell'); - $Providers = CRM_SMS_BAO_Provider::getProviders(False, $filter, False); - if ($Providers){ - foreach($Providers as $key => $value){ - CRM_SMS_BAO_Provider::del($value['id']); - } - } - return _clickatell_civix_civicrm_uninstall(); -} - -/** - * Implementation of hook_civicrm_enable - */ -function clickatell_civicrm_enable() { - $optionID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue','clickatell' ,'id','name'); - if ($optionID) - CRM_Core_BAO_OptionValue::setIsActive($optionID, TRUE); - - $filter = array('name' => 'org.civicrm.sms.clickatell'); - $Providers = CRM_SMS_BAO_Provider::getProviders(False, $filter, False); - if ($Providers){ - foreach($Providers as $key => $value){ - CRM_SMS_BAO_Provider::setIsActive($value['id'], TRUE); - } - } - return _clickatell_civix_civicrm_enable(); -} - -/** - * Implementation of hook_civicrm_disable - */ -function clickatell_civicrm_disable() { - $optionID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue','clickatell','id','name'); - if ($optionID) - CRM_Core_BAO_OptionValue::setIsActive($optionID, FALSE); - - $filter = array('name' => 'org.civicrm.sms.clickatell'); - $Providers = CRM_SMS_BAO_Provider::getProviders(False, $filter, False); - if ($Providers){ - foreach($Providers as $key => $value){ - CRM_SMS_BAO_Provider::setIsActive($value['id'], FALSE); - } - } - return _clickatell_civix_civicrm_disable(); -} - -/** - * Implementation of hook_civicrm_upgrade - * - * @param $op string, the type of operation being performed; 'check' or 'enqueue' - * @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks - * - * @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending) - * for 'enqueue', returns void - */ -function clickatell_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) { - return _clickatell_civix_civicrm_upgrade($op, $queue); -} - -/** - * Implementation of hook_civicrm_managed - * - * Generate a list of entities to create/deactivate/delete when this module - * is installed, disabled, uninstalled. - */ -function clickatell_civicrm_managed(&$entities) { - return _clickatell_civix_civicrm_managed($entities); -} diff --git a/tools/extensions/org.civicrm.sms.clickatell/info.xml b/tools/extensions/org.civicrm.sms.clickatell/info.xml deleted file mode 100644 index 944b0d44a5..0000000000 --- a/tools/extensions/org.civicrm.sms.clickatell/info.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - https://github.com/civicrm/civicrm-core/blob/4.3/tools/extensions/org.civicrm.sms.clickatell.zip?raw=true - clickatell - clickatell - Clickatell integration allows delivering short message service (SMS) messages through its Clickatell Gateway to mobile phone users. - - http://civicrm.org - http://wiki.civicrm.org/confluence/display/CRMDOC/Setting+up+a+SMS+Provider+for+CiviSMS - http://forum.civicrm.org - http://civicrm.org/licensing - - AGPL - - CiviCRM LLC - info@civicrm.org - - 2012-11-15 - 1.0 - stable - - 4.3 - - For support, please contact project team on the forums. - diff --git a/tools/extensions/org.civicrm.sms.clickatell/org_civicrm_sms_clickatell.php b/tools/extensions/org.civicrm.sms.clickatell/org_civicrm_sms_clickatell.php deleted file mode 100644 index 926d159c91..0000000000 --- a/tools/extensions/org.civicrm.sms.clickatell/org_civicrm_sms_clickatell.php +++ /dev/null @@ -1,465 +0,0 @@ - 'Message unknown', - '002' => 'Message queued', - '003' => 'Delivered', - '004' => 'Received by recipient', - '005' => 'Error with message', - '006' => 'User cancelled message delivery', - '007' => 'Error delivering message', - '008' => 'OK', - '009' => 'Routing error', - '010' => 'Message expired', - '011' => 'Message queued for later delivery', - '012' => 'Out of credit', - ); - - /** - * We only need one instance of this object. So we use the singleton - * pattern and cache the instance in this variable - * - * @var object - * @static - */ - static private $_singleton = array(); - - /** - * Constructor - * - * Create and auth a Clickatell session. - * - * @param array $provider - * @param bool $skipAuth - * - * @return \org_civicrm_sms_clickatell - */ - function __construct($provider = array( ), $skipAuth = FALSE) { - // initialize vars - $this->_apiType = CRM_Utils_Array::value('api_type', $provider, 'http'); - $this->_providerInfo = $provider; - - if ($skipAuth) { - return TRUE; - } - - // first create the curl handle - - /** - * Reuse the curl handle - */ - $this->_ch = curl_init(); - if (!$this->_ch || !is_resource($this->_ch)) { - return PEAR::raiseError('Cannot initialise a new curl handle.'); - } - - curl_setopt($this->_ch, CURLOPT_TIMEOUT, 20); - curl_setopt($this->_ch, CURLOPT_VERBOSE, 1); - curl_setopt($this->_ch, CURLOPT_FAILONERROR, 1); - if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off') { - curl_setopt($this->_ch, CURLOPT_FOLLOWLOCATION, 1); - } - curl_setopt($this->_ch, CURLOPT_COOKIEJAR, "/dev/null"); - curl_setopt($this->_ch, CURLOPT_SSL_VERIFYHOST, 2); - curl_setopt($this->_ch, CURLOPT_USERAGENT, 'CiviCRM - http://civicrm.org/'); - - $this->authenticate(); - } - - /** - * singleton function used to manage this object - * - * @param array $providerParams - * @param bool $force - * @return object - * @static - */ - static function &singleton($providerParams = array( - ), $force = FALSE) { - $providerID = CRM_Utils_Array::value('provider_id', $providerParams); - $skipAuth = $providerID ? FALSE : TRUE; - $cacheKey = (int) $providerID; - - if (!isset(self::$_singleton[$cacheKey]) || $force) { - $provider = array(); - if ($providerID) { - $provider = CRM_SMS_BAO_Provider::getProviderInfo($providerID); - } - self::$_singleton[$cacheKey] = new org_civicrm_sms_clickatell($provider, $skipAuth); - } - return self::$_singleton[$cacheKey]; - } - - /** - * Authenticate to the Clickatell API Server. - * - * @return mixed true on sucess or PEAR_Error object - * @access public - * @since 1.1 - */ - function authenticate() { - $url = $this->_providerInfo['api_url'] . "/http/auth"; - - $postDataArray = array( - 'user' => $this->_providerInfo['username'], - 'password' => $this->_providerInfo['password'], - 'api_id' => $this->_providerInfo['api_params']['api_id'] - ); - - if (array_key_exists('is_test', $this->_providerInfo['api_params']) && - $this->_providerInfo['api_params']['is_test'] == 1 ) { - $response = array('data' => 'OK:' . rand()); - } else { - $postData = $this->urlEncode($postDataArray); - $response = $this->curl($url, $postData); - } - if (PEAR::isError($response)) { - return $response; - } - $sess = explode(":", $response['data']); - - $this->_sessionID = trim($sess[1]); - - if ($sess[0] == "OK") { - return TRUE; - } - else { - return PEAR::raiseError($response['data']); - } - } - - /** - * @param $url - * @param $postDataArray - * @param null $id - * - * @return object|string - */ - function formURLPostData($url, &$postDataArray, $id = NULL) { - $url = $this->_providerInfo['api_url'] . $url; - $postDataArray['session_id'] = $this->_sessionID; - if ($id) { - if (strlen($id) < 32 || strlen($id) > 32) { - return PEAR::raiseError('Invalid API Message Id'); - } - $postDataArray['apimsgid'] = $id; - } - return $url; - } - - /** - * Send an SMS Message via the Clickatell API Server - * - * @param $recipients - * @param $header - * @param $message - * @param null $jobID - * @param null $userID - * @internal param \the $array message with a to/from/text - * - * @return mixed true on sucess or PEAR_Error object - * @access public - */ - function send($recipients, $header, $message, $jobID = NULL, $userID = NULL) { - if ($this->_apiType == 'http') { - $postDataArray = array( ); - $url = $this->formURLPostData("/http/sendmsg", $postDataArray); - - if (array_key_exists('from', $this->_providerInfo['api_params'])) { - $postDataArray['from'] = $this->_providerInfo['api_params']['from']; - } - if (array_key_exists('concat', $this->_providerInfo['api_params'])) { - $postDataArray['concat'] = $this->_providerInfo['api_params']['concat']; - } - //TODO: - $postDataArray['to'] = $header['To']; - $postDataArray['text'] = utf8_decode(substr($message, 0, 460)); // max of 460 characters, is probably not multi-lingual - if (array_key_exists('mo', $this->_providerInfo['api_params'])) { - $postDataArray['mo'] = $this->_providerInfo['api_params']['mo']; - } - // sendmsg with callback request: - $postDataArray['callback'] = 3; - - $isTest = 0; - if (array_key_exists('is_test', $this->_providerInfo['api_params']) && - $this->_providerInfo['api_params']['is_test'] == 1 - ) { - $isTest = 1; - } - - /** - * Check if we are using a queue when sending as each account - * with Clickatell is assigned three queues namely 1, 2 and 3. - */ - if (isset($header['queue']) && is_numeric($header['queue'])) { - if (in_array($header['queue'], range(1, 3))) { - $postDataArray['queue'] = $header['queue']; - } - } - - /** - * Must we escalate message delivery if message is stuck in - * the queue at Clickatell? - */ - if (isset($header['escalate']) && !empty($header['escalate'])) { - if (is_numeric($header['escalate'])) { - if (in_array($header['escalate'], range(1, 2))) { - $postDataArray['escalate'] = $header['escalate']; - } - } - } - - if ($isTest == 1) { - $response = array('data' => 'ID:' . rand()); - } - else { - $postData = $this->urlEncode($postDataArray); - $response = $this->curl($url, $postData); - } - if (PEAR::isError($response)) { - return $response; - } - $send = explode(":", $response['data']); - - if ($send[0] == "ID") { - $this->createActivity($send[1], $message, $header, $jobID, $userID); - return $send[1]; - } - else { - // TODO: Should add a failed activity instead. - CRM_Core_Error::debug_log_message($response['data'] . " - for phone: {$postDataArray['to']}"); - return PEAR::raiseError($response['data'], null, PEAR_ERROR_RETURN); - } - } - } - - /** - * @return bool - */ - function callback() { - $apiMsgID = $this->retrieve('apiMsgId', 'String'); - - $activity = new CRM_Activity_DAO_Activity(); - $activity->result = $apiMsgID; - - if ($activity->find(TRUE)) { - $actStatusIDs = array_flip(CRM_Core_OptionGroup::values('activity_status')); - - $status = $this->retrieve('status', 'String'); - switch ($status) { - case "001": - $statusID = $actStatusIDs['Cancelled']; - $clickStat = $this->_messageStatus[$status] . " - Message Unknown"; - break; - - case "002": - $statusID = $actStatusIDs['Scheduled']; - $clickStat = $this->_messageStatus[$status] . " - Message Queued"; - break; - - case "003": - $statusID = $actStatusIDs['Completed']; - $clickStat = $this->_messageStatus[$status] . " - Delivered to Gateway"; - break; - - case "004": - $statusID = $actStatusIDs['Completed']; - $clickStat = $this->_messageStatus[$status] . " - Received by Recipient"; - break; - - case "005": - $statusID = $actStatusIDs['Cancelled']; - $clickStat = $this->_messageStatus[$status] . " - Error with Message"; - break; - - case "006": - $statusID = $actStatusIDs['Cancelled']; - $clickStat = $this->_messageStatus[$status] . " - User cancelled message"; - break; - - case "007": - $statusID = $actStatusIDs['Cancelled']; - $clickStat = $this->_messageStatus[$status] . " - Error delivering message"; - break; - - case "008": - $statusID = $actStatusIDs['Completed']; - $clickStat = $this->_messageStatus[$status] . " - Ok, Message Received by Gateway"; - break; - - case "009": - $statusID = $actStatusIDs['Cancelled']; - $clickStat = $this->_messageStatus[$status] . " - Routing Error"; - break; - - case "010": - $statusID = $actStatusIDs['Cancelled']; - $clickStat = $this->_messageStatus[$status] . " - Message Expired"; - break; - - case "011": - $statusID = $actStatusIDs['Scheduled']; - $clickStat = $this->_messageStatus[$status] . " - Message Queued for Later"; - break; - - case "012": - $statusID = $actStatusIDs['Cancelled']; - $clickStat = $this->_messageStatus[$status] . " - Out of Credit"; - break; - } - - if ($statusID) { - // update activity with status + msg in location - $activity->status_id = $statusID; - $activity->location = $clickStat; - $activity->activity_date_time = CRM_Utils_Date::isoToMysql($activity->activity_date_time); - $activity->save(); - CRM_Core_Error::debug_log_message("SMS Response updated for apiMsgId={$apiMsgID}."); - return TRUE; - } - } - - // if no update is done - CRM_Core_Error::debug_log_message("Could not update SMS Response for apiMsgId={$apiMsgID}."); - return FALSE; - } - - /** - * @return $this|null|object - */ - function inbound() { - $like = ""; - $fromPhone = $this->retrieve('from', 'String'); - $fromPhone = $this->formatPhone($this->stripPhone($fromPhone), $like, "like"); - - return parent::processInbound($fromPhone, $this->retrieve('text', 'String'), NULL, $this->retrieve('moMsgId', 'String')); - } - - /** - * Perform curl stuff - * - * @param string URL to call - * @param string HTTP Post Data - * - * @return mixed HTTP response body or PEAR Error Object - * @access private - */ - function curl($url, $postData) { - $this->_fp = tmpfile(); - - curl_setopt($this->_ch, CURLOPT_URL, $url); - curl_setopt($this->_ch, CURLOPT_POST, 1); - curl_setopt($this->_ch, CURLOPT_POSTFIELDS, $postData); - curl_setopt($this->_ch, CURLOPT_FILE, $this->_fp); - - $status = curl_exec($this->_ch); - $response['http_code'] = curl_getinfo($this->_ch, CURLINFO_HTTP_CODE); - - if (empty($response['http_code'])) { - return PEAR::raiseError('No HTTP Status Code was returned.'); - } - elseif ($response['http_code'] === 0) { - return PEAR::raiseError('Cannot connect to the Clickatell API Server.'); - } - - if ($status) { - $response['error'] = curl_error($this->_ch); - $response['errno'] = curl_errno($this->_ch); - } - - rewind($this->_fp); - - $pairs = ""; - while ($str = fgets($this->_fp, 4096)) { - $pairs .= $str; - } - fclose($this->_fp); - - $response['data'] = $pairs; - unset($pairs); - asort($response); - - return ($response); - } -} - -- 2.25.1