From cf979b82dc74e6980342aba41bdbbe353e4446a4 Mon Sep 17 00:00:00 2001
From: Mike Gifford <mike@openconcept.ca>
Date: Sun, 27 Feb 2011 23:53:35 -0500
Subject: [PATCH] initial d7 migration

---
 wwsgd.info    |    9 ++++-
 wwsgd.install |   23 ++++++++----
 wwsgd.module  |  112 ++++++++++++++++++++++++++++++++------------------------
 3 files changed, 86 insertions(+), 58 deletions(-)

diff --git a/wwsgd.info b/wwsgd.info
index 5c2e5b0..0e74624 100644
--- a/wwsgd.info
+++ b/wwsgd.info
@@ -1,5 +1,10 @@
 ; $Id $
 name = What Would Seth Godin Do?
 description = "Shows a link to the site's RSS feed if someone is a new visitor to the site."
-core = 6.x
-dependencies[] = session_api
\ No newline at end of file
+core = 7.x
+dependencies[] = session_api
+
+files[] = wwsgd.module
+
+; configure = admin/config/development/coder/upgrade/settings
+
diff --git a/wwsgd.install b/wwsgd.install
index 3fea17d..ddd6027 100644
--- a/wwsgd.install
+++ b/wwsgd.install
@@ -1,23 +1,34 @@
 <?php
+// $Id$
 
