MyBB Community Forums

Full Version: 1st Time Developing a Plugin Support
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I'm trying to make a plugin like the Facebook like plugin but I'm wanting it to link to the users chrome extension directory location and have a image with it but I have a error 0n line 89 and I can't figure out what's going on. Any ideas on what the problem is and how to fix it?

Here's the code:
<?php
/********************************************************************************
 *
 *  Chrome Extension Plugin (/inc/plugins/ChromeExtension.php)
 *  Author: Technologx
 *  Copyright: © 2015 Technologx
 *  
 *  Website: http://technologx.fulba.com
 *  License: license.txt
 *  Any codes in this plugin are copyrighted and not allowed to be reproduced.
 * 
 *  Allows you to add a Chrome Extension Link on your website.
 *
 ********************************************************************************/


if(!defined("IN_MYBB"))
	die("This file cannot be accessed directly.");

// add hooks

function ChromeExtension_info()
{
	return array(
		"name"			=> "Chrome Extension",
		"description"	=> "Allows you to add a Chrome Extension Link on your website.",
		"website"		=> "http://technologx.fulba.com",
		"author"		=> "Technologx",
		"authorsite"	=> "http://technologx.fulba.com",
		"version"		=> "1.0",
		"guid" 		=> "",
		"compatibility"	=> "*"
	);
}


function ChromeExtension_activate()
{
	global $db, $lang;
      require MYBB_ROOT."/inc/adminfunctions_templates.php";
	$insertarray = array(
		'name' => 'ChromeExtension', 
		'title' => 'Chrome Extension', 
		'description' => "Settings for Chrome Extension", 
		'disporder' => 1, 
		'isdefault' => 0
	);
	$gid = $db->insert_query("settinggroups", $insertarray);
	// add settings

	$furl = array(
		"sid"			=> NULL,
		"name"			=> "ChromeExtensionURL",
		"title"			=> "URL",
		"description"	=> "Enter the Chrome Extension URL here.",
		"optionscode"	=> "textarea",
		"value"			=> "",
		"disporder"		=> 1,
		"gid"			=> intval($gid)
	);

	$db->insert_query("settings", $furl);
	rebuild_settings();

    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("header", "#".preg_quote("{\$pending_joinrequests}")."#i", "{\$pending_joinrequests}{\$flike}");

}

function ChromeExtension_deactivate()
{
    global $db, $mybb;
    $db->delete_query("settinggroups", "name='Chrome_Extension'");
    $db->delete_query('settings', 'name IN ( \'Chrome_Extension_Url\')');

	
require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets("header", "#".preg_quote('{$cextension}')."#i", '', 0);


	rebuild_settings();

}

$plugins->add_hook("global_start", "cextension");
function cextension()
{
    global $mybb, $templates,  $cextension;
    $cextension = '<br /><div align="center"><a href="{$mybb->settings['bburl']}"><img src="{$mybb->settings['bburl']}/images/chrome.png"></a></div><br />';
}

