Ejemplo n.º 1
0
/**
* Display categories
*
* @param int $parent_id The parent id/name (only show categories under this category)
* @param string $blockname The name of the template block to use (categories by default)
*/
function titania_display_categories($parent_id = 0, $blockname = 'categories', $is_manage = false)
{
    $only_visible = !$is_manage ? 'AND category_visible = 1' : '';
    $sql = 'SELECT * FROM ' . TITANIA_CATEGORIES_TABLE . '
		WHERE parent_id = ' . (int) $parent_id . "\n\t\t\t{$only_visible}\n\t\tORDER BY left_id ASC";
    $result = phpbb::$db->sql_query($sql);
    $category = new titania_category();
    while ($row = phpbb::$db->sql_fetchrow($result)) {
        $category->__set_array($row);
        phpbb::$template->assign_block_vars($blockname, $category->assign_display(true));
    }
    phpbb::$db->sql_freeresult($result);
    unset($category);
}
Ejemplo n.º 2
0
 /**
  * Set submitted settings on the category object.
  *
  * @param \titania_category $category	Category object.
  * @return \titania_category
  */
 protected function set_submitted_settings($category)
 {
     $category->__set_array(array('category_name' => $this->request->variable('category_name', '', true), 'category_name_clean' => $this->request->variable('category_name_clean', '', true), 'parent_id' => $this->request->variable('category_parent', 0), 'category_visible' => $this->request->variable('category_visible', 1), 'category_type' => $this->request->variable('category_type', 0), 'category_options' => 0));
     // Set category options
     foreach ($category->available_options as $option => $flag) {
         if ($this->request->variable($option, false)) {
             $category->set_option($option);
         }
     }
     return $category;
 }
Ejemplo n.º 3
0
 /**
  * Generate the category select (much is from the make_jumpbox function)
  *
  * @param array|bool $selected		Array of selected categories. Defaults to false.
  * @param bool $is_manage			Whether in category management, in which case all are listed
  * @param bool $disable_parents		Whether to disable categories that do not have a contribution type
  * @param bool|int $category_type	Category type to limit list to
  * @return void
  */
 public function generate_category_select($selected = false, $is_manage = false, $disable_parents = true, $category_type = false)
 {
     if (!is_array($selected)) {
         $selected = array($selected);
     }
     $right = $padding = 0;
     $padding_store = array('0' => 0);
     $categories = $this->cache->get_categories();
     $hidden_categories = array();
     $category = new \titania_category();
     foreach ($categories as $row) {
         $type = $this->types->get($row['category_type']);
         if ($type && (!$type->acl_get('submit') || $category_type && $type->id != $category_type)) {
             continue;
         }
         $category->__set_array($row);
         if ($row['left_id'] < $right) {
             $padding++;
             $padding_store[$row['parent_id']] = $padding;
         } else {
             if ($row['left_id'] > $right + 1) {
                 $padding = isset($padding_store[$row['parent_id']]) ? $padding_store[$row['parent_id']] : $padding;
             }
         }
         $right = $row['right_id'];
         if (!$is_manage) {
             // Non-postable category with no children, don't display
             $not_postable = $row['category_type'] == 0 && $row['left_id'] + 1 == $row['right_id'];
             $hidden = !$row['category_visible'] || in_array($row['parent_id'], $hidden_categories);
             $team_only_restriction = $category->is_option_set('team_only') && !$type->acl_get('moderate');
             if ($not_postable || $hidden || $team_only_restriction) {
                 if ($hidden) {
                     $hidden_categories[] = $row['category_id'];
                 }
                 continue;
             }
         }
         $this->template->assign_block_vars('category_select', array('S_SELECTED' => in_array($row['category_id'], $selected), 'S_DISABLED' => $row['category_type'] == 0 && $disable_parents, 'VALUE' => $row['category_id'], 'TYPE' => $row['category_type'], 'NAME' => $category->get_name()));
         for ($i = 0; $i < $padding; $i++) {
             $this->template->assign_block_vars('category_select.level', array());
         }
     }
 }
