PHP SimpleXMLElement Code Examples

This page contains top rated real world PHP examples of SimpleXMLElement extracted from open source projects. You can rate examples to help us improve the quality of examples
Example #1
Show file File: DispatchXmlParser.php Project: leqg/leqg
0
 public function encode(\Esendex\Model\DispatchMessage $message)
 {
     if (strlen($message->originator()) < 1) {
         throw new ArgumentException("Originator is invalid");
     }
     if (strlen($message->recipient()) < 1) {
         throw new ArgumentException("Recipient is invalid");
     }
     if ($message->validityPeriod() > 72) {
         throw new ArgumentException("Validity too long, must be less or equal to than 72");
     }
     $doc = new \SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><messages />", 0, false, Api::NS);
     $doc->accountreference = $this->reference;
     $child = $doc->addChild("message");
     $child->from = $message->originator();
     $child->to = $message->recipient();
     $child->body = $message->body();
     $child->type = $message->type();
     if ($message->validityPeriod() > 0) {
         $child->validity = $message->validityPeriod();
     }
     if ($message->language() != null) {
         $child->lang = $message->language();
     }
     return $doc->asXML();
 }
Example #2
Show file File: GenSitemapXml.php Project: neoartdoo/CMS
0
 public function __construct($lg = 'fr')
 {
     parent::__construct($lg);
     $this->lg = URL . 't/' . $lg . '/';
     $base = $this->lg;
     $this->xmlOut = '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
     $this->xmlOut .= "<url><loc>{$base}</loc><priority>1.00</priority><changefreq>daily</changefreq></url>";
     $this->Gen();
     $this->xmlOut .= '</urlset>';
     $fileSitemap = BASE . 'sitemap.xml';
     $newXml = new SimpleXMLElement($this->xmlOut);
     $newXml->asXML($fileSitemap);
     $aL = $this->allLanguages;
     foreach ($aL as $k => $v) {
         parent::__construct($k);
         $this->lg = URL . 't/' . $k . '/';
         $base = $this->lg;
         $this->xmlOut = '';
         $this->xmlOut = '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
         $this->xmlOut .= "<url><loc>{$base}</loc><priority>1.00</priority><changefreq>daily</changefreq></url>";
         $this->Gen();
         $this->xmlOut .= '</urlset>';
         $fileSitemap = BASE . 't/' . $k . '/sitemap.xml';
         $newXml = new SimpleXMLElement($this->xmlOut);
         $newXml->asXML($fileSitemap);
     }
 }
Example #3
Show file File: core_stack_display.php Project: ricardomccerqueira/rcerqueira.portfolio
0
 public function export(SimpleXMLElement $blockNode)
 {
     $stack = Stack::getByID($this->stID);
     if (is_object($stack)) {
         $blockNode->addChild('stack', '<![CDATA[' . $stack->getCollectionName() . ']]>');
     }
 }
Example #4
Show file File: arraytoxml.php Project: carriercomm/opengateway
0
 /**
  * Convert an XML document to a multi dimensional array
  * Pass in an XML document (or SimpleXMLElement object) and this recrusively loops through and builds a representative array
  *
  * @param string $xml - XML document - can optionally be a SimpleXMLElement object
  * @return array ARRAY
  */
 public static function toArray($xml)
 {
     if (is_string($xml)) {
         $xml = new SimpleXMLElement($xml);
     }
     $children = $xml->children();
     if (!$children) {
         return (string) $xml;
     }
     $arr = array();
     foreach ($children as $key => $node) {
         $node = ArrayToXML::toArray($node);
         // support for 'anon' non-associative arrays
         if ($key == 'anon') {
             $key = count($arr);
         }
         // if the node is already set, put it into an array
         if (isset($arr[$key])) {
             if (!is_array($arr[$key]) || !isset($arr[$key][0])) {
                 $arr[$key] = array($arr[$key]);
             }
             $arr[$key][] = $node;
         } else {
             $arr[$key] = $node;
         }
     }
     return $arr;
 }
