Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -109,10 +109,23 @@ class _Comment extends \IPS\Content\Comment
|
||||
public function url( $action='find' )
|
||||
{
|
||||
$url = parent::url( $action );
|
||||
$idColumn = static::$databaseColumnId;
|
||||
|
||||
if ( isset( $url->queryString['do'] ) )
|
||||
{
|
||||
return $url->setQueryString( array( 'do' => NULL, 'action' => $url->queryString['do'] ) );
|
||||
return $url->stripQueryString( 'do' )->setQueryString( array( 'action' => $url->queryString['do'], 'comment' => $this->$idColumn ) );
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can promote this comment/item?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for (NULL for currently logged in member)
|
||||
* @return boolean
|
||||
*/
|
||||
public function canPromoteToSocialMedia( $member=NULL )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,12 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
*/
|
||||
class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
|
||||
{
|
||||
/**
|
||||
* @brief Const No type selected
|
||||
*/
|
||||
const TYPE_MESSAGE = 0;
|
||||
|
||||
|
||||
/* !\IPS\Patterns\ActiveRecord */
|
||||
|
||||
/**
|
||||
@@ -103,7 +109,25 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load by class and content_id
|
||||
*
|
||||
* @return \IPS\core\Reports\Report
|
||||
* @throws OutofRangeException
|
||||
*/
|
||||
public static function loadByClassAndId( $class, $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
return static::constructFromData( \IPS\Db::i()->select( '*', 'core_rc_index', array( 'class=? and content_id=?', $class, $id ) )->first() );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
throw new \OutofRangeException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mapped value
|
||||
*
|
||||
@@ -199,11 +223,11 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
|
||||
foreach( \IPS\Db::i()->select(
|
||||
"{$databaseTable}.{$class::$databasePrefix}{$class::$databaseColumnId} as commentId, {$databaseTable}.{$class::$databasePrefix}{$class::$databaseColumnMap['item']} AS itemId, {$itemClass::$databaseTable}.{$itemClass::$databasePrefix}{$itemTitleField} AS title",
|
||||
$databaseTable,
|
||||
\IPS\Db::i()->in( $class::$databasePrefix . $class::$databaseColumnId, array_keys( $objects ) )
|
||||
)->join(
|
||||
$itemDatabaseTable,
|
||||
"{$itemDatabaseTable}.{$itemClass::$databasePrefix}{$itemClass::$databaseColumnId}={$databaseTable}.{$class::$databasePrefix}{$class::$databaseColumnMap['item']}"
|
||||
)->setKeyField( 'commentId' ) as $k => $data
|
||||
\IPS\Db::i()->in( $databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnId, array_keys( $objects ) )
|
||||
)->join(
|
||||
$itemDatabaseTable,
|
||||
"{$itemDatabaseTable}.{$itemClass::$databasePrefix}{$itemClass::$databaseColumnId}={$databaseTable}.{$class::$databasePrefix}{$class::$databaseColumnMap['item']}"
|
||||
)->setKeyField( 'commentId' ) as $k => $data
|
||||
)
|
||||
{
|
||||
$objects[ $k ]->_data = array_merge( $objects[ $k ]->_data, $data );
|
||||
@@ -214,8 +238,8 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
|
||||
foreach( \IPS\Db::i()->select(
|
||||
"{$class::$databasePrefix}{$class::$databaseColumnId} as itemId, {$class::$databasePrefix}{$class::$databaseColumnMap['title']} AS title",
|
||||
$class::$databaseTable,
|
||||
\IPS\Db::i()->in( $class::$databasePrefix . $class::$databaseColumnId, array_keys( $objects ) )
|
||||
)->setKeyField( 'itemId' ) as $k => $data
|
||||
\IPS\Db::i()->in( $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnId, array_keys( $objects ) )
|
||||
)->setKeyField( 'itemId' ) as $k => $data
|
||||
)
|
||||
{
|
||||
$objects[ $k ]->_data = array_merge( $objects[ $k ]->_data, $data );
|
||||
@@ -322,6 +346,16 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
|
||||
{
|
||||
$this->status = mb_substr( $action, -1 );
|
||||
$this->save();
|
||||
|
||||
/* Post a comment on the report */
|
||||
$content = \IPS\Member::loggedIn()->language()->addToStack( 'update_report_status_content', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( 'report_status_' . $this->status ) ) ) );
|
||||
\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $content );
|
||||
|
||||
$comment = \IPS\core\Reports\Comment::create( $this, $content, TRUE, NULL, NULL, \IPS\Member::loggedIn(), new \IPS\DateTime );
|
||||
$comment->save();
|
||||
|
||||
/* And add to the moderator log */
|
||||
\IPS\Session::i()->modLog( 'modlog__action_update_report_status', array( $this->url()->__toString() => FALSE ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -380,9 +414,16 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function reports()
|
||||
public function reports( $filterByType=NULL)
|
||||
{
|
||||
return iterator_to_array( \IPS\Db::i()->select( '*', 'core_rc_reports', array( 'rid=?', $this->id ), 'date_reported' ) );
|
||||
$where = array( array( 'rid=?', $this->id ) );
|
||||
|
||||
if ( $filterByType )
|
||||
{
|
||||
$where[] = array( 'report_type=?', $filterByType );
|
||||
}
|
||||
|
||||
return iterator_to_array( \IPS\Db::i()->select( '*', 'core_rc_reports', $where, 'date_reported' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -415,8 +456,131 @@ class _Report extends \IPS\Content\Item implements \IPS\Content\ReadMarkers
|
||||
parent::delete();
|
||||
|
||||
\IPS\Db::i()->delete( 'core_rc_reports', array( 'rid=?', $this->id ) );
|
||||
\IPS\Db::i()->delete( 'core_automatic_moderation_pending', array( 'pending_object_class=? and pending_object_id=?', $this->class, $this->content_id ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock auto moderation to prevent auto moderation from changing the status again
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function lockAutoModeration()
|
||||
{
|
||||
$this->auto_moderation_exempt = 1;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock auto moderation to prevent auto moderation from changing the status again
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function isAutoModerationLocked()
|
||||
{
|
||||
return (boolean) $this->auto_moderation_exempt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run any automatic moderation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function runAutomaticModeration()
|
||||
{
|
||||
if ( ! \IPS\Settings::i()->automoderation_enabled )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* If it is auto moderation locked, skip it */
|
||||
if ( $this->isAutoModerationLocked() )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$className = $this->class;
|
||||
try
|
||||
{
|
||||
$reportedContent = $className::load( $this->content_id );
|
||||
}
|
||||
catch ( \OutOfRangeException $ex )
|
||||
{
|
||||
/* No content, no moderation, no cry */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Fetch a count of report flags so far */
|
||||
$typeCounts = $this->getReportTypeCounts();
|
||||
$ruleToUse = NULL;
|
||||
|
||||
/* Loop over all group promotion rules and get the last one that matches us */
|
||||
foreach( \IPS\core\Reports\Rules::roots() as $rule )
|
||||
{
|
||||
if( $rule->enabled and $rule->matches( $reportedContent->author(), $typeCounts ) )
|
||||
{
|
||||
$ruleToUse = $rule->id;
|
||||
}
|
||||
}
|
||||
|
||||
/* If there's no rule, return now */
|
||||
if( $ruleToUse === NULL )
|
||||
{
|
||||
/* It is possible a few reports have been removed so the threshold is no longer met, delete any pending rows if this is the case */
|
||||
\IPS\Db::i()->delete( 'core_automatic_moderation_pending', array( 'pending_object_class=? and pending_object_id=?', $className, $this->content_id ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Log the bad boy for actioning later. A small delay allows users to retract their warning */
|
||||
\IPS\Db::i()->replace( 'core_automatic_moderation_pending', array(
|
||||
'pending_object_class' => $className,
|
||||
'pending_object_id' => $this->content_id,
|
||||
'pending_report_id' => $this->id,
|
||||
'pending_added' => time(),
|
||||
'pending_rule_id' => $ruleToUse
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the report type counts
|
||||
*
|
||||
* @param boolean $totalOnly Return either an int of the total counts, or an array with the breakdown
|
||||
* @return array( 1 => 10, 2 => 3 )|INT
|
||||
*/
|
||||
public function getReportTypeCounts( $totalOnly=false )
|
||||
{
|
||||
$typeCounts = array();
|
||||
$total = 0;
|
||||
$seen = array();
|
||||
foreach( \IPS\Db::i()->select( '*', 'core_rc_reports', array( 'rid=? and report_type > 0', $this->id ) ) as $row )
|
||||
{
|
||||
if ( isset( $seen[ $row['report_by'] ] ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$seen[ $row['report_by'] ] = true;
|
||||
|
||||
$typeCounts[ $row['report_type'] ][ $row['report_by'] ] = true;
|
||||
}
|
||||
|
||||
$return = array();
|
||||
foreach( array_keys( \IPS\core\Reports\Types::roots() ) as $type )
|
||||
{
|
||||
if ( isset( $typeCounts[ $type ] ) )
|
||||
{
|
||||
$return[ $type ] = count( $typeCounts[ $type ] );
|
||||
$total += count( $typeCounts[ $type ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$return[ $type ] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $totalOnly ? $total : $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filters that are available for selecting table rows
|
||||
*
|
||||
|
||||
@@ -0,0 +1,427 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Automatic Content Moderation Rules
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @since 7 Dec 2017
|
||||
*/
|
||||
|
||||
namespace IPS\core\Reports;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Group promotion node model
|
||||
*/
|
||||
class _Rules extends \IPS\Node\Model
|
||||
{
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_automatic_moderation_rules';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'rule_';
|
||||
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Map
|
||||
*/
|
||||
protected static $multitonMap = array();
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'automaticmoderation';
|
||||
|
||||
/**
|
||||
* @brief [Node] Sortable
|
||||
*/
|
||||
public static $nodeSortable = TRUE;
|
||||
|
||||
/**
|
||||
* @brief [Node] Positon Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'position';
|
||||
|
||||
/**
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static $titleLangPrefix = 'automaticmoderation_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Enabled/Disabled Column
|
||||
*/
|
||||
public static $databaseColumnEnabledDisabled = 'enabled';
|
||||
|
||||
/**
|
||||
* Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
{
|
||||
$form->addHeader( 'automaticmoderation_generic_details' );
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'automaticmoderation_title', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? 'automaticmoderation_' . $this->id : NULL ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'automaticmoderation_enabled', $this->id ? $this->enabled : 1, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'automaticmoderation_points', $this->id ? $this->points_needed : 10, TRUE, array( 'min' => 1, 'max' => 9999 ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('automaticmoderation_points_suffix') ) );
|
||||
|
||||
$options = array();
|
||||
foreach( \IPS\core\Reports\Types::roots() as $type )
|
||||
{
|
||||
$options[ $type->id ] = $type->_title;
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'automaticmoderation_type', $this->types ? explode( ',', $this->types ) : array(), TRUE, array( 'options' => $options ) ) );
|
||||
|
||||
/* Loop over our member filters */
|
||||
$form->addHeader( 'automaticmoderation_generic_filters' );
|
||||
$options = $this->id ? $this->_filters : array();
|
||||
|
||||
$lastApp = 'core';
|
||||
|
||||
/* We take an extra step with groups to disable invalid options */
|
||||
//$options['core_Group']['disabled_groups'] = $this->getDisabledGroups();
|
||||
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' ) as $key => $extension )
|
||||
{
|
||||
if( method_exists( $extension, 'getSettingField' ) AND $extension->availableIn( 'automatic_moderation' ) )
|
||||
{
|
||||
/* See if we need a new form header - one per app */
|
||||
$_key = explode( '_', $key );
|
||||
|
||||
if( $_key[0] != $lastApp )
|
||||
{
|
||||
$lastApp = $_key[0];
|
||||
$form->addHeader( $lastApp . '_bm_filters' );
|
||||
}
|
||||
|
||||
/* Grab our fields and add to the form */
|
||||
$fields = $extension->getSettingField( !empty( $options[ $key ] ) ? $options[ $key ] : array() );
|
||||
|
||||
foreach( $fields as $field )
|
||||
{
|
||||
$form->add( $field );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of groups that cannot be promoted
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getDisabledGroups()
|
||||
{
|
||||
$return = array( \IPS\Settings::i()->guest_group );
|
||||
|
||||
foreach( \IPS\Member\Group::groups() as $group )
|
||||
{
|
||||
if( $group->g_promote_exclude )
|
||||
{
|
||||
$return[] = $group->g_id;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Format form values from add/edit form for save
|
||||
*
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
{
|
||||
if ( !$this->id )
|
||||
{
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/* Save the title */
|
||||
\IPS\Lang::saveCustom( 'core', 'automaticmoderation_' . $this->id, $values['automaticmoderation_title'] );
|
||||
|
||||
/* Json-encode the rules */
|
||||
$_options = array();
|
||||
|
||||
/* Loop over bulk mail extensions to format the options */
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' ) as $key => $extension )
|
||||
{
|
||||
if( method_exists( $extension, 'save' ) AND $extension->availableIn( 'automatic_moderation' ) )
|
||||
{
|
||||
/* Grab our fields and add to the form */
|
||||
$_value = $extension->save( $values );
|
||||
|
||||
if( $_value )
|
||||
{
|
||||
$_options[ $key ] = $_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$values['rule_filters'] = json_encode( $_options );
|
||||
$values['rule_points_needed'] = $values['automaticmoderation_points'];
|
||||
$values['rule_enabled'] = $values['automaticmoderation_enabled'];
|
||||
$values['rule_types'] = $values['automaticmoderation_type'];
|
||||
|
||||
/* Now we have to remove any fields that aren't valid... */
|
||||
foreach( $values as $k => $v )
|
||||
{
|
||||
if( !in_array( $k, array( 'rule_filters', 'rule_points_needed', 'rule_enabled', 'rule_types', 'rule_position' ) ) )
|
||||
{
|
||||
unset( $values[ $k ] );
|
||||
}
|
||||
}
|
||||
|
||||
return parent::formatFormValues( $values );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return our filters as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get__filters()
|
||||
{
|
||||
return json_decode( $this->filters, TRUE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch All Root Nodes
|
||||
*
|
||||
* @param string|NULL $permissionCheck The permission key to check for or NULl to not check permissions
|
||||
* @param \IPS\Member|NULL $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param mixed $where Additional WHERE clause
|
||||
* @return array
|
||||
*/
|
||||
public static function roots( $permissionCheck='view', $member=NULL, $where=array() )
|
||||
{
|
||||
if ( !count( $where ) )
|
||||
{
|
||||
$return = array();
|
||||
foreach( static::getStore() AS $node )
|
||||
{
|
||||
$return[ $node['rule_id'] ] = static::constructFromData( $node );
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::roots( $permissionCheck, $member, $where );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Enabled
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set__enabled( $enabled )
|
||||
{
|
||||
parent::set__enabled( $enabled );
|
||||
|
||||
unset( \IPS\Data\Store::i()->automatic_moderation_rules );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data store
|
||||
*
|
||||
* @return array
|
||||
* @note Note that all records are returned, even disabled promotion rules. Enable status needs to be checked in userland code when appropriate.
|
||||
*/
|
||||
public static function getStore()
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->automatic_moderation_rules ) )
|
||||
{
|
||||
\IPS\Data\Store::i()->automatic_moderation_rules = iterator_to_array( \IPS\Db::i()->select( '*', static::$databaseTable, NULL, "rule_position ASC" )->setKeyField( 'rule_id' ) );
|
||||
}
|
||||
|
||||
return \IPS\Data\Store::i()->automatic_moderation_rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Record
|
||||
*
|
||||
* @see \IPS\Db::build
|
||||
* @param int|string $id ID
|
||||
* @param string $idField The database column that the $id parameter pertains to (NULL will use static::$databaseColumnId)
|
||||
* @param mixed $extraWhereClause Additional where clause(s) (see \IPS\Db::build for details)
|
||||
* @return static
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \OutOfRangeException
|
||||
*/
|
||||
public static function load( $id, $idField=NULL, $extraWhereClause=NULL )
|
||||
{
|
||||
if ( ( $idField === NULL or $idField === 'rule_id' ) and $extraWhereClause === NULL )
|
||||
{
|
||||
$rule = static::getStore();
|
||||
if ( isset( $rule[ $id ] ) )
|
||||
{
|
||||
return static::constructFromData( $rule[ $id ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::load( $id, $idField, $extraWhereClause );
|
||||
}
|
||||
|
||||
/**
|
||||
* [ActiveRecord] Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
parent::delete();
|
||||
|
||||
unset( \IPS\Data\Store::i()->automatic_moderation_rules );
|
||||
}
|
||||
|
||||
/**
|
||||
* [ActiveRecord] Save Changed Columns
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
parent::save();
|
||||
|
||||
unset( \IPS\Data\Store::i()->automatic_moderation_rules );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cache extensions so we only need to load them once
|
||||
*/
|
||||
protected static $extensions = NULL;
|
||||
|
||||
/**
|
||||
* Check if a member matches the rule
|
||||
*
|
||||
* @param \IPS\Member $member Member to check
|
||||
* @param array $typeCounts Array of type counts indexed by report_type (constants in \IPS\core\Reports\Report)
|
||||
* @return bool
|
||||
*/
|
||||
public function matches( \IPS\Member $member, $typeCounts=array() )
|
||||
{
|
||||
if ( ! \IPS\Settings::i()->automoderation_enabled )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if( static::$extensions === NULL )
|
||||
{
|
||||
static::$extensions = \IPS\Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' );
|
||||
}
|
||||
|
||||
/* Nothing flagged as bad? Back you go */
|
||||
if ( ! count( $typeCounts ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Author can bypass? */
|
||||
if ( $member->group['gbw_immune_auto_mod'] )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Match the count threshold */
|
||||
$count = 0;
|
||||
foreach( explode( ',', $this->types ) as $type )
|
||||
{
|
||||
if ( isset( $typeCounts[ $type ] ) )
|
||||
{
|
||||
$count += $typeCounts[ $type ];
|
||||
}
|
||||
}
|
||||
|
||||
if ( $count < $this->points_needed )
|
||||
{
|
||||
/* You lose */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Loop over the filters */
|
||||
foreach( $this->_filters as $key => $filter )
|
||||
{
|
||||
if( isset( static::$extensions[ $key ] ) )
|
||||
{
|
||||
/* Ask the extension if this member matches the defined rule...if not, just return FALSE now */
|
||||
if( !static::$extensions[ $key ]->matches( $member, $filter, $this ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If we are still here, then the rule matched */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* ! ACP STUFF */
|
||||
|
||||
/**
|
||||
* [Node] Return the custom badge for each row
|
||||
*
|
||||
* @return NULL|array Null for no badge, or an array of badge data (0 => CSS class type, 1 => language string, 2 => optional raw HTML to show instead of language string)
|
||||
*/
|
||||
protected function get__badge()
|
||||
{
|
||||
return array(
|
||||
0 => 'ipsBadge ipsBadge_positive',
|
||||
1 => \IPS\Member::loggedIn()->language()->addToStack( 'automoderation_points_needed_badge', NULL, array( 'pluralize' => array( $this->points_needed ) ) )
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a warning if this promotion uses not existing groups
|
||||
*/
|
||||
public function get__description()
|
||||
{
|
||||
if( static::$extensions === NULL )
|
||||
{
|
||||
static::$extensions = \IPS\Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' );
|
||||
}
|
||||
|
||||
/* Loop over the filters */
|
||||
$descriptions = array();
|
||||
foreach( $this->_filters as $key => $filter )
|
||||
{
|
||||
if( isset( static::$extensions[ $key ] ) )
|
||||
{
|
||||
/* Ask the extension if this member matches the defined rule...if not, just return FALSE now */
|
||||
if( method_exists( static::$extensions[ $key ], 'getDescription' ) and $description = static::$extensions[ $key ]->getDescription( $filter ) )
|
||||
{
|
||||
$descriptions[] = $description; /* Is this descriptive enough? */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'automaticmoderation_row_desc', TRUE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->formatList( $descriptions ) ) ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Report Types
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @since 14 Dec 2017
|
||||
*/
|
||||
|
||||
namespace IPS\core\Reports;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report types node model
|
||||
*/
|
||||
class _Types extends \IPS\Node\Model
|
||||
{
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_automatic_moderation_types';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'type_';
|
||||
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Map
|
||||
*/
|
||||
protected static $multitonMap = array();
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'automaticmod_types';
|
||||
|
||||
/**
|
||||
* @brief [Node] Sortable
|
||||
*/
|
||||
public static $nodeSortable = TRUE;
|
||||
|
||||
/**
|
||||
* @brief [Node] Positon Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'position';
|
||||
|
||||
/**
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static $titleLangPrefix = 'automaticmod_types_';
|
||||
|
||||
/**
|
||||
* Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'automaticmod_types_title', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? 'automaticmod_types_' . $this->id : NULL ) ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Format form values from add/edit form for save
|
||||
*
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
{
|
||||
if ( !$this->id )
|
||||
{
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/* Save the title */
|
||||
\IPS\Lang::saveCustom( 'core', 'automaticmod_types_' . $this->id, $values['automaticmod_types_title'] );
|
||||
|
||||
unset( $values['automaticmod_types_title'] );
|
||||
|
||||
return parent::formatFormValues( $values );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch All Root Nodes
|
||||
*
|
||||
* @param string|NULL $permissionCheck The permission key to check for or NULl to not check permissions
|
||||
* @param \IPS\Member|NULL $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param mixed $where Additional WHERE clause
|
||||
* @return array
|
||||
*/
|
||||
public static function roots( $permissionCheck='view', $member=NULL, $where=array() )
|
||||
{
|
||||
if ( !count( $where ) )
|
||||
{
|
||||
$return = array();
|
||||
foreach( static::getStore() AS $node )
|
||||
{
|
||||
$return[ $node['type_id'] ] = static::constructFromData( $node );
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::roots( $permissionCheck, $member, $where );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data store
|
||||
*
|
||||
* @return array
|
||||
* @note Note that all records are returned, even disabled promotion rules. Enable status needs to be checked in userland code when appropriate.
|
||||
*/
|
||||
public static function getStore()
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->automatic_moderation_types ) )
|
||||
{
|
||||
\IPS\Data\Store::i()->automatic_moderation_types = iterator_to_array( \IPS\Db::i()->select( '*', static::$databaseTable, NULL, "type_position ASC" )->setKeyField( 'type_id' ) );
|
||||
}
|
||||
|
||||
return \IPS\Data\Store::i()->automatic_moderation_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Record
|
||||
*
|
||||
* @see \IPS\Db::build
|
||||
* @param int|string $id ID
|
||||
* @param string $idField The database column that the $id parameter pertains to (NULL will use static::$databaseColumnId)
|
||||
* @param mixed $extraWhereClause Additional where clause(s) (see \IPS\Db::build for details)
|
||||
* @return static
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \OutOfRangeException
|
||||
*/
|
||||
public static function load( $id, $idField=NULL, $extraWhereClause=NULL )
|
||||
{
|
||||
if ( ( $idField === NULL or $idField === 'type_id' ) and $extraWhereClause === NULL )
|
||||
{
|
||||
$type = static::getStore();
|
||||
if ( isset( $type[ $id ] ) )
|
||||
{
|
||||
return static::constructFromData( $type[ $id ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::load( $id, $idField, $extraWhereClause );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item count
|
||||
* I'm sure you could have figured that out from the method name
|
||||
* but I'll spoon feed you, it's ok.
|
||||
*
|
||||
* @return INT
|
||||
*/
|
||||
public function getItemCount()
|
||||
{
|
||||
return intval( \IPS\Db::i()->select( 'COUNT(*)', 'core_rc_reports', array( 'report_type=?', $this->id ) )->first() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Form to delete or move content
|
||||
*
|
||||
* @param bool $showMoveToChildren If TRUE, will show "move to children" even if there are no children
|
||||
* @return \IPS\Helpers\Form
|
||||
*/
|
||||
public function deleteOrMoveForm( $showMoveToChildren=FALSE )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'delete_node_form', 'delete' );
|
||||
$form->addMessage( 'node_delete_blurb' );
|
||||
|
||||
if ( $this->getItemCount() )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'node_move_content', 0, TRUE, array( 'class' => get_class( $this ), 'disabled' => array( $this->_id ), 'disabledLang' => 'node_move_delete', 'zeroVal' => 'node_delete_content', 'subnodes' => FALSE, 'permissionCheck' => function( $node )
|
||||
{
|
||||
return true;
|
||||
} ) ) );
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle submissions of form to delete or move content
|
||||
*
|
||||
* @param array $values Values from form
|
||||
* @return void
|
||||
*/
|
||||
public function deleteOrMoveFormSubmit( $values )
|
||||
{
|
||||
if ( isset( $values['node_move_content'] ) and $values['node_move_content'] )
|
||||
{
|
||||
/* We're moving first */
|
||||
\IPS\Db::i()->update( 'core_rc_reports', array( 'report_type' => $values['node_move_content']->_id ), array( 'report_type=?', $this->id ) );
|
||||
}
|
||||
|
||||
$this->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* [ActiveRecord] Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
parent::delete();
|
||||
|
||||
unset( \IPS\Data\Store::i()->automatic_moderation_types );
|
||||
}
|
||||
|
||||
/**
|
||||
* [ActiveRecord] Save Changed Columns
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
parent::save();
|
||||
|
||||
unset( \IPS\Data\Store::i()->automatic_moderation_types );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user