1 | <?php |
---|
2 | /* |
---|
3 | Theme Name: Smart Pocket |
---|
4 | Version: 2.6.0 |
---|
5 | Description: Mobile theme. |
---|
6 | Theme URI: http://piwigo.org/ext/extension_view.php?eid=599 |
---|
7 | Author: P@t |
---|
8 | Author URI: http://piwigo.org |
---|
9 | */ |
---|
10 | |
---|
11 | $themeconf = array( |
---|
12 | 'mobile' => true, |
---|
13 | ); |
---|
14 | |
---|
15 | // Need upgrade? |
---|
16 | global $conf; |
---|
17 | include(PHPWG_THEMES_PATH.'smartpocket/admin/upgrade.inc.php'); |
---|
18 | |
---|
19 | load_language('theme.lang', PHPWG_THEMES_PATH.'smartpocket/'); |
---|
20 | |
---|
21 | |
---|
22 | // Redirect if page is not compatible with mobile theme |
---|
23 | /*if (!in_array(script_basename(), array('index', 'register', 'profile', 'identification', 'ws', 'admin'))) |
---|
24 | redirect(duplicate_index_url()); |
---|
25 | */ |
---|
26 | |
---|
27 | |
---|
28 | class SPThumbPicker |
---|
29 | { |
---|
30 | var $candidates; |
---|
31 | var $default; |
---|
32 | var $height; |
---|
33 | |
---|
34 | function init($height) |
---|
35 | { |
---|
36 | $this->candidates = array(); |
---|
37 | foreach( ImageStdParams::get_defined_type_map() as $params) |
---|
38 | { |
---|
39 | if ($params->max_height() < $height || $params->sizing->max_crop) |
---|
40 | continue; |
---|
41 | if ($params->max_height() > 3*$height) |
---|
42 | break; |
---|
43 | $this->candidates[] = $params; |
---|
44 | } |
---|
45 | $this->default = ImageStdParams::get_custom($height*3, $height, 1, 0, $height ); |
---|
46 | $this->height = $height; |
---|
47 | } |
---|
48 | |
---|
49 | function pick($src_image) |
---|
50 | { |
---|
51 | $ok = false; |
---|
52 | foreach($this->candidates as $candidate) |
---|
53 | { |
---|
54 | $deriv = new DerivativeImage($candidate, $src_image); |
---|
55 | $size = $deriv->get_size(); |
---|
56 | if ($size[1]>=$row_height-2) |
---|
57 | { |
---|
58 | $ok = true; |
---|
59 | break; |
---|
60 | } |
---|
61 | } |
---|
62 | if (!$ok) |
---|
63 | { |
---|
64 | $deriv = new DerivativeImage($this->default, $src_image); |
---|
65 | } |
---|
66 | return $deriv; |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | //Retrive all pictures on thumbnails page |
---|
71 | add_event_handler('loc_index_thumbnails_selection', 'sp_select_all_thumbnails'); |
---|
72 | |
---|
73 | function sp_select_all_thumbnails($selection) |
---|
74 | { |
---|
75 | global $page, $template; |
---|
76 | |
---|
77 | $template->assign('page_selection', array_flip($selection)); |
---|
78 | $template->assign('thumb_picker', new SPThumbPicker() ); |
---|
79 | return $page['items']; |
---|
80 | } |
---|
81 | |
---|
82 | // Retrive all categories on thumbnails page |
---|
83 | add_event_handler('loc_end_index_category_thumbnails', 'sp_select_all_categories'); |
---|
84 | |
---|
85 | function sp_select_all_categories($selection) |
---|
86 | { |
---|
87 | global $tpl_thumbnails_var; |
---|
88 | return $tpl_thumbnails_var; |
---|
89 | } |
---|
90 | |
---|
91 | // Get better derive parameters for screen size |
---|
92 | $type = IMG_LARGE; |
---|
93 | if (!empty($_COOKIE['screen_size'])) |
---|
94 | { |
---|
95 | $screen_size = explode('x', $_COOKIE['screen_size']); |
---|
96 | foreach (ImageStdParams::get_all_type_map() as $type => $map) |
---|
97 | { |
---|
98 | if (max($map->sizing->ideal_size) >= max($screen_size) and min($map->sizing->ideal_size) >= min($screen_size)) |
---|
99 | break; |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | $this->assign('picture_derivative_params', ImageStdParams::get_by_type($type)); |
---|
104 | $this->assign('thumbnail_derivative_params', ImageStdParams::get_by_type(IMG_SQUARE)); |
---|
105 | |
---|
106 | //------------------------------------------------------------- mobile version & theme config |
---|
107 | add_event_handler('init', 'mobile_link'); |
---|
108 | |
---|
109 | function mobile_link() |
---|
110 | { |
---|
111 | global $template, $conf; |
---|
112 | $config = unserialize( $conf['smartpocket'] ); |
---|
113 | $template->assign( 'smartpocket', $config ); |
---|
114 | if ( !empty($conf['mobile_theme']) && (get_device() != 'desktop' || mobile_theme())) |
---|
115 | { |
---|
116 | $template->assign(array( |
---|
117 | 'TOGGLE_MOBILE_THEME_URL' => add_url_params(duplicate_index_url(),array('mobile' => mobile_theme() ? 'false' : 'true')), |
---|
118 | )); |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | |
---|
123 | if ( !function_exists( 'add_menu_on_public_pages' ) ) { |
---|
124 | if ( defined('IN_ADMIN') and IN_ADMIN ) return false; |
---|
125 | add_event_handler('loc_after_page_header', 'add_menu_on_public_pages', 20); |
---|
126 | |
---|
127 | function add_menu_on_public_pages() { |
---|
128 | if ( function_exists( 'initialize_menu') ) return false; # The current page has already the menu |
---|
129 | global $template, $page, $conf; |
---|
130 | if ( isset($page['body_id']) and $page['body_id']=="thePicturePage" ) |
---|
131 | { |
---|
132 | $template->set_filenames(array( |
---|
133 | 'add_menu_on_public_pages' => dirname(__FILE__) . '/template/add_menu_on_public_pages.tpl', |
---|
134 | )); |
---|
135 | include_once(PHPWG_ROOT_PATH.'include/menubar.inc.php'); |
---|
136 | $template->parse('add_menu_on_public_pages'); |
---|
137 | } |
---|
138 | |
---|
139 | |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | ?> |
---|