Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,54 +12,61 @@
|
||||
namespace IPS\blog\modules\front\blogs;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use IPS\blog\Blog;
|
||||
use IPS\blog\Blog\Table;
|
||||
use IPS\blog\Category;
|
||||
use IPS\blog\Entry;
|
||||
use IPS\Content\Filter;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* browse
|
||||
*/
|
||||
class _browse extends \IPS\Dispatcher\Controller
|
||||
class browse extends Controller
|
||||
{
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
/* Category */
|
||||
try
|
||||
{
|
||||
$category = \IPS\blog\Category::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
$category = Category::loadAndCheckPerms( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
$category = NULL;
|
||||
}
|
||||
|
||||
/* Featured stuff */
|
||||
$featured = iterator_to_array( \IPS\blog\Entry::featured( 5, '_rand' ) );
|
||||
$blogs = \IPS\blog\Blog::loadByOwner( \IPS\Member::loggedIn(), array( array( 'blog_disabled=?', 0 ) ) );
|
||||
|
||||
if ( ! \IPS\Settings::i()->blog_allow_grid )
|
||||
{
|
||||
$viewMode = 'list';
|
||||
}
|
||||
else
|
||||
{
|
||||
$viewMode = ( isset( \IPS\Request::i()->view ) ) ? \IPS\Request::i()->view : ( isset( \IPS\Request::i()->cookie['blog_view'] ) ? \IPS\Request::i()->cookie['blog_view'] : \IPS\Settings::i()->blog_view_mode );
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->view ) )
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
\IPS\Request::i()->setCookie( 'blog_view', \IPS\Request::i()->view, ( new \IPS\DateTime )->add( new \DateInterval( 'P1Y' ) ) );
|
||||
$featured = iterator_to_array( Entry::featured( 5, '_rand' ) );
|
||||
$blogs = Blog::loadByOwner( Member::loggedIn(), array( array( 'blog_disabled=?', 0 ) ) );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=blog', 'front', 'blogs' ) );
|
||||
}
|
||||
$viewMode = Member::loggedIn()->getLayoutValue( 'blog_view' );
|
||||
|
||||
/* Grid view */
|
||||
if ( $viewMode == 'grid' )
|
||||
@@ -67,9 +74,9 @@ class _browse extends \IPS\Dispatcher\Controller
|
||||
$perpage = 23;
|
||||
$page = 1;
|
||||
|
||||
if ( \IPS\Request::i()->page )
|
||||
if ( Request::i()->page )
|
||||
{
|
||||
$page = \intval( \IPS\Request::i()->page );
|
||||
$page = intval( Request::i()->page );
|
||||
if ( !$page OR $page < 1 )
|
||||
{
|
||||
$page = 1;
|
||||
@@ -80,7 +87,7 @@ class _browse extends \IPS\Dispatcher\Controller
|
||||
|
||||
$where = array();
|
||||
$where[] = array( "blog_entries.entry_status!=?", 'draft' );
|
||||
if ( !\IPS\Settings::i()->club_nodes_in_apps )
|
||||
if ( !Settings::i()->club_nodes_in_apps )
|
||||
{
|
||||
$where[] = array( "blog_blogs.blog_club_id IS NULL" );
|
||||
}
|
||||
@@ -88,8 +95,8 @@ class _browse extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$where[] = array( 'blog_blogs.blog_category_id=?', $category->_id );
|
||||
}
|
||||
$count = \IPS\blog\Entry::getItemsWithPermission( $where, 'entry_date desc', NULL, 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, TRUE, FALSE, FALSE, TRUE );
|
||||
$entries = \IPS\blog\Entry::getItemsWithPermission( $where, 'entry_date desc', array( ( $perpage * ( $page - 1 ) ), $perpage ), 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, TRUE );
|
||||
$count = Entry::getItemsWithPermission( $where, 'entry_date desc', NULL, 'read', Filter::FILTER_AUTOMATIC, 0, NULL, TRUE, FALSE, FALSE, TRUE );
|
||||
$entries = Entry::getItemsWithPermission( $where, 'entry_date desc', array( ( $perpage * ( $page - 1 ) ), $perpage ), 'read', Filter::FILTER_AUTOMATIC, 0, NULL, TRUE );
|
||||
|
||||
/* Validate Pagination */
|
||||
$totalPages = ceil( $count / $perpage );
|
||||
@@ -102,67 +109,68 @@ class _browse extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
}
|
||||
|
||||
$queryString = 'app=blog&module=blogs&controller=browse';
|
||||
$queryString = 'app=blog&module=blogs&controller=browse';
|
||||
if( $category )
|
||||
{
|
||||
$queryString .= '&id=' . $category->_id;
|
||||
}
|
||||
$paginationUrl = \IPS\Http\Url::internal( $queryString, 'front', ( $category ) ? 'blog_category' : 'blogs' );
|
||||
$paginationUrl = Url::internal( $queryString, 'front', ( $category ) ? 'blog_category' : 'blogs' );
|
||||
|
||||
if( $redirect )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $paginationUrl->setPage('page', 1 ), NULL, 303 );
|
||||
Output::i()->redirect( $paginationUrl->setPage('page', 1 ), NULL, 303 );
|
||||
}
|
||||
|
||||
$pagination = array(
|
||||
'page' => $page,
|
||||
'pages' => $totalPages,
|
||||
'perpage' => $perpage,
|
||||
'url' => $paginationUrl
|
||||
);
|
||||
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'grid.css', 'blog', 'front' ) );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'browse' )->indexGrid( $entries, $featured, $blogs, $pagination, $viewMode, $category );
|
||||
|
||||
Output::i()->output = Theme::i()->getTemplate( 'browse' )->indexGrid( $entries, $featured, $blogs, $pagination, $viewMode, $category );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Blogs table */
|
||||
$table = new \IPS\blog\Blog\Table( \IPS\Http\Url::internal( 'app=blog&module=blogs&controller=browse', 'front', 'blogs' ) );
|
||||
$table = new Table( Url::internal( 'app=blog&module=blogs&controller=browse', 'front', 'blogs' ) );
|
||||
if( $category )
|
||||
{
|
||||
$table->where[] = array( 'blog_category_id=?', $category->_id );
|
||||
}
|
||||
$table->title = 'our_community_blogs';
|
||||
$table->classes = array( 'cBlogList', 'ipsAreaBackground', 'ipsDataList_large' );
|
||||
$table->classes = array( 'cBlogList', 'ipsBlogData' );
|
||||
|
||||
/* Filters */
|
||||
$table->filters = array(
|
||||
'my_blogs' => array( '(' . \IPS\Db::i()->findInSet( 'blog_groupblog_ids', \IPS\Member::loggedIn()->groups ) . ' OR ' . 'blog_member_id=? )', \IPS\Member::loggedIn()->member_id ),
|
||||
'my_blogs' => array( '(' . Db::i()->findInSet( 'blog_groupblog_ids', Member::loggedIn()->groups ) . ' OR ' . 'blog_member_id=? )', Member::loggedIn()->member_id ),
|
||||
'blogs_with_content' => array( 'blog_count_entries>0' )
|
||||
);
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'browse' )->index( $table, $featured, $blogs, $viewMode, $category );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'browse' )->index( $table, $featured, $blogs, $viewMode, $category );
|
||||
}
|
||||
|
||||
\IPS\Session::i()->setLocation( \IPS\Http\Url::internal( 'app=blog', 'front', 'blogs' ), array(), 'loc_blog_viewing_index' );
|
||||
Session::i()->setLocation( Url::internal( 'app=blog', 'front', 'blogs' ), array(), 'loc_blog_viewing_index' );
|
||||
|
||||
/* Display */
|
||||
if( \count( \IPS\blog\Category::roots() ) > 1 )
|
||||
if( count( Category::roots() ) > 1 )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['contextual'] = \IPS\Theme::i()->getTemplate( 'browse' )->categories( $category );
|
||||
Output::i()->sidebar['contextual'] = Theme::i()->getTemplate( 'browse' )->categories( $category );
|
||||
}
|
||||
|
||||
if( $category )
|
||||
{
|
||||
foreach( $category->parents() as $parent )
|
||||
{
|
||||
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
}
|
||||
\IPS\Output::i()->breadcrumb[] = array( $category->url(), $category->_title );
|
||||
Output::i()->breadcrumb[] = array( $category->url(), $category->_title );
|
||||
|
||||
/* Set default search option */
|
||||
\IPS\Output::i()->defaultSearchOption = array( 'blog_entry', 'blog_entry_pl' );
|
||||
Output::i()->defaultSearchOption = array( 'blog_entry', 'blog_entry_pl' );
|
||||
}
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_browse.js', 'blog', 'front' ) );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('blogs');
|
||||
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'front_browse.js', 'blog', 'front' ) );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('blogs');
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user