/** * Get an instance of the TagEngine * * @return TagEngine to get */ public static function getInstance() { if (self::$instance == null) { self::$instance = new TagEngine(); } return self::$instance; }
/** * @see CacheBuilder::getData() */ public function getData($cacheResource) { list($cache, $boardID, $languageIDs) = explode('-', $cacheResource['cache']); $data = array(); // get taggable require_once WCF_DIR . 'lib/data/tag/TagEngine.class.php'; $taggable = TagEngine::getInstance()->getTaggable('com.woltlab.wbb.thread'); // get tag ids $tagIDArray = array(); $sql = "SELECT\t\tCOUNT(*) AS counter, object.tagID\n\t\t\tFROM \t\twbb" . WBB_N . "_thread thread,\n\t\t\t\t\twcf" . WCF_N . "_tag_to_object object\n\t\t\tWHERE \t\tthread.boardID = " . $boardID . "\n\t\t\t\t\tAND object.taggableID = " . $taggable->getTaggableID() . "\n\t\t\t\t\tAND object.languageID IN (" . $languageIDs . ")\n\t\t\t\t\tAND object.objectID = thread.threadID\n\t\t\tGROUP BY \tobject.tagID\n\t\t\tORDER BY \tcounter DESC"; $result = WCF::getDB()->sendQuery($sql, 500); while ($row = WCF::getDB()->fetchArray($result)) { $tagIDArray[$row['tagID']] = $row['counter']; } // get tags if (count($tagIDArray)) { $sql = "SELECT\t\tname, tagID\n\t\t\t\tFROM\t\twcf" . WCF_N . "_tag\n\t\t\t\tWHERE\t\ttagID IN (" . implode(',', array_keys($tagIDArray)) . ")"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $row['counter'] = $tagIDArray[$row['tagID']]; $this->tags[StringUtil::toLowerCase($row['name'])] = new Tag(null, $row); } // sort by counter uasort($this->tags, array('self', 'compareTags')); $data = $this->tags; } return $data; }
/** * Creates a new TagList object. * * @param array<string> $taggables */ public function __construct($taggables = array(), $languageIDArray = array()) { // language ids $this->languageIDArray = $languageIDArray; if (!count($this->languageIDArray)) { $this->languageIDArray = array(0); } // taggable ids if (count($taggables)) { // get taggable ids foreach ($taggables as $taggable) { if (($taggableObj = TagEngine::getInstance()->getTaggable($taggable)) !== null) { $this->taggableIDArray[] = $taggableObj->getTaggableID(); } } } else { // get ids of all taggables in this environment foreach (TagEngine::getInstance()->getTaggables() as $taggableObj) { $this->taggableIDArray[] = $taggableObj->getTaggableID(); } } }
$db = new MysqliDb('localhost', 'root', 'root', 'db'); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>PHP TagEngine</title> <meta name="author" content="Josh Campbell - Ajillion"> </head> <body> <p>Use tabels.sql to create the tag engine tabels and insert test data (tag types).</p> <?php $tagEngine = new TagEngine($db); echo '<br/><strong>Tag Engine Tests</strong><br/><br/>'; echo '<strong>getTagTypeId(\'img\') =</strong> ' . $tagEngine->getTagTypeId('img') . '<br/><br/>'; echo '<pre>Insert 3 new tags (tag1,tag2,tag3) and map them to relId 100 with a type of img.' . "\n<strong>mapTags(100,'img','tag1,tag2,tag3') =</strong>\n"; print_r($tagEngine->mapTags(100, 'img', 'tag1,tag2,tag3')); echo '</pre><br/>'; echo '<strong>getTagId(\'tag3\') =</strong> ' . $tagEngine->getTagId('tag3') . '<br/>'; echo '<strong>tagExists(\'tag3\') =</strong> '; if ($tagEngine->tagExists('tag3')) { echo 'true<br/>'; } else { echo 'false<br/>'; } echo '<strong>tagExists(\'tag5\') =</strong> '; if ($tagEngine->tagExists('tag5')) { echo 'true<br/>';
/** * Returns the tags of this thread. * * @return array */ public function getTags($languageIDArray) { // include files require_once WCF_DIR . 'lib/data/tag/TagEngine.class.php'; require_once WBB_DIR . 'lib/data/thread/TaggedThread.class.php'; // get tags return TagEngine::getInstance()->getTagsByTaggedObject(new TaggedThread(null, array('threadID' => $this->threadID, 'taggable' => TagEngine::getInstance()->getTaggable('com.woltlab.wbb.thread'))), $languageIDArray); }
/** * Gets the list of tags. */ protected function readTags() { if (MODULE_TAGGING) { require_once WCF_DIR . 'lib/data/tag/TagEngine.class.php'; $taggable = TagEngine::getInstance()->getTaggable('de.easy-coding.wcf.contest.entry'); $sql = "SELECT\t\ttag_to_object.objectID AS contestID,\n\t\t\t\t\t\ttag.tagID, tag.name\n\t\t\t\tFROM\t\twcf" . WCF_N . "_tag_to_object tag_to_object\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_tag tag\n\t\t\t\tON\t\t(tag.tagID = tag_to_object.tagID)\n\t\t\t\tWHERE\t\ttag_to_object.taggableID = " . intval($taggable->getTaggableID()) . "\n\t\t\t\t\t\tAND tag_to_object.languageID IN (" . implode(',', count(WCF::getSession()->getVisibleLanguageIDArray()) ? WCF::getSession()->getVisibleLanguageIDArray() : array(0)) . ")\n\t\t\t\t\t\tAND tag_to_object.objectID IN (" . implode(',', $this->objectIDArray) . ")"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { if (!isset($this->tags[$row['contestID']])) { $this->tags[$row['contestID']] = array(); } $this->tags[$row['contestID']][] = new Tag(null, $row); } } }
/** * Returns the tags of this entry. * * @return array<Tag> */ public function getTags($languageIDArray) { if ($this->isViewable() == false) { return array(); } // include files require_once WCF_DIR . 'lib/data/tag/TagEngine.class.php'; require_once WCF_DIR . 'lib/data/contest/TaggedContest.class.php'; // get tags return TagEngine::getInstance()->getTagsByTaggedObject(new TaggedContest(null, array('contestID' => $this->contestID, 'taggable' => TagEngine::getInstance()->getTaggable('de.easy-coding.wcf.contest.entry'))), $languageIDArray); }
/** * Updates the tags of this thread. * * @param array $tags */ public function updateTags($tagArray) { // include files require_once WCF_DIR . 'lib/data/tag/TagEngine.class.php'; require_once WBB_DIR . 'lib/data/thread/TaggedThread.class.php'; // save tags $tagged = new TaggedThread(null, array('threadID' => $this->threadID, 'taggable' => TagEngine::getInstance()->getTaggable('com.woltlab.wbb.thread'))); // delete old tags TagEngine::getInstance()->deleteObjectTags($tagged, array($this->languageID)); // save new tags if (count($tagArray) > 0) { TagEngine::getInstance()->addTags($tagArray, $tagged, $this->languageID); } }
/** * @see Page::readData(); */ public function readData() { parent::readData(); if ($this->tagObj) { // get tagged objects if ($this->taggableID == 0) { // get objects for overview $this->taggedObjects = TagEngine::getInstance()->getGroupedTaggedObjectsByTagID($this->tagObj->getID()); } else { $this->taggedObjects = $this->taggable->getObjectsByTagID($this->tagObj->getID(), $this->itemsPerPage, ($this->pageNo - 1) * $this->itemsPerPage); } } // get tags $tagCloud = new TagCloud(WCF::getSession()->getVisibleLanguageIDArray()); $this->tags = $tagCloud->getTags($this->tagObj !== null ? 50 : 500); }
/** * Updates the tags of this entry. * * @param array<string> $tagArray */ public function updateTags($tagArray) { // include files require_once WCF_DIR . 'lib/data/tag/TagEngine.class.php'; require_once WCF_DIR . 'lib/data/contest/TaggedContest.class.php'; // save tags $tagged = new TaggedContest(null, array('contestID' => $this->contestID, 'taggable' => TagEngine::getInstance()->getTaggable('de.easy-coding.wcf.contest.entry'))); $languageID = 0; if (count(Language::getAvailableContentLanguages()) > 0) { $languageID = WCF::getLanguage()->getLanguageID(); } // delete old tags TagEngine::getInstance()->deleteObjectTags($tagged, array($languageID)); // save new tags if (count($tagArray) > 0) { TagEngine::getInstance()->addTags($tagArray, $tagged, $languageID); } }
/** * Creates a new TaggedContestList object. */ public function __construct($tagID) { $this->tagID = $tagID; $this->taggable = TagEngine::getInstance()->getTaggable('de.easy-coding.wcf.contest.entry'); }
/** * Creates a new TaggedBoardThreadList object. */ public function __construct($tagID, Board $board, $daysPrune = 100, $prefix = '', $status = '', $languageID = 0) { $this->tagID = $tagID; $this->taggable = TagEngine::getInstance()->getTaggable('com.woltlab.wbb.thread'); parent::__construct($board, $daysPrune, $prefix, $status, $languageID); }
/** * Reads the given parameters. */ public function readParameters() { parent::readParameters(); // get board id if (isset($_REQUEST['boardID'])) { $this->boardID = intval($_REQUEST['boardID']); } else { if (isset($_REQUEST['boardid'])) { $this->boardID = intval($_REQUEST['boardid']); } } // wbb2 style if (isset($_REQUEST['prefix'])) { $this->prefix = $_REQUEST['prefix']; } if (isset($_REQUEST['status'])) { $this->status = $_REQUEST['status']; } if (isset($_REQUEST['languageID'])) { $this->languageID = intval($_REQUEST['languageID']); } if (isset($_REQUEST['tagID'])) { $this->tagID = intval($_REQUEST['tagID']); } // get board $this->board = new Board($this->boardID); // threads per page if ($this->board->threadsPerPage) { $this->itemsPerPage = $this->board->threadsPerPage; } if (WCF::getUser()->threadsPerPage) { $this->itemsPerPage = WCF::getUser()->threadsPerPage; } // enter board $this->board->enter(); // redirect to external url if given if ($this->board->isExternalLink()) { if (!WCF::getSession()->spiderID) { // count redirects $sql = "UPDATE\twbb" . WBB_N . "_board\n\t\t\t\t\tSET\tclicks = clicks + 1\n\t\t\t\t\tWHERE\tboardID = " . $this->boardID; WCF::getDB()->registerShutdownUpdate($sql); // reset cache WCF::getCache()->clearResource('boardData'); } // do redirect HeaderUtil::redirect($this->board->externalURL, false); exit; } // get sorting values if ($this->board->sortField) { $this->defaultSortField = $this->board->sortField; } if ($this->board->sortOrder) { $this->defaultSortOrder = $this->board->sortOrder; } if ($this->board->daysPrune) { $this->defaultDaysPrune = $this->board->daysPrune; } if (WCF::getUser()->threadDaysPrune) { $this->defaultDaysPrune = WCF::getUser()->threadDaysPrune; } // thread rating if ($this->board->enableRating != -1) { $this->enableRating = $this->board->enableRating; } // days prune if (isset($_REQUEST['daysPrune'])) { $this->daysPrune = intval($_REQUEST['daysPrune']); } if ($this->daysPrune < 1) { $this->daysPrune = $this->defaultDaysPrune; } // status filter if (!empty($this->status)) { switch ($this->status) { case 'read': case 'unread': case 'open': case 'closed': case 'deleted': case 'hidden': case 'done': case 'undone': break; default: $this->status = ''; } } if ($this->board->isBoard()) { if (MODULE_TAGGING && $this->tagID) { require_once WCF_DIR . 'lib/data/tag/TagEngine.class.php'; $this->tag = TagEngine::getInstance()->getTagByID($this->tagID); if ($this->tag === null) { throw new IllegalLinkException(); } require_once WBB_DIR . 'lib/data/thread/TaggedBoardThreadList.class.php'; $this->threadList = new TaggedBoardThreadList($this->tagID, $this->board, $this->daysPrune, $this->prefix, $this->status, $this->languageID); } else { require_once WBB_DIR . 'lib/data/thread/BoardThreadList.class.php'; $this->threadList = new BoardThreadList($this->board, $this->daysPrune, $this->prefix, $this->status, $this->languageID); } } }
/** * @see Page::readParameters() */ public function readParameters() { parent::readParameters(); // get tag if (isset($_REQUEST['tagID'])) { $this->tagID = intval($_REQUEST['tagID']); } // get juryID if (isset($_REQUEST['juryID'])) { $this->juryID = intval($_REQUEST['juryID']); } // get participantID if (isset($_REQUEST['participantID'])) { $this->participantID = intval($_REQUEST['participantID']); } // get classID if (isset($_REQUEST['classID'])) { $this->classID = intval($_REQUEST['classID']); } // init entry list if (MODULE_TAGGING && $this->tagID) { require_once WCF_DIR . 'lib/data/tag/TagEngine.class.php'; $this->tag = TagEngine::getInstance()->getTagByID($this->tagID); if ($this->tag === null) { throw new IllegalLinkException(); } require_once WCF_DIR . 'lib/data/contest/TaggedContestOverviewList.class.php'; $this->entryList = new TaggedContestOverviewList($this->tagID); } else { if ($this->juryID) { require_once WCF_DIR . 'lib/data/contest/ContestOverviewList.class.php'; $this->entryList = new ContestOverviewList(); $this->entryList->sqlConditions .= 'contest_jury.juryID = ' . intval($this->juryID); $this->entryList->sqlJoins .= " LEFT JOIN wcf" . WCF_N . "_contest_jury contest_jury ON (contest_jury.contestID = contest.contestID) "; } else { if ($this->participantID) { require_once WCF_DIR . 'lib/data/contest/ContestOverviewList.class.php'; $this->entryList = new ContestOverviewList(); $this->entryList->sqlConditions .= 'contest_participant.participantID = ' . intval($this->participantID); $this->entryList->sqlJoins .= " LEFT JOIN wcf" . WCF_N . "_contest_participant contest_participant ON (contest_participant.contestID = contest.contestID) "; } else { if ($this->classID) { require_once WCF_DIR . 'lib/data/contest/ContestOverviewList.class.php'; $this->entryList = new ContestOverviewList(); $this->entryList->sqlConditions .= 'contest_to_class.classID = ' . intval($this->classID); $this->entryList->sqlJoins .= " LEFT JOIN wcf" . WCF_N . "_contest_to_class contest_to_class ON (contest_to_class.contestID = contest.contestID) "; } else { require_once WCF_DIR . 'lib/data/contest/ContestOverviewList.class.php'; $this->entryList = new ContestOverviewList(); } } } } // init tag list if (MODULE_TAGGING) { require_once WCF_DIR . 'lib/data/tag/TagList.class.php'; $this->tagList = new TagList(array('de.easy-coding.wcf.contest.entry'), WCF::getSession()->getVisibleLanguageIDArray()); } }