| blib/lib/Drupal/Module/Starter/4_7_3.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 6 | 8 | 75.0 |
| branch | n/a | ||
| condition | n/a | ||
| subroutine | 2 | 3 | 66.6 |
| pod | 2 | 2 | 100.0 |
| total | 10 | 13 | 76.9 |
| line | stmt | bran | cond | sub | pod | time | code | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | package Drupal::Module::Starter::4_7_3; | |||||||||||||
| 2 | ||||||||||||||
| 3 | # 4_7_3_ hooks | |||||||||||||
| 4 | # | |||||||||||||
| 5 | # | |||||||||||||
| 6 | ||||||||||||||
| 7 | 4 | 4 | 26993 | use strict; | ||||||||||
| 4 | 8 | |||||||||||||
| 4 | 4014 | |||||||||||||
| 8 | ||||||||||||||
| 9 | ||||||||||||||
| 10 | our $stubs = { | |||||||||||||
| 11 | hook_access => q!function MODULENAME_access($op, $node) { | |||||||||||||
| 12 | global $user; | |||||||||||||
| 13 | ||||||||||||||
| 14 | if ($op == 'create') { | |||||||||||||
| 15 | return user_access('create stories'); | |||||||||||||
| 16 | } | |||||||||||||
| 17 | ||||||||||||||
| 18 | if ($op == 'update' || $op == 'delete') { | |||||||||||||
| 19 | if (user_access('edit own stories') && ($user->uid == $node->uid)) { | |||||||||||||
| 20 | return TRUE; | |||||||||||||
| 21 | } | |||||||||||||
| 22 | } | |||||||||||||
| 23 | } !, | |||||||||||||
| 24 | ||||||||||||||
| 25 | ||||||||||||||
| 26 | hook_auth => q!function MODULENAME_auth($username, $password, $server) { | |||||||||||||
| 27 | $message = new xmlrpcmsg('drupal.login', array(new xmlrpcval($username, | |||||||||||||
| 28 | 'string'), new xmlrpcval($password, 'string'))); | |||||||||||||
| 29 | ||||||||||||||
| 30 | $client = new xmlrpc_client('/xmlrpc.php', $server, 80); | |||||||||||||
| 31 | $result = $client->send($message, 5); | |||||||||||||
| 32 | if ($result && \!$result->faultCode()) { | |||||||||||||
| 33 | $value = $result->value(); | |||||||||||||
| 34 | $login = $value->scalarval(); | |||||||||||||
| 35 | } | |||||||||||||
| 36 | ||||||||||||||
| 37 | return $login; | |||||||||||||
| 38 | } !, | |||||||||||||
| 39 | ||||||||||||||
| 40 | ||||||||||||||
| 41 | hook_block => q!function MODULENAME_block($op = 'list', $delta = 0, $edit = array()) { | |||||||||||||
| 42 | if ($op == 'list') { | |||||||||||||
| 43 | $blocks[0] = array('info' => t('Mymodule block #1 shows ...'), | |||||||||||||
| 44 | 'weight' => 0, 'enabled' => 1, 'region' => 'left'); | |||||||||||||
| 45 | $blocks[1] = array('info' => t('Mymodule block #2 describes ...'), | |||||||||||||
| 46 | 'weight' => 0, 'enabled' => 0, 'region' => 'right'); | |||||||||||||
| 47 | return $blocks; | |||||||||||||
| 48 | } | |||||||||||||
| 49 | else if ($op == 'configure' && $delta == 0) { | |||||||||||||
| 50 | $form['items'] = array( | |||||||||||||
| 51 | '#type' => 'select', | |||||||||||||
| 52 | '#title' => t('Number of items'), | |||||||||||||
| 53 | '#default_value' => variable_get('mymodule_block_items', 0), | |||||||||||||
| 54 | '#options' => array('1', '2', '3'), | |||||||||||||
| 55 | ); | |||||||||||||
| 56 | return $form; | |||||||||||||
| 57 | } | |||||||||||||
| 58 | else if ($op == 'save' && $delta == 0) { | |||||||||||||
| 59 | variable_set('mymodule_block_items', $edit['items']); | |||||||||||||
| 60 | } | |||||||||||||
| 61 | else if ($op == 'view') { | |||||||||||||
| 62 | switch($delta) { | |||||||||||||
| 63 | case 0: | |||||||||||||
| 64 | $block = array('subject' => t('Title of block #1'), | |||||||||||||
| 65 | 'content' => mymodule_display_block_1()); | |||||||||||||
| 66 | break; | |||||||||||||
| 67 | case 1: | |||||||||||||
| 68 | $block = array('subject' => t('Title of block #2'), | |||||||||||||
| 69 | 'content' => mymodule_display_block_2()); | |||||||||||||
| 70 | break; | |||||||||||||
| 71 | } | |||||||||||||
| 72 | return $block; | |||||||||||||
| 73 | } | |||||||||||||
| 74 | } !, | |||||||||||||
| 75 | ||||||||||||||
| 76 | ||||||||||||||
| 77 | hook_comment => q!function MODULENAME_comment($comment, $op) { | |||||||||||||
| 78 | if ($op == 'insert' || $op == 'update') { | |||||||||||||
| 79 | $nid = $comment['nid']; | |||||||||||||
| 80 | } | |||||||||||||
| 81 | ||||||||||||||
| 82 | cache_clear_all_like(drupal_url(array('id' => $nid))); | |||||||||||||
| 83 | } !, | |||||||||||||
| 84 | ||||||||||||||
| 85 | ||||||||||||||
| 86 | hook_cron => q!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 | ||||||||||||||
| 96 | hook_db_rewrite_sql => q!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 | ||||||||||||||
| 117 | hook_delete => q!function MODULENAME_delete(&$node) { | |||||||||||||
| 118 | db_query('DELETE FROM {mytable} WHERE nid = %d', $node->nid); | |||||||||||||
| 119 | } !, | |||||||||||||
| 120 | ||||||||||||||
| 121 | ||||||||||||||
| 122 | hook_elements => q!function MODULENAME_elements() { | |||||||||||||
| 123 | $type['filter_format'] = array('#input' => TRUE); | |||||||||||||
| 124 | return $type; | |||||||||||||
| 125 | } !, | |||||||||||||
| 126 | ||||||||||||||
| 127 | ||||||||||||||
| 128 | hook_exit => q!function MODULENAME_exit($destination = NULL) { | |||||||||||||
| 129 | db_query('UPDATE {counter} SET hits = hits + 1 WHERE type = 1'); | |||||||||||||
| 130 | } !, | |||||||||||||
| 131 | ||||||||||||||
| 132 | ||||||||||||||
| 133 | hook_file_download => q!function MODULENAME_file_download($file) { | |||||||||||||
| 134 | if (user_access('access content')) { | |||||||||||||
| 135 | if ($filemime = db_result(db_query("SELECT filemime FROM {fileupload} WHERE filepath = '%s'", file_create_path($file)))) { | |||||||||||||
| 136 | return array('Content-type:' . $filemime); | |||||||||||||
| 137 | } | |||||||||||||
| 138 | } | |||||||||||||
| 139 | else { | |||||||||||||
| 140 | return -1; | |||||||||||||
| 141 | } | |||||||||||||
| 142 | } !, | |||||||||||||
| 143 | ||||||||||||||
| 144 | ||||||||||||||
| 145 | hook_filter => q!function MODULENAME_filter($op, $delta = 0, $format = -1, $text = '') { | |||||||||||||
| 146 | switch ($op) { | |||||||||||||
| 147 | case 'list': | |||||||||||||
| 148 | return array(0 => t('Code filter')); | |||||||||||||
| 149 | ||||||||||||||
| 150 | case 'description': | |||||||||||||
| 151 | return t('Allows users to post code verbatim using <code> and <?php ?> tags.'); | |||||||||||||
| 152 | ||||||||||||||
| 153 | case 'prepare': | |||||||||||||
| 154 | // Note: we use the bytes 0xFE and 0xFF to replace < > during the filtering process. | |||||||||||||
| 155 | // These bytes are not valid in UTF-8 data and thus least likely to cause problems. | |||||||||||||
| 156 | $text = preg_replace('@(.+?)@se', "'\xFEcode\xFF'. codefilter_escape('\\1') .'\xFE/code\xFF'", $text); |
|||||||||||||
| 157 | $text = preg_replace('@<(\?(php)?|%)(.+?)(\?|%)>@se', "'\xFEphp\xFF'. codefilter_escape('\\3') .'\xFE/php\xFF'", $text); | |||||||||||||
| 158 | return $text; | |||||||||||||
| 159 | ||||||||||||||
| 160 | case "process": | |||||||||||||
| 161 | $text = preg_replace('@\xFEcode\xFF(.+?)\xFE/code\xFF@se', "codefilter_process_code('$1')", $text); | |||||||||||||
| 162 | $text = preg_replace('@\xFEphp\xFF(.+?)\xFE/php\xFF@se', "codefilter_process_php('$1')", $text); | |||||||||||||
| 163 | return $text; | |||||||||||||
| 164 | ||||||||||||||
| 165 | default: | |||||||||||||
| 166 | return $text; | |||||||||||||
| 167 | } | |||||||||||||
| 168 | } !, | |||||||||||||
| 169 | ||||||||||||||
| 170 | ||||||||||||||
| 171 | hook_filter_tips => q!function MODULENAME_filter_tips($delta, $format, $long = false) { | |||||||||||||
| 172 | if ($long) { | |||||||||||||
| 173 | 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.'); | |||||||||||||
| 174 | } | |||||||||||||
| 175 | else { | |||||||||||||
| 176 | return t('You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.'); | |||||||||||||
| 177 | } | |||||||||||||
| 178 | } !, | |||||||||||||
| 179 | ||||||||||||||
| 180 | ||||||||||||||
| 181 | hook_footer => q!function MODULENAME_footer($main = 0) { | |||||||||||||
| 182 | if (variable_get('dev_query', 0)) { | |||||||||||||
| 183 | print ' '. devel_query_table() .' '; |
|||||||||||||
| 184 | } | |||||||||||||
| 185 | } !, | |||||||||||||
| 186 | ||||||||||||||
| 187 | ||||||||||||||
| 188 | hook_form => q!function MODULENAME_form(&$node, &$param) { | |||||||||||||
| 189 | $form['title'] = array( | |||||||||||||
| 190 | '#type'=> 'textfield', | |||||||||||||
| 191 | '#title' => t('Title'), | |||||||||||||
| 192 | '#required' => TRUE, | |||||||||||||
| 193 | ); | |||||||||||||
| 194 | $form['body'] = array( | |||||||||||||
| 195 | '#type' => 'textatea', | |||||||||||||
| 196 | '#title' => t('Description'), | |||||||||||||
| 197 | '#rows' => 20, | |||||||||||||
| 198 | '#required' => TRUE, | |||||||||||||
| 199 | ); | |||||||||||||
| 200 | $form['field1'] = array( | |||||||||||||
| 201 | '#type' => 'textfield', | |||||||||||||
| 202 | '#title' => t('Custom field'), | |||||||||||||
| 203 | '#default_value' => $node->field1, | |||||||||||||
| 204 | '#maxlength' => 127, | |||||||||||||
| 205 | ); | |||||||||||||
| 206 | $form['selectbox'] = array( | |||||||||||||
| 207 | '#type' => 'select', | |||||||||||||
| 208 | '#title' => t('Select box'), | |||||||||||||
| 209 | '#default_value' => $node->selectbox, | |||||||||||||
| 210 | '#options' => array( | |||||||||||||
| 211 | 1 => 'Option A', | |||||||||||||
| 212 | 2 => 'Option B', | |||||||||||||
| 213 | 3 => 'Option C', | |||||||||||||
| 214 | ), | |||||||||||||
| 215 | '#description' => t('Please choose an option.'), | |||||||||||||
| 216 | ); | |||||||||||||
| 217 | ||||||||||||||
| 218 | return $form; | |||||||||||||
| 219 | } !, | |||||||||||||
| 220 | ||||||||||||||
| 221 | ||||||||||||||
| 222 | hook_form_alter => q!function MODULENAME_form_alter($form_id, &$form) { | |||||||||||||
| 223 | if (isset($form['type']) && $form['type']['#value'] .'_node_settings' == $form_id) { | |||||||||||||
| 224 | $form['workflow']['upload_'. $form['type']['#value']] = array( | |||||||||||||
| 225 | '#type' => 'radios', | |||||||||||||
| 226 | '#title' => t('Attachments'), | |||||||||||||
| 227 | '#default_value' => variable_get('upload_'. $form['type']['#value'], 1), | |||||||||||||
| 228 | '#options' => array(t('Disabled'), t('Enabled')), | |||||||||||||
| 229 | ); | |||||||||||||
| 230 | } | |||||||||||||
| 231 | } !, | |||||||||||||
| 232 | ||||||||||||||
| 233 | ||||||||||||||
| 234 | hook_help => q!function MODULENAME_help($section) { | |||||||||||||
| 235 | switch ($section) { | |||||||||||||
| 236 | case 'admin/help#block': | |||||||||||||
| 237 | return t(' Blocks are the boxes visible in the sidebar(s) |
|||||||||||||
| 238 | of your web site. These are usually generated automatically by | |||||||||||||
| 239 | modules (e.g. recent forum topics), but you can also create your | |||||||||||||
| 240 | own blocks using either static HTML or dynamic PHP content.'); | |||||||||||||
| 241 | break; | |||||||||||||
| 242 | case 'admin/modules#description': | |||||||||||||
| 243 | return t('Controls the boxes that are displayed around the main content.'); | |||||||||||||
| 244 | break; | |||||||||||||
| 245 | } | |||||||||||||
| 246 | } !, | |||||||||||||
| 247 | ||||||||||||||
| 248 | ||||||||||||||
| 249 | hook_info => q!function MODULENAME_info($field = 0) { | |||||||||||||
| 250 | $info['name'] = 'Drupal'; | |||||||||||||
| 251 | $info['protocol'] = 'XML-RPC'; | |||||||||||||
| 252 | ||||||||||||||
| 253 | if ($field) { | |||||||||||||
| 254 | return $info[$field]; | |||||||||||||
| 255 | } | |||||||||||||
| 256 | else { | |||||||||||||
| 257 | return $info; | |||||||||||||
| 258 | } | |||||||||||||
| 259 | } !, | |||||||||||||
| 260 | ||||||||||||||
| 261 | ||||||||||||||
| 262 | hook_init => q!function MODULENAME_init() { | |||||||||||||
| 263 | global $recent_activity; | |||||||||||||
| 264 | ||||||||||||||
| 265 | if ((variable_get('statistics_enable_auto_throttle', 0)) && | |||||||||||||
| 266 | (\!rand(0, variable_get('statistics_probability_limiter', 9)))) { | |||||||||||||
| 267 | ||||||||||||||
| 268 | $throttle = throttle_status(); | |||||||||||||
| 269 | // if we're at throttle level 5, we don't do anything | |||||||||||||
| 270 | if ($throttle < 5) { | |||||||||||||
| 271 | $multiplier = variable_get('statistics_throttle_multiplier', 60); | |||||||||||||
| 272 | // count all hits in past sixty seconds | |||||||||||||
| 273 | $result = db_query('SELECT COUNT(timestamp) AS hits FROM | |||||||||||||
| 274 | {accesslog} WHERE timestamp >= %d', (time() - 60)); | |||||||||||||
| 275 | $recent_activity = db_fetch_array($result); | |||||||||||||
| 276 | throttle_update($recent_activity['hits']); | |||||||||||||
| 277 | } | |||||||||||||
| 278 | } | |||||||||||||
| 279 | } !, | |||||||||||||
| 280 | ||||||||||||||
| 281 | ||||||||||||||
| 282 | hook_insert => q!function MODULENAME_insert($node) { | |||||||||||||
| 283 | db_query("INSERT INTO {mytable} (nid, extra) | |||||||||||||
| 284 | VALUES (%d, '%s')", $node->nid, $node->extra); | |||||||||||||
| 285 | } !, | |||||||||||||
| 286 | ||||||||||||||
| 287 | ||||||||||||||
| 288 | hook_install => q!function MODULENAME_install() { | |||||||||||||
| 289 | switch ($GLOBALS['db_type']) { | |||||||||||||
| 290 | case 'mysql': | |||||||||||||
| 291 | case 'mysqli': | |||||||||||||
| 292 | db_query("CREATE TABLE {event} ( | |||||||||||||
| 293 | nid int(10) unsigned NOT NULL default '0', | |||||||||||||
| 294 | event_start int(10) unsigned NOT NULL default '0', | |||||||||||||
| 295 | event_end int(10) unsigned NOT NULL default '0', | |||||||||||||
| 296 | timezone int(10) NOT NULL default '0', | |||||||||||||
| 297 | PRIMARY KEY (nid), | |||||||||||||
| 298 | KEY event_start (event_start) | |||||||||||||
| 299 | ) TYPE=MyISAM /*\!40100 DEFAULT CHARACTER SET utf8 */;" | |||||||||||||
| 300 | ); | |||||||||||||
| 301 | break; | |||||||||||||
| 302 | ||||||||||||||
| 303 | case 'pgsql': | |||||||||||||
| 304 | db_query("CREATE TABLE {event} ( | |||||||||||||
| 305 | nid int NOT NULL default '0', | |||||||||||||
| 306 | event_start int NOT NULL default '0', | |||||||||||||
| 307 | event_end int NOT NULL default '0', | |||||||||||||
| 308 | timezone int NOT NULL default '0', | |||||||||||||
| 309 | PRIMARY KEY (nid) | |||||||||||||
| 310 | );" | |||||||||||||
| 311 | ); | |||||||||||||
| 312 | break; | |||||||||||||
| 313 | } | |||||||||||||
| 314 | } !, | |||||||||||||
| 315 | ||||||||||||||
| 316 | ||||||||||||||
| 317 | hook_link => q!function MODULENAME_link($type, $node = NULL, $teaser = FALSE) { | |||||||||||||
| 318 | $links = array(); | |||||||||||||
| 319 | ||||||||||||||
| 320 | if ($type == 'node' && $node->type == 'book') { | |||||||||||||
| 321 | if (book_access('update', $node)) { | |||||||||||||
| 322 | $links[] = l(t('edit this page'), "node/$node->nid/edit", | |||||||||||||
| 323 | array('title' => t('Suggest an update for this book page.'))); | |||||||||||||
| 324 | } | |||||||||||||
| 325 | if (\!$teaser) { | |||||||||||||
| 326 | $links[] = l(t('printer-friendly version'), "book/print/$node->nid", | |||||||||||||
| 327 | array('title' => t('Show a printer-friendly version of this book page | |||||||||||||
| 328 | and its sub-pages.'))); | |||||||||||||
| 329 | } | |||||||||||||
| 330 | } | |||||||||||||
| 331 | ||||||||||||||
| 332 | return $links; | |||||||||||||
| 333 | } !, | |||||||||||||
| 334 | ||||||||||||||
| 335 | ||||||||||||||
| 336 | hook_load => q!function MODULENAME_load($node) { | |||||||||||||
| 337 | $additions = db_fetch_object(db_query('SELECT * FROM {mytable} WHERE nid = %s', $node->nid)); | |||||||||||||
| 338 | return $additions; | |||||||||||||
| 339 | } !, | |||||||||||||
| 340 | ||||||||||||||
| 341 | ||||||||||||||
| 342 | hook_menu => q!function MODULENAME_menu($may_cache) { | |||||||||||||
| 343 | global $user; | |||||||||||||
| 344 | $items = array(); | |||||||||||||
| 345 | ||||||||||||||
| 346 | if ($may_cache) { | |||||||||||||
| 347 | ||||||||||||||
| 348 | $items[] = array( | |||||||||||||
| 349 | 'path' => 'your/path', | |||||||||||||
| 350 | 'title' => t('my path'), | |||||||||||||
| 351 | 'access' => user_access('my custom permission'), | |||||||||||||
| 352 | 'type' => MENU_NORMAL_ITEM); | |||||||||||||
| 353 | ||||||||||||||
| 354 | ||||||||||||||
| 355 | $items[] = array( | |||||||||||||
| 356 | 'path' => 'your/other/path', | |||||||||||||
| 357 | 'title' => t('my other path'), | |||||||||||||
| 358 | 'callback' => '_myFunction', | |||||||||||||
| 359 | 'access' => user_access('my custom permission'), | |||||||||||||
| 360 | 'type' => MENU_CALLBACK); | |||||||||||||
| 361 | } | |||||||||||||
| 362 | return $items; | |||||||||||||
| 363 | } !, | |||||||||||||
| 364 | ||||||||||||||
| 365 | ||||||||||||||
| 366 | hook_nodeapi => q!function MODULENAME_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { | |||||||||||||
| 367 | switch ($op) { | |||||||||||||
| 368 | case 'validate': | |||||||||||||
| 369 | if ($node->nid && $node->moderate) { | |||||||||||||
| 370 | // Reset votes when node is updated: | |||||||||||||
| 371 | $node->score = 0; | |||||||||||||
| 372 | $node->users = ''; | |||||||||||||
| 373 | $node->votes = 0; | |||||||||||||
| 374 | } | |||||||||||||
| 375 | break; | |||||||||||||
| 376 | case 'insert': | |||||||||||||
| 377 | case 'update': | |||||||||||||
| 378 | if ($node->moderate && user_access('access submission queue')) { | |||||||||||||
| 379 | drupal_set_message(t('The post is queued for approval')); | |||||||||||||
| 380 | } | |||||||||||||
| 381 | elseif ($node->moderate) { | |||||||||||||
| 382 | drupal_set_message(t('The post is queued for approval. The editors will decide whether it should be published.')); | |||||||||||||
| 383 | } | |||||||||||||
| 384 | break; | |||||||||||||
| 385 | } | |||||||||||||
| 386 | } !, | |||||||||||||
| 387 | ||||||||||||||
| 388 | ||||||||||||||
| 389 | hook_node_grants => q!function MODULENAME_node_grants($user, $op) { | |||||||||||||
| 390 | $grants = array(); | |||||||||||||
| 391 | if ($op == 'view') { | |||||||||||||
| 392 | if (user_access('access content')) { | |||||||||||||
| 393 | $grants[] = 0; | |||||||||||||
| 394 | } | |||||||||||||
| 395 | if (user_access('access private content')) { | |||||||||||||
| 396 | $grants[] = 1; | |||||||||||||
| 397 | } | |||||||||||||
| 398 | } | |||||||||||||
| 399 | if ($op == 'update' || $op == 'delete') { | |||||||||||||
| 400 | if (user_access('edit content')) { | |||||||||||||
| 401 | $grants[] = 0; | |||||||||||||
| 402 | } | |||||||||||||
| 403 | if (user_access('edit private content')) { | |||||||||||||
| 404 | $grants[] = 1; | |||||||||||||
| 405 | } | |||||||||||||
| 406 | } | |||||||||||||
| 407 | return array('example' => $grants); | |||||||||||||
| 408 | } !, | |||||||||||||
| 409 | ||||||||||||||
| 410 | ||||||||||||||
| 411 | hook_node_info => q!function MODULENAME_node_info() { | |||||||||||||
| 412 | return array( | |||||||||||||
| 413 | 'project_project' => array('name' => t('project'), 'base' => 'project_project'), | |||||||||||||
| 414 | 'project_issue' => array('name' => t('issue'), 'base' => 'project_issue') | |||||||||||||
| 415 | ); | |||||||||||||
| 416 | } !, | |||||||||||||
| 417 | ||||||||||||||
| 418 | ||||||||||||||
| 419 | hook_perm => q!function MODULENAME_perm() { | |||||||||||||
| 420 | return array('administer my module'); | |||||||||||||
| 421 | } !, | |||||||||||||
| 422 | ||||||||||||||
| 423 | ||||||||||||||
| 424 | hook_ping => q!function MODULENAME_ping($name = '', $url = '') { | |||||||||||||
| 425 | $feed = url('node/feed'); | |||||||||||||
| 426 | ||||||||||||||
| 427 | $client = new xmlrpc_client('/RPC2', 'rpc.weblogs.com', 80); | |||||||||||||
| 428 | ||||||||||||||
| 429 | $message = new xmlrpcmsg('weblogUpdates.ping', | |||||||||||||
| 430 | array(new xmlrpcval($name), new xmlrpcval($url))); | |||||||||||||
| 431 | ||||||||||||||
| 432 | $result = $client->send($message); | |||||||||||||
| 433 | ||||||||||||||
| 434 | if (\!$result || $result->faultCode()) { | |||||||||||||
| 435 | watchdog('error', 'failed to notify "weblogs.com" (site)'); | |||||||||||||
| 436 | } | |||||||||||||
| 437 | ||||||||||||||
| 438 | unset($client); | |||||||||||||
| 439 | } !, | |||||||||||||
| 440 | ||||||||||||||
| 441 | ||||||||||||||
| 442 | hook_prepare => q!function MODULENAME_prepare(&$node) { | |||||||||||||
| 443 | if ($file = file_check_upload($field_name)) { | |||||||||||||
| 444 | $file = file_save_upload($field_name, _image_filename($file->filename, NULL, TRUE)); | |||||||||||||
| 445 | if ($file) { | |||||||||||||
| 446 | if (\!image_get_info($file->filepath)) { | |||||||||||||
| 447 | form_set_error($field_name, t('Uploaded file is not a valid image')); | |||||||||||||
| 448 | return; | |||||||||||||
| 449 | } | |||||||||||||
| 450 | } | |||||||||||||
| 451 | else { | |||||||||||||
| 452 | return; | |||||||||||||
| 453 | } | |||||||||||||
| 454 | $node->images['_original'] = $file->filepath; | |||||||||||||
| 455 | _image_build_derivatives($node, true); | |||||||||||||
| 456 | $node->new_file = TRUE; | |||||||||||||
| 457 | } | |||||||||||||
| 458 | } !, | |||||||||||||
| 459 | ||||||||||||||
| 460 | ||||||||||||||
| 461 | hook_search => q!function MODULENAME_search($op = 'search', $keys = null) { | |||||||||||||
| 462 | switch ($op) { | |||||||||||||
| 463 | case 'name': | |||||||||||||
| 464 | return t('content'); | |||||||||||||
| 465 | case 'reset': | |||||||||||||
| 466 | variable_del('node_cron_last'); | |||||||||||||
| 467 | return; | |||||||||||||
| 468 | case 'search': | |||||||||||||
| 469 | $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()); | |||||||||||||
| 470 | $results = array(); | |||||||||||||
| 471 | foreach ($find as $item) { | |||||||||||||
| 472 | $node = node_load(array('nid' => $item)); | |||||||||||||
| 473 | $extra = node_invoke_nodeapi($node, 'search result'); | |||||||||||||
| 474 | $results[] = array('link' => url('node/'. $item), | |||||||||||||
| 475 | 'type' => node_invoke($node, 'node_name'), | |||||||||||||
| 476 | 'title' => $node->title, | |||||||||||||
| 477 | 'user' => theme('username', $node), | |||||||||||||
| 478 | 'date' => $node->changed, | |||||||||||||
| 479 | 'extra' => $extra, | |||||||||||||
| 480 | 'snippet' => search_excerpt($keys, check_output($node->body, $node->format))); | |||||||||||||
| 481 | } | |||||||||||||
| 482 | return $results; | |||||||||||||
| 483 | } | |||||||||||||
| 484 | } !, | |||||||||||||
| 485 | ||||||||||||||
| 486 | ||||||||||||||
| 487 | hook_search_item => q!function MODULENAME_search_item($item) { | |||||||||||||
| 488 | $output .= ' 489 | .'">'. $item['title'] .' '; |
||||||||||||
| 490 | $output .= ' ' . $item['description'] . ''; | |||||||||||||
| 491 | $output .= ' '; |
|||||||||||||
| 492 | ||||||||||||||
| 493 | return $output; | |||||||||||||
| 494 | } !, | |||||||||||||
| 495 | ||||||||||||||
| 496 | ||||||||||||||
| 497 | hook_search_preprocess => q!function MODULENAME_search_preprocess($text) { | |||||||||||||
| 498 | // Do processing on $text | |||||||||||||
| 499 | return $text; | |||||||||||||
| 500 | } !, | |||||||||||||
| 501 | ||||||||||||||
| 502 | ||||||||||||||
| 503 | hook_settings => q!function MODULENAME_settings() { | |||||||||||||
| 504 | $form['example_a'] = array( | |||||||||||||
| 505 | '#type' => 'textfield', | |||||||||||||
| 506 | '#title' => t('Setting A'), | |||||||||||||
| 507 | '#default_value' => variable_get('example_a', 'Default setting'), | |||||||||||||
| 508 | '#size' => 20, | |||||||||||||
| 509 | '#maxlength' => 255, | |||||||||||||
| 510 | '#description' => t('A description of this setting.'), | |||||||||||||
| 511 | ); | |||||||||||||
| 512 | $form['example_b'] = array( | |||||||||||||
| 513 | '#type' => 'checkbox', | |||||||||||||
| 514 | '#title' => t('Setting B'), | |||||||||||||
| 515 | '#default_value' => variable_get('example_b', 0), | |||||||||||||
| 516 | '#description' => t('A description of this setting.'), | |||||||||||||
| 517 | ); | |||||||||||||
| 518 | ||||||||||||||
| 519 | return $form; | |||||||||||||
| 520 | } !, | |||||||||||||
| 521 | ||||||||||||||
| 522 | ||||||||||||||
| 523 | hook_submit => q!function MODULENAME_submit(&$node) { | |||||||||||||
| 524 | // if a file was uploaded, move it to the files directory | |||||||||||||
| 525 | if ($file = file_check_upload('file')) { | |||||||||||||
| 526 | $node->file = file_save_upload($file, file_directory_path(), false); | |||||||||||||
| 527 | } | |||||||||||||
| 528 | } !, | |||||||||||||
| 529 | ||||||||||||||
| 530 | ||||||||||||||
| 531 | hook_taxonomy => q!function MODULENAME_taxonomy($op, $type, $object) { | |||||||||||||
| 532 | if ($type == 'vocabulary' && ($op == 'insert' || $op == 'update')) { | |||||||||||||
| 533 | if (variable_get('forum_nav_vocabulary', '') == '' | |||||||||||||
| 534 | && in_array('forum', $object['nodes'])) { | |||||||||||||
| 535 | // since none is already set, silently set this vocabulary as the navigation vocabulary | |||||||||||||
| 536 | variable_set('forum_nav_vocabulary', $object['vid']); | |||||||||||||
| 537 | } | |||||||||||||
| 538 | } | |||||||||||||
| 539 | } !, | |||||||||||||
| 540 | ||||||||||||||
| 541 | ||||||||||||||
| 542 | hook_update => q!function MODULENAME_update($node) { | |||||||||||||
| 543 | db_query("UPDATE {mytable} SET extra = '%s' WHERE nid = %d", | |||||||||||||
| 544 | $node->extra, $node->nid); | |||||||||||||
| 545 | } !, | |||||||||||||
| 546 | ||||||||||||||
| 547 | ||||||||||||||
| 548 | hook_update_index => q!function MODULENAME_update_index() { | |||||||||||||
| 549 | $last = variable_get('node_cron_last', 0); | |||||||||||||
| 550 | $limit = (int)variable_get('search_cron_limit', 100); | |||||||||||||
| 551 | ||||||||||||||
| 552 | $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); | |||||||||||||
| 553 | ||||||||||||||
| 554 | while ($node = db_fetch_object($result)) { | |||||||||||||
| 555 | $last_comment = $node->last_comment_timestamp; | |||||||||||||
| 556 | $node = node_load(array('nid' => $node->nid)); | |||||||||||||
| 557 | ||||||||||||||
| 558 | // We update this variable per node in case cron times out, or if the node | |||||||||||||
| 559 | // cannot be indexed (PHP nodes which call drupal_goto, for example). | |||||||||||||
| 560 | // In rare cases this can mean a node is only partially indexed, but the | |||||||||||||
| 561 | // chances of this happening are very small. | |||||||||||||
| 562 | variable_set('node_cron_last', max($last_comment, $node->changed, $node->created)); | |||||||||||||
| 563 | ||||||||||||||
| 564 | // Get node output (filtered and with module-specific fields). | |||||||||||||
| 565 | if (node_hook($node, 'view')) { | |||||||||||||
| 566 | node_invoke($node, 'view', false, false); | |||||||||||||
| 567 | } | |||||||||||||
| 568 | else { | |||||||||||||
| 569 | $node = node_prepare($node, false); | |||||||||||||
| 570 | } | |||||||||||||
| 571 | // Allow modules to change $node->body before viewing. | |||||||||||||
| 572 | node_invoke_nodeapi($node, 'view', false, false); | |||||||||||||
| 573 | ||||||||||||||
| 574 | $text = ''. drupal_specialchars($node->title) .''. $node->body; |
|||||||||||||
| 575 | ||||||||||||||
| 576 | // Fetch extra data normally not visible | |||||||||||||
| 577 | $extra = node_invoke_nodeapi($node, 'update index'); | |||||||||||||
| 578 | foreach ($extra as $t) { | |||||||||||||
| 579 | $text .= $t; | |||||||||||||
| 580 | } | |||||||||||||
| 581 | ||||||||||||||
| 582 | // Update index | |||||||||||||
| 583 | search_index($node->nid, 'node', $text); | |||||||||||||
| 584 | } | |||||||||||||
| 585 | } !, | |||||||||||||
| 586 | ||||||||||||||
| 587 | ||||||||||||||
| 588 | hook_update_N => q!function MODULENAME_update_N() { | |||||||||||||
| 589 | $ret = array(); | |||||||||||||
| 590 | ||||||||||||||
| 591 | switch ($GLOBALS['db_type']) { | |||||||||||||
| 592 | case 'pgsql': | |||||||||||||
| 593 | db_add_column($ret, 'contact', 'weight', 'smallint', array('not null' => TRUE, 'default' => 0)); | |||||||||||||
| 594 | db_add_column($ret, 'contact', 'selected', 'smallint', array('not null' => TRUE, 'default' => 0)); | |||||||||||||
| 595 | break; | |||||||||||||
| 596 | ||||||||||||||
| 597 | case 'mysql': | |||||||||||||
| 598 | case 'mysqli': | |||||||||||||
| 599 | $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN weight tinyint(3) NOT NULL DEFAULT 0"); | |||||||||||||
| 600 | $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN selected tinyint(1) NOT NULL DEFAULT 0"); | |||||||||||||
| 601 | break; | |||||||||||||
| 602 | } | |||||||||||||
| 603 | ||||||||||||||
| 604 | return $ret; | |||||||||||||
| 605 | } !, | |||||||||||||
| 606 | ||||||||||||||
| 607 | ||||||||||||||
| 608 | hook_user => q!function MODULENAME_user($op, &$edit, &$account, $category = NULL) { | |||||||||||||
| 609 | if ($op == 'form' && $category == 'account') { | |||||||||||||
| 610 | $form['comment_settings'] = array( | |||||||||||||
| 611 | '#type' => 'fieldset', | |||||||||||||
| 612 | '#title' => t('Comment settings'), | |||||||||||||
| 613 | '#collapsible' => TRUE, | |||||||||||||
| 614 | '#weight' => 4); | |||||||||||||
| 615 | $form['comment_settings']['signature'] = array( | |||||||||||||
| 616 | '#type' => 'textarea', | |||||||||||||
| 617 | '#title' => t('Signature'), | |||||||||||||
| 618 | '#default_value' => $edit['signature'], | |||||||||||||
| 619 | '#description' => t('Your signature will be publicly displayed at the end of your comments.')); | |||||||||||||
| 620 | return $form; | |||||||||||||
| 621 | } | |||||||||||||
| 622 | } !, | |||||||||||||
| 623 | ||||||||||||||
| 624 | ||||||||||||||
| 625 | hook_validate => q!function MODULENAME_validate(&$node) { | |||||||||||||
| 626 | if ($node) { | |||||||||||||
| 627 | if ($node->end && $node->start) { | |||||||||||||
| 628 | if ($node->start > $node->end) { | |||||||||||||
| 629 | form_set_error('time', t('An event may not end before it starts.')); | |||||||||||||
| 630 | } | |||||||||||||
| 631 | } | |||||||||||||
| 632 | } | |||||||||||||
| 633 | } !, | |||||||||||||
| 634 | ||||||||||||||
| 635 | ||||||||||||||
| 636 | hook_view => q!function MODULENAME_view(&$node, $teaser = FALSE, $page = FALSE) { | |||||||||||||
| 637 | if ($page) { | |||||||||||||
| 638 | $breadcrumb = array(); | |||||||||||||
| 639 | $breadcrumb[] = array('path' => 'example', 'title' => t('example')); | |||||||||||||
| 640 | $breadcrumb[] = array('path' => 'example/'. $node->field1, | |||||||||||||
| 641 | 'title' => t('%category', array('%category' => $node->field1))); | |||||||||||||
| 642 | $breadcrumb[] = array('path' => 'node/'. $node->nid); | |||||||||||||
| 643 | menu_set_location($breadcrumb); | |||||||||||||
| 644 | } | |||||||||||||
| 645 | ||||||||||||||
| 646 | $node = node_prepare($node, $teaser); | |||||||||||||
| 647 | } !, | |||||||||||||
| 648 | ||||||||||||||
| 649 | ||||||||||||||
| 650 | hook_xmlrpc => q!function MODULENAME_xmlrpc() { | |||||||||||||
| 651 | return array( | |||||||||||||
| 652 | 'drupal.login' => 'drupal_login', | |||||||||||||
| 653 | array( | |||||||||||||
| 654 | 'drupal.site.ping', | |||||||||||||
| 655 | 'drupal_directory_ping', | |||||||||||||
| 656 | array('boolean', 'string', 'string', 'string', 'string', 'string'), | |||||||||||||
| 657 | t('Handling ping request')) | |||||||||||||
| 658 | ); | |||||||||||||
| 659 | } !, | |||||||||||||
| 660 | ||||||||||||||
| 661 | }; | |||||||||||||
| 662 | ||||||||||||||
| 663 | ||||||||||||||
| 664 | ||||||||||||||
| 665 | =head1 SYNOPSIS | |||||||||||||
| 666 | ||||||||||||||
| 667 | 4_7_2 stubs | |||||||||||||
| 668 | ||||||||||||||
| 669 | =head1 FUNCTIONS | |||||||||||||
| 670 | ||||||||||||||
| 671 | =head2 new - constructor - no paramaters required | |||||||||||||
| 672 | ||||||||||||||
| 673 | =cut | |||||||||||||
| 674 | ||||||||||||||
| 675 | sub new { | |||||||||||||
| 676 | 2 | 2 | 1 | 8 | my ($self,$class) = ({},shift); | |||||||||
| 677 | 2 | 7 | bless $stubs,$class; | |||||||||||
| 678 | 2 | 8 | return $stubs; | |||||||||||
| 679 | } | |||||||||||||
| 680 | ||||||||||||||
| 681 | =head2 stub - return a php function stub for the named parameter | |||||||||||||
| 682 | ||||||||||||||
| 683 | =cut | |||||||||||||
| 684 | ||||||||||||||
| 685 | sub stub { | |||||||||||||
| 686 | 0 | 0 | 1 | my $self = shift; | ||||||||||
| 687 | 0 | return $self->{stubs}->{shift}; | ||||||||||||
| 688 | } | |||||||||||||
| 689 | ||||||||||||||
| 690 | =head1 AUTHOR | |||||||||||||
| 691 | ||||||||||||||
| 692 | Steve McNabb, C<< |
|||||||||||||
| 693 | IT Director, F5 Site Design - http://www.f5sitedesign.com | |||||||||||||
| 694 | Open Source Internet Application Development | |||||||||||||
| 695 | ||||||||||||||
| 696 | =cut | |||||||||||||
| 697 | 1; | |||||||||||||
| 698 | ||||||||||||||
| 699 | ||||||||||||||
| 700 |