XML loading plugin
Posted: 08 September 2008 05:42 AM   [ Ignore ]  
Grad Student
Rank
Total Posts:  100
Joined  11-26-2007

Hi,
I am trying to build a plugin that reads out an XML file specified in the tag and then outputs data. So here is my code so far:

<?php
/*
=====================================================
Copyright (c) 2008 Frecuencies
-----------------------------------------------------
http://frecuencies.com/
=====================================================
File: pi.favorites_ranking.php
-----------------------------------------------------
Purpose: Grabs ranking from XML file
=====================================================
Changelog:

-Version 1.0
    First release
*/

$plugin_info = array(
    
'pi_name'            => 'Favorites Ranking',
    
'pi_version'        => '1.0.1',
    
'pi_author'            => 'Maximilian Schöning',
    
'pi_author_url'        => 'http://maximilianschoening.com/',
    
'pi_description'    => 'Grabs ranking from XML file.',
    
/*'pi_usage'        => Favorites_ranking::usage()*/
);

class
Favorites_ranking {
    
var $entry_id = '';
    var
$xml = '';
    var
$xml_path = '';
    var
$return_data = '';
    
    function
Favorites_ranking() {
        
global $TMPL, $LOC, $FNS, $PREFS, $SESS, $REGX, $DB;
        
        
$xml_path = $TMPL->fetch_param('xml_path');
        
$entry_id = $TMPL->fetch_param('entry_id');

        if (
file_exists($xml_path)) {
            $xml
= simplexml_load_file($xml_path);

            
$this->return_data = $xml->id_$entry_id;
        
}
        
        
else {
            
exit('No rank available.');
        
}
    }
}
?>

And here is my tag:

{exp:favorites_ranking entry_id="23" xml_path="{path=list/ranking}"}

Now which of these variables do I have to load for it to work:

global $TMPL, $LOC, $FNS, $PREFS, $SESS, $REGX, $DB;

I know I need to load the $TMPL and one other in order to parse the {path=list/ranking} but which one is it?

Also I get the following error:

Parse error: syntax error, unexpected T_VARIABLE in //pi.favorites_ranking.php on line 42

The line 42 is:

$this->return_data = $xml->id_$entry_id;

By the way my XML looks like this:

<?xml version="1.0" encoding="{charset}" ?>

<deejays>
    
{exp:weblog:entries orderby_favorites="yes" status="open" weblog="deejays"}
    
<id_{entry_id}>{absolute_count}</id_{entry_id}>
    
{/exp:weblog:entries}
</deejays>

Thanks,
Max

Profile
 
 
Posted: 08 September 2008 05:42 AM   [ Ignore ]   [ # 1 ]  
Grad Student
Rank
Total Posts:  100
Joined  11-26-2007

Oh and do I have to load the empty variables at the beginning?

var $entry_id = '';
    var
$xml = '';
    var
$xml_path = '';
    var
$return_data = '';

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64887 Total Logged-in Users: 64
Total Topics: 81813 Total Anonymous Users: 33
Total Replies: 439843 Total Guests: 279
Total Posts: 521656    
Members ( View Memberlist )