". t("%module type", array("%module" => ucfirst(module_invoke($name, "node", "name")))). ""; print module_invoke($name, "help"); } } } } function node_system($field){ $system["description"] = t("The core that allows content to be submitted to the site."); return $system[$field]; } /* ** Accepts a DB result object which can be used to fetch node objects. ** Returns an HTML list suitable as content for a block. */ function node_title_list($result, $title = NULL) { // no queries if site is in distress if (module_exist("statistics") && throttle_status() > 3) { return; } while ($node = db_fetch_object($result)) { $number = module_invoke("comment", "num_all", $node->nid); $items[] = l($node->title, "node/view/$node->nid", array("title" => t("Comments: %number", array("%number" => $number)))); } return theme("theme_node_list", $items, $title); } function theme_node_list($items, $title = NULL) { return theme("theme_item_list", $items, $title); } // Update the 'last viewed' timestamp of the specified node for current user. function node_tag_new($nid) { global $user; if ($user->uid) { $nid = check_query($nid); $result = db_query("SELECT timestamp FROM history WHERE uid = %d AND nid = %d", $user->uid, $nid); if (db_fetch_object($result)) { db_query("UPDATE history SET timestamp = %d WHERE uid = %d AND nid = %d", time(), $user->uid, $nid); } else { db_query("INSERT INTO history (uid, nid, timestamp) VALUES (%d, %d, %d)", $user->uid, $nid, time()); } } } /* ** Retrieves the timestamp at which the current user last viewed the ** specified node. */ function node_last_viewed($nid) { global $user; $history = db_fetch_object(db_query("SELECT timestamp FROM history WHERE uid = '$user->uid' AND nid = %d", $nid)); return ($history->timestamp ? $history->timestamp : 0); } /** * Determines whether the supplied timestamp is newer than the user's last view of a given node * * @param $nid node-id twhose history supplies the 'last viewed' timestamp * @param $timestamp time which is compared against node's 'last veiwed' timestamp */ function node_is_new($nid, $timestamp) { global $user; static $cache; if (!isset($cache[$nid])) { if ($user->uid) { $history = db_fetch_object(db_query("SELECT timestamp FROM history WHERE uid = %d AND nid = %d", $user->uid, $nid)); $cache[$nid] = $history->timestamp ? $history->timestamp : 0; } else { $cache[$nid] = time(); } } if ($timestamp > $cache[$nid]) { return 1; } else { return 0; } } function node_teaser($body) { $size = variable_get("teaser_length", 600); /* ** If the size is zero, teasers are disabled so we ** return the entire body. */ if ($size == 0) { return $body; } /* ** If we have a short body, return the entire body: */ if (strlen($body) < $size) { return $body; } /* ** If a valid delimiter has been specified, use it to ** chop of the teaser. The delimiter can be outside ** the allowed range but no more than a factor two. */ $delimiter = strpos($body, ""); if ($delimiter > 0) { return substr($body, 0, $delimiter); } /* ** In some cases no delimiter has been specified (eg. ** when posting using the Blogger API) in which case ** we try to split at paragraph boundaries. */ if ($length = strpos($body, "
", $size)) { return substr($body, 0, $length); } if ($length = strpos($body, "
", $size)) { return substr($body, 0, $length); } if ($length = strpos($body, "