+/**
+ * @file
+ * Install, update, and uninstall functions for wwsgd.
+ *
+ * @ingroup wwsgd
+ */
+
+/**
+ * Implementation of hook_schema().
+ */
 function wwsgd_schema() {
   $schema['wwsgd_visits'] = array(
-    'description' => t('How many times a person has visited the site.'),
+    'description' => 'How many times a person has visited the site.',
     'fields' => array(
        'sid' => array(
-         'description' => t('Session ID, mapped to the one the Session API module sets'),
+         'description' => 'Session ID, mapped to the one the Session API module sets',
          'type' => 'int', 
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'visits' => array(
-         'description' => t('The number of visits to the site. This will change to mean views of a block with the associated bid'),
+         'description' => 'The number of visits to the site. This will change to mean views of a block with the associated bid',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'bid' => array(
-         'description' => t('Block ID viewed by this session. Unused until http://drupal.org/node/300909 Unlimited number of blocks is resolved'),
+         'description' => 'Block ID viewed by this session. Unused until http://drupal.org/node/300909 Unlimited number of blocks is resolved',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
@@ -26,7 +37,3 @@ function wwsgd_schema() {
   );
   return $schema;
 }
-
-function wwsgd_install() {
-  drupal_install_schema('wwsgd');
-}
\ No newline at end of file
diff --git a/wwsgd.module b/wwsgd.module
index 3a86656..161d9ec 100644
--- a/wwsgd.module
+++ b/wwsgd.module
@@ -1,9 +1,11 @@
 <?php
+// $Id$
 
 function wwsgd_get_visits($sid) {
-  $result = db_result(db_query("SELECT visits FROM {wwsgd_visits} WHERE sid = %d", $sid));
+  $result = db_query("SELECT visits FROM {wwsgd_visits} WHERE sid = :sid", array(':sid' => $sid));
   if (empty($result)) {
     wwsgd_set_visits($sid, 1);
+    watchdog('wwsgd', 'New visitor from $sid', array(),  WATCHDOG_INFO, NULL);
   }
   else {
     $visits = $result;
@@ -25,53 +27,67 @@ function wwsgd_set_visits($sid, $visits) {
   }
 }
 
-function wwsgd_block($op = 'list', $delta = 0, $edit = array()) {
+/**
+ * Implementation of hook_block_info().
+ */
+function wwsgd_block_info() {
+  // This example comes from node.module.
+  $blocks['wwsgd'] = array(
+    'info' => t('What Would Seth Godin Do?'),
+    'status' => '',
+    'weight' => 0,
+    'visibility' => 1,
+    'cache' => DRUPAL_NO_CACHE,
+  );
+  return $blocks;
+}
+
+/**
+ * Implementation of hook_block_view().
+ * add basic html with raw details about earth hour
+ */
+function wwsgd_block_view($delta = '') {
   $wwsgd_block_text_default = "Is this your first time visiting?  Consider subscribing to <a href=\"rss.xml\">this site's RSS feed</a> to get updates.";
-  switch ($op) {
-  case 'list':
-    $blocks = array();
-    $blocks[0] = array(
-      'info' => 'What Would Seth Godin Do?',
-      'status' => '',
-      'weight' => 0,
-      'visibility' => 1,
-      'cache' => BLOCK_NO_CACHE,
-    );
-    return $blocks;
-  break;
-  case 'configure':
-    $form = array();
-    $form['wwsgd_block_text'] = array(
-      '#type' => 'textarea',
-      '#size' => 150,
-      '#description' => 'This text will display in the sidebar block for first-time visitors',
-      '#default_value' => variable_get('wwsgd_block_text', $wwsgd_block_text_default),
-    );
-    $form['wwsgd_max_visits'] = array(
-      '#type' => 'select',
-      '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)),
-      '#default_value' => variable_get('wwsgd_max_visits', 5),
-      '#description' => 'Number of visits before the block turns off for a user.',
-    );
-    return $form;
-    break;
-  case 'save':
-    variable_set('wwsgd_max_visits', $edit['wwsgd_max_visits']);
-    variable_set('wwsgd_block_text', $edit['wwsgd_block_text']); 
-    break;
-  case 'view':
-    $wwsgd_block = array();
-    $session_id = session_api_get_sid();
-    $wwsgd_visits = wwsgd_get_visits($session_id);
 
-    $wwsgd_block_visits_setting = variable_get('wwsgd_max_visits', 5);
-    if ($wwsgd_visits < $wwsgd_block_visits_setting) {
-      $wwsgd_block_text = variable_get('wwsgd_block_text', $wwsgd_block_text_default);
-      $wwsgd_block['content'] = $wwsgd_block_text;  
-      $wwsgd_visits = $wwsgd_visits + 1;
-      wwsgd_set_visits($session_id, $wwsgd_visits);
-    }
-    return $wwsgd_block;
-    break;
+  $wwsgd_block = array();
+  $session_id = session_api_get_sid();
+  $wwsgd_visits = wwsgd_get_visits($session_id);
+
+  $wwsgd_block_visits_setting = variable_get('wwsgd_max_visits', 5);
+  if ($wwsgd_visits < $wwsgd_block_visits_setting) {
+    $wwsgd_block_text = variable_get('wwsgd_block_text', $wwsgd_block_text_default);
+    $wwsgd_block['content'] = $wwsgd_block_text;  
+    $wwsgd_visits = $wwsgd_visits + 1;
+    wwsgd_set_visits($session_id, $wwsgd_visits);
   }
-}
\ No newline at end of file
+  return $wwsgd_block;
+}
+
+/**
+ * Implementation of hook_block_configure().
+ */
+function wwsgd_block_configure($delta = '') {
+  $form = array();
+  $form['wwsgd_block_text'] = array(
+    '#type' => 'textarea',
+    '#size' => 150,
+    '#description' => ('This text will display in the sidebar block for first-time visitors'),
+    '#default_value' => variable_get('wwsgd_block_text', $wwsgd_block_text_default),
+  );
+  $form['wwsgd_max_visits'] = array(
+    '#type' => 'select',
+    '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)),
+    '#default_value' => variable_get('wwsgd_max_visits', 5),
+    '#description' => ('Number of visits before the block turns off for a user.'),
+  );
+  return $form;
+}
+
+/**
+ * Implementation of hook_block_save().
+ */
+function wwsgd_block_save($delta = '', $edit = array()) {
+  variable_set('wwsgd_max_visits', $edit['wwsgd_max_visits']);
+  variable_set('wwsgd_block_text', $edit['wwsgd_block_text']); 
+}
+
-- 
1.7.1

