/** * Returns template vars for main categories menu. * * @return array[] */ function get_categories_menu() { global $page, $user, $filter, $conf; $query = ' SELECT '; // From CATEGORIES_TABLE $query .= ' id, name, permalink, nb_images, global_rank,'; // From USER_CACHE_CATEGORIES_TABLE $query .= ' date_last, max_date_last, count_images, count_categories'; // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE $query .= ' FROM ' . CATEGORIES_TABLE . ' INNER JOIN ' . USER_CACHE_CATEGORIES_TABLE . ' ON id = cat_id and user_id = ' . $user['id']; // Always expand when filter is activated if (!$user['expand'] and !$filter['enabled']) { $where = ' (id_uppercat is NULL'; if (isset($page['category'])) { $where .= ' OR id_uppercat IN (' . $page['category']['uppercats'] . ')'; } $where .= ')'; } else { $where = ' ' . get_sql_condition_FandF(array('visible_categories' => 'id'), null, true); } $where = trigger_change('get_categories_menu_sql_where', $where, $user['expand'], $filter['enabled']); $query .= ' WHERE ' . $where . ' ;'; $result = pwg_query($query); $cats = array(); $selected_category = isset($page['category']) ? $page['category'] : null; while ($row = pwg_db_fetch_assoc($result)) { $child_date_last = @$row['max_date_last'] > @$row['date_last']; $row = array_merge($row, array('NAME' => trigger_change('render_category_name', $row['name'], 'get_categories_menu'), 'TITLE' => get_display_images_count($row['nb_images'], $row['count_images'], $row['count_categories'], false, ' / '), 'URL' => make_index_url(array('category' => $row)), 'LEVEL' => substr_count($row['global_rank'], '.') + 1, 'SELECTED' => $selected_category['id'] == $row['id'] ? true : false, 'IS_UPPERCAT' => $selected_category['id_uppercat'] == $row['id'] ? true : false)); if ($conf['index_new_icon']) { $row['icon_ts'] = get_icon($row['max_date_last'], $child_date_last); } $cats[] = $row; if ($row['id'] == @$page['category']['id']) { //save the number of subcats for later optim $page['category']['count_categories'] = $row['count_categories']; } } usort($cats, 'global_rank_compare'); // Update filtered data if (function_exists('update_cats_with_filtered_data')) { update_cats_with_filtered_data($cats); } return $cats; }
foreach ($infos_of_image as &$info) { $info['src_image'] = new SrcImage($info); } unset($info); } if (count($user_representative_updates_for)) { $updates = array(); foreach ($user_representative_updates_for as $cat_id => $image_id) { $updates[] = array('user_id' => $user['id'], 'cat_id' => $cat_id, 'user_representative_picture_id' => $image_id); } mass_updates(USER_CACHE_CATEGORIES_TABLE, array('primary' => array('user_id', 'cat_id'), 'update' => array('user_representative_picture_id')), $updates); } if (count($categories) > 0) { // Update filtered data if (function_exists('update_cats_with_filtered_data')) { update_cats_with_filtered_data($categories); } $template->set_filename('index_category_thumbnails', 'mainpage_categories.tpl'); trigger_notify('loc_begin_index_category_thumbnails', $categories); $tpl_thumbnails_var = array(); foreach ($categories as $category) { if (0 == $category['count_images']) { continue; } $category['name'] = trigger_change('render_category_name', $category['name'], 'subcatify_category_name'); if ($page['section'] == 'recent_cats') { $name = get_cat_display_name_cache($category['uppercats'], null); } else { $name = $category['name']; } $representative_infos = $infos_of_image[$category['representative_picture_id']];