-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update for SMF 2.1, revamping into supporting alerts
- Loading branch information
1 parent
5839e8f
commit 27daf0f
Showing
13 changed files
with
201 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0
hooks_add.php → SMF2.0/hooks_add.php
100755 → 100644
File renamed without changes.
0
hooks_remove.php → SMF2.0/hooks_remove.php
100755 → 100644
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.