View source
<?php
include_once drupal_get_path('module', 'author_pane') . '/d6_compat.inc';
function author_pane_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Author Pane');
return $blocks;
case 'configure':
$form['author_pane_block_template'] = array(
'#type' => 'textfield',
'#title' => t('Template file'),
'#description' => t('Template file to use. Do not include .tpl.php. Default is author-pane-block.'),
'#default_value' => variable_get('author_pane_block_template', 'author-pane-block'),
);
$form['author_pane_block_image_path'] = array(
'#type' => 'textfield',
'#title' => t('Image path'),
'#description' => t('Path to author pane images. Leave blank to use default.'),
'#default_value' => variable_get('author_pane_block_image_path', ''),
);
$types = node_get_types();
$options = array();
foreach ($types as $type) {
$options[$type->type] = $type->name;
}
$form['author_pane_block_display_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Node types to display on'),
'#options' => $options,
'#default_value' => variable_get('author_pane_block_display_types', array()),
);
if (module_exists('imagecache') && function_exists('imagecache_presets')) {
$options = array(
'' => '',
);
$presets = imagecache_presets();
foreach ($presets as $preset) {
$options[$preset['presetname']] = $preset['presetname'];
}
$form['author_pane_block_user_picture_preset'] = array(
'#type' => 'select',
'#title' => t('User picture preset'),
'#options' => $options,
'#description' => t('Imagecache preset to use for the user picture on this block. Leave blank to not use this feature.'),
'#default_value' => variable_get('author_pane_block_user_picture_preset', ''),
);
}
return $form;
case 'save':
variable_set('author_pane_block_image_path', $edit['author_pane_block_image_path']);
variable_set('author_pane_block_template', $edit['author_pane_block_template']);
variable_set('author_pane_block_display_types', $edit['author_pane_block_display_types']);
variable_set('author_pane_block_user_picture_preset', $edit['author_pane_block_user_picture_preset']);
return;
case 'view':
$block = array();
$block['subject'] = t('Author Information');
$block['content'] = author_pane_get_block();
return $block;
}
}
function author_pane_include($file) {
$includes = array();
$author_pane_path = drupal_get_path('module', 'author_pane') . '/modules';
foreach (module_list() as $module) {
$module_path = drupal_get_path('module', $module);
if (file_exists("{$module_path}/{$module}.{$file}")) {
$includes[] = "./{$module_path}/{$module}.{$file}";
}
else {
if (file_exists("{$module_path}/includes/{$module}.{$file}")) {
$includes[] = "./{$module_path}/includes/{$module}.{$file}";
}
else {
if (file_exists("{$author_pane_path}/{$module}.{$file}")) {
$includes[] = "./{$author_pane_path}/{$module}.{$file}";
}
}
}
}
if (!empty($includes)) {
foreach ($includes as $include) {
require_once $include;
}
}
}
function theme_author_pane($account, $image_path = NULL, $template_suggestion = NULL) {
$variables = array();
$variables['account'] = $account;
$variables['image_path'] = $image_path;
$variables['template_suggestion'] = $template_suggestion;
author_pane_include('author-pane.inc');
author_pane_call_preprocess('author_pane', $variables);
return _phptemplate_callback("author_pane", $variables, array(
"author-pane",
));
}
function template_preprocess_author_pane(&$variables) {
if (!empty($variables['template_suggestion'])) {
$variables['template_files'][] = $variables['template_suggestion'];
}
if (empty($variables['image_path'])) {
$variables['image_path'] = drupal_get_path('module', 'author_pane') . '/images';
}
else {
$path_to_theme = path_to_theme();
$variables['image_path'] = str_replace('[theme_path]', $path_to_theme, $variables['image_path']);
}
$image_path = $variables['image_path'];
drupal_add_css(drupal_get_path('module', 'author_pane') . '/author_pane.css');
$account = $variables['account'];
$account_id = $account->uid;
$variables['account_name'] = theme('username', $account);
$variables['account_id'] = $account_id;
$block_template = variable_get('author_pane_block_template', 'author-pane-block');
if ($variables['template_suggestion'] == $block_template) {
$sized_picture = theme('author_pane_block_user_picture', $variables['account']);
if (!empty($sized_picture)) {
$variables['picture'] = $sized_picture;
}
}
if (empty($variables['picture'])) {
$variables['picture'] = theme('user_picture', $account);
}
if ($account_id != 0) {
$just_date = str_replace(array(
'H:i',
'g:ia',
' - ',
), '', variable_get('date_format_short', 'm/d/Y - H:i'));
$variables['joined'] = format_date($account->created, 'custom', $just_date);
$variables['joined_ago'] = format_interval(time() - $account->created);
$variables['last_active'] = format_interval(time() - $account->access);
if (round((time() - $account->access) / 60) < 15) {
$variables['online_icon'] = theme('image', "{$image_path}/user-online.png", t('User is online'), t('User is online'));
$variables['online_status'] = t('Online');
}
else {
$variables['online_icon'] = theme('image', "{$image_path}/user-offline.png", t('User offline. Last seen @time ago.', array(
'@time' => $variables['last_active'],
)), t('User offline. Last seen @time ago.', array(
'@time' => $variables['last_active'],
)));
$variables['online_status'] = t('Offline');
}
}
}
function author_pane_panels_include_directory($plugintype) {
if ($plugintype == 'content_types') {
return 'panels_content_types';
}
}
function author_pane_get_block() {
$image_path = variable_get('author_pane_block_image_path', NULL);
$template = variable_get('author_pane_block_template', NULL);
$area = arg(0);
if (!($area == 'user' || $area == 'node' || $area == 'blog') || !is_numeric(arg(1)) || arg(2) != '') {
return;
}
if ($area == 'user' || $area == 'blog') {
$uid = arg(1);
}
else {
$node = node_load(arg(1));
$allowed_types = variable_get('author_pane_block_display_types', array());
if (empty($allowed_types[$node->type])) {
return;
}
$uid = $node->uid;
}
$account = user_load(array(
'uid' => $uid,
));
$author_pane = theme('author_pane', $account, $image_path, $template);
return $author_pane;
}
function theme_author_pane_block_user_picture($account) {
$preset = variable_get('author_pane_block_user_picture_preset', '');
if (variable_get('user_pictures', 0) && !empty($preset) && module_exists('imagecache')) {
if ($account->picture && file_exists($account->picture)) {
$alt = t("@user's picture", array(
'@user' => $account->name ? $account->name : 'Visitor',
));
$picture = theme('imagecache', $preset, $account->picture);
}
else {
$default_picture = variable_get('user_picture_default', '');
if ($default_picture) {
$picture = theme('imagecache', $preset, $default_picture);
}
}
if (!empty($picture)) {
if (!empty($account->uid) && user_access('access user profiles')) {
$picture = l($picture, "user/{$account->uid}", array(
'title' => t('View user profile.'),
), NULL, NULL, FALSE, TRUE);
}
}
return '<div class="picture">' . $picture . '</div>';
}
}