URL rewrite for chronology: uses $page['chronology'] and

$page['chronology_date']. $page['chronology'] is an array with 'field', 
'style' and 'view' keys. This is step 1.

git-svn-id: http://piwigo.org/svn/trunk@1086 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices 2006-03-17 04:13:19 +00:00
commit 97b681f1fa
8 changed files with 415 additions and 373 deletions

View file

@ -131,26 +131,29 @@ if (isset($page['cat_nb_images']) and $page['cat_nb_images'] > 0)
$icon_recent = get_icon(date('Y-m-d')); $icon_recent = get_icon(date('Y-m-d'));
$calendar_view_link = duplicate_index_URL( if (!isset($page['chronology']))
array(), // nothing to redefine
array('chronology_type', 'start') // what to remove ?
);
if (!isset($page['chronology_type']))
{ {
$calendar_view_link.= '/calendar-'; $chronology =
array(
'chronology' =>
array(
'field' => 'created',
'style' => 'monthly',
'view' => 'list',
)
);
$template->assign_block_vars( $template->assign_block_vars(
'mode_created', 'mode_created',
array( array(
'URL' => $calendar_view_link.'created' 'URL' => duplicate_index_URL( $chronology, array('start') )
) )
); );
$chronology['chronology']['field'] = 'posted';
$template->assign_block_vars( $template->assign_block_vars(
'mode_posted', 'mode_posted',
array( array(
'URL' => $calendar_view_link.'posted' 'URL' => duplicate_index_URL( $chronology, array('start') )
) )
); );
} }
@ -159,29 +162,29 @@ else
$template->assign_block_vars( $template->assign_block_vars(
'mode_normal', 'mode_normal',
array( array(
'URL' => $calendar_view_link 'URL' => duplicate_index_URL( array(), array('chronology','start') )
) )
); );
$calendar_view_link .= '/calendar-'; $chronology = $page['chronology'];
if ($page['chronology_type'] == 'created') if ($chronology['field'] == 'created')
{ {
$template->assign_block_vars( $chronology['field'] = 'posted';
'mode_posted',
array(
'URL' => $calendar_view_link.'posted'
)
);
} }
else else
{ {
$template->assign_block_vars( $chronology['field'] = 'created';
'mode_created',
array(
'URL' => $calendar_view_link.'created'
)
);
} }
$url = duplicate_index_URL(
array(
'chronology'=>$chronology
),
array('chronology_date', 'start')
);
$template->assign_block_vars(
'mode_'.$chronology['field'],
array('URL' => $url )
);
} }
$template->assign_vars( $template->assign_vars(
@ -293,10 +296,16 @@ $template->assign_block_vars(
'special_cat', 'special_cat',
array( array(
'URL' => 'URL' =>
make_index_URL() make_index_URL(
.'/calendar-' array(
.($conf['calendar_datefield'] == 'date_available' ? 'posted' : 'created') 'chronology'=>
.'-monthly-c', array(
'field' => ($conf['calendar_datefield']=='date_available' ? 'posted' : 'created'),
'style' => 'monthly',
'view' => 'calendar'
)
)
),
'TITLE' => $lang['calendar_hint'], 'TITLE' => $lang['calendar_hint'],
'NAME' => $lang['calendar'] 'NAME' => $lang['calendar']
) )

View file

@ -33,10 +33,6 @@ class CalendarBase
var $date_field; var $date_field;
// used for queries (INNER JOIN or normal) // used for queries (INNER JOIN or normal)
var $inner_sql; var $inner_sql;
// base url used when generating html links
var $url_base;
// array of date components e.g. (2005,10,12) ...
var $date_components;
// //
var $calendar_levels; var $calendar_levels;
@ -44,44 +40,48 @@ class CalendarBase
/** /**
* Initialize the calendar * Initialize the calendar
* @param string date_field db column on which this calendar works
* @param string inner_sql used for queries (INNER JOIN or normal) * @param string inner_sql used for queries (INNER JOIN or normal)
* @param array date_components
*/ */
function initialize($date_field, $inner_sql, $date_components) function initialize($inner_sql)
{ {
$this->date_field = $date_field; global $page;
if ($page['chronology']['field']=='posted')
{
$this->date_field = 'date_available';
}
else
{
$this->date_field = 'date_creation';
}
$this->inner_sql = $inner_sql; $this->inner_sql = $inner_sql;
$this->date_components = $date_components;
$this->has_nav_bar = false; $this->has_nav_bar = false;
} }
function get_display_name() function get_display_name()
{ {
global $conf; global $conf, $page;
$res = ''; $res = '';
$url = $this->url_base;
for ($i=0; $i<count($this->date_components); $i++) for ($i=0; $i<count($page['chronology_date']); $i++)
{ {
$res .= $conf['level_separator']; $res .= $conf['level_separator'];
if ($i>0) if ( isset($page['chronology_date'][$i+1]) )
{
$url .= '-';
}
$url .= $this->date_components[$i];
if ( isset($this->date_components[$i+1]) )
{ {
$chronology_date = array_slice($page['chronology_date'],0, $i+1);
$url = duplicate_index_url(
array( 'chronology_date'=>$chronology_date ),
array( 'start' )
);
$res .= $res .=
'<a href="'.$url.'">' '<a href="'.$url.'">'
.$this->get_date_component_label($i, $this->date_components[$i]) .$this->get_date_component_label($i, $page['chronology_date'][$i])
.'</a>'; .'</a>';
} }
else else
{ {
$res .= $res .=
'<span class="calInHere">' '<span class="calInHere">'
.$this->get_date_component_label($i, $this->date_components[$i]) .$this->get_date_component_label($i, $page['chronology_date'][$i])
.'</span>'; .'</span>';
} }
} }
@ -131,7 +131,7 @@ class CalendarBase
/** /**
* Creates a calendar navigation bar. * Creates a calendar navigation bar.
* *
* @param string url_base - links start with this root * @param array date_components
* @param array items - hash of items to put in the bar (e.g. 2005,2006) * @param array items - hash of items to put in the bar (e.g. 2005,2006)
* @param array selected_item - item currently selected (e.g. 2005) * @param array selected_item - item currently selected (e.g. 2005)
* @param string class_prefix - html class attribute prefix for span elements * @param string class_prefix - html class attribute prefix for span elements
@ -140,11 +140,11 @@ class CalendarBase
* @param array labels - optional labels for items (e.g. Jan,Feb,...) * @param array labels - optional labels for items (e.g. Jan,Feb,...)
* @return string the navigation bar * @return string the navigation bar
*/ */
function get_nav_bar_from_items($url_base, $items, $selected_item, function get_nav_bar_from_items($date_components, $items, $selected_item,
$class_prefix, $show_any, $class_prefix, $show_any,
$show_empty=false, $labels=null) $show_empty=false, $labels=null)
{ {
global $conf; global $conf, $page;
$nav_bar = ''; $nav_bar = '';
@ -180,7 +180,10 @@ class CalendarBase
else else
{ {
$nav_bar .= '<span class="'.$class_prefix.'">'; $nav_bar .= '<span class="'.$class_prefix.'">';
$url = $url_base . $item; $url = duplicate_index_url(
array('chronology_date'=>array_merge($date_components,$item)),
array( 'start' )
);
$nav_bar .= '<a href="'.$url.'">'; $nav_bar .= '<a href="'.$url.'">';
$nav_bar .= $label; $nav_bar .= $label;
$nav_bar .= '</a>'; $nav_bar .= '</a>';
@ -203,7 +206,10 @@ class CalendarBase
else else
{ {
$nav_bar .= '<span class="'.$class_prefix.'">'; $nav_bar .= '<span class="'.$class_prefix.'">';
$url = $url_base . 'any'; $url = duplicate_index_url(
array('chronology_date'=>array_merge($date_components,'any')),
array( 'start' )
);
$nav_bar .= '<a href="'.$url.'">'; $nav_bar .= '<a href="'.$url.'">';
$nav_bar .= $label; $nav_bar .= $label;
$nav_bar .= '</a>'; $nav_bar .= '</a>';
@ -221,7 +227,7 @@ class CalendarBase
*/ */
function build_nav_bar($level, $labels=null) function build_nav_bar($level, $labels=null)
{ {
global $template, $conf; global $template, $conf, $page;
$query = ' $query = '
SELECT DISTINCT('.$this->calendar_levels[$level]['sql'] SELECT DISTINCT('.$this->calendar_levels[$level]['sql']
@ -240,14 +246,14 @@ SELECT DISTINCT('.$this->calendar_levels[$level]['sql']
} }
if ( count($level_items)==1 and if ( count($level_items)==1 and
count($this->date_components)<count($this->calendar_levels)-1) count($page['chronology_date'])<count($this->calendar_levels)-1)
{ {
if ( ! isset($this->date_components[$level]) ) if ( ! isset($page['chronology_date'][$level]) )
{ {
list($key) = array_keys($level_items); list($key) = array_keys($level_items);
$this->date_components[$level] = (int)$key; $page['chronology_date'][$level] = (int)$key;
if ( $level<count($this->date_components) and if ( $level<count($page['chronology_date']) and
$level!=count($this->calendar_levels)-1 ) $level!=count($this->calendar_levels)-1 )
{ {
return; return;
@ -255,16 +261,8 @@ SELECT DISTINCT('.$this->calendar_levels[$level]['sql']
} }
} }
$url_base = $this->url_base;
for ($i=0; $i<$level; $i++)
{
if (isset($this->date_components[$i]))
{
$url_base .= $this->date_components[$i].'-';
}
}
$nav_bar = $this->get_nav_bar_from_items( $nav_bar = $this->get_nav_bar_from_items(
$url_base, $page['chronology_date'],
$level_items, $level_items,
null, null,
'calItem', 'calItem',
@ -288,14 +286,14 @@ SELECT DISTINCT('.$this->calendar_levels[$level]['sql']
*/ */
function build_next_prev() function build_next_prev()
{ {
global $template; global $template, $page;
$prev = $next =null; $prev = $next =null;
if ( empty($this->date_components) ) if ( empty($page['chronology_date']) )
return; return;
$query = 'SELECT CONCAT_WS("-"'; $query = 'SELECT CONCAT_WS("-"';
for ($i=0; $i<count($this->date_components); $i++) for ($i=0; $i<count($page['chronology_date']); $i++)
{ {
if ( 'any' === $this->date_components[$i] ) if ( 'any' === $page['chronology_date'] )
{ {
$query .= ','.'"any"'; $query .= ','.'"any"';
} }
@ -304,7 +302,7 @@ SELECT DISTINCT('.$this->calendar_levels[$level]['sql']
$query .= ','.$this->calendar_levels[$i]['sql']; $query .= ','.$this->calendar_levels[$i]['sql'];
} }
} }
$current = implode('-', $this->date_components ); $current = implode('-', $page['chronology_date'] );
$query.=') as period' . $this->inner_sql .' $query.=') as period' . $this->inner_sql .'
AND ' . $this->date_field . ' IS NOT NULL AND ' . $this->date_field . ' IS NOT NULL
@ -327,26 +325,32 @@ GROUP BY period';
{ {
$template->assign_block_vars( 'calendar.navbar', array() ); $template->assign_block_vars( 'calendar.navbar', array() );
} }
if ( $current_rank>0 ) if ( $current_rank>0 )
{ // has previous { // has previous
$prev = $upper_items[$current_rank-1]; $prev = $upper_items[$current_rank-1];
$chronology_date = explode('-', $prev);
$template->assign_block_vars( $template->assign_block_vars(
'calendar.navbar.prev', 'calendar.navbar.prev',
array( array(
'LABEL' => $this->get_date_nice_name($prev), 'LABEL' => $this->get_date_nice_name($prev),
'URL' => $this->url_base . $prev, 'URL' => duplicate_index_url(
array('chronology_date'=>$chronology_date), array('start')
)
) )
); );
} }
if ( $current_rank < count($upper_items)-1 ) if ( $current_rank < count($upper_items)-1 )
{ { // has next
// has next
$next = $upper_items[$current_rank+1]; $next = $upper_items[$current_rank+1];
$chronology_date = explode('-', $next);
$template->assign_block_vars( $template->assign_block_vars(
'calendar.navbar.next', 'calendar.navbar.next',
array( array(
'LABEL' => $this->get_date_nice_name($next), 'LABEL' => $this->get_date_nice_name($next),
'URL' => $this->url_base . $next, 'URL' => duplicate_index_url(
array('chronology_date'=>$chronology_date), array('start')
)
) )
); );
} }

View file

@ -1,4 +1,4 @@
<?php <?php
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery | // | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | // | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
@ -38,13 +38,11 @@ class Calendar extends CalendarBase
/** /**
* Initialize the calendar * Initialize the calendar
* @param string date_field db column on which this calendar works
* @param string inner_sql used for queries (INNER JOIN or normal) * @param string inner_sql used for queries (INNER JOIN or normal)
* @param array date_components
*/ */
function initialize($date_field, $inner_sql, $date_components) function initialize($inner_sql)
{ {
parent::initialize($date_field, $inner_sql, $date_components); parent::initialize($inner_sql);
global $lang; global $lang;
$this->calendar_levels = array( $this->calendar_levels = array(
array( array(
@ -67,21 +65,20 @@ class Calendar extends CalendarBase
* @return boolean false to indicate that thumbnails * @return boolean false to indicate that thumbnails
* where not included here, true otherwise * where not included here, true otherwise
*/ */
function generate_category_content($url_base, $view_type) function generate_category_content()
{ {
global $conf; global $conf, $page;
$this->url_base = $url_base;
$view_type = $page['chronology']['view'];
if ($view_type==CAL_VIEW_CALENDAR) if ($view_type==CAL_VIEW_CALENDAR)
{ {
if ( count($this->date_components)==0 ) if ( count($page['chronology_date'])==0 )
{//case A: no year given - display all years+months {//case A: no year given - display all years+months
if ($this->build_global_calendar()) if ($this->build_global_calendar())
return true; return true;
} }
if ( count($this->date_components)==1 ) if ( count($page['chronology_date'])==1 )
{//case B: year given - display all days in given year {//case B: year given - display all days in given year
if ($this->build_year_calendar()) if ($this->build_year_calendar())
{ {
@ -90,7 +87,7 @@ function generate_category_content($url_base, $view_type)
} }
} }
if ( count($this->date_components)==2 ) if ( count($page['chronology_date'])==2 )
{//case C: year+month given - display a nice month calendar {//case C: year+month given - display a nice month calendar
$this->build_month_calendar(); $this->build_month_calendar();
//$this->build_nav_bar(CYEAR); // years //$this->build_nav_bar(CYEAR); // years
@ -100,21 +97,21 @@ function generate_category_content($url_base, $view_type)
} }
} }
if ($view_type==CAL_VIEW_LIST or count($this->date_components)==3) if ($view_type==CAL_VIEW_LIST or count($page['chronology_date'])==3)
{ {
$has_nav_bar = false; $has_nav_bar = false;
if ( count($this->date_components)==0 ) if ( count($page['chronology_date'])==0 )
{ {
$this->build_nav_bar(CYEAR); // years $this->build_nav_bar(CYEAR); // years
} }
if ( count($this->date_components)==1) if ( count($page['chronology_date'])==1)
{ {
$this->build_nav_bar(CMONTH); // month $this->build_nav_bar(CMONTH); // month
} }
if ( count($this->date_components)==2 ) if ( count($page['chronology_date'])==2 )
{ {
$day_labels = range( 1, $this->get_all_days_in_month( $day_labels = range( 1, $this->get_all_days_in_month(
$this->date_components[CYEAR] ,$this->date_components[CMONTH] ) ); $page['chronology_date'][CYEAR] ,$page['chronology_date'][CMONTH] ) );
array_unshift($day_labels, 0); array_unshift($day_labels, 0);
unset( $day_labels[0] ); unset( $day_labels[0] );
$this->build_nav_bar( CDAY, $day_labels ); // days $this->build_nav_bar( CDAY, $day_labels ); // days
@ -133,7 +130,8 @@ function generate_category_content($url_base, $view_type)
*/ */
function get_date_where($max_levels=3) function get_date_where($max_levels=3)
{ {
$date = $this->date_components; global $page;
$date = $page['chronology_date'];
while (count($date)>$max_levels) while (count($date)>$max_levels)
{ {
array_pop($date); array_pop($date);
@ -218,7 +216,8 @@ function get_all_days_in_month($year, $month)
function build_global_calendar() function build_global_calendar()
{ {
assert( count($this->date_components) == 0 ); global $page;
assert( count($page['chronology_date']) == 0 );
$query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%Y%m")) as period, $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%Y%m")) as period,
COUNT( DISTINCT(id) ) as count'; COUNT( DISTINCT(id) ) as count';
$query.= $this->inner_sql; $query.= $this->inner_sql;
@ -244,21 +243,21 @@ function build_global_calendar()
if (count($items)==1) if (count($items)==1)
{// only one year exists so bail out to year view {// only one year exists so bail out to year view
list($y) = array_keys($items); list($y) = array_keys($items);
$this->date_components[CYEAR] = $y; $page['chronology_date'][CYEAR] = $y;
return false; return false;
} }
global $lang, $template; global $lang, $template;
foreach ( $items as $year=>$year_data) foreach ( $items as $year=>$year_data)
{ {
$url_base = $this->url_base.$year; $chronology_date = array( $year );
$url = duplicate_index_url( array('chronology_date'=>$chronology_date) );
$nav_bar = '<span class="calCalHead"><a href="'.$url_base.'">'.$year.'</a>'; $nav_bar = '<span class="calCalHead"><a href="'.$url.'">'.$year.'</a>';
$nav_bar .= ' ('.$year_data['nb_images'].')'; $nav_bar .= ' ('.$year_data['nb_images'].')';
$nav_bar .= '</span><br>'; $nav_bar .= '</span><br>';
$url_base .= '-'; $nav_bar .= $this->get_nav_bar_from_items( $chronology_date,
$nav_bar .= $this->get_nav_bar_from_items( $url_base,
$year_data['children'], null, 'calCal', false, false, $lang['month'] ); $year_data['children'], null, 'calCal', false, false, $lang['month'] );
$template->assign_block_vars( 'calendar.calbar', $template->assign_block_vars( 'calendar.calbar',
@ -270,7 +269,8 @@ function build_global_calendar()
function build_year_calendar() function build_year_calendar()
{ {
assert( count($this->date_components) == 1 ); global $page;
assert( count($page['chronology_date']) == 1 );
$query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%m%d")) as period, $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%m%d")) as period,
COUNT( DISTINCT(id) ) as count'; COUNT( DISTINCT(id) ) as count';
$query.= $this->inner_sql; $query.= $this->inner_sql;
@ -294,21 +294,21 @@ function build_year_calendar()
if (count($items)==1) if (count($items)==1)
{ // only one month exists so bail out to month view { // only one month exists so bail out to month view
list($m) = array_keys($items); list($m) = array_keys($items);
$this->date_components[CMONTH] = $m; $page['chronology_date'][CMONTH] = $m;
return false; return false;
} }
global $lang, $template; global $lang, $template;
foreach ( $items as $month=>$month_data) foreach ( $items as $month=>$month_data)
{ {
$url_base = $this->url_base.$this->date_components[CYEAR].'-'.$month; $chronology_date = array( $page['chronology_date'][CYEAR], $month );
$url = duplicate_index_url( array('chronology_date'=>$chronology_date) );
$nav_bar = '<span class="calCalHead"><a href="'.$url_base.'">'; $nav_bar = '<span class="calCalHead"><a href="'.$url.'">';
$nav_bar .= $lang['month'][$month].'</a>'; $nav_bar .= $lang['month'][$month].'</a>';
$nav_bar .= ' ('.$month_data['nb_images'].')'; $nav_bar .= ' ('.$month_data['nb_images'].')';
$nav_bar .= '</span><br>'; $nav_bar .= '</span><br>';
$url_base .= '-'; $nav_bar .= $this->get_nav_bar_from_items( $chronology_date,
$nav_bar .= $this->get_nav_bar_from_items( $url_base,
$month_data['children'], null, 'calCal', false ); $month_data['children'], null, 'calCal', false );
$template->assign_block_vars( 'calendar.calbar', $template->assign_block_vars( 'calendar.calbar',
@ -321,10 +321,11 @@ function build_year_calendar()
function build_month_calendar() function build_month_calendar()
{ {
global $page;
$query='SELECT DISTINCT(DAYOFMONTH('.$this->date_field.')) as period, $query='SELECT DISTINCT(DAYOFMONTH('.$this->date_field.')) as period,
COUNT( DISTINCT(id) ) as count'; COUNT( DISTINCT(id) ) as count';
$query.= $this->inner_sql; $query.= $this->inner_sql;
$query.= $this->get_date_where($this->date_components); $query.= $this->get_date_where();
$query.= ' $query.= '
GROUP BY period'; GROUP BY period';
@ -337,7 +338,7 @@ function build_month_calendar()
foreach ( $items as $day=>$data) foreach ( $items as $day=>$data)
{ {
$this->date_components[CDAY]=$day; $page['chronology_date'][CDAY]=$day;
$query = ' $query = '
SELECT file,tn_ext,path, width, height, DAYOFWEEK('.$this->date_field.')-1 as dow'; SELECT file,tn_ext,path, width, height, DAYOFWEEK('.$this->date_field.')-1 as dow';
$query.= $this->inner_sql; $query.= $this->inner_sql;
@ -345,7 +346,7 @@ SELECT file,tn_ext,path, width, height, DAYOFWEEK('.$this->date_field.')-1 as do
$query.= ' $query.= '
ORDER BY RAND() ORDER BY RAND()
LIMIT 0,1'; LIMIT 0,1';
unset ( $this->date_components[CDAY] ); unset ( $page['chronology_date'][CDAY] );
$row = mysql_fetch_array(pwg_query($query)); $row = mysql_fetch_array(pwg_query($query));
$items[$day]['tn_path'] = get_thumbnail_src($row['path'], @$row['tn_ext']); $items[$day]['tn_path'] = get_thumbnail_src($row['path'], @$row['tn_ext']);
@ -416,8 +417,11 @@ SELECT file,tn_ext,path, width, height, DAYOFWEEK('.$this->date_field.')-1 as do
$template->assign_block_vars('calendar.thumbnails.row.col', array()); $template->assign_block_vars('calendar.thumbnails.row.col', array());
$template->assign_block_vars('calendar.thumbnails.row.col.blank', array()); $template->assign_block_vars('calendar.thumbnails.row.col.blank', array());
} }
for ($day=1; $day<=$this->get_all_days_in_month( for ( $day = 1;
$this->date_components[CYEAR] ,$this->date_components[CMONTH]); $day++) $day <= $this->get_all_days_in_month(
$page['chronology_date'][CYEAR], $page['chronology_date'][CMONTH]
);
$day++)
{ {
$dow = ($first_day_dow + $day-1)%7; $dow = ($first_day_dow + $day-1)%7;
if ($dow==0) if ($dow==0)
@ -486,9 +490,16 @@ SELECT file,tn_ext,path, width, height, DAYOFWEEK('.$this->date_field.')-1 as do
{ {
$css_style.='top:'.round(-$pos_top).'px;'; $css_style.='top:'.round(-$pos_top).'px;';
} }
$url = $this->url_base. $url = duplicate_index_url(
$this->date_components[CYEAR].'-'. array(
$this->date_components[CMONTH].'-'.$day; 'chronology_date' =>
array(
$page['chronology_date'][CYEAR],
$page['chronology_date'][CMONTH],
$day
)
)
);
$alt = $wday_labels[$dow] . ' ' . $day. $alt = $wday_labels[$dow] . ' ' . $day.
' ('.$items[$day]['nb_images'].')'; ' ('.$items[$day]['nb_images'].')';
$template->assign_block_vars('calendar.thumbnails.row.col.full', $template->assign_block_vars('calendar.thumbnails.row.col.full',
@ -519,9 +530,16 @@ SELECT file,tn_ext,path, width, height, DAYOFWEEK('.$this->date_field.')-1 as do
$template->assign_block_vars('thumbnails.line', array()); $template->assign_block_vars('thumbnails.line', array());
foreach ( $items as $day=>$data) foreach ( $items as $day=>$data)
{ {
$url = $this->url_base. $url = duplicate_index_url(
$this->date_components[CYEAR].'-'. array(
$this->date_components[CMONTH].'-'.$day; 'chronology_date' =>
array(
$page['chronology_date'][CYEAR],
$page['chronology_date'][CMONTH],
$day
)
)
);
$thumbnail_title = $lang['day'][$data['dow']] . ' ' . $day; $thumbnail_title = $lang['day'][$data['dow']] . ' ' . $day;
$name = $thumbnail_title .' ('.$data['nb_images'].')'; $name = $thumbnail_title .' ('.$data['nb_images'].')';

View file

@ -38,13 +38,11 @@ class Calendar extends CalendarBase
/** /**
* Initialize the calendar * Initialize the calendar
* @param string date_field db column on which this calendar works
* @param string inner_sql used for queries (INNER JOIN or normal) * @param string inner_sql used for queries (INNER JOIN or normal)
* @param array date_components
*/ */
function initialize($date_field, $inner_sql, $date_components) function initialize($inner_sql)
{ {
parent::initialize($date_field, $inner_sql, $date_components); parent::initialize($inner_sql);
global $lang; global $lang;
$week_no_labels=array(); $week_no_labels=array();
for ($i=1; $i<=53; $i++) for ($i=1; $i<=53; $i++)
@ -79,23 +77,19 @@ class Calendar extends CalendarBase
* Generate navigation bars for category page * Generate navigation bars for category page
* @return boolean false to indicate that thumbnails where not included here * @return boolean false to indicate that thumbnails where not included here
*/ */
function generate_category_content($url_base, $view_type) function generate_category_content()
{ {
global $conf; global $conf, $page;
$this->url_base = $url_base; if ( count($page['chronology_date'])==0 )
assert($view_type==CAL_VIEW_LIST);
if ( count($this->date_components)==0 )
{ {
$this->build_nav_bar(CYEAR); // years $this->build_nav_bar(CYEAR); // years
} }
if ( count($this->date_components)==1 ) if ( count($page['chronology_date'])==1 )
{ {
$this->build_nav_bar(CWEEK, array()); // week nav bar 1-53 $this->build_nav_bar(CWEEK, array()); // week nav bar 1-53
} }
if ( count($this->date_components)==2 ) if ( count($page['chronology_date'])==2 )
{ {
$this->build_nav_bar(CDAY); // days nav bar Mon-Sun $this->build_nav_bar(CDAY); // days nav bar Mon-Sun
} }
@ -112,7 +106,8 @@ function generate_category_content($url_base, $view_type)
*/ */
function get_date_where($max_levels=3) function get_date_where($max_levels=3)
{ {
$date = $this->date_components; global $page;
$date = $page['chronology_date'];
while (count($date)>$max_levels) while (count($date)>$max_levels)
{ {
array_pop($date); array_pop($date);

View file

@ -223,7 +223,7 @@ function get_picture_size( $original_width, $original_height,
$width = $original_width; $width = $original_width;
$height = $original_height; $height = $original_height;
$is_original_size = true; $is_original_size = true;
if ( $max_width != "" ) if ( $max_width != "" )
{ {
if ( $original_width > $max_width ) if ( $original_width > $max_width )
@ -249,13 +249,13 @@ function get_picture_size( $original_width, $original_height,
if ( ( $ratioWidth > 1 ) or ( $ratioHeight > 1 ) ) if ( ( $ratioWidth > 1 ) or ( $ratioHeight > 1 ) )
{ {
if ( $ratioWidth < $ratioHeight ) if ( $ratioWidth < $ratioHeight )
{ {
$width = floor( $original_width / $ratioHeight ); $width = floor( $original_width / $ratioHeight );
$height = $max_height; $height = $max_height;
} }
else else
{ {
$width = $max_width; $width = $max_width;
$height = floor( $original_height / $ratioWidth ); $height = floor( $original_height / $ratioWidth );
} }
$is_original_size = false; $is_original_size = false;
@ -330,7 +330,7 @@ function add_style( $string, $search, $style )
'<span style="'.$style.'">\\0</span>', '<span style="'.$style.'">\\0</span>',
$remaining ); $remaining );
$return_string.= $treatment; $return_string.= $treatment;
return $return_string; return $return_string;
} }
@ -340,7 +340,7 @@ function replace_search( $string, $search )
{ {
// FIXME : with new advanced search, this function needs a rewrite // FIXME : with new advanced search, this function needs a rewrite
return $string; return $string;
$words = explode( ',', $search ); $words = explode( ',', $search );
$style = 'background-color:white;color:red;'; $style = 'background-color:white;color:red;';
foreach ( $words as $word ) { foreach ( $words as $word ) {
@ -359,7 +359,7 @@ function pwg_log( $file, $category, $picture = '' )
{ {
$login = ($user['id'] == $conf['guest_id']) $login = ($user['id'] == $conf['guest_id'])
? 'guest' : addslashes($user['username']); ? 'guest' : addslashes($user['username']);
$query = ' $query = '
INSERT INTO '.HISTORY_TABLE.' INSERT INTO '.HISTORY_TABLE.'
(date,login,IP,file,category,picture) (date,login,IP,file,category,picture)
@ -387,7 +387,7 @@ function format_date($date, $type = 'us', $show_time = false)
global $lang; global $lang;
list($year,$month,$day,$hour,$minute,$second) = array(0,0,0,0,0,0); list($year,$month,$day,$hour,$minute,$second) = array(0,0,0,0,0,0);
switch ( $type ) switch ( $type )
{ {
case 'us' : case 'us' :
@ -432,10 +432,10 @@ function format_date($date, $type = 'us', $show_time = false)
function pwg_query($query) function pwg_query($query)
{ {
global $conf,$page,$debug,$t2; global $conf,$page,$debug,$t2;
$start = get_moment(); $start = get_moment();
$result = mysql_query($query) or my_error($query."\n"); $result = mysql_query($query) or my_error($query."\n");
$time = get_moment() - $start; $time = get_moment() - $start;
if (!isset($page['count_queries'])) if (!isset($page['count_queries']))
@ -443,10 +443,10 @@ function pwg_query($query)
$page['count_queries'] = 0; $page['count_queries'] = 0;
$page['queries_time'] = 0; $page['queries_time'] = 0;
} }
$page['count_queries']++; $page['count_queries']++;
$page['queries_time']+= $time; $page['queries_time']+= $time;
if ($conf['show_queries']) if ($conf['show_queries'])
{ {
$output = ''; $output = '';
@ -459,10 +459,10 @@ function pwg_query($query)
$output.= "\n".'(total time : '; $output.= "\n".'(total time : ';
$output.= number_format( ($time+$start-$t2), 3, '.', ' ').' s)'; $output.= number_format( ($time+$start-$t2), 3, '.', ' ').' s)';
$output.= "</pre>\n"; $output.= "</pre>\n";
$debug .= $output; $debug .= $output;
} }
return $result; return $result;
} }
@ -500,10 +500,10 @@ function redirect( $url )
$title = 'redirection'; $title = 'redirection';
include( PHPWG_ROOT_PATH.'include/page_header.php' ); include( PHPWG_ROOT_PATH.'include/page_header.php' );
$template->set_filenames( array( 'redirect' => 'redirect.tpl' ) ); $template->set_filenames( array( 'redirect' => 'redirect.tpl' ) );
$template->parse('redirect'); $template->parse('redirect');
include( PHPWG_ROOT_PATH.'include/page_tail.php' ); include( PHPWG_ROOT_PATH.'include/page_tail.php' );
exit(); exit();
@ -518,10 +518,10 @@ function redirect( $url )
function get_query_string_diff($rejects = array()) function get_query_string_diff($rejects = array())
{ {
$query_string = ''; $query_string = '';
$str = $_SERVER['QUERY_STRING']; $str = $_SERVER['QUERY_STRING'];
parse_str($str, $vars); parse_str($str, $vars);
$is_first = true; $is_first = true;
foreach ($vars as $key => $value) foreach ($vars as $key => $value)
{ {
@ -553,7 +553,7 @@ function get_pwg_themes()
$themes = array(); $themes = array();
$template_dir = PHPWG_ROOT_PATH.'template'; $template_dir = PHPWG_ROOT_PATH.'template';
foreach (get_dirs($template_dir) as $template) foreach (get_dirs($template_dir) as $template)
{ {
foreach (get_dirs($template_dir.'/'.$template.'/theme') as $theme) foreach (get_dirs($template_dir.'/'.$template.'/theme') as $theme)
@ -595,7 +595,7 @@ function get_thumbnail_src($path, $tn_ext = '')
$src = get_themeconf('mime_icon_dir'); $src = get_themeconf('mime_icon_dir');
$src.= strtolower(get_extension($path)).'.png'; $src.= strtolower(get_extension($path)).'.png';
} }
return $src; return $src;
} }
@ -622,7 +622,7 @@ function my_error($header)
function array_from_query($query, $fieldname) function array_from_query($query, $fieldname)
{ {
$array = array(); $array = array();
$result = pwg_query($query); $result = pwg_query($query);
while ($row = mysql_fetch_array($result)) while ($row = mysql_fetch_array($result))
{ {
@ -641,10 +641,10 @@ function array_from_query($query, $fieldname)
function get_day_list($blockname, $selection) function get_day_list($blockname, $selection)
{ {
global $template; global $template;
$template->assign_block_vars( $template->assign_block_vars(
$blockname, array('SELECTED' => '', 'VALUE' => 0, 'OPTION' => '--')); $blockname, array('SELECTED' => '', 'VALUE' => 0, 'OPTION' => '--'));
for ($i = 1; $i <= 31; $i++) for ($i = 1; $i <= 31; $i++)
{ {
$selected = ''; $selected = '';
@ -668,7 +668,7 @@ function get_day_list($blockname, $selection)
function get_month_list($blockname, $selection) function get_month_list($blockname, $selection)
{ {
global $template, $lang; global $template, $lang;
$template->assign_block_vars( $template->assign_block_vars(
$blockname, array('SELECTED' => '', $blockname, array('SELECTED' => '',
'VALUE' => 0, 'VALUE' => 0,
@ -697,9 +697,9 @@ function get_month_list($blockname, $selection)
function fill_caddie($elements_id) function fill_caddie($elements_id)
{ {
global $user; global $user;
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
$query = ' $query = '
SELECT element_id SELECT element_id
FROM '.CADDIE_TABLE.' FROM '.CADDIE_TABLE.'
@ -749,7 +749,7 @@ function l10n($key)
{ {
echo '[l10n] language key "'.$key.'" is not defined<br />'; echo '[l10n] language key "'.$key.'" is not defined<br />';
} }
return isset($lang[$key]) ? $lang[$key] : $key; return isset($lang[$key]) ? $lang[$key] : $key;
} }
@ -797,14 +797,14 @@ function get_search_array($search_id)
{ {
die('Search id must be an integer'); die('Search id must be an integer');
} }
$query = ' $query = '
SELECT rules SELECT rules
FROM '.SEARCH_TABLE.' FROM '.SEARCH_TABLE.'
WHERE id = '.$search_id.' WHERE id = '.$search_id.'
;'; ;';
list($serialized_rules) = mysql_fetch_row(pwg_query($query)); list($serialized_rules) = mysql_fetch_row(pwg_query($query));
return unserialize($serialized_rules); return unserialize($serialized_rules);
} }
@ -820,11 +820,11 @@ SELECT rules
function get_sql_search_clause($search_id) function get_sql_search_clause($search_id)
{ {
$search = get_search_array($search_id); $search = get_search_array($search_id);
// SQL where clauses are stored in $clauses array during query // SQL where clauses are stored in $clauses array during query
// construction // construction
$clauses = array(); $clauses = array();
foreach (array('file','name','comment','keywords','author') as $textfield) foreach (array('file','name','comment','keywords','author') as $textfield)
{ {
if (isset($search['fields'][$textfield])) if (isset($search['fields'][$textfield]))
@ -847,7 +847,7 @@ function get_sql_search_clause($search_id)
); );
} }
} }
if (isset($search['fields']['allwords'])) if (isset($search['fields']['allwords']))
{ {
$fields = array('file', 'name', 'comment', 'keywords', 'author'); $fields = array('file', 'name', 'comment', 'keywords', 'author');
@ -875,12 +875,12 @@ function get_sql_search_clause($search_id)
) )
); );
} }
array_walk( array_walk(
$word_clauses, $word_clauses,
create_function('&$s','$s="(".$s.")";') create_function('&$s','$s="(".$s.")";')
); );
array_push( array_push(
$clauses, $clauses,
"\n ". "\n ".
@ -892,7 +892,7 @@ function get_sql_search_clause($search_id)
) )
); );
} }
foreach (array('date_available', 'date_creation') as $datefield) foreach (array('date_available', 'date_creation') as $datefield)
{ {
if (isset($search['fields'][$datefield])) if (isset($search['fields'][$datefield]))
@ -902,26 +902,26 @@ function get_sql_search_clause($search_id)
$datefield." = '".$search['fields'][$datefield]['date']."'" $datefield." = '".$search['fields'][$datefield]['date']."'"
); );
} }
foreach (array('after','before') as $suffix) foreach (array('after','before') as $suffix)
{ {
$key = $datefield.'-'.$suffix; $key = $datefield.'-'.$suffix;
if (isset($search['fields'][$key])) if (isset($search['fields'][$key]))
{ {
array_push( array_push(
$clauses, $clauses,
$datefield. $datefield.
($suffix == 'after' ? ' >' : ' <'). ($suffix == 'after' ? ' >' : ' <').
($search['fields'][$key]['inc'] ? '=' : ''). ($search['fields'][$key]['inc'] ? '=' : '').
" '".$search['fields'][$key]['date']."'" " '".$search['fields'][$key]['date']."'"
); );
} }
} }
} }
if (isset($search['fields']['cat'])) if (isset($search['fields']['cat']))
{ {
if ($search['fields']['cat']['sub_inc']) if ($search['fields']['cat']['sub_inc'])
@ -933,22 +933,22 @@ function get_sql_search_clause($search_id)
{ {
$cat_ids = $search['fields']['cat']['words']; $cat_ids = $search['fields']['cat']['words'];
} }
$local_clause = 'category_id IN ('.implode(',', $cat_ids).')'; $local_clause = 'category_id IN ('.implode(',', $cat_ids).')';
array_push($clauses, $local_clause); array_push($clauses, $local_clause);
} }
// adds brackets around where clauses // adds brackets around where clauses
$clauses = prepend_append_array_items($clauses, '(', ')'); $clauses = prepend_append_array_items($clauses, '(', ')');
$where_separator = $where_separator =
implode( implode(
"\n ".$search['mode'].' ', "\n ".$search['mode'].' ',
$clauses $clauses
); );
$search_clause = $where_separator; $search_clause = $where_separator;
if (isset($forbidden)) if (isset($forbidden))
{ {
$search_clause.= "\n AND ".$forbidden; $search_clause.= "\n AND ".$forbidden;
@ -986,7 +986,7 @@ function get_available_upgrade_ids()
$upgrades_path = PHPWG_ROOT_PATH.'install/db'; $upgrades_path = PHPWG_ROOT_PATH.'install/db';
$available_upgrade_ids = array(); $available_upgrade_ids = array();
if ($contents = opendir($upgrades_path)) if ($contents = opendir($upgrades_path))
{ {
while (($node = readdir($contents)) !== false) while (($node = readdir($contents)) !== false)
@ -1015,11 +1015,8 @@ function make_index_URL($params = array())
PHPWG_ROOT_PATH.'category.php?' PHPWG_ROOT_PATH.'category.php?'
.'/'.make_section_in_URL($params) .'/'.make_section_in_URL($params)
; ;
if (isset($params['start']) and $params['start'] > 0) $url = add_well_known_params_in_url($url, $params);
{
$url.= '/start-'.$params['start'];
}
return $url; return $url;
} }
@ -1106,19 +1103,40 @@ function make_picture_URL($params)
{ {
die('make_picture_URL: image_id is a required parameter'); die('make_picture_URL: image_id is a required parameter');
} }
$url = $url =
PHPWG_ROOT_PATH.'picture.php?' PHPWG_ROOT_PATH.'picture.php?'
.'/'.$params['image_id'] .'/'.$params['image_id']
.'/'.make_section_in_URL($params) .'/'.make_section_in_URL($params)
; ;
// first comment to start on $url = add_well_known_params_in_url($url, $params);
return $url;
}
/**
*adds to the url the chronology and start parameters
*/
function add_well_known_params_in_url($url, $params)
{
if ( isset($params['chronology']) )
{
$url .= '/'. $params['chronology']['field'];
$url .= '-'. $params['chronology']['style'];
if ( isset($params['chronology']['view']) )
{
$url .= '-'. $params['chronology']['view'];
}
if ( isset($params['chronology_date']) )
{
$url .= '-'. implode('-', $params['chronology_date'] );
}
}
if (isset($params['start']) and $params['start'] > 0) if (isset($params['start']) and $params['start'] > 0)
{ {
$url.= '/start-'.$params['start']; $url.= '/start-'.$params['start'];
} }
return $url; return $url;
} }
@ -1134,7 +1152,7 @@ function make_picture_URL($params)
function make_section_in_URL($params) function make_section_in_URL($params)
{ {
$section_string = ''; $section_string = '';
if (!isset($params['section'])) if (!isset($params['section']))
{ {
if (isset($params['category'])) if (isset($params['category']))
@ -1159,7 +1177,7 @@ function make_section_in_URL($params)
{ {
$params['section'] = 'categories'; $params['section'] = 'categories';
} }
switch($params['section']) switch($params['section'])
{ {
case 'categories' : case 'categories' :
@ -1172,7 +1190,7 @@ function make_section_in_URL($params)
{ {
$section_string.= 'category/'.$params['category']; $section_string.= 'category/'.$params['category'];
} }
break; break;
} }
case 'tags' : case 'tags' :
@ -1188,7 +1206,7 @@ function make_section_in_URL($params)
{ {
$section_string.= '/'.$tag; $section_string.= '/'.$tag;
} }
break; break;
} }
case 'search' : case 'search' :
@ -1197,7 +1215,7 @@ function make_section_in_URL($params)
{ {
die('make_section_in_URL: require a search identifier'); die('make_section_in_URL: require a search identifier');
} }
$section_string.= 'search/'.$params['search']; $section_string.= 'search/'.$params['search'];
break; break;
@ -1210,7 +1228,7 @@ function make_section_in_URL($params)
} }
$section_string.= 'list/'.implode(',', $params['list']); $section_string.= 'list/'.implode(',', $params['list']);
break; break;
} }
default : default :

View file

@ -24,27 +24,8 @@
// | USA. | // | USA. |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
define('CAL_VIEW_LIST', 'l'); define('CAL_VIEW_LIST', 'list');
define('CAL_VIEW_CALENDAR', 'c'); define('CAL_VIEW_CALENDAR', 'calendar');
function get_calendar_parameter($options, &$parameters )
{
if ( count($parameters) and isset($options[$parameters[0]]) )
{
return array_shift($parameters);
}
else
{
foreach ($options as $option => $data)
{
if ( empty( $data['default_link'] ) )
{
break;
}
}
return $option;
}
}
function initialize_calendar() function initialize_calendar()
{ {
@ -53,17 +34,17 @@ function initialize_calendar()
//------------------ initialize the condition on items to take into account --- //------------------ initialize the condition on items to take into account ---
$inner_sql = ' FROM ' . IMAGES_TABLE; $inner_sql = ' FROM ' . IMAGES_TABLE;
if (!isset($page['cat']) or is_numeric($page['cat'])) if (!isset($page['category']) or is_numeric($page['category']))
{ // we will regenerate the items by including subcats elements { // we will regenerate the items by including subcats elements
$page['cat_nb_images'] = 0; $page['cat_nb_images'] = 0;
$page['items'] = array(); $page['items'] = array();
$inner_sql .= ' $inner_sql .= '
INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
if (isset($page['cat']) and is_numeric($page['cat'])) if (isset($page['category']) and is_numeric($page['category']))
{ {
$sub_ids = array_diff( $sub_ids = array_diff(
get_subcat_ids(array($page['cat'])), get_subcat_ids(array($page['category'])),
explode(',', $user['forbidden_categories']) explode(',', $user['forbidden_categories'])
); );
@ -92,129 +73,123 @@ WHERE id IN (' . implode(',',$page['items']) .')';
//-------------------------------------- initialize the calendar parameters --- //-------------------------------------- initialize the calendar parameters ---
pwg_debug('start initialize_calendar'); pwg_debug('start initialize_calendar');
// the parameters look like (FIELD)?(STYLE)?(VIEW)?(DATE COMPONENTS)?
// FIELD = (created-|posted-)
// STYLE = (m-|w-)
// VIEW = (l-|c-)
// DATE COMPONENTS= YEAR(-MONTH/WEEK)?(-DAY)?
$fields = array( $fields = array(
// Created // Created
'created' => array( 'created' => array(
'default_link' => 'created-',
'label' => l10n('Creation date'), 'label' => l10n('Creation date'),
'db_field' => 'date_creation',
), ),
// Posted // Posted
'posted' => array( 'posted' => array(
'default_link' => 'posted-',
'label' => l10n('Post date'), 'label' => l10n('Post date'),
'db_field' => 'date_available',
), ),
); );
$styles = array( $styles = array(
// Monthly style // Monthly style
'monthly' => array( 'monthly' => array(
'default_link' => '',
'include' => 'calendar_monthly.class.php', 'include' => 'calendar_monthly.class.php',
'view_calendar' => true, 'view_calendar' => true,
), ),
// Weekly style // Weekly style
'weekly' => array( 'weekly' => array(
'default_link' => 'weekly-',
'include' => 'calendar_weekly.class.php', 'include' => 'calendar_weekly.class.php',
'view_calendar' => false, 'view_calendar' => false,
), ),
); );
$views = array( $views = array(CAL_VIEW_LIST,CAL_VIEW_CALENDAR);
// list view
CAL_VIEW_LIST => array(
'default_link' => '',
),
// calendar view
CAL_VIEW_CALENDAR => array(
'default_link' => CAL_VIEW_CALENDAR.'-',
),
);
$requested = explode('-', $_GET['calendar']);
// Retrieve calendar field // Retrieve calendar field
$cal_field = get_calendar_parameter($fields, $requested); if ( !isset( $fields[ $page['chronology']['field'] ] ) )
{
die('bad field');
}
// Retrieve style // Retrieve style
$cal_style = get_calendar_parameter($styles, $requested); if ( !isset( $styles[ $page['chronology']['style'] ] ) )
{
$page['chronology']['style'] = 'monthly';
}
$cal_style = $page['chronology']['style'];
include(PHPWG_ROOT_PATH.'include/'. $styles[$cal_style]['include']); include(PHPWG_ROOT_PATH.'include/'. $styles[$cal_style]['include']);
$calendar = new Calendar(); $calendar = new Calendar();
// Retrieve view // Retrieve view
$cal_view = get_calendar_parameter($views, $requested);
if ( CAL_VIEW_CALENDAR==$cal_view and !$styles[$cal_style]['view_calendar'] ) if ( !isset($page['chronology']['view']) or
!in_array( $page['chronology']['view'], $views ) )
{ {
$cal_view=CAL_VIEW_LIST; $page['chronology']['view'] = CAL_VIEW_LIST;
} }
// perform a sanity check on $requested if ( CAL_VIEW_CALENDAR==$page['chronology']['view'] and
while (count($requested) > 3) !$styles[$cal_style]['view_calendar'] )
{ {
array_pop($requested);
$page['chronology']['view'] = CAL_VIEW_LIST;
}
$cal_view = $page['chronology']['view'];
// perform a sanity check on $requested
if (!isset($page['chronology_date']))
{
$page['chronology_date'] = array();
}
while ( count($page['chronology_date']) > 3)
{
array_pop($page['chronology_date']);
} }
$any_count = 0; $any_count = 0;
for ($i = 0; $i < count($requested); $i++) for ($i = 0; $i < count($page['chronology_date']); $i++)
{ {
if ($requested[$i] == 'any') if ($page['chronology_date'][$i] == 'any')
{ {
if ($cal_view == CAL_VIEW_CALENDAR) if ($cal_view == CAL_VIEW_CALENDAR)
{// we dont allow any in calendar view {// we dont allow any in calendar view
while ($i < count($requested)) while ($i < count($page['chronology_date']))
{ {
array_pop($requested); array_pop($page['chronology_date']);
} }
break; break;
} }
$any_count++; $any_count++;
} }
elseif ($requested[$i] == '') elseif ($page['chronology_date'][$i] == '')
{ {
while ($i < count($requested)) while ($i < count($page['chronology_date']))
{ {
array_pop($requested); array_pop($page['chronology_date']);
} }
} }
else else
{ {
$requested[$i] = (int)$requested[$i]; $page['chronology_date'][$i] = (int)$page['chronology_date'][$i];
} }
} }
if ($any_count == 3) if ($any_count == 3)
{ {
array_pop($requested); array_pop($page['chronology_date']);
} }
$calendar->initialize($fields[$cal_field]['db_field'], $inner_sql, $requested); $calendar->initialize($inner_sql);
//echo ('<pre>'. var_export($calendar, true) . '</pre>'); //echo ('<pre>'. var_export($calendar, true) . '</pre>');
$url_base = get_query_string_diff(array('start', 'calendar')); /* $url_base = get_query_string_diff(array('start', 'calendar'));
$url_base = $url_base =
PHPWG_ROOT_PATH.'category.php' PHPWG_ROOT_PATH.'category.php'
.$url_base .$url_base
.(empty($url_base) ? '?' : '&') .(empty($url_base) ? '?' : '&')
.'calendar='.$cal_field.'-' .'calendar='.$cal_field.'-'
; ;*/
$must_show_list = true; // true until calendar generates its own display $must_show_list = true; // true until calendar generates its own display
if (basename($_SERVER["PHP_SELF"]) == 'category.php') if (basename($_SERVER["PHP_SELF"]) == 'category.php')
{ {
$template->assign_block_vars('calendar', array()); $template->assign_block_vars('calendar', array());
if ($calendar->generate_category_content( if ($calendar->generate_category_content())
$url_base.$cal_style.'-'.$cal_view.'-',
$cal_view
)
)
{ {
unset( unset(
$page['thumbnails_include'], $page['thumbnails_include'],
@ -228,27 +203,39 @@ WHERE id IN (' . implode(',',$page['items']) .')';
$template->assign_block_vars( 'calendar.views', array() ); $template->assign_block_vars( 'calendar.views', array() );
foreach ($styles as $style => $style_data) foreach ($styles as $style => $style_data)
{ {
foreach ($views as $view => $view_data) foreach ($views as $view)
{ {
if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR) if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR)
{ {
$selected = ''; $selected = '';
$url = $url_base.$style.'-'.$view; $chronology = $page['chronology'];
if ($style==$cal_style) $chronology['style'] = $style;
$chronology['view'] = $view;
if ($style!=$cal_style)
{ {
$url .= '-'.implode('-', $calendar->date_components); $chronology_date = array();
if ( $view==$cal_view ) if ( isset($page['chronology_date'][0]) )
{ {
$selected = 'SELECTED'; array_push($chronology_date, $page['chronology_date'][0]);
} }
} }
else else
{ {
if (isset($calendar->date_components[0])) $chronology_date = $page['chronology_date'];
{
$url .= '-' . $calendar->date_components[0];
}
} }
$url = duplicate_index_url(
array(
'chronology' => $chronology,
'chronology_date' => $chronology_date,
)
);
if ($style==$cal_style and $view==$cal_view )
{
$selected = 'SELECTED';
}
$template->assign_block_vars( $template->assign_block_vars(
'calendar.views.view', 'calendar.views.view',
array( array(
@ -260,9 +247,11 @@ WHERE id IN (' . implode(',',$page['items']) .')';
} }
} }
} }
$calendar_title = $url = duplicate_index_url(
'<a href="'.$url_base.$cal_style.'-'.$cal_view.'">' array('chronology_date'=>array()), array('start')
.$fields[$cal_field]['label'].'</a>'; );
$calendar_title = '<a href="'.$url.'">'
.$fields[$chronology['field']]['label'].'</a>';
$calendar_title.= $calendar->get_display_name(); $calendar_title.= $calendar->get_display_name();
//this should be an assign_block_vars, but I need to assign 'calendar' //this should be an assign_block_vars, but I need to assign 'calendar'
//above and at that point I don't have the title yet. //above and at that point I don't have the title yet.

View file

@ -78,17 +78,17 @@ foreach (array_keys($_GET) as $keynum => $key)
die('Fatal: picture identifier is missing'); die('Fatal: picture identifier is missing');
} }
$page['image_id'] = $matches[1]; $page['image_id'] = $matches[1];
$next_token++; $next_token++;
} }
if (0 === strpos($tokens[$next_token], 'cat')) if (0 === strpos($tokens[$next_token], 'cat'))
{ {
$page['section'] = 'categories'; $page['section'] = 'categories';
$next_token++; $next_token++;
if (isset($tokens[$next_token]) if (isset($tokens[$next_token])
and preg_match('/(\d+)/', $tokens[$next_token], $matches)) and preg_match('/^(\d+)/', $tokens[$next_token], $matches))
{ {
$page['category'] = $matches[1]; $page['category'] = $matches[1];
$next_token++; $next_token++;
@ -98,16 +98,16 @@ foreach (array_keys($_GET) as $keynum => $key)
{ {
$page['section'] = 'tags'; $page['section'] = 'tags';
$page['tags'] = array(); $page['tags'] = array();
$next_token++; $next_token++;
for ($i = $next_token; ; $i++) for ($i = $next_token; ; $i++)
{ {
if (!isset($tokens[$i])) if (!isset($tokens[$i]))
{ {
break; break;
} }
preg_match('/^(\d+)/', $tokens[$i], $matches); preg_match('/^(\d+)/', $tokens[$i], $matches);
if (!isset($matches[1])) if (!isset($matches[1]))
{ {
@ -122,7 +122,7 @@ foreach (array_keys($_GET) as $keynum => $key)
} }
array_push($page['tags'], $matches[1]); array_push($page['tags'], $matches[1]);
} }
$next_token = $i; $next_token = $i;
} }
else if (0 === strpos($tokens[$next_token], 'fav')) else if (0 === strpos($tokens[$next_token], 'fav'))
@ -154,7 +154,7 @@ foreach (array_keys($_GET) as $keynum => $key)
{ {
$page['section'] = 'search'; $page['section'] = 'search';
$next_token++; $next_token++;
preg_match('/(\d+)/', $tokens[$next_token], $matches); preg_match('/(\d+)/', $tokens[$next_token], $matches);
if (!isset($matches[1])) if (!isset($matches[1]))
{ {
@ -184,24 +184,36 @@ foreach (array_keys($_GET) as $keynum => $key)
$page['section'] = 'categories'; $page['section'] = 'categories';
$next_token++; $next_token++;
} }
for ($i = $next_token; ; $i++) for ($i = $next_token; ; $i++)
{ {
if (!isset($tokens[$i])) if (!isset($tokens[$i]))
{ {
break; break;
} }
if (preg_match('/^start-(\d+)/', $tokens[$i], $matches)) if (preg_match('/^start-(\d+)/', $tokens[$i], $matches))
{ {
$page['start'] = $matches[1]; $page['start'] = $matches[1];
} }
if (preg_match('/^calendar-(.+)$/', $tokens[$i], $matches)) if (preg_match('/^posted|created/', $tokens[$i] ))
{ {
// TODO: decide with rvelices how we name calendar/chronology is the $chronology_tokens = explode('-', $tokens[$i] );
// URL $page['chronology']['field'] = $chronology_tokens[0];
$_GET['calendar'] = $matches[1]; array_shift($chronology_tokens);
$page['chronology']['style'] = $chronology_tokens[0];
array_shift($chronology_tokens);
if ( count($chronology_tokens)>0 )
{
if ('list'==$chronology_tokens[0] or
'calendar'==$chronology_tokens[0])
{
$page['chronology']['view'] = $chronology_tokens[0];
array_shift($chronology_tokens);
}
$page['chronology_date'] = $chronology_tokens;
}
} }
} }
} }
@ -219,7 +231,7 @@ if (isset($_COOKIE['pwg_image_order'])
$conf['order_by'] = str_replace( $conf['order_by'] = str_replace(
'ORDER BY ', 'ORDER BY ',
'ORDER BY '.$orders[ $_COOKIE['pwg_image_order'] ][1].',', 'ORDER BY '.$orders[ $_COOKIE['pwg_image_order'] ][1].',',
$conf['order_by'] $conf['order_by']
); );
$page['super_order_by'] = true; $page['super_order_by'] = true;
@ -233,7 +245,7 @@ if ('categories' == $page['section'])
if (isset($page['category'])) if (isset($page['category']))
{ {
$result = get_cat_info($page['category']); $result = get_cat_info($page['category']);
$page = array_merge( $page = array_merge(
$page, $page,
array( array(
@ -246,11 +258,11 @@ if ('categories' == $page['section'])
'cat_commentable' => $result['commentable'], 'cat_commentable' => $result['commentable'],
'cat_id_uppercat' => $result['id_uppercat'], 'cat_id_uppercat' => $result['id_uppercat'],
'uppercats' => $result['uppercats'], 'uppercats' => $result['uppercats'],
'title' => get_cat_display_name($result['name'], '', false), 'title' => get_cat_display_name($result['name'], '', false),
) )
); );
if (!isset($_GET['calendar'])) if (!isset($_GET['calendar']))
{ {
$query = ' $query = '
@ -261,7 +273,7 @@ SELECT image_id
'.$conf['order_by'].' '.$conf['order_by'].'
;'; ;';
$page['items'] = array_from_query($query, 'image_id'); $page['items'] = array_from_query($query, 'image_id');
$page['thumbnails_include'] = $page['thumbnails_include'] =
$result['nb_images'] > 0 $result['nb_images'] > 0
? 'include/category_default.inc.php' ? 'include/category_default.inc.php'
@ -387,7 +399,7 @@ SELECT DISTINCT(id)
'.$conf['order_by'].' '.$conf['order_by'].'
LIMIT 0, '.$conf['top_number'].' LIMIT 0, '.$conf['top_number'].'
;'; ;';
$page = array_merge( $page = array_merge(
$page, $page,
array( array(
@ -404,7 +416,7 @@ SELECT DISTINCT(id)
{ {
$page['super_order_by'] = true; $page['super_order_by'] = true;
$conf['order_by'] = ' ORDER BY average_rate DESC, id ASC'; $conf['order_by'] = ' ORDER BY average_rate DESC, id ASC';
$query =' $query ='
SELECT DISTINCT(id) SELECT DISTINCT(id)
FROM '.IMAGES_TABLE.' FROM '.IMAGES_TABLE.'
@ -436,7 +448,7 @@ SELECT DISTINCT(id)
AND '.$forbidden.' AND '.$forbidden.'
'.$conf['order_by'].' '.$conf['order_by'].'
;'; ;';
$page = array_merge( $page = array_merge(
$page, $page,
array( array(
@ -446,7 +458,7 @@ SELECT DISTINCT(id)
) )
); );
} }
if (!isset($page['cat_nb_images'])) if (!isset($page['cat_nb_images']))
{ {
$page['cat_nb_images'] = count($page['items']); $page['cat_nb_images'] = count($page['items']);
@ -457,7 +469,7 @@ SELECT DISTINCT(id)
// | chronology | // | chronology |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
if (isset($_GET['calendar'])) if (isset($page['chronology']))
{ {
include_once( PHPWG_ROOT_PATH.'include/functions_calendar.inc.php' ); include_once( PHPWG_ROOT_PATH.'include/functions_calendar.inc.php' );
initialize_calendar(); initialize_calendar();

View file

@ -63,46 +63,16 @@ $page['current_item'] = $page['image_id'];
if ($page['current_rank'] != $page['first_rank']) if ($page['current_rank'] != $page['first_rank'])
{ {
// "go to first picture of this section" link is displayed only if the // caching first & previous item : readability purpose
// displayed item is not the first.
$template->assign_block_vars(
'first',
array(
'U_IMG' => duplicate_picture_URL(
// redefinitions
array(
'image_id' => $page['items'][ $page['first_rank'] ],
),
// removes
array()
)
)
);
// caching previous item : readability purpose
$page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ]; $page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ];
$page['first_item'] = $page['items'][ $page['first_rank'] ];
} }
if ($page['current_rank'] != $page['last_rank']) if ($page['current_rank'] != $page['last_rank'])
{ {
// "go to last picture of this section" link is displayed only if the // caching next & last item : readability purpose
// displayed item is not the last.
$template->assign_block_vars(
'last',
array(
'U_IMG' => duplicate_picture_URL(
// redefinitions
array(
'image_id' => $page['items'][ $page['last_rank'] ],
),
// removes
array()
)
)
);
// caching next item : readability purpose
$page['next_item'] = $page['items'][ $page['current_rank'] + 1 ]; $page['next_item'] = $page['items'][ $page['current_rank'] + 1 ];
$page['last_item'] = $page['items'][ $page['last_rank'] ];
} }
$url_up = duplicate_index_URL( $url_up = duplicate_index_URL(
@ -144,7 +114,7 @@ INSERT INTO '.FAVORITES_TABLE.'
pwg_query($query); pwg_query($query);
redirect($url_self); redirect($url_self);
break; break;
} }
case 'remove_from_favorites' : case 'remove_from_favorites' :
@ -164,7 +134,7 @@ DELETE FROM '.FAVORITES_TABLE.'
{ {
redirect($url_self); redirect($url_self);
} }
break; break;
} }
case 'set_as_representative' : case 'set_as_representative' :
@ -178,9 +148,9 @@ UPDATE '.CATEGORIES_TABLE.'
;'; ;';
pwg_query($query); pwg_query($query);
} }
redirect($url_self); redirect($url_self);
break; break;
} }
case 'toggle_metadata' : case 'toggle_metadata' :
@ -243,17 +213,19 @@ while ($row = mysql_fetch_array($result))
array_push($related_categories, $row); array_push($related_categories, $row);
} }
usort($related_categories, 'global_rank_compare'); usort($related_categories, 'global_rank_compare');
//------------------------------------- prev, current & next picture management //-------------------------first, prev, current, next & last picture management
$picture = array(); $picture = array();
$ids = array($page['image_id']); $ids = array($page['image_id']);
if (isset($page['previous_item'])) if (isset($page['previous_item']))
{ {
array_push($ids, $page['previous_item']); array_push($ids, $page['previous_item']);
array_push($ids, $page['first_item']);
} }
if (isset($page['next_item'])) if (isset($page['next_item']))
{ {
array_push($ids, $page['next_item']); array_push($ids, $page['next_item']);
array_push($ids, $page['last_item']);
} }
$query = ' $query = '
@ -268,12 +240,20 @@ while ($row = mysql_fetch_array($result))
{ {
if (isset($page['previous_item']) and $row['id'] == $page['previous_item']) if (isset($page['previous_item']) and $row['id'] == $page['previous_item'])
{ {
$i = 'prev'; $i = 'previous';
} }
else if (isset($page['next_item']) and $row['id'] == $page['next_item']) else if (isset($page['next_item']) and $row['id'] == $page['next_item'])
{ {
$i = 'next'; $i = 'next';
} }
else if (isset($page['first_item']) and $row['id'] == $page['first_item'])
{
$i = 'first';
}
else if (isset($page['last_item']) and $row['id'] == $page['last_item'])
{
$i = 'last';
}
else else
{ {
$i = 'current'; $i = 'current';
@ -350,6 +330,15 @@ while ($row = mysql_fetch_array($result))
'start', 'start',
) )
); );
if ('previous'==$i and $page['previous_item']==$page['first_item'])
{
$picture['first'] = $picture[$i];
}
if ('next'==$i and $page['next_item']==$page['last_item'])
{
$picture['last'] = $picture[$i];
}
} }
$url_admin = $url_admin =
@ -427,30 +416,20 @@ $url_metadata = duplicate_picture_URL();
$page['body_id'] = 'thePicturePage'; $page['body_id'] = 'thePicturePage';
//------------------------------------------------------- navigation management //------------------------------------------------------- navigation management
if (isset($page['previous_item'])) foreach ( array('first','previous','next','last') as $which_image )
{ {
$template->assign_block_vars( if (isset($picture[$which_image]))
'previous', {
array( $template->assign_block_vars(
'TITLE_IMG' => $picture['prev']['name'], $which_image,
'IMG' => $picture['prev']['thumbnail'], array(
'U_IMG' => $picture['prev']['url'], 'TITLE_IMG' => $picture[$which_image]['name'],
'U_IMG_SRC' => $picture['prev']['src'] 'IMG' => $picture[$which_image]['thumbnail'],
) 'U_IMG' => $picture[$which_image]['url'],
); 'U_IMG_SRC' => $picture[$which_image]['src']
} )
);
if (isset($page['next_item'])) }
{
$template->assign_block_vars(
'next',
array(
'TITLE_IMG' => $picture['next']['name'],
'IMG' => $picture['next']['thumbnail'],
'U_IMG' => $picture['next']['url'],
'U_IMG_SRC' => $picture['next']['src'] // allow navigator to preload
)
);
} }
include(PHPWG_ROOT_PATH.'include/page_header.php'); include(PHPWG_ROOT_PATH.'include/page_header.php');
@ -519,7 +498,7 @@ if (!$picture['current']['is_picture'])
if (isset($picture['current']['high'])) if (isset($picture['current']['high']))
{ {
$uuid = uniqid(rand()); $uuid = uniqid(rand());
$template->assign_block_vars( $template->assign_block_vars(
'high', 'high',
array( array(
@ -527,7 +506,7 @@ if (isset($picture['current']['high']))
'UUID' => $uuid, 'UUID' => $uuid,
) )
); );
$template->assign_block_vars( $template->assign_block_vars(
'download', 'download',
array( array(
@ -571,7 +550,7 @@ SELECT COUNT(*) AS nb_fav
;'; ;';
$result = pwg_query($query); $result = pwg_query($query);
$row = mysql_fetch_array($result); $row = mysql_fetch_array($result);
if ($row['nb_fav'] == 0) if ($row['nb_fav'] == 0)
{ {
$url = $url_self.'&amp;action=add_to_favorites'; $url = $url_self.'&amp;action=add_to_favorites';
@ -641,9 +620,18 @@ else
if (!empty($picture['current']['date_creation'])) if (!empty($picture['current']['date_creation']))
{ {
$val = format_date($picture['current']['date_creation']); $val = format_date($picture['current']['date_creation']);
$infos['INFO_CREATION_DATE'] = '<a href="'. $url = make_index_URL(
PHPWG_ROOT_PATH.'category.php?calendar=created-c-'. array(
$picture['current']['date_creation'].'">'.$val.'</a>'; 'chronology' =>
array(
'field'=>'created',
'style'=>'monthly',
'view'=>'list',
),
'chronology_date' => explode('-', $picture['current']['date_creation'])
)
);
$infos['INFO_CREATION_DATE'] = '<a href="'.$url.'">'.$val.'</a>';
} }
else else
{ {
@ -652,9 +640,18 @@ else
// date of availability // date of availability
$val = format_date($picture['current']['date_available'], 'mysql_datetime'); $val = format_date($picture['current']['date_available'], 'mysql_datetime');
$infos['INFO_POSTED_DATE'] = '<a href="'. $url = make_index_URL(
PHPWG_ROOT_PATH.'category.php?calendar=posted-c-'. array(
substr($picture['current']['date_available'],0,10).'">'.$val.'</a>'; 'chronology' =>
array(
'field'=>'posted',
'style'=>'monthly',
'view'=>'list',
),
'chronology_date' => explode('-', substr($picture['current']['date_available'],0,10))
)
);
$infos['INFO_POSTED_DATE'] = '<a href="'.$url.'">'.$val.'</a>';
// size in pixels // size in pixels
if ($picture['current']['is_picture']) if ($picture['current']['is_picture'])