diff --git a/upload/source/class/table/table_common_style.php b/upload/source/class/table/table_common_style.php index 6050492fa61891ebf31abaa4686c52995505862d..2f9007f5a52c8d02e28298e1257c34c2d6c5c6e2 100644 --- a/upload/source/class/table/table_common_style.php +++ b/upload/source/class/table/table_common_style.php @@ -39,6 +39,14 @@ class table_common_style extends discuz_table return DB::result_first("SELECT COUNT(*) FROM %t WHERE name=%s", array($this->_table, $stylename)); } + public function fetch_by_stylename_templateid($stylename, $templateid = 0) { + if($templateid) { + return DB::fetch_first("SELECT * FROM %t WHERE name=%s AND templateid=%d ORDER BY styleid ASC LIMIT 1", array($this->_table, $stylename, $templateid)); + }else{ + return DB::fetch_first("SELECT * FROM %t WHERE name=%s ORDER BY styleid ASC LIMIT 1", array($this->_table, $stylename)); + } + } + } ?> \ No newline at end of file diff --git a/upload/source/class/table/table_common_template.php b/upload/source/class/table/table_common_template.php index f643479a413d1c37ee31a4049dc8e767a98ac0c2..44493bdb7992add80e410029130268c19225312a 100644 --- a/upload/source/class/table/table_common_template.php +++ b/upload/source/class/table/table_common_template.php @@ -36,6 +36,14 @@ class table_common_template extends discuz_table return DB::result_first("SELECT templateid FROM %t WHERE name=%s", array($this->_table, $name)); } + public function get_templateid_by_directory($directory) { + return DB::result_first("SELECT templateid FROM %t WHERE directory=%s", array($this->_table, $directory)); + } + + public function fetch_by_templateid($templateid) { + return DB::fetch_first("SELECT * FROM %t WHERE templateid=%s", array($this->_table, $templateid)); + } + } ?> \ No newline at end of file diff --git a/upload/source/function/function_importdata.php b/upload/source/function/function_importdata.php index 27e727e1f7f9cf794d85571988109e0c99a805c7..a2916521237b201bf1596469b303a8b2722a5d4a 100644 --- a/upload/source/function/function_importdata.php +++ b/upload/source/function/function_importdata.php @@ -70,7 +70,7 @@ function import_styles($ignoreversion = 1, $dir = '', $restoreid = 0, $updatecac if(empty($ignoreversion) && !versioncompatible($stylearray['version'])) { cpmsg('styles_import_version_invalid', 'action=styles', 'error', array('cur_version' => $stylearray['version'], 'set_version' => $_G['setting']['version'])); } - + $styleidnew = 0; if(!$restoreid) { $renamed = 0; if($stylearray['templateid'] != 1) { @@ -81,8 +81,11 @@ function import_styles($ignoreversion = 1, $dir = '', $restoreid = 0, $updatecac cpmsg('styles_import_directory_invalid', 'action=styles', 'error', array('basedir' => $basedir, 'directory' => $stylearray['directory'])); } } - - if(!($templateid = C::t('common_template')->get_templateid($stylearray['tplname']))) { + $templateid = C::t('common_template')->get_templateid_by_directory($stylearray['directory']); + if (!$templateid) { + $templateid = C::t('common_template')->get_templateid($stylearray['tplname']); + } + if(!$templateid) { $templateid = C::t('common_template')->insert(array( 'name' => $stylearray['tplname'], 'directory' => $stylearray['directory'], @@ -95,6 +98,25 @@ function import_styles($ignoreversion = 1, $dir = '', $restoreid = 0, $updatecac if(C::t('common_style')->check_stylename($stylearray['name'])) { $renamed = 1; + $styleinfo = C::t('common_style')->fetch_by_stylename_templateid($stylearray['name']); + if(!empty($styleinfo['styleid'])) { + if($styleinfo['templateid'] != $templateid) { + $template = C::t('common_template')->fetch_by_templateid($styleinfo['templateid']); + if (empty($template)) { + C::t('common_style')->update($styleinfo['styleid'], array('templateid' => $templateid), true); + $styleidnew = $styleinfo['styleid']; + }else{ + $styleinfo = C::t('common_style')->fetch_by_stylename_templateid($stylearray['name'], $templateid); + if(!empty($styleinfo['styleid'])) { + $styleidnew = $styleinfo['styleid']; + }else{ + $styleidnew = C::t('common_style')->insert(array('name' => $stylearray['name'], 'templateid' => $templateid), true); + } + } + }else{ + $styleidnew = $styleinfo['styleid']; + } + } } else { $styleidnew = C::t('common_style')->insert(array('name' => $stylearray['name'], 'templateid' => $templateid), true); } @@ -103,9 +125,20 @@ function import_styles($ignoreversion = 1, $dir = '', $restoreid = 0, $updatecac C::t('common_stylevar')->delete_by_styleid($styleidnew); } - foreach($stylearray['style'] as $variable => $substitute) { - $substitute = @dhtmlspecialchars($substitute); - C::t('common_stylevar')->insert(array('styleid' => $styleidnew, 'variable' => $variable, 'substitute' => $substitute)); + if($styleidnew) { + $stylevars = array(); + $result = C::t('common_stylevar')->fetch_all_by_styleid($styleidnew); + if(is_array($result) && !empty($result)) { + foreach($result as $style) { + $stylevars[$style['variable']] = $style['substitute']; + } + } + foreach($stylearray['style'] as $variable => $substitute) { + if(!isset($stylevars[$variable])) { + $substitute = @dhtmlspecialchars($substitute); + C::t('common_stylevar')->insert(array('styleid' => $styleidnew, 'variable' => $variable, 'substitute' => $substitute)); + } + } } }