Photo Of The Day Photo Of The Day
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Photo Of The Day

Started by Rick X, March 05, 2011, 03:10:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rick X

My suggestion is to develop a system for photo of the day.

This is very important to take the coppermine to a higher level.

In my humble opinion the picture of the day would bring a lot of interest for users of any website in any language or culture.

Competition is inherent in human beings.

This routine would be based on the direct sum of the votes and a cron job and not so dependent on manual intervention.

That's it.

Thank you for your attention.

Αndré

Quote from: Rick X on March 05, 2011, 03:10:19 PM
This routine would be based on the direct sum of the votes and a cron job and not so dependent on manual intervention.
So the picture with the most votes will be every day the photo of the day? How exactly should it be determined? Where should it be displayed?

Rick X

Quote from: Αndré on March 07, 2011, 12:02:18 PM
So the picture with the most votes will be every day the photo of the day? How exactly should it be determined? Where should it be displayed?

Hi André. The picture with the most votes on that day will be the potd when the sun of votes of that day was the greater. Does not matter when the picture was posted. The sun of votes has to be made day by day. The picture should be displayed in the main page in normal size and caption: Photo of the Day - 99/99/9999.

Thank you.

Αndré

I doubt that this will become a core feature, as Coppermine doesn't stores the date/time when votes has been made by default. And there are more things to consider: What happens if there are no votes on that day? What happens if two pictures have the same votes on that day? Maybe some of the other devs have another opinion regarding this feature request.

Rick X

Quote from: Αndré on March 07, 2011, 04:42:27 PM
I doubt that this will become a core feature, as Coppermine doesn't stores the date/time when votes has been made by default.

1 - That should be added since this is the core of potd. Without this, no potd.

Quote from: Αndré on March 07, 2011, 04:42:27 PMWhat happens if there are no votes on that day?

2 - In a site with a lot of users that will not happens but, if happens, no potd will be displayed.

Quote from: Αndré on March 07, 2011, 04:42:27 PMWhat happens if two pictures have the same votes on that day?

3 - The first one (posted) woud be the photo of the day.

Thanks.

Αndré

If you need that feature urgently I think it can be already accomplished with cpg1.5.x without core code modification. I recommend to enable detailed voting stats and use anycontent.php to store your potd code.

Rick X

Thanks André.

I will try to code it.


Rick X

Well, I did the job.
I coded the photo of the day in a minimalistic way.
It´s fast and has to work as a cron job.
Where, in the forum, I can put the line guides?
Regards!

Αndré

I suggest to post it right here in this thread. We can decide to move it to another place later, if needed.

Rick X

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 potd

2 - 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.br

It it´s cool if you have a lot of users voting.

I´m really sorry if my english is not so good...

Regards.

Αndré

Some things to optimize:
1. Instead of using hard coded table names we should use $CONFIG['TABLE_XYZ'].
2. Instead of using a cron job we could also update the data by adding something similar to Coppermine.
3. Instead of using an xml file, we should store the calculated data in the database.
4. There's a function that checks if an intermediate-sized picture exists (sometimes it isn't needed if the picture is small enough). So it will also work if you don't create intermediate-sized pictures.
5. Instead of calculating your potd once a day it could also be done on the fly.