Example #1
0
 protected function _contentToDom($content, $return_parent = FALSE)
 {
     if ($content instanceof \SimpleXMLElement) {
         $new = dom_import_simplexml($content);
         if ($return_parent) {
             $new = $new->parentNode;
         }
     } elseif ($content instanceof \DOMNode) {
         $new = $content;
         if ($return_parent) {
             $new = $new->parentNode;
         }
     } elseif (is_string($content)) {
         if ($return_parent) {
             $new = Quip::load("<root>{$content}</root>")->dom();
         } else {
             $new = Quip::load($content)->dom();
         }
     } else {
         throw new \InvalidArgumentException("Unknown type of content.");
     }
     $me = $this->dom();
     if ($new->ownerDocument !== $me->ownerDocument) {
         $clone = $new->cloneNode(TRUE);
         $new = $me->ownerDocument->importNode($clone, TRUE);
     }
     return $new;
 }
Example #2
0
 public function testMultipleReferences()
 {
     // Document how much memory is used when additional iterators are instantiated.
     $quip = Quip::load(__DIR__ . '/Resources/XmlBasicList.xml', 0, TRUE);
     $count = 1000;
     $v = array();
     $pre = memory_get_usage(FALSE);
     for ($i = 0; $i < $count; ++$i) {
         $v[] = $quip->xpath("//item");
     }
     $post = memory_get_usage(FALSE);
     $memory_per_reference = round(($post - $pre) / $count);
     // This test is targeted to PHP 5.3
     // 5.4 and 5.5 both use 25% less memory
     $this->assertLessThanOrEqual(21400, $memory_per_reference, "Early tests only show 21K per additional iterator in context.");
     // Document how much memory is used when additional iterators are instantiated.
     $quip = Quip::load(__DIR__ . '/Resources/XmlBasicList.xml', 0, TRUE);
     $count = 1000;
     $v = array();
     $pre = memory_get_usage(FALSE);
     for ($i = 0; $i < $count; ++$i) {
         $v[] = $quip->xpath("//original");
     }
     $post = memory_get_usage(FALSE);
     $memory_per_reference = round(($post - $pre) / $count);
     //     var_dump($memory_per_reference);
     // This test is targeted to PHP 5.3
     // 5.4 and 5.5 both use 25% less memory
     $this->assertLessThanOrEqual(2250, $memory_per_reference, "Early tests only show 2.2K per additional 1-item iterator in context.");
 }
Example #3
0
 /**
  *
  * @param unknown $source
  * @param number $options
  * @param string $data_is_url
  * @param string $ns
  * @param string $is_prefix
  * @param number $quip_options
  * @return \QuipXml\Xml\QuipXmlElement
  */
 public static function loadIcal($source, $options = 0, $data_is_url = FALSE, $ns = '', $is_prefix = FALSE, $quip_options = 0)
 {
     // Get the content.
     if ($data_is_url) {
         $source = file_get_contents($source);
         $data_is_url = FALSE;
     }
     // Initialize the XML object using an empty iCal element.
     $dom =& \DOMDocument::loadXML('<iCalendar xmlns:xCal="http://ietf.org/rfc/rfcXXXX.txt"></iCalendar>');
     // Strip off the bad white space.
     $source = trim(preg_replace("@[\n\r]+@s", "\n", $source));
     $lines = explode("\n", $source);
     // Iterate through the lines
     $i = 0;
     while (count($lines) > $i) {
         QuipCalendar::loadICalElement($dom->documentElement, $lines, $i);
     }
     return Quip::load($dom);
 }
 public function convertString($source, &$destination)
 {
     $source = str_replace("\r\n", "\n", $source);
     $source = str_replace("\r", "\n", $source);
     $quip = Quip::load($source, 0, FALSE, '', FALSE, Quip::LOAD_NS_UNWRAP);
     try {
         // Unwrap spelling/grammar errors.
         $found = TRUE;
         while ($found) {
             $found = FALSE;
             $quip->xpath("//span[matches(@class, '(SpellE|GramE)'")->unwrap();
         }
         // Remove references to external resource files.
         $quip->xpath("//link[@rel = 'themeData']")->remove();
         $quip->xpath("//link[@rel = 'colorSchemeMapping']")->remove();
         $quip->xpath("//link[@rel = 'File-List']")->remove();
         //       $quip->xpath("//meta[@http-equiv = 'Content-Type']")->not(':first')->remove();
         $quip->xpath("//meta[@name]")->remove();
         // Iterate through <style> tags and remove mso-* properties
         foreach ($quip->xpath('//style') as $style_node) {
             $style = $style_node->html();
             $prev = '';
             while ($prev !== $style) {
                 $prev = $style;
                 // Remove mso-
                 $style = preg_replace('@([\\s;{])mso-.*?;@', '\\1', $style);
                 // Remove empty blocks
                 $style = preg_replace('@\\{\\s+\\}@s', '{}', $style);
                 $style = preg_replace("@\\}[^\\*\\{\\}/]+?\\{\\}@s", '}', $style);
                 // Blank lines
                 $style = preg_replace("@\n\\s*\n@s", "\n", $style);
             }
             $style_node->html($style);
         }
     } catch (\Exception $e) {
         echo $e->getMessage();
     }
     $destination = $quip->html();
     //     echo $destination;
     return $this;
 }
Example #5
0
 public function testWrapUnwrap()
 {
     $quip = Quip::load(__DIR__ . '/Resources/XmlBasicList.xml', 0, TRUE);
     $expected = $quip->xpath("//output[@method = 'list-newlist']")->html($this->formatter);
     $quip = Quip::load(__DIR__ . '/Resources/XmlBasicList.xml', 0, TRUE);
     $tgt = $quip->xpath("//original//item[@class = 'target']");
     $tgt->xparent()->wrap('<newlist/>');
     $tgt->unwrap();
     $actual = $quip->original->html($this->formatter);
     $this->assertEquals($expected, $actual);
     $quip = Quip::load(__DIR__ . '/Resources/XmlBasicList.xml', 0, TRUE);
     $quip->original->wrapInner('<newlist />');
     $quip->original->newlist->html($quip->xpath("//original//list")->html());
     $actual = $quip->original->html($this->formatter);
     $this->assertEquals($expected, $actual);
     $quip = Quip::load(__DIR__ . '/Resources/XmlBasicList.xml', 0, TRUE);
     $list = $quip->xpath("//original//item")->xparent()->wrapInner('<newlist />')->xpath("./*[1]")->unwrap();
     $actual = $quip->original->html($this->formatter);
     $this->assertEquals($expected, $actual);
 }