diff options
| author | Lester Caine <lester@lsces.co.uk> | 2026-05-14 09:52:56 +0100 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2026-05-14 09:52:56 +0100 |
| commit | 59f4b840506330fd044b0c8e583a428209ab533f (patch) | |
| tree | ead62e12adc402b29bee3c3733924b4c33d2299b /includes | |
| parent | 0aa24a7f24b573fd3f19cb888dfefcdc31ae6b82 (diff) | |
| download | tags-59f4b840506330fd044b0c8e583a428209ab533f.tar.gz tags-59f4b840506330fd044b0c8e583a428209ab533f.tar.bz2 tags-59f4b840506330fd044b0c8e583a428209ab533f.zip | |
php-cs-fixer tidies to php8.5 standards
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'includes')
| -rwxr-xr-x | includes/bit_setup_inc.php | 18 | ||||
| -rwxr-xr-x | includes/classes/LibertyTag.php | 73 |
2 files changed, 39 insertions, 52 deletions
diff --git a/includes/bit_setup_inc.php b/includes/bit_setup_inc.php index c4b1dfb..e80e742 100755 --- a/includes/bit_setup_inc.php +++ b/includes/bit_setup_inc.php @@ -14,9 +14,9 @@ $pRegisterHash = [ 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_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/'); +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' )) { @@ -30,9 +30,9 @@ if( $gBitSystem->isPackageActive( 'tags' ) && $gBitUser->hasPermission( 'p_tags_ ]; $gBitSystem->registerAppMenu( $menuHash ); - $gLibertySystem->registerService( - LIBERTY_SERVICE_TAGS, - TAGS_PKG_NAME, + $gLibertySystem->registerService( + LIBERTY_SERVICE_TAGS, + TAGS_PKG_NAME, [ 'content_display_function' => 'tags_content_display', 'content_edit_function' => 'tags_content_edit', @@ -45,10 +45,10 @@ if( $gBitSystem->isPackageActive( 'tags' ) && $gBitUser->hasPermission( 'p_tags_ 'content_nav_tpl' => 'bitpackage:tags/view_tags_nav.tpl', 'content_body_tpl' => 'bitpackage:tags/view_tags_body.tpl', 'users_expunge_function' => 'tags_user_expunge', - 'content_search_tpl' => 'bitpackage:tags/search_inc.tpl' + 'content_search_tpl' => 'bitpackage:tags/search_inc.tpl', + ], + [ + 'description' => KernelTools::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 index df75c8c..12acd9f 100755 --- a/includes/classes/LibertyTag.php +++ b/includes/classes/LibertyTag.php @@ -12,6 +12,7 @@ * required setup */ namespace Bitweaver\Tags; + use Bitweaver\BitBase; use Bitweaver\Liberty\LibertyContent; @@ -26,7 +27,6 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { $this->mContentId = $pContentId; } - /* Delete when package complete! -wjames5 * methods needed * @@ -43,7 +43,6 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { * */ - /** * 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 @@ -57,13 +56,13 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { WHERE tgc.`content_id`=?"; //$this->mInfo = $this->mDb->query( $query, array( $this->mContentId ) ); - $result = $this->mDb->query( $query, array( $this->mContentId ) ); + $result = $this->mDb->query( $query, [ $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; @@ -88,15 +87,13 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { 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 @@ -115,7 +112,7 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { // $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(); + $pParamHash['tag_map_store']['tagged_on'] = $pParamHash['tagged_on'] ?? $gBitSystem->getUTCTime(); if( @$this->verifyId( $pParamHash['content_id']) ){ $pParamHash['tag_map_store']['content_id'] = $pParamHash['content_id']; @@ -131,7 +128,6 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { return count( $this->mErrors )== 0; } - /* check tag exists */ function verifyTag ( &$pParamHash ){ @@ -163,8 +159,6 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { 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 @@ -193,8 +187,6 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { return count( $this->mErrors )== 0; } - - function storeOneTag( &$pParamHash ) { if( $this->verify( $pParamHash ) ) { $this->mDb->StartTrans(); @@ -203,7 +195,7 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { 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'] ) ); + $this->mDb->associateUpdate( $tagtable, ["tag" => $pParamHash['tag_store']['tag']], [ "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'] ); @@ -250,14 +242,14 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { $timeStamp = $gBitSystem->getUTCTime(); //need to break up this string - $tagMixed = isset($pParamHash['tags']) ? $pParamHash['tags'] : null; + $tagMixed = $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 ); + $tagIds = [ $tagMixed ]; } foreach( $tagIds as $value ) { @@ -266,12 +258,12 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { if( !empty($value) ) { $value = LibertyTag::sanitizeTag($value); if ( !empty($value) ) { - array_push( $pParamHash['tag_map_store'], array( + array_push( $pParamHash['tag_map_store'], [ 'tag' => $value, 'tagged_on' => $timeStamp, 'content_id' => $this->mContentId, 'user_id' => $gBitUser->mUserId, - )); + ]); } else { $this->mErrors[$value] = "Invalid tag."; @@ -283,7 +275,6 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { 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 @@ -302,7 +293,6 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { return count( $this->mErrors ) == 0; } - /** * check if the mContentId is set and valid */ @@ -322,9 +312,9 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { $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 } + //some rollback feature would be nice here + } $this->mDb->CompleteTrans(); } @@ -337,7 +327,7 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { 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 ) ); + $result = $this->mDb->query( $query, [ $this->mContentId ] ); $this->mDb->CompleteTrans(); } return $ret; @@ -375,14 +365,14 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { $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 ) ) ) { + if( !$this->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."tags_content_map` WHERE `tag_id`=?", [ $tagId ] ) ) { $this->expungeTag( $tagId ); } } $this->mDb->CompleteTrans(); } } - + function getDisplayUriWithTag( $tag ) { return BIT_BASE_URI.$this->getDisplayUrlWithTag( $tag ); } @@ -414,7 +404,7 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { $sort_mode_prefix = 'tg'; //Backward compatability for most popular sort method - + if( empty( $pParamHash['sort_mode'] ) ) { $pParamHash['sort_mode'] = 'tag_asc'; } else { @@ -497,13 +487,12 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { } } - //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 + $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){ @@ -515,14 +504,13 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { } $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 **/ @@ -531,7 +519,7 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { SELECT COUNT( * ) FROM `".BIT_DB_PREFIX."tags_content_map` tgc WHERE tgc.`tag_id` = ?"; - $cant = $this->mDb->getOne($queryCount, array($tag_id) ); + $cant = $this->mDb->getOne($queryCount, [$tag_id] ); return $cant; } @@ -559,7 +547,7 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { $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 ); + $gBitSmarty->assign( 'content_type_guids', $pParamHash['content_type_guid'] ?? null ); if ( isset($pParamHash['matchtags']) && $pParamHash['matchtags'] == 'all'){ //need some sort of matching function @@ -572,7 +560,6 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { 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 @@ -583,8 +570,8 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { * @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); + if (!is_array ($group_keys)) $group_keys = [$group_keys]; + if (!is_array ($sum_keys)) $sum_keys = [$sum_keys]; $existing_sub_keys = []; $output = []; @@ -619,7 +606,7 @@ class LibertyTag extends \Bitweaver\Liberty\LibertyBase { /********* 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' ) ) { @@ -645,7 +632,7 @@ function tags_content_list_sql( &$pObject, &$pParamHash = null ) { // $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 ) ){ @@ -653,7 +640,7 @@ function tags_content_list_sql( &$pObject, &$pParamHash = null ) { }else if ( is_array( $tagMixed ) ) { $tagIds = $tagMixed; }else if ( is_numeric( $tagMixed ) ) { - $tagIds = array( $tagMixed ); + $tagIds = [ $tagMixed ]; } } @@ -668,7 +655,7 @@ function tags_content_list_sql( &$pObject, &$pParamHash = null ) { } $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 @@ -681,7 +668,7 @@ function tags_content_list_sql( &$pObject, &$pParamHash = null ) { 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 ); @@ -747,7 +734,7 @@ function tags_content_expunge( &$pObject ) { 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->query( "DELETE FROM `".BIT_DB_PREFIX."tags_content_map` WHERE tagger_id=?", [ $pObject->mUserId ] ); $pObject->mDb->CompleteTrans(); } } |
