? nbproject
? views_attach-399648.patch
Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views_attach/README.txt,v
retrieving revision 1.1
diff -u -p -r1.1 README.txt
--- README.txt	13 Jan 2009 08:07:10 -0000	1.1
+++ README.txt	27 Apr 2009 10:37:26 -0000
@@ -21,6 +21,7 @@ REQUIREMENTS
 
 - Drupal 6
 - Views 2
+- Token
 
 AUTHOR AND CREDIT
 
@@ -29,3 +30,6 @@ Jeff Eaton "eaton" (http://drupal.org/us
 
 Maintainer:
 Larry Garfield "Crell" (http://drupal.org/user/26398)
+
+Token integration:
+Alexander Makarov "Sam Dark" (http://drupal.org/user/281132)
\ No newline at end of file
Index: views_attach.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views_attach/views_attach.info,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 views_attach.info
--- views_attach.info	20 Jan 2009 21:19:48 -0000	1.1.2.1
+++ views_attach.info	27 Apr 2009 10:37:26 -0000
@@ -3,4 +3,12 @@ name = Views attach
 description = Provides new Views display types that can be attached to nodes or users. 
 core = 6.x
 dependencies[] = views
+dependencies[] = token
 package = Views
+
+; Information added by drupal.org packaging script on 2009-02-23
+version = "6.x-1.x-dev"
+core = "6.x"
+project = "views_attach"
+datestamp = "1235348398"
+
Index: views_attach.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views_attach/views_attach.module,v
retrieving revision 1.1.2.7
diff -u -p -r1.1.2.7 views_attach.module
--- views_attach.module	22 Feb 2009 23:05:36 -0000	1.1.2.7
+++ views_attach.module	27 Apr 2009 10:37:26 -0000
@@ -50,7 +50,21 @@ function views_attach_user($op, &$edit, 
       foreach ($views as $info) {
         $view = views_get_view($info['name']);
         $view->set_display($info['display']);
-        $args = $view->display_handler->get_option('default_argument') === 'uid' ? array($account->uid) : array();
+
+		//TODO: check
+		// we will need taxonomy and cck for sure
+		$token_string = $view->display_handler->get_option('default_argument');
+
+		$user = user_load($account->uid);
+
+		if($user){
+			$args = views_attach_get_arguments_from_token_string($token_string, 'user', $user);
+		}
+		else {
+			//TODO: is this possible not to get user by $account->uid?
+			$args = array();
+		}
+
         $result = $view->execute_display($info['display'], $args);
         if (!empty($result)) {
           $account->content[$view->name . '_' . $info['display']] = array(
@@ -91,7 +105,12 @@ function views_attach_nodeapi(&$node, $o
       foreach ($views as $info) {
         $view = views_get_view($info['name']);
         $view->set_display($info['display']);
-        $args = $view->display_handler->get_option('default_argument') === 'nid' ? array($node->nid) : array();
+
+		//TODO: check
+		$token_string = $view->display_handler->get_option('default_argument');
+
+		$args = views_attach_get_arguments_from_token_string($token_string, 'node', $node);
+
         $result = $view->execute_display($info['display'], $args);
         if (!empty($result)) {
           // This is not really a form item, but by using item here we get
@@ -220,4 +239,50 @@ function views_attach_build_modes() {
     );
   }
   return $modes;
+}
+
+/**
+ * Get view arguments array from string that contains tokens
+ *
+ * @param $string
+ *   The token string defined by the view.
+ * @param $type
+ *   The token type.
+ * @param $object
+ *   The object being used for replacement data (typically a node).
+ * @return
+ *   An array of argument values.
+ *
+ * @todo: security?
+ */
+function views_attach_get_arguments_from_token_string($string, $type, $object) {
+	$args = trim($string);
+
+  if (empty($args)) {
+    return array();
+  }
+		
+	$args = token_replace($args, $type, $object);
+	return explode('/', $args);
+}
+
+/**
+ * Get the proper node type data based on the base table.
+ *
+ * @param $base_table
+ *   A string representing the base table of the view.
+ * @return
+ *   A string indicating the token type for this table.
+ */
+function views_attach_get_token_type($base_table) {
+  // TODO: add other object types?
+  switch ($base_table) {
+    case 'users':
+      $token_type = 'user';
+      break;
+    default:
+      $token_type = 'node';
+      break;
+   }
+   return $token_type;
 }
\ No newline at end of file
Index: views_attach_plugin_display_node_content.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views_attach/views_attach_plugin_display_node_content.inc,v
retrieving revision 1.1.2.7
diff -u -p -r1.1.2.7 views_attach_plugin_display_node_content.inc
--- views_attach_plugin_display_node_content.inc	22 Feb 2009 23:05:36 -0000	1.1.2.7
+++ views_attach_plugin_display_node_content.inc	27 Apr 2009 10:37:26 -0000
@@ -10,7 +10,7 @@ class views_attach_plugin_display_node_c
 
     $options['types'] = array('default' => array());
     $options['modes'] = array('default' => array('full'));
-    $options['default_argument'] = array('default' => 'nid');
+    $options['default_argument'] = array('default' => '');
     $options['show_title'] = 0;
 
     return $options;
@@ -57,11 +57,12 @@ class views_attach_plugin_display_node_c
       $weight = 10;
     }
 
+	//TODO: rename "argument" to "arguments string"?
     $default_argument = $this->get_option('default_argument');
     $options['default_argument'] = array(
       'category' => 'node_content',
       'title' => t('Default argument'),
-      'value' => empty($default_argument) ? t('None') : $default_argument,
+      'value' => empty($default_argument) ? t('None') : check_plain($default_argument),
     );
 
     $options['show_title'] = array(
@@ -103,12 +104,17 @@ class views_attach_plugin_display_node_c
 
       case 'default_argument':
         $form['#title'] .= t('Default argument');
-        $form['default_argument'] = array(
-          '#type' => 'checkbox',
-          '#title' => t('Provide the current node id as a default argument.'),
-          '#default_value' => $this->get_option('default_argument') === 'nid',
-          '#return_value' => 'nid',
+		$form['default_argument'] = array(
+          '#type' => 'textfield',
+          '#default_value' => $this->get_option('default_argument'),
+          '#description' => t('Separate arguments with "/".'),
         );
+        // Add the token help to the form.
+        if ($token_type = views_attach_get_token_type($form_state['view']->base_table)) {
+		$form['help'] = array(
+            '#value' => t('You may use token replacement to provide arguments based on the node. Token replacements require that NID is the first argument of the URL for the view.') . theme('token_help', $token_type),
+		);
+        }
         break;
 
       case 'show_title':
@@ -143,6 +149,29 @@ class views_attach_plugin_display_node_c
   }
 
   /**
+   * We have to run token replacement before the arguments are used.
+   */
+   function pre_execute() {
+     $args = $this->view->args;
+     $token_string = $this->view->display_handler->get_option('default_argument');
+     if (empty($args) || empty($token_string)) {
+       return;
+     }
+     $node_types = $this->view->display_handler->get_option('types');
+
+     $node = node_load($args[0]);
+     if (!in_array($node->type, $node_types)) {
+       return;
+     }
+      // Now do the token replacement.
+
+     $token_type = views_attach_get_token_type($this->view->base_table);
+     $new_args = views_attach_get_arguments_from_token_string($token_string, $token_type, $node);
+  
+     $this->view->args = $new_args;
+   }
+
+  /**
    * The display block handler returns the structure necessary for a block.
    */
   function execute() {
Index: views_attach_plugin_display_profile.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views_attach/views_attach_plugin_display_profile.inc,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 views_attach_plugin_display_profile.inc
--- views_attach_plugin_display_profile.inc	13 Feb 2009 17:14:26 -0000	1.1.2.1
+++ views_attach_plugin_display_profile.inc	27 Apr 2009 10:37:26 -0000
@@ -10,7 +10,7 @@ class views_attach_plugin_display_profil
 
     $options['weight'] = array('default' => 10);
     $options['category'] = array('default' => NULL);
-    $options['default_argument'] = array('default' => 'uid');
+    $options['default_argument'] = array('default' => '');
 
     return $options;
   }
@@ -50,10 +50,11 @@ class views_attach_plugin_display_profil
       'value' => $weight,
     );
 
+    $default_argument = $this->get_option('default_argument');
     $options['default_argument'] = array(
       'category' => 'profile',
       'title' => t('Default argument'),
-      'value' => $this->get_option('default_argument') === 'uid' ? t('Yes') : t('No'),
+      'value' => empty($default_argument) ? t('None') : check_plain($default_argument),
     );
   }
 
@@ -84,11 +85,16 @@ class views_attach_plugin_display_profil
       case 'default_argument':
         $form['#title'] .= t('Default argument');
         $form['default_argument'] = array(
-          '#type' => 'checkbox',
-          '#title' => t("Provide the current user id as a default argument."),
-          '#default_value' => $this->get_option('default_argument') === 'uid',
-          '#return_value' => 'uid',
+          '#type' => 'textfield',
+          '#default_value' => $this->get_option('default_argument'),
+          '#description' => t('Separate arguments with "/".'),
+        );
+        // Add the token help to the form.
+        if ($token_type = views_attach_get_token_type($form_state['view']->base_table)) {
+          $form['help'] = array(
+            '#value' => '<p>'. t('You may use token replacement to provide arguments based on the user. Token replacements require that UID is the first argument of the URL for the view.') .'</p>'. theme('token_help', $token_type),
         );
+        }
         break;
     }
   }
@@ -110,6 +116,25 @@ class views_attach_plugin_display_profil
   }
 
   /**
+   * We have to run token replacement before the arguments are used.
+   */
+   function pre_execute() {
+     $args = $this->view->args;
+     $token_string = $this->view->display_handler->get_option('default_argument');
+     if (empty($args) || empty($token_string)) {
+       return;
+     }
+
+     $user = user_load($args[0]);
+
+      // Now do the token replacement.
+     $token_type = views_attach_get_token_type($this->view->base_table);
+     $new_args = views_attach_get_arguments_from_token_string($token_string, $token_type, $user);
+  
+     $this->view->args = $new_args;
+   }
+
+  /**
    * The display block handler returns the structure necessary for a block.
    */
   function execute() {
