Ejemplo n.º 1
0
function mosLoadCustomModule(&$module, &$params)
{
    global $mosConfig_absolute_path, $mosConfig_cachepath;
    $rssurl = $params->get('rssurl', '');
    $rssitems = $params->get('rssitems', '');
    $rssdesc = $params->get('rssdesc', '');
    $moduleclass_sfx = $params->get('moduleclass_sfx', '');
    $rsscache = $params->get('rsscache', 3600);
    $cachePath = $mosConfig_cachepath . '/';
    echo '<table cellpadding="0" cellspacing="0" class="moduletable' . $moduleclass_sfx . '">';
    if ($module->content) {
        echo '<tr>';
        echo '<td>' . $module->content . '</td>';
        echo '</tr>';
    }
    // feed output
    if ($rssurl) {
        if (!is_writable($cachePath)) {
            echo '<tr>';
            echo '<td>Please make cache directory writable.</td>';
            echo '</tr>';
        } else {
            $LitePath = $mosConfig_absolute_path . '/includes/Cache/Lite.php';
            require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_rss_lite.php';
            $rssDoc = new xml_domit_rss_document_lite();
            $rssDoc->setRSSTimeout(5);
            $rssDoc->useHTTPClient(true);
            $rssDoc->useCacheLite(true, $LitePath, $cachePath, $rsscache);
            $success = $rssDoc->loadRSS($rssurl);
            if ($success) {
                $totalChannels = $rssDoc->getChannelCount();
                for ($i = 0; $i < $totalChannels; $i++) {
                    $currChannel =& $rssDoc->getChannel($i);
                    $feed_title = $currChannel->getTitle();
                    $feed_title = mosCommonHTML::newsfeedEncoding($rssDoc, $feed_title);
                    echo '<tr>';
                    echo '<td><strong><a href="' . $currChannel->getLink() . '" target="_child">';
                    echo $feed_title . '</a></strong></td>';
                    echo '</tr>';
                    if ($rssdesc) {
                        $feed_descrip = $currChannel->getDescription();
                        $feed_descrip = mosCommonHTML::newsfeedEncoding($rssDoc, $feed_descrip);
                        echo '<tr>';
                        echo '<td>' . $feed_descrip . '</td>';
                        echo '</tr>';
                    }
                    $actualItems = $currChannel->getItemCount();
                    $setItems = $rssitems;
                    if ($setItems > $actualItems) {
                        $totalItems = $actualItems;
                    } else {
                        $totalItems = $setItems;
                    }
                    for ($j = 0; $j < $totalItems; $j++) {
                        $currItem =& $currChannel->getItem($j);
                        $item_title = $currItem->getTitle();
                        $item_title = mosCommonHTML::newsfeedEncoding($rssDoc, $item_title);
                        $text = $currItem->getDescription();
                        $text = mosCommonHTML::newsfeedEncoding($rssDoc, $text);
                        echo '<tr>';
                        echo '<td><strong><a href="' . $currItem->getLink() . '" target="_child">';
                        echo $item_title . '</a></strong> - ' . $text . '</td>';
                        echo '</tr>';
                    }
                }
            }
        }
    }
    echo '</table>';
}
 /**
  * Function to import post from a given import url
  * @param $import_url : Feed url from where posts will be imported
  * @param $max_posts : Max number of posts to be imported from the feed.
  * @param array of posts.
  */
 public function import_feed()
 {
     Logger::log("Enter: ExternalFeed::import_feed");
     //initializing the object of the Domit Rss feed parser.
     $domit_obj = new xml_domit_rss_document_lite($this->import_url);
     $channel_count = $domit_obj->getChannelCount();
     $feed_data = array();
     if ($channel_count) {
         $post_count = 0;
         for ($counter = 0; $counter < $channel_count; $counter++) {
             $channel =& $domit_obj->getChannel($counter);
             $item_count = $channel->getItemCount($channel);
             for ($item = 0; $item < $item_count; $item++) {
                 $item_obj =& $channel->getItem($item);
                 $feed_data[$item]['title'] = $item_obj->getTitle($item);
                 $feed_data[$item]['description'] = $item_obj->getDescription($item);
                 $feed_data[$item]['original_url'] = $item_obj->getLink($item);
                 $feed_data[$item]['publish_date'] = @strtotime($item_obj->getPubDate($item));
                 if (++$post_count == $this->max_posts) {
                     // if posts = max_posts allowed, futher import will be halted.
                     return $feed_data;
                 }
             }
         }
     } else {
         Logger::log("Exit: ExternalFeed::import_feed No posts are found for Import Url = {$this->import_url}");
         throw new CNException(IMPORT_FAILED, 'No posts are being imported. Given import url is incorrect or feed has yielded zero posts.');
         return $feed_data;
     }
     Logger::log("Exit: ExternalFeed::import_feed");
     return $feed_data;
 }
Ejemplo n.º 3
0
//$url = 'http://rss.topix.net/rss/who/hair-of-the-dog.xml';
//$url = 'http://www.betaland.net/joke/index.rdf';
//$url = 'http://rss.topix.net/rss/music/acoustic.xml';
//$url = 'http://baseballcrank.com/index.rdf';
//********RSS 2.0***********
//$url = 'http://www.solport.com/roundtable/index.xml';
//$url = 'http://sport.scotsman.com/tennis.cfm?format=rss';
//$url = 'http://radio.weblogs.com/0106123/categories/python/rss.xml';
//$url = 'http://www.peer-solutions.com/weblog/SyndicationService.asmx/GetRss?';
//$url = 'http://radio.weblogs.com/0105058/rss.xml';
//$url = 'http://mosforge.net/export/rss_sfnews.php';
//*******************CODE*************************
//instantiate rss document
$cacheDir = './';
$cacheTime = 3600;
$rssdoc = new xml_domit_rss_document_lite($url, $cacheDir, $cacheTime);
//get total number of channels
$totalChannels = $rssdoc->getChannelCount();
//loop through each channel
for ($i = 0; $i < $totalChannels; $i++) {
    //get reference to current channel
    $currChannel = $rssdoc->getChannel($i);
    //echo channel info
    echo "<h2><a href=\"" . $currChannel->getLink() . "\" target=\"_child\">" . $currChannel->getTitle() . "</a>";
    echo "  " . $currChannel->getDescription() . "</h2>\n\n";
    //get total number of items
    $totalItems = $currChannel->getItemCount();
    //loop through each item
    for ($j = 0; $j < $totalItems; $j++) {
        //get reference to current item
        $currItem = $currChannel->getItem($j);