Commit 1b3d6beba24ea906b425a7234e6287a8c21d8b9a

Authored by Megan
1 parent af71151c

KTS-4024. Removed the utf8_encode on the paths and files, they are usually already encoded.

"Character garbled issue (For Japanese file names)"
Partially Fixed.

Committed by: Megan Watson 
Reviewed by: Kevin Cyster
Showing 1 changed file with 34 additions and 15 deletions
lib/import/bulkimport.inc.php
... ... @@ -8,31 +8,31 @@
8 8 * Document Management Made Simple
9 9 * Copyright (C) 2008, 2009 KnowledgeTree Inc.
10 10 * Portions copyright The Jam Warehouse Software (Pty) Limited
11   - *
  11 + *
12 12 * This program is free software; you can redistribute it and/or modify it under
13 13 * the terms of the GNU General Public License version 3 as published by the
14 14 * Free Software Foundation.
15   - *
  15 + *
16 16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 19 * details.
20   - *
  20 + *
21 21 * You should have received a copy of the GNU General Public License
22 22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23   - *
24   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  23 + *
  24 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
25 25 * California 94120-7775, or email info@knowledgetree.com.
26   - *
  26 + *
27 27 * The interactive user interfaces in modified source and object code versions
28 28 * of this program must display Appropriate Legal Notices, as required under
29 29 * Section 5 of the GNU General Public License version 3.
30   - *
  30 + *
31 31 * In accordance with Section 7(b) of the GNU General Public License version 3,
32 32 * these Appropriate Legal Notices must retain the display of the "Powered by
33   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  33 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
34 34 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
35   - * must display the words "Powered by KnowledgeTree" and retain the original
  35 + * must display the words "Powered by KnowledgeTree" and retain the original
36 36 * copyright notice.
37 37 * Contributor( s): ______________________________________
38 38 */
... ... @@ -89,9 +89,12 @@ class KTBulkImportManager {
89 89 return $aFolderPaths;
90 90 }
91 91 foreach ($aFolderPaths as $sFolderPath) {
92   - if (Folder::folderExistsName(utf8_encode(basename($sFolderPath)), KTUtil::getId($oFolder))) {
93   - $_SESSION['KTErrorMessage'][] = sprintf(_kt("The folder %s is already present in %s. Adding files into pre-existing folder."), utf8_encode(basename($sFolderPath)), $oFolder->getName());
94   - $aOptions = Folder::getList("parent_id = " . KTUtil::getId($oFolder) . ' AND name = "' . DBUtil::escapeSimple(utf8_encode(basename($sFolderPath))) . '"');
  92 + $sFolderBasePath = basename($sFolderPath);
  93 + $sFolderBasePath = ($this->is_utf8($sFolderBasePath)) ? $sFolderBasePath : utf8_encode($sFolderBasePath);
  94 +
  95 + if (Folder::folderExistsName($sFolderPath, KTUtil::getId($oFolder))) {
  96 + $_SESSION['KTErrorMessage'][] = sprintf(_kt("The folder %s is already present in %s. Adding files into pre-existing folder."), $sFolderBasePath, $oFolder->getName());
  97 + $aOptions = Folder::getList("parent_id = " . KTUtil::getId($oFolder) . ' AND name = "' . DBUtil::escapeSimple($sFolderBasePath) . '"');
95 98 if (PEAR::isError($aOptions)) {
96 99 return $aOptions;
97 100 }
... ... @@ -104,7 +107,7 @@ class KTBulkImportManager {
104 107  
105 108 if(KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $oFolder))
106 109 {
107   - $oThisFolder = KTFolderUtil::add($oFolder, utf8_encode(basename($sFolderPath)), $this->oUser);
  110 + $oThisFolder = KTFolderUtil::add($oFolder, $sFolderBasePath, $this->oUser);
108 111 }
109 112 else
110 113 {
... ... @@ -152,9 +155,25 @@ class KTBulkImportManager {
152 155 'documenttype' => $this->oDocumentType,
153 156 );
154 157 $aOptions = array_merge($aOptions, $this->aOptions);
155   - $oDocument =& KTDocumentUtil::add($oFolder, utf8_encode(basename($sPath)), $this->oUser, $aOptions);
  158 + $sPath = basename($sPath);
  159 + $sPath = ($this->is_utf8($sPath)) ? $sPath : utf8_encode($sPath);
  160 + $oDocument =& KTDocumentUtil::add($oFolder, $sPath, $this->oUser, $aOptions);
156 161 return $oDocument;
157 162 }
  163 +
  164 + function is_utf8($string) {
  165 + // From http://w3.org/International/questions/q ... utf-8.html
  166 + return preg_match('%^(?:
  167 + [\x09\x0A\x0D\x20-\x7E] # ASCII
  168 + | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
  169 + | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
  170 + | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
  171 + | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
  172 + | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
  173 + | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
  174 + | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
  175 + )*$%xs', $string);
  176 + }
158 177 }
159 178  
160 179 -?>
  180 +?>
161 181 \ No newline at end of file
... ...