Exemple #1
0
   /**
    * Apply code from Cli
    */
   public static function cli()
   {
       $formats = 'odtx|tei|html';
       array_shift($_SERVER['argv']);
       // shift first arg, the script filepath
       if (!count($_SERVER['argv'])) {
           exit('
   usage    : php -f Odt.php $formats ? src.odt
   format?  : optional dest format, default tei, others may be odtx, html
   src.odt  : glob patterns are allowed, but in quotes, to not be expanded by shell "folder/*.odt"
 ');
       }
       $format = "tei";
       while ($arg = array_shift($_SERVER['argv'])) {
           if ($arg[0] == '-') {
               $format = substr($arg, 1);
           } else {
               if (preg_match("/^({$formats})\$/", $arg)) {
                   $format = $arg;
               } else {
                   if (!isset($srcGlob)) {
                       $srcGlob = $arg;
                   }
               }
           }
           /*
           $destdir=array_shift($_SERVER['argv']);
           if (!$destdir) $destdir='';
           $destdir=rtrim($destdir, '/').'/';
           if (!file_exists($destdir)) mkdir($destdir, 0775, true);
           */
       }
       $ext = ".{$format}";
       if ($ext == '.tei') {
           $ext = ".xml";
       }
       $count = 0;
       foreach (glob($srcGlob) as $srcfile) {
           $count++;
           $destfile = dirname($srcfile) . '/' . basename($srcfile, ".odt") . $ext;
           _log("{$count}. {$srcfile} > {$destfile}");
           if (file_exists($destfile)) {
               _log("  {$destfile} already exists, it will not be overwritten");
               continue;
           }
           $odt = new Odette_Odt2tei($srcfile);
           $odt->save($destfile, $format);
       }
   }