diff options
| author | lsces <lester@lsces.co.uk> | 2025-08-28 17:13:24 +0100 |
|---|---|---|
| committer | lsces <lester@lsces.co.uk> | 2025-08-28 17:13:24 +0100 |
| commit | c4d94b5d3320db21e5dcb7e01eecd5e1f3a361b6 (patch) | |
| tree | 52c8eb5cf920597e108b962a02a50b7c3f88372f /includes | |
| parent | ca99260af5783d2d12b3f79fbd43a1aadbef15ff (diff) | |
| download | blogs-c4d94b5d3320db21e5dcb7e01eecd5e1f3a361b6.tar.gz blogs-c4d94b5d3320db21e5dcb7e01eecd5e1f3a361b6.tar.bz2 blogs-c4d94b5d3320db21e5dcb7e01eecd5e1f3a361b6.zip | |
Extra code updated to PHP8.4 and namespace
Diffstat (limited to 'includes')
| -rwxr-xr-x[-rw-r--r--] | includes/bit_setup_inc.php | 36 | ||||
| -rwxr-xr-x[-rw-r--r--] | includes/display_bitblog_inc.php | 38 | ||||
| -rwxr-xr-x[-rw-r--r--] | includes/display_bitblogpost_inc.php | 41 | ||||
| -rwxr-xr-x[-rw-r--r--] | includes/lookup_blog_inc.php | 17 | ||||
| -rwxr-xr-x[-rw-r--r--] | includes/lookup_post_inc.php | 16 |
5 files changed, 84 insertions, 64 deletions
diff --git a/includes/bit_setup_inc.php b/includes/bit_setup_inc.php index 5f1fdef..66dc8e0 100644..100755 --- a/includes/bit_setup_inc.php +++ b/includes/bit_setup_inc.php @@ -2,39 +2,49 @@ /** * @package blogs */ +namespace Bitweaver\Blogs; +use Bitweaver\KernelTools; global $gBitSystem, $gBitUser, $gBitSmarty; define( 'LIBERTY_SERVICE_BLOGS', 'blogs' ); -$registerHash = array( +$pRegisterHash = [ 'package_name' => 'blogs', 'package_path' => dirname( dirname( __FILE__ ) ).'/', - 'homeable' => TRUE, -); -$gBitSystem->registerPackage( $registerHash ); + 'homeable' => true, +]; + +// fix to quieten down VS Code which can't see the dynamic creation of these ... +define( 'BLOGS_PKG_NAME', $pRegisterHash['package_name'] ); +define( 'BLOGS_PKG_URL', BIT_ROOT_URL . basename( $pRegisterHash['package_path'] ) . '/' ); +define( 'BLOGS_PKG_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/' ); +define( 'BLOGS_PKG_INCLUDE_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/includes/'); +define( 'BLOGS_PKG_CLASS_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/includes/classes/'); +define( 'BLOGS_PKG_ADMIN_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/admin/'); + +$gBitSystem->registerPackage( $pRegisterHash ); if( $gBitSystem->isPackageActive( 'blogs' ) ) { if( $gBitUser->hasPermission( 'p_blogs_view' ) ) { - $menuHash = array( + $menuHash = [ 'package_name' => BLOGS_PKG_NAME, 'index_url' => BLOGS_PKG_URL.'index.php', 'menu_template' => 'bitpackage:blogs/menu_blogs.tpl', 'admin_comments_url' => KERNEL_PKG_URL.'admin/index.php?page=blogs', - ); + ]; $gBitSystem->registerAppMenu( $menuHash ); $gLibertySystem->registerService( LIBERTY_SERVICE_BLOGS, BLOGS_PKG_NAME, - array( 'module_display_function' => 'blogs_module_display', ), - array( - 'description' => tra( 'A module display service which helps hook in javascript necessary when using the center module on other pages. This is a temporary fix to address a limitation of the rendering order in BitThemes and only applies to blog content.' ), - 'required' => TRUE, - ) + [ 'module_display_function' => 'blogs_module_display', ], + [ + 'description' => KernelTools::tra( 'A module display service which helps hook in javascript necessary when using the center module on other pages. This is a temporary fix to address a limitation of the rendering order in BitThemes and only applies to blog content.' ), + 'required' => true, + ] ); } - $gBitSystem->registerNotifyEvent( array( "blog_post" => tra("An entry is posted to a blog") ) ); - + $gBitSystem->registerNotifyEvent( [ "blog_post" => KernelTools::tra("An entry is posted to a blog") ] ); } diff --git a/includes/display_bitblog_inc.php b/includes/display_bitblog_inc.php index 19c70eb..a806fc9 100644..100755 --- a/includes/display_bitblog_inc.php +++ b/includes/display_bitblog_inc.php @@ -12,10 +12,13 @@ /** * required setup */ -$gBitSystem->verifyPackage( 'blogs' ); -require_once( BLOGS_PKG_CLASS_PATH.'BitBlog.php' ); -require_once( BLOGS_PKG_INCLUDE_PATH.'lookup_blog_inc.php'); +namespace Bitweaver\Liberty; +use Bitweaver\KernelTools; +use Bitweaver\Blogs\BitBlogPost; +require_once BLOGS_PKG_INCLUDE_PATH.'lookup_blog_inc.php'; + +$gBitSystem->verifyPackage( 'blogs' ); $displayHash = array( 'perm_name' => $gContent->mViewContentPerm ); $gContent->invokeServices( 'content_display_function', $displayHash ); @@ -30,7 +33,7 @@ if( isset($_REQUEST['user_id']) && !isset( $_REQUEST['blog_id'] ) ) { if( !$gContent->isValid() ) { $gBitSystem->setHttpStatus( 404 ); - $gBitSystem->fatalError( tra( 'No blog indicated' )); + $gBitSystem->fatalError( KernelTools::tra( 'No blog indicated' )); } $gContent->verifyViewPermission(); @@ -51,18 +54,18 @@ if( !$gContent->hasUpdatePermission() ) { $now = $gBitSystem->getUTCTime(); $blogPost = new BitBlogPost(); -$listHash = array(); +$listHash = $_REQUEST; $listHash['blog_id'] = $gContent->getField( 'blog_id' ); -$listHash['parse_data'] = TRUE; +$listHash['parse_data'] = true; $listHash['max_records'] = $gContent->getField( 'max_posts' ); -$listHash['load_num_comments'] = TRUE; +$listHash['load_num_comments'] = true; $blogPosts = $blogPost->getList( $listHash ); if( count( $blogPosts ) ) { // If there're more records then assign next_offset - $gBitSmarty->assignByRef('blogPosts', $blogPosts); - $gBitSmarty->assign( 'listInfo', $listHash ); + $gBitSmarty->assign('blogPosts', $blogPosts); + $gBitSmarty->assign( 'listInfo', $listHash['listInfo'] ); } elseif( $gContent->hasPostPermission() ) { - bit_redirect( BLOGS_PKG_URL.'post.php?blog_id='.$gContent->getField( 'blog_id' ) ); + KernelTools::bit_redirect( BLOGS_PKG_URL.'post.php?blog_id='.$gContent->getField( 'blog_id' ) ); } if( $gBitSystem->isFeatureActive( 'users_watches' ) ) { @@ -70,7 +73,7 @@ if( $gBitSystem->isFeatureActive( 'users_watches' ) ) { if ($_REQUEST['watch_action'] == 'add') { $blogPost = new BitBlogPost( $_REQUEST['watch_object'] ); if( $blogPost->load() ) { - $gBitUser->storeWatch( $_REQUEST['watch_event'], $_REQUEST['watch_object'], tra('blog'), $blogPost->getTitle(), $blogPost->getDisplayUrl() ); + $gBitUser->storeWatch( $_REQUEST['watch_event'], $_REQUEST['watch_object'], KernelTools::tra('blog'), $blogPost->getTitle(), $blogPost->getDisplayUrl() ); } } else { $gBitUser->expungeWatch( $_REQUEST['watch_event'], $_REQUEST['watch_object'] ); @@ -85,12 +88,15 @@ if( $gBitSystem->isFeatureActive( 'users_watches' ) ) { } $gBitSmarty->assign('descriptionLength', $gBitSystem->getConfig( 'blog_posts_description_length', 500 ) ); -$gBitSmarty->assign('showDescriptionsOnly', TRUE); +$gBitSmarty->assign('showDescriptionsOnly', true); if ( $gBitSystem->isFeatureActive( 'blog_ajax_more' ) && $gBitThemes->isJavascriptEnabled() ){ - $gBitSmarty->assign('ajax_more', TRUE); - $gBitThemes->loadAjax( 'mochikit', array( 'Iter.js', 'DOM.js', 'Style.js', 'Color.js', 'Position.js', 'Visual.js' ) ); + $gBitSmarty->assign('ajax_more', true); + $gBitThemes->loadAjax( 'mochikit', [ 'Iter.js', 'DOM.js', 'Style.js', 'Color.js', 'Position.js', 'Visual.js' ] ); +} + +if( $gContent->isValid() ) { + $gBitSystem->setCanonicalLink( $gContent->getDisplayUrl() ); } // Display the template -$gBitSystem->display( 'bitpackage:blogs/view_blog.tpl', $gContent->getTitle() , array( 'display_mode' => 'display' )); -?> +$gBitSystem->display( 'bitpackage:blogs/view_blog.tpl', $gContent->getTitle() , [ 'display_mode' => 'display' ] );
\ No newline at end of file diff --git a/includes/display_bitblogpost_inc.php b/includes/display_bitblogpost_inc.php index 266d725..08bd0a6 100644..100755 --- a/includes/display_bitblogpost_inc.php +++ b/includes/display_bitblogpost_inc.php @@ -7,7 +7,9 @@ /** * required setup */ -include_once( BLOGS_PKG_CLASS_PATH.'BitBlog.php' ); +use Bitweaver\Blogs\BitBlog; +use Bitweaver\KernelTools; +use \Bitweaver\Liberty\LibertyContent; if (!isset($gContent->mPostId)) { $parts = parse_url($_SERVER['REQUEST_URI']); @@ -29,18 +31,18 @@ if (!isset($gContent->mPostId)) { $blog_name = isset($_REQUEST['blog_name']) ? $_REQUEST['blog_name'] : ''; if ($gContent->addTrackbackFrom( $_REQUEST['url'], $title, $excerpt, $blog_name ) ) { - print ('<?xml version="1.0" encoding="iso-8859-1"?>'); + print '<?xml version="1.0" encoding="iso-8859-1"?>'; - print ('<response>'); - print ('<error>0</error>'); - print ('</response>'); + print '<response>'; + print '<error>0</error>'; + print '</response>'; } else { - print ('<?xml version="1.0" encoding="iso-8859-1"?>'); + print '<?xml version="1.0" encoding="iso-8859-1"?>'; - print ('<response>'); - print ('<error>1</error>'); - print ('<message>Error trying to add ping for post</message>'); - print ('</response>'); + print '<response>'; + print '<error>1</error>'; + print '<message>Error trying to add ping for post</message>'; + print '</response>'; } die; @@ -49,15 +51,17 @@ if (!isset($gContent->mPostId)) { $gBitSystem->verifyPackage( 'blogs' ); -$gBitSystem->verifyPermission( 'p_blogs_view' ); +// $gBitSystem->verifyPermission( 'p_blogs_view' ); // Check permissions to access this page if( !$gContent->isValid() ) { $gBitSystem->setHttpStatus( 404 ); - $gBitSystem->fatalError( tra( 'Post cannot be found' )); + $gBitSystem->fatalError( KernelTools::tra( 'Post cannot be found' )); +} else { + $gBitSystem->setCanonicalLink( $gContent->getDisplayUrl() ); } -$displayHash = array( 'perm_name' => 'p_blogs_view' ); +$displayHash = [ 'perm_name' => 'p_blogs_view' ]; $gContent->invokeServices( 'content_display_function', $displayHash ); $gBitSmarty->assign('post_id', $gContent->mPostId); @@ -67,9 +71,9 @@ if ( empty( $_REQUEST['format'] ) || $_REQUEST['format'] == "full" || $_REQUEST[ if ($gBitSystem->isFeatureActive( 'blog_posts_comments' ) ) { $comments_return_url = $_SERVER['SCRIPT_NAME']."?post_id=".$gContent->mPostId; $commentsParentId = $gContent->mContentId; - include_once ( LIBERTY_PKG_INCLUDE_PATH.'comments_inc.php' ); + include_once LIBERTY_PKG_INCLUDE_PATH.'comments_inc.php'; } - $extendedTitle = isset($gContent->mInfo['blogtitle']) ? ' - '.$gContent->mInfo['blogtitle'] : NULL; + $extendedTitle = $gContent->mInfo['blogtitle'] ?? ''; $gBitSystem->setBrowserTitle($gContent->mInfo['title'].$extendedTitle); } else { // if the format requested is not the full post or the readmore data we default to just the first half of the post @@ -82,8 +86,7 @@ $gBitSmarty->assign('post_info', $gContent->mInfo ); // Display the template if ( isset( $_REQUEST['output'] ) && $_REQUEST['output']="ajax"){ - $gBitSystem->display( 'bitpackage:blogs/view_blog_post_xml.tpl', NULL, array( 'format' => 'center_only', 'display_mode' => 'display' )); + $gBitSystem->display( 'bitpackage:blogs/view_blog_post_xml.tpl', null, [ 'format' => 'center_only', 'display_mode' => 'display' ] ); }else{ - $gBitSystem->display( 'bitpackage:blogs/view_blog_post.tpl' , NULL, array( 'display_mode' => 'display' )); -} -?> + $gBitSystem->display( 'bitpackage:blogs/view_blog_post.tpl' , null, [ 'display_mode' => 'display' ] ); +}
\ No newline at end of file diff --git a/includes/lookup_blog_inc.php b/includes/lookup_blog_inc.php index fa384dd..838596d 100644..100755 --- a/includes/lookup_blog_inc.php +++ b/includes/lookup_blog_inc.php @@ -8,22 +8,23 @@ * required setup */ global $gContent; -require_once( BLOGS_PKG_CLASS_PATH.'BitBlog.php' ); -require_once( LIBERTY_PKG_INCLUDE_PATH.'lookup_content_inc.php' ); +use Bitweaver\Blogs\BitBlog; +use Bitweaver\BitBase; + +require_once LIBERTY_PKG_INCLUDE_PATH.'lookup_content_inc.php'; // if we already have a gContent, we assume someone else created it for us, and has properly loaded everything up. if( empty( $gContent ) || !is_object( $gContent ) || !$gContent->isValid() ) { // if blog_id supplied, use that - if( @BitBase::verifyId( $_REQUEST['blog_id'] ) ) { + if( BitBase::verifyId( $_REQUEST['blog_id'] ?? -2 ) ) { $gContent = new BitBlog( $_REQUEST['blog_id'] ); $gContent->load(); - } elseif( @BitBase::verifyId( $_REQUEST['content_id'] ) ) { - $gContent = new BitBlog( NULL, $_REQUEST['content_id'] ); + } elseif( BitBase::verifyId( $_REQUEST['content_id'] ?? -2 ) ) { + $gContent = new BitBlog( null, $_REQUEST['content_id'] ); $gContent->load(); } else { $gContent = new BitBlog(); } - $gBitSmarty->assignByRef( 'gContent', $gContent ); -} -?> + $gBitSmarty->assign( 'gContent', $gContent ); +}
\ No newline at end of file diff --git a/includes/lookup_post_inc.php b/includes/lookup_post_inc.php index 0803a4e..efa3f90 100644..100755 --- a/includes/lookup_post_inc.php +++ b/includes/lookup_post_inc.php @@ -8,21 +8,21 @@ * Initial Setup */ global $gContent; -require_once( BLOGS_PKG_CLASS_PATH.'BitBlogPost.php'); -require_once( LIBERTY_PKG_INCLUDE_PATH.'lookup_content_inc.php' ); +use Bitweaver\Blogs\BitBlogPost; +use Bitweaver\BitBase; +require_once LIBERTY_PKG_INCLUDE_PATH.'lookup_content_inc.php'; if( empty( $gContent ) || !is_object( $gContent ) || !$gContent->isValid() ) { // if blog_id supplied, use that - if( @BitBase::verifyId( $_REQUEST['post_id'] ) ) { + if( BitBase::verifyId( $_REQUEST['post_id'] ?? 0 ) ) { $gContent = new BitBlogPost( $_REQUEST['post_id'] ); $gContent->load(); - } elseif( @BitBase::verifyId( $_REQUEST['content_id'] ) ) { - $gContent = new BitBlogPost( NULL, $_REQUEST['content_id'] ); + } elseif( BitBase::verifyId( $_REQUEST['content_id'] ?? 0 ) ) { + $gContent = new BitBlogPost( null, $_REQUEST['content_id'] ); $gContent->load(); } else { $gContent = new BitBlogPost(); } - $gBitSmarty->assignByRef( 'gContent', $gContent ); -} -?> + $gBitSmarty->assign( 'gContent', $gContent ); +}
\ No newline at end of file |
