Index: /extensions/linked_pages/include/functions.inc.php
===================================================================
--- /extensions/linked_pages/include/functions.inc.php	(revision 27041)
+++ /extensions/linked_pages/include/functions.inc.php	(revision 27042)
@@ -25,5 +25,5 @@
   global $page, $user, $template, $conf;
   
-  if ( isset($page['section']) and $page['section']=='categories' and isset($page['category']) )
+  if (isset($page['section']) and $page['section']=='categories' and isset($page['category']))
   {
     $where_clauses = array('category_id = '.$page['category']['id']);
@@ -50,5 +50,5 @@
   WHERE user_id = '.$user['id'].'
 ;';
-        $user_groups = array_from_query($query, 'group_id');
+        $user_groups = query2array($query, null, 'group_id');
       }
     }
@@ -78,5 +78,5 @@
     while ($row = pwg_db_fetch_assoc($result))
     {
-      if ( !is_admin() and $conf['AP']['group_perm'] and !empty($row['groups']) )
+      if (!is_admin() and $conf['AP']['group_perm'] and !empty($row['groups']))
       {
         $authorized = false;
@@ -91,5 +91,4 @@
         if (!$authorized) continue;
       }
-        
       
       $row['U_PAGE'] = make_index_url(array('section'=>'page')).'/'.(isset($row['permalink']) ? $row['permalink'] : $row['page_id']);
@@ -99,8 +98,9 @@
     
     $template->assign('LINKEDPAGES_PATH', LINKEDPAGES_PATH);
-    $template->set_prefilter('index', 'linked_pages_prefilter_index');
+    $template->set_filename('linked_pages_content', realpath(LINKEDPAGES_PATH . 'template/index_menu.tpl'));
+    $template->assign('PLUGIN_INDEX_CONTENT_BEGIN', $template->parse('linked_pages_content',true).$template->get_template_vars('PLUGIN_INDEX_CONTENT_BEGIN'));
     
   }
-  else if ( isset($page['section']) and $page['section']=='additional_page' and isset($page['additional_page']) )
+  else if (isset($page['section']) and $page['section']=='additional_page' and isset($page['additional_page']))
   {
     $where_clauses = array('page_id = '.$page['additional_page']['id']);
@@ -150,12 +150,2 @@
   }
 }
-
-function linked_pages_prefilter_index($content)
-{
-  $search = '#(</div>{\* <!-- titrePage --> \*}|<div id="subcontent">|<div class="subcontent">)#';
-  $replace = "$1\n".file_get_contents(LINKEDPAGES_PATH . 'template/index_menu.tpl');
-  return preg_replace($search, $replace, $content);
-}
-
-
-?>
Index: tensions/linked_pages/include/install.inc.php
===================================================================
--- /extensions/linked_pages/include/install.inc.php	(revision 27041)
+++ 	(revision )
@@ -1,18 +1,0 @@
-<?php
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
-
-function linked_pages_install() 
-{
-  global $prefixeTable;
-  
-	pwg_query('
-CREATE TABLE IF NOT EXISTS `'.$prefixeTable.'linked_pages` (
-  `page_id` smallint(5) unsigned NOT NULL,
-  `category_id` smallint(5) unsigned NOT NULL,
-  `pos` smallint(5) unsigned NOT NULL,
-  UNIQUE KEY `UNIQUE`(`page_id`,`category_id`)
-) DEFAULT CHARSET=utf8
-;');
-}
-
-?>
Index: /extensions/linked_pages/main.inc.php
===================================================================
--- /extensions/linked_pages/main.inc.php	(revision 27041)
+++ /extensions/linked_pages/main.inc.php	(revision 27042)
@@ -9,5 +9,5 @@
 */
 
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
 
 if (mobile_theme())
@@ -21,5 +21,5 @@
 // | Define plugin constants                                               |
 // +-----------------------------------------------------------------------+
-defined('LINKEDPAGES_ID') or define('LINKEDPAGES_ID', basename(dirname(__FILE__)));
+define('LINKEDPAGES_ID',      basename(dirname(__FILE__)));
 define('LINKEDPAGES_PATH' ,   PHPWG_PLUGINS_PATH . LINKEDPAGES_ID . '/');
 define('LINKEDPAGES_TABLE',   $prefixeTable . 'linked_pages');
@@ -44,4 +44,8 @@
   }
   
