Exemplo n.º 1
0
function spiel_view_page($topic)
{
    //	$result = new MagpieRSS(file_get_contents("$_SERVER[FILE_ROOT]/spiels/$topic.rss"));
    $url = "http://planwatch.org/spiels/{$topic}.rss";
    include_once 'plan_read.php';
    $content = plan_read_simplepie_rss($url);
    /*
    	$channel_info=$result->channel;
    	$content.= "<h1>$channel_info[title]</h1>\n";
    	$content.= "<a href='$_SERVER[WEB_ROOT]/write/?autocontent=!spiel:$channel_info[title]:TITLE%20OF%20YOUR%20ENTRY!'>join the conversation</a><br />\n";
    	$content.= "<a href='$_SERVER[WEB_ROOT]/lists/add/spiels/$topic'>watch</a><br /><br />\n";
    	foreach($result->items as $item)
    	{
    		if ($item['items_title'])
    		$content.= "
    		 <h3><a href='$item[link]'>
    		  $item[items_title]
    		 </a></h3>\n";
    		$dc=$item['dc'];
    		if ($dc['items_date']) $timecodes="posted ".formattime(parse_w3cdtf($dc['items_date']));
    		$content.= "<span class='edit_links'>$dc[items_subject] | $dc[items_creator] | $timecodes</span><br />\n";
    		if ($item['items_description']) $content.= "$item[items_description]<br />";
    		
    		$content.= "<br />\n\n";
    	}
    */
    return $content;
}
Exemplo n.º 2
0
function plan_read_simplepie_rss($urls, $offset = 0, $item_count = 30)
{
    if (IS_JOSH) {
        include_once 'simplepie.1.2.inc';
    } else {
        include_once 'simplepie.inc';
    }
    profile('rss_read');
    $lastview = plan_get_last_view($urls);
    $multifeed = TRUE;
    if (is_string($urls)) {
        if (substr_count($urls, ",http") > 0) {
            $urls = explode(",http", $urls);
            foreach ($urls as $i => $url) {
                if (!strstr($url, 'http')) {
                    $urls[$i] = "http" . $url;
                }
            }
        } else {
            $urls = array($urls);
            $multifeed = FALSE;
        }
    }
    preg_match("|\\/\\/(.*)@|", $urls[0], $match);
    if ($match[1]) {
        $_SERVER['DIGEST_USERINFO'] = $match[1];
        $_SERVER['DIGEST_AUTH'] = TRUE;
    }
    profile("load feeds");
    $feed = new SimplePie($urls);
    profile("load feeds");
    $items = $feed->get_items();
    usort($items, "plan_multifeed_sort_items");
    $items = array_slice($items, $offset, $item_count);
    if (!is_object($items[0])) {
        //		if(IS_JOSH) print_r($items);
        // do stuff to fix the url and try again
        preg_match("|.*://([^/]+)/|", $urls[0], $base_url_array);
        $base_link = "<a href='{$base_url_array['0']}'>{$base_url_array['1']}</a>";
        if ($offset != "RECURSION") {
            $content = plan_read_simplepie_rss($base_url_array[0], "RECURSION");
        }
        if (!$content) {
            $title = "Failed to read feed {$urls['0']}";
            $content = "<h1>Plan Read Failed</h1> We tried <tt>{$urls['0']}</tt> and did not get a valid feed.<br />\n\t\t\tYou may want to try the site directly: {$base_link}<br />\n\t\t\tIf the feed address is incorrect, you can <a href='/lists/edit/watched'>edit your watched list</a> to correct it.<br /><br />\n\t\t\tStill have questions? Ask for <a href='mailto:help@planwatch.org'>help</a>.";
            $alternate_links = array_unique(array_merge(plan_feed_search(str_replace("http://", "http://www.", $base_url_array[0])), plan_feed_search($base_url_array[0]), plan_feed_search($urls[0])));
            if ($alternate_links) {
                $content .= "<hr /><h2>Alternate Links</h2>Here are some possible alternate feed links:<ul>";
                foreach ($alternate_links as $link) {
                    $content .= "<li><a href='http://planwatch.org/read/{$link}'>{$link}</a></li>\n";
                }
            }
        }
    } else {
        foreach ($items as $item) {
            unset($item_categories);
            $item_authors_string = '';
            $entry_header = '';
            $item_title = $item->get_title();
            $item_link = $item->get_permalink();
            $item_date = formattime($item->get_date('U'));
            $item_data = $item->get_content();
            if ($item_category_list = $item->get_categories()) {
                foreach ($item_category_list as $category) {
                    $item_categories .= " " . $category->get_label();
                }
            }
            $item_authors = $item->get_authors();
            $item_id = $item->get_id();
            if ($item_authors) {
                foreach ($item_authors as $item_author) {
                    if ($item_author->get_name()) {
                        $item_authors_string .= "<a href='" . $item_author->get_link() . "'>" . $item_author->get_name() . "</a> ";
                    } elseif ($item_author->get_email()) {
                        $item_authors_string .= $item_author->get_email() . " ";
                    }
                }
            }
            if ($item_title) {
                $feed = $item->get_feed();
                $feed_title = $feed->get_title();
                $feed_link = $feed->get_link();
                $feed_url = $feed->feed_url;
                if ($multifeed) {
                    $entry_header = "<a target='_self' href='/read/{$feed_url}'>{$feed_title}</a><br/><a target='_self' href='{$item_link}' class='entry_title'>{$item_title}</a>\n";
                } else {
                    $entry_header .= "<a target='_self' href='{$item_link}' class='entry_title'>{$item_title}</a>\n";
                }
            }
            $entry_header .= "<span class='edit_links'>";
            if ($item_categories) {
                $entry_header .= " {$item_categories}, ";
            }
            if ($item_date) {
                $entry_header .= " posted {$item_date} ";
            }
            if ($item_authors_string) {
                $entry_header .= "by {$item_authors_string} ";
            }
            $item_id_hash = md5($item_id);
            $entry_header .= "</span><br />\n";
            //$entry_text=removeEvilTags($item_data);
            $entry_text = $item_data;
            $content .= "\n\t\t\t<div class='plan_entry' id='plan_entry_{$item_id_hash}'>\n\t\t\t{$entry_header}\n\t\t\t<div class='entry_content' id='entry_content_{$item_id_hash}'>";
            $content .= str_replace("<a ", "<a target='_self' ", $entry_text);
            $content .= "\n\t\t\t</div>\n\t\t\t</div>\n\t\t\t";
        }
    }
    if (!$multifeed && is_object($item)) {
        $feed = $item->get_feed();
        $feed_title = $feed->get_title();
        $feed_link = $feed->get_link();
        $feed_description = $feed->get_description();
        $content = "<h1><a href='{$feed_link}'>{$feed_title}</a></h1>{$feed_description}<br /><br />{$content}";
        //		if($urls[0]!=$feed_link) $content="<div class='message'><b>This feed is autodiscovered</b> based on the link you provided. It may keep working, but discovery is unpredictable. If you want to ".$content;
    }
    profile('rss_read');
    return $content;
}