Пример #1
0
/**
 * Adds an item to the XML feeds for the given entry ID.
 *
 * The function uses the global array $items_added to avoid
 * adding the same entry twice.
 *
 * @uses feedtemplate loads the item template for XML feeds.
 *
 * @param int $uid
 * @param string $orgdate
 * @param string $title
 * @param string $introduction
 * @param string $body
 * @param string $user
 * @param string $category
 */
function add_rss($uid, $orgdate, $title, $introduction, $body, $user, $category)
{
    global $db, $rss_items, $atom_items, $items_added, $Cfg, $Weblogs, $Current_weblog, $Allow_RSS, $Paths, $Users;
    if (!$Allow_RSS) {
        return;
    }
    // Checking if the item is already added to avoid duplication
    if (in_array($uid, $items_added)) {
        return;
    } else {
        $items_added[] = $uid;
    }
    $link = make_fileurl($uid, "", "");
    if (!siteurl_isset()) {
        $weblog = gethost() . $Paths['pivot_url'];
        // we strip off the 'www.' part. It may not always result in a valid URL, but the
        // guid isn't supposed to be one anyhow. This prevents problems in readers, when
        // the feed is sometimes generated from www.example.org, and sometimes from example.org.
        $weblog = str_replace("www.", "", $weblog);
    } else {
        $weblog = $Weblogs[$Current_weblog]['siteurl'];
    }
    $title = trim(unentify($db->entry['title']));
    $subtitle = trim(unentify($db->entry['subtitle']));
    // parse fields and remove scripting from the feed. Script in feed is bad..
    $introduction = parse_intro_or_body($db->entry['introduction']);
    $introduction = clean_rss_text($introduction);
    $body = parse_intro_or_body($db->entry['body']);
    $body = clean_rss_text($body);
    $tag = str_replace("_", "", strtolower(safe_string($Cfg['sitename'], TRUE))) . "," . date("Y") . ":" . str_replace("_", "", safe_string($Weblogs[$Current_weblog]['name'], TRUE)) . "." . $uid;
    $lang = str_replace("_utf8", "", snippet_lang());
    $date = format_date($orgdate, "%year%-%month%-%day%T%hour24%:%minute%:00") . rss_offset();
    $date_rfc = format_date($orgdate, "%english_dname%, %day% %english_monname% %year% %hour24%:%minute%:00 ") . rss_offset("rfc822");
    if ($db->entry['edit_date'] != "") {
        $edit_date = format_date($db->entry['edit_date'], "%year%-%month%-%day%T%hour24%:%minute%:00") . rss_offset();
    } else {
        // if the entry was never edited, use the entrydate
        $edit_date = $date;
    }
    $summary = unentify(strip_tags($introduction));
    $summary = trim(str_replace("&", "&", str_replace(" ", " ", $summary)));
    // Set content (Atom 1.0) and description (RSS 2.0) according to completeness settings
    if (isset($Weblogs[$Current_weblog]['rss_full']) && $Weblogs[$Current_weblog]['rss_full'] == 0) {
        // don't put anything in the content.
        $content = "";
        $description = trim($introduction);
        if (strlen($body) > 5) {
            $description .= snippet_more();
            $summary .= ' ...';
        }
    } else {
        // put the introduction and body in the content..
        $content = trim(str_replace(" ", " ", $introduction . $body));
        $description = trim($introduction . $body);
    }
    $rss_item = feedtemplate('feed_rss_template.xml', 'item');
    $atom_item = feedtemplate('feed_atom_template.xml', 'item');
    // Handling viatitle special to avoid validation errors
    if (!empty($db->entry['viatitle'])) {
        $viatitle = 'title="' . $db->entry['viatitle'] . '"';
    } else {
        $viatitle = "";
    }
    $from = array("%title%", "%subtitle%", "%link%", "%description%", "%summary%", "%author%", "%author-email%", "%author-nick%", "%guid%", "%date%", "%edit_date%", "%date_rfc%", "%category%", "%content%", "%tag%", "%lang%", "%vialink%", "%viatitle%");
    $to = array(htmlspecialchars(strip_tags($title)), htmlspecialchars(strip_tags($subtitle)), $link, RelativeToAbsoluteURLS($description), RelativeToAbsoluteURLS($summary), $user, $Users[$user]['email'], $Users[$user]['nick'], $uid . "@" . $weblog, $date, $edit_date, $date_rfc, htmlspecialchars(implode(", ", $category)), RelativeToAbsoluteURLS($content), $tag, $lang, $db->entry['vialink'], $viatitle);
    $rss_item = str_replace($from, $to, $rss_item);
    $atom_item = str_replace($from, $to, $atom_item);
    // We add the count($rss_items), because otherwise we can't have two items
    // that are posted at the same minute.
    $rss_items[$orgdate . "." . count($rss_items)] = $rss_item;
    $atom_items[$orgdate . "." . count($rss_items)] = $atom_item;
}
Пример #2
0
function add_comment_feeditem($item)
{
    global $db, $rss_items, $atom_items, $Cfg, $Weblogs, $Current_weblog, $Allow_RSS, $Paths;
    if (!siteurl_isset()) {
        $weblog = $Paths['host'] . $Paths['pivot_url'];
    } else {
        $weblog = $Weblogs[$Current_weblog]['siteurl'];
    }
    $entry = $db->read_entry($item['code']);
    $link = make_fileurl($item['uid'], "", "");
    $title = $db->entry['title'];
    $date = format_date($item['date'], "%year%-%month%-%day%T%hour24%:%minute%:00") . rss_offset();
    $description = htmlspecialchars(strip_tags($item['comment']));
    $description = str_replace(" ", " ", $description);
    $id = safe_string($item["name"], TRUE) . "-" . format_date($item["date"], "%ye%%month%%day%%hour24%%minute%");
    $tag = str_replace("_", "", strtolower(safe_string($Cfg['sitename'], TRUE))) . "," . date("Y") . ":" . $id;
    // make sure description is not too long..
    if (isset($Weblogs[$Current_weblog]['rss_full']) && $Weblogs[$Current_weblog]['rss_full'] == 0) {
        // don't put anything in the content.
        $content = "";
    } else {
        // put the introduction and body in the content..
        $content = str_replace(" ", " ", $introduction . $body);
    }
    if (isemail($item['email'])) {
        $email = "\n<email>" . $item['email'] . "</email>";
    } else {
        $email = "";
    }
    if (isurl($item['url'])) {
        if (strpos($item["url"], "ttp://") < 1) {
            $item["url"] = "http://" . $item["url"];
        }
        $url = "\n<uri>" . $item['url'] . "</uri>";
    } else {
        $url = "";
    }
    $atom_item = '
	<entry>
	    <title>%author% on %title%</title>
	    <link rel="alternate" type="text/html" href="%link%#%id%"/>
	    <updated>%date%</updated>
	    <published>%date%</published>
	    <id>tag:%tag%</id>
	    <summary type="text">%description%</summary>
	    <content type="html" xml:lang="%lang%" xml:base="%link%">
		<![CDATA[ 
			%content%
		]]>
	    </content>
	    <author>
		<name>%author%</name>%url%%email%
	    </author>
	</entry>
';
    $from = array("%title%", "%link%", "%id%", "%description%", "%content%", "%author%", "%guid%", "%date%", "%tag%", "%lang%", "%url%", "%email%");
    $to = array(htmlspecialchars(strip_tags($entry['title'])), $link, $id, RelativeToAbsoluteURLS($description), trim(comment_format($item['comment'])), htmlspecialchars(unentify($item['name'])), $item['uid'] . "@" . $weblog, $date, $tag, snippet_lang(), $url, $email);
    $atom_item = str_replace($from, $to, $atom_item);
    $atom_items[$date] = $atom_item;
}