Hi,
I have my rss.php to work with twitterfeed so each time an author updates their story it posts on the site's twitter and FB. The problem I have is that after they have updated once, twitterfeed thinks it's spam and won't post any further updates. I think it's because it links directly to the story's main page instead of the new chapter (it's the same link as before). Is there a way of changing the rss.php so that when someone updates the link sends them to the new chapter (and therefore a new page so twitterfeed posts).
My rss.php:
<?php
// ----------------------------------------------------------------------
// Copyright (c) 2007 by Tammy Keefer
// Based on eFiction 1.1
// Copyright (C) 2003 by Rebecca Smallwood.
// http://efiction.sourceforge.net/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
define("_BASEDIR", "");
include_once("includes/dbfunctions.php");
include_once("config.php");
$settingsresults = dbquery("SELECT sitename, url, siteemail, slogan, language, tableprefix, dateformat FROM ".$settingsprefix."fanfiction_settings WHERE sitekey = '$sitekey'");
$settings = dbassoc($settingsresults);
foreach($settings as $var => $val) {
$$var = $val;
}
define("TABLEPREFIX", $tableprefix);
define("SITEKEY", $sitekey);
include_once("includes/queries.php");
if(file_exists("languages/{$language}.php")) include("languages/{$language}.php");
else include("languages/en.php");
ob_start ("ob_gzhandler");
function xmlentities ( $string )
{
return str_replace ( array ( '&', '"', "'", '<', '>' ), array ( '&' , '"', ''' , '<' , '>' ), $string );
}
$ratlist = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_ratings");
while($rate = dbassoc($ratlist)) {
$ratings[$rate['rid']] = $rate['rating'];
}
$rss="<?xml version="1.0" encoding=""._CHARSET.""?>n";
$rss.="<rss version="2.0">n";
$rss.="<channel>n";
$rss.="<copyright>Copyright ".date("Y")."</copyright>n";
$rss.="<lastBuildDate>".date("r")."</lastBuildDate>n";
$rss.="<description>".xmlentities($slogan)."</description>n";
$rss.="<link>$url</link>n";
$rss.="<title>".xmlentities( $sitename)."</title>n";
$rss.="<managingEditor>$siteemail</managingEditor>n";
$rss.="<webMaster>$siteemail</webMaster>n";
$rss.="<language>$language</language>n";
$query = _STORYQUERY." ORDER BY updated DESC LIMIT 20";
$results = dbquery($query);
while($story = dbassoc($results)) {
$story['authors'][] = $story['penname'];
if($story['coauthors']) {
$coauth = dbquery("SELECT "._PENNAMEFIELD." as penname, co.uid FROM ".TABLEPREFIX."fanfiction_coauthors AS co LEFT JOIN "._AUTHORTABLE." ON co.uid = "._UIDFIELD." WHERE co.sid = '".$story['sid']."'");
while($c = dbassoc($coauth)) {
$story['authors'][] = $c['penname'];
}
}
foreach($story['authors'] AS $k => $v) {
$story['authors'][$k] = strip_tags(xmlentities( $v));
}
$rss.= "<item>
<title>".strip_tags(xmlentities($story['title']))." "._BY." ".implode(", ", $story['authors'])." [".$ratings[$story['rid']]."]</title>
<link>$url/fiction/viewstory.php?sid=".$story['sid']."</link>
<description>".strip_tags(xmlentities($story['summary']))."</description>
<pubDate>".date("r",$story['updated'])."</pubDate>
</item>n";
}
$rss.="</channel>
</rss>";
header("Content-type: application/rss+xml");
header("Cache-Control: must-revalidate");
header("Expires: ".gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
echo $rss;
?>
The only change I've made to that file is the location in <url> so it goes to /fiction.
Any help would be great. At the moment I've got links disabled in twitterfeed so it updates but that's really not desirable.
Thanks,
Jo
http://www.gigglesnort.net
You'd have to modify two things.
1. Either this query needs to be changed, or an additional one added:
$query = _STORYQUERY." ORDER BY updated DESC LIMIT 20";
_STORYQUERY only pulls from fanfiction_stories, which doesn't contain chapter information. You need a query that can pull that info from fanfiction_chapters.
2. You need to modify this to output the correct URL based on your modified/additional query:
<link>$url/fiction/viewstory.php?sid=".$story['sid']."</link>
_STORYQUERY, in case you don't know where to find it. (includes/queries.php)
define ("_STORYQUERY", "SELECT stories.*, "._PENNAMEFIELD." as penname, UNIX_TIMESTAMP(stories.date) as date, UNIX_TIMESTAMP(stories.updated) as updated FROM ("._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories) WHERE "._UIDFIELD." = stories.uid AND stories.validated > 0 ");
Oh, ok. Sorry, I'm a completely idiot when it comes to php and stuff like this.
Sounds a bit complicated.
What would I have to change that query to and what would I have to add for the correct URL in output?
Don't worry if it's too much.
So... would I change it to:
define ("_STORYQUERY", "SELECT stories.*, "._PENNAMEFIELD." as penname, UNIX_TIMESTAMP(stories.date) as date, UNIX_TIMESTAMP(stories.updated) as updated FROM ("._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_chapters as stories) WHERE "._UIDFIELD." = stories.uid AND stories.validated > 0 ");
I've no idea what I would have to change the URL to still...
Oh, no. _STORYQUERY is the query in what you quoted. It's just used so often it's been defined as a constant. So rather than using that default query, I think you need to make another that joins fanfiction_chapters to get the right info to add in the URL. Unfortunately I don't have time to test it right now so I can't be more specific, but maybe it will set someone on the right path!
You should do an additional query. Don't edit _STORYQUERY. That is used everywhere in the site. Adding the chapter information to it would add a lot of unnecessary querying to the rest of the site.
Thanks,
So what would the new query be?
This was suggested to me on the twitterfeed helpdesk, but the guy wasn't an expert in php:
<link>$url/fiction/viewstory.php?sid=".$story['sid']."&upd=".$story['updated']</link>
It resulted in the following error though:
Parse error: syntax error, unexpected '/' in /home/gigglesn/public_html/fiction/rss.php on line 75
I basically just need it so that when an author updates, the link on twitter/rss.php goes to the new chapter and not the main story page.
Cheers,
Jo
