diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/comment.inc | 16 | ||||
-rw-r--r-- | includes/common.inc | 27 | ||||
-rw-r--r-- | includes/module.inc | 2 | ||||
-rw-r--r-- | includes/node.inc | 11 | ||||
-rw-r--r-- | includes/theme.inc | 57 | ||||
-rw-r--r-- | includes/user.inc | 10 |
6 files changed, 44 insertions, 79 deletions
diff --git a/includes/comment.inc b/includes/comment.inc index 9bbc0c259..dc5bbd48a 100644 --- a/includes/comment.inc +++ b/includes/comment.inc @@ -87,7 +87,7 @@ function comment_reply($pid, $id) { $pid = 0; } - if (user_access($user, "post comments")) { + if (user_access("post comments")) { $theme->box(t("Reply"), comment_form(array(pid=>$pid, id=>$id))); } else { @@ -107,7 +107,7 @@ function comment_preview($edit) { function comment_post($edit) { global $theme, $user; - if (user_access($user, "post comments")) { + if (user_access("post comments")) { // check comment submission rate: throttle("post comment", variable_get(max_comment_rate, 60)); @@ -213,7 +213,7 @@ function comment_uri($args = 0) { else return ($mod) ? "module.php?mod=$mod" : "node.php"; } -function comment_link($comment, $return = 1) { +function comment_links($comment, $return = 1) { global $theme; if ($return) return "<A HREF=\"". comment_uri("id=$comment->lid#$comment->cid") ."\"><FONT COLOR=\"$theme->type\">". t("return") ."</FONT></A> | <A HREF=\"". comment_uri("op=reply&id=$comment->lid&pid=$comment->cid") ."\"><FONT COLOR=\"$theme->type\">". t("reply to this comment") ."</FONT></A>"; else return "<A HREF=\"". comment_uri("op=reply&id=$comment->lid&pid=$comment->cid") ."\"><FONT COLOR=\"$theme->type\">". t("reply to this comment") ."</FONT></A>"; @@ -250,7 +250,7 @@ function comment_thread_max($cid, $mode, $threshold, $level = 0, $dummy = 0) { while ($comment = db_fetch_object($result)) { print "<UL>"; - comment_view($comment, (comment_visible($comment, $threshold) ? comment_link($comment, 0) : 0)); + comment_view($comment, (comment_visible($comment, $threshold) ? comment_links($comment, 0) : 0)); comment_thread_max($comment->cid, $mode, $threshold, $level + 1, $dummy + 1); print "</UL>"; } @@ -259,7 +259,7 @@ function comment_thread_max($cid, $mode, $threshold, $level = 0, $dummy = 0) { function comment_render($lid, $cid) { global $user, $theme, $REQUEST_URI; - if (user_access($user, "view comments")) { + if (user_access("access comments")) { // Pre-process variables: $lid = empty($lid) ? 0 : $lid; @@ -279,7 +279,7 @@ function comment_render($lid, $cid) { if ($cid > 0) { $result = db_query("SELECT c.*, u.* FROM comments c LEFT JOIN users u ON c.author = u.id WHERE cid = '$cid'"); if ($comment = db_fetch_object($result)) { - comment_view($comment, comment_link($comment)); + comment_view($comment, comment_links($comment)); } } else { @@ -297,7 +297,7 @@ function comment_render($lid, $cid) { else if ($mode == 2) { $result = comment_query($lid, $order); while ($comment = db_fetch_object($result)) { - comment_view($comment, (comment_visible($comment, $threshold) ? comment_link($comment, 0) : 0)); + comment_view($comment, (comment_visible($comment, $threshold) ? comment_links($comment, 0) : 0)); } } else if ($mode == 3) { @@ -310,7 +310,7 @@ function comment_render($lid, $cid) { else { $result = comment_query($lid, $order, 0); while ($comment = db_fetch_object($result)) { - comment_view($comment, (comment_visible($comment, $threshold) ? comment_link($comment, 0) : 0)); + comment_view($comment, (comment_visible($comment, $threshold) ? comment_links($comment, 0) : 0)); comment_thread_max($comment->cid, $mode, $threshold, $level + 1); } } diff --git a/includes/common.inc b/includes/common.inc index a5b82357c..9ef2da44f 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -24,8 +24,7 @@ function watchdog($type, $message) { } function throttle($type, $rate) { - global $user; - if (!user_access($user, "access administration pages")) { + if (!user_access("access administration pages")) { if ($throttle = db_fetch_object(db_query("SELECT * FROM watchdog WHERE type = '$type' AND hostname = '". getenv("REMOTE_ADDR") ."' AND ". time() ." - timestamp < $rate"))) { watchdog("warning", "throttle: '". getenv("REMOTE_ADDR") ."' exceeded submission rate - $throttle->type"); die(message_throttle()); @@ -135,8 +134,7 @@ function format_date($timestamp, $type = "medium", $format = "") { } function format_username($username) { - global $user; - if ($username) return (user_access($user, "add and edit user accounts") ? "<A HREF=\"admin.php?mod=account&op=view&name=". urlencode($username) ."\">$username</A>" : "<A HREF=\"account.php?op=view&name=". urlencode($username) ."\">$username</A>"); + if ($username) return (user_access("administer accounts") ? "<A HREF=\"admin.php?mod=account&op=view&name=". urlencode($username) ."\">$username</A>" : "<A HREF=\"account.php?op=view&name=". urlencode($username) ."\">$username</A>"); else return variable_get(anonymous, "Anonymous"); } @@ -209,6 +207,27 @@ function field_merge($a, $b) { return $a; } +function link_page() { + + $links[] = "<a href=\"index.php\">". t("home") ."</a>"; + $links[] = "<a href=\"search.php\">". t("search") ."</a>"; + $links[] = "<a href=\"submit.php\">". t("submit") ."</a>"; + $links[] = "<a href=\"account.php\">". t("account") ."</a>"; + + foreach (module_list() as $name) { + if (module_hook($name, "link")) { + $links = array_merge($links, module_invoke($name, "link", "page")); + } + } + + + return $links; +} + +function link_node($node) { + return module_invoke("node", "link", array("node", $node)); +} + function timer_start() { global $timer; $timer = explode(" ", microtime()); diff --git a/includes/module.inc b/includes/module.inc index 2843e5547..cbbb1b18d 100644 --- a/includes/module.inc +++ b/includes/module.inc @@ -11,7 +11,7 @@ function module_iterate($function, $argument = "") { } // invoke hook $hook of module $name with optional arguments: -function module_invoke($name, $hook, $argument = "") { +function module_invoke($name, $hook, $argument = 0) { $function = $name ."_". $hook; return function_exists($function) ? $function($argument) : $argument; } diff --git a/includes/node.inc b/includes/node.inc index affb44371..47a317547 100644 --- a/includes/node.inc +++ b/includes/node.inc @@ -236,20 +236,11 @@ function node_index($node) { function node_visible($node) { global $user, $status; - return ($node->status == $status[posted]) || ($node->status == $status[queued] && $user->id) || user_access($user, $node->type) || user_access($user, "add and edit nodes"); + return ($node->status == $status[posted]) || ($node->status == $status[queued] && $user->id) || user_access("administer nodes"); } function node_access($account, $node) { return strstr($node->moderate, $account->userid); } -function node_links(&$links, &$node, $main = 0) { - if ($main) { - if ($node->body) $_links[] = array("node.php?id=$node->nid", t("read more")); - if ($node->comment) $_links[] = array("node.php?id=$node->nid", format_plural(node_get_comments($node->nid), "comment", "comments")); - } - $links = ($links ? array_merge($_links, $links) : $_links); - return count($links) ? $links : 0; -} - ?>
\ No newline at end of file diff --git a/includes/theme.inc b/includes/theme.inc index b01638d60..9530c60b1 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -1,16 +1,8 @@ <?php class BaseTheme { - function links(&$links, $state = 0) { - // $state = 0 : default behaviour - // $state = 1 : main page - // $state = 2 : theme_link() - // Subject to change coz its messy - foreach ($links as $link) { - if ($link[0]) $_links[] = count($link) == 2 ? "<A HREF=\"$link[0]\"><FONT COLOR=\"$theme->link\">". t($link[1]) ."</FONT></A>" : t($link[0]); - } - - return ($_links ? implode(" | ", $_links) : ""); + function links($links, $delimiter = " | ") { + return implode($delimiter, $links); } } @@ -26,21 +18,6 @@ function theme_init() { return new Theme(); } -function theme_link() { - global $user, $theme; - $links[] = array("index.php", t("home")); - $links[] = array("search.php", t("search")); - $links[] = array("submit.php", t("submit")); - $links[] = array("account.php", t("account")); - - foreach (module_list() as $name) { - if (module_hook($name, "page")) $links[] = array("module.php?mod=$name", t($name)); - } - - return $theme->links($links, 2); -} - - function theme_account($theme) { global $user; @@ -55,13 +32,14 @@ function theme_account($theme) { $content .= "<A HREF=\"account.php?op=edit&topic=content\">". t("edit your content") ."</A><BR>\n"; $content .= "<P>\n"; - if (user_access($user, "access administration pages")) { + if (user_access("access administration pages")) { $content .= "<A HREF=\"admin.php\">". strtr(t("administer %a"), array("%a" => variable_get("site_name", "drupal"))) ."</A><BR>\n"; $content .= "<P>\n"; } foreach (module_list() as $name) { - if ($links = module_invoke($name, "menu")) { + if (module_hook($name, "link")) { + $links = module_invoke($name, "link", "menu"); foreach ($links as $link) $content .= "$link<BR>\n"; } } @@ -119,29 +97,4 @@ function theme_moderation_results($theme, $node) { $theme->box(t("Moderation results"), ($output ? $output : t("This node has not been moderated yet."))); } -/* -// -// depricated -> new block strategy -// -function theme_new_headlines($theme, $num = 10) { - $result = db_query("SELECT nid, title FROM node WHERE status = 2 AND type = 'story' ORDER BY nid DESC LIMIT $num"); - while ($node = db_fetch_object($result)) $content .= "<LI><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></LI>\n"; - $theme->box(t("Latest headlines"), $content); -} - -function theme_old_headlines($theme, $num = 10) { - global $user; - - $result = db_query("SELECT id, subject, timestamp FROM story WHERE status = 2 ORDER BY timestamp DESC LIMIT ". ($user->nodes ? $user->nodes : $num) .", $num"); - while ($node = db_fetch_object($result)) { - if ($time != date("F jS", $node->timestamp)) { - $content .= "<P><B>". date("l, M jS", $node->timestamp) ."</B></P>\n"; - $time = date("F jS", $node->timestamp); - } - $content .= "<LI><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></LI>\n"; - } - $theme->box(t("Older headlines"), $content); -} -*/ - ?> diff --git a/includes/user.inc b/includes/user.inc index 5e0bf2274..9e1370f6b 100644 --- a/includes/user.inc +++ b/includes/user.inc @@ -52,12 +52,14 @@ function user_save($account, $array) { return user_load(($account->userid ? $account->userid : $array[userid])); } -function user_access($account, $perm) { - if ($account->id == 1) { +function user_access($perm) { + global $user; + + if ($user->id == 1) { return 1; } - else if ($account->perm) { - return strstr($account->perm, $perm); + else if ($user->perm) { + return strstr($user->perm, $perm); } else { return db_fetch_object(db_query("SELECT * FROM role WHERE name = 'anonymous user' AND perm LIKE '%$perm%'")); |