From 665dc6a617b54d96d69464fb1811e1df83493be6 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Sat, 23 Aug 2014 12:21:44 +0200 Subject: [PATCH] implemented filters on Community Content - defined CC flags - implemented flagging by comments --- includes/ajaxHandler.class.php | 36 ++++++++++++++++++++++++---- includes/community.class.php | 18 +++++++------- includes/defines.php | 6 +++++ includes/types/achievement.class.php | 21 +++++++--------- includes/types/creature.class.php | 8 +++---- includes/types/gameobject.class.php | 13 ++++------ includes/types/item.class.php | 9 +++---- includes/types/itemset.class.php | 19 +++++++-------- includes/types/quest.class.php | 31 ++++++++++++------------ includes/types/spell.class.php | 11 ++++----- includes/utilities.php | 17 +++++++++++++ 11 files changed, 112 insertions(+), 77 deletions(-) diff --git a/includes/ajaxHandler.class.php b/includes/ajaxHandler.class.php index f0e278d4..c97233d7 100644 --- a/includes/ajaxHandler.class.php +++ b/includes/ajaxHandler.class.php @@ -293,8 +293,13 @@ class AjaxHandler if ($postIdx = DB::Aowow()->query('INSERT INTO ?_comments (type, typeId, userId, roles, body, date) VALUES (?d, ?d, ?d, ?d, ?, UNIX_TIMESTAMP())', $this->get['type'], $this->get['typeid'], User::$id, User::$groups, $this->post['commentbody'])) { Util::gainSiteReputation(User::$id, SITEREP_ACTION_COMMENT, ['id' => $postIdx]); + // every comment starts with a rating of +1 and i guess the simplest thing to do is create a db-entry with the system as owner DB::Aowow()->query('INSERT INTO ?_comments_rates (commentId, userId, value) VALUES (?d, 0, 1)', $postIdx); + + // flag target with hasComment (if filtrable) + if ($tbl = Util::getCCTableParent($this->get['type'])) + DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags | ?d WHERE id = ?d', CUSTOM_HAS_COMMENT, $this->get['typeid']); } } @@ -330,23 +335,44 @@ class AjaxHandler if (empty($this->post['id']) && empty($this->get['id'])) break; - DB::Aowow()->query('UPDATE ?_comments SET flags = flags | 0x2, deleteUserId = ?d, deleteDate = UNIX_TIMESTAMP() WHERE id = ?d{ AND userId = ?d}', + $ok = DB::Aowow()->query('UPDATE ?_comments SET flags = flags | ?d, deleteUserId = ?d, deleteDate = UNIX_TIMESTAMP() WHERE id = ?d{ AND userId = ?d}', + CC_FLAG_DELETED, User::$id, empty($this->post['id']) ? $this->get['id'] : $this->post['id'], User::isInGroup(U_GROUP_MODERATOR) ? DBSIMPLE_SKIP : User::$id ); + // deflag hasComment (if filtrable) + if ($ok) + { + $coInfo = DB::Aowow()->selectRow('SELECT IF(BIT_OR(~b.flags) & ?d, 1, 0) as hasMore, b.type, b.typeId FROM ?_comments a JOIN ?_comments b ON a.type = b.type AND a.typeId = b.typeId WHERE a.id = ?d', + CC_FLAG_DELETED, + empty($this->post['id']) ? $this->get['id'] : $this->post['id'] + ); + + if (!$coInfo['hasMore'] && ($tbl = Util::getCCTableParent($coInfo['type']))) + DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags & ~?d WHERE id = ?d', CUSTOM_HAS_COMMENT, $coInfo['typeId']); + } + break; case 'undelete': // user.js uses GET; global.js uses POST if (empty($this->post['id']) && empty($this->get['id'])) break; - - DB::Aowow()->query('UPDATE ?_comments SET flags = flags & ~0x2 WHERE id = ?d{ AND userId = deleteUserId AND deleteUserId = ?d}', + $ok = DB::Aowow()->query('UPDATE ?_comments SET flags = flags & ~?d WHERE id = ?d{ AND userId = deleteUserId AND deleteUserId = ?d}', + CC_FLAG_DELETED, empty($this->post['id']) ? $this->get['id'] : $this->post['id'], User::isInGroup(U_GROUP_MODERATOR) ? DBSIMPLE_SKIP : User::$id ); + // reflag hasComment (if filtrable) + if ($ok) + { + $coInfo = DB::Aowow()->selectRow('SELECT type, typeId FROM ?_comments WHERE id = ?d', empty($this->post['id']) ? $this->get['id'] : $this->post['id']); + if ($tbl = Util::getCCTableParent($coInfo['type'])) + DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags | ?d WHERE id = ?d', CUSTOM_HAS_COMMENT, $coInfo['typeId']); + } + break; case 'rating': // up/down - distribution if (empty($this->get['id'])) @@ -410,9 +436,9 @@ class AjaxHandler break; if (!empty($this->post['sticky'])) - DB::Aowow()->query('UPDATE ?_comments SET flags = flags | 0x1 WHERE id = ?d', $this->post['id']); + DB::Aowow()->query('UPDATE ?_comments SET flags = flags | ?d WHERE id = ?d', CC_FLAG_STICKY, $this->post['id']); else - DB::Aowow()->query('UPDATE ?_comments SET flags = flags & ~0x1 WHERE id = ?d', $this->post['id']); + DB::Aowow()->query('UPDATE ?_comments SET flags = flags & ~?d WHERE id = ?d', CC_FLAG_STICKY, $this->post['id']); break; case 'out-of-date': // toggle flag diff --git a/includes/community.class.php b/includes/community.class.php index 14161607..7bcadb13 100644 --- a/includes/community.class.php +++ b/includes/community.class.php @@ -46,7 +46,7 @@ class CommunityContent ?_reports r ON r.subject = c.id AND r.mode = 1 AND r.reason = 19 WHERE c.replyTo = ?d AND c.type = ?d AND c.typeId = ?d AND - ((c.flags & 0x2) = 0 OR c.userId = ?d OR ?d) + ((c.flags & ?d) = 0 OR c.userId = ?d OR ?d) GROUP BY c.id ORDER BY @@ -60,7 +60,7 @@ class CommunityContent c.date, c.replyTo AS commentid, UNIX_TIMESTAMP() - c.date AS elapsed, - IF(c.flags & 0x2, 1, 0) AS deleted, + IF(c.flags & ?d, 1, 0) AS deleted, IF(c.type <> 0, c.type, c2.type) AS type, IF(c.typeId <> 0, c.typeId, c2.typeId) AS typeId, IFNULL(SUM(cr.value), 0) AS rating, @@ -77,7 +77,7 @@ class CommunityContent {c.userId = ?d AND} {c.replyTo <> ?d AND} {c.replyTo = ?d AND} - ((c.flags & 0x2) = 0 OR c.userId = ?d OR ?d) + ((c.flags & ?d) = 0 OR c.userId = ?d OR ?d) GROUP BY c.id ORDER BY @@ -96,9 +96,11 @@ class CommunityContent $subjCache = []; $comments = DB::Aowow()->select( self::$previewQuery, + CC_FLAG_DELETED, empty($params['user']) ? DBSIMPLE_SKIP : $params['user'], empty($params['replies']) ? DBSIMPLE_SKIP : 0, // i dont know, how to switch the sign around !empty($params['replies']) ? DBSIMPLE_SKIP : 0, + CC_FLAG_DELETED, User::$id, User::isInGroup(U_GROUP_COMMENTS_MODERATOR), CFG_SQL_LIMIT_DEFAULT @@ -186,7 +188,7 @@ class CommunityContent $query = $limit > 0 ? self::$commentQuery.' LIMIT '.$limit : self::$commentQuery; // get replies - $results = DB::Aowow()->SelectPage($nFound, $query, User::$id, User::$id, $commentId, 0, 0, User::$id, User::isInGroup(U_GROUP_COMMENTS_MODERATOR)); + $results = DB::Aowow()->SelectPage($nFound, $query, User::$id, User::$id, $commentId, 0, 0, CC_FLAG_DELETED, User::$id, User::isInGroup(U_GROUP_COMMENTS_MODERATOR)); foreach ($results as $r) { (new Markup($r['body']))->parseGlobalsFromText(self::$jsGlobals); @@ -219,7 +221,7 @@ class CommunityContent private static function getComments($type, $typeId) { - $results = DB::Aowow()->query(self::$commentQuery, User::$id, User::$id, 0, $type, $typeId, User::$id, (int)User::isInGroup(U_GROUP_COMMENTS_MODERATOR)); + $results = DB::Aowow()->query(self::$commentQuery, User::$id, User::$id, 0, $type, $typeId, CC_FLAG_DELETED, User::$id, (int)User::isInGroup(U_GROUP_COMMENTS_MODERATOR)); $comments = []; // additional informations @@ -256,16 +258,16 @@ class CommunityContent if ($r['editCount']) // lastEdit $c['lastEdit'] = [date(Util::$dateFormatInternal, $r['editDate']), $r['editCount'], $r['editUser']]; - if ($r['flags'] & 0x1) + if ($r['flags'] & CC_FLAG_STICKY) $c['sticky'] = true; - if ($r['flags'] & 0x2) + if ($r['flags'] & CC_FLAG_DELETED) { $c['deleted'] = true; $c['deletedInfo'] = [date(Util::$dateFormatInternal, $r['deleteDate']), $r['deleteUser']]; } - if ($r['flags'] & 0x4) + if ($r['flags'] & CC_FLAG_OUTDATED) $c['outofdate'] = true; $comments[] = $c; diff --git a/includes/defines.php b/includes/defines.php index 64b8c05f..c6a5a2d9 100644 --- a/includes/defines.php +++ b/includes/defines.php @@ -177,6 +177,12 @@ define('SPAWNINFO_ZONES', 1); // not a mask, mutua define('SPAWNINFO_SHORT', 2); define('SPAWNINFO_FULL', 3); +// Community Content +define('CC_FLAG_STICKY', 0x1); +define('CC_FLAG_DELETED', 0x2); +define('CC_FLAG_OUTDATED', 0x4); +define('CC_FLAG_APPROVED', 0x8); + /* * Game */ diff --git a/includes/types/achievement.class.php b/includes/types/achievement.class.php index 11ac4740..ae87ff60 100644 --- a/includes/types/achievement.class.php +++ b/includes/types/achievement.class.php @@ -259,12 +259,15 @@ class AchievementListFilter extends Filter ) ); protected $genericFilter = array( // misc (bool): _NUMERIC => useFloat; _STRING => localized; _FLAG => match Value; _BOOLEAN => stringSet - 2 => [FILTER_CR_BOOLEAN, 'reward_loc0', true ], // givesreward - 3 => [FILTER_CR_STRING, 'reward', true ], // rewardtext - 7 => [FILTER_CR_BOOLEAN, 'series', ], // givesreward - 9 => [FILTER_CR_NUMERIC, 'id', null, true], // prcntbasemanarequired - 10 => [FILTER_CR_STRING, 'iconString', ], // icon - 18 => [FILTER_CR_STAFFFLAG, 'flags', ], // lastrank + 2 => [FILTER_CR_BOOLEAN, 'reward_loc0', true ], // givesreward + 3 => [FILTER_CR_STRING, 'reward', true ], // rewardtext + 7 => [FILTER_CR_BOOLEAN, 'series', ], // givesreward + 9 => [FILTER_CR_NUMERIC, 'id', null, true], // prcntbasemanarequired + 10 => [FILTER_CR_STRING, 'iconString', ], // icon + 18 => [FILTER_CR_STAFFFLAG, 'flags', ], // lastrank + 14 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_COMMENT ], // hascomments + 15 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_SCREENSHOT ], // hasscreenshots + 16 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_VIDEO ], // hasvideos ); protected function createSQLForCriterium(&$cr) @@ -303,12 +306,6 @@ class AchievementListFilter extends Filter } } break; - case 14: // hascomments [yn] -/* todo */ return [1]; - case 15: // hasscreenshots [yn] -/* todo */ return [1]; - case 16: // hasvideos [yn] -/* todo */ return [1]; } unset($cr); diff --git a/includes/types/creature.class.php b/includes/types/creature.class.php index 5ac59081..1586c440 100644 --- a/includes/types/creature.class.php +++ b/includes/types/creature.class.php @@ -257,7 +257,10 @@ class CreatureListFilter extends Filter 19 => [FILTER_CR_FLAG, 'npcflag', NPC_FLAG_BANKER ], // banker 37 => [FILTER_CR_NUMERIC, 'id', null, true], // id 35 => [FILTER_CR_STRING, 'textureString' ], // useskin - 32 => [FILTER_CR_FLAG, 'cuFlags', NPC_CU_INSTANCE_BOSS ] // instanceboss + 32 => [FILTER_CR_FLAG, 'cuFlags', NPC_CU_INSTANCE_BOSS ], // instanceboss + 33 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_COMMENT ], // hascomments + 31 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_SCREENSHOT ], // hasscreenshots + 40 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_VIDEO ], // hasvideos ); protected function createSQLForCriterium(&$cr) @@ -424,9 +427,6 @@ class CreatureListFilter extends Filter case 6: // foundin [enum] case 38: // relatedevent [enum] case 34: // usemodel [str] // displayId -> id:creatureDisplayInfo.dbc/model -> id:cratureModelData.dbc/modelPath - case 33: // hascomments [yn] - case 31: // hasscreenshots [yn] - case 40: // hasvideos [yn] case 41: // haslocation [yn] [staff] /* todo */ return [1]; } diff --git a/includes/types/gameobject.class.php b/includes/types/gameobject.class.php index eaf8b42e..5fe9f2b0 100644 --- a/includes/types/gameobject.class.php +++ b/includes/types/gameobject.class.php @@ -137,8 +137,11 @@ class GameObjectListFilter extends Filter public $extraOpts = []; protected $genericFilter = array( - 15 => [FILTER_CR_NUMERIC, 'id', null], // id - 7 => [FILTER_CR_NUMERIC, 'reqSkill', null], // requiredskilllevel + 15 => [FILTER_CR_NUMERIC, 'id', null ], // id + 7 => [FILTER_CR_NUMERIC, 'reqSkill', null ], // requiredskilllevel + 13 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_COMMENT ], // hascomments + 11 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_SCREENSHOT], // hasscreenshots + 18 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_VIDEO ], // hasvideos ); /* @@ -202,12 +205,6 @@ class GameObjectListFilter extends Filter return [1]; } break; - case 13: // hascomments [yn] - break; - case 11: // hasscreenshots [yn] - break; - case 18: // hasvideos [yn] - break; } unset($cr); diff --git a/includes/types/item.class.php b/includes/types/item.class.php index c92dbbcc..a3dd308b 100644 --- a/includes/types/item.class.php +++ b/includes/types/item.class.php @@ -1617,6 +1617,9 @@ class ItemListFilter extends Filter 91 => [FILTER_CR_ENUM, 'totemCategory' ], // tool 176 => [FILTER_CR_STAFFFLAG, 'flags' ], // flags 177 => [FILTER_CR_STAFFFLAG, 'flagsExtra' ], // flags2 + 130 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_COMMENT ], // hascomments + 113 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_SCREENSHOT ], // hasscreenshots + 167 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_VIDEO ], // hasvideos ); public function __construct() @@ -1969,12 +1972,6 @@ class ItemListFilter extends Filter return ['startQuest', 0]; } break; - case 130: // hascomments [yn] - break; - case 113: // hasscreenshots [yn] - break; - case 167: // hasvideos [yn] - break; } unset($cr); diff --git a/includes/types/itemset.class.php b/includes/types/itemset.class.php index 74ef7317..3c9cf520 100644 --- a/includes/types/itemset.class.php +++ b/includes/types/itemset.class.php @@ -97,11 +97,14 @@ class ItemsetListFilter extends Filter { // cr => [type, field, misc, extraCol] protected $genericFilter = array( // misc (bool): _NUMERIC => useFloat; _STRING => localized; _FLAG => match Value; _BOOLEAN => stringSet - 2 => [FILTER_CR_NUMERIC, 'id', null, true], // id - 3 => [FILTER_CR_NUMERIC, 'npieces', ], // pieces - 4 => [FILTER_CR_STRING, 'bonusText', true ], // bonustext - 5 => [FILTER_CR_BOOLEAN, 'heroic', ], // heroic - 6 => [FILTER_CR_ENUM, 'holidayId', ], // relatedevent + 2 => [FILTER_CR_NUMERIC, 'id', null, true], // id + 3 => [FILTER_CR_NUMERIC, 'npieces', ], // pieces + 4 => [FILTER_CR_STRING, 'bonusText', true ], // bonustext + 5 => [FILTER_CR_BOOLEAN, 'heroic', ], // heroic + 6 => [FILTER_CR_ENUM, 'holidayId', ], // relatedevent + 8 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_COMMENT ], // hascomments + 9 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_SCREENSHOT ], // hasscreenshots + 10 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_VIDEO ], // hasvideos ); protected function createSQLForCriterium(&$cr) @@ -119,12 +122,6 @@ class ItemsetListFilter extends Filter switch ($cr[0]) { case 12: // available to players [yn] ugh .. scan loot, quest and vendor templates and write to ?_itemset -/* todo */ return [1]; - case 8: // hascomments [yn] -/* todo */ return [1]; - case 9: // hasscreenshots [yn] -/* todo */ return [1]; - case 10: // hasvideos [yn] /* todo */ return [1]; } diff --git a/includes/types/quest.class.php b/includes/types/quest.class.php index fbe4f474..085063a4 100644 --- a/includes/types/quest.class.php +++ b/includes/types/quest.class.php @@ -394,18 +394,21 @@ class QuestListFilter extends Filter 38 => [null, 1, 2, 3, 4, 5, 6, 7, 8, null, 10, 11, true, false], ); protected $genericFilter = array( - 27 => [FILTER_CR_FLAG, 'flags', QUEST_FLAG_DAILY ], // daily - 28 => [FILTER_CR_FLAG, 'flags', QUEST_FLAG_WEEKLY ], // weekly - 29 => [FILTER_CR_FLAG, 'flags', QUEST_FLAG_REPEATABLE ], // repeatable - 30 => [FILTER_CR_NUMERIC, 'id', null, true], // id - 5 => [FILTER_CR_FLAG, 'flags', QUEST_FLAG_SHARABLE ], // sharable - 11 => [FILTER_CR_NUMERIC, 'suggestedPlayers', ], // suggestedplayers - 6 => [FILTER_CR_NUMERIC, 'timeLimit', ], // timer - 42 => [FILTER_CR_STAFFFLAG, 'flags', ], // flags - 45 => [FILTER_CR_BOOLEAN, 'rewardTitleId', ], // titlerewarded - 2 => [FILTER_CR_NUMERIC, 'rewardXP', ], // experiencegained - 3 => [FILTER_CR_NUMERIC, 'rewardOrReqMoney', ], // moneyrewarded - 33 => [FILTER_CR_ENUM, 'holidayId', ], // relatedevent + 27 => [FILTER_CR_FLAG, 'flags', QUEST_FLAG_DAILY ], // daily + 28 => [FILTER_CR_FLAG, 'flags', QUEST_FLAG_WEEKLY ], // weekly + 29 => [FILTER_CR_FLAG, 'flags', QUEST_FLAG_REPEATABLE ], // repeatable + 30 => [FILTER_CR_NUMERIC, 'id', null, true], // id + 5 => [FILTER_CR_FLAG, 'flags', QUEST_FLAG_SHARABLE ], // sharable + 11 => [FILTER_CR_NUMERIC, 'suggestedPlayers', ], // suggestedplayers + 6 => [FILTER_CR_NUMERIC, 'timeLimit', ], // timer + 42 => [FILTER_CR_STAFFFLAG, 'flags', ], // flags + 45 => [FILTER_CR_BOOLEAN, 'rewardTitleId', ], // titlerewarded + 2 => [FILTER_CR_NUMERIC, 'rewardXP', ], // experiencegained + 3 => [FILTER_CR_NUMERIC, 'rewardOrReqMoney', ], // moneyrewarded + 33 => [FILTER_CR_ENUM, 'holidayId', ], // relatedevent + 25 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_COMMENT ], // hascomments + 18 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_SCREENSHOT ], // hasscreenshots + 36 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_VIDEO ], // hasvideos ); protected function createSQLForCriterium(&$cr) @@ -568,10 +571,6 @@ class QuestListFilter extends Filter case 15: // lastquestseries case 16: // partseries /* todo */ return [1]; // self-joining eats substential amounts of time: should restructure that and also incorporate reqQ and openQ cases from infobox - case 25: // hascomments - case 18: // hasscreenshots - case 36: // hasvideos -/* todo */ return [1]; default: break; } diff --git a/includes/types/spell.class.php b/includes/types/spell.class.php index 72ba7067..5a594a86 100644 --- a/includes/types/spell.class.php +++ b/includes/types/spell.class.php @@ -1927,7 +1927,10 @@ class SpellListFilter extends Filter 14 => [FILTER_CR_NUMERIC, 'id', null, true], // id 15 => [FILTER_CR_STRING, 'iconString', ], // icon 19 => [FILTER_CR_FLAG, 'attributes0', 0x80000 ], // scaling - 25 => [FILTER_CR_BOOLEAN, 'skillLevelYellow' ] // rewardsskillups + 25 => [FILTER_CR_BOOLEAN, 'skillLevelYellow' ], // rewardsskillups + 11 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_COMMENT ], // hascomments + 8 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_SCREENSHOT ], // hasscreenshots + 17 => [FILTER_CR_FLAG, 'cuFlags', CUSTOM_HAS_VIDEO ], // hasvideos ); protected function createSQLForCriterium(&$cr) @@ -1970,12 +1973,6 @@ class SpellListFilter extends Filter else return ['AND', ['reagent1', 0], ['reagent2', 0], ['reagent3', 0], ['reagent4', 0], ['reagent5', 0], ['reagent6', 0], ['reagent7', 0], ['reagent8', 0]]; } - case 11: // hascomments [yn] -/* todo */ return [1]; - case 8: // hasscreenshots [yn] -/* todo */ return [1]; - case 17: // hasvideos [yn] -/* todo */ return [1]; } unset($cr); diff --git a/includes/utilities.php b/includes/utilities.php index cc04b7f2..92e71a0a 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -1495,6 +1495,23 @@ class Util return DB::Aowow()->query('INSERT IGNORE INTO ?_account_reputation (?#) VALUES (?a)', array_keys($x), array_values($x)); } + // TYPE => tableName; when handling comments, screenshots or videos + public static function getCCTableParent($type) + { + // only filtrable types; others don't care about being flagged for having CommunityContent + switch ($type) + { + case TYPE_ACHIEVEMENT: return '?_achievement'; + case TYPE_SPELL: return '?_spell'; + case TYPE_OBJECT: return '?_objects'; + case TYPE_ITEM: return '?_items'; + case TYPE_ITEMSET: return '?_itemset'; + case TYPE_NPC: return '?_creature'; + case TYPE_QUEST: return '?_quests'; + default: return null; + } + } + public static function createShowOnMap() { /*