Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Setting Categories as Frontpage

edited November 2006 in Vanilla 1.0 Help
Hello, I've been trying to do alot of tweeking to Vanilla recently, and one of the things I've been stuck on for awhile is making the "Categories" tab the default, since my forum has many different things all going on at once and it makes it look a bit like someone barfed something up when you look at the frontpage (it goes from stupidity like "count to infinity", to totally different things, like coding and such), so I recently read this discussion on setting the categories, but I've kind of attacked the original script there, so I was hoping maybe someone would be able to help me out with what I've done wrong..

The editted index.php looks like this:
<?php /* * Copyright 2003 - 2005 Mark O'Sullivan * This file is part of Vanilla. * Vanilla is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. * Vanilla is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * The latest source code for Vanilla is available at www.lussumo.com * Contact Mark O'Sullivan at mark [at] lussumo [dot] com * Description: Display and manipulate discussions */ // 1. DEFINE VARIABLES AND PROPERTIES SPECIFIC TO THIS PAGE $referer = $_SERVER['HTTP_REFERRER']; if (! strpos($referer, "http://www.infinite9.net\vitae\index.php")) { header("Location: categories.php"); } else { include("appg/settings.php"); $Configuration['SELF_URL'] = 'index.php'; include("appg/init_vanilla.php"); include("appg/settings.php"); include_once(sgLIBRARY."Vanilla.Discussion.class.php"); include_once(sgLIBRARY."Vanilla.Comment.class.php"); include_once(sgLIBRARY."Vanilla.Search.class.php"); include_once(sgLIBRARY."Utility.Pagelist.class.php"); include("appg/init_internal.php"); // 1. DEFINE VARIABLES AND PROPERTIES SPECIFIC TO THIS PAGE // Ensure the user is allowed to view this page $Context->Session->Check(agSAFE_REDIRECT); // Instantiate data managers to be used in this page $DiscussionManager = $Context->ObjectFactory->NewContextObject($Context, "DiscussionManager"); $SearchManager = $Context->ObjectFactory->NewContextObject($Context, "SearchManager"); // Define properties of the page controls that are specific to this page $Menu->CurrentTab = "discussions"; $Panel->CssClass = "DiscussionPanel"; $Body->CssClass = "Discussions"; // 2. BUILD PAGE CONTROLS // Panel AddDiscussionOptionsToPanel($Context, $Panel); AddBookmarksToPanel($Context, $Panel, $DiscussionManager); AddDiscussionsToPanel($Context, $Panel, $DiscussionManager, "GetDiscussionsByUserID", agPANEL_USERDISCUSSIONS_COUNT, $Context->GetDefinition("YourDiscussions"), "Recent", $Context->Session->User->Setting("ShowRecentDiscussions")); AddDiscussionsToPanel($Context, $Panel, $DiscussionManager, "GetViewedDiscussionsByUserID", agPANEL_HISTORY_COUNT, $Context->GetDefinition("History"), "History", $Context->Session->User->Setting("ShowBrowsingHistory")); AddSearchesToPanel($Context, $Panel, $SearchManager, agPANEL_SEARCH_COUNT); AddAppendixToPanel($Context, $Panel, "Discussion"); AddTextModeToPanel($Context, $Panel); AddGuestInfoToPanel($Context, $Panel); // Add the discussion grid to the body $CategoryID = ForceIncomingInt("CategoryID", 0); $View = ForceIncomingString("View", ""); $DiscussionGrid = $Context->ObjectFactory->NewContextObject($Context, "DiscussionGrid", $DiscussionManager, $CategoryID, $View); $Body->AddControl($DiscussionGrid); // 3. ADD CONTROLS TO THE PAGE $Page->AddControl("Head_Render", $Head); $Page->AddControl("Menu_Render", $Menu); $Page->AddControl("Panel_Render", $Panel); $Page->AddControl("Body_Render", $Body); // 4. FIRE PAGE EVENTS $Page->FireEvents(); } ?>

I'm very new to PHP (I'm only 15 and I've been learning since maybe December, but for a long time in between I'd lost my computer to a virus =(...) But I can't see anything wrong. As far as I interprete the code IF the page before was the index.php then it will redirect to the categories.php page. If not, then it will continue to load the recent discussions list. But instead, no matter what the last page the user loaded, it brings you back to categories.php

Any ideas on fixing this? Did I leave out anything that you might need to know? ^^;;
«1

