source: extensions/gvideo/maintain.class.php @ 28842

Last change on this file since 28842 was 28842, checked in by mistic100, 10 years ago

use new maintain class

File size: 7.2 KB
Line 
1<?php
2defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
3
4class gvideo_maintain extends PluginMaintain
5{
6  private $default_conf = array(
7    'autoplay' => 0,
8    'width' => 640,
9    'height' => 360,
10    'sync_description' => 1,
11    'sync_tags' => 1,
12    'vimeo' => array(
13      'title' => 1,
14      'portrait' => 1,
15      'byline' => 1,
16      'color' => '00adef',
17      ),
18    'dailymotion' => array(
19      'logo' => 1,
20      'title' => 1,
21      'color' => 'F7FFFD',
22      ),
23    'youtube' => array(),
24    'wat' => array(),
25    'wideo' => array(),
26    );
27   
28  private $table;
29 
30  function __construct($plugin_id)
31  {
32    global $prefixeTable;
33   
34    parent::__construct($plugin_id);
35    $this->table = $prefixeTable . 'image_video';
36  }
37
38  function install($plugin_version, &$errors=array())
39  {
40    global $conf;
41
42    // add config parameter
43    if (empty($conf['gvideo']))
44    {
45      conf_update_param('gvideo', $this->default_conf, true);
46    }
47    else
48    {
49      $conf['gvideo'] = safe_unserialize($conf['gvideo']);
50
51      if (!isset($conf['gvideo']['sync_description']))
52      {
53        $conf['gvideo']['sync_description'] = 1;
54        $conf['gvideo']['sync_tags'] = 1;
55       
56        conf_update_param('gvideo', $conf['gvideo']);
57      }
58    }
59
60    // create table
61  $query = '
62CREATE TABLE IF NOT EXISTS `' . $this->table . '` (
63  `picture_id` mediumint(8) NOT NULL,
64  `url` varchar(255) DEFAULT NULL,
65  `type` varchar(64) NOT NULL,
66  `video_id` varchar(128) NOT NULL,
67  `width` smallint(9) DEFAULT NULL,
68  `height` smallint(9) DEFAULT NULL,
69  `autoplay` tinyint(1) DEFAULT NULL,
70  `embed` text DEFAULT NULL
71) ENGINE=MyISAM DEFAULT CHARSET=utf8
72;';
73    pwg_query($query);
74   
75    // update video_id lenght
76    pwg_query('ALTER TABLE `' . $this->table . '` CHANGE `video_id` `video_id` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;');
77   
78    // new collumn in images table
79    $result = pwg_query('SHOW COLUMNS FROM `' . IMAGES_TABLE . '` LIKE "is_gvideo";');
80    if (!pwg_db_num_rows($result))
81    {
82      pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` ADD `is_gvideo` TINYINT(1) NOT NULL DEFAULT 0;');
83     
84      $query = '
85UPDATE `' . IMAGES_TABLE . '`
86  SET is_gvideo = 1
87  WHERE id IN(
88    SELECT picture_id FROM `' . $this->table . '`
89    )
90;';
91      pwg_query($query);
92    }
93   
94    // new column "embed"
95    $result = pwg_query('SHOW COLUMNS FROM `' . $this->table . '` LIKE "embed";');
96    if (!pwg_db_num_rows($result))
97    {
98      pwg_query('ALTER TABLE `' . $this->table . '` ADD `embed` text DEFAULT NULL;');
99    }
100   
101    // remove old configuration
102    if (isset($conf['PY_GVideo']))
103    {
104      conf_delete_param('PY_GVideo');
105    }
106   
107    // updade video files
108    $this->update_24();
109  }
110
111  function update($old_version, $new_version, &$errors=array())
112  {
113    $this->install($new_version, $errors);
114  }
115
116  function uninstall()
117  {
118    conf_delete_param('gvideo');
119
120    pwg_query('DROP TABLE `' . $this->table . '`;');
121
122    pwg_query('ALTER TABLE `'. IMAGES_TABLE .'` DROP `is_gvideo`;');
123  }
124 
125  /**
126   * update from 2.3 to 2.4
127   */
128  function update_24()
129  {
130    global $conf;
131   
132    // search existing videos
133  $query = '
134SELECT *
135  FROM '.IMAGES_TABLE.'
136  WHERE
137    file LIKE "%.gvideo"
138    OR file LIKE "%.dm"
139    OR file LIKE "%.ytube"
140    OR file LIKE "%.wideo"
141    OR file LIKE "%.vimeo"
142    OR file LIKE "%.wat"
143;';
144    $result = pwg_query($query);
145   
146    if (!pwg_db_num_rows($result))
147    {
148      return;
149    }
150   
151    if (!isset($conf['prefix_thumbnail']))
152    {
153      $conf['prefix_thumbnail'] = 'TN-';
154    }
155
156    if (!isset($conf['dir_thumbnail']))
157    {
158      $conf['dir_thumbnail'] = 'thumbnail';
159    }
160   
161    set_time_limit(600);
162    include_once(gvideo_path . 'include/functions.inc.php');
163    include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
164   
165    $videos_inserts = array();
166    $images_updates = array();
167    $images_delete = array();
168   
169    while ($img = pwg_db_fetch_assoc($result))
170    {
171      $file_content = file_get_contents($img['path']);
172      list($file['id'], $file['height'], $file['width'], ) = explode('/', $file_content);
173      $file['type'] = get_extension($img['path']);
174     
175      switch ($file['type'])
176      {
177        case 'vimeo':
178          $video = array(
179            'type' => 'vimeo',
180            'url' => 'http://vimeo.com/'.$file['id'],
181            );
182          break;
183        case 'dm':
184          $video = array(
185            'type' => 'dailymotion',
186            'url' => 'http://dailymotion.com/video/'.$file['id'],
187            );
188          break;
189        case 'ytube':
190          $video = array(
191            'type' => 'youtube',
192            'url' => 'http://youtube.com/watch?v='.$file['id'],
193            );
194          break;
195        case 'wideo':
196          $video = array(
197            'type' => 'wideo',
198            'url' => 'http://wideo.fr/video/'.$file['id'].'.html',
199            );
200          break;
201        case 'wat':
202          $video = array(
203            'type' => 'wat',
204            'url' => null,
205            );
206          break;
207        case 'gvideo': // closed
208        default:
209          $images_delete[] = $img['id'];
210          continue;
211      }
212     
213      $real_path = str_replace($img['file'], null, str_replace('././', './', $img['path']));
214     
215      // get existing thumbnail
216      $thumb = $real_path.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'].get_filename_wo_extension($img['file']).'.*';
217      $thumb = glob($thumb);
218      if (!empty($thumb))
219      {
220        $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.'.get_extension($thumb[0]);
221        $thumb_source = $conf['data_location'].$thumb_name;
222        copy($thumb[0], $thumb_source);
223      }
224      else
225      {
226        $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.jpg';
227        $thumb_source = $conf['data_location'].$thumb_name;
228        copy(gvideo_path.'mimetypes/'.$video['type'].'.jpg', $thumb_source);
229        add_film_frame($thumb_source);
230      }
231     
232      // update element
233      $image_id = add_uploaded_file($thumb_source, $thumb_name, null, null, $img['id']);
234     
235      // update path and rename the file
236      $img['new_path'] = $real_path.$thumb_name;
237      rename($img['path'], $img['new_path']); // why ? what's the purpose of this line ?
238     
239      $images_updates[] = array(
240        'id' => $img['id'],
241        'path' => $img['new_path'],
242        'is_gvideo' => 1,
243        );
244     
245      if (empty($file['width'])) $file['width'] = '';
246      if (empty($file['height'])) $file['height'] = '';
247     
248      // register video   
249      $videos_inserts[] = array(
250        'picture_id' => $image_id,
251        'url' => $video['url'],
252        'type' => $video['type'],
253        'video_id' => $file['id'],
254        'width' => $file['width'],
255        'height' => $file['height'],
256        'autoplay' => '',
257        );
258       
259      unset($thumb_source, $thumb_name, $file, $video, $url);
260    }
261   
262    // delete obsolete elements
263    delete_elements($images_delete);
264   
265    // registers videos
266    mass_inserts(
267      gvideo_table,
268      array('picture_id', 'url', 'type', 'video_id', 'width', 'height', 'autoplay'),
269      $videos_inserts
270      );
271     
272    // update images
273    mass_updates(
274      IMAGES_TABLE,
275      array('primary'=>array('id'), 'update'=>array('path', 'is_gvideo')),
276      $images_updates
277      );
278  }
279}
Note: See TracBrowser for help on using the repository browser.