source: extensions/piwigo_videojs/main.inc.php @ 27153

Last change on this file since 27153 was 24676, checked in by ddtddt, 11 years ago

[extensions] - piwigo_videojs - add file for translate

File size: 7.7 KB
Line 
1<?php
2/*
3Plugin Name: VideoJS
4Version: 1.0.1
5Description: videojs integration for piwigo
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=610
7Author: xbmgsharp
8Author URI: https://github.com/xbgmsharp/piwigo-videojs
9*/
10
11// Chech whether we are indeed included by Piwigo.
12if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
13
14// Define the path to our plugin.
15define('VIDEOJS_PATH', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)).'/');
16
17global $conf;
18
19// Prepare configuration
20$conf['vjs_conf'] = unserialize($conf['vjs_conf']);
21
22// Register the allowed extentions to the global conf in order
23// to sync them with other contents
24$vjs_extensions = array(
25    'ogg',
26    'mp4',
27    'm4v',
28    'ogv',
29    'webm',
30    'webmv',
31);
32$conf['file_ext'] = array_merge ($conf['file_ext'], $vjs_extensions, array_map('strtoupper', $vjs_extensions) );
33
34// Hook on to an event to display videos as standard images
35add_event_handler('render_element_content', 'vjs_render_media', 40, 2);
36
37// Hook to display a fallback thumbnail if not defined
38add_event_handler('get_mimetype_location', 'vjs_get_mimetype_icon', 60, 2);
39
40// Hook to change the picture data to template
41//add_event_handler('picture_pictures_data', 'vjs_pictures_data');
42
43// Hook to sync geotag metadata on upload or sync
44//add_event_handler('format_exif_data', 'vjs_format_exif_data', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
45
46// If admin do the init
47if (defined('IN_ADMIN')) {
48        include_once(VIDEOJS_PATH.'/admin/admin_boot.php');
49}
50
51function vjs_format_exif_data($exif, $file, $map)
52{
53
54}
55
56function vjs_render_media($content, $picture)
57{
58        global $template, $picture, $page, $conf, $user, $refresh;
59        //print_r( $picture['current']);
60        // do nothing if the current picture is actually an image !
61        if ( (array_key_exists('src_image', @$picture['current'])
62                && @$picture['current']['src_image']->is_original()) )
63        {
64                return $content;
65        }
66
67        // In case, the we handle a large video, we define a MAX_WIDTH
68        // variable to limit the display size.
69        if (isset($user['maxwidth']) and $user['maxwidth']!='')
70        {
71                $MAX_WIDTH = $user['maxwidth'];
72        }
73        else
74        {
75                $MAX_WIDTH = isset($conf['vjs_conf']['max_width']) ? $conf['vjs_conf']['max_width'] : '720';
76        }
77        //print "$MAX_WIDTH=" . $MAX_WIDTH;
78        //print_r($user);
79
80        // Avoid Conflict with other plugin using getID3
81        if( !class_exists('getID3')){
82                // Get video infos with getID3 lib
83                require_once(dirname(__FILE__) . '/include/getid3/getid3.php');
84        }
85        $getID3 = new getID3;
86        $fileinfo = $getID3->analyze($picture['current']['path']);
87        //print "getID3\n";
88        //print_r($fileinfo);
89
90        $extension = strtolower(get_extension($picture['current']['path']));
91        if ($extension == "m4v")
92        {
93                $extension = "mp4";
94        }
95        else if ($extension == "webmv")
96        {
97                $extension = "webm4";
98        }
99        else if ($extension == "ogv")
100        {
101                $extension = "ogg";
102        }
103        //print "extension\n";
104        //print_r($extension);
105
106        if(isset($fileinfo['video']))
107        {
108                // -- video file --
109                // guess resolution
110                if (isset($fileinfo['video']['resolution_x']) )
111                {
112                        $width = $fileinfo['video']['resolution_x'];
113                }
114                if (isset($fileinfo['video']['resolution_y']) )
115                {
116                        $height = $fileinfo['video']['resolution_y'];
117                }
118                if ( !isset($width) || !isset($height))
119                {
120                        // If guess was unsuccessful, fallback to default 16/9 resolution
121                        // This is the case for ogv video for example.
122                        $width = $MAX_WIDTH;
123                        $height = intval( 9 * ($width / 16 ));
124                }
125        }
126        else // Not a supported video format or an image
127        {
128                return $content;
129        }
130
131        // Resize if video is too large
132        if ( $width > $MAX_WIDTH )
133        {
134                //$height = intval($height * ($MAX_WIDTH / $width));
135                //$width  = $MAX_WIDTH;
136                $height = intval($height / 2);
137                $width = intval($width / 2);
138        }
139
140        // Slideshow : The video needs to be launch automatically in
141        // slideshow mode. The refresh of the page is set to the
142        // duration of the video.
143        $autoplay = isset($conf['vjs_conf']['autoplay']) ? strbool($conf['vjs_conf']['autoplay']) : 'false';
144        if ( $page['slideshow'] )
145        {
146                $refresh = $fileinfo['playtime_seconds'];
147                $autoplay = 'true';
148        }
149
150        // Load parameter, fallback to default if unset
151        $skin = isset($conf['vjs_conf']['skin']) ? $conf['vjs_conf']['skin'] : 'vjs-default-skin';
152        $customcss = isset($conf['vjs_customcss']) ? $conf['vjs_customcss'] : '';
153        $preload = isset($conf['vjs_conf']['preload']) ? $conf['vjs_conf']['preload'] : 'none';
154        $loop = isset($conf['vjs_conf']['loop']) ? strbool($conf['vjs_conf']['loop']) : 'false';
155        $controls = isset($conf['vjs_conf']['controls']) ? strbool($conf['vjs_conf']['controls']) : 'false';
156
157        // Assing the CSS file according to the skin
158        $skincss = "";
159        if ($skin == 'vjs-default-skin')
160        {
161                $skincss = "video-js.min.css";
162        } else if ($skin == 'vjs-darkfunk-skin')
163        {
164                $skincss = "darkfunk-skin.css";
165        } else if ($skin == 'vjs-redsheen-skin')
166        {
167                $skincss = "redsheen-skin.css";
168        }
169
170        // Select the template
171        $template->set_filenames(
172                array('vjs_content' => dirname(__FILE__)."/template/vjs-player.tpl")
173        );
174
175        // Try to guess the poster extension
176        $parts = pathinfo($picture['current']['element_url']);
177        $poster = getposterfile (Array(
178                $fileinfo['filepath']."/".$parts['filename'].".png" =>
179                        get_gallery_home_url() . $parts['dirname'] . "/".$parts['filename'].".png",
180                $fileinfo['filepath']."/".$parts['filename'].".jpg" =>
181                        get_gallery_home_url() . $parts['dirname'] . "/".$parts['filename'].".jpg",
182                $fileinfo['filepath']."/thumbnail/TN-".$parts['filename'].".jpg" =>
183                        get_gallery_home_url() . $parts['dirname'] . "/thumbnail/TN-".$parts['filename'].".jpg",
184                $fileinfo['filepath']."/thumbnail/TN-".$parts['filename'].".png" =>
185                        get_gallery_home_url() . $parts['dirname'] . "/thumbnail/TN-".$parts['filename'].".png",
186                $fileinfo['filepath']."/pwg_representative/".$parts['filename'].".jpg" =>
187                        get_gallery_home_url() . $parts['dirname'] . "/pwg_representative/".$parts['filename'].".jpg",
188                $fileinfo['filepath']."/pwg_representative/".$parts['filename'].".png" =>
189                        get_gallery_home_url() . $parts['dirname'] . "/pwg_representative/".$parts['filename'].".png",
190        ));
191        //print $poster;
192
193        // Genrate HTML5 tags
194        // Why the data-setup attribute does not work if only one video
195        $options = "";
196        if ($controls == "true")
197        {
198                $options .= "controls";
199        }
200        if ($autoplay == "true")
201        {
202                $options .= " autoplay ";
203        }
204        if ($loop == "true")
205        {
206                $options .= " loop ";
207        }
208        $options .= ' preload="'. $preload .'"';
209
210        // Assign the template variables
211        // We use here the piwigo's get_gallery_home_url function to build
212        // the full URL as suggested by videojs for flash fallback compatibility
213        $template->assign(
214                array(
215                        'VIDEOJS_MEDIA_URL'     => embellish_url(get_gallery_home_url() . $picture['current']['element_url']),
216                        'VIDEOJS_POSTER_URL'    => $poster,
217                        'VIDEOJS_PATH'          => VIDEOJS_PATH,
218                        'VIDEOJS_FULLPATH'      => realpath(dirname(__FILE__)),
219                        'WIDTH'                 => $width,
220                        'HEIGHT'                => $height,
221                        'TYPE'                  => $extension,
222                        'OPTIONS'               => $options,
223                        'VIDEOJS_SKIN'          => $skin,
224                        'VIDEOJS_SKINCSS'       => $skincss,
225                        'VIDEOJS_CUSTOMCSS'     => $customcss,
226                )
227        );
228
229        // Return the rendered html
230        $vjs_content = $template->parse('vjs_content', true);
231        return $vjs_content;
232}
233
234function vjs_get_mimetype_icon ($location, $element_info)
235{
236        $location= 'plugins/'
237                . basename(dirname(__FILE__))
238                . '/mimetypes/' . $element_info . '.png';
239        return $location;
240}
241
242function strbool($value)
243{
244        return $value ? 'true' : 'false';
245}
246
247function getposterfile($file_list)
248{
249        foreach ($file_list as $file=>$url) {
250                //print $file."=>".$url."<br/>\n";
251                if (file_exists($file)) return $url;
252        }
253        return '';
254}
255
256function vjs_dbSet($fields, $data = array())
257{
258    if (!$data) $data = &$_POST;
259    $set='';
260    foreach ($fields as $field)
261    {
262        if (isset($data[$field]))
263        {
264            $set.="`$field`='".pwg_db_real_escape_string($data[$field])."', ";
265        }
266    }
267    return substr($set, 0, -2);
268}
269
270?>
Note: See TracBrowser for help on using the repository browser.