source: extensions/gvideo/maintain.inc.php @ 17310

Last change on this file since 17310 was 17310, checked in by mistic100, 12 years ago

-restore option to add film frame effect (improved)
-update mimetypes to avoid double frames

File size: 5.6 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4global $prefixeTable;
5
6define('gvideo_path', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)));
7define('gvideo_table', $prefixeTable.'image_video');
8
9define(
10  'gvideo_default_config', 
11  serialize(array(
12    'autoplay' => 0,
13    'width' => 640,
14    'height' => 360,
15    'vimeo' => array(
16      'title' => 1,
17      'portrait' => 1,
18      'byline' => 1,
19      'color' => '00adef',
20      ),
21    'dailymotion' => array(
22      'logo' => 1,
23      'title' => 1,
24      'color' => 'F7FFFD',
25      ),
26    'youtube' => array(),
27    'wat' => array(),
28    'wideo' => array(),
29    'videobb' => array(),
30    ))
31  );
32
33
34function plugin_install() 
35{
36  global $conf;
37 
38  conf_update_param('gvideo', gvideo_default_config);
39 
40  $query = '
41CREATE TABLE IF NOT EXISTS `'.gvideo_table.'` (
42  `picture_id` mediumint(8) NOT NULL,
43  `type` varchar(64) NOT NULL,
44  `video_id` varchar(64) NOT NULL,
45  `width` smallint(9) DEFAULT NULL,
46  `height` smallint(9) DEFAULT NULL,
47  `autoplay` tinyint(1) DEFAULT NULL
48) ENGINE=MyISAM DEFAULT CHARSET=utf8
49;';
50  pwg_query($query);
51 
52  if (isset($conf['PY_GVideo']))
53  {
54    pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "PY_GVideo" LIMIT 1;');
55    unset($conf['PY_GVideo']);
56 
57    gvideo_update_24();
58  }
59}
60
61function plugin_activate()
62{
63  global $conf;
64   
65  if (isset($conf['PY_GVideo']))
66  {
67    plugin_install();
68  }
69  else if (!isset($conf['gvideo']))
70  {
71    conf_update_param('gvideo', gvideo_default_config);
72  }
73}
74
75function plugin_uninstall() 
76{ 
77  pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "gvideo" LIMIT 1;');
78  pwg_query('DROP TABLE `'.gvideo_table.'`;');
79}
80
81
82/**
83 * update from 2.3 to 2.4
84 */
85function gvideo_update_24()
86{
87  global $conf;
88 
89  // search existing videos
90  $query = '
91SELECT *
92  FROM '.IMAGES_TABLE.'
93  WHERE
94    file LIKE "%.gvideo"
95    OR file LIKE "%.dm"
96    OR file LIKE "%.ytube"
97    OR file LIKE "%.wideo"
98    OR file LIKE "%.vimeo"
99    OR file LIKE "%.wat"
100;';
101  $result = pwg_query($query);
102 
103  if (!pwg_db_num_rows($result))
104  {
105    return;
106  }
107 
108  set_time_limit(600);
109  include_once(gvideo_path . '/include/functions.inc.php');
110  include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
111 
112  $videos_inserts = array();
113  $images_updates = array();
114  $images_delete = array();
115 
116  while ($img = pwg_db_fetch_assoc($result))
117  {
118    $file_content = file_get_contents($img['path']);
119    list($file['id'], $file['height'], $file['width'], ) = explode('/', $file_content);
120    $file['type'] = get_extension($img['path']);
121   
122    switch ($file['type'])
123    {
124      case 'vimeo':
125        $url = 'http://vimeo.com/'.$file['id'];
126        break;
127      case 'dm':
128        $url = 'http://dailymotion.com/video/'.$file['id'];
129        break;
130      case 'ytube':
131        $url = 'http://youtu.be/'.$file['id'];
132        break;
133      case 'wideo':
134        $url = 'http://wideo.fr/video/'.$file['id'].'.html';
135        break;
136       
137      case 'wat': // can't get original page from id !
138        $thumb = str_replace($img['file'], null, $img['path']).'thumbnail/TN-'.get_filename_wo_extension($img['file']).'.*';
139        $thumb = glob($thumb);
140        if (!empty($thumb))
141        {
142          $thumb_name = 'wat-'.$file['id'].'-'.uniqid().'.'.get_extension($thumb[0]);
143          $thumb_source = $conf['data_location'].$thumb_name;
144          copy($thumb[0], $thumb_source);
145        }
146       
147        $video = array(
148          'type' => 'wat',
149          'id' => $file['id'],
150          'title' => null,
151          'description' => null,
152          'thumbnail' => null,
153          );
154        break;
155       
156      case 'gvideo': // closed
157      default:
158        array_push($images_delete, $img['id']);
159        continue;
160    }
161   
162    // get video infos
163    if (!isset($video))
164    {
165      if ( ($video = parse_video_url($url)) === false )
166      {
167        array_push($images_delete, $img['id']);
168        continue;
169      }
170    }
171   
172    // download thumbnail
173    if (!isset($thumb_source))
174    {
175      $thumb_name = $video['type'].'-'.$video['id'].'-'.uniqid().'.'.get_extension($video['thumbnail']);
176      $thumb_source = $conf['data_location'].$thumb_name;
177      if (download_remote_file($video['thumbnail'], $thumb_source) !== true)
178      {
179        $thumb_source = $conf['data_location'].get_filename_wo_extension($thumb_name).'.jpg';
180        copy(gvideo_path.'mimetypes/'.$video['type'].'.jpg', $thumb_source);
181        add_film_frame($thumb_source);
182      }
183    }
184   
185    // update element
186    $image_id = add_uploaded_file($thumb_source, $thumb_name, null, null, $img['id']);
187   
188    // update path and rename the file
189    $img['new_path'] = str_replace($img['file'], null, $img['path']).$thumb_name;
190    rename($img['path'], $img['new_path']);
191    array_push($images_updates, array(
192      'id' => $img['id'],
193      'path' => str_replace('././', './', $img['new_path']),
194      ));
195   
196    if (empty($file['width'])) $file['width'] = '';
197    if (empty($file['height'])) $file['height'] = '';
198   
199    // register video   
200    array_push($videos_inserts, array(
201      'picture_id' => $image_id,
202      'type' => $video['type'],
203      'video_id' => $video['id'],
204      'width' => $file['width'],
205      'height' => $file['height'],
206      'autoplay' => '',
207      ));
208     
209    unset($thumb_source, $thumb_name, $file, $video, $url);
210  }
211 
212  // delete obsolete elements
213  delete_elements($images_delete);
214 
215  // registers videos
216  mass_inserts(
217    gvideo_table,
218    array('picture_id', 'type', 'video_id', 'width', 'height', 'autoplay'),
219    $videos_inserts
220    );
221   
222  // update images
223  mass_updates(
224    IMAGES_TABLE,
225    array('primary'=>array('id'), 'update'=>array('path')),
226    $images_updates
227    );
228}
229
230?>
Note: See TracBrowser for help on using the repository browser.