本文整理汇总了PHP中qp函数的典型用法代码示例。如果您正苦于以下问题:PHP qp函数的具体用法?PHP qp怎么用?PHP qp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了qp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extractValue
/**
* @param string $name
* @return string
*/
public function extractValue($name)
{
if (isset($this->extractedValues[$name])) {
return $this->extractedValues[$name];
}
$mapping = isset($this->itemMapping[$name]) ? $this->itemMapping[$name] : $name;
if (is_string($mapping)) {
$mapping = array('selector' => $mapping);
}
$value = !empty($mapping['defaultValue']) ? $mapping['defaultValue'] : '';
if (empty($mapping['selector']) && empty($mapping['defaultValue'])) {
throw new \RuntimeException('Missing \'selector\' or \'defaultValue\' for ' . htmlentities($name) . ' mapping');
}
if (!empty($mapping['selector'])) {
if (!empty($mapping['source'])) {
$source = $this->extractorService->extractValue($this->item, $mapping['source']);
$source = $this->extractorService->fetchRawContent($source);
try {
$item = qp($source);
} catch (\QueryPath\Exception $e) {
$item = htmlqp($source);
}
} else {
$item = $this->item;
}
$value = $this->extractorService->extractValue($item, $mapping, $value);
}
$this->extractedValues[$name] = $value;
return $this->extractedValues[$name];
}
示例2: tplArrayR
public function tplArrayR($qp, $array, $options = NULL)
{
if (!is_array($array) && !$array instanceof Traversable) {
$qp->append($array);
} elseif ($this->isAssoc($array)) {
foreach ($array as $k => $v) {
$first = substr($k, 0, 1);
if ($first != '.' && $first != '#') {
$k = '.' . $k;
}
if (is_array($v)) {
$this->tplArrayR($qp->top($k), $v, $options);
} else {
$qp->branch()->children($k)->append($v);
}
}
} else {
foreach ($array as $entry) {
$eles = $qp->get();
$template = array();
foreach ($eles as $ele) {
$template = $ele->cloneNode(TRUE);
}
$tpl = qp($template);
$tpl = $this->tplArrayR($tpl, $entry, $options);
$qp->before($tpl);
}
$dead = $qp->branch();
$qp->parent();
$dead->remove();
unset($dead);
}
return $qp;
}
示例3: testXSLT
public function testXSLT()
{
// XML and XSLT taken from http://us.php.net/manual/en/xsl.examples-collection.php
// and then modified to be *actually welformed* XML.
$orig = '<?xml version="1.0"?><collection>
<cd>
<title>Fight for your mind</title>
<artist>Ben Harper</artist>
<year>1995</year>
</cd>
<cd>
<title>Electric Ladyland</title>
<artist>Jimi Hendrix</artist>
<year>1997</year>
</cd>
</collection>';
$template = '<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="owner" select="\'Nicolas Eliaszewicz\'"/>
<xsl:output method="html" encoding="iso-8859-1" indent="no"/>
<xsl:template match="collection">
<div>
Hey! Welcome to <xsl:value-of select="$owner"/>\'s sweet CD collection!
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="cd">
<h1><xsl:value-of select="title"/></h1>
<h2>by <xsl:value-of select="artist"/> - <xsl:value-of select="year"/></h2>
<hr />
</xsl:template>
</xsl:stylesheet>
';
$qp = qp($orig)->xslt($template);
$this->assertEquals(2, $qp->top('h1')->size(), 'Make sure that data was formatted');
}
示例4: getThing
public static function getThing($type_or_qp, $version = 0)
{
$thingNames = array_flip(HVRawConnector::$things);
$typeId = '';
if ($type_or_qp instanceof Query) {
$typeId = $type_or_qp->top()->find('type-id')->text();
} elseif (is_string($type_or_qp)) {
$typeId = HealthRecordItemFactory::getTypeId($type_or_qp);
$template = __DIR__ . '/HealthRecordItem/XmlTemplates/' . $typeId . '.xml';
if (is_readable($template)) {
$type_or_qp = qp(file_get_contents($template), NULL, array('use_parser' => 'xml'));
}
} else {
throw new HVClientException('ThingFactory::getThing must be called with a valid thing name or type id or a QueryPath object representing a thing.');
}
if ($typeId) {
if ($type_or_qp instanceof Query) {
if ($className = HealthRecordItemFactory::convertThingNameToClassName($thingNames[$typeId])) {
return new $className($type_or_qp);
} else {
throw new HVClientException('Things of that type id are not supported yet: ' . $typeId);
}
} else {
throw new HVClientException('Creation of new empty things of that type id is not supported yet: ' . $typeId);
}
} else {
throw new HVClientException('Unable to detect type id.');
}
}
示例5: index
/**
* Check IP address for present in public blacklists.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
$ipAddress = Input::get('ipV4');
$ipAddress = trim($ipAddress);
if ($ipAddress == '') {
$ipAddress = $_SERVER['REMOTE_ADDR'];
}
$checkPerformed = false;
$inBlacklist = false;
$blacklistInfoLinks = [];
$checkerUrl = '';
if (Input::get('check')) {
$spamhausBaseUrl = 'http://www.spamhaus.org';
$checkerUrl = $spamhausBaseUrl . '/query/ip/' . $ipAddress;
// :TODO: Get with guzzle
$data = file_get_contents($checkerUrl);
foreach (qp($data, 'span.body') as $row) {
$link = $row->find('ul li a')->attr('href');
if ($link != '') {
$blacklistInfoLinks[] = $spamhausBaseUrl . $link;
}
}
if (!empty($blacklistInfoLinks)) {
$inBlacklist = true;
}
$checkPerformed = true;
}
return view('ip-blacklist.form', ['ipV4' => $ipAddress, 'inBlacklist' => $inBlacklist, 'blacklistInfoLinks' => $blacklistInfoLinks, 'checkerUrl' => $checkerUrl, 'checkPerformed' => $checkPerformed]);
}
示例6: test_header
public function test_header()
{
update_option('blogname', 'Unholy Site Title');
update_option('blogdescription', 'Unholy Site Description');
$dom = $this->get_permalink_as_dom('/');
$this->assertEquals('Unholy Site Title', qp($dom, '#masthead .site-title')->text());
$this->assertEquals('Unholy Site Description', qp($dom, '#masthead .site-description')->text());
}
示例7: test_rss_feed_loads_post
public function test_rss_feed_loads_post()
{
$user_id = $this->factory->user->create(array('display_name' => 'Unholy Author'));
$this->factory->post->create(array('post_title' => 'Unholy Post Title', 'post_author' => $user_id));
$dom = $this->get_feed_as_dom(home_url('feed/'));
$this->assertEquals('Unholy Post Title', qp($dom, 'channel item title')->eq(0)->text());
$this->assertEquals('Unholy Author', qp($dom, 'channel item dc|creator')->eq(0)->text());
}
示例8: filterDate
public function filterDate($date_start, $date_end)
{
$this->items = $this->items->filterCallback(function ($index, $item) use($date_start, $date_end) {
$text = qp($item)->find('due_date')->text();
$date = strtotime(implode('-', array_reverse(explode('/', $text))));
return $date_start <= $date && $date <= $date_end;
});
return $this;
}
示例9: getHPFanficArchiveInfo
function getHPFanficArchiveInfo($url)
{
$urlParts = parse_url($url);
parse_str($urlParts['query'], $query);
if (isset($query['sid'])) {
$storyId = $query['sid'];
if (is_numeric($storyId)) {
$url = "{$urlParts['scheme']}://{$urlParts['host']}/stories/viewstory.php?sid={$storyId}";
$response = cURL($url);
$html = new HTML5();
$html = $html->loadHTML($response);
$story = new Story();
$story->id = $storyId;
$story->url = $url;
$title = qp($html, '#pagetitle')->find('a[href^="viewstory"]')->first()->text();
if (empty($title)) {
throw new FicSaveException("Could not retrieve title for story at {$url}.");
} else {
$story->title = $title;
}
$author = qp($html, '#pagetitle')->find('a[href^="viewuser"]')->first()->text();
if (empty($author)) {
throw new FicSaveException("Could not retrieve author for story at {$url}.");
} else {
$story->author = $author;
}
$description = qp($html, '#mainpage')->find('.block')->get(1);
if ($description == NULL) {
throw new FicSaveException("Could not retrieve description for story at {$url}.");
} else {
$story->description = stripAttributes(preg_replace('/<a(.*?)>(.*?)<\\/a>/', '\\2', trim(qp($description)->find('.content')->first()->innerHTML())));
}
$chaptersBlock = qp($html, '#mainpage')->find('.block')->get(3);
if ($chaptersBlock == NULL) {
throw new FicSaveException("Could not get number of chapters for story at {$url}.");
} else {
$chapterLinks = qp($chaptersBlock)->find('a[href^="viewstory"]');
$numChapters = $chapterLinks->count();
if ($numChapters > 0) {
$story->chapters = $numChapters;
$story->metadata = array();
foreach ($chapterLinks as $chapterLink) {
$story->metadata[] = $chapterLink->text();
}
} else {
throw new FicSaveException("Could not get number of chapters for story at {$url}.");
}
}
return $story;
} else {
throw new FicSaveException("URL has an invalid story ID: {$storyId}.");
}
} else {
throw new FicSaveException("URL is missing story ID.");
}
}
示例10: eventPresenceDefault
private function eventPresenceDefault($room, $nick, $item, $stanza)
{
// away, dnd, xa, chat, [default].
$show = \qp($stanza, 'show')->text() || 'default';
$status = \qp($stanza, 'status')->text() || '';
// Create the user object.
$user = array('nick' => $nick, 'jid' => $item->attr('jid'), 'role' => $item->attr('role'), 'affiliation' => $item->attr('affiliation'), 'show' => $show, 'status' => $status);
$this->roster[$room][$nick] = $user;
l("[" . $room . "] " . $user['nick'] . " joined room");
}
示例11: xslt
public function xslt($style)
{
if (!$style instanceof QueryPath) {
$style = qp($style);
}
$sourceDoc = $this->src->top()->get(0)->ownerDocument;
$styleDoc = $style->get(0)->ownerDocument;
$processor = new XSLTProcessor();
$processor->importStylesheet($styleDoc);
return qp($processor->transformToDoc($sourceDoc));
}
示例12: testQPOverrideOrder
public function testQPOverrideOrder()
{
$expect = array('test1' => 'val3', 'test2' => 'val2');
$options = array('test1' => 'val1', 'test2' => 'val2');
Options::set($options);
$qpOpts = qp(NULL, NULL, array('test1' => 'val3', 'replace_entities' => TRUE))->getOptions();
$this->assertEquals($expect['test1'], $qpOpts['test1']);
$this->assertEquals(TRUE, $qpOpts['replace_entities']);
$this->assertNull($qpOpts['parser_flags']);
$this->assertEquals($expect['test2'], $qpOpts['test2']);
}
示例13: testQPEntityReplacement
public function testQPEntityReplacement()
{
$test = '<?xml version="1.0"?><root>&©&& nothing.</root>';
/*$expect = '<?xml version="1.0"?><root>&©&& nothing.</root>';*/
// We get this because the DOM serializer re-converts entities.
$expect = '<?xml version="1.0"?>
<root>&©&& nothing.</root>';
$qp = qp($test, NULL, array('replace_entities' => TRUE));
// Interestingly, the XML serializer converts decimal to hex and ampersands
// to &.
$this->assertEquals($expect, trim($qp->xml()));
}
示例14: getFanfictionNetInfo
function getFanfictionNetInfo($url)
{
$urlParts = parse_url($url);
$pathParts = explode('/', $urlParts['path']);
if (isset($pathParts[2])) {
$storyId = $pathParts[2];
if (is_numeric($storyId)) {
$response = cURL($url);
$html = new HTML5();
$html = $html->loadHTML($response);
$story = new Story();
$story->id = $storyId;
$urlParts = parse_url($url);
$story->url = "{$urlParts['scheme']}://{$urlParts['host']}/s/{$storyId}";
$title = qp($html, '#profile_top')->find('b')->first()->text();
if (empty($title)) {
throw new FicSaveException("Could not retrieve title for story at {$url}.");
} else {
$story->title = $title;
}
$author = qp($html, '#profile_top')->find('a')->first()->text();
if (empty($author)) {
throw new FicSaveException("Could not retrieve author for story at {$url}.");
} else {
$story->author = $author;
}
$description = qp($html, '#profile_top')->find('div')->get(2);
if ($description == NULL) {
throw new FicSaveException("Could not retrieve description for story at {$url}.");
} else {
$story->description = stripAttributes(preg_replace('/<a(.*?)>(.*?)<\\/a>/', '\\2', trim(qp($description)->html() . qp($description)->next()->html())));
}
$numChapters = qp($html, '#chap_select')->find('option')->count() / 2;
// value is always doubled for some reason
$story->chapters = $numChapters == 0 ? 1 : $numChapters;
$coverImageUrl = qp($html, '#profile_top')->find('img')->first()->attr('src');
if ($coverImageUrl != NULL) {
$coverImageUrlParts = parse_url($coverImageUrl);
if (!isset($coverImageUrlParts['scheme']) && substr($coverImageUrl, 0, 2) == '//') {
$coverImageUrl = $urlParts['scheme'] . ":" . $coverImageUrl;
}
$coverImageUrl = str_replace('/75/', '/180/', $coverImageUrl);
$story->coverImageUrl = $coverImageUrl;
}
return $story;
} else {
throw new FicSaveException("URL has an invalid story ID: {$storyId}.");
}
} else {
throw new FicSaveException("URL is missing story ID.");
}
}
示例15: parents
public function parents($selector = null)
{
$parents = $this->wrappedQuery->parents();
if ($selector === null) {
return $this->createQuery($parents);
}
$matchingParents = array();
foreach ($parents as $parent) {
if ($this->matcher->matches($parent->get(0), $selector)) {
$matchingParents[] = $parent->get(0);
}
}
return $this->createQuery(qp($matchingParents));
}