
--- a/sites/all/modules/cumulus/cumulus.module	Sun Sep 06 11:54:52 2009 +0200
+++ b/sites/all/modules/cumulus/cumulus.module	Sun Sep 13 10:33:28 2009 +0200
@@ -19,34 +19,39 @@
  * Implementation of hook_block().
  */
 function cumulus_block($op = 'list', $delta = 0, $edit = array()) {
+  $multi_id = isset($edit['multiblock_delta']) ? '_'. $edit['multiblock_delta']['#value'] : NULL;
+
   switch ($op) {
     case 'list':
       $blocks[0]['info'] = t('Cumulus Tag Cloud');
       $blocks[0]['cache'] = BLOCK_NO_CACHE;
       return $blocks;
 
+    case 'mb_enabled':
+      return 'mb_enabled';
+
     case 'configure':
-      return cumulus_block_configure();
+      return cumulus_block_configure($multi_id);
 
     case 'save':
-      variable_set('cumulus_vid', $edit['vid']);
-      variable_set('cumulus_tagadelic_step', $edit['tagadelic_step']);
-      variable_set('cumulus_tagadelic_limit', $edit['tagadelic_limit']);
-      variable_set('cumulus_flash_width', $edit['flash_width']);
-      variable_set('cumulus_flash_height', $edit['flash_height']);
-      variable_set('cumulus_flash_background', $edit['flash_background']);
-      variable_set('cumulus_flash_transparency', $edit['flash_transparency']);
-      variable_set('cumulus_flash_color', $edit['flash_color']);
-      variable_set('cumulus_flash_color2', $edit['flash_color2']);
-      variable_set('cumulus_flash_hicolor', $edit['flash_hicolor']);
-      variable_set('cumulus_flash_speed', $edit['flash_speed']);
-      variable_set('cumulus_flash_distribute', $edit['flash_distribute']);
-      variable_set('cumulus_flash_font_size', $edit['flash_font_size']);
-      variable_set('cumulus_flash_font_size_interval', $edit['flash_font_size_interval']);
+      variable_set('cumulus_vid' . $multi_id, $edit['vid']);
+      variable_set('cumulus_tagadelic_step' . $multi_id, $edit['tagadelic_step']);
+      variable_set('cumulus_tagadelic_limit' . $multi_id, $edit['tagadelic_limit']);
+      variable_set('cumulus_flash_width' . $multi_id, $edit['flash_width']);
+      variable_set('cumulus_flash_height' . $multi_id, $edit['flash_height']);
+      variable_set('cumulus_flash_background' . $multi_id, $edit['flash_background']);
+      variable_set('cumulus_flash_transparency' . $multi_id, $edit['flash_transparency']);
+      variable_set('cumulus_flash_color' . $multi_id, $edit['flash_color']);
+      variable_set('cumulus_flash_color2' . $multi_id, $edit['flash_color2']);
+      variable_set('cumulus_flash_hicolor' . $multi_id, $edit['flash_hicolor']);
+      variable_set('cumulus_flash_speed' . $multi_id, $edit['flash_speed']);
+      variable_set('cumulus_flash_distribute' . $multi_id, $edit['flash_distribute']);
+      variable_set('cumulus_flash_font_size' . $multi_id, $edit['flash_font_size']);
+      variable_set('cumulus_flash_font_size_interval' . $multi_id, $edit['flash_font_size_interval']);
       return;
 
     case 'view':
-      $vocs = variable_get('cumulus_vid', 1);
+      $vocs = variable_get('cumulus_vid' . $multi_id, 1);
       if (is_numeric($vocs)) {
         $vocs = array($vocs);
       }
@@ -56,7 +61,7 @@
       else {
         $vocs = array(1);
       }
-      $tags = tagadelic_get_weighted_tags($vocs, variable_get('cumulus_tagadelic_step', 6), variable_get('cumulus_tagadelic_limit', 24));
+      $tags = tagadelic_get_weighted_tags($vocs, variable_get('cumulus_tagadelic_step' . $multi_id, 6), variable_get('cumulus_tagadelic_limit' . $multi_id, 24));
       $tags = tagadelic_sort_tags($tags);
       $tags_formatted_flash = theme('cumulus_weighted', $tags);
       $tags_formatted_alt = theme('tagadelic_weighted', $tags);
@@ -68,47 +73,58 @@
       else {
         drupal_set_message(t('The file @folder is missing. Please download it from !link, and add it to the Cumulus module folder!', array('@folder' => $js, '!link' => l('http://pratul.in/files/cumulus.js', 'http://pratul.in/files/cumulus.js'))), 'error');
       }
-      if (!(variable_get('cumulus_vid', 1))) {
+      if (!(variable_get('cumulus_vid' . $multi_id, 1))) {
         drupal_set_message(t('You haven\'t yet configured and saved the Cumulus settings on !link. Cumulus might not work properly!', array('!link' => l('your blocks configuration page', 'admin/build/block/configure/cumulus/0'))), 'warning');
       }
       // Flash params
       $param = array(
         'path_to_flash' => base_path() . drupal_get_path('module', 'cumulus') .'/cumulus.swf',
-        'width' => variable_get('cumulus_flash_width', 1),
-        'height' => variable_get('cumulus_flash_height', 1),
-        'background' => variable_get('cumulus_flash_background', 'ffffff'),
-        'color' => '0x'. variable_get('cumulus_flash_color', '000000'),
-        'color2' => '0x'. variable_get('cumulus_flash_color2', 'ff0000'),
-        'hicolor' => '0x'. variable_get('cumulus_flash_hicolor', '666666'),
-        'speed' => variable_get('cumulus_flash_speed', 220),
-        'distribute' => variable_get('cumulus_flash_distribute', 'true'),
+        'width' => variable_get('cumulus_flash_width' . $multi_id, 1),
+        'height' => variable_get('cumulus_flash_height' . $multi_id, 1),
+        'background' => '0x'. variable_get('cumulus_flash_background' . $multi_id, 'ffffff'),
+        'color' => '0x'. variable_get('cumulus_flash_color' . $multi_id, '000000'),
+        'color2' => '0x'. variable_get('cumulus_flash_color2' . $multi_id, 'ff0000'),
+        'hicolor' => '0x'. variable_get('cumulus_flash_hicolor' . $multi_id, '666666'),
+        'speed' => variable_get('cumulus_flash_speed' . $multi_id, 220),
+        'distribute' => variable_get('cumulus_flash_distribute' . $multi_id, 'true'),
       );
-      if (variable_get('cumulus_flash_transparency', 'false') == 'true' ) {
-        $param['transparency'] = 'widget_so.addParam("wmode", "transparent");';
+      if (variable_get('cumulus_flash_transparency' . $multi_id, 'false') == 'true' ) {
+        $param['transparency'] = 'wmode: "transparent",';
       }
       // link to view with additional tags
-      $links['more'] = l(t('more tags'), 'tagadelic/chunk/'. variable_get('cumulus_vid', 1));
+      $links['more'] = l(t('more tags'), 'tagadelic/chunk/'. variable_get('cumulus_vid' . $multi_id, 1));
       // output content
       $blocks['subject'] = t('Cumulus Tag Cloud');
-      // param with value 9 indicates required version of flash player - see http://blog.deconcept.com/swfobject/
+      // param with value 9 indicates required version of flash player - see http://code.google.com/p/swfobject/ 
+      $inline_js = <<<EOT
+var rnumber = Math.floor(Math.random()*9999999);
+var flashvars{$multi_id} = {
+  tcolor: {$param['color']},
+  tcolor2: {$param['color2']},
+  hicolor: {$param['hicolor']},
+  tspeed: {$param['speed']},
+  distr: {$param['distribute']},
+  mode: "tags",
+ tagcloud: "{$tags_formatted_flash}"
+};
+var params{$multi_id} = {
+  {$param['transparency']}
+  allowScriptAccess: "always",
+  bgcolor: {$param['background']}
+};
+var attributes{$multi_id} = {
+  id: 'dynamicTags{$multi_id}',
+  name: 'dynamicTags{$multi_id}'
+};
+
+swfobject.embedSWF("{$param['path_to_flash']}?r="+rnumber, "tags{$multi_id}", "{$param['width']}", "{$param['height']}", "9", false, flashvars{$multi_id}, params{$multi_id}, attributes{$multi_id});
+EOT;
+      drupal_add_js($inline_js, 'inline', 'header', FALSE, FALSE,FALSE);
+
       $blocks['content'] = <<<EOT
-        <div id="tags">
+        <div id="tags{$multi_id}">
         {$tags_formatted_alt}
-        <script type="text/javascript">
-          var rnumber = Math.floor(Math.random()*9999999);
-          var widget_so = new SWFObject("{$param['path_to_flash']}?r="+rnumber, "cumulusflash", "{$param['width']}", "{$param['height']}", "9", "{$param['background']}");
-          {$param['transparency']}
-          widget_so.addParam("allowScriptAccess", "always");
-          widget_so.addVariable("tcolor", "{$param['color']}");
-          widget_so.addVariable("tcolor2", "{$param['color2']}");
-          widget_so.addVariable("hicolor", "{$param['hicolor']}");
-          widget_so.addVariable("tspeed", "{$param['speed']}");
-          widget_so.addVariable("distr", "{$param['distribute']}");
-          widget_so.addVariable("mode", "tags");
-          widget_so.addVariable("tagcloud", "{$tags_formatted_flash}");
-          widget_so.write("tags");
-        </script>
-        </div>
+	</div>
         <div class="more-link">{$links['more']}</div>
 EOT;
       return $blocks;
@@ -210,53 +226,53 @@
 /**
  * Implementation of hook_configure().
  */
-function cumulus_block_configure() {
+function cumulus_block_configure($multi_id) {
   $form['vid'] = array(
     '#type' => 'textfield',
     '#title' => t('Vocabulary IDs to be included'),
-    '#default_value' => variable_get('cumulus_vid', 1),
+    '#default_value' => variable_get('cumulus_vid' . $multi_id, 1),
     '#maxlength' => 10,
     '#description' => t('The IDs of the vocabularies that will be displayed. Separate the IDs by commas only (eg: 1, 3, 4)'),
   );
   $form['tagadelic_step'] = array(
     '#type' => 'textfield',
     '#title' => t('Tag size interval'),
-    '#default_value' => variable_get('cumulus_tagadelic_step', 6),
+    '#default_value' => variable_get('cumulus_tagadelic_step' . $multi_id, 6),
     '#maxlength' => 2,
     '#description' => t('The number of tag sizes you want to use.'),
   );
   $form['tagadelic_limit'] = array(
     '#type' => 'textfield',
     '#title' => t('Number of tags to display'),
-    '#default_value' => variable_get('cumulus_tagadelic_limit', 24),
+    '#default_value' => variable_get('cumulus_tagadelic_limit' . $multi_id, 24),
     '#maxlength' => 2,
     '#description' => t('The maximum number of tags that will be displayed.'),
   );
   $form['flash_width'] = array(
     '#type' => 'textfield',
     '#title' => t('Width of cumulus'),
-    '#default_value' => variable_get('cumulus_flash_width', 200),
+    '#default_value' => variable_get('cumulus_flash_width' . $multi_id, 200),
     '#maxlength' => 3,
     '#description' => t('The width of the cumulus in pixels.'),
   );
   $form['flash_height'] = array(
     '#type' => 'textfield',
     '#title' => t('Height of cumulus'),
-    '#default_value' => variable_get('cumulus_flash_height', 150),
+    '#default_value' => variable_get('cumulus_flash_height' . $multi_id, 150),
     '#maxlength' => 3,
     '#description' => t('The height of the cumulus in pixels.'),
   );
   $form['flash_background'] = array(
     '#type' => 'textfield',
     '#title' => t('Background color of cumulus'),
-    '#default_value' => variable_get('cumulus_flash_background', 'ffffff'),
+    '#default_value' => variable_get('cumulus_flash_background' . $multi_id, 'ffffff'),
     '#maxlength' => 6,
     '#description' => t('The hex color value for the background of the cumulus. E.g. ffffff. If "Background transparency" is enabled, this option will have no effect.'),
   );
   $form['flash_transparency'] = array(
     '#type' => 'select',
     '#title' => t('Background transparency'),
-    '#default_value' => variable_get('cumulus_flash_transparency', 'false'),
+    '#default_value' => variable_get('cumulus_flash_transparency' . $multi_id, 'false'),
     '#options' => array(
       'false' => t('no'),
       'true' => t('yes'),
@@ -266,35 +282,35 @@
   $form['flash_color'] = array(
     '#type' => 'textfield',
     '#title' => t('Font color of cumulus'),
-    '#default_value' => variable_get('cumulus_flash_color', 'ff0000'),
+    '#default_value' => variable_get('cumulus_flash_color' . $multi_id, 'ff0000'),
     '#maxlength' => 6,
     '#description' => t('The hex color value you would like to use for the tags. E.g. 000000.'),
   );
   $form['flash_color2'] = array(
     '#type' => 'textfield',
     '#title' => t('Second font color of cumulus'),
-    '#default_value' => variable_get('cumulus_flash_color2', '000000'),
+    '#default_value' => variable_get('cumulus_flash_color2' . $multi_id, '000000'),
     '#maxlength' => 6,
     '#description' => t('Second tag color. If supplied, tags will get a color from a gradient between both colors based on their popularity.'),
   );
   $form['flash_hicolor'] = array(
     '#type' => 'textfield',
     '#title' => t('Highlight color of cumulus'),
-    '#default_value' => variable_get('cumulus_flash_hicolor', '666666'),
+    '#default_value' => variable_get('cumulus_flash_hicolor' . $multi_id, '666666'),
     '#maxlength' => 6,
     '#description' => t('The hex color value you would like to use for the tag mouseover/hover color'),
   );
   $form['flash_speed'] = array(
     '#type' => 'textfield',
     '#title' => t('Rotation speed'),
-    '#default_value' => variable_get('cumulus_flash_speed', 100),
+    '#default_value' => variable_get('cumulus_flash_speed' . $multi_id, 100),
     '#maxlength' => 3,
     '#description' => t('Set the speed of the cumulus. Options between 25 and 500 work best.'),
   );
   $form['flash_distribute'] = array(
     '#type' => 'select',
     '#title' => t('Distribute tags evenly on cumulus'),
-    '#default_value' => variable_get('cumulus_flash_distribute', 'true'),
+    '#default_value' => variable_get('cumulus_flash_distribute' . $multi_id, 'true'),
     '#options' => array(
       'false' => t('no'),
       'true' => t('yes'),
@@ -304,16 +320,16 @@
   $form['flash_font_size'] = array(
     '#type' => 'textfield',
     '#title' => t('Font size'),
-    '#default_value' => variable_get('cumulus_flash_font_size', 10),
+    '#default_value' => variable_get('cumulus_flash_font_size' . $multi_id, 10),
     '#maxlength' => 2,
     '#description' => t('Set the font size of the tag with the lowest tag-size in pixels (level 1).'),
   );
   $form['flash_font_size_interval'] = array(
     '#type' => 'textfield',
     '#title' => t('Font size interval'),
-    '#default_value' => variable_get('cumulus_flash_font_size_interval', 2),
+    '#default_value' => variable_get('cumulus_flash_font_size_interval' . $multi_id, 2),
     '#maxlength' => 1,
     '#description' => t('Set the font size interval used for the different tag-sizes (level 2 and higher).'),
   );
   return $form;
-}
\ No newline at end of file
+}




