Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplefeed/README.txt,v
retrieving revision 1.18.2.24
diff -u -F^f -r1.18.2.24 README.txt
--- README.txt 26 Sep 2008 04:20:04 -0000 1.18.2.24
+++ README.txt 27 Sep 2008 00:37:03 -0000
@@ -48,6 +48,7 @@
- optional views support
- optional token support
- optionally verify feeds before adding to database
+- optional stats collecting module for per-feed stats and global stats on feed usage
Index: simplefeed.css
===================================================================
RCS file: simplefeed.css
diff -N simplefeed.css
--- simplefeed.css 3 Oct 2007 21:19:05 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,15 +0,0 @@
-/* $Id: simplefeed.css,v 1.3 2007/10/03 21:19:05 m3avrck Exp $ */
-ul.simplefeed, ul.simplefeed-item {
-margin:0;
-padding:0.3em;
-border:1px solid #ccc;
-background:#eee;
-}
-
-ul.simplefeed li, ul.simplefeed-item li {
-display: inline;
-list-style-type: none;
-background:none;
-margin:0;
-padding:0 2em 0 0;
-}
\ No newline at end of file
Index: simplefeed.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplefeed/simplefeed.module,v
retrieving revision 1.44.2.15
diff -u -F^f -r1.44.2.15 simplefeed.module
--- simplefeed.module 26 Sep 2008 04:10:40 -0000 1.44.2.15
+++ simplefeed.module 27 Sep 2008 00:37:04 -0000
@@ -43,25 +43,29 @@ function simplefeed_menu($may_cache) {
else {
if (arg(0) == 'node' && is_numeric(arg(1)) && user_access('administer feeds')) {
- $items[] = array(
- 'path' => 'node/'. arg(1) .'/refresh',
- 'title' => t('Refresh feed'),
- 'callback' => 'simplefeed_feed_refresh',
- 'callback arguments' => array(arg(1)),
- 'access' => user_access('administer feeds'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 2,
- );
-
- $items[] = array(
- 'path' => 'node/'. arg(1) . '/empty',
- 'title' => t('Empty feed'),
- 'callback' => 'simplefeed_feed_empty',
- 'callback arguments' => array(arg(1)),
- 'access' => user_access('administer feeds'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 3,
- );
+ // since you are viewing a node this is already cached
+ $node = node_load(arg(1));
+ if ($node->type == 'feed') {
+ $items[] = array(
+ 'path' => 'node/'. arg(1) .'/refresh',
+ 'title' => t('Refresh feed'),
+ 'callback' => 'simplefeed_feed_refresh',
+ 'callback arguments' => array(arg(1)),
+ 'access' => user_access('administer feeds'),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 2,
+ );
+
+ $items[] = array(
+ 'path' => 'node/'. arg(1) . '/empty',
+ 'title' => t('Empty feed'),
+ 'callback' => 'simplefeed_feed_empty',
+ 'callback arguments' => array(arg(1)),
+ 'access' => user_access('administer feeds'),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 3,
+ );
+ }
}
}
@@ -195,19 +199,19 @@ function simplefeed_validate($node) {
if ($duplicate != '' && $duplicate != $node->nid) {
form_set_error('url', t('The URL entered already exists. Please try a different URL.'));
}
-
+
if (variable_get('simplefeed_check_url', 1)) {
include_once './'. drupal_get_path('module', 'simplefeed') .'/simplepie.inc';
-
+
// init simplepie and have it see if it can find a feed
$feed = new SimplePie();
$feed->enable_cache(FALSE);
$feed->set_timeout(15);
-
+
// prevent SimplePie from using all of it's data santization since we use Drupal's input formats to handle this
$feed->set_stupidly_fast(TRUE);
$feed->set_feed_url($node->url);
-
+
// feed hasn't been added yet, so use a very low time setting
// FeedBurner requires this
header("If-Modified-Since:" . 1);
@@ -287,58 +291,6 @@ function simplefeed_nodeapi(&$node, $op,
/**
- * Implementation of hook_view().
- */
-function simplefeed_view($node, $teaser = FALSE, $page = FALSE) {
- $node = node_prepare($node, $teaser);
-
- $node->content['simplefeed']['#theme'] = 'simplefeed_node_view';
- $node->content['simplefeed']['#weight'] = 2;
- $node->content['simplefeed']['url'] = array(
- '#value' => check_url($node->url),
- '#weight' => 1,
- );
-
- // since only administrators can edit when a feed expires, only admins can see what this value is
- if (user_access('administer feeds')) {
- $node->content['simplefeed']['expires'] = array(
- '#value' => format_interval($node->expires),
- );
- $node->content['simplefeed']['refresh'] = array(
- '#value' => format_interval($node->refresh),
- );
- $node->content['simplefeed']['checked'] = array(
- '#value' => $node->checked > 0 ? format_interval(time() - $node->checked) . t(' ago') : t('Never'),
- );
- }
-
- return $node;
-}
-
-
-/**
- * Theme the display of a feed node.
- */
-function theme_simplefeed_node_view($values) {
- // needs to be a space so default values aren't outputed
- $output = ' ';
-
- // since only administrators can edit when a feed expires, only admins can see what this value is
- if (user_access('administer feeds')) {
- drupal_add_css(drupal_get_path('module', 'simplefeed') .'/simplefeed.css');
-
- $output .= '
';
- $output .= '- Expires: '. $values['expires']['#value'] .'
';
- $output .= '- Refresh: '. $values['refresh']['#value'] .'
';
- $output .= '- Checked: '. $values['checked']['#value'] .'
';
- $output .= '
';
- }
-
- return $output;
-}
-
-
-/**
* Implementation of hook_link().
*/
function simplefeed_link($type, $node = NULL, $teaser = FALSE) {
@@ -432,7 +384,7 @@ function simplefeed_admin_settings() {
'#options' => $throttle,
'#default_value' => variable_get('simplefeed_cron_throttle', 50),
);
-
+
$form['simplefeed_check_url'] = array(
'#type' => 'select',
'#title' => t('Verify feed before adding to database'),
@@ -562,6 +514,10 @@ function simplefeed_feed_process($nid) {
else if (isset($feed->error)) {
watchdog('simplefeed', t('The feed %feed could not be processed due to the following error: %error', array('%feed' => $process_feed->title, '%error' => $feed->error)), WATCHDOG_ERROR, l('view', 'node/'. $process_feed->nid));
db_query("UPDATE {simplefeed_feed} SET error = 1 WHERE vid = %d", $process_feed->vid);
+
+ if (module_exists('simplefeed_stats')) {
+ simplefeed_stats_feed_fail($process_feed, $feed->error);
+ }
}
else {
watchdog('simplefeed', 'You shouldn\'t be here. Something has gone terribly wrong.');
@@ -579,6 +535,11 @@ function simplefeed_feed_empty($nid) {
node_delete($node->nid);
}
db_query("UPDATE {simplefeed_feed} SET hash = NULL WHERE nid = %d", $nid);
+
+ if (module_exists('simplefeed_stats')) {
+ simplefeed_stats_feed_empty($nid);
+ }
+
drupal_set_message(t('Feed emptied.'));
drupal_goto('node/'. $nid);
}
Index: simplefeed_item.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplefeed/simplefeed_item.module,v
retrieving revision 1.51.2.15
diff -u -F^f -r1.51.2.15 simplefeed_item.module
--- simplefeed_item.module 2 Jul 2008 20:09:51 -0000 1.51.2.15
+++ simplefeed_item.module 27 Sep 2008 00:37:04 -0000
@@ -353,6 +353,7 @@ function simplefeed_item_feed_expire() {
function simplefeed_item_feed_parse($process_feed, $feed) {
// loop through all of the items in the feed, faster than foreach
$max = $feed->get_item_quantity();
+ $count = 0;
for ($i = 0; $i < $max; $i++) {
$item = $feed->get_item($i);
@@ -455,6 +456,7 @@ function simplefeed_item_feed_parse($pro
$values['fid'] = $process_feed->nid;
$values['taxonomy'] = $item->taxonomy;
+ $count++;
// create a new feed-item node, adding in all of the other node defaults
drupal_execute('feed_item_node_form', $values, $node);
}
@@ -462,4 +464,7 @@ function simplefeed_item_feed_parse($pro
// we unset $item each time to prevent any pass by reference memory leaks that PHP encounters with objects in foreach loops
unset($item);
}
+ if (module_exists('simplefeed_stats')) {
+ simplefeed_stats_updated_feed($count, $process_feed);
+ }
}
Index: simplefeed_stats.info
===================================================================
RCS file: simplefeed_stats.info
diff -N simplefeed_stats.info
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ simplefeed_stats.info 27 Sep 2008 00:37:04 -0000
@@ -0,0 +1,5 @@
+; $Id: $
+name = SimpleFeed Statistics
+description = Collects statistics about Simplefeed usage.
+package = SimpleFeed
+dependencies = simplefeed
Index: simplefeed_stats.install
===================================================================
RCS file: simplefeed_stats.install
diff -N simplefeed_stats.install
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ simplefeed_stats.install 27 Sep 2008 00:37:04 -0000
@@ -0,0 +1,40 @@
+ 'admin/content/simplefeed',
+ 'title' => t('Feeds'),
+ 'description' => t('View statistics about Simplefeed processing'),
+ 'callback' => 'simplefeed_stats_admin',
+ 'access' => user_access('administer feeds'),
+ );
+
+ return $items;
+ }
+ else {
+ if (arg(0) == 'node' && is_numeric(arg(1)) && (user_access('view simplefeed logs') || user_access('view own simplefeed logs'))) {
+ // since you are viewing a node this is already cached
+ $node = node_load(arg(1));
+ if ($node->type == 'feed') {
+ $items[] = array(
+ 'path' => 'node/'. arg(1) . '/log',
+ 'title' => t('Feed log'),
+ 'callback' => 'simplefeed_stats_log',
+ 'callback arguments' => array(arg(1)),
+ 'access' => user_access('view simplefeed logs') || user_access('view own simplefeed logs'),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 4
+ );
+ }
+ }
+ return $items;
+ }
+}
+
+function simplefeed_stats_perm() {
+ return array('view simplefeed logs', 'view own simplefeed logs');
+}
+
+/**
+ * Page callback for the status page of simplefeed
+ */
+function simplefeed_stats_admin() {
+ $header = array(
+ array(
+ 'data' => t('Title'),
+ 'sort' => 'ASC',
+ 'field' => 'title',
+ ),
+ array(
+ 'data' => t('Last Refresh'),
+ 'sort' => 'DESC',
+ 'field' => 'timestamp',
+ ),
+ array(
+ 'data' => t('Number of Posts'),
+ 'field' => 'number',
+ ),
+ array(
+ 'data' => t('Average Posts per Update'),
+ 'field' => 'average',
+ ),
+ t('Actions'),
+ );
+
+ $sql = "SELECT n.nid, n.title, s.timestamp, count(DISTINCT(i.vid)) as number, count(DISTINCT(i.vid)) / count(DISTINCT(s.sid)) as average FROM {node} n JOIN {simplefeed_feed_stats} s ON s.fid = n.nid LEFT JOIN {simplefeed_feed_item} i ON i.fid = s.fid GROUP BY s.fid";
+ $count_sql = "SELECT count(s.nid) FROM {simplefeed_feed} s";
+ $results = pager_query($sql . tablesort_sql($header), 15, 0, $count_sql);
+
+ while ($feed_array = db_fetch_array($results)) {
+ $nid = $feed_array['nid'];
+ unset($feed_array['nid']);
+
+ $actions_column = theme('item_list', array(
+ l('Empty', 'node/' . $nid . '/empty'),
+ l('Refresh', 'node/' . $nid . '/refresh'),
+ l('View Log', 'node/' . $nid . '/log'),
+ )
+ );
+
+ $feed_array['timestamp'] = format_date($feed_array['timestamp'], 'small');
+ $feed_array['title'] = l($feed_array['title'], 'node/' . $nid);
+ $feed_array['average'] = round($feed_array['average'], 2);
+ $feed_array['actions'] = $actions_column;
+ $rows[] = $feed_array;
+ }
+
+ if (count($rows) > 0) {
+ $output = theme('table', $header, $rows);
+ $output .= theme('pager', NULL, 15);
+ }
+ else {
+ $output .= t('Cron needs to run first to collect feed stats.');
+ }
+
+ return $output;
+}
+
+/**
+ * recieves the number of simplefeed_items created by a given feed
+ * and adds to the db table
+ *
+ * @param $count
+ * number of nodes created
+ *
+ * @param $feed_node
+ * the feed node
+ */
+function simplefeed_stats_updated_feed($count, $feed_node) {
+ // update the table add in the count msg et al to the table
+ // php5 use $_REQUEST['time'] instead of time()
+ // insert even if no nodes were added
+ db_query("INSERT INTO {simplefeed_feed_stats} (sid, fid, new_nodes, timestamp, msg) VALUES (%d, %d, %d, %d, '%s')", db_next_id('{simplefeed_sid}'), $feed_node->nid, $count, time(), 'Success');
+}
+
+/**
+ * Recieves the error msg when a feed fails and logs it
+ *
+ * @param $feed_node
+ * the feed node that failed
+ *
+ * @param error_msg
+ * error message recieve when it failed
+ */
+function simplefeed_stats_feed_fail($feed_node, $error_msg) {
+ db_query("INSERT INTO {simplefeed_feed_stats} (sid, fid, msg, timestamp) VALUES (%d, %d, '%s', %d)", db_next_id('{simplefeed_sid}'), $feed_node->nid, $error_msg, time());
+}
+
+/**
+ * Recieves a nid that was just emptied
+ *
+ * @param $fid
+ * fid that was just emptied
+ */
+function simplefeed_stats_feed_empty($fid) {
+ db_query("INSERT INTO {simplefeed_feed_stats} (sid, fid, msg, timestamp) VALUES (%d, %d, '%s', %d)", db_next_id('{simplefeed_sid}'), $fid, 'Feed was emptied', time());
+}
+
+/**
+ * Displays the log of the feed
+ *
+ * @param $nid
+ * nid of the feed node
+ */
+function simplefeed_stats_log($nid) {
+ drupal_set_title('Feed log');
+
+ // need a check to make sure the node is a feed ?
+ $header = array(
+ array(
+ 'data' => t('Date'),
+ 'field' => 'timestamp',
+ 'sort' => 'DESC',
+ ),
+ array(
+ 'data' => t('New Posts'),
+ 'field' => 'new_nodes',
+ ),
+ t('Message'),
+ );
+
+ $sql = "SELECT timestamp, new_nodes, msg FROM {simplefeed_feed_stats} WHERE fid = %d";
+ $count_sql = "SELECT COUNT(sid) FROM {simplefeed_feed_stats} WHERE fid = %d";
+ $log_result = pager_query($sql . tablesort_sql($header), 15, 0, $count_sql, $nid);
+ while ($log_object = db_fetch_object($log_result)) {
+ $rows[] = array(
+ date('n/j/Y g:i a', $log_object->timestamp),
+ $log_object->new_nodes,
+ t($log_object->msg),
+ );
+ }
+ return theme('table', $header, $rows) . theme('pager', NULL, 15);
+}