1 | <?php |
---|
2 | /*********************************************** |
---|
3 | * File : maintain.inc.php |
---|
4 | * Project : piwigo-videojs |
---|
5 | * Descr : Install / Uninstall method |
---|
6 | * |
---|
7 | * Created : 24.06.2012 |
---|
8 | * |
---|
9 | * Copyright 2012-2013 <xbgmsharp@gmail.com> |
---|
10 | * |
---|
11 | * This program is free software: you can redistribute it and/or modify |
---|
12 | * it under the terms of the GNU General Public License as published by |
---|
13 | * the Free Software Foundation, either version 3 of the License, or |
---|
14 | * (at your option) any later version. |
---|
15 | * |
---|
16 | * This program is distributed in the hope that it will be useful, |
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | * GNU General Public License for more details. |
---|
20 | * |
---|
21 | * You should have received a copy of the GNU General Public License |
---|
22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
23 | * |
---|
24 | ************************************************/ |
---|
25 | |
---|
26 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
27 | |
---|
28 | function plugin_install() |
---|
29 | { |
---|
30 | if (!defined('VIDEOJS_PATH')) |
---|
31 | define('VIDEOJS_PATH', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)).'/'); |
---|
32 | |
---|
33 | // Remove unused directory or files from 0.4 and 0.5 to 0.6 |
---|
34 | $toremove = array("skin", "js", "language/es_ES"); |
---|
35 | foreach ($toremove as $dir) |
---|
36 | { |
---|
37 | if (is_dir(VIDEOJS_PATH.$dir)) |
---|
38 | { |
---|
39 | deltree(VIDEOJS_PATH.$dir); |
---|
40 | } |
---|
41 | } |
---|
42 | $toremove = array("language/index.htm", "language/fr_FR/index.htm", "language/en_UK/index.htm", "admin.tpl", "admin.php"); |
---|
43 | foreach ($toremove as $file) |
---|
44 | { |
---|
45 | if (is_file(VIDEOJS_PATH.$file)) |
---|
46 | { |
---|
47 | @unlink(VIDEOJS_PATH.$file); |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | $default_config = array( |
---|
52 | 'skin' => 'vjs-default-skin', |
---|
53 | 'max_width' => '720', |
---|
54 | 'preload' => 'auto', |
---|
55 | 'controls' => true, |
---|
56 | 'autoplay' => false, |
---|
57 | 'loop' => false, |
---|
58 | ); |
---|
59 | |
---|
60 | /* Add configuration to the config table */ |
---|
61 | $conf['vjs_conf'] = serialize($default_config); |
---|
62 | conf_update_param('vjs_conf', $conf['vjs_conf']); |
---|
63 | |
---|
64 | /* Add a comment to the entry */ |
---|
65 | $q = 'UPDATE '.CONFIG_TABLE.' SET `comment` = "Configuration settings for piwigo-videojs plugin" WHERE `param` = "vjs_conf";'; |
---|
66 | pwg_query( $q ); |
---|
67 | |
---|
68 | /* Keep customCSS separate as it can be big entry */ |
---|
69 | conf_update_param('vjs_customcss', ''); |
---|
70 | |
---|
71 | /* Add a comment to the entry */ |
---|
72 | $q = 'UPDATE '.CONFIG_TABLE.' SET `comment` = "Custom CSS used by the piwigo-videojs plugin" WHERE `param` = "vjs_customcss";'; |
---|
73 | pwg_query( $q ); |
---|
74 | } |
---|
75 | |
---|
76 | function plugin_uninstall() |
---|
77 | { |
---|
78 | /* Delete all files */ |
---|
79 | /* Don't remove myself on restore settings |
---|
80 | if (is_dir(VIDEOJS_PATH)) |
---|
81 | { |
---|
82 | deltree(VIDEOJS_PATH); |
---|
83 | } |
---|
84 | */ |
---|
85 | $q = 'DELETE FROM '.CONFIG_TABLE.' WHERE param LIKE "%vjs_%" LIMIT 2;'; |
---|
86 | pwg_query( $q ); |
---|
87 | // TODO : Do we need to purge the videos from the images table? |
---|
88 | } |
---|
89 | |
---|
90 | function plugin_activate() |
---|
91 | { |
---|
92 | global $conf; |
---|
93 | |
---|
94 | if ( (!isset($conf['vjs_conf'])) or (!isset($conf['vjs_customcss'])) |
---|
95 | or (count($conf['vjs_conf']) != 6)) |
---|
96 | { |
---|
97 | plugin_install(); |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | function deltree($path) |
---|
102 | { |
---|
103 | if (is_dir($path)) |
---|
104 | { |
---|
105 | $fh = opendir($path); |
---|
106 | while ($file = readdir($fh)) |
---|
107 | { |
---|
108 | if ($file != '.' and $file != '..') |
---|
109 | { |
---|
110 | $pathfile = $path . '/' . $file; |
---|
111 | if (is_dir($pathfile)) |
---|
112 | { |
---|
113 | deltree($pathfile); |
---|
114 | } |
---|
115 | else |
---|
116 | { |
---|
117 | @unlink($pathfile); |
---|
118 | } |
---|
119 | } |
---|
120 | } |
---|
121 | closedir($fh); |
---|
122 | return @rmdir($path); |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | ?> |
---|