function actionSave()
 {
     echo 'Saving the XML STRING in the TEMP folder<br /><br />';
     $xml = new YDXml();
     $xml->loadString($this->contents);
     $xml->save(YD_DIR_TEMP . '/xml_save_' . date('H_i_s') . '.xml');
     echo 'Done. <a href="../YDFramework2/temp/xml_save_' . date('H_i_s') . '.xml">' . YD_DIR_TEMP . '/xml_save_' . date('H_i_s') . '.xml</a>';
 }
 /**
  *	This function will return the feed in the specified format. The following formats are recognized: RSS0.91,
  *	RSS1.0, RSS2.0, ATOM
  *
  *	@remark
  *		The default format is "RSS2.0". If you specify no argument indicating the requested format, the "RSS2.0"
  *		format will be used.
  *
  *	@param $format	(optional) The format in which the items should be converted.
  *
  *	@returns	String with the data in the requested format.
  */
 function toXml($format = 'RSS2.0')
 {
     // Convert the format to uppercase
     $format = strtoupper($format);
     // Check if the format is an allowed one
     if (!in_array($format, array('RSS0.91', 'RSS1.0', 'RSS2.0', 'ATOM'))) {
         trigger_error('The YDFeedCreator does not support the format called "' . $format . '". Only the formats "RSS0.91"' . ', "RSS1.0", "RSS2.0" and "ATOM" are supported.', YD_ERROR);
     }
     $xml = new YDXml();
     $xml->encoding = $this->_encoding;
     // Formatter for RSS 0.91
     if ($format == 'RSS0.91' || $format == 'RSS2.0') {
         $feed['rss'][0]['#'] = array();
         if ($format == 'RSS0.91') {
             $feed['rss'][0]['@']['version'] = '0.91';
         } else {
             $feed['rss'][0]['@']['version'] = '2.0';
         }
         $feed['rss'][0]['#']['channel'][0]['#'] = array();
         $channel =& $feed['rss'][0]['#']['channel'][0]['#'];
         $channel['title'][0]['#'] = $this->_title;
         if (!empty($this->_description)) {
             $channel['description'][0]['#'] = $this->_description;
         }
         $channel['link'][0]['#'] = $this->_link;
         $channel['generator'][0]['#'] = $this->_generator;
         $i = 0;
         foreach ($this->_items as $arr) {
             $channel['item'][$i]['#'] = array();
             $item =& $channel['item'][$i]['#'];
             $item['title'][0]['#'] = $arr['title'];
             $item['link'][0]['#'] = $arr['link'];
             $item['guid'][0]['#'] = $arr['guid'];
             $item['guid'][0]['@']['isPermanlink'] = 'false';
             if (!is_null($arr['comments'])) {
                 $item['comments'] = $arr['comments'];
             }
             if (!empty($arr['description'])) {
                 $item['description'] = $arr['description'];
             }
             if ($format == 'RSS2.0' && !is_null($arr['enclosure'])) {
                 $item['enclosure'][0]['@']['url'] = $arr['enclosure'];
                 $item['enclosure'][0]['@']['length'] = $arr['enclosure_size'];
                 $item['enclosure'][0]['@']['type'] = $arr['enclosure_type'];
             }
             $i++;
         }
     }
     // Formatter for RSS1.0
     if ($format == 'RSS1.0') {
         $feed['rdf:RDF'][0]['#'] = array();
         $feed['rdf:RDF'][0]['@']['xmlns'] = "http://purl.org/rss/1.0/";
         $feed['rdf:RDF'][0]['@']['xmlns:rdf'] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
         $feed['rdf:RDF'][0]['@']['xmlns:dc'] = "http://purl.org/dc/elements/1.1/";
         $feed['rdf:RDF'][0]['#']['channel'][0]['#'] = array();
         $feed['rdf:RDF'][0]['#']['channel'][0]['@']['rdf:about'] = '';
         $channel =& $feed['rdf:RDF'][0]['#']['channel'][0]['#'];
         $channel['title'][0]['#'] = $this->_title;
         $channel['description'][0]['#'] = $this->_description;
         $channel['link'][0]['#'] = $this->_link;
         $channel['items'][0]['#']['rdf:Seq'][0]['#'] = array();
         $i = 0;
         foreach ($this->_items as $item) {
             $li =& $channel['items'][0]['#']['rdf:Seq'][0]['#']['rdf:li'][$i];
             $li['@']['rdf:resource'] = $item['link'];
             $i++;
         }
         $i = 0;
         foreach ($this->_items as $arr) {
             $rss['rdf:RDF'][0]['#']['item'][$i]['@']['rdf:about'] = $arr['link'];
             $item =& $feed['rdf:RDF'][0]['#']['item'][$i]['#'];
             $item['dc:format'][0]['#'] = 'text/html';
             $item['title'][0]['#'] = $arr['title'];
             $item['link'][0]['#'] = $arr['link'];
             if (!empty($arr['description'])) {
                 $item['description'][0]['#'] = $arr['description'];
             }
             $i++;
         }
     }
     // Formatter for ATOM
     if ($format == 'ATOM') {
         $feed['feed'][0]['#'] = array();
         $feed['feed'][0]['@']['version'] = "0.3";
         $feed['feed'][0]['@']['xmlns'] = "http://purl.org/atom/ns#";
         $feed['feed'][0]['#']['title'][0]['#'] = $this->_title;
         if (!empty($this->_description)) {
             $feed['feed'][0]['#']['tagline'][0]['#'] = $this->_description;
         }
         $feed['feed'][0]['#']['link'][0]['@']['rel'] = 'alternate';
         $feed['feed'][0]['#']['link'][0]['@']['type'] = 'text/html';
         $feed['feed'][0]['#']['link'][0]['@']['href'] = $this->_link;
         $feed['feed'][0]['#']['id'][0]['#'] = $this->_link;
         $feed['feed'][0]['#']['generator'][0]['#'] = $this->_generator;
         $i = 0;
         foreach ($this->_items as $arr) {
             $item =& $feed['feed'][0]['#']['entry'][$i]['#'];
             $item['title'][0]['#'] = $arr['title'];
             $item['link'][0]['@']['rel'] = 'alternate';
             $item['link'][0]['@']['type'] = 'text/html';
             $item['link'][0]['@']['href'] = $arr['link'];
             $item['id'][0]['#'] = $arr['guid'];
             if (!empty($arr['description'])) {
                 $item['content'][0]['@']['type'] = 'text/html';
                 $item['content'][0]['@']['mode'] = 'escaped';
                 $item['content'][0]['@']['xml:base'] = $arr['link'];
                 $item['content'][0]['#'] = '<![CDATA[' . $arr['description'] . ']]>';
             }
             if (!is_null($arr['enclosure'])) {
                 $item['link'][0]['@']['rel'] = 'enclosure';
                 $item['link'][0]['@']['href'] = $arr['enclosure'];
                 $item['link'][0]['@']['length'] = $arr['enclosure_size'];
                 $item['link'][0]['@']['type'] = $arr['enclosure_type'];
             }
             $i++;
         }
     }
     $xml->loadArray($feed);
     $xml->encoding = $this->_encoding;
     return $xml->toString();
 }
 /**
  *  This function will parse the contents of a render and return
  *  a new YDForm object.
  *
  *  @returns    A YDForm object.
  */
 function import($content, $options = array())
 {
     $class = isset($options['class']) ? $options['class'] : 'YDForm';
     $type = isset($options['type']) ? $options['type'] : YD_XML_STRING;
     $xml = new YDXml($content, $type);
     $arr = $xml->toArray();
     // Form Name, Method, Action, Target
     $f_name = $arr['form'][0]['@']['name'];
     $f_method = $arr['form'][0]['@']['method'];
     $f_action = $arr['form'][0]['@']['action'];
     $f_target = $arr['form'][0]['@']['target'];
     $f_legend = $arr['form'][0]['@']['legend'];
     // References
     $form =& $arr['form'][0]['#'];
     $attr =& $form['attributes'][0]['#'];
     $elem =& $form['elements'][0]['#'];
     $rule =& $form['rules'][0]['#'];
     $comp =& $form['comparerules'][0]['#'];
     $frul =& $form['formrules'][0]['#'];
     $filt =& $form['filters'][0]['#'];
     $r_elem =& $form['registered'][0]['#']['elements'][0]['#'];
     $r_filt =& $form['registered'][0]['#']['filters'][0]['#'];
     $r_rule =& $form['registered'][0]['#']['rules'][0]['#'];
     $r_rend =& $form['registered'][0]['#']['renderers'][0]['#'];
     // Attributes
     $f_attr = array();
     if (is_array($attr)) {
         $attr =& $attr['attribute'];
         for ($i = 0; $i < count($attr); $i++) {
             $f_attr[$attr[$i]['@']['name']] = $attr[$i]['@']['value'];
         }
     }
     // YDForm object
     $f = new $class($f_name, $f_method, $f_action, $f_target, $f_attr);
     $f->setLegend($f_legend);
     // Elements
     if (is_array($elem)) {
         $elem =& $elem['element'];
         for ($i = 0; $i < count($elem); $i++) {
             // Name, Type, Label, Value
             $name = $elem[$i]['@']['name'];
             $type = $elem[$i]['@']['type'];
             $label = $elem[$i]['#']['labels'][0]['#']['label'][0]['@']['value'];
             $value = $elem[$i]['#']['values'][0]['#']['value'][0]['@']['value'];
             // Attributes
             $attributes = array();
             $attr =& $elem[$i]['#']['attributes'][0]['#'];
             if (is_array($attr)) {
                 $attr =& $attr['attribute'];
                 for ($j = 0; $j < count($attr); $j++) {
                     $attributes[$attr[$j]['@']['name']] = $attr[$j]['@']['value'];
                 }
             }
             // Options
             $options = array();
             $opts =& $elem[$i]['#']['options'][0]['#'];
             if (is_array($opts)) {
                 $opts =& $opts['option'];
                 for ($j = 0; $j < count($opts); $j++) {
                     $options[$opts[$j]['@']['name']] = $opts[$j]['@']['value'];
                 }
             }
             // Add
             $e =& $f->addElement($type, $name, $label, $attributes, $options);
             $e->setValue($value);
         }
     }
     // Rules
     if (is_array($rule)) {
         $rule =& $rule['rule'];
         for ($i = 0; $i < count($rule); $i++) {
             // Element, Type, Error
             $element = $rule[$i]['@']['element'];
             $type = $rule[$i]['@']['type'];
             $error = $rule[$i]['#']['errors'][0]['#']['error'][0]['@']['value'];
             // Options
             $options = array();
             $opts =& $rule[$i]['#']['options'][0]['#'];
             if (is_array($opts)) {
                 $opts =& $opts['option'];
                 for ($j = 0; $j < count($opts); $j++) {
                     if ($opts[$j]['@']['serialized'] == 'true') {
                         $opts[$j]['@']['value'] = YDObjectUtil::unserialize($opts[$j]['@']['value']);
                     }
                     if ($opts[$j]['@']['id'] == '') {
                         $options = $opts[$j]['@']['value'];
                     } else {
                         $options[$opts[$j]['@']['id']] = $opts[$j]['@']['value'];
                     }
                 }
             }
             // Add
             $f->addRule($element, $type, $error, $options);
         }
     }
     // Compare Rules
     if (is_array($comp)) {
         $comp =& $comp['rule'];
         for ($i = 0; $i < count($comp); $i++) {
             // Type, Error
             $type = $comp[$i]['@']['type'];
             $error = $comp[$i]['#']['errors'][0]['#']['error'][0]['@']['value'];
             // Elements
             $elements = array();
             $elem =& $comp[$i]['#']['elements'][0]['#'];
             if (is_array($elem)) {
                 $elem =& $elem['element'];
                 for ($j = 0; $j < count($elem); $j++) {
                     $elements[] = $elem[$j]['@']['name'];
                 }
             }
             // Add
             $f->addCompareRule($elements, $type, $error);
         }
     }
     // Form Rules
     if (is_array($frul)) {
         $frul =& $frul['rule'];
         for ($i = 0; $i < count($frul); $i++) {
             // Callback
             $callback = $frul[$i]['@']['callback'];
             if (strpos($callback, '::') !== false) {
                 $c = explode('::', $callback);
                 $callback = array($c[0], $c[1]);
             }
             // Add
             $f->addFormRule($callback);
         }
     }
     // Filters
     if (is_array($filt)) {
         $filt =& $filt['element'];
         for ($i = 0; $i < count($filt); $i++) {
             // Element, Type
             $element = $filt[$i]['@']['name'];
             $type = $filt[$i]['@']['filter'];
             // Add
             $f->addFilter($element, $type);
         }
     }
     // Registered Elements
     if (is_array($r_elem)) {
         $r_elem =& $r_elem['element'];
         for ($i = 0; $i < count($r_elem); $i++) {
             // Name, Class, File
             $name = $r_elem[$i]['@']['name'];
             $class = $r_elem[$i]['@']['class'];
             $file = $r_elem[$i]['@']['file'];
             // Add
             $f->registerElement($name, $class, $file);
         }
     }
     // Registered Renderers
     if (is_array($r_rend)) {
         $r_rend =& $r_rend['renderer'];
         for ($i = 0; $i < count($r_rend); $i++) {
             // Name, Class, File
             $name = $r_rend[$i]['@']['name'];
             $class = $r_rend[$i]['@']['class'];
             $file = $r_rend[$i]['@']['file'];
             // Add
             $f->registerRenderer($name, $class, $file);
         }
     }
     // Registered Filters
     if (is_array($r_filt)) {
         $r_filt =& $r_filt['filter'];
         for ($i = 0; $i < count($r_filt); $i++) {
             // Name, File
             $name = $r_filt[$i]['@']['name'];
             $file = $r_filt[$i]['@']['file'];
             // Callback
             $callback = $r_filt[$i]['@']['callback'];
             if (strpos($callback, '::') !== false) {
                 $c = explode('::', $callback);
                 $callback = array($c[0], $c[1]);
             }
             // Add
             $f->registerFilter($name, $callback, $file);
         }
     }
     // Registered Rules
     if (is_array($r_rule)) {
         $r_rule =& $r_rule['rule'];
         for ($i = 0; $i < count($r_rule); $i++) {
             // Name, File
             $name = $r_rule[$i]['@']['name'];
             $file = $r_rule[$i]['@']['file'];
             // Callback
             $callback = $r_rule[$i]['@']['callback'];
             if (strpos($callback, '::') !== false) {
                 $c = explode('::', $callback);
                 $callback = array($c[0], $c[1]);
             }
             // Add
             $f->registerFilter($name, $callback, $file);
         }
     }
     return $f;
 }
 /**
  *  This function returns the XML as a string representation of the array
  *  returned by toArray.
  *
  *  @param $array  (Optional) The array to traverse. If null, the result from
  *                 toArray of the current object. Default: null.
  *  @param $name   (Optional) The name of the array. Default: array.
  *  @param $level  (Optional) The level of parsing the array.
  *
  *  @returns  A string representation of the array returned by toArray.
  *
  *  @static  If $array is passed.
  */
 function traverse($array = null, $name = 'array', $level = 0)
 {
     if (is_null($array)) {
         $array = $this->toArray();
     }
     $traverse = array();
     if (is_array($array)) {
         foreach ($array as $key => $val) {
             if (is_array($val)) {
                 $traverse = array_merge($traverse, YDXml::traverse($val, $name . "[" . $key . "]", $level + 1));
             } else {
                 $traverse[] = '$' . $name . '[' . $key . '] = "' . str_replace("\n", "", trim($val)) . "\"\n";
             }
         }
     }
     return implode('', $traverse);
 }