home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / pear-dh-compile-translationfile < prev    next >
Text File  |  2008-07-02  |  3KB  |  89 lines

  1. #!/usr/bin/php
  2.  
  3. <?php
  4. /**
  5.  * Script that can be used to compile xml-based language-files.
  6.  * 
  7.  * @version     $Id: pear-dh-compile-translationfile,v 1.1 2005/10/14 21:40:51 luckec Exp $
  8.  * @author      Carsten Lucke <luckec@php.net>
  9.  */
  10.  
  11. require_once 'Console/Getargs.php';
  12. require_once 'XML/Unserializer.php';
  13. $options = array(
  14.     'parseAttributes'   =>  false,
  15.     'attributesArray'   =>  false,
  16.     'keyAttribute'      => array('property' => 'id')
  17. );
  18.                 
  19.                 
  20. $config = array(
  21.     'outputdir' => array(
  22.         'short'     => 'd',
  23.         'min'       => 1,
  24.         'max'       => 1,
  25.         'desc'      => 'Directory where compiled files are saved. Defaults to the current working directory.',
  26.         'default'   => getcwd()
  27.     ),
  28.     
  29.     'verbose' => array(
  30.         'short'     => 'v',
  31.         'min'       => 0,
  32.         'max'       => 0,
  33.         'desc'      => 'Enable verbose mode.'
  34.     ),
  35.     
  36.     CONSOLE_GETARGS_PARAMS => array(
  37.         'min'       => 1,
  38.         'max'       => -1,
  39.         'desc'      => 'Input file(s)'
  40.     )
  41. );
  42.  
  43. $args = &Console_Getargs::factory($config);
  44. if (PEAR::isError($args) || is_null($args->getValue(CONSOLE_GETARGS_PARAMS))) {
  45.     $header = "Date_Holidays language-file compiler\n--\n".
  46.               'Usage: '.basename($_SERVER['SCRIPT_NAME'])." [options] filename(s)\n\n";
  47.     if (is_a($args, 'PEAR_Error') && $args->getCode() === CONSOLE_GETARGS_ERROR_USER) {
  48.         echo Console_Getargs::getHelp($config, $header, $args->getMessage())."\n";
  49.     } else {
  50.         echo Console_Getargs::getHelp($config, $header)."\n";
  51.     }
  52.     exit;
  53. }
  54.  
  55. $files = $args->getValue(CONSOLE_GETARGS_PARAMS);
  56. if (is_string($files)) {
  57.     $files = array($files);
  58. }
  59. $outputDir = $args->getValue('outputdir');
  60.  
  61.  
  62. foreach ($files as $file) {
  63.     
  64.     if (! file_exists($file)) {
  65.         die(sprintf('File not found: %s', $file) . "\n");
  66.     }
  67.     
  68.     $unserializer = &new XML_Unserializer($options);
  69.     $status = $unserializer->unserialize($file, true);    
  70.     if (PEAR::isError($status)) {
  71.         die('Error occurred: ' . $status->getMessage());
  72.     } else {
  73.         $content = $unserializer->getUnserializedData();
  74.         
  75.         $filename = $outputDir . DIRECTORY_SEPARATOR . basename($file, '.xml') . '.ser';
  76.         if ($fp = fopen($filename, 'w')) {
  77.             fwrite($fp, serialize($content));
  78.             fclose($fp);
  79.             if ($args->isDefined('v')) {
  80.                 echo 'Writing compiled data to: ' . $filename . "\n";
  81.             }
  82.         } else  {
  83.             die('Could not write compiled file' . "\n");
  84.         }
  85.     }
  86. }
  87.        
  88. ?>
  89.