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

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

I should stop trying to go fast

File size: 6.5 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/* install */
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  `url` varchar(255) DEFAULT NULL,
44  `type` varchar(64) NOT NULL,
45  `video_id` varchar(64) NOT NULL,
46  `width` smallint(9) DEFAULT NULL,
47  `height` smallint(9) DEFAULT NULL,
48  `autoplay` tinyint(1) DEFAULT NULL
49) ENGINE=MyISAM DEFAULT CHARSET=utf8
50;';
51  pwg_query($query);
52 
53  pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` ADD `is_gvideo` TINYINT(1) NOT NULL DEFAULT 0;');
54 
55  if (isset($conf['PY_GVideo']))
56  {
57    pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "PY_GVideo" LIMIT 1;');
58    unset($conf['PY_GVideo']);
59 
60    gvideo_update_24();
61  }
62}
63
64/* activate */
65function plugin_activate()
66{
67  global $conf;
68   
69  if (isset($conf['PY_GVideo']))
70  {
71    plugin_install();
72  }
73  else 
74  {
75    if (!isset($conf['gvideo']))
76    {
77      conf_update_param('gvideo', gvideo_default_config);
78    }
79   
80    $result = pwg_query('SHOW COLUMNS FROM '.gvideo_table.' LIKE "url";');
81    if (!pwg_db_num_rows($result))
82    {     
83      pwg_query('ALTER TABLE '.gvideo_table.' ADD `url` VARCHAR(255) DEFAULT NULL;');
84    }
85   
86    $result = pwg_query('SHOW COLUMNS FROM '.IMAGES_TABLE.' LIKE "is_gvideo";');
87    if (!pwg_db_num_rows($result))
88    {     
89      pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` ADD `is_gvideo` TINYINT(1) NOT NULL DEFAULT 0;');
90     
91      $query = '
92UPDATE '.IMAGES_TABLE.'
93  SET is_gvideo = 1
94  WHERE id IN(
95    SELECT picture_id FROM '.gvideo_table.'
96    )
97;';
98      pwg_query($query);
99    }
100  }
101}
102
103/* uninstall */
104function plugin_uninstall() 
105{ 
106  pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "gvideo" LIMIT 1;');
107  pwg_query('DROP TABLE `'.gvideo_table.'`;');
108  pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` DROP `is_gvideo`;');
109}
110
111
112/**
113 * update from 2.3 to 2.4
114 */
115function gvideo_update_24()
116{
117  global $conf;
118 
119  // search existing videos
120  $query = '
121SELECT *
122  FROM '.IMAGES_TABLE.'
123  WHERE
124    file LIKE "%.gvideo"
125    OR file LIKE "%.dm"
126    OR file LIKE "%.ytube"
127    OR file LIKE "%.wideo"
128    OR file LIKE "%.vimeo"
129    OR file LIKE "%.wat"
130;';
131  $result = pwg_query($query);
132 
133  if (!pwg_db_num_rows($result))
134  {
135    return;
136  }
137 
138  if (!isset($conf['prefix_thumbnail']))
139  {
140    $conf['prefix_thumbnail'] = 'TN-';
141  }
142
143  if (!isset($conf['dir_thumbnail']))
144  {
145    $conf['dir_thumbnail'] = 'thumbnail';
146  }
147 
148  set_time_limit(600);
149  include_once(gvideo_path . '/include/functions.inc.php');
150  include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
151 
152  $videos_inserts = array();
153  $images_updates = array();
154  $images_delete = array();
155 
156  while ($img = pwg_db_fetch_assoc($result))
157  {
158    $file_content = file_get_contents($img['path']);
159    list($file['id'], $file['height'], $file['width'], ) = explode('/', $file_content);
160    $file['type'] = get_extension($img['path']);
161   
162    switch ($file['type'])
163    {
164      case 'vimeo':
165        $video = array(
166          'type' => 'vimeo',
167          'url' => 'http://vimeo.com/'.$file['id'],
168          );
169        break;
170      case 'dm':
171        $video = array(
172          'type' => 'dailymotion',
173          'url' => 'http://dailymotion.com/video/'.$file['id'],
174          );
175        break;
176      case 'ytube':
177        $video = array(
178          'type' => 'youtube',
179          'url' => 'http://youtube.com/watch?v='.$file['id'],
180          );
181        break;
182      case 'wideo':
183        $video = array(
184          'type' => 'wideo',
185          'url' => 'http://wideo.fr/video/'.$file['id'].'.html',
186          );
187        break;
188      case 'wat':
189        $video = array(
190          'type' => 'wat',
191          'url' => null,
192          );
193        break;
194      case 'gvideo': // closed
195      default:
196        array_push($images_delete, $img['id']);
197        continue;
198    }
199   
200    $real_path = str_replace($img['file'], null, str_replace('././', './', $img['path']));
201   
202    // get existing thumbnail
203    $thumb = $real_path.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'].get_filename_wo_extension($img['file']).'.*';
204    $thumb = glob($thumb);
205    if (!empty($thumb))
206    {
207      $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.'.get_extension($thumb[0]);
208      $thumb_source = $conf['data_location'].$thumb_name;
209      copy($thumb[0], $thumb_source);
210    }
211    else
212    {
213      $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.jpg';
214      $thumb_source = $conf['data_location'].$thumb_name;
215      copy(gvideo_path.'mimetypes/'.$video['type'].'.jpg', $thumb_source);
216      add_film_frame($thumb_source);
217    }
218   
219    // update element
220    $image_id = add_uploaded_file($thumb_source, $thumb_name, null, null, $img['id']);
221   
222    // update path and rename the file
223    $img['new_path'] = $real_path.$thumb_name;
224    rename($img['path'], $img['new_path']);
225    array_push($images_updates, array(
226      'id' => $img['id'],
227      'path' => $img['new_path'],
228      'is_gvideo' => 1,
229      ));
230   
231    if (empty($file['width'])) $file['width'] = '';
232    if (empty($file['height'])) $file['height'] = '';
233   
234    // register video   
235    array_push($videos_inserts, array(
236      'picture_id' => $image_id,
237      'url' => $video['url'],
238      'type' => $video['type'],
239      'video_id' => $file['id'],
240      'width' => $file['width'],
241      'height' => $file['height'],
242      'autoplay' => '',
243      ));
244     
245    unset($thumb_source, $thumb_name, $file, $video, $url);
246  }
247 
248  // delete obsolete elements
249  delete_elements($images_delete);
250 
251  // registers videos
252  mass_inserts(
253    gvideo_table,
254    array('picture_id', 'url', 'type', 'video_id', 'width', 'height', 'autoplay'),
255    $videos_inserts
256    );
257   
258  // update images
259  mass_updates(
260    IMAGES_TABLE,
261    array('primary'=>array('id'), 'update'=>array('path', 'is_gvideo')),
262    $images_updates
263    );
264}
265
266?>
Note: See TracBrowser for help on using the repository browser.