? follow-D7-619276-6.patch
? follow-D7-619276-7.patch
? follow-D7-619276-8.patch
Index: follow.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/follow/follow.install,v
retrieving revision 1.2
diff -u -p -r1.2 follow.install
--- follow.install	30 Oct 2009 21:09:28 -0000	1.2
+++ follow.install	2 Nov 2009 17:53:36 -0000
@@ -18,20 +18,20 @@ function follow_install() {
  */
 function follow_schema() {
   $schema['follow_links'] = array(
-    'description' => t('Stores sitewide and user follow links.'),
+    'description' => 'Stores sitewide and user follow links.',
     'fields' => array(
       'lid' => array(
         'type' => 'serial',
         'unsigned' => TRUE,
         'not null' => TRUE,
-        'description' => t('Unique identifier for the {follow_links}.'),
+        'description' => 'Unique identifier for the {follow_links}.',
       ),
       'name' => array(
         'type' => 'varchar',
         'length' => 255,
         'not null' => TRUE,
         'default' => '',
-        'description' => t("The machine name of the {follow_links}."),
+        'description' => "The machine name of the {follow_links}.",
       ),
       'uid' => array(
         'type' => 'int',
@@ -51,7 +51,7 @@ function follow_schema() {
         'not null' => TRUE,
         'default' => 0,
         'size' => 'tiny',
-        'description' => t('The weight of this {follow_links}.'),
+        'description' => 'The weight of this {follow_links}.',
       ),
     ),
     'primary key' => array('lid'),
@@ -70,5 +70,9 @@ function follow_uninstall() {
   variable_del('follow_user_block_title');
   variable_del('follow_site_block_title');
   variable_del('follow_site_block_user');
+}
+
+function follow_update_7000() {
   cache_clear_all('follow:networks', 'cache');
+  return array();
 }
Index: follow.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/follow/follow.module,v
retrieving revision 1.5
diff -u -p -r1.5 follow.module
--- follow.module	30 Oct 2009 22:00:08 -0000	1.5
+++ follow.module	2 Nov 2009 17:53:36 -0000
@@ -259,7 +259,7 @@ function _follow_block_content($uid = 0)
   $output = '';
 
   if ($links = follow_links_load($uid)) {
-    $output = theme('follow_links', $links, follow_networks_load());
+    $output = theme('follow_links', array('links' => $links, 'networks' => follow_networks_load($uid)));
     $output .= _follow_block_config_links($uid);
   }
 
@@ -276,7 +276,7 @@ function _follow_block_content($uid = 0)
  *
  * @ingroup themeable
  */
-function theme_follow_links($variables) {
+function theme_follow_links($variables) {drupal_set_message(print_r($variables,1));
   $links = $variables['links'];
   $networks = $variables['networks'];
   $output = '<div class="follow-links clear-block">';
@@ -365,12 +365,12 @@ function _follow_block_config_links($uid
  */
  function follow_links_form($form, &$form_state, $uid = 0) {
   $form = array();
-
+  $form['#theme'] = 'follow_links_form';
   $form['uid'] = array('#type' => 'hidden', '#value' => $uid);
   $form['follow_links']['#tree'] = TRUE;
 
   $links = follow_links_load($uid);
-  $networks = follow_networks_load(TRUE);
+  $networks = follow_networks_load($uid, TRUE);
 
   // Put all our existing links at the top, sorted by weight.
   if (is_array($links)) {
@@ -384,6 +384,7 @@ function _follow_block_config_links($uid
   // Now add all the empty ones.
   foreach ($networks as $name => $title) {
     $link = new stdClass();
+    $link->name = $name;
     $form['follow_links'][$name] = _follow_links_form_link($link, $title);
   }
 
@@ -399,8 +400,7 @@ function _follow_links_form_link($link, 
   $elements = array();
 
   $elements['name'] = array(
-    '#type' => 'markup',
-    '#value' => $title,
+    '#markup' => $title,
   );
   if (isset($link->lid)) {
     $elements['lid'] = array(
@@ -415,6 +415,7 @@ function _follow_links_form_link($link, 
   $elements['url'] = array(
     '#type' => 'textfield',
     '#default_value' => isset($link->url) ? $link->url : '',
+    '#network' => $link->name,
     '#element_validate' => array('follow_url_validate'),
   );
 
@@ -426,12 +427,46 @@ function _follow_links_form_link($link, 
  */
 function follow_url_validate($form) {
   $url = trim($form['#value']);
-  if($url && !preg_match("/^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i", $url)) {
+  $regex = follow_build_url_regex($form['#network']);
+  if($url && !preg_match($regex, $url)) {
     form_error($form, t('The specified url is invalid.'));
   }
 }
 
 /**
+ * Build a regex to validate the url based on a know service url.
+ */
+function follow_build_url_regex($network) {
+  static $url_map;
+
+  if (!isset($url_map)) {
+    $url_map = array(
+      'facebook'  => 'facebook.com',
+      'virb'      => 'virb.com',
+      'myspace'   => 'myspace.com',
+      'twitter'   => 'twitter.com',
+      'picasa'    => 'picasaweb.google.com',
+      'flickr'    => 'flickr.com',
+      'youtube'   => 'youtube.com',
+      'vimeo'     => 'vimeo.com',
+      'bliptv'    => 'blip.tv',
+      'lastfm'    => 'last.fm',
+      'linkedin'  => 'linkedin.com',
+      'delicious' => 'delicious.com',
+      'tumblr'    => 'tumblr.com',
+      'self'      => '',
+    );
+    drupal_alter('follow_networks_urls', $url_map);
+  }
+  $regex = '@^';
+  if (!empty($url_map[$network])) {
+    $regex .= 'https?://[a-z0-9\-_.]+' . str_replace('.', '\\.', $url_map[$network]);
+  }
+  $regex .= '[A-Za-z0-9./%&=\?\-_]+$@i';
+  return $regex;
+}
+
+/**
  * Submit handler for the follow_links_form.
  */
 function follow_links_form_submit($form, &$form_state) {
@@ -575,7 +610,6 @@ function follow_link_delete($lid) {
     ->execute();
 }
 
-
 /**
  * Loads all follow networks
  *
@@ -585,29 +619,22 @@ function follow_link_delete($lid) {
  * @return
  *   An array of network names, keys are machine names, values are visible titles.
  */
-function follow_networks_load($reset = FALSE) {
+function follow_networks_load($uid, $reset = FALSE) {
   static $networks = array();
 
   // Clear cache if $reset is TRUE;
   if ($reset) {
     $networks = array();
-    cache_clear_all('follow:networks', 'cache');
   }
   // Return presets if the array is populated.
-  if (!empty($networks)) {
-    return $networks;
+  if (empty($networks[$uid])) {
+    // We don't have an API to create new networks yet, so for now, we only
+    // call hook_follow_networks_alter().
+    $networks[$uid] = follow_default_networks($uid);
+    drupal_alter('follow_networks', $networks, $uid);
   }
 
-  // Grab from cache or build the array of networks.
-  if (($cache = cache_get('follow:networks', 'cache')) && is_array($cache->data)) {
-    $networks = $cache->data;
-  }
-  else {
-    // We don't have an API to create new networks yet, so for now, we only call hook_follow_networks().
-    $networks = module_invoke_all('follow_networks');
-    cache_set('follow:networks', $networks);
-  }
-  return $networks;
+  return $networks[$uid];
 }
 
 /**
@@ -616,8 +643,8 @@ function follow_networks_load($reset = F
  * @return
  *   An array of network names, keys are machine names, values are visible titles.
  */
-function follow_follow_networks() {
-  return array(
+function follow_default_networks($uid) {
+  $networks = array(
     'facebook'  => t('Facebook'),
     'virb'      => t('Virb'),
     'myspace'   => t('MySpace'),
@@ -632,4 +659,8 @@ function follow_follow_networks() {
     'delicious' => t('Delicious'),
     'tumblr'    => t('Tumblr'),
   );
+  if ($uid == 0) {
+    $networks['self'] = t('This site (RSS)');
+  }
+  return $networks;
 }
