| 1 | <?php |
|---|
| 2 | ############################################################################### |
|---|
| 3 | # Gregarius - A PHP based RSS aggregator. |
|---|
| 4 | # Copyright (C) 2003 - 2006 Marco Bonetti |
|---|
| 5 | # |
|---|
| 6 | ############################################################################### |
|---|
| 7 | # This program is free software and open source software; you can redistribute |
|---|
| 8 | # it and/or modify it under the terms of the GNU General Public License as |
|---|
| 9 | # published by the Free Software Foundation; either version 2 of the License, |
|---|
| 10 | # or (at your option) any later version. |
|---|
| 11 | # |
|---|
| 12 | # This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 13 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 14 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 15 | # more details. |
|---|
| 16 | # |
|---|
| 17 | # You should have received a copy of the GNU General Public License along |
|---|
| 18 | # with this program; if not, write to the Free Software Foundation, Inc., |
|---|
| 19 | # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit |
|---|
| 20 | # http://www.gnu.org/licenses/gpl.html |
|---|
| 21 | # |
|---|
| 22 | ############################################################################### |
|---|
| 23 | # E-mail: mbonetti at gmail dot com |
|---|
| 24 | # Web page: http://gregarius.net/ |
|---|
| 25 | # |
|---|
| 26 | ############################################################################### |
|---|
| 27 | |
|---|
| 28 | /// Name: Mark All Read |
|---|
| 29 | /// Author: Keith D. Zimmerman |
|---|
| 30 | /// Description: Display "Mark All Read" buttons and links in many places |
|---|
| 31 | /// Version: 0.6 |
|---|
| 32 | /// Configuration: __markallread_config |
|---|
| 33 | |
|---|
| 34 | /** |
|---|
| 35 | * Changelog: |
|---|
| 36 | * |
|---|
| 37 | * 0.1 getting started |
|---|
| 38 | * 0.2 initial public release |
|---|
| 39 | * 0.3 support for i18n |
|---|
| 40 | * 0.4 Fixed a couple validation issues |
|---|
| 41 | * 0.5 Adapted for new l10n method |
|---|
| 42 | * 0.6 Fixed quotes |
|---|
| 43 | */ |
|---|
| 44 | |
|---|
| 45 | define ('MARKALLREAD_CONFIG_OPTIONS', 'markallread.options'); |
|---|
| 46 | |
|---|
| 47 | define ('MARKALLREAD_OPTION_BUTTON', 0x1); |
|---|
| 48 | define ('MARKALLREAD_OPTION_LINK_FEED', 0x2); |
|---|
| 49 | define ('MARKALLREAD_OPTION_LINK_FOLDER', 0x4); |
|---|
| 50 | define ('MARKALLREAD_OPTION_LINK_CATEGORY', 0x8); |
|---|
| 51 | define ('MARKALLREAD_OPTION_CONFIIRM', 0x10); |
|---|
| 52 | define ('MARKALLREAD_OPTION_BOTTOM_BUTTON', 0x20); |
|---|
| 53 | |
|---|
| 54 | function __markallread_js($js) { |
|---|
| 55 | $js[] = getPath(). RSS_PLUGINS_DIR . "/markallread.php?myjs"; |
|---|
| 56 | return $js; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | function __markallread_sidemenu_categoryunreadlabel( $existingText ) { |
|---|
| 60 | if( hidePrivate() ) |
|---|
| 61 | return $existingText; |
|---|
| 62 | |
|---|
| 63 | $options = rss_plugins_get_option( MARKALLREAD_CONFIG_OPTIONS ); |
|---|
| 64 | if( $options & MARKALLREAD_OPTION_LINK_CATEGORY ) |
|---|
| 65 | return "<a title=\"".__('Mark This Category as Read')."\" href=\"". getPath() ."feed.php?metaaction=ACT_MARK_VFOLDER_READ&vfolder=" . rss_feeds_folder_id() . "\" onclick=\"return _markallread(this,'category','" . rss_feeds_folder_name() . "');\">" . $existingText . '</a>'; |
|---|
| 66 | else |
|---|
| 67 | return $existingText; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | function __markallread_sidemenu_folderunreadlabel( $existingText ) { |
|---|
| 71 | if( hidePrivate() ) |
|---|
| 72 | return $existingText; |
|---|
| 73 | |
|---|
| 74 | $options = rss_plugins_get_option( MARKALLREAD_CONFIG_OPTIONS ); |
|---|
| 75 | if( $options & MARKALLREAD_OPTION_LINK_FOLDER ) |
|---|
| 76 | return "<a title=\"".__('Mark This Folder as Read')."\" href=\"". getPath() ."feed.php?metaaction=ACT_MARK_FOLDER_READ&folder=" . rss_feeds_folder_id() . "\" onclick=\"return _markallread(this,'folder','" . rss_feeds_folder_name() . "');\">" . $existingText . '</a>'; |
|---|
| 77 | else |
|---|
| 78 | return $existingText; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | function __markallread_sidemenu_feedunreadlabel( $existingText ) { |
|---|
| 82 | if (hidePrivate() || (class_exists('TagList') && is_a($GLOBALS['rss']-> feedList, 'TagList'))) { |
|---|
| 83 | return $existingText; |
|---|
| 84 | } |
|---|
| 85 | $options = rss_plugins_get_option( MARKALLREAD_CONFIG_OPTIONS ); |
|---|
| 86 | if( $options & MARKALLREAD_OPTION_LINK_FEED ) |
|---|
| 87 | return "<a title='".__('Mark This Feed as Read')."\" href=\"". getPath() ."feed.php?metaaction=ACT_MARK_CHANNEL_READ&channel=" . $GLOBALS['rss']->currentFeedsFeed-> id . "\" onclick=\"return _markallread(this,'feed','" . rss_feeds_feed_title() . "');\">" . $existingText . '</a>'; |
|---|
| 88 | else |
|---|
| 89 | return $existingText; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | function __markallread_buttondisplay() { |
|---|
| 93 | $options = rss_plugins_get_option( MARKALLREAD_CONFIG_OPTIONS ); |
|---|
| 94 | $safety = ''; |
|---|
| 95 | |
|---|
| 96 | if(defined('MARK_READ_FEED_FORM')) { |
|---|
| 97 | $metaaction = "ACT_MARK_CHANNEL_READ"; |
|---|
| 98 | $id = 'name="channel" value="' . MARK_READ_FEED_FORM . '"'; |
|---|
| 99 | $text = __('Mark This Feed as Read'); |
|---|
| 100 | if( $options & MARKALLREAD_OPTION_CONFIIRM ) |
|---|
| 101 | $safety = ' onclick="return _confirmmarkallread(\'feed\', \'\');"'; |
|---|
| 102 | } elseif(defined('MARK_READ_FOLDER_FORM')) { |
|---|
| 103 | $metaaction = "ACT_MARK_FOLDER_READ"; |
|---|
| 104 | $id = 'name="folder" value="' . MARK_READ_FOLDER_FORM . '"'; |
|---|
| 105 | $text = __('Mark This Folder as Read'); |
|---|
| 106 | if( $options & MARKALLREAD_OPTION_CONFIIRM ) |
|---|
| 107 | $safety = ' onclick="return _confirmmarkallread(\'folder\', \'\');"'; |
|---|
| 108 | } elseif(defined('MARK_READ_VFOLDER_FORM')){ |
|---|
| 109 | $metaaction = "ACT_MARK_VFOLDER_READ"; |
|---|
| 110 | $id = 'name="vfolder" value="' . MARK_READ_VFOLDER_FORM . '"'; |
|---|
| 111 | $text = __('Mark This Category as Read'); |
|---|
| 112 | if( $options & MARKALLREAD_OPTION_CONFIIRM ) |
|---|
| 113 | $safety = ' onclick="return _confirmmarkallread(\'category\', \'\');"'; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | if( isset( $id ) && isset( $metaaction ) && isset( $text ) ) |
|---|
| 117 | { |
|---|
| 118 | ?> |
|---|
| 119 | <form action="<?php echo getPath(); ?>feed.php" method="post"> |
|---|
| 120 | <p><input id="_markReadButton" type="submit" name="action" accesskey="m" value="<?php echo $text;?>" <?php echo $safety ?>/> |
|---|
| 121 | <input type="hidden" name="metaaction" value="<?php echo $metaaction; ?>"/> |
|---|
| 122 | <input type="hidden" <?php echo $id; ?>/> |
|---|
| 123 | </p> |
|---|
| 124 | </form> |
|---|
| 125 | <?php |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | function __markallread_beforeitemsimmediate( $in ) { |
|---|
| 130 | $options = rss_plugins_get_option( MARKALLREAD_CONFIG_OPTIONS ); |
|---|
| 131 | if( hidePrivate() || !( $options & MARKALLREAD_OPTION_BUTTON ) ) |
|---|
| 132 | return $in; |
|---|
| 133 | __markallread_buttondisplay(); |
|---|
| 134 | return $in; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | function __markallread_afteritems( $in ) { |
|---|
| 138 | $options = rss_plugins_get_option( MARKALLREAD_CONFIG_OPTIONS ); |
|---|
| 139 | if( hidePrivate() || !( $options & MARKALLREAD_OPTION_BOTTOM_BUTTON ) ) |
|---|
| 140 | return $in; |
|---|
| 141 | |
|---|
| 142 | if (defined ('MARK_READ_FEED_FORM') || |
|---|
| 143 | defined ('MARK_READ_FOLDER_FORM') || |
|---|
| 144 | defined ('MARK_READ_VFOLDER_FORM')) { |
|---|
| 145 | |
|---|
| 146 | echo "<div style=\"text-align:right\">\n"; |
|---|
| 147 | __markallread_buttondisplay(); |
|---|
| 148 | echo "</div>\n"; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | return $in; |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | function __markallread_config() { |
|---|
| 155 | $options = rss_plugins_get_option( MARKALLREAD_CONFIG_OPTIONS ); |
|---|
| 156 | if(null == $options) { |
|---|
| 157 | $options = MARKALLREAD_OPTION_CONFIIRM; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | if( rss_plugins_is_submit() ) |
|---|
| 161 | { |
|---|
| 162 | $options = 0; |
|---|
| 163 | if(!empty($_REQUEST['chkMarkReadButton'])) { |
|---|
| 164 | $options |= MARKALLREAD_OPTION_BUTTON; |
|---|
| 165 | } |
|---|
| 166 | if(!empty($_REQUEST['chkMarkReadButtonBottom'])) { |
|---|
| 167 | $options |= MARKALLREAD_OPTION_BOTTOM_BUTTON; |
|---|
| 168 | } |
|---|
| 169 | if(!empty($_REQUEST['chkFeedLink'])) { |
|---|
| 170 | $options |= MARKALLREAD_OPTION_LINK_FEED; |
|---|
| 171 | } |
|---|
| 172 | if(!empty($_REQUEST['chkFolderLink'])) { |
|---|
| 173 | $options |= MARKALLREAD_OPTION_LINK_FOLDER; |
|---|
| 174 | } |
|---|
| 175 | if(!empty($_REQUEST['chkChannelLink'])) { |
|---|
| 176 | $options |= MARKALLREAD_OPTION_LINK_CATEGORY; |
|---|
| 177 | } |
|---|
| 178 | if(!empty($_REQUEST['chkConfirm'])) { |
|---|
| 179 | $options |= MARKALLREAD_OPTION_CONFIIRM; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | rss_plugins_add_option(MARKALLREAD_CONFIG_OPTIONS, $options, 'num'); |
|---|
| 183 | } |
|---|
| 184 | else |
|---|
| 185 | { |
|---|
| 186 | ?> |
|---|
| 187 | <p> |
|---|
| 188 | <input type='checkbox' value='1' name='chkMarkReadButton' id='chkMarkReadButton'<?php echo( $options & MARKALLREAD_OPTION_BUTTON ? " checked='1'" : "" );?> /> |
|---|
| 189 | <label for='chkMarkReadButton'>Display a button to mark all items read in the current feed, folder, or channel</label> |
|---|
| 190 | </p> |
|---|
| 191 | <p> |
|---|
| 192 | <input type='checkbox' value='1' name='chkMarkReadButtonBottom' id='chkMarkReadButtonBottom'<?php echo( $options & MARKALLREAD_OPTION_BOTTOM_BUTTON ? " checked='1'" : "" );?> /> |
|---|
| 193 | <label for='chkMarkReadButtonBottom'>Display an identical button at the bottom of the screen</label> |
|---|
| 194 | </p> |
|---|
| 195 | <fieldset> |
|---|
| 196 | <legend>Sidebar</legend> |
|---|
| 197 | <p> |
|---|
| 198 | <input type='checkbox' value='1' name='chkFeedLink' id='chkFeedLink'<?php echo( $options & MARKALLREAD_OPTION_LINK_FEED ? " checked='1'" : "" );?> /> |
|---|
| 199 | <label for='chkFeedLink'>Display a mark read link for feeds</label> |
|---|
| 200 | </p> |
|---|
| 201 | <p> |
|---|
| 202 | <input type='checkbox' value ='1' name='chkFolderLink' id='chkFolderLink'<?php echo( $options & MARKALLREAD_OPTION_LINK_FOLDER ? " checked='1'" : "" );?> /> |
|---|
| 203 | <label for='chkFolderLink'>Display a mark read link for folders</label> |
|---|
| 204 | </p> |
|---|
| 205 | <p> |
|---|
| 206 | <input type='checkbox' value='1' name='chkChannelLink' id='chkChannelLink'<?php echo( $options & MARKALLREAD_OPTION_LINK_CATEGORY ? " checked='1'" : "" );?> /> |
|---|
| 207 | <label for='chkChannelLink'>Display a mark read link for channels</label> |
|---|
| 208 | </p> |
|---|
| 209 | </fieldset> |
|---|
| 210 | <p> |
|---|
| 211 | <input type='checkbox' value='1' name='chkConfirm' id='chkConfirm'<?php echo( $options & MARKALLREAD_OPTION_CONFIIRM ? " checked='1'" : "" );?> /> |
|---|
| 212 | <label for='chkConfirm'>Ask for confirmation before marking items read</label> |
|---|
| 213 | </p> |
|---|
| 214 | <?php |
|---|
| 215 | } |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | if (isset($_REQUEST['myjs'])) { |
|---|
| 219 | require_once('../core.php'); |
|---|
| 220 | rss_bootstrap(false,'$Revision: 1181 $',0); |
|---|
| 221 | require_once('../init.php'); |
|---|
| 222 | |
|---|
| 223 | if (hidePrivate()) { |
|---|
| 224 | return ""; |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | ?> |
|---|
| 228 | function _confirmmarkallread( type, name ) |
|---|
| 229 | { |
|---|
| 230 | if( name != "" ) |
|---|
| 231 | name = " " + name; |
|---|
| 232 | return window.confirm( "Are you sure that you want to mark all items in the " + type + name + " as read?" ); |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | function _markallread(o,type,name) |
|---|
| 236 | { |
|---|
| 237 | //window.alert( o.href + "&redirectto=" + escape(window.location) ); |
|---|
| 238 | <?php |
|---|
| 239 | $options = rss_plugins_get_option( MARKALLREAD_CONFIG_OPTIONS ); |
|---|
| 240 | if(null == $options) { |
|---|
| 241 | $options = MARKALLREAD_OPTION_CONFIIRM; |
|---|
| 242 | } |
|---|
| 243 | if( $options & MARKALLREAD_OPTION_CONFIIRM ) { |
|---|
| 244 | ?> |
|---|
| 245 | if( _confirmmarkallread( type, name ) ) |
|---|
| 246 | <?php } ?> |
|---|
| 247 | window.location = o.href + "&redirectto=" + escape(window.location); |
|---|
| 248 | return false; |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | <?php |
|---|
| 252 | flush(); |
|---|
| 253 | exit(); |
|---|
| 254 | } |
|---|
| 255 | else |
|---|
| 256 | { |
|---|
| 257 | rss_set_hook('rss.plugins.javascript','__markallread_js'); |
|---|
| 258 | rss_set_hook('rss.plugins.sidemenu.categoryunreadlabel', '__markallread_sidemenu_categoryunreadlabel'); |
|---|
| 259 | rss_set_hook('rss.plugins.sidemenu.folderunreadlabel', '__markallread_sidemenu_folderunreadlabel'); |
|---|
| 260 | rss_set_hook('rss.plugins.sidemenu.feedunreadlabel', '__markallread_sidemenu_feedunreadlabel'); |
|---|
| 261 | rss_set_hook('rss.plugins.items.beforeitemsimmediate', '__markallread_beforeitemsimmediate'); |
|---|
| 262 | rss_set_hook('rss.plugins.items.afteritems','__markallread_afteritems'); |
|---|
| 263 | } |
|---|
| 264 | ?> |
|---|