View source
<?php
define('SMS_USER_BLOCKED', 0);
define('SMS_USER_PENDING', 1);
define('SMS_USER_CONFIRMED', 2);
define('SMS_USER_SMS_REGISTERED', 3);
define('SMS_USER_MAX_CHARS', 140);
require_once 'sms_user.actions.inc';
require_once 'sms_user.rules.inc';
function sms_user_permission() {
return array(
'receive sms' => array(
'title' => t('receive sms'),
'description' => t('Receive SMS from the site.'),
),
'edit own sms number' => array(
'title' => t('edit own sms number'),
'description' => t('Edit own SMS number.'),
),
);
}
function sms_user_menu() {
$items = array();
$items['admin/smsframework/sms_user_options'] = array(
'title' => 'SMS User Options',
'description' => 'Edit options for SMS and user integration.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'sms_user_admin_settings',
),
'access arguments' => array(
'administer smsframework',
),
'file' => 'sms_user.admin.inc',
);
return $items;
}
function sms_user_menu_alter(&$callbacks) {
$callbacks['user/%user_category/edit/mobile']['page callback'] = 'sms_user_settings';
$callbacks['user/%user_category/edit/mobile']['page arguments'] = array(
1,
);
$callbacks['user/%user_category/edit/mobile']['module'] = 'sms_user';
$callbacks['user/%user_category/edit/mobile']['file'] = 'sms_user.module';
}
function sms_user_edit_access($account) {
return user_edit_access($account) && user_access('receive sms', $account);
}
function sms_user_send($uid, $message) {
$account = user_load($uid);
if (user_access('receive sms', $account)) {
if ($account->sms_user['status'] >= SMS_USER_CONFIRMED) {
return sms_send($account->sms_user['number'], $message, $account->sms_user['gateway']);
}
else {
watchdog('sms_user', "User %user has not validated mobile number", array(
'%user' => $account->name,
), WATCHDOG_ALERT);
return FALSE;
}
}
else {
watchdog('sms_user', "User %user is not enabled to receive SMS, see 'receive sms' permission", array(
'%user' => $account->name,
), WATCHDOG_ALERT);
}
}
function sms_user_get_number($account) {
if (user_access('receive sms', $account)) {
if ($account->sms_user['status'] >= SMS_USER_CONFIRMED) {
return $account->sms_user['number'];
}
else {
return FALSE;
}
}
return FALSE;
}
function sms_user_get_uid($number, $status = NULL) {
$query = db_select('sms_user', 'u')
->fields('u', array(
'uid',
))
->condition('number', $number);
if (isset($status)) {
$query
->condition('status', $status);
}
return $query
->execute()
->fetchField();
}
function sms_user_sms_send(&$number, &$message, &$options, &$gateway) {
if (variable_get('sms_user_sleep', 1) && ($uid = sms_user_get_uid($number))) {
$account = user_load_multiple(array(
$uid,
), array(
'status' => 1,
));
$account = array_shift($account);
if (_sms_user_opted_out($account)) {
unset($gateway['send']);
watchdog('sms_user', 'Message was not sent to @user because user opted out.', array(
'@user' => $account->name,
));
}
else {
if (_sms_user_sleep_active($account)) {
unset($gateway['send']);
watchdog('sms_user', 'Message was not sent to @user due to sleep settings.', array(
'@user' => $account->name,
));
}
}
}
}
function _sms_user_sleep_active($account) {
if (variable_get('configurable_timezones', 1) && !empty($account->timezone_name)) {
$timezone = new DateTimeZone($account->timezone);
}
else {
$default = variable_get('date_default_timezone', '');
$timezonestring = empty($default) ? 'UTC' : $default;
$timezone = new DateTimeZone($timezonestring);
}
$date = new DateTime();
$date
->setTimezone($timezone);
$current_hour = date('G');
if (!empty($account->sms_user['sleep_enabled'])) {
$start = $account->sms_user['sleep_start_time'];
$end = $account->sms_user['sleep_end_time'];
}
else {
$start = variable_get('sms_user_sleep_start_time', 0);
$end = variable_get('sms_user_sleep_end_time', 0);
}
if ($start == 0 && $end == 0) {
return FALSE;
}
if ($start < $end) {
if ($start <= $current_hour && $end > $current_hour) {
return TRUE;
}
}
if ($end < $start) {
if ($start <= $current_hour) {
return TRUE;
}
if ($current_hour < $end) {
return TRUE;
}
}
return FALSE;
}
function _sms_user_opted_out($account) {
if (variable_get('sms_user_allow_opt_out', 1) && $account->sms_user['sms_user_opt_out']) {
return TRUE;
}
return FALSE;
}
function sms_user_settings($account) {
$output = array();
switch (isset($account->sms_user) ? $account->sms_user['status'] : 0) {
case 0:
$output['number_form'] = drupal_get_form('sms_user_settings_add_form', $account);
break;
case SMS_USER_PENDING:
$output['number_form'] = drupal_get_form('sms_user_settings_confirm_form', $account);
break;
case SMS_USER_CONFIRMED:
case SMS_USER_SMS_REGISTERED:
$output['number_form'] = drupal_get_form('sms_user_settings_reset_form', $account);
break;
}
if (variable_get('sms_user_sleep', 1) && $account->sms_user['number'] && $account->sms_user['status'] == SMS_USER_CONFIRMED) {
$output['sleep_form'] = drupal_get_form('sms_user_settings_sleep_form', $account);
}
if (variable_get('sms_user_allow_opt_out', 1) && $account->sms_user['number'] && $account->sms_user['status'] == SMS_USER_CONFIRMED) {
$output['opt_out_form'] = drupal_get_form('sms_user_opt_out_form', $account);
}
return drupal_render($output);
}
function sms_user_settings_add_form($form, &$form_state, $account) {
$form = sms_send_form(TRUE);
$form['number']['#element_validate'][] = 'sms_user_validate_number_element';
$form['uid'] = array(
'#type' => 'hidden',
'#value' => $account->uid,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Confirm number'),
);
$form['#submit'][] = 'sms_user_settings_add_form_submit';
return $form;
}
function sms_user_settings_add_form_submit($form, &$form_state, $account = NULL) {
$number = $form_state['values']['number'];
$gateway = empty($form_state['values']['gateway']) ? array() : $form_state['values']['gateway'];
if (!$account) {
$account = user_load($form_state['values']['uid']);
}
sms_user_send_confirmation($account, $number, $gateway);
}
function sms_user_settings_confirm_form($form, &$form_state, $account) {
$form['uid'] = array(
'#type' => 'hidden',
'#value' => $account->uid,
);
$form['number'] = array(
'#type' => 'item',
'#title' => t('Mobile phone number'),
'#markup' => $account->sms_user['number'],
);
$form['confirm_code'] = array(
'#type' => 'textfield',
'#title' => t('Confirmation code'),
'#description' => t('Enter the confirmation code sent by SMS to your mobile phone.'),
'#size' => 4,
'#maxlength' => 4,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Confirm number'),
);
$form['reset'] = array(
'#type' => 'submit',
'#value' => t('Delete & start over'),
'#access' => user_access('edit own sms number'),
);
$form['confirm'] = array(
'#type' => 'submit',
'#value' => t('Confirm without code'),
'#access' => user_access('administer smsframework'),
);
return $form;
}
function sms_user_settings_confirm_form_validate($form, &$form_state) {
if ($form_state['clicked_button']['#value'] == t('Confirm number')) {
$account = user_load($form_state['values']['uid']);
if ($form_state['values']['confirm_code'] != $account->sms_user['code']) {
form_set_error('confirm_code', t('The confirmation code is invalid.'));
}
}
}
function sms_user_settings_confirm_form_submit($form, &$form_state) {
$account = user_load($form_state['values']['uid']);
if ($form_state['clicked_button']['#value'] == t('Delete & start over')) {
sms_user_delete_user_info($account->uid);
}
else {
$data = array(
'number' => $account->sms_user['number'],
'status' => SMS_USER_CONFIRMED,
'gateway' => $account->sms_user['gateway'],
);
user_save($account, array(
'sms_user' => $data,
), 'mobile');
if (module_exists('rules')) {
rules_invoke_event('sms_user_number_validated', $account);
}
}
}
function sms_user_settings_reset_form($form, &$form_state, $account) {
$form['uid'] = array(
'#type' => 'hidden',
'#value' => $account->uid,
);
$form['number'] = array(
'#type' => 'item',
'#title' => t('Your mobile phone number'),
'#markup' => $account->sms_user['number'],
'#description' => t('Your mobile phone number has been confirmed.'),
);
$form['reset'] = array(
'#type' => 'submit',
'#value' => t('Delete & start over'),
'#access' => user_access('edit own sms number'),
);
return $form;
}
function sms_user_settings_reset_form_submit($form, &$form_state) {
$account = user_load($form_state['values']['uid']);
if (module_exists('rules')) {
rules_invoke_event('sms_user_number_removed', $account);
}
sms_user_delete_user_info($account->uid);
drupal_set_message(t('Your mobile information has been removed'), 'status');
}
function sms_user_settings_sleep_form($form, &$form_state, $account) {
$form['uid'] = array(
'#type' => 'hidden',
'#value' => $account->uid,
);
$form['sleep'] = array(
'#type' => 'fieldset',
'#title' => t('Sleep Time'),
'#collapsible' => TRUE,
);
$form['sleep']['sleep_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Disable messages between these hours'),
'#description' => t('If enabled, you will not receive messages between the specified hours.'),
'#default_value' => isset($account->sms_user['sleep_enabled']) ? $account->sms_user['sleep_enabled'] : NULL,
);
if (strpos(variable_get('date_format_short', 'm/d/Y - H:i'), 'g')) {
$format = 'g A';
}
else {
$format = 'H:00';
}
$hour = 0;
while ($hour < 24) {
$options[$hour] = date($format, mktime($hour));
$hour++;
}
$form['sleep']['sleep_start_time'] = array(
'#type' => 'select',
'#multiple' => FALSE,
'#options' => $options,
'#default_value' => isset($account->sms_user['sleep_start_time']) ? $account->sms_user['sleep_start_time'] : NULL,
);
$form['sleep']['sleep_end_time'] = array(
'#type' => 'select',
'#multiple' => FALSE,
'#options' => $options,
'#default_value' => isset($account->sms_user['sleep_end_time']) ? $account->sms_user['sleep_end_time'] : NULL,
);
$form['sleep']['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function sms_user_settings_sleep_form_submit($form, &$form_state) {
$account = user_load($form_state['values']['uid']);
if (isset($account->sms_user)) {
$data = $account->sms_user;
}
else {
$data = array();
}
$data['sleep_enabled'] = $form_state['values']['sleep_enabled'];
$data['sleep_start_time'] = $form_state['values']['sleep_start_time'];
$data['sleep_end_time'] = $form_state['values']['sleep_end_time'];
user_save($account, array(
'sms_user' => $data,
), 'mobile');
drupal_set_message(t('The changes have been saved.'), 'status');
}
function sms_user_opt_out_form($form, &$form_state, $account) {
$form['uid'] = array(
'#type' => 'hidden',
'#value' => $account->uid,
);
$form['opt_out'] = array(
'#type' => 'fieldset',
'#title' => t('Opt Out'),
'#collapsible' => TRUE,
);
$form['opt_out']['sms_user_opt_out'] = array(
'#type' => 'checkbox',
'#title' => t('Opt out of sms messages from this site.'),
'#description' => t('If enabled, you will not receive messages from this site.'),
'#default_value' => isset($account->sms_user['sms_user_opt_out']) ? $account->sms_user['sms_user_opt_out'] : NULL,
);
$form['opt_out']['set'] = array(
'#type' => 'submit',
'#value' => t('Set'),
);
return $form;
}
function sms_user_opt_out_form_submit($form, &$form_state) {
$account = user_load($form_state['values']['uid']);
if (isset($account->sms_user)) {
$data = $account->sms_user;
}
else {
$data = array();
}
$data['sms_user_opt_out'] = $form_state['values']['sms_user_opt_out'];
user_save($account, array(
'sms_user' => $data,
), 'mobile');
drupal_set_message(t('The changes have been saved.'), 'status');
}
function sms_user_send_confirmation($account, $number, $options) {
$code = rand(1000, 9999);
$number = sms_formatter($number);
$data = array(
'number' => $number,
'status' => SMS_USER_PENDING,
'code' => $code,
'gateway' => $options,
);
user_save($account, array(
'sms_user' => $data,
), 'mobile');
sms_send($number, _sms_user_confirm_message($code), $options);
}
function sms_user_validate_number_element($element, &$form_state, $form) {
$number = $element['#value'];
if ($error = sms_validate_number($number)) {
foreach ($error as $lerror) {
form_error($element, $lerror);
}
}
elseif (sms_user_get_uid($number)) {
form_error($element, t('This phone number is already registered to another user.'));
}
}
function sms_user_user_presave(&$edit, $account, $category) {
return sms_user_save($edit, $account, $category);
}
function sms_user_user_insert(&$edit, $account, $category) {
return sms_user_save($edit, $account, $category);
}
function sms_user_user_view($account, $view_mode) {
global $user;
if (user_access('receive sms', $account) && ($user->uid == $account->uid || user_access('access user profiles'))) {
if (isset($account->sms_user['status']) && $account->sms_user['status'] == SMS_USER_PENDING) {
drupal_set_message(t('You need to confirm your mobile number, <a href="@mobile_url">enter the confirmation code sent to your mobile</a>.', array(
'@mobile_url' => url('user/' . $account->uid . '/edit/mobile'),
)));
}
$account->content['sms'] = array(
'#type' => 'user_profile_category',
'#title' => t('Mobile'),
);
$account->content['sms']['number'] = array(
'#type' => 'user_profile_item',
'#title' => '',
'#markup' => isset($account->sms_user['number']) ? $account->sms_user['number'] : '',
);
if (variable_get('sms_user_sleep', 1) && (isset($account->sms_user) && $account->sms_user['sleep_enabled'])) {
$account->content['sms']['sleep'] = array(
'#type' => 'user_profile_item',
'#title' => '',
'#markup' => t('You will not receive messages between ' . $account->sms_user['sleep_start_time'] . ':00 and ' . $account->sms_user['sleep_end_time'] . ':00'),
);
}
if (variable_get('sms_user_allow_opt_out', 1) && isset($account->sms_user) && $account->sms_user['sms_user_opt_out']) {
$account->content['sms']['opt_out'] = array(
'#type' => 'user_profile_item',
'#title' => '',
'#markup' => t('You will not receive any messages from the site.'),
);
}
}
}
function sms_user_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == "user_register_form") {
if (variable_get('sms_user_registration_form', 0)) {
$form['sms_user'] = array(
'#type' => 'fieldset',
'#title' => t('Mobile settings'),
'#description' => t('You will receive a message to confirm your mobile information upon login.'),
'#collapsible' => TRUE,
'#tree' => TRUE,
);
$required = FALSE;
if (variable_get('sms_user_registration_form', 0) == 2) {
$required = TRUE;
}
$form['sms_user'] += sms_send_form($required);
$form['sms_user']['number']['#element_validate'] = array(
'sms_user_validate_number_element',
);
return $form;
}
}
return $form;
}
function sms_user_user_delete($account) {
return sms_user_delete_user_info($account->uid);
}
function sms_user_user_login(&$edit, $account) {
if (!$account->access && !empty($account->sms_user['number']) && $account->sms_user['status'] <= SMS_USER_CONFIRMED) {
sms_user_send_confirmation($account, $account->sms_user['number'], $account->sms_user['gateway']);
drupal_set_message(t('A confirmation message has been sent to your mobile phone. Please !link.', array(
'!link' => l(t('confirm your number'), 'user/' . $account->uid . '/edit/mobile'),
)), 'status');
}
}
function sms_user_user_categories() {
$categories['mobile'] = array(
'name' => 'mobile',
'title' => t('Mobile'),
'weight' => 10,
);
return $categories;
}
function sms_user_user_load($users) {
$result = db_select('sms_user', 'u')
->fields('u', array(
'uid',
'number',
'status',
'code',
'gateway',
'sleep_enabled',
'sleep_start_time',
'sleep_end_time',
'sms_user_opt_out',
))
->condition('uid', array_keys($users), 'IN')
->execute();
foreach ($result as $record) {
if (!empty($record->uid)) {
$record->gateway = unserialize($record->gateway);
$users[$record->uid]->sms_user = (array) $record;
$users[$record->uid]->sms_user[0] = (array) $record;
}
}
foreach ($users as $id => $user) {
if (!isset($user->sms_user)) {
$users[$id]->sms_user = array(
'uid' => $id,
'number' => '',
'status' => 0,
'code' => 0,
'gateway' => '',
'sleep_enabled' => 0,
'sleep_start_time' => 0,
'sleep_end_time' => 0,
'sms_user_opt_out' => 0,
);
$users[$id]->sms_user[0] = $users[$id]->sms_user;
}
}
}
function sms_user_save(&$edit, &$account, $category) {
if (($category == 'mobile' || $category == 'account') && isset($edit['sms_user']) && $edit['sms_user']['number'] && (isset($account->uid) && $account->uid != 0)) {
$number = (object) $edit['sms_user'];
$number->uid = $account->uid;
if (!isset($number->status)) {
$number->status = NULL;
}
$primary_keys = array();
if (isset($account->sms_user) && sms_user_get_uid($number->number)) {
$primary_keys = array(
'number',
);
}
$edit['sms_user']['number'] = NULL;
$edit['sms_user']['status'] = NULL;
$edit['sms_user']['code'] = NULL;
$edit['sms_user']['gateway'] = NULL;
$edit['sms_user']['sleep_enabled'] = NULL;
$edit['sms_user']['sleep_start_time'] = NULL;
$edit['sms_user']['sleep_end_time'] = NULL;
$edit['sms_user']['sms_user_opt_out'] = NULL;
return drupal_write_record('sms_user', $number, $primary_keys);
}
return FALSE;
}
function sms_user_delete_user_info($uid, $number = FALSE) {
if (is_object($uid)) {
$uid = $uid->uid;
}
$query = db_delete('sms_user')
->condition('uid', $uid);
if ($number) {
$query
->condition('number', $number);
}
return $query
->execute();
}
function _sms_user_confirm_message($code) {
$text_format = variable_get('sms_user_confirmation_message', '[site:name] confirmation code: ') . $code;
$text = token_replace($text_format, array(
'confirm-code' => $code,
));
return $text;
}
function sms_user_tokens($type, $tokens, array $data = array(), array $options = array()) {
global $user;
$replacements = array();
if ($type == 'sms_user') {
foreach ($tokens as $name => $original) {
switch ($name) {
case 'confirm-code':
$replacements[$original] = $data['confirm-code'];
break;
case 'mobile-url':
$replacements[$original] = url("user/{$user->uid}/edit/mobile", array(
'absolute' => TRUE,
));
break;
}
}
}
return $replacements;
}
function sms_user_token_info() {
$info['types']['sms_user'] = array(
'name' => t('SMS User'),
'description' => t('Tokens related to a users\' sms settings.'),
'needs-data' => 'user',
);
$info['tokens']['sms_user']['confirm-code'] = array(
'name' => t('Confirmation code'),
'description' => t('The mobile confirmation code for the user.'),
'type' => 'sms_user',
);
$info['tokens']['sms_user']['mobile-url'] = array(
'name' => t('Mobile URL'),
'description' => t('The URL for the user\'s mobile settings page.'),
'type' => 'sms_user',
);
return $info;
}
function sms_user_sms_incoming($op, $number, $message, $options) {
switch ($op) {
case 'pre process':
if (variable_get('sms_user_switch_account_incoming', 0)) {
if ($account = sms_user_authenticate($number)) {
$metadata = array(
'login' => TRUE,
'number' => $number,
'message' => $message,
'options' => $options,
);
sms_user_login_metadata($account->uid, $metadata);
_sms_user_switch($account);
}
}
elseif (variable_get('sms_user_registration_enabled', 0) && $number) {
if ($account = sms_user_register_new_user($number, $message, $options)) {
if ($message = variable_get('sms_user_new_account_message', '')) {
sms_user_send($account->uid, $message);
}
}
}
break;
case 'post process':
if (variable_get('sms_user_switch_account_incoming', 0)) {
_sms_user_switch();
}
break;
}
}
function sms_user_login_metadata($uid = NULL, $metadata = NULL, $reset = FALSE) {
static $accounts = array();
if ($reset) {
$accounts = array();
}
if (!isset($uid)) {
return $accounts;
}
if (isset($metadata)) {
$accounts[$uid] = $metadata;
return TRUE;
}
elseif (isset($accounts[$uid])) {
return $accounts[$uid];
}
else {
return FALSE;
}
}
function _sms_user_switch($account = NULL) {
global $user;
$original_user =& drupal_static(__FUNCTION__ . '_user');
$original_state =& drupal_static(__FUNCTION__ . '_state');
if ($account) {
$original_user = $user;
$original_state = drupal_save_session();
drupal_save_session(FALSE);
$user = $account;
$edit = array();
user_module_invoke('login', $edit, $account);
$username = $user->uid > 0 ? $user->name : variable_get('anonymous', t('Anonymous'));
watchdog('sms_user', '%name was logged in using SMS.', array(
'%name' => $username,
));
}
elseif (!empty($original_user)) {
$user = $original_user;
drupal_save_session($original_state);
$username = $user->uid > 0 ? $user->name : variable_get('anonymous', t('Anonymous'));
watchdog('sms_user', '%name was restored as logged in using SMS.', array(
'%name' => $username,
));
}
}
function sms_user_register_new_user($number, $message, $options) {
$edit = array();
$mail = isset($options['sms_email_gateway_from']) ? $options['sms_email_gateway_from'] : '';
$edit['sms_user'] = array(
'number' => $number,
'status' => SMS_USER_SMS_REGISTERED,
'code' => '',
'gateway' => array(),
);
$edit['timezone'] = '';
if (!empty($mail) && ($account = array_shift(user_load_multiple(array(), array(
'mail' => $mail,
), TRUE)))) {
$account = user_save($account, $edit);
}
else {
$edit['mail'] = $edit['init'] = $mail;
if (variable_get('sms_user_allow_password', 0)) {
$lines = explode("\n", $message);
$words = explode(" ", $lines[0]);
foreach ($words as $word) {
if (trim($word)) {
$edit['pass'] = preg_replace('/\\s+/', '-', $word);
break;
}
}
}
if (!isset($edit['pass']) || !$edit['pass']) {
$edit['pass'] = user_password();
}
$edit['name'] = substr(md5($number . strval(REQUEST_TIME)), 0, 10);
$edit['status'] = variable_get('user_register', 1) == 1;
$account = user_save('', $edit);
watchdog('sms_user', '%name was created using SMS.', array(
'%name' => $account->name,
));
}
if (is_object($account)) {
$user = $account;
$metadata = array(
'register' => TRUE,
'number' => $number,
'message' => $message,
'options' => $options,
);
sms_user_login_metadata($account->uid, $metadata);
if ($account->status) {
_sms_user_switch($account);
}
user_module_invoke('login', $edit, $account);
return $account;
}
return FALSE;
}
function sms_user_authenticate($number) {
if ($uid = sms_user_get_uid($number)) {
$account = user_load_multiple(array(
$uid,
), array(
'status' => 1,
));
$account = reset($account);
if (!empty($account)) {
watchdog('sms_user', '%name was authenticated using SMS.', array(
'%name' => $account->name,
));
return $account;
}
}
else {
return false;
}
}
function sms_user_views_api() {
return array(
'api' => 2,
);
}
function sms_user_feeds_processor_targets_alter(&$targets, $entity_type, $bundle) {
$targets['sms_user_phonenumber'] = array(
'name' => t('SMS User Phonenumber'),
'description' => t('The Phone number for the user to be used in the SMS Framework.'),
'optional_unique' => TRUE,
'callback' => '_sms_user_feedsprocess_set_value',
);
$targets['sms_user_status'] = array(
'name' => t('SMS User Status'),
'description' => t('The Phone number for the user to be used in the SMS Framework.'),
'optional_unique' => TRUE,
'callback' => '_sms_user_feedsprocess_set_value',
);
$targets['sms_user_gateway'] = array(
'name' => t('SMS User Gateway'),
'description' => t('The Phone number for the user to be used in the SMS Framework.'),
'optional_unique' => TRUE,
'callback' => '_sms_user_feedsprocess_set_value',
);
}
function _sms_user_feedsprocess_set_value($source, $target_item, $target, $value, $mapping) {
switch ($target) {
case 'sms_user_phonenumber':
$target_item->sms_user['number'] = $value;
break;
case 'sms_user_status':
$target_item->sms_user['status'] = $value;
break;
case 'sms_user_gateway':
$target_item->sms_user['gateway'] = $value;
break;
}
}
function sms_user_entity_property_info_alter(&$info) {
$properties =& $info['user']['properties'];
$properties['sms_user_phone_number'] = array(
'label' => t("Phone Number"),
'description' => t("The users mobile phone number."),
'type' => 'text',
'getter callback' => 'entity_property_sms_user_get_properties',
'computed' => TRUE,
'required' => FALSE,
);
$properties['sms_user_status'] = array(
'label' => t("SMS Status"),
'description' => t("The users status of the Mobile Phone number."),
'type' => 'text',
'getter callback' => 'entity_property_sms_user_get_properties',
'computed' => TRUE,
'required' => FALSE,
);
$properties['sms_user_gateway'] = array(
'label' => t("SMS Gateway"),
'description' => t("The SMS Gateway for this user."),
'type' => 'text',
'getter callback' => 'entity_property_sms_user_get_properties',
'computed' => TRUE,
'required' => FALSE,
);
}
function entity_property_sms_user_get_properties($data, array $options, $name, $type, $info) {
if (isset($data->uid) && $data->uid > 0) {
$account = user_load($data->uid);
if (isset($account->sms_user)) {
switch ($name) {
case "sms_user_phone_number":
return isset($account->sms_user['number']) ? $account->sms_user['number'] : '';
case "sms_user_status":
if (!isset($account->sms_user['status'])) {
return t('Blocked');
}
switch ($account->sms_user['status']) {
case SMS_USER_BLOCKED:
return t('Blocked');
break;
case SMS_USER_PENDING:
return t('Pending');
break;
case SMS_USER_CONFIRMED:
return t('Active');
break;
case SMS_USER_SMS_REGISTERED:
return t('SMS Registered');
break;
}
case "sms_user_gateway":
if (is_string($account->sms_user['gateway'])) {
return $account->sms_user['gateway'];
}
break;
}
}
}
return NULL;
}