Commit 05d44015 authored by davisben's avatar davisben

remove old files

parent 4263817b
*******************************************************
INSTALL.txt for weight.module for Drupal
by Jeff Robbins ::: jeff /@t\ jjeff /d0t\ com
*******************************************************
INSTALL:
Put the module in your modules directory.
Enable it.
Go to admin/config/content/weight
and select the weight range as well as which node
types should display weight.
Done.
TO CREATE AN ORDERABLE VIEW:
Create a view as normal with a "page" display
Change the view style to "weight changer"
Include Field Weight.
Sort by Weight DESC.
Ensure only appropriate roles have access to the view.
Load up the view, reorder, and save!
*******************************************************
README.txt for weight.module for Drupal
by Jeff Robbins ::: jeff /@t\ jjeff /d0t\ com
maintained by harry slaughter <harry@devbee.com>
*******************************************************
This module adds a weight option to enabled node types. It uses the node
table's 'sticky' column to store weights as well as sticky information (so
that feature is not lost). Nodes with lower weight will float to the top of
lists, while heavier items will sink.
This is useful for sorting non-cronological nodes like bios or ecommerce
products.
Nodes will be sorted first by stickiness, then by weight, then by creation
date.
TO CREATE AN ORDERABLE VIEW (Admins can reweight nodes using drag-and-drop):
* Create a view as normal with a "page" display
* Change the view style to "weight changer"
* Include Field Weight (though not as the first field you include).
* Sort by ASC (Ascending).
* Ensure only appropriate roles have access to the view.
* Load up the view, reorder, and save!
/*
Code borrowed from: http://safari.oreilly.com/0596101694
Wrapper function for constructing a request object.
Parameters:
reqType: The HTTP request type, such as GET or POST.
url: The URL of the server program.
asynch: Whether to send the request asynchronously or not.
*/
function httpRequest(reqType,url,asynch){
//Mozilla-based browsers
if(window.XMLHttpRequest){
request = new XMLHttpRequest( );
} else if (window.ActiveXObject){
request=new ActiveXObject("Msxml2.XMLHTTP");
if (! request){
request=new ActiveXObject("Microsoft.XMLHTTP");
}
}
//the request could still be null if neither ActiveXObject
//initialization succeeded
if(request){
initReq(reqType,url,asynch);
} else {
alert(Drupal.t("Your browser does not permit the use of all " +
"of this application's features!"));
}
}
/* Initialize a request object that is already constructed */
function initReq(reqType,url,bool){
/* Specify the function that will handle the HTTP response */
request.onreadystatechange=null;
request.open(reqType,url,bool);
request.send(null);
}
// $Id: $
(function ($) {
Drupal.behaviors.weightFieldsetSummaries = {
attach: function (context) {
// Provide the summary for the node type form.
$('fieldset#edit-weight-form', context).drupalSetSummary(function(context) {
var vals = [];
// Default weight setting.
vals.push(Drupal.t("Weight: @weight", {'@weight': $("select[name='node_weight'] option:selected", context).text()}));
return Drupal.checkPlain(vals.join(', '));
});
}
};
})(jQuery);
<?php
/**
* @file
* Views template for Weight module.
*/
?>
<table class="<?php print $class; ?>" id="<?php print $id; ?>">
<?php if (!empty($title)) : ?>
<caption><?php print $title; ?></caption>
<?php endif; ?>
<thead>
<tr>
<?php if (count($header)): ?>
<?php foreach ($header as $field => $label): ?>
<th class="views-field views-field-<?php print $fields[$field]; ?>">
<?php print $label; ?>
</th>
<?php endforeach; ?>
<?php endif; ?>
</tr>
</thead>
<tbody>
<?php if (count($rows)): ?>
<?php foreach ($rows as $count => $row): ?>
<tr class="<?php print (($count + 1) % 2 == 0) ? 'even' : 'odd';?> draggable">
<?php foreach ($row as $field => $content): ?>
<td class="views-field views-field-<?php print isset($fields[$field]) ? $fields[$field] : '' ?>">
<?php print $content; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<?php print $submit; ?>
<?php
/**
* @file
* This module uses the sticky column of the node table
* to add weighting to nodes.
*/
function weight_settings_form() {
drupal_add_css(drupal_get_path('module', 'weight') . '/weight.css');
$form = array();
$types = node_type_get_names();
$form['weight_range'] = array(
'#type' => 'radios',
'#title' => t('Node Weight Range'),
'#default_value' => variable_get('weight_range', 20),
'#options' => array(5 => 5, 10 => 10, 20 => 20, 30 => 30, 40 => 40, 50 => 50, 60 => 60, 70 => 70, 80 => 80, 90 => 90),
'#description' => '<p>' . t('This will be the +/- range for node weight.') . '</p>',
);
$form['weight_use_menu'] = array(
'#type' => 'checkbox',
'#title' => t('Use Menu Weight'),
'#default_value' => variable_get('weight_use_menu', FALSE),
'#description' => '<p>' . t('If the node has not been weighted, should we use the menu item weight if there is one?') . '</p>',
);
$form['node'] = array(
'#type' => 'fieldset',
'#title' => t('Node weight selector settings'),
'#description' => '<p>' . t('These settings are for the Weight section of the node form.') . '</p>',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['node']['weight_position'] = array(
'#type' => 'weight',
'#delta' => 10,
'#title' => t('Weight selector position weight'),
'#default_value' => variable_get('weight_position', 0),
'#description' => '<p>' . t('This controls where the selection for node weight goes on the node edit form. If the position is 10 and the user has "administer nodes" permission, it will be added into the "Workflow options."') . '</p>',
);
$form['node']['weight_label'] = array(
'#type' => 'textfield',
'#maxlength' => 64,
'#size' => 64,
'#title' => t('Weight field set label'),
'#default_value' => variable_get('weight_label', t('Node Weight')),
'#description' => '<p>' . t('This determines the legend that is used on the field set. (Maximum length is 64 characters.)') . '</p>',
);
$form['weight_node_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Display On'),
'#default_value' => variable_get('weight_node_types', $types),
'#options' => $types,
'#description' => '<p>' . t('Select the content types to be weighted.
The selected content types will be mass updated to the default weight</p>
<p><i>Note:</i> Unselecting a node type after having changed weights
will result in the loss of those weights. You may want to check the
<a href="@posts_page">content page</a> before unsetting any node types.',
array('@posts_page' => url('admin/content/node'))
) . '</p>',
);
$form['weight_default'] = array(
'#type' => 'weight',
'#delta' => variable_get('weight_range', 20),
'#title' => t('Default weight'),
'#default_value' => variable_get('weight_default', 0),
'#description' => t('If a new content type is selected, this is the weight that will be assigned to those nodes. If you are also changing the range above, "Save" that change first.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
}
function weight_settings_form_submit($form, &$form_state) {
variable_set('weight_range', $form_state['values']['weight_range']);
variable_set('weight_position', $form_state['values']['weight_position']);
variable_set('weight_default', $form_state['values']['weight_default']);
variable_set('weight_use_menu', $form_state['values']['weight_use_menu']);
variable_set('weight_label', $form_state['values']['weight_label']);
// Check for changes in the list.
$before = array_filter(variable_get('weight_node_types', array()));
$after = array_filter($form_state['values']['weight_node_types']);
$del = array_diff($before, $after);
$add = array_diff($after, $before);
// Add weighting to new types.
if ($add) {
weight_old_nodes($add);
}
// Remove weighting from types taken out of the list.
if ($del) {
weight_disable($del);
}
variable_set('weight_node_types', $after);
drupal_set_message(t('Settings updated.'));
}
/**
* Update the sticky value of existing nodes if they are enabled for weights.
* This ensures that they will sort correctly.
*/
function weight_old_nodes($weight_node_types = array()) {
if ($weight_node_types) {
$temp = new stdClass();
$temp->node_weight = variable_get('weight_default', 0);
drupal_set_message(t('Enabling weight for: !types, default weight: !default',
array('!types' => implode(', ', $weight_node_types), '!default' => $temp->node_weight)));
// Get default for non-sticky nodes;
$temp->sticky = 0;
_weight_encode($temp);
$not_sticky = $temp->sticky;
// Get default for sticky nodes;
$temp->sticky = 1;
_weight_encode($temp);
$is_sticky = $temp->sticky;
$count = db_update('node')
->fields(array('sticky' => $is_sticky))
->condition('type', $weight_node_types, 'IN')
->execute();
$count += db_update('node')
->fields(array('sticky' => $not_sticky))
->condition('type', $weight_node_types, 'IN')
->execute();
drupal_set_message(t('@count nodes weight enabled.', array('@count' => $count)));
}
}
/**
* Set nodes back to normal sticky values if they are not enabled for weights.
*/
function weight_disable($weight_node_types = array()) {
if ($weight_node_types) {
drupal_set_message(t('Disabling weight for: !types', array('!types' => implode(', ', $weight_node_types))));
$count = db_update('node')
->fields(array('sticky' => 1))
->condition('sticky', 1, '>')
->condition('type', $weight_node_types, 'IN')
->execute();
$count += db_update('node')
->fields(array('sticky' => 0))
->condition('sticky', 0, '<')
->condition('type', $weight_node_types, 'IN')
->execute();
}
else {
$count = db_update('node')
->fields(array('sticky' => 1))
->condition('sticky', 1, '>')
->execute();
$count += db_update('node')
->fields(array('sticky' => 0))
->condition('sticky', 0, '<')
->execute();
}
drupal_set_message(t('@count nodes weight disabled.', array('@count' => $count)));
}
/**
* @file style sheet for Weight module.
*/
.weight-selector {
display: inline;
float: left;
position: relative;
}
#node-admin-nodes td a {
margin-right: 3px;
}
#weight-settings-form .form-radios, #weight-settings-form .form-radios .form-item {
display: inline;
margin-top: 0;
margin-left: 2em;
}
#weight-settings-form .form-text,
#weight-settings-form .form-select,
#weight-settings-form .form-checkboxes .form-item,
#weight-settings-form .form-radios .form-item {
margin-left: 1em;
}
#weight-settings-form .form-radios .form-item label {
}
#weight-settings-form .form-checkboxes .form-item label {
width: 24%;
float: left;
}
#weight-settings-form .description {
clear: both;
}
name = Weight
description = Add weight-based sorting to nodes.
core = 7.x
files[] = weight_handler_field_sticky.inc
files[] = weight_handler_filter_sticky.inc
files[] = weight_handler_filter_weight.inc
files[] = weight_handler_sort.inc
<?php
/**
* @file
* This module uses the sticky column of the node table
* to add weighting to nodes.
*/
/**
* Implements hook_install().
*/
function weight_install() {
// change taxonomy_index sticky field to type INT from TINYINT to hold larger weight values.
$spec = array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
);
db_change_field('taxonomy_index', 'sticky', 'sticky', $spec);
}
/**
* Implements hook_uninstall().
*/
function weight_uninstall() {
// We need to unset any weighted nodes and reset sticky to normal values.
$weight_node_types = variable_get('weight_node_types', array());
if ($weight_node_types) {
db_update('node')
->fields(array('sticky' => 1))
->condition('sticky', 1, '>')
->condition('type', $weight_node_types, 'IN')
->execute();
db_update('node')
->fields(array('sticky' => 0))
->condition('sticky', 0, '<')
->condition('type', $weight_node_types, 'IN')
->execute();
}
// reset sticky values in taxonomy_index table.
db_update('taxonomy_index')
->fields(array('sticky' => 1))
->condition('sticky', 1, '>')
->execute();
db_update('taxonomy_index')
->fields(array('sticky' => 0))
->condition('sticky', 0, '<')
->execute();
// reset taxonomy_index field to original type.
$spec = array(
'description' => 'Boolean indicating whether the node is sticky.',
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'size' => 'tiny',
);
db_change_field('taxonomy_index', 'sticky', 'sticky', $spec);
// Delete our variables.
variable_del('weight_node_types');
variable_del('weight_range');
variable_del('weight_use_menu');
}
/**
* Implements hook_schema_alter().
*/
function weight_schema_alter(&$schema) {
$schema['taxonomy_index']['fields']['sticky'] = array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
);
}
/**
* Change {taxonomy_index} stick field to type INT from TINYINT.
*/
function weight_update_7100() {
$spec = array(
'type' => 'int',
'not null' => FALSE,
'default' => 0,
);
db_change_field('taxonomy_index', 'sticky', 'sticky', $spec);
}
This diff is collapsed.
<?php
/**
* @file
* Views2 support for Weight module.
*/
/**
* Implements hook_views_data().
*/
function weight_views_data() {
$data['node_weight'] = array(
'table' => array(
'group' => t('Weight'),
'join' => array(
'node' => array(
'table' => 'node',
'left_field' => 'nid',
'field' => 'nid',
),
),
),
'weight' => array(
'real field' => 'sticky',
'title' => t('Weight'), // The item it appears as on the UI,
'help' => t('The node weight.'), // The help that appears on the UI,
'field' => array(
'handler' => 'weight_handler_field_sticky',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'weight_handler_filter_weight',
'label' => t('Weight'),
),
'sort' => array(
'handler' => 'weight_handler_sort',
),
),
);
$data['node_weight_stick'] = array(
'table' => array(
'group' => t('Weight'),
'join' => array(
'node' => array(
'table' => 'node',
'left_field' => 'nid',
'field' => 'nid',
),
),
),
'weight_stick' => array(
'real field' => 'sticky',
'title' => t('Weighted Sticky'), // The item it appears as on the UI,
'help' => t('Checks if something really is sticky.'), // The help that appears on the UI,
'filter' => array(
'handler' => 'weight_handler_filter_sticky',
'label' => t('Weighted Sticky'),
'type' => 'yes-no',
),
),
);
return $data;
}
/**
* Implements hook_views_plugins();
*/
function weight_views_plugins() {
return array(
'style' => array(
'weight' => array(
'title' => t('Weight Changer'),
'help' => t('Displays rows in a table which allows weight change. Be sure to add the Weight field and Sort by Weight.'),
'handler' => 'views_plugin_style_table',
'parent' => 'table',
'path' => drupal_get_path('module', 'weight'),
'theme' => 'weight_view_weight',
'uses row plugin' => FALSE,
'uses fields' => TRUE,
'uses options' => TRUE,
'type' => 'normal',
),
),
);
}
/**
* Implements hook_views_handlers().
*/
function weight_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'weight') /* .'/handlers' */,
),
'handlers' => array(
'weight_handler_field_sticky' => array(
'parent' => 'views_handler_field_numeric',
),
'weight_handler_sort' => array(
'parent' => 'views_handler_sort',
),
'weight_handler_filter_sticky' => array(
'parent' => 'views_handler_filter_boolean_operator',
),
'weight_handler_filter_weight' => array(
'parent' => 'views_handler_filter_numeric',
),
),
);
}
/**
* Display a view as a weight changing table.
*/
function theme_weight_view_weight(&$vars) {
$view = $vars['view'];
$result = $vars['result'] = $vars['rows'];
$rows = array();
$options = $view->style_plugin->options;
$handler = $view->style_plugin;
$fields = &$view->field;
$columns = $handler->sanitize_columns($options['columns'], $fields);
$active = !empty($handler->active) ? $handler->active : '';
$order = !empty($handler->order) ? $handler->order : 'asc';
$query = tablesort_get_query_parameters();
$renders = array();
$view->row_index = 0;
$keys = array_keys($view->field);
foreach ($result as $count => $row) {
foreach ($keys as $id) {
$renders[$count][$id] = $view->field[$id]->theme($row);
}
$view->row_index = $count + 1;
}
unset($view->row_index);
foreach ($columns as $field => $column) {
// render the header labels
if ($field == $column && empty($fields[$field]->options['exclude'])) {
$label = check_plain(!empty($fields[$field]) ? $fields[$field]->label() : '');
if (empty($options['info'][$field]['sortable']) || !$fields[$field]->click_sortable()) {
$vars['header'][$field] = $label;
}
else {
// @todo -- make this a setting
$initial = 'asc';
if ($active == $field && $order == 'asc') {
$initial = 'desc';
}
$title = t('sort by @s', array('@s' => $label));
if ($active == $field) {
$label .= theme('tablesort_indicator', array('style' => $initial));
}
$query['order'] = urlencode($field);
$query['sort'] = $initial;
$link_options = array(
'html' => TRUE,
'attributes' => array('title' => $title),
'query' => $query,
);
$vars['header'][$field] = l($label, $_GET['q'], $link_options);
}
}
// Create a second variable so we can easily find what fields we have and what the
// CSS classes should be.
$vars['fields'][$field] = drupal_clean_css_identifier($field);
if ($active == $field) {
$vars['fields'][$field] .= ' active';
}
// Render each field into its appropriate column.
foreach ($result as $num => $row) {
if (!empty($fields[$field]) && empty($fields[$field]->options['exclude'])) {
$field_output = $renders[$num][$field];
// Don't bother with separators and stuff if the field does not show up.
if (empty($field_output) && !empty($vars['rows'][$num]->$column)) {
continue;
}
// Place the field into the column, along with an optional separator.
if (!empty($vars['rows'][$num]->$column)) {
if (!empty($options['info'][$column]['separator'])) {
$vars['rows'][$num][$column] .= filter_xss_admin($options['info'][$column]['separator']);
}
}
else {
$vars['rows'][$num]->$column = $field_output;
}
}
}
}
$vars['class'] = 'views-table-weight';
if (!empty($options['sticky'])) {
drupal_add_js('misc/tableheader.js');
$vars['class'] .= ' sticky-enabled';
}
// Pass along the nid.
foreach ($view->result as $count => $item) {
$vars['rows'][$count]->nid_hidden = $item->nid;
}
$id = $view->name . '_drag';
$form = drupal_get_form('weight_view_weight_form', $vars['header'], $vars['rows'], $vars['fields'], $vars['class'], $id, $vars['title']);
return render($form);
}
/**
* Display a view as a weight changing table.
*/
function weight_view_weight_form($form, &$form_state, $header, $rows, $fields, $class, $id, $title) {
// Make this form draggable
drupal_add_tabledrag($id, 'order', 'sibling', 'weight_dragger');
$form = array('#tree' => TRUE);
$form['#variables'] = array(
'header' => $header,
'class' => $class,
'fields' => $fields,
'id' => $id,
'title' => $title,
);
foreach ($rows as $count => $row) {
if (is_numeric($count)) {
foreach ($row as $field => $content) {
$nid = $row->nid_hidden;
if (drupal_substr($field, 0, 6) == 'weight') {
$form['rows'][$count][$field] = array(
'#default_value' => $content,
'#type' => 'weight',
'#delta' => variable_get('weight_range', 20),
);
}
elseif ($field != 'nid_hidden') {
$form['rows'][$count][$field] = array(
'#type' => 'value',
'#value' => $content,
);
}
else {
$form['rows'][$count][$field] = array(
'#type' => 'hidden',
'#value' => $content,
);
}
}
}
foreach ($form['rows'][$count] as $key => $frow) {
if (!array_key_exists($key, $header) && $key != 'nid_hidden') {
unset($form['rows'][$count][$key]);
}
}
}
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
return $form;
}
/**
* Save the changed weights.
*/
function weight_view_weight_form_submit($form, &$form_state) {
foreach ($form_state['values']['rows'] as $count => $value) {
$weight = $value['weight'];
$nid = $value['nid_hidden'];
$node = node_load($nid);
if ($node->sticky) {
$node->sticky = (-1 * $weight) + 100;
}
// Unweighted non-sticky nodes will have a value of -100.
else {
$node->sticky = (-1 * $weight