Skip to content

Commit

Permalink
Shorten some forum code about length
Browse files Browse the repository at this point in the history
  • Loading branch information
slawkens committed Jul 7, 2023
1 parent 34725e0 commit df48363
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 38 deletions.
26 changes: 10 additions & 16 deletions system/pages/forum/edit_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,18 @@
$post_topic = stripslashes(trim($_REQUEST['topic']));
$smile = isset($_REQUEST['smile']) ? (int)$_REQUEST['smile'] : 0;
$html = isset($_REQUEST['html']) ? (int)$_REQUEST['html'] : 0;
$lenght = 0;
for($i = 0; $i < strlen($post_topic); $i++)
{
if(ord($post_topic[$i]) >= 33 && ord($post_topic[$i]) <= 126)
$lenght++;
}
if(($lenght < 1 || strlen($post_topic) > 60) && $thread['id'] == $thread['first_post'])
$errors[] = 'Too short or too long topic (short: '.$lenght.' long: '.strlen($post_topic).' letters). Minimum 1 letter, maximum 60 letters.';
$lenght = 0;
for($i = 0; $i < strlen($text); $i++)
{
if(ord($text[$i]) >= 33 && ord($text[$i]) <= 126)
$lenght++;
}
if($lenght < 1 || strlen($text) > 15000)
$errors[] = 'Too short or too long post (short: '.$lenght.' long: '.strlen($text).' letters). Minimum 1 letter, maximum 15000 letters.';

$length = strlen($post_topic);
if(($length < 1 || $length > 60) && $thread['id'] == $thread['first_post'])
$errors[] = "Too short or too long topic (Length: $length letters). Minimum 1 letter, maximum 60 letters.";

$length = strlen($text);
if($length < 1 || $length > 15000)
$errors[] = "Too short or too long post (Length: $length letters). Minimum 1 letter, maximum 15000 letters.";

if($char_id == 0)
$errors[] = 'Please select a character.';

if(empty($post_topic) && $thread['id'] == $thread['first_post'])
$errors[] = 'Thread topic can\'t be empty.';

Expand Down
12 changes: 4 additions & 8 deletions system/pages/forum/new_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,10 @@
}
elseif(isset($_REQUEST['save']))
{
$lenght = 0;
for($i = 0; $i < strlen($text); $i++)
{
if(ord($text[$i]) >= 33 && ord($text[$i]) <= 126)
$lenght++;
}
if($lenght < 1 || strlen($text) > 15000)
$errors[] = 'Too short or too long post (short: '.$lenght.' long: '.strlen($text).' letters). Minimum 1 letter, maximum 15000 letters.';
$length = strlen($text);
if($length < 1 || strlen($text) > 15000)
$errors[] = 'Too short or too long post (Length: $length letters). Minimum 1 letter, maximum 15000 letters.';

if($char_id == 0)
$errors[] = 'Please select a character.';

Expand Down
21 changes: 7 additions & 14 deletions system/pages/forum/new_thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,13 @@
if (isset($_REQUEST['save'])) {
$errors = array();

$lenght = 0;
for ($i = 0; $i < strlen($post_topic); $i++) {
if (ord($post_topic[$i]) >= 33 && ord($post_topic[$i]) <= 126)
$lenght++;
}
if ($lenght < 1 || strlen($post_topic) > 60)
$errors[] = 'Too short or too long topic (short: ' . $lenght . ' long: ' . strlen($post_topic) . ' letters). Minimum 1 letter, maximum 60 letters.';
$lenght = 0;
for ($i = 0; $i < strlen($text); $i++) {
if (ord($text[$i]) >= 33 && ord($text[$i]) <= 126)
$lenght++;
}
if ($lenght < 1 || strlen($text) > 15000)
$errors[] = 'Too short or too long post (short: ' . $lenght . ' long: ' . strlen($text) . ' letters). Minimum 1 letter, maximum 15000 letters.';
$length = strlen($post_topic);
if ($length < 1 || $length > 60)
$errors[] = "Too short or too long topic (Length: $length letters). Minimum 1 letter, maximum 60 letters.";

$length = strlen($text);
if ($length < 1 || $length > 15000)
$errors[] = "Too short or too long post (Length: $length letters). Minimum 1 letter, maximum 15000 letters.";

if ($char_id == 0)
$errors[] = 'Please select a character.';
Expand Down

0 comments on commit df48363

Please sign in to comment.