+  include_once(LINKEDPAGES_PATH . 'maintain.inc.php');
+  $maintain = new linked_pages_maintain(LINKEDPAGES_ID);
+  $maintain->autoUpdate(LINKEDPAGES_VERSION, 'install');
+  
   // add event handlers
   if (defined('IN_ADMIN'))
@@ -55,31 +59,3 @@
 
   include_once(LINKEDPAGES_PATH . 'include/functions.inc.php');
-  
-  if (
-    LINKEDPAGES_VERSION == 'auto' or
-    $pwg_loaded_plugins[LINKEDPAGES_ID]['version'] == 'auto' or
-    version_compare($pwg_loaded_plugins[LINKEDPAGES_ID]['version'], LINKEDPAGES_VERSION, '<')
-  )
-  {
-    include_once(LINKEDPAGES_PATH . 'include/install.inc.php');
-    linked_pages_install();
-    
-    if ( $pwg_loaded_plugins[LINKEDPAGES_ID]['version'] != 'auto' and LINKEDPAGES_VERSION != 'auto')
-    {
-      $query = '
-UPDATE '. PLUGINS_TABLE .'
-SET version = "'. LINKEDPAGES_VERSION .'"
-WHERE id = "'. LINKEDPAGES_ID .'"';
-      pwg_query($query);
-      
-      $pwg_loaded_plugins[LINKEDPAGES_ID]['version'] = LINKEDPAGES_VERSION;
-      
-      if (defined('IN_ADMIN'))
-      {
-        $_SESSION['page_infos'][] = 'Linked Pages updated to version '. LINKEDPAGES_VERSION;
-      }
-    }
-  }
 }
-
-?>
Index: /extensions/linked_pages/maintain.inc.php
===================================================================
--- /extensions/linked_pages/maintain.inc.php	(revision 27041)
+++ /extensions/linked_pages/maintain.inc.php	(revision 27042)
@@ -1,31 +1,42 @@
 <?php
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
 
