You are here

function sms_sendtophone_node_view in SMS Framework 7

Implements hook_node_view().

File

modules/sms_sendtophone/sms_sendtophone.module, line 462
Provides various tools for sending bits of information via SMS.

Code

function sms_sendtophone_node_view($node, $view_mode, $langcode) {
  global $user;
  $links = array();
  $user = user_load($user->uid);
  $types = variable_get('sms_sendtophone_content_types', array());
  if (in_array($node->type, $types)) {
    if (user_access('send to any number') || !empty($user->sms_user['number']) && $user->sms_user['status'] == 2) {

      // Only show "send to phone" link if user is permitted to do so.
      $links['sms_sendtophone'] = array(
        'title' => t('Send to phone'),
        'href' => "sms/sendtophone/node/{$node->nid}",
        'query' => drupal_get_destination(),
        'attributes' => array(
          'class' => 'sms-sendtophone',
          'title' => 'Send a link via SMS.',
        ),
      );
    }
    else {
      if ($user->uid > 0) {

        // Show messages to encourage users to register their mobile number.
        if (empty($user->sms_user['number'])) {
          $links['sms_sendtophone'] = array(
            'title' => t('Setup your mobile number to send to phone.'),
            'href' => 'user/' . $user->uid . '/edit/mobile',
          );
        }
        elseif ($user->sms_user['status'] != 2) {
          $links['sms_sendtophone'] = array(
            'title' => t('Confirm your mobile number to send to phone.'),
            'href' => 'user/' . $user->uid . '/edit/mobile',
          );
        }
      }
    }
    $node->content['links']['sms_sendtophone'] = array(
      '#theme' => 'links__sms_sendtophone',
      '#links' => $links,
      '#attributes' => array(
        'class' => array(
          'links',
          'inline',
        ),
      ),
    );
  }
}