Index: extensions/Comments_on_Albums/include/coa_albums.php
===================================================================
--- extensions/Comments_on_Albums/include/coa_albums.php	(revision 12618)
+++ extensions/Comments_on_Albums/include/coa_albums.php	(revision 14528)
@@ -27,10 +27,6 @@
     case 'edit_comment' : 
     {
-      check_pwg_token();
-      
       include_once(COA_PATH.'include/functions_comment.inc.php'); // custom fonctions
-      
       check_input_parameter('comment_to_edit', $_GET, false, PATTERN_ID);
-      
       $author_id = get_comment_author_id_albums($_GET['comment_to_edit']);
 
@@ -39,4 +35,5 @@
         if (!empty($_POST['content'])) 
         {
+          check_pwg_token();
           $comment_action = update_user_comment_albums(
             array(
@@ -48,16 +45,16 @@
             );
           
-          $infos = array();
-          
+          $perform_redirect = false;
           switch ($comment_action)
           {
             case 'moderate':
-              array_push($infos, l10n('An administrator must authorize your comment before it is visible.'));
+              $_SESSION['page_infos'][] = l10n('An administrator must authorize your comment before it is visible.');
             case 'validate':
-              array_push($infos, l10n('Your comment has been registered'));
+              $_SESSION['page_infos'][] = l10n('Your comment has been registered');
+              $perform_redirect = true;
               break;
             case 'reject':
-              set_status_header(403);
-              array_push($infos, l10n('Your comment has NOT been registered because it did not pass the validation rules'));
+              $_SESSION['page_errors'][] = l10n('Your comment has NOT been registered because it did not pass the validation rules');
+              $perform_redirect = true;
               break;
             default:
@@ -65,17 +62,15 @@
           }
 
-          $template->assign(
-              ($comment_action=='reject') ? 'errors' : 'infos',
-              $infos
-            );
-
+          if ($perform_redirect)
+          {
+            redirect($url_self);
+          }
           unset($_POST['content']);
-          break;
         } 
         else 
         {
           $edit_comment = $_GET['comment_to_edit'];
-          break;
         }
+        break;
       }
     }
@@ -84,5 +79,5 @@
       check_pwg_token();
       
-      include_once(COA_PATH.'include/functions_comment.inc.php');
+      include_once(COA_PATH.'include/functions_comment.inc.php'); // custom fonctions
       
       check_input_parameter('comment_to_delete', $_GET, false, PATTERN_ID);
@@ -101,5 +96,5 @@
       check_pwg_token();
       
-      include_once(COA_PATH.'include/functions_comment.inc.php');
+      include_once(COA_PATH.'include/functions_comment.inc.php'); // custom fonctions
       
       check_input_parameter('comment_to_validate', $_GET, false, PATTERN_ID);
@@ -116,4 +111,5 @@
   }
 }
+
 
 // +-----------------------------------------------------------------------+
@@ -133,27 +129,22 @@
   );
 
-  include_once(COA_PATH.'include/functions_comment.inc.php');
+  include_once(COA_PATH.'include/functions_comment.inc.php'); // custom fonctions
   
-  $comment_action = insert_user_comment_albums($comm, @$_POST['key'], $infos);
+  $comment_action = insert_user_comment_albums($comm, @$_POST['key'], $page['infos']);
 
   switch ($comment_action) 
   {
     case 'moderate':
-      array_push($infos, l10n('An administrator must authorize your comment before it is visible.'));
+      array_push($page['infos'], l10n('An administrator must authorize your comment before it is visible.'));
     case 'validate':
-      array_push($infos, l10n('Your comment has been registered'));
+      array_push($page['infos'], l10n('Your comment has been registered'));
       break;
     case 'reject':
       set_status_header(403);
-      array_push($infos, l10n('Your comment has NOT been registered because it did not pass the validation rules'));
+      array_push($page['errors'], l10n('Your comment has NOT been registered because it did not pass the validation rules'));
       break;
     default:
       trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
   }
-
-  $template->assign(
-      ($comment_action=='reject') ? 'errors' : 'infos',
-      $infos
-    );
     
   // allow plugins to notify what's going on
@@ -161,5 +152,6 @@
       array_merge($comm, array('action'=>$comment_action) )
     );
-  
+    
+  $template->assign('DISPLAY_COMMENTS_BLOCK', true);
 } 
 else if (isset($_POST['content'])) 
@@ -194,5 +186,5 @@
   $row = pwg_db_fetch_assoc(pwg_query($query));
 
-  // navigation bar creation, custom again
+  // navigation bar creation, can't use $_GET['start'] because used by thumbnails navigation bar
   if (isset($_GET['start_comments'])) 
   {
@@ -203,5 +195,5 @@
     $page['start_comments'] = 0;
   }
