Announcement

Collapse
No announcement yet.

plugin system in my own scripts

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • plugin system in my own scripts

    I would like to add a plug-in system in my own scripts (not a hack for vbulletin).
    Since the developers know how to do it I thought I'd ask here.

  • #2
    It's fairly straightforward. In a very generalized overview:

    1) Setup a database table to store the hook locations and PHP code
    2) Write a fetch_hook() function to get the PHP code from the database for the given hook name
    3) At strategic places through your code, add a hook call. Something like:

    PHP Code:
    ($hook fetch_hook('my_hook_location')) ? eval($hook) : false
    What that's saying is:

    Code:
    If fetch_hook('my_hook_location') returns something other than false, then exec(), otherwise, do nothing
    vBulletins hook system is a little more in-depth, but that's pretty much all you should need to add a small hook system.

    Comment


    • #3
      So for the function I would write
      PHP Code:
      function fetch_hook($hook_name)
      {
        
      $gethook mysql_query("SELECT * FROM hook 
        WHERE hook_name ='
      $hook_name' ");
        
      $hook mysql_fetch_array($gethook);

      Comment


      • #4
        In that function, you'll need to add a check to see if $hook contains anything, and if so, return it. other wise return false.

        Something like:

        PHP Code:
        function fetch_hook($hook_name)
        {
          
        $gethook mysql_query("SELECT * FROM hook 
          WHERE hook_name ='
        $hook_name' ");

          
        $hook mysql_fetch_array($gethook);

          if (
        count($hook) > 0)
          {
             return 
        $hook;
          }

          return 
        false;


        Comment


        • #5
          Well I was close.

          Thank you, I'm going to start coding.

          Comment


          • #6
            Well you need to add $hook = $hook2['code'];

            PHP Code:
            function fetch_hook($hook_name)
            {
              
            $gethook mysql_query("SELECT * FROM hooks 
              WHERE hook_name ='
            $hook_name' ");

              
            $hook2 mysql_fetch_array($gethook);
              
              
            $hook $hook2['code'];
              
              if (
            count($hook2) > 0)
              {
                  
                 return 
            $hook;
              }

              return 
            false;


            Thanks for the help.

            Comment


            • #7
              I need help on this.

              I am using a hook in a switch statements like so..
              PHP Code:
              switch ($_GET['act'])
              {
                  case 
              "test":
                  echo 
              "test";
                  break;    
                  (
              $hook fetch_hook('rpg_login_case')) ? eval($hook) : false;
                  default:
                  
              index();

              In the database I have
              PHP Code:
              case "test2":
              echo 
              "test2";
              break; 
              So now the switch should look like....
              PHP Code:
              case "test":
              echo 
              "test";
              break;    
              case 
              "test2":
              echo 
              "test2";
              break;
              default:
              index(); 
              I would think I could use script.php?act=test2 but it doesn't work.

              After doing this I realized that I could do it a complelety different way but I want to solve this if possible.

              Comment


              • #8
                A hook is not an include of source code, but it executes the code in the hook in this place. You can not use hooks to add options to a switch statement.
                Want to take your board beyond the standard vBulletin features?
                Visit the official Member to Member support site for vBulletin Modifications: www.vbulletin.org

                Comment


                • #9
                  So I guess hooks can only be used for variables and outputting text (echo)
                  As I said I realized this can be done a completely different way.
                  I guess I was so caught up in these hooks to see it.

                  Comment


                  • #10
                    You can put statements that are executable by itself in hooks, so execute queries, fill variables. But they can not be used as 'replacement text' in source code. They must be standalone statements.
                    Want to take your board beyond the standard vBulletin features?
                    Visit the official Member to Member support site for vBulletin Modifications: www.vbulletin.org

                    Comment

                    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                    Working...
                    X