Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+5 -5
View File
@@ -12,7 +12,7 @@
namespace IPS\blog\api;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -27,7 +27,7 @@ class _blogs extends \IPS\Node\Api\NodeController
/**
* Class
*/
protected $class = 'IPS\blogs\Blog';
protected $class = 'IPS\blog\Blog';
/**
* GET /blog/blogs
@@ -65,7 +65,7 @@ class _blogs extends \IPS\Node\Api\NodeController
/* Pinned */
if ( isset( \IPS\Request::i()->pinned ) )
{
$where[] = array( 'blog_pinned=?', intval( \IPS\Request::i()->pinned ) );
$where[] = array( 'blog_pinned=?', \intval( \IPS\Request::i()->pinned ) );
}
/* Permission */
@@ -75,7 +75,7 @@ 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( \IPS\Request::i()->sortBy ) and \in_array( \IPS\Request::i()->sortBy, array( 'count_entries', 'last_edate' ) ) )
{
$sortBy = 'blog_' . \IPS\Request::i()->sortBy;
}
@@ -83,7 +83,7 @@ class _blogs extends \IPS\Node\Api\NodeController
{
$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( \IPS\Request::i()->sortDir ) and \in_array( mb_strtolower( \IPS\Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortDir : 'asc';
/* Return */
return new \IPS\Api\PaginatedResponse(
+167
View File
@@ -0,0 +1,167 @@
<?php
/**
* @brief Blog Categories API
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Blog
* @since 4 Sep 2019
*/
namespace IPS\blog\api;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief Blog Blogs API
*/
class _categories extends \IPS\Node\Api\NodeController
{
/**
* Class
*/
protected $class = 'IPS\blog\Category';
/**
* GET /blog/categories
* Get list of blog categories
*
* @apiparam string sortBy What to sort by. Can be 'count_entries' for number of entries, 'last_edate' for last entry date or do not specify for ID
* @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>
*/
public function GETindex()
{
/* Where clause */
$where = array();
/* Sort */
if ( isset( \IPS\Request::i()->sortBy ) and \in_array( \IPS\Request::i()->sortBy, array( 'position' ) ) )
{
$sortBy = 'category_' . \IPS\Request::i()->sortBy;
}
else
{
$sortBy = 'category_id';
}
$sortDir = ( isset( \IPS\Request::i()->sortDir ) and \in_array( mb_strtolower( \IPS\Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortDir : 'asc';
/* Return */
return new \IPS\Api\PaginatedResponse(
200,
\IPS\Db::i()->select( '*', 'blog_categories', $where, "{$sortBy} {$sortDir}" ),
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
'IPS\blog\Category',
\IPS\Db::i()->select( 'COUNT(*)', 'blog_categories', $where )->first(),
$this->member,
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
);
}
/**
* GET /blog/categories/{id}
* Get information about a specific blog category
*
* @param int $id ID Number
* @return \IPS\blog\Blog
*/
public function GETitem( $id )
{
return $this->_view( $id );
}
/**
* POST /blog/categories
* Create a blog category
*
* @apiclientonly
* @reqapiparam string name The category name
* @apiparam int|null parent The ID number of the parent the category should be created in. NULL for root.
* @apiparam int position The category position
* @return \IPS\blog\Category
* @throws 1B408/1 NO_TITLE A name for the category must be supplied
*/
public function POSTindex()
{
if ( !\IPS\Request::i()->name )
{
throw new \IPS\Api\Exception( 'NO_TITLE', '1B408/1', 400 );
}
return new \IPS\Api\Response( 201, $this->_create()->apiOutput( $this->member ) );
}
/**
* POST /blog/categories/{id}
* Edit a blog category
*
* @apiclientonly
* @reqapiparam string name The category name
* @apiparam int|null parent The ID number of the parent the category should be created in. NULL for root.
* @apiparam int position The category position
* @param int $id ID Number
* @return \IPS\blog\Category
*/
public function POSTitem( $id )
{
$class = $this->class;
$category = $class::load( $id );
return new \IPS\Api\Response( 200, $this->_createOrUpdate( $category )->apiOutput( $this->member ) );
}
/**
* DELETE /blog/categories/{id}
* Delete a blog category
*
* @apiclientonly
* @param int $id ID Number
* @return void
* @throws 2B408/3 INVALID_ID The blog category ID does not exist or the authorized user does not have permission to delete it
*/
public function DELETEitem( $id )
{
$class = $this->class;
try
{
$category = $class::load( $id );
$category->delete();
return new \IPS\Api\Response( 200, NULL );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B408/3', 404 );
}
}
/**
* Create or update node
*
* @param \IPS\Node\Model $category The node
* @return \IPS\Node\Model
*/
protected function _createOrUpdate( \IPS\Node\Model $category )
{
if ( isset( \IPS\Request::i()->name ) )
{
\IPS\Lang::saveCustom( 'blog', "blog_category_{$category->id}", \IPS\Request::i()->name );
$category->seo_name = \IPS\Http\Url\Friendly::seoTitle( \IPS\Request::i()->name );
}
$category->parent = (int) \IPS\Request::i()->parent?: \IPS\blog\Category::$databaseColumnParentRootValue;
return parent::_createOrUpdate( $category );
}
}
+3 -3
View File
@@ -12,7 +12,7 @@
namespace IPS\blog\api;
/* To prentry PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -98,7 +98,7 @@ class _comments extends \IPS\Content\Api\CommentController
* POST /blog/comments
* Create a comment
*
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, hidden will only be honoured if the authentictaed user has permission to hide content).
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, hidden will only be honoured if the authenticated user has permission to hide content).
* @reqapiparam int entry The ID number of the entry the comment is for
* @reqapiparam int author The ID number of the member making the comment (0 for guest). Required for requests made using an API Key or the Client Credentials Grant Type. For requests using an OAuth Access Token for a particular member, that member will always be the author
* @apiparam string author_name If author is 0, the guest name that should be used
@@ -164,7 +164,7 @@ class _comments extends \IPS\Content\Api\CommentController
* POST /blog/comments/{id}
* Edit a comment
*
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, hidden will only be honoured if the authentictaed user has permission to hide content).
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, hidden will only be honoured if the authenticated user has permission to hide content).
* @param int $id ID Number
* @apiparam int author The ID number of the member making the comment (0 for guest). Ignored for requests using an OAuth Access Token for a particular member.
* @apiparam string author_name If author is 0, the guest name that should be used
+25 -6
View File
@@ -12,7 +12,7 @@
namespace IPS\blog\api;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -40,7 +40,7 @@ class _entries extends \IPS\Content\Api\ItemController
* @apiparam int pinned If 1, only entries which are pinned are returned, if 0 only not pinned
* @apiparam int featured If 1, only entries which are featured are returned, if 0 only not featured
* @apiparam int draft If 1, only draft entries are returned, if 0 only published
* @apiparam string sortBy What to sort by. Can be 'date' for creation date, 'title' or leave unspecified for ID
* @apiparam string sortBy What to sort by. Can be 'date' for creation date, 'title', 'updated' or leave unspecified for ID
* @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
@@ -111,7 +111,7 @@ class _entries extends \IPS\Content\Api\ItemController
* POST /blog/entries
* Create an entry
*
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, locked will only be honoured if the authentictaed user has permission to lock topics).
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, locked will only be honoured if the authenticated user has permission to lock topics).
* @reqapiparam int blog The ID number of the blog the entry should be created in
* @reqapiparam int author The ID number of the member creating the entry (0 for guest). Required for requests made using an API Key or the Client Credentials Grant Type. For requests using an OAuth Access Token for a particular member, that member will always be the author
* @reqapiparam string title The entry title
@@ -125,6 +125,11 @@ class _entries extends \IPS\Content\Api\ItemController
* @apiparam int hidden 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
* @apiparam int pinned 1/0 indicating if the entry should be pinned
* @apiparam int featured 1/0 indicating if the entry should be featured
* @apiparam int category The blog entry category
* @apiparam string poll_title Poll title (to create a poll)
* @apiparam bool poll_public Make the poll public
* @apiparam bool poll_only Make this a poll-only topic
* @apiparam array poll_options Array of objects with keys 'title' (string), 'answers' (array of objects with key 'value' set to the choice) and 'multichoice' (bool)
* @throws 1B300/2 NO_BLOG The blog ID does not exist
* @throws 1B300/3 NO_AUTHOR The author ID does not exist
* @throws 1B300/4 NO_TITLE No title was supplied
@@ -133,7 +138,7 @@ class _entries extends \IPS\Content\Api\ItemController
* @return \IPS\blog\Entry
*/
public function POSTindex()
{
{
/* Get blog */
try
{
@@ -187,7 +192,7 @@ class _entries extends \IPS\Content\Api\ItemController
* POST /blog/entries/{id}
* Edit a blog entry
*
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, locked will only be honoured if the authentictaed user has permission to lock topics).
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, locked will only be honoured if the authenticated user has permission to lock topics).
* @reqapiparam int blog The ID number of the blog the entry should be created in
* @reqapiparam int author The ID number of the member creating the entry (0 for guest). Ignored for requests using an OAuth Access Token for a particular member.
* @reqapiparam string title The entry title
@@ -195,12 +200,17 @@ class _entries extends \IPS\Content\Api\ItemController
* @apiparam bool draft If this is a draft
* @apiparam string prefix Prefix tag
* @apiparam string tags Comma-separated list of tags (do not include prefix)
* @apiparam datetime date The date/time that should be used for the entry date. If not provided, will use the current date/time. Ignored for requests using an OAuth Access Token for a particular member.
* @apiparam string ip_address The IP address that should be stored for the entry/post. If not provided, will use the IP address from the API request. Ignored for requests using an OAuth Access Token for a particular member.
* @apiparam int locked 1/0 indicating if the entry should be locked
* @apiparam int hidden 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
* @apiparam int pinned 1/0 indicating if the entry should be pinned
* @apiparam int featured 1/0 indicating if the entry should be featured
* @apiparam int category The blog entry category
* @apiparam string poll_title Poll title (to create a poll)
* @apiparam bool poll_public Make the poll public
* @apiparam bool poll_only Make this a poll-only topic
* @apiparam array poll_options Array of objects with keys 'title' (string), 'answers' (array of objects with key 'value' set to the choice) and 'multichoice' (bool)
* @param int $id ID Number
* @throws 2B300/6 INVALID_ID The entry ID is invalid or the authorized user does not have permission to view it
* @throws 1B300/7 NO_BLOG The blog ID does not exist or the authorized user does not have permission to post in it
* @throws 1B300/8 NO_AUTHOR The author ID does not exist
@@ -297,6 +307,15 @@ class _entries extends \IPS\Content\Api\ItemController
}
$item->content = $entryContents;
}
/* Do we have a poll to attach? */
$this->_createOrUpdatePoll( $item, $type );
/* Category */
if ( isset( \IPS\Request::i()->category ) )
{
$item->category_id = \IPS\Request::i()->category;
}
/* Pass up */
return parent::_createOrUpdate( $item, $type );
+118
View File
@@ -0,0 +1,118 @@
<?php
/**
* @brief Blog Entry Category API
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Blog
* @since 4 Sep 2019
*/
namespace IPS\blog\api;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief Blog Categories API
*/
class _entrycategories extends \IPS\Node\Api\NodeController
{
/**
* Class
*/
protected $class = 'IPS\blog\Entry\Category';
/**
* GET /blog/entrycategories
* Get list of entry categories
*
* @apiparam int blog ID of blog. Null for all.
* @apiparam string sortBy What to sort by. Can be 'position' for category position or do not specify for ID
* @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\Category>
*/
public function GETindex()
{
/* Where clause */
$where = array();
/* Blog */
if ( isset( \IPS\Request::i()->blog ) )
{
$where[] = array( 'entry_category_blog_id=?', \intval( \IPS\Request::i()->blog ) );
}
/* Sort */
if ( isset( \IPS\Request::i()->sortBy ) and \in_array( \IPS\Request::i()->sortBy, array( 'position' ) ) )
{
$sortBy = 'entry_category_' . \IPS\Request::i()->sortBy;
}
else
{
$sortBy = 'entry_category_id';
}
$sortDir = ( isset( \IPS\Request::i()->sortDir ) and \in_array( mb_strtolower( \IPS\Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortDir : 'asc';
/* Return */
return new \IPS\Api\PaginatedResponse(
200,
\IPS\Db::i()->select( '*', 'blog_entry_categories', $where, "{$sortBy} {$sortDir}" ),
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
'IPS\blog\Entry\Category',
\IPS\Db::i()->select( 'COUNT(*)', 'blog_entry_categories', $where )->first(),
$this->member,
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
);
}
/**
* GET /blog/entrycategories/{id}
* Get information about a specific entry category
*
* @param int $id ID Number
* @return \IPS\blog\Entry\Category
*/
public function GETitem( $id )
{
return $this->_view( $id );
}
/**
* DELETE /blog/entrycategories/{id}
* Delete an entry category
*
* @param int $id ID Number
* @return void
* @throws 2B408/5 INVALID_ID The category ID does not exist or the authorized user does not have permission to delete it
*/
public function DELETEitem( $id )
{
$class = $this->class;
try
{
$category = $class::load( $id );
if ( !$category->canDelete( $this->member ) )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B408/5', 404 );
}
$category->delete();
return new \IPS\Api\Response( 200, NULL );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2B408/6', 404 );
}
}
}
View File
Whitespace-only changes.