-defined('LINKEDPAGES_ID') or define('LINKEDPAGES_ID', basename(dirname(__FILE__)));
-include_once(PHPWG_PLUGINS_PATH . LINKEDPAGES_ID . '/include/install.inc.php');
+class linked_pages_maintain extends PluginMaintain
+{
+  private $installed = false;
 
+  function install($plugin_version, &$errors=array())
+  {
+    global $prefixeTable;
 
-function plugin_install() 
-{
-  linked_pages_install();
-  define('linked_pages_installed', true);
-}
+    pwg_query('
+CREATE TABLE IF NOT EXISTS `'.$prefixeTable.'linked_pages` (
+  `page_id` smallint(5) unsigned NOT NULL,
+  `category_id` smallint(5) unsigned NOT NULL,
+  `pos` smallint(5) unsigned NOT NULL,
+  UNIQUE KEY `UNIQUE`(`page_id`,`category_id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8
+;');
 
+    $this->installed = true;
+  }
 
-function plugin_activate()
-{
-  if (!defined('linked_pages_installed'))
+  function activate($plugin_version, &$errors=array())
   {
-    linked_pages_install();
+    if (!$this->installed)
+    {
+      $this->install($plugin_version, $errors);
+    }
+  }
+
+  function deactivate()
+  {
+  }
+
+  function uninstall()
+  {
+    global $prefixeTable;
+    
+    pwg_query('DROP TABLE `'.$prefixeTable.'linked_pages`;');
   }
 }
-
-
-function plugin_uninstall() 
-{
-  global $prefixeTable;
-  
-  pwg_query('DROP TABLE `'.$prefixeTable.'linked_pages`;');
-}
-
-?>
Index: /extensions/linked_pages/template/admin_album.tpl
===================================================================
--- /extensions/linked_pages/template/admin_album.tpl	(revision 27041)
+++ /extensions/linked_pages/template/admin_album.tpl	(revision 27042)
@@ -1,72 +1,68 @@
-{footer_script require='jquery.ui.sortable'}{literal}
-function init_handlers() {
-  jQuery(".menuPos").hide();
-  jQuery(".drag_button").show();
-  jQuery(".menuLi").css("cursor","move");
-  jQuery(".menuUl").sortable({
-    axis: "y",
-    opacity: 0.8
+{combine_script id='jquery.underscore' load='footer' path='themes/default/js/plugins/underscore.js'}
+
+{footer_script require='jquery.ui.sortable'}
+(function($){
+  $("#menuOrdering").submit(function() {
+    $('.menuUl li').each(function(i) {
+      $('.menuPos[name="position[' + $(this).data('id') + ']"]').val(i);
+    });
   });
-  
-  jQuery("#menuOrdering").submit(function() {
-    ar = jQuery('.menuUl').sortable('toArray');
-    for(i=0; i<ar.length; i++) {
-      men = ar[i].split('menu_');
-      document.getElementsByName('position[' + men[1] + ']')[0].value = i;
-    }
-  });
-  
-  $("a.deletePage").click(function() {
-    id = $(this).parents("li.menuLi").attr("id").split("menu_")[1];
+
+  $('.menuUl').on('click', 'a.deletePage', function() {
+    var id = $(this).parents("li.menuLi").data('id');
     $(this).parents("li.menuLi").remove();
     $("select[name='add_page'] option[value='"+ id +"']").removeAttr("disabled");
   });
-}
 
-$("select[name='add_page']").change(function() {
-  if ($(this).val() != -1) {
-    $option = $(this).children("option:selected");
-    
-  {/literal}
-    var html =
-      '<li class="menuLi" id="menu_'+ $(this).val() +'">'+
-        '<p>'+
-          '<span style="margin:2px 5px;">'+
-            '<a href="#" class="deletePage"><img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/category_delete.png" alt="{'delete'|@translate}" title="{'delete'|@translate}"></a>'+
-          '</span>'+
+  function init_sortable() {
+    $(".menuUl").sortable({
+      axis: "y",
+      opacity: 0.8
+    });
+  }
 
-          ' <img src="{$themeconf.admin_icon_dir}/cat_move.png" class="button drag_button" style="display:none;" alt="{'Drag to re-order'|@translate}" title="{'Drag to re-order'|@translate}">'+
-          ' <b><a href="'+ $option.data('href') +'">'+ $option.html() +'</a></b>';
-    if ($option.data('standalone')) html+= ' - {'ap_standalone_page'|@translate}';
-    if ($option.data('language'))   html+= ' <i>('+ $option.data('language')+')</i>';
-    html+=
-        '</p>'+
-        '<p class="menuPos">'+
-          '<label>'+
-            '{'Position'|@translate} :'+
-            ' <input type="text" size="4" name="position['+ $(this).val() +']" maxlength="4" value="0">'+
-          '</label>'+
-        '</p>'+
-      '</li>';
-  {literal}
-      
-    $("ul.menuUl").append(html);
+  var template = _.template($('#lp_template').html());
 
-    $option.attr("disabled", "disabled");
-    $(this).val(-1);
-    init_handlers();
-  }
-});
+  $("select[name='add_page']").change(function() {
+    if ($(this).val() != -1) {
+      var $option = $(this).children("option:selected");
 
-init_handlers();
-{/literal}{/footer_script}
+      $("ul.menuUl").append(template({
+        id: $(this).val(),
+        name: $option.html(),
+        href: $option.data('href'),
+        standalone: $option.data('standalone'),
+        language: $option.data('language')
+      }));
 
-{html_style}{literal}
+      $option.attr("disabled", "disabled");
+      $(this).val(-1);
+      init_sortable();
+    }
+  });
+
+  init_sortable();
+  
+  {foreach from=$cat_pages item=page}
+  $("ul.menuUl").append(template({
+    id: {$page.page_id},
+    name: '{$page.title}',
+    href: '{$page.U_PAGE}',
+    standalone: {$page.standalone},
+    language: '{$page.language}'
+  }));
+  {/foreach}
+}(jQuery));
+{/footer_script}
+
+{html_style}
 #menuOrdering a:hover { border:none; }
-{/literal}{/html_style}
+.menuPos { display:none; }
+.menuLi { cursor:move; }
+{/html_style}
 
 
 <div class="titrePage">
-  <h2><span style="letter-spacing:0">{$CATEGORIES_NAV}</span> &#8250; {'Edit album'|@translate} {$TABSHEET_TITLE}</h2>
+  <h2><span style="letter-spacing:0">{$CATEGORIES_NAV}</span> &#8250; {'Edit album'|translate} {$TABSHEET_TITLE}</h2>
 </div>
 
@@ -74,5 +70,5 @@
 {if count($pages)}
   <p style="margin-bottom:15px;">
-    {'ap_add_page'|@translate}
+    {'ap_add_page'|translate}
     <select name="add_page">
       <option value="-1" selected="selected">------------</option>
@@ -85,37 +81,36 @@
   </p>
 
-  <ul class="menuUl">
-    {foreach from=$cat_pages item=page}
-    <li class="menuLi" id="menu_{$page.page_id}">
-      <p>
-        <span style="margin:2px 5px;">
-          <a href="#" class="deletePage"><img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/category_delete.png" alt="{'delete'|@translate}" title="{'delete'|@translate}"></a>
-        </span>
-
-        <img src="{$themeconf.admin_icon_dir}/cat_move.png" class="button drag_button" style="display:none;" alt="{'Drag to re-order'|@translate}" title="{'Drag to re-order'|@translate}">
-        <b><a href="{$page.U_PAGE}">{$page.title}</a></b>
-        {if $page.standalone == 'true'} - {'ap_standalone_page'|@translate}{/if}
-        {if !empty($page.language)}<i>({$page.language})</i>{/if}
-      </p>
-
-      <p class="menuPos">
-        <label>
-          {'Position'|@translate} :
-          <input type="text" size="4" name="position[{$page.page_id}]" maxlength="4" value="{$page.pos}">
-        </label>
-      </p>
-    </li>
-    {/foreach}
-  </ul>
+  <ul class="menuUl"></ul>
   
   <p class="menuSubmit">
-    <input type="submit" name="save_pages" value="{'Submit'|@translate}">
-    <input type="submit" name="reset" value="{'Reset'|@translate}">
+    <input type="submit" name="save_pages" value="{'Submit'|translate}">
+    <input type="submit" name="reset" value="{'Reset'|translate}">
   </p>
 {/if}
 
 <p style="text-align:left;">
-  <a href="{$AP_ADMIN}">{'ap_add_page'|@translate}</a>
+  <a href="{$AP_ADMIN}">{'ap_add_page'|translate}</a>
 </p>
 
 </form>
+
+<script type="text/template" id="lp_template">
+  <li class="menuLi" data-id=<%= id %>>
+    <p>
+      <span style="margin:2px 5px;">
+        <a href="#" class="deletePage"><img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/category_delete.png" alt="{'delete'|translate}" title="{'delete'|translate}"></a>
+      </span>
+
+      <img src="{$themeconf.admin_icon_dir}/cat_move.png" class="button drag_button" alt="{'Drag to re-order'|translate}" title="{'Drag to re-order'|translate}">
+      <b><a href="<%= href %>"><%= name %></a></b>
+    <% if (standalone) { %>
+      - {'ap_standalone_page'|translate}
+    <% } %>
+    <% if (language) { %>
+      <i>(<%= language %>)</i>
+    <% } %>
+    </p>
+    
+    <input class="menuPos" type="text" size="4" name="position[<%= id %>]" maxlength="4" value="0">
+  </li>
+</script>
Index: /extensions/linked_pages/template/index_menu.tpl
===================================================================
--- /extensions/linked_pages/template/index_menu.tpl	(revision 27041)
+++ /extensions/linked_pages/template/index_menu.tpl	(revision 27042)
@@ -1,3 +1,3 @@
-{combine_css path=$LINKEDPAGES_PATH|@cat:"template/style.css"}
+{combine_css path=$LINKEDPAGES_PATH|cat:"template/style.css"}
 
 <ul id="linked_pages">
Index: /extensions/linked_pages/template/style.css
===================================================================
--- /extensions/linked_pages/template/style.css	(revision 27041)
+++ /extensions/linked_pages/template/style.css	(revision 27042)
@@ -6,5 +6,5 @@
   #linked_pages li {
     display:inline-block;
-    padding:0;
+    padding:0 0 15px 0;
   }
   #linked_pages li a {
