You are here

function profile2_diff_block_view in Profile 2 7.2

Implements hook_block_view().

File

contrib/profile2_diff.module, line 279
Provides functionality to show a diff between two profile2 revisions.

Code

function profile2_diff_block_view($delta) {
  $block = array();
  if ($delta === 'inline') {

    // A profile tab has a menu object for 'user', a profile page has one for 'profile2_by_uid'.
    if ($user = menu_get_object('user')) {

      // A profile tab, the profile type is arg(3).
      $profile = profile2_load_by_user($user, arg(3));
    }
    else {

      // A profile page, the profile is loaded by the menu.
      $profile = menu_get_object('profile2_by_uid');
    }
    if (is_object($profile) && _profile2_revision_access($profile, array(
      'view own profile revisions',
      'view any profile revisions',
    ))) {
      $enabled_types = variable_get('profile2_diff_show_diff_inline_types', array());
      if (!empty($enabled_types[$profile->type])) {

        // Check if we're on the view-revision page of a profile.
        $path = current_path();
        $base_path = _profile2_revision_base_path($profile, TRUE);
        if (strpos($path, $base_path) === 0 && strpos($path, '/view/') == strlen($base_path)) {

          // Load the correct vid
          $count = count(explode('/', $base_path));
          $vid = arg($count + 1);
          $profile = profile2_load($profile->pid, $vid);
          $revisions = profile2_revision_list($profile);
          if (count($revisions) > 1) {
            unset($revisions[$profile->vid]);
            $old_vid = arg($count + 2);
            $block['subject'] = t('Highlight changes');
            $block['content'] = drupal_get_form('profile2_diff_inline_form', $profile, $old_vid, $revisions);
          }
        }
      }
    }
  }
  return $block;
}