2018-01-23, 07:34 AM
So instead of requesting a plugin to be made, I decided I'd try my hand at creating my own for the site I help run. My background is in Python and django for work and figured why not try my hand at some php as well. Though before I dive way deep into what I want to start making I want to make sure I understand how creating plugin hooks work.
So basically what I want to do is add a custom profile field (which is already supported) I want to create a plugin that will pull the custom field from the database and use it to show the person's twitch. I've read over the following page and just want to know if I am heading in the right direction. with how hooks work. The randomstreamer_promotion function is most likely completely wrong. Any help on or point to the right direction for the function would be great. From what I understand what I have would replace the entire portal page. I'm still looking up how to only do a certain area of the page. And yes I know I still have to set up the rest of the plugin. I also the know the query I have right now would select all the twitchaccounts form the profilefields and only return the first one. I'm going to create a random number based on how many accounts have the field filled in and have the random number be the selection of which user to pick.
So basically what I want to do is add a custom profile field (which is already supported) I want to create a plugin that will pull the custom field from the database and use it to show the person's twitch. I've read over the following page and just want to know if I am heading in the right direction. with how hooks work. The randomstreamer_promotion function is most likely completely wrong. Any help on or point to the right direction for the function would be great. From what I understand what I have would replace the entire portal page. I'm still looking up how to only do a certain area of the page. And yes I know I still have to set up the rest of the plugin. I also the know the query I have right now would select all the twitchaccounts form the profilefields and only return the first one. I'm going to create a random number based on how many accounts have the field filled in and have the random number be the selection of which user to pick.
<?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" => "example.com",
"author" => "TheCrzyDoctor",
"authorsite" => "example.com",
"version" => "1.0",
"guid" => "",
"codename" => "",
"compatibility" => "18*"
);
}
function otgs_install()
{
}
function otgs_is_installed()
{
}
function otgs_uninstall()
{
}
function otgs_activate()
{
}
function otgs_deactivate()
{
}
function randomstreamer_promotion($page){
// This is most likely completely all wrong (still reading up on how to do this..)
// pull text from custom field
$query = $db->simple_select("profilefields", "*", "name='TwitchAccount'");
$streamer_to_promote = $db->fetch_field($query))
$page = str_replace(
'<html>
<body>
<!-- Add a placeholder for the Twitch embed -->
<div id="twitch-embed"></div>
<!-- Load the Twitch embed script -->
<script src="https://embed.twitch.tv/embed/v1.js"></script>
<!-- Create a Twitch.Embed object that will render within the "twitch-embed" root element. -->
<script type="text/javascript">
new Twitch.Embed("twitch-embed", {
width: 854,
height: 480,
channel: $streamer_to_promote
});
</script>
</body>
</html>'
);
return $page;
}