예제 #1
0
/**
 * Process CMS tags into HTML for comments.
 */
function cms_tag_comments($tag_attr, $tag_default)
{
    global $db, $row, $block, $Current_weblog, $Weblogs, $Paths;
    if (strlen($Weblogs[$Current_weblog]['comment_format']) > 1) {
        $format = $Weblogs[$Current_weblog]['comment_format'];
    } else {
        $format = "%anchor%<p>%comment%</p><p><small><b>%name%</b> %email% %url% - %date%</small></p>";
    }
    if (strlen($Weblogs[$Current_weblog]['comment_reply']) > 1) {
        $format_reply = $Weblogs[$Current_weblog]['comment_reply'];
    } else {
        $format_reply = "Reply on %name%";
    }
    if (strlen($Weblogs[$Current_weblog]['comment_forward']) > 1) {
        $format_forward = $Weblogs[$Current_weblog]['comment_forward'];
    } else {
        $format_forward = "Replied on by %name%";
    }
    if (strlen($Weblogs[$Current_weblog]['comment_backward']) > 1) {
        $format_backward = $Weblogs[$Current_weblog]['comment_backward'];
    } else {
        $format_backward = "This is a reply on %name%";
    }
    // If %editlink% is not present, insert it right after %date%..
    if (strpos($format, "%editlink%") == 0) {
        $format = str_replace("%date%", "%date% %editlink%", $format);
    }
    $content_code = get_attr_value('content_code', $tag_attr);
    $nocomments = get_attr_value('ifnocomments', $tag_attr);
    $comments = get_attr_value('ifcomments', $tag_attr);
    $order = get_attr_value('order', $tag_attr);
    $entrydate = $Weblogs[$Current_weblog]['fulldate_format'];
    if ($content_code == "") {
        $content_code = $row["code"];
    }
    $last_comment = "";
    if (isset($db->entry['comments']) && count($db->entry['comments']) > 0) {
        // first, make a list of comment-on-comments..
        $crosslink = array();
        foreach ($db->entry['comments'] as $count => $temp_row) {
            if (preg_match("/\\[(.*):([0-9]*)\\]/Ui", $temp_row['comment'], $matches)) {
                $crosslink[$count + 1] = $matches[2];
                // remove [name:1] from comment..
                $db->entry['comments'][$count]['comment'] = str_replace($matches[0], "", $db->entry['comments'][$count]['comment']);
            }
        }
        $last_count = count($db->entry['comments']) - 1;
        foreach ($db->entry['comments'] as $count => $temp_row) {
            /**
             * If we get here, this is a record we have to output in some form..
             */
            $temp_row['name'] = strip_tags($temp_row['name']);
            $temp_row['email'] = strip_tags($temp_row['email']);
            $temp_row['url'] = strip_tags($temp_row['url']);
            // Set the flag to display the 'awaiting moderation' text.
            if ($temp_row["moderate"] == 1) {
                $awaiting_moderation = true;
            }
            // Check if the comment is different than the last one, if the author's
            // IP isn't blocked, and if the comment isn't waiting for moderation.
            if ($temp_row["ip"] . $temp_row["comment"] != $last_comment && !ip_check_block($temp_row["ip"]) && ($temp_row["moderate"] != 1 || $temp_row['showpreview'] == 1)) {
                /**
                 * make email link..
                 */
                if (isemail($temp_row["email"]) && !$temp_row["discreet"]) {
                    $email_format = "(" . encodemail_link($temp_row["email"], lang('email'), $temp_row["name"]) . ")";
                    $emailtoname = encodemail_link($temp_row["email"], $temp_row["name"], $temp_row["name"]);
                } else {
                    $email_format = "";
                    $emailtoname = $temp_row["name"];
                }
                if (isemail($temp_row["email"])) {
                    $grav_email = $temp_row["email"];
                    $grav_default = $Weblogs[$Current_weblog]['comment_gravatardefault'];
                    $grav_html = stripslashes($Weblogs[$Current_weblog]['comment_gravatarhtml']);
                    $grav_size = $Weblogs[$Current_weblog]['comment_gravatarsize'];
                    if ($grav_default == "") {
                        $grav_default = "http://www.pivotlog.net/images/gravatar.gif";
                    }
                    if ($grav_html == "") {
                        $grav_html = '<img src="%img%" align="right" valign="top" hspace="2" vspace="2" />';
                    }
                    if ($grav_size == "") {
                        $grav_size = 48;
                    }
                    $grav_imgurl = "http://www.gravatar.com/avatar.php?gravatar_id=" . md5($grav_email) . "&amp;default=" . urlencode($grav_default) . "&amp;size=" . $grav_size;
                    $grav_url = str_replace("%img%", $grav_imgurl, $grav_html);
                } else {
                    $grav_url = "";
                }
                /**
                 * make url link..
                 */
                if (isurl($temp_row["url"])) {
                    if (strpos($temp_row["url"], "ttp://") < 1) {
                        $temp_row["url"] = "http://" . $temp_row["url"];
                    }
                    $target = $Weblogs[$Current_weblog]['target_blank'] == 1 ? " target='_blank'" : "";
                    $temp_row["url_title"] = str_replace('http://', '', $temp_row["url"]);
                    //perhaps redirect the link..
                    if (isset($Weblogs[$Current_weblog]['lastcomm_redirect']) && $Weblogs[$Current_weblog]['lastcomm_redirect'] == 1) {
                        $target .= " rel=\"nofollow\" ";
                    }
                    $url_format = sprintf("(<a href='%s' {$target} title='%s'>%s</a>)", $temp_row["url"], $temp_row["url_title"], lang('url'));
                    $urltoname = sprintf("<a href='%s' {$target} title='%s'>%s</a>", $temp_row["url"], $temp_row["url_title"], $temp_row['name']);
                } else {
                    $url_format = "";
                    $urltoname = $temp_row["name"];
                }
                /**
                 * Make 'edit' and 'delete' links..
                 */
                $editlink = get_editcommentlink($db->entry['code'], $count);
                /**
                 * make a 'registered user' span..
                 */
                if ($temp_row['registered'] == 1) {
                    $name = "<span class='registered'>[" . $temp_row["name"] . "]</span>";
                } else {
                    $name = $temp_row["name"];
                }
                /**
                 * make quote link..
                 */
                $quote = sprintf("<a href='#form' onclick='javascript:var pv=document.getElementsByName(\"piv_comment\");pv[0].value=\"[%s:%s] \"+pv[0].value;'>%s</a>", $temp_row["name"], $count + 1, $format_reply);
                // make backward link..
                if (isset($crosslink[$count + 1])) {
                    $to = $db->entry['comments'][$crosslink[$count + 1] - 1];
                    $backward_text = str_replace("%name%", $to['name'], $format_backward);
                    $backward_anchor = safe_string($to["name"], TRUE) . "-" . format_date($to["date"], "%ye%%month%%day%%hour24%%minute%");
                    $backward_link = sprintf("<a href='#%s'>%s</a>", $backward_anchor, $backward_text);
                } else {
                    $backward_link = "";
                }
                /**
                 * make forward link..
                 */
                $forward_link = "";
                foreach ($crosslink as $key => $val) {
                    if ($val - 1 == $count) {
                        $from = $db->entry['comments'][$key - 1];
                        $forward_text = str_replace("%name%", $from['name'], $format_forward);
                        $forward_anchor = safe_string($from["name"], TRUE) . "-" . format_date($from["date"], "%ye%%month%%day%%hour24%%minute%");
                        $forward_link .= sprintf("<a href='#%s'>%s</a> ", $forward_anchor, $forward_text);
                    }
                }
                /**
                 * make anchor
                 */
                $anchor = "<a id=\"" . safe_string($temp_row["name"], TRUE) . "-" . format_date($temp_row["date"], "%ye%%month%%day%%hour24%%minute%") . "\"></a>";
                /**
                 * substite all of the parameters into the comment, and add it to the output.
                 */
                $this_tag = $format;
                $this_tag = str_replace("%quote%", $quote, $this_tag);
                $this_tag = str_replace("%quoted-back%", $backward_link, $this_tag);
                $this_tag = str_replace("%quoted-forward%", $forward_link, $this_tag);
                $this_tag = str_replace("%count%", $count + 1, $this_tag);
                $this_tag = str_replace("%code%", $db->entry['code'], $this_tag);
                $this_tag = str_replace("%even-odd%", $count % 2 ? 'even' : 'odd', $this_tag);
                $this_tag = str_replace("%ip%", $temp_row["ip"], $this_tag);
                $this_tag = str_replace("%date%", format_date($temp_row["date"], $entrydate), $this_tag);
                $this_tag = str_replace("%comment%", comment_format($temp_row["comment"]), $this_tag);
                $this_tag = str_replace("%name%", $name, $this_tag);
                $this_tag = str_replace("%email%", $email_format, $this_tag);
                $this_tag = str_replace("%url%", $url_format, $this_tag);
                $this_tag = str_replace("%anchor%", $anchor, $this_tag);
                $this_tag = str_replace("%url-to-name%", $urltoname, $this_tag);
                $this_tag = str_replace("%email-to-name%", $emailtoname, $this_tag);
                $this_tag = str_replace("%gravatar%", $grav_url, $this_tag);
                $this_tag = str_replace("%editlink%", $editlink, $this_tag);
                if ($count == $last_count) {
                    $this_tag = '<a id="lastcomment"></a>' . $this_tag;
                }
                $last_comment = $temp_row["ip"] . $temp_row["comment"];
                // Outputting according to order:
                if ($order == 'ascending') {
                    $output .= $this_tag . "\n";
                } elseif ($order == 'descending') {
                    $output = $this_tag . "\n" . $output;
                }
            }
        }
    }
    // If there are comments waiting for moderation, append a note saying so.
    if ($awaiting_moderation) {
        $output .= sprintf("<p id='moderate_queue_waiting'>%s</p>", lang("comment", "moderate_waiting"));
    }
    return '<a id="comm"></a>' . "\n" . $output;
}
예제 #2
0
function snippet_email_to_nick()
{
    global $db, $Users;
    if ($db->entry['code'] == 'ROOT') {
        $output = '<cms emailtonick></cms>';
    } else {
        if (isset($Users[$db->entry['user']])) {
            $output = encodemail_link($Users[$db->entry['user']]['email'], $db->entry['user']);
        } else {
            $output = $db->entry['user'];
        }
    }
    return $output;
}