MyBB Community Forums

Full Version: Quick Access links.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey,

I tried making a plugin to add 2 Quick Access links and grab the name and link from 4 settings, i got the settings and the area where they should appear to actually appear in the ACP, But I'm unable to use the plugin methods to grab what the user put for the setting, Right now i have

function cpanelandwhm_acp_menu(&$sub_menu)
{
           // Not $lang and $page
	global $mybb

	// Sub menu item
	$sub_menu[80] = array("id" => "home", "title" => "{$mybb->settings['cpname']}", "link" => "{$mybb->settings['cpdomain']}");
	$sub_menu[90] = array("id" => "home", "title" => "{$mybb->settings['cpname2']}", "link" => "{$mybb->settings['cpdomain']}");

	return $sub_menu;
}
If there's any un-needed stuff please tell me, Thanks.


WOW, i got it, it was SO simple lol. ill change the code above

-----------------------------------------------------------------------------------

I need help yet again, How can i make it so there's a drop down box and when you pick one it shows the settings?
Something like this?

<SELECT ONCHANGE="location = this.options[this.selectedIndex].value;">
<OPTION VALUE="link1.php">Link 1
<OPTION VALUE="link2.php">Link 2
</SELECT>

An example of how to get that in your code is:

$options = "";
foreach($links as $link) {
$options .= "<option value=\"{$link['link']}\">{$link['name']}\n";
}
$options = "<SELECT ONCHANGE=\"location = this.options[this.selectedIndex].value;\">{$options}</SELECT>";

Obviously change that to work with your code, but that should work.

Regards,
Jammerx2
Ok here's my plugin now,

<?php

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

if(defined("IN_ADMINCP"))
{
	global $mybb;

	$plugins->run_hooks("quicklink_acp_start");

	if(!$mybb->input['module'])
	{
		$plugins->add_hook("admin_home_menu_quick_access", "quicklink_acp_menu");
	}
}
	function quicklink_info()
	{
		return array(
		"name"		=> "Quick Links",
		"description"		=> "Adds cPanel and WHM links to quick access.",
		"website"		=> "http://www.webhostingfox.com",
		"author"		=> "Alex",
		"authorsite"		=> "http://www.webhostingfox.com",
		"version"		=> "1.0",
		"guid" 		=> "",
		"compatibility"	=> "*"
		);
	}

function quicklink_activate()
{
	global $db;

	$quicklink_group = array(
        'gid'    => 'NULL',
        'name'  => 'quicklink',
        'title'      => 'Add New Quick Links.',
        'description'    => 'cPanel and WHM Links in Quick Access.',
        'disporder'    => "1",
        'isdefault'  => 'no',
	);
	$db->insert_query('settinggroups', $quicklink_group);
 	$gid = $db->insert_id();

	$quicklink_setting_1 = array(
	'sid'	 => 'NULL',
	'name'	 => "linkname",
	'title'	 => "Domain Name Number 1",
	'description'	=> "Enter the Quick Access link",
	'optionscode'	=> "text", 
	'value'	 => "Mybb Wiki",
	'disporder'	 => 1,
	'gid'		=> intval($gid),
	);
	$quicklink_setting_2 = array(
	'sid'	 => 'NULL',
	'name'	 => "linkdomain",
	'title'	 => "Domain Link Number 1",
	'description'	=> "Enter the Quick Access link",
	'optionscode'	=> "text", 
	'value'	 => "http://wiki.mybb.com",
	'disporder'	 => 2,
	'gid'		=> intval($gid),
	);
	$quicklink_setting_3 = array(
	'sid'	 => 'NULL',
	'name'	 => "linkname2",
	'title'	 => "Domain Name Number 2",
	'description'	=> "Enter the Quick Access link",
	'optionscode'	=> "text", 
	'value'	 => "Mybb Blog",
	'disporder'	 => 3,
	'gid'		=> intval($gid),
	);
	$quicklink_setting_4 = array(
	'sid'	 => 'NULL',
	'name'	 => "linkdomain2",
	'title'	 => "Domain Link Number 2",
	'description'	=> "Enter the Quick Access link",
	'optionscode'	=> "text", 
	'value'	 => "http://blog.mybb.com",
	'disporder'	 => 4,
	'gid'		=> intval($gid),
	);

	$db->insert_query('settings', $quicklink_setting_1);
	$db->insert_query('settings', $quicklink_setting_2);
	$db->insert_query('settings', $quicklink_setting_3);
	$db->insert_query('settings', $quicklink_setting_4);
	rebuild_settings();
}

function quicklink_deactivate()
{
	global $db;

	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('linkname','linkdomain','linkname2','linkdomain2')");
	$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='quicklink'");
rebuild_settings();
} 

