Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Output feedwordpress database for use in Planet

You'll need to change the initial settings as I didn't bother to read them from the Wordpress config file. You may also need to change the table name (wp_links) in the sql query.

<?php
$username = "myuser";
$password = "P455w0rd";
$database = "db_name";
$hostname = "127.0.0.1";

$query = "SELECT link_name, link_rss FROM wp_links WHERE link_category=2";

mysql_connect($hostname, $username,$password);
@mysql_select_db($database) or die("Unable to select database");
$result = mysql_query($query);
$num = mysql_numrows($result);
mysql_close();

$i=0;
while($i < $num) {
        $rss = mysql_result($result,$i,"link_rss");
        $name = mysql_result($result,$i,"link_name");

        echo "[".$rss."]\r\n";
        echo "name = ".$name."\r\n";
        $i++;
}
?>

Feedwordpress mod

A simplified version of update-feeds.php from the Feedwordpress project. This version doesn't bother checking for authentication as there's really no point. It doesn't check whether it's being run at the commandline either, it simply assumes it is being called by wget as a cron job. This is designed to be run with version 0.98

<?php

// Help us to pick out errors, if any.
ini_set('error_reporting', E_ALL & ~E_NOTICE);
ini_set('display_errors', true);
define('MAGPIE_DEBUG', true);

// Are we running from a web request or from the command line?
                $update_feeds_display = 'text/plain';
                $update_feeds_invoke = 'post';
                $update_feeds_verbose = false;

require_once ('../wp-blog-header.php');

function update_feeds_mention ($feed) {
        global $update_feeds_display;

        if ($update_feeds_display=='text/html') :
                echo "<li>Updating <cite>".$feed['link/name']."</cite> from &lt;<a href=\""
                        .$feed['link/uri']."\">".$feed['link/uri']."</a>&gt; ...</li>\n";
        else :
                echo "* Updating ".$feed['link/name']." from <".$feed['link/uri']."> ...\n";
        endif;
        flush();
}

# -- Don't change these unless you know what you're doing...
define ('RPC_MAGIC', 'tag:radgeek.com/projects/feedwordpress/'); // update all

// Query secret word from database
$rpc_secret = get_settings('feedwordpress_rpc_secret');

header("Content-Type: {$update_feeds_display}; charset=utf-8");


        // Henceforward, we can proceed on the assumption that we have an authenticated user
        $uri = (isset($_REQUEST['uri']) ? $_REQUEST['uri'] : RPC_MAGIC.$rpc_secret);

        if ($update_feeds_display=='text/html') :
                echo <<<EOHTML
<?xml version="1.0" encoding="utf-8"?>
<html>
<head>
<title>update-feeds :: FeedWordPress</title>
</head>

<body>
<h1>update-feeds: make FeedWordPress check for new syndicated content</h1>

EOHTML;
        endif;

$feedwordpress =& new FeedWordPress;

if ($update_feeds_display=='text/html' or $update_feeds_verbose) :
        add_action('feedwordpress_check_feed', 'update_feeds_mention');
endif;

if ($update_feeds_display=='text/html') : // HTTP GET or HTTP POST: add some web niceties


        echo "<form action=\"\" method=\"POST\">\n";
        echo "<select name=\"uri\">\n";
        echo "<option value=\"".RPC_MAGIC.$rpc_secret."\">All feeds</option>\n";
        foreach ($feedwordpress->feeds as $feed) :
                echo "<option value=\"{$feed['link/uri']}\"";
                if ($feed['link/uri']==$_REQUEST['uri']) : echo ' selected="selected"'; endif;
                echo ">{$feed['link/name']}</option>\n";
        endforeach;
        echo "</select> ";
        echo "<input type=\"submit\" name=\"update\" value=\"Update\" />\n";
        echo "</form>\n";
endif;

if ($update_feeds_invoke != 'get') : // Only do things with side-effects for HTTP POST or command l
ine
        if ($update_feeds_display == 'text/html') : echo "<ul>\n"; endif;
        $delta = @$feedwordpress->update($uri);
        if ($update_feeds_display == 'text/html') : echo "</ul>\n"; endif;

        if (is_null($delta)) :
                if ($update_feeds_invoke == 'cmd') :
                        $stderr = fopen('php://stderr', 'w');
                        fputs($stderr, "update-feeds (".date('Y-m-d H:i:s')."): ERROR: I don't synd
icate <$uri>\n");
                elseif ($update_feeds_display == 'text/plain') :
                        echo "update-feeds (".date('Y-m-d H:i:s')."): ERROR: I don't syndicate <$ur
i>\n";
                else :
                        echo "<p><strong>Error:</strong> I don't syndicate <a href=\"$uri\">$uri</a
></p>\n";
                endif;
        elseif ($update_feeds_display=='text/html' or $update_feeds_verbose) :
                $mesg = array();
                if (isset($delta['new'])) : $mesg[] = ' '.$delta['new'].' new posts were syndicated
'; endif;
                if (isset($delta['updated'])) : $mesg[] = ' '.$delta['updated'].' existing posts we
re updated'; endif;
                if ($update_feeds_display=='text/html') : echo "<p>"; endif;
                echo "Update complete.".implode(' and', $mesg);
                if ($update_feeds_display=='text/html') : echo "</p>"; endif;
                echo "\n"; flush();
        endif;
endif;

if ($update_feeds_display=='text/html') : // HTTP GET or HTTP POST: close off web niceties
        echo <<<EOHTML

<p><a href="../wp-admin">&larr; Return to WordPress Dashboard</a></p>
</body>
</html>
EOHTML;
endif;
?>

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS