Advanced search  

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]

Pages: [1]   Go Down

Author Topic: [MOD] Album-based sort order for files  (Read 10258 times)

0 Members and 1 Guest are viewing this topic.

Ludo

  • Contributor
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 706
    • E+GiElle
[MOD] Album-based sort order for files
« on: January 24, 2009, 12:38:14 pm »

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!)
Code: [Select]
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
Code: [Select]
);

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

BEFORE, ADD (translate english definitions in your_lang!)
Code: [Select]
  '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
Code: [Select]
$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
Code: [Select]
$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
Code: [Select]
    array($lang_modifyalb_php['alb_keyword'].$help_album_keywords, 'keyword', 0),
AFTER, ADD
Code: [Select]
    array($lang_modifyalb_php['alb_sort_order'].$help_album_sort_order, 'sort_order', 8),
FIND
Code: [Select]
function form_alb_thumb($text, $name)
BEFORE, ADD
Code: [Select]
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
Code: [Select]
                case 7:
                    form_password_hint($element[0],$element[1]);
                    break;

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



OPEN
db_input.php

FIND
Code: [Select]
        $keyword = addslashes(trim($_POST['keyword']));
AFTER, ADD
Code: [Select]
        $sort_order = addslashes(trim($_POST['sort_order']));
FIND
Code: [Select]
            $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
Code: [Select]
            $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
Code: [Select]
            $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
Code: [Select]
            $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
Code: [Select]
    $result = cpg_db_query("SELECT category, title, aid, keyword, description, alb_password_hint FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid='$album'");
REPLACE WITH
Code: [Select]
    $result = cpg_db_query("SELECT category, title, aid, keyword, description, alb_password_hint, sort_order FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid='$album'");
FIND
Code: [Select]
        $CURRENT_ALBUM_KEYWORD = $CURRENT_ALBUM_DATA['keyword'];
AFTER, ADD
Code: [Select]
        $CURRENT_ALBUM_SORT_ORDER = $CURRENT_ALBUM_DATA['sort_order'];

OPEN
displayimage.php

FIND
Code: [Select]
/**
 * Main code
 */

BEFORE, ADD
Code: [Select]
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
Code: [Select]
    $album = $row['aid'];
AFTER, ADD
Code: [Select]
    $CURRENT_ALBUM_SORT_ORDER = get_album_sort_order($album);
FIND
Code: [Select]
} elseif (isset($_GET['pos'])) {
AFTER, ADD
Code: [Select]
    $CURRENT_ALBUM_SORT_ORDER = get_album_sort_order($album);

OPEN
include/functions.inc.php

FIND (in function get_pic_data)
Code: [Select]
        global $USER, $CONFIG, $ALBUM_SET, $META_ALBUM_SET, $CURRENT_CAT_NAME, $CURRENT_ALBUM_KEYWORD, $HTML_SUBST, $THEME_DIR, $FAVPICS, $FORBIDDEN_SET_DATA;
REPLACE WITH
Code: [Select]
        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
Code: [Select]
        $sort_code = isset($USER['sort'])? $USER['sort'] : $CONFIG['default_sort_order'];
REPLACE WITH
Code: [Select]
        $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).
« Last Edit: January 30, 2009, 11:11:09 am by Ludo »
Logged

Ludo

  • Contributor
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 706
    • E+GiElle
Re: [MOD] Album-based sort order for files
« Reply #1 on: January 30, 2009, 10:58:07 am »

Modded displayimage.php too, so that displayed image matches clicked thumbnail  ;D  :-[
Logged
Pages: [1]   Go Up
 

Page created in 0.019 seconds with 19 queries.