Skip to content

Commit

Permalink
- Dropped smileys support for IE6 and IE7. (Subs-BBC.php, Class-Edito…
Browse files Browse the repository at this point in the history
…r.php, Subs-Cache.php)

! Smiley cache emptying code didn't actually force reloading the smiley CSS file. I'm not kidding you. This really happened. In my code, of all places. (ManageSmileys.php)

@ Note that you can safely remove all smiley-cache-* variables from your settings table (note: dashes, not underscores). This was just too confusing.

@ Yes, IE6/7 support sounded acceptable back in 2012, but we're in 2017 and this legacy code shouldn't be here any more. It wastes CPU cycles for 0.5% of browser market share that, let's just say it, is mostly spam bots with fake user agents or people who enjoy their computers with viruses everywhere. I'm not gonna encourage that. Plus I think I already started removing support for IE6/7 compatibility in other places a couple years ago, so this is just the start.
  • Loading branch information
Nao committed Feb 21, 2017
1 parent 5e742b0 commit 78b0f70
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
9 changes: 3 additions & 6 deletions core/app/Class-Editor.php
Expand Up @@ -2466,18 +2466,15 @@ public function outputEditor()
$can_gzip = !empty($settings['enableCompressedData']) && function_exists('gzencode') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
$context['smiley_gzip'] = $can_gzip;
$context['smiley_ext'] = $can_gzip ? (we::is('safari[-5.1]') ? '.cgz' : (we::is('ie[11-]') ? '.gz.css' : '.css.gz')) : '.css';
$extra = we::is('ie6,ie7') ? '-ie' : '';
$var_name = 'smiley-cache-' . $extra . '-' . we::$user['smiley_set'];
$dummy = '';
$max = 0;

