[MOD] Album-based sort order for files [MOD] Album-based sort order for files
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

[MOD] Album-based sort order for files

Started by Ludo, January 24, 2009, 12:38:14 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ludo

Hoping that this old GauGau's wish hasn't been granted yet, here is a mod to allow setting file sort order for each album in properties page.

Files to edit: 6 (+ 2 database queries):
lang/your_lang.php
modifyalb.php
db_input.php
thumbnails.php
displayimage.php
include/functions.inc.php


RUN
these two queries on your CPG database (change CPG_ to your CPG table prefix!)
ALTER TABLE CPG_albums ADD COLUMN sort_order CHAR(2) NOT NULL;
UPDATE CPG_albums SET sort_order = (SELECT value FROM CPG_config WHERE name = 'default_sort_order');


OPEN
lang/your_lang.php

FIND
);

// ------------------------------------------------------------------------- //
// File phpinfo.php
// ------------------------------------------------------------------------- //


BEFORE, ADD (translate english definitions in your_lang!)
  'alb_sort_order' => 'Sort order for files',
  'name_a' => 'Name ascending',
  'name_d' => 'Name descending',
  'title_a' => 'Title ascending',
  'title_d' => 'Title descending',
  'date_a' => 'Date ascending',
  'date_d' => 'Date descending',
  'pos_a' => 'Position ascending', //cpg1.4
  'pos_d' => 'Position descending', //cpg1.4



OPEN
modifyalb.php

FIND
$help_album_keywords = ' '.cpg_display_help('f=index.htm&as=album_prop_keyword_start&ae=album_prop_keyword_end&top=1', '400', '200');

AFTER, ADD
$help_album_sort_order = ' '.cpg_display_help('f=index.htm&as=admin_thumbnail_default_sortorder&ae=admin_thumbnail_default_sortorder_end&top=1', '600', '350');

FIND
    array($lang_modifyalb_php['alb_keyword'].$help_album_keywords, 'keyword', 0),

AFTER, ADD
    array($lang_modifyalb_php['alb_sort_order'].$help_album_sort_order, 'sort_order', 8),

FIND
function form_alb_thumb($text, $name)

BEFORE, ADD
function form_alb_sort_order($text, $name)
{
    global $CONFIG, $ALBUM_DATA, $lang_modifyalb_php;

    $value = (empty($ALBUM_DATA[$name])) ? $CONFIG['default_sort_order'] : $ALBUM_DATA[$name];
    $ta_selected = ($value == 'ta') ? 'selected="selected"' : '';
    $td_selected = ($value == 'td') ? 'selected="selected"' : '';
    $na_selected = ($value == 'na') ? 'selected="selected"' : '';
    $nd_selected = ($value == 'nd') ? 'selected="selected"' : '';
    $da_selected = ($value == 'da') ? 'selected="selected"' : '';
    $dd_selected = ($value == 'dd') ? 'selected="selected"' : '';
    $pa_selected = ($value == 'pa') ? 'selected="selected"' : '';
    $pd_selected = ($value == 'pd') ? 'selected="selected"' : '';

echo <<<EOT
        <tr>
                <td class="tableb">
                        $text
                </td>
                <td class="tableb" valign="top">
                        <select name="$name" class="listbox">
                                <option value="ta" $ta_selected>{$lang_modifyalb_php['title_a']}</option>
                                <option value="td" $td_selected>{$lang_modifyalb_php['title_d']}</option>
                                <option value="na" $na_selected>{$lang_modifyalb_php['name_a']}</option>
                                <option value="nd" $nd_selected>{$lang_modifyalb_php['name_d']}</option>
                                <option value="da" $da_selected>{$lang_modifyalb_php['date_a']}</option>
                                <option value="dd" $dd_selected>{$lang_modifyalb_php['date_d']}</option>
                                <option value="pa" $pa_selected>{$lang_modifyalb_php['pos_a']}</option>
                                <option value="pd" $pd_selected>{$lang_modifyalb_php['pos_d']}</option>
                        </select>
                </td>
        </tr>

EOT;
}



FIND
                case 7:
                    form_password_hint($element[0],$element[1]);
                    break;


AFTER, ADD
                case 8:
                    form_alb_sort_order($element[0],$element[1]);
                    break;




