![]() |
|---|
| [ Index ] |
Source Code Reference for V1.00 |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: install.inc.php,v 1.2.2.2 2007/02/26 21:04:48 merlinyoda Exp $ 3 4 if (!defined('W2P_BASE_DIR')) { 5 die('You should not access this file directly.'); 6 } 7 8 // Provide fake interface classes and installation functions 9 // so that most db shortcuts will work without, for example, an AppUI instance. 10 11 // Defines required by setMsg, these are different to those used by the real CAppUI. 12 13 define('UI_MSG_OK', ''); 14 define('UI_MSG_ALERT', 'Warning: '); 15 define('UI_MSG_WARNING', 'Warning: '); 16 define('UI_MSG_ERROR', 'ERROR: '); 17 # 18 # function to output a message 19 # currently just outputs it expecting there to be a pre block. 20 # but could be changed to format it better - and only needs to be done here. 21 # The flush is called so that the user gets progress as it occurs. It depends 22 # upon the webserver/browser combination though. 23 # 24 function w2Pmsg($msg) { 25 echo $msg . "\n"; 26 flush(); 27 } 28 29 # 30 # function to return a default value if a variable is not set 31 # 32 33 function InstallDefVal($var, $def) { 34 return isset($var) ? $var : $def; 35 } 36 37 /** 38 * Utility function to return a value from a named array or a specified default 39 */ 40 function w2PInstallGetParam(&$arr, $name, $def = null) { 41 return isset($arr[$name]) ? $arr[$name] : $def; 42 } 43 44 /** 45 * Utility function to get last updated dates/versions for the 46 * system. The default is to 47 */ 48 function InstallGetVersion($mode, $db) { 49 $result = array('last_db_update' => '', 'last_code_update' => '', 'code_version' => '1.0.2', 'db_version' => '1'); 50 $res = $db->Execute('SELECT * FROM w2pversion LIMIT 1'); 51 if ($res && $res->RecordCount() > 0) { 52 $row = $res->FetchRow(); 53 $result['last_db_update'] = str_replace('-', '', $row['last_db_update']); 54 $result['last_code_update'] = str_replace('-', '', $row['last_code_update']); 55 $result['code_version'] = $row['code_version'] ? $row['code_version'] : '1.0.2'; 56 $result['db_version'] = $row['db_version'] ? $row['db_version'] : '1'; 57 } 58 return $result; 59 60 } 61 62 /* 63 * Utility function to split given SQL-Code 64 * @param $sql string SQL-Code 65 * @param $last_update string last update that has been installed 66 */ 67 function InstallSplitSql($sql, $last_update) { 68 global $lastDBUpdate; 69 70 $buffer = array(); 71 $ret = array(); 72 73 $sql = trim($sql); 74 75 $matched = preg_match_all('/\n#\s*(\d{8})\b/', $sql, $matches); 76 if ($matched) { 77 // Used for updating from previous versions, even if the update 78 // is not correctly set. 79 $len = count($matches[0]); 80 $lastDBUpdate = $matches[1][$len - 1]; 81 } 82 83 if ($last_update && $last_update != '00000000') { 84 // Find the first occurrance of an update that is 85 // greater than the last_update number. 86 w2Pmsg("Checking for previous updates"); 87 if ($matched) { 88 for ($i = 0; $i < $len; $i++) { 89 if ((int)$last_update < (int)$matches[1][$i]) { 90 // Remove the SQL up to the point found 91 $match = '/^.*' . trim($matches[0][$i]) . '/Us'; 92 $sql = preg_replace($match, "", $sql); 93 break; 94 } 95 } 96 // If we run out of indicators, we need to debunk, otherwise we will reinstall 97 if ($i == $len) 98 return $ret; 99 } 100 } 101 $sql = ereg_replace("\n#[^\n]*\n", "\n", $sql); 102 103 $in_string = false; 104 105 for ($i = 0; $i < strlen($sql) - 1; $i++) { 106 if ($sql[$i] == ";" && !$in_string) { 107 $ret[] = substr($sql, 0, $i); 108 $sql = substr($sql, $i + 1); 109 $i = 0; 110 } 111 112 if ($in_string && ($sql[$i] == $in_string) && $buffer[1] != "\\") { 113 $in_string = false; 114 } elseif (!$in_string && ($sql[$i] == '"' || $sql[$i] == "'") && (!isset($buffer[0]) || $buffer[0] != "\\")) { 115 $in_string = $sql[$i]; 116 } 117 if (isset($buffer[1])) { 118 $buffer[0] = $buffer[1]; 119 } 120 $buffer[1] = $sql[$i]; 121 } 122 123 if (!empty($sql)) { 124 $ret[] = $sql; 125 } 126 return ($ret); 127 } 128 129 function InstallLoadSQL($sqlfile, $last_update = null) { 130 global $dbErr, $dbMsg, $db; 131 132 // Don't complain about missing files. 133 if (!file_exists($sqlfile)) 134 return; 135 136 $mqr = @get_magic_quotes_runtime(); 137 @set_magic_quotes_runtime(0); 138 139 $pieces = array(); 140 if ($sqlfile) { 141 $query = fread(fopen($sqlfile, "r"), filesize($sqlfile)); 142 $pieces = InstallSplitSql($query, $last_update); 143 } 144 145 @set_magic_quotes_runtime($mqr); 146 $errors = 0; 147 $piece_count = count($pieces); 148 149 for ($i = 0; $i < $piece_count; $i++) { 150 $pieces[$i] = trim($pieces[$i]); 151 if (!empty($pieces[$i]) && $pieces[$i] != "#") { 152 if (!$result = $db->Execute($pieces[$i])) { 153 $errors++; 154 $dbErr = true; 155 $dbMsg .= $db->ErrorMsg() . '<br>'; 156 } 157 } 158 } 159 w2Pmsg("There were $errors errors in $piece_count SQL statements"); 160 } 161 162 class InstallerUI { 163 164 var $user_id = 0; 165 166 function setMsg($msg, $msgno = '', $append = false) { 167 return w2Pmsg($msgno . $msg); 168 } 169 } 170 171 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Jul 17 03:00:04 2010 | Cross-referenced by PHPXref 0.7 |