Example #5
Show file File: showBookings.php Project: romangn/Taxi-booking-system
0
function displayBookings()
{
    $host;
    $user;
    $pswd;
    $dbnm;
    $connection = mysqli_connect($host, $user, $pswd, $dbnm) or die('Failed to connect.');
    $searchQuery = "SELECT * FROM bookings where status = 'unassigned'";
    $result = mysqli_query($connection, $searchQuery);
    $xml = new SimpleXMLElement('<xml/>');
    if (mysqli_num_rows($result) > 0) {
        while ($result_array = mysqli_fetch_array($result)) {
            $data = $xml->addChild('search');
            $data->addChild('bookingNumber', $result_array['bookingNumber']);
            $data->addChild('customerName', $result_array['customerName']);
            $data->addChild('pickupAddress', $result_array['pickupAddress']);
            $data->addChild('suburb', $result_array['suburb']);
            $data->addChild('destination', $result_array['destination']);
            $data->addChild('phoneNumber', $result_array['contactPhone']);
            $data->addChild('pickUpDate', $result_array['pickUpDate']);
            $data->addChild('pickUpTime', $result_array['pickUpTime']);
            $data->addChild('bookingDate', $result_array['bookingDate']);
            $data->addChild('bookingTime', $result_array['bookingTime']);
        }
    }
    echo $xml->asXML();
}
Example #6
Show file File: DatePart.php Project: geissler/csl
0
 /**
  * Parses the affix configuration.
  *
  * @param \SimpleXMLElement $date
  * @param array $additional Array with key form and value text or numeric
  */
 public function __construct(\SimpleXMLElement $date, array $additional)
 {
     $this->name = '';
     $this->delimiter = '–';
     $this->formatting = new Formatting($date);
     $this->textCase = new TextCase($date);
     $this->affix = new Affix($date);
     foreach ($date->attributes() as $name => $value) {
         switch ($name) {
             case 'name':
                 $this->name = (string) $value;
                 switch ($this->name) {
                     case 'day':
                         $this->render = Factory::day($additional['form'], $date);
                         break;
                     case 'month':
                         $this->render = Factory::month($additional['form'], $date);
                         break;
                     case 'year':
                         $this->render = Factory::year($additional['form'], $date);
                         break;
                 }
                 break;
             case 'range-delimiter':
                 $this->delimiter = (string) $value;
                 break;
         }
     }
 }
Example #7
Show file File: Svn2Rss.php Project: rcappuccio/gitsvn
0
 /**
  * Starts the processing of the current rss-request.
  * Acts like some kind of a main-method, so manages the further control-flow.
  */
 public function processSvn2RssRequest($strFeedParam = "")
 {
     try {
         //start by loading the config-file
         $objConfig = new ConfigReader($strFeedParam);
         //create the svn-reader and pass control
         $objSvnReader = new SvnReader($objConfig);
         $strSvnLog = $objSvnReader->getSvnLogContent();
         //create rss-nodes out of the logfile
         $objRssConverter = new Log2RssConverter($objConfig);
         $objRssRootNode = $objRssConverter->generateRssNodesFromLogContent($strSvnLog);
         $this->strOutput = $objRssRootNode->asXML();
     } catch (Svn2RssException $objException) {
         //Wrap error-message as a rss-feed element, too
         $objFeedRootNode = new SimpleXMLElement("<rss version=\"2.0\"></rss>");
         $objChannel = $objFeedRootNode->addChild("channel");
         $objChannel->addChild("title", "Error");
         $objChannel->addChild("description", "Error while loading feed");
         $objChannel->addChild("link", "n.a.");
         $objChannel->addChild("pubDate", strftime("%a, %d %b %Y %H:%M:%S GMT", time()));
         $objRssItemNode = $objChannel->addChild("item");
         $objRssItemNode->addChild("title", "Something bad happened: \n" . $objException->getMessage() . "");
         $objRssItemNode->addChild("description", "Something bad happened: \n" . $objException->getMessage() . "");
         $objRssItemNode->addChild("pubDate", strftime("%a, %d %b %Y %H:%M:%S GMT", time()));
         $this->strOutput = $objFeedRootNode->asXML();
     }
 }
Example #8
Show file File: IndexObjectsGenerator.php Project: visomar/server
0
 public function load($inputFile)
 {
     $objects = array();
     if (!file_exists($inputFile)) {
         KalturaLog::err("input file " . $inputFile . " not found");
         exit(1);
     }
     $inputXml = file_get_contents($inputFile);
     $xml = new SimpleXMLElement($inputXml);
     foreach ($xml->children() as $searchableObject) {
         $objectAttribtues = $searchableObject->attributes();
         $objName = $objectAttribtues["name"];
         $this->parseObject("{$objName}", $objectAttribtues);
         $this->searchableIndices["{$objName}"] = array();
         foreach ($searchableObject->children() as $type => $searchableField) {
             switch ($type) {
                 case "field":
                     $this->parseField("{$objName}", $searchableField);
                     break;
                 case "index":
                     $this->parseIndex("{$objName}", $searchableField);
                     break;
             }
         }
         $objects[] = "{$objName}";
     }
     return $objects;
 }
