Ignore:
Timestamp:
Jun 3, 2011, 1:57:17 PM (13 years ago)
Author:
mistic100
Message:

clean code, add some options

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Front2Back/Front2Back.php

    r9784 r11217  
    44function Front2Back_content($content, $image)
    55{
    6         global $template, $conf;
    7         $conf['Front2Back'] = explode(',', $conf['Front2Back']);
    8         load_language('plugin.lang', F2B_PATH);
     6  global $template, $conf, $user;
     7  $conf['Front2Back'] = explode(',', $conf['Front2Back']);
     8  load_language('plugin.lang', F2B_PATH);
    99
    10         /* dirs and files */
    11         if (empty($conf['Front2Back'][0])) {
    12                 $verso_dir = str_replace($image['file'], null, $image['path']) . $conf['Front2Back'][1];
    13                 $hd_dir = str_replace($image['file'], null, $image['path']) . $conf['Front2Back'][2];
    14         } else {
    15                 $verso_dir = PHPWG_ROOT_PATH . $conf['Front2Back'][0] . $conf['Front2Back'][1];
    16                 $hd_dir = PHPWG_ROOT_PATH . $conf['Front2Back'][0] . $conf['Front2Back'][2];
    17         }
    18         $verso_file = get_filename_wo_extension($image['file']) . $conf['Front2Back'][3] . '.' . get_extension($image['file']);
    19         $rotat_file = get_filename_wo_extension($image['file']) . '-r.' . get_extension($image['file']);
     10  /* dirs and files */
     11  if (empty($conf['Front2Back'][0])) {
     12    $verso_dir = str_replace($image['file'], null, $image['path']) . $conf['Front2Back'][1];
     13    $hd_dir = str_replace($image['file'], null, $image['path']) . $conf['Front2Back'][2];
     14  } else {
     15    $verso_dir = PHPWG_ROOT_PATH . $conf['Front2Back'][0] . $conf['Front2Back'][1];
     16    $hd_dir = PHPWG_ROOT_PATH . $conf['Front2Back'][0] . $conf['Front2Back'][2];
     17  }
     18  $verso_file = get_filename_wo_extension($image['file']) . $conf['Front2Back'][3] . '.' . get_extension($image['file']);
     19  $rotat_file = get_filename_wo_extension($image['file']) . '-r.' . get_extension($image['file']);
    2020
    21         $template->set_filenames(array('Front2Back' => dirname(__FILE__) . '/template/Front2Back.tpl') );
    22         $template->assign('F2B_PATH', F2B_PATH);
     21  /* Is there a verso file ? */
     22  if (is_file($verso_dir.$verso_file))
     23  {
     24    $template->assign('VERSO_URL', $verso_dir.$verso_file);
    2325
    24         /* Is there a verso file ? */
    25         if (is_file($verso_dir.$verso_file))
    26         {
    27                 $template->assign('VERSO_URL', $verso_dir.$verso_file);
     26    if (is_file($hd_dir.$verso_file)) {
     27      $template->assign('VERSO_HD', $hd_dir.$verso_file);
     28    }
     29  }
     30  /* useless section, just for retrocompatibility */
     31  else if (is_file($verso_dir.$rotat_file))
     32  {           
     33    $template->assign('VERSO_URL', $verso_dir.$rotat_file);
     34   
     35    if (is_file($hd_dir.$rotat_file)) {
     36      $template->assign('VERSO_HD', $hd_dir.$rotat_file);
     37    }
     38  }
     39  /* otherwise */
     40  else
     41  {
     42    return $content;
     43  }
     44 
     45  /* link name */
     46  $conf['Front2Back'][7] = unserialize($conf['Front2Back'][7]);
     47  if (!empty($conf['Front2Back'][7][$user['language']]))
     48  {
     49    $conf['Front2Back'][7] = explode('|', $conf['Front2Back'][7][$user['language']]);
     50  }
     51  else if (!empty($conf['Front2Back'][7]['default']))
     52  {
     53    $conf['Front2Back'][7] = explode('|', $conf['Front2Back'][7]['default']);
     54  }
     55  else
     56  {
     57    $conf['Front2Back'][7] = array(l10n('See back'), l10n('See front'));
     58  }
     59 
     60  $template->set_filenames(array('Front2Back' => dirname(__FILE__) . '/template/Front2Back.tpl') );
     61  $template->assign(array(
     62    'F2B_PATH' => F2B_PATH,
     63    'F2B_position' => $conf['Front2Back'][4],
     64    'F2B_switch_mode' => $conf['Front2Back'][5],
     65    'F2B_transition' => $conf['Front2Back'][6],
     66    'F2B_see_back' => $conf['Front2Back'][7][0],
     67    'F2B_see_front' => $conf['Front2Back'][7][1],
     68  ));
     69 
     70  switch ($conf['Front2Back'][4])
     71  {
     72    case 'toolbar':
     73      $template->set_prefilter('picture', 'Front2Back_toolbar_prefilter');
     74      return $content; 
     75      break;
     76    case 'top':
     77      return $template->parse('Front2Back', true)."\n".$content;
     78      break;
     79    case 'bottom':
     80      return $content."\n".$template->parse('Front2Back', true);
     81      break;
     82  }
    2883
    29                 if (is_file($hd_dir.$verso_file)) {
    30                         $template->assign('VERSO_HD', $hd_dir.$verso_file);
    31                 }
    32         }
    33         /* useless section, just for retrocompatibility */
    34         else if (is_file($verso_dir.$rotat_file))
    35         {           
    36                 $template->assign('VERSO_URL', $verso_dir.$rotat_file);
    37                
    38                 if (is_file($hd_dir.$rotat_file)) {
    39                         $template->assign('VERSO_HD', $hd_dir.$rotat_file);
    40                 }
    41         }
    42         /* otherwise */
    43         else
    44         {
    45                 return $content;
    46         }
    47        
    48         return $content . $template->parse('Front2Back', true);   
    4984
    5085
     86function Front2Back_toolbar_prefilter($content, &$smarty)
     87{
     88  $search = '{/if}{/strip}{*caddie management END*}';
     89  $replacement = $search."\n".file_get_contents(F2B_PATH.'template/Front2Back.tpl');
     90  return str_replace($search, $replacement, $content);
     91}
     92
    5193?>
Note: See TracChangeset for help on using the changeset viewer.