Projet

Général

Profil

Paste
Télécharger (1,86 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / author_pane / modules / og.author-pane.inc @ 87dbc3bf

1
<?php
2

    
3
/**
4
 * @file
5
 *   This file provides a preprocess function on behalf of the OG module.
6
 */
7

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

    
17
  $account = $variables['account'];
18
  $account_id = $variables['account']->uid;
19

    
20
  if (isset($account->og_groups) && !empty($account->og_groups)) {
21
    $groups = array();
22

    
23
    // Implement static caching for cases where this Author Pane appears more
24
    // than once on a given page.
25
    static $cached_og_groups_array;
26
    static $cached_og_groups;
27

    
28
    if (isset($cached_og_groups[$account_id])) {
29
      $variables['og_groups_array'] = $cached_og_groups_array[$account_id];
30
      $variables['og_groups'] = $cached_og_groups[$account_id];
31
    }
32
    else {
33
      // Check if there is the potential for private groups on the site to
34
      // avoid needless node loads on sites with no private gorups.
35
      $has_private = module_exists('og_access');
36
      foreach ($account->og_groups as $og_id => $og) {
37
        if ($has_private) {
38
          $og_node = node_load($og['nid']) ;
39
          if (!$og_node->og_private) {
40
            $groups[] = l($og['title'], 'node/' . $og['nid']);
41
          }
42
        }
43
        else {
44
          $groups[] = l($og['title'], 'node/' . $og['nid']);
45
        }
46
      }
47

    
48
      $variables['og_groups_array'] = $groups;
49
      $cached_og_groups_array[$account_id] = $groups;
50

    
51
      $variables['og_groups'] = implode(', ', $groups);
52
      $cached_og_groups[$account_id] = $variables['og_groups'];
53
    }
54
  }
55
  else {
56
    $variables['og_groups'] = t('None');
57
  }
58
}
59

    
60
/**
61
 * Implements hook_author_pane_allow_preprocess_disable().
62
 */
63
function og_author_pane_allow_preprocess_disable() {
64
  return array('og' => 'Organic Groups');
65
}