Example #9
Show file File: anno0Tasks.php Project: valerio-bozzolan/openparlamento
0
function getImportantActs($xml_url, $xsl_filename, $n_nodes)
{
    try {
        // read the xml from url
        $xmldoc = new DomDocument();
        $xmldoc->load($xml_url);
        // read xslt file
        $xsldoc = new DomDocument();
        $xsldoc->load($xsl_filename);
        $xsl = new XSLTProcessor();
        $xsl->importStyleSheet($xsldoc);
        // trasforma XML secondo l'XSLT ed estrae il contenuto del div
        $transformed_xml = new SimpleXMLElement($xsl->transformToXML($xmldoc));
        $nodes = $transformed_xml->children();
        // write values to screen
        $cnt = 0;
        foreach ($nodes as $node) {
            $cnt++;
            $atto = OppAttoPeer::retrieveByPK($node['atto_id']);
            printf("\t%d. %s => %f\n", $cnt, $atto->getTitoloCompleto(), $node['totale']);
            if ($cnt >= $n_nodes) {
                break;
            }
        }
    } catch (Exception $e) {
        printf("Errore durante la scrittura del file: %s\n", $e->getMessage());
    }
}
Example #10
Show file File: twillip.php Project: jmhobbs/Twillip
0
 /** Prettifies an XML string into a human-readable and indented work of art
  *  @param string $xml The XML as a string
  *  @param boolean $html_output True if the output should be escaped (for use in HTML)
  */
 public static function xmlpp($xml, $html_output = false)
 {
     $xml_obj = new SimpleXMLElement($xml);
     $level = 4;
     $indent = 0;
     // current indentation level
     $pretty = array();
     // get an array containing each XML element
     $xml = explode("\n", preg_replace('/>\\s*</', ">\n<", $xml_obj->asXML()));
     // shift off opening XML tag if present
     if (count($xml) && preg_match('/^<\\?\\s*xml/', $xml[0])) {
         $pretty[] = array_shift($xml);
     }
     foreach ($xml as $el) {
         if (preg_match('/^<([\\w])+[^>\\/]*>$/U', $el)) {
             // opening tag, increase indent
             $pretty[] = str_repeat(' ', $indent) . $el;
             $indent += $level;
         } else {
             if (preg_match('/^<\\/.+>$/', $el)) {
                 $indent -= $level;
                 // closing tag, decrease indent
             }
             if ($indent < 0) {
                 $indent += $level;
             }
             $pretty[] = str_repeat(' ', $indent) . $el;
         }
     }
     $xml = implode("\n", $pretty);
     return $html_output ? htmlentities($xml) : $xml;
 }
Example #11
Show file File: ConvertArray.php Project: shabbirvividads/magento2
0
 /**
  * Function, that actually recursively transforms array to xml
  *
  * @param array $array
  * @param string $rootName
  * @param \SimpleXMLElement $xml
  * @return \SimpleXMLElement
  * @throws Exception
  */
 private function _assocToXml(array $array, $rootName, \SimpleXMLElement $xml)
 {
     $hasNumericKey = false;
     $hasStringKey = false;
     foreach ($array as $key => $value) {
         if (!is_array($value)) {
             if (is_string($key)) {
                 if ($key === $rootName) {
                     throw new Exception('Associative key must not be the same as its parent associative key.');
                 }
                 $hasStringKey = true;
                 $xml->addChild($key, $value);
             } elseif (is_int($key)) {
                 $hasNumericKey = true;
                 $xml->addChild($key, $value);
             }
         } else {
             $xml->addChild($key);
             self::_assocToXml($value, $key, $xml->{$key});
         }
     }
     if ($hasNumericKey && $hasStringKey) {
         throw new Exception('Associative and numeric keys must not be mixed at one level.');
     }
     return $xml;
 }
