Announcement

Collapse
No announcement yet.

Including Custom PHP in Modules.

Collapse
X
Collapse
  •  

  • Including Custom PHP in Modules.

    We've created a new package that is intended to facilitate the replacement of custom PHP modules with custom Display Template modules. It also demonstrates how to create custom API functions in general. You will find this package attached below.

    Steps to replace a PHP module Module

    Edit the api/main.php file

    1. Find the customWidgetHtml function
    2. Copy your php code from the module into the function.
    3. Change the code to generate a string value instead of echoing content and set that to the $myhtml parameter.

    If you have more than one PHP module you can copy the function, give it a new name, and copy/edit the code above for each module.

    1. Upload this package directory into core/packages

    Create a custom template

    1. Go to the style editor in the admincp and select add a new template for the site style you are using.
    2. Give it a name like 'customtemplatemodule'
    3. copy the following into the template changing the name to match the function name(s) in the api/main.php:
    Code:
    {vb:data result, localapi:main, customWidgetHtml}
    {vb:raw result.html}
    1. Do this for each PHP module you are replacing.

    Adding Your Code to a Page

    1. Go to sitebuilder.
    2. Edit the page that you want to display the module on.
    3. Add a "Display Template" Module to replace the PHP Module
    4. Set the template name to 'customtemplatemodule' or whatever you named your new template.
    5. Remove the old PHP module template
    6. Save the Page.

    Note you can return html and display it from the API in this way. It's the quickest and easiest way of porting from an existing PHP module to a Template module. But it isn't necesarily the best way. The API functions are intended to return data that can be inserted into the markup in the templates. And alternative example is provided in the sample class. You can uncomment the function if you want to try it out. The template to use this to provide the same result as the sample html return is:

    Code:
    {vb:data result, localapi:main, dataOnly}
    <p>{vb:var result.hello}</p><p></b>{vb:var result.hellobold}</b></p>

    As above save that as a custom template and create a Display Template Module that uses it.

    Attached Files
    Last edited by Wayne Luke; Fri 14 Aug '20, 12:53pm.

    • Wayne Luke
      #4
      Wayne Luke commented
      Editing a comment
      1. Fixed the text above. I am sorry, this due to calling things Module on the front end and Widget on the back. Even though they mean the same thing. It was an overzealous find and replace that changed the function name.

      2. For this function, you want to return a string in the $myhtml variety. You'll have to adjust to make your code fit. This is working with the example code provided.

      3. Whatever your custom code is. I can't know what you're trying to do.

    • NumNum
      #5
      NumNum commented
      Editing a comment
      Thank you for clarifying.

      I'm trying to move my jssor photo banner that was using the php module. So I'm not sure where to place the code from the index page that points to the picture titles and the directory, and for the <script src="js/jssor.slider-28.0.0.min.js" .

      What I don't understand is returning a string in the $myhtml variety, and the instructions in step 3. I think its the terminolgy I am not used to.

      I did load the sample to see if I could make sense of it all and I get an error "Failed to create API controller." (should I post this in the support forums?)

    • Wayne Luke
      #6
      Wayne Luke commented
      Editing a comment
      I have no idea what jssor is. You'll need to open a proper support topic with code examples and what you're trying to do so I can help you.

      $myhtml is a PHP Variable that contains a string. Instead of using echo "some string of text"; in a PHP module, you assign it to a variable - $myhtml="some string of text": Then you output that variable in the template. You can use any variable name. This is just an example. Without knowing what you're trying to do with concrete code examples, all I can do is give examples. This is the most basic example known to programming. Literally the equivalent of writing a program that outputs "Hello World" on the screen.

      Knowledge of PHP is a requirement for this kind of work. Really you shouldn't need any PHP to add javascript to the page. You can just include your file in the head_include template and it will be on every page. Then you would use HTML modules to display whatever javascript you want to display.
    Posting comments is disabled.

About the Author

Collapse

Wayne Luke A curious juxtaposition of nature, technology and sustainability. Find out more about Wayne Luke

Article Tags

Collapse

beginner (3) calendar (1) channels (1) connect (1) Custom (1) database (1) Google (1) howto (1) https (1) Intermediate (2) MYSQL (1) options (1) passwords (1) security (2) seo (1) sftp (1) site builder (1) ssl (1) ssl certificate (1) style (1) styles (1) tutorial (2) users (1) vb5howto (5) vbcloud (1)

Latest Articles

Collapse

  • Including Custom PHP in Modules.
    by Wayne Luke
    We've created a new package that is intended to facilitate the replacement of custom PHP modules with custom Display Template modules. It also demonstrates how to create custom API functions in general. You will find this package attached below. Steps to replace a PHP module Module Edit the api/main.php file Find the customWidgetHtml function Copy your php code from the module into the function. Change the code to generate a string value instead of echoing content and set that to the $myhtml par...
    Mon 10 Aug '20, 3:05pm
  • vBulletin Password Handling
    by Wayne Luke
    Note: vBulletin Cloud sites cannot use custom password schemes at this time. The core security of your site is the User Password and how it is stored. In the beginning, vBulletin used a simple MD5 hash to represent the password. However as Floating Point Processors (i.e. GPU and ASICs) have become more powerful, this method proved to be risky and reduced security. If we significantly changed the password scheme, then users wouldn't be able to login and would need to change their passwords fir...
    Sat 27 Oct '18, 1:34pm
  • Creating the Sitemap XML for your vBulletin
    by Wayne Luke
    The XML Sitemap specification allows search engines to index your site more efficiently. vBulletin 5 Connect can create the Sitemap automatically so you can submit it to your favorite search engines. Using the default path If you are using vBulletin Cloud, you must use this option. The default value for this is core/store_sitemap. Make sure the directory is CHMOD 0777 on your server. In the AdminCP, go to Settings -> Options -> XML Sitemap and set Enable Automatic Sitemap Generation to Yes. ...
    Sat 27 Oct '18, 1:18pm
Working...
X