Esempio n. 1
0
 /**
  * Convert object to XML.
  * 
  * @param object $doc DOMDocument
  * @param object $parent DOMElement
  * @param string $nodeName name of the node you want to convert to
  * @param array $arrayToConvert array (or 2d array) you are trying to convert
  *
  * Adds one or more properly formatted xml nodes to the parent
  */
 public function appendChildren($doc, $parent, $nodeName, $arrayToConvert)
 {
     if (array_key_exists($nodeName, $arrayToConvert)) {
         //one object was sent.
         $elem = $doc->createElement($nodeName, $arrayToConvert[$nodeName]);
         $parent->appendChild($elem);
         foreach ($arrayToConvert as $key => $val) {
             if ($key != $nodeName) {
                 $attrName = $doc->createAttribute($key);
                 $elem->appendChild($attrName);
                 $attrVal = $doc->createTextNode($val);
                 $attrName->appendChild($attrVal);
             }
         }
     } else {
         //array of objects was sent
         foreach ($arrayToConvert as $key => $val) {
             $elem = $doc->createElement($nodeName, $val[$nodeName]);
             $parent->appendChild($elem);
             foreach ($val as $attrName => $attrVal) {
                 if ($attrName != $nodeName) {
                     $attribute = $doc->createAttribute($attrName);
                     $elem->appendChild($attribute);
                     $attributevalue = $doc->createTextNode($attrVal);
                     $attribute->appendChild($attributevalue);
                 }
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * Fixes Empty HTML Headers
  * @param string $error_html        - The bad html that needs to be fixed
  * @param string|array $new_content - The new Heading text from the user
  * @param bool $submitting_again    - If the user is resubmitting their error fix
  * @return string $fixed_heading        - The html with corrected Heading
  */
 public function fixHeading($error_html, $new_content, $submitting_again = false)
 {
     $fixed_heading = '';
     if ($new_content == '') {
         return $fixed_heading;
     }
     $matches = array();
     preg_match('/h[0-6]/i', $error_html, $matches);
     $this->dom->loadHTML('<?xml encoding="utf-8" ?>' . $error_html);
     $tag = $this->dom->getElementsByTagName($matches[0])->item(0);
     $headingText = $this->dom->createTextNode($new_content);
     $tag->appendChild($headingText);
     $fixed_heading = $this->dom->saveHTML($tag);
     return $fixed_heading;
 }
 /**
  * Append a single snippet item to the document
  * @param array $snippet
  */
 protected function do_item($snippet)
 {
     $item = $this->dom->createElement('snippet');
     $item = $this->root->appendChild($item);
     foreach ($snippet as $field_name => $field_value) {
         /*  Don't export certain fields */
         if (in_array($field_name, $this->exclude_fields)) {
             continue;
         }
         /* Create a new element for each field */
         $field = $this->dom->createElement($field_name);
         $field = $item->appendChild($field);
         /* Add the field's content */
         $value = $this->dom->createTextNode($field_value);
         $value = $field->appendChild($value);
     }
 }
Esempio n. 4
0
 /**
  * @access 	protected
  * @param 	string			$type					
  * @param 	string			$element				
  * @param 	string			$str					
  * @param 	object			$parent					
  * @return 	object	
  */
 protected function _setElement($type, $element, $str = null, $parent = null)
 {
     try {
         $elem = $this->xpath->query('//' . $type . ':' . $element);
         if ($elem->length == 0) {
             return $this->_addElement($type, $element, $str, $parent);
         } else {
             $pos = 0;
             $el = $elem->item($pos);
             $txt = $this->core->createTextNode($str);
             $el->replaceChild($txt, $el->firstChild);
             return $el;
         }
     } catch (Exception $e) {
         throw $e;
     }
 }
Esempio n. 5
0
 /**
  * Adds a new controller to the layout XML. The unique ID of the attached
  * cntrlr will be returned.
  *
  * @param string $sector
  * @param array $details
  * @param int $id
  * @return int
  */
 public function addController($sector, array $details, $id = null)
 {
     $details = array('id' => $id ? $id : $this->makeCntrlrUid(), 'sector' => $sector, 'order' => isset($details['order']) ? $details['order'] : 0, 'mod' => isset($details['mod']) ? $details['mod'] : 'index', 'con' => isset($details['con']) ? $details['con'] : 'index', 'sec' => isset($details['sec']) ? $details['sec'] : 'index', 'config' => array_merge(array('displayTitle' => true, 'customTitle' => ''), isset($details['config']) ? $details['config'] : array()));
     // Create the new element with attributes
     $cntrlrElement = $this->dom->createElement('controller');
     foreach (array('id', 'sector', 'order') as $attr) {
         $attrElement = $this->dom->createAttribute($attr);
         $attrElement->appendChild($this->dom->createTextNode($details[$attr]));
         $cntrlrElement->appendChild($attrElement);
     }
     // Add all of the elements for this controller.
     foreach (array('mod', 'con', 'sec', 'config') as $key) {
         $val = $details[$key];
         $element = $this->dom->createElement($key);
         if (is_array($val)) {
             // Configuration values, currently only 1 level
             foreach ($val as $confKey => $confVal) {
                 $confElement = $this->dom->createElement($confKey);
                 $method = zula_needs_cdata($confVal) ? 'createCDATASection' : 'createTextNode';
                 $confElement->appendChild($this->dom->{$method}((string) $confVal));
                 $element->appendChild($confElement);
             }
         } else {
             $method = zula_needs_cdata($val) ? 'createCDATASection' : 'createTextNode';
             $element->appendChild($this->dom->{$method}($val));
         }
         $cntrlrElement->appendChild($element);
     }
     $this->dom->documentElement->appendChild($cntrlrElement);
     /**
      * Add ACL resource with default permissions (if needed), cleanup and return
      */
     $resource = 'layout_controller_' . $details['id'];
     if (!$this->_acl->resourceExists($resource)) {
         $this->_acl->allow($resource, 'group_guest');
         $this->_acl->allow($resource, 'group_root');
     }
     $this->_cache->delete('layout_cntrlrs_' . $this->name);
     Hooks::notifyAll('layout_add_cntrlr', $details);
     return $details['id'];
 }
Esempio n. 6
0
/**
 * create the DOM from a node
 * 
 * @param   object  $objMasterDOM   master-DOM
 * @param   array   $arrConfig      the configuration received from the editor, or a part of it
 * @returns object                  DOM-object
 * @throws  InvalidArgumentException
 */
function createDOMFromData($objMasterDOM, $arrConfig)
{
    if (false === isset($arrConfig['nodeName'])) {
        throw new InvalidArgumentException('node has no name, ' . var_export($arrConfig, true));
    }
    if ($arrConfig['nodeName'] == '#text') {
        // this is a masqueraded text-only node
        $objXMLElement = $objMasterDOM->createTextNode($arrConfig['nodeValue']);
        return $objXMLElement;
    }
    // create a new DOM-Element
    $objXMLElement = $objMasterDOM->createElement($arrConfig['nodeName']);
    if (false === empty($arrConfig['attributes'])) {
        // add all of our attributes
        foreach ($arrConfig['attributes'] as $strName => $mixValue) {
            if ($mixValue !== '') {
                $objXMLElement->setAttribute($strName, $mixValue);
            }
        }
    }
    if (false === empty($arrConfig['children'])) {
        // create and add new nodes for all of our children
        foreach ($arrConfig['children'] as $arrChildData) {
            $objXMLElement->appendChild(createDOMFromData($objMasterDOM, $arrChildData));
        }
    }
    if (false === empty($arrConfig['nodeValue'])) {
        // set the node value, if any
        $objCDATA = $objMasterDOM->createTextNode($arrConfig['nodeValue']);
        $objXMLElement->appendChild($objCDATA);
    }
    return $objXMLElement;
}
Esempio n. 7
0
 /**
  * Recursive method to create childs from array
  *
  * @param object $dom Handler to DOMDocument
  * @param object $node Handler to DOMElement (child)
  * @param array $data Array of data to append to the $node.
  * @param string $format Either 'attribute' or 'tags'.  This determines where nested keys go.
  * @return void
  */
 protected static function _fromArray($dom, $node, &$data, $format)
 {
     if (empty($data) || !is_array($data)) {
         return;
     }
     foreach ($data as $key => $value) {
         if (is_string($key)) {
             if (!is_array($value)) {
                 if (is_bool($value)) {
                     $value = (int) $value;
                 } elseif ($value === null) {
                     $value = '';
                 }
                 $isNamespace = strpos($key, 'xmlns:');
                 $nsUri = null;
                 if ($isNamespace !== false) {
                     $node->setAttributeNS('http://www.w3.org/2000/xmlns/', $key, $value);
                     continue;
                 }
                 if ($key[0] !== '@' && $format === 'tags') {
                     $child = $dom->createElement($key, $value);
                     $node->appendChild($child);
                 } else {
                     if ($key[0] === '@') {
                         $key = substr($key, 1);
                     }
                     $attribute = $dom->createAttribute($key);
                     $attribute->appendChild($dom->createTextNode($value));
                     $node->appendChild($attribute);
                 }
             } else {
                 if ($key[0] === '@') {
                     throw new XmlException(__('Invalid array'));
                 }
                 if (array_keys($value) === range(0, count($value) - 1)) {
                     // List
                     foreach ($value as $item) {
                         $data = compact('dom', 'node', 'key', 'format');
                         $data['value'] = $item;
                         self::__createChild($data);
                     }
                 } else {
                     // Struct
                     self::__createChild(compact('dom', 'node', 'key', 'value', 'format'));
                 }
             }
         } else {
             throw new XmlException(__('Invalid array'));
         }
     }
 }
Esempio n. 8
0
 /**
  * Create the portType node
  *
  * @return void
  */
 protected function createWSDL_portType()
 {
     /*
     <portType name="myServicePort">
         <operation name="hello">
             <input message="typens:hello"/>
             <output message="typens:helloResponse"/>
         </operation>
     </portType>
     */
     $portType = $this->wsdl->createElement('portType');
     $portType->setAttribute('name', $this->classname . 'Port');
     foreach ($this->wsdlStruct[$this->classname]['method'] as $methodName => $methodVars) {
         $operation = $this->wsdl->createElement('operation');
         $operation->setAttribute('name', $methodName);
         $portType->appendChild($operation);
         $documentation = $this->wsdl->createElement('documentation');
         $documentation->appendChild($this->wsdl->createTextNode($methodVars['description']));
         $operation->appendChild($documentation);
         $input = $this->wsdl->createElement('input');
         $output = $this->wsdl->createElement('output');
         $input->setAttribute('message', 'typens:' . $methodName);
         $output->setAttribute('message', 'typens:' . $methodName . 'Response');
         $operation->appendChild($input);
         $operation->appendChild($output);
     }
     $this->wsdl_definitions->appendChild($portType);
 }
Esempio n. 9
0
 /**
  * Insert content into an element - content encountered while looping within renderTemplate().
  *
  * @param DOMNode	$element					An instance of DOMNode representing the element.
  * @param string	$data_value					Data to be inserted.
  * @param string	$value_insert_fn			A flag to either replace element's already existing data, to prepend or append it.
  * @param array		$sub_runtime_props			List of insertion settings compiled for this element.
  *
  * @see PHPFrontNodeList::populateNodeList()
  *
  * This is used internally
  *
  * @access private
  *
  * @return	null|DOMNode				Null on error. The originally provided DOMNode on success.
  */
 private function elemSetContent($element, $data_value, $value_insert_fn = 'replace', $sub_runtime_props = array())
 {
     if (empty($element)) {
         return;
     }
     # 2. $data_value is string; insert into matched elements
     // This is crucial!
     // This element may have already been parsed. Its content - the inserted data - may be also be parseable as well.
     // If this is so, a loop call to reparse the document may already have captured this parseable data in a nodeList.
     // Insert-replacing this element's parseable data will send the data out of the current document and make it unavailable.
     // To avoid this problem, all already-parsed elements have the 'data-phpfront-no_parse' attribute set. Detect this attribute and return!
     if ($this->on_reparse && $element->hasAttribute("data-phpfront-no_parse")) {
         $element->removeAttribute("data-phpfront-no_parse");
         return;
     }
     if (!empty(trim($data_value))) {
         // How should we create the element's content?
         $content_type = $this->elemGetParam('content_type', $sub_runtime_props, $element);
         // If $data_value is plain text - Check if $data_value contains HTML tags
         if (!preg_match("/<[^<].*>/", $data_value) || strtoupper($content_type) == 'TEXT' || strtoupper($content_type) == 'CDATA') {
             if (strtoupper($content_type) == 'TEXT') {
                 // Create TextNode and append
                 $documentFragment = $this->PHPFrontDom->createTextNode($data_value);
                 // Encodes entities - even though already encoded
             } else {
                 // Create CDATA Section and append. CDATA is the default where content has not HTML tags
                 $documentFragment = $this->PHPFrontDom->createCDATASection($data_value);
             }
         } else {
             $documentFragment = $this->PHPFrontDom->createDocumentFragment();
             $documentFragment->appendXML($data_value);
         }
         // appendChild() throws error if $documentFragment is empty
         if (!empty($documentFragment)) {
             if ($value_insert_fn == "prepend" && $element->hasChildNodes()) {
                 $element->insertBefore($documentFragment, $element->firstChild);
             } else {
                 if ($value_insert_fn == "replace") {
                     $element->nodeValue = "";
                 }
                 $element->appendChild($documentFragment);
             }
         }
     } else {
         $on_content_empty = $this->elemGetParam('on_content_empty', $sub_runtime_props, $element);
         if ($on_content_empty == "clear" || $on_content_empty == "clear_and_set_flag") {
             $element->nodeValue = "";
         } elseif ($on_content_empty == "set_flag" || $on_content_empty == "clear_and_set_flag") {
             $element->setAttribute("data-phpfront-content_empty", "true");
         } elseif ($on_content_empty == "no_render") {
             $parentNode = $element->parentNode;
             $parentNode->removeChild($element);
             // This element hanle now changes to parent... This is what will be returned
             $element = $parentNode;
         } else {
             $element->nodeValue = $data_value;
         }
     }
     // This whole documen may be parsed again to parse inserted data
     // When this happens, the currently parsed elements should not be parsed again... so lets set the flag
     if ($this->parse_inserted_data && !$this->on_reparse && !isset($parentNode)) {
         $element->setAttribute("data-phpfront-no_reparse", "true");
     }
     return $element;
 }
Esempio n. 10
0
 /**
  * Retreives the output of this object.
  *
  * @return void
  *
  * @author     Benoit Grégoire <*****@*****.**>
  * @author     Francois Proulx <*****@*****.**>
  * @author     Max Horváth <*****@*****.**>
  * @copyright  2004-2006 Benoit Grégoire, Technologies Coeus inc.
  * @copyright  2004-2006 Francois Proulx, Technologies Coeus inc.
  * @copyright  2006 Max Horváth, Horvath Web Consulting
  */
 public function getOutput()
 {
     $db = AbstractDb::getObject();
     // Root node
     $_rss = $this->_xmldoc->createElement("rss");
     $this->_xmldoc->appendChild($_rss);
     $_rss->setAttribute('version', '2.0');
     // channel
     $_channel = $this->_xmldoc->createElement("channel");
     $_rss->appendChild($_channel);
     /*
      * Required channel elements
      */
     // title
     $_title = $this->_xmldoc->createElement("title");
     $_title = $_channel->appendChild($_title);
     $_textNode = $this->_xmldoc->createTextNode($this->_network->getName() . ": " . _("Newest Hotspots"));
     $_title->appendChild($_textNode);
     // link
     $_link = $this->_xmldoc->createElement("link");
     $_channel->appendChild($_link);
     $_textNode = $this->_xmldoc->createTextNode($this->_network->getWebSiteURL());
     $_link->appendChild($_textNode);
     // description
     $_description = $this->_xmldoc->createElement("description");
     $_channel->appendChild($_description);
     $_textNode = $this->_xmldoc->createTextNode(_("List of the most recent Hotspots opened by the network: ") . $this->_network->getName());
     $_description->appendChild($_textNode);
     /*
      * Optional channel elements
      */
     // language
     $_language = $this->_xmldoc->createElement("language");
     $_channel->appendChild($_language);
     if (User::getCurrentUser() != null) {
         $_textNode = $this->_xmldoc->createTextNode(substr(User::getCurrentUser()->getPreferedLocale(), 0, 5));
     } else {
         $_textNode = $this->_xmldoc->createTextNode("en-US");
     }
     $_language->appendChild($_textNode);
     // copyright
     $_copyright = $this->_xmldoc->createElement("copyright");
     $_channel->appendChild($_copyright);
     $_textNode = $this->_xmldoc->createTextNode(_("Copyright ") . $this->_network->getName());
     $_copyright->appendChild($_textNode);
     // webMaster
     if ($this->_network->getTechSupportEmail() != "") {
         $_webMaster = $this->_xmldoc->createElement("webMaster");
         $_channel->appendChild($_webMaster);
         $_textNode = $this->_xmldoc->createTextNode($this->_network->getTechSupportEmail());
         $_webMaster->appendChild($_textNode);
     }
     // pubDate
     $_pubDate = $this->_xmldoc->createElement("pubDate");
     $_channel->appendChild($_pubDate);
     $_textNode = $this->_xmldoc->createTextNode(gmdate("D, d M Y H:i:s \\G\\M\\T", time()));
     $_pubDate->appendChild($_textNode);
     /**
      * lastBuildDate
      *
      * <lastBuildDate> -- The date-time the last time the content of the
      * channel changed.
      *
      * Make a request through the database for the latest modification date
      * of an object.
      *
      * @todo The latest modification date of an object should be an
      *       object property
      */
     $db->execSqlUniqueRes("SELECT EXTRACT(epoch FROM MAX(creation_date)) as date_last_hotspot_opened FROM nodes WHERE network_id = '" . $db->escapeString($this->_network->getId()) . "' AND (node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE')", $_lastHotspotRow, false);
     $_lastBuildDate = $this->_xmldoc->createElement("lastBuildDate");
     $_channel->appendChild($_lastBuildDate);
     $_textNode = $this->_xmldoc->createTextNode(gmdate("D, d M Y H:i:s \\G\\M\\T", $_lastHotspotRow['date_last_hotspot_opened']));
     $_lastBuildDate->appendChild($_textNode);
     // generator
     $_generator = $this->_xmldoc->createElement("generator");
     $_channel->appendChild($_generator);
     $_textNode = $this->_xmldoc->createTextNode(WIFIDOG_NAME . " " . WIFIDOG_VERSION);
     $_generator->appendChild($_textNode);
     // docs
     $_docs = $this->_xmldoc->createElement("docs");
     $_channel->appendChild($_docs);
     $_textNode = $this->_xmldoc->createTextNode("http://blogs.law.harvard.edu/tech/rss");
     $_docs->appendChild($_textNode);
     // image
     /*if (defined('NETWORK_LOGO_NAME') && file_exists(WIFIDOG_ABS_FILE_PATH . "local_content/common/" . constant('NETWORK_LOGO_NAME'))) {
                 $_image = $this->_xmldoc->createElement("image");
                 $_channel->appendChild($_image);
     
                 // title
                 $_title = $this->_xmldoc->createElement("title");
                 $_image->appendChild($_title);
                 $_textNode = $this->_xmldoc->createTextNode($this->_network->getName() . ": " . _("Newest Hotspots"));
                 $_title->appendChild($_textNode);
     
                 // url
                 $_url = $this->_xmldoc->createElement("url");
                 $_image->appendChild($_url);
                 $_textNode = $this->_xmldoc->createTextNode(COMMON_CONTENT_URL . NETWORK_LOGO_NAME);
                 $_url->appendChild($_textNode);
     
                 // link
                 $_link = $this->_xmldoc->createElement("link");
                 $_image->appendChild($_link);
                 $_textNode = $this->_xmldoc->createTextNode($this->_network->getWebSiteURL());
                 $_link->appendChild($_textNode);
     
                 $_imageSize = @getimagesize(WIFIDOG_ABS_FILE_PATH . "local_content/common/" . NETWORK_LOGO_NAME);
     
                 if ($_imageSize) {
                     // width
                     $_width = $this->_xmldoc->createElement("width");
                     $_image->appendChild($_width);
                     $_textNode = $this->_xmldoc->createTextNode($_imageSize[0]);
                     $_width->appendChild($_textNode);
     
                     // height
                     $_height = $this->_xmldoc->createElement("height");
                     $_image->appendChild($_height);
                     $_textNode = $this->_xmldoc->createTextNode($_imageSize[1]);
                     $_height->appendChild($_textNode);
                 }
     
                 // description
                 $_description = $this->_xmldoc->createElement("description");
                 $_image->appendChild($_description);
                 $_textNode = $this->_xmldoc->createTextNode(_("List of the most recent Hotspots opened by the network: ") . $this->_network->getName());
                 $_description->appendChild($_textNode);
             }*/
     // Node details
     if ($this->_nodes) {
         foreach ($this->_nodes as $_nodeData) {
             $_node = Node::getObject($_nodeData['node_id']);
             $this->_network = $_node->getNetwork();
             $_hotspot = $this->_xmldoc->createElement("item");
             $_hotspot = $_channel->appendChild($_hotspot);
             // Hotspot name
             $_hotspotName = $this->_xmldoc->createElement("title", htmlspecialchars($_node->getName(), ENT_QUOTES));
             $_hotspot->appendChild($_hotspotName);
             // Hotspot Website URL
             if ($_node->getWebSiteURL() != "") {
                 $_hotspotUrl = $this->_xmldoc->createElement("link", htmlspecialchars($_node->getWebSiteURL(), ENT_QUOTES));
                 $_hotspot->appendChild($_hotspotUrl);
             }
             // Hotspot name
             $_hotspotDesc = $this->_xmldoc->createElement("description");
             $_hotspot->appendChild($_hotspotDesc);
             $_descriptionText = '<p>';
             // Hotspot global status
             if ($_node->getDeploymentStatus() != 'NON_WIFIDOG_NODE') {
                 if ($_nodeData['is_up'] == 't') {
                     $_descriptionText .= "<img src='" . COMMON_IMAGES_URL . "HotspotStatus/up.gif' alt='up' />";
                 } else {
                     $_descriptionText .= "<img src='" . COMMON_IMAGES_URL . "HotspotStatus/down.gif' alt='down' />";
                 }
             }
             // Description
             if ($_node->getDescription() != "") {
                 $_descriptionText .= htmlspecialchars($_node->getDescription(), ENT_QUOTES);
             }
             $_descriptionText .= '</p>';
             $_descriptionText .= '<p>';
             $_descriptionText .= _("Address") . ": ";
             // Civic number
             if ($_node->getCivicNumber() != "") {
                 $_descriptionText .= $_node->getCivicNumber() . ", ";
             }
             // Street address
             if ($_node->getStreetName() != "") {
                 $_descriptionText .= htmlspecialchars($_node->getStreetName(), ENT_QUOTES) . ", ";
             }
             // City
             if ($_node->getCity() != "") {
                 $_descriptionText .= htmlspecialchars($_node->getCity(), ENT_QUOTES) . ", ";
             }
             // Province
             if ($_node->getProvince() != "") {
                 $_descriptionText .= htmlspecialchars($_node->getProvince(), ENT_QUOTES) . ", ";
             }
             // Postal code
             if ($_node->getPostalCode() != "") {
                 $_descriptionText .= $_node->getPostalCode() . ", ";
             }
             // Country
             if ($_node->getCountry() != "") {
                 $_descriptionText .= htmlspecialchars($_node->getCountry(), ENT_QUOTES);
             }
             // Map Url
             if ($_node->getMapURL() != "") {
                 $_descriptionText .= " <a href='" . $_node->getMapURL() . "'>" . _("See Map") . "</a>";
             }
             // Mass transit info
             if ($_node->getTransitInfo() != "") {
                 $_descriptionText .= "<br />";
                 $_descriptionText .= htmlspecialchars($_node->getTransitInfo(), ENT_QUOTES);
             }
             $_descriptionText .= "</p>";
             if ($_node->getEmail() != "" || $_node->getTelephone() != "") {
                 $_descriptionText .= "<p>";
                 $_descriptionText .= _("Contact") . ": ";
                 // Contact e-mail
                 if ($_node->getEmail() != "") {
                     $_descriptionText .= "<br /><a href='mailto:" . $_node->getEmail() . "'>" . $_node->getEmail() . "</a>";
                 }
                 // Contact phone
                 if ($_node->getTelephone() != "") {
                     $_descriptionText .= "<br />" . $_node->getTelephone();
                 }
                 $_descriptionText .= "</p>";
             }
             $_hotspotDesc->appendChild($this->_xmldoc->createTextNode($_descriptionText));
             // guid
             if ($_node->getWebSiteURL() != "") {
                 $_guid = $this->_xmldoc->createElement("guid");
                 $_guid->setAttribute('isPermaLink', 'false');
                 $_hotspot->appendChild($_guid);
                 $_textNode = $this->_xmldoc->createTextNode(htmlspecialchars($_node->getWebSiteURL(), ENT_QUOTES));
                 $_guid->appendChild($_textNode);
             }
             // pubDate
             $_hotspotOpeningDate = $this->_xmldoc->createElement("pubDate", gmdate("D, d M Y H:i:s \\G\\M\\T", $_nodeData['creation_date_epoch']));
             $_hotspot->appendChild($_hotspotOpeningDate);
         }
     }
     echo $this->_xmldoc->saveXML();
 }
Esempio n. 11
0
 /**
  * Convert the supplied node into its bbc equivalent
  *
  * @param object $node
  */
 private function _convert_to_bbc($node)
 {
     // HTML tag names
     $tag = $this->_get_name($node);
     $parent = $this->_get_name($this->_parser ? $node->parentNode : $node->parentNode());
     $next_tag = $this->_get_name($this->_parser ? $node->nextSibling : $node->next_sibling());
     // Looking around, do we need to add any breaks here?
     $needs_leading_break = in_array($tag, $this->block_elements);
     $needs_trailing_break = !in_array($next_tag, $this->block_elements) && $needs_leading_break;
     // Flip things around inside li element, it looks better
     if ($parent == 'li' && $needs_leading_break) {
         $needs_trailing_break = true;
         $needs_leading_break = false;
     }
     // Skipping over this tag?
     if (in_array($tag, $this->_skip_tags)) {
         $tag = '';
     }
     // Based on the current tag, determine how to convert
     switch ($tag) {
         case 'a':
             $bbc = $this->_convert_anchor($node);
             break;
         case 'abbr':
             $bbc = $this->_convert_abbr($node);
             break;
         case 'b':
         case 'strong':
             $bbc = '[b]' . $this->_get_value($node) . '[/b]';
             break;
         case 'bdo':
             $bbc = $this->_convert_bdo($node);
             break;
         case 'blockquote':
             $bbc = '[quote]' . $this->_get_value($node) . '[/quote]';
             break;
         case 'br':
             $bbc = $this->line_break . $this->line_end;
             break;
         case 'center':
             $bbc = '[center]' . $this->_get_value($node) . '[/center]' . $this->line_end;
             break;
         case 'code':
             $bbc = $this->_convert_code($node);
             break;
         case 'dt':
             $bbc = str_replace(array("\n", "\r", "\n\r"), '', $this->_get_value($node)) . $this->line_end;
             break;
         case 'dd':
             $bbc = ':   ' . $this->_get_value($node) . $this->line_break;
             break;
         case 'dl':
             $bbc = trim($this->_get_value($node)) . $this->line_break;
             break;
         case 'div':
             $bbc = $this->strip_newlines ? str_replace("\n", ' ', $this->_convert_styles($node)) : $this->_convert_styles($node);
             break;
         case 'em':
         case 'i':
             $bbc = '[i]' . $this->_get_value($node) . '[/i]';
             break;
         case 'font':
             $bbc = $this->_convert_font($node);
             break;
         case 'hr':
             $bbc = '[hr]';
             break;
         case 'h1':
         case 'h2':
         case 'h3':
         case 'h4':
         case 'h5':
         case 'h6':
             $bbc = $this->_convert_header($tag, $this->_get_value($node));
             break;
         case 'img':
             $bbc = $this->_convert_image($node);
             break;
         case 'ol':
             $bbc = '[list type=decimal]' . $this->line_end . $this->_get_value($node) . '[/list]';
             break;
         case 'ul':
             $bbc = '[list]' . $this->line_end . $this->_get_value($node) . '[/list]';
             break;
         case 'li':
             $bbc = '[li]' . $this->_get_value($node) . '[/li]' . $this->line_end;
             break;
         case 'p':
             $bbc = $this->strip_newlines ? str_replace("\n", ' ', $this->_convert_styles($node)) : $this->_convert_styles($node);
             break;
         case 'pre':
             $bbc = '[pre]' . $this->_get_value($node) . '[/pre]';
             break;
         case 'script':
         case 'style':
             $bbc = '';
             break;
         case 'span':
             // Convert some basic inline styles to bbc
             $bbc = $this->_convert_styles($node);
             break;
         case 'strike':
         case 'del':
         case 's':
             $bbc = '[s]' . $this->_get_value($node) . '[/s]';
             break;
         case 'sub':
             $bbc = '[sub]' . $this->_get_value($node) . '[/sub]';
             break;
         case 'sup':
             $bbc = '[sup]' . $this->_get_value($node) . '[/sup]';
             break;
         case 'title':
             $bbc = '[size=2]' . $this->_get_value($node) . '[/size]';
             break;
         case 'table':
             $bbc = '[table]' . $this->line_end . $this->_get_value($node) . '[/table]';
             break;
         case 'th':
         case 'td':
             $bbc = $this->_convert_table_cell($node) . $this->line_end;
             break;
         case 'tr':
             $bbc = '[tr]' . $this->line_end . $this->_get_value($node) . '[/tr]' . $this->line_end;
             break;
         case 'tbody':
         case 'tfoot':
         case 'thead':
             $bbc = $this->_get_innerHTML($node);
             break;
         case 'tt':
             $bbc = '[tt]' . $this->_get_value($node) . '[/tt]';
             break;
         case 'u':
         case 'ins':
             $bbc = '[u]' . $this->_get_value($node) . '[/u]';
             break;
         case 'root':
         case 'body':
             // Remove these tags and simply replace with the text inside the tags
             $bbc = '~`skip`~';
             break;
         default:
             // Don't know you, so just preserve whats there, less the tag
             $bbc = $this->_get_outerHTML($node);
     }
     // Replace the node with our bbc replacement, or with the node itself if none was found
     if ($bbc !== '~`skip`~') {
         $bbc = $needs_leading_break ? $this->line_break . $this->line_end . $bbc : $bbc;
         $bbc = $needs_trailing_break ? $bbc . $this->line_break . $this->line_end : $bbc;
         if ($this->_parser) {
             // Create a new text node with our bbc tag and replace the original node
             $bbc_node = $this->doc->createTextNode($bbc);
             $node->parentNode->replaceChild($bbc_node, $node);
         } else {
             $node->outertext = $bbc;
         }
     }
 }
Esempio n. 12
0
 /**
  * Inserts a new text node using the property object field provided.
  * @param string $element
  * @param string $var
  * @param object $hp
  * @param object $prop
  * @return object
  * @access private
  */
 protected function hpTextNode($element = 'node', $var = false, &$hp, $prop)
 {
     $var = $var ? $var : $element;
     $node = $hp->createElement($element);
     $node->appendChild($hp->createTextNode($hp->encode_for_xml($prop->{$var})));
     return $node;
 }
Esempio n. 13
0
 /**
  * Displays the output of this object.
  *
  * @return void
  *
  * @author     Benoit Gregoire <*****@*****.**>
  * @author     Francois Proulx <*****@*****.**>
  * @author     Max Horváth <*****@*****.**>
  * @author     Joe Bowser <*****@*****.**>
  * @copyright  2004-2006 Benoit Gregoire, Technologies Coeus inc.
  * @copyright  2004-2006 Francois Proulx, Technologies Coeus inc.
  * @copyright  2006 Max Horváth, Horvath Web Consulting
  * @copyright  2006 Joe Bowser
  */
 public function getOutput()
 {
     $_kml = $this->_xmldoc->createElement("kml");
     $_kml->setAttribute('xmlns', 'http://earth.google.com/kml/2.0');
     $this->_xmldoc->appendChild($_kml);
     // Document
     $_document = $this->_xmldoc->createElement("Document");
     $_kml->appendChild($_document);
     /*
      * Style Elements (Up Nodes)
      */
     $_style_up = $this->_xmldoc->createElement("Style");
     $_style_up->setAttribute('id', 'node_up');
     $_document->appendChild($_style_up);
     $_iconStyle = $this->_xmldoc->createElement("IconStyle");
     $_style_up->appendChild($_iconStyle);
     /* Since scale is the same, we only have to define it once */
     $_scale = $this->_xmldoc->createElement("scale");
     $_iconStyle->appendChild($_scale);
     $_textNode = $this->_xmldoc->createTextNode("0.5");
     $_scale->appendChild($_textNode);
     $_icon = $this->_xmldoc->createElement("Icon");
     $_iconStyle->appendChild($_icon);
     $_href = $this->_xmldoc->createElement("href");
     $_icon->appendChild($_href);
     $_textNode = $this->_xmldoc->createTextNode(BASE_URL_PATH . "images/HotspotStatusMap/up.png");
     $_href->appendChild($_textNode);
     /*
      * Style Elements (Down Nodes)
      */
     $_style_down = $this->_xmldoc->createElement("Style");
     $_style_down->setAttribute('id', 'node_down');
     $_document->appendChild($_style_down);
     $_iconStyle = $this->_xmldoc->createElement("IconStyle");
     $_style_down->appendChild($_iconStyle);
     $_scale = $this->_xmldoc->createElement("scale");
     $_iconStyle->appendChild($_scale);
     $_textNode = $this->_xmldoc->createTextNode("0.5");
     $_scale->appendChild($_textNode);
     $_iconStyle->appendChild($_scale);
     $_icon = $this->_xmldoc->createElement("Icon");
     $_iconStyle->appendChild($_icon);
     $_href = $this->_xmldoc->createElement("href");
     $_icon->appendChild($_href);
     $_textNode = $this->_xmldoc->createTextNode(BASE_URL_PATH . "images/HotspotStatusMap/down.png");
     $_href->appendChild($_textNode);
     /*
      * Style Elements (Unknown Nodes)
      */
     $_style_unknown = $this->_xmldoc->createElement("Style");
     $_style_unknown->setAttribute('id', 'node_unknown');
     $_document->appendChild($_style_unknown);
     $_iconStyle = $this->_xmldoc->createElement("IconStyle");
     $_style_unknown->appendChild($_iconStyle);
     $_scale = $this->_xmldoc->createElement("scale");
     $_iconStyle->appendChild($_scale);
     $_textNode = $this->_xmldoc->createTextNode("0.5");
     $_scale->appendChild($_textNode);
     $_icon = $this->_xmldoc->createElement("Icon");
     $_iconStyle->appendChild($_icon);
     $_href = $this->_xmldoc->createElement("href");
     $_icon->appendChild($_href);
     $_textNode = $this->_xmldoc->createTextNode(BASE_URL_PATH . "images/HotspotStatusMap/unknown.png");
     $_href->appendChild($_textNode);
     /*
      * Creating the Folder
      */
     $_folder = $this->_xmldoc->createElement("Folder");
     $_document->appendChild($_folder);
     $_name = $this->_xmldoc->createElement("name");
     $_folder->appendChild($_name);
     $_textNode = $this->_xmldoc->createTextNode($this->_network->getName());
     $_name->appendChild($_textNode);
     /*
      * Creating the Placemarks (Nodes)
      */
     if ($this->_nodes) {
         foreach ($this->_nodes as $_nodeData) {
             $_node = Node::getObject($_nodeData['node_id']);
             $this->_network = $_node->getNetwork();
             $_placemark = $this->_xmldoc->createElement("Placemark");
             $_folder->appendChild($_placemark);
             // Hotspot name
             $_hotspotName = $this->_xmldoc->createElement("name", htmlspecialchars($_node->getName(), ENT_QUOTES));
             $_placemark->appendChild($_hotspotName);
             $_html_data = "<b>" . _("Address") . ":</b><br />" . $_node->getCivicNumber() . " " . $_node->getStreetName() . "<br />" . $_node->getCity() . "," . $_node->getProvince() . "<br />" . $_node->getCountry() . "<br />" . $_node->getPostalCode() . "<br /><br /> <b>" . _("URL") . ":</b> <a href='" . $_node->getWebSiteURL() . "'>" . $_node->getWebSiteURL() . "</a> <br /> <b> " . _("Email") . ":</b> <a href='mailto:" . $_node->getEmail() . "'>" . $_node->getEmail() . "</a>";
             // Creating the description node with the data from it
             $_description = $this->_xmldoc->createElement("description");
             $_placemark->appendChild($_description);
             $_cdata = $this->_xmldoc->createCDATASection($_html_data);
             $_description->appendChild($_cdata);
             // Description data goes here
             $_point = $this->_xmldoc->createElement("Point");
             $_placemark->appendChild($_point);
             // Get GIS Location
             $_gis_loc = $_node->getGisLocation();
             $_gis_string = $_gis_loc->getLongitude() . "," . $_gis_loc->getLatitude() . "," . $_gis_loc->getAltitude();
             $_coordinates = $this->_xmldoc->createElement("coordinates", $_gis_string);
             // Hotspot global status
             if ($_node->getDeploymentStatus() != 'NON_WIFIDOG_NODE') {
                 if ($_nodeData['is_up'] == 't') {
                     $_styleURL = $this->_xmldoc->createElement("styleURL", "#node_up");
                 } else {
                     $_styleURL = $this->_xmldoc->createElement("styleURL", "#node_down");
                 }
             } else {
                 $_styleURL = $this->_xmldoc->createElement("styleURL", "#node_unknown");
             }
             $_point->appendChild($_coordinates);
         }
     }
     echo $this->_xmldoc->saveXML();
 }
Esempio n. 14
0
 /**
  * Method: buildCoordinatesNode
  * Builds and returns the KML coordinates node with the given geometry
  * <coordinates>...</coordinates>
  * 
  * Parameters:
  * geometry - {<OpenLayers.Geometry>}
  * 
  * Return:
  * {DOMElement}
  */
 private function _buildCoordinatesNode($geometry)
 {
     $coordinatesNode = $this->doc->createElementNS($this->kmlns, "coordinates");
     $points = $geometry->components;
     if (!empty($points)) {
         // LineString or LinearRing
         //          $numPoints = count($points);
         //          var parts = new Array(numPoints);
         $parts = array();
         foreach ($points as $point) {
             $parts[] = $point->x . "," . $point->y;
         }
         //$path = parts.join(" ");
     } else {
         // Point
         $path = $geometry->x . "," . $geometry->y;
     }
     $txtNode = $this->doc->createTextNode($path);
     $coordinatesNode->appendChild($txtNode);
     return $coordinatesNode;
 }
Esempio n. 15
0
 /**
  * Convert the supplied node into its markdown equivalent
  *  - Supports *some* markdown extra tags, namely: table, abbr & dl in a limited fashion
  *
  * @param object $node
  */
 private function _convert_to_markdown($node)
 {
     // HTML tag we are dealing with
     $tag = $this->_get_name($node);
     // Based on the tag, determine how to convert
     switch ($tag) {
         case 'a':
             $markdown = $this->_convert_anchor($node);
             break;
         case 'abbr':
             $markdown = $this->_convert_abbr($node);
             break;
         case 'b':
         case 'strong':
             $markdown = '**' . $this->_get_value($node) . '**';
             break;
         case 'blockquote':
             $markdown = $this->_convert_blockquote($node);
             break;
         case 'br':
             $markdown = '  ' . $this->line_end;
             break;
         case 'center':
             $markdown = $this->line_end . $this->_get_value($node) . $this->line_end;
             break;
         case 'code':
             $markdown = $this->_convert_code($node);
             break;
         case 'dt':
             $markdown = str_replace(array("\n", "\r", "\n\r"), '', $this->_get_value($node)) . $this->line_end;
             break;
         case 'dd':
             $markdown = ':   ' . $this->_get_value($node) . $this->line_break;
             break;
         case 'dl':
             $markdown = trim($this->_get_value($node)) . $this->line_break;
             break;
         case 'em':
         case 'i':
             $markdown = '_' . $this->_get_value($node) . '_';
             break;
         case 'hr':
             $markdown = $this->line_end . str_repeat('-', 3) . $this->line_end;
             break;
         case 'h1':
         case 'h2':
         case 'h3':
         case 'h4':
         case 'h5':
         case 'h6':
             $markdown = $this->_convert_header($tag, $this->_get_value($node));
             break;
         case 'img':
             $markdown = $this->_convert_image($node);
             break;
         case 'ol':
         case 'ul':
             $markdown = rtrim($this->_get_value($node)) . $this->line_break;
             break;
         case 'li':
             $markdown = $this->_convert_list($node);
             break;
         case 'p':
             if (!$node->hasChildNodes()) {
                 $markdown = str_replace("\n", ' ', $this->_get_value($node)) . $this->line_break;
                 $markdown = $this->_escape_text($markdown);
             } else {
                 $markdown = rtrim($this->_get_value($node)) . $this->line_break;
             }
             break;
         case 'pre':
             $markdown = $this->_get_value($node) . $this->line_break;
             break;
         case 'div':
             $markdown = $this->line_end . $this->_get_value($node) . $this->line_end;
             if (!$node->hasChildNodes()) {
                 $markdown = $this->_escape_text($markdown);
             }
             break;
             //case '#text':
             //  $markdown = $this->_escape_text($this->_get_value($node));
             //  break;
         //case '#text':
         //  $markdown = $this->_escape_text($this->_get_value($node));
         //  break;
         case 'title':
             $markdown = '# ' . $this->_get_value($node) . $this->line_break;
             break;
         case 'table':
             $markdown = $this->_convert_table($node) . $this->line_break;
             break;
         case 'th':
         case 'tr':
         case 'td':
         case 'tbody':
         case 'tfoot':
         case 'thead':
             // Just skip over these as we handle them in the table tag itself
             $markdown = '~`skip`~';
             break;
         case 'root':
         case 'span':
         case 'body':
             // Remove these tags and simply replace with the text inside the tags
             $markdown = $this->_get_innerHTML($node);
             break;
         default:
             // Don't know you or text, so just preserve whats there
             $markdown = $this->_get_outerHTML($node);
     }
     // Replace the node with our markdown replacement, or with the node itself if none was found
     if ($markdown !== '~`skip`~') {
         if ($this->_parser) {
             // Create a new text node with our markdown tag and replace the original node
             $markdown_node = $this->doc->createTextNode($markdown);
             $node->parentNode->replaceChild($markdown_node, $node);
         } else {
             $node->outertext = $markdown;
         }
     }
 }
Esempio n. 16
0
 /**
  * Add a text node to an XML element (tag)
  * 
  * @param   string $text Text value to add
  * @param   object $bind XML element to add the text to
  * @return  null
  */
 public function addText($text, $bind)
 {
     $bind->appendChild($this->dom->createTextNode($text));
 }
 /**
  * parse tree ready for insertion into sitemap DB
  *
  * @param string $n 
  * @param object $dom 
  * @param object $child 
  * @param array $items 
  * @return void
  * @author Andy Bennett
  */
 private static function save_parse($n, &$dom, &$child, $items)
 {
     $arr = array('txt' => 'title', 'id' => 'url');
     $element = $dom->createElement($n);
     foreach ($items as $k => $item) {
         if ($k != 'items') {
             if (isset($arr[$k])) {
                 $f = 'translate_' . $k;
                 $item = self::$f($item);
                 if ($item == '') {
                     continue;
                 }
                 $k = $arr[$k];
             }
             $att = $dom->createAttribute($k);
             $att->appendChild($dom->createTextNode($item));
             $element->appendChild($att);
         } else {
             foreach ($item as $sub) {
                 self::save_parse('item', $dom, $element, $sub);
             }
         }
     }
     $child->appendChild($element);
 }
Esempio n. 18
0
 /**
  * Used in rendering a cached web page to highlight the search terms.
  *
  * @param object $node DOM object to mark html elements of
  * @param array $words an array of words to be highlighted
  * @param object $dom a DOM object for the whole document
  * @return object the node modified to now have highlighting
  */
 function markChildren($node, $words, $dom)
 {
     if (!isset($node->childNodes->length) || get_class($node) != 'DOMElement') {
         return $node;
     }
     for ($k = 0; $node->childNodes->length; $k++) {
         if (!$node->childNodes->item($k)) {
             break;
         }
         $clone = $node->childNodes->item($k)->cloneNode(true);
         if ($clone->nodeType == XML_TEXT_NODE) {
             $text = $clone->textContent;
             foreach ($words as $word) {
                 //only mark string of length at least 2
                 if (mb_strlen($word) > 1) {
                     $mark_prefix = crawlHash($word);
                     if (stristr($mark_prefix, $word) !== false) {
                         $mark_prefix = preg_replace("/\\b{$word}\\b/i", '', $mark_prefix);
                     }
                     $text = preg_replace("/\\b{$word}\\b/i", $mark_prefix . '$0', $text);
                 }
             }
             $textNode = $dom->createTextNode($text);
             $node->replaceChild($textNode, $node->childNodes->item($k));
         } else {
             $clone = $this->markChildren($clone, $words, $dom);
             $node->replaceChild($clone, $node->childNodes->item($k));
         }
     }
     return $node;
 }