// Retrieve the current smiley cache's URL. If not available, attempt to regenerate it.
while (empty($exists) && $max++ < 3)
{
if (!isset($settings[$var_name]))
updateSettings(array($var_name => time() % 1000));
$context['smiley_now'] = $settings[$var_name];
$filename = '/css/smileys' . $extra . (we::$user['smiley_set'] == 'default' ? '' : '-' . we::$user['smiley_set']) . '-' . $context['smiley_now'] . $context['smiley_ext'];
if (!isset($settings['smiley_cache']))
updateSettings(array('smiley_cache' => time() % 1000));
$filename = '/css/smileys' . (we::$user['smiley_set'] == 'default' ? '' : '-' . we::$user['smiley_set']) . '-' . $settings['smiley_cache'] . $context['smiley_ext'];
$exists = file_exists(CACHE_DIR . $filename);
if (!$exists)
parsesmileys($dummy);
Expand Down
5 changes: 1 addition & 4 deletions core/app/ManageSmileys.php
Expand Up @@ -291,10 +291,8 @@ function EditSmileySets()
$smileys = array();
$dir = dir(ASSETS_DIR . '/smileys/' . $context['current_set']['path']);
while ($entry = $dir->read())
{
if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
$smileys[strtolower($entry)] = $entry;
}
$dir->close();

// Exclude the smileys that are already in the database.
Expand Down Expand Up @@ -531,10 +529,8 @@ function AddSmiley()
{
$writeErrors = array();
foreach ($context['smiley_sets'] as $set)
{
if (!is_writable(ASSETS_DIR . '/smileys/' . un_htmlspecialchars($set['path'])))
$writeErrors[] = $set['path'];
}
if (!empty($writeErrors))
fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors)));
}
Expand Down Expand Up @@ -1681,6 +1677,7 @@ function sortSmileyTable()
// A helper function to easily wipe out the smiley cache, both in the file cache and in the CSS cache.
function cleanSmileyCache($clean_cache = true)
{
updateSettings(array('smiley_cache' => time() % 1000));
cache_put_data('smiley_parser', null, 'forever');
cache_put_data('smiley_poster', null, 'forever');
if ($clean_cache)
Expand Down
15 changes: 6 additions & 9 deletions core/app/Subs-BBC.php
Expand Up @@ -1211,13 +1211,10 @@ function parsesmileys(&$message)
$can_gzip = !empty($settings['enableCompressedData']) && function_exists('gzencode') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
$context['smiley_gzip'] = $can_gzip;
$context['smiley_ext'] = $can_gzip ? (we::is('safari[-5.1]') ? '.cgz' : (we::is('ie[11-]') ? '.gz.css' : '.css.gz')) : '.css';
$extra = we::is('ie6,ie7') ? '-ie' : '';
$var_name = 'smiley-cache-' . $extra . '-' . we::$user['smiley_set'];
if (!isset($settings[$var_name]))
updateSettings(array($var_name => time() % 1000));
$context['smiley_now'] = $settings[$var_name];
if (!isset($settings['smiley_cache']))
updateSettings(array('smiley_cache' => time() % 1000));

if (!file_exists(CACHE_DIR . '/css/smileys' . $extra . (we::$user['smiley_set'] == 'default' ? '' : '-' . we::$user['smiley_set']) . '-' . $context['smiley_now'] . $context['smiley_ext']))
if (!file_exists(CACHE_DIR . '/css/smileys' . (we::$user['smiley_set'] == 'default' ? '' : '-' . we::$user['smiley_set']) . '-' . $settings['smiley_cache'] . $context['smiley_ext']))
{
// We're only going to cache the smileys that show up on the post editor by default.
// The reason is to help save bandwidth by only storing whatever is most likely to be used.
Expand All @@ -1227,7 +1224,7 @@ function parsesmileys(&$message)
if (!empty($cache))
{
loadSource('Subs-Cache');
wedge_cache_smileys(we::$user['smiley_set'], $cache, $extra);
wedge_cache_smileys(we::$user['smiley_set'], $cache);
}
}

Expand All @@ -1247,11 +1244,11 @@ function replace_smileys($match)
{
if (empty($smiley_css_done))
{
global $context;
global $context, $settings;

$smiley_css_done = true;
$context['header'] .= '
<link rel="stylesheet" href="' . CACHE . '/css/smileys' . (we::is('ie6,ie7') ? '-ie' : '') . (we::$user['smiley_set'] == 'default' ? '' : '-' . we::$user['smiley_set']) . '-' . $context['smiley_now'] . $context['smiley_ext'] . '">';
<link rel="stylesheet" href="' . CACHE . '/css/smileys' . (we::$user['smiley_set'] == 'default' ? '' : '-' . we::$user['smiley_set']) . '-' . $settings['smiley_cache'] . $context['smiley_ext'] . '">';
}
return $smileyPregReplace[$match[1]];
}
Expand Down
9 changes: 4 additions & 5 deletions core/app/Subs-Cache.php
Expand Up @@ -1281,9 +1281,8 @@ function ($match) { return !empty(we::$is[$match[1]]) ? $match[3] : (isset($matc
*
* @param string $set The current smiley folder
* @param array $smileys The list of smileys to cache
* @param string $extra '-ie', if using oldIE, which doesn't support base64 encoding.
*/
function wedge_cache_smileys($set, $smileys, $extra)
function wedge_cache_smileys($set, $smileys)
{
global $context, $settings;

Expand All @@ -1292,7 +1291,7 @@ function wedge_cache_smileys($set, $smileys, $extra)
$url = SMILEYS . '/' . $set . '/';

// Delete other cached versions, if they exist.
clean_cache($context['smiley_ext'], 'smileys' . $extra, CACHE_DIR . '/css');
clean_cache($context['smiley_ext'], 'smileys', CACHE_DIR . '/css');

foreach ($smileys as $name => $smiley)
{
Expand All @@ -1306,7 +1305,7 @@ function wedge_cache_smileys($set, $smileys, $extra)
$cur_url = SMILEYS . '/default/';
}
// Only small files should be embedded, really. 4KB should have a fair bandwidth/hit ratio.
if ($extra || ($smiley['embed'] && filesize($filename) > 4096) || !$context['smiley_gzip'])
if (($smiley['embed'] && filesize($filename) > 4096) || !$context['smiley_gzip'])
$smiley['embed'] = false;
list ($width, $height) = getimagesize($filename);
$ext = strtolower(substr($filename, strrpos($filename, '.') + 1));
Expand All @@ -1324,7 +1323,7 @@ function wedge_cache_smileys($set, $smileys, $extra)
if ($context['smiley_gzip'])
$final = gzencode($final, 9);

file_put_contents(CACHE_DIR . '/css/smileys' . $extra . ($set == 'default' ? '' : '-' . $set) . '-' . $context['smiley_now'] . $context['smiley_ext'], $final);
file_put_contents(CACHE_DIR . '/css/smileys' . ($set == 'default' ? '' : '-' . $set) . '-' . $settings['smiley_cache'] . $context['smiley_ext'], $final);
}

/**
Expand Down

0 comments on commit 78b0f70

Please sign in to comment.