Ejemplo n.º 1
0
 /**
  * Static function wrapping RSSParser to handle rendering of RSS elements
  * @param $input String: text inside the tags.
  * @param $args Array: value associative list of the element attributes and
  * 						their values.
  * @param $parser Parser
  * @param $frame PPFrame parser context
  */
 static function renderRss($input, $args, $parser, $frame)
 {
     global $wgRSSCacheAge, $wgRSSCacheCompare, $wgRSSNamespaces, $wgRSSAllowedFeeds;
     if (is_array($wgRSSNamespaces) && count($wgRSSNamespaces)) {
         $ns = $parser->getTitle()->getNamespace();
         $checkNS = array_flip($wgRSSNamespaces);
         if (!isset($checkNS[$ns])) {
             return wfMsg('rss-ns-permission');
         }
     }
     if (count($wgRSSAllowedFeeds) && !in_array($input, $wgRSSAllowedFeeds)) {
         return wfMsg('rss-url-permission');
     }
     if (!Http::isValidURI($input)) {
         return wfMsg('rss-invalid-url', htmlspecialchars($input));
     }
     if ($wgRSSCacheCompare) {
         $timeout = $wgRSSCacheCompare;
     } else {
         $timeout = $wgRSSCacheAge;
     }
     $parser->getOutput()->updateCacheExpiry($timeout);
     $rss = new RSSParser($input, $args);
     $status = $rss->fetch();
     # Check for errors.
     if (!$status->isGood()) {
         return wfMsg('rss-error', htmlspecialchars($input), $status->getWikiText());
     }
     if (!is_object($rss->rss) || !is_array($rss->rss->items)) {
         return wfMsg('rss-empty', htmlspecialchars($input));
     }
     return $rss->renderFeed($parser, $frame);
 }
Ejemplo n.º 2
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     $rss_parser = new RSSParser();
     if (!empty($url)) {
         $rss_parser->parse_url($url, $debug);
     }
     if (!empty($rss_parser->channel['title'])) {
         $feed = $rss_parser->channel['title'];
     }
     if (!empty($rss_parser->channel['link'])) {
         $url = $rss_parser->channel['link'];
     }
     if (!empty($rss_parser->channel['description'])) {
         $description = $rss_parser->channel['description'];
     }
     if (!empty($feed)) {
         if (!empty($url)) {
             $titre = HTML::span(HTML::a(array('href' => $rss_parser->channel['link']), $rss_parser->channel['title']));
         } else {
             $titre = HTML::span($rss_parser->channel['title']);
         }
         $th = HTML::div(array('class' => 'feed'), $titre);
         if (!empty($description)) {
             $th->pushContent(HTML::p(array('class' => 'chandesc'), HTML::raw($description)));
         }
     } else {
         $th = HTML();
     }
     if (!empty($rss_parser->channel['date'])) {
         $th->pushContent(HTML::raw("<!--" . $rss_parser->channel['date'] . "-->"));
     }
     $html = HTML::div(array('class' => 'rss'), $th);
     if ($rss_parser->items) {
         // only maxitem's
         if ($maxitem > 0) {
             $rss_parser->items = array_slice($rss_parser->items, 0, $maxitem);
         }
         foreach ($rss_parser->items as $item) {
             $cell = HTML::div(array('class' => 'rssitem'));
             if ($item['link'] and empty($item['title'])) {
                 $item['title'] = $item['link'];
             }
             $cell_title = HTML::div(array('class' => 'itemname'), HTML::a(array('href' => $item['link']), HTML::raw($item['title'])));
             $cell->pushContent($cell_title);
             if (!empty($item['description'])) {
                 $cell->pushContent(HTML::div(array('class' => 'itemdesc'), HTML::raw($item['description'])));
             }
             $html->pushContent($cell);
         }
     } else {
         $html = HTML::div(array('class' => 'rss'), HTML::em(_("no RSS items")));
     }
     if (!check_php_version(5)) {
         $rss_parser->__destruct();
     }
     return $html;
 }
