WIKINDX PHP Cross Reference Collaborative Wikis

Source: /core/importexport/RICHTEXTFORMAT.php - 1170 lines - 37897 bytes - Summary - Text - Print

   1  <?php
   2  /**
   3  WIKINDX: Bibliographic Management system.
   4  Copyright (C)
   5  
   6  This program is free software; you can redistribute it and/or modify it under the terms
   7  of the GNU General Public License as published by the Free Software Foundation; either
   8  version 2 of the License, or (at your option) any later version.
   9  
  10  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  11  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12  See the GNU General Public License for more details.
  13  
  14  You should have received a copy of the GNU General Public License along with this program;
  15  if not, write to the
  16  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17  
  18  The WIKINDX Team 2012
  19  sirfragalot@users.sourceforge.net
  20  */
  21  /**
  22  *    RICHTEXTFORMAT extends TINYMCETEXTEXPORT
  23  */
  24  include_once ("core/importexport/TINYMCETEXTEXPORT.php");
  25  
  26  /**
  27  * RTF encoding
  28  * 
  29  * NB - this produces just the bare minimum of RTF code to work in Word and OO.org
  30  * @version    1
  31  *
  32  *    @package wikindx4\core\importexport
  33  *    @author Mark Grimshaw <sirfragalot@users.sourceforge.net>
  34  *
  35  */
  36  class RICHTEXTFORMAT extends TINYMCETEXTEXPORT
  37  {
  38  /** array */
  39  private $vars;
  40  /** array */
  41  private $fontBlocks = array();
  42  /** array */
  43  private $colours = array();
  44  /** string */
  45  private $defaultFontBlock;
  46  /** string */
  47  public $fontBlock = FALSE;
  48  /** string */
  49  public $colourTable = FALSE;
  50  /** 
  51  * array 
  52  *
  53  * default black font and blue for hyperlinks
  54  */
  55  public $colourArray = array('\\red0\\green0\\blue0', '\\red0\\green0\\blue255'); // default black font and blue for hyperlinks
  56  /** string */
  57  public $lineSpacing;
  58  /** string */
  59  private $listOverrideTable;
  60  /** string */
  61  public $listTable;
  62  /** string */
  63  private $listType;
  64  /** int */
  65  private $listId;
  66  /** int */
  67  private $listIndex = 2;
  68  /** int */
  69  private $listIndent = 720;
  70  /** int */
  71  private $listIndentExtra = 360;
  72  /** object */
  73  private $wpConfig;
  74  /** string */
  75  private $imConvertPath = FALSE;
  76  /** int */
  77  private $quoteNumWords;
  78  /** boolean */
  79  private $keepQuoteMarks;
  80  /** string */
  81  private $quoteFontSize;
  82  /** string */
  83  private $qme;
  84  /** string */
  85  private $qms;
  86  
  87  /**
  88  * RICHTEXTFORMAT
  89  *
  90  * @param string $imgMagickPath
  91  */
  92  	public function __construct($imgMagickPath = FALSE)
  93      {
  94          parent::initClass('rtf');
  95          $this->vars = GLOBALS::getVars();
  96          if($imgMagickPath)
  97              $this->imConvertPath = $imgMagickPath;
  98          else if(file_exists("plugins/wordProcessor/index.php"))
  99          {
 100              include_once("plugins/wordProcessor/config.php");
 101              $this->wpConfig = new wordProcessor_CONFIG();
 102              if($this->wpConfig->imageMagickConvertUtilityPath)
 103              {
 104                  $this->imConvertPath = $this->wpConfig->imageMagickConvertUtilityPath . 'convert';
 105                  if(!file_exists($this->imConvertPath))
 106                      die("Image Magick path defined in config.php but convert utility not found");
 107              }
 108              else if(file_exists("/usr/bin/convert"))
 109                  $this->imConvertPath = '/usr/bin/convert';
 110              else if(file_exists("/usr/bin/local/convert"))
 111                  $this->imConvertPath = '/usr/bin/local/convert';
 112              else if(file_exists("/usr/local/bin/convert"))
 113                  $this->imConvertPath = '/usr/bin/local/convert';
 114          }
 115  // set up defaults and parameters
 116          $this->init();
 117      }
 118  /**
 119  * Initialize RTF values either as defaults or from user-requested settings
 120  */
 121  	private function init()
 122      {
 123  // Line spacing of main paper body
 124          if($this->session->getVar('wp_ExportPaperSpace') == 'oneHalfSpace')
 125              $this->lineSpacing = '\\sl360\\slmult1';
 126          else if($this->session->getVar('wp_ExportPaperSpace') == 'doubleSpace')
 127              $this->lineSpacing = '\\sl480\\slmult1';
 128          else
 129              $this->lineSpacing = '';
 130          $this->paperSize = $this->session->getVar('wp_ExportPaperSize');
 131  // Line spacing of indented quotations
 132          if($this->session->getVar('wp_ExportSpaceIndentQ') == 'oneHalfSpace')
 133              $this->lineSpacingIndentQ = '\\sl360\\slmult1';
 134          else if($this->session->getVar('wp_ExportSpaceIndentQ') == 'doubleSpace')
 135              $this->lineSpacingIndentQ = '\\sl480\\slmult1';
 136          else
 137              $this->lineSpacingIndentQ = '\\sl240\\slmult1'; // singlepublic $paperSize = FALSE;
 138          $fontSizes = array(16, 20, 24, 28, 36, 48, 72);
 139          $temp = array();
 140          foreach($this->fontSizes as $value)
 141              $temp[$value] = array_shift($fontSizes);
 142          $this->fontSizes = $temp;
 143          $this->footnoteText = FALSE;
 144          $this->tableStyle = FALSE;
 145          $this->justify = array(
 146                              "center"    =>    "\\qc",
 147                              "left"        =>    "\\ql",
 148                              "right"        =>    "\\qr",
 149                              "justify"    =>    "\\qj",
 150                          );
 151  /**
 152  * Lists:
 153  * \\ls0 => a, b ('a')
 154  * \\ls5 => A, B ('aa')
 155  * \\ls2 => i, ii ('i')
 156  * \\ls3 => I, II ('ii')
 157  * \\ls4 => 1, 2
 158  * \\ls1 => bullets -- currently, only this one is used from this array.  Arabic numbered lists are handled in the code.
 159  */
 160          $this->lists = array(
 161                              'aa'    =>    "\\ls5\\fi-360",
 162                              'a'        =>    "\\ls0\\fi-360",
 163                              'ii'    =>    "\\ls3\\fi-360",
 164                              'i'        =>    "\\ls2\\fi-360",
 165                              '1'        =>    "\\ls4\\fi-360",
 166                              'bullet'    =>    "\\ls1\\fi-360",
 167                          );
 168          $this->fontIndex = 1;
 169          $this->listIndex = 2;
 170          $this->defaultFontBlock = "{\\f0\\fcharset0 Arial;}\n";
 171          $this->listOverrideTable = "{\\listoverride\\listid1\\ls1}\n";
 172  // Default bullets - 'listid1' == bullets, 'listidN' where 'N' is greater than 1 == Arabic
 173  // $this->listTable is closed in $this->closeListTable() below
 174          $this->listTable = "{\\*\\listtable\n
 175          {\\list
 176          {\\listlevel\\levelnfc23\\levelstartat1\\levelfollow0{\\leveltext \\'01\\u8226 ?;}{\\levelnumbers;}\\fi-360\\li720}
 177          \\listid1}\n";
 178      }
 179  /**
 180  * Set some defaults and create the RTF opening tag
 181  *
 182  * @return string
 183  */
 184  	public function header()
 185      {
 186          $this->lineSpacingIndentQ = "\n" . $this->lineSpacingIndentQ . "\n";
 187          $text = "{\\rtf1\\ansi\\ansicpg1252\n\n";
 188  // 'letter' is default size for RTF -- presumably, 'legal' has the default width of 'letter'
 189  // The tables always go beyond the paper width so we set each table width to 96% of standard
 190          if($this->paperSize == 'letter')
 191              $this->tableWidth = floor(8748 * 0.96);
 192          else if($this->paperSize == 'A4')
 193          {
 194              $text .= "\\paperw11909\\paperh16834\n\n";
 195              $this->tableWidth = floor(8417 * 0.96);
 196          }
 197          else if($this->paperSize == 'A5')
 198          {
 199              $text .= "\\paperw8395\\paperh11909\n\n";
 200              $this->tableWidth = floor(4903 * 0.96);
 201          }
 202          else if($this->paperSize == 'legal')
 203          {
 204              $text .= "\\paperh20160\n\n";
 205              $this->tableWidth = floor(8748 * 0.96);
 206          }
 207          else if($this->paperSize == 'executive')
 208          {
 209              $text .= "\\paperw10440\\paperh15120\n\n";
 210              $this->tableWidth = floor(6948 * 0.96);
 211          }
 212          return $text . "\n\n";
 213      }
 214  /**
 215  * Create the RTF closing tag
 216  *
 217  * @return string
 218  */
 219  	public function footer()
 220      {
 221          return "\n}\n";
 222      }
 223  /**
 224  * parse tinyMCE code to RTF tags
 225  *
 226  * @author Mark Grimshaw
 227  * @version 1
 228  * @param string input text
 229  * @return string parsed text
 230  */
 231  	public function parse($text)
 232      {
 233  //print htmlentities($text); die;
 234  ///        include_once("core/cite/CITE.php");
 235  ///        $cite = new CITE($this->db, $this->vars);
 236          $text = $this->formatText($text);
 237  
 238  // handle <font>...</font> MAY NOT BE NEEDED
 239  //        $text = $this->parseFont($text, array($this, "styleCallback"));
 240  // handle <span>...</span>
 241          $text = $this->parseSpan($text, array($this, "styleCallback"));
 242          $text = $this->parseLists($text, array($this, "callbackUnorderedList"), array($this, "callbackOrderedList"));
 243  // Handle tables
 244          $text = $this->createTables($text);
 245  // Handle images
 246          $text = preg_replace_callback("/<img.*[>]+/Usi", array($this, "imageCallback"), $text);
 247  // URL + emails
 248          $text = $this->createEmail($text);
 249          $text = $this->createFancyUrl($text);
 250  /*
 251  // Handle <div>...</div>
 252          $text = $this->rtf->parseDiv($text);
 253  //print "FINAL: " . htmlentities($text) . "<P>";
 254  // Ensure there are no hanging HTML tags (some browsers produce untidy HTML or superfluous HTML)
 255          $patterns = array(
 256              "/<\/div>/iU",
 257              "/<\/span>/iU",
 258              "/<\/font>/iU",
 259              );
 260          $text = preg_replace($patterns, '', $text);
 261  */
 262  // indent long quotations
 263          if(array_key_exists('exportIndentQuoteWords', $this->vars))
 264          {
 265              $quoteIndentWords = $this->vars['exportIndentQuoteWords'];
 266              if(is_numeric($quoteIndentWords))
 267              {
 268                  settype($quoteIndentWords, "integer");
 269                  if(array_key_exists('exportIndentQuoteFontSize', $this->vars))
 270                      $indentQuoteFontSize = $this->vars['exportIndentQuoteFontSize'];
 271                  else
 272                      $indentQuoteFontSize = 8; // font size 16 in RTF
 273                  if(($sizeKey = array_search($indentQuoteFontSize * 2, $this->fontSizes)) !== FALSE)
 274                      $this->quoteFontSize = $this->fontSizes[$sizeKey];
 275                  else
 276                      $this->quoteFontSize = $this->fontSizes['large']; // font size 9/18
 277                  if(array_key_exists('exportIndentQuoteMarks', $this->vars))
 278                      $indentQuoteMarks = TRUE;
 279                  else
 280                      $indentQuoteMarks = FALSE;
 281                  $text = $this->indentQuotations($text, $quoteIndentWords, $indentQuoteFontSize, $indentQuoteMarks);
 282  // Perhaps footnote immediately follows (so should be part of indent) -- NB indentQ() method in WPRTF.php
 283  //print "TEXT1: $text<P>";
 284                  $text = preg_replace_callback("/(\[\/cite\][.,:;?!°ø])(\s*__WIKINDX__NEWLINEPAR__}__WIKINDX__NEWLINEPAR____WIKINDX__QUOTEINDENTREMOVESPACE__\}*)(\[footnote\].*\[\/footnote\])/Usi", 
 285                      array($this, "callback_footnoteIndent"), $text);
 286  //print "TEXT2: $text<P>";
 287  //                $pattern =     "__WIKINDX__QUOTEINDENTDONE__|__WIKINDX__NEWLINE__|__WIKINDX__QUOTEINDENTREMOVESPACE__(\s*)|__WIKINDX__QUOTEINDENTREMOVESPACE__\}*(\s*)";
 288                  $text = preg_replace("/$pattern/", "\n", $text);
 289              }
 290          }
 291  // Deal with citations
 292          $text = $this->cite->parseCitations($text, 'rtf', FALSE, FALSE, TRUE);
 293  //print "TEXT3: $text<P>";
 294  // handles section breaks
 295          $text = preg_replace("/(__WIKINDX__NEWLINEPAR__)*__WIKINDX__SECTION__(__WIKINDX__NEWLINEPAR__)*/", 
 296              "\n\n{\\sect}\n\\sectd\n\n", $text);
 297  // Replace temporary newlines
 298          $text = str_replace("__WIKINDX__NEWLINEPAR__", "\\par\n", $text);
 299  //        $text = str_replace("__WIKINDX__NEWLINE__", "\n", $text);
 300          $text = str_replace("&nbsp;", " ", $text);
 301  //        $text = str_replace("__WIKINDX__QUOTEINDENTDONE__", "\n", $text);
 302          $pattern = "__WIKINDX__QUOTEINDENTDONE__|__WIKINDX__NEWLINE__|__WIKINDX__QUOTEINDENTREMOVESPACE__(\s*)";
 303          $text = preg_replace("/$pattern/", "\n", $text);
 304  // when user is cut 'n' pasting, superfluous codes are sometimes inserted so remove them
 305          $text = preg_replace("/[ ]*<span.*[>]+(.*)<\/span[>]+[ ]*/Usi", "$1", $text);
 306  // Deal with footnotes
 307          if(array_key_exists('exportFontSizeFt', $this->vars))
 308              $fontSizeFt = $this->vars['exportFontSizeFt'];
 309          else
 310              $fontSizeFt = 8; // font size 16 in RTF
 311          $text = $this->parseFootnotes($text, $footnoteOffsetIds, $fontSizeFt);
 312          if($this->footnoteText)
 313              $text .= $this->footnoteText;
 314          $text = str_replace('__WIKINDX__ENDNOTE__START__', '', $text);
 315          $text = str_replace('__WIKINDX__ENDNOTE__END__', '', $text);
 316          $text = str_replace(" } ", " }", $text);
 317  // Sometimes (not sure why), single quote gets replaced as &#039; so replace it
 318          $text = str_replace("&#039;", "'", $text);
 319  // sometimes, with footnote/endnote styles, __WIKINDX__ gets left behind.  Temp. FIX.
 320          $text = str_replace("__WIKINDX__\par\qj __", "", $text);
 321          if(!empty($this->fontBlocks))
 322          {
 323              $this->fontBlock = "{\\fonttbl\n";
 324              $this->fontBlock .= $this->defaultFontBlock;
 325              foreach($this->fontBlocks as $index => $font)
 326                  $this->fontBlock .= "{\\f$index\\fcharset0 $font;}\n";
 327              $this->fontBlock .= "}\n\n";
 328          }
 329          $this->colourTable = "{\\colortbl;";
 330          foreach($this->colourArray as $colour)
 331              $this->colourTable .= $colour . ';';
 332          $this->colourTable .= "}\n\n";
 333          $this->closeListTable();
 334          return $this->utf8_2_unicode($text);
 335      }
 336  /**
 337  * Format text for HTML characters
 338  *
 339  * @param string $text
 340  * @return string
 341  */
 342  	public function formatText($text)
 343      {
 344  // Deal with potential RTF control characters first
 345          $text = str_replace("\\", "\\\\", $text);
 346          $text = str_replace("{", "\\{", $text);
 347          $text = str_replace("}", "\\}", $text);
 348  // Replace CR and newline characters and combinations with a single space
 349          $text = preg_replace("/(\r\n)+|(\n\r)+|\n+|\r+/", ' ', $text);
 350  // Simple substitutions - italics and bold sometimes come in as standard HTML tags if they were copy 'n' pasted from elsewhere.
 351          $pattern = array(
 352  //                            "/\s*<br>\s*<\/p>/si",
 353  //                            "/\s*(.*?)\s*<br>/si",
 354                              "/<hr>/si",
 355                              "/<p>\s*(.*?)\s*<\/p>\s*/si",
 356                              "/<sup>(.*?)<\/sup>/si",
 357                              "/<sub>(.*?)<\/sub>/si",
 358                              "/&amp;/si",
 359                              "/\s*<br.*?>\s*/si",
 360                              "/<em>(.*?)<\/em>/si",
 361                              "/<i>(.*?)<\/i>/si",
 362                              "/<strong>(.*?)<\/strong>/si",
 363                              "/<b>(.*?)<\/b>/si",
 364                              "/&lt;/si",
 365                              "/&gt;/si",
 366                          );
 367          $change = array(
 368  //                            "</p>",
 369  //                            "\\s1\\cf1$1__WIKINDX__NEWLINEPAR__", // temporary replace
 370                              "__WIKINDX__SECTION__",
 371                              "{__WIKINDX__NEWLINEPAR____WIKINDX__NEWLINEPAR__$1}", // temporary replace
 372                              "{\\super $1}",
 373                              "{\\sub $1}",
 374                              "&",
 375                              "{__WIKINDX__NEWLINEPAR__}",
 376                              "{\\i $1}",
 377                              "{\\i $1}",
 378                              "{\\b $1}",
 379                              "{\\b $1}",
 380                              "\\u60 ?",
 381                              "\\u62 ?",
 382                          );
 383          return preg_replace($pattern, $change, $text);
 384      }
 385  /**
 386  * Callback for adding a footnote to an indented quotation.
 387  *
 388  * @param array $matches
 389  * @return string
 390  */
 391  	private function callback_footnoteIndent($matches)
 392      {
 393          return $matches[1] . $matches[3] . $matches[2];
 394      }
 395  /**
 396  * Create list tables for Arabic numerals
 397  */
 398  	private function createListTablesArabic()
 399      {
 400          $this->listTable .= "
 401  {\\list
 402  {\\listlevel\\levelnfc0\\levelstartat1\\levelfollow0{\\leveltext \\'02\\'00.;}{\\levelnumbers\\'01;}\\fi-360\\li720}\\listid" . $this->listIndex . "}\n
 403  ";
 404          $this->listId = "\\ls" . $this->listIndex;
 405          $this->listOverrideTable .= 
 406  "{\\listoverride\\listid" . $this->listIndex . $this->listId . "}\n";
 407          ++$this->listIndex;
 408      }
 409  /**
 410  * Close the list table and append the listOverrideTable string
 411  */
 412  	public function closeListTable()
 413      {
 414          $this->listTable .= "}\n" . "{\\listoverridetable\n" . $this->listOverrideTable . "}\n\n";
 415      }
 416  /**
 417  * Create fancy url hyperlinks
 418  *
 419  * @param string $text
 420  * @return string
 421  */
 422  	public function createFancyUrl($text)
 423      {
 424          return preg_replace_callback("/<a\s*.*\s*href\s*=\s*\"http:\/\/(.*)\"\s*.*\s*>(.*)<\/a>/Usi",
 425              array($this, "setFancyUrl"), $text);
 426      }
 427  /**
 428  * Create email hyperlinks
 429  *
 430  * @param string $text
 431  * @return string
 432  */
 433  	private function createEmail($text)
 434      {
 435          return preg_replace_callback("/<a\s*href\s*=\s*\"mailto:(.*)\"\s*>(.*)<\/a>/Usi",
 436              array($this, "setEmail"), $text);
 437      }
 438  /**
 439  * Callback for createFancyUrl() above
 440  *
 441  * @param array $matchArray
 442  * @return string
 443  */
 444  	private function setFancyUrl($matchArray)
 445      {
 446          $url = trim($matchArray[1]);
 447          $text = preg_replace("/^__WIKINDX__NEWLINEPAR__|__WIKINDX__NEWLINEPAR__$/", '', $matchArray[2]);
 448          return "{\\field{\\fldinst { HYPERLINK \"http://$url\" }}{\\fldrslt {\\cs1\\ul\\cf2 $text}}}__WIKINDX__NEWLINE__";
 449      }
 450  /**
 451  * Callback for createEmail() above
 452  *
 453  * @param array $matchArray
 454  * @return string
 455  */
 456  	private function setEmail($matchArray)
 457      {
 458          $email = preg_replace("/^__WIKINDX__NEWLINEPAR__|__WIKINDX__NEWLINEPAR__$/", '', $matchArray[1]);
 459          return "{\\field{\\fldinst { HYPERLINK \"mailto:$email\" }}{\\fldrslt {\\cs1\\ul\\cf2 $email}}}__WIKINDX__NEWLINE__";
 460      }
 461  /**
 462  * Set font types and create top level font blocks
 463  *
 464  * @param string $font
 465  * @return int Font index
 466  */
 467  	private function createFontBlocks($font)
 468      {
 469          $fonts = explode(',', $font);
 470          $font = $fonts[0];
 471          $fontIndex = $this->setFontBlock($font);
 472          return $fontIndex;
 473      }
 474  /**
 475  * Set font blocks
 476  *
 477  * @param string $font
 478  * @return int Font index
 479  */
 480  	private function setFontBlock($font)
 481      {
 482          if(array_search(strtolower($font), $this->fonts) === FALSE)
 483              $font = 'arial';
 484          if(($index = array_search($font, $this->fontBlocks)) === FALSE)
 485          {
 486              $this->fontBlocks[$this->fontIndex] = $font;
 487              $fontIndex = $this->fontIndex;
 488              ++$this->fontIndex;
 489          }
 490          else
 491              $fontIndex = $index;
 492          return $fontIndex;
 493      }
 494  /**
 495  * Find any tables
 496  *
 497  * @param string $text
 498  * @return string
 499  */
 500  	private function createTables($text)
 501      {
 502          return preg_replace_callback("/\s*<table(.*)>\s*(.*)\s*<\/table>\s*/Usi",
 503              array($this, "tableFormat"), $text);
 504      }
 505  /**
 506  * Format Tables
 507  *
 508  * We've no way of knowing the browser window size from PHP so we assume a width of 1000 -- if the resultant tableWidth is higher 
 509  * than $this->tableWidth, we limit it to $this->tableWidth.
 510  * Must count the number of cells in each row and divide them into $tableWidth to get cell width.
 511  *
 512  * @param array $matchArray
 513  * @return string
 514  */
 515  	private function tableFormat($matchArray)
 516      {
 517          $text = preg_replace("/^__WIKINDX__NEWLINEPAR__|__WIKINDX__NEWLINEPAR__$/", '', $matchArray[2]);
 518          preg_match("/width.*(\d+)px/Usi", $matchArray[1], $array);
 519          $tableWidth = array_key_exists(1, $array) ? $this->tableWidth * $array[1] / 1000 : $this->tableWidth;
 520          $tableWidth = $tableWidth > $this->tableWidth ? $this->tableWidth : floor($tableWidth);
 521          $row = "\n\\trowd\\trql\\trpaddft3\\trpaddt55\\trpaddfl3\\trpaddl55\\trpaddfb3\\trpaddb55\\trpaddfr3\\trpaddr55__WIKINDX__NEWLINE__";
 522          $cell = "\\clbrdrt\\brdrs\\brdrw1\\brdrcf1\\clbrdrl\\brdrs\\brdrw1\\brdrcf1\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\clbrdrr\\brdrs\\brdrw1\\brdrcf1";
 523          $finalCell = "\\clbrdrt\\brdrs\\brdrw1\\brdrcf1\\clbrdrl\\brdrs\\brdrw1\\brdrcf1\\clbrdrb\\brdrs\\brdrw1\\brdrcf1\\clbrdrr\\brdrs\\brdrw1\\brdrcf1\\cellx" . $tableWidth . "__WIKINDX__NEWLINE__";
 524          preg_match_all("/\s*<tr.*>\s*(.*)\s*\<\/tr>\s*/Usi", $text, $matches);
 525  // Count no. table cells in each row
 526          $output = '';
 527          foreach($matches[1] as $data)
 528          {
 529              $cellString = '\\intbl\n ';
 530              $rowString = $row;
 531              $numCells = preg_match_all("/\s*<td(.*)>\s*(.*)\s*\<\/td>\s*/Usi", $data, $cells);
 532              if(empty($cells))
 533                  return $output;
 534              $cellText = $cells[2];
 535              $cellStyle = $cells[1];
 536              $width = $baseWidth = floor($tableWidth / $numCells);
 537              $cellNumber = 1;
 538  //print_r($cells); print "<P>";
 539              foreach($cellText as $cellData)
 540              {
 541                  if($cellNumber != $numCells)
 542                      $rowString .= $cell . "\\cellx$width" . "__WIKINDX__NEWLINE__";
 543                  else
 544                      $rowString .= $finalCell;
 545                  $cellData = preg_replace("/^__WIKINDX__NEWLINEPAR__|__WIKINDX__NEWLINEPAR__$/", '', $cellData);
 546                  if(preg_match("/style\s*=\s*\"(.*?)\"/si", array_shift($cellStyle), $styleMatch))
 547                  {
 548                      $this->tableStyle = TRUE;
 549                      $cellData = $this->style($styleMatch[1], $cellData);
 550                  }
 551                  else
 552                  {
 553                      $cellData .= "\\cell";
 554                      $this->tableStyle = FALSE;
 555                  }
 556                  $cellString .= $cellData . "__WIKINDX__NEWLINE__\\s1\\cf1";
 557                  ++$cellNumber;
 558                  $width += $baseWidth;
 559              }
 560              $output .= $rowString . $cellString . "\\row\\pard" . $this->lineSpacing . "\n\n";
 561          }
 562          $this->tableStyle = FALSE;
 563          return "{__WIKINDX__NEWLINEPAR____WIKINDX__NEWLINEPAR__}" . $output;
 564      }
 565  /**
 566  * Callback for createLists()
 567  *
 568  * Unordered lists.
 569  * NB - IE sometimes closes the <li> tag sometimes doesn't - bravo!
 570  * @param array $matchArray
 571  * @return string
 572  */
 573  	protected function callbackUnorderedList($matchArray)
 574      {
 575          $this->listType = $this->lists['bullet'] . '\\li' . ($this->listIndent + $this->nested * $this->listIndentExtra);
 576          $text = $matchArray[1];
 577          $text = preg_replace("/\s*<li>\s*(.*?)\s*<\/li>\s*/si", 
 578              $this->listType . ' {' . "$1}\\par__WIKINDX__NEWLINE__", $text);
 579          $text = preg_replace_callback("/\s*<li\s*style\s*=\s*\"(.*?)\">\s*(.*?)\s*<\/li>\s*/si", 
 580              array($this, "listStyleCallback"), $text);
 581          $text = preg_replace("/\s*<li>\s*(.*?)\s*/si", 
 582              $this->listType . ' {' . "$1}\\par__WIKINDX__NEWLINE__", $text);
 583          $text = preg_replace_callback("/\s*<li\s*style\s*=\s*\"(.*?)\">\s*(.*?)\s*/si", 
 584              array($this, "listStyleCallback"), $text);
 585          return "\\par\n$text" . "\\pard" . $this->lineSpacing . "\\par\n";
 586      }
 587  /**
 588  * Callback for createLists() 
 589  *
 590  * Ordered Lists.
 591  * NB - IE sometimes closes the <li> tag sometimes doesn't - bravo!
 592  * @param array $matchArray
 593  * @return string
 594  */
 595  	protected function callbackOrderedList($matchArray)
 596      {
 597          $this->createListTablesArabic();
 598          $this->listType = $this->listId . "\\fi-360\\li" . $this->listIndent;
 599          $text = $matchArray[1];
 600          $text = preg_replace("/\s*<li>\s*(.*?)\s*<\/li>\s*/si", 
 601              $this->listType . ' {' . "$1}\\par__WIKINDX__NEWLINE__", $text);
 602          $text = preg_replace_callback("/\s*<li\s*style\s*=\s*\"(.*?)\">\s*(.*?)\s*<\/li>\s*/si", 
 603              array($this, "listStyleCallback"), $text);
 604          $text = preg_replace("/\s*<li>\s*(.*?)\s*/si", 
 605              $this->listType . ' {' . "$1}\\par__WIKINDX__NEWLINE__", $text);
 606          $text = preg_replace_callback("/\s*<li\s*style\s*=\s*\"(.*?)\">\s*(.*?)\s*/si", 
 607              array($this, "listStyleCallback"), $text);
 608          return "\\par\n$text" . "\\pard" . $this->lineSpacing . "\\par\n";
 609      }
 610  /**
 611  * For the cases where a list element has style information
 612  *
 613  * @param array $match
 614  * @return string
 615  */
 616  	private function listStyleCallback($match)
 617      {
 618          $text = trim($match[2]);
 619          $text = $this->style($match[1], $text);
 620          return $this->listType . " {$text}\\par__WIKINDX__NEWLINE__";
 621      }
 622  /**
 623  * Read an image from either file or URL
 624  *
 625  * @param array $matchArray
 626  * @return string
 627  */
 628  	public function imageCallback($matchArray)
 629      {
 630          $editW = $editH = FALSE;
 631          if(preg_match("/src\s*=\s*\"(.*)\"/Usi", $matchArray[0], $array))
 632              $file = $array[1];
 633          else if(array_key_exists(1, $matchArray))
 634              $file = $matchArray[1];
 635          else
 636              return $matchArray[0]; // unable to read file so return link
 637          preg_match("/width.*(\d*)px/Usi", $matchArray[0], $array);
 638          if(array_key_exists(1, $array))
 639              $editW = $array[1];
 640          preg_match("/height.*(\d*)px/Usi", $matchArray[0], $array);
 641          if(array_key_exists(1, $array))
 642              $editH = $array[1];
 643  // Currently just working for JPEG and PNG in both OO.org and Word. (NB - Word can open GIFs processed here.)
 644          $tempFile = FALSE;
 645          if($fp = @fopen($file, "rb")) // don't do anything on file read error
 646          {
 647              list($width, $height, $type, $atrr) = GetImageSize($file);
 648              if(!$editW || !$editH)
 649                  $blipScale = "\\picscalex100\\picscaley100";
 650              else
 651              {
 652                  $scaleX = floor(100 * ($editW/$width));
 653                  $scaleY = floor(100 * ($editH/$height));
 654                  $blipScale = "\\picscalex$scaleX\\picscaley$scaleY";
 655              }
 656              if($type == 2) // JPEG
 657                  $blipType = "\\jpegblip";
 658              else if($type == 3) // PNG
 659                  $blipType = "\\pngblip";
 660              else
 661              {
 662                  $blipType = "\\pngblip";
 663                  $tempFile = "files/" . session_id() . ".png";
 664  // Try to run imageMagick convert utility if available (probably just on *NIX) to convert to a PNG
 665                  if($this->imConvertPath)
 666                      exec("$this->imConvertPath $file $tempFile");
 667                  else
 668                      return $matchArray[0]; // unable to read file so return link
 669              }
 670              $out = "";
 671              if($tempFile)
 672              {
 673                  fclose($fp);
 674                  $fp = fopen($tempFile, "rb");
 675                  @unlink($tempFile);
 676              }
 677              while (!feof($fp))
 678              {
 679                  $file = fread($fp, 64);
 680                  $out .= bin2hex($file) . "__WIKINDX__NEWLINE__";
 681              }
 682              return "{\\pict__WIKINDX__NEWLINE__" . $blipScale . $blipType . "__WIKINDX__NEWLINE__" . $out . "}";
 683          }
 684          return $matchArray[0]; // unable to read file so return link
 685      }
 686  /**
 687  * callback for HTML style elements of font and span
 688  *
 689  * @author Mark Grimshaw
 690  * @version 1
 691  * @param array $match
 692  * @return string
 693  */
 694  	protected function styleCallback($match)
 695      {
 696  /*
 697  $temp = $match;
 698  array_shift($temp);
 699  print "MATCH: "; 
 700  foreach($temp as $value)
 701      print htmlentities($value) . "<P>";
 702  print "<BR>";
 703  */
 704          if($this->spanParse)
 705              $text = $match[2];
 706          else
 707              $text = trim($match[3]);
 708          $newText = $this->style($match[1], $text);
 709          return $newText;
 710      }
 711  /**
 712  * callback for HTML style elements of <P>
 713  *
 714  * @author Mark Grimshaw
 715  * @version 1
 716  * @param array $match
 717  * @return string
 718  */
 719  	function paraCallback($match)
 720      {
 721          $text = $match[2];
 722          return $this->paraStyle($match[1], $text) . "__WIKINDX__NEWLINEPAR____WIKINDX__NEWLINEPAR__";
 723      }
 724  /**
 725  * Convert hexadecimal colours to RTF colours
 726  *
 727  * @param string $colour
 728  * @return string
 729  */
 730  	private function convertColour($colour)
 731      {
 732          $colour = rtrim(ltrim($colour));
 733          $colorVal = hexdec($colour);
 734          $rgbArray['red'] = 0xFF & ($colorVal >> 0x10);
 735          $rgbArray['green'] = 0xFF & ($colorVal >> 0x8);
 736          $rgbArray['blue'] = 0xFF & $colorVal;
 737          $colour = '\\red' . $rgbArray['red'];
 738          $colour .= '\\green' . $rgbArray['green'];
 739          $colour .= '\\blue' . $rgbArray['blue'];
 740          if(($index = array_search($colour, $this->colourArray)) !== FALSE)
 741              $index++;
 742          else
 743          {
 744              $this->colourArray[] = $colour;
 745              $index = sizeof($this->colourArray);
 746          }
 747          return "\\s1\\cf$index";
 748      }
 749  /**
 750  * deal with style elements for DIV and SPAN
 751  *
 752  * @author Mark Grimshaw
 753  * @version 1
 754  * @param string $styleString
 755  * @param string $text
 756  * @return string
 757  */
 758  	private function style($styleString, $text)
 759      {
 760  //print "STYLESTRING: $styleString<P>";
 761          $text = str_replace(" ", "WIKINDX_SPACE", $text);
 762          if($this->isIE)
 763              $params = explode('&nbsp;', $styleString);
 764          else
 765              $params = explode(";", $styleString);
 766  //print_r($params); print "<P>";
 767          $justify = $pixelsR = $pixelsL = $indentL = $indentR = FALSE;
 768          $slashCellAdded = FALSE;
 769  //print_r($params); print ": $text<P>";
 770          foreach($params as $param)
 771          {
 772              if(!$param)
 773                  continue;
 774              if($this->isIE)
 775                  $splitParam = explode("=", $param);
 776              else
 777                  $splitParam = explode(":", $param);
 778              if(!array_key_exists(1, $splitParam)) // not recognised - usually result of pasting from Office etc.
 779                  continue;
 780  //print "PARAM: $param<BR>";
 781  //print "#" . $splitParam[0] . "# | #" . $splitParam[1] . "#<P>";
 782              $param0 = strtolower(trim($splitParam[0]));
 783              $param1 = trim(str_replace('"', '', $splitParam[1]));
 784  //print html_entity_decode("param0: $param0; param1: $param1<P>");
 785  //print "$param0<P>";
 786              if(($param0 == 'font-weight') && ($param1 == 'bold'))
 787                  $text = "{\\b\n$text}";
 788              else if(($param0 == 'font-weight') && ($param1 == 'normal'))
 789                  $text = "{$text}";
 790              else if(($param0 == 'text-decoration') && ($param1 == 'underline'))
 791                  $text = "{\\ul $text}";
 792              else if(($param0 == 'font-style') && ($param1 == 'italic'))
 793                  $text = "{\\i\n$text}";
 794              else if($param0 == 'color')
 795              {
 796                  $colour = $this->convertColour($param1);
 797                  $text = '__WIKINDX__NEWLINE__{' . "$colour" . "__WIKINDX__NEWLINE__$text}";
 798              }
 799              else if($param0 == 'font-family')
 800              {
 801                  $fontIndex = $this->createFontBlocks($param1);
 802                  $text = "{\\f$fontIndex $text}__WIKINDX__NEWLINE__";
 803              }
 804              else if($param0 == 'face')
 805              {
 806                  $fontIndex = $this->createFontBlocks($param1);
 807                  $text = "{\\f$fontIndex $text}__WIKINDX__NEWLINE__";
 808              }
 809              else if($param0 == 'font-size')
 810              {
 811                  $fontSize = $this->fontSizes[$param1];
 812                  $text = "{\\fs$fontSize $text}__WIKINDX__NEWLINE__";
 813              }
 814              else if($param0 == 'text-align')
 815                  $justify = $param1;
 816              else if($param0 == 'margin-left')
 817              {
 818                  if(preg_match("/(\d+)/", $param1, $array))
 819                      $indentL = '\\li' . $array[1] * 18;
 820              }
 821              else if($param0 == 'margin-right')
 822              {
 823                  if(preg_match("/(\d+)/", $param1, $array))
 824                      $indentR = '\\ri' . $array[1] * 18;
 825              }
 826          }
 827  // Although it works in OO.org, for Word, justification needs to be outside {...} and therefore not mixed up with bold, italics etc.  so deal with it last.
 828          if($justify)
 829          {
 830              if(!array_key_exists($justify, $this->justify))
 831                  $justify = $this->justify['justify'];
 832              else
 833                  $justify = $this->justify[$justify];
 834              if($this->tableStyle)
 835              {
 836                  $text = "{" . "$justify\n$text \\cell}\n";
 837                  $slashCellAdded = TRUE;
 838              }
 839              else
 840                  $text = "$justify\n$text\n";
 841          }
 842          if($this->tableStyle && !$slashCellAdded)
 843              $text .= "\\cell";
 844          if($indentL || $indentR)
 845              $text = "\par$indentL$indentR\n" . '{' . "$text\par}\n\n\\li0\\ri0\n";
 846              $text = str_replace("WIKINDX_SPACE", " ", $text);
 847          return $text;
 848      }
 849  /**
 850  * deal with <P> parameters
 851  *
 852  * @author Mark Grimshaw
 853  * @version 1
 854  * @param string $param
 855  * @param string $text
 856  * @return string
 857  */
 858  	function paraStyle($param, $text)
 859      {
 860          $text = str_replace(" ", "&nbsp;", $text);
 861          $justify = $pixelsR = $pixelsL = $indentL = $indentR = FALSE;
 862          $justify = trim($param);
 863  // Although it works in OO.org, for Word, justification needs to be outside {...} and therefore not mixed up with bold, italics etc.  so deal with it last.
 864          if($justify)
 865          {
 866              if(!array_key_exists($justify, $this->justify))
 867                  $justify = $this->justify['justify'];
 868              else
 869                  $justify = $this->justify[$justify];
 870              $text = "$justify\n$text\n";
 871          }
 872          if($pixelsL)
 873          {
 874              if(!array_key_exists($pixelsL, $this->indentL))
 875                  $indentL = $this->indentL[40];
 876              else
 877                  $indentL = $this->indentL[$pixelsL];
 878          }
 879          if($pixelsR)
 880          {
 881              if(!array_key_exists($pixelsR, $this->indentR))
 882                  $indentR = $this->indentR[40];
 883              else
 884                  $indentR = $this->indentR[$pixelsR];
 885          }
 886          if($indentL || $indentR)
 887              $text = "$indentL$indentR\n$text\n\\par\n\\li0\\ri0\n";
 888          return $text;
 889      }
 890  /**
 891  * indent long quotations
 892  *
 893  * @author Mark Grimshaw
 894  * @version 1
 895  * @param string $text
 896  * @param integer $numWords
 897  * @param boolean
 898  * @return string
 899  */
 900  	private function indentQuotations($text, $numWords, $keepQuoteMarks)
 901      {
 902          $this->quoteNumWords = $numWords;
 903          $this->keepQuoteMarks = $keepQuoteMarks;
 904  // Get quotation marks for this localization
 905          if((!$languageDir = $this->session->getVar("setup_Language")) || !is_dir("languages/$languageDir"))
 906              $languageDir = "en";
 907          include_once("languages/$languageDir/CONSTANTS.php");
 908          $class = "CONSTANTS_" . $languageDir;
 909          $wikindxLanguageClass = new $class();
 910          if(isset($wikindxLanguageClass->startQuotation) && $wikindxLanguageClass->startQuotation)
 911              $qms = preg_quote($wikindxLanguageClass->startQuotation);
 912          else
 913              $qms = "\"";
 914          $this->qms = $qms;
 915          if(isset($wikindxLanguageClass->endQuotation) && $wikindxLanguageClass->endQuotation)
 916              $qme = preg_quote($wikindxLanguageClass->endQuotation);
 917          else
 918              $qme = "\"";
 919          $this->qme = $qme;
 920          return preg_replace_callback("/($qms)(.*)($qme)(.*)(\[cite\].*\[\/cite\])(.*)(\[footnote\].*\[\/footnote\]){0,}([.,:;?!°ø])/Usi", array($this, "indentQ"), $text);
 921      }
 922  /**
 923  * callback for indent long quotations
 924  *
 925  * @author Mark Grimshaw
 926  * @version 1
 927  * @param array $matchArray
 928  * @return string
 929  */
 930  	private function indentQ($matchArray)
 931      {
 932  // [1] => initial quote marker
 933  // [2] => quoted text
 934  // [3] => final quote marker
 935  // [4] => intervening text (should be a single space)
 936  // [5] => citation
 937  // [6] => intervening text
 938  // [7] => tags such as footnotes etc.
 939  // [8] => punctuation immediately following citation
 940  
 941  //print "HERE: "; print_r($matchArray); print "<P>";
 942  //print $matchArray[4]; print "<P>";
 943  // No indentation if this is part of a footnote...
 944          if(strpos($matchArray[4], '[/footnote]'))
 945              return $matchArray[0];
 946  // are there quotes within the quote?
 947          if(strpos($matchArray[4], $this->qme))
 948          {
 949              $split = explode($this->qme, $matchArray[4]);
 950  //print_r($split); print "<P>";
 951              $lastElement = array_pop($split);
 952              $matchArray[4] = $lastElement;
 953              $matchArray[2] .= $matchArray[3] . join($this->qme, $split);
 954  //print $matchArray[2]; print "<P>";
 955  //print $matchArray[4]; die;
 956          }
 957          if(str_word_count($matchArray[2]) >= $this->quoteNumWords)
 958          {
 959              if(trim($matchArray[6])) // intervening text
 960              {
 961                  $trail = trim($matchArray[6]) . $matchArray[7] . $matchArray[8];
 962                  $removeSpace = '';
 963              }
 964              else
 965              {
 966                  $trail = $matchArray[6] . $matchArray[7] . trim($matchArray[8]);
 967                  $removeSpace = '__WIKINDX__QUOTEINDENTREMOVESPACE__';
 968              }
 969              $fs = $this->quoteFontSize . $this->lineSpacingIndentQ;
 970              $start = "\n__WIKINDX__NEWLINEPAR__{\\fs$fs __WIKINDX__NEWLINEPAR__\\li720\\ri720";
 971              $codaA = $matchArray[4] . $matchArray[5] . $trail . 
 972                  "__WIKINDX__NEWLINEPAR__}__WIKINDX__NEWLINEPAR__$removeSpace";
 973              $codaB = 
 974                  "__WIKINDX__NEWLINEPAR__}__WIKINDX__NEWLINEPAR__" . $matchArray[4] . $matchArray[5] . 
 975                  $trail . $removeSpace;
 976              $codaC = $matchArray[4] . $matchArray[5] . 
 977                  "__WIKINDX__NEWLINEPAR__}__WIKINDX__NEWLINEPAR__" . $trail . $removeSpace;
 978              if($this->keepQuoteMarks)
 979              {
 980                  if($matchArray[4] == ' ')
 981                  {
 982                      if(trim($matchArray[6])) // intervening text
 983                          return $start . $this->qms . $matchArray[2] . $this->qme . $codaC;
 984                      else
 985                          return $start . $this->qms . $matchArray[2] . $this->qme . $codaA;
 986                  }
 987                  else // intervening text
 988                      return $start . $this->qms . $matchArray[2] . $this->qme . $codaB;
 989  
 990              }
 991              else
 992              {
 993                  if($matchArray[4] == ' ')
 994                  {
 995                      if(trim($matchArray[6])) // intervening text
 996                          return $start . '__WIKINDX__QUOTEINDENTDONE__' . $matchArray[2] . 
 997                          '__WIKINDX__QUOTEINDENTDONE__' . $codaC;
 998                      else
 999                          return $start . '__WIKINDX__QUOTEINDENTDONE__' . $matchArray[2] . 
1000                          '__WIKINDX__QUOTEINDENTDONE__' . $codaA;
1001                  }
1002                  else // intervening text
1003                      return $start . '__WIKINDX__QUOTEINDENTDONE__' . $matchArray[2] . 
1004                      '__WIKINDX__QUOTEINDENTDONE__' . $codaB;
1005  
1006              }
1007          }
1008          return $matchArray[0];
1009  //        unset($matchArray[0]);
1010  //        return join('', $matchArray);
1011      }
1012  /**
1013  * parse [footnote]...[/footnote]
1014  *
1015  * @author Mark Grimshaw
1016  * @version 1
1017  * @param string $text
1018  * @param array $footnoteOffsetIds
1019  * @param int $fontSize
1020  * @return string
1021  */
1022  	private function parseFootnotes($text,$footnoteOffsetIds, $fontSize)
1023      {
1024  //print_r($this->styleArray); die;
1025          if(($sizeKey = array_search($fontSize * 2, $this->fontSizes)) !== FALSE)
1026              $this->fontSizeFt = $this->fontSizes[$sizeKey];
1027          else
1028              $this->fontSizeFt = $this->fontSizes['large']; // font size 9/18
1029          if(!empty($footnoteOffsetIds)) // endnotes same IDs and there are existing cite tags being used
1030              $this->footnoteOffsetIds = $footnoteOffsetIds;
1031          return preg_replace_callback("/\[footnote\](.*)\[\/footnote\]([.,:;?!]*\s*)/Usi", 
1032              array($this, "footnotes"), $text);
1033      }
1034  /**
1035  * callback for parsing [footnote]...[/footnote]
1036  *
1037  * @author Mark Grimshaw
1038  * @version 1
1039  * @param array $matchArray
1040  * @return string
1041  */
1042  	private function footnotes($matchArray)
1043      {
1044          $text = $matchArray[1];
1045          $id = '\\chftn';
1046          if(!$this->styleArray['citationStyle']) // in-text citations so footnotes here really are footnotes
1047              $ft = "\\footnote";
1048          else // endnotes and footnotes
1049          {
1050              if(!$this->styleArray['endnoteStyle']) // endnotes incrementing
1051                  $ft = "\\footnote\\ftnalt";
1052              else if($this->styleArray['endnoteStyle'] == 1) // endnotes same IDs
1053              {
1054                  $ft = "\\footnote\\ftnalt";
1055                  $id = array_shift($this->footnoteOffsetIds);
1056              }
1057              else    // '2' == footnotes incrementing
1058                  $ft = "\\footnote";
1059          }
1060          $preInText = $this->styleArray['firstCharsEndnoteInText'];
1061          $postInText = $this->styleArray['lastCharsEndnoteInText'];
1062          $preId = $this->styleArray['firstCharsEndnoteID'];
1063          if($postInText && preg_match("/[.,:;?!]\s*/", $matchArray[2], $null))
1064              $matchArray[2] = '';
1065          $postId = $this->styleArray['lastCharsEndnoteID'];
1066          if($this->styleArray['formatEndnoteInText'] == 1) // superscript
1067          {
1068              $preInTextFormat = "{\\super";
1069              $postInTextFormat = '}';
1070          }
1071          else if($this->styleArray['formatEndnoteInText'] == 2) // subscript
1072          {
1073              $preInTextFormat = "{\\sub";
1074              $postInTextFormat = '}';
1075          }
1076          else
1077          {
1078              $preInTextFormat = '';
1079              $postInTextFormat = '';
1080          }
1081          if($this->styleArray['formatEndnoteID'] == 1) // superscript
1082          {
1083              $preIDFormat = "{\\super";
1084              $postIDFormat = '}';
1085          }
1086          else if($this->styleArray['formatEndnoteID'] == 2) // subscript
1087          {
1088              $preIDFormat = "{\\sub";
1089              $postIDFormat = '}';
1090          }
1091          else
1092          {
1093              $preIDFormat = '';
1094              $postIDFormat = '';
1095          }
1096          if($this->session->getVar('wp_ExportIndentFt') == 'indentAll')
1097              $ftf = "\\li720 ";
1098          else if($this->session->getVar('wp_ExportIndentFt') == 'indentFL')
1099              $ftf = "\\fi720 ";
1100          else if($this->session->getVar('wp_ExportIndentFt') == 'indentNotFL')
1101              $ftf = "\\li720\\fi-720 ";
1102          else
1103              $ftf = "\\li1\\fi1 ";
1104          $ftf .= "\\fs" . $this->fontSizeFt;
1105          if($this->session->getVar('wp_ExportSpaceFt') == 'oneHalfSpace')
1106              $ftf = "\\pard\\plain $ftf\\sl360\\slmult1 ";
1107          else if($this->session->getVar('wp_ExportSpaceFt') == 'doubleSpace')
1108              $ftf = "\\pard\\plain $ftf\\sl480\\slmult1 ";
1109          else
1110              $ftf = "\\pard\\plain$ftf";
1111          if(($this->styleArray['endnoteStyle'] == 1)
1112               && array_key_exists('sameIdOrderBib', $this->styleArray)) // endnotes same IDs, bibliography order
1113          {
1114              $this->footnoteText .= "$ftf\\qj$preIDFormat$preId{\\cs2 $id}" . $postId . $postIDFormat . 
1115                  $matchArray[1] . "\\par\n" . $postInTextFormat . $matchArray[2];
1116              return "\n$preInTextFormat{" . "$preInText$id$postInText\n}}";
1117          }
1118          return "\n$preInTextFormat$preInText{\\cs2 $id\n{" . 
1119              "$ft$ftf\\qj" . "$preIDFormat$preId{\\cs2 $id}" . $postId . "$postIDFormat{" . 
1120              $text . "}}}$postInText\n" . $postInTextFormat . $matchArray[2];
1121      }
1122  /*
1123  FUNCTIONS NOT USED
1124      function setFontSize($matchArray)
1125      {
1126          $size = $matchArray[1];
1127          $text = preg_replace("/^__WIKINDX__NEWLINEPAR__|__WIKINDX__NEWLINEPAR__$/", '', $matchArray[2]);
1128          $fontSize = $this->fontSizes[$size];
1129          return "{\\fs$fontSize $text}__WIKINDX__NEWLINE__";
1130      }
1131      function setFontColor($matchArray)
1132      {
1133          $colour = $matchArray[1];
1134          $text = preg_replace("/^__WIKINDX__NEWLINEPAR__|__WIKINDX__NEWLINEPAR__$/", '', $matchArray[2]);
1135          if(!array_key_exists($colour, $this->colours))
1136              $colour = $this->colours['black'];
1137          else
1138              $colour = $this->colours[$colour];
1139          return "__WIKINDX__NEWLINE__$colour" . "__WIKINDX__NEWLINE__$text";
1140      }
1141      function setFontFace($matchArray)
1142      {
1143          $face = $matchArray[1];
1144          $text = preg_replace("/^__WIKINDX__NEWLINEPAR__|__WIKINDX__NEWLINEPAR__$/", '', $matchArray[2]);
1145          $fontIndex = $this->createFontBlocks(trim($face));
1146          return "{\\f$fontIndex $text}__WIKINDX__NEWLINE__";
1147      }
1148      function createIndentFirstLine($text)
1149      {
1150          return preg_replace_callback("/\[indent\s*=\s*l_first_line\](.*)\[\/indent\]/Usi",
1151              array($this, "setIndentFirstLine"), $text);
1152      }
1153      function setIndentFirstLine($matchArray)
1154      {
1155          $text = preg_replace("/^__WIKINDX__NEWLINEPAR__|__WIKINDX__NEWLINEPAR__$/", '', $matchArray[1]);
1156          return "\fi720\n$text\n\\par\n\fi0\n";
1157      }
1158      function colourFormat($colours)
1159      {
1160          $colour = trim($colours[1]);
1161          if(!array_key_exists($colour, $this->colours))
1162              $colour = $this->colours['black'];
1163          else
1164              $colour = $this->colours[$colour];
1165          $text = preg_replace("/^__WIKINDX__NEWLINEPAR__|__WIKINDX__NEWLINEPAR__$/", '', $colours[2]);
1166          return "__WIKINDX__NEWLINE__$colour" . "__WIKINDX__NEWLINE__$text";
1167      }
1168  */
1169  }
1170  ?>

title

Description

title

Description

title

Description

title

title

Body