예제 #1
0
 public function _toHtml()
 {
     $this->_checkRequired();
     $info = $this->getInfo();
     $certain = $info['certain'];
     $dom = new DomDocument();
     $dom->preserveWhitespace = false;
     $block = $dom->createElement('block');
     $attr = $dom->createAttribute('type');
     $attr->value = $this->getAlias();
     $block->appendChild($attr);
     $dom->appendChild($block);
     $output = simplexml_load_string('<block />');
     foreach ($certain as $method) {
         $block->appendChild($dom->createComment("\n     " . $this->_getDocumentation($method) . "\n  "));
         $dom_action = $dom->createElement('action');
         $block->appendChild($dom_action);
         $dom_attr = $dom->createAttribute('method');
         $dom_attr->value = $method->getName();
         $dom_action->appendChild($dom_attr);
         $this->addParamsToDomActionNodeFromReflectionMethod($dom, $dom_action, $method);
         //$action = $this->addParamsToActionNodeFromReflectionMethod($action, $method);
     }
     $dom->formatOutput = true;
     return $this->_extraXmlFormatting($dom->saveXml());
 }
 /**
  * add ie css.
  * add a style file to the document
  *
  * @param string $file
  * @param string $ieCondition
  * @access public
  * @return bool
  */
 public function addIeCss($file, $ieCondition)
 {
     if (!empty($file) && !empty($ieCondition)) {
         $comment = $this->document->createComment(sprintf('[if %s]><link href="%s" rel="stylesheet" type="text/css" /><![endif]', $ieCondition, BASEPATH . '/' . $file));
         $this->head->appendChild($comment);
         return true;
     } else {
         return false;
     }
 }
예제 #3
0
 /**
  * Add a comment
  *
  * @param   string  $content
  * @return  object  $this
  */
 public function comment($content)
 {
     $this->current->appendChild($this->dom->createComment(htmlentities($content, ENT_QUOTES | ENT_XML1)));
     return $this;
 }
