Changeset 16688


Ignore:
Timestamp:
Jul 13, 2012, 12:09:19 PM (8 years ago)
Author:
mistic100
Message:

-rework the main menu
-bug when a collection is create through AJAX
-add "Remove from collection" on colorbox
-minor interfaces changes

Location:
extensions/UserCollections
Files:
13 edited

Legend:

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

    r16658 r16688  
    1717   
    1818    $this->data = array(
    19       'col_id' => 0,
     19      'id' => 0,
    2020      'user_id' => $user['id'],
    2121      'name' => null,
     
    5353      $query = '
    5454SELECT
     55    id,
    5556    user_id,
    5657    name,
     
    6970      if (pwg_db_num_rows($result))
    7071      {
    71         $this->data['col_id'] = $col_id;
    7272        $this->data = array_merge(
    7373          $this->data,
     
    8787SELECT image_id
    8888  FROM '.COLLECTION_IMAGES_TABLE.'
    89   WHERE col_id = '.$this->data['col_id'].'
     89  WHERE col_id = '.$this->data['id'].'
    9090;';
    9191        $this->images = array_from_query($query, 'image_id');
     
    107107      $this->data['active'] = $active;
    108108      $this->data['public'] = $public;
    109       $this->data['public_id'] = 'uc'.hash('crc32', uniqid(serialize($this->data, true)));
     109      $this->data['public_id'] = 'uc'.hash('crc32', uniqid(serialize($this->data), true));
    110110     
    111111      $query = '
     
    128128;';
    129129      pwg_query($query);
    130       $this->data['col_id'] = pwg_db_insert_id();
     130      $this->data['id'] = pwg_db_insert_id();
    131131     
    132132      $date = pwg_query('SELECT FROM_UNIXTIME(NOW());');
     
    146146  WHERE
    147147    user_id = '.$this->data['user_id'].'
    148     AND id != '.$this->data['col_id'].'
     148    AND id != '.$this->data['id'].'
    149149;';
    150150        pwg_query($query);
     
    165165  {
    166166    $this->data[$name] = $value;
    167     pwg_query('UPDATE '.COLLECTIONS_TABLE.' SET '.$name.' = "'.$value.'" WHERE id = '.$this->data['col_id'].';');
     167    pwg_query('UPDATE '.COLLECTIONS_TABLE.' SET '.$name.' = "'.$value.'" WHERE id = '.$this->data['id'].';');
    168168  }
    169169 
     
    213213DELETE FROM '.COLLECTION_IMAGES_TABLE.'
    214214  WHERE
    215     col_id = '.$this->data['col_id'].'
     215    col_id = '.$this->data['id'].'
    216216    AND image_id IN('.implode(',', $image_ids).')
    217217;';
     
    237237     
    238238      array_push($this->images, $image_id);
    239       array_push($inserts, array('col_id'=>$this->data['col_id'], 'image_id'=>$image_id));
     239      array_push($inserts, array('col_id'=>$this->data['id'], 'image_id'=>$image_id));
    240240    }
    241241   
     
    275275    $query = '
    276276DELETE FROM '.COLLECTION_IMAGES_TABLE.'
    277   WHERE col_id = '.$this->data['col_id'].'
     277  WHERE col_id = '.$this->data['id'].'
    278278;';
    279279    pwg_query($query);
  • extensions/UserCollections/include/collections.inc.php

    r16658 r16688  
    2424        case 'new':
    2525        {
    26           new UserCollection('new', array(), empty($_GET['name']) ? 'temp' : $_GET['name'], 1);
    27           redirect(USER_COLLEC_PUBLIC);
    28           break;
    29         }
    30        
    31         // clear
    32         case 'clear':
    33         {
    34           $query = '
    35 DELETE ci
    36   FROM '.COLLECTION_IMAGES_TABLE.' AS ci
    37     INNER JOIN '.COLLECTIONS_TABLE.' AS c
    38     ON ci.col_id = c.id
    39   WHERE
    40     c.user_id = '.$user['id'].'
    41     AND c.id = '.$_GET['col_id'].'
    42 ;';
    43           pwg_query($query);
     26          $UserCollection = new UserCollection('new', array(), empty($_GET['name']) ? 'temp' : $_GET['name'], 1);
    4427         
    45           if (!empty($_SERVER['HTTP_REFERER']))
     28          if (isset($_GET['redirect']))
    4629          {
    47             redirect($_SERVER['HTTP_REFERER']);
     30            $redirect = USER_COLLEC_PUBLIC.'edit/'.$UserCollection->getParam('id');
    4831          }
     32          else
     33          {
     34            $redirect = USER_COLLEC_PUBLIC;
     35          }
     36          redirect($redirect);
    4937          break;
    5038        }
     
    194182      }
    195183     
     184      // clear
     185      if ( isset($_GET['action']) and $_GET['action'] == 'clear' )
     186      {
     187        $UserCollection->clearImages();
     188      }
     189     
    196190      // remove an element
    197191      if ( isset($_GET['collection_toggle']) and preg_match('#^[0-9]+$#', $_GET['collection_toggle']) )
    198192      {
    199193        $UserCollection->removeImages(array($_GET['collection_toggle']));
     194        unset($_GET['collection_toggle']);
    200195      }
    201196     
     
    205200     
    206201      // collection content
    207       $template->assign('collection', $UserCollection->getCollectionInfo());
     202      $col = $UserCollection->getCollectionInfo();
     203      $col['U_CLEAR'] = $self_url.'&action=clear';
     204      $col['U_DELETE'] = USER_COLLEC_PUBLIC.'&action=delete&col_id='.$page['col_id'];
     205      $template->assign('collection', $col);
     206     
    208207      $page['items'] = $UserCollection->getImages();
    209208     
     
    252251      $UserCollection = new UserCollection($page['col_id']);
    253252     
    254       // backlink for owner
    255       if ($UserCollection->getParam('user_id') == $user['id'])
    256       {
    257         $template->assign('U_LIST', USER_COLLEC_PUBLIC);
    258       }
    259      
    260253      // special template
    261254      add_event_handler('loc_end_index_thumbnails', 'user_collections_thumbnails_in_collection', EVENT_HANDLER_PRIORITY_NEUTRAL+10, 2); // +10 to overload GThumb+
    262255     
    263256      // collection content
    264       $template->assign('collection', $UserCollection->getCollectionInfo());
    265257      $page['items'] = $UserCollection->getImages();
    266258     
  • extensions/UserCollections/include/events.inc.php

    r16625 r16688  
    216216function user_collections_applymenu($menu_ref_arr)
    217217{
    218   global $template, $conf, $UserCollection;
     218  $max = 6;
     219 
     220  global $template, $conf, $user, $UserCollection;
    219221  $menu = &$menu_ref_arr[0];
    220222 
    221223  if (($block = $menu->get_block('mbUserCollection')) != null)
    222224  {
    223     if (($col_id = get_current_collection_id(false)) !== false)
    224     {
    225       if (empty($UserCollection))
    226       {
    227         $UserCollection = new UserCollection($col_id);
    228       }
    229    
    230       $data = array(
    231         'current' => array(
    232           'NAME' => $UserCollection->getParam('name'),
    233           'NB_IMAGES' => $UserCollection->getParam('nb_images'),
    234           ),
    235         'links' => array(),
    236         );
    237        
    238       if ($data['current']['NB_IMAGES'] > 0)
    239       {
    240         $data['links'] = array(
    241           array(
    242             'URL' => USER_COLLEC_PUBLIC.'edit/'.$UserCollection->getParam('col_id'),
    243             'NAME' => l10n('Display collection'),
    244             ),
    245           array(
    246             'URL' => USER_COLLEC_PUBLIC.'&action=clear&col_id='.$UserCollection->getParam('col_id'),
    247             'NAME' => l10n('Clear collection'),
    248             ),
    249           );
    250       }
     225    $query = '
     226SELECT *
     227  FROM '.COLLECTIONS_TABLE.'
     228  WHERE user_id = '.$user['id'].'
     229  ORDER BY
     230    active DESC,
     231    date_creation DESC
     232;';
     233    $collections = array_values(hash_from_query($query, 'id'));
     234   
     235    $data['collections'] = array();
     236    for ($i=0; $i<$max && $i<count($collections); $i++)
     237    {
     238      $collections[$i]['U_EDIT'] = USER_COLLEC_PUBLIC.'edit/'.$collections[$i]['id'];
     239      array_push($data['collections'], $collections[$i]);
     240    }
     241   
     242    $data['NB_COL'] = count($collections);
     243    if ($data['NB_COL'] > $max)
     244    {
     245      $data['MORE'] = count($collections)-$max;
    251246    }
    252247   
    253248    $data['U_LIST'] = USER_COLLEC_PUBLIC;
     249    $data['U_CREATE'] = USER_COLLEC_PUBLIC.'&amp;action=new&amp;col_id=0&amp;redirect=true';
    254250   
    255251    $template->set_template_dir(USER_COLLEC_PATH . 'template/');
    256     $block->set_title(l10n('Collections'));
     252    $block->set_title('<a href="'.USER_COLLEC_PUBLIC.'">'.l10n('Collections').'</a>');
    257253    $block->template = 'menublock_user_collec.tpl';
    258254    $block->data = $data;
  • extensions/UserCollections/include/functions.inc.php

    r16591 r16688  
    2626  {
    2727    $UserCollection = new UserCollection('new', array(), 'temp', 1);
    28     return $UserCollection->getParam('col_id');
     28    return $UserCollection->getParam('id');
    2929  }
    3030 
  • extensions/UserCollections/language/en_UK/plugin.lang.php

    r16599 r16688  
    1212$lang['set active'] = 'set active';
    1313$lang['Saved collections'] = 'Saved collections';
    14 $lang['Current collection:'] = 'Current collection:';
    1514$lang['See all my collections'] = 'See all my collections';
    1615$lang['Please give a name'] = 'Please give a name';
     
    2120$lang['Remove from collection'] = 'Remove from collection';
    2221$lang['Add to collection'] = 'Add to collection';
    23 $lang['Display collection'] = 'Display';
    2422$lang['Clear collection'] = 'Clear';
     23$lang['You have %d collections'] = 'You have %d collections';
     24$lang['active'] = 'active';
     25$lang['Save'] = 'Save';
     26$lang['%d more...'] = '%d more...';
    2527
    2628?>
  • extensions/UserCollections/language/fr_FR/plugin.lang.php

    r16599 r16688  
    1212$lang['set active'] = 'choisir comme collection active';
    1313$lang['Saved collections'] = 'Collections sauvegardées';
    14 $lang['Current collection:'] = 'Collection actuelle:';
    1514$lang['See all my collections'] = 'Voir toutes mes collections';
    1615$lang['Please give a name'] = 'Veuillez donner un nom';
     
    2120$lang['Remove from collection'] = 'Supprimer de la collection';
    2221$lang['Add to collection'] = 'Ajouter à la collection';
    23 $lang['Display collection'] = 'Afficher';
    2422$lang['Clear collection'] = 'Vider';
     23$lang['You have %d collections'] = 'Vous avez %d collections';
     24$lang['active'] = 'active';
     25$lang['Save'] = 'Sauvegarder';
     26$lang['%d more...'] = 'et %d autres...';
    2527
    2628?>
  • extensions/UserCollections/main.inc.php

    r16597 r16688  
    2323
    2424add_event_handler('loc_end_section_init', 'user_collections_section_init');
    25 add_event_handler('loc_end_index', 'user_collections_page');
     25add_event_handler('loc_end_index', 'user_collections_page', EVENT_HANDLER_PRIORITY_NEUTRAL-10);
    2626
    2727add_event_handler('loc_end_index', 'user_collections_index_actions');
  • extensions/UserCollections/template/edit.tpl

    r16658 r16688  
    2323  delay: 0,
    2424  defaultPosition: 'right'
     25});
     26
     27jQuery("#actions input").click(function() {ldelim}
     28  if (confirm("{'Are you sure?'|@translate}")) {ldelim}
     29    document.location.href = jQuery(this).data("href");
     30  }
     31  return false;
    2532});
    2633{if $collection.PUBLIC}bindZclip();{/if}
     
    4956
    5057
    51 {if $collection and not $collection.IS_TEMP}
     58{if $collection}
    5259<form action="{$F_ACTION}" method="post">
    5360<fieldset id="colProperties">
     
    6875</fieldset>
    6976</form>
    70 {/if}
    7177
    7278
    73 {if !empty($THUMBNAILS)}
     79{if $collection.NB_IMAGES > 0}
    7480<ul class="thumbnails" id="thumbnails">
    7581{$THUMBNAILS}
     
    8288
    8389
    84 <p style="text-align:center;font-weight:bold;margin:20px;"><a href="{$U_LIST}" rel="nofollow">{'Return to collections list'|@translate}</a></p>
     90<form id="actions" style="text-align:center;">
     91<input type="submit" data-href="{$collection.U_CLEAR}" value="{'Clear collection'|@translate}">
     92<input type="submit" data-href="{$collection.U_DELETE}" value="{'Delete'|@translate}">
     93</form>
     94{/if}
     95
    8596
    8697</div>{* <!-- content --> *}
  • extensions/UserCollections/template/list.tpl

    r16658 r16688  
    5656        | <a href="{$col.U_SAVE}" class="save_col" rel="nofollow">{'save'|@translate}</a>
    5757        {if $col.U_DOWNLOAD}| <a href="{$col.U_DOWNLOAD}" rel="nofollow">{'download'|@translate}</a>{/if}
    58         | <a href="{$col.U_DELETE}" onClick="return confirm('{'Are you sure?'|@translate}');" rel="nofollow">{'delete'|@translate}</a>
     58        | <a href="{$col.U_DELETE}" onClick="return confirm('{'Are you sure?'|@translate}');" rel="nofollow">{'Delete'|@translate}</a>
    5959        {if not $col.active}| <a href="{$col.U_ACTIVE}" rel="nofollow">{'set active'|@translate}</a>{/if}
    6060      </p>
     
    8383        <a href="{$col.U_EDIT}" rel="nofollow">{'Edit'|@translate}</a>
    8484        {if $col.U_DOWNLOAD}| <a href="{$col.U_DOWNLOAD}" rel="nofollow">{'download'|@translate}</a>{/if}
    85         | <a href="{$col.U_DELETE}" onClick="return confirm('{'Are you sure?'|@translate}');" rel="nofollow">{'delete'|@translate}</a>
     85        | <a href="{$col.U_DELETE}" onClick="return confirm('{'Are you sure?'|@translate}');" rel="nofollow">{'Delete'|@translate}</a>
    8686        {if not $col.active}| <a href="{$col.U_ACTIVE}" rel="nofollow">{'set active'|@translate}</a>{/if}
    8787      </p>
  • extensions/UserCollections/template/menublock_user_collec.tpl

    r16625 r16688  
    11<dt>{$block->get_title()}</dt>
    22<dd>
    3 {if $block->data.current}
    4   {assign var="nb_images" value='<span class="nbImagesCollec">'|@cat:$block->data.current.NB_IMAGES|@cat:'</span>'}
    5   <p>{'Current collection:'|@translate} <b>{$block->data.current.NAME}</b>, {'%d photos'|@translate|replace:'%d':'%s'|sprintf:$nb_images}</p>
    6         <ul>{strip}
    7                 {foreach from=$block->data.links item=link}
    8                 <li><a href="{$link.URL}" title="{$link.TITLE}" rel="nofollow">{$link.NAME}</a></li>
     3  <p><a href="{$block->data.U_LIST}">{'You have %d collections'|@translate|sprintf:$block->data.NB_COL}</a></p>
     4  {if $block->data.collections}
     5  <ul>{strip}
     6                {foreach from=$block->data.collections item=col}
     7                <li>{if $col.active}
     8      <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>
     9    {else}
     10      <a href="{$col.U_EDIT}" rel="nofollow">{$col.name}</a> <span class="menuInfoCat">[{$col.nb_images}]</span>
     11    {/if}</li>
    912                {/foreach}
     13    {if $block->data.MORE}<li class="menuInfoCat">{'%d more...'|@translate|sprintf:$block->data.MORE}</li>{/if}
    1014        {/strip}</ul>
    11 {/if}
    12   <p><a href="{$block->data.U_LIST}" rel="nofollow">{'See all my collections'|@translate}</a></p>
     15  {/if}
     16  <p><a href="{$block->data.U_CREATE}" rel="nofollow">{'Create a new collection'|@translate}</a></p>
    1317</dd>
  • extensions/UserCollections/template/thumbnails.tpl

    r16658 r16688  
    55  rel: ".preview-box",
    66  title: function() {ldelim}
    7     return $(this).attr("title") +' · <a href="'+ $(this).data('url') +'" target="_blank">{'jump to photo'|@translate} →</a>';
     7    var title = $(this).attr("title");
     8    {if $F_ACTION} title+= ' · <a href="{$collection_toggle_url}&amp;collection_toggle='+ $(this).data('id') +'" class="addCollection" data-id="'+ $(this).data('id') +'">{'Remove from collection'|@translate}</a>';{/if}
     9    title+= ' · <a href="'+ $(this).data('url') +'" target="_blank">{'jump to photo'|@translate} →</a>';
     10    return  title;
    811  }
     12});
     13jQuery(document).on("click", "#cboxTitle .addCollection", function() {ldelim}
     14  jQuery.colorbox.close();
     15  jQuery("#thumbnails a.addCollection[data-id='"+ $(this).data('id')+"']").trigger("click");
     16  return false;
    917});
    1018{/footer_script}
     
    4250        <span class="wrap1">
    4351                <span class="wrap2">
    44                 <a href="{$thumbnail.FILE_SRC}" class="preview-box" title="{$thumbnail.NAME}" data-url="{$thumbnail.URL}">
     52                <a href="{$thumbnail.FILE_SRC}" class="preview-box" title="{$thumbnail.NAME}" data-url="{$thumbnail.URL}" data-id="{$thumbnail.id}">
    4553                        <img class="thumbnail" {if $derivative->is_cached()}src="{$derivative->get_url()}"{else}src="{$ROOT_URL}{$themeconf.img_dir}/ajax-loader-small.gif" data-src="{$derivative->get_url()}"{/if} alt="{$thumbnail.TN_ALT}" title="{$thumbnail.TN_TITLE}">
    4654                </a>
  • extensions/UserCollections/template/thumbnails_css_js.tpl

    r16658 r16688  
    11{html_style}
    22.thumbnails .wrap1 {ldelim} position:relative !important; }
    3 .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; }
     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; }
    44.wrap1:hover .addCollection {ldelim} display:block; }
    55{/html_style}
  • extensions/UserCollections/template/view.tpl

    r16658 r16688  
    3232
    3333
    34 {if $U_LIST}<p style="text-align:center;font-weight:bold;margin:20px;"><a href="{$U_LIST}" rel="nofollow">{'Return to collections list'|@translate}</a></p>{/if}
    35 
    3634</div>{* <!-- content --> *}
Note: See TracChangeset for help on using the changeset viewer.