Skip to content

Commit

Permalink
Improve smiley editor
Browse files Browse the repository at this point in the history
* Default "Same image for all sets" to checked, when adding
new smiley.
* Add help text about "Same image for all sets".
* Make it possible to upload new images when editing existing
smileys.

Fixes #5368

Signed-off-by: Oscar Rydhé oscar.rydhe@gmail.com
  • Loading branch information
SGA-oscar-rydhe authored and MissAllSunday committed May 13, 2021
1 parent 11f880b commit c19eace
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 8 deletions.
54 changes: 54 additions & 0 deletions Sources/ManageSmileys.php
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,10 @@ function EditSmileys()

// Force the correct tab to be displayed.
$context[$context['admin_menu_name']]['current_subsection'] = 'editsmileys';
$context['smileys_dir'] = empty($modSettings['smileys_dir']) ? $boarddir . '/Smileys' : $modSettings['smileys_dir'];

$allowedTypes = array('gif', 'png', 'jpg', 'jpeg', 'tiff', 'svg');
$disabledFiles = array('con', 'com1', 'com2', 'com3', 'com4', 'prn', 'aux', 'lpt1', '.htaccess', 'index.php');
$known_sets = explode(',', $modSettings['smiley_sets_known']);

// Submitting a form?
Expand Down Expand Up @@ -1011,6 +1013,58 @@ function EditSmileys()
if (empty($_POST['smiley_code']))
fatal_lang_error('smiley_has_no_code');

// If upload a new smiley image, check that smiley set folders are writable for the sets with new images.
$writeErrors = array();
foreach ($_FILES['smiley_upload']['name'] as $set => $name)
{
if (!empty($name))
if (!is_writable($context['smileys_dir'] . '/' . $set))
$writeErrors[] = $set['path'];
}

if (!empty($writeErrors))
fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors)));

foreach ($known_sets as $set)
{
if (!isset($_FILES['smiley_upload']['name'][$set]) || empty($_FILES['smiley_upload']['name'][$set]))
continue;

// Got a new image for this set
if (!is_uploaded_file($_FILES['smiley_upload']['tmp_name'][$set]) || (ini_get('open_basedir') == '' && !file_exists($_FILES['smiley_upload']['tmp_name'][$set])))
fatal_lang_error('smileys_upload_error');

// Sorry, no spaces, dots, or anything else but letters allowed.
$_FILES['smiley_upload']['name'][$set] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['smiley_upload']['name'][$set]);

// We only allow image files - it's THAT simple - no messing around here...
if (!in_array(strtolower(pathinfo($_FILES['smiley_upload']['name'][$set], PATHINFO_EXTENSION)), $allowedTypes))
fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));

// We only need the filename...
$destName = basename($_FILES['smiley_upload']['name'][$set]);

// Make sure they aren't trying to upload a nasty file - for their own good here!
if (in_array(strtolower($destName), $disabledFiles))
fatal_lang_error('smileys_upload_error_illegal');

// If the file exists - ignore it.
$smileyLocation = $context['smileys_dir'] . '/' . $set . '/' . $destName;
if (!file_exists($smileyLocation))
{
// Finally - move the image!
move_uploaded_file($_FILES['smiley_upload']['tmp_name'][$set], $smileyLocation);
smf_chmod($smileyLocation, 0644);
}

// Double-check
if (!file_exists($smileyLocation))
fatal_lang_error('smiley_not_found');

// Overwrite smiley filename with uploaded filename
$_POST['smiley_filename'][$set] = $destName;
}

// Make sure all submitted filenames are clean.
$filenames = array();
foreach ($_POST['smiley_filename'] as $posted_set => $posted_filename)
Expand Down
18 changes: 10 additions & 8 deletions Themes/default/ManageSmileys.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function template_modifysmiley()
global $context, $scripturl, $txt, $modSettings;

