Index: /extensions/SmartAlbums/admin/albums.inc.php
===================================================================
--- /extensions/SmartAlbums/admin/albums.inc.php	(revision 11545)
+++ /extensions/SmartAlbums/admin/albums.inc.php	(revision 11546)
@@ -65,15 +65,13 @@
       array_push(
         $page['infos'], 
-        l10n_args(get_l10n_args(
-          '%d photos associated to album &laquo;%s&raquo;', 
-          array(
-            count($associated_images), 
-            trigger_event(
-              'render_category_name',
-              $category['name'],
-              'admin_cat_list'
-              )
-            )
-          ))
+        sprintf(
+          l10n('%d photos associated to album %s'), 
+          count($associated_images), 
+          '&laquo;'.trigger_event(
+            'render_category_name',
+            $category['name'],
+            'admin_cat_list'
+            ).'&raquo;'
+          )
         );
     }
@@ -85,15 +83,13 @@
     array_push(
       $page['infos'], 
-      l10n_args(get_l10n_args(
-        '%d photos associated to album &laquo;%s&raquo;', 
-        array(
-          count($associated_images), 
-          trigger_event(
-            'render_category_name',
-            $categories[$_GET['smart_generate']]['name'],
-            'admin_cat_list'
-            )
-          )
-        ))
+      sprintf(
+        l10n('%d photos associated to album %s'), 
+        count($associated_images), 
+        '&laquo;'.trigger_event(
+          'render_category_name',
+          $categories[$_GET['smart_generate']]['name'],
+          'admin_cat_list'
+          ).'&raquo;'
+        )
       );
   }
Index: /extensions/SmartAlbums/include/functions.inc.php
===================================================================
--- /extensions/SmartAlbums/include/functions.inc.php	(revision 11545)
+++ /extensions/SmartAlbums/include/functions.inc.php	(revision 11546)
@@ -9,5 +9,11 @@
 function smart_make_associations($cat_id)
 {
-  pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;');
+  $query = '
+DELETE FROM '.IMAGE_CATEGORY_TABLE.' 
+  WHERE 
+    category_id = '.$cat_id.' 
+    AND smart = true
+;';
+  pwg_query($query);
   
   $images = smart_get_pictures($cat_id);
@@ -30,9 +36,20 @@
   }
   
-  if (!function_exists('set_random_representant'))
-  {
-    include(PHPWG_ROOT_PATH.'admin/include/functions.php');
-  }
-  set_random_representant(array($cat_id));
+  // represantant, try to not overwrite if still in images list
+  $query = '
+SELECT representative_picture_id
+  FROM '.CATEGORIES_TABLE.'
+  WHERE id = '.$cat_id.'
+;';
+  list($rep_id) = pwg_db_fetch_row(pwg_query($query));
+  
+  if ( !in_array($rep_id, $images) )
+  {
+    if (!function_exists('set_random_representant'))
+    {
+      include(PHPWG_ROOT_PATH.'admin/include/functions.php');
+    }
+    set_random_representant(array($cat_id));
+  }
   
   return $images;