-  include_once(COA_PATH.'include/functions.inc.php');
+  include_once(COA_PATH.'include/functions.inc.php'); // custom fonctions
 
   $navigation_bar = create_comment_navigation_bar(
@@ -221,4 +213,16 @@
   if ($row['nb_comments'] > 0) 
   {
+    // comments order (get, session, conf)
+    if (!empty($_GET['comments_order']) && in_array(strtoupper($_GET['comments_order']), array('ASC', 'DESC')))
+    {
+      pwg_set_session_var('comments_order', $_GET['comments_order']);
+    }
+    $comments_order = pwg_get_session_var('comments_order', $conf['comments_order']);
+
+    $template->assign(array(
+      'COMMENTS_ORDER_URL' => add_url_params( duplicate_index_url(), array('comments_order'=> ($comments_order == 'ASC' ? 'DESC' : 'ASC') ) ),
+      'COMMENTS_ORDER_TITLE' => $comments_order == 'ASC' ? l10n('Show latest comments first') : l10n('Show oldest comments first'),
+      ));
+      
     // get comments
     $query = '
@@ -237,5 +241,5 @@
   WHERE category_id = '.$category['id'].'
     '.$validated_clause.'
-  ORDER BY date ASC
+  ORDER BY date '.$comments_order.'
   LIMIT '.$conf['nb_comment_page'].' OFFSET '.$page['start_comments'].'
 ;';
@@ -285,13 +289,13 @@
             'action' => 'edit_comment',
             'comment_to_edit' => $row['id'],
-            'pwg_token' => get_pwg_token(),
             )
           );
         if (isset($edit_comment) and ($row['id'] == $edit_comment)) 
         {
+          $tpl_comment['IN_EDIT'] = true;
           $key = get_ephemeral_key(2, $category['id']);
-          $tpl_comment['IN_EDIT'] = true;
           $tpl_comment['KEY'] = $key;
           $tpl_comment['CONTENT'] = $row['content'];
+          $tpl_comment['PWG_TOKEN'] = get_pwg_token();
         }
       }
@@ -331,6 +335,5 @@
       $content = htmlspecialchars(stripslashes($comm['content']));
     }
-    $template->assign(
-      'comment_add', 
+    $template->assign('comment_add', 
       array(
         'F_ACTION' => $url_self,
@@ -343,51 +346,18 @@
   
   // template
-  $template->assign(
-    array(
-      'COA_PATH' => COA_PATH, // for css
-      'COA_ABSOLUTE_PATH' => dirname(__FILE__) .'/../', // for template
-      )
-    );
+  $template->assign(array(
+    'COA_PATH' => COA_PATH, // for css
+    'COA_ABSOLUTE_PATH' => dirname(__FILE__) .'/../', // for template
+    ));
   
-  global $user;
-  if ( $is_simple = strstr($user['theme'], 'simple') !== false or strstr($user['theme'], 'stripped') !== false )
-  {
-    $template->assign('IS_SIMPLE', $is_simple);
-    $template->set_filename('comments_on_albums', dirname(__FILE__) .'/../template/albums_simple.tpl');
+  $template->set_filename('comments_on_albums', dirname(__FILE__) .'/../template/albums.tpl');
+  if (isset($pwg_loaded_plugins['rv_tscroller']) AND count($page['navigation_bar']) != 0)
+  {
+    $template->assign('COMMENTS_ON_TOP', true);
+    $template->concat('PLUGIN_INDEX_CONTENT_BEGIN', $template->parse('comments_on_albums', true));
   }
   else
   {
-    $template->set_filename('comments_on_albums', dirname(__FILE__) .'/../template/albums.tpl');
-  }
-  $template->concat('PLUGIN_INDEX_CONTENT_END', $template->parse('comments_on_albums', true));
-  
-  if (isset($infos))
-  {
-    $template->set_prefilter('index', 'coa_messages');
-  }
-  
-  function coa_messages($content, &$smarty) 
-  {
-    $replacement = '
-{if !empty($errors)}
-<div class="errors">
-  <ul>
-    {foreach from=$errors item=error}
-    <li>{$error}</li>
-    {/foreach}
-  </ul>
-</div>
-{/if}
-{if !empty($infos)}
-<div class="infos">
-  <ul>
-    {foreach from=$infos item=info}
-    <li>{$info}</li>
-    {/foreach}
-  </ul>
-</div>
-{/if}';
-
-    return str_replace('{$MENUBAR}', $replacement.'{$MENUBAR}', $content);
+    $template->concat('PLUGIN_INDEX_CONTENT_END', $template->parse('comments_on_albums', true));
   }
 }
