source: trunk/include/functions_html.inc.php @ 492

Last change on this file since 492 was 492, checked in by z0rglub, 20 years ago

in get_icon function, if the date is not in the right format, returns empty
string

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                         functions_html.inc.php                        |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-08-21 13:50:54 +0000 (Sat, 21 Aug 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 492 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28function get_icon( $date )
29{
30  global $user, $conf, $lang;
31
32  if (!preg_match('/\d{4}-\d{2}-\d{2}/', $date))
33  {
34    return '';
35  }
36
37  list( $year,$month,$day ) = explode( '-', $date );
38  $unixtime = mktime( 0, 0, 0, $month, $day, $year );
39 
40  $diff = time() - $unixtime;
41  $day_in_seconds = 24*60*60;
42  $output = '';
43  $title = $lang['recent_image'].'&nbsp;';
44  if ( $diff < $user['recent_period'] * $day_in_seconds )
45  {
46    $icon_url = './template/'.$user['template'].'/theme/';
47    $icon_url.= 'recent.gif';
48    $title .= $user['recent_period'];
49    $title .=  '&nbsp;'.$lang['days'];
50    $size = getimagesize( $icon_url );
51    $output = '<img title="'.$title.'" src="'.$icon_url.'" style="border:0;';
52    $output.= 'height:'.$size[1].'px;width:'.$size[0].'px" alt="" />';
53  }
54  return $output;
55}
56
57function create_navigation_bar( $url, $nb_element, $start,
58                                $nb_element_page, $link_class )
59{
60  global $lang;
61  $navigation_bar = "";
62  // 0. détection de la page en cours
63  if( !isset( $start )
64      || !is_numeric( $start )
65      || ( is_numeric( $start ) && $start < 0 ) )
66  {
67    $start = 0;
68  }
69  // on n'affiche la bare de navigation que si on plus de 1 page
70  if ( $nb_element > $nb_element_page )
71  {
72    // 1.une page précédente ?
73    if ( $start != 0 )
74    {
75      $previous = $start - $nb_element_page;
76      $navigation_bar.= '<a href="';
77      $navigation_bar.= add_session_id( $url.'&amp;start='.$previous );
78      $navigation_bar.= '" class="'.$link_class.'">'.$lang['previous_page'];
79      $navigation_bar.= '</a>';
80      $navigation_bar.= ' | ';
81    }
82    // 2.liste des numéros de page
83    $maximum = ceil ( $nb_element / $nb_element_page );
84    for ( $i = 1; $i <= $maximum; $i++ )
85    {
86      $temp_start = ( $i - 1 ) * $nb_element_page;
87      if ( $temp_start == $start )
88      {
89        $navigation_bar.= ' <span style="font-weight:bold;">'.$i.'</span> ';
90      }
91      else
92      {
93        $navigation_bar.= ' <a href="';
94        $navigation_bar.= add_session_id( $url.'&amp;start='.$temp_start );
95        $navigation_bar.= '" class="'.$link_class.'">'.$i.'</a> ';
96      }
97    }
98    // 3.une page suivante ?
99    if ( $nb_element > $nb_element_page
100         && $start + $nb_element_page < $nb_element )
101    {
102      $next = $start + $nb_element_page;
103      $navigation_bar.= ' | <a href="';
104      $navigation_bar.= add_session_id( $url.'&amp;start='.$next );
105      $navigation_bar.= '" class="'.$link_class.'">'.$lang['next_page'].'</a>';
106    }
107  }
108  return $navigation_bar;
109}
110
111//
112// Pick a language, any language ...
113//
114function language_select($default, $select_name = "language")
115{
116
117  $dir = opendir(PHPWG_ROOT_PATH . 'language');
118  $available_lang= array();
119
120  while ( $file = readdir($dir) )
121  {
122    $path= realpath(PHPWG_ROOT_PATH . 'language/'.$file);
123    if (is_dir ($path) && !is_link($path) && file_exists($path . '/iso.txt'))
124    {
125          list($displayname) = @file($path . '/iso.txt');
126          $available_lang[$displayname] = $file;
127    }
128  }
129  closedir($dir);
130  @asort($available_lang);
131  @reset($available_lang);
132
133  $lang_select = '<select name="' . $select_name . '" onchange="this.form.submit()">';
134  foreach ($available_lang as $displayname => $code)
135  {
136    $selected = ( strtolower($default) == strtolower($code) ) ? ' selected="selected"' : '';
137    $lang_select .= '<option value="' . $code . '"' . $selected . '>' . ucwords($displayname) . '</option>';
138  }
139  $lang_select .= '</select>';
140
141  return $lang_select;
142}
143
144//
145// Pick a template/theme combo,
146//
147function style_select($default_style, $select_name = "style")
148{
149  $dir = opendir(PHPWG_ROOT_PATH . 'template');
150  $style_select = '<select name="' . $select_name . '">';
151  while ( $file = readdir($dir) )
152  {
153    if (is_dir ( realpath(PHPWG_ROOT_PATH.'template/'.$file) ) 
154          && !is_link(realpath(PHPWG_ROOT_PATH  . 'template/' . $file))
155          && !strstr($file,'.'))
156    {
157      $selected = ( $file == $default_style ) ? ' selected="selected"' : '';
158          $style_select .= '<option value="' . $file . '"' . $selected . '>' . $file . '</option>';
159    }
160  }
161  closedir($dir);
162  return $style_select;
163}
164
165// The function get_cat_display_name returns a string containing the list
166// of upper categories to the root category from the lowest category shown
167// example : "anniversaires - fete mere 2002 - animaux - erika"
168// You can give this parameters :
169//   - $style : the style of the span tag for the lowest category,
170//     "font-style:italic;" for example
171function get_cat_display_name( $cat_informations, $separator, 
172  $url = 'category.php?cat=', $replace_space = true)
173{
174  $output = '';
175  $i=0;
176  while ( list ($id, $name) = each($cat_informations)) 
177  {
178    if ( $i )  $output.= $separator;
179        $i++;
180        if (empty($style) && empty($url) || ($i == count( $cat_informations))) 
181          $output.= $name;
182    elseif (!empty($url))
183      $output.= '<a class="" href="'.add_session_id(PHPWG_ROOT_PATH.$url.$id).'">'.$name."</a>";
184        else
185      $output.= '<span style="'.$style.'">'.$name.'</span>';
186  }
187  if ( $replace_space ) return replace_space( $output );
188  else                  return $output;
189}
190
191/**
192 * returns the HTML code for a category item in the menu (for category.php)
193 *
194 * HTML code generated uses logical list tags ul and each category is an
195 * item li. The paramter given is the category informations as an array,
196 * used keys are : id, name, dir, nb_images, date_last, subcats (sub-array)
197 *
198 * @param array category
199 * @return string
200 */
201function get_html_menu_category($category)
202{
203  global $page, $lang;
204
205  $menu = '
206
207           <li>';
208 
209  $url = add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$category['id']);
210
211  $class = '';
212  if (isset($page['cat'])
213      and is_numeric($page['cat'])
214      and $category['id'] == $page['cat'])
215  {
216    $class = 'menuCategorySelected';
217  }
218  else
219  {
220    $class = 'menuCategoryNotSelected';
221  }
222 
223  $name = $category['name'];
224  if (empty($name))
225  {
226    $name = str_replace('_', ' ', $category['dir']);
227  }
228
229  $menu.= '
230           <a href="'.$url.'"
231              title="'.$lang['hint_category'].'"
232              class="'.$class.'">
233             '.$name.'
234           </a>';
235
236  if ($category['nb_images'] > 0)
237  {
238    $menu.= '
239             <span class="menuInfoCat"
240                   title="'.$category['nb_images'].'
241                          '.$lang['images_available'].'">
242             ['.$category['nb_images'].']
243             </span>
244             '.get_icon($category['date_last']);
245  }
246 
247  // recursive call
248  if ($category['expanded'] and count($category['subcats']) > 0)
249  {
250    $menu.= '
251             <ul class="menu">';
252    foreach ($category['subcats'] as $subcat)
253    {
254      $menu.= get_html_menu_category($subcat, &$menu);
255    }
256    $menu.= '
257             </ul>';
258  }
259
260  $menu.= '</li>';
261
262  return $menu;
263}
264?>
Note: See TracBrowser for help on using the repository browser.