force_recode && (LANG_CHARSET == 'ISO-8859-1' || LANG_CHARSET == 'UTF-8')) {
return $string;
}
$target = $this->data['charset'];
switch($target) {
case 'native':
return $string;
case 'ISO-8859-1':
if (function_exists('iconv')) {
$out = iconv('ISO-8859-1', LANG_CHARSET, $string);
} elseif (function_exists('recode')) {
$out = recode('iso-8859-1..' . LANG_CHARSET, $string);
} elseif (LANG_CHARSET == 'UTF-8') {
return utf8_encode($string);
} else {
return $string;
}
return $out;
case 'UTF-8':
default:
$out = utf8_decode($string);
return $out;
}
}
/**
* Decode/Transcode a string with the indicated translation table (member property). Useful for transcoding HTML entities to native characters.
*
* @access public
* @param string input string
* @return string output string
*/
function strtr($data) {
return strtr($this->decode($data), $this->trans_table);
}
/**
* Decode/Transcode an array of strings.
*
* LONG
*
* @access public
* @see $this->strtr()
* @param array input array
* @return array output array
*/
function strtrRecursive($data) {
foreach ($data as $key => $val) {
if (is_array($val)) {
$data[$key] = $this->strtrRecursive($val);
} else {
$data[$key] = $this->strtr($val);
}
}
return $data;
}
/**
* Get the transcoding table, depending on whether it was enabled for the instance of the importer plugin
*
* The member property $this->trans_table will be filled with the output of this function
*
* @access public
* @see $this->strtr()
* @return null
*/
function getTransTable() {
if (!serendipity_db_bool($this->data['use_strtr'])) {
$this->trans_table = array();
return true;
}
// We need to convert interesting characters to HTML entities, except for those with special relevance to HTML.
$this->trans_table = get_html_translation_table(HTML_ENTITIES);
foreach (get_html_translation_table(HTML_SPECIALCHARS) as $char => $encoded) {
if (isset($this->trans_table[$char])) {
unset($this->trans_table[$char]);
}
}
}
/**
* Execute a DB query on the source database of the import, instead of a DB query on the target database
*
* @access public
* @param string SQL Query
* @param ressource DB connection resource
* @return ressource SQL response
*/
function &nativeQuery($query, $db = false) {
global $serendipity;
mysql_select_db($this->data['name'], $db);
$return = &mysql_query($query, $db);
mysql_select_db($serendipity['dbName'], $serendipity['dbConn']); $return = &mysql_query($query, $db);
return $return;
}
}
if (isset($serendipity['GET']['importFrom']) && serendipity_checkFormToken()) {
/* Include the importer */
$class = @require_once(S9Y_INCLUDE_PATH . 'include/admin/importers/'. basename($serendipity['GET']['importFrom']) .'.inc.php');
if ( !class_exists($class) ) {
die('FAILURE: Unable to require import module, possible syntax error?');
}
/* Init the importer with form data */
$importer = new $class($serendipity['POST']['import']);
/* Yes sir, we are importing if we have valid data */
if ( $importer->validateData() ) {
echo IMPORT_STARTING . '
';
/* import() MUST return (bool)true, otherwise we assume it failed */
if ( ($result = $importer->import()) !== true ) {
echo IMPORT_FAILED .': '. $result . '
';
} else {
echo IMPORT_DONE . '
';
}
/* Apprently we do not have valid data, ask for some */
} else {
?>
: