/** * Display categories * * @param int $parent_id The parent id (only show categories under this category) * @param string $blockname The name of the template block to use (categories by default) * @param bool $is_manage Whether the categories are being displayed in management page. Defaults to false. * @param bool $display_full_tree Whether to display the full category tree. */ public function display_categories($parent_id = 0, $blockname = 'categories', $is_manage = false, $display_full_tree = false, array $params = array()) { $categories = $this->cache->get_categories(); $category = new \titania_category(); $active_parents = array(); if ($parent_id) { $active_parents = $this->cache->get_category_parents($parent_id); $active_parents = $active_parents ? array_keys($active_parents) : array(); $active_parents[] = $parent_id; } foreach ($categories as $data) { $category->__set_array($data); $ignore = !$is_manage && !$category->category_visible || !$display_full_tree && $parent_id != $category->parent_id; if ($ignore) { continue; } $active = in_array($category->category_id, $active_parents) || in_array($category->parent_id, $active_parents); $this->template->assign_block_vars($blockname, array_merge($category->assign_display(true), array('ACTIVE' => $active, 'U_VIEW_CATEGORY' => $category->get_url($params)))); } }
/** * Get category/index URL. * * @param array $params * @return string */ protected function get_item_url(array $params) { return $this->id ? $this->category->get_url($params) : $this->get_index_url($params); }
$category_ary = explode('-', $category); if ($category_ary) { $category_id = array_pop($category_ary); } else { $category_id = (int) $category; } titania_display_categories($category_id); $categories_ary = false; if ($category_id != 0) { // Breadcrumbs $category_object = new titania_category(); $categories_ary = titania::$cache->get_categories(); // Parents foreach (array_reverse(titania::$cache->get_category_parents($category_id)) as $row) { $category_object->__set_array($categories_ary[$row['category_id']]); titania::generate_breadcrumbs(array(isset(phpbb::$user->lang[$categories_ary[$row['category_id']]['category_name']]) ? phpbb::$user->lang[$categories_ary[$row['category_id']]['category_name']] : $categories_ary[$row['category_id']]['category_name'] => titania_url::build_url($category_object->get_url()))); } // Self $category_object->__set_array($categories_ary[$category_id]); titania::generate_breadcrumbs(array(isset(phpbb::$user->lang[$categories_ary[$category_id]['category_name']]) ? phpbb::$user->lang[$categories_ary[$category_id]['category_name']] : $categories_ary[$category_id]['category_name'] => titania_url::build_url($category_object->get_url()))); // Get the child categories we want to select the contributions from $child_categories = array_keys(titania::$cache->get_category_children($category_id)); phpbb::$template->assign_vars(array('CATEGORY_ID' => $category_id, 'S_DISPLAY_SEARCHBOX' => true, 'S_SEARCHBOX_ACTION' => titania_url::build_url('find-contribution'))); $sort = false; // If there are categories we are listing as well, only show 10 by default if (sizeof($child_categories)) { // Setup the sort tool to only display the 10 most recent $sort = contribs_overlord::build_sort(); $sort->set_defaults(10); } // Include the current category in the ones selected
/** * Load contribution * * Call this AFTER you have loaded the main object (like the FAQ item if requested for example) * * @param mixed $contrib contrib_id (always send if you have loaded an item for this contrib!) */ function load_contrib($contrib_id = false) { $contrib = request_var('id', 0) ? request_var('id', 0) : utf8_normalize_nfc(request_var('c', '', true)); $type = request_var('type', ''); // Load the contribution titania::$contrib = new titania_contribution(); if (!titania::$contrib->load($contrib)) { trigger_error('CONTRIB_NOT_FOUND'); } // Make sure the contrib requested is the same as the contrib loaded if ($contrib_id !== false && $contrib_id != titania::$contrib->contrib_id || $type != titania_types::$types[titania::$contrib->contrib_type]->url) { // Mismatch, redirect redirect(titania::$contrib->get_url(basename(request_var('page', 'details')))); } // Put the author in titania::$author titania::$author = titania::$contrib->author; // Check to see if the currently accessing user is an author if (titania::$access_level == TITANIA_ACCESS_PUBLIC && phpbb::$user->data['is_registered'] && !phpbb::$user->data['is_bot']) { if (titania::$contrib->is_author || titania::$contrib->is_active_coauthor) { titania::$access_level = TITANIA_ACCESS_AUTHORS; } } // Count the number of FAQ items to display $flags = titania_count::get_flags(titania::$access_level); $faq_count = titania_count::from_db(titania::$contrib->contrib_faq_count, $flags); /** * Menu Array * * 'filename' => array( * 'title' => 'nav menu title', * 'url' => $page_url, * 'auth' => ($can_see_page) ? true : false, // Not required, always true if missing * ), */ $nav_ary = array('details' => array('title' => 'CONTRIB_DETAILS', 'url' => titania::$contrib->get_url()), 'faq' => array('title' => 'CONTRIB_FAQ', 'url' => titania::$contrib->get_url('faq'), 'auth' => titania::$access_level != TITANIA_ACCESS_PUBLIC || $faq_count ? true : false, 'count' => $faq_count), 'support' => array('title' => 'CONTRIB_SUPPORT', 'url' => titania::$contrib->get_url('support'), 'auth' => titania::$config->support_in_titania || titania::$access_level < TITANIA_ACCESS_PUBLIC ? true : false), 'manage' => array('title' => 'CONTRIB_MANAGE', 'url' => titania::$contrib->get_url('manage'), 'auth' => (titania::$contrib->is_author || titania::$contrib->is_active_coauthor) && phpbb::$auth->acl_get('u_titania_post_edit_own') && !in_array(titania::$contrib->contrib_status, array(TITANIA_CONTRIB_CLEANED, TITANIA_CONTRIB_DISABLED)) || phpbb::$auth->acl_get('u_titania_mod_contrib_mod') || titania_types::$types[titania::$contrib->contrib_type]->acl_get('moderate'))); // Display nav menu $page = request_var('page', ''); titania::generate_nav($nav_ary, $page, 'details'); // Search for a category with the same name as the contrib type. This is a bit ugly, but there really isn't any better option $categories_ary = titania::$cache->get_categories(); foreach ($categories_ary as $category_id => $category_row) { $category_row['category_name'] = isset(phpbb::$user->lang[$category_row['category_name']]) ? phpbb::$user->lang[$category_row['category_name']] : $category_row['category_name']; if ($category_row['category_name'] == titania_types::$types[titania::$contrib->contrib_type]->lang || $category_row['category_name'] == titania_types::$types[titania::$contrib->contrib_type]->langs) { $category_object = new titania_category(); $category_object->__set_array($categories_ary[$category_id]); // Generate the main breadcrumbs titania::generate_breadcrumbs(array($category_object->category_name => titania_url::build_url($category_object->get_url()))); break; } } titania::generate_breadcrumbs(array(titania::$contrib->contrib_name => titania::$contrib->get_url())); if ($page) { titania::generate_breadcrumbs(array($nav_ary[$page]['title'] => $nav_ary[$page]['url'])); } }
/** * Assign breadcrumbs to template. * * @return null */ protected function generate_breadcrumbs() { // Search for a category with the same name as the contrib type. This is a bit ugly, but there really isn't any better option $categories = $this->cache->get_categories(); $category = new \titania_category(); foreach ($categories as $category_id => $category_row) { $category->__set_array($category_row); $name = $category->get_name(); if ($name == $this->contrib->type->lang || $name == $this->contrib->type->langs) { // Generate the main breadcrumbs $this->display->generate_breadcrumbs(array($name => $category->get_url())); } } }