Ejemplo n.º 3
0
 /**
  * wikiFeed executes the RSSParser for type "wiki"
  *
  * @param int $items number of feeditems to parse from feed (RSSParser)
  * @param string $url url of the feed to parse (RSSParser)
  * @param boolean $includetext ???following??? add table-tag?
  * @return string HTML string used for smarty assign method
  */
 private function wikiFeed($items = null, $url = null, $includetext = null)
 {
     // global
     global $opt;
     // check $items and set defaults
     if (is_null($items) || !is_numeric($items)) {
         $items = 10;
     }
     // check $url and set defaults
     if (is_null($url) || !is_string($url)) {
         $url = 'http://wiki.opencaching.de/index.php/Spezial:Neue_Seiten?feed=rss';
     }
     // check $includetext and set defaults
     if (is_null($includetext) || !is_bool($includetext)) {
         $includetext = false;
     }
     // execute RSSParser
     return RSSParser::parse($items, $url, $includetext);
 }
Ejemplo n.º 4
0
function txRssFeedAccess()
{
    global $DB, $json, $C;
    require_once "{$GLOBALS['BASE_DIR']}/includes/rssparser.class.php";
    $out = array('status' => JSON_FAILURE, 'message' => 'Could not access the RSS feed');
    $http = new Http();
    if ($http->Get($_REQUEST['url'], TRUE, $C['install_url'])) {
        $parser = new RSSParser();
        if (($feed = $parser->Parse($http->body)) !== FALSE) {
            if (count($feed['items']) > 0) {
                $out['status'] = JSON_SUCCESS;
                $item = $feed['items'][0];
                ob_start();
                eval('?>' . file_get_contents('includes/rss-feeds-item.php'));
                $out['html'] .= ob_get_contents();
                ob_end_clean();
            } else {
                $out['message'] = 'No &lt;item&gt; tags could be found in the RSS feed';
            }
        } else {
            $out['message'] = $parser->errstr;
        }
    } else {
        $out['message'] = 'Accessing RSS feed failed: ' . $http->errstr;
    }
    echo $json->encode($out);
}
Ejemplo n.º 5
0
 /**
  * wikiFeed executes the RSSParser for type "wiki"
  *
  * @param int $items number of feeditems to parse from feed (RSSParser)
  * @param string $url url of the feed to parse (RSSParser)
  * @param boolean $includetext ???following??? add table-tag?
  * @param int $timeout maximum seconds to wait for the requested page
  * @return string HTML string used for smarty assign method
  */
 private function wikiFeed($items = null, $url = null, $timeout = null, $includetext = null)
 {
     // global
     global $opt;
     // check $items and set defaults
     if (is_null($items) || !is_numeric($items)) {
         $items = $opt['wikinews']['count'];
     }
     // check $url and set defaults
     if (is_null($url) || !is_string($url)) {
         $url = $opt['wikinews']['url'];
     }
     if (is_null($timeout) || !is_numeric($timeout)) {
         $timeout = $opt['wikinews']['timeout'];
     }
     // check $includetext and set defaults
     if (is_null($includetext) || !is_bool($includetext)) {
         $includetext = false;
     }
     // execute RSSParser
     return RSSParser::parse($items, $url, $timeout, $includetext);
 }
