| 1 |
|
<?php |
| 2 |
|
// $Id: sidecontent.module,v 1.11.2.3 2006/10/22 19:43:50 MegaGrunt Exp $ |
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* Implementation of hook_perm(). |
| 6 |
|
*/ |
| 7 |
|
function sidecontent_perm() { |
| 8 |
|
|
| 9 |
|
return array('access side content', 'create side content'); |
| 10 |
|
} |
| 11 |
|
|
| 12 |
|
|
| 13 |
|
/** |
| 14 |
|
* Implementation of hook_block(). |
| 15 |
|
* |
| 16 |
|
* Displays content in side bar |
| 17 |
|
*/ |
| 18 |
|
function sidecontent_block($op = 'list', $delta = 0, $edit = array()) { |
| 19 |
|
|
| 20 |
|
switch ($op) { |
| 21 |
|
|
| 22 |
|
case 'list': |
| 23 |
|
$blocks[0]['info'] = t('Side content'); |
| 24 |
|
return $blocks; |
| 25 |
|
|
| 26 |
|
case 'configure': |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
$form['sidecontent_print'] = array( |
| 30 |
|
'#type' => 'checkbox', |
| 31 |
|
'#title' => t('Print view include'), |
| 32 |
|
'#default_value' => variable_get('sidecontent_print', false), |
| 33 |
|
'#description' => t('Show content in print view (requires Print Friendly Pages module).'), |
| 34 |
|
); |
| 35 |
|
|
| 36 |
|
$form['sidecontent_options'] = array( |
| 37 |
|
'#prefix' => '<strong>', |
| 38 |
|
'#value' => t('Options for node form:'), |
| 39 |
|
'#suffix' => '</strong>', |
| 40 |
|
); |
| 41 |
|
|
| 42 |
|
$form['sidecontent_show_input_format'] = array( |
| 43 |
|
'#type' => 'checkbox', |
| 44 |
|
'#title' => t('Show input format'), |
| 45 |
|
'#default_value' => variable_get('sidecontent_show_input_format', true), |
| 46 |
|
'#description' => t('If this box is not checked, the default input format will be used when formatting the block content.'), |
| 47 |
|
); |
| 48 |
|
|
| 49 |
|
$form['sidecontent_show_in_group'] = array( |
| 50 |
|
'#type' => 'checkbox', |
| 51 |
|
'#title' => t('Show in form group'), |
| 52 |
|
'#default_value' => variable_get('sidecontent_show_in_group', true), |
| 53 |
|
'#description' => t('Show textarea and form filters formatted as a form group.'), |
| 54 |
|
); |
| 55 |
|
|
| 56 |
|
$form['sidecontent_group_description'] = array( |
| 57 |
|
'#type' => 'textfield', |
| 58 |
|
'#title' => t('Group description'), |
| 59 |
|
'#default_value' => check_plain(variable_get('sidecontent_group_description', 'Content to display in side block.')), |
| 60 |
|
'#size' => 50, |
| 61 |
|
'#maxlength' => 64, |
| 62 |
|
'#description' => t('Short description that is displayed at the end of the form group.'), |
| 63 |
|
); |
| 64 |
|
|
| 65 |
|
return $form; |
| 66 |
|
|
| 67 |
|
case 'save': |
| 68 |
|
|
| 69 |
|
if (!user_access('create side content')) break; |
| 70 |
|
variable_set('sidecontent_print', !empty($edit['sidecontent_print'])); |
| 71 |
|
variable_set('sidecontent_show_input_format', !empty($edit['sidecontent_show_input_format'])); |
| 72 |
|
variable_set('sidecontent_show_in_group', !empty($edit['sidecontent_show_in_group'])); |
| 73 |
|
variable_set('sidecontent_group_description', trim($edit['sidecontent_group_description'])); |
| 74 |
|
return; |
| 75 |
|
|
| 76 |
|
case 'view': default: |
| 77 |
|
|
| 78 |
|
// is this a node? |
| 79 |
|
if (arg(0) != 'node') break; |
| 80 |
|
if (!is_numeric(arg(1)) && arg(1) != 'add') break; |
| 81 |
|
|
| 82 |
|
// does user have access to view node? |
| 83 |
|
if (!user_access('access content')) break; |
| 84 |
|
|
| 85 |
|
// does user have access to view sidecontent? |
| 86 |
|
if (!user_access('access side content') && !user_access('create side content' )) break; |
| 87 |
|
|
| 88 |
|
if (is_numeric(arg(1))) { |
| 89 |
|
|
| 90 |
|
$node = node_load(arg(1)); |
| 91 |
|
$type = $node->type; |
| 92 |
|
} else { |
| 93 |
|
$type = arg(2); |
| 94 |
|
} |
| 95 |
|
|
| 96 |
|
// is sidecontent enabled for this node type? |
| 97 |
|
if (!variable_get('sidecontent_' . $type, 1)) break; |
| 98 |
|
|
| 99 |
|
// Preview |
| 100 |
|
$node_form = $_POST['edit']; |
| 101 |
|
|
| 102 |
|
if (!empty($node_form) && user_access('create side content' )) { |
| 103 |
|
|
| 104 |
|
if (empty($node_form['sidecontent_format']) || !is_numeric($node_form['sidecontent_format'])) $node_form['sidecontent_format'] = FILTER_FORMAT_DEFAULT; |
| 105 |
|
$sidecontent->sidetitle = $node_form['sidecontent_title']; |
| 106 |
|
$sidecontent->sidecontent = $node_form['sidecontent']; |
| 107 |
|
$sidecontent->format = $node_form['sidecontent_format']; |
| 108 |
|
|
| 109 |
|
} else { |
| 110 |
|
|
| 111 |
|
$sidecontent = db_fetch_object(db_query("SELECT s.format, s.sidetitle, s.sidecontent FROM {sidecontent} s WHERE nid = %d", $node->nid)); |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
if ($sidecontent->sidecontent) { |
| 115 |
|
|
| 116 |
|
if (!empty($sidecontent->sidetitle)) $block['subject'] = check_plain($sidecontent->sidetitle); |
| 117 |
|
$block['content'] = check_markup($sidecontent->sidecontent, $sidecontent->format, FALSE); |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
return $block; |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
return; |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
|
| 127 |
|
/** |
| 128 |
|
* Implementation of hook_form_alter. |
| 129 |
|
*/ |
| 130 |
|
function sidecontent_form_alter($form_id, &$form) { |
| 131 |
|
|
| 132 |
|
// Alter the settings form. |
| 133 |
|
if ($form_id == 'node_type_form') { |
| 134 |
|
$node_type = $form['old_type']['#value']; |
| 135 |
|
|
| 136 |
|
$form['submission']['sidecontent'] = array( |
| 137 |
|
'#type' => 'radios', |
| 138 |
|
'#title' => t('Enable side content'), |
| 139 |
|
'#default_value' => variable_get('sidecontent_' . $node_type, 0), |
| 140 |
|
'#options' => array(t('Disabled'), t('Enabled')), |
| 141 |
|
); |
| 142 |
|
} |
| 143 |
|
|
| 144 |
|
// Add stuff to the node submit form. |
| 145 |
|
if (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id) { |
| 146 |
|
|
| 147 |
|
if (!user_access('create side content' )) return; |
| 148 |
|
|
| 149 |
|
$node = $form['#node']; |
| 150 |
|
|
| 151 |
|
$type = variable_get('sidecontent_' . $node->type, 1); |
| 152 |
|
|
| 153 |
|
if (!empty($type)) { |
| 154 |
|
|
| 155 |
|
if (variable_get('sidecontent_show_in_group', true)) { |
| 156 |
|
|
| 157 |
|
$form['sidecontent'] = array( |
| 158 |
|
'#type' => 'fieldset', |
| 159 |
|
'#title' => t('Side Content'), |
| 160 |
|
'#description' => check_plain(variable_get('sidecontent_group_description', '')), |
| 161 |
|
'#collapsible' => TRUE, |
| 162 |
|
'#collapsed' => empty($node->sidecontent), |
| 163 |
|
); |
| 164 |
|
} |
| 165 |
|
|
| 166 |
|
$default_title = trim(variable_get('sidecontent_title', t('blank'))); |
| 167 |
|
$default_title = (empty($default_title)) ? t('blank') : check_plain($default_title); |
| 168 |
|
|
| 169 |
|
$form['sidecontent']['sidecontent_title'] = array( |
| 170 |
|
'#type' => 'textfield', |
| 171 |
|
'#title' => t('Side Content Title'), |
| 172 |
|
'#default_value' => check_plain($node->sidecontent_title), |
| 173 |
|
'#description' => t("Leave blank to use default side content title: <em>%title</em>", array('%title' => $default_title)), |
| 174 |
|
'#size' => 50, |
| 175 |
|
'#maxlength' => 128 |
| 176 |
|
); |
| 177 |
|
|
| 178 |
|
$content_default = (empty($node->sidecontent)) ? '' : check_markup($node->sidecontent, $node->sidecontent_format); |
| 179 |
|
|
| 180 |
|
$form['sidecontent']['sidecontent'] = array( |
| 181 |
|
'#type' => 'textarea', |
| 182 |
|
'#title' => t('Side Content Text'), |
| 183 |
|
'#default_value' => $content_default, |
| 184 |
|
'#description' => t('Content to display in side block.'), |
| 185 |
|
'#cols' => 60, |
| 186 |
|
'#rows' => 20, |
| 187 |
|
); |
| 188 |
|
|
| 189 |
|
if (variable_get('sidecontent_show_input_format', true)) { |
| 190 |
|
$form['sidecontent']['sidecontent_format'] = filter_form($node->sidecontent_format, NULL, array('sidecontent_format')); |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
} |
| 194 |
|
} |
| 195 |
|
|
| 196 |
|
} |
| 197 |
|
|
| 198 |
|
|
| 199 |
|
/** |
| 200 |
|
* Implementation of hook_nodeapi. |
| 201 |
|
*/ |
| 202 |
|
function sidecontent_nodeapi(&$node, $op, $teaser, $page) { |
| 203 |
|
|
| 204 |
|
switch ($op) { |
| 205 |
|
|
| 206 |
|
case 'load': |
| 207 |
|
|
| 208 |
|
if (!user_access('access side content') && !user_access('create side content' )) break; |
| 209 |
|
|
| 210 |
|
$results = db_fetch_object(db_query("SELECT * FROM {sidecontent} WHERE nid = %d", $node->nid)); |
| 211 |
|
if ($results) { |
| 212 |
|
$node->sidecontent_title = $results->sidetitle; |
| 213 |
|
$node->sidecontent = $results->sidecontent; |
| 214 |
|
$node->sidecontent_format = $results->format; |
| 215 |
|
} |
| 216 |
|
break; |
| 217 |
|
|
| 218 |
|
case 'validate': |
| 219 |
|
|
| 220 |
|
if (!variable_get('sidecontent_'. $node->type, 1)) break; |
| 221 |
|
if (!user_access('create side content' )) break; |
| 222 |
|
$node->sidecontent = rtrim($node->sidecontent); |
| 223 |
|
break; |
| 224 |
|
|
| 225 |
|
case 'insert': |
| 226 |
|
|
| 227 |
|
if (!variable_get('sidecontent_'. $node->type, 1)) break; |
| 228 |
|
if (empty($node->sidecontent)) return; |
| 229 |
|
if (!user_access('create side content' )) break; |
| 230 |
|
|
| 231 |
|
if (!variable_get('sidecontent_show_input_format', true)) $node->sidecontent_format = FILTER_FORMAT_DEFAULT; |
| 232 |
|
|
| 233 |
|
db_query("DELETE FROM {sidecontent} WHERE nid = %d", $node->nid); |
| 234 |
|
db_query("INSERT INTO {sidecontent} (nid, format, sidetitle, sidecontent) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->sidecontent_format, $node->sidecontent_title, $node->sidecontent); |
| 235 |
|
break; |
| 236 |
|
|
| 237 |
|
case 'update': |
| 238 |
|
|
| 239 |
|
if (!variable_get('sidecontent_'. $node->type, 1)) break; |
| 240 |
|
if (!user_access('create side content' )) break; |
| 241 |
|
db_query("DELETE FROM {sidecontent} WHERE nid = %d", $node->nid); |
| 242 |
|
|
| 243 |
|
if (empty($node->sidecontent)) return; |
| 244 |
|
|
| 245 |
|
if (!variable_get('sidecontent_show_input_format', true)) $node->sidecontent_format = FILTER_FORMAT_DEFAULT; |
| 246 |
|
db_query("INSERT INTO {sidecontent} (nid, format, sidetitle, sidecontent) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->sidecontent_format, $node->sidecontent_title, $node->sidecontent); |
| 247 |
|
break; |
| 248 |
|
|
| 249 |
|
case 'view': |
| 250 |
|
|
| 251 |
|
// add sidecontent into print view pages |
| 252 |
|
if (arg(2) == 'print' && !empty($node->sidecontent)) { |
| 253 |
|
|
| 254 |
|
$print = variable_get('sidecontent_print', false); |
| 255 |
|
if (empty($print)) break; |
| 256 |
|
|
| 257 |
|
// does user have access to view sidecontent? |
| 258 |
|
if (!user_access('access side content') && !user_access('create side content' )) break; |
| 259 |
|
|
| 260 |
|
$sidecontent = check_markup($node->sidecontent, $node->format); |
| 261 |
|
|
| 262 |
|
// note: print module disregards theme, so we have to include our markup here - yuuk! |
| 263 |
|
$node->content['sidecontent'] = array( |
| 264 |
|
'#value' => '<div class="sidecontent-print">' . $sidecontent . '</div>', |
| 265 |
|
'#weight' => -10, |
| 266 |
|
); |
| 267 |
|
} |
| 268 |
|
|
| 269 |
|
break; |
| 270 |
|
|
| 271 |
|
case 'delete': |
| 272 |
|
|
| 273 |
|
if (!variable_get('sidecontent_'. $node->type, 1)) break; |
| 274 |
|
if (!user_access('create side content' )) break; |
| 275 |
|
db_query("DELETE FROM {sidecontent} WHERE nid = %d", $node->nid); |
| 276 |
|
break; |
| 277 |
|
|
| 278 |
|
case 'update index': |
| 279 |
|
|
| 280 |
|
if (!variable_get('sidecontent_'. $node->type, 1)) break; |
| 281 |
|
if (!user_access('create side content' )) break; |
| 282 |
|
if (!variable_get('sidecontent_show_input_format', true)) $node->sidecontent_format = FILTER_FORMAT_DEFAULT; |
| 283 |
|
$text = check_markup($node->sidecontent, $node->sidecontent_format); |
| 284 |
|
return $text; |
| 285 |
|
} |
| 286 |
|
} |