Random Image
My Account

lgLib Plugin

Provides a central repository for custom functions, javascript and CSS used by other plugins. This ensures that the Javascript and CSS are loaded only once to prevent problems with duplicate JS classes.


  • glFusion v1.6.0 or newer
  • PHP 5.6 or newer


This plugin uses the glFusion automated plugin installer. Simply upload the distribtuion using the glFusion plugin installer located in the Plugin Administration page.

The plugin may be installed manually, if necessary.


The upgrade process is identical to the installation process, simply upload the distribution from the Plugin Administration page.


Provides commonly-used Javascript and PHP functions

  • Calendar (DHTML calendar from dynarch.com)
  • Slimbox, to allow flipping between images without the timer used by MediaGallery
  • Color picker, currently used only by the Classifieds plugin


Nearly all of the functions of lgLib are transparent to the administrator and site visitor, except for enabling popup messages.

The messaging function allows plugins to store messages for a user or session that can be displayed during a subsequent visit. For example, the Membership plugin uses this facility to add a message during user creation so that the user will be invited to join the organization after their first login.


LGLIB_getDocURL($file=“”, $pi_name=“lglib”, $doclang=“english”)

Gets the URL to a plugin's configuration help file, or other documentation file found under public_html/<plugin>/doc/<language>


LGLIB_invokeService($type, $action, $args, &$output, &$svc_msg)

This invokes a service function in another plugin, if available. It is identical to the standard PLG_invokeService() function, except this version does not require enabling web services.


LGLIB_storeMessage($args, $title=“”, $persist=false, $expires = “”, $pi_code = “”, $uid = 0, $use_sess_id = true)

Stores a text message in the database for a plugin. This allows messages to be created asynchronously and not require an immediate page refresh. Any type of text message can be stored.

  • $args - Either the text message, or an array containing 'message' plus any or all of the remaining options.
  • title - Message title to display
  • persist - True to keep the message and redisplay it until it is deleted, False to delete after the first viewing
  • expires - Messages will be deleted after this date whether they have been viewed or not. For anonymous users the default is 4 hours from creation, for logged-in uses the default is 12/31/2037.
  • pi_code - The plugin creating the message. Plugins can delete their own messages.
  • uid - The user ID that should see the message.
  • use_sess_id - True to use the session ID to retrieve messages. This allows messages stored for anonymous users to be displayed after the user logs in.


Retrieves all the messages for the current user. Called by LGLIB_showAllMessages().

Args: None


Deletes all messages for the current user.

Args: None


LGLIB_deleteMessage($uid, $pi_code = “”)

Deletes a single message for a specific user and, optionally, a specific plugin.


Deletes all expired messages from the database


LGLIB_showAllMessages($persist = false)

Retrieves and displays all pending messages for the current user. If $persist is true, the message box will remain visible using a simple message box. If false, the function calls COM_showMessageText() to display the fading message box.

Note that if any individual message has its own “persist” flag set then the message box will persist regardless of the parameter passed to this function.


LGLIB_setGlobal($name, $value, $clobber=true)

Sets a value in the global variable array $_LGLIB_GLOBALS. This, coupled with LGLIB_getGlobal(), gives a convenient method to pass variables between functions without needing to declare the global variable everywhere.

  • name - Name of variable
  • value - Value of variable
  • clobber - True to overwrite any current value


LGLIB_getGlobal($name, $remove=false)

Retrieves a variable set by LGLIB_setGlobal().

  • name - Name of variable to retrieve
  • remove - True to unset the variable after retrieval, False to leave it


LGLIB_setSession($name, $value, $clobber=true)

Like LGLIB_setGlobal(), this function is just a shortcut to set a session variable.

  • name - Name of variable to set
  • value - Value of variable
  • clobber - Overrwite any existing value?


LGLIB_getSession($name, $remove=false)

Retrieves a session variable.


LGLIB_ImageUrl($orig_path, $width=0, $height=0, $rnd = 0)

Resizes an image and places the resized version under public_html/lglib/imgcache with a unique filename.

  • orig_path - Full path to original image. May be under the private directory
  • width - New width for image
  • height - New height for image
  • rnd - Some unique identifier added to the filename. This is to “bust the cache” of images if necessary, for example if the original image been replaced without changing the filename.

Comparison with img.php (TimThumb):

  • Pro - Images are pre-sized and stored on the filesystem, so viewing is fast
  • Con - Images can only be sized to dimensions set in the code, not in templates.



A simple function to obfuscate sensitive strings, such as email addresses, to (somewhat) thwart spders.

  • str - Original string to obfuscate


LGLIB_pushJob($pi_name, $job_name, $params=“”)

Pushes a job into the job queue. This is meant to be used with public_html/lglib/cron.php to run long-running jobs from the command line to avoid browser timeouts.

  • pi_name - Plugin storing the job
  • job_name - Some unique job name
  • params - Job parameters. An array of parameters is stored as JSON, a string is stored as-is. It's up to the plugin's job function to handle its own parameters.


LGLIB_run_jobqueue($pi = “”)

Runs jobs in the job queue, for a single plugin or for all. cron.php can be called with a plugin name to run only one plugin's jobs.

Jobs are run by calling LGLIB_invokeService(pi_name, “runjob”, array(complete job queue record), $output, $svc_msg). The plugin is responsible for implementing a “service_runjob_plugin” function and returning either PLG_RET_OK or PLG_RET_ERROR. The $output is not used.


LGLIB_update_job_status($jobid, $status)

Update the status of a single job. The $status comes from the plugin's service function.


LGLIB_getIcon($name, $style=“info”)

Gets the icon name for either Uikit or FontAwesome icon sets. The style is used to add coloring to the icon, for instance, “info”, “warning”, “danger”, etc.

Automatic Image Resizing

A configuration option can be set to enable the experimental automatic image resizer. This is called from plugin_templateSetVars_lglib() and resizes images to the specified width and height values in the image tag.

Compared to LGLIB_imageUrl():

  • Pro - Can resize images based on values in templates, for greater flexibility
  • Con - First page load can be slow while images are resized
  • Con - Currently doesn't quite support GIF and BMP images, only JPG and PNG
  • Con - Only supports story templates

TimThumb Implementation

Also included is a modified version of TimThumb. TimThumb is no longer supported and this version will likely be scaled down to minimize any attack surface.

Session variables are used to locate the original images for plugins and images are resized on the fly. This is similar to the automatic resizer, but works for all plugins.

Compared to LGLIB_imageUrl():

  • Pro - Resizes on the fly using actual image tag values
  • Con - Original code no longer supported, need to maintain this version
  • Con - First page load can be slow while images are resized


This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

Logged in as: Guest (anonymous)
glfusion/lglib/start.txt · Last modified: 2017/09/11 23:58 by lee
Except where otherwise noted, content on this wiki is licensed under the following license: GNU Free Documentation License 1.3
Random Image
My Account