Index: fasttoggle.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/fasttoggle/Attic/fasttoggle.module,v retrieving revision 1.8.2.8 diff -u -r1.8.2.8 fasttoggle.module --- fasttoggle.module 8 Nov 2008 11:38:19 -0000 1.8.2.8 +++ fasttoggle.module 5 Dec 2008 23:47:43 -0000 @@ -402,3 +402,7 @@ return fasttoggle($options[$key][intval($data->$key)], 'node/'. $data->nid .'/toggle/'. $key, true, $key .'_'. $data->nid); } } + +function fasttoggle_views_api() { + return array('api' => 2); +} Index: fasttoggle.views.inc =================================================================== RCS file: fasttoggle.views.inc diff -N fasttoggle.views.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ fasttoggle.views.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,307 @@ + array( + 'title' => t('Publish Node'), + 'help' => t('Provide a simple link to publish the node.'), + 'handler' => 'fasttoggle_handler_field_node_link_publish', + ), + ); + return $data; +} + +/** + * Field handler to present a link toggle status. + */ + + +class fasttoggle_handler_field_node_link extends fasttoggle_handler_field { + function construct() { + parent::construct(); + $this->additional_fields['nid'] = 'nid'; + } + + function option_definition() { + $options = parent::option_definition(); + + $options['text'] = array('default' => '', 'translatable' => TRUE); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['text'] = array( + '#type' => 'textfield', + '#title' => t('Text to display'), + '#default_value' => $this->options['text'], + ); + } + + function query() { + $this->ensure_my_table(); + $this->add_additional_fields(); + } + + function render($values) { + $text = !empty($this->options['text']) ? $this->options['text'] : t('view'); + $nid = $values->{$this->aliases['nid']}; + return l($text, "node/$nid"); + } +} + + +class fasttoggle_handler_field_node_link_publish extends fasttoggle_handler_field_node_link { + function construct() { + parent::construct(); + $this->additional_fields['uid'] = 'uid'; + $this->additional_fields['status'] = 'status'; + $this->additional_fields['type'] = 'type'; + $this->additional_fields['format'] = array('table' => 'node_revisions', 'field' => 'format'); + } + + function render($values) { + // ensure user has access to edit this node. + $node = new stdClass(); + $node->nid = $values->{$this->aliases['nid']}; + $node->uid = $values->{$this->aliases['uid']}; + $node->type = $values->{$this->aliases['type']}; + $node->format = $values->{$this->aliases['format']}; + $node->status = 1; // unpublished nodes ignore access control + if (!node_access('update', $node)) { + return; + } + + $realstatus = $values->{$this->aliases['status']}; + if ($realstatus == 1) { + return fasttoggle('unpublish it', 'node/'. $node->nid .'/toggle/status', true, 'status_'. $node->nid); + } + else { + return fasttoggle('publish it', 'node/'. $node->nid .'/toggle/status', true, 'status_'. $node->nid); + } + } +} + + + + +class fasttoggle_handler_field extends views_handler { + var $field_alias = 'unknown'; + var $aliases = array(); + + + /** + * Construct a new field handler. + */ + + + function construct() { + parent::construct(); + + $this->additional_fields = array(); + if (!empty($this->definition['additional fields'])) { + $this->additional_fields = $this->definition['additional fields']; + } + + if (!isset($this->options['exclude'])) { + $this->options['exclude'] = ''; + } + } + + function init(&$view, $options) { + parent::init($view, $options); + + $this->options += array( + 'exclude' => FALSE, + ); + } + + /** + * Called to add the field to a query. + */ + + function query() { + $this->ensure_my_table(); + // Add the field. + $this->field_alias = $this->query->add_field($this->table_alias, $this->real_field); + + $this->add_additional_fields(); + } + + /** + * Add 'additional' fields to the query. + * + * @param $fields + * An array of fields. The key is an identifier used to later find the + * field alias used. The value is either a string in which case it's + * assumed to be a field on this handler's table; or it's an array in the + * form of + * @code array('table' => $tablename, 'field' => $fieldname) @endcode + */ + + function add_additional_fields($fields = NULL) { + if (!isset($fields)) { + // notice check + if (empty($this->additional_fields)) { + return; + } + $fields = $this->additional_fields; + } + if (!empty($fields) && is_array($fields)) { + foreach ($fields as $identifier => $info) { + if (is_array($info)) { + if (isset($info['table'])) { + $table_alias = $this->query->ensure_table($info['table'], $this->relationship); + } + else { + $table_alias = $this->table_alias; + } + $this->aliases[$identifier] = $this->query->add_field($table_alias, $info['field']); + } + else { + $this->aliases[$info] = $this->query->add_field($this->table_alias, $info); + } + } + } + } + + /** + * Called to determine what to tell the clicksorter. + */ + + function click_sort($order) { + $this->query->add_orderby($this->table, $this->field, $order, $this->field_alias); + } + + /** + * Determine if this field is click sortable. + */ +/* + function click_sortable() { + return !empty($this->definition['click sortable']); + } + + /** + * Get this field's label. + */ + + function label() { + if (!isset($this->options['label'])) { + return ''; + } + return $this->options['label']; + } + + /** + * Return DIV or SPAN based upon the field's element type. + */ + + function element_type() { + if (isset($this->definition['element type'])) { + return $this->definition['element type']; + } + + return 'span'; + } + + function option_definition() { + $options = parent::option_definition(); + + $options['label'] = array('default' => $this->definition['title'], 'translatable' => TRUE); + + return $options; + } + + /** + * Default options form that provides the label widget that all fields + * should have. + */ + + function options_form(&$form, &$form_state) { + $form['label'] = array( + '#type' => 'textfield', + '#title' => t('Label'), + '#default_value' => isset($this->options['label']) ? $this->options['label'] : '', + '#description' => t('The label for this field that will be displayed to end users if the style requires it.'), + ); + $form['exclude'] = array( + '#type' => 'checkbox', + '#title' => t('Exclude from display'), + '#default_value' => $this->options['exclude'], + '#description' => t('Check this box to not display this field, but still load it in the view. Use this option to not show a grouping field in each record, or when doing advanced theming.'), + ); + } + + /** + * Provide extra data to the administration form + */ + + function admin_summary() { + return $this->label(); + } + + /** + * Run before any fields are rendered. + * + * This gives the handlers some time to set up before any handler has + * been rendered. + * + * @param $values + * An array of all objects returned from the query. + */ + + function pre_render($values) { } + + /** + * Render the field. + * + * @param $values + * The values retrieved from the database. + */ + + function render($values) { + $value = $values->{$this->field_alias}; + return check_plain($value); + } + + /** + * Call out to the theme() function, which probably just calls render() but + * allows sites to override output fairly easily. + */ + + function theme($values) { + return theme($this->theme_functions(), $this->view, $this, $values); + } + + function theme_functions() { + $themes = array(); + $hook = 'views_view_field'; + + $display = $this->view->display[$this->view->current_display]; + + if (!empty($display)) { + $themes[] = $hook . '__' . $this->view->name . '__' . $display->id . '__' . $this->options['id']; + $themes[] = $hook . '__' . $this->view->name . '__' . $display->id; + $themes[] = $hook . '__' . $display->id . '__' . $this->options['id']; + $themes[] = $hook . '__' . $display->id; + if ($display->id != $display->display_plugin) { + $themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin . '__' . $this->options['id']; + $themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin; + $themes[] = $hook . '__' . $display->display_plugin . '__' . $this->options['id']; + $themes[] = $hook . '__' . $display->display_plugin; + } + } + $themes[] = $hook . '__' . $this->view->name . '__' . $this->options['id']; + $themes[] = $hook . '__' . $this->view->name; + $themes[] = $hook . '__' . $this->options['id']; + $themes[] = $hook; + + return $themes; + } +} +