source: extensions/Automatic_Oversize/main.inc.php @ 31834

Last change on this file since 31834 was 31834, checked in by lexming, 7 years ago

Initial commit

File size: 2.9 KB
Line 
1<?php
2/*
3Plugin Name: Automatic Oversize
4Version: 1.0
5Description: Automatically selects the smallest image size required to cover the full screen
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=854
7Author: lexming
8Author URI: http://piwigo.org/forum/profile.php?id=23261
9Note: This plugin is heavily based on the Automatic Size plugin by plg
10      (http://piwigo.org/ext/extension_view.php?eid=702)
11*/
12
13if (!defined('PHPWG_ROOT_PATH'))
14{
15  die('Hacking attempt!');
16}
17
18define('ASIZE_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
19
20add_event_handler(
21  'render_element_content',
22  'asize_picture_content',
23  EVENT_HANDLER_PRIORITY_NEUTRAL-1,
24  2
25  );
26
27function asize_picture_content($content, $element_info)
28{
29  global $conf;
30
31  if ( !empty($content) )
32  {// someone hooked us - so we skip;
33    return $content;
34  }
35
36  if (isset($_COOKIE['picture_deriv']))
37  {
38    if ( array_key_exists($_COOKIE['picture_deriv'], ImageStdParams::get_defined_type_map()) )
39    {
40      pwg_set_session_var('picture_deriv', $_COOKIE['picture_deriv']);
41    }
42  }
43  $deriv_type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']);
44  $selected_derivative = $element_info['derivatives'][$deriv_type];
45  $unique_derivatives = array();
46  $show_original = isset($element_info['element_url']);
47  $added = array();
48  foreach(array_reverse($element_info['derivatives']) as $type => $derivative)
49  {
50    if ($type==IMG_SQUARE || $type==IMG_THUMB)
51      continue;
52    if (!array_key_exists($type, ImageStdParams::get_defined_type_map()))
53      continue;
54    $url = $derivative->get_url();
55    if (isset($added[$url]))
56      continue;
57    $added[$url] = 1;
58    $show_original &= !($derivative->same_as_source());
59    $unique_derivatives[$type]= $derivative;
60
61    if (isset($_COOKIE['available_size']) and !isset($_COOKIE['picture_deriv']))
62    {
63      $available_size = explode('x', $_COOKIE['available_size']);
64
65      $size = $derivative->get_size();
66      if (!isset($automatic_size) or ($size and ($size[0] >= $available_size[0] or $size[1] >= $available_size[1])))
67      {
68        $automatic_size = $type;
69      }
70    }
71  }
72
73  global $page, $template;
74
75  if (isset($automatic_size)) {
76    $selected_derivative = $element_info['derivatives'][$automatic_size];
77  }
78       
79  if ($show_original)
80  {
81    $template->assign( 'U_ORIGINAL', $element_info['element_url'] );
82  }
83
84  $template->append('current', array(
85      'selected_derivative' => $selected_derivative,
86      'unique_derivatives' => $unique_derivatives,
87    ), true);
88
89
90  $template->set_filenames(
91    array('default_content'=>'picture_content.tpl')
92    );
93
94  $template->assign( array(
95      'ALT_IMG' => $element_info['file'],
96      'COOKIE_PATH' => cookie_path() )
97    );
98
99  $template->set_filename('asize_picture_js', realpath(ASIZE_PATH.'picture_js.tpl'));
100  $template->parse('asize_picture_js');
101 
102  return $template->parse( 'default_content', true);
103}
104
105
106?>
Note: See TracBrowser for help on using the repository browser.