| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
function newsclient_pagesetup() { |
|---|
| 4 |
|
|---|
| 5 |
global $profile_id; |
|---|
| 6 |
global $PAGE; |
|---|
| 7 |
global $CFG; |
|---|
| 8 |
|
|---|
| 9 |
$page_owner = $profile_id; |
|---|
| 10 |
$rss_username = user_info('username', $page_owner); |
|---|
| 11 |
|
|---|
| 12 |
if (isloggedin()) { |
|---|
| 13 |
if (defined("context") && context == "resources" && $page_owner == $_SESSION['userid']) { |
|---|
| 14 |
$PAGE->menu[] = array( 'name' => 'feeds', |
|---|
| 15 |
'html' => "<li><a href=\"{$CFG->wwwroot}{$_SESSION['username']}/feeds/\" class=\"selected\" >" .__gettext("Your Resources").'</a></li>'); |
|---|
| 16 |
} else { |
|---|
| 17 |
$PAGE->menu[] = array( 'name' => 'feeds', |
|---|
| 18 |
'html' => "<li><a href=\"{$CFG->wwwroot}{$_SESSION['username']}/feeds/\" >" .__gettext("Your Resources").'</a></li>'); |
|---|
| 19 |
} |
|---|
| 20 |
} |
|---|
| 21 |
|
|---|
| 22 |
if (defined("context") && context == "resources") { |
|---|
| 23 |
|
|---|
| 24 |
if ($page_owner != -1) { |
|---|
| 25 |
$PAGE->menu_sub[] = array( 'name' => 'newsfeed:subscription', |
|---|
| 26 |
'html' => a_href( $CFG->wwwroot.$rss_username."/feeds/", |
|---|
| 27 |
__gettext("Feeds"))); |
|---|
| 28 |
if (permissions_check("profile",$page_owner) && isloggedin()) { |
|---|
| 29 |
$PAGE->menu_sub[] = array( 'name' => 'newsfeed:subscription:publish:blog', |
|---|
| 30 |
'html' => a_href( $CFG->wwwroot."_rss/blog.php?profile_name=" . user_info("username",$page_owner), |
|---|
| 31 |
__gettext("Publish to blog"))); |
|---|
| 32 |
} |
|---|
| 33 |
$PAGE->menu_sub[] = array( 'name' => 'newsclient', |
|---|
| 34 |
'html' => a_href( $CFG->wwwroot.$rss_username."/feeds/all/", |
|---|
| 35 |
__gettext("View aggregator"))); |
|---|
| 36 |
} |
|---|
| 37 |
$PAGE->menu_sub[] = array( 'name' => 'feed', |
|---|
| 38 |
'html' => a_href( $CFG->wwwroot."_rss/popular.php", |
|---|
| 39 |
__gettext("Popular Feeds"))); |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
$PAGE->menu_sub[] = array( 'name' => 'feed', |
|---|
| 43 |
'html' => a_href( $CFG->wwwroot."help/feeds_help.php", |
|---|
| 44 |
"Page help")); |
|---|
| 45 |
*/ |
|---|
| 46 |
|
|---|
| 47 |
} |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
function newsclient_cron() { |
|---|
| 51 |
global $CFG; |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
if (!empty($CFG->newsclient_lastcron) && (time() - 300) < $CFG->newsclient_lastcron) { |
|---|
| 55 |
return true; |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
run("weblogs:init"); |
|---|
| 59 |
run("profile:init"); |
|---|
| 60 |
run("rss:init"); |
|---|
| 61 |
|
|---|
| 62 |
define('context','resources'); |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
if (empty($CFG->newsclient_lastcronprune)) { |
|---|
| 66 |
set_config('newsclient_lastcronprune',time()); |
|---|
| 67 |
} |
|---|
| 68 |
if ((time() - 86400) >= $CFG->newsclient_lastcronprune) { |
|---|
| 69 |
run('rss:prune'); |
|---|
| 70 |
set_config('newsclient_lastcronprune',time()); |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
run("rss:update:all:cron"); |
|---|
| 74 |
|
|---|
| 75 |
set_config('newsclient_lastcron',time()); |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
function newsclient_init() { |
|---|
| 81 |
global $CFG,$function; |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
// ben@elgg.net Oct 17, 2005 |
|---|
| 85 |
|
|---|
| 86 |
// Library functions |
|---|
| 87 |
require_once ($CFG->dirroot . "mod/newsclient/lib/library.php"); |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
$function['init'][] = $CFG->dirroot . "mod/newsclient/lib/default_template.php"; |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
$function['rss:init'][] = $CFG->dirroot . "mod/newsclient/lib/function_init.php"; |
|---|
| 94 |
$function['rss:init'][] = $CFG->dirroot . "mod/newsclient/lib/function_actions.php"; |
|---|
| 95 |
|
|---|
| 96 |
$function['rss:get'][] = $CFG->dirroot . "mod/newsclient/lib/function_get.php"; |
|---|
| 97 |
|
|---|
| 98 |
$function['rss:subscriptions'][] = $CFG->dirroot . "mod/newsclient/lib/function_subscriptions.php"; |
|---|
| 99 |
|
|---|
| 100 |
$function['rss:subscriptions:publish:blog'][] = $CFG->dirroot . "mod/newsclient/lib/function_subscriptions_publish_to_blog.php"; |
|---|
| 101 |
|
|---|
| 102 |
$function['rss:subscriptions:get'][] = $CFG->dirroot . "mod/newsclient/lib/function_get_subscriptions.php"; |
|---|
| 103 |
|
|---|
| 104 |
$function['rss:subscriptions:popular'][] = $CFG->dirroot . "mod/newsclient/lib/function_subscriptions_popular.php"; |
|---|
| 105 |
|
|---|
| 106 |
$function['rss:update'][] = $CFG->dirroot . "mod/newsclient/lib/function_update.php"; |
|---|
| 107 |
|
|---|
| 108 |
$function['rss:update:all'][] = $CFG->dirroot . "mod/newsclient/lib/function_update_all.php"; |
|---|
| 109 |
|
|---|
| 110 |
$function['rss:update:all:cron'][] = $CFG->dirroot . "mod/newsclient/lib/function_update_all_cron.php"; |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
$function['permissions:check'][] = $CFG->dirroot . "mod/newsclient/lib/permissions_check.php"; |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
$function['rss:view'][] = $CFG->dirroot . "mod/newsclient/lib/function_view.php"; |
|---|
| 117 |
$function['rss:view:feed'][] = $CFG->dirroot . "mod/newsclient/lib/function_view_individual.php"; |
|---|
| 118 |
$function['rss:view:post'][] = $CFG->dirroot . "mod/newsclient/lib/function_view_post.php"; |
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
$function['rss:subscribed'][] = $CFG->dirroot . "mod/newsclient/lib/function_is_subscribed.php"; |
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
$function['rss:prune'][] = $CFG->dirroot . "mod/newsclient/lib/function_prune.php"; |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
listen_for_event("user","delete","newsclient_user_delete"); |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
//$CFG->widgets->edit['feed'] = "newsclient_widget_edit"; |
|---|
| 131 |
$CFG->widgets->list[] = array( |
|---|
| 132 |
'name' => __gettext("Feed widget"), |
|---|
| 133 |
'description' => __gettext("Displays the latest entries from an external feed of your choice."), |
|---|
| 134 |
'type' => "newsclient::feed" |
|---|
| 135 |
); |
|---|
| 136 |
|
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
function newsclient_widget_display($widget) { |
|---|
| 140 |
|
|---|
| 141 |
global $CFG; |
|---|
| 142 |
$body = ""; |
|---|
| 143 |
$title = ""; |
|---|
| 144 |
|
|---|
| 145 |
$feed_id = widget_get_data("feed_id",$widget->ident); |
|---|
| 146 |
$feed_posts = widget_get_data("feed_posts",$widget->ident); |
|---|
| 147 |
if (empty($feed_posts)) { |
|---|
| 148 |
$feed_posts = 1; |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
if (!empty($feed_id)) { |
|---|
| 152 |
|
|---|
| 153 |
if ($posts = get_records_sql("SELECT fp.*,f.name,f.siteurl,f.tagline FROM ".$CFG->prefix."feed_posts fp |
|---|
| 154 |
JOIN ".$CFG->prefix."feeds f ON f.ident = fp.feed |
|---|
| 155 |
WHERE f.ident = $feed_id ORDER BY fp.added DESC, fp.ident ASC limit $feed_posts")) { |
|---|
| 156 |
|
|---|
| 157 |
foreach($posts as $post) { |
|---|
| 158 |
$body .= "<h2><a href=\"" .$post->url . "\">". $post->title . "</a></h2>" . $post->body; |
|---|
| 159 |
} |
|---|
| 160 |
|
|---|
| 161 |
$title = $post->name; |
|---|
| 162 |
|
|---|
| 163 |
} else { |
|---|
| 164 |
|
|---|
| 165 |
$body .= "<p>" . __gettext("This feed is currently empty.") . "</p>"; |
|---|
| 166 |
|
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
} else { |
|---|
| 171 |
|
|---|
| 172 |
$body .= "<p>" . __gettext("This feed widget is undefined.") . "</p>"; |
|---|
| 173 |
|
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
return array('title'=>$title,'content'=>$body); |
|---|
| 177 |
|
|---|
| 178 |
} |
|---|
| 179 |
|
|---|
| 180 |
function newsclient_widget_edit($widget) { |
|---|
| 181 |
|
|---|
| 182 |
global $CFG, $page_owner; |
|---|
| 183 |
|
|---|
| 184 |
$feed_id = widget_get_data("feed_id",$widget->ident); |
|---|
| 185 |
$feed_posts = widget_get_data("feed_posts",$widget->ident); |
|---|
| 186 |
if (empty($feed_posts)) { |
|---|
| 187 |
$feed_posts = 1; |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
$body = "<h2>" . __gettext("Feeds widget") . "</h2>"; |
|---|
| 191 |
$body .= "<p>" . __gettext("This widget displays the last couple of entries from an external feed you have subscribed to. To begin, select the feed from your subscriptions below:") . "</p>"; |
|---|
| 192 |
|
|---|
| 193 |
$feed_subscriptions = newsclient_get_subscriptions_user($page_owner, true); |
|---|
| 194 |
|
|---|
| 195 |
if (is_array($feed_subscriptions) && !empty($feed_subscriptions)) { |
|---|
| 196 |
|
|---|
| 197 |
$body .= "<p><select name=\"widget_data[feed_id]\">\n"; |
|---|
| 198 |
foreach ($feed_subscriptions as $subscription) { |
|---|
| 199 |
if ($subscription->ident == $feed_id) { |
|---|
| 200 |
$selected = "selected=\"selected\""; |
|---|
| 201 |
} else { |
|---|
| 202 |
$selected = ""; |
|---|
| 203 |
} |
|---|
| 204 |
$body .= "<option value=\"" . $subscription->ident . "\" $selected>" . $subscription->name . "</option>\n"; |
|---|
| 205 |
} |
|---|
| 206 |
$body .= "</select></p>\n"; |
|---|
| 207 |
|
|---|
| 208 |
$body .= "<p>" . __gettext("Then enter the number of feed entries you'd like to display:") . "</p>"; |
|---|
| 209 |
|
|---|
| 210 |
$body .= "<p><input type=\"text\" name=\"widget_data[feed_posts]\" value=\"" . $feed_posts . "\" /></p>"; |
|---|
| 211 |
|
|---|
| 212 |
} else { |
|---|
| 213 |
|
|---|
| 214 |
$body .= "<p>" . sprintf(__gettext("You can't select a feed for this widget because you don't have any feed subscriptions. Click on <a href=\"%s\">Your</a> Resources to subscribe to a feed."),$CFG->wwwroot . $_SESSION['username'] . "/feeds/") . "</p>"; |
|---|
| 215 |
|
|---|
| 216 |
} |
|---|
| 217 |
|
|---|
| 218 |
return $body; |
|---|
| 219 |
|
|---|
| 220 |
} |
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
function newsclient_get_subscriptions_user($userid, $joined = false) { |
|---|
| 226 |
|
|---|
| 227 |
global $CFG; |
|---|
| 228 |
|
|---|
| 229 |
$userid = (int) $userid; |
|---|
| 230 |
if (empty($joined)) { |
|---|
| 231 |
|
|---|
| 232 |
$feed_subscriptions = get_records('feed_subscriptions', 'user_id', $userid); |
|---|
| 233 |
|
|---|
| 234 |
} else { |
|---|
| 235 |
|
|---|
| 236 |
$feed_subscriptions = get_records_sql('SELECT fs.ident AS subid, fs.autopost, fs.autopost_tag, f.* FROM '.$CFG->prefix.'feed_subscriptions fs |
|---|
| 237 |
JOIN '.$CFG->prefix.'feeds f ON f.ident = fs.feed_id |
|---|
| 238 |
WHERE fs.user_id = ? ORDER BY f.name ASC',array($userid)); |
|---|
| 239 |
|
|---|
| 240 |
} |
|---|
| 241 |
|
|---|
| 242 |
return $feed_subscriptions; |
|---|
| 243 |
} |
|---|
| 244 |
|
|---|
| 245 |
function newsclient_user_delete($object_type, $event, $object) { |
|---|
| 246 |
global $CFG, $data; |
|---|
| 247 |
if (!empty($object->ident) && $object_type == "user" && $event == "delete") { |
|---|
| 248 |
delete_records('feed_subscriptions','user_id',$object->ident); |
|---|
| 249 |
} |
|---|
| 250 |
return $object; |
|---|
| 251 |
} |
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
?> |
|---|
| 255 |
|
|---|