Changeset 10821


Ignore:
Timestamp:
May 9, 2011, 3:15:45 AM (13 years ago)
Author:
mistic100
Message:

use a private album instead a privacy level

Location:
extensions/Back2Front
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • extensions/Back2Front/Back2Front.php

    r10819 r10821  
    6262function Back2Front_picture_modify()
    6363{
    64   global $page, $template;
     64  global $page, $template, $conf;
     65  $conf['back2front'] = explode(',',$conf['back2front']);
    6566 
    6667  if ($page['page'] == 'picture_modify')
     
    7576        if (picture_exists($_POST['b2f_front_id']))
    7677        {
    77           $query = "
    78             INSERT INTO ".B2F_TABLE."
    79             VALUES(".$_POST['b2f_front_id'].", ".$_GET['image_id'].", ".$_POST['b2f_old_level'].")
    80             ON DUPLICATE KEY UPDATE image_id = ".$_POST['b2f_front_id'].", old_level = ".$_POST['b2f_old_level']."
    81           ;";
    82           pwg_query($query);
    83          
    84           $query = "
    85             UPDATE ".IMAGES_TABLE."
    86             SET level = 99
    87             WHERE id = ".$_GET['image_id']."
    88           ;";
    89           pwg_query($query);
    90          
    91           $template->assign(array(
    92             'B2F_IS_VERSO' => 'checked="checked"',
    93             'B2F_FRONT_ID' => $_POST['b2f_front_id'],
    94             'B2F_OLD_LEVEL' => $_POST['b2f_old_level'],
    95           ));
     78          /* search if recto has already a verso */
     79          $query = "SELECT verso_id
     80            FROM ".B2F_TABLE."
     81            WHERE image_id = ".$_POST['b2f_front_id'].";";
     82          $result = pwg_query($query);
     83          list($recto_current_verso['id']) = pwg_db_fetch_row($result);
     84         
     85          if (pwg_db_num_rows($result) AND $recto_current_verso['id'] != $_GET['image_id'])
     86          {
     87            $recto_current_verso['link'] = get_root_url().'admin.php?page=picture_modify&cat_id=&image_id='.$recto_current_verso['id'];
     88            $template->append('errors', l10n('This picture has already a backside : ').'<a href="'.$recto_current_verso['link'].'">'.$recto_current_verso['id'].'</a>');
     89          }
     90          /* recto is clean */
     91          else
     92          {
     93            $verso_categories = implode(',',array_keys($template->get_template_vars('associated_options')));
     94            pwg_query("INSERT INTO ".B2F_TABLE."
     95              VALUES(".$_POST['b2f_front_id'].", ".$_GET['image_id'].", '".$verso_categories."')
     96              ON DUPLICATE KEY UPDATE image_id = ".$_POST['b2f_front_id'].";");
     97           
     98            /* move the verso ? */
     99            if (isset($_POST['b2f_move_verso']))
     100            {
     101              pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE."
     102                WHERE image_id = ".$_GET['image_id'].";");
     103               
     104              pwg_query("INSERT INTO ".IMAGE_CATEGORY_TABLE."
     105                VALUES(".$_GET['image_id'].", ".$conf['back2front'][0].", NULL);");
     106            }
     107         
     108            $template->assign(array(
     109              'B2F_IS_VERSO' => 'checked="checked"',
     110              'B2F_FRONT_ID' => $_POST['b2f_front_id'],
     111            ));
     112           
     113            $template->append('infos', l10n('This picture is now the backside of the picture n° ').$_POST['b2f_front_id']);
     114          }
    96115        }
    97116        else
    98117        {
    99           $template->assign('errors', l10n('Unknown id for frontside picture'));
     118          $template->append('errors', l10n('Unknown id for frontside picture : ').$_POST['b2f_front_id']);
    100119        }
    101120      }
     
    103122      else
    104123      {
    105         $query = "
    106           DELETE FROM ".B2F_TABLE."
    107           WHERE verso_id = ".$_GET['image_id']."
    108         ;";
    109         pwg_query($query);
     124        /* search if it was a verso */
     125        $query = "SELECT categories
     126          FROM ".B2F_TABLE."
     127          WHERE verso_id = ".$_GET['image_id'].";";
     128        $result = pwg_query($query);
    110129       
    111         $query = "
    112           UPDATE ".IMAGES_TABLE."
    113           SET level = ".$_POST['b2f_old_level']."
    114           WHERE id = ".$_GET['image_id']."
    115         ;";
    116         pwg_query($query);
    117        
    118         $template->assign(array(
    119           'level_options_selected' => array($_POST['b2f_old_level']),
    120         ));
     130        /* it must be restored to its original categories (see criteria on maintain.inc) */
     131        if (pwg_db_num_rows($result))
     132        {
     133          /* original categories */
     134          list($item['categories']) = pwg_db_fetch_row($result);
     135          /* catch current categories */
     136          $versos_infos = pwg_query("SELECT category_id FROM ".IMAGE_CATEGORY_TABLE." WHERE image_id = ".$_GET['image_id'].";");
     137          while (list($verso_cat) = pwg_db_fetch_row($versos_infos))
     138          {
     139            $current_verso_cats[] = $verso_cat;
     140          }
     141          /* if verso € 'versos' cat only */
     142          if (count($current_verso_cats) == 1 AND $current_verso_cats[0] == $conf['back2front'][0])
     143          {
     144            foreach (explode(',',$item['categories']) as $cat)
     145            {
     146              $datas[] = array(
     147                'image_id' => $_GET['image_id'],
     148                'category_id' => $cat,
     149                );
     150            }
     151            if (isset($datas))
     152            {
     153              mass_inserts(
     154                IMAGE_CATEGORY_TABLE,
     155                array('image_id', 'category_id'),
     156                $datas
     157                );
     158            }
     159          }
     160         
     161          pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE."
     162            WHERE image_id = ".$_GET['image_id']." AND category_id = ".$conf['back2front'][0].";");
     163         
     164          pwg_query("DELETE FROM ".B2F_TABLE."
     165            WHERE verso_id = ".$_GET['image_id'].";");
     166           
     167          $template->append('infos', l10n('This picture is no longer a backside'));
     168        }
    121169      }
    122170    }
     
    126174      /* is the pisture a verso ? */
    127175      $query = "
    128         SELECT image_id, old_level
     176        SELECT image_id
    129177        FROM ".B2F_TABLE."
    130178        WHERE verso_id = ".$_GET['image_id']."
     
    134182      if (pwg_db_num_rows($result))
    135183      {
    136         $item = pwg_db_fetch_assoc($result);
     184        list($recto_id) = pwg_db_fetch_row($result);
    137185        $template->assign(array(
    138186          'B2F_IS_VERSO' => 'checked="checked"',
    139           'B2F_FRONT_ID' => $item['image_id'],
    140           'B2F_OLD_LEVEL' => $item['old_level'],
     187          'B2F_FRONT_ID' => $recto_id,
    141188        ));
    142189      }
     
    144191      else
    145192      {
    146         $query = "
    147           SELECT verso_id
     193        $query = "SELECT verso_id
    148194          FROM ".B2F_TABLE."
    149           WHERE image_id = ".$_GET['image_id']."
    150         ;";
     195          WHERE image_id = ".$_GET['image_id'].";";
    151196        $result = pwg_query($query);
    152197       
     
    156201         
    157202          $item = pwg_db_fetch_assoc($result);
    158           $query = "
    159             SELECT id, name, file
     203          $query = "SELECT id, name, file
    160204            FROM ".IMAGES_TABLE."
    161             WHERE id = ".$item['verso_id']."
    162           ;";
     205            WHERE id = ".$item['verso_id'].";";
    163206          $item = pwg_db_fetch_assoc(pwg_query($query));
    164207         
     
    188231}
    189232
    190 
    191 $versos = null; // needs to be declared outside any function for the array_filter callback ?!
    192 /*
    193  * Change/remove navigation thumbnails
    194  */
    195 function Back2Front_items()
    196 {
    197   global $template, $page, $versos;
    198  
    199   /* search all verso ids */
    200   $query = "
    201     SELECT verso_id as id
    202     FROM ".B2F_TABLE."
    203   ;";
    204   $versos = array_values(array_from_query($query, 'id'));
    205  
    206   /* output */
    207   function remove_versos($item)
    208   {
    209     global $versos;
    210     return !in_array($item, $versos);
    211   }
    212   $page['items'] = array_values(array_filter($page['items'], 'remove_versos'));
    213 }
    214 
    215233?>
  • extensions/Back2Front/language/en_UK/plugin.lang.php

    r10819 r10821  
    33$lang['See back'] = 'See back';
    44$lang['See front'] = 'See front';
    5 $lang['Unknown id for frontside picture'] = 'Unknown id for frontside picture';
    6 $lang['Nobody (backside)'] = 'Nobody (backside)';
    7 $lang['Level 99'] = 'Backside';
     5
    86$lang['This picture is a backside...'] = 'This picture is a backside...';
    97$lang['...of the picture n°'] = '...of the picture n°';
    108$lang['Backside management'] = 'Backside management';
    11 $lang['This picture has a backside :'] = 'This picture has a backside :';
     9$lang['Move backside to private album'] = 'Move backside to private album';
     10$lang['This picture has a backside : '] = 'This picture has a backside : ';
     11
     12$lang['This picture has already a backside : '] = 'This picture has already a backside : ';
     13$lang['This picture is now the backside of the picture n° '] = 'This picture is now the backside of the picture n° ';
     14$lang['Unknown id for frontside picture : '] = 'Unknown id for frontside picture : ';
     15$lang['This picture is no longer a backside'] = 'This picture is no longer a backside';
    1216
    1317?>
  • extensions/Back2Front/language/fr_FR/plugin.lang.php

    r10819 r10821  
    33$lang['See back'] = 'Voir le verso';
    44$lang['See front'] = 'Voir le recto';
    5 $lang['Unknown id for frontside picture'] = 'id inconnu pour le recto';
    6 $lang['Nobody (backside)'] = 'Personne (verso)';
    7 $lang['Level 99'] = 'Verso';
     5
    86$lang['This picture is a backside...'] = 'Cette image est le verso...';
    9 $lang['...of the picture n°'] = "...de l'image n°";
    10 $lang['Backside management'] = 'Gestion recto/verso';
    11 $lang['This picture has a backside :'] = 'Cette image a un verso :';
     7$lang['...of the picture n°'] = '...de l\'image n°';
     8$lang['Backside management'] = 'Gestion des recto-verso';
     9$lang['Move backside to private album'] = 'Déplacer le verso vers un album privé';
     10$lang['This picture has a backside : '] = 'Cette image a un verso : ';
     11
     12$lang['This picture has already a backside : '] = 'Cette image a déjà un verso : ';
     13$lang['This picture is now the backside of the picture n° '] = 'Cette image est maintenant le verso de l\'image n° ';
     14$lang['Unknown id for frontside picture : '] = 'Id inconnu pour le recto : ';
     15$lang['This picture is no longer a backside'] = 'Cette image n\'est plus un verso';
    1216
    1317?>
  • extensions/Back2Front/main.inc.php

    r10819 r10821  
    2020
    2121add_event_handler('render_element_content', 'Back2Front_picture_content', 99, 2);
    22 //add_event_handler('loc_end_section_init', 'Back2Front_items');
    2322add_event_handler('loc_end_admin', 'Back2Front_picture_modify');
    2423
    25 
    26 /*      add_event_handler('get_admin_plugin_menu_links', 'Front2Back_admin_menu');
    27         function Front2Back_admin_menu($menu)
    28         {
    29                 array_push($menu, array(
    30                         'NAME' => 'Front2Back',
    31                         'URL' => get_root_url().'admin.php?page=plugin-' . B2F_DIR));
    32                 return $menu;
    33         } */
    34 
    3524?>
  • extensions/Back2Front/maintain.inc.php

    r10819 r10821  
    55        global $prefixeTable;
    66
    7         pwg_query("CREATE TABLE `" . $prefixeTable . "image_verso` (
     7  /* create table for recto/veros pairs | stores original verso categories */
     8        pwg_query("CREATE TABLE IF NOT EXISTS `" . $prefixeTable . "image_verso` (
    89    `image_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
    9     `verso_id` smallint(8) unsigned NOT NULL DEFAULT '0',
    10     `old_level` tinyint unsigned NOT NULL DEFAULT '0',
    11     PRIMARY KEY (`image_id`,`verso_id`)
     10    `verso_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
     11    `categories` varchar(128) NULL,
     12    PRIMARY KEY (`image_id`),
     13    UNIQUE KEY (`verso_id`)
    1214        ) DEFAULT CHARSET=utf8;");
    13 }
    14 
    15 function plugin_activate(){
    16         global $conf, $prefixeTable;
    17 
     15 
     16  /* create a virtual category to store versos */
     17  $versos_cat = create_virtual_category('Back2Front private album');
     18  $versos_cat = array(
     19    'id' => $versos_cat['id'],
     20    'comment' => 'Used by Back2Front to store backsides.',
     21    'status'  => 'private',
     22    'visible' => 'false',
     23    'commentable' => 'false',
     24    );
     25  mass_updates(
     26    CATEGORIES_TABLE,
     27    array(
     28      'primary' => array('id'),
     29      'update' => array_diff(array_keys($versos_cat), array('id'))
     30      ),
     31    array($versos_cat)
     32    );
     33   
     34  /* config parameter */
     35  pwg_query("INSERT INTO `" . CONFIG_TABLE . "`
     36    VALUES ('back2front', '".$versos_cat['id']."', 'Configuration for Back2Front plugin');");
    1837}
    1938
    2039function plugin_uninstall() {
    21         global $prefixeTable;
     40        global $conf, $prefixeTable;
     41 
     42  $conf['back2front'] = explode(',',$conf['back2front']);
     43 
     44  /* versos must be restored to their original categories
     45   criterias :
     46    - verso € 'versos' cat only => restore verso to original categories
     47    - otherwise nothing is changed
     48  */
    2249
    2350  $query = "SELECT * FROM `" . $prefixeTable . "image_verso`;";
    24   $result = pwg_query($query);
    25   while ($item = pwg_db_fetch_assoc($result))
     51  $images_versos = pwg_query($query);
     52 
     53  while ($item = pwg_db_fetch_assoc($images_versos))
    2654  {
    27     pwg_query("UPDATE ".IMAGES_TABLE." SET level = ".$item['old_level']." WHERE id = ".$item['verso_id'].";");
     55    /* catch current verso categories */
     56    $versos_infos = pwg_query("SELECT category_id FROM ".IMAGE_CATEGORY_TABLE." WHERE image_id = ".$item['verso_id'].";");
     57    while (list($verso_cat) = pwg_db_fetch_row($versos_infos))
     58    {
     59      $item['current_verso_cats'][] = $verso_cat;
     60    }
     61   
     62    /* if verso € 'versos' cat only */
     63    if (count($item['current_verso_cats']) == 1 AND $item['current_verso_cats'][0] == $conf['back2front'][0])
     64    {
     65      foreach (explode(',',$item['categories']) as $cat)
     66      {
     67        $datas[] = array(
     68          'image_id' => $item['verso_id'],
     69          'category_id' => $cat,
     70          );
     71      }
     72    }
     73   
     74    pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE."
     75      WHERE image_id = ".$item['verso_id']." AND category_id = ".$conf['back2front'][0].";");
    2876  }
    2977 
     78  if (isset($datas))
     79  {
     80    mass_inserts(
     81      IMAGE_CATEGORY_TABLE,
     82      array('image_id', 'category_id'),
     83      $datas
     84      );
     85  }
     86
    3087        pwg_query("DROP TABLE `" . $prefixeTable . "image_verso`;");
     88  pwg_query("DELETE FROM `" . CONFIG_TABLE . "` WHERE param = 'back2front';");
     89  pwg_query("DELETE FROM `" . CATEGORIES_TABLE ."`WHERE id = ".$conf['back2front'][0].";");
     90 
     91  /* rebuild categories cache */
     92  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     93  invalidate_user_cache(true);
    3194}
    3295?>
  • extensions/Back2Front/template/picture_content.tpl

    r10819 r10821  
    22
    33{footer_script require="jquery"}
    4         jQuery('.reverse').click(function() {ldelim}
    5                 if (jQuery(this).attr('rel') == 'front') {ldelim}
    6                         /* picture attributes */
    7                         jQuery('#theImage img:first-child').attr({ldelim}
    8                                 src: '{$VERSO_URL}',
    9                                 style: 'width:;height:;',
    10                         });
    11                        
    12                         /* hd link atributes */
    13                         {if isset($VERSO_HD)}
    14                         jQuery('#theImage a:first-child').attr({ldelim}
    15                                 href: "javascript:phpWGOpenWindow('{$VERSO_HD}','{$high.UUID}','scrollbars=yes,toolbar=no,status=no,resizable=yes')"
    16                         });
    17                         {/if}
    18                        
    19                         /* B2F link content */
    20                         jQuery(this).html('<img src="{$B2F_PATH}template/rotate_2.png"/> {'See front'|@translate}');
    21                         jQuery(this).attr('rel', 'back');
    22                        
    23                 } else if (jQuery(this).attr('rel') == 'back') {ldelim}
    24                         jQuery('#theImage img:first-child').attr({ldelim}
    25                                 src: '{$SRC_IMG}',
    26                                 style: 'width:{$WIDTH_IMG}px;height:{$HEIGHT_IMG}px;',
    27                         });
    28                        
    29                         {if isset($VERSO_HD)}
    30                         jQuery('#theImage a:first-child').attr({ldelim}
    31                                 href: "javascript:phpWGOpenWindow('{$high.U_HIGH}','{$high.UUID}','scrollbars=yes,toolbar=no,status=no,resizable=yes')')"
    32                         });
    33                         {/if}
    34                        
    35                         jQuery(this).html('<img src="{$B2F_PATH}template/rotate_1.png"/> {'See back'|@translate}');
    36                         jQuery(this).attr('rel', 'front');
    37                 }
    38         });
     4jQuery(document).ready(function () {ldelim}
     5  jQuery('.reverse').click(function() {ldelim}
     6    if (jQuery(this).attr('rel') == 'front') {ldelim}
     7      /* picture attributes */
     8      jQuery('#theImage img:first-child').attr({ldelim}
     9        src: '{$VERSO_URL}',
     10        style: 'width:;height:;',
     11      });
     12     
     13      /* hd link atributes */
     14      {if isset($VERSO_HD)}
     15      jQuery('#theImage a:first-child').attr({ldelim}
     16        href: "javascript:phpWGOpenWindow('{$VERSO_HD}','{$high.UUID}','scrollbars=yes,toolbar=no,status=no,resizable=yes')"
     17      });
     18      {/if}
     19     
     20      /* B2F link content */
     21      jQuery(this).html('<img src="{$B2F_PATH}template/rotate_2.png"/> {'See front'|@translate}');
     22      jQuery(this).attr('rel', 'back');
     23     
     24    } else if (jQuery(this).attr('rel') == 'back') {ldelim}
     25      jQuery('#theImage img:first-child').attr({ldelim}
     26        src: '{$SRC_IMG}',
     27        style: 'width:{$WIDTH_IMG}px;height:{$HEIGHT_IMG}px;',
     28      });
     29     
     30      {if isset($VERSO_HD)}
     31      jQuery('#theImage a:first-child').attr({ldelim}
     32        href: "javascript:phpWGOpenWindow('{$high.U_HIGH}','{$high.UUID}','scrollbars=yes,toolbar=no,status=no,resizable=yes')')"
     33      });
     34      {/if}
     35     
     36      jQuery(this).html('<img src="{$B2F_PATH}template/rotate_1.png"/> {'See back'|@translate}');
     37      jQuery(this).attr('rel', 'front');
     38    }
     39  });
     40});
    3941{/footer_script}
    4042
    4143<a class="reverse" rel="front" href="#">
    42         <img src="{$B2F_PATH}template/rotate_1.png"/>
    43         {'See back'|@translate}
     44  <img src="{$B2F_PATH}template/rotate_1.png"/>
     45  {'See back'|@translate}
    4446</a>
  • extensions/Back2Front/template/picture_modify.tpl

    r10819 r10821  
    33  $('input[name="b2f_is_verso"]').change(function () {ldelim}
    44    if (this.checked) {ldelim}
    5       $('#frontside_id').css('visibility', '');
    6       $('select[name="level"]').prepend('<option label="{'Nobody (backside)'|@translate}" value="99">{'Nobody (backside)'|@translate}</option>');
    7       $('select[name="level"]').val('99').attr('readonly', 'readonly').css('opacity', '0.6');
    8      
     5      $('.frontside_id').css('visibility', '');
    96    } else {ldelim}
    10       $('#frontside_id').css('visibility', 'hidden');
    11       $('select[name="level"] option[value="99"]').remove();
    12       $('select[name="level"]').val($('input[name="b2f_old_level"]').val()).removeAttr('readonly').css('opacity', '1');
     7      $('.frontside_id').css('visibility', 'hidden');
    138    }
    149  });
    15 
    16   {if isset($B2F_IS_VERSO)}
    17   $('#frontside_id').css('visibility', '');
    18   $('select[name="level"]').prepend('<option label="{'Nobody (backside)'|@translate}" value="99">{'Nobody (backside)'|@translate}</option>');
    19   $('select[name="level"]').val('99').attr('readonly', 'readonly').css('opacity', '0.6');
    20   {else}
    21   $('#frontside_id').css('visibility', 'hidden');
    22   $('select[name="level"]').val('{$level_options_selected.0}');
    23   {/if}
    2410});
    2511{/footer_script}
    2612
    2713
    28 <form action="{$F_ACTION}#back2front" method="post" id="back2front">
     14<form action="{$F_ACTION}" method="post" id="back2front">
    2915
    3016  <fieldset>
    3117    <legend>{'Backside management'|@translate}</legend>
    3218
     19  {if isset($B2F_VERSO_ID)}
    3320    <table>
    34     {if isset($B2F_VERSO_ID)}
    3521      <tr>
    36         <td><strong>{'This picture has a backside :'|@translate}</strong></td>
     22        <td><b>{'This picture has a backside :'|@translate}</b></td>
    3723        <td><a href="{$B2F_VERSO_URL}">{$B2F_VERSO_ID} - {$B2F_VERSO_NAME}</a></td>
    3824      </tr>
    3925    </table>
    40     {else}
    41 
     26  {else}
     27    <table>
    4228      <tr>
    43         <td><strong>{'This picture is a backside...'|@translate}</strong></td>
     29        <td><b>{'This picture is a backside...'|@translate}</b></td>
    4430        <td><input type="checkbox" name="b2f_is_verso" {$B2F_IS_VERSO}></td>
    4531      </tr>
    4632
    47       <tr id="frontside_id">
    48         <td><strong>{'...of the picture n°'|@translate}</strong></td>
     33      <tr class="frontside_id" {if !isset($B2F_IS_VERSO)}style="visibility:hidden;"{/if}>
     34        <td><b>{'...of the picture n°'|@translate}</b></td>
    4935        <td><input type="text" size="4" name="b2f_front_id" value="{$B2F_FRONT_ID}"></td>
    5036      </tr>
    51 
     37     
     38      <tr class="frontside_id" {if !isset($B2F_IS_VERSO)}style="visibility:hidden;"{/if}>
     39        <td><b>{'Move backside to private album'|@translate}</b></td>
     40        <td><input type="checkbox" name="b2f_move_verso" checked="checked"></td>
     41      </tr>
    5242    </table>
    5343
    5444    <p style="text-align:center;">
    55       <input type="hidden" name="b2f_old_level" value="{if isset($B2F_OLD_LEVEL)}{$B2F_OLD_LEVEL}{else}{$level_options_selected.0}{/if}">
    5645      <input class="submit" type="submit" value="{'Submit'|@translate}" name="b2f_submit">
    5746    </p>
    58     {/if}
     47  {/if}
    5948
    6049  </fieldset>
Note: See TracChangeset for help on using the changeset viewer.