| 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 | |
|---|
| 29 | /// Name: StickyFlag |
|---|
| 30 | /// Author: Chris J. Friesen |
|---|
| 31 | /// Description: Adds Sticky item and Flagged item functionality. |
|---|
| 32 | /// Version: 1.0 |
|---|
| 33 | /// Configuration: __StickyFlag_Config |
|---|
| 34 | |
|---|
| 35 | define ('STICKYFLAG_CONFIG_OPTIONS', 'stickyflag.options'); |
|---|
| 36 | define ('STICKYFLAG_CONFIG_FLAGICON', 'stickyflag.flagicon'); |
|---|
| 37 | |
|---|
| 38 | define ('STICKYFLAG_ENABLE_STICKY_MENU', 0x01); |
|---|
| 39 | define ('STICKYFLAG_ENABLE_FLAG_MENU', 0x02); |
|---|
| 40 | define ('STICKYFLAG_ENABLE_STICKY_SHORTCUT', 0x04); |
|---|
| 41 | define ('STICKYFLAG_ENABLE_FLAG_SHORTCUT', 0x08); |
|---|
| 42 | |
|---|
| 43 | define ('STICKYFLAG_FLAG_BLUE', 0); |
|---|
| 44 | define ('STICKYFLAG_FLAG_GREEN', 1); |
|---|
| 45 | define ('STICKYFLAG_FLAG_ORANGE', 2); |
|---|
| 46 | define ('STICKYFLAG_FLAG_RED', 3); |
|---|
| 47 | define ('STICKYFLAG_FLAG_WHITE', 4); |
|---|
| 48 | |
|---|
| 49 | define ('STICKYFLAG_EXT_FILES', getPath() . RSS_PLUGINS_DIR . "/stickyflag"); |
|---|
| 50 | define ('STICKYFLAG_ICON_STICKY', STICKYFLAG_EXT_FILES . '/sticky.png'); |
|---|
| 51 | define ('STICKYFLAG_ICON_NOSTICKY', STICKYFLAG_EXT_FILES . '/nosticky.png'); |
|---|
| 52 | define ('STICKYFLAG_ICON_FLAG_BLUE', STICKYFLAG_EXT_FILES . '/flag_blue.png'); |
|---|
| 53 | define ('STICKYFLAG_ICON_FLAG_GREEN', STICKYFLAG_EXT_FILES . '/flag_green.png'); |
|---|
| 54 | define ('STICKYFLAG_ICON_FLAG_ORANGE', STICKYFLAG_EXT_FILES . '/flag_orange.png'); |
|---|
| 55 | define ('STICKYFLAG_ICON_FLAG_RED', STICKYFLAG_EXT_FILES . '/flag_red.png'); |
|---|
| 56 | define ('STICKYFLAG_ICON_FLAG_WHITE', STICKYFLAG_EXT_FILES . '/flag_white.png'); |
|---|
| 57 | define ('STICKYFLAG_ICON_NOFLAG', STICKYFLAG_EXT_FILES . '/noflag.png'); |
|---|
| 58 | |
|---|
| 59 | function __stickyflag_Config() { |
|---|
| 60 | $options = rss_plugins_get_option(STICKYFLAG_CONFIG_OPTIONS); |
|---|
| 61 | $flag_icon = rss_plugins_get_option(STICKYFLAG_CONFIG_FLAGICON); |
|---|
| 62 | |
|---|
| 63 | if(null == $options) { |
|---|
| 64 | $options = 0; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | if(null == $flag_icon) { |
|---|
| 68 | $flag_option = 0; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | if(rss_plugins_is_submit()) { |
|---|
| 72 | $options = 0; |
|---|
| 73 | if(!empty($_REQUEST['ui_sm'])) { |
|---|
| 74 | $options |= STICKYFLAG_ENABLE_STICKY_MENU; |
|---|
| 75 | } |
|---|
| 76 | if(!empty($_REQUEST['ui_fm'])) { |
|---|
| 77 | $options |= STICKYFLAG_ENABLE_FLAG_MENU; |
|---|
| 78 | } |
|---|
| 79 | if(!empty($_REQUEST['ui_ss'])) { |
|---|
| 80 | $options |= STICKYFLAG_ENABLE_STICKY_SHORTCUT; |
|---|
| 81 | } |
|---|
| 82 | if(!empty($_REQUEST['ui_fs'])) { |
|---|
| 83 | $options |= STICKYFLAG_ENABLE_FLAG_SHORTCUT; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | rss_plugins_add_option(STICKYFLAG_CONFIG_OPTIONS, $options, 'num'); |
|---|
| 87 | rss_plugins_add_option(STICKYFLAG_CONFIG_FLAGICON, $_REQUEST['flag_icon'], 'num'); |
|---|
| 88 | return; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | print ("<fieldset>\n"); |
|---|
| 92 | print (" <legend>" . __('Sticky') . " " . __('items') . "</legend>\n"); |
|---|
| 93 | print (" <p><input id='ui_sm' type='checkbox' value='1' name='ui_sm'" . ($options & STICKYFLAG_ENABLE_STICKY_MENU ? "checked='1'" : "") . ">" |
|---|
| 94 | . "<label for='ui_sm'>Show Menu Item</label></br></p>\n"); |
|---|
| 95 | print (" <p><input id='ui_ss' type='checkbox' value='1' name='ui_ss'" . ($options & STICKYFLAG_ENABLE_STICKY_SHORTCUT ? "checked='1'" : "") . ">" |
|---|
| 96 | . "<label for='ui_ss'>Show Shortcut</label></br></p>\n"); |
|---|
| 97 | print (" <p> </p>\n"); |
|---|
| 98 | print ("</fieldset>\n"); |
|---|
| 99 | print ("<fieldset>\n"); |
|---|
| 100 | print (" <legend>" . __('Flagged') . " " . __('items') . "</legend>\n"); |
|---|
| 101 | print (" <p><input id='ui_fm' type='checkbox' value='1' name='ui_fm'" . ($options & STICKYFLAG_ENABLE_FLAG_MENU ? "checked='1'" : "") . ">" |
|---|
| 102 | . "<label for='ui_fm'>Show Menu Item</label></br></p>\n"); |
|---|
| 103 | print (" <p><input id='ui_fs' type='checkbox' value='1' name='ui_fs'" . ($options & STICKYFLAG_ENABLE_FLAG_SHORTCUT ? "checked='1'" : "") . ">" |
|---|
| 104 | . "<label for='ui_fs'>Show Shortcut</label></br></p>\n"); |
|---|
| 105 | print (" <p><input id='flag_icon' name='flag_icon' type='radio' value='" . STICKYFLAG_FLAG_BLUE . "'" . (STICKYFLAG_FLAG_BLUE == $flag_icon ? " checked='1'" : "") . ">" |
|---|
| 106 | . "<img src='" . STICKYFLAG_ICON_FLAG_BLUE . "' alt='blue'>\n" |
|---|
| 107 | . "<input id='flag_icon' name='flag_icon' type='radio' value='" . STICKYFLAG_FLAG_GREEN . "'" . (STICKYFLAG_FLAG_GREEN == $flag_icon ? " checked='1'" : "") . ">" |
|---|
| 108 | . "<img src='" . STICKYFLAG_ICON_FLAG_GREEN . "' alt='green'>\n" |
|---|
| 109 | . "<input id='flag_icon' name='flag_icon' type='radio' value='" . STICKYFLAG_FLAG_ORANGE . "'" . (STICKYFLAG_FLAG_ORANGE == $flag_icon ? " checked='1'" : "") . ">" |
|---|
| 110 | . "<img src='" . STICKYFLAG_ICON_FLAG_ORANGE . "' alt='orange'>\n" |
|---|
| 111 | . "<input id='flag_icon' name='flag_icon' type='radio' value='" . STICKYFLAG_FLAG_RED . "'" . (STICKYFLAG_FLAG_RED == $flag_icon ? " checked='1'" : "") . ">" |
|---|
| 112 | . "<img src='" . STICKYFLAG_ICON_FLAG_RED . "' alt='red'>\n" |
|---|
| 113 | . "<input id='flag_icon' name='flag_icon' type='radio' value='" . STICKYFLAG_FLAG_WHITE . "'" . (STICKYFLAG_FLAG_WHITE == $flag_icon ? " checked='1'" : "") . ">" |
|---|
| 114 | . "<img src='" . STICKYFLAG_ICON_FLAG_WHITE . "' alt='white'></p>\n"); |
|---|
| 115 | print ("</fieldset>\n"); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | function __stickyflag_GetFlagIcon() { |
|---|
| 119 | $icon = rss_plugins_get_option(STICKYFLAG_CONFIG_FLAGICON); |
|---|
| 120 | |
|---|
| 121 | if(null == $icon) { |
|---|
| 122 | $icon = 0; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | switch($icon) { |
|---|
| 126 | case STICKYFLAG_FLAG_BLUE : $ret = STICKYFLAG_ICON_FLAG_BLUE; |
|---|
| 127 | break; |
|---|
| 128 | case STICKYFLAG_FLAG_GREEN : $ret = STICKYFLAG_ICON_FLAG_GREEN; |
|---|
| 129 | break; |
|---|
| 130 | case STICKYFLAG_FLAG_ORANGE : $ret = STICKYFLAG_ICON_FLAG_ORANGE; |
|---|
| 131 | break; |
|---|
| 132 | case STICKYFLAG_FLAG_RED : $ret = STICKYFLAG_ICON_FLAG_RED; |
|---|
| 133 | break; |
|---|
| 134 | case STICKYFLAG_FLAG_WHITE : $ret = STICKYFLAG_ICON_FLAG_WHITE; |
|---|
| 135 | break; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | return $ret; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | function __stickyflag_AddButtons(){ |
|---|
| 142 | $usemodrewrite = getConfig('rss.output.usemodrewrite'); |
|---|
| 143 | $options = rss_plugins_get_option(STICKYFLAG_CONFIG_OPTIONS); |
|---|
| 144 | |
|---|
| 145 | if(null == $options) { |
|---|
| 146 | return; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | if($options & STICKYFLAG_ENABLE_STICKY_MENU || (isMobileDevice() && $options & STICKYFLAG_ENABLE_STICKY_SHORTCUT)) { |
|---|
| 150 | if (true == $usemodrewrite) { |
|---|
| 151 | $url = getPath() . "state/" . RSS_STATE_STICKY . ""; |
|---|
| 152 | } else { |
|---|
| 153 | $url = getPath() . "state.php?state=" . RSS_STATE_STICKY . ""; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | $GLOBALS['rss']->nav->addNavItem($url,'Stick<span>y</span>'); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | if($options & STICKYFLAG_ENABLE_FLAG_MENU || (isMobileDevice() && $options & STICKYFLAG_ENABLE_FLAG_SHORTCUT)) { |
|---|
| 160 | if (true == $usemodrewrite) { |
|---|
| 161 | $url = getPath() . "state/" . RSS_STATE_FLAG . ""; |
|---|
| 162 | } else { |
|---|
| 163 | $url = getPath() . "state.php?state=" . RSS_STATE_FLAG . ""; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | $GLOBALS['rss']->nav->addNavItem($url, '<span>F</span>lag'); |
|---|
| 167 | } |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | function __stickyflag_BeforeTitle($id){ |
|---|
| 171 | $ret = ""; |
|---|
| 172 | $flags = rss_item_flags(); |
|---|
| 173 | |
|---|
| 174 | if(! hidePrivate()) { |
|---|
| 175 | $options = rss_plugins_get_option(STICKYFLAG_CONFIG_OPTIONS); |
|---|
| 176 | |
|---|
| 177 | if(null == $options) { |
|---|
| 178 | return; |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | if($options & STICKYFLAG_ENABLE_STICKY_SHORTCUT) { |
|---|
| 182 | if($flags & RSS_MODE_STICKY_STATE) { |
|---|
| 183 | $ret .= "<a id='ms" . $id . "' href='#' onclick='_stickyflag_sticky(" . $id . ", " . $flags . "); return false;' title='Make Un-Sticky'>" |
|---|
| 184 | . "<img id='sticky_img_" . $id . "' src='" . STICKYFLAG_ICON_STICKY . "' alt='S' /></a> "; |
|---|
| 185 | } else { |
|---|
| 186 | $ret .= "<a id='ms" . $id . "' href='#' onclick='_stickyflag_sticky(" . $id . ", " . $flags . "); return false;' title='Make Sticky'>" |
|---|
| 187 | . "<img id='sticky_img_" . $id . "' src='" . STICKYFLAG_ICON_NOSTICKY . "' alt='S' /></a> "; |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | if($options & STICKYFLAG_ENABLE_FLAG_SHORTCUT) { |
|---|
| 192 | if($flags & RSS_MODE_FLAG_STATE) { |
|---|
| 193 | $ret .= "<a id='mf" . $id . "' href='#' onclick='_stickyflag_flag(" . $id . ", " . $flags . "); return false;' title='Un-Flag Item'>" |
|---|
| 194 | . "<img id='flag_img_" . $id . "' src='" . __stickyflag_GetFlagIcon() . "' alt='F' /></a> "; |
|---|
| 195 | } else { |
|---|
| 196 | $ret .= "<a id='mf" . $id . "' href='#' onclick='_stickyflag_flag(" . $id . ", " . $flags . "); return false;' title='Flag Item'>" |
|---|
| 197 | . "<img id='flag_img_" . $id . "' src='" . STICKYFLAG_ICON_NOFLAG . "' alt='F' /></a> "; |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | if(!empty($ret)) { |
|---|
| 202 | print($ret); |
|---|
| 203 | } |
|---|
| 204 | } |
|---|
| 205 | return $id; |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | function __stickyflag_js(){ |
|---|
| 209 | $options = rss_plugins_get_option(STICKYFLAG_CONFIG_OPTIONS); |
|---|
| 210 | |
|---|
| 211 | if(null == $options) { |
|---|
| 212 | return; |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | $ret = ""; |
|---|
| 216 | |
|---|
| 217 | if($options & STICKYFLAG_ENABLE_STICKY_SHORTCUT) { |
|---|
| 218 | $ret .= "function _stickyflag_sticky(id, state) {\n" |
|---|
| 219 | . " var sticky = " . RSS_MODE_STICKY_STATE . ";\n" |
|---|
| 220 | . " var img = document.getElementById('sticky_img_'+id);\n" |
|---|
| 221 | . "\n" |
|---|
| 222 | . " if(!document.states[id]) {\n" |
|---|
| 223 | . " document.states[id] = state;\n" |
|---|
| 224 | . " }\n" |
|---|
| 225 | . "\n" |
|---|
| 226 | . " if(document.states[id] & sticky) {\n" |
|---|
| 227 | . " document.states[id] ^= sticky;\n" |
|---|
| 228 | . " img.src = '" . STICKYFLAG_ICON_NOSTICKY . "';\n" |
|---|
| 229 | . " } else {\n" |
|---|
| 230 | . " document.states[id] |= sticky;\n" |
|---|
| 231 | . " img.src = '" . STICKYFLAG_ICON_STICKY . "';\n" |
|---|
| 232 | . " }\n" |
|---|
| 233 | . "\n" |
|---|
| 234 | . " setState(id, document.states[id]);\n" |
|---|
| 235 | . "}\n"; |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | if($options & STICKYFLAG_ENABLE_FLAG_SHORTCUT) { |
|---|
| 239 | $ret .= "function _stickyflag_flag(id, state) {\n" |
|---|
| 240 | . " var flag = " . RSS_MODE_FLAG_STATE . ";\n" |
|---|
| 241 | . " var img = document.getElementById('flag_img_'+id);\n" |
|---|
| 242 | . "\n" |
|---|
| 243 | . " if(!document.states[id]) {\n" |
|---|
| 244 | . " document.states[id] = state;\n" |
|---|
| 245 | . " }\n" |
|---|
| 246 | . "\n" |
|---|
| 247 | . " if(document.states[id] & flag) {\n" |
|---|
| 248 | . " document.states[id] ^= flag;\n" |
|---|
| 249 | . " img.src = '" . STICKYFLAG_ICON_NOFLAG . "';\n" |
|---|
| 250 | . " } else {\n" |
|---|
| 251 | . " document.states[id] |= flag;\n" |
|---|
| 252 | . " img.src = '" . __stickyflag_GetFlagIcon() . "';\n" |
|---|
| 253 | . " }\n" |
|---|
| 254 | . "\n" |
|---|
| 255 | . " setState(id, document.states[id]);\n" |
|---|
| 256 | . "}\n"; |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | if(!empty($ret)) { |
|---|
| 260 | print ($ret); |
|---|
| 261 | } |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | function __stickyflag_OnOk($ret){ |
|---|
| 265 | $options = rss_plugins_get_option(STICKYFLAG_CONFIG_OPTIONS); |
|---|
| 266 | |
|---|
| 267 | if(null == $options) { |
|---|
| 268 | return; |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | $ret .= " "; |
|---|
| 272 | |
|---|
| 273 | if($options & STICKYFLAG_ENABLE_STICKY_SHORTCUT) { |
|---|
| 274 | $ret .= "if((sfs = document.getElementById(\'sf_ID_s\')) && sfs.checked) {" |
|---|
| 275 | . " document.getElementById(\'sticky_img__ID_\').src = \'" . STICKYFLAG_ICON_STICKY . "\';" |
|---|
| 276 | . "} else {" |
|---|
| 277 | . " document.getElementById(\'sticky_img__ID_\').src = \'" . STICKYFLAG_ICON_NOSTICKY . "\';" |
|---|
| 278 | . "}"; |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | if($options & STICKYFLAG_ENABLE_FLAG_SHORTCUT) { |
|---|
| 282 | $ret .= "if((sff = document.getElementById(\'sf_ID_f\')) && sff.checked) {" |
|---|
| 283 | . " document.getElementById(\'flag_img__ID_\').src = \'" . __stickyflag_GetFlagIcon() . "\';" |
|---|
| 284 | . "} else {" |
|---|
| 285 | . " document.getElementById(\'flag_img__ID_\').src = \'" . STICKYFLAG_ICON_NOFLAG . "\';" |
|---|
| 286 | . "}"; |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | return $ret; |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | rss_set_hook("rss.plugins.navelements", "__stickyflag_AddButtons"); |
|---|
| 293 | rss_set_hook("rss.plugins.items.beforetitle", "__stickyflag_BeforeTitle"); |
|---|
| 294 | rss_set_hook("rss.plugins.ajax.extrajs.private", "__stickyflag_js"); |
|---|
| 295 | rss_set_hook("rss.plugins.ajax.admindlg.onok", "__stickyflag_OnOk"); |
|---|
| 296 | ?> |
|---|