391fac78a8
"private or public" choice = different language item - get_cat_display_name changed : use $conf['level_separator'] to unify presentation - default values for category properties commentable, uploadable, status and visible (set in include/config.inc.php) used for category creation (admin/update, admin/remote_site, admin/cat_list) - use mass_inserts in admin/update for inserting new categories - only one query for counting the number of sub categories in admin/cat_list git-svn-id: http://piwigo.org/svn/trunk@642 68402e56-0260-453c-a942-63ccdbb3a9ee
376 lines
10 KiB
PHP
376 lines
10 KiB
PHP
<?php
|
||
// +-----------------------------------------------------------------------+
|
||
// | PhpWebGallery - a PHP based picture gallery |
|
||
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
|
||
// | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net |
|
||
// +-----------------------------------------------------------------------+
|
||
// | branch : BSF (Best So Far)
|
||
// | file : $RCSfile$
|
||
// | last update : $Date$
|
||
// | last modifier : $Author$
|
||
// | revision : $Revision$
|
||
// +-----------------------------------------------------------------------+
|
||
// | This program is free software; you can redistribute it and/or modify |
|
||
// | it under the terms of the GNU General Public License as published by |
|
||
// | the Free Software Foundation |
|
||
// | |
|
||
// | This program is distributed in the hope that it will be useful, but |
|
||
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
||
// | General Public License for more details. |
|
||
// | |
|
||
// | You should have received a copy of the GNU General Public License |
|
||
// | along with this program; if not, write to the Free Software |
|
||
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
||
// | USA. |
|
||
// +-----------------------------------------------------------------------+
|
||
|
||
function get_icon( $date )
|
||
{
|
||
global $user, $conf, $lang;
|
||
|
||
if (!preg_match('/\d{4}-\d{2}-\d{2}/', $date))
|
||
{
|
||
return '';
|
||
}
|
||
|
||
list( $year,$month,$day ) = explode( '-', $date );
|
||
$unixtime = mktime( 0, 0, 0, $month, $day, $year );
|
||
|
||
$diff = time() - $unixtime;
|
||
$day_in_seconds = 24*60*60;
|
||
$output = '';
|
||
$title = $lang['recent_image'].' ';
|
||
if ( $diff < $user['recent_period'] * $day_in_seconds )
|
||
{
|
||
$icon_url = './template/'.$user['template'].'/theme/';
|
||
$icon_url.= 'recent.gif';
|
||
$title .= $user['recent_period'];
|
||
$title .= ' '.$lang['days'];
|
||
$size = getimagesize( $icon_url );
|
||
$output = '<img title="'.$title.'" src="'.$icon_url.'" style="border:0;';
|
||
$output.= 'height:'.$size[1].'px;width:'.$size[0].'px" alt="" />';
|
||
}
|
||
return $output;
|
||
}
|
||
|
||
function create_navigation_bar( $url, $nb_element, $start,
|
||
$nb_element_page, $link_class )
|
||
{
|
||
global $lang;
|
||
$navigation_bar = "";
|
||
// 0. d<>tection de la page en cours
|
||
if( !isset( $start )
|
||
|| !is_numeric( $start )
|
||
|| ( is_numeric( $start ) && $start < 0 ) )
|
||
{
|
||
$start = 0;
|
||
}
|
||
// on n'affiche la bare de navigation que si on plus de 1 page
|
||
if ( $nb_element > $nb_element_page )
|
||
{
|
||
// 1.une page pr<70>c<EFBFBD>dente ?
|
||
if ( $start != 0 )
|
||
{
|
||
$previous = $start - $nb_element_page;
|
||
$navigation_bar.= '<a href="';
|
||
$navigation_bar.= add_session_id( $url.'&start='.$previous );
|
||
$navigation_bar.= '" class="'.$link_class.'">'.$lang['previous_page'];
|
||
$navigation_bar.= '</a>';
|
||
$navigation_bar.= ' | ';
|
||
}
|
||
// 2.liste des num<75>ros de page
|
||
$maximum = ceil ( $nb_element / $nb_element_page );
|
||
for ( $i = 1; $i <= $maximum; $i++ )
|
||
{
|
||
$temp_start = ( $i - 1 ) * $nb_element_page;
|
||
if ( $temp_start == $start )
|
||
{
|
||
$navigation_bar.= ' <span class="pageNumberSelected">'.$i.'</span> ';
|
||
}
|
||
else
|
||
{
|
||
$navigation_bar.= ' <a href="';
|
||
$navigation_bar.= add_session_id( $url.'&start='.$temp_start );
|
||
$navigation_bar.= '" class="'.$link_class.'">'.$i.'</a> ';
|
||
}
|
||
}
|
||
// 3.une page suivante ?
|
||
if ( $nb_element > $nb_element_page
|
||
&& $start + $nb_element_page < $nb_element )
|
||
{
|
||
$next = $start + $nb_element_page;
|
||
$navigation_bar.= ' | <a href="';
|
||
$navigation_bar.= add_session_id( $url.'&start='.$next );
|
||
$navigation_bar.= '" class="'.$link_class.'">'.$lang['next_page'].'</a>';
|
||
}
|
||
}
|
||
return $navigation_bar;
|
||
}
|
||
|
||
//
|
||
// Pick a language, any language ...
|
||
//
|
||
function language_select($default, $select_name = "language")
|
||
{
|
||
$available_lang = get_languages();
|
||
|
||
$lang_select = '<select name="' . $select_name . '" onchange="this.form.submit()">';
|
||
foreach ($available_lang as $code => $displayname)
|
||
{
|
||
$selected = ( strtolower($default) == strtolower($code) ) ? ' selected="selected"' : '';
|
||
$lang_select .= '<option value="' . $code . '"' . $selected . '>' . ucwords($displayname) . '</option>';
|
||
}
|
||
$lang_select .= '</select>';
|
||
|
||
return $lang_select;
|
||
}
|
||
|
||
//
|
||
// Pick a template/theme combo,
|
||
//
|
||
function style_select($default_style, $select_name = "style")
|
||
{
|
||
$templates = get_templates();
|
||
|
||
$style_selected = '<select name="' . $select_name . '" >';
|
||
foreach ($templates as $template)
|
||
{
|
||
$selected = ( $template == $default_style ) ? ' selected="selected"' : '';
|
||
$style_selected.= '<option value="'.$template.'"'.$selected.'>';
|
||
$style_selected.= $template.'</option>';
|
||
}
|
||
$style_selected .= '</select>';
|
||
return $style_selected;
|
||
}
|
||
|
||
/**
|
||
* returns the list of categories as a HTML string
|
||
*
|
||
* categories string returned contains categories as given in the input
|
||
* array $cat_informations. $cat_informations array must be an association
|
||
* of {category_id => category_name}. If url input parameter is empty,
|
||
* returns only the categories name without links.
|
||
*
|
||
* @param array cat_informations
|
||
* @param string separator
|
||
* @param string url
|
||
* @param boolean replace_space
|
||
* @return string
|
||
*/
|
||
function get_cat_display_name($cat_informations,
|
||
$url = 'category.php?cat=',
|
||
$replace_space = true)
|
||
{
|
||
global $conf;
|
||
|
||
$output = '';
|
||
$is_first = true;
|
||
foreach ($cat_informations as $id => $name)
|
||
{
|
||
if ($is_first)
|
||
{
|
||
$is_first = false;
|
||
}
|
||
else
|
||
{
|
||
$output.= $conf['level_separator'];
|
||
}
|
||
|
||
if ($url == '')
|
||
{
|
||
$output.= $name;
|
||
}
|
||
else
|
||
{
|
||
$output.= '
|
||
<a class="" href="'.add_session_id(PHPWG_ROOT_PATH.$url.$id).'">'.$name.'</a>';
|
||
}
|
||
}
|
||
if ($replace_space)
|
||
{
|
||
return replace_space($output);
|
||
}
|
||
else
|
||
{
|
||
return $output;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* returns the list of categories as a HTML string, with cache of names
|
||
*
|
||
* categories string returned contains categories as given in the input
|
||
* array $cat_informations. $uppercats is the list of category ids to
|
||
* display in the right order. If url input parameter is empty, returns only
|
||
* the categories name without links.
|
||
*
|
||
* @param string uppercats
|
||
* @param string url
|
||
* @param boolean replace_space
|
||
* @return string
|
||
*/
|
||
function get_cat_display_name_cache($uppercats,
|
||
$url = 'category.php?cat=',
|
||
$replace_space = true)
|
||
{
|
||
global $cat_names, $conf;
|
||
|
||
if (!isset($cat_names))
|
||
{
|
||
$query = '
|
||
SELECT id,name
|
||
FROM '.CATEGORIES_TABLE.'
|
||
;';
|
||
$result = pwg_query($query);
|
||
while ($row = mysql_fetch_array($result))
|
||
{
|
||
$cat_names[$row['id']] = $row['name'];
|
||
}
|
||
}
|
||
|
||
$output = '';
|
||
$is_first = true;
|
||
foreach (explode(',', $uppercats) as $category_id)
|
||
{
|
||
$name = $cat_names[$category_id];
|
||
|
||
if ($is_first)
|
||
{
|
||
$is_first = false;
|
||
}
|
||
else
|
||
{
|
||
$output.= $conf['level_separator'];
|
||
}
|
||
|
||
if ($url == '')
|
||
{
|
||
$output.= $name;
|
||
}
|
||
else
|
||
{
|
||
$output.= '
|
||
<a class=""
|
||
href="'.add_session_id(PHPWG_ROOT_PATH.$url.$category_id).'">'.$name.'</a>';
|
||
}
|
||
}
|
||
if ($replace_space)
|
||
{
|
||
return replace_space($output);
|
||
}
|
||
else
|
||
{
|
||
return $output;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* returns the HTML code for a category item in the menu (for category.php)
|
||
*
|
||
* HTML code generated uses logical list tags ul and each category is an
|
||
* item li. The paramter given is the category informations as an array,
|
||
* used keys are : id, name, nb_images, date_last
|
||
*
|
||
* @param array categories
|
||
* @return string
|
||
*/
|
||
function get_html_menu_category($categories)
|
||
{
|
||
global $page, $lang;
|
||
|
||
$ref_level = 0;
|
||
$menu = '
|
||
<ul class="menu">';
|
||
|
||
foreach ($categories as $category)
|
||
{
|
||
$level = substr_count($category['global_rank'], '.');
|
||
if ($level > $ref_level)
|
||
{
|
||
$menu.= '
|
||
<ul class="menu">';
|
||
}
|
||
else if ($level < $ref_level)
|
||
{
|
||
$menu.= '
|
||
</ul>';
|
||
}
|
||
$ref_level = $level;
|
||
|
||
$menu.= '
|
||
|
||
<li>';
|
||
|
||
$url = add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$category['id']);
|
||
|
||
$class = '';
|
||
if (isset($page['cat'])
|
||
and is_numeric($page['cat'])
|
||
and $category['id'] == $page['cat'])
|
||
{
|
||
$class = 'menuCategorySelected';
|
||
}
|
||
else
|
||
{
|
||
$class = 'menuCategoryNotSelected';
|
||
}
|
||
|
||
$menu.= '
|
||
<a href="'.$url.'"
|
||
title="'.$lang['hint_category'].'"
|
||
class="'.$class.'">
|
||
'.$category['name'].'
|
||
</a>';
|
||
|
||
if ($category['nb_images'] > 0)
|
||
{
|
||
$menu.= '
|
||
<span class="menuInfoCat"
|
||
title="'.$category['nb_images'].'
|
||
'.$lang['images_available'].'">
|
||
['.$category['nb_images'].']
|
||
</span>
|
||
'.get_icon($category['date_last']);
|
||
}
|
||
|
||
$menu.= '</li>';
|
||
}
|
||
|
||
$menu.= '
|
||
</ul>';
|
||
|
||
return $menu;
|
||
}
|
||
|
||
/**
|
||
* returns HTMLized comment contents retrieved from database
|
||
*
|
||
* newlines becomes br tags, _word_ becomes underline, /word/ becomes
|
||
* italic, *word* becomes bolded
|
||
*
|
||
* @param string content
|
||
* @return string
|
||
*/
|
||
function parse_comment_content($content)
|
||
{
|
||
$content = nl2br($content);
|
||
|
||
// replace _word_ by an underlined word
|
||
$pattern = '/_([^\s]*)_/';
|
||
$replacement = '<span style="text-decoration:underline;">\1</span>';
|
||
$content = preg_replace($pattern, $replacement, $content);
|
||
|
||
// replace *word* by a bolded word
|
||
$pattern = '/\*([^\s]*)\*/';
|
||
$replacement = '<span style="font-weight:bold;">\1</span>';
|
||
$content = preg_replace($pattern, $replacement, $content);
|
||
|
||
// replace /word/ by an italic word
|
||
$pattern = '/\/([^\s]*)\//';
|
||
$replacement = '<span style="font-style:italic;">\1</span>';
|
||
$content = preg_replace($pattern, $replacement, $content);
|
||
|
||
return $content;
|
||
}
|
||
?>
|