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'));
$calendar_view_link = duplicate_index_URL(
array(), // nothing to redefine
array('chronology_type', 'start') // what to remove ?
);
if (!isset($page['chronology_type']))
if (!isset($page['chronology']))
{
$calendar_view_link.= '/calendar-';
$chronology =
array(
'chronology' =>
array(
'field' => 'created',
'style' => 'monthly',
'view' => 'list',
)
);
$template->assign_block_vars(
'mode_created',
array(
'URL' => $calendar_view_link.'created'
'URL' => duplicate_index_URL( $chronology, array('start') )
)
);
$chronology['chronology']['field'] = 'posted';
$template->assign_block_vars(
'mode_posted',
array(
'URL' => $calendar_view_link.'posted'
'URL' => duplicate_index_URL( $chronology, array('start') )
)
);
}
@ -159,29 +162,29 @@ else
$template->assign_block_vars(
'mode_normal',
array(
'URL' => $calendar_view_link
'URL' => duplicate_index_URL( array(), array('chronology','start') )
)
);
$calendar_view_link .= '/calendar-';
if ($page['chronology_type'] == 'created')
$chronology = $page['chronology'];
if ($chronology['field'] == 'created')
{
$template->assign_block_vars(
'mode_posted',
array(
'URL' => $calendar_view_link.'posted'
)
);
$chronology['field'] = 'posted';
}
else
{
$template->assign_block_vars(
'mode_created',
array(
'URL' => $calendar_view_link.'created'
)
);
$chronology['field'] = '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(
@ -293,10 +296,16 @@ $template->assign_block_vars(
'special_cat',
array(
'URL' =>
make_index_URL()
.'/calendar-'
.($conf['calendar_datefield'] == 'date_available' ? 'posted' : 'created')
.'-monthly-c',
make_index_URL(
array(
'chronology'=>
array(
'field' => ($conf['calendar_datefield']=='date_available' ? 'posted' : 'created'),
'style' => 'monthly',
'view' => 'calendar'
)
)
),
'TITLE' => $lang['calendar_hint'],
'NAME' => $lang['calendar']
)

View file

@ -33,10 +33,6 @@ class CalendarBase
var $date_field;
// used for queries (INNER JOIN or normal)
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;
@ -44,44 +40,48 @@ class CalendarBase
/**
* 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 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->date_components = $date_components;
$this->has_nav_bar = false;
}
function get_display_name()
{
global $conf;
global $conf, $page;
$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'];
if ($i>0)
{
$url .= '-';
}
$url .= $this->date_components[$i];
if ( isset($this->date_components[$i+1]) )
if ( isset($page['chronology_date'][$i+1]) )
{
$chronology_date = array_slice($page['chronology_date'],0, $i+1);
$url = duplicate_index_url(
array( 'chronology_date'=>$chronology_date ),
array( 'start' )
);
$res .=
'<a href="'.$url.'">'
.$this->get_date_component_label($i, $this->date_components[$i])
.$this->get_date_component_label($i, $page['chronology_date'][$i])
.'</a>';
}
else
{
$res .=
'<span class="calInHere">'
.$this->get_date_component_label($i, $this->date_components[$i])
.$this->get_date_component_label($i, $page['chronology_date'][$i])
.'</span>';
}
}
@ -131,7 +131,7 @@ class CalendarBase
/**
* 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 selected_item - item currently selected (e.g. 2005)
* @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,...)
* @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,
$show_empty=false, $labels=null)
{
global $conf;
global $conf, $page;
$nav_bar = '';
@ -180,7 +180,10 @@ class CalendarBase
else
{
$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 .= $label;
$nav_bar .= '</a>';
@ -203,7 +206,10 @@ class CalendarBase
else
{
$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 .= $label;
$nav_bar .= '</a>';
@ -221,7 +227,7 @@ class CalendarBase
*/
function build_nav_bar($level, $labels=null)
{
global $template, $conf;
global $template, $conf, $page;
$query = '
SELECT DISTINCT('.$this->calendar_levels[$level]['sql']
@ -240,14 +246,14 @@ SELECT DISTINCT('.$this->calendar_levels[$level]['sql']
}
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);
$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 )
{
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(
$url_base,
$page['chronology_date'],
$level_items,
null,
'calItem',
@ -288,14 +286,14 @@ SELECT DISTINCT('.$this->calendar_levels[$level]['sql']
*/
function build_next_prev()
{
global $template;
global $template, $page;
$prev = $next =null;
if ( empty($this->date_components) )
if ( empty($page['chronology_date']) )
return;
$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"';
}
@ -304,7 +302,7 @@ SELECT DISTINCT('.$this->calendar_levels[$level]['sql']
$query .= ','.$this->calendar_levels[$i]['sql'];
}
}
$current = implode('-', $this->date_components );
$current = implode('-', $page['chronology_date'] );
$query.=') as period' . $this->inner_sql .'
AND ' . $this->date_field . ' IS NOT NULL
@ -327,26 +325,32 @@ GROUP BY period';
{
$template->assign_block_vars( 'calendar.navbar', array() );
}
if ( $current_rank>0 )
{ // has previous
$prev = $upper_items[$current_rank-1];
$chronology_date = explode('-', $prev);
$template->assign_block_vars(
'calendar.navbar.prev',
array(
'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 )
{
// has next
{ // has next
$next = $upper_items[$current_rank+1];
$chronology_date = explode('-', $next);
$template->assign_block_vars(
'calendar.navbar.next',
array(
'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

@ -38,13 +38,11 @@ class Calendar extends CalendarBase
/**
* 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 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;
$this->calendar_levels = array(
array(
@ -67,21 +65,20 @@ class Calendar extends CalendarBase
* @return boolean false to indicate that thumbnails
* where not included here, true otherwise
*/
function generate_category_content($url_base, $view_type)
function generate_category_content()
{
global $conf;
$this->url_base = $url_base;
global $conf, $page;
$view_type = $page['chronology']['view'];
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
if ($this->build_global_calendar())
return true;
}
if ( count($this->date_components)==1 )
if ( count($page['chronology_date'])==1 )
{//case B: year given - display all days in given year
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
$this->build_month_calendar();
//$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;
if ( count($this->date_components)==0 )
if ( count($page['chronology_date'])==0 )
{
$this->build_nav_bar(CYEAR); // years
}
if ( count($this->date_components)==1)
if ( count($page['chronology_date'])==1)
{
$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(
$this->date_components[CYEAR] ,$this->date_components[CMONTH] ) );
$page['chronology_date'][CYEAR] ,$page['chronology_date'][CMONTH] ) );
array_unshift($day_labels, 0);
unset( $day_labels[0] );
$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)
{
$date = $this->date_components;
global $page;
$date = $page['chronology_date'];
while (count($date)>$max_levels)
{
array_pop($date);
@ -218,7 +216,8 @@ function get_all_days_in_month($year, $month)
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,
COUNT( DISTINCT(id) ) as count';
$query.= $this->inner_sql;
@ -244,21 +243,21 @@ function build_global_calendar()
if (count($items)==1)
{// only one year exists so bail out to year view
list($y) = array_keys($items);
$this->date_components[CYEAR] = $y;
$page['chronology_date'][CYEAR] = $y;
return false;
}
global $lang, $template;
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 .= '</span><br>';
$url_base .= '-';
$nav_bar .= $this->get_nav_bar_from_items( $url_base,
$nav_bar .= $this->get_nav_bar_from_items( $chronology_date,
$year_data['children'], null, 'calCal', false, false, $lang['month'] );
$template->assign_block_vars( 'calendar.calbar',
@ -270,7 +269,8 @@ function build_global_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,
COUNT( DISTINCT(id) ) as count';
$query.= $this->inner_sql;
@ -294,21 +294,21 @@ function build_year_calendar()
if (count($items)==1)
{ // only one month exists so bail out to month view
list($m) = array_keys($items);
$this->date_components[CMONTH] = $m;
$page['chronology_date'][CMONTH] = $m;
return false;
}
global $lang, $template;
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 .= ' ('.$month_data['nb_images'].')';
$nav_bar .= '</span><br>';
$url_base .= '-';
$nav_bar .= $this->get_nav_bar_from_items( $url_base,
$nav_bar .= $this->get_nav_bar_from_items( $chronology_date,
$month_data['children'], null, 'calCal', false );
$template->assign_block_vars( 'calendar.calbar',
@ -321,10 +321,11 @@ function build_year_calendar()
function build_month_calendar()
{
global $page;
$query='SELECT DISTINCT(DAYOFMONTH('.$this->date_field.')) as period,
COUNT( DISTINCT(id) ) as count';
$query.= $this->inner_sql;
$query.= $this->get_date_where($this->date_components);
$query.= $this->get_date_where();
$query.= '
GROUP BY period';
@ -337,7 +338,7 @@ function build_month_calendar()
foreach ( $items as $day=>$data)
{
$this->date_components[CDAY]=$day;
$page['chronology_date'][CDAY]=$day;
$query = '
SELECT file,tn_ext,path, width, height, DAYOFWEEK('.$this->date_field.')-1 as dow';
$query.= $this->inner_sql;
@ -345,7 +346,7 @@ SELECT file,tn_ext,path, width, height, DAYOFWEEK('.$this->date_field.')-1 as do
$query.= '
ORDER BY RAND()
LIMIT 0,1';
unset ( $this->date_components[CDAY] );
unset ( $page['chronology_date'][CDAY] );
$row = mysql_fetch_array(pwg_query($query));
$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.blank', array());
}
for ($day=1; $day<=$this->get_all_days_in_month(
$this->date_components[CYEAR] ,$this->date_components[CMONTH]); $day++)
for ( $day = 1;
$day <= $this->get_all_days_in_month(
$page['chronology_date'][CYEAR], $page['chronology_date'][CMONTH]
);
$day++)
{
$dow = ($first_day_dow + $day-1)%7;
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;';
}
$url = $this->url_base.
$this->date_components[CYEAR].'-'.
$this->date_components[CMONTH].'-'.$day;
$url = duplicate_index_url(
array(
'chronology_date' =>
array(
$page['chronology_date'][CYEAR],
$page['chronology_date'][CMONTH],
$day
)
)
);
$alt = $wday_labels[$dow] . ' ' . $day.
' ('.$items[$day]['nb_images'].')';
$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());
foreach ( $items as $day=>$data)
{
$url = $this->url_base.
$this->date_components[CYEAR].'-'.
$this->date_components[CMONTH].'-'.$day;
$url = duplicate_index_url(
array(
'chronology_date' =>
array(
$page['chronology_date'][CYEAR],
$page['chronology_date'][CMONTH],
$day
)
)
);
$thumbnail_title = $lang['day'][$data['dow']] . ' ' . $day;
$name = $thumbnail_title .' ('.$data['nb_images'].')';

View file

@ -38,13 +38,11 @@ class Calendar extends CalendarBase
/**
* 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 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;
$week_no_labels=array();
for ($i=1; $i<=53; $i++)
@ -79,23 +77,19 @@ class Calendar extends CalendarBase
* Generate navigation bars for category page
* @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;
assert($view_type==CAL_VIEW_LIST);
if ( count($this->date_components)==0 )
if ( count($page['chronology_date'])==0 )
{
$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
}
if ( count($this->date_components)==2 )
if ( count($page['chronology_date'])==2 )
{
$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)
{
$date = $this->date_components;
global $page;
$date = $page['chronology_date'];
while (count($date)>$max_levels)
{
array_pop($date);

View file

@ -1016,10 +1016,7 @@ function make_index_URL($params = array())
.'/'.make_section_in_URL($params)
;
if (isset($params['start']) and $params['start'] > 0)
{
$url.= '/start-'.$params['start'];
}
$url = add_well_known_params_in_url($url, $params);
return $url;
}
@ -1113,12 +1110,33 @@ function make_picture_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)
{
$url.= '/start-'.$params['start'];
}
return $url;
}

View file

@ -24,27 +24,8 @@
// | USA. |
// +-----------------------------------------------------------------------+
define('CAL_VIEW_LIST', 'l');
define('CAL_VIEW_CALENDAR', 'c');
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;
}
}
define('CAL_VIEW_LIST', 'list');
define('CAL_VIEW_CALENDAR', 'calendar');
function initialize_calendar()
{
@ -53,17 +34,17 @@ function initialize_calendar()
//------------------ initialize the condition on items to take into account ---
$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
$page['cat_nb_images'] = 0;
$page['items'] = array();
$inner_sql .= '
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(
get_subcat_ids(array($page['cat'])),
get_subcat_ids(array($page['category'])),
explode(',', $user['forbidden_categories'])
);
@ -92,129 +73,123 @@ WHERE id IN (' . implode(',',$page['items']) .')';
//-------------------------------------- initialize the calendar parameters ---
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(
// Created
'created' => array(
'default_link' => 'created-',
'label' => l10n('Creation date'),
'db_field' => 'date_creation',
),
// Posted
'posted' => array(
'default_link' => 'posted-',
'label' => l10n('Post date'),
'db_field' => 'date_available',
),
);
$styles = array(
// Monthly style
'monthly' => array(
'default_link' => '',
'include' => 'calendar_monthly.class.php',
'view_calendar' => true,
),
// Weekly style
'weekly' => array(
'default_link' => 'weekly-',
'include' => 'calendar_weekly.class.php',
'view_calendar' => false,
),
);
$views = array(
// list view
CAL_VIEW_LIST => array(
'default_link' => '',
),
// calendar view
CAL_VIEW_CALENDAR => array(
'default_link' => CAL_VIEW_CALENDAR.'-',
),
);
$requested = explode('-', $_GET['calendar']);
$views = array(CAL_VIEW_LIST,CAL_VIEW_CALENDAR);
// Retrieve calendar field
$cal_field = get_calendar_parameter($fields, $requested);
if ( !isset( $fields[ $page['chronology']['field'] ] ) )
{
die('bad field');
}
// 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']);
$calendar = new Calendar();
// 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
while (count($requested) > 3)
if ( CAL_VIEW_CALENDAR==$page['chronology']['view'] and
!$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;
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)
{// 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;
}
$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
{
$requested[$i] = (int)$requested[$i];
$page['chronology_date'][$i] = (int)$page['chronology_date'][$i];
}
}
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>');
$url_base = get_query_string_diff(array('start', 'calendar'));
/* $url_base = get_query_string_diff(array('start', 'calendar'));
$url_base =
PHPWG_ROOT_PATH.'category.php'
.$url_base
.(empty($url_base) ? '?' : '&')
.'calendar='.$cal_field.'-'
;
;*/
$must_show_list = true; // true until calendar generates its own display
if (basename($_SERVER["PHP_SELF"]) == 'category.php')
{
$template->assign_block_vars('calendar', array());
if ($calendar->generate_category_content(
$url_base.$cal_style.'-'.$cal_view.'-',
$cal_view
)
)
if ($calendar->generate_category_content())
{
unset(
$page['thumbnails_include'],
@ -228,27 +203,39 @@ WHERE id IN (' . implode(',',$page['items']) .')';
$template->assign_block_vars( 'calendar.views', array() );
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)
{
$selected = '';
$url = $url_base.$style.'-'.$view;
if ($style==$cal_style)
$chronology = $page['chronology'];
$chronology['style'] = $style;
$chronology['view'] = $view;
if ($style!=$cal_style)
{
$url .= '-'.implode('-', $calendar->date_components);
if ( $view==$cal_view )
$chronology_date = array();
if ( isset($page['chronology_date'][0]) )
{
$selected = 'SELECTED';
array_push($chronology_date, $page['chronology_date'][0]);
}
}
else
{
if (isset($calendar->date_components[0]))
$chronology_date = $page['chronology_date'];
}
$url = duplicate_index_url(
array(
'chronology' => $chronology,
'chronology_date' => $chronology_date,
)
);
if ($style==$cal_style and $view==$cal_view )
{
$url .= '-' . $calendar->date_components[0];
}
$selected = 'SELECTED';
}
$template->assign_block_vars(
'calendar.views.view',
array(
@ -260,9 +247,11 @@ WHERE id IN (' . implode(',',$page['items']) .')';
}
}
}
$calendar_title =
'<a href="'.$url_base.$cal_style.'-'.$cal_view.'">'
.$fields[$cal_field]['label'].'</a>';
$url = duplicate_index_url(
array('chronology_date'=>array()), array('start')
);
$calendar_title = '<a href="'.$url.'">'
.$fields[$chronology['field']]['label'].'</a>';
$calendar_title.= $calendar->get_display_name();
//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.

View file

@ -88,7 +88,7 @@ foreach (array_keys($_GET) as $keynum => $key)
$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];
$next_token++;
@ -197,11 +197,23 @@ foreach (array_keys($_GET) as $keynum => $key)
$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
// URL
$_GET['calendar'] = $matches[1];
$chronology_tokens = explode('-', $tokens[$i] );
$page['chronology']['field'] = $chronology_tokens[0];
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;
}
}
}
}
@ -457,7 +469,7 @@ SELECT DISTINCT(id)
// | chronology |
// +-----------------------------------------------------------------------+
if (isset($_GET['calendar']))
if (isset($page['chronology']))
{
include_once( PHPWG_ROOT_PATH.'include/functions_calendar.inc.php' );
initialize_calendar();

View file

@ -63,46 +63,16 @@ $page['current_item'] = $page['image_id'];
if ($page['current_rank'] != $page['first_rank'])
{
// "go to first picture of this section" link is displayed only if the
// 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
// caching first & previous item : readability purpose
$page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ];
$page['first_item'] = $page['items'][ $page['first_rank'] ];
}
if ($page['current_rank'] != $page['last_rank'])
{
// "go to last picture of this section" link is displayed only if the
// 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
// caching next & last item : readability purpose
$page['next_item'] = $page['items'][ $page['current_rank'] + 1 ];
$page['last_item'] = $page['items'][ $page['last_rank'] ];
}
$url_up = duplicate_index_URL(
@ -243,17 +213,19 @@ while ($row = mysql_fetch_array($result))
array_push($related_categories, $row);
}
usort($related_categories, 'global_rank_compare');
//------------------------------------- prev, current & next picture management
//-------------------------first, prev, current, next & last picture management
$picture = array();
$ids = array($page['image_id']);
if (isset($page['previous_item']))
{
array_push($ids, $page['previous_item']);
array_push($ids, $page['first_item']);
}
if (isset($page['next_item']))
{
array_push($ids, $page['next_item']);
array_push($ids, $page['last_item']);
}
$query = '
@ -268,12 +240,20 @@ while ($row = mysql_fetch_array($result))
{
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'])
{
$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
{
$i = 'current';
@ -350,6 +330,15 @@ while ($row = mysql_fetch_array($result))
'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 =
@ -427,30 +416,20 @@ $url_metadata = duplicate_picture_URL();
$page['body_id'] = 'thePicturePage';
//------------------------------------------------------- navigation management
if (isset($page['previous_item']))
foreach ( array('first','previous','next','last') as $which_image )
{
if (isset($picture[$which_image]))
{
$template->assign_block_vars(
'previous',
$which_image,
array(
'TITLE_IMG' => $picture['prev']['name'],
'IMG' => $picture['prev']['thumbnail'],
'U_IMG' => $picture['prev']['url'],
'U_IMG_SRC' => $picture['prev']['src']
'TITLE_IMG' => $picture[$which_image]['name'],
'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');
@ -641,9 +620,18 @@ else
if (!empty($picture['current']['date_creation']))
{
$val = format_date($picture['current']['date_creation']);
$infos['INFO_CREATION_DATE'] = '<a href="'.
PHPWG_ROOT_PATH.'category.php?calendar=created-c-'.
$picture['current']['date_creation'].'">'.$val.'</a>';
$url = make_index_URL(
array(
'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
{
@ -652,9 +640,18 @@ else
// date of availability
$val = format_date($picture['current']['date_available'], 'mysql_datetime');
$infos['INFO_POSTED_DATE'] = '<a href="'.
PHPWG_ROOT_PATH.'category.php?calendar=posted-c-'.
substr($picture['current']['date_available'],0,10).'">'.$val.'</a>';
$url = make_index_URL(
array(
'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
if ($picture['current']['is_picture'])