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


PHP phpQuery::newDocumentXML方法代码示例

本文整理汇总了PHP中phpQuery::newDocumentXML方法的典型用法代码示例。如果您正苦于以下问题:PHP phpQuery::newDocumentXML方法的具体用法?PHP phpQuery::newDocumentXML怎么用?PHP phpQuery::newDocumentXML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在phpQuery的用法示例。


在下文中一共展示了phpQuery::newDocumentXML方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testExtend

 public function testExtend()
 {
     $newMethods = array('newMethod1' => array($this, 'callback1'), 'newMethod2' => array($this, 'callback2'));
     phpQuery::extend('phpQueryObject', $newMethods);
     $doc = phpQuery::newDocumentXML("<div/>");
     $this->assertTrue($doc->newMethod1() == $doc, '$doc->newMethod1 == $doc');
     $this->assertTrue($doc->newMethod2() == "callback2", '$doc->newMethod1 == "callback2"');
 }
开发者ID:fobiaphp,项目名称:phpquery,代码行数:8,代码来源:test_callback.php

示例2: _getCurrencyArray

 protected function _getCurrencyArray()
 {
     $client = new Zend_Http_Client($this->url);
     $response = $client->request('GET');
     if ($response->getStatus() != 200) {
         throw new Zend_Exception('Не удалось получить страницу курсов валют');
     }
     $body = $response->getBody();
     $phpq = phpQuery::newDocumentXML($body);
     $items = $phpq->find('ValCurs Valute');
     $result = array();
     foreach ($items as $el) {
         $code = pq($el)->find('CharCode')->text();
         $result[$code] = array('name' => pq($el)->find('Name')->text(), 'value' => pq($el)->find('Value')->text(), 'nominal' => pq($el)->find('Nominal')->text());
     }
     return $result;
 }
开发者ID:Konstnantin,项目名称:zf-app,代码行数:17,代码来源:Currency.php

示例3: processFeeds

 public function processFeeds($time)
 {
     if ($time >= $this->currentTime + self::PERIOD) {
         $this->currentTime = $time;
         $timers = $this->rssDb['timers'] ?: [];
         $rssStr = [];
         foreach ($this->pluginConfig['feeds'] as $feedName => $feedData) {
             $timer = array_key_exists($feedName, $timers) ? $timers[$feedName] : 0;
             if (!$feedData['enabled'] || $timer && $timer + $this->pluginConfig['refresh_timeout'] > $time) {
                 //                    \Util::debug('RSS not ready');
                 continue;
             }
             //                \Util::debug('RSS get ' . $feedData['url']);
             $response = $this->http->getResponse('GET', $feedData['url']);
             if ($response && $response->getStatusCode() === 200 && ($body = $response->getBody())) {
                 //                    \Util::debug('RSS got');
                 $format = array_key_exists('format', $feedData) ? $feedData['format'] : $this->pluginConfig['format'];
                 $items = \phpQuery::newDocumentXML($body)->find('channel item');
                 rsort($items);
                 foreach ($items as $item) {
                     \Util::debug($item);
                     $dateTime = \DateTime::createFromFormat(\DateTime::RSS, (string) pq($item)->find('pubDate')->text());
                     $matches = [];
                     \Util::debug([$dateTime->getTimestamp(), $timer]);
                     if ($dateTime->getTimestamp() > $timer && preg_match_all('/%(\\w+)%/', $format, $matches) && count($matches)) {
                         $timer = $dateTime->getTimestamp();
                         $matchesCount = count($matches[0]);
                         for ($i = 0; $i < $matchesCount; $i++) {
                             $rssStr[] = preg_replace($matches[0][$i], (string) pq($item)->find($matches[1][$i])->text(), $format);
                         }
                     }
                 }
             }
             if (count($rssStr)) {
                 foreach ($feedData['chats'] as $chatName) {
                     $this->core->send($chatName, implode(PHP_EOL, $rssStr));
                 }
                 $timers[$feedName] = $timer;
             }
         }
         $this->rssDb['timers'] = $timers;
     }
 }
开发者ID:WaveCutz,项目名称:skype-bot,代码行数:43,代码来源:Rss.php