@@ -79,4 +96,6 @@
   if ($filters == null)
   {
+    $filters = array();
+    
     $query = '
 SELECT * 
@@ -85,18 +104,16 @@
   ORDER BY type ASC, cond ASC
 ;';
-    $filters = pwg_query($query);
-    
-    if (!pwg_db_num_rows($filters)) return array();
-    
-    while ($filter = pwg_db_fetch_assoc($filters))
-    {
-      $temp[] = array(
-        'type' => $filter['type'],
-        'cond' => $filter['cond'],
-        'value' => $filter['value'],
+    $result = pwg_query($query);
+    
+    if (!pwg_db_num_rows($result)) return $filters;
+    
+    while ($row = pwg_db_fetch_assoc($result))
+    {
+      $filters[] = array(
+        'type' => $row['type'],
+        'cond' => $row['cond'],
+        'value' => $row['value'],
         );
     }
-     
-    $filters = $temp;
   }
     
@@ -110,24 +127,24 @@
     if ($filter['type'] == 'tags')
     {
-        if($filter['cond'] == "all")
-        {
-          $tags_arr = explode(',', $filter['value']);
-          
-          foreach($tags_arr as $value)
-          {
-            $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
-            $where[] = 'it_'.$i_tags.'.tag_id = '.$value;
-            $i_tags++;
-          }
-        }
-        else if ($filter['cond'] == 'one') 
+      if($filter['cond'] == "all")
+      {
+        $tags_arr = explode(',', $filter['value']);
+        
+        foreach($tags_arr as $value)
         {
           $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
-          $where[] = 'it_'.$i_tags.'.tag_id IN ('.$filter['value'].')';
+          $where[] = 'it_'.$i_tags.'.tag_id = '.$value;
           $i_tags++;
         }
-        else if ($filter['cond'] == 'none') 
-        {
-          $sub_query = '
+      }
+      else if ($filter['cond'] == 'one') 
+      {
+        $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
+        $where[] = 'it_'.$i_tags.'.tag_id IN ('.$filter['value'].')';
+        $i_tags++;
+      }
+      else if ($filter['cond'] == 'none') 
+      {
+        $sub_query = '
       SELECT it_'.$i_tags.'.image_id
         FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.'
@@ -137,10 +154,10 @@
         GROUP BY it_'.$i_tags.'.image_id
     ';
-          $where[] = 'NOT EXISTS ('.$sub_query.')';
-          $i_tags++;
-        }
-        else if ($filter['cond'] == 'only') 
-        {
-          $sub_query = '
+        $where[] = 'NOT EXISTS ('.$sub_query.')';
+        $i_tags++;
+      }
+      else if ($filter['cond'] == 'only') 
+      {
+        $sub_query = '
       SELECT it_'.$i_tags.'.image_id
         FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.'
@@ -150,16 +167,16 @@
         GROUP BY it_'.$i_tags.'.image_id
     ';
-          $where[] = 'NOT EXISTS ('.$sub_query.')';
+        $where[] = 'NOT EXISTS ('.$sub_query.')';
+      
+        $i_tags++;
+        $tags_arr = explode(',', $filter['value']);
         
+        foreach($tags_arr as $value)
+        {
+          $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
+          $where[] = 'it_'.$i_tags.'.tag_id = '.$value;
           $i_tags++;
-          $tags_arr = explode(',', $filter['value']);
-          
-          foreach($tags_arr as $value)
-          {
-            $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
-            $where[] = 'it_'.$i_tags.'.tag_id = '.$value;
-            $i_tags++;
-          }
-        }        
+        }
+      }        
     }
     // date
@@ -234,5 +251,4 @@
 /**
  * Check if the filter is proper
- *
  * @param array filter
  * @return array or false
@@ -246,5 +262,5 @@
   if ($filter['type'] == 'tags')
   {
-    if ($filter['value'] == null) // tags fields musn't be null
+    if ($filter['value'] == null)
     {
       $error = true;
@@ -259,5 +275,5 @@
   else if ($filter['type'] == 'date')
   {
-    if (!preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})#', $filter['value'])) // dates must be proper
+    if (!preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})#', $filter['value']))
     {
       $error = true;
@@ -268,5 +284,5 @@
   else if ($filter['type'] == 'limit')
   {
-    if (!preg_match('#([0-9]{1,})#', $filter['value'])) // limit must be an integer
+    if (!preg_match('#([0-9]{1,})#', $filter['value']))
     {
       $error = true;
@@ -298,5 +314,4 @@
 /**
  * inserts multiple lines in a table, ignore duplicate entries
- *
  * @param string table_name
  * @param array dbfields
Index: /extensions/SmartAlbums/include/init_cat_list.php
===================================================================
--- /extensions/SmartAlbums/include/init_cat_list.php	(revision 11545)
+++ /extensions/SmartAlbums/include/init_cat_list.php	(revision 11546)
@@ -44,15 +44,13 @@
         array_push(
           $page['infos'], 
-          l10n_args(get_l10n_args(
-            '%d photos associated to album &laquo;%s&raquo;', 
-            array(
-              count($associated_images), 
-              trigger_event(
-                'render_category_name',
-                $category['name'],
-                'admin_cat_list'
-                )
-              )
-            ))
+          sprintf(
+            l10n('%d photos associated to album %s'), 
+            count($associated_images), 
+            '&laquo;'.trigger_event(
+              'render_category_name',
+              $category['name'],
+              'admin_cat_list'
+              ).'&raquo;'
+            )
           );
       }
@@ -64,15 +62,13 @@
       array_push(
         $page['infos'], 
-        l10n_args(get_l10n_args(
-          '%d photos associated to album &laquo;%s&raquo;', 
-          array(
-            count($associated_images), 
-            trigger_event(
-              'render_category_name',
-              $smart_cats[$_GET['smart_generate']]['name'],
-              'admin_cat_list'
-              )
-            )
-          ))
+        sprintf(
+          l10n('%d photos associated to album %s'), 
+          count($associated_images), 
+          '&laquo;'.trigger_event(
+            'render_category_name',
+            $smart_cats[$_GET['smart_generate']]['name'],
+            'admin_cat_list'
+            ).'&raquo;'
+          )
         );
     }
@@ -113,6 +109,5 @@
   {
     $search[1] = '</ul>
-</form>
-{/if}';
+</form>';
     $replacement[1] = $search[1].'
 <form method="post" action="{$SMART_URL.all}">
Index: /extensions/SmartAlbums/include/init_cat_modify.php
===================================================================
--- /extensions/SmartAlbums/include/init_cat_modify.php	(revision 11545)
+++ /extensions/SmartAlbums/include/init_cat_modify.php	(revision 11546)
@@ -62,4 +62,13 @@
       $associated_images = smart_make_associations($cat_id);
       $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', count($associated_images)));
+      
+      array_push(
+          $page['infos'], 
+          sprintf(
+            l10n('%d photos associated to album %s'), 
+            count($associated_images), 
+            ''
+            )
+          );
       
       define('SMART_NOT_UPDATE', 1);
Index: /extensions/SmartAlbums/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/SmartAlbums/language/en_UK/plugin.lang.php	(revision 11545)
+++ /extensions/SmartAlbums/language/en_UK/plugin.lang.php	(revision 11546)
@@ -1,5 +1,5 @@
 <?php
 
-$lang['%d photos associated to album &laquo;%s&raquo;'] = '%d photos associated to album &laquo;%s&raquo;';
+$lang['%d photos associated to album %s'] = '%d photos associated to album %s';
 $lang['No filter selected'] = 'No filter selected';
 $lang['No tag selected'] = 'No tag selected';
Index: /extensions/SmartAlbums/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/SmartAlbums/language/fr_FR/plugin.lang.php	(revision 11545)
+++ /extensions/SmartAlbums/language/fr_FR/plugin.lang.php	(revision 11546)
@@ -1,5 +1,5 @@
 <?php
 
-$lang['%d photos associated to album &laquo;%s&raquo;'] = '%d photos associées à l\'album &laquo;%s&raquo;';
+$lang['%d photos associated to album %s'] = '%d photos associées à l\'album %s';
 $lang['No filter selected'] = 'Aucun filtre sélectionné';
 $lang['No tag selected'] = 'Aucun tag sélectionné';
Index: /extensions/SmartAlbums/language/it_IT/plugin.lang.php
===================================================================
--- /extensions/SmartAlbums/language/it_IT/plugin.lang.php	(revision 11545)
+++ /extensions/SmartAlbums/language/it_IT/plugin.lang.php	(revision 11546)
@@ -1,5 +1,5 @@
 <?php
 
-$lang['%d photos associated to album &laquo;%s&raquo;'] = '%d foto associate all\'album "%s"';
+$lang['%d photos associated to album %s'] = '%d foto associate all\'album %s';
 $lang['No filter selected'] = 'Nessun filtro selezionato';
 $lang['No tag selected'] = 'Nessun tag selezionato';
Index: /extensions/SmartAlbums/language/lv_LV/plugin.lang.php
===================================================================
--- /extensions/SmartAlbums/language/lv_LV/plugin.lang.php	(revision 11545)
+++ /extensions/SmartAlbums/language/lv_LV/plugin.lang.php	(revision 11546)
@@ -1,5 +1,5 @@
 <?php
 
-$lang['%d photos associated to album «%s»'] = '%d fotogrāfiju saistītas ar albūmu «%s»';
+$lang['%d photos associated to album %s'] = '%d fotogrāfiju saistītas ar albūmu %s';
 $lang['No filter selected'] = 'Nav izvēlēts neviens no filtriem';
 $lang['No tag selected'] = 'Nav izvēlēts neviens no tagiem';
