View source
<?php
function spaces_shoutbox_node_info() {
return array(
'shout' => array(
'name' => t('Shout'),
'module' => 'spaces_shoutbox',
'description' => t('A shoutbox shout.'),
'locked' => true,
),
);
}
function spaces_shoutbox_form(&$node) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Text'),
'#required' => true,
'#default_value' => $node->title,
);
return $form;
}
function spaces_shoutbox_spaces_settings() {
$items = array();
$items['shoutbox'] = array(
'label' => t('Shoutbox'),
'description' => t('A shoutbox for informal message blasts.'),
'options' => array(
0 => t('Disabled'),
1 => t('Enabled'),
),
);
return $items;
}
function spaces_shoutbox_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'js/shoutbox',
'description' => t('Shoutbox AJAX submission callback.'),
'callback' => 'spaces_shoutbox_ajax',
'access' => user_access('access content'),
'type' => MENU_CALLBACK,
);
}
return $items;
}
function spaces_shoutbox_ajax() {
if (isset($_GET['shout'])) {
if (check_plain($_GET['shout']) && !empty($_GET['shout'])) {
global $user;
$node = new stdClass();
$node->uid = $user->uid;
$node->title = $_GET['shout'];
$node->type = 'shout';
$node->status = 1;
if ($gid = spaces_gid()) {
$node->og_groups = array(
$gid,
);
$node->og_public = 0;
}
node_validate($node);
node_save($node);
print theme('spaces_shout', array(
'name' => theme('username', $user),
'title' => $node->title,
));
exit;
}
}
exit;
}
function spaces_shoutbox_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[1] = array(
'info' => t('Spaces: Shoutbox'),
'region' => 'right',
'status' => 1,
);
return $blocks;
}
else {
if ($op == 'view') {
switch ($delta) {
case 1:
if (spaces_setting('shoutbox')) {
drupal_add_css(drupal_get_path('module', 'spaces_shoutbox') . '/spaces_shoutbox.css');
drupal_add_js(drupal_get_path('module', 'spaces_shoutbox') . '/spaces_shoutbox.js');
$shoutbox_url = url('js/shoutbox');
$js = "Drupal.extend({shout: {shout_url:'{$shoutbox_url}'}})";
drupal_add_js($js, 'inline');
$view = views_get_view('spaces_shouts');
$block['content'] = "<div id='spaces-shouts'>" . views_build_view('block', $view, array(), false, $view->nodes_per_block) . "</div>";
$block['content'] .= drupal_get_form('spaces_shoutbox_ajaxform');
$block['subject'] = t('Shoutbox');
return $block;
}
break;
}
}
}
}
function spaces_shoutbox_ajaxform() {
$form = array(
'#action' => null,
'shout' => array(
'#type' => 'textfield',
'#size' => 20,
'#required' => true,
),
'submit' => array(
'#type' => 'button',
'#value' => t('Shout'),
),
);
$form['#theme'] = '';
return $form;
}
function theme_spaces_shout($vars) {
extract($vars);
$title = _filter_url($title, 'shout');
return "<div class='shout'><span class='name'>{$name}</span> {$title}</div>";
}
function theme_views_view_list_spaces_shouts($view, $nodes, $type) {
$fields = _views_get_fields();
$items = array();
foreach ($nodes as $node) {
$item = array();
foreach ($view->field as $field) {
if (!isset($fields[$field['id']]['visible']) && $fields[$field['id']]['visible'] !== FALSE) {
$item[$field['field']] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
}
}
$items[] = theme('spaces_shout', $item);
}
return implode("\n", $items);
}
function spaces_shoutbox_views_default_views() {
$views = array();
$view = _spaces_shoutbox_views_shouts();
$views[$view->name] = $view;
return $views;
}
function _spaces_shoutbox_views_shouts() {
$view = new stdClass();
$view->name = 'spaces_shouts';
$view->description = t('Displays a short list of shouts.');
$view->access = array();
$view->view_args_php = '';
$view->block = TRUE;
$view->block_title = t('Shoutbox');
$view->block_empty = '<p class="views-empty">' . t('There are no shouts to view.') . '</p>';
$view->block_empty_format = '1';
$view->block_type = 'list';
$view->nodes_per_block = '10';
$view->sort = array(
array(
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array();
$view->field = array(
array(
'tablename' => 'users',
'field' => 'name',
'label' => '',
),
array(
'tablename' => 'node',
'field' => 'title',
'label' => '',
'handler' => 'views_handler_field_nodelink',
'options' => 'nolink',
),
);
$view->filter = array(
array(
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array(
0 => 'shout',
),
),
array(
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array(
'tablename' => 'og_ancestry',
'field' => 'picg',
'operator' => '=',
'options' => '',
'value' => '***CURRENT_GID***',
),
array(
'tablename' => 'node',
'field' => 'changed',
'operator' => '>',
'options' => -1 * SPACES_ARCHIVE_TIMESTAMP,
'value' => 'now',
),
);
$view->exposed_filter = array();
$view->requires = array(
node,
users,
);
return $view;
}