profile_block

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

modules/profile/profile.module, строка 101

Версии
5 – 6
profile_block($op = 'list', $delta = 0, $edit = array())

Реализация hook_block().

Код

<?php
function profile_block($op = 'list', $delta = 0, $edit = array()) {

  if ($op == 'list') {
     $blocks[0]['info'] = t('Author information');

     return $blocks;
  }
  else if ($op == 'configure' && $delta == 0) {
    // Compile a list of fields to show
    $fields = array();
    $result = db_query('SELECT name, title, weight, visibility FROM {profile_fields} WHERE visibility IN (%d, %d) ORDER BY weight', PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS);
    while ($record = db_fetch_object($result)) {
      $fields[$record->name] = check_plain($record->title);
    }
    $fields['user_profile'] = t('Link to full user profile');
    $form['profile_block_author_fields'] = array('#type' => 'checkboxes',
      '#title' => t('Profile fields to display'),
      '#default_value' => variable_get('profile_block_author_fields', NULL),
      '#options' => $fields,
      '#description' => t('Select which profile fields you wish to display in the block. Only fields designated as public in the <a href="@profile-admin">profile field configuration</a> are available.', array('@profile-admin' => url('admin/user/profile'))),
    );
    return $form;
  }
  else if ($op == 'save' && $delta == 0) {
    variable_set('profile_block_author_fields', $edit['profile_block_author_fields']);
  }
  else if ($op == 'view') {
    if (user_access('access user profiles')) {
      if ((arg(0) == 'node') && is_numeric(arg(1)) && (arg(2) == NULL)) {
        $node = node_load(arg(1));
        $account = user_load(array('uid' => $node->uid));

        if ($use_fields = variable_get('profile_block_author_fields', array())) {
          // Compile a list of fields to show.
          $fields = array();
          $result = db_query('SELECT name, title, type, visibility, weight FROM {profile_fields} WHERE visibility IN (%d, %d) ORDER BY weight', PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS);
          while ($record = db_fetch_object($result)) {
            // Ensure that field is displayed only if it is among the defined block fields and, if it is private, the user has appropriate permissions.
            if (isset($use_fields[$record->name]) && $use_fields[$record->name]) {
              $fields[] = $record;
            }
          }
        }

        if ($fields) {
          $profile = _profile_update_user_fields($fields, $account);
          $output .= theme('profile_block', $account, $profile, TRUE);
        }

        if (isset($use_fields['user_profile']) && $use_fields['user_profile']) {
          $output .= '<div>'. l(t('View full user profile'), 'user/'. $account->uid) .'</div>';
        }
      }

      if ($output) {
         $block['subject'] = t('About %name', array('%name' => $account->name));
         $block['content'] = $output;
         return $block;
      }
    }
  }
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему