[12770] | 1 | <?php /* |
---|
| 2 | Plugin Name: Dynamic images |
---|
| 3 | Version: 0 |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | global $conf; |
---|
| 7 | // 0-'auto', 1-'derivative' 2-'script' |
---|
| 8 | $conf['derivative_url_style']=0; |
---|
| 9 | |
---|
| 10 | defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', PWG_LOCAL_DIR.'i/'); |
---|
| 11 | |
---|
| 12 | include_once( dirname(__FILE__) .'/include/derivative_params.inc.php'); |
---|
| 13 | include_once( dirname(__FILE__) .'/include/derivative_std_params.inc.php'); |
---|
| 14 | include_once( dirname(__FILE__) .'/include/derivative.inc.php'); |
---|
| 15 | |
---|
| 16 | ImageStdParams::load_from_db(); |
---|
| 17 | |
---|
| 18 | add_event_handler('get_thumbnail_url', 'dyn_thumb_url', 60, 2); |
---|
| 19 | |
---|
| 20 | function dyn_thumb_url($url, $infos) |
---|
| 21 | { |
---|
| 22 | $url2 = DerivativeImage::thumb_url($infos); |
---|
| 23 | return $url2; |
---|
| 24 | } |
---|
| 25 | |
---|
[12775] | 26 | |
---|
| 27 | add_event_handler( |
---|
| 28 | 'render_element_content', |
---|
| 29 | 'dyn_render_picture_content', |
---|
| 30 | EVENT_HANDLER_PRIORITY_NEUTRAL-1, |
---|
| 31 | 2 |
---|
| 32 | ); |
---|
| 33 | |
---|
| 34 | function dyn_render_picture_content($content, $element_info) |
---|
| 35 | { |
---|
| 36 | if ( !empty($content) ) |
---|
| 37 | {// someone hooked us - so we skip; |
---|
| 38 | return $content; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | $all_derivatives = DerivativeImage::get_all($element_info); |
---|
| 42 | //var_export($all_derivatives); |
---|
| 43 | $selected_derivative = $all_derivatives[IMG_LARGE]; |
---|
| 44 | |
---|
| 45 | $available_derivatives = array(); |
---|
| 46 | $added = array(); |
---|
| 47 | foreach($all_derivatives as $type => $derivative) |
---|
| 48 | { |
---|
| 49 | $url = $derivative->get_url(); |
---|
| 50 | if (isset($added[$url])) |
---|
| 51 | continue; |
---|
| 52 | $added[$url] = 1; |
---|
| 53 | $available_derivatives[] = $type; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | global $user, $page, $template; |
---|
| 58 | |
---|
| 59 | $template->set_filenames( |
---|
| 60 | array('default_content'=> dirname(__FILE__).'/picture_content.tpl') |
---|
| 61 | ); |
---|
| 62 | |
---|
| 63 | $template->append('current', array( |
---|
| 64 | 'all_derivatives' => $all_derivatives, |
---|
| 65 | 'selected_derivative' => $selected_derivative, |
---|
| 66 | 'available_derivative_types' => $available_derivatives, |
---|
| 67 | ), true); |
---|
| 68 | |
---|
| 69 | $template->assign( array( |
---|
| 70 | 'ALT_IMG' => $element_info['file'] )); |
---|
| 71 | |
---|
| 72 | return $template->parse( 'default_content', true);; |
---|
| 73 | } |
---|
[12770] | 74 | ?> |
---|