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: Most Recent Picture in catlist  (Read 11350 times)

0 Members and 1 Guest are viewing this topic.

philipmatarese

  • Contributor
  • Coppermine newbie
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 8
    • matarese.org - the pictures
Most Recent Picture in catlist
« on: September 11, 2006, 11:27:01 pm »

This mod will add a column to the catlist that shows the date of the most recently added picture and sorts by it.  This mod changes the function get_subcat_data from index.php to return an additional column - you will have to modify your theme to display it.


In index.php find the function get_subcat_data at line 126 (the next updates are all in this function).
Find this code:
Code: [Select]
    $result = cpg_db_query("SELECT cid, name, description, thumb FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent'  ORDER BY $cat_sort_order");Change to this code:
Code: [Select]
    $result = cpg_db_query("SELECT max(p.ctime) max_ctime, c.cid, c.name, c.description, c.thumb FROM {$CONFIG['TABLE_CATEGORIES']} c INNER JOIN {$CONFIG['TABLE_ALBUMS']} a ON c.cid = a.category INNER JOIN {$CONFIG['TABLE_PICTURES']} p ON a.aid = p.aid WHERE parent = '$parent' GROUP BY c.cid, c.name, c.description, c.thumb ORDER BY max_ctime DESC");
Find this code:
Code: [Select]
                if ($album_count) {
                    $cat_data[] = array($link, $ident . $subcat['description'], $album_count, $pic_count);
Change to this code:
Code: [Select]
                $pic_update = $subcat['max_ctime'];
                if ($album_count) {
                    $cat_data[] = array($link, $ident . $subcat['description'], $album_count, $pic_count, $pic_update);

Find this code:
Code: [Select]
                    $cat_data[] = array($link, $subcat['description'], $album_count, $pic_count, 'cat_albums' => $cat_albums, 'cat_thumb' => $user_thumb);Change to this code:
Code: [Select]
                    $pic_update = $subcat['max_ctime'];
                    $cat_data[] = array($link, $subcat['description'], $album_count, $pic_count, $pic_update, 'cat_albums' => $cat_albums,'cat_thumb' =>$user_thumb);



Now add an entry to your language file(s).  Here's english.php.
Find this code:
Code: [Select]
$lang_cat_list = array(
  'category' => 'Category',
  'albums' => 'Albums',
  'pictures' => 'Files',
);
Change to this code:
Code: [Select]
$lang_cat_list = array(
  'category' => 'Category',
  'recent' => 'Most Recent Picture',
  'albums' => 'Albums',
  'pictures' => 'Files',
);



Here are the update to my theme.php, which is pretty close to the classic theme.
Add a column heading:
Code: [Select]
<!-- BEGIN header -->
        <tr>
                <td class="tableh1" width="50%"><b>{CATEGORY}</b></td>
                <td class="tableh1" width="30%" align="center"><b>{DATES}</b></td>
                <td class="tableh1" width="10%" align="center"><b>{ALBUMS}</b></td>
                <td class="tableh1" width="10%" align="center"><b>{PICTURES}</b></td>
        </tr>
<!-- END header -->
Add the data:
Code: [Select]
<!-- BEGIN catrow -->
        <tr>
                <td class="catrow" align="left"><table border="0"><tr><td>{CAT_THUMB}</td><td><span class="catlink"><b>{CAT_TITLE}</b></span>{CAT_DESC}</td></tr></table></td>
                <td class="catrow" align="center">{DATE}</td>
                <td class="catrow" align="center">{ALB_COUNT}</td>
                <td class="catrow" align="center">{PIC_COUNT}</td>
        </tr>
        <tr>
                <td class="tableb" colspan="4">{CAT_ALBUMS}</td>
        </tr>
<!-- END catrow -->
Change any colspans to 4 instead of 3:
Code: [Select]
<!-- BEGIN catrow_noalb -->
        <tr>
                <td class="catrow_noalb" colspan="4"><table border="0"><tr><td align="left">{CAT_THUMB}</td><td align="left"><span class="catlink"><b>{CAT_TITLE}</b></span>{CAT_DESC}</td></tr></table></td>
        </tr>
<!-- END catrow_noalb -->
<!-- BEGIN footer -->
        <tr>
                <td colspan="4" class="tableh1" align="center"><span class="statlink"><b>{STATISTICS}</b></span></td>
        </tr>
<!-- END footer -->
Add the replacement function (if you already have theme_display_cat_list defined, you will have to figure out what differences are important):
Code: [Select]
function theme_display_cat_list($breadcrumb, &$cat_data, $statistics)
{
    global $template_cat_list, $lang_cat_list;

    starttable('100%');

    if (count($cat_data) > 0) {
        $template = template_extract_block($template_cat_list, 'header');
        $params = array('{CATEGORY}' => $lang_cat_list['category'],
            '{DATES}' => $lang_cat_list['recent'],
            '{ALBUMS}' => $lang_cat_list['albums'],
            '{PICTURES}' => $lang_cat_list['pictures'],
            );
        echo template_eval($template, $params);
    }

    $template_noabl = template_extract_block($template_cat_list, 'catrow_noalb');
    $template = template_extract_block($template_cat_list, 'catrow');
    foreach($cat_data as $category) {
        if (count($category) == 3) {
            $params = array('{CAT_TITLE}' => $category[0],
                    '{CAT_THUMB}' => $category['cat_thumb'],
                '{CAT_DESC}' => $category[1]
                );
            echo template_eval($template_noabl, $params);
        } elseif (isset($category['cat_albums']) && ($category['cat_albums'] != '')) {
            $params = array('{CAT_TITLE}' => $category[0],
                '{CAT_THUMB}' => $category['cat_thumb'],
                '{CAT_DESC}' => $category[1],
                '{CAT_ALBUMS}' => $category['cat_albums'],
                '{DATE}' => date("M d, Y",$category[4]),
                '{ALB_COUNT}' => $category[2],
                '{PIC_COUNT}' => $category[3],
                );
            echo template_eval($template, $params);
        } else {
            $params = array('{CAT_TITLE}' => $category[0],
                '{CAT_THUMB}' => $category['cat_thumb'],
                '{CAT_DESC}' => $category[1],
                '{CAT_ALBUMS}' => '',
                '{DATE}' => date("M d, Y",$category[4]),
                '{ALB_COUNT}' => $category[2],
                '{PIC_COUNT}' => $category[3],
                );
            echo template_eval($template, $params);
        }
    }

    if ($statistics && count($cat_data) > 0) {
        $template = template_extract_block($template_cat_list, 'footer');
        $params = array('{STATISTICS}' => $statistics);
        echo template_eval($template, $params);
    }
    endtable();

    if (count($cat_data) > 0)
        echo template_extract_block($template_cat_list, 'spacer');
}
« Last Edit: September 12, 2006, 08:34:58 am by GauGau »
Logged
Pages: [1]   Go Up
 

Page created in 0.03 seconds with 19 queries.