Commit b16917d844df6979aa19821c5b4367ae1ac5a9e8

Authored by kevin_fourie
1 parent e3634044

Merged in from DEV trunk...

KTS-2642
"Improve magicDatabase path detection"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Megan Watson

KTS-2828
"Mime types of Microsoft Office documents are being resolved incorrectly as binary files that cannot be indexed"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Megan Watson

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@7983 c91229c3-7414-0410-bfa2-8a42b809f60b
config/dmsDefaults.php
... ... @@ -182,10 +182,12 @@ class KTInit {
182 182  
183 183 $oKTConfig =& KTConfig::getSingleton();
184 184  
  185 + $prefix = defined('USE_DB_ADMIN_USER')?'Admin':'';
  186 +
185 187 $dsn = array(
186 188 'phptype' => $oKTConfig->get('db/dbType'),
187   - 'username' => $oKTConfig->get('db/dbUser'),
188   - 'password' => $oKTConfig->get('db/dbPass'),
  189 + 'username' => $oKTConfig->get("db/db{$prefix}User"),
  190 + 'password' => $oKTConfig->get("db/db{$prefix}Pass"),
189 191 'hostspec' => $oKTConfig->get('db/dbHost'),
190 192 'database' => $oKTConfig->get('db/dbName'),
191 193 'port' => $oKTConfig->get('db/dbPort'),
... ... @@ -320,6 +322,25 @@ class KTInit {
320 322 }
321 323 // }}}
322 324  
  325 + static function detectMagicFile()
  326 + {
  327 + $knownPaths = array(
  328 + '/usr/share/file/magic', // the old default
  329 + '/etc/httpd/conf/magic', // fedora's location
  330 + '/etc/magic' // worst case scenario. Noticed this is sometimes empty and containing a reference to somewher else
  331 + );
  332 +
  333 + foreach($knownPaths as $path)
  334 + {
  335 + if (file_exists($path))
  336 + {
  337 + return $path;
  338 + }
  339 + }
  340 + return KT_DIR . '/config/magic';
  341 + }
  342 +
  343 +
323 344 static protected $handlerMapping = array(
324 345 E_WARNING=>PEAR_LOG_WARNING,
325 346 E_USER_WARNING=>PEAR_LOG_WARNING,
... ... @@ -360,10 +381,10 @@ function catchFatalErrors($p_OnOff='On'){
360 381 ini_set('display_errors','On');
361 382 $phperror='><div id="phperror" style="display:none">';
362 383 ini_set('error_prepend_string',$phperror);
363   -
  384 +
364 385 $phperror='</div>><form name="catcher" action="/customerrorpage.php" method="post" ><input type="hidden" name="fatal" value=""></form>
365 386 <script> document.catcher.fatal.value = document.getElementById("phperror").innerHTML; document.catcher.submit();</script>';
366   - ini_set('error_append_string',$phperror);
  387 + ini_set('error_append_string',$phperror);
367 388 }
368 389  
369 390  
... ... @@ -452,7 +473,7 @@ function catchFatalErrors($p_OnOff=&#39;On&#39;){
452 473 $oKTConfig->setdefaultns('KnowledgeTree', 'rootUrl', $this->guessRootUrl());
453 474 $oKTConfig->setdefaultns('KnowledgeTree', 'execSearchPath', $_SERVER['PATH']);
454 475 $oKTConfig->setdefaultns('KnowledgeTree', 'pathInfoSupport', false);
455   - $oKTConfig->setdefaultns('KnowledgeTree', 'magicDatabase', '/usr/share/file/magic');
  476 + $oKTConfig->setdefaultns('KnowledgeTree', 'magicDatabase', KTInit::detectMagicFile());
456 477  
457 478 $oKTConfig->setdefaultns('dashboard', 'alwaysShowYCOD', true);
458 479  
... ... @@ -612,14 +633,14 @@ require_once(KT_LIB_DIR . &#39;/ktentity.inc&#39;);
612 633 $KTInit->catchFatalErrors();
613 634  
614 635 if (phpversion()<5){
615   -
  636 +
616 637 $sErrorPage = 'http://'.$_SERVER['HTTP_HOST'].'/'.'customerrorpage.php';
617   -
  638 +
618 639 session_start();
619   -
  640 +
620 641 $_SESSION['sErrorMessage'] = 'KnowledgeTree now requires that PHP version 5 is installed. PHP version 4 is no longer supported.';
621   -
622   -
  642 +
  643 +
623 644 header('location:'. $sErrorPage ) ;
624 645  
625 646 }
... ... @@ -632,7 +653,7 @@ $KTInit-&gt;setupI18n();
632 653  
633 654 define('KTLOG_CACHE',false);
634 655  
635   -if ($GLOBALS['kt_test']) {
  656 +if (isset($GLOBALS['kt_test'])) {
636 657 $KTInit->initTesting();
637 658 }
638 659  
... ...
lib/mime.inc.php
... ... @@ -5,32 +5,32 @@
5 5 * KnowledgeTree Open Source Edition
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
8   - *
  8 + *
9 9 * This program is free software; you can redistribute it and/or modify it under
10 10 * the terms of the GNU General Public License version 3 as published by the
11 11 * Free Software Foundation.
12   - *
  12 + *
13 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 16 * details.
17   - *
  17 + *
18 18 * You should have received a copy of the GNU General Public License
19 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20   - *
  20 + *
21 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23   - *
  23 + *
24 24 * The interactive user interfaces in modified source and object code versions
25 25 * of this program must display Appropriate Legal Notices, as required under
26 26 * Section 5 of the GNU General Public License version 3.
27   - *
  27 + *
28 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 29 * these Appropriate Legal Notices must retain the display of the "Powered by
30   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  30 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
31 31 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
32   - * must display the words "Powered by KnowledgeTree" and retain the original
33   - * copyright notice.
  32 + * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * copyright notice.
34 34 * Contributor( s): ______________________________________
35 35 *
36 36 */
... ... @@ -50,15 +50,9 @@ class KTMime {
50 50 function getMimeTypeID($sMimeType, $sFileName) {
51 51 global $default;
52 52 $sTable = KTUtil::getTableName('mimetypes');
53   - $lookupExtension = false;
54 53  
55   - if (in_array($sMimeType, array('application/x-zip','application/octet-stream', 'application/msword', 'text/plain')))
56   - {
57   - $lookupExtension = true;
58   - }
59 54  
60   - if ($lookupExtension || empty($sMimeType))
61   - {
  55 +
62 56 // check by file extension
63 57 $sExtension = KTMime::stripAllButExtension($sFileName);
64 58 $res = DBUtil::getOneResultKey(array("SELECT id FROM " . $sTable . " WHERE LOWER(filetypes) = ?", array($sExtension)),'id');
... ... @@ -69,7 +63,7 @@ class KTMime {
69 63 else {
70 64 return $res;
71 65 }
72   - }
  66 +
73 67  
74 68 // get the mime type id
75 69 if (isset($sMimeType)) {
... ... @@ -207,12 +201,12 @@ class KTMime {
207 201 function stripAllButExtension($sFileName) {
208 202 return strtolower(substr($sFileName, strrpos($sFileName, ".")+1, strlen($sFileName) - strrpos($sFileName, ".")));
209 203 }
210   -
  204 +
211 205 /**
212   - * getAllMimeTypesInformation is a staic function used to get a fuller set of
  206 + * getAllMimeTypesInformation is a staic function used to get a fuller set of
213 207 * information on the mime types held in the database.
214   - *
215   - */
  208 + *
  209 + */
216 210 function getAllMimeTypesInformation()
217 211 {
218 212 $sTable = KTUtil::getTableName('mimetypes');
... ... @@ -221,10 +215,10 @@ class KTMime {
221 215 $res = DBUtil::getResultArray($aQuery);
222 216 return $res;
223 217 }
224   -
  218 +
225 219 /**
226 220 * get all information on all the extractors in the database
227   - *
  221 + *
228 222 */
229 223 function getMimeExtractorInformation()
230 224 {
... ... @@ -232,11 +226,11 @@ class KTMime {
232 226 $res = DBUtil::getResultArray($aQuery);
233 227 return $res;
234 228 }
235   -
  229 +
236 230 /**
237 231 *give the mimetype name and get the friendly names and the extensions
238 232 *
239   - */
  233 + */
240 234 function getFriendlyNameAndExtension($sMimeType)
241 235 {
242 236 $sTable = KTUtil::getTableName('mimetypes');
... ...