Ejemplo n.º 4
0
							SET right_id = right_id + 2
							WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id';
                        phpbb::$db->sql_query($sql);
                        $category_object->left_id = $row['right_id'];
                        $category_object->right_id = $row['right_id'] + 1;
                    } else {
                        $sql = 'SELECT MAX(right_id) AS right_id
							FROM ' . TITANIA_CATEGORIES_TABLE;
                        $result = phpbb::$db->sql_query($sql);
                        $row = phpbb::$db->sql_fetchrow($result);
                        phpbb::$db->sql_freeresult($result);
                        $category_object->left_id = $row['right_id'] + 1;
                        $category_object->right_id = $row['right_id'] + 2;
                    }
                } else {
                    $category_check = new titania_category();
                    $category_check->load($category_id);
                    if ($category_check->parent_id != $category_object->parent_id) {
                        if ($category_check->category_id != $category_object->parent_id) {
                            $errors_extra = $category_object->move_category($category_object->parent_id);
                            // Check for errors from moving the category
                            if (sizeof($errors_extra)) {
                                $error = array_merge($error, $errors_extra);
                            }
                        } else {
                            $category_object->parent_id = $category_check->parent_id;
                        }
                    }
                }
                // Only update category if no errors occurred from moving it
                if (!sizeof($error)) {
Ejemplo n.º 5
0
 /**
  * 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);
 }
Ejemplo n.º 6
0
    /**
     * Move category
     *
     * @param int $to_id			New parent id
     * @param sync|null $sync	If given sync class, category counts are resynchronized
     * @return array
     */
    function move_category($to_id, $sync)
    {
        $to_data = $moved_ids = $errors = array();
        if ($to_id > 0) {
            // Retrieve $to_data
            $to_data = new titania_category();
            $to_data->load($to_id);
        }
        // Make sure we're not moving this category under one if its own children
        if ($to_id > 0 && $to_data->left_id > $this->left_id && $to_data->right_id < $this->right_id) {
            $errors[] = phpbb::$user->lang['CATEGORY_CHILD_AS_PARENT'];
        } else {
            $moved_categories = $this->get_category_branch('children');
            $diff = sizeof($moved_categories) * 2;
            $moved_ids = array();
            for ($i = 0; $i < sizeof($moved_categories); ++$i) {
                $moved_ids[] = (int) $moved_categories[$i]['category_id'];
            }
            // Resync parents
            $sql = 'UPDATE ' . $this->sql_table . "\n\t\t\t\tSET right_id = right_id - {$diff}\n\t\t\t\tWHERE left_id < " . $this->right_id . "\n\t\t\t\t\tAND right_id > " . $this->right_id;
            phpbb::$db->sql_query($sql);
            // Resync righthand side of tree
            $sql = 'UPDATE ' . $this->sql_table . "\n\t\t\t\tSET left_id = left_id - {$diff}, right_id = right_id - {$diff}\n\t\t\t\tWHERE left_id > " . $this->right_id;
            phpbb::$db->sql_query($sql);
            if ($to_id > 0) {
                // Retrieve $to_data again, it may have been changed...
                unset($to_data);
                $to_data = new titania_category();
                $to_data->load($to_id);
                // Resync new parents
                $sql = 'UPDATE ' . $this->sql_table . "\n\t\t\t\t\tSET right_id = right_id + {$diff}\n\t\t\t\t\tWHERE " . $to_data->right_id . ' BETWEEN left_id AND right_id
						AND ' . phpbb::$db->sql_in_set('category_id', $moved_ids, true);
                phpbb::$db->sql_query($sql);
                // Resync the righthand side of the tree
                $sql = 'UPDATE ' . $this->sql_table . "\n\t\t\t\t\tSET left_id = left_id + {$diff}, right_id = right_id + {$diff}\n\t\t\t\t\tWHERE left_id > " . $to_data->right_id . '
						AND ' . phpbb::$db->sql_in_set('category_id', $moved_ids, true);
                phpbb::$db->sql_query($sql);
                // Resync moved branch
                $to_data->right_id += $diff;
                if ($to_data->right_id > $this->right_id) {
                    $diff = '+ ' . ($to_data->right_id - $this->right_id - 1);
                } else {
                    $diff = '- ' . abs($to_data->right_id - $this->right_id - 1);
                }
            } else {
                $sql = 'SELECT MAX(right_id) AS right_id
					FROM ' . $this->sql_table . '
					WHERE ' . phpbb::$db->sql_in_set('category_id', $moved_ids, true);
                $result = phpbb::$db->sql_query($sql);
                $row = phpbb::$db->sql_fetchrow($result);
                phpbb::$db->sql_freeresult($result);
                $diff = '+ ' . ($row['right_id'] - $this->left_id + 1);
            }
            $sql = 'UPDATE ' . $this->sql_table . "\n\t\t\t\tSET left_id = left_id {$diff}, right_id = right_id {$diff}\n\t\t\t\tWHERE " . phpbb::$db->sql_in_set('category_id', $moved_ids);
            phpbb::$db->sql_query($sql);
            if ($sync) {
                // Resync counters
                $sync->categories('count');
            }
        }
        return $errors;
    }
Ejemplo n.º 7
0
/**
* 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']));
    }
}
Ejemplo n.º 8
0
    /**
     * Set the relations between contribs and categories
     *
     * @param array $contrib_categories		Categories to put the contribution in
     * @param bool $protect_team_only		Whether to protect "Team only" categories.
     *	If true, existing categories that are "Team only" and are not part of $contrib_categories
     *	will be preserved.
     *
     * @return null
     */
    public function put_contrib_in_categories($contrib_categories = array(), $protect_team_only = true)
    {
        if (!$this->contrib_id) {
            return;
        }
        $protected_categories = array();
        $exclude_sql = '';
        if ($protect_team_only && !empty($this->category_data)) {
            $category = new \titania_category();
            foreach ($this->category_data as $row) {
                $category->__set_array($row);
                if ($category->is_option_set('team_only')) {
                    $protected_categories[] = (int) $category->category_id;
                }
            }
        }
        if (!empty($protected_categories)) {
            $exclude_sql = 'AND ' . phpbb::$db->sql_in_set('category_id', $protected_categories, true);
        }
        // Resync the count
        $this->update_category_count('-');
        // Remove them from the old categories
        $sql = 'DELETE
			FROM ' . TITANIA_CONTRIB_IN_CATEGORIES_TABLE . '
			WHERE contrib_id = ' . $this->contrib_id . "\n\t\t\t\t{$exclude_sql}";
        phpbb::$db->sql_query($sql);
        if (!sizeof($contrib_categories)) {
            return;
        }
        $sql_ary = array();
        foreach ($contrib_categories as $category_id) {
            $sql_ary[] = array('contrib_id' => $this->contrib_id, 'category_id' => $category_id);
        }
        phpbb::$db->sql_multi_insert(TITANIA_CONTRIB_IN_CATEGORIES_TABLE, $sql_ary);
        $this->contrib_categories = implode(',', array_merge($contrib_categories, $protected_categories));
        $this->fill_categories();
        // Resync the count
        $this->update_category_count();
    }
Ejemplo n.º 9
0
  */
 default:
     titania::_include('functions_display', 'titania_display_categories');
     // Get the category_id
     $category = request_var('c', '');
     $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)) {
Ejemplo n.º 10
0
 /**
  * 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()));
         }
     }
 }