Example #1
0
 public function __construct()
 {
     // Creates an object of type DOMDocument
     // and exposes it as the attribute $tei
     $this->tei = new DOMDocument();
     $tei_dom = new TeiDom($_POST);
     $this->tei->loadXML($tei_dom->getTeiString());
     $this->xpath = new DOMXpath($this->tei);
     $this->xpath->registerNamespace('tei', TEI);
     $this->xpath->registerNamespace('html', HTML);
     $this->xpath->registerNamespace('anth', ANTH);
 }
Example #2
0
<?php

include_once WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . "anthologize" . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'class-tei-dom.php';
$tei = new TeiDom($_POST);
$fileName = TeiDom::getFileName($_POST);
$ext = "xml";
header("Content-type: application/xml");
header("Content-Disposition: attachment; filename={$fileName}.{$ext}");
echo $tei->getTeiString();
die;
Example #3
0
<?php

//PMJ--I don't understand why the encoding done in class-tei-dom isn't coming through, but this seems to work
function convertSmartQuotes($string)
{
    $search = array(chr(0xe2) . chr(0x80) . chr(0x98), chr(0xe2) . chr(0x80) . chr(0x99), chr(0xe2) . chr(0x80) . chr(0x9c), chr(0xe2) . chr(0x80) . chr(0x9d), chr(0xe2) . chr(0x80) . chr(0x93), chr(0xe2) . chr(0x80) . chr(0x94));
    $replace = array("'", "'", '"', '"', '-');
    return str_replace($search, $replace, $string);
}
error_reporting(0);
require_once WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . "anthologize" . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'class-tei-dom.php';
$tei = new TeiDom($_POST);
$fileName = TeiDom::getFileName($_POST);
$ext = "rtf";
$bookTitle = convertSmartQuotes($tei->xpath->query("//tei:titleStmt/tei:title/text()")->item(0)->wholeText);
$author = convertSmartQuotes($tei->xpath->query("//tei:docAuthor/text()")->item(0)->wholeText);
$copyright = convertSmartQuotes($tei->xpath->query("//tei:availability/tei:p/text()")->item(0)->wholeText);
// get contents of template file
$filename = WP_PLUGIN_DIR . "/anthologize/templates/rtf/poc_template.rtf";
// future: this will be a user-uploaded template
$fp = fopen($filename, 'r');
// open for reading stream only
$output = fread($fp, filesize($filename));
//prepare the output variable
fclose($fp);
// replace the place holders in the template with our data
// future: allow users to define things to replace, so this will not be hardcoded
$output = str_replace('[[BOOK TITLE]]', $bookTitle, $output);
$output = str_replace('[[AUTHOR NAME]]', $author, $output);
$output = str_replace('[[COPYRIGHT]]', $copyright, $output);
$libraryItems = $tei->xpath->query("//tei:div[@type='libraryItem']");
Example #4
0
$fp = fopen($mimetype_filename, "w") or die("Couldn't open temporary file for epub archive (mimetype)");
fwrite($fp, "application/epub+zip");
fclose($fp);
// Create & populate container.xml file
$container_filename = $temp_epub_dir_name . DIRECTORY_SEPARATOR . "META-INF" . DIRECTORY_SEPARATOR . "container.xml";
$fp = fopen($container_filename, "w") or die("Couldn't open temporary file for epub archive (container.xml)");
$container_file_contents = '<?xml version="1.0"?>';
$container_file_contents .= '<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">';
$container_file_contents .= '<rootfiles>';
$container_file_contents .= '<rootfile full-path="OEBPS/book.opf" media-type="application/oebps-package+xml"/>';
$container_file_contents .= '</rootfiles>';
$container_file_contents .= '</container>';
fwrite($fp, $container_file_contents);
fclose($fp);
// Load intermediate TEI file
$tei_data = new TeiDom($_POST);
$teiDom = $tei_data->getTeiDom();
// echo $tei_data->getTeiString(); die();
// Get all images referenced in tei & copy over to image directory
// DOM Query using xpath: http://www.exforsys.com/tutorials/php-oracle/querying-a-dom-document-with-xpath.html
$xpath = new DOMXPath($teiDom);
$xpath->registerNamespace('tei', TEI);
$xpath->registerNamespace('html', HTML);
$xpath->registerNamespace('anth', ANTH);
$query = '//img/@src';
$image_url_nodes = $xpath->query($query);
foreach ($image_url_nodes as $image_url_node) {
    // Get image url & open file
    $image_url = $image_url_node->nodeValue;
    $image_filename = preg_replace('/^.*\\//', '', $image_url);
    // Erase all but filename from URL