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,64 +12,66 @@
|
||||
namespace IPS\forums\widgets;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Db;
|
||||
use IPS\forums\Topic\ArchivedPost;
|
||||
use IPS\Settings;
|
||||
use IPS\Widget\StaticCache;
|
||||
use function defined;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* forumStatistics Widget
|
||||
*/
|
||||
class _forumStatistics extends \IPS\Widget\StaticCache
|
||||
class forumStatistics extends StaticCache
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'forumStatistics';
|
||||
public string $key = 'forumStatistics';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'forums';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
public string $app = 'forums';
|
||||
|
||||
/**
|
||||
* @brief Cache Expiration - 24h
|
||||
*/
|
||||
public $cacheExpiration = 86400;
|
||||
public int $cacheExpiration = 86400;
|
||||
|
||||
/**
|
||||
* Render a widget
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
public function render(): string
|
||||
{
|
||||
$stats = array();
|
||||
|
||||
$approxRows = \IPS\Db::i()->query( "SHOW TABLE STATUS LIKE '" . \IPS\Db::i()->prefix . "forums_posts';" )->fetch_assoc();
|
||||
$approxRows = Db::i()->query( "SHOW TABLE STATUS LIKE '" . Db::i()->prefix . "forums_posts';" )->fetch_assoc();
|
||||
|
||||
if( (int) $approxRows['Rows'] >= 1000000 )
|
||||
{
|
||||
$stats['total_posts'] = \IPS\Db::i()->select( 'SUM(posts)', 'forums_forums' )->first();
|
||||
$stats['total_posts'] = Db::i()->select( 'SUM(posts)', 'forums_forums' )->first();
|
||||
}
|
||||
else
|
||||
{
|
||||
$stats['total_posts'] = \IPS\Db::i()->select( "COUNT(*)", 'forums_posts', array( 'queued = ?', 0 ) )->first();
|
||||
$stats['total_posts'] = Db::i()->select( "COUNT(*)", 'forums_posts', array( 'queued = ?', 0 ) )->first();
|
||||
}
|
||||
|
||||
/* Only query if we're not using the cached forums count, the cached count includes these */
|
||||
if ( (int) $approxRows['Rows'] <= 1000000 AND \IPS\Settings::i()->archive_on )
|
||||
if ( (int) $approxRows['Rows'] <= 1000000 AND Settings::i()->archive_on )
|
||||
{
|
||||
$stats['total_posts'] += \IPS\forums\Topic\ArchivedPost::db()->select( 'COUNT(*)', 'forums_archive_posts', array( 'archive_queued = ?', 0 ) )->first();
|
||||
$stats['total_posts'] += ArchivedPost::db()->select( 'COUNT(*)', 'forums_archive_posts', array( 'archive_queued = ?', 0 ) )->first();
|
||||
}
|
||||
|
||||
$stats['total_topics'] = \IPS\Db::i()->select( "COUNT(*)", 'forums_topics', array( 'approved = ?', 1 ) )->first();
|
||||
$stats['total_topics'] = Db::i()->select( "COUNT(*)", 'forums_topics', array( 'approved = ?', 1 ) )->first();
|
||||
|
||||
return $this->output( $stats );
|
||||
}
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief hotTopics Widget
|
||||
* @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 Forums
|
||||
* @since 2 Sep 2014
|
||||
*/
|
||||
|
||||
namespace IPS\forums\widgets;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* hotTopics Widget
|
||||
*/
|
||||
class _hotTopics extends \IPS\Widget\PermissionCache
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'hotTopics';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'forums';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
|
||||
/**
|
||||
* Specify widget configuration
|
||||
*
|
||||
* @param null|\IPS\Helpers\Form $form Form object
|
||||
* @return \IPS\Helpers\Form
|
||||
*/
|
||||
public function configuration( &$form=null )
|
||||
{
|
||||
$form = parent::configuration( $form );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'number_to_show', isset( $this->configuration['number_to_show'] ) ? $this->configuration['number_to_show'] : 5, TRUE ) );
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is executable by app?
|
||||
*
|
||||
* @param string|array $app Application key (core,cms,gallery, etc)
|
||||
* @return boolean
|
||||
*/
|
||||
public function isExecutableByApp( $app )
|
||||
{
|
||||
/* Kill this widget on cloud, it's meaningless */
|
||||
if( \IPS\CIC )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::isExecutableByApp( $app );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a widget
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
/* Kill this widget on cloud, it's meaningless */
|
||||
if( \IPS\CIC )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
$topics = \IPS\forums\Topic::getItemsWithPermission( array( array( 'popular_time > ? AND forums_forums.password IS NULL AND forums_forums.can_view_others=1', time() ) ), NULL, isset( $this->configuration['number_to_show'] ) ? $this->configuration['number_to_show'] : 5, 'read', \IPS\Content\Hideable::FILTER_PUBLIC_ONLY );
|
||||
if ( \count( $topics ) )
|
||||
{
|
||||
return $this->output( $topics );
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,43 +12,48 @@
|
||||
namespace IPS\forums\widgets;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DomainException;
|
||||
use Exception;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Item;
|
||||
use IPS\Theme;
|
||||
use IPS\Widget;
|
||||
use function defined;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* poll Widget
|
||||
*/
|
||||
class _poll extends \IPS\Widget
|
||||
class poll extends Widget
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'poll';
|
||||
public string $key = 'poll';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'forums';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
public string $app = 'forums';
|
||||
|
||||
/**
|
||||
* Specify widget configuration
|
||||
*
|
||||
* @param null|\IPS\Helpers\Form $form Form object
|
||||
* @return null|\IPS\Helpers\Form
|
||||
* @param null|Form $form Form object
|
||||
* @return Form
|
||||
*/
|
||||
public function configuration( &$form=null )
|
||||
public function configuration( Form &$form=null ): Form
|
||||
{
|
||||
$form = parent::configuration( $form );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Item( 'widget_poll_tid', ( isset( $this->configuration['widget_poll_tid'] ) ? $this->configuration['widget_poll_tid'] : NULL ), TRUE, array(
|
||||
$form->add( new Item( 'widget_poll_tid', ( $this->configuration['widget_poll_tid'] ?? NULL ), TRUE, array(
|
||||
'class' => '\IPS\forums\Topic',
|
||||
'maxItems' => 1,
|
||||
'where' => array( array( '(poll_state<>0 AND poll_state IS NOT NULL)' ) )
|
||||
@@ -60,7 +65,7 @@ class _poll extends \IPS\Widget
|
||||
if ( $poll === NULL )
|
||||
{
|
||||
/* poll_state is set to something other than 0 or NULL, but the poll doesn't exist, so let the user know. */
|
||||
throw new \DomainException( 'poll_widget_no_poll' );
|
||||
throw new DomainException( 'poll_widget_no_poll' );
|
||||
}
|
||||
}
|
||||
} ) );
|
||||
@@ -74,7 +79,7 @@ class _poll extends \IPS\Widget
|
||||
* @param array $values Values from form
|
||||
* @return array
|
||||
*/
|
||||
public function preConfig( $values )
|
||||
public function preConfig( array $values ): array
|
||||
{
|
||||
$item = array_pop( $values['widget_poll_tid'] );
|
||||
$values['widget_poll_tid'] = $item->tid;
|
||||
@@ -86,7 +91,7 @@ class _poll extends \IPS\Widget
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
public function render(): string
|
||||
{
|
||||
if ( empty( $this->configuration['widget_poll_tid'] ) )
|
||||
{
|
||||
@@ -95,12 +100,12 @@ class _poll extends \IPS\Widget
|
||||
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( $this->configuration['widget_poll_tid'] );
|
||||
$topic = Topic::loadAndCheckPerms( $this->configuration['widget_poll_tid'] );
|
||||
$poll = $topic->getPoll();
|
||||
|
||||
if ( $poll )
|
||||
{
|
||||
$poll->displayTemplate = array( \IPS\Theme::i()->getTemplate( 'widgets', 'forums', 'front' ), 'pollWidget' );
|
||||
$poll->displayTemplate = array( Theme::i()->getTemplate( 'widgets', 'forums', 'front' ), 'pollWidget' );
|
||||
$poll->url = $topic->url();
|
||||
|
||||
return $this->output( $topic, $poll );
|
||||
@@ -110,7 +115,7 @@ class _poll extends \IPS\Widget
|
||||
return '';
|
||||
}
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
catch( Exception $ex )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Topic Feed Widget
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
@@ -12,55 +13,62 @@
|
||||
namespace IPS\forums\widgets;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Content\WidgetComment;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\forums\Topic\Post;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use function count;
|
||||
use function defined;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* postFeed Widget
|
||||
*/
|
||||
class _postFeed extends \IPS\Content\WidgetComment
|
||||
class postFeed extends WidgetComment
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'postFeed';
|
||||
public string $key = 'postFeed';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'forums';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
|
||||
public string $app = 'forums';
|
||||
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected static $class = 'IPS\forums\Topic\Post';
|
||||
protected static string $class = 'IPS\forums\Topic\Post';
|
||||
|
||||
/**
|
||||
* @brief Moderator permission to generate caches on [optional]
|
||||
*/
|
||||
protected $moderatorPermissions = array( 'can_view_hidden_content', 'can_view_hidden_post' );
|
||||
protected array $moderatorPermissions = array( 'can_view_hidden_content', 'can_view_hidden_post' );
|
||||
|
||||
/**
|
||||
* Return the form elements to use
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function formElements()
|
||||
protected function formElements(): array
|
||||
{
|
||||
$elements = parent::formElements();
|
||||
|
||||
/* @var Post $class */
|
||||
$class = static::$class;
|
||||
|
||||
/* @var Topic $itemClass */
|
||||
$itemClass = $class::$itemClass;
|
||||
|
||||
$elements['container'] = new \IPS\Helpers\Form\Node( 'widget_feed_container_' . $itemClass::$title, isset( $this->configuration['widget_feed_container'] ) ? $this->configuration['widget_feed_container'] : 0, FALSE, array(
|
||||
$elements['container'] = new Node( 'widget_feed_container_' . $itemClass::$title, $this->configuration['widget_feed_container'] ?? 0, FALSE, array(
|
||||
'class' => $itemClass::$containerNodeClass,
|
||||
'zeroVal' => 'all_public',
|
||||
'permissionCheck' => function ( $forum )
|
||||
@@ -80,17 +88,22 @@ class _postFeed extends \IPS\Content\WidgetComment
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function buildWhere()
|
||||
protected function buildWhere(): array
|
||||
{
|
||||
$class = static::$class;
|
||||
|
||||
/* @var Post $class */
|
||||
$itemClass = $class::$itemClass;
|
||||
|
||||
/* @var Topic $itemClass */
|
||||
/* @var Forum $containerClass */
|
||||
$containerClass = $itemClass::$containerNodeClass;
|
||||
$where = parent::buildWhere();
|
||||
if ( !isset( $this->configuration['widget_feed_use_perms'] ) or $this->configuration['widget_feed_use_perms'] )
|
||||
{
|
||||
if ( $customNodes = $containerClass::customPermissionNodes() )
|
||||
{
|
||||
if ( \count( $customNodes['password'] ) )
|
||||
if ( count( $customNodes['password'] ) )
|
||||
{
|
||||
$where['container'][] = array('forums_forums.password IS NULL AND forums_forums.can_view_others=1');
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Topic Feed Widget
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
@@ -12,49 +13,54 @@
|
||||
namespace IPS\forums\widgets;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Content\Widget;
|
||||
use IPS\Db;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use function count;
|
||||
use function defined;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* latestTopics Widget
|
||||
*/
|
||||
class _topicFeed extends \IPS\Content\Widget
|
||||
class topicFeed extends Widget
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'topicFeed';
|
||||
public string $key = 'topicFeed';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'forums';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
|
||||
public string $app = 'forums';
|
||||
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected static $class = 'IPS\forums\Topic';
|
||||
protected static string $class = 'IPS\forums\Topic';
|
||||
|
||||
/**
|
||||
* Return the form elements to use
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function formElements()
|
||||
protected function formElements(): array
|
||||
{
|
||||
$elements = parent::formElements();
|
||||
|
||||
/* @var Topic $class */
|
||||
$class = static::$class;
|
||||
|
||||
$elements['container'] = new \IPS\Helpers\Form\Node( 'widget_feed_container_' . $class::$title, isset( $this->configuration['widget_feed_container'] ) ? $this->configuration['widget_feed_container'] : 0, FALSE, array(
|
||||
$elements['container'] = new Node( 'widget_feed_container_' . $class::$title, $this->configuration['widget_feed_container'] ?? 0, FALSE, array(
|
||||
'class' => $class::$containerNodeClass,
|
||||
'zeroVal' => 'all_public',
|
||||
'permissionCheck' => function ( $forum )
|
||||
@@ -74,16 +80,18 @@ class _topicFeed extends \IPS\Content\Widget
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function buildWhere()
|
||||
protected function buildWhere(): array
|
||||
{
|
||||
/* @var Topic $class */
|
||||
$class = static::$class;
|
||||
/* @var Forum $containerClass */
|
||||
$containerClass = $class::$containerNodeClass;
|
||||
$where = parent::buildWhere();
|
||||
if ( !isset( $this->configuration['widget_feed_use_perms'] ) or $this->configuration['widget_feed_use_perms'] )
|
||||
{
|
||||
if ( $customNodes = $containerClass::customPermissionNodes() )
|
||||
{
|
||||
if ( \count( $customNodes['password'] ) )
|
||||
if ( count( $customNodes['password'] ) )
|
||||
{
|
||||
$where['container'][] = array('forums_forums.password IS NULL AND forums_forums.can_view_others=1');
|
||||
}
|
||||
@@ -96,7 +104,7 @@ class _topicFeed extends \IPS\Content\Widget
|
||||
|
||||
if ( isset( $this->configuration['widget_feed_status_solved'] ) and $this->configuration['widget_feed_status_solved'] == 'unsolved' and empty( $this->configuration['widget_feed_container'] ) )
|
||||
{
|
||||
$where['container'][] = array( '( (' . \IPS\Db::i()->bitwiseWhere( \IPS\forums\Forum::$bitOptions['forums_bitoptions'], 'bw_enable_answers' ) . ') OR ( ' . \IPS\Db::i()->bitwiseWhere( \IPS\forums\Forum::$bitOptions['forums_bitoptions'], 'bw_enable_answers_moderator' ) . ' ) )' );
|
||||
$where['container'][] = array( '(' . Db::i()->bitwiseWhere( Forum::$bitOptions['forums_bitoptions'], 'bw_solved_set_by_moderator' ) . ' )' );
|
||||
}
|
||||
|
||||
return $where;
|
||||
|
||||
Reference in new issue
Block a user