| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Gathers information from user related contrib modules into one template.
|
| 7 |
*/
|
| 8 |
|
| 9 |
// DRUPAL HOOKS **************************************************************/
|
| 10 |
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Implementation of hook_theme().
|
| 14 |
*/
|
| 15 |
function author_pane_theme() {
|
| 16 |
author_pane_include('author-pane.inc');
|
| 17 |
$items['author_pane'] = array(
|
| 18 |
'template' => 'author-pane',
|
| 19 |
'arguments' => array('account' => NULL, 'image_path' => NULL),
|
| 20 |
);
|
| 21 |
|
| 22 |
return $items;
|
| 23 |
}
|
| 24 |
|
| 25 |
// TEMPLATE PREPROCESS *******************************************************/
|
| 26 |
|
| 27 |
/**
|
| 28 |
* Load advanced forum files on behalf of modules.
|
| 29 |
*
|
| 30 |
* This function, taken from the views include system, allows us to include
|
| 31 |
* an appropriately named include file bundled with any enabled module.
|
| 32 |
* It is currently used only to load the MODULE.author-pane.inc files which
|
| 33 |
* allow other modules to add to the author pane.
|
| 34 |
*/
|
| 35 |
function author_pane_include($file) {
|
| 36 |
static $cache;
|
| 37 |
|
| 38 |
$includes = array();
|
| 39 |
|
| 40 |
if (!isset($cache->data) || !$cache->data) {
|
| 41 |
$cache = cache_get('author_pane_includes', 'cache');
|
| 42 |
}
|
| 43 |
|
| 44 |
if (isset($cache->data) && $cache->data) {
|
| 45 |
$includes = $cache->data;
|
| 46 |
}
|
| 47 |
else {
|
| 48 |
$author_pane_path = drupal_get_path('module', 'author_pane') . '/modules';
|
| 49 |
foreach (module_list() as $module) {
|
| 50 |
$module_path = drupal_get_path('module', $module);
|
| 51 |
if (file_exists("$module_path/$module.$file")) {
|
| 52 |
$includes[] = "./$module_path/$module.$file";
|
| 53 |
}
|
| 54 |
else if (file_exists("$module_path/includes/$module.$file")) {
|
| 55 |
$includes[] = "./$module_path/includes/$module.$file";
|
| 56 |
}
|
| 57 |
else if (file_exists("$author_pane_path/$module.$file")) {
|
| 58 |
$includes[] = "./$author_pane_path/$module.$file";
|
| 59 |
}
|
| 60 |
}
|
| 61 |
cache_set('author_pane_includes', $includes);
|
| 62 |
}
|
| 63 |
|
| 64 |
if (!empty($includes)) {
|
| 65 |
foreach ($includes as $include) {
|
| 66 |
require_once $include;
|
| 67 |
}
|
| 68 |
}
|
| 69 |
}
|
| 70 |
|
| 71 |
/**
|
| 72 |
* Preprocesses template variables for the author info template.
|
| 73 |
*/
|
| 74 |
function template_preprocess_author_pane(&$variables) {
|
| 75 |
author_pane_include('author-pane.inc');
|
| 76 |
|
| 77 |
// The passed in $variables['account'] refers to the user who's info is in the pane.
|
| 78 |
$account = $variables['account'];
|
| 79 |
$account_id = $account->uid;
|
| 80 |
$image_path = $variables['image_path'];
|
| 81 |
|
| 82 |
drupal_add_css(drupal_get_path('module', 'author_pane') . '/author_pane.css');
|
| 83 |
|
| 84 |
// Get a reference to the currently logged in user.
|
| 85 |
global $user;
|
| 86 |
|
| 87 |
// Username
|
| 88 |
$variables['account_name'] = theme('username', $account);
|
| 89 |
$variables['account_id'] = $account_id;
|
| 90 |
|
| 91 |
// Avatar
|
| 92 |
$variables['picture'] = theme('user_picture', $account);
|
| 93 |
|
| 94 |
// Nothing else applies to anon users, so just stop here
|
| 95 |
if ($account_id == 0) {
|
| 96 |
return;
|
| 97 |
}
|
| 98 |
|
| 99 |
// Join date / since
|
| 100 |
$just_date = str_replace(array('H:i', 'g:ia', ' - '), '', variable_get('date_format_short', 'm/d/Y - H:i'));
|
| 101 |
$variables['joined'] = format_date($account->created, 'custom', $just_date);
|
| 102 |
|
| 103 |
$variables['joined_ago'] = format_interval(time() - $account->created);
|
| 104 |
|
| 105 |
// Online status
|
| 106 |
$variables['last_active'] = format_interval(time() - $account->access);
|
| 107 |
if (round((time()-$account->access)/60) < 15) {
|
| 108 |
$variables['online_icon'] = theme('image', "$image_path/user-online.png", t('User is online'));
|
| 109 |
$variables['online_status'] = t('Online');
|
| 110 |
}
|
| 111 |
else {
|
| 112 |
$variables['online_icon'] = theme('image', "$image_path/user-offline.png", t('User offline. Last seen @time ago.', array('@time' => $variables['last_active'])));
|
| 113 |
$variables['online_status'] = t('Offline');
|
| 114 |
}
|
| 115 |
|
| 116 |
}
|
| 117 |
|
| 118 |
|