Exemplo n.º 1
0
function start_comment_feed()
{
    global $atom, $atom_items, $build, $Current_user, $Weblogs, $Current_weblog, $Paths, $Users, $Cfg;
    $link = $Paths['host'] . fixPath($Paths['pivot_url'] . $Weblogs[$Current_weblog]['front_path'] . $Weblogs[$Current_weblog]['front_filename']);
    $link_self = $Paths['host'] . $Paths['pivot_url'] . "commentsfeed.php";
    if (!empty($_SERVER['QUERY_STRING'])) {
        $link_self .= "?" . $_SERVER['QUERY_STRING'];
    }
    $atom_preamble = '<?xml version="1.0" encoding="%charset%"?' . '>
<feed xmlns="http://www.w3.org/2005/Atom"
	xml:lang="%lang%">
	<title>%title% - Comments</title>
	<subtitle>%description%</subtitle>
	<link rel="alternate" type="text/html" href="%link%"/>
	<link rel="self" type="application/atom+xml" href="%link_self%"/>
        <updated>%date%</updated>
        <author>
		<name>%admin-nick%</name>
		<uri>%link%</uri>
		<email>%admin-email%</email>
	</author>
	<id>tag:%sitename_safe%,%year%:%title_safe%</id>
	<generator uri="http://www.pivotlog.net" version="%version%">Pivot</generator>
	<rights>Copyright (c) %year%, Authors of %sitename%</rights>
';
    reset($Users);
    $user = each($Users);
    $user = $user['value'];
    $from = array("%title%", "%title_safe%", "%sitename%", "%sitename_safe%", "%link%", "%link_self%", "%description%", "%author%", "%admin-email%", "%admin-nick%", "%year%", "%date%", "%genagent%", "%version%", "%lang%", "%charset%");
    $to = array(str_replace("&", "&amp;", $Weblogs[$Current_weblog]['name']), str_replace("_", "", safe_string($Weblogs[$Current_weblog]['name'], TRUE)), $Cfg['sitename'], strtolower(str_replace("_", "", safe_string($Cfg['sitename'], TRUE))), $link, $link_self, $Weblogs[$Current_weblog]['payoff'], $Current_user, $user['email'], $user['nick'], date("Y"), date("Y-m-d\\TH:i:s") . rss_offset(), "http://www.pivotlog.net/?ver=" . urlencode($build), $build, snippet_lang(), snippet_charset());
    $atom = str_replace($from, $to, $atom_preamble);
    $atom_items = array();
}
Exemplo n.º 2
0
/**
 * Generates the head for the XML feeds.
 *
 * @uses feedtemplate loads the head template for XML feeds.
 */