Example #12
Show file File: XmlParser.php Project: gerdlaser/SimilarWebApi
0
 private function parseMaps(\SimpleXMLElement $xml)
 {
     $maps = array();
     if (array_key_exists('maps', $this->mapping)) {
         foreach ($this->mapping['maps'] as $key => $item) {
             /* --- XML NS --- */
             if ('MobileRelatedApps' == $this->name) {
                 /** @var $element \SimpleXMLElement */
                 $element = $xml->{'RelatedApps'};
                 $ns = $xml->getNamespaces(true);
                 $map = array();
                 foreach ($element->children($ns['d2p1']) as $element) {
                     $map[(string) $element->{$item['xml']['key']}] = (string) $element->{$item['xml']['value']};
                 }
                 $maps[$key] = $map;
                 continue;
             }
             /* --- XML NS --- */
             $map = array();
             $parts = explode('.', $item['xml']['field']);
             $items = array();
             if (2 == count($parts)) {
                 $items = $xml->{$parts[0]}->{$parts[1]};
             }
             foreach ($items as $element) {
                 $map[(string) $element->{$item['xml']['key']}] = (string) $element->{$item['xml']['value']};
             }
             $maps[$key] = $map;
         }
     }
     return $maps;
 }
Example #13
Show file File: simple.php Project: shambhukumar/code
0
/**
 * @param SimpleXMLElement $element
 */
function sxml_show_info(SimpleXMLElement $element)
{
    $isSingleElement = $element[0] == $element;
    $isListOfElements = $element[0] != $element and $element->attributes() !== NULL;
    printf("  Is single-element?   - %s\n", $isSingleElement ? 'Yes' : 'No');
    printf("  Is list-of-elements? - %s\n", $isListOfElements ? 'Yes' : 'No');
}
Example #14
Show file File: Issue.php Project: iseth/php-www
0
 /**
  * Build the XML for an issue
  * @param  array             $params for the new/updated issue data
  * @return \SimpleXMLElement
  */
 private function buildXML(array $params = array())
 {
     $xml = new \SimpleXMLElement('<?xml version="1.0"?><issue></issue>');
     foreach ($params as $k => $v) {
         if ('custom_fields' === $k && is_array($v)) {
             $custom_fields_item = $xml->addChild('custom_fields', '');
             $custom_fields_item->addAttribute('type', 'array');
             foreach ($v as $field) {
                 $item = $custom_fields_item->addChild('custom_field', '');
                 $item->addAttribute('id', (int) $field['id']);
                 $item->addChild('value', $field['value']);
             }
         } elseif ('watcher_user_ids' === $k && is_array($v)) {
             $watcher_user_ids = $xml->addChild('watcher_user_ids', '');
             $watcher_user_ids->addAttribute('type', 'array');
             foreach ($v as $watcher) {
                 $watcher_user_ids->addChild('watcher_user_id', (int) $watcher);
             }
         } elseif ('uploads' === $k && is_array($v)) {
             $uploads_item = $xml->addChild('uploads', '');
             $uploads_item->addAttribute('type', 'array');
             foreach ($v as $upload) {
                 $upload_item = $uploads_item->addChild('upload', '');
                 foreach ($upload as $upload_k => $upload_v) {
                     $upload_item->addChild($upload_k, $upload_v);
                 }
             }
         } else {
             $xml->addChild($k, $v);
         }
     }
     return $xml;
 }
Example #15
Show file File: ApiController.php Project: hukumonline/zfurl
0
 public function indexAction()
 {
     $url = $this->getRequest()->getParam('url');
     $xmlString = '<?xml version="1.0" standalone="yes"?><response></response>';
     $xml = new SimpleXMLElement($xmlString);
     if (strlen($url) < 1) {
         $xml->addChild('status', 'failed no url passed');
     } else {
         $shortid = $this->db->fetchCol("select * from urls where url = ?", $url);
         $config = Zend_Registry::getInstance();
         $sh = $config->get('configuration');
         if ($shortid[0]) {
             $hex = dechex($shortid[0]);
             $short = $sh->siteroot . $hex;
         } else {
             //if not insert then return the id
             $data = array('url' => $url, 'createdate' => date("Y-m-d h:i:s"), 'remoteip' => Pandamp_Lib_Formater::getRealIpAddr());
             $insert = $this->db->insert('urls', $data);
             $id = $this->db->lastInsertId('urls', 'id');
             $hex = dechex($id);
             $short = $sh->siteroot . $hex;
         }
         $xml->addChild('holurl', $short);
         $xml->addChild('status', 'success');
     }
     $out = $xml->asXML();
     //This returns the XML xmlreponse should be key value pairs
     $this->getResponse()->setHeader('Content-Type', 'text/xml')->setBody($out);
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
 }
