Commit 3a5c84b94c08c89d7c1886d550dedac9d939b64e
1 parent
f37d7045
KTS-1557
"Implement Tag Cloud system. " Implemented. Reviewed By: Conrad git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@6283 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
8 changed files
with
735 additions
and
0 deletions
lib/browse/Criteria.inc
| ... | ... | @@ -1041,7 +1041,46 @@ class TransactionTextCriterion extends BrowseCriterion { |
| 1041 | 1041 | } |
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | +class TagCloudCriterion extends BrowseCriterion { | |
| 1045 | + var $bString = true; | |
| 1046 | + var $bContains = false; | |
| 1047 | + var $bHandleNot = false; | |
| 1048 | + var $sDocumentField = 'tag';// this is linked to the field | |
| 1049 | + var $sSortField = 'tag'; | |
| 1050 | + var $sNamespace = 'ktcore.criteria.tagcloud'; | |
| 1051 | + var $sSearchTable = "TWS" ; | |
| 1052 | + | |
| 1053 | + function TagCloudCriterion() { | |
| 1054 | + $this->sDisplay = _kt('Tag Cloud'); | |
| 1055 | + } | |
| 1056 | + | |
| 1057 | + function documentDisplay ($oDocument) { | |
| 1058 | + return "Tag Cloud"; | |
| 1059 | + } | |
| 1060 | + function getName() { | |
| 1061 | + return "tagcloud"; | |
| 1062 | + } | |
| 1063 | + | |
| 1064 | + function searchSQL ($aRequest) { | |
| 1065 | + $p = parent::searchSQL($aRequest, false); // handle not ourselves. | |
| 1066 | + | |
| 1067 | + // handle the boolean "not" stuff. | |
| 1068 | + $want_invert = KTUtil::arrayGet($aRequest, $this->getWidgetBase() . '_not'); | |
| 1069 | + if (is_null($want_invert) || ($want_invert == "0")) { | |
| 1070 | + return $p; | |
| 1071 | + } else { | |
| 1072 | + $p[0] = '(NOT (' . $p[0] . '))'; | |
| 1073 | + } | |
| 1074 | + | |
| 1075 | + return $p; | |
| 1076 | + } | |
| 1044 | 1077 | |
| 1078 | + function searchJoinSQL () { | |
| 1079 | + global $default; | |
| 1080 | + return "INNER JOIN document_tags AS DTS ON DTS.document_id = D.id | |
| 1081 | + INNER JOIN tag_words AS TWS ON tws.id = DTS.tag_id"; | |
| 1082 | + } | |
| 1083 | +} | |
| 1045 | 1084 | |
| 1046 | 1085 | class DateCreatedDeltaCriterion extends DateCreatedCriterion { |
| 1047 | 1086 | var $sDocumentField = 'created'; | ... | ... |
lib/browse/criteriaregistry.php
| ... | ... | @@ -44,6 +44,7 @@ class KTCriteriaRegistry { |
| 44 | 44 | foreach($aFields as $oField) { |
| 45 | 45 | $sNamespace = $oField->getNamespace(); |
| 46 | 46 | $oFieldset =& KTFieldset::get($oField->getParentFieldset()); |
| 47 | + if(is_null($oFieldset->userinfo)){continue;} | |
| 47 | 48 | $aInitialize = array(sprintf("%s: %s", $oFieldset->getName(), $oField->getName()), 'id', 'id', $oField->getId(), $sNamespace); |
| 48 | 49 | $this->registerCriterion('GenericMetadataCriterion', $sNamespace, null, $aInitialize); |
| 49 | 50 | } | ... | ... |
lib/documentmanagement/documentutil.inc.php
| ... | ... | @@ -422,6 +422,7 @@ class KTDocumentUtil { |
| 422 | 422 | |
| 423 | 423 | // {{{ _in_add |
| 424 | 424 | function &_in_add($oFolder, $sFilename, $oUser, $aOptions) { |
| 425 | + $aOrigOptions = $aOptions; | |
| 425 | 426 | if (KTDocumentUtil::fileExists($oFolder, $sFilename)) { |
| 426 | 427 | $oDoc = Document::getByFilenameAndFolder($sFilename, $oFolder->getId()); |
| 427 | 428 | if (PEAR::isError($oDoc)) { |
| ... | ... | @@ -514,6 +515,7 @@ class KTDocumentUtil { |
| 514 | 515 | $oTrigger = new $sTrigger; |
| 515 | 516 | $aInfo = array( |
| 516 | 517 | "document" => $oDocument, |
| 518 | + 'aOptions' => $aOrigOptions, | |
| 517 | 519 | ); |
| 518 | 520 | $oTrigger->setInfo($aInfo); |
| 519 | 521 | $ret = $oTrigger->postValidate(); | ... | ... |
plugins/ktcore/document/edit.php
| ... | ... | @@ -205,6 +205,7 @@ class KTDocumentEditAction extends KTDocumentAction { |
| 205 | 205 | $oTrigger = new $sTrigger; |
| 206 | 206 | $aInfo = array( |
| 207 | 207 | "document" => $this->oDocument, |
| 208 | + "aOptions" => $MDPack, | |
| 208 | 209 | ); |
| 209 | 210 | $oTrigger->setInfo($aInfo); |
| 210 | 211 | $ret = $oTrigger->postValidate(); | ... | ... |
plugins/tagcloud/TagCloudDashlet.php
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * $Id: TagCloudDashlet.php,v 1.1 2006/02/28 16:53:49 nbm Exp $ | |
| 5 | + * | |
| 6 | + * Copyright (c) 2007 Jam Warehouse http://www.jamwarehouse.com | |
| 7 | + * | |
| 8 | + * This program is free software; you can redistribute it and/or modify | |
| 9 | + * it under the terms of the GNU General Public License as published by | |
| 10 | + * the Free Software Foundation; using version 2 of the License. | |
| 11 | + * | |
| 12 | + * This program is distributed in the hope that it will be useful, | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | + * GNU General Public License for more details. | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License | |
| 18 | + * along with this program; if not, write to the Free Software | |
| 19 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 20 | + * | |
| 21 | + * ------------------------------------------------------------------------- | |
| 22 | + * | |
| 23 | + * You can contact the copyright owner regarding licensing via the contact | |
| 24 | + * details that can be found on the KnowledgeTree web site: | |
| 25 | + * | |
| 26 | + * http://www.knowledgetree.com/ | |
| 27 | + */ | |
| 28 | + | |
| 29 | + | |
| 30 | +require_once(KT_LIB_DIR . '/browse/browseutil.inc.php'); | |
| 31 | +require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php'); | |
| 32 | +require_once(KT_LIB_DIR . '/plugins/plugin.inc.php'); | |
| 33 | + | |
| 34 | +class TagCloudDashlet extends KTBaseDashlet { | |
| 35 | + var $oUser; | |
| 36 | + var $sClass = 'ktBlock'; | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * Constructor method | |
| 40 | + * | |
| 41 | + * @return TagCloudDashlet | |
| 42 | + */ | |
| 43 | + function TagCloudDashlet(){ | |
| 44 | + $this->sTitle = _kt('Tag Cloud'); | |
| 45 | + } | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Check to see if user is active | |
| 49 | + * | |
| 50 | + * @param object $oUser | |
| 51 | + * @return boolean | |
| 52 | + */ | |
| 53 | + function is_active($oUser) { | |
| 54 | + $this->oUser = $oUser; | |
| 55 | + return true; | |
| 56 | + } | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Render function for template | |
| 60 | + * | |
| 61 | + * @return unknown | |
| 62 | + */ | |
| 63 | + function render() { | |
| 64 | + $oTemplating =& KTTemplating::getSingleton(); | |
| 65 | + $oTemplate = $oTemplating->loadTemplate('TagCloud/dashlet'); | |
| 66 | + | |
| 67 | + $aTags = & $this->get_relevant_tags(); | |
| 68 | + $aTags = & $this->get_tag_weightings($aTags); | |
| 69 | + | |
| 70 | + $oRegistry =& KTPluginRegistry::getSingleton(); | |
| 71 | + $oPlugin =& $oRegistry->getPlugin('ktcore.tagcloud.plugin'); | |
| 72 | + $url = $oPlugin->getPagePath('TagCloudRedirection'); | |
| 73 | + | |
| 74 | + $aTemplateData = array( | |
| 75 | + 'tags' => $aTags, | |
| 76 | + 'url'=>$url | |
| 77 | + ); | |
| 78 | + return $oTemplate->render($aTemplateData); | |
| 79 | + } | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * Builds the weightings for tags based on their frequency | |
| 83 | + * | |
| 84 | + * @param array $aTags | |
| 85 | + * @return array | |
| 86 | + */ | |
| 87 | + function & get_tag_weightings(&$aTags) | |
| 88 | + { | |
| 89 | + $aTags = $this->get_relevant_tags(); | |
| 90 | + | |
| 91 | + if (count($aTags) == 0) $min_freq=$max_freq=0; | |
| 92 | + else | |
| 93 | + { | |
| 94 | + $min_freq = min(array_values($aTags)); | |
| 95 | + $max_freq = max(array_values($aTags)); | |
| 96 | + } | |
| 97 | + $min_size = 12; | |
| 98 | + $max_size = 30; | |
| 99 | + | |
| 100 | + $distrib = $max_freq - $min_freq; | |
| 101 | + if ($distrib == 0) $distrib=1; | |
| 102 | + | |
| 103 | + $step = ($max_size - $min_size)/($distrib); | |
| 104 | + | |
| 105 | + foreach($aTags as $tag=>$freq) | |
| 106 | + { | |
| 107 | + $size = ceil($min_size + (($freq - $min_freq) * $step)); | |
| 108 | + $aTags[$tag] = $size; | |
| 109 | + } | |
| 110 | + | |
| 111 | + return $aTags; | |
| 112 | + } | |
| 113 | + | |
| 114 | + /** | |
| 115 | + * Returns the relevant tags for the current user | |
| 116 | + * | |
| 117 | + * @return array | |
| 118 | + */ | |
| 119 | + function & get_relevant_tags() | |
| 120 | + { | |
| 121 | + | |
| 122 | + list($where, $params, $joins) = KTSearchUtil::permissionToSQL($this->oUser, null); | |
| 123 | + | |
| 124 | + | |
| 125 | + $sql = " | |
| 126 | + SELECT | |
| 127 | + tw.tag, count(*) as freq | |
| 128 | + FROM | |
| 129 | + document_tags dt INNER JOIN tag_words tw ON dt.tag_id=tw.id | |
| 130 | + WHERE dt.document_id in (SELECT d.id FROM documents d $joins WHERE $where) GROUP BY tw.tag"; | |
| 131 | + | |
| 132 | + | |
| 133 | + $tags = DBUtil::getResultArray( | |
| 134 | + array($sql,$params) | |
| 135 | + | |
| 136 | + ); | |
| 137 | + $aTags = array(); | |
| 138 | + foreach($tags as $tag) | |
| 139 | + { | |
| 140 | + $word=$tag['tag']; | |
| 141 | + $freq=$tag['freq']; | |
| 142 | + $aTags[$word] = $freq; | |
| 143 | + } | |
| 144 | + return $aTags; | |
| 145 | + | |
| 146 | + } | |
| 147 | + | |
| 148 | +} | |
| 149 | +?> | ... | ... |
plugins/tagcloud/TagCloudPlugin.php
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * $Id: TagCloudPlugin.php,v 1.1 2006/02/28 16:53:49 nbm Exp $ | |
| 5 | + * | |
| 6 | + * Copyright (c) 2006 Jam Warehouse http://www.jamwarehouse.com | |
| 7 | + * | |
| 8 | + * This program is free software; you can redistribute it and/or modify | |
| 9 | + * it under the terms of the GNU General Public License as published by | |
| 10 | + * the Free Software Foundation; using version 2 of the License. | |
| 11 | + * | |
| 12 | + * This program is distributed in the hope that it will be useful, | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | + * GNU General Public License for more details. | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License | |
| 18 | + * along with this program; if not, write to the Free Software | |
| 19 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 20 | + * | |
| 21 | + * ------------------------------------------------------------------------- | |
| 22 | + * | |
| 23 | + * You can contact the copyright owner regarding licensing via the contact | |
| 24 | + * details that can be found on the KnowledgeTree web site: | |
| 25 | + * | |
| 26 | + * http://www.ktdms.com/ | |
| 27 | + */ | |
| 28 | + | |
| 29 | +require_once(KT_LIB_DIR . '/plugins/plugin.inc.php'); | |
| 30 | +require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php'); | |
| 31 | +require_once('TagCloudRedirectPage.php'); | |
| 32 | +require_once(KT_LIB_DIR . '/templating/templating.inc.php'); | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * Tag Cloud Plugin class | |
| 36 | + * | |
| 37 | + */ | |
| 38 | + class TagCloudPlugin extends KTPlugin{ | |
| 39 | + | |
| 40 | + var $sNamespace = 'ktcore.tagcloud.plugin'; | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * Constructor method for plugin | |
| 44 | + * | |
| 45 | + * @param string $sFilename | |
| 46 | + * @return TagCloudPlugin | |
| 47 | + */ | |
| 48 | + function TagCloudPlugin($sFilename = null) { | |
| 49 | + $res = parent::KTPlugin($sFilename); | |
| 50 | + $this->sFriendlyName = _kt('Tag Cloud Plugin'); | |
| 51 | + return $res; | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Setup function for plugin | |
| 56 | + * | |
| 57 | + */ | |
| 58 | + function setup() { | |
| 59 | + // Register plugin components | |
| 60 | + $this->registerCriterion('TagCloudCriterion', 'ktcore.criteria.tagcloud', KT_LIB_DIR . '/browse/Criteria.inc'); | |
| 61 | + $this->registerDashlet('TagCloudDashlet', 'ktcore.tagcloud.feed.dashlet', 'TagCloudDashlet.php'); | |
| 62 | + $this->registerPage('TagCloudRedirection', 'TagCloudRedirectPage', __FILE__); | |
| 63 | + $this->registerTrigger('add', 'postValidate', 'KTAddDocumentTrigger', | |
| 64 | + 'ktcore.triggers.tagcloud.add'); | |
| 65 | + $this->registerTrigger('edit', 'postValidate', 'KTEditDocumentTrigger', | |
| 66 | + 'ktcore.triggers.tagcloud.edit'); | |
| 67 | + | |
| 68 | + // Check if the tagcloud fielset entry exists, if not, create it | |
| 69 | + if(!TagCloudPlugin::tagFieldsetExists()){ | |
| 70 | + $oFieldset = TagCloudPlugin::createFieldset(); | |
| 71 | + if (PEAR::isError($oFieldset)) { | |
| 72 | + return false; | |
| 73 | + } | |
| 74 | + if($oFieldset){ | |
| 75 | + // make the fieldset id viewable | |
| 76 | + $iFieldsetId = $oFieldset->iId; | |
| 77 | + } | |
| 78 | + }else{ // if the entry exists, make the fieldset id viewable anyway | |
| 79 | + $iFieldsetId = TagCloudPlugin::tagFieldsetExists(); | |
| 80 | + } | |
| 81 | + | |
| 82 | + // Check if the tagcloud document field entry exists, if not, create it | |
| 83 | + if(!TagCloudPlugin::tagFieldExists()){ | |
| 84 | + $oField = TagCloudPlugin::createDocumentField($iFieldsetId); | |
| 85 | + if (PEAR::isError($oField)) { | |
| 86 | + return false; | |
| 87 | + } | |
| 88 | + } | |
| 89 | + | |
| 90 | + $oTemplating =& KTTemplating::getSingleton(); | |
| 91 | + $oTemplating->addLocation('Tag Cloud Plugin', '/plugins/tagcloud/templates'); | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * function to add fieldset entry to fieldsets table | |
| 96 | + * | |
| 97 | + * @return unknown | |
| 98 | + */ | |
| 99 | + function createFieldset(){ | |
| 100 | + // create the fieldsets entry | |
| 101 | + $oFieldset = KTFieldset::createFromArray(array( | |
| 102 | + 'name' => 'Tag Cloud', | |
| 103 | + 'description' => 'Tag Cloud', | |
| 104 | + 'namespace' => 'tagcloud', | |
| 105 | + 'mandatory' => false, | |
| 106 | + 'isConditional' => false, | |
| 107 | + 'isGeneric' => true, | |
| 108 | + 'isComplete' => false, | |
| 109 | + 'isComplex' => false, | |
| 110 | + 'isSystem' => false, | |
| 111 | + )); | |
| 112 | + | |
| 113 | + return $oFieldset; | |
| 114 | + } | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * function to add the tagcloud entry to the document_fields table | |
| 118 | + * | |
| 119 | + * @param int $parentId | |
| 120 | + * @return int $id | |
| 121 | + */ | |
| 122 | + function createDocumentField($parentId){ | |
| 123 | + // create the document_field entry | |
| 124 | + $id = DocumentField::createFromArray(array( | |
| 125 | + 'Name' => 'Tag', | |
| 126 | + 'Description' => 'Tag Words', | |
| 127 | + 'DataType' => 'STRING', | |
| 128 | + 'IsGeneric' => false, | |
| 129 | + 'HasLookup' => false, | |
| 130 | + 'HasLookupTree' => false, | |
| 131 | + 'ParentFieldset' => $parentId, | |
| 132 | + 'IsMandatory' => false, | |
| 133 | + )); | |
| 134 | + | |
| 135 | + return $id; | |
| 136 | + } | |
| 137 | + | |
| 138 | + /** | |
| 139 | + * function to check if the Tag field exists in the document_fields table | |
| 140 | + * | |
| 141 | + * @return boolean | |
| 142 | + */ | |
| 143 | + function tagFieldExists(){ | |
| 144 | + $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' . | |
| 145 | + 'WHERE df.name = \'Tag\''; | |
| 146 | + $sTag = DBUtil::getOneResultKey(array($sQuery), 'id'); | |
| 147 | + | |
| 148 | + if (PEAR::isError($sTag)) { | |
| 149 | + // XXX: log error | |
| 150 | + return false; | |
| 151 | + | |
| 152 | + } | |
| 153 | + if(!is_null($sTag)){ | |
| 154 | + return $sTag; | |
| 155 | + }else{ | |
| 156 | + return false; | |
| 157 | + } | |
| 158 | + } | |
| 159 | + | |
| 160 | + /** | |
| 161 | + * function to check if the fieldset exists in the database | |
| 162 | + * | |
| 163 | + * @return boolean | |
| 164 | + */ | |
| 165 | + function tagFieldsetExists(){ | |
| 166 | + $sQuery = 'SELECT fs.id AS id FROM fieldsets AS fs '. | |
| 167 | + 'WHERE namespace = \'tagcloud\''; | |
| 168 | + $iFieldset = DBUtil::getOneResultKey(array($sQuery), 'id'); | |
| 169 | + | |
| 170 | + if (PEAR::isError($iFieldset)) { | |
| 171 | + // XXX: log error | |
| 172 | + return false; | |
| 173 | + | |
| 174 | + } | |
| 175 | + if(!is_null($iFieldset)){ | |
| 176 | + return $iFieldset; | |
| 177 | + }else{ | |
| 178 | + return false; | |
| 179 | + } | |
| 180 | + } | |
| 181 | + } | |
| 182 | +$oPluginRegistry =& KTPluginRegistry::getSingleton(); | |
| 183 | +$oPluginRegistry->registerPlugin('TagCloudPlugin', 'ktcore.tagcloud.plugin', __FILE__); | |
| 184 | + | |
| 185 | +/** | |
| 186 | + * Trigger for document add (postValidate) | |
| 187 | + * | |
| 188 | + */ | |
| 189 | +class KTAddDocumentTrigger { | |
| 190 | + var $aInfo = null; | |
| 191 | + /** | |
| 192 | + * function to set the info for the trigger | |
| 193 | + * | |
| 194 | + * @param array $aInfo | |
| 195 | + */ | |
| 196 | + function setInfo(&$aInfo) { | |
| 197 | + $this->aInfo =& $aInfo; | |
| 198 | + } | |
| 199 | + | |
| 200 | + /** | |
| 201 | + * postValidate method for trigger | |
| 202 | + * | |
| 203 | + * @return unknown | |
| 204 | + */ | |
| 205 | + function postValidate() { | |
| 206 | + global $default; | |
| 207 | + $oDocument =& $this->aInfo['document']; | |
| 208 | + $aMeta = & $this->aInfo['aOptions']; | |
| 209 | + | |
| 210 | + $iDocId = $oDocument->getID(); | |
| 211 | + | |
| 212 | + // get tag id from document_fields table where name = Tag | |
| 213 | + $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' . | |
| 214 | + 'WHERE df.name = \'Tag\''; | |
| 215 | + | |
| 216 | + $sTags = DBUtil::getOneResultKey(array($sQuery), 'id'); | |
| 217 | + if (PEAR::isError($sTags)) { | |
| 218 | + // XXX: log error | |
| 219 | + return false; | |
| 220 | + } | |
| 221 | + $tagString = ''; | |
| 222 | + // add tags | |
| 223 | + if ($sTags) { | |
| 224 | + foreach($aMeta[metadata] as $aMetaData){ | |
| 225 | + $oProxy = $aMetaData[0]; | |
| 226 | + if($oProxy->iId == $sTags){ | |
| 227 | + $tagString = $aMetaData[1]; | |
| 228 | + } | |
| 229 | + } | |
| 230 | + if($tagString != ''){ | |
| 231 | + $words_table = KTUtil::getTableName('tag_words'); | |
| 232 | + $tagString = str_replace(' ', '', $tagString); | |
| 233 | + $tags = explode(',',$tagString); | |
| 234 | + | |
| 235 | + $aTagIds = array(); | |
| 236 | + | |
| 237 | + foreach($tags as $sTag) | |
| 238 | + { | |
| 239 | + $sTag=strtolower(trim($sTag)); | |
| 240 | + | |
| 241 | + $res = DBUtil::getOneResult(array("SELECT id FROM $words_table WHERE tag = ?", array($sTag))); | |
| 242 | + | |
| 243 | + if (PEAR::isError($res)) { | |
| 244 | + return $res; | |
| 245 | + } | |
| 246 | + | |
| 247 | + if (is_null($res)) | |
| 248 | + { | |
| 249 | + $id = & DBUtil::autoInsert($words_table, array('tag'=>$sTag)); | |
| 250 | + $aTagIds[$sTag] = $id; | |
| 251 | + } | |
| 252 | + else | |
| 253 | + { | |
| 254 | + $aTagIds[$sTag] = $res['id']; | |
| 255 | + } | |
| 256 | + } | |
| 257 | + | |
| 258 | + $doc_tags = KTUtil::getTableName('document_tags'); | |
| 259 | + | |
| 260 | + foreach($aTagIds as $sTag=>$tagid) | |
| 261 | + { | |
| 262 | + DBUtil::autoInsert($doc_tags, array( | |
| 263 | + | |
| 264 | + 'document_id'=>$iDocId, | |
| 265 | + 'tag_id'=>$tagid), | |
| 266 | + array('noid'=>true)); | |
| 267 | + } | |
| 268 | + } | |
| 269 | + } | |
| 270 | + } | |
| 271 | +} | |
| 272 | + | |
| 273 | +/** | |
| 274 | + * Trigger for document edit (postValidate) | |
| 275 | + * | |
| 276 | + */ | |
| 277 | +class KTEditDocumentTrigger { | |
| 278 | + var $aInfo = null; | |
| 279 | + /** | |
| 280 | + * function to set the info for the trigger | |
| 281 | + * | |
| 282 | + * @param array $aInfo | |
| 283 | + */ | |
| 284 | + function setInfo(&$aInfo) { | |
| 285 | + $this->aInfo =& $aInfo; | |
| 286 | + } | |
| 287 | + | |
| 288 | + /** | |
| 289 | + * postValidate method for trigger | |
| 290 | + * | |
| 291 | + * @return unknown | |
| 292 | + */ | |
| 293 | + function postValidate() { | |
| 294 | + global $default; | |
| 295 | + $oDocument =& $this->aInfo['document']; | |
| 296 | + $aMeta = & $this->aInfo['aOptions']; | |
| 297 | + // get document id | |
| 298 | + $iDocId = $oDocument->getID(); | |
| 299 | + | |
| 300 | + // get all tags that are linked to the document | |
| 301 | + $sQuery = 'SELECT tw.id FROM tag_words AS tw, document_tags AS dt, documents AS d ' . | |
| 302 | + 'WHERE dt.tag_id = tw.id ' . | |
| 303 | + 'AND dt.document_id = d.id ' . | |
| 304 | + 'AND d.id = ?'; | |
| 305 | + $aParams = array($iDocId); | |
| 306 | + $aTagId = DBUtil::getResultArray(array($sQuery, $aParams)); | |
| 307 | + if (PEAR::isError($aTagId)) { | |
| 308 | + // XXX: log error | |
| 309 | + return false; | |
| 310 | + } | |
| 311 | + // if there are any related tags proceed | |
| 312 | + if ($aTagId) { | |
| 313 | + // delete all entries from document_tags table for the document | |
| 314 | + $sQuery = 'DELETE FROM document_tags ' . | |
| 315 | + 'WHERE document_id = ?'; | |
| 316 | + $aParams = array($iDocId); | |
| 317 | + $removed = DBUtil::runQuery(array($sQuery, $aParams)); | |
| 318 | + if (PEAR::isError($removed)) { | |
| 319 | + // XXX: log error | |
| 320 | + return false; | |
| 321 | + } | |
| 322 | + } | |
| 323 | + // proceed to add the tags as per normal | |
| 324 | + if($res){ | |
| 325 | + $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' . | |
| 326 | + 'WHERE df.name = \'Tag\''; | |
| 327 | + | |
| 328 | + $sTags = DBUtil::getOneResultKey(array($sQuery), 'id'); | |
| 329 | + if (PEAR::isError($sTags)) { | |
| 330 | + // XXX: log error | |
| 331 | + return false; | |
| 332 | + } | |
| 333 | + $tagString = ''; | |
| 334 | + if ($sTags) { | |
| 335 | + foreach($aMeta as $aMetaData){ | |
| 336 | + $oProxy = $aMetaData[0]; | |
| 337 | + if($oProxy->iId == $sTags){ | |
| 338 | + $tagString = $aMetaData[1]; | |
| 339 | + break; | |
| 340 | + } | |
| 341 | + } | |
| 342 | + if($tagString != ''){ | |
| 343 | + $words_table = KTUtil::getTableName('tag_words'); | |
| 344 | + $tagString = str_replace(' ', ' ', $tagString); | |
| 345 | + $tags = explode(',',$tagString); | |
| 346 | + | |
| 347 | + $aTagIds = array(); | |
| 348 | + | |
| 349 | + foreach($tags as $sTag) | |
| 350 | + { | |
| 351 | + $sTag=strtolower(trim($sTag)); | |
| 352 | + | |
| 353 | + $res = DBUtil::getOneResult(array("SELECT id FROM $words_table WHERE tag = ?", array($sTag))); | |
| 354 | + | |
| 355 | + if (PEAR::isError($res)) { | |
| 356 | + return $res; | |
| 357 | + } | |
| 358 | + | |
| 359 | + if (is_null($res)) | |
| 360 | + { | |
| 361 | + $id = & DBUtil::autoInsert($words_table, array('tag'=>$sTag)); | |
| 362 | + $aTagIds[$sTag] = $id; | |
| 363 | + } | |
| 364 | + else | |
| 365 | + { | |
| 366 | + $aTagIds[$sTag] = $res['id']; | |
| 367 | + } | |
| 368 | + } | |
| 369 | + | |
| 370 | + $doc_tags = KTUtil::getTableName('document_tags'); | |
| 371 | + | |
| 372 | + foreach($aTagIds as $sTag=>$tagid) | |
| 373 | + { | |
| 374 | + DBUtil::autoInsert($doc_tags, array( | |
| 375 | + 'document_id'=>$iDocId, | |
| 376 | + 'tag_id'=>$tagid), | |
| 377 | + array('noid'=>true)); | |
| 378 | + } | |
| 379 | + } | |
| 380 | + } | |
| 381 | + } | |
| 382 | + } | |
| 383 | +} | |
| 384 | +?> | ... | ... |
plugins/tagcloud/TagCloudRedirectPage.php
0 → 100644
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * $Id: TagCloudRedirectPage.php,v 1.1 2006/02/28 16:53:49 nbm Exp $ | |
| 4 | + * | |
| 5 | + * Copyright (c) 2006 Jam Warehouse http://www.jamwarehouse.com | |
| 6 | + * | |
| 7 | + * This program is free software; you can redistribute it and/or modify | |
| 8 | + * it under the terms of the GNU General Public License as published by | |
| 9 | + * the Free Software Foundation; using version 2 of the License. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU General Public License | |
| 17 | + * along with this program; if not, write to the Free Software | |
| 18 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | + * | |
| 20 | + * ------------------------------------------------------------------------- | |
| 21 | + * | |
| 22 | + * You can contact the copyright owner regarding licensing via the contact | |
| 23 | + * details that can be found on the KnowledgeTree web site: | |
| 24 | + * | |
| 25 | + * http://www.ktdms.com/ | |
| 26 | + **/ | |
| 27 | + | |
| 28 | +require_once(KT_LIB_DIR . '/plugins/plugin.inc.php'); | |
| 29 | +require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php'); | |
| 30 | +require_once(KT_LIB_DIR . '/templating/templating.inc.php'); | |
| 31 | +require_once(KT_LIB_DIR . '/database/dbutil.inc'); | |
| 32 | +require_once(KT_LIB_DIR . '/util/ktutil.inc'); | |
| 33 | +require_once(KT_LIB_DIR . '/dispatcher.inc.php'); | |
| 34 | +require_once(KT_LIB_DIR . '/browse/Criteria.inc'); | |
| 35 | +require_once(KT_LIB_DIR . '/search/savedsearch.inc.php'); | |
| 36 | +require_once(KT_LIB_DIR . '/search/searchutil.inc.php'); | |
| 37 | + | |
| 38 | +require_once(KT_LIB_DIR . '/browse/DocumentCollection.inc.php'); | |
| 39 | +require_once(KT_LIB_DIR . '/browse/BrowseColumns.inc.php'); | |
| 40 | +require_once(KT_LIB_DIR . '/browse/PartialQuery.inc.php'); | |
| 41 | + | |
| 42 | +require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php'); | |
| 43 | +require_once(KT_LIB_DIR . '/actions/bulkaction.php'); | |
| 44 | + | |
| 45 | +class TagCloudRedirectPage extends KTStandardDispatcher { | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Dispatcher main method | |
| 49 | + * | |
| 50 | + * @return unknown | |
| 51 | + */ | |
| 52 | + function do_main() { | |
| 53 | + $searchable_text = KTUtil::arrayGet($_REQUEST, 'tag'); | |
| 54 | + // set breadcrumbs | |
| 55 | + $this->aBreadcrumbs[] = array('url' => 'dashboard.php', 'name' => _kt('Dashboard')); | |
| 56 | + $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'].'&tag='.$searchable_text, 'name' => _kt('Tag Cloud Search')); | |
| 57 | + // set page title | |
| 58 | + $sTitle = _kt('Search Results'); | |
| 59 | + | |
| 60 | + $this->oPage->setBreadcrumbDetails($sTitle); | |
| 61 | + | |
| 62 | + // build criteria set | |
| 63 | + $aCriteriaSet = array( | |
| 64 | + 'join'=>'AND', | |
| 65 | + 'subgroup'=>array( | |
| 66 | + 0=>array( | |
| 67 | + 'join'=>'AND', | |
| 68 | + 'values'=>array( | |
| 69 | + 1=>array( | |
| 70 | + 'data'=>array( | |
| 71 | + 'ktcore.criteria.tagcloud'=>$searchable_text, | |
| 72 | + 'ktcore.criteria.tagcloud_not'=>0 | |
| 73 | + ), | |
| 74 | + 'type'=>'ktcore.criteria.tagcloud' | |
| 75 | + ) | |
| 76 | + ) | |
| 77 | + ) | |
| 78 | + ) | |
| 79 | + ); | |
| 80 | + | |
| 81 | + | |
| 82 | + $this->browseType = 'Folder'; | |
| 83 | + $sSearch = md5(serialize($aCriteriaSet)); | |
| 84 | + $_SESSION['boolean_search'][$sSearch] = $aCriteriaSet; | |
| 85 | + | |
| 86 | + $collection = new AdvancedCollection; | |
| 87 | + $oColumnRegistry = KTColumnRegistry::getSingleton(); | |
| 88 | + $aColumns = $oColumnRegistry->getColumnsForView('ktcore.views.search'); | |
| 89 | + $collection->addColumns($aColumns); | |
| 90 | + | |
| 91 | + // set a view option | |
| 92 | + $aTitleOptions = array( | |
| 93 | + 'documenturl' => $GLOBALS['KTRootUrl'] . '/view.php', | |
| 94 | + ); | |
| 95 | + $collection->setColumnOptions('ktcore.columns.title', $aTitleOptions); | |
| 96 | + $collection->setColumnOptions('ktcore.columns.selection', array( | |
| 97 | + 'rangename' => 'selection', | |
| 98 | + 'show_folders' => true, | |
| 99 | + 'show_documents' => true, | |
| 100 | + )); | |
| 101 | + | |
| 102 | + $aOptions = $collection->getEnvironOptions(); // extract data from the environment | |
| 103 | + | |
| 104 | + $aOptions['return_url'] = KTUtil::addQueryString('dashboard.php', false); | |
| 105 | + $aOptions['empty_message'] = _kt('No documents or folders match this query.'); | |
| 106 | + $aOptions['is_browse'] = true; | |
| 107 | + | |
| 108 | + $collection->setOptions($aOptions); | |
| 109 | + $collection->setQueryObject(new BooleanSearchQuery($aCriteriaSet)); | |
| 110 | + | |
| 111 | + $oTemplating =& KTTemplating::getSingleton(); | |
| 112 | + $oTemplate = $oTemplating->loadTemplate('kt3/browse'); | |
| 113 | + $aTemplateData = array( | |
| 114 | + 'context' => $this, | |
| 115 | + 'collection' => $collection, | |
| 116 | + 'custom_title' => $sTitle, | |
| 117 | + 'isEditable' => true, | |
| 118 | + 'boolean_search' => $sSearch, | |
| 119 | + 'bulkactions' => KTBulkActionUtil::getAllBulkActions(), | |
| 120 | + 'browseutil' => new KTBrowseUtil(), | |
| 121 | + 'returnaction' => 'booleanSearch', | |
| 122 | + 'returndata' => $sSearch, | |
| 123 | + | |
| 124 | + ); | |
| 125 | + return $oTemplate->render($aTemplateData); | |
| 126 | + | |
| 127 | + } | |
| 128 | +} | |
| 129 | +?> | ... | ... |
plugins/tagcloud/templates/TagCloud/dashlet.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 | + | |
| 15 | +There are no tags defined or accessible. | |
| 16 | + | |
| 17 | +{else} | |
| 18 | +<div id=tagcloud> | |
| 19 | +{foreach from=$tags key=tag item=size} | |
| 20 | + | |
| 21 | + <a href="{$url}&tag={$tag|urlencode}" style="font-size: {$size}px">{$tag}</a> | |
| 22 | + | |
| 23 | +{/foreach} | |
| 24 | +</div> | |
| 25 | +{/if} | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | +<br> | |
| 30 | +<br> | ... | ... |