echo '
<form action="', $scripturl, '?action=admin;area=smileys;sa=editsmileys" method="post" accept-charset="', $context['character_set'], '" name="smileyForm" id="smileyForm">
<form action="', $scripturl, '?action=admin;area=smileys;sa=editsmileys" method="post" accept-charset="', $context['character_set'], '" name="smileyForm" id="smileyForm" enctype="multipart/form-data">
<div class="cat_bar">
<h3 class="catbg">', $txt['smiley_modify_existing'], '</h3>
</div>
Expand Down Expand Up @@ -152,6 +152,7 @@ function template_modifysmiley()

echo '
</select>
<input type="file" name="smiley_upload[', $set, ']" id="smiley_upload_', $set, '">
</dd>';
}
}
Expand Down Expand Up @@ -266,28 +267,29 @@ function template_addsmiley()
<fieldset id="ul_settings" style="display: none;">
<dl class="settings">
<dt>
<a href="', $scripturl, '?action=helpadmin;help=smiley_sameall" onclick="return reqOverlayDiv(this.href);" class="help"><span class="main_icons help" title="', $txt['help'], '"></span></a>
<strong><label for="sameall">', $txt['smileys_add_upload_all'], ':</label></strong>
</dt>
<dd>
<input type="checkbox" name="sameall" id="sameall" onclick="swapUploads(); selectMethod(\'upload\');">
<input type="checkbox" name="sameall" id="sameall" onclick="swapUploads(); selectMethod(\'upload\');" checked>
</dd>
<dt>
<strong>', $txt['smileys_add_upload_choose'], ':</strong>
</dt>
<dt class="upload_sameall" style="display: none;">
<dt class="upload_sameall">
', $txt['smileys_add_upload_choose_desc'], '
</dt>
<dd class="upload_sameall" style="display: none;">
<input type="file" name="uploadSmiley" id="uploadSmiley" disabled onchange="selectMethod(\'upload\');">
<dd class="upload_sameall">
<input type="file" name="uploadSmiley" id="uploadSmiley" onchange="selectMethod(\'upload\');">
</dd>';

foreach ($context['smiley_sets'] as $smiley_set)
echo '
<dt class="upload_more">
<dt class="upload_more" style="display: none;">
', sprintf($txt['smileys_add_upload_for'], '<strong>' . $smiley_set['name'] . '</strong>'), ':
</dt>
<dd class="upload_more">
<input type="file" name="individual_', $smiley_set['path'], '" onchange="selectMethod(\'upload\');">
<dd class="upload_more" style="display: none;">
<input type="file" name="individual_', $smiley_set['path'], '" disabled onchange="selectMethod(\'upload\');">
</dd>';

echo '
Expand Down
2 changes: 2 additions & 0 deletions Themes/default/languages/Help.english.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@

$helptxt['disableHostnameLookup'] = 'This disables host name lookups, which on some servers are very slow. Note that this will make banning less effective.';

$helptxt['smiley_sameall'] = 'If checking "Same image for all sets", the same image will be added to all your smiley sets. If you uncheck the box; a different image can be uploaded for every installed smiley set. Note that an image needs to be provided for every smiley set.';

$helptxt['search_weight_frequency'] = 'Weight factors are used to determine the relevancy of a search result. Change these weight factors to match the things that are specifically important for your forum. For instance, a forum of a news site, might want a relatively high value for \'age of last matching message\'. All values are relative in relation to each other and should be positive integers.<br><br>This factor counts the amount of matching messages and divides them by the total number of messages within a topic.';
$helptxt['search_weight_age'] = 'Weight factors are used to determine the relevancy of a search result. Change these weight factors to match the things that are specifically important for your forum. For instance, a forum of a news site, might want a relatively high value for \'age of last matching message\'. All values are relative in relation to each other and should be positive integers.<br><br>This factor rates the age of the last matching message within a topic. The more recent this message is, the higher the score.';
$helptxt['search_weight_length'] = 'Weight factors are used to determine the relevancy of a search result. Change these weight factors to match the things that are specifically important for your forum. For instance, a forum of a news site, might want a relatively high value for \'age of last matching message\'. All values are relative in relation to each other and should be positive integers.<br><br>This factor is based on the topic size. The more messages are within the topic, the higher the score.';
Expand Down

0 comments on commit c19eace

Please sign in to comment.