function pugpig_get_opds_container($edition_ids, $internal = false, $atom_mode = false, $newsstand_mode = false, $extra_comments = array())
{
    $d = new DomDocument('1.0', 'UTF-8');
    $feed = $d->createElement('feed');
    $feed->setAttribute('xmlns', 'http://www.w3.org/2005/Atom');
    if ($newsstand_mode) {
        $feed->setAttribute('xmlns:news', 'http://itunes.apple.com/2011/Newsstand');
    } else {
        $feed->setAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
        $feed->setAttribute('xmlns:opds', 'http://opds-spec.org/2010/catalog');
        $feed->setAttribute('xmlns:app', 'http://www.w3.org/2007/app');
        $feed->setAttribute('xmlns:at', 'http://purl.org/atompub/tombstones/1.0');
        $feed->setAttribute('xmlns:pp', 'http://pugpig.com/2014/atom/');
    }
    $comment = $atom_mode ? "Atom" : "Package";
    if ($internal) {
        $comment .= ' Internal Feed';
    } else {
        $comment .= ' External Feed';
    }
    if ($newsstand_mode) {
        $comment .= " for Newsstand";
    }
    $feed->appendChild($d->createComment(' ' . $comment . " - Generated: " . date(DATE_RFC822) . ' '));
    foreach ($extra_comments as $extra_comment) {
        $feed->appendChild($d->createComment(' ' . $extra_comment . ' '));
    }
    $feed->appendChild(newElement($d, 'id', pugpig_get_atom_tag('opds')));
    _pugpig_create_xml_link($d, $feed, array('rel' => 'self', 'type' => 'application/atom+xml;profile=opds-catalog;kind=acquisition', 'href' => pugpig_self_link()));
    if (function_exists('pugpig_get_opds_extras')) {
        $extras = pugpig_get_opds_extras();
        if (isset($extras['links'])) {
            foreach ($extras['links'] as $link) {
                _pugpig_create_xml_link($d, $feed, $link);
            }
        }
        if (!empty($extras['auth_endpoints'])) {
            $authorisation = $d->createElement('pp:authorisation', '');
            $feed->appendChild($authorisation);
            foreach ($extras['auth_endpoints'] as $auth) {
                $authorisation = pugpig_get_authorisationprovider($d, $auth, $authorisation);
            }
        }
        if (isset($extras['custom_categories'])) {
            foreach ($extras['custom_categories'] as $scheme => $values) {
                _pugpig_create_atom_category($d, $feed, $scheme, $values);
            }
        }
    }
    $author = $d->createElement('author');
    $author->appendChild($d->createElement('name', 'Pugpig'));
    $feed->appendChild($author);
    $feed->appendChild($d->createElement('title', 'All Issues'));
    $feed->appendChild($d->createElement('subtitle', $comment));
    $editions = array();
    $updated = 1;
    // 1 second into UNIX epoch (0 == current time?)
    foreach ($edition_ids as $key => $edition_id) {
        $editions[] = $edition_id;
        $edition_updated_atom = pugpig_get_edition_update_date(pugpig_get_edition($edition_id, true, !$atom_mode), true);
        $edition_updated_package = pugpig_get_edition_update_date(pugpig_get_edition($edition_id, true, !$atom_mode), false);
        $edition_updated = max($edition_updated_atom, $edition_updated_package);
        if ($edition_updated > $updated) {
            $updated = $edition_updated;
        }
    }
    $feed->appendChild(newElement($d, 'updated', pugpig_date3339($updated)));
    foreach ($editions as $edition) {
        $edition = pugpig_get_edition($edition, true, !$atom_mode);
        if (!$atom_mode && array_key_exists('zip', $edition) && $edition['zip'] == '' && !$edition['is_pdf']) {
            $feed->appendChild($d->createComment(' ' . ucfirst($edition['status']) . ' ' . pugpig_get_atom_tag($edition['key']) . ' does not have an up to date package '));
        } else {
            $feed->appendChild(pugpig_get_opds_entry($d, $edition, $internal, $atom_mode, $newsstand_mode));
        }
    }
    $d->appendChild($feed);
    return $d;
}
예제 #5
0
function _package_edition_package_list_xml($base, $edition_tag, $url_root = '', $cdn = '', $output = 'string', $timestamp = '*', $content_xml_url = "content.xml")
{
    $url_root = pugpig_strip_domain($url_root);
    $contents = _package_edition_package_contents($base, $edition_tag, $timestamp);
    if (!file_exists($contents['html_archive'])) {
        return NULL;
    }
    $total_size = 0;
    //$content_xml = "content.xml";
    $d = new DomDocument('1.0', 'UTF-8');
    $d->formatOutput = TRUE;
    $package = $d->createElement('package');
    $package->setAttribute('root', $content_xml_url);
    $comment = "Generated: " . date(DATE_RFC822);
    $package->appendChild($d->createComment($comment));
    $part = $d->createElement('part');
    $part->setAttribute('name', 'html');
    $part->setAttribute('src', $url_root . $contents['html_url']);
    $part->setAttribute('size', $contents['html_size']);
    $total_size += $contents['html_size'];
    $part->setAttribute('modified', gmdate(DATE_ATOM, $contents['html_timestamp']));
    $package->appendChild($part);
    if (is_numeric($contents['assets_size']) && $contents['assets_size'] > 0) {
        $part = $d->createElement('part');
        $part->setAttribute('name', 'assets');
        $part->setAttribute('src', $cdn . $url_root . $contents['assets_url']);
        $part->setAttribute('size', $contents['assets_size']);
        $total_size += $contents['assets_size'];
        $part->setAttribute('modified', gmdate(DATE_ATOM, $contents['assets_timestamp']));
        $package->appendChild($part);
    }
    $package->setAttribute('size', $total_size);
    $d->appendChild($package);
    if ($output == 'string') {
        return $d->saveXML();
    } else {
        $d->save($output);
        return $output;
    }
}
<?php

