". 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 includes nid and title from node table, and name from the user table // returns an HTML list suitable as content for a block, and eventually other uses. function node_title_list($result, $title = NULL) { // no queries if site is in distress if (module_exist("statistics") && throttle_status() > 4) { return; } while ($node = db_fetch_object($result)) { $number = module_invoke("comment", "num_all", $node->nid); $name = strip_tags(format_name($node)); // required for anonymous users to work $items[] = l(check_output($node->title), array("id" => $node->nid), "node", "", array("title" => t("Author: %name, comments: %number", array("%name" => $name, "%number" => $number)))); } return theme_invoke("theme_item_list", $items, $title); } 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. */ $delimiter = strpos($body, "---"); if ($delimiter > 100 && $delimiter < $size) { 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, "\n", $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); } if ($length = strpos($body, "

", $size)) { return substr($body, 0, $length + 1); } /* ** 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, $name, $arg = 0) { if (is_array($node)) { $function = $node["type"] ."_$name"; } else if (is_object($node)) { $function = $node->type ."_$name"; } else if (is_string($node)) { $function = $node ."_$name"; } if (function_exists($function)) { return ($arg ? $function($node, $arg) : $function($node)); } } 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, $filter) { $fields = array("nid", "uid", "type", "title", "teaser", "body", "revisions", "score", "status", "comment", "promote", "static", "moderate", "created", "changed", "users", "votes"); foreach ($filter as $key => $value) { /* ** Only save those fields specified by the filter. If the filter ** does not specify a default value, use the value of the $node's ** corresponding field instead. */ if (is_numeric($key)) { if (isset($node->$value)) { // The above check is mandatory. $edit->$value = $node->$value; } } else { if (isset($value)) { // The above check is mandatory. $edit->$key = $value; } } } $node = $edit; /* ** 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"); // 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): module_invoke($node->type, "insert", $node); } 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): module_invoke($node->type, "update", $node); } /* ** 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) { global $theme; $node = array2object($node); /* ** Remove the delimiter (if any) that seperates the teaser from the ** body. */ $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: */ $theme->node($node, $main); } } 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) { global $PHP_SELF; // 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_conf_options() { $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 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'.")); return $output; } function node_conf_filters() { $output .= form_select(t("Enable HTML tags"), "filter_html", variable_get("filter_html", 0), array(t("Disabled"), t("Enabled")), t("Allow HTML and PHP tags in user-contributed content.")); $output .= form_textfield(t("Allowed HTML tags"), "allowed_html", variable_get("allowed_html", "