The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 22, 2019, 07:31:31 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: need help with magpie rss  (Read 1791 times)
jaobedoza
Rookie
**
Offline Offline

Posts: 11


View Profile
« on: October 24, 2009, 09:33:22 AM »

i'm trying to make something like this addictomatic.com using magpie, when you type a keyword a new page is created with nothing but scraped rss feeds about the keyword.


my first approach was using the classic mygen script with a magpie hook i found somewhere. but the problem with this is i have to put the keywords in  a text file, and the magpie hook puts all the feeds in an array so there's only one output.

what i like is type the keyword to the search box and new page created with the feeds shown from different sources.


here's the magpie hook

Code:

<? // Magpie Blog Hook

//To use
// Magpie_Blog(THIS_PAGE, 5) for index page
// Magpie_Blog($page_keyword, 5) for results page
// change the number 5 to the desired number of entries

function Magpie_Blog($keyword, $num)
{

switch($keyword) :
case 'index':
$keywords = @file(FILE_KEYWORDS);
$keyword = trim($keywords[0]);
break;
case 'sitemap':
$keywords = @file(FILE_KEYWORDS);
$keyword = trim($keywords[0]);
break;
endswitch;

if($num==null) $num = 100;

define('MAX_ITEMS', $num);
require_once('./rss_fetch.inc');

$urls = array
    (
    'http://news.google.com/news?hl=en&ned=us&q='.urlencode($keyword).'&ie=UTF-8&output=rss',
    'http://blogsearch.google.com/blogsearch_feeds?hl=en&q='.urlencode($keyword).'&ie=utf-8&num=10&output=rss',
    'http://feeds.technorati.com/feed/posts/tag/'.urlencode($keyword).'',
    'http://www.sphere.com/rss?q='.urlencode($keyword).'&datedrop=1&lang=en&x=0&y=0',
    'http://video.google.com/videosearch?q='.urlencode($keyword).'&sitesearch=&output=rss',
    'http://del.icio.us/rss/tag/'.urlencode($keyword).''   
    );

$items = array();

// loop thru all urls & merge feeds into master array
foreach ( $urls as $url ) {
    $rss = fetch_rss($url);
    if (!$rss) continue;
    $items = array_merge($items, $rss->items);
}

// sorts feed array based on published date (used with usort)
// -------------------------------------------------------------
    function date_cmp($a, $b)
    {
        $atime = (empty($a['date_timestamp']))
            ? strtotime($a['dc']['date'])
            : $a['date_timestamp'];

        $btime = (empty($b['date_timestamp']))
            ? strtotime($b['dc']['date'])
            : $b['date_timestamp'];

        if ($atime == $btime)
            return 0;
   
        return ($atime > $btime) ? -1 : 1;
    }


// sort all items in array by date
usort($items, 'date_cmp');

// generate ouput array
$out = array();

foreach ($items as $item) {
    $href    = $item['link'];
    $title    = $item['title'];
    $out[] = '<div class="post"><h2><a href="'.$item['link'].'">'.ucwords($item['title']).'</a></h2><div

class="entry"><p>'.$item['description'].'</p></div></div>';
}

if (count($out) > MAX_ITEMS)
    $out = array_slice($out,0,MAX_ITEMS);

echo ($out)
    ? "\n".join("\n",$out)."\n"
    : '';

   

}
?>





thanks,
jay
Logged

No links in signatures please
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!