Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief forums
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Board
|
||||
* @since 07 Jan 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\forums\modules\admin\forums;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* forums
|
||||
*/
|
||||
class _forums extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\forums\Forum';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'forums_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Permissions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function permissions()
|
||||
{
|
||||
try
|
||||
{
|
||||
$forum = \IPS\forums\Forum::load( \IPS\Request::i()->id );
|
||||
|
||||
if ( $forum->min_posts_view )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['perm_forum_perm__view'] = \IPS\Member::loggedIn()->language()->addToStack( 'perm_forum_perm__view_rest', FALSE, array( 'pluralize' => array( $forum->min_posts_view ) ) );
|
||||
}
|
||||
|
||||
if ( $forum->forums_bitoptions['bw_enable_answers'] )
|
||||
{
|
||||
if ( $forum->password and !$forum->can_view_others )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['perm_forum_perm__read'] = \IPS\Member::loggedIn()->language()->addToStack( 'perm_forum_perm__read2_qa_pass', FALSE );
|
||||
}
|
||||
elseif ( !$forum->can_view_others )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['perm_forum_perm__read'] = \IPS\Member::loggedIn()->language()->addToStack( 'perm_forum_perm__read2_qa', FALSE );
|
||||
}
|
||||
elseif ( $forum->password )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['perm_forum_perm__read'] = \IPS\Member::loggedIn()->language()->addToStack( 'perm_forum_perm__read_qa_pass', FALSE );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['perm_forum_perm__read'] = \IPS\Member::loggedIn()->language()->addToStack( 'perm_forum_perm__read_qa', FALSE );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $forum->password and !$forum->can_view_others )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['perm_forum_perm__read'] = \IPS\Member::loggedIn()->language()->addToStack( 'perm_forum_perm__read2_pass', FALSE );
|
||||
}
|
||||
elseif ( !$forum->can_view_others )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['perm_forum_perm__read'] = \IPS\Member::loggedIn()->language()->addToStack( 'perm_forum_perm__read2', FALSE );
|
||||
}
|
||||
elseif ( $forum->password )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['perm_forum_perm__read'] = \IPS\Member::loggedIn()->language()->addToStack( 'perm_forum_perm__read_pass', FALSE );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $forum->forums_bitoptions['bw_enable_answers'] )
|
||||
{
|
||||
if ( $forum->min_posts_post )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['perm_forum_perm__add'] = \IPS\Member::loggedIn()->language()->addToStack('perm_forum_perm__add_qa_rest', FALSE, array( 'pluralize' => array( $forum->min_posts_post ) ) );
|
||||
\IPS\Member::loggedIn()->language()->words['perm_forum_perm__reply'] = \IPS\Member::loggedIn()->language()->addToStack('perm_forum_perm__reply_qa_rest', FALSE, array( 'pluralize' => array( $forum->min_posts_post ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['perm_forum_perm__add'] = \IPS\Member::loggedIn()->language()->addToStack( 'perm_forum_perm__add_qa', FALSE, array( 'pluralize' => array( $forum->min_posts_post ) ) );
|
||||
\IPS\Member::loggedIn()->language()->words['perm_forum_perm__reply'] = \IPS\Member::loggedIn()->language()->addToStack( 'perm_forum_perm__reply_qa', FALSE, array( 'pluralize' => array( $forum->min_posts_post ) ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $forum->min_posts_post )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['perm_forum_perm__add'] = \IPS\Member::loggedIn()->language()->addToStack( 'perm_forum_perm__add_rest', FALSE, array( 'pluralize' => array( $forum->min_posts_post ) ) );
|
||||
\IPS\Member::loggedIn()->language()->words['perm_forum_perm__reply'] = \IPS\Member::loggedIn()->language()->addToStack( 'perm_forum_perm__reply_rest', FALSE, array( 'pluralize' => array( $forum->min_posts_post ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) {}
|
||||
|
||||
return parent::permissions();
|
||||
}
|
||||
|
||||
|
||||
protected function form()
|
||||
{
|
||||
parent::form();
|
||||
|
||||
if ( \IPS\Request::i()->id )
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('edit_forum') . ': ' . \IPS\Output::i()->title;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('add_forum');
|
||||
}
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Feeds
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Board
|
||||
* @since 04 Feb 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\forums\modules\admin\forums;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* rss
|
||||
*/
|
||||
class _rss extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'rss_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = '\IPS\forums\Feed';
|
||||
|
||||
/**
|
||||
* Get Root Buttons
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _getRootButtons()
|
||||
{
|
||||
$buttons = parent::_getRootButtons();
|
||||
|
||||
if ( isset( $buttons['add'] ) )
|
||||
{
|
||||
$buttons['add']['link'] = $buttons['add']['link']->setQueryString( '_new', TRUE );
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add/Edit Form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
$nodeClass = $this->nodeClass;
|
||||
if ( !\IPS\Request::i()->id and $nodeClass::canAddRoot() )
|
||||
{
|
||||
\IPS\Output::i()->output = new \IPS\Helpers\Wizard( array(
|
||||
'rss_import_url' => function( $data )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'rss_import_url', NULL, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'rss_import_auth_user' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Password( 'rss_import_auth_pass' ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = $values['rss_import_url']->request();
|
||||
|
||||
if ( $values['rss_import_auth_user'] or $values['rss_import_auth_pass'] )
|
||||
{
|
||||
$request = $request->login( $values['rss_import_auth_user'], $values['rss_import_auth_pass'] );
|
||||
}
|
||||
|
||||
$response = $request->get();
|
||||
|
||||
if ( $response->httpResponseCode == 401 )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack( 'rss_import_auth' );
|
||||
return $form;
|
||||
}
|
||||
|
||||
$response = $response->decodeXml();
|
||||
if ( !( $response instanceof \IPS\Xml\Rss ) and !( $response instanceof \IPS\Xml\Atom ) )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack( 'rss_import_invalid' );
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack( 'form_url_bad' );
|
||||
return $form;
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack( 'rss_import_invalid' );
|
||||
return $form;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
return $form;
|
||||
},
|
||||
'rss_import_preview' => function( $data )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->continue ) )
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
$request = \IPS\Http\Url::external( $data['rss_import_url'] )->request();
|
||||
if ( $data['rss_import_auth_user'] or $data['rss_import_auth_pass'] )
|
||||
{
|
||||
$request = $request->login( $data['rss_import_auth_user'], $data['rss_import_auth_pass'] );
|
||||
}
|
||||
return \IPS\Theme::i()->getTemplate( 'feeds' )->importPreview( $request->get()->decodeXml()->articles() );
|
||||
},
|
||||
'rss_import_details' => function ( $data )
|
||||
{
|
||||
$request = \IPS\Http\Url::external( $data['rss_import_url'] )->request();
|
||||
if ( $data['rss_import_auth_user'] or $data['rss_import_auth_pass'] )
|
||||
{
|
||||
$request = $request->login( $data['rss_import_auth_user'], $data['rss_import_auth_pass'] );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'rss_import_forum_id', NULL, TRUE, array( 'class' => 'IPS\forums\Forum', 'permissionCheck' => function ( $forum )
|
||||
{
|
||||
return $forum->sub_can_post and !$forum->redirect_url;
|
||||
} ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Member( 'rss_import_mid', \IPS\Member::loggedIn(), TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'rss_import_showlink', \IPS\Member::loggedIn()->language()->addToStack('rss_import_showlink_default') ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'rss_import_topic_open', NULL, FALSE, array( 'options' => array( 1 => 'unlocked', 0 => 'locked' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'rss_import_topic_hide', NULL, FALSE, array( 'options' => array( 0 => 'unhidden', 1 => 'hidden' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'rss_import_topic_pre', NULL, FALSE, array( 'trim' => FALSE ) ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$import = new \IPS\forums\Feed;
|
||||
$import->enabled = TRUE;
|
||||
$import->title = $request->get()->decodeXml()->title();
|
||||
$import->url = (string) $data['rss_import_url'];
|
||||
$import->forum_id = $values['rss_import_forum_id']->_id;
|
||||
$import->mid = $values['rss_import_mid']->member_id;
|
||||
$import->pergo = 10;
|
||||
$import->time = 30;
|
||||
$import->showlink = $values['rss_import_showlink'];
|
||||
$import->topic_open = $values['rss_import_topic_open'];
|
||||
$import->topic_hide = $values['rss_import_topic_hide'];
|
||||
$import->topic_pre = $values['rss_import_topic_pre'];
|
||||
$import->auth = ( $data['rss_import_auth_user'] or $data['rss_import_auth_pass'] );
|
||||
$import->auth_user = ( $data['rss_import_auth_user'] or $data['rss_import_auth_pass'] ) ? $data['rss_import_auth_user'] : NULL;
|
||||
$import->auth_pass = ( $data['rss_import_auth_user'] or $data['rss_import_auth_pass'] ) ? $data['rss_import_auth_pass'] : NULL;
|
||||
$import->save();
|
||||
try
|
||||
{
|
||||
$import->run();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'rss_run_error', '3F181/3', 500, '' );
|
||||
}
|
||||
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 1 ), array( '`key`=?', 'rssimport' ) );
|
||||
\IPS\Session::i()->log( 'acplog__node_created', array( (string) $import->title => TRUE, (string) $import->title => FALSE ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=forums&module=forums&controller=rss' ) );
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
), \IPS\Http\Url::internal('app=forums&module=forums&controller=rss&do=form') );
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::form();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'rss_run' );
|
||||
|
||||
try
|
||||
{
|
||||
$feed = \IPS\forums\Feed::load( \IPS\Request::i()->id );
|
||||
$feed->run();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2F181/1', 404, '' );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'rss_run_error', '3F181/2', 500, '' );
|
||||
}
|
||||
|
||||
\IPS\Session::i()->log( 'acplog__rss_ran', array( $feed->title => FALSE ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=forums&module=forums&controller=rss' ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief savedActions
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Board
|
||||
* @since 30 Jan 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\forums\modules\admin\forums;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* savedActions
|
||||
*/
|
||||
class _savedActions extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\forums\SavedAction';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'savedActions_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,593 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Settings
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Board
|
||||
* @since 20 Jan 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\forums\modules\admin\forums;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* settings
|
||||
*/
|
||||
class _settings extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Manage Settings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'settings_access' );
|
||||
|
||||
$tabs = array();
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction('forum_settings') )
|
||||
{
|
||||
$tabs['settings'] = 'forum_settings';
|
||||
}
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction('archive_manage') )
|
||||
{
|
||||
$tabs['archiving'] = 'archiving';
|
||||
}
|
||||
|
||||
$activeTab = \IPS\Request::i()->tab ?: 'settings';
|
||||
$activeTabContents = call_user_func( array( $this, 'manage' . ucfirst( $activeTab ) ) );
|
||||
|
||||
if( \IPS\Request::i()->isAjax() and !isset( \IPS\Request::i()->ajaxValidate ) )
|
||||
{
|
||||
\IPS\Output::i()->output = $activeTabContents;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__forums_forums_settings');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, $activeTabContents, \IPS\Http\Url::internal( "app=forums&module=forums&controller=settings" ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Archive settings
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function manageArchiving()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'archive_manage' );
|
||||
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_settings.js', 'forums', 'admin' ) );
|
||||
|
||||
/* Init */
|
||||
$maxTopics = \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics' )->first();
|
||||
$existingRules = iterator_to_array( \IPS\Db::i()->select( '*', 'forums_archive_rules' ) );
|
||||
$existingCount = \IPS\Settings::i()->archive_on ? \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics', array_merge( array( array( 'topic_archive_status!=?', \IPS\forums\Topic::ARCHIVE_EXCLUDE ) ), \IPS\Application::load('forums')->archiveWhere( $existingRules ) ) )->first() : 0;
|
||||
|
||||
/* Work out existing values */
|
||||
$existingValues = array();
|
||||
foreach ( $existingRules as $rule )
|
||||
{
|
||||
switch ( $rule['archive_field'] )
|
||||
{
|
||||
case 'lastpost':
|
||||
if ( $rule['archive_skip'] )
|
||||
{
|
||||
$existingValues['archive_not_last_post'] = array( $rule['archive_value'], $rule['archive_text'], $rule['archive_unit'], FALSE );
|
||||
}
|
||||
else
|
||||
{
|
||||
$existingValues['archive_last_post'] = array( $rule['archive_value'], $rule['archive_text'], $rule['archive_unit'], FALSE );
|
||||
}
|
||||
break;
|
||||
|
||||
case 'forum':
|
||||
if ( $rule['archive_value'] == '+' )
|
||||
{
|
||||
$existingValues['archive_topic_forums'] = explode( ',', $rule['archive_text'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$existingValues['archive_topic_not_forums'] = explode( ',', $rule['archive_text'] );
|
||||
}
|
||||
break;
|
||||
|
||||
case 'pinned':
|
||||
case 'featured':
|
||||
case 'state':
|
||||
case 'approved':
|
||||
case 'poll':
|
||||
$existingValues[ "archive_topic_{$rule['archive_field']}" ] = array( $rule['archive_value'] );
|
||||
break;
|
||||
|
||||
case 'post':
|
||||
case 'view':
|
||||
case 'rating':
|
||||
if ( $rule['archive_skip'] )
|
||||
{
|
||||
$existingValues[ "archive_not_topic_{$rule['archive_field']}" ] = array( $rule['archive_value'], $rule['archive_text'], FALSE );
|
||||
}
|
||||
else
|
||||
{
|
||||
$existingValues[ "archive_topic_{$rule['archive_field']}" ] = array( $rule['archive_value'], $rule['archive_text'], FALSE );
|
||||
}
|
||||
break;
|
||||
|
||||
case 'member':
|
||||
if ( $rule['archive_value'] == '+' )
|
||||
{
|
||||
$members = array();
|
||||
foreach( explode( ',', $rule['archive_text'] ) AS $v )
|
||||
{
|
||||
$members[] = \IPS\Member::load( $v )->name;
|
||||
}
|
||||
|
||||
$existingValues['archive_topic_starter'] = implode( ',', $members );
|
||||
}
|
||||
else
|
||||
{
|
||||
$members = array();
|
||||
foreach( explode( ',', $rule['archive_text'] ) AS $v )
|
||||
{
|
||||
$members[] = \IPS\Member::load( $v )->name;
|
||||
}
|
||||
|
||||
$existingValues['archive_topic_starter_not'] = implode( ',', $members );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Build Form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->attributes['id'] = 'elArchiveForm';
|
||||
$form->addHeader( 'archive_settings' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'archive_on', \IPS\Settings::i()->archive_on, FALSE, array(
|
||||
'togglesOn' => array(
|
||||
'archive_storage_location',
|
||||
'archive_last_post',
|
||||
'archive_topic_forums',
|
||||
'archive_topic_pinned',
|
||||
'archive_topic_featured',
|
||||
'archive_topic_state',
|
||||
'archive_topic_approved',
|
||||
'archive_topic_poll',
|
||||
'archive_topic_post',
|
||||
'archive_topic_view',
|
||||
'archive_topic_rating',
|
||||
'archive_topic_starter',
|
||||
'archive_topic_not_forums',
|
||||
'archive_not_topic_post',
|
||||
'archive_not_topic_view',
|
||||
'archive_not_topic_rating',
|
||||
'archive_not_last_post',
|
||||
'archive_topic_starter_not',
|
||||
'form_header_archive_topics_where',
|
||||
'form_header_archive_topics_not_where'
|
||||
),
|
||||
) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'archive_storage_location', \IPS\Settings::i()->archive_remote_sql_host ? 'remote' : 'local', FALSE, array(
|
||||
'options' => array( 'local' => 'archive_storage_location_local', 'remote' => 'archive_storage_location_remote' ),
|
||||
'toggles' => array( 'remote' => array( 'archive_sql_host', 'archive_sql_user', 'archive_sql_pass', 'archive_sql_database', 'archive_sql_port', 'archive_sql_socket', 'archive_sql_tbl_prefix' ) )
|
||||
), NULL, NULL, NULL, 'archive_storage_location' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'archive_remote_sql_host', \IPS\Settings::i()->archive_remote_sql_host ?: ini_get('mysqli.default_host') ?: 'localhost', FALSE, array(), NULL, NULL, NULL, 'archive_sql_host' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'archive_remote_sql_user', \IPS\Settings::i()->archive_remote_sql_user ?: ini_get('mysqli.default_user'), FALSE, array(), NULL, NULL, NULL, 'archive_sql_user' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'archive_remote_sql_pass', \IPS\Settings::i()->archive_remote_sql_pass ?: ini_get('mysqli.default_pw'), FALSE, array(), NULL, NULL, NULL, 'archive_sql_pass' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'archive_remote_sql_database', \IPS\Settings::i()->archive_remote_sql_database ?: NULL, FALSE, array(), NULL, NULL, NULL, 'archive_sql_database' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'archive_sql_port', \IPS\Settings::i()->archive_sql_port ?: ini_get('mysqli.default_port'), FALSE, array(), NULL, NULL, NULL, 'archive_sql_port' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'archive_sql_socket', \IPS\Settings::i()->archive_sql_socket ?: ini_get('mysqli.default_socket'), FALSE, array(), NULL, NULL, NULL, 'archive_sql_socket' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'archive_sql_tbl_prefix', \IPS\Settings::i()->archive_sql_tbl_prefix ?: NULL, FALSE, array(), NULL, NULL, NULL, 'archive_sql_tbl_prefix' ) );
|
||||
|
||||
$form->addHeader( 'archive_topics_where' );
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'archive_last_post', isset( $existingValues['archive_last_post'] ) ? $existingValues['archive_last_post'] : array( '>', 0, 'm', TRUE ), FALSE, array( 'getHtml' => array( $this, '_beforeAfterTimeAgo' ), 'validate' => array( $this, '_validateBeforeAfterTimeAgo' ) ), NULL, NULL, NULL, 'archive_last_post' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'archive_topic_forums', isset( $existingValues['archive_topic_forums'] ) ? $existingValues['archive_topic_forums'] : 0, FALSE, array( 'class' => 'IPS\forums\Forum', 'zeroVal' => 'any', 'multiple' => TRUE, 'permissionCheck' => function ( $forum )
|
||||
{
|
||||
return $forum->sub_can_post and !$forum->redirect_url;
|
||||
} ), NULL, NULL, NULL, 'archive_topic_forums' ) );
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'archive_topic_pinned', isset( $existingValues['archive_topic_pinned'] ) ? $existingValues['archive_topic_pinned'] : array( 1, 0 ), FALSE, array( 'options' => array( 1 => 'pinned', 0 => 'mod_confirm_unpin' ) ), NULL, NULL, NULL, 'archive_topic_pinned' ) );
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'archive_topic_featured', isset( $existingValues['archive_topic_featured'] ) ? $existingValues['archive_topic_featured'] : array( 1, 0 ), FALSE, array( 'options' => array( 1 => 'featured', 0 => 'mod_confirm_unfeature' ) ), NULL, NULL, NULL, 'archive_topic_featured' ) );
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'archive_topic_state', isset( $existingValues['archive_topic_state'] ) ? $existingValues['archive_topic_state'] : array( 'closed', 'open' ), FALSE, array( 'options' => array( 'closed' => 'locked', 'open' => 'unlocked' ) ), NULL, NULL, NULL, 'archive_topic_state' ) );
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'archive_topic_approved', isset( $existingValues['archive_topic_approved'] ) ? $existingValues['archive_topic_approved'] : array( -1, 1 ), FALSE, array( 'options' => array( -1 => 'hidden', 1 => 'unhidden' ) ), NULL, NULL, NULL, 'archive_topic_approved' ) );
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'archive_topic_poll', isset( $existingValues['archive_topic_poll'] ) ? $existingValues['archive_topic_poll'] : array( 1, 0 ), FALSE, array( 'options' => array( 1 => 'topic_has_poll', 0 => 'topic_does_not_have_poll' ) ), NULL, NULL, NULL, 'archive_topic_poll' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'archive_topic_post', isset( $existingValues['archive_topic_post'] ) ? $existingValues['archive_topic_post'] : array( NULL, NULL, TRUE ), FALSE, array( 'getHtml' => array( $this, '_greaterThanLessThanField' ) ), NULL, NULL, NULL, 'archive_topic_post' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'archive_topic_view', isset( $existingValues['archive_topic_view'] ) ? $existingValues['archive_topic_view'] : array( NULL, NULL, TRUE ), FALSE, array( 'getHtml' => array( $this, '_greaterThanLessThanField' ) ), NULL, NULL, NULL, 'archive_topic_view' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'archive_topic_rating', isset( $existingValues['archive_topic_rating'] ) ? $existingValues['archive_topic_rating'] : array( NULL, NULL, TRUE ), FALSE, array( 'getHtml' => array( $this, '_greaterThanLessThanField' ) ), NULL, NULL, NULL, 'archive_topic_rating' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Member( 'archive_topic_starter', isset( $existingValues['archive_topic_starter'] ) ? $existingValues['archive_topic_starter'] : array(), FALSE, array( 'multiple' => 999999 ), NULL, NULL, NULL, 'archive_topic_starter' ) );
|
||||
$form->addHeader( 'archive_topics_not_where' );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'archive_topic_not_forums', isset( $existingValues['archive_topic_not_forums'] ) ? $existingValues['archive_topic_not_forums'] : array(), FALSE, array( 'class' => 'IPS\forums\Forum', 'multiple' => TRUE, 'permissionCheck' => function ( $forum )
|
||||
{
|
||||
return $forum->sub_can_post and !$forum->redirect_url;
|
||||
} ), NULL, NULL, NULL, 'archive_topic_not_forums' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'archive_not_topic_post', isset( $existingValues['archive_not_topic_post'] ) ? $existingValues['archive_not_topic_post'] : array( NULL, NULL, TRUE ), FALSE, array( 'getHtml' => array( $this, '_greaterThanLessThanField' ) ), NULL, NULL, NULL, 'archive_not_topic_post' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'archive_not_topic_view', isset( $existingValues['archive_not_topic_view'] ) ? $existingValues['archive_not_topic_view'] : array( NULL, NULL, TRUE ), FALSE, array( 'getHtml' => array( $this, '_greaterThanLessThanField' ) ), NULL, NULL, NULL, 'archive_not_topic_view' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'archive_not_topic_rating', isset( $existingValues['archive_not_topic_rating'] ) ? $existingValues['archive_not_topic_rating'] : array( NULL, NULL, TRUE ), FALSE, array( 'getHtml' => array( $this, '_greaterThanLessThanField' ) ), NULL, NULL, NULL, 'archive_not_topic_rating' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'archive_not_last_post', isset( $existingValues['archive_not_last_post'] ) ? $existingValues['archive_not_last_post'] : array( '>', 0, 'm', TRUE ), FALSE, array( 'getHtml' => array( $this, '_beforeAfterTimeAgo' ), 'validate' => array( $this, '_validateBeforeAfterTimeAgo' ) ), NULL, NULL, NULL, 'archive_not_last_post' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Member( 'archive_topic_starter_not', isset( $existingValues['archive_topic_starter_not'] ) ? $existingValues['archive_topic_starter_not'] : array(), FALSE, array( 'multiple' => 999999 ), NULL, NULL, NULL, 'archive_topic_starter_not' ) );
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Translate into rules */
|
||||
$rules = array();
|
||||
foreach ( $values as $k => $v )
|
||||
{
|
||||
if ( in_array( $k, array( 'archive_last_post' ) ) )
|
||||
{
|
||||
if ( !isset( $v[3] ) or !$v[3] )
|
||||
{
|
||||
$rules[] = array(
|
||||
'archive_key' => md5( "forums_{$k}" ),
|
||||
'archive_app' => 'forums',
|
||||
'archive_field' => 'lastpost',
|
||||
'archive_value' => $v[0],
|
||||
'archive_text' => $v[1],
|
||||
'archive_unit' => $v[2],
|
||||
'archive_skip' => 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
elseif ( in_array( $k, array( 'archive_not_last_post' ) ) )
|
||||
{
|
||||
if ( !isset( $v[3] ) or !$v[3] )
|
||||
{
|
||||
$rules[] = array(
|
||||
'archive_key' => md5( "forums_{$k}" ),
|
||||
'archive_app' => 'forums',
|
||||
'archive_field' => 'lastpost',
|
||||
'archive_value' => $v[0],
|
||||
'archive_text' => $v[1],
|
||||
'archive_unit' => $v[2],
|
||||
'archive_skip' => 1,
|
||||
);
|
||||
}
|
||||
}
|
||||
elseif( in_array( $k, array( 'archive_topic_forums' ) ) )
|
||||
{
|
||||
if ( !empty( $v ) )
|
||||
{
|
||||
$rules[] = array(
|
||||
'archive_key' => md5( "forums_{$k}" ),
|
||||
'archive_app' => 'forums',
|
||||
'archive_field' => 'forum',
|
||||
'archive_value' => '+',
|
||||
'archive_text' => implode( ',', array_keys( $v ) ),
|
||||
'archive_unit' => '',
|
||||
'archive_skip' => 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
elseif( in_array( $k, array( 'archive_topic_not_forums' ) ) )
|
||||
{
|
||||
if ( !empty( $v ) )
|
||||
{
|
||||
$rules[] = array(
|
||||
'archive_key' => md5( "forums_{$k}" ),
|
||||
'archive_app' => 'forums',
|
||||
'archive_field' => 'forum',
|
||||
'archive_value' => '-',
|
||||
'archive_text' => implode( ',', array_keys( $v ) ),
|
||||
'archive_unit' => '',
|
||||
'archive_skip' => 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
elseif ( in_array( $k, array( 'archive_topic_pinned', 'archive_topic_featured', 'archive_topic_state', 'archive_topic_approved', 'archive_topic_poll' ) ) )
|
||||
{
|
||||
if ( !empty( $v ) and count( $v ) == 1 )
|
||||
{
|
||||
$rules[] = array(
|
||||
'archive_key' => md5( "forums_{$k}" ),
|
||||
'archive_app' => 'forums',
|
||||
'archive_field' => mb_substr( $k, 14 ),
|
||||
'archive_value' => array_pop( $v ),
|
||||
'archive_text' => '',
|
||||
'archive_unit' => '',
|
||||
'archive_skip' => 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
elseif( in_array( $k, array( 'archive_topic_post', 'archive_topic_view', 'archive_topic_rating' ) ) )
|
||||
{
|
||||
if ( !isset( $v[2] ) )
|
||||
{
|
||||
$rules[] = array(
|
||||
'archive_key' => md5( "forums_{$k}" ),
|
||||
'archive_app' => 'forums',
|
||||
'archive_field' => mb_substr( $k, 14 ),
|
||||
'archive_value' => $v[0],
|
||||
'archive_text' => $v[1],
|
||||
'archive_unit' => '',
|
||||
'archive_skip' => 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
elseif( in_array( $k, array( 'archive_not_topic_post', 'archive_not_topic_view', 'archive_not_topic_rating' ) ) )
|
||||
{
|
||||
if ( !isset( $v[2] ) )
|
||||
{
|
||||
$rules[] = array(
|
||||
'archive_key' => md5( "forums_{$k}" ),
|
||||
'archive_app' => 'forums',
|
||||
'archive_field' => mb_substr( $k, 18 ),
|
||||
'archive_value' => $v[0],
|
||||
'archive_text' => $v[1],
|
||||
'archive_unit' => '',
|
||||
'archive_skip' => 1,
|
||||
);
|
||||
}
|
||||
}
|
||||
elseif( in_array( $k, array( 'archive_topic_starter' ) ) )
|
||||
{
|
||||
if ( is_array( $v ) )
|
||||
{
|
||||
$ids = array();
|
||||
foreach( $v AS $member )
|
||||
{
|
||||
$ids[] = $member->member_id;
|
||||
}
|
||||
|
||||
$rules[] = array(
|
||||
'archive_key' => md5( "forums_{$k}" ),
|
||||
'archive_app' => 'forums',
|
||||
'archive_field' => 'member',
|
||||
'archive_value' => '+',
|
||||
'archive_text' => implode( ',', $ids ),
|
||||
'archive_unit' => '',
|
||||
'archive_skip' => 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
elseif( in_array( $k, array( 'archive_topic_starter_not' ) ) )
|
||||
{
|
||||
if ( is_array( $v ) )
|
||||
{
|
||||
$ids = array();
|
||||
foreach( $v AS $member )
|
||||
{
|
||||
$ids[] = $member->member_id;
|
||||
}
|
||||
|
||||
$rules[] = array(
|
||||
'archive_key' => md5( "forums_{$k}" ),
|
||||
'archive_app' => 'forums',
|
||||
'archive_field' => 'member',
|
||||
'archive_value' => '-',
|
||||
'archive_text' => implode( ',', $ids ),
|
||||
'archive_unit' => '',
|
||||
'archive_skip' => 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Did we just want a new count? */
|
||||
if ( isset( \IPS\Request::i()->getCount ) )
|
||||
{
|
||||
if ( !$values['archive_on'] )
|
||||
{
|
||||
$count = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$count = \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics', array_merge( array( array( 'topic_archive_status!=?', \IPS\forums\Topic::ARCHIVE_EXCLUDE ) ), \IPS\Application::load('forums')->archiveWhere( $rules ) ) )->first();
|
||||
}
|
||||
\IPS\Output::i()->json( array( 'count' => $count, 'percentage' => ( $maxTopics * $count > 0 ) ? round( 100 / $maxTopics * $count ) : 0 ) );
|
||||
}
|
||||
|
||||
/* No, we're actually saving */
|
||||
else
|
||||
{
|
||||
/* Check remote database */
|
||||
if ( $values['archive_storage_location'] === 'remote' )
|
||||
{
|
||||
try
|
||||
{
|
||||
$remoteDatabase = \IPS\Db::i( 'archive', array(
|
||||
'sql_host' => $values['archive_remote_sql_host'],
|
||||
'sql_user' => $values['archive_remote_sql_user'],
|
||||
'sql_pass' => $values['archive_remote_sql_pass'],
|
||||
'sql_database' => $values['archive_remote_sql_database'],
|
||||
'sql_port' => $values['archive_sql_port'],
|
||||
'sql_socket' => $values['archive_sql_socket'],
|
||||
'sql_tbl_prefix'=> $values['archive_sql_tbl_prefix'],
|
||||
'sql_utf8mb4' => isset( \IPS\Settings::i()->sql_utf8mb4 ) ? \IPS\Settings::i()->sql_utf8mb4 : FALSE
|
||||
) );
|
||||
|
||||
if ( !$remoteDatabase->checkForTable('forums_archive_posts') )
|
||||
{
|
||||
$remoteDatabase->createTable( \IPS\Db::i()->getTableDefinition('forums_archive_posts') );
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack( 'archive_remote_db_error', FALSE, array( 'sprintf' => array( "{$e->getMessage()} ({$e->getCode()})" ) ) );
|
||||
goto showForm; // Dinosaur attack!!!!
|
||||
}
|
||||
}
|
||||
|
||||
/* Save settings */
|
||||
$settingValues = array();
|
||||
foreach ( array( 'archive_on', 'archive_remote_sql_host', 'archive_remote_sql_user', 'archive_remote_sql_user', 'archive_remote_sql_pass', 'archive_remote_sql_database', 'archive_sql_port', 'archive_sql_socket', 'archive_sql_tbl_prefix' ) as $k )
|
||||
{
|
||||
if ( $k !== 'archive_on' and $values['archive_storage_location'] !== 'remote' )
|
||||
{
|
||||
$settingValues[ $k ] = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
$settingValues[ $k ] = $values[ $k ];
|
||||
}
|
||||
}
|
||||
$form->saveAsSettings( $settingValues );
|
||||
|
||||
\IPS\Db::i()->delete( 'forums_archive_rules' );
|
||||
if ( count( $rules ) )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'forums_archive_rules', $rules );
|
||||
}
|
||||
|
||||
/* Do we need to unarchive some? */
|
||||
$whereClause = \IPS\Db::i()->compileWhereClause( \IPS\Application::load('forums')->archiveWhere( $rules ) );
|
||||
$_whereClause = array( 'topic_archive_status=? AND !( ' . $whereClause['clause'] . ')' );
|
||||
$_whereClause[] = \IPS\forums\Topic::ARCHIVE_DONE;
|
||||
foreach ( $whereClause['binds'] as $bind )
|
||||
{
|
||||
$_whereClause[] = $bind;
|
||||
}
|
||||
|
||||
if( $values['archive_on'] )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => (int)$values['archive_on'] ), array( '`key`=?', 'archive' ) );
|
||||
}
|
||||
|
||||
/* Log and redirect */
|
||||
\IPS\Session::i()->log( 'acplogs__archive_settings' );
|
||||
if ( \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics', $values['archive_on'] ? $_whereClause : array( 'topic_archive_status=?', \IPS\forums\Topic::ARCHIVE_DONE ) )->first() )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=forums&module=forums&controller=settings&do=unarchive' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=forums&module=forums&controller=settings&tab=archiving' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display */
|
||||
showForm:
|
||||
return \IPS\Theme::i()->getTemplate( 'settings' )->archiveRules( $form, $maxTopics, $existingCount, ( $maxTopics * $existingCount > 0 ) ? round( 100 / $maxTopics * $existingCount ) : 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Greater/Less Than X or Any
|
||||
*
|
||||
* @param \IPS\Helpers\Form\Custom $field The field
|
||||
* @return string
|
||||
*/
|
||||
public function _greaterThanLessThanField( $field )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'settings' )->archiveRuleGtLt( $field->name, $field->value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Before/After X days/months/years ago
|
||||
*
|
||||
* @param \IPS\Helpers\Form\Custom $field The field
|
||||
* @return string
|
||||
*/
|
||||
public function _beforeAfterTimeAgo( $field )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'settings' )->archiveRuleTime( $field->name, $field->value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Before/After X days/months/years ago
|
||||
*
|
||||
* @param \IPS\Helpers\Form\Custom $field The field
|
||||
* @return string
|
||||
*/
|
||||
public function _validateBeforeAfterTimeAgo( $field )
|
||||
{
|
||||
if ( isset( $field->value[1] ) and $field->value[1] < 0 )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'form_number_min', FALSE, array( 'sprintf' => array( 0 ) ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unarchive topics that no longer match settings?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unarchive()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'archive_manage' );
|
||||
|
||||
if ( isset( \IPS\Request::i()->confirm ) )
|
||||
{
|
||||
if ( \IPS\Settings::i()->archive_on )
|
||||
{
|
||||
$whereClause = \IPS\Db::i()->compileWhereClause( \IPS\Application::load('forums')->archiveWhere( \IPS\Db::i()->select( '*', 'forums_archive_rules' ) ) );
|
||||
$_whereClause = array( 'topic_archive_status=? AND !( ' . $whereClause['clause'] . ')' );
|
||||
$_whereClause[] = \IPS\forums\Topic::ARCHIVE_DONE;
|
||||
foreach ( $whereClause['binds'] as $bind )
|
||||
{
|
||||
$_whereClause[] = $bind;
|
||||
}
|
||||
\IPS\Db::i()->update( 'forums_topics', array( 'topic_archive_status' => \IPS\forums\Topic::ARCHIVE_RESTORE ), $_whereClause );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Db::i()->update( 'forums_topics', array( 'topic_archive_status' => \IPS\forums\Topic::ARCHIVE_RESTORE ), array( 'topic_archive_status=?', \IPS\forums\Topic::ARCHIVE_DONE ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=forums&module=forums&controller=settings&tab=archiving' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->decision( 'uanrchive_settings_change', array(
|
||||
'restore_unmatched_settings' => \IPS\Http\Url::internal( 'app=forums&module=forums&controller=settings&do=unarchive&confirm=1' ),
|
||||
'leave_archived_topics' => \IPS\Http\Url::internal( 'app=forums&module=forums&controller=settings&tab=archiving' ),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function manageSettings()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'forum_settings' );
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->addHeader('forum_settings');
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'forums_rss', \IPS\Settings::i()->forums_rss ) );
|
||||
$form->addHeader('topic_settings');
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'forums_popular_now', json_decode( \IPS\Settings::i()->forums_popular_now, TRUE ), FALSE, array(
|
||||
'getHtml' => function( $obj )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('settings')->popularNow( $obj->name, $obj->value );
|
||||
}
|
||||
) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'forums_posts_per_page', \IPS\Settings::i()->forums_posts_per_page , TRUE, array( 'min' => 2, 'max' => 250 ) ) );
|
||||
$form->addHeader('question_settings');
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'forums_questions_downvote', \IPS\Settings::i()->forums_questions_downvote ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'forums_answers_downvote', \IPS\Settings::i()->forums_answers_downvote ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'forums_new_questions', \IPS\Settings::i()->forums_new_questions, FALSE, array( 'options' => array( '0' => 'forums_new_questions_best', '1' => 'forums_new_questions_any' ) ) ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
if ( isset( $values['forums_popular_now']['never'] ) )
|
||||
{
|
||||
$values['forums_popular_now'] = json_encode( array( 'posts' => 0, 'minutes' => 0 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$values['forums_popular_now'] = json_encode( $values['forums_popular_now'] );
|
||||
}
|
||||
|
||||
$form->saveAsSettings( $values );
|
||||
|
||||
/* Clear guest page caches */
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__forums_settings' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=forums&module=forums&controller=settings&tab=settings' ), 'saved' );
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief posts
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage
|
||||
* @since 18 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\forums\modules\admin\stats;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* posts
|
||||
*/
|
||||
class _posts extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'posts_manage' );
|
||||
|
||||
$chart = new \IPS\Helpers\Chart\Dynamic( \IPS\Http\Url::internal( "app=forums&module=stats&controller=posts" ), 'forums_posts', 'post_date', '', array( 'isStacked' => FALSE ) );
|
||||
$chart->addSeries( \IPS\Member::loggedIn()->language()->addToStack( 'stats_new_posts' ), 'number', 'COUNT(*)', FALSE );
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack( 'stats_posts_title' );
|
||||
$chart->availableTypes = array( 'LineChart', 'ColumnChart', 'BarChart' );
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'menu__forums_stats_posts' );
|
||||
\IPS\Output::i()->output = (string) $chart;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief topics
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage
|
||||
* @since 18 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\forums\modules\admin\stats;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* topics
|
||||
*/
|
||||
class _topics extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'topics_manage' );
|
||||
|
||||
$chart = new \IPS\Helpers\Chart\Dynamic( \IPS\Http\Url::internal( "app=forums&module=stats&controller=topics" ), 'forums_topics', 'start_date', '', array( 'isStacked' => FALSE ) );
|
||||
$chart->addSeries( \IPS\Member::loggedIn()->language()->addToStack( 'stats_new_topics' ), 'number', 'COUNT(*)', FALSE );
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack( 'stats_topics_title' );
|
||||
$chart->availableTypes = array( 'LineChart', 'ColumnChart', 'BarChart' );
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'menu__forums_stats_topics' );
|
||||
\IPS\Output::i()->output = (string) $chart;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Legacy 3.x findpost
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Board
|
||||
* @since 09 Jul 2015
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\forums\modules\front\forums;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy 3.x findpost
|
||||
*/
|
||||
class _findpost extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Route
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\forums\Topic\Post::loadAndCheckPerms( \IPS\Request::i()->pid )->url(), NULL, 301 );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2F284/1', 404, '' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,541 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Forum Index
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Board
|
||||
* @since 08 Jan 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\forums\modules\front\forums;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forum Index
|
||||
*/
|
||||
class _forums extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Route
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
\IPS\forums\Forum::loadIntoMemory();
|
||||
|
||||
$forum = NULL;
|
||||
try
|
||||
{
|
||||
$this->_forum( \IPS\forums\Forum::loadAndCheckPerms( \IPS\Request::i()->id ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2F176/1', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show Forum
|
||||
*
|
||||
* @param \IPS\forums\Forum $forum The forum to show
|
||||
* @return void
|
||||
*/
|
||||
public function _forum( $forum )
|
||||
{
|
||||
/* Password protected */
|
||||
if ( $form = $forum->passwordForm() )
|
||||
{
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forums', 'forums', 'front' ), 'forumPasswordPopup' ) );
|
||||
return;
|
||||
}
|
||||
|
||||
/* We can read? */
|
||||
if ( $forum->sub_can_post and !$forum->permission_showtopic and !$forum->can('read') )
|
||||
{
|
||||
\IPS\Output::i()->error( $forum->errorMessage(), '1F176/3', 403, '' );
|
||||
}
|
||||
|
||||
/* Theme */
|
||||
$forum->setTheme();
|
||||
|
||||
/* Users can see topics posted by other users? */
|
||||
$where = array();
|
||||
if ( !$forum->can_view_others and !\IPS\Member::loggedIn()->modPermission( 'can_read_all_topics' ) )
|
||||
{
|
||||
$where[] = array( 'starter_id = ?', \IPS\Member::loggedIn()->member_id );
|
||||
}
|
||||
|
||||
/* Init table (it won't show anything until after the password check, but it sets navigation and titles) */
|
||||
$table = new \IPS\Helpers\Table\Content( 'IPS\forums\Topic', $forum->url(), $where, $forum, NULL, NULL );
|
||||
$table->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'forums', 'forums', 'front' ), 'forumTable' );
|
||||
$table->classes = array( 'cTopicList' );
|
||||
$table->title = \IPS\Member::loggedIn()->language()->addToStack( ( $forum->forums_bitoptions['bw_enable_answers'] ) ? 'count_questions_in_forum' : 'count_topics_in_forum', FALSE, array( 'pluralize' => array( $forum->topics ) ) );
|
||||
if ( $forum->forums_bitoptions['bw_enable_answers'] )
|
||||
{
|
||||
$table->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'forums', 'forums', 'front' ), 'questionRow' );
|
||||
}
|
||||
else
|
||||
{
|
||||
$table->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'forums', 'forums', 'front' ), 'topicRow' );
|
||||
}
|
||||
$table->hover = TRUE;
|
||||
$table->sortOptions['num_replies'] = $table->sortOptions['num_comments'];
|
||||
unset( $table->sortOptions['num_comments'] );
|
||||
|
||||
/* If there's only one forum we actually don't want the nav */
|
||||
if ( \IPS\forums\Forum::theOnlyForum() )
|
||||
{
|
||||
\IPS\Output::i()->breadcrumb = isset( \IPS\Output::i()->breadcrumb['module'] ) ? array( 'module' => \IPS\Output::i()->breadcrumb['module'] ) : array();
|
||||
}
|
||||
|
||||
/* Redirect? */
|
||||
if ( $forum->redirect_url )
|
||||
{
|
||||
$forum->redirect_hits++;
|
||||
$forum->save();
|
||||
\IPS\Output::i()->redirect( $forum->redirect_url );
|
||||
}
|
||||
|
||||
/* Custom Search */
|
||||
$filterOptions = array(
|
||||
'all' => 'all_topics',
|
||||
'open' => 'open_topics',
|
||||
'popular' => 'popular_now',
|
||||
'poll' => 'poll',
|
||||
'locked' => 'locked_topics',
|
||||
'moved' => 'moved_topics',
|
||||
);
|
||||
$timeFrameOptions = array(
|
||||
'show_all' => 'show_all',
|
||||
'today' => 'today',
|
||||
'last_5_days' => 'last_5_days',
|
||||
'last_7_days' => 'last_7_days',
|
||||
'last_10_days' => 'last_10_days',
|
||||
'last_15_days' => 'last_15_days',
|
||||
'last_20_days' => 'last_20_days',
|
||||
'last_25_days' => 'last_25_days',
|
||||
'last_30_days' => 'last_30_days',
|
||||
'last_60_days' => 'last_60_days',
|
||||
'last_90_days' => 'last_90_days',
|
||||
);
|
||||
|
||||
if ( \IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
$filterOptions['starter'] = $forum->forums_bitoptions['bw_enable_answers'] ? 'questions_i_asked' : 'topics_i_started';
|
||||
$filterOptions['replied'] = $forum->forums_bitoptions['bw_enable_answers'] ? 'questions_i_posted_in' : 'topics_i_posted_in';
|
||||
|
||||
if ( \IPS\Member::loggedIn()->member_id AND \IPS\Member::loggedIn()->last_visit)
|
||||
{
|
||||
$timeFrameOptions['since_last_visit'] = \IPS\Member::loggedIn()->language()->addToStack('since_last_visit', FALSE, array( 'sprintf' => array( \IPS\DateTime::ts( \IPS\Member::loggedIn()->last_visit ) ) ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( $forum->forums_bitoptions['bw_enable_answers'] )
|
||||
{
|
||||
$table->filters = array(
|
||||
'questions_with_best_answers' => 'topic_answered_pid>0',
|
||||
'questions_without_best_answers' => 'topic_answered_pid=0',
|
||||
);
|
||||
}
|
||||
|
||||
/* Are we a moderator? */
|
||||
if( \IPS\forums\Topic::modPermission( 'unhide', NULL, $forum ) )
|
||||
{
|
||||
$filterOptions['queued_topics'] = 'queued_topics';
|
||||
$filterOptions['queued_posts'] = 'queued_posts';
|
||||
}
|
||||
|
||||
$table->advancedSearch = array(
|
||||
'topic_type' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => $filterOptions ) ),
|
||||
'sort_by' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => array(
|
||||
'last_post' => 'last_post',
|
||||
'replies' => 'replies',
|
||||
'views' => 'views',
|
||||
'topic_title' => 'topic_title',
|
||||
'last_poster' => 'last_poster',
|
||||
'topic_started' => 'topic_started',
|
||||
'topic_starter' => $forum->forums_bitoptions['bw_enable_answers'] ? 'question_asker' : 'topic_starter',
|
||||
) )
|
||||
),
|
||||
'sort_direction'=> array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => array(
|
||||
'asc' => 'asc',
|
||||
'desc' => 'desc',
|
||||
) )
|
||||
),
|
||||
'time_frame' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => $timeFrameOptions ) ),
|
||||
);
|
||||
$table->advancedSearchCallback = function( $table, $values )
|
||||
{
|
||||
/* Type */
|
||||
switch ( $values['topic_type'] )
|
||||
{
|
||||
case 'open':
|
||||
$table->where[] = array( 'state=?', 'open' );
|
||||
break;
|
||||
case 'popular':
|
||||
$table->where[] = array( 'popular_time IS NOT NULL AND popular_time>?', time() );
|
||||
break;
|
||||
case 'poll':
|
||||
$table->where[] = 'poll_state<>0';
|
||||
break;
|
||||
case 'locked':
|
||||
$table->where[] = array( 'state=?', 'closed' );
|
||||
break;
|
||||
case 'moved':
|
||||
$table->where[] = array( 'state=?', 'link' );
|
||||
break;
|
||||
case 'starter':
|
||||
$table->where[] = array( 'starter_id=?', \IPS\Member::loggedIn()->member_id );
|
||||
break;
|
||||
case 'replied':
|
||||
$table->joinComments = TRUE;
|
||||
$table->where[] = array( 'forums_posts.author_id=?', \IPS\Member::loggedIn()->member_id );
|
||||
break;
|
||||
case 'answered':
|
||||
$table->where[] = 'topic_answered_pid<>0';
|
||||
break;
|
||||
case 'unanswered':
|
||||
$table->where[] = 'topic_answered_pid=0';
|
||||
break;
|
||||
case 'queued_topics':
|
||||
$table->where[] = 'approved=0';
|
||||
break;
|
||||
case 'queued_posts':
|
||||
$table->where[] = 'topic_queuedposts>0';
|
||||
break;
|
||||
}
|
||||
|
||||
/* Sort */
|
||||
switch ( $values['sort_by'] )
|
||||
{
|
||||
case 'last_post':
|
||||
case 'views':
|
||||
$table->sortBy = $values['sort_by'];
|
||||
break;
|
||||
case 'replies':
|
||||
$table->sortBy = 'posts';
|
||||
break;
|
||||
case 'topic_title':
|
||||
$table->sortBy = 'title';
|
||||
break;
|
||||
case 'last_poster':
|
||||
$table->sortBy = 'last_poster_name';
|
||||
break;
|
||||
case 'topic_started':
|
||||
$table->sortBy = 'start_date';
|
||||
break;
|
||||
case 'topic_starter':
|
||||
$table->sortBy = 'starter_name';
|
||||
break;
|
||||
}
|
||||
$table->sortDirection = $values['sort_direction'];
|
||||
|
||||
/* Cutoff */
|
||||
$days = NULL;
|
||||
switch ( $values['time_frame'] )
|
||||
{
|
||||
case 'today':
|
||||
$days = 1;
|
||||
break;
|
||||
case 'last_5_days':
|
||||
$days = 5;
|
||||
break;
|
||||
case 'last_7_days':
|
||||
$days = 7;
|
||||
break;
|
||||
case 'last_10_days':
|
||||
$days = 10;
|
||||
break;
|
||||
case 'last_15_days':
|
||||
$days = 15;
|
||||
break;
|
||||
case 'last_20_days':
|
||||
$days = 20;
|
||||
break;
|
||||
case 'last_25_days':
|
||||
$days = 25;
|
||||
break;
|
||||
case 'last_30_days':
|
||||
$days = 30;
|
||||
break;
|
||||
case 'last_60_days':
|
||||
$days = 60;
|
||||
break;
|
||||
case 'last_90_days':
|
||||
$days = 90;
|
||||
break;
|
||||
case 'since_last_visit':
|
||||
$table->where[] = array( 'forums_topics.last_post>?', \IPS\Member::loggedIn()->last_visit );
|
||||
break;
|
||||
}
|
||||
if ( $days !== NULL )
|
||||
{
|
||||
$table->where[] = array( 'forums_topics.last_post>?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . $days . 'D' ) ) );
|
||||
}
|
||||
};
|
||||
\IPS\Request::i()->sort_direction = \IPS\Request::i()->sort_direction ?: mb_strtolower( $table->sortDirection );
|
||||
|
||||
/* Saved actions */
|
||||
foreach ( \IPS\forums\SavedAction::actions( $forum ) as $action )
|
||||
{
|
||||
$table->savedActions[ $action->_id ] = $action->_title;
|
||||
}
|
||||
|
||||
/* RSS */
|
||||
if ( \IPS\Settings::i()->forums_rss and $forum->topics )
|
||||
{
|
||||
/* Show the link */
|
||||
$rssUrl = \IPS\Http\Url::internal( "app=forums&module=forums&controller=forums&id={$forum->_id}&rss=1", 'front', 'forums_rss', array( $forum->name_seo ) );
|
||||
if ( $forum->forums_bitoptions['bw_enable_answers'] )
|
||||
{
|
||||
$rssTitle = \IPS\Member::loggedIn()->language()->addToStack( 'forum_rss_title_questions', FALSE, array( 'sprintf' => array( $forum->_title ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$rssTitle = \IPS\Member::loggedIn()->language()->addToStack( 'forum_rss_title_topics', FALSE, array( 'sprintf' => array( $forum->_title ) ) );
|
||||
}
|
||||
\IPS\Output::i()->rssFeeds[ $rssTitle ] = $rssUrl;
|
||||
|
||||
/* Or actually show RSS feed */
|
||||
if ( isset( \IPS\Request::i()->rss ) )
|
||||
{
|
||||
if ( $forum->forums_bitoptions['bw_enable_answers'] )
|
||||
{
|
||||
$rssTitle = sprintf( \IPS\Member::loggedIn()->language()->get( 'forum_rss_title_questions'), \IPS\Member::loggedIn()->language()->get( "forums_forum_{$forum->id}" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$rssTitle = sprintf( \IPS\Member::loggedIn()->language()->get( 'forum_rss_title_topics'), \IPS\Member::loggedIn()->language()->get( "forums_forum_{$forum->id}" ) );
|
||||
}
|
||||
|
||||
$document = \IPS\Xml\Rss::newDocument( $forum->url(), $rssTitle, $rssTitle );
|
||||
|
||||
/* We can't include "moved" links in the RSS feed, as there is no content to include ( $topic->content() results in BadMethodCallException) */
|
||||
$table->where[] = array( 'forums_topics.moved_to IS NULL' );
|
||||
|
||||
foreach ( $table->getRows( array() ) as $topic )
|
||||
{
|
||||
if ( ! $topic->hidden() )
|
||||
{
|
||||
$document->addItem( $topic->title, $topic->url(), $topic->content(), \IPS\DateTime::ts( $topic->last_post ), $topic->tid );
|
||||
}
|
||||
}
|
||||
|
||||
/* @note application/rss+xml is not a registered IANA mime-type so we need to stick with text/xml for RSS */
|
||||
\IPS\Output::i()->sendOutput( $document->asXML(), 200, 'text/xml' );
|
||||
}
|
||||
}
|
||||
|
||||
/* Online User Location */
|
||||
$permissions = $forum->permissions();
|
||||
\IPS\Session::i()->setLocation( $forum->url(), explode( ",", $permissions['perm_view'] ), 'loc_forums_viewing_forum', array( "forums_forum_{$forum->id}" => TRUE ) );
|
||||
|
||||
/* Show Forum */
|
||||
if ( isset( \IPS\Request::i()->advancedSearchForm ) )
|
||||
{
|
||||
\IPS\Output::i()->output = (string) $table;
|
||||
return;
|
||||
}
|
||||
\IPS\Output::i()->contextualSearchOptions[ \IPS\Member::loggedIn()->language()->addToStack( 'search_contextual_item', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( 'forums_sg' ) ) ) ) ] = array( 'type' => 'forums_topic', 'nodes' => $forum->_id );
|
||||
|
||||
$forumOutput = '';
|
||||
|
||||
if ( $forum->forums_bitoptions['bw_enable_answers'] )
|
||||
{
|
||||
$featuredTopic = NULL;
|
||||
|
||||
foreach ( \IPS\forums\Topic::featured( 1, 'RAND()', $forum ) as $featuredTopic )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
$popularQuestions = \IPS\forums\Topic::getItemsWithPermission( array( array( 'forum_id=?', $forum->id ), array( 'start_date>?', \IPS\DateTime::ts( time() - ( 86400 * 30 ) )->getTimestamp() ), array( 'question_rating>0' ) ), 'question_rating DESC', 5 );
|
||||
$newQuestionsWhere = array( array( 'forum_id=?', $forum->id ) );
|
||||
|
||||
if ( !\IPS\Settings::i()->forums_new_questions )
|
||||
{
|
||||
$newQuestionsWhere[] = array( 'topic_answered_pid=0' );
|
||||
}
|
||||
else
|
||||
{
|
||||
$newQuestionsWhere[] = array( '( forums_topics.posts IS NULL OR forums_topics.posts=1 )' );
|
||||
}
|
||||
|
||||
$newQuestions = \IPS\forums\Topic::getItemsWithPermission( $newQuestionsWhere, 'start_date DESC', 5 );
|
||||
$forumOutput = \IPS\Theme::i()->getTemplate( 'forums' )->qaForum( (string) $table, $popularQuestions, $newQuestions, $featuredTopic, $forum );
|
||||
}
|
||||
else if( $forum->sub_can_post )
|
||||
{
|
||||
$forumOutput = (string) $table;
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'forums' )->forumDisplay( $forum, $forumOutput );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Topic
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function add()
|
||||
{
|
||||
if ( !isset( \IPS\Request::i()->id ) )
|
||||
{
|
||||
$this->_selectForum();
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$forum = \IPS\forums\Forum::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
$forum->setTheme();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2F173/2', 403, 'no_module_permission_guest' );
|
||||
}
|
||||
|
||||
if ( $forum->forums_bitoptions['bw_enable_answers'] )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['topic_mainTab'] = \IPS\Member::loggedIn()->language()->addToStack( 'question_mainTab', FALSE );
|
||||
}
|
||||
|
||||
$form = \IPS\forums\Topic::create( $forum );
|
||||
|
||||
$hasModOptions = false;
|
||||
|
||||
if ( \IPS\forums\Topic::modPermission( 'lock', NULL, $forum ) or
|
||||
\IPS\forums\Topic::modPermission( 'pin', NULL, $forum ) or
|
||||
\IPS\forums\Topic::modPermission( 'hide', NULL, $forum ) or
|
||||
\IPS\forums\Topic::modPermission( 'feature', NULL, $forum ) )
|
||||
{
|
||||
$hasModOptions = TRUE;
|
||||
}
|
||||
|
||||
$formTemplate = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'submit', 'forums' ) ), 'createTopicForm' ), $forum, $hasModOptions );
|
||||
|
||||
if ( \IPS\forums\Topic::moderateNewItems( \IPS\Member::loggedIn() ) )
|
||||
{
|
||||
$formTemplate = \IPS\Theme::i()->getTemplate( 'forms', 'core' )->modQueueMessage( \IPS\Member::loggedIn()->warnings( 5, NULL, 'mq' ), \IPS\Member::loggedIn()->mod_posts ) . $formTemplate;
|
||||
}
|
||||
|
||||
$title = $forum->forums_bitoptions['bw_enable_answers'] ? 'ask_new_question' : 'create_new_topic';
|
||||
|
||||
/* Online User Location */
|
||||
$permissions = $forum->permissions();
|
||||
\IPS\Session::i()->setLocation( $forum->url(), explode( ",", $permissions['perm_view'] ), 'loc_forums_creating_topic', array( "forums_forum_{$forum->id}" => TRUE ) );
|
||||
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'submit' )->createTopic( $formTemplate, $forum, $title );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( $title );
|
||||
|
||||
if ( !\IPS\forums\Forum::theOnlyForum() )
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach( $forum->parents() as $parent )
|
||||
{
|
||||
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
\IPS\Output::i()->breadcrumb[] = array( $forum->url(), $forum->_title );
|
||||
}
|
||||
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack( ( $forum->forums_bitoptions['bw_enable_answers'] ) ? 'ask_new_question' : 'create_new_topic' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Category Selector
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function createMenu()
|
||||
{
|
||||
$this->_selectForum();
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark Read
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function markRead()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$forum = \IPS\forums\Forum::load( \IPS\Request::i()->id );
|
||||
$returnTo = $forum;
|
||||
|
||||
if( \IPS\Request::i()->return )
|
||||
{
|
||||
$returnTo = \IPS\forums\Forum::load( \IPS\Request::i()->return );
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->fromForum )
|
||||
{
|
||||
\IPS\forums\Topic::markContainerRead( $forum, NULL, FALSE );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\forums\Topic::markContainerRead( $forum );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( ( \IPS\Request::i()->return OR \IPS\Request::i()->fromForum ) ? $returnTo->url() : \IPS\Http\Url::internal( 'app=forums&module=forums&controller=index', NULL, 'forums' ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2F173/3', 403, 'no_module_permission_guest' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the forum selector for creating a topic outside of specific forum
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _selectForum()
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'select_forum', 'continue' );
|
||||
$form->class = 'ipsForm_vertical ipsForm_noLabels';
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'forum', NULL, TRUE, array(
|
||||
'url' => \IPS\Http\Url::internal( 'app=forums&module=forums&controller=forums&do=createMenu' ),
|
||||
'class' => 'IPS\forums\Forum',
|
||||
'permissionCheck' => function( $node )
|
||||
{
|
||||
if ( $node->can( 'view' ) )
|
||||
{
|
||||
if ( $node->can( 'add' ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
},
|
||||
) ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $values['forum']->url()->setQueryString( 'do', 'add' ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'select_forum' );
|
||||
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack( 'select_forum' ) );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'forums' )->forumSelector( $form );
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief index
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage
|
||||
* @since 28 Jul 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\forums\modules\front\forums;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* index
|
||||
*/
|
||||
class _index extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js('front_browse.js', 'gallery' ) );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js('front_forum.js', 'forums' ) );
|
||||
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Load into memory */
|
||||
\IPS\forums\Forum::loadIntoMemory();
|
||||
|
||||
/* Is there only one forum? */
|
||||
if ( $theOnlyForum = \IPS\forums\Forum::theOnlyForum() )
|
||||
{
|
||||
$controller = new \IPS\forums\modules\front\forums\forums( $this->url );
|
||||
return $controller->_forum( $theOnlyForum );
|
||||
}
|
||||
|
||||
/* Prepare output */
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'global_core.js', 'core', 'global' ) );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'forums' );
|
||||
\IPS\Output::i()->linkTags['canonical'] = (string) \IPS\Http\Url::internal( 'app=forums&module=forums&controller=index', 'front', 'forums' );
|
||||
\IPS\Output::i()->metaTags['og:title'] = \IPS\Settings::i()->board_name;
|
||||
\IPS\Output::i()->metaTags['og:type'] = 'website';
|
||||
\IPS\Output::i()->metaTags['og:url'] = (string) \IPS\Http\Url::internal( 'app=forums&module=forums&controller=index', 'front', 'forums' );
|
||||
|
||||
/* Set Online Location */
|
||||
$permissions = \IPS\Dispatcher::i()->module->permissions();
|
||||
\IPS\Session::i()->setLocation( \IPS\Http\Url::internal( 'app=forums&module=forums&controller=index', 'front', 'forums' ), explode( ',', $permissions['perm_view'] ), 'loc_forums_index' );
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'index' )->index();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,720 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Topic View
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Board
|
||||
* @since 08 Jan 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\forums\modules\front\forums;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Topic View
|
||||
*/
|
||||
class _topic extends \IPS\Content\Controller
|
||||
{
|
||||
/**
|
||||
* [Content\Controller] Class
|
||||
*/
|
||||
protected static $contentModel = 'IPS\forums\Topic';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js('front_topic.js', 'forums' ) );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View Topic
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Load topic */
|
||||
\IPS\forums\Forum::loadIntoMemory();
|
||||
$topic = parent::manage();
|
||||
\IPS\Member::loggedIn()->language()->words['submit_comment'] = \IPS\Member::loggedIn()->language()->addToStack( 'submit_reply', FALSE );
|
||||
|
||||
/* If there's only one forum we actually don't want the nav */
|
||||
if ( \IPS\forums\Forum::theOnlyForum() )
|
||||
{
|
||||
$topicBreadcrumb = array_pop( \IPS\Output::i()->breadcrumb );
|
||||
\IPS\Output::i()->breadcrumb = isset( \IPS\Output::i()->breadcrumb['module'] ) ? array( 'module' => \IPS\Output::i()->breadcrumb['module'] ) : array();
|
||||
\IPS\Output::i()->breadcrumb[] = $topicBreadcrumb;
|
||||
}
|
||||
|
||||
/* If it failed, it might be because we want a password */
|
||||
if ( $topic === NULL )
|
||||
{
|
||||
$forum = NULL;
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::load( \IPS\Request::i()->id );
|
||||
$forum = $topic->container();
|
||||
if ( $forum->can('view') and !$forum->loggedInMemberHasPasswordAccess() )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $forum->url()->setQueryString( 'topic', \IPS\Request::i()->id ) );
|
||||
}
|
||||
|
||||
if ( !$topic->canView() )
|
||||
{
|
||||
\IPS\Output::i()->error( $forum ? $forum->errorMessage() : 'node_error_no_perm', '2F173/H', 403, '' );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
/* Nope, just a generic no access error */
|
||||
\IPS\Output::i()->error( 'node_error', '2F173/1', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/* Legacy findpost redirect */
|
||||
if ( \IPS\Request::i()->findpost )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $topic->url()->setQueryString( array( 'do' => 'findComment', 'comment' => \IPS\Request::i()->findpost ) ), NULL, 301 );
|
||||
}
|
||||
elseif ( \IPS\Request::i()->p )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $topic->url()->setQueryString( array( 'do' => 'findComment', 'comment' => \IPS\Request::i()->p ) ), NULL, 301 );
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->view )
|
||||
{
|
||||
$this->_doViewCheck();
|
||||
}
|
||||
|
||||
/* AJAX hover preview? */
|
||||
if ( \IPS\Request::i()->isAjax() and \IPS\Request::i()->preview )
|
||||
{
|
||||
$firstPost = $topic->comments( 1 );
|
||||
$topicOverview = array( 'firstPost' => array( $topic->isQuestion() ? 'question_mainTab' : 'first_post', $firstPost ) );
|
||||
|
||||
if ( $topic->posts > 1 )
|
||||
{
|
||||
$latestPost = $topic->comments( 1, 0, 'date', 'DESC' );
|
||||
$topicOverview['latestPost'] = array( $topic->isQuestion() ? 'latest_answer' : 'latest_post', $latestPost );
|
||||
|
||||
$timeLastRead = $topic->timeLastRead();
|
||||
if ( $timeLastRead instanceof \IPS\DateTime AND $topic->unread() !== 0 )
|
||||
{
|
||||
$firstUnread = $topic->comments( 1, NULL, 'date', 'asc', NULL, NULL, $timeLastRead );
|
||||
if( $firstUnread instanceof \IPS\forums\Topic\Post AND $firstUnread->date !== $latestPost->date AND $firstUnread->date !== $firstPost->date )
|
||||
{
|
||||
$topicOverview['firstUnread'] = array( 'first_unread_post_hover', $topic->comments( 1, NULL, 'date', 'asc', NULL, NULL, $timeLastRead ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $topic->isQuestion() and $topic->topic_answered_pid )
|
||||
{
|
||||
$topicOverview['bestAnswer'] = array( 'best_answer_post', \IPS\forums\Topic\Post::load( $topic->topic_answered_pid ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'forums' )->topicHover( $topic, $topicOverview ) );
|
||||
return;
|
||||
}
|
||||
|
||||
$topic->container()->setTheme();
|
||||
|
||||
/* Watch for votes */
|
||||
if ( $poll = $topic->getPoll() )
|
||||
{
|
||||
$poll->attach( $topic );
|
||||
}
|
||||
|
||||
/* One for the brits */
|
||||
if ( mb_strpos( $topic->title, base64_decode( 'c3BhbmlzaA==' ) ) !== FALSE and $topic->isQuestion() )
|
||||
{
|
||||
\IPS\Output::i()->output .= base64_decode( 'PCEtLSBOTyBPTkUgRVhQRUNUUyBUSEUgU1BBTklTSCBJTlFVSVNJVElPTiAtLT4=' );
|
||||
}
|
||||
|
||||
/* How are we sorting posts? */
|
||||
$question = NULL;
|
||||
$offset = NULL;
|
||||
$order = 'date';
|
||||
$orderDirection = 'asc';
|
||||
$where = NULL;
|
||||
if( \IPS\forums\Topic::modPermission( 'unhide', NULL, $topic->container() ) AND \IPS\Request::i()->queued_posts )
|
||||
{
|
||||
$where = 'queued=1';
|
||||
$queuedPagesCount = ceil( \IPS\Db::i()->select( 'COUNT(*)', 'forums_posts', array( 'topic_id=? AND queued=1', $topic->id ) )->first() / $topic->getCommentsPerPage() );
|
||||
$pagination = ( $queuedPagesCount > 1 ) ? $topic->commentPagination( array( 'queued_posts', 'sortby' ), 'pagination', $queuedPagesCount ) : NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $topic->isQuestion() )
|
||||
{
|
||||
$question = $topic->comments( 1, 0 );
|
||||
$page = ( isset( \IPS\Request::i()->page ) ) ? intval( \IPS\Request::i()->page ) : 1;
|
||||
|
||||
if( $page < 1 )
|
||||
{
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$offset = ( ( $page - 1 ) * $topic::getCommentsPerPage() ) + 1;
|
||||
|
||||
if ( ( !isset( \IPS\Request::i()->sortby ) or \IPS\Request::i()->sortby != 'date' ) )
|
||||
{
|
||||
if ( $topic->isArchived() )
|
||||
{
|
||||
$order = "archive_is_first desc, archive_bwoptions";
|
||||
$orderDirection = 'desc';
|
||||
}
|
||||
else
|
||||
{
|
||||
$order = "new_topic DESC, post_bwoptions DESC, post_field_int DESC, post_date";
|
||||
$orderDirection = 'ASC';
|
||||
}
|
||||
}
|
||||
}
|
||||
$pagination = ( $topic->commentPageCount() > 1 ) ? $topic->commentPagination( array( 'sortby' ) ) : NULL;
|
||||
}
|
||||
$comments = $topic->comments( NUll, $offset, $order, $orderDirection, NULL, NULL, NULL, $where );
|
||||
$current = current( $comments );
|
||||
reset( $comments );
|
||||
|
||||
if( !count( $comments ) AND !$topic->isQuestion() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_posts_returned', '2F173/L', 404, '' );
|
||||
}
|
||||
|
||||
/* On pages 2 and more, it will show the first post on that page, and that is fine as the title has - Page 2 in it meaning its a different page */
|
||||
$metaDescription = strip_tags( $topic->isQuestion() ? $question->post : $current->post );
|
||||
\IPS\Output::i()->metaTags['description'] = \IPS\Output::i()->metaTags['og:description'] = ( mb_strlen( $metaDescription ) > 160 ? ( mb_substr( $metaDescription, 0, 157 ) . '...' ) : $metaDescription );
|
||||
|
||||
/* Did we request a specific post? If so, reset descriptions. */
|
||||
if( isset( $_SESSION['_findComment'] ) )
|
||||
{
|
||||
$commentId = $_SESSION['_findComment'];
|
||||
unset( $_SESSION['_findComment'] );
|
||||
|
||||
try
|
||||
{
|
||||
$comment = \IPS\forums\Topic\Post::loadAndCheckPerms( $commentId );
|
||||
|
||||
\IPS\Output::i()->metaTags['description'] = \IPS\Output::i()->metaTags['og:description'] = strip_tags( $comment->content() );
|
||||
}
|
||||
catch( \Exception $e ){}
|
||||
}
|
||||
|
||||
/* Mark read */
|
||||
if( !$topic->isLastPage() )
|
||||
{
|
||||
$maxTime = 0;
|
||||
|
||||
foreach( $comments as $comment )
|
||||
{
|
||||
$maxTime = ( $comment->mapped('date') > $maxTime ) ? $comment->mapped('date') : $maxTime;
|
||||
}
|
||||
|
||||
$topic->markRead( NULL, $maxTime );
|
||||
}
|
||||
|
||||
$votes = array();
|
||||
$topicVotes = array();
|
||||
|
||||
/* Get post ratings for this user */
|
||||
if ( $topic->isQuestion() && \IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
$votes = $topic->answerVotes( \IPS\Member::loggedIn() );
|
||||
$topicVotes = $topic->votes();
|
||||
}
|
||||
|
||||
if ( $topic->isQuestion() )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words[ 'topic__comment_placeholder' ] = \IPS\Member::loggedIn()->language()->addToStack( 'question__comment_placeholder', FALSE );
|
||||
}
|
||||
|
||||
/* Online User Location */
|
||||
\IPS\Session::i()->setLocation( $topic->url(), ( $topic->container()->password or !$topic->container()->can_view_others or $topic->container()->min_posts_view ) ? 0 : $topic->onlineListPermissions(), 'loc_forums_viewing_topic', array( $topic->title => FALSE ) );
|
||||
|
||||
/* Next unread */
|
||||
try
|
||||
{
|
||||
$nextUnread = $topic->nextUnread();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
$nextUnread = NULL;
|
||||
}
|
||||
|
||||
/* Show topic */
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'topics' )->topic( $topic, $comments, $question, $votes, $nextUnread, $pagination, $topicVotes );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check our view method and act accordingly (redirect if appropriate)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _doViewCheck()
|
||||
{
|
||||
try
|
||||
{
|
||||
$class = static::$contentModel;
|
||||
$topic = $class::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
|
||||
switch( \IPS\Request::i()->view )
|
||||
{
|
||||
case 'getnewpost':
|
||||
\IPS\Output::i()->redirect( $topic->url( 'getNewComment' ) );
|
||||
break;
|
||||
|
||||
case 'getlastpost':
|
||||
\IPS\Output::i()->redirect( $topic->url( 'getLastComment' ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2F173/F', 403, '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit topic
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
try
|
||||
{
|
||||
$class = static::$contentModel;
|
||||
$topic = $class::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
$forum = $topic->container();
|
||||
$forum->setTheme();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2F173/D', 403, 'no_module_permission_guest' );
|
||||
}
|
||||
|
||||
if ( $forum->forums_bitoptions['bw_enable_answers'] )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['topic_mainTab'] = \IPS\Member::loggedIn()->language()->addToStack( 'question_mainTab', FALSE );
|
||||
}
|
||||
|
||||
if ( !$topic->canEdit() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_noperm_edit', '2F173/E', 403, '' );
|
||||
}
|
||||
|
||||
$formElements = $class::formElements( $topic, $forum );
|
||||
|
||||
$hasModOptions = FALSE;
|
||||
|
||||
if ( $class::modPermission( 'lock', NULL, $forum ) )
|
||||
{
|
||||
$hasModOptions = TRUE;
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'form', \IPS\Member::loggedIn()->language()->checkKeyExists( $class::$formLangPrefix . '_save' ) ? $class::$formLangPrefix . '_save' : 'save' );
|
||||
$form->class = 'ipsForm_vertical';
|
||||
|
||||
if ( isset( $formElements['poll'] ) )
|
||||
{
|
||||
$form->addTab( $class::$formLangPrefix . 'mainTab' );
|
||||
}
|
||||
|
||||
foreach( $formElements AS $k => $element )
|
||||
{
|
||||
if ( $k === 'poll' )
|
||||
{
|
||||
$form->addTab( $class::$formLangPrefix . 'pollTab' );
|
||||
}
|
||||
|
||||
$form->add( $element );
|
||||
}
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$topic->processForm( $values );
|
||||
$topic->save();
|
||||
$topic->processAfterEdit( $values );
|
||||
|
||||
\IPS\Output::i()->redirect( $topic->url() );
|
||||
}
|
||||
|
||||
$formTemplate = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'submit', 'forums' ) ), 'createTopicForm' ), $forum, $hasModOptions );
|
||||
|
||||
$title = $forum->forums_bitoptions['bw_enable_answers'] ? 'edit_question' : 'edit_topic';
|
||||
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'submit' )->createTopic( $formTemplate, $forum, $title );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( $title );
|
||||
|
||||
if ( !\IPS\forums\Forum::theOnlyForum() )
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach( $forum->parents() AS $parent )
|
||||
{
|
||||
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
}
|
||||
\IPS\Output::i()->breadcrumb[] = array( $forum->url(), $forum->_title );
|
||||
}
|
||||
catch( \Exception $e ) {}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->breadcrumb[] = array( $topic->url(), $topic->mapped('title') );
|
||||
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack( $title ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unarchive
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unarchive()
|
||||
{
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
if ( !$topic->canUnarchive() )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2F173/B', 404, '' );
|
||||
}
|
||||
|
||||
$topic->topic_archive_status = \IPS\forums\Topic::ARCHIVE_RESTORE;
|
||||
$topic->save();
|
||||
|
||||
\IPS\Output::i()->redirect( $topic->url() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rate Question
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function rateQuestion()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$question = \IPS\forums\Topic::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2F173/8', 404, '' );
|
||||
}
|
||||
|
||||
if ( !$question->canVote() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2F173/9', 403, '' );
|
||||
}
|
||||
|
||||
$rating = intval( \IPS\Request::i()->rating );
|
||||
if ( $rating !== 1 and $rating !== -1 )
|
||||
{
|
||||
\IPS\Output::i()->error( 'form_bad_value', '2F173/A', 403, '' );
|
||||
}
|
||||
|
||||
\IPS\Db::i()->insert( 'forums_question_ratings', array(
|
||||
'topic' => $question->tid,
|
||||
'forum' => $question->forum_id,
|
||||
'member' => \IPS\Member::loggedIn()->member_id,
|
||||
'rating' => $rating,
|
||||
'date' => time()
|
||||
), TRUE );
|
||||
|
||||
$question->question_rating = \IPS\Db::i()->select( 'SUM(rating)', 'forums_question_ratings', array( 'topic=?', $question->tid ) )->first();
|
||||
$question->save();
|
||||
|
||||
\IPS\Output::i()->redirect( $question->url() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rate Answer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function rateAnswer()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$question = \IPS\forums\Topic::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
$answer = \IPS\forums\Topic\Post::loadAndCheckPerms( \IPS\Request::i()->answer );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2F173/4', 404, '' );
|
||||
}
|
||||
|
||||
if ( !$answer->item()->can('read') or !$answer->canVote() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2F173/5', 403, '' );
|
||||
}
|
||||
|
||||
$rating = intval( \IPS\Request::i()->rating );
|
||||
if ( $rating !== 1 and $rating !== -1 )
|
||||
{
|
||||
\IPS\Output::i()->error( 'form_bad_value', '2F173/6', 403, '' );
|
||||
}
|
||||
|
||||
\IPS\Db::i()->insert( 'forums_answer_ratings', array(
|
||||
'post' => $answer->pid,
|
||||
'topic' => $question->tid,
|
||||
'member' => \IPS\Member::loggedIn()->member_id,
|
||||
'rating' => $rating,
|
||||
'date' => time()
|
||||
), TRUE );
|
||||
|
||||
$answer->post_field_int = \IPS\Db::i()->select( 'SUM(rating)', 'forums_answer_ratings', array( 'post=?', $answer->pid ) )->first();
|
||||
$answer->save();
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( array( 'votes' => $answer->post_field_int, 'canVoteUp' => $answer->canVote(1), 'canVoteDown' => $answer->canVote(-1) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( $answer->url() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Best Answer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function bestAnswer()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
if ( !$topic->canSetBestAnswer() )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
$post = \IPS\forums\Topic\Post::loadAndCheckPerms( \IPS\Request::i()->answer );
|
||||
if ( $post->item() != $topic )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2F173/7', 404, '' );
|
||||
}
|
||||
|
||||
if ( $topic->topic_answered_pid )
|
||||
{
|
||||
try
|
||||
{
|
||||
$oldBestAnswer = \IPS\forums\Topic\Post::load( $topic->topic_answered_pid );
|
||||
$oldBestAnswer->post_bwoptions['best_answer'] = FALSE;
|
||||
$oldBestAnswer->save();
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
}
|
||||
|
||||
$post->post_bwoptions['best_answer'] = TRUE;
|
||||
$post->save();
|
||||
|
||||
$topic->topic_answered_pid = $post->pid;
|
||||
$topic->save();
|
||||
|
||||
/* Log */
|
||||
if ( \IPS\Member::loggedIn()->modPermission('can_set_best_answer') )
|
||||
{
|
||||
\IPS\Session::i()->modLog( 'modlog__best_answer_set', array( $post->pid => FALSE ), $topic );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $topic->url() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset Best Answer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetBestAnswer()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
if ( !$topic->canSetBestAnswer() )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2F173/G', 404, '' );
|
||||
}
|
||||
|
||||
if ( $topic->topic_answered_pid )
|
||||
{
|
||||
try
|
||||
{
|
||||
$post = \IPS\forums\Topic\Post::load( $topic->topic_answered_pid );
|
||||
$post->post_bwoptions['best_answer'] = FALSE;
|
||||
$post->save();
|
||||
|
||||
if ( \IPS\Member::loggedIn()->modPermission('can_set_best_answer') )
|
||||
{
|
||||
\IPS\Session::i()->modLog( 'modlog__best_answer_unset', array( $topic->topic_answered_pid => FALSE ), $topic );
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
}
|
||||
|
||||
$topic->topic_answered_pid = FALSE;
|
||||
$topic->save();
|
||||
|
||||
\IPS\Output::i()->redirect( $topic->url() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Saved Action
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function savedAction()
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( \IPS\Request::i()->id );
|
||||
$action = \IPS\forums\SavedAction::load( \IPS\Request::i()->action );
|
||||
$action->runOn( $topic );
|
||||
|
||||
/* Log */
|
||||
\IPS\Session::i()->modLog( 'modlog__saved_action', array( 'forums_mmod_' . $action->mm_id => TRUE, $topic->url()->__toString() => FALSE, $topic->mapped( 'title' ) => FALSE ), $topic );
|
||||
|
||||
\IPS\Output::i()->redirect( $topic->url() );
|
||||
}
|
||||
catch ( \LogicException $e )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark Topic Read
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function markRead()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::load( \IPS\Request::i()->id );
|
||||
$topic->markRead();
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json( "OK" );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( $topic->url() );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2F173/C', 403, 'no_module_permission_guest' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit Comment/Review
|
||||
*
|
||||
* @param string $commentClass The comment/review class
|
||||
* @param \IPS\Content\Comment $comment The comment/review
|
||||
* @param \IPS\Content\Item $item The item
|
||||
* @return void
|
||||
* @throws \LogicException
|
||||
*/
|
||||
protected function _edit( $commentClass, $comment, $item )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['edit_comment'] = \IPS\Member::loggedIn()->language()->addToStack( 'edit_reply', FALSE );
|
||||
|
||||
return parent::_edit( $commentClass, $comment, $item );
|
||||
}
|
||||
|
||||
/**
|
||||
* Stuff that applies to both comments and reviews
|
||||
*
|
||||
* @param string $method Desired method
|
||||
* @param array $args Arguments
|
||||
* @return void
|
||||
*/
|
||||
public function __call( $method, $args )
|
||||
{
|
||||
$class = static::$contentModel;
|
||||
|
||||
try
|
||||
{
|
||||
$item = $class::load( \IPS\Request::i()->id );
|
||||
if ( !$item->canView() )
|
||||
{
|
||||
$forum = $item->container();
|
||||
\IPS\Output::i()->error( $forum ? $forum->errorMessage() : 'node_error_no_perm', '2F173/K', 403, '' );
|
||||
}
|
||||
|
||||
if ( $item->isArchived() )
|
||||
{
|
||||
$class::$commentClass = $class::$archiveClass;
|
||||
}
|
||||
|
||||
return parent::__call( $method, $args );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->do ) AND \IPS\Request::i()->do === 'findComment' AND isset( \IPS\Request::i()->comment ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$comment = \IPS\forums\Topic\Post::load( \IPS\Request::i()->comment );
|
||||
$topic = \IPS\forums\Topic::load( $comment->topic_id );
|
||||
|
||||
\IPS\Output::i()->redirect( $topic->url()->setQueryString( array( 'do' => 'findComment', 'comment' => \IPS\Request::i()->comment ) ), NULL, 301 );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2F173/M', 404, '' );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2F173/I', 404, '' );
|
||||
}
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
Whitespace-only changes.
Reference in new issue
Block a user