本文整理汇总了PHP中DomDocument::createProcessingInstruction方法的典型用法代码示例。如果您正苦于以下问题:PHP DomDocument::createProcessingInstruction方法的具体用法?PHP DomDocument::createProcessingInstruction怎么用?PHP DomDocument::createProcessingInstruction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomDocument
的用法示例。
在下文中一共展示了DomDocument::createProcessingInstruction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getString
/**
* @return string
*/
public function getString()
{
// ensure the xml has the required xpacket processing instructions
$result = $this->xpath->query('/processing-instruction(\'xpacket\')');
$hasBegin = $hasEnd = false;
/** @var $item \DOMProcessingInstruction */
foreach ($result as $item) {
// do a quick check if the processing instruction contains 'begin' or 'end'
if (false !== stripos($item->nodeValue, 'begin')) {
$hasBegin = true;
} elseif (false !== stripos($item->nodeValue, 'end')) {
$hasEnd = true;
}
}
if (!$hasBegin) {
$this->dom->insertBefore($this->dom->createProcessingInstruction('xpacket', "begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\""), $this->dom->documentElement);
}
if (!$hasEnd) {
$this->dom->appendChild($this->dom->createProcessingInstruction('xpacket', 'end="w"'));
// append to end
}
// ensure all rdf:Description elements have an rdf:about attribute
$descriptions = $this->xpath->query('//rdf:Description');
for ($i = 0; $i < $descriptions->length; $i++) {
/** @var \DOMElement $desc */
$desc = $descriptions->item($i);
$desc->setAttributeNS(self::RDF_NS, 'rdf:about', $this->about);
}
return $this->dom->saveXML();
}
示例2: DomDocument
function _createDOM($action = "view")
{
$dom = new DomDocument('1.0', 'UTF-8');
if ($this->theme) {
if (!$this->theme->hasAction($action)) {
$this->err[] = "Whoops! Your current theme does not support the selected action!";
$action = "view";
}
$xslt = $this->theme->xslFor($action);
$xslt = $dom->createProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"{$xslt}\"");
$dom->appendChild($xslt);
}
$root = $dom->createElementNS(SGlossWiki::$NS, 'sgloss');
$dom->appendChild($root);
$title = $dom->createElementNS(SGlossWiki::$NS, 'title');
$title->appendChild($dom->createTextNode($this->title));
$root->appendChild($title);
foreach ($this->err as $msg) {
$e = $dom->createElementNS(SGlossWiki::$NS, 'error');
$e->appendChild($dom->createTextNode($msg));
$root->appendChild($e);
}
foreach ($this->msg as $msg) {
$e = $dom->createElementNS(SGlossWiki::$NS, 'message');
$e->appendChild($dom->createTextNode($msg));
$root->appendChild($e);
}
foreach ($this->warn as $msg) {
$e = $dom->createElementNS(SGlossWiki::$NS, 'warning');
$e->appendChild($dom->createTextNode($msg));
$root->appendChild($e);
}
if (FALSE && $this->debug) {
$node = $dom->createElementNS(SGlossWiki::$NS, 'debug');
$node->appendChild($dom->createTextNode(print_r($this->debug, 1)));
$root->appendChild($node);
}
return $dom;
}
示例3: foreach
function gglstmp_sitemapcreate()
{
global $wpdb, $gglstmp_settings;
$str_post_type = "";
foreach ($gglstmp_settings['post_type'] as $val) {
if ($str_post_type != "") {
$str_post_type .= ", ";
}
$str_post_type .= "'" . $val . "'";
}
$taxonomies = array();
foreach ($gglstmp_settings['taxonomy'] as $val) {
$taxonomies[] = $val;
}
$xml = new DomDocument('1.0', 'utf-8');
$xml_stylesheet_path = defined('WP_CONTENT_DIR') ? home_url('/') . basename(WP_CONTENT_DIR) : home_url('/') . 'wp-content';
$xml_stylesheet_path .= defined('WP_PLUGIN_DIR') ? '/' . basename(WP_PLUGIN_DIR) . '/google-sitemap-plugin/sitemap.xsl' : '/plugins/google-sitemap-plugin/sitemap.xsl';
$xslt = $xml->createProcessingInstruction('xml-stylesheet', "type=\"text/xsl\" href=\"{$xml_stylesheet_path}\"");
$xml->appendChild($xslt);
$gglstmppr_urlset = $xml->appendChild($xml->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset'));
if (!empty($str_post_type)) {
$loc = $wpdb->get_results("SELECT `ID`, `post_modified` FROM {$wpdb->posts} WHERE `post_status` = 'publish' AND `post_type` IN (" . $str_post_type . ")");
if (!empty($loc)) {
foreach ($loc as $val) {
$gglstmppr_url = $gglstmppr_urlset->appendChild($xml->createElement('url'));
$loc = $gglstmppr_url->appendChild($xml->createElement('loc'));
$permalink = get_permalink($val->ID);
$loc->appendChild($xml->createTextNode($permalink));
$lastmod = $gglstmppr_url->appendChild($xml->createElement('lastmod'));
$now = $val->post_modified;
$date = date('Y-m-d\\TH:i:sP', strtotime($now));
$lastmod->appendChild($xml->createTextNode($date));
$changefreq = $gglstmppr_url->appendChild($xml->createElement('changefreq'));
$changefreq->appendChild($xml->createTextNode('monthly'));
$priority = $gglstmppr_url->appendChild($xml->createElement('priority'));
$priority->appendChild($xml->createTextNode(1.0));
}
}
}
if (!empty($taxonomies)) {
foreach ($taxonomies as $value) {
$terms = get_terms($value, 'hide_empty=1');
if (!empty($terms) && !is_wp_error($terms)) {
foreach ($terms as $term_value) {
$gglstmppr_url = $gglstmppr_urlset->appendChild($xml->createElement('url'));
$loc = $gglstmppr_url->appendChild($xml->createElement('loc'));
$permalink = get_term_link((int) $term_value->term_id, $value);
$loc->appendChild($xml->createTextNode($permalink));
$lastmod = $gglstmppr_url->appendChild($xml->createElement('lastmod'));
$now = $wpdb->get_var("SELECT `post_modified` FROM {$wpdb->posts}, {$wpdb->term_relationships} WHERE `post_status` = 'publish' AND `term_taxonomy_id` = " . $term_value->term_taxonomy_id . " AND {$wpdb->posts}.ID= {$wpdb->term_relationships}.object_id ORDER BY `post_modified` DESC");
$date = date('Y-m-d\\TH:i:sP', strtotime($now));
$lastmod->appendChild($xml->createTextNode($date));
$changefreq = $gglstmppr_url->appendChild($xml->createElement('changefreq'));
$changefreq->appendChild($xml->createTextNode('monthly'));
$priority = $gglstmppr_url->appendChild($xml->createElement('priority'));
$priority->appendChild($xml->createTextNode(1.0));
}
}
}
}
$xml->formatOutput = true;
if (is_multisite()) {
$home_url = preg_replace("/[^a-zA-ZА-Яа-я0-9\\s]/", "_", str_replace('http://', '', str_replace('https://', '', home_url())));
$xml->save(ABSPATH . 'sitemap_' . $home_url . '.xml');
} else {
$xml->save(ABSPATH . 'sitemap.xml');
}
gglstmp_sitemap_info();
}
示例4: foreach
function gglstmp_sitemapcreate()
{
global $wpdb;
if (isset($_POST['gglstmp_settings'])) {
$gglstmp_settings = $_POST['gglstmp_settings'];
} else {
global $gglstmp_settings;
}
$str = "";
foreach ($gglstmp_settings as $val) {
if ($str != "") {
$str .= ", ";
}
$str .= "'" . $val . "'";
}
$xml = new DomDocument('1.0', 'utf-8');
$xml_stylesheet_path = plugins_url() . "/google-sitemap-plugin/sitemap.xsl";
$xslt = $xml->createProcessingInstruction('xml-stylesheet', "type=\"text/xsl\" href=\"{$xml_stylesheet_path}\"");
$xml->appendChild($xslt);
$urlset = $xml->appendChild($xml->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset'));
if (!empty($str)) {
$loc = $wpdb->get_results("SELECT ID, post_modified, post_status, post_type, ping_status FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_type IN (" . $str . ")");
foreach ($loc as $val) {
$url = $urlset->appendChild($xml->createElement('url'));
$loc = $url->appendChild($xml->createElement('loc'));
$permalink = get_permalink($val->ID);
$loc->appendChild($xml->createTextNode($permalink));
$lastmod = $url->appendChild($xml->createElement('lastmod'));
$now = $val->post_modified;
$date = date('Y-m-d\\TH:i:sP', strtotime($now));
$lastmod->appendChild($xml->createTextNode($date));
$changefreq = $url->appendChild($xml->createElement('changefreq'));
$changefreq->appendChild($xml->createTextNode('monthly'));
$priority = $url->appendChild($xml->createElement('priority'));
$priority->appendChild($xml->createTextNode(1.0));
}
$xml->formatOutput = true;
}
if (is_multisite()) {
$home_url = preg_replace("/[^a-zA-ZА-Яа-я0-9\\s]/", "_", str_replace('http://', '', str_replace('https://', '', home_url())));
$xml->save(ABSPATH . 'sitemap_' . $home_url . '.xml');
} else {
$xml->save(ABSPATH . 'sitemap.xml');
}
}