function error($__error_type, $__error_message) { // Array containing known error-types $valid_error_types = array('Fatal error', 'Warning'); // If not - print a 'Fatal Error' (will terminate the script) if (in_array($__error_type, $valid_error_types) == false) { basic::error('Fatal error', 'Invalid error-type: "' . $__error_type . '" in error()'); } // Write error-message Basic::printToConsole($__error_type . ": " . $__error_message); // If the error is fatal the script will be terminated if ($__error_type == 'Fatal error') { exit; } }
function _startToParse() { //Load php's XML parser $this->xml_parser = xml_parser_create(); xml_set_object($this->xml_parser, $this); //Parser option: Skip whitespace xml_parser_set_option($this->xml_parser, XML_OPTION_SKIP_WHITE, true); //Parser option: Case folding off xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, false); //Set callback functions xml_set_element_handler($this->xml_parser, "_startTagProcessor", "_endTagProcessor"); xml_set_character_data_handler($this->xml_parser, "_charDataProcessor"); //Read XML file if (!($fp = fopen($this->xml_file, 'r'))) { basic::error('Fatal error', "File I/O error: {$this->xml_file}"); } //Parse XML while ($data = fread($fp, 4096)) { //error... :( if (!xml_parse($this->xml_parser, $data, feof($fp))) { $ec = xml_get_error_code($this->xml_parser); basic::error('Fatal error', "XML parser error (error code " . $ec . "): " . xml_error_string($ec) . "\nThe error was found on line: " . xml_get_current_line_number($this->xml_parser)); } } //free your mind, and the rest will follow :) xml_parser_free($this->xml_parser); }
function extract() { Basic::printToConsole("\n\nExtracting the gunzipped file...", false); //Open the downloaded gunzip file if (!($file = gzopen($this->filename . ".u8.gz", "r"))) { basic::error('Fatal error', 'I/O error! Could not open the downloaded file!'); } //Open the file we write to if (!($openfile = fopen($this->filename, 'a'))) { basic::error('Fatal error', 'Cannot open the file (' . $this->filename . ')'); } //Write the data while (!gzeof($file)) { $buff = gzgets($file, 4096); fputs($openfile, $buff); } fclose($openfile); gzclose($file); Basic::printToConsole("\n\n " . strtoupper($this->filename) . ".U8.GZ WAS SUCCESSFUL EXTRACTED! \n Filename: " . $this->filename . "\n"); }