Welcome to Geeklog, Anonymous Friday, March 29 2024 @ 01:15 am EDT

Geeklog Forums

User Content Syndication


Status: offline

ronack

Forum User
Full Member
Registered: 05/27/03
Posts: 612
This is something that I think should be added to Geeklog. Back in 2005 Rick Westmoreland created this (see rss.php below) script which created a RSS Feed by Author. Just place this in a file called rss.php then anyone who posts stories on the site will have their own RSS Feed of just their stories.

This for instance http://www.some_site.com/rss.php?uid=2 would show all the stories/articles for User ID 2.

Add a little code to the User Profile template with the XML icon then every user can see their RSS Feed . I added this to
profile.thtml

Text Formatted Code

                                <tr valign="top">
                                        <td align="right"><b>RSS Feed for {username}:</b></td>
                                        <td><a href="{site_url}/rss.php?uid={user_id}"> <img src="{site_url}/images/xmlicon.gif" border=0></a></td>
                                </tr>
 

rss.php

Text Formatted Code

<?php

// rss.php
// May 11, 2005 Rick Westmoreland
//
// Code borrowed from (geeklog):
// $Id: users.php,v 1.93 2004/10/23 10:23:01 dhaun Exp $
//
// Original code by:
// @author   Tony Bibbs <tony@tonybibbs.com>
// @author   Mark Limburg <mlimburg@users.sourceforge.net>
// @author   Jason Whittenburg
//

require_once ('lib-common.php');


function userarticles ($user)
{
    global $_CONF, $_TABLES, $_USER;

    $result = DB_query("SELECT username,fullname FROM {$_TABLES['userinfo']},{$_TABLES["users"]} WHERE {$_TABLES['userinfo']}.uid = {$_TABLES['users']}.uid AND {$_TABLES['users']}.uid = $user");
    $nrows = DB_numRows($result);
    if ($nrows == 0) { // no such user
        return COM_refresh ($_CONF['site_url'] . '/');
    }
    $A = DB_fetchArray($result);


    header ("Content-Type: application/xml; charset=iso-8859-1");
    $displayRSS = '';
    //
    // change this for number of articles
    //
    $limit = '15';


    $displayRSS .= '<rss version="2.0">
';
    $displayRSS .= '    <channel>
';

    $result = DB_query ("SELECT tid FROM {$_TABLES['topics']}"
            . COM_getPermSQL ());
    $nrows = DB_numRows ($result);
    $tids = array ();
    for ($i = 0; $i < $nrows; $i++) {
        $T = DB_fetchArray ($result);
        $tids[] = $T['tid'];
    }
    $topics = "'" . implode ("','", $tids) . "'";


    // list of last 10 stories by this user (RSS)
    if (sizeof ($tids) > 0) {
        $sql = "SELECT sid,tid,title,introtext,UNIX_TIMESTAMP(date) AS unixdate FROM {$_TABLES['stories']} WHERE (uid = $user) AND (draft_flag = 0) AND (date <= NOW()) AND (tid IN ($topics))" . COM_getPermSQL ('AND');
        $sql .= " ORDER BY unixdate DESC LIMIT " . $limit;
        $result = DB_query($sql);
        $nrows = DB_numRows($result);
    } else {
        $nrows = 0;
    }

    $displayRSS .= '        <title>' . $_CONF['site_name'] . ' Articles by ' . $A['fullname'] . '</title>
';
    $displayRSS .= '        <link>' . $_CONF['site_url'] . '</link>
';
    $displayRSS .= '        <description>Last ' . $nrows . ' Articles written by ' . $A['fullname'] . '</description>
';
    $displayRSS .= '        <language>' . $_CONF['rdf_language'] . '</language>
';
    $displayRSS .= '        <generator>Geeklog Author RSS Script</generator>
';


    if ($nrows > 0) {
        for ($i = 1; $i <= $nrows; $i++) {
            $C = DB_fetchArray($result);

            $displayRSS .= '        <item>
';

            $C['title'] = str_replace ('$', '$', $C['title']);
            $displayRSS .= '            <title>' . stripslashes($C['title']) . '</title>
';

            $articleUrl = COM_buildUrl ($_CONF['site_url'] . '/article.php?story=' . $C['sid']);
            $displayRSS .= '            <link>' . $articleUrl . '</link>
';

            $introtext = stripslashes($C['introtext']);
            $introtext = trim($introtext);
            $introtext = preg_replace('/(\015)/', '', $introtext);
            $breaks = array('<br>', '<br/>', '', '</p>');
            $introtext = str_replace($breaks, ' ', $introtext);
            $introtext = strip_tags($introtext);
            $introtext = htmlspecialchars($introtext, ENT_QUOTES);
            $displayRSS .= '            <description>' . $introtext . '</description>
';

            $displayRSS .= '            <category>' . $C['tid'] . '</category>
';

            $datetime = date(r, $C['unixdate']);
            $displayRSS .= '            <pubDate>' . $datetime . '</pubDate>
';

            $displayRSS .= '            <guid isPermaLink="false">' . $C['sid'] . '</guid>
';

            $displayRSS .= '            <comments>' . $articleUrl . '#comments</comments>
';

            $displayRSS .= '        </item>
';
        }
    }

    $displayRSS .= '    </channel>
';
    $displayRSS .= '</rss>
';


    return $displayRSS;
}


// MAIN

$display = '';


$uid = COM_applyFilter ($HTTP_GET_VARS['uid'], true);

if (is_numeric ($uid) && ($uid > 0)) {
    $display .= userarticles ($uid);
} else {
    $display .= COM_refresh ($_CONF['site_url'] . '/');
}


echo $display;

?>
 
 Quote

All times are EDT. The time is now 01:15 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content