Changeset 20097


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

full compatibility with Gthumb+, improve some code

Location:
extensions/UserCollections
Files:
1 added
1 deleted
6 edited

Legend:

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

    r20093 r20097  
    250250      }
    251251     
    252      
    253       // add links for colorbox
    254       add_event_handler('loc_end_index_thumbnails', 'user_collections_thumbnails_in_collection', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
    255      
    256252      // add remove item links
    257253      $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_prefilter');
    258254     
    259255      // thumbnails
    260       define('USER_COLLEC_REMOVE_GTHUMB', true);
    261256      include(USER_COLLEC_PATH . '/include/display_thumbnails.inc.php');
    262257     
     
    335330function user_collections_thumbnails_in_collection($tpl_thumbnails_var, $pictures)
    336331{
    337   global $template, $page;
    338  
    339   $template->set_filename('index_thumbnails', dirname(__FILE__).'/../template/thumbnails.tpl');
     332  global $template;
    340333 
    341334  foreach ($tpl_thumbnails_var as &$thumbnail)
     
    354347  }
    355348 
     349  $template->set_prefilter('index_thumbnails', 'user_collections_add_colorbox');
     350 
    356351  return $tpl_thumbnails_var;
    357352}
    358353
     354function user_collections_add_colorbox($content)
     355{
     356  // add datas
     357  $search = '<a href="{$thumbnail.URL}"';
     358  $replace = $search.' class="preview-box" data-src="{$thumbnail.FILE_SRC}" data-id="{$thumbnail.id}"';
     359 
     360  // colorbox script
     361  $content.= file_get_contents(USER_COLLEC_PATH.'template/thumbnails_colorbox.tpl');
     362 
     363  return str_replace($search, $replace, $content);
     364}
     365
    359366?>
  • extensions/UserCollections/include/display_thumbnails.inc.php

    r20093 r20097  
    7575}
    7676
    77 
    78 // display
    79 if (defined('USER_COLLEC_REMOVE_GTHUMB'))
    80 {
    81   global $uc_nb_image_page_save;
    82 
    83   $user['nb_image_page'] = $uc_nb_image_page_save['user'];
    84   $page['nb_image_page'] = $uc_nb_image_page_save['page'];
    85   remove_event_handler('loc_end_index_thumbnails', 'process_GThumb', 50);
    86   remove_event_handler('loc_end_index', 'GThumb_remove_thumb_size');
    87 }
     77// add links for colorbox
     78add_event_handler('loc_end_index_thumbnails', 'user_collections_thumbnails_in_collection', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
    8879
    8980include(PHPWG_ROOT_PATH . 'include/category_default.inc.php');
  • 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]);
  • extensions/UserCollections/main.inc.php

    r20090 r20097  
    3232{
    3333  // collections page
    34   add_event_handler('loc_begin_index', 'user_collections_save_pagination', EVENT_HANDLER_PRIORITY_NEUTRAL-10);
    3534  add_event_handler('loc_end_section_init', 'user_collections_section_init');
    3635  add_event_handler('loc_end_index', 'user_collections_page', EVENT_HANDLER_PRIORITY_NEUTRAL-10);
     
    3837  // thumbnails actions
    3938  add_event_handler('loc_end_index', 'user_collections_index_actions');
    40   add_event_handler('loc_end_index_thumbnails', 'user_collections_thumbnails_list', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
     39  add_event_handler('loc_end_index_thumbnails', 'user_collections_thumbnails_list', EVENT_HANDLER_PRIORITY_NEUTRAL-10, 2);
    4140
    4241  // picture action
  • extensions/UserCollections/template/menublock_user_collec.tpl

    r16698 r20097  
    33  <p>
    44    {if $block->data.NB_COL == 0}
    5       {'You have no collection'|@translate|sprintf:$block->data.NB_COL}
     5      {'You have no collection'|@translate}
    66    {else}
    77      <a href="{$block->data.U_LIST}">{$pwg->l10n_dec('You have %d collection', 'You have %d collections', $block->data.NB_COL)}</a>
     
    1010  <ul>{strip}
    1111                {foreach from=$block->data.collections item=col}
    12                 <li>{if $col.active}
    13       <a href="{$col.U_EDIT}" style="font-weight:bold;" rel="nofollow">{$col.name}</a> <i class="menuInfoCat">({'active'|@translate})</i> <span class="menuInfoCat">[<span class="nbImagesCollec">{$col.nb_images}</span>]</span>
    14     {else}
    15       <a href="{$col.U_EDIT}" rel="nofollow">{$col.name}</a> <span class="menuInfoCat">[{$col.nb_images}]</span>
    16     {/if}</li>
     12                <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>
     16    </li>
    1717                {/foreach}
    1818    {if $block->data.MORE}<li class="menuInfoCat">{'%d more...'|@translate|sprintf:$block->data.MORE}</li>{/if}
  • extensions/UserCollections/template/thumbnails_css_js.tpl

    r20090 r20097  
    11{html_style}
    22.thumbnails .wrap1 {ldelim} position:relative !important; }
    3 .wrap1 .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;color:#eee;white-space:nowrap; }
    4 .wrap1:hover .addCollection {ldelim} display:block; }
     3.wrap1 .addCollection, .gthumb .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.wrap1:hover .addCollection, .gthumb:hover .addCollection {ldelim} display:block; }
    55{/html_style}
    66
     
    1717  }).done(function(msg) {ldelim}
    1818    if (msg == "true") {ldelim}
    19       $trigger.html('{'Remove from collection'|@translate}&nbsp;<img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/resources/image_delete.png" title="{'Remove from collection'|@translate}">');
     19      $trigger.children(".uc_remove").show();
     20      $trigger.children(".uc_add").hide();
    2021      jQuery(".nbImagesCollec").html(parseInt(jQuery(".nbImagesCollec").html()) +1);
    2122    } else if (msg == "false") {ldelim}
    2223    {if $COL_ID}
    23       $trigger.parent(".wrap1").hide("fast", function() {ldelim} $trigger.remove() });
     24      $trigger.parent(".wrap1, .gthumb").hide("fast", function() {ldelim} $trigger.remove() });
    2425      if (typeof batchdown_count != 'undefined') batchdown_count-=1;
    2526    {else}
    26       $trigger.html('{'Add to collection'|@translate}&nbsp;<img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/resources/image_add.png" title="{'Add to collection'|@translate}">');
     27      $trigger.children(".uc_remove").hide();
     28      $trigger.children(".uc_add").show();
    2729    {/if}
    28       jQuery(".nbImagesCollec").html(parseInt(jQuery(".nbImagesCollec").html()) -1);
     30    jQuery(".nbImagesCollec").html(parseInt(jQuery(".nbImagesCollec").html()) -1);
    2931    } else {ldelim}
    3032      $trigger.html('{'Un unknown error occured'|@translate}');
Note: See TracChangeset for help on using the changeset viewer.