本文整理汇总了PHP中DOMDocument::createComment方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMDocument::createComment方法的具体用法?PHP DOMDocument::createComment怎么用?PHP DOMDocument::createComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::createComment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
/**
* @throws BuildException
*/
public function main()
{
if (!$this->getDatabaseName()) {
throw new BuildException("The databaseName attribute (defined in propel.project property) is required for schema reverse engineering", $this->getLocation());
}
//(not yet supported) $this->log("schema : " . $this->dbSchema);
//DocumentTypeImpl docType = new DocumentTypeImpl(null, "database", null,
// "http://jakarta.apache.org/turbine/dtd/database.dtd");
$this->doc = new DOMDocument('1.0', 'utf-8');
$this->doc->formatOutput = true;
// pretty printing
$this->doc->appendChild($this->doc->createComment("Autogenerated by " . get_class($this) . " class."));
try {
$database = $this->buildModel();
if ($this->validatorBits !== self::VALIDATORS_NONE) {
$this->addValidators($database);
}
$database->appendXml($this->doc);
$this->log("Writing XML to file: " . $this->xmlSchema->getPath());
$out = new FileWriter($this->xmlSchema);
$xmlstr = $this->doc->saveXML();
$out->write($xmlstr);
$out->close();
} catch (Exception $e) {
$this->log("There was an error building XML from metadata: " . $e->getMessage(), Project::MSG_ERR);
return false;
}
$this->log("Schema reverse engineering finished");
}
示例2: appendFormatComment
/**
* Add document comment for formatting
*
* @param string $element
* @param string $comment
*/
protected function appendFormatComment(string $element, string $comment)
{
if ($this->format_output) {
$com = $this->docObj->createComment($comment);
$this->{$element}->appendChild($com);
}
}
示例3: convert
public function convert($mailchimp)
{
$vars = array('*|MC:SUBJECT|*' => '<?php echo $this->getSubject() ?>', '*|ARCHIVE|*' => '<?php echo $this->getViewInBrowserUrl() ?>', '*|CURRENT_YEAR|*' => '<?php echo date("Y") ?>', '*|UNSUB|*' => '<?php echo $this->getUnsubscribeUrl() ?>', '*|FACEBOOK:PROFILEURL|*' => '<?php echo $this->getFacebookUrl() ?>', '*|TWITTER:PROFILEURL|*' => '<?php echo $this->getTwitterUrl() ?>', '*|LIST:COMPANY|*' => '<?php echo $this->getStoreName() ?>', '*|LIST:DESCRIPTION|*' => '', '*|HTML:LIST_ADDRESS_HTML|*' => 'outgoiing@email.address', '*|IF:REWARDS|* *|HTML:REWARDS|*' => '', '*|FORWARD|*' => '', '/*@editable*/' => '', '*|UPDATE_PROFILE|*' => '', 'mc:repeatable' => '', 'mc:allowtext' => '', 'mc:hideable' => '', 'mc:allowdesigner' => '', '*|IFNOT:ARCHIVE_PAGE|*' => '', '*|END:IF|*' => '', 'mc:edit' => 'mcedit');
foreach ($vars as $old => $new) {
$mailchimp = str_replace($old, $new, $mailchimp);
}
$dom = new DOMDocument();
$dom->recover = true;
$dom->strictErrorChecking = false;
@$dom->loadHTML($mailchimp);
$xpath = new DomXpath($dom);
$items = $xpath->query('//*[@mcedit]');
foreach ($items as $mcedit) {
$area = 'area.' . $mcedit->getAttribute('mcedit');
if ($area == 'area.monkeyrewards') {
$mcedit->parentNode->removeChild($mcedit);
continue;
}
$mcedit->removeAttribute('mcedit');
$a = $dom->createComment('<?php echo $this->area("' . $area . '"); ?>');
// $b = $dom->createComment('{{/ivar}}');
$mcedit->parentNode->insertBefore($a, $mcedit);
// $mcedit->parentNode->insertBefore($b);
}
$dom->formatOutput = true;
$dom->preserveWhitespace = false;
$html = $dom->saveHTML();
$html = str_replace('%7B', '{', $html);
$html = str_replace('%7D', '}', $html);
$html = str_replace('%20', ' ', $html);
$html = preg_replace('/mc:label="[a-zA-Z0-9_]*"/', '', $html);
$html = preg_replace('/mc:variant="[^"]*"/', '', $html);
$html = str_replace('%24', '$', $html);
return $html;
}
示例4: render
/**
* @see Renderable::render()
*/
public function render(\DOMDocument $domDocument)
{
$domElement = $domDocument->createElement("script");
if ($this->text) {
$scriptComment = $domDocument->createComment($this->text);
$domElement->appendChild($scriptComment);
}
return $domElement;
}
示例5: do_header_comments
/**
* Append header comments to the DOM document
*/
protected function do_header_comments()
{
/* Array of translated comment lines */
$lines = array(__('This is a code snippets export file generated by the Code Snippets WordPress plugin.', 'code-snippets'), 'https://wordpress.org/plugins/code-snippets', __('To import these snippets a WordPress site follow these steps:', 'code-snippets'), __('1. Log in to that site as an administrator.', 'code-snippets'), __('2. Install the Code Snippets plugin using the directions provided at the above link.', 'code-snippets'), __("3. Go to 'Tools: Import' in the WordPress admin panel.", 'code-snippets'), __('4. Click on the "Code Snippets" importer in the list', 'code-snippets'), __('5. Upload this file using the form provided on that page.', 'code-snippets'), __('6. Code Snippets will then import all of the snippets and associated information contained in this file into your site.', 'code-snippets'), __("7. You will then have to visit the 'Snippets: Manage' admin menu and activate desired snippets.", 'code-snippets'));
/* Add each line as a comment element */
foreach ($lines as $line) {
$comment = $this->dom->createComment(" {$line} ");
$this->dom->appendChild($comment);
}
/* Build a generator line, like the WordPress export files */
$gen = sprintf('generator="Code Snippets/%s" created="%s"', CODE_SNIPPETS_VERSION, date('Y-m-d H:i'));
/* Run the generator line through the standard WordPress filter */
$type = 'code_snippets_export';
$gen = apply_filters("get_the_generator_{$type}", $gen, $type);
/* Add it to the file as a comment */
$gen = $this->dom->createComment(" {$gen} ");
$this->dom->appendChild($gen);
}
示例6: add_comment
/**
* Add comment
*
* @param string $data
*/
public function add_comment($data)
{
$n = $this->node ? new self($this->owner) : $this;
$e = $this->doc->createComment($data);
if (!$this->node) {
$n->node = $this->node = $this->doc->appendChild($e);
} else {
$n->node = $this->node->appendChild($e);
}
unset($e);
return $n;
}
示例7: appendAssets
/**
* Append assets
*
* @param array $assets
* @return void
*/
public function appendAssets(array $assets)
{
if (!empty($assets)) {
if ($this->format_output) {
$com = $this->docObj->createComment('');
$this->scene->appendChild($com);
}
foreach ($assets as $asset) {
$this->appendAsset($asset);
}
$this->scene->appendChild($this->assets);
}
}
示例8: on_create
protected function on_create(DOMDocument &$doc, $rootmanifestnode = null, $nmanifestID = null)
{
$doc->formatOutput = true;
$doc->preserveWhiteSpace = true;
$this->manifestID = is_null($nmanifestID) ? cc_helpers::uuidgen('M_') : $nmanifestID;
$mUUID = $doc->createAttribute('identifier');
$mUUID->nodeValue = $this->manifestID;
if (is_null($rootmanifestnode)) {
if (!empty($this->_generator)) {
$comment = $doc->createComment($this->_generator);
$doc->appendChild($comment);
}
$rootel = $doc->createElementNS($this->ccnamespaces['imscc'], 'manifest');
$rootel->appendChild($mUUID);
$doc->appendChild($rootel);
//add all namespaces
foreach ($this->ccnamespaces as $key => $value) {
if ($key != 'lom') {
$dummy_attr = $key . ":dummy";
$doc->createAttributeNS($value, $dummy_attr);
}
}
// add location of schemas
$schemaLocation = '';
foreach ($this->ccnsnames as $key => $value) {
$vt = empty($schemaLocation) ? '' : ' ';
$schemaLocation .= $vt . $this->ccnamespaces[$key] . ' ' . $value;
}
$aSchemaLoc = $doc->createAttributeNS($this->ccnamespaces['xsi'], 'xsi:schemaLocation');
$aSchemaLoc->nodeValue = $schemaLocation;
$rootel->appendChild($aSchemaLoc);
} else {
$rootel = $doc->createElementNS($this->ccnamespaces['imscc'], 'imscc:manifest');
$rootel->appendChild($mUUID);
}
$metadata = $doc->createElementNS($this->ccnamespaces['imscc'], 'metadata');
$schema = $doc->createElementNS($this->ccnamespaces['imscc'], 'schema', 'IMS Common Cartridge');
$schemaversion = $doc->createElementNS($this->ccnamespaces['imscc'], 'schemaversion', $this->ccversion);
$metadata->appendChild($schema);
$metadata->appendChild($schemaversion);
$rootel->appendChild($metadata);
if (!is_null($rootmanifestnode)) {
$rootmanifestnode->appendChild($rootel);
}
$organizations = $doc->createElementNS($this->ccnamespaces['imscc'], 'organizations');
$rootel->appendChild($organizations);
$resources = $doc->createElementNS($this->ccnamespaces['imscc'], 'resources');
$rootel->appendChild($resources);
return true;
}
示例9: reverse
public function reverse()
{
if (!$this->getDatabaseName()) {
throw new BuildException('The databaseName attribute is required for schema reverse engineering');
}
$this->xml = new \DOMDocument('1.0', 'utf-8');
$this->xml->formatOutput = true;
// pretty printing
$this->xml->appendChild($this->xml->createComment("Autogenerated by " . get_class($this) . " class."));
try {
$database = $this->buildModel();
$database->appendXml($this->xml);
$file = $this->getWorkingDirectory() . DIRECTORY_SEPARATOR . $this->getSchemaName() . '.xml';
$this->log("Writing XML file to " . $file);
file_put_contents($file, $this->xml->saveXML());
} catch (\Exception $e) {
$this->log(sprintf('<error>There was an error building XML from metadata: %s</error>', $e->getMessage()));
return false;
}
return true;
}
示例10: exportHelper
}
/**
* exportHelper object to help us in the exporting process...
*/
$exportHelper = new exportHelper($exportCourse);
/**
* comment to be inserted as first line of XML document
*/
$commentStr = "Exported From " . PORTAL_NAME . " v" . ADA_VERSION;
// create a dom document with encoding utf8
$domtree = new DOMDocument('1.0', ADA_CHARSET);
$domtree->preserveWhiteSpace = false;
$domtree->formatOutput = true;
// generate and add comment, if any
if (isset($commentStr)) {
$domtree->appendChild($domtree->createComment($commentStr));
unset($commentStr);
}
// create the root element of the xml tree
$xmlRoot = $domtree->createElement("ada_export");
$xmlRoot->setAttribute("exportDate", date('r'));
// append it to the document created
$xmlRoot = $domtree->appendChild($xmlRoot);
foreach ($nodesToExport as $course_id => $nodeList) {
// need an Import/Export DataHandler
$dh = AMAImpExportDataHandler::instance(MultiPort::getDSN($_SESSION['sess_selected_tester']));
$course_data = $dh->get_course($course_id);
if (!empty($course_data) && !AMA_DB::isError($course_data)) {
// create node for current course
$XMLcourse = $domtree->createElement('modello_corso');
$XMLcourse->setAttribute('exportedId', $course_id);
示例11: exportData
private function exportData($aaExportPageGroups)
{
$oDoc = new DOMDocument("1.0", "UTF-8");
//put information as comment
$sComment = "";
$sComment .= $this->t_("xmlcomment_info") . "\n";
$sComment .= ANWIKI_WEBSITE . "\n\n";
$sComment .= $this->t_("xmlcomment_time", array("time" => Anwi18n::dateTime(time()))) . "\n";
$sComment .= $this->t_("xmlcomment_version", array("version" => ANWIKI_VERSION_NAME)) . "\n";
$sComment .= $this->t_("xmlcomment_user", array("user" => AnwCurrentSession::getUser()->getLogin())) . "\n";
$sComment .= $this->t_("xmlcomment_from", array("url" => self::globalCfgUrlRoot())) . "\n\n";
$sComment .= $this->t_("xmlcomment_contents") . "\n";
//list exported contents as comment
foreach ($aaExportPageGroups as $amPageGroup) {
foreach ($amPageGroup['PAGES'] as $oPage) {
$sPageTime = Anwi18n::dateTime($oPage->getTime());
$sComment .= ' * ' . $oPage->getName() . " (" . $oPage->getLang() . ") (" . $sPageTime . ")\n";
}
}
$sCommentSeparator = "\n**************************************************\n";
$sComment = " " . $sCommentSeparator . $sComment . $sCommentSeparator . " ";
$oCommentNode = $oDoc->createComment($sComment);
$oDoc->appendChild($oCommentNode);
//end comment
//<anwexport time="" origin="">
$oRootNode = $oDoc->createElement(self::XMLTAG_ROOT);
$oRootNode->setAttribute("time", time());
$oRootNode->setAttribute("from", AnwXml::xmlFileAttributeEncode(self::globalCfgUrlRoot()));
$oRootNode->setAttribute("version_id", ANWIKI_VERSION_ID);
$oRootNode->setAttribute("version_name", AnwXml::xmlFileAttributeEncode(ANWIKI_VERSION_NAME));
$oDoc->appendChild($oRootNode);
foreach ($aaExportPageGroups as $amPageGroup) {
$oPageGroup = $amPageGroup['GROUP'];
$sContentClassName = $oPageGroup->getContentClass()->getName();
//<anwpagegroup>
$oPageGroupNode = $oDoc->createElement(self::XMLTAG_PAGEGROUP);
$oPageGroupNode->setAttribute("contentclass", AnwXml::xmlFileAttributeEncode($sContentClassName));
foreach ($amPageGroup['PAGES'] as $oPage) {
//add comment
$sPageTime = Anwi18n::dateTime($oPage->getTime());
$sComment = $oPage->getName() . " (" . $oPage->getLang() . ") (" . $sPageTime . ") (" . $oPageGroup->getContentClass()->getLabel() . "/" . $sContentClassName . ")";
//$sComment = " \n*\n* ".$sComment."\n*\n ";
$sCommentSeparator = "\n**************************************************\n";
$sComment = " \n\n" . $sCommentSeparator . $sComment . $sCommentSeparator . " ";
$oCommentNode = $oDoc->createComment($sComment);
$oPageGroupNode->appendChild($oCommentNode);
//end comment
//using a CDATA node to preserve source breaklines :-)
//$sPageContent = $oPage->getContent()->toXml();
//$oPageContentNode = $oDoc->createCDATASection($sPageContent);
$oContentNodeDoc = $oPage->getContent()->toXml()->documentElement;
//here we got a <doc> node
$oPageContentNodeDoc = $oDoc->importNode($oContentNodeDoc, true);
//<anwpage name="" lang="" time="">
$oPageNode = $oDoc->createElement(self::XMLTAG_PAGE);
$oPageNode->setAttribute("name", AnwXml::xmlFileAttributeEncode($oPage->getName()));
$oPageNode->setAttribute("lang", AnwXml::xmlFileAttributeEncode($oPage->getLang()));
$oPageNode->setAttribute("time", $oPage->getTime());
//we need to do this to squeeze the unwanted <doc> node in
//WARNING - special loop ! childs are getting modified...
while ($oChildNode = $oPageContentNodeDoc->childNodes->item(0)) {
$oPageNode->appendChild($oChildNode);
}
$oPageGroupNode->appendChild($oPageNode);
}
$oRootNode->appendChild($oPageGroupNode);
}
$sReturn = AnwUtils::xmlDumpNode($oRootNode);
// even if final XML structure may be broken due to undeclared namespaces used in content,
// we let raw content as it is for better compatibility in later versions.
// $sReturn = AnwXml::prepareXmlValueToXml($sReturn);
return $sReturn;
}
示例12: array
)
);
} else {
$indexes[$indexName]['columns'][$indexColumn] = array(
'key' => $indexColumn,
'length' => $indexColumnLength,
'collation' => $indexColumnCollation,
'null' => $indexColumnNull
);
}
}
if (!empty($indexes)) {
$xpdo->log(xPDO::LOG_LEVEL_INFO, "Generating XML for index elements: " . print_r($indexes, true));
$fragment = $schema->createDocumentFragment();
$fragment->appendChild($schema->createTextNode("\n "));
$fragment->appendChild($schema->createComment("Element indexes automatically generated by script: {$scriptTitle}"));
$fragment->appendChild($schema->createTextNode("\n"));
foreach ($indexes as $indexName => $index) {
$indexElement = $schema->createElement('index');
$indexElement->appendChild($schema->createTextNode("\n "));
foreach ($index['attributes'] as $attrKey => $attrVal) {
$indexElement->setAttribute($attrKey, $attrVal);
}
foreach ($index['columns'] as $columnKey => $column) {
$columnElement = $schema->createElement('column');
foreach ($column as $colAttrKey => $colAttrVal) {
$columnElement->setAttribute($colAttrKey, $colAttrVal);
}
$indexElement->appendChild($schema->createTextNode(" "));
$indexElement->appendChild($columnElement);
$indexElement->appendChild($schema->createTextNode("\n "));
示例13: testRecursiveSerialize
public function testRecursiveSerialize()
{
$ns1 = 'tests://test/';
$ns2 = 'tests://test_more/';
$xmlDoc = new DOMDocument('1.0', 'UTF-8');
$root = $xmlDoc->createElementNS($ns1, 'root');
$sub1 = $xmlDoc->createElementNS($ns1, 'sub1');
$sub1_1 = $xmlDoc->createElementNS($ns1, 'sub1_1');
$cdata1_1 = $xmlDoc->createCDATASection('test text');
$sub2 = $xmlDoc->createElementNS($ns2, 'sub2');
$sub2_1 = $xmlDoc->createElementNS($ns1, 'sub2_1');
$comment2_1 = $xmlDoc->createComment('test comment');
$xmlDoc->appendChild($root);
$root->appendChild($sub1);
$sub1->appendChild($sub1_1);
$sub1_1->appendChild($cdata1_1);
$root->appendChild($sub2);
$sub2->appendChild($sub2_1);
$sub2_1->appendChild($comment2_1);
// Because recursiveSerialize is not forced to use ns1 and ns2 as namespace prefixes, this test is a bit awkward. But it works for now, so let's just ignore it :)
$this->assertSame('<ns1:root xmlns:ns1="tests://test/" xmlns:ns2="tests://test_more/"><ns1:sub1><ns1:sub1_1>test text</ns1:sub1_1></ns1:sub1><ns2:sub2><ns1:sub2_1><!--test comment--></ns1:sub2_1></ns2:sub2></ns1:root>', DAV::recursiveSerialize($root), 'DAV::recursiveSerialize() should return correct XML');
}
示例14: saveAction
public function saveAction()
{
if ($data = $this->getRequest()->getPost()) {
$doc = new DOMDocument();
$doc->version = '1.0';
$doc->encoding = 'ISO-8859-1';
$comment_elt = $doc->createComment('Generated by FormatiX.Eu ');
$doc->appendChild($comment_elt);
$note_elt = $doc->createElement('trendy');
$doc->appendChild($note_elt);
$skuids = $this->getRequest()->getParam('sku');
$model = Mage::getModel('catalog/product');
//getting product model
$skuidarr = explode(",", $skuids);
foreach ($skuidarr as $sku) {
$item_elt = $doc->createElement('item');
$doc->appendChild($item_elt);
$productid = $model->getIdBySku($sku);
$product = Mage::getModel('catalog/product')->load($productid);
$product->getData();
$pid = $product->getId();
$productname = $product->getShortDescription();
$price = $product->getPrice();
//$producturl =$product->getProductUrl();
$producturl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . $product->url_path;
$imageurl = $product->getImageUrl();
$sprice = $product->getSpecialPrice();
//$description=$product->getShortDescription();
$productname = str_replace("&", "&", $productname);
// Create to/from/heading/body elements
$id_elt = $doc->createElement('id', $pid);
$name_elt = $doc->createElement('name', $productname);
$price_elt = $doc->createElement('price', $price);
$url_elt = $doc->createElement('producturl', $producturl);
$imageurl_elt = $doc->createElement('image', $imageurl);
$sprice_elt = $doc->createElement('specialprice', $sprice);
$descri_elt = $doc->createElement('description', $productname);
// Specify that thos newly created elements are 'unique and trendy' children
$note_elt->appendChild($item_elt);
$item_elt->appendChild($id_elt);
$item_elt->appendChild($name_elt);
$item_elt->appendChild($price_elt);
$item_elt->appendChild($url_elt);
$item_elt->appendChild($imageurl_elt);
$item_elt->appendChild($sprice_elt);
$item_elt->appendChild($descri_elt);
}
// Beautify
$doc->formatOutput = true;
// Display the XML content we just created
$doc->saveXML();
// Save this to topseller.xml
$doc->save('trendy.xml');
if (isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
try {
/* Starting upload */
$uploader = new Varien_File_Uploader('filename');
// Any extention would work
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(false);
// Set the file upload mode
// false -> get the file directly in the specified folder
// true -> get the file in the product like folders
// (file.jpg will go in something like /media/f/i/file.jpg)
$uploader->setFilesDispersion(false);
// We set media as the upload dir
$path = Mage::getBaseDir('media') . DS;
$uploader->save($path, $_FILES['filename']['name']);
} catch (Exception $e) {
}
//this way the name is saved in DB
$data['filename'] = $_FILES['filename']['name'];
}
$model = Mage::getModel('trendy/trendy');
$model->setData($data)->setId($this->getRequest()->getParam('id'));
try {
if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
$model->setCreatedTime(now())->setUpdateTime(now());
} else {
$model->setUpdateTime(now());
}
$model->save();
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('trendy')->__('Item was successfully saved'));
Mage::getSingleton('adminhtml/session')->setFormData(false);
if ($this->getRequest()->getParam('back')) {
$this->_redirect('*/*/edit', array('id' => $model->getId()));
return;
}
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
Mage::getSingleton('adminhtml/session')->setFormData($data);
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
}
}
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('trendy')->__('Unable to find item to save'));
$this->_redirect('*/*/');
}
示例15: comment
static function comment($comment)
{
end(self::$parentNodes)->appendChild(self::$domDocument->createComment($comment));
}