source: extensions/gvideo/include/install.inc.php @ 17661

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

consolidate upgrade process, cURL compliant with safe_mode

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