12, 'automatic_size_height_margin' => 40, 'automatic_size_min_ratio' => 0.2, 'automatic_size_max_ratio' => 5, ); foreach ($asize_conf_default_values as $key => $value) { if (!isset($conf[$key])) { $conf[$key] = $value; } } if ( !empty($content) ) {// someone hooked us - so we skip; return $content; } if (isset($_COOKIE['picture_deriv'])) { if ( array_key_exists($_COOKIE['picture_deriv'], ImageStdParams::get_defined_type_map()) ) { pwg_set_session_var('picture_deriv', $_COOKIE['picture_deriv']); } setcookie('picture_deriv', false, 0, cookie_path() ); } $deriv_type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']); $selected_derivative = $element_info['derivatives'][$deriv_type]; $unique_derivatives = array(); $show_original = isset($element_info['element_url']); $added = array(); foreach($element_info['derivatives'] as $type => $derivative) { if ($type==IMG_SQUARE || $type==IMG_THUMB) continue; if (!array_key_exists($type, ImageStdParams::get_defined_type_map())) continue; $url = $derivative->get_url(); if (isset($added[$url])) continue; $added[$url] = 1; $show_original &= !($derivative->same_as_source()); $unique_derivatives[$type]= $derivative; if (isset($_COOKIE['available_size'])) { $available_size = explode('x', $_COOKIE['available_size']); $size = $derivative->get_size(); if ($size) { // if we have a very high picture (such as an infographic), we only try to match width if ($size[0]/$size[1] < $conf['automatic_size_min_ratio']) { if ($size[0] <= $available_size[0]) { $automatic_size = $type; } } // if we have a very wide picture (panoramic), we only try to match height elseif ($size[0]/$size[1] > $conf['automatic_size_max_ratio']) { if ($size[1] <= $available_size[1]) { $automatic_size = $type; } } else { if ($size[0] <= $available_size[0] and $size[1] <= $available_size[1]) { $automatic_size = $type; } } } } } global $page, $template; load_language('plugin.lang', ASIZE_PATH); $template->set_prefilter('picture', 'asize_picture_prefilter'); $is_automatic_size = true; if (@$_COOKIE['is_automatic_size'] == 'no') { $is_automatic_size = false; } $template->assign( array( 'is_automatic_size' => $is_automatic_size, 'ASIZE_URL' => duplicate_picture_url(), ) ); if (isset($automatic_size)) { if ($is_automatic_size) { $selected_derivative = $element_info['derivatives'][$automatic_size]; } $template->assign( array( 'automatic_size' => $automatic_size, 'ASIZE_TITLE' => sprintf( l10n('The best adapted size for this photo and your screen is size %s'), l10n($automatic_size) ) ) ); } if ($show_original) { $template->assign( 'U_ORIGINAL', $element_info['element_url'] ); } $template->append('current', array( 'selected_derivative' => $selected_derivative, 'unique_derivatives' => $unique_derivatives, ), true); $template->set_filenames( array('default_content'=>'picture_content.tpl') ); $template->assign( array( 'ALT_IMG' => $element_info['file'], 'COOKIE_PATH' => cookie_path(), 'asize_width_margin' => $conf['automatic_size_width_margin'], 'asize_height_margin' => $conf['automatic_size_height_margin'], ) ); $template->set_filename('asize_picture_js', realpath(ASIZE_PATH.'picture_js.tpl')); $template->parse('asize_picture_js'); return $template->parse( 'default_content', true); } function asize_picture_prefilter($content, &$smarty) { $pattern = '#\{foreach from=\$current\.unique_derivatives#'; $replacement = ' {\'Automatic\'|@translate}

{foreach from=$current.unique_derivatives'; $content = preg_replace($pattern, $replacement, $content); return $content; } ?>