Beispiel #1
0
 public function __construct($bible)
 {
     $this->bible = $bible;
     $this->currentParagraphStyle = "";
     $this->currentParagraphContent = "";
     $this->currentTextStyle = array();
     $this->frameCount = 0;
     $this->noteCount = 0;
     $this->currentNoteTextStyle = array();
     $database_config_general = Database_Config_General::getInstance();
     $database_config_bible = Database_Config_Bible::getInstance();
     $template = dirname(__FILE__) . "/template.odt";
     $this->unpackedOdtFolder = Filter_Archive::unzip($template, false);
     Filter_Rmdir::rmdir($this->unpackedOdtFolder . "/Configurations2");
     $this->contentDom = new DOMDocument();
     $this->contentDom->load($this->unpackedOdtFolder . "/content.xml");
     $contentXpath = new DOMXpath($this->contentDom);
     $this->officeTextDomNode = $contentXpath->query("office:body/office:text")->item(0);
     // Remove the default content from the template. This is a text:p element.
     $node = $contentXpath->query("text:p", $this->officeTextDomNode)->item(0);
     $this->officeTextDomNode->removeChild($node);
     $this->createdStyles = array();
     $this->stylesDom = new DOMDocument();
     $this->stylesDom->load($this->unpackedOdtFolder . "/styles.xml");
     $stylesXpath = new DOMXpath($this->stylesDom);
     $this->officeStylesDomNode = $stylesXpath->query("office:styles")->item(0);
     // Set the page size and margins.
     $pageLayoutProperties = $stylesXpath->query("descendant::style:page-layout-properties")->item(0);
     $pageLayoutProperties->setAttribute("fo:page-width", $database_config_bible->getPageWidth($this->bible) . "mm");
     $pageLayoutProperties->setAttribute("fo:page-height", $database_config_bible->getPageHeight($this->bible) . "mm");
     $pageLayoutProperties->setAttribute("fo:margin-left", $database_config_bible->getInnerMargin($this->bible) . "mm");
     $pageLayoutProperties->setAttribute("fo:margin-right", $database_config_bible->getOuterMargin($this->bible) . "mm");
     $pageLayoutProperties->setAttribute("fo:margin-top", $database_config_bible->getTopMargin($this->bible) . "mm");
     $pageLayoutProperties->setAttribute("fo:margin-bottom", $database_config_bible->getBottomMargin($this->bible) . "mm");
     // Update the tab-stops in the relevant header styles. The tab stops depend on page and margin dimensions.
     $nodeList = $stylesXpath->query("descendant::style:style[contains(attribute::style:parent-style-name,'Header')]//descendant::style:tab-stop");
     $centerPosition = $database_config_bible->getPageWidth($this->bible) - $database_config_bible->getInnerMargin($this->bible) - $database_config_bible->getOuterMargin($this->bible);
     $centerPosition /= 2;
     $counter = 0;
     foreach ($nodeList as $node) {
         $modulus = $counter % 2;
         $node->setAttribute("style:position", $centerPosition * ($modulus + 1) . "mm");
         $counter++;
     }
     // Remove the date style for the running headers, so that it takes the default style.
     $numberDateStyleNode = $stylesXpath->query("descendant::number:date-style")->item(0);
     $numberDateStyleNode->parentNode->removeChild($numberDateStyleNode);
     // Whether and how to put the date in the running headers.
     $nodeList = $stylesXpath->query("descendant::text:date");
     foreach ($nodeList as $node) {
         if ($database_config_bible->getDateInHeader($this->bible)) {
             $node->removeAttribute("text:date-value");
             $node->nodeValue = "";
         } else {
             $node->parentNode->removeChild($node);
         }
     }
 }
Beispiel #2
0
 public function testFilterArchiveUnzip()
 {
     $zipfile = Filter_Archive::zip($this->file1, false);
     // Test unzip.
     $folder = Filter_Archive::unzip($zipfile, false);
     $this->assertTrue(file_exists($folder));
     foreach (new DirectoryIterator($folder) as $fileInfo) {
         if ($fileInfo->isDot()) {
             continue;
         }
         $path = $fileInfo->getFilename();
         $path = "{$folder}/{$path}";
         $this->assertEquals(9000, filesize($path));
     }
     unlink($zipfile);
     Filter_Rmdir::rmdir($folder);
     // Test that unzipping garbage returns NULL.
     $folder = Filter_Archive::unzip("xxxxx", false);
     $this->assertEquals(NULL, $folder);
 }
Beispiel #3
0
 /**
  * Uncompresses a known archive identified by $file.
  * Returns the path to the folder it created.
  * If $show_errors is true, it outputs errors in html.
  */
 public static function uncompress($file, $show_errors)
 {
     // Tar (.tar) archives, including those compressed with gzip (.tar.gz, .tgz), bzip (.tar.bz, .tbz), bzip2 (.tar.bz2, .tbz2), compress (.tar.Z, .taz), lzop (.tar.lzo, .tzo) and lzma (.tar.lzma)
     // Zip archives (.zip)
     // Jar archives (.jar, .ear, .war)
     // 7z archives (.7z)
     // iso9660 CD images (.iso)
     // Lha archives (.lzh)
     // Single files compressed with gzip (.gz), bzip (.bz), bzip2 (.bz2), compress (.Z), lzop (.lzo) and lzma (.lzma)
     $suffix = pathinfo($file, PATHINFO_EXTENSION);
     switch ($suffix) {
         case "tar.gz":
             // Never called because pathinfo would give the 'gz' suffix only.
         // Never called because pathinfo would give the 'gz' suffix only.
         case "gz":
         case "tgz":
             return Filter_Archive::untargz($file, $show_errors);
         case "zip":
             return Filter_Archive::unzip($file, $show_errors);
         case "tar.bz":
         case "tbz":
         case "tar.bz2":
         case "tbz2":
     }
     return NULL;
 }