Ignore:
Timestamp:
Mar 19, 2011, 10:41:40 PM (13 years ago)
Author:
mistic100
Message:

[extensions] Front2Back

  • compatibility with 2.2.0
  • jQuery method for swap
  • localisation
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Front2Back/Front2Back.php

    r3339 r9782  
    11<?php
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    3 add_event_handler('render_element_content',
    4     array('Front2Back', 'Front2Back_content'), 99, 2 );
    53
    6 class Front2Back
     4function Front2Back_content($content, $image)
    75{
    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') );
     6        global $template, $conf;
     7       
     8        /* Default values */
     9        if (!isset($conf['Front2Back_dir'])) $conf['Front2Back_dir'] = 'verso/';
     10        if (!isset($conf['Front2Back_parent'])) $conf['Front2Back_parent'] = 'thumbnail/';
     11        if (!isset($conf['Front2Back_hd_parent'])) $conf['Front2Back_hd_parent'] = 'pwg_high/';
     12        if (!isset($conf['Front2Back_path']))
     13                $conf['Front2Back_inside']= true;
     14        else
     15                $conf['Front2Back_inside']= false;
    4216
    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 }
     17        /* dirs and files */
     18        if ( $conf['Front2Back_inside'] ) {
     19                $verso_dir = str_replace($image['file'], null, $image['path']) . $conf['Front2Back_parent'] . $conf['Front2Back_dir'];
     20                $hd_dir = str_replace($image['file'], null, $image['path']) . $conf['Front2Back_hd_parent'] . $conf['Front2Back_dir'];
     21        } else {
     22                $verso_dir = $conf['Front2Back_path'] . $conf['Front2Back_parent'] . $conf['Front2Back_dir'];
     23                $hd_dir = $conf['Front2Back_path'] . $conf['Front2Back_hd_parent'] . $conf['Front2Back_dir'];
     24        }
     25        $rotat_file = substr($image['file'],0,-4).'-r'.substr($image['file'],-4);
     26
     27        $template->set_filenames(array('Front2Back' => dirname(__FILE__) . '/Front2Back.tpl') );
     28        $template->assign('F2B_PATH', F2B_PATH);
     29
     30        /* Is there a verso file ? */
     31        if (is_file($verso_dir.$image['file']))
     32        {
     33                $template->assign('VERSO_URL', $verso_dir.$image['file']);
     34
     35                if (is_file($hd_dir.$image['file'])) {
     36                        $template->assign('VERSO_HD', $hd_dir.$image['file']);
     37                }
     38        }
     39        /* useless section, just for retrocompatibility */
     40        else if (is_file($verso_dir.$rotat_file))
     41        {           
     42                $template->assign('VERSO_URL', $verso_dir.$rotat_file);
     43               
     44                if (is_file($hd_dir.$rotat_file)) {
     45                        $template->assign('VERSO_HD', $hd_dir.$rotat_file);
     46                }
     47        }
     48        /* otherwise */
     49        else
     50        {
     51                return $content;
     52        }
     53       
     54        return $content . $template->parse('Front2Back', true);   
     55
     56
    7357?>
Note: See TracChangeset for help on using the changeset viewer.