Changeset 23177


Ignore:
Timestamp:
Jun 13, 2013, 2:01:34 PM (7 years ago)
Author:
mistic100
Message:

use serialized array for config + custom upgrade process

Location:
extensions/Back2Front
Files:
3 added
6 edited
2 moved

Legend:

Unmodified
Added
Removed
  • extensions/Back2Front/admin.php

    r12361 r23177  
    33
    44global $conf, $template;
    5 load_language('plugin.lang', B2F_PATH);
    6 $conf['back2front'] = explode(',', $conf['back2front']);
    75
    8 include_once(B2F_PATH.'functions.inc.php');
     6include_once(B2F_PATH . 'include/functions.inc.php');
    97
    108// Enregistrement de la configuration
     
    1210{
    1311  $conf['back2front'] = array(
    14     $conf['back2front'][0],
    15     $_POST['switch_mode'],
    16     $_POST['transition'],
    17     $_POST['position'],
    18     serialize(stripslashes_deep(str_replace(array("'",'"',','), null, $_POST['link_name']))),
    19     isset($_POST['show_thumbnail']),
    20   );
     12    'versos_cat' => $conf['back2front']['versos_cat'],
     13    'switch_mode' => $_POST['switch_mode'],
     14    'transition' => $_POST['transition'],
     15    'position' => $_POST['position'],
     16    'link_name' => stripslashes_deep($_POST['link_name']),
     17    'show_thumbnail' => isset($_POST['show_thumbnail']),
     18    );
    2119 
    22   conf_update_param('back2front', implode (',', $conf['back2front']));
     20  conf_update_param('back2front', serialize($conf['back2front']));
    2321  array_push($page['infos'], l10n('Information data registered in database'));
    2422}
    2523
    2624// Gestion des langues pour le bloc menu
    27 $conf['back2front'][4] = unserialize($conf['back2front'][4]);
    2825$template->append('link_name', array(
    2926  'LANGUAGE_NAME' => l10n('Default'),
    3027  'LANGUAGE_CODE' => 'default',
    31   'VALUE' => @$conf['back2front'][4]['default'],
    32   )
    33 );
     28  'VALUE' => @$conf['back2front']['link_name']['default'],
     29  ));
     30 
    3431foreach (get_languages() as $language_code => $language_name)
    3532{
     
    3734    'LANGUAGE_NAME' => $language_name,
    3835    'LANGUAGE_CODE' => $language_code,
    39     'VALUE' => isset($conf['back2front'][4][$language_code]) ? $conf['back2front'][4][$language_code] : '',
    40     )
    41   );
     36    'VALUE' => @$conf['back2front']['link_name'][$language_code],
     37    ));
    4238}
    4339
    4440$template->assign(array(
    4541  'B2F_PATH' => B2F_PATH,
    46   'SWITCH_MODE' => $conf['back2front'][1],
    47   'TRANSITION' => $conf['back2front'][2],
    48   'POSITION' => $conf['back2front'][3],
    49   'SHOW_THUMBNAIL' => $conf['back2front'][5],
    50 ));
     42  'SWITCH_MODE' => $conf['back2front']['switch_mode'],
     43  'TRANSITION' => $conf['back2front']['transition'],
     44  'POSITION' => $conf['back2front']['position'],
     45  'SHOW_THUMBNAIL' => $conf['back2front']['show_thumbnail'],
     46  ));
    5147 
    52 $template->set_filename('back2front_conf', dirname(__FILE__).'/template/admin.tpl');
     48$template->set_filename('back2front_conf', realpath(B2F_PATH.'template/admin.tpl'));
    5349$template->assign_var_from_handle('ADMIN_CONTENT', 'back2front_conf');
    5450
  • extensions/Back2Front/include/Back2Front.php

    r23167 r23177  
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    33
    4 include_once(B2F_PATH.'functions.inc.php');
     4include_once(B2F_PATH.'include/functions.inc.php');
    55
    66/*
    77 * Add verso link on picture page
    88 */
    9 function Back2Front_picture_content($content, $element_info)
     9function back2front_picture_content($content, $element_info)
    1010{
    1111  global $template, $user, $conf;
    1212
    1313  /* search for a verso picture */
    14   $query = "
    15     SELECT i.*
    16     FROM ".IMAGES_TABLE." as i
    17       INNER JOIN ".B2F_TABLE." as v
    18       ON i.id = v.verso_id
    19       AND v.image_id = ".$element_info['id']."
    20   ;";
     14  $query = '
     15SELECT i.*
     16  FROM '.IMAGES_TABLE.' as i
     17    INNER JOIN '.B2F_TABLE.' as v
     18    ON i.id = v.verso_id
     19    AND v.image_id = '.$element_info['id'].'
     20;';
    2121  $result = pwg_query($query);
    2222
     
    2424  {
    2525    $verso = pwg_db_fetch_assoc($result);
    26     $conf['back2front'] = explode(',',$conf['back2front']);
    2726    $deriv_type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']);
    2827   
     
    4241    {
    4342      $template->assign('VERSO_U_ADMIN', get_root_url().'admin.php?page=photo-'.$verso['id']);
    44       $template->set_filename('B2F_admin_button', dirname(__FILE__).'/template/admin_button.tpl');
     43      $template->set_filename('B2F_admin_button', realpath(B2F_PATH.'template/admin_button.tpl'));
    4544      $template->concat('PLUGIN_PICTURE_ACTIONS', $template->parse('B2F_admin_button', true));
    4645    }
    4746   
    4847    /* link name */
    49     $conf['back2front'][4] = unserialize($conf['back2front'][4]);
    50     if (!empty($conf['back2front'][4][$user['language']]))
    51     {
    52       if (strpos($conf['back2front'][4][$user['language']], '|') !== false)
    53       {
    54         $conf['back2front'][4] = explode('|', $conf['back2front'][4][$user['language']]);
     48    if (!empty($conf['back2front']['link_name'][$user['language']]))
     49    {
     50      if (strpos($conf['back2front']['link_name'][$user['language']], '|') !== false)
     51      {
     52        $conf['back2front']['link_name'] = explode('|', $conf['back2front']['link_name'][$user['language']]);
    5553      }
    5654      else
    5755      {
    58         $conf['back2front'][4] = array($conf['back2front'][4][$user['language']], $conf['back2front'][4][$user['language']]);
    59       }
    60     }
    61     else if (!empty($conf['back2front'][4]['default']))
    62     {
    63       if (strpos($conf['back2front'][4]['default'], '|') != false)
    64       {
    65         $conf['back2front'][4] = explode('|', $conf['back2front'][4]['default']);
     56        $conf['back2front']['link_name'] = array_fill(0, 2, $conf['back2front']['link_name'][$user['language']]);
     57      }
     58    }
     59    else if (!empty($conf['back2front']['link_name']['default']))
     60    {
     61      if (strpos($conf['back2front']['link_name']['default'], '|') != false)
     62      {
     63        $conf['back2front']['link_name'] = explode('|', $conf['back2front']['link_name']['default']);
    6664      }
    6765      else
    6866      {
    69         $conf['back2front'][4] = array($conf['back2front'][4]['default'], $conf['back2front'][4]['default']);
     67        $conf['back2front']['link_name'] = array_fill(0, 2, $conf['back2front']['link_name']['default']);
    7068      }
    7169    }
    7270    else
    7371    {
    74       $conf['back2front'][4] = array(l10n('See back'), l10n('See front'));
    75     }
    76    
    77     if ($conf['back2front'][2] == 'fade' and $conf['back2front'][3] == 'bottom')
    78     {
    79       $conf['back2front'][3] = 'top';
     72      $conf['back2front']['link_name'] = array(l10n('See back'), l10n('See front'));
     73    }
     74   
     75    if ($conf['back2front']['transition'] == 'fade' && $conf['back2front']['position'] == 'bottom')
     76    {
     77      $conf['back2front']['position'] = 'top';
    8078    }
    8179   
    8280
    8381    /* template & output */
    84     $template->set_filename('B2F_picture_content', dirname(__FILE__).'/template/picture_content.tpl');   
     82    $template->set_filename('B2F_picture_content', realpath(B2F_PATH.'template/picture_content.tpl'));   
    8583    $template->assign(array(
    86       'b2f_switch_mode' => $conf['back2front'][1],
    87       'b2f_transition' => $conf['back2front'][2],
    88       'b2f_position' => $conf['back2front'][3],
    89       'b2f_see_back' => $conf['back2front'][4][0],
    90       'b2f_see_front' => $conf['back2front'][4][1],
     84      'b2f_switch_mode' => $conf['back2front']['switch_mode'],
     85      'b2f_transition' => $conf['back2front']['transition'],
     86      'b2f_position' => $conf['back2front']['position'],
     87      'b2f_see_back' => $conf['back2front']['link_name'][0],
     88      'b2f_see_front' => $conf['back2front']['link_name'][1],
    9189    ));
    9290   
    93     switch ($conf['back2front'][3])
     91    switch ($conf['back2front']['position'])
    9492    {
    9593      case 'toolbar':
     
    9795        break;
    9896      case 'top':
    99         return $template->parse('B2F_picture_content', true)."\n".$content;
     97        $content = $template->parse('B2F_picture_content', true)."\n".$content;
    10098        break;
    10199      case 'bottom':
    102         return $content."\n".$template->parse('B2F_picture_content', true);
     100        $content = $content."\n".$template->parse('B2F_picture_content', true);
    103101        break;
    104102    }   
     
    112110 * Add field on picture modify page
    113111 */
    114 function Back2Front_picture_modify()
     112function back2front_picture_modify()
    115113{
    116114  global $page, $template, $conf;
     
    118116  if ($page['page'] != 'photo') return;
    119117  if (isset($_GET['tab']) && $_GET['tab']!='properties') return;
    120  
    121  
    122   $conf['back2front'] = explode(',',$conf['back2front']);
    123118 
    124119/* SAVE VALUES */
     
    126121  {
    127122    /* catch all verso and recto ids and original categories */
    128     $query = "SELECT image_id, verso_id, categories
    129       FROM ".B2F_TABLE.";";
    130     $rectos = array_from_query($query, 'image_id');
    131     $versos = array_from_query($query, 'verso_id');
    132     $cats = array_from_query($query, 'categories');
     123    $query = 'SELECT * FROM '.B2F_TABLE.';';
     124    $result = pwg_query($query);
     125   
     126    $rectos = $versos = $cats = array();
     127    while ($row = pwg_db_fetch_assoc($result))
     128    {
     129      $rectos[] = $row['image_id'];
     130      $versos[] = $row['verso_id'];
     131      $cats[] = $row['categories'];
     132    }
    133133   
    134134    if (count($rectos) != 0)
     
    140140    {
    141141      $all_recto_verso = array(0=>0);
    142       $verso_cats = array(0=>NULL);
     142      $verso_cats = array(0=>null);
    143143    }
    144144    unset($rectos, $versos, $cats);
     
    150150      if (!picture_exists($_POST['b2f_front_id']))
    151151      {
    152         array_push(
    153           $page['errors'],
    154           sprintf(
    155             l10n('Unknown id %d for frontside picture'),
    156             $_POST['b2f_front_id']
    157             )
    158           );
     152        array_push($page['errors'], sprintf(
     153          l10n('Unknown id %d for frontside picture'),
     154          $_POST['b2f_front_id']
     155          ));
    159156      }
    160157      /* verso same as recto  */
     
    164161      }
    165162      /* recto has already a verso */
    166       else if (in_array($_POST['b2f_front_id'], array_keys($all_recto_verso)) AND $all_recto_verso[$_POST['b2f_front_id']] != $_GET['image_id'])
    167       {
    168           $recto_current_verso['id'] = $all_recto_verso[$_POST['b2f_front_id']];
    169           $recto_current_verso['link'] = get_root_url().'admin.php?page=photo-'.$recto_current_verso['id'];
    170           array_push(
    171             $page['errors'],
    172             sprintf(
    173               l10n('The picture n°%d has already a backside : %s'),
    174               $_POST['b2f_front_id'],
    175               '<a href="'.$recto_current_verso['link'].'">'.$recto_current_verso['id'].'</a>'
    176               )
    177             );
     163      else if (in_array($_POST['b2f_front_id'], array_keys($all_recto_verso)) && $all_recto_verso[$_POST['b2f_front_id']] != $_GET['image_id'])
     164      {
     165        $recto_current_verso['id'] = $all_recto_verso[$_POST['b2f_front_id']];
     166        $recto_current_verso['link'] = get_root_url().'admin.php?page=photo-'.$recto_current_verso['id'];
     167       
     168        array_push($page['errors'], sprintf(
     169          l10n('The picture n°%d has already a backside : %s'),
     170          $_POST['b2f_front_id'],
     171          '<a href="'.$recto_current_verso['link'].'">'.$recto_current_verso['id'].'</a>'
     172          ));
    178173      }
    179174      /* recto is already a verso */
    180175      else if (in_array($_POST['b2f_front_id'], array_values($all_recto_verso)))
    181176      {
    182           $recto_is_verso['id'] = $_POST['b2f_front_id'];
    183           $recto_is_verso['link'] = get_root_url().'admin.php?page=picture_modify&amp;image_id='.$recto_is_verso['id'];
    184           array_push(
    185             $page['errors'],
    186             sprintf(
    187               l10n('The picture n°%s is already a backside'),
    188               '<a href="'.$recto_is_verso['link'].'">'.$recto_is_verso['id'].'</a>'
    189               )
    190             );
     177        $recto_is_verso['id'] = $_POST['b2f_front_id'];
     178        $recto_is_verso['link'] = get_root_url().'admin.php?page=picture_modify&amp;image_id='.$recto_is_verso['id'];
     179       
     180        array_push($page['errors'],  sprintf(
     181          l10n('The picture n°%s is already a backside'),
     182          '<a href="'.$recto_is_verso['link'].'">'.$recto_is_verso['id'].'</a>'
     183          ));
    191184      }
    192185      /* everything is fine */
     
    194187      {
    195188        // move the verso - if first save
    196         if (isset($_POST['b2f_move_verso']) AND (!array_key_exists($_GET['image_id'], $verso_cats) OR $verso_cats[$_GET['image_id']] == NULL))
     189        if (isset($_POST['b2f_move_verso']) && (!array_key_exists($_GET['image_id'], $verso_cats) || $verso_cats[$_GET['image_id']] == null))
    197190        {
    198191          // get current categories
    199           $query = "SELECT category_id FROM ".IMAGE_CATEGORY_TABLE." WHERE image_id = ".$_GET['image_id'].";";
     192          $query = 'SELECT category_id FROM '.IMAGE_CATEGORY_TABLE.' WHERE image_id = '.$_GET['image_id'].';';
    200193          $verso_categories = array_from_query($query, 'category_id');
    201194         
    202           pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE."
    203             WHERE image_id = ".$_GET['image_id'].";");
    204           pwg_query("INSERT INTO ".IMAGE_CATEGORY_TABLE."(image_id, category_id)
    205             VALUES(".$_GET['image_id'].", ".$conf['back2front'][0].");");
     195          pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE image_id = '.$_GET['image_id'].';');
     196          pwg_query('INSERT INTO '.IMAGE_CATEGORY_TABLE.'(image_id, category_id) VALUES('.$_GET['image_id'].', '.$conf['back2front']['versos_cat'].');');
    206197           
    207198          // random representant for each categories
     
    212203        }
    213204        // restore the verso - if precedently moved
    214         else if (!isset($_POST['b2f_move_verso']) AND array_key_exists($_GET['image_id'], $verso_cats) AND $verso_cats[$_GET['image_id']] != NULL)
     205        else if (!isset($_POST['b2f_move_verso']) && array_key_exists($_GET['image_id'], $verso_cats) && $verso_cats[$_GET['image_id']] != null)
    215206        {
    216207          $item['verso_id'] = $_GET['image_id'];
     
    229220       
    230221        // insert or update verso associations
    231         pwg_query("INSERT INTO ".B2F_TABLE."
    232           VALUES(".$_POST['b2f_front_id'].", ".$_GET['image_id'].", '".$verso_categories."')
    233           ON DUPLICATE KEY UPDATE image_id = ".$_POST['b2f_front_id'].", categories = '".$verso_categories."';");
    234      
     222        $query = '
     223INSERT INTO '.B2F_TABLE.'
     224  VALUES(
     225    '.$_POST['b2f_front_id'].',
     226    '.$_GET['image_id'].',
     227    "'.$verso_categories.'"
     228  )
     229  ON DUPLICATE KEY UPDATE
     230    image_id = '.$_POST['b2f_front_id'].',
     231    categories = "'.$verso_categories.'"
     232;';
     233        pwg_query($query);
     234       
    235235        $template->assign(array(
    236236          'B2F_IS_VERSO' => 'checked="checked"',
     
    240240        $verso['id'] = $_POST['b2f_front_id'];
    241241        $verso['link'] = get_root_url().'admin.php?page=photo-'.$verso['id'];
    242         array_push($page['infos'], l10n_args(get_l10n_args('This picture is now the backside of the picture n°%s', '<a href="'.$verso['link'].'">'.$verso['id'].'</a>')));
     242       
     243        array_push($page['infos'], sprintf(
     244          l10n('This picture is now the backside of the picture n°%s'),
     245          '<a href="'.$verso['link'].'">'.$verso['id'].'</a>'
     246          ));
    243247      }
    244248    }
     
    247251    {
    248252      /* search if it was a verso */
    249       $query = "SELECT categories
    250         FROM ".B2F_TABLE."
    251         WHERE verso_id = ".$_GET['image_id'].";";
     253      $query = '
     254SELECT categories
     255  FROM '.B2F_TABLE.'
     256  WHERE verso_id = '.$_GET['image_id'].'
     257;';
    252258      $result = pwg_query($query);
    253259     
    254       /* it must be restored to its original categories (see criteria on maintain.inc) */
     260      /* it must be restored to its original categories */
    255261      if (pwg_db_num_rows($result))
    256262      {
    257263        $item['verso_id'] = $_GET['image_id'];
    258264        list($item['categories']) = pwg_db_fetch_row($result);
     265       
    259266        back2front_restaure_categories($item);
    260        
    261         pwg_query("DELETE FROM ".B2F_TABLE."
    262           WHERE verso_id = ".$_GET['image_id'].";");
    263          
     267        pwg_query('DELETE FROM '.B2F_TABLE.' WHERE verso_id = '.$_GET['image_id'].';');
    264268        array_push($page['infos'], l10n('This picture is no longer a backside'));
    265269      }
     
    273277   
    274278    /* is the picture a verso ? */
    275     $query = "
    276       SELECT image_id, categories
    277       FROM ".B2F_TABLE."
    278       WHERE verso_id = ".$_GET['image_id']."
    279     ;";
     279    $query = '
     280SELECT image_id, categories
     281  FROM '.B2F_TABLE.'
     282  WHERE verso_id = '.$_GET['image_id'].'
     283;';
    280284    $result = pwg_query($query);
    281285   
     
    283287    {
    284288      list($recto_id, $cats) = pwg_db_fetch_row($result);
     289     
    285290      $template->assign(array(
    286291        'B2F_IS_VERSO' => 'checked="checked"',
     
    292297    else
    293298    {
    294       $query = "SELECT verso_id
    295         FROM ".B2F_TABLE."
    296         WHERE image_id = ".$_GET['image_id'].";";
     299      $query = '
     300SELECT verso_id
     301  FROM '.B2F_TABLE.'
     302  WHERE image_id = '.$_GET['image_id'].'
     303;';
    297304      $result = pwg_query($query);
    298305     
     
    309316  }
    310317 
    311   $template->set_prefilter('picture_modify', 'Back2front_picture_modify_prefilter');
     318  $template->set_prefilter('picture_modify', 'back2front_picture_modify_prefilter');
    312319}
    313320
    314321
    315 function Back2front_picture_modify_prefilter($content, &$smarty)
     322function back2front_picture_modify_prefilter($content, &$smarty)
    316323{
    317324  $search = '</form>';
     
    324331 * Add mark on thumbnails list
    325332 */
    326 function Back2Front_thumbnails($tpl_thumbnails_var)
     333function back2front_thumbnails($tpl_thumbnails_var)
    327334{
    328335  global $conf, $selection;
    329336 
    330   $conf['back2front'] = explode(',',$conf['back2front']);
    331   if (!$conf['back2front'][5]) return $tpl_thumbnails_var;
     337  if (!$conf['back2front']['show_thumbnail']) return $tpl_thumbnails_var;
    332338  if (empty($tpl_thumbnails_var)) return $tpl_thumbnails_var;
    333339   
    334340  /* has the pictures a verso ? */
    335   $query = "SELECT image_id
    336     FROM ".B2F_TABLE."
    337     WHERE image_id IN(".implode(',', $selection).");";
     341  $query = '
     342SELECT image_id
     343  FROM '.B2F_TABLE.'
     344  WHERE image_id IN('.implode(',', $selection).')
     345;';
    338346  $ids = array_from_query($query, 'image_id');
    339347 
  • extensions/Back2Front/include/functions.inc.php

    r23167 r23177  
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    33
    4 /* $item = array('verso_id', 'categories'); */
     4/*
     5 * restore verso to its original categories
     6 * criterias :
     7 *  - verso € 'versos' cat only => restore verso to original categories
     8 *  - otherwise nothing is changed
     9 * 
     10 * $item = array('verso_id', 'categories');
     11*/
    512function back2front_restaure_categories($item)
    613{
    714  global $conf;
    8        
     15 
    916  /* catch current verso categories */
    10   $versos_infos = pwg_query("SELECT category_id FROM ".IMAGE_CATEGORY_TABLE." WHERE image_id = ".$item['verso_id'].";");
    11   $item['current_verso_cats'] = array();
    12   while (list($verso_cat) = pwg_db_fetch_row($versos_infos))
    13   {
    14     $item['current_verso_cats'][] = $verso_cat;
    15   }
     17  $query = 'SELECT DISTINCT category_id FROM '.IMAGE_CATEGORY_TABLE.' WHERE image_id = '.$item['verso_id'].';';
     18  $item['current_verso_cats'] = array_from_query($query, 'category_id');
    1619
    1720  /* if verso € 'versos' cat only */
    18   if (count($item['current_verso_cats']) == 1 AND $item['current_verso_cats'][0] == $conf['back2front'][0])
     21  if (count($item['current_verso_cats']) == 1 && $item['current_verso_cats'][0] == $conf['back2front']['versos_cat'])
    1922  {
    2023    foreach (explode(',',$item['categories']) as $cat)
     
    3639  }
    3740 
    38   pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE."
    39     WHERE image_id = ".$item['verso_id']." AND category_id = ".$conf['back2front'][0].";");
     41  $query = '
     42DELETE FROM '.IMAGE_CATEGORY_TABLE.'
     43  WHERE image_id = '.$item['verso_id'].'
     44    AND category_id = '.$conf['back2front']['versos_cat'].'
     45;';
     46  pwg_query($query);
     47}
     48
     49function back2front_check_storage()
     50{
     51  global $conf;
     52 
     53  if ($conf['back2front']['versos_cat'] != 0)
     54  {
     55    $query = '
     56SELECT COUNT(*) FROM '.CATEGORIES_TABLE.'
     57  WHERE id = '.$conf['back2front']['versos_cat'].'
     58    AND name = "Back2Front private album"
     59;';
     60    $result = pwg_query($query);
     61   
     62    if (pwg_db_num_rows($result))
     63    {
     64      return;
     65    }
     66  }
     67 
     68  $versos_cat = create_virtual_category('Back2Front private album');
     69  $versos_cat = array(
     70    'id' => $versos_cat['id'],
     71    'comment' => 'Used by Back2Front to store backsides.',
     72    'status'  => 'private',
     73    'visible' => 'false',
     74    'commentable' => 'false',
     75    );
     76 
     77  mass_updates(
     78    CATEGORIES_TABLE,
     79    array(
     80      'primary' => array('id'),
     81      'update' => array_diff(array_keys($versos_cat), array('id'))
     82      ),
     83    array($versos_cat)
     84    );
     85   
     86  $conf['back2front']['versos_cat'] = $versos_cat['id'];
     87  conf_update_param('back2front', serialize($conf['back2front']));
    4088}
    4189
    4290function picture_exists($id)
    4391{
    44   if (!preg_match('#([0-9]{1,})#', $id) OR $id == '0') return false;
     92  if (!preg_match('#([0-9]{1,})#', $id) || $id == '0') return false;
    4593 
    4694  $query = "SELECT id FROM ".IMAGES_TABLE." WHERE id = ".$id.";";
  • extensions/Back2Front/language/en_UK/plugin.lang.php

    r21335 r23177  
    2222$lang['...of the picture n°'] = '...of the picture n°';
    2323$lang['Backside management'] = 'Backside management';
    24 $lang['Move backside to private album'] = 'Move backside to private album';
     24$lang['Hide backside from albums'] = 'Hide backside from albums';
    2525$lang['This picture has a backside :'] = 'This picture has a backside: ';
    2626
  • extensions/Back2Front/language/fr_FR/plugin.lang.php

    r12361 r23177  
    2222$lang['...of the picture n°'] = '...de l\'image n°';
    2323$lang['Backside management'] = 'Gestion des recto-verso';
    24 $lang['Move backside to private album'] = 'Déplacer le verso vers un album privé';
     24$lang['Hide backside from albums'] = 'Masquer le verso dans les albums';
    2525$lang['This picture has a backside :'] = 'Cette image a un verso : ';
    2626
  • extensions/Back2Front/main.inc.php

    r21213 r23177  
    1212global $prefixeTable;
    1313
    14 define('B2F_DIR', basename(dirname(__FILE__)));
    15 define('B2F_PATH', PHPWG_PLUGINS_PATH . B2F_DIR . '/');
     14defined('B2F_ID') or define('B2F_ID', basename(dirname(__FILE__)));
     15define('B2F_PATH', PHPWG_PLUGINS_PATH . B2F_ID . '/');
    1616define('B2F_TABLE', $prefixeTable . 'image_verso');
     17define('B2F_ADMIN',   get_root_url() . 'admin.php?page=plugin-' . B2F_ID);
     18define('B2F_VERSION', 'auto');
    1719
    18 include_once(B2F_PATH . 'Back2Front.php');
     20include_once(B2F_PATH . 'include/Back2Front.php');
    1921
    20 add_event_handler('init', 'Back2Front_init');
     22add_event_handler('init', 'back2front_init');
    2123
    22 function Back2Front_init()
     24function back2front_init()
    2325{
     26  global $conf, $pwg_loaded_plugins;
     27 
     28  if (
     29    B2F_VERSION == 'auto' or
     30    $pwg_loaded_plugins[B2F_ID]['version'] == 'auto' or
     31    version_compare($pwg_loaded_plugins[B2F_ID]['version'], B2F_VERSION, '<')
     32  )
     33  {
     34    include_once(B2F_PATH . 'include/install.inc.php');
     35    back2front_install();
     36   
     37    if ( $pwg_loaded_plugins[B2F_ID]['version'] != 'auto' and B2F_VERSION != 'auto' )
     38    {
     39      $query = '
     40UPDATE '. PLUGINS_TABLE .'
     41SET version = "'. B2F_VERSION .'"
     42WHERE id = "'. B2F_ID .'"';
     43      pwg_query($query);
     44     
     45      $pwg_loaded_plugins[B2F_ID]['version'] = B2F_VERSION;
     46     
     47      if (defined('IN_ADMIN'))
     48      {
     49        $_SESSION['page_infos'][] = 'Back2Front updated to version '. B2F_VERSION;
     50      }
     51    }
     52  }
     53 
     54  $conf['back2front'] = unserialize($conf['back2front']);
    2455  load_language('plugin.lang', B2F_PATH);
    2556}
     
    2758if (script_basename() == 'picture')
    2859{
    29   add_event_handler('render_element_content', 'Back2Front_picture_content', EVENT_HANDLER_PRIORITY_NEUTRAL+20, 2);
     60  add_event_handler('render_element_content', 'back2front_picture_content', EVENT_HANDLER_PRIORITY_NEUTRAL+20, 2);
    3061}
    3162
    3263if (script_basename() == 'index')
    3364{
    34   add_event_handler('loc_end_index_thumbnails', 'Back2Front_thumbnails');
     65  add_event_handler('loc_end_index_thumbnails', 'back2front_thumbnails');
    3566}
    3667
    3768if (script_basename() == 'admin')
    3869{
    39   add_event_handler('loc_begin_admin_page', 'Back2Front_picture_modify');
     70  add_event_handler('loc_begin_admin_page', 'back2front_picture_modify');
    4071 
    41   add_event_handler('get_admin_plugin_menu_links', 'Back2Front_admin_menu');
    42   function Back2Front_admin_menu($menu)
     72  add_event_handler('get_admin_plugin_menu_links', 'back2front_admin_menu');
     73  function back2front_admin_menu($menu)
    4374  {
    4475    array_push($menu, array(
    4576      'NAME' => 'Back2Front',
    46       'URL' => get_root_url().'admin.php?page=plugin-' . B2F_DIR));
     77      'URL' => B2F_ADMIN,
     78    ));
    4779    return $menu;
    4880  }
  • extensions/Back2Front/maintain.inc.php

    r12648 r23177  
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    33
    4 include_once(PHPWG_PLUGINS_PATH.'Back2Front/functions.inc.php');
     4defined('B2F_ID') or define('B2F_ID', basename(dirname(__FILE__)));
     5include_once(PHPWG_PLUGINS_PATH . B2F_ID . '/include/install.inc.php');
     6include_once(PHPWG_PLUGINS_PATH . B2F_ID . '/include/functions.inc.php');
    57
    68function plugin_install()
    79{
    8   global $prefixeTable;
    9 
    10   /* create table for recto/verso pairs | stores original verso categories */
    11   pwg_query("CREATE TABLE IF NOT EXISTS `" . $prefixeTable . "image_verso` (
    12     `image_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
    13     `verso_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
    14     `categories` varchar(128) NULL,
    15     PRIMARY KEY (`image_id`),
    16     UNIQUE KEY (`verso_id`)
    17   ) DEFAULT CHARSET=utf8;");
     10  back2front_install();
    1811 
    19   /* create a virtual category to store versos */
    20   $versos_cat = create_virtual_category('Back2Front private album');
    21   $versos_cat = array(
    22     'id' => $versos_cat['id'],
    23     'comment' => 'Used by Back2Front to store backsides.',
    24     'status'  => 'private',
    25     'visible' => 'false',
    26     'commentable' => 'false',
    27     );
    28   mass_updates(
    29     CATEGORIES_TABLE,
    30     array(
    31       'primary' => array('id'),
    32       'update' => array_diff(array_keys($versos_cat), array('id'))
    33       ),
    34     array($versos_cat)
    35     );
    36    
    37   /* config parameter */
    38   pwg_query("INSERT INTO `" . CONFIG_TABLE . "`
    39     VALUES ('back2front', '".$versos_cat['id'].",click,none,top,".serialize(array('default'=>null)).",1', 'Configuration for Back2Front plugin');");
     12  define('back2front_installed', true);
    4013}
    4114
    4215function plugin_activate()
    4316{
    44   global $conf;
    45 
    46 
    47   $conf['back2front'] = explode(',', $conf['back2front']);
    48  
    49   if (!isset($conf['back2front'][3]))
     17  if (!defined('back2front_installed'))
    5018  {
    51     $conf['back2front'][3] = 'top';
    52     $conf['back2front'][4] = serialize(array('default'=>null));
     19    back2front_install();
    5320  }
    54   if (!isset($conf['back2front'][5]))
    55   {
    56     $conf['back2front'][5] = true;
    57   }
    58  
    59   conf_update_param('back2front', implode (',', $conf['back2front']));
    6021}
    6122
    6223
    63 function plugin_uninstall() {
     24function plugin_uninstall()
     25{
    6426  global $conf, $prefixeTable;
    6527 
    66   $conf['back2front'] = explode(',',$conf['back2front']);
     28  $conf['back2front'] = unserialize($conf['back2front']);
    6729 
    68   /* versos must be restored to their original categories
    69    criterias :
    70     - verso € 'versos' cat only => restore verso to original categories
    71     - otherwise nothing is changed
    72   */
    73 
    7430  $query = "SELECT * FROM `" . $prefixeTable . "image_verso`;";
    7531  $images_versos = pwg_query($query);
     
    8238  pwg_query("DROP TABLE `" . $prefixeTable . "image_verso`;");
    8339  pwg_query("DELETE FROM `" . CONFIG_TABLE . "` WHERE param = 'back2front';");
    84   pwg_query("DELETE FROM `" . CATEGORIES_TABLE ."`WHERE id = ".$conf['back2front'][0].";");
     40  pwg_query("DELETE FROM `" . CATEGORIES_TABLE ."`WHERE id = ".$conf['back2front']['versos_cat'].";");
    8541 
    86   /* rebuild categories cache */
     42  // rebuild categories cache
    8743  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    8844  invalidate_user_cache(true);
  • extensions/Back2Front/template/picture_modify.tpl

    r21212 r23177  
    3333     
    3434      <tr class="frontside_param" {if !isset($B2F_IS_VERSO)}style="display:none;"{/if}>
    35         <td><b>{'Move backside to private album'|@translate}</b></td>
     35        <td><b>{'Hide backside from albums'|@translate}</b></td>
    3636        <td><input type="checkbox" name="b2f_move_verso" {$B2F_MOVE_VERSO}></td>
    3737      </tr>
Note: See TracChangeset for help on using the changeset viewer.