';
$nav_bar .= $lang['month'][$month].'';
@@ -255,12 +318,12 @@ function build_year_calendar(&$requested)
}
-function build_month_calendar($requested)
+function build_month_calendar()
{
$query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%d")) as period,
COUNT(id) as count';
$query.= $this->inner_sql;
- $query.= $this->get_date_where($requested, 2);
+ $query.= $this->get_date_where($this->date_components);
$query.= '
GROUP BY period';
@@ -277,15 +340,18 @@ function build_month_calendar($requested)
$template->assign_block_vars('thumbnails.line', array());
foreach ( $items as $day=>$nb_images)
{
- $url_base = $this->url_base.'c-'.$requested[0].'-'.$requested[1].'-'.$day;
- $requested[2]=$day;
+ $url_base = $this->url_base.
+ $this->date_components[CYEAR].'-'.
+ $this->date_components[CMONTH].'-'.$day;
+ $this->date_components[CDAY]=$day;
$query = '
SELECT file,tn_ext,path, DAYOFWEEK('.$this->date_field.')-1 as dw';
$query.= $this->inner_sql;
- $query.= $this->get_date_where($requested);
+ $query.= $this->get_date_where();
$query.= '
ORDER BY RAND()
LIMIT 0,1';
+ unset ( $this->date_components[CDAY] );
$row = mysql_fetch_array(pwg_query($query));
diff --git a/include/calendar_weekly.class.php b/include/calendar_weekly.class.php
index 3e591eecd..5ab550e29 100644
--- a/include/calendar_weekly.class.php
+++ b/include/calendar_weekly.class.php
@@ -26,6 +26,10 @@
include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php');
+define ('CYEAR', 0);
+define ('CWEEK', 1);
+define ('CDAY', 2);
+
/**
* Weekly calendar style (composed of years/week in years and days in week)
*/
@@ -36,52 +40,61 @@ 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, &$requested)
+function generate_category_content($url_base, $view_type)
{
- global $lang;
+ global $lang, $conf;
$this->url_base = $url_base;
assert($view_type==CAL_VIEW_LIST);
- $this->build_nav_bar($view_type, $requested, 0, 'YEAR'); // years
- if (count($requested)>0)
- $this->build_nav_bar($view_type, $requested, 1, 'WEEK', '+1' ); // month
- if (count($requested)>1)
- $this->build_nav_bar($view_type, $requested, 2, 'DAYOFWEEK', '-1',
+ if ( $conf['calendar_multi_bar'] or count($this->date_components)==0 )
+ {
+ $this->build_nav_bar(CYEAR, 'YEAR'); // years
+ }
+ if ( count($this->date_components)>=1 and
+ ( $conf['calendar_multi_bar'] or count($this->date_components)==1 )
+ )
+ {
+ $this->build_nav_bar(CWEEK, 'WEEK', '+1' ); // month
+ }
+ if ( count($this->date_components)>=2 )
+ {
+ $this->build_nav_bar(CDAY, 'DAYOFWEEK', '-1',
$lang['day'] ); // days
+ }
return false;
}
/**
* Returns a sql where subquery for the date field
- * @param array requested selected levels for this calendar
- * (e.g. 2005,42,1 for 41st week of 2005, Monday)
* @param int max_levels return the where up to this level
* (e.g. 2=only year and week in year)
* @return string
*/
-function get_date_where($requested, $max_levels=3)
+function get_date_where($max_levels=3)
{
- while (count($requested)>$max_levels)
+ $date_components = $this->date_components;
+ while (count($date_components)>$max_levels)
{
- array_pop($requested);
+ array_pop($date_components);
}
$res = '';
- if (isset($requested[0]) and $requested[0]!='any')
+ if (isset($date_components[CYEAR]) and $date_components[CYEAR]!='any')
{
- $y = $requested[0];
+ $y = $date_components[CYEAR];
$res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31 23:59:59'";
}
- if (isset($requested[1]) and $requested[1]!='any')
+ if (isset($date_components[CWEEK]) and $date_components[CWEEK]!='any')
{
- $res .= ' AND WEEK('.$this->date_field.')+1='.$requested[1];
+ $res .= ' AND WEEK('.$this->date_field.')+1='.$date_components[CWEEK];
}
- if (isset($requested[2]) and $requested[2]!='any')
+ if (isset($date_components[CDAY]) and $date_components[CDAY]!='any')
{
- $res .= ' AND DAYOFWEEK('.$this->date_field.')-1='.$requested[2];
+ $res .= ' AND DAYOFWEEK('.$this->date_field.')-1='
+ .$date_components[CDAY];
}
if (empty($res))
{
@@ -90,6 +103,44 @@ function get_date_where($requested, $max_levels=3)
return $res;
}
+function get_display_name()
+{
+ global $conf,$lang;
+ $res = '';
+ $url = $this->url_base;
+ if ( isset($this->date_components[CYEAR]) )
+ {
+ $res .= $conf['level_separator'];
+ $url .= $this->date_components[CYEAR].'-';
+ $res .=
+ ''
+ .$this->get_date_component_label($this->date_components[CYEAR])
+ .'';
+ }
+ if ( isset($this->date_components[CWEEK]) )
+ {
+ $res .= $conf['level_separator'];
+ $url .= $this->date_components[CWEEK].'-';
+ $res .=
+ ''
+ .$this->get_date_component_label($this->date_components[CWEEK])
+ .'';
+ }
+ if ( isset($this->date_components[CDAY]) )
+ {
+ $res .= $conf['level_separator'];
+ $url .= $this->date_components[CDAY].'-';
+ $res .=
+ ''
+ .$this->get_date_component_label(
+ $this->date_components[CDAY],
+ $lang['day']
+ )
+ .'';
+ }
+ return $res;
+}
+
}
?>
\ No newline at end of file
diff --git a/include/config_default.inc.php b/include/config_default.inc.php
index 78121af0f..a21351241 100644
--- a/include/config_default.inc.php
+++ b/include/config_default.inc.php
@@ -90,6 +90,14 @@ $conf['anti-flood_time'] = 60;
// catgory
$conf['calendar_datefield'] = 'date_creation';
+// calendar_multi_bar : the calendar shows a maximum number of
+// year/month/week/day navigation bars
+$conf['calendar_multi_bar'] = true;
+
+// calendar_show_any : the calendar shows an aditional 'any' button in the
+// year/month/week/day navigation bars
+$conf['calendar_show_any'] = true;
+
// newcat_default_commentable : at creation, must a category be commentable
// or not ?
$conf['newcat_default_commentable'] = 'true';
diff --git a/include/functions_calendar.inc.php b/include/functions_calendar.inc.php
index 43ca188ef..6f6a5f44b 100644
--- a/include/functions_calendar.inc.php
+++ b/include/functions_calendar.inc.php
@@ -27,6 +27,25 @@
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;
+ }
+}
+
function initialize_calendar()
{
global $page, $conf, $user, $template;
@@ -73,65 +92,76 @@ WHERE id IN (' . implode(',',$page['items']) .')';
//-------------------------------------- initialize the calendar parameters ---
pwg_debug('start initialize_calendar');
-
- $cal_styles = array(
+ // 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(
+ // TODO change next line when calendar_datefield disapears
+ 'default_link' => ( $conf['calendar_datefield']=='date_creation' ? '' : 'created-' ),
+ 'label' => l10n('Creation date'),
+ 'db_field' => 'date_creation',
+ ),
+ // Posted
+ 'posted' => array(
+ // TODO change next line when calendar_datefield disapears
+ 'default_link' => ( $conf['calendar_datefield']=='date_available' ? '' : 'posted-' ),
+ 'label' => l10n('Availability date'),
+ 'db_field' => 'date_available',
+ ),
+ );
+
+ $styles = array(
// Monthly style
- array(
- 'link' => 'm',
+ 'monthly' => array(
'default_link' => '',
- 'name' => l10n('Monthly'),
+ 'label' => l10n('Monthly'),
'include' => 'calendar_monthly.class.php',
'view_calendar' => true,
),
// Weekly style
- array(
- 'link' => 'w',
- 'default_link' => 'w-',
- 'name' => l10n('Weekly'),
+ 'weekly' => array(
+ 'default_link' => 'weekly-',
+ 'label' => l10n('Weekly'),
'include' => 'calendar_weekly.class.php',
'view_calendar' => false,
),
);
+ $views = array(
+ // list view
+ CAL_VIEW_LIST => array(
+ 'default_link' => '',
+ 'label' => l10n('List')
+ ),
+ // calendar view
+ CAL_VIEW_CALENDAR => array(
+ 'default_link' => CAL_VIEW_CALENDAR.'-',
+ 'label' => l10n('calendar')
+ ),
+ );
+
$requested = explode('-', $_GET['calendar']);
- $calendar = null;
- foreach ($cal_styles as $cal_style)
- {
- if ($requested[0] == $cal_style['link'])
- {
- include(PHPWG_ROOT_PATH.'include/'.$cal_style['include']);
- $calendar = new Calendar();
- array_shift($requested);
- break;
- }
- }
- if (!isset($calendar))
+ // Retrieve calendar field
+ $cal_field = get_calendar_parameter($fields, $requested);
+
+ // Retrieve style
+ $cal_style = get_calendar_parameter($styles, $requested);
+ 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'] )
{
- foreach($cal_styles as $cal_style)
- {
- if ('' == $cal_style['default_link'])
- {
- break;
- }
- }
- include( PHPWG_ROOT_PATH.'include/'.$cal_style['include']);
- $calendar = new Calendar();
+ $cal_view=CAL_VIEW_LIST;
}
- $view_type = CAL_VIEW_LIST;
- if ($requested[0] == CAL_VIEW_LIST)
- {
- array_shift($requested);
- }
- elseif ($requested[0] == CAL_VIEW_CALENDAR)
- {
- if ($cal_style['view_calendar'])
- {
- $view_type = CAL_VIEW_CALENDAR;
- }
- array_shift($requested);
- }
// perform a sanity check on $requested
while (count($requested) > 3)
{
@@ -143,7 +173,7 @@ WHERE id IN (' . implode(',',$page['items']) .')';
{
if ($requested[$i] == 'any')
{
- if ($view_type == CAL_VIEW_CALENDAR)
+ if ($cal_view == CAL_VIEW_CALENDAR)
{// we dont allow any in calendar view
while ($i < count($requested))
{
@@ -165,29 +195,26 @@ WHERE id IN (' . implode(',',$page['items']) .')';
{
array_pop($requested);
}
-
- $calendar->initialize($conf['calendar_datefield'], $inner_sql);
- //echo (''. var_export($requested, true) . '
');
- //echo (''. var_export($calendar, true) . '
');
-
- // TODO: what makes the list view required?
- $must_show_list = true;
+ $calendar->initialize($fields[$cal_field]['db_field'], $inner_sql, $requested);
+
+ //echo (''. var_export($fields, true) . '
');
+
+ $url_base =
+ PHPWG_ROOT_PATH.'category.php'
+ .get_query_string_diff(array('start', 'calendar'))
+ .(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());
- $url_base =
- PHPWG_ROOT_PATH.'category.php'
- .get_query_string_diff(array('start', 'calendar'))
- .(empty($url_base) ? '?' : '&')
- .'calendar='
- ;
-
if ($calendar->generate_category_content(
- $url_base.$cal_style['default_link'],
- $view_type,
- $requested
+ $url_base.$cal_style.'-'.$cal_view.'-',
+ $cal_view
)
)
{
@@ -199,82 +226,60 @@ WHERE id IN (' . implode(',',$page['items']) .')';
$must_show_list = false;
}
-
- if ($cal_style['view_calendar'])
- { // Build bar for views (List/Calendar)
- $views = array(
- // list view
- array(
- 'type' => CAL_VIEW_LIST,
- 'label' => l10n('List')
- ),
- // calendar view
- array(
- 'type' => CAL_VIEW_CALENDAR,
- 'label' => l10n('calendar')
- ),
- );
-
- $views_bar = '';
-
- foreach ($views as $view)
- {
- if ($view_type != $view['type'])
- {
- $views_bar.=
- ''.$view['label'].' ';
- }
- else
- {
- $views_bar.= $view['label'].' ';
- }
-
- $views_bar.= ' ';
- }
-
- $template->assign_block_vars(
- 'calendar.views',
- array(
- 'BAR' => $views_bar,
- )
- );
- }
-
- // Build bar for calendar styles (Monthly, Weekly)
- $styles_bar = '';
- foreach ($cal_styles as $style)
+
+ $template->assign_block_vars( 'calendar.views', array() );
+ foreach ($styles as $style => $style_data)
{
- if ($cal_style['link'] != $style['link'])
+ foreach ($views as $view => $view_data)
{
- $url = $url_base.$style['default_link'];
- $url .= $view_type;
- if (isset($requested[0]))
+ if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR)
{
- $url .= '-' . $requested[0];
+ $selected = '';
+ $url = $url_base.$style.'-'.$view;
+ if ($style==$cal_style)
+ {
+ $url .= '-'.implode('-', $calendar->date_components);
+ if ( $view==$cal_view )
+ {
+ $selected = 'SELECTED';
+ }
+ }
+ else
+ {
+ if (isset($calendar->date_components[0]))
+ {
+ $url .= '-' . $calendar->date_components[0];
+ }
+ }
+ $template->assign_block_vars(
+ 'calendar.views.view',
+ array(
+ 'VALUE' => $url,
+ 'CONTENT' => $style_data['label'].' ('.$view_data['label'].')',
+ 'SELECTED' => $selected,
+ )
+ );
}
- $styles_bar .= ''.$style['name'].' ';
- }
- else
- {
- $styles_bar .= $style['name'].' ';
}
}
- $template->assign_block_vars(
- 'calendar.styles',
- array(
- 'BAR' => $styles_bar,
- )
- );
} // end category calling
+ $calendar_title =
+ ''
+ .$fields[$cal_field]['label'].'';
+ $calendar_title.= $calendar->get_display_name();
+ $template->assign_block_vars(
+ 'calendar',
+ array(
+ 'TITLE' => $calendar_title,
+ )
+ );
+
if ($must_show_list)
{
$query = 'SELECT DISTINCT(id)';
$query .= $calendar->inner_sql;
- $query .= $calendar->get_date_where($requested);
+ $query .= $calendar->get_date_where();
if ( isset($page['super_order_by']) )
{
$query .= '
diff --git a/picture.php b/picture.php
index 000af4caf..2ae8e01b9 100644
--- a/picture.php
+++ b/picture.php
@@ -793,16 +793,9 @@ else
if (!empty($picture['current']['date_creation']))
{
$val = format_date($picture['current']['date_creation']);
- if ( $conf['calendar_datefield'] == 'date_creation' )
- {
- $infos['INFO_CREATION_DATE'] = ''.$val.'';
- }
- else
- {
- $infos['INFO_CREATION_DATE'] = $val;
- }
}
else
{
@@ -811,16 +804,9 @@ else
// date of availability
$val = format_date($picture['current']['date_available'], 'mysql_datetime');
-if ( $conf['calendar_datefield'] == 'date_available' )
-{
- $infos['INFO_AVAILABILITY_DATE'] = ''.$val.'';
-}
-else
-{
- $infos['INFO_AVAILABILITY_DATE'] = $val;
-}
+$infos['INFO_AVAILABILITY_DATE'] = ''.$val.'';
// size in pixels
if ($picture['current']['is_picture'])
diff --git a/template/yoga/category.tpl b/template/yoga/category.tpl
index 11acfa853..0942a0f2d 100644
--- a/template/yoga/category.tpl
+++ b/template/yoga/category.tpl
@@ -138,19 +138,23 @@
- {TITLE}
-
+ {TITLE}
+
+
{calendar.TITLE}
+
-
-Style: {calendar.styles.BAR}
-
-
-{calendar.views.BAR}
+
+
+
-
+
{calendar.navbar.BAR}
diff --git a/template/yoga/content.css b/template/yoga/content.css
index cc85cbc1e..fa45ab676 100644
--- a/template/yoga/content.css
+++ b/template/yoga/content.css
@@ -179,12 +179,8 @@ SPAN.filename:after {
}
-#content DIV.calendarStyles {
- float: left;
-}
-
#content DIV.calendarViews {
- float: right;
+ float: left;
}
SPAN.cal {