Custom API: Current Page details

Collapse
X
 
Clear All
new posts
  • eolesen
    Senior Member
    • Mar 2023
    • 213
    • 5.7.5

    Custom API: Current Page details

    Using the custom API and some PHP for a display module....

    How can I get the current page's nodeID short of parsing out the URL via regex?

    Is there a $vbulletin->something['nodeid'] option or function I can invoke? Parsing was working fine until it started finding digits in the URL or channel name.....

  • Wayne Luke
    vBulletin Technical Support Lead
    • Aug 2000
    • 74652
    • 6.X

    #2
    The page controller should generate a $page object. It generates the inline Javascript of the page (in 6.0.3) so that jQuery has access to this information. You can pass this into your API. If that doesn't work, and you know the ID of the page, you can use the API function fetchPageByID(). You can look at /includes/vb5/frontend/controller/page.php to see how it sets things up.

    An example call is: $page = $api->callApi('page', 'fetchPageById', [$pageid, $arguments]);

    Note: in 6.0.4, the inline information will be added as HTML data attributes and not inline Javascript.
    Translations provided by Google.

    Wayne Luke
    The Rabid Badger - a vBulletin Cloud demonstration site.
    vBulletin 5 API

    Comment

    • eolesen
      Senior Member
      • Mar 2023
      • 213
      • 5.7.5

      #3
      I'll dig into that.

      Since node can be the channel, subchannel, reply or comment.... to clarify, I'm looking for whats now the 8 digit nodeID for the conversation that gets embedded into the friendly URL e.g. /23456789-topic-title-in-words

      Comment

      • Wayne Luke
        vBulletin Technical Support Lead
        • Aug 2000
        • 74652
        • 6.X

        #4
        That is the nodeid. It would be in the page object as $page['nodeid'];
        Translations provided by Google.

        Wayne Luke
        The Rabid Badger - a vBulletin Cloud demonstration site.
        vBulletin 5 API

        Comment

        • eolesen
          Senior Member
          • Mar 2023
          • 213
          • 5.7.5

          #5
          Yeah, it's not feeling the love in 5.7.6

          If I try to call the API as you show:
          An unexpected error was returned: 'Call to a member function callApi() on null'
          Last edited by eolesen; Wed 13 Mar '24, 2:09pm.

          Comment

          • eolesen
            Senior Member
            • Mar 2023
            • 213
            • 5.7.5

            #6
            OK, experimentation worked the 73rd time....

            Modified my localAPI to take an input variable:

            Code:
            public function conversation_banner($passed)
            {
            $nodeid = $passed;
            ....
            And modified the style template to pass the vb:var in the API call:

            Code:
            {vb:data result, localapi:banner, conversation_banner, {vb:var page.nodeid}}
            {vb:raw result.html}
            And it's working.

            Still wish there was an easier way to access the variables directly in PHP, but at least I can pass the variable for use rather than trying to set it in the template.

            Comment

            • Wayne Luke
              vBulletin Technical Support Lead
              • Aug 2000
              • 74652
              • 6.X

              #7
              Originally posted by eolesen
              OK, experimentation worked the 73rd time....
              Still wish there was an easier way to access the variables directly in PHP, but at least I can pass the variable for use rather than trying to set it in the template.
              Simple passing of variables worked in vBulletin 3.X and 4.X because almost everything ended up being in the Global space due to the coding style. However, this isn't a secure method of handling things and people could expose variables that shouldn't be exposed. I am glad you got it working for your needs.
              Translations provided by Google.

              Wayne Luke
              The Rabid Badger - a vBulletin Cloud demonstration site.
              vBulletin 5 API

              Comment

              • eolesen
                Senior Member
                • Mar 2023
                • 213
                • 5.7.5

                #8
                Nah, I get the insecurity of how PHP was integrated in 4.x and 5.6.3.

                Is there a reference as to what's available in the global space? I know the $vbulletin->userInfo[] elements are there, but what else? Feel free to PM if it's something you don't want exposed publicly.

                That said, there are still cases where we need to do some functions entirely outside the VB5 wrapper e.g. pages where we stream file output for downloads and need full control over the page headers. In those cases, I don't have access to the template variables and have to resort to reading and writing a cookie value.

                Comment

                Related Topics

                Collapse

                Working...