WordPress.org

Plugin Directory

Changeset 486503


Ignore:
Timestamp:
01/08/12 13:28:40 (6 years ago)
Author:
RaymondDesign
Message:

Added Wordpress shortcodes.

Location:
advanced-xml-reader/trunk
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • advanced-xml-reader/trunk/advanced-xml-reader.php

    r390213 r486503  
    44Plugin URI: http://dev.raymonddesign.nl/wordpress-plugins/advanced-xml-reader/ 
    55Description: Use the content of every XML file in your posts. 
    6 Version: 0.3.2 
     6Version: 0.3.4 
    77Author: RaymondDesign 
    88Author URI: http://www.raymonddesign.nl/ 
     
    1010*/ 
    1111 
    12 /*  Copyright 2010  RaymondDesign  (email : webmaster@raymonddesign.nl) 
     12/*  Copyright 2011  RaymondDesign  (email : webmaster@raymonddesign.nl) 
    1313 
    1414    This program is free software; you can redistribute it and/or modify 
     
    2626*/ 
    2727 
    28  
    29 // Include a curl library, this lib caches the data, so it's much faster 
    30 // Author: Mike Purvis, http://uwmike.com/maps/curl.php.source 
    31     require_once('curl.php'); 
    3228 
    3329// Define some plugin variables 
     
    3733    $plugindata['shortname']    = 'Advanced XML'; 
    3834    $plugindata['shortnicename']= 'advanced-xml'; 
    39     $plugindata['versionhash']  = 'dgt3kSr2tf'; // This hash represent the current version 
     35    $plugindata['versionhash']  = 'TQQLx9SFSu'; // This hash represents the current version 
    4036     
    4137    $pluginvars['remove_tag']   = array(); // Contains the tags that has to be hidden 
     
    4440    load_plugin_textdomain( 'advanced-xml-reader', 'wp-content/plugins/'.$plugindata['dir']); 
    4541    add_action('admin_menu', 'aXMLreader_AdminMenu'); 
    46     add_action('the_content', 'aXMLreader_ParseTags',0); 
    47     add_filter('widget_title', 'aXMLreader_ParseTags'); 
    48     add_filter('widget_text', 'aXMLreader_ParseTags'); 
     42    add_action('the_content', 'aXMLreader_ParseTags',0); // DEPRECATED as of version 0.3.4 
     43    add_filter('widget_title', 'aXMLreader_ParseTags'); // DEPRECATED as of version 0.3.4 
     44    add_filter('widget_text', 'aXMLreader_ParseTags'); // DEPRECATED as of version 0.3.4 
     45    add_shortcode('advanced-xml', 'aXMLreader_ParseShortcode'); 
    4946 
    5047// Define some usefull functions 
     
    110107    /** 
    111108     * Transforms the array from aXMLreader_show_data into two arrays, which can be used in str_replace 
     109     *  
     110     * DEPRECATED as of version 0.3.4 
     111     *  
    112112     * Return: A array containing two arrays: patterns & replacements 
    113113     */ 
     
    125125            } 
    126126            return array('pattern' => $pattern, 'replace' => $replace); 
     127        } 
     128         
     129     /** 
     130     * Merge multiple items for same tag into one string 
     131     *  
     132     * Return: string 
     133     */ 
     134        function aXMLreader_merge_data($array, $row_delimiter, $item_delimiter){ 
     135            global $plugindata; 
     136            foreach($array as $key => $value){ 
     137                if(is_array($value)){ 
     138                    $array[$key] = implode($item_delimiter,aXMLreader_makeclickable($array[$key])); 
     139                } 
     140            } 
     141            return implode($row_delimiter,$array); 
    127142        } 
    128143 
     
    189204                </div>'; 
    190205            if($feed = get_option($plugindata['nicename'].'_feed')){ 
    191                 $curl = new CURL(); 
    192                 //$curl->enableCache(); 
    193                 $data = $curl->get($feed); 
    194                 $xml = new SimpleXmlElement($data, LIBXML_NOCDATA); 
    195                 $taglist = aXMLreader_show_data($xml); 
    196                 echo '<table> 
    197                         <tr><td><strong>'.__('XML tag', 'advanced-xml-reader').'</strong></td><td><strong>'.__('Value', 'advanced-xml-reader').'</strong></td><td><strong>'.__('How to use in a post', 'advanced-xml-reader').'</strong></td></tr>'; 
    198                     foreach($taglist as $key => $value){ 
    199                         $tmpvalue = '<em>This is a list containing multiple values.</em>'; 
    200                         if(isset($value[0])){ 
    201                             $tmpvalue = aXMLreader_cutstr($value[0],30); 
    202                         } 
    203                         echo '<tr><td>'.$key.'</td><td>'.$tmpvalue.'</td><td>['.$plugindata['shortnicename'].':'.$key.']</td></tr>'; 
    204                     }   
    205                 echo '</table>'; 
     206                $data = wp_remote_get($feed); 
     207                if(array_key_exists('errors', $data)){ 
     208                    echo __('Unable to load XML file!', 'advanced-xml-reader'); 
     209                }else{ 
     210                    $xml = new SimpleXmlElement($data['body'], LIBXML_NOCDATA); 
     211                    $taglist = aXMLreader_show_data($xml); 
     212                    echo '<table> 
     213                            <tr><td><strong>'.__('XML tag', 'advanced-xml-reader').'</strong></td><td><strong>'.__('Value', 'advanced-xml-reader').'</strong></td><td><strong>'.__('How to use in a post', 'advanced-xml-reader').'</strong></td></tr>'; 
     214                        foreach($taglist as $key => $value){ 
     215                            $tmpvalue = '<em>This is a list containing multiple values.</em>'; 
     216                            if(isset($value[0])){ 
     217                                $tmpvalue = aXMLreader_cutstr($value[0],30); 
     218                            } 
     219                            echo '<tr><td>'.$key.'</td><td>'.$tmpvalue.'</td><td>['.$plugindata['shortnicename'].' tag=&quot;'.$key.'&quot;]</td></tr>'; 
     220                        }   
     221                    echo '</table>'; 
     222                } 
    206223            } 
    207224            echo '<div style="border: 1px solid #ccc; background-color: #EEEEEE; padding: 5px;padding-bottom:13px; width: 700px;margin-top:30px;"> 
     
    223240    /** 
    224241     * Replaces the tags used in posts in real values 
     242     *  
     243     * DEPRECATED as of version 0.3.4 
     244     *  
    225245     * Return: $text (string) 
    226246     */ 
    227247     function aXMLreader_ParseTags($text){ 
    228         global $plugindata, $patterns, $replacements, $pluginvars; 
     248        global $plugindata, $pluginvars; 
    229249        if($feed = get_option($plugindata['nicename'].'_feed')){ 
    230             $curl = new CURL(); 
    231             //$curl->enableCache(); 
    232             $data = $curl->get($feed); 
    233             $xml = new SimpleXmlElement($data, LIBXML_NOCDATA); 
    234             $pluginvars['remove_tag'] = explode(',',str_replace(' ','',get_option($plugindata['nicename'].'_hidetag'))); 
    235             $taglist = aXMLreader_create_replace_arrays(aXMLreader_show_data($xml),get_option($plugindata['nicename'].'_rowdel'),get_option($plugindata['nicename'].'_itemdel')); 
    236             //aXMLreader_multiarray_walk($xml,'aXMLreader_fill_replace_arrays'); 
    237             $text = str_replace($taglist['pattern'], $taglist['replace'], $text); 
     250            $data = wp_remote_get($feed); 
     251            if(!array_key_exists('errors', $data)){ 
     252                $xml = new SimpleXmlElement($data['body'], LIBXML_NOCDATA); 
     253                $pluginvars['remove_tag'] = explode(',',str_replace(' ','',get_option($plugindata['nicename'].'_hidetag'))); 
     254                $taglist = aXMLreader_create_replace_arrays(aXMLreader_show_data($xml),get_option($plugindata['nicename'].'_rowdel'),get_option($plugindata['nicename'].'_itemdel')); 
     255                //aXMLreader_multiarray_walk($xml,'aXMLreader_fill_replace_arrays'); 
     256                $text = str_replace($taglist['pattern'], $taglist['replace'], $text); 
     257            } 
     258            // Do nothing on error, we don't want visitors to see errors. 
    238259        } 
    239260        return $text; 
    240261     } 
     262      
     263     /** 
     264     * Parse Wordpress shortcode tags 
     265     * Return: $text (string) 
     266     */ 
     267     function aXMLreader_ParseShortcode($atts){ 
     268        global $plugindata; 
     269        extract(shortcode_atts(array('tag' => false), $atts)); 
     270        if($tag !== false){ 
     271            $tag = strtolower($tag); 
     272            if($feed = get_option($plugindata['nicename'].'_feed')){ 
     273                $data = wp_remote_get($feed); 
     274                if(!array_key_exists('errors', $data)){ 
     275                    $xml = new SimpleXmlElement($data['body'], LIBXML_NOCDATA); 
     276                    $pluginvars['remove_tag'] = explode(',',str_replace(' ','',get_option($plugindata['nicename'].'_hidetag'))); 
     277                    $data = aXMLreader_show_data($xml); 
     278                    if(array_key_exists($tag,$data)){ 
     279                        $text = aXMLreader_merge_data($data[$tag],get_option($plugindata['nicename'].'_rowdel'),get_option($plugindata['nicename'].'_itemdel')); 
     280                        return $text; 
     281                    } 
     282                } 
     283            } 
     284        } 
     285        return false; 
     286     } 
    241287?> 
  • advanced-xml-reader/trunk/readme.txt

    r465347 r486503  
    22Contributors: RaymondDesign 
    33Donate link: http://dev.raymonddesign.nl/donate/ 
    4 Tags: xml, reader, post, page 
     4Tags: xml, reader, curl, post, page, xmlreader 
    55Requires at least: 2.5 
    6 Tested up to: 3.2.1 
    7 Stable tag: 0.3.3 
     6Tested up to: 3.3.1 
     7Stable tag: 0.3.4 
    88 
    99Use the content of every XML file in your posts. Simply use every xml tag in a post. 
     
    19191. Install the plugin using the build-in plugin installer or upload the folder to the `/wp-content/plugins/` directory 
    20202. Go to `Settings > Advanced XML` and fill in your xml file url 
    21 3. Now you can use the plugin, insert a tag in a post using `[advanced-xml:tagname]` 
     213. Now you can use the plugin, insert a tag in a post using `[advanced-xml tag="tagname"]` 
    2222 
    2323== Frequently Asked Questions == 
     
    5858* Now using the Wordpress HTTP API instead of cURL. cURL isn't necessary anymore. 
    5959 
     60= 0.3.4 =  
     61* Now using the Wordpress Shortcode. New format for adding xml to your post: `[advanced-xml tag="tagname"]`. Old format still exists, but is deprecated. 
     62 
    6063== Upgrade Notice == 
    6164 
     
    8083= 0.3.3 = 
    8184* Now using the Wordpress HTTP API instead of cURL. cURL isn't necessary anymore. Please update when you do not want to use cURL. 
     85 
     86= 0.3.4 = 
     87* Now using native Wordpress Shortcodes, it's strongly recommended to update. 
Note: See TracChangeset for help on using the changeset viewer.