Skip to content

Commit

Permalink
Update for SMF 2.1, revamping into supporting alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
jdarwood007 committed Mar 7, 2022
1 parent 5839e8f commit 27daf0f
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 93 deletions.
43 changes: 24 additions & 19 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
Copyright (c) 2012, SleePy (smf [dash] mods [dash] license [dash] upc [at] sleepycode [dot]com)
BSD 3-Clause License

Copyright (c) 2022, SleePy
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6 changes: 4 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SMF 2.0+ Modification. I will not back support this mod to older versions.

This modification adds a unread PM counter to the favicon. In addition it continues to check for PMs at a specified interval. Setting this variable to lower can result in server degration/performance issues. Use with caution. The default timeout is 1 minute (60 seconds).

Prior to asking for support, check out the wiki: https://github.com/jdarwood007/smf-unreadPM_count/wiki
Prior to asking for support, check out the wiki: https://github.com/jdarwood007/smfmod-faviconindicator/wiki

Credits for this ability go to Tom Moor for creating Tinycon: https://github.com/tommoor/tinycon

Expand All @@ -13,4 +13,6 @@ Opera 11+

The following browsers will fall back to changing the title due to lack of support for this:
Internet Explorer 9
Safari 5
Safari 5

Websites with apple icons meta data may not function as iOS/Safari may overload the favicon
4 changes: 2 additions & 2 deletions UnreadPMs.php → SMF2.0/UnreadPMs.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

