MyBB Community Forums

Full Version: MyBB Guest Home - Show homepage for guest
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Feature
  • Show Index Page for Guest

Description
This plugin will show an index page for guests only and you can freely edit the page in Global Templates >> index_guest.

[Image: o4sKpkF.png]
[Image: gp03DtF.png]

Download Link
https://community.mybb.com/mods.php?acti...w&pid=1434
Hi, thank you for your contribution.

However, please note that the following is wrong:
$gid = $mybb->user['gid'];

As the gid key doesn't exists, you should instead simply use the uid key:
if($mybb->settings['mybbguest_onoff'] == "1" && $mybb->user['uid'] <= "0")
(2021-02-09, 01:41 AM)Omar G. Wrote: [ -> ]Hi, thank you for your contribution.

However, please note that the following is wrong:
$gid = $mybb->user['gid'];

As the gid key doesn't exists, you should instead simply use the uid key:
if($mybb->settings['mybbguest_onoff'] == "1" && $mybb->user['uid'] <= "1")
 
Hi , and exactly where should this be inserted?

My forums usergroup = Guest  = gid=1

here is the full plugin.php cod


<?php

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.");
}

$plugins->add_hook("index_start", "mybbguest_page");

function mybbguest_info()
{
	$codename = str_replace('.php', '', basename(__FILE__));
	
	return array(
		"name"			=> "MyBB Guest Home",
		"description"	=> "Show homepage for guest.",
		"website"		=> "https://sinfulsite.com",
		"author"		=> "YASAKA",
		"authorsite"	=> "https://sinfulsite.com/@YASAKA",
		"version"		=> "1.0",
		"guid" 			=> "",
		"codename"		=> $codename,
		"compatibility" => "18*"
	);
}

function mybbguest_is_installed()
{
	global $mybb;

	if(isset($mybb->settings['mybbguest_onoff']))
	{
	    return true;
	}
	
	return false;
}

function mybbguest_install()
{
	mybbguest_install_settings();
	mybbguest_install_templates();
}

function mybbguest_uninstall()
{
	mybbguest_uninstall_settings();
	mybbguest_uninstall_templates();
}

function mybbguest_install_settings()
{
	global $db;

	$group = array(
        "name" => "mybbguest",
        "title" => "MyBB Guest Home",
        "description" => "Show homepage for guest.",
        "disporder" => 1,
        "isdefault" => 0
    );
    $gid = $db->insert_query("settinggroups", $group);

    $setting = array(
        "sid"            => NULL,
        "name"            => "mybbguest_onoff",
        "title"            => "MyBB Guest Home",
        "description"    => "Enable or disable this plugin.",
        "optionscode"    => "onoff",
        "value"            => "1",
        "disporder"        => 0,
        "gid"            => $gid
    );
    $db->insert_query("settings", $setting);

    rebuild_settings();
}

function mybbguest_uninstall_settings()
{
	global $db;

	$db->delete_query('settings', "name IN ('mybbguest_onoff')");
	$db->delete_query('settinggroups', "name = 'mybbguest'");

	rebuild_settings();
}

function mybbguest_install_templates()
{
	global $db;

	$template = '<html>
<head>
<title>{$mybb->settings[\'bbname\']}</title>
{$headerinclude}
</head>
<body>
{$header}
<div align="center" style="width: 50%; margin: auto;">
	<h1>Welcome to {$mybb->settings[\'bbname\']}</h1>
	<h2>Forum of Cracking</h2>
	<h4>Sinful Site is a forum based on general discussion and sharing of related resources. We encourage creativity, freedom, and above all, individuality. You can also find lots of leaks, tools, software, tutorials, and more. Learn many things here, new friends and have fun with our special features. We will not disappoint you!
If you want to contact us, you can use our contact form.</h4>
	<br>
	<a class="button" href="{$mybb->settings[\'bburl\']}/member.php?action=login" onclick="$(\'#quick_login\').modal({ fadeDuration: 250, keepelement: true, zIndex: (typeof modal_zindex !== \'undefined\' ? modal_zindex : 9999) }); return false;" style="margin-right:10px">Login</a>
	<a href="{$mybb->settings[\'bburl\']}/member.php?action=register" class="button">Register</a>
</div>
{$footer}
</body>
</html>';
	$insert_array = array(
	    'title' => 'index_guest',
	    'template' => $db->escape_string($template),
	    'sid' => '-1',
	    'version' => '',
	    'dateline' => time()
	);
	$db->insert_query('templates', $insert_array);
}

function mybbguest_uninstall_templates()
{
	global $db;

	$db->delete_query("templates", "title = 'index_guest'");
}

function mybbguest_page()
{
	global $mybb, $db, $templates, $lang, $header, $headerinclude, $footer, $theme;

	$uid = $mybb->user['uid'];

	if($mybb->settings['mybbguest_onoff'] == "1" && $uid <= "1")
	{
		eval('$index = "'.$templates->get('index_guest').'";');
		output_page($index);
		die();
	}
}
As Omar said to you Guests users does not have a valid user id, so it is better to use that besides groups.

User gid is not present if you declare to integer then you may see the values and put the same condition.

See yah !!!
(2021-02-09, 05:41 PM)Whiteneo Wrote: [ -> ]As Omar said to you Guests users does not have a valid user id, so it is better to use that besides groups.

User gid is not present if you declare to integer then you may see the values and put the same condition.

See yah !!!

Yes I tried it as @Omar wrote it, but it didn't work for me because everyone gets in the table that only Guest users should come in!

everyone saw it, not just the guests!

is there any solution why? or can the problem be solved?
If I'm not wrong guests have uid = 0 so you can check that:
if ($mybb->user['uid'] == 0) {
  // Show guest page
}
(2021-02-10, 10:10 AM)chack1172 Wrote: [ -> ]If I'm not wrong guests have uid = 0 so you can check that:
if ($mybb->user['uid'] == 0) {
  // Show guest page
}

Hi , 

I'm login Admin panels

cheak guest -- admin/index.php?module=user-groups&action=edit&gid=1
I know that, but I think the best way to check if they are really guests is to check the user id (uid field).
(2021-02-10, 10:18 AM)chack1172 Wrote: [ -> ]I know that, but I think the best way to check if they are really guests is to check the user id (uid field).


I understand, but then what's wrong with me, why it doesn't work the way it should, @Omar what I wrote I did, but not good unfortunately!

i can't find the uid anywhere, where can i find it at all?
Oh, I saw now the updated code. It is correct but instead of ['uid'] <= "1" the correct condition is ['uid'] < "1".
Pages: 1 2 3