". ucfirst($name) ." type"; print module_invoke($name, "help"); } } } } // DEPRICATED: still used by themes, yet doesn't return anything at the moment function node_index() { } function node_teaser($body) { $size = 400; /* ** If we have a short body, return the entire body: */ if (strlen($body) < $size) { return $body; } /* ** If we have a long body, try not to split paragraphs: */ if ($length = strpos($body, "\n", $size)) { return substr($body, 0, $length + 1); } /* ** If we have a long body, try not to split sentences: */ return substr($body, 0, strpos($body, ". ", $size) + 1); } 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: $node->created = time(); $node->changed = time(); $node->nid = db_result(db_query("SELECT MAX(nid) + 1 FROM node")); $node->nid = empty($node->nid) ? 1 : $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): 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); } /* ** Return the node ID: */ return $node->nid; } function node_view($node, $main = 0) { global $theme; $node = array2object($node); /* ** 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; } else { /* ** 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", "post 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("Default number of nodes to display"), "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 nodes to display on the main page.")); return $output; } function node_conf_filters() { $output .= form_select(t("Enable HTML tags"), "filter_html", variable_get("filter_html", 0), array("Disabled", "Enabled"), t("Allow HTML and PHP tags in user-contributed content.")); $output .= form_textfield(t("Allowed HTML tags"), "allowed_html", variable_get("allowed_html", "