示例4: parse

 function parse($file)
 {
     $authors = $posts = $attachments = $post = $author_snapshots = $authors_meta = array();
     if (!class_exists('phpQueryObject')) {
         require trailingslashit(TEMPLATEPATH) . 'functions/phpQuery/phpQuery.php';
     }
     $file_content = file_get_contents($file);
     if (!$file_content) {
         return new WP_Error('xml_parse_error', __('There was an error when reading this Kipling DTD file', 'anno'));
     }
     phpQuery::newDocumentXML($file_content);
     // Made up post IDs just for sanities sake, and parent relationship
     $post_id = 1;
     $articles = pq('article');
     // Lets make sure we have article tags
     $num_articles = $articles->length();
     if (empty($num_articles)) {
         return new WP_Error('xml_parse_article_error', __('This does not appear to be a Kipling DTD file, no articles could be found', 'anno'));
     }
     // Process articles, this contains all catergory, tag, author, term etc... processing.
     foreach ($articles as $article) {
         $article = pq('article');
         $article_meta = pq('article-meta', $article);
         $article_back = pq('back', $article);
         $post['post_type'] = 'article';
         $post['post_content_filtered'] = trim(pq('> body', $article)->html());
         $post['post_title'] = trim(pq('article-title', $article_meta)->text());
         $post['postmeta'][] = array('key' => '_anno_subtitle', 'value' => trim(pq('subtitle', $article_meta)->text()));
         // Auto generated
         $post['guid'] = '';
         $abstract = pq('abstract', $article_meta);
         // We don't want the title of the abstract
         pq('title', $abstract)->remove();
         // Just the text, wpautop is run on it later (excerpt)
         $post['post_excerpt'] = trim($abstract->text());
         // Post content gets generated by Annotum theme from the XML on wp_insert_post. We can leave it empty for now.
         $post['post_content'] = '';
         $post['post_id'] = $post_id;
         // Generated from post title on insert
         $post['post_name'] = '';
         $pub_date = pq('pub-date', $article_meta);
         $pub_date = $this->parse_date($pub_date);
         $post['post_date'] = (string) $pub_date;
         $post['post_date_gmt'] = (string) $pub_date;
         $post['status'] = 'draft';
         // Reflect in post_state meta as well.
         $post['postmeta'][] = array('key' => '_post_state', 'value' => 'draft');
         // Not used in Kipling DTD, but set for data structure integrity required by the importer
         $post['post_parent'] = 0;
         $post['menu_order'] = 0;
         $post['post_password'] = '';
         $post['is_sticky'] = 0;
         $post['ping_status'] = '';
         $post['comment_status'] = '';
         // Grab the category(ies). Annotum DTD should contain only one, Kipling DTD does not contain this requirement.
         foreach (pq('subject', $article_meta) as $category) {
             $category = pq($category);
             // We really don't care about the global categories, categories aren't defined outside of an article in the XML
             $cat_name = trim($category->text());
             if (!empty($cat_name)) {
                 $post['terms'][] = array('name' => $cat_name, 'slug' => sanitize_title($cat_name), 'domain' => 'article_category');
             }
         }
         // Grab the tags.
         foreach (pq('kwd', $article_meta) as $tag) {
             $tag = pq($tag);
             // We really don't care about the global tags, tags aren't defined outside of an article in the XML
             $tag_name = trim($tag->text());
             if (!empty($tag_name)) {
                 $post['terms'][] = array('name' => $tag_name, 'slug' => sanitize_title($tag_name), 'domain' => 'article_tag');
             }
         }
         // First author is the primary author, possible @todo - look for primary-author contrib type
         $first_author_check = true;
         $default_author_id = $first_author_id = 1;
         // Grab the author(s).
         foreach (pq('contrib', $article_meta) as $contributor) {
             $contributor = pq($contributor);
             $author_arr = $this->parse_author($contributor);
             $author = $author_arr['author'];
             $author_meta = $author_arr['author_meta'];
             // Check for author_id existance, if not, assign one.
             if (empty($author['author_id'])) {
                 $author['author_id'] = $default_author_id;
             }
             // Save in authors
             $authors[$author['author_id']] = $author;
             // Save in authors_meta, consistant with author_id to match on import of user
             $authors_meta[$author['author_id']] = $author_meta;
             if ($first_author_check) {
                 $post['post_author'] = $author['author_id'];
             }
             $author_snapshots[] = $this->author_snapshot($author, $author_meta);
             if ($first_author_check) {
                 // Used in attachment assignment
                 $first_author_id = $author['author_id'];
             }
             // We'll convert this in the import process
             $post['postmeta'][] = array('key' => '_anno_author_' . $author['author_id'], 'value' => $author['author_id']);
             $first_author_check = false;
//.........这里部分代码省略.........
开发者ID:kingofyeti,项目名称:wordpress,代码行数:101,代码来源:WXR_importer.php

示例5: initPhpQuery

 /**
  * @param $document
  * @param string $type
  */
 public static function initPhpQuery($document, $type = 'html')
 {
     try {
         if ($type == 'html') {
             phpQuery::newDocumentHTML($document);
         } else {
             $document = str_replace('encoding="gbk"', 'encoding="UTF-8"', $document);
             phpQuery::newDocumentXML($document);
         }
         usleep(2000000);
     } catch (Exception $e) {
         self::outError('phpQueryException', $e->getMessage());
         exit;
     }
 }
开发者ID:savey,项目名称:weixcraw,代码行数:19,代码来源:main.php

示例6: anno_reference_import_doi

/**
 * AJAX handler that looks up an article based on PMID and parses the data for a reference.
 * Echos a JSON encoded array
 * 
 * @return void
 */
function anno_reference_import_doi()
{
    check_ajax_referer('anno_import_doi', '_ajax_nonce-import-doi');
    if (!isset($_POST['doi'])) {
        anno_reference_error_response();
    } else {
        $doi = $_POST['doi'];
    }
    $lookup_response = array('message' => 'error', 'text' => _x('An error has occurred, please try again later', 'pmid lookup error message', 'anno'));
    // DOIs cannot contain any control characters. As defined here: http://www.doi.org/handbook_2000/appendix_1.html
    $doi = trim($doi);
    if (preg_match('/[\\x00-\\x1F\\x7F]/', $doi)) {
        anno_reference_error_response(_x('Invalid DOI', 'pmid lookup error message', 'anno'));
    }
    // Generate the URL for lookup
    $crossref_login = cfct_get_option('crossref_login');
    $crossref_pass = cfct_get_option('crossref_pass');
    // Empty login, or empty password and login is not an email.
    if (empty($crossref_login) || empty($crossref_pass) && !anno_is_valid_email($crossref_login)) {
        anno_reference_error_response(_x('Invalid CrossRef Login', 'pmid lookup error message', 'anno'));
    } else {
        if (empty($croossref_pass)) {
            $url = 'http://www.crossref.org/openurl/?pid=' . $crossref_login . '&id=doi:' . $doi . '&noredirect=true';
        } else {
            $url = 'http://www.crossref.org/openurl/?pid=' . $crossref_login . ':' . $crossref_pass . '&id=doi:' . $doi . '&noredirect=true';
        }
    }
    // Use wp.com functions if available for lookup.
    if (function_exists('vip_safe_wp_remote_get')) {
        $response = vip_safe_wp_remote_get($url);
    } else {
        $response = wp_remote_get($url);
    }
    if (is_wp_error($response) || isset($response['response']['code']) && $response['response']['code'] != 200 || !isset($response['body'])) {
        anno_reference_error_response();
    } else {
        include_once CFCT_PATH . 'functions/phpquery/phpquery.php';
        phpQuery::newDocumentXML($response['body']);
        phpQuery::getDocument();
        $html = pq('html');
        // If we find an HTML tag, echo error.
        if ($html->length > 0) {
            // We should only hit an HTML page for malformed URLs or invalid logins
            // @TODO error for invalid login.
            anno_reference_error_response(_x('Invalid DOI', 'pmid lookup error message', 'anno'));
        }
        $query_status = pq('query')->attr('status');
        // Error if unresolved
        if ($query_status == 'unresolved') {
            $lookup_response = anno_reference_error_response(pq('msg')->text());
        } else {
            if ($query_status == 'resolved') {
                $text = '';
                // There should only be a single 'first' author.
                $prime_author = pq('contributor[sequence="first"][contributor_role="author"]');
                $author_text = anno_reference_doi_process_author($prime_author);
                if (!empty($author_text)) {
                    $author_arr[] = $author_text;
                }
                $additional_authors = pq('contributor[sequence="additional"][contributor_role="author"]');
                foreach ($additional_authors as $additional_author) {
                    $additional_author = pq($additional_author);
                    $author_text = anno_reference_doi_process_author($additional_author);
                    if (!empty($author_text)) {
                        $author_arr[] = $author_text;
                    }
                }
                $text .= implode(', ', $author_arr) . '. ';
                // Title
                $title = pq('article_title')->text();
                if (!empty($title)) {
                    // Titles do not have periods
                    $text .= $title . '. ';
                }
                // Source
                $source = pq('journal_title')->text();
                if (!empty($source)) {
                    $text .= $source . '. ';
                }
                // Date, Volume, Issue, Page
                $date_meta = '';
                $date = pq('year')->text();
                $volume = pq('volume')->text();
                $issue = pq('issue')->text();
                $first_page = pq('first_page')->text();
                $last_page = pq('last_page')->text();
                if (!empty($date)) {
                    $date_meta .= $date;
                }
                if (!empty($volume) || !empty($issue) || !empty($page)) {
                    $date_meta .= ';';
                    if (!empty($volume)) {
                        $date_meta .= $volume;
                    }
//.........这里部分代码省略.........
开发者ID:nameofname,项目名称:momo-wordpress-theme,代码行数:101,代码来源:anno-article-lookup.php

示例7: ZipArchive

<?php

// Copyright 2014 David Lippman for Lumen Learning
// GPL Licensed
//
// Script for doing modifications to a common cartridge file
$file = "filename.zip";
require "phpQuery-onefile.php";
$zip = new ZipArchive();
$zip->open($file);
//read in manifest file
phpQuery::newDocumentXML($zip->getFromName("imsmanifest.xml"));
//read resource list so we know what file to look in for things
$ref = pq("resource");
$reflist = array();
$reftype = array();
foreach ($ref as $r) {
    $reflist[pq($r)->attr("identifier")] = pq($r)->attr("href");
    $reftype[pq($r)->attr("identifier")] = pq($r)->attr("type");
}
$cnt = 0;
//this accesses all the learning module items
//so this script will only modify items actually listed in the modules
$base = pq("item[identifier='LearningModules'] > item");
foreach ($base as $item) {
    $moduletitle = pq($item)->children("title")->html();
    $pgs = pq($item)->children("item");
    foreach ($pgs as $pg) {
        $title = addslashes(pq($pg)->children("title")->html());
        $iref = pq($pg)->attr("identifierref");
        if ($reftype[$iref] == "webcontent") {
开发者ID:jlagreca,项目名称:canvas-scripts-1,代码行数:31,代码来源:searchreplace.php

示例8: fetch

 /**
  * Fetch api endpoint response
  *
  * @param $endpoint
  * @param string $data
  * @param string $verb
  * @return mixed
  * @throws Exception
  */
 public function fetch($endpoint, $data = "", $verb = 'GET')
 {
     $queryStr = "";
     if ($data instanceof \phpQuery) {
         $data = (string) $data;
     } else {
         if (is_array($data)) {
             $queryStr = http_build_query($data);
             $data = "";
         }
     }
     $context = stream_context_create(array('http' => array('method' => $verb, 'header' => $this->getAuthHeader(), 'content' => $data)));
     $url = "{$this->apiUri}?srv={$endpoint}&{$queryStr}";
     $xml = file_get_contents($url, false, $context);
     $response = \phpQuery::newDocumentXML($xml);
     if ($response['error']->length > 0) {
         throw new Exception($response['error']->text(), $response['error']->attr('number'), (string) $response);
     }
     return $response;
 }
开发者ID:deboorn,项目名称:ccb-api,代码行数:29,代码来源:api.php

示例9: consulta


//.........这里部分代码省略.........
     if (0) {
         echo 'query_as_q: ' . $query_as_q . '<br />';
         echo 'query_as_epq: ' . $query_as_epq . '<br />';
         echo 'query_as_oq: ' . $query_as_oq . '<br />';
         echo 'query_as_eq: ' . $query_as_eq . '<br />';
         echo 'query_as_filetype: ' . $query_as_filetype . '<br />';
         echo 'query_as_qdr: ' . $query_as_qdr . '<br />';
         echo 'query_as_dt: ' . $query_as_dt . '<br />';
         echo 'query_as_sitesearch: ' . $query_as_sitesearch . '<br />';
         echo 'query_as_occt: ' . $query_as_occt . '<br />';
         echo '<br />http://www.google.com/cse?cx=009673987297622511854%3Adcpcxycquak&client=google-csbe&output=xml_no_dtd&cr=countryCL&num=10&q=' . $query . $query_as_q . $query_as_epq . $query_as_oq . $query_as_eq . $query_as_filetype . $query_as_qdr . $query_as_sitesearch . $filtro . $start;
         exit;
     }
     // create a new cURL resource
     $datosxml = curl_init();
     // set URL and other appropriate options
     //curl_setopt($datosxml, CURLOPT_URL, "http://www.google.com/cse?cx=009673987297622511854%3Adcpcxycquak&client=google-csbe&output=xml_no_dtd&cr=countryCL&num=10&q=" . $query . $query_as_q . $query_as_epq . $query_as_oq . $query_as_eq . $query_as_filetype . $query_as_qdr . $query_as_sitesearch . $filtro . $start);
     curl_setopt($datosxml, CURLOPT_URL, "http://www.google.com/cse?cx=009673987297622511854%3Adcpcxycquak&client=google-csbe&output=xml_no_dtd&cr=countryCL&num=10&q=" . $query . $query_as_q . $query_as_epq . $query_as_oq . $query_as_eq . $query_as_filetype . $query_as_qdr . $query_as_sitesearch . $filtro . $start);
     //curl_setopt($datosxml, CURLOPT_HEADER, 0);
     curl_setopt($datosxml, CURLOPT_RETURNTRANSFER, true);
     // grab URL and pass it to the browser
     $xml = curl_exec($datosxml);
     // close cURL resource, and free up system resources
     curl_close($datosxml);
     //definimos elchorizo, que es la url completa
     $elchorizo = $query . $query_as_q . $query_as_epq . $query_as_oq . $query_as_eq . $query_as_filetype . $query_as_qdr . $query_as_sitesearch . $filtro;
     $id = '';
     $url = '';
     $titulo = '';
     $bajada = '';
     $articulos = '';
     $data = array();
     $paginador = '';
     $doc = phpQuery::newDocumentXML($xml, $charset = 'utf-8');
     $sugerencia = pq('Spelling')->find('Suggestion')->text();
     $nroResultado = pq('M')->text();
     foreach (pq('R') as $articulo) {
         $destacado = 0;
         $id = pq($articulo)->attr('N');
         $url = pq($articulo)->children('U')->text();
         $titulo = pq($articulo)->children('T')->text();
         $bajada = pq($articulo)->find('S')->text();
         foreach (pq($articulo)->find('SL_MAIN') as $artDestacado) {
             $destacado = 1;
             $tmpdestacado = 1;
             foreach (pq($artDestacado)->find('BLOCK') as $artDestacadoInterior) {
                 $bajada = pq($artDestacadoInterior)->children('T')->text();
             }
         }
         if ($destacado) {
             $data['destacados'][$id] = '
                 <div class="box-art-dest" id="link_' . $id . '">
                     <h3><a href="' . $url . '">' . $titulo . '</a></h3>
                     <p>' . $bajada . '</p>
                     <a href="' . $url . '">' . $url . '</a>
                 </div>
                 ';
         } else {
             $data['articulos'][$id] = '
                 <div class="box-art" id="link_' . $id . '">
                     <h3><a href="' . $url . '">' . $titulo . '</a></h3>
                     <p>' . $bajada . '</p>
                     <a href="' . $url . '">' . $url . '</a>
                 </div>
                 ';
         }
开发者ID:e-gob,项目名称:ChileAtiende-buscador,代码行数:67,代码来源:buscador.php


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