aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/picture_rate.inc.php11
-rw-r--r--picture.php39
2 files changed, 40 insertions, 10 deletions
diff --git a/include/picture_rate.inc.php b/include/picture_rate.inc.php
index b5fc884d9..aa1071452 100644
--- a/include/picture_rate.inc.php
+++ b/include/picture_rate.inc.php
@@ -28,14 +28,21 @@
if ($conf['rate'])
{
- $query = '
+ if ( NULL != $picture['current']['average_rate'] )
+ {
+ $query = '
SELECT COUNT(rate) AS count
, ROUND(AVG(rate),2) AS average
, ROUND(STD(rate),2) AS std
FROM '.RATE_TABLE.'
WHERE element_id = '.$picture['current']['id'].'
;';
- $row = mysql_fetch_array(pwg_query($query));
+ $row = mysql_fetch_array(pwg_query($query));
+ }
+ else
+ { // avg rate null -> no rate -> no need to query db
+ $row = array( 'count'=>0, 'average'=>NULL, 'std'=>NULL );
+ }
$template->assign('rate_summary', $row);
$user_rate = null;
diff --git a/picture.php b/picture.php
index d6ce69ca0..286b51ff6 100644
--- a/picture.php
+++ b/picture.php
@@ -612,7 +612,7 @@ $template->assign(
'SHOW_PICTURE_NAME_ON_TITLE' => $conf['show_picture_name_on_title'],
'LEVEL_SEPARATOR' => $conf['level_separator'],
-
+
'FILE_PICTURE_NAV_BUTTONS' => 'picture_nav_buttons.tpl',
'U_HOME' => make_index_url(),
@@ -637,7 +637,7 @@ if (is_admin())
)
);
}
-
+
$template->assign(
array(
'U_CADDIE' => add_url_params($url_self,
@@ -815,15 +815,38 @@ if ( count($tags) )
}
// related categories
-foreach ($related_categories as $category)
-{
+if ( count($related_categories)==1 and
+ isset($page['category']) and
+ $related_categories[0]['category_id']==$page['category']['id'] )
+{ // no need to go to db, we have all the info
$template->append(
- 'related_categories',
- count($related_categories) > 3
- ? get_cat_display_name_cache($category['uppercats'])
- : get_cat_display_name_from_id($category['category_id'])
+ 'related_categories',
+ get_cat_display_name( $page['category']['upper_names'] )
);
}
+else
+{ // use only 1 sql query to get names for all related categories
+ $ids = array();
+ foreach ($related_categories as $category)
+ {// add all uppercats to $ids
+ $ids = array_merge($ids, explode(',', $category['uppercats']) );
+ }
+ $ids = array_unique($ids);
+ $query = '
+SELECT id, name, permalink
+ FROM '.CATEGORIES_TABLE.'
+ WHERE id IN ('.implode(',',$ids).')';
+ $cat_map = hash_from_query($query, 'id');
+ foreach ($related_categories as $category)
+ {
+ $cats = array();
+ foreach ( explode(',', $category['uppercats']) as $id )
+ {
+ $cats[] = $cat_map[$id];
+ }
+ $template->append('related_categories', get_cat_display_name($cats) );
+ }
+}
// maybe someone wants a special display (call it before page_header so that
// they can add stylesheets)