We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

XML loading plugin

Development and Programming

mschoening's avatar
mschoening
71 posts
16 years ago
mschoening's avatar mschoening

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

       
mschoening's avatar
mschoening
71 posts
16 years ago
mschoening's avatar mschoening

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

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

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.