RdfScript
Zur Navigation springen
Zur Suche springen
Lizenz: Dieser Artikel wurde als problematisch in Bezug auf der Lizenz markiert, dafür kann es verschiedene Gründe geben:
Bitte hilf mit alle diese Fragen zunächst zu klären, danach kann dieser Hinweis entfernt werden. |
Scripting / Scripting Web / Netzwerk / RdfScript
<?php
/***************************************************************************
* rdf.php
* -------------------
* begin : Saturday, Mar 2, 2002
* copyright : (C) 2002 Matthijs van de Water
* Sascha Carlin
* email : matthijs@beryllium.net
* sc@itst.org
*
* $Id: rdf.php,v 1.2 2002/04/15 13:15:01 mvdwater Exp $
*
*
***************************************************************************/
/***************************************************************************
*
* I added a cache table to this software because we had big performace
* problems caused by this script
* See http://www.debianforum.de/wiki/NewRDFScript
*
* Martin Lohmeier, debianforum.de Jan 2005
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
/***************************************************************************
*
* PHPBB 2.0 RDF CONTENT SYNDICATOR
* Shows last active topics RDF XML form
*
***************************************************************************
*
* Put this file in your phpBB2 directory.
* You can call this script without parameters, what will
* result in an RDF with the 10 latest posts from all your forums.
* You can specify the number of posts via the url parameter count:
*
* http://www.domain.com/phpBB2/rdf.php?count=50
*
* This will result in an RDF file with the latest 50 posts from
* all your forums.
*
* You can also specify to look only at a specified forum using the
* fid parameter:
*
* http://www.domain.com/phpBB2/rdf.php?fid=9
*
* This will result in an RDF file with the latest 10 posts from
* your forum with the id 9.
*
* You can also mix the paramters:
*
* http://www.domain.com/phpBB2/rdf.php?fid=5&count=3
*
* will show you the latest 3 posts from forum 5.
*
* THIS SCRIPT WILL ONLY SHOW POSTS FROM PUBLIC FORUMS
*
***************************************************************************/
// XML and nocaching headers
header ('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
header ('Expires: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
header ('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header ('Content-Type: text/xml');
// Includes of phpBB scripts
define ('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
// for the cache function
//
define(CACHE_TABLE, "rdf_cache");
define(POSTS_PER_FORUM, "30");
define(MAX_CACHE_SIZE, "1000");
// which is the biggest post_id in cache
//
$sql = "SELECT MAX(post_id) AS post_id FROM " . CACHE_TABLE . ";";
$max_post_id_query = $db->sql_query($sql);
if( !$max_post_id_query ) {
die("SQL Error: $sql <br>" . mysql_error() );
}
else {
$max_post_id = $db->sql_fetchrowset($max_post_id_query);
}
// get all new post_id's
//
$sql = "SELECT post_id FROM " . POSTS_TABLE ." WHERE post_id > " . $max_post_id[0]['post_id'] . ";";
$new_posts_query = $db->sql_query($sql);
if( !$new_posts_query ) {
die("SQL Error: $sql <br>" . mysql_error() );
}
else {
$new_posts = $db->sql_fetchrowset($new_posts_query);
for ($i = 0; $i < count($new_posts); $i++) {
// get new post's and all data that is needed for the rdf part
//
$sql = "INSERT INTO " . CACHE_TABLE . " SELECT p.post_id, p.post_time, pt.post_text, pt.bbcode_uid, t.topic_id, t.topic_time, t.topic_title, f.forum_id, f.forum_name, t.topic_first_post_id, t.topic_last_post_id FROM dfdeforum_topics AS t, dfdeforum_posts AS p, dfdeforum_posts_text AS pt, dfdeforum_forums as f WHERE p.post_id = '" . $new_posts[$i]['post_id'] . "' AND f.auth_view = '0' AND p.topic_id = t.topic_id AND pt.post_id = p.post_id AND p.forum_id = f.forum_id;";
$post_cache_query = $db->sql_query($sql) or die("SQL Error: " . mysql_error() );
}
}
// clean up cache if it is to big
//
//
$sql = "SELECT COUNT(post_id) AS post_id FROM " . CACHE_TABLE . ";";
$cache_count_query = $db->sql_query($sql) or die("SQL Error $sql : " . mysql_error() );
$cache_count = $db->sql_fetchrowset($cache_count_query);
if($cache_count[0]['post_id'] > MAX_CACHE_SIZE ) {
$sql = "SELECT forum_id FROM " . FORUMS_TABLE . ";";
$all_forums_query = $db->sql_query($sql);
if( !$all_forums_query ) {
die("SQL Error: $sql <br>" . mysql_error() );
}
else {
$all_forums = $db->sql_fetchrowset($all_forums_query);
for ($i = 0; $i < count($all_forums); $i++) {
// get COUNT
//
$sql = "SELECT COUNT(post_id) AS post_id FROM " . CACHE_TABLE . " WHERE forum_id = '" . $all_forums[$i]['forum_id'] . "';";
$posts_per_forum_query = $db->sql_query($sql) or die("SQL Error $sql : " . mysql_error() );
$posts_per_forum = $db->sql_fetchrowset($posts_per_forum_query);
// selecet range of messages that should be deleted
//
if($posts_per_forum[0]['post_id'] <= POSTS_PER_FORUM ) {
continue;
}
$limit = $posts_per_forum[0]['post_id'] - POSTS_PER_FORUM;
// delete messages
//
$sql = "SELECT post_id FROM rdf_cache WHERE forum_id = '" . $all_forums[$i]['forum_id'] . "' ORDER BY post_id ASC LIMIT " . $limit . ";";
$delete_query = $db->sql_query($sql) or die("SQL Error $sql : " . mysql_error() );
$delete = $db->sql_fetchrowset($delete_query);
for ($j = 0; $j < count($delete);$j++) {
$sql = "DELETE FROM " . CACHE_TABLE . " WHERE post_id = '" . $delete[$j]['post_id'] . "';";
$delete_post_query = $db->sql_query($sql) or die("SQL Error $sql : " . mysql_error() );
}
}
}
}
// If not set, set the output count to 10
$count = ( !isset($HTTP_GET_VARS['count']) ) ? 10 : intval($HTTP_GET_VARS['count']);
$count = ( $count == 0 ) ? 10 : $count;
// characters
//
$chars = ( isset($HTTP_GET_VARS['chars']) ) ? intval($HTTP_GET_VARS['chars']) : 200;
if($chars<0 || $chars>500) $chars=500; //Maximum
$type = ( isset($HTTP_GET_VARS['type']) ) ? $HTTP_GET_VARS['type'] : 'latest';
$news = ( $type == 'news' );
// Create main board url (some code borrowed from functions_post.php)
$script_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['script_path']));
$viewtopic = ( $script_name != '' ) ? $script_name . '/viewtopic.' . $phpEx : 'viewtopic.'. $phpEx;
$index = ( $script_name != '' ) ? $script_name . '/index.' . $phpEx : 'index.'. $phpEx;
$server_name = trim($board_config['server_name']);
$server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://';
$server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/';
$index_url = $server_protocol . $server_name . $server_port . $index;
$viewtopic_url = $server_protocol . $server_name . $server_port . $viewtopic;
$rdf = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>
<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns=\"http://my.netscape.com/rdf/simple/0.9/\">
<channel>
<title>" . $board_config['sitename'] . " Forum</title>
<link>" . $index_url . "</link>
<description>" . $board_config['site_desc'] . "</description>
</channel>
";
$fid = ( isset($HTTP_GET_VARS['fid']) ) ? $HTTP_GET_VARS['fid'] : array();
if(!is_array($fid)) $fid = array($fid);
$fid_new = array();
for($i=0; $i<sizeof($fid); $i++)
{
if(intval($fid[$i]) > 0)
{
if(!in_array($fid[$i], $fid_new))
{
$fid_new[] = $fid[$i];
}
}
}
$fid = $fid_new;
$sql_where = ( sizeof($fid)>0 ) ? "AND forum_id IN (" . implode($fid, ", ") . ")" : " ";
$sql_orderby = $news ? 'topic_time DESC' : 'post_time DESC';
$sql_post_id_field = $news ? 'topic_first_post_id' : 'topic_last_post_id';
// SQL statement to fetch active topics of public forums
//
$sql = "SELECT topic_id, topic_title, post_id, post_time, post_text, bbcode_uid, forum_name
FROM " . CACHE_TABLE . " WHERE
post_id = $sql_post_id_field
$sql_where
ORDER BY $sql_orderby LIMIT $count";
$topics_query = $db->sql_query($sql);
if ( !$topics_query )
{
die("Failed obtaining list of active topics <b>$sql</b>" . mysql_error() );
}
else
{
$topics = $db->sql_fetchrowset($topics_query);
}
if ( count($topics) == 0 )
{
die("No topics found");
}
else
{
// $topics contains all interesting data
for ($i = 0; $i < count($topics); $i++)
{
if(isset($HTTP_GET_VARS['titlepattern']))
{
$title = $HTTP_GET_VARS['titlepattern'];
$title = str_replace('__DATE__', date("d.m.Y H:i", $topics[$i]['post_time']), $title);
$title = str_replace('__TITLE__', $topics[$i]['topic_title'], $title);
$title = str_replace('__FORUM__', $topics[$i]['forum_name'], $title);
}
else
{
$title = $topics[$i]['topic_title'];
}
//$title = "[" . date("d.m.Y H:i", $topics[$i]['post_time']) . "|" . $topics[$i]['forum_name'] . "] " . $topics[$i]['topic_title'];
$url = ($news) ? $viewtopic_url . "?" . POST_TOPIC_URL . "=" . $topics[$i]['topic_id'] : $viewtopic_url . "?" . POST_POST_URL . "=" . $topics[$i]['post_id'] . "#" . $topics[$i]['post_id'];
$message = $topics[$i]['post_text'];
$bbcode_uid = $topics[$i]['bbcode_uid'];
$message = strip_tags($message);
$message = preg_replace("/\[.*?:$bbcode_uid:?.*?\]/si", '', $message);
$message = preg_replace('/\[url\]|\[\/url\]/si', '', $message);
if($chars > 0) {
$message = ( strlen($message) > $chars ) ? substr($message, 0, ($chars - 4)) . ' ...' : $message;
}
$rdf .= "
<item>
<title>" . $title . "</title>
<link>" . $url . "</link>";
// <pubDate>" . date('r', $topics[$i]['post_time']) . "</pubDate>";
if($chars != 0 && strlen($message)>0) $rdf .= "
<description>" . htmlspecialchars($message) . "</description>";
$rdf.="
</item>
";
}
}
// Create RDF footer
$rdf .= "
</rdf:RDF>";
// Output the RDF
echo $rdf;
?>
Das Script benötigt folgende Tabelle:
CREATE TABLE `rdf_cache` (
`post_id` mediumint(8) unsigned NOT NULL default '0',
`post_time` int(11) unsigned NOT NULL default '0',
`post_text` text NOT NULL,
`bbcode_uid` varchar(10) NOT NULL default '',
`topic_id` mediumint(8) unsigned NOT NULL default '0',
`topic_time` int(11) unsigned NOT NULL default '0',
`topic_title` varchar(60) NOT NULL default '',
`forum_id` smallint(5) unsigned NOT NULL default '0',
`forum_name` varchar(150) NOT NULL default '',
`topic_first_post_id` mediumint(8) unsigned NOT NULL default '0',
`topic_last_post_id` mediumint(8) unsigned NOT NULL default '0',
UNIQUE KEY `post_id` (`post_id`)
) TYPE=MyISAM COMMENT='damit das rdf script schneller wird';
Scripting / Scripting Web / Netzwerk / RdfScript