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

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

replacement of obsolete header title file

  • 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-07 18:00:55 +0000 (Sat, 07 Aug 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 481 $
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  list( $year,$month,$day ) = explode( '-', $date );
33  $unixtime = mktime( 0, 0, 0, $month, $day, $year );
34 
35  $diff = time() - $unixtime;
36  $day_in_seconds = 24*60*60;
37  $output = '';
38  $title = $lang['recent_image'].'&nbsp;';
39  if ( $diff < $user['recent_period'] * $day_in_seconds )
40  {
41    $icon_url = './template/'.$user['template'].'/theme/';
42    $icon_url.= 'recent.gif';
43    $title .= $user['recent_period'];
44    $title .=  '&nbsp;'.$lang['days'];
45    $size = getimagesize( $icon_url );
46    $output = '<img title="'.$title.'" src="'.$icon_url.'" style="border:0;';
47    $output.= 'height:'.$size[1].'px;width:'.$size[0].'px" alt="" />';
48  }
49  return $output;
50}
51
52function create_navigation_bar( $url, $nb_element, $start,
53                                $nb_element_page, $link_class )
54{
55  global $lang;
56  $navigation_bar = "";
57  // 0. détection de la page en cours
58  if( !isset( $start )
59      || !is_numeric( $start )
60      || ( is_numeric( $start ) && $start < 0 ) )
61  {
62    $start = 0;
63  }
64  // on n'affiche la bare de navigation que si on plus de 1 page
65  if ( $nb_element > $nb_element_page )
66  {
67    // 1.une page précédente ?
68    if ( $start != 0 )
69    {
70      $previous = $start - $nb_element_page;
71      $navigation_bar.= '<a href="';
72      $navigation_bar.= add_session_id( $url.'&amp;start='.$previous );
73      $navigation_bar.= '" class="'.$link_class.'">'.$lang['previous_page'];
74      $navigation_bar.= '</a>';
75      $navigation_bar.= ' | ';
76    }
77    // 2.liste des numéros de page
78    $maximum = ceil ( $nb_element / $nb_element_page );
79    for ( $i = 1; $i <= $maximum; $i++ )
80    {
81      $temp_start = ( $i - 1 ) * $nb_element_page;
82      if ( $temp_start == $start )
83      {
84        $navigation_bar.= ' <span style="font-weight:bold;">'.$i.'</span> ';
85      }
86      else
87      {
88        $navigation_bar.= ' <a href="';
89        $navigation_bar.= add_session_id( $url.'&amp;start='.$temp_start );
90        $navigation_bar.= '" class="'.$link_class.'">'.$i.'</a> ';
91      }
92    }
93    // 3.une page suivante ?
94    if ( $nb_element > $nb_element_page
95         && $start + $nb_element_page < $nb_element )
96    {
97      $next = $start + $nb_element_page;
98      $navigation_bar.= ' | <a href="';
99      $navigation_bar.= add_session_id( $url.'&amp;start='.$next );
100      $navigation_bar.= '" class="'.$link_class.'">'.$lang['next_page'].'</a>';
101    }
102  }
103  return $navigation_bar;
104}
105
106//
107// Pick a language, any language ...
108//
109function language_select($default, $select_name = "language")
110{
111
112  $dir = opendir(PHPWG_ROOT_PATH . 'language');
113  $available_lang= array();
114
115  while ( $file = readdir($dir) )
116  {
117    $path= realpath(PHPWG_ROOT_PATH . 'language/'.$file);
118    if (is_dir ($path) && !is_link($path) && file_exists($path . '/iso.txt'))
119    {
120          list($displayname) = @file($path . '/iso.txt');
121          $available_lang[$displayname] = $file;
122    }
123  }
124  closedir($dir);
125  @asort($available_lang);
126  @reset($available_lang);
127
128  $lang_select = '<select name="' . $select_name . '" onchange="this.form.submit()">';
129  foreach ($available_lang as $displayname => $code)
130  {
131    $selected = ( strtolower($default) == strtolower($code) ) ? ' selected="selected"' : '';
132    $lang_select .= '<option value="' . $code . '"' . $selected . '>' . ucwords($displayname) . '</option>';
133  }
134  $lang_select .= '</select>';
135
136  return $lang_select;
137}
138
139//
140// Pick a template/theme combo,
141//
142function style_select($default_style, $select_name = "style")
143{
144  $dir = opendir(PHPWG_ROOT_PATH . 'template');
145  $style_select = '<select name="' . $select_name . '">';
146  while ( $file = readdir($dir) )
147  {
148    if (is_dir ( realpath(PHPWG_ROOT_PATH.'template/'.$file) ) 
149          && !is_link(realpath(PHPWG_ROOT_PATH  . 'template/' . $file))
150          && !strstr($file,'.'))
151    {
152      $selected = ( $file == $default_style ) ? ' selected="selected"' : '';
153          $style_select .= '<option value="' . $file . '"' . $selected . '>' . $file . '</option>';
154    }
155  }
156  closedir($dir);
157  return $style_select;
158}
159
160// The function get_cat_display_name returns a string containing the list
161// of upper categories to the root category from the lowest category shown
162// example : "anniversaires - fete mere 2002 - animaux - erika"
163// You can give this parameters :
164//   - $style : the style of the span tag for the lowest category,
165//     "font-style:italic;" for example
166function get_cat_display_name( $cat_informations, $separator, 
167  $url = 'category.php?cat=', $replace_space = true)
168{
169  $output = '';
170  $i=0;
171  while ( list ($id, $name) = each($cat_informations)) 
172  {
173    if ( $i )  $output.= $separator;
174        $i++;
175        if (empty($style) && empty($url) || ($i == count( $cat_informations))) 
176          $output.= $name;
177    elseif (!empty($url))
178      $output.= '<a class="" href="'.add_session_id(PHPWG_ROOT_PATH.$url.$id).'">'.$name."</a>";
179        else
180      $output.= '<span style="'.$style.'">'.$name.'</span>';
181  }
182  if ( $replace_space ) return replace_space( $output );
183  else                  return $output;
184}
185
186/**
187 * returns the HTML code for a category item in the menu (for category.php)
188 *
189 * HTML code generated uses logical list tags ul and each category is an
190 * item li. The paramter given is the category informations as an array,
191 * used keys are : id, name, dir, nb_images, date_last, subcats (sub-array)
192 *
193 * @param array category
194 * @return string
195 */
196function get_html_menu_category($category)
197{
198  global $page, $lang;
199
200  $menu = '
201
202           <li>';
203 
204  $url = add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$category['id']);
205
206  $class = '';
207  if (isset($page['cat'])
208      and is_numeric($page['cat'])
209      and $category['id'] == $page['cat'])
210  {
211    $class = 'menuCategorySelected';
212  }
213  else
214  {
215    $class = 'menuCategoryNotSelected';
216  }
217 
218  $name = $category['name'];
219  if (empty($name))
220  {
221    $name = str_replace('_', ' ', $category['dir']);
222  }
223
224  $menu.= '
225           <a href="'.$url.'"
226              title="'.$lang['hint_category'].'"
227              class="'.$class.'">
228             '.$name.'
229           </a>';
230
231  if ($category['nb_images'] > 0)
232  {
233    $menu.= '
234             <span class="menuInfoCat"
235                   title="'.$category['nb_images'].'
236                          '.$lang['images_available'].'">
237             ['.$category['nb_images'].']
238             </span>
239             '.get_icon($category['date_last']);
240  }
241 
242  // recursive call
243  if ($category['expanded'] and count($category['subcats']) > 0)
244  {
245    $menu.= '
246             <ul class="menu">';
247    foreach ($category['subcats'] as $subcat)
248    {
249      $menu.= get_html_menu_category($subcat, &$menu);
250    }
251    $menu.= '
252             </ul>';
253  }
254
255  $menu.= '</li>';
256
257  return $menu;
258}
259?>
Note: See TracBrowser for help on using the repository browser.