MOD: How-to define number of Titles displayed determined on device typeEdited 16oct12 15:48 PT using suggestions from FredLooks
First .. disclaimer .. I really like phpDVDProfiler. It is a great hack and so far it appears to be very well supported by community and by FredLooks. This is just an extension that I wanted and thought I would share. But please .. this requires a change to your phpDVDProfiler's
localsiteconfig.php file. Be sure to back it up before proceeding. If you have problems I will be happy to try and help. Also if you have any suggestions please let me know. Although I have done a lot of php programming .. it has been several years/releases ago .. but my ego isn't fragile
The OpportunityI didn't like just setting the $TitlesPerPage to a specific number because I might access the site from my phone or tablet or computer (desktop and laptop).
So to speed up the retrieval times for phone and tablet I wanted this value to be set according to device type.
I found a class called "Mobil-Detect" and it's home page is located
here. Installation is pretty simple and there is a demo program available also. I would suggest that you install the demo program so you can be sure that it all working before making any change to phpDVDProfiler.
My Installation Steps for Mobile-Detect:- Create Directory - i created a directory called MobileDetect in the 'htdocs' folder (on my system it is www).
- Go to the Mobil_Detect.php source page found here. Note: if that link doesn't work then bring up the 'home' page noted above as 'here' and look for the source. Else let me know.
- This will bring up another page with all the source. Then click the button RAW at the top right of the page. This will bring the source up in another window .. better for our purposes
- Once the window is open press Ctrl-A (on windows) to select all the source.
- Once the source is all highlighted then press Ctrl-C (on windows) to copy the source to the clipboard
- Open a text editor (notepad will do). Don't use word or any program that formats.
- On a blank page (new text file) press Ctrl-V (on windows) to paste the clipboard to the document.
- Save the file as Mobile-Detect.php in the newly created folder (step 1)
- Exit your editor
Installation Steps for Mobile-Detect's Demo program- Go to the Demo.php source page found here. Note: if that link doesn't work then bring up the 'home' page noted above as 'here' and look for the source. Else let me know.
- This will bring up another page with all the source. Then click the button RAW at the top right of the page. This will bring the source up in another window .. better for our purposes
- Once the window is open press Ctrl-A (on windows) to select all the source.
- Once the source is all highlighted then press Ctrl-C (on windows) to copy the source to the clipboard
- Open a text editor (notepad will do). Don't use word or any program that formats.
- On a blank page (new text file) press Ctrl-V (on windows) to paste the clipboard to the document.
- Save the file as test-Mobile-Detect.php in your 'htdocs' folder (in my environment it is www)
- NOW before exiting your editor we need to make a small change to the demo file. In your editor do a FIND (in notepad it is Ctrl-F) and search for "require_once" (without the double quotes). The line found should be "require_once 'Mobile_Detect.php';"
- Change the "'Mobile_Detect.php'" part to "'/MobileDetect/Mobile_Detect.php'" (without the double quotes). It should now read
require_once '/MobileDetect/Mobile_Detect.php';
- Now after reviewing you change .. save the text file.
- Exit your text editor
If you are playing with the demo (and you should!) you should be able to simply enter "localhost/test-mobile-detect.php" into your browsers address bar. If you are not working on the webserver then replace "localhost" with the address of your server.
Okay .. Changes required to phpDVDProfiler to make this all workIf you have an existing
localsiteconfig.php in the phpDVDProfiler directory. If you don't have this file .. the easiest thing to do is so simply copy the
siteconfig.php file to the
localsiteconfig.php file in the phpdvdprofiler folder.
FredLooks has suggested that any setup/configuration information should be made to the
localsiteconfig.php and not to the
siteconfig.php file, as the
siteconfig.php file maybe/will be overwritten by updates to phpDVDProfiler. For this reason all 'local site specific' information should reside in the
localsiteconfig.php. This is also where we will be putting our code for the Mobile-Detect mod.
Once you have the
localsiteconfig.php file you will need to add the following code at the end of the file, before the line with "?>".
<?php
// 16Oct12 - dsig - added Mobile Detect function so can tell size to display
require_once("../MobileDetect/Mobile_Detect.php");
$detect = new Mobile_Detect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
// set according to 'type'
switch ($deviceType) {
case "tablet":
// this is the number of titles to load/display if a tablet device
$TitlesPerPage = 60;
break;
case "phone":
// this is the number of titles to load/display if a phone device
$TitlesPerPage = 40;
break;
case "computer":
// this is the number of titles to load/display if a computer device
$TitlesPerPage = 0;
break;
}
?>
NOTE: Be sure to get all the code. Sometimes the 'code window' will have a slider ..
Does it work?If the demo worked .. and if you pasted this code in correctly .. you should now be able to access phpDVDProfiler from any of the devices and have only that number of titles appear.
IMPORTANT: These instructions expect that the folder structure is as defined. So for any system, the 'htdocs' folder (folder where all the web pages go (including subfolders) is the 'root' folder. In this folder you should see phpdvdprofiler. This is the directory where you create the new folder MobileDetect.
If you have any problems or suggestions please let me know.