Photo of the Day / Week hack
This hack adds an admin settable photo of the Day, Photo of the Week, or both, to a gallery, without the need to move files around between albums.
These selected photos can be displayed on the gallery index page, or any other page on the site, or in their own page.
This hack also adds archive albums, which will display the previous selected photos, in reverse date order.
Although these are set as photos of the day or week, it is easy to change this to month or year etc, simply by changing 2 lines in the language file.
Open file editpics.php.
Find;
$user_album_set = array();
foreach($user_albums_list as $album) $user_album_set[$album['aid']] = 1;
add after;
// Create a timestamp.
$timestamp = time();
Find;
$reset_votes = isset($_POST['reset_votes'.$pid]);
add after;
$reset_potd = isset($_POST['reset_potd'.$pid]);
$reset_potd_date = isset($_POST['reset_potd_date'.$pid]);
$reset_potdn = isset($_POST['reset_potdn'.$pid]);
$reset_potw = isset($_POST['reset_potw'.$pid]);
$reset_potw_date = isset($_POST['reset_potw_date'.$pid]);
$reset_potwn = isset($_POST['reset_potwn'.$pid]);
Find;
if ($reset_votes) $update .= ", pic_rating = '0', votes = '0'";
Add after;
if (GALLERY_ADMIN_MODE) {
if ($reset_potd) $update .= ", potd = '1', potd_date = '$timestamp'";
if ($reset_potdn) $update .= ", potd = '2'";
if ($reset_potw) $update .= ", potw = '1', potw_date = '$timestamp'";
if ($reset_potwn) $update .= ", potw = '2'";
}
Find;
<tr>
<td class="tableb" colspan="3" align="center">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="20%" align="center"><input type="radio" name="galleryicon" id="galleryicon{$CURRENT_PIC['pid']}" value="{$CURRENT_PIC['pid']}" {$isgalleryicon_selected}{$isgalleryicon_disabled}class="checkbox">{$lang_editpics_php['gallery_icon']}</td>
<td width="20%" align="center"><input type="checkbox" name="delete{$CURRENT_PIC['pid']}" id="delete{$CURRENT_PIC['pid']}" value="1" class="checkbox"><label for="delete{$CURRENT_PIC['pid']}" class="clickable_option">{$lang_editpics_php['del_pic']}</label></td>
<td width="20%" align="center"><input type="checkbox" name="reset_vcount{$CURRENT_PIC['pid']}" id="reset_vcount{$CURRENT_PIC['pid']}" value="1" class="checkbox"><label for="reset_vcount{$CURRENT_PIC['pid']}" class="clickable_option">{$lang_editpics_php['reset_view_count']}</label></td>
<td width="20%" align="center"><input type="checkbox" name="reset_votes{$CURRENT_PIC['pid']}" id="reset_votes{$CURRENT_PIC['pid']}" value="1" class="checkbox"><label for="reset_votes{$CURRENT_PIC['pid']}" class="clickable_option">{$lang_editpics_php['reset_votes']}</label></td>
<td width="20%" align="center"><input type="checkbox" name="del_comments{$CURRENT_PIC['pid']}" id="del_comments{$CURRENT_PIC['pid']}" value="1" class="checkbox"><label for="del_comments{$CURRENT_PIC['pid']}" class="clickable_option">{$lang_editpics_php['del_comm']}</label></td>
</tr>
</table>
</td>
</tr>
EOT;
}
}
Replace with;
<tr>
<td class="tableb" colspan="3" align="center">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="20%" align="center"><input type="radio" name="galleryicon" id="galleryicon{$CURRENT_PIC['pid']}" value="{$CURRENT_PIC['pid']}" {$isgalleryicon_selected}{$isgalleryicon_disabled}class="checkbox">{$lang_editpics_php['gallery_icon']}</td>
<td width="20%" align="center"><input type="checkbox" name="delete{$CURRENT_PIC['pid']}" id="delete{$CURRENT_PIC['pid']}" value="1" class="checkbox"><label for="delete{$CURRENT_PIC['pid']}" class="clickable_option">{$lang_editpics_php['del_pic']}</label></td>
<td width="20%" align="center"><input type="checkbox" name="reset_vcount{$CURRENT_PIC['pid']}" id="reset_vcount{$CURRENT_PIC['pid']}" value="1" class="checkbox"><label for="reset_vcount{$CURRENT_PIC['pid']}" class="clickable_option">{$lang_editpics_php['reset_view_count']}</label></td>
<td width="20%" align="center"><input type="checkbox" name="reset_votes{$CURRENT_PIC['pid']}" id="reset_votes{$CURRENT_PIC['pid']}" value="1" class="checkbox"><label for="reset_votes{$CURRENT_PIC['pid']}" class="clickable_option">{$lang_editpics_php['reset_votes']}</label></td> <td width="20%" align="center"><input type="checkbox" name="del_comments{$CURRENT_PIC['pid']}" id="del_comments{$CURRENT_PIC['pid']}" value="1" class="checkbox"><label for="del_comments{$CURRENT_PIC['pid']}" class="clickable_option">{$lang_editpics_php['del_comm']}</label></td></tr>
</table>
</td>
</tr>
EOT;
if (GALLERY_ADMIN_MODE){
echo <<<EOT
<tr>
<td class="tableb" colspan="3" align="center">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<tr>
<td width="25%" align="center">
<b><input type="checkbox" name="reset_potd{$CURRENT_PIC['pid']}" value="YES" class="checkbox" />{$lang_editpics_php['potdnew']}</b></td><td width="25%" align="center"><b><input type="checkbox" name="reset_potdn{$CURRENT_PIC['pid']}" value="NO" class="checkbox" />{$lang_editpics_php['potdold']}</b>
<td width="25%" align="center">
<b><input type="checkbox" name="reset_potw{$CURRENT_PIC['pid']}" value="YES" class="checkbox" />{$lang_editpics_php['potwnew']}</b></td><td width="25%" align="center"><b><input type="checkbox" name="reset_potwn{$CURRENT_PIC['pid']}" value="NO" class="checkbox" />{$lang_editpics_php['potwold']}</b>
</td>
</tr>
</table>
</td>
</tr>
EOT;
}
}
}
Save and close editpics.php
--------------------------------------------------------------------------------------------------
Open your language file, english.php shown here.
Find;
$lang_meta_album_names = array(
Add into the array;
'potd' => 'Photo of the Day',
'potdarch' => 'Photo of the Day Archive',
'potw' => 'Photo of the Week',
'potwarch' => 'Photo of the Week Archive',
'by' => 'by our member ',
Change the above translations as you need them.
Find;
// File editpics.php
add into the array;
'potdnew' => 'Set as P.o.t.Day',
'potdold' => 'Move to POTD archive',
'potwnew' => 'Set as P.o.t.Week',
'potwold' => 'Move to POTW archive',
Change the translations as you need them.
Save and close your language file.
----------------------------------------------------------------------------------------------------
Open your include/functions.inc.php.
Find;
case 'topn': // Most viewed pictures
Add, immediately before this;
case 'potdarch': // Last uploads
if ($ALBUM_SET && $CURRENT_CAT_NAME) {
$album_name = $lang_meta_album_names['potdarch'].' - '. $CURRENT_CAT_NAME;
} else {
$album_name = $lang_meta_album_names['potdarch'];
}
$query = "SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE (approved = 'YES' && potd = '2') $ALBUM_SET";
$result = db_query($query);
$nbEnr = mysql_fetch_array($result);
$count = $nbEnr[0];
mysql_free_result($result);
if($select_columns != '*' ) $select_columns .= ',title, caption, owner_id, owner_name, potd_date';
$query = "SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE (approved = 'YES' && potd = '2') $ALBUM_SET ORDER BY potd_date DESC $limit";
$result = db_query($query);
$rowset = db_fetch_rowset($result);
mysql_free_result($result);
if ($set_caption) foreach ($rowset as $key => $row){
$user_link = ($CONFIG['display_uploader'] && $row['owner_id'] && $row['owner_name']) ? '<span class="thumb_title"><a href ="profile.php?uid='.$row['owner_id'].'">'.$row['owner_name'].'</a></span>' : '';
$caption = $user_link.'<span class="thumb_caption">'.localised_date($row['potd_date'], $lastup_date_fmt).'</span>';
$rowset[$key]['caption_text'] = $caption;
}
$rowset = CPGPluginAPI::filter('thumb_caption_lastup',$rowset);
return $rowset;
break;
case 'potwarch': // Last uploads
if ($ALBUM_SET && $CURRENT_CAT_NAME) {
$album_name = $lang_meta_album_names['potwarch'].' - '. $CURRENT_CAT_NAME;
} else {
$album_name = $lang_meta_album_names['potwarch'];
}
$query = "SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE (approved = 'YES' && potw = '2') $ALBUM_SET";
$result = db_query($query);
$nbEnr = mysql_fetch_array($result);
$count = $nbEnr[0];
mysql_free_result($result);
if($select_columns != '*' ) $select_columns .= ',title, caption, owner_id, owner_name, potw_date';
$query = "SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE (approved = 'YES' && potw = '2') $ALBUM_SET ORDER BY potw_date DESC $limit";
$result = db_query($query);
$rowset = db_fetch_rowset($result);
mysql_free_result($result);
if ($set_caption) foreach ($rowset as $key => $row){
$user_link = ($CONFIG['display_uploader'] && $row['owner_id'] && $row['owner_name']) ? '<span class="thumb_title"><a href ="profile.php?uid='.$row['owner_id'].'">'.$row['owner_name'].'</a></span>' : '';
$caption = $user_link.'<span class="thumb_caption">'.localised_date($row['potw_date'], $lastup_date_fmt).'</span>';
$rowset[$key]['caption_text'] = $caption;
}
$rowset = CPGPluginAPI::filter('thumb_caption_lastup',$rowset);
return $rowset;
break;
Save and close functions.inc.php
---------------------------------------------------------------------------------------------------
Open index.php.
Find;
case 'lasthits':
display_thumbnails('lasthits', $cat, 1, $CONFIG['thumbcols'], max(1, $matches[2]), false);
flush();
break;
Add after;
case 'potd':
if ($cat == 0) {
include('potd.php');
}
flush();
break;
case 'potw':
if ($cat == 0) {
include('potw.php');
}
flush();
break;
Save and close index.php.
----------------------------------------------------------------------------------------------------
Now, upload the file update.sql into the sql folder on your server, replacing the one that is there.
Now you need to make 1 edit to each of the enclosed files, as they are designed for use with version 1.4.
Open each of the files, and find 'cpg_db_query', and change it to 'db_query'. Each file has this once only.
Now, depending on what you want, upload the following.
- To show the POTD or POTW (or both) on the gallery index page, similar to anycontent.php, upload potd.php and/orpotw.php
- To show the POTD or POTW (or both) in seperate pages within the gallery itsef, upload day.php and/or week.php
- To show the POTD or POTW (or both) on other pages outside of your coppermine gallery(but on the same server), upload showdaypic.php and/or showweekpic.php
- To show the thumb versions of above outside your gallery, upload daythumb.php and/or thumbweek.php
You can use any combination of the above.
Run the update by going into admin tools, and click on 'Update database'.
Well, that's it, your Photo of the Day is ready to use. See the file potduse.html for instructions on how to use.
Good luck.