Comments

  • edited August 2006
    I'm also relatively new to PHP, so I can't help you there unfortunately. The PHP page says this about HTTP_REFERER, "... Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted."
  • Hmm, well I wonder if I can sift through the PHP manual to find a different meathod of going about it... But the PHP manual is usually too difficult to understand -_-;; So still, if anyone else knows any ways to fix it, much thanks obliged!
  • The problem is that the index.php page is the same thing as the discussion list. Otherwise it would be easy. You only want the index.php page accessible through the category page, right? When you click on one of the categories, it appends "?CategoryID=#" to the url. You could check for that, and only redirect the users to categories.php if that is not there.
  • Heyyy... Sounds like an idea. Thing is is whether or not I can implement that I will try that though, before bashing my head repeatedly and giving up. ^^;;
  • ithcyithcy New
    edited August 2006
    how about this:

    go into conf/settings.php
    change this:
    $Configuration['FORWARD_VALIDATED_USER_URL'] = 'http://your.site/forum/';
    to this:
    $Configuration['FORWARD_VALIDATED_USER_URL'] = 'http://your.site/forum/categories.php';

    and add these two lines:
    $Configuration['TAB_POSITION_DISCUSSIONS'] = '20';
    $Configuration['TAB_POSITION_CATEGORIES'] = '10';

    then go into your .htaccess file in your forum root and add:
    DirectoryIndex categories.php

    //actually that won't quite work... "discussions" tab link would take you to categories. let me see
  • Yeah, I tried the .htaccess way, but that didn't work at all.. ^^;; So I've really tried everything I know how to do (which isn't much), and I'm at the end of my line and I'm going crazy. Ha ha, so much work just to change the silly default page.
  • also you need to change \ into / here: if (! strpos($referer, "http://www.infinite9.net\vitae\index.php")) {
  • http://lussumo.com/community/discussion/1658/have-the-categories-displayed-first-as-default/ http://lussumo.com/community/discussion/3100/setting-categories-as-the-default-page-for-vanilla/ http://lussumo.com/community/discussion/1334/set-categories-as-homepage-starting-point-frontpage-/ http://lussumo.com/community/discussion/2511/2-things-select-all-and-categories-as-home/ http://lussumo.com/community/discussion/655/howto-set-categories-tab-as-homepage/ http://lussumo.com/community/discussion/1896/user-list-and-default-to-categories/ http://lussumo.com/community/discussion/1236/select-discussions-categories-as-default-view/ http://lussumo.com/community/discussion/707/startup-to-categories/
  • MarkMark Vanilla Staff
    One thing I've done for clients in the past is I've created an extension that just does:

    if ($Context->SelfUrl == 'index.php' && ForceIncomingInt('CategoryID', 0) == 0) { header('location:categories.php'); }
  • edited August 2006
    Mark: that would remove the all discussions page entirely, though, right? EDIT: except for removing the tab.
  • Given this question comes up so incredibly often - would it be possible to make an add-on for this (which does not depend on htaccess)?
  • edited August 2006
    with Friendly urls on and "DirectoryIndex categories.php" in .htaccess, it is working.
    I don't see how you could do that in an addons.
  • The way Mark showed works just perfectly for me, and I'm not even very technical, just replace your index.php with this: <?php /* * Copyright 2003 - 2005 Mark O'Sullivan * This file is part of Vanilla. * Vanilla is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. * Vanilla is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * The latest source code for Vanilla is available at www.lussumo.com * Contact Mark O'Sullivan at mark [at] lussumo [dot] com * Description: Display and manipulate discussions */ // 1. DEFINE VARIABLES AND PROPERTIES SPECIFIC TO THIS PAGE $referer = $_SERVER['HTTP_REFERRER']; if ($Context->SelfUrl == 'index.php' && ForceIncomingInt('CategoryID', 0) == 0) { header('location:categories.php'); } else { include("appg/settings.php"); $Configuration['SELF_URL'] = 'index.php'; include("appg/init_vanilla.php"); // 1. DEFINE VARIABLES AND PROPERTIES SPECIFIC TO THIS PAGE // Ensure the user is allowed to view this page $Context->Session->Check($Context); // Define properties of the page controls that are specific to this page $Head->BodyId = 'DiscussionsPage'; $Menu->CurrentTab = 'discussions'; $Panel->CssClass = 'DiscussionPanel'; $Panel->BodyCssClass = 'Discussions'; // 2. BUILD PAGE CONTROLS $DiscussionGrid = $Context->ObjectFactory->CreateControl($Context, 'DiscussionGrid'); // Add an update reminder if necessary if ($Configuration['UPDATE_REMINDER'] != '') { if ($Context->Session->User && $Context->Session->User->Permission('PERMISSION_CHECK_FOR_UPDATES')) { $ShowUpdateMessage = 0; $LastUpdate = $Configuration['LAST_UPDATE']; if ($LastUpdate == '') $LastUpdate = time(); $Difference = time() - $LastUpdate; $Days = floor($Difference/60/60/24); if ($Configuration['LAST_UPDATE'] == '') { $ShowUpdateMessage = 1; } elseif ($Configuration['UPDATE_REMINDER'] == 'Weekly') { if ($Days > 7) $ShowUpdateMessage = 1; } elseif ($Configuration['UPDATE_REMINDER'] == 'Monthly') { if ($Days > 30) $ShowUpdateMessage = 1; } elseif ($Configuration['UPDATE_REMINDER'] == 'Quarterly') { if ($Days > 90) $ShowUpdateMessage = 1; } if ($ShowUpdateMessage) { $Message = ''; if ($Days == 0) { $Message = $Context->GetDefinition('NeverCheckedForUpdates'); } else { $Message = str_replace('//1', $Days, $Context->GetDefinition('XDaysSinceUpdateCheck')); } $NoticeCollector->AddNotice($Message.' <a href="'.GetUrl($Configuration, 'settings.php', '', '', '', '', 'PostBackAction=UpdateCheck').'">'.$Context->GetDefinition('CheckForUpdatesNow').'</a>'); } } } // Remind them to get addons if this is a new install if ($Configuration['ADDON_NOTICE']) { if ($Context->Session->User && $Context->Session->User->Permission('PERMISSION_MANAGE_EXTENSIONS')) { $HideNotice = ForceIncomingBool('TurnOffAddonNotice', 0); if ($HideNotice) { $SettingsFile = $Configuration['APPLICATION_PATH'].'conf/settings.php'; $SettingsManager = $Context->ObjectFactory->NewContextObject($Context, 'ConfigurationManager'); $SettingsManager->DefineSetting("ADDON_NOTICE", '0', 1); $SettingsManager->SaveSettingsToFile($SettingsFile); } else { $NoticeCollector->AddNotice('<span><a href="'.GetUrl($Configuration, 'index.php', '', '', '', '', 'TurnOffAddonNotice=1').'">'.$Context->GetDefinition('RemoveThisNotice').'</a></span> '.$Context->GetDefinition('WelcomeToVanillaGetSomeAddons')); } } } // 3. ADD CONTROLS TO THE PAGE $Page->AddRenderControl($Head, $Configuration['CONTROL_POSITION_HEAD']); $Page->AddRenderControl($Menu, $Configuration['CONTROL_POSITION_MENU']); $Page->AddRenderControl($Panel, $Configuration['CONTROL_POSITION_PANEL']); $Page->AddRenderControl($NoticeCollector, $Configuration['CONTROL_POSITION_NOTICES']); $Page->AddRenderControl($DiscussionGrid, $Configuration['CONTROL_POSITION_BODY_ITEM']); $Page->AddRenderControl($Foot, $Configuration['CONTROL_POSITION_FOOT']); $Page->AddRenderControl($PageEnd, $Configuration['CONTROL_POSITION_PAGE_END']); // 4. FIRE PAGE EVENTS $Page->FireEvents(); } ?> And it will work puuurfectly ;)
  • Right - so it can be done without htaccess. Now, can it be made an add-on?
  • mm that index.php thing dont work for me :(
  • Now, can it be made an add-on?
    — Thomas Heath
    Of course. As Mark said: "...created an extension that just does...."
  • MarkMark Vanilla Staff
    First of all, don't make any changes to your index.php file. All of this can be done in an extension. If you change the index.php file, your changes will be overwritten when you upgrade.

    The theory behind my code up there is that if they don't click on a category name to get to the discussions in that category, they will be sent to the category page. In other words, you can't ever see all of the discussions at once.

    Yes, this can be done as an extension, like this:

    <?php /* Extension Name: Category Page First Extension Url: http://lussumo.com/docs/ Description: Makes the category page the default page. Version: 1.0 Author: Mark O'Sullivan Author Url: http://www.markosullivan.ca/ */ // Make the category tab come first. $Configuration['TAB_POSITION_CATEGORIES'] = '10'; $Configuration['TAB_POSITION_DISCUSSIONS'] = '20'; // If looking at the discussions without a category specified, send them to the category page. if ($Context->SelfUrl == 'index.php' && ForceIncomingInt('CategoryID', 0) == 0) { header('location:categories.php'); } ?>
  • edited August 2006
    when we make this as an extension do we copy the code save it as categorypagefirst.php and save it to extension dir ? i don't see it in my ext list update: ok i know what happen, the code you show above is not complete so I just copied and pasted but your code is missing the first part include("appg/settings.php"); $Configuration['SELF_URL'] = 'index.php'; include("appg/init_vanill now it works :-)
  • Make a folder called eg CategoryPageFirst and save that code into a file named default.php inside that new dir.
  • This does work but seems to interfere with a few other extensions. You loose the "announcement". Pages that you created now go to the Categories, even after re-syncing. Any ideas how to resolve this?
This discussion has been closed.