1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Stereo - a Piwigo Plugin | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2010 philippe Brangier | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | This program is free software; you can redistribute it and/or modify | |
---|
8 | // | it under the terms of the GNU General Public License as published by | |
---|
9 | // | the Free Software Foundation | |
---|
10 | // | | |
---|
11 | // | This program is distributed in the hope that it will be useful, but | |
---|
12 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
13 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
14 | // | General Public License for more details. | |
---|
15 | // | | |
---|
16 | // | You should have received a copy of the GNU General Public License | |
---|
17 | // | along with this program; if not, write to the Free Software | |
---|
18 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
19 | // | USA. | |
---|
20 | // +-----------------------------------------------------------------------+ |
---|
21 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
22 | add_event_handler('render_element_content', 'Stereo_change_picture', 40, 2 ); |
---|
23 | add_event_handler('get_admin_plugin_menu_links', 'Stereo_plugin_admin_menu'); |
---|
24 | |
---|
25 | define('STEREO_VER' , '2.0.b'); |
---|
26 | global $conf, $stereo; |
---|
27 | |
---|
28 | // stereo plugin configuration |
---|
29 | $stereoSerialized = @file_get_contents( $conf['local_data_dir'].'/plugins/'.STEREO_DIR.'.dat'); |
---|
30 | if ($stereoSerialized!==false) $stereo = unserialize($stereoSerialized); |
---|
31 | if (!isset($stereo['version']) or $stereo['version'] != STEREO_VER) |
---|
32 | { |
---|
33 | $stereo['version'] = STEREO_VER; |
---|
34 | if (!isset($stereo['ext'])) $stereo['ext'] = 'jps'; |
---|
35 | if (!isset($stereo['menuheight'])) $stereo['menuheight'] = '20'; |
---|
36 | if (!isset($stereo['containerheight'])) $stereo['containerheight'] = ''; |
---|
37 | if (!isset($stereo['containerwidth'])) $stereo['containerwidth'] = ''; |
---|
38 | if (!isset($stereo['allowFullScreen'])) $stereo['allowFullScreen'] = 'true'; |
---|
39 | if (!isset($stereo['fixedwidth'])) $stereo['fixedwidth'] = ''; |
---|
40 | if (!isset($stereo['fixedheight'])) $stereo['fixedheight'] = ''; |
---|
41 | if (!isset($stereo['showhelp'])) $stereo['showhelp'] = 'true'; |
---|
42 | if (!isset($stereo['helpbuttonblock'])) $stereo['helpbuttonblock'] = 'navButtons'; |
---|
43 | if (!isset($stereo['helpbuttonposition'])) $stereo['helpbuttonposition'] = 'right'; |
---|
44 | $dir = $conf['local_data_dir'].'/plugins/'; |
---|
45 | @mkdir($dir); |
---|
46 | $file = fopen( $dir.STEREO_DIR.'.dat', 'w' ); |
---|
47 | fwrite($file, serialize($stereo)); |
---|
48 | fclose( $file ); |
---|
49 | } |
---|
50 | |
---|
51 | // add our file extension in the global config |
---|
52 | $conf['file_ext'] = array_merge($conf['file_ext'],(array)$stereo['ext']); |
---|
53 | $conf['picture_ext'] = array_merge($conf['picture_ext'],(array)$stereo['ext']); |
---|
54 | |
---|
55 | function Stereo_plugin_admin_menu($menu) |
---|
56 | { |
---|
57 | array_push($menu, array( |
---|
58 | 'NAME' => 'Stereo', |
---|
59 | 'URL' => get_admin_plugin_menu_link(STEREO_PATH.'/config.php'), |
---|
60 | )); |
---|
61 | return $menu; |
---|
62 | } |
---|
63 | |
---|
64 | function Stereo_change_picture($content, $image) |
---|
65 | { |
---|
66 | global $conf, $stereo, $template, $page; |
---|
67 | // |
---|
68 | $extension = strtolower(get_extension($image['file'])); |
---|
69 | if ($extension !== $stereo['ext']) |
---|
70 | { return $content; } |
---|
71 | if (!isset($image['image_url']) or !empty($content)) |
---|
72 | { // nothing to do or someone hooked us - so we skip; |
---|
73 | return $content; |
---|
74 | } |
---|
75 | |
---|
76 | $template->set_filenames(array('stereo_content' => dirname(__FILE__) . '/stereo.tpl') ); |
---|
77 | |
---|
78 | // compute display size |
---|
79 | if ( $stereo['fixedheight'] === '' ) { |
---|
80 | $stereo['containerheight'] = $image['height'] + $stereo['menuheight']; |
---|
81 | } |
---|
82 | else { |
---|
83 | $stereo['containerheight'] = $stereo['fixedheight'] + $stereo['menuheight']; |
---|
84 | } |
---|
85 | if ( $stereo['fixedwidth'] === '' ) { |
---|
86 | $stereo['containerwidth'] = $image['width']; |
---|
87 | } |
---|
88 | else { |
---|
89 | $stereo['containerwidth'] = $stereo['fixedwidth']; |
---|
90 | } |
---|
91 | |
---|
92 | // is high def available ? if ( !isset($page['slideshow']) and isset($image['high_url']) ) |
---|
93 | if ( !$page['slideshow'] and isset($image['high_url']) ) |
---|
94 | { |
---|
95 | $uuid = uniqid(rand()); |
---|
96 | $template->assign( |
---|
97 | 'high', |
---|
98 | array( |
---|
99 | 'U_HIGH' => $image['high_url'], |
---|
100 | 'UUID' => $uuid, |
---|
101 | ) |
---|
102 | ); |
---|
103 | } |
---|
104 | $template->assign( |
---|
105 | array( |
---|
106 | 'PHPWG_ROOT_PATH' => PHPWG_ROOT_PATH, |
---|
107 | 'STEREO_PATH' => STEREO_PATH, |
---|
108 | 'SRC_IMG' => $image['element_url'], |
---|
109 | 'stereo' => $stereo, |
---|
110 | ) |
---|
111 | ); |
---|
112 | |
---|
113 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
114 | return $template->parse('stereo_content', true); |
---|
115 | } |
---|
116 | ?> |
---|