Index: /extensions/gvideo/include/functions.inc.php
===================================================================
--- /extensions/gvideo/include/functions.inc.php	(revision 17660)
+++ /extensions/gvideo/include/functions.inc.php	(revision 17661)
@@ -239,6 +239,9 @@
       curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-language: en"));
       curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
-      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
-      curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
+      if (!ini_get('safe_mode'))
+      {
+        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+        curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
+      }
       if (strpos($src, 'https://') !== false)
       {
Index: /extensions/gvideo/include/install.inc.php
===================================================================
--- /extensions/gvideo/include/install.inc.php	(revision 17661)
+++ /extensions/gvideo/include/install.inc.php	(revision 17661)
@@ -0,0 +1,238 @@
+<?php
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+global $prefixeTable;
+
+// defined here only because it's more convenient
+define('gvideo_path', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
+define('gvideo_table', $prefixeTable.'image_video');
+
+/**
+ * installation
+ */
+function gvideo_install() 
+{
+  global $conf;
+  
+  // configuration
+  if (empty($conf['gvideo']))
+  {
+    $gvideo_default_config = serialize(array(
+      'autoplay' => 0,
+      'width' => 640,
+      'height' => 360,
+      'vimeo' => array(
+        'title' => 1,
+        'portrait' => 1,
+        'byline' => 1,
+        'color' => '00adef',
+        ),
+      'dailymotion' => array(
+        'logo' => 1,
+        'title' => 1,
+        'color' => 'F7FFFD',
+        ),
+      'youtube' => array(),
+      'wat' => array(),
+      'wideo' => array(),
+      'videobb' => array(),
+      ));
+    
+    conf_update_param('gvideo', $gvideo_default_config);
+    $conf['gvideo'] = $gvideo_default_config;
+  }
+  
+  // create table
+  $query = '
+CREATE TABLE IF NOT EXISTS `'.gvideo_table.'` (
+  `picture_id` mediumint(8) NOT NULL,
+  `url` varchar(255) DEFAULT NULL,
+  `type` varchar(64) NOT NULL,
+  `video_id` varchar(64) NOT NULL,
+  `width` smallint(9) DEFAULT NULL,
+  `height` smallint(9) DEFAULT NULL,
+  `autoplay` tinyint(1) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=utf8
+;';
+  pwg_query($query);
+  
+  // new collumn in images table
+  $result = pwg_query('SHOW COLUMNS FROM '.IMAGES_TABLE.' LIKE "is_gvideo";');
+  if (!pwg_db_num_rows($result))
+  {      
+    pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` ADD `is_gvideo` TINYINT(1) NOT NULL DEFAULT 0;');
+    
+    $query = '
+UPDATE '.IMAGES_TABLE.'
+  SET is_gvideo = 1
+  WHERE id IN(
+    SELECT picture_id FROM '.gvideo_table.'
+    )
+;';
+    pwg_query($query);
+  }
+  
+  // remove old configuration and upgrade video files
+  if (isset($conf['PY_GVideo']))
+  {
+    pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "PY_GVideo" LIMIT 1;');
+    unset($conf['PY_GVideo']);
+  
+    gvideo_update_24();
+  }
+}
+
+
+/**
+ * update from 2.3 to 2.4
+ */
+function gvideo_update_24()
+{
+  global $conf;
+  
+  // search existing videos
+  $query = '
+SELECT *
+  FROM '.IMAGES_TABLE.'
+  WHERE
+    file LIKE "%.gvideo"
+    OR file LIKE "%.dm"
+    OR file LIKE "%.ytube"
+    OR file LIKE "%.wideo"
+    OR file LIKE "%.vimeo"
+    OR file LIKE "%.wat"
+;';
+  $result = pwg_query($query);
+  
+  if (!pwg_db_num_rows($result))
+  {
+    return;
+  }
+  
+  if (!isset($conf['prefix_thumbnail']))
+  {
+    $conf['prefix_thumbnail'] = 'TN-';
+  }
+
+  if (!isset($conf['dir_thumbnail']))
+  {
+    $conf['dir_thumbnail'] = 'thumbnail';
+  }
+  
+  set_time_limit(600);
+  include_once(gvideo_path . '/include/functions.inc.php');
+  include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
+  
+  $videos_inserts = array();
+  $images_updates = array();
+  $images_delete = array();
+  
+  while ($img = pwg_db_fetch_assoc($result))
+  {
+    $file_content = file_get_contents($img['path']);
+    list($file['id'], $file['height'], $file['width'], ) = explode('/', $file_content);
+    $file['type'] = get_extension($img['path']);
+    
+    switch ($file['type'])
+    {
+      case 'vimeo':
+        $video = array(
+          'type' => 'vimeo',
+          'url' => 'http://vimeo.com/'.$file['id'],
+          );
+        break;
+      case 'dm':
+        $video = array(
+          'type' => 'dailymotion',
+          'url' => 'http://dailymotion.com/video/'.$file['id'],
+          );
+        break;
+      case 'ytube':
+        $video = array(
+          'type' => 'youtube',
+          'url' => 'http://youtube.com/watch?v='.$file['id'],
+          );
+        break;
+      case 'wideo':
+        $video = array(
+          'type' => 'wideo',
+          'url' => 'http://wideo.fr/video/'.$file['id'].'.html',
+          );
+        break;
+      case 'wat':
+        $video = array(
+          'type' => 'wat',
+          'url' => null,
+          );
+        break;
+      case 'gvideo': // closed
+      default:
+        array_push($images_delete, $img['id']);
+        continue;
+    }
+    
+    $real_path = str_replace($img['file'], null, str_replace('././', './', $img['path']));
+    
+    // get existing thumbnail
+    $thumb = $real_path.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'].get_filename_wo_extension($img['file']).'.*';
+    $thumb = glob($thumb);
+    if (!empty($thumb))
+    {
+      $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.'.get_extension($thumb[0]);
+      $thumb_source = $conf['data_location'].$thumb_name;
+      copy($thumb[0], $thumb_source);
+    }
+    else
+    {
+      $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.jpg';
+      $thumb_source = $conf['data_location'].$thumb_name;
+      copy(gvideo_path.'mimetypes/'.$video['type'].'.jpg', $thumb_source);
+      add_film_frame($thumb_source);
+    }
+    
+    // update element
+    $image_id = add_uploaded_file($thumb_source, $thumb_name, null, null, $img['id']);
+    
+    // update path and rename the file
+    $img['new_path'] = $real_path.$thumb_name;
+    rename($img['path'], $img['new_path']);
+    array_push($images_updates, array(
+      'id' => $img['id'],
+      'path' => $img['new_path'],
+      'is_gvideo' => 1,
+      ));
+    
+    if (empty($file['width'])) $file['width'] = '';
+    if (empty($file['height'])) $file['height'] = '';
+    
+    // register video    
+    array_push($videos_inserts, array(
+      'picture_id' => $image_id,
+      'url' => $video['url'],
+      'type' => $video['type'],
+      'video_id' => $file['id'],
+      'width' => $file['width'],
+      'height' => $file['height'],
+      'autoplay' => '',
+      ));
+      
+    unset($thumb_source, $thumb_name, $file, $video, $url);
+  }
+  
+  // delete obsolete elements
+  delete_elements($images_delete);
+  
+  // registers videos
+  mass_inserts(
+    gvideo_table,
+    array('picture_id', 'url', 'type', 'video_id', 'width', 'height', 'autoplay'),
+    $videos_inserts
+    );
+    
+  // update images
+  mass_updates(
+    IMAGES_TABLE,
+    array('primary'=>array('id'), 'update'=>array('path', 'is_gvideo')),
+    $images_updates
+    );
+}
Index: /extensions/gvideo/main.inc.php
===================================================================
--- /extensions/gvideo/main.inc.php	(revision 17660)
+++ /extensions/gvideo/main.inc.php	(revision 17661)
@@ -13,10 +13,11 @@
 global $prefixeTable;
 
-define('GVIDEO_PATH', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
-define('GVIDEO_ADMIN', get_root_url() . 'admin.php?page=plugin-' . basename(dirname(__FILE__)));
-define('GVIDEO_TABLE', $prefixeTable.'image_video');
+define('GVIDEO_PATH',    PHPWG_PLUGINS_PATH . 'gvideo/');
+define('GVIDEO_ADMIN',   get_root_url() . 'admin.php?page=plugin-gvideo');
+define('GVIDEO_TABLE',   $prefixeTable.'image_video');
+define('GVIDEO_VERSION', '2.4.c');
 
-include(GVIDEO_PATH . 'include/gvideo.inc.php');
 
+add_event_handler('init', 'gvideo_init');
 add_event_handler('render_element_content', 'gvideo_element_content', EVENT_HANDLER_PRIORITY_NEUTRAL-10, 2);
 
@@ -26,44 +27,82 @@
   add_event_handler('get_admin_plugin_menu_links', 'gvideo_admin_menu');
   add_event_handler('tabsheet_before_select','gvideo_tab', EVENT_HANDLER_PRIORITY_NEUTRAL+10, 2); 
-  add_event_handler('init', 'gvideo_init');
+}
+
+include_once(GVIDEO_PATH . 'include/gvideo.inc.php');
+
+
+/**
+ * update & load language
+ */
+function gvideo_init()
+{
+  global $pwg_loaded_plugins;
   
-  function gvideo_init()
+  if (
+    $pwg_loaded_plugins['gvideo']['version'] == 'auto' or
+    version_compare($pwg_loaded_plugins['gvideo']['version'], GVIDEO_VERSION, '<')
+  )
   {
-    load_language('plugin.lang', GVIDEO_PATH);
-  }
-
-  function gvideo_admin_menu($menu) 
-  {
-    array_push($menu, array(
-      'NAME' => 'Embedded Videos',
-      'URL' => GVIDEO_ADMIN,
-    ));
-    return $menu;
+    include_once(GVIDEO_PATH . 'include/install.inc.php');
+    gvideo_install();
+    
+    if ($pwg_loaded_plugins['gvideo']['version'] != 'auto')
+    {
+      $query = '
+UPDATE '. PLUGINS_TABLE .'
+SET version = "'. GVIDEO_VERSION .'"
+WHERE id = "gvideo"';
+      pwg_query($query);
+      
+      $pwg_loaded_plugins['gvideo']['version'] = GVIDEO_VERSION;
+      
+      if (defined('IN_ADMIN'))
+      {
+        $_SESSION['page_infos'][] = 'Embedded Videos updated to version '. GVIDEO_VERSION;
+      }
+    }
   }
   
-  function gvideo_tab($sheets, $id)
-  {
-    if ($id != 'photo') return $sheets;
-    
-    $query = '
+  load_language('plugin.lang', GVIDEO_PATH);
+}
+
+/**
+ * admin plugins menu
+ */
+function gvideo_admin_menu($menu) 
+{
+  array_push($menu, array(
+    'NAME' => 'Embedded Videos',
+    'URL' => GVIDEO_ADMIN,
+  ));
+  return $menu;
+}
+
+/**
+ * special tabs
+ */
+function gvideo_tab($sheets, $id)
+{
+  if ($id != 'photo') return $sheets;
+  
+  $query = '
 SELECT *
   FROM '.GVIDEO_TABLE.'
   WHERE picture_id = '.$_GET['image_id'].'
 ;';
-    $result = pwg_query($query);
+  $result = pwg_query($query);
+
+  if (!pwg_db_num_rows($result)) return $sheets;
   
-    if (!pwg_db_num_rows($result)) return $sheets;
-    
-    global $gvideo;
-    $gvideo = pwg_db_fetch_assoc($result);
-    
-    $sheets['gvideo'] = array(
-      'caption' => l10n('Video properties'),
-      'url' => GVIDEO_ADMIN.'-photo&amp;image_id='.$_GET['image_id'],
-      );
-    unset($sheets['coi'], $sheets['update']);
-    
-    return $sheets;
-  }
+  global $gvideo;
+  $gvideo = pwg_db_fetch_assoc($result);
+  
+  $sheets['gvideo'] = array(
+    'caption' => l10n('Video properties'),
+    'url' => GVIDEO_ADMIN.'-photo&amp;image_id='.$_GET['image_id'],
+    );
+  unset($sheets['coi'], $sheets['update']);
+  
+  return $sheets;
 }
 
Index: /extensions/gvideo/maintain.inc.php
===================================================================
--- /extensions/gvideo/maintain.inc.php	(revision 17660)
+++ /extensions/gvideo/maintain.inc.php	(revision 17661)
@@ -2,62 +2,12 @@
 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
 
-global $prefixeTable;
-
-define('gvideo_path', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
-define('gvideo_table', $prefixeTable.'image_video');
-
-define(
-  'gvideo_default_config', 
-  serialize(array(
-    'autoplay' => 0,
-    'width' => 640,
-    'height' => 360,
-    'vimeo' => array(
-      'title' => 1,
-      'portrait' => 1,
-      'byline' => 1,
-      'color' => '00adef',
-      ),
-    'dailymotion' => array(
-      'logo' => 1,
-      'title' => 1,
-      'color' => 'F7FFFD',
-      ),
-    'youtube' => array(),
-    'wat' => array(),
-    'wideo' => array(),
-    'videobb' => array(),
-    ))
-  );
+include_once(PHPWG_PLUGINS_PATH . 'gvideo/include/install.inc.php');
 
 /* install */
 function plugin_install() 
 {
-  global $conf;
+  gvideo_install();
   
-  conf_update_param('gvideo', gvideo_default_config);
-  
-  $query = '
-CREATE TABLE IF NOT EXISTS `'.gvideo_table.'` (
-  `picture_id` mediumint(8) NOT NULL,
-  `url` varchar(255) DEFAULT NULL,
-  `type` varchar(64) NOT NULL,
-  `video_id` varchar(64) NOT NULL,
-  `width` smallint(9) DEFAULT NULL,
-  `height` smallint(9) DEFAULT NULL,
-  `autoplay` tinyint(1) DEFAULT NULL
-) ENGINE=MyISAM DEFAULT CHARSET=utf8
-;';
-  pwg_query($query);
-  
-  pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` ADD `is_gvideo` TINYINT(1) NOT NULL DEFAULT 0;');
-  
-  if (isset($conf['PY_GVideo']))
-  {
-    pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "PY_GVideo" LIMIT 1;');
-    unset($conf['PY_GVideo']);
-  
-    gvideo_update_24();
-  }
+  define('gvideo_installed', true);
 }
 
@@ -65,37 +15,7 @@
 function plugin_activate()
 {
-  global $conf;
-    
-  if (isset($conf['PY_GVideo']))
+  if (!defined('gvideo_installed'))
   {
-    plugin_install();
-  }
-  else 
-  {
-    if (!isset($conf['gvideo']))
-    {
-      conf_update_param('gvideo', gvideo_default_config);
-    }
-    
-    $result = pwg_query('SHOW COLUMNS FROM '.gvideo_table.' LIKE "url";');
-    if (!pwg_db_num_rows($result))
-    {      
-      pwg_query('ALTER TABLE '.gvideo_table.' ADD `url` VARCHAR(255) DEFAULT NULL;');
-    }
-    
-    $result = pwg_query('SHOW COLUMNS FROM '.IMAGES_TABLE.' LIKE "is_gvideo";');
-    if (!pwg_db_num_rows($result))
-    {      
-      pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` ADD `is_gvideo` TINYINT(1) NOT NULL DEFAULT 0;');
-      
-      $query = '
-UPDATE '.IMAGES_TABLE.'
-  SET is_gvideo = 1
-  WHERE id IN(
-    SELECT picture_id FROM '.gvideo_table.'
-    )
-;';
-      pwg_query($query);
-    }
+    gvideo_install();
   }
 }
@@ -103,164 +23,11 @@
 /* uninstall */
 function plugin_uninstall() 
-{  
+{
+  global $prefixeTable;
+  
   pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "gvideo" LIMIT 1;');
-  pwg_query('DROP TABLE `'.gvideo_table.'`;');
+  pwg_query('DROP TABLE `'.$prefixeTable.'image_video`;');
   pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` DROP `is_gvideo`;');
 }
 
-
-/**
- * update from 2.3 to 2.4
- */
-function gvideo_update_24()
-{
-  global $conf;
-  
-  // search existing videos
-  $query = '
-SELECT *
-  FROM '.IMAGES_TABLE.'
-  WHERE
-    file LIKE "%.gvideo"
-    OR file LIKE "%.dm"
-    OR file LIKE "%.ytube"
-    OR file LIKE "%.wideo"
-    OR file LIKE "%.vimeo"
-    OR file LIKE "%.wat"
-;';
-  $result = pwg_query($query);
-  
-  if (!pwg_db_num_rows($result))
-  {
-    return;
-  }
-  
-  if (!isset($conf['prefix_thumbnail']))
-  {
-    $conf['prefix_thumbnail'] = 'TN-';
-  }
-
-  if (!isset($conf['dir_thumbnail']))
-  {
-    $conf['dir_thumbnail'] = 'thumbnail';
-  }
-  
-  set_time_limit(600);
-  include_once(gvideo_path . '/include/functions.inc.php');
-  include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
-  
-  $videos_inserts = array();
-  $images_updates = array();
-  $images_delete = array();
-  
-  while ($img = pwg_db_fetch_assoc($result))
-  {
-    $file_content = file_get_contents($img['path']);
-    list($file['id'], $file['height'], $file['width'], ) = explode('/', $file_content);
-    $file['type'] = get_extension($img['path']);
-    
-    switch ($file['type'])
-    {
-      case 'vimeo':
-        $video = array(
-          'type' => 'vimeo',
-          'url' => 'http://vimeo.com/'.$file['id'],
-          );
-        break;
-      case 'dm':
-        $video = array(
-          'type' => 'dailymotion',
-          'url' => 'http://dailymotion.com/video/'.$file['id'],
-          );
-        break;
-      case 'ytube':
-        $video = array(
-          'type' => 'youtube',
-          'url' => 'http://youtube.com/watch?v='.$file['id'],
-          );
-        break;
-      case 'wideo':
-        $video = array(
-          'type' => 'wideo',
-          'url' => 'http://wideo.fr/video/'.$file['id'].'.html',
-          );
-        break;
-      case 'wat':
-        $video = array(
-          'type' => 'wat',
-          'url' => null,
-          );
-        break;
-      case 'gvideo': // closed
-      default:
-        array_push($images_delete, $img['id']);
-        continue;
-    }
-    
-    $real_path = str_replace($img['file'], null, str_replace('././', './', $img['path']));
-    
-    // get existing thumbnail
-    $thumb = $real_path.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'].get_filename_wo_extension($img['file']).'.*';
-    $thumb = glob($thumb);
-    if (!empty($thumb))
-    {
-      $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.'.get_extension($thumb[0]);
-      $thumb_source = $conf['data_location'].$thumb_name;
-      copy($thumb[0], $thumb_source);
-    }
-    else
-    {
-      $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.jpg';
-      $thumb_source = $conf['data_location'].$thumb_name;
-      copy(gvideo_path.'mimetypes/'.$video['type'].'.jpg', $thumb_source);
-      add_film_frame($thumb_source);
-    }
-    
-    // update element
-    $image_id = add_uploaded_file($thumb_source, $thumb_name, null, null, $img['id']);
-    
-    // update path and rename the file
-    $img['new_path'] = $real_path.$thumb_name;
-    rename($img['path'], $img['new_path']);
-    array_push($images_updates, array(
-      'id' => $img['id'],
-      'path' => $img['new_path'],
-      'is_gvideo' => 1,
-      ));
-    
-    if (empty($file['width'])) $file['width'] = '';
-    if (empty($file['height'])) $file['height'] = '';
-    
-    // register video    
-    array_push($videos_inserts, array(
-      'picture_id' => $image_id,
-      'url' => $video['url'],
-      'type' => $video['type'],
-      'video_id' => $file['id'],
-      'width' => $file['width'],
-      'height' => $file['height'],
-      'autoplay' => '',
-      ));
-      
-    unset($thumb_source, $thumb_name, $file, $video, $url);
-  }
-  
-  // delete obsolete elements
-  delete_elements($images_delete);
-  
-  // registers videos
-  mass_inserts(
-    gvideo_table,
-    array('picture_id', 'url', 'type', 'video_id', 'width', 'height', 'autoplay'),
-    $videos_inserts
-    );
-    
-  // update images
-  mass_updates(
-    IMAGES_TABLE,
-    array('primary'=>array('id'), 'update'=>array('path', 'is_gvideo')),
-    $images_updates
-    );
-}
-
 ?>