function quicklink_acp_menu(&$sub_menu)
{
	global $mybb;
	
	// Sub menu item
	$sub_menu[70] = array("id" => "home", "title" => "{$mybb->settings['linkname']}", "link" => "{$mybb->settings['linkdomain']}");
	$sub_menu[80] = array("id" => "home", "title" => "{$mybb->settings['linkname2']}", "link" => "{$mybb->settings['linkdomain2']}");

	return $sub_menu;
}
?>

It works fine as showing the links in the sidebar, But is there any errors with this? (Or easier way)
Also, If i wanted to use the select optionscode with this, how could i make it like the mail_handler setting when you change it, it shows more settings/hide others.

Also i got one quick question about how setting coding goes. I've seen a lot of different tuts about making plugins and im wondering whats the best/right way for settings like

$Setting= array(
	'sid'	 => 'NULL',
	'name'	 => "name",
	'title'	 => "Title",
	'description'	=> "description",
	'optionscode'	=> "text", 
	'value'	 => "value",
	'disporder'	 => 3,
	'gid'		=> intval($gid),
	);
Or should the ' be " or the " be '
Use a single query to delete all setting instead of 4
Thanks, i updated the post above yours and added some other questions.. Should i also have the insert setting queries by themselves or as one?
(2010-08-19, 11:33 PM)Alex597 Wrote: [ -> ]It works fine as showing the links in the sidebar, But is there any errors with this? (Or easier way)

Don't see any errors, but haven't looked to in depth.

(2010-08-19, 11:33 PM)Alex597 Wrote: [ -> ]Also, If i wanted to use the select optionscode with this, how could i make it like the mail_handler setting when you change it, it shows more settings/hide others.

Do you mean change the possible values when another value is changed?

I'm assuming you want to be able to change between sets of options. If so, you could use something similar to this (once again, untested)

<script type="text/javascript">
values('values1');
function add(value,text)
{
var opt = document.createElement("OPTION");
opt.text = text;
opt.value = value;
box = document.getElementById('box1');
box.options.add(opt);
}
function values(values) {
box = document.getElementById('box1');
var i;
for(i=box.options.length-1;i>=0;i--)
{
box.remove(i);
}
if(values == "values1") {
add("", "Select");
add("link1.php", "Link 1");
add("link2.php", "Link 2");
add("link3.php", "Link 3");
}

if(values == "values2") {
add("", "Select");
add("secondlink1.php", "Second Link 1");
add("secondlink2.php", "Second Link 2");
add("secondlink3.php", "Second Link 3");
}
}
</script>
<SELECT ONCHANGE="values(this.options[this.selectedIndex].value);">
<OPTION VALUE="values1">Value Set 1
<OPTION VALUE="values2">Value Set 2
</SELECT>
<SELECT ID="box1" ONCHANGE="location = this.options[this.selectedIndex].value;">
</SELECT>

That should work, this time generate values1, values2, etc with the script.

(2010-08-19, 11:33 PM)Alex597 Wrote: [ -> ]Also i got one quick question about how setting coding goes. I've seen a lot of different tuts about making plugins and im wondering whats the best/right way for settings like

$Setting= array(
	'sid'	 => 'NULL',
	'name'	 => "name",
	'title'	 => "Title",
	'description'	=> "description",
	'optionscode'	=> "text", 
	'value'	 => "value",
	'disporder'	 => 3,
	'gid'		=> intval($gid),
	);
Or should the ' be " or the " be '

It really doesn't matter, unless you need to use something in the quotes. E.G. "\n" will be a new line but '\n' won't be.

Regards,
Jammerx2
I actually found how Mybb does it.

<script type="text/javascript" src="./jscripts/peeker.js"></script>
	<script type="text/javascript">
		Event.observe(window, "load", function() {
			loadPeekers();			
		});
		function loadPeekers()
		{
             new Peeker($$(".setting_MYSETTINGHERE"), $("row_setting_MYSETTINGHERE"), /SETTINGVALUE/, false);
		}
	</script>

How could i include that in my plugin, If i can?
Could you explain in more detail exactly what your trying to do?
Ok, look in ACP -> Config -> Settings -> Mail Settings -> basically that when you change to smtp, it makes the smtp settings pop up. And thats done via a js in the acp, but i tried adding my own settings to /admin/module/config/setting.php but it doesn't actually get it, it only gets the default setting.

EDIT: Ok i got it working fine, I'm just wondering, How can i make it so if theres another plugin that adds a link to the quick access (Like the Mynetwork plugin) to make mine plugin go always at the bottom?