Ignore:
Timestamp:
Jan 13, 2013, 12:29:56 AM (11 years ago)
Author:
mistic100
Message:

full compatibility with Gthumb+, improve some code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/UserCollections/include/events.inc.php

    r20093 r20097  
    22defined('USER_COLLEC_PATH') or die('Hacking attempt!');
    33
    4 # this file contains all functions directly called by the triggers #
    5 
    6 /* compatibility fix with Gthumb+ */
    7 function user_collections_save_pagination()
    8 {
    9   global $user, $page, $uc_nb_image_page_save;
    10    
    11   $uc_nb_image_page_save['user'] = $user['nb_image_page'];
    12   $uc_nb_image_page_save['page'] = $page['nb_image_page'];
    13 }
    14 
    15 
     4// +-----------------------------------------------------------------------+
     5// | SECTION INIT
     6// +-----------------------------------------------------------------------+
    167/* define page section from url */
    178function user_collections_section_init()
     
    5243
    5344
    54 /* add buttons on thumbnails list */
     45// +-----------------------------------------------------------------------+
     46// | CATEGORY PAGE
     47// +-----------------------------------------------------------------------+
     48/* toggle an image, in case of no javascript or first call (must create the collection) */
    5549function user_collections_index_actions()
    5650{
     
    7165}
    7266
     67/* add buttons on thumbnails list */
    7368function user_collections_thumbnails_list($tpl_thumbnails_var, $pictures)
    7469{
     
    7772  global $page, $template, $UserCollection;
    7873 
    79   // the prefilter is different on collection page
    80   if (isset($page['section']) and ($page['section'] == 'collections' or $page['section'] == 'download')) return $tpl_thumbnails_var;
     74  // the content is different on collection edition page and no button on batch downloader set edition page
     75  if ( (@$page['section'] == 'collections' and @$page['sub_section']=='edit') or @$page['section'] == 'download')
     76  {
     77    return $tpl_thumbnails_var;
     78  }
    8179 
    8280  // get existing collections
     
    9694  }
    9795 
    98   // if the collection is created we don't use AJAX to force menu refresh
     96  // if the collection doesn't exists we don't use AJAX to force menu refresh
    9997  if ($col_id === false)
    10098  {
     
    102100  }
    103101 
    104  
    105   $self_url = duplicate_index_url(array(), array('collection_toggle')); 
     102  // template vars
     103  $url = duplicate_index_url(array(), array('collection_toggle')); 
    106104 
    107105  foreach ($tpl_thumbnails_var as &$thumbnail)
     
    114112  unset($thumbnail);
    115113 
    116   // thumbnails buttons
    117114  $template->assign(array(
    118115    'USER_COLLEC_PATH' => USER_COLLEC_PATH,
    119     'collection_toggle_url' =>  add_url_params($self_url, array('collection_toggle'=>'')),
     116    'collection_toggle_url' =>  add_url_params($url, array('collection_toggle'=>'')),
    120117    ));
     118 
     119  // thumbnails buttons
    121120  $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_prefilter');
    122121 
     
    127126{
    128127  // add links
    129   $search = '<span class="wrap1">';
    130   $replace = $search.'
     128  $search = '#(<span class="wrap1">|<li class="gthumb">)#';
     129  $replace = '$1
    131130{strip}<a class="addCollection" href="{$collection_toggle_url}{$thumbnail.id}" data-id="{$thumbnail.id}" rel="nofollow">
    132 {if $COL_ID or $thumbnail.COLLECTION_SELECTED}
     131<span class="uc_remove" {if not $COL_ID and not $thumbnail.COLLECTION_SELECTED}style="display:none;"{/if}>
    133132{\'Remove from collection\'|@translate}&nbsp;<img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/resources/image_delete.png" title="{\'Remove from collection\'|@translate}">
    134 {else}
     133</span>
     134<span class="uc_add" {if $COL_ID or $thumbnail.COLLECTION_SELECTED}style="display:none;"{/if}>
    135135{\'Add to collection\'|@translate}&nbsp;<img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/resources/image_add.png" title="{\'Add to collection\'|@translate}">
    136 {/if}
     136</span>
    137137</a>{/strip}';
    138138
    139139  // custom CSS and AJAX request
    140140  $content.= file_get_contents(USER_COLLEC_PATH.'template/thumbnails_css_js.tpl');
    141 
    142   return str_replace($search, $replace, $content);
    143 }
    144 
    145 
     141 
     142  return preg_replace($search, $replace, $content);
     143}
     144
     145
     146// +-----------------------------------------------------------------------+
     147// | PICTURE PAGE
     148// +-----------------------------------------------------------------------+
    146149/* add button on picture page */
    147150function user_collections_picture_page()
     
    190193
    191194
    192 /* menu block */
     195// +-----------------------------------------------------------------------+
     196// | MENU BLOCK
     197// +-----------------------------------------------------------------------+
     198/* register block */
    193199function user_collections_add_menublock($menu_ref_arr)
    194200{
     
    201207}
    202208
     209/* fill block */
    203210function user_collections_applymenu($menu_ref_arr)
    204211{
    205212  $max = 6;
    206213 
    207   global $template, $conf, $user, $UserCollection;
     214  global $template, $page, $conf, $user, $UserCollection;
    208215  $menu = &$menu_ref_arr[0];
     216 
     217  // the editable counter is for the active collection, except if we are currently editing a collection
     218  $col_in_edit = 0;
     219  if ( @$page['section'] == 'collections' and @$page['sub_section']=='edit' and !empty($page['col_id']) )
     220  {
     221    $col_in_edit = $page['col_id'];
     222  }
    209223 
    210224  if (($block = $menu->get_block('mbUserCollection')) != null)
     
    223237    for ($i=0; $i<$max && $i<count($collections); $i++)
    224238    {
     239      $collections[$i]['count_handler'] = $col_in_edit!=0 ? $collections[$i]['id']==$col_in_edit : $collections[$i]['active'];
    225240      $collections[$i]['U_EDIT'] = USER_COLLEC_PUBLIC.'edit/'.$collections[$i]['id'];
    226241      array_push($data['collections'], $collections[$i]);
Note: See TracChangeset for help on using the changeset viewer.