Commit 2b7fc6dfef08ecd1a230b8af511870fd3247224a

Authored by Megan Watson
1 parent ff38c011

KTS-2841

"Document linked to a tag (with non-alphaneumeric characters) not returned when the tag is navigated."
Fixed. Replaced the strtolower.

Committed by: Megan Watson
Reviewed by: Jonathan Byrne




git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8240 c91229c3-7414-0410-bfa2-8a42b809f60b
plugins/tagcloud/TagCloudTriggers.php
@@ -5,32 +5,32 @@ @@ -5,32 +5,32 @@
5 * KnowledgeTree Open Source Edition 5 * KnowledgeTree Open Source Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
7 * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited 7 * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
8 - * 8 + *
9 * This program is free software; you can redistribute it and/or modify it under 9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 3 as published by the 10 * the terms of the GNU General Public License version 3 as published by the
11 * Free Software Foundation. 11 * Free Software Foundation.
12 - * 12 + *
13 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * details. 16 * details.
17 - * 17 + *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 - * 20 + *
21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23 - * 23 + *
24 * The interactive user interfaces in modified source and object code versions 24 * The interactive user interfaces in modified source and object code versions
25 * of this program must display Appropriate Legal Notices, as required under 25 * of this program must display Appropriate Legal Notices, as required under
26 * Section 5 of the GNU General Public License version 3. 26 * Section 5 of the GNU General Public License version 3.
27 - * 27 + *
28 * In accordance with Section 7(b) of the GNU General Public License version 3, 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 * these Appropriate Legal Notices must retain the display of the "Powered by 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 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices 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 * Contributor( s): ______________________________________ 34 * Contributor( s): ______________________________________
35 * 35 *
36 */ 36 */
@@ -56,11 +56,11 @@ class KTAddDocumentTrigger { @@ -56,11 +56,11 @@ class KTAddDocumentTrigger {
56 */ 56 */
57 function postValidate() { 57 function postValidate() {
58 global $default; 58 global $default;
59 - $oDocument =& $this->aInfo['document']; 59 + $oDocument =& $this->aInfo['document'];
60 $aMeta = & $this->aInfo['aOptions']; 60 $aMeta = & $this->aInfo['aOptions'];
61 -  
62 - $iDocId = $oDocument->getID();  
63 - 61 +
  62 + $iDocId = $oDocument->getID();
  63 +
64 // get tag id from document_fields table where name = Tag 64 // get tag id from document_fields table where name = Tag
65 $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' . 65 $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' .
66 'WHERE df.name = \'Tag\''; 66 'WHERE df.name = \'Tag\'';
@@ -77,7 +77,7 @@ class KTAddDocumentTrigger { @@ -77,7 +77,7 @@ class KTAddDocumentTrigger {
77 { 77 {
78 foreach($aMeta['metadata'] as $aMetaData) 78 foreach($aMeta['metadata'] as $aMetaData)
79 { 79 {
80 - 80 +
81 $oProxy = $aMetaData[0]; 81 $oProxy = $aMetaData[0];
82 if($oProxy->iId == $sTags) 82 if($oProxy->iId == $sTags)
83 { 83 {
@@ -89,35 +89,39 @@ class KTAddDocumentTrigger { @@ -89,35 +89,39 @@ class KTAddDocumentTrigger {
89 $words_table = KTUtil::getTableName('tag_words'); 89 $words_table = KTUtil::getTableName('tag_words');
90 $tagString = str_replace(' ', '', $tagString); 90 $tagString = str_replace(' ', '', $tagString);
91 $tags = explode(',',$tagString); 91 $tags = explode(',',$tagString);
92 - 92 +
93 $aTagIds = array(); 93 $aTagIds = array();
94 - 94 +
95 foreach($tags as $sTag) 95 foreach($tags as $sTag)
96 { 96 {
97 - $sTag = mb_strtolower(trim($sTag), mb_detect_encoding($sTag)); 97 + $sTag = trim($sTag);
  98 + $sTag = utf8_decode($sTag);
  99 + $sTag = mb_strtolower($sTag);
  100 + $sTag = utf8_encode($sTag);
  101 +
98 $res = DBUtil::getOneResult(array("SELECT id FROM $words_table WHERE tag = ?", array($sTag))); 102 $res = DBUtil::getOneResult(array("SELECT id FROM $words_table WHERE tag = ?", array($sTag)));
99 - 103 +
100 if (PEAR::isError($res)) { 104 if (PEAR::isError($res)) {
101 return $res; 105 return $res;
102 } 106 }
103 -  
104 - if (is_null($res)) 107 +
  108 + if (is_null($res))
105 { 109 {
106 $id = & DBUtil::autoInsert($words_table, array('tag'=>$sTag)); 110 $id = & DBUtil::autoInsert($words_table, array('tag'=>$sTag));
107 $aTagIds[$sTag] = $id; 111 $aTagIds[$sTag] = $id;
108 } 112 }
109 - else 113 + else
110 { 114 {
111 $aTagIds[$sTag] = $res['id']; 115 $aTagIds[$sTag] = $res['id'];
112 } 116 }
113 } 117 }
114 - 118 +
115 $doc_tags = KTUtil::getTableName('document_tags'); 119 $doc_tags = KTUtil::getTableName('document_tags');
116 - 120 +
117 foreach($aTagIds as $sTag=>$tagid) 121 foreach($aTagIds as $sTag=>$tagid)
118 { 122 {
119 DBUtil::autoInsert($doc_tags, array( 123 DBUtil::autoInsert($doc_tags, array(
120 - 124 +
121 'document_id'=>$iDocId, 125 'document_id'=>$iDocId,
122 'tag_id'=>$tagid), 126 'tag_id'=>$tagid),
123 array('noid'=>true)); 127 array('noid'=>true));
@@ -150,11 +154,11 @@ class KTEditDocumentTrigger { @@ -150,11 +154,11 @@ class KTEditDocumentTrigger {
150 */ 154 */
151 function postValidate() { 155 function postValidate() {
152 global $default; 156 global $default;
153 - $oDocument =& $this->aInfo['document']; 157 + $oDocument =& $this->aInfo['document'];
154 $aMeta = & $this->aInfo['aOptions']; 158 $aMeta = & $this->aInfo['aOptions'];
155 // get document id 159 // get document id
156 - $iDocId = $oDocument->getID();  
157 - 160 + $iDocId = $oDocument->getID();
  161 +
158 // get all tags that are linked to the document 162 // get all tags that are linked to the document
159 $sQuery = 'SELECT tw.id FROM tag_words AS tw, document_tags AS dt, documents AS d ' . 163 $sQuery = 'SELECT tw.id FROM tag_words AS tw, document_tags AS dt, documents AS d ' .
160 'WHERE dt.tag_id = tw.id ' . 164 'WHERE dt.tag_id = tw.id ' .
@@ -178,7 +182,7 @@ class KTEditDocumentTrigger { @@ -178,7 +182,7 @@ class KTEditDocumentTrigger {
178 return false; 182 return false;
179 } 183 }
180 } 184 }
181 - // proceed to add the tags as per normaly 185 + // proceed to add the tags as per normal
182 $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' . 186 $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' .
183 'WHERE df.name = \'Tag\''; 187 'WHERE df.name = \'Tag\'';
184 188
@@ -206,32 +210,35 @@ class KTEditDocumentTrigger { @@ -206,32 +210,35 @@ class KTEditDocumentTrigger {
206 $words_table = KTUtil::getTableName('tag_words'); 210 $words_table = KTUtil::getTableName('tag_words');
207 $tagString = str_replace(' ', ' ', $tagString); 211 $tagString = str_replace(' ', ' ', $tagString);
208 $tags = explode(',',$tagString); 212 $tags = explode(',',$tagString);
209 - 213 +
210 $aTagIds = array(); 214 $aTagIds = array();
211 - 215 +
212 foreach($tags as $sTag) 216 foreach($tags as $sTag)
213 { 217 {
214 - $sTag=strtolower(trim($sTag));  
215 - 218 + $sTag = trim($sTag);
  219 + $sTag = utf8_decode($sTag);
  220 + $sTag = mb_strtolower($sTag);
  221 + $sTag = utf8_encode($sTag);
  222 +
216 $res = DBUtil::getOneResult(array("SELECT id FROM $words_table WHERE tag = ?", array($sTag))); 223 $res = DBUtil::getOneResult(array("SELECT id FROM $words_table WHERE tag = ?", array($sTag)));
217 - 224 +
218 if (PEAR::isError($res)) { 225 if (PEAR::isError($res)) {
219 return $res; 226 return $res;
220 } 227 }
221 -  
222 - if (is_null($res)) 228 +
  229 + if (is_null($res))
223 { 230 {
224 $id = & DBUtil::autoInsert($words_table, array('tag'=>$sTag)); 231 $id = & DBUtil::autoInsert($words_table, array('tag'=>$sTag));
225 $aTagIds[$sTag] = $id; 232 $aTagIds[$sTag] = $id;
226 } 233 }
227 - else 234 + else
228 { 235 {
229 $aTagIds[$sTag] = $res['id']; 236 $aTagIds[$sTag] = $res['id'];
230 } 237 }
231 } 238 }
232 - 239 +
233 $doc_tags = KTUtil::getTableName('document_tags'); 240 $doc_tags = KTUtil::getTableName('document_tags');
234 - 241 +
235 foreach($aTagIds as $sTag=>$tagid) 242 foreach($aTagIds as $sTag=>$tagid)
236 { 243 {
237 DBUtil::autoInsert($doc_tags, array( 244 DBUtil::autoInsert($doc_tags, array(