本文整理汇总了PHP中phpQuery类的典型用法代码示例。如果您正苦于以下问题:PHP phpQuery类的具体用法?PHP phpQuery怎么用?PHP phpQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了phpQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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');
}
示例2: init
function init()
{
parent::init();
if (!$this->api->auth->isLoggedIn()) {
$this->js()->univ()->errorMessage('You Are Not Logged In')->execute();
}
if ($_POST['length'] != strlen($_POST['body_html'])) {
$this->js()->univ()->successMessage('Length send ' . $_POST['length'] . " AND Length calculated again is " . strlen($_POST['body_html']))->execute();
}
if ($_POST['crc32'] != sprintf("%u", crc32($_POST['body_html']))) {
$this->js()->univ()->successMessage('CRC send ' . $_POST['crc32'] . " AND CRC calculated again is " . sprintf("%u", crc32($_POST['body_html'])))->execute();
}
try {
$content = $_POST['body_html'];
include_once getcwd() . '/lib/phpQuery.php';
$pq = new \phpQuery();
$doc =& $pq->newDocument(trim($content));
// include_once getcwd().'/lib/phpQuery.php';
// $doc = \phpQuery::newDocument( $content );
$server = $doc['[data-is-serverside-component=true]'];
foreach ($doc['[data-is-serverside-component=true]'] as $ssc) {
$pq->pq($ssc)->html("")->append($html);
}
$content = $doc->htmlOuter();
$this->api->current_page['content'] = urldecode(trim($content));
$this->api->current_page['body_attributes'] = urldecode($_POST['body_attributes']);
$this->api->exec_plugins('epan-page-before-save', $this->api->current_page);
$this->api->current_page->save();
$this->api->exec_plugins('epan-page-after-save', $this->api->current_page);
if ($_POST['take_snapshot'] == 'Y') {
// $this->api->exec_plugins('epan-page-before-snapshot',$this->api->current_page);
$new_version = $this->api->current_page->ref('EpanPageSnapshots');
$new_version['title'] = $this->api->current_page['title'];
$new_version['keywords'] = $this->api->current_page['keywords'];
$new_version['description'] = $this->api->current_page['description'];
$new_version['body_attributes'] = $this->api->current_page['body_attributes'];
$new_version['content'] = $this->api->current_page['content'];
$new_version->save();
// $this->api->exec_plugins('epan-page-after-snapshot',$this->api->current_page);
}
} catch (Exception_StopInit $e) {
} catch (Exception $e) {
throw $e;
$this->js()->univ()->errorMessage('Error... Could not save your page ' . $e->getMEssage())->excute();
exit;
}
echo "saved";
exit;
}
示例3: hyphenate
public static function hyphenate($strBuffer)
{
global $objPage;
$arrSkipPages = \Config::get('hyphenator_skipPages');
if (is_array($arrSkipPages) && in_array($objPage->id, $arrSkipPages)) {
return $strBuffer;
}
$o = new \Org\Heigl\Hyphenator\Options();
$o->setHyphen(\Config::get('hyphenator_hyphen'))->setDefaultLocale(static::getLocaleFromLanguage($objPage->language))->setRightMin(\Config::get('hyphenator_rightMin'))->setLeftMin(\Config::get('hyphenator_leftMin'))->setWordMin(\Config::get('hyphenator_wordMin'))->setFilters(\Config::get('hyphenator_filter'))->setQuality(\Config::get('hyphenator_quality'))->setTokenizers(\Config::get('hyphenator_tokenizers'));
$h = new \Org\Heigl\Hyphenator\Hyphenator();
$h->setOptions($o);
$doc = \phpQuery::newDocumentHTML($strBuffer);
foreach (pq('body')->find(\Config::get('hyphenator_tags')) as $n => $item) {
$strText = pq($item)->html();
// ignore html tags, otherwise ­ will be added to links for example
if ($strText != strip_tags($strText)) {
continue;
}
$strText = str_replace('­', '', $strText);
// remove manual ­ html entities before
$strText = $h->hyphenate($strText);
if (is_array($strText)) {
$strText = current($strText);
}
pq($item)->html($strText);
}
return $doc->htmlOuter();
}
示例4: search_query
function search_query($kw)
{
$wf = new Workflows();
$url = 'http://www.bilibili.tv/search?keyword=' . urlencode($kw) . '&orderby=&formsubmit=';
$content = $wf->request($url, array(CURLOPT_ENCODING => 1));
$doc = phpQuery::newDocumentHTML($content);
$list = $doc->find('li.l');
$i = 0;
foreach ($list as $item) {
$link = pq($item)->children('a:first')->attr('href');
if (strpos($link, 'http') !== 0) {
$link = 'http://www.bilibili.tv' . $link;
}
$info = pq($item)->find('div.info > i');
$author = pq($item)->find('a.upper:first')->text();
$view = $info->eq(0)->text();
$comment = $info->eq(1)->text();
$bullet = $info->eq(2)->text();
$save = $info->eq(3)->text();
$date = $info->eq(4)->text();
$subtitle = 'UP主:' . $author . ' 播放:' . $view . ' 评论:' . $comment . ' 弹幕:' . $bullet . ' 收藏:' . $save . ' 日期:' . $date;
$wf->result($i, $link, pq($item)->find('div.t:first')->text(), $subtitle, 'icon.png', 'yes');
$i++;
}
if (count($wf->results()) == 0) {
$wf->result('0', $url, '在bilibili.tv中搜索', $kw, 'icon.png', 'yes');
}
return $wf->toxml();
}
示例5: finish
public function finish()
{
phpQuery::newDocumentFileHTML($this->downloadUrl, $this->charset);
$nodeCount = pq("#list2")->count();
$articleList = pq("#list2 tr");
echo "Start\n";
for ($i = 0; $i < $this->loop; $i++) {
echo '=';
}
echo "\n";
$i = 0;
foreach ($articleList as $tr) {
$i++;
if ($i <= 1) {
# Filter the first node which has no meaning.
continue;
}
$className = $tr->nodeValue;
# This class order and its name.
$classNameCombine = explode(' ', $className);
$j = 0;
$this->content[$i - 1]['chapterName'] = '';
foreach ($classNameCombine as $k => $v) {
# Put all class order and its name into $this->content array.
$v = trim($v);
if (empty($v)) {
continue;
}
$j++;
if ($j == 1) {
$this->content[$i - 1]['chapterId'] = $v;
} else {
$this->content[$i - 1]['chapterName'] .= $v . " ";
}
}
$child = pq("td", $tr)->html();
$trueContent = explode(' ', $child);
$linkString = '';
foreach ($trueContent as $k => $v) {
$v = trim($v);
if (empty($v)) {
continue;
}
if ($v == "<a") {
$linkString = $v . ' ' . $trueContent[$k + 1];
break;
}
}
$urls = explode("\"", $linkString);
$this->content[$i - 1]['link'] = $urls[1];
// $name = explode("<", $urls[2]);
// $name = substr($name[0], 1);
// $this->content[$i-1]['name'] = $name;
}
var_dump($this->content);
for ($i = 0; $i < $this->loop; $i++) {
echo '=';
}
echo "\nFinished! \n";
}
示例6: getAllSubCategories
function getAllSubCategories($filename)
{
$categories = unserialize(file_get_contents($filename));
echo "---- run getAllSubCategories() ----\n\r";
foreach ($categories as $j => $category) {
if ($category['childrens']) {
foreach ($category['childrens'] as $k => $children) {
echo "---- crawling childrens for {$children['name']} ----\n\r";
$doc = phpQuery::newDocumentHTML(fetch('http://www.walmart.com' . $children['link']));
phpQuery::selectDocument($doc);
foreach (pq('.shop-by-category li') as $el) {
echo "---- " . pq($el)->find('a')->attr('href') . "} ----\n\r";
$childrens[] = array('name' => pq($el)->find('a')->data('name'), 'link' => pq($el)->find('a')->attr('href'));
}
$categories[$j]['childrens'][$k]['childrens'] = $childrens;
}
}
}
echo "---- creating deparment file ----\n\r";
$file = fopen($filename, 'w+');
echo "---- writing deparment file ----\n\r";
fputs($file, serialize($categories));
echo "---- closing deparment file ----\n\r";
fclose($file);
}
示例7: first_image
public function first_image($htmldata)
{
$pq = phpQuery::newDocumentHTML($htmldata);
$img = $pq->find('img:first');
$src = $img->attr('src');
return $src;
}
示例8: parse_archive
public function parse_archive(Archive $archive)
{
if ($archive->cover_mode) {
return [$this->get_image_by_cover($archive->cover)];
}
$result = curl($archive->url, curl_options($this->domain));
$archivePQ = \phpQuery::newDocumentHTML($result['data']);
$content = $archivePQ['#content'];
$title = $content['.entry-title']->html();
$imgs = $content['.entry-content']->html();
if (preg_match_all('#' . $this->domain . 'wp-content/[^"]*#', $imgs, $matches)) {
$archive->images = array_merge(array_unique($matches[0]));
}
if (!$archive->images) {
$title = $content['.main-title']->html();
$imgs = $content['.main-body']->html();
if (preg_match_all('#<a[^>]+href="(' . $this->domain . 'wp-content/[^"]*)">#', $imgs, $matches)) {
$archive->images = array_merge(array_unique($matches[1]));
}
}
if (strtolower($this->charset) != strtolower($GLOBALS['app_config']['charset'])) {
$archive->title = iconv(strtoupper($this->charset), strtoupper($GLOBALS['app_config']['charset']) . '//IGNORE', $title);
}
$archive->title = $title;
}
示例9: 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;
}
}
示例10: 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);
}
示例11: theContent
function theContent($content)
{
$doc = phpQuery::newDocumentHTML($content);
phpQuery::selectDocument($doc);
foreach (pq('a') as $link) {
$linkurl = pq($link)->attr('href');
$linkHostname = $this->getUrlHostname($linkurl);
if ($linkHostname != FALSE) {
if (!in_array($linkHostname, $this->blockedDomains)) {
$linkHash = md5($linkurl);
$query = "SELECT * FROM {$this->tableBitlyExternal} WHERE id='{$linkHash}'LIMIT 1;";
$linkData = $this->db->get_row($query, ARRAY_A);
if (empty($linkData)) {
$bitly = new Bitly($this->bitlyUsername, $this->bitlyApikey);
$shortURL = $bitly->shorten($linkurl);
$shortURLData = get_object_vars($bitly->getData());
if (!empty($shortURLData)) {
$linkData = array('id' => $linkHash, 'url' => $linkurl, 'short_url' => $shortURLData['shortUrl'], 'hash' => $shortURLData['userHash'], 'created' => current_time('mysql'));
$this->db->insert($this->tableBitlyExternal, $linkData);
}
}
if (!empty($linkData)) {
pq($link)->attr('href', $linkData['short_url']);
}
}
}
}
return $doc->htmlOuter();
}
示例12: 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));
}
示例13: 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');
}
示例14: ___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;
}
示例15: go
public function go()
{
require_once $_SERVER["DOCUMENT_ROOT"] . "/classes/XML.php";
$xml = file_get_contents("http://alfabank.by/a-blog.xml");
$rss = new \XML($xml);
foreach ($rss->rss->channel->item as $it) {
$dom = \phpQuery::newDocumentHTML($it->childByName("content:encoded"));
$date = date_create($it->pubDate->getData());
$arResult = array(
"IBLOCK_ID" => self::ABLOG_IBLOCK_ID,
"NAME" => $it->title->getData(),
"DATE_ACTIVE_FROM" => date_format($date, 'd.m.Y'),
"PREVIEW_TEXT" => $it->description->getData(),
"PREVIEW_PICTURE" => \CFile::MakeFileArray($dom->find('img')->attr('src')),
"DETAIL_TEXT" => $it->childByName("content:encoded"),
"CODE" => \Ns\Bitrix\Helper::Create('iblock')->useVariant('text')->translite($it->title->getData()),
"PROPERTY_VALUES" => array("ORIGINAL_LINK" => $it->link->getData())
);
$this->objElement->Add($arResult);
if ($this->objElement->LAST_ERROR) {
prentExpection($this->objElement->LAST_ERROR);
}
}
return true;
}