Guide to put a picture of the day on your site based on votes from the previous day.
Not for beginners.
1 - Create the a writable directory called
potd2 - Enable the statistics of votes in the admin panel
3 - In the album list view-> The content of the main page -> put
anycontent where you want.
4 - Write the following php code and save it as you want into the root directory of Coopermine. Let's say saving with the name of photooftheday.php
<?php
define('IN_COPPERMINE', true);
require('include/init.inc.php');
$result = cpg_db_query("select sum(rating) as total,pid as pid from ftp2011_vote_stats where date(FROM_UNIXTIME(sdate,'%Y-%m-%d'))=date_sub(curdate(),INTERVAL 1 DAY) group by pid order by sum(rating) desc");
if (!mysql_num_rows($result)) {
cpg_die(CRITICAL_ERROR, sprintf("Nenhuma foto do dia"));
}
$CURRENT_ALBUM_DATA = mysql_fetch_assoc($result);
mysql_free_result($result);
$FotoDoDia=$CURRENT_ALBUM_DATA['pid'];
$TotalDeVotos=$CURRENT_ALBUM_DATA['total'];
echo $FotoDoDia.' - '.$TotalDeVotos;
$info_photo_of_the_day=cpg_db_query("select filename,filepath from ftp2011_pictures where pid=".$FotoDoDia);
$current_photo_of_the_day= mysql_fetch_assoc($info_photo_of_the_day);
mysql_free_result($info_photo_of_the_day);
$filename=$current_photo_of_the_day['filename'];
$path_normal=$current_photo_of_the_day['filepath'];
echo $filename.' - '.$path_normal;
$final= '<a href=displayimage.php?pid='.$FotoDoDia.'><img border=0 src=albums/'.$path_normal.'normal_'.$filename.'></a>';
$c = "<root><pod>";
$c.= htmlentities('<a href=displayimage.php?pid='.$FotoDoDia.'><img border=0 src=albums/'.$path_normal.'normal_'.$filename.'></a>',ENT_QUOTES);
$c.= "</pod></root>";
file_put_contents("potd/potd.xml", $c);
?>5 - Open the file anycontent.php and write the following code, right after the-> starttable ("100%", $ lang_index_php ['Welcome']);
if(file_exists('potd/potd.xml')) {
$xmldoc = new DOMDocument();
$xmldoc->load( 'potd/potd.xml' );
$potds = $xmldoc->getElementsByTagName( "root" );
foreach( $potds as $potd )
{
$fotos_do_dia = $potd->getElementsByTagName( "pod" );
$foto_do_dia = $fotos_do_dia->item(0)->nodeValue;
}
echo <<< EOT
<tr>
<td class="tableb" align="center">
{$foto_do_dia}<br>
Foto destaque
</td>
</tr>
EOT;
}
6 - Make a cron job on your server (or on your host) scheduling the task to run everyday after midnight: http:///www.yoursite.com/photooftheday.php
7 -
You must have the "normal" size photos enabled.You can see it working here:
http://www.fotopoint.com.brIt it´s cool if you have a lot of users voting.
I´m really sorry if my english is not so good...
Regards.