From c80190fcbdd88b10f9071bd057a0408ff9243c4a Mon Sep 17 00:00:00 2001 From: pdontthink Date: Wed, 4 Jun 2008 23:00:50 +0000 Subject: [PATCH] Make newmail plugin work again, various small cleanup and add ability for admin to configure custom title bar strings git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@13170 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- plugins/newmail/config_default.php | 40 +++++++++++++ plugins/newmail/config_sample.php | 72 ++++++++++++++++++++-- plugins/newmail/functions.php | 96 ++++++++++++++++++------------ plugins/newmail/newmail.php | 42 +++++++++++-- plugins/newmail/newmail_opt.php | 30 ++++++---- plugins/newmail/setup.php | 59 +++++++++++++++--- 6 files changed, 273 insertions(+), 66 deletions(-) diff --git a/plugins/newmail/config_default.php b/plugins/newmail/config_default.php index cd52c791..881db663 100644 --- a/plugins/newmail/config_default.php +++ b/plugins/newmail/config_default.php @@ -11,6 +11,41 @@ * @subpackage newmail */ + +/** + * Custom formatting for both new mail popup window title + * bar and changed main SquirrelMail window title bar + * + * If you change these, they will ONLY show up in the + * language you use here unless you add it to your + * SquirrelMail translation files! + * + * Use ###USERNAME### in these strings if you want to insert + * the username in the title. + * + * Use ###ORG_TITLE### in these strings if you want to insert + * the $org_title setting from the main SquirrelMail config + * in the title. + * + * Use %s in these strings if you want to insert the number + * of new messages in the title. + * + * Leave blank to use default title bar strings + * + * $newmail_title_bar_singular = '###USERNAME### - %s New Message'; + * $newmail_title_bar_plural = '###USERNAME### - %s New Messages'; + * $newmail_popup_title_bar_singular = '###ORG_TITLE### - New Mail'; + * $newmail_popup_title_bar_plural = '###ORG_TITLE### - New Mail'; + * + */ +global $newmail_title_bar_singular, $newmail_title_bar_plural, + $newmail_popup_title_bar_singular, $newmail_popup_title_bar_plural; +$newmail_title_bar_singular = ''; +$newmail_title_bar_plural = ''; +$newmail_popup_title_bar_singular = ''; +$newmail_popup_title_bar_plural = ''; + + /** * Set $newmail_allowsound to false if you don't want sound files available * @global boolean $newmail_allowsound @@ -18,6 +53,7 @@ global $newmail_allowsound; $newmail_allowsound = true; + /** * Set $newmail_uploadsounds to false if you don't want to allow uploading * of custom sound files. @@ -26,6 +62,7 @@ $newmail_allowsound = true; global $newmail_uploadsounds; $newmail_uploadsounds = true; + /** * controls insertion of embed tags * @global boolean $newmail_mediacompat_mode @@ -33,6 +70,7 @@ $newmail_uploadsounds = true; global $newmail_mediacompat_mode; $newmail_mediacompat_mode=false; + /** * List of available multimedia files. * @@ -46,3 +84,5 @@ $newmail_mediacompat_mode=false; */ global $newmail_mmedia; $newmail_mmedia=array(); + + diff --git a/plugins/newmail/config_sample.php b/plugins/newmail/config_sample.php index 88994d8e..7d8ef303 100644 --- a/plugins/newmail/config_sample.php +++ b/plugins/newmail/config_sample.php @@ -11,20 +11,78 @@ * @subpackage newmail */ -// Set $newmail_allowsound to false if you don't want sound files available + +/** + * Custom formatting for both new mail popup window title + * bar and changed main SquirrelMail window title bar + * + * If you change these, they will ONLY show up in the + * language you use here unless you add it to your + * SquirrelMail translation files! + * + * Use ###USERNAME### in these strings if you want to insert + * the username in the title. + * + * Use ###ORG_TITLE### in these strings if you want to insert + * the $org_title setting from the main SquirrelMail config + * in the title. + * + * Use %s in these strings if you want to insert the number + * of new messages in the title. + * + * Leave blank to use default title bar strings + * + * $newmail_title_bar_singular = '###USERNAME### - %s New Message'; + * $newmail_title_bar_plural = '###USERNAME### - %s New Messages'; + * $newmail_popup_title_bar_singular = '###ORG_TITLE### - New Mail'; + * $newmail_popup_title_bar_plural = '###ORG_TITLE### - New Mail'; + * + */ +global $newmail_title_bar_singular, $newmail_title_bar_plural, + $newmail_popup_title_bar_singular, $newmail_popup_title_bar_plural; +$newmail_title_bar_singular = ''; +$newmail_title_bar_plural = ''; +$newmail_popup_title_bar_singular = ''; +$newmail_popup_title_bar_plural = ''; + + +/** + * Set $newmail_allowsound to false if you don't want sound files available + * @global boolean $newmail_allowsound + */ +global $newmail_allowsound; $newmail_allowsound = true; + /** - * Don't allow custom sounds - * prefs are stored in DB and data directory is not shared between - * web cluster hosts. + * Set $newmail_uploadsounds to false if you don't want to allow uploading + * of custom sound files. + * @global boolean $newmail_uploadsounds */ +global $newmail_uploadsounds; $newmail_uploadsounds = false; -// controls insertion of embed tags + +/** + * controls insertion of embed tags + * @global boolean $newmail_mediacompat_mode + */ +global $newmail_mediacompat_mode; $newmail_mediacompat_mode=false; -// List of enabled media files + +/** + * List of available multimedia files. + * + * For example. + * $newmail_mmedia['notify']['types'] = array(SM_NEWMAIL_FILETYPE_SWF,SM_NEWMAIL_FILETYPE_MP3,SM_NEWMAIL_FILETYPE_WAV); + * $newmail_mmedia['notify']['args'] = array('width'=>0,'height'=>0); + * + * These two entries say that media/ directory contains notify.swf, notify.mp3 and notify.wav files + * Object elements for these files should use zero width and height attributes + * @global array $newmail_mmedia + */ +global $newmail_mmedia; $newmail_mmedia['notify']['types'] = array(SM_NEWMAIL_FILETYPE_SWF,SM_NEWMAIL_FILETYPE_MP3,SM_NEWMAIL_FILETYPE_WAV); $newmail_mmedia['notify']['args'] = array('width'=>0,'height'=>0); $newmail_mmedia['got_a_message']['types'] = array(SM_NEWMAIL_FILETYPE_SWF,SM_NEWMAIL_FILETYPE_MP3,SM_NEWMAIL_FILETYPE_WAV); @@ -33,3 +91,5 @@ $newmail_mmedia['monty_message']['types'] = array(SM_NEWMAIL_FILETYPE_SWF,SM_NEW $newmail_mmedia['monty_message']['args'] = array('width'=>0,'height'=>0); $newmail_mmedia['austin_mail']['types'] = array(SM_NEWMAIL_FILETYPE_SWF,SM_NEWMAIL_FILETYPE_MP3,SM_NEWMAIL_FILETYPE_WAV); $newmail_mmedia['austin_mail']['args'] = array('width'=>0,'height'=>0); + + diff --git a/plugins/newmail/functions.php b/plugins/newmail/functions.php index 23f0cab8..c85f63e6 100644 --- a/plugins/newmail/functions.php +++ b/plugins/newmail/functions.php @@ -44,7 +44,7 @@ function newmail_optpage_register_block_function() { /* Register Squirrelspell with the $optionpages array. */ $optpage_blocks[] = array( - 'name' => _("NewMail Options"), + 'name' => _("New Mail Options"), 'url' => sqm_baseuri() . 'plugins/newmail/newmail_opt.php', 'desc' => _("This configures settings for playing sounds and/or showing popup windows when new mail arrives."), 'js' => TRUE @@ -166,7 +166,7 @@ function newmail_pref_function() { function newmail_set_loadinfo_function() { global $optpage, $optpage_name; if ($optpage=='newmail') { - $optpage_name=_("NewMail Options"); + $optpage_name=_("New Mail Options"); } } @@ -216,16 +216,18 @@ function newmail_folder_status($statusarr) { */ function newmail_plugin_function() { global $username, $newmail_media, $newmail_media_enable, $newmail_popup, - $newmail_recent, $newmail_changetitle, $imapConnection; - global $newmail_mmedia, $newmail_allowsound; - global $newmail_userfile_type; - global $newmail_popup_width, $newmail_popup_height; - global $totalNewArr; + $newmail_recent, $newmail_changetitle, $imapConnection, + $newmail_mmedia, $newmail_allowsound, $newmail_userfile_type, + $newmail_popup_width, $newmail_popup_height, $totalNewArr, + $newmail_title_bar_singular, $newmail_title_bar_plural, + $org_title; if ($newmail_media_enable == 'on' || $newmail_popup == 'on' || $newmail_changetitle) { + $output = ''; + if (!empty($totalNewArr)) { $totalNew=array_sum($totalNewArr); } else { $totalNew=0; } @@ -233,46 +235,64 @@ function newmail_plugin_function() { // will play the sound as follows: if ($newmail_changetitle) { - echo "\n"; + + // make sure default strings are in pot file + $ignore = _("%s New Message"); + $ignore = _("%s New Messages"); + + $singular_title = "%s New Message"; + $plural_title = "%s New Messages"; + if (!empty($newmail_title_bar_singular)) + $singular_title = $newmail_title_bar_singular; + if (!empty($newmail_title_bar_plural)) + $plural_title = $newmail_title_bar_plural; + list($singular_title, $plural_title) = str_replace(array('###USERNAME###', '###ORG_TITLE###'), array($username, $org_title), array($singular_title, $plural_title)); + $title = sprintf(ngettext($singular_title, $plural_title, $totalNew), $totalNew); + +//FIXME: remove HTML from core - put this into a template file + $output .= "\n"; } // create media output if there are new email messages if ($newmail_allowsound && $totalNew > 0 - && $newmail_media_enable == 'on' - && $newmail_media != '' ) { - echo newmail_create_media_tags($newmail_media); + && $newmail_media_enable == 'on' + && $newmail_media != '' ) { +//FIXME: remove HTML from core - put this into a template file + $output .= newmail_create_media_tags($newmail_media); } if ($totalNew > 0 && $newmail_popup == 'on') { - // Idea by: Nic Wolfe (Nic@TimelapseProductions.com) - // Web URL: http://fineline.xs.mw - // More code from Tyler Akins - echo "\n"; +//FIXME: remove HTML from core - put this into a template file + $output .= "\n"; } + + return array('left_main_after' => $output); + } + } // ----- end of hooked functions ----- diff --git a/plugins/newmail/newmail.php b/plugins/newmail/newmail.php index 7262d5f5..e9e79fb7 100644 --- a/plugins/newmail/newmail.php +++ b/plugins/newmail/newmail.php @@ -18,10 +18,45 @@ */ require('../../include/init.php'); -sqGetGlobalVar('numnew', $numnew, SQ_GET); -$numnew = (int)$numnew; +/** + * Make sure plugin is activated! + */ +global $plugins; +if (!in_array('newmail', $plugins)) + exit; + +/** load default config */ +if (file_exists(SM_PATH . 'plugins/newmail/config_default.php')) { + include_once(SM_PATH . 'plugins/newmail/config_default.php'); +} + +/** load config */ +if (file_exists(SM_PATH . 'config/newmail_config.php')) { + include_once(SM_PATH . 'config/newmail_config.php'); +} elseif (file_exists(SM_PATH . 'plugins/newmail/config.php')) { + include_once(SM_PATH . 'plugins/newmail/config.php'); +} + + sqGetGlobalVar('numnew', $numnew, SQ_GET); + $numnew = (int)$numnew; + + global $username, $org_title, + $newmail_popup_title_bar_singular, $newmail_popup_title_bar_plural; + + // make sure default strings are in pot file + $ignore = _("New Mail"); + + $singular_title = "New Mail"; + $plural_title = "New Mail"; + if (!empty($newmail_popup_title_bar_singular)) + $singular_title = $newmail_popup_title_bar_singular; + if (!empty($newmail_popup_title_bar_plural)) + $plural_title = $newmail_popup_title_bar_plural; + list($singular_title, $plural_title) = str_replace(array('###USERNAME###', '###ORG_TITLE###'), array($username, $org_title), array($singular_title, $plural_title)); + $title = sprintf(ngettext($singular_title, $plural_title, $numnew), $numnew); + - displayHtmlHeader( _("New Mail"), '', FALSE ); + displayHtmlHeader( $title, '', FALSE ); echo ''."\n". '
'. "\n" . @@ -49,4 +84,3 @@ $numnew = (int)$numnew; "-->\n". "\n". "\n"; -?> \ No newline at end of file diff --git a/plugins/newmail/newmail_opt.php b/plugins/newmail/newmail_opt.php index ff581ac9..8cef1c3d 100644 --- a/plugins/newmail/newmail_opt.php +++ b/plugins/newmail/newmail_opt.php @@ -18,6 +18,13 @@ */ require('../../include/init.php'); +/** + * Make sure plugin is activated! + */ +global $plugins; +if (!in_array('newmail', $plugins)) + exit; + /** Plugin functions (also loads plugin's config) */ include_once(SM_PATH . 'plugins/newmail/functions.php'); @@ -25,6 +32,7 @@ include_once(SM_PATH . 'functions/forms.php'); displayPageHeader($color); +//FIXME: Remove all HTML from core - put this all into a template file echo html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . "\n" . html_tag( 'tr' ) . "\n" . html_tag( 'td', '', 'center' ) . @@ -33,15 +41,15 @@ echo html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" ce html_tag( 'tr' ) . "\n" . html_tag( 'td', '', 'left', $color[4] ) . "
\n"; -echo html_tag( 'p',_("The NewMail plugin will follow the Folder Preferences option "Enable Unread Message Notification"")) . "\n" . +echo html_tag( 'p',_("Based on the Folder Preferences option "Enable Unread Message Notification", you can be notified when new messages arrive in your account.")) . "\n" . html_tag( 'p', - sprintf(_("Selecting the %s option will enable the showing of a popup window when unseen mail is in your folders (requires JavaScript)."), '"'._("Show popup window on new mail").'"') + sprintf(_("Selecting the %s option will enable the showing of a popup window when unseen mail is in one of your folders (requires JavaScript)."), '"'._("Show popup window on new mail").'"') ) . "\n" . html_tag( 'p', sprintf(_("Use the %s option to only check for messages that are recent. Recent messages are those that have just recently showed up and have not been \"viewed\" or checked yet. This can prevent being continuously annoyed by sounds or popups for unseen mail."), '"'._("Count only messages that are RECENT").'"') ) . "\n" . html_tag( 'p', - sprintf(_("Selecting the %s option will change the title in some browsers to let you know when you have new mail (requires JavaScript). This will always tell you if you have new mail, even if you have %s enabled."), '"'._("Change title on supported browsers").'"', '"'._("Count only messages that are RECENT").'"') + sprintf(_("Selecting the %s option will change the browser title bar to let you know when you have new mail (requires JavaScript and may only work in some browsers). This will always tell you if you have new mail, even if you have %s enabled."), '"'._("Change title on supported browsers").'"', '"'._("Count only messages that are RECENT").'"') ) . "\n"; if ($newmail_allowsound) { echo html_tag( 'p', @@ -72,33 +80,33 @@ echo html_tag('tr', // Option: media_recent echo html_tag( 'tr' ) . - html_tag( 'td', _("Count only messages that are RECENT").':', 'right', '', 'style="white-space: nowrap;"' ) . + html_tag( 'td', '', 'right', '', 'style="white-space: nowrap;"' ) . html_tag( 'td', '', 'left' ) . '' . "\n"; +echo 'name="media_recent" id="media_recent" />' . "\n"; // Option: media_changetitle echo html_tag( 'tr' ) . - html_tag( 'td', _("Change title on supported browsers").':', 'right', '', 'style="white-space: nowrap;"' ) . + html_tag( 'td', '', 'right', '', 'style="white-space: nowrap;"' ) . html_tag( 'td', '', 'left' ) . ' ('._("requires JavaScript to work").')' . "\n"; +echo 'name="media_changetitle" id="media_changetitle" /> ' . "\n"; // Option: media_popup echo html_tag( 'tr' ) . - html_tag( 'td', _("Show popup window on new mail").':', 'right', '', 'style="white-space: nowrap;"' ) . + html_tag( 'td', '', 'right', '', 'style="white-space: nowrap;"' ) . html_tag( 'td', '', 'left' ) . ' ('._("requires JavaScript to work").')' . "\n"; +echo 'name="media_popup" id="media_popup" /> ' . "\n"; echo html_tag( 'tr' ) . html_tag('td',_("Width of popup window:"),'right','', 'style="white-space: nowrap;"') @@ -117,13 +125,13 @@ echo html_tag( 'tr' ) if ($newmail_allowsound) { // Option: media_enable echo html_tag( 'tr' ) . - html_tag( 'td', _("Enable Media Playing").':', 'right', '', 'style="white-space: nowrap;"' ) . + html_tag( 'td', '', 'right', '', 'style="white-space: nowrap;"' ) . html_tag( 'td', '', 'left' ) . '' . "\n"; + echo 'name="media_enable" id="media_enable" />' . "\n"; // Option: media_sel echo html_tag( 'tr' ) . diff --git a/plugins/newmail/setup.php b/plugins/newmail/setup.php index 796f965e..0e2fcab0 100644 --- a/plugins/newmail/setup.php +++ b/plugins/newmail/setup.php @@ -32,18 +32,27 @@ * Init newmail plugin */ function squirrelmail_plugin_init_newmail() { + global $squirrelmail_plugin_hooks; $totalNewArr=array(); global $totalNewArr; - $squirrelmail_plugin_hooks['folder_status']['newmail'] = 'newmail_folder_status'; - $squirrelmail_plugin_hooks['left_main_after']['newmail'] = 'newmail_plugin'; - $squirrelmail_plugin_hooks['optpage_register_block']['newmail'] = 'newmail_optpage_register_block'; - $squirrelmail_plugin_hooks['options_save']['newmail'] = 'newmail_sav'; - $squirrelmail_plugin_hooks['loading_prefs']['newmail'] = 'newmail_pref'; - $squirrelmail_plugin_hooks['optpage_set_loadinfo']['newmail'] = 'newmail_set_loadinfo'; + $squirrelmail_plugin_hooks['folder_status']['newmail'] + = 'newmail_folder_status'; + $squirrelmail_plugin_hooks['template_construct_left_main.tpl']['newmail'] + = 'newmail_plugin'; + $squirrelmail_plugin_hooks['optpage_register_block']['newmail'] + = 'newmail_optpage_register_block'; + $squirrelmail_plugin_hooks['options_save']['newmail'] + = 'newmail_sav'; + $squirrelmail_plugin_hooks['loading_prefs']['newmail'] + = 'newmail_pref'; + $squirrelmail_plugin_hooks['optpage_set_loadinfo']['newmail'] + = 'newmail_set_loadinfo'; + } + /** * Register newmail option block */ @@ -52,6 +61,7 @@ function newmail_optpage_register_block() { newmail_optpage_register_block_function(); } + /** * Save newmail plugin settings */ @@ -60,6 +70,7 @@ function newmail_sav() { newmail_sav_function(); } + /** * Load newmail plugin settings */ @@ -68,6 +79,7 @@ function newmail_pref() { newmail_pref_function(); } + /** * Set loadinfo data * @@ -78,10 +90,43 @@ function newmail_set_loadinfo() { newmail_set_loadinfo_function(); } + /** * Insert needed data in left_main */ function newmail_plugin() { include_once(SM_PATH . 'plugins/newmail/functions.php'); - newmail_plugin_function(); + return newmail_plugin_function(); +} + + +/** + * Returns info about this plugin + * + */ +function newmail_info() { + return array( + 'english_name' => 'New Mail', + 'authors' => array( + 'SquirrelMail Team' => array(), + ), + 'version' => 'CORE', + 'required_sm_version' => 'CORE', + 'requires_configuration' => 0, + 'summary' => 'This plugin is used to notify the user when a new mail arrives.', + 'details' => 'This plugin is used to notify the user when a new mail arrives. This is accomplished by playing a sound through the browser or spawning a popup window whenever the user has unseen messages.', + ); } + + + +/** + * Returns version info about this plugin + * + */ +function newmail_version() { + $info = newmail_info(); + return $info['version']; +} + + -- 2.25.1