MyBB Community Forums

Full Version: Install Hack Partnership
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Seeing as I'm no good with MySQL, I need someone to work up a database schema for the install hack I mentioned in MM's thread.

That way I can do the PHP coding for it.

If anyone was willing to help me with this I'd be much obliged! Big Grin
If you can post exactly what you need the mod to do (just what was in the other thread, or anything you missed out, etc? Smile) then I'll see if I can give you a hand once I've finished on a couple of other things I'm currently working on. Smile
Yep, pretty much what I said in the other thread.

Note: I actually need the database portion of the hack written.
Ok, so what this basically requires is:

* A new field in the forums table, which controls which forums show the "Install" link.

* A new table for modifications, in which each mod holds a user ID as the author (just how this site works Wink).

It seems fairly straight forward, but I'm quite busy tonight. If you can wait untill tomorrow I'll give you a few database changes and some information on setting and using this information in your script. Smile
I can wait. Smile

Thanks for your help. Big Grin
Ok, I've made a start on this. Firstly you need to run a mySQL query to modify the forums table. You can use phpMyAdmin to run this query if you use it.

The query is: ALTER TABLE forums ADD showinstalllink CHAR( 3 ) DEFAULT 'no' NOT NULL ;

This value is set to no by default. If you want to show the "Install" link, you need to add a control to the forums administration part of the control panel. To do this you need to edit admin/forums.php. In there, look for if($action == "add") and then just add a line like this somewhere...

makeyesnocode("Show \\"Install\\" link on threads in this forum?", "showinstalllink", "no");

I'm not sure how farmiliar you are with myBB's admin functions, so to explain the code above, the makeyesnocode() function creates two radio buttons, obviously one labelled "yes" and the other labelled "no". The first argument in this line is what the option should be labelled as, the second is the name of the database field that this option will effect, and the third ("no") controls which option is selected by default. So, this line inparticular adds a new line to the "Add Forum" page, asking whether the "Install" link should be shown at the top of all threads in that forum, this setting will be held in a databas field named "showinstalllink" and by default it is set to "no". Wink

Baring this information in mind, you will also need to edit the database query in the "do_add" block of the file. It should look something like this in order to work correctly (changes are in bold)...

$db->query("INSERT INTO forums (fid,name,description,linkto,type,pid,disporder,active,open,threads,posts,lastpost,lastposter,allowhtml,allowmycode,allowsmilies,allowimgcode,allowpicons,allowtratings,usepostcounts,password,showinjump,modposts,modthreads,modattachments,style,overridestyle,showinstalllink) VALUES (NULL,'$name','$description','$linkto','$type','$pid','$disporder','$isactive','$isopen','0','0','0','0','$allowhtml','$allowmycode','$allowsmilies','$allowimgcode','$allowpicons','$allowtratings','$usepostcounts','$password','$showinjump','$modposts','$modthreads','$modattachments','$fstyle','$overridestyle','$showinstalllink')");

Similarly, you will need to edit the $action == "edit" and $action == "do_edit" blocks of the file too. Wink

As for the rest of what you want, I need a little more information. I realise you need a new table to hold all the mods and things that users submit, but what exactly should be stored in this table, and how are the mods submitted and viewed? Are they in the forum of threads, so each thread is classed as a modification, or are they submitted some other way and echoed into threads etc? Also, what happens when a user clicks the "Install" link for that mod? Are they automatically subscribed to the thread? etc.

Sorry for all the questions, but I need a crystal clear picture of what you need before I can make anything more. It's quite straight forward after that. Smile
Well, I've changed it completely around from what I was gonna do originally.

I've got the database all set up with a new table called "installs" with the following: username, uid, and tid.

And when someone installs the mod their username, uid, and the tid of the thread is inserted into the table.

I got it all set up and I click install to test it. The information is inserted into the database fine, but, the install doesn't change to an uninstall link.

It's confused me...

Here's the code I used in showthread.php.

// ############################# Install Hack ##################################
// Database Stuff
if ($thread[fid]==2)
{
$installerid = $db->query("SELECT uid FROM installs WHERE tid = $tid and uid = $mybbuser[uid]");
}
// Install Link
if ($thread[fid]==2 && $installerid[uid]!=$mybbuser[uid])
{
$install="( <a href=\\"showthread.php?do=install&tid=$tid\\">Install This Mod</a> )";
}
else
{
$install="";
}
// Uninstall Link
if ($thread[fid]==2 && $installerid[uid]==$mybbuser[uid])
{
$uninstall="( <a href=\\"showthread.php?do=uninstall&tid=$tid\\">Uninstall This Mod</a> )";
}
else
{
$uninstall="";
}
// Do Install
if ($_REQUEST["do"] == "install")
{
if ($installerid[userid]!=$mybbuser[uid])
{
$db->query("
INSERT INTO installs
(username,uid,tid)
VALUES
('".addslashes($mybbuser[username])."','".$mybbuser[uid]."','".$tid."')
");

}
eval("\\$message = \\"".$templates->get("redirect_installed")."\\";");
redirect("$settings[bbname] - Mod Installed", $message, "showthread.php?tid=$tid");
}

// Do Un-Install
if ($_REQUEST["do"] == "uninstall")
{
$db->query("
DELETE FROM installs WHERE tid = $tid AND uid = $mybbuser[uid]
");
eval("\\$message = \\"".$templates->get("redirect_uninstalled")."\\";");
redirect("$settings[bbname] - Mod Uninstalled", $message, "showthread.php?tid=$tid");
}
// ####################### End Install Hack ####################################

Anything wrong?
As the official myBB forums have working [code] tags, I posted a response to you there. :p

http://www.mybboard.com/community/showth...955#pid955

Let me know how you get on. Smile
It worked thanks. Smile