TinyPortal

Development => Block Codes => Topic started by: necrit on May 30, 2007, 10:10:36 PM

Title: tinyRSS w/ cURL method
Post by: necrit on May 30, 2007, 10:10:36 PM
Couple of issues arose when i tried to implement the various RSS scripts from thsi site.  I was unable to figure it out until i started digging through the code and my host forums.  My host has banned fopen for remote files.  the solution was to use curl.  here are the functions that you put in a file called tinyRSS.php and stash it either in root or a sub folder.  Also to keep problems down create a temp folder at the root of the server.  Then CHMOD it to 744


<?php
/*
======================================================================
tinyRSS v.0.1

Integrated parsing and caching of RSS files in Tiny Portal.
Inspired by lastRSS and Tinyportal RSS

Credit to
 Vojtech Semecky at http://lastrss.oslab.net/
 The ENTIRE Amazing TP TEAM at http://www.tinyportal.co.uk
======================================================================
*/



function getFile($url,$timeout=0) {
# use CURL library to fetch remote file
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
if ( curl_getinfo($ch,CURLINFO_HTTP_CODE) !== 200 ) {
return('Bad Data File '.$url);
} else {
return $file_contents;
}
}

function
tinyRSS($rss_url)
{
// All around variables used by TP?!?
global $context, $settings, $options, $scripturl, $txt, $modSettings;

// Function Variables specific to TP?
$insideitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";
$curl = "";

// absolute path to the cache dir.  leave blank to disable caching
$cache_dir = "temp";
// timeout of the cached rss files in the cache directory
$cache_time = 1200;


// Lets try and mix these scripts
if ($cache_dir != '') {
$cache_file = $cache_dir . '/rsscache_' . md5($rss_url);
$timedif = @(time() - filemtime($cache_file));

if ($timedif > $cache_time) {
// cached file is too old, create new
$result = getFile($rss_url,$timeout=0);
if ($f = @fopen($cache_file, 'w')) {
fwrite ($f, $result, strlen($result));
fclose($f);
}
}

// Open the actual datafile:
$fp = fopen($cache_file, "r");

}
// If CACHE DISABLED >> load and parse the file directly
else {

$fp = getURL($rss_url,$timeout=0);

}




// Now to the parsing itself. Starts by creating it:

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");



// Run through it line by line and parse:
while ($data = fread($fp, 4096))
{
xml_parse($xml_parser, $data, feof($fp)) or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}

// Close the datafile
fclose($fp);

// Free any memmory used
xml_parser_free($xml_parser);
}

?>


After completing that create a phpbox in TP and enter this script info


// include tinyRSS
include "feedreader/tinyRSS.php";

echo '<div style="padding: 5px;" class="smalltext">';
tinyRSS("http://forums.keyboardjunkies.com/index.php?action=.xml;type=rss;sa=recent");
echo '</div>';
Title: Re: tinyRSS w/ cURL method
Post by: knat on May 31, 2007, 08:01:41 AM
Is there a demo to show what this looks like ?  ::)
Title: Re: tinyRSS w/ cURL method
Post by: necrit on May 31, 2007, 10:01:58 PM
Quote from: Tank on May 31, 2007, 08:01:41 AM
Is there a demo to show what this looks like ?  ::)

Whoops.   :o its probably a WHOLE lot more visible if you can actually SEE the link then huh?

http://forums.loquinth.com/index.php/board,3.0.html (http://forums.loquinth.com/index.php/board,3.0.html)
Title: Re: tinyRSS w/ cURL method
Post by: hillsborough on July 03, 2007, 07:39:29 PM
Done. I get this errorFatal error: Call to undefined function: tinyrss() in /home/content/f/x/a/fxaw1/html/Sources/Load.php(1736) : eval()'d code(35) : eval()'d code on line 5

and

http://awfx.info/index.php 
2: (null)(): Failed opening 'feedreader/tinyRSS.php' for inclusion (include_path='.:/usr/local/lib/php')
File: /home/content/f/x/a/fxaw1/html/Themes/default/TPortal.template.php (eval?)

and



    http://awfx.info/index.php 
2: Unknown(feedreader/tinyRSS.php): failed to open stream: No such file or directory
File: /home/content/f/x/a/fxaw1/html/Themes/default/TPortal.template.php (eval?)
Line: 2


pardon my lack of knowlege. The file is in the root.