What is AMP?
https://www.ampproject.org/
Info
When Google announced AMP, I realized I'd eventually need AMP support for my vBulletin forum. After reading the AMP implementation docs, I decided to modify
printthread.php file since It only displays the basic elements and contents of a thread. So, you got the idea...
Implementation
- You will upload 1 file to forum root: amp.php
- You will edit /includes/class_bbcode.php and edit/replace a few lines.
- You will add two new templates, and edit a few.
- You will probably want to customize the <style amp-custom> CSS in ampthread template.
Demo
- Visit any thread from https://www.msxlabs.org homepage.
- Scroll down to footer; you will see the AMP link at the left bottom corner, click on it. It will open the AMP version of the thread.
- The link is there for quick access to AMP version of a thread, It is not mandatory, nor It is used by AMP recognation.
Installation
- Download and extract the ZIP file.
- Upload the amp.php file to your forum root folder (same folder with showthread.php)
- Add a new template called "ampthread" and copy the template content from ampthread_template.txt file.
- Add a new template called "ampthreadbit" and copy the template content from ampthreadbit_template.txt file.
- Edit your bbcode_quote template and replace It's content with bbcode_quote.txt file's.
- Edit includes/class_bbcode.php, find:
PHP Code:
if ($do_imgcode AND ($this->registry->userinfo['userid'] == 0 OR $this->registry->userinfo['showimages']))
replace with:
PHP Code:
if ($do_imgcode AND ($this->registry->userinfo['userid'] == 0 OR $this->registry->userinfo['showimages']) OR THIS_SCRIPT == 'amp') //amp hack
find:
PHP Code:
return '<img src="' . $link . '" border="0" alt="" />';
replace with:
Code:
if (THIS_SCRIPT == 'amp') { return '<amp-img layout="responsive" src="' . $link . '" width="300" height="250" alt=""></amp-img>';} else { return '<img src="' . $link . '" border="0" alt="" />'; } //amp hack
- Save and upload class_bbcode.php (overwrite).
- Edit SHOWTHREAD template and add
Code:
<link rel="amphtml" href="http://www.vbulletin.com/amp.php?t=$threadid<if condition="$pagenumber>1">&page=$pagenumber</if>" />
before </head>. Don't forget to change "yourforum.com" URL with yours.
- Edit ampthread template and change "vbulletin.com" with your forum URL:
Code:
<link rel="canonical" href="http://www.vbulletin.com/showthread.php?t=$threadinfo[threadid]<if condition="$pagenumber>1">&page=$pagenumber</if>" />
- You will find some comments in amp.php and ampthread template; modify them according to your needs (optional).
Notes
I installed a fresh vBulletin 3.8 to my localhost and tested this mod. It should work just fine unless your vBulletin is highly modified. If you get validation errors, I believe you can fix them by looking at the examples (comments).
Does it work?
- Open a thread from your forum.
- Replace the "showthread.php" with "amp.php" in the address bar, hit enter.
- Add "#development=1" at the end of the URL and refresh the page.
- Open Chrome DevTools, check the console log, it should say "AMP validation successful."
Screenshots
Credits
Accelerated Mobile Pages for vBulletin 3.8 is created by NeutralizeR from https://www.msxlabs.org