Projet

Général

Profil

Paste
Télécharger (2,07 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / author_pane / modules / userpoints.author-pane.inc @ a6e869e4

1
<?php
2
/**
3
 * @file
4
 * This file provides a preprocess function on behalf of the User Points module.
5
 */
6

    
7
/**
8
 * Implements hook_preprocess_author_pane().
9
 */
10
function userpoints_preprocess_author_pane(&$variables) {
11
  // Check if this preprocess needs to be run given who's calling it.
12
  if (!author_pane_run_preprocess('userpoints', $variables['caller'])) {
13
    return;
14
  }
15
  global $user;
16

    
17
  // Anonymous users can not have user points and also if
18
  // userpoints_get_current_points() gets $uid = 0, it returns the points
19
  // of the global $user.
20
  // Current user needs the permission 'view userpoints' to view userpoints or
21
  // the permission 'view own userpoints' if the user if viewing his own points.
22
  if ($variables['account']->uid != 0 && (user_access('view userpoints') || ($user->uid == $variables['account']->uid && user_access('view own userpoints')))) {
23
    // Total of amount of points (userpoints_points) is static cached in
24
    // userpoints_get_current_points() so no need to use static cache for that.
25
    // But amount of points for each category (userpoints_categories) is also
26
    // cached in userpoints_get_current_points() but to save count(userpoints_get_categories())
27
    // function calls to userpoints_get_current_points() a static cache is used.
28
    $userpoints_categories_cache = &drupal_static(__FUNCTION__, array());
29

    
30
    if (!isset($userpoints_categories_cache[$variables['account']->uid])) {
31
      $userpoints_categories_cache[$variables['account']->uid] = array();
32
      foreach (userpoints_get_categories() AS $tid => $category) {
33
        $userpoints_categories_cache[$variables['account']->uid][$category] = userpoints_get_current_points($variables['account']->uid, $tid);
34
      }
35
    }
36

    
37
    $variables['userpoints_points'] = userpoints_get_current_points($variables['account']->uid, 'all');
38
    $variables['userpoints_categories'] = $userpoints_categories_cache[$variables['account']->uid];
39
  }
40
}
41

    
42
/**
43
 * Implements hook_author_pane_allow_preprocess_disable().
44
 */
45
function userpoints_author_pane_allow_preprocess_disable() {
46
  return array('userpoints' => 'User Points');
47
}