MyBB Community Forums

Full Version: Check plugin version before run
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I implemented this code in my plugin so that it checks whether there is a latest language file uploaded. Here's part of my codes:
$fbconnectversion = '0.1.0';
require_once "./global.php";
$lang->load("fbconnect");
if ($fbconnectversion == $lang->fbconnectversion)
	{
		$allowrun = true;
	}
if ($allowrun)
{
	//Do magic xD
}
Everything runs perfectly. However, i need to set the version in "$fbconnectversion" manually each time.

Is there a way for it to fetch the version of the plugin as set in "function fbconnect_info()" and insert it in "$fbconnectversion"?

n00b here Blush

Best regards
Nayar
You can use .xml files for such purposes.
First you have to use an external .xml file to insert versions. Then you can fetch the contents of that file. Like;

$fetch_list = fetch_remote_file("URL_OF_XML_FILE_GOES_HERE.xml");

It should have an .xml extension !

Then you can parse the .xml file using strpos(); and substr(); functions.

EDIT:
Oh well, Try to see this plugin , the author has used version thing using external file link. I'm sure you will learn how to use such thing.
thanks a lot buddy Smile

It is much more complicated than i imagined. Maybe its better for me to use my actual method Wink

Regards
The best solution is to not do this at all. It's a waste of resources to load an XML file with every request, and/or use other methods to check whether all plugin files are the correct version. Leave it to the forum admin to provide the correct files. If they use the wrong files and that causes problems, that's their fault, not yours.

If its the same plugin then here is a simple way of getting the version:

$info = fbconnect_info();

The version will then be $info['version']

Unless I misunderstood what you were asking :p
(2010-11-20, 08:43 PM)- G33K - Wrote: [ -> ]If its the same plugin then here is a simple way of getting the version:

$info = fbconnect_info();

The version will then be $info['version']

Unless I misunderstood what you were asking :p

that is what i am using in my garage plugin to set the copyright line in the ACP and to handle upgrades in the code.
(2010-11-20, 08:47 PM)pavemen Wrote: [ -> ]
(2010-11-20, 08:43 PM)- G33K - Wrote: [ -> ]If its the same plugin then here is a simple way of getting the version:

$info = fbconnect_info();

The version will then be $info['version']

Unless I misunderstood what you were asking :p

that is what i am using in my garage plugin to set the copyright line in the ACP and to handle upgrades in the code.

Yeah me too. Though I added an additional array element (intver) that will use only numerical value for example 121 for 1.2.1 which takes care of multiple decimal points.
use the built in php version comparison function handles multiple dot versions
(2010-11-20, 10:16 PM)pavemen Wrote: [ -> ]use the built in php version comparison function handles multiple dot versions

Yeah the above was just an example where I use intver. I also use it for other purposes like unique identifier for js calls (like MyBB's .js?ver=)
Just an example for the OP to manipulate the info function to your like Wink
(2010-11-20, 08:43 PM)- G33K - Wrote: [ -> ]$info = fbconnect_info();
The version will then be $info['version']
Thanks a lot. it worked. I also used a technique that frostschutz used to put the info in a separate file.
My codes now look like this:
require_once "./global.php";

require_once MYBB_ROOT."fbconnect/fbconnectinfo.php";
$fbconnectinfo = info();
$fbconnectversion = $fbconnectinfo['version'];

$lang->load("fbconnect");

if ($fbconnectversion == $lang->fbconnectversion)
    {
        $allowrun = true;
    }
if ($allowrun)
{
    //Do magic xD
}

And sorry for late reply. I did not get the email notifications of replies. It was by chance that i notice this thread has replies in usercp Big Grin

total n00b here Blush