Ejemplo n.º 6
0
        echo "bash=" . PHP_PATH . " param1=" . SCRIPT_PATH . " param2={$guid}\n";
    }
    public function rssItems($items)
    {
        if (empty($items)) {
            return false;
        }
        foreach ($items as $item) {
            $this->rssItem($item['title'], $item['guid'], !$item['visited']);
        }
    }
    public function markAsRead()
    {
        echo "Mark all as read | terminal=false refresh=true ";
        echo "bash=" . PHP_PATH . " param1=" . SCRIPT_PATH . " param2=MARK_ALL_AS_READ\n";
    }
    public function refresh()
    {
        echo "Refresh | refresh=true";
    }
}
$parser = new RSSParser(FEED_URL);
$bb = new BitBar();
$bb->icon($feed_image, $parser->getUnreadCnt());
$bb->divider();
$bb->println($parser->title);
$bb->divider();
$bb->rssItems($parser->items);
$bb->divider();
$bb->markAsRead();
$bb->refresh();
Ejemplo n.º 7
0
function ImportFromRss($feed)
{
    global $DB, $C;
    $settings = unserialize($feed['settings']);
    $category = $DB->Row('SELECT * FROM `tx_categories` WHERE `category_id`=?', array($settings['category']));
    $columns = $DB->GetColumns('tx_gallery_fields');
    $imported = 0;
    $defaults = array('gallery_url' => null, 'description' => null, 'keywords' => null, 'thumbnails' => 0, 'email' => $C['from_email'], 'nickname' => null, 'weight' => $C['gallery_weight'], 'clicks' => 0, 'submit_ip' => GetIpFromUrl($feed['feed_url']), 'gallery_ip' => '', 'sponsor_id' => !empty($feed['sponsor_id']) ? $feed['sponsor_id'] : null, 'type' => $settings['type'], 'format' => $settings['format'], 'status' => $settings['status'], 'previous_status' => null, 'date_scanned' => null, 'date_added' => MYSQL_NOW, 'date_approved' => null, 'date_scheduled' => null, 'date_displayed' => null, 'date_deletion' => null, 'partner' => null, 'administrator' => $_SERVER['REMOTE_USER'], 'admin_comments' => null, 'page_hash' => null, 'has_recip' => 0, 'has_preview' => 0, 'allow_scan' => 1, 'allow_preview' => 1, 'times_selected' => 0, 'used_counter' => 0, 'build_counter' => 0, 'tags' => null, 'categories' => MIXED_CATEGORY . " " . $category['tag'], 'preview_url' => null, 'dimensions' => null);
    require_once "{$GLOBALS['BASE_DIR']}/includes/rssparser.class.php";
    $http = new Http();
    if ($http->Get($feed['feed_url'], TRUE, $C['install_url'])) {
        $parser = new RSSParser();
        if (($rss = $parser->Parse($http->body)) !== FALSE) {
            foreach ($rss['items'] as $item) {
                $gallery = array();
                $gallery['gallery_url'] = html_entity_decode($item[$settings['gallery_url_from']]);
                $gallery['description'] = html_entity_decode($item[$settings['description_from']]);
                if (!empty($settings['date_added_from'])) {
                    if (($timestamp = strtotime($item[$settings['date_added_from']])) !== FALSE) {
                        $gallery['date_added'] = date(DF_DATETIME, $timestamp);
                    }
                }
                if (!empty($settings['preview_from'])) {
                    if (!is_array($item[$settings['preview_from']])) {
                        $item[$settings['preview_from']] = array($item[$settings['preview_from']]);
                    }
                    foreach ($item[$settings['preview_from']] as $item_value) {
                        if (preg_match('~(http://[^>< ]+\\.(jpg|png))~i', $item_value, $matches)) {
                            $gallery['preview_url'] = $matches[1];
                            break;
                        }
                    }
                }
                // Remove HTML tags and trim the description
                $gallery['description'] = trim(strip_tags($gallery['description']));
                // Merge with the defaults
                $gallery = array_merge($defaults, $gallery);
                // Skip over duplicate or empty URLs
                if ($DB->Count('SELECT COUNT(*) FROM `tx_galleries` WHERE `gallery_url`=?', array($gallery['gallery_url'])) || IsEmptyString($gallery['gallery_url'])) {
                    continue;
                }
                $imported++;
                // Has a preview thumbnail
                if (!empty($gallery['preview_url'])) {
                    $gallery['has_preview'] = 1;
                }
                // Add regular fields
                $DB->Update('INSERT INTO `tx_galleries` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $gallery['gallery_url'], $gallery['description'], $gallery['keywords'], $gallery['thumbnails'], $gallery['email'], $gallery['nickname'], $gallery['weight'], $gallery['clicks'], $gallery['submit_ip'], $gallery['gallery_ip'], $gallery['sponsor_id'], $gallery['type'], $gallery['format'], $gallery['status'], $gallery['previous_status'], $gallery['date_scanned'], $gallery['date_added'], $gallery['date_approved'], $gallery['date_scheduled'], $gallery['date_displayed'], $gallery['date_deletion'], $gallery['partner'], $gallery['administrator'], $gallery['admin_comments'], $gallery['page_hash'], $gallery['has_recip'], $gallery['has_preview'], $gallery['allow_scan'], $gallery['allow_preview'], $gallery['times_selected'], $gallery['used_counter'], $gallery['build_counter'], $gallery['tags'], $gallery['categories']));
                $gallery['gallery_id'] = $DB->InsertID();
                // Add user defined fields
                $query_data = CreateUserInsert('tx_gallery_fields', $gallery, $columns);
                $DB->Update('INSERT INTO `tx_gallery_fields` VALUES (' . $query_data['bind_list'] . ')', $query_data['binds']);
                // Has a preview thumbnail
                if (!empty($gallery['preview_url'])) {
                    $DB->Update('INSERT INTO `tx_gallery_previews` VALUES (?,?,?,?)', array(null, $gallery['gallery_id'], $gallery['preview_url'], $gallery['dimensions']));
                }
            }
        }
        $DB->Update('UPDATE `tx_rss_feeds` SET `date_last_import`=? WHERE `feed_id`=?', array(MYSQL_NOW, $feed['feed_id']));
    } else {
        return "Could not access the RSS feed: " . $http->errstr;
    }
    return $imported;
}
Ejemplo n.º 8
0
function GetRSSFeed($url, $cache, $showit)
{
    global $carpconf, $CarpRedirs;
    $carpconf['desctags'] = preg_replace("/(^\\|)|(\\|\$)/", '', preg_replace("/\\|+/", "|", preg_replace("#/?(script|embed|object|applet|iframe)#i", '', $carpconf['descriptiontags'])));
    $carpconf['desctags'] = str_replace('|', '\\b|', $carpconf['desctags']) . '\\b';
    // 3 lines for backwards compatibility
    if ($carpconf['corder'] !== false) {
        $carpconf['cborder'] = $carpconf['corder'];
    }
    if ($carpconf['bc'] !== false) {
        $carpconf['bcb'] = $carpconf['bc'];
    }
    if ($carpconf['ac'] !== false) {
        $carpconf['acb'] = $carpconf['ac'];
    }
    $rss_parser = new RSSParser();
    $rss_parser->showit = $showit;
    $rss_parser->channelborder = explode(',', preg_replace('/[^a-z0-9,]/', '', strtolower($carpconf['cborder'])));
    $rss_parser->channelaorder = explode(',', preg_replace('/[^a-z0-9,]/', '', strtolower($carpconf['caorder'])));
    $rss_parser->SetItemOrder($carpconf['iorder']);
    // the next 2 lines are for backward compatibility and will eventually be removed
    if ($carpconf['ilinktarget'] != '-1') {
        $carpconf['linktarget'] = $carpconf['ilinktarget'];
    } else {
        if ($carpconf['clinktarget'] != '-1') {
            $carpconf['linktarget'] = $carpconf['clinktarget'];
        }
    }
    if (preg_match("/[^0-9]/", $carpconf['linktarget'])) {
        $rss_parser->linktargets[$carpconf['linktarget']] = ' target="' . $carpconf['linktarget'] . '"';
    }
    $rss_parser->filterinfield = array();
    if (strlen($carpconf['filterin'])) {
        $rss_parser->filterin = explode('|', strtolower($carpconf['filterin']));
        for ($i = count($rss_parser->filterin) - 1; $i >= 0; $i--) {
            if (strpos($rss_parser->filterin[$i], ':') !== false) {
                list($rss_parser->filterinfield[$i], $rss_parser->filterin[$i]) = explode(':', $rss_parser->filterin[$i], 2);
            } else {
                $rss_parser->filterinfield[$i] = '';
            }
        }
    } else {
        $rss_parser->filterin = array();
    }
    $rss_parser->filteroutfield = array();
    if (strlen($carpconf['filterout'])) {
        $rss_parser->filterout = explode('|', strtolower($carpconf['filterout']));
        for ($i = count($rss_parser->filterout) - 1; $i >= 0; $i--) {
            if (strpos($rss_parser->filterout[$i], ':') !== false) {
                list($rss_parser->filteroutfield[$i], $rss_parser->filterout[$i]) = explode(':', $rss_parser->filterout[$i], 2);
            } else {
                $rss_parser->filteroutfield[$i] = '';
            }
        }
    } else {
        $rss_parser->filterout = array();
    }
    /*********************************************************
     * Note (2006-10-13, Adam Franco)
     *
     * I have reworked this code so that the data is fetched
     * first and the character encoding checked before the 
     * parser is created. As well, if a non-PHP-Supported 
     * encoding is found, the data will first be converted to
     * UTF-8 using iconv.
     *********************************************************/
    if ($fp = OpenRSSFeed($url)) {
        while ($data = fread($fp, 4096)) {
            // Set up the XML Parser
            if (!isset($xml_parser)) {
                // If an input enconding is specified, use that
                if ($carpconf['encodingin']) {
                    $xml_parser = xml_parser_create(strtoupper($carpconf['encodingin']));
                } else {
                    if (preg_match('/<\\?xml[^>]*encoding=[\'"]([^\'"]+)[\'"][^>]*\\?>/i', $data, $matches)) {
                        $sourceEncoding = strtoupper($matches[1]);
                        // 						print "<pre>".basename(__FILE__)." Line ".__LINE__.":\nEncoding found: ".$sourceEncoding."</pre>";
                        if ($sourceEncoding == 'UTF-8' || $sourceEncoding == 'ISO-8859-1' || $sourceEncoding == 'ASCII') {
                            $xml_parser = xml_parser_create($sourceEncoding);
                            unset($sourceEncoding);
                        } else {
                            $xml_parser = xml_parser_create("UTF-8");
                        }
                    } else {
                        // 						print "<pre>".basename(__FILE__)." Line ".__LINE__.":\nNo encoding found, assuming UTF-8</pre>";
                        $xml_parser = xml_parser_create("UTF-8");
                    }
                }
                if (strlen($carpconf['encodingout'])) {
                    xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, $carpconf['encodingout']);
                }
                xml_set_object($xml_parser, $rss_parser);
                xml_set_element_handler($xml_parser, "startElement", "endElement");
                xml_set_character_data_handler($xml_parser, "characterData");
                $CarpRedirs = array();
                $rss_parser->PrepTagPairs($carpconf['desctags']);
            }
            if (isset($sourceEncoding) && function_exists("iconv")) {
                // 				print "<pre>Converting $sourceEncoding to UTF-8</pre>";
                $data = iconv($sourceEncoding, "UTF-8", $data);
            }
            // Doubly escape any necessary ampersands.
            $data = preg_replace("/&(?!lt|gt|amp|apos|quot|nbsp)(.*\\b)/is", "&amp;\\1\\2", $data);
            if (!xml_parse($xml_parser, $data, feof($fp))) {
                CarpError("XML error: " . xml_error_string(xml_get_error_code($xml_parser)) . " at line " . xml_get_current_line_number($xml_parser));
                fclose($fp);
                xml_parser_free($xml_parser);
                return;
            }
            $data = '';
        }
        fclose($fp);
        if ($showit) {
            if ($carpconf['shownoitems'] && !$rss_parser->itemcount) {
                CarpOutput($carpconf['noitems']);
            } else {
                CarpOutput($rss_parser->top . $carpconf['bitems'] . $rss_parser->body . $carpconf['aitems'] . $rss_parser->bottom . $carpconf['poweredby']);
            }
        }
        if ($cache) {
            if ($cfp = OpenCacheWrite()) {
                if ($carpconf['shownoitems'] && !$rss_parser->itemcount) {
                    fwrite($cfp, $carpconf['noitems']);
                } else {
                    fwrite($cfp, ($showit ? $rss_parser->top . $carpconf['bitems'] : 'cb: :' . $rss_parser->top . "\n" . 'ca: :' . $rss_parser->bottom . "\n") . $rss_parser->body . ($showit ? $carpconf['aitems'] . $rss_parser->bottom . $carpconf['poweredby'] : ''));
                }
                CloseCacheWrite($cfp);
            } else {
                CarpError("Unable to create/open RSS cache file.", 0);
            }
        }
        xml_parser_free($xml_parser);
    } else {
        if ($showit && strlen($carpconf['cachefile']) && file_exists($carpconf['cachefile'])) {
            CarpOutput(file($carpconf['cachefile']));
        } else {
            if ($showit) {
                CarpError('Can\'t open remote newsfeed.', 0);
            }
        }
    }
}