From 49fd7246de6340f0d9b5358d0fbdd3d14f9c2664 Mon Sep 17 00:00:00 2001 From: lsces Date: Wed, 27 Aug 2025 17:15:51 +0100 Subject: Code updated to PHP8.4 and namespace --- admin/admin_pigeonholes_inc.php | 81 ++++--- admin/schema_inc.php | 44 ++-- admin/upgrade_inc.php | 57 ----- assign_content.php | 36 ++-- edit_pigeonholes.php | 38 ++-- edit_structure.php | 12 +- includes/bit_setup_inc.php | 26 ++- includes/classes/Pigeonholes.php | 408 +++++++++++++++++------------------- includes/lookup_pigeonholes_inc.php | 5 +- index.php | 2 +- list.php | 4 +- modules/mod_category_menu.php | 7 +- modules/mod_category_suckerfish.php | 24 +-- modules/mod_whats_related.php | 7 +- view.php | 12 +- 15 files changed, 339 insertions(+), 424 deletions(-) mode change 100644 => 100755 admin/admin_pigeonholes_inc.php mode change 100644 => 100755 admin/schema_inc.php delete mode 100644 admin/upgrade_inc.php mode change 100644 => 100755 assign_content.php mode change 100644 => 100755 edit_pigeonholes.php mode change 100644 => 100755 edit_structure.php mode change 100644 => 100755 includes/bit_setup_inc.php mode change 100644 => 100755 includes/classes/Pigeonholes.php mode change 100644 => 100755 index.php mode change 100644 => 100755 list.php mode change 100644 => 100755 modules/mod_category_menu.php mode change 100644 => 100755 modules/mod_category_suckerfish.php mode change 100644 => 100755 modules/mod_whats_related.php mode change 100644 => 100755 view.php diff --git a/admin/admin_pigeonholes_inc.php b/admin/admin_pigeonholes_inc.php old mode 100644 new mode 100755 index 20dbe48..48087a0 --- a/admin/admin_pigeonholes_inc.php +++ b/admin/admin_pigeonholes_inc.php @@ -1,74 +1,74 @@ array( +$pigeonholeDisplaySettings = [ + 'pigeonholes_display_path' => [ 'label' => 'Display Path', 'note' => 'Display category paths above the page leading to the object.', - ), - 'pigeonholes_display_description' => array( + ], + 'pigeonholes_display_description' => [ 'label' => 'Display Description', 'note' => 'When showing the category members, you can display the category description as well.', - ), - 'pigeonholes_list_filter' => array( + ], + 'pigeonholes_list_filter' => [ 'label' => 'Listing Filter', 'note' => 'When viewing a listing of content items, users can limit the listing based on category.', - ), - 'pigeonholes_display_members' => array( + ], + 'pigeonholes_display_members' => [ 'label' => 'Display Members', 'note' => 'Show the other members of the same categories at the bottom of the page.', - ), -); + ], +]; $gBitSmarty->assign( 'pigeonholeDisplaySettings', $pigeonholeDisplaySettings ); -$pigeonholeListSettings = array( - 'pigeonholes_display_subtree' => array( +$pigeonholeListSettings = [ + 'pigeonholes_display_subtree' => [ 'label' => 'Display Subtree', 'note' => 'When viewing the category list, you can display the subcategories as well.', - ), - 'pigeonholes_display_content_type' => array( + ], + 'pigeonholes_display_content_type' => [ 'label' => 'Display Content Type', 'note' => 'When viewing the category members, you can display the content type alongside the item.', - ), -); + ], +]; $gBitSmarty->assign( 'pigeonholeListSettings', $pigeonholeListSettings ); -$pigeonholeEditSettings = array( - 'pigeonholes_themes' => array( +$pigeonholeEditSettings = [ + 'pigeonholes_themes' => [ 'label' => 'Theme selection', 'note' => 'Allow the selection of a different theme to use for a category.', - ), - 'pigeonholes_permissions' => array( + ], + 'pigeonholes_permissions' => [ 'label' => 'Permission gating', 'note' => 'Limit category access to users with a given permission. Permission settings are inhertied by child categories.', - ), - 'pigeonholes_groups' => array( + ], + 'pigeonholes_groups' => [ 'label' => 'Group gating', 'note' => 'Limit category access to specific groups. Group settings are inhertied by child categories.', - ), - 'pigeonholes_reverse_assign_table' => array( + ], + 'pigeonholes_reverse_assign_table' => [ 'label' => 'Assign Categories in Rows', 'note' => 'The assign categories page will have categories in rows instead of columns and content in columns instead of rows. This is better if you have lots of categories that do not fit on a single page easily.', - ), - 'pigeonholes_allow_forbid_insertion' => array( + ], + 'pigeonholes_allow_forbid_insertion' => [ 'label' => 'Allow Forbid Insertion', 'note' => 'Allows pigeonholes to be set to forbid insertion of new members. This is good for heirarchical categories where only leaf categories should have members.' - ), -); + ], +]; $gBitSmarty->assign( 'pigeonholeEditSettings', $pigeonholeEditSettings ); -$pigeonholeContentEditSettings = array( - 'pigeonholes_use_jstab' => array( +$pigeonholeContentEditSettings = [ + 'pigeonholes_use_jstab' => [ 'label' => 'Use separate Tab', 'note' => 'When editing content use a separate tab to categorise.', - ), -); + ], +]; $gBitSmarty->assign( 'pigeonholeContentEditSettings', $pigeonholeContentEditSettings ); -$listStyles = array( +$listStyles = [ 'dynamic' => tra( 'Dynamic list' ), 'table' => tra( 'Table based list' ), -); +]; $gBitSmarty->assign( 'listStyles', $listStyles ); // sensible table column numbers @@ -76,7 +76,7 @@ $tableColumns = range( 0, 6 ); unset( $tableColumns[0] ); $gBitSmarty->assign( 'tableColumns', $tableColumns ); -$memberLimit = array( +$memberLimit = [ '0' => tra( 'Only display category title' ), '10' => 10, '20' => 20, @@ -84,14 +84,14 @@ $memberLimit = array( '50' => 50, '100' => 100, '9999' => tra( 'Unlimited' ), -); +]; $gBitSmarty->assign( 'memberLimit', $memberLimit ); // various image sizes -$gBitSmarty->assign( 'imageSizes', get_image_size_options() ); +$gBitSmarty->assign( 'imageSizes', Bitweaver\Liberty\get_image_size_options() ); // Which kinds of content? -$exclude = array( 'tikisticky', 'pigeonholes' ); +$exclude = [ 'tikisticky', 'pigeonholes' ]; foreach( $gLibertySystem->mContentTypes as $cType ) { if( !in_array( $cType['content_type_guid'], $exclude ) ) { $formPigeonholeable['guids']['pigeonhole_no_'.$cType['content_type_guid']] = $gLibertySystem->getContentTypeName( $cType['content_type_guid'] ); @@ -111,7 +111,7 @@ if( !empty( $_REQUEST['pigeonhole_settings'] ) ) { simple_set_value( 'pigeonholes_list_style', PIGEONHOLES_PKG_NAME ); foreach( array_keys( $formPigeonholeable['guids'] ) as $holeable ) { - $gBitSystem->storeConfig( $holeable, ( ( !empty( $_REQUEST['pigeonholeable_content'] ) && in_array( $holeable, $_REQUEST['pigeonholeable_content'] ) ) ? NULL : 'y' ), PIGEONHOLES_PKG_NAME ); + $gBitSystem->storeConfig( $holeable, !empty( $_REQUEST['pigeonholeable_content'] ) && in_array( $holeable, $_REQUEST['pigeonholeable_content'] ) ? null : 'y', PIGEONHOLES_PKG_NAME ); } } @@ -123,6 +123,3 @@ foreach( $gLibertySystem->mContentTypes as $cType ) { } } $gBitSmarty->assign( 'formPigeonholeable', $formPigeonholeable ); - - -?> diff --git a/admin/schema_inc.php b/admin/schema_inc.php old mode 100644 new mode 100755 index df9b8db..48dae8c --- a/admin/schema_inc.php +++ b/admin/schema_inc.php @@ -1,6 +1,6 @@ " content_id I4 NOTNULL PRIMARY, structure_id I4 NOTNULL PRIMARY @@ -14,7 +14,7 @@ $tables = array( , CONSTRAINT `pigeonhole_members_parent_ref` FOREIGN KEY (`parent_id`) REFERENCES `".BIT_DB_PREFIX."liberty_content`( `content_id` ) , CONSTRAINT `pigeonhole_members_content_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."liberty_content`( `content_id` )' " -); +]; global $gBitInstaller; @@ -22,36 +22,36 @@ foreach( array_keys( $tables ) AS $tableName ) { $gBitInstaller->registerSchemaTable( PIGEONHOLES_PKG_NAME, $tableName, $tables[$tableName] ); } -$gBitInstaller->registerPackageInfo( PIGEONHOLES_PKG_NAME, array( +$gBitInstaller->registerPackageInfo( PIGEONHOLES_PKG_NAME, [ 'description' => "A Categorisation system that makes it easy to keep an overview of your data. Has a simple, yet powerful interface for categorising multiple pages at once.", 'license' => 'LGPL', -) ); +] ); // ### Sequences -$sequences = array ( - 'pigeonholes_id_seq' => array( 'start' => 1 ) -); +$sequences = [ + 'pigeonholes_id_seq' => [ 'start' => 1 ] +]; $gBitInstaller->registerSchemaSequences( PIGEONHOLES_PKG_NAME, $sequences ); // ### Default Preferences -$gBitInstaller->registerPreferences( PIGEONHOLES_PKG_NAME, array( - array( PIGEONHOLES_PKG_NAME, 'pigeonholes_display_members','y' ), - array( PIGEONHOLES_PKG_NAME, 'pigeonholes_limit_member_number','100' ), - array( PIGEONHOLES_PKG_NAME, 'pigeonholes_list_style','table' ), - array( PIGEONHOLES_PKG_NAME, 'pigeonholes_menu_text', 'Categories' ), -) ); +$gBitInstaller->registerPreferences( PIGEONHOLES_PKG_NAME, [ + [ PIGEONHOLES_PKG_NAME, 'pigeonholes_display_members','y' ], + [ PIGEONHOLES_PKG_NAME, 'pigeonholes_limit_member_number','100' ], + [ PIGEONHOLES_PKG_NAME, 'pigeonholes_list_style','table' ], + [ PIGEONHOLES_PKG_NAME, 'pigeonholes_menu_text', 'Categories' ], +] ); // ### Default UserPermissions -$gBitInstaller->registerUserPermissions( PIGEONHOLES_PKG_NAME, array( - array( 'p_pigeonholes_view', 'Can view pigeonholes', 'basic', PIGEONHOLES_PKG_NAME ), - array( 'p_pigeonholes_insert_member', 'Can insert content into an existing pigeonhole', 'registered', PIGEONHOLES_PKG_NAME ), - array( 'p_pigeonholes_update', 'Can update pigeonholes', 'editors', PIGEONHOLES_PKG_NAME ), - //array( 'p_pigeonholes_admin', 'Can administer all aspects of pigeonholes', 'editors', PIGEONHOLES_PKG_NAME ), -) ); +$gBitInstaller->registerUserPermissions( PIGEONHOLES_PKG_NAME, [ + [ 'p_pigeonholes_view', 'Can view pigeonholes', 'basic', PIGEONHOLES_PKG_NAME ], + [ 'p_pigeonholes_insert_member', 'Can insert content into an existing pigeonhole', 'registered', PIGEONHOLES_PKG_NAME ], + [ 'p_pigeonholes_update', 'Can update pigeonholes', 'editors', PIGEONHOLES_PKG_NAME ], + //[ 'p_pigeonholes_admin', 'Can administer all aspects of pigeonholes', 'editors', PIGEONHOLES_PKG_NAME ], +] ); // Requirements -$gBitInstaller->registerRequirements( PIGEONHOLES_PKG_NAME, array( - 'liberty' => array( 'min' => '2.1.4' ), -)); +$gBitInstaller->registerRequirements( PIGEONHOLES_PKG_NAME, [ + 'liberty' => [ 'min' => '5.0.0' ], +] ); diff --git a/admin/upgrade_inc.php b/admin/upgrade_inc.php deleted file mode 100644 index 8fd8eb3..0000000 --- a/admin/upgrade_inc.php +++ /dev/null @@ -1,57 +0,0 @@ - array( - 'BWR2' => array( -// transfer all the pigeonhole settings into liberty_content_prefs -array( 'PHP' => ' - global $gBitSystem; - $pigeonhole_settings = $gBitSystem->mDb->getAll( "SELECT `content_id`, `name`, `value` FROM `".BIT_DB_PREFIX."bit_pigeonhole_settings`" ); - if( !empty( $pigeonhole_settings ) ) { - foreach( $pigeonhole_settings as $store ) { - $query = "INSERT INTO `".BIT_DB_PREFIX."liberty_content_prefs` (`content_id`,`pref_name`,`pref_value`) VALUES(?, ?, ?)"; - $result = $this->mDb->query( $query, $store ); - } - } -'), - -// drop unused columns and tables -array( 'DATADICT' => array( - // positional data for categories is just odd - array( 'DROPCOLUMN' => array( - 'bit_pigeonhole_members' => array( '`pos`' ), - )), - // bw now has liberty_content_prefs for this - array( 'DROPTABLE' => array( - 'bit_pigeonhole_settings', - )), - // remove bit_ prefix - array( 'RENAMETABLE' => array( - 'bit_pigeonholes' => 'pigeonholes', - 'bit_pigeonhole_members' => 'pigeonhole_members', - )), - array( 'RENAMESEQUENCE' => array( - "bit_pigeonholes_id_seq" => "pigeonholes_id_seq", - )), -)), - -// add constraints for pgsql -array( 'QUERY' => - array( 'PGSQL' => array( - "ALTER TABLE `".BIT_DB_PREFIX."pigeonholes` ADD CONSTRAINT `pigeonholes_content_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."liberty_content`( `content_id` )", - "ALTER TABLE `".BIT_DB_PREFIX."pigeonholes` ADD CONSTRAINT `pigeonholes_structure_ref` FOREIGN KEY (`structure_id`) REFERENCES `".BIT_DB_PREFIX."liberty_structures`( `structure_id` )", - "ALTER TABLE `".BIT_DB_PREFIX."pigeonhole_members` ADD CONSTRAINT `pigeonhole_members_parent_ref` FOREIGN KEY (`parent_id`) REFERENCES `".BIT_DB_PREFIX."liberty_content`( `content_id` )", - "ALTER TABLE `".BIT_DB_PREFIX."pigeonhole_members` ADD CONSTRAINT `pigeonhole_members_content_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."liberty_content`( `content_id` )", - )), -), - ) - ) -); - -if( isset( $upgrades[$gUpgradeFrom][$gUpgradeTo] ) ) { - $gBitSystem->registerUpgrade( PIGEONHOLES_PKG_NAME, $upgrades[$gUpgradeFrom][$gUpgradeTo] ); -} - -?> diff --git a/assign_content.php b/assign_content.php old mode 100644 new mode 100755 index 24bed3f..b49ef34 --- a/assign_content.php +++ b/assign_content.php @@ -16,7 +16,7 @@ /** * required setup */ -require_once( '../kernel/includes/setup_inc.php' ); +require_once '../kernel/includes/setup_inc.php'; $gBitSystem->verifyPackage( 'pigeonholes' ); $gBitSystem->verifyPermission( 'p_pigeonholes_insert_member' ); @@ -24,7 +24,7 @@ $gBitSystem->verifyPermission( 'p_pigeonholes_insert_member' ); include_once( PIGEONHOLES_PKG_INCLUDE_PATH.'lookup_pigeonholes_inc.php' ); $feedback = ''; -$gBitSmarty->assignByRef( 'feedback', $feedback ); +$gBitSmarty->assign( 'feedback', $feedback ); $contentTypes = array( '' => tra( 'All Content' ) ); foreach( $gLibertySystem->mContentTypes as $cType ) { @@ -33,13 +33,13 @@ foreach( $gLibertySystem->mContentTypes as $cType ) { } } $gBitSmarty->assign( 'contentTypes', $contentTypes ); -$gBitSmarty->assign( 'contentSelect', $contentSelect = !isset( $_REQUEST['content_type'] ) ? NULL : $_REQUEST['content_type'] ); +$gBitSmarty->assign( 'contentSelect', $contentSelect = !isset( $_REQUEST['content_type'] ) ? null : $_REQUEST['content_type'] ); $listHash = array( - 'find' => ( empty( $_REQUEST['find'] ) ? NULL : $_REQUEST['find'] ), - 'sort_mode' => ( empty( $_REQUEST['sort_mode'] ) ? NULL : $_REQUEST['sort_mode'] ), - 'max_records' => ( @BitBase::verifyId( $_REQUEST['max_records'] ) ) ? $_REQUEST['max_records'] : 10, - 'include_members' => ( ( !empty( $_REQUEST['include'] ) && $_REQUEST['include'] == 'members' ) ? TRUE : FALSE ), + 'find' => ( empty( $_REQUEST['find'] ) ? null : $_REQUEST['find'] ), + 'sort_mode' => ( empty( $_REQUEST['sort_mode'] ) ? null : $_REQUEST['sort_mode'] ), + 'max_records' => ( BitBase::verifyId( $_REQUEST['max_records'] ) ) ? $_REQUEST['max_records'] : 10, + 'include_members' => ( ( !empty( $_REQUEST['include'] ) && $_REQUEST['include'] == 'members' ) ? true : false ), 'content_type' => $contentSelect, ); @@ -47,15 +47,15 @@ $listHash = array( if( !empty( $_REQUEST['insert_content'] ) || !empty( $_REQUEST['insert_content_and_next'] )) { $listHash['list_page'] = ( empty( $_REQUEST['list_page'] ) ? 2 : $_REQUEST['list_page'] + 1 ); } else { - $listHash['list_page'] = ( empty( $_REQUEST['list_page'] ) ? NULL : $_REQUEST['list_page'] ); + $listHash['list_page'] = ( empty( $_REQUEST['list_page'] ) ? null : $_REQUEST['list_page'] ); } $assignableContent = $gContent->getAssignableContent( $listHash ); if(( !empty( $_REQUEST['insert_content'] ) || !empty( $_REQUEST['insert_content_and_next'] ))) { // here we need to limit all killing to the selected structure - $deletableParentIds = array(); - if( empty( $gStructure ) && @BitBase::verifyId( $_REQUEST['root_structure_id'] ) ) { + $deletableParentIds = []; + if( empty( $gStructure ) && BitBase::verifyId( $_REQUEST['root_structure_id'] ) ) { $gStructure = new LibertyStructure(); $struct = $gStructure->getStructure( $_REQUEST ); foreach( $struct as $node ) { @@ -101,30 +101,30 @@ if(( !empty( $_REQUEST['insert_content'] ) || !empty( $_REQUEST['insert_content_ $assignableContent = $gContent->getAssignableContent( $listHash ); } -$gBitSmarty->assignByRef( 'listInfo', $listHash['listInfo'] ); +$gBitSmarty->assign( 'listInfo', $listHash['listInfo'] ); $listHash = array( - 'load_only_root' => TRUE, + 'load_only_root' => true, 'max_records' => -1, - 'parse_data' => TRUE, + 'parse_data' => true, ); $pigeonRootData = $gContent->getList( $listHash ); $pigeonRoots[0] = 'All'; foreach( $pigeonRootData as $root ) { $pigeonRoots[$root['root_structure_id']] = $root['title']; } -$gBitSmarty->assign( 'pigeonRoots', !empty( $pigeonRoots ) ? $pigeonRoots : NULL ); +$gBitSmarty->assign( 'pigeonRoots', !empty( $pigeonRoots ) ? $pigeonRoots : null ); $listHash = array( - 'root_structure_id' => ( !empty( $_REQUEST['root_structure_id'] ) ? $_REQUEST['root_structure_id'] : NULL ), - 'force_extras' => TRUE, + 'root_structure_id' => ( !empty( $_REQUEST['root_structure_id'] ) ? $_REQUEST['root_structure_id'] : null ), + 'force_extras' => true, 'max_records' => -1, 'sort_mode' => 'ls.`parent_id_asc`', - 'parse_data' => TRUE, + 'parse_data' => true, ); if( $gBitSystem->isFeatureActive( 'pigeonholes_allow_forbid_insertion' )) { - $listHash['insertable'] = TRUE; + $listHash['insertable'] = true; } $pigeonList = $gContent->getList( $listHash ); diff --git a/edit_pigeonholes.php b/edit_pigeonholes.php old mode 100644 new mode 100755 index 1a4ca21..2439ef2 --- a/edit_pigeonholes.php +++ b/edit_pigeonholes.php @@ -16,19 +16,20 @@ /** * required setup */ -require_once( '../kernel/includes/setup_inc.php' ); +require_once '../kernel/includes/setup_inc.php'; $gBitSystem->verifyPackage( 'pigeonholes' ); $gBitSystem->verifyPermission( 'p_pigeonholes_create' ); -include_once( LIBERTY_PKG_CLASS_PATH.'LibertyStructure.php' ); -include_once( PIGEONHOLES_PKG_INCLUDE_PATH.'lookup_pigeonholes_inc.php' ); +use Bitweaver\Pigeonholes\Pigeonholes; +use Bitweaver\Liberty\LibertyStructure; +include_once PIGEONHOLES_PKG_INCLUDE_PATH.'lookup_pigeonholes_inc.php'; // include edit structure file only when structure_id is known if( !empty( $_REQUEST["structure_id"] ) && ( empty( $_REQUEST['action'] ) || $_REQUEST['action'] != 'remove' ) ) { $verifyStructurePermission = 'p_pigeonholes_create'; - $noAjaxContent = TRUE; - include_once( LIBERTY_PKG_INCLUDE_PATH.'structure_edit_inc.php' ); + $noAjaxContent = true; + include_once LIBERTY_PKG_INCLUDE_PATH.'structure_edit_inc.php'; // get all the nodes in this structure foreach( $rootTree as $node ) { @@ -45,9 +46,9 @@ if( !empty( $_REQUEST['pigeonhole_store'] ) ) { } // we need to get the root structure id - $_REQUEST['pigeonhole']['root_structure_id'] = !empty( $rootStructure->mStructureId ) ? $rootStructure->mStructureId : NULL; + $_REQUEST['pigeonhole']['root_structure_id'] = !empty( $rootStructure->mStructureId ) ? $rootStructure->mStructureId : null; // store the pigeonhole - $pigeonStore = new Pigeonholes( NULL, !empty( $_REQUEST['pigeonhole_content_id'] ) ? $_REQUEST['pigeonhole_content_id'] : NULL ); + $pigeonStore = new Pigeonholes( null, !empty( $_REQUEST['pigeonhole_content_id'] ) ? $_REQUEST['pigeonhole_content_id'] : null ); $pigeonStore->load(); if( $pigeonStore->store( $_REQUEST['pigeonhole'] )) { header( "Location: ".$_SERVER['SCRIPT_NAME'].'?structure_id='.$pigeonStore->mStructureId.( !empty( $_REQUEST['action'] ) ? '&action='.$_REQUEST['action'] : '' )."&success=".urlencode( tra( "The category was successfully stored" ) ) ); @@ -64,19 +65,19 @@ if( !empty( $_REQUEST['action'] ) || isset( $_REQUEST["confirm"] ) ) { } if( $_REQUEST['action'] == 'edit' || $_REQUEST['action'] == 'create' ) { - $gBitSmarty->assign( 'pigeonInfo', !empty( $pigeonInfo ) ? $pigeonInfo : NULL ); + $gBitSmarty->assign( 'pigeonInfo', !empty( $pigeonInfo ) ? $pigeonInfo : null ); } if( $_REQUEST["action"] == 'remove' || isset( $_REQUEST["confirm"] ) ) { if( isset( $_REQUEST["confirm"] ) ) { - if( $gContent->expunge( $_REQUEST["structure_id"] ) ) { + if( $gContent->expunge() ) { bit_redirect( $_SERVER['SCRIPT_NAME'].'?structure_id='.$gContent->mInfo["parent_id"] ); } else { $feedback['error'] = $gContent->mErrors; } } $gBitSystem->setBrowserTitle( 'Confirm removal of '.$gContent->mInfo['title'] ); - $formHash['remove'] = TRUE; + $formHash['remove'] = true; $formHash['structure_id'] = $_REQUEST['structure_id']; $formHash['action'] = 'remove'; $msgHash = array( @@ -108,11 +109,7 @@ if( !empty( $_REQUEST['success'] ) ) { // get all available perms only when the admin is visiting here. if ( $gBitSystem->isFeatureActive( 'pigeonholes_permissions' ) ) { - if( $gBitUser->isAdmin() ) { - $tmpPerms = $gBitUser->getGroupPermissions(); - } else { - $tmpPerms = $gBitUser->mPerms; - } + $tmpPerms = $gBitUser->isAdmin() ? $gBitUser->getGroupPermissions() : $gBitUser->mPerms; $perms[''] = tra( 'None' ); foreach( $tmpPerms as $perm => $info ) { @@ -124,7 +121,7 @@ if ( $gBitSystem->isFeatureActive( 'pigeonholes_permissions' ) ) { // get available groups ready that we can assign the pigoenhole to one of them if ( $gBitSystem->isFeatureActive( 'pigeonholes_groups' ) ) { $listHash = array( - 'only_root_groups' => TRUE, + 'only_root_groups' => true, 'sort_mode' => !empty( $_REQUEST['sort_mode'] ) ? $_REQUEST['sort_mode'] : 'group_name_asc' ); $allGroups = $gBitUser->getAllGroups( $listHash ); @@ -138,17 +135,17 @@ if ( $gBitSystem->isFeatureActive( 'pigeonholes_groups' ) ) { } $listHash = array( - 'root_structure_id' => !empty( $gContent->mInfo['root_structure_id'] ) ? $gContent->mInfo['root_structure_id'] : NULL, - 'force_extras' => TRUE, + 'root_structure_id' => !empty( $gContent->mInfo['root_structure_id'] ) ? $gContent->mInfo['root_structure_id'] : null, + 'force_extras' => true, 'max_records' => -1 ); $pigeonList = $gContent->getList( $listHash ); $gBitSmarty->assign( 'pigeonList', $pigeonList ); -$gBitSmarty->assign( 'feedback', !empty( $feedback ) ? $feedback : NULL ); +$gBitSmarty->assign( 'feedback', !empty( $feedback ) ? $feedback : null ); // Get list of available styles if ( $gBitSystem->isFeatureActive( 'pigeonholes_themes' ) ) { - $styles = $gBitThemes->getStyles( NULL, TRUE ); + $styles = $gBitThemes->getStyles( null, true ); $gBitSmarty->assign( 'styles', $styles ); } @@ -158,4 +155,3 @@ if ( !empty( $gStructure ) ) { } else { $gBitSystem->display( 'bitpackage:pigeonholes/edit_pigeonholes.tpl', tra( 'Create Pigeonhole' ) , array( 'display_mode' => 'edit' )); } -?> diff --git a/edit_structure.php b/edit_structure.php old mode 100644 new mode 100755 index 9e3ff77..4c37108 --- a/edit_structure.php +++ b/edit_structure.php @@ -16,23 +16,19 @@ /** * required setup */ -require_once( '../kernel/includes/setup_inc.php' ); +require_once '../kernel/includes/setup_inc.php'; $gBitSystem->verifyPackage( 'pigeonholes' ); $gBitSystem->verifyPermission( 'p_pigeonholes_create' ); // we need to load some javascript and css for this page $gBitThemes->loadCss( UTIL_PKG_PATH.'javascript/libs/mygosu/DynamicTree.css' ); -if( $gSniffer->_browser_info['browser'] == 'ie' && $gSniffer->_browser_info['maj_ver'] == 5 ) { - $gBitThemes->loadJavascript( UTIL_PKG_PATH.'javascript/libs/mygosu/ie5.js' ); -} $gBitThemes->loadJavascript( UTIL_PKG_PATH.'javascript/libs/mygosu/DynamicTreeBuilder.js' ); -include_once( PIGEONHOLES_PKG_INCLUDE_PATH.'lookup_pigeonholes_inc.php' ); +include_once PIGEONHOLES_PKG_INCLUDE_PATH.'lookup_pigeonholes_inc.php'; $verifyStructurePermission = 'p_pigeonholes_create'; -include_once( LIBERTY_PKG_INCLUDE_PATH.'structure_edit_inc.php' ); +include_once LIBERTY_PKG_INCLUDE_PATH.'structure_edit_inc.php'; // Display the template -$gBitSystem->display( 'bitpackage:pigeonholes/edit_structure.tpl', $gStructure->mInfo["title"] , array( 'display_mode' => 'edit' )); -?> +$gBitSystem->display( 'bitpackage:pigeonholes/edit_structure.tpl', $gStructure->mInfo["title"] , array( 'display_mode' => 'edit' )); \ No newline at end of file diff --git a/includes/bit_setup_inc.php b/includes/bit_setup_inc.php old mode 100644 new mode 100755 index c859de5..1fd129b --- a/includes/bit_setup_inc.php +++ b/includes/bit_setup_inc.php @@ -7,19 +7,28 @@ */ global $gBitSystem, $gBitUser, $gLibertySystem; -$registerHash = array( +$pRegisterHash = [ 'package_name' => 'pigeonholes', 'package_path' => dirname( dirname( __FILE__ ) ).'/', 'service' => LIBERTY_SERVICE_CATEGORIZATION, -); -$gBitSystem->registerPackage( $registerHash ); +]; + +// fix to quieten down VS Code which can't see the dynamic creation of these ... +define( 'PIGEONHOLES_PKG_NAME', $pRegisterHash['package_name'] ); +define( 'PIGEONHOLES_PKG_URL', BIT_ROOT_URL . basename( $pRegisterHash['package_path'] ) . '/' ); +define( 'PIGEONHOLES_PKG_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/' ); +define( 'PIGEONHOLES_PKG_INCLUDE_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/includes/'); +define( 'PIGEONHOLES_PKG_CLASS_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/includes/classes/'); +define( 'PIGEONHOLES_PKG_ADMIN_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/admin/'); + +$gBitSystem->registerPackage( $pRegisterHash ); define( 'PIGEONHOLES_CONTENT_TYPE_GUID', 'pigeonholes' ); if( $gBitSystem->isPackageActive( 'pigeonholes' )) { $tpl = $gBitSystem->isFeatureActive( 'pigeonholes_use_jstab' ) ? 'tab' : 'mini'; - $gLibertySystem->registerService( LIBERTY_SERVICE_CATEGORIZATION, PIGEONHOLES_PKG_NAME, array( + $gLibertySystem->registerService( LIBERTY_SERVICE_CATEGORIZATION, PIGEONHOLES_PKG_NAME, [ // functions 'content_display_function' => 'pigeonholes_content_display', 'content_preview_function' => 'pigeonholes_content_preview', @@ -34,15 +43,14 @@ if( $gBitSystem->isPackageActive( 'pigeonholes' )) { 'content_view_tpl' => 'bitpackage:pigeonholes/service_view_members_inc.tpl', 'content_nav_tpl' => 'bitpackage:pigeonholes/service_nav_path_inc.tpl', 'content_list_options_tpl' => 'bitpackage:pigeonholes/service_list_options_inc.tpl', - )); + ] ); if( $gBitUser->hasPermission( 'p_pigeonholes_view' )) { - $menuHash = array( + $menuHash = [ 'package_name' => PIGEONHOLES_PKG_NAME, 'index_url' => PIGEONHOLES_PKG_URL.'index.php', 'menu_template' => 'bitpackage:pigeonholes/menu_pigeonholes.tpl', - ); + ]; $gBitSystem->registerAppMenu( $menuHash ); } -} -?> +} \ No newline at end of file diff --git a/includes/classes/Pigeonholes.php b/includes/classes/Pigeonholes.php old mode 100644 new mode 100755 index 558fca9..a267b91 --- a/includes/classes/Pigeonholes.php +++ b/includes/classes/Pigeonholes.php @@ -24,8 +24,12 @@ /** * required setup */ -require_once( LIBERTY_PKG_CLASS_PATH.'LibertyMime.php' ); -require_once( LIBERTY_PKG_CLASS_PATH.'LibertyStructure.php' ); +namespace Bitweaver\Pigeonholes; +use Bitweaver\BitBase; +use Bitweaver\Liberty\LibertyContent; +use Bitweaver\Liberty\LibertyMime; +use Bitweaver\Liberty\LibertyStructure; +use Bitweaver\Users\RoleUser; /** * Pigeonholes @@ -38,10 +42,12 @@ class Pigeonholes extends LibertyMime { * @param $pContentId content id of the pigeonhole - use either one of the ids. * @param $pStructureId structure id of the pigeonhole - use either one of the ids. * @param $pMembersList hash with optional values to tweak the getMemberList loading sql. Used keys are Order, Select, Join and Where. - * @return none - * @access public + * @return void **/ - function Pigeonholes( $pStructureId=NULL, $pContentId=NULL, $pMemberList=Null ) { + + public $mMemberList; + + public function __construct( $pStructureId=null, $pContentId=null, $pMemberList=Null ) { parent::__construct(); $this->registerContentType( PIGEONHOLES_CONTENT_TYPE_GUID, array( 'content_type_guid' => PIGEONHOLES_CONTENT_TYPE_GUID, @@ -70,14 +76,13 @@ class Pigeonholes extends LibertyMime { /** * load the pigeonhole * @param $pExtras boolean - if set to true, pigeonhole content is added as well - * @return bool TRUE on success, FALSE if it's not valid - * @access public + * @return bool true on success, false if it's not valid **/ - function load( $pExtras=FALSE, $pLoadAttachable=TRUE ) { - if( @BitBase::verifyId( $this->mContentId ) || @BitBase::verifyId( $this->mStructureId ) ) { + public function load( $pExtras=false, $pLoadAttachable=true ) { + if( BitBase::verifyId( $this->mContentId ) || BitBase::verifyId( $this->mStructureId ) ) { global $gBitSystem; - $lookupColumn = ( @BitBase::verifyId( $this->mContentId ) ? 'lc.`content_id`' : 'ls.`structure_id`' ); - $lookupId = ( @BitBase::verifyId( $this->mContentId ) ? $this->mContentId : $this->mStructureId ); + $lookupColumn = BitBase::verifyId( $this->mContentId ) ? 'lc.`content_id`' : 'ls.`structure_id`'; + $lookupId = BitBase::verifyId( $this->mContentId ) ? $this->mContentId : $this->mStructureId; $query = "SELECT pig.*, ls.`root_structure_id`, ls.`parent_id`, lc.`title`, lc.`data`, lc.`user_id`, lc.`content_type_guid`, lc.`format_guid`, uue.`login` AS modifier_user, uue.`real_name` AS modifier_real_name, @@ -95,9 +100,9 @@ class Pigeonholes extends LibertyMime { $this->mContentId = $row['content_id']; $this->mStructureId = $row['structure_id']; $this->mInfo['user'] = $row['creator_user']; - $this->mInfo['real_name'] = ( isset( $row['creator_real_name'] ) ? $row['creator_real_name'] : $row['creator_user'] ); - $this->mInfo['display_name'] = BitUser::getTitleFromHash( $this->mInfo ); - $this->mInfo['editor'] = ( isset( $row['modifier_real_name'] ) ? $row['modifier_real_name'] : $row['modifier_user'] ); + $this->mInfo['real_name'] = isset( $row['creator_real_name'] ) ? $row['creator_real_name'] : $row['creator_user']; + $this->mInfo['display_name'] = RoleUser::getTitleFromHash( $this->mInfo ); + $this->mInfo['editor'] = isset( $row['modifier_real_name'] ) ? $row['modifier_real_name'] : $row['modifier_user']; $this->mInfo['display_link'] = $this->getDisplayLink(); $this->mInfo['display_url'] = $this->getDisplayUrl(); $this->parseData(); @@ -116,25 +121,24 @@ class Pigeonholes extends LibertyMime { $this->mInfo['members_count'] = count( $this->mInfo['members'] ); } } - return( count( $this->mInfo ) ); + return count( $this->mInfo ); } /** * get all content inserted in a given pigeonhole. if no id is given, it gets all content for all pigeonholes * @param $pContentId content id of the pigeonhole * @return array of pigeonhole members with according title and content type guid - * @access public **/ - function getMemberList( &$pListHash ) { + public function getMemberList( &$pListHash ) { global $gBitUser, $gLibertySystem, $gBitSystem; - $ret = FALSE; + $ret = false; LibertyContent::prepGetList( $pListHash ); $select = $where = $join = ''; - $bindVars = array(); - if( @BitBase::verifyId( $this->mContentId ) || @BitBase::verifyId( $pListHash['content_id'] ) ) { + $bindVars = []; + if( BitBase::verifyId( $this->mContentId ?? 0 ) || BitBase::verifyId( $pListHash['content_id'] ?? 0 ) ) { $where = " WHERE pig.`content_id` = ? "; - $bindVars[] = @BitBase::verifyId( $pListHash['content_id'] ) ? $pListHash['content_id'] : $this->mContentId; + $bindVars[] = BitBase::verifyId( $pListHash['content_id'] ?? 0 ) ? $pListHash['content_id'] : $this->mContentId; } if( !empty( $pListHash['content_type_guid'] ) ) { @@ -171,7 +175,7 @@ class Pigeonholes extends LibertyMime { } - $ret = array(); + $ret = []; $query = " SELECT pigm.*, lc.`content_id`, lc.`last_modified`, lc.`user_id`, lc.`title`, lc.`content_type_guid`, lc.`created`, @@ -186,7 +190,7 @@ class Pigeonholes extends LibertyMime { LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_attachments` latt ON ( latt.`content_id` = lc.`content_id` AND latt.`is_primary` = 'y' ) LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON ( lf.`file_id` = latt.`foreign_id` ) $join $where $order"; - $result = $this->mDb->query( $query, $bindVars, @BitBase::verifyId( $pListHash['max_records'] ) ? $pListHash['max_records'] : NULL, @BitBase::verifyId( $pListHash['offset'] ) ? $pListHash['offset'] : NULL ); + $result = $this->mDb->query( $query, $bindVars, BitBase::verifyId( $pListHash['max_records'] ?? 0 ) ? $pListHash['max_records'] : null, BitBase::verifyId( $pListHash['offset'] ?? 0 ) ? $pListHash['offset'] : null ); $contentTypes = $gLibertySystem->mContentTypes; while( $aux = $result->fetchRow() ) { if( !empty( $contentTypes[$aux['content_type_guid']] ) ) { @@ -199,7 +203,7 @@ class Pigeonholes extends LibertyMime { $aux['display_url'] = $type['content_object']->getDisplayUrlFromHash( $aux ); $aux['display_link'] = $type['content_object']->getDisplayLink( $aux ); $aux['title'] = $type['content_object']->getTitleFromHash( $aux ); - // needs updating to bw3 $aux['thumbnail_url'] = liberty_fetch_thumbnails( array()); + // needs updating to bw3 $aux['thumbnail_url'] = liberty_fetch_thumbnails( []); $ret[] = $aux; } } @@ -221,29 +225,28 @@ class Pigeonholes extends LibertyMime { LibertyContent::postGetList($pListHash); - return( !empty( $this->mErrors ) ? $this->mErrors : $ret ); + return !empty( $this->mErrors ) ? $this->mErrors : $ret; } /** * get all items that are not part of a pigeonhole yet * @return array of content not in any pigeonhole yet - * @access public **/ - function getAssignableContent( &$pListHash ) { + public function getAssignableContent( &$pListHash ) { global $gBitUser, $gLibertySystem, $gBitSystem; $where = ''; - $bindVars = array(); + $bindVars = []; LibertyContent::prepGetList( $pListHash ); if( empty( $pListHash['include_members'] ) ) { - $where .= "WHERE pigm.`content_id` IS NULL"; + $where .= "WHERE pigm.`content_id` IS null"; } if( !empty( $pListHash['find'] ) && is_string( $pListHash['find'] ) ) { $where .= empty( $where ) ? ' WHERE ' : ' AND '; $where .= " UPPER( lc.`title` ) LIKE ?"; - $bindVars[] = ( '%'.strtoupper( $pListHash['find'] ).'%'); + $bindVars[] = '%'.strtoupper( $pListHash['find'].'%'); } if( !empty( $pListHash['content_type'] ) ) { @@ -267,7 +270,7 @@ class Pigeonholes extends LibertyMime { LEFT JOIN `".BIT_DB_PREFIX."pigeonhole_members` pigm ON ( pigm.`content_id` = lc.`content_id` ) LEFT JOIN `".BIT_DB_PREFIX."users_users` uu ON ( uu.`user_id` = lc.`user_id` ) $where $order"; - $result = $this->mDb->query( $query, $bindVars, @BitBase::verifyId( $pListHash['max_records'] ) ? $pListHash['max_records'] : NULL , $pListHash['offset']); + $result = $this->mDb->query( $query, $bindVars, BitBase::verifyId( $pListHash['max_records'] ?? 0 ) ? $pListHash['max_records'] : null , $pListHash['offset']); $query = "SELECT COUNT(lc.`content_id`) FROM `".BIT_DB_PREFIX."liberty_content` lc @@ -284,7 +287,7 @@ class Pigeonholes extends LibertyMime { $type = &$contentTypes[$row['content_type_guid']]; if( empty( $type['content_object'] ) ) { // create *one* object for each object *type* to call virtual methods. - include_once( $gBitSystem->mPackages[$type['handler_package']]['path'].$type['handler_file'] ); + include_once $gBitSystem->mPackages[$type['handler_package']]['path'].$type['handler_file']; $type['content_object'] = new $type['handler_class'](); } $ret[$i]['display_link'] = $type['content_object']->getDisplayLink( $row['title'], $row ); @@ -292,7 +295,7 @@ class Pigeonholes extends LibertyMime { } // generate a map of what items are assigned to what pigeonholes - if( !empty( $pListHash['include_members'] ) && @BitBase::verifyId( $row['parent_id'] ) ) { + if( !empty( $pListHash['include_members'] ) && BitBase::verifyId( $row['parent_id'] ) ) { $map[$i][] = $row['parent_id']; } } @@ -300,31 +303,30 @@ class Pigeonholes extends LibertyMime { // complete the output if( !empty( $pListHash['include_members'] ) && !empty( $ret ) ) { foreach( $ret as $i => $r ) { - $ret[$i]['assigned'] = !empty( $map[$i] ) ? $map[$i] : NULL; + $ret[$i]['assigned'] = !empty( $map[$i] ) ? $map[$i] : null; } } LibertyContent::postGetList( $pListHash ); - return( !empty( $ret ) ? $ret : NULL ); + return !empty( $ret ) ? $ret : null; } /** * get an array of paths for all pigeonholes. used for pages where data can be inserted into pigeonholes * - * @param numeric $pContentId content id of pigeonhole. - * @param numeric $pTruncate Setting this to a number will do some smart truncations depending on how many parents there are + * @param int $pContentId content id of pigeonhole. + * @param int $pTruncate Setting this to a number will do some smart truncations depending on how many parents there are * setting it to 60 will allow 30 chars for all parents combined and 30 for the actual title - * @access public - * @return TRUE on success, FALSE if there is no pigeonhole + * @return array|null if there is no pigeonhole * @TODO We need to sort the returned values that successive pigoenholes are grouped together. */ - function getPigeonholesPathList( $pContentId=NULL, $pTruncate = FALSE, $pShowAll = FALSE ) { + public function getPigeonholesPathList( $pContentId=null, $pTruncate = false, $pShowAll = false ) { global $gBitSystem; $where = $join = ''; if( $gBitSystem->isFeatureActive( 'pigeonholes_allow_forbid_insertion' ) && !$pShowAll ) { $where .= empty( $where ) ? ' WHERE ' : ' AND '; - $where .= ' lcp.`pref_value` IS NULL OR lcp.`pref_value` != \'on\' '; + $where .= ' lcp.`pref_value` IS null OR lcp.`pref_value` != \'on\' '; $join .= ' LEFT JOIN `'.BIT_DB_PREFIX.'liberty_content_prefs` lcp ON (pig.`content_id` = lcp.`content_id` AND lcp.`pref_name` = \'no_insert\') '; } @@ -362,46 +364,44 @@ class Pigeonholes extends LibertyMime { // sort the pathlist to make the display nicer uasort( $ret, 'pigeonholes_pathlist_sorter' ); - if( @BitBase::verifyId( $pContentId ) && $assigned = $this->getPigeonholesFromContentId( $pContentId ) ) { + if( BitBase::verifyId( $pContentId ) && $assigned = $this->getPigeonholesFromContentId( $pContentId ) ) { foreach( $assigned as $a ) { - $ret[$a['content_id']][0]['selected'] = TRUE; + $ret[$a['content_id']][0]['selected'] = true; } } } - return( !empty( $ret ) ? $ret : array() ); + return !empty( $ret ) ? $ret : null; } /** * get all pigeonholes where the contenent has been inserted - * @param $pContentId content id of item in question - * @return basic information about item requested - * @access public + * @param int $pContentId content id of item in question + * @return array|null basic information about item requested **/ - function getPigeonholesFromContentId( $pContentId ) { - if( @BitBase::verifyId( $pContentId ) ) { + public function getPigeonholesFromContentId( $pContentId ) { + if( BitBase::verifyId( $pContentId ) ) { $query = "SELECT ls.* FROM `".BIT_DB_PREFIX."pigeonhole_members` pigm INNER JOIN `".BIT_DB_PREFIX."pigeonholes` pig ON ( pig.`content_id` = pigm.`parent_id` ) INNER JOIN `".BIT_DB_PREFIX."liberty_structures` ls ON ( pig.`structure_id` = ls.`structure_id` ) WHERE pigm.`content_id`=?"; - $ret = $this->mDb->getAll( $query, array( $pContentId ) ); + $ret = $this->mDb->getAll( $query, [ $pContentId ] ); } - return( !empty( $ret ) ? $ret : FALSE ); + return !empty( $ret ) ? $ret : null; } /** * get the path of a pigeonhole - * @param $pStructureId structure id of pigeonhole, if no id is given, it gets the id from $this->mStructureId - * @return path in form of an array - * @access public + * @param int|null $pStructureId structure id of pigeonhole, if no id is given, it gets the id from $this->mStructureId + * @return array|null path in form of an array **/ - function getPigeonholePath( $pStructureId=NULL ) { - if( !@BitBase::verifyId( $pStructureId ) ) { + public function getPigeonholePath( $pStructureId = null ) { + if( !BitBase::verifyId( $pStructureId ) ) { $pStructureId = $this->mStructureId; } - if( @BitBase::verifyId( $pStructureId ) ) { + if( BitBase::verifyId( $pStructureId ) ) { global $gStructure; // create new object if needed if( empty( $gStructure ) ) { @@ -410,21 +410,21 @@ class Pigeonholes extends LibertyMime { // get the structure path $ret = $gStructure->getPath( $pStructureId ); } - return( !empty( $ret ) ? $ret : FALSE ); + return !empty( $ret ) ? $ret : null; } /** * Converts a structure path into valid html links * @param $pPath path given by getPigeonholePath() - * @return the link to display the page. + * @return string the link to display the page. */ - function getDisplayPath( $pPath ) { + public function getDisplayPath( $pPath ) { global $gBitSystem; $ret = ''; if( !empty( $pPath ) && is_array( $pPath ) ) { foreach( $pPath as $node ) { $title = htmlspecialchars( $node['title'] ); - $ret .= ( @BitBase::verifyId( $node['parent_id'] ) ? ' » ' : '' ).''.preg_replace('/ /',' ',$title).''; + $ret .= ( BitBase::verifyId( $node['parent_id'] ) ? ' » ' : '' ).''.preg_replace('/ /',' ',$title).''; } } @@ -432,29 +432,28 @@ class Pigeonholes extends LibertyMime { } /** - * get list of all pigeonholes - * @param $pListHash contains array of items used to limit search results - * @param $pListHash[sort_mode] column and orientation by which search results are sorted - * @param $pListHash[find] search for a pigeonhole title - case insensitive - * @param $pListHash[max_records] maximum number of rows to return - * @param $pListHash[offset] number of results data is offset by - * @param $pListHash[title] pigeonhole name - * @param $pListHash[parent_id] pigeonhole parent_id, optional - * @param $pListHash[root_structure_id] only load the pigoenhole this root_structure_id is part of - * @param $pListHash[load_only_root] only load top most items - * @param $pListHash[parent_content_id] all the sons of the pigeonhole parent content_id , optional - * @param $pListHash[load_also_root] if parent_content_id is set load also the father, optionnal - * @return array of pigeonholes in 'data' and count of pigeonholes in 'cant' - * @access public + * get list of all pigeonholes + * @param $pListHash contains array of items used to limit search results + * @var string [sort_mode] column and orientation by which search results are sorted + * @var string [find] search for a pigeonhole title - case insensitive + * @var int [max_records] maximum number of rows to return + * @var int [offset] number of results data is offset by + * @var string [title] pigeonhole name + * @var int [parent_id] pigeonhole parent_id, optional + * @var int [root_structure_id] only load the pigoenhole this root_structure_id is part of + * @var bool [load_only_root] only load top most items + * @var int [parent_content_id] all the sons of the pigeonhole parent content_id , optional + * @var bool [load_also_root] if parent_content_id is set load also the father, optional + * @return array of pigeonholes in 'data' and count of pigeonholes in 'cant' **/ - function getList( &$pListHash ) { + public function getList( &$pListHash ) { global $gBitSystem, $gBitUser, $gBitDbType; LibertyContent::prepGetList( $pListHash ); - $ret = $bindVars = array(); + $ret = $bindVars = []; $where = $order = $join = $select = ''; - if( @BitBase::verifyId( $pListHash['root_structure_id'] ) ) { + if( BitBase::verifyId( $pListHash['root_structure_id'] ?? 0 ) ) { $where .= empty( $where ) ? ' WHERE ' : ' AND '; $where .= " ls.`root_structure_id`=? "; $bindVars[] = $pListHash['root_structure_id']; @@ -479,7 +478,7 @@ class Pigeonholes extends LibertyMime { if( $gBitSystem->isFeatureActive( 'pigeonholes_allow_forbid_insertion' ) && !empty( $pListHash['insertable'] )) { $where .= empty( $where ) ? ' WHERE ' : ' AND '; - $where .= ' lcp.`pref_value` IS NULL OR lcp.`pref_value` != \'on\' '; + $where .= ' lcp.`pref_value` IS null OR lcp.`pref_value` != \'on\' '; $join .= ' LEFT JOIN `'.BIT_DB_PREFIX.'liberty_content_prefs` lcp ON (lc.`content_id` = lcp.`content_id` AND lcp.`pref_name` = \'no_insert\') '; $select .= ' , lcp.`pref_value` AS no_insert '; } @@ -534,9 +533,9 @@ class Pigeonholes extends LibertyMime { while( $aux = $result->fetchRow() ) { //$content_ids[] = $aux['content_id']; $aux['user'] = $aux['creator_user']; - $aux['real_name'] = ( isset( $aux['creator_real_name'] ) ? $aux['creator_real_name'] : $aux['creator_user'] ); - $aux['display_name'] = BitUser::getDisplayNameFromHash( FALSE, $aux ); - $aux['editor'] = ( isset( $aux['modifier_real_name'] ) ? $aux['modifier_real_name'] : $aux['modifier_user'] ); + $aux['real_name'] = isset( $aux['creator_real_name'] ) ? $aux['creator_real_name'] : $aux['creator_user']; + $aux['display_name'] = RoleUser::getDisplayNameFromHash( $aux ); + $aux['editor'] = isset( $aux['modifier_real_name'] ) ? $aux['modifier_real_name'] : $aux['modifier_user']; $aux['display_link'] = Pigeonholes::getDisplayLink( $aux['title'], $aux ); // get member count for mysql - haha if( $gBitDbType == 'mysql' ) { @@ -551,14 +550,14 @@ class Pigeonholes extends LibertyMime { $aux['path'] = $this->getPigeonholePath( $aux['structure_id'] ); $aux['display_path'] = Pigeonholes::getDisplayPath( $aux['path'] ); // Move all the members data into the right place - $memberListHash = array ( + $memberListHash = [ 'content_id' => $aux['content_id'], - 'content_type_guid' => !empty( $pListHash['content_type_guid'] ) ? $pListHash['content_type_guid'] : NULL, - 'max_records' => !empty( $pListHash['members_max_records'] ) ? $pListHash['members_max_records'] : NULL, - 'list_page' => !empty( $pListHash['members_list_page'] ) ? $pListHash['members_list_page'] : NULL, - 'sort_mode' => !empty( $pListHash['members_sort_mode'] ) ? $pListHash['members_sort_mode'] : NULL, - 'find' => !empty( $pListHash['members_find'] ) ? $pListHash['members_find'] : NULL, - ); + 'content_type_guid' => !empty( $pListHash['content_type_guid'] ) ? $pListHash['content_type_guid'] : null, + 'max_records' => !empty( $pListHash['members_max_records'] ) ? $pListHash['members_max_records'] : null, + 'list_page' => !empty( $pListHash['members_list_page'] ) ? $pListHash['members_list_page'] : null, + 'sort_mode' => !empty( $pListHash['members_sort_mode'] ) ? $pListHash['members_sort_mode'] : null, + 'find' => !empty( $pListHash['members_find'] ) ? $pListHash['members_find'] : null, + ]; $aux['members'] = $this->getMemberList( $memberListHash ); $aux['listInfo'] = $memberListHash['listInfo']; @@ -586,10 +585,9 @@ class Pigeonholes extends LibertyMime { /** * Check permissions of all nodes that lead to this - * @return a nicely grouped set of pigeonhole members in a set of columns and starting letters. - * @access public + * @return bool a nicely grouped set of pigeonhole members in a set of columns and starting letters. **/ - function checkPathPermissions( $pPath ) { + public function checkPathPermissions( $pPath ) { global $gBitUser, $gBitSystem; if( !empty( $pPath ) && is_array( $pPath )) { foreach( $pPath as $path ) { @@ -599,22 +597,21 @@ class Pigeonholes extends LibertyMime { $query = "SELECT `pref_name`, `pref_value` FROM `".BIT_DB_PREFIX."liberty_content_prefs` WHERE `content_id` IN( ".preg_replace( "/,$/", "", str_repeat( "?,", count( $contentIds ) ) )." ) "; $result = $this->mDb->query( $query, $contentIds ); while( $aux = $result->fetchRow() ) { - ${$aux['pref_name']} = $aux['pref_value']; + $aux['pref_name'] = $aux['pref_value']; if( ( !empty( $group_id ) && !$gBitUser->isInGroup( $group_id ) ) || ( !empty( $permission ) && !$gBitUser->hasPermission( $permission ) ) ) { - return FALSE; + return false; } } } } - return TRUE; + return true; } /** * Alphabetise all member items - * @return a nicely grouped set of pigeonhole members in a set of columns and starting letters. - * @access public + * @return void array a nicely grouped set of pigeonhole members in a set of columns and starting letters. **/ - function alphabetiseMembers( &$pMememberHash ) { + public function alphabetiseMembers( &$pMememberHash ) { global $gBitSystem; if( !empty( $pMememberHash ) ) { usort( $pMememberHash, "pigeonholes_alphabetiser" ); @@ -636,17 +633,16 @@ class Pigeonholes extends LibertyMime { } /** - * Store pigeonhole data - * @param $pParamHash contains all data to store the pigeonholes - * @param $pParamHash[title] title of the new pigeonhole - * @param $pParamHash[edit] description of the pigeonhole - * @param $pParamHash[members] array of content_ids that are associated with this pigeonhole - * @param $pParamHash[root_structure_id] if this is set, it will add the pigeonhole to this structure. if it's not set, a new structure / top level pigeonhole is created - * @param $pParamHash[parent_id] set the structure_id that will server as the parent in the structure - * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why - * @access public + * Store pigeonhole data + * @param $pParamHash contains all data to store the pigeonholes + * @var string [title] title of the new pigeonhole + * @var string [edit] description of the pigeonhole + * @var array [members] array of content_ids that are associated with this pigeonhole + * @var int [root_structure_id] if this is set, it will add the pigeonhole to this structure. if it's not set, a new structure / top level pigeonhole is created + * @var int [parent_id] set the structure_id that will server as the parent in the structure + * @return bool true on success, false if store could not occur. If false, $this->mErrors will have reason why **/ - function store( &$pParamHash ) { + public function store( array &$pParamHash): bool { $this->mDb->StartTrans(); if( $this->verify( $pParamHash ) && LibertyMime::store( $pParamHash ) ) { $table = BIT_DB_PREFIX."pigeonholes"; @@ -689,19 +685,19 @@ class Pigeonholes extends LibertyMime { $this->mDb->CompleteTrans(); $this->load(); } - return( count( $this->mErrors ) == 0 ); + return count( $this->mErrors ) == 0; } /** * verify, clean up and prepare data to be stored * @param $pParamHash all information that is being stored. will update $pParamHash by reference with fixed array of itmes - * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why + * @return bool true on success, false if store could not occur. If false, $this->mErrors will have reason why * @access private **/ - function verify( &$pParamHash ) { + public function verify( array &$pParamHash ): bool { // make sure we're all loaded up if everything is valid if( $this->isValid() && empty( $this->mInfo ) ) { - $this->load( TRUE ); + $this->load( true ); } // It is possible a derived class set this to something different @@ -709,22 +705,22 @@ class Pigeonholes extends LibertyMime { $pParamHash['content_type_guid'] = $this->mContentTypeGuid; } - if( @BitBase::verifyId( $this->mContentId ) ) { + if( BitBase::verifyId( $this->mContentId ) ) { $pParamHash['content_id'] = $this->mContentId; - $pParamHash['update'] = TRUE; + $pParamHash['update'] = true; } // content store // check for name issues, first truncate length if too long if( !empty( $pParamHash['title'] ) ) { - if( !@BitBase::verifyId( $this->mContentId ) ) { + if( !BitBase::verifyId( $this->mContentId ) ) { if( empty( $pParamHash['title'] ) ) { $this->mErrors['title'] = 'You must enter a name for this category.'; } else { $pParamHash['content_store']['title'] = substr( $pParamHash['title'], 0, 160 ); } } else { - $pParamHash['content_store']['title'] = ( isset( $pParamHash['title'] ) ) ? substr( $pParamHash['title'], 0, 160 ) : $this->mInfo['title']; + $pParamHash['content_store']['title'] = isset( $pParamHash['title'] ) ? substr( $pParamHash['title'], 0, 160 ) : $this->mInfo['title']; } } elseif( empty( $pParamHash['title'] ) ) { // no name specified @@ -757,22 +753,22 @@ class Pigeonholes extends LibertyMime { if( $gBitSystem->isFeatureActive('pigeonholes_allow_forbid_insertion') && empty( $pParamHash['prefs']['no_insert'] ) ) { $pParamHash['prefs']['no_insert'] = '0'; } - $pParamHash['preferences_store'] = !empty( $pParamHash['prefs'] ) ? $pParamHash['prefs'] : NULL; + $pParamHash['preferences_store'] = !empty( $pParamHash['prefs'] ) ? $pParamHash['prefs'] : null; // structure store - if( @BitBase::verifyId( $pParamHash['root_structure_id'] ) ) { + if( BitBase::verifyId( $pParamHash['root_structure_id'] ?? 0 ) ) { $pParamHash['structure_store']['root_structure_id'] = $pParamHash['root_structure_id']; } else { - $pParamHash['structure_store']['root_structure_id'] = NULL; + $pParamHash['structure_store']['root_structure_id'] = null; } - if( @BitBase::verifyId( $pParamHash['parent_id'] ) ) { + if( BitBase::verifyId( $pParamHash['parent_id'] ?? 0 ) ) { $pParamHash['structure_store']['parent_id'] = $pParamHash['parent_id']; } else { - $pParamHash['structure_store']['parent_id'] = NULL; + $pParamHash['structure_store']['parent_id'] = null; } - return( count( $this->mErrors ) == 0 ); + return count( $this->mErrors ) == 0; } /** @@ -780,10 +776,9 @@ class Pigeonholes extends LibertyMime { * @param $pParamHash an array of content to be stored. * @param $pParamHash[parent_id] id of pigeonhole it belongs to, default is $this->mContentId * @param $pParamHash[content_id] content_id of the item to be stored - * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why - * @access public + * @return bool true on success, false if store could not occur. If false, $this->mErrors will have reason why **/ - function insertPigeonholeMember( &$pParamHash ) { + public function insertPigeonholeMember( &$pParamHash ) { if( $this->verifyPigeonholeMember( $pParamHash ) ) { foreach( $pParamHash['member_store'] as $item ) { $result = $this->mDb->associateInsert( BIT_DB_PREFIX."pigeonhole_members", $item ); @@ -791,28 +786,28 @@ class Pigeonholes extends LibertyMime { } else { error_log( "Error inserting pigeonhole: " . vc($this->mErrors)); } - return( count( $this->mErrors ) == 0 ); + return count( $this->mErrors ) == 0; } /** * verify, clean up and prepare data to be stored * @param $pParamHash all information that is being stored. will update $pParamHash by reference with fixed array of itmes - * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why + * @return bool true on success, false if store could not occur. If false, $this->mErrors will have reason why * @access private **/ - function verifyPigeonholeMember( &$pParamHash ) { + public function verifyPigeonholeMember( &$pParamHash ) { $this->mDb->StartTrans(); foreach( $pParamHash as $key => $item ) { - if( isset( $item['parent_id'] ) && @BitBase::verifyId( $item['parent_id'] ) ) { + if( isset( $item['parent_id'] ) && BitBase::verifyId( $item['parent_id'] ) ) { $tmp['member_store'][$key]['parent_id'] = $item['parent_id']; - } elseif( @BitBase::verifyId( $this->mContentId ) ) { + } elseif( BitBase::verifyId( $this->mContentId ) ) { $tmp['member_store'][$key]['parent_id'] = $this->mContentId; $pParamHash[$key]['parent_id'] = $this->mContentId; } else { $this->mErrors['store_members'] = tra( 'The content could not be inserted because the parent_id was missing.' ); } - if( isset( $item['content_id'] ) && @BitBase::verifyId( $item['content_id'] ) ) { + if( isset( $item['content_id'] ) && BitBase::verifyId( $item['content_id'] ) ) { $tmp['member_store'][$key]['content_id'] = $item['content_id']; } else { $this->mErrors['store_members'] = 'The content id is not valid.'; @@ -821,7 +816,7 @@ class Pigeonholes extends LibertyMime { $this->mDb->CompleteTrans(); $pParamHash = $tmp; - return( count( $this->mErrors ) == 0 ); + return count( $this->mErrors ) == 0; } /** @@ -830,20 +825,19 @@ class Pigeonholes extends LibertyMime { * @param $pParamHash['member_id'] content_id of content to be deleted * @param $pParamHash['deletables'] array of content_ids to check against when deleting. makes sure that only members of a given structure are removed * Note if only one of the 2 ids is given, all items with that id will be removed. if both are given, only that one particular entry is removed - * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why - * @access public + * @return bool true on success, false if store could not occur. If false, $this->mErrors will have reason why **/ - function expungePigeonholeMember( $pParamHash ) { - if( @BitBase::verifyId( $pParamHash['parent_id'] ) || @BitBase::verifyId( $pParamHash['member_id'] ) ) { + public function expungePigeonholeMember( $pParamHash ) { + if( BitBase::verifyId( $pParamHash['parent_id'] ) || BitBase::verifyId( $pParamHash['member_id'] ?? 0 ) ) { $where = ''; - $bindVars = array(); + $bindVars = []; - if( @BitBase::verifyId( $pParamHash['parent_id'] ) ) { + if( BitBase::verifyId( $pParamHash['parent_id'] ?? 0 ) ) { $where .= " WHERE `parent_id`=? "; $bindVars[] = $pParamHash['parent_id']; } - if( @BitBase::verifyId( $pParamHash['member_id'] ) ) { + if( BitBase::verifyId( $pParamHash['member_id'] ?? 0 ) ) { $where .= ( empty( $where ) ? " WHERE " : " AND " )." `content_id`=? "; $bindVars[] = $pParamHash['member_id']; } @@ -860,26 +854,22 @@ class Pigeonholes extends LibertyMime { } else { $this->mErrors['members_store'] = 'The category member(s) could not be removed.'; } - return( count( $this->mErrors ) == 0 ); + return count( $this->mErrors ) == 0; } /** * Expunge currently loaded pigeonhole - * @return bool TRUE on success, FALSE if store could not occur. - * @access public + * @return void **/ - function expunge( $pStructureId = NULL ) { - $ret = FALSE; + public function expunge(): bool { // if we have a custom structure id we want to remove, load it - if( @BitBase::verifyId( $pStructureId ) ) { - $this->mStructureId = $pStructureId; + if( BitBase::verifyId( $this->mStructureId ) ) { $this->load(); } if( $this->isValid() ) { $this->mDb->StartTrans(); // get all items that are part of the sub tree - require_once( LIBERTY_PKG_CLASS_PATH.'LibertyStructure.php' ); $struct = new LibertyStructure(); // include the current structure id as well @@ -907,7 +897,7 @@ class Pigeonholes extends LibertyMime { // remove all entries from content tables $this->mContentId = $id['content_id']; if( LibertyMime::expunge() ) { - $ret = TRUE; + $ret = true; $this->mDb->CompleteTrans(); } else { $this->mDb->RollbackTrans(); @@ -915,27 +905,25 @@ class Pigeonholes extends LibertyMime { } // finally nuke the structure in liberty_structures - $struct->removeStructureNode( $this->mStructureId, FALSE ); + $struct->removeStructureNode( $this->mStructureId, false ); } - return $ret; + return true; } /** * Generates the URL to this pigeonhole - * @param $pContentId is the pigeonhole id we want to see - * @return the link to display the page. + * @param array $pParamHash is the pigeonhole id we want to see + * @return string the link to display the page. */ public static function getDisplayUrlFromHash( &$pParamHash ) { global $gBitSystem; - $ret = NULL; + $ret = null; - if( @BitBase::verifyId( $$pParamHash['content_id'] ) ) { + if( BitBase::verifyId( $pParamHash['content_id'] ) ) { $rewrite_tag = $gBitSystem->isFeatureActive( 'pretty_urls_extended' ) ? 'view/' : ''; - if( $gBitSystem->isFeatureActive( 'pretty_urls' ) || $gBitSystem->isFeatureActive( 'pretty_urls_extended' ) ) { - $ret = PIGEONHOLES_PKG_URL.$rewrite_tag.$pContentId; - }else{ - $ret = PIGEONHOLES_PKG_URL.'view.php?content_id='.$pContentId; - } + $ret = $gBitSystem->isFeatureActive( 'pretty_urls' ) || $gBitSystem->isFeatureActive( 'pretty_urls_extended' ) + ? PIGEONHOLES_PKG_URL.$rewrite_tag.$pParamHash['content_id'] + : PIGEONHOLES_PKG_URL.'view.php?content_id='.$pParamHash['content_id']; } return $ret; @@ -943,11 +931,12 @@ class Pigeonholes extends LibertyMime { /** * Returns HTML link to display a pigeonhole - * @param $pTitle is the pigeonhole we want to see - * @param $pContentId content id of the pigeonhole in question - * @return the link to display the page. + * @param string $pLinkText is the pigeonhole we want to see + * @param array $pMixed content id of the pigeonhole in question + * @param $pAnchor + * @return string the link to display the page. */ - function getDisplayLink( $pLinkText = NULL, $pMixed = NULL, $pAnchor = NULL ) { + public function getDisplayLink( $pLinkText = null, $pMixed = null, $pAnchor = null ) { global $gBitSystem; if( empty( $pLinkText ) && !empty( $this ) ) { $ppLinkText = $this->getTitle(); @@ -972,12 +961,11 @@ class Pigeonholes extends LibertyMime { * * @param array $pContentId of the pigoenhole * @param array $pStructureId of the pigeonhole - * @access public * @return array of child pigeonholes on success, empty array on failure */ - function getSubPigeonholes( $pContentId = NULL, $pStructureId = NULL ) { + public function getSubPigeonholes( $pContentId = null, $pStructureId = null ) { global $gStructure; - $ret = array(); + $ret = []; if( empty( $gStructure )) { $struct = new LibertyStructure(); @@ -985,12 +973,12 @@ class Pigeonholes extends LibertyMime { $struct = &$gStructure; } - if( @BitBase::verifyId( $pContentId ) && !@BitBase::verifyId( $pStructureId )) { - $pigeon = $struct->getNode( NULL, $pContentId ); + if( BitBase::verifyId( $pContentId ) && !BitBase::verifyId( $pStructureId )) { + $pigeon = $struct->getNode( null, $pContentId ); $pStructureId = $pigeon['structure_id']; } - if( @BitBase::verifyId( $pStructureId )) { + if( BitBase::verifyId( $pStructureId )) { $tree = $struct->getSubTree( $pStructureId ); // weed out duplicates @@ -1031,7 +1019,7 @@ function pigeonholes_pathlist_sorter( $aa, $ab ) { * * @param array $pObject * @access public - * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure + * @return bool true on success, false on failure - mErrors will contain reason for failure */ function pigeonholes_content_display( &$pObject ) { global $gBitSystem, $gBitSmarty, $gBitUser, $gBitThemes; @@ -1043,19 +1031,15 @@ function pigeonholes_content_display( &$pObject ) { foreach( $pigeons as $pigeon ) { // we will loop through here until we get one pigeonhole that allows access if( empty( $access_granted )) { - if( $pigeonholes->checkPathPermissions( $pigeonholes->getPigeonholePath( $pigeon['structure_id'] ))) { - $access_granted = TRUE; - } else { - $access_granted = FALSE; - } + $access_granted = $pigeonholes->checkPathPermissions( $pigeonholes->getPigeonholePath( $pigeon['structure_id'] ) ) ? true : false; } } } // we need to check all pigeonholes in the path, load the prefs and work out if the user is allowed to view the page - if( isset( $access_granted ) && $access_granted === FALSE ) { + if( isset( $access_granted ) && $access_granted === false ) { $msg = tra( "This content is part of a category to which you have no access to. Please log in or request the appropriate permission from the site administrator." ); - $gBitSystem->fatalPermission( NULL, $msg ); + $gBitSystem->fatalPermission( null, $msg ); } } @@ -1064,7 +1048,7 @@ function pigeonholes_content_display( &$pObject ) { if( $pigeons = $pigeonholes->getPigeonholesFromContentId( $pObject->mContentId )) { foreach( $pigeons as $key => $pigeon ) { $pigeonholes->mContentId = $pigeon['content_id']; - $pigeonholes->load( TRUE, FALSE ); + $pigeonholes->load( true, false ); $pigeonData[] = $pigeonholes->mInfo; // set the theme chosen for this page - virtually random if page is part of multiple themes @@ -1073,7 +1057,7 @@ function pigeonholes_content_display( &$pObject ) { $gBitThemes->setStyle( $pigeonholes->getPreference( 'style' )); } } - $gBitSmarty->assign( 'pigeonData', !empty( $pigeonData ) ? $pigeonData : FALSE ); + $gBitSmarty->assign( 'pigeonData', !empty( $pigeonData ) ? $pigeonData : false ); } } } @@ -1084,25 +1068,25 @@ function pigeonholes_content_display( &$pObject ) { * * @param array $pObject * @access public - * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure + * @return bool true on success, false on failure - mErrors will contain reason for failure */ -function pigeonholes_content_edit( $pObject=NULL ) { +function pigeonholes_content_edit( $pObject=null ) { global $gBitSmarty, $gBitUser, $gBitSystem; - $pigeonPathList = array(); + $pigeonPathList = []; if( is_object($pObject) && isset($pObject->mContentTypeGuid) && !$gBitSystem->isFeatureActive('pigeonhole_no_'.$pObject->mContentTypeGuid) && $gBitUser->hasPermission( 'p_pigeonholes_insert_member' ) ) { $pigeonholes = new Pigeonholes(); - $gBitSmarty->assign('editPigeonholesEnabled', TRUE); + $gBitSmarty->assign('editPigeonholesEnabled', true); // get pigeonholes path list - if( $pigeonPathList = $pigeonholes->getPigeonholesPathList(( !empty( $pObject->mContentId ) ? $pObject->mContentId : NULL ), ( $gBitSystem->isFeatureActive( 'pigeonholes_use_jstab' ) ? FALSE : 100 ))) { + if( $pigeonPathList = $pigeonholes->getPigeonholesPathList(!empty( $pObject->mContentId ) ? $pObject->mContentId : null, $gBitSystem->isFeatureActive( 'pigeonholes_use_jstab' ) ? false : 100 )) { $gBitSmarty->assign( 'pigeonPathList', $pigeonPathList ); } } else { - $gBitSmarty->assign('editPigeonholesEnabled', FALSE); + $gBitSmarty->assign('editPigeonholesEnabled', false); } } @@ -1111,22 +1095,21 @@ function pigeonholes_content_edit( $pObject=NULL ) { * * @param array $pObject * @access public - * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure + * @return bool true on success, false on failure - mErrors will contain reason for failure */ -function pigeonholes_content_expunge( $pObject=NULL ) { +function pigeonholes_content_expunge( $pObject=null ) { $pigeonholes = new Pigeonholes(); - $pigeonholes->expungePigeonholeMember( array( 'member_id' => $pObject->mContentId ) ); + $pigeonholes->expungePigeonholeMember( [ 'member_id' => $pObject->mContentId ] ); } /** * pigeonholes_content_preview * - * @access public - * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure + * @return void */ -function pigeonholes_content_preview( $pObject=NULL, $pParamHash ) { +function pigeonholes_content_preview( $pObject=null, $pParamHash ) { global $gBitSmarty, $gBitUser, $gBitSystem; - $pigeonPathList = array(); + $pigeonPathList = []; if( is_object($pObject) && isset($pObject->mContentTypeGuid) && !$gBitSystem->isFeatureActive('pigeonhole_no_'.$pObject->mContentTypeGuid) && @@ -1136,11 +1119,7 @@ function pigeonholes_content_preview( $pObject=NULL, $pParamHash ) { // get pigeonholes path list if( $pigeonPathList = $pigeonholes->getPigeonholesPathList() ) { foreach( $pigeonPathList as $key => $path ) { - if( !empty( $pParamHash['pigeonholes']['pigeonhole'] ) && in_array( $key, $pParamHash['pigeonholes']['pigeonhole'] ) ) { - $pigeonPathList[$key][0]['selected'] = TRUE; - } else { - $pigeonPathList[$key][0]['selected'] = FALSE; - } + $pigeonPathList[$key][0]['selected'] = !empty( $pParamHash['pigeonholes']['pigeonhole'] ) && in_array( $key, $pParamHash['pigeonholes']['pigeonhole'] ) ? true : false; } $gBitSmarty->assign( 'pigeonPathList', $pigeonPathList ); } @@ -1153,7 +1132,7 @@ function pigeonholes_content_preview( $pObject=NULL, $pParamHash ) { * @param array $pObject * @param array $pParamHash * @access public - * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure + * @return void */ function pigeonholes_content_store( $pObject, $pParamHash ) { global $gBitSmarty, $gBitUser, $gBitSystem; @@ -1172,7 +1151,7 @@ function pigeonholes_content_store( $pObject, $pParamHash ) { // here we need to work out if we need to save at all // get all originally selected items - $selectedItem = array(); + $selectedItem = []; if( !empty( $pigeonPathList ) ) { foreach( $pigeonPathList as $path ) { if( !empty( $path[0]['selected'] ) ) { @@ -1184,30 +1163,30 @@ function pigeonholes_content_store( $pObject, $pParamHash ) { // quick and dirty check to start off with if( empty( $pParamHash['pigeonholes'] ) || count( $pParamHash['pigeonholes']['pigeonhole'] ) != count( $selectedItem ) ) { - $modified = TRUE; + $modified = true; } else { // more thorough check foreach( $selectedItem as $item ) { if( !in_array( $item, $pParamHash['pigeonholes']['pigeonhole'] ) ) { - $modified = TRUE; + $modified = true; } } } if( !empty( $modified ) ) { // first remove all entries with this content_id - if( $pigeonholes->expungePigeonholeMember( array( 'member_id' => $pParamHash['content_id'] ) ) && !empty( $pParamHash['pigeonholes'] ) ) { + if( $pigeonholes->expungePigeonholeMember( [ 'member_id' => $pParamHash['content_id'] ] ) && !empty( $pParamHash['pigeonholes'] ) ) { // insert the content into the desired pigeonholes foreach( $pParamHash['pigeonholes']['pigeonhole'] as $p_id ) { - $memberHash[] = array( + $memberHash[] = [ 'parent_id' => $p_id, 'content_id' => $pParamHash['content_id'] - ); + ]; } if( !$pigeonholes->insertPigeonholeMember( $memberHash ) ) { $gBitSmarty->assign( 'msg', tra( "There was a problem inserting the content into the pigeonholes." ) ); - $gBitSystem->display( 'error.tpl' , NULL, array( 'display_mode' => 'display' )); + $gBitSystem->display( 'error.tpl' , null, [ 'display_mode' => 'display' ] ); die; } } @@ -1224,7 +1203,7 @@ function pigeonholes_content_store( $pObject, $pParamHash ) { * @access public * @return void */ -function pigeonholes_content_list( &$pObject, $pParamHash = NULL ) { +function pigeonholes_content_list( &$pObject, $pParamHash = null ) { global $gBitSystem, $gBitSmarty; if( $gBitSystem->isFeatureActive( 'pigeonholes_list_filter' )) { $pigeonholes = new Pigeonholes(); @@ -1232,10 +1211,10 @@ function pigeonholes_content_list( &$pObject, $pParamHash = NULL ) { 'sort_mode' => array( 'root_structure_id_asc', 'title_asc' ), - 'insertable' => TRUE, + 'insertable' => true, ); $pigeonList = $pigeonholes->getList( $listHash ); - $list = array(); + $list = []; foreach( $pigeonList as $pigeon ) { $list[$pigeon['content_id']] = $pigeon['display_link']; } @@ -1247,12 +1226,12 @@ function pigeonholes_content_list( &$pObject, $pParamHash = NULL ) { * filter the search with pigeonholes * @param $pParamHash['pigeonholes']['filter'] - a pigeonhole or an array of pigeonhole content_id **/ -function pigeonholes_content_list_sql( &$pObject, $pParamHash = NULL ) { +function pigeonholes_content_list_sql( &$pObject, $pParamHash = null ) { global $gBitSystem; - $ret = array(); + $ret = []; if( !empty( $pParamHash['pigeonholes']['no_filter'] )) { - $pParamHash['pigeonholes']['filter'] = array(); + $pParamHash['pigeonholes']['filter'] = []; } else { if( !empty( $pParamHash['pigeonholes']['filter'] )) { $pParamHash['liberty_categories'] = $pParamHash['pigeonholes']['filter']; @@ -1266,7 +1245,7 @@ function pigeonholes_content_list_sql( &$pObject, $pParamHash = NULL ) { // if we want to allow items in subcategories, we get those and include them in the query if( !empty( $pParamHash['pigeonholes']['sub_holes'] )) { $pigeonholes = new Pigeonholes(); - $contentIds = array(); + $contentIds = []; foreach( $pParamHash['liberty_categories'] as $pigeonhole ) { $pigeons = $pigeonholes->getSubPigeonholes( $pigeonhole ); $contentIds = array_merge( $contentIds, array_keys( $pigeons )); @@ -1293,7 +1272,7 @@ function pigeonholes_content_list_sql( &$pObject, $pParamHash = NULL ) { // if we want to allow items in subcategories, we get those and include them in the query if( !empty( $pParamHash['pigeonholes']['root_sub_holes'] )) { $pigeonholes = new Pigeonholes(); - $contentIds = array(); + $contentIds = []; foreach( $pParamHash['liberty_root_categories'] as $pigeonhole ) { $pigeons = $pigeonholes->getSubPigeonholes( $pigeonhole ); $contentIds = array_merge( $contentIds, array_keys( $pigeons )); @@ -1310,5 +1289,4 @@ function pigeonholes_content_list_sql( &$pObject, $pParamHash = NULL ) { } return $ret; -} -?> +} \ No newline at end of file diff --git a/includes/lookup_pigeonholes_inc.php b/includes/lookup_pigeonholes_inc.php index fcd4b4b..18fe4d1 100644 --- a/includes/lookup_pigeonholes_inc.php +++ b/includes/lookup_pigeonholes_inc.php @@ -15,9 +15,8 @@ * Required Files */ // include service functions -require_once( PIGEONHOLES_PKG_CLASS_PATH.'Pigeonholes.php' ); +use Bitweaver\Pigeonholes; $gContent = new Pigeonholes( ( !empty( $_REQUEST['structure_id'] ) ? $_REQUEST['structure_id'] : NULL ), ( !empty( $_REQUEST['content_id'] ) ? $_REQUEST['content_id'] : NULL ) ); $gContent->load( TRUE ); -$gBitSmarty->assignByRef( 'gContent', $gContent ); -?> +$gBitSmarty->assign( 'gContent', $gContent ); diff --git a/index.php b/index.php old mode 100644 new mode 100755 index 57269c4..89bc133 --- a/index.php +++ b/index.php @@ -16,7 +16,7 @@ /** * required setup */ -require_once( '../kernel/includes/setup_inc.php' ); +require_once '../kernel/includes/setup_inc.php'; include_once( PIGEONHOLES_PKG_INCLUDE_PATH.'lookup_pigeonholes_inc.php' ); if( !empty( $gContent->mStructureId ) ) { header( 'Location: '.$gContent->getDisplayUrl() ); diff --git a/list.php b/list.php old mode 100644 new mode 100755 index 5d94d70..9612650 --- a/list.php +++ b/list.php @@ -19,9 +19,9 @@ $gBitSystem->verifyPermission( 'p_pigeonholes_view' ); include_once( PIGEONHOLES_PKG_INCLUDE_PATH.'lookup_pigeonholes_inc.php' ); $listHash = &$_REQUEST; -$listHash['load_only_root'] = TRUE; +$listHash['load_only_root'] = true; $listHash['sort_mode'] = !empty( $listHash['sort_mode'] ) ? $listHash['sort_mode'] : 'title_asc'; -$listHash['parse_data'] = TRUE; +$listHash['parse_data'] = true; $pigeonList = $gContent->getList( $listHash ); // set up structure related stuff diff --git a/modules/mod_category_menu.php b/modules/mod_category_menu.php old mode 100644 new mode 100755 index fc7eeda..a7d5e2b --- a/modules/mod_category_menu.php +++ b/modules/mod_category_menu.php @@ -23,10 +23,9 @@ if( !empty( $gContent->mContentId ) ) { } if( $pigeons = $pigeonholes->getPigeonholesFromContentId( $gContent->mContentId ) ) { foreach( $pigeons as $pigeon ) { - $modPigeonStructures[] = $gStructure->getSubTree( $pigeon['root_structure_id'], TRUE ); + $modPigeonStructures[] = $gStructure->getSubTree( $pigeon['root_structure_id'], true ); } - $_template->tpl_vars['modPigeonStructures'] = new Smarty_variable( !empty( $modPigeonStructures ); + $gBitSmarty->assign( 'modPigeonStructures', !empty( $modPigeonStructures )); } } -} -?> +} \ No newline at end of file diff --git a/modules/mod_category_suckerfish.php b/modules/mod_category_suckerfish.php old mode 100644 new mode 100755 index 5f7e177..23acc5b --- a/modules/mod_category_suckerfish.php +++ b/modules/mod_category_suckerfish.php @@ -20,17 +20,17 @@ global $gBitSmarty, $gQueryUserId, $gBitThemes, $module_rows, $moduleParams, $gB $module_rows = $moduleParams['module_rows']; $module_params = $moduleParams['module_params']; -$_template->tpl_vars['moduleTitle'] = new Smarty_variable( isset($moduleParams['title']) ); +$gBitSmarty->assign( 'moduleTitle', isset($moduleParams['title']) ); -$ns = array(); +$ns = []; if($gBitSystem->isPackageActive('pigeonholes')) { - require_once(PIGEONHOLES_PKG_CLASS_PATH.'Pigeonholes.php'); + require_once(PIGEONHOLES_PKG_PATH.'Pigeonholes.php'); $p = new Pigeonholes(); $s = new LibertyStructure(); // Prep get list screws with us. - $listHash = array('load_only_root'=> TRUE, 'sort_mode' => 'lc.title_asc', 'offset' => 0, 'max_records' => '999999', 'find' => ''); + $listHash = array('load_only_root'=> true, 'sort_mode' => 'lc.title_asc', 'offset' => 0, 'max_records' => '999999', 'find' => ''); if (!empty($module_params['root_structure_id'])) { $listHash['root_structure_id'] = $module_params['root_structure_id']; } @@ -42,7 +42,7 @@ if($gBitSystem->isPackageActive('pigeonholes')) { } foreach ($l as $e) { $d = $s->getSubTree( $e['structure_id'] ); - $d_o = array(); + $d_o = []; foreach ($d as $c) { $pos_var = &$d_o; if($c['level']!=0) { @@ -50,16 +50,16 @@ if($gBitSystem->isPackageActive('pigeonholes')) { $pos_var = &$d_o; foreach ($pos as $pos_v) { if (!isset($pos_var['children'])) { - $pos_var['children']=array(); + $pos_var['children']=[]; } if (!isset($pos_var['children'][$pos_v-1])) { - $pos_var['children'][$pos_v-1]=array(); + $pos_var['children'][$pos_v-1]=[]; } $pos_var = &$pos_var['children'][$pos_v-1]; } } if (empty($pos_var['data'])) { - $pos_var['children']=array(); + $pos_var['children']=[]; $c['display_url']=$p->getDisplayUrl($c['content_id']); $pos_var['data']=$c; } @@ -105,15 +105,15 @@ if (!defined('MENU_LEVELS_DEFINED')) { if (!empty($module_params['expand_root']) && $module_params['expand_root']) { if (isset($ns[0]) && !empty($ns[0]['children'])) { - $_template->tpl_vars['pigeonMenu'] = new Smarty_variable( menuLevels($ns[0]['children'], 0)); + $gBitSmarty->assign( 'pigeonMenu', menuLevels($ns[0]['children'], 0)); } else if (!empty($ns[0]['children'])) { - $_template->tpl_vars['pigeonMenu'] = new Smarty_variable( menuLevels($ns['children'], 0)); + $gBitSmarty->assign( 'pigeonMenu', menuLevels($ns['children'], 0)); } } else { - $_template->tpl_vars['pigeonMenu'] = new Smarty_variable( menuLevels($ns, 0)); + $gBitSmarty->assign( 'pigeonMenu', menuLevels($ns, 0)); } -$_template->tpl_vars['pigeonholesPackageActive'] = new Smarty_variable( $gBitSystem->isPackageActive('pigeonholes')); +$gBitSmarty->assign( 'pigeonholesPackageActive', $gBitSystem->isPackageActive('pigeonholes')); ?> diff --git a/modules/mod_whats_related.php b/modules/mod_whats_related.php old mode 100644 new mode 100755 index b40e7a9..36e012e --- a/modules/mod_whats_related.php +++ b/modules/mod_whats_related.php @@ -21,11 +21,10 @@ if( !empty( $gContent->mContentId ) ) { if( $pigeons = $pigeonholes->getPigeonholesFromContentId( $gContent->mContentId ) ) { foreach( $pigeons as $pigeon ) { $pigeonholes->mContentId = $pigeon['content_id']; - $pigeonholes->load( TRUE ); + $pigeonholes->load( true ); $modRelatedPigeon[] = $pigeonholes->mInfo; } - $_template->tpl_vars['modRelatedPigeon'] = new Smarty_variable( !empty( $modRelatedPigeon ); + $gBitSmarty->assign( 'modRelatedPigeon', !empty( $modRelatedPigeon ) ); } } -} -?> +} \ No newline at end of file diff --git a/view.php b/view.php old mode 100644 new mode 100755 index c7aabbd..2651575 --- a/view.php +++ b/view.php @@ -16,7 +16,7 @@ /** * required setup */ -require_once( '../kernel/includes/setup_inc.php' ); +require_once '../kernel/includes/setup_inc.php'; $gBitSystem->verifyPackage( 'pigeonholes' ); $gBitSystem->verifyPermission( 'p_pigeonholes_view' ); @@ -28,11 +28,11 @@ if (isset($_REQUEST['structure_id'])) { header("Location:".$gContent->getDisplayUrl()); } -$gBitSmarty->assignByRef( 'memberFeedback', $memberFeedback = array() ); +$gBitSmarty->assign( 'memberFeedback', $memberFeedback = [] ); // set up structure related stuff global $gStructure; -if( !@BitBase::verifyId( $gContent->mInfo['root_structure_id'] ) ) { +if( !BitBase::verifyId( $gContent->mInfo['root_structure_id'] ) ) { header( "Location:".PIGEONHOLES_PKG_URL."list.php" ); } @@ -55,7 +55,7 @@ if( empty( $gStructure ) || !$gStructure->isValid() ) { $gBitSystem->fatalError( tra( 'Invalid structure' )); } -$gBitSmarty->assignByRef( 'gStructure', $gStructure ); +$gBitSmarty->assign( 'gStructure', $gStructure ); $gBitSmarty->assign( 'structureInfo', $gStructure->mInfo ); $gBitSmarty->assign( 'subtree', $gStructure->getSubTree( $gStructure->mStructureId ) ); @@ -63,9 +63,9 @@ if( $gContent->checkPathPermissions( $gContent->getField( 'path' ) ) ) { $listHash = array( 'root_structure_id' => $gContent->mInfo['root_structure_id'], 'structure_id' => $gContent->mInfo['structure_id'], - 'parse_data' => TRUE, + 'parse_data' => true, 'max_records' => -1, - 'load_extras' => TRUE, + 'load_extras' => true, 'members_max_records' => -1, ); $pigeonList = $gContent->getList( $listHash ); -- cgit v1.3