Need some coding help. Yumi please help.
walkman Offline
Junior Member
**
Posts: 36
Joined: May 2010
Post: #1
Need some coding help. Yumi please help.
I am trying to create a mod that adds a few extra pages to my forum. After looking around I have found everything. The only thing I want to know is how to add the permissions for the user groups so they can see or not see my custom pages. I have found out how to do it by entering their number id but I want to add a yes/no option at their groups when they are being editing by going to Admin Panel->Groups->Edit Groups->Miscellaneous. And add my yes no option somewhere there.

After being helped by MattRogowski I got half way there. He was kind enough to create a plugin for me. This is the content of the plugin.

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
if(!defined("IN_MYBB"))
{
	die("This file cannot be accessed directly.");
}

$plugins->add_hook("admin_user_groups_edit", "custompages_perms_admin_user_groups_edit");
$plugins->add_hook("admin_user_groups_edit_commit", "custompages_perms_admin_user_groups_edit_commit");

function custompages_perms_info()
{
	return array(
		"name"		=> "Custom Pages Permissions",
		"description"	=> "Add permissions for custom pages.",
		"website"	=> "http://community.mybboard.net/user-13556.html",
		"author"	=> "MattRogowski",
		"authorsite"	=> "http://community.mybboard.net/user-13556.html",
		"version"	=> "1.0",
		"compatibility" => "14*,16*"
	);
}

function custompages_perms_activate()
{
	
}

function custompages_perms_deactivate()
{
	
}

function custompages_perms_admin_user_groups_edit()
{
	global $plugins;
	
	$plugins->add_hook("admin_formcontainer_end", "custompages_perms_admin_user_groups_edit_form");
}

