diff options
Diffstat (limited to 'vendors/dokuwiki/lib/plugins/odt')
19 files changed, 2307 insertions, 0 deletions
diff --git a/vendors/dokuwiki/lib/plugins/odt/ChangeLog.txt b/vendors/dokuwiki/lib/plugins/odt/ChangeLog.txt new file mode 100644 index 000000000..4c9835a1d --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/ChangeLog.txt @@ -0,0 +1,255 @@ +2010-07-17  Aurélien Bompard <aurelien@bompard.org> + +	* action.php, syntax.php: Better handling of the cache system  The +	template used for the ODT export is now added in the page's +	dependencies, so the cached ODT page will not be used if the +	template has been updated. + +2010-05-24  Aurélien Bompard <aurelien@bompard.org> + +	* lang/ru/lang.php, lang/ru/settings.php: Add translation by Yuri +	Timofeev + +2010-05-12  Aurélien Bompard <aurelien@bompard.org> + +	* lang/zh/lang.php, lang/zh/settings.php: Add Chinese translation by +	lainme + +2010-04-04  Aurélien Bompard <aurelien@bompard.org> + +	* ChangeLog, ChangeLog.txt: Add .txt to the ChangeLog for our +	Windows-based friends + +2010-04-04  Aurélien Bompard <aurelien@bompard.org> + +	* ChangeLog: Cleanup changelog + +2010-04-04  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: Fix a small syntax error + +2010-04-04  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: Better tag replacement in the template ODT file + +2010-04-04  Aurélien Bompard <aurelien@bompard.org> + +	* README.txt, info.txt: Prepare for a new release + +2010-04-04  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: Add options to cut off a part of the ODT template +	In an ODT file, the only styles that will be saved are the styles +	which are applied to some content in the document. If you want to +	create an empty ODT document for this plugin, and still want to +	define styles which will be applied to the wiki content, you have to +	write some dummy text, apply the styles to this text, and surround +	the text in the DOKUWIKI-ODT-CUT-START and DOKUWIKI-ODT-CUT-STOP +	tags. This way, the styles will be retained in the ODT file, but the +	dummy text will be removed on export. + +2010-04-04  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: Better tag replacement in the template ODT file + +2010-04-04  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: Better tag replacement in the template ODT file + +2010-04-04  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: replace with unicode entities instead of HTML (not +	always defined) + +2009-08-15  Martin Braure de Calignon <braure@free.fr> + +	* syntax.php: Fix button link to export old revisions + +2009-07-02  Aurélien Bompard <aurelien@bompard.org> + +	* ChangeLog, info.txt: prepare for release + +2009-07-02  Aurélien Bompard <aurelien@bompard.org> + +	* ChangeLog, renderer.php: Fixes from Andy Webber (thanks !) + +2009-06-07  Aurélien Bompard <aurelien@bompard.org> + +	* ChangeLog, renderer.php: use $['savedir'] as suggested on the wiki +	page + +2009-06-07  Aurélien Bompard <aurelien@bompard.org> + +	* ChangeLog, info.txt: release + +2009-06-07  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: add patch by Korsani + +2009-06-07  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: typo + +2009-02-11  Aurélien Bompard <aurelien@bompard.org> + +	* info.txt, renderer.php: Make the renderer class a singleton  Only +	make a single instance of the renderer. This is needed for Dokuwiki +	>= rc2009-02-06. For details, see: +	http://bugs.splitbrain.org/index.php?do=details&task_id=1598 + +2009-02-09  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: Revert "Create zipper on-demand"  This reverts +	commit 5e746e84b62fb0fdcd5607d7f9abc636a7710e2e. + +2009-02-08  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: Create zipper on-demand + +2009-01-15  Aurélien Bompard <aurelien@bompard.org> + +	* ChangeLog, info.txt: prepare for new release + +2009-01-15  Aurélien Bompard <aurelien@bompard.org> + +	* ChangeLog, renderer.php: don't compress mimetype declaration + +2008-11-11  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: more safeguards. wiki:syntax now passes validators + +2008-09-28  Aurélien Bompard <aurelien@bompard.org> + +	* lang/ja/lang.php, lang/ja/settings.php: Add Japanese translation +	from Ikuo Obataya. Thanks ! + +2008-05-07  Aurélien Bompard <aurelien@bompard.org> + +	* ChangeLog, info.txt: new release + +2008-05-07  Aurélien Bompard <aurelien@bompard.org> + +	* ChangeLog: update ChangeLog + +2008-05-07  Aurélien Bompard <aurelien@bompard.org> + +	* lang/es/lang.php, lang/es/settings.php: complete spanish +	translation + +2008-05-07  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php, syntax.php: leftover from history cleaning + +2008-05-07  Aurélien Bompard <aurelien@bompard.org> + +	* lang/es/lang.php: spanish translation, 1st part + +2008-05-06  Aurélien Bompard <aurelien@bompard.org> + +	* ChangeLog: add changelog in changelog... + +2008-05-05  Aurélien Bompard <aurelien@bompard.org> + +	* ChangeLog: add ChangeLog (thanks to http://josefsson.org/git2cl/) + + +2008-05-05  Aurélien Bompard <aurelien@bompard.org> + +	* README.txt, info.txt: update metadata for new release + +2008-05-05  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: use new headers/caching system if available + +2008-04-22  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: choose appropriate ZipLib file + +2008-04-21  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: dokuwiki's future temp dir is data/tmp, not +	data/temp + +2008-04-08  Aurélien Bompard <aurelien@bompard.org> + +	* README.txt, TODO, TODO.txt, info.txt: ready for release + +2008-04-08  Aurélien Bompard <aurelien@bompard.org> + +	* lang/it/lang.php: add italian translation + +2008-04-07  Aurélien Bompard <aurelien@bompard.org> + +	* README.txt, TODO, info.txt: get ready for release + +2008-03-08  Aurélien Bompard <aurelien@bompard.org> + +	* .gitignore: ignore Makefile + +2008-03-06  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: fix quotes + +2008-03-06  root <root@shiva.c-s.fr> + +	* renderer.php: extract template before checking for the styles + +2008-03-04  Aurélien Bompard <aurelien@bompard.org> + +	* syntax.php: leftover + +2008-03-05  root <root@shiva.c-s.fr> + +	* syntax.php: Revert "leftover"  This reverts commit +	93d7c67d705f3a6a5847554b15384dc5a1a50de6. + +2008-03-05  root <root@shiva.c-s.fr> + +	* renderer.php: fix <code> tag in list items + +2008-03-04  Aurélien Bompard <aurelien@bompard.org> + +	* syntax.php: leftover + +2008-03-04  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: cleanup for patch + +2008-03-04  Aurélien Bompard <aurelien@bompard.org> + +	* README.txt, info.txt: even better doc + +2008-03-04  Aurélien Bompard <aurelien@bompard.org> + +	* README.txt: better doc + +2008-03-04  Aurélien Bompard <aurelien@bompard.org> + +	* README.txt: doc + +2008-03-03  Aurélien Bompard <aurelien@bompard.org> + +	* renderer.php: spit into the fields plugin + +2008-03-01  Aurélien Bompard <aurelien@bompard.org> + +	* TODO, renderer.php, styles.xml, syntax.php: closer to upstream + +2008-03-01  Aurélien Bompard <aurelien@bompard.org> + +	* TODO, admin.php, conf/default.php, conf/metadata.php, +	lang/de/lang.php, lang/en/lang.php, lang/en/settings.php, +	lang/fr/lang.php, lang/fr/settings.php, renderer.php: niiice :) + +2008-02-29  Aurélien Bompard <aurelien@bompard.org> + +	* admin.php, lang/en/lang.php: bla + +2008-02-28  Aurélien Bompard <aurelien@bompard.org> + +	* admin.php, lang/en/lang.php: niice + +2008-05-07  Aurélien Bompard <aurelien@bompard.org> + +	* initial commit from existing repo + diff --git a/vendors/dokuwiki/lib/plugins/odt/README.txt b/vendors/dokuwiki/lib/plugins/odt/README.txt new file mode 100644 index 000000000..3d4c97f8d --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/README.txt @@ -0,0 +1,16 @@ +====== Dokuwiki ODT plugin ====== + +This plugin lets you export wiki pages to ODT, the OpenDocument Text format as +used by many applications, included OpenOffice.org + +Further documentation on the OpenDocument format is available here : +http://en.wikipedia.org/wiki/OpenDocument + + +===== Official documentation ===== + +For installation and usage documentation, please refer to  +http://www.dokuwiki.org/plugin:odt + +This version of the plugin works with Dokuwiki 2007-06-26 and later. + diff --git a/vendors/dokuwiki/lib/plugins/odt/ZipLib.class.php b/vendors/dokuwiki/lib/plugins/odt/ZipLib.class.php new file mode 100644 index 000000000..20e74a0e8 --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/ZipLib.class.php @@ -0,0 +1,391 @@ +<?php + +/** + * @author     bouchon + * @link       http://dev.maxg.info + * @link       http://forum.maxg.info + * + *  Modified for Dokuwiki + *  @author    Christopher Smith <chris@jalakai.co.uk> + */ +class ZipLib +{ + + var $datasec, $ctrl_dir = array(); + var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; + var $old_offset = 0; var $dirs = Array("."); + + function get_List($zip_name) + { +   $zip = @fopen($zip_name, 'rb'); +   if(!$zip) return(0); +   $centd = $this->ReadCentralDir($zip,$zip_name); + +    @rewind($zip); +    @fseek($zip, $centd['offset']); + +   for ($i=0; $i<$centd['entries']; $i++) +   { +    $header = $this->ReadCentralFileHeaders($zip); +    $header['index'] = $i;$info['filename'] = $header['filename']; +    $info['stored_filename'] = $header['stored_filename']; +    $info['size'] = $header['size'];$info['compressed_size']=$header['compressed_size']; +    $info['crc'] = strtoupper(dechex( $header['crc'] )); +    $info['mtime'] = $header['mtime']; $info['comment'] = $header['comment']; +    $info['folder'] = ($header['external']==0x41FF0010||$header['external']==16)?1:0; +    $info['index'] = $header['index'];$info['status'] = $header['status']; +    $ret[]=$info; unset($header); +   } +  return $ret; + } + + function Add($files,$compact) + { +  if(!is_array($files[0])) $files=Array($files); + +  for($i=0;$files[$i];$i++){ +    $fn = $files[$i]; +    if(!in_Array(dirname($fn[0]),$this->dirs)) +     $this->add_Dir(dirname($fn[0])); +    if(basename($fn[0])) +     $ret[basename($fn[0])]=$this->add_File($fn[1],$fn[0],$compact); +  } +  return $ret; + } + + /** +  * Zips recursively the $folder directory, from the $basedir directory +  */ + function Compress($folder, $basedir=null, $parent=null) + { +  $full_path = $basedir."/".$parent.$folder; +  $zip_path = $parent.$folder; +  if ($zip_path) { +   $zip_path .= "/"; +   $this->add_dir($zip_path); +  } +  $dir = opendir($full_path); +  while (false !== ($filename = readdir($dir))) { +   if ($filename != "." && $filename != "..") { +    if (is_dir($full_path."/".$filename)) { +     $this->Compress($filename, $basedir, $zip_path); +    } else { +     $content = join('', file($full_path.'/'.$filename)); +     $this->add_File($content, $zip_path.$filename); +    } +   } +  } + } + + /** +  * Returns the Zip file +  */ + function get_file() + { +   $data = implode('', $this -> datasec); +   $ctrldir = implode('', $this -> ctrl_dir); + +   return $data . $ctrldir . $this -> eof_ctrl_dir . +    pack('v', sizeof($this -> ctrl_dir)).pack('v', sizeof($this -> ctrl_dir)). +    pack('V', strlen($ctrldir)) . pack('V', strlen($data)) . "\x00\x00"; + } + + function add_dir($name)  + {  +   $name = str_replace("\\", "/", $name);  +   $fr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00";  + +   $fr .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) );  +   $fr .= pack("v", 0 ).$name.pack("V", 0).pack("V", 0).pack("V", 0);  +   $this -> datasec[] = $fr; + +   $new_offset = strlen(implode("", $this->datasec));  + +   $cdrec = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00";  +   $cdrec .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) );  +   $cdrec .= pack("v", 0 ).pack("v", 0 ).pack("v", 0 ).pack("v", 0 );  +   $ext = "\xff\xff\xff\xff";  +   $cdrec .= pack("V", 16 ).pack("V", $this -> old_offset ).$name;  + +   $this -> ctrl_dir[] = $cdrec;  +   $this -> old_offset = $new_offset;  +   $this -> dirs[] = $name; + } + + /** +  * Add a file named $name from a string $data +  */ + function add_File($data, $name, $compact = 1) + { +   $name     = str_replace('\\', '/', $name); +   $dtime    = dechex($this->DosTime()); + +   $hexdtime = '\x' . $dtime[6] . $dtime[7].'\x'.$dtime[4] . $dtime[5] +     . '\x' . $dtime[2] . $dtime[3].'\x'.$dtime[0].$dtime[1]; +   eval('$hexdtime = "' . $hexdtime . '";'); + +   if($compact) +   $fr = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00".$hexdtime; +   else $fr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00".$hexdtime; +   $unc_len = strlen($data); $crc = crc32($data); + +   if($compact){ +     $zdata = gzcompress($data); $c_len = strlen($zdata); +     $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); +   }else{ +     $zdata = $data; +   } +   $c_len=strlen($zdata); +   $fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len); +   $fr .= pack('v', strlen($name)).pack('v', 0).$name.$zdata; + +   $fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len); + +   $this -> datasec[] = $fr; +   $new_offset        = strlen(implode('', $this->datasec)); +   if($compact) +        $cdrec = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00"; +   else $cdrec = "\x50\x4b\x01\x02\x14\x00\x0a\x00\x00\x00\x00\x00"; +   $cdrec .= $hexdtime.pack('V', $crc).pack('V', $c_len).pack('V', $unc_len); +   $cdrec .= pack('v', strlen($name) ).pack('v', 0 ).pack('v', 0 ); +   $cdrec .= pack('v', 0 ).pack('v', 0 ).pack('V', 32 ); +   $cdrec .= pack('V', $this -> old_offset ); + +   $this -> old_offset = $new_offset; +   $cdrec .= $name; +   $this -> ctrl_dir[] = $cdrec; +   return true; + } + + function DosTime() { +   $timearray = getdate(); +   if ($timearray['year'] < 1980) { +     $timearray['year'] = 1980; $timearray['mon'] = 1; +     $timearray['mday'] = 1; $timearray['hours'] = 0; +     $timearray['minutes'] = 0; $timearray['seconds'] = 0; +   } +   return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) |     ($timearray['mday'] << 16) | ($timearray['hours'] << 11) |  +    ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1); + } + + /** +  * Extract a zip file $zn to the $to directory +  */ + function Extract ( $zn, $to, $index = Array(-1) ) + { +   if(!@is_dir($to)) @mkdir($to,0777); +   $ok = 0; $zip = @fopen($zn,'rb'); +   if(!$zip) return(-1); +   $cdir = $this->ReadCentralDir($zip,$zn); +   $pos_entry = $cdir['offset']; + +   if(!is_array($index)){ $index = array($index);  } +   for($i=0; isset($index[$i]);$i++){ +     if(intval($index[$i])!=$index[$i]||$index[$i]>$cdir['entries']) +      return(-1); +   } + +   for ($i=0; $i<$cdir['entries']; $i++) +   { +     @fseek($zip, $pos_entry); +     $header = $this->ReadCentralFileHeaders($zip); +     $header['index'] = $i; $pos_entry = ftell($zip); +     @rewind($zip); fseek($zip, $header['offset']); +     if(in_array("-1",$index)||in_array($i,$index)) +      $stat[$header['filename']]=$this->ExtractFile($header, $to, $zip); +       +   } +   fclose($zip); +   return $stat; + } + +  function ReadFileHeader($zip, $header) +  { +    $binary_data = fread($zip, 30); +    $data = unpack('vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data); + +    $header['filename'] = fread($zip, $data['filename_len']); +    if ($data['extra_len'] != 0) { +      $header['extra'] = fread($zip, $data['extra_len']); +    } else { $header['extra'] = ''; } + +    $header['compression'] = $data['compression']; +    $header['flag'] = $data['flag']; +    $header['mdate'] = $data['mdate'];$header['mtime'] = $data['mtime']; +    if (($header['flag'] & 8) != 8) { // Purpose bit flag bit 3 not set, overwrite the central header values +     foreach (array('size','compressed_size','crc') as $hd) { +      $header[$hd] = $data[$hd]; +     } +    } + +    if ($header['mdate'] && $header['mtime']){ +     $hour=($header['mtime']&0xF800)>>11;$minute=($header['mtime']&0x07E0)>>5; +     $seconde=($header['mtime']&0x001F)*2;$year=(($header['mdate']&0xFE00)>>9)+1980; +     $month=($header['mdate']&0x01E0)>>5;$day=$header['mdate']&0x001F; +     $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year); +    }else{$header['mtime'] = time();} + +    $header['stored_filename'] = $header['filename']; +    $header['status'] = "ok"; +    return $header; +  } + + function ReadCentralFileHeaders($zip){ +    $binary_data = fread($zip, 46); +    $header = unpack('vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $binary_data); + +    if ($header['filename_len'] != 0) +      $header['filename'] = fread($zip,$header['filename_len']); +    else $header['filename'] = ''; + +    if ($header['extra_len'] != 0) +      $header['extra'] = fread($zip, $header['extra_len']); +    else $header['extra'] = ''; + +    if ($header['comment_len'] != 0) +      $header['comment'] = fread($zip, $header['comment_len']); +    else $header['comment'] = ''; + +    if ($header['mdate'] && $header['mtime']) +    { +      $hour = ($header['mtime'] & 0xF800) >> 11; +      $minute = ($header['mtime'] & 0x07E0) >> 5; +      $seconde = ($header['mtime'] & 0x001F)*2; +      $year = (($header['mdate'] & 0xFE00) >> 9) + 1980; +      $month = ($header['mdate'] & 0x01E0) >> 5; +      $day = $header['mdate'] & 0x001F; +      $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year); +    } else { +      $header['mtime'] = time(); +    } +    $header['stored_filename'] = $header['filename']; +    $header['status'] = 'ok'; +    if (substr($header['filename'], -1) == '/') +      $header['external'] = 0x41FF0010; +    return $header; + } + + function ReadCentralDir($zip,$zip_name) + { +  $size = filesize($zip_name); +  if ($size < 277) $maximum_size = $size; +  else $maximum_size=277; + +  @fseek($zip, $size-$maximum_size); +  $pos = ftell($zip); $bytes = 0x00000000; + +  while ($pos < $size) +  { +    $byte = @fread($zip, 1); +    $bytes=(($bytes << 8) & 0xFFFFFFFF) | Ord($byte); +    if ($bytes == 0x504b0506){ $pos++; break; } $pos++; +  } + + $data=unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', +        fread($zip, 18)); + +  if ($data['comment_size'] != 0) +    $centd['comment'] = fread($zip, $data['comment_size']); +    else $centd['comment'] = ''; $centd['entries'] = $data['entries']; +  $centd['disk_entries'] = $data['disk_entries']; +  $centd['offset'] = $data['offset'];$centd['disk_start'] = $data['disk_start']; +  $centd['size'] = $data['size'];  $centd['disk'] = $data['disk']; +  return $centd; + } + + function ExtractFile($header,$to,$zip) + { +   $header = $this->readfileheader($zip, $header); + +   if(substr($to,-1)!="/") $to.="/"; +   if(substr($header['filename'],-1)=="/") +   { +//    @mkdir($to.$header['filename']);   --CS +    $this->_mkdir($to.$header['filename']);  //-- CS +    return +2; +   } + +//   $pth = explode("/",dirname($header['filename'])); +//   for($i=0,$tmp="";isset($pth[$i]);$i++){ +//     if(!$pth[$i]) continue; +//     if(!is_dir($to.$tmp.$pth[$i])) @mkdir($to.$pth[$i],0777); +//     $tmp.=$pth[$i]."/"; +//   } +  if (!$this->_mkdir($to.dirname($header['filename']))) return (-1);   //--CS + +  if (!array_key_exists("external", $header) || (!($header['external']==0x41FF0010)&&!($header['external']==16))) +  { +   if ($header['compression']==0) +   { +    $fp = @fopen($to.$header['filename'], 'wb'); +    if(!$fp) return(-1); +    $size = $header['compressed_size']; + +    while ($size != 0) +    { +      $read_size = ($size < 2048 ? $size : 2048); +      $buffer = fread($zip, $read_size); +      $binary_data = pack('a'.$read_size, $buffer); +      @fwrite($fp, $binary_data, $read_size); +      $size -= $read_size; +    } +    fclose($fp); +    touch($to.$header['filename'], $header['mtime']); + +  }else{ +   if (!is_dir(dirname($to.$header['filename']))) $this->_mkdir(dirname($to.$header['filename']));  //-CS +   $fp = fopen($to.$header['filename'].'.gz','wb'); +   if(!$fp) return(-1); +   $binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($header['compression']), +     Chr(0x00), time(), Chr(0x00), Chr(3)); + +   fwrite($fp, $binary_data, 10); +   $size = $header['compressed_size']; + +   while ($size != 0) +   { +     $read_size = ($size < 1024 ? $size : 1024); +     $buffer = fread($zip, $read_size); +     $binary_data = pack('a'.$read_size, $buffer); +     @fwrite($fp, $binary_data, $read_size); +     $size -= $read_size; +   } + +   $binary_data = pack('VV', $header['crc'], $header['size']); +   fwrite($fp, $binary_data,8); fclose($fp); + +   $gzp = @gzopen($to.$header['filename'].'.gz','rb'); +    if(!$gzp){ +       @gzclose($gzp); @unlink($to.$header['filename']); +       die("Archive is compressed whereas ZLIB is not enabled."); +    } +   $fp = @fopen($to.$header['filename'],'wb'); +   if(!$fp) return(-1); +   $size = $header['size']; + +   while ($size != 0) +   { +     $read_size = ($size < 2048 ? $size : 2048); +     $buffer = gzread($gzp, $read_size); +     $binary_data = pack('a'.$read_size, $buffer); +     @fwrite($fp, $binary_data, $read_size); +     $size -= $read_size; +   } +   fclose($fp); gzclose($gzp); + +   touch($to.$header['filename'], $header['mtime']); +   @unlink($to.$header['filename'].'.gz'); + +  }} +  return true; + } +  + //--CS start + // centralize mkdir calls and use dokuwiki io functions   + function _mkdir($d) { +    return io_mkdir_p($d); // --AB +    //return ap_mkdir($d);   + } + //--CS end +} + diff --git a/vendors/dokuwiki/lib/plugins/odt/action.php b/vendors/dokuwiki/lib/plugins/odt/action.php new file mode 100644 index 000000000..0ca861518 --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/action.php @@ -0,0 +1,41 @@ +<?php +/** + * ODT Plugin: Exports to ODT + * + * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author     Aurelien Bompard <aurelien@bompard.org> + */ +// must be run within Dokuwiki +if(!defined('DOKU_INC')) die(); + +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'action.php'); + +/** + * Add the template as a page dependency for the caching system + */ +class action_plugin_odt extends DokuWiki_Action_Plugin { + +    function register($controller) { +        $controller->register_hook('PARSER_CACHE_USE','BEFORE', $this, 'handle_cache_prepare'); +    } + +    function handle_cache_prepare(&$event, $param) { +        global $conf, $ID; +        $cache =& $event->data; +        // only the ODT rendering mode needs caching tweaks +        if ($cache->mode != "odt") return; +        $odt_meta = p_get_metadata($ID, 'relation odt'); +        $template_name = $odt_meta["template"]; +        if (!$template_name) { +            return; +        } +        $template_path = $conf['mediadir'].'/'.$this->getConf("tpl_dir")."/".$template_name; +        if (file_exists($template_path)) { +            $cache->depends['files'][] = $template_path; +        } +    } + +} + +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/vendors/dokuwiki/lib/plugins/odt/conf/default.php b/vendors/dokuwiki/lib/plugins/odt/conf/default.php new file mode 100644 index 000000000..d69966874 --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/conf/default.php @@ -0,0 +1,7 @@ +<?php +/** + * @author Aurelien Bompard <aurelien@bompard.org> + */ + +// Directory of the templates in the media manager +$conf['tpl_dir'] = 'odt'; diff --git a/vendors/dokuwiki/lib/plugins/odt/conf/metadata.php b/vendors/dokuwiki/lib/plugins/odt/conf/metadata.php new file mode 100644 index 000000000..7614f3c73 --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/conf/metadata.php @@ -0,0 +1,8 @@ +<?php +/** + * Options for the odt plugin + * + * @author Andreas Gohr <andi@splitbrain.org> + */ + +$meta['tpl_dir']   = array('string'); diff --git a/vendors/dokuwiki/lib/plugins/odt/info.txt b/vendors/dokuwiki/lib/plugins/odt/info.txt new file mode 100644 index 000000000..3006078be --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/info.txt @@ -0,0 +1,8 @@ +# General Plugin Info do not edit + +author Andreas Gohr, Aurelien Bompard +email  andi@splitbrain.org, aurelien@bompard.org +date   2010-07-24 +name   Open Document Plugin +desc   Export the current Wiki page to a OpenOffice ODT file +url    http://www.dokuwiki.org/plugin:odt diff --git a/vendors/dokuwiki/lib/plugins/odt/lang/de/lang.php b/vendors/dokuwiki/lib/plugins/odt/lang/de/lang.php new file mode 100644 index 000000000..607ff99e3 --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/lang/de/lang.php @@ -0,0 +1,9 @@ +<?php + +// settings must be present and set appropriately for the language +$lang['encoding']   = 'utf-8'; +$lang['direction']  = 'ltr'; +        +// export button +$lang['view'] = 'Ins Open-Document-Format exportieren'; + diff --git a/vendors/dokuwiki/lib/plugins/odt/lang/en/lang.php b/vendors/dokuwiki/lib/plugins/odt/lang/en/lang.php new file mode 100644 index 000000000..4a6d50985 --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/lang/en/lang.php @@ -0,0 +1,12 @@ +<?php + +// settings must be present and set appropriately for the language +$lang['encoding']   = 'utf-8'; +$lang['direction']  = 'ltr'; +        +// export button +$lang['view'] = 'Export page to Open Document format'; + +// template not found in the directory +$lang['tpl_not_found'] = 'WARNING : the ODT template "%s" was not found in the templates directory "%s". Using the default template.'; + diff --git a/vendors/dokuwiki/lib/plugins/odt/lang/es/lang.php b/vendors/dokuwiki/lib/plugins/odt/lang/es/lang.php new file mode 100644 index 000000000..f86a80426 --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/lang/es/lang.php @@ -0,0 +1,19 @@ +<?php +/** + * Spanish language file + * + * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author     Rodolfo Pilas <rodolfo@pilas.net> + */ + + +// settings must be present and set appropriately for the language +$lang['encoding']   = 'utf-8'; +$lang['direction']  = 'ltr'; +        +// export button +$lang['view'] = 'Exportar página en formato Open Document'; + +// template not found in the directory +$lang['tpl_not_found'] = 'ATENCION : la plantilla ODT "%s" no ha sido encontrada en el directorio de plantillas "%s". Se usa la plantilla por defecto.'; + diff --git a/vendors/dokuwiki/lib/plugins/odt/lang/fr/lang.php b/vendors/dokuwiki/lib/plugins/odt/lang/fr/lang.php new file mode 100644 index 000000000..4290573ec --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/lang/fr/lang.php @@ -0,0 +1,12 @@ +<?php + +// settings must be present and set appropriately for the language +$lang['encoding']   = 'utf-8'; +$lang['direction']  = 'ltr'; +        +// export button +$lang['view'] = 'Exporter la page au format Open Document'; + +// template not found in the directory +$lang['tpl_not_found'] = 'ATTENTION: le modèle ODT "%s" n\'a pas été trouvé dans le répertoire de modèles "%s". L\'export est réalisé avec le modèle par défaut.'; + diff --git a/vendors/dokuwiki/lib/plugins/odt/lang/it/lang.php b/vendors/dokuwiki/lib/plugins/odt/lang/it/lang.php new file mode 100644 index 000000000..45e171be5 --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/lang/it/lang.php @@ -0,0 +1,7 @@ +<?php +/** + * Options for odt plugin + * @author Diego Pierotto <ita.translations@tiscali.it> + */ + +$lang['view'] = 'Esporta pagina in formato Open Document'; diff --git a/vendors/dokuwiki/lib/plugins/odt/lang/ja/lang.php b/vendors/dokuwiki/lib/plugins/odt/lang/ja/lang.php new file mode 100644 index 000000000..6df1be2d0 --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/lang/ja/lang.php @@ -0,0 +1,12 @@ +<?php + +// settings must be present and set appropriately for the language +$lang['encoding']   = 'utf-8'; +$lang['direction']  = 'ltr'; +        +// export button +$lang['view'] = 'このページをOpen Documentフォーマットで保存'; + +// template not found in the directory +$lang['tpl_not_found'] = '注意:ODTテンプレート "%s" はテンプレートディレクトリ "%s"の中にありませんでした。デフォルトのテンプレートを使用します。'; + diff --git a/vendors/dokuwiki/lib/plugins/odt/lang/ru/lang.php b/vendors/dokuwiki/lib/plugins/odt/lang/ru/lang.php new file mode 100644 index 000000000..9eaaf2c43 --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/lang/ru/lang.php @@ -0,0 +1,12 @@ +<?php + +// settings must be present and set appropriately for the language +$lang['encoding']   = 'utf-8'; +$lang['direction']  = 'ltr'; +        +// export button +$lang['view'] = 'Экспорт страницы в формат Open Document'; + +// template not found in the directory +$lang['tpl_not_found'] = 'ВНИМАНИЕ: ODT шаблон "%s" не найден в каталоге для шаблонов "%s". Используется шаблон по умолчанию.'; + diff --git a/vendors/dokuwiki/lib/plugins/odt/lang/zh/lang.php b/vendors/dokuwiki/lib/plugins/odt/lang/zh/lang.php new file mode 100644 index 000000000..808b248e0 --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/lang/zh/lang.php @@ -0,0 +1,12 @@ +<?php + +// settings must be present and set appropriately for the language +$lang['encoding']   = 'utf-8'; +$lang['direction']  = 'ltr'; +        +// export button +$lang['view'] = '将页面导出为开放文档格式'; + +// template not found in the directory +$lang['tpl_not_found'] = '警告:模板目录中没有找到ODT模板 “%s”。; + diff --git a/vendors/dokuwiki/lib/plugins/odt/odt.png b/vendors/dokuwiki/lib/plugins/odt/odt.png Binary files differnew file mode 100644 index 000000000..4ea3cec8f --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/odt.png diff --git a/vendors/dokuwiki/lib/plugins/odt/renderer.php b/vendors/dokuwiki/lib/plugins/odt/renderer.php new file mode 100644 index 000000000..5525e4926 --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/renderer.php @@ -0,0 +1,1232 @@ +<?php +/** + * ODT Plugin: Exports to ODT + * + * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Andreas Gohr <andi@splitbrain.org> + * @author Aurelien Bompard <aurelien@bompard.org> + */ +// must be run within Dokuwiki +if(!defined('DOKU_INC')) die(); + +require_once DOKU_INC.'inc/parser/renderer.php'; + +// ZipLib.class.php +$dw_version = preg_replace('/[^\d]/', '', getversion()); +if (version_compare($dw_version, "20070626") and  +    version_compare(PHP_VERSION,'5.0.0','>')) { +    // If strictly newer than 2007-06-26 and use PHP5, fixes to ZipLib are +    // included in Dokuwiki's ZipLib +    require_once DOKU_INC.'inc/ZipLib.class.php'; +} else { // for DW up to 2007-06-26, we need the patched version +    require_once 'ZipLib.class.php'; +} + +/** + * The Renderer + */ +class renderer_plugin_odt extends Doku_Renderer { +    var $ZIP = null; +    var $meta; +    var $store = ''; +    var $footnotes = array(); +    var $manifest  = array(); +    var $headers = array(); +    var $template = ""; +    var $fields = array(); +    var $in_list_item = false; +    var $in_paragraph = false; +    // Automatic styles. Will always be added to content.xml and styles.xml +    var $autostyles = array( +        "pm1"=>' +            <style:page-layout style:name="pm1"> +                <style:page-layout-properties fo:page-width="21cm" fo:page-height="29.7cm" style:num-format="1" style:print-orientation="portrait" fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm" style:writing-mode="lr-tb" style:footnote-max-height="0cm"> +                    <style:footnote-sep style:width="0.018cm" style:distance-before-sep="0.1cm" style:distance-after-sep="0.1cm" style:adjustment="left" style:rel-width="25%" style:color="#000000"/> +                </style:page-layout-properties> +                <style:header-style/> +                <style:footer-style/> +            </style:page-layout>', +        "sub"=>' +            <style:style style:name="sub" style:family="text"> +                <style:text-properties style:text-position="-33% 80%"/> +            </style:style>', +        "sup"=>' +            <style:style style:name="sup" style:family="text"> +                <style:text-properties style:text-position="33% 80%"/> +            </style:style>', +        "del"=>' +            <style:style style:name="del" style:family="text"> +                <style:text-properties style:text-line-through-style="solid"/> +            </style:style>', +        "underline"=>' +            <style:style style:name="underline" style:family="text"> +              <style:text-properties style:text-underline-style="solid" +                 style:text-underline-width="auto" style:text-underline-color="font-color"/> +            </style:style>', +        "media"=>' +            <style:style style:name="media" style:family="graphic" style:parent-style-name="Graphics"> +                <style:graphic-properties style:run-through="foreground" style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" +                   style:wrap-contour="false" style:vertical-pos="top" style:vertical-rel="baseline" style:horizontal-pos="left" +                   style:horizontal-rel="paragraph"/> +            </style:style>', +        "medialeft"=>' +            <style:style style:name="medialeft" style:family="graphic" style:parent-style-name="Graphics"> +              <style:graphic-properties style:run-through="foreground" style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" +                 style:wrap-contour="false" style:horizontal-pos="left" style:horizontal-rel="paragraph"/> +            </style:style>', +        "mediaright"=>' +            <style:style style:name="mediaright" style:family="graphic" style:parent-style-name="Graphics"> +              <style:graphic-properties style:run-through="foreground" style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" +                 style:wrap-contour="false" style:horizontal-pos="right" style:horizontal-rel="paragraph"/> +            </style:style>', +        "mediacenter"=>' +            <style:style style:name="mediacenter" style:family="graphic" style:parent-style-name="Graphics"> +               <style:graphic-properties style:run-through="foreground" style:wrap="none" style:horizontal-pos="center" +                  style:horizontal-rel="paragraph"/> +            </style:style>', +        "tablealigncenter"=>' +            <style:style style:name="tablealigncenter" style:family="paragraph" style:parent-style-name="Table_20_Contents"> +                <style:paragraph-properties fo:text-align="center"/> +            </style:style>', +        "tablealignright"=>' +            <style:style style:name="tablealignright" style:family="paragraph" style:parent-style-name="Table_20_Contents"> +                <style:paragraph-properties fo:text-align="end"/> +            </style:style>', +        "tablealignleft"=>' +            <style:style style:name="tablealignleft" style:family="paragraph" style:parent-style-name="Table_20_Contents"> +                <style:paragraph-properties fo:text-align="left"/> +            </style:style>', +        "tableheader"=>' +            <style:style style:name="tableheader" style:family="table-cell"> +                <style:table-cell-properties fo:padding="0.05cm" fo:border-left="0.002cm solid #000000" fo:border-right="0.002cm solid #000000" fo:border-top="0.002cm solid #000000" fo:border-bottom="0.002cm solid #000000"/> +            </style:style>', +        "tablecell"=>' +            <style:style style:name="tablecell" style:family="table-cell"> +                <style:table-cell-properties fo:padding="0.05cm" fo:border-left="0.002cm solid #000000" fo:border-right="0.002cm solid #000000" fo:border-top="0.002cm solid #000000" fo:border-bottom="0.002cm solid #000000"/> +            </style:style>', +        "legendcenter"=>' +            <style:style style:name="legendcenter" style:family="paragraph" style:parent-style-name="Illustration"> +                <style:paragraph-properties fo:text-align="center"/> +            </style:style>', +    ); +    // Regular styles. May not be present if in template mode, in which case they will be added to styles.xml +    var $styles = array( +        "Source_20_Text"=>' +            <style:style style:name="Source_20_Text" style:display-name="Source Text" style:family="text"> +                <style:text-properties style:font-name="Bitstream Vera Sans Mono" style:font-name-asian="Bitstream Vera Sans Mono" style:font-name-complex="Bitstream Vera Sans Mono"/> +            </style:style>', +        "Preformatted_20_Text"=>' +            <style:style style:name="Preformatted_20_Text" style:display-name="Preformatted Text" style:family="paragraph" style:parent-style-name="Standard" style:class="html"> +                <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0cm"/> +                <style:text-properties style:font-name="Bitstream Vera Sans Mono" style:font-name-asian="Bitstream Vera Sans Mono" style:font-name-complex="Bitstream Vera Sans Mono"/> +            </style:style>', +        "Horizontal_20_Line"=>' +            <style:style style:name="Horizontal_20_Line" style:display-name="Horizontal Line" style:family="paragraph" style:parent-style-name="Standard" style:next-style-name="Text_20_body" style:class="html"> +                <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0.5cm" style:border-line-width-bottom="0.002cm 0.035cm 0.002cm" fo:padding="0cm" fo:border-left="none" fo:border-right="none" fo:border-top="none" fo:border-bottom="0.04cm double #808080" text:number-lines="false" text:line-number="0" style:join-border="false"/> +                <style:text-properties fo:font-size="6pt" style:font-size-asian="6pt" style:font-size-complex="6pt"/> +            </style:style>', +        "Footnote"=>' +            <style:style style:name="Footnote" style:family="paragraph" style:parent-style-name="Standard" style:class="extra"> +                <style:paragraph-properties fo:margin-left="0.5cm" fo:margin-right="0cm" fo:text-indent="-0.5cm" style:auto-text-indent="false" text:number-lines="false" text:line-number="0"/> +                <style:text-properties fo:font-size="10pt" style:font-size-asian="10pt" style:font-size-complex="10pt"/> +            </style:style>', +        "Emphasis"=>' +            <style:style style:name="Emphasis" style:family="text"> +                <style:text-properties fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic"/> +            </style:style>', +        "Strong_20_Emphasis"=>' +            <style:style style:name="Strong_20_Emphasis" style:display-name="Strong Emphasis" style:family="text"> +                <style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"/> +            </style:style>', +    ); +    // Font definitions. May not be present if in template mode, in which case they will be added to styles.xml +    var $fonts = array( +        "StarSymbol"=>'<style:font-face style:name="StarSymbol" svg:font-family="StarSymbol"/>', // for bullets +        "Bitstream Vera Sans Mono"=>'<style:font-face style:name="Bitstream Vera Sans Mono" svg:font-family="\'Bitstream Vera Sans Mono\'" style:font-family-generic="modern" style:font-pitch="fixed"/>', // for source code +    ); + +    /** +     * Return version info +     */ +    function getInfo(){ +        return confToHash(dirname(__FILE__).'/info.txt'); +    } + +    /** +     * Returns the format produced by this renderer. +     */ +    function getFormat(){ +        return "odt"; +    } + +    /** +     * Do not make multiple instances of this class +     */ +    function isSingleton(){ +        return true; +    } + + +    /** +     * Initialize the rendering +     */ +    function document_start() { +        global $ID; + +        // If older or equal to 2007-06-26, we need to disable caching +        $dw_version = preg_replace('/[^\d]/', '', getversion()); +        if (version_compare($dw_version, "20070626", "<=")) { +            $this->info["cache"] = false; +        } + +        // prepare the zipper +        $this->ZIP = new ZipLib(); + +        // prepare meta data +        $this->meta             = array( +                'meta:generator'            => 'DokuWiki '.getversion(), +                'meta:initial-creator'      => 'Generated', +                'meta:creation-date'        => date('Y-m-d\\TH::i:s', null), //FIXME +                'dc:creator'                => 'Generated', +                'dc:date'                   => date('Y-m-d\\TH::i:s', null), +                'dc:language'               => 'en-US', +                'meta:editing-cycles'       => '1', +                'meta:editing-duration'     => 'PT0S', +            ); + +        // send the content type header, new method after 2007-06-26 (handles caching) +        $output_filename = str_replace(':','-',$ID).".odt"; +        if (version_compare($dw_version, "20070626")) { +            // store the content type headers in metadata +            $headers = array( +                'Content-Type' => 'application/vnd.oasis.opendocument.text', +                'Content-Disposition' => 'attachment; filename="'.$output_filename.'";', +            ); +            p_set_metadata($ID,array('format' => array('odt' => $headers) )); +        } else { // older method +            header('Content-Type: application/vnd.oasis.opendocument.text'); +            header('Content-Disposition: attachment; filename="'.$output_filename.'";'); +        } +    } + +    /** +     * Prepare meta.xml +     */ +    function _odtMeta(){ +        $value  =   '<' . '?xml version="1.0" encoding="UTF-8"?' . ">\n"; +        $value .=   '<office:document-meta '; +        $value .=       'xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" '; +        $value .=       'xmlns:xlink="http://www.w3.org/1999/xlink" '; +        $value .=       'xmlns:dc="http://purl.org/dc/elements/1.1/" '; +        $value .=       'xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" '; +        $value .=   'office:version="1.0">'; +        $value .=       '<office:meta>'; +    # FIXME +    #    foreach($meta as $meta_key => $meta_value) +    #        $value .=       '<' . $meta_key . '>' . ODUtils::encode($meta_value) . '</' . $meta_key . '>'; +        $value .=       '</office:meta>'; +        $value .=   '</office:document-meta>'; +        $this->ZIP->add_File($value,'meta.xml'); +    } + +    /** +     * Prepare manifest.xml +     */ +    function _odtManifest(){ +        $value  =   '<' . '?xml version="1.0" encoding="UTF-8"?' . ">\n"; +        $value .=   '<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">'; +        $value .=   '<manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.text" manifest:full-path="/"/>'; +        $value .=   '<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="settings.xml"/>'; +        $value .=   '<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="meta.xml"/>'; +        $value .=   '<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="content.xml"/>'; +        $value .=   '<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="styles.xml"/>'; + +        foreach($this->manifest as $path => $type){ +            $value .= '<manifest:file-entry manifest:media-type="'.$this->_xmlEntities($type). +                      '" manifest:full-path="'.$this->_xmlEntities($path).'"/>'; +        } + +        $value .=   '</manifest:manifest>'; +        $this->ZIP->add_File($value,'META-INF/manifest.xml'); +    } + +    /** +     * Prepare settings.xml +     */ +    function _odtSettings(){ +        $value  =   '<' . '?xml version="1.0" encoding="UTF-8"?' . ">\n"; +        $value .=   '<office:document-settings xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" office:version="1.0"><office:settings><config:config-item-set config:name="dummy-settings"><config:config-item config:name="MakeValidatorHappy" config:type="boolean">true</config:config-item></config:config-item-set></office:settings></office:document-settings>'; +        $this->ZIP->add_File($value,'settings.xml'); +    } + + + + +    /** +     * Closes the document +     */ +    function document_end(){ +        global $conf; +        if ($this->template) { // template chosen +            if (file_exists($conf['mediadir'].'/'.$this->getConf("tpl_dir")."/".$this->template)) { //template found +                $this->document_end_template(); +            } else { // template chosen but not found : warn the user and use the default template +                $this->doc = '<text:p text:style-name="Text_20_body"><text:span text:style-name="Strong_20_Emphasis">' +                             .$this->_xmlEntities( sprintf($this->getLang('tpl_not_found'),$this->template,$this->getConf("tpl_dir")) ) +                             .'</text:span></text:p>'.$this->doc; +                $this->document_end_scratch(); +            } +        } else { +            $this->document_end_scratch(); +        } +        $this->doc = $this->ZIP->get_file(); +    } + + +    /** +     * Closes the document when not using a template +     */ +    function document_end_scratch(){ +        $autostyles = $this->_odtAutoStyles(); +        $userfields = $this->_odtUserFields(); + +        // add defaults +        $this->ZIP->add_File('application/vnd.oasis.opendocument.text', 'mimetype', 0); + +        $this->_odtMeta(); +        $this->_odtSettings(); + +        $value  =   '<' . '?xml version="1.0" encoding="UTF-8"?' . ">\n"; +        $value .=   '<office:document-content '; +        $value .=       'xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" '; +        $value .=       'xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" '; +        $value .=       'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" '; +        $value .=       'xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" '; +        $value .=       'xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" '; +        $value .=       'xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" '; +        $value .=       'xmlns:xlink="http://www.w3.org/1999/xlink" '; +        $value .=       'xmlns:dc="http://purl.org/dc/elements/1.1/" '; +        $value .=       'xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" '; +        $value .=       'xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" '; +        $value .=       'xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" '; +        $value .=       'xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" '; +        $value .=       'xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" '; +        $value .=       'xmlns:math="http://www.w3.org/1998/Math/MathML" '; +        $value .=       'xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" '; +        $value .=       'xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" '; +        $value .=       'xmlns:dom="http://www.w3.org/2001/xml-events" '; +        $value .=       'xmlns:xforms="http://www.w3.org/2002/xforms" '; +        $value .=       'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '; +        $value .=       'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '; +        $value .=   'office:version="1.0">'; +        $value .=       '<office:scripts/>'; +        $value .=       '<office:font-face-decls>'; +        $value .=           '<style:font-face style:name="Tahoma1" svg:font-family="Tahoma"/>'; +        $value .=           '<style:font-face style:name="Lucida Sans Unicode" svg:font-family="'Lucida Sans Unicode'" style:font-pitch="variable"/>'; +        $value .=           '<style:font-face style:name="Tahoma" svg:font-family="Tahoma" style:font-pitch="variable"/>'; +        $value .=           '<style:font-face style:name="Times New Roman" svg:font-family="'Times New Roman'" style:font-family-generic="roman" style:font-pitch="variable"/>'; +        $value .=       '</office:font-face-decls>'; +        $value .=       $autostyles; +        $value .=       '<office:body>'; +        $value .=           '<office:text>'; +        $value .=               '<office:forms form:automatic-focus="false" form:apply-design-mode="false"/>'; +        $value .=               '<text:sequence-decls>'; +        $value .=                   '<text:sequence-decl text:display-outline-level="0" text:name="Illustration"/>'; +        $value .=                   '<text:sequence-decl text:display-outline-level="0" text:name="Table"/>'; +        $value .=                   '<text:sequence-decl text:display-outline-level="0" text:name="Text"/>'; +        $value .=                   '<text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>'; +        $value .=               '</text:sequence-decls>'; +        $value .=               $userfields; +        $value .=   $this->doc; +        $value .=           '</office:text>'; +        $value .=       '</office:body>'; +        $value .=   '</office:document-content>'; + +        $this->ZIP->add_File($value,'content.xml'); + +        $value = io_readFile(DOKU_PLUGIN.'odt/styles.xml'); +        $value = str_replace('<office:automatic-styles/>', $autostyles, $value); +        $this->ZIP->add_File($value,'styles.xml'); + +        // build final manifest +        $this->_odtManifest(); +    } + +    /** +     * Closes the document using a template +     */ +    function document_end_template(){ +        global $conf, $ID; // for the temp dir + +        // Temp dir +        if (is_dir($conf['tmpdir'])) { +            $temp_dir = $conf['tmpdir']; // version > 20070626 +        } else { +            $temp_dir = $conf['savedir'].'/cache/tmp'; // version <= 20070626 +        } +        $this->temp_dir = $temp_dir."/odt/".str_replace(':','-',$ID); +        if (is_dir($this->temp_dir)) { $this->io_rm_rf($this->temp_dir); } +        io_mkdir_p($this->temp_dir); + +        // Extract template +        $template_path = $conf['mediadir'].'/'.$this->getConf("tpl_dir")."/".$this->template; +        $this->ZIP->Extract($template_path, $this->temp_dir); + +        // Prepare content +        $autostyles = $this->_odtAutoStyles(); +        $missingstyles = $this->_odtStyles(); +        $missingfonts = $this->_odtFonts(); +        $userfields = $this->_odtUserFields(); + +        // Insert content +        $old_content = io_readFile($this->temp_dir.'/content.xml'); +        if (strpos($old_content, 'DOKUWIKI-ODT-INSERT') !== FALSE) { // Replace the mark +            $this->_odtReplaceInFile('/<text:p[^>]*>DOKUWIKI-ODT-INSERT<\/text:p>/',  +                $this->doc, $this->temp_dir.'/content.xml', true); +        } else { // Append to the template +            $this->_odtReplaceInFile('</office:text>', $this->doc.'</office:text>', $this->temp_dir.'/content.xml'); +        } + +        // Cut off unwanted content +        if (strpos($old_content, 'DOKUWIKI-ODT-CUT-START') !== FALSE  +                && strpos($old_content, 'DOKUWIKI-ODT-CUT-STOP') !== FALSE) { +            $this->_odtReplaceInFile('/DOKUWIKI-ODT-CUT-START.*DOKUWIKI-ODT-CUT-STOP/',  +                '', $this->temp_dir.'/content.xml', true); +        } + +        // Insert userfields +        if (strpos($old_content, "text:user-field-decls") === FALSE) { // no existing userfields +            $this->_odtReplaceInFile('/<office:text([^>]*)>/U', '<office:text\1>'.$userfields, $this->temp_dir.'/content.xml', TRUE); +        } else { +            $this->_odtReplaceInFile('</text:user-field-decls>', substr($userfields,23), $this->temp_dir.'/content.xml'); +        } + +        // Insert styles & fonts +        $this->_odtReplaceInFile('</office:automatic-styles>', substr($autostyles, 25), $this->temp_dir.'/content.xml'); +        $this->_odtReplaceInFile('</office:automatic-styles>', substr($autostyles, 25), $this->temp_dir.'/styles.xml'); +        $this->_odtReplaceInFile('</office:styles>', $missingstyles.'</office:styles>', $this->temp_dir.'/styles.xml'); +        $this->_odtReplaceInFile('</office:font-face-decls>', $missingfonts.'</office:font-face-decls>', $this->temp_dir.'/styles.xml'); + +        // Build the Zip +        $this->ZIP->Compress(null, $this->temp_dir, null); +        $this->io_rm_rf($this->temp_dir); +    } + +    function _odtReplaceInFile($from, $to, $file, $regexp=FALSE) { +        $value = io_readFile($file); +        if ($regexp) { +            $value = preg_replace($from, $to, $value); +        } else { +            $value = str_replace($from, $to, $value); +        } +        $file_f = fopen($file, 'w'); +        fwrite($file_f, $value); +        fclose($file_f); +    } + +    /** +     * Recursively deletes a directory (equivalent to the "rm -rf" command) +     * Found in comments on http://www.php.net/rmdir +     */ +    function io_rm_rf($f) { +        if (is_dir($f)) { +            foreach(glob($f.'/*') as $sf) { +                if (is_dir($sf) && !is_link($sf)) { +                    $this->io_rm_rf($sf); +                } else { +                    unlink($sf); +                } +            } +        } else { // avoid nasty consequenses if something wrong is given +            die("Error: not a directory - $f"); +        } +        rmdir($f); +    } + +    // not supported - use OpenOffice builtin tools instead! +    function render_TOC() { return ''; } + +    function toc_additem($id, $text, $level) {} + +    function _odtAutoStyles() { +        $value = '<office:automatic-styles>'; +        foreach ($this->autostyles as $stylename=>$stylexml) { +            $value .= $stylexml; +        } +        $value .= '</office:automatic-styles>'; +        return $value; +    } + +    function _odtUserFields() { +        $value = '<text:user-field-decls>'; +        foreach ($this->fields as $fname=>$fvalue) { +            $value .= '<text:user-field-decl office:value-type="string" text:name="'.$fname.'" office:string-value="'.$fvalue.'"/>'; +        } +        $value .= '</text:user-field-decls>'; +        return $value; +    } + +    /* Add missing styles in the template */ +    function _odtStyles() { +        $value = ''; +        $existing_styles = io_readFile($this->temp_dir.'/styles.xml'); +        foreach ($this->styles as $stylename=>$stylexml) { +            if (strpos($existing_styles, 'style:name="'.$stylename.'"') === FALSE) { +                $value .= $stylexml; +            } +        } +        // Loop on bullet/numerotation styles +        if (strpos($existing_styles, 'style:name="List_20_1"') === FALSE) { +            $value .= '<text:list-style style:name="List_20_1" style:display-name="List 1">'; +            for ($i=1;$i<=10;$i++) { +                $value .= '<text:list-level-style-bullet text:level="'.$i.'" text:style-name="Numbering_20_Symbols" text:bullet-char="•"> +                               <style:list-level-properties text:space-before="'.(0.4*($i-1)).'cm" text:min-label-width="0.4cm"/> +                               <style:text-properties style:font-name="StarSymbol"/> +                           </text:list-level-style-bullet>'; +            } +            $value .= '</text:list-style>'; +        } +        if (strpos($existing_styles, 'style:name="Numbering_20_1"') === FALSE) { +            $value .= '<text:list-style style:name="Numbering_20_1" style:display-name="Numbering 1">'; +            for ($i=1;$i<=10;$i++) { +                $value .= '<text:list-level-style-number text:level="'.$i.'" text:style-name="Numbering_20_Symbols" style:num-suffix="." style:num-format="1"> +                               <style:list-level-properties text:space-before="'.(0.5*($i-1)).'cm" text:min-label-width="0.5cm"/> +                           </text:list-level-style-number>'; +            } +            $value .= '</text:list-style>'; +        } +        return $value; +    } + +    /* Add missing fonts in the template */ +    function _odtFonts() { +        $value = ''; +        $existing_styles = io_readFile($this->temp_dir.'/styles.xml'); +        foreach ($this->fonts as $name=>$xml) { +            if (strpos($existing_styles, 'style:name="'.$name.'"') === FALSE) { +                $value .= $xml; +            } +        } +        return $value; +    } + +    function cdata($text) { +        $this->doc .= $this->_xmlEntities($text); +    } + +    function p_open($style='Text_20_body'){ +        if (!$this->in_paragraph) { // opening a paragraph inside another paragraph is illegal +            $this->in_paragraph = true; +            $this->doc .= '<text:p text:style-name="'.$style.'">'; +        } +    } + +    function p_close(){ +        if ($this->in_paragraph) { +            $this->in_paragraph = false; +            $this->doc .= '</text:p>'; +        } +    } + +    function header($text, $level, $pos){ +        $hid = $this->_headerToLink($text,true); +        $this->doc .= '<text:h text:style-name="Heading_20_'.$level.'" text:outline-level="'.$level.'">'; +        $this->doc .= '<text:bookmark-start text:name="'.$hid.'"/>'; +        $this->doc .= $this->_xmlEntities($text); +        $this->doc .= '<text:bookmark-end text:name="'.$hid.'"/>'; +        $this->doc .= '</text:h>'; +    } + +    function hr() { +        $this->doc .= '<text:p text:style-name="Horizontal_20_Line"/>'; +    } + +    function linebreak() { +        $this->doc .= '<text:line-break/>'; +    } + +    function strong_open() { +        $this->doc .= '<text:span text:style-name="Strong_20_Emphasis">'; +    } + +    function strong_close() { +        $this->doc .= '</text:span>'; +    } + +    function emphasis_open() { +        $this->doc .= '<text:span text:style-name="Emphasis">'; +    } + +    function emphasis_close() { +        $this->doc .= '</text:span>'; +    } + +    function underline_open() { +        $this->doc .= '<text:span text:style-name="underline">'; +    } + +    function underline_close() { +        $this->doc .= '</text:span>'; +    } + +    function monospace_open() { +        $this->doc .= '<text:span text:style-name="Source_20_Text">'; +    } + +    function monospace_close() { +        $this->doc .= '</text:span>'; +    } + +    function subscript_open() { +        $this->doc .= '<text:span text:style-name="sub">'; +    } + +    function subscript_close() { +        $this->doc .= '</text:span>'; +    } + +    function superscript_open() { +        $this->doc .= '<text:span text:style-name="sup">'; +    } + +    function superscript_close() { +        $this->doc .= '</text:span>'; +    } + +    function deleted_open() { +        $this->doc .= '<text:span text:style-name="del">'; +    } + +    function deleted_close() { +        $this->doc .= '</text:span>'; +    } + +    /* +     * Tables +     */ +    function table_open($maxcols = NULL, $numrows = NULL){ +        $this->doc .= '<table:table>'; +        for($i=0; $i<$maxcols; $i++){ +            $this->doc .= '<table:table-column />'; +        } +    } + +    function table_close(){ +        $this->doc .= '</table:table>'; +    } + +    function tablerow_open(){ +        $this->doc .= '<table:table-row>'; +    } + +    function tablerow_close(){ +        $this->doc .= '</table:table-row>'; +    } + +    function tableheader_open($colspan = 1, $align = "left"){ +        $this->doc .= '<table:table-cell office:value-type="string" table:style-name="tableheader" '; +        //$this->doc .= ' table:style-name="tablealign'.$align.'"'; +        if ( $colspan > 1 ) { +            $this->doc .= ' table:number-columns-spanned="'.$colspan.'"'; +        } +        $this->doc .= '>'; +        $this->p_open('Table_20_Heading'); +    } + +    function tableheader_close(){ +        $this->p_close(); +        $this->doc .= '</table:table-cell>'; +    } + +    function tablecell_open($colspan = 1, $align = "left"){ +        $this->doc .= '<table:table-cell office:value-type="string" table:style-name="tablecell" '; +        if ( $colspan > 1 ) { +            $this->doc .= ' table:number-columns-spanned="'.$colspan.'"'; +        } +        $this->doc .= '>'; +        if (!$align) $align = "left"; +        $style = "tablealign".$align; +        $this->p_open($style); +    } + +    function tablecell_close(){ +        $this->p_close(); +        $this->doc .= '</table:table-cell>'; +    } + +    /** +     * Callback for footnote start syntax +     * +     * All following content will go to the footnote instead of +     * the document. To achieve this the previous rendered content +     * is moved to $store and $doc is cleared +     * +     * @author Andreas Gohr <andi@splitbrain.org> +     */ +    function footnote_open() { + +        // move current content to store and record footnote +        $this->store = $this->doc; +        $this->doc   = ''; +    } + +    /** +     * Callback for footnote end syntax +     * +     * All rendered content is moved to the $footnotes array and the old +     * content is restored from $store again +     * +     * @author Andreas Gohr +     */ +    function footnote_close() { +        // recover footnote into the stack and restore old content +        $footnote = $this->doc; +        $this->doc = $this->store; +        $this->store = ''; + +        // check to see if this footnote has been seen before +        $i = array_search($footnote, $this->footnotes); + +        if ($i === false) { +            $i = count($this->footnotes); +            // its a new footnote, add it to the $footnotes array +            $this->footnotes[$i] = $footnote; + +            $this->doc .= '<text:note text:id="ftn'.$i.'" text:note-class="footnote">'; +            $this->doc .= '<text:note-citation>'.($i+1).'</text:note-citation>'; +            $this->doc .= '<text:note-body>'; +            $this->doc .= '<text:p text:style-name="Footnote">'; +            $this->doc .= $footnote; +            $this->doc .= '</text:p>'; +            $this->doc .= '</text:note-body>'; +            $this->doc .= '</text:note>'; + +        } else { +            // seen this one before - just reference it FIXME: style isn't correct yet +            $this->doc .= '<text:note-ref text:note-class="footnote" text:ref-name="ftn'.$i.'">'.($i+1).'</text:note-ref>'; +        } +    } + +    function listu_open() { +        $this->p_close(); +        $this->doc .= '<text:list text:style-name="List_20_1">'; +    } + +    function listu_close() { +        $this->doc .= '</text:list>'; +    } + +    function listo_open() { +        $this->p_close(); +        $this->doc .= '<text:list text:style-name="Numbering_20_1">'; +    } + +    function listo_close() { +        $this->doc .= '</text:list>'; +    } + +    function listitem_open($level) { +        $this->in_list_item = true; +        $this->doc .= '<text:list-item>'; +    } + +    function listitem_close() { +        $this->in_list_item = false; +        $this->doc .= '</text:list-item>'; +    } + +    function listcontent_open() { +        $this->doc .= '<text:p text:style-name="Text_20_body">'; +    } + +    function listcontent_close() { +        $this->doc .= '</text:p>'; +    } + +    function unformatted($text) { +        $this->doc .= $this->_xmlEntities($text); +    } + +    function acronym($acronym) { +        $this->doc .= $this->_xmlEntities($acronym); +    } + +    function smiley($smiley) { +        if ( array_key_exists($smiley, $this->smileys) ) { +            $src = DOKU_INC."lib/images/smileys/".$this->smileys[$smiley]; +            $this->_odtAddImage($src); +        } else { +            $this->doc .= $this->_xmlEntities($smiley); +        } +    } + +    function entity($entity) { +        # UTF-8 entity decoding is broken in PHP <5 +        if (version_compare(phpversion(), "5.0.0") and array_key_exists($entity, $this->entities) ) { +            # decoding may fail for missing Multibyte-Support in entity_decode +            $dec = @html_entity_decode($this->entities[$entity],ENT_NOQUOTES,'UTF-8'); +            if($dec){ +                $this->doc .= $this->_xmlEntities($dec); +            }else{ +                $this->doc .= $this->_xmlEntities($entity); +            } +        } else { +            $this->doc .= $this->_xmlEntities($entity); +        } +    } + +    function multiplyentity($x, $y) { +        $this->doc .= $x.'×'.$y; +    } + +    function singlequoteopening() { +        global $lang; +        $this->doc .= $lang['singlequoteopening']; +    } + +    function singlequoteclosing() { +        global $lang; +        $this->doc .= $lang['singlequoteclosing']; +    } + +    function apostrophe() { +        global $lang; +        $this->doc .= $lang['apostrophe']; +    } + +    function doublequoteopening() { +        global $lang; +        $this->doc .= $lang['doublequoteopening']; +    } + +    function doublequoteclosing() { +        global $lang; +        $this->doc .= $lang['doublequoteclosing']; +    } + +    function php($text, $wrapper='dummy') { +        $this->monospace_open(); +        $this->doc .= $this->_xmlEntities($text); +        $this->monospace_close(); +    } +    function phpblock($text) { +        $this->file($text); +    } + +    function html($text, $wrapper='dummy') { +        $this->monospace_open(); +        $this->doc .= $this->_xmlEntities($text); +        $this->monospace_close(); +    } +    function htmlblock($text) { +        $this->file($text); +    } + +    /** +     * static call back to replace spaces +     */ +    function _preserveSpace($matches){ +        $spaces = $matches[1]; +        $len    = strlen($spaces); +        return '<text:s text:c="'.$len.'"/>'; +    } + +    function preformatted($text) { +        $text = $this->_xmlEntities($text); +        if (strpos($text, "\n") !== FALSE and strpos($text, "\n") == 0) { +            // text starts with a newline, remove it +            $text = substr($text,1); +        } +        $text = str_replace("\n",'<text:line-break/>',$text); +        $text = preg_replace_callback('/(  +)/',array('renderer_plugin_odt','_preserveSpace'),$text); + +        if ($this->in_list_item) { // if we're in a list item, we must close the <text:p> tag +            $this->doc .= '</text:p>'; +            $this->doc .= '<text:p text:style-name="Preformatted_20_Text">'; +            $this->doc .= $text; +            $this->doc .= '</text:p>'; +            $this->doc .= '<text:p>'; +        } else { +            $this->doc .= '<text:p text:style-name="Preformatted_20_Text">'; +            $this->doc .= $text; +            $this->doc .= '</text:p>'; +        } +    } + +    function file($text) { +        $this->preformatted($text); +    } + +    function quote_open() { +        if (!$this->in_paragraph) { // only start a new par if we're not already in one +            $this->p_open(); +        } +        $this->doc .= ">"; +    } + +    function quote_close() { +        if ($this->in_paragraph) { // only close the paragraph if we're actually in one +            $this->p_close(); +        } +    } + +    function code($text, $language = NULL) { +        // FIXME we could convert GeSHi HTML and CSS classes to ODT XML here +        $this->preformatted($text); +    } + +    function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL, +                            $height=NULL, $cache=NULL, $linking=NULL) { +        global $conf; +        global $ID; +        resolve_mediaid(getNS($ID),$src, $exists); +        list($ext,$mime) = mimetype($src); + +        if(substr($mime,0,5) == 'image'){ +            $file = mediaFN($src); +            $this->_odtAddImage($file, $width, $height, $align, $title); +        }else{ +            // FIXME build absolute medialink and call externallink() +            $this->code('FIXME internalmedia: '.$src); +        } +    } + +    function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL, +                            $height=NULL, $cache=NULL, $linking=NULL) { +        global $conf; +        global $ID; +        list($ext,$mime) = mimetype($src); + +        if(substr($mime,0,5) == 'image'){ +            if($width) { +                $width  = 'svg:width="'.(($width/96.0)*2.54).'cm"'; +            } else { +                $width  = 'svg:rel-width="100%"'; +            } +            if($height) { +                $height  = 'svg:height="'.(($height/96.0)*2.54).'cm"'; +            } else { +                $height  = 'svg:rel-height="100%"'; +            } + +            $style = 'media'.$align; +            if($align){ +                $anchor = 'paragraph'; +            }else{ +                $anchor = 'as-char'; +            } + +            $this->doc .= '<draw:frame draw:style-name="'.$style.'" draw:name="'.$this->_xmlEntities($title).'" +                            text:anchor-type="'.$anchor.'" draw:z-index="0" +                            '.$width.' '.$height.' >'; +            $this->doc .= '<draw:image xlink:href="'.$this->_xmlEntities($src).'" +                            xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>'; +            $this->doc .= '</draw:frame>'; +        }else{ +            $this->externallink($src,$title); +        } +    } + +    function camelcaselink($link) { +        $this->internallink($link,$link); +    } + +    function reference($id, $name = NULL) { +        $this->doc .= '<text:a xlink:type="simple" xlink:href="#'.$id.'"'; +        if ($name) { +            $this->doc .= '>'.$this->_xmlEntities($name).'</text:a>'; +        } else { +            $this->doc .= '/>'; +        } +    } + +    /** +     * Render an internal Wiki Link +     * +     * @author Andreas Gohr <andi@splitbrain.org> +     */ +    function internallink($id, $name = NULL) { +        global $conf; +        global $ID; +        // default name is based on $id as given +        $default = $this->_simpleTitle($id); +        // now first resolve and clean up the $id +        resolve_pageid(getNS($ID),$id,$exists); +        $name = $this->_getLinkTitle($name, $default, $isImage, $id); + +        // build the absolute URL (keeping a hash if any) +        list($id,$hash) = explode('#',$id,2); +        $url = wl($id,'',true); +        if($hash) $url .='#'.$hash; + +        if ($ID == $id) { +            $this->reference($hash, $name); +        } else { +            $this->_doLink($url,$name); +        } +    } + +    /** +     * Add external link +     */ +    function externallink($url, $name = NULL) { +        global $conf; + +        $name = $this->_getLinkTitle($name, $url, $isImage); + +        $this->_doLink($url,$name); +    } + +    /** +     * Just print local links +     * +     * @fixme add image handling +     */ +    function locallink($hash, $name = NULL){ +        $name  = $this->_getLinkTitle($name, $hash, $isImage); +        $this->doc .= $name; +    } + +    /** +     * InterWiki links +     */ +    function interwikilink($match, $name = NULL, $wikiName, $wikiUri) { +        $name  = $this->_getLinkTitle($name, $wikiUri, $isImage); +        $url = $this-> _resolveInterWiki($wikiName,$wikiUri); +        $this->_doLink($url,$name); +    } + +    /** +     * Just print WindowsShare links +     * +     * @fixme add image handling +     */ +    function windowssharelink($url, $name = NULL) { +        $name  = $this->_getLinkTitle($name, $url, $isImage); +        $this->doc .= $name; +    } + +    /** +     * Just print email links +     * +     * @fixme add image handling +     */ +    function emaillink($address, $name = NULL) { +        $name  = $this->_getLinkTitle($name, $address, $isImage); +        $this->_doLink("mailto:".$address,$name); +    } + +    /** +     * Add a hyperlink, handling Images correctly +     * +     * @author Andreas Gohr <andi@splitbrain.org> +     */ +    function _doLink($url,$name){ +        $url = $this->_xmlEntities($url); +        if(is_array($name)){ +            // Images +            if($url) $this->doc .= '<draw:a xlink:type="simple" xlink:href="'.$url.'">'; + +            if($name['type'] == 'internalmedia'){ +                $this->internalmedia($name['src'], +                                     $name['title'], +                                     $name['align'], +                                     $name['width'], +                                     $name['height'], +                                     $name['cache'], +                                     $name['linking']); +            } + +            if($url) $this->doc .= '</draw:a>'; +        }else{ +            // Text +            if($url) $this->doc .= '<text:a xlink:type="simple" xlink:href="'.$url.'">'; +            $this->doc .= $name; // we get the name already XML encoded +            if($url) $this->doc .= '</text:a>'; +        } +    } + +    /** +     * Construct a title and handle images in titles +     * +     * @author Harry Fuecks <hfuecks@gmail.com> +     */ +    function _getLinkTitle($title, $default, & $isImage, $id=null) { +        global $conf; + +        $isImage = false; +        if ( is_null($title) ) { +            if ($conf['useheading'] && $id) { +                $heading = p_get_first_heading($id); +                if ($heading) { +                    return $this->_xmlEntities($heading); +                } +            } +            return $this->_xmlEntities($default); +        } else if ( is_string($title) ) { +            return $this->_xmlEntities($title); +        } else if ( is_array($title) ) { +            $isImage = true; +            return $title; +        } +    } + +    /** +     * Creates a linkid from a headline +     * +     * @param string  $title   The headline title +     * @param boolean $create  Create a new unique ID? +     * @author Andreas Gohr <andi@splitbrain.org> +     */ +    function _headerToLink($title,$create=false) { +        $title = str_replace(':','',cleanID($title)); +        $title = ltrim($title,'0123456789._-'); +        if(empty($title)) $title='section'; + +        if($create){ +            // make sure tiles are unique +            $num = ''; +            while(in_array($title.$num,$this->headers)){ +                ($num) ? $num++ : $num = 1; +            } +            $title = $title.$num; +            $this->headers[] = $title; +        } + +        return $title; +    } + + +    function _xmlEntities($value) { +        return str_replace( array('&','"',"'",'<','>'), array('&','"',''','<','>'), $value); +    } + +    function rss ($url,$params){ +        global $lang; +        global $conf; + +        require_once(DOKU_INC.'inc/FeedParser.php'); +        $feed = new FeedParser(); +        $feed->feed_url($url); + +        //disable warning while fetching +        if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } +        $rc = $feed->init(); +        if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } + +        //decide on start and end +        if($params['reverse']){ +            $mod = -1; +            $start = $feed->get_item_quantity()-1; +            $end   = $start - ($params['max']); +            $end   = ($end < -1) ? -1 : $end; +        }else{ +            $mod   = 1; +            $start = 0; +            $end   = $feed->get_item_quantity(); +            $end   = ($end > $params['max']) ? $params['max'] : $end;; +        } + +        $this->listu_open(); +        if($rc){ +            for ($x = $start; $x != $end; $x += $mod) { +                $item = $feed->get_item($x); +                $this->listitem_open(0); +                $this->listcontent_open(); +                $this->externallink($item->get_permalink(), +                                    $item->get_title()); +                if($params['author']){ +                    $author = $item->get_author(0); +                    if($author){ +                        $name = $author->get_name(); +                        if(!$name) $name = $author->get_email(); +                        if($name) $this->cdata(' '.$lang['by'].' '.$name); +                    } +                } +                if($params['date']){ +                    $this->cdata(' ('.$item->get_date($conf['dformat']).')'); +                } +                if($params['details']){ +                    $this->cdata(strip_tags($item->get_description())); +                } +                $this->listcontent_close(); +                $this->listitem_close(); +            } +        }else{ +            $this->listitem_open(0); +            $this->listcontent_open(); +            $this->emphasis_open(); +            $this->cdata($lang['rssfailed']); +            $this->emphasis_close(); +            $this->externallink($url); +            $this->listcontent_close(); +            $this->listitem_close(); +        } +        $this->listu_close(); +    } + + +    function _odtAddImage($src, $width = NULL, $height = NULL, $align = NULL, $title = NULL, $style = NULL){ +        list($ext,$mime) = mimetype($src); +        $name = 'Pictures/'.md5($src).'.'.$ext; +        if(!$this->manifest[$name]){ +            $this->manifest[$name] = $mime; +            $this->ZIP->add_File(io_readfile($src,false),$name,0); +        } +        // make sure width and height is available +        // FIXME we don't have the dimension of an external file +        // (except it's cached, but this is not the default) there seems +        // to be no way to specify "use original image" in ODF - thus +        // a hardcoded default size of 200 pixel here +        if(!$width || !$height){ +            $info  = getimagesize($src); +            if(!$width){ +                $width  = $info[0]; +                $height = $info[1]; +            }else{ +                $height = round(($width * $info[1]) / $info[0]); +            } +        } + +        // convert from pixel to centimeters +        $width  = (($width/96.0)*2.54); +        $height = (($height/96.0)*2.54); +        // Don't be wider than the page +        if ($width >= 17){ // FIXME : this assumes A4 page format with 2cm margins +            $width = $width.'cm"  style:rel-width="100%'; +            $height = $height.'cm"  style:rel-height="scale'; +        } else { +            $width = $width.'cm'; +            $height = $height.'cm'; +        } + +        if($align){ +            $anchor = 'paragraph'; +        }else{ +            $anchor = 'as-char'; +        } + +        if (!$style or !array_key_exists($style, $this->autostyles)) { +            $style = 'media'.$align; +        } + +        if ($title) { +            $this->doc .= '<draw:frame draw:style-name="'.$style.'" draw:name="'.$this->_xmlEntities($title).' Legend" +                            text:anchor-type="'.$anchor.'" draw:z-index="0" svg:width="'.$width.'">'; +            $this->doc .= '<draw:text-box>'; +            $this->doc .= '<text:p text:style-name="legendcenter">'; +        } +        $this->doc .= '<draw:frame draw:style-name="'.$style.'" draw:name="'.$this->_xmlEntities($title).'" +                        text:anchor-type="'.$anchor.'" draw:z-index="0" +                        svg:width="'.$width.'" svg:height="'.$height.'" >'; +        $this->doc .= '<draw:image xlink:href="'.$this->_xmlEntities($name).'" +                        xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>'; +        $this->doc .= '</draw:frame>'; +        if ($title) { +            $this->doc .= $this->_xmlEntities($title).'</text:p></draw:text-box></draw:frame>'; +        } +    } + +} + +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/vendors/dokuwiki/lib/plugins/odt/styles.xml b/vendors/dokuwiki/lib/plugins/odt/styles.xml new file mode 100644 index 000000000..c328464f3 --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/styles.xml @@ -0,0 +1,158 @@ +<?xml version="1.0"?> +<!-- +  This file defines how the document is styled. This was extracted from a ODT file +  created in OpenOffice 2.0 and could probably be much simpler. + +  You probably want to replace this file with a style fitting your corporate identity. + +  To do so, export the wiki:syntax page, edit it's style definitions (be sure to keep +  the names) and save the resulting file. Extract the resulting file with unzip and +  copy the styles.xml over this one. +--> +<office:document-styles xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" office:version="1.0"> +    <office:font-face-decls> +        <style:font-face style:name="StarSymbol" svg:font-family="StarSymbol"/> +        <style:font-face style:name="Bitstream Vera Sans Mono" svg:font-family="'Bitstream Vera Sans Mono'" style:font-family-generic="modern" style:font-pitch="fixed"/> +        <style:font-face style:name="Bitstream Vera Sans" svg:font-family="'Bitstream Vera Sans'" style:font-family-generic="roman" style:font-pitch="variable"/> +        <style:font-face style:name="Bitstream Vera Sans1" svg:font-family="'Bitstream Vera Sans'" style:font-family-generic="swiss" style:font-pitch="variable"/> +        <style:font-face style:name="Bitstream Vera Sans2" svg:font-family="'Bitstream Vera Sans'" style:font-family-generic="system" style:font-pitch="variable"/> +    </office:font-face-decls> +    <office:styles> +        <style:default-style style:family="graphic"> +            <style:graphic-properties draw:shadow-offset-x="0.3cm" draw:shadow-offset-y="0.3cm" draw:start-line-spacing-horizontal="0.283cm" draw:start-line-spacing-vertical="0.283cm" draw:end-line-spacing-horizontal="0.283cm" draw:end-line-spacing-vertical="0.283cm" style:flow-with-text="false"/> +            <style:paragraph-properties style:text-autospace="ideograph-alpha" style:line-break="strict" style:writing-mode="lr-tb" style:font-independent-line-spacing="false"> +                <style:tab-stops/> +            </style:paragraph-properties> +            <style:text-properties style:use-window-font-color="true" fo:font-size="12pt" style:font-size-asian="12pt" style:font-size-complex="12pt"/> +        </style:default-style> +        <style:default-style style:family="paragraph"> +            <style:paragraph-properties fo:hyphenation-ladder-count="no-limit" style:text-autospace="ideograph-alpha" style:punctuation-wrap="hanging" style:line-break="strict" style:tab-stop-distance="1.251cm" style:writing-mode="page"/> +            <style:text-properties style:use-window-font-color="true" style:font-name="Bitstream Vera Sans" fo:font-size="12pt" style:font-name-asian="Bitstream Vera Sans2" style:font-size-asian="12pt" style:font-name-complex="Bitstream Vera Sans2" style:font-size-complex="12pt" fo:hyphenate="false" fo:hyphenation-remain-char-count="2" fo:hyphenation-push-char-count="2"/> +        </style:default-style> +        <style:default-style style:family="table"> +            <style:table-properties table:border-model="collapsing"/> +        </style:default-style> +        <style:default-style style:family="table-row"> +            <style:table-row-properties fo:keep-together="auto"/> +        </style:default-style> +        <style:style style:name="Standard" style:family="paragraph" style:class="text"/> +        <style:style style:name="Text_20_body" style:display-name="Text body" style:family="paragraph" style:parent-style-name="Standard" style:class="text"> +            <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0.212cm" fo:text-align="justify" style:justify-single-word="false"/> +        </style:style> +        <style:style style:name="Heading" style:family="paragraph" style:parent-style-name="Standard" style:next-style-name="Text_20_body" style:class="text"> +            <style:paragraph-properties fo:margin-top="0.423cm" fo:margin-bottom="0.212cm" fo:keep-with-next="always"/> +            <style:text-properties style:font-name="Bitstream Vera Sans1" fo:font-size="14pt" style:font-name-asian="Bitstream Vera Sans2" style:font-size-asian="14pt" style:font-name-complex="Bitstream Vera Sans2" style:font-size-complex="14pt"/> +        </style:style> +        <style:style style:name="Heading_20_1" style:display-name="Heading 1" style:family="paragraph" style:parent-style-name="Heading" style:next-style-name="Text_20_body" style:class="text" style:default-outline-level="1"> +            <style:text-properties style:font-name="Bitstream Vera Sans" fo:font-size="24pt" fo:font-weight="bold" style:font-name-asian="Bitstream Vera Sans2" style:font-size-asian="24pt" style:font-weight-asian="bold" style:font-name-complex="Bitstream Vera Sans2" style:font-size-complex="24pt" style:font-weight-complex="bold"/> +        </style:style> +        <style:style style:name="Heading_20_2" style:display-name="Heading 2" style:family="paragraph" style:parent-style-name="Heading" style:next-style-name="Text_20_body" style:class="text" style:default-outline-level="2"> +            <style:text-properties style:font-name="Bitstream Vera Sans" fo:font-size="18pt" fo:font-weight="bold" style:font-name-asian="Bitstream Vera Sans2" style:font-size-asian="18pt" style:font-weight-asian="bold" style:font-name-complex="Bitstream Vera Sans2" style:font-size-complex="18pt" style:font-weight-complex="bold"/> +        </style:style> +        <style:style style:name="Heading_20_3" style:display-name="Heading 3" style:family="paragraph" style:parent-style-name="Heading" style:next-style-name="Text_20_body" style:class="text" style:default-outline-level="3"> +            <style:text-properties style:font-name="Bitstream Vera Sans" fo:font-size="14pt" fo:font-weight="bold" style:font-name-asian="Bitstream Vera Sans2" style:font-size-asian="14pt" style:font-weight-asian="bold" style:font-name-complex="Bitstream Vera Sans2" style:font-size-complex="14pt" style:font-weight-complex="bold"/> +        </style:style> +        <style:style style:name="Heading_20_4" style:display-name="Heading 4" style:family="paragraph" style:parent-style-name="Heading" style:next-style-name="Text_20_body" style:class="text" style:default-outline-level="4"> +            <style:text-properties style:font-name="Bitstream Vera Sans" fo:font-size="12pt" fo:font-weight="bold" style:font-name-asian="Bitstream Vera Sans2" style:font-size-asian="12pt" style:font-weight-asian="bold" style:font-name-complex="Bitstream Vera Sans2" style:font-size-complex="12pt" style:font-weight-complex="bold"/> +        </style:style> +        <style:style style:name="Heading_20_5" style:display-name="Heading 5" style:family="paragraph" style:parent-style-name="Heading" style:next-style-name="Text_20_body" style:class="text" style:default-outline-level="5"> +            <style:text-properties style:font-name="Bitstream Vera Sans" fo:font-size="10pt" fo:font-weight="bold" style:font-name-asian="Bitstream Vera Sans2" style:font-size-asian="10pt" style:font-weight-asian="bold" style:font-name-complex="Bitstream Vera Sans2" style:font-size-complex="10pt" style:font-weight-complex="bold"/> +        </style:style> +        <style:style style:name="List" style:family="paragraph" style:parent-style-name="Text_20_body" style:class="list"/> +        <style:style style:name="Table_20_Contents" style:display-name="Table Contents" style:family="paragraph" style:parent-style-name="Standard" style:class="extra"> +            <style:paragraph-properties text:number-lines="false" text:line-number="0"/> +        </style:style> +        <style:style style:name="Table_20_Heading" style:display-name="Table Heading" style:family="paragraph" style:parent-style-name="Table_20_Contents" style:class="extra"> +            <style:paragraph-properties fo:text-align="center" style:justify-single-word="false" text:number-lines="false" text:line-number="0"/> +            <style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"/> +        </style:style> +        <style:style style:name="Caption" style:family="paragraph" style:parent-style-name="Standard" style:class="extra"> +            <style:paragraph-properties fo:margin-top="0.212cm" fo:margin-bottom="0.212cm" text:number-lines="false" text:line-number="0"/> +            <style:text-properties fo:font-size="12pt" fo:font-style="italic" style:font-size-asian="12pt" style:font-style-asian="italic" style:font-size-complex="12pt" style:font-style-complex="italic"/> +        </style:style> +        <style:style style:name="Index" style:family="paragraph" style:parent-style-name="Standard" style:class="index"> +            <style:paragraph-properties text:number-lines="false" text:line-number="0"/> +        </style:style> +        <style:style style:name="Quotations" style:family="paragraph" style:parent-style-name="Standard" style:class="html"> +            <style:paragraph-properties fo:margin-left="1cm" fo:margin-right="1cm" fo:margin-top="0cm" fo:margin-bottom="0.499cm" fo:text-indent="0cm" style:auto-text-indent="false"/> +        </style:style> +        <style:style style:name="Preformatted_20_Text" style:display-name="Preformatted Text" style:family="paragraph" style:parent-style-name="Standard" style:class="html"> +            <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0cm"/> +            <style:text-properties style:font-name="Bitstream Vera Sans Mono" fo:font-size="10pt" style:font-name-asian="Bitstream Vera Sans Mono" style:font-size-asian="10pt" style:font-name-complex="Bitstream Vera Sans Mono" style:font-size-complex="10pt"/> +        </style:style> +        <style:style style:name="Horizontal_20_Line" style:display-name="Horizontal Line" style:family="paragraph" style:parent-style-name="Standard" style:next-style-name="Text_20_body" style:class="html"> +            <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0.499cm" style:border-line-width-bottom="0.002cm 0.035cm 0.002cm" fo:padding="0cm" fo:border-left="none" fo:border-right="none" fo:border-top="none" fo:border-bottom="0.039cm double #808080" text:number-lines="false" text:line-number="0" style:join-border="false"/> +            <style:text-properties fo:font-size="6pt" style:font-size-asian="6pt" style:font-size-complex="6pt"/> +        </style:style> +        <style:style style:name="Footnote" style:family="paragraph" style:parent-style-name="Standard" style:class="extra"> +            <style:paragraph-properties fo:margin-left="0.5cm" fo:margin-right="0cm" fo:text-indent="-0.5cm" style:auto-text-indent="false" text:number-lines="false" text:line-number="0"/> +            <style:text-properties fo:font-size="10pt" style:font-size-asian="10pt" style:font-size-complex="10pt"/> +        </style:style> +        <style:style style:name="Numbering_20_Symbols" style:display-name="Numbering Symbols" style:family="text"/> +        <style:style style:name="Bullet_20_Symbols" style:display-name="Bullet Symbols" style:family="text"> +            <style:text-properties style:font-name="StarSymbol" fo:font-size="9pt" style:font-name-asian="StarSymbol" style:font-size-asian="9pt" style:font-name-complex="StarSymbol" style:font-size-complex="9pt"/> +        </style:style> +        <style:style style:name="Internet_20_link" style:display-name="Internet link" style:family="text"> +            <style:text-properties fo:color="#000080" style:text-underline-style="solid" style:text-underline-width="auto" style:text-underline-color="font-color"/> +        </style:style> +        <style:style style:name="Emphasis" style:family="text"> +            <style:text-properties fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic"/> +        </style:style> +        <style:style style:name="Strong_20_Emphasis" style:display-name="Strong Emphasis" style:family="text"> +            <style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"/> +        </style:style> +        <style:style style:name="Source_20_Text" style:display-name="Source Text" style:family="text"> +            <style:text-properties style:font-name="Bitstream Vera Sans Mono" style:font-name-asian="Bitstream Vera Sans Mono" style:font-name-complex="Bitstream Vera Sans Mono"/> +        </style:style> +        <style:style style:name="Graphics" style:family="graphic"> +            <style:graphic-properties text:anchor-type="paragraph" svg:x="0cm" svg:y="0cm" style:wrap="dynamic" style:number-wrapped-paragraphs="no-limit" style:wrap-contour="false" style:vertical-pos="top" style:vertical-rel="paragraph" style:horizontal-pos="center" style:horizontal-rel="paragraph"/> +        </style:style> +        <text:outline-style> +            <text:outline-level-style text:level="1" style:num-format=""> +                <style:list-level-properties text:min-label-distance="0.381cm"/> +            </text:outline-level-style> +            <text:outline-level-style text:level="2" style:num-format=""> +                <style:list-level-properties text:min-label-distance="0.381cm"/> +            </text:outline-level-style> +            <text:outline-level-style text:level="3" style:num-format=""> +                <style:list-level-properties text:min-label-distance="0.381cm"/> +            </text:outline-level-style> +            <text:outline-level-style text:level="4" style:num-format=""> +                <style:list-level-properties text:min-label-distance="0.381cm"/> +            </text:outline-level-style> +            <text:outline-level-style text:level="5" style:num-format=""> +                <style:list-level-properties text:min-label-distance="0.381cm"/> +            </text:outline-level-style> +            <text:outline-level-style text:level="6" style:num-format=""> +                <style:list-level-properties text:min-label-distance="0.381cm"/> +            </text:outline-level-style> +            <text:outline-level-style text:level="7" style:num-format=""> +                <style:list-level-properties text:min-label-distance="0.381cm"/> +            </text:outline-level-style> +            <text:outline-level-style text:level="8" style:num-format=""> +                <style:list-level-properties text:min-label-distance="0.381cm"/> +            </text:outline-level-style> +            <text:outline-level-style text:level="9" style:num-format=""> +                <style:list-level-properties text:min-label-distance="0.381cm"/> +            </text:outline-level-style> +            <text:outline-level-style text:level="10" style:num-format=""> +                <style:list-level-properties text:min-label-distance="0.381cm"/> +            </text:outline-level-style> +        </text:outline-style> + +        <text:list-style style:name="Numbering_20_1" style:display-name="Numbering 1"/> +        <text:list-style style:name="List_20_1" style:display-name="List 1"/> + +        <text:notes-configuration text:note-class="footnote" style:num-format="1" text:start-value="0" text:footnotes-position="page" text:start-numbering-at="document"/> +        <text:notes-configuration text:note-class="endnote" style:num-format="i" text:start-value="0"/> +        <text:linenumbering-configuration text:number-lines="false" text:offset="0.499cm" style:num-format="1" text:number-position="left" text:increment="5"/> + +    </office:styles> + +    <office:automatic-styles/> + +    <office:master-styles> +        <style:master-page style:name="Standard" style:page-layout-name="pm1"/> +    </office:master-styles> +</office:document-styles> + diff --git a/vendors/dokuwiki/lib/plugins/odt/syntax.php b/vendors/dokuwiki/lib/plugins/odt/syntax.php new file mode 100644 index 000000000..a8d0832d7 --- /dev/null +++ b/vendors/dokuwiki/lib/plugins/odt/syntax.php @@ -0,0 +1,96 @@ +<?php +/** + * ODT Plugin: Exports to ODT + * + * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author     Andreas Gohr <andi@splitbrain.org> + * @author     Aurelien Bompard <aurelien@bompard.org> + */ +// must be run within Dokuwiki +if(!defined('DOKU_INC')) die(); + +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'syntax.php'); + +class syntax_plugin_odt extends DokuWiki_Syntax_Plugin { + +    /** +     * return some info +     */ +    function getInfo(){ +        return confToHash(dirname(__FILE__).'/info.txt'); +    } + +    /** +     * What kind of syntax are we? +     */ +    function getType(){ +        return 'substition'; +    } + +    /** +     * What about paragraphs? +     */ +    function getPType(){ +        return 'normal'; +    } + +    /** +     * Where to sort in? +     */ +    function getSort(){ +        return 319; // Before image detection, which uses {{...}} and is 320 +    } + +    /** +     * Connect pattern to lexer +     */ +    function connectTo($mode) { +        $this->Lexer->addSpecialPattern('~~ODT~~',$mode,'plugin_odt'); +        $this->Lexer->addSpecialPattern('{{odt>.+?}}',$mode,'plugin_odt'); +    } + +    /** +     * Handle the match +     */ +    function handle($match, $state, $pos, &$handler){ +        // Export button +        if ($match == '~~ODT~~') { return array(); } +        // Extended info +        $match = substr($match,6,-2); //strip markup +        $extinfo = explode(':',$match); +        $info_type = $extinfo[0]; +        if (count($extinfo) < 2) { // no value +            $info_value = ''; +        } elseif (count($extinfo) == 2) { +            $info_value = $extinfo[1]; +        } else { // value may contain colons +            $info_value = implode(array_slice($extinfo,1), ':'); +        } +        return array($info_type, $info_value); +    } + +    /** +     * Create output +     */ +    function render($format, &$renderer, $data) { +        global $ID, $REV; +        if (!$data) { // Export button +            if($format != 'xhtml') return false; +            $renderer->doc .= '<a href="'.exportlink($ID, 'odt', ($REV != '' ? 'rev='.$REV : '')).'" title="'.$this->getLang('view').'">'; +            $renderer->doc .= '<img src="'.DOKU_BASE.'lib/plugins/odt/odt.png" align="right" alt="'.$this->getLang('view').'" width="48" height="48" />'; +            $renderer->doc .= '</a>'; +            return true; +        } else { // Extended info +            list($info_type, $info_value) = $data; +            if ($info_type == "template") { // Template-based export +                $renderer->template = $info_value; +                p_set_metadata($ID, array("relation"=> array("odt"=>array("template"=>$info_value)))); +            } +        } +        return false; +    } + +} + +//Setup VIM: ex: et ts=4 enc=utf-8 :  | 
