'.l10n('Home').''.$conf['level_separator'].''.l10n('Collections').''; if (in_array(@$tokens[1], array('edit','view','list'))) { $page['sub_section'] = $tokens[1]; } else { $page['sub_section'] = 'list'; } if (!empty($tokens[2])) { $page['col_id'] = $tokens[2]; } } } /* collections section */ function user_collections_page() { global $page; if (isset($page['section']) and $page['section'] == 'collections') { include(USER_COLLEC_PATH . '/include/collections.inc.php'); } } /* add buttons on thumbnails list */ function user_collections_index_actions() { if (is_a_guest()) return; global $page, $UserCollection; // add image to collection list if ( isset($_GET['collection_toggle']) and preg_match('#^[0-9]+$#', $_GET['collection_toggle']) ) { if (empty($UserCollection)) { $UserCollection = new UserCollection(get_current_collection_id(true)); } $UserCollection->toggleImage($_GET['collection_toggle']); redirect(duplicate_index_url(array(), array('collection_toggle'))); } } function user_collections_thumbnails_list($tpl_thumbnails_var, $pictures) { if (is_a_guest()) return $tpl_thumbnails_var; global $page, $template, $UserCollection; // the prefilter is different on collection page if (isset($page['section']) and ($page['section'] == 'collections' or $page['section'] == 'download')) return $tpl_thumbnails_var; // get existing collections $col_id = get_current_collection_id(false); if (empty($UserCollection) and $col_id !== false) { $UserCollection = new UserCollection($col_id); $collection = $UserCollection->getImages(); } else if (!empty($UserCollection)) { $collection = $UserCollection->getImages(); } else { $collection = array(); } // if the collection is created we don't use AJAX to force menu refresh if ($col_id === false) { $template->assign('NO_AJAX', true); } $self_url = duplicate_index_url(array(), array('collection_toggle')); foreach ($tpl_thumbnails_var as &$thumbnail) { if (in_array($thumbnail['id'], $collection)) { $thumbnail['COLLECTION_SELECTED'] = true; } } unset($thumbnail); // thumbnails buttons $template->assign(array( 'USER_COLLEC_PATH' => USER_COLLEC_PATH, 'collection_toggle_url' => add_url_params($self_url, array('collection_toggle'=>'')), )); $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_prefilter'); return $tpl_thumbnails_var; } function user_collections_thumbnails_list_prefilter($content, &$smarty) { // add links $search = ''; $replace = $search.' {strip} {if $COL_ID or $thumbnail.COLLECTION_SELECTED} {\'Remove from collection\'|@translate}  {else} {\'Add to collection\'|@translate}  {/if} {/strip}'; // custom CSS and AJAX request $content.= file_get_contents(USER_COLLEC_PATH.'template/thumbnails_css_js.tpl'); return str_replace($search, $replace, $content); } /* add button on picture page */ function user_collections_picture_page() { if (is_a_guest()) return; global $template, $picture, $UserCollection; // add image to collection list if ( isset($_GET['action']) and $_GET['action'] == 'collection_toggle' ) { if (empty($UserCollection)) { $UserCollection = new UserCollection(get_current_collection_id(true)); } $UserCollection->toggleImage($picture['current']['id']); redirect(duplicate_picture_url()); } // get existing collection if (empty($UserCollection) and ($col_id = get_current_collection_id(false)) !== false) { $UserCollection = new UserCollection($col_id); $collection = $UserCollection->isInSet($picture['current']['id']); } else if (!empty($UserCollection)) { $collection = $UserCollection->isInSet($picture['current']['id']); } else { $collection = false; } $url = add_url_params(duplicate_picture_url(), array('action'=>'collection_toggle')); $button = ' '.($collection?l10n('Remove from collection'):l10n('Add to collection')).' '; // $template->add_picture_button($button, 50); $template->concat('PLUGIN_PICTURE_ACTIONS', $button); } /* menu block */ function user_collections_add_menublock($menu_ref_arr) { if (is_a_guest()) return; $menu = &$menu_ref_arr[0]; if ($menu->get_id() != 'menubar') return; $menu->register_block(new RegisteredBlock('mbUserCollection', l10n('Collections'), 'UserCollection')); } function user_collections_applymenu($menu_ref_arr) { $max = 6; global $template, $conf, $user, $UserCollection; $menu = &$menu_ref_arr[0]; if (($block = $menu->get_block('mbUserCollection')) != null) { $query = ' SELECT * FROM '.COLLECTIONS_TABLE.' WHERE user_id = '.$user['id'].' ORDER BY active DESC, date_creation DESC ;'; $collections = array_values(hash_from_query($query, 'id')); $data['collections'] = array(); for ($i=0; $i<$max && $i $max) { $data['MORE'] = count($collections)-$max; } $data['U_LIST'] = USER_COLLEC_PUBLIC; $data['U_CREATE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'new','col_id'=>'0','redirect'=>'true')); $template->set_template_dir(USER_COLLEC_PATH . 'template/'); $block->set_title(''.l10n('Collections').''); $block->template = 'menublock_user_collec.tpl'; $block->data = $data; } } ?>