/** * Tells the wizard component to update itself - this may include getting * form post data or validation - whatever this particular component wants to * do every pageload. * @param string $fieldName The field name to use when outputting form data or * similar parameters/information. * @access public * @return boolean - TRUE if everything is OK */ function update($fieldName) { $val = RequestContext::value($fieldName); if ($val !== null && (!$this->_startingDisplay || $val != $this->_startingDisplay)) { $string = HtmlString::fromString($val); $string->cleanXSS(); $this->_value = $string->asString(); if (trim($this->_value) != trim($val)) { $this->_origErrorText = $this->getErrorText(); $this->setErrorText(dgettext('polyphony', "The value you entered has been reformatted to meet XHTML validity standards.")); // Add both error text if validation failed as well. if (!$this->validate()) { $this->setErrorText($this->getErrorText() . " " . $this->_origErrorText); } $this->_showError = true; // Add a dummy rule if needed. if (!$this->getErrorRule()) { $this->setErrorRule(new WECRegex('.*')); } } else { // Reset the original error text. if (isset($this->_origErrorText)) { $this->setErrorText($this->_origErrorText); } } } return $this->validate(); }
/** * Return the heading text for this action, or an empty string. * * @return string * @access public * @since 4/26/05 */ function getHeadingText() { $repository = $this->getRepository(); $description = HtmlString::fromString($repository->getDescription()); $description->clean(); return $repository->getDisplayName() . "<div style='font-size: small; margin-left: 25px;'>" . $description->asString() . "</div> "; }
/** * Required: Set the description * * @param string $description * @return void * @access public * @since 8/7/06 */ function setDescription($description) { ArgumentValidator::validate($description, StringValidatorRule::getRule()); $this->_description = HtmlString::fromString(str_replace(" ", " ", $description)); $this->_description->makeUtf8(); $this->_description->clean(); }
/** * Load feed data, convert and clean it, and return its string value. * * @param string $url * @return string RSS xml * @access protected * @since 7/8/08 */ protected function loadFeedXml($url) { $feedData = @file_get_contents($url); if (!strlen($feedData)) { throw new OperationFailedException("Could not access feed, '" . $url . "'."); } $feed = new DOMDocument(); // If the encoding is not UTF-8, convert the document if (preg_match('/^<\\?xml .*encoding=[\'"]([a-zA-Z0-9-]+)[\'"].*\\?>/m', $feedData, $matches)) { $encoding = $matches[1]; if (strtoupper($encoding) != 'UTF8' && strtoupper($encoding) != 'UTF-8') { $feedData = mb_convert_encoding($feedData, 'UTF-8', strtoupper($encoding)); $feedData = preg_replace('/^(<\\?xml .*encoding=[\'"])([a-zA-Z0-9-]+)([\'"].*\\?>)/m', '\\1UTF-8\\3', $feedData); } } // Convert any non-UTF-8 characters $string = String::withValue($feedData); $string->makeUtf8(); $feedData = $string->asString(); if (!@$feed->loadXML($feedData)) { throw new OperationFailedException("Invalid feed data: \"" . $feedData . "\" for URL: " . $url); } // Handle any format conversions $feed = $this->convertToRss($feed); // Validate Feed. // $tmpFeed = $feed; // $feed = new Harmoni_DOMDocument; // $feed->loadXML($tmpFeed->saveXML()); // unset($tmpFeed); // $feed->schemaValidateWithException(dirname(__FILE__).'/rss-2_0-lax.xsd'); // Run through the titles, authors, and descriptions and clean out any unsafe HTML foreach ($feed->getElementsByTagName('title') as $element) { $element->nodeValue = strip_tags(htmlspecialchars_decode($element->nodeValue)); } foreach ($feed->getElementsByTagName('author') as $element) { $element->nodeValue = strip_tags(htmlspecialchars_decode($element->nodeValue)); } foreach ($feed->getElementsByTagName('comments') as $element) { $element->nodeValue = htmlentities(strip_tags(html_entity_decode($element->nodeValue))); } foreach ($feed->getElementsByTagName('link') as $element) { $element->nodeValue = htmlentities(strip_tags(html_entity_decode($element->nodeValue))); } foreach ($feed->getElementsByTagName('description') as $description) { $html = HtmlString::fromString(htmlspecialchars_decode($description->nodeValue)); $html->cleanXSS(); $description->nodeValue = htmlspecialchars($html->asString()); } // Move the feed into a dom document. $tmpFeed = $feed; $feed = new Harmoni_DOMDocument(); $feed->loadXML($tmpFeed->saveXML()); unset($tmpFeed); // Validate the feed again // $feed->schemaValidateWithException(dirname(__FILE__).'/rss-2_0-lax.xsd'); // Just ensure a few basic things: if (!$feed->documentElement->nodeName == 'rss') { throw new DOMDocumentException("Feed root must be an rss element"); } // Check for channels foreach ($feed->documentElement->childNodes as $element) { if ($element->nodeType == 1 && $element->nodeName != 'channel') { throw new DOMDocumentException("'" . $node->nodeName . "' is not expected, expecting 'channel'."); } } // Check dates foreach ($feed->getElementsByTagName('pubdate') as $element) { if (!preg_match('/(((Mon)|(Tue)|(Wed)|(Thu)|(Fri)|(Sat)|(Sun)), *)?\\d\\d? +((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec)) +\\d\\d(\\d\\d)? +\\d\\d:\\d\\d(:\\d\\d)? +(([+\\-]?\\d\\d\\d\\d)|(UT)|(GMT)|(EST)|(EDT)|(CST)|(CDT)|(MST)|(MDT)|(PST)|(PDT)|\\w)/', $element->nodeValue)) { throw new DOMDocumentException("'" . $element->nodeValue . "' is not a valid date."); } } return $feed->saveXMLWithWhitespace(); }
/** * Answer a valid XHTML with any tag or special-character errors fixed. * * @param string $htmlString * @return string * @access public * @since 1/26/06 */ public final function cleanHTML($htmlString) { $htmlStringObj = HtmlString::fromString($htmlString); // SafeHTML looks for the first colon to determine if something is a // a protocal. $htmlStringObj->addSafeProtocal('[[fileurl'); $htmlStringObj->addSafeProtocal('[[localurl'); $htmlStringObj->cleanXSS(); $htmlStringObj->makeUtf8(); return $htmlStringObj->asString(); }
/** * Print out a log entry * * @param object Entry $entry * @return void * @access public * @since 8/7/06 */ function addEntry($entry) { $rssItem = $this->addItem(new RSSItem()); $harmoni = Harmoni::instance(); $agentManager = Services::getService("Agent"); $hierarchyManager = Services::getService("Hierarchy"); $timestamp = $entry->getTimestamp(); $timestamp = $timestamp->asTimestamp(); $item = $entry->getItem(); $desc = HtmlString::fromString($item->getDescription()); // a title $rssItem->setTitle($desc->stripTagsAndTrim(5)); // Date of occurance $rssItem->setPubDate($timestamp); // A unique id... $rssItem->setGUID(md5($timestamp->asUnixTimeStamp() . $item->getDescription() . $item->getBacktrace()), false); // Category $rssItem->addCategory($item->getCategory()); // Agent / 'author' $agentList = ''; $agentIds = $item->getAgentIds(true); while ($agentIds->hasNext()) { $agentId = $agentIds->next(); if ($agentManager->isAgent($agentId) || $agentManager->isGroup($agentId)) { $agent = $agentManager->getAgent($agentId); $agentList .= $agent->getDisplayName(); } else { $agentList .= _("Id: ") . $agentId->getIdString(); } if ($agentIds->hasNext()) { $agentList .= ", "; } } $rssItem->setAuthor($agentList); // Agents with links ob_start(); $agentIds = $item->getAgentIds(true); $authorList = ''; while ($agentIds->hasNext()) { $agentId = $agentIds->next(); if ($agentManager->isAgent($agentId) || $agentManager->isGroup($agentId)) { $agent = $agentManager->getAgent($agentId); print "<a href='"; print $harmoni->request->quickURL("logs", "browse", array("agent_id" => $agentId->getIdString())); print "'>"; print $agent->getDisplayName(); print "</a>"; $authorList .= $agent->getDisplayName(); } else { print _("Id: ") . $agentId->getIdString(); $authorList .= _("Id: ") . $agentId->getIdString(); } if ($agentIds->hasNext()) { print ", <br/>"; $authorList .= ", "; } } $agentList = ob_get_clean(); // Nodes ob_start(); $nodeIds = $item->getNodeIds(true); while ($nodeIds->hasNext()) { $nodeId = $nodeIds->next(); print "<a href='"; print $harmoni->request->quickURL("logs", "browse", array("node_id" => $nodeId->getIdString())); print "'>"; if ($hierarchyManager->nodeExists($nodeId)) { $node = $hierarchyManager->getNode($nodeId); if ($node->getDisplayName()) { print $node->getDisplayName(); } else { print _("Id: ") . $nodeId->getIdString(); } } else { print _("Id: ") . $nodeId->getIdString(); } print "</a>"; if ($nodeIds->hasNext()) { print ", <br/>"; } } $nodeList = ob_get_clean(); // Description text ob_start(); print "\n\t\t\t\t<dl>"; print "\n\t\t\t\t\t<dt style='font-weight: bold;'>" . _("Date: ") . "</dt>"; print "\n\t\t\t\t\t<dd style='margin-bottom: 20px;'>"; print $timestamp->monthName() . " "; print $timestamp->dayOfMonth() . ", "; print $timestamp->year() . " "; print $timestamp->hmsString(); print "</dd>"; print "\n\t\t\t\t\t<dt style='font-weight: bold;'>" . _("Category: ") . "</dt>"; print "\n\t\t\t\t\t<dd style='margin-bottom: 20px;'>" . $item->getCategory() . "</dd>"; print "\n\t\t\t\t\t<dt style='font-weight: bold;'>" . _("Description: ") . "</dt>"; $desc->clean(); print "\n\t\t\t\t\t<dd style='margin-bottom: 20px;'>" . $desc->asString() . "</dd>"; print "\n\t\t\t\t\t<dt style='font-weight: bold;'>" . _("Agents: ") . "</dt>"; print "\n\t\t\t\t\t<dd style='margin-bottom: 20px;'>" . $agentList . "</dd>"; print "\n\t\t\t\t\t<dt style='font-weight: bold;'>" . _("Nodes: ") . "</dt>"; print "\n\t\t\t\t\t<dd style='margin-bottom: 20px;'>" . $nodeList . "</dd>"; print "\n\t\t\t\t\t<dt style='font-weight: bold;'>" . _("Backtrace: ") . "</dt>"; print "\n\t\t\t\t\t<dd style='margin-bottom: 20px;'>" . $item->getBacktrace() . "</dd>"; print "\n\t\t\t\t</dl>"; $rssItem->setDescription(ob_get_clean()); }