function custompages_perms_admin_user_groups_edit_form()
{
	global $mybb, $lang, $form, $form_container;
	
	if($form_container->_title == $lang->misc)
	{
		$custom_pages_options = array(
			$form->generate_check_box("canviewpage_contact", 1, "Can view contact page??", array("checked" => $mybb->input['canviewpage_contact']))
		);
		$form_container->output_row("Custom Pages Permissions", "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $custom_pages_options)."</div>");
	}
}

function custompages_perms_admin_user_groups_edit_commit()
{
	global $mybb, $updated_group;
	
	$updated_group['canviewpage_contact'] = $mybb->input['canviewpage_contact'];
}
?>


If I upload it and activate it the option doesn't appear at the Misc area of the member groups when being edited. The member pavemen found out that if you remove this conditional

PHP Code:
if($form_container->_title == $lang->misc) 


The option appears but at every tab. Can someone please tell me how I can fix it. I habe trying for a long time and no luck. It is driving me crazy. I would appreciate all the help I can get.

06-01-2010 04:16 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: Need some coding help. Yumi please help.
I haven't tried it, but it looks like it should work on MyBB 1.4.  Can't say anything about 1.5/1.6 as they may make that variable private.

There's a number of alternatives:
  • If you don't need it right after everything else, you can hook admin_formcontainer_output_row instead.
  • You might want to consider adding a single checkbox to the Miscellaneous row instead of adding a completely new row (still hook admin_formcontainer_output_row).
  • Use a convoluted solution that I did for getting the XThreads options to appear where I want (I suggest against this though).

Also note that you'll probably also want to add the checkbox for the add group page as well.

Hope that helps.

EDIT: it seems it is private.  Oh well, this elaborate hack will get around it...

PHP Code:
1
2
3
4
5
6
7
if($mybb->version_code >= 1500) {
 $fc = (array)$forum_container;
 $fctitle = $fc["\0".get_class($forum_container)."\0".'_title'];
 unset($fc);
} else $fctitle = $forum_container->_title;

if($fctitle == $lang->misc) ...

Sorry have to go right now, so it may be wrong - just need to double check on that...


My Blog
(This post was last modified: 06-01-2010 12:18 PM by ZiNgA BuRgA.)
06-01-2010 12:07 PM
Find all posts by this user Quote this message in a reply
walkman Offline
Junior Member
**
Posts: 36
Joined: May 2010
Post: #3
RE: Need some coding help. Yumi please help.
(06-01-2010 12:07 PM)ZiNgA BuRgA Wrote:  I haven't tried it, but it looks like it should work on MyBB 1.4.  Can't say anything about 1.5/1.6 as they may make that variable private.

There's a number of alternatives:
  • If you don't need it right after everything else, you can hook admin_formcontainer_output_row instead.
  • You might want to consider adding a single checkbox to the Miscellaneous row instead of adding a completely new row (still hook admin_formcontainer_output_row).
  • Use a convoluted solution that I did for getting the XThreads options to appear where I want (I suggest against this though).

Also note that you'll probably also want to add the checkbox for the add group page as well.

Hope that helps.

EDIT: it seems it is private.  Oh well, this elaborate hack will get around it...

PHP Code:
1
2
3
4
5
6
7
if($mybb->version_code >= 1500) {
 $fc = (array)$forum_container;
 $fctitle = $fc["\0".get_class($forum_container)."\0".'_title'];
 unset($fc);
} else $fctitle = $forum_container->_title;

if($fctitle == $lang->misc) ...

Sorry have to go right now, so it may be wrong - just need to double check on that...


It didn''t work. Would be too much if I asked if you could put the whole plugin file together because maybe I am not doing it right?

Thank you very much for making time to help me. I really appreciate it sir Smile
06-02-2010 01:06 AM
Find all posts by this user Quote this message in a reply
Pirata Nervo Offline
Member
***
Posts: 235
Joined: Jan 2008
Post: #4
RE: Need some coding help. Yumi please help.
@Zinga is there any list of variables that became private in 1.6?
06-02-2010 03:36 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #5
RE: Need some coding help. Yumi please help.
(06-02-2010 01:06 AM)walkman Wrote:  Would be too much if I asked if you could put the whole plugin file together because maybe I am not doing it right?

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
if(!defined("IN_MYBB"))
{
	die("This file cannot be accessed directly.");
}

$plugins->add_hook("admin_user_groups_edit", "custompages_perms_admin_user_groups_edit");
$plugins->add_hook("admin_user_groups_edit_commit", "custompages_perms_admin_user_groups_edit_commit");

function custompages_perms_info()
{
	return array(
		"name"		=> "Custom Pages Permissions",
		"description"	=> "Add permissions for custom pages.",
		"website"	=> "http://community.mybboard.net/user-13556.html",
		"author"	=> "MattRogowski",
		"authorsite"	=> "http://community.mybboard.net/user-13556.html",
		"version"	=> "1.0",
		"compatibility" => "14*,16*"
	);
}

function custompages_perms_activate()
{
	
}

function custompages_perms_deactivate()
{
	
}

function custompages_perms_admin_user_groups_edit()
{
	global $plugins;
	
	$plugins->add_hook("admin_formcontainer_end", "custompages_perms_admin_user_groups_edit_form");
}

function custompages_perms_admin_user_groups_edit_form()
{
	global $mybb, $lang, $form, $form_container;
	
	
	if($mybb->version_code >= 1500) {
		$fc = (array)$form_container;
		$fctitle = $fc["\0DefaultFormContainer\0_title"];
		unset($fc);
	} else $fctitle = $form_container->_title;

	if($fctitle == $lang->misc)
	{
		$custom_pages_options = array(
			$form->generate_check_box("canviewpage_contact", 1, "Can view contact page??", array("checked" => $mybb->input['canviewpage_contact']))
		);
		$form_container->output_row("Custom Pages Permissions", "", "<div class=\"group_settings_bit\">".implode("</div><div class=\"group_settings_bit\">", $custom_pages_options)."</div>");
	}
}

function custompages_perms_admin_user_groups_edit_commit()
{
	global $mybb, $updated_group;
	
	$updated_group['canviewpage_contact'] = $mybb->input['canviewpage_contact'];
}
?>

Seems that PHP sticks the name from the originating class...

(06-02-2010 03:36 AM)Pirata Nervo Wrote:  @Zinga is there any list of variables that became private in 1.6?
Don't think so.
Best you can do is try diffing all the classes you use.

And of course, blame MyBB devs for being annoying (not that that'll actually get anywhere).

My Blog
(This post was last modified: 06-02-2010 11:53 AM by ZiNgA BuRgA.)
06-02-2010 11:52 AM
Find all posts by this user Quote this message in a reply
walkman Offline
Junior Member
**
Posts: 36
Joined: May 2010
Post: #6
RE: Need some coding help. Yumi please help.
You are genius sir. I don''t know how to thank you for your help with this as it was driving me crazy for days. Thank you very much sir. I really appreciate it. I hope that someday I can return the kindness Smile
06-03-2010 01:00 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: