Skip to content

Commit

Permalink
Working Changes (#3707)
Browse files Browse the repository at this point in the history
* ! misc

* ! those bitwise operators are not doing what you expect
they are not logical checks and do not return booleans

* ! thats a profile action not quickhelp

* ! drop the php ending from user language display

* ! lets return the board_id as ints, it was mixed

* ! QR was not working if the area was collapsed
! experiment with expanding collapsed QR vs jumping to full post page

* ! the like button could fail when clicking on the icon
in the button as it was e.target but we needed the e.currentTarget

* ! thats is not a color variant selector

* ! attachments need the per message poster list

* ! tweak

* ! provide option to load board selection "on load" or "on mouse"

* ! only collapse if its empty

* ! approving attachments caused fatal error (empty array)

* ! cleanup / PSR / 7+

* ! formatting / psr / cleanup

* ! edit all option in board profiles was broken

* ! formatting / psr / cleanup / docblock / []

* ! replace jSqueeze with JavaScriptMinifier for better support
+ add fast css compression with a whitespace/comment stripper

* ! string needs to be available on script load

* ! fix credits

* ! update chart.js to latest

* ! replace fill data as real data is available

* ! dont count former members

* ! psr cleanup

* ! space holder

* ! test fix, security now prevents that action
  • Loading branch information
Spuds committed Apr 3, 2023
1 parent 46b8be4 commit 4b5853c
Show file tree
Hide file tree
Showing 48 changed files with 2,388 additions and 1,821 deletions.
4 changes: 1 addition & 3 deletions sources/ElkArte/AdminController/ManageAttachments.php
Expand Up @@ -31,7 +31,6 @@
* This is the attachments and avatars controller class.
* It is doing the job of attachments and avatars maintenance and management.
*
* @package Attachments
*/
class ManageAttachments extends AbstractController
{
Expand Down Expand Up @@ -1113,8 +1112,7 @@ public function action_repair()
* @param int $max_substep = 0
* @throws \ElkArte\Exceptions\Exception
* @todo Move to ManageAttachments.subs.php
* @package Attachments
*/
*/
private function _pauseAttachmentMaintenance($to_fix, $max_substep = 0)
{
global $context, $txt, $time_start;
Expand Down
2 changes: 1 addition & 1 deletion sources/ElkArte/AdminController/ManageFeatures.php
Expand Up @@ -160,6 +160,7 @@ public function action_basicSettings_display()

// Initialize it with our settings
$settingsForm->setConfigVars($this->_basicSettings());
theme()->addJavascriptVar(['txt_invalid_response' => $txt['ajax_bad_response']], true);

// Saving?
if (isset($this->_req->query->save))
Expand Down Expand Up @@ -204,7 +205,6 @@ public function action_basicSettings_display()

theme()->getLayers()->removeAll();
theme()->getTemplates()->load('Json');
theme()->addJavascriptVar(array('txt_invalid_response' => $txt['ajax_bad_response']), true);
$context['sub_template'] = 'send_json';
$context['json_data'] = array(
'success' => $clean_hives_result,
Expand Down
8 changes: 3 additions & 5 deletions sources/ElkArte/AttachmentsDirectory.php
Expand Up @@ -60,7 +60,7 @@ class AttachmentsDirectory
protected $last_dirs = [];

/** @var \ElkArte\Database\QueryInterface|null */
protected $db = null;
protected $db;

/**
* The constructor for attachment directories, controls where to add files
Expand Down Expand Up @@ -374,8 +374,7 @@ public function autoManageIsLevel($level)
* - Increments the above directory to the next available slot
* - Uses createDirectory to create the incremental directory
*
* @package Attachments
*/
*/
public function manageBySpace()
{
if ($this->autoManageEnabled(self::AUTO_SEQUENCE))
Expand Down Expand Up @@ -461,8 +460,7 @@ protected function initLastDir($base_dir)
* @param string $updir
* @return bool
* @throws \Exception
* @package Attachments
*
*
*/
public function createDirectory($updir)
{
Expand Down
17 changes: 10 additions & 7 deletions sources/ElkArte/AttachmentsDisplay.php
Expand Up @@ -46,9 +46,14 @@ public function __construct($messages, $posters, $includeUnapproved)
// The filter returns false when:
// - the attachment is unapproved, and
// - the viewer is not the poster of the message where the attachment is
$this->getAttachments($this->messages, $this->includeUnapproved, static function ($attachment_info, $all_posters) {
return !(!$attachment_info['approved'] && (!isset($all_posters[$attachment_info['id_msg']]) || $all_posters[$attachment_info['id_msg']] != User::$info->id));
}, $posters);
$this->getAttachments(
$this->messages,
$this->includeUnapproved,
static function ($attachment_info, $all_posters) {
return !(!$attachment_info['approved'] && (!isset($all_posters[$attachment_info['id_msg']]) || $all_posters[$attachment_info['id_msg']] != User::$info->id));
},
$posters
);
}
}

Expand All @@ -63,8 +68,7 @@ public function __construct($messages, $posters, $includeUnapproved)
* @param string|null $filter name of a callback function
* @param array $all_posters
*
* @package Attachments
*/
*/
protected function getAttachments($messages, $includeUnapproved = false, $filter = null, $all_posters = array())
{
global $modSettings;
Expand Down Expand Up @@ -128,8 +132,7 @@ function ($row) use ($includeUnapproved, $filter, $all_posters, &$attachments, &
* @return array of attachments
* @todo change this pre-condition, too fragile and error-prone.
*
* @package Attachments
*/
*/
public function loadAttachmentContext($id_msg)
{
global $context, $modSettings, $scripturl, $topic;
Expand Down
88 changes: 24 additions & 64 deletions sources/ElkArte/BoardsList.php
Expand Up @@ -25,80 +25,40 @@
*/
class BoardsList
{
/**
* All the options
*
* @var mixed[]
*/
/** @var array All the options */
private $_options;

/**
* Some data regarding the current user
*
* @var mixed[]
*/
/** @var array Some data regarding the current user */
private $_user;

/**
* Holds the info about the latest post of the series
*
* @var mixed[]
*/
private $_latest_post = array();
/** @var array Holds the info about the latest post of the series */
private $_latest_post = [];

/**
* Remembers boards to easily scan the array to add moderators later
*
* @var int[]
*/
private $_boards = array();
/** @var int[] Remembers boards to easily scan the array to add moderators later */
private $_boards = [];

/**
* An array containing all the data of the categories and boards requested
*
* @var mixed[]
*/
private $_categories = array();
/** @var array An array containing all the data of the categories and boards requested */
private $_categories = [];

/**
* The category/board that is being processed "now"
*
* @var mixed[]
*/
private $_current_boards = array();
/** @var array The category/board that is being processed "now" */
private $_current_boards = [];

/**
* The url where to find images
*
* @var string
*/
/** @var string The url where to find images */
private $_images_url;

/**
* Cut the subject at this number of chars, set from modSettings
*
* @var int
*/
/** @var int Cut the subject at this number of chars, set from modSettings */
private $_subject_length = 48;

/**
* The id of the recycle board (0 for none or not enabled)
*
* @var int
*/
/** @var int The id of the recycle board (0 for none or not enabled) */
private $_recycle_board = 0;

/**
* The database!
*
* @var object
*/
/** @var \ElkArte\Database\QueryInterface The database! */
private $_db;

/**
* Initialize the class
*
* @param mixed[] $options - Available options and corresponding defaults are:
* @param array $options - Available options and corresponding defaults are:
* - 'include_categories' => false
* - 'countChildPosts' => false
* - 'base_level' => false
Expand Down Expand Up @@ -135,17 +95,17 @@ public function __construct($options)
// Start with an empty array.
if ($this->_options['include_categories'])
{
$this->_categories = array();
$this->_categories = [];
}
else
{
$this->_current_boards = array();
$this->_current_boards = [];
}

// For performance, track the latest post while going through the boards.
if (!empty($this->_options['set_latest_post']))
{
$this->_latest_post = array('timestamp' => 0);
$this->_latest_post = ['timestamp' => 0];
}

if (!empty($modSettings['recycle_enable']))
Expand Down Expand Up @@ -203,7 +163,7 @@ public function getBoards()

$result_boards = $request->fetch_all();

usort($result_boards, function ($a, $b) {
usort($result_boards, static function ($a, $b) {
return $a['board_order'] <=> $b['board_order'];
});

Expand Down Expand Up @@ -333,7 +293,7 @@ public function getBoards()
// @todo why this is not initialized outside the loop?
if (!isset($parent_map))
{
$parent_map = array();
$parent_map = [];
}

if (!isset($parent_map[$row_board['id_parent']]))
Expand Down Expand Up @@ -425,10 +385,10 @@ public function getBoards()
$this->_current_boards[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post;

// If there are no posts in this board, it really can't be new...
$this->_current_boards[$row_board['id_parent']]['children'][$row_board['id_board']]['new'] &= $row_board['poster_name'] != '';
$this->_current_boards[$row_board['id_parent']]['children'][$row_board['id_board']]['new'] &= $row_board['poster_name'] !== '';
}
// No last post for this board? It's not new then, is it..?
elseif ($row_board['poster_name'] == '')
elseif ($row_board['poster_name'] === '')
{
$this->_current_boards[$row_board['id_board']]['new'] = false;
}
Expand All @@ -445,7 +405,7 @@ public function getBoards()
$this->_getBoardModerators();
}

usort($this->_categories, function ($a, $b) {
usort($this->_categories, static function ($a, $b) {
return $a['order'] <=> $b['order'];
});

Expand Down Expand Up @@ -506,7 +466,7 @@ public function getLatestPost()
{
if (empty($this->_latest_post) || empty($this->_latest_post['link']))
{
return array();
return [];
}

return $this->_latest_post;
Expand Down
4 changes: 1 addition & 3 deletions sources/ElkArte/Controller/Attachment.php
Expand Up @@ -29,7 +29,6 @@
use ElkArte\Themes\ThemeLoader;
use ElkArte\Languages\Txt;
use ElkArte\User;
use ElkArte\Util;

/**
* Everything to do with attachment handling / processing
Expand All @@ -40,7 +39,6 @@
* - Handles the uploading of attachments via Ajax
* - Increments the download count where applicable
*
* @package Attachments
*/
class Attachment extends AbstractController
{
Expand Down Expand Up @@ -421,7 +419,7 @@ public function action_dlattach()
$mime_type = '';
}
// Does this have a mime type?
elseif (empty($mime_type) || !isset($this->_req->query->image) && getValidMimeImageType($file_ext) !== '')
elseif (empty($mime_type) || (!isset($this->_req->query->image) && getValidMimeImageType($file_ext) !== ''))
{
$mime_type = '';
if (isset($this->_req->query->image))
Expand Down
2 changes: 1 addition & 1 deletion sources/ElkArte/Controller/Display.php
Expand Up @@ -175,7 +175,7 @@ public function action_display()
$context['first_message'] = 0;
$context['first_new_message'] = false;

call_integration_hook('integrate_display_message_list', array(&$messages, &$posters));
call_integration_hook('integrate_display_message_list', array(&$messages, &$all_posters));

// If there _are_ messages here... (probably an error otherwise :!)
if (!empty($messages))
Expand Down
2 changes: 1 addition & 1 deletion sources/ElkArte/Controller/Groups.php
Expand Up @@ -452,7 +452,7 @@ public function action_members()

$context['members'][$id] = array(
'id' => $row['id_member'],
'name' => '<a href="' . getUrl('profile', ['action' => 'quickhelp', 'u' => $row['id_member'], 'name' => $row['real_name']]) . '">' . $row['real_name'] . '</a>',
'name' => '<a href="' . getUrl('profile', ['action' => 'profile', 'u' => $row['id_member'], 'name' => $row['real_name']]) . '">' . $row['real_name'] . '</a>',
'email' => $row['email_address'],
'show_email' => showEmailAddress(!empty($row['hide_email']), $row['id_member']),
'ip' => '<a href="' . getUrl('action', ['action' => 'trackip', 'searchip' => $row['member_ip']]) . '">' . $row['member_ip'] . '</a>',
Expand Down
6 changes: 3 additions & 3 deletions sources/ElkArte/Controller/ModerateAttachments.php
Expand Up @@ -51,7 +51,7 @@ public function action_attachapprove()
// Is it approve or delete?
$is_approve = !isset($this->_req->query->sa) || $this->_req->query->sa !== 'reject';

$attachments = array();
$attachments = [];
require_once(SUBSDIR . '/ManageAttachments.subs.php');

// If we are approving all ID's in a message, get the ID's.
Expand All @@ -74,7 +74,7 @@ public function action_attachapprove()
// Now we have some ID's cleaned and ready to approve, but first - let's check we have permission!
$allowed_boards = !empty($this->user->mod_cache['ap']) ? $this->user->mod_cache['ap'] : boardsAllowedTo('approve_posts');

if ($allowed_boards == array(0))
if ($allowed_boards == [0])
{
$approve_query = '';
}
Expand Down Expand Up @@ -107,7 +107,7 @@ public function action_attachapprove()
}
else
{
removeAttachments(array('id_attach' => $attachments, 'do_logging' => true));
removeAttachments(['id_attach' => $attachments, 'do_logging' => true]);
}

// We approved or removed, either way we reset those numbers
Expand Down
4 changes: 2 additions & 2 deletions sources/ElkArte/Controller/ProfileInfo.php
Expand Up @@ -663,10 +663,10 @@ public function action_showPosts()
}

// Clean up after posts that cannot be deleted and quoted.
$quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
$quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']), true);
foreach ($context['posts'] as $counter => $dummy)
{
$context['posts'][$counter]['tests']['can_delete'] &= $context['posts'][$counter]['delete_possible'];
$context['posts'][$counter]['tests']['can_delete'] = $context['posts'][$counter]['tests']['can_delete'] && $context['posts'][$counter]['delete_possible'];
$context['posts'][$counter]['tests']['can_quote'] = $context['posts'][$counter]['tests']['can_reply'] && $quote_enabled;
}
}
Expand Down
2 changes: 1 addition & 1 deletion sources/ElkArte/Controller/Recent.php
Expand Up @@ -233,7 +233,7 @@ public function action_recent()
foreach ($context['posts'] as $counter => $post)
{
// Some posts - the first posts - can't just be deleted.
$context['posts'][$counter]['tests']['can_delete'] &= $context['posts'][$counter]['delete_possible'];
$context['posts'][$counter]['tests']['can_delete'] = $context['posts'][$counter]['tests']['can_delete'] && $context['posts'][$counter]['delete_possible'];

// And some cannot be quoted...
$context['posts'][$counter]['tests']['can_quote'] = $context['posts'][$counter]['tests']['can_reply'] && $quote_enabled;
Expand Down

0 comments on commit 4b5853c

Please sign in to comment.