-
Notifications
You must be signed in to change notification settings - Fork 2
/
plugins.php
219 lines (192 loc) · 6.5 KB
/
plugins.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
###############################################################################
# Gregarius - A PHP based RSS aggregator.
# Copyright (C) 2003 - 2006 Marco Bonetti
#
###############################################################################
# This program is free software and open source software; you can redistribute
# it and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the License,
# or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit
# http://www.gnu.org/licenses/gpl.html
#
###############################################################################
# E-mail: mbonetti at gmail dot com
# Web page: http://gregarius.net/
#
###############################################################################
require_once('init.php');
/**
* (private)
* Returns a reference to the hooks array, which holds
* references of installed plugin's callback functions
*/
function & __getHooksArray() {
static $__rss_hooks;
if ($__rss_hooks == null) {
$__rss_hooks = array();
}
return ($__rss_hooks);
}
/**
* (private)
* Returns a reference to the filename of the plugin
* being currently loaded
*/
function & __getLoadingPlugin() {
static $__rss_loading_plugin;
return ($__rss_loading_plugin);
}
function set_loading_plugin($loading) {
$static_var =& __getLoadingPlugin();
$static_var = $loading;
}
/**
* Allows a plugin to register itself for the
* given hook
*/
function rss_set_hook($hook,$fnct) {
$hooks =& __getHooksArray();
$loading_filename =& __getLoadingPlugin();
if (!array_key_exists($loading_filename, $hooks)) {
$hooks[$loading_filename]=array();
}
$filehooks =& $hooks[$loading_filename];
if (array_key_exists($hook, $filehooks)) {
$filehooks[$hook][] = $fnct;
} else {
$filehooks[$hook]=array($fnct);
}
}
/**
* Performs callbacks for the given hook,
* based on the plugins registered functions
*/
function rss_plugin_hook($hook, $data, $plugin_filename=null) {
$hooks =& __getHooksArray();
foreach($hooks as $this_plugin_name => $filehooks) {
if (!isset($plugin_filename) || $this_plugin_name == $plugin_filename) {
if (array_key_exists($hook, $filehooks)) {
foreach($filehooks[$hook] as $fnct) {
if (function_exists($fnct)) {
_pf("calling plugin func $fnct in '$this_plugin_name' for $hook ...");
$data = call_user_func($fnct,$data);
_pf("done");
}
}
}
}
}
return $data;
}
/***** Plugin options ******/
/**
* Wrapper functions for plugins
*
* Notes: Make sure that $value and $default are not escaped strings/arrays of strings,
* otherwise they will not come out of the database correctly because of rss_real_escape_string
*/
function rss_plugins_add_option($key, $value, $type = "string", $default = "", $desc= "", $export = NULL) {
if (!$key) {
return false;
}
$pKey = "plugins." . rss_real_escape_string($key);
if (is_array($value) || $type == 'array') {
$value = serialize($value);
}
$value = rss_real_escape_string($value);
$default = $default? $default: $value;
$ret = rss_query("replace into " . getTable("config")
. " (key_,value_,default_,type_,desc_,export_) VALUES ("
. "'$pKey','$value','$default','$type','$desc','$export')" );
configInvalidate();
return $ret;
}
function rss_plugins_get_option($key) {
if (!$key) {
return false;
}
return getConfig("plugins.".rss_real_escape_string($key), false);
}
function rss_plugins_delete_option($key) {
if (!$key) {
return;
}
$pKey = "plugins." . rss_real_escape_string($key);
$ret = rss_query("delete from " . getTable("config") . " where key_='$pKey'");
configInvalidate();
return $ret;
}
function rss_plugins_set_item_state($itemId, $bit_mask, $set
, $sqlwhere = "", $entire_db = false) {
$retvalue = false;
if($itemId || $entire_db) { // Check to see if itemId is set or if we are allowed to fsck up the entire db
// the bitmask has a one in the spot (field(s)) we want to change.
if($set
) { // Set the value to the field to 1
$sql = "update " .getTable("item") ." set unread = unread | ". $bit_mask;
}
else { // set the value of the field to 0
$sql = "update " .getTable("item") ." set unread = unread & ". ~ $bit_mask;
}
if($itemId) {
if (is_array($itemId)) {
$sql .= " where id in (" . implode(',',$itemId) .")";
} else { // assume it is a number or a string
$sql .= " where id=" .$itemId;
}
} else {
$sql .= " where 1";
}
if($sqlwhere) {
$sql .= " and " . $sqlwhere;
}
$retvalue = rss_query($sql);
rss_invalidate_cache();
} else {
$retvalue = false;
}
return $retvalue;
}
function rss_plugins_get_plugins_http_path() {
//returns http://example.com/rss/plugins/
return guessTransportProto().$_SERVER['HTTP_HOST'] . getPath() . RSS_PLUGINS_DIR . "/";
}
/**
* loads the specified plugin file
*/
function rss_load_plugin( $plugin_filename )
{
set_loading_plugin($plugin_filename);
if( file_exists(rss_home_dir() . RSS_PLUGINS_DIR.'/'.$plugin_filename ) ) {
rss_require(RSS_PLUGINS_DIR.'/'.$plugin_filename);
}
set_loading_plugin('');
}
/**
* loads the active plugins from the config, instantiates
* them
*/
foreach(getConfig('rss.config.plugins') as $pf) {
rss_load_plugin($pf);
}
/*
* autoload plugins specific to a theme without the
* need to add them to config
* all plugins def must be inside a unique file called plugins.php that
* do all the works
*/
$mythemeplugin=getThemePath(GREGARIUS_HOME)."plugins.php";
if (file_exists($mythemeplugin)) {
require_once($mythemeplugin);
}
?>