/** -------------------------------------
 	/**  Create XML File
 	/** -------------------------------------*/
 function create_xml()
 {
     global $DSP, $IN, $LANG, $OUT;
     /** -------------------------------------
     		/**  Snag POST data
     		/** -------------------------------------*/
     $member_file = !$IN->GBL('member_file', 'POST') ? '' : $IN->GBL('member_file', 'POST');
     switch ($IN->GBL('delimiter', 'POST')) {
         case 'tab':
             $this->delimiter = "\t";
             break;
         case ',':
             $this->delimiter = ",";
             break;
         case 'other':
             $this->delimiter = $IN->GBL('delimiter_special', 'POST');
     }
     $this->enclosure = !$IN->GBL('enclosure', 'POST') ? '' : $this->prep_enclosure($IN->GBL('enclosure', 'POST'));
     $encrypt = $IN->GBL('encrypt', 'POST') == 'y' ? TRUE : FALSE;
     $type = $IN->GBL('type', 'POST');
     /** -------------------------------------
     		/**  Read file contents
     		/** -------------------------------------*/
     if (function_exists('file_get_contents')) {
         $contents = file_get_contents($member_file);
     } else {
         $fp = fopen($member_file, 'r');
         $contents = fread($fp, filesize($member_file));
         fclose($fp);
     }
     /** -------------------------------------
     		/**  Get structure
     		/** -------------------------------------*/
     $structure = array();
     foreach ($_POST as $key => $val) {
         if (substr($key, 0, 5) == 'field') {
             $structure[] = $val;
         }
     }
     /** -------------------------------------
     		/**  Instantiate EE_XMLparser Class
     		/** -------------------------------------*/
     if (!class_exists('EE_XMLparser')) {
         require PATH_CORE . 'core.xmlparser' . EXT;
     }
     $XML = new EE_XMLparser();
     /** -------------------------------------
     		/**  Convert the data to XML
     		/** -------------------------------------*/
     $params = array('data' => $contents, 'structure' => $structure, 'root' => 'members', 'element' => 'member', 'delimiter' => $this->delimiter, 'enclosure' => $this->enclosure);
     $xml = $XML->delimited_to_xml($params);
     /** -------------------------------------
     		/**  Add type="text" parameter for plaintext passwords
     		/** -------------------------------------*/
     if ($encrypt === TRUE) {
         $xml = str_replace('<password>', '<password type="text">', $xml);
     }
     if (!empty($XML->errors)) {
         $OUT->show_user_error('general', $XML->errors);
         exit;
     }
     /** -------------------------------------
     		/**  Output to browser or download
     		/** -------------------------------------*/
     switch ($type) {
         case 'view':
             $this->view_xml($xml);
             break;
         case 'download':
             $this->download_xml($xml);
             break;
     }
 }
 /**
  * Takes the control panel home page and adds an update method if needed
  *
  * @param	string $out The control panel html
  * @return	string The modified control panel html
  * @since 	Version 1.0.0
  */
 function control_panel_home_page($home)
 {
     global $EXT, $LOC, $SESS;
     $updates = '';
     $updates_available = FALSE;
     // -- Check if we're not the only one using this hook
     if ($EXT->last_call !== FALSE) {
         $home = $EXT->last_call;
     }
     // see if we even need to check for updates
     if ($this->settings['check_for_updates'] == 'n') {
         return $home;
     }
     if (!class_exists('EE_XMLparser')) {
         require PATH_CORE . 'core.xmlparser' . EXT;
     }
     $XML = new EE_XMLparser();
     // valid XML?
     if (($versions = $XML->parse_xml($this->_get_latest_versions())) === FALSE) {
         $updates = "<div class='alert'>LG Addon Updater failed. There may be a problem with some of the addon sources.</div>";
     } else {
         foreach ($versions->children as $addon) {
             $addon_id = $addon->attributes['id'];
             if (isset($SESS->cache['lg'][LG_AU_addon_id]['addons'][$addon_id]) === TRUE && $addon->attributes['version'] > $SESS->cache['lg'][LG_AU_addon_id]['addons'][$addon_id]) {
                 if ($updates_available === FALSE) {
                     $updates_available = TRUE;
                     $updates = "<div class='alert'>Module / extension / plugin updates available:</div><ul class='alert-list'>";
                 }
                 $updates .= "<li><a href='" . $addon->attributes['docs_url'] . "'>" . $addon->attributes['id'] . " v" . $addon->attributes['version'] . "</a> <small>Last Updated: " . $LOC->set_human_time($addon->attributes['last_updated']) . "</small></li>";
             }
         }
         if ($updates_available === TRUE) {
             $updates .= "</ul><style type='text/css' media='screen'>\n#contentNB > .box:first-child .alert{border-top:1px dotted #CCC9A4; margin-top:3px; padding-top:9px;}\n#contentNB > .box:first-child .alert:first-child{border:none; margin:0; padding:0}\n#contentNB > .box:first-child ul.alert-list{margin-bottom:0}\n</style>";
             $home->messages = array_merge($home->messages, array($updates));
         }
     }
     return $home;
 }
 /**
  * Fetch data
  *
  * Checks cache, gets data, writes cache, returns array of parsed xml
  *
  * @access	public
  * @param	string
  * @return	mixed
  */
 function _fetch_data($url)
 {
     global $TMPL;
     $cache_expired = FALSE;
     $url = $this->base_url . $url;
     // Grab the data
     if (($rawxml = $this->_check_cache($url)) === FALSE) {
         $cache_expired = TRUE;
         $TMPL->log_item("Fetching Github data remotely");
         if (function_exists('curl_init')) {
             $rawxml = $this->_curl_fetch($url);
         } else {
             $rawxml = $this->_fsockopen_fetch($url);
         }
     }
     if ($rawxml == '' or substr($rawxml, 0, 5) != "<?xml") {
         // Attempt to use a stale cache?
         if ($this->offline_stale_cache) {
             $rawxml = $this->_check_cache($url, TRUE);
         }
         if ($rawxml == '' or substr($rawxml, 0, 5) != "<?xml") {
             $TMPL->log_item("Github Error: Unable to retrieve data from: " . $url);
             return FALSE;
         }
         // Yucky - stale
         $TMPL->log_item("Github Stale Cache: " . $url);
         $cache_expired = FALSE;
     }
     // Write the cache file if necessary
     if ($cache_expired === TRUE) {
         $this->_write_cache($rawxml, $url);
     }
     // Parse the XML
     if (!class_exists('EE_XMLparser')) {
         require PATH_CORE . 'core.xmlparser' . EXT;
     }
     $XML = new EE_XMLparser();
     // valid XML?
     if (($xml_obj = $XML->parse_xml($rawxml)) === FALSE) {
         $TMPL->log_item("Github Error: Unable to retrieve data from: " . $url);
         return FALSE;
     }
     // Create array from the xml
     $github_data = $this->_parse_xml($xml_obj);
     if (!is_array($github_data) or count($github_data) == 0) {
         return FALSE;
     }
     return $github_data;
 }