当前位置: 首页>>代码示例>>PHP>>正文


PHP qp函数代码示例

本文整理汇总了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];
 }
开发者ID:ruudsilvrants,项目名称:news_importer,代码行数:34,代码来源:ExtractedItem.php

示例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;
 }
开发者ID:GitError404,项目名称:favrskov.dk,代码行数:34,代码来源:QPTPL.php

示例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');
 }
开发者ID:GettyScholarsWorkspace,项目名称:GettyScholarsWorkspace,代码行数:35,代码来源:QPXSLTest.php

示例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.');
     }
 }
开发者ID:rajeevs1992,项目名称:HVClientLibPHP,代码行数:29,代码来源:HealthRecordItemFactory.php

示例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]);
 }
开发者ID:the-tool,项目名称:the-tool,代码行数:34,代码来源:IpBlacklistController.php

示例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());
 }
开发者ID:danielbachhuber,项目名称:unholy,代码行数:8,代码来源:test-twentyfifteen-theme.php

示例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());
 }
开发者ID:danielbachhuber,项目名称:unholy,代码行数:8,代码来源:test-rss-feed.php

示例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;
 }
开发者ID:BarbershopLX,项目名称:wpinvoicexpress,代码行数:9,代码来源:InvoicexpressInvoices.php

示例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.");
    }
}
开发者ID:namchu,项目名称:FicSave,代码行数:56,代码来源:hpfanficarchive.php

示例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");
 }
开发者ID:sylae,项目名称:loungesim,代码行数:10,代码来源:roster.php

示例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));
 }
开发者ID:GitError404,项目名称:favrskov.dk,代码行数:11,代码来源:QPXSL.php

示例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']);
 }
开发者ID:GettyScholarsWorkspace,项目名称:GettyScholarsWorkspace,代码行数:11,代码来源:OptionsTest.php

示例13: testQPEntityReplacement

    public function testQPEntityReplacement()
    {
        $test = '<?xml version="1.0"?><root>&amp;&copy;&#38;& nothing.</root>';
        /*$expect = '<?xml version="1.0"?><root>&#38;&#169;&#38;&#38; nothing.</root>';*/
        // We get this because the DOM serializer re-converts entities.
        $expect = '<?xml version="1.0"?>
<root>&amp;&#xA9;&amp;&amp; nothing.</root>';
        $qp = qp($test, NULL, array('replace_entities' => TRUE));
        // Interestingly, the XML serializer converts decimal to hex and ampersands
        // to &amp;.
        $this->assertEquals($expect, trim($qp->xml()));
    }
开发者ID:GettyScholarsWorkspace,项目名称:GettyScholarsWorkspace,代码行数:12,代码来源:EntitiesTest.php

示例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.");
    }
}
开发者ID:namchu,项目名称:FicSave,代码行数:52,代码来源:fanfictionnet.php

示例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));
 }
开发者ID:asadlive84,项目名称:uniter-jquery,代码行数:14,代码来源:Query.php


注:本文中的qp函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。