diff -u -F'^f' /www/contaire.net/nc/cvsmaster/sites/all/modules/nodeorder/nodeorder.module ./nodeorder.module --- /www/contaire.net/nc/cvsmaster/sites/all/modules/nodeorder/nodeorder.module 2007-06-16 00:47:16.000000000 +0200 +++ ./nodeorder.module 2007-10-31 08:22:43.000000000 +0100 @@ -15,7 +15,8 @@ function nodeorder_perm() { */ function nodeorder_form_alter($form_id, &$form) { if ($form_id == 'taxonomy_form_vocabulary') { - $is_orderable = $form['module']['#value'] == 'nodeorder'; + $vid = $form['vid']['#value']; + $is_orderable = variable_get('nodeorder_vid_' . $vid, FALSE); $form['orderable'] = array( '#type' => 'checkbox', @@ -35,9 +36,10 @@ function nodeorder_form_alter($form_id, */ function nodeorder_taxonomy_form_vocabulary_submit($form_id, $form_values) { $vid = $form_values['vid']; + $is_orderable = variable_get('nodeorder_vid_' . $vid, FALSE); if ($form_values['orderable']) { - if ($form_values['module'] != 'nodeorder') { + if (!$is_orderable) { // Switching from non-orderable to orderable... // Set weight_in_tid to nid for all rows in term_node where @@ -53,16 +55,15 @@ function nodeorder_taxonomy_form_vocabul if (count($tids) > 0) { db_query("UPDATE {term_node} SET weight_in_tid = nid WHERE tid IN (". implode(',', $tids) .")"); } - - db_query("UPDATE {vocabulary} SET module = '%s' WHERE vid = %d", 'nodeorder', $vid); + variable_set('nodeorder_vid_' . $vid, TRUE); drupal_set_message(t('You may now order nodes within this vocabulary.')); } } else { - if ($form_values['module'] == 'nodeorder') { + if ($is_orderable) { // Switching from orderable to non-orderable... - db_query("UPDATE {vocabulary} SET module = '%s' WHERE vid = %d", 'taxonomy', $vid); + variable_set('nodeorder_vid_' . $vid, FALSE); // Set weight_in_tid to 0 for all rows in term_node where // the tid is in this vocabulary... @@ -96,8 +97,7 @@ function nodeorder_link($type, $node = 0 if ($type == 'node') { if (array_key_exists('taxonomy', $node)) { foreach ($node->taxonomy as $term) { - $vocabulary = taxonomy_get_vocabulary($term->vid); - if ($vocabulary->module == 'nodeorder') { + if (variable_get('nodeorder_vid_' . $term->vid, FALSE)) { $links['nodeorder_move_up_'. $term->tid] = array( 'href' => "nodeorder/moveup/". $node->nid ."/". $term->tid, 'title' => t("move up in ". $term->name), @@ -538,11 +538,32 @@ function nodeorder_move_in_category(&$no drupal_goto($_GET['destination']); } +function nodeorder_orderable_vids() { + static $orderable; + + if (!isset($orderable)) { + $orderable = array(); + $result = db_query("SELECT name, value from {variable} WHERE name LIKE 'nodeorder_vid_%' AND value = 'b:1;'"); + + while ($var = db_fetch_object($result)) { + if (preg_match('/nodeorder_vid_(\d+)/', $var->name, $match)) { + $orderable[] = $match[1]; + } + } + } + return $orderable; +} + /** * Returns TRUE if the node has terms in any orderable vocabulary... */ function nodeorder_can_be_ordered($node) { - $sql = "SELECT v.vid AS vid FROM {vocabulary_node_types} vnt JOIN {vocabulary} v ON vnt.vid = v.vid WHERE vnt.type = '%s' AND v.module = 'nodeorder'"; + $orderable = join(',', nodeorder_orderable_vids()); + if (!$orderable) { + return FALSE; + } + + $sql = "SELECT vid FROM {vocabulary_node_types} WHERE type = '%s' and vid in ($orderable)"; $result = db_query($sql, $node->type); if (db_num_rows($result)) { @@ -556,9 +577,14 @@ function nodeorder_can_be_ordered($node) * Returns an array of the node's tids that are in orderable vocabularies... */ function nodeorder_orderable_tids($node) { + $orderable = join(',', nodeorder_orderable_vids()); + if (!$orderable) { + return FALSE; + } + $tids = array(); - $sql = "SELECT v.vid AS vid FROM {vocabulary_node_types} vnt JOIN {vocabulary} v ON vnt.vid = v.vid WHERE vnt.type = '%s' AND v.module = 'nodeorder'"; + $sql = "SELECT vid FROM {vocabulary_node_types} WHERE type = '%s' AND vid in ($orderable)"; $result = db_query($sql, $node->type); while ($row = db_fetch_object($result)) { @@ -575,14 +601,7 @@ function nodeorder_orderable_tids($node) * Returns TRUE if the vocabulary is orderable... */ function nodeorder_vocabulary_can_be_ordered($vid) { - $sql = "SELECT * FROM {vocabulary} WHERE module = 'nodeorder' AND vid = %d"; - $result = db_query($sql, $vid); - - if (db_num_rows($result)) { - return TRUE; - } - - return FALSE; + return variable_get('nodeorder_vid_' . $vid, FALSE); } /**