<?php /** * @version $Header$ * @package tags * @subpackage functions * * @copyright Copyright (c) 2004-2006, bitweaver.org * All Rights Reserved. See below for details and a complete list of authors. * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details. */ /** * required setup */ require_once "../kernel/setup_inc.php"; require_once TAGS_PKG_PATH . "LibertyTag.php"; $gBitSystem->verifyPackage('tags'); if (!$gBitUser->hasPermission('p_tags_admin')) { $gBitSystem->fatalError('You do not have permission to edit Tags'); } $tag = new LibertyTag(); if ($tag->loadTag($_REQUEST)) { $gBitSmarty->assign('tagData', $tag->mInfo); } if (!empty($_REQUEST["save"])) { if ($tag->storeOneTag($_REQUEST)) { header("location: " . TAGS_PKG_URL . "index.php?tags=" . $tag->mInfo['tag']); } } $gBitSystem->display('bitpackage:tags/edit_tag.tpl', tra("Edit Tag"), array('display_mode' => 'edit'));
<?php /** * @version * @package tags * @subpackage modules */ /** * required setup */ require_once TAGS_PKG_PATH . "LibertyTag.php"; // moduleParams contains lots of goodies: extract for easier handling extract($moduleParams); $listHash = array('sort' => !empty($module_params['sort']) ? $module_params['sort'] : NULL, 'sort_mode' => !empty($module_params['sort_mode']) ? $module_params['sort_mode'] : 'tag_asc', 'user' => !empty($module_params['user']) ? $module_params['user'] : NULL, 'group_id' => @BitBase::verifyId($module_params['group_id']) ? $module_params['group_id'] : NULL, 'max_popular' => !empty($module_params['max_popular']) ? $module_params['max_popular'] : NULL); $tag = new LibertyTag(); $listData = $tag->getList($listHash); $_template->tpl_vars['modTagData'] = new Smarty_variable($listData["data"]);
<?php require_once "../kernel/setup_inc.php"; require_once TAGS_PKG_PATH . "LibertyTag.php"; $gBitSystem->verifyPackage('tags'); $gBitSystem->verifyPermission('p_tags_view'); $tag = new LibertyTag(); $_REQUEST['max_records'] = !empty($_REQUEST['max_records']) ? $_REQUEST['max_records'] : NULL; $listHash = $_REQUEST; $tagHash = $_REQUEST; $gBitSmarty->assign('cloud', TRUE); if (isset($_REQUEST['tags'])) { $pageTitle = tra('Tagged Content'); if ($listData = $tag->assignContentList($listHash)) { $pageTitle .= ' ' . tra('with') . ' ' . $_REQUEST['tags']; $gBitSystem->setCanonicalLink($tag->getDisplayUrlWithTag($_REQUEST['tags'])); } else { $gBitSystem->setHttpStatus(HttpStatusCodes::HTTP_GONE); } $tagData = $tag->getList($tagHash); $gBitSmarty->assign('tagData', $tagData["data"]); $gBitSmarty->assign('tagsReq', $_REQUEST['tags']); $gBitSystem->display('bitpackage:tags/list_content.tpl', $pageTitle, array('display_mode' => 'display')); } else { $listData = $tag->getList($listHash); $gBitSmarty->assign('tagData', $listData["data"]); $gBitSystem->display('bitpackage:tags/list_tags.tpl', tra('Tags'), array('display_mode' => 'display')); }
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details. */ /** * required setup */ require_once "../kernel/setup_inc.php"; require_once TAGS_PKG_PATH . "LibertyTag.php"; $gBitSystem->verifyPackage('tags'); require_once LIBERTY_PKG_PATH . 'lookup_content_inc.php'; if (!$gContent || !$gContent->isValid()) { $gBitSystem->fatalError('The content is not valid.'); } if (!($gBitUser->hasPermission('p_tags_admin') || $gContent->isOwner())) { $gBitSystem->fatalError('You do not have permission to remove tags.'); } if (empty($_REQUEST['tag_id'])) { $gBitSystem->fatalError('You must select some tags.'); } if (isset($_REQUEST["confirm"])) { $tag = new LibertyTag(); $tag->expungeTags($_REQUEST['content_id'], explode(",", $_REQUEST['tag_id'])); header("location: " . $gContent->getDisplayUrl()); } $gBitSystem->setBrowserTitle(tra('Confirm drop of tags from: ') . $gContent->getTitle()); $formHash['tag_id'] = implode(",", $_REQUEST['tag_id']); $formHash['content_id'] = $_REQUEST['content_id']; foreach ($_REQUEST['tag_id'] as $id) { $tags[] = $_REQUEST['tag_' . $id]; } $msgHash = array('label' => tra('Drop Tags'), 'confirm_item' => implode("<br>", $tags), 'warning' => tra('These tags will be dropped from this content.<br />This cannot be undone!')); $gBitSystem->confirmDialog($formHash, $msgHash);
/** * This function gets a list of tags **/ function getList(&$pParamHash) { global $gBitUser, $gBitSystem; $bindVars = array(); $joinSql = !empty($pParamHash['join_sql']) ? $pParamHash['join_sql'] : ''; if (!empty($pParamHash['content_type_guid'])) { $bindVars[] = $pParamHash['content_type_guid']; $joinSql = "INNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON (tgc.`content_id`=lc.`content_id` AND lc.`content_type_guid`=?) "; } $sort_mode_prefix = 'tg'; //Backward compatability for most popular sort method if (empty($pParamHash['sort_mode'])) { $pParamHash['sort_mode'] = 'tag_asc'; } else { switch ($pParamHash['sort_mode']) { case 'tag_asc': case 'tag_desc': case 'tag_count_desc': case 'tag_count_asc': break; default: $pParamHash['sort_mode'] = 'tag_asc'; break; } } /** * @TODO this all needs to go in in some other getList type method * and these are just sketches - need to be different kinds of queries in most cases **/ /* // get tags by most hits on content if ($pParamHash['sort_mode'] == 'hits_desc') { $joinSql .= "LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` lch ON lc.`content_id` = lch.`content_id`"; } // get tags sorted by tagged date <- getList sorted by map tagged date if ($pParamHash['sort_mode'] == 'tagged_on_desc') { $sort_mode_prefix = 'tgc'; } */ $sort_mode = $this->mDb->convertSortmode($pParamHash['sort_mode']); // get all tags $query = "SELECT tg.`tag_id`, tg.`tag`, COUNT(tgc.`content_id`) AS tag_count\n\t\t\t\tFROM `" . BIT_DB_PREFIX . "tags` tg\n\t\t\t\t\t INNER JOIN `" . BIT_DB_PREFIX . "tags_content_map` tgc ON ( tgc.`tag_id` = tg.`tag_id` ) \n\t\t\t\t{$joinSql}\n\t\t\t\tGROUP BY tg.`tag_id`,tg.`tag`\n\t\t\t\tORDER BY {$sort_mode}"; $result = $this->mDb->query($query, $bindVars, !empty($pParamHash['max_records']) ? $pParamHash['max_records'] : NULL); $queryCount = "SELECT COUNT( * ) FROM `" . BIT_DB_PREFIX . "tags` tg"; $cant = $this->mDb->getOne($queryCount); $ret = array(); while ($res = $result->fetchRow()) { // this was really sucky, its now replaced by the slightly lesssucky subselect above. the subselect should prolly be replaced with a count table // $res['tag_count'] = $this->getPopCount($res['tag_id']); $res['tag_url'] = LibertyTag::getDisplayUrlWithTag($res['tag']); $ret[] = $res; } //get keys for doing sorts foreach ($ret as $key => $row) { $popcant[$key] = $row['tag_count']; $orderedcant[$key] = $row['tag_count']; } //this part creates the tag weight in a scale of 1-10 //get highest count and get lowest count if (!empty($orderedcant)) { sort($orderedcant); $lowcant = $orderedcant[0]; $highcant = $orderedcant[count($orderedcant) - 1]; //hack to prevent us from dividing by zero - this whole weighting thing could use a slightly better formula if ($highcant == $lowcant) { $lowcant -= 1; } //rescore //1. High-low = x $cantoffset = $highcant - $lowcant; //2. ratio 10/x if ($cantoffset > 9) { $tagscale = 9 / $cantoffset; } else { //@todo make this more sophisticated if the spread is not big enough $tagscale = 9 / $cantoffset; } //3. (n - low+1)*ratio (n is # to be scaled) foreach ($ret as $key => $row) { $ret[$key]['tagscale'] = round(($row['tag_count'] - $lowcant) * $tagscale + 1, 0); } } //trim to max popular count if a limit is asked for if (isset($pParamHash["max_popular"]) && is_numeric($pParamHash["max_popular"])) { $max_popular = $ret; array_multisort($popcant, SORT_DESC, $max_popular); $max_popular = array_slice($max_popular, 0, $pParamHash["max_popular"]); // preserve the sort requested by matching to the original list $sorted_popular = array(); foreach ($ret as $retkey => $retrow) { foreach ($max_popular as $key => $row) { if ($row['tag_id'] == $retrow['tag_id']) { $sorted_popular[] = $retrow; break; } } } $ret = $sorted_popular; } $pParamHash["data"] = $ret; $pParamHash["cant"] = $cant; return $pParamHash; }