Index: views_argument_api.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_argument_api/views_argument_api.install,v retrieving revision 1.1 diff -u -r1.1 views_argument_api.install --- views_argument_api.install 11 Jun 2007 20:39:32 -0000 1.1 +++ views_argument_api.install 11 Jul 2007 05:16:35 -0000 @@ -8,41 +8,42 @@ switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': - $r = db_query("CREATE TABLE {views_argument_api} ( - view varchar(32) NOT NULL default '0', - argid varchar(32) NOT NULL default '0', - element varchar(32) NOT NULL default '0' - ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); - break; - $r2 = db_query("CREATE TABLE {views_argument_api_args} ( - api_id varchar(32) NOT NULL default '0', - api_values longtext - ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); + $r = db_query("CREATE TABLE {views_argument_api} ( + view varchar(32) NOT NULL default '0', + argid varchar(32) NOT NULL default '0', + element varchar(32) NOT NULL default '0' + ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); + break; + $r2 = db_query("CREATE TABLE {views_argument_api_args} ( + api_id varchar(32) NOT NULL default '0', + api_values longtext + ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); case 'pgsql': $r = db_query("CREATE TABLE {views_argument_api} ( - view varchar(32) NOT NULL default '0', - argid varchar(32) NOT NULL default '0', - element varchar(32) NOT NULL default '0' - )"); + view varchar(32) NOT NULL default '0', + argid varchar(32) NOT NULL default '0', + element varchar(32) NOT NULL default '0' + )"); $r2 = db_query("CREATE TABLE {views_argument_api_args} ( - api_id varchar(32) NOT NULL default '0', - api_values longtext - )"); + api_id varchar(32) NOT NULL default '0', + api_values longtext + )"); break; } - $weight = db_result(db_query_range("SELECT s.weight FROM {system} s ORDER BY s.weight ASC", 0, 1)); + $weight = db_result(db_query_range("SELECT s.weight FROM {system} s ORDER BY s.weight ASC", 0, 1)); $weight = empty($weight) ? 0 : $weight - 1; - $r3 = db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", $weight, 'views_argument_api'); + $r3 = db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", $weight, 'views_argument_api'); - if($r && $r2) { + if ($r && $r2) { drupal_set_message(t("Views Argument API tables created successfully.")); - } else { - drupal_set_message(t('Views Argument API tables could not be created.'), 'error'); + } + else { + drupal_set_message(t('Views Argument API tables could not be created.'), 'error'); } - if($r3) { + if ($r3) { drupal_set_message(t("Views Argument API module weight moved to the top")); } @@ -52,7 +53,7 @@ * Update 1 */ function views_argument_api_update_1() { - views_argument_api_install(); + views_argument_api_install(); } /** * Update 2 @@ -61,22 +62,23 @@ switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': - $r = db_query("CREATE TABLE {views_argument_api_args} ( - api_id varchar(32) NOT NULL default '0', - api_values longtext - ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); - break; + $r = db_query("CREATE TABLE {views_argument_api_args} ( + api_id varchar(32) NOT NULL default '0', + api_values longtext + ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); + break; case 'pgsql': $r = db_query("CREATE TABLE {views_argument_api_args} ( - api_id varchar(32) NOT NULL default '0', - api_values longtext - )"); + api_id varchar(32) NOT NULL default '0', + api_values longtext + )"); break; } - if($r) { - drupal_set_message(t("Views Argument API Arguments table created successfully.")); - } else { - drupal_set_message(t('Views Argument API Arguments table created successfully.'), 'error'); + if ($r) { + drupal_set_message(t("Views Argument API Arguments table created successfully.")); + } + else { + drupal_set_message(t('Views Argument API Arguments table created successfully.'), 'error'); } } @@ -84,17 +86,17 @@ * Update 3 */ function views_argument_api_update_3() { - db_query("ALTER TABLE {views_argument_api} DROP PRIMARY KEY"); + db_query("ALTER TABLE {views_argument_api} DROP PRIMARY KEY"); } /** * Update 4 */ function views_argument_api_update_4() { - $weight = db_result(db_query_range("SELECT s.weight FROM {system} s ORDER BY s.weight ASC", 0, 1)); + $weight = db_result(db_query_range("SELECT s.weight FROM {system} s ORDER BY s.weight ASC", 0, 1)); $weight = empty($weight) ? 0 : $weight - 1; - $r3 = db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", $weight, 'views_argument_api'); + $r3 = db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", $weight, 'views_argument_api'); drupal_set_message(t("Views Argument API module weight moved to the top")); } Index: views_argument_api.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_argument_api/views_argument_api.module,v retrieving revision 1.1.2.1 diff -u -r1.1.2.1 views_argument_api.module --- views_argument_api.module 14 Jun 2007 18:26:23 -0000 1.1.2.1 +++ views_argument_api.module 11 Jul 2007 05:16:35 -0000 @@ -9,82 +9,82 @@ * Implementation of hook_menu(). */ function views_argument_api_menu($may_cache) { - //Include functionality on behalf of core modules. - _views_argument_api_include_core_modules(); - - if(!$may_cache && $_POST['form_id'] == 'views_edit_view') { - $form_values = $_POST['views_argument_api_configure_form']; - $form_values['name'] = $_POST['name']; - $form_values = _views_argument_api_check_plain($form_values); - views_argument_api_form_submit($_POST['form_id'], $form_values); - } + //Include functionality on behalf of core modules. + _views_argument_api_include_core_modules(); + + if (!$may_cache && $_POST['form_id'] == 'views_edit_view') { + $form_values = $_POST['views_argument_api_configure_form']; + $form_values['name'] = $_POST['name']; + $form_values = _views_argument_api_check_plain($form_values); + views_argument_api_form_submit($_POST['form_id'], $form_values); + } } /** * Implementation of hook_xmlrpc(). */ function views_argument_api_xmlrpc() { - - //Include functionality on behalf of core modules. - _views_argument_api_include_core_modules(); + + //Include functionality on behalf of core modules. + _views_argument_api_include_core_modules(); } /** * Implementation of hook_cron(). */ function views_argument_api_cron() { - //Include functionality on behalf of core modules. - _views_argument_api_include_core_modules(); + //Include functionality on behalf of core modules. + _views_argument_api_include_core_modules(); } /** * Implementation of hook_form_alter(). */ function views_argument_api_form_alter($form_id, &$form) { - switch($form_id) { - case 'views_edit_view': - $name = $form['basic-info']['name']['#default_value']; - - //Get all available elements - $elements = views_argument_api_get_elements(); - - foreach($elements as $argid => $element_set) { - foreach($element_set as $key => $element) { - $options[$argid][$key] = $element['label']; - } - } - - if(!empty($name)) { - //Get default values - $default_elements = views_argument_api_get_element_names_by_view($name); - } - - $f = 'views_argument_api_configure_form'; - $form[$f] = array( - '#description' => t('Select the argument form elements you wish to use with this form when passing arguments to block or embedded views.'), - '#type' => 'fieldset', - '#title' => t('Argument API'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#weight' => -1, - '#tree' => TRUE, - '#theme' => 'views_argument_api_configure_form', - ); - foreach($form['argument'] as $key => $element) { - if(is_numeric($key)) { - $argid = $element['id']['#value']; - $title = $form['argument']['add']['id']['#options'][$argid]; - if(isset($options[$argid])) { - $form[$f][$argid] = array( - '#type' => 'select', - '#title' => $title, - '#options' => $options[$argid], - '#default_value' => $default_elements[$argid], - ); - } - } - } - } + switch($form_id) { + case 'views_edit_view': + $name = $form['basic-info']['name']['#default_value']; + + //Get all available elements + $elements = views_argument_api_get_elements(); + + foreach($elements as $argid => $element_set) { + foreach($element_set as $key => $element) { + $options[$argid][$key] = $element['label']; + } + } + + if (!empty($name)) { + //Get default values + $default_elements = views_argument_api_get_element_names_by_view($name); + } + + $f = 'views_argument_api_configure_form'; + $form[$f] = array( + '#description' => t('Select the argument form elements you wish to use with this form when passing arguments to block or embedded views.'), + '#type' => 'fieldset', + '#title' => t('Argument API'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#weight' => -1, + '#tree' => TRUE, + '#theme' => 'views_argument_api_configure_form', + ); + foreach($form['argument'] as $key => $element) { + if (is_numeric($key)) { + $argid = $element['id']['#value']; + $title = $form['argument']['add']['id']['#options'][$argid]; + if (isset($options[$argid])) { + $form[$f][$argid] = array( + '#type' => 'select', + '#title' => $title, + '#options' => $options[$argid], + '#default_value' => $default_elements[$argid], + ); + } + } + } + } } /********************************************************************* @@ -95,77 +95,78 @@ * Handles submission of additional information on the views_edit_view form. * * @param $form_id - * The form ID of the form being submitted. + * The form ID of the form being submitted. */ function views_argument_api_form_submit($form_id, $form_values) { - //Get the view name; - $name = $form_values['name']; - unset($form_values['name']); - //Delete old query results - db_query("DELETE FROM {views_argument_api} WHERE view = '%s'", $name); - - foreach($form_values as $argid => $element) { - db_query("INSERT INTO {views_argument_api} (view, argid, element) VALUES ('%s', '%s', '%s')", $name, $argid, $element); - } + //Get the view name; + $name = $form_values['name']; + unset($form_values['name']); + //Delete old query results + db_query("DELETE FROM {views_argument_api} WHERE view = '%s'", $name); + + foreach($form_values as $argid => $element) { + db_query("INSERT INTO {views_argument_api} (view, argid, element) VALUES ('%s', '%s', '%s')", $name, $argid, $element); + } } /** * Recursively runs check_plain() on arrays * * @param $form_values - * A single value, an array of values, or a multi-dimensional array of values. + * A single value, an array of values, or a multi-dimensional array of values. * @return - * The array, having each value been run through check_plain(). + * The array, having each value been run through check_plain(). */ function _views_argument_api_check_plain($form_values) { - if(is_array($form_values)) { - foreach($form_values as $key => $value) { - $form_values[$key] = _views_argument_api_check_plain($value); - } - return $form_values; - } else { - return check_plain($form_values); - } + if (is_array($form_values)) { + foreach($form_values as $key => $value) { + $form_values[$key] = _views_argument_api_check_plain($value); + } + return $form_values; + } + else { + return check_plain($form_values); + } } /** * Includes views argument api functionality for core modules. */ function _views_argument_api_include_core_modules() { - $path = drupal_get_path('module', 'views_argument_api'); - $dirpath = "$path/modules"; - $dh = opendir($dirpath); - while (false !== ($file = readdir($dh))) { - if (!is_dir("$dirpath/$file")) { - if(substr($file, -4, 4) == ".inc") { - require_once("$dirpath/$file"); - } - } - } - closedir($dh); + $path = drupal_get_path('module', 'views_argument_api'); + $dirpath = "$path/modules"; + $dh = opendir($dirpath); + while (false !== ($file = readdir($dh))) { + if (!is_dir("$dirpath/$file")) { + if (substr($file, -4, 4) == ".inc") { + require_once("$dirpath/$file"); + } + } + } + closedir($dh); } /********************************************************************* * Theme Functions */ function theme_views_argument_api_configure_form(&$form) { - foreach (element_children($form) as $key) { - $row = array(); - $row['title'] = $form[$key]['#title']; - $form[$key]['#title'] = NULL; - - $row['element'] = drupal_render($form[$key]); - - $rows[] = $row; - $row = array(); - } - - if(!empty($rows)) { - return theme('table', array(t('Argument'), t('Form element to use')), $rows); - } else { - return drupal_render($form); - } - + foreach (element_children($form) as $key) { + $row = array(); + $row['title'] = $form[$key]['#title']; + $form[$key]['#title'] = NULL; + + $row['element'] = drupal_render($form[$key]); + + $rows[] = $row; + $row = array(); + } + + if (!empty($rows)) { + return theme('table', array(t('Argument'), t('Form element to use')), $rows); + } + else { + return drupal_render($form); + } } /********************************************************************* @@ -181,7 +182,7 @@ /** * @file - * Provides the API for the views_argument_api module. This file is + * Provides the API for the views_argument_api module. This file is * supposed to be a collection of useful public access functions for * other modules that want to lean on this module. */ @@ -190,36 +191,38 @@ * Returns an array of form element names for a particular view. * * @param $name - * A view name + * A view name * @return - * An array of form element names. + * An array of form element names. */ function views_argument_api_get_element_names_by_view($name) { - $qs = db_query("SELECT * FROM {views_argument_api} v WHERE v.view = '%s'", $name); - while($obj = db_fetch_object($qs)) { - $elements[$obj->argid] = $obj->element; - } - - return $elements; + $qs = db_query("SELECT * FROM {views_argument_api} v WHERE v.view = '%s'", $name); + $elements = array(); + while($obj = db_fetch_object($qs)) { + $elements[$obj->argid] = $obj->element; + } + + return $elements; } /** * Get all elements currently assigned to a specific view. * * @param $name - * A view name. + * A view name. * @return - * An array of elements, keyed by argid. + * An array of elements, keyed by argid. */ function views_argument_api_get_elements_by_view($name) { - $elements = views_argument_api_get_elements(); - $view_elements_chosen = views_argument_api_get_element_names_by_view($name); - - foreach($view_elements_chosen as $key => $chosen_element) { - $return[$key] = $elements[$key][$chosen_element]; - } - - return $return; + $elements = views_argument_api_get_elements(); + $view_elements_chosen = views_argument_api_get_element_names_by_view($name); + $return = array(); + + foreach($view_elements_chosen as $key => $chosen_element) { + $return[$key] = $elements[$key][$chosen_element]; + } + + return $return; } /** @@ -231,56 +234,58 @@ * returns just the form values related to the API, keyed by argument ID. * * @param $view_name - * A unique view name. + * A unique view name. * @param $form_values - * An array of form values, as would be passed to a form validation or + * An array of form values, as would be passed to a form validation or * form submission function. * @return - * An array of form values that come from form elements generated by this + * An array of form values that come from form elements generated by this * API. */ function views_argument_api_get_api_form_values($view_name, $form_values) { - $elements = views_argument_api_get_elements_by_view($view_name); - foreach($elements as $argid => $element) { - $return[$argid] = $form_values[$argid]; - } - - return $return; + $elements = views_argument_api_get_elements_by_view($view_name); + $return = array(); + foreach($elements as $argid => $element) { + $return[$argid] = $form_values[$argid]; + } + + return $return; } /** * Call all modules to get their exposed form element information. * * @return - * An array of elements. + * An array of elements. */ function views_argument_api_get_elements() { - //See if the elements are cached, and return the cached version if they are. - if($cached = cache_get('views_argument_api_elements_all', 'cache')) { - return unserialize($cached->data); - } - - foreach(module_implements('views_argument_api_argument_elements') as $module) { - $module_elements = array(); - $func = $module . '_views_argument_api_argument_elements'; - $module_elements = $func(); - foreach($module_elements as $argid => $set) { - foreach($set as $element) { - $elements[$argid][$module . '_' . $element['name']] = array( - 'name' => $module . '_' . $element['name'], - 'label' => $element['label'], - 'handler' => $element['handler'], - 'callback arguments' => $element['callback arguments'], - 'element' => $element['element'], - ); - } - } + //See if the elements are cached, and return the cached version if they are. + if ($cached = cache_get('views_argument_api_elements_all', 'cache')) { + return unserialize($cached->data); + } + + $elements = array(); + foreach(module_implements('views_argument_api_argument_elements') as $module) { + $module_elements = array(); + $func = $module . '_views_argument_api_argument_elements'; + $module_elements = $func(); + foreach($module_elements as $argid => $set) { + foreach($set as $element) { + $elements[$argid][$module . '_' . $element['name']] = array( + 'name' => $module . '_' . $element['name'], + 'label' => $element['label'], + 'handler' => $element['handler'], + 'callback arguments' => $element['callback arguments'], + 'element' => $element['element'], + ); + } + } - } + } - //Cache the element data - cache_set('views_argument_api_elements_all', 'cache', serialize($elements), CACHE_PERMANENT); + //Cache the element data + cache_set('views_argument_api_elements_all', 'cache', serialize($elements), CACHE_PERMANENT); - return $elements; + return $elements; } /********************************************************************* @@ -291,35 +296,36 @@ * Builds a form for handling views arguments for a specific view. * * @param $name - * A view name. + * A view name. * @return - * An array of form elements. + * An array of form elements. */ function views_argument_api_build_argument_form($name) { - $elements = views_argument_api_get_elements_by_view($name); - foreach($elements as $argid => $element) { - $form[$argid] = $element['element']; - } - - return $form; + $elements = views_argument_api_get_elements_by_view($name); + $form = array(); + foreach($elements as $argid => $element) { + $form[$argid] = $element['element']; + } + + return $form; } /** * Handles processing of a argument form element generated by this API. * * @param $view_name - * A unique view name. + * A unique view name. * @param $arg_id - * An argument id (e.g. 'taxid'). + * An argument id (e.g. 'taxid'). * @value - * The value of a views_argument_api form element. + * The value of a views_argument_api form element. * @return - * A processed value for a view argument, given by a specific element's handler. + * A processed value for a view argument, given by a specific element's handler. */ function views_argument_api_process_argument_element($view_name, $arg_id, $value) { - $elements = views_argument_api_get_elements_by_view($view_name); - $func = $elements[$arg_id]['handler']; - return call_user_func_array($func, array_merge(array($value), $elements[$arg_id]['callback arguments'])); + $elements = views_argument_api_get_elements_by_view($view_name); + $func = $elements[$arg_id]['handler']; + return call_user_func_array($func, array_merge(array($value), $elements[$arg_id]['callback arguments'])); } /** @@ -331,20 +337,21 @@ * to one time for each element. * * @param $view_name - * A unique view name. + * A unique view name. * @param $form_values - * A set of form values for processing, keyed by argument ID. + * A set of form values for processing, keyed by argument ID. * @return - * An array of processed values for view arguments, keyed by argid. + * An array of processed values for view arguments, keyed by argid. */ function views_argument_api_process_argument_elements_by_view($view_name, $form_values) { - $elements = views_argument_api_get_elements_by_view($view_name); - foreach($elements as $argid => $element) { - $func = $elements[$argid]['handler']; - $processed[$argid] = call_user_func_array($func, array_merge(array($form_values[$argid]), $elements[$argid]['callback arguments'])); - } - - return $processed; + $elements = views_argument_api_get_elements_by_view($view_name); + $processed = array(); + foreach($elements as $argid => $element) { + $func = $elements[$argid]['handler']; + $processed[$argid] = call_user_func_array($func, array_merge(array($form_values[$argid]), (array)$elements[$argid]['callback arguments'])); + } + + return $processed; } /** @@ -355,27 +362,28 @@ * values. * * @param $api_id - * An API set ID (of your choosing) to save the form values against. + * An API set ID (of your choosing) to save the form values against. * Think of this as the ID you would provide in a call to * variable_set() as the first argument. * @param $edit - * A set of form values, which may or may not be exclusively the values + * A set of form values, which may or may not be exclusively the values * provided by a form generated by this API. * @param $view_name - * A view name against which to cross-check the keys of $edit. (optional). + * A view name against which to cross-check the keys of $edit. (optional). * @return - * TRUE if successful. FALSE if there was a problem. + * TRUE if successful. FALSE if there was a problem. */ function views_argument_api_save_arguments($api_id, $edit, $view_name = NULL) { - if(!empty($view_name)) { - $api_values = views_argument_api_get_api_form_values($view_name, $edit); - } else { - $api_values = $edit; - } - - db_query("DELETE FROM {views_argument_api_args} WHERE api_id = '%s'", $api_id); - $r = db_query("INSERT INTO {views_argument_api_args} (api_id, api_values) VALUES ('%s', '%s')", $api_id, serialize($api_values)); - return $r; + if (!empty($view_name)) { + $api_values = views_argument_api_get_api_form_values($view_name, $edit); + } + else { + $api_values = $edit; + } + + db_query("DELETE FROM {views_argument_api_args} WHERE api_id = '%s'", $api_id); + $r = db_query("INSERT INTO {views_argument_api_args} (api_id, api_values) VALUES ('%s', '%s')", $api_id, serialize($api_values)); + return $r; } /** @@ -383,17 +391,17 @@ * a specific API set ID, or $default if none is found. * * @param $api_id - * An API set ID for a set of form values. + * An API set ID for a set of form values. * @param $default - * A value to return if no values have been set for the API set ID + * A value to return if no values have been set for the API set ID * provided. * @return - * An entire set of argument form element values matching a + * An entire set of argument form element values matching a * specific API set ID, or $default if none is found. */ function views_argument_api_get($api_id, $default) { - $values = db_result(db_query("SELECT v.api_values FROM {views_argument_api_args} v WHERE v.api_id = '%s'", $api_id)); - return (!empty($values) ? unserialize($values) : $default); + $values = db_result(db_query("SELECT v.api_values FROM {views_argument_api_args} v WHERE v.api_id = '%s'", $api_id)); + return (!empty($values) ? unserialize($values) : $default); } /** @@ -402,38 +410,41 @@ * set of arguments to pass to a view from an API set ID and a view name. * * @param $api_id - * An API set ID for a set of form values. + * An API set ID for a set of form values. * @param $default - * A value to return if no values have been set for the API set ID + * A value to return if no values have been set for the API set ID * provided. * @param $view_name - * A unique view name. + * A unique view name. * @param $for_view - * If this paramater is set, the function will return a numerically-keyed + * If this paramater is set, the function will return a numerically-keyed * view, as opposed to an associative array. This is suitable to pass * to views_build_view. * @return - * An entire set of arguments that may be passed to a view, if + * An entire set of arguments that may be passed to a view, if * the specific API set ID returns a match. $default, otherwise. */ function views_argument_api_get_processed($api_id, $default, $view_name, $for_view = FALSE) { - $values = views_argument_api_get($api_id, $default); + $values = views_argument_api_get($api_id, $default); - if(empty($values)) { - return $default; - } else { - $processed_values = views_argument_api_process_argument_elements_by_view($view_name, $values); - - if($for_view) { - foreach($processed_values as $value) { - $arg_set[] = $value; - } - } else { - $arg_set = $processed_values; - } - return $arg_set; - } + if (empty($values)) { + return $default; + } + else { + $processed_values = views_argument_api_process_argument_elements_by_view($view_name, $values); + + if ($for_view) { + foreach($processed_values as $value) { + $arg_set[] = $value; + } + } + else { + $arg_set = $processed_values; + } + return $arg_set; + } } + /********************************************************************* * Some default processing handlers that your API elements can use. */ @@ -449,8 +460,8 @@ * This would certainly be the case for many textfield form elements, * and perhaps for some select elements as well. */ -function views_argument_api_handler_default_form_value($value) { - return check_plain($value); +function views_argument_api_handler_default_form_value($value = NULL) { + return check_plain($value); } /********************************************************************* @@ -461,33 +472,33 @@ * Tabular theme for argument form. */ function theme_views_argument_api_form_tabular(&$form) { - foreach (element_children($form) as $key) { - $row1 = array(); - $row2 = array(); - - $row1['title'] = $form[$key]['#title']; - $form[$key]['#title'] = NULL; - if(isset($form[$key]['#description'])) { - $row2[] = array( - 'data' => $form[$key]['#description'], - 'colspan' => 2, - ); - } - - $form[$key]['#description'] = NULL; - - $row1['element'] = drupal_render($form[$key]); - - $rows[] = $row1; - if(!empty($row2)) { - $rows[] = $row2; - } - } - - if(!empty($rows)) { - return theme('table', array(t('Argument'), t('Value')), $rows); - } else { - return drupal_render($form); - } - + foreach (element_children($form) as $key) { + $row1 = array(); + $row2 = array(); + + $row1['title'] = $form[$key]['#title']; + $form[$key]['#title'] = NULL; + if (isset($form[$key]['#description'])) { + $row2[] = array( + 'data' => $form[$key]['#description'], + 'colspan' => 2, + ); + } + + $form[$key]['#description'] = NULL; + + $row1['element'] = drupal_render($form[$key]); + + $rows[] = $row1; + if (!empty($row2)) { + $rows[] = $row2; + } + } + + if (!empty($rows)) { + return theme('table', array(t('Argument'), t('Value')), $rows); + } + else { + return drupal_render($form); + } } Index: modules/views_argument_api_og.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_argument_api/modules/views_argument_api_og.inc,v retrieving revision 1.1 diff -u -r1.1 views_argument_api_og.inc --- modules/views_argument_api_og.inc 11 Jun 2007 20:43:19 -0000 1.1 +++ modules/views_argument_api_og.inc 11 Jul 2007 05:16:35 -0000 @@ -3,7 +3,7 @@ /** * @file - * This include file implements views_argument_api functionality on + * This include file implements views_argument_api functionality on * behalf of og.module */ @@ -15,42 +15,42 @@ * Hook to define ways to handle user argument form elements. */ function og_views_argument_api_argument_elements() { - $qs = db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {og} og ON n.nid = og.nid"); - while($obj = db_fetch_object($qs)) { - $group_options[$obj->nid] = $obj->title; - } + $qs = db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {og} og ON n.nid = og.nid"); + while($obj = db_fetch_object($qs)) { + $group_options[$obj->nid] = $obj->title; + } - $elements = array(); - - // Gid - $elements['gid'] = array(); - - $elements['gid']['gid_select'] = array( - 'name' => 'uid_select', - 'label' => t('Groups: Select a pre-defined group'), - 'handler' => 'views_argument_api_handler_default_form_value', - 'element' => array( - '#options' => $group_options, - '#type' => 'select', - '#title' => t('Group'), - '#description' => t('Choose a group from which to display nodes.'), - ), - ); - - $elements['gid']['gid_node'] = array( - 'name' => 'gid_current', - 'label' => t('Groups: Based on current group'), - 'handler' => 'og_views_argument_api_handler_current', - 'element' => array( - '#type' => 'checkbox', - '#default_value' => TRUE, - '#title' => t('Use the current group to filter for nodes.'), - '#disabled' => TRUE, - '#description' => t('Pass the current group\'s ID to the view.'), - ), - ); - - return $elements; + $elements = array(); + + // Gid + $elements['gid'] = array(); + + $elements['gid']['gid_select'] = array( + 'name' => 'uid_select', + 'label' => t('Groups: Select a pre-defined group'), + 'handler' => 'views_argument_api_handler_default_form_value', + 'element' => array( + '#options' => $group_options, + '#type' => 'select', + '#title' => t('Group'), + '#description' => t('Choose a group from which to display nodes.'), + ), + ); + + $elements['gid']['gid_node'] = array( + 'name' => 'gid_current', + 'label' => t('Groups: Based on current group'), + 'handler' => 'og_views_argument_api_handler_current', + 'element' => array( + '#type' => 'checkbox', + '#default_value' => TRUE, + '#title' => t('Use the current group to filter for nodes.'), + '#disabled' => TRUE, + '#description' => t('Pass the current group\'s ID to the view.'), + ), + ); + + return $elements; } /********************************************************************* @@ -61,21 +61,22 @@ * Passes the current group's gid to the view. */ function og_views_argument_api_handler_gid_current($value) { - $nid = explode('node/', substr(urldecode(drupal_get_destination()), 12)); - if(count($nid) < 2) { - return NULL; - } - - $nid = $nid[1]; - $nid = explode('/', $nid); - $nid = array_shift($nid); - - if(is_numeric($nid)) { - $node = node_load($nid); - $gid = $node->gid; // Todo: verify that this is the right place to look. - } else { - $gid = NULL; - } - - return $gid; + $nid = explode('node/', substr(urldecode(drupal_get_destination()), 12)); + if (count($nid) < 2) { + return NULL; + } + + $nid = $nid[1]; + $nid = explode('/', $nid); + $nid = array_shift($nid); + + if (is_numeric($nid)) { + $node = node_load($nid); + $gid = $node->gid; // Todo: verify that this is the right place to look. + } + else { + $gid = NULL; + } + + return $gid; } \ No newline at end of file Index: modules/views_argument_api_taxonomy.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_argument_api/modules/views_argument_api_taxonomy.inc,v retrieving revision 1.1 diff -u -r1.1 views_argument_api_taxonomy.inc --- modules/views_argument_api_taxonomy.inc 11 Jun 2007 20:43:19 -0000 1.1 +++ modules/views_argument_api_taxonomy.inc 11 Jul 2007 05:16:35 -0000 @@ -3,7 +3,7 @@ /** * @file - * This include file implements views_argument_api functionality on + * This include file implements views_argument_api functionality on * behalf of taxonomy.module */ @@ -16,73 +16,73 @@ */ function taxonomy_views_argument_api_argument_elements() { - $elements = array(); - - // Taxid - $elements['taxid'] = array(); - - $elements['taxid']['taxid_select'] = array( - 'name' => 'taxid_select', - 'label' => t('Taxonomy: Select a pre-defined term'), - 'handler' => 'views_argument_api_handler_default_form_value', - 'element' => array( - '#options' => taxonomy_form_all(), - '#type' => 'select', - '#title' => t('Term'), - '#description' => t('Choose a term from which to display nodes.'), - ), - ); - - foreach(taxonomy_get_vocabularies() as $vocabulary) { - $elements['taxid']['taxid_node_' . $vocabulary->vid] = array( - 'name' => 'taxid_node_' . $vocabulary->vid, - 'label' => t('Taxonomy: Use node\'s term for !vocabulary', array('!vocabulary' => $vocabulary->name)), - 'handler' => 'taxonomy_views_argument_api_handler_node', - 'callback arguments' => array( - 'vid' => $vocabulary->vid, - ), - 'element' => array( - '#type' => 'checkbox', - '#default_value' => TRUE, - '#title' => t('Use node\'s term for !vocabulary.', array('!vocabulary' => $vocabulary->name)), - '#disabled' => TRUE, - '#description' => t('Pass the node\'s taxonomy for !vocabulary to the view.', array('!vocabulary' => $vocabulary->name)), - ), - ); - } - - // Taxletter - $elements['taxletter'] = array(); - $elements['taxletter']['taxletter_textfield'] = array( - 'name' => 'taxletter_textfield', - 'label' => t('Taxonomy: Enter a pre-defined term'), - 'handler' => 'views_argument_api_handler_default_form_value', - 'element' => array( - '#type' => 'textfield', - '#title' => t('Term'), - '#description' => t('Enter a term (by name) from which to display nodes.'), - ), - ); - - // Vocid - foreach(taxonomy_get_vocabularies() as $vocabulary) { - $vocabularies[$vocabulary->vid] = $vocabulary->name; - } - - $elements['vocid'] = array(); - $elements['vocid']['vocid_select'] = array( - 'name' => 'taxletter_select', - 'label' => t('Taxonomy: Select a pre-defined vocabulary'), - 'handler' => 'views_argument_api_handler_default_form_value', - 'element' => array( - '#options' => $vocabularies, - '#type' => 'select', - '#title' => t('Vocabulary'), - '#description' => t('Choose a vocabulary from which to display nodes.'), - ), - ); - - return $elements; + $elements = array(); + + // Taxid + $elements['taxid'] = array(); + + $elements['taxid']['taxid_select'] = array( + 'name' => 'taxid_select', + 'label' => t('Taxonomy: Select a pre-defined term'), + 'handler' => 'views_argument_api_handler_default_form_value', + 'element' => array( + '#options' => taxonomy_form_all(), + '#type' => 'select', + '#title' => t('Term'), + '#description' => t('Choose a term from which to display nodes.'), + ), + ); + + foreach(taxonomy_get_vocabularies() as $vocabulary) { + $elements['taxid']['taxid_node_' . $vocabulary->vid] = array( + 'name' => 'taxid_node_' . $vocabulary->vid, + 'label' => t('Taxonomy: Use node\'s term for !vocabulary', array('!vocabulary' => $vocabulary->name)), + 'handler' => 'taxonomy_views_argument_api_handler_node', + 'callback arguments' => array( + 'vid' => $vocabulary->vid, + ), + 'element' => array( + '#type' => 'checkbox', + '#default_value' => TRUE, + '#title' => t('Use node\'s term for !vocabulary.', array('!vocabulary' => $vocabulary->name)), + '#disabled' => TRUE, + '#description' => t('Pass the node\'s taxonomy for !vocabulary to the view.', array('!vocabulary' => $vocabulary->name)), + ), + ); + } + + // Taxletter + $elements['taxletter'] = array(); + $elements['taxletter']['taxletter_textfield'] = array( + 'name' => 'taxletter_textfield', + 'label' => t('Taxonomy: Enter a pre-defined term'), + 'handler' => 'views_argument_api_handler_default_form_value', + 'element' => array( + '#type' => 'textfield', + '#title' => t('Term'), + '#description' => t('Enter a term (by name) from which to display nodes.'), + ), + ); + + // Vocid + foreach(taxonomy_get_vocabularies() as $vocabulary) { + $vocabularies[$vocabulary->vid] = $vocabulary->name; + } + + $elements['vocid'] = array(); + $elements['vocid']['vocid_select'] = array( + 'name' => 'taxletter_select', + 'label' => t('Taxonomy: Select a pre-defined vocabulary'), + 'handler' => 'views_argument_api_handler_default_form_value', + 'element' => array( + '#options' => $vocabularies, + '#type' => 'select', + '#title' => t('Vocabulary'), + '#description' => t('Choose a vocabulary from which to display nodes.'), + ), + ); + + return $elements; } /********************************************************************* @@ -93,22 +93,23 @@ * Returns a tid from a particular vid for a loaded node. */ function taxonomy_views_argument_api_handler_node($value, $vid) { - $nid = explode('node/', substr(urldecode(drupal_get_destination()), 12)); - if(count($nid) < 2) { - return NULL; - } - - $nid = $nid[1]; - $nid = explode('/', $nid); - $nid = array_shift($nid); - - if(is_numeric($nid)) { - $terms = taxonomy_node_get_terms_by_vocabulary($nid, $vid); - $term = array_shift($terms); - $tid = $term->tid; - } else { - $tid = NULL; - } - - return $tid; + $nid = explode('node/', substr(urldecode(drupal_get_destination()), 12)); + if (count($nid) < 2) { + return NULL; + } + + $nid = $nid[1]; + $nid = explode('/', $nid); + $nid = array_shift($nid); + + if (is_numeric($nid)) { + $terms = taxonomy_node_get_terms_by_vocabulary($nid, $vid); + $term = array_shift($terms); + $tid = $term->tid; + } + else { + $tid = NULL; + } + + return $tid; } \ No newline at end of file Index: modules/views_argument_api_user.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views_argument_api/modules/views_argument_api_user.inc,v retrieving revision 1.1 diff -u -r1.1 views_argument_api_user.inc --- modules/views_argument_api_user.inc 11 Jun 2007 20:43:19 -0000 1.1 +++ modules/views_argument_api_user.inc 11 Jul 2007 05:16:35 -0000 @@ -3,7 +3,7 @@ /** * @file - * This include file implements views_argument_api functionality on + * This include file implements views_argument_api functionality on * behalf of user.module */ @@ -15,113 +15,114 @@ * Hook to define ways to handle user argument form elements. */ function user_views_argument_api_argument_elements() { - $qs = db_query("SELECT u.uid, u.name FROM {users} u"); - while($obj = db_fetch_object($qs)) { - if(empty($obj->name)) { - $name = t('Anonymous'); - } else { - $name = $obj->name; - } - $user_options[$obj->uid] = $name; - } - - $elements = array(); - - // Uid - $elements['uid'] = array(); - - $elements['uid']['uid_select'] = array( - 'name' => 'uid_select', - 'label' => t('User: Select a pre-defined user'), - 'handler' => 'views_argument_api_handler_default_form_value', - 'element' => array( - '#options' => $user_options, - '#type' => 'select', - '#title' => t('User'), - '#description' => t('Choose a user from which to display nodes.'), - ), - ); - - $elements['uid']['uid_current'] = array( - 'name' => 'uid_current', - 'label' => t('User: Based on current user'), - 'handler' => 'user_views_argument_api_handler_current', - 'element' => array( - '#type' => 'checkbox', - '#default_value' => TRUE, - '#title' => t('Use the current user to filter nodes.'), - '#disabled' => TRUE, - '#description' => t('Pass the current user\'s ID to the view.'), - ), - ); - - $elements['uid']['uid_node'] = array( - 'name' => 'uid_node', - 'label' => t('User: Based on current node\'s author'), - 'handler' => 'user_views_argument_api_handler_node', - 'element' => array( - '#type' => 'checkbox', - '#default_value' => TRUE, - '#title' => t('Use the current node\'s author to filter nodes.'), - '#disabled' => TRUE, - '#description' => t('Pass the current node\'s author to the view.'), - ), - ); - - // Uidtouch - $elements['uidtouch'] = array(); - $elements['uidtouch']['uidtouch_select'] = array( - 'name' => 'uidtouch_select', - 'label' => t('User: Select a pre-defined user'), - 'handler' => 'views_argument_api_handler_default_form_value', - 'element' => array( - '#options' => $user_options, - '#type' => 'select', - '#title' => t('User'), - '#description' => t('Choose a user from which to display touched nodes.'), - ), - ); - - $elements['uidtouch']['uidtouch_current'] = array( - 'name' => 'uidtouch_current', - 'label' => t('User: Based on current user'), - 'handler' => 'user_views_argument_api_handler_current', - 'element' => array( - '#type' => 'checkbox', - '#default_value' => TRUE, - '#title' => t('Use the current user to filter for touched nodes.'), - '#disabled' => TRUE, - '#description' => t('Pass the current user\'s ID to the view to filter for touched nodes.'), - ), - ); - - $elements['uidtouch']['uidtouch_node'] = array( - 'name' => 'uidtouch_node', - 'label' => t('User: Based on current node\'s author'), - 'handler' => 'user_views_argument_api_handler_node', - 'element' => array( - '#type' => 'checkbox', - '#default_value' => TRUE, - '#title' => t('Use the current node\'s author to filter for touched nodes.'), - '#disabled' => TRUE, - '#description' => t('Pass the current node\'s author to the view to filter for touched nodes.'), - ), - ); + $qs = db_query("SELECT u.uid, u.name FROM {users} u"); + while($obj = db_fetch_object($qs)) { + if (empty($obj->name)) { + $name = t('Anonymous'); + } + else { + $name = $obj->name; + } + $user_options[$obj->uid] = $name; + } + + $elements = array(); + + // Uid + $elements['uid'] = array(); + + $elements['uid']['uid_select'] = array( + 'name' => 'uid_select', + 'label' => t('User: Select a pre-defined user'), + 'handler' => 'views_argument_api_handler_default_form_value', + 'element' => array( + '#options' => $user_options, + '#type' => 'select', + '#title' => t('User'), + '#description' => t('Choose a user from which to display nodes.'), + ), + ); + + $elements['uid']['uid_current'] = array( + 'name' => 'uid_current', + 'label' => t('User: Based on current user'), + 'handler' => 'user_views_argument_api_handler_current', + 'element' => array( + '#type' => 'checkbox', + '#default_value' => TRUE, + '#title' => t('Use the current user to filter nodes.'), + '#disabled' => TRUE, + '#description' => t('Pass the current user\'s ID to the view.'), + ), + ); + + $elements['uid']['uid_node'] = array( + 'name' => 'uid_node', + 'label' => t('User: Based on current node\'s author'), + 'handler' => 'user_views_argument_api_handler_node', + 'element' => array( + '#type' => 'checkbox', + '#default_value' => TRUE, + '#title' => t('Use the current node\'s author to filter nodes.'), + '#disabled' => TRUE, + '#description' => t('Pass the current node\'s author to the view.'), + ), + ); + + // Uidtouch + $elements['uidtouch'] = array(); + $elements['uidtouch']['uidtouch_select'] = array( + 'name' => 'uidtouch_select', + 'label' => t('User: Select a pre-defined user'), + 'handler' => 'views_argument_api_handler_default_form_value', + 'element' => array( + '#options' => $user_options, + '#type' => 'select', + '#title' => t('User'), + '#description' => t('Choose a user from which to display touched nodes.'), + ), + ); + + $elements['uidtouch']['uidtouch_current'] = array( + 'name' => 'uidtouch_current', + 'label' => t('User: Based on current user'), + 'handler' => 'user_views_argument_api_handler_current', + 'element' => array( + '#type' => 'checkbox', + '#default_value' => TRUE, + '#title' => t('Use the current user to filter for touched nodes.'), + '#disabled' => TRUE, + '#description' => t('Pass the current user\'s ID to the view to filter for touched nodes.'), + ), + ); + + $elements['uidtouch']['uidtouch_node'] = array( + 'name' => 'uidtouch_node', + 'label' => t('User: Based on current node\'s author'), + 'handler' => 'user_views_argument_api_handler_node', + 'element' => array( + '#type' => 'checkbox', + '#default_value' => TRUE, + '#title' => t('Use the current node\'s author to filter for touched nodes.'), + '#disabled' => TRUE, + '#description' => t('Pass the current node\'s author to the view to filter for touched nodes.'), + ), + ); - //Username - $elements['username'] = array(); - $elements['username']['username_textfield'] = array( - 'name' => 'username_textfield', - 'label' => t('User: Enter a pre-defined username'), - 'handler' => 'views_argument_api_handler_default_form_value', - 'element' => array( - '#type' => 'textfield', - '#title' => t('Username'), - '#description' => t('Enter a username from which to display nodes.'), - ), - ); - - return $elements; + //Username + $elements['username'] = array(); + $elements['username']['username_textfield'] = array( + 'name' => 'username_textfield', + 'label' => t('User: Enter a pre-defined username'), + 'handler' => 'views_argument_api_handler_default_form_value', + 'element' => array( + '#type' => 'textfield', + '#title' => t('Username'), + '#description' => t('Enter a username from which to display nodes.'), + ), + ); + + return $elements; } /********************************************************************* @@ -132,29 +133,30 @@ * Pass the current user's uid to the view. */ function user_views_argument_api_handler_current($value) { - global $user; - return $user->uid; + global $user; + return $user->uid; } /** * Pass the current node's author's uid to the view. */ function user_views_argument_api_handler_node($value) { - $nid = explode('node/', substr(urldecode(drupal_get_destination()), 12)); - if(count($nid) < 2) { - return NULL; - } - - $nid = $nid[1]; - $nid = explode('/', $nid); - $nid = array_shift($nid); - - if(is_numeric($nid)) { - $node = node_load($nid); - $uid = $node->uid; - } else { - $uid = NULL; - } - - return $uid; + $nid = explode('node/', substr(urldecode(drupal_get_destination()), 12)); + if (count($nid) < 2) { + return NULL; + } + + $nid = $nid[1]; + $nid = explode('/', $nid); + $nid = array_shift($nid); + + if (is_numeric($nid)) { + $node = node_load($nid); + $uid = $node->uid; + } + else { + $uid = NULL; + } + + return $uid; } \ No newline at end of file