Example #16
Show file File: EnumerationsTree.php Project: lucianobenetti/clearhealth
0
 function toXml()
 {
     $baseStr = '<?xml version="1.0" standalone="yes"?><tree id="0"></tree>';
     $xml = new SimpleXMLElement($baseStr);
     $currentLevel = array($xml);
     $currentRgt = 0;
     foreach ($this->_tree as $key => $row) {
         if ($key == 0) {
             $currentLevel[0]->addAttribute('lft', $row['lft']);
             $currentLevel[0]->addAttribute('rgt', $row['rgt']);
             continue;
         } elseif ($row['lft'] > $currentLevel[count($currentLevel) - 1]->attributes()->rgt) {
             while ($row['lft'] > $currentLevel[count($currentLevel) - 1]->attributes()->rgt) {
                 array_pop($currentLevel);
             }
         }
         $node = $currentLevel[count($currentLevel) - 1]->addChild('item');
         $node->addAttribute('id', $row['enumerationId']);
         $node->addAttribute('text', $row['name']);
         $node->addAttribute('lft', $row['lft']);
         $node->addAttribute('rgt', $row['rgt']);
         if ($row['rgt'] > $row['lft'] + 1) {
             $node->addAttribute('child', 1);
             array_push($currentLevel, $node);
             $currentRgt = $row['rgt'];
         } elseif ($row['rgt'] + 1 == $currentRgt) {
             array_pop($currentLevel);
             $node->addAttribute('curRgt', $currentLevel[count($currentLevel) - 1]->attributes()->rgt);
         }
     }
     return $xml->asXml();
 }
Example #17
Show file File: AvaTax.php Project: alex974/prestashop-avalaratax
0
/**
* Takes xml as a string and returns it nicely indented
*
* @param string $xml The xml to beautify
* @param boolean $html_output If the xml should be formatted for display on an html page
* @return string The beautified xml
*/
function xml_pretty_printer($xml, $html_output = FALSE)
{
    $xml_obj = new SimpleXMLElement($xml);
    $xml_lines = explode("n", $xml_obj->asXML());
    $indent_level = 0;
    $new_xml_lines = array();
    foreach ($xml_lines as $xml_line) {
        if (preg_match('#(<[a-z0-9:-]+((s+[a-z0-9:-]+="[^"]+")*)?>.*<s*/s*[^>]+>)|(<[a-z0-9:-]+((s+[a-z0-9:-]+="[^"]+")*)?s*/s*>)#i', $xml_line)) {
            $new_line = str_pad('', $indent_level * 4) . $xml_line;
            $new_xml_lines[] = $new_line;
        } elseif (preg_match('#<[a-z0-9:-]+((s+[a-z0-9:-]+="[^"]+")*)?>#i', $xml_line)) {
            $new_line = str_pad('', $indent_level * 4) . $xml_line;
            $indent_level++;
            $new_xml_lines[] = $new_line;
        } elseif (preg_match('#<s*/s*[^>/]+>#i', $xml_line)) {
            $indent_level--;
            if (trim($new_xml_lines[sizeof($new_xml_lines) - 1]) == trim(str_replace("/", "", $xml_line))) {
                $new_xml_lines[sizeof($new_xml_lines) - 1] .= $xml_line;
            } else {
                $new_line = str_pad('', $indent_level * 4) . $xml_line;
                $new_xml_lines[] = $new_line;
            }
        } else {
            $new_line = str_pad('', $indent_level * 4) . $xml_line;
            $new_xml_lines[] = $new_line;
        }
    }
    $xml = join("n", $new_xml_lines);
    return $html_output ? '<pre>' . htmlentities($xml) . '</pre>' : $xml;
}
Example #18
Show file File: ActionDefinition.class.php Project: quantegy/php-cascade-ws-ns
0
 public function __construct(\SimpleXMLElement $action_xml)
 {
     if ($action_xml == NULL) {
         throw new e\EmptyValueException("The xml cannot be empty.");
     }
     if (self::DEBUG && self::DUMP) {
         DebugUtility::dump(u\XMLUtility::replaceBrackets($action_xml->asXML()));
     }
     $this->action_xml = $action_xml;
     $action_attr = $action_xml->attributes();
     $this->identifier = $action_attr->identifier->__toString();
     if ($action_attr->label) {
         $this->label = $action_attr->label->__toString();
     }
     if ($action_attr->move) {
         $this->move = $action_attr->move->__toString();
     } else {
         $this->move = "";
     }
     if ($action_attr->{"next-id"}) {
         $this->next_id = $action_attr->{"next-id"}->__toString();
     } else {
         $this->next_id = "";
     }
     $this->triggers = array();
     if ($this->action_xml->trigger) {
         foreach ($this->action_xml->trigger as $trigger) {
             $this->triggers[] = new TriggerDefinition($trigger);
         }
     }
 }
