From 9a7a232cef393a829e7e5088ceb5d145c2f942ed Mon Sep 17 00:00:00 2001 From: plegall Date: Thu, 23 Feb 2006 16:53:11 +0000 Subject: modification: DAY() MySQL function replaced by DAYOFMONTH() to improve backward compatibility (this function was added in MySQL 4.1) bug fixed: with chronology mode, PWG displays thumbnails on main page if even if no category (which will soon be called "section") is set. This was producing warnings on category.php from include/category_default.inc.php. refactoring: on include/calendar_base.class.php and include/functions_calendar.inc.php. Unix file format, coding guidelines, etc. While trying to understand the code, I've made some presentation modification to clarify variable names and so on. git-svn-id: http://piwigo.org/svn/trunk@1053 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/calendar_base.class.php | 342 ++++++++++++----------- include/calendar_monthly.class.php | 6 +- include/category_default.inc.php | 29 +- include/functions_calendar.inc.php | 551 ++++++++++++++++++++----------------- 4 files changed, 494 insertions(+), 434 deletions(-) (limited to 'include') diff --git a/include/calendar_base.class.php b/include/calendar_base.class.php index 1f120c811..26472bf1b 100644 --- a/include/calendar_base.class.php +++ b/include/calendar_base.class.php @@ -1,165 +1,179 @@ -date_field = $date_field; - $this->inner_sql = $inner_sql; -} - -//--------------------------------------------------------- private members --- -/** - * Creates a calendar navigation bar. - * @param string url_base - links start with this root - * @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 - * @param bool allow_any - adds any to the end of the bar - * @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, - $class_prefix, $allow_any, $labels=null) -{ - $nav_bar=''; - foreach ($items as $item => $nb_images) - { - $label = $item; - if (isset($labels[$item])) - { - $label = $labels[$item]; - } - if ( isset($selected_item) and $item==$selected_item ) - { - $nav_bar .= ''; - $nav_bar .= $label; - } - else - { - $nav_bar .= ''; - $url = $url_base . $item; - $nav_bar .= ''; - $nav_bar .= $label; - $nav_bar .= ''; - } - if ($nb_images>0) - { - $nav_bar .= '('.$nb_images.')'; - } - $nav_bar.= ''; - } - - if ($allow_any and count($items)>1 ) - { - $label = l10n('calendar_any'); - if ( isset($selected_item) and 'any'==$selected_item ) - { - $nav_bar .= ''; - $nav_bar .= $label; - } - else - { - $nav_bar .= ''; - $url = $url_base . 'any'; - $nav_bar .= ''; - $nav_bar .= $label; - $nav_bar .= ''; - } - $nav_bar.= ''; - } - return $nav_bar; -} - - -/** - * Creates a calendar navigation bar for a given level. - * @param string view_type - list or calendar (e.g. 'l' or 'c') - * @param array requested - array of current selected elements (e.g. 2005,10) - * @param string sql_func - YEAR/MONTH/DAY/WEEK/DAYOFWEEK ... - * @param string sql_offset - (e.g. +1 for WEEK - first in year is 1) - * @param array labels - optional labels to show in the navigation bar - * @return void - */ -function build_nav_bar($view_type, $requested, $level, $sql_func, - $sql_offset='', $labels=null) -{ - global $template; - $query = 'SELECT DISTINCT('.$sql_func.'('.$this->date_field.')'.$sql_offset - .') as period'; - $query.= $this->inner_sql; - $query.= $this->get_date_where($requested, $level); - $query.= ' - GROUP BY period'; - - $level_items=array(); - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - $level_items[$row['period']] = 0; - } - - $url_base = $this->url_base; - $url_base .= $view_type.'-'; - for ($i=0; $i<$level; $i++) - { - if (isset($requested[$i])) - { - $url_base .= $requested[$i].'-'; - } - } - - $nav_bar = $this->get_nav_bar_from_items( $url_base, $level_items, - $requested[$level], 'cal', true, $labels); - - $template->assign_block_vars( 'calendar.navbar', - array( 'BAR' => $nav_bar) - ); -} -} - +date_field = $date_field; + $this->inner_sql = $inner_sql; + } + +//--------------------------------------------------------- private members --- + + /** + * Creates a calendar navigation bar. + * + * @param string url_base - links start with this root + * @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 + * @param bool allow_any - adds any to the end of the bar + * @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, + $class_prefix, $allow_any, $labels=null) + { + $nav_bar = ''; + + foreach ($items as $item => $nb_images) + { + $label = $item; + if (isset($labels[$item])) + { + $label = $labels[$item]; + } + if (isset($selected_item) and $item == $selected_item) + { + $nav_bar .= ''; + $nav_bar .= $label; + } + else + { + $nav_bar .= ''; + $url = $url_base . $item; + $nav_bar .= ''; + $nav_bar .= $label; + $nav_bar .= ''; + } + if ($nb_images > 0) + { + $nav_bar .= '('.$nb_images.')'; + } + $nav_bar.= ''; + } + + if ($allow_any and count($items) > 1) + { + $label = l10n('calendar_any'); + if (isset($selected_item) and 'any' == $selected_item) + { + $nav_bar .= ''; + $nav_bar .= $label; + } + else + { + $nav_bar .= ''; + $url = $url_base . 'any'; + $nav_bar .= ''; + $nav_bar .= $label; + $nav_bar .= ''; + } + $nav_bar.= ''; + } + return $nav_bar; + } + + /** + * Creates a calendar navigation bar for a given level. + * + * @param string view_type - list or calendar (e.g. 'l' or 'c') + * @param array requested - array of current selected elements (e.g. 2005,10) + * @param string sql_func - YEAR/MONTH/DAY/WEEK/DAYOFWEEK ... + * @param string sql_offset - (e.g. +1 for WEEK - first in year is 1) + * @param array labels - optional labels to show in the navigation bar + * @return void + */ + function build_nav_bar($view_type, $requested, $level, $sql_func, + $sql_offset='', $labels=null) + { + global $template; + + $query = ' +SELECT DISTINCT('.$sql_func.'('.$this->date_field.')'.$sql_offset + .') as period'; + $query.= $this->inner_sql; + $query.= $this->get_date_where($requested, $level); + $query.= ' + GROUP BY period +;'; + + $level_items = array(); + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + $level_items[$row['period']] = 0; + } + + $url_base = $this->url_base; + $url_base .= $view_type.'-'; + for ($i=0; $i<$level; $i++) + { + if (isset($requested[$i])) + { + $url_base .= $requested[$i].'-'; + } + } + + $nav_bar = $this->get_nav_bar_from_items( + $url_base, + $level_items, + $requested[$level], + 'cal', + true, + $labels + ); + + $template->assign_block_vars( + 'calendar.navbar', + array( + 'BAR' => $nav_bar + ) + ); + } +} ?> \ No newline at end of file diff --git a/include/calendar_monthly.class.php b/include/calendar_monthly.class.php index 3103880c3..128afff87 100644 --- a/include/calendar_monthly.class.php +++ b/include/calendar_monthly.class.php @@ -73,7 +73,7 @@ function generate_category_content($url_base, $view_type, &$requested) if (count($requested)>0) $this->build_nav_bar2($view_type, $requested, 1, 'MONTH', $lang['month']); // month if (count($requested)>1) - $this->build_nav_bar2($view_type, $requested, 2, 'DAY' ); // days + $this->build_nav_bar2($view_type, $requested, 2, 'DAYOFWEEK' ); // days } return false; } @@ -123,7 +123,7 @@ function get_date_where($requested, $max_levels=3) } if (isset($requested[2]) and $requested[2]!='any') { - $res .= ' AND DAY('.$this->date_field.')='.$requested[2]; + $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$requested[2]; } } $res = " AND $this->date_field BETWEEN '$b' AND '$e 23:59:59'" . $res; @@ -137,7 +137,7 @@ function get_date_where($requested, $max_levels=3) } if (isset($requested[2]) and $requested[2]!='any') { - $res .= ' AND DAY('.$this->date_field.')='.$requested[2]; + $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$requested[2]; } } return $res; diff --git a/include/category_default.inc.php b/include/category_default.inc.php index 558e3d389..5c31e4a18 100644 --- a/include/category_default.inc.php +++ b/include/category_default.inc.php @@ -79,22 +79,25 @@ foreach ($pictures as $row) { $thumbnail_title .= ' : '.$row['filesize'].' KB'; } + // url link on picture.php page - $url_link = PHPWG_ROOT_PATH.'picture.php?'; - if ( isset($page['cat']) ) - { - $url_link .= 'cat='.$page['cat'].'&'; - } - $url_link.= 'image_id='.$row['id']; - if ($page['cat'] == 'search') - { - $url_link.= '&search='.$_GET['search']; - } - else if ($page['cat'] == 'list') + $url_link = PHPWG_ROOT_PATH.'picture.php?image_id='.$row['id']; + + if (isset($page['cat'])) { - $url_link.= '&list='.$_GET['list']; + $url_link.= 'cat='.$page['cat'].'&'; + + if ($page['cat'] == 'search') + { + $url_link.= '&search='.$_GET['search']; + } + else if ($page['cat'] == 'list') + { + $url_link.= '&list='.$_GET['list']; + } } - if ( isset($_GET['calendar']) ) + + if (isset($_GET['calendar'])) { $url_link.= '&calendar='.$_GET['calendar']; } diff --git a/include/functions_calendar.inc.php b/include/functions_calendar.inc.php index e39bbe2a0..acc8b15b0 100644 --- a/include/functions_calendar.inc.php +++ b/include/functions_calendar.inc.php @@ -1,255 +1,298 @@ -'m', 'default_link'=>'', 'name'=>l10n('Monthly'), - 'include'=>'calendar_monthly.class.php', 'view_calendar'=>true ), - array('link'=>'w', 'default_link'=>'w-', 'name'=>l10n('Weekly'), - 'include'=>'calendar_weekly.class.php', ), - ); - - $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) ) - { - foreach( $cal_styles as $cal_style) - { - if (''==$cal_style['default_link']) - break; - } - include( PHPWG_ROOT_PATH.'include/'.$cal_style['include']); - $calendar = new Calendar(); - } - - $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) - { - array_pop($requested); - } - - $any_count = 0; - for ($i=0; $iinitialize($conf['calendar_datefield'], $inner_sql); - //echo ('
'. var_export($requested, true) . '
'); - //echo ('
'. var_export($calendar, true) . '
'); - - $category_calling = false; - if (basename($_SERVER["PHP_SELF"]) == 'category.php') - { - $category_calling = true; - } - - $must_show_list = true; - if ($category_calling) - { - $template->assign_block_vars('calendar', array()); - - $url_base = get_query_string_diff(array('start','calendar')); - $url_base .= empty($url_base) ? '?' : '&'; - $url_base .= 'calendar='; - $url_base = PHPWG_ROOT_PATH.'category.php'.$url_base; - - if ( $calendar->generate_category_content( - $url_base.$cal_style['default_link'], $view_type, $requested) ) - { - unset( $page['thumbnails_include'] ); - unset( $page['items'] ); - unset( $page['cat_nb_images'] ); - $must_show_list = false; - } - - if ($cal_style['view_calendar']) - { // Build bar for view modes (List/Calendar) - $views = array( - array(CAL_VIEW_LIST, l10n('List') ), - array(CAL_VIEW_CALENDAR, l10n('calendar') ), - ); - $views_bar = ''; - foreach( $views as $view ) - { - $v = $view[1]; - if ( $view_type!=$view[0] ) - { - $url = $url_base.$cal_style['default_link'].$view[0].'-'; - $url .= implode('-', $requested); - $v = ''.$v.' '; - } - else - { - $v = $v.' '; - } - $views_bar .= $v . ' '; - } - $template->assign_block_vars('calendar.views', array( - 'BAR'=>$views_bar - )); - } - - // Build bar for calendar styles (Monthly, Weekly) - $styles_bar = ''; - foreach ( $cal_styles as $style) - { - if ($cal_style['link']!=$style['link']) - { - $url = $url_base.$style['default_link']; - $url .= $view_type; - if (isset($requested[0])) - { - $url .= '-' . $requested[0]; - } - $styles_bar .= ''.$style['name'].' '; - } - else - { - $styles_bar .= $style['name'].' '; - } - } - $template->assign_block_vars( 'calendar.styles', - array( 'BAR' => $styles_bar) - ); - } // end category calling - - if ($must_show_list) - { - $query = 'SELECT DISTINCT(id)'; - $query .= $calendar->inner_sql; - $query .= $calendar->get_date_where($requested); - if ( isset($page['super_order_by']) ) - { - $query .= ' - '.$conf['order_by']; - } - else - { - $order_by = str_replace( - 'ORDER BY ', - 'ORDER BY '.$calendar->date_field.',', $conf['order_by'] - ); - $query .= $order_by; - } - - $page['items'] = array_from_query($query, 'id'); - $page['cat_nb_images'] = count($page['items']); - $page['thumbnails_include'] = 'include/category_default.inc.php'; - } - pwg_debug('end initialize_calendar'); -} - + 'm', + 'default_link' => '', + 'name' => l10n('Monthly'), + 'include' => 'calendar_monthly.class.php', + 'view_calendar' => true, + ), + // Monthly style + array( + 'link' => 'w', + 'default_link' => 'w-', + 'name' => l10n('Weekly'), + 'include' => 'calendar_weekly.class.php', + ), + ); + + $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)) + { + foreach($cal_styles as $cal_style) + { + if ('' == $cal_style['default_link']) + { + break; + } + } + include( PHPWG_ROOT_PATH.'include/'.$cal_style['include']); + $calendar = new Calendar(); + } + + $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) + { + array_pop($requested); + } + + $any_count = 0; + for ($i = 0; $i < count($requested); $i++) + { + if ($requested[$i] == 'any') + { + if ($view_type == CAL_VIEW_CALENDAR) + {// we dont allow any in calendar view + while ($i < count($requested)) + { + array_pop($requested); + } + break; + } + $any_count++; + } + elseif ($requested[$i] == '') + { + while ($i < count($requested)) + { + array_pop($requested); + } + } + } + if ($any_count == 3) + { + 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; + + 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 + ) + ) + { + unset( + $page['thumbnails_include'], + $page['items'], + $page['cat_nb_images'] + ); + + $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) + { + if ($cal_style['link'] != $style['link']) + { + $url = $url_base.$style['default_link']; + $url .= $view_type; + if (isset($requested[0])) + { + $url .= '-' . $requested[0]; + } + $styles_bar .= ''.$style['name'].' '; + } + else + { + $styles_bar .= $style['name'].' '; + } + } + $template->assign_block_vars( + 'calendar.styles', + array( + 'BAR' => $styles_bar, + ) + ); + } // end category calling + + if ($must_show_list) + { + $query = 'SELECT DISTINCT(id)'; + $query .= $calendar->inner_sql; + $query .= $calendar->get_date_where($requested); + if ( isset($page['super_order_by']) ) + { + $query .= ' + '.$conf['order_by']; + } + else + { + $order_by = str_replace( + 'ORDER BY ', + 'ORDER BY '.$calendar->date_field.',', $conf['order_by'] + ); + $query .= $order_by; + } + + $page['items'] = array_from_query($query, 'id'); + $page['cat_nb_images'] = count($page['items']); + $page['thumbnails_include'] = 'include/category_default.inc.php'; + } + pwg_debug('end initialize_calendar'); +} + ?> \ No newline at end of file -- cgit v1.2.3