本文整理汇总了PHP中phpQuery::getDocument方法的典型用法代码示例。如果您正苦于以下问题:PHP phpQuery::getDocument方法的具体用法?PHP phpQuery::getDocument怎么用?PHP phpQuery::getDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpQuery
的用法示例。
在下文中一共展示了phpQuery::getDocument方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: trigger
/**
* Trigger a type of event on every matched element.
*
* @param DOMNode|phpQueryObject|string $document
* @param unknown_type $type
* @param unknown_type $data
*
* @TODO exclusive events (with !)
* @TODO global events (test)
* @TODO support more than event in $type (space-separated)
*/
public static function trigger($document, $type, $data = array(), $node = null)
{
// trigger: function(type, data, elem, donative, extra) {
$documentID = phpQuery::getDocumentID($document);
$namespace = null;
if (strpos($type, '.') !== false) {
list($name, $namespace) = explode('.', $type);
} else {
$name = $type;
}
if (!$node) {
if (self::issetGlobal($documentID, $type)) {
$pq = phpQuery::getDocument($documentID);
// TODO check add($pq->document)
$pq->find('*')->add($pq->document)->trigger($type, $data);
}
} else {
if (isset($data[0]) && $data[0] instanceof DOMEvent) {
$event = $data[0];
$event->relatedTarget = $event->target;
$event->target = $node;
$data = array_slice($data, 1);
} else {
$event = new DOMEvent(array('type' => $type, 'target' => $node, 'timeStamp' => time()));
}
$i = 0;
while ($node) {
// TODO whois
phpQuery::debug("Triggering " . ($i ? "bubbled " : '') . "event '{$type}' on " . "node \n");
//.phpQueryObject::whois($node)."\n");
$event->currentTarget = $node;
$eventNode = self::getNode($documentID, $node);
if (isset($eventNode->eventHandlers)) {
foreach ($eventNode->eventHandlers as $eventType => $handlers) {
$eventNamespace = null;
if (strpos($type, '.') !== false) {
list($eventName, $eventNamespace) = explode('.', $eventType);
} else {
$eventName = $eventType;
}
if ($name != $eventName) {
continue;
}
if ($namespace && $eventNamespace && $namespace != $eventNamespace) {
continue;
}
foreach ($handlers as $handler) {
phpQuery::debug("Calling event handler\n");
$event->data = $handler['data'] ? $handler['data'] : null;
$params = array_merge(array($event), $data);
$return = phpQuery::callbackRun($handler['callback'], $params);
if ($return === false) {
$event->bubbles = false;
}
}
}
}
// to bubble or not to bubble...
if (!$event->bubbles) {
break;
}
$node = $node->parentNode;
$i++;
}
}
}
示例2: getDocument
/**
* Returns object with stack set to document root.
*
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
*/
public function getDocument()
{
return phpQuery::getDocument($this->getDocumentID());
}
示例3: anno_xml_to_html
/**
* Utility function to convert our XML into HTML
* By default, this doesn't do anything by itself, but it runs the
* 'anno_xml_to_html' action to allow various actions to change
* small specific portions of the XML
*
* @see anno_xml_to_html_replace_bold() for simple example on usage
*
* @param string $xml_content
* @return void
*/
function anno_xml_to_html($xml_content)
{
// Most translation is done by xslt - disabled broadly for now. Some tweaking
// will likely be done here later.
//
// Unable to do this with phpQuery, break tag doesn't register as self closing element
$xml_content = str_replace('<break />', '<br />', $xml_content);
// Load our phpQuery document up, so filters should be able to use the pq() function to access its elements
phpQuery::newDocument($xml_content);
// Let our various actions alter the document into HTML
do_action('anno_xml_to_html', $xml_content);
// Return the newly formed HTML
return phpQuery::getDocument()->__toString();
}
示例4: getTextExcerpt
private function getTextExcerpt($commentid)
{
static $Text = null;
if ($Text === null) {
$res = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('Content', 'tx_webetatext_text', 'pid=' . intval($this->id));
$Text = trim(preg_replace('~\\s+~', ' ', $res['Content']));
$Text = preg_replace('~<!--.*-->~U', '', $Text);
}
phpQuery::newDocument($Text, 'text/html');
foreach (pq('span.savedComment') as $comment) {
if (!pq($comment)->hasClass('comment-' . $commentid)) {
pq($comment)->replaceWith(pq($comment)->contents());
}
}
$rawResult = phpQuery::getDocument();
// jetzt noch Text in den Abschnitt vor und nach der Markierung splitten
if (preg_match('~(.*)<span[^>]*class="savedComment [^>]+>(.*)</span>(.*)~sm', $rawResult, $matches)) {
$matches = array_map('strip_tags', $matches);
$strip_length = max(50, (300 - mb_strlen($matches[2])) / 2);
$ret = array('before' => $this->truncate($matches[1], $strip_length, 'end'), 'comment' => $matches[2], 'after' => $this->truncate($matches[3], $strip_length, 'beginning'));
return $ret;
} else {
return false;
}
}
示例5: anno_xml_to_html
/**
* Utility function to convert our XML into HTML
* By default, this doesn't do anything by itself, but it runs the
* 'anno_xml_to_html' action to allow various actions to change
* small specific portions of the XML
*
* @see anno_xml_to_html_replace_bold() for simple example on usage
*
* @param string $xml_content
* @return void
*/
function anno_xml_to_html($xml_content)
{
// Unable to do this with phpQuery, break tag doesn't register as self closing element
$xml_content = str_replace('<break />', '<br />', $xml_content);
// Load our phpQuery document up, so filters should be able to use the pq() function to access its elements
phpQuery::newDocument($xml_content);
// Let our various actions alter the document into HTML
do_action('anno_xml_to_html', $xml_content);
// Return the newly formed HTML
return phpQuery::getDocument()->__toString();
}
示例6: pq
$li = null;
// almost everything can be a chain
$doc['ul > li']->addClass('my-new-class')->filter(':last')->addClass('last-li')->toReference($li);
// SELECT DOCUMENT
// pq(); is using selected document as default
phpQuery::selectDocument($doc);
// documents are selected when created or by above method
// query all unordered lists in last selected document
$ul = pq('ul')->insertAfter('div');
// ITERATE IT
// all direct LIs from $ul
foreach ($ul['> li'] as $li) {
// iteration returns PLAIN dom nodes, NOT phpQuery objects
$tagName = $li->tagName;
$childNodes = $li->childNodes;
// so you NEED to wrap it within phpQuery, using pq();
pq($li)->addClass('my-second-new-class');
}
// PRINT OUTPUT
// 1st way
print phpQuery::getDocument($doc->getDocumentID());
// 2nd way
print phpQuery::getDocument(pq('div')->getDocumentID());
// 3rd way
print pq('div')->getDocument();
// 4th way
print $doc->htmlOuter();
// 5th way
print $doc;
// another...
print $doc['ul'];
示例7: 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;
}
//.........这里部分代码省略.........
示例8: array
$response = array('id' => (int) $pdo->lastInsertId());
echo json_encode($response);
});
$app->get("/show/variation/:variation_id", function ($variationId) use($pdo) {
// Load Variation Content;
$statement = $pdo->prepare("\n SELECT st.ElementID, v.Content\n FROM variation AS v\n INNER JOIN splittest AS st ON v.SplitTest_ID = st.ID\n WHERE v.ID = :id\n ");
$statement->bindParam(":id", $variationId, \PDO::PARAM_INT);
$statement->execute();
$result = $statement->fetch();
if (!$result) {
throw new \Exception("Variation '" . $variationId . "' not found.");
}
$doc = phpQuery::newDocumentFileHTML(__DIR__ . "/templates/coolblue-static.html");
$element = pq($result["ElementID"]);
$element->html($result["Content"]);
echo phpQuery::getDocument($doc->getDocumentID());
});
$app->get("/splittest", function () use($app, $twig, $pdo) {
$app->request->get("");
});
$app->get("/external/:url", function ($url) {
$style = '<link rel="stylesheet" href="/templates/lib/splittester/splittester.css" type="text/css"/>';
$js = '<script src="/templates/lib/jquery-modal/jquery.modal.min.js"></script>';
$js .= '<script src="/templates/lib/splittester/splittester.js"></script>';
$client = new GuzzleHttp\Client([]);
$response = $client->request('GET', $url);
$contentBody = $response->getBody();
$contentBody = preg_replace("/<head(.*?)>/", "<head\$1>{$style}", $contentBody);
$contentBody = preg_replace("/<\\/html>/", "{$js}</html>", $contentBody);
print $contentBody;
});
示例9: pq
<?php
require 'phpQuery/phpQuery.php';
phpQuery::newDocument('<div>mydiv<ul><li>1</li><li>2</li><li>3</li></ul></div>')->find('ul >li')->addClass('my-new-class')->filter(':last')->addClass('last-li');
pq('ul')->insertAfter('div');
foreach (pq('li') as $li) {
$li->addClass('my-second-new-class');
}
print phpQuery::getDocument();
示例10: html
function html()
{
pq("title")->html($this->meta['title']);
/*
<meta name="author" content="Anna Lyse">
*/
foreach ($this->meta as $k => $v) {
pq("head")->append(pq("<meta />")->attr("name", $k)->attr("content", $v));
}
/*
<link rel="stylesheet" href="css/md-style.css" type="text/css" media="screen,print" title="no title" charset="utf-8">
*/
if ($this->doc_meta['css']) {
$css_links = explode(' ', $this->doc_meta['css']);
foreach ($css_links as $css) {
list($css, $media) = explode(';', $css, 2);
pq("head")->append(pq("<link />")->attr("href", $css)->attr('rel', 'stylesheet'));
}
}
$this->assets_rewrite();
return phpQuery::getDocument($this->docID);
}