--- /home/renato/image_old/contrib/image_gallery/image_gallery.module 2007-09-07 20:26:58.000000000 +0100 +++ image_gallery.module 2007-12-10 19:04:25.000000000 +0000 @@ -82,6 +82,15 @@ '#size' => 3, '#description' => t('Sets the number of images to be displayed in a gallery page.'), ); + $form['gallery']['image_order'] = array( + '#type' => 'radios', + '#title' => t('Sort order'), + '#default_value' => variable_get('image_order', 'desc'), + '#options' => array( + 'desc' => t('Most recent to least recent'), + 'asc' => t('Least recent to most recent')), + '#description' => t('Defines how images are sorted in a gallery page.'), + ); $form['gallery']['image_gallery_node_info'] = array( '#type' => 'checkbox', '#title' => t('Display node info'), @@ -139,6 +148,12 @@ * Image gallery callback, displays an image gallery */ function image_gallery_page($type = NULL, $tid = 0) { + if (variable_get('image_order', 'desc') == 'asc') { + $order = 'n.created ASC, n.nid ASC'; + } + else { + $order = 'n.created DESC, n.nid DESC'; + } $galleries = taxonomy_get_tree(_image_gallery_get_vid(), $tid, -1, 1); for ($i=0; $i < count($galleries); $i++) { $galleries[$i]->count = taxonomy_term_count_nodes($galleries[$i]->tid, 'image'); @@ -146,7 +161,7 @@ $descendant_tids = array_merge(array($galleries[$i]->tid), array_map('_taxonomy_get_tid_from_term', $tree)); // The values of $descendant_tids should be safe for raw inclusion in the // SQL since they're all loaded from integer fields in the database. - $sql = 'SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. implode(',', $descendant_tids) .') AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'; + $sql = 'SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. implode(',', $descendant_tids) .') AND n.status = 1 ORDER BY n.sticky DESC, $order'; if ($nid = db_result(db_query_range(db_rewrite_sql($sql), 0, 1))) { $galleries[$i]->latest = node_load(array('nid' => $nid)); } @@ -154,7 +169,7 @@ $images = array(); if ($tid) { - $result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d ORDER BY n.sticky DESC, n.created DESC"), variable_get('image_images_per_page', 6), 0, NULL, $tid); + $result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d ORDER BY n.sticky DESC, $order"), variable_get('image_images_per_page', 6), 0, NULL, $tid); while ($node = db_fetch_object($result)) { $images[] = node_load(array('nid' => $node->nid)); }