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

Last change on this file since 19213 was 19213, checked in by mistic100, 11 years ago
  • add safe mode
  • fix little error when adding video without thumbnail
File size: 6.5 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(128) 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  // update video_id lenght
76  $query = 'ALTER TABLE `'.gvideo_table.'` CHANGE `video_id` `video_id` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;';
77  pwg_query($query);
78 
79  // new collumn in images table
80  $result = pwg_query('SHOW COLUMNS FROM '.IMAGES_TABLE.' LIKE "is_gvideo";');
81  if (!pwg_db_num_rows($result))
82  {
83    pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` ADD `is_gvideo` TINYINT(1) NOT NULL DEFAULT 0;');
84   
85    $query = '
86UPDATE '.IMAGES_TABLE.'
87  SET is_gvideo = 1
88  WHERE id IN(
89    SELECT picture_id FROM '.gvideo_table.'
90    )
91;';
92    pwg_query($query);
93  }
94 
95  // remove old configuration and upgrade video files
96  if (isset($conf['PY_GVideo']))
97  {
98    pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "PY_GVideo" LIMIT 1;');
99    unset($conf['PY_GVideo']);
100 
101    gvideo_update_24();
102  }
103}
104
105
106/**
107 * update from 2.3 to 2.4
108 */
109function gvideo_update_24()
110{
111  global $conf;
112 
113  // search existing videos
114  $query = '
115SELECT *
116  FROM '.IMAGES_TABLE.'
117  WHERE
118    file LIKE "%.gvideo"
119    OR file LIKE "%.dm"
120    OR file LIKE "%.ytube"
121    OR file LIKE "%.wideo"
122    OR file LIKE "%.vimeo"
123    OR file LIKE "%.wat"
124;';
125  $result = pwg_query($query);
126 
127  if (!pwg_db_num_rows($result))
128  {
129    return;
130  }
131 
132  if (!isset($conf['prefix_thumbnail']))
133  {
134    $conf['prefix_thumbnail'] = 'TN-';
135  }
136
137  if (!isset($conf['dir_thumbnail']))
138  {
139    $conf['dir_thumbnail'] = 'thumbnail';
140  }
141 
142  set_time_limit(600);
143  include_once(gvideo_path . 'include/functions.inc.php');
144  include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
145 
146  $videos_inserts = array();
147  $images_updates = array();
148  $images_delete = array();
149 
150  while ($img = pwg_db_fetch_assoc($result))
151  {
152    $file_content = file_get_contents($img['path']);
153    list($file['id'], $file['height'], $file['width'], ) = explode('/', $file_content);
154    $file['type'] = get_extension($img['path']);
155   
156    switch ($file['type'])
157    {
158      case 'vimeo':
159        $video = array(
160          'type' => 'vimeo',
161          'url' => 'http://vimeo.com/'.$file['id'],
162          );
163        break;
164      case 'dm':
165        $video = array(
166          'type' => 'dailymotion',
167          'url' => 'http://dailymotion.com/video/'.$file['id'],
168          );
169        break;
170      case 'ytube':
171        $video = array(
172          'type' => 'youtube',
173          'url' => 'http://youtube.com/watch?v='.$file['id'],
174          );
175        break;
176      case 'wideo':
177        $video = array(
178          'type' => 'wideo',
179          'url' => 'http://wideo.fr/video/'.$file['id'].'.html',
180          );
181        break;
182      case 'wat':
183        $video = array(
184          'type' => 'wat',
185          'url' => null,
186          );
187        break;
188      case 'gvideo': // closed
189      default:
190        array_push($images_delete, $img['id']);
191        continue;
192    }
193   
194    $real_path = str_replace($img['file'], null, str_replace('././', './', $img['path']));
195   
196    // get existing thumbnail
197    $thumb = $real_path.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'].get_filename_wo_extension($img['file']).'.*';
198    $thumb = glob($thumb);
199    if (!empty($thumb))
200    {
201      $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.'.get_extension($thumb[0]);
202      $thumb_source = $conf['data_location'].$thumb_name;
203      copy($thumb[0], $thumb_source);
204    }
205    else
206    {
207      $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.jpg';
208      $thumb_source = $conf['data_location'].$thumb_name;
209      copy(gvideo_path.'mimetypes/'.$video['type'].'.jpg', $thumb_source);
210      add_film_frame($thumb_source);
211    }
212   
213    // update element
214    $image_id = add_uploaded_file($thumb_source, $thumb_name, null, null, $img['id']);
215   
216    // update path and rename the file
217    $img['new_path'] = $real_path.$thumb_name;
218    rename($img['path'], $img['new_path']);
219    array_push($images_updates, array(
220      'id' => $img['id'],
221      'path' => $img['new_path'],
222      'is_gvideo' => 1,
223      ));
224   
225    if (empty($file['width'])) $file['width'] = '';
226    if (empty($file['height'])) $file['height'] = '';
227   
228    // register video   
229    array_push($videos_inserts, array(
230      'picture_id' => $image_id,
231      'url' => $video['url'],
232      'type' => $video['type'],
233      'video_id' => $file['id'],
234      'width' => $file['width'],
235      'height' => $file['height'],
236      'autoplay' => '',
237      ));
238     
239    unset($thumb_source, $thumb_name, $file, $video, $url);
240  }
241 
242  // delete obsolete elements
243  delete_elements($images_delete);
244 
245  // registers videos
246  mass_inserts(
247    gvideo_table,
248    array('picture_id', 'url', 'type', 'video_id', 'width', 'height', 'autoplay'),
249    $videos_inserts
250    );
251   
252  // update images
253  mass_updates(
254    IMAGES_TABLE,
255    array('primary'=>array('id'), 'update'=>array('path', 'is_gvideo')),
256    $images_updates
257    );
258}
Note: See TracBrowser for help on using the repository browser.