function start_rss()
{
    global $rss, $rss_items, $atom, $atom_items, $items_added, $db, $build, $Current_user, $Weblogs, $Current_weblog, $Paths, $Users, $Cfg;
    $rss_preamble = feedtemplate('feed_rss_template.xml', 'head');
    $atom_preamble = feedtemplate('feed_atom_template.xml', 'head');
    if (strlen($Weblogs[$Current_weblog]['rss_link']) > 2) {
        $link = trim($Weblogs[$Current_weblog]['rss_link']);
    } else {
        if (gethost() != $Paths['host']) {
            // use the override value from weblog config..
            $link = gethost();
        } else {
            // determine the value ourselves..
            $link = gethost() . fixPath($Paths['pivot_url'] . $Weblogs[$Current_weblog]['front_path'] . $Weblogs[$Current_weblog]['front_filename']);
        }
    }
    $link_self = gethost() . fixPath($Paths['pivot_url'] . $Weblogs[$Current_weblog]['rss_path'] . $Weblogs[$Current_weblog]['atom_filename']);
    if (strlen($Weblogs[$Current_weblog]['rss_img']) > 2) {
        $image = trim($Weblogs[$Current_weblog]['rss_img']);
    } else {
        // if no image is set, we will also have to remove the <image> .. </image>
        // part from the feed.. Bit hackish, but it works.
        $image = "";
        $rss_preamble = preg_replace("/<image>(.*)<\\/image>/msi", "", $rss_preamble);
    }
    $charset = snippet_charset();
    $lang = str_replace("_utf8", "", snippet_lang());
    reset($Users);
    $user = each($Users);
    $user = $user['value'];
    $from = array("%sitename%", "%title%", "%sitename_safe%", "%title_safe%", "%link%", "%link_self%", "%description%", "%author%", "%admin-email%", "%admin-nick%", "%year%", "%date%", "%date_rfc%", "%genagent%", "%version%", "%lang%", "%charset%", "%image%");
    $to = array($Cfg['sitename'], str_replace("&", "&amp;", $Weblogs[$Current_weblog]['name']), strtolower(str_replace("_", "", safe_string($Cfg['sitename'], TRUE))), str_replace("_", "", safe_string($Weblogs[$Current_weblog]['name'], TRUE)), $link, $link_self, $Weblogs[$Current_weblog]['payoff'], $Current_user, $user['email'], $user['nick'], date("Y"), date("Y-m-d\\TH:i:s") . rss_offset(), get_rfcdate(mktime()), "http://www.pivotlog.net/?ver=" . urlencode($build), $build, $lang, $charset, $image);
    $rss = str_replace($from, $to, $rss_preamble);
    $atom = str_replace($from, $to, $atom_preamble);
    $items_added = array();
    $rss_items = array();
    $atom_items = array();
}
Exemplo n.º 3
0
}
// -----------------------
// Main
// -----------------------
$rssformat = stripslashes($rssformat);
define('MAGPIE_DIR', dirname(__FILE__) . '/magpierss/');
define('MAGPIE_CACHE_DIR', $pivot_path . './db/rsscache/');
define('MAGPIE_FETCH_TIME_OUT', 5);
// 5 second timeout
if (isset($rss_cache_age) && is_int($rss_cache_age)) {
    define('MAGPIE_CACHE_AGE', $rss_cache_age);
} else {
    define('MAGPIE_CACHE_AGE', 60 * 60 * 8);
    // 8 hours
}
define('MAGPIE_OUTPUT_ENCODING', snippet_charset());
if (!isset($trimlen) || $trimlen == 0) {
    $trimlen = 60;
}
require_once 'magpierss/rss_fetch.inc';
$feed = fetch_rss($rssurl);
$count = 1;
foreach ($feed->items as $item) {
    $itemformat = $rssformat;
    // Supporting upto two level arrays in item elements.
    foreach ($item as $key => $value) {
        if (is_string($value)) {
            if ($key == "link") {
                $value = trim($value);
            } else {
                $value = trimtext(trim($value), $trimlen);
Exemplo n.º 4
0
function encodeEntities($text)
{
    /*  Convert high and low ascii to entities. If multibyte string functions are
        available (on by default in php 4.3+), we convert using unicode mapping as 
        defined in the function encode_high(). If not, we use php's nasty
        built-in htmlentities() */
    return function_exists('mb_encode_numericentity') ? encode_high($text) : htmlentities($text, ENT_NOQUOTES, snippet_charset());
}
Exemplo n.º 5
0
/**
 * Trim a text to a given length, taking html entities into account.
 *
 * Formerly we first removed entities (using unentify), cut the text at the
 * wanted length and then added the entities again (using entify). This caused
 * lot of problems so now we are using a trick from
 * http://www.greywyvern.com/code/php/htmlwrap.phps
 * where entities are replaced by the ACK (006) ASCII symbol, the text cut and
 * then the entities reinserted.
 *
 * @param string $str string to trim
 * @param int $length position where to trim
 * @param boolean $nbsp whether to replace spaces by &nbsp; entities
 * @param boolean $hellip whether to add &hellip; entity at the end
 *
 * @return string trimmed string
 */
function trimtext($str, $length, $nbsp = false, $hellip = true)
{
    $str = strip_tags($str);
    // Use the ACK (006) ASCII symbol to replace all HTML entities temporarily
    $str = str_replace("", "", $str);
    preg_match_all("/&([a-z\\d]{2,7}|#\\d{2,5});/i", $str, $ents);
    $str = preg_replace("/&([a-z\\d]{2,7}|#\\d{2,5});/i", "", $str);
    if (function_exists('mb_strwidth')) {
        if (mb_strwidth($str) > $length) {
            $my_encoding = snippet_charset();
            if ($my_encoding != "") {
                $str = mb_strimwidth($str, 0, $length + 1, '', $my_encoding);
            } else {
                $str = mb_strimwidth($str, 0, $length + 1);
            }
            if ($hellip) {
                $str .= '&hellip;';
            }
        }
    } else {
        if (strlen($str) > $length) {
            $str = substr($str, 0, $length + 1);
            if ($hellip) {
                $str .= '&hellip;';
            }
        }
    }
    if ($nbsp == true) {
        $str = str_replace(" ", "&nbsp;", $str);
    }
    $str = str_replace("http://", "", $str);
    // Put captured HTML entities back into the string
    foreach ($ents[0] as $ent) {
        $str = preg_replace("//", $ent, $str, 1);
    }
    return $str;
}