Other Script to convert old Smilies XML format to New one

#1
Really simple script, nothing special here, just a quick hack to convert Smilies XML files I find around this site in an older format to a newer one that works.

Example Old Format:
Code:
<smilies_export>
  <smilie_categories/>
  <smilies>
    <smilie title="Android" display_order="1" display_in_editor="1">
      <image_url>styles/default/xenforo/xenforo-extended-sprite.png</image_url>
      <sprite_params h="18" w="18" x="-80" y="0"/>
      <smilie_text>:android:</smilie_text>
    </smilie>
    <smilie title="Angelic" display_order="1" display_in_editor="1">
      <image_url>styles/default/xenforo/xenforo-extended-sprite.png</image_url>
      <sprite_params h="18" w="18" x="0" y="-209"/>
      <smilie_text>:angelic:</smilie_text>
After Script Runs:
Code:
<smilies>
  <smilie y="0" x="-80" h="18" w="18" sprite_mode="1">
    <title><![CDATA[Android]]></title>
    <image_url><![CDATA[styles/default/xenforo/xenforo-extended-sprite.png]]></image_url>
    <smilie_text><![CDATA[:android:]]></smilie_text>
  </smilie>
  <smilie y="-209" x="0" h="18" w="18" sprite_mode="1">
    <title><![CDATA[Angelic]]></title>
    <image_url><![CDATA[styles/default/xenforo/xenforo-extended-sprite.png]]></image_url>
    <smilie_text><![CDATA[:angelic:]]></smilie_text>
Source Code:
PHP:
<?php
// Grab xml2array.php from http://www.bin-co.com/php/scripts/xml2array/
//   or https://gist.github.com/detain/a168ef3c4d57880cd3e0
require_once(dirname(__FILE__) . '/xml2array.php');
$xml = trim(file_get_contents('smilies-xenforo_extended.xml'));
$arr = xml2array($xml, 1, 'attribute');
$sar = $arr['smilies_export']['smilies']['smilie'];
echo '<?xml version="1.0" encoding="utf-8"?>
<smilies>
';
foreach ($sar as $odx => $smilie)
{
        $smilie_text = array();
        if (sizeof($smilie['smilie_text']) > 1)
        {
                foreach ($smilie['smilie_text'] as $idx => $sdata)
                {
                        $smilie_text[] = $sdata['value'];
                }
        }
        elseif (isset($smilie['smilie_text']['value']))
        {
                $smilie_text[] = $smilie['smilie_text']['value'];
        }
        echo '  <smilie y="'
        .$smilie['sprite_params']['attr']['y'].'" x="'
        .$smilie['sprite_params']['attr']['x'].'" h="'
        .$smilie['sprite_params']['attr']['h'].'" w="'
        .$smilie['sprite_params']['attr']['w'].'" sprite_mode="1">
    <title><![CDATA['.$smilie['attr']['title'].']]></title>
    <image_url><![CDATA['.$smilie['image_url']['value'].']]></image_url>
    <smilie_text><![CDATA['.implode("\n",$smilie_text).']]></smilie_text>
  </smilie>
';
}
echo '</smilies>
';
?>

*Note: No idea here if im really posting this in the right area or if this kind of stuff is wanted here..so feel free to correct me where i should be putting stuff like this.
 
Top