Changeset 23361


Ignore:
Timestamp:
Jun 19, 2013, 2:43:41 PM (8 years ago)
Author:
mistic100
Message:

all collections are "active", display a menu when adding to a collection

Location:
extensions/UserCollections
Files:
3 added
13 edited

Legend:

Unmodified
Added
Removed
  • extensions/UserCollections/include/UserCollection.class.php

    r20099 r23361  
    2626      'date_creation' => '0000-00-00 00:00:00',
    2727      'nb_images' => 0,
    28       'active' => false,
    29       'public' => false,
     28      'active' => 0,
     29      'public' => 0,
    3030      'public_id' => null,
    3131      );
     
    5656    {
    5757      $query = '
    58 SELECT
    59     id,
    60     user_id,
    61     name,
    62     date_creation,
    63     nb_images,
    64     active,
    65     public,
    66     public_id
     58SELECT *
    6759  FROM '.COLLECTIONS_TABLE.'
    6860  WHERE
     
    10799    {
    108100      $this->data['name'] = $name;
    109       $this->data['active'] = $active;
    110       $this->data['public'] = $public;
     101      $this->data['active'] = (int)$active;
     102      $this->data['public'] = (int)$public;
    111103      $this->data['public_id'] = 'uc'.hash('crc32', uniqid(serialize($this->data), true));
    112104     
     
    139131        $this->addImages($images);
    140132      }
    141      
    142       // only one active collection allowed
    143       if ($this->data['active'])
    144       {
    145         $query = '
    146 UPDATE '.COLLECTIONS_TABLE.'
    147   SET active = 0
    148   WHERE
    149     user_id = '.$this->data['user_id'].'
    150     AND id != '.$this->data['id'].'
    151 ;';
    152         pwg_query($query);
    153       }
    154133    }
    155134    else
     
    210189    if (empty($image_ids) or !is_array($image_ids)) return;
    211190   
    212     foreach ($image_ids as $image_id)
    213     {
    214       unset($this->images[ array_search($image_id, $this->images) ]);
    215     }
     191    $this->images = array_diff($this->images, $image_ids);
    216192   
    217193    $query = '
     
    241217      if ($this->isInSet($image_id)) continue;
    242218     
    243       array_push($this->images, $image_id);
    244       array_push($inserts, array('col_id'=>$this->data['id'], 'image_id'=>$image_id));
     219      $this->images[] = $image_id;
     220      $inserts[] = array(
     221        'col_id' => $this->data['id'],
     222        'image_id' => $image_id,
     223        );
    245224    }
    246225   
     
    302281  {
    303282    $set = array(
     283      'ID' => $this->data['id'],
    304284      'NAME' => $this->data['name'],
    305285      'NB_IMAGES' => $this->data['nb_images'],
     
    308288      'DATE_CREATION' => $this->data['date_creation'],
    309289      'U_PUBLIC' => USER_COLLEC_PUBLIC . 'view/'.$this->data['public_id'],
    310       'IS_TEMP' =>  $this->data['name'] == 'temp',
    311290      );
    312291   
     
    568547    return $content;
    569548  }
     549 
     550  /**
     551   * delete
     552   */
     553  function delete()
     554  {
     555    $this->clearImages();
     556    pwg_query('DELETE FROM '.COLLECTIONS_TABLE.' WHERE id = '.$this->data['id'].';');
     557  }
    570558}
    571559
  • extensions/UserCollections/include/collections.inc.php

    r23166 r23361  
    1919    if (is_a_guest()) access_denied();
    2020   
    21     $template->set_filename('index', dirname(__FILE__) . '/../template/list.tpl');
     21    $template->set_filename('index', realpath(USER_COLLEC_PATH.'template/list.tpl'));
    2222   
    2323    // actions
     
    2929        case 'new':
    3030        {
    31           $UserCollection = new UserCollection('new', array(), empty($_GET['name']) ? 'temp' : $_GET['name'], 1);
    32          
    33           if (isset($_GET['redirect']))
    34           {
    35             $redirect = USER_COLLEC_PUBLIC.'edit/'.$UserCollection->getParam('id');
     31          if (empty($_GET['name']))
     32          {
     33            array_push($page['errors'], l10n('Please give a name'));
    3634          }
    3735          else
    3836          {
    39             $redirect = USER_COLLEC_PUBLIC;
    40           }
    41           redirect($redirect);
     37            $UserCollection = new UserCollection('new', array(), $_GET['name'], 1);
     38           
     39            if (isset($_GET['redirect']))
     40            {
     41              $redirect = USER_COLLEC_PUBLIC.'edit/'.$UserCollection->getParam('id');
     42            }
     43            else
     44            {
     45              $redirect = USER_COLLEC_PUBLIC;
     46            }
     47            redirect($redirect);
     48          }
    4249          break;
    4350        }
     
    4653        case 'delete':
    4754        {
    48           $query = '
    49 DELETE ci, c
    50   FROM '.COLLECTION_IMAGES_TABLE.' AS ci
    51     RIGHT JOIN '.COLLECTIONS_TABLE.' AS c
    52     ON ci.col_id = c.id
    53   WHERE
    54     c.user_id = '.$user['id'].'
    55     AND c.id = '.$_GET['col_id'].'
    56 ;';
    57           pwg_query($query);
    58      
    59           redirect(USER_COLLEC_PUBLIC);
    60           break;
    61         }
    62        
    63         // save
    64         case 'save':
    65         {
    66           if (empty($_GET['name']))
    67           {
    68             array_push($page['errors'], l10n('Please give a name'));
    69           }
    70           else
    71           {
    72             $query = '
    73 UPDATE '.COLLECTIONS_TABLE.'
    74   SET
    75     name = "'.pwg_db_real_escape_string($_GET['name']).'",
    76     active = 0
    77   WHERE
    78     user_id = '.$user['id'].'
    79     AND id = '.$_GET['col_id'].'
    80 ;';
    81             pwg_query($query);
    82            
     55          try {
     56            $UserCollection = new UserCollection($_GET['col_id']);
     57            $UserCollection->delete();
    8358            redirect(USER_COLLEC_PUBLIC);
     59          }
     60          catch (Exception $e)
     61          {
     62            $page['errors'][] = $e->getMessage();
    8463          }
    8564          break;
     
    8766       
    8867        // set active
    89         case 'set_active':
     68        case 'toggle_active':
    9069        {
    9170          $query = '
    9271UPDATE '.COLLECTIONS_TABLE.'
    93   SET active = 0
    94   WHERE user_id = '.$user['id'].'
    95 ;';
    96           pwg_query($query);
    97          
    98           $query = '
    99 UPDATE '.COLLECTIONS_TABLE.'
    100   SET active = 1
     72  SET active = IF(active=1, 0, 1)
    10173  WHERE
    10274    user_id = '.$user['id'].'
     
    11183    }
    11284   
    113    
    114     // get collections
    115     $query = '
    116 SELECT *
    117   FROM '.COLLECTIONS_TABLE.'
    118   WHERE user_id = '.$user['id'].'
    119   ORDER BY date_creation DESC
    120 ';
    121     $collections = hash_from_query($query, 'id');
    122    
    123     foreach ($collections as $col)
    124     {
    125       $col['date_creation'] = format_date($col['date_creation'], true);
    126       $col['U_EDIT'] = USER_COLLEC_PUBLIC.'edit/'.$col['id'];
    127       $col['U_ACTIVE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'set_active','col_id'=>$col['id']));
    128       $col['U_DELETE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'delete','col_id'=>$col['id']));
    129      
    130       if (isset($pwg_loaded_plugins['BatchDownloader']))
    131       {
    132         $col['U_DOWNLOAD'] = add_url_params(USER_COLLEC_PUBLIC.'edit/'.$col['id'], array('action'=>'advdown_set'));
    133       }
    134      
    135       // temporary collections are above save collections
    136       if ($col['name'] == 'temp')
    137       {
    138         $col['name'] = 'temp #'.$col['id'];
    139         $col['U_SAVE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'save','col_id'=>$col['id']));
    140         $template->append('temp_col', $col);
    141       }
    142       else
    143       {
    144         $template->append('collections', $col);
    145       }
    146     }
    147    
    14885    $template->assign('U_CREATE', add_url_params(USER_COLLEC_PUBLIC, array('action'=>'new','col_id'=>'0')));
     86   
     87    $template->set_prefilter('index_category_thumbnails', 'user_collections_categories_list');
     88   
     89    include(USER_COLLEC_PATH . '/include/display_collections.inc.php');
     90   
    14991    break;
    15092  }
     
    160102    }
    161103   
    162     $template->set_filename('index', dirname(__FILE__).'/../template/edit.tpl');
     104    $template->set_filename('index', realpath(USER_COLLEC_PATH.'template/edit.tpl'));
    163105   
    164106    $self_url = USER_COLLEC_PUBLIC . 'edit/'.$page['col_id'];
     
    169111      'collection_toggle_url' => $self_url,
    170112      'U_LIST' => USER_COLLEC_PUBLIC,
    171       'AJAX_COL_ID' => $page['col_id'],
    172113      'UC_IN_EDIT' => true,
    173114      ));
     
    175116    try {
    176117      $UserCollection = new UserCollection($page['col_id']);
    177      
    178       // security
    179       if ( !is_admin() and $UserCollection->getParam('user_id') != $user['id'] )
    180       {
    181         access_denied();
    182       }
    183118     
    184119      // save properties
     
    244179      }
    245180     
    246       // remove an element
    247       if ( isset($_GET['collection_toggle']) and preg_match('#^[0-9]+$#', $_GET['collection_toggle']) )
    248       {
    249         $UserCollection->removeImages(array($_GET['collection_toggle']));
    250         unset($_GET['collection_toggle']);
    251       }
    252181     
    253182      // add remove item links
    254       $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_prefilter');
     183      $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_button');
     184      $template->set_prefilter('index', 'user_collections_thumbnails_list_cssjs');
     185      $template->set_prefilter('index_thumbnails', 'user_collections_add_colorbox');
    255186     
    256187      // thumbnails
     
    273204        add_url_params(USER_COLLEC_PUBLIC, array('action'=>'delete','col_id'=>$page['col_id']))
    274205        );
    275       if ($conf['user_collections']['allow_public'] and $conf['user_collections']['allow_mails'])
     206      if ($conf['user_collections']['allow_public'] and $conf['user_collections']['allow_mails'] and !empty($page['items']))
    276207      {
    277208        $template->assign('U_MAIL', true);
     
    308239      $UserCollection = new UserCollection($page['col_id']);
    309240      $page['col_id'] = $UserCollection->getParam('id');
     241     
     242      $template->set_prefilter('index_thumbnails', 'user_collections_add_colorbox');
    310243     
    311244      // thumbnails
     
    328261}
    329262
    330 
    331 function user_collections_thumbnails_in_collection($tpl_thumbnails_var, $pictures)
     263// modification on mainpage_categories.tpl
     264function user_collections_categories_list($content, &$samrty)
    332265{
    333   global $template, $page;
    334  
    335   $url = USER_COLLEC_PUBLIC . 'edit/'.$page['col_id'];
    336  
    337   foreach ($tpl_thumbnails_var as &$thumbnail)
    338   {
    339     $src_image = new SrcImage($thumbnail);
    340    
    341     $thumbnail['FILE_SRC'] = DerivativeImage::url(IMG_LARGE, $src_image);
    342     $thumbnail['URL'] = duplicate_picture_url(
    343         array(
    344           'image_id' => $thumbnail['id'],
    345           'image_file' => $thumbnail['file'],
    346           'section' => 'none',
    347         ),
    348         array('start')
    349       );
    350      
    351     $thumbnail['COLLECTION_SELECTED'] = true;
    352     $thumbnail['COLLECTION_TOGGLE_URL'] = add_url_params($url, array('collection_toggle'=>$thumbnail['id']));
    353   }
    354  
    355   $template->set_prefilter('index_thumbnails', 'user_collections_add_colorbox');
    356  
    357   return $tpl_thumbnails_var;
     266  $search[0] = '<div class="thumbnailCategory">';
     267  $replace[0] = '<div class="thumbnailCategory {*if $cat.active}activeCollection{/if*}">
     268  <div class="collectionActions">
     269    <a href="{$cat.URL}" rel="nofollow">{"Edit"|@translate}</a>
     270    | <a href="{$cat.U_DELETE}" onClick="return confirm(\'{"Are you sure?"|@translate}\');" rel="nofollow">{"Delete"|@translate}</a>
     271    {if $cat.U_ACTIVE}| <a href="{$cat.U_ACTIVE}" rel="nofollow">{if $cat.active}{"set inactive"|@translate}{else}{"set active"|@translate}{/if}</a>{/if}
     272  </div>';
     273 
     274  // $search[1] = '<a href="{$cat.URL}">{$cat.NAME}</a>';
     275  // $replace[1] = '<a href="{$cat.URL}">{$cat.NAME}</a> {if $cat.active}<span class="collectionActive">({"active"|@translate})</span>{/if}';
     276 
     277  return str_replace($search, $replace, $content);
    358278}
    359279
     280// colorbox
    360281function user_collections_add_colorbox($content)
    361282{
  • extensions/UserCollections/include/display_thumbnails.inc.php

    r21382 r23361  
    113113    );
    114114}
     115
     116
     117function user_collections_thumbnails_in_collection($tpl_thumbnails_var, $pictures)
     118{
     119  global $template, $page;
     120 
     121  $url = USER_COLLEC_PUBLIC . 'edit/'.$page['col_id'];
     122 
     123  foreach ($tpl_thumbnails_var as &$thumbnail)
     124  {
     125    $src_image = new SrcImage($thumbnail);
     126   
     127    $thumbnail['FILE_SRC'] = DerivativeImage::url(IMG_LARGE, $src_image);
     128    $thumbnail['URL'] = duplicate_picture_url(
     129        array(
     130          'image_id' => $thumbnail['id'],
     131          'image_file' => $thumbnail['file'],
     132          'section' => 'none',
     133        ),
     134        array('start')
     135      );
     136     
     137    $thumbnail['COLLECTION_SELECTED'] = true;
     138    $thumbnail['COLLECTION_TOGGLE_URL'] = add_url_params($url, array('collection_toggle'=>$thumbnail['id']));
     139  }
     140 
     141  return $tpl_thumbnails_var;
     142}
    115143 
    116144?>
  • extensions/UserCollections/include/events.inc.php

    r21382 r23361  
    2020    if (in_array(@$tokens[1], array('edit','view','list')))
    2121    {
    22        $page['sub_section'] = $tokens[1];
     22      $page['sub_section'] = $tokens[1];
     23      if ($tokens[1]=='edit' and isset($conf['GThumb']) && is_array($conf['GThumb']))
     24      {
     25        $conf['GThumb']['big_thumb'] = false; // big thumb is buggy with removes
     26      }
    2327    }
    2428    else
     
    5559// | CATEGORY PAGE
    5660// +-----------------------------------------------------------------------+
    57 /* toggle an image, in case of no javascript or first call (must create the collection) */
    58 function user_collections_index_actions()
    59 {
    60   if (is_a_guest()) return;
    61  
    62   global $page, $UserCollection;
    63      
    64   // add image to collection list
    65   if ( isset($_GET['collection_toggle']) and  preg_match('#^[0-9]+$#', $_GET['collection_toggle']) )
    66   {
    67     if (empty($UserCollection))
    68     {
    69       $UserCollection = new UserCollection(get_current_collection_id(true));
    70     }
    71     $UserCollection->toggleImage($_GET['collection_toggle']);
    72     redirect(duplicate_index_url(array(), array('collection_toggle')));
    73   }
    74 }
    75 
    7661/* add buttons on thumbnails list */
    7762function user_collections_thumbnails_list($tpl_thumbnails_var, $pictures)
     
    7964  if (is_a_guest()) return $tpl_thumbnails_var;
    8065 
    81   global $page, $template, $UserCollection;
     66  global $page, $template, $user;
    8267 
    8368  // the content is different on collection edition page and no button on batch downloader set edition page
     
    8772  }
    8873 
    89   // get existing collections
    90   $col_id = get_current_collection_id(false);
    91   if (empty($UserCollection) and $col_id !== false)
    92   {
    93     $UserCollection = new UserCollection($col_id);
    94     $collection = $UserCollection->getImages();
    95   }
    96   else if (!empty($UserCollection))
    97   {
    98     $collection = $UserCollection->getImages();
    99   }
    100   else
    101   {
    102     $collection = array();
    103   }
    104  
    105   // if the collection doesn't exists we don't use AJAX to force menu refresh
    106   if ($col_id === false)
    107   {
    108     $template->assign('NO_AJAX', true);
    109   }
    110   else
    111   {
    112     $template->assign('AJAX_COL_ID', $col_id );
    113   }
    114  
    115   // template vars
    116   $url = duplicate_index_url(array(), array('collection_toggle'));
     74  $image_ids = array_map(create_function('$i', 'return $i["id"];'), $pictures);
     75 
     76  // get collections for each picture
     77  $query = '
     78SELECT
     79    image_id,
     80    GROUP_CONCAT(col_id) AS col_ids
     81  FROM '.COLLECTION_IMAGES_TABLE.'
     82  WHERE col_id IN (
     83      SELECT id
     84      FROM '.COLLECTIONS_TABLE.'
     85      WHERE user_id = '.$user['id'].'
     86    )
     87    AND image_id IN('.implode(',', $image_ids).')
     88  GROUP BY image_id
     89;';
     90  $image_collections = simple_hash_from_query($query, 'image_id', 'col_ids');
    11791 
    11892  foreach ($tpl_thumbnails_var as &$thumbnail)
    11993  {
    120     if (in_array($thumbnail['id'], $collection))
    121     {
    122       $thumbnail['COLLECTION_SELECTED'] = true;
    123     }
    124     $thumbnail['COLLECTION_TOGGLE_URL'] = add_url_params($url, array('collection_toggle'=>$thumbnail['id']));
     94    $thumbnail['COLLECTIONS'] = @$image_collections[ $thumbnail['id'] ];
    12595  }
    12696  unset($thumbnail);
    12797 
     98  // get all collections
     99  $query = '
     100SELECT id, name, nb_images, active
     101  FROM '.COLLECTIONS_TABLE.'
     102  WHERE user_id = '.$user['id'].'
     103  ORDER BY name ASC
     104;';
     105  $collections = hash_from_query($query, 'id');
     106 
    128107  $template->assign(array(
     108    'COLLECTIONS' => $collections,
    129109    'USER_COLLEC_PATH' => USER_COLLEC_PATH,
    130110    ));
    131111 
    132112  // thumbnails buttons
    133   $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_prefilter');
     113  $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_button');
     114  $template->set_prefilter('index', 'user_collections_thumbnails_list_cssjs');
    134115 
    135116  return $tpl_thumbnails_var;
    136117}
    137118
    138 function user_collections_thumbnails_list_prefilter($content, &$smarty)
    139 {
    140   // add links
     119// add links
     120function user_collections_thumbnails_list_button($content, &$smarty)
     121{
    141122  $search = '#(<li>|<li class="gthumb">)#';
    142123  $replace = '$1
    143 {strip}<a class="addCollection" href="{$thumbnail.COLLECTION_TOGGLE_URL}" data-id="{$thumbnail.id}" data-stat="{if $thumbnail.COLLECTION_SELECTED}remove{else}add{/if}" rel="nofollow">
    144 <span class="uc_remove" {if not $thumbnail.COLLECTION_SELECTED}style="display:none;"{/if}>
    145 {\'Remove from collection\'|@translate}&nbsp;<img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/resources/image_delete.png" title="{\'Remove from collection\'|@translate}">
    146 </span>
    147 <span class="uc_add" {if $thumbnail.COLLECTION_SELECTED}style="display:none;"{/if}>
    148 {\'Add to collection\'|@translate}&nbsp;<img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/resources/image_add.png" title="{\'Add to collection\'|@translate}">
    149 </span>
     124{strip}<a class="addCollection" data-id="{$thumbnail.id}" data-cols="[{$thumbnail.COLLECTIONS}]" rel="nofollow">
     125{if not $UC_IN_EDIT}
     126{\'Add to collection\'|@translate}&nbsp;<img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/resources/image_add.png" alt="[+]">
     127{else}
     128{\'Remove from collection\'|@translate}&nbsp;<img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/resources/image_delete.png" alt="[+]">
     129{/if}
    150130</a>{/strip}';
    151 
    152   // custom CSS and AJAX request
     131 
     132  return preg_replace($search, $replace, $content);
     133}
     134
     135// add css & js and menu
     136function user_collections_thumbnails_list_cssjs($content, &$smarty)
     137{
    153138  $content.= file_get_contents(USER_COLLEC_PATH.'template/thumbnails_css_js.tpl');
    154  
    155   return preg_replace($search, $replace, $content);
     139  return $content;
    156140}
    157141
     
    165149  if (is_a_guest()) return;
    166150 
    167   global $template, $picture, $UserCollection;
    168  
    169   // add image to collection list
    170   if ( isset($_GET['action']) and $_GET['action'] == 'collection_toggle' )
    171   {
    172     if (empty($UserCollection))
    173     {
    174       $UserCollection = new UserCollection(get_current_collection_id(true));
    175     }
    176    
    177     $UserCollection->toggleImage($picture['current']['id']);
    178     redirect(duplicate_picture_url());
    179   }
    180  
    181   // get existing collection
    182   if (empty($UserCollection) and ($col_id = get_current_collection_id(false)) !== false)
    183   {
    184     $UserCollection = new UserCollection($col_id);
    185     $collection = $UserCollection->isInSet($picture['current']['id']);
    186   }
    187   else if (!empty($UserCollection))
    188   {
    189     $collection = $UserCollection->isInSet($picture['current']['id']);
    190   }
    191   else
    192   {
    193     $collection = false;
    194   } 
    195  
    196   $url = add_url_params(duplicate_picture_url(), array('action'=>'collection_toggle'));   
    197  
    198   $button = '
    199 <a href="'.$url.'" title="'.($collection?l10n('Remove from collection'):l10n('Add to collection')).'" class="pwg-state-default pwg-button" rel="nofollow">
    200   <span class="pwg-icon" style="background:url(\''.get_root_url().USER_COLLEC_PATH.'template/resources/image_'.($collection?'delete':'add').'.png\') center center no-repeat;"> </span>
    201   <span class="pwg-button-text">'.($collection?l10n('Remove from collection'):l10n('Add to collection')).'</span>
    202 </a>';
    203   // $template->add_picture_button($button, 50);
    204   $template->concat('PLUGIN_PICTURE_ACTIONS', $button);
     151  global $template, $picture, $user;
     152 
     153  // get collections for this picture
     154  $query = '
     155SELECT GROUP_CONCAT(col_id)
     156  FROM '.COLLECTION_IMAGES_TABLE.'
     157  WHERE col_id IN (
     158      SELECT id
     159      FROM '.COLLECTIONS_TABLE.'
     160      WHERE user_id = '.$user['id'].'
     161    )
     162    AND image_id = '.$picture['current']['id'].'
     163  GROUP BY image_id
     164;';
     165  list($image_collections) = pwg_db_fetch_row(pwg_query($query));
     166 
     167  // get all collections
     168  $query = '
     169SELECT id, name, nb_images, active
     170  FROM '.COLLECTIONS_TABLE.'
     171  WHERE user_id = '.$user['id'].'
     172  ORDER BY name ASC
     173;';
     174  $collections = hash_from_query($query, 'id');
     175 
     176  $template->assign(array(
     177    'CURRENT_COLLECTIONS' => $image_collections,
     178    'COLLECTIONS' => $collections,
     179    'USER_COLLEC_PATH' => USER_COLLEC_PATH,
     180    'USER_COLLEC_ABS_PATH' => realpath(USER_COLLEC_PATH).'/',
     181    'IN_PICTURE' => true,
     182    ));
     183 
     184  // toolbar button
     185  $template->set_filename('usercol_button', realpath(USER_COLLEC_PATH.'template/picture_button.tpl'));
     186  $button = $template->parse('usercol_button', true);
     187  $template->add_picture_button($button, 50);
    205188}
    206189
     
    225208  $max = 6;
    226209 
    227   global $template, $page, $conf, $user, $UserCollection;
     210  global $template, $page, $conf, $user;
    228211  $menu = &$menu_ref_arr[0];
    229  
    230   // the editable counter is for the active collection, except if we are currently editing a collection
    231   $col_in_edit = 0;
    232   if ( @$page['section'] == 'collections' and @$page['sub_section']=='edit' and !empty($page['col_id']) )
    233   {
    234     $col_in_edit = $page['col_id'];
    235   }
    236212 
    237213  if (($block = $menu->get_block('mbUserCollection')) != null)
     
    250226    for ($i=0; $i<$max && $i<count($collections); $i++)
    251227    {
    252       $collections[$i]['count_handler'] = $col_in_edit!=0 ? $collections[$i]['id']==$col_in_edit : $collections[$i]['active'];
    253228      $collections[$i]['U_EDIT'] = USER_COLLEC_PUBLIC.'edit/'.$collections[$i]['id'];
    254       array_push($data['collections'], $collections[$i]);
     229      $data['collections'][] = $collections[$i];
    255230    }
    256231   
  • extensions/UserCollections/include/functions.inc.php

    r20093 r23361  
    5454function get_collection_preferred_image_orders()
    5555{
    56   global $conf, $page;
     56  global $conf;
    5757   
    5858  return trigger_event('get_category_preferred_image_orders', array(
     
    7272}
    7373
     74function get_collections_preferred_orders()
     75{
     76  return array(
     77    array(l10n('Name, A &rarr; Z'),               'name ASC',           true),
     78    array(l10n('Name, Z &rarr; A'),               'name DESC',          true),
     79    array(l10n('Date created, new &rarr; old'),   'date_creation DESC', true),
     80    array(l10n('Date created, old &rarr; new'),   'date_creation ASC',  true),
     81    array(l10n('Photos number, high &rarr; low'), 'nb_images DESC',     true),
     82    array(l10n('Photos number, low &rarr; high'), 'nb_images ASC',      true),
     83    );
     84}
     85
    7486?>
  • extensions/UserCollections/include/ws_functions.inc.php

    r20090 r23361  
    1212    array(
    1313      'name' => array(),
    14       'user_id' => array('default' => null),
     14      'user_id' => array('default' => null, 'info'=>'Admin parameter, default is current user'),
    1515      'active' => array('default' => 0),
    1616      'public' => array('default' => 0),
    1717      ),
    18     'Create a new User Collection. If "user_id" is empty, the collection is created for the current user.'
     18    'Create a new User Collection.'
    1919    );
    2020   
     
    2323    'ws_collections_delete',
    2424    array(
    25       'col_id' => array(),
    26       ),
    27     'Delete a User Collection. The current user must be admin or owner of the collection.'
     25      'col_id' => array('info'=>'The current user must be admin or owner of the collection'),
     26      ),
     27    'Delete a User Collection.'
    2828    );
    2929   
     
    3333    array(
    3434      'col_id' => array('default' => null),
    35       'user_id' => array('default' => null),
     35      'user_id' => array('default' => null, 'info'=>'Admin parameter, default is current user'),
    3636      'name' => array('default' => null),
    3737      'public' => array('default' => null),
     
    4545    'ws_collections_addImages',
    4646    array(
    47       'col_id' => array(),
     47      'col_id' => array('info'=>'The current user must be admin or owner of the collection'),
    4848      'image_ids' => array('flags'=>WS_PARAM_FORCE_ARRAY),
    4949      ),
    50     'Add images to a collection. The current user must be admin or owner of the collection.'
     50    'Add images to a collection.'
    5151    );
    5252   
     
    5555    'ws_collections_removeImages',
    5656    array(
    57       'col_id' => array(),
     57      'col_id' => array('info'=>'The current user must be admin or owner of the collection'),
    5858      'image_ids' => array('flags'=>WS_PARAM_FORCE_ARRAY),
    5959      ),
    60     'Remove images from a collection. The current user must be admin or owner of the collection.'
     60    'Remove images from a collection.'
    6161    );
    6262   
     
    7878    array(
    7979      'col_id' => array(),
    80       'content' => array('default'=>array('id','name','url','path'), 'flags'=>WS_PARAM_FORCE_ARRAY),
    81       ),
    82     'Returns a serialized version of the collection in CSV.<br>Available options for "content" are : id, file, name, url, path.<br>The return type is plain/text whatever you select as response format.'
     80      'content' => array(
     81        'default'=>array('id','name','url','path'),
     82        'flags'=>WS_PARAM_FORCE_ARRAY,
     83        'info'=>'Available options are: id, file, name, url, path'
     84        ),
     85      ),
     86    'Returns a serialized version of the collection in CSV.<br>The return type is plain/text whatever you select as response format.'
    8387    );
    8488}
  • extensions/UserCollections/language/en_UK/plugin.lang.php

    r20150 r23361  
    2727$lang['Save'] = 'Save';
    2828$lang['%d more...'] = '%d more...';
     29$lang['(remove)'] = '(remove)';
    2930
    3031$lang['Allow users to set their collections as public'] = 'Allow users to set their collections as public';
     
    5859$lang['Date added to collection, new &rarr; old'] = 'Date added to collection, new &rarr; old';
    5960$lang['Date added to collection, old &rarr; new'] = 'Date added to collection, old &rarr; new';
    60 
     61$lang['Name, A &rarr; Z'] = 'Name, A &rarr; Z';
     62$lang['Name, Z &rarr; A'] = 'Name, Z &rarr; A';
     63$lang['Photos number, high &rarr; low'] = 'Photos number, high &rarr; low';
     64$lang['Photos number, low &rarr; high'] = 'Photos number, low &rarr; high';
    6165
    6266?>
  • extensions/UserCollections/language/fr_FR/plugin.lang.php

    r20093 r23361  
    1919$lang['Collection'] = 'Collection';
    2020$lang['Remove from collection'] = 'Supprimer de la collection';
    21 $lang['Add to collection'] = 'Ajouter à la collection';
     21$lang['Add to collection'] = 'Ajouter à une collection';
    2222$lang['Clear'] = 'Vider';
    2323$lang['You have %d collection'] = 'Vous avez %d collection';
     
    2727$lang['Save'] = 'Sauvegarder';
    2828$lang['%d more...'] = 'et %d autres...';
     29$lang['(remove)'] = '(retirer)';
    2930
    3031$lang['Allow users to set their collections as public'] = 'Les utilisateurs peuvent rendre leurs collections publiques';
     
    5859$lang['Date added to collection, new &rarr; old'] = 'Date d\'ajout à la collection, récent &rarr; ancien';
    5960$lang['Date added to collection, old &rarr; new'] = 'Date d\'ajout à la collection, ancien &rarr; récent';
     61$lang['Name, A &rarr; Z'] = 'Nom, A &rarr; Z';
     62$lang['Name, Z &rarr; A'] = 'Nom, Z &rarr; A';
     63$lang['Photos number, high &rarr; low'] = 'Nombre de photos, élévé &rarr; faible';
     64$lang['Photos number, low &rarr; high'] = 'Nombre de photos, faible &rarr; élévé';
    6065
    6166?>
  • extensions/UserCollections/main.inc.php

    r21382 r23361  
    44Version: auto
    55Description: Registered users can select pictures from the gallery and save them into collections, like advanced favorites.
    6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=615
     6Plugin URI: auto
    77Author: Mistic
    88Author URI: http://www.strangeplanet.fr
     
    4141
    4242  // thumbnails actions
    43   add_event_handler('loc_end_index', 'user_collections_index_actions');
    4443  add_event_handler('loc_end_index_thumbnails', 'user_collections_thumbnails_list', EVENT_HANDLER_PRIORITY_NEUTRAL-10, 2);
    4544
  • extensions/UserCollections/template/list.tpl

    r17519 r23361  
    22
    33{footer_script require='jquery'}
    4 jQuery(".save_col").click(function() {ldelim}
     4jQuery(".new_col").click(function() {ldelim}
    55  var name = prompt("{'Collection name:'|@translate}");
    66  if (name != null) {ldelim}
     
    1111  }
    1212});
     13
     14jQuery(".titrePage h2").append(" [{$COLLECTIONS_COUNT}]");
    1315{/footer_script}
    14 
    15 {if $themeconf.name == "clear"}
    16 {html_head}{literal}
    17 <style type="text/css">.collecList a { color:#eee; }</style>
    18 {/literal}{/html_head}
    19 {/if}
    2016
    2117{* <!-- Menubar & titrePage --> *}
     
    3531
    3632
    37 <p style="text-align:left;font-weight:bold;margin:20px;"><a href="{$U_CREATE}" class="save_col">{'Create a new collection'|@translate}</a></p>
     33<p style="text-align:left;font-weight:bold;margin:20px;"><a href="{$U_CREATE}" class="new_col">{'Create a new collection'|@translate}</a></p>
    3834
    39 
    40 {if $temp_col}
    41 <fieldset>
    42   <legend>{'Unsaved collections'|@translate}</legend>
    43  
    44   <ul class="collecList">
    45   {foreach from=$temp_col item=col}
    46     <li {if $col.active}class="active"{/if}>
    47       <p class="collecTitle">
    48         <a href="{$col.U_EDIT}" rel="nofollow"><b>{$col.name}</b></a>
    49         <i>{'%d photos'|@translate|@sprintf:$col.nb_images}</i>
    50       </p>
    51       <p class="collecActions">
    52         <a href="{$col.U_EDIT}" rel="nofollow">{'Edit'|@translate}</a>
    53         | <a href="{$col.U_SAVE}" class="save_col" rel="nofollow">{'save'|@translate}</a>
    54         {if $col.U_DOWNLOAD}| <a href="{$col.U_DOWNLOAD}" rel="nofollow">{'download'|@translate}</a>{/if}
    55         | <a href="{$col.U_DELETE}" onClick="return confirm('{'Are you sure?'|@translate}');" rel="nofollow">{'Delete'|@translate}</a>
    56         {if not $col.active}| <a href="{$col.U_ACTIVE}" rel="nofollow">{'set active'|@translate}</a>{/if}
    57       </p>
    58     </li>
    59   {/foreach}
    60   </ul>
    61 </fieldset>
    62 {/if}
    63 
    64 
    65 {if $collections}
    66 <fieldset>
    67   <legend>{'Saved collections'|@translate}</legend>
    68  
    69   <ul class="collecList">
    70   {foreach from=$collections item=col}
    71     <li {if $col.active}class="active"{/if}>
    72       <p class="collecDate">
    73         {'created on %s'|@translate|@sprintf:$col.date_creation}
    74       </p>
    75       <p class="collecTitle">
    76         <a href="{$col.U_EDIT}" rel="nofollow"><b>{$col.name}</b></a>
    77         <i>{'%d photos'|@translate|@sprintf:$col.nb_images}</i>
    78       </p>
    79       <p class="collecActions">
    80         <a href="{$col.U_EDIT}" rel="nofollow">{'Edit'|@translate}</a>
    81         {if $col.U_DOWNLOAD}| <a href="{$col.U_DOWNLOAD}" rel="nofollow">{'download'|@translate}</a>{/if}
    82         | <a href="{$col.U_DELETE}" onClick="return confirm('{'Are you sure?'|@translate}');" rel="nofollow">{'Delete'|@translate}</a>
    83         {if not $col.active}| <a href="{$col.U_ACTIVE}" rel="nofollow">{'set active'|@translate}</a>{/if}
    84       </p>
    85     </li>
    86   {/foreach}
    87   </ul>
    88 </fieldset>
     35{if !empty($CATEGORIES)}
     36{$CATEGORIES}
     37{else}
     38{'You have no collection'|@translate}
    8939{/if}
    9040
  • extensions/UserCollections/template/menublock_user_collec.tpl

    r20097 r23361  
    1111                {foreach from=$block->data.collections item=col}
    1212                <li>
    13       <a href="{$col.U_EDIT}" {if $col.active}style="font-weight:bold;"{/if} rel="nofollow">{$col.name}</a>&nbsp;
    14       {if $col.active}<i class="menuInfoCat">({'active'|@translate})</i>&nbsp;{/if}
    15       <span class="menuInfoCat">[<span {if $col.count_handler}class="nbImagesCollec"{/if}>{$col.nb_images}</span>]</span>
     13      <a href="{$col.U_EDIT}" {*if $col.active}style="font-weight:bold;"{/if*} rel="nofollow">{$col.name}</a>&nbsp;
     14      {*if $col.active}<i class="menuInfoCat">({'active'|@translate})</i>&nbsp;{/if*}
     15      <span class="menuInfoCat">[<span class="nbImagesCollec-{$col.id}">{$col.nb_images}</span>]</span>
    1616    </li>
    1717                {/foreach}
    18     {if $block->data.MORE}<li class="menuInfoCat">{'%d more...'|@translate|sprintf:$block->data.MORE}</li>{/if}
     18    {if $block->data.MORE}<li class="menuInfoCat"><a href="{$block->data.U_LIST}">{'%d more...'|@translate|sprintf:$block->data.MORE}</a></li>{/if}
    1919        {/strip}</ul>
    2020  {/if}
  • extensions/UserCollections/template/style.css

    r21382 r23361  
    4242    margin-left:5px;
    4343  }
    44  
    45 .collecList {
    46   list-style:none;
    47   padding:0;
    48   margin:0;
     44
     45/* .thumbnailCategory.activeCollection {
     46  border:1px solid #999;
     47} */
     48.thumbnailCategory {
     49  position:relative;
    4950}
    50   .collecList li {
    51     height:35px;
    52     padding:5px 10px;
    53     margin:4px 0;
    54     background:#444;
    55     border-radius:4px;
    56   }
    57     .collecList li.active {
    58       background:#555;
    59       border:1px solid #999;
    60     }
    61   .collecList p {
    62     margin:0;
    63   }
    64     .collecList .collecDate {
    65       float:right;
    66       font-size:0.9em;
    67     }
    68     .collecList .collecActions {
    69       margin-top:2px;
    70       display:none;
    71     }
    72     .collecList li:hover .collecActions {
    73       display:block;
    74     }
    75  
     51.thumbnailCategory .collectionActions {
     52  display:none;
     53  position:absolute;
     54  right:5px;
     55  bottom:5px;
     56}
     57.thumbnailCategory:hover .collectionActions {
     58  display:block;
     59}
     60/* .thumbnailCategory .collectionActive {
     61  font-weight:normal;
     62  font-style:italic;
     63} */
     64
    7665/* SEND BY MAIL */
    7766#mail_form {
  • extensions/UserCollections/template/thumbnails_css_js.tpl

    r21382 r23361  
    1 {html_style}
    2 #thumbnails li {ldelim} position:relative !important;display:inline-block; }
    3 li .addCollection {ldelim} width:100%;height:16px;display:none;position:absolute;top:0;background:rgba(0,0,0,0.8);padding:2px;border-radius:2px;font-size:10px;z-index:100 !important;color:#eee;white-space:nowrap; }
    4 li:hover .addCollection {ldelim} display:block !important; }
    5 {/html_style}
    6 
    7 {if not $NO_AJAX}
     1{combine_css path=$USER_COLLEC_PATH|@cat:"template/style_thumbnails.css"}
     2
     3{* <!-- all pages but collection edit page --> *}
     4{if not $UC_IN_EDIT}
    85{footer_script require='jquery'}
    9 jQuery(".addCollection").click(function() {ldelim}
    10   var $trigger = jQuery(this);
    11   var toggle_id = $trigger.data("id");
    12   var method = $trigger.data("stat");
    13  
    14   if (method != "add" && method != "remove") {ldelim}
    15     $trigger.html("{'Un unknown error occured'|@translate}");
     6var $cdm = jQuery("#collectionsDropdown");
     7
     8{if not $IN_PICTURE}
     9$cdm.on("mouseleave", function() {ldelim}
     10  $cdm.hide();
     11});
     12{/if}
     13
     14// click on "create collection" button
     15$cdm.find("a.new").on("click", function(event) {ldelim}
     16  jQuery(this).hide().next().show().focus();
     17  event.stopPropagation();
     18  return false;
     19});
     20
     21// events on "new collection" input
     22$cdm.find("input.new").on({ldelim}
     23  // ENTER pressed
     24  "keyup": function(event) {ldelim}
     25    if (event.which != 13) return;
     26   
     27    jQuery(this).hide().prev().show();
     28    var name = jQuery(this).val();
     29    jQuery(this).val("{'Name'|@translate}");
     30   
     31    if (name == "") return;
     32   
     33    jQuery.ajax({ldelim}
     34      type: "GET",
     35      dataType: "json",
     36      url: "{$ROOT_URL}ws.php",
     37      data: {ldelim}
     38        format: "json",
     39        method: "pwg.collections.create",
     40        name: name,
     41        active: 1,
     42      },
     43      success: function(data) {ldelim}
     44        if (data.stat == 'ok') {ldelim}
     45          var col = data.result;
     46          var html = '<span>&#9733;</span> <a class="add" data-id="'+ col.id +'">'+ col.name +'</a> '
     47            +'<span class="menuInfoCat">[<span class="nbImagesCollec-'+ col.id +'">'+ col.nb_images +'</span>]</span> '
     48            +'<a class="remove" data-id="'+ col.id +'">{'(remove)'|@translate}</a>'
     49            +'<br>';
     50         
     51          $cdm.children(".switchBoxFooter").before(html);
     52          $cdm.children(".noCollecMsg").remove();
     53        }
     54        else {ldelim}
     55          alert(data.message);
     56        }
     57      },
     58      error: function() {ldelim}
     59        alert("{'Un unknown error occured'|@translate}");
     60      }
     61    });
     62   
    1663    return false;
     64  },
     65  // prevent click propagation
     66  "click": function(event) {ldelim}
     67    event.stopPropagation();
     68  },
     69  // remove help on focus
     70  "focus": function() {ldelim}
     71    if (jQuery(this).val() == "{'Name'|@translate}") jQuery(this).val("");
     72  },
     73  // restore help on blur
     74  "blur" : function() {ldelim}
     75    if (jQuery(this).val() == "") jQuery(this).val("{'Name'|@translate}");
    1776  }
     77});
     78
     79// add and remove links (delegate for new collections)
     80$cdm.on("click", ".add, .remove", function() {ldelim}
     81  var img_id = $cdm.data("img_id");
     82  var col_id = jQuery(this).data("id");
     83  var method = jQuery(this).hasClass("add") ? "pwg.collections.addImages" : "pwg.collections.removeImages";
    1884 
    1985  jQuery.ajax({ldelim}
     
    2187    dataType: "json",
    2288    url: "{$ROOT_URL}ws.php",
    23     data: {ldelim} "format": "json", "method": "pwg.collections."+method+"Images", "col_id": {$AJAX_COL_ID}, "image_ids": toggle_id },
     89    data: {ldelim}
     90      format: "json",
     91      method: method,
     92      col_id: col_id,
     93      image_ids: img_id
     94    },
    2495    success: function(data) {ldelim}
    25       if (data['stat'] == 'ok') {ldelim}
    26         if (method == "add") {ldelim}
    27           $trigger.children(".uc_remove").show();
    28           $trigger.children(".uc_add").hide();
    29           $trigger.data("stat", "remove");
    30         }
    31         else if (method == "remove") {ldelim}
    32         {if $UC_IN_EDIT}
    33           $trigger.parent("li").hide("fast", function() {ldelim} $(this).remove() });
    34           if (typeof batchdown_count != 'undefined') batchdown_count-=1;
    35         {else}
    36           $trigger.children(".uc_remove").hide();
    37           $trigger.children(".uc_add").show();
    38           $trigger.data("stat", "add");
    39         {/if}
    40         }
     96      if (data.stat == 'ok') {ldelim}
     97        // update col counters
     98        jQuery(".nbImagesCollec-"+col_id).html(data.result.nb_images);
    4199       
    42         jQuery(".nbImagesCollec").html(data['result']['nb_images']);
     100        // update item datas
     101        var $target = jQuery(".addCollection[data-id='"+ img_id +"']");
     102        var col_ids = $target.data("cols");
     103        if (method == "pwg.collections.addImages" && col_ids.indexOf(col_id) == -1)
     104          col_ids[ col_ids.length ] = col_id;
     105        else
     106          col_ids.splice(col_ids.indexOf(col_id), 1);
     107        $target.data("col", col_ids);
    43108      }
    44109      else {ldelim}
    45         $trigger.html("{'Un unknown error occured'|@translate}");
     110        alert(data.message);
    46111      }
    47112    },
    48113    error: function() {ldelim}
    49       $trigger.html("{'Un unknown error occured'|@translate}");
    50     }
    51   });
    52  
     114      alert("{'Un unknown error occured'|@translate}");
     115    }
     116  });
     117 
     118  $cdm.hide();
     119  return false;
     120});
     121
     122// main button, open the menu
     123jQuery(".addCollection").on("click", function(event) {ldelim}
     124  var img_id = jQuery(this).data("id");
     125  var col_ids = jQuery(this).data("cols");
     126 
     127  $cdm.data("img_id", img_id);
     128 
     129  $cdm.children(".add").each(function() {ldelim}   
     130    if (col_ids.indexOf($(this).data("id")) != -1) {ldelim}
     131      $(this).css("font-weight", "bold").next().next().show();
     132    }
     133    else {ldelim}
     134      $(this).css("font-weight", "normal").next().next().hide();
     135    }
     136  });
     137 
     138  {if not $IN_PICTURE}
     139  $cdm.css({ldelim}
     140    "top": event.pageY-5-$(window).scrollTop(),
     141    "left": Math.min(event.pageX-jQuery(window).scrollLeft()-20, jQuery(window).width()-$cdm.outerWidth(true)-5)
     142  });
     143  $cdm.show();
     144  {/if}
     145 
     146  return false;
     147});
     148
     149// try to respect theme colors
     150$cdm.children(".switchBoxFooter").css("border-top-color", $cdm.children(".switchBoxTitle").css("border-bottom-color"));
     151{/footer_script}
     152
     153<div id="collectionsDropdown" class="switchBox">
     154  <div class="switchBoxTitle">{'Collections'|@translate}</div>
     155 
     156  {foreach from=$COLLECTIONS item=col}
     157    <span>&#9733;</span> <a class="add" data-id="{$col.id}">{$col.name}</a>
     158    <span class="menuInfoCat">[<span class="nbImagesCollec-{$col.id}">{$col.nb_images}</span>]</span>
     159    <a class="remove" data-id="{$col.id}">{'(remove)'|@translate}</a>
     160    <br>
     161  {foreachelse}
     162    <span class="noCollecMsg">{'You have no collection'|@translate}</span>
     163  {/foreach}
     164 
     165  <div class="switchBoxFooter">
     166  <span>&#10010;</span> <a class="new">{'Create a new collection'|@translate}</a>
     167  <input class="new" value="{'Name'|@translate}" size="25"/>
     168  </div>
     169</div>
     170
     171{* <!-- collection edit page --> *}
     172{else}
     173{footer_script require='jquery'}
     174jQuery(".addCollection").on("click", function(event) {ldelim}
     175  var $trigger = jQuery(this);
     176  var img_id = jQuery(this).data("id");
     177  var col_id = {$collection.ID};
     178 
     179  jQuery.ajax({ldelim}
     180    type: "GET",
     181    dataType: "json",
     182    url: "{$ROOT_URL}ws.php",
     183    data: {ldelim}
     184      format: "json",
     185      method: "pwg.collections.removeImages",
     186      col_id: col_id,
     187      image_ids: img_id
     188    },
     189    success: function(data) {ldelim}
     190      if (data.stat == 'ok') {ldelim}
     191        $trigger.parent("li").hide("fast", function() {ldelim}
     192          jQuery(this).remove();
     193          if (typeof GThumb != "undefined") GThumb.build();
     194        });
     195       
     196        jQuery(".nbImagesCollec-"+col_id).html(data.result.nb_images);
     197        if (typeof batchdown_count != 'undefined') batchdown_count = data.result.nb_images;
     198      }
     199      else {ldelim}
     200        alert(data.message);
     201      }
     202    },
     203    error: function() {ldelim}
     204      alert("{'Un unknown error occured'|@translate}");
     205    }
     206  });
     207 
     208  // not working, the event is fired twice
     209  event.stopPropagation();
     210  event.preventDefault();
    53211  return false;
    54212});
Note: See TracChangeset for help on using the changeset viewer.