/** * Parse next commend token. * * @return CommentNode */ protected function parseComment() { $token = $this->expectTokenType('comment'); $node = new CommentNode(preg_replace('/^ +| +$/', '', $token->value), $token->buffer, $this->lexer->getCurrentLine()); // Skip newlines while ('newline' === $this->lexer->predictToken()->type) { $this->lexer->getAdvancedToken(); } if ('indent' === $this->lexer->predictToken()->type) { $node->setBlock($this->parseBlock()); } return $node; }
/** * Answer the files attached to a site component. * * @param object CommentNode $comment * @access protected */ protected function addCommentAttachedMedia(CommentNode $comment) { $mediaAssetType = new Type('segue', 'edu.middlebury', 'media_file', 'A file that is uploaded to Segue.'); $children = $comment->getAsset()->getAssets(); while ($children->hasNext()) { $child = $children->next(); if ($mediaAssetType->isEqual($child->getAssetType())) { try { $this->addMediaAsset($child); } catch (PermissionDeniedException $e) { } catch (OperationFailedException $e) { } } } }
/** * Answer an element that represents a comment. * * @param object CommentNode $comment * @return DOMElement * @access protected * @since 1/17/08 */ protected function getComment(CommentNode $comment) { $element = $this->doc->createElementNS("http://wordpress.org/export/1.1/", 'wp:comment'); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:comment_id', $comment->getId())); $author = $comment->getAuthor(); $authorUID = $this->recordAgent($author->getId()); if ($properties = $author->getPropertiesByType(new HarmoniType("GroupProperties", "edu.middlebury", "CAS Properties"))) { $email = $properties->getProperty('EMail'); } else { if ($properties = $author->getPropertiesByType(new HarmoniType("Authentication", "edu.middlebury.harmoni", "Visitors"))) { $email = $properties->getProperty('email'); } else { $email = ''; } } $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:comment_author', $author->getDisplayName())); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:comment_author_email', $email)); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:comment_user_id', $author->getId())); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:comment_date', $comment->getCreationDate()->format('Y-m-d H:i:s'))); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:comment_date_gmt', $comment->getCreationDate()->asUTC()->format('Y-m-d H:i:s'))); $content = "<h3>" . $comment->getSubject() . "</h3>"; $pluginManager = Services::getService('PluginManager'); $plugin = $pluginManager->getPlugin($comment->getAsset()); $this->recordPluginExtras($comment->getAsset()); $content .= $plugin->executeAndGetMarkup(false, true); $element->appendChild($this->getCDATAElementNS("http://wordpress.org/export/1.1/", 'wp:comment_content', $content)); $parent = $comment->getParentComment(); if ($parent) { $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:comment_parent', $parent->getId())); } else { $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:comment_parent', '0')); } $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:comment_approved', '1')); $element->appendChild($this->getElementNS("http://wordpress.org/export/1.1/", 'wp:comment_type', '')); return $element; }
/** * Creates a commented-out version of this statement. * * @return \Pharborist\CommentNode|\Pharborist\LineCommentBlockNode */ public function toComment() { return CommentNode::create($this->getText()); }
/** * Apply data to a comment * * @param object CommentNode $comment * @param object DOMElement $element * @return void * @access protected * @since 1/24/08 */ protected function applyCommentData(CommentNode $comment, DOMElement $element) { $element->setAttribute('new_id', $comment->getId()->getIdString()); $comment->updateSubject($this->getStringValue($this->getSingleChild('subject', $element))); $this->applyPluginContent($comment->getAsset(), $element); $this->applyMedia($comment->getAsset(), $element); $this->setAssetAuthorship($comment->getAsset(), $element); $this->setAssetDates($comment->getAsset(), $element); if (isset($this->status)) { $this->status->updateStatistics(); } // Replies $commentMgr = CommentManager::instance(); $replyElements = $this->xpath->query('./replies/Comment', $element); foreach ($replyElements as $replyElement) { $reply = $commentMgr->createReply($comment->getId(), new Type($this->getSingleNode("./type/domain/text()", $replyElement)->nodeValue, $this->getSingleNode("./type/authority/text()", $replyElement)->nodeValue, $this->getSingleNode("./type/keyword/text()", $replyElement)->nodeValue)); $this->applyCommentData($reply, $replyElement); } }