Changeset 1091
- Timestamp:
- 12/22/09 22:02:05 (3 years ago)
- Location:
- taggingreloaded
- Files:
-
- 5 modified
-
files/lib/action/TaggingReloadedSaveAction.class.php (modified) (4 diffs)
-
files/lib/system/event/listener/TaggingReloadedMessageFormListener.class.php (modified) (4 diffs)
-
files/lib/util/TaggingReloadedUtil.class.php (modified) (2 diffs)
-
optionals/de.easy-coding.wbb.taggingreloaded/files/lib/system/event/listener/TaggingReloadedWBBPageListener.class.php (modified) (1 diff)
-
templates/taggingReloadedSidebar.tpl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
taggingreloaded/files/lib/action/TaggingReloadedSaveAction.class.php
r1087 r1091 12 12 */ 13 13 class TaggingReloadedSaveAction extends AbstractAction { 14 protected $taggable ID = 0;14 protected $taggable = ''; 15 15 protected $className = ''; 16 protected $classPath = ''; 16 17 protected $entryKey = 'entryID'; 17 protected $ entryID = 0;18 protected $objectID = 0; 18 19 protected $languageID = 0; 19 20 … … 24 25 parent::readParameters(); 25 26 26 $this->taggableID = intval($_REQUEST['taggableID']);27 27 $this->className = $_REQUEST['className']; 28 $this->entryID = intval($_REQUEST['entryID']); 28 $this->classPath = $_REQUEST['classPath']; 29 $this->objectID = intval($_REQUEST['objectID']); 29 30 30 if(isset($_REQUEST['entryKey']) $this->entryKey = $_REQUEST['entryKey']; 31 if(isset($_REQUEST['languageID']) $this->languageID = intval($_REQUEST['languageID']); 31 if(isset($_REQUEST['entryKey'])) $this->entryKey = $_REQUEST['entryKey']; 32 if(isset($_REQUEST['languageID'])) $this->languageID = intval($_REQUEST['languageID']); 33 if(isset($_REQUEST['taggable'])) $this->taggable = $_REQUEST['taggable']; 34 35 $this->tags3 = TaggingReloadedUtil::readFormParameters(); 32 36 } 33 37 … … 38 42 parent::execute(); 39 43 40 $tagged = new $this->className(array( 41 $this->entryKey => $this->entryID, 44 if(!preg_match('/^Tagged/', $this->className) || preg_match('/\./', $this->className)) { 45 throw new PermissionDeniedException(); 46 } 47 48 $classPath = WCF_DIR.'lib/data/'.$this->classPath.'/'.$this->className.'.class.php'; 49 50 if(preg_match('/\./', $this->classPath) || !file_exists($classPath)) { 51 throw new PermissionDeniedException(); 52 } 53 54 require_once $classPath; 55 56 $tagged = new $this->className(null, array( 57 $this->entryKey => $this->objectID, 42 58 'taggable' => TagEngine::getInstance()->getTaggable($this->taggable) 43 59 )); … … 47 63 } 48 64 49 TaggingUtil::save($userid. $tags, $tagged, $this->languageID); 65 $userID = WCF::getUser()->userID; 66 67 $existingTagsUser = TaggingReloadedUtil::getTagsByObject($userID, $tagged, $this->languageID, true); 68 $existingTagsObject = TaggingReloadedUtil::getTagsByObject($userID, $tagged, $this->languageID, false); 69 TaggingReloadedUtil::tagging3save($userID, $tagged, $this->languageID, $this->tags3, $existingTagsUser, $existingTagsObject); 50 70 51 71 $this->executed(); -
taggingreloaded/files/lib/system/event/listener/TaggingReloadedMessageFormListener.class.php
r1079 r1091 2 2 // wcf imports 3 3 require_once(WCF_DIR.'lib/system/event/EventListener.class.php'); 4 require_once(WCF_DIR.'lib/data/tag/Tag.class.php');5 require_once(WCF_DIR.'lib/data/tag/TagEngine.class.php');6 4 7 5 // tagging3 imports … … 65 63 */ 66 64 protected function readFormParameters() { 67 68 // handle reloaded input 69 if (isset($_REQUEST['taggingname']) && isset($_REQUEST['taggingval'])) { 70 if(count($_REQUEST['taggingname']) > count($_REQUEST['taggingval'])) { 71 $_REQUEST['taggingval'] = array_slice($_REQUEST['taggingval'], 0, count($_REQUEST['taggingname'])); 72 } else if(count($_REQUEST['taggingname']) < count($_REQUEST['taggingval'])) { 73 $_REQUEST['taggingname'] = array_slice($_REQUEST['taggingname'], 0, count($_REQUEST['taggingval'])); 74 } 75 $this->tags3 = array_combine($_REQUEST['taggingname'], $_REQUEST['taggingval']); 76 } 77 78 // handle classic input 79 if (!isset($_REQUEST['wheeltags_enabled']) || !($_REQUEST['wheeltags_enabled'])) { 80 // copy reference 81 $tags3 = $this->tags3; 82 $this->tags3 = array(); 83 84 // proceed with classic 85 if (isset($_REQUEST['tags']) && !empty($_REQUEST['tags'])) { 86 foreach(TaggingUtil::splitString($_REQUEST['tags']) as $tag) { 87 // use weights from modern input (even if hidden) 88 if(array_key_exists($tag, $tags3)) { 89 $this->tags3[$tag] = $tags3[$tag]; 90 } else if(array_key_exists($tag, $this->tags3)) { 91 $this->tags3[$tag] *= 1.33; // increase with 33% 92 } else { 93 $this->tags3[$tag] = 100; 94 } 95 } 96 } 97 } 98 99 // conversion from post to Tag 100 foreach($this->tags3 as $name => $weight) { 101 if(strlen($name) < 3) { 102 unset($this->tags3[$name]); 103 continue; 104 } 105 106 $this->tags3[$name] = new Tag(null, array( 107 'name' => $name, 108 'weight' => $weight 109 )); 110 } 65 $this->tags3 = TaggingReloadedUtil::readFormParameters(); 111 66 112 67 // workaround to be called before validate from woltlab … … 122 77 } 123 78 124 public function deleteFromTagging3($userID, $tags, Tagged $object, $languageIDArray) {125 if(!count($tags)) return;126 127 $ids = array();128 foreach($tags as $tag) {129 $ids[] = $tag->tagID;130 }131 132 $sql = "DELETE FROM wcf".WCF_N."_tagging3133 WHERE taggableID = ".$object->getTaggable()->getTaggableID()."134 AND languageID IN (".implode(',', $languageIDArray).")135 AND objectID = ".$object->getObjectID()."136 AND tagID IN (".implode(",", $ids).")137 AND userID = ".intval($userID);138 WCF::getDB()->sendQuery($sql);139 $result = WCF::getDB()->sendQuery($sql);140 }141 142 /**143 * this is a reimplemenation of TagEngine::deleteObjectTags with a slite modification.144 * not all tags are deleted. just some tagIDs145 */146 public function deleteFromSystem($tags, Tagged $object, $languageIDArray) {147 if(!count($tags)) return;148 149 $ids = array();150 foreach($tags as $tag) {151 $ids[] = $tag->tagID;152 }153 154 $sql = "DELETE FROM wcf".WCF_N."_tag_to_object155 WHERE taggableID = ".$object->getTaggable()->getTaggableID()."156 AND languageID IN (".implode(',', $languageIDArray).")157 AND objectID = ".$object->getObjectID()."158 AND tagID IN (".implode(",", $ids).")";159 WCF::getDB()->sendQuery($sql);160 $result = WCF::getDB()->sendQuery($sql);161 }162 163 public function addToSystem($tags, Tagged $object, $languageID) {164 if(!count($tags)) return;165 166 $tags = array_keys($tags);167 try {168 TagEngine::getInstance()->addTags($tags, $object, $languageID);169 } catch(Exception $e) {170 // please handle171 }172 }173 174 /**175 * this is a reimplementation of TagEngine::addTags with a slite modification to write to our table and to update existing tables with weight176 */177 public function addToTagging3($userID, $tags, Tagged $object, $languageID) {178 if(!count($tags)) return;179 180 // store tagging3 database181 $tagIDs = array();182 foreach ($tags as $tag) {183 $tagID = $tag->tagID ? $tag->tagID : Tag::test($tag->name, $languageID);184 if (!$tagID) $tagID = Tag::insert($tag->name, $languageID);185 186 if (empty($tag->userID)) $tag->userID = $userID;187 $tagIDs[$tagID] = $tag;188 }189 190 $sql = "REPLACE INTO wcf".WCF_N."_tagging3191 (objectID, tagID, taggableID, languageID, userID, weight)192 VALUES ";193 foreach ($tagIDs as $tagID => $tag) {194 $sql .= "(" . $object->getObjectID() . ", " . $tagID . ", " . $object->getTaggable()->getTaggableID() . ",195 ".$languageID.", ".$tag->userID.", ".$tag->weight."),";196 }197 $sql = StringUtil::substring($sql, 0, StringUtil::length($sql) - 1);198 $result = WCF::getDB()->sendQuery($sql);199 }200 201 79 /** 202 80 * save 203 81 */ 204 82 protected function tagging3Save($userID, $tagged, $languageID) { 205 $languageIDArray = array($languageID); 206 207 // remove old links 208 if(count($this->existingTagsUser) || count($this->existingTagsObject)) { 209 210 // tagging3: remove the link to the current user 211 $deleteFromTagging3 = TaggingReloadedUtil::diff($this->existingTagsUser, $this->tags3); 212 213 // woltlab system: when no other user has this tag, remove the link from tag to object 214 $deleteFromSystem = TaggingReloadedUtil::diff($deleteFromTagging3, $this->existingTagsObject); 215 216 // tagging3: ids are known.. delete is easy 217 $this->deleteFromTagging3($userID, $deleteFromTagging3, $tagged, $languageIDArray); 218 219 // woltlab system: ids are known.. delete is easy 220 $this->deleteFromSystem($deleteFromSystem, $tagged, $languageIDArray); 221 } 222 223 // tagging3: add user specific tags 224 $addToTagging3 = TaggingReloadedUtil::diff($this->tags3, $this->existingTagsUser); 225 226 // woltlab system: add link from tag to object 227 $addToSystem = TaggingReloadedUtil::diff($addToTagging3, $this->existingTagsObject); 228 229 // woltlab system: save 230 $this->addToSystem($addToSystem, $tagged, $languageID); 231 232 // tagging3: save 233 // attention: use $this->tags3 instead of the diff, because we want to update all weights 234 $this->addToTagging3($userID, $this->tags3, $tagged, $languageID); 83 return TaggingReloadedUtil::tagging3Save($userID, $tagged, $languageID, $this->tags3, $this->existingTagsUser, $this->existingTagsObject); 235 84 } 236 85 … … 248 97 */ 249 98 protected function getTagsByObject($userID, Tagged $tagged, $languageID, $even = true) { 250 $taggableID = $tagged->getTaggable()->getTaggableID(); 251 $objectID = $tagged->getObjectID(); 252 $sign = $even ? '=' : '!='; 253 254 $sql = "SELECT tag.*, 255 userID, 256 weight 257 FROM ( 258 SELECT tagID, 259 userID, 260 weight 261 FROM wcf".WCF_N."_tagging3 262 WHERE taggableID = ".intval($taggableID)." 263 AND languageID = ".intval($languageID)." 264 AND objectID = ".intval($objectID)." 265 AND userID $sign ".intval($userID)." 266 ) x 267 INNER JOIN wcf".WCF_N."_tag tag USING(tagID) 268 "; 269 $result = WCF::getDB()->sendQuery($sql); 270 $tags = array(); 271 while ($row = WCF::getDB()->fetchArray($result)) { 272 $tags[$row['name']] = new Tag(null, $row); 273 } 274 return $tags; 99 return TaggingReloadedUtil::getTagsByObject($userID, $tagged, $languageID, $even); 275 100 } 276 101 } -
taggingreloaded/files/lib/util/TaggingReloadedUtil.class.php
r1080 r1091 3 3 require_once(WCF_DIR.'/lib/util/ArrayUtil.class.php'); 4 4 require_once(WCF_DIR.'/lib/util/StringUtil.class.php'); 5 require_once(WCF_DIR.'lib/data/tag/Tag.class.php'); 6 require_once(WCF_DIR.'lib/data/tag/TagCloudWrapper.class.php'); 7 require_once(WCF_DIR.'lib/data/tag/TagEngine.class.php'); 5 8 6 9 /** … … 12 15 */ 13 16 class TaggingReloadedUtil { 17 public static function readFormParameters() { 18 $tags3 = array(); 19 20 // handle reloaded input 21 if (isset($_REQUEST['taggingname']) && isset($_REQUEST['taggingval'])) { 22 if(count($_REQUEST['taggingname']) > count($_REQUEST['taggingval'])) { 23 $_REQUEST['taggingval'] = array_slice($_REQUEST['taggingval'], 0, count($_REQUEST['taggingname'])); 24 } else if(count($_REQUEST['taggingname']) < count($_REQUEST['taggingval'])) { 25 $_REQUEST['taggingname'] = array_slice($_REQUEST['taggingname'], 0, count($_REQUEST['taggingval'])); 26 } 27 $tags3 = array_combine($_REQUEST['taggingname'], $_REQUEST['taggingval']); 28 } 29 30 // handle classic input 31 if (!isset($_REQUEST['wheeltags_enabled']) || !($_REQUEST['wheeltags_enabled'])) { 32 // copy reference 33 $tags = $tags3; 34 $tags3 = array(); 35 36 // proceed with classic 37 if (isset($_REQUEST['tags']) && !empty($_REQUEST['tags'])) { 38 foreach(TaggingUtil::splitString($_REQUEST['tags']) as $tag) { 39 // use weights from modern input (even if hidden) 40 if(array_key_exists($tag, $tags)) { 41 $tags3[$tag] = $tags[$tag]; 42 } else if(array_key_exists($tag, $tags3)) { 43 $tags3[$tag] *= 1.33; // increase with 33% 44 } else { 45 $tags3[$tag] = 100; 46 } 47 } 48 } 49 } 50 51 // conversion from post to Tag 52 foreach($tags3 as $name => $weight) { 53 if(strlen($name) < 3) { 54 unset($tags3[$name]); 55 continue; 56 } 57 58 $tags3[$name] = new Tag(null, array( 59 'name' => $name, 60 'weight' => $weight 61 )); 62 } 63 64 return $tags3; 65 } 66 67 protected static function deleteFromTagging3($userID, $tags, Tagged $object, $languageIDArray) { 68 if(!count($tags)) return; 69 70 $ids = array(); 71 foreach($tags as $tag) { 72 $ids[] = $tag->tagID; 73 } 74 75 $sql = "DELETE FROM wcf".WCF_N."_tagging3 76 WHERE taggableID = ".$object->getTaggable()->getTaggableID()." 77 AND languageID IN (".implode(',', $languageIDArray).") 78 AND objectID = ".$object->getObjectID()." 79 AND tagID IN (".implode(",", $ids).") 80 AND userID = ".intval($userID); 81 WCF::getDB()->sendQuery($sql); 82 $result = WCF::getDB()->sendQuery($sql); 83 } 84 85 /** 86 * this is a reimplemenation of TagEngine::deleteObjectTags with a slite modification. 87 * not all tags are deleted. just some tagIDs 88 */ 89 protected static function deleteFromSystem($tags, Tagged $object, $languageIDArray) { 90 if(!count($tags)) return; 91 92 $ids = array(); 93 foreach($tags as $tag) { 94 $ids[] = $tag->tagID; 95 } 96 97 $sql = "DELETE FROM wcf".WCF_N."_tag_to_object 98 WHERE taggableID = ".$object->getTaggable()->getTaggableID()." 99 AND languageID IN (".implode(',', $languageIDArray).") 100 AND objectID = ".$object->getObjectID()." 101 AND tagID IN (".implode(",", $ids).")"; 102 WCF::getDB()->sendQuery($sql); 103 $result = WCF::getDB()->sendQuery($sql); 104 } 105 106 protected static function addToSystem($tags, Tagged $object, $languageID) { 107 if(!count($tags)) return; 108 109 $tags = array_keys($tags); 110 try { 111 TagEngine::getInstance()->addTags($tags, $object, $languageID); 112 } catch(Exception $e) { 113 // please handle 114 } 115 } 116 117 /** 118 * this is a reimplementation of TagEngine::addTags with a slite modification to write to our table and to update existing tables with weight 119 */ 120 protected static function addToTagging3($userID, $tags, Tagged $object, $languageID) { 121 if(!count($tags)) return; 122 123 // store tagging3 database 124 $tagIDs = array(); 125 foreach ($tags as $tag) { 126 $tagID = $tag->tagID ? $tag->tagID : Tag::test($tag->name, $languageID); 127 if (!$tagID) $tagID = Tag::insert($tag->name, $languageID); 128 129 if (empty($tag->userID)) $tag->userID = $userID; 130 $tagIDs[$tagID] = $tag; 131 } 132 133 $sql = "REPLACE INTO wcf".WCF_N."_tagging3 134 (objectID, tagID, taggableID, languageID, userID, weight) 135 VALUES "; 136 foreach ($tagIDs as $tagID => $tag) { 137 $sql .= "(" . $object->getObjectID() . ", " . $tagID . ", " . $object->getTaggable()->getTaggableID() . ", 138 ".$languageID.", ".$tag->userID.", ".$tag->weight."),"; 139 } 140 $sql = StringUtil::substring($sql, 0, StringUtil::length($sql) - 1); 141 $result = WCF::getDB()->sendQuery($sql); 142 } 143 144 /** 145 * save 146 */ 147 public static function tagging3Save($userID, $tagged, $languageID, array $tags3, array $existingTagsUser = array(), array $existingTagsObject = array()) { 148 $languageIDArray = array($languageID); 149 150 // remove old links 151 if(count($existingTagsUser) || count($existingTagsObject)) { 152 153 // tagging3: remove the link to the current user 154 $deleteFromTagging3 = TaggingReloadedUtil::diff($existingTagsUser, $tags3); 155 156 // woltlab system: when no other user has this tag, remove the link from tag to object 157 $deleteFromSystem = TaggingReloadedUtil::diff($deleteFromTagging3, $existingTagsObject); 158 159 // tagging3: ids are known.. delete is easy 160 self::deleteFromTagging3($userID, $deleteFromTagging3, $tagged, $languageIDArray); 161 162 // woltlab system: ids are known.. delete is easy 163 self::deleteFromSystem($deleteFromSystem, $tagged, $languageIDArray); 164 } 165 166 // tagging3: add user specific tags 167 $addToTagging3 = TaggingReloadedUtil::diff($tags3, $existingTagsUser); 168 169 // woltlab system: add link from tag to object 170 $addToSystem = TaggingReloadedUtil::diff($addToTagging3, $existingTagsObject); 171 172 // woltlab system: save 173 self::addToSystem($addToSystem, $tagged, $languageID); 174 175 // tagging3: save 176 // attention: use $tags3 instead of the diff, because we want to update all weights 177 self::addToTagging3($userID, $tags3, $tagged, $languageID); 178 } 179 180 /** 181 * @return Tag[] 182 */ 183 public static function getTagsByObject($userID, Tagged $tagged, $languageID, $even = true) { 184 $taggableID = $tagged->getTaggable()->getTaggableID(); 185 $objectID = $tagged->getObjectID(); 186 187 $sign = $even ? '=' : '!='; 188 $signline = $even === null ? '' : "AND userID $sign ".intval($userID); 189 190 $sql = "SELECT tag.*, 191 userID, 192 weight 193 FROM ( 194 SELECT tagID, 195 userID, 196 weight 197 FROM wcf".WCF_N."_tagging3 198 WHERE taggableID = ".intval($taggableID)." 199 AND languageID = ".intval($languageID)." 200 AND objectID = ".intval($objectID)." 201 ".$signline." 202 ) x 203 INNER JOIN wcf".WCF_N."_tag tag USING(tagID) 204 "; 205 $result = WCF::getDB()->sendQuery($sql); 206 $tags = array(); 207 while ($row = WCF::getDB()->fetchArray($result)) { 208 $tags[$row['name']] = new Tag(null, $row); 209 } 210 return $tags; 211 } 14 212 15 213 /** -
taggingreloaded/optionals/de.easy-coding.wbb.taggingreloaded/files/lib/system/event/listener/TaggingReloadedWBBPageListener.class.php
r1078 r1091 41 41 INNER JOIN wcf".WCF_N."_tag tag USING(tagID) 42 42 LIMIT ".intval($limit); 43 echo $sql; 43 44 return $sql; 44 45 } -
taggingreloaded/templates/taggingReloadedSidebar.tpl
r1087 r1091 5 5 <input type="hidden" name="taggable" value="{$taggable}" /> 6 6 <input type="hidden" name="languageID" value="{$languageID}" /> 7 <input type="hidden" name="entryID" value="{$entry->entryID}" /> 7 <input type="hidden" name="objectID" value="{$objectID}" /> 8 <input type="hidden" name="className" value="{$className}" /> 9 <input type="hidden" name="classPath" value="{$classPath}" /> 8 10 <div class="containerHead"> 9 11 <h3>{lang}wcf.taggingreloaded.tags{/lang}</h3> … … 15 17 </div> 16 18 <div class="containerContent"> 17 <input type="text" id="tags" name="tags" size="45" style="margin-right:10px" />19 <input type="text" id="tags" name="tags" value="{$tags}" size="45" style="margin-right:10px" /> 18 20 <input type="button" value="{lang}Tags bearbeiten{/lang}" onclick="return taggingReloadedToggle(this)" /> 19 21 </div>
