| blib/lib/Drupal/Module/Starter/4_6_2.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 0 | 5 | 0.0 |
| branch | n/a | ||
| condition | n/a | ||
| subroutine | 0 | 2 | 0.0 |
| pod | 2 | 2 | 100.0 |
| total | 2 | 9 | 22.2 |
| line | stmt | bran | cond | sub | pod | time | code | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | package Drupal::Module::Starter::4_6_2; | |||||||||||||
| 2 | ||||||||||||||
| 3 | ||||||||||||||
| 4 | ||||||||||||||
| 5 | =head1 NAME | |||||||||||||
| 6 | ||||||||||||||
| 7 | Drupal::Module::Starter::4_6_2 - stub php code for 4.6.2 hooks | |||||||||||||
| 8 | ||||||||||||||
| 9 | =head1 VERSION | |||||||||||||
| 10 | ||||||||||||||
| 11 | Version 0.01 | |||||||||||||
| 12 | ||||||||||||||
| 13 | =cut | |||||||||||||
| 14 | ||||||||||||||
| 15 | our $VERSION = '0.01'; | |||||||||||||
| 16 | ||||||||||||||
| 17 | # stub code for each hook | |||||||||||||
| 18 | our $stubs = { | |||||||||||||
| 19 | hook_access => q!function MODULENAME_access($op, $node) { | |||||||||||||
| 20 | global $user; | |||||||||||||
| 21 | if ($op == 'create') { | |||||||||||||
| 22 | return user_access('create MODULENAMEs'); | |||||||||||||
| 23 | } | |||||||||||||
| 24 | ||||||||||||||
| 25 | if ($op == 'update' || $op == 'delete') { | |||||||||||||
| 26 | if (user_access('edit own MODULENAMEs') && ($user->uid == $node->uid)) { | |||||||||||||
| 27 | return TRUE; | |||||||||||||
| 28 | } | |||||||||||||
| 29 | } | |||||||||||||
| 30 | }!, | |||||||||||||
| 31 | ||||||||||||||
| 32 | hook_auth => q| | |||||||||||||
| 33 | function MODULENAME_auth($username, $password, $server) { | |||||||||||||
| 34 | /* return TRUE for a valid authentication, FALSE otherwise */ | |||||||||||||
| 35 | ||||||||||||||
| 36 | $message = new xmlrpcmsg('drupal.login', array(new xmlrpcval($username, | |||||||||||||
| 37 | 'string'), new xmlrpcval($password, 'string'))); | |||||||||||||
| 38 | ||||||||||||||
| 39 | $client = new xmlrpc_client('/xmlrpc.php', $server, 80); | |||||||||||||
| 40 | $result = $client->send($message, 5); | |||||||||||||
| 41 | if ($result && !$result->faultCode()) { | |||||||||||||
| 42 | $value = $result->value(); | |||||||||||||
| 43 | $login = $value->scalarval(); | |||||||||||||
| 44 | } | |||||||||||||
| 45 | ||||||||||||||
| 46 | return $login; | |||||||||||||
| 47 | }|, | |||||||||||||
| 48 | ||||||||||||||
| 49 | hook_block => q| | |||||||||||||
| 50 | function MODULENAME_block($op = 'list', $delta = 0, $edit = array()) { | |||||||||||||
| 51 | if ($op == 'list') { | |||||||||||||
| 52 | $blocks[0]['info'] = t('Mymodule block #1 shows ...'); | |||||||||||||
| 53 | $blocks[1]['info'] = t('Mymodule block #2 describes ...'); | |||||||||||||
| 54 | return $blocks; | |||||||||||||
| 55 | } | |||||||||||||
| 56 | else if ($op == 'configure' && $delta == 0) { | |||||||||||||
| 57 | return form_select(t('Number of items'), 'items', variable_get('mymodule_block_items', 0), array('1', '2', '3')); | |||||||||||||
| 58 | } | |||||||||||||
| 59 | else if ($op == 'save' && $delta == 0) { | |||||||||||||
| 60 | variable_set('mymodule_block_items', $edit['items']); | |||||||||||||
| 61 | } | |||||||||||||
| 62 | else if ($op == 'view') { | |||||||||||||
| 63 | switch($delta) { | |||||||||||||
| 64 | case 0: | |||||||||||||
| 65 | $block['subject'] = t('Title of block #1'); | |||||||||||||
| 66 | $block['content'] = mymodule_display_block_1(); | |||||||||||||
| 67 | break; | |||||||||||||
| 68 | case 1: | |||||||||||||
| 69 | $block['subject'] = t('Title of block #2'); | |||||||||||||
| 70 | $block['content'] = mymodule_display_block_2(); | |||||||||||||
| 71 | break; | |||||||||||||
| 72 | } | |||||||||||||
| 73 | return $block; | |||||||||||||
| 74 | } | |||||||||||||
| 75 | }|, | |||||||||||||
| 76 | ||||||||||||||
| 77 | hook_comment => q! | |||||||||||||
| 78 | function MODULENAME_comment($op, $comment) { | |||||||||||||
| 79 | if ($op == 'insert' || $op == 'update') { | |||||||||||||
| 80 | $nid = $comment['nid']; | |||||||||||||
| 81 | } | |||||||||||||
| 82 | cache_clear_all_like(drupal_url(array('id' => $nid))); | |||||||||||||
| 83 | }!, | |||||||||||||
| 84 | ||||||||||||||
| 85 | hook_cron => q! | |||||||||||||
| 86 | function MODULENAME_cron() { | |||||||||||||
| 87 | $result = db_query('SELECT * FROM {site} WHERE checked = 0 OR checked | |||||||||||||
| 88 | + refresh < %d', time()); | |||||||||||||
| 89 | ||||||||||||||
| 90 | while ($site = db_fetch_array($result)) { | |||||||||||||
| 91 | cloud_update($site); | |||||||||||||
| 92 | } | |||||||||||||
| 93 | }!, | |||||||||||||
| 94 | ||||||||||||||
| 95 | hook_db_rewrite_sql => q| | |||||||||||||
| 96 | function MODULENAME_db_rewrite_sql($query, $primary_table, $primary_field, $args) { | |||||||||||||
| 97 | switch ($primary_field) { | |||||||||||||
| 98 | case 'nid': | |||||||||||||
| 99 | // this query deals with node objects | |||||||||||||
| 100 | $return = array(); | |||||||||||||
| 101 | if ($primary_table != 'n') { | |||||||||||||
| 102 | $return['join'] = "LEFT JOIN {node} n ON $primary_table.nid = n.nid"; | |||||||||||||
| 103 | } | |||||||||||||
| 104 | $return['where'] = 'created >' . mktime(0, 0, 0, 1, 1, 2005); | |||||||||||||
| 105 | return $return; | |||||||||||||
| 106 | break; | |||||||||||||
| 107 | case 'tid': | |||||||||||||
| 108 | // this query deals with taxonomy objects | |||||||||||||
| 109 | break; | |||||||||||||
| 110 | case 'vid': | |||||||||||||
| 111 | // this query deals with vocabulary objects | |||||||||||||
| 112 | break; | |||||||||||||
| 113 | } | |||||||||||||
| 114 | } |, | |||||||||||||
| 115 | ||||||||||||||
| 116 | hook_delete => q! | |||||||||||||
| 117 | function MODULENAME_delete(&$node) { | |||||||||||||
| 118 | db_query('DELETE FROM {mytable} WHERE nid = %d', $node->nid); | |||||||||||||
| 119 | }!, | |||||||||||||
| 120 | ||||||||||||||
| 121 | hook_exit => q! | |||||||||||||
| 122 | function MODULENAME_exit($destination = NULL) { | |||||||||||||
| 123 | db_query('UPDATE {counter} SET hits = hits + 1 WHERE type = 1'); | |||||||||||||
| 124 | }!, | |||||||||||||
| 125 | ||||||||||||||
| 126 | hook_filter => q! | |||||||||||||
| 127 | function MODULENAME_filter($op, $delta = 0, $format = -1, $text = '') { | |||||||||||||
| 128 | switch ($op) { | |||||||||||||
| 129 | case 'list': | |||||||||||||
| 130 | return array(0 => t('Code filter')); | |||||||||||||
| 131 | ||||||||||||||
| 132 | case 'description': | |||||||||||||
| 133 | return t('Allows users to post code verbatim using <code> and <?php ?> tags.'); | |||||||||||||
| 134 | ||||||||||||||
| 135 | case 'prepare': | |||||||||||||
| 136 | // Note: we use the bytes 0xFE and 0xFF to replace < > during the filtering process. | |||||||||||||
| 137 | // These bytes are not valid in UTF-8 data and thus least likely to cause problems. | |||||||||||||
| 138 | $text = preg_replace('@(.+?)@se', "'\xFEcode\xFF'. codefilter_escape('\\1') .'\xFE/code\xFF'", $text); |
|||||||||||||
| 139 | $text = preg_replace('@<(\?(php)?|%)(.+?)(\?|%)>@se', "'\xFEphp\xFF'. codefilter_escape('\\3') .'\xFE/php\xFF'", $text); | |||||||||||||
| 140 | return $text; | |||||||||||||
| 141 | ||||||||||||||
| 142 | case "process": | |||||||||||||
| 143 | $text = preg_replace('@\xFEcode\xFF(.+?)\xFE/code\xFF@se', "codefilter_process_code('$1')", $text); | |||||||||||||
| 144 | $text = preg_replace('@\xFEphp\xFF(.+?)\xFE/php\xFF@se', "codefilter_process_php('$1')", $text); | |||||||||||||
| 145 | return $text; | |||||||||||||
| 146 | ||||||||||||||
| 147 | default: | |||||||||||||
| 148 | return $text; | |||||||||||||
| 149 | } | |||||||||||||
| 150 | } !, | |||||||||||||
| 151 | ||||||||||||||
| 152 | hook_filter_tips => q! | |||||||||||||
| 153 | function MODULENAME_filter_tips($delta, $format, $long = false) { | |||||||||||||
| 154 | if ($long) { | |||||||||||||
| 155 | return t('To post pieces of code, surround them with <code>...</code> tags. For PHP code, you can use <?php ... ?>, which will also colour it based on syntax.'); | |||||||||||||
| 156 | } | |||||||||||||
| 157 | else { | |||||||||||||
| 158 | return t('You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.'); | |||||||||||||
| 159 | } | |||||||||||||
| 160 | } !, | |||||||||||||
| 161 | ||||||||||||||
| 162 | hook_footer => q! | |||||||||||||
| 163 | function MODULENAME_footer($main = 0) { | |||||||||||||
| 164 | if (variable_get('dev_query', 0)) { | |||||||||||||
| 165 | print ' '. devel_query_table() .' '; |
|||||||||||||
| 166 | } | |||||||||||||
| 167 | }!, | |||||||||||||
| 168 | ||||||||||||||
| 169 | hook_form => q! | |||||||||||||
| 170 | function MODULENAME_form(&$node, &$param) { | |||||||||||||
| 171 | if (function_exists('taxonomy_node_form')) { | |||||||||||||
| 172 | $output = implode('', taxonomy_node_form('example', $node)); | |||||||||||||
| 173 | } | |||||||||||||
| 174 | ||||||||||||||
| 175 | $output .= form_textfield(t('Custom field'), 'field1', $node->field1, 60, | |||||||||||||
| 176 | 127); | |||||||||||||
| 177 | $output .= form_select(t('Select box'), 'selectbox', $node->selectbox, | |||||||||||||
| 178 | array (1 => 'Option A', 2 => 'Option B', 3 => 'Option C'), | |||||||||||||
| 179 | t('Please choose an option.')); | |||||||||||||
| 180 | ||||||||||||||
| 181 | return $output; | |||||||||||||
| 182 | }!, | |||||||||||||
| 183 | ||||||||||||||
| 184 | hook_help => q! | |||||||||||||
| 185 | function MODULENAME_help($section) { | |||||||||||||
| 186 | switch ($section) { | |||||||||||||
| 187 | case 'admin/help#block': | |||||||||||||
| 188 | return t(' Blocks are the boxes visible in the sidebar(s) |
|||||||||||||
| 189 | of your web site. These are usually generated automatically by | |||||||||||||
| 190 | modules (e.g. recent forum topics), but you can also create your | |||||||||||||
| 191 | own blocks using either static HTML or dynamic PHP content.'); | |||||||||||||
| 192 | break; | |||||||||||||
| 193 | case 'admin/modules#description': | |||||||||||||
| 194 | return t('Controls the boxes that are displayed around the main content.'); | |||||||||||||
| 195 | break; | |||||||||||||
| 196 | } | |||||||||||||
| 197 | }!, | |||||||||||||
| 198 | ||||||||||||||
| 199 | hook_info => q! | |||||||||||||
| 200 | function MODULENAME_info($field = 0) { | |||||||||||||
| 201 | $info['name'] = 'Drupal'; | |||||||||||||
| 202 | $info['protocol'] = 'XML-RPC'; | |||||||||||||
| 203 | ||||||||||||||
| 204 | if ($field) { | |||||||||||||
| 205 | return $info[$field]; | |||||||||||||
| 206 | } | |||||||||||||
| 207 | else { | |||||||||||||
| 208 | return $info; | |||||||||||||
| 209 | } | |||||||||||||
| 210 | }!, | |||||||||||||
| 211 | ||||||||||||||
| 212 | hook_init => q| | |||||||||||||
| 213 | function MODULENAME_init() { | |||||||||||||
| 214 | global $recent_activity; | |||||||||||||
| 215 | ||||||||||||||
| 216 | if ((variable_get('statistics_enable_auto_throttle', 0)) && | |||||||||||||
| 217 | (!rand(0, variable_get('statistics_probability_limiter', 9)))) { | |||||||||||||
| 218 | ||||||||||||||
| 219 | $throttle = throttle_status(); | |||||||||||||
| 220 | // if we're at throttle level 5, we don't do anything | |||||||||||||
| 221 | if ($throttle < 5) { | |||||||||||||
| 222 | $multiplier = variable_get('statistics_throttle_multiplier', 60); | |||||||||||||
| 223 | // count all hits in past sixty seconds | |||||||||||||
| 224 | $result = db_query('SELECT COUNT(timestamp) AS hits FROM | |||||||||||||
| 225 | {accesslog} WHERE timestamp >= %d', (time() - 60)); | |||||||||||||
| 226 | $recent_activity = db_fetch_array($result); | |||||||||||||
| 227 | throttle_update($recent_activity['hits']); | |||||||||||||
| 228 | } | |||||||||||||
| 229 | } | |||||||||||||
| 230 | }|, | |||||||||||||
| 231 | ||||||||||||||
| 232 | hook_insert => q! | |||||||||||||
| 233 | function MODULENAME_insert($node) { | |||||||||||||
| 234 | db_query("INSERT INTO {mytable} (nid, extra) | |||||||||||||
| 235 | VALUES (%d, '%s')", $node->nid, $node->extra); | |||||||||||||
| 236 | }!, | |||||||||||||
| 237 | ||||||||||||||
| 238 | hook_link => q| | |||||||||||||
| 239 | function MODULENAME_link($type, $node = NULL, $teaser = FALSE) { | |||||||||||||
| 240 | $links = array(); | |||||||||||||
| 241 | ||||||||||||||
| 242 | if ($type == 'node' && $node->type == 'book') { | |||||||||||||
| 243 | if (MODULENAME_access('update', $node)) { | |||||||||||||
| 244 | $links[] = l(t('edit this page'), "node/$node->nid/edit", | |||||||||||||
| 245 | array('title' => t('Suggest an update for this book page.'))); | |||||||||||||
| 246 | } | |||||||||||||
| 247 | if (!$teaser) { | |||||||||||||
| 248 | $links[] = l(t('printer-friendly version'), "book/print/$node->nid", | |||||||||||||
| 249 | array('title' => t('Show a printer-friendly version of this book page | |||||||||||||
| 250 | and its sub-pages.'))); | |||||||||||||
| 251 | } | |||||||||||||
| 252 | } | |||||||||||||
| 253 | ||||||||||||||
| 254 | return $links; | |||||||||||||
| 255 | }|, | |||||||||||||
| 256 | ||||||||||||||
| 257 | hook_load => q! | |||||||||||||
| 258 | function MODULENAME_load($node) { | |||||||||||||
| 259 | $additions = db_fetch_object(db_query('SELECT * FROM {mytable} WHERE nid = %s', $node->nid)); | |||||||||||||
| 260 | return $additions; | |||||||||||||
| 261 | }!, | |||||||||||||
| 262 | ||||||||||||||
| 263 | hook_menu => q! | |||||||||||||
| 264 | function MODULENAME_menu($may_cache) { | |||||||||||||
| 265 | global $user; | |||||||||||||
| 266 | $items = array(); | |||||||||||||
| 267 | ||||||||||||||
| 268 | if ($may_cache) { | |||||||||||||
| 269 | $items[] = array('path' => 'node/add/blog', 'title' => t('blog entry'), | |||||||||||||
| 270 | 'access' => user_access('maintain personal blog')); | |||||||||||||
| 271 | $items[] = array('path' => 'blog', 'title' => t('blogs'), | |||||||||||||
| 272 | 'callback' => 'blog_page', | |||||||||||||
| 273 | 'access' => user_access('access content'), | |||||||||||||
| 274 | 'type' => MENU_SUGGESTED_ITEM); | |||||||||||||
| 275 | $items[] = array('path' => 'blog/'. $user->uid, 'title' => t('my blog'), | |||||||||||||
| 276 | 'access' => user_access('maintain personal blog'), | |||||||||||||
| 277 | 'type' => MENU_DYNAMIC_ITEM); | |||||||||||||
| 278 | $items[] = array('path' => 'blog/feed', 'title' => t('RSS feed'), | |||||||||||||
| 279 | 'callback' => 'blog_feed', | |||||||||||||
| 280 | 'access' => user_access('access content'), | |||||||||||||
| 281 | 'type' => MENU_CALLBACK); | |||||||||||||
| 282 | } | |||||||||||||
| 283 | return $items; | |||||||||||||
| 284 | }!, | |||||||||||||
| 285 | ||||||||||||||
| 286 | hook_nodeapi => q! | |||||||||||||
| 287 | function MODULENAME_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { | |||||||||||||
| 288 | switch ($op) { | |||||||||||||
| 289 | case 'fields': | |||||||||||||
| 290 | return array('score', 'users', 'votes'); | |||||||||||||
| 291 | case 'validate': | |||||||||||||
| 292 | if ($node->nid && $node->moderate) { | |||||||||||||
| 293 | // Reset votes when node is updated: | |||||||||||||
| 294 | $node->score = 0; | |||||||||||||
| 295 | $node->users = ''; | |||||||||||||
| 296 | $node->votes = 0; | |||||||||||||
| 297 | } | |||||||||||||
| 298 | break; | |||||||||||||
| 299 | case 'insert': | |||||||||||||
| 300 | case 'update': | |||||||||||||
| 301 | if ($node->moderate && user_access('access submission queue')) { | |||||||||||||
| 302 | print theme('box', t('Post queued'), t('The post is queued for approval. | |||||||||||||
| 303 | You can check the votes in the submission | |||||||||||||
| 304 | queue.', array('%queue' => url('queue')))); | |||||||||||||
| 305 | } | |||||||||||||
| 306 | elseif ($node->moderate) { | |||||||||||||
| 307 | print theme('box', t('Post queued'), t('The post is queued for approval. | |||||||||||||
| 308 | The editors will decide whether it should be published.')); | |||||||||||||
| 309 | } | |||||||||||||
| 310 | else { | |||||||||||||
| 311 | print theme('box', t('Post published'), t('The post is published.')); | |||||||||||||
| 312 | } | |||||||||||||
| 313 | break; | |||||||||||||
| 314 | } | |||||||||||||
| 315 | }!, | |||||||||||||
| 316 | ||||||||||||||
| 317 | hook_node_grants => q! | |||||||||||||
| 318 | function MODULENAME_node_grants($user, $op) { | |||||||||||||
| 319 | $grants = array(); | |||||||||||||
| 320 | if ($op == 'view') { | |||||||||||||
| 321 | if (user_access('access content')) { | |||||||||||||
| 322 | $grants[] = 0; | |||||||||||||
| 323 | } | |||||||||||||
| 324 | if (user_access('access private content')) { | |||||||||||||
| 325 | $grants[] = 1; | |||||||||||||
| 326 | } | |||||||||||||
| 327 | } | |||||||||||||
| 328 | if ($op == 'update' || $op == 'delete') { | |||||||||||||
| 329 | if (user_access('edit content')) { | |||||||||||||
| 330 | $grants[] = 0; | |||||||||||||
| 331 | } | |||||||||||||
| 332 | if (user_access('edit private content')) { | |||||||||||||
| 333 | $grants[] = 1; | |||||||||||||
| 334 | } | |||||||||||||
| 335 | } | |||||||||||||
| 336 | return array('example' => $grants); | |||||||||||||
| 337 | }!, | |||||||||||||
| 338 | ||||||||||||||
| 339 | hook_node_name => q|function MODULENAME_node_name($node) { | |||||||||||||
| 340 | return MODULENAME; | |||||||||||||
| 341 | }|, | |||||||||||||
| 342 | ||||||||||||||
| 343 | hook_node_types => q!function MODULENAME_node_types() { | |||||||||||||
| 344 | return array('project-issue', 'project-project'); | |||||||||||||
| 345 | }!, | |||||||||||||
| 346 | ||||||||||||||
| 347 | hook_onload => q!function MODULENAME_onload() { | |||||||||||||
| 348 | return array('my_javascript_function()'); | |||||||||||||
| 349 | }!, | |||||||||||||
| 350 | ||||||||||||||
| 351 | ||||||||||||||
| 352 | ||||||||||||||
| 353 | ||||||||||||||
| 354 | ||||||||||||||
| 355 | hook_perm => q!function MODULENAME_perm() { | |||||||||||||
| 356 | return array('create MODULENAME', 'edit own MODULENAMEs'); | |||||||||||||
| 357 | }!, | |||||||||||||
| 358 | ||||||||||||||
| 359 | hook_ping => q"function MODULENAME_ping($name = '', $url = '') { | |||||||||||||
| 360 | $feed = url('node/feed'); | |||||||||||||
| 361 | ||||||||||||||
| 362 | $client = new xmlrpc_client('/RPC2', 'rpc.weblogs.com', 80); | |||||||||||||
| 363 | ||||||||||||||
| 364 | $message = new xmlrpcmsg('weblogUpdates.ping', | |||||||||||||
| 365 | array(new xmlrpcval($name), new xmlrpcval($url))); | |||||||||||||
| 366 | ||||||||||||||
| 367 | $result = $client->send($message); | |||||||||||||
| 368 | ||||||||||||||
| 369 | if (!$result || $result->faultCode()) { | |||||||||||||
| 370 | watchdog('error', 'failed to notify \'weblogs.com\' (site)'); | |||||||||||||
| 371 | } | |||||||||||||
| 372 | ||||||||||||||
| 373 | unset($client); | |||||||||||||
| 374 | }" , | |||||||||||||
| 375 | ||||||||||||||
| 376 | hook_search => q!function MODULENAME_search($op = 'search', $keys = null) { | |||||||||||||
| 377 | switch ($op) { | |||||||||||||
| 378 | case 'name': | |||||||||||||
| 379 | return t('content'); | |||||||||||||
| 380 | case 'reset': | |||||||||||||
| 381 | variable_del('node_cron_last'); | |||||||||||||
| 382 | return; | |||||||||||||
| 383 | case 'search': | |||||||||||||
| 384 | $find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid '. node_access_join_sql() .' INNER JOIN {users} u ON n.uid = u.uid', 'n.status = 1 AND '. node_access_where_sql()); | |||||||||||||
| 385 | $results = array(); | |||||||||||||
| 386 | foreach ($find as $item) { | |||||||||||||
| 387 | $node = node_load(array('nid' => $item)); | |||||||||||||
| 388 | $extra = node_invoke_nodeapi($node, 'search result'); | |||||||||||||
| 389 | $results[] = array('link' => url('node/'. $item), | |||||||||||||
| 390 | 'type' => node_invoke($node, 'node_name'), | |||||||||||||
| 391 | 'title' => $node->title, | |||||||||||||
| 392 | 'user' => format_name($node), | |||||||||||||
| 393 | 'date' => $node->changed, | |||||||||||||
| 394 | 'extra' => $extra, | |||||||||||||
| 395 | 'snippet' => search_excerpt($keys, check_output($node->body, $node->format))); | |||||||||||||
| 396 | } | |||||||||||||
| 397 | return $results; | |||||||||||||
| 398 | } | |||||||||||||
| 399 | } !, | |||||||||||||
| 400 | ||||||||||||||
| 401 | hook_search_item => q!function MODULENAME_search_item($item) { | |||||||||||||
| 402 | $output .= ' 403 | .'">'. $item['title'] .' '; |
||||||||||||
| 404 | $output .= ' ' . $item['description'] . ''; | |||||||||||||
| 405 | $output .= ' '; |
|||||||||||||
| 406 | ||||||||||||||
| 407 | return $output; | |||||||||||||
| 408 | }!, | |||||||||||||
| 409 | ||||||||||||||
| 410 | hook_search_preprocess => q!function MODULENAME_search_preprocess($text) { | |||||||||||||
| 411 | // Do processing on $text | |||||||||||||
| 412 | return $text; | |||||||||||||
| 413 | }!, | |||||||||||||
| 414 | ||||||||||||||
| 415 | hook_settings => q!function MODULENAME_settings() { | |||||||||||||
| 416 | $output = form_textfield(t('Setting A'), 'example_a', | |||||||||||||
| 417 | variable_get('example_a', 'Default setting'), 20, 255, | |||||||||||||
| 418 | t('A description of this setting.')); | |||||||||||||
| 419 | $output .= form_checkbox(t('Setting B'), 'example_b', 1, | |||||||||||||
| 420 | variable_get('example_b', 0), t('A description of this setting.')); | |||||||||||||
| 421 | return $output; | |||||||||||||
| 422 | }!, | |||||||||||||
| 423 | ||||||||||||||
| 424 | ||||||||||||||
| 425 | hook_taxonomy => q!function MODULENAME_taxonomy($op, $type, $object) { | |||||||||||||
| 426 | if ($type == 'vocabulary' && ($op == 'insert' || $op == 'update')) { | |||||||||||||
| 427 | if (variable_get('forum_nav_vocabulary', '') == '' | |||||||||||||
| 428 | && in_array('forum', $object['nodes'])) { | |||||||||||||
| 429 | // since none is already set, silently set this vocabulary as the navigation vocabulary | |||||||||||||
| 430 | variable_set('forum_nav_vocabulary', $object['vid']); | |||||||||||||
| 431 | } | |||||||||||||
| 432 | } | |||||||||||||
| 433 | }!, | |||||||||||||
| 434 | ||||||||||||||
| 435 | hook_textarea => q!function MODULENAME_textarea($op, $name) { | |||||||||||||
| 436 | global $htmlarea_init, $htmlarea_fields, $htmlarea_codeview; | |||||||||||||
| 437 | ||||||||||||||
| 438 | if ($op == 'pre') { | |||||||||||||
| 439 | $real_name = $name; | |||||||||||||
| 440 | $name = _htmlarea_parse_name($name); | |||||||||||||
| 441 | ||||||||||||||
| 442 | if (_htmlarea_is_changed($name)) { | |||||||||||||
| 443 | $htmlarea_init[] = "var $name = null;"; | |||||||||||||
| 444 | $htmlarea_fields[] = "attacheditor($name, '$name');"; | |||||||||||||
| 445 | } | |||||||||||||
| 446 | } | |||||||||||||
| 447 | }!, | |||||||||||||
| 448 | ||||||||||||||
| 449 | hook_update => q!function MODULENAME_update($node) { | |||||||||||||
| 450 | db_query("UPDATE {mytable} SET extra = '%s' WHERE nid = %d", | |||||||||||||
| 451 | $node->extra, $node->nid); | |||||||||||||
| 452 | } !, | |||||||||||||
| 453 | ||||||||||||||
| 454 | hook_update_index => q!function MODULENAME_update_index() { | |||||||||||||
| 455 | $last = variable_get('node_cron_last', 0); | |||||||||||||
| 456 | $limit = (int)variable_get('search_cron_limit', 100); | |||||||||||||
| 457 | ||||||||||||||
| 458 | $result = db_query_range('SELECT n.nid, c.last_comment_timestamp FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 AND (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d) ORDER BY GREATEST(n.created, n.changed, c.last_comment_timestamp) ASC', $last, $last, $last, 0, $limit); | |||||||||||||
| 459 | ||||||||||||||
| 460 | while ($node = db_fetch_object($result)) { | |||||||||||||
| 461 | $last_comment = $node->last_comment_timestamp; | |||||||||||||
| 462 | $node = node_load(array('nid' => $node->nid)); | |||||||||||||
| 463 | ||||||||||||||
| 464 | // We update this variable per node in case cron times out, or if the node | |||||||||||||
| 465 | // cannot be indexed (PHP nodes which call drupal_goto, for example). | |||||||||||||
| 466 | // In rare cases this can mean a node is only partially indexed, but the | |||||||||||||
| 467 | // chances of this happening are very small. | |||||||||||||
| 468 | variable_set('node_cron_last', max($last_comment, $node->changed, $node->created)); | |||||||||||||
| 469 | ||||||||||||||
| 470 | // Get node output (filtered and with module-specific fields). | |||||||||||||
| 471 | if (node_hook($node, 'view')) { | |||||||||||||
| 472 | node_invoke($node, 'view', false, false); | |||||||||||||
| 473 | } | |||||||||||||
| 474 | else { | |||||||||||||
| 475 | $node = node_prepare($node, false); | |||||||||||||
| 476 | } | |||||||||||||
| 477 | // Allow modules to change $node->body before viewing. | |||||||||||||
| 478 | node_invoke_nodeapi($node, 'view', false, false); | |||||||||||||
| 479 | ||||||||||||||
| 480 | $text = ''. drupal_specialchars($node->title) .''. $node->body; |
|||||||||||||
| 481 | ||||||||||||||
| 482 | // Fetch extra data normally not visible | |||||||||||||
| 483 | $extra = node_invoke_nodeapi($node, 'update index'); | |||||||||||||
| 484 | foreach ($extra as $t) { | |||||||||||||
| 485 | $text .= $t; | |||||||||||||
| 486 | } | |||||||||||||
| 487 | ||||||||||||||
| 488 | // Update index | |||||||||||||
| 489 | search_index($node->nid, 'node', $text); | |||||||||||||
| 490 | } | |||||||||||||
| 491 | }!, | |||||||||||||
| 492 | ||||||||||||||
| 493 | hook_user => q!function MODULENAME_user($op, &$edit, &$user, $category) { | |||||||||||||
| 494 | switch ($op) { | |||||||||||||
| 495 | case 'view': | |||||||||||||
| 496 | if ($user->signature) { | |||||||||||||
| 497 | return array('account' => form_item(t('Signature'), check_output($user->signature))); | |||||||||||||
| 498 | } | |||||||||||||
| 499 | break; | |||||||||||||
| 500 | case 'form': | |||||||||||||
| 501 | // When user tries to edit his own data: | |||||||||||||
| 502 | if ($category == 'account') { | |||||||||||||
| 503 | return array(array('title' => t('Personal information'), 'data' => form_textarea(t('Signature'), 'signature', $user->signature, 70, 3, t('Your signature will be publicly displayed at the end of your comments.') .' '. filter_tips_short()), 'weight' => 0)); |
|||||||||||||
| 504 | } | |||||||||||||
| 505 | } | |||||||||||||
| 506 | }!, | |||||||||||||
| 507 | ||||||||||||||
| 508 | hook_validate => q!function MODULENAME_validate(&$node) { | |||||||||||||
| 509 | if ($node) { | |||||||||||||
| 510 | if ($node->end && $node->start) { | |||||||||||||
| 511 | if ($node->start > $node->end) { | |||||||||||||
| 512 | form_set_error('time', t('An event may not end before it starts.')); | |||||||||||||
| 513 | } | |||||||||||||
| 514 | } | |||||||||||||
| 515 | } | |||||||||||||
| 516 | } !, | |||||||||||||
| 517 | ||||||||||||||
| 518 | hook_view => q!function MODULENAME_view(&$node, $teaser = FALSE, $page = FALSE) { | |||||||||||||
| 519 | if ($page) { | |||||||||||||
| 520 | $breadcrumb = array(); | |||||||||||||
| 521 | $breadcrumb[] = array('path' => 'example', 'title' => t('example')); | |||||||||||||
| 522 | $breadcrumb[] = array('path' => 'example/'. $node->field1, | |||||||||||||
| 523 | 'title' => t('%category', array('%category' => $node->field1))); | |||||||||||||
| 524 | $breadcrumb[] = array('path' => 'node/'. $node->nid); | |||||||||||||
| 525 | menu_set_location($breadcrumb); | |||||||||||||
| 526 | } | |||||||||||||
| 527 | ||||||||||||||
| 528 | $node = node_prepare($node, $teaser); | |||||||||||||
| 529 | }!, | |||||||||||||
| 530 | ||||||||||||||
| 531 | hook_xmlrpc => q!function MODULENAME_xmlrpc() { | |||||||||||||
| 532 | return array('drupal.site.ping' => array('function' => 'drupal_directory_ping'), | |||||||||||||
| 533 | 'drupal.login' => array('function' => 'drupal_login')); | |||||||||||||
| 534 | } !, | |||||||||||||
| 535 | ||||||||||||||
| 536 | clean_menu => q!function MODULENAME_menu($may_cache) { | |||||||||||||
| 537 | global $user; | |||||||||||||
| 538 | $items = array(); | |||||||||||||
| 539 | ||||||||||||||
| 540 | if ($may_cache) { | |||||||||||||
| 541 | ||||||||||||||
| 542 | MENU_ITEMLIST | |||||||||||||
| 543 | ||||||||||||||
| 544 | } | |||||||||||||
| 545 | return $items!, | |||||||||||||
| 546 | ||||||||||||||
| 547 | }; | |||||||||||||
| 548 | ||||||||||||||
| 549 | ||||||||||||||
| 550 | ||||||||||||||
| 551 | =head1 SYNOPSIS | |||||||||||||
| 552 | ||||||||||||||
| 553 | For this version, 4_6_2.pm is the only set of hooks provided. Other versions | |||||||||||||
| 554 | could easily be created | |||||||||||||
| 555 | ||||||||||||||
| 556 | =head1 FUNCTIONS | |||||||||||||
| 557 | ||||||||||||||
| 558 | =head2 new - constructor - no paramaters required | |||||||||||||
| 559 | ||||||||||||||
| 560 | =cut | |||||||||||||
| 561 | ||||||||||||||
| 562 | sub new { | |||||||||||||
| 563 | 0 | 0 | 1 | my ($self,$class) = ({},shift); | ||||||||||
| 564 | 0 | bless $stubs,$class; | ||||||||||||
| 565 | 0 | return $stubs; | ||||||||||||
| 566 | } | |||||||||||||
| 567 | ||||||||||||||
| 568 | =head2 stub - return a php function stub for the named parameter | |||||||||||||
| 569 | ||||||||||||||
| 570 | =cut | |||||||||||||
| 571 | ||||||||||||||
| 572 | sub stub { | |||||||||||||
| 573 | 0 | 0 | 1 | my $self = shift; | ||||||||||
| 574 | 0 | return $self->{stubs}->{shift}; | ||||||||||||
| 575 | } | |||||||||||||
| 576 | ||||||||||||||
| 577 | ||||||||||||||
| 578 | ||||||||||||||
| 579 | ||||||||||||||
| 580 | =head1 AUTHOR | |||||||||||||
| 581 | ||||||||||||||
| 582 | Steve McNabb, C<< |
|||||||||||||
| 583 | IT Director, F5 Site Design - http://www.f5sitedesign.com | |||||||||||||
| 584 | Open Source Internet Application Development | |||||||||||||
| 585 | ||||||||||||||
| 586 | =cut | |||||||||||||
| 587 | 1; |