", $size)) { return substr($body, 0, $length); } if ($length = strpos($body, "\n", $size)) { return substr($body, 0, $length); } /* ** When even the first paragraph is too long, try to ** split at the end of the next sentence. */ if ($length = strpos($body, ". ", $size)) { return substr($body, 0, $length + 1); } if ($length = strpos($body, "! ", $size)) { return substr($body, 0, $length + 1); } if ($length = strpos($body, "? ", $size)) { return substr($body, 0, $length + 1); } /* ** Nevermind, we split it the hard way ... */ return substr($body, 0, $size); } function node_invoke(&$node, $hook, $arg = 0) { if (is_array($node)) { $function = $node["type"] ."_$hook"; } else if (is_object($node)) { $function = $node->type ."_$hook"; } else if (is_string($node)) { $function = $node ."_$hook"; } if (function_exists($function)) { return ($arg ? $function($node, $arg) : $function($node)); } } function node_invoke_all(&$node, $hook, $op, $arg = 0) { $return = array(); foreach (module_list() as $name) { if ((module_hook($name, "node") || module_hook($name, "nodeapi")) && module_hook($name, $hook)) { $function = $name ."_". $hook; $result = $function($node, $op, $arg); if (isset($result)) { $return = array_merge($return, $result); } } } return $return; } function node_load($conditions) { /* ** Turn the conditions into a query: */ foreach ($conditions as $key => $value) { $cond[] = "n.". check_query($key) ." = '". check_query($value) ."'"; } /* ** Retrieve the node: */ $node = db_fetch_object(db_query("SELECT n.*, u.uid, u.name FROM node n LEFT JOIN users u ON u.uid = n.uid WHERE ". implode(" AND ", $cond))); /* ** Unserialize the revisions field: */ if ($node->revisions) { $node->revisions = unserialize($node->revisions); } /* ** Call the node specific callback (if any) and piggy-back the ** results to the node or overwrite some values: */ if ($extra = module_invoke($node->type, "load", $node)) { foreach ($extra as $key => $value) { $node->$key = $value; } } return $node; } function node_save($node) { /* ** Fetch fields to save to node table: */ $fields = node_invoke_all($node, "nodeapi", "fields"); /* ** Serialize the revisions field: */ if ($node->revisions) { $node->revisions = serialize($node->revisions); } /* ** Apply filters to some default node fields: */ if (empty($node->nid)) { /* ** Insert a new node: */ // Set some required fields: if (!$node->created) { $node->created = time(); } $node->changed = time(); $node->nid = db_next_id("node_nid"); // Prepare the query: foreach ($node as $key => $value) { if (in_array($key, $fields)) { $k[] = check_query($key); $v[] = "'". check_query($value) ."'"; } } // Insert the node into the database: db_query("INSERT INTO node (". implode(", ", $k) .") VALUES (". implode(", ", $v) .")"); // Call the node specific callback (if any): node_invoke($node, "insert"); node_invoke_all($node, "nodeapi", "insert"); } else { /* ** Update an existing node: */ // Set some required fields: $node->changed = time(); // Prepare the query: foreach ($node as $key => $value) { if (in_array($key, $fields)) { $q[] = check_query($key) ." = '". check_query($value) ."'"; } } // Update the node in the database: db_query("UPDATE node SET ". implode(", ", $q) ." WHERE nid = '$node->nid'"); // Call the node specific callback (if any): node_invoke($node, "update"); node_invoke_all($node, "nodeapi", "update"); } /* ** Clear the cache so an anonymous poster can see the node being ** added or updated. */ cache_clear_all(); /* ** Return the node ID: */ return $node->nid; } function node_view($node, $main = 0) { $node = array2object($node); /* ** Remove the delimiter (if any) that seperates the teaser from the ** body. TODO: this strips legitimate uses of '' also. */ $node->body = str_replace("", "", $node->body); /* ** The "view" hook can be implemented to overwrite the default function ** to display nodes. */ if (module_hook($node->type, "view")) { node_invoke($node, "view", $main); } else { /* ** Default behavior: */ $node->teaser = filter($node->teaser); $node->body = filter($node->body); theme("node", $node, $main); } } function node_show($nid, $cid) { global $revision; $node = node_load(array("status" => 1, "nid" => $nid)); if (node_access("view", $node)) { if (isset($revision)) { $node = $node->revisions[$revision]["node"]; } node_view($node); if (function_exists("comment_render") && $node->comment) { comment_render($node, $cid); } /* ** Update the history table, stating that this user viewed this node. */ node_tag_new($node->nid); } } function node_access($op, $node = 0) { if (user_access("administer nodes")) { return 1; } /* ** Convert the node to an object if necessary: */ $node = array2object($node); /* ** Construct a function: */ if ($node->type) { $type = $node->type; } else { $type = $node; } $function = $type ."_access"; if (function_exists($function)) { return $function($op, $node); } else { return 0; } } function node_perm() { return array("administer nodes", "access content"); } function node_search($keys) { // Return the results of performing a search using the indexed search // for this particular type of node. // // Pass an array to the "do_search" function which dictates what it // will search through, and what it will search for // // "keys"'s value is the keywords entered by the user // // "type"'s value is used to identify the node type in the search // index. // // "select"'s value is used to relate the data from the specific nodes // table to the data that the search_index table has in it, and the the // do_search functino will rank it. // // The select must always provide the following fields - lno, title, // created, uid, name, count // $find = do_search(array("keys" => $keys, "type" => "node", "select" => "select s.lno as lno, n.title as title, n.created as created, u.uid as uid, u.name as name, s.count as count FROM search_index s, node n LEFT JOIN users u ON n.uid = u.uid WHERE s.lno = n.nid AND s.type = 'node' AND s.word like '%' AND n.status = 1")); return $find; } function node_settings() { $output .= form_select(t("Number of posts on main page"), "default_nodes_main", variable_get("default_nodes_main", 10), array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 15 => 15, 20 => 20, 25 => 25, 30 => 30), t("The default maximum number of posts to display on overview pages such as the main page.")); $output .= form_select(t("Length of trimmed posts"), "teaser_length", variable_get("teaser_length", 600), array(0 => t("Unlimited"), 200 => t("200 characters"), 400 => t("400 characters"), 600 => t("600 characters"), 800 => t("800 characters"), 1000 => t("1000 characters"), 1200 => t("1200 characters"), 1400 => t("1400 characters"), 1600 => t("1600 characters"), 1800 => t("1800 characters"), 2000 => t("2000 characters")), t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited'.")); $output .= form_select(t("Preview post"), "node_preview", variable_get("node_preview", 0), array(t("Optional"), t("Required")), t("Must users preview posts before submitting?")); return $output; } function node_conf_filters() { $output .= form_select(t("Filter HTML tags"), "filter_html", variable_get("filter_html", 0), array(t("Disabled"), t("Enabled")), t("Filter HTML and PHP tags in user-contributed content.")); $output .= form_textfield(t("Allowed HTML tags"), "allowed_html", variable_get("allowed_html", "