diff options
author | z0rglub <z0rglub@piwigo.org> | 2004-10-23 17:56:46 +0000 |
---|---|---|
committer | z0rglub <z0rglub@piwigo.org> | 2004-10-23 17:56:46 +0000 |
commit | 98b65edb831e95695cc840692ab8ad294478f80d (patch) | |
tree | 2b1ffe5ba3c8bc1fcdb209e8f8d793bd18e9dd1d /include | |
parent | 60ac6f180e9500c6fea0c872277f107f05d7d26d (diff) |
- 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
Diffstat (limited to 'include')
-rw-r--r-- | include/category_calendar.inc.php | 78 | ||||
-rw-r--r-- | include/category_default.inc.php | 28 | ||||
-rw-r--r-- | include/category_recent_cats.inc.php | 19 | ||||
-rw-r--r-- | include/category_subcats.inc.php | 17 | ||||
-rw-r--r-- | include/functions.inc.php | 48 | ||||
-rw-r--r-- | include/functions_category.inc.php | 20 | ||||
-rw-r--r-- | include/functions_html.inc.php | 31 |
7 files changed, 119 insertions, 122 deletions
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 = '<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; +} ?> |