Example #19
Show file File: CareerBuilder.php Project: robjcordes/nexnewwp
0
 public function _indeed()
 {
     $response = new stdClass();
     $response->complete = false;
     $response->isError = false;
     $request = Daq_Request::getInstance();
     $posted = $request->post("posted_within", 1);
     $country = $request->post("country", "US");
     $location = $request->post("location", "");
     $max = $request->post("max");
     $added = $request->post("added");
     $instance = Wpjb_Project::getInstance();
     $publisher = $instance->getConfig("indeed_publisher");
     $url = "http://api.indeed.com/ads/apisearch?publisher=";
     $url .= $publisher . "&co=" . $country . "&limit=";
     $url .= $max . "&l=" . urlencode($location) . "&fromage=" . $posted;
     $url .= "&q=" . urlencode($request->post("keyword", ""));
     $url .= "&v=2";
     $str = file_get_contents($url);
     $xml = new SimpleXMLElement($str);
     $found = intval($xml->totalresults);
     if ($found < $max) {
         $max = $found;
     }
     if (!$xml->xpath("//result")) {
         $response->complete = true;
         die(json_encode($response));
     }
     try {
         $all = $xml->xpath("//result");
         foreach ($xml->results->result as $r) {
             $keys[] = (string) $r->jobkey;
         }
         for ($i = 0; $i < count($keys); $i++) {
             if ($i != count($keys)) {
                 $key .= $keys[$i] . ",";
             } else {
                 $key .= $keys[$i];
             }
         }
         $url = "http://api.indeed.com/ads/apigetjobs?publisher={$publisher}&jobkeys=" . $key . "&v=2";
         $str = file_get_contents($url);
         $xml = new SimpleXMLElement($str);
         $all = $xml->xpath("//result");
         foreach ($xml->results->result as $r) {
             $added++;
             $response->added = $added;
             self::_insertIndeedJob($r);
         }
     } catch (Exception $e) {
         $response->error = $e->getMessage();
         $response->isError = true;
         die(json_encode($response));
     }
     if ($added >= $max) {
         $response->complete = true;
     }
     $response->max = $max;
     die(json_encode($response));
 }
Example #20
Show file File: controller.php Project: ngreimel/kovent
0
 public function export(\SimpleXMLElement $blockNode)
 {
     $data = $blockNode->addChild('data');
     foreach ($this->getSelectedServices() as $link) {
         $data->addChild('service', $link->getHandle());
     }
 }
Example #21
Show file File: Item.php Project: robihidayat/htmly
0
 public function asXML()
 {
     $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><item></item>', LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_ERR_FATAL);
     $xml->addChild('title', $this->title);
     $xml->addChild('link', $this->url);
     $xml->addChild('description', $this->description);
     foreach ($this->categories as $category) {
         $element = $xml->addChild('category', $category[0]);
         if (isset($category[1])) {
             $element->addAttribute('domain', $category[1]);
         }
     }
     if ($this->guid) {
         $guid = $xml->addChild('guid', $this->guid);
         if ($this->isPermalink) {
             $guid->addAttribute('isPermaLink', 'true');
         }
     }
     if ($this->pubDate !== null) {
         $xml->addChild('pubDate', date(DATE_RSS, $this->pubDate));
     }
     if (is_array($this->enclosure) && count($this->enclosure) == 3) {
         $element = $xml->addChild('enclosure');
         $element->addAttribute('url', $this->enclosure['url']);
         $element->addAttribute('type', $this->enclosure['type']);
         if ($this->enclosure['length']) {
             $element->addAttribute('length', $this->enclosure['length']);
         }
     }
     if (!empty($this->author)) {
         $xml->addChild('author', $this->author);
     }
     return $xml;
 }
