Hi all,
could you think about improvement of the search engine so that we could search by date using calendar popup? And if possible search the pictures taken between two dates?
Another little idea - is there some particular cause why we can not give to archive a calendar view? That means the visitor could choose if he/she want to see picture arhive as it is displayed today (list of years, months) or as a calendar view? Also, not most important but still very nice would be an iCal feed for those people who may want to show (links to) pictures in their calendar (Google etc).
Comments
So you are invited to provide third party solutions for what you need and provide it for others.
http://www.zenphoto.org/get-involved/
But can you tell me how to make with today's search form query par exemple "between 2009-07-12 and 2010-01-01" to see pictures taken during this periode?
I have started a calendar plugin for the archive page.
But I have a problem. I have done the SQL request so that I have one picture per day but then I do not have informations about the picture: album that it belongs to, paht of the picture to display it, ... and I would like that when I click on the picture, I use the "search" page to display the pictures from the selected day.
Could you please explain me, how to create the plugin properly so that I use the Image class and use the search engine.
Thanks.
PS: I hope you understood everything :-)
For example, to create an album object, I need to have a gallery object and the folder name, and to create an image object, I need an album object and the file name of the picture. But I do not have the information at the beginning. I have only the SQL request.
--- Edit
Where can I have an gallery object? Isn't it created automatically?
For example, I have two albums in September 2009. Those two albums are on the 4 and 12. So my SQL request fetches the first picture of both dates. As result, I have an array of two picture with al the information about the picture and the album it belongs too.
How can I now use this information, and properly-coded, to show this to pictures and linked to the search page with the right search.
I'm really sorry for my questions and my ignorance.
If you don't know the album name and/or image name before hand you have to get them. There are methods like `getAlbums` for example.
If you know the names of the albums, create an object of theme and then use `getImages()` on them. That is an array of the images in that album ordered how you set it in the options. From that you can now create your image objects.
Since you want a calendar it would be better to get images by date or mtime for each date first via SQL and then create an object from that for each. Each image has a albumid so that you then can get its album via SQL as well.
I managed to create my objects and display the thumbnails. Youhouuu!!! :-).
Now the second part, is to link those thumbnails with the search page and the right date. So that the search page, displays all the pictures of the selected date.
I will take example from the original archive page.
When I'm finished with the calendar, I will post the code, so that it can be improved, before publishing it as a plugin.
I managed the calendar plug-in. I must admit that I'm proud of it but I also know that it can be improved.
Please let me know any suggestion. I will give a link on my web page in some days, so you have an example of the plug-in.
So here is the code.
`
/**
* Calendar
*
* It display a calendar per month or per year, with a picture in each where needed
*
* @author the Whole Life To Learn
* @package plugins
*/
$plugin_description = gettext("Prints a calendar with a picture in each day where pictures belong to.");
$plugin_author = "the Whole Life To Learn";
$plugin_version = '1.0.0';
$option_interface = new Calendar();
class Calendar {
private $month;
private $year;
private $minDate;
private $maxDate;
private $strToTime;
/**
* class constructor
*
*/
public function __construct() {
$this->getDates();
$this->variablesInit();
}
/**
* Reports the supported options
*
* @return array
*/
function getOptionsSupported() {
$tmp = array(
gettext('Monthy/Yearly') => array(
'key' => 'calendar_month_year',
'type' => OPTION_TYPE_RADIO,
'buttons' => array(
gettext('Monthly') => 'OPT_MONTH',
gettext('Yearly') => 'OPT_YEAR'
),
'desc' => gettext('Choose if you wish to display a monthly calendar (1 month per page or a yearly calendar (12 month per page)')
)
);
return $tmp;
}
/**
* get the dates that will be used
*
* @return admin_login
*/
private function getDates() {
if( !( isset($_GET['month']) AND is_numeric($_GET['month']) AND $_GET['month'] >= 1 AND $_GET['month'] <= 12) ) {
$this->month = date('m');
//$this->month = '09';
} else {
$this->month = $_GET['month'];
}
if( !( isset($_GET['year']) AND is_numeric($_GET['year']) AND $_GET['year'] <= date('Y') ) ) {
$this->year = date('Y');
//$this->year = '2009';
} else {
$this->year = $_GET['year'];
}
}
public function setDates($month, $year) {
$this->month = $month;
$this->year = $year;
$this->variablesInit();
}
/**
* Initializes the variables needed for the process
*
*/
private function variablesInit() {
$this->minDate = $this->year . '-' . $this->month . '-01';
$this->maxDate = $this->year . '-' . $this->month . '-' . date('t', strtotime($minDate)); // Last day of the month
$this->strToTime = strtotime( $this->minDate );
setOptionDefault('calendar_month_year', 'OPT_MONTH');
}
/**
* Fetches in the database the picture that should be displayed
*
* @return array
*/
protected function getMonth() {
$allDates = array();
$allFiles = array();
$sql = "SELECT DATE_FORMAT(". prefix('images') . ".date, '%Y-%m-%d') as day, ". prefix('albums') . ".title, filename, folder FROM ". prefix('images') . ", ". prefix('albums') . " WHERE ". prefix('images') . ".albumid = ". prefix('albums') . ".id AND ". prefix('images') . ".date >= '$this->minDate' AND ". prefix('images') . ".date <= '$this->maxDate'";
if (!zp_loggedin()) {
$sql .= ' AND ' . prefix('albums') . '.show = 1';
}
$hidealbums = getNotViewableAlbums();
if (!is_null($hidealbums)) {
foreach ($hidealbums as $id) {
$sql .= ' AND albumid!='.$id;
}
}
$sql .= ' GROUP BY day';
$result = query_full_array($sql);
return $result;
}
/**
* Goes to the next picture
*
*/
protected function next_calendar_image( $images, $number ) {
global $_zp_current_image;
set_context( ZP_IMAGE );
$_zp_current_image = $images[$number];
}
/**
* Creates the pictures objects that will be processed
*
* @return array
*/
protected function imgObjCreation( $array ) {
$temp = array();
$galleryObj = new Gallery();
foreach( $array as $a )
{
$album = new Album( $galleryObj, $a['folder'] );
$image = newImage( $album, $a['filename'] );
$temp[] = $image;
}
return $temp;
}
/**
* Creates the the header of the calendar
*
* @return string
*/
protected function getCalHeader() {
$line = '';
if( getOption('calendar_month_year') == 'OPT_MONTH' ) {
$line .= 'minDate . ' -1 Month') ) . '&month=' . date('m', strtotime( $this->minDate . ' -1 Month') ) . '" id="prev"><<</a>';
$line .= ' ' . strftime('%B', $this->strToTime ) .' '. $this->year . ' ';
$line .= 'minDate . ' +1 Month') ) . '&month=' . date('m', strtotime( $this->minDate . ' +1 Month') ) . '" id="next">>>';
} elseif( getOption('calendar_month_year') == 'OPT_YEAR' ) {
$line .= 'minDate . ' -1 Year') ) . '&month=' . date('m', strtotime( $this->minDate . ' -1 Year') ) . '" id="prev"><<</a>';
$line .= ' ' . strftime('%B', $this->strToTime ) .' '. $this->year . ' ';
$line .= 'minDate . ' +1 Year') ) . '&month=' . date('m', strtotime( $this->minDate . ' +1 Year') ) . '" id="next">>>';
}
$line .= '';
$line .= ''.strftime('%A', strtotime('2009-12-07' ) ).'';
$line .= ''.strftime('%A', strtotime('2009-12-08' ) ).'';
$line .= ''.strftime('%A', strtotime('2009-12-09' ) ).'';
$line .= ''.strftime('%A', strtotime('2009-12-10' ) ).'';
$line .= ''.strftime('%A', strtotime('2009-12-11' ) ).'';
$line .= ''.strftime('%A', strtotime('2009-12-12' ) ).'';
$line .= ''.strftime('%A', strtotime('2009-12-13' ) ).'';
return $line;
}
/**
* Creates the body of the calendar
*
* @return string
*/
protected function getCalBody() {
$d = 0;
$line = null;
$allDays = $this->getMonth();
$dayS = $this->imgObjCreation( $allDays );
$this->next_calendar_image($dayS, $d);
for ( $i = ( 2 - date('N', $this->strToTime ) ); $i <= date('t', $this->strToTime ); $i++ ) {
$line .= ' 0) AND (date('N', strtotime( $this->year . '-' . $this->month . '-' . $i ) ) == 1 ) ) {
$line .= ' class="first day">' . $i;
}
// Other days
elseif ( $i > 0 ) {
$line .= ' class="day">' . $i;
}
// Box that is displayed for "beauty" reason
else {
$line .= ' class="empty">';
}
if ( !empty($dayS) and ($i == substr(getImageDate(), 8, 2) ) ) {
$line .= '';
$line .= '';
$line .= '';
if ( $d + 1 < count( $dayS ) ) {
$d++;
}
}
$line .='';
$this->next_calendar_image($dayS, $d);
}
return $line;
}
/**
* Get the monthly calendar
*
* @return string
*/
public function getMonthCalendar() {
$tmp = $this->getCalHeader();
$tmp .= $this->getCalBody();
return $tmp;
}
/**
* Prints a monthly calendar. The user can't modify the data
*
*/
public function printMonthCalendar() {
echo '
';
';echo $this->getMonthCalendar();
echo '
}
/**
* get a yearly calendar
*
* @return string
*/
public function getYearCalendar() {
$cal = null;
for( $i = 1; $i <= 12; $i++ ) {
$this->setDates($i, $this->year);
$cal .= $this->getMonthCalendar();
$cal .= '';
}
return $cal;
}
/**
* Prints on the screen a yearly based calendar. The data can't be modified by the user.
*
*/
public function printYearCalendar() {
$cal = null;
echo '
';
';echo $this->getYearCalendar();
echo '
}
}
function printMonthCalendar() {
$cal = new Calendar();
$cal->printMonthCalendar();
}
function getMonthCalendar() {
$cal = new Calendar();
$cal->getMonthCalendar();
}
function printYearCalendar() {
$cal = new Calendar();
$cal->printYearCalendar();
}
function getYearCalendar() {
$cal = new Calendar();
$cal->getYearCalendar();
}
/**
* Prints a monthly or yearly based calendar depending on the option defined in the administration panel
*
*/
function printCalendar() {
$cal = new Calendar();
if( getOption('calendar_month_year') == 'OPT_MONTH' ) {
$cal->printMonthCalendar();
} elseif( getOption('calendar_month_year') == 'OPT_YEAR' ) {
$cal->printYearCalendar();
}
}
`
Although it probably works the class object you create with `$option_interface = new Calendar();` is actually only meant for the plugin option setup for the backend.
I was using my brothers account and I created now my own.
I have created a post for this plug-in few seconds ago at this page:
http://www.zenphoto.org/support/topic.php?id=7782&replies=1#post-45970