forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: Statistics => Topic started by: philipmatarese on September 11, 2006, 11:27:01 pm

Title: Most Recent Picture in catlist
Post by: philipmatarese 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');
}