Example #22
Show file File: atomicon.plugin.php Project: habari-extras/atomicon
0
 /**
  * Do any wrapper-like things to the Atom feed proper.
  * @param SimpleXMLElement $xml the Atom feed document
  * @return SimpleXMLElement the modified Atom feed document
  */
 public function action_atom_create_wrapper($xml)
 {
     if ($iconurl = Options::get('atomicon_iconurl')) {
         $xml->addChild('icon', $iconurl);
     }
     return $xml;
 }
Example #23
Show file File: JsonLogger.php Project: Ingewikkeld/phing
0
 private function xml2js(SimpleXMLElement $xmlnode, $isRoot = true)
 {
     $jsnode = array();
     if (!$isRoot) {
         if (count($xmlnode->attributes()) > 0) {
             $jsnode["@attribute"] = array();
             foreach ($xmlnode->attributes() as $key => $value) {
                 $jsnode["@attribute"][$key] = (string) $value;
             }
         }
         $textcontent = trim((string) $xmlnode);
         if (count($textcontent) > 0) {
             $jsnode['_'] = $textcontent;
         }
         foreach ($xmlnode->children() as $childxmlnode) {
             $childname = $childxmlnode->getName();
             if (!array_key_exists($childname, $jsnode)) {
                 $jsnode[$childname] = array();
             }
             array_push($jsnode[$childname], $this->xml2js($childxmlnode, false));
         }
         return $jsnode;
     } else {
         $nodename = $xmlnode->getName();
         $jsnode[$nodename] = array();
         array_push($jsnode[$nodename], $this->xml2js($xmlnode, false));
         return json_encode($jsnode, JSON_PRETTY_PRINT);
     }
 }
Example #24
Show file File: rss.php Project: BGCX067/f3site-svn-to-git
0
 function save($file)
 {
     if (!file_exists($file) && !touch($file)) {
         throw new Exception(sprintf('File %s does NOT exist!', $file));
     } elseif (!is_writable($file)) {
         throw new Exception(sprintf('Cannot write to %s - CHMOD it 766!', $file));
     }
     $xml = new SimpleXMLElement('<rss version="2.0" xml:base="' . $this->base . '"></rss>');
     $rss = $xml->addChild('channel');
     $rss->title = $this->title;
     $rss->link = $this->link;
     $rss->description = $this->desc;
     foreach ($this->data as $x) {
         $item = $rss->addChild('item');
         $item->title = $x['title'];
         $item->description = $x['text'];
         $item->link = $x['url'];
         #Optional tags
         if (isset($x['author'])) {
             $item->author = $x['author'];
         }
         if (isset($x['category'])) {
             $item->category = $x['cat'];
         }
         if (isset($x['date'])) {
             $item->pubDate = $x['date'];
         }
         if (isset($x['id'])) {
             $item->id = $x['ID'];
             $item->id['isPermaLink'] = 'false';
         }
     }
     #Save file
     return $xml->asXML($file);
 }
Example #25
Show file File: Settings.php Project: kokkez/shineisp
0
 /**
 * Save the setup data
 * @param array $dbconfig
 * @param array $preferences
 * 
 * <?xml version="1.0" encoding="UTF-8"?>
 		<shineisp>
 			<config>
 				<database>
 					<hostname>localhost</hostname>
 					<db>shineisp</db>
 					<username>shineisp</username>
 					<password>shineisp2013</password>
 				</database>
 			</config>
 		</shineisp>
 */
 public static function saveConfig($dbconfig, $version = null)
 {
     try {
         $xml = new SimpleXMLElement('<shineisp></shineisp>');
         if (!empty($version)) {
             $xml->addAttribute('version', $version);
         }
         $xml->addAttribute('setupdate', date('Ymdhis'));
         $config = $xml->addChild('config');
         // Database Configuration
         $database = $config->addChild('database');
         $database->addChild('hostname', $dbconfig->hostname);
         $database->addChild('username', $dbconfig->username);
         $database->addChild('password', $dbconfig->password);
         $database->addChild('database', $dbconfig->database);
         // Get the xml string
         $xmlstring = $xml->asXML();
         // Prettify and save the xml configuration
         $dom = new DOMDocument();
         $dom->loadXML($xmlstring);
         $dom->formatOutput = true;
         $dom->saveXML();
         // Save the config xml file
         if (@$dom->save(APPLICATION_PATH . "/configs/config.xml")) {
             Shineisp_Commons_Utilities::log("Update ShineISP config xml file");
             return true;
         } else {
             throw new Exception("Error on saving the xml file in " . APPLICATION_PATH . "/configs/config.xml <br/>Please check the folder permissions");
         }
     } catch (Exception $e) {
         throw new Exception($e->getMessage());
     }
     return false;
 }
