TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,004
  • Total Topics: 21,330
  • Online today: 141
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 99
  • Total: 99

tinyRSS w/ cURL method

Started by necrit, May 30, 2007, 10:10:36 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

necrit

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 ($chCURLOPT_URL$url);
curl_setopt ($chCURLOPT_RETURNTRANSFER1);
curl_setopt ($chCURLOPT_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$resultstrlen($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($fp4096))
{
xml_parse($xml_parser$datafeof($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>';

knat

Is there a demo to show what this looks like ?  ::)

necrit

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

hillsborough

#3
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.

This website is proudly hosted on Crocweb Cloud Website Hosting.