MyBB Community Forums

Full Version: is this PC?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi all
I am producing a plugin that requires core edits, however I would perfer to copy the 2 functions and modify them (if a user updates their version of mybb the plugin still works). So is it politically correct to copy and modify some core mybb functions and include them within my plugin
Declaring a function that already exists will cause a PHP error.
(2012-11-05, 07:28 PM)Paul H. Wrote: [ -> ]Declaring a function that already exists will cause a PHP error.

It is declared under a different name....
however you can use mybb functions within a plugin without a problem
Jim you can use the Patches plugin I think, not sure.
(2012-11-05, 07:40 PM)master412160 Wrote: [ -> ]Jim you can use the Patches plugin I think, not sure.

that could be true but what happens if the user does not have that plugin installed ? Also I have never looked at that plugin so it may not do what is required
(2012-11-05, 07:21 PM)JimR Wrote: [ -> ]Hi all
I am producing a plugin that requires core edits, however I would perfer to copy the 2 functions and modify them (if a user updates their version of mybb the plugin still works). So is it politically correct to copy and modify some core mybb functions and include them within my plugin

I do this once and a while, new name, but indicate in the comment that it is from MyBB and what file and then indicate in the code where my edits start and stop.

(2012-11-05, 07:28 PM)Paul H. Wrote: [ -> ]Declaring a function that already exists will cause a PHP error.

Is it a function within a class or a standard function like in functions.php? if in a class, then just create a new class and override it.


(2012-11-05, 07:43 PM)JimR Wrote: [ -> ]
(2012-11-05, 07:40 PM)master412160 Wrote: [ -> ]Jim you can use the Patches plugin I think, not sure.

that could be true but what happens if the user does not have that plugin installed ? Also I have never looked at that plugin so it may not do what is required

you dont need patches, you need pluginlibrary (which Patches uses) and then you can make your core edits that way. you dont "install" pluginlibrary, so you can include it with your plugin (if the license allows) or run a simple check to see if the plugin exists and then prompt for it to be installed.

here is how I use it (part of it) in my Subject Color plugin

<?php
/**
 * Subject Color Plugin for MyBB
 * Copyright 2011 CommunityPlugins.com, All Rights Reserved
 *
 * Website: http://www.communityplugins.com
 * Version 1.0
 * License: Creative Commons Attribution-NonCommerical ShareAlike 3.0
				http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode
 *
 */

// 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("PLUGINLIBRARY"))
{
    define("PLUGINLIBRARY", MYBB_ROOT."inc/plugins/pluginlibrary.php");
}

$plugins->add_hook("editpost_end", "subcolor_add_picker");
$plugins->add_hook("newthread_end", "subcolor_add_picker");

$plugins->add_hook("datahandler_post_update_thread", "subcolor_add_data"); //passes $this as hander object
$plugins->add_hook("datahandler_post_insert_thread", "subcolor_add_data"); //passes $this as hander object

$plugins->add_hook("subcolor_apply", "subcolor_apply");

function subcolor_info()
{
	return array(
		"name"		=> "Subject Color",
		"description"	=> "Allows specifc usergroups to alter the color of a thread subject.",
		"website"	=> "http://www.communityplugins.com",
		"author"	=> "CommunityPlugins.com",
		"authorsite"	=> "http://www.communityplugins.com",
		"version"	=> "1.0",
		"guid"		=> "",
		"compatibility" => "16*",
	);
}
 
