MyBB Community Forums

Full Version: Website News Plugin for MyBB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ok so i want to integrate myBB in my website a little. So what i had in mind was that when you create a topic in a specific forum and you're in a specific usergroup (the admin one) in the Topic Creation Page you get an additional block below Attachments that has a textarea for entering a short news message and some other options (like the news image). When this topic is created, in the database in the the row of this topic there are additional fields that have those details saved so my website can access them and for example output the short news message on the website.

Now this is what i have now:

<?php

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

$plugins->add_hook("newthread_start", "stellarnews");

function stellarnews_info()
{
	return array(
		"name"			=> "Site News Plugin",
		"description"	=> "Posts the news on the website!",
		"website"		=> "http://site.net",
		"author"		=> "Fabis",
		"authorsite"	=> "http://site.net",
		"version"		=> "1.0",
		"guid" 			=> "",
		"compatibility" => "16*"
	);
}

function stellarnews_activate() {
	global $db;

	  
	  $group = array(
        "gid"            => "NULL",
        "title"          => "StellarHelp News Plugin",
        "name"           => "stellarnews",
        "description"    => "Posts the news on the website!",
        "disporder"      => "88",
        "isdefault"      => "0",
    );
	      $db->insert_query("settinggroups", $group);
    $gid = $db->insert_id();
	
//This setting turns the first bar on
$snews1 = array(
		"sid"  => "NULL",
		"name" => "snews1",
		"title" => "News Forum ID's",
		"description" => "Enter the ID's of the news forums, seperated by a comma",
		"optionscode" => "text",
		"value" => "1",
		"disporder" => "1",
		"gid" => intval($gid),
		);
	$db->insert_query("settings", $snews1);
	
$snews2 = array(
		"sid"  => "NULL",
		"name" => "snews2",
		"title" => "Usergroup ID's",
		"description" => "Enter the ID's of the usergroups allowed to post news, seperated by a comma",
		"optionscode" => "text",
		"value" => "1",
		"disporder" => "2",
		"gid" => intval($gid),
		);
	$db->insert_query("settings", $snews2);
	rebuildsettings();

	
}

function stellarnews_deactivate() {
	global $db;
	

	
	$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name IN ('stellarnews')");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('snews1','snews2')");

	rebuild_settings();

}

function stellarnews() {
	$ugroups = explode(",",$mybb->settings['snews2']);
	$forums = explode(",",$mybb->settings['snews1']);
	$admin = false;
	$inforum = false;
	for ($i = 0; $i < count($ugroups); $i++) {
		if ($mybb->user['usergroup'] == $ugroups[$i]) {
			$admin = true;
		}
	}
	for ($i = 0; $i < count($forums); $i++) {
		if ($forum_that_user_is_posting_in == $forums[$i]) {
			$inforum = true;
		}
	}
	if ($admin && $inforum) {
		//Change whatever is necessary
	}
}
?>

This is what i want to display under the attachment block (for now):

<br />
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder">

<tr>
	<td class="thead" colspan="3"><strong>Website News Post</strong></td>
</tr>

<tr>
	<td class="tcat smalltext" colspan="3">Please fill out this section, so the news post will succesfully work on the website.</td>
</tr>

<tr>
<td class="trow1" width="20%"><strong>News Image</strong></td>
<td class="trow1" style="white-space: nowrap"><input type="file" name="attachment" size="30" class="fileupload" /></td><td class="trow1" align="center"><input type="submit" class="button" name="updateattachment" value="Upload Image" tabindex="12" />
</td>
</tr>

<tr>
<td class="trow2" style="vertical-align: top"><strong>News Text</strong></td>
<td class="trow2"><textarea class="textbox" name="subject" rows="6" cols="40" tabindex="1" /></textarea></td>
</tr>

<tr>
<td class="trow1" style="vertical-align: top"><strong>Select the News Image</strong><br></td>
<td class="trow1" style="vertical-align: top">

<select>
<option value="image1">Image number 1</option>
<option value="image2">Image number 2</option>
<option value="image3">Image number 3</option>
<option value="image4">Image number 4</option>
</select>

</td>
</tr>

<tr>
<td class="trow2" style="vertical-align: top"><strong>Current Image</strong></td>
<td class="trow2"><img src="/icy_test/images/news_img_test.png"></td>
</tr>

</table>

Now i was checking out the newthread.php and i cant find or understand what am i supposed to do next. I'd appreciate some help from you guys Smile

Also this will be a private plugin and will not be uploaded to the Mods database, so what do i enter in those guid and GID fields?
For the code that needs to go into under attachments, you need to edit a template. The guid field in the _info() section is optional.
Yeah, but that block only needs to appear to the people in a specific usergroup. If i edit a template, it'll show for everyone.
(2010-08-26, 09:22 PM)jlong1 Wrote: [ -> ]The guid field in the _info() section is optional.
If I remember correctly, the guid field is for the MyBB mods site to alert users of updates to a plugin.
Yeah, that's why I said it was optional. It's only needed if it's being uploaded to the mybb mods db (which this isn't), and if you want updates available for users through the mods system. The guid is generated when you make the plugin on the mods site I think.

And to OP, you can always use the bit with the mod options or you can use the PHP in Templates and Template Conditionals plugin to check if the user is an admin/supermod/mod/other usergroup.
What bit with the mod options?
Look at the template newreply_modoptions, you can add your code in above/below that.
(2010-08-26, 09:44 PM)Conor Calby Wrote: [ -> ]
(2010-08-26, 09:22 PM)jlong1 Wrote: [ -> ]The guid field in the _info() section is optional.
If I remember correctly, the guid field is for the MyBB mods site to alert users of updates to a plugin.

That is correct. You can just leave it as "" Smile

(2010-08-26, 10:07 PM)jlong1 Wrote: [ -> ]Look at the template newreply_modoptions, you can add your code in above/below that.

Oh yeah that could work, but what if i want to add another usergroup to be able to see that :/ It's not very customizable that way.

Also about that PHP plugin - isn't it very unsafe? Like if someone phishes an account of an admin or something, he can do pretty much anything in a template.

EDIT: Hmm it still doesn't work even with the plugin. The plugin works if i directly write something into the template (like <?php echo 'hi'; ?>), but the plugin adds {$stellarnews} which contains the PHP code and then it doesn't execute it.