Example #26
Show file File: ContentSet.php Project: nidzix/Newscoop
0
 /**
  * Set remote content
  *
  * @param SimpleXMLElement $xml
  * @return void
  */
 private function setRemoteContent(\SimpleXMLElement $xml)
 {
     $this->remoteContent = new \Doctrine\Common\Collections\ArrayCollection();
     foreach ($xml->children() as $remoteContentXml) {
         $this->remoteContent->add(RemoteContent::createFromXml($remoteContentXml));
     }
 }
Example #27
Show file File: TokenRegistration.php Project: petflow/litle
0
 /**
  * Litle Request
  */
 private static function litle_request($content)
 {
     $xml = new \SimpleXMLElement($content);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
     curl_setopt($ch, CURLOPT_URL, self::$url);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $xml->asXML());
     curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_SSLVERSION, 3);
     $output = curl_exec($ch);
     $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if (!$output) {
         throw new \Exception(curl_error($ch));
     } else {
         $p = fopen('/data/litle/' . date('Y-m-d\\.H:i:s'), 'w+');
         fwrite($p, $output);
         fclose($p);
         curl_close($ch);
         return $output;
     }
 }
Example #28
Show file File: tumblover.php Project: landsurveyorsunited/tumblover
0
 function maptweets()
 {
     # get recent tweet-format posts
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_USERAGENT, TL_USERAGENT);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_URL, "http://tumblr.com/statuses/home_timeline.xml?count=" . TL_HISTORY);
     curl_setopt($ch, CURLOPT_USERPWD, TL_TUMBLR_USERNAME . ':' . TL_TUMBLR_PASS);
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     $data = curl_exec($ch);
     curl_close($ch);
     # go through each status and resolve the short-url to a full Tumblr ID
     $xml = new SimpleXMLElement($data);
     foreach ($xml->xpath("//status") as $status) {
         $tweet_id = (string) $status->id;
         $content = (string) $status->text;
         preg_match('/(http:\\/\\/tumblr.com\\/[a-z0-9]+)/', $content, $matches);
         $short_url = $matches[1];
         $full_url = $this->resolve_redirects($short_url);
         $tumblr_id = $this->tumblr_id_from_url($full_url);
         if (false !== $tumblr_id) {
             $this->id_map[$tumblr_id] = $tweet_id;
         }
     }
     return !empty($this->id_map);
 }
Example #29
Show file File: Address.php Project: thinkerytim/thinkery-reaxml-parser
0
 public function __construct(\SimpleXMLElement $address, $municipality = false)
 {
     // set display_address
     $this->setDisplayAddress($address->attributes()->display);
     // set site
     $this->setSite((string) $address->site);
     // set subNumber
     $this->setSubNumber((string) $address->subNumber);
     // set lotNumber
     $this->setLotNumber((string) $address->lotNumber);
     // set streetNumber
     $this->setStreetNumber((string) $address->streetNumber);
     // set street
     $this->setStreet((string) $address->street);
     // set suburb
     $this->setSuburb((string) $address->suburb);
     // set municipality
     $this->setMunicipality($municipality);
     // set state
     $this->setState((string) $address->state);
     // set region
     $this->setRegion((string) $address->region);
     // set postcode
     $this->setPostcode((string) $address->postcode);
     // set country
     $this->setCountry((string) $address->country);
 }
Example #30
Show file File: Form.php Project: Hywan/moxl
0
 public function __toString()
 {
     $xml = '<x xmlns="jabber:x:data" type="submit"></x>';
     $node = new \SimpleXMLElement($xml);
     foreach ($this->_data as $key => $value) {
         $field = $node->addChild('field');
         if ($value == 'true') {
             $value = '1';
         }
         if ($value == 'false') {
             $value = '0';
         }
         $field->addChild('value', trim($value->value));
         /*if(isset($value->attributes->required))
           $field->addChild('required', '');*/
         $field->addAttribute('var', $value->attributes->name);
         //$field->addAttribute('type', $value->attributes->type);
         //$field->addAttribute('label', $value->attributes->label);
     }
     $xml = $node->asXML();
     $doc = new \DOMDocument();
     $doc->loadXML($xml);
     $doc->formatOutput = true;
     return substr($doc->saveXML(), strpos($doc->saveXML(), "\n") + 1);
 }