function subcolor_install()
{
	global $db, $mybb;
	
	if(!file_exists(PLUGINLIBRARY))
	{
		flash_message("This plugin requires PluginLibrary 8 or later. Please install it prior to installing Subject Color.", 'error');
		admin_redirect("index.php?module=config-plugins");
	}

	global $PL;
	$PL or require_once PLUGINLIBRARY;

	if($PL->version < 8)
	{
		flash_message("This plugin requires PluginLibrary 8 or later. Please install it prior to installing Subject Color.", "error");
		admin_redirect("index.php?module=config-plugins");
	}
(2012-11-05, 09:35 PM)pavemen Wrote: [ -> ]
(2012-11-05, 07:21 PM)JimR Wrote: [ -> ]Hi all
I am producing a plugin that requires core edits, however I would perfer to copy the 2 functions and modify them (if a user updates their version of mybb the plugin still works). So is it politically correct to copy and modify some core mybb functions and include them within my plugin

I do this once and a while, new name, but indicate in the comment that it is from MyBB and what file and then indicate in the code where my edits start and stop.

(2012-11-05, 07:28 PM)Paul H. Wrote: [ -> ]Declaring a function that already exists will cause a PHP error.

Is it a function within a class or a standard function like in functions.php? if in a class, then just create a new class and override it.


(2012-11-05, 07:43 PM)JimR Wrote: [ -> ]
(2012-11-05, 07:40 PM)master412160 Wrote: [ -> ]Jim you can use the Patches plugin I think, not sure.

that could be true but what happens if the user does not have that plugin installed ? Also I have never looked at that plugin so it may not do what is required

you dont need patches, you need pluginlibrary (which Patches uses) and then you can make your core edits that way. you dont "install" pluginlibrary, so you can include it with your plugin (if the license allows) or run a simple check to see if the plugin exists and then prompt for it to be installed.

here is how I use it (part of it) in my Subject Color plugin

<?php
/**
 * Subject Color Plugin for MyBB
 * Copyright 2011 CommunityPlugins.com, All Rights Reserved
 *
 * Website: http://www.communityplugins.com
 * Version 1.0
 * License: Creative Commons Attribution-NonCommerical ShareAlike 3.0
				http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode
 *
 */

// 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("PLUGINLIBRARY"))
{
    define("PLUGINLIBRARY", MYBB_ROOT."inc/plugins/pluginlibrary.php");
}

$plugins->add_hook("editpost_end", "subcolor_add_picker");
$plugins->add_hook("newthread_end", "subcolor_add_picker");

$plugins->add_hook("datahandler_post_update_thread", "subcolor_add_data"); //passes $this as hander object
$plugins->add_hook("datahandler_post_insert_thread", "subcolor_add_data"); //passes $this as hander object

$plugins->add_hook("subcolor_apply", "subcolor_apply");

function subcolor_info()
{
	return array(
		"name"		=> "Subject Color",
		"description"	=> "Allows specifc usergroups to alter the color of a thread subject.",
		"website"	=> "http://www.communityplugins.com",
		"author"	=> "CommunityPlugins.com",
		"authorsite"	=> "http://www.communityplugins.com",
		"version"	=> "1.0",
		"guid"		=> "",
		"compatibility" => "16*",
	);
}
 
function subcolor_install()
{
	global $db, $mybb;
	
	if(!file_exists(PLUGINLIBRARY))
	{
		flash_message("This plugin requires PluginLibrary 8 or later. Please install it prior to installing Subject Color.", 'error');
		admin_redirect("index.php?module=config-plugins");
	}

	global $PL;
	$PL or require_once PLUGINLIBRARY;

	if($PL->version < 8)
	{
		flash_message("This plugin requires PluginLibrary 8 or later. Please install it prior to installing Subject Color.", "error");
		admin_redirect("index.php?module=config-plugins");
	}
thanks for that I'll add remarks to the plugin, The idea was not to reinvent the wheel, just modify it. I don't want to use core edits as the functions I have modified may have undesired results on other parts of the forum, going off topic is there code to test for the version of php installed on the server as my plugin requires php v5.3 or greater .. if you add it to a site running php v5.2x it crashes the admin cp
echo substr(phpversion(),0,strpos(phpversion(), '-'));
(2012-11-08, 04:45 PM)pavemen Wrote: [ -> ]echo substr(phpversion(),0,strpos(phpversion(), '-'));

thanks
then use the version_compare() php function to test.
Pages: 1 2