Chainable.
public static newDocumentXHTML ( unknown_type $markup = null, $charset = null ) : phpQueryObject | QueryTemplatesSource | QueryTemplatesParse | QueryTemplatesSourceQuery | ||
$markup | unknown_type | |
리턴 | phpQueryObject | QueryTemplatesSource | QueryTemplatesParse | QueryTemplatesSourceQuery |
/** * checks that an empty form is initialized correctly */ function test_defaults() { global $INPUT; global $ID; $ID = 'some:test'; $INPUT->get->set('id', $ID); $INPUT->get->set('foo', 'bar'); $form = new Form\Form(); $html = $form->toHTML(); $pq = phpQuery::newDocumentXHTML($html); $this->assertTrue($pq->find('form')->hasClass('doku_form')); $this->assertEquals(wl($ID, array('foo' => 'bar'), false, '&'), $pq->find('form')->attr('action')); $this->assertEquals('post', $pq->find('form')->attr('method')); $this->assertTrue($pq->find('input[name=sectok]')->length == 1); }
/** * check that posted values overwrite preset default */ function test_prefill() { global $INPUT; $INPUT->post->set('foo', 'second'); $form = new Form\Form(); $form->addRadioButton('foo', 'label text first')->val('first')->attr('checked', 'checked'); $form->addRadioButton('foo', 'label text second')->val('second'); $html = $form->toHTML(); $pq = phpQuery::newDocumentXHTML($html); $inputs = $pq->find('input[name=foo]'); $this->assertEquals('first', pq($inputs->elements[0])->val()); $this->assertEquals('second', pq($inputs->elements[1])->val()); $this->assertEquals('', pq($inputs->elements[0])->attr('checked')); $this->assertEquals('checked', pq($inputs->elements[1])->attr('checked')); }
/** * Creates phpQuery document from string or file. * Options: * FixHtml (True|False): Clean content by HtmlFormatter * phpQuery is a server-side, chainable, CSS3 selector driven Document Object Model (DOM), * API based on jQuery JavaScript Library. * More information: http://code.google.com/p/phpquery/ * * @param mixed $Document, string, file or url. * @return PhpQueryDocument object. */ function PqDocument($Document, $Options = False) { if (!function_exists('Pq')) { require_once USEFULFUNCTIONS_VENDORS . '/phpQuery.php'; } $Cache = GetValue('Cache', $Options); if ($Cache) { $Name = Crc32Value($Options); if ($Cache === True) { $Name = Crc32Value($Document, $Name); } $CacheDirectory = PATH_CACHE . '/PqDocument'; if (!is_dir($CacheDirectory)) { mkdir($CacheDirectory, 0777, True); } $CacheFile = $CacheDirectory . DS . $Name . '.php'; if (file_exists($CacheFile)) { $IncludeCache = True; if (is_numeric($Cache)) { $Created = filemtime($CacheFile); $LifeTime = time() - $Created; if ($LifeTime > $Cache) { // Cache expired. $IncludeCache = False; } } if ($IncludeCache) { $Document = (include $CacheFile); return phpQuery::newDocumentXHTML($Document); } } } if (strpos($Document, '<') === False) { if (is_file($Document) || substr($Document, 0, 7) == 'http://') { $Document = file_get_contents($Document); } } if (ArrayValue('ConvertEncoding', $Options)) { $Document = ConvertEncoding($Document); } if (ArrayValue('FixHtml', $Options, True)) { $HtmlFormatter = Gdn::Factory('HtmlFormatter'); if ($HtmlFormatter) { $Document = $HtmlFormatter->Format($Document); } } elseif (ArrayValue('Body', $Options, False)) { $BodyPos1 = strpos($Document, '<body'); $EndTag = '</body>'; $BodyPos2 = strrpos($Document, $EndTag); if ($BodyPos1 !== False) { if ($BodyPos2 === False) { $Document = substr($Document, $BodyPos1); } else { $Document = substr($Document, $BodyPos1, strlen($Document) - $BodyPos1 - strlen($EndTag)); } } } if ($Cache) { $Contents = "<?php if(!defined('APPLICATION')) exit(); \nreturn " . var_export($Document, True) . ';'; file_put_contents($CacheFile, $Contents); } return phpQuery::newDocumentXHTML($Document); }
/** * Creates phpQuery document from string or file. * Options: * FixHtml (True|False): Clean content by HtmlFormatter * phpQuery is a server-side, chainable, CSS3 selector driven Document Object Model (DOM), * API based on jQuery JavaScript Library. * More information: http://code.google.com/p/phpquery/ * * @param mixed $Document, string, file or url. * @return PhpQueryDocument object. */ function PqDocument($Document, $Options = False) { if (!function_exists('Pq')) { require_once USEFULFUNCTIONS_VENDORS . '/phpQuery.php'; } if (strpos($Document, '<') === False) { if (is_file($Document) || substr($Document, 0, 7) == 'http://') { $Document = file_get_contents($Document); } } if (ArrayValue('ConvertEncoding', $Options)) { $Document = ConvertEncoding($Document); } if (ArrayValue('FixHtml', $Options, True)) { $HtmlFormatter = Gdn::Factory('HtmlFormatter'); if ($HtmlFormatter) { $Document = $HtmlFormatter->Format($Document); } } return phpQuery::newDocumentXHTML($Document); }