Ajout d'une extension
This commit is contained in:
593
ext/phpbbstudio/aps/actions/manager.php
Normal file
593
ext/phpbbstudio/aps/actions/manager.php
Normal file
@@ -0,0 +1,593 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System points actions manager.
|
||||
*/
|
||||
class manager
|
||||
{
|
||||
/** @var \phpbb\di\service_collection Array of action types from the service collection */
|
||||
protected $actions;
|
||||
|
||||
/** @var \phpbbstudio\aps\points\distributor */
|
||||
protected $distributor;
|
||||
|
||||
/** @var \phpbbstudio\aps\core\functions */
|
||||
protected $functions;
|
||||
|
||||
/** @var \phpbb\language\language */
|
||||
protected $lang;
|
||||
|
||||
/** @var \phpbb\log\log */
|
||||
protected $log;
|
||||
|
||||
/** @var \phpbbstudio\aps\points\valuator */
|
||||
protected $valuator;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/** @var array Array of points fields for the triggered action types */
|
||||
protected $fields;
|
||||
|
||||
/** @var array Array of action types that are triggered */
|
||||
protected $types;
|
||||
|
||||
/** @var array Array of users that can receive points for the triggered action */
|
||||
protected $users;
|
||||
|
||||
/** @var array Array of point values required for the triggered action types */
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\di\service_collection $actions Array of action types from the service collection
|
||||
* @param \phpbbstudio\aps\points\distributor $distributor APS Distributor object
|
||||
* @param \phpbbstudio\aps\core\functions $functions APS Core functions
|
||||
* @param \phpbb\language\language $lang Language object
|
||||
* @param \phpbb\log\log $log phpBB Log object
|
||||
* @param \phpbbstudio\aps\points\valuator $valuator APS Valuator
|
||||
* @param \phpbb\user $user User object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct($actions, \phpbbstudio\aps\points\distributor $distributor, \phpbbstudio\aps\core\functions $functions, \phpbb\language\language $lang, \phpbb\log\log $log, \phpbbstudio\aps\points\valuator $valuator, \phpbb\user $user)
|
||||
{
|
||||
$this->distributor = $distributor;
|
||||
$this->functions = $functions;
|
||||
$this->lang = $lang;
|
||||
$this->log = $log;
|
||||
$this->valuator = $valuator;
|
||||
$this->user = $user;
|
||||
|
||||
$this->actions = $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the APS Distributor object.
|
||||
*
|
||||
* @return \phpbbstudio\aps\points\distributor
|
||||
* @access public
|
||||
*/
|
||||
public function get_distributor()
|
||||
{
|
||||
return $this->distributor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the APS Core functions.
|
||||
*
|
||||
* @return \phpbbstudio\aps\core\functions
|
||||
* @access public
|
||||
*/
|
||||
public function get_functions()
|
||||
{
|
||||
return $this->functions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the APS Valuator.
|
||||
*
|
||||
* @return \phpbbstudio\aps\points\valuator
|
||||
* @access public
|
||||
*/
|
||||
public function get_valuator()
|
||||
{
|
||||
return $this->valuator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the localised points name.
|
||||
*
|
||||
* @return string The localised points name
|
||||
* @access public
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return $this->functions->get_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean an array from a listener, turns an object into an array.
|
||||
*
|
||||
* @param mixed $event The event to clean
|
||||
* @return array The event data
|
||||
* @access public
|
||||
*/
|
||||
public function clean_event($event)
|
||||
{
|
||||
if ($event instanceof \phpbb\event\data)
|
||||
{
|
||||
return (array) $event->get_data();
|
||||
}
|
||||
else
|
||||
{
|
||||
return (array) $event;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all values for the provided key in an array.
|
||||
*
|
||||
* @param array $array The array to retrieve the values from
|
||||
* @param string $key The keys of which to return the values
|
||||
* @return array Array of unique integers
|
||||
* @access public
|
||||
*/
|
||||
public function get_identifiers(array $array, $key)
|
||||
{
|
||||
return (array) array_map('intval', array_unique(array_filter(array_column($array, $key))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger a point action and calculate users' points.
|
||||
*
|
||||
* This is the "main" function for this extension.
|
||||
*
|
||||
* $action
|
||||
* Calling this with an $action will trigger all action type which have their get_action() set to $action.
|
||||
*
|
||||
* $user_ids
|
||||
* User identifiers are for the users who can receive points by this action, this user ($this->user) is
|
||||
* automatically added to the list. If it was already present in the list, it's filtered out.
|
||||
*
|
||||
* $event
|
||||
* An array with data that was available from the event (or any other occurrence) that triggered this action.
|
||||
* For instance, phpBB's event object that is available in a listener. If indeed phpBB's event object is
|
||||
* send it is automatically 'cleaned', which means the object is turned into an array.
|
||||
*
|
||||
* $forum_ids
|
||||
* A list of forum identifiers for which the point values should be retrieved, as those values are necessary
|
||||
* to require the amount of points for the users. If it's left empty it will assume that the triggered action
|
||||
* is a "global" action, which means the forum_id = 0.
|
||||
*
|
||||
* @param string $action The action to trigger
|
||||
* @param array|int $user_ids The user identifiers that can receive points
|
||||
* @param array $event The event data
|
||||
* @param array|int $forum_ids The forum identifiers (array or single value)
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function trigger($action, $user_ids = [], $event = [], $forum_ids = 0)
|
||||
{
|
||||
// 1. Initialise arrays
|
||||
$this->initialise_arrays();
|
||||
|
||||
// 2. Get action types
|
||||
$this->get_types_and_fields($action);
|
||||
|
||||
// 3. Get values
|
||||
$this->get_values($forum_ids);
|
||||
|
||||
// 4. Set users
|
||||
$this->set_users($user_ids);
|
||||
|
||||
// 5. Calculate
|
||||
$this->calculate($this->clean_event($event));
|
||||
|
||||
// 6. Distribute
|
||||
$this->distribute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the array fields used by this points manager.
|
||||
*
|
||||
* Has to be declared per each trigger() call, as otherwise types are carried over in chained calls.
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function initialise_arrays()
|
||||
{
|
||||
// Array of points fields for the triggered action types
|
||||
$this->fields = [0 => [], 1 => []];
|
||||
|
||||
// Array of action types that are triggered
|
||||
$this->types = [];
|
||||
|
||||
// Array of users that can receive points for the triggered action
|
||||
$this->users = [];
|
||||
|
||||
// Array of point values required for the triggered action types
|
||||
$this->values = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all action types and their fields for the trigger action.
|
||||
*
|
||||
* $types
|
||||
* While the $this->actions array holds ALL the registered action types,
|
||||
* only a certain few are required. Only the required once are added to $this->types.
|
||||
*
|
||||
* $fields
|
||||
* Each action type has an array of point value keys with a language string as value.
|
||||
* Those keys are used for storing the points values set by the Administrator in the database.
|
||||
* Therefore a list is generated with all the fields that need to be retrieved from the database.
|
||||
*
|
||||
* @param string $action The action that is triggered
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function get_types_and_fields($action)
|
||||
{
|
||||
/** @var \phpbbstudio\aps\actions\type\action $type */
|
||||
foreach ($this->actions as $name => $type)
|
||||
{
|
||||
// Only add action types that are listed under this $action
|
||||
if ($type->get_action() === $action)
|
||||
{
|
||||
// Add this service to the action types
|
||||
$this->types[$name] = $type;
|
||||
|
||||
// Get scope: 0 = local | 1 = global
|
||||
$key = (int) $type->is_global();
|
||||
|
||||
// Get the type fields indexed by the scope
|
||||
$this->fields[$key] = array_merge($type->get_fields(), $this->fields[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all point values required by the triggered action types from the database.
|
||||
*
|
||||
* $values
|
||||
* Get all point values from the database that are in the $fields array and
|
||||
* have their forum identifier set to one provided in the $forum_ids array.
|
||||
* The values array will contain all point values indexed by the forum identifier,
|
||||
* if the fields are global, the forum identifier is set to 0.
|
||||
*
|
||||
* @param array|int $forum_ids The forum identifiers
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function get_values($forum_ids)
|
||||
{
|
||||
// Create array filled with integers
|
||||
$forum_ids = is_array($forum_ids) ? array_map('intval', $forum_ids) : [(int) $forum_ids];
|
||||
|
||||
// Make sure there are only unique and non-empty forum identifiers
|
||||
$forum_ids = array_unique($forum_ids);
|
||||
|
||||
$this->values = $this->valuator->get_points($this->fields, $forum_ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all users available for receiving points by the triggered action.
|
||||
*
|
||||
* $user_ids
|
||||
* The array of user identifiers provided from the place where the action is triggered.
|
||||
* This user's ($this->user) identifier is automatically added.
|
||||
*
|
||||
* $users
|
||||
* The array of users that are able to receive points, with a base array to make sure all keys are set,
|
||||
* aswell as all the users' current points.
|
||||
*
|
||||
* @param array|int $user_ids The user identifiers
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function set_users($user_ids)
|
||||
{
|
||||
// Create array filled with integers
|
||||
$user_ids = is_array($user_ids) ? array_map('intval', $user_ids) : [(int) $user_ids];
|
||||
|
||||
// Make sure to include this user ($this->user)
|
||||
$user_ids[] = (int) $this->user->data['user_id'];
|
||||
|
||||
// Make sure only unique users are set
|
||||
$user_ids = array_unique(array_filter($user_ids));
|
||||
|
||||
// If there is only one user, that will be this user, so no need to query
|
||||
if (count($user_ids) === 1)
|
||||
{
|
||||
// Build the base user array for this user
|
||||
$this->users[(int) $this->user->data['user_id']] = $this->user_array($this->user->data['user_points']);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Grab all the current point values for these users
|
||||
$user_points = $this->valuator->users($user_ids);
|
||||
|
||||
foreach ($user_ids as $user_id)
|
||||
{
|
||||
if (isset($user_points[$user_id]))
|
||||
{
|
||||
// Build the base user arrays
|
||||
$this->users[$user_id] = $this->user_array($user_points[$user_id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Lets make sure the anonymous user is never used
|
||||
unset($this->users[ANONYMOUS]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Let all the required action types calculate their user points.
|
||||
*
|
||||
* @param array $data Array of event data
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function calculate(array $data)
|
||||
{
|
||||
/** @var \phpbbstudio\aps\actions\type\action $type */
|
||||
foreach ($this->types as $type)
|
||||
{
|
||||
// Make the functions object available
|
||||
$type->set_functions($this->functions);
|
||||
|
||||
// Set the users
|
||||
$type->set_users($this->users);
|
||||
|
||||
// Check if APS is in Safe Mode
|
||||
if ($this->functions->safe_mode())
|
||||
{
|
||||
// If so, catch any exceptions and log them
|
||||
try
|
||||
{
|
||||
$type->calculate($data, $this->values);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
// Catch any error in the action type and log it!
|
||||
$this->log->add('critical', $this->user->data['user_id'], $this->user->ip, 'LOG_ACP_APS_CALCULATION_ERROR', time(), [$e->getMessage(), $e->getFile(), $e->getLine(), $this->functions->get_name()]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If not, calculate and let the exceptions do their thing.
|
||||
$type->calculate($data, $this->values);
|
||||
}
|
||||
|
||||
// Iterate over all the users
|
||||
foreach (array_keys($this->users) as $user_id)
|
||||
{
|
||||
// Get all received points for this user from this action type
|
||||
$this->users[$user_id]['actions'][] = $type->get_points($user_id);
|
||||
|
||||
// Check for logs that need approving
|
||||
if ($approve = $type->get_approve($user_id))
|
||||
{
|
||||
$this->users[$user_id]['approve'] = array_merge($this->users[$user_id]['approve'], $approve);
|
||||
}
|
||||
|
||||
// Check for logs that need disapproving
|
||||
if ($disapprove = $type->get_disapprove($user_id))
|
||||
{
|
||||
$this->users[$user_id]['disapprove'] = array_merge($this->users[$user_id]['disapprove'], $disapprove);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Distribute the points gained for all the users
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function distribute()
|
||||
{
|
||||
// Iterate over all the users
|
||||
foreach ($this->users as $user_id => $user_row)
|
||||
{
|
||||
// Iterate over all the action types
|
||||
foreach ($user_row['actions'] as $actions)
|
||||
{
|
||||
// Iterate over the arrays added per action type
|
||||
foreach ($actions as $action)
|
||||
{
|
||||
if ($action['approved'])
|
||||
{
|
||||
// Calculate the total points gained for this user
|
||||
$this->functions->equate_reference($this->users[$user_id]['total'], $action['points']);
|
||||
}
|
||||
|
||||
// Grab the post identifier, as we group the logs per post id
|
||||
$post_id = (int) $action['post_id'];
|
||||
|
||||
// Set the logs for this user
|
||||
$this->set_logs($user_id, $post_id, $action);
|
||||
}
|
||||
}
|
||||
|
||||
// And send it off: update user points and add log entries
|
||||
$this->distributor->distribute(
|
||||
$user_id,
|
||||
$this->users[$user_id]['total'],
|
||||
$this->users[$user_id]['logs'],
|
||||
$this->users[$user_id]['current']
|
||||
);
|
||||
|
||||
// Approve logs
|
||||
if ($user_row['approve'])
|
||||
{
|
||||
$user_points = $this->functions->equate_points($this->users[$user_id]['total'], $this->users[$user_id]['current']);
|
||||
|
||||
$this->distributor->approve($user_id, array_unique(array_filter($user_row['approve'])), $user_points);
|
||||
}
|
||||
|
||||
// Disapprove logs
|
||||
if ($user_row['disapprove'])
|
||||
{
|
||||
$this->distributor->disapprove($user_id, array_unique(array_filter($user_row['disapprove'])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the log entries for this user and index per post identifier.
|
||||
*
|
||||
* @param int $user_id The user identifier
|
||||
* @param int $post_id The post identifier
|
||||
* @param array $row The log array
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function set_logs($user_id, $post_id, array $row)
|
||||
{
|
||||
// Get the logs in a local variable for easier coding
|
||||
$logs = $this->users[$user_id]['logs'];
|
||||
|
||||
// Filter out the empty values except the first key
|
||||
if (empty($logs[$post_id]))
|
||||
{
|
||||
$first = array_splice($row['logs'], 0, 1);
|
||||
$row['logs'] = array_filter($row['logs']);
|
||||
$row['logs'] = $first + $row['logs'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$row['logs'] = array_filter($row['logs']);
|
||||
}
|
||||
|
||||
// If there are no logs entries yet under this post identifier
|
||||
if (empty($logs[$post_id]))
|
||||
{
|
||||
$logs[$post_id] = [
|
||||
'action' => (string) $this->main_log($row['logs']),
|
||||
'actions' => (array) $row['logs'],
|
||||
'approved' => (bool) $row['approved'],
|
||||
'forum_id' => (int) $row['forum_id'],
|
||||
'topic_id' => (int) $row['topic_id'],
|
||||
'post_id' => (int) $row['post_id'],
|
||||
'user_id' => (int) $user_id,
|
||||
'reportee_id' => (int) $this->user->data['user_id'],
|
||||
'reportee_ip' => (string) $this->user->ip,
|
||||
'points_old' => (double) $this->users[$user_id]['current'],
|
||||
'points_sum' => (double) $row['points'],
|
||||
'points_new' => (double) $this->functions->equate_points($this->users[$user_id]['current'], $row['points']),
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Else there already exists log entries under this post identifier, so merge this one in
|
||||
$this->merge_logs($logs[$post_id]['actions'], $row['logs']);
|
||||
|
||||
// Equate (by reference) the points gained ('sum') and the new total ('new').
|
||||
$this->functions->equate_reference($logs[$post_id]['points_sum'], $row['points']);
|
||||
$this->functions->equate_reference($logs[$post_id]['points_new'], $row['points']);
|
||||
}
|
||||
|
||||
// Set the logs in the global variable again
|
||||
$this->users[$user_id]['logs'] = $logs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "main" log entry, the first key of the array.
|
||||
*
|
||||
* @param array $logs The logs array
|
||||
* @return string The main log entry string
|
||||
* @access protected
|
||||
*/
|
||||
protected function main_log(array $logs)
|
||||
{
|
||||
reset($logs);
|
||||
$action = key($logs);
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge a log entry into existing log entries.
|
||||
*
|
||||
* Log entries are language strings (key) with point values (value).
|
||||
* array('APS_SOME_ACTION' => 5.00)
|
||||
*
|
||||
* If logs are merged, an array is created which has to be equated.
|
||||
* array('APS_SOME_ACTION' => array(5.00, 2.00)
|
||||
*
|
||||
* @param array $logs The existing log entries
|
||||
* @param array $array The log entry to merge in
|
||||
* @return void Passed by reference
|
||||
* @access protected
|
||||
*/
|
||||
protected function merge_logs(array &$logs, array $array)
|
||||
{
|
||||
// Merge the array in to the existing entries
|
||||
$logs = array_merge_recursive($logs, $array);
|
||||
|
||||
// Iterate over the logged actions
|
||||
foreach ($logs as $key => $value)
|
||||
{
|
||||
// If the logged action is no longer a single points value, equate it.
|
||||
if (is_array($value))
|
||||
{
|
||||
$logs[$key] = $this->functions->equate_array($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up a base array for this user.
|
||||
*
|
||||
* 'current
|
||||
* The user's current points
|
||||
*
|
||||
* 'actions'
|
||||
* Array that will be filled with arrays added by all the action types.
|
||||
*
|
||||
* 'points'
|
||||
* Array that will be filled with points added by all the action types.
|
||||
*
|
||||
* 'approve'
|
||||
* Array that will be filled with post identifiers that need to be approved from the logs table.
|
||||
*
|
||||
* 'disapprove'
|
||||
* Array that will be filled with post identifiers that need to be disapproved from the logs table.
|
||||
*
|
||||
* 'logs'
|
||||
* Array of log entries that are going to be added for this user.
|
||||
*
|
||||
* 'total'
|
||||
* The total points gained for this user, summing up all points per action type.
|
||||
*
|
||||
* @param double $points The user's current points
|
||||
* @return array The user's base array
|
||||
* @access protected
|
||||
*/
|
||||
protected function user_array($points)
|
||||
{
|
||||
return [
|
||||
'current' => (double) $points,
|
||||
'actions' => [],
|
||||
'points' => [],
|
||||
'approve' => [],
|
||||
'disapprove' => [],
|
||||
'logs' => [],
|
||||
'total' => 0.00,
|
||||
];
|
||||
}
|
||||
}
|
||||
116
ext/phpbbstudio/aps/actions/type/action.php
Normal file
116
ext/phpbbstudio/aps/actions/type/action.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Base
|
||||
*/
|
||||
interface action
|
||||
{
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @abstract This function MUST be present in all extending classes
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action();
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @abstract This function MUST be present in all extending classes
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global();
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @abstract This function MUST be present in all extending classes
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category();
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @abstract This function MUST be present in all extending classes
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data();
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @abstract This function MUST be present in all extending classes
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @return void
|
||||
*/
|
||||
public function calculate($data, $values);
|
||||
|
||||
/**
|
||||
* Get type value names.
|
||||
*
|
||||
* @return array An array of value names, the keys from get_data()
|
||||
* @access public
|
||||
*/
|
||||
public function get_fields();
|
||||
|
||||
/**
|
||||
* Set APS functions.
|
||||
*
|
||||
* @param \phpbbstudio\aps\core\functions $functions Common APS functions
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function set_functions($functions);
|
||||
|
||||
/**
|
||||
* Set users that are available for this action.
|
||||
*
|
||||
* @param array $users
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function set_users($users);
|
||||
|
||||
/**
|
||||
* Get the calculated points from this type for a given user identifier.
|
||||
*
|
||||
* @param int $user_id The user identifier
|
||||
* @return array The calculated points array(s)
|
||||
* @access public
|
||||
*/
|
||||
public function get_points($user_id);
|
||||
|
||||
/**
|
||||
* Get the post identifiers that need to be approved for this user.
|
||||
*
|
||||
* @param int $user_id The user identifier
|
||||
* @return array Array of post identifiers to approve for this user
|
||||
* @access protected
|
||||
*/
|
||||
public function get_approve($user_id);
|
||||
|
||||
/**
|
||||
* Get the post identifiers that need to be disapproved for this user.
|
||||
*
|
||||
* @param int $user_id The user identifier
|
||||
* @return array Array of post identifiers to disapprove for this user
|
||||
* @access protected
|
||||
*/
|
||||
public function get_disapprove($user_id);
|
||||
}
|
||||
159
ext/phpbbstudio/aps/actions/type/base.php
Normal file
159
ext/phpbbstudio/aps/actions/type/base.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Base interface
|
||||
*/
|
||||
abstract class base implements action
|
||||
{
|
||||
/** @var \phpbbstudio\aps\core\functions */
|
||||
protected $functions;
|
||||
|
||||
/** @var array The users available for this action */
|
||||
protected $users;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
abstract public function get_action();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
abstract public function is_global();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
abstract public function get_category();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
abstract public function get_data();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
abstract public function calculate($data, $values);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_fields()
|
||||
{
|
||||
return array_keys($this->get_data());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set_functions($functions)
|
||||
{
|
||||
$this->functions = $functions;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set_users($users)
|
||||
{
|
||||
$this->users = $users;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_points($user_id)
|
||||
{
|
||||
return $this->users[(int) $user_id]['points'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_approve($user_id)
|
||||
{
|
||||
return $this->users[(int) $user_id]['approve'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_disapprove($user_id)
|
||||
{
|
||||
return $this->users[(int) $user_id]['disapprove'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a points array from calculation to the provided user id.
|
||||
*
|
||||
* @param int $user_id The user identifier
|
||||
* @param array $points_array The points array to add
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function add($user_id, array $points_array)
|
||||
{
|
||||
// Make sure everything is set
|
||||
$array = array_merge([
|
||||
'approved' => true,
|
||||
'forum_id' => 0,
|
||||
'topic_id' => 0,
|
||||
'post_id' => 0,
|
||||
'points' => 0.00,
|
||||
'logs' => [],
|
||||
], $points_array);
|
||||
|
||||
$this->users[(int) $user_id]['points'][] = $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a post id to the array of logs to approve.
|
||||
*
|
||||
* @param int $user_id The user identifier
|
||||
* @param int $post_id The post identifier
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function approve($user_id, $post_id)
|
||||
{
|
||||
$this->users[(int) $user_id]['approve'][] = (int) $post_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a post id to the array of logs to disapprove.
|
||||
*
|
||||
* @param int $user_id The user identifier
|
||||
* @param int $post_id The post identifier
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function disapprove($user_id, $post_id)
|
||||
{
|
||||
$this->users[(int) $user_id]['disapprove'][] = (int) $post_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Equate two numbers.
|
||||
*
|
||||
* @param double $a The first number
|
||||
* @param double $b The second number
|
||||
* @param string $operator The equation operator
|
||||
* @return double The result of the equation
|
||||
* @access protected
|
||||
*/
|
||||
protected function equate($a, $b, $operator = '+')
|
||||
{
|
||||
return $this->functions->equate_points($a, $b, $operator);
|
||||
}
|
||||
}
|
||||
109
ext/phpbbstudio/aps/actions/type/birthday.php
Normal file
109
ext/phpbbstudio/aps/actions/type/birthday.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Birthday
|
||||
*/
|
||||
class birthday extends base
|
||||
{
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\user $user User object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(\phpbb\user $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'birthday';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'ACP_APS_POINTS_MISC';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
'aps_birthday' => 'APS_POINTS_BIRTHDAY',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
$value = $values[0];
|
||||
$logs = $this->get_data();
|
||||
|
||||
$date = $data['day'] . '-' . $data['month'];
|
||||
|
||||
foreach (array_keys($this->users) as $user_id)
|
||||
{
|
||||
// This user is automatically added by the manager, so make sure it's actually their birthday
|
||||
if ($user_id == $this->user->data['user_id'] && substr($this->user->data['user_birthday'], 0, 5) !== $date)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$points = [
|
||||
'points' => (double) $value['aps_birthday'],
|
||||
'logs' => [$logs['aps_birthday'] => $value['aps_birthday']],
|
||||
];
|
||||
|
||||
$this->add($user_id, $points);
|
||||
}
|
||||
}
|
||||
}
|
||||
101
ext/phpbbstudio/aps/actions/type/change.php
Normal file
101
ext/phpbbstudio/aps/actions/type/change.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Change author
|
||||
*/
|
||||
class change extends base
|
||||
{
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'change';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'MODERATE';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
'aps_mod_change' => 'APS_POINTS_MOD_CHANGE',
|
||||
'aps_user_change_from' => 'APS_POINTS_USER_CHANGE_FROM',
|
||||
'aps_user_change_to' => 'APS_POINTS_USER_CHANGE_TO',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
// Grab the data we need from the event
|
||||
$forum_id = (int) $data['post_info']['forum_id'];
|
||||
$topic_id = (int) $data['post_info']['topic_id'];
|
||||
$post_id = (int) $data['post_info']['post_id'];
|
||||
$from_id = (int) $data['post_info']['poster_id'];
|
||||
$to_id = (int) $data['userdata']['user_id'];
|
||||
|
||||
// Get some base variables
|
||||
$value = $values[$forum_id];
|
||||
$logs = $this->get_data();
|
||||
|
||||
foreach (array_keys($this->users) as $user_id)
|
||||
{
|
||||
$action = in_array($user_id, [$from_id, $to_id]) ? ($user_id == $from_id ? 'aps_user_change_from' : 'aps_user_change_to') : 'aps_mod_change';
|
||||
|
||||
$points = [
|
||||
'points' => (double) $value[$action],
|
||||
'forum_id' => (int) $forum_id,
|
||||
'topic_id' => (int) $topic_id,
|
||||
'post_id' => (int) $post_id,
|
||||
'logs' => [$logs[$action] => $value[$action]],
|
||||
];
|
||||
|
||||
$this->add($user_id, $points);
|
||||
}
|
||||
}
|
||||
}
|
||||
95
ext/phpbbstudio/aps/actions/type/copy.php
Normal file
95
ext/phpbbstudio/aps/actions/type/copy.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Copy
|
||||
*/
|
||||
class copy extends base
|
||||
{
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'copy';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'MODERATE';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
'aps_mod_copy' => 'APS_POINTS_MOD_COPY',
|
||||
'aps_user_copy' => 'APS_POINTS_USER_COPY',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
// Grab the data we need from the event
|
||||
$forum_id = (int) $data['topic_row']['forum_id'];
|
||||
$poster_id = (int) $data['topic_row']['topic_poster'];
|
||||
|
||||
// Get some base variables
|
||||
$value = $values[$forum_id];
|
||||
$logs = $this->get_data();
|
||||
|
||||
foreach (array_keys($this->users) as $user_id)
|
||||
{
|
||||
$action = ($user_id == $poster_id) ? 'aps_user_copy' : 'aps_mod_copy';
|
||||
|
||||
$points = [
|
||||
'points' => (double) $value[$action],
|
||||
'forum_id' => (int) $forum_id,
|
||||
'logs' => [$logs[$action] => $value[$action]],
|
||||
];
|
||||
|
||||
$this->add($user_id, $points);
|
||||
}
|
||||
}
|
||||
}
|
||||
131
ext/phpbbstudio/aps/actions/type/delete.php
Normal file
131
ext/phpbbstudio/aps/actions/type/delete.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Delete
|
||||
*/
|
||||
class delete extends base
|
||||
{
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\user $user User object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(\phpbb\user $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'delete';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'MODERATE';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
'aps_mod_delete_topic' => 'APS_POINTS_MOD_DELETE_TOPIC',
|
||||
'aps_user_delete_topic' => 'APS_POINTS_USER_DELETE_TOPIC',
|
||||
'aps_mod_delete_soft_topic' => 'APS_POINTS_MOD_DELETE_SOFT_TOPIC',
|
||||
'aps_user_delete_soft_topic' => 'APS_POINTS_USER_DELETE_SOFT_TOPIC',
|
||||
'aps_mod_delete_post' => 'APS_POINTS_MOD_DELETE_POST',
|
||||
'aps_user_delete_post' => 'APS_POINTS_USER_DELETE_POST',
|
||||
'aps_mod_delete_soft_post' => 'APS_POINTS_MOD_DELETE_SOFT_POST',
|
||||
'aps_user_delete_soft_post' => 'APS_POINTS_USER_DELETE_SOFT_POST',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
$action = $data['action'];
|
||||
$posts = $action === 'topic' ? $data['topics'] : $data['posts'];
|
||||
$is_soft = isset($data['is_soft']) ? $data['is_soft'] : false;
|
||||
|
||||
$key_user = 'aps_user_delete_' . ($is_soft ? 'soft_' : '') . $action;
|
||||
$key_mod = 'aps_mod_delete_' . ($is_soft ? 'soft_' : '') . $action;
|
||||
$strings = $this->get_data();
|
||||
|
||||
foreach ($posts as $post_data)
|
||||
{
|
||||
$forum_id = $post_data['forum_id'];
|
||||
$topic_id = $post_data['topic_id'];
|
||||
$post_id = $action === 'topic' ? $post_data['topic_first_post_id'] : $post_data['post_id'];
|
||||
$user_id = $action === 'topic' ? $post_data['topic_poster'] : $post_data['poster_id'];
|
||||
|
||||
$this->add($user_id, [
|
||||
'forum_id' => $forum_id,
|
||||
'topic_id' => $topic_id,
|
||||
'post_id' => $post_id,
|
||||
'points' => $values[$forum_id][$key_user],
|
||||
'logs' => [
|
||||
$strings[$key_user] => $values[$forum_id][$key_user],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->add($this->user->data['user_id'], [
|
||||
'forum_id' => $forum_id,
|
||||
'topic_id' => $topic_id,
|
||||
'post_id' => $post_id,
|
||||
'points' => $values[$forum_id][$key_mod],
|
||||
'logs' => [
|
||||
$strings[$key_mod] => $values[$forum_id][$key_mod],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
95
ext/phpbbstudio/aps/actions/type/edit.php
Normal file
95
ext/phpbbstudio/aps/actions/type/edit.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Edit
|
||||
*/
|
||||
class edit extends base
|
||||
{
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'edit';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'MODERATE';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
'aps_mod_edit' => 'APS_POINTS_MOD_EDIT',
|
||||
'aps_user_edit' => 'APS_POINTS_USER_EDIT',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
// Grab the data we need from the event
|
||||
$forum_id = (int) $data['data']['forum_id'];
|
||||
$poster_id = (int) $data['data']['poster_id'];
|
||||
|
||||
// Get some base variables
|
||||
$value = $values[$forum_id];
|
||||
$logs = $this->get_data();
|
||||
|
||||
foreach (array_keys($this->users) as $user_id)
|
||||
{
|
||||
$action = ($user_id == $poster_id) ? 'aps_user_edit' : 'aps_mod_edit';
|
||||
|
||||
$points = [
|
||||
'points' => (double) $value[$action],
|
||||
'forum_id' => (int) $forum_id,
|
||||
'logs' => [$logs[$action] => $value[$action]],
|
||||
];
|
||||
|
||||
$this->add($user_id, $points);
|
||||
}
|
||||
}
|
||||
}
|
||||
131
ext/phpbbstudio/aps/actions/type/lock.php
Normal file
131
ext/phpbbstudio/aps/actions/type/lock.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Lock
|
||||
*/
|
||||
class lock extends base
|
||||
{
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\user $user User object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(\phpbb\user $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'lock';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'MODERATE';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
'aps_mod_lock' => 'APS_POINTS_MOD_LOCK',
|
||||
'aps_user_lock' => 'APS_POINTS_USER_LOCK',
|
||||
'aps_mod_lock_post' => 'APS_POINTS_MOD_LOCK_POST',
|
||||
'aps_user_lock_post' => 'APS_POINTS_USER_LOCK_POST',
|
||||
'aps_mod_unlock' => 'APS_POINTS_MOD_UNLOCK',
|
||||
'aps_user_unlock' => 'APS_POINTS_USER_UNLOCK',
|
||||
'aps_mod_unlock_post' => 'APS_POINTS_MOD_UNLOCK_POST',
|
||||
'aps_user_unlock_post' => 'APS_POINTS_USER_UNLOCK_POST',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
$action = $data['action'];
|
||||
$posts = $data['data'];
|
||||
$s_topic = in_array($action, ['lock', 'unlock']);
|
||||
|
||||
$key_user = 'aps_user_' . $action;
|
||||
$key_mod = 'aps_mod_' . $action;
|
||||
$strings = $this->get_data();
|
||||
|
||||
foreach ($posts as $post_data)
|
||||
{
|
||||
$forum_id = $post_data['forum_id'];
|
||||
$topic_id = $post_data['topic_id'];
|
||||
$post_id = $s_topic ? $post_data['topic_first_post_id'] : $post_data['post_id'];
|
||||
$user_id = $s_topic ? $post_data['topic_poster'] : $post_data['poster_id'];
|
||||
|
||||
$this->add($user_id, [
|
||||
'forum_id' => $forum_id,
|
||||
'topic_id' => $topic_id,
|
||||
'post_id' => $post_id,
|
||||
'points' => $values[$forum_id][$key_user],
|
||||
'logs' => [
|
||||
$strings[$key_user] => $values[$forum_id][$key_user],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->add($this->user->data['user_id'], [
|
||||
'forum_id' => $forum_id,
|
||||
'topic_id' => $topic_id,
|
||||
'post_id' => $post_id,
|
||||
'points' => $values[$forum_id][$key_mod],
|
||||
'logs' => [
|
||||
$strings[$key_mod] => $values[$forum_id][$key_mod],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
113
ext/phpbbstudio/aps/actions/type/merge.php
Normal file
113
ext/phpbbstudio/aps/actions/type/merge.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Merge
|
||||
*/
|
||||
class merge extends base
|
||||
{
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\user $user User object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(\phpbb\user $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'merge';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'MODERATE';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
'aps_mod_merge' => 'APS_POINTS_MOD_MERGE',
|
||||
'aps_user_merge' => 'APS_POINTS_USER_MERGE',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
$topics = $data['all_topic_data'];
|
||||
$topic_id = $data['to_topic_id'];
|
||||
$forum_id = $topics[$topic_id]['forum_id'];
|
||||
|
||||
$values = $values[$forum_id];
|
||||
$strings = $this->get_data();
|
||||
|
||||
foreach ($topics as $topic)
|
||||
{
|
||||
$this->add($topic['topic_poster'], [
|
||||
'forum_id' => (int) $forum_id,
|
||||
'topic_id' => (int) $topic_id,
|
||||
'points' => $values['aps_user_merge'],
|
||||
'logs' => [$strings['aps_user_merge'] => $values['aps_user_merge']],
|
||||
]);
|
||||
|
||||
$this->add($this->user->data['user_id'], [
|
||||
'forum_id' => (int) $forum_id,
|
||||
'topic_id' => (int) $topic_id,
|
||||
'points' => $values['aps_mod_merge'],
|
||||
'logs' => [$strings['aps_mod_merge'] => $values['aps_mod_merge']],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
127
ext/phpbbstudio/aps/actions/type/move.php
Normal file
127
ext/phpbbstudio/aps/actions/type/move.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Move
|
||||
*/
|
||||
class move extends base
|
||||
{
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\user $user User object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(\phpbb\user $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'move';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'MODERATE';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
'aps_mod_move_post' => 'APS_POINTS_MOD_MOVE_POST',
|
||||
'aps_user_move_post' => 'APS_POINTS_USER_MOVE_POST',
|
||||
'aps_mod_move_topic' => 'APS_POINTS_MOD_MOVE_TOPIC',
|
||||
'aps_user_move_topic' => 'APS_POINTS_USER_MOVE_TOPIC',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
$action = $data['action'];
|
||||
$s_topic = $action === 'topic';
|
||||
$posts = $s_topic ? $data['topics'] : $data['posts'];
|
||||
|
||||
$key_user = 'aps_user_move_' . $action;
|
||||
$key_mod = 'aps_mod_move_' . $action;
|
||||
$strings = $this->get_data();
|
||||
|
||||
foreach ($posts as $post)
|
||||
{
|
||||
$forum_id = $post['forum_id'];
|
||||
$topic_id = $post['topic_id'];
|
||||
$post_id = $s_topic ? $post['topic_first_post_id'] : $post['post_id'];
|
||||
$user_id = $s_topic ? $post['topic_poster'] : $post['poster_id'];
|
||||
|
||||
$this->add($user_id, [
|
||||
'forum_id' => $forum_id,
|
||||
'topic_id' => $topic_id,
|
||||
'post_id' => $post_id,
|
||||
'points' => $values[$forum_id][$key_user],
|
||||
'logs' => [
|
||||
$strings[$key_user] => $values[$forum_id][$key_user],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->add($this->user->data['user_id'], [
|
||||
'forum_id' => $forum_id,
|
||||
'topic_id' => $topic_id,
|
||||
'post_id' => $post_id,
|
||||
'points' => $values[$forum_id][$key_mod],
|
||||
'logs' => [
|
||||
$strings[$key_mod] => $values[$forum_id][$key_mod],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
202
ext/phpbbstudio/aps/actions/type/pm.php
Normal file
202
ext/phpbbstudio/aps/actions/type/pm.php
Normal file
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Private message
|
||||
*/
|
||||
class pm extends base
|
||||
{
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var \phpbb\textformatter\s9e\utils */
|
||||
protected $utils;
|
||||
|
||||
/** @var array Ignore criteria constants */
|
||||
protected $ignore;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\config\config $config Config object
|
||||
* @param \phpbb\textformatter\s9e\utils $utils s9e Textformatter utilities object
|
||||
* @param array $constants APS Constants
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(\phpbb\config\config $config, \phpbb\textformatter\s9e\utils $utils, array $constants)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->utils = $utils;
|
||||
$this->ignore = $constants['ignore'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'pm';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'PRIVATE_MESSAGE';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
// Initial points
|
||||
'aps_pm_base' => 'APS_POINTS_PM',
|
||||
|
||||
// Recipients points
|
||||
'aps_pm_per_recipient' => 'APS_POINTS_PM_PER_RECIPIENT',
|
||||
|
||||
// Text points
|
||||
'aps_pm_per_char' => 'APS_POINTS_PER_CHAR',
|
||||
'aps_pm_per_word' => 'APS_POINTS_PER_WORD',
|
||||
'aps_pm_per_quote' => 'APS_POINTS_PER_QUOTE',
|
||||
|
||||
// Attachment points
|
||||
'aps_pm_has_attach' => 'APS_POINTS_ATTACH_HAS',
|
||||
'aps_pm_per_attach' => 'APS_POINTS_ATTACH_PER',
|
||||
|
||||
// Modification points
|
||||
'aps_pm_edit' => 'APS_POINTS_EDIT',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
// Grab event data
|
||||
$mode = $data['mode'];
|
||||
$message = $data['data']['message'];
|
||||
$attachments = !empty($data['data']['attachment_data']) ? $data['data']['attachment_data'] : [];
|
||||
$recipients = $data['pm_data']['recipients'];
|
||||
|
||||
$logs = [];
|
||||
$values = $values[0];
|
||||
$strings = $this->get_data();
|
||||
|
||||
switch ($mode)
|
||||
{
|
||||
case 'edit':
|
||||
$points = $logs[$strings['aps_pm_' . $mode]] = $values['aps_pm_' . $mode];
|
||||
break;
|
||||
|
||||
default:
|
||||
// Initial points
|
||||
$points = $logs[$strings['aps_pm_base']] = $values['aps_pm_base'];
|
||||
|
||||
// Recipient points
|
||||
$points += $logs[$strings['aps_pm_per_recipient']] = $this->equate($values['aps_pm_per_recipient'], count($recipients), '*');
|
||||
|
||||
// Text points
|
||||
$quotes = $this->utils->get_outermost_quote_authors($message);
|
||||
$message = $this->utils->remove_bbcode($message, 'quote');
|
||||
$message = $this->utils->remove_bbcode($message, 'attachment');
|
||||
$message = $this->utils->clean_formatting($message);
|
||||
$words = $exclude_words = array_filter(preg_split('/[\s]+/', $message));
|
||||
$chars = $exclude_chars = implode('', $words);
|
||||
|
||||
if ($min = $this->config['aps_points_exclude_words'])
|
||||
{
|
||||
$exclude_words = array_filter($words, function($word) use ($min)
|
||||
{
|
||||
return strlen($word) > $min;
|
||||
});
|
||||
|
||||
if ($this->config['aps_points_exclude_chars'])
|
||||
{
|
||||
$exclude_chars = implode('', $exclude_words);
|
||||
}
|
||||
}
|
||||
|
||||
// Check ignore criteria
|
||||
if ($this->config['aps_ignore_criteria'])
|
||||
{
|
||||
$ignore_words = $this->config['aps_ignore_excluded_words'] ? $exclude_words : $words;
|
||||
$ignore_chars = $this->config['aps_ignore_excluded_chars'] ? $exclude_chars : $chars;
|
||||
|
||||
$ignore_words = count($ignore_words) < $this->config['aps_ignore_min_words'];
|
||||
$ignore_chars = strlen($ignore_chars) < $this->config['aps_ignore_min_chars'];
|
||||
|
||||
if (($this->config['aps_ignore_criteria'] == $this->ignore['both'] && $ignore_words && $ignore_chars)
|
||||
|| ($this->config['aps_ignore_criteria'] == $this->ignore['words'] && $ignore_words)
|
||||
|| ($this->config['aps_ignore_criteria'] == $this->ignore['chars'] && $ignore_chars))
|
||||
{
|
||||
$points = 0;
|
||||
|
||||
// Break out of calculation
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$words = $exclude_words;
|
||||
$chars = $exclude_chars;
|
||||
|
||||
$points += $logs[$strings['aps_pm_per_quote']] = $this->equate($values['aps_pm_per_quote'], count($quotes), '*');
|
||||
$points += $logs[$strings['aps_pm_per_word']] = $this->equate($values['aps_pm_per_word'], count($words), '*');
|
||||
$points += $logs[$strings['aps_pm_per_char']] = $this->equate($values['aps_pm_per_char'], strlen($chars), '*');
|
||||
|
||||
// Attachment points
|
||||
if (!empty($attachments))
|
||||
{
|
||||
$points += $logs[$strings['aps_pm_has_attach']] = $values['aps_pm_has_attach'];
|
||||
$points += $logs[$strings['aps_pm_per_attach']] = $this->equate($values['aps_pm_per_attach'], count($attachments), '*');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (array_keys($this->users) as $user_id)
|
||||
{
|
||||
$this->add($user_id, [
|
||||
'points' => $points,
|
||||
'logs' => $logs,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
211
ext/phpbbstudio/aps/actions/type/post.php
Normal file
211
ext/phpbbstudio/aps/actions/type/post.php
Normal file
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Post
|
||||
*/
|
||||
class post extends base
|
||||
{
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var \phpbb\textformatter\s9e\utils */
|
||||
protected $utils;
|
||||
|
||||
/** @var array Ignore criteria constants */
|
||||
protected $ignore;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\config\config $config Config object
|
||||
* @param \phpbb\textformatter\s9e\utils $utils s9e Textformatter utilities object
|
||||
* @param array $constants APS Constants
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(\phpbb\config\config $config, \phpbb\textformatter\s9e\utils $utils, array $constants)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->utils = $utils;
|
||||
$this->ignore = $constants['ignore'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'post';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'POST';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
// Initial points
|
||||
'aps_post_base' => 'APS_POINTS_POST',
|
||||
|
||||
// Text points
|
||||
'aps_post_per_char' => 'APS_POINTS_PER_CHAR',
|
||||
'aps_post_per_word' => 'APS_POINTS_PER_WORD',
|
||||
'aps_post_per_quote' => 'APS_POINTS_PER_QUOTE',
|
||||
|
||||
// Attachment points
|
||||
'aps_post_has_attach' => 'APS_POINTS_ATTACH_HAS',
|
||||
'aps_post_per_attach' => 'APS_POINTS_ATTACH_PER',
|
||||
|
||||
// Modification points
|
||||
'aps_post_edit' => 'APS_POINTS_EDIT',
|
||||
'aps_post_delete' => 'APS_POINTS_DELETE',
|
||||
'aps_post_delete_soft' => 'APS_POINTS_DELETE_SOFT',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
// Grab event data
|
||||
$mode = $data['mode'];
|
||||
$s_delete = in_array($mode, ['delete', 'soft_delete']);
|
||||
$forum_id = $s_delete ? $data['forum_id'] : $data['data']['forum_id'];
|
||||
$topic_id = $s_delete ? $data['topic_id'] : $data['data']['topic_id'];
|
||||
$post_id = $s_delete ? $data['post_id'] : $data['data']['post_id'];
|
||||
$message = $s_delete ? '' : $data['data']['message'];
|
||||
$s_approved = !$s_delete ? $data['post_visibility'] == ITEM_APPROVED : true;
|
||||
$attachments = $s_delete ? [] : $data['data']['attachment_data'];
|
||||
|
||||
$logs = [];
|
||||
$values = $values[$forum_id];
|
||||
$strings = $this->get_data();
|
||||
|
||||
switch ($mode)
|
||||
{
|
||||
/** @noinspection PhpMissingBreakStatementInspection */
|
||||
case 'soft_delete':
|
||||
$mode = 'delete_soft';
|
||||
// no break;
|
||||
case 'edit':
|
||||
case 'delete':
|
||||
$points = $logs[$strings['aps_post_' . $mode]] = $values['aps_post_' . $mode];
|
||||
break;
|
||||
|
||||
default:
|
||||
// Initial points
|
||||
$points = $logs[$strings['aps_post_base']] = $values['aps_post_base'];
|
||||
|
||||
// Text points
|
||||
$quotes = $this->utils->get_outermost_quote_authors($message);
|
||||
$message = $this->utils->remove_bbcode($message, 'quote');
|
||||
$message = $this->utils->remove_bbcode($message, 'attachment');
|
||||
$message = $this->utils->clean_formatting($message);
|
||||
$words = $exclude_words = array_filter(preg_split('/[\s]+/', $message));
|
||||
$chars = $exclude_chars = implode('', $words);
|
||||
|
||||
if ($min = $this->config['aps_points_exclude_words'])
|
||||
{
|
||||
$exclude_words = array_filter($words, function($word) use ($min)
|
||||
{
|
||||
return strlen($word) > $min;
|
||||
});
|
||||
|
||||
if ($this->config['aps_points_exclude_chars'])
|
||||
{
|
||||
$exclude_chars = implode('', $exclude_words);
|
||||
}
|
||||
}
|
||||
|
||||
// Check ignore criteria
|
||||
if ($this->config['aps_ignore_criteria'])
|
||||
{
|
||||
$ignore_words = $this->config['aps_ignore_excluded_words'] ? $exclude_words : $words;
|
||||
$ignore_chars = $this->config['aps_ignore_excluded_chars'] ? $exclude_chars : $chars;
|
||||
|
||||
$ignore_words = count($ignore_words) < $this->config['aps_ignore_min_words'];
|
||||
$ignore_chars = strlen($ignore_chars) < $this->config['aps_ignore_min_chars'];
|
||||
|
||||
if (($this->config['aps_ignore_criteria'] == $this->ignore['both'] && $ignore_words && $ignore_chars)
|
||||
|| ($this->config['aps_ignore_criteria'] == $this->ignore['words'] && $ignore_words)
|
||||
|| ($this->config['aps_ignore_criteria'] == $this->ignore['chars'] && $ignore_chars))
|
||||
{
|
||||
$points = 0;
|
||||
|
||||
// Break out of calculation
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$words = $exclude_words;
|
||||
$chars = $exclude_chars;
|
||||
|
||||
$points += $logs[$strings['aps_post_per_quote']] = $this->equate($values['aps_post_per_quote'], count($quotes), '*');
|
||||
$points += $logs[$strings['aps_post_per_word']] = $this->equate($values['aps_post_per_word'], count($words), '*');
|
||||
$points += $logs[$strings['aps_post_per_char']] = $this->equate($values['aps_post_per_char'], strlen($chars), '*');
|
||||
|
||||
// Attachment points
|
||||
if (!empty($attachments))
|
||||
{
|
||||
$points += $logs[$strings['aps_post_has_attach']] = $values['aps_post_has_attach'];
|
||||
$points += $logs[$strings['aps_post_per_attach']] = $this->equate($values['aps_post_per_attach'], count($attachments), '*');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (array_keys($this->users) as $user_id)
|
||||
{
|
||||
$this->add($user_id, [
|
||||
'approved' => $s_approved,
|
||||
'forum_id' => $forum_id,
|
||||
'topic_id' => $topic_id,
|
||||
'post_id' => $post_id,
|
||||
'points' => $points,
|
||||
'logs' => $logs,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
140
ext/phpbbstudio/aps/actions/type/queue.php
Normal file
140
ext/phpbbstudio/aps/actions/type/queue.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Queue
|
||||
*/
|
||||
class queue extends base
|
||||
{
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\user $user User object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(\phpbb\user $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'queue';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'MODERATE';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
'aps_mod_restore' => 'APS_POINTS_MOD_RESTORE',
|
||||
'aps_mod_approve' => 'APS_POINTS_MOD_APPROVE',
|
||||
'aps_mod_disapprove' => 'APS_POINTS_MOD_DISAPPROVE',
|
||||
'aps_user_restore' => 'APS_POINTS_USER_RESTORE',
|
||||
'aps_user_approve' => 'APS_POINTS_USER_APPROVE',
|
||||
'aps_user_disapprove' => 'APS_POINTS_USER_DISAPPROVE',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
$action = $data['mode'];
|
||||
$s_post = isset($data['post_info']);
|
||||
$posts = $s_post ? $data['post_info'] : $data['topic_info'];
|
||||
|
||||
$key_user = 'aps_user_' . $action;
|
||||
$key_mod = 'aps_mod_' . $action;
|
||||
$strings = $this->get_data();
|
||||
|
||||
foreach ($posts as $post_id => $post_data)
|
||||
{
|
||||
$user_id = $s_post ? $post_data['poster_id'] : $post_data['topic_poster'];
|
||||
$topic_id = $post_data['topic_id'];
|
||||
$forum_id = $post_data['forum_id'];
|
||||
|
||||
$logs = [];
|
||||
|
||||
$points = $logs[$strings[$key_user]] = $values[$forum_id][$key_user];
|
||||
|
||||
switch ($action)
|
||||
{
|
||||
case 'approve':
|
||||
$this->approve($user_id, $post_id);
|
||||
break;
|
||||
case 'disapprove':
|
||||
$this->disapprove($user_id, $post_id);
|
||||
break;
|
||||
}
|
||||
|
||||
$this->add($user_id, [
|
||||
'forum_id' => $forum_id,
|
||||
'topic_id' => $topic_id,
|
||||
'post_id' => $post_id,
|
||||
'points' => $points,
|
||||
'logs' => $logs,
|
||||
]);
|
||||
|
||||
$this->add($this->user->data['user_id'], [
|
||||
'forum_id' => $forum_id,
|
||||
'topic_id' => $topic_id,
|
||||
'post_id' => $post_id,
|
||||
'points' => $values[$forum_id][$key_mod],
|
||||
'logs' => [
|
||||
$strings[$key_mod] => $values[$forum_id][$key_mod],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
91
ext/phpbbstudio/aps/actions/type/register.php
Normal file
91
ext/phpbbstudio/aps/actions/type/register.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Register
|
||||
*/
|
||||
class register extends base
|
||||
{
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'register';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'ACP_APS_POINTS_MISC';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
'aps_register' => 'APS_POINTS_REGISTER',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
$value = $values[0];
|
||||
$logs = $this->get_data();
|
||||
|
||||
foreach (array_keys($this->users) as $user_id)
|
||||
{
|
||||
if ($user_id == ANONYMOUS)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$points = [
|
||||
'points' => (double) $value['aps_register'],
|
||||
'logs' => [$logs['aps_register'] => $value['aps_register']],
|
||||
];
|
||||
|
||||
$this->add($user_id, $points);
|
||||
}
|
||||
}
|
||||
}
|
||||
243
ext/phpbbstudio/aps/actions/type/topic.php
Normal file
243
ext/phpbbstudio/aps/actions/type/topic.php
Normal file
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Topic
|
||||
*/
|
||||
class topic extends base
|
||||
{
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var \phpbb\textformatter\s9e\utils */
|
||||
protected $utils;
|
||||
|
||||
/** @var array Ignore criteria constants */
|
||||
protected $ignore;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\config\config $config Config object
|
||||
* @param \phpbb\textformatter\s9e\utils $utils s9e Textformatter utilities object
|
||||
* @param array $constants APS Constants
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(\phpbb\config\config $config, \phpbb\textformatter\s9e\utils $utils, array $constants)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->utils = $utils;
|
||||
$this->ignore = $constants['ignore'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'topic';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'TOPIC';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
// Type points
|
||||
'aps_topic_base' => 'APS_POINTS_TOPIC',
|
||||
'aps_topic_sticky' => 'APS_POINTS_STICKY',
|
||||
'aps_topic_announce' => 'APS_POINTS_ANNOUNCE',
|
||||
'aps_topic_global' => 'APS_POINTS_GLOBAL',
|
||||
|
||||
// Text points
|
||||
'aps_topic_per_char' => 'APS_POINTS_PER_CHAR',
|
||||
'aps_topic_per_word' => 'APS_POINTS_PER_WORD',
|
||||
'aps_topic_per_quote' => 'APS_POINTS_PER_QUOTE',
|
||||
|
||||
// Attachment points
|
||||
'aps_topic_has_attach' => 'APS_POINTS_ATTACH_HAS',
|
||||
'aps_topic_per_attach' => 'APS_POINTS_ATTACH_PER',
|
||||
|
||||
// Poll points
|
||||
'aps_topic_has_poll' => 'APS_POINTS_POLL_HAS',
|
||||
'aps_topic_per_option' => 'APS_POINTS_POLL_OPTION',
|
||||
|
||||
// Miscellaneous
|
||||
'aps_topic_bump' => 'APS_POINTS_BUMP',
|
||||
'aps_topic_edit' => 'APS_POINTS_EDIT',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
$mode = $data['mode'];
|
||||
$s_bump = $mode === 'bump';
|
||||
|
||||
$type = !$s_bump ? $data['topic_type'] : '';
|
||||
$post_data = !$s_bump ? $data['data'] : $data['post_data'];
|
||||
|
||||
$s_approved = isset($data['post_visibility']) ? $data['post_visibility'] == ITEM_APPROVED : true;
|
||||
$poll = isset($data['poll']['poll_options']) ? $data['poll']['poll_options'] : [];
|
||||
|
||||
$forum_id = $post_data['forum_id'];
|
||||
$topic_id = $post_data['topic_id'];
|
||||
$post_id = !$s_bump ? $post_data['post_id'] : 0;
|
||||
$message = !$s_bump ? $post_data['message'] : '';
|
||||
$attachments = !$s_bump ? $post_data['attachment_data'] : [];
|
||||
|
||||
$logs = [];
|
||||
$values = $values[$forum_id];
|
||||
$strings = $this->get_data();
|
||||
|
||||
switch ($mode)
|
||||
{
|
||||
case 'bump':
|
||||
case 'edit':
|
||||
$points = $logs[$strings['aps_topic_' . $mode]] = $values['aps_topic_' . $mode];
|
||||
break;
|
||||
|
||||
default:
|
||||
// Initial type points
|
||||
switch ($type)
|
||||
{
|
||||
default:
|
||||
case POST_NORMAL:
|
||||
$points = $logs[$strings['aps_topic_base']] = $values['aps_topic_base'];
|
||||
break;
|
||||
|
||||
case POST_STICKY:
|
||||
$points = $logs[$strings['aps_topic_sticky']] = $values['aps_topic_sticky'];
|
||||
break;
|
||||
|
||||
case POST_ANNOUNCE:
|
||||
$points = $logs[$strings['aps_topic_announce']] = $values['aps_topic_announce'];
|
||||
break;
|
||||
|
||||
case POST_GLOBAL:
|
||||
$points = $logs[$strings['aps_topic_global']] = $values['aps_topic_global'];
|
||||
break;
|
||||
}
|
||||
|
||||
// Text points
|
||||
$quotes = $this->utils->get_outermost_quote_authors($message);
|
||||
$message = $this->utils->remove_bbcode($message, 'quote');
|
||||
$message = $this->utils->remove_bbcode($message, 'attachment');
|
||||
$message = $this->utils->clean_formatting($message);
|
||||
$words = $exclude_words = array_filter(preg_split('/[\s]+/', $message));
|
||||
$chars = $exclude_chars = implode('', $words);
|
||||
|
||||
if ($min = $this->config['aps_points_exclude_words'])
|
||||
{
|
||||
$exclude_words = array_filter($words, function($word) use ($min)
|
||||
{
|
||||
return strlen($word) > $min;
|
||||
});
|
||||
|
||||
if ($this->config['aps_points_exclude_chars'])
|
||||
{
|
||||
$exclude_chars = implode('', $exclude_words);
|
||||
}
|
||||
}
|
||||
|
||||
// Check ignore criteria
|
||||
if ($this->config['aps_ignore_criteria'])
|
||||
{
|
||||
$ignore_words = $this->config['aps_ignore_excluded_words'] ? $exclude_words : $words;
|
||||
$ignore_chars = $this->config['aps_ignore_excluded_chars'] ? $exclude_chars : $chars;
|
||||
|
||||
$ignore_words = count($ignore_words) < $this->config['aps_ignore_min_words'];
|
||||
$ignore_chars = strlen($ignore_chars) < $this->config['aps_ignore_min_chars'];
|
||||
|
||||
if (($this->config['aps_ignore_criteria'] == $this->ignore['both'] && $ignore_words && $ignore_chars)
|
||||
|| ($this->config['aps_ignore_criteria'] == $this->ignore['words'] && $ignore_words)
|
||||
|| ($this->config['aps_ignore_criteria'] == $this->ignore['chars'] && $ignore_chars))
|
||||
{
|
||||
$points = 0;
|
||||
|
||||
// Break out of calculation
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$words = $exclude_words;
|
||||
$chars = $exclude_chars;
|
||||
|
||||
$points += $logs[$strings['aps_topic_per_quote']] = $this->equate($values['aps_topic_per_quote'], count($quotes), '*');
|
||||
$points += $logs[$strings['aps_topic_per_word']] = $this->equate($values['aps_topic_per_word'], count($words), '*');
|
||||
$points += $logs[$strings['aps_topic_per_char']] = $this->equate($values['aps_topic_per_char'], strlen($chars), '*');
|
||||
|
||||
// Attachment points
|
||||
if (!empty($attachments))
|
||||
{
|
||||
$points += $logs[$strings['aps_topic_has_attach']] = $values['aps_topic_has_attach'];
|
||||
$points += $logs[$strings['aps_topic_per_attach']] = $this->equate($values['aps_topic_per_attach'], count($attachments), '*');
|
||||
}
|
||||
|
||||
// Poll points
|
||||
if ($poll)
|
||||
{
|
||||
$points += $logs[$strings['aps_topic_has_poll']] = $values['aps_topic_has_poll'];
|
||||
$points += $logs[$strings['aps_topic_per_option']] = $this->equate($values['aps_topic_per_option'], count($poll), '*');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (array_keys($this->users) as $user_id)
|
||||
{
|
||||
$this->add($user_id, [
|
||||
'approved' => $s_approved,
|
||||
'forum_id' => $forum_id,
|
||||
'topic_id' => $topic_id,
|
||||
'post_id' => $post_id,
|
||||
'points' => $points,
|
||||
'logs' => $logs,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
132
ext/phpbbstudio/aps/actions/type/topic_type.php
Normal file
132
ext/phpbbstudio/aps/actions/type/topic_type.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Topic type
|
||||
*/
|
||||
class topic_type extends base
|
||||
{
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'topic_type';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'ACP_APS_TOPIC_TYPES';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
'aps_mod_normal_sticky' => 'APS_POINTS_MOD_NORMAL_STICKY',
|
||||
'aps_mod_normal_announce' => 'APS_POINTS_MOD_NORMAL_ANNOUNCE',
|
||||
'aps_mod_normal_global' => 'APS_POINTS_MOD_NORMAL_GLOBAL',
|
||||
'aps_mod_sticky_normal' => 'APS_POINTS_MOD_STICKY_NORMAL',
|
||||
'aps_mod_sticky_announce' => 'APS_POINTS_MOD_STICKY_ANNOUNCE',
|
||||
'aps_mod_sticky_global' => 'APS_POINTS_MOD_STICKY_GLOBAL',
|
||||
'aps_mod_announce_normal' => 'APS_POINTS_MOD_ANNOUNCE_NORMAL',
|
||||
'aps_mod_announce_sticky' => 'APS_POINTS_MOD_ANNOUNCE_STICKY',
|
||||
'aps_mod_announce_global' => 'APS_POINTS_MOD_ANNOUNCE_GLOBAL',
|
||||
'aps_mod_global_normal' => 'APS_POINTS_MOD_GLOBAL_NORMAL',
|
||||
'aps_mod_global_sticky' => 'APS_POINTS_MOD_GLOBAL_STICKY',
|
||||
'aps_mod_global_announce' => 'APS_POINTS_MOD_GLOBAL_ANNOUNCE',
|
||||
|
||||
'aps_user_normal_sticky' => 'APS_POINTS_USER_NORMAL_STICKY',
|
||||
'aps_user_normal_announce' => 'APS_POINTS_USER_NORMAL_ANNOUNCE',
|
||||
'aps_user_normal_global' => 'APS_POINTS_USER_NORMAL_GLOBAL',
|
||||
'aps_user_sticky_normal' => 'APS_POINTS_USER_STICKY_NORMAL',
|
||||
'aps_user_sticky_announce' => 'APS_POINTS_USER_STICKY_ANNOUNCE',
|
||||
'aps_user_sticky_global' => 'APS_POINTS_USER_STICKY_GLOBAL',
|
||||
'aps_user_announce_normal' => 'APS_POINTS_USER_ANNOUNCE_NORMAL',
|
||||
'aps_user_announce_sticky' => 'APS_POINTS_USER_ANNOUNCE_STICKY',
|
||||
'aps_user_announce_global' => 'APS_POINTS_USER_ANNOUNCE_GLOBAL',
|
||||
'aps_user_global_normal' => 'APS_POINTS_USER_GLOBAL_NORMAL',
|
||||
'aps_user_global_sticky' => 'APS_POINTS_USER_GLOBAL_STICKY',
|
||||
'aps_user_global_announce' => 'APS_POINTS_USER_GLOBAL_ANNOUNCE',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
// Grab the data we need from the event
|
||||
$forum_id = (int) $data['data']['forum_id'];
|
||||
$topic_id = (int) $data['data']['topic_id'];
|
||||
$post_id = (int) $data['data']['post_id'];
|
||||
$poster_id = (int) $data['post_data']['topic_poster'];
|
||||
$type_from = (int) $data['type_from'];
|
||||
$type_to = (int) $data['type_to'];
|
||||
|
||||
$types = [
|
||||
POST_NORMAL => 'normal',
|
||||
POST_STICKY => 'sticky',
|
||||
POST_ANNOUNCE => 'announce',
|
||||
POST_GLOBAL => 'global',
|
||||
];
|
||||
|
||||
// Get some base variables
|
||||
$value = $values[$forum_id];
|
||||
$logs = $this->get_data();
|
||||
|
||||
foreach (array_keys($this->users) as $user_id)
|
||||
{
|
||||
$action = ($user_id == $poster_id) ? 'aps_user_' : 'aps_mod_';
|
||||
$action .= $types[$type_from] . '_' . $types[$type_to];
|
||||
|
||||
$points = [
|
||||
'points' => (double) $value[$action],
|
||||
'forum_id' => (int) $forum_id,
|
||||
'topic_id' => (int) $topic_id,
|
||||
'post_id' => (int) $post_id,
|
||||
'logs' => [$logs[$action] => $value[$action]],
|
||||
];
|
||||
|
||||
$this->add($user_id, $points);
|
||||
}
|
||||
}
|
||||
}
|
||||
117
ext/phpbbstudio/aps/actions/type/vote.php
Normal file
117
ext/phpbbstudio/aps/actions/type/vote.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Vote
|
||||
*/
|
||||
class vote extends base
|
||||
{
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'vote';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'ACP_APS_POINTS_MISC';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
'aps_vote' => 'APS_POINTS_PER_VOTE',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
$votes = $data['vote_counts'];
|
||||
$options = $data['poll_info'];
|
||||
$forum_id = $data['forum_id'];
|
||||
$topic_id = $data['topic_data']['topic_id'];
|
||||
$value = $values[$forum_id]['aps_vote'];
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($options as $option)
|
||||
{
|
||||
$new = $votes[$option['poll_option_id']];
|
||||
$old = $option['poll_option_total'];
|
||||
|
||||
if ($new > $old)
|
||||
{
|
||||
$i++;
|
||||
}
|
||||
else if ($new < $old)
|
||||
{
|
||||
$i--;
|
||||
}
|
||||
}
|
||||
|
||||
if ($i !== 0)
|
||||
{
|
||||
$points = $this->equate($value, $i, '*');
|
||||
|
||||
foreach ($this->users as $user_id => $user_data)
|
||||
{
|
||||
$string = $points > 0 ? 'APS_POINTS_VOTE_ADDED' : 'APS_POINTS_VOTE_REMOVED';
|
||||
|
||||
$this->add($user_id, [
|
||||
'forum_id' => $forum_id,
|
||||
'topic_id' => $topic_id,
|
||||
'post_id' => 0,
|
||||
'points' => $points,
|
||||
'logs' => [
|
||||
$string => $points,
|
||||
'APS_POINTS_VOTE_AMOUNT' => $i,
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
104
ext/phpbbstudio/aps/actions/type/warn.php
Normal file
104
ext/phpbbstudio/aps/actions/type/warn.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\actions\type;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System action: Warn
|
||||
*/
|
||||
class warn extends base
|
||||
{
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\user $user User object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(\phpbb\user $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action name.
|
||||
*
|
||||
* @return string The name of the action this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_action()
|
||||
{
|
||||
return 'warn';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global state.
|
||||
*
|
||||
* @return bool If this type is global or local (per-forum basis)
|
||||
* @access public
|
||||
*/
|
||||
public function is_global()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type category under which it will be listed in the ACP.
|
||||
*
|
||||
* @return string The name of the category this type belongs to
|
||||
* @access public
|
||||
*/
|
||||
public function get_category()
|
||||
{
|
||||
return 'ACP_APS_POINTS_MISC';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type data.
|
||||
*
|
||||
* @return array An array of value names and their language string
|
||||
* @access public
|
||||
*/
|
||||
public function get_data()
|
||||
{
|
||||
return [
|
||||
'aps_mod_warn' => 'APS_POINTS_MOD_WARN',
|
||||
'aps_user_warn' => 'APS_POINTS_USER_WARN',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate points for this type.
|
||||
*
|
||||
* @param array $data The data available from the $event that triggered this action
|
||||
* @param array $values The point values available, indexed per forum_id and 0 for global values
|
||||
* @retrun void
|
||||
*/
|
||||
public function calculate($data, $values)
|
||||
{
|
||||
$value = $values[0];
|
||||
$logs = $this->get_data();
|
||||
|
||||
foreach (array_keys($this->users) as $user_id)
|
||||
{
|
||||
$mode = $user_id == $this->user->data['user_id'] ? 'mod' : 'user';
|
||||
|
||||
$points = [
|
||||
'points' => (double) $value['aps_' . $mode . '_warn'],
|
||||
'logs' => [$logs['aps_' . $mode . '_warn'] => $value['aps_' . $mode . '_warn']],
|
||||
];
|
||||
|
||||
$this->add($user_id, $points);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user