| 1 |
<?php
|
| 2 |
// $Id: spaces_shoutbox.module,v 1.7.6.1 2008/09/19 13:48:55 yhahn Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_context_define().
|
| 6 |
*/
|
| 7 |
function spaces_shoutbox_context_define() {
|
| 8 |
$items = array();
|
| 9 |
$items[] = array(
|
| 10 |
'namespace' => 'spaces',
|
| 11 |
'attribute' => 'feature',
|
| 12 |
'value' => 'shoutbox',
|
| 13 |
'spaces' => array(
|
| 14 |
'label' => t('Shoutbox'),
|
| 15 |
'description' => t('A shoutbox for informal message blasts.'),
|
| 16 |
'types' => array('og'),
|
| 17 |
),
|
| 18 |
);
|
| 19 |
return $items;
|
| 20 |
}
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Implementation of hook_node_info()
|
| 24 |
*/
|
| 25 |
function spaces_shoutbox_node_info() {
|
| 26 |
return array(
|
| 27 |
'shout' => array(
|
| 28 |
'name' => t('Shout'),
|
| 29 |
'module' => 'spaces_shoutbox',
|
| 30 |
'description' => t('A shoutbox shout.'),
|
| 31 |
'locked' => true,
|
| 32 |
)
|
| 33 |
);
|
| 34 |
}
|
| 35 |
|
| 36 |
/**
|
| 37 |
* Implementation of hook_form()
|
| 38 |
*/
|
| 39 |
function spaces_shoutbox_form(&$node) {
|
| 40 |
$form['title'] = array(
|
| 41 |
'#type' => 'textfield',
|
| 42 |
'#title' => t('Text'),
|
| 43 |
'#required' => true,
|
| 44 |
'#default_value' => $node->title,
|
| 45 |
);
|
| 46 |
return $form;
|
| 47 |
}
|
| 48 |
|
| 49 |
/**
|
| 50 |
* Implementation of hook_menu()
|
| 51 |
*/
|
| 52 |
function spaces_shoutbox_menu($may_cache) {
|
| 53 |
$items = array();
|
| 54 |
if ($may_cache) {
|
| 55 |
$items[] = array(
|
| 56 |
'path' => 'js/shoutbox',
|
| 57 |
'description' => t('Shoutbox AJAX submission callback.'),
|
| 58 |
'callback' => 'spaces_shoutbox_ajax',
|
| 59 |
'access' => user_access('access content'),
|
| 60 |
'type' => MENU_CALLBACK,
|
| 61 |
);
|
| 62 |
}
|
| 63 |
return $items;
|
| 64 |
}
|
| 65 |
|
| 66 |
/**
|
| 67 |
* Shoutbox AJAX callback
|
| 68 |
*/
|
| 69 |
function spaces_shoutbox_ajax() {
|
| 70 |
if (isset($_GET['shout']) && $space = spaces_get_space()) {
|
| 71 |
if (check_plain($_GET['shout']) && !empty($_GET['shout'])) {
|
| 72 |
global $user;
|
| 73 |
$node = new stdClass();
|
| 74 |
$node->uid = $user->uid;
|
| 75 |
$node->title = $_GET['shout'];
|
| 76 |
$node->type = 'shout';
|
| 77 |
$node->status= 1;
|
| 78 |
|
| 79 |
if ($gid = $space->sid) {
|
| 80 |
$node->og_groups = array($gid);
|
| 81 |
$node->og_public = 0;
|
| 82 |
}
|
| 83 |
|
| 84 |
node_validate($node);
|
| 85 |
node_save($node);
|
| 86 |
print theme('spaces_shout', array('name' => theme('username', $user), 'title' => $node->title));
|
| 87 |
exit;
|
| 88 |
}
|
| 89 |
}
|
| 90 |
exit;
|
| 91 |
}
|
| 92 |
|
| 93 |
/**
|
| 94 |
* Implementation of hook_block()
|
| 95 |
*/
|
| 96 |
function spaces_shoutbox_block($op = 'list', $delta = 0) {
|
| 97 |
if ($op == 'list') {
|
| 98 |
$blocks[1] = array(
|
| 99 |
'info' => t('Spaces: Shoutbox'),
|
| 100 |
'region' => 'right',
|
| 101 |
'status' => 1,
|
| 102 |
);
|
| 103 |
return $blocks;
|
| 104 |
}
|
| 105 |
else if ($op == 'view') {
|
| 106 |
switch ($delta) {
|
| 107 |
case 1:
|
| 108 |
// If this isn't a groups site, or if it is and the shoutbox feature is enabled...
|
| 109 |
$space = spaces_get_space();
|
| 110 |
if ($space && ($space->features['shoutbox'] != SPACES_FEATURE_DISABLED) && $space->feature_access('shoutbox')) {
|
| 111 |
drupal_add_css(drupal_get_path('module', 'spaces_shoutbox') .'/spaces_shoutbox.css');
|
| 112 |
drupal_add_js(drupal_get_path('module', 'spaces_shoutbox') .'/spaces_shoutbox.js');
|
| 113 |
|
| 114 |
$shoutbox_url = url('js/shoutbox');
|
| 115 |
$js = "Drupal.extend({shout: {shout_url:'$shoutbox_url'}})";
|
| 116 |
drupal_add_js($js, 'inline');
|
| 117 |
|
| 118 |
$view = views_get_view('spaces_shouts');
|
| 119 |
$block['content'] = "<div id='spaces-shouts'>". views_build_view('block', $view, array(), false, $view->nodes_per_block) ."</div>";
|
| 120 |
$block['content'] .= drupal_get_form('spaces_shoutbox_ajaxform');
|
| 121 |
$block['subject'] = t('Shoutbox');
|
| 122 |
return $block;
|
| 123 |
}
|
| 124 |
break;
|
| 125 |
}
|
| 126 |
}
|
| 127 |
}
|
| 128 |
|
| 129 |
/**
|
| 130 |
* Shoutbox form definition
|
| 131 |
*/
|
| 132 |
function spaces_shoutbox_ajaxform() {
|
| 133 |
$form = array(
|
| 134 |
'#action' => null,
|
| 135 |
'shout' => array(
|
| 136 |
'#type' => 'textfield',
|
| 137 |
'#size' => 20,
|
| 138 |
'#required' => true,
|
| 139 |
),
|
| 140 |
'submit' => array(
|
| 141 |
'#type' => 'button',
|
| 142 |
'#value' => t('Shout'),
|
| 143 |
),
|
| 144 |
);
|
| 145 |
$form['#theme'] = ''; // force default renderer
|
| 146 |
return $form;
|
| 147 |
}
|
| 148 |
|
| 149 |
/**
|
| 150 |
* Shoutbox markup
|
| 151 |
*/
|
| 152 |
function theme_spaces_shout($vars) {
|
| 153 |
extract($vars);
|
| 154 |
$title = _filter_url($title, 'shout'); // link shout urls
|
| 155 |
return "<div class='shout'><span class='name'>$name</span> $title</div>";
|
| 156 |
}
|
| 157 |
|
| 158 |
/**
|
| 159 |
* Custom spaces shout theme f()
|
| 160 |
*/
|
| 161 |
function theme_views_view_list_spaces_shouts($view, $nodes, $type) {
|
| 162 |
$fields = _views_get_fields();
|
| 163 |
$items = array();
|
| 164 |
foreach ($nodes as $node) {
|
| 165 |
$item = array();
|
| 166 |
foreach ($view->field as $field) {
|
| 167 |
if (!isset($fields[$field['id']]['visible']) && $fields[$field['id']]['visible'] !== FALSE) {
|
| 168 |
$item[$field['field']] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
|
| 169 |
}
|
| 170 |
}
|
| 171 |
$items[] = theme('spaces_shout', $item);
|
| 172 |
}
|
| 173 |
return implode("\n", $items);
|
| 174 |
}
|
| 175 |
|
| 176 |
/**
|
| 177 |
* Implementation hook_views_default_views()
|
| 178 |
*/
|
| 179 |
function spaces_shoutbox_views_default_views() {
|
| 180 |
$views = array();
|
| 181 |
$view = _spaces_shoutbox_views_shouts();
|
| 182 |
$views[$view->name] = $view;
|
| 183 |
return $views;
|
| 184 |
}
|
| 185 |
|
| 186 |
function _spaces_shoutbox_views_shouts() {
|
| 187 |
$view = new stdClass();
|
| 188 |
$view->name = 'spaces_shouts';
|
| 189 |
$view->description = t('Displays a short list of shouts.');
|
| 190 |
$view->access = array();
|
| 191 |
$view->view_args_php = '';
|
| 192 |
$view->block = TRUE;
|
| 193 |
$view->block_title = t('Shoutbox');
|
| 194 |
$view->block_empty = '<p class="views-empty">'.t('There are no shouts to view.').'</p>';
|
| 195 |
$view->block_empty_format = '1';
|
| 196 |
$view->block_type = 'list';
|
| 197 |
$view->nodes_per_block = '10';
|
| 198 |
$view->sort = array (
|
| 199 |
array (
|
| 200 |
'tablename' => 'node',
|
| 201 |
'field' => 'created',
|
| 202 |
'sortorder' => 'DESC',
|
| 203 |
'options' => 'normal',
|
| 204 |
),
|
| 205 |
);
|
| 206 |
$view->argument = array();
|
| 207 |
$view->field = array (
|
| 208 |
array (
|
| 209 |
'tablename' => 'users',
|
| 210 |
'field' => 'name',
|
| 211 |
'label' => '',
|
| 212 |
),
|
| 213 |
array (
|
| 214 |
'tablename' => 'node',
|
| 215 |
'field' => 'title',
|
| 216 |
'label' => '',
|
| 217 |
'handler' => 'views_handler_field_nodelink',
|
| 218 |
'options' => 'nolink',
|
| 219 |
),
|
| 220 |
);
|
| 221 |
$view->filter = array (
|
| 222 |
array (
|
| 223 |
'tablename' => 'node',
|
| 224 |
'field' => 'type',
|
| 225 |
'operator' => 'OR',
|
| 226 |
'options' => '',
|
| 227 |
'value' => array (
|
| 228 |
0 => 'shout',
|
| 229 |
),
|
| 230 |
),
|
| 231 |
array (
|
| 232 |
'tablename' => 'node',
|
| 233 |
'field' => 'status',
|
| 234 |
'operator' => '=',
|
| 235 |
'options' => '',
|
| 236 |
'value' => '1',
|
| 237 |
),
|
| 238 |
array (
|
| 239 |
'tablename' => 'og_ancestry',
|
| 240 |
'field' => 'picg',
|
| 241 |
'operator' => '=',
|
| 242 |
'options' => '',
|
| 243 |
'value' => '***CURRENT_GID***',
|
| 244 |
),
|
| 245 |
array (
|
| 246 |
'tablename' => 'node',
|
| 247 |
'field' => 'changed',
|
| 248 |
'operator' => '>',
|
| 249 |
'options' => -1*SPACES_ARCHIVE_TIMESTAMP,
|
| 250 |
'value' => 'now',
|
| 251 |
),
|
| 252 |
);
|
| 253 |
$view->exposed_filter = array();
|
| 254 |
$view->requires = array(node, users);
|
| 255 |
return $view;
|
| 256 |
}
|