Hacking LDM
From EIRMA Wiki
| Quick Links |
|---|
|
Overview and Tutorial |
|
Pre-Installation Installation Post-Installation |
|
Administration |
|
Moderation Design Advanced |
|
Other |
Contents |
Beware of Goblins!
LDM is written in php with some supporting Javascript and Flash ActionScript. It is quite large (some 20,000 lines of code) but remains modular in design, maintaining the principle of separation of layout and content, and using much of the standard vBulletin infrastructure. (An exercise for the happy programmer will be to rewrite LDM to a class-based design with a proper object-oriented approach to data management.)
LDM is distributed as a vBulletin product installer with supporting php scripts and image and language files and a wide range of optional 'extras'. Installation requires no changes to a standard vBulletin board, so the good folks at vBulletin.com will continue to help you. The installer handles upgrades from all previous versions.
The zip file that you download contains:
- A full set of development files in the development subdirectory:
- codes : the vBulletin installation and deinstallation routines
- phrases : phrase files in each supported language
- plugins : standard plugins required by the base product
- utility scripts : scripts used to rebuilt the product and vbAdvanced modules and to debug the code
- The release code and product installer in the release subdirectory
- Add-on extras in the extras subdirectory, and
- Translated phrase files in the translations directory
Renaming the PHP Scripts
As distributed, all php scripts have names that begin local_, and hence are normally accessed as using urls that end with these script names. There are two ways to modify these names:
- By using Apache's mod_rewrite, see Search Engine Optimisation
- By renaming the php files stored in the forums directory, for example changing local_links.php to downloads.php. If you choose this approach, also edit includes/local_links_defns.php. Find the following lines:
define('LINKS_SCRIPT', 'local_links');
define('ACTION_SCRIPT', 'local_links_actions');
define('ADMIN_SCRIPT', 'local_links_admin');
define('SEARCH_SCRIPT', 'local_links_search');
define('STREAM_SCRIPT', 'local_stream');
define('RESIZE_SCRIPT', 'local_resize');
Change each definition to reflect the new name of the corresponding script, e.g. if you have renamed local_links.php to downloads.php, modify the first line to read:
define('LINKS_SCRIPT', 'downloads');
Renaming the Database Tables
The standard installation of LDM create database tables with names that are also prefixed local_links. There is a hint in includes/local_links_init.php explaining how to change this prefix.
Warning - if you make this modification when you install LDM, remember to make the same changes whenever you upgrade. Otherwise, you will find yourself looking at an empty LDM database.
Rebuilding the Product File and the vbAdvanced Modules
vBulletin product installers for LDM are built using the build_ldm_product_modules.pl Perl script in the development/utilities branch of the release. The English version of the product file is written into the top of the release tree and other language versions into the translations directory.
The vbAdvanced modules are built using the stand-alone PHP script, build_ldm_vba_modules.php, also in the development/utilities directory.
Access to LDM Administration Commands
LDM restricts acccess to admininstration pages to members of the usergroups defined in the ADMIN_USER_GROUP setting in file includes/local_links_init.php. By default, ADMIN_USER_GROUP has the value 6, which is the standard vBulletin admininstrator usergroup. The check is performed against the user's extended group memberships, so any user who is a primary or secondary member of this usergroup will be allowed access.
To modify this setting, edit includes/local_links_init.php. ADMIN_USER_GROUP can either be set to one usergroup, e.g. 6, or to a list of usergroups, e.g. 5,6,7.
If you have several administrators for your main board but only want one of these to be able to administer LDM, create a new user group, give that user extended access rights to the new usergroup via the vb admincp, and set ADMIN_USER_GROUP accordingly.
Those LDM adminstration commands which handle major maintenance options, such as reinitialisating the LDM database, are further restricted to users defined as superadministrators in the site's vBulletin config.php file. This access can be modified using the admin_maintain extra, for example to limit access to a specific userid.
Plugins and Hooks
vBulletin hooks are scattered through the LDM code and listed in the includes/xml/hooks_ldm.xml, with fairly self-explanatory names. Most of the 'extras' (/release/extras) are written as plugins, so you can use these to get an idea of how things work.
Example: Hide LDM from unregistered users
Normally, you will use LDM's in-built access control mechanisms to limit what your users can see, do and access. If you want to completely block (e.g.) unregistered users from accessing LDM at all, create the following plugin, attached to the hook ldm_start
if ($vbulletin->userinfo['usergroupid'] <= 1) {
print_no_permission();
exit;
}
Consider also including a usergroup test on any menu items that point to LDM.
Example: Deliver .mp3 files as an .m3u file
Suppose your database contains a library of mp3 files. Rather than sending these files directly to your users, you want to download a one-line m3u file instead. (Why? - because some mp3 players do a better job of buffering and time shifting the media contents when given an m3u instead of an mp3.) This code does the job:
<?xml version="1.0" encoding="ISO-8859-1"?>
<plugins>
<plugin active="1" product="eirma_ldm">
<title>Change mp3 download into m3u download</title>
<hookname>ldm_download_begin</hookname>
<phpcode><![CDATA[
if (strtolower($type)=='mp3') {
@header("HTTP/1.1 200");
@header("Expires: 0");
@header("Cache-Control: private, post-check=0, pre-check=0, max-age=0");
@header("Pragma: no-cache"); // HTTP/1.0
@header("Content-disposition: inline; filename=\"".preg_replace("/mp3|MP3/", "m3u", $dfname)."\"");
@header("Content-type: audio/mpegurl");
echo create_full_url(STREAM_SCRIPT.".php?action=stream&linkid=".$linkid."&catid=".$catid);
exit;
}
]]></phpcode>
</plugin>
</plugins>
Plugins installed automatically
A number of standard LDM functions are handled using vBulletin plugins, so are installed and active by default:
- Patch Forum Home
- When a forum is set up as a link that points to a category in your LDM database, this plugin extends the forum display bit to provide information about the latest updates in the category.
- Style Fetch
- Loads the correct style when displaying an LDM category.
- Template Groups
- Consolidates LDM's templates in a single group in vBadmin/Styles & Templates/Style Manager/Edit Templates.
- Update Usernames
- Catches changes in usernames and updates the 'submitted by' information in LDM.
- What Viewed and My latest LDM entries
- summarises user's LDM activity within his profile when the admin enables profile_ldmactivity.
- Who's Online
- Extends vBulletin's Who's Online feature (Home page, What's Going On?, Currently Active Users) to display users who are viewing LDM pages.
Templates
LDM's templates are accessed as a single group (Links and Downloads) in VB Admin/Styles and Templates, and provided as a single file within the development/templates branch of the release.
The key linkbit templates are constructed within function ldm_get_entrybits() in the file includes/local_links_include.php. This is a lengthy and quite compex function, and it is easiest to look at the code to see which variables are used/available.
The main displays can use these templates to construct the display of each element:
- Modern (links_linkbit)
- The default linkbit based around nested fieldsets
- Tabular (links_linkbit_table)
- An obviously table-based linkbit
- Photo (links_linkbit_photo)
- An image-oriented linkbit
- Featured (links_linkbit_featured)
- Like the default linkbit, without the controls
- Bold (links_linkbit_greg)
- Bold
- Jukebox (links_linkbit_jukebox)
- Used for the short list of entries under the Jukebox
- Short (links_linkbit_short)
- Used for the abbreviated lists when categories are collapsed
The set of linkbits is then wrapped in a sequence which looks something like this:
links_header (header, including the standard VB header and navbar) links_main (main display page, or another template, as the case may be) links_footer (footer, including the standard VB footer)
Other key templates include:
- links_linkseparator
- separates groups of links with different values of display_order
- links_catbit
- builds individual category descriptions
- links_ratebit
- build link rating for use in links_linkbit
- links_othercatsbit
- build message for links in multiple categories
- links_search
- specify a search (only used on non-DHTML browsers)
- links_addnewcat
- add/edit category
- links_addnewlink
- add/edit link
- links_notify
- add/remove notification requests
- links_email_sent
- 'send to friend' email feature
- links_playbit
- main layout of Jukebox
Phrases
LDM's phrases are named ll_XXX or (for phrases used outside LDM itself, such as in vbAdvanced) ldm_XX. The phrase files are included in the development/phrases branch of the release.
LDM's mod_rewrite
A simplified version of Apache's mod_rewrite is included within LDM to modify entry urls at the point where the user selects a link. You may ask 'why bother?' The examples explain.
NB: This feature edits urls stored in the LDM database. It is *not* an all-purpose mod_rewrite engine for your site and it does not affect the command line urls that you enter into your browser or the urls that are used to access LDM. For those purposes, you need to use Apache. (See Search_Engine_Optimisation for information on how to configure LDM to work together with Apache to provide search engine friendly links.)
To use LDM's mod_rewrite feature, create and upload a text file containing your rewrite rules, then point the global setting mod_rewrite at this file. The usual rules apply concerning local_file_root, etc.
Rewrite rules reflect the standard Apache mod_rewrite format, except that only the RewriteRule directive and the NC/nocase flags are processed. In addition, there are two (non-standard) variables available: %{CATID} and %{LINKID}, with obvious meanings.
Each rule consists of a line defining the string to be trapped and its replacement.
RewriteRule regex1 regex2 [flag]
Mirroring urls
Suppose you have set up a library of files held on http://www.site1.com, which are mirrored on a second server http://www.site2.com. To switch temporarily from site1 to site2, install this rewrite file:
RewriteRule www.site1.com www.site2.com
Processing downloads through a separate web server
You are running two web servers on the same machine, one handling the vBulletin site on port 80 and the second handling file downloads on port 81, using the same part of the server file system. LDM is used to allow users to upload files into directory /downloads on http://www.site1.com/.
To force the downloads to be processed by the second server, install this rewrite file:
RewriteRule /downloads http://www.site2.com:81/downloads
and set force_redirect to 1.
Fixing the navbar in showthread
If you use LDM to create links to other parts of your forum, e.g. showthread.php?t=NN or ?p=PP for thread NN and post PP, you may want to fix showthread's navbar to refer to the LDM hierarchy rather than the normal forum/thread hierarchy.
To achieve this, enable mod_rewrite (see above), and install the <patch-showthread</tt> plugin and upload the accompanying rewrite.txt file. This uses the showthread_complete hook to catch situations where there is an additional 'catid=N' parameter as part of the url. showthread does not expect this parameter and ignores it. The plugin spots the parameter, looks up the original link's details and substitutes an LDM-based navbar.
RewriteRule (showthread.php.*)$ $1&catid=%{catid}
This will perform conversions on link urls such as the following:
LDM url: /forums/showthread.php?t=96 rewrite: /forums/showthread.php?t=96&catid=KK
when processed while the user is viewing category KK
Catch and redirect attempts to jump to 'forbidden' sites
You can use a rewrite file such as the following to prevent your users adding entries that point to certain urls.
RewriteRule .*/www.forbidden1.com.* http://mysite/warning.html RewriteRule .*/www.forbidden2.com.* http://mysite/warning.html RewriteRule .*/www.forbidden3.com.* http://mysite/warning.html

