本文整理汇总了PHP中phpQuery::newDocument方法的典型用法代码示例。如果您正苦于以下问题:PHP phpQuery::newDocument方法的具体用法?PHP phpQuery::newDocument怎么用?PHP phpQuery::newDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpQuery
的用法示例。
在下文中一共展示了phpQuery::newDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_data
public function get_data()
{
if (!class_exists('phpQuery')) {
include dirname(__FILE__) . '/phpQuery.php';
}
$response = wp_remote_get($this->url . '/tags');
if (is_wp_error($response)) {
return false;
}
phpQuery::newDocument($response['body']);
$version = false;
$zip_url = false;
foreach (pq('table.tags a.name') as $tag) {
$tag = pq($tag);
if (version_compare($tag->text(), $version, '>=')) {
$href = $tag->attr('href');
$commit = substr($href, strrpos($href, '/') + 1);
$zip_url = $this->url . '/snapshot/' . $commit . '.zip';
$version = $tag->text();
$updated_at = $tag->parent()->prev()->text();
}
}
$this->new_version = $version;
$this->zip_url = $zip_url;
$this->updated_at = date('Y-m-d', strtotime($updated_at));
$this->description = pq('div.page_footer_text')->text();
}
示例2: getBody
function getBody()
{
if ($this->parts && $this->body === null) {
foreach ($this->parts as $part) {
$partNo = $part['partNo'];
$encoding = $part['encoding'];
$charset = $part['charset'];
$body = imap_fetchbody($this->message->getMailbox(), $this->message->getUID(), $partNo, FT_UID);
$body = BrIMAP::decode($body, $encoding);
if ($charset) {
$body = @iconv($charset, 'UTF-8', $body);
}
$body = trim($body);
$body = preg_replace('~<head[^>]*?>.*?</head>~ism', '', $body);
$body = preg_replace('~<meta[^>]*?>~ism', '', $body);
$body = preg_replace('~<base[^>]*?>~ism', '', $body);
$body = preg_replace('~<style[^>]*?>.*?</style>~ism', '', $body);
if ($this->isHTML && $body) {
try {
$doc = phpQuery::newDocument($body);
$bodyTag = $doc->find('body');
if ($bodyTag->length() > 0) {
$body = trim(pq($bodyTag)->html());
} else {
$body = trim($doc->html());
}
phpQuery::unloadDocuments();
} catch (Exception $e) {
}
}
$this->body .= $body;
}
}
return $this->body;
}
示例3: find_product_url
public function find_product_url($product_name)
{
$url = 'http://ek.ua/';
$data = array('search_' => $product_name);
$response = Request::factory($url)->query($data)->execute();
//echo Debug::vars($response->body());
//echo Debug::vars($response->headers());
$response = $response->body();
try {
$doc = phpQuery::newDocument($response);
} catch (Exception $ex) {
$errors[] = $ex->getMessage();
echo Debug::vars($errors);
}
if (!isset($errors)) {
/* Нужно взять заголовок и найти в нем слово найдено */
/*
* что я заметил, удивительно но на разных машинах этот заголовои идет с разным классом
* на данный момент этот класс oth
*/
$str = $doc->find('h1.oth')->html();
if (preg_match('/найдено/', $str)) {
echo Debug::vars('алилуя !!!');
die;
}
return $str;
}
}
示例4: test_data
public function test_data()
{
$this->prepareLookup();
$this->preparePages();
$access = AccessTable::byTableName('dropdowns', 'test1');
$data = $access->getData();
$this->assertEquals('["1","[\\"title1\\",\\"This is a title\\"]"]', $data[0]->getValue());
$this->assertEquals('["1","title1"]', $data[1]->getValue());
$this->assertEquals('John', $data[2]->getValue());
$this->assertEquals('1', $data[0]->getRawValue());
$this->assertEquals('1', $data[1]->getRawValue());
$this->assertEquals('John', $data[2]->getRawValue());
$this->assertEquals('This is a title', $data[0]->getDisplayValue());
$this->assertEquals('title1', $data[1]->getDisplayValue());
$this->assertEquals('John', $data[2]->getDisplayValue());
$R = new \Doku_Renderer_xhtml();
$data[0]->render($R, 'xhtml');
$pq = \phpQuery::newDocument($R->doc);
$this->assertEquals('This is a title', $pq->find('a')->text());
$this->assertContains('title1', $pq->find('a')->attr('href'));
$R = new \Doku_Renderer_xhtml();
$data[1]->render($R, 'xhtml');
$pq = \phpQuery::newDocument($R->doc);
$this->assertEquals('title1', $pq->find('a')->text());
$this->assertContains('title1', $pq->find('a')->attr('href'));
$R = new \Doku_Renderer_xhtml();
$data[2]->render($R, 'xhtml');
$this->assertEquals('John', $R->doc);
}
示例5: createSpots
function createSpots()
{
// TODO :: Some caching ??
$this->pq = $pq = new phpQuery();
$this->dom = $dom = $pq->newDocument($this->owner->template->template_source);
if (!$this->owner instanceof \Frontend) {
$pq->pq($dom)->attr('xepan-page-content', 'true');
$pq->pq($dom)->addClass('xepan-page-content');
}
foreach ($dom['.xepan-component'] as $d) {
$d = $pq->pq($d);
if (!$d->hasClass('xepan-serverside-component')) {
continue;
}
$i = $this->spots++;
$inner_html = $d->html();
$with_spot = '{' . $this->owner->template->name . '_' . $i . '}' . $inner_html . '{/}';
$d->html($with_spot);
}
$content = $this->updateBaseHrefForTemplates();
$content = str_replace('<!--xEpan-ATK-Header-Start', '', $content);
$content = str_replace('xEpan-ATK-Header-End-->', '', $content);
$this->owner->template->loadTemplateFromString($content);
$this->owner->template->trySet($this->app->page . '_active', 'active');
}
示例6: queryHTML
/**
* Query the response for a JQuery compatible CSS selector
*
* @link https://code.google.com/p/phpquery/wiki/Selectors
* @param $selector string
* @return phpQueryObject
*/
public function queryHTML($selector)
{
if (is_null($this->pq)) {
$this->pq = phpQuery::newDocument($this->content);
}
return $this->pq->find($selector);
}
示例7: getLinkContent
public function getLinkContent()
{
require_once './ThinkPHP/Library/Vendor/Collection/phpQuery.php';
$link = op_t(I('post.url'));
$content = get_content_by_url($link);
$charset = preg_match("/<meta.+?charset=[^\\w]?([-\\w]+)/i", $content, $temp) ? strtolower($temp[1]) : "utf-8";
\phpQuery::$defaultCharset = $charset;
\phpQuery::newDocument($content);
$title = pq("meta[name='title']")->attr('content');
if (empty($title)) {
$title = pq("title")->html();
}
$title = iconv($charset, "UTF-8", $title);
$keywords = pq("meta[name='keywords'],meta[name='Keywords']")->attr('content');
$description = pq("meta[name='description'],meta[name='Description']")->attr('content');
$url = parse_url($link);
$img = pq("img")->eq(0)->attr('src');
if (is_bool(strpos($img, 'http://'))) {
$img = 'http://' . $url['host'] . $img;
}
$title = text($title);
$description = text($description);
$keywords = text($keywords);
$return['title'] = $title;
$return['img'] = $img;
$return['description'] = empty($description) ? $title : $description;
$return['keywords'] = empty($keywords) ? $title : $keywords;
exit(json_encode($return));
}
示例8: testShowData
function testShowData()
{
$handler = new Doku_Handler();
$xhtml = new Doku_Renderer_xhtml();
$plugin = new syntax_plugin_data_entry();
$result = $plugin->handle($this->exampleEntry, 0, 10, $handler);
$plugin->_showData($result, $xhtml);
$doc = phpQuery::newDocument($xhtml->doc);
$this->assertEquals(1, pq('div.inline.dataplugin_entry.projects', $doc)->length);
$this->assertEquals(1, pq('dl dt.type')->length);
$this->assertEquals(1, pq('dl dd.type')->length);
$this->assertEquals(1, pq('dl dt.volume')->length);
$this->assertEquals(1, pq('dl dd.volume')->length);
$this->assertEquals(1, pq('dl dt.employee')->length);
$this->assertEquals(1, pq('dl dd.employee')->length);
$this->assertEquals(1, pq('dl dt.customer')->length);
$this->assertEquals(1, pq('dl dd.customer')->length);
$this->assertEquals(1, pq('dl dt.deadline')->length);
$this->assertEquals(1, pq('dl dd.deadline')->length);
$this->assertEquals(1, pq('dl dt.server')->length);
$this->assertEquals(1, pq('dl dd.server')->length);
$this->assertEquals(1, pq('dl dt.website')->length);
$this->assertEquals(1, pq('dl dd.website')->length);
$this->assertEquals(1, pq('dl dt.task')->length);
$this->assertEquals(1, pq('dl dd.task')->length);
$this->assertEquals(1, pq('dl dt.tests')->length);
$this->assertEquals(1, pq('dl dd.tests')->length);
}
示例9: real_test
function real_test($idnum, $name)
{
error_reporting(E_ALL);
ini_set('display_errors', 'On');
include './vendor/autoload.php';
//$idnum = '130123198706234534';
//$name = '祁星月';
$url = 'http://www.runchina.org.cn/portal.php?mod=score&ac=personal';
$headstr = "-H 'Pragma: no-cache' -H 'Origin: http://www.runchina.org.cn' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4,ja;q=0.2' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: no-cache' -H 'Referer: http://www.runchina.org.cn/portal.php?mod=score&ac=personal' -H 'Cookie: SMHa_2132_saltkey=tQi19Tmq; SMHa_2132_lastvisit=1468828350; SMHa_2132_sid=l9z09Q; SMHa_2132_lastact=1468832009%09portal.php%09score; Hm_lvt_b0a502205e02e6127ae831a751ff05b3=1468831949; Hm_lpvt_b0a502205e02e6127ae831a751ff05b3=1468832009' -H 'Connection: keep-alive'";
$data = array('idnum' => $idnum, 'name' => $name);
$reg = '/\'([A-Za-z]+)\\:\\s?([^\']+)\'/';
preg_match_all($reg, $headstr, $matches);
$keys = $matches[1];
$values = $matches[2];
$headers = array_combine($keys, $values);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$content = curl_exec($ch);
$pq = phpQuery::newDocument($content);
$real_items = array();
$results = $pq->find("table tr:gt(0)");
foreach ($results as $result) {
$x = $result->nodeValue;
$v = explode("\n", $x);
$real_items[] = array($v[0], trim($v[2]), trim($v[5]), trim($v[6]));
}
echo json_encode($real_items);
}
示例10: addclass
public function addclass($html, $selector, $class)
{
require __DIR__ . '/phpQuery.php';
$pq = \phpQuery::newDocument($html);
$pq[$selector]->addClass($class);
return new \Twig_Markup($pq, 'UTF-8');
}
示例11: __construct
function __construct($bookfile)
{
$src = file_get_contents($bookfile);
$this->source_dir = dirname($bookfile);
list($meta, $src) = explode("\n\n", $src, 2);
foreach (explode("\n", $meta) as $line) {
list($k, $v) = explode(":", $line, 2);
list($dk, $mk) = explode('-', trim($k), 2);
if ($dk == 'doc') {
$this->doc_meta[$mk] = trim($v);
} else {
if ($dk) {
$this->meta[$dk . $mk] = trim($v);
}
}
}
$src = $this->fetch_includes($src);
$layout = "default_layout.html";
if (true) {
$this->html = $this->layout($layout, array("content" => Markdown($src)));
} else {
$this->html = '<div id="body"><div id="cont">' . Markdown($src) . "</div></div>";
}
if ($this->doc_meta['toc-levels']) {
$this->levels = explode(',', $this->doc_meta['toc-levels']);
} else {
$this->levels = array('h1', 'h2');
}
$doc = phpQuery::newDocument($this->html);
$this->docID = $doc->getDocumentID();
}
示例12: ___render___
/**
* ___render___
*
* @method ___render___
* @param {string} $content
*/
protected function ___render___($content)
{
if ($content && is_string($content)) {
if ($this->functions_for_render && (is_array($this->functions_for_render) || $this->functions_for_render instanceof ArrayObject)) {
$before = $this->cache_read === true ? array() : array_filter((array) $this->functions_for_render, create_function('$v', 'return $v[\'after_cache\'] !== true;'));
$after = array_filter((array) $this->functions_for_render, create_function('$v', 'return $v[\'after_cache\'] === true;'));
} else {
$before = $after = array();
}
if (0 < count($before) || 0 < count($after)) {
$pq = phpQuery::newDocument($content);
//before cache
foreach ($before as $fn) {
$pq = call_user_func($fn, $pq);
}
if ($this->cache_file && !$this->cache_read) {
file_put_contents($this->cache_file, $pq);
}
//after cache
foreach ($before as $fn) {
$pq = call_user_func($fn, $pq);
}
$content = $pq;
} else {
if ($this->cache_file) {
file_put_contents($this->cache_file, $content);
}
}
}
echo $content;
}
示例13: getcwd
function Plugins_RunServerSideComponent($obj, $page)
{
include_once getcwd() . '/lib/phpQuery.php';
$pq = new \phpQuery();
$doc = $pq->newDocument($page['content']);
$server = $doc['[data-is-serverside-component=true]'];
foreach ($doc['[data-is-serverside-component=true]'] as $ssc) {
$options = array();
foreach ($ssc->attributes as $attrName => $attrNode) {
$options[$attrName] = $pq->pq($ssc)->attr($attrName);
}
$namespace = $pq->pq($ssc)->attr('data-responsible-namespace');
$view = $pq->pq($ssc)->attr('data-responsible-view');
if (!file_exists($path = getcwd() . DS . 'epan-components' . DS . $namespace . DS . 'lib' . DS . 'View' . DS . 'Tools' . DS . str_replace("View_Tools_", "", $view) . '.php')) {
$temp_view = $this->owner->add('View_Error')->set("Server Side Component Not Found :: {$namespace}/{$view}");
} else {
$temp_view = $this->owner->add("{$namespace}/{$view}", array('html_attributes' => $options, 'data_options' => $pq->pq($ssc)->attr('data-options')));
}
if (!$_GET['cut_object'] and !$_GET['cut_page']) {
$html = $temp_view->getHTML();
$pq->pq($ssc)->html("")->append($html);
}
}
$page['content'] = $doc->htmlOuter();
}
示例14: run
public function run()
{
$content = ob_get_clean();
$formatted = phpQuery::newDocument($content);
$imageNodes = pq('img');
foreach ($imageNodes as $imNode) {
$imNode = pq($imNode);
$imPath = $imNode->attr('src');
$thumbPath = $this->thumbsDir . '/' . basename($imPath);
//$thumbPath = dirname($imPath).'/thumbs/'.basename($imPath);
// Create thumbnail if not exists
if (!file_exists($thumbPath)) {
$imgObj = Yii::app()->simpleImage->load($imPath);
if (!isset($this->thumbHeight)) {
$imgObj->resizeToWidth($this->thumbWidth);
} else {
$imgObj->resize($this->thumbWidth, $this->thumbHeight);
}
$imgObj->save($thumbPath);
}
$imNode->wrap('<a href="' . $imPath . '" rel="gallery"></a>');
$imNode->attr('src', Yii::app()->request->baseUrl . DIRECTORY_SEPARATOR . $thumbPath);
}
echo $formatted;
}
示例15: success
public function success($response)
{
$pq = phpQuery::newDocument($response);
foreach ($this->calls as $k => $r) {
// check if method exists
if (!method_exists(get_class($pq), $r['method'])) {
throw new Exception("Method '{$r['method']}' not implemented in phpQuery, sorry...");
// execute method
} else {
$pq = call_user_func_array(array($pq, $r['method']), $r['arguments']);
}
}
if (!isset($this->options['dataType'])) {
$this->options['dataType'] = '';
}
switch (strtolower($this->options['dataType'])) {
case 'json':
if ($pq instanceof PHPQUERYOBJECT) {
$results = array();
foreach ($pq as $node) {
$results[] = pq($node)->htmlOuter();
}
print phpQuery::toJSON($results);
} else {
print phpQuery::toJSON($pq);
}
break;
default:
print $pq;
}
// output results
}