View source
<?php
define('NODEQUEUE_OK', 0);
define('NODEQUEUE_INVALID_POSITION', 1);
define('NODEQUEUE_INVALID_NID', 2);
define('NODEQUEUE_DUPLICATE_POSITION', 3);
function nodequeue_perm() {
return array(
'manipulate queues',
'administer nodequeue',
'manipulate all queues',
);
}
function nodequeue_menu() {
$items = array();
$admin_access = array(
'administer nodequeue',
);
$items['admin/content/nodequeue'] = array(
'title' => 'Nodequeue',
'page callback' => 'nodequeue_view_queues',
'access callback' => '_nodequeue_access_admin_or_manipulate',
'description' => 'Create and maintain simple nodequeues.',
'file' => 'includes/nodequeue.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
$items['admin/content/nodequeue/list'] = array(
'title' => 'List',
'page callback' => 'nodequeue_view_queues',
'access callback' => '_nodequeue_access_admin_or_manipulate',
'file' => 'includes/nodequeue.admin.inc',
'weight' => -1,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/content/nodequeue/settings'] = array(
'title' => 'Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'nodequeue_admin_settings',
),
'access arguments' => $admin_access,
'file' => 'includes/nodequeue.admin.inc',
'type' => MENU_LOCAL_TASK,
);
$items['nodequeue/autocomplete'] = array(
'title' => 'Autocomplete',
'page callback' => 'nodequeue_autocomplete',
'access callback' => '_nodequeue_access_admin_or_manipulate',
'file' => 'includes/nodequeue.admin.inc',
'type' => MENU_CALLBACK,
);
$info = nodequeue_api_info();
foreach ($info as $key => $data) {
$items['admin/content/nodequeue/add/' . $key] = array(
'title' => 'Add @type',
'title arguments' => array(
'@type' => strtolower($data['title']),
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'nodequeue_edit_queue_form',
$key,
),
'access arguments' => $admin_access,
'file' => 'includes/nodequeue.admin.inc',
'type' => MENU_LOCAL_TASK,
);
}
$items['node/%node/nodequeue'] = array(
'title' => '@tab',
'title arguments' => array(
'@tab' => variable_get('nodequeue_tab_name', 'Nodequeue'),
),
'page callback' => 'nodequeue_node_tab',
'page arguments' => array(
1,
),
'access callback' => 'nodequeue_node_tab_access',
'access arguments' => array(
1,
),
'file' => 'includes/nodequeue.admin.inc',
'weight' => 5,
'type' => MENU_LOCAL_TASK,
);
$items['admin/content/nodequeue/%nodequeue'] = array(
'page callback' => 'nodequeue_admin_view',
'page arguments' => array(
3,
),
'access callback' => 'nodequeue_queue_access',
'access arguments' => array(
3,
),
'file' => 'includes/nodequeue.admin.inc',
'type' => MENU_CALLBACK,
);
$items['admin/content/nodequeue/%nodequeue/view'] = array(
'title' => 'View',
'page callback' => 'nodequeue_admin_view',
'page arguments' => array(
3,
),
'access callback' => 'nodequeue_queue_access',
'access arguments' => array(
3,
),
'file' => 'includes/nodequeue.admin.inc',
'weight' => -10,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/content/nodequeue/%nodequeue/view/%subqueue'] = array(
'title' => 'View',
'page callback' => 'nodequeue_admin_view',
'page arguments' => array(
3,
5,
),
'access callback' => 'nodequeue_queue_access',
'access arguments' => array(
3,
5,
),
'file' => 'includes/nodequeue.admin.inc',
'weight' => -10,
'tab parent' => 'admin/content/nodequeue/%',
'type' => MENU_LOCAL_TASK,
);
$items['admin/content/nodequeue/%nodequeue/edit'] = array(
'title' => 'Edit queue',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'nodequeue_edit_queue_form',
3,
),
'access arguments' => $admin_access,
'file' => 'includes/nodequeue.admin.inc',
'type' => MENU_LOCAL_TASK,
);
$items['admin/content/nodequeue/%nodequeue/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'nodequeue_admin_delete',
3,
),
'access arguments' => $admin_access,
'file' => 'includes/nodequeue.admin.inc',
'weight' => 5,
'type' => MENU_CALLBACK,
);
$items["admin/content/nodequeue/%nodequeue/add/%subqueue/%node"] = array(
'page callback' => 'nodequeue_admin_add_node',
'page arguments' => array(
3,
5,
6,
),
'access callback' => 'nodequeue_node_and_queue_access',
'access arguments' => array(
6,
3,
5,
),
'file' => 'includes/nodequeue.admin.inc',
'type' => MENU_CALLBACK,
);
$items["admin/content/nodequeue/%nodequeue/remove-node/%subqueue/%node"] = array(
'page callback' => 'nodequeue_admin_remove_node',
'page arguments' => array(
3,
5,
6,
),
'access callback' => 'nodequeue_node_and_queue_access',
'access arguments' => array(
6,
3,
5,
),
'file' => 'includes/nodequeue.admin.inc',
'type' => MENU_CALLBACK,
);
$items["admin/content/nodequeue/%nodequeue/clear/%subqueue"] = array(
'title' => 'Clear',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'nodequeue_clear_confirm',
3,
5,
),
'access callback' => 'nodequeue_queue_access',
'access arguments' => array(
3,
5,
),
'file' => 'includes/nodequeue.admin.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
function nodequeue_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'delete':
$result = db_query("SELECT qid, sqid FROM {nodequeue_nodes} WHERE nid = %d", $node->nid);
while ($obj = db_fetch_object($result)) {
$queues = nodequeue_load_queues(array(
$obj->qid,
));
$queue = array_shift($queues);
if (!$queue->i18n || isset($node->tnid) && empty($node->tnid)) {
nodequeue_subqueue_remove_node($obj->sqid, $node->nid);
}
}
break;
case 'translation_change':
if (isset($node->translation_change)) {
$content_id = $node->translation_change['new_tnid'] == 0 ? $node->translation_change['remaining_nid'] : $node->translation_change['new_tnid'];
db_query("UPDATE {nodequeue_nodes} SET nid = %d WHERE nid = %d", $content_id, $node->translation_change['old_tnid']);
}
}
}
function nodequeue_link($type, $node = NULL, $teaser = FALSE) {
$links = array();
if ($type == 'node' && variable_get('nodequeue_links', FALSE) && user_access('manipulate queues')) {
$queues = nodequeue_load_queues_by_type($node->type, 'links');
$subqueues = nodequeue_get_subqueues_by_node($queues, $node);
if (empty($subqueues)) {
return;
}
ksort($subqueues);
foreach ($subqueues as $id => $subqueue) {
unset($subqueues[$id]->position);
}
if (!module_exists('translation')) {
nodequeue_set_subqueue_positions($subqueues, $node->nid);
}
foreach ($subqueues as $subqueue) {
$queue = $queues[$subqueue->qid];
$id = nodequeue_get_content_id($queue, $node);
if (module_exists('translation')) {
$subqueue = array(
$subqueue->sqid => $subqueue,
);
nodequeue_set_subqueue_positions($subqueue, $id);
$subqueue = array_shift($subqueue);
}
$query_string = nodequeue_get_query_string($id, TRUE);
$class = 'nodequeue-ajax-toggle nodequeue-toggle-q-' . $queue->qid . ' nodequeue-toggle-sq-' . $subqueue->sqid . ' nodequeue-toggle-ref-' . $subqueue->reference;
if (!isset($subqueue->position)) {
$links[$class] = array(
'title' => nodequeue_title_substitute($queue->link, $queue, $subqueue),
'href' => "admin/content/nodequeue/{$queue->qid}/add/{$subqueue->sqid}/{$id}",
'attributes' => array(
'class' => $class . ' toggle-add',
),
'query' => $query_string,
'purl' => array(
'disabled' => TRUE,
),
);
}
elseif ($queue->link_remove) {
$links[$class] = array(
'title' => nodequeue_title_substitute($queue->link_remove, $queue, $subqueue),
'href' => "admin/content/nodequeue/{$queue->qid}/remove-node/{$subqueue->sqid}/{$id}",
'attributes' => array(
'class' => $class . ' toggle-remove',
),
'query' => $query_string,
'purl' => array(
'disabled' => TRUE,
),
);
}
}
drupal_add_js(drupal_get_path('module', 'nodequeue') . '/nodequeue.js');
drupal_add_css(drupal_get_path('module', 'nodequeue') . '/nodequeue.css');
}
return $links;
}
function nodequeue_forms($form_id) {
$forms = array();
if (strpos($form_id, 'nodequeue_arrange_subqueue_form_') === 0) {
$forms[$form_id] = array(
'callback' => 'nodequeue_arrange_subqueue_form',
);
}
return $forms;
}
function nodequeue_action_info() {
return array(
'nodequeue_add_action' => array(
'type' => 'node',
'description' => t('Add to Nodequeues'),
'configurable' => TRUE,
'hooks' => array(
'nodeapi' => array(
'insert',
'update',
),
),
),
'nodequeue_remove_action' => array(
'type' => 'node',
'description' => t('Remove from Nodequeues'),
'configurable' => TRUE,
'hooks' => array(
'nodeapi' => array(
'insert',
'update',
),
),
),
);
}
function nodequeue_theme() {
return array(
'nodequeue_arrange_subqueue_form' => array(
'arguments' => array(
'form',
),
),
'nodequeue_subqueue_empty_text' => array(
'arguments' => array(),
),
'nodequeue_subqueue_full_text' => array(
'arguments' => array(),
),
'nodequeue_subqueue_count_text' => array(
'arguments' => array(),
),
);
}
function nodequeue_elements() {
$type = array();
$type['position'] = array(
'#input' => TRUE,
'#delta' => 10,
'#default_value' => 0,
'#process' => array(
'process_position',
'form_expand_ahah',
),
);
return $type;
}
function process_position($element) {
for ($n = 1; $n <= $element['#delta']; $n++) {
$positions[$n] = $n;
}
$element['#options'] = $positions;
$element['#options']['r'] = t('Remove');
$element['#type'] = 'select';
$element += _element_info('select');
return $element;
}
function position_value(&$form) {
if (isset($form['#default_value'])) {
$form['#value'] = $form['#default_value'];
}
else {
$form['#value'] = 1;
}
}
function nodequeue_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'nodequeue') . '/includes/views',
);
}
function nodequeue_form_apachesolr_search_bias_form_alter(&$form, $form_state) {
$weights = drupal_map_assoc(array(
'21.0',
'13.0',
'8.0',
'5.0',
'3.0',
'2.0',
'1.0',
'0.8',
'0.5',
'0.3',
'0.2',
'0.1',
));
$weights['0'] = t('Normal');
$queues = nodequeue_load_subqueues_by_queue(array_keys(nodequeue_get_all_qids()));
$form['biasing']['nodequeue_boost'] = array(
'#type' => 'fieldset',
'#title' => t('Nodequeue Biasing'),
'#weight' => -5,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['biasing']['nodequeue_boost']['nodequeue_apachesolr_boost'] = array(
'#type' => 'item',
'#description' => t("Specify to bias the search result when a node is in a queue. Any value except <em>Normal</em> will increase the socre for the given queue in the search results"),
);
foreach ($queues as $sqid => $queue) {
$boost = variable_get("nodequeue_apachesolr_boost_{$sqid}", 0);
$form['biasing']['nodequeue_boost']['nodequeue_apachesolr_boost']["nodequeue_apachesolr_boost_{$sqid}"] = array(
'#type' => 'select',
'#title' => t('Weight for %title nodequeue', array(
'%title' => $queue->title,
)),
'#options' => $weights,
'#default_value' => $boost,
);
}
}
function nodequeue_apachesolr_update_index(&$document, $node) {
if (empty($document)) {
return;
}
$queues = nodequeue_load_queues(array_keys(nodequeue_get_all_qids()));
$subqueues = nodequeue_get_subqueues_by_node($queues, $node);
nodequeue_set_subqueue_positions($subqueues, $node->nid);
if (is_array($subqueues)) {
foreach ($subqueues as $sqid => $subqueue) {
if (!empty($subqueue->position)) {
$key = _nodequeue_solr_qid_key();
$document
->setMultiValue($key, $sqid);
}
}
}
}
function _nodequeue_solr_qid_key() {
$qid_key = array(
'index_type' => 'sint',
'multiple' => TRUE,
'name' => "nodequeue",
);
return apachesolr_index_key($qid_key);
}
function nodequeue_apachesolr_modify_query($query, &$params, $caller) {
$queues = nodequeue_load_subqueues_by_queue(array_keys(nodequeue_get_all_qids()));
$added = FALSE;
foreach ($queues as $sqid => $queue) {
$boost = variable_get("nodequeue_apachesolr_boost_{$sqid}", 0);
if (!empty($boost)) {
$params['bq'][] = _nodequeue_solr_qid_key() . ":{$sqid}^{$boost}";
if (!$added) {
$params['facet.field'][] = _nodequeue_solr_qid_key();
$added = TRUE;
}
}
}
}
class nodequeue_queue {
var $title = '';
var $size = 0;
var $link = '';
var $link_remove = '';
var $roles = array();
var $types = array();
var $show_in_links = TRUE;
var $show_in_tab = TRUE;
var $show_in_ui = TRUE;
var $reference = 0;
var $i18n = 0;
var $subqueue_title = '';
var $reverse = 0;
var $subqueues = array();
var $subqueue = NULL;
var $current = NULL;
function nodequeue_queue($type) {
$this->owner = $type;
}
}
function nodequeue_load_queues_by_type($type, $location = NULL, $account = NULL, $bypass_cache = FALSE) {
$qids = nodequeue_get_qids($type, $account, $bypass_cache);
if ($location) {
nodequeue_filter_qids($qids, $location);
}
return nodequeue_load_queues(array_keys($qids), $bypass_cache);
}
function nodequeue_load_queue_by_name($name) {
$map = nodequeue_get_qid_map();
if (isset($map[$name])) {
$queues = nodequeue_load_queues(array(
$map[$name],
));
if ($queues) {
return current($queues);
}
}
return array();
}
function nodequeue_get_qid_map() {
static $map = array();
if (!$map) {
$result = db_query("SELECT qid, name FROM {nodequeue_queue}");
while ($get = db_fetch_object($result)) {
$map[$get->name] = $get->qid;
}
}
return $map;
}
function nodequeue_filter_qids(&$qids, $location) {
$var = "show_in_{$location}";
foreach ($qids as $qid => $info) {
if (empty($info->{$var})) {
unset($qids[$qid]);
}
}
}
function nodequeue_get_qids($type, $account = NULL, $bypass_cache = FALSE) {
if (!isset($account)) {
global $user;
$account = $user;
}
static $cache = array();
if ($bypass_cache || !isset($cache[$type])) {
$roles_join = $roles_where = '';
$roles = array();
if (!user_access('manipulate all queues', $account)) {
$roles_join = "INNER JOIN {nodequeue_roles} nr ON nr.qid = nq.qid ";
$roles = array_keys((array) $account->roles) + array(
DRUPAL_AUTHENTICATED_RID,
);
$roles_where .= "AND nr.rid IN (" . db_placeholders($roles, 'int') . ")";
}
$sql = 'SELECT nq.qid, nq.show_in_tab, nq.show_in_links, nq.show_in_ui, nq.i18n ' . 'FROM {nodequeue_queue} nq ' . 'INNER JOIN {nodequeue_types} nt ON nt.qid = nq.qid ' . $roles_join . "WHERE nt.type = '%s' " . $roles_where;
$result = db_query($sql, array_merge(array(
$type,
), $roles));
$qids = array();
while ($qid = db_fetch_object($result)) {
$qids[$qid->qid] = $qid;
}
$cache[$type] = $qids;
}
return $cache[$type];
}
function nodequeue_get_all_qids($page_size = 0, $pager_element = 0, $bypass_cache = FALSE) {
static $cache = array();
if ($bypass_cache || empty($cache[$page_size])) {
$sql = 'SELECT nq.qid ' . 'FROM {nodequeue_queue} nq ' . 'WHERE nq.show_in_ui = 1 ';
$count_sql = 'SELECT COUNT(q.qid) FROM {nodequeue_queue} q WHERE q.show_in_ui = 1 ';
if ($page_size) {
$result = pager_query($sql, $page_size, $pager_element, $count_sql);
}
else {
$result = db_query($sql, $count_sql);
}
$qids = array();
while ($qid = db_fetch_object($result)) {
$qids[$qid->qid] = $qid->qid;
}
$cache[$page_size] = $qids;
}
return $cache[$page_size];
}
function nodequeue_load_queues($qids = array(), $bypass_cache = FALSE) {
static $cache = array();
$to_load = $loaded = array();
foreach ($qids as $qid) {
if ($bypass_cache || !isset($cache[$qid])) {
$to_load[] = $qid;
}
}
if (!empty($to_load)) {
$placeholders = db_placeholders($to_load, 'int');
$result = db_query("SELECT q.*, (SELECT count(*) FROM {nodequeue_subqueue} s WHERE q.qid = s.qid) AS subqueues FROM {nodequeue_queue} q WHERE q.qid IN ({$placeholders})", $to_load);
while ($queue = db_fetch_object($result)) {
$loaded[$queue->qid] = $queue;
$loaded[$queue->qid]->types = array();
$loaded[$queue->qid]->roles = array();
$loaded[$queue->qid]->count = 0;
}
$result = db_query("SELECT qid, rid FROM {nodequeue_roles} WHERE qid IN ({$placeholders})", $to_load);
while ($obj = db_fetch_object($result)) {
$loaded[$obj->qid]->roles[] = $obj->rid;
}
$result = db_query("SELECT qid, type FROM {nodequeue_types} WHERE qid IN ({$placeholders})", $to_load);
while ($obj = db_fetch_object($result)) {
$loaded[$obj->qid]->types[] = $obj->type;
}
drupal_alter('nodequeue', $loaded, 'load_queues');
}
if ($bypass_cache) {
return $loaded;
}
else {
if (!empty($loaded)) {
$cache += $loaded;
}
$queues = array();
foreach ($qids as $qid) {
if (isset($cache[$qid])) {
$queues[$qid] = $cache[$qid];
}
}
return $queues;
}
}
function nodequeue_load($qid) {
$queues = nodequeue_load_queues(array(
$qid,
));
return !empty($queues) ? array_shift($queues) : array();
}
function subqueue_load($sqid) {
if (!$sqid) {
return NULL;
}
$queues = nodequeue_load_subqueues(array(
$sqid,
));
return !empty($queues) ? array_shift($queues) : array();
}
function nodequeue_load_subqueues($sqids, $bypass_cache = FALSE) {
static $cache = array();
$to_load = array();
foreach ($sqids as $sqid) {
if ($bypass_cache || !isset($cache[$sqid])) {
$to_load[] = $sqid;
}
}
if (!empty($to_load)) {
$placeholders = db_placeholders($to_load, 'int');
$result = db_query("SELECT s.*, (SELECT count(*) FROM {nodequeue_nodes} n WHERE n.sqid = s.sqid) AS count FROM {nodequeue_subqueue} s WHERE s.sqid IN ({$placeholders})", $to_load);
while ($obj = db_fetch_object($result)) {
$cache[$obj->sqid] = $obj;
}
}
foreach ($sqids as $sqid) {
if (isset($cache[$sqid])) {
$subqueues[$sqid] = $cache[$sqid];
}
}
return $subqueues;
}
function nodequeue_load_subqueue($sqid, $bypass_cache = FALSE) {
$subqueues = nodequeue_load_subqueues(array(
$sqid,
), $bypass_cache);
if ($subqueues) {
return array_shift($subqueues);
}
}
function nodequeue_load_subqueues_by_queue($qids, $page_size = 0) {
if (is_numeric($qids)) {
$qids = array(
$qids,
);
}
if (empty($qids)) {
return array();
}
$query = "SELECT s.*, (SELECT count(*) FROM {nodequeue_nodes} n WHERE n.sqid = s.sqid) AS count FROM {nodequeue_subqueue} s WHERE s.qid IN (" . db_placeholders($qids, 'int') . ")";
if ($page_size) {
$result = pager_query($query, $page_size, 0, $qids);
}
else {
$result = db_query($query, $qids);
}
$subqueues = array();
while ($subqueue = db_fetch_object($result)) {
$subqueues[$subqueue->sqid] = $subqueue;
}
return $subqueues;
}
function nodequeue_load_subqueues_by_reference($references, $bypass_cache = FALSE) {
static $cache = array();
$subqueues = array();
if ($bypass_cache) {
$cache = array();
}
$keys = $values = array();
foreach ($references as $qid => $qid_references) {
$keys[$qid] = array();
$qid_values = array();
foreach ($qid_references as $reference) {
if (isset($cache[$qid][$reference])) {
$subqueues[$cache[$qid][$reference]->sqid] = $cache[$qid][$reference];
}
else {
$keys[$qid][] = "'%s'";
$qid_values[] = $reference;
}
}
if (!empty($keys[$qid])) {
$values = array_merge($values, array(
$qid,
), $qid_values);
}
else {
unset($keys[$qid]);
}
}
if (!empty($keys)) {
$where = '';
foreach ($keys as $key_list) {
if ($where) {
$where .= ' OR ';
}
$where .= 's.qid = %d AND s.reference IN (' . implode(', ', $key_list) . ')';
}
$result = db_query("SELECT s.*, (SELECT count(*) FROM {nodequeue_nodes} n WHERE n.sqid = s.sqid) AS count FROM {nodequeue_subqueue} s WHERE " . $where, $values);
while ($subqueue = db_fetch_object($result)) {
$cache[$subqueue->qid][$subqueue->reference] = $subqueues[$subqueue->sqid] = $subqueue;
}
}
return $subqueues;
}
function nodequeue_save(&$queue) {
if (!isset($queue->qid)) {
db_query("INSERT INTO {nodequeue_queue} (title, name, subqueue_title, size, link, link_remove, owner, show_in_links, show_in_tab, show_in_ui, i18n, reverse, reference) VALUES ('%s', '%s', '%s', %d, '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s')", $queue->title, $queue->name, $queue->subqueue_title, $queue->size, $queue->link, $queue->link_remove, $queue->owner, $queue->show_in_links, $queue->show_in_tab, $queue->show_in_ui, $queue->i18n, $queue->reverse, $queue->reference);
$queue->qid = db_last_insert_id('nodequeue_queue', 'qid');
if (function_exists('views_invalidate_cache')) {
views_invalidate_cache();
}
}
else {
if (isset($queue->name) && !empty($queue->name)) {
db_query("UPDATE {nodequeue_queue} SET size = %d, title = '%s', subqueue_title = '%s', link = '%s', link_remove = '%s', owner = '%s', show_in_links = %d, show_in_tab = %d, show_in_ui = %d, i18n = %d, reverse = %d, reference = '%s' WHERE qid = %d", $queue->size, $queue->title, $queue->subqueue_title, $queue->link, $queue->link_remove, $queue->owner, $queue->show_in_links, $queue->show_in_tab, $queue->show_in_ui, $queue->i18n, $queue->reverse, $queue->reference, $queue->qid);
}
else {
db_query("UPDATE {nodequeue_queue} SET size = %d, title = '%s', name = '%s', subqueue_title = '%s', link = '%s', link_remove = '%s', owner = '%s', show_in_links = %d, show_in_tab = %d, show_in_ui = %d, i18n = %d, reverse = %d, reference = '%s' WHERE qid = %d", $queue->size, $queue->title, $queue->name, $queue->subqueue_title, $queue->link, $queue->link_remove, $queue->owner, $queue->show_in_links, $queue->show_in_tab, $queue->show_in_ui, $queue->i18n, $queue->reverse, $queue->reference, $queue->qid);
}
db_query("DELETE FROM {nodequeue_roles} WHERE qid = %d", $queue->qid);
db_query("DELETE FROM {nodequeue_types} WHERE qid = %d", $queue->qid);
}
if (is_array($queue->roles)) {
foreach ($queue->roles as $rid) {
db_query("INSERT INTO {nodequeue_roles} (qid, rid) VALUES (%d, %d)", $queue->qid, $rid);
}
}
if (is_array($queue->types)) {
foreach ($queue->types as $type) {
db_query("INSERT INTO {nodequeue_types} (qid, type) VALUES (%d, '%s')", $queue->qid, $type);
}
}
if (db_result(db_query("SELECT COUNT(*) FROM {nodequeue_queue} WHERE link <> ''"))) {
variable_set('nodequeue_links', TRUE);
}
else {
variable_set('nodequeue_links', FALSE);
}
if (isset($queue->add_subqueue) && is_array($queue->add_subqueue)) {
foreach ($queue->add_subqueue as $reference => $title) {
if ($reference == 0) {
$reference = $queue->qid;
}
nodequeue_add_subqueue($queue, $title, $reference);
}
}
return $queue->qid;
}
function nodequeue_delete($qid) {
db_query("DELETE FROM {nodequeue_queue} WHERE qid = %d", $qid);
db_query("DELETE FROM {nodequeue_roles} WHERE qid = %d", $qid);
db_query("DELETE FROM {nodequeue_types} WHERE qid = %d", $qid);
db_query("DELETE FROM {nodequeue_nodes} WHERE qid = %d", $qid);
db_query("DELETE FROM {nodequeue_subqueue} WHERE qid = %d", $qid);
module_invoke_all('nodequeue_delete', $qid);
}
function nodequeue_add_subqueue(&$queue, $title, $reference = NULL) {
if (empty($reference)) {
$insert_reference = "";
}
else {
$insert_reference = $reference;
}
$subqueue = new stdClass();
$subqueue->reference = $reference;
$subqueue->qid = $queue->qid;
$subqueue->title = $title;
db_query("INSERT INTO {nodequeue_subqueue} (qid, reference, title) VALUES (%d, '%s', '%s')", $queue->qid, $insert_reference, $title);
$subqueue->sqid = db_last_insert_id('nodequeue_subqueue', 'sqid');
if (empty($reference)) {
db_query("UPDATE {nodequeue_subqueue} SET reference = '%s' WHERE sqid = %d", $subqueue->sqid, $subqueue->sqid);
}
return $subqueue;
}
function nodequeue_subqueue_update_title($sqid, $title) {
db_query("UPDATE {nodequeue_subqueue} SET title = '%s' WHERE sqid = %d", $title, $sqid);
}
function nodequeue_remove_subqueue($sqid) {
nodequeue_queue_clear($sqid);
db_query("DELETE FROM {nodequeue_subqueue} WHERE sqid = %d", $sqid);
}
function nodequeue_subqueue_add($queue, &$subqueue, $nid) {
if (!empty($nid)) {
db_query("INSERT INTO {nodequeue_nodes} (sqid, qid, nid, position, timestamp) VALUES (%d, %d, %d, COALESCE((SELECT MAX(position)+1 FROM (SELECT * from {nodequeue_nodes} WHERE sqid = %d) as nn), 1), %d)", $subqueue->sqid, $queue->qid, $nid, $subqueue->sqid, time());
$subqueue->count = db_result(db_query("SELECT count(nid) FROM {nodequeue_nodes} WHERE sqid = %d", $subqueue->sqid));
if (!empty($queue->size)) {
nodequeue_check_subqueue_size($queue, $subqueue, $queue->size);
}
if (module_exists('apachesolr')) {
if (function_exists('apachesolr_mark_node')) {
apachesolr_mark_node($nid);
}
else {
apachesolr_mark_entity('node', $nid);
}
}
module_invoke_all('nodequeue_add', $subqueue->sqid, $nid);
}
}
function nodequeue_subqueue_remove_node($sqid, $nid) {
if ($pos = nodequeue_get_subqueue_position($sqid, $nid)) {
nodequeue_subqueue_remove($sqid, $pos);
if (module_exists('apachesolr')) {
if (function_exists('apachesolr_mark_node')) {
apachesolr_mark_node($nid);
}
else {
apachesolr_mark_entity('node', $nid);
}
}
}
}
function nodequeue_subqueue_remove($sqid, $start, $end = NULL) {
if (!isset($end)) {
$end = $start;
}
$result = db_query("SELECT nid FROM {nodequeue_nodes} WHERE sqid = %d AND position >= %d AND position <= %d", $sqid, $start, $end);
$diff = $end - $start + 1;
db_query("DELETE FROM {nodequeue_nodes} WHERE sqid = %d AND position >= %d AND position <= %d", $sqid, $start, $end);
db_query("UPDATE {nodequeue_nodes} SET position = position - %d WHERE sqid = %d AND position > %d", $diff, $sqid, $end);
while ($node = db_fetch_object($result)) {
module_invoke_all('nodequeue_remove', $sqid, $node->nid);
}
}
function nodequeue_queue_clear($sqid) {
db_query("DELETE FROM {nodequeue_nodes} WHERE sqid = %d", $sqid);
}
function nodequeue_check_subqueue_size($queue, &$subqueue, $size = NULL) {
if (!isset($size)) {
$size = $queue->size;
}
if ($queue->size && $subqueue->count > $size) {
nodequeue_subqueue_remove($subqueue->sqid, 1, $subqueue->count - $size);
$subqueue->count = $size;
}
}
function nodequeue_check_subqueue_sizes($queue) {
if (!$queue->size) {
return;
}
$subqueues = nodequeue_load_subqueues_by_queue($queue->qid);
foreach ($subqueues as $subqueue) {
nodequeue_check_subqueue_size($queue, $subqueue);
}
}
function nodequeue_queue_swap($subqueue, $pos1, $pos2) {
$nid = db_result(db_query("SELECT nid FROM {nodequeue_nodes} WHERE sqid = %d AND position = %d", $subqueue->sqid, $pos1));
if (!$nid) {
return;
}
db_query("UPDATE {nodequeue_nodes} SET position = %d WHERE position = %d AND sqid = %d", $pos1, $pos2, $subqueue->sqid);
db_query("UPDATE {nodequeue_nodes} SET position = %d WHERE nid = %d AND sqid = %d", $pos2, $nid, $subqueue->sqid);
module_invoke_all('nodequeue_swap', $subqueue->sqid, $nid);
}
function nodequeue_queue_up($subqueue, $position) {
if ($position < 2 || $position > $subqueue->count) {
return;
}
nodequeue_queue_swap($subqueue, $position - 1, $position);
}
function nodequeue_queue_down($subqueue, $position) {
if ($position < 1 || $position >= $subqueue->count) {
return;
}
nodequeue_queue_swap($subqueue, $position + 1, $position);
}
function nodequeue_queue_front($subqueue, $position) {
if ($position < 2 || $position > $subqueue->count) {
return;
}
$entry = db_fetch_object(db_query("SELECT * FROM {nodequeue_nodes} WHERE sqid= %d AND position = %d", $subqueue->sqid, $position));
db_query("DELETE FROM {nodequeue_nodes} WHERE sqid = %d AND position = %d", $subqueue->sqid, $position);
db_query("UPDATE {nodequeue_nodes} SET position = position + 1 WHERE sqid= %d AND position < %d", $subqueue->sqid, $position);
db_query("INSERT INTO {nodequeue_nodes} (qid, sqid, nid, position, timestamp) VALUES (%d, %d, %d, 1, %d)", $entry->qid, $subqueue->sqid, $entry->nid, $entry->timestamp);
}
function nodequeue_queue_back($subqueue, $position) {
if ($position < 1 || $position >= $subqueue->count) {
return;
}
$entry = db_fetch_object(db_query("SELECT * FROM {nodequeue_nodes} WHERE sqid = %d AND position = %d", $subqueue->sqid, $position));
db_query("DELETE FROM {nodequeue_nodes} WHERE sqid = %d AND position = %d", $subqueue->sqid, $position);
db_query("UPDATE {nodequeue_nodes} SET position = position - 1 WHERE sqid = %d AND position > %d", $subqueue->sqid, $position);
db_query("INSERT INTO {nodequeue_nodes} (qid, sqid, nid, position, timestamp) VALUES (%d, %d, %d, %d, %d)", $entry->qid, $subqueue->sqid, $entry->nid, $subqueue->count, $entry->timestamp);
}
function nodequeue_get_subqueue_position($sqid, $nid) {
$pos = db_result(db_query("SELECT MIN(position) FROM {nodequeue_nodes} WHERE sqid = %d AND nid = %d", $sqid, $nid));
return $pos;
}
function nodequeue_set_subqueue_positions(&$subqueues, $nid) {
if (empty($subqueues)) {
return;
}
$placeholders = db_placeholders($subqueues, 'int');
$args = array_keys($subqueues);
$args[] = $nid;
$result = db_query("SELECT sqid, MIN(position) AS position FROM {nodequeue_nodes} WHERE sqid IN ({$placeholders}) AND nid = %d GROUP BY sqid", $args);
while ($obj = db_fetch_object($result)) {
$subqueues[$obj->sqid]->position = $obj->position;
}
}
function nodequeue_get_subqueues_by_node($queues, $node) {
$references = array();
static $last_nid = 0;
foreach ($queues as $queue) {
if ($result = nodequeue_api_subqueues($queue, $node)) {
$references[$queue->qid] = is_array($result) ? $result : array(
$result,
);
}
}
if (empty($references)) {
return array();
}
$subqueues = nodequeue_load_subqueues_by_reference($references, $last_nid != $node->nid);
$last_nid = $node->nid;
return $subqueues;
}
function nodequeue_subqueue_size_text($max, $count, $long = TRUE) {
if (empty($count)) {
$message = theme('nodequeue_subqueue_empty_text');
}
elseif ($count == $max) {
$message = theme('nodequeue_subqueue_full_text');
}
else {
if ($long) {
$message = theme('nodequeue_subqueue_count_text', $count);
}
else {
$message = $count;
}
}
return $message;
}
function nodequeue_title_substitute($text, $queue, $subqueue) {
if (empty($text)) {
return $subqueue->title;
}
$text = str_replace('%subqueue', $subqueue->title, $text);
return $text;
}
function nodequeue_subqueue_shuffle($subqueue) {
if (!is_object($subqueue)) {
$subqueue = nodequeue_load_subqueue($subqueue);
}
if (empty($subqueue)) {
return;
}
$count = $subqueue->count;
foreach (range(1, $count) as $i) {
nodequeue_queue_swap($subqueue, $i, rand(1, $count));
}
}
function nodequeue_nodequeue_info() {
return array(
'nodequeue' => array(
'title' => t('Simple queue'),
'description' => t('Simple queues have just one subqueue. Nodes put into a queue are added to the back of the queue; when a node is added to a full queue, the node in the front of the queue will be popped out to make room.'),
),
);
}
function nodequeue_nodequeue_form_submit(&$queue, $form_state) {
if (!isset($queue->qid) && !isset($queue->add_subqueue)) {
$queue->add_subqueue = array(
0 => $queue->title,
);
}
if (isset($queue->qid)) {
db_query("UPDATE {nodequeue_subqueue} SET title = '%s' WHERE qid = %d", array(
$form_state['values']['title'],
$queue->qid,
));
}
}
function nodequeue_node_titles($sqid, $title = '', $backward = TRUE, $from = 0, $count = 0, $published_only = TRUE) {
$orderby = $backward ? "DESC" : "ASC";
$published_sql = '';
if ($published_only) {
$published_sql = 'AND n.status = 1';
}
$sql = db_rewrite_sql("SELECT n.nid, n.title FROM {node} n LEFT JOIN {nodequeue_nodes} nn ON n.nid = nn.nid WHERE nn.sqid = %d " . $published_sql . " ORDER BY nn.position " . $orderby);
if ($count) {
$result = db_query_range($sql, $sqid, $from, $count);
}
else {
$result = db_query($sql, $sqid);
}
return node_title_list($result, $title);
}
function nodequeue_view_nodes($sqid, $backward = TRUE, $teaser = TRUE, $links = TRUE, $from = 0, $count = 0) {
$nodes = nodequeue_load_nodes($sqid, $backward, $from, $count);
foreach ($nodes as $node) {
$output .= node_view($node, $teaser, FALSE, $links);
}
return $output;
}
function nodequeue_load_nodes($sqid, $backward = FALSE, $from = 0, $count = 5, $published_only = TRUE) {
$orderby = $backward ? "DESC" : "ASC";
$published_sql = '';
if ($published_only) {
$published_sql = 'AND n.status = 1';
}
$sql = db_rewrite_sql("SELECT n.nid FROM {node} n INNER JOIN {nodequeue_nodes} nn ON n.nid = nn.nid WHERE nn.sqid = %d " . $published_sql . " ORDER BY nn.position " . $orderby);
if ($count) {
$result = db_query_range($sql, $sqid, $from, $count);
}
else {
$result = db_query($sql, $sqid);
}
$nodes = array();
while ($nid = db_fetch_object($result)) {
$nodes[] = node_load($nid->nid);
}
return $nodes;
}
function nodequeue_load_front($sqid) {
return array_shift(nodequeue_load_nodes($sqid, FALSE, 0, 1));
}
function nodequeue_load_back($sqid, $teaser = TRUE, $links = TRUE) {
return array_shift(nodequeue_load_nodes($sqid, TRUE, 0, 1));
}
function nodequeue_view_random_node($sqid, $teaser = TRUE, $links = TRUE) {
$count = db_result(db_query(db_rewrite_sql("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {nodequeue_nodes} nn ON n.nid = nn.nid WHERE nn.sqid = %d AND n.status = 1"), $sqid));
return nodequeue_view_nodes($sqid, FALSE, $teaser, $links, rand(0, $count - 1), 1);
}
function nodequeue_load_random_node($sqid) {
$count = db_result(db_query(db_rewrite_sql("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {nodequeue_nodes} nn ON n.nid = nn.nid WHERE nn.sqid = %d AND n.status = 1"), $sqid));
return array_shift(nodequeue_load_nodes($sqid, TRUE, rand(0, $count - 1), 1));
}
function nodequeue_subqueue_position($sqid, $nid) {
return db_result(db_query("SELECT position FROM {nodequeue_nodes} WHERE sqid = %d AND nid = %d", $sqid, $nid));
}
function nodequeue_queue_position($qid, $nid) {
$sqid = db_result(db_query_range("SELECT sqid FROM {nodequeue_subqueue} WHERE qid = %d", $qid, 0, 1));
return nodequeue_subqueue_position($sqid, $nid);
}
function nodequeue_api_queue_form($queue, &$form) {
$function = $queue->owner . "_nodequeue_form";
if (function_exists($function)) {
$function($queue, $form);
}
}
function nodequeue_api_queue_form_validate($queue, &$form_state, &$form) {
$function = $queue->owner . "_nodequeue_form_validate";
if (function_exists($function)) {
$function($queue, $form_state, $form);
}
}
function nodequeue_api_queue_form_submit(&$queue, &$form_state) {
$function = $queue->owner . "_nodequeue_form_submit";
if (function_exists($function)) {
$function($queue, $form_state);
}
}
function nodequeue_api_queue_form_submit_finish($queue, &$form_state) {
$function = $queue->owner . "_nodequeue_form_submit_finish";
if (function_exists($function)) {
$function($queue, $form_state);
}
}
function nodequeue_api_subqueues(&$queue, $node) {
$function = $queue->owner . "_nodequeue_subqueues";
if (function_exists($function)) {
return $function($queue, $node);
}
else {
return $queue->qid;
}
}
function nodequeue_api_autocomplete($queue, $subqueue, $string) {
$matches = array();
if (empty($string)) {
return $matches;
}
$where_args = array();
global $user;
if (!user_access('administer nodes', $user)) {
$where = '(n.status = 1 || n.uid = %d) AND ';
$where_args = array(
$user->uid,
);
}
$where .= "n.type IN (" . db_placeholders($queue->types, 'varchar') . ')';
$where_args = array_merge($where_args, $queue->types);
$preg_matches = array();
$match = preg_match('/\\[nid: (\\d+)\\]/', $string, $preg_matches);
if (!$match) {
$match = preg_match('/^nid: (\\d+)/', $string, $preg_matches);
}
if ($match) {
$where .= " AND n.nid = %d";
array_push($where_args, $preg_matches[1]);
}
else {
$where .= " AND LOWER(n.title) LIKE LOWER('%%%s%%')";
array_push($where_args, $string);
}
$function = $queue->owner . "_nodequeue_autocomplete";
if (function_exists($function)) {
return $function($queue, $subqueue, $string, $where, $where_args);
}
else {
if (module_exists('i18n')) {
i18n_selection_mode('off');
}
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.tnid FROM {node} n WHERE " . $where), $where_args, 0, variable_get('nodequeue_autocomplete_limit', 10));
if (module_exists('i18n')) {
i18n_selection_mode('reset');
}
while ($node = db_fetch_object($result)) {
$id = nodequeue_get_content_id($queue, $node);
$matches[$id] = check_plain($node->title) . " [nid: {$id}]";
}
}
return $matches;
}
function nodequeue_api_info() {
return module_invoke_all('nodequeue_info');
}
function nodequeue_api_queue_access($queue, $account = NULL) {
if (!$account) {
global $user;
$account = $user;
}
if ($queue->owner != 'nodequeue') {
$function = $queue->owner . '_queue_access';
if (function_exists($function)) {
$access = $function($queue, $account);
}
}
if (!isset($access)) {
$access = TRUE;
}
return $access;
}
function nodequeue_api_subqueue_access($subqueue, $account = NULL, $queue = NULL) {
if (!$account) {
global $user;
$account = $user;
}
if (!$queue) {
$queue = nodequeue_load($subqueue->qid);
}
$function = $queue->owner . '_subqueue_access';
if (function_exists($function)) {
$access = $function($subqueue, $account, $queue);
}
if (!isset($access)) {
$access = TRUE;
}
return $access;
}
function nodequeue_get_query_string($seed, $destination = FALSE, $query = array()) {
if ($dest = drupal_get_destination()) {
$query[] = $dest;
}
if (isset($seed)) {
$query[] = nodequeue_get_token($seed);
}
return implode('&', $query);
}
function nodequeue_get_token($nid) {
return 'token=' . drupal_get_token($nid);
}
function nodequeue_check_token($seed) {
return drupal_get_token($seed) == $_GET['token'];
}
function _nodequeue_access_admin_or_manipulate() {
return user_access('administer nodequeue') || user_access('manipulate queues') || user_access('manipulate all queues');
}
function nodequeue_node_and_queue_access($node, $queue, $subqueue = NULL) {
return nodequeue_node_access($node->type) && nodequeue_queue_access($queue, $subqueue);
}
function nodequeue_node_access($type, $location = NULL, $account = NULL) {
$qids = nodequeue_get_qids($type, $account);
if ($location) {
nodequeue_filter_qids($qids, $location);
}
return !empty($qids);
}
function nodequeue_queue_access($queue, $subqueue = NULL, $account = NULL) {
if (!$account) {
global $user;
$account = $user;
}
if (user_access('manipulate all queues', $account)) {
return TRUE;
}
if (!user_access('manipulate queues', $account) || empty($queue->roles)) {
return FALSE;
}
if ($subqueue) {
return nodequeue_api_subqueue_access($subqueue, $account);
}
if (!nodequeue_api_queue_access($queue, $account)) {
return FALSE;
}
$roles = array_keys((array) $account->roles) + array(
DRUPAL_AUTHENTICATED_RID,
);
return (bool) array_intersect($roles, $queue->roles);
}
function nodequeue_node_tab_access($node) {
if (!variable_get('nodequeue_use_tab', 1) || !user_access('manipulate queues')) {
return FALSE;
}
$queues = nodequeue_load_queues_by_type($node->type, 'tab');
$subqueues = nodequeue_get_subqueues_by_node($queues, $node);
if (empty($subqueues)) {
return FALSE;
}
foreach ($subqueues as $subqueue) {
if (nodequeue_api_subqueue_access($subqueue)) {
return TRUE;
}
}
return FALSE;
}
function nodequeue_js_output($label, $href, $count = NULL, $sqid = NULL) {
$return = new stdClass();
$return->status = 1;
$return->label = check_plain($label);
$return->href = $href;
if (isset($count)) {
$return->count = $count;
}
if (isset($sqid)) {
$return->sqid = $sqid;
}
drupal_json($return);
exit;
}
function nodequeue_get_content_id($queue, $node) {
return $queue->i18n && !empty($node->tnid) ? $node->tnid : $node->nid;
}
function nodequeue_nids_visible($sqid = -1, $account = NULL) {
$node_status_sql = '';
if (!$account) {
global $user;
$account = $user;
}
$nids_visible = array();
if (!user_access('administer nodes', $account)) {
$node_status_sql = ' AND (n.status = 1 || n.uid = %d)';
}
if (module_exists('i18n') && arg(0) == 'admin') {
i18n_selection_mode('off');
}
$query_restricted = db_query(db_rewrite_sql("SELECT DISTINCT(n.nid), nq.position FROM {node} n LEFT JOIN {nodequeue_nodes} nq ON nq.nid = n.nid WHERE nq.sqid = %d " . $node_status_sql . " ORDER BY nq.position ASC"), $sqid, $account->uid);
while ($result_restricted = db_fetch_object($query_restricted)) {
$nids_visible[$result_restricted->nid] = $result_restricted->nid;
}
if (module_exists('i18n') && arg(0) == 'admin') {
i18n_selection_mode('reset');
}
return $nids_visible;
}
function nodequeue_machine_name_available($machine_name, $qid = NULL) {
$result = db_query("SELECT qid FROM {nodequeue_queue} WHERE `name` LIKE '%s'", $machine_name);
$existing_queues = array();
while ($record = db_fetch_object($result)) {
$existing_queues[] = $record->qid;
}
if (count($existing_queues) == 0) {
return TRUE;
}
elseif (count($existing_queues) == 1 && !empty($qid) && $qid == $existing_queues[0]) {
return TRUE;
}
return FALSE;
}
function nodequeue_add_action($node, $context) {
$queues = nodequeue_load_queues($context['qids'], TRUE);
$eligible_queues = array();
foreach ($queues as $queue) {
if (in_array($node->type, $queue->types)) {
$eligible_queues[$queue->qid] = $queue;
}
}
if (!empty($eligible_queues)) {
nodequeue_remove_action($node, array(
'qids' => array_keys($eligible_queues),
));
$eligible_subqueues = nodequeue_get_subqueues_by_node($eligible_queues, $node);
foreach ($eligible_subqueues as $subqueue) {
nodequeue_subqueue_add($queues[$subqueue->qid], $subqueue, $node->nid);
}
}
}
function nodequeue_add_action_form($context) {
if (!isset($context['qids'])) {
$context['qids'] = '';
}
$queues = nodequeue_load_queues(nodequeue_get_all_qids(0, 0, TRUE), TRUE);
foreach ($queues as $qid => $queue) {
$options[$qid] = $queue->title;
}
$form = array();
if (count($options)) {
$form['qids'] = array(
'#type' => 'select',
'#title' => t("Queue"),
'#default_value' => $context['qids'],
'#multiple' => TRUE,
'#options' => $options,
'#required' => TRUE,
'#description' => t('Specify the queues into which the node should be submitted. If the queue is a smartqueue, the node shall be placed into every subqueue for which it is eligible.'),
);
}
else {
drupal_set_message(t('Please <a href="@url">create</a> a nodequeue first.', array(
'@url' => url('admin/content/nodequeue'),
)));
}
return $form;
}
function nodequeue_add_action_submit($form, &$form_state) {
return array(
'qids' => $form_state['values']['qids'],
);
}
function nodequeue_remove_action($node, $context) {
$qids = $context['qids'];
$placeholders = implode(',', array_fill(0, count($qids), '%d'));
$args = $qids;
$args[] = $node->nid;
$result = db_query("SELECT * FROM {nodequeue_nodes} WHERE qid IN ({$placeholders}) AND nid = %d", $args);
while ($obj = db_fetch_object($result)) {
nodequeue_subqueue_remove_node($obj->sqid, $node->nid);
}
}
function nodequeue_remove_action_form($context) {
if (!isset($context['qids'])) {
$context['qids'] = array();
}
$queues = nodequeue_load_queues(nodequeue_get_all_qids(0, 0, TRUE), TRUE);
foreach ($queues as $qid => $queue) {
$options[$qid] = $queue->title;
}
$form['qids'] = array(
'#type' => 'select',
'#title' => t("Queues"),
'#default_value' => $context['qids'],
'#multiple' => TRUE,
'#decription' => t('Specify the queues from which the node should be removed. If the queue is a smartqueue, the node shall be removed from all subqueues.'),
'#required' => TRUE,
'#options' => $options,
);
return $form;
}
function nodequeue_remove_action_submit($form, &$form_state) {
return array(
'qids' => $form_state['values']['qids'],
);
}
function theme_nodequeue_arrange_subqueue_form($form) {
$output = '';
$subqueue = $form['#subqueue'];
drupal_add_css(drupal_get_path('module', 'nodequeue') . '/nodequeue.css');
$table_id = 'nodequeue-dragdrop-' . $subqueue['sqid'];
$table_classes = array(
'nodequeue-dragdrop',
'nodequeue-dragdrop-qid-' . $subqueue['qid'],
'nodequeue-dragdrop-sqid-' . $subqueue['sqid'],
'nodequeue-dragdrop-reference-' . $subqueue['reference'],
);
drupal_add_tabledrag($table_id, 'order', 'sibling', 'node-position');
drupal_add_js(drupal_get_path('module', 'nodequeue') . '/nodequeue_dragdrop.js');
$reverse[str_replace('-', '_', $table_id)] = (bool) $form['#queue']['reverse'];
drupal_add_js(array(
'nodequeue' => array(
'reverse' => $reverse,
),
), 'setting');
$rows = array();
$counter = 1;
foreach (element_children($form) as $key) {
if (isset($form[$key]['title'])) {
$row = array();
$row[] = drupal_render($form[$key]['title']);
$row[] = drupal_render($form[$key]['author']);
$row[] = drupal_render($form[$key]['date']);
$row[] = drupal_render($form[$key]['position']);
$row[] = !empty($form[$key]['edit']) ? drupal_render($form[$key]['edit']) : ' ';
$row[] = drupal_render($form[$key]['remove']);
$row[] = array(
'data' => $counter,
'class' => 'position',
);
$rows[] = array(
'data' => $row,
'class' => 'draggable',
);
}
$counter++;
}
if (empty($rows)) {
$rows[] = array(
array(
'data' => t('No nodes in this queue.'),
'colspan' => 7,
),
);
}
$header = array(
t('Title'),
t('Author'),
t('Post Date'),
t('Position'),
array(
'data' => t('Operations'),
'colspan' => 2,
),
t('Position'),
);
$output .= theme('table', $header, $rows, array(
'id' => $table_id,
'class' => implode(' ', $table_classes),
));
$output .= '<div class="container-inline">';
$output .= drupal_render($form['add']['nid']);
$output .= drupal_render($form['add']['submit']);
$output .= '</div>';
$output .= drupal_render($form);
return $output;
}
function theme_nodequeue_subqueue_empty_text() {
return t('Queue empty');
}
function theme_nodequeue_subqueue_full_text() {
return t('Queue full');
}
function theme_nodequeue_subqueue_count_text($count) {
return t('@count in queue', array(
'@count' => $count,
));
}