//Negative offset
$dom = new DomDocument();
$comment = $dom->createComment('test-comment');
try {
    $comment->replaceData(-1, 4, '-inserted');
} catch (DOMException $e) {
    if ($e->getMessage() == 'Index Size Error') {
        echo "Throws DOMException for -ve offest\n";
    }
}
예제 #7
0
function pugpig_get_opds_container($edition_ids, $internal = FALSE, $atom_mode = FALSE, $newsstand_mode = FALSE, $extra_comments = array())
{
    $d = new DomDocument('1.0', 'UTF-8');
    $feed = $d->createElement('feed');
    $feed->setAttribute('xmlns', 'http://www.w3.org/2005/Atom');
    if ($newsstand_mode) {
        $feed->setAttribute('xmlns:news', 'http://itunes.apple.com/2011/Newsstand');
    } else {
        $feed->setAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
        $feed->setAttribute('xmlns:opds', 'http://opds-spec.org/2010/catalog');
        $feed->setAttribute('xmlns:app', 'http://www.w3.org/2007/app');
        $feed->setAttribute('xmlns:at', 'http://purl.org/atompub/tombstones/1.0');
    }
    $comment = $atom_mode ? "Atom" : "Package";
    if ($internal) {
        $comment .= ' Internal Feed';
    } else {
        $comment .= ' External Feed';
    }
    if ($newsstand_mode) {
        $comment .= " for Newsstand";
    }
    $feed->appendChild($d->createComment(' ' . $comment . " - Generated: " . date(DATE_RFC822) . ' '));
    foreach ($extra_comments as $extra_comment) {
        $feed->appendChild($d->createComment(' ' . $extra_comment . ' '));
    }
    $feed->appendChild(newElement($d, 'id', pugpig_get_atom_tag('opds')));
    $link = $d->createElement('link');
    $link->setAttribute('rel', 'self');
    $link->setAttribute('type', 'application/atom+xml;profile=opds-catalog;kind=acquisition');
    $link->setAttribute('href', pugpig_self_link());
    $feed->appendChild($link);
    $author = $d->createElement('author');
    $author->appendChild($d->createElement('name', 'Pugpig'));
    $feed->appendChild($author);
    $feed->appendChild($d->createElement('title', 'All Issues'));
    $feed->appendChild($d->createElement('subtitle', $comment));
    $editions = array();
    $updated = 1;
    // 1 second into UNIX epoch (0 == current time?)
    foreach ($edition_ids as $key => $edition_id) {
        $editions[] = $edition_id;
        $edition_updated = pugpig_get_edition_update_date(pugpig_get_edition($edition_id, TRUE, !$atom_mode), $atom_mode);
        if ($edition_updated > $updated) {
            $updated = $edition_updated;
        }
    }
    $feed->appendChild(newElement($d, 'updated', pugpig_date3339($updated)));
    foreach ($editions as $edition) {
        $edition = pugpig_get_edition($edition, TRUE, !$atom_mode);
        if (!$atom_mode && array_key_exists('zip', $edition) && $edition['zip'] == '') {
            $feed->appendChild($d->createComment(' ' . ucfirst($edition['status']) . ' ' . pugpig_get_atom_tag($edition['key']) . ' does not have an up to date package '));
        } else {
            $feed->appendChild(pugpig_get_opds_entry($d, $edition, $internal, $atom_mode, $newsstand_mode));
        }
    }
    $d->appendChild($feed);
    return $d;
}
function _package_edition_package_list_xml_core($base, $edition_tag, $bucket_infos, $url_root = '', $cdn = '', $output_type = 'string', $timestamp = '*', $content_xml_url = "content.xml")
{
    $d = new DomDocument('1.0', 'UTF-8');
    $d->formatOutput = true;
    $package = $d->createElement('package');
    $package->setAttribute('root', $content_xml_url);
    $package->appendChild($d->createComment("Generated: " . date(DATE_RFC822)));
    $url_root_without_domain = pugpig_strip_domain($url_root);
    $total_size = 0;
    foreach ($bucket_infos as $bucket_name => $bucket_info) {
        $bucket_cdn = $bucket_info['is_cdn'] ? $cdn : '';
        $total_size += _package_edition_package_list_xml_part($package, $d, $url_root_without_domain, $bucket_info['zips'], $bucket_name, $bucket_cdn, $base);
    }
    $package->setAttribute('size', $total_size);
    $d->appendChild($package);
    $out = null;
    if ($output_type === 'string') {
        $out = $d->saveXML();
    } else {
        $d->save($output_type);
        $out = 'string';
    }
    return $out;
}
<?php

$x = new DomDocument();
$x->createComment();
?>
===DONE===