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

Last change on this file since 19056 was 19056, checked in by mistic100, 11 years ago

allow to add private dailymotion videos, remove videobb support, add tags support

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