Commit 8035779b31822ae57fa16eea95eddc41d3bfbfaa

Authored by Megan Watson
1 parent 52936350

KTS-3175

"Add "browse by tag" feature"
Fixed. Created a portlet that displays next to the search results and can be used to filter down through the results.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8364 c91229c3-7414-0410-bfa2-8a42b809f60b
plugins/ktcore/KTPortlets.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 */
... ... @@ -48,7 +48,7 @@ class KTSearchPortlet extends KTPortlet {
48 48  
49 49 $oTemplating =& KTTemplating::getSingleton();
50 50 $oTemplate = $oTemplating->loadTemplate("kt3/portlets/search_portlet");
51   -
  51 +
52 52 $iFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId', 1);
53 53 $iDocumentId = KTUtil::arrayGet($_REQUEST, 'fDocumentId');
54 54 if (!$iFolderId && !$iDocumentId) {
... ... @@ -59,10 +59,10 @@ class KTSearchPortlet extends KTPortlet {
59 59 $aSearches = KTSavedSearch::getUserSearches($iUserId);
60 60  
61 61 // empty on error.
62   - if (PEAR::isError($aSearches)) {
63   - $aSearches = array();
  62 + if (PEAR::isError($aSearches)) {
  63 + $aSearches = array();
64 64 }
65   -
  65 +
66 66 $iFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId', 1);
67 67 $aTemplateData = array(
68 68 "context" => $this,
... ... @@ -87,16 +87,24 @@ class KTBrowseModePortlet extends KTPortlet {
87 87 parent::KTPortlet($sTitle);
88 88 }
89 89  
90   - function render() {
  90 + function render() {
91 91 // this is unfortunate, but such is life.
92 92 $current_action = KTUtil::arrayGet($_REQUEST, 'fBrowseMode', null);
93 93 $modes = array(
94   - 'folder' => array('name' => _kt('Folder'), 'target' => "main"),
  94 + 'folder' => array('name' => _kt('Folder'), 'target' => "main"),
95 95 'document_type' => array('name' => _kt('Document Type'), 'target' => 'selectType'),
96 96 'lookup_value' => array('name' => _kt('Lookup Value'), 'target' => 'selectField'),
97   - );
98   -
99   - $oTemplating =& KTTemplating::getSingleton();
  97 + );
  98 +
  99 + // Browse by tag
  100 + $oRegistry =& KTPluginRegistry::getSingleton();
  101 + $oPlugin =& $oRegistry->getPlugin('ktcore.tagcloud.plugin');
  102 + if(!PEAR::isError($oPlugin) && !empty($oPlugin)){
  103 + $tagUrl = $oPlugin->getPagePath('TagCloudRedirection');
  104 + $modes['tag'] = array('name' => '<a href="'.$tagUrl.'">'._kt('Tag').'</a>');
  105 + }
  106 +
  107 + $oTemplating =& KTTemplating::getSingleton();
100 108 $oTemplate = $oTemplating->loadTemplate("kt3/portlets/browsemodes_portlet");
101 109 $aTemplateData = array(
102 110 "context" => $this,
... ... @@ -104,7 +112,7 @@ class KTBrowseModePortlet extends KTPortlet {
104 112 "modes" => $modes,
105 113 );
106 114  
107   - return $oTemplate->render($aTemplateData);
  115 + return $oTemplate->render($aTemplateData);
108 116 }
109 117 }
110 118  
... ... @@ -161,21 +169,21 @@ class KTAdminSectionNavigation extends KTPortlet {
161 169 function KTAdminSectionNavigation() {
162 170 parent::KTPortlet(_kt("Administration"));
163 171 }
164   -
  172 +
165 173 function render() {
166 174 require_once(KT_LIB_DIR . "/plugins/KTAdminNavigation.php");
167   -
  175 +
168 176 $oRegistry =& KTAdminNavigationRegistry::getSingleton();
169   - $categories = $oRegistry->getCategories();
170   -
  177 + $categories = $oRegistry->getCategories();
  178 +
171 179 // we need to investigate sub_url solutions.
172   -
  180 +
173 181 $oTemplating =& KTTemplating::getSingleton();
174 182 $oTemplate = $oTemplating->loadTemplate("kt3/portlets/admin_categories");
175 183 $aTemplateData = array(
176 184 "context" => $this,
177 185 "categories" => $categories,
178 186 );
179   - return $oTemplate->render($aTemplateData);
  187 + return $oTemplate->render($aTemplateData);
180 188 }
181 189 }
... ...
plugins/tagcloud/TagCloudDashlet.php
... ... @@ -6,32 +6,32 @@
6 6 * KnowledgeTree Open Source Edition
7 7 * Document Management Made Simple
8 8 * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
9   - *
  9 + *
10 10 * This program is free software; you can redistribute it and/or modify it under
11 11 * the terms of the GNU General Public License version 3 as published by the
12 12 * Free Software Foundation.
13   - *
  13 + *
14 14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 17 * details.
18   - *
  18 + *
19 19 * You should have received a copy of the GNU General Public License
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - *
  21 + *
22 22 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
23 23 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
24   - *
  24 + *
25 25 * The interactive user interfaces in modified source and object code versions
26 26 * of this program must display Appropriate Legal Notices, as required under
27 27 * Section 5 of the GNU General Public License version 3.
28   - *
  28 + *
29 29 * In accordance with Section 7(b) of the GNU General Public License version 3,
30 30 * these Appropriate Legal Notices must retain the display of the "Powered by
31   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32 32 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33   - * must display the words "Powered by KnowledgeTree" and retain the original
34   - * copyright notice.
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * copyright notice.
35 35 * Contributor( s): ______________________________________
36 36 *
37 37 */
... ... @@ -44,7 +44,7 @@ require_once(KT_LIB_DIR . &#39;/plugins/plugin.inc.php&#39;);
44 44 class TagCloudDashlet extends KTBaseDashlet {
45 45 var $oUser;
46 46 var $sClass = 'ktBlock';
47   -
  47 +
48 48 /**
49 49 * Constructor method
50 50 *
... ... @@ -53,7 +53,7 @@ class TagCloudDashlet extends KTBaseDashlet {
53 53 function TagCloudDashlet(){
54 54 $this->sTitle = _kt('Tag Cloud');
55 55 }
56   -
  56 +
57 57 /**
58 58 * Check to see if user is active
59 59 *
... ... @@ -74,9 +74,7 @@ class TagCloudDashlet extends KTBaseDashlet {
74 74 $oTemplating =& KTTemplating::getSingleton();
75 75 $oTemplate = $oTemplating->loadTemplate('TagCloud/dashlet');
76 76  
77   - $aTags = & $this->get_relevant_tags();
78   - if($aTags)
79   - $aTags = & $this->get_tag_weightings($aTags);
  77 + $aTags = $this->get_tag_weightings($aTags);
80 78  
81 79 $oRegistry =& KTPluginRegistry::getSingleton();
82 80 $oPlugin =& $oRegistry->getPlugin('ktcore.tagcloud.plugin');
... ... @@ -88,14 +86,14 @@ class TagCloudDashlet extends KTBaseDashlet {
88 86 );
89 87 return $oTemplate->render($aTemplateData);
90 88 }
91   -
  89 +
92 90 /**
93 91 * Builds the weightings for tags based on their frequency
94 92 *
95 93 * @param array $aTags
96 94 * @return array
97 95 */
98   - function & get_tag_weightings(&$aTags)
  96 + function get_tag_weightings($aTags)
99 97 {
100 98 $aTags = $this->get_relevant_tags();
101 99  
... ... @@ -121,23 +119,23 @@ class TagCloudDashlet extends KTBaseDashlet {
121 119  
122 120 return $aTags;
123 121 }
124   -
  122 +
125 123 /**
126 124 * Returns the relevant tags for the current user
127 125 *
128 126 * @return array
129 127 */
130   - function & get_relevant_tags()
  128 + function get_relevant_tags()
131 129 {
132 130 $aUserPermissions = KTSearchUtil::permissionToSQL($this->oUser, null);
133 131 if(PEAR::isError($aUserPermissions)) {
134 132 return false;
135 133 }
136   - list($where, $params, $joins) = KTSearchUtil::permissionToSQL($this->oUser, null);
  134 + list($where, $params, $joins) = $aUserPermissions;
137 135 $sql = "
138   - SELECT
139   - TW.tag, count(*) as freq
140   - FROM
  136 + SELECT
  137 + TW.tag, count(*) as freq
  138 + FROM
141 139 document_tags DT INNER JOIN tag_words TW ON DT.tag_id=TW.id
142 140 WHERE DT.document_id in (SELECT D.id FROM documents D $joins WHERE $where AND D.status_id = '1') GROUP BY TW.tag";
143 141  
... ... @@ -155,6 +153,6 @@ class TagCloudDashlet extends KTBaseDashlet {
155 153 return $aTags;
156 154  
157 155 }
158   -
  156 +
159 157 }
160 158 ?>
... ...
plugins/tagcloud/TagCloudPlugin.php
... ... @@ -6,36 +6,36 @@
6 6 * KnowledgeTree Open Source Edition
7 7 * Document Management Made Simple
8 8 * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
9   - *
  9 + *
10 10 * This program is free software; you can redistribute it and/or modify it under
11 11 * the terms of the GNU General Public License version 3 as published by the
12 12 * Free Software Foundation.
13   - *
  13 + *
14 14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 17 * details.
18   - *
  18 + *
19 19 * You should have received a copy of the GNU General Public License
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - *
  21 + *
22 22 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
23 23 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
24   - *
  24 + *
25 25 * The interactive user interfaces in modified source and object code versions
26 26 * of this program must display Appropriate Legal Notices, as required under
27 27 * Section 5 of the GNU General Public License version 3.
28   - *
  28 + *
29 29 * In accordance with Section 7(b) of the GNU General Public License version 3,
30 30 * these Appropriate Legal Notices must retain the display of the "Powered by
31   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32 32 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33   - * must display the words "Powered by KnowledgeTree" and retain the original
34   - * copyright notice.
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * copyright notice.
35 35 * Contributor( s): ______________________________________
36 36 *
37 37 */
38   -
  38 +
39 39 require_once(KT_LIB_DIR . '/plugins/plugin.inc.php');
40 40 require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php');
41 41 require_once('TagCloudRedirectPage.php');
... ... @@ -48,7 +48,8 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
48 48 class TagCloudPlugin extends KTPlugin{
49 49  
50 50 var $sNamespace = 'ktcore.tagcloud.plugin';
51   -
  51 + var $iVersion = 1;
  52 +
52 53 /**
53 54 * Constructor method for plugin
54 55 *
... ... @@ -60,7 +61,7 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
60 61 $this->sFriendlyName = _kt('Tag Cloud Plugin');
61 62 return $res;
62 63 }
63   -
  64 +
64 65 /**
65 66 * Setup function for plugin
66 67 *
... ... @@ -69,8 +70,9 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
69 70 // Register plugin components
70 71 $this->registerCriterion('TagCloudCriterion', 'ktcore.criteria.tagcloud', KT_LIB_DIR . '/browse/Criteria.inc');
71 72 $this->registerDashlet('TagCloudDashlet', 'ktcore.tagcloud.feed.dashlet', 'TagCloudDashlet.php');
72   - $this->registerPage('TagCloudRedirection', 'TagCloudRedirectPage', __FILE__);
73   -
  73 + $this->registerPage('TagCloudRedirection', 'TagCloudRedirectPage', __FILE__);
  74 + $this->registerPortlet(array(), 'TagCloudPortlet', 'tagcloud.portlet', 'TagCloudPortlet.php');
  75 +
74 76  
75 77 // Check if the tagcloud fielset entry exists, if not, create it
76 78 if(!TagCloudPlugin::tagFieldsetExists()){
... ... @@ -85,7 +87,7 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
85 87 }else{ // if the entry exists, make the fieldset id viewable anyway
86 88 $iFieldsetId = TagCloudPlugin::tagFieldsetExists();
87 89 }
88   -
  90 +
89 91 // Check if the tagcloud document field entry exists, if not, create it
90 92 if(!TagCloudPlugin::tagFieldExists()){
91 93 $oField = TagCloudPlugin::createDocumentField($iFieldsetId);
... ... @@ -93,18 +95,18 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
93 95 return false;
94 96 }
95 97 }
96   -
  98 +
97 99 $oTemplating =& KTTemplating::getSingleton();
98 100 $oTemplating->addLocation('Tag Cloud Plugin', '/plugins/tagcloud/templates');
99 101 }
100   -
  102 +
101 103 /**
102 104 * function to add fieldset entry to fieldsets table
103 105 *
104 106 * @return unknown
105 107 */
106 108 function createFieldset(){
107   - // create the fieldsets entry
  109 + // create the fieldsets entry
108 110 $oFieldset = KTFieldset::createFromArray(array(
109 111 'name' => 'Tag Cloud',
110 112 'description' => 'Tag Cloud',
... ... @@ -114,12 +116,12 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
114 116 'isGeneric' => true,
115 117 'isComplete' => false,
116 118 'isComplex' => false,
117   - 'isSystem' => false,
  119 + 'isSystem' => false,
118 120 ));
119   -
  121 +
120 122 return $oFieldset;
121 123 }
122   -
  124 +
123 125 /**
124 126 * function to add the tagcloud entry to the document_fields table
125 127 *
... ... @@ -127,7 +129,7 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
127 129 * @return int $id
128 130 */
129 131 function createDocumentField($parentId){
130   - // create the document_field entry
  132 + // create the document_field entry
131 133 $id = DocumentField::createFromArray(array(
132 134 'Name' => 'Tag',
133 135 'Description' => 'Tag Words',
... ... @@ -136,12 +138,12 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
136 138 'HasLookup' => false,
137 139 'HasLookupTree' => false,
138 140 'ParentFieldset' => $parentId,
139   - 'IsMandatory' => false,
  141 + 'IsMandatory' => false,
140 142 ));
141 143  
142 144 return $id;
143 145 }
144   -
  146 +
145 147 /**
146 148 * function to check if the Tag field exists in the document_fields table
147 149 *
... ... @@ -155,7 +157,7 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
155 157 if (PEAR::isError($sTag)) {
156 158 // XXX: log error
157 159 return false;
158   -
  160 +
159 161 }
160 162 if(!is_null($sTag)){
161 163 return $sTag;
... ... @@ -163,7 +165,7 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
163 165 return false;
164 166 }
165 167 }
166   -
  168 +
167 169 /**
168 170 * function to check if the fieldset exists in the database
169 171 *
... ... @@ -177,7 +179,7 @@ require_once(KT_LIB_DIR . &#39;/templating/templating.inc.php&#39;);
177 179 if (PEAR::isError($iFieldset)) {
178 180 // XXX: log error
179 181 return false;
180   -
  182 +
181 183 }
182 184 if(!is_null($iFieldset)){
183 185 return $iFieldset;
... ...
plugins/tagcloud/TagCloudPortlet.php 0 → 100644
  1 +<?php
  2 +
  3 +/*
  4 + * $Id: $
  5 + *
  6 + * KnowledgeTree Open Source Edition
  7 + * Document Management Made Simple
  8 + * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
  9 + *
  10 + * This program is free software; you can redistribute it and/or modify it under
  11 + * the terms of the GNU General Public License version 3 as published by the
  12 + * Free Software Foundation.
  13 + *
  14 + * This program is distributed in the hope that it will be useful, but WITHOUT
  15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17 + * details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + *
  22 + * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
  23 + * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
  24 + *
  25 + * The interactive user interfaces in modified source and object code versions
  26 + * of this program must display Appropriate Legal Notices, as required under
  27 + * Section 5 of the GNU General Public License version 3.
  28 + *
  29 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  30 + * these Appropriate Legal Notices must retain the display of the "Powered by
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * copyright notice.
  35 + * Contributor( s): ______________________________________
  36 + *
  37 + */
  38 +
  39 +require_once(KT_LIB_DIR . '/widgets/portlet.inc.php');
  40 +require_once('TagCloudUtil.inc.php');
  41 +
  42 +class TagCloudPortlet extends KTPortlet {
  43 + var $bActive = true;
  44 + var $oUser = '';
  45 + var $sTag = '';
  46 +
  47 + function TagCloudPortlet($oUser = NULL, $sTag = NULL) {
  48 + if(empty($oUser)){
  49 + $iUserId = $_SESSION['userID'];
  50 + $oUser = User::get($iUserId);
  51 + }
  52 + $this->oUser = $oUser;
  53 + $this->sTag = $sTag;
  54 + $title = _kt('Tag Cloud');
  55 + parent::KTPortlet($title);
  56 + }
  57 +
  58 + function render() {
  59 + $oRegistry =& KTPluginRegistry::getSingleton();
  60 + $oPlugin =& $oRegistry->getPlugin('ktcore.tagcloud.plugin');
  61 + $url = $oPlugin->getPagePath('TagCloudRedirection');
  62 + $url .= '&action=search';
  63 +
  64 + $aTags = get_relevant_tags($this->oUser, $this->sTag);
  65 + $aTags = get_tag_weightings($aTags);
  66 +
  67 + $oTemplating =& KTTemplating::getSingleton();
  68 + $oTemplate = $oTemplating->loadTemplate('TagCloud/portlet');
  69 + $aTemplateData = array(
  70 + 'tags' => $aTags,
  71 + 'url' => $url
  72 + );
  73 + return $oTemplate->render($aTemplateData);
  74 + }
  75 +
  76 +}
  77 +
  78 +?>
0 79 \ No newline at end of file
... ...
plugins/tagcloud/TagCloudRedirectPage.php
1 1 <?php
2 2 /*
3   - * $Id$
4   - *
5   - * KnowledgeTree Open Source Edition
6   - * Document Management Made Simple
7   - * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
8   - *
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
11   - * Free Software Foundation.
12   - *
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
15   - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16   - * details.
17   - *
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/>.
20   - *
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.
23   - *
24   - * The interactive user interfaces in modified source and object code versions
25   - * of this program must display Appropriate Legal Notices, as required under
26   - * Section 5 of the GNU General Public License version 3.
27   - *
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
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
32   - * must display the words "Powered by KnowledgeTree" and retain the original
33   - * copyright notice.
34   - * Contributor( s): ______________________________________
35   - *
36   - */
  3 +* $Id$
  4 +*
  5 +* KnowledgeTree Open Source Edition
  6 +* Document Management Made Simple
  7 +* Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
  8 +*
  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
  11 +* Free Software Foundation.
  12 +*
  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
  15 +* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  16 +* details.
  17 +*
  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/>.
  20 +*
  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.
  23 +*
  24 +* The interactive user interfaces in modified source and object code versions
  25 +* of this program must display Appropriate Legal Notices, as required under
  26 +* Section 5 of the GNU General Public License version 3.
  27 +*
  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
  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
  32 +* must display the words "Powered by KnowledgeTree" and retain the original
  33 +* copyright notice.
  34 +* Contributor( s): ______________________________________
  35 +*
  36 +*/
37 37  
38 38 require_once(KT_LIB_DIR . '/plugins/plugin.inc.php');
39 39 require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php');
... ... @@ -52,46 +52,71 @@ require_once(KT_LIB_DIR . &#39;/browse/PartialQuery.inc.php&#39;);
52 52 require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php');
53 53 require_once(KT_LIB_DIR . '/actions/bulkaction.php');
54 54  
  55 +require_once(KT_DIR . '/plugins/tagcloud/TagCloudPortlet.php');
  56 +
55 57 class TagCloudRedirectPage extends KTStandardDispatcher {
56 58  
57   - /**
  59 + /**
58 60 * Dispatcher main method
59 61 *
60 62 * @return unknown
61 63 */
62   - function do_main() {
63   - $searchable_text = KTUtil::arrayGet($_REQUEST, 'tag');
64   - // set breadcrumbs
65   - $this->aBreadcrumbs[] = array('url' => 'dashboard.php', 'name' => _kt('Dashboard'));
66   - $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'].'&tag='.htmlentities($searchable_text,ENT_QUOTES,'UTF-8'), 'name' => _kt('Tag Cloud Search'));
67   - // set page title
68   - $sTitle = _kt('Search Results');
69   -
70   - $this->oPage->setBreadcrumbDetails($sTitle);
71   -
72   - // build criteria set
73   - $aCriteriaSet = array(
74   - 'join'=>'AND',
75   - 'subgroup'=>array(
76   - 0=>array(
77   - 'join'=>'AND',
78   - 'values'=>array(
79   - 1=>array(
80   - 'data'=>array(
81   - 'ktcore.criteria.tagcloud'=>$searchable_text,
82   - 'ktcore.criteria.tagcloud_not'=>0
83   - ),
84   - 'type'=>'ktcore.criteria.tagcloud'
85   - )
86   - )
87   - )
88   - )
89   - );
90   -
91   -
92   - $this->browseType = 'Folder';
93   - $sSearch = md5(serialize($aCriteriaSet));
94   - $_SESSION['boolean_search'][$sSearch] = $aCriteriaSet;
  64 + function do_main() {
  65 + // Clear the session for a new search
  66 + $url = isset($_REQUEST['tag']) ? 'tag='.$_REQUEST['tag'] : '';
  67 + $_SESSION['tagList'] = array();
  68 + $this->redirectTo('search', $url);
  69 + }
  70 +
  71 + /**
  72 + * Recall a previous tag search and remove the tags that were selected after it.
  73 + */
  74 + function do_recall() {
  75 + $tag = $_REQUEST['tag'];
  76 + $pos = $_REQUEST['pos'];
  77 +
  78 + // Delete all tags after and including the selected tag
  79 + $tagList = $_SESSION['tagList'];
  80 + $tagList = array_slice($tagList, 0, $pos);
  81 +
  82 + $_SESSION['tagList'] = $tagList;
  83 +
  84 + $this->redirectTo('search', 'tag='.$tag);
  85 + }
  86 +
  87 + function do_search() {
  88 + // Get the tag to search for and create search query
  89 + $tag = isset($_REQUEST['tag']) ? $_REQUEST['tag'] : '';
  90 +
  91 + $iUserId = $_SESSION['userID'];
  92 + $oUser = User::get($iUserId);
  93 +
  94 + // set breadcrumbs
  95 + $this->aBreadcrumbs[] = array('url' => 'dashboard.php', 'name' => _kt('Dashboard'));
  96 + $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Tag Cloud Search'));
  97 +
  98 + $tagList = $_SESSION['tagList'];
  99 + if(!empty($tagList)){
  100 + $aPrevTag = end($tagList);
  101 + $aTagTree = $aPrevTag['tagTree'];
  102 +
  103 + $base = KTUtil::addQueryString('TagCloudRedirection&action=recall', null);
  104 + foreach($aTagTree as $key => $item){
  105 + $url = $base.'&tag='.$item.'&pos='.$key;
  106 + $this->aBreadcrumbs[] = array('url' => $url, 'name' => $item);
  107 + }
  108 + }
  109 + if(!empty($tag)){
  110 + $this->aBreadcrumbs[] = array('url' => '', 'name' => $tag);
  111 + }
  112 +
  113 + // set page title
  114 + $sTitle = _kt('Search Results');
  115 + $this->oPage->setBreadcrumbDetails($sTitle);
  116 +
  117 + // Set tag cloud portlet
  118 + $portlet = new TagCloudPortlet($oUser, $tag);
  119 + $this->oPage->addPortlet($portlet);
95 120  
96 121 $collection = new AdvancedCollection;
97 122 $oColumnRegistry = KTColumnRegistry::getSingleton();
... ... @@ -99,25 +124,22 @@ class TagCloudRedirectPage extends KTStandardDispatcher {
99 124 $collection->addColumns($aColumns);
100 125  
101 126 // set a view option
102   - $aTitleOptions = array(
103   - 'documenturl' => $GLOBALS['KTRootUrl'] . '/view.php',
104   - );
  127 + $aTitleOptions = array('documenturl' => $GLOBALS['KTRootUrl'] . '/view.php',);
105 128 $collection->setColumnOptions('ktcore.columns.title', $aTitleOptions);
106 129 $collection->setColumnOptions('ktcore.columns.selection', array(
107 130 'rangename' => 'selection',
108 131 'show_folders' => true,
109 132 'show_documents' => true,
110   - ));
  133 + ));
111 134  
112 135 $aOptions = $collection->getEnvironOptions(); // extract data from the environment
113 136  
114   - //$aOptions['return_url'] = KTUtil::addQueryString('dashboard.php', false);
115   - $aOptions['return_url'] = KTUtil::addQueryString('TagCloudRedirection&tag='. $searchable_text, false );
  137 + $aOptions['return_url'] = KTUtil::addQueryString('TagCloudRedirection&action=search&tag='. $tag, false );
116 138 $aOptions['empty_message'] = _kt('No documents or folders match this query.');
117 139 $aOptions['is_browse'] = true;
118 140  
119 141 $collection->setOptions($aOptions);
120   - $collection->setQueryObject(new BooleanSearchQuery($aCriteriaSet));
  142 + $collection->setQueryObject(new TagQuery($oUser, $tag));
121 143  
122 144 $oTemplating =& KTTemplating::getSingleton();
123 145 $oTemplate = $oTemplating->loadTemplate('kt3/browse');
... ... @@ -131,10 +153,8 @@ class TagCloudRedirectPage extends KTStandardDispatcher {
131 153 'browseutil' => new KTBrowseUtil(),
132 154 'returnaction' => 'booleanSearch',
133 155 'returndata' => $sSearch,
134   -
135 156 );
136 157 return $oTemplate->render($aTemplateData);
137   -
138   - }
  158 + }
139 159 }
140 160 ?>
... ...
plugins/tagcloud/TagCloudUtil.inc.php 0 → 100644
  1 +<?php
  2 +
  3 +/*
  4 + * $Id: $
  5 + *
  6 + * KnowledgeTree Open Source Edition
  7 + * Document Management Made Simple
  8 + * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
  9 + *
  10 + * This program is free software; you can redistribute it and/or modify it under
  11 + * the terms of the GNU General Public License version 3 as published by the
  12 + * Free Software Foundation.
  13 + *
  14 + * This program is distributed in the hope that it will be useful, but WITHOUT
  15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17 + * details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + *
  22 + * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
  23 + * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
  24 + *
  25 + * The interactive user interfaces in modified source and object code versions
  26 + * of this program must display Appropriate Legal Notices, as required under
  27 + * Section 5 of the GNU General Public License version 3.
  28 + *
  29 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  30 + * these Appropriate Legal Notices must retain the display of the "Powered by
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * copyright notice.
  35 + * Contributor( s): ______________________________________
  36 + *
  37 + */
  38 +
  39 +
  40 +/**
  41 +* Builds the weightings for tags based on their frequency
  42 +*
  43 +* @param array $aTags
  44 +* @return array
  45 +*/
  46 +function get_tag_weightings($aTags)
  47 +{
  48 + if (empty($aTags)){
  49 + return array();
  50 + }else{
  51 + $min_freq = min(array_values($aTags));
  52 + $max_freq = max(array_values($aTags));
  53 + }
  54 + $min_size = 10;
  55 + $max_size = 20;
  56 +
  57 + $distrib = $max_freq - $min_freq;
  58 + if ($distrib == 0){
  59 + $distrib=1;
  60 + }
  61 +
  62 + $step = ($max_size - $min_size)/($distrib);
  63 +
  64 + foreach($aTags as $tag => $freq)
  65 + {
  66 + $size = ceil($min_size + (($freq - $min_freq) * $step));
  67 + $aTags[$tag] = $size;
  68 + }
  69 +
  70 + return $aTags;
  71 +}
  72 +
  73 +/**
  74 +* Returns the relevant tags for the current user
  75 +*
  76 +* @return array
  77 +*/
  78 +function get_relevant_tags($oUser, $sTag)
  79 +{
  80 + $aTagList = isset($_SESSION['tagList']) ? $_SESSION['tagList'] : array();
  81 + $tagTree = array();
  82 + $documentList = '';
  83 +
  84 + // Get the previous tag info:
  85 + // the list of documents that contain the tag to search within
  86 + // the tags that have already been filtered so they aren't displayed again
  87 + if(!empty($aTagList)){
  88 + $aPrevTag = end($aTagList);
  89 + $sPrevTag = $aPrevTag['tag'];
  90 + $documentList = $aPrevTag['docs'];
  91 + $tagTree = $aPrevTag['tagTree'];
  92 + }
  93 +
  94 + if(empty($sTag)){
  95 + // If there is no tag specified then get all tags.
  96 + $aUserPermissions = KTSearchUtil::permissionToSQL($oUser, 'ktcore.permissions.read');
  97 + if(PEAR::isError($aUserPermissions)) {
  98 + return array();
  99 + }
  100 + // ensure the user has read permission on the documents
  101 + list($sWhere, $aParams, $sJoins) = $aUserPermissions;
  102 +
  103 + $sql = "SELECT TW.tag, count(*) as freq
  104 + FROM document_tags DT
  105 + INNER JOIN tag_words TW ON DT.tag_id=TW.id
  106 + WHERE DT.document_id in (SELECT D.id FROM documents D $sJoins WHERE $sWhere AND D.status_id = '1')
  107 + GROUP BY TW.tag";
  108 +
  109 + $tags = DBUtil::getResultArray(array($sql, $aParams));
  110 + }else{
  111 + // Create a new tag query to get the document id's associated with the tag
  112 + $oQuery = new TagQuery($oUser, $sTag);
  113 + $aOptions = array();
  114 + $aOptions['select'] = 'DISTINCT DTS.document_id';
  115 +
  116 + $aQuery = $oQuery->getQuery($aOptions);
  117 + $sInnerQuery = $aQuery[0];
  118 + $aParams = $aQuery[1];
  119 +
  120 + $aDocIds = DBUtil::getResultArrayKey($aQuery, 'document_id');
  121 + $sDocs = implode(',', $aDocIds);
  122 +
  123 + // Don't display tags that have already been selected.
  124 + $tagTree[] = $sTag;
  125 + $cnt = count($tagTree);
  126 + $sIgnoreTags = '?';
  127 + for($i = 1; $i < $cnt; $i++){
  128 + $sIgnoreTags .= ',?';
  129 + }
  130 +
  131 + // Get the tags within the documents that haven't been selected before
  132 + $sQuery = "SELECT TW.tag, count(*) as freq
  133 + FROM document_tags DT INNER JOIN tag_words TW ON DT.tag_id=TW.id
  134 + WHERE DT.document_id in ($sDocs) AND TW.tag NOT IN ($sIgnoreTags)
  135 + GROUP BY TW.tag";
  136 +
  137 + $tags = DBUtil::getResultArray(array($sQuery, $tagTree), null);
  138 +
  139 + // Add new tag to the session
  140 + if($sPrevTag != $sTag){
  141 + $aTagList[] = array('tag' => $sTag, 'docs' => $sDocs, 'tagTree' => $tagTree);
  142 + $_SESSION['tagList'] = $aTagList;
  143 + }
  144 + }
  145 +
  146 + // Create tag / frequency array
  147 + $aTags = array();
  148 + foreach($tags as $tag)
  149 + {
  150 + $word=$tag['tag'];
  151 + $freq=$tag['freq'];
  152 + $aTags[$word] = $freq;
  153 + }
  154 +
  155 + return $aTags;
  156 +
  157 +}
  158 +
  159 +class TagQuery extends PartialQuery
  160 +{
  161 + var $oUser;
  162 + var $sTag;
  163 +
  164 + function TagQuery($oUser, $sTag = '')
  165 + {
  166 + $this->sTag = $sTag;
  167 + $this->oUser = $oUser;
  168 + }
  169 +
  170 + function getDocumentCount()
  171 + {
  172 + $aOptions = array(
  173 + 'select' => 'count(DISTINCT DTS.document_id) AS cnt',
  174 + );
  175 + $aQuery = $this->getQuery($aOptions);
  176 + if (PEAR::isError($aQuery)) { return 0; }
  177 + $iRet = DBUtil::getOneResultKey($aQuery, 'cnt');
  178 + return $iRet;
  179 + }
  180 +
  181 + function getBaseQuery($aOptions)
  182 + {
  183 + $aCriteriaSet = array(
  184 + 'join'=>'AND',
  185 + 'subgroup'=>array(
  186 + 0=>array(
  187 + 'join'=>'AND',
  188 + 'values'=>array(
  189 + 1=>array(
  190 + 'data'=>array(
  191 + 'ktcore.criteria.tagcloud' => $this->sTag,
  192 + 'ktcore.criteria.tagcloud_not'=>0
  193 + ),
  194 + 'type'=>'ktcore.criteria.tagcloud'
  195 + )
  196 + ),
  197 + )
  198 + )
  199 + );
  200 +
  201 + $aQuery = KTSearchUtil::criteriaToQuery($aCriteriaSet, $this->oUser, 'ktcore.permissions.read', $aOptions);
  202 + return $aQuery;
  203 + }
  204 +
  205 + function getQuery($aOptions = null)
  206 + {
  207 + $aTagList = isset($_SESSION['tagList']) ? $_SESSION['tagList'] : array();
  208 + if(!empty($aTagList)){
  209 + $aPrevTag = end($aTagList);
  210 + $documentList = $aPrevTag['docs'];
  211 + }
  212 +
  213 + // If the document list is empty then create internal query with read permissions for the user and the first tag
  214 + $aQuery = $this->getBaseQuery($aOptions);
  215 + if(empty($documentList)){
  216 + return $aQuery;
  217 + }
  218 +
  219 + $sQuery = $aQuery[0];
  220 +
  221 + $sQuery .= " AND DTS.document_id IN ($documentList) ";
  222 + $aQuery[0] = $sQuery;
  223 +
  224 + return $aQuery;
  225 + }
  226 +
  227 + function getDocuments($iBatchSize, $iBatchStart, $sSortColumn, $sSortOrder, $sJoinClause = null, $aJoinParams = null)
  228 + {
  229 + $aOptions = array(
  230 + 'select' => 'DISTINCT DTS.document_id AS id'
  231 + );
  232 + $res = $this->getQuery($aOptions);
  233 + if (PEAR::isError($res)) { return array(); }
  234 + list($sQuery, $aParams) = $res;
  235 + $sQuery .= ' ORDER BY ' . $sSortColumn . ' ' . $sSortOrder . ' ';
  236 + $sQuery .= ' LIMIT ?, ?';
  237 +
  238 + $aParams[] = $iBatchStart;
  239 + $aParams[] = $iBatchSize;
  240 +
  241 + $q = array($sQuery, $aParams);
  242 + $res = DBUtil::getResultArray($q);
  243 +
  244 + return $res;
  245 + }
  246 +}
  247 +
  248 +
  249 +?>
0 250 \ No newline at end of file
... ...
plugins/tagcloud/templates/TagCloud/portlet.smarty 0 → 100644
  1 +{literal}
  2 +<style type="text/css">
  3 +#tagcloud a, a.link, a.visited, a.hover, a.active {
  4 +
  5 +color: gray;
  6 +border-bottom: 0px;
  7 +text-decoration: none;
  8 +
  9 +}
  10 +</style>
  11 +{/literal}
  12 +
  13 +{if empty($tags)}
  14 +<p>
  15 + {i18n}There are no tags defined or accessible.{/i18n}
  16 +</p>
  17 +
  18 +{else}
  19 +<div id=tagcloud>
  20 +{foreach from=$tags key=tag item=size}
  21 +
  22 + <a href="{$url}&tag={$tag|urlencode}" style="color: #333; font-size: {$size}px">{$tag|sanitize}</a>&nbsp;
  23 +
  24 +{/foreach}
  25 +</div>
  26 +{/if}
  27 +
  28 +<br>
  29 +<br>
0 30 \ No newline at end of file
... ...