MyBB Community Forums
[Tutorial] Making the 'Rules' page to show with rules. - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Resources (https://community.mybb.com/forum-8.html)
+--- Forum: Tutorials (https://community.mybb.com/forum-38.html)
+--- Thread: [Tutorial] Making the 'Rules' page to show with rules. (/thread-57141.html)

Pages: 1 2


[Tutorial] Making the 'Rules' page to show with rules. - Joshee - 2009-09-26

If you go to http://yourforum.com/misc.php?action=rules, you will see a blank page. This tutorial will show you how to make that page show along with rules that you can edit via the the Configuration tab in you Admin CP.

Difficulty: 6/10
Est. time: About 5 minutes if you do it right.

Ok, first thing you have to do is open up your misc.php file.
Find:
elseif($mybb->input['action'] == "rules")
{
	if($mybb->input['fid'])
	{
		$plugins->run_hooks("misc_rules_start");

		$query = $db->simple_select("forums", "*", "fid='".intval($mybb->input['fid'])."' AND active!=0");
		$forum = $db->fetch_array($query);

		$forumpermissions = forum_permissions($forum['fid']);

		if($forum['type'] != "f" || $forum['rules'] == '')
		{
			error($lang->error_invalidforum);
		}
		if($forumpermissions['canview'] != 1)
		{
			error_no_permission();
		}
		if(!$forum['rulestitle'])
		{
			$forum['rulestitle'] = $lang->sprintf($lang->forum_rules, $forum['name']);
		}

		require_once MYBB_ROOT."inc/class_parser.php";
		$parser = new postParser();
		$parser_options = array(
			"allow_html" => 1,
			"allow_mycode" => 1,
			"allow_smilies" => 1,
			"allow_imgcode" => 1,
			"filter_badwords" => 1
		);

		$forum['rules'] = $parser->parse_message($forum['rules'], $parser_options);

		// Make navigation
		build_forum_breadcrumb($mybb->input['fid']);
		add_breadcrumb($forum['rulestitle']);

		$plugins->run_hooks("misc_rules_end");

		eval("\$rules = \"".$templates->get("misc_rules_forum")."\";");
		output_page($rules);
	}

}
(Hopefully thats what it looks like.)

Replace with:
elseif($mybb->input['action'] == "rules")
{
    if($mybb->input['fid'])
    {
        $plugins->run_hooks("misc_rules_start");

        $query = $db->simple_select("forums", "*", "fid='".intval($mybb->input['fid'])."' AND active!=0");
        $forum = $db->fetch_array($query);

        $forumpermissions = forum_permissions($forum['fid']);

        if($forum['type'] != "f" || $forum['rules'] == '')
        {
            error($lang->error_invalidforum);
        }
        if($forumpermissions['canview'] != 1)
        {
            error_no_permission();
        }
        if(!$forum['rulestitle'])
        {
            $forum['rulestitle'] = $lang->sprintf($lang->forum_rules, $forum['name']);
        }

        require_once MYBB_ROOT."inc/class_parser.php";
        $parser = new postParser();
        $parser_options = array(
            "allow_html" => 1,
            "allow_mycode" => 1,
            "allow_smilies" => 1,
            "allow_imgcode" => 1,
            "filter_badwords" => 1
        );

        $forum['rules'] = $parser->parse_message($forum['rules'], $parser_options);

        // Make navigation
        build_forum_breadcrumb($mybb->input['fid']);
        add_breadcrumb($forum['rulestitle']);

        $plugins->run_hooks("misc_rules_end");

        eval("\$rules = \"".$templates->get("misc_rules_forum")."\";");
        output_page($rules);
    }
    else
    {
        add_breadcrumb("Rules Page", "misc.php?action=rules");
        eval("\$rules = \"".$templates->get("misc_rules")."\";");
        output_page($rules);
    }

}

And save the file.

Now when you go to http://yourforum.com/misc.php?action=rules, you should still see a blank page.

Go into your Admin CP, go to the Templates & Style tab, on the left, click Templates, click the theme you are using to open up the templates for that theme, and click Add Template.

Make the name of the template 'misc_rules', and make the content this:
<html>
<head>
<title>{$mybb->settings['bbname']} - {$mybb->settings['rules_title']}</title>
{$headerinclude}
</head>
<body>
{$header}
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder">
<tr>
<td class="thead" colspan="{$colspan}"><strong>{$mybb->settings['rules_title']}</strong></td>
</tr>
<tr>
<td class="trow1">{$mybb->settings['rules_content']}</td>
</tr>
</table>
{$footer}
</body>
</html>

Now if you refresh your Rules page, you should at lease see a page in your site with an empty box.

Go into you Admin CP, go to the Configuration tab, and click Add New Setting.

Make the settings:
Title: Rules Title
Description: This is what the title of the page will be, as well as the title of the rules box.
Group: General Configuration
Display Order: 7
Identifier: rules_title (Must be exactly that for this to work)
Type: Text
Value: Rules
And click Insert New Setting.

Now, click Add New Setting again, and make the settings:
Title: Rules Content
Description: This is what the content of the rules page will be.
Group: General Configuration
Display Order: 8
Identifier: rules_content (Must be exactly that for this to work)
Type: Textarea
Value: The administrator has not set any rules...
And click Insert New Setting.

Thats it! Now when you refresh your rules page, you should see a box that says 'The administrator has not set any rules...'!
To change this, go to your Admin CP, go to the Configuration tab, and go to General Configuration. Scroll down until you see Rules Title and Rules Content, and edit those fields to fit your needs Smile

I hope this tutorial helped, if you have any problems feel free to post here!


RE: [Tutorial] Making the 'Rules' page to show with rules. - Matt - 2009-09-26

Um, I wouldn't suggest doing this as it currently is. What if people currently use this rules page?? You're removing current functionality, and removing a plugin hook, what it people use it??

What you should do is this... because of...

if($mybb->input['fid'])

... it executes that big block of code you're saying to remove, if there's an fid... what you should do, is after it says...

output_page($rules);
    }

... in the first code block, add...

   else
    {
        //code
    }

... where //code is the code you added into the elseif statement. Then, create a custom template, and change the eval code to eval that new template instead. Basically change the first bit of code you posted to this:

elseif($mybb->input['action'] == "rules")
{
	if($mybb->input['fid'])
	{
		$plugins->run_hooks("misc_rules_start");

		$query = $db->simple_select("forums", "*", "fid='".intval($mybb->input['fid'])."' AND active!=0");
		$forum = $db->fetch_array($query);

		$forumpermissions = forum_permissions($forum['fid']);

		if($forum['type'] != "f" || $forum['rules'] == '')
		{
			error($lang->error_invalidforum);
		}
		if($forumpermissions['canview'] != 1)
		{
			error_no_permission();
		}
		if(!$forum['rulestitle'])
		{
			$forum['rulestitle'] = $lang->sprintf($lang->forum_rules, $forum['name']);
		}

		require_once MYBB_ROOT."inc/class_parser.php";
		$parser = new postParser();
		$parser_options = array(
			"allow_html" => 1,
			"allow_mycode" => 1,
			"allow_smilies" => 1,
			"allow_imgcode" => 1,
			"filter_badwords" => 1
		);

		$forum['rules'] = $parser->parse_message($forum['rules'], $parser_options);

		// Make navigation
		build_forum_breadcrumb($mybb->input['fid']);
		add_breadcrumb($forum['rulestitle']);

		$plugins->run_hooks("misc_rules_end");

		eval("\$rules = \"".$templates->get("misc_rules_forum")."\";");
		output_page($rules);
	}
	else
	{
		add_breadcrumb("Rules Page", "misc.php?action=rules");
		eval("\$rules = \"".$templates->get("TEMPLATE")."\";");
		output_page($rules);
	}

}

Change TEMPLATE to the name of the template you create. Then, if there's an fid, it'll work as normal, and if there isn't, it'll show the new page you're adding.

And sorry, I opened quick edit to copy your code whilst I had my quick edit open too, and I clicked save on yours by accident so it says I've edited yours, I didn't change anything, sorry!!


RE: [Tutorial] Making the 'Rules' page to show with rules. - Joshee - 2009-09-26

Ah I see... Well thanks for telling me all that! Should I just change the code I said to the one you posted?
I dont know anything about PHP, I just messed around with something I thought would work and it did Toungue
In the next MyBB version the rules page should be a feature, because even though there is coding in the misc.php file, the rules page just shows up blank.


RE: [Tutorial] Making the 'Rules' page to show with rules. - Matt - 2009-09-26

Sure, you can change it to mine... your code worked fine for what you intended it to do though, just removed some other stuff with it, and yeah, probably wouldn't be too hard to implement it for a future release, just making an edit where I made, probably with some more fancy code though Toungue


RE: [Tutorial] Making the 'Rules' page to show with rules. - Joshee - 2009-09-26

So what exactly did your code change? Did I remove something important when I changed the code?


RE: [Tutorial] Making the 'Rules' page to show with rules. - Matt - 2009-09-26

Well, you said to remove a chunk of default code, which deals with the default functionality, normally, if you go to ./misc.php?action=rules&fid=81 then it would run the code you said to remove and show rules for that forum.

At the start it has elseif($mybb->input['action'] == "rules") for if you're loading ./misc.php?action=rules, and then, there's the if($mybb->input['fid']) bit, so if there's an fid, it runs the default code. However, if there wasn't an fid, it'd do nothing, hence the blank page. So, with my change, if the ($mybb->input['fid']) wasn't true, i.e. there wasn't an fid, the 'else' bit will show the bit you initially said to put in, the general rules.

Don't think I've explained that very well... this is what it would have been before:

if($page = rules)
{
	if($fid)
	{
		//code for the rules for requested forum
	}
}

Shows rules for the forum if there's an fid, nothing if there isn't one. You then said to just do this:

if($page = rules)
{
	//code to show general rules
}

That would mean if there was no fid it would show the general rules, but wouldn't show the rules from a forum if you gave an fid. I said to do:

if($page = rules)
{
	if($fid)
	{
		//code for the rules for requested forum
	}
	else
	{
		//code to show general rules
	}
}

Then, if there's an fid, it shows rules for that forum, if there isn't an fid, it shows the general rules.


RE: [Tutorial] Making the 'Rules' page to show with rules. - Joshee - 2009-09-26

Ah that makes sense. Thanks for explaining! I edited the tutorial with your code and made some other modifications to it because of your code. Thanks Matt Big Grin


RE: [Tutorial] Making the 'Rules' page to show with rules. - labrocca - 2009-09-26

I am going to campaign that people start using the Help Documents more often that's built into MyBB. There is no reason why you can't use it for a Rules section.

It's built in. It works well. It requires no modifications. You can just as easily link this:

http://community.mybboard.net/misc.php?action=help&hid=5

As you can this:

http://community.mybboard.net/misc.php?action=rules

Heck if you want use an htaccess rewrite so it comes off as this:
http://community.mybboard.net/rules

Don't reinvent the wheel.


RE: [Tutorial] Making the 'Rules' page to show with rules. - Joshee - 2009-09-27

The main idea of this tutorial was just to get the rules page to show up. It was not supposed to be a replacement to something like that.
That help document just tells you how to post a topic, not the rules for posting a topic. This rules page allows admins to set rules for the entire forum to use, and if they need to make rules for a specific forum, they can use the built in rules system for certain forums.


RE: [Tutorial] Making the 'Rules' page to show with rules. - labrocca - 2009-09-27

Quote:That help document just tells you how to post a topic, not the rules for posting a topic.

Have you ever taken the time to view the admincp Help Documents section? Try it before you speak on the subject please. You can add whatever "documents" you want in the admincp including sections and categories. Essentially the exact same thing your modification does except without modification. As a matter of fact it's better since you can create sections and you don't need to make a template. The Help Documents are also html compatible.

Maybe an example will wake you up.

http://www.mybbcentral.com/misc.php?action=help

I just quickly added a new section and two new documents. Rules and the Privacy Policy. These took me about 5 minutes.

If I wanted a RULES link in header I just point it to this:
http://www.mybbcentral.com/misc.php?action=help&hid=12