From 0aa24a7f24b573fd3f19cb888dfefcdc31ae6b82 Mon Sep 17 00:00:00 2001 From: lsces Date: Wed, 27 Aug 2025 17:27:24 +0100 Subject: Code updated to PHP8.4 and namespace --- LibertyTag.php | 762 ---------------------------------------- admin/admin_tags_inc.php | 86 +++-- admin/schema_inc.php | 46 +-- drop_tags.php | 18 +- edit.php | 8 +- includes/bit_setup_inc.php | 32 +- includes/classes/LibertyTag.php | 753 +++++++++++++++++++++++++++++++++++++++ index.php | 15 +- list.php | 29 +- modules/mod_tags_cloud.php | 17 +- 10 files changed, 880 insertions(+), 886 deletions(-) delete mode 100644 LibertyTag.php mode change 100644 => 100755 admin/admin_tags_inc.php mode change 100644 => 100755 drop_tags.php mode change 100644 => 100755 edit.php mode change 100644 => 100755 includes/bit_setup_inc.php create mode 100755 includes/classes/LibertyTag.php mode change 100644 => 100755 index.php mode change 100644 => 100755 list.php mode change 100644 => 100755 modules/mod_tags_cloud.php diff --git a/LibertyTag.php b/LibertyTag.php deleted file mode 100644 index d02bcad..0000000 --- a/LibertyTag.php +++ /dev/null @@ -1,762 +0,0 @@ -mContentId = $pContentId; - } - - - /* Delete when package complete! -wjames5 - * methods needed - * - * get all tags limited by content_id <- load - * get all tags <- getList - * get all content for tag_id <- getContentList - * get tags by map use count <- getList with map refs count - * get tags sorted by tagged date <- getList sorted by map tagged date - * - * store new tags from tags array - * store new tag-content map for content_id - * expunge tag and all tag-content maps - * expunge tag-content map for content_id - * - */ - - - /** - * Load all the tags for a given ContentId - * @param pParamHash be sure to pass by reference in case we need to make modifcations to the hash - **/ - function load() { - if( $this->isValid() ) { - $query = " - SELECT tgc.*, tg.* - FROM `".BIT_DB_PREFIX."tags_content_map` tgc - INNER JOIN `".BIT_DB_PREFIX."tags` tg ON tg.`tag_id` = tgc.`tag_id` - WHERE tgc.`content_id`=?"; - - //$this->mInfo = $this->mDb->query( $query, array( $this->mContentId ) ); - $result = $this->mDb->query( $query, array( $this->mContentId ) ); - if ($result) { - $ret = array(); - while ($res = $result->fetchRow()) { - //Add tag urls - $res['tag_url'] = LibertyTag::getDisplayUrlWithTag($res['tag']); - - $ret[] = $res; - } - $this->mInfo['tags'] = $ret; - } - } - return( count( $this->mInfo ) ); - } - - function loadTag ( &$pParamHash ){ - if( !empty( $pParamHash['tag_id'] ) && is_numeric( $pParamHash['tag_id'] )) { - $selectSql = ''; $joinSql = ''; $whereSql = ''; - $bindVars = array(); - - $whereSql .= "WHERE tg.`tag_id` = ?"; - $bindVars[] = $pParamHash['tag_id']; - - $query = " - SELECT tg.* - FROM `".BIT_DB_PREFIX."tags` tg - $whereSql"; - - if ( $result = $this->mDb->getRow( $query, $bindVars ) ){ - //Add tag url - $result['tag_url'] = LibertyTag::getDisplayUrlWithTag($result['tag']); - - $this->mInfo = $result; - }; - } - return( count( $this->mInfo ) ); - } - - - - /** - * Make sure the data is safe to store - * @param array pParams reference to hash of values that will be used to store the page, they will be modified where necessary - * @return bool TRUE on success, FALSE if verify failed. If FALSE, $this->mErrors will have reason why - * @access private - **/ - function verify( &$pParamHash ) { - global $gBitUser, $gBitSystem; - $pParamHash['tag_store'] = array(); - $pParamHash['tag_map_store'] = array(); - - if(!empty( $pParamHash['tag'])){ - $pParamHash['tag_store']['tag'] = $pParamHash['tag']; - } - if( !empty( $pParamHash['tag_id']) && is_numeric( $pParamHash['tag_id'])){ -// $pParamHash['tag_map_store']['tag_id'] = $pParamHash['tag_id']; - $pParamHash['tag_store']['tag_id'] = $pParamHash['tag_id']; - } - if( isset( $pParamHash['tagged_on']) ){ - $pParamHash['tag_map_store']['tagged_on'] = $pParamHash['tagged_on']; - } else { - $pParamHash['tag_map_store']['tagged_on'] = $gBitSystem->getUTCTime(); - } - if( @$this->verifyId( $pParamHash['content_id']) ){ - $pParamHash['tag_map_store']['content_id'] = $pParamHash['content_id']; - }/* else { - $this->mErrors['content_id'] = "No content id specified."; - }*/ - if( $gBitUser->mUserId ){ - $pParamHash['tag_map_store']['tagger_id'] = $gBitUser->mUserId; - } else { - $this->mErrors['user_id'] = "No user id specified."; - } - - return( count( $this->mErrors )== 0 ); - } - - - /* check tag exists - */ - function verifyTag ( &$pParamHash ){ - $ret = FALSE; - $selectSql = ''; $joinSql = ''; $whereSql = ''; - $bindVars = array(); - - // Bounds checking on tag name length - if( !empty( $pParamHash['tag'] ) && strlen( $pParamHash['tag'] ) > 64 ) { - $pParamHash['tag'] = substr( $pParamHash['tag'], 0, 64 ); - } - - // if tag_id supplied, use that - if( !empty( $pParamHash['tag_id'] ) && is_numeric( $pParamHash['tag_id'] )) { - $whereSql .= "WHERE tg.`tag_id` = ?"; - $bindVars[] = $pParamHash['tag_id']; - }elseif( isset( $pParamHash['tag'] ) ) { - $whereSql .= "WHERE tg.`tag` = ?"; - $bindVars[] = $pParamHash['tag']; - } - - $query = " SELECT tg.* FROM `".BIT_DB_PREFIX."tags` tg $whereSql"; - if ( $result = $this->mDb->getRow( $query, $bindVars ) ){ - $pParamHash['tag_id'] = $result['tag_id']; - $this->mTagId = $result['tag']; - $ret = TRUE; - }; - - return $ret; - } - - - - /** - * @param array pParams hash of values that will be used to store the page - * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why - * @access public - **/ - function store( &$pParamHash ) { - if( $this->verify( $pParamHash ) ) { - $this->mDb->StartTrans(); - if (!empty($pParamHash['tag_store'])) { - $tagtable = BIT_DB_PREFIX."tags"; - $maptable = BIT_DB_PREFIX."tags_content_map"; - - if( $this->verifyTag($pParamHash['tag_store']) ) { - $pParamHash['tag_map_store']['tag_id'] = $pParamHash['tag_store']['tag_id']; - $this->mDb->associateInsert( $maptable, $pParamHash['tag_map_store'] ); - } else { - $pParamHash['tag_store']['tag_id'] = $this->mDb->GenID( 'tags_tag_id_seq' ); - $this->mDb->associateInsert( $tagtable, $pParamHash['tag_store'] ); - $this->mTagId = $pParamHash['tag_map_store']['tag_id'] = $pParamHash['tag_store']['tag_id']; - $this->mDb->associateInsert( $maptable, $pParamHash['tag_map_store'] ); - } - } - $this->mDb->CompleteTrans(); - // since we use store generally in a loop of several tags we should not load here - //$this->load(); - } - return( count( $this->mErrors )== 0 ); - } - - - - function storeOneTag( &$pParamHash ) { - if( $this->verify( $pParamHash ) ) { - $this->mDb->StartTrans(); - if (!empty($pParamHash['tag_store'])) { - $tagtable = BIT_DB_PREFIX."tags"; - - if( isset($pParamHash['tag_store']['tag_id']) ) { - //this is kind of ugly but it works right - $this->mDb->associateUpdate( $tagtable, array("tag" => $pParamHash['tag_store']['tag']), array( "tag_id" => $pParamHash['tag_id'] ) ); - } else { - $pParamHash['tag_store']['tag_id'] = $this->mDb->GenID( 'tags_tag_id_seq' ); - $this->mDb->associateInsert( $tagtable, $pParamHash['tag_store'] ); - } - } - $this->mDb->CompleteTrans(); - $this->loadTag( $pParamHash['tag_store'] ); - } - return( count( $this->mErrors )== 0 ); - } - - function sanitizeTag($pTag) { - global $gBitSystem; - - // We always trim tags - $pTag = trim($pTag); - - if( $gBitSystem->isFeatureActive("tags_strip_spaces") ) { - $pTag = preg_replace('/\s+/', '', $pTag); - } - - if( $gBitSystem->isFeatureActive("tags_strip_nonword") ) { - $pTag = preg_replace('/\W+/', '', $pTag); - } - - if( $gBitSystem->isFeatureActive("tags_lowercase") ) { - $pTag = strtolower($pTag); - } - - if( $gBitSystem->getConfig('tags_strip_regexp') ) { - $pTag = preg_replace($gBitSystem->getConfig('tags_strip_regexp', $pTag), $gBitSystem->getConfig('tags_strip_replace'), $pTag); - } - return $pTag; - } - - /* make tag data is safe to store - */ - function verifyTagsMap( &$pParamHash ) { - global $gBitUser, $gBitSystem; - - $pParamHash['tag_map_store'] = array(); - - //this is to set the time we add content to a tag. - $timeStamp = $gBitSystem->getUTCTime(); - - //need to break up this string - $tagMixed = isset($pParamHash['tags']) ? $pParamHash['tags'] : NULL; - if( !empty( $tagMixed )){ - if (!is_array( $tagMixed ) && !is_numeric( $tagMixed ) ){ - $tagIds = explode( ",", $tagMixed ); - }else if ( is_array( $tagMixed ) ) { - $tagIds = $tagMixed; - }else if ( is_numeric( $tagMixed ) ) { - $tagIds = array( $tagMixed ); - } - - foreach( $tagIds as $value ) { - $value = trim($value); - /* Ignore empty tags like a trailing , generate */ - if( !empty($value) ) { - $value = LibertyTag::sanitizeTag($value); - if ( !empty($value) ) { - array_push( $pParamHash['tag_map_store'], array( - 'tag' => $value, - 'tagged_on' => $timeStamp, - 'content_id' => $this->mContentId, - 'user_id' => $gBitUser->mUserId, - )); - } - else { - $this->mErrors[$value] = "Invalid tag."; - } - } - } - } - - return ( count( $this->mErrors ) == 0 ); - } - - - /** - * @param array pParams hash includes mix of tags that will be storeded and associated with a ContentId used by service - * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why - * @access public - **/ - function storeTags( &$pParamHash ){ - global $gBitSystem; - if( $this->verifyTagsMap( $pParamHash ) ) { - if( $this->isValid() ) { - foreach ( $pParamHash['tag_map_store'] as $value) { - $result = $this->store( $value ); - } - $this->load(); - } - } - return ( count( $this->mErrors ) == 0 ); - } - - - /** - * check if the mContentId is set and valid - */ - function isValid() { - return( @BitBase::verifyId( $this->mContentId ) ); - } - - /** - * This function removes a tag entry - **/ - function expunge( $tag_id ) { - $ret = FALSE; - $this->mDb->StartTrans(); - $query = "DELETE FROM `".BIT_DB_PREFIX."tags_content_map` WHERE `tag_id` = ?"; - - if ( $result = $this->mDb->query( $query, array( $tag_id ) ) ){ - // remove all references to tag in tags_content_map - $query = "DELETE FROM `".BIT_DB_PREFIX."tags` WHERE `tag_id` = ?"; - if ( $result = $this->mDb->query( $query, array( $tag_id ) ) ) { - $ret = TRUE; - }else{ - //some rollback feature would be nice here - } - } - $this->mDb->CompleteTrans(); - return $ret; - } - - /** - * This function removes all references to contentid from tags_content_map - **/ - function expungeContentFromTagMap(){ - $ret = FALSE; - if( $this->isValid() ) { - $this->mDb->StartTrans(); - $query = "DELETE FROM `".BIT_DB_PREFIX."tags_content_map` WHERE `content_id` = ?"; - $result = $this->mDb->query( $query, array( $this->mContentId ) ); - $this->mDb->CompleteTrans(); - } - return $ret; - } - - /** - * This function removes all references to contentid from tags_content_map - **/ - function expungeMyContentFromTagMap( &$pObject ){ - global $gBitUser; - $ret = FALSE; - if( $this->isValid() ) { - $this->mDb->StartTrans(); - $whereSql = ""; - $bindVars[] = $this->mContentId; - if( !$pObject->hasAdminPermission() ){ - $whereSql .= " AND tagger_id = ?"; - $bindVars[] = $gBitUser->mUserId; - } - $query = "DELETE FROM `".BIT_DB_PREFIX."tags_content_map` WHERE `content_id` = ? $whereSql"; - $result = $this->mDb->query( $query, $bindVars ); - $this->mDb->CompleteTrans(); - } - return $ret; - } - - /** - * The function removes one or more tag from a piece of content - */ - function expungeTags($pContentId, $pTagIdArray) { - if (LibertyContent::verifyId($pContentId)) { - $this->mDb->StartTrans(); - $query = "DELETE FROM `".BIT_DB_PREFIX."tags_content_map` WHERE `content_id` = ? AND `tag_id` IN (".implode( ',',array_fill( 0,count( $pTagIdArray ),'?' ) )." )"; - $bind[] = $pContentId; - $bind = array_merge($bind, $pTagIdArray); - $result = $this->mDb->query( $query, $bind ); - foreach( $pTagIdArray as $tagId ) { - if( !$this->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."tags_content_map` WHERE `tag_id`=?", array( $tagId ) ) ) { - $this->expunge( $tagId ); - } - } - $this->mDb->CompleteTrans(); - } - } - - function getDisplayUriWithTag( $tag ) { - return BIT_BASE_URI.$this->getDisplayUrlWithTag( $tag ); - } - - function getDisplayUrlWithTag($tag){ - global $gBitSystem; - if( $gBitSystem->isFeatureActive( 'pretty_urls' ) || $gBitSystem->isFeatureActive( 'pretty_urls_extended' ) ) { - $rewrite_tag = $gBitSystem->isFeatureActive( 'pretty_urls_extended' ) ? 'view/':''; - $tag_url = TAGS_PKG_URL.$rewrite_tag.urlencode( $tag ); - } else { - $tag_url = TAGS_PKG_URL.'index.php?tags='.urlencode( $tag ); - } - return $tag_url; - } - - /** - * 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 - FROM `".BIT_DB_PREFIX."tags` tg - INNER JOIN `".BIT_DB_PREFIX."tags_content_map` tgc ON ( tgc.`tag_id` = tg.`tag_id` ) - $joinSql - GROUP BY tg.`tag_id`,tg.`tag` - ORDER 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; - } - - - /** - * This function gets the number of times a tag is used aka Popularity Count - **/ - function getPopCount($tag_id){ - $queryCount = " - SELECT COUNT( * ) - FROM `".BIT_DB_PREFIX."tags_content_map` tgc - WHERE tgc.`tag_id` = ?"; - $cant = $this->mDb->getOne($queryCount, array($tag_id) ); - return $cant; - } - - /** - * This function gets all content by matching to any tag passed in a group of tags, eliminates dupe records - **/ - function assignContentList(&$pParamHash){ - global $gBitSystem, $gBitSmarty; - - $gBitSystem->verifyPermission( 'p_tags_view' ); - - // some content specific offsets and pagination settings - if( !empty( $pParamHash['sort_mode'] )) { - $content_sort_mode = $pParamHash['sort_mode']; - $gBitSmarty->assign( 'sort_mode', $content_sort_mode ); - } - - $max_content = ( !empty( $pParamHash['max_records'] )) ? $pParamHash['max_records'] : $gBitSystem->getConfig( 'max_records' ); - $gBitSmarty->assign( 'user_id', @BitBase::verifyId( $pParamHash['user_id'] ) ? $pParamHash['user_id'] : NULL ); - - // now that we have all the offsets, we can get the content list - include_once( LIBERTY_PKG_INCLUDE_PATH.'get_content_list_inc.php' ); - - $gBitSmarty->assign( 'contentSelect', $contentSelect ); - $gBitSmarty->assign( 'contentTypes', $contentTypes ); - $contentListHash['parameters']['content_type_guid'] = $contentSelect; - $gBitSmarty->assign( 'listInfo', $contentListHash ); - $gBitSmarty->assign( 'content_type_guids', ( isset( $pParamHash['content_type_guid'] ) ? $pParamHash['content_type_guid'] : NULL )); - - if ( isset($pParamHash['matchtags']) && $pParamHash['matchtags'] == 'all'){ - //need some sort of matching function - } else { - //match on any tags - $distinctdata = $this->array_distinct( $contentList, 'content_id' ); - $distinctdata = array_merge($distinctdata); - } - $gBitSmarty->assignByRef('contentList', $distinctdata); - return $contentList; - } - - - /** - * Used by getContentList to strip out duplicate records in a list - * Lifted from http://us3.php.net/manual/en/function.array-unique.php#57006 - * - * @param $array - nothing to say - * @param $group_keys - columns which have to be grouped - can be STRING or ARRAY (STRING, STRING[, ...]) - * @param $sum_keys - columns which have to be summed - can be STRING or ARRAY (STRING, STRING[, ...]) - * @param $count_key - must be STRING - count the grouped keys - */ - function array_distinct ($array, $group_keys, $sum_keys = NULL, $count_key = NULL){ - if (!is_array ($group_keys)) $group_keys = array ($group_keys); - if (!is_array ($sum_keys)) $sum_keys = array ($sum_keys); - - $existing_sub_keys = array (); - $output = array (); - - foreach ($array as $key => $sub_array){ - $puffer = NULL; - #group keys - foreach ($group_keys as $group_key){ - $puffer .= $sub_array[$group_key]; - } - $puffer = serialize ($puffer); - if (!in_array ($puffer, $existing_sub_keys)){ - $existing_sub_keys[$key] = $puffer; - $output[$key] = $sub_array; - } - else{ - $puffer = array_search ($puffer, $existing_sub_keys); - #sum keys - foreach ($sum_keys as $sum_key){ - if (is_string ($sum_key)) $output[$puffer][$sum_key] += $sub_array[$sum_key]; - } - #count grouped keys - if (!array_key_exists ($count_key, $output[$puffer])) $output[$puffer][$count_key] = 1; - if (is_string ($count_key)) $output[$puffer][$count_key]++; - } - } - return $output; - } - -} - -/********* SERVICE FUNCTIONS *********/ -function tags_content_display( &$pObject ) { - global $gBitSystem, $gBitSmarty, $gBitUser; - - if( method_exists( $pObject, 'getContentType' ) && $gBitSystem->isFeatureActive( 'tags_tag_'.$pObject->getContentType()) ){ - if ( $gBitSystem->isPackageActive( 'tags' ) ) { - if( $gBitUser->hasPermission( 'p_tags_view' ) ) { - $tag = new LibertyTag( $pObject->mContentId ); - if( $tag->load() ) { - $gBitSmarty->assign( 'tagData', !empty( $tag->mInfo['tags'] ) ? $tag->mInfo['tags'] : NULL ); - } - } - } - } -} - -/** - * filter the search with pigeonholes - * @param $pParamHash['tags']['filter'] - a tag or an array of tags - **/ -function tags_content_list_sql( &$pObject, &$pParamHash = NULL ) { - global $gBitSystem; - $ret = array(); - - if (isset($pParamHash['tags']) && !empty($pParamHash['tags'])){ - /* slated for removal - makes no sense since content likely has multiple tags */ - // $ret['select_sql'] = ", tgc.`tag_id`, tgc.`tagger_id`, tgc.`tagged_on`"; - $ret['join_sql'] = " INNER JOIN `".BIT_DB_PREFIX."tags_content_map` tgc ON ( lc.`content_id`=tgc.`content_id` ) - INNER JOIN `".BIT_DB_PREFIX."tags` tg ON ( tg.`tag_id`=tgc.`tag_id` )"; - - $tagMixed = $pParamHash['tags']; //need to break up this string - if( !empty( $tagMixed )){ - if (!is_array( $tagMixed ) && !is_numeric( $tagMixed ) ){ - $tagIds = explode( ",", $tagMixed ); - }else if ( is_array( $tagMixed ) ) { - $tagIds = $tagMixed; - }else if ( is_numeric( $tagMixed ) ) { - $tagIds = array( $tagMixed ); - } - } - - $tags = array(); - // strip off whitespace - foreach( $tagIds as $value ){ - // ignore empty ones created by trailing ,'s - $value = trim( $value ); - if( !empty($value) ) { - $tags[] = $value; - } - } - - $ret['where_sql'] = ' AND tg.`tag` IN ('.implode( ',', array_fill(0, count( $tags ), '?' ) ).')'; - - $ret['bind_vars'] = $tags; - - // return the values sent for pagination / url purposes - $pParamHash['listInfo']['tags'] = $pParamHash['tags']; - $pParamHash['listInfo']['ihash']['tags'] = $pParamHash['tags']; - } - - return $ret; -} - -function tags_content_edit( $pObject=NULL ) { - global $gBitSystem, $gBitSmarty, $gBitUser; - - if( method_exists( $pObject, 'getContentType' ) && $gBitSystem->isFeatureActive( 'tags_tag_'.$pObject->getContentType()) ){ - if ( $gBitSystem->isPackageActive( 'tags' )) { - $tag = new LibertyTag( $pObject->mContentId ); - if( $tag->load() && ($pObject->hasUserPermission( 'p_tags_create' ) || $gBitUser->hasPermission( 'p_tags_moderate' )) ) { - $tags = array(); - foreach ($tag->mInfo['tags'] as $t) { - if ($t['tagger_id'] == $gBitUser->mUserId || $gBitUser->hasPermission('p_tags_admin') ) { - $tags[] = $t['tag']; - } - } - - $pObject->setField( 'tags', implode(", ", $tags) ); - - $gBitSmarty->assign( 'loadTags', TRUE ); - $gBitSmarty->assign( 'tagList', $pObject->getField( 'tags' ) ); - $gBitSmarty->assign( 'tagData', $tag->getField( 'tags' ) ); - } - } - } -} - -/** - * @param includes a string or array of 'tags' and contentid for association. - **/ -function tags_content_store( &$pObject, &$pParamHash ) { - global $gBitUser, $gBitSystem; - if( $gBitUser->hasPermission( 'p_tags_create' ) ) { - $errors = NULL; - // If a content access system is active, let's call it - if( $gBitSystem->isPackageActive( 'tags' ) && isset( $pParamHash['tags'] ) ) { - $tag = new LibertyTag( $pObject->mContentId ); - if( $gBitUser->hasPermission('p_tags_create') ) { - $tag->expungeMyContentFromTagMap( $pObject ); - } - if ( !$tag->storeTags( $pParamHash ) ) { - $errors=$tag->mErrors; - } - } - return( $errors ); - } -} - -function tags_content_preview( &$pObject) { - global $gBitUser, $gBitSystem, $gBitSmarty; - tags_content_edit( $pObject ); - if( $gBitUser->hasPermission( 'p_tags_create' ) ) { - if ( $gBitSystem->isPackageActive( 'tags' ) ) { - if (isset($_REQUEST['tags'])) { - //$pObject->mInfo['tags'] = $_REQUEST['tags']; - $gBitSmarty->assign('tagList', $_REQUEST['tags']); - } - } - } -} - -function tags_content_expunge( &$pObject ) { - $tag = new LibertyTag( $pObject->mContentId ); - $tag->expungeContentFromTagMap(); -} - -// make sure all tags from a deleted user are nuked -function tags_user_expunge( &$pObject ) { - if( is_a( $pObject, 'BitUser' ) && !empty( $pObject->mUserId ) ) { - $pObject->mDb->StartTrans(); - $pObject->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."tags_content_map` WHERE tagger_id=?", array( $pObject->mUserId ) ); - $pObject->mDb->CompleteTrans(); - } -} - -?> diff --git a/admin/admin_tags_inc.php b/admin/admin_tags_inc.php old mode 100644 new mode 100755 index 6533da1..d8fc015 --- a/admin/admin_tags_inc.php +++ b/admin/admin_tags_inc.php @@ -4,108 +4,108 @@ // 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. -$formTagsDisplayOptions = array( - "tags_in_nav" => array( +$formTagsDisplayOptions = [ + "tags_in_nav" => [ 'label' => 'Nav', 'note' => 'Shows the tags in the "nav" location', 'type' => 'toggle', - ), - "tags_in_body" => array( + ], + "tags_in_body" => [ 'label' => 'Body', 'note' => 'Shows the tags in the "body" location', 'type' => 'toggle', - ), - "tags_in_view" => array( + ], + "tags_in_view" => [ 'label' => 'View', 'note' => 'Shows the tags in the "view" location', 'type' => 'toggle', - ), -); + ], +]; $gBitSmarty->assign( 'formTagsDisplayOptions', $formTagsDisplayOptions ); /* -$formTagsOtherOptions = array( - "tags_on_comments" => array( +$formTagsOtherOptions = [ + "tags_on_comments" => [ 'label' => 'Allow Tags on Comments', 'note' => 'Allows tags to be placed on comments', 'type' => 'toggle', - ), -); +], +]; $gBitSmarty->assign( 'formTagsOtherOptions', $formTagsOtherOptions ); */ -$formTagsStripOptions = array( - "tags_lowercase" => array( +$formTagsStripOptions = [ + "tags_lowercase" => [ 'label' => 'Lowercase Tags', 'note' => 'Convert all Tags to lowercase', 'type' => 'toggle', - ), - "tags_strip_spaces" => array( + ], + "tags_strip_spaces" => [ 'label' => 'Strip Spaces', 'note' => 'Strip white space from tags', 'type' => 'toggle', - ), - "tags_strip_nonword" => array( + ], + "tags_strip_nonword" => [ 'label' => 'Strip Non-Word', 'note' => 'Strip non-word characters from tags', 'type' => 'toggle', - ), - "tags_strip_regexp" => array( + ], + "tags_strip_regexp" => [ 'label' => 'Strip Custom', 'note' => 'A regular expression used to strip. Be VERY careful with this expression. This should include the delimiters for the regular expression.', 'type' => 'input', - ), - "tags_strip_replace" => array( + ], + "tags_strip_replace" => [ 'label' => 'Strip Custom Replacement', 'note' => 'The expresion used in the replacement made with the Strip Custom above. Leave blank to just strip any matches.', 'type' => 'input', - ), -); + ], +]; $gBitSmarty->assign( 'formTagsStripOptions', $formTagsStripOptions ); -$formTagLists = array( - "tags_list_id" => array( +$formTagLists = [ + "tags_list_id" => [ 'label' => 'ID', 'note' => 'Content ID', 'type' => 'toggle', - ), - "tags_list_title" => array( + ], + "tags_list_title" => [ 'label' => 'Title', 'note' => 'content title', 'type' => 'toggle', - ), - "tags_list_type" => array( + ], + "tags_list_type" => [ 'label' => 'Type', 'note' => 'content type', 'type' => 'toggle', - ), - "tags_list_author" => array( + ], + "tags_list_author" => [ 'label' => 'Author', 'note' => 'author of tagged content', 'type' => 'toggle', - ), - "tags_list_editor" => array( + ], + "tags_list_editor" => [ 'label' => 'Editor', 'note' => 'last editor', 'type' => 'toggle', - ), - "tags_list_lastmodif" => array( + ], + "tags_list_lastmodif" => [ 'label' => 'last modified', 'note' => 'modification date', 'type' => 'toggle', - ), - "tags_list_ip" => array( + ], + "tags_list_ip" => [ 'label' => 'IP', 'note' => 'editor\'s IP', 'type' => 'toggle', - ), -); + ], +]; $gBitSmarty->assign( 'formTagLists',$formTagLists ); // list of content types that can be tagged // 'sample' is presented anyways, if sample package is installed // 'bitcomment' (?) ... isFeatureActive('tags_on_comments') -$exclude = array( 'bituser', 'tikisticky', 'sample', 'bitcomment'); +$exclude = [ 'bituser', 'tikisticky', 'sample', 'bitcomment']; foreach( $gLibertySystem->mContentTypes as $cType ) { if( !in_array( $cType['content_type_guid'], $exclude ) ) { $formTaggable['guids']['tags_tag_'.$cType['content_type_guid']] = $gLibertySystem->getContentTypeName( $cType['content_type_guid'] ); @@ -125,7 +125,7 @@ if( !empty( $_REQUEST['tags_preferences'] ) ) { } } foreach( array_keys( $formTaggable['guids'] ) as $taggable ) { - $gBitSystem->storeConfig( $taggable, ( ( !empty( $_REQUEST['taggable_content'] ) && in_array( $taggable, $_REQUEST['taggable_content'] ) ) ? 'y' : NULL ), TAGS_PKG_NAME ); + $gBitSystem->storeConfig( $taggable, !empty( $_REQUEST['taggable_content'] ) && in_array( $taggable, $_REQUEST['taggable_content'] ) ? 'y' : null, TAGS_PKG_NAME); } } @@ -138,5 +138,3 @@ foreach( $gLibertySystem->mContentTypes as $cType ) { } $gBitSmarty->assign( 'formTaggable', $formTaggable ); - -?> diff --git a/admin/schema_inc.php b/admin/schema_inc.php index f2b1290..8b63aa6 100644 --- a/admin/schema_inc.php +++ b/admin/schema_inc.php @@ -1,5 +1,5 @@ " tag_id I4 PRIMARY, tag C(64) NOTNULL @@ -14,7 +14,7 @@ $tables = array( , CONSTRAINT `tags_content_map_content_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."liberty_content` ( `content_id` ) , CONSTRAINT `tags_content_map_tagger_id_ref` FOREIGN KEY (`tagger_id`) REFERENCES `".BIT_DB_PREFIX."users_users` ( `user_id` )' " -); +]; global $gBitInstaller; @@ -22,36 +22,36 @@ foreach( array_keys( $tables ) AS $tableName ) { $gBitInstaller->registerSchemaTable( TAGS_PKG_NAME, $tableName, $tables[$tableName] ); } -$gBitInstaller->registerPackageInfo( TAGS_PKG_NAME, array( +$gBitInstaller->registerPackageInfo( TAGS_PKG_NAME, [ 'description' => "A simple Liberty Service that any package can use to tag its content with key words.", 'license' => 'LGPL', -) ); +] ); -$gBitInstaller->registerPreferences( TAGS_PKG_NAME, array( - array( TAGS_PKG_NAME, 'tags_in_view', 'y' ), - array( TAGS_PKG_NAME, 'tags_list_title', 'y' ), - array( TAGS_PKG_NAME, 'tags_list_type', 'y' ), - array( TAGS_PKG_NAME, 'tags_list_author', 'y' ), - array( TAGS_PKG_NAME, 'tags_list_lastmodif', 'y' ), -) ); +$gBitInstaller->registerPreferences( TAGS_PKG_NAME, [ + [ TAGS_PKG_NAME, 'tags_in_view', 'y' ], + [ TAGS_PKG_NAME, 'tags_list_title', 'y' ], + [ TAGS_PKG_NAME, 'tags_list_type', 'y' ], + [ TAGS_PKG_NAME, 'tags_list_author', 'y' ], + [ TAGS_PKG_NAME, 'tags_list_lastmodif', 'y' ], +] ); // ### Sequences -$sequences = array ( - 'tags_tag_id_seq' => array( 'start' => 1 ), -); +$sequences = [ + 'tags_tag_id_seq' => [ 'start' => 1 ], +]; $gBitInstaller->registerSchemaSequences( TAGS_PKG_NAME, $sequences ); // ### Default UserPermissions -$gBitInstaller->registerUserPermissions( TAGS_PKG_NAME, array( - array( 'p_tags_admin', 'Can admin tags', 'admin', TAGS_PKG_NAME ), - array( 'p_tags_create', 'Can create tags', 'registered', TAGS_PKG_NAME ), - array( 'p_tags_view', 'Can view tags', 'basic', TAGS_PKG_NAME ), - array( 'p_tags_moderate', 'Can edit tags', 'editors', TAGS_PKG_NAME ), -) ); +$gBitInstaller->registerUserPermissions( TAGS_PKG_NAME, [ + [ 'p_tags_admin', 'Can admin tags', 'admin', TAGS_PKG_NAME ], + [ 'p_tags_create', 'Can create tags', 'registered', TAGS_PKG_NAME ], + [ 'p_tags_view', 'Can view tags', 'basic', TAGS_PKG_NAME ], + [ 'p_tags_moderate', 'Can edit tags', 'editors', TAGS_PKG_NAME ], +] ); // Requirements -$gBitInstaller->registerRequirements( TAGS_PKG_NAME, array( - 'liberty' => array( 'min' => '2.1.4' ), -)); +$gBitInstaller->registerRequirements( TAGS_PKG_NAME, [ + 'liberty' => [ 'min' => '5.0.0' ], +] ); diff --git a/drop_tags.php b/drop_tags.php old mode 100644 new mode 100755 index e8dcbea..9b4a1a7 --- a/drop_tags.php +++ b/drop_tags.php @@ -12,12 +12,14 @@ /** * required setup */ -require_once( "../kernel/includes/setup_inc.php" ); -require_once( TAGS_PKG_CLASS_PATH.'LibertyTag.php' ); +require_once "../kernel/includes/setup_inc.php"; +use Bitweaver\Tags\LibertyTag; +use Bitweaver\KernelTools; +use Bitweaver\HttpStatusCodes; $gBitSystem->verifyPackage( 'tags' ); -require_once( LIBERTY_PKG_INCLUDE_PATH.'lookup_content_inc.php' ); +require_once LIBERTY_PKG_INCLUDE_PATH.'lookup_content_inc.php'; if (!$gContent || !$gContent->isValid()) { $gBitSystem->fatalError( 'The content is not valid.' ); @@ -37,19 +39,15 @@ if( isset( $_REQUEST["confirm"] ) ) { header("location: ".$gContent->getDisplayUrl()); } -$gBitSystem->setBrowserTitle( tra( 'Confirm drop of tags from: ' ).$gContent->getTitle() ); +$gBitSystem->setBrowserTitle( KernelTools::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' ), + 'label' => KernelTools::tra( 'Drop Tags' ), 'confirm_item' => implode("
", $tags), - 'warning' => tra( 'These tags will be dropped from this content.
This cannot be undone!' ), + 'warning' => KernelTools::tra( 'These tags will be dropped from this content.
This cannot be undone!' ), ); $gBitSystem->confirmDialog( $formHash,$msgHash ); - - - -?> diff --git a/edit.php b/edit.php old mode 100644 new mode 100755 index 16a0d16..4e6e791 --- a/edit.php +++ b/edit.php @@ -12,8 +12,9 @@ /** * required setup */ -require_once( "../kernel/includes/setup_inc.php" ); -require_once( TAGS_PKG_CLASS_PATH.'LibertyTag.php' ); +require_once "../kernel/includes/setup_inc.php"; +use Bitweaver\Tags\LibertyTag; +use Bitweaver\KernelTools; $gBitSystem->verifyPackage( 'tags' ); @@ -33,5 +34,4 @@ if( !empty( $_REQUEST["save"] ) ) { } } -$gBitSystem->display( 'bitpackage:tags/edit_tag.tpl', tra( "Edit Tag" ) , array( 'display_mode' => 'edit' )); -?> +$gBitSystem->display( 'bitpackage:tags/edit_tag.tpl', KernelTools::tra( "Edit Tag" ) , array( 'display_mode' => 'edit' )); diff --git a/includes/bit_setup_inc.php b/includes/bit_setup_inc.php old mode 100644 new mode 100755 index 6774732..c4b1dfb --- a/includes/bit_setup_inc.php +++ b/includes/bit_setup_inc.php @@ -1,32 +1,39 @@ 'tags', 'package_path' => dirname( dirname( __FILE__ ) ).'/', 'service' => LIBERTY_SERVICE_TAGS, -); -$gBitSystem->registerPackage( $registerHash ); +]; + +// fix to quieten down VS Code which can't see the dynamic creation of these ... +define( 'TAGS_PKG_NAME', $pRegisterHash['package_name'] ); +define( 'TAGS_PKG_URL', BIT_ROOT_URL . basename( $pRegisterHash['package_path'] ) . '/' ); +define( 'TAGS_PKG_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/' ); +define( 'TAGS_PKG_INCLUDE_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/includes/'); +define( 'TAGS_PKG_CLASS_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/includes/classes/'); +define( 'TAGS_PKG_ADMIN_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/admin/'); +$gBitSystem->registerPackage( $pRegisterHash ); if( $gBitSystem->isPackageActive( 'tags' ) && $gBitUser->hasPermission( 'p_tags_view' )) { // load css file $gBitThemes->loadCss( TAGS_PKG_PATH.'templates/tags.css' ); - require_once( TAGS_PKG_CLASS_PATH.'LibertyTag.php' ); - - $menuHash = array( + $menuHash = [ 'package_name' => TAGS_PKG_NAME, 'index_url' => TAGS_PKG_URL.'index.php', 'menu_template' => 'bitpackage:tags/menu_tags.tpl', - ); + ]; $gBitSystem->registerAppMenu( $menuHash ); $gLibertySystem->registerService( LIBERTY_SERVICE_TAGS, TAGS_PKG_NAME, - array( + [ 'content_display_function' => 'tags_content_display', 'content_edit_function' => 'tags_content_edit', 'content_list_sql_function' => 'tags_content_list_sql', @@ -39,10 +46,9 @@ if( $gBitSystem->isPackageActive( 'tags' ) && $gBitUser->hasPermission( 'p_tags_ 'content_body_tpl' => 'bitpackage:tags/view_tags_body.tpl', 'users_expunge_function' => 'tags_user_expunge', 'content_search_tpl' => 'bitpackage:tags/search_inc.tpl' - ), - array( - 'description' => tra( 'Enables the addition of tags to any content' ), - ) + ], + [ + 'description' => KernelTools::tra( 'Enables the addition of tags to any content' ), + ] ); } -?> diff --git a/includes/classes/LibertyTag.php b/includes/classes/LibertyTag.php new file mode 100755 index 0000000..df75c8c --- /dev/null +++ b/includes/classes/LibertyTag.php @@ -0,0 +1,753 @@ +mContentId = $pContentId; + } + + + /* Delete when package complete! -wjames5 + * methods needed + * + * get all tags limited by content_id <- load + * get all tags <- getList + * get all content for tag_id <- getContentList + * get tags by map use count <- getList with map refs count + * get tags sorted by tagged date <- getList sorted by map tagged date + * + * store new tags from tags array + * store new tag-content map for content_id + * expunge tag and all tag-content maps + * expunge tag-content map for content_id + * + */ + + + /** + * Load all the tags for a given ContentId + * @param array pParamHash be sure to pass by reference in case we need to make modifcations to the hash + **/ + function load() { + if( $this->isValid() ) { + $query = " + SELECT tgc.*, tg.* + FROM `".BIT_DB_PREFIX."tags_content_map` tgc + INNER JOIN `".BIT_DB_PREFIX."tags` tg ON tg.`tag_id` = tgc.`tag_id` + WHERE tgc.`content_id`=?"; + + //$this->mInfo = $this->mDb->query( $query, array( $this->mContentId ) ); + $result = $this->mDb->query( $query, array( $this->mContentId ) ); + if ($result) { + $ret = []; + while ($res = $result->fetchRow()) { + //Add tag urls + $res['tag_url'] = LibertyTag::getDisplayUrlWithTag($res['tag']); + + $ret[] = $res; + } + $this->mInfo['tags'] = $ret; + } + } + return count( $this->mInfo ); + } + + function loadTag ( &$pParamHash ){ + if( !empty( $pParamHash['tag_id'] ) && is_numeric( $pParamHash['tag_id'] )) { + $selectSql = ''; $joinSql = ''; $whereSql = ''; + $bindVars = []; + + $whereSql .= "WHERE tg.`tag_id` = ?"; + $bindVars[] = $pParamHash['tag_id']; + + $query = " + SELECT tg.* + FROM `".BIT_DB_PREFIX."tags` tg + $whereSql"; + + if ( $result = $this->mDb->getRow( $query, $bindVars ) ){ + //Add tag url + $result['tag_url'] = LibertyTag::getDisplayUrlWithTag($result['tag']); + + $this->mInfo = $result; + }; + } + return count( $this->mInfo ); + } + + + + /** + * Make sure the data is safe to store + * @param array pParams reference to hash of values that will be used to store the page, they will be modified where necessary + * @return bool true on success, false if verify failed. If false, $this->mErrors will have reason why + * @access private + **/ + public function verify( array &$pParamHash ): bool { + global $gBitUser, $gBitSystem; + $pParamHash['tag_store'] = []; + $pParamHash['tag_map_store'] = []; + + if(!empty( $pParamHash['tag'])){ + $pParamHash['tag_store']['tag'] = $pParamHash['tag']; + } + if( !empty( $pParamHash['tag_id']) && is_numeric( $pParamHash['tag_id'])){ +// $pParamHash['tag_map_store']['tag_id'] = $pParamHash['tag_id']; + $pParamHash['tag_store']['tag_id'] = $pParamHash['tag_id']; + } + $pParamHash['tag_map_store']['tagged_on'] = isset( $pParamHash['tagged_on']) ? $pParamHash['tagged_on'] : $gBitSystem->getUTCTime(); + + if( @$this->verifyId( $pParamHash['content_id']) ){ + $pParamHash['tag_map_store']['content_id'] = $pParamHash['content_id']; + }/* else { + $this->mErrors['content_id'] = "No content id specified."; + }*/ + if( $gBitUser->mUserId ){ + $pParamHash['tag_map_store']['tagger_id'] = $gBitUser->mUserId; + } else { + $this->mErrors['user_id'] = "No user id specified."; + } + + return count( $this->mErrors )== 0; + } + + + /* check tag exists + */ + function verifyTag ( &$pParamHash ){ + $ret = false; + $selectSql = ''; $joinSql = ''; $whereSql = ''; + $bindVars = []; + + // Bounds checking on tag name length + if( !empty( $pParamHash['tag'] ) && strlen( $pParamHash['tag'] ) > 64 ) { + $pParamHash['tag'] = substr( $pParamHash['tag'], 0, 64 ); + } + + // if tag_id supplied, use that + if( !empty( $pParamHash['tag_id'] ) && is_numeric( $pParamHash['tag_id'] )) { + $whereSql .= "WHERE tg.`tag_id` = ?"; + $bindVars[] = $pParamHash['tag_id']; + }elseif( isset( $pParamHash['tag'] ) ) { + $whereSql .= "WHERE tg.`tag` = ?"; + $bindVars[] = $pParamHash['tag']; + } + + $query = " SELECT tg.* FROM `".BIT_DB_PREFIX."tags` tg $whereSql"; + if ( $result = $this->mDb->getRow( $query, $bindVars ) ){ + $pParamHash['tag_id'] = $result['tag_id']; + $this->mTagId = $result['tag']; + $ret = true; + }; + + return $ret; + } + + + + /** + * @param array pParams hash of values that will be used to store the page + * @return bool true on success, false if store could not occur. If false, $this->mErrors will have reason why + **/ + public function store( array &$pParamHash): bool { + if( $this->verify( $pParamHash ) ) { + $this->mDb->StartTrans(); + if (!empty($pParamHash['tag_store'])) { + $tagtable = BIT_DB_PREFIX."tags"; + $maptable = BIT_DB_PREFIX."tags_content_map"; + + if( $this->verifyTag($pParamHash['tag_store']) ) { + $pParamHash['tag_map_store']['tag_id'] = $pParamHash['tag_store']['tag_id']; + $this->mDb->associateInsert( $maptable, $pParamHash['tag_map_store'] ); + } else { + $pParamHash['tag_store']['tag_id'] = $this->mDb->GenID( 'tags_tag_id_seq' ); + $this->mDb->associateInsert( $tagtable, $pParamHash['tag_store'] ); + $this->mTagId = $pParamHash['tag_map_store']['tag_id'] = $pParamHash['tag_store']['tag_id']; + $this->mDb->associateInsert( $maptable, $pParamHash['tag_map_store'] ); + } + } + $this->mDb->CompleteTrans(); + // since we use store generally in a loop of several tags we should not load here + //$this->load(); + } + return count( $this->mErrors )== 0; + } + + + + function storeOneTag( &$pParamHash ) { + if( $this->verify( $pParamHash ) ) { + $this->mDb->StartTrans(); + if (!empty($pParamHash['tag_store'])) { + $tagtable = BIT_DB_PREFIX."tags"; + + if( isset($pParamHash['tag_store']['tag_id']) ) { + //this is kind of ugly but it works right + $this->mDb->associateUpdate( $tagtable, array("tag" => $pParamHash['tag_store']['tag']), array( "tag_id" => $pParamHash['tag_id'] ) ); + } else { + $pParamHash['tag_store']['tag_id'] = $this->mDb->GenID( 'tags_tag_id_seq' ); + $this->mDb->associateInsert( $tagtable, $pParamHash['tag_store'] ); + } + } + $this->mDb->CompleteTrans(); + $this->loadTag( $pParamHash['tag_store'] ); + } + return count( $this->mErrors )== 0; + } + + function sanitizeTag($pTag) { + global $gBitSystem; + + // We always trim tags + $pTag = trim($pTag); + + if( $gBitSystem->isFeatureActive("tags_strip_spaces") ) { + $pTag = preg_replace('/\s+/', '', $pTag); + } + + if( $gBitSystem->isFeatureActive("tags_strip_nonword") ) { + $pTag = preg_replace('/\W+/', '', $pTag); + } + + if( $gBitSystem->isFeatureActive("tags_lowercase") ) { + $pTag = strtolower($pTag); + } + + if( $gBitSystem->getConfig('tags_strip_regexp') ) { + $pTag = preg_replace($gBitSystem->getConfig('tags_strip_regexp', $pTag), $gBitSystem->getConfig('tags_strip_replace'), $pTag); + } + return $pTag; + } + + /* make tag data is safe to store + */ + function verifyTagsMap( &$pParamHash ) { + global $gBitUser, $gBitSystem; + + $pParamHash['tag_map_store'] = []; + + //this is to set the time we add content to a tag. + $timeStamp = $gBitSystem->getUTCTime(); + + //need to break up this string + $tagMixed = isset($pParamHash['tags']) ? $pParamHash['tags'] : null; + if( !empty( $tagMixed )){ + if (!is_array( $tagMixed ) && !is_numeric( $tagMixed ) ){ + $tagIds = explode( ",", $tagMixed ); + }else if ( is_array( $tagMixed ) ) { + $tagIds = $tagMixed; + }else if ( is_numeric( $tagMixed ) ) { + $tagIds = array( $tagMixed ); + } + + foreach( $tagIds as $value ) { + $value = trim($value); + /* Ignore empty tags like a trailing , generate */ + if( !empty($value) ) { + $value = LibertyTag::sanitizeTag($value); + if ( !empty($value) ) { + array_push( $pParamHash['tag_map_store'], array( + 'tag' => $value, + 'tagged_on' => $timeStamp, + 'content_id' => $this->mContentId, + 'user_id' => $gBitUser->mUserId, + )); + } + else { + $this->mErrors[$value] = "Invalid tag."; + } + } + } + } + + return count( $this->mErrors ) == 0; + } + + + /** + * @param array pParams hash includes mix of tags that will be storeded and associated with a ContentId used by service + * @return bool true on success, false if store could not occur. If false, $this->mErrors will have reason why + * @access public + **/ + function storeTags( &$pParamHash ){ + global $gBitSystem; + if( $this->verifyTagsMap( $pParamHash ) ) { + if( $this->isValid() ) { + foreach ( $pParamHash['tag_map_store'] as $value) { + $result = $this->store( $value ); + } + $this->load(); + } + } + return count( $this->mErrors ) == 0; + } + + + /** + * check if the mContentId is set and valid + */ + public function isValid() { + return BitBase::verifyId( $this->mContentId ); + } + + /** + * This function removes a tag entry + **/ + public function expungeTag( $tag_id ): void { + $this->mDb->StartTrans(); + $query = "DELETE FROM `".BIT_DB_PREFIX."tags_content_map` WHERE `tag_id` = ?"; + + if ( $result = $this->mDb->query( $query, [ $tag_id ] ) ){ + // remove all references to tag in tags_content_map + $query = "DELETE FROM `".BIT_DB_PREFIX."tags` WHERE `tag_id` = ?"; + if ( $result = $this->mDb->query( $query, [ $tag_id ] ) ) { + $ret = true; + }else{ + //some rollback feature would be nice here + } + } + $this->mDb->CompleteTrans(); + } + + /** + * This function removes all references to contentid from tags_content_map + **/ + function expungeContentFromTagMap(){ + $ret = false; + if( $this->isValid() ) { + $this->mDb->StartTrans(); + $query = "DELETE FROM `".BIT_DB_PREFIX."tags_content_map` WHERE `content_id` = ?"; + $result = $this->mDb->query( $query, array( $this->mContentId ) ); + $this->mDb->CompleteTrans(); + } + return $ret; + } + + /** + * This function removes all references to contentid from tags_content_map + **/ + function expungeMyContentFromTagMap( &$pObject ){ + global $gBitUser; + $ret = false; + if( $this->isValid() ) { + $this->mDb->StartTrans(); + $whereSql = ""; + $bindVars[] = $this->mContentId; + if( !$pObject->hasAdminPermission() ){ + $whereSql .= " AND tagger_id = ?"; + $bindVars[] = $gBitUser->mUserId; + } + $query = "DELETE FROM `".BIT_DB_PREFIX."tags_content_map` WHERE `content_id` = ? $whereSql"; + $result = $this->mDb->query( $query, $bindVars ); + $this->mDb->CompleteTrans(); + } + return $ret; + } + + /** + * The function removes one or more tag from a piece of content + */ + function expungeTags($pContentId, $pTagIdArray) { + if (LibertyContent::verifyId($pContentId)) { + $this->mDb->StartTrans(); + $query = "DELETE FROM `".BIT_DB_PREFIX."tags_content_map` WHERE `content_id` = ? AND `tag_id` IN (".implode( ',',array_fill( 0,count( $pTagIdArray ),'?' ) )." )"; + $bind[] = $pContentId; + $bind = array_merge($bind, $pTagIdArray); + $result = $this->mDb->query( $query, $bind ); + foreach( $pTagIdArray as $tagId ) { + if( !$this->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."tags_content_map` WHERE `tag_id`=?", array( $tagId ) ) ) { + $this->expungeTag( $tagId ); + } + } + $this->mDb->CompleteTrans(); + } + } + + function getDisplayUriWithTag( $tag ) { + return BIT_BASE_URI.$this->getDisplayUrlWithTag( $tag ); + } + + function getDisplayUrlWithTag($tag){ + global $gBitSystem; + if( $gBitSystem->isFeatureActive( 'pretty_urls' ) || $gBitSystem->isFeatureActive( 'pretty_urls_extended' ) ) { + $rewrite_tag = $gBitSystem->isFeatureActive( 'pretty_urls_extended' ) ? 'view/':''; + $tag_url = TAGS_PKG_URL.$rewrite_tag.urlencode( $tag ); + } else { + $tag_url = TAGS_PKG_URL.'index.php?tags='.urlencode( $tag ); + } + return $tag_url; + } + + /** + * This function gets a list of tags + **/ + function getList( &$pParamHash ) { + global $gBitUser, $gBitSystem; + + $bindVars = []; + $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 + FROM `".BIT_DB_PREFIX."tags` tg + INNER JOIN `".BIT_DB_PREFIX."tags_content_map` tgc ON ( tgc.`tag_id` = tg.`tag_id` ) + $joinSql + GROUP BY tg.`tag_id`,tg.`tag` + ORDER 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 = []; + + 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 + $tagscale = $cantoffset > 9 ? 9/$cantoffset : 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 = []; + 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; + } + + + /** + * This function gets the number of times a tag is used aka Popularity Count + **/ + function getPopCount($tag_id){ + $queryCount = " + SELECT COUNT( * ) + FROM `".BIT_DB_PREFIX."tags_content_map` tgc + WHERE tgc.`tag_id` = ?"; + $cant = $this->mDb->getOne($queryCount, array($tag_id) ); + return $cant; + } + + /** + * This function gets all content by matching to any tag passed in a group of tags, eliminates dupe records + **/ + function assignContentList(&$pParamHash){ + global $gBitSystem, $gBitSmarty; + + $gBitSystem->verifyPermission( 'p_tags_view' ); + + // some content specific offsets and pagination settings + if( !empty( $pParamHash['sort_mode'] )) { + $content_sort_mode = $pParamHash['sort_mode']; + $gBitSmarty->assign( 'sort_mode', $content_sort_mode ); + } + + $max_content = ( !empty( $pParamHash['max_records'] )) ? $pParamHash['max_records'] : $gBitSystem->getConfig( 'max_records' ); + $gBitSmarty->assign( 'user_id', BitBase::verifyId( $pParamHash['user_id'] ) ? $pParamHash['user_id'] : null ); + + // now that we have all the offsets, we can get the content list + include_once LIBERTY_PKG_INCLUDE_PATH.'get_content_list_inc.php'; + + $gBitSmarty->assign( 'contentSelect', $contentSelect ); + $gBitSmarty->assign( 'contentTypes', $contentTypes ); + $contentListHash['parameters']['content_type_guid'] = $contentSelect; + $gBitSmarty->assign( 'listInfo', $contentListHash ); + $gBitSmarty->assign( 'content_type_guids', isset( $pParamHash['content_type_guid'] ) ? $pParamHash['content_type_guid'] : null ); + + if ( isset($pParamHash['matchtags']) && $pParamHash['matchtags'] == 'all'){ + //need some sort of matching function + } else { + //match on any tags + $distinctdata = $this->array_distinct( $contentList, 'content_id' ); + $distinctdata = array_merge($distinctdata); + } + $gBitSmarty->assign('contentList', $distinctdata); + return $distinctdata; + } + + + /** + * Used by getContentList to strip out duplicate records in a list + * Lifted from http://us3.php.net/manual/en/function.array-unique.php#57006 + * + * @param $array - nothing to say + * @param $group_keys - columns which have to be grouped - can be STRING or ARRAY (STRING, STRING[, ...]) + * @param $sum_keys - columns which have to be summed - can be STRING or ARRAY (STRING, STRING[, ...]) + * @param $count_key - must be STRING - count the grouped keys + */ + function array_distinct ($array, $group_keys, $sum_keys = null, $count_key = null){ + if (!is_array ($group_keys)) $group_keys = array ($group_keys); + if (!is_array ($sum_keys)) $sum_keys = array ($sum_keys); + + $existing_sub_keys = []; + $output = []; + + foreach ($array as $key => $sub_array){ + $puffer = null; + #group keys + foreach ($group_keys as $group_key){ + $puffer .= $sub_array[$group_key]; + } + $puffer = serialize ($puffer); + if (!in_array ($puffer, $existing_sub_keys)){ + $existing_sub_keys[$key] = $puffer; + $output[$key] = $sub_array; + } + else{ + $puffer = array_search ($puffer, $existing_sub_keys); + #sum keys + foreach ($sum_keys as $sum_key){ + if (is_string ($sum_key)) $output[$puffer][$sum_key] += $sub_array[$sum_key]; + } + #count grouped keys + if (!array_key_exists ($count_key, $output[$puffer])) $output[$puffer][$count_key] = 1; + if (is_string ($count_key)) $output[$puffer][$count_key]++; + } + } + return $output; + } + +} + +/********* SERVICE FUNCTIONS *********/ +function tags_content_display( &$pObject ) { + global $gBitSystem, $gBitSmarty, $gBitUser; + + if( method_exists( $pObject, 'getContentType' ) && $gBitSystem->isFeatureActive( 'tags_tag_'.$pObject->getContentType()) ){ + if ( $gBitSystem->isPackageActive( 'tags' ) ) { + if( $gBitUser->hasPermission( 'p_tags_view' ) ) { + $tag = new LibertyTag( $pObject->mContentId ); + if( $tag->load() ) { + $gBitSmarty->assign( 'tagData', !empty( $tag->mInfo['tags'] ) ? $tag->mInfo['tags'] : null ); + } + } + } + } +} + +/** + * filter the search with pigeonholes + * @param $pParamHash['tags']['filter'] - a tag or an array of tags + **/ +function tags_content_list_sql( &$pObject, &$pParamHash = null ) { + global $gBitSystem; + $ret = []; + + if (isset($pParamHash['tags']) && !empty($pParamHash['tags'])){ + /* slated for removal - makes no sense since content likely has multiple tags */ + // $ret['select_sql'] = ", tgc.`tag_id`, tgc.`tagger_id`, tgc.`tagged_on`"; + $ret['join_sql'] = " INNER JOIN `".BIT_DB_PREFIX."tags_content_map` tgc ON ( lc.`content_id`=tgc.`content_id` ) + INNER JOIN `".BIT_DB_PREFIX."tags` tg ON ( tg.`tag_id`=tgc.`tag_id` )"; + + $tagMixed = $pParamHash['tags']; //need to break up this string + if( !empty( $tagMixed )){ + if (!is_array( $tagMixed ) && !is_numeric( $tagMixed ) ){ + $tagIds = explode( ",", $tagMixed ); + }else if ( is_array( $tagMixed ) ) { + $tagIds = $tagMixed; + }else if ( is_numeric( $tagMixed ) ) { + $tagIds = array( $tagMixed ); + } + } + + $tags = []; + // strip off whitespace + foreach( $tagIds as $value ){ + // ignore empty ones created by trailing ,'s + $value = trim( $value ); + if( !empty($value) ) { + $tags[] = $value; + } + } + + $ret['where_sql'] = ' AND tg.`tag` IN ('.implode( ',', array_fill(0, count( $tags ), '?' ) ).')'; + + $ret['bind_vars'] = $tags; + + // return the values sent for pagination / url purposes + $pParamHash['listInfo']['tags'] = $pParamHash['tags']; + $pParamHash['listInfo']['ihash']['tags'] = $pParamHash['tags']; + } + + return $ret; +} + +function tags_content_edit( $pObject=null ) { + global $gBitSystem, $gBitSmarty, $gBitUser; + + if( method_exists( $pObject, 'getContentType' ) && $gBitSystem->isFeatureActive( 'tags_tag_'.$pObject->getContentType()) ){ + if ( $gBitSystem->isPackageActive( 'tags' )) { + $tag = new LibertyTag( $pObject->mContentId ); + if( $tag->load() && ($pObject->hasUserPermission( 'p_tags_create' ) || $gBitUser->hasPermission( 'p_tags_moderate' )) ) { + $tags = []; + foreach ($tag->mInfo['tags'] as $t) { + if ($t['tagger_id'] == $gBitUser->mUserId || $gBitUser->hasPermission('p_tags_admin') ) { + $tags[] = $t['tag']; + } + } + + $pObject->setField( 'tags', implode(", ", $tags) ); + + $gBitSmarty->assign( 'loadTags', true ); + $gBitSmarty->assign( 'tagList', $pObject->getField( 'tags' ) ); + $gBitSmarty->assign( 'tagData', $tag->getField( 'tags' ) ); + } + } + } +} + +/** + * @param object source content + * @param array includes a string or array of 'tags' and contentid for association. + **/ +function tags_content_store( &$pObject, &$pParamHash ) { + global $gBitUser, $gBitSystem; + if( $gBitUser->hasPermission( 'p_tags_create' ) ) { + $errors = null; + // If a content access system is active, let's call it + if( $gBitSystem->isPackageActive( 'tags' ) && isset( $pParamHash['tags'] ) ) { + $tag = new LibertyTag( $pObject->mContentId ); + if( $gBitUser->hasPermission('p_tags_create') ) { + $tag->expungeMyContentFromTagMap( $pObject ); + } + if ( !$tag->storeTags( $pParamHash ) ) { + $errors=$tag->mErrors; + } + } + return $errors; + } +} + +function tags_content_preview( &$pObject) { + global $gBitUser, $gBitSystem, $gBitSmarty; + tags_content_edit( $pObject ); + if( $gBitUser->hasPermission( 'p_tags_create' ) ) { + if ( $gBitSystem->isPackageActive( 'tags' ) ) { + if (isset($_REQUEST['tags'])) { + //$pObject->mInfo['tags'] = $_REQUEST['tags']; + $gBitSmarty->assign('tagList', $_REQUEST['tags']); + } + } + } +} + +function tags_content_expunge( &$pObject ) { + $tag = new LibertyTag( $pObject->mContentId ); + $tag->expungeContentFromTagMap(); +} + +// make sure all tags from a deleted user are nuked +function tags_user_expunge( &$pObject ) { + if( is_a( $pObject, 'BitUser' ) && !empty( $pObject->mUserId ) ) { + $pObject->mDb->StartTrans(); + $pObject->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."tags_content_map` WHERE tagger_id=?", array( $pObject->mUserId ) ); + $pObject->mDb->CompleteTrans(); + } +} diff --git a/index.php b/index.php old mode 100644 new mode 100755 index 6171572..ac4253a --- a/index.php +++ b/index.php @@ -1,6 +1,7 @@ verifyPackage( 'tags' ); @@ -8,16 +9,16 @@ $gBitSystem->verifyPermission('p_tags_view'); $tag = new LibertyTag(); -$_REQUEST['max_records'] = !empty( $_REQUEST['max_records'] ) ? $_REQUEST['max_records'] : NULL; +$_REQUEST['max_records'] = !empty( $_REQUEST['max_records'] ) ? $_REQUEST['max_records'] : null; $listHash = $_REQUEST; $tagHash = $_REQUEST; -$gBitSmarty->assign( 'cloud', TRUE ); +$gBitSmarty->assign( 'cloud', true ); if( isset($_REQUEST['tags']) ){ - $pageTitle = tra( 'Tagged Content' ); + $pageTitle = KernelTools::tra( 'Tagged Content' ); if( $listData = $tag->assignContentList( $listHash ) ) { - $pageTitle .= ' '.tra( 'with' ).' '.$_REQUEST['tags']; + $pageTitle .= ' '.KernelTools::tra( 'with' ).' '.$_REQUEST['tags']; $gBitSystem->setCanonicalLink( $tag->getDisplayUrlWithTag( $_REQUEST['tags'] ) ); } else { $gBitSystem->setHttpStatus( HttpStatusCodes::HTTP_GONE ); @@ -29,6 +30,6 @@ if( isset($_REQUEST['tags']) ){ }else{ $listData = $tag->getList( $listHash ); $gBitSmarty->assign( 'tagData', $listData["data"] ); - $gBitSystem->display( 'bitpackage:tags/list_tags.tpl', tra( 'Tags' ) , array( 'display_mode' => 'display' )); + $gBitSystem->display( 'bitpackage:tags/list_tags.tpl', KernelTools::tra( 'Tags' ) , array( 'display_mode' => 'display' )); } diff --git a/list.php b/list.php old mode 100644 new mode 100755 index 68c948f..e20b28a --- a/list.php +++ b/list.php @@ -12,37 +12,39 @@ /** * required setup */ -require_once( "../kernel/includes/setup_inc.php" ); -require_once( TAGS_PKG_CLASS_PATH.'LibertyTag.php' ); +require_once "../kernel/includes/setup_inc.php"; +use Bitweaver\Tags\LibertyTag; +use Bitweaver\KernelTools; +use Bitweaver\HttpStatusCodes; $gBitSystem->verifyPackage( 'tags' ); if( !empty( $_REQUEST['action'] ) ) { if( $_REQUEST['action'] == 'remove' && !empty( $_REQUEST['tag_id'] ) ) { if ( !$gBitUser->hasPermission('p_tags_moderate') ){ - $gBitSystem->fatalError( tra('You do not have permission to remove tags.') ); + $gBitSystem->fatalError( KernelTools::tra('You do not have permission to remove tags.') ); } $tmpTag = new LibertyTag(); $tmpTag->loadTag($_REQUEST); if( isset( $_REQUEST["confirm"] ) ) { - if( $tmpTag->expunge( $tmpTag->mInfo['tag_id'] ) ) { - bit_redirect( TAGS_PKG_URL.'list.php?status_id='.( !empty( $_REQUEST['status_id'] ) ? $_REQUEST['status_id'] : '' ) ); + if( $tmpTag->expungeTag( $tmpTag->mInfo['tag_id'] ) ) { + KernelTools::bit_redirect( TAGS_PKG_URL.'list.php?status_id='.( !empty( $_REQUEST['status_id'] ) ? $_REQUEST['status_id'] : '' ) ); } else { $feedback['error'] = $tmpTag->mErrors; } } $gBitSystem->setBrowserTitle( 'Confirm removal of '.$tmpTag->mInfo['tag'] ); - $formHash['remove'] = TRUE; + $formHash['remove'] = true; $formHash['action'] = 'remove'; - $formHash['status_id'] = ( !empty( $_REQUEST['status_id'] ) ? $_REQUEST['status_id'] : '' ); + $formHash['status_id'] = !empty( $_REQUEST['status_id'] ) ? $_REQUEST['status_id'] : ''; $formHash['tag_id'] = $_REQUEST['tag_id']; $msgHash = array( - 'label' => tra('Remove Tag'), + 'label' => KernelTools::tra('Remove Tag'), 'confirm_item' => $tmpTag->mInfo['tag'], - 'warning' => ('This will remove the above tag.'), - 'error' => tra('This cannot be undone!'), + 'warning' => 'This will remove the above tag.', + 'error' => KernelTools::tra('This cannot be undone!'), ); $gBitSystem->confirmDialog( $formHash, $msgHash ); } @@ -54,9 +56,9 @@ $listHash = $_REQUEST; $tagHash = $_REQUEST; if( isset($_REQUEST['tags']) ){ - $pageTitle = tra( 'Tagged Content' ); + $pageTitle = KernelTools::tra( 'Tagged Content' ); if( $listData = $tag->assignContentList( $listHash ) ) { - $pageTitle .= ' '.tra( 'with' ).' '.$_REQUEST['tags']; + $pageTitle .= ' '.KernelTools::tra( 'with' ).' '.$_REQUEST['tags']; $gBitSystem->setCanonicalLink( $tag->getDisplayUrlWithTag( $_REQUEST['tags'] ) ); } else { $gBitSystem->setHttpStatus( HttpStatusCodes::HTTP_GONE ); @@ -68,6 +70,5 @@ if( isset($_REQUEST['tags']) ){ }else{ $listData = $tag->getList( $listHash ); $gBitSmarty->assign( 'tagData', $listData["data"] ); - $gBitSystem->display( 'bitpackage:tags/list_tags.tpl', tra( 'Tags' ) , array( 'display_mode' => 'list' )); + $gBitSystem->display( 'bitpackage:tags/list_tags.tpl', KernelTools::tra( 'Tags' ) , array( 'display_mode' => 'list' )); } -?> diff --git a/modules/mod_tags_cloud.php b/modules/mod_tags_cloud.php old mode 100644 new mode 100755 index 1513fc1..6538d19 --- a/modules/mod_tags_cloud.php +++ b/modules/mod_tags_cloud.php @@ -8,23 +8,22 @@ /** * required setup */ -require_once( TAGS_PKG_CLASS_PATH.'LibertyTag.php' ); +use Bitweaver\Tags\LibertyTag; // moduleParams contains lots of goodies: extract for easier handling extract( $moduleParams ); -$listHash = array( - 'sort' => ( !empty( $module_params['sort'] ) ? $module_params['sort'] : NULL ), +$listHash = [ + 'sort' => ( !empty( $module_params['sort'] ) ? $module_params['sort'] : null ), 'sort_mode' => ( !empty( $module_params['sort_mode'] ) ? $module_params['sort_mode'] : 'tag_asc' ), // do not enable until getList can return max of most popular requires more sophisticated query // 'max_records' => $module_rows, - '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 ), -); + 'user' => ( !empty( $module_params['user'] ) ? $module_params['user'] : null ), + 'group_id' => ( \Bitweaver\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"] ); -?> +$gBitSmarty->assign( 'modTagData', $listData["data"] ); -- cgit v1.3