From 58f259fa8419f3d82973567ddf4bdf330c19c6ed Mon Sep 17 00:00:00 2001
Message-Id: <58f259fa8419f3d82973567ddf4bdf330c19c6ed.1300914606.git.jarodms@JMSWork.(none)>
From: Jarod Smith <jarodms@gmail.com>
Date: Wed, 23 Mar 2011 15:58:44 -0500
Subject: [PATCH] Added links_history module

---
 modules/links_history/links_history.info           |    9 +
 modules/links_history/links_history.install        |   51 ++++
 modules/links_history/links_history.module         |   19 ++
 modules/links_history/links_history.views.inc      |   60 +++++
 .../links_history/links_history.views_default.inc  |  268 ++++++++++++++++++++
 5 files changed, 407 insertions(+), 0 deletions(-)

diff --git a/modules/links_history/links_history.info b/modules/links_history/links_history.info
new file mode 100755
index 0000000..f843f9b
--- /dev/null
+++ b/modules/links_history/links_history.info
@@ -0,0 +1,9 @@
+name = Links History
+description = "Links package used to track history of link clicking for more detailed reporting."
+package = "Links"
+core = "6.x"
+version = "6.x-1.0"
+dependencies[] = "links"
+
+
+
diff --git a/modules/links_history/links_history.install b/modules/links_history/links_history.install
new file mode 100755
index 0000000..4f5bd3f
--- /dev/null
+++ b/modules/links_history/links_history.install
@@ -0,0 +1,51 @@
+<?php
+
+/**
+ * Implementation of hook_install().
+ */
+function links_history_install() {
+  drupal_install_schema('links_history');
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function links_history_uninstall() {
+  // Drop tables.
+  drupal_uninstall_schema('links_history');
+}
+
+function links_history_schema() {
+  $schema = array();
+  $schema['links_history'] = array(
+      'description' => t('Holds link click history'),
+      'fields' => array(
+          'lhid' => array(
+              'description' => t('Links History UID'),
+              'type' => 'serial',
+              'unsigned' => TRUE,
+              'not null' => TRUE,
+          ),
+          'lid' => array(
+              'description' => t('Links ID'),
+              'type' => 'int',
+              'unsigned' => TRUE,
+              'not null' => TRUE,
+          ),
+          'datetime' => array(
+              'description' => t('DateTime of click'),
+              'type' => 'int',
+              'unsigned' => TRUE,
+              'not null' => TRUE,
+          ),
+          'user_ip' => array(
+              'description' => 'IP of user who made the click',
+              'type' => 'text',
+              'size' => 'small',
+          ),
+      ),
+      'primary key' => array('lhid'),
+  );
+  return $schema;
+}
+
diff --git a/modules/links_history/links_history.module b/modules/links_history/links_history.module
new file mode 100755
index 0000000..15329a3
--- /dev/null
+++ b/modules/links_history/links_history.module
@@ -0,0 +1,19 @@
+<?php
+
+/*
+ * Stores a link click event in links_history
+ */
+function _link_clicked($lid) {
+  db_query("INSERT INTO {links_history} (lid, datetime, user_ip) VALUES (%d, %d, '%s')", $lid, time(),ip_address());
+}
+
+/**
+ * Implements hook_views_api()
+ */
+function links_history_views_api() {
+  return array(
+    'api' => 2,
+    'path' => drupal_get_path('module', 'links_history'),
+  );
+}
+
diff --git a/modules/links_history/links_history.views.inc b/modules/links_history/links_history.views.inc
new file mode 100755
index 0000000..861ca3b
--- /dev/null
+++ b/modules/links_history/links_history.views.inc
@@ -0,0 +1,60 @@
+<?php
+
+/**
+ * Implements hook_views_data()
+ */
+function links_history_views_data() {
+
+  $data['links_history']['table']['group'] = t('Links');
+  $data['links_history']['table']['join']['node'] = array(
+      'left_table' => 'links_node',
+      'left_field' => 'lid',
+      'field' => 'lid',
+  );
+
+  $data['links_history']['lhid'] = array(
+      'title' => t('Link History ID'),
+      'help' => t('Link History ID'),
+      'field' => array(
+          'handler' => 'views_handler_field',
+          'click sortable' => TRUE,
+      ),
+  );
+
+  $data['links_history']['lid'] = array(
+      'title' => t('Link ID'),
+      'help' => t('Link ID from Links History'),
+      'field' => array(
+          'handler' => 'views_handler_field',
+          'click sortable' => TRUE,
+      ),
+  );
+
+  $data['links_history']['user_ip'] = array(
+      'title' => t('User IP'),
+      'help' => t('IP of the user who made the click'),
+      'field' => array(
+          'handler' => 'views_handler_field',
+          'click sortable' => TRUE,
+      ),
+  );
+
+  // datetime
+  $data['links_history']['datetime'] = array(
+      'title' => t('Click time'),
+      'help' => t('The most recent time the link was clicked.'),
+      'field' => array(
+          'handler' => 'views_handler_field_date',
+          'click sortable' => TRUE,
+      ),
+      'sort' => array(
+          'handler' => 'views_handler_sort',
+      ),
+      'filter' => array(
+        'handler' => 'views_handler_filter_date',
+      ),
+
+  );
+
+  return $data;
+}
diff --git a/modules/links_history/links_history.views_default.inc b/modules/links_history/links_history.views_default.inc
new file mode 100755
index 0000000..92ca68e
--- /dev/null
+++ b/modules/links_history/links_history.views_default.inc
@@ -0,0 +1,268 @@
+<?php
+
+/**
+ * Implementation of hook_views_default_views().
+ *
+ */
+function links_history_views_default_views() {
+  $view = new view;
+  
+  // START CODE GENERATED BY EXPORT
+  $view->name = 'link_click_tracking';
+  $view->description = 'Link Click Tracking';
+  $view->tag = '';
+  $view->view_php = '';
+  $view->base_table = 'node';
+  $view->is_cacheable = FALSE;
+  $view->api_version = 2;
+  $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
+  $handler = $view->new_display('default', 'Defaults', 'default');
+  $handler->override_option('fields', array(
+      'lhid' => array(
+          'label' => 'Click Count',
+          'alter' => array(
+              'alter_text' => 0,
+              'text' => '',
+              'make_link' => 0,
+              'path' => '',
+              'link_class' => '',
+              'alt' => '',
+              'prefix' => '',
+              'suffix' => '',
+              'target' => '',
+              'help' => '',
+              'trim' => 0,
+              'max_length' => '',
+              'word_boundary' => 1,
+              'ellipsis' => 1,
+              'html' => 0,
+              'strip_tags' => 0,
+          ),
+          'empty' => '',
+          'hide_empty' => 0,
+          'empty_zero' => 0,
+          'exclude' => 0,
+          'id' => 'lhid',
+          'table' => 'links_history',
+          'field' => 'lhid',
+          'relationship' => 'none',
+      ),
+      'lid' => array(
+          'label' => 'Link ID',
+          'alter' => array(
+              'alter_text' => 0,
+              'text' => '',
+              'make_link' => 0,
+              'path' => '',
+              'link_class' => '',
+              'alt' => '',
+              'prefix' => '',
+              'suffix' => '',
+              'target' => '',
+              'help' => '',
+              'trim' => 0,
+              'max_length' => '',
+              'word_boundary' => 1,
+              'ellipsis' => 1,
+              'html' => 0,
+              'strip_tags' => 0,
+          ),
+          'empty' => '',
+          'hide_empty' => 0,
+          'empty_zero' => 0,
+          'exclude' => 0,
+          'id' => 'lid',
+          'table' => 'links_history',
+          'field' => 'lid',
+          'relationship' => 'none',
+      ),
+      'url' => array(
+          'id' => 'url',
+          'table' => 'links',
+          'field' => 'url',
+          'exclude' => 0,
+          'relationship' => 'none',
+          'label' => '',
+          'alter' => array(
+              'alter_text' => 0,
+              'text' => '',
+              'make_link' => 0,
+              'path' => '',
+              'link_class' => '',
+              'alt' => '',
+              'prefix' => '',
+              'suffix' => '',
+              'target' => '',
+              'help' => '',
+              'trim' => 0,
+              'max_length' => '',
+              'word_boundary' => 0,
+              'ellipsis' => 0,
+              'html' => 0,
+              'strip_tags' => 0,
+          ),
+          'empty' => '',
+          'empty_zero' => 0,
+          'hide_empty' => 0,
+          'link_type' => 'url',
+      ),
+      'views_sql_groupedfields' => array(
+          'label' => 'Group By Fields',
+          'alter' => array(
+              'alter_text' => FALSE,
+              'text' => '',
+              'make_link' => FALSE,
+              'path' => '',
+              'alt' => '',
+              'link_class' => '',
+              'prefix' => '',
+              'suffix' => '',
+              'target' => '',
+              'trim' => FALSE,
+              'max_length' => '',
+              'word_boundary' => TRUE,
+              'ellipsis' => TRUE,
+              'strip_tags' => FALSE,
+              'html' => FALSE,
+          ),
+          'empty' => '',
+          'hide_empty' => 0,
+          'empty_zero' => 0,
+          'exclude' => '1',
+          'id' => 'views_sql_groupedfields',
+          'table' => 'views_groupby',
+          'field' => 'views_sql_groupedfields',
+          'relationship' => 'none',
+          'views_groupby_fields_to_group' => array(
+              'lid' => 'lid',
+          ),
+          'views_groupby_sql_function' => 'count',
+          'views_groupby_fields_to_aggregate' => array(
+              'lhid' => 'lhid',
+          ),
+          'views_groupby_field_sortby' => 'url',
+          'views_groupby_sortby_direction' => 'asc',
+      ),
+      'title' => array(
+          'label' => 'Title',
+          'alter' => array(
+              'alter_text' => 0,
+              'text' => '',
+              'make_link' => 0,
+              'path' => '',
+              'link_class' => '',
+              'alt' => '',
+              'prefix' => '',
+              'suffix' => '',
+              'target' => '',
+              'help' => '',
+              'trim' => 0,
+              'max_length' => '',
+              'word_boundary' => 1,
+              'ellipsis' => 1,
+              'html' => 0,
+              'strip_tags' => 0,
+          ),
+          'empty' => '',
+          'hide_empty' => 0,
+          'empty_zero' => 0,
+          'link_to_node' => 0,
+          'exclude' => 0,
+          'id' => 'title',
+          'table' => 'node',
+          'field' => 'title',
+          'relationship' => 'none',
+      ),
+  ));
+  $handler->override_option('filters', array(
+      'type' => array(
+          'operator' => 'in',
+          'value' => array(
+              'weblink' => 'weblink',
+          ),
+          'group' => '0',
+          'exposed' => FALSE,
+          'expose' => array(
+              'operator' => FALSE,
+              'label' => '',
+          ),
+          'id' => 'type',
+          'table' => 'node',
+          'field' => 'type',
+          'relationship' => 'none',
+      ),
+      'datetime' => array(
+          'operator' => 'between',
+          'value' => array(
+              'type' => 'date',
+              'value' => '',
+              'min' => '2010-12-01 00:00:00',
+              'max' => '2011-02-01 00:00:00',
+          ),
+          'group' => '0',
+          'exposed' => TRUE,
+          'expose' => array(
+              'use_operator' => 0,
+              'operator' => 'datetime_op',
+              'identifier' => 'datetime',
+              'label' => 'Links: Click time',
+              'optional' => 1,
+              'remember' => 0,
+          ),
+          'id' => 'datetime',
+          'table' => 'links_history',
+          'field' => 'datetime',
+          'relationship' => 'none',
+      ),
+  ));
+  $handler->override_option('access', array(
+      'type' => 'none',
+  ));
+  $handler->override_option('cache', array(
+      'type' => 'none',
+  ));
+  $handler->override_option('distinct', 0);
+  $handler->override_option('style_plugin', 'table');
+  $handler->override_option('style_options', array(
+      'grouping' => '',
+      'override' => 1,
+      'sticky' => 0,
+      'order' => 'asc',
+      'columns' => array(
+          'url' => 'url',
+          'datetime' => 'datetime',
+      ),
+      'info' => array(
+          'url' => array(
+              'sortable' => 0,
+              'separator' => '',
+          ),
+          'datetime' => array(
+              'sortable' => 0,
+              'separator' => '',
+          ),
+      ),
+      'default' => '-1',
+  ));
+  $handler = $view->new_display('page', 'Page', 'page_1');
+  $handler->override_option('path', 'link_tracker');
+  $handler->override_option('menu', array(
+      'type' => 'none',
+      'title' => '',
+      'description' => '',
+      'weight' => 0,
+      'name' => 'navigation',
+  ));
+  $handler->override_option('tab_options', array(
+      'type' => 'none',
+      'title' => '',
+      'description' => '',
+      'weight' => 0,
+      'name' => 'navigation',
+  ));
+  // END CODE GENERATED BY EXPORT
+
+  $views[$view->name] = $view;
+
+  return $views;
+}
\ No newline at end of file
-- 
1.7.4

