Skip to content

Instantly share code, notes, and snippets.

@amcgowanca
Created December 2, 2013 15:45
Show Gist options
  • Save amcgowanca/7751417 to your computer and use it in GitHub Desktop.
Save amcgowanca/7751417 to your computer and use it in GitHub Desktop.
Patch from https://drupal.org/files/vud_node_module_D7_port.patch revised with full module path.
diff --git a/vote_up_down/vud_node/README.txt b/vote_up_down/vud_node/README.txt
new file mode 100644
index 0000000..31c622c
--- /dev/null
+++ b/vote_up_down/vud_node/README.txt
@@ -0,0 +1,81 @@
+Aug 5, 2013
+
+This README addresses the *Port vud_node to D7* issue
+
+@see https://drupal.org/node/1194274
+@see https://drupal.org/node/1194274#comment-7721375
+
+This patch -- vud_node_module_D7_port.patch -- should be applied to the
+7.x-1.x branch of the git repository for the Vote Up/Down project.
+
+The Vote Up/Down module currently includes four distinct submodules which can be
+(and probably should be) spawned off into separate modules.
+
+ - vud_field
+ - vud_node
+ - vud_comment
+ - vud_term
+
+All of these sub-modules reference the code in the 'widgets' subdirectory.
+
+'widgets' has the code, stylesheets, and images to generate and trigger
+each of the different voting widgets. Currently there are 5 different vote
+widgets included with the module.
+
+This patch should only change the behavior of the vud_node module. All other
+sub-modules should work exactly the same as before.
+
+This is a major revision of the vud_node module. The aforementioned
+patch includes the following:
+
+ - 3 new files in the parent directory (vote_up_down)
+
+ - widgets_table.php: This is a prototyping web page that works without
+ Drupal -- just open
+
+ http://localhost/sites/all/modules/vote_up_down/widgets_table.php
+
+ with your web browser.
+
+ The widgets_table web page calls the code found in...
+
+ - vud_node_options.inc - this code is referenced by the code contained in
+ the vud_node/vud_node.module file and by the widgets_table.php page.
+
+ - vud_node_options.css - these are style rules that override the individual
+ widget style sheets found in each widget subdirectory.
+
+ - 2 files have been deleted along with their parent directory
+ - vud_node/views/vud_node.views.inc
+ - vud_node/views/vud_node_handler_field_widget.inc
+
+ - 2 files have been modified
+ -vud_node/vud_node.module - lots of changes, the focus of this patch.
+ -vud_node/vud_node.install - removed some variables no longer used.
+
+
+*New Features*
+
+The 'Node' config page has been replaced with a 'Content' config page.
+
+@try http://localhost/admin/config/search/voteupdown/options
+
+The Content config is a table that lists current content types vertically and
+available vote widgets on the horizontal axis.
+
+The content types listed are dynamic -- they reflect the content types that have
+been defined for the site. The Widget gallery is not dynamic -- it is
+hand/hard coded and fixed. This may change in future releases.
+
+The vud_field module has a dynamic widget gallery -- the module enumerates the
+widgets subdirectory and present the admin with a list of widgets available.
+
+The vud_field and vud_node modules are compatible in a limited context. If both
+modules are enabled, it is possible to have to have two independent voting
+widgets appear on the same page.
+
+No sane person would want this so, as a rule of thumb, use the vud_field module
+or the vud_node module, but not both together, unless you know what you are
+doing.
+
+The option to have a vote widget appear with a *teaser* has been removed.
diff --git a/vote_up_down/vud_node/views/vud_node.views.inc b/vote_up_down/vud_node/views/vud_node.views.inc
deleted file mode 100644
index a88e785..0000000
--- a/vote_up_down/vud_node/views/vud_node.views.inc
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-
-/**
- * @file
- * Provide views data and handlers for vud_node.module
- */
-
-/**
- * Implementation of hook_views_data_alter().
- */
-function vud_node_views_data_alter(&$data) {
- $data['node']['vud_node_widget'] = array(
- 'group' => t('Vote Up/Down'),
- 'title' => t('Node Widget'),
- 'help' => t('Provide a node widget for the Vote up/Down module.'),
- 'field' => array(
- 'handler' => 'vud_node_handler_field_widget',
- ),
- );
-}
-
-/**
- * Implementation of hook_views_handlers().
- */
-function vud_node_views_handlers() {
- return array(
- 'info' => array(
- 'path' => drupal_get_path('module', 'vud_node') . '/views'
- ),
- 'handlers' => array(
- 'vud_node_handler_field_widget' => array(
- 'parent' => 'views_handler_field',
- ),
- ),
- );
-}
diff --git a/vote_up_down/vud_node/views/vud_node_handler_field_widget.inc b/vote_up_down/vud_node/views/vud_node_handler_field_widget.inc
deleted file mode 100644
index 7d39f48..0000000
--- a/vote_up_down/vud_node/views/vud_node_handler_field_widget.inc
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-
-/**
- * @file
- * Provide a handler for Vote Up/down widget field for nodes.
- */
-
-/**
- * A handler that provides a Vote Up/Down widget field for nodes.
- */
-class vud_node_handler_field_widget extends views_handler_field {
- function query() {
- // We have to override the parent here, because we don't want
- // to do anything.
- }
-
- function option_definition() {
- $options = parent::option_definition();
- return $options;
- }
-
- function options_form(&$form, &$form_state) {
- parent::options_form($form, $form_state);
- // It doesn't make sense to have the ability to alter the output.
- $form['alter']['#access'] = FALSE;
- }
-
- function render($values) {
- $widget = '';
- if (($can_edit = user_access('use vote up/down on nodes')) || user_access('view vote up/down count on nodes')) {
- $nid = $values->nid;
- $type = db_query("SELECT type FROM {node} WHERE nid = :nid", array(':nid' => $nid))->fetchField();
- $valid_type = in_array($type, variable_get('vud_node_types', array()), TRUE);
-
- if ($valid_type) {
- $tag = variable_get('vud_tag', 'vote');
- $widget_type = variable_get('vud_node_widget', 'plain');
- $widget_message_code = (!$can_edit) ? VUD_WIDGET_MESSAGE_DENIED : VUD_WIDGET_MESSAGE_ERROR;
-
- $variables = array(
- 'entity_id' => $nid,
- 'type' => 'node',
- 'tag' => $tag,
- 'widget_type' => $widget_type,
- 'readonly' => !$can_edit,
- 'widget_message_code' => $widget_message_code,
- );
- $widget = theme('vud_widget', $variables);
- }
- }
-
- return $widget;
- }
-}
diff --git a/vote_up_down/vud_node/vud_node.install b/vote_up_down/vud_node/vud_node.install
index 711e437..811374b 100644
--- a/vote_up_down/vud_node/vud_node.install
+++ b/vote_up_down/vud_node/vud_node.install
@@ -9,24 +9,6 @@
* Implementation of hook_uninstall().
*/
function vud_node_uninstall() {
- variable_del('vud_node_types');
- variable_del('vud_node_widget');
- variable_del('vud_node_widget_show');
variable_del('vud_node_votes');
- variable_del('vud_node_reset');
- variable_del('vud_node_widget_vote_on_teaser');
-}
-
-/**
- * use new constants to manage count/widget visibility
- */
-function vud_node_update_6201() {
- $ret = array();
- $widget_visibility = variable_get('vud_node_widget_show', NULL);
- if (!is_null($widget_visibility)) {
- $widget_visibility++;
- variable_set('vud_node_widget_show', $widget_visibility);
- }
- // no DB updates
- return $ret;
+ variable_del('vud_node_config');
}
diff --git a/vote_up_down/vud_node/vud_node.module b/vote_up_down/vud_node/vud_node.module
index e4b91b4..9038681 100644
--- a/vote_up_down/vud_node/vud_node.module
+++ b/vote_up_down/vud_node/vud_node.module
@@ -1,16 +1,11 @@
<?php
-
/**
* @file
- * Adds a voting widget to nodes.
+ * vote_up_down support module for nodes (/vud_node).
+ * Configure Vote widgets for each content type.
*/
-define('VUD_NODE_DISPLAY_NO', 0); // used only by vote count
-define('VUD_NODE_DISPLAY_TEASER_ONLY', 1);
-define('VUD_NODE_DISPLAY_FULL_ONLY', 2);
-define('VUD_NODE_DISPLAY_BOTH', 3);
-
-define('VUD_NODE_WIDGET_MESSAGE_TEASER_DENIED', 2);
+include 'vud_node_options.inc';
/**
* Implementation of hook_permission().
@@ -34,17 +29,18 @@ function vud_node_permission() {
}
/**
- * Implementation of hook_menu().
+ * Implements hook_menu().
*/
function vud_node_menu() {
$items = array();
- $items['admin/config/search/voteupdown/node'] = array(
- 'title' => 'Nodes',
- 'description' => 'Vote Up/Down Node settings',
- 'page arguments' => array('vud_node_admin_settings'),
+ $items['admin/config/search/voteupdown/options'] = array(
+ 'title' => 'Content',
+ 'description' => 'Vote Up/Down configuration page.',
'access arguments' => array('administer vote up/down on nodes'),
- 'weight' => -10,
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('vud_node_options_form'),
+ 'weight' => -5,
'type' => MENU_LOCAL_TASK,
);
@@ -60,11 +56,11 @@ function vud_node_menu() {
}
/**
- * Implementation of hook_views_api().
+ * Implements hook_views_api().
*/
function vud_node_views_api() {
return array(
- 'api' => 2,
+ 'api' => 3,
'path' => drupal_get_path('module', 'vud_node') . '/views',
);
}
@@ -77,136 +73,48 @@ function vud_node_tab_view_stats($node) {
if (!user_access('see vote up/down node stats')) {
return FALSE;
}
-
- if (in_array($node->type, variable_get('vud_node_types', array()), TRUE)) {
- return TRUE;
- }
+ return TRUE;
}
/**
- * Advanced menu settings callback.
+ * Implements hook_node_view().
*/
-function vud_node_admin_settings() {
- $form['vud_node_types'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Node types'),
- '#description' => t('Select the node types for which you want to activate voting.'),
- '#default_value' => variable_get('vud_node_types', array()),
- '#options' => node_type_get_names(),
- );
- $form['vud_node_widget'] = array(
- '#title' => t('Widget selection'),
- '#description' => t('Select the voting widget theme that will be displayed.'),
- '#type' => 'radios',
- '#default_value' => variable_get('vud_node_widget', 'updown'),
- '#options' => vud_widget_get_names(),
- );
- $form['vud_node_widget_show'] = array(
- '#type' => 'select',
- '#title' => t('Widget and votes display'),
- '#description' => t('When will the vote widget be displayed?'),
- '#default_value' => variable_get('vud_node_widget_show', VUD_NODE_DISPLAY_BOTH),
- '#options' => array(VUD_NODE_DISPLAY_TEASER_ONLY => 'Teaser only', VUD_NODE_DISPLAY_FULL_ONLY => 'Full display only', VUD_NODE_DISPLAY_BOTH => 'Both teaser and full'),
- );
- $form['vud_node_widget_vote_on_teaser'] = array(
- '#type' => 'checkbox',
- '#title' => t('Voting on teasers'),
- '#description' => t('Do you want to allow voting on teasers?'),
- '#default_value' => variable_get('vud_node_widget_vote_on_teaser', TRUE),
- );
- $form['vud_node_votes'] = array(
- '#type' => 'select',
- '#description' => t('When will the total vote count be displayed?'),
- '#default_value' => variable_get('vud_node_votes', VUD_NODE_DISPLAY_BOTH),
- '#options' => array(VUD_NODE_DISPLAY_NO => 'Don\'t display', VUD_NODE_DISPLAY_TEASER_ONLY => 'Teaser only', VUD_NODE_DISPLAY_FULL_ONLY => 'Full display only', VUD_NODE_DISPLAY_BOTH => 'Both teaser and full'),
- );
- $form['vud_node_reset'] = array(
- '#type' => 'radios',
- '#title' => t('Votes reset'),
- '#description' => t('Choose if users are allowed to reset their votes on a node.'),
- '#default_value' => variable_get('vud_node_reset', 0),
- '#options' => array(0 => 'No', 1 => 'Yes'),
- );
-
-return system_settings_form($form);
-}
+function vud_node_node_view($node, $view_mode, $langcode) {
+ // Check to see if a widget is enabled
+ $config = variable_get('vud_node_config');
-/**
- * Implementation of vud hook_vud_widget_message_codes_alter().
- */
-function vud_node_vud_widget_message_codes_alter(&$widget_message_codes) {
- $widget_message_codes[VUD_NODE_WIDGET_MESSAGE_TEASER_DENIED] = t('Please go to full version of this content to vote.');
-}
+ if (!isset($config['vud_enable_' . $node->type])) {
+ // This occurs if a new content type has been added but not yet configured.
+ return;
+ }
-/**
- * Implementation of hook_node_view().
- */
-function vud_node_node_view($node, $view_mode, $langcode) {
- // avoid showing the widget in some node builds
- $exclude_modes = array(
- NODE_BUILD_PREVIEW,
- NODE_BUILD_SEARCH_INDEX,
- NODE_BUILD_SEARCH_RESULT,
- NODE_BUILD_RSS,
- );
- if (in_array($node->build_mode, $exclude_modes)) {
- break;
+ if ($config['vud_enable_' . $node->type] != 'on') {
+ return;
}
- if (($can_edit=user_access('use vote up/down on nodes')) || user_access('view vote up/down count on nodes')) {
- $node_type = in_array($node->type, variable_get('vud_node_types', array()), TRUE);
- $widget_showmode = variable_get('vud_node_widget_show', VUD_NODE_DISPLAY_BOTH);
- $tag = variable_get('vud_tag', 'vote');
- $widget = variable_get('vud_node_widget', 'plain');
- $vote_on_teaser = (bool)variable_get('vud_node_widget_vote_on_teaser', TRUE);
- $teaser = $a3;
- $widget_message_code = VUD_WIDGET_MESSAGE_ERROR;
- if (!$can_edit) {
- $widget_message_code = VUD_WIDGET_MESSAGE_DENIED;
- }
- elseif (!$vote_on_teaser) {
- $widget_message_code = VUD_NODE_WIDGET_MESSAGE_TEASER_DENIED;
- }
+ $can_edit = user_access('use vote up/down on nodes');
- if ($node_type) {
+ if ($can_edit || user_access('view vote up/down count on nodes')) {
+ $tag = variable_get('vud_tag', 'vote');
+ $widget_theme = $config['vud_widget_' . $node->type];
+
+ $variables = array(
+ 'entity_id' => $node->nid,
+ 'type' => $node->type,
+ 'tag' => $tag,
+ 'widget_theme' => $widget_theme,
+ 'readonly' => !$can_edit,
+ );
- switch ($widget_showmode) {
- case VUD_NODE_DISPLAY_TEASER_ONLY:
- if ($teaser == 1) {
- $node->content['vud_node_widget_display'] = array(
- '#value' => theme('vud_widget', $node->nid, 'node', $tag, $widget, !$vote_on_teaser || !$can_edit, $widget_message_code),
- '#weight' => -10,
- );
- }
- break;
- case VUD_NODE_DISPLAY_FULL_ONLY:
- if ($teaser == 0) {
- $node->content['vud_node_widget_display'] = array(
- '#value' => theme('vud_widget', $node->nid, 'node', $tag, $widget, !$can_edit, $widget_message_code),
- '#weight' => -10,
- );
- }
- break;
- case VUD_NODE_DISPLAY_BOTH:
- if ($teaser == 1) {
- $readonly = !$vote_on_teaser || !$can_edit;
- }
- else {
- $readonly = !$can_edit;
- }
- $node->content['vud_node_widget_display'] = array(
- '#value' => theme('vud_widget', $node->nid, 'node', $tag, $widget, $readonly, $widget_message_code),
- '#weight' => -10,
- );
- break;
- }
+ $node->vud_node_widget = theme('vud_widget', $variables);
- }
+ // TODO: Return a renderable array instead of markup.
+ $node->content['vud_node_widget'] = array('#markup' => $node->vud_node_widget);
}
}
/**
- * Implementation of vud hook_template_suggestions().
+ * Implements hook_template_suggestions().
*/
function vud_node_template_suggestions($template_type, $plugin, $entity_id) {
$node = node_load($entity_id);
@@ -229,20 +137,26 @@ function vud_node_tracker() {
array('data' => t('Date'))
);
$tag = variable_get('vud_tag', 'vote');
- $criteria = array('entity_type' => 'node', 'entity_id' => $node->nid, 'tag' => $tag);
+ $criteria = array('entity_type' => $node->type, 'entity_id' => $node->nid, 'tag' => $tag);
$votes = votingapi_select_votes($criteria);
- $rows[] = array();
+ $rows = array();
+
foreach ($votes as $vote) {
- $account = user_load($vote['uid']);
+ // OK - some weird decontruction/reconstruction needed to get the
+ // correct parameter format for the theme('username', $voter) call.
+ // Ugly and counter-intuitive but it seems to work.
+ $voter_uid = $vote['uid'];
+ $voter_info = array('account' => user_load($voter_uid));
+
$rows[] = array(
- theme('username', $account),
+ theme('username', $voter_info),
$vote['value'],
- array('data' => format_date($vote['timestamp'], 'small'), 'class' => 'nowrap')
+ array('data' => format_date($vote['timestamp'], 'small'), 'class' => 'nowrap'),
);
}
drupal_set_title(check_plain($node->title));
- $output = theme('table', $header, $rows);
- $output .= theme('pager', NULL, 30);
+ $output = theme('table', array('header' => $header, 'rows' => $rows));
+ //$output .= theme('pager', NULL, 3);
return $output;
}
@@ -252,81 +166,78 @@ function vud_node_tracker() {
}
/**
- * Implementation of hook_link().
+ * The form for the vud_node configurtion.
+ * @see vud_configure_page();
+ *
+ * @return
+ * A drupal form array.
*/
-function vud_node_link($type, $object, $teaser = FALSE) {
- $links = array();
- switch ($type) {
- case 'node':
- $node = &$object;
- $votes_display_mode = variable_get('vud_node_votes', VUD_NODE_DISPLAY_BOTH);
- $node_type = in_array($node->type, variable_get('vud_node_types', array()), TRUE);
- $widget_theme = variable_get('vud_node_widget', 'plain');
- $tag = variable_get('vud_tag', 'vote');
- $view_vud_node_votes_count = user_access('view vote up/down count on nodes') || user_access('use vote up/down on nodes');
- switch ($votes_display_mode) {
- case VUD_NODE_DISPLAY_NO:
- break;
- case VUD_NODE_DISPLAY_TEASER_ONLY:
- if (($teaser == 1) && $node_type && $view_vud_node_votes_count) {
- $links['vud_node_votes_count'] = array(
- 'title' => theme('vud_votes', $node->nid, $type, $tag, $widget_theme),
- 'html' => TRUE,
- );
- }
- break;
- case VUD_NODE_DISPLAY_FULL_ONLY:
- if (($teaser == 0) && $node_type && $view_vud_node_votes_count) {
- $links['vud_node_votes_count'] = array(
- 'title' => theme('vud_votes', $node->nid, $type, $tag, $widget_theme),
- 'html' => TRUE,
- );
- }
- break;
- case VUD_NODE_DISPLAY_BOTH:
- if ($node_type && $view_vud_node_votes_count) {
- $links['vud_node_votes_count'] = array(
- 'title' => theme('vud_votes', $node->nid, $type, $tag, $widget_theme),
- 'html' => TRUE,
- );
- }
- break;
- }
- if ($node_type && variable_get('vud_node_reset', 0) && user_access('reset vote up/down votes')) {
- $tag = variable_get('vud_tag', 'vote');
- $criteria = array(
- 'entity_type' => $type,
- 'entity_id' => $node->nid,
- 'tag' => $tag,
- );
- $criteria += votingapi_current_user_identifier();
- $user_vote = votingapi_select_single_vote_value($criteria);
- if (!is_null($user_vote)) {
- $reset_token = drupal_get_token("votereset/node/$node->nid/$tag/$widget_theme");
- $links['vud_node_votes_reset_link'] = array(
- 'title' => t('Reset your vote'),
- 'href' => "votereset/node/$node->nid/$tag/$widget_theme/$reset_token",
- 'attributes' => array('rel' => 'nofollow'),
- 'html' => TRUE,
- );
- }
- }
- break;
- }
- return $links;
+function vud_node_options_form() {
+ $form = array();
+
+ $form['vud_node_options'] = array(
+ '#markup' => vud_configure_page()
+ );
+ $path = drupal_get_path('module', 'vud');
+ $form['vud_node_options']['#attached']['css'] = array(
+ $path . '/widgets/plain/plain.css',
+ $path . '/widgets/default/default.css',
+ $path . '/widgets/updown/updown.css',
+ $path . '/widgets/upanddown/upanddown.css',
+ $path . '/widgets/thumbs/thumbs.css',
+ $path . '/widgets/alternate/alternate.css',
+ $path . '/vud_node/vud_node_options.css',
+ );
+
+ return $form;
}
/**
- * Implementation of hook_content_extra_fields().
+ * Implements FORM_validate()
+ *
+ * Processes the vud_node_options_form data. The validate function works (is called)
+ * but the the submit function does not. So this function is usded to process
+ * the form data.
+ *
+ * @return
+ * boolean -- true or false. Messages posted either way.
*/
-function vud_node_content_extra_fields($type_name) {
- if (in_array($type_name, variable_get('vud_node_types', array()), TRUE)) {
- $extra = array();
- $extra['vud_node_widget_display'] = array(
- 'label' => t('Vote Up/Down on nodes'),
- 'description' => t('Vote Up/Down module widget.'),
- 'weight' => -10,
- );
- return $extra;
+function vud_node_options_form_validate($form, &$form_state) {
+ // Validate form_token
+ if ($form_state['values']['form_token'] != $_POST['form_token']) {
+ drupal_set_message('Form validation fail');
+ return false;
+ }
+
+ $names = node_type_get_names();
+ $types = array_keys($names);
+ $settings = vud_node_options($types);
+
+ foreach($_POST as $key => $value) {
+ if(array_key_exists($key, $settings)) {
+ $settings[$key] = $value;
+ }
+ }
+
+ // Reset the reset checkbox if the widget is not enabled to begin with.
+ foreach($types as $type) {
+ if ($settings['vud_enable_' . $type] == NULL) {
+ $settings['vud_reset_' . $type] = NULL;
+ $settings['vud_widget_' . $type] = 'updown';
+ }
}
+
+ variable_set('vud_node_config', $settings);
+ drupal_set_message('Voting options have been saved.');
+
+ return true;
+}
+
+/**
+ * Implements FORM_submit()
+ *
+ * For some reason this never fires. It remains a mystery to me.
+ */
+function vud_node_options_form_submit($form, &$form_state) {
+ drupal_set_message('WTF? -- vud_node_options_form_submit() was called! What happened here?');
}
diff --git a/vote_up_down/vud_node/vud_node_options.css b/vote_up_down/vud_node/vud_node_options.css
new file mode 100644
index 0000000..0481fd3
--- /dev/null
+++ b/vote_up_down/vud_node/vud_node_options.css
@@ -0,0 +1,43 @@
+/**
+ * @file
+ * CSS rules for the vud_node configuration page. This file is loaded after
+ * the other vud widget css files and the drupal theme css files have loaded
+ * therefore overriding or tweaking the rules as necessary for the vud_node
+ * configuration page.
+ */
+#vud_options_table { border: 1px solid red; }
+#vud_options_table THEAD > TR+TR > TH { background: none; }
+
+#vud_options_table TH,
+#vud_options_table TD {
+ color: black;
+ padding: 6px 8px;
+ text-align: center;
+ border: none;
+}
+
+#vud_options_table TR TH { background-color: transparent; }
+
+
+#vud_options_table TD+TD { border-left: 1px solid black; }
+#vud_options_table TD+TD+TD+TD+TD { border-left: none }
+
+.vud-widget-alternate { margin-left: 10px }
+.vud-widget-plain { margin-left: 10px; margin-bottom: 18px; }
+.vud-widget-updown { margin-left: 10px }
+.vud-widget-upanddown { margin-left: 17px }
+.vud-widget-alternate { margin-left: 10px; margin-bottom: 24px; }
+
+
+#vud_options_table THEAD TH.widget-gallery {
+ color: black;
+ background-color: inherit;
+ border-bottom: 1px solid black;
+ border-left: 1px solid black;
+}
+
+#vud_options_table TH { text-align: center; vertical-align: bottom; }
+
+#vud_options_table TR:last-child > TH { border-bottom: 1px solid black; }
+
+#vud_options_table TH.lborder { border-left: 1px solid black; }
diff --git a/vote_up_down/vud_node/vud_node_options.inc b/vote_up_down/vud_node/vud_node_options.inc
new file mode 100644
index 0000000..eab20f1
--- /dev/null
+++ b/vote_up_down/vud_node/vud_node_options.inc
@@ -0,0 +1,222 @@
+<?php
+/**
+ * @file
+ * Generate a configuration form for the node options for the Drupal 7
+ * vote_up_down module.
+ *
+ * This is a hand crafted page that was first prototyped as a basic html form
+ * called panel.html in the vote_up_down/vud_node directory. That file was then
+ * updated to panel.php.
+ *
+ * panel.php is the current prototyping page. If a new vote widget is added,
+ * modify and test this page first; then test in the Drupal environment.
+ */
+
+/**
+ * Creates the markup for a table that contains the VUD node configuration
+ * form.
+ *
+ * @return
+ * The html markup for a form containing a table with a sample widget display
+ * along with checkboxes and radio buttons.
+ */
+function vud_configure_page() {
+ // A form is created with a table as a container. The table can be extended
+ // by adding a drupal content type. In the prototype model the types are
+ // represented as an object: types => array('page', 'question', 'remark')
+
+ $str = 'Enable and configure voting for each content type';
+ $heading = (function_exists('t') ? t($str) : $str) .'&hellip;';
+
+ $tableHeaders = <<<PREAMBLE
+<h2>$heading</h2>
+
+<form id="vud_options" method="post" action="panel.php">
+<table id="vud_options_table" summary="" cellspacing="0">
+ <thead>
+ <tr class="firstrow">
+ <th colspan="3" rowspan="2"></th>
+ <th colspan="5" class="widget-gallery" >Vote widget selection</th>
+ </tr>
+
+ <tr>
+ <!-- <th colspan="3"></th> -->
+ <th class="lborder">Default</th>
+ <th>Plain</th>
+ <th>Thumbs</th>
+ <th>Up/Down</th>
+ <th>Alternate</th>
+ </tr>
+ <tr> <!-- widgets -->
+ <th>Content<br/>type</th>
+ <th>Widget<br/>enable</th>
+ <th>Reset<br/>enable</th>
+
+ <th class="lborder">
+ <div class="vud-widget-updown">
+ <div class="updown-score">
+ <span class="updown-current-score">4</span>votes
+ </div>
+ <div class="up-active updown-up" title="Vote up!">+</div>
+ <div class="element-invisible">Vote up!</div>
+ <div class="vud-link-down">
+ <div class="down-inactive updown-down" title="Vote down!">-</div>
+ <div class="element-invisible">Vote down!</div>
+ </div>
+ <div class="vud-link-reset" title="Reset your vote">
+ <div class="reset-active">(reset)</div>
+ </div>
+ </div>
+ </th>
+
+ <th>
+ <div class="vud-widget-plain">
+ <span class="up-inactive" title="Vote up!"></span>
+ <div class="element-invisible"></div>
+ <div class="down-inactive">
+ </div>
+ <div class="vud-link-reset" title="Reset your vote">
+ <div class="reset-active">&hearts;</div>
+ </div>
+ </div>
+ </th>
+
+ <th>
+ <div class="vud-widget-thumbs">
+ <div class="up-score clear-block">
+ <div class="vote-thumb up-active" title="Vote up!"></div>
+ <div class="element-invisible">Vote up!</div>
+ </div>
+ <div class="down-score clear-block">
+ <div class="vud-link-down" title="Vote down!">
+ <div class="vote-thumb down-inactive" title="Vote down!"></div>
+ <div class="element-invisible">Vote down!</div>
+ </div>
+ </div>
+ <div class="vud-link-reset" title="Reset your vote">
+ <div class="reset-active">(reset)</div>
+ </div>
+ <p class="vote-current-score">Points: <strong>3</strong></p>
+ <p class="voted-how">You voted &lsquo;up&rsquo;</p>
+ </div>
+ </th>
+
+ <th>
+ <div class="vud-widget-upanddown">
+ <div class="up-score clear-block">
+ <div class="up-active" title="Vote up!"></div>
+ <div class="element-invisible">Vote up!</div>
+ <span class="up-current-score">5</span>
+ </div>
+ <div class="down-score clear-block">
+ <div class="vud-link-down" title="Vote down!">
+ <div class="down-inactive" title="Vote down!"></div>
+ <div class="element-invisible">Vote down!</div>
+ </div>
+ <span class="down-current-score">-2</span>
+ </div>
+ <div class="vud-link-reset" title="Reset your vote">
+ <div class="reset-active">(reset)</div>
+ </div>
+ </div>
+ </th>
+
+ <th>
+ <div class="vud-widget-alternate">
+ <div class="alternate-votes-display">2</div>
+ <div class="up-active" title="Vote up!"></div>
+ <div class="element-invisible">Vote up!</div>
+ <div class="vud-link-reset" title="Reset your vote">
+ <div class="reset-active">(reset)</div>
+ </div>
+ </div>
+ </th>
+
+ </tr>
+ </thead>
+ <tbody>
+PREAMBLE;
+
+ // Begin the markup.
+ $markup = $tableHeaders;
+
+ // This is the array of vote widgets in the order they appear in the table
+ // headers. This array is hard coded because the table headers are hand coded.
+ // @see vud_widget_get_names() for enumeration of this list.
+ $widgets = array('updown', 'plain', 'thumbs', 'upanddown', 'alternate' );
+
+ if (function_exists('node_type_get_names')) {
+ $names = node_type_get_names();
+ $types = array_keys($names);
+ } else {
+ // This is used for prototyping without drupal.
+ $types = array('page', 'question', 'remark');
+ }
+
+ // Get the current data.
+ $config = function_exists('variable_get') ? variable_get('vud_node_config', vud_node_options($types)) : vud_node_options($types);
+
+ // Create a reference config.
+ $ref = vud_node_options($types);
+
+ // Remove any types from config that are not in the reference.
+ $diff = array_diff_key($config, $ref);
+ foreach ($diff as $key => $value) {
+ unset($config[$key]);
+ }
+
+ // Add any new types in reference that are not in config.
+ $diff = array_diff_key($ref, $config);
+ foreach ($diff as $key => $value) {
+ $config[$key] = $value;
+ }
+
+ foreach($types as $node_type) {
+ if (empty($names)) {
+ $html = '<tr><td>' . $node_type . '</td>' . "\n";
+ } else {
+ $html = '<tr><td>' . $names[$node_type] . '</td>' . "\n";
+ }
+
+ $enabled = $config['vud_enable_' . $node_type] == 'on' ? 'checked="checked"' : '';
+ $html .= '<td><input type="checkbox" name="vud_enable_' . $node_type . '" ' . $enabled . '/></td>' . "\n";
+
+ $reset = $config['vud_reset_' . $node_type] ? 'checked="checked"' : '';
+ $html .= '<td><input type="checkbox" name="vud_reset_' . $node_type . '" ' . $reset . ' /></td>' . "\n";
+
+ foreach($widgets as $widget) {
+ $enabled = $config['vud_widget_' . $node_type] == $widget ? ' checked="checked"' : '';
+ $html .= '<td><input type="radio" name="vud_widget_' . $node_type . '" value="' . $widget . '" ' . $enabled . ' /></td>' . "\n";
+ }
+ $html .= '</tr>' ."\n";
+ $markup .= $html;
+ }
+
+ $markup .= '</tbody></table><div><button type="submit">Save</button></div></form>';
+
+ return $markup;
+}
+
+/**
+ * Create an initialized vud_node options array that is used to record
+ * vud configuration settings for each node type. This array expands (and
+ * contracts) with the addition (and deletion) of content types.
+ *
+ * @param $types
+ * An array of content type machine names. i.e. ('article', 'page')
+ *
+ * @return
+ * An initialized vud_node configuration array.
+ */
+function vud_node_options($node_types) {
+ // Create the default array. This array is merged with the $_POST data that
+ // is returned in vud_node_options_form_validated()
+ $options = array();
+ foreach($node_types as $ntype) {
+ $options['vud_enable_' . $ntype] = NULL;
+ $options['vud_reset_' . $ntype] = NULL;
+ $options['vud_widget_' . $ntype] = 'updown';
+ }
+
+ return $options;
+}
diff --git a/widgets_table.php b/widgets_table.php
new file mode 100644
index 0000000..76c6d1b
--- /dev/null
+++ b/widgets_table.php
@@ -0,0 +1,55 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
+ "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" version="XHTML+RDFa 1.0" dir="ltr"
+ xmlns:content="http://purl.org/rss/1.0/modules/content/"
+ xmlns:dc="http://purl.org/dc/terms/"
+ xmlns:foaf="http://xmlns.com/foaf/0.1/"
+ xmlns:og="http://ogp.me/ns#"
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+ xmlns:sioc="http://rdfs.org/sioc/ns#"
+ xmlns:sioct="http://rdfs.org/sioc/types#"
+ xmlns:skos="http://www.w3.org/2004/02/skos/core#"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
+
+<head profile="http://www.w3.org/1999/xhtml/vocab">
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>Vote Up/Down configure template</title>
+<link rel="stylesheet" type="text/css" href="widgets/plain/plain.css" title="" media="all" />
+<link rel="stylesheet" type="text/css" href="widgets/updown/updown.css" title="" media="all" />
+<link rel="stylesheet" type="text/css" href="widgets/thumbs/thumbs.css" title="" media="all" />
+<link rel="stylesheet" type="text/css" href="widgets/upanddown/upanddown.css" title="" media="all" />
+<link rel="stylesheet" type="text/css" href="widgets/alternate/alternate.css" title="" media="all" />
+<link rel="stylesheet" type="text/css" href="vud_node/vud_node_options.css" title="" media="all" />
+<style type="text/css">
+<!-- used to hide the reset control
+.element-invisible {
+ height: 1px;
+ overflow: hidden;
+}
+-->
+</style>
+</head>
+<body>
+
+<?php
+
+include 'vud_node/vud_node_options.inc';
+
+ error_reporting(E_ALL);
+ ini_set('display_errors', TRUE);
+ ini_set('display_startup_errors', TRUE);
+
+ echo vud_configure_page();
+?>
+
+<pre>
+<?php
+ if(isset($_POST) && !empty($_POST)) {
+ $str = print_r($_POST, TRUE);
+ echo $str;
+ }
+?>
+</pre>
+
+</body>
+</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment