| 1 |
<?php
|
| 2 |
// $Id: simpleblogroll.module,v 1.1.2.4 2008/08/23 15:06:47 filiptc Exp $
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Module for displaying a dynamic, feed-driven blogroll.
|
| 6 |
* This module provides block displaying latest feed items
|
| 7 |
* from pre-set RSS/ATOM feeds with the help of simplepie parser.
|
| 8 |
* @see http://simplepie.org
|
| 9 |
*/
|
| 10 |
|
| 11 |
function _simpleblogroll_item_has_date($url) {
|
| 12 |
$feed = simplepie_get($url);
|
| 13 |
$item = $feed->get_item(0);
|
| 14 |
if ($item->get_date('U')) {
|
| 15 |
return TRUE;
|
| 16 |
}
|
| 17 |
return FALSE;
|
| 18 |
}
|
| 19 |
|
| 20 |
/**
|
| 21 |
* Check feed for validity
|
| 22 |
*
|
| 23 |
* This pushes the feed (by means of its url) through SimplePie
|
| 24 |
* and sees if an error is returned.
|
| 25 |
*
|
| 26 |
* @param $url
|
| 27 |
* URL to the feed.
|
| 28 |
* @return
|
| 29 |
* FALSE on error, TRUE when feed valid or empty.
|
| 30 |
* @see _simpleblogroll_get_error()
|
| 31 |
*/
|
| 32 |
function _simpleblogroll_valid_feed($url) {
|
| 33 |
if ($url != '') {
|
| 34 |
$feed = simplepie_get($url);
|
| 35 |
$item = $feed->get_item(0);
|
| 36 |
if (!$feed->error()) {
|
| 37 |
return TRUE;
|
| 38 |
}
|
| 39 |
return FALSE;
|
| 40 |
}
|
| 41 |
return TRUE;
|
| 42 |
}
|
| 43 |
|
| 44 |
/**
|
| 45 |
* Gets simplepie error
|
| 46 |
*
|
| 47 |
* Gives out the error returned by simplepie for a given URL.
|
| 48 |
*
|
| 49 |
* @param $url
|
| 50 |
* URL to the feed.
|
| 51 |
* @return
|
| 52 |
* A string with the error SimplePie gave.
|
| 53 |
* @see _simpleblogroll_valid_feed()
|
| 54 |
*/
|
| 55 |
function _simpleblogroll_get_error($url) {
|
| 56 |
$feed = simplepie_get($url);
|
| 57 |
$item = $feed->get_item(0);
|
| 58 |
return $feed->error();
|
| 59 |
}
|
| 60 |
|
| 61 |
/**
|
| 62 |
* Builds watchdog queries
|
| 63 |
*
|
| 64 |
* Depending on the level of notification set, sends notifications .
|
| 65 |
*
|
| 66 |
* @param $op
|
| 67 |
* Holds information about the operation we want to execute:
|
| 68 |
* - Possible values are 'noupdates', 'nocron', 'created', 'deleted' and 'updated'.
|
| 69 |
* @param $title
|
| 70 |
* Title of a feed.
|
| 71 |
* @param $item
|
| 72 |
* Title of an item.
|
| 73 |
* @param $feedurl
|
| 74 |
* URL of a feed.
|
| 75 |
*/
|
| 76 |
function _simpleblogroll_watchdog_informing($op, $title = '', $item = '', $feedurl = '') {
|
| 77 |
switch (variable_get('simpleblogroll_info', 'operations')) {
|
| 78 |
case 'all':
|
| 79 |
if ($op == 'noupdates') {
|
| 80 |
$msg = 'Feed "%title" checked. No update necessary: last item still "%item".';
|
| 81 |
$vars = array('%title' => $title, '%item' => $item);
|
| 82 |
watchdog('simpleblogroll', $msg, $vars, WATCHDOG_NOTICE);
|
| 83 |
}
|
| 84 |
if ($op == 'nocronyet') {
|
| 85 |
$remaining = variable_get('simpleblogroll_cron_runs', '1') - variable_get('simpleblogroll_cron_run', '0');
|
| 86 |
$msg = 'Updates will not be checked on this cron run. '. format_plural($remaining, 'There is 1 run remaining until next check.', 'There are @count runs remaining until next check.');
|
| 87 |
$vars = array();
|
| 88 |
watchdog('simpleblogroll', $msg, $vars, WATCHDOG_NOTICE);
|
| 89 |
}
|
| 90 |
if ($op == 'nocron') {
|
| 91 |
$msg = 'Updates will not be checked through cron. You can check for updates manually through the %url page. If you would like to change this behavior, you can do so changing the update in the '. l(t('SimpleBlogroll settings'), 'admin/settings/simpleblogroll') .' page.';
|
| 92 |
$vars = array();
|
| 93 |
watchdog('simpleblogroll', $msg, $vars, WATCHDOG_NOTICE);
|
| 94 |
}
|
| 95 |
case 'operations':
|
| 96 |
if ($op == 'created' && _simpleblogroll_valid_feed($feed_url)) {
|
| 97 |
if (!_simpleblogroll_item_has_date($feedurl)) {
|
| 98 |
$msg = 'Feed "%title" has been created. Latest item: "%item". Item contains no valid date information. Date will be set to now (%date).';
|
| 99 |
$vars = array('%title' => $title, '%item' => $item, '%date' => format_date(time()));
|
| 100 |
}
|
| 101 |
else {
|
| 102 |
$msg = 'Feed "%title" has been created. Latest item: "%item".';
|
| 103 |
$vars = array('%title' => $title, '%item' => $item);
|
| 104 |
}
|
| 105 |
watchdog('simpleblogroll', $msg, $vars, WATCHDOG_NOTICE);
|
| 106 |
}
|
| 107 |
if ($op == 'deleted') {
|
| 108 |
$msg = 'Feed with URL "%url"';
|
| 109 |
$vars = array('%url' => $feedurl);
|
| 110 |
watchdog('simpleblogroll', $msg, $vars, WATCHDOG_NOTICE);
|
| 111 |
}
|
| 112 |
case 'updates':
|
| 113 |
if ($op == 'updated' && _simpleblogroll_valid_feed($feedurl)) {
|
| 114 |
if (!_simpleblogroll_item_has_date($feedurl)) {
|
| 115 |
$msg = 'Feed "%title" has been updated. Latest item: "%item". Item contains no valid date information. Date will be set to now (%date).';
|
| 116 |
$vars = array('%title' => $title, '%item' => $item, '%date' => format_date(time()));
|
| 117 |
}
|
| 118 |
else {
|
| 119 |
$msg = 'Feed "%title" has been updated. Latest item: "%item".';
|
| 120 |
$vars = array('%title' => $title, '%item' => $item);
|
| 121 |
}
|
| 122 |
watchdog('simpleblogroll', $msg, $vars, WATCHDOG_NOTICE);
|
| 123 |
}
|
| 124 |
case 'none':
|
| 125 |
break;
|
| 126 |
}
|
| 127 |
}
|
| 128 |
|
| 129 |
/**
|
| 130 |
* Parses a feed
|
| 131 |
*
|
| 132 |
* Fetches all the feed data through simplepie for a given feed-URL.
|
| 133 |
*
|
| 134 |
* @param $feedurl
|
| 135 |
* URL to the feed.
|
| 136 |
* @return
|
| 137 |
* An array with the following keys:
|
| 138 |
* - 'title': contains the feed title.
|
| 139 |
* - 'site': contains the site url that holds the content reffered to by the feed.
|
| 140 |
* - 'item': contains the item title.
|
| 141 |
* - 'date': contains the item date.
|
| 142 |
* - 'url': contains the item url.
|
| 143 |
*/
|
| 144 |
function _simpleblogroll_parse_feed($feedurl) {
|
| 145 |
$feed = simplepie_get($feedurl);
|
| 146 |
$item = $feed->get_item(0);
|
| 147 |
$site_url = check_url($feed->get_link());
|
| 148 |
$item_url = check_url($item->get_link());
|
| 149 |
$item_title = decode_entities(check_plain($item->get_title()));
|
| 150 |
$feed_title = decode_entities(check_plain($feed->get_title()));
|
| 151 |
if (!$feed_date = $item->get_date('U')) {
|
| 152 |
$feed_date = time();
|
| 153 |
}
|
| 154 |
return array('title' => $feed_title, 'site' => $site_url, 'item' => $item_title, 'date' => $feed_date, 'url' => $item_url);
|
| 155 |
}
|
| 156 |
|
| 157 |
/**
|
| 158 |
* Makes database modifications
|
| 159 |
*
|
| 160 |
* Performs database modifications depending on the operation and the feed url.
|
| 161 |
*
|
| 162 |
* @param $op
|
| 163 |
* Information on the operation to perform:
|
| 164 |
* - Can be: 'delete', 'create', 'update' or 'empty',
|
| 165 |
* @param $feedurl
|
| 166 |
* URL to the feed.
|
| 167 |
*/
|
| 168 |
function _simpleblogroll_modify_db($op, $feedurl = '') {
|
| 169 |
if (_simpleblogroll_valid_feed($feedurl) || $op == 'empty') {
|
| 170 |
if ($feedurl != '') {
|
| 171 |
$feed = _simpleblogroll_parse_feed($feedurl);
|
| 172 |
$title = $feed['title'];
|
| 173 |
$siteurl = $feed['site'];
|
| 174 |
$item = $feed['item'];
|
| 175 |
$itemurl = $feed['url'];
|
| 176 |
$date = $feed['date'];
|
| 177 |
}
|
| 178 |
switch ($op) {
|
| 179 |
case 'create':
|
| 180 |
db_query('INSERT INTO {simpleblogroll} '
|
| 181 |
.'(site_url, feed_title, feed_url, last_item, item_url, timestamp) '
|
| 182 |
."VALUES ('%s', '%s', '%s', '%s', '%s', %d) ",
|
| 183 |
$siteurl,
|
| 184 |
$title,
|
| 185 |
$feedurl,
|
| 186 |
$item,
|
| 187 |
$itemurl,
|
| 188 |
$date
|
| 189 |
);
|
| 190 |
_simpleblogroll_watchdog_informing('created', $title, $item, $feedurl);
|
| 191 |
break;
|
| 192 |
case 'delete':
|
| 193 |
db_query('DELETE FROM {simpleblogroll} '
|
| 194 |
."WHERE feed_url='%s'",
|
| 195 |
$feedurl
|
| 196 |
);
|
| 197 |
_simpleblogroll_watchdog_informing('deleted', $title, $item, $feedurl);
|
| 198 |
break;
|
| 199 |
case 'update':
|
| 200 |
$query_check_for_item = db_query('SELECT feed_title, last_item '
|
| 201 |
.'FROM {simpleblogroll} '
|
| 202 |
."WHERE last_item = '%s'",
|
| 203 |
$item
|
| 204 |
);
|
| 205 |
if (!db_fetch_array($query_check_for_item)) {
|
| 206 |
db_query('DELETE FROM {simpleblogroll} '
|
| 207 |
."WHERE feed_url='%s' "
|
| 208 |
.'ORDER BY timestamp ASC '
|
| 209 |
.'LIMIT 1',
|
| 210 |
$feedurl
|
| 211 |
);
|
| 212 |
db_query('INSERT INTO {simpleblogroll} '
|
| 213 |
.'(site_url, feed_title, feed_url, last_item, item_url, timestamp) '
|
| 214 |
."VALUES ('%s', '%s', '%s', '%s', '%s', %d) ",
|
| 215 |
$siteurl,
|
| 216 |
$title,
|
| 217 |
$feedurl,
|
| 218 |
$item,
|
| 219 |
$itemurl,
|
| 220 |
$date
|
| 221 |
);
|
| 222 |
_simpleblogroll_watchdog_informing('updated', $title, $item, $feedurl);
|
| 223 |
}
|
| 224 |
else {
|
| 225 |
_simpleblogroll_watchdog_informing('noupdates', $title, $item, $feedurl);
|
| 226 |
}
|
| 227 |
break;
|
| 228 |
case 'empty':
|
| 229 |
db_query('TRUNCATE TABLE {simpleblogroll}');
|
| 230 |
break;
|
| 231 |
}
|
| 232 |
}
|
| 233 |
}
|
| 234 |
|
| 235 |
/**
|
| 236 |
* Sets feeds
|
| 237 |
*
|
| 238 |
* Converts introduced feed URLs (one per line) into an array. If empty, returns empty array.
|
| 239 |
*
|
| 240 |
* @return
|
| 241 |
* An array with all feed URLs. If none set, empty.
|
| 242 |
*/
|
| 243 |
function _simpleblogroll_set_feeds() {
|
| 244 |
$d = variable_get('simpleblogroll_feeds', '');
|
| 245 |
if ($d != '') {
|
| 246 |
$d = ereg_replace("(\n|\r|\r\n)", "|", $d);
|
| 247 |
$d = explode("|", $d);
|
| 248 |
foreach ($d as $url) {
|
| 249 |
check_url($url);
|
| 250 |
$arr[]=$url;
|
| 251 |
}
|
| 252 |
return $arr;
|
| 253 |
}
|
| 254 |
else {
|
| 255 |
return array();
|
| 256 |
}
|
| 257 |
}
|
| 258 |
|
| 259 |
/**
|
| 260 |
* Counts feeds.
|
| 261 |
*
|
| 262 |
* Counts set feeds and corrects the feeds set to display if set higher than number of feeds.
|
| 263 |
*
|
| 264 |
* @return
|
| 265 |
* A number describing the total number of feeds. If none is set yet, return 5.
|
| 266 |
* @see _simpleblogroll_set_feeds()
|
| 267 |
*/
|
| 268 |
function _simpleblogroll_count_set_feeds() {
|
| 269 |
$number = count(_simpleblogroll_set_feeds());
|
| 270 |
if ($number == 0) {
|
| 271 |
$number = 5;
|
| 272 |
}
|
| 273 |
if (variable_get('simpleblogroll_display', '5') >= $number) {
|
| 274 |
variable_set('simpleblogroll_display', $number);
|
| 275 |
}
|
| 276 |
return $number;
|
| 277 |
}
|
| 278 |
|
| 279 |
/**
|
| 280 |
* Checks current feeds
|
| 281 |
*
|
| 282 |
* Checks the existing feeds in database and returns their URL in a unique array. If empty, returns empty array.
|
| 283 |
*
|
| 284 |
* @return
|
| 285 |
* An array with all feed URLs. If none set, empty.
|
| 286 |
*/
|
| 287 |
function _simpleblogroll_get_current_feeds() {
|
| 288 |
$query_check = db_query('SELECT feed_url '
|
| 289 |
.'FROM {simpleblogroll}'
|
| 290 |
);
|
| 291 |
while ($result_array = db_fetch_array($query_check)) {
|
| 292 |
$arr[] = $result_array['feed_url'];
|
| 293 |
}
|
| 294 |
if ($arr) {
|
| 295 |
return array_unique($arr);
|
| 296 |
}
|
| 297 |
else {
|
| 298 |
return array();
|
| 299 |
}
|
| 300 |
}
|
| 301 |
|
| 302 |
/**
|
| 303 |
* Checks for feed updates
|
| 304 |
*
|
| 305 |
* Goes through all the set URLs and performs an update check and operation when necessary.
|
| 306 |
*
|
| 307 |
* @return
|
| 308 |
* An array with all feed URLs. If none set, empty.
|
| 309 |
* @see _simpleblogroll_modify_db()
|
| 310 |
*/
|
| 311 |
function _simpleblogroll_check_for_update() {
|
| 312 |
foreach (_simpleblogroll_set_feeds() as $feed_url) {
|
| 313 |
_simpleblogroll_modify_db('update', $feed_url);
|
| 314 |
}
|
| 315 |
}
|
| 316 |
|
| 317 |
/**
|
| 318 |
* Perform a series of start checks
|
| 319 |
*
|
| 320 |
* Checks what operations are necessary after hitting submit on the simpleblogroll module settings page.
|
| 321 |
* If no feed has been changed (no diff between feeds in database and set feeds) exits.
|
| 322 |
* If there are changes, updates the database (either by creating or deleting items).
|
| 323 |
* On each execution, checks if any URLs are invalid.
|
| 324 |
* Reports all operations and warnings to user.
|
| 325 |
*
|
| 326 |
*/
|
| 327 |
function _simpleblogroll_startchecks() {
|
| 328 |
$setfeeds = _simpleblogroll_set_feeds();
|
| 329 |
$currentfeeds = _simpleblogroll_get_current_feeds();
|
| 330 |
if ($setfeeds) {
|
| 331 |
foreach ($setfeeds as $key => $feed_url) {
|
| 332 |
if (!valid_url($feed_url, TRUE)) {
|
| 333 |
form_set_error('simpleblogroll_feeds', t('The URL %url is invalid. Please enter a fully-qualified URL, such as http://www.example.com/feed.xml.', array('%url' => $feed_url)));
|
| 334 |
}
|
| 335 |
elseif (!_simpleblogroll_valid_feed($feed_url)) {
|
| 336 |
$error = _simpleblogroll_get_error($url);
|
| 337 |
$message .= '<li>'. t('The URL %url is not a valid feed and was removed. <br />SimplePie returned: %error', array(
|
| 338 |
'%url' => $feed_url,
|
| 339 |
'%error' => $error
|
| 340 |
)) .'</li>';
|
| 341 |
$counter++;
|
| 342 |
unset($setfeeds[$key]);
|
| 343 |
}
|
| 344 |
}
|
| 345 |
if ($error) {
|
| 346 |
form_set_error('simpleblogroll_feeds', '<ul>'. $message .'</ul>'. format_plural($counter, 'If the URL links to an ATOM/RSS feed and was tiped correctly, there might be a problem with its XML syntax. Contacting the owner of the feed might resolve the issue.', 'If the URLs link to ATOM/RSS feeds and were tiped correctly, there might be a problem with their XML syntax. Contacting the owners of the feeds might resolve the issues.'));
|
| 347 |
$feeds = implode("\n", $setfeeds);
|
| 348 |
variable_set('simpleblogroll_feeds', $feeds);
|
| 349 |
$setfeeds = _simpleblogroll_set_feeds();
|
| 350 |
}
|
| 351 |
}
|
| 352 |
if (!$setfeeds && !$currentfeeds) {
|
| 353 |
return;
|
| 354 |
}
|
| 355 |
elseif ($setfeeds && $currentfeeds) {
|
| 356 |
$todelete = array_diff($currentfeeds, $setfeeds);
|
| 357 |
if ($todelete) {
|
| 358 |
$i = 0;
|
| 359 |
foreach ($todelete as $feed_url) {
|
| 360 |
_simpleblogroll_modify_db('delete', $feed_url);
|
| 361 |
$i++;
|
| 362 |
}
|
| 363 |
drupal_set_message(format_plural($i, '1 feed has been deleted.', '@count feeds have been deleted'));
|
| 364 |
}
|
| 365 |
|
| 366 |
$toadd = array_diff($setfeeds, $currentfeeds);
|
| 367 |
if ($toadd) {
|
| 368 |
$i = 0;
|
| 369 |
foreach ($toadd as $feed_url) {
|
| 370 |
_simpleblogroll_modify_db('create', $feed_url);
|
| 371 |
if (_simpleblogroll_valid_feed($feed_url)) {
|
| 372 |
if (!_simpleblogroll_item_has_date($feed_url)) {
|
| 373 |
drupal_set_message(t('The URL %url does not contain items with a valid date. Since parser cannot read it, it will set it to now (%date). This should not become a problem if you update on a regular basis (dates will still be approximate, but more accurate the higher the update frequency).', array('%url' => $feed_url, '%date' => format_date(time()))), 'warning');
|
| 374 |
}
|
| 375 |
}
|
| 376 |
$i++;
|
| 377 |
}
|
| 378 |
drupal_set_message(format_plural($i, '1 feed has been added.', '@count feeds have been added'));
|
| 379 |
}
|
| 380 |
}
|
| 381 |
elseif ($currentfeeds) {
|
| 382 |
_simpleblogroll_modify_db('empty');
|
| 383 |
drupal_set_message(t('All feeds have been removed.'));
|
| 384 |
}
|
| 385 |
elseif ($setfeeds) {
|
| 386 |
$i = 0;
|
| 387 |
foreach ($setfeeds as $feed_url) {
|
| 388 |
_simpleblogroll_modify_db('create', $feed_url);
|
| 389 |
if (!_simpleblogroll_item_has_date($feed_url) && _simpleblogroll_valid_feed($feed_url)) {
|
| 390 |
drupal_set_message(t('The URL %url does not contain items with a valid date. Since parser cannot read it, it will set it to now (%date). This should not become a problem if you update on a regular basis (dates will still be approximate, but more accurate the higher the update frequency).', array('%url' => $feed_url, '%date' => format_date(time()))), 'warning');
|
| 391 |
}
|
| 392 |
$i++;
|
| 393 |
}
|
| 394 |
drupal_set_message(format_plural($i, '1 feed has been added.', '@count feeds have been added'));
|
| 395 |
}
|
| 396 |
}
|
| 397 |
|
| 398 |
/**
|
| 399 |
* FAPI definition for the SimpleBlogroll admin page.
|
| 400 |
*/
|
| 401 |
function _simpleblogroll_admin_settings() {
|
| 402 |
if (variable_get('simpleblogroll_on_submit', '0') == '1') {
|
| 403 |
_simpleblogroll_startchecks();
|
| 404 |
variable_set('simpleblogroll_on_submit', '0');
|
| 405 |
}
|
| 406 |
if (variable_get('simpleblogroll_parse', '0') == 1) {
|
| 407 |
_simpleblogroll_check_for_update();
|
| 408 |
drupal_set_message(t('All feeds have been checked for updates. If you set watchdog configuration accordingly, you can check results under ') . l(t('recent log entries'), 'admin/reports/dblog'));
|
| 409 |
variable_set('simpleblogroll_parse', '0');
|
| 410 |
}
|
| 411 |
$form['simpleblogroll_on_submit'] = array(
|
| 412 |
'#type' => 'hidden',
|
| 413 |
'#default_value' => '0',
|
| 414 |
'#value' => '1',
|
| 415 |
);
|
| 416 |
$form['simpleblogroll_feeds'] = array(
|
| 417 |
'#type' => 'textarea',
|
| 418 |
'#title' => t('Feed URLs'),
|
| 419 |
'#description' => t('Enter URL of feeds to parse. One per line.'),
|
| 420 |
'#default_value' => variable_get('simpleblogroll_feeds', ''),
|
| 421 |
);
|
| 422 |
$form['simpleblogroll_display'] = array(
|
| 423 |
'#type' => 'textfield',
|
| 424 |
'#title' => t('Number of feeds to display'),
|
| 425 |
'#description' => t('If set to less than the total number of feeds, oldest feeds will not be displayed.<br />If set to more than the total number of feeds, it will automatically be lowered to the total number of feeds and all feeds will be displayed.'),
|
| 426 |
'#default_value' => variable_get('simpleblogroll_display', _simpleblogroll_count_set_feeds()),
|
| 427 |
'#size' => 2,
|
| 428 |
'#maxlength' => 2,
|
| 429 |
'#required' => TRUE,
|
| 430 |
);
|
| 431 |
$form['display_time_new'] = array(
|
| 432 |
'#type' => 'textfield',
|
| 433 |
'#title' => t('Persistence of "(new)" tag since update'),
|
| 434 |
'#description' => t('Set the time in hours to display the "(new)" tags next to updated items from their updated time. No decimals. Set 0 to not display the tag.'),
|
| 435 |
'#default_value' => variable_get('display_time_new', '24'),
|
| 436 |
'#size' => 3,
|
| 437 |
'#maxlength' => 3,
|
| 438 |
'#required' => TRUE,
|
| 439 |
);
|
| 440 |
$form['display_links'] = array(
|
| 441 |
'#type' => 'select',
|
| 442 |
'#title' => t('Link to site'),
|
| 443 |
'#description' => t('Choose if you want to display a link to the feed\'s site.'),
|
| 444 |
'#default_value' => variable_get('display_links', 'none'),
|
| 445 |
'#options' => array(
|
| 446 |
'iconleft' => 'Show clickable icon to the left of feed title',
|
| 447 |
'iconright' => 'Show clickable icon to the right of feed title',
|
| 448 |
'link' => 'Make the title a link',
|
| 449 |
'none' => 'Don\'t show link to the linked feed\'s site',
|
| 450 |
),
|
| 451 |
);
|
| 452 |
$form['simpleblogroll_info'] = array(
|
| 453 |
'#type' => 'select',
|
| 454 |
'#title' => t('Watchdog'),
|
| 455 |
'#description' => t('Set the amount of info you want to display in watchdog'),
|
| 456 |
'#default_value' => variable_get('simpleblogroll_info', 'operations'),
|
| 457 |
'#options' => array(
|
| 458 |
'all' => 'Inform about everything',
|
| 459 |
'operations' => 'Inform about all feed operations (except checking)',
|
| 460 |
'updates' => 'Inform about feed updates only',
|
| 461 |
'none' => 'Don\'t use watchdog',
|
| 462 |
),
|
| 463 |
);
|
| 464 |
$form['simpleblogroll_cron_runs'] = array(
|
| 465 |
'#type' => 'select',
|
| 466 |
'#title' => t('Check for feed updates...'),
|
| 467 |
'#default_value' => variable_get('simpleblogroll_cron_runs', '1'),
|
| 468 |
'#options' => array(
|
| 469 |
'1' => t('on every Cron run'),
|
| 470 |
'2' => t('every 2 Cron runs'),
|
| 471 |
'3' => t('every 3 Cron runs'),
|
| 472 |
'4' => t('every 4 Cron runs'),
|
| 473 |
'5' => t('every 5 Cron runs'),
|
| 474 |
'10' => t('every 10 Cron runs'),
|
| 475 |
'20' => t('every 20 Cron runs'),
|
| 476 |
'-1' => t('never (Manual only)'),
|
| 477 |
),
|
| 478 |
'#description' => t('Set how often you want to check for feed updates.'),
|
| 479 |
);
|
| 480 |
$form['simpleblogroll_parse'] = array(
|
| 481 |
'#type' => 'checkbox',
|
| 482 |
'#title' => t('Check for updates now?'),
|
| 483 |
'#description' => t('Check in order to update feeds on submitting (<b>not necessary for just added <em>Feed URLs</em></b>). This is the way to update if you set update frequency to "Manual".'),
|
| 484 |
'#default_value' => variable_get('simpleblogroll_parse', '0'),
|
| 485 |
'#return_value' => 1,
|
| 486 |
);
|
| 487 |
return system_settings_form($form);
|
| 488 |
}
|
| 489 |
|
| 490 |
/**
|
| 491 |
* Builds block content
|
| 492 |
*
|
| 493 |
* Fetches all the feed data and returns it in an HTML friendly format.
|
| 494 |
*
|
| 495 |
* @return
|
| 496 |
* A string with the content of the block
|
| 497 |
*/
|
| 498 |
function _simpleblogroll_build_block() {
|
| 499 |
$result = db_query(' SELECT * '
|
| 500 |
.'FROM {simpleblogroll} '
|
| 501 |
.'ORDER BY timestamp DESC '
|
| 502 |
.'LIMIT %d',
|
| 503 |
variable_get('simpleblogroll_display', _simpleblogroll_count_set_feeds())
|
| 504 |
);
|
| 505 |
|
| 506 |
while ($row = db_fetch_array($result)) {
|
| 507 |
$return .= '<b>';
|
| 508 |
$linkimagepath = drupal_get_path('module', 'simpleblogroll') .'/images/external.png';
|
| 509 |
switch (variable_get('display_links', 'none')) {
|
| 510 |
case 'iconleft':
|
| 511 |
$return .= l(theme_image($linkimagepath, '>', $row['site_url']), $row['site_url'], array('html' => TRUE));
|
| 512 |
$return .= ' '. $row['feed_title'] .'</b><br />';
|
| 513 |
break;
|
| 514 |
case 'iconright':
|
| 515 |
$return .= $row['feed_title'] .'</b> ';
|
| 516 |
$return .= l(theme_image($linkimagepath, '>', $row['site_url']), $row['site_url'], array('html' => TRUE)) .'<br>';
|
| 517 |
break;
|
| 518 |
case 'link':
|
| 519 |
$return .= l($row['feed_title'], $row['site_url']) .'</b><br />';
|
| 520 |
break;
|
| 521 |
case 'none':
|
| 522 |
$return .= $row['feed_title'] .'</b><br />';
|
| 523 |
break;
|
| 524 |
}
|
| 525 |
$return .= l($row['last_item'], $row['item_url']);
|
| 526 |
if ($row['timestamp'] > (time() - 60 * 60 * variable_get('display_time_new', '24'))) {
|
| 527 |
$return .= ' <small>('. t('new') .')</small>';
|
| 528 |
}
|
| 529 |
$return .= '<br /><br />';
|
| 530 |
}
|
| 531 |
return $return;
|
| 532 |
}
|
| 533 |
|
| 534 |
/**
|
| 535 |
* Implementation of hook_perm().
|
| 536 |
*/
|
| 537 |
function simpleblogroll_perm() {
|
| 538 |
return array('access simpleblogroll', 'administer simpleblogroll');
|
| 539 |
}
|
| 540 |
|
| 541 |
/**
|
| 542 |
* Implementation of hook_block().
|
| 543 |
*/
|
| 544 |
function simpleblogroll_block($op = 'list', $delta = 0, $edit = array()) {
|
| 545 |
switch ($op) {
|
| 546 |
case 'list':
|
| 547 |
$blocks[0]['info'] = t('SimpleBlogroll');
|
| 548 |
$blocks[0]['cache'] = 'BLOCK_NO_CACHE';
|
| 549 |
$blocks[0]['status'] = TRUE;
|
| 550 |
return $blocks;
|
| 551 |
case 'view':
|
| 552 |
if (user_access('access simpleblogroll')) {
|
| 553 |
$blocks['subject'] = t('Blogroll');
|
| 554 |
$blocks['content'] = _simpleblogroll_build_block();
|
| 555 |
return $blocks;
|
| 556 |
}
|
| 557 |
}
|
| 558 |
}
|
| 559 |
|
| 560 |
/**
|
| 561 |
* Implementation of hook_help().
|
| 562 |
*/
|
| 563 |
function simpleblogroll_help($section) {
|
| 564 |
switch ($section) {
|
| 565 |
case 'admin/help#simpleblogroll':
|
| 566 |
return '<p>'. t('Thank you for using SimpleBlogroll! Before you start, make sure the Simplepie module is installed, cache is set (on its !simplepie) and it does not return any errors.<br /><br />Go to the !module, enter the URLs of the feeds you want to display in your dynamic blogroll, choose the number of feeds you want to display in the block and if you want to add a link to the feed\'s site. If you want, set the watchdog activity and frequency of update checks. If you were to select a manual update, you have the option to update feeds checking the "Check for updates now" checkbox before submitting.<br />Whern done, you have to set !permissions. If you don\'t want it to be visible to all roles, check only those which you want to give access.<br /><br />Please report any bugs through the issue queue on the project page!', array(
|
| 567 |
'!module' => l(t('SimpleBlogroll configuarion page'), 'admin/settings/simpleblogroll'),
|
| 568 |
'!simplepie' => l(t('configuaration page'), 'admin/settings/simplepie'),
|
| 569 |
'!permissions' => l(t("SimpleBlogroll's permissions"), 'admin/user/permissions', array('fragment' => 'module-simpleblogroll'))
|
| 570 |
)) .'</p>';
|
| 571 |
case 'admin/settings/simpleblogroll':
|
| 572 |
return '<p>'. t('Configure SimpleBlogroll.') .'</p>';
|
| 573 |
}
|
| 574 |
}
|
| 575 |
|
| 576 |
/**
|
| 577 |
* Implementation of hook_menu().
|
| 578 |
*/
|
| 579 |
function simpleblogroll_menu() {
|
| 580 |
$items['admin/settings/simpleblogroll'] = array(
|
| 581 |
'title' => 'SimpleBlogroll settings',
|
| 582 |
'description' => 'Control how simpleblogroll works.',
|
| 583 |
'page callback' => 'drupal_get_form',
|
| 584 |
'page arguments' => array('_simpleblogroll_admin_settings'),
|
| 585 |
'access arguments' => array('administer simpleblogroll'),
|
| 586 |
);
|
| 587 |
return $items;
|
| 588 |
}
|
| 589 |
|
| 590 |
/**
|
| 591 |
* Implementation of hook_cron().
|
| 592 |
*/
|
| 593 |
function simpleblogroll_cron() {
|
| 594 |
$cron_runs = variable_get('simpleblogroll_cron_run', '0');
|
| 595 |
$cron_runs++;
|
| 596 |
if ($cron_runs == (int) variable_get('simpleblogroll_cron_runs', '1')) {
|
| 597 |
variable_set('simpleblogroll_cron_run', '0');
|
| 598 |
_simpleblogroll_check_for_update();
|
| 599 |
}
|
| 600 |
elseif ($cron_runs > (int) variable_get('simpleblogroll_cron_runs', '1')) {
|
| 601 |
_simpleblogroll_watchdog_informing('nocron');
|
| 602 |
variable_del('simpleblogroll_cron_run');
|
| 603 |
}
|
| 604 |
else {
|
| 605 |
variable_set('simpleblogroll_cron_run', $cron_runs);
|
| 606 |
_simpleblogroll_watchdog_informing('nocronyet');
|
| 607 |
}
|
| 608 |
}
|