We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23072
    • 150 Posts
    Well I started off with a bit of a white lie there as it’s not integration, rather getting access tothe MyBB core via a Snippet.

    I’m running into a bit of trouble getting it to work inside a snippet, despite stripping down my code to the bare minimum.

    I started by putting the following into a PHP file to test it worked:

    <?php
    
    // We're not in MyBB, but we have to define this or nothing will work.
    define("IN_MYBB", 0);
    
    // Grab the global file. This will kick absolutely everything off for us.
    require "path/to/mybb/global.php";
    
    // Let's see what we've just got then...
    var_dump($mybb);
    ?>


    If you did a normal install of MyBB and put the above code in a PHP file and called it as usual, it’d basically return a lot of stuff including your current member details and give you access to the whole of the MyBB system. With that information you can do some lovely integration - the following site of mine grabs news from the forums, events from the forum calendar, stats, online members and so forth: http://www.theturtlemoves.com

    Unfortunately, when you put the above code in a snippet, it gives an error as follows:

    Fatal error: Call to a member function simple_select() on a non-object in /home/acronym/public_html/mybb/inc/class_datacache.php on line 42

    So, any ideas why identical code woeks outside MODx and not inside?

    I’m pretty sure something’s conflicting somewhere along the line. I can circumvent the above error with a lot of fiddling by not loading some MyBB stuff, but I then run into almost identical errors elsewhere.


    My goal is, once I can understand and get around this block, to create similar snippets to grab data from MyTopix and IPB 2.x. I know all three pieces of software pretty well, but not MODx wink

    I wonder if there’s a way to run the above code before MODx even starts doing anything and return the gathered information via a snippet?

    Any advice would be greatly appreciated.
      Notanotherdotcom Ltd

      Web | Print | Marketing
      • 22303 MODX Staff
      • 10,725 Posts
      That’s likely because the snippet code is being eval()’d and does not have full access to the same variable scope. You might try just including an external file with that code in it as your snippet.
        • 23072
        • 150 Posts
        Unfortunately that didn’t work either. Thanks for the suggestion and a possible reason why though - although I know my way around PHP a bit, things like variable scope and so on still give me headaches wink

        It looks like the only way this particular one is going to work is by grabbing all the data long before MODx tries to display the page and making just the results available to a snippet.

        Any thoughts on how to achieve this? I did start looking at Plugins, but wasn’t sure if that was the way forward.
          Notanotherdotcom Ltd

          Web | Print | Marketing
          • 23072
          • 150 Posts
          Never mind. I’d just woken up when I posted the above.

          Declaring some gloabl variables is getting me a lot further. I’d just forgotten globals existed at midnight last night wink

          Thanks again, will keep folks posted smiley


          UPDATE

          Well that seemed to do the trick. I can now tap into MyBB’s functions and my own custom functions so the following info can be used in MODx snippets for MyBB:

          * Last X forum topics (useful for grabing news - parses smilies and images etc)
          * Your member data - unread posts and topics, unread PM’s, your name etc
          * Last X posts (in the form of topic title, date and a link)
          * Next X events (grabbed from the calendar - the next X upcoming events)

          I’ve still got a lot of work to do with regards to templating, but I’m confident that once I get this one out the door, MyTopix won’t be far behind and then I can tackle the tricky one - IPB 2.x. I think that’s my lot after that - I don’t like phpBB or vB enough to even go there I’m afraid laugh



          The down-side to this is that I have no idea how many extra queries are being run. However, if you don’t use a function, that’s a few less queries wink

          The up-side is that because I’m only initialising the forum’s core and using it’s functions for tha majority of the above, unless they do a major rewrite I won’t need to update my code for each minor patch they release.


          I also intend to try something quite creative with the news grabbing - getting the news content and dumping the output as regular HTML straight into a MODx page, then when someone views the page, checking the page creation date against the database for new news before doing it again. This way the news page can be cached and save on a pretty complex query, though it does admittedly have to do a quick simple one to check for new news. In the long run it could save a lot of wear and tear on the server.

          At least this way visitors will be viewing a cached news page the majority of the time... if I get it to work alright wink


          Another Update

          You’ll also be able to call on the snippet multiple times on the same page/in the same template without initialising the MyBB code more than once. Since my website mentioned earlier calls on this set of functions four times on the homepage alone, this is quite a good thing.


          Can anyone tell I’m getting excited now? wink
            Notanotherdotcom Ltd

            Web | Print | Marketing
            • 23072
            • 150 Posts
            Okay, well my MyBB function "integration" is nearly complete.

            Giving myself a lot to learn in one day, I’ve done the following and made chunks for various parts so it can all be easily be re-styled to suit:



            The news headlines are forum topics being grabbed from MyBB. I’ve only got the basic info up for now, but other varibales you can have are number of comments, who posted it, last reply... basically there’s a lot.

            On the right, there’s a user menu for logged in and logged out users. The snippet I’m writing works out whether you’re logged into the forums or not and displays the associated chunk and data.

            Beneath the user info, there’s "Site Statistics", which is really just the latest forum stats, but you could easily add things like number of MODx pages if you were so inclined.

            Finally, beneath that is the Online Users section detailing... well, you get the idea wink

            I’m probably going to take a breather at this point, get my website - Acronymity.co.uk (a website for me to ramble and create snippets on) themed and then release this snippet.
              Notanotherdotcom Ltd

              Web | Print | Marketing
              • 23072
              • 150 Posts
              Well I’m not sure why I’m keepign some sort of ongoingdiary here, but that’s what it’s turning into.

              The MyBB Bolt-On seems fairly stable, but there’s definitely still parts to improve on.

              I’ve been a little sidetracked, but I’ve begun having a go at the IPB forum version of this bolt-on. The bit I love about MODx is that anything’s possible, and... well... I’ll let the links below speak for themselves:

              Firstly, this is the original news page - articles dragged and parsed from the forum database:
              http://www.strategycore.co.uk/

              Next, using the beginnings of my IPB bolt-on, is the MODx version:
              http://www.strategycore.co.uk/modx/ipb-topics.html

              It’s not much to look at yet, but as you can see it’s displaying the news articles almost identically.

              The downside is that this method can get a bit slow. In both examples the page takes a while to render, as both systems battle to extract the last fifteen posts from across four specified forums.

              My next step with this one is to use the MODx page publish date, and the dbAPI to save the HMTL output directly to a MODx page, and run ONE query on page-load to check for topics from those forums that have a newer post date than the page’s publish date.

              This should also allow the dumped HTML content to be searchable too smiley
                Notanotherdotcom Ltd

                Web | Print | Marketing
                • 6726
                • 7,075 Posts
                I started toying with MyBB and I must say, I am pretty impressed with it so far... it’s faster than SMF, and feature wise it’s quite complete !
                The thing I am not yet sure about is the licence aspect of it, I’ll dig into that...

                And now I’ll try the MyBB Bolt-on snippet smiley
                  .: COO - Commerce Guys - Community Driven Innovation :.


                  MODx est l&#39;outil id