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,374 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Feed Import Node
|
||||
* @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 4 Fed 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Feed Import Node
|
||||
*/
|
||||
class _Feed extends \IPS\Node\Model
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'forums_rss_import';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'rss_import_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'rss_import';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
* @code
|
||||
array(
|
||||
'app' => 'core', // The application key which holds the restrictrions
|
||||
'module' => 'foo', // The module key which holds the restrictions
|
||||
'map' => array( // [Optional] The key for each restriction - can alternatively use "prefix"
|
||||
'add' => 'foo_add',
|
||||
'edit' => 'foo_edit',
|
||||
'permissions' => 'foo_perms',
|
||||
'delete' => 'foo_delete'
|
||||
),
|
||||
'all' => 'foo_manage', // [Optional] The key to use for any restriction not provided in the map (only needed if not providing all 4)
|
||||
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
|
||||
* @endcode
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
'app' => 'forums',
|
||||
'module' => 'forums',
|
||||
'prefix' => 'rss_'
|
||||
);
|
||||
|
||||
/**
|
||||
* [Node] Get title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get__title()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get__description()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get whether or not this node is enabled
|
||||
*
|
||||
* @note Return value NULL indicates the node cannot be enabled/disabled
|
||||
* @return bool|null
|
||||
*/
|
||||
protected function get__enabled()
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Set whether or not this node is enabled
|
||||
*
|
||||
* @param bool|int $enabled Whether to set it enabled or disabled
|
||||
* @return void
|
||||
*/
|
||||
protected function set__enabled( $enabled )
|
||||
{
|
||||
if ( $enabled )
|
||||
{
|
||||
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 1 ), array( '`key`=?', 'rssimport' ) );
|
||||
}
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get buttons to display in tree
|
||||
* Example code explains return value
|
||||
*
|
||||
* @code
|
||||
array(
|
||||
array(
|
||||
'icon' => 'plus-circle', // Name of FontAwesome icon to use
|
||||
'title' => 'foo', // Language key to use for button's title parameter
|
||||
'link' => \IPS\Http\Url::internal( 'app=foo...' ) // URI to link to
|
||||
'class' => 'modalLink' // CSS Class to use on link (Optional)
|
||||
),
|
||||
... // Additional buttons
|
||||
);
|
||||
* @endcode
|
||||
* @param string $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
*/
|
||||
public function getButtons( $url, $subnode=FALSE )
|
||||
{
|
||||
$buttons = parent::getButtons( $url, $subnode );
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction('rss_run') )
|
||||
{
|
||||
$buttons = array_merge( array( 'run' => array(
|
||||
'icon' => 'refresh',
|
||||
'title' => 'rss_run',
|
||||
'link' => $url->setQueryString( array( 'do' => 'run', 'id' => $this->_id ) )
|
||||
) ), $buttons );
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
{
|
||||
$form->addHeader('rss_import_url');
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'rss_import_url', $this->url, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'rss_import_auth_user', $this->auth_user ) );
|
||||
$form->add( new \IPS\Helpers\Form\Password( 'rss_import_auth_pass', $this->auth_pass ) );
|
||||
$form->addHeader('rss_import_details');
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'rss_import_forum_id', $this->forum_id, 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::load( $this->mid ), TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'rss_import_showlink', $this->showlink ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'rss_import_topic_open', $this->topic_open, FALSE, array( 'options' => array( 1 => 'unlocked', 0 => 'locked' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'rss_import_topic_hide', $this->topic_hide, FALSE, array( 'options' => array( 0 => 'unhidden', 1 => 'hidden' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'rss_import_topic_pre', $this->topic_pre, FALSE, array( 'trim' => FALSE ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Format form values from add/edit form for save
|
||||
*
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
{
|
||||
if( isset( $values['rss_import_url'] ) )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
throw new \DomainException('rss_import_auth');
|
||||
}
|
||||
|
||||
$response = $response->decodeXml();
|
||||
if ( !( $response instanceof \IPS\Xml\Rss ) and !( $response instanceof \IPS\Xml\Atom ) )
|
||||
{
|
||||
throw new \DomainException('rss_import_invalid');
|
||||
}
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
throw new \DomainException( 'form_url_bad' );
|
||||
}
|
||||
catch ( \ErrorException $e )
|
||||
{
|
||||
throw new \DomainException( 'rss_import_invalid' );
|
||||
}
|
||||
|
||||
$values['title'] = (string) $request->get()->decodeXml()->channel->title;
|
||||
}
|
||||
|
||||
if( isset( $values['rss_import_forum_id'] ) )
|
||||
{
|
||||
$values['forum_id'] = $values['rss_import_forum_id']->_id;
|
||||
unset( $values['rss_import_forum_id'] );
|
||||
}
|
||||
|
||||
if( isset( $values['rss_import_mid'] ) )
|
||||
{
|
||||
$values['mid'] = $values['rss_import_mid']->member_id;
|
||||
unset( $values['rss_import_mid'] );
|
||||
}
|
||||
|
||||
if( isset( $values['rss_import_auth_user'] ) OR isset( $values['rss_import_auth_pass'] ) )
|
||||
{
|
||||
$values['auth'] = ( $values['rss_import_auth_user'] or $values['rss_import_auth_pass'] );
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Perform actions after saving the form
|
||||
*
|
||||
* @param array $values Values from the form
|
||||
* @return void
|
||||
*/
|
||||
public function postSaveForm( $values )
|
||||
{
|
||||
$this->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Import
|
||||
*
|
||||
* @return void
|
||||
* @throws \IPS\Http\Url\Exception
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$previouslyImportedGuids = iterator_to_array( \IPS\Db::i()->select( 'rss_imported_guid', 'forums_rss_imported', array( 'rss_imported_impid=?', $this->id ) ) );
|
||||
|
||||
$request = \IPS\Http\Url::external( $this->url )->request();
|
||||
if ( $this->auth )
|
||||
{
|
||||
$request = $request->login( $this->auth_user, $this->auth_pass );
|
||||
}
|
||||
$request = $request->get();
|
||||
|
||||
$container = \IPS\forums\Forum::load( $this->forum_id );
|
||||
|
||||
$i = 0;
|
||||
$inserts = array();
|
||||
$request = $request->decodeXml();
|
||||
|
||||
if( !in_array( $request->getname(), array( 'feed', 'rss' ) ) )
|
||||
{
|
||||
throw new \RuntimeException( 'rss_import_invalid' );
|
||||
}
|
||||
|
||||
foreach ( $request->articles( $this->id ) as $guid => $article )
|
||||
{
|
||||
if ( !in_array( $guid, $previouslyImportedGuids ) )
|
||||
{
|
||||
$topic = \IPS\forums\Topic::createItem( \IPS\Member::load( $this->mid ), NULL, $article['date'], $container, $this->topic_hide );
|
||||
$topic->title = $this->topic_pre . $article['title'];
|
||||
if ( !$this->topic_open )
|
||||
{
|
||||
$topic->state = 'closed';
|
||||
}
|
||||
$topic->save();
|
||||
|
||||
/* Add to search index */
|
||||
\IPS\Content\Search\Index::i()->index( $topic );
|
||||
|
||||
$readMoreLink = '';
|
||||
if ( $article['link'] and $this->showlink )
|
||||
{
|
||||
$rel = array();
|
||||
$rel['nofollow'] = \IPS\Settings::i()->posts_add_nofollow ? "nofollow" : FALSE;
|
||||
$rel['external'] = \IPS\Settings::i()->links_external ? "external" : FALSE;
|
||||
|
||||
$linkRelPart = '';
|
||||
if ( count ( $rel ) )
|
||||
{
|
||||
$linkRelPart = 'rel="' . implode($rel, ' ') . '"';
|
||||
}
|
||||
|
||||
$readMoreLink = "<p><a href='{$article['link']}' {$linkRelPart}>{$this->showlink}</a></p>";
|
||||
}
|
||||
|
||||
$member = \IPS\Member::load( $this->mid );
|
||||
$content = \IPS\Text\Parser::parseStatic( $article['content'] . $readMoreLink, FALSE, NULL, $member, 'forums_Forums', TRUE, !(bool) $member->group['g_dohtml'] );
|
||||
|
||||
$post = \IPS\forums\Topic\Post::create( $topic, $content, TRUE, NULL, \IPS\forums\Topic\Post::incrementPostCount( $container ), $member, $article['date'] );
|
||||
$topic->topic_firstpost = $post->pid;
|
||||
$topic->save();
|
||||
|
||||
$inserts[] = array(
|
||||
'rss_imported_guid' => $guid,
|
||||
'rss_imported_tid' => $topic->tid,
|
||||
'rss_imported_impid'=> $this->id
|
||||
);
|
||||
|
||||
$i++;
|
||||
|
||||
if ( $i >= 10 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( count( $inserts ) )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'forums_rss_imported', $inserts );
|
||||
}
|
||||
|
||||
$this->last_import = time();
|
||||
$this->save();
|
||||
|
||||
$container->setLastComment();
|
||||
$container->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* [ActiveRecord] Delete Record
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
\IPS\Db::i()->delete( 'forums_rss_imported', array( "rss_imported_impid=?", $this->id ) );
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Search
|
||||
*
|
||||
* @param string $column Column to search
|
||||
* @param string $query Search query
|
||||
* @param string|null $order Column to order by
|
||||
* @param mixed $where Where clause
|
||||
* @return array
|
||||
*/
|
||||
public static function search( $column, $query, $order=NULL, $where=array() )
|
||||
{
|
||||
if ( $column === '_title' )
|
||||
{
|
||||
$column = 'rss_import_title';
|
||||
}
|
||||
if ( $order === '_title' )
|
||||
{
|
||||
$order = 'rss_import_title';
|
||||
}
|
||||
return parent::search( $column, $query, $order, $where );
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
File diff suppressed because it is too large.
Load diff
Whitespace-only changes.
@@ -0,0 +1,329 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Saved Action Node
|
||||
* @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 31 Jan 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saved Action Node
|
||||
*/
|
||||
class _SavedAction extends \IPS\Node\Model
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'forums_topic_mmod';
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'saved_actions';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'mm_id';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
* @code
|
||||
array(
|
||||
'app' => 'core', // The application key which holds the restrictrions
|
||||
'module' => 'foo', // The module key which holds the restrictions
|
||||
'map' => array( // [Optional] The key for each restriction - can alternatively use "prefix"
|
||||
'add' => 'foo_add',
|
||||
'edit' => 'foo_edit',
|
||||
'permissions' => 'foo_perms',
|
||||
'delete' => 'foo_delete'
|
||||
),
|
||||
'all' => 'foo_manage', // [Optional] The key to use for any restriction not provided in the map (only needed if not providing all 4)
|
||||
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
|
||||
* @endcode
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
'app' => 'forums',
|
||||
'module' => 'forums',
|
||||
'prefix' => 'savedActions_'
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static $titleLangPrefix = 'forums_mmod_';
|
||||
|
||||
/**
|
||||
* Get available saved actions for a forum
|
||||
*
|
||||
* @param \IPS\forums\Forum $forum The forum
|
||||
* @param \IPS\Member|NULL $member The member (NULL for currently logged in)
|
||||
* @return array
|
||||
*/
|
||||
public static function actions( \IPS\forums\Forum $forum, \IPS\Member $member = NULL )
|
||||
{
|
||||
$return = array();
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
if ( $member->modPermission('can_use_saved_actions') and \IPS\forums\Topic::modPermission( 'use_saved_actions', $member, $forum ) )
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->forumsSavedActions ) )
|
||||
{
|
||||
\IPS\Data\Store::i()->forumsSavedActions = iterator_to_array( \IPS\Db::i()->select( '*', 'forums_topic_mmod' ) );
|
||||
}
|
||||
|
||||
foreach ( \IPS\Data\Store::i()->forumsSavedActions as $action )
|
||||
{
|
||||
if ( $action['mm_enabled'] and ( $action['mm_forums'] == '*' or in_array( $forum->id, array_filter( explode( ',', $action['mm_forums'] ) ) ) ) )
|
||||
{
|
||||
$return[ $action['mm_id'] ] = static::constructFromData( $action );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* [Node] Get whether or not this node is enabled
|
||||
*
|
||||
* @note Return value NULL indicates the node cannot be enabled/disabled
|
||||
* @return bool|null
|
||||
*/
|
||||
protected function get__enabled()
|
||||
{
|
||||
return $this->mm_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Set whether or not this node is enabled
|
||||
*
|
||||
* @param bool|int $enabled Whether to set it enabled or disabled
|
||||
* @return void
|
||||
*/
|
||||
protected function set__enabled( $enabled )
|
||||
{
|
||||
$this->mm_enabled = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
{
|
||||
$form->addHeader( 'settings' );
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'mm_title', NULL, TRUE, array( 'app' => 'forums', 'key' => ( $this->mm_id ? "forums_mmod_{$this->mm_id}" : NULL ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'mm_forums', ( $this->mm_id and $this->mm_forums != '*' ) ? $this->mm_forums : 0, FALSE, array( 'class' => 'IPS\forums\Forum', 'multiple' => TRUE, 'zeroVal' => 'all' ) ) );
|
||||
|
||||
$form->addHeader( 'topic_properties' );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'topic_state', $this->mm_id ? $this->topic_state : 'leave', FALSE, array( 'options' => array( 'leave' => 'mm_leave', 'open' => 'unlock', 'close' => 'lock' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'topic_pin', $this->mm_id ? $this->topic_pin : 'leave', FALSE, array( 'options' => array( 'leave' => 'mm_leave', 'pin' => 'pin', 'unpin' => 'unpin' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'topic_approve', $this->mm_id ? $this->topic_approve : 0, FALSE, array( 'options' => array( 0 => 'mm_leave', 1 => 'unhide', 2 => 'hide' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'topic_move', ( $this->mm_id and $this->topic_move != -1 ) ? $this->topic_move : 0, FALSE, array( 'class' => 'IPS\forums\Forum', 'zeroVal' => 'topic_move_none', 'zeroValTogglesOff' => array( 'topic_move_link' ), 'permissionCheck' => function ( $forum )
|
||||
{
|
||||
return $forum->sub_can_post and !$forum->redirect_url;
|
||||
} ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'topic_move_link', $this->mm_id ? $this->topic_move_link : TRUE, FALSE, array(), NULL, NULL, NULL, 'topic_move_link' ) );
|
||||
|
||||
$form->addHeader( 'topic_title' );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'topic_title_st', $this->mm_id ? $this->topic_title_st : NULL, FALSE, array( 'trim' => FALSE ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'topic_title_end', $this->mm_id ? $this->topic_title_end : NULL, FALSE, array( 'trim' => FALSE ) ) );
|
||||
|
||||
$form->addHeader( 'add_reply' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'topic_reply', $this->mm_id ? $this->topic_reply : FALSE, FALSE, array( 'togglesOn' => array( 'topic_reply_content_editor', 'topic_reply_postcount' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Editor( 'topic_reply_content', $this->mm_id ? $this->topic_reply_content : FALSE, FALSE, array( 'app' => 'core', 'key' => 'Admin', 'autoSaveKey' => ( $this->mm_id ? "forums-mmod-{$this->mm_id}" : "forums-new-mmod" ), 'attachIds' => $this->mm_id ? array( $this->mm_id, NULL, 'mmod' ) : NULL ), NULL, NULL, NULL, 'topic_reply_content_editor' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'topic_reply_postcount', $this->mm_id ? $this->topic_reply_postcount : TRUE, FALSE, array(), NULL, NULL, NULL, 'topic_reply_postcount' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Format form values from add/edit form for save
|
||||
*
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
{
|
||||
if( isset( $values['mm_forums'] ) )
|
||||
{
|
||||
if ( $values['mm_forums'] == 0 )
|
||||
{
|
||||
$values['mm_forums'] = '*';
|
||||
}
|
||||
else
|
||||
{
|
||||
$forums = array();
|
||||
foreach ( $values['mm_forums'] as $forum )
|
||||
{
|
||||
$forums[] = $forum->_id;
|
||||
}
|
||||
|
||||
$values['mm_forums'] = ( implode( ',', $forums ) );
|
||||
}
|
||||
}
|
||||
|
||||
if( isset( $values['topic_move'] ) )
|
||||
{
|
||||
if ( !is_object( $values['topic_move'] ) and $values['topic_move'] == 0 )
|
||||
{
|
||||
$values['topic_move'] = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$values['topic_move'] = $values['topic_move']->_id;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$this->mm_id )
|
||||
{
|
||||
$this->mm_enabled = $values['mm_enabled'] = TRUE;
|
||||
$this->save();
|
||||
\IPS\File::claimAttachments( 'forums-new-mmod', $this->mm_id, NULL, 'forumsSavedAction' );
|
||||
}
|
||||
|
||||
if ( isset( $values['mm_title'] ) )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'forums', "forums_mmod_{$this->mm_id}", $values['mm_title'] );
|
||||
unset( $values['mm_title'] );
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run
|
||||
*
|
||||
* @param \IPS\forums\Topic $topic The topic to run on
|
||||
* @param \IPS\Member|NULL $member Member running (NULL for currently logged in member)
|
||||
* @return void
|
||||
*/
|
||||
public function runOn( \IPS\forums\Topic $topic, \IPS\Member $member = NULL )
|
||||
{
|
||||
/* Permission Checks */
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
if ( !$member->modPermission('can_use_saved_actions') )
|
||||
{
|
||||
throw new \DomainException('NO_PERMISSION');
|
||||
}
|
||||
if ( !$this->mm_enabled )
|
||||
{
|
||||
throw new \DomainException('DISABLED');
|
||||
}
|
||||
if ( $this->mm_forums !== '*' and !in_array( $topic->container()->_id, explode( ',', $this->mm_forums ) ) )
|
||||
{
|
||||
throw new \DomainException('BAD_FORUM');
|
||||
}
|
||||
if ( $this->mm_forums !== '*' and !in_array( $topic->container()->_id, explode( ',', $this->mm_forums ) ) )
|
||||
{
|
||||
throw new \DomainException('BAD_FORUM');
|
||||
}
|
||||
if ( $topic->isArchived() )
|
||||
{
|
||||
throw new \DomainException('TOPIC_ARCHIVED');
|
||||
}
|
||||
/* Open/Close */
|
||||
if ( $this->topic_state == 'open' )
|
||||
{
|
||||
$topic->state = 'open';
|
||||
}
|
||||
elseif ( $this->topic_state == 'close' )
|
||||
{
|
||||
$topic->state = 'closed';
|
||||
}
|
||||
|
||||
/* Pin/Unpin */
|
||||
if ( $this->topic_pin == 'pin' )
|
||||
{
|
||||
$topic->pinned = TRUE;
|
||||
}
|
||||
elseif ( $this->topic_pin == 'unpin' )
|
||||
{
|
||||
$topic->pinned = FALSE;
|
||||
}
|
||||
|
||||
/* Title */
|
||||
if ( $this->topic_title_st )
|
||||
{
|
||||
$topic->title = $this->topic_title_st . $topic->title;
|
||||
}
|
||||
if ( $this->topic_title_end )
|
||||
{
|
||||
$topic->title .= $this->topic_title_end;
|
||||
}
|
||||
|
||||
/* Save */
|
||||
$topic->save();
|
||||
|
||||
/* Hide/Unhide */
|
||||
if ( $this->topic_approve == 1 )
|
||||
{
|
||||
$topic->unhide();
|
||||
}
|
||||
elseif ( $this->topic_approve == 2 )
|
||||
{
|
||||
$topic->hide();
|
||||
}
|
||||
|
||||
/* Reply */
|
||||
if ( $this->topic_reply )
|
||||
{
|
||||
$reply = \IPS\forums\Topic\Post::create( $topic, $this->topic_reply_content, FALSE, NULL, $this->topic_reply_postcount );
|
||||
}
|
||||
|
||||
/* Move */
|
||||
if ( $this->topic_move != -1 )
|
||||
{
|
||||
try
|
||||
{
|
||||
$topic->move( \IPS\forums\Forum::load( $this->topic_move ), $this->topic_move_link );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Record
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
parent::save();
|
||||
unset( \IPS\Data\Store::i()->forumsSavedActions );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Record
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
\IPS\File::unclaimAttachments( 'core_Admin', $this->mm_id, NULL, 'forumsSavedAction' );
|
||||
parent::delete();
|
||||
|
||||
unset( \IPS\Data\Store::i()->forumsSavedActions );
|
||||
}
|
||||
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Archived Post Model
|
||||
* @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 24 Jan 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\forums\Topic;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post Model
|
||||
*/
|
||||
class _ArchivedPost extends Post
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Connection
|
||||
*/
|
||||
public static function db()
|
||||
{
|
||||
return ( !\IPS\Settings::i()->archive_remote_sql_host ) ? \IPS\Db::i() : \IPS\Db::i( 'archive', array(
|
||||
'sql_host' => \IPS\Settings::i()->archive_remote_sql_host,
|
||||
'sql_user' => \IPS\Settings::i()->archive_remote_sql_user,
|
||||
'sql_pass' => \IPS\Settings::i()->archive_remote_sql_pass,
|
||||
'sql_database' => \IPS\Settings::i()->archive_remote_sql_database,
|
||||
'sql_port' => \IPS\Settings::i()->archive_sql_port,
|
||||
'sql_socket' => \IPS\Settings::i()->archive_sql_socket,
|
||||
'sql_tbl_prefix'=> \IPS\Settings::i()->archive_sql_tbl_prefix,
|
||||
'sql_utf8mb4' => isset( \IPS\Settings::i()->sql_utf8mb4 ) ? \IPS\Settings::i()->sql_utf8mb4 : FALSE
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'forums_archive_posts';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'archive_';
|
||||
|
||||
/**
|
||||
* @brief Database Column Map
|
||||
*/
|
||||
public static $databaseColumnMap = array(
|
||||
'item' => 'topic_id',
|
||||
'author' => 'author_id',
|
||||
'author_name' => 'author_name',
|
||||
'content' => 'content',
|
||||
'date' => 'content_date',
|
||||
'ip_address' => 'ip_address',
|
||||
'edit_time' => 'edit_time',
|
||||
'edit_show' => 'append_edit',
|
||||
'edit_member_name' => 'edit_name',
|
||||
'edit_reason' => 'post_edit_reason',
|
||||
'hidden' => 'queued',
|
||||
'first' => 'is_first'
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Bitwise values for post_bwoptions field
|
||||
*/
|
||||
public static $bitOptions = array(
|
||||
'bwoptions' => array(
|
||||
'bwoptions' => array(
|
||||
'best_answer' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Database Column ID
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* Post count for member
|
||||
*
|
||||
* @param \IPS\Member $member The memner
|
||||
* @return int
|
||||
*/
|
||||
public static function memberPostCount( \IPS\Member $member )
|
||||
{
|
||||
return static::db()->select( 'COUNT(*)', 'forums_archive_posts', array(
|
||||
array( 'archive_author_id=?', $member->member_id ),
|
||||
array( \IPS\Db::i()->in( 'archive_forum_id', iterator_to_array( \IPS\Db::i()->select( 'id', 'forums_forums', 'inc_postcount=0' ) ), TRUE ) )
|
||||
) )->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins (when loading comments)
|
||||
*
|
||||
* @param \IPS\Content\Item $item The item
|
||||
* @return array
|
||||
*/
|
||||
public static function joins( \IPS\Content\Item $item )
|
||||
{
|
||||
$return = parent::joins( $item );
|
||||
|
||||
unset( $return['author'] );
|
||||
unset( $return['author_pfields'] );
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can edit?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for (NULL for currently logged in member)
|
||||
* @return bool
|
||||
*/
|
||||
public function canEdit( $member=NULL )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can hide?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for (NULL for currently logged in member)
|
||||
* @return bool
|
||||
*/
|
||||
public function canHide( $member=NULL )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can unhide?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for (NULL for currently logged in member)
|
||||
*/
|
||||
public function canUnhide( $member=NULL )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can delete?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for (NULL for currently logged in member)
|
||||
* @return bool
|
||||
*/
|
||||
public function canDelete( $member=NULL )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can split?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for (NULL for currently logged in member)
|
||||
* @return bool
|
||||
*/
|
||||
public function canSplit( $member=NULL )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can give reputation?
|
||||
*
|
||||
* @note This method is also ran to check if a member can "unrep"
|
||||
* @param int $type 1 for positive, -1 for negative
|
||||
* @param \IPS\Member|NULL $member The member to check for (NULL for currently logged in member)
|
||||
* @return bool
|
||||
*/
|
||||
public function canGiveReputation( $type, \IPS\Member $member = NULL )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,351 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Post Model
|
||||
* @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 8 Jan 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\forums\Topic;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post Model
|
||||
*/
|
||||
class _Post extends \IPS\Content\Comment implements \IPS\Content\ReportCenter, \IPS\Content\EditHistory, \IPS\Content\Hideable, \IPS\Content\Reputation, \IPS\Content\Shareable, \IPS\Content\Searchable, \IPS\Content\Embeddable
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'pid';
|
||||
|
||||
/**
|
||||
* @brief [Content\Comment] Item Class
|
||||
*/
|
||||
public static $itemClass = 'IPS\forums\Topic';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'forums_posts';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = '';
|
||||
|
||||
/**
|
||||
* @brief Application
|
||||
*/
|
||||
public static $application = 'forums';
|
||||
|
||||
/**
|
||||
* @brief Title
|
||||
*/
|
||||
public static $title = 'post';
|
||||
|
||||
/**
|
||||
* @brief Database Column Map
|
||||
*/
|
||||
public static $databaseColumnMap = array(
|
||||
'item' => 'topic_id',
|
||||
'author' => 'author_id',
|
||||
'author_name' => 'author_name',
|
||||
'content' => 'post',
|
||||
'date' => 'post_date',
|
||||
'ip_address' => 'ip_address',
|
||||
'edit_time' => 'edit_time',
|
||||
'edit_show' => 'append_edit',
|
||||
'edit_member_name' => 'edit_name',
|
||||
'edit_reason' => 'post_edit_reason',
|
||||
'hidden' => 'queued',
|
||||
'first' => 'new_topic'
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Icon
|
||||
*/
|
||||
public static $icon = 'comment';
|
||||
|
||||
/**
|
||||
* @brief Reputation Type
|
||||
*/
|
||||
public static $reputationType = 'pid';
|
||||
|
||||
/**
|
||||
* @brief [Content\Comment] Comment Template
|
||||
*/
|
||||
public static $commentTemplate = array( array( 'topics', 'forums', 'front' ), 'postContainer' );
|
||||
|
||||
/**
|
||||
* @brief [Content] Key for hide reasons
|
||||
*/
|
||||
public static $hideLogKey = 'post';
|
||||
|
||||
/**
|
||||
* @brief Bitwise values for post_bwoptions field
|
||||
*/
|
||||
public static $bitOptions = array(
|
||||
'post_bwoptions' => array(
|
||||
'post_bwoptions' => array(
|
||||
'best_answer' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Join profile fields when loading comments?
|
||||
*/
|
||||
public static $joinProfileFields = TRUE;
|
||||
|
||||
/**
|
||||
* Create comment
|
||||
*
|
||||
* @param \IPS\Content\Item $item The content item just created
|
||||
* @param string $comment The comment
|
||||
* @param bool $first Is the first comment?
|
||||
* @param string $guestName If author is a guest, the name to use
|
||||
* @param bool|NULL $incrementPostCount Increment post count? If NULL, will use static::incrementPostCount()
|
||||
* @param \IPS\Member|NULL $member The author of this comment. If NULL, uses currently logged in member.
|
||||
* @param \IPS\DateTime|NULL $time The time
|
||||
* @return static
|
||||
*/
|
||||
public static function create( $item, $comment, $first=FALSE, $guestName=NULL, $incrementPostCount=NULL, $member=NULL, \IPS\DateTime $time=NULL )
|
||||
{
|
||||
$comment = call_user_func_array( 'parent::create', func_get_args() );
|
||||
|
||||
if ( !$comment->hidden() and $popularNowSettings = json_decode( \IPS\Settings::i()->forums_popular_now, TRUE ) and $popularNowSettings['posts'] and $popularNowSettings['minutes'] )
|
||||
{
|
||||
$popularNowInterval = new \DateInterval( 'PT' . $popularNowSettings['minutes'] . 'M' );
|
||||
|
||||
$comments = $item->comments( NULL, NULL, 'date', 'desc', NULL, FALSE, \IPS\DateTime::create()->sub( $popularNowInterval ) );
|
||||
if ( count( $comments ) >= $popularNowSettings['posts'] )
|
||||
{
|
||||
$commentToBasePopularNowTimeOff = array_slice( $comments, ( $popularNowSettings['posts'] - 1 ), 1 );
|
||||
$commentToBasePopularNowTimeOff = array_pop( $commentToBasePopularNowTimeOff );
|
||||
|
||||
$item->popular_time = \IPS\DateTime::ts( $commentToBasePopularNowTimeOff->post_date )->add( $popularNowInterval )->getTimestamp();
|
||||
$item->save();
|
||||
}
|
||||
elseif ( $item->popular_time !== NULL )
|
||||
{
|
||||
$item->popular_time = NULL;
|
||||
$item->save();
|
||||
}
|
||||
}
|
||||
|
||||
return $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should posting this increment the poster's post count?
|
||||
*
|
||||
* @param \IPS\Node\Model|NULL $container Container
|
||||
* @return void
|
||||
* @see \IPS\Topic\Post::incrementPostCount()
|
||||
*/
|
||||
public static function incrementPostCount( \IPS\Node\Model $container = NULL )
|
||||
{
|
||||
return $container and $container->inc_postcount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post count for member
|
||||
*
|
||||
* @param \IPS\Member $member The memner
|
||||
* @return int
|
||||
*/
|
||||
public static function memberPostCount( \IPS\Member $member )
|
||||
{
|
||||
return \IPS\Db::i()->select( 'COUNT(*)', 'forums_posts', array(
|
||||
'author_id=? AND forum_id IN(?)',
|
||||
$member->member_id,
|
||||
\IPS\Db::i()->select( 'id', 'forums_forums', 'inc_postcount=1' )
|
||||
) )->join( 'forums_topics', 'tid=topic_id' )->first() ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get items with permisison check
|
||||
*
|
||||
* @param array $where Where clause
|
||||
* @param string $order MySQL ORDER BY clause (NULL to order by date)
|
||||
* @param int|array $limit Limit clause
|
||||
* @param string $permissionKey A key which has a value in the permission map (either of the container or of this class) matching a column ID in core_permission_index
|
||||
* @param bool|NULL $includeHiddenItems Include hidden files? Boolean or NULL to detect if currently logged member has permission
|
||||
* @param int $queryFlags Select bitwise flags
|
||||
* @param \IPS\Member $member The member (NULL to use currently logged in member)
|
||||
* @param bool $joinContainer If true, will join container data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $joinComments If true, will join comment data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $joinReviews If true, will join review data (set to TRUE if your $where clause depends on this data)
|
||||
* @return \IPS\Patterns\ActiveRecordIterator|int
|
||||
*/
|
||||
public static function getItemsWithPermission( $where=array(), $order=NULL, $limit=10, $permissionKey='read', $includeHiddenItems=NULL, $queryFlags=0, \IPS\Member $member=NULL, $joinContainer=FALSE, $joinComments=FALSE, $joinReviews=FALSE, $countOnly=FALSE, $joins=NULL )
|
||||
{
|
||||
$where = \IPS\forums\Topic::getItemsWithPermissionWhere( $where, $permissionKey, $member, $joinContainer );
|
||||
|
||||
return parent::getItemsWithPermission( $where, $order, $limit, $permissionKey, $includeHiddenItems, $queryFlags, $member, $joinContainer, $joinComments, $joinReviews, $countOnly, $joins );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML for search result display
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public function searchResultHtml()
|
||||
{
|
||||
if ( $this->item()->container()->password and !\IPS\Member::loggedIn()->inGroup( explode( ',', $this->item()->container()->password_override ) ) and !( isset( \IPS\Request::i()->cookie[ 'ipbforumpass_' . $this->item()->container()->id ] ) and md5( $this->item()->container()->password ) === \IPS\Request::i()->cookie[ 'ipbforumpass_' . $this->item()->container()->id ] ) )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'forums' )->searchNoPermission( $this, \IPS\Member::loggedIn()->language()->addToStack('no_perm_post_password'), $this->item()->container()->url()->setQueryString( 'topic', $this->item()->tid ) );
|
||||
}
|
||||
elseif ( $this->item()->container()->min_posts_view and $this->item()->container()->min_posts_view >= \IPS\Member::loggedIn()->member_posts )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'forums' )->searchNoPermission( $this, \IPS\Member::loggedIn()->language()->addToStack( 'no_perm_post_min_posts', FALSE, array( 'pluralize' => array( $this->item()->container()->min_posts_view ) ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'search', 'core', 'front' )->contentComment( $this );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML for search result display
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public function activityStreamHtml()
|
||||
{
|
||||
if ( $this->item()->container()->password and !\IPS\Member::loggedIn()->inGroup( explode( ',', $this->item()->container()->password_override ) ) and !( isset( \IPS\Request::i()->cookie[ 'ipbforumpass_' . $this->item()->container()->id ] ) and md5( $this->item()->container()->password ) === \IPS\Request::i()->cookie[ 'ipbforumpass_' . $this->item()->container()->id ] ) )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'forums' )->searchNoPermission( $this, \IPS\Member::loggedIn()->language()->addToStack('no_perm_post_password'), $this->item()->container()->url()->setQueryString( 'topic', $this->item()->tid ) );
|
||||
}
|
||||
elseif ( $this->item()->container()->min_posts_view and $this->item()->container()->min_posts_view >= \IPS\Member::loggedIn()->member_posts )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'forums' )->searchNoPermission( $this, \IPS\Member::loggedIn()->language()->addToStack( 'no_perm_post_min_posts', FALSE, array( 'pluralize' => array( $this->item()->container()->min_posts_view ) ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'system', 'core', 'front' )->activityStreamResult( $this );
|
||||
}
|
||||
}
|
||||
|
||||
/* !Questions & Answers */
|
||||
|
||||
/**
|
||||
* Can the user rate answers?
|
||||
*
|
||||
* @param int $rating 1 for positive, -1 for negative, 0 for either
|
||||
* @param \IPS\Member|NULL $member The member (NULL for currently logged in member)
|
||||
* @return bool
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function canVote( $rating=0, $member=NULL )
|
||||
{
|
||||
/* Is $rating valid */
|
||||
if ( !in_array( $rating, array( -1, 0, 1 ) ) )
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
}
|
||||
|
||||
/* Downvoting disabled? */
|
||||
if ( $rating === -1 and !\IPS\Settings::i()->forums_answers_downvote )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Guests can't vote */
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
if ( !$member->member_id )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Can't vote your own answers */
|
||||
if ( $member == $this->author() )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Check the forum settings */
|
||||
if ( $this->item()->container()->qa_rate_answers !== NULL and $this->item()->container()->qa_rate_answers != '*' and !$member->inGroup( explode( ',', $this->item()->container()->qa_rate_answers ) ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Have we already voted? */
|
||||
if ( $rating !== 0 or !\IPS\Settings::i()->forums_answers_downvote )
|
||||
{
|
||||
$ratings = $this->item()->answerVotes( $member );
|
||||
if ( isset( $ratings[ $this->pid ] ) and $ratings[ $this->pid ] === $rating )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Post
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
/* Reset best answer if relevant */
|
||||
if ( $this->item()->topic_answered_pid == $this->pid )
|
||||
{
|
||||
$this->item()->topic_answered_pid = FALSE;
|
||||
$this->item()->save();
|
||||
}
|
||||
|
||||
parent::delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indefinite Article
|
||||
*
|
||||
* @param \IPS\Lang|NULL $language The language to use, or NULL for the language of the currently logged in member
|
||||
* @return string
|
||||
*/
|
||||
public function indefiniteArticle( \IPS\Lang $lang = NULL )
|
||||
{
|
||||
if ( $this->item()->isQuestion() )
|
||||
{
|
||||
$lang = $lang ?: \IPS\Member::loggedIn()->language();
|
||||
|
||||
return ( $this->isFirst() ) ? $lang->get( '__indefart_question', FALSE ) : $lang->get( '__indefart_answer', FALSE );
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::indefiniteArticle( $lang );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
{
|
||||
/* Set forum theme if it has been overridden */
|
||||
$this->item()->container()->setTheme();
|
||||
|
||||
return parent::html();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
Whitespace-only changes.
Whitespace-only changes.
Reference in new issue
Block a user