Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+49 -31
View File
@@ -1,4 +1,5 @@
<?php
/**
* @brief Blog Blogs API
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
@@ -12,22 +13,35 @@
namespace IPS\blog\api;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Api\Exception;
use IPS\Api\PaginatedResponse;
use IPS\Api\Response;
use IPS\blog\Blog;
use IPS\Db;
use IPS\Node\Api\NodeController;
use IPS\Request;
use OutOfRangeException;
use function defined;
use function in_array;
use function intval;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief Blog Blogs API
*/
class _blogs extends \IPS\Node\Api\NodeController
class blogs extends NodeController
{
/**
* Class
*/
protected $class = 'IPS\blog\Blog';
protected string $class = 'IPS\blog\Blog';
/**
* GET /blog/blogs
@@ -42,31 +56,32 @@ class _blogs extends \IPS\Node\Api\NodeController
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @apiparam int page Page number
* @apiparam int perPage Number of results per page - defaults to 25
* @return \IPS\Api\PaginatedResponse<IPS\blog\Entry>
* @apireturn PaginatedResponse<\IPS\blog\Blog>
* @return PaginatedResponse<Blog>
*/
public function GETindex()
public function GETindex(): PaginatedResponse
{
/* Where clause */
$where = $this->_globalWhere();
/* Owners */
if ( isset( \IPS\Request::i()->owners ) and isset( \IPS\Request::i()->groups ) )
if ( isset( Request::i()->owners ) and isset( Request::i()->groups ) )
{
$where[] = array( '( ' . \IPS\Db::i()->in( 'blog_member_id', array_filter( explode( ',', \IPS\Request::i()->owners ) ) ) . ' OR ' . \IPS\Db::i()->findInSet( 'blog_groupblog_ids', array_filter( explode( ',', \IPS\Request::i()->groups ) ) ) . ' )' );
$where[] = array( '( ' . Db::i()->in( 'blog_member_id', array_filter( explode( ',', Request::i()->owners ) ) ) . ' OR ' . Db::i()->findInSet( 'blog_groupblog_ids', array_filter( explode( ',', Request::i()->groups ) ) ) . ' )' );
}
elseif ( isset( \IPS\Request::i()->owners ) )
elseif ( isset( Request::i()->owners ) )
{
$where[] = array( '( ' . \IPS\Db::i()->in( 'blog_member_id', array_filter( explode( ',', \IPS\Request::i()->owners ) ) ) . ' OR blog_groupblog_ids<>? )', '' );
$where[] = array( '( ' . Db::i()->in( 'blog_member_id', array_filter( explode( ',', Request::i()->owners ) ) ) . ' OR blog_groupblog_ids<>? )', '' );
}
elseif ( isset( \IPS\Request::i()->groups ) )
elseif ( isset( Request::i()->groups ) )
{
$where[] = array( '( blog_member_id>0 OR ' . \IPS\Db::i()->findInSet( 'blog_groupblog_ids', array_filter( explode( ',', \IPS\Request::i()->groups ) ) ) . ' )' );
$where[] = array( '( blog_member_id>0 OR ' . Db::i()->findInSet( 'blog_groupblog_ids', array_filter( explode( ',', Request::i()->groups ) ) ) . ' )' );
}
/* Pinned */
if ( isset( \IPS\Request::i()->pinned ) )
if ( isset( Request::i()->pinned ) )
{
$where[] = array( 'blog_pinned=?', \intval( \IPS\Request::i()->pinned ) );
$where[] = array( 'blog_pinned=?', intval( Request::i()->pinned ) );
}
/* Permission */
@@ -76,25 +91,25 @@ class _blogs extends \IPS\Node\Api\NodeController
}
/* Sort */
if ( isset( \IPS\Request::i()->sortBy ) and \in_array( \IPS\Request::i()->sortBy, array( 'count_entries', 'last_edate' ) ) )
if ( isset( Request::i()->sortBy ) and in_array( Request::i()->sortBy, array( 'count_entries', 'last_edate' ) ) )
{
$sortBy = 'blog_' . \IPS\Request::i()->sortBy;
$sortBy = 'blog_' . Request::i()->sortBy;
}
else
{
$sortBy = 'blog_id';
}
$sortDir = ( isset( \IPS\Request::i()->sortDir ) and \in_array( mb_strtolower( \IPS\Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortDir : 'asc';
$sortDir = ( isset( Request::i()->sortDir ) and in_array( mb_strtolower( Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? Request::i()->sortDir : 'asc';
/* Return */
return new \IPS\Api\PaginatedResponse(
return new PaginatedResponse(
200,
\IPS\Db::i()->select( '*', 'blog_blogs', $where, "{$sortBy} {$sortDir}" ),
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
Db::i()->select( '*', 'blog_blogs', $where, "{$sortBy} {$sortDir}" ),
isset( Request::i()->page ) ? Request::i()->page : 1,
'IPS\blog\Blog',
\IPS\Db::i()->select( 'COUNT(*)', 'blog_blogs', $where )->first(),
Db::i()->select( 'COUNT(*)', 'blog_blogs', $where )->first(),
$this->member,
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
isset( Request::i()->perPage ) ? Request::i()->perPage : NULL
);
}
@@ -104,9 +119,10 @@ class _blogs extends \IPS\Node\Api\NodeController
*
* @param int $id ID Number
* @throws 2B302/1 INVALID_ID The blog ID does not exist or the authorized user does not have permission to view it
* @return \IPS\blog\Blog
* @apireturn \IPS\blog\Blog
* @return Response
*/
public function GETitem( $id )
public function GETitem( int $id ): Response
{
return $this->_view( $id );
}
@@ -116,28 +132,30 @@ class _blogs extends \IPS\Node\Api\NodeController
* Delete a blog
*
* @param int $id ID Number
* @return void
* @apireturn void
* @return Response
* @throws 2B302/2 INVALID_ID The blog ID does not exist or the authorized user does not have permission to view it
* @throws 2B302/3 NO_PERMISSION The authorized user does not have permission to delete the blog
*/
public function DELETEitem( $id )
public function DELETEitem( int $id ): Response
{
/* @var Blog $class */
$class = $this->class;
try
{
$blog = $this->member ? $class::loadAndCheckPerms( $id ) : $class::load( $id );
if ( !$blog->canDelete( $this->member ) )
if ( !$blog->canDelete() )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B302/3', 404 );
throw new Exception( 'INVALID_ID', '2B302/3', 404 );
}
$blog->delete();
return new \IPS\Api\Response( 200, NULL );
return new Response( 200, NULL );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B302/2', 404 );
throw new Exception( 'INVALID_ID', '2B302/2', 404 );
}
}
}