OPEN
db_input.php

FIND
        $keyword = addslashes(trim($_POST['keyword']));

AFTER, ADD
        $sort_order = addslashes(trim($_POST['sort_order']));

FIND
            $query = "UPDATE {$CONFIG['TABLE_ALBUMS']} SET title='$title', description='$description', category='$category', thumb='$thumb', uploads='$uploads', comments='$comments', votes='$votes', visibility='$visibility', alb_password='$password', alb_password_hint='$password_hint', keyword='$keyword' WHERE aid='$aid' LIMIT 1";       


REPLACE WITH
            $query = "UPDATE {$CONFIG['TABLE_ALBUMS']} SET title='$title', description='$description', category='$category', thumb='$thumb', uploads='$uploads', comments='$comments', votes='$votes', visibility='$visibility', alb_password='$password', alb_password_hint='$password_hint', keyword='$keyword', sort_order='$sort_order' WHERE aid='$aid' LIMIT 1";

FIND
            $query = "UPDATE {$CONFIG['TABLE_ALBUMS']} SET title='$title', description='$description', thumb='$thumb',  comments='$comments', votes='$votes', visibility='$visibility', alb_password='$password', alb_password_hint='$password_hint',keyword='$keyword' WHERE aid='$aid' AND category='$category' LIMIT 1";

REPLACE WITH
            $query = "UPDATE {$CONFIG['TABLE_ALBUMS']} SET title='$title', description='$description', thumb='$thumb',  comments='$comments', votes='$votes', visibility='$visibility', alb_password='$password', alb_password_hint='$password_hint',keyword='$keyword', sort_order='$sort_order' WHERE aid='$aid' AND category='$category' LIMIT 1";


OPEN
thumbnails.php

FIND
    $result = cpg_db_query("SELECT category, title, aid, keyword, description, alb_password_hint FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid='$album'");

REPLACE WITH
    $result = cpg_db_query("SELECT category, title, aid, keyword, description, alb_password_hint, sort_order FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid='$album'");

FIND
        $CURRENT_ALBUM_KEYWORD = $CURRENT_ALBUM_DATA['keyword'];

AFTER, ADD
        $CURRENT_ALBUM_SORT_ORDER = $CURRENT_ALBUM_DATA['sort_order'];


OPEN
displayimage.php

FIND
/**
* Main code
*/


BEFORE, ADD
function get_album_sort_order($album)
{
    global $CONFIG;
    $result = cpg_db_query("SELECT sort_order FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid='$album' LIMIT 1");
    $row = mysql_fetch_array($result);   
    return $row['sort_order'];
}



FIND
    $album = $row['aid'];

AFTER, ADD
    $CURRENT_ALBUM_SORT_ORDER = get_album_sort_order($album);

FIND
} elseif (isset($_GET['pos'])) {

AFTER, ADD
    $CURRENT_ALBUM_SORT_ORDER = get_album_sort_order($album);


OPEN
include/functions.inc.php

FIND (in function get_pic_data)
        global $USER, $CONFIG, $ALBUM_SET, $META_ALBUM_SET, $CURRENT_CAT_NAME, $CURRENT_ALBUM_KEYWORD, $HTML_SUBST, $THEME_DIR, $FAVPICS, $FORBIDDEN_SET_DATA;

REPLACE WITH
        global $USER, $CONFIG, $ALBUM_SET, $META_ALBUM_SET, $CURRENT_CAT_NAME, $CURRENT_ALBUM_KEYWORD, $CURRENT_ALBUM_SORT_ORDER, $HTML_SUBST, $THEME_DIR, $FAVPICS, $FORBIDDEN_SET_DATA;

FIND
        $sort_code = isset($USER['sort'])? $USER['sort'] : $CONFIG['default_sort_order'];

REPLACE WITH
        $default_sort_code = isset($CURRENT_ALBUM_SORT_ORDER) ? $CURRENT_ALBUM_SORT_ORDER : $CONFIG['default_sort_order'];
        $sort_code = isset($USER['sort'])? $USER['sort'] : $default_sort_code;



SAVE AND CLOSE ALL FILES

Not tested on private, password and user albums (I have none of these).

Ludo

Modded displayimage.php too, so that displayed image matches clicked thumbnail  ;D  :-[