?>
change 2 occurrences of settings['bburl'] to settings[\'bburl\']

details => Escaping quotation marks in PHP
(2015-12-11, 07:22 AM).m. Wrote: [ -> ]change 2 occurrences of settings['bburl'] to settings[\'bburl\']

details => Escaping quotation marks in PHP

Parse error: syntax error, unexpected '\' (T_NS_SEPARATOR) in inc/plugins/ChromeExtension.php on line 89

Updated code:
<?php
/********************************************************************************
 *
 *  Chrome Extension Plugin (/inc/plugins/ChromeExtension.php)
 *  Author: Technologx
 *  Copyright: © 2015 Technologx
 *  
 *  Website: http://technologx.fulba.com
 *  License: license.txt
 *  Any codes in this plugin are copyrighted and not allowed to be reproduced.
 * 
 *  Allows you to add a Chrome Extension Link on your website.
 *
 ********************************************************************************/


if(!defined("IN_MYBB"))
 die("This file cannot be accessed directly.");

// add hooks

function ChromeExtension_info()
{
 return array(
 "name" => "Chrome Extension",
 "description" => "Allows you to add a Chrome Extension Link on your website.",
 "website" => "http://technologx.fulba.com",
 "author" => "Technologx",
 "authorsite" => "http://technologx.fulba.com",
 "version" => "1.0",
 "guid" => "",
 "compatibility" => "*"
 );
}


function ChromeExtension_activate()
{
 global $db, $lang;
      require MYBB_ROOT."/inc/adminfunctions_templates.php";
 $insertarray = array(
 'name' => 'ChromeExtension', 
 'title' => 'Chrome Extension', 
 'description' => "Settings for Chrome Extension", 
 'disporder' => 1, 
 'isdefault' => 0
 );
 $gid = $db->insert_query("settinggroups", $insertarray);
 // add settings

 $furl = array(
 "sid" => NULL,
 "name" => "ChromeExtensionURL",
 "title" => "URL",
 "description" => "Enter the Chrome Extension URL here.",
 "optionscode" => "textarea",
 "value" => "",
 "disporder" => 1,
 "gid" => intval($gid)
 );

 $db->insert_query("settings", $furl);
 rebuild_settings();

    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("header", "#".preg_quote("{\$pending_joinrequests}")."#i", "{\$pending_joinrequests}{\$flike}");

}

function ChromeExtension_deactivate()
{
    global $db, $mybb;
    $db->delete_query("settinggroups", "name='Chrome_Extension'");
    $db->delete_query('settings', 'name IN ( \'Chrome_Extension_Url\')');

 
require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets("header", "#".preg_quote('{$cextension}')."#i", '', 0);


 rebuild_settings();

}

$plugins->add_hook("global_start", "cextension");
function cextension()
{
    global $mybb, $templates,  $cextension;
    $cextension = '<br /><div align="center"><a href="{$mybb->settings['\bburl\']}"><img src="{$mybb->settings['\bburl\']}/images/chrome.png"></a></div><br />';
}

?>

It had to be / instead of \

Now I get this on the forum itself:
[attachment=35629]
backslash (\) should be used before the quote mark (')
Please try this:
function cextension()
{
   global $mybb, $templates,  $cextension;
   $cextension = "<br /><div align=\"center\"><a href=\"'.$mybb->settings['bburl'].'\"><img src=\"'.$mybb->settings['bburl'].'/images/chrome.png\" alt=\"crome.png\" /></a></div><br />";
}
(2015-12-11, 11:27 AM)SvePu Wrote: [ -> ]Please try this:
function cextension()
{
   global $mybb, $templates,  $cextension;
   $cextension = "<br /><div align=\"center\"><a href=\"'.$mybb->settings['bburl'].'\"><img src=\"'.$mybb->settings['bburl'].'/images/chrome.png\" alt=\"crome.png\" /></a></div><br />";
}

That worked now I'm getting 2 Facebook like buttons with no chrome button.

I also have double settings options in the ACP:
[attachment=35631]
There are some issues in your plugin script:

Please try this:
<?php
/********************************************************************************
*
*  Chrome Extension Plugin (/inc/plugins/ChromeExtension.php)
*  Author: Technologx
*  Copyright: © 2015 Technologx
*  
*  Website: http://technologx.fulba.com
*  License: license.txt
*  Any codes in this plugin are copyrighted and not allowed to be reproduced.
* 
*  Allows you to add a Chrome Extension Link on your website.
*
********************************************************************************/


if(!defined("IN_MYBB"))
    die("This file cannot be accessed directly.");

// add hooks
$plugins->add_hook("global_start", "ChromeExtension_run");

function ChromeExtension_info()
{
    return array(
        "name"          => "Chrome Extension",
        "description"   => "Allows you to add a Chrome Extension Link on your website.",
        "website"       => "http://technologx.fulba.com",
        "author"        => "Technologx",
        "authorsite"    => "http://technologx.fulba.com",
        "version"       => "1.0",
        "guid"         => "",
        "compatibility"    => "*"
    );
}


function ChromeExtension_activate()
{
    global $db;
    $insertarray = array(
        'name' => 'ChromeExtension', 
        'title' => 'Chrome Extension', 
        'description' => "Settings for Chrome Extension", 
        'disporder' => 1, 
        'isdefault' => 0
    );
    $gid = $db->insert_query("settinggroups", $insertarray);
    // add settings

    $furl = array(
        "sid"            => NULL,
        "name"           => "ChromeExtensionURL",
        "title"          => "URL",
        "description"    => "Enter the Chrome Extension URL here.",
        "optionscode"    => "textarea",
        "value"          => "",
        "disporder"      => 1,
        "gid"            => intval($gid)
    );

    $db->insert_query("settings", $furl);
    rebuild_settings();

    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("header", "#".preg_quote("{\$pending_joinrequests}")."#i", "{\$pending_joinrequests}{\$flike}");

}

function ChromeExtension_deactivate()
{
 global $db;

 require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
 find_replace_templatesets("header", "#".preg_quote('{$cextension}')."#i", '', 0);

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

 rebuild_settings();
}

function ChromeExtension_run()
{
 global $mybb, $templates,  $cextension;
 $cextension = '';
 if(!empty($mybb->settings['ChromeExtensionURL']))
 {
   $cextension = "<br /><div align=\"center\"><a href=\"'.$mybb->settings['ChromeExtensionURL'].'\"><img src=\"'.$mybb->settings['bburl'].'/images/chrome.png\" alt=\"crome.png\" /></a></div><br />";
 }   
}
(2015-12-12, 12:09 AM)SvePu Wrote: [ -> ]There are some issues in your plugin script:

Please try this:
<?php
/********************************************************************************
*
*  Chrome Extension Plugin (/inc/plugins/ChromeExtension.php)
*  Author: Technologx
*  Copyright: © 2015 Technologx
*  
*  Website: http://technologx.fulba.com
*  License: license.txt
*  Any codes in this plugin are copyrighted and not allowed to be reproduced.
* 
*  Allows you to add a Chrome Extension Link on your website.
*
********************************************************************************/


if(!defined("IN_MYBB"))
    die("This file cannot be accessed directly.");

// add hooks
$plugins->add_hook("global_start", "ChromeExtension_run");

function ChromeExtension_info()
{
    return array(
        "name"          => "Chrome Extension",
        "description"   => "Allows you to add a Chrome Extension Link on your website.",
        "website"       => "http://technologx.fulba.com",
        "author"        => "Technologx",
        "authorsite"    => "http://technologx.fulba.com",
        "version"       => "1.0",
        "guid"         => "",
        "compatibility"    => "*"
    );
}


function ChromeExtension_activate()
{
    global $db;
    $insertarray = array(
        'name' => 'ChromeExtension', 
        'title' => 'Chrome Extension', 
        'description' => "Settings for Chrome Extension", 
        'disporder' => 1, 
        'isdefault' => 0
    );
    $gid = $db->insert_query("settinggroups", $insertarray);
    // add settings

    $furl = array(
        "sid"            => NULL,
        "name"           => "ChromeExtensionURL",
        "title"          => "URL",
        "description"    => "Enter the Chrome Extension URL here.",
        "optionscode"    => "textarea",
        "value"          => "",
        "disporder"      => 1,
        "gid"            => intval($gid)
    );

    $db->insert_query("settings", $furl);
    rebuild_settings();

    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("header", "#".preg_quote("{\$pending_joinrequests}")."#i", "{\$pending_joinrequests}{\$flike}");

}

function ChromeExtension_deactivate()
{
 global $db;

 require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
 find_replace_templatesets("header", "#".preg_quote('{$cextension}')."#i", '', 0);

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

 rebuild_settings();
}

function ChromeExtension_run()
{
 global $mybb, $templates,  $cextension;
 $cextension = '';
 if(!empty($mybb->settings['ChromeExtensionURL']))
 {
   $cextension = "<br /><div align=\"center\"><a href=\"'.$mybb->settings['ChromeExtensionURL'].'\"><img src=\"'.$mybb->settings['bburl'].'/images/chrome.png\" alt=\"crome.png\" /></a></div><br />";
 }   
}

How do I get rid of the double settings?

Also it's still showing 2 Facebook like buttons on the front end.
Please deactivate the new plugin version once...then the doubled settings also will be deleted.

Maybe the chrome.png in images folder is a facebook button.
(2015-12-12, 07:58 AM)SvePu Wrote: [ -> ]Please deactivate the new plugin version once...then the doubled settings also will be deleted.

Maybe the chrome.png in images folder is a facebook button.

This is the image I have in the images folder:
[attachment=35634]

I've tried deactivating the plugin and remove it from my website directory and it still shows up in the ACP now I have triple Chrome Extension settings.
Pages: 1 2