2018-01-27, 06:28 PM
I'm having issues with the plugin I'm creating. Right now its not doing aything as when I upload it to inc/plugins folder it destroys the page for plugins in the ACP. By destroy I mean it hides the list of installed/active plugins and the uninstalled/not active plugins. Could someone skim over my code and see if I'm doing something wrong?
<?php
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.");
}
$plugins->add_hook('portal_start', 'randomstreamer_promotion');
function otgs_info()
{
return array(
"name" => "OTGS",
"description" => "Team G Twitch Streamer",
"website" => "http://goltrix2580.com",
"author" => "TheCrzyDoctor",
"authorsite" => "http://goltrix2580.com",
"version" => "0.01",
"codename" => "otgs",
"compatibility" => "18*"
);
}
function otgs_install()
{
global $mybb, $db;
$gid = $db->insert_query('settinggroups', array(
'name' => 'Official Team G Streamer',
'title' => 'OTGS',
'description' => 'Solution to pick random streamer to promote based on user groups',
));
$cfg = array (
array(
"name" => "OTGS Enabled",
"title" => "Enable OTGS",
"description" => "Turn OTGS On/Off",
"optioncode" => "yesno",
"value" => "1",
"isdefault" => 1,
"disporder" => 1,
"gid" => $gid,
),
array(
"name" => "User Group to Promote",
"title" => 'User Group to Promote",
"description" => "Pick a user group to promote.",
"optionscode' => "groupselect",
"isdefault" => 1,
"value" => "",
"disporder" => 0,
"gid" => $gid,
),
);
// insert array into database
foreach ($cfg as $settings){
$db->insert_query("settings", $settings);
}
rebuild_settings();
}
function otgs_is_installed()
{
global $db;
// Checks to see if the settings are in the table. If so the plugin is installed.
$query = $db->simple_select("settinggroups", "gid", "name='Official Team G Streamer'");
$row = $db->num_rows($query);
$settings_exists = !empty($row);
return $settings_exists
}
function otgs_uninstall()
{
global $db;
$settingsGroupId = $ db->fetch_field(
$db->simple_select("settinggroups", "gid", "name='Official Team G Streamer'"), "gid";
);
$db->delete_query("settinggroups", "gid=", (int)$settingsGroupId);
$db->delete_query("settings", "gid=", (int)$settingsGroupId);
rebuild_settings();
}
function otgs_activate()
{
global $db;
$db->update_query("settings", array("value" => 1), "name='OTGS Enabled'");
}
function otgs_deactivate()
{
global $db;
$db->update_query("settings", array("value" => 0), "name='OTGS Enabled'");
}
function randomstreamer_promotion(){
// This is most likely completely all wrong (still reading up on how to do this..)
// Bring in db to use database
global $db, $streamer;
// pull text from custom field
//$query = $db->query("SELECT * FROM profilefields WHERE twitchaccount IS NOT NULL");
// lets get how many rows are in the query
//$max_number = $db->num_rows($query);
// lets generate a random number to select what streamer to promote.
//$streamer_num = rand(1, $max_number);
// set text from query to variable.
//$var = $db->fetch_field($query)) // still need to figure out how to get the $treamer_num row from the query.
$streamer = "thecrzydoctor"; // hard coded for testing as I still need to setup the custom profile field and integrate checking what group a person belongs to.
echo $streamer; // now if i use {$streamer} inside my portal template I should get $var which would be a single row since I'm using simple_select?
}