From 98b65edb831e95695cc840692ab8ad294478f80d Mon Sep 17 00:00:00 2001 From: z0rglub Date: Sat, 23 Oct 2004 17:56:46 +0000 Subject: - refactoring of comments.php - creation of function get_thumbnail_src used everywhere a thumbnail must be displayed - creation of function parse_comment_content (used in comments.php and picture.php) - concerning undefined index on arrays retrieved in database, instead of testing possibly unset values, use of @ operator (smarter...) - add pre tag in default.css stylesheet for debugging purpose (need to have left aligned text) git-svn-id: http://piwigo.org/svn/trunk@579 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/infos_images.php | 47 +----- admin/picture_modify.php | 42 ++--- comments.php | 316 +++++++++++++++++------------------ include/category_calendar.inc.php | 78 ++------- include/category_default.inc.php | 28 +--- include/category_recent_cats.inc.php | 19 +-- include/category_subcats.inc.php | 17 +- include/functions.inc.php | 48 ++++++ include/functions_category.inc.php | 20 ++- include/functions_html.inc.php | 31 ++++ picture.php | 61 +++---- template/default/default.css | 5 + 12 files changed, 321 insertions(+), 391 deletions(-) diff --git a/admin/infos_images.php b/admin/infos_images.php index caa7d07d9..0c95bdf5b 100644 --- a/admin/infos_images.php +++ b/admin/infos_images.php @@ -319,40 +319,9 @@ SELECT * $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { - if (!isset($array_cat_directories[$row['storage_category_id']])) - { - $array_cat_directories[$row['storage_category_id']] = - get_complete_dir($row['storage_category_id']); - } - - // thumbnail url - if (isset($row['tn_ext']) and $row['tn_ext'] != '') - { - $thumbnail_url = $array_cat_directories[$row['storage_category_id']]; - $thumbnail_url.= 'thumbnail/'.$conf['prefix_thumbnail']; - $thumbnail_url.= get_filename_wo_extension($row['file']); - $thumbnail_url.= '.'.$row['tn_ext']; - } - else - { - $thumbnail_url = PHPWG_ROOT_PATH; - $thumbnail_url = 'template/'.$user['template'].'/mimetypes/'; - $thumbnail_url.= strtolower(get_extension($row['file'])).'.png'; - } - - // some fields are nullable in the images table - $nullables = array('name','author','keywords','date_creation','comment'); - foreach ($nullables as $field) - { - if (isset($row[$field])) - { - $$field = $row[$field]; - } - else - { - $$field = ''; - } - } + $thumbnail_url = get_thumbnail_src($row['file'], + $row['storage_category_id'], + @$row['tn_ext']); $template->assign_block_vars( 'picture', @@ -362,11 +331,11 @@ SELECT * 'TN_URL_IMG'=>$thumbnail_url, 'FILENAME_IMG'=>$row['file'], 'DEFAULTNAME_IMG'=>get_filename_wo_extension($row['file']), - 'NAME_IMG'=>$name, - 'DATE_IMG'=>date_convert_back($date_creation), - 'AUTHOR_IMG'=>$author, - 'KEYWORDS_IMG'=>$keywords, - 'COMMENT_IMG'=>$comment + 'NAME_IMG'=>@$row['name'], + 'DATE_IMG'=>date_convert_back(@$row['date_creation']), + 'AUTHOR_IMG'=>@$row['author'], + 'KEYWORDS_IMG'=>@$row['keywords'], + 'COMMENT_IMG'=>@$row['comment'] )); } diff --git a/admin/picture_modify.php b/admin/picture_modify.php index 42259dd9e..1e0e7ce31 100644 --- a/admin/picture_modify.php +++ b/admin/picture_modify.php @@ -187,17 +187,6 @@ SELECT * ;'; $row = mysql_fetch_array(mysql_query($query)); -// some fields are nullable in the images table -$nullables = array('name','author','keywords','date_creation','comment', - 'width','height'); -foreach ($nullables as $field) -{ - if (!isset($row[$field])) - { - $row[$field] = ''; - } -} - if (empty($row['name'])) { $title = str_replace('_', ' ',get_filename_wo_extension($row['file'])); @@ -210,25 +199,14 @@ else $current_category = get_cat_info($row['storage_category_id']); $dir_path = get_cat_display_name($current_category['name'], '->', ''); -// thumbnail url -if (isset($row['tn_ext']) and $row['tn_ext'] != '') -{ - $thumbnail_url = get_complete_dir($row['storage_category_id']); - $thumbnail_url.= 'thumbnail/'.$conf['prefix_thumbnail']; - $thumbnail_url.= get_filename_wo_extension($row['file']); - $thumbnail_url.= '.'.$row['tn_ext']; -} -else -{ - $thumbnail_url = PHPWG_ROOT_PATH; - $thumbnail_url = 'template/'.$user['template'].'/mimetypes/'; - $thumbnail_url.= strtolower(get_extension($row['file'])).'.png'; -} +$thumbnail_url = get_thumbnail_src($row['file'], + $row['storage_category_id'], + @$row['tn_ext']); $url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id']; $url_img .= '&cat='.$row['storage_category_id']; $date = isset($_POST['date_creation']) && empty($errors) - ?$_POST['date_creation']:date_convert_back($row['date_creation']); + ?$_POST['date_creation']:date_convert_back(@$row['date_creation']); // retrieving all the linked categories $query = ' @@ -257,14 +235,14 @@ $template->assign_vars(array( 'URL_IMG'=>add_session_id($url_img), 'DEFAULT_NAME_IMG'=>str_replace('_',' ',get_filename_wo_extension($row['file'])), 'FILE_IMG'=>$row['file'], - 'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:$row['name'], - 'SIZE_IMG'=>$row['width'].' * '.$row['height'], - 'FILESIZE_IMG'=>$row['filesize'].' KB', + 'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:@$row['name'], + 'SIZE_IMG'=>@$row['width'].' * '.@$row['height'], + 'FILESIZE_IMG'=>@$row['filesize'].' KB', 'REGISTRATION_DATE_IMG'=> format_date($row['date_available']), - 'AUTHOR_IMG'=>isset($_POST['author'])?$_POST['author']:$row['author'], + 'AUTHOR_IMG'=>isset($_POST['author'])?$_POST['author']:@$row['author'], 'CREATION_DATE_IMG'=>$date, - 'KEYWORDS_IMG'=>isset($_POST['keywords'])?$_POST['keywords']:$row['keywords'], - 'COMMENT_IMG'=>isset($_POST['comment'])?$_POST['comment']:$row['comment'], + 'KEYWORDS_IMG'=>isset($_POST['keywords'])?$_POST['keywords']:@$row['keywords'], + 'COMMENT_IMG'=>isset($_POST['comment'])?$_POST['comment']:@$row['comment'], 'ASSOCIATED_CATEGORIES'=>$categories, 'L_UPLOAD_NAME'=>$lang['upload_name'], diff --git a/comments.php b/comments.php index 564e93af2..e39bb0693 100644 --- a/comments.php +++ b/comments.php @@ -25,213 +25,207 @@ // | USA. | // +-----------------------------------------------------------------------+ -//----------------------------------------------------------- include +// +-----------------------------------------------------------------------+ +// | initialization | +// +-----------------------------------------------------------------------+ if (!defined('IN_ADMIN')) { define('PHPWG_ROOT_PATH','./'); - include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); + include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); } -//--------------------------------------------------- number of days to display -if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] ); -else define( 'MAX_DAYS', 0 ); -//----------------------------------------- non specific section initialization -$array_cat_directories = array(); -$array_cat_names = array(); -$array_cat_site_id = array(); - -// comment deletion -if ( isset( $_POST['delete'] ) ) +if (isset($_GET['last_days'])) { - $mod_sql=''; - while( list($id, $row_id) = @each($_POST['comment_id']) ) - { - $mod_sql .= ( ( $mod_sql != '' ) ? ', ' : '' ) . $row_id; - } - $query = 'DELETE FROM '.COMMENTS_TABLE.' WHERE id IN ('.$mod_sql.');'; - mysql_query( $query ); + define('MAX_DAYS', $_GET['last_days']); } - -//--------------------------------------------------------- comments validation -if ( isset( $_POST['validate'] ) ) +else { - $mod_sql=''; - while( list($id, $row_id) = @each($_POST['comment_id']) ) - { - $mod_sql .= ( ( $mod_sql != '' ) ? ', ' : '' ) . $row_id; - } - $query = 'UPDATE '.COMMENTS_TABLE; - $query.= " SET validated = 'true'"; - $query.=' WHERE id IN ('.$mod_sql.');'; - mysql_query( $query ); + define('MAX_DAYS', 0); } -//------------------------------------------------------- last comments display - -// -// Start output of page -// +$array_cat_names = array(); +// +-----------------------------------------------------------------------+ +// | comments management | +// +-----------------------------------------------------------------------+ +// comments deletion +if (isset($_POST['delete']) and count($_POST['comment_id']) > 0) +{ + $query = ' +DELETE FROM '.COMMENTS_TABLE.' + WHERE id IN ('.implode(',', $_POST['comment_id']).') +;'; + mysql_query($query); +} +// comments validation +if (isset($_POST['validate']) and count($_POST['comment_id']) > 0) +{ + $query = ' +UPDATE '.COMMENTS_TABLE.' + SET validated = \'true\' + WHERE id IN ('.implode(',', $_POST['comment_id']).') +;'; + mysql_query($query); +} +// +-----------------------------------------------------------------------+ +// | page header and options | +// +-----------------------------------------------------------------------+ if (!defined('IN_ADMIN')) { $title= $lang['title_comments']; include(PHPWG_ROOT_PATH.'include/page_header.php'); } -$template->set_filenames( array('comments'=>'comments.tpl') ); -$template->assign_vars(array( - 'L_COMMENT_TITLE' => $title, - 'L_COMMENT_STATS' => $lang['stats_last_days'], - 'L_COMMENT_RETURN' => $lang['return_main_page'], - 'L_DELETE' =>$lang['delete'], - 'L_VALIDATE'=>$lang['submit'], - - 'T_DEL_IMG' =>PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/delete.gif', - - 'U_HOME' => add_session_id( PHPWG_ROOT_PATH.'category.php' ) - ) -); +$template->set_filenames(array('comments'=>'comments.tpl')); +$template->assign_vars( + array( + 'L_COMMENT_TITLE' => $title, + 'L_COMMENT_STATS' => $lang['stats_last_days'], + 'L_COMMENT_RETURN' => $lang['return_main_page'], + 'L_DELETE' =>$lang['delete'], + 'L_VALIDATE'=>$lang['submit'], + + 'U_HOME' => add_session_id(PHPWG_ROOT_PATH.'category.php') + ) + ); -foreach ( $conf['last_days'] as $option ) { +foreach ($conf['last_days'] as $option) +{ $url = $_SERVER['PHP_SELF'].'?last_days='.($option - 1); - if (defined('IN_ADMIN')) $url.= '&page=comments'; + if (defined('IN_ADMIN')) + { + $url.= '&page=comments'; + } $template->assign_block_vars( 'last_day_option', array( 'OPTION'=>$option, - 'T_STYLE'=>(( $option == MAX_DAYS + 1 )?'text-decoration:underline;':''), - 'U_OPTION'=>add_session_id( $url ) + 'T_STYLE'=>(($option == MAX_DAYS + 1)?'text-decoration:underline;':''), + 'U_OPTION'=>add_session_id($url) ) ); } - +// +-----------------------------------------------------------------------+ +// | last comments display | +// +-----------------------------------------------------------------------+ // 1. retrieving picture ids which have comments recently added -$date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) ); -list($year,$month,$day) = explode( '-', $date); -$maxtime = mktime( 0,0,0,$month,$day,$year ); -$query = 'SELECT DISTINCT(ic.image_id) as image_id,'; -$query.= '(ic.category_id) as category_id'; -$query.= ' FROM '.COMMENTS_TABLE.' AS c'; -$query.= ', '.IMAGE_CATEGORY_TABLE.' AS ic'; -$query.= ' WHERE c.image_id = ic.image_id'; -$query.= ' AND date > FROM_UNIXTIME('.$maxtime.')'; -if ( $user['status'] != 'admin' ) +$maxdate = date('Y-m-d', strtotime('-'.MAX_DAYS.' day')); + +$query = ' +SELECT DISTINCT(ic.image_id) AS image_id,(ic.category_id) AS category_id + FROM '.COMMENTS_TABLE.' AS c, '.IMAGE_CATEGORY_TABLE.' AS ic + WHERE c.image_id = ic.image_id + AND date >= \''.$maxdate.'\''; +if ($user['status'] != 'admin') { - $query.= " AND validated = 'true'"; + $query.= " + AND validated = 'true'"; // we must not show pictures of a forbidden category - if ( $user['forbidden_categories'] != '' ) + if ($user['forbidden_categories'] != '') { - $query.= ' AND category_id NOT IN '; - $query.= '('.$user['forbidden_categories'].')'; + $query.= ' + AND category_id NOT IN ('.$user['forbidden_categories'].')'; } } -$query.= ' ORDER BY ic.image_id DESC'; -$query.= ';'; -$result = mysql_query( $query ); -if ( $user['status'] == 'admin' ) +$query.= ' + ORDER BY ic.image_id DESC +;'; +$result = mysql_query($query); +if ($user['status'] == 'admin') { $template->assign_block_vars('validation', array()); } -while ( $row = mysql_fetch_array( $result ) ) - { - $category_id=$row['category_id']; - - // for each picture, getting informations for displaying thumbnail and - // link to the full size picture - $query = 'SELECT name,file,storage_category_id as cat_id,tn_ext'; - $query.= ' FROM '.IMAGES_TABLE; - $query.= ' WHERE id = '.$row['image_id']; - $query.= ';'; - $subresult = mysql_query( $query ); - $subrow = mysql_fetch_array( $subresult ); +while ($row = mysql_fetch_array($result)) +{ + $category_id = $row['category_id']; + + // for each picture, getting informations for displaying thumbnail and + // link to the full size picture + $query = ' +SELECT name,file,storage_category_id as cat_id,tn_ext + FROM '.IMAGES_TABLE.' + WHERE id = '.$row['image_id'].' +;'; + $subresult = mysql_query($query); + $subrow = mysql_fetch_array($subresult); - if ( !isset($array_cat_directories[$subrow['cat_id']]) ) + if (!isset($array_cat_names[$subrow['cat_id']])) + { + $cat_result = get_cat_info($subrow['cat_id']); + $array_cat_names[$subrow['cat_id']] = + get_cat_display_name($cat_result['name'], ' > ', ''); + } + + // name of the picture + $name = $array_cat_names[$category_id].' > '; + if (!empty($subrow['name'])) + { + $name.= $subrow['name']; + } + else + { + $name.= str_replace('_',' ',get_filename_wo_extension($subrow['file'])); + } + $name.= ' [ '.$subrow['file'].' ]'; + // source of the thumbnail picture + $thumbnail_src = get_thumbnail_src($subrow['file'], + $subrow['cat_id'], + @$subrow['tn_ext']); + // link to the full size picture + $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id; + $url.= '&image_id='.$row['image_id']; + + $template->assign_block_vars( + 'picture', + array( + 'TITLE_IMG'=>$name, + 'I_THUMB'=>$thumbnail_src, + 'U_THUMB'=>add_session_id($url) + )); + + // for each picture, retrieving all comments + $query = ' +SELECT * + FROM '.COMMENTS_TABLE.' + WHERE image_id = '.$row['image_id'].' + AND date >= \''.$maxdate.'\''; + if ($user['status'] != 'admin') + { + $query.= ' + AND validated = \'true\''; + } + $query.= ' + ORDER BY date DESC +;'; + $handleresult = mysql_query($query); + while ($subrow = mysql_fetch_array($handleresult)) + { + $author = $subrow['author']; + if (empty($subrow['author'])) { - $array_cat_directories[$subrow['cat_id']] = - get_complete_dir( $subrow['cat_id'] ); - $cat_result = get_cat_info( $subrow['cat_id'] ); - $array_cat_site_id[$subrow['cat_id']] = $cat_result['site_id']; - $array_cat_names[$subrow['cat_id']] = - get_cat_display_name( $cat_result['name'], ' > ', '' ); + $author = $lang['guest']; } - $file = get_filename_wo_extension( $subrow['file'] ); - // name of the picture - $name = $array_cat_names[$category_id].' > '; - if (!empty($subrow['name'])) $name.= $subrow['name']; - else $name.= str_replace( '_', ' ', $file ); - $name.= ' [ '.$subrow['file'].' ]'; - // source of the thumbnail picture - if (isset($subrow['tn_ext']) and $subrow['tn_ext'] != '') - { - $src = $array_cat_directories[$subrow['cat_id']]; - $src.= 'thumbnail/'.$conf['prefix_thumbnail']; - $src.= $file.'.'.$subrow['tn_ext']; - } - else - { - $src = './template/'.$user['template'].'/mimetypes/'; - $src.= strtolower(get_extension($subrow['file'])).'.png'; - } - - // link to the full size picture - $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id; - $url.= '&image_id='.$row['image_id']; - $template->assign_block_vars( - 'picture', + 'picture.comment', array( - 'TITLE_IMG'=>$name, - 'I_THUMB'=>$src, - 'U_THUMB'=>add_session_id( $url ) + 'COMMENT_AUTHOR'=>$author, + 'COMMENT_DATE'=>format_date($subrow['date'],'mysql_datetime',true), + 'COMMENT'=>parse_comment_content($subrow['content']), )); - // for each picture, retrieving all comments - $query = 'SELECT * FROM '.COMMENTS_TABLE; - $query.= ' WHERE image_id = '.$row['image_id']; - $query.= ' AND date > FROM_UNIXTIME('.$maxtime.')'; - if ( $user['status'] != 'admin' ) - { - $query.= " AND validated = 'true'"; - } - $query.= ' ORDER BY date DESC'; - $query.= ';'; - $handleresult = mysql_query( $query ); - while ( $subrow = mysql_fetch_array( $handleresult ) ) + if ($user['status'] == 'admin') { - $author = $subrow['author']; - if ( empty($subrow['author'] )) $author = $lang['guest']; - $content = nl2br( $subrow['content'] ); - - // replace _word_ by an underlined word - $pattern = '/_([^\s]*)_/'; - $replacement = '\1'; - $content = preg_replace( $pattern, $replacement, $content ); - - // replace *word* by a bolded word - $pattern = '/\*([^\s]*)\*/'; - $replacement = '\1'; - $content = preg_replace( $pattern, $replacement, $content ); - - // replace /word/ by an italic word - $pattern = '/\/([^\s]*)\//'; - $replacement = '\1'; - $content = preg_replace( $pattern, $replacement, $content ); $template->assign_block_vars( - 'picture.comment',array( - 'COMMENT_AUTHOR'=>$author, - 'COMMENT_DATE'=>format_date( $subrow['date'],'mysql_datetime',true ), - 'COMMENT'=>$content, + 'picture.comment.validation', + array( + 'ID'=> $subrow['id'], + 'CHECKED'=>($subrow['validated']=='false')?'checked="checked"': '' )); - if ( $user['status'] == 'admin' ) - { - $template->assign_block_vars( - 'picture.comment.validation', array( - 'ID'=> $subrow['id'], - 'CHECKED'=>($subrow['validated']=='false')?'checked="checked"': '' - )); - } } } -//----------------------------------------------------------- html code display +} +// +-----------------------------------------------------------------------+ +// | html code display | +// +-----------------------------------------------------------------------+ if (defined('IN_ADMIN')) { $template->assign_var_from_handle('ADMIN_CONTENT', 'comments'); diff --git a/include/category_calendar.inc.php b/include/category_calendar.inc.php index f41f5bb97..fddf1b2cf 100644 --- a/include/category_calendar.inc.php +++ b/include/category_calendar.inc.php @@ -229,20 +229,9 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id ;'; $row = mysql_fetch_array(mysql_query($query)); - $file = get_filename_wo_extension($row['file']); - - // creating links for thumbnail and associated category - if (isset($row['tn_ext']) and $row['tn_ext'] != '') - { - $thumbnail_link = get_complete_dir($row['storage_category_id']); - $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail']; - $thumbnail_link.= $file.'.'.$row['tn_ext']; - } - else - { - $thumbnail_link = './template/'.$user['template'].'/mimetypes/'; - $thumbnail_link.= strtolower(get_extension($row['file'])).'.png'; - } + $thumbnail_src = get_thumbnail_src($row['file'], + $row['storage_category_id'], + @$row['tn_ext']); $name = $calendar_year.' ('.$nb_pics.')'; @@ -254,7 +243,7 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id $template->assign_block_vars( 'thumbnails.line.thumbnail', array( - 'IMAGE'=>$thumbnail_link, + 'IMAGE'=>$thumbnail_src, 'IMAGE_ALT'=>$row['file'], 'IMAGE_TITLE'=>$thumbnail_title, 'IMAGE_NAME'=>$name, @@ -288,21 +277,10 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id ;'; $row = mysql_fetch_array(mysql_query($query)); - $file = get_filename_wo_extension($row['file']); - - // creating links for thumbnail and associated category - if (isset($row['tn_ext']) and $row['tn_ext'] != '') - { - $thumbnail_link = get_complete_dir($row['storage_category_id']); - $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail']; - $thumbnail_link.= $file.'.'.$row['tn_ext']; - } - else - { - $thumbnail_link = './template/'.$user['template'].'/mimetypes/'; - $thumbnail_link.= strtolower(get_extension($row['file'])).'.png'; - } - + $thumbnail_src = get_thumbnail_src($row['file'], + $row['storage_category_id'], + @$row['tn_ext']); + $name = $lang['month'][$calendar_month]; $name.= ' '.$page['calendar_year']; $name.= ' ('.$nb_pics.')'; @@ -321,7 +299,7 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id $template->assign_block_vars( 'thumbnails.line.thumbnail', array( - 'IMAGE'=>$thumbnail_link, + 'IMAGE'=>$thumbnail_src, 'IMAGE_ALT'=>$row['file'], 'IMAGE_TITLE'=>$thumbnail_title, 'IMAGE_NAME'=>$name, @@ -354,20 +332,9 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id ;'; $row = mysql_fetch_array(mysql_query($query)); - $file = get_filename_wo_extension($row['file']); - - // creating links for thumbnail and associated category - if (isset($row['tn_ext']) and $row['tn_ext'] != '') - { - $thumbnail_link = get_complete_dir($row['storage_category_id']); - $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail']; - $thumbnail_link.= $file.'.'.$row['tn_ext']; - } - else - { - $thumbnail_link = './template/'.$user['template'].'/mimetypes/'; - $thumbnail_link.= strtolower(get_extension($row['file'])).'.png'; - } + $thumbnail_src = get_thumbnail_src($row['file'], + $row['storage_category_id'], + @$row['tn_ext']); list($year,$month,$day) = explode('-', $calendar_day); $unixdate = mktime(0,0,0,$month,$day,$year); @@ -383,7 +350,7 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id $template->assign_block_vars( 'thumbnails.line.thumbnail', array( - 'IMAGE'=>$thumbnail_link, + 'IMAGE'=>$thumbnail_src, 'IMAGE_ALT'=>$row['file'], 'IMAGE_TITLE'=>$thumbnail_title, 'IMAGE_NAME'=>$name, @@ -434,20 +401,9 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id ;'; $row = mysql_fetch_array(mysql_query($query)); - $file = get_filename_wo_extension($row['file']); - - // creating links for thumbnail and associated category - if (isset($row['tn_ext']) and $row['tn_ext'] != '') - { - $thumbnail_link = get_complete_dir($row['storage_category_id']); - $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail']; - $thumbnail_link.= $file.'.'.$row['tn_ext']; - } - else - { - $thumbnail_link = './template/'.$user['template'].'/mimetypes/'; - $thumbnail_link.= strtolower(get_extension($row['file'])).'.png'; - } + $thumbnail_src = get_thumbnail_src($row['file'], + $row['storage_category_id'], + @$row['tn_ext']); $thumbnail_title = $lang['calendar_picture_hint'].$name; @@ -461,7 +417,7 @@ SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id $template->assign_block_vars( 'thumbnails.line.thumbnail', array( - 'IMAGE'=>$thumbnail_link, + 'IMAGE'=>$thumbnail_src, 'IMAGE_ALT'=>$row['file'], 'IMAGE_TITLE'=>$thumbnail_title, 'IMAGE_NAME'=>$name, diff --git a/include/category_default.inc.php b/include/category_default.inc.php index 56b43524c..0bed31a36 100644 --- a/include/category_default.inc.php +++ b/include/category_default.inc.php @@ -61,15 +61,6 @@ if ( mysql_num_rows($result) > 0 ) while ($row = mysql_fetch_array($result)) { - // retrieving the storage dir of the picture - if (!isset($array_cat_directories[$row['storage_category_id']])) - { - $array_cat_directories[$row['storage_category_id']] = - get_complete_dir($row['storage_category_id']); - } - $cat_directory = $array_cat_directories[$row['storage_category_id']]; - - $file = get_filename_wo_extension($row['file']); // name of the picture if (isset($row['name']) and $row['name'] != '') { @@ -77,7 +68,7 @@ while ($row = mysql_fetch_array($result)) } else { - $name = str_replace('_', ' ', $file); + $name = str_replace('_', ' ', get_filename_wo_extension($row['file'])); } if ($page['cat'] == 'best_rated') { @@ -88,19 +79,10 @@ while ($row = mysql_fetch_array($result)) { $name = replace_search($name, $_GET['search']); } - // thumbnail url - if (isset($row['tn_ext']) and $row['tn_ext'] != '') - { - $thumbnail_url = $cat_directory; - $thumbnail_url.= 'thumbnail/'.$conf['prefix_thumbnail']; - $thumbnail_url.= $file.'.'.$row['tn_ext']; - } - else - { - $thumbnail_url = PHPWG_ROOT_PATH; - $thumbnail_url.= 'template/'.$user['template'].'/mimetypes/'; - $thumbnail_url.= strtolower(get_extension($row['file'])).'.png'; - } + + $thumbnail_url = get_thumbnail_src($row['file'], + $row['storage_category_id'], + @$row['tn_ext']); // message in title for the thumbnail $thumbnail_title = $row['file']; diff --git a/include/category_recent_cats.inc.php b/include/category_recent_cats.inc.php index 283d15ec6..a71148353 100644 --- a/include/category_recent_cats.inc.php +++ b/include/category_recent_cats.inc.php @@ -77,27 +77,16 @@ SELECT id,file,tn_ext,storage_category_id ;'; $subrow = mysql_fetch_array( mysql_query( $query ) ); - $file = get_filename_wo_extension( $subrow['file'] ); - - // creating links for thumbnail and associated category - if (isset($subrow['tn_ext']) and $subrow['tn_ext'] != '') - { - $thumbnail_link = get_complete_dir($subrow['storage_category_id']); - $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail']; - $thumbnail_link.= $file.'.'.$subrow['tn_ext']; - } - else - { - $thumbnail_link = './template/'.$user['template'].'/mimetypes/'; - $thumbnail_link.= strtolower(get_extension($subrow['file'])).'.png'; - } + $thumbnail_src = get_thumbnail_src($subrow['file'], + $subrow['storage_category_id'], + @$subrow['tn_ext']); $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['category_id']; $template->assign_block_vars( 'thumbnails.line.thumbnail', array( - 'IMAGE' => $thumbnail_link, + 'IMAGE' => $thumbnail_src, 'IMAGE_ALT' => $subrow['file'], 'IMAGE_TITLE' => $lang['hint_category'], 'IMAGE_NAME' => '['.$name.']', diff --git a/include/category_subcats.inc.php b/include/category_subcats.inc.php index a7791a5a2..6758f9e9a 100644 --- a/include/category_subcats.inc.php +++ b/include/category_subcats.inc.php @@ -86,20 +86,9 @@ SELECT file,tn_ext,storage_category_id $image_result = mysql_query($query); $image_row = mysql_fetch_array($image_result); - $file = get_filename_wo_extension($image_row['file']); - - // creating links for thumbnail and associated category - if (isset($image_row['tn_ext']) and $image_row['tn_ext'] != '') - { - $thumbnail_link = get_complete_dir($image_row['storage_category_id']); - $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail']; - $thumbnail_link.= $file.'.'.$image_row['tn_ext']; - } - else - { - $thumbnail_link = './template/'.$user['template'].'/mimetypes/'; - $thumbnail_link.= strtolower(get_extension($image_row['file'])).'.png'; - } + $thumbnail_link = get_thumbnail_src($image_row['file'], + $image_row['storage_category_id'], + @$image_row['tn_ext']); $thumbnail_title = $lang['hint_category']; diff --git a/include/functions.inc.php b/include/functions.inc.php index 841c86f74..82577b66e 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -546,4 +546,52 @@ function get_templates() { return get_dirs(PHPWG_ROOT_PATH.'template'); } + +/** + * returns thumbnail filepath (or distant URL if thumbnail is remote) for a + * given element + * + * this function could have taken only the element id as parameter but to + * optimize database access we directly ask file, storage category + * identifier and extension since when this function is called, + * PhpWebGallery should have all these infos. No need to retrieve them + * another time in the database. + * + * the returned string can represente the filepath of the thumbnail or the + * filepath to the corresponding icon for non picture elements + * + * complete directories are cached to be used more than once during a page + * generation (many thumbnails of the same category on the same page) + * + * @param string file + * @param int storage_category_id + * @param string tn_ext + * @return string + */ +function get_thumbnail_src($file, $storage_category_id, $tn_ext = '') +{ + global $conf, $user, $array_cat_directories; + + if (!isset($array_cat_directories[$storage_category_id])) + { + $array_cat_directories[$storage_category_id] = + get_complete_dir($storage_category_id); + } + + if ($tn_ext != '') + { + $src = $array_cat_directories[$storage_category_id]; + $src.= 'thumbnail/'.$conf['prefix_thumbnail']; + $src.= get_filename_wo_extension($file); + $src.= '.'.$tn_ext; + } + else + { + $src = PHPWG_ROOT_PATH; + $src.= 'template/'.$user['template'].'/mimetypes/'; + $src.= strtolower(get_extension($file)).'.png'; + } + + return $src; +} ?> \ No newline at end of file diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index c9485d17b..6171b562c 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -345,7 +345,7 @@ function get_cat_info( $id ) // get_complete_dir(22) returns "./galleries/pets/rex/1_year_old/" function get_complete_dir( $category_id ) { - return get_site_url( $category_id ).get_local_dir( $category_id ); + return get_site_url($category_id).get_local_dir($category_id); } // get_local_dir returns an array with complete path without the site url @@ -383,7 +383,8 @@ function get_local_dir( $category_id ) { $database_dirs[$row['id']] = $row['dir']; } - foreach ( $upper_array as $id ) { + foreach ($upper_array as $id) + { $local_dir.= $database_dirs[$id].'/'; } @@ -392,16 +393,17 @@ function get_local_dir( $category_id ) // retrieving the site url : "http://domain.com/gallery/" or // simply "./galleries/" -function get_site_url( $category_id ) +function get_site_url($category_id) { global $page; - $query = 'SELECT galleries_url'; - $query.= ' FROM '.SITES_TABLE.' AS s,'.CATEGORIES_TABLE.' AS c'; - $query.= ' WHERE s.id = c.site_id'; - $query.= ' AND c.id = '.$category_id; - $query.= ';'; - $row = mysql_fetch_array( mysql_query( $query ) ); + $query = ' +SELECT galleries_url + FROM '.SITES_TABLE.' AS s,'.CATEGORIES_TABLE.' AS c + WHERE s.id = c.site_id + AND c.id = '.$category_id.' +;'; + $row = mysql_fetch_array(mysql_query($query)); return $row['galleries_url']; } diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php index a7752e4c2..454c4c24f 100644 --- a/include/functions_html.inc.php +++ b/include/functions_html.inc.php @@ -269,4 +269,35 @@ function get_html_menu_category($category) 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 = '\1'; + $content = preg_replace($pattern, $replacement, $content); + + // replace *word* by a bolded word + $pattern = '/\*([^\s]*)\*/'; + $replacement = '\1'; + $content = preg_replace($pattern, $replacement, $content); + + // replace /word/ by an italic word + $pattern = '/\/([^\s]*)\//'; + $replacement = '\1'; + $content = preg_replace($pattern, $replacement, $content); + + return $content; +} ?> diff --git a/picture.php b/picture.php index 1816aaffc..1ef71bea5 100644 --- a/picture.php +++ b/picture.php @@ -181,16 +181,9 @@ foreach (array('prev', 'current', 'next') as $i) $picture[$i]['download'] = $cat_directory.$row['file']; } - if (isset($row['tn_ext']) and $row['tn_ext'] != '') - { - $picture[$i]['thumbnail'] = $cat_directory.'thumbnail/'; - $picture[$i]['thumbnail'].= $conf['prefix_thumbnail'].$file_wo_ext; - $picture[$i]['thumbnail'].= '.'.$row['tn_ext']; - } - else - { - $picture[$i]['thumbnail'] = $icon; - } + $picture[$i]['thumbnail'] = get_thumbnail_src($row['file'], + $row['storage_category_id'], + @$row['tn_ext']); if ( !empty( $row['name'] ) ) { @@ -961,46 +954,40 @@ if ( $conf['show_comments'] ) while ( $row = mysql_fetch_array( $result ) ) { - $content = nl2br( $row['content'] ); - - // replace _word_ by an underlined word - $pattern = '/_([^\s]*)_/'; - $replacement = '\1'; - $content = preg_replace( $pattern, $replacement, $content ); - - // replace *word* by a bolded word - $pattern = '/\*([^\s]*)\*/'; - $replacement = '\1'; - $content = preg_replace( $pattern, $replacement, $content ); - - // replace /word/ by an italic word - $pattern = '/\/([^\s]*)\//'; - $replacement = '\1'; - $content = preg_replace( $pattern, $replacement, $content ); - - $template->assign_block_vars('comments.comment', array( - 'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'], - 'COMMENT_DATE'=>format_date( $row['date'], 'mysql_datetime', true ), - 'COMMENT'=>$content + $template->assign_block_vars( + 'comments.comment', + array( + 'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'], + 'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true), + 'COMMENT'=>parse_comment_content($row['content']) )); if ( $user['status'] == 'admin' ) { - $template->assign_block_vars('comments.comment.delete', array('U_COMMENT_DELETE'=>add_session_id( $url.'&del='.$row['id'] ))); + $template->assign_block_vars( + 'comments.comment.delete', + array('U_COMMENT_DELETE'=>add_session_id( $url.'&del='.$row['id']) + )); } } - if ( !$user['is_the_guest']||( $user['is_the_guest'] and $conf['comments_forall'] ) ) + if (!$user['is_the_guest'] + or ($user['is_the_guest'] and $conf['comments_forall'])) { $template->assign_block_vars('comments.add_comment', array()); // display author field if the user is not logged in - if ( !$user['is_the_guest'] ) + if (!$user['is_the_guest']) { - $template->assign_block_vars('comments.add_comment.author_known', array('KNOWN_AUTHOR'=>$user['username'])); - } + $template->assign_block_vars( + 'comments.add_comment.author_known', + array('KNOWN_AUTHOR'=>$user['username']) + ); + } else { - $template->assign_block_vars('comments.add_comment.author_field', array()); + $template->assign_block_vars( + 'comments.add_comment.author_field', array() + ); } } } diff --git a/template/default/default.css b/template/default/default.css index 69829a98c..4994645ab 100644 --- a/template/default/default.css +++ b/template/default/default.css @@ -419,4 +419,9 @@ li.remoteError { div.remoteLocal { text-align:center; +} + +/* for debugging purpose */ +pre { + text-align:left; } \ No newline at end of file -- cgit v1.2.3