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 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 */
... ... @@ -56,11 +56,11 @@ class KTAddDocumentTrigger {
56 56 */
57 57 function postValidate() {
58 58 global $default;
59   - $oDocument =& $this->aInfo['document'];
  59 + $oDocument =& $this->aInfo['document'];
60 60 $aMeta = & $this->aInfo['aOptions'];
61   -
62   - $iDocId = $oDocument->getID();
63   -
  61 +
  62 + $iDocId = $oDocument->getID();
  63 +
64 64 // get tag id from document_fields table where name = Tag
65 65 $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' .
66 66 'WHERE df.name = \'Tag\'';
... ... @@ -77,7 +77,7 @@ class KTAddDocumentTrigger {
77 77 {
78 78 foreach($aMeta['metadata'] as $aMetaData)
79 79 {
80   -
  80 +
81 81 $oProxy = $aMetaData[0];
82 82 if($oProxy->iId == $sTags)
83 83 {
... ... @@ -89,35 +89,39 @@ class KTAddDocumentTrigger {
89 89 $words_table = KTUtil::getTableName('tag_words');
90 90 $tagString = str_replace(' ', '', $tagString);
91 91 $tags = explode(',',$tagString);
92   -
  92 +
93 93 $aTagIds = array();
94   -
  94 +
95 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 102 $res = DBUtil::getOneResult(array("SELECT id FROM $words_table WHERE tag = ?", array($sTag)));
99   -
  103 +
100 104 if (PEAR::isError($res)) {
101 105 return $res;
102 106 }
103   -
104   - if (is_null($res))
  107 +
  108 + if (is_null($res))
105 109 {
106 110 $id = & DBUtil::autoInsert($words_table, array('tag'=>$sTag));
107 111 $aTagIds[$sTag] = $id;
108 112 }
109   - else
  113 + else
110 114 {
111 115 $aTagIds[$sTag] = $res['id'];
112 116 }
113 117 }
114   -
  118 +
115 119 $doc_tags = KTUtil::getTableName('document_tags');
116   -
  120 +
117 121 foreach($aTagIds as $sTag=>$tagid)
118 122 {
119 123 DBUtil::autoInsert($doc_tags, array(
120   -
  124 +
121 125 'document_id'=>$iDocId,
122 126 'tag_id'=>$tagid),
123 127 array('noid'=>true));
... ... @@ -150,11 +154,11 @@ class KTEditDocumentTrigger {
150 154 */
151 155 function postValidate() {
152 156 global $default;
153   - $oDocument =& $this->aInfo['document'];
  157 + $oDocument =& $this->aInfo['document'];
154 158 $aMeta = & $this->aInfo['aOptions'];
155 159 // get document id
156   - $iDocId = $oDocument->getID();
157   -
  160 + $iDocId = $oDocument->getID();
  161 +
158 162 // get all tags that are linked to the document
159 163 $sQuery = 'SELECT tw.id FROM tag_words AS tw, document_tags AS dt, documents AS d ' .
160 164 'WHERE dt.tag_id = tw.id ' .
... ... @@ -178,7 +182,7 @@ class KTEditDocumentTrigger {
178 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 186 $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' .
183 187 'WHERE df.name = \'Tag\'';
184 188  
... ... @@ -206,32 +210,35 @@ class KTEditDocumentTrigger {
206 210 $words_table = KTUtil::getTableName('tag_words');
207 211 $tagString = str_replace(' ', ' ', $tagString);
208 212 $tags = explode(',',$tagString);
209   -
  213 +
210 214 $aTagIds = array();
211   -
  215 +
212 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 223 $res = DBUtil::getOneResult(array("SELECT id FROM $words_table WHERE tag = ?", array($sTag)));
217   -
  224 +
218 225 if (PEAR::isError($res)) {
219 226 return $res;
220 227 }
221   -
222   - if (is_null($res))
  228 +
  229 + if (is_null($res))
223 230 {
224 231 $id = & DBUtil::autoInsert($words_table, array('tag'=>$sTag));
225 232 $aTagIds[$sTag] = $id;
226 233 }
227   - else
  234 + else
228 235 {
229 236 $aTagIds[$sTag] = $res['id'];
230 237 }
231 238 }
232   -
  239 +
233 240 $doc_tags = KTUtil::getTableName('document_tags');
234   -
  241 +
235 242 foreach($aTagIds as $sTag=>$tagid)
236 243 {
237 244 DBUtil::autoInsert($doc_tags, array(
... ...