classes/i18n/EditableEmailFile.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 // $Id$
00017 
00018 import('file.EditableFile');
00019 
00020 class EditableEmailFile {
00021    var $locale;
00022    var $editableFile;
00023 
00024    function EditableEmailFile($locale, $filename) {
00025       $this->locale = $locale;
00026       $this->editableFile = new EditableFile($filename);
00027    }
00028 
00029    function write() {
00030       $this->editableFile->write();
00031    }
00032 
00033    function &getContents() {
00034       return $this->editableFile->getContents();
00035    }
00036 
00037    function setContents(&$contents) {
00038       $this->editableFile->setContents($contents);
00039    }
00040 
00041    function update($key, $subject, $body, $description) {
00042       $matches = null;
00043       $quotedKey = String::regexp_quote($key);
00044       preg_match(
00045          "/<row>[\W]*<field name=\"email_key\">$quotedKey<\/field>/",
00046          $this->getContents(),
00047          $matches,
00048          PREG_OFFSET_CAPTURE
00049       );
00050       if (!isset($matches[0])) return false;
00051 
00052       $offset = $matches[0][1];
00053       $closeOffset = strpos($this->getContents(), '</row>', $offset);
00054       if ($closeOffset === FALSE) return false;
00055 
00056       $newContents = substr($this->getContents(), 0, $offset);
00057       $newContents .= '<row>
00058          <field name="email_key">' . $this->editableFile->xmlEscape($key) . '</field>
00059          <field name="subject">' . $this->editableFile->xmlEscape($subject) . '</field>
00060          <field name="body">' . $this->editableFile->xmlEscape($body) . '</field>
00061          <field name="description">' . $this->editableFile->xmlEscape($description) . '</field>
00062       ';
00063       $newContents .= substr($this->getContents(), $closeOffset);
00064       $this->setContents($newContents);
00065       return true;
00066    }
00067 
00068    function delete($key) {
00069       $matches = null;
00070       $quotedKey = String::regexp_quote($key);
00071       preg_match(
00072          "/[ \t]*<row>[\W]*<field name=\"email_key\">$quotedKey<\/field>/",
00073          $this->getContents(),
00074          $matches,
00075          PREG_OFFSET_CAPTURE
00076       );
00077       if (!isset($matches[0])) return false;
00078       $offset = $matches[0][1];
00079 
00080       preg_match("/<\/row>[ \t]*[\r]?\n/", $this->getContents(), $matches, PREG_OFFSET_CAPTURE, $offset);
00081       if (!isset($matches[0])) return false;
00082       $closeOffset = $matches[0][1] + strlen($matches[0][0]);
00083 
00084       $newContents = substr($this->getContents(), 0, $offset);
00085       $newContents .= substr($this->getContents(), $closeOffset);
00086       $this->setContents($newContents);
00087       return true;
00088    }
00089 
00090    function insert($key, $subject, $body, $description) {
00091       $offset = strrpos($this->getContents(), '</table>');
00092       if ($offset === false) return false;
00093       $newContents = substr($this->getContents(), 0, $offset);
00094       $newContents .= ' <row>
00095          <field name="email_key">' . $this->editableFile->xmlEscape($key) . '</field>
00096          <field name="subject">' . $this->editableFile->xmlEscape($subject) . '</field>
00097          <field name="body">' . $this->editableFile->xmlEscape($body) . '</field>
00098          <field name="description">' . $this->editableFile->xmlEscape($description) . '</field>
00099       </row>
00100    ';
00101       $newContents .= substr($this->getContents(), $offset);
00102       $this->setContents($newContents);
00103    }
00104 }
00105 
00106 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7