| [ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php # $Id: import.inc.php 1767 2007-07-12 09:36:32Z garvinhicking $ 2 # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team) 3 # All rights reserved. See LICENSE file for licensing details 4 5 if (IN_serendipity !== true) { 6 die ("Don't hack!"); 7 } 8 9 if (!serendipity_checkPermission('adminImport')) { 10 return; 11 } 12 13 /* This won't do anything if safe-mode is ON, but let's try anyway since importing could take a while */ 14 if (function_exists('set_time_limit')) { 15 @set_time_limit(0); 16 } 17 18 /* Class construct. Each importer plugin must extend this class. */ 19 class Serendipity_Import { 20 var $trans_table = ''; 21 var $force_recode = true; 22 /** 23 * Return textual notes of an importer plugin 24 * 25 * If an importer plugin needs to show any notes on the userinterface, those can be returned in this method. 26 * 27 * @access public 28 * @return string HTML-code of a interface/user hint 29 */ 30 function getImportNotes() { 31 return ""; 32 } 33 34 /** 35 * Get a list of available charsets the user can choose from. Depends on current language of the blog. 36 * 37 * @access public 38 * @param boolean If set to true, returns the option "UTF-8" as first select choice, which is then preselected. If false, the current language of the blog will be the default. 39 * @return array Array of available charsets to choose from 40 */ 41 function getCharsets($utf8_default = true) { 42 $charsets = array(); 43 44 if (!$utf8_default) { 45 $charsets['native'] = LANG_CHARSET; 46 } 47 48 if (LANG_CHARSET != 'UTF-8') { 49 $charsets['UTF-8'] = 'UTF-8'; 50 } 51 52 if (LANG_CHARSET != 'ISO-8859-1') { 53 $charsets['ISO-8859-1'] = 'ISO-8859-1'; 54 } 55 56 if ($utf8_default) { 57 $charsets['native'] = LANG_CHARSET; 58 } 59 60 return $charsets; 61 } 62 63 /** 64 * Decodes/Transcodes a string according to the selected charset, and the charset of the blog 65 * 66 * @access public 67 * @param string input string to convert 68 * @return string converted string 69 */ 70 function &decode($string) { 71 // xml_parser_* functions do recoding from ISO-8859-1/UTF-8 72 if (!$this->force_recode && (LANG_CHARSET == 'ISO-8859-1' || LANG_CHARSET == 'UTF-8')) { 73 return $string; 74 } 75 76 $target = $this->data['charset']; 77 78 switch($target) { 79 case 'native': 80 return $string; 81 82 case 'ISO-8859-1': 83 if (function_exists('iconv')) { 84 $out = iconv('ISO-8859-1', LANG_CHARSET, $string); 85 } elseif (function_exists('recode')) { 86 $out = recode('iso-8859-1..' . LANG_CHARSET, $string); 87 } elseif (LANG_CHARSET == 'UTF-8') { 88 return utf8_encode($string); 89 } else { 90 return $string; 91 } 92 return $out; 93 94 case 'UTF-8': 95 default: 96 $out = utf8_decode($string); 97 return $out; 98 } 99 } 100 101 /** 102 * Decode/Transcode a string with the indicated translation table (member property). Useful for transcoding HTML entities to native characters. 103 * 104 * @access public 105 * @param string input string 106 * @return string output string 107 */ 108 function strtr($data) { 109 return strtr($this->decode($data), $this->trans_table); 110 } 111 112 /** 113 * Decode/Transcode an array of strings. 114 * 115 * LONG 116 * 117 * @access public 118 * @see $this->strtr() 119 * @param array input array 120 * @return array output array 121 */ 122 function strtrRecursive($data) { 123 foreach ($data as $key => $val) { 124 if (is_array($val)) { 125 $data[$key] = $this->strtrRecursive($val); 126 } else { 127 $data[$key] = $this->strtr($val); 128 } 129 } 130 131 return $data; 132 } 133 134 /** 135 * Get the transcoding table, depending on whether it was enabled for the instance of the importer plugin 136 * 137 * The member property $this->trans_table will be filled with the output of this function 138 * 139 * @access public 140 * @see $this->strtr() 141 * @return null 142 */ 143 function getTransTable() { 144 if (!serendipity_db_bool($this->data['use_strtr'])) { 145 $this->trans_table = array(); 146 return true; 147 } 148 149 // We need to convert interesting characters to HTML entities, except for those with special relevance to HTML. 150 $this->trans_table = get_html_translation_table(HTML_ENTITIES); 151 foreach (get_html_translation_table(HTML_SPECIALCHARS) as $char => $encoded) { 152 if (isset($this->trans_table[$char])) { 153 unset($this->trans_table[$char]); 154 } 155 } 156 } 157 158 /** 159 * Execute a DB query on the source database of the import, instead of a DB query on the target database 160 * 161 * @access public 162 * @param string SQL Query 163 * @param ressource DB connection resource 164 * @return ressource SQL response 165 */ 166 function &nativeQuery($query, $db = false) { 167 global $serendipity; 168 169 mysql_select_db($this->data['name'], $db); 170 $return = &mysql_query($query, $db); 171 mysql_select_db($serendipity['dbName'], $serendipity['dbConn']); $return = &mysql_query($query, $db); 172 return $return; 173 } 174 } 175 176 if (isset($serendipity['GET']['importFrom']) && serendipity_checkFormToken()) { 177 178 /* Include the importer */ 179 $class = @require_once(S9Y_INCLUDE_PATH . 'include/admin/importers/'. basename($serendipity['GET']['importFrom']) .'.inc.php'); 180 if ( !class_exists($class) ) { 181 die('FAILURE: Unable to require import module, possible syntax error?'); 182 } 183 184 /* Init the importer with form data */ 185 $importer = new $class($serendipity['POST']['import']); 186 187 /* Yes sir, we are importing if we have valid data */ 188 if ( $importer->validateData() ) { 189 echo IMPORT_STARTING . '<br />'; 190 191 /* import() MUST return (bool)true, otherwise we assume it failed */ 192 if ( ($result = $importer->import()) !== true ) { 193 echo IMPORT_FAILED .': '. $result . '<br />'; 194 } else { 195 echo IMPORT_DONE . '<br />'; 196 } 197 198 199 /* Apprently we do not have valid data, ask for some */ 200 } else { 201 ?> 202 203 <?php echo IMPORT_PLEASE_ENTER ?>:<br /> 204 <br /> 205 <form action="" method="POST" enctype="multipart/form-data"> 206 <?php echo serendipity_setFormToken(); ?> 207 <table cellpadding="3" cellspacing="2"> 208 <?php foreach ( $importer->getInputFields() as $field ) { ?> 209 <tr> 210 <td><?php echo $field['text'] ?></td> 211 <td><?php serendipity_guessInput($field['type'], 'serendipity[import]['. $field['name'] .']', (isset($serendipity['POST']['import'][$field['name']]) ? $serendipity['POST']['import'][$field['name']] : $field['default']), $field['default']) ?></td> 212 </tr> 213 <?php } ?> 214 <?php if ($notes = $importer->getImportNotes()){ ?> 215 <tr> 216 <td colspan="2"> 217 <b><?php echo IMPORT_NOTES; ?></b><br /> 218 <?php echo $notes ?> 219 </td> 220 </tr> 221 <?php } ?> 222 <tr> 223 <td colspan="2" align="right"><input type="submit" value="<?php echo IMPORT_NOW ?>" class="serendipityPrettyButton input_button"></td> 224 </tr> 225 </table> 226 </form> 227 <?php 228 } 229 230 } else { 231 232 $importpath = S9Y_INCLUDE_PATH . 'include/admin/importers/'; 233 $dir = opendir($importpath); 234 $list = array(); 235 while (($file = readdir($dir)) !== false ) { 236 if (!is_file($importpath . $file) || !preg_match('@.php$@', $file)) { 237 continue; 238 } 239 240 $class = include_once($importpath . $file); 241 if ( class_exists($class) ) { 242 $tmpClass = new $class(array()); 243 $list[substr($file, 0, strpos($file, '.'))] = $tmpClass->info['software']; 244 unset($tmpClass); 245 } 246 } 247 closedir($dir); 248 ksort($list); 249 ?> 250 <?php echo IMPORT_WELCOME ?>.<br /> 251 <?php echo IMPORT_WHAT_CAN ?>. <br /> 252 <br /> 253 <?php echo IMPORT_SELECT ?>:<br /> 254 <br /> 255 <form action="" method="GET"> 256 <input type="hidden" name="serendipity[adminModule]" value="import"> 257 <?php echo serendipity_setFormToken(); ?> 258 <strong><?php echo IMPORT_WEBLOG_APP ?>: </strong> 259 <select name="serendipity[importFrom]"> 260 <?php foreach ($list as $v=>$k) { ?> 261 <option value="<?php echo $v ?>"><?php echo $k ?></option> 262 <?php } ?> 263 </select> 264 <input type="submit" value="<?php echo GO ?>" class="serendipityPrettyButton input_button"> 265 </form> 266 <?php 267 } 268 269 /* vim: set sts=4 ts=4 expandtab : */
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sat Nov 24 09:00:37 2007 | par Balluche grâce à PHPXref 0.7 |
|