summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJochen Stals2008-11-09 13:05:43 (GMT)
committer Jochen Stals2008-11-09 13:05:43 (GMT)
commitbeb7118044780b69bb04d138e4c4604d6bb44999 (patch)
tree4b715409324609ecc498884c3273fe3abb5d079a
Project Heartbeat releases with development version. The idea is to provide information first on drupal.org.
-rw-r--r--heartbeat.admin.inc19
-rw-r--r--heartbeat.info11
-rw-r--r--heartbeat.install32
-rw-r--r--heartbeat.module138
-rw-r--r--user_activity/modules/friendlist_activity/friendlist_activity.info9
-rw-r--r--user_activity/modules/friendlist_activity/friendlist_activity.module15
-rw-r--r--user_activity/modules/friendlist_activity/friendlist_activity.rules.inc91
-rw-r--r--user_activity/modules/friendlist_activity/friendlist_activity.rules_defaults.inc164
-rw-r--r--user_activity/user_activity.admin.inc31
-rw-r--r--user_activity/user_activity.info8
-rw-r--r--user_activity/user_activity.install110
-rw-r--r--user_activity/user_activity.module41
-rw-r--r--user_activity/user_activity.rules.inc176
-rw-r--r--user_activity/user_activity.rules_defaults.inc116
-rw-r--r--user_activity/user_activity.views.inc109
-rw-r--r--user_activity_views/user_activity_views.info9
16 files changed, 1079 insertions, 0 deletions
diff --git a/heartbeat.admin.inc b/heartbeat.admin.inc
new file mode 100644
index 0000000..c32119c
--- /dev/null
+++ b/heartbeat.admin.inc
@@ -0,0 +1,19 @@
+<?php
+// $Id$
+// by Jochen Stals - ONE-agency - www.one-agency.be
+
+
+/**
+ * Function to maintain and administer heartbeat settings
+ *
+ * @return settingsform
+ */
+function heartbeat_admin_settings() {
+ $form['heatbeat_enabled'] = array(
+ '#title' => t('Do you want to enable the heatbeat?'),
+ '#type' => 'checkbox',
+ '#size' => 5,
+ '#default_value' => variable_get('heatbeat_enabled',1)
+ );
+ return system_settings_form($form);
+} \ No newline at end of file
diff --git a/heartbeat.info b/heartbeat.info
new file mode 100644
index 0000000..502d634
--- /dev/null
+++ b/heartbeat.info
@@ -0,0 +1,11 @@
+; $Id: heartbeat.info,v0.0.1 2008/10/02 11:16:29 Stalski Exp $
+package = Heartbeat
+name = Heartbeat
+description = Logs user activity when certain events occur, triggering actions. The logged data is accessable through views. The module includes predefined rules and views.
+dependencies[] = content
+dependencies[] = views
+dependencies[] = rules
+dependencies[] = token
+dependencies[] = trigger
+core = 6.x
+version = 6.x-1.0 \ No newline at end of file
diff --git a/heartbeat.install b/heartbeat.install
new file mode 100644
index 0000000..eacba5c
--- /dev/null
+++ b/heartbeat.install
@@ -0,0 +1,32 @@
+<?php
+
+// $Id$
+// by Jochen Stals - ONE-agency - www.one-agency.be
+
+/**
+ * Implementation of hook_install().
+ */
+function heartbeat_install() {
+ heartbeat_variables_install();
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function heartbeat_uninstall() {
+ heartbeat_variables_uninstall();
+}
+
+/**
+ * install basic variables
+ */
+function heartbeat_variables_install() {
+ variable_set('heartbeat_enabled',1);
+}
+
+/**
+ * Uninstall basic variables
+ */
+function heartbeat_variables_uninstall() {
+ variable_del('heartbeat_enabled');
+} \ No newline at end of file
diff --git a/heartbeat.module b/heartbeat.module
new file mode 100644
index 0000000..27c6149
--- /dev/null
+++ b/heartbeat.module
@@ -0,0 +1,138 @@
+<?php
+// $Id$
+// by Jochen Stals - ONE-agency - www.one-agency.be
+
+/**
+ * Implementation of hook_views_api()
+ *
+ * This hook will tell views2 that heartbeat activity is available
+ */
+function heartbeat_views_api() {
+ return array(
+ 'api' => 2,
+ 'path' => drupal_get_path('module', 'heartbeat'),
+ );
+}
+
+/**
+ * Implementation of hook_perm().
+ */
+function heartbeat_perm() {
+ return array('configure heartbeat');
+}
+
+/**
+ * Implementation of hook_menu().
+ */
+function heartbeat_menu() {
+ $items = array();
+ // Administer list
+ $items['admin/settings/heartbeat'] = array(
+ 'title' => t('heartbeat settings'),
+ 'description' => t('Administer settings for heartbeat.'),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('heartbeat_admin_settings'),
+ 'access arguments' => array('configure heartbeat'),
+ 'file' => 'heartbeat.admin.inc',
+ );
+ // Tabs
+ $items['admin/settings/heartbeat/settings'] = array(
+ 'title' => 'Heartbeat settings',
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => 5,
+ );
+ return $items;
+}
+
+/**
+ * Class to handle user activity data
+ *
+ */
+class user_activity {
+
+ // Private members are prefixed with m_
+ private $m_uid = 0;
+ private $m_uid_target = 0;
+ private $m_nid_target = 0;
+ private $m_message = '';
+ private $m_event = '';
+ private $m_variables = array();
+ private $m_variables_string = '';
+
+ /**
+ * constructor
+ */
+ function __construct($data=null) {
+ if(isset($data)) {
+ $this->set_data($data);
+ }
+ }
+
+ /**
+ * Set data into members
+ */
+ public function set_data($data) {
+ if(isset($data['m_uid']))
+ $this->m_uid = $data['m_uid'];
+ if(isset($data['m_uid_target']))
+ $this->m_uid_target = $data['m_uid_target'];
+ if(isset($data['m_nid_target']))
+ $this->m_nid_target = $data['m_nid_target'];
+ if(isset($data['m_message']))
+ $this->m_message = $data['m_message'];
+ if(isset($data['m_event']))
+ $this->m_event = $data['m_event'];
+ if(isset($data['m_variables_string']))
+ $this->m_variables_string = $data['m_variables_string'];
+ // if the data variables have not been included
+ // as normal members, do so now to be available when asked for
+ if($this->m_variables == array() && $this->m_variables_string != '') {
+ $this->variables2array($this->m_variables_string);
+ }
+ }
+
+ /**
+ * Method gets a user_activity variable
+ *
+ * @desc The magic getter method fetches a variable
+ * in members. If not found there, it will always
+ * check the variables as well
+ */
+ public function __get($variable) {
+ // a private member is asked
+ $var = null;
+ if( isset( $this->{'m_'.$variable} ) ) {
+ $var = $this->{'m_'.$variable};
+ }
+ else if(array_key_exists($variable, $this->m_variables)) {
+ $var = $this->m_variables[$variable];
+ }
+ return $var;
+ }
+
+ /**
+ * public function to set variables into readable array
+ */
+ public function variables2array($string) {
+ $array = explode(";", $string);
+ if(!empty($array)) {
+ foreach($array as $var => $value) {
+ $this->m_variables[$var] = (string)$value;
+ }
+ }
+ return $this->m_variables;
+ }
+
+ /**
+ * Public function to save activity to database
+ */
+ public function save() {
+ // Log relational message to user activity
+ db_query("INSERT INTO user_activity SET
+ uid=%d, uid_target=%d, nid_target=%d,
+ message='%s', timestamp=%d, event='%s', variables='%s'",
+ $this->m_uid, $this->m_uid_target, $this->m_nid_target,
+ $this->m_message, $_SERVER['REQUEST_TIME'], $this->m_event, $this->m_variables_string );
+ }
+
+} // eof class user_activity
diff --git a/user_activity/modules/friendlist_activity/friendlist_activity.info b/user_activity/modules/friendlist_activity/friendlist_activity.info
new file mode 100644
index 0000000..c6b17f8
--- /dev/null
+++ b/user_activity/modules/friendlist_activity/friendlist_activity.info
@@ -0,0 +1,9 @@
+; $Id$
+package = Heartbeat
+project = Heartbeat
+name = friendlist activity
+description = Logs activity when a friendlist event occurs. Integration module for all modules that defined rules/events with Rules ui.
+dependencies[] = heartbeat
+dependencies[] = friendlist_rules
+core = 6.x
+version = 6.x-1.0 \ No newline at end of file
diff --git a/user_activity/modules/friendlist_activity/friendlist_activity.module b/user_activity/modules/friendlist_activity/friendlist_activity.module
new file mode 100644
index 0000000..4894e1c
--- /dev/null
+++ b/user_activity/modules/friendlist_activity/friendlist_activity.module
@@ -0,0 +1,15 @@
+<?php
+// $Id$
+// by Jochen Stals - ONE-agency - www.one-agency.be
+
+/**
+ * Implementation of hook_views_api()
+ *
+ * This hook will tell views2 that friendlist_activiy is available
+ */
+function friendlist_activiy_views_api() {
+ return array(
+ 'api' => 2,
+ 'path' => drupal_get_path('module', 'friendlist_activiy'),
+ );
+} \ No newline at end of file
diff --git a/user_activity/modules/friendlist_activity/friendlist_activity.rules.inc b/user_activity/modules/friendlist_activity/friendlist_activity.rules.inc
new file mode 100644
index 0000000..fec02c0
--- /dev/null
+++ b/user_activity/modules/friendlist_activity/friendlist_activity.rules.inc
@@ -0,0 +1,91 @@
+<?php
+// $Id$
+// by Jochen Stals - ONE-agency - www.one-agency.be
+
+
+# ACTIONS
+
+/**
+ * Implementation of hook_rules_action_info().
+ * @ingroup rules
+ */
+function friendlist_activity_rules_action_info() {
+ $info = array(
+ 'rules_friendlist_activity_action' => array(
+ 'label' => t('Logs relational friendlist activity'),
+ 'eval input' => array(
+ 'uid_param',
+ 'uid_target_param',
+ 'message_param',
+ 'variables_param'
+ ),
+ 'help' => 'Create a relation between users by logging their activities',
+ 'module' => 'User activity',
+ ),
+ );
+ return $info;
+}
+
+/**
+ * Action drupal message configuration form.
+ */
+function rules_friendlist_activity_action_form($settings, &$form) {
+ $settings += array(
+ 'uid_param' => '',
+ 'uid_target_param' => '',
+ 'message_param' => '',
+ 'variables_param' => ''
+ );
+ $form['settings']['uid_param'] = array(
+ '#type' => 'textfield',
+ '#size' => '15',
+ '#maxsize' => '25',
+ '#title' => t('User'),
+ '#default_value' => $settings['uid_param'],
+ '#description' => t('The user doing the activity'),
+ );
+ $form['settings']['uid_target_param'] = array(
+ '#type' => 'textfield',
+ '#size' => '15',
+ '#maxsize' => '25',
+ '#title' => t('User target'),
+ '#default_value' => $settings['uid_target_param'],
+ '#description' => t('The user target of the activity'),
+ );
+ $form['settings']['message_param'] = array(
+ '#type' => 'textfield',
+ '#size' => '250',
+ '#maxsize' => '250',
+ '#title' => t('The message'),
+ '#default_value' => $settings['message_param'],
+ '#description' => t('The message'),
+ );
+ $form['settings']['variables_param'] = array(
+ '#type' => 'textarea',
+ '#title' => t('The variables area.'),
+ '#default_value' => $settings['variables_param'],
+ '#description' => t('The variables, leave empty or use with care! <br /> Extra modular stuff goes here with the synthax:<br /><b>var1:value1;var2:value2;va</b> ...'),
+ );
+}
+
+/**
+ * Action Implementation: Log an activity
+ *
+ * @param array $settings
+ * @param array form
+ * @param array with two arrays (set_info and variables)
+ * @ToDo figure out what params mean / can do
+ */
+function rules_friendlist_activity_action($settings, $form=array(), $event_info=array()){
+ //dsm(func_get_args());
+ $data = array();
+ $data['uid'] = $settings['uid_param'];
+ $data['uid_target'] = $settings['uid_target_param'];
+ $data['message'] = $settings['message_param'];
+ $data['variables'] = $settings['variables_param'];
+ $event = '';
+ if(isset($event_info['set_info']['label']) ){
+ $data['event'] = $event_info['set_info']['label'];
+ }
+ user_activity_log($data);
+} \ No newline at end of file
diff --git a/user_activity/modules/friendlist_activity/friendlist_activity.rules_defaults.inc b/user_activity/modules/friendlist_activity/friendlist_activity.rules_defaults.inc
new file mode 100644
index 0000000..64770a7
--- /dev/null
+++ b/user_activity/modules/friendlist_activity/friendlist_activity.rules_defaults.inc
@@ -0,0 +1,164 @@
+<?php
+
+// $Id$
+
+/**
+ * @file
+ * Rules' pre-configured rules.
+ */
+
+function friendlist_activity_rules_defaults() {
+ $config['rules'] = array();
+ $config['rules'] += friendlist_activity_default();
+ // dsm('friendlist_activity_rules_defaults');
+ return $config;
+}
+
+/**
+ * Function to work with rules defined in friendlist
+ */
+function friendlist_activity_default(){
+ // Friendlist
+ // Add an action to the existing event "event_friendlist_add",
+ // for a user relation TWO_WAY user1 -> user2
+ $config['friendlist_activity_rule_1_2'] = array(
+ '#type' => 'rule',
+ '#set' => 'event_friendlist_add',
+ '#label' => 'UserActivity - log requester: Friendlist Request accepted',
+ '#active' => 1,
+ '#weight' => '3',
+ '#status' => 'default',
+ '#conditions' => array(),
+ '#actions' => array(),
+ );
+ $config['friendlist_activity_rule_1_2']['#conditions'] = array(
+ 1 => array(
+ '#weight' => 0,
+ '#settings' =>array(
+ 'status_param' => 'TW_BOTH',
+ '#argument map' => array(
+ 'status_post' => 'relation_status',
+ ),
+ ),
+ '#info' => array(
+ 'label' => 'Request has been accepted',
+ 'label callback' => FALSE,
+ 'arguments' => array(
+ 'relation_status' => array(
+ 'label' => 'Relation status',
+ 'type' => 'relation_status',
+ 'description' => 'The relation to compare',
+ ),
+ ),
+ 'help' => 'TRUE is returned if the relation status equals the string in the input box',
+ 'module' => 'Friendlist Rules',
+ ),
+ '#name' => 'rules_condition_relation_status_compare',
+ '#type' => 'condition',
+ ),
+ );
+ $config['friendlist_activity_rule_1_2']['#actions'][0] = array(
+ '#weight' => 0,
+ '#type' => 'action',
+ '#name' => 'friendlist_activity_rules_action',
+ '#info' => array(
+ 'label' => t('Logs relational user activity'),
+ 'eval input' => array(
+ 'uid_param',
+ 'uid_target_param',
+ 'message_param'
+ ),
+ 'help' => 'Create a relation between users by logging their activities',
+ 'module' => 'User activity',
+ ),
+ '#settings' => array(
+ 'uid_param' => '[user1:uid]',
+ 'uid_target_param' => '[user2:uid]',
+ 'message_param' => t('[user1:user] is now [rtid:name_p] with [user2:user].'),
+ '#argument map' => array('user2' => 'user'),
+ '#eval input' => array(
+ 'token_rules_input_evaluator' => array(
+ 'uid_param' => array(0 => 'user1'),
+ 'uid_target_param' => array(0 => 'user2'),
+ 'message_param' => array(
+ 0 => 'user1',
+ 1 => 'rtid',
+ 2 => 'user2',
+ ),
+ ),
+ ),
+ )
+ );
+ // Add an action to the existing event "event_friendlist_add",
+ // for a user relation TWO_WAY user2 -> user1
+ $config['friendlist_activity_rule_2_1'] = array(
+ '#type' => 'rule',
+ '#set' => 'event_friendlist_add',
+ '#label' => 'UserActivity - log requestee: Friendlist Request accepted',
+ '#active' => 1,
+ '#weight' => '3',
+ '#status' => 'default',
+ '#conditions' => array(),
+ '#actions' => array(),
+ );
+ $config['friendlist_activity_rule_2_1']['#conditions'] = array(
+ 1 => array(
+ '#weight' => 0,
+ '#settings' =>array(
+ 'status_param' => 'TW_BOTH',
+ '#argument map' => array(
+ 'status_post' => 'relation_status',
+ ),
+ ),
+ '#info' => array(
+ 'label' => 'Request has been accepted',
+ 'label callback' => FALSE,
+ 'arguments' => array(
+ 'relation_status' => array(
+ 'label' => 'Relation status',
+ 'type' => 'relation_status',
+ 'description' => 'The relation to compare',
+ ),
+ ),
+ 'help' => 'TRUE is returned if the relation status equals the string in the input box',
+ 'module' => 'Friendlist Rules',
+ ),
+ '#name' => 'rules_condition_relation_status_compare',
+ '#type' => 'condition',
+ ),
+ );
+ $config['friendlist_activity_rule_2_1']['#actions'][0] = array(
+ '#weight' => 0,
+ '#type' => 'action',
+ '#name' => 'rules_action_user_activity',
+ '#info' => array(
+ 'label' => t('Logs relational user activity'),
+ 'eval input' => array(
+ 'uid_param',
+ 'uid_target_param',
+ 'message_param'
+ ),
+ 'help' => 'Create a relation between users by logging their activities',
+ 'module' => 'User activity',
+ ),
+ '#settings' => array(
+ 'uid_param' => '[user2:uid]',
+ 'uid_target_param' => '[user1:uid]',
+ 'message_param' => t('[user2:user] is now [rtid:name_p] with [user1:user].'),
+ '#argument map' => array('user1' => 'user'),
+ '#eval input' => array(
+ 'token_rules_input_evaluator' => array(
+ 'uid_param' => array(0 => 'user2'),
+ 'uid_target_param' => array(0 => 'user1'),
+ 'message_param' => array(
+ 0 => 'user2',
+ 1 => 'rtid',
+ 2 => 'user1',
+ ),
+ ),
+ ),
+ )
+ );
+ //dsm($config);
+ return $config;
+} \ No newline at end of file
diff --git a/user_activity/user_activity.admin.inc b/user_activity/user_activity.admin.inc
new file mode 100644
index 0000000..55319e4
--- /dev/null
+++ b/user_activity/user_activity.admin.inc
@@ -0,0 +1,31 @@
+<?php
+// $Id$
+// by Jochen Stals - ONE-agency - www.one-agency.be
+
+
+/**
+ * Function to maintain and administer specific settings
+ *
+ * @return settingsform
+ */
+function user_activity_admin_settings() {
+ $form['user_activity_no_duplicate_seconds'] = array(
+ '#title' => t('Seconds before an identical activity can be logged again'),
+ '#type' => 'textfield',
+ '#size' => 8,
+ '#default_value' => variable_get('user_activity_no_duplicate_seconds',3600)
+ );
+ $form['user_activity_grouping_seconds'] = array(
+ '#title' => t('Maximum gap (in seconds) for the same activity to be grouped together'),
+ '#type' => 'textfield',
+ '#size' => 8,
+ '#default_value' => variable_get('user_activity_grouping_seconds',3600)
+ );
+ $form['user_activity_grouping_how_many'] = array(
+ '#title' => t('Maximum number of items that can be grouped'),
+ '#type' => 'textfield',
+ '#size' => 8,
+ '#default_value' => variable_get('user_activity_grouping_how_many',5)
+ );
+ return system_settings_form($form);
+} \ No newline at end of file
diff --git a/user_activity/user_activity.info b/user_activity/user_activity.info
new file mode 100644
index 0000000..0757bdf
--- /dev/null
+++ b/user_activity/user_activity.info
@@ -0,0 +1,8 @@
+; $Id$
+package = Heartbeat
+project = Heartbeat
+name = User activity
+description = Logs user activity when certain events occur, triggering actions.
+dependencies[] = heartbeat
+core = 6.x
+version = 6.x-1.0 \ No newline at end of file
diff --git a/user_activity/user_activity.install b/user_activity/user_activity.install
new file mode 100644
index 0000000..436a0c7
--- /dev/null
+++ b/user_activity/user_activity.install
@@ -0,0 +1,110 @@
+<?php
+// $Id$
+// by Jochen Stals - ONE-agency - www.one-agency.be
+
+/**
+ * Implementation of hook_install().
+ */
+function user_activity_install() {
+ // Create tables.
+ drupal_install_schema('user_activity');
+ user_activity_variables_install();
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function user_activity_uninstall() {
+ // Remove tables.
+ drupal_uninstall_schema('user_activity');
+ user_activity_variables_uninstall();
+}
+
+/**
+ * Implementation of hook_schema().
+ */
+function user_activity_schema() {
+ $schema['user_activity'] = array(
+ 'description' => t('Table that contains logs of all user triggerable actions.'),
+ 'fields' => array(
+ 'uaid' => array(
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ 'description' => t('Primary Key: Unique user_activity event ID.'),
+ ),
+ 'uid' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => t('The {users}.uid of the user who triggered the event (requester).'),
+ ),
+ 'uid_target' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => FALSE,
+ 'default' => 0,
+ 'description' => t('The target User ID'),
+ ),
+ 'nid_target' => array(
+ 'description' => t('The target Node ID.'),
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => FALSE,
+ ),
+ 'message' => array(
+ 'type' => 'text',
+ 'not null' => TRUE,
+ 'size' => 'big',
+ 'description' => t('Text of log message to be passed into the t() function.'),
+ ),
+ 'timestamp' => array(
+ 'description' => t('The activity\'s unix timestamp when action occurred'),
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ ),
+ 'event' => array(
+ 'type' => 'varchar',
+ 'length' => 150,
+ 'not null' => FALSE,
+ 'default' => '',
+ 'description' => t('Event type that is hooked. For example "user hook, login operation" or "nodeapi hook, insert operation".'),
+ ),
+ 'variables' => array(
+ 'type' => 'text',
+ 'not null' => FALSE,
+ 'size' => 'big',
+ 'description' => t('Serialized array of variables that match the message string and that is passed into the t() function.'),
+ ),
+ ),
+ 'primary key' => array('uaid'),
+ 'indexes' => array(
+ 'timestamp' => array('timestamp'),
+ 'uid' => array('uid'),
+ 'uid_target' => array('uid_target'),
+ 'nid_target' => array('nid_target'),
+ ),
+ );
+
+ return $schema;
+}
+
+/**
+ * install basic variables
+ */
+function user_activity_variables_install() {
+ variable_set('user_activity_no_duplicate_seconds',3600);
+ variable_get('user_activity_grouping_seconds',3600);
+ variable_get('user_activity_grouping_how_many',5);
+}
+
+/**
+ * Uninstall basic variables
+ */
+function user_activity_variables_uninstall() {
+ variable_del('user_activity_no_duplicate_seconds');
+ variable_del('user_activity_grouping_seconds');
+ variable_del('user_activity_grouping_how_many');
+} \ No newline at end of file
diff --git a/user_activity/user_activity.module b/user_activity/user_activity.module
new file mode 100644
index 0000000..a206332
--- /dev/null
+++ b/user_activity/user_activity.module
@@ -0,0 +1,41 @@
+<?php
+// $Id$
+// by Jochen Stals - ONE-agency - www.one-agency.be
+
+/**
+ * Implementation of hook_views_api()
+ *
+ * This hook will tell views2 that user activity is available
+ */
+function user_activity_views_api() {
+ return array(
+ 'api' => 2,
+ 'path' => drupal_get_path('module', 'user_activity'),
+ );
+}
+
+/**
+ * Implementation of hook_menu().
+ */
+function user_activity_menu() {
+ $items = array();
+ $items['admin/settings/heartbeat/user_activity'] = array(
+ 'title' => 'user activity settings',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('user_activity_admin_settings'),
+ 'access arguments' => array('configure user activity'),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 6,
+ 'file' => 'user_activity.admin.inc',
+ );
+ return $items;
+}
+
+/**
+ * User activity logger function
+ * @param The data to add one row
+ */
+function user_activity_log($data) {
+ $user_activity = new user_activity($data);
+ $user_activity->save();
+} \ No newline at end of file
diff --git a/user_activity/user_activity.rules.inc b/user_activity/user_activity.rules.inc
new file mode 100644
index 0000000..2c03d43
--- /dev/null
+++ b/user_activity/user_activity.rules.inc
@@ -0,0 +1,176 @@
+<?php
+// $Id$
+// by Jochen Stals - ONE-agency - www.one-agency.be
+
+
+/**
+* Implementation of hook_rules_data_type_info()
+*/
+function user_activity_rules_data_type_info() {
+ return array(
+ 'message' => array(
+ 'label' => t('Logged message'),
+ 'class' => 'rules_data_type_message',
+ 'identifiable' => FALSE,
+ ),
+ );
+}
+
+/**
+* Rules relation_message data type
+*/
+class rules_data_type_message extends rules_data_type {
+}
+
+
+# ACTIONS
+
+/**
+ * Implementation of hook_rules_action_info().
+ * @ingroup rules
+ */
+function user_activity_rules_action_info() {
+ $info = array(
+ 'rules_user_activity_action' => array(
+ 'label' => t('Logs relational user activity'),
+ 'eval input' => array(
+ 'uid_param',
+ 'uid_target_param',
+ 'nid_target_param',
+ 'message_param',
+ 'variables_param'
+ ),
+ 'help' => 'Create a relation between users by logging their activities',
+ 'module' => 'User activity',
+ ),
+ );
+ return $info;
+}
+
+/**
+ * Action drupal message configuration form.
+ */
+function rules_user_activity_action_form($settings, &$form) {
+ $settings += array(
+ 'uid_param' => '',
+ 'uid_target_param' => '',
+ 'nid_target_param' => '',
+ 'message_param' => '',
+ 'variables_param' => ''
+ );
+ $form['settings']['uid_param'] = array(
+ '#type' => 'textfield',
+ '#size' => '15',
+ '#maxsize' => '25',
+ '#title' => t('User'),
+ '#default_value' => $settings['uid_param'],
+ '#description' => t('The user doing the activity'),
+ );
+ $form['settings']['uid_target_param'] = array(
+ '#type' => 'textfield',
+ '#size' => '15',
+ '#maxsize' => '25',
+ '#title' => t('User target'),
+ '#default_value' => $settings['uid_target_param'],
+ '#description' => t('The user target of the activity'),
+ );
+ $form['settings']['nid_target_param'] = array(
+ '#type' => 'textfield',
+ '#size' => '15',
+ '#maxsize' => '25',
+ '#title' => t('Node target'),
+ '#default_value' => $settings['nid_target_param'],
+ '#description' => t('The node target of the activity'),
+ );
+ $form['settings']['message_param'] = array(
+ '#type' => 'textfield',
+ '#size' => '250',
+ '#maxsize' => '250',
+ '#title' => t('The message'),
+ '#default_value' => $settings['message_param'],
+ '#description' => t('The message'),
+ );
+ $form['settings']['variables_param'] = array(
+ '#type' => 'textarea',
+ '#title' => t('The variables area.'),
+ '#default_value' => $settings['variables_param'],
+ '#description' => t('The variables, leave empty or use with care! <br /> Extra modular stuff goes here with the synthax:<br /><b>var1:value1;var2:value2;va</b> ...'),
+ );
+}
+
+/**
+ * Action Implementation: Log an activity
+ *
+ * @param array $settings
+ * @param array form
+ * @param array with two arrays (set_info and variables)
+ * @ToDo figure out what params mean / can do
+ */
+function rules_user_activity_action($settings, $form=array(), $event_info=array()){
+ //dsm(func_get_args());
+ $data = array();
+ $data['uid'] = $settings['uid_param'];
+ $data['uid_target'] = $settings['uid_target_param'];
+ $data['nid_target'] = $settings['nid_target_param'];
+ $data['message'] = $settings['message_param'];
+ $data['variables'] = $settings['variables_param'];
+ $event = '';
+ if(isset($event_info['set_info']['label']) ){
+ $data['event'] = $event_info['set_info']['label'];
+ }
+ user_activity_log($data);
+}
+
+
+# Conditions
+
+/**
+ * Implentation of hook_rules_conditions_info().
+ */
+function user_activity_rules_condition_info() {
+ // example code here
+}
+
+
+# TOKENS
+
+/**
+ * Implementation of hook_token_list().
+ */
+function user_activity_token_list($type = 'all') {
+ if ($type == 'logged__message') {
+ $tokens['message']['string-raw'] = t("The raw message");
+ }
+ if ($type == 'boolean') {
+ $tokens['boolean']['1-or-0'] = t("1 for true, 0 for false");
+ }
+ if ($type == 'node') {
+ $tokens['node']['title-link'] = t("The node's title with a link to it");
+ }
+ if ($type == 'user') {
+ $tokens['node']['user-name-url'] = t("The user's name with a link to it");
+ }
+ return $tokens;
+}
+
+/**
+ * Implementation of hook_token_values().
+ */
+function user_activity_token_values($type, $object = NULL, $options = array()) {
+ $values = array();
+ switch ($type) {
+ case 'message':
+ $values['raw'] = $object;
+ break;
+ case 'boolean':
+ $values['1-or-0'] = $object ? '1' : '0' ;
+ break;
+ case 'node':
+ $values['title-link'] = l($object->title,'node/'.$object->nid);
+ break;
+ case 'user':
+ $values['user-name-url'] = l($object->name,'user/'.$object->uid);
+ break;
+ }
+ return $values;
+} \ No newline at end of file
diff --git a/user_activity/user_activity.rules_defaults.inc b/user_activity/user_activity.rules_defaults.inc
new file mode 100644
index 0000000..5fc69e3
--- /dev/null
+++ b/user_activity/user_activity.rules_defaults.inc
@@ -0,0 +1,116 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Rules' pre-configured rules for default drupal core behaviour.
+ */
+
+function user_activity_rules_defaults() {
+ $config['rules'] = array();
+ $config['rules'] += user_activity_default();
+ //dsm('user_activity_rules_defaults');
+ return $config;
+}
+
+/**
+ * Function to work with rules defined in friendlist
+ */
+function user_activity_default(){
+ $config = array (
+ 'rules' => array (
+ 'node_update_activity_rule' =>
+ array (
+ '#type' => 'rule',
+ '#set' => 'event_node_update',
+ '#label' => 'UserActivity - log user updating a node',
+ '#active' => 1,
+ '#weight' => '0',
+ '#status' => 'custom',
+ '#conditions' =>
+ array (
+ 0 =>
+ array (
+ '#type' => 'condition',
+ '#settings' =>
+ array (
+ '#argument map' =>
+ array (
+ 'node' => 'node',
+ ),
+ ),
+ '#name' => 'rules_condition_content_is_published',
+ '#info' =>
+ array (
+ 'label' => 'Updated content is published',
+ 'arguments' =>
+ array (
+ 'node' =>
+ array (
+ 'type' => 'node',
+ 'label' => 'Content',
+ ),
+ ),
+ 'module' => 'Node',
+ ),
+ '#weight' => 0,
+ ),
+ ),
+ '#actions' =>
+ array (
+ 0 =>
+ array (
+ '#weight' => 0,
+ '#info' =>
+ array (
+ 'label' => 'Logs relational user activity',
+ 'eval input' =>
+ array (
+ 0 => 'uid_param',
+ 1 => 'uid_target_param',
+ 2 => 'nid_target_param',
+ 3 => 'message_param',
+ 3 => 'message_variables',
+ ),
+ 'module' => 'User activity',
+ ),
+ '#name' => 'rules_user_activity_action',
+ '#settings' =>
+ array (
+ 'uid_param' => '[author:uid]',
+ 'uid_target_param' => '0',
+ 'nid_target_param' => '[node:nid]',
+ 'message_param' => '[author:user] has updated [node:title]. ([node:type])',
+ 'message_variables' => 'group_id:[node:og-id];node_type:[node:type];',
+ '#eval input' =>
+ array (
+ 'token_rules_input_evaluator' =>
+ array (
+ 'uid_param' =>
+ array (
+ 0 => 'author',
+ ),
+ 'nid_target_param' =>
+ array (
+ 0 => 'node',
+ ),
+ 'message_param' =>
+ array (
+ 0 => 'node',
+ 1 => 'author',
+ ),
+ 'message_variables' =>
+ array (
+ 0 => 'node',
+ ),
+ ),
+ ),
+ ),
+ '#type' => 'action',
+ ),
+ ),
+ ),
+ ),
+ );
+ return $config;
+} \ No newline at end of file
diff --git a/user_activity/user_activity.views.inc b/user_activity/user_activity.views.inc
new file mode 100644
index 0000000..f34a4c0
--- /dev/null
+++ b/user_activity/user_activity.views.inc
@@ -0,0 +1,109 @@
+<?php
+//
+
+// http://blue.live4all.co.il/~mooffie/tmp/views_illustrated/
+//http://views.doc.logrus.com/
+
+/**
+ * Implementation of hook_views_handlers
+ *
+ * @return unknown
+ */
+function user_activity_views_handlers() {
+ return array(
+ 'info' => array(
+ 'path' => drupal_get_path('module', 'user_activity'),
+ ),
+ 'handlers' => array(),
+ );
+}
+
+/**
+ * Implementation of views hook hook_views_data()
+ *
+ * @return unknown
+ */
+function user_activity_views_data() {
+ $data = array(
+ 'user_activity' => array(
+ 'table' => array(
+ 'group' => t('User activity log table'),
+ 'base' => array(
+ 'field' => 'aid',
+ 'title' => t('Activities'),
+ 'help' => t("User activities on the site"),
+ ),
+ ),
+ 'uid' => array(
+ 'title' => t('User'),
+ 'help' => t('The user who carried out the activity'),
+ 'relationship' => array(
+ 'base' => 'users',
+ 'field' => 'uid',
+ 'handler' => 'views_handler_relationship',
+ 'label' => t('User'),
+ ),
+ ),
+ 'uid_current' => array(
+ 'real field' => 'uid',
+ 'title' => t('Currently logged in user carried out the activity'),
+ 'help' => t('The user who did the activity is the currently logged in user'),
+ 'filter' => array(
+ 'handler' => 'views_handler_filter_user_current',
+ ),
+ ),
+ 'uid_target' => array(
+ 'title' => t('Target User'),
+ 'help' => t('The user who was the target of the activity (if present)'),
+ 'relationship' => array(
+ 'base' => 'users',
+ 'field' => 'uid',
+ 'handler' => 'views_handler_relationship',
+ 'label' => t('User'),
+ ),
+ ),
+ 'uid_tarted_current' => array(
+ 'real field' => 'uid_target',
+ 'title' => t('Currently logged in user is the activity\'s recipient'),
+ 'help' => t('The user who was the target of the activity is the currently logged in user'),
+ 'filter' => array(
+ 'handler' => 'views_handler_filter_user_current',
+ ),
+ ),
+ 'nid_target' => array(
+ 'title' => t('Target Node'),
+ 'help' => t('The node which was the target of the activity (if present)'),
+ 'relationship' => array(
+ 'base' => 'node',
+ 'field' => 'nid',
+ 'handler' => 'views_handler_relationship',
+ 'label' => t('Node'),
+ ),
+ ),
+ 'message' => array(
+ 'title' => t('Message'),
+ 'help' => t('Logged Message'),
+ 'field' => array(
+ 'handler' => 'views_handler_field',
+ 'click sortable' => TRUE,
+ ),
+ ),
+ 'timestamp' => array(
+ 'title' => t('Action\'s timestamp'),
+ 'help' => t('When the action happened'),
+ 'field' => array(
+ 'handler' => 'views_handler_field_date',
+ 'click sortable' => TRUE,
+ ),
+ 'sort' => array(
+ 'handler' => 'views_handler_sort_date',
+ ),
+ 'filter' => array(
+ 'handler' => 'views_handler_filter_date',
+ ),
+ ),
+ ),
+ );
+ return $data;
+}
+
diff --git a/user_activity_views/user_activity_views.info b/user_activity_views/user_activity_views.info
new file mode 100644
index 0000000..f4860b6
--- /dev/null
+++ b/user_activity_views/user_activity_views.info
@@ -0,0 +1,9 @@
+; $Id$
+package = Heartbeat
+project = Heartbeat
+name = User activity views
+description = Contains default views to view the heartbeat of users. Additionally you can add your own views with the extra fields and arguments added by the heartbeat module.
+dependencies[] = heartbeat
+dependencies[] = User activity
+core = 6.x
+version = 6.x-1.0 \ No newline at end of file