[3339] | 1 | <?php |
---|
| 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 3 | add_event_handler('render_element_content', |
---|
| 4 | array('Front2Back', 'Front2Back_content'), 99, 2 ); |
---|
| 5 | |
---|
| 6 | class Front2Back |
---|
| 7 | { |
---|
| 8 | function Front2Back_content($content, $image) |
---|
| 9 | { |
---|
| 10 | global $template, $lang, $user, $conf; |
---|
| 11 | /* Default values */ |
---|
| 12 | if (!isset($lang['Front2Back'])) $lang['Front2Back'] = 'See back'; |
---|
| 13 | if (!isset($conf['Front2Back_dir'])) $conf['Front2Back_dir'] = 'verso/'; |
---|
| 14 | if (!isset($conf['Front2Back_vshift'])) $conf['Front2Back_vshift']= 16; |
---|
| 15 | if (!isset($conf['Front2Back_hshift'])) $conf['Front2Back_hshift']= -28; |
---|
| 16 | if (!isset($conf['Front2Back_parent'])) $conf['Front2Back_parent']= 'thumbnail/'; |
---|
| 17 | if (!isset($conf['Front2Back_path'])) $conf['Front2Back_inside']= true; |
---|
| 18 | else $conf['Front2Back_inside']= false; |
---|
| 19 | |
---|
| 20 | /* Build reversal parms and filename */ |
---|
| 21 | if ( $conf['Front2Back_inside'] ) { |
---|
| 22 | $verso = substr( $image['path'], |
---|
| 23 | 0, strrpos( $image['path'], '/' )+1 ) |
---|
| 24 | . $conf['Front2Back_parent'] . $conf['Front2Back_dir']; |
---|
| 25 | } |
---|
| 26 | else { /* example: |
---|
| 27 | $conf['Front2Back_path'] = PHPWG_ROOT_PATH; |
---|
| 28 | $conf['Front2Back_parent'] = 'front2back/'; |
---|
| 29 | $conf['Front2Back_dir'] = ''; |
---|
| 30 | */ |
---|
| 31 | $verso = $conf['Front2Back_path'] |
---|
| 32 | . $conf['Front2Back_parent'] . $conf['Front2Back_dir']; |
---|
| 33 | } |
---|
| 34 | $verso.= $image['file']; |
---|
| 35 | $height = @$image['scaled_height']; |
---|
| 36 | $width = @$image['scaled_width']; |
---|
| 37 | $shift_left = (int) ($width / 2) + $conf['Front2Back_hshift']; |
---|
| 38 | $shift_up = $height + $conf['Front2Back_vshift']; |
---|
| 39 | $rotat = substr($verso,0,-4).'-r'.substr($verso,-4); // extension .jpg 4car. |
---|
| 40 | $template->set_filenames( |
---|
| 41 | array('Front2Back' => dirname(__FILE__) . '/Front2Back.tpl') ); |
---|
| 42 | |
---|
| 43 | $template->assign(array('F2B_PATH' => F2B_PATH)); |
---|
| 44 | if (is_file($verso)) { |
---|
| 45 | $template->assign( |
---|
| 46 | 'verso', |
---|
| 47 | array( |
---|
| 48 | 'VERSO_URL' => $verso, |
---|
| 49 | 'WIDTH_IMG' => $width, |
---|
| 50 | 'HEIGHT_IMG' => $height, |
---|
| 51 | 'HSHIFT_IMG' => $shift_left, |
---|
| 52 | 'VSHIFT_IMG' => $shift_up, |
---|
| 53 | ) |
---|
| 54 | ); |
---|
| 55 | } |
---|
| 56 | elseif (is_file($rotat)) { /* Is there a rotated file ? */ |
---|
| 57 | $shift_left = (int) ($height / 2) + $conf['Front2Back_hshift']; |
---|
| 58 | $template->assign( |
---|
| 59 | 'verso', |
---|
| 60 | array( |
---|
| 61 | 'VERSO_URL' => $rotat, |
---|
| 62 | 'WIDTH_IMG' => $height, /* Swap width/height */ |
---|
| 63 | 'HEIGHT_IMG' => $width, /* "" "" */ |
---|
| 64 | 'HSHIFT_IMG' => $shift_left, |
---|
| 65 | 'VSHIFT_IMG' => $shift_up, |
---|
| 66 | ) |
---|
| 67 | ); |
---|
| 68 | } |
---|
| 69 | else return $content; |
---|
| 70 | return $content . $template->parse('Front2Back', true); |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | ?> |
---|