0)); // drupal_set_session('book_update_6000', array()); $_SESSION['dblog_overview_filter'][$name] = $form_state['values'][$name]; // Unchanged? $_SESSION['dblog_overview_filter'] = array(); // drupal_set_session('dblog_overview_filter', array()); $session = &$_SESSION['node_overview_filter']; $_SESSION['node_overview_filter'][] = array($filter, $form_state['values'][$filter]); // Unchanged? $_SESSION['openid']['service'] = $services[0]; // Unchanged? } function example_request_time() { // time() -- Change the next line but leave this alone $nextWeek = time() + (7 * 24 * 60 * 60); $nextWeek = 8*time() + (7 * 24 * 60 * 60); // Catch poor formatting. } function example_rebuild_functions() { // drupal_rebuild_theme_registry() -- Change the next line but leave this alone drupal_rebuild_theme_registry(); // drupal_rebuild_code_registry() -- Change the next line but leave this alone drupal_rebuild_code_registry(); } function example_uninstall_module() { // drupal_uninstall_module() -- Change the next line but leave this alone drupal_uninstall_module($module); } // use module_implements not module_list when calling hook implementations function example_module_list() { foreach (module_list() as $module) { // do something with a hook on each module } } // Parameters for drupal_http_request() have changed function example_http_request() { // drupal_http_request() -- Change the next line but leave this alone drupal_http_request('http://example.com/', array('Header-Title' => 'value'), 'GET', NULL, 0); /* * Trying to produce this: * drupal_http_request('http://example.com/', array('headers' => array('Header-Title' => 'value'), 'max_redirects' => 0)); */ drupal_http_request('http://example.com/', array('Header-Title' => 'value'), 'GET', 'Some data', 0); drupal_http_request('http://example.com/', array('Header-Title' => 'value'), 'POST', 'Some data', 3); drupal_http_request('http://example.com/', array('Header-Title' => 'value'), 'POST', 'Some data'); drupal_http_request('http://example.com/', array('Header-Title' => 'value'), 'POST'); drupal_http_request('http://example.com/'); } function example_moved_statistics_settings() { drupal_goto($path = 'admin/reports/settings'); } function example_system_theme_data() { // module_rebuild_cache() -- Change the next line but leave this alone module_rebuild_cache(); // system_theme_data() -- Change the next line but leave this alone system_theme_data(); } function example_static_variable() { static $menu1; static $menu2 = 2; static $menu3 = array(); static $menu4 = 'xx'; } function example_html_head() { // drupal_set_html_head() -- Change the next line but leave this alone $data = 'my header'; drupal_set_html_head($data); if (drupal_set_html_head($data)) { // } } function example_drupal_eval() { // drupal_eval() -- Change the next line but leave this alone drupal_eval(''); $text = drupal_eval(''); if ($text = drupal_eval('')) { // } print_r(drupal_eval('')); // drupal_eval() -- try this for nesting complexity echo print_r(drupal_eval(''), 1); } function example_http_header_functions() { // drupal_set_header() -- Change the next line but leave this alone drupal_set_header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal server error'); drupal_set_header('HTTP/1.1 503 Service unavailable'); drupal_set_header('HTTP/1.1 403 Forbidden'); drupal_set_header('Content-Type: text/plain'); drupal_set_header('Content-Type: text/javascript; charset=utf-8'); drupal_set_header('Content-Type: octet/stream'); drupal_set_header('Content-Disposition: attachment; filename="'. $filename .'"'); drupal_set_header('Content-Length: '.filesize(file_directory_path().'/'.$filename)); // Double quotes. drupal_set_header($_SERVER["SERVER_PROTOCOL"] . " 500 Internal server error"); drupal_set_header("HTTP/1.1 503 Service unavailable"); drupal_set_header("HTTP/1.1 403 Forbidden"); drupal_set_header("Content-Type: text/plain"); drupal_set_header("Content-Type: text/javascript; charset=utf-8"); drupal_set_header("Content-Type: octet/stream"); drupal_set_header("Content-Disposition: attachment; filename='". $filename ."'"); drupal_set_header("Content-Length: ".filesize(file_directory_path()."/".$filename)); // drupal_get_headers() -- Change the next line but leave this alone $headers = drupal_get_headers(); foreach (drupal_get_headers() as $name => $value) { // } } function example_file_download() { if (_mymodule_access($filepath)) { return array( 'Content-Type: text/plain', ); } } function example_set_content() { // drupal_set_content() -- Change the next line but leave this alone // Add our own text to the footer. drupal_set_content('footer', 'Adding custom text to footer'); // Get the complete footer contents. // drupal_get_content() -- Change the next line but leave this alone $full_footer = drupal_get_content(); if ($full_footer = drupal_get_content()) { // } } function example_time_limit() { // set_time_limit() -- Change the next line but leave this alone $time_limit = 5; set_time_limit($time_limit); if (set_time_limit($time_limit) > 5) { // } } // http://drupal.org/node/224333#remove-drupal-urlencode function example_remove_drupal_urlencode() { // drupal_urlencode() -- Change the next line but leave this alone $string = drupal_urlencode('test'); } /* function example_() { } function example_() { } */ /* * Permissions and Access */ /** * Implement hook_perm. * * Use case 1: returns array directly. * * http://drupal.org/node/224333#hook_permission * http://drupal.org/node/224333#descriptions_permissions */ function example_perm() { return array('administer my module', $perm_1['one'], 'permission two', $perm_2[1]['2']); } /** * Implement hook_perm. * * Use case 2: makes one assignment to array variable; returns variable. */ function example_perm() { $perm = array( 'administer my module', $perm_1['one'], 'permission two', $perm_2[1]['2'], ); return $perm; } /** * Implement hook_perm. * * Use case 3: makes multiple assignments to array variable; returns variable. */ function example_perm() { // This use case does not apply as the permission strings do not have any values. $perm = array(); $perm['administer my module'] = array(); $perm[$perm_1['one']] = array(); $perm['permission two'] = array(); $perm[$perm_2[1]['2']] = array(); return $perm; } /** * Other permission items in http://drupal.org/files/issues/506976_0.patch. */ function example_perm_items() { $options = array(); foreach (module_implements('perm') as $module) { $function = $module . '_perm'; if ($permissions = $function('perm')) { asort($permissions); foreach ($permissions as $permission => $description) { $options[t('@module module', array('@module' => $module))][$permission] = t($permission); } } } foreach ($modules as $module) { $permissions = array_merge($permissions, array_keys(module_invoke($module, 'perm'))); } // Check for permissions. if (in_array($module, module_implements('perm')) && $admin_access) { $admin_tasks[-1] = l(t('Configure permissions'), 'admin/user/permissions', array('fragment' => 'module-' . $module)); } } function example_php_permissions() { // 'use PHP for block visibility' -- Change the next line but leave this alone $access = user_access('use PHP for block visibility'); if ($access = user_access('use PHP for block visibility')) { // } } /** * Implement hook_access. * * http://drupal.org/node/224333#hook_node_access */ function example_access($op, $node, $account) { if ($op == 'create') { return user_access('create stories', $account); } if ($op == 'update' || $op == 'delete') { if (user_access('edit own stories', $account) && ($account->uid == $node->uid)) { return TRUE; } } } /* * Database */ // Do table renames along with the new dbtng format. function example_dbtng() { // db_query() -- Change the next line but leave this alone // Insert query. db_query("INSERT INTO {mytable} (intvar, stringvar, floatvar) VALUES (%d, '%s', %f)", 5, 'hello world', 3.14); $sql = "INSERT INTO {mytable} (intvar, stringvar, floatvar) VALUES (%d, '%s', %f)"; db_query($sql, 5, 'hello world', 3.14); $values= array(5, 'hello world', 3.14); db_query($sql, $values); $id = db_last_insert_id(); // Update query. db_query("UPDATE {node} SET title='%s', status=%d WHERE uid=%d", 'hello world', 1, 5); // Delete query. db_query("DELETE FROM {node} WHERE uid=%d AND created < %d", 5, time() - 3600); } // TODO Move these schema hooks to an install file!!! // Schema descriptions are no longer translated. // Function name needs to be the hook name not the html tag on the change. // Use case 1: returns array directly. function example_schema() { return array( 'forum' => array( 'description' => t('Stores the relationship of nodes to forum terms.'), 'fields' => array( 'nid' => array( 'description' => t('The {node}.nid of the node.'), ), ), ), // This tests the #schema_html upgrade. 'foo_url' => array( 'description' => t('Stores URLs that appear in <a href=....> tags.'), 'fields' => array( 'url' => array( 'description' => t('The URL.'), ), ), ), // When did the description item come into play between above and below??? 'example' => array( 'fields' => array( 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), ), 'primary key' => array('nid'), ), ); } // Use case 2: makes one assignment to array variable; returns variable. function example_schema() { $schema = array( 'forum' => array( 'description' => t('Stores the relationship of nodes to forum terms.'), 'fields' => array( 'nid' => array( 'description' => t('The {node}.nid of the node.'), ), ), ), // This tests the #schema_html upgrade. 'foo_url' => array( 'description' => t('Stores URLs that appear in <a href=....> tags.'), 'fields' => array( 'url' => array( 'description' => t('The URL.'), ), ), ), // When did the description item come into play between above and below??? 'example' => array( 'fields' => array( 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), ), 'primary key' => array('nid'), ), ); return $schema; } // Use case 3: makes multiple assignments to array variable; returns variable. function example_schema() { $schema['forum'] = array( 'description' => t('Stores the relationship of nodes to forum terms.'), 'fields' => array( 'nid' => array( 'description' => t('The {node}.nid of the node.'), ), ), ); // This tests the #schema_html upgrade. $schema['foo_url'] = array( 'description' => t('Stores URLs that appear in <a href=....> tags.'), 'fields' => array( 'url' => array( 'description' => t('The URL.'), ), ), ); // When did the description item come into play between above and below??? $schema['example'] = array( 'fields' => array( 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), ), 'primary key' => array('nid'), ); return $schema; } // Database schema (un)installed automatically function example_install() { // drupal_install_schema('example'); if ($results = drupal_install_schema('example')) { // Do something. } } function example_uninstall() { $result = db_query("SELECT * FROM {example}"); while ($data = db_fetch_object($result)) { db_query("DELETE FROM {variable} WHERE name = '%s'", 'example_'. $data->nid); } drupal_uninstall_schema('example'); } function example_schema_ret() { // db_add_field() -- Change the next line but leave this alone // The parameters are not correct for each of these functions, but should // allow the upgrade code to be tested. // includes/database.pgsql.inc Add a new field to a table. db_add_field($ret, $table, $new_name); // includes/database.pgsql.inc Add an index. db_add_index($ret, $table, $new_name); // includes/database.pgsql.inc Add a primary key. db_add_primary_key($ret, $table, $new_name); // includes/database.pgsql.inc Add a unique key. db_add_unique_key($ret, $table, $new_name); // includes/database.pgsql.inc Change a field definition. db_change_field($ret, $table, $new_name); // includes/database.inc Create a new table from a Drupal table definition. db_create_table($ret, $table, $new_name); // includes/database.pgsql.inc Generate SQL to create a new table from a Drupal schema definition. db_create_table_sql($ret, $table, $new_name); // includes/database.pgsql.inc Drop a field. db_drop_field($ret, $table, $new_name); // includes/database.pgsql.inc Drop an index. db_drop_index($ret, $table, $new_name); // includes/database.pgsql.inc Drop the primary key. db_drop_primary_key($ret, $table, $new_name); // includes/database.pgsql.inc Drop a table. db_drop_table($ret, $table, $new_name); // includes/database.pgsql.inc Drop a unique key. db_drop_unique_key($ret, $table, $new_name); // includes/database.inc Return an array of field names from an array of key/index column specifiers. db_field_names($ret, $table, $new_name); // includes/database.pgsql.inc Set the default value for a field. db_field_set_default($ret, $table, $new_name); // includes/database.pgsql.inc Set a field to have no default value. db_field_set_no_default($ret, $table, $new_name); // includes/database.pgsql.inc Rename a table. db_rename_table($ret, $table, $new_name); } // #db_result (not documented); see #741998 function example_db_result() { $val = db_result(db_query('SELECT nid FROM {node}')); $val = db_result( db_query(' SELECT nid FROM {node} LIMIT 1 ') ); $val = db_result(db_query('SELECT title FROM {node} WHERE nid = %d ', $nid)); $val = db_result( db_query(' SELECT title FROM {node} WHERE nid = %d ', $nid) ); $query = db_query('SELECT * FROM {node}'); $val = db_result($query); } // #db_column_exists (not documented) function example_db_column_exists() { $ret = db_column_exists('table', 'field'); $ret = db_column_exists($table, $field); if ($ret = db_column_exists('table', 'field')) { } } // http://drupal.org/node/224333#db_is_active function example_db_is_active() { // db_is_active() -- Change the next line but leave this alone if (db_is_active()) { // Database is active. } // function_exists() -- Change the next line but leave this alone if (function_exists('db_is_active')) { // Do something. } } /* * Menus */ function example_menu_link_alter(&$item, $menu) { // Example 1 - make all new admin links hidden (a.k.a disabled). if (strpos($item['link_path'], 'admin') === 0 && empty($item['mlid'])) { $item['hidden'] = 1; } } // http://drupal.org/node/224333#admin_path_changes function example_admin_path_changes() { $menu['admin/reports/settings'] = array(); $menu['admin/build/modules/'] = array(); $menu['admin/build/modules/custom-module'] = array(); $menu['admin/build/themes'] = array(); $menu['admin/build/themes/custom-theme'] = array(); $menu['admin/build/path'] = array(); $menu['admin/build/path/path-setting'] = array(); $menu['admin/build/block'] = array(); $menu['admin/build/block/block-setting'] = array(); $menu['admin/build/menu'] = array(); $menu['admin/build/menu/menu-setting'] = array(); $menu['admin/content/types'] = array(); $menu['admin/content/taxonomy'] = array(); $menu['admin/content/forum'] = array(); $menu['admin/build/testing'] = array(); $menu['admin/settings/site-maintenance'] = array(); $menu['admin/settings/performance'] = array(); $menu['admin/settings/filters'] = array(); $menu['admin/settings/search'] = array(); $menu['admin/settings/clean-urls'] = array(); } // Where is http://drupal.org/node/224333#menu-link-hooks? // http://drupal.org/node/224333#menu_tree_data function example_menu_tree_data() { $sql = "menu_tree_data SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.* FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path WHERE ml.menu_name = '%s' ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC"; $result = db_query($sql, $menu['menu_name']); $tree = menu_tree_data($result); $sql = " SELECT b.*, m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, ml.* FROM {menu_links} ml INNER JOIN {menu_router} m ON m.path = ml.router_path INNER JOIN {book} b ON ml.mlid = b.mlid WHERE ". implode(' AND ', $match) ." ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC"; $data['tree'] = menu_tree_data(db_query($sql, $args), array(), $item['depth']); } /* * Blocks */ /** * Implementation of hook_block(). * * http://drupal.org/node/224333#remove_op */ function example_block($op, $delta, $edit) { if ($op == 'configure') { // Configuration form for the block. if ($delta == 'exciting') { $form['items'] = array( '#type' => 'select', '#title' => t('Number of items'), '#default_value' => variable_get('mymodule_block_items', 0), '#options' => array('1', '2', '3'), ); return $form; } } elseif ($op == 'list') { // A list of all blocks defined by the module. $blocks['exciting'] = array( 'info' => t('An exciting block provided by Mymodule.'), 'weight' => 0, 'status' => 1, 'region' => 'sidebar_first', // DRUPAL_CACHE_PER_ROLE will be assumed for block 0. ); $blocks['amazing'] = array( 'info' => t('An amazing block provided by Mymodule.'), 'cache' => DRUPAL_CACHE_PER_ROLE | DRUPAL_CACHE_PER_PAGE, ); return $blocks; } elseif ($op == 'save') { // Save the configuration options. if ($delta == 'exciting') { variable_set('mymodule_block_items', $edit['items']); } } elseif ($op == 'view') { // Process the block when enabled in a region in order to view its contents. switch ($delta) { case 'exciting': $block = array( 'subject' => t('Default title of the exciting block'), 'content' => mymodule_display_block_exciting(), ); break; case 'amazing': $block = array( 'subject' => t('Default title of the amazing block'), 'content' => mymodule_display_block_amazing(), ); break; } return $block; } switch ($op) { case 'configure': // Configuration form for the block. if ($delta == 'exciting') { $form['items'] = array( '#type' => 'select', '#title' => t('Number of items'), '#default_value' => variable_get('mymodule_block_items', 0), '#options' => array('1', '2', '3'), ); return $form; } break; case 'list': // A list of all blocks defined by the module. $blocks['exciting'] = array( 'info' => t('An exciting block provided by Mymodule.'), 'weight' => 0, 'status' => 1, 'region' => 'sidebar_first', // DRUPAL_CACHE_PER_ROLE will be assumed for block 0. ); $blocks['amazing'] = array( 'info' => t('An amazing block provided by Mymodule.'), 'cache' => DRUPAL_CACHE_PER_ROLE | DRUPAL_CACHE_PER_PAGE, ); return $blocks; break; case 'save': // Save the configuration options. if ($delta == 'exciting') { variable_set('mymodule_block_items', $edit['items']); } break; case 'view': // Process the block when enabled in a region in order to view its contents. switch ($delta) { case 'exciting': $block = array( 'subject' => t('Default title of the exciting block'), 'content' => mymodule_display_block_exciting(), ); break; case 'amazing': $block = array( 'subject' => t('Default title of the amazing block'), 'content' => mymodule_display_block_amazing(), ); break; } return $block; break; } foreach (array('configure', 'list', 'view') as $op) { // Do something. } } /** * Implementation of hook_block(). * * http://drupal.org/node/224333#block_deltas_renamed */ function example_block($op, $delta = 0, $edit = array()) { switch ($op) { case 'list': $blocks[0] = array( 'info' => t('Example block #1'), ); $blocks[1] = array( 'info' => t('Example block #2'), ); return $blocks; break; case 'configure': if ($delta == 0) { $form['block_example'] = array( '#type' => 'textfield', '#title' => t('Block Example Field'), '#default_value' => variable_get('example_block_example_field', ''), ); } break; case 'save': if ($delta == 0) { variable_set('example_block_example_field', $edit['block_example_string']); } break; case 'view': switch ($delta) { case 0: $block['subject'] = t('Example Block #1'); $block['content'] = variable_get('example_block_example_field', ''); break; case 1: $block['subject'] = t('Example Block #1'); $block['content'] = t('Example Block #2'); break; } return $block; break; } } // http://drupal.org/node/224333#block_tables_renamed function example_block_db_tables() { $result = db_query("SELECT * FROM {blocks}"); $result = db_query("SELECT * FROM {blocks_roles}"); $result = db_query("SELECT * FROM {boxes}"); } // http://drupal.org/node/224333#custom_block function example_custom_block() { block_box_delete($form); block_box_delete_submit(); block_box_form(); $box = block_box_get(1); $box = block_box_get($id); block_custom_block_save($edit, $delta); db_query("SELECT * FROM {box}"); db_query("SELECT * FROM {BOX}"); } /* * Comments */ function example_comment_load() { if ($value) { // perform the update action, then refresh node statistics db_query($query, $cid); // _comment_load() -- Change the next line but leave this alone $comment = _comment_load($cid); _comment_update_node_statistics($comment->nid); // Allow modules to respond to the updating of a comment. } } /** * Implementation of hook_menu(). * * Example for comment_wildcard. */ function example_menu() { global $user; $items = array(); $access = user_access('administer all signups'); $items['node/%_comment/signup'] = array( 'title' => user_access('access administration pages') ? t('Signup') : t('Signup settings'), 'description' => 'Add a signup node.', 'page callback' => 'drupal_get_form', 'page arguments' => array('signup_settings_page'), 'access callback' => $access, 'type' => MENU_LOCAL_TASK, ); $items['admin/content/signup'] = array( 'title' => 'Signup overview', 'description' => t('View all signup-enabled posts, and open or close signups on them.'), 'page callback' => 'example_signup_admin_form', 'access callback' => $access, 'type' => MENU_LOCAL_TASK, ); } function example_comment_validate() { // comment_validate() -- Change the next line but leave this alone if ($x = comment_validate('xx')) { } $y = comment_validate($xx['y']); } function example_comment_node_url() { // comment_node_url() -- Change the next line but leave this alone $var = 'xx/' . comment_node_url() . 'yy'; if (comment_node_url() == '') { } return comment_node_url(); } /** * Implement hook_comment(). * * This change is missing from the roadmaps!!! */ function example_comment(&$a1, $op) { // TODO This is an example of multiple $op values in one condition. if ($op == 'insert' || $op == 'update') { $nid = $a1['nid']; } if ($op == "insert") { // The comment is being inserted. } elseif ($op == "update") { // The comment is being updated. } elseif ($op == "view") { // The comment is being viewed. This hook can be used to add additional data to the comment before theming. } elseif ($op == "validate") { // The user has just finished editing the comment and is trying to preview or submit it. This hook can be used to check or even modelseify the node. Errors should be set with form_set_error(). } elseif ($op == "publish") { // The comment is being published by the moderator. } elseif ($op == "unpublish") { // The comment is being unpublished by the moderator. } elseif ($op == "delete") { // The comment is being deleted by the moderator. } switch ($op) { case "insert": // The comment is being inserted. break; case "update": // The comment is being updated. break; case "view": // The comment is being viewed. This hook can be used to add additional data to the comment before theming. break; case "validate": // The user has just finished editing the comment and is trying to preview or submit it. This hook can be used to check or even modify the node. Errors should be set with form_set_error(). break; case "publish": // The comment is being published by the moderator. break; case "unpublish": // The comment is being unpublished by the moderator. break; case "delete": // The comment is being deleted by the moderator. break; } cache_clear_all_like(drupal_url(array('id' => $nid))); } /* * Input Sanitization and Input Formats */ function example_check_markup() { // check_markup() -- Change the next line but leave this alone $node->body = check_markup($node->body, $node->format); // $node->body = check_markup($node->body, $node->format, $node->language); $content = check_markup($block->body, $block->format, FALSE); } function example_drupal_set_title() { // drupal_set_title() -- Change the next line but leave this alone drupal_set_title($node->title); drupal_set_title(check_plain($node->title)); drupal_set_title(t("@name's blog", array('@name' => $account->name))); drupal_set_title(t("@name's blog is %status", array('@name' => $account->name, '%status' => 'very popular'))); drupal_set_title(t("@name's blog is %status in !country", array('@name' => $account->name, '%status' => 'very popular', '!country' => 'my country'))); if (drupal_set_title(t("@name's blog", array('@name' => $account->name)))) { } drupal_set_title('check_plain' . ($node->title)); drupal_set_title(/* smoke screen */ 'check_plain' . check_plain($node->title/* smoke screen1 */ . 'xxx') . 'yyy' . check_plain($node->title2/* smoke screen2 */)); } /** * Implement hook_filter(). */ function example_filter($op, $delta = 0, $format = -1, $text = '', $cache_id = 0) { switch (/*smoke1*/ $op /*smoke2*/) { case /*smoke1*/ 'list' /*smoke2*/: return array(0 => t('Limit allowed HTML tags'), 1 => t('Convert line breaks'), 2 => t('Convert URLs into links'), 3 => t('Correct broken HTML'), 4 => t('Escape all HTML')); case /*smoke1*/ 'description' /*smoke2*/: switch ($delta) { case 0: return t('Allows you to restrict the HTML tags the user can use. It will also remove harmful content such as JavaScript events, JavaScript URLs and CSS styles from those tags that are not removed.'); case 1: return t('Converts line breaks into HTML (i.e. <br> and <p>) tags.'); case 2: return t('Turns web and e-mail addresses into clickable links.'); case 3: return t('Corrects faulty and chopped off HTML in postings.'); case 4: return t('Escapes all HTML tags, so they will be visible instead of being effective.'); default: return; } case 'process': switch ($delta) { case 0: return _filter_html($text, $format); case 1: return _filter_autop($text); case 2: return _filter_url($text, $format); case 3: return _filter_htmlcorrector($text); case 4: return trim(check_plain($text)); default: return $text; } case 'settings': switch ($delta) { case 0: return _filter_html_settings($format); case 2: return _filter_url_settings($format); default: return; } default: return $text; } } /** * Implement hook_filter_tips(). */ function example_filter_tips($delta, $format, $long = FALSE) { switch ($delta) { case 0: if ($allowed_html = variable_get("allowed_html_$format", '
    1. ')) { switch ($long) { case 0: return t('Allowed HTML tags: @tags', array('@tags' => $allowed_html)); case 1: $output = '

      ' . t('Allowed HTML tags: @tags', array('@tags' => $allowed_html)) . '

      '; if (!variable_get("filter_html_help_$format", 1)) { return $output; } } } break; case 1: switch ($long) { case 0: return t('Lines and paragraphs break automatically.'); case 1: return t('Lines and paragraphs are automatically recognized. The <br /> line break, <p> paragraph and </p> close paragraph tags are inserted automatically. If paragraphs are not recognized simply add a couple blank lines.'); } break; case 2: return t('Web page addresses and e-mail addresses turn into links automatically.'); break; case 4: return t('No HTML tags allowed.'); break; } } function example_hook_filter_urls() { $form[$id]['roles'] = array('#markup' => $default ? t('All roles may use default format') : ($roles ? implode(', ', $roles) : t('No roles may use this format'))); $form[$id]['edit'] = array('#markup' => l(t('edit'), 'admin/settings/filters/' . $id)); $form[$id]['delete'] = array('#markup' => $default ? '' : l(t('delete'), 'admin/settings/filters/delete/' . $id)); if ($url = 'admin/settings/filters/delete/' . $id) { } } function example_hook_filter_formats_parameters() { // filter_formats() -- Change the next line but leave this alone // Get a list of formats that the current user has access to. $formats = filter_formats(); $formats = filter_formats($index); } /* * Taxonomy */ // http://drupal.org/files/issues/taxonomy_get_tree-depth.patch function example_taxonomy_get_tree() { // Do we need to change module_invoke??? if ($vocabularies) { foreach ($vocabularies as $vocabulary) { $terms = module_invoke('taxonomy', 'get_tree', $vocabulary->vid, 0, 2); $terms = module_invoke('taxonomy', 'get_tree', $vocabulary->vid, 0, 2, NULL); $terms = module_invoke('taxonomy', 'get_tree', $vocabulary->vid, 0, 2, $max_depth); $terms = module_invoke('taxonomy', 'get_tree', $vocabulary->vid, 0, -1); $terms = module_invoke('taxonomy', 'get_tree', $vocabulary->vid, 0, -1, NULL); $terms = module_invoke('taxonomy', 'get_tree', $vocabulary->vid, 0, -1, $max_depth); $terms = module_invoke('taxonomy', 'get_tree', $vocabulary->vid, 0); foreach ($terms as $term) { $term_name = $term->name; foreach (module_invoke('taxonomy', 'get_parents', $term->tid, 'tid') as $parent) { } } } } // taxonomy_get_tree() -- Change the next line but leave this alone if (!empty($children[$vid][$child])) { $tree = array_merge($tree, taxonomy_get_tree($vid, $child, $depth, $max_depth)); // $tree = array_merge($tree, taxonomy_get_tree($vid, $child, $max_depth, $depth)); } // taxonomy_get_term_data() -- Change the next line but leave this alone foreach ($tids as $index => $tid) { $term = taxonomy_get_term_data($tid); $tree = taxonomy_get_tree($term->vid, $tid, 2); $tree = taxonomy_get_tree($term->vid, $tid, 2, NULL); $tree = taxonomy_get_tree($term->vid, $tid, 2, $depth); $tree = taxonomy_get_tree($term->vid, $tid, -1); $tree = taxonomy_get_tree($term->vid, $tid, -1, NULL); $tree = taxonomy_get_tree($term->vid, $tid, -1, $depth); $tree = taxonomy_get_tree($term->vid, $tid); } } function example_taxonomy_tables() { // vocabulary_node_types() -- Change the next line but leave this alone // term_node() -- Change the next line but leave this alone /* * {menu}, {term_data} or {vocabulary}. However, in most cases the usual * {menu}, {term_data} or {vocabulary}. However, it is more common to use the */ $result = db_query(db_rewrite_sql("SELECT t.tid, t.vid FROM {term_data} t INNER JOIN {vocabulary_node_types} n ON t.vid = n.vid WHERE t.tid IN (". db_placeholders($term_list) .") AND n.type = '%s'", 't', 'tid'), $params); // Look up all the vocabularies for this node type. $result2 = db_query(db_rewrite_sql("SELECT v.vid, v.name, v.required, v.multiple FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s'", 'v', 'vid'), $node->type); // Check each vocabulary associated with this node type. while ($vocabulary = db_fetch_object($result2)) { $row = array( // Required vocabularies must have at least one term. 'description' => 'The {term_data}.tid of the forum term assigned to the node.', ); } $result = db_query(db_rewrite_sql('SELECT t.tid, t.vid, t.name, t.description, t.weight FROM {term_data} t WHERE t.tid = %d AND t.vid = %d', 't', 'tid'), $tid, variable_get('forum_nav_vocabulary', '')); foreach ($node->taxonomy as $term) { if (db_result(db_query('SELECT COUNT(*) FROM {term_data} WHERE tid = %d AND vid = %d', $term, $vocabulary))) { } } $old_tid = db_result(db_query_range("SELECT t.tid FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.nid = %d ORDER BY t.vid DESC", $node->nid, 0, 1)); if ($op == 'delete' && $term['vid'] == variable_get('forum_nav_vocabulary', '')) { switch ($type) { case 'term': $results = db_query('SELECT tn.nid FROM {term_node} tn WHERE tn.tid = %d', $term['tid']); $tn_alias = $query->join('term_node', 'tn', 'tn.vid = n.vid'); $td_alias = $query->join('term_data', 'td', 'tn.tid = tn.tid'); case 'new': $title = t('New forum topics'); $sql = db_rewrite_sql("SELECT n.nid, n.title, l.comment_count FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid INNER JOIN {term_data} td ON td.tid = tn.tid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND td.vid = %d ORDER BY n.nid DESC"); break; } $sql = "SELECT r.tid, COUNT(n.nid) AS topic_count, SUM(l.comment_count) AS comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {term_node} r ON n.vid = r.vid WHERE n.status = 1 GROUP BY r.tid"; // This query does not use full ANSI syntax since MySQL 3.x does not support // table1 INNER JOIN table2 INNER JOIN table3 ON table2_criteria ON table3_criteria // used to join node_comment_statistics to users. $sql = "SELECT ncs.last_comment_timestamp, IF (ncs.last_comment_uid != 0, u2.name, ncs.last_comment_name) AS last_comment_name, ncs.last_comment_uid FROM {node} n INNER JOIN {users} u1 ON n.uid = u1.uid INNER JOIN {term_node} tn ON n.vid = tn.vid INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid INNER JOIN {users} u2 ON ncs.last_comment_uid=u2.uid WHERE n.status = 1 AND tn.tid = %d ORDER BY ncs.last_comment_timestamp DESC"; } $sql = "SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} tn ON n.vid = tn.vid AND tn.tid = %d LEFT JOIN {history} h ON n.nid = h.nid AND h.uid = %d WHERE n.status = 1 AND n.created > %d AND h.nid IS NULL"; $sql = db_rewrite_sql("SELECT n.nid, r.tid, n.title, n.type, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid != 0, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments, f.tid AS forum_tid FROM {node_comment_statistics} l INNER JOIN {node} n ON n.nid = l.nid INNER JOIN {users} cu ON l.last_comment_uid = cu.uid INNER JOIN {term_node} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {forum} f ON n.vid = f.vid WHERE n.status = 1 AND r.tid = %d"); $sql_count = db_rewrite_sql("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} r ON n.vid = r.vid AND r.tid = %d WHERE n.status = 1"); $sql = "SELECT n.nid, n.title, n.sticky, l.comment_count, l.last_comment_timestamp FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.status = 1 ORDER BY n.sticky DESC, " . _forum_get_topic_order_sql(variable_get('forum_order', 1)); // Verify forum. $term = db_fetch_array(db_query("SELECT * FROM {term_data} t WHERE t.vid = %d AND t.name = '%s' AND t.description = '%s'", variable_get('forum_nav_vocabulary', ''), $name, $description)); $parent_tid = db_result(db_query("SELECT t.parent FROM {term_hierarchy} t WHERE t.tid = %d", $tid)); /* * @param array $forum Forum array (a row from term_data table). * @param array $forum Forum array (a row from term_data table). */ $join .= "INNER JOIN {term_node} $table ON n.nid = $table.nid "; $join1 .= ' INNER JOIN {term_node} tn ON n.vid = tn.vid'; $join1 .= ' INNER JOIN {term_node} tn ON n.vid = tn.vid'; $row = array( 'description' => 'The {term_data}.tid of the term.', ); $results = pager_query(db_rewrite_sql('SELECT t.*, h.parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $page_increment, 0, NULL, $vocabulary->vid); $total_entries = db_query(db_rewrite_sql('SELECT count(*) FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = :vid'), array(':vid' => $vocabulary->vid)); db_query('UPDATE {term_data} SET weight = 0 WHERE vid = :vid', array(':vid' => $form_state['values']['vid'])); db_insert('term_synonym'); } function example_taxonomy_crud() { // taxonomy_get_term() -- Change the next line but leave this alone // taxonomy_save_term() -- Change the next line but leave this alone // taxonomy_del_term() -- Change the next line but leave this alone taxonomy_get_term($tid); // taxonomy_term_load($tid) taxonomy_save_term($form_values); // taxonomy_term_save($term) (Old is ODD!!!) taxonomy_del_term($tid); // taxonomy_term_delete($tid) // taxonomy_vocabulary_load() -- Change the next line but leave this alone // taxonomy_save_vocabulary() -- Change the next line but leave this alone // taxonomy_del_vocabulary() -- Change the next line but leave this alone taxonomy_vocabulary_load($vid); taxonomy_save_vocabulary($edit); // taxonomy_vocabulary_save($vocabulary) taxonomy_del_vocabulary($vid); // taxonomy_vocabulary_delete($vid) } // http://drupal.org/node/224333#taxonomy_form_all function example_taxonomy_form_all() { $form = array(); $form['term'] = array( '#type' => 'select', '#title' => t('Term'), '#options' => taxonomy_form_all(), '#description' => t('Select a term to apply to the node. Keep in mind that the selected product node type must have the selected vocabulary enabled.'), '#default_value' => $settings['term'], ); $terms = taxonomy_form_all(); if ($terms) { $form['term'] = array( '#type' => 'select', '#title' => t('Term'), '#options' => $terms, '#description' => t('Select a term to apply to the node. Keep in mind that the selected product node type must have the selected vocabulary enabled.'), '#default_value' => $settings['term'], ); } return $form; } // http://drupal.org/node/224333#no-synonyms-taxonomy function example_no_synonyms_taxonomy() { $synonyms = taxonomy_get_synonyms($tid); $synonyms = taxonomy_get_synonyms(0); function_call(taxonomy_get_synonyms($tid)); $root = taxonomy_get_synonym_root($synonyms[0]); $root = taxonomy_get_synonym_root(0); $synonyms = db_query("SELECT * FROM {term_synonym} s WHERE s.name = '%s'", $synonym); } /* * Javascript */ // http://drupal.org/node/224333#drupal_add_js_external function example_drupal_add_js_external() { // Single quotes. drupal_set_html_head('