// This adds a hook to our action=.
function uPMs_hook_actionArray(&$actionArray)
function uPMs_hook_actionArray($actionArray)
{
global $modSettings;

Expand Down Expand Up @@ -45,7 +45,7 @@ function uPMs_hook_load_theme()


// Adds a hook to the general mod settings so we can manage the setting.
function uPMs_hook_general_mod_settings(&$config_vars)
function uPMs_hook_general_mod_settings($config_vars)
{
global $txt;

Expand Down
File renamed without changes.
File renamed without changes.
30 changes: 15 additions & 15 deletions language.xml → SMF2.0/language.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0"?>
<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">
<!-- This package was generated by SleePys Modification Maker at http://sleepycode.com -->
<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
<id>sleepy:unreadpmfav</id>
<version>1.0</version>

<file name="$languagedir/Modifications.english.php">
<operation>
<search position="end"/>
<add><![CDATA[// Unread PMs strings.
$txt['unreadPMstimeout'] = 'Unread PMs Favicon Counter';
$txt['unreadPMstimeout_post'] = 'seconds between checks (setting this to low may cause performance issues)';]]></add>
</operation>
</file>
<?xml version="1.0"?>
<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">
<!-- This package was generated by SleePys Modification Maker at http://sleepycode.com -->
<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
<id>sleepy:unreadpmfav</id>
<version>1.0</version>

<file name="$languagedir/Modifications.english.php">
<operation>
<search position="end"/>
<add><![CDATA[// Unread PMs strings.
$txt['unreadPMstimeout'] = 'Unread PMs Favicon Counter';
$txt['unreadPMstimeout_post'] = 'seconds between checks (setting this to low may cause performance issues)';]]></add>
</operation>
</file>
</modification>
104 changes: 104 additions & 0 deletions SMF2.1/FaviconIndicator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

/**
* The main class for Favicon Indicator customization
* @package AntiSpamLinks
* @author SleePy https://sleepycode.com
* @copyright 2022
* @license 3-Clause BSD https://opensource.org/licenses/BSD-3-Clause
* @version 2.0
*/
class FaviconIndicator
{
/**
* Creates the hook to the class for the xml sub actions.
*
* @param array $subActions A associate array of all the valid sub actions.
*
* @version 2.0
* @since 1.0
* @uses integrate_XMLhttpMain_subActions - Hook SMF2.1
* @return void No return is generated
*/
public static function hook_XMLhttpMain_subActions(array &$subActions): void
{
$subActions['faviconnotify'] = 'FaviconIndicator::CheckNotifications';
}

/**
* Prepares some XML data to send backt o the client. This contains the unread pm and alerts counts.
*
* @version 2.0
* @since 1.0
* @return void No return is generated, it is sent to output
*/
public static function CheckNotifications(): void
{
global $user_info, $context;

header('Content-Type: text/xml; charset=UTF-8');

echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
<smf>
<unreadpms>', $user_info['unread_messages'], '</unreadpms>
<alerts>', $user_info['alerts'], '</alerts>
</smf>';

obExit(false, false, false);
}

/**
* Adds the javascript needed to make things work.
*
* @version 2.0
* @since 1.0
* @uses integrate_load_theme - Hook SMF2.1
* @return void No return is generated
*/
public static function hook_load_theme(): void
{
global $context, $settings, $modSettings;

// Default the setting to 1 minute.
if (!isset($modSettings['faviconIndicatorTimeout']))
$modSettings['faviconIndicatorTimeout'] = 60;
elseif (empty($modSettings['faviconIndicatorTimeout']) || $context['user']['is_guest'])
return;

// Append the html headers.
loadJavaScriptFile('tinycon.min.js', [
'defer' => true,
]);

addInlineJavaScript('
fFaviconNotification = function ()
{
window.setTimeout(\'fFaviconNotification();\', ' . ((int) $modSettings['faviconIndicatorTimeout']) * 600 . ');
getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=xmlhttp;sa=faviconnotify\', function(responseXML){
var unreadPMs = responseXML.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'unreadpms\')[0].firstChild.nodeValue;
var alerts = responseXML.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'alerts\')[0].firstChild.nodeValue;
Tinycon.setBubble(parseInt(unreadPMs) + parseInt(alerts));
});
}
addLoadEvent(fFaviconNotification);', true);
}

/**
* Creates the hook to the class for the general mod settings.
*
* @param array $config_vars A associate array of all the valid configuration variables.
*
* @version 2.0
* @since 1.0
* @uses integrate_general_mod_settings - Hook SMF2.1
* @return void No return is generated
*/
public static function hook_general_mod_settings(array &$config_vars): void
{
global $txt;

loadLanguage('FaviconIndicator');
$config_vars[] = array('int', 'faviconIndicatorTimeout', 'postinput' => $txt['faviconIndicatorTimeout_post']);
}
}
3 changes: 3 additions & 0 deletions SMF2.1/language/FaviconIndicator.english.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
$txt['faviconIndicatorTimeout'] = 'Favicon Indicator Timeout';
$txt['faviconIndicatorTimeout_post'] = 'seconds between checks (setting this to low may cause performance issues)';
13 changes: 13 additions & 0 deletions SMF2.1/upgrade-2.0.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
require_once(dirname(__FILE__) . '/SSI.php');
elseif (!defined('SMF'))
exit('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');

global $modSettings;

if (isset($modSettings['unreadPMstimeout']) && !isset($modSettings['faviconIndicatorTimeout']))
updateSettings(array(
'faviconIndicatorTimeout' => (int) $modSettings['unreadPMstimeout'],
'unreadPMstimeout' => null
), true);
16 changes: 0 additions & 16 deletions language.russian-utf8.xml

This file was deleted.

16 changes: 0 additions & 16 deletions language.russian.xml

This file was deleted.

47 changes: 31 additions & 16 deletions package-info.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
<!DOCTYPE package-info SYSTEM "http://www.simplemachines.org/xml/package-info">
<!-- This package was generated by SleePys Package Maker at http://sleepycode.com -->
<package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/">
<id>sleepy:unreadpmfav</id>
<name>Unread PMs Favicon</name>
<version>1.0.2</version>
<name>Favicon Indictator</name>
<version>2.0</version>
<type>modification</type>

<install for="SMF 2.0-2.0.99">
<code>hooks_add.php</code>
<move-file name="UnreadPMs.php" destination="$sourcedir/" />
<install for="SMF 2.1.*">
<readme>README.txt</readme>
<hook hook="integrate_general_mod_settings" function="FaviconIndicator::hook_general_mod_settings" file="$sourcedir/FaviconIndicator.php" />
<hook hook="integrate_XMLhttpMain_subActions" function="FaviconIndicator::hook_XMLhttpMain_subActions" file="$sourcedir/FaviconIndicator.php" />
<hook hook="integrate_load_theme" function="FaviconIndicator::hook_load_theme" file="$sourcedir/FaviconIndicator.php" />

<require-file name="SMF2.1/language/FaviconIndicator.english.php" destination="$themes_dir/default/languages" />
<require-file name="tinycon.min.js" destination="$themes_dir/default/scripts" />
<require-file name="SMF2.1/FaviconIndicator.php" destination="$sourcedir" />
</install>

<uninstall for="SMF 2.1.*">
<hook reverse="true" hook="integrate_general_mod_settings" function="FaviconIndicator::hook_general_mod_settings" file="$sourcedir/FaviconIndicator.php" />
<hook reverse="true" hook="integrate_XMLhttpMain_subActions" function="FaviconIndicator::hook_XMLhttpMain_subActions" file="$sourcedir/FaviconIndicator.php" />
<hook reverse="true" hook="integrate_load_theme" function="FaviconIndicator::hook_load_theme" file="$sourcedir/FaviconIndicator.php" />

<remove-file name="$themes_dir/default/languages/FaviconIndicator.english.php" />
<remove-file name="$themes_dir/default/scripts/tinycon.min.js" />
<remove-file name="$sourcedir/FaviconIndicator.php" />
</uninstall>

<install for="SMF 2.0.*">
<code>SMF2.0/hooks_add.php</code>
<move-file name="SMF2.0/UnreadPMs.php" destination="$sourcedir/" />
<move-file name="tinycon.min.js" destination="$themedir/scripts/" />
<modification>language.xml</modification>
<modification>language.russian.xml</modification>
<modification>language.russian-utf8.xml</modification>
<redirect url="?action=admin;area=modsettings;" timeout="1000" />
<modification>SMF2.0/language.xml</modification>
</install>

<uninstall for="SMF 2.0-2.0.99">
<code>hooks_remove.php</code>
<uninstall for="SMF 2.0.*">
<code>SMF2.0/hooks_remove.php</code>
<remove-file name="$themedir/scripts/tinycon.min.js" />
<remove-file name="$sourcedir/UnreadPMs.php" />
<modification reverse="true">language.xml</modification>
<modification reverse="true">language.russian.xml</modification>
<modification reverse="true">language.russian-utf8.xml</modification>
<modification reverse="true">SMF2.0/language.xml</modification>
</uninstall>

</package-info>
</package-info>

0 comments on commit 27daf0f

Please sign in to comment.