Convertir du Php en Xml ?

sylvaneau
Invité n'ayant pas de compte PHPfrance

12 nov. 2006, 14:39

Bonjour,

j'ai un fichier rss2.php me permettant de récupérer les infos de mon forum pour un fil d'actu. I marche trés bien et me génère un ficjier xml, cependant j'aurais besoin d'avoir ce fichier en .xml pour que firefox le repère bien comme un fil d'actu et l'utiliser en marque page dinamique.
Comment faire ?

merci

voilà son code :
<?php
/************************************************************************/
/*    Pc-Nuke! Systems -  Advanced Content Management System            */
/************************************************************************/
/*    Created by PcNuke.com -- Released: 2005                           */
/*    http://www.max.pcnuke.com  --  http://www.pcnuke.com              */
/*    All Rights Reserved 2005 -- by Pc-Nuke!                           */
/*    No Modding, Porting, Changing, or Distribution of this program    */
/*    is allowed without written permission from www.pcnuke.com         */
/************************************************************************/
/************************************************************************/
/*          The Power of the Nuke - Without the Radiation!              */
/************************************************************************/
/************************************************************************/
/*    Pc-Nuke! Portal is derrived from the following source:            */
/*    Copyright (c) 2002 by Francisco Burzi                             */
/*    http://phpnuke.org                                                */
/************************************************************************/
/*
*
*   Put this file in your PHP-Nuke root  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/php-nuke/rdf-nuke.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/php-nuke/rdf-nuke.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/php-Nuke/rdf-nuke.php?fid=5&count=3
*
*   will show you the latest 3 posts from forum 5.
*
*   THIS SCRIPT WILL ONLY SHOW POSTS FROM PUBLIC FORUMS
*
***************************************************************************/




// Inserted by Chris:
include("mainfile.php");

$module_name = "Forums";
$nuke_root_path = "modules.php?name=" . $module_name;
$nuke_file_path = $nuke_root_path . "&file=";
// require("modules/$module_name/nukebb.php");

define('IN_PHPBB', true);
$phpbb_root_path = './modules/' . $module_name . '/';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
// include("includes/functions_selects.php");


// Taken from rdf.php:

// 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; charset=ISO-8859-1');


// 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)
// viewtopic and index adapted by Chris
$viewtopic = $nuke_file_path . 'viewtopic';

// We don't need these three, but I include them anyway,
// just in case you need them...
$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']) . '/' : '/';

$viewtopic_url = $nukeurl . '/' . $viewtopic;

// For debugging purposes, you can see $viewtopic here:
// echo $viewtopic_url;

// Some code taken from backendforums.php in this rdf string:
$rdf = "<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>".htmlspecialchars($sitename)." Forums</title>
    <link>$nukeurl</link>
    <description>".htmlspecialchars($backend_title)."</description>
</channel>
";


// Taken from rdf.php:
$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 f.forum_id IN (" . implode($fid, ", ") . ")" : " ";

$sql_orderby = $news ? 't.topic_time DESC' : 'p.post_time DESC';
$sql_post_id_field = $news ? 't.topic_first_post_id' : 't.topic_last_post_id';

// Added by Chris:
define('TOPICS_TABLE', $prefix.'_bbtopics');
define('POSTS_TABLE', $prefix.'_bbposts');
define('POSTS_TEXT_TABLE', $prefix.'_bbposts_text');
define('FORUMS_TABLE', $prefix.'_bbforums');
define('AUTH_ALL', 0);
define('POST_TOPIC_URL', 't');
define('POST_POST_URL', 'p');

// Taken from rdf.php:
// SQL statement to fetch active topics of public forums
$sql = "SELECT t.topic_id, t.topic_title, p.post_id, p.post_time, pt.post_text, pt.bbcode_uid, f.forum_name FROM " . TOPICS_TABLE . " AS t, " . POSTS_TABLE . " AS p, " . POSTS_TEXT_TABLE . " AS pt, " . FORUMS_TABLE . " AS f WHERE f.forum_id = t.forum_id AND f.auth_view = " . AUTH_ALL . " AND p.topic_id = t.topic_id AND p.post_id = $sql_post_id_field AND pt.post_id = p.post_id $sql_where ORDER BY $sql_orderby LIMIT $count";

// For debugging purposes, you can echo the SQL statement here:
// echo $sql;

$topics_query = $db->sql_query($sql);
//die($sql);
if ( !$topics_query )
{
    die("Failed obtaining list of active topics");
}
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'];
   // Changed the "?" to "&" in $url (Chris)
        $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>";


$rdf.="
</item>
"; 
    }
}

// Create RDF footer
$rdf .= "
</rdf:RDF>";

// Output the RDF
echo $rdf;

?>

Modérateur PHPfrance
Modérateur PHPfrance | 6037 Messages

20 nov. 2006, 13:51

Ton problème est juste de mettre le contenu d'une variable dans un fichier plutôt que de l'afficher ?

file_put_contents() te conviendra,alors.
Règle n°2 du webmaster : Toujours commencer par le HTML qu'on veut obtenir....toujours ! :priere:
J'aime apprendre de nouvelles choses.