Plugins, Hooks And Components In Php?

Discussion in 'PHP' started by Blaxus, Feb 3, 2013.

  1. #1
    I am building a PHP component that I intend on reusing. A Forum system. In this particular case. I want to display Profile information on the post page (much like you see here, username / avatar etc.)

    The Forum Component is independent of a login system. If I could somehow make a simple plugin system... register the plugin, it basically should allow modification of a certain placeholder perhaps? I also want that mutliple plugins can modify the same spot, to allow users to add new functionality. Perhaps they want to display karma or some other custom content like userbars, groups, website links etc. you name it.

    I already know basically how to make a plugin or basic hook system. What I'm wondering however, is how should I implement it.

    Because it all boils down to how far down below do I want to take it. If you don't understand I'll give you an example:

    PHPBB, MyBB, VBulletin etc, are all Fully Fledged Web Solutions. They feature their own Login System etc. as opposed to a complete PHP Class for forum interaction. (the latter requires a lot of work regarding implementation).

    I'm looking somewhere in between, but i'm asking regarding on how far to take it. Should I have this compontent spit out a semi-full page? Or should it just handle all the grunt work and spit out placeholders (or variables) for me to style (echo) later?

    What does this all have to do with plugins and hooks? A lot, because they will allow me to modify the behaviour of this component, and I'm not sure how to go about it.

    Ideas please?
     
    Last edited: Feb 3, 2013
    Blaxus, Feb 3, 2013 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,898
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Your questions raise plenty more questions.
    • Why are you creating this system - will you be selling it or will it only ever be used once?
    • If you are selling it will it be encrypted or will you be encouraging others to write their own plugins?
    • How much time have you budgeted to put into the system - implementing a useful hook system may cost you more hours than you can recoup
     
    sarahk, Feb 3, 2013 IP
  3. Blaxus

    Blaxus Active Member

    Messages:
    23
    Likes Received:
    2
    Best Answers:
    2
    Trophy Points:
    78
    #3
    Why are you creating this system - will you be selling it or will it only ever be used once?
    To answer that unanswered question in between, I will not sell it. The goal it create a Component that can be used to more easily create a Forum whenever I create a website and integrate this forum within said website.

    If you are selling it will it be encrypted or will you be encouraging others to write their own plugins?
    No encryption nonse, that only gives more complications for people who don't have encryption enabled on their servers. I don't know about encouraging people to write their own plugins. But the idea is that I want it to make my system a little more flexible and decoupled.

    Currently the problem I am trying to solve is the fact that a small portion of the page known as "post.php?id=*" has to somehow be modified to show information that is not actually part of the system. So I need to show Profile information, how am I going to do that if the profile system is not part of the forum?

    How much time have you budgeted to put into the system - implementing a useful hook system may cost you more hours than you can recoup.

    Interesting question, but don't think it applies here. It's not a business thing. I'm simply trying to solve a problem here, that's all that matters. And I have a lot of time to do it in.

    Currently I have spent some time creating a basic system, but I am wondering how I could make it so that I don't have to build a Login System. I would say, as barebones as possible.

    Here's the code of the page that I'm talking about.
    <?php
     
    # Each of the views are available through this interface.
    class ForumInterface extends Permissions
    {
     
        function topic( $id )
        {
            global $permission;
     
            if( $permission->verify('view_topic') )
            {
                # Fetch Thread
                $query = bindParams("SELECT * FROM ".TABLE_PREFIX."threads WHERE id = ?", array($id));
                $query = mysql_query($query)or die(mysql_error());
       
                $thread = mysql_fetch_object($query);
       
                $query2 = bindParams("SELECT * FROM ".TABLE_PREFIX."posts WHERE thread = ? ORDER BY timestamp ASC", array($id));
                $query2 = mysql_query($query2)or die(mysql_error());
       
                echo '<div class="titel">'.htmlspecialchars($thread->title).'</div><!-- post -->';
       
                /**
                * Mockup Example of Users
                * for testing purposes.
                */
                $users[1]['name']      = 'Blaxus';
                $users[1]['ondertitel'] = 'Elite Member';
                $users[1]['role']      = 'Administrator';
                $users[1]['profile']    = 'https://en.gravatar.com/blaxus1';
                $users[1]['signature']  = 'I am the Webmaster here.';
                $users[1]['avatar']    = 'http://i44.photobucket.com/albums/f43/spwn/Avatars/15010-1.gif';
       
                $users[2]['name']      = 'Darkhawk';
                $users[2]['ondertitel'] = 'Freelancer';
                $users[2]['role']      = 'Member';
                $users[2]['profile']    = 'https://en.gravatar.com/blaxus1';
                $users[2]['signature']  = "I know everything, I just can't remember it all at once.";
                $users[2]['avatar']    = 'http://i44.photobucket.com/albums/f43/spwn/Avatars/1.png';
       
                $users[3]['name']      = 'Vendetta';
                $users[3]['ondertitel'] = 'Freedom Fighter';
                $users[3]['role']      = 'Moderator';
                $users[3]['profile']    = 'https://en.gravatar.com/blaxus1';
                $users[3]['signature']  = "If you're looking for the guilty, You need only into a mirror.";
                $users[3]['avatar']    = 'http://i44.photobucket.com/albums/f43/spwn/Avatars/v2.png';
       
                $users[4]['name']      = 'Kenshin';
                $users[4]['ondertitel'] = 'Ex-Samurai';
                $users[4]['role']      = 'Honored';
                $users[4]['profile']    = 'https://en.gravatar.com/blaxus1';
                $users[4]['signature']  = "If you're looking for the guilty, You need only into a mirror.";
                $users[4]['avatar']    = 'http://i44.photobucket.com/albums/f43/spwn/Avatars/14974.gif';
       
                /**
                * Mockup Colors
                */
                $color['Member']        = '#000000';
                $color['Honored']      = '#4373ff';
                $color['Moderator']    = 'Green';
                $color['SuperModerator']= 'Navy';
                $color['Administrator'] = 'DarkRed';
       
                # Fetch Posts
                while( $post = mysql_fetch_object($query2))
                {
                    $pId      = htmlspecialchars($post->id);
                    $pAuthor  = htmlspecialchars($post->uid);
                    $pThread  = htmlspecialchars($post->thread);
                    $pMessage = htmlspecialchars($post->message);
                    $pDate    = new DateTime($post->timestamp);
           
                    $user = $users[$pAuthor];
           
                    echo '<div class="bericht2">
                            <table cellpadding="0" cellspacing="0" border="0" width="98%">
                                <tr>
                                    <td width="25%" valign="top">
                                        <p><strong><a href="'.$user['profile'].'"><font color="'.$color[$user['role']].'">'.$user['name'].'</font></a></strong><br />
                                        '.$user['ondertitel'].'</p>
                                        <img src="'.$user['avatar'].'" width="100" height="100"><br />
                                        <br />
                                        <a href="?pagina=leden/mailen&id=1"><img src="assets/img/mail.gif" border="0" title="E-mail"></a>
                                        <img src="assets/img/offline.gif" title="Offline"><br />
                                        <br />
                                    </td>
                                    <td width="75%" valign="top">
                                    <p>'.bbcode($pMessage).'</p>
                                    _______________________________<br />
                                    '.$user['signature'].'
                                    </td>
                                </tr>
                                </table>
                            </div>
                            <div class="foot">
                                <table cellpadding="0" cellspacing="0" border="0" width="98%">
                                    <tr>
                                        <td><strong>Datum:</strong> '.$pDate->format(FORMAT_DATE).'</td>
                                        <td align="right"> Reageren | Quote | Bewerken</td>
                                    </tr>
                                </table>
                            </div>';
                }
       
                echo '<!-- post -->';
            }
        }
    }
    PHP:
    and then used like so:
    <?php
    include('ForumInterface.php');
    $view = new ForumInterface;
     
    # Custom Login System will change this behaviour
    $permission = new Permissions;
    $permission->allow('view_topic');
     
    $id = (!empty($_GET['id'])) ? $_GET['id'] : 1;
    $view->topic( $id );
    PHP:
    Ignore the fact that it's echo'd out. This is just a test version. I was running some mockups on how to implement this, I also have a Twig version of this, and a Str_replace (oldschool template system) but this is just simpler to see how it works.

    Currently, the profile system (users) is a mockup. I could of course build a custom MySQL thing that would pull the information from some table, but since it's not part of the system it would allow me to only show the information I code into it. So I would have to come back and re-add new stuff everytime. I don't want to do that.

    What would be a good way to allow people to basically change the way this piece of code behaves?
     
    Last edited: Feb 4, 2013
    Blaxus, Feb 4, 2013 IP
  4. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #4
    Hi, i have no idea how to help you but couldn't help my selve. You are using dutch and english in your code 'ondertitel'? lol shouldn't that be signature or something?

    Will be watching this topic as i find this very interesting! :)
     
    EricBruggema, Feb 4, 2013 IP
  5. Blaxus

    Blaxus Active Member

    Messages:
    23
    Likes Received:
    2
    Best Answers:
    2
    Trophy Points:
    78
    #5
    I thought it was finally time to let WebmasterCity / WMCity behind me. Anyway, technically you are right, Ondertitel is sort of a Signature type deal. The difference however is the locaction and the amount of characters allowed.

    Ondertitel would go somewhere like where you would see Member/Administrator/Active Member etc. You can't fit images and a whole bunch of random crap in there so it's more likely to just be a "status" or "mood" thingy.

    I like it because it allows people to sort of differantiate themselves, apart from the obvious avatars of course. It's like sort of describing how you feel or the way you present yourself in one word.

    Anyway, I have been thinking about it. I know I will figure it out. But I'm just thinking out loud.
    You never know when someone says something that lights up your bulb :D
     
    Last edited: Feb 4, 2013
    Blaxus, Feb 4, 2013 IP