[476] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[593] | 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
| 5 | // | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[476] | 6 | // +-----------------------------------------------------------------------+ |
---|
[593] | 7 | // | branch : BSF (Best So Far) |
---|
[476] | 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2004-11-20 17:23:42 +0000 (Sat, 20 Nov 2004) $ |
---|
| 10 | // | last modifier : $Author: plg $ |
---|
| 11 | // | revision : $Revision: 610 $ |
---|
| 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 | |
---|
| 28 | function get_icon( $date ) |
---|
| 29 | { |
---|
| 30 | global $user, $conf, $lang; |
---|
| 31 | |
---|
[492] | 32 | if (!preg_match('/\d{4}-\d{2}-\d{2}/', $date)) |
---|
| 33 | { |
---|
| 34 | return ''; |
---|
| 35 | } |
---|
| 36 | |
---|
[476] | 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'].' '; |
---|
| 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 .= ' '.$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 | |
---|
| 57 | function 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.'&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 | { |
---|
[514] | 89 | $navigation_bar.= ' <span class="pageNumberSelected">'.$i.'</span> '; |
---|
[476] | 90 | } |
---|
| 91 | else |
---|
| 92 | { |
---|
| 93 | $navigation_bar.= ' <a href="'; |
---|
| 94 | $navigation_bar.= add_session_id( $url.'&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.'&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 | // |
---|
| 114 | function language_select($default, $select_name = "language") |
---|
| 115 | { |
---|
[512] | 116 | $available_lang = get_languages(); |
---|
[476] | 117 | |
---|
| 118 | $lang_select = '<select name="' . $select_name . '" onchange="this.form.submit()">'; |
---|
[528] | 119 | foreach ($available_lang as $code => $displayname) |
---|
[476] | 120 | { |
---|
| 121 | $selected = ( strtolower($default) == strtolower($code) ) ? ' selected="selected"' : ''; |
---|
| 122 | $lang_select .= '<option value="' . $code . '"' . $selected . '>' . ucwords($displayname) . '</option>'; |
---|
| 123 | } |
---|
| 124 | $lang_select .= '</select>'; |
---|
| 125 | |
---|
| 126 | return $lang_select; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | // |
---|
| 130 | // Pick a template/theme combo, |
---|
| 131 | // |
---|
| 132 | function style_select($default_style, $select_name = "style") |
---|
| 133 | { |
---|
[512] | 134 | $templates = get_templates(); |
---|
| 135 | |
---|
[519] | 136 | $style_selected = '<select name="' . $select_name . '" >'; |
---|
[512] | 137 | foreach ($templates as $template) |
---|
[476] | 138 | { |
---|
[512] | 139 | $selected = ( $template == $default_style ) ? ' selected="selected"' : ''; |
---|
[519] | 140 | $style_selected.= '<option value="'.$template.'"'.$selected.'>'; |
---|
| 141 | $style_selected.= $template.'</option>'; |
---|
[476] | 142 | } |
---|
[519] | 143 | $style_selected .= '</select>'; |
---|
| 144 | return $style_selected; |
---|
[476] | 145 | } |
---|
| 146 | |
---|
[572] | 147 | /** |
---|
| 148 | * returns the list of categories as a HTML string |
---|
| 149 | * |
---|
| 150 | * categories string returned contains categories as given in the input |
---|
| 151 | * array $cat_informations. $cat_informations array must be an association |
---|
| 152 | * of {category_id => category_name}. If url input parameter is empty, |
---|
| 153 | * returns only the categories name without links. |
---|
| 154 | * |
---|
| 155 | * @param array cat_informations |
---|
| 156 | * @param string separator |
---|
| 157 | * @param string url |
---|
| 158 | * @param boolean replace_space |
---|
| 159 | * @return string |
---|
| 160 | */ |
---|
[569] | 161 | function get_cat_display_name($cat_informations, |
---|
| 162 | $separator, |
---|
| 163 | $url = 'category.php?cat=', |
---|
| 164 | $replace_space = true) |
---|
[476] | 165 | { |
---|
| 166 | $output = ''; |
---|
[569] | 167 | $is_first = true; |
---|
| 168 | foreach ($cat_informations as $id => $name) |
---|
[476] | 169 | { |
---|
[569] | 170 | if ($is_first) |
---|
| 171 | { |
---|
| 172 | $is_first = false; |
---|
| 173 | } |
---|
| 174 | else |
---|
| 175 | { |
---|
| 176 | $output.= $separator; |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | if ($url == '') |
---|
| 180 | { |
---|
| 181 | $output.= $name; |
---|
| 182 | } |
---|
| 183 | else |
---|
| 184 | { |
---|
| 185 | $output.= ' |
---|
| 186 | <a class="" href="'.add_session_id(PHPWG_ROOT_PATH.$url.$id).'">'.$name.'</a>'; |
---|
| 187 | } |
---|
[476] | 188 | } |
---|
[569] | 189 | if ($replace_space) |
---|
| 190 | { |
---|
| 191 | return replace_space($output); |
---|
| 192 | } |
---|
| 193 | else |
---|
| 194 | { |
---|
| 195 | return $output; |
---|
| 196 | } |
---|
[476] | 197 | } |
---|
| 198 | |
---|
| 199 | /** |
---|
[610] | 200 | * returns the list of categories as a HTML string, with cache of names |
---|
| 201 | * |
---|
| 202 | * categories string returned contains categories as given in the input |
---|
| 203 | * array $cat_informations. $uppercats is the list of category ids to |
---|
| 204 | * display in the right order. If url input parameter is empty, returns only |
---|
| 205 | * the categories name without links. |
---|
| 206 | * |
---|
| 207 | * @param string uppercats |
---|
| 208 | * @param string separator |
---|
| 209 | * @param string url |
---|
| 210 | * @param boolean replace_space |
---|
| 211 | * @return string |
---|
| 212 | */ |
---|
| 213 | function get_cat_display_name_cache($uppercats, |
---|
| 214 | $separator, |
---|
| 215 | $url = 'category.php?cat=', |
---|
| 216 | $replace_space = true) |
---|
| 217 | { |
---|
| 218 | global $cat_names; |
---|
| 219 | |
---|
| 220 | if (!isset($cat_names)) |
---|
| 221 | { |
---|
| 222 | $query = ' |
---|
| 223 | SELECT id,name |
---|
| 224 | FROM '.CATEGORIES_TABLE.' |
---|
| 225 | ;'; |
---|
| 226 | $result = pwg_query($query); |
---|
| 227 | while ($row = mysql_fetch_array($result)) |
---|
| 228 | { |
---|
| 229 | $cat_names[$row['id']] = $row['name']; |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | $output = ''; |
---|
| 234 | $is_first = true; |
---|
| 235 | foreach (explode(',', $uppercats) as $category_id) |
---|
| 236 | { |
---|
| 237 | $name = $cat_names[$category_id]; |
---|
| 238 | |
---|
| 239 | if ($is_first) |
---|
| 240 | { |
---|
| 241 | $is_first = false; |
---|
| 242 | } |
---|
| 243 | else |
---|
| 244 | { |
---|
| 245 | $output.= $separator; |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | if ($url == '') |
---|
| 249 | { |
---|
| 250 | $output.= $name; |
---|
| 251 | } |
---|
| 252 | else |
---|
| 253 | { |
---|
| 254 | $output.= ' |
---|
| 255 | <a class="" |
---|
| 256 | href="'.add_session_id(PHPWG_ROOT_PATH.$url.$category_id).'">'.$name.'</a>'; |
---|
| 257 | } |
---|
| 258 | } |
---|
| 259 | if ($replace_space) |
---|
| 260 | { |
---|
| 261 | return replace_space($output); |
---|
| 262 | } |
---|
| 263 | else |
---|
| 264 | { |
---|
| 265 | return $output; |
---|
| 266 | } |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | /** |
---|
[476] | 270 | * returns the HTML code for a category item in the menu (for category.php) |
---|
| 271 | * |
---|
| 272 | * HTML code generated uses logical list tags ul and each category is an |
---|
| 273 | * item li. The paramter given is the category informations as an array, |
---|
| 274 | * used keys are : id, name, dir, nb_images, date_last, subcats (sub-array) |
---|
| 275 | * |
---|
| 276 | * @param array category |
---|
| 277 | * @return string |
---|
| 278 | */ |
---|
| 279 | function get_html_menu_category($category) |
---|
| 280 | { |
---|
| 281 | global $page, $lang; |
---|
| 282 | |
---|
| 283 | $menu = ' |
---|
| 284 | |
---|
| 285 | <li>'; |
---|
| 286 | |
---|
| 287 | $url = add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$category['id']); |
---|
| 288 | |
---|
| 289 | $class = ''; |
---|
| 290 | if (isset($page['cat']) |
---|
| 291 | and is_numeric($page['cat']) |
---|
| 292 | and $category['id'] == $page['cat']) |
---|
| 293 | { |
---|
| 294 | $class = 'menuCategorySelected'; |
---|
| 295 | } |
---|
| 296 | else |
---|
| 297 | { |
---|
| 298 | $class = 'menuCategoryNotSelected'; |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | $name = $category['name']; |
---|
| 302 | if (empty($name)) |
---|
| 303 | { |
---|
| 304 | $name = str_replace('_', ' ', $category['dir']); |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | $menu.= ' |
---|
| 308 | <a href="'.$url.'" |
---|
| 309 | title="'.$lang['hint_category'].'" |
---|
| 310 | class="'.$class.'"> |
---|
| 311 | '.$name.' |
---|
| 312 | </a>'; |
---|
| 313 | |
---|
| 314 | if ($category['nb_images'] > 0) |
---|
| 315 | { |
---|
| 316 | $menu.= ' |
---|
| 317 | <span class="menuInfoCat" |
---|
| 318 | title="'.$category['nb_images'].' |
---|
| 319 | '.$lang['images_available'].'"> |
---|
| 320 | ['.$category['nb_images'].'] |
---|
| 321 | </span> |
---|
| 322 | '.get_icon($category['date_last']); |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | // recursive call |
---|
| 326 | if ($category['expanded'] and count($category['subcats']) > 0) |
---|
| 327 | { |
---|
| 328 | $menu.= ' |
---|
| 329 | <ul class="menu">'; |
---|
| 330 | foreach ($category['subcats'] as $subcat) |
---|
| 331 | { |
---|
[496] | 332 | $menu.= get_html_menu_category($subcat); |
---|
[476] | 333 | } |
---|
| 334 | $menu.= ' |
---|
| 335 | </ul>'; |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | $menu.= '</li>'; |
---|
| 339 | |
---|
| 340 | return $menu; |
---|
| 341 | } |
---|
[579] | 342 | |
---|
| 343 | /** |
---|
| 344 | * returns HTMLized comment contents retrieved from database |
---|
| 345 | * |
---|
| 346 | * newlines becomes br tags, _word_ becomes underline, /word/ becomes |
---|
| 347 | * italic, *word* becomes bolded |
---|
| 348 | * |
---|
| 349 | * @param string content |
---|
| 350 | * @return string |
---|
| 351 | */ |
---|
| 352 | function parse_comment_content($content) |
---|
| 353 | { |
---|
| 354 | $content = nl2br($content); |
---|
| 355 | |
---|
| 356 | // replace _word_ by an underlined word |
---|
| 357 | $pattern = '/_([^\s]*)_/'; |
---|
| 358 | $replacement = '<span style="text-decoration:underline;">\1</span>'; |
---|
| 359 | $content = preg_replace($pattern, $replacement, $content); |
---|
| 360 | |
---|
| 361 | // replace *word* by a bolded word |
---|
| 362 | $pattern = '/\*([^\s]*)\*/'; |
---|
| 363 | $replacement = '<span style="font-weight:bold;">\1</span>'; |
---|
| 364 | $content = preg_replace($pattern, $replacement, $content); |
---|
| 365 | |
---|
| 366 | // replace /word/ by an italic word |
---|
| 367 | $pattern = '/\/([^\s]*)\//'; |
---|
| 368 | $replacement = '<span style="font-style:italic;">\1</span>'; |
---|
| 369 | $content = preg_replace($pattern, $replacement, $content); |
---|
| 370 | |
---|
| 371 | return $content; |
---|
| 372 | } |
---|
[476] | 373 | ?> |
---|