glFusion Wiki

Site Tools


glfusion:development:api:com:functions

lib-common.php

This is the common library for glFusion. Through our code, you will see functions with the COM_ prefix (e.g. COM_siteHeader()). Any such functions can be found in this file.

WARNING: put any custom hacks in lib-custom.php and not in here. This file is modified frequently by the glFusion development team. If you put your hacks in lib-custom.php you will find upgrading much easier.

COM_404

(glFusion v1.1.0)

void COM_404( )

Prints a HTML 404 Not found page

COM_accessLog

(glFusion v1.0.0)

COM_accessLog - Logs message to access.log

Description

void COM_accessLog( string $logentry )

This will print a message to the glFusion access log

Parameters

string $logentry Message to write to access log

Return Value

None

Example

Notes

See Also

COM_errorLog()

COM_adminMenu

(glFusion v1.0.0)

void COM_adminMenu( [string $help = ''], [string $title = ''], [string $position = ''])

Prints administration menu

This will return the administration menu items that the user has sufficient rights to – Admin Block on the left side.

Parameters

string $help Help file to show
string $title Menu Title
string $position Side being shown on 'left', 'right' or blank.

See Also

COM_userMenu()

COM_allowedHTML

(glFusion v1.0.0)

string COM_allowedHTML( [string $permissions = 'story.edit'], [boolean $list_only = false])

Returns what HTML is allowed in content

Returns what HTML tags the system allows to be used inside content. You can modify this by changing $_CONF['user_html'] in the configuration (for admins, see also $_CONF['admin_html']).

Parameters

string $permissions comma-separated list of rights which identify the current user as an “Admin”
boolean $list_only true = return only the list of HTML tags

Return

HTML <div>/<span> enclosed string

Notes

DEPRECIATED glFusion does not maintain a list of valid HTML elements.

See Also

COM_checkHTML()

COM_applyBasicFilter

(glFusion v1.0.0)

string COM_applyBasicFilter( string $parameter, [boolean $isnumeric = false])

Filter parameters

NOTE: Use this function instead of COM_applyFilter for parameters not coming in through a GET or POST request.

Parameters

string $parameter the parameter to test
boolean $isnumeric true if $parameter is supposed to be numeric

Return

the filtered parameter (may now be empty or 0)

Notes

Use this function instead of COM_applyFilter() for parameters not coming in through a GET or POST request, because COM_applyFilter() will also call COM_stripslashes() on the item.

See Also

COM_applyFilter()

COM_applyFilter

(glFusion v1.0.0)

string COM_applyFilter( string $parameter, [boolean $isnumeric = false])

Filter parameters passed per GET (URL) or POST.

Parameters

string $parameter the parameter to test
boolean $isnumeric true if $parameter is supposed to be numeric

Return

The filtered parameter (may now be empty or 0)

See Also

COM_applyBasicFilter()

COM_buildOwnerList

(glFusion v1.1.0)

string COM_buildOwnerList(string $fieldName, [int $owner_id=2] )

Build a drop down list of owners

Parameters

string $fieldName HTML fieldname to use in select
int $owner_id Owner ID to select

Return

HTML select

COM_buildURL

(glFusion v1.0.0)

string COM_buildURL( string $url)

Wrapper function for URL class so as to not confuse people as this will eventually get used all over the place

This function returns a crawler friendly URL (if possible)

Parameters

string $url URL to try to build crawler friendly URL for

Return

Rewritten URL

COM_checkHTML

(glFusion v1.0.0)

string COM_checkHTML( string $str, [string $permissions = 'story.edit'])

This function checks html tags.

Checks to see that the HTML tags are on the approved list and removes them if not.

Parameters

string $str HTML to check
string $permissions comma-separated list of rights which identify the current user as an “Admin”

Return

Filtered HTML

See Also

COM_filterHTML()

Notes

This function calls COM_stripslashes() on the input. To filter without COM_stripSlashes() use COM_filterHTML()

COM_checkList

(glFusion v1.0.0)

string COM_checkList( string $table, string $selection, [string $where = ''], [string $selected = ''], [string $fieldname = ''])

Creates a <input> checklist from a database list for use in forms

Creates a group of checkbox form fields with given arguments

Parameters

string $table DB Table to pull data from
string $selection Comma delimited list of fields to pull from table
string $where Where clause of SQL statement
string $selected Value to set to CHECKED
string $fieldname Name to use for the checkbox array

Return

HTML with Checkbox code

See Also

COM_optionList()

COM_checkSpeedlimit

(glFusion v1.0.0)

int COM_checkSpeedlimit( [string $type = 'submit'], [int $max = 1], [string $property = ''])

Check if speed limit applies

Parameters

string $type type of speed limit, e.g. 'submit', 'comment'
int $max max number of allowed tries within speed limit
string $property IP address or other identifiable property

Return

0: does not apply, else: seconds since last post

COM_checkVersion

(glFusion v1.1.0)

int COM_checkVersion( string $have, string $need )

Compares 2 version numbers

Parameters

string $have The version number of something we have
string $need Minimum version number needed

Return

true if $have is greater or equal to $need otherwise false

COM_checkWords

(glFusion v1.0.0)

string COM_checkWords( string $Message)

This censors inappropriate content

This will replace 'bad words' with something more appropriate

Parameters

string $Message String to check

Return

Edited $Message

See Also

COM_checkHTML()

COM_clearSpeedlimit

(glFusion v1.0.0)

void COM_clearSpeedlimit( [speedlimit $speedlimit = 60], [type $type = ''])

Clear out expired speed limits, i.e. entries older than 'x' seconds

Parameters

speedlimit $speedlimit int number of seconds
type $type string type of speed limit, e.g. 'submit', 'comment'

COM_convertDate2Timestamp

(glFusion v1.0.0)

int COM_convertDate2Timestamp( string $date, [string $time = ''])

Convert a text based date YYYY-MM-DD to a unix timestamp integer value

Parameters

string $date Date in the format YYYY-MM-DD
string $time Option time in the format HH:MM::SS

Return

UNIX Timestamp

COM_createImage

(glFusion v1.0.0)

string COM_createImage( string $url, [string $alt = &quot;&quot;], [array $attr = array()])

Create an HTML img

Parameters

string $url the URL of the image, either starting with http://... or $_CONF['layout_url'] is prepended
string $alt the 'alt'-tag of the image
array $attr an array of optional attributes for the link for example array('title' ⇒ 'whatever');

Return

the HTML img

COM_createLink

(glFusion v1.0.0)

string COM_createLink( string $content, string $url, [array $attr = array()])

Create an HTML link

Parameters

string $content the object to be linked (text, image etc)
string $url the URL the link will point to
array $attr an array of optional attributes for the link for example array('title' ⇒ 'whatever');

Return

the HTML link

COM_dateDiff

(glFusion v1.0.0)

int COM_dateDiff( string $interval, string|int $date1, string|int $date2)

Determines the difference between two dates.

This will takes either unixtimestamps or English dates as input and will automatically do the date diff on the more recent of the two dates (e.g. the order of the two dates given doesn't matter).

Parameters

string $interval Can be: y = year m = month w = week h = hours i = minutes s = seconds
string|int $date1 English date (e.g. 10 Dec 2004) or unixtimestamp
string|int $date2 English date (e.g. 10 Dec 2004) or unixtimestamp

Return

Difference of the two dates in the unit of time indicated by the interval

COM_decompress

(glFusion v1.1.0)

int COM_decompress( string $file, string $target )

Decompress an archive

This function will decompress the archive $file to the directory specified by $target.

Parameters

string $file source file to decompress
string $target destination directory

Return

True on success, False on failure

COM_debug

(glFusion v1.0.0)

string COM_debug( array $array)

Prints out an associative array for debugging

The core of this code has been lifted from phpweblog which is licenced under the GPL. This is not used very much in the code but you can use it if you see fit

Parameters

array $array Array to loop through and print values for

Return

Formatted HTML List

COM_displayMessageAndAbort

(glFusion v1.0.0)

void COM_displayMessageAndAbort( int $msg, [string $plugin = ''], [int $http_status = 200], [string $http_text = 'OK'])

Display a message and abort

NOTE: Displays the message and aborts the script.

Parameters

int $msg message number
string $plugin plugin name, if applicable
int $http_status HTTP status code to send with the message
string $http_text Textual version of the HTTP status code

Notes

Displays the message and aborts the script.

COM_emailEscape

(glFusion v1.0.0)

string COM_emailEscape( string $string)

Encode a string such that it can be used in an email header

Parameters

string $string the text to be encoded

Return

encoded text

COM_emailUserTopics

(glFusion v1.0.0)

void COM_emailUserTopics( )

This will email new stories in the topics that the user is interested in

In account information the user can specify which topics for which they will receive any new article for in a daily digest.

COM_endBlock

(glFusion v1.0.0)

string COM_endBlock( [string $template = 'blockfooter.thtml'])

Closes out COM_startBlock

Parameters

string $template HTML template file used to format block footer

Return

Formatted HTML to close block

See Also

COM_startBlock()

COM_errorLog

(glFusion v1.0.0)

string COM_errorLog( string $logentry, [int $actionid = ''])

Logs messages to error.log or the web page or both

Prints a well formatted message to either the web page, error log or both.

Parameters

string $logentry Text to log to error log
int $actionid where 1 = write to log file, 2 = write to screen (default) both

Return

If $actionid = 2 or '' then HTML formatted string (wrapped in block) else nothing

See Also

COM_accessLog()

COM_featuredCheck

(glFusion v1.0.0)

void COM_featuredCheck( )

DEPRECIATED Use STORY_featuredCheck()

Checks to see if any articles that were published for the future have been published and, if so, will see if they are featured. If they are featured, this will set old featured article (if there is one) to normal

COM_filterHTML

(glFusion v1.0.0)

string COM_filterHTML( string $str, [string $permissions = 'story.edit'])

Filters the HTML, removing any malicious content and attempts to clean up invalid markup.

Parameters

string $str HTML to check
string $permissions comma-separated list of rights which identify the current user as an “Admin”

Return

Filtered HTML

See Also

COM_checkHTML()

COM_formatBlock

(glFusion v1.0.0)

string COM_formatBlock( array $A, [boolean $noboxes = false])

Formats a glFusion block

This shows a single block and is typically called from COM_showBlocks OR from plugin code

Parameters

array $A Block Record
boolean $noboxes Set to true if userpref is no blocks

Return

HTML Formated block

COM_formatEmailAddress

(glFusion v1.0.0)

string COM_formatEmailAddress( string $name, string $address)

Takes a name and an email address and returns a string that vaguely resembles an email address specification conforming to RFC(2)822 …

Parameters

string $name name, e.g. John Doe
string $address email address only, e.g. john.doe@example.com

Returns

Formatted email address

COM_formatTimeString

(glFusion v1.0.0)

void COM_formatTimeString( string $time_string, int $time, [string $type = ''], [int $amount = 0])

Creates the string that indicates the timespan in which new items were found

Parameters

string $time_string template string
int $time number of seconds in which results are found
string $type type (translated string) of new item
int $amount amount of things that have been found.

COM_getAmPmFormSelection

(glFusion v1.0.0)

string COM_getAmPmFormSelection( string $name, [string $selected = ''])

Create an am/pm selector dropdown menu

Parameters

string $name name of the <select>
string $selected preselection: 'am' or 'pm'

Return

HTML for the dropdown; empty string in 24 hour mode

COM_getArgument

(glFusiono v1.0.0)

string COM_getArgument( string $name)

Wrapper function for URL class

returns value for specified argument

Parameters

string $name argument to get value for

Return

Argument value

COM_getBlockTemplate

(glFusion v1.0.0)

string COM_getBlockTemplate( string $blockname, string $which, [string $position = ''])

Return the file to use for a block template.

This returns the template needed to build the HTML for a block. This function allows designers to give a block it's own custom look and feel. If no templates for the block are specified, the default blockheader.html and blockfooter.html will be used.

Parameters

string $blockname corresponds to name field in block table
string $which can be either 'header' or 'footer' for corresponding template
string $position can be 'left', 'right' or blank. If set, will be used to find a side specific override template.

Return

Template name

See Also

COM_showBlock()

COM_showBlocks()

COM_endBlock()

COM_startBlock()

COM_getCharset

(glFusion v1.0.0)

string COM_getCharset( )

Get the current character set

Uses (if available, and in this order)

  • $LANG_CHARSET (from the current language file)
  • $_CONF['default_charset'] (from siteconfig.php)
  • 'iso-8859-1' (hard-coded fallback)

Return

Character set, e.g. 'utf-8'

COM_getCurrentURL

(glFusion v1.0.0)

string COM_getCurrentURL( )

Try to figure out our current URL, including all parameters.

This is an ugly hack since there's no single variable that returns what we want and the variables used here may not be available on all servers and / or setups.

Seems to work on Apache (1.3.x and 2.x), IIS, and Zeus …

Return

Complete URL, e.g. http://www.example.com/blah.php?foo=bar

COM_getDayFormOptions

(glFusion v1.0.0)

string COM_getDayFormOptions( [string $selected = ''])

Gets the <option> values for calendar days

Parameters

string $selected Selected day

Return

HTML days as option values

See Also

COM_getMinuteFormOptions()

COM_getHourFormOptions()

COM_getYearFormOptions()

COM_getMonthFormOptions()

COM_getDisplayName

(glFusion v1.0.0)

string COM_getDisplayName( [int $uid = ''], [string $username = ''], [string $fullname = ''], [string $remoteusername = ''], [string $remoteservice = ''])

Return the username or fullname for the passed member id (uid)

Allows the siteAdmin to determine if loginname (username) or fullname should be displayed.

Parameters

int $uid site member id
string $username Username, if this is set no lookup is done.
string $fullname Users full name.
string $remoteusername Username on remote service
string $remoteservice Remote login service.

Return

Username, fullname or username@Service

COM_getEncodingt

(glFusion v1.0.0)

string COM_getEncodingt( )

Returns a valid character set for use with htmlspecialchars()

Return

Character set (i.e.; utf-8)

COM_getHourFormOptions

(glFusion v1.0.0)

string COM_getHourFormOptions( [string $selected = ''], [int $mode = 12])

Gets the <option> values for clock hours

Parameters

string $selected Selected hour
int $mode 12 or 24 hour mode

Return

HTML string of options

See Also

COM_getMinuteFormOptions()

COM_getYearFormOptions()

COM_getDayFormOptions()

COM_getMonthFormOptions()

COM_getImgSizeAttributes

(glFusion v1.0.0)

string COM_getImgSizeAttributes( string $file)

Get the HTML for an image with height & width

Parameters

string $file full path to the file

Return

HTML that will be included in the img-tag

COM_getLangSQL

(glFusion v1.0.0)

string COM_getLangSQL( string $field, [string $type = 'WHERE'], [string $table = ''])

Return SQL expression to request language-specific content

Creates part of an SQL expression that can be used to request items in the current language only.

Parameters

string $field name of the “id” field, e.g. 'sid' for stories
string $type part of the SQL expression, e.g. 'WHERE', 'AND'
string $table table name if ambiguous, e.g. in JOINs

Return

SQL expression string (may be empty)

COM_getLanguage

(glFusion v1.0.0)

string COM_getLanguage( )

Determine current language

Return

Name of the language file (minus the '.php' extension)

COM_getLanguageFromBrowser

(glFusion v1.0.0)

string COM_getLanguageFromBrowser( )

Try to determine the user's preferred language by looking at the “Accept-Language” header sent by their browser (assuming they bothered to select a preferred language there).

Sample header: Accept-Language: en-us,en;q=0.7,de-de;q=0.3

Return

Name of the language file to use or an empty string

Notes

Does not take the quantity ('q') parameter into account, but only looks at the order of language codes.

COM_getLanguageId

(glFusion v1.0.0)

string COM_getLanguageId( [string $language = ''])

Determine the ID to use for the current language

The $_CONF['language_files'] array maps language IDs to language file names. This function returns the language ID for a certain language file, to be used in language-dependent URLs.

Parameters

string $language current language file name (optional)

Return

language ID, i.e.; 'en'; empty string on error

COM_getLanguageName

(glFusion v1.0.0)

string COM_getLanguageName( )

Get the name of the current language, minus the character set

Strips the character set from $_CONF['language'] configuration setting.

Return

Language name

COM_getMinuteFormOptions

(glFusion v1.0.0)

string COM_getMinuteFormOptions( [string $selected = ''], [int $step = 1])

Gets the <option> values for clock minutes

Parameters

string $selected Selected minutes
int $step number of minutes between options, e.g. 15

Return

HTML of option minutes

See Also

COM_getYearFormOptions() COM_getHourFormOptions() COM_getDayFormOptions() COM_getMonthFormOptions()

COM_getMinuteOptions

(glFusion v1.0.0)

void COM_getMinuteOptions( [ $selected = ''], [ $step = 1])

For backward compatibility only.

This function should always have been called COM_getMinuteFormOptions

Parameters

$selected
$step

See Also

COM_getMinuteFormOptions()

COM_getMonthFormOptions

(glFusion v1.0.0)

string COM_getMonthFormOptions( [string $selected = ''])

Gets the <option> values for calendar months

Parameters

string $selected Selected month

Return

HTML Months as option values

See Also

COM_getMinuteFormOptions() COM_getHourFormOptions() COM_getYearFormOptions() COM_getDayFormOptions()

COM_getPassword

(glFusion v1.0.0)

string COM_getPassword( string $loginname)

Return the password for the given username

Fetches a password for the given user

Parameters

string $loginname username to get password for

Return

Password or ''

COM_getPermSQL

(glFusion v1.0.0)

string COM_getPermSQL( [string $type = 'WHERE'], [int $u_id = 0], [int $access = 2], [string $table = ''])

Return SQL expression to check for permissions.

Creates part of an SQL expression that can be used to request items with the standard set of glFusion permissions.

Parameters

string $type part of the SQL expr. e.g. 'WHERE', 'AND'
int $u_id user id or 0 = current user
int $access access to check for (2=read, 3=r&write)
string $table table name if ambiguous (e.g. in JOINs)

Return

SQL expression string (may be empty)

COM_getRate

(glFusion v1.0.0)

int COM_getRate( int $occurrences, int $timespan)

Occurences / time

This will take a number of occurrences, and number of seconds for the time span and return the smallest #/time interval

Parameters

int $occurrences how many occurrences during time interval
int $timespan time interval in seconds

Return

Seconds per interval

COM_getThemes

array COM_getThemes( [boolean $all = false])

Gets all installed themes

Returns a list of all the directory names in $_CONF['path_themes'], i.e. a list of all the theme names.

Parameters

boolean $all if true, return all themes even if users aren't allowed to change their default themes

Return

All installed themes

COM_getTopicImageUrl

(glFusion v1.0.0)

string COM_getTopicImageUrl( string $imageurl)

Return full URL of a topic icon

Parameters

string $imageurl (relative) topic icon URL

Return

Full URL

COM_getTopicSQL

(glFusion v1.0.0)

string COM_getTopicSQL( [string $type = 'WHERE'], [int $u_id = 0], [string $table = ''])

Return SQL expression to check for allowed topics.

Creates part of an SQL expression that can be used to only request stories from topics to which the user has access to.

Note that this function does an SQL request, so you should cache the resulting SQL expression if you need it more than once.

Parameters

string $type part of the SQL expr. e.g. 'WHERE', 'AND'
int $u_id user id or 0 = current user
string $table table name if ambiguous (e.g. in JOINs)

Return

SQL expression string (may be empty)

Notes

This function does an SQL request, so you should cache the resulting SQL expression if you need it more than once.

COM_getUserCookieTimeout

(glFusion v1.0.0)

int COM_getUserCookieTimeout( )

Returns user-defined cookie timeout

In account preferences users can specify when their long-term cookie expires. This function returns that value.

Return

return: Cookie time out value in seconds

COM_getUserDateTimeFormat

(glFusion v1.0.0)

array COM_getUserDateTimeFormat( [string $date = ''])

Returns formatted date/time for user

This function takes a date in either unixtimestamp or in english and formats it to the users preference. If the user didn't specify a format the format in the config file is used. This returns an array where array[0] is the formatted date and array[1] is the unixtimestamp

Parameters

string $date date to format, otherwise we format current date/time

Return

array[0] is the formatted date and array[1] is the unixtimestamp.

COM_getYearFormOptions

(glFusion v1.0.0)

string COM_getYearFormOptions( [string $selected = ''], [int $startoffset = -1], [int $endoffset = 5])

Gets the <option> values for calendar years

Returns Option list Containing 5 years starting with current unless @selected is < current year then starts with @selected

Parameters

string $selected Selected year
int $startoffset Optional (can be +/-) Used to determine start year for range of years
int $endoffset Optional (can be +/-) Used to determine end year for range of years

Return

HTML years as option values

See Also

COM_getMinuteFormOptions() COM_getHourFormOptions() COM_getDayFormOptions() COM_getMonthFormOptions()

COM_handleCode

(glFusion v1.0.0)

string COM_handleCode( string $str)

Handles the part within a [code] … [/code] section, i.e. escapes all special characters.

Parameters

string $str the code section to encode

Return

With the special characters encoded

COM_checkHTML()

COM_handleError

(glFusion v1.0.0)

void COM_handleError( int $errno, string $errstr, [string $errfile = ''], [int $errline = 0], [array $errcontext = ''])

Handle errors.

This function will handle all PHP errors thrown at it, without exposing paths, and hopefully, providing much more information to Root Users than the default white error page.

This function will call out to CUSTOM_handleError if it exists, but, be advised, only override this function with a very, very stable function. I'd suggest one that outputs some static, basic HTML.

The PHP feature that allows us to do so is documented here: http://uk2.php.net/manual/en/function.set-error-handler.php

Parameters

int $errno Error Number.
string $errstr Error Message.
string $errfile The file the error was raised in.
int $errline The line of the file that the error was raised at.
array $errcontext An array that points to the active symbol table at the point the error occurred.

COM_highlightQuery

(glFusion v1.0.0)

string COM_highlightQuery( string $text, string $query, [string $class = 'highlight'])

Highlight the words from a search query in a given text string.

Parameters

string $text the text
string $query the search query
string $class html class to use to highlight

Return

The text with highlighted search words

COM_hit

void COM_hit( )

Adds a hit to the system

This function is called in the footer of every page and is used to track the number of hits to the glFusion system. This information is shown on stats.php

COM_isAnonUser

(glFusion v1.0.0)

boolean COM_isAnonUser( [int $uid = ''])

Checks to see if a specified user, or the current user if non-specified is the anonymous user.

Parameters

int $uid ID of the user to check, or none for the current user.

Return

true if the user is the anonymous user.

COM_isEmail

(glFusion v1.0.0)

boolean COM_isEmail( string $email)

Checks to see if email address is valid.

This function checks to see if an email address is in the correct from.

Parameters

string $email Email address to verify

Return

True if valid otherwise false

COM_isFrontpage

(glFusion v1.0.0)

void COM_isFrontpage( )

DEPRECIATED

Check if we're on glFusion's index page [deprecated]

Note that this function returns FALSE when we're on the index page. Due to the inverted return values, it has been deprecated and is only provided for backward compatibility - use COM_onFrontpage() instead.

See Also

COM_onFrontpage()

Notes

Deprecated - use COM_onFrontpage()

COM_isWritable

(glFusion v1.1.0)

int COM_isWritable( string $path )

Determines if directory $path is writable by the web server.

Parameters

string $path Path to file or directory

Return

True if writable, false if not

COM_killJS

(glFusion v1.0.0)

string COM_killJS( string $Message)

Takes some amount of text and replaces all javascript events on*= with in

This script takes some amount of text and matches all javascript events, on*= (onBlur= onMouseClick=) and replaces them with in*= Essentially this will cause onBlur to become inBlur, onFocus to be inFocus These are not valid javascript events and the browser will ignore them.

Parameters

string $Message Text to filter

Return

with javascript filtered

See Also

COM_checkHTML() COM_checkWords()

COM_mail

(glFusion v1.0.0)

boolean COM_mail( string $to, string $subject, string $message, [string $from = ''], [boolean $html = false], [int $priority = 0], [mixed $optional = null])

Send an email.

All emails sent by glFusion are sent through this function.

NOTE: Please note that using CC: will expose the email addresses of all recipients. Use with care.

Parameters

string $to recipients name and email address
string $subject subject of the email
string $message the text of the email
string $from (optional) sender of the the email
boolean $html (optional) true if to be sent as HTML email
int $priority (optional) add X-Priority header, if > 0
string $cc (optional) other recipients (name + email)
string $altBody (optional) alternative message body (plain text)

Return

true if successful, otherwise false

Notes

Please note that using the $cc parameter will expose the email addresses of all recipients. Use with care.

COM_makeClickableLinks

(glFusion v1.0.0)

string COM_makeClickableLinks( string $text)

Detect links in a plain-ascii text and turn them into clickable links.

Will detect links starting with “http:”, “https:”, “ftp:”, and “www.”.

Parameters

string $text the (plain-ascii) text string

Return

The same string, with links enclosed in <a>…</a> tags

COM_makeClickableLinksCallback

(glFusion v1.0.0)

string COM_makeClickableLinksCallback( string $http, string $link)

Callback function to help format links in COM_makeClickableLinks

Parameters

string $http set to 'http://' when not already in the url
string $link the url

Return

link enclosed in <a>…</a> tags

COM_makeList

(glFusion v1.0.0)

string COM_makeList( array $listofitems, [string $classname = ''])

Creates an HTML unordered list from the given array.

It formats one list item per array element, using the list.thtml and listitem.thtml templates.

Parameters

array $listofitems Items to list out
string $classname optional CSS class name for the list

Return

HTML unordered list of array items

COM_makesid

(glFusion v1.0.0)

string COM_makesid( )

Makes an ID based on current date/time

This function creates a 17 digit sid for stories based on the 14 digit date and a 3 digit random number that was seeded with the number of microseconds (.000001th of a second) since the last full second. NOTE: this is now used for more than just stories!

Return

Story ID

COM_numberFormat

(glFusion v1.0.0)

string COM_numberFormat( float $number)

Converts a number for output into a formatted number with thousands- separator, comma-separator and fixed decimals if necessary

Parameters

float $number Number that will be formatted

Return

Formatted number

COM_olderStuff

(glFusion v1.0.0)

void COM_olderStuff( )

Creates older stuff block

Creates the olderstuff block for display. Actually updates the olderstuff record in the gl_blocks database.

COM_onFrontpage

(glFusion v1.0.0)

boolean COM_onFrontpage( )

Check if we're on glFusion's index page.

See if we're on the main index page (first page, no topics selected).

Return

True = we're on the frontpage, false = we're not

COM_optionList

(glFusion v1.0.0)

string COM_optionList( string $table, string $selection, [string/array $selected = ''], [int $sortcol = 1], [string $where = ''])

Creates a <option> list from a database list for use in forms

Creates option list form field using given arguments

Parameters

string $table Database Table to get data from
string $selection Comma delimited string of fields to pull The first field is the value of the option and the second is the label to be displayed. This is used in a SQL statement and can include DISTINCT to start.
string/array $selected Value (from $selection) to set to SELECTED or default
int $sortcol Which field to sort option list by 0 (value) or 1 (label)
string $where Optional WHERE clause to use in the SQL Selection

Return

Formated HTML of option values

See Also

COM_checkList()

COM_printPageNavigation

(glFusion v1.0.0)

string COM_printPageNavigation( string $base_url, int $curpage, int $num_pages, [string $page_str = 'page='], [boolean $do_rewrite = false], [string $msg = ''], [string $open_ended = ''])

Prints Google™-like paging navigation

Parameters

string $base_url base url to use for all generated links
int $curpage current page we are on
int $num_pages Total number of pages
string $page_str page-variable name AND '='
boolean $do_rewrite if true, url-rewriting is respected
string $msg to be displayed with the navigation
string $open_ended replace next/last links with this

Return

HTML formatted widget

COM_rdfCheck

(glFusion v1.0.0)

void COM_rdfCheck( string $bid, string $rdfurl, string $date, [string $maxheadlines = 0])

Checks to see if it's time to import and RDF/RSS block again

Updates RDF/RSS block if needed

Parameters

string $bid Block ID
string $rdfurl URL to get headlines from
string $date Last time the headlines were imported
string $maxheadlines max. number of headlines to import

See Also

COM_rdfImport()

COM_rdfImport

(glFusion v1.0.0)

void COM_rdfImport( string $bid, string $rdfurl, [int $maxheadlines = 0])

Syndication import function. Imports headline data to a portal block.

Parameters

string $bid Block ID
string $rdfurl URL to get content from
int $maxheadlines Maximum number of headlines to display

See Also

COM_rdfCheck()

COM_rdfUpToDateCheck

(glFusion v1.0.0)

void COM_rdfUpToDateCheck( [string $updated_type = ''], [string $updated_topic = ''], [string $updated_id = ''])

Checks to see if RDF file needs updating and updates it if so.

Checks to see if we need to update the RDF as a result of an article with a future publish date reaching it's publish time and if so updates the RDF file.

Parameters

string $updated_type (optional) feed type to update
string $updated_topic (optional) feed topic to update
string $updated_id (optional) feed id to update

Notes

NOTE: When called without parameters, this will only check for new entries to include in the feeds. Pass the $updated_XXX parameters when the content of an existing entry has changed.

COM_refresh

(glFusion v1.0.0)

string COM_refresh( string $url)

Redirects user to a given URL

This function does a redirect using a meta refresh. This is (or at least used to be) more compatible than using a HTTP Location: header.

Parameters

string $url URL to send user to

Return

HTML meta redirect

Notes

This does not need to be XHTML compliant. It may also be used in situations where the XHTML constant is not defined yet …

COM_renderMenu

(glFusion v1.0.0)

void COM_renderMenu( Template &$header, array $plugin_menu)

Create the menu, i.e. replace {menu_elements} in the site header with the actual menu entries.

Parameters

template &$header reference to the header template
array $plugin_menu array of plugin menu entries, if any

COM_renderWikiText

(glFusion v1.0.0)

string COM_renderWikiText( string $wikitext)

Convert wiki-formatted text to (X)HTML

Parameters

string $wikitext wiki-formatted text

Return

XHTML formatted text

COM_resetSpeedlimit

(glFusion v1.0.0)

void COM_resetSpeedlimit( [string $type = 'submit'], [string $property = ''])

Reset the speedlimit

Parameters

string $type type of speed limit to reset, e.g. 'submit'
string $property IP address or other identifiable property

COM_rootDebugClean

array COM_rootDebugClean( array $array, [boolean $blank = false])

Recurse through the error context array removing/blanking password/cookie values in case the “for development” only switch is left on in a production environment.

Parameters

array $array Array of state info (Recursive array).
boolean $blank override (wouldn't that blank out everything?)

Return

Cleaned array

COM_sanitizeFilename

(glFusion v1.0.0)

string COM_sanitizeFilename( string $filename, [boolean $allow_dots = false])

Sanitize a filename.

Parameters

string $filename the filename to clean up
boolean $allow_dots whether to allow dots in the filename or not

Return

Sanitized filename

Notes

This function is pretty strict in what it allows. Meant to be used for files to be included where part of the filename is dynamic.

COM_sanitizeID

(glFusion v1.0.0)

string COM_sanitizeID( string $id, [boolean $new_id = true])

Ensure an ID contains only alphanumeric characters, dots, dashes, or underscores

Parameters

string $id the ID to sanitize
boolean $new_id true = create a new ID in case we end up with an empty string

Return

The sanitized ID

COM_sanitizeUrl

(glFusion v1.0.0)

string COM_sanitizeUrl( string $url, [array $allowed_protocols = ''], [string $default_protocol = ''])

Sanitize a URL

Parameters

string $url URL to sanitized
array $allowed_protocols array of allowed protocols
string $default_protocol replacement protocol (default: http)

Return

Sanitized URL

COM_setArgNames

(glFusion v1.0.0)

boolean COM_setArgNames( array $names)

Wrapper function for URL class so as to not confuse people

This function sets the name of the arguments found in url

Parameters

array $names Names of arguments in query string to assign to values

Return

True if successful

COM_setLangIdAndAttribute

(glFusion v1.0.0)

void COM_setLangIdAndAttribute( ref &$template)

Set the {lang_id} and {lang_attribute} variables for a template

NOTE: {lang_attribute} is only set in multi-language environments.

Parameters

ref &$template template to use

COM_showBlock

(glFusion v1.0.0)

string COM_showBlock( string $name, [string $help = ''], [string $title = ''], [string $position = ''])

Shows a single glFusion block

This shows a single block and is typically called from COM_showBlocks OR from plugin code

Parameters

string $name Logical name of block (not same as title) – 'user_block', 'admin_block', 'section_block', 'whats_new_block'.
string $help Help file location
string $title Title shown in block header
string $position Side, 'left', 'right' or empty.

Return

HTML Formated block

See Also

COM_showBlocks()

COM_showBlocks

(glFusion v1.0.0)

string COM_showBlocks( string $side, [string $topic = ''], [string $name = 'all'])

Shows glFusion blocks

Returns HTML for blocks on a given side and, potentially, for a given topic. Currently only used by static pages.

Parameters

string $side Side to get blocks for (right or left for now)
string $topic Only get blocks for this topic
string $name Block name (not used)

Return

HTML Formated blocks

See Also

COM_showBlock()

COM_showMessage

(glFusion v1.0.0)

string COM_showMessage( int $msg, [string $plugin = ''])

Displays a message on the webpage

Display one of the predefined messages from the $MESSAGE array. If a plugin name is provided, display that plugin's message instead.

Parameters

int $msg ID of message to show
string $plugin Optional name of plugin to lookup plugin defined message

Return

HTML block with message

See Also

COM_showMessageText() COM_showMessageFromParameter()

COM_showMessageFromParameter

(glFusion v1.0.0)

string COM_showMessageFromParameter( )

Displays a message, as defined by URL parameters

Helper function to display a message, if URL parameters 'msg' and 'plugin' (optional) are defined. Only for GET requests, but that's what glFusion uses everywhere anyway.

Return

HTML block with message

See Also

COM_showMessageText() COM_showMessage()

COM_showMessageText

(glFusion v1.0.0)

string COM_showMessageText( string $message, [string $title = ''])

Displays a message text in a “System Message” block

Parameters

string $message Message text; may contain HTML
string $title (optional) alternative block title

Return

HTML block with message

See Also

COM_showMessageFromParameter() COM_showMessage()

COM_showTopics

(glFusion v1.0.0)

string COM_showTopics( [string $topic = ''])

Shows all available topics

Show the topics in the system the user has access to and prints them in HTML. This function is used to show the topics in the topics block.

Parameters

string $topic ID of currently selected topic

Return

HTML formatted topic list

COM_siteFooter

(glFusion v1.0.0)

string COM_siteFooter( [boolean $rightblock = -1], [array $custom = ''])

Returns the site footer

This loads the proper templates, does variable substitution and returns the HTML for the site footer.

Parameters

boolean $rightblock Whether or not to show blocks on right hand side default is no
array $custom An array defining custom function to be used to format Rightblocks

Return

Formated HTML containing site footer and optionally right blocks

See Also

COM_siteHeader()

COM_siteHeader

(glFusion v1.0.0)

string COM_siteHeader( [string $what = 'menu'], [string $pagetitle = ''], [string $headercode = ''])

Returns the site header

This loads the proper templates, does variable substitution and returns the HTML for the site header with or without blocks depending on the value of $what

Programming Note:

The two functions COM_siteHeader and COM_siteFooter provide the framework for page display in glFusion. COM_siteHeader controls the display of the Header and left blocks and COM_siteFooter controls the dsiplay of the right blocks and the footer. You use them like a sandwich. Thus the following code will display a glFusion page with both right and left blocks displayed.

<?php
require_once 'lib-common.php';
// Change to COM_siteHeader('none') to not display left blocks
$display .= COM_siteHeader();
$display .= "Here is your html for display";
// Change to COM_siteFooter() to not display right blocks
$display .= COM_siteFooter(true);
echo $display;
? >

Note that the default for the header is to display the left blocks and the default of the footer is to not display the right blocks.

This sandwich produces code like this (greatly simplified)

// COM_siteHeader
<table><tr><td colspan="3">Header</td></tr>
<tr><td>Left Blocks</td><td>
// Your HTML goes here
Here is your html for display
// COM_siteFooter
</td><td>Right Blocks</td></tr>
<tr><td colspan="3">Footer</td></table>

Parameters

string $what If 'none' then no left blocks are returned, if 'menu' (default) then right blocks are returned
string $pagetitle optional content for the page's <title>
string $headercode optional code to go into the page's <head>

Return

Formatted HTML containing the site header

See Also

COM_siteFooter()

COM_startBlock

(glFusion v1.0.0)

string COM_startBlock( [string $title = ''], [string $helpfile = ''], [string $template = 'blockheader.thtml'])

Prints out standard block header

Prints out standard block header but pulling header HTML formatting from the database.

Parameters

string $title Value to set block title to
string $helpfile Help file, if one exists
string $template HTML template file to use to format the block

Return

Formatted HTML containing block header

See Also

COM_siteHeader() COM_endBlock()

Notes

The two functions COM_startBlock and COM_endBlock are used to sandwich your block content. These functions are not used only for blocks but anything that uses that format, e.g. Stats page. They are used like COM_siteHeader and COM_siteFooter but for internal page elements.

COM_stripslashes

(glFusion v1.0.0)

string COM_stripslashes( string $text)

Strip slashes from a string only when magic_quotes_gpc = on.

Parameters

string $text The text

Return

The text, possibly without slashes.

COM_switchLocaleSettings

(glFusion v1.0.0)

void COM_switchLocaleSettings( )

Switch locale settings

When multi-language support is enabled, allow overwriting the default locale settings with language-specific settings (date format, etc.). So in addition to $_CONF['date'] you can have a $_CONF['date_en'], $_CONF['date_de'], etc.

COM_topicArray

(glFusion v1.0.0)

array COM_topicArray( string $selection, [int $sortcol = 0], [boolean $ignorelang = false])

Return a list of topics in an array (derived from COM_topicList - API may change)

Parameters

string $selection Comma delimited string of fields to pull The first field is the value of the option and the second is the label to be displayed. This is used in a SQL statement and can include DISTINCT to start.
int $sortcol Which field to sort option list by 0 (value) or 1 (label)
boolean $ignorelang Whether to return all topics (true) or only the ones for the current language (false)
int $access Permission to filter topics. Default is 2 (Read)

Return

Array of topics

See Also

COM_topicList()

COM_topicList

(glFusion v1.0.0)

string COM_topicList( string $selection, [string $selected = ''], [int $sortcol = 1], [boolean $ignorelang = false])

Create and return a dropdown-list of available topics

This is a variation of COM_optionList() from lib-common.php. It will add only those topics to the option list which are accessible by the current user.

Parameters

string $selection Comma delimited string of fields to pull The first field is the value of the option and the second is the label to be displayed. This is used in a SQL statement and can include DISTINCT to start.
string $selected Value (from $selection) to set to SELECTED or default
int $sortcol Which field to sort option list by 0 (value) or 1 (label)
boolean $ignorelang Whether to return all topics (true) or only the ones for the current language (false)
int $access Permission to filter topics. Default is 2 (Read)

Return

Formated HTML of option values

See Also

COM_optionList()

COM_truncate

(glFusion v1.0.0)

string COM_truncate( string $text, int $maxlen, [string $filler = ''], [int $endchars = 0])

Truncate a string

Truncates a string to a max. length and optionally adds a filler string, e.g. '…', to indicate the truncation. This function is multi-byte string aware, based on a patch by Yusuke Sakata.

Parameters

string $text the text string to truncate
int $maxlen max. number of characters in the truncated string
string $filler optional filler string, e.g. '…'
int $endchars number of characters to show after the filler

Return

Truncated string

Notes

The truncated string may be shorter but will never be longer than $maxlen characters, i.e. the $filler string is taken into account.

COM_undoClickableLinks

(glFusion v1.0.0)

string COM_undoClickableLinks( string $text)

Undo the conversion of URLs to clickable links (in plain text posts), e.g. so that we can present the user with the post as they entered them.

Parameters

string $text story text

Return

Story text without links

COM_undoSpecialChars

(glFusion v1.0.0)

string COM_undoSpecialChars( string $string)

undo function for htmlspecialchars()

This function translates HTML entities created by htmlspecialchars() back into their ASCII equivalents. Also handles the entities for $, {, and }.

Parameters

string $string The string to convert.

Return

The converted string.

COM_updateSpeedlimit

(glFusion v1.0.0)

void COM_updateSpeedlimit( [string $type = 'submit'], [string $property = ''])

Store post info for speed limit

Parameters

string $type type of speed limit, e.g. 'submit', 'comment'
string $property IP address or other identifiable property

COM_userComments

(glFusion v1.0.0)

void COM_userComments( $sid, $title, [ $type = 'article'], [ $order = ''], [ $mode = ''], [ $pid = 0], [ $page = 1], [ $cid = false], [ $delete_option = false])

DEPRECIATED – see CMT_userComments in lib-comment.php

See Also

CMT_userComments()

COM_userMenu

(glFusion v1.0.0)

void COM_userMenu( [string $help = ''], [string $title = ''], [string $position = ''])

Shows the user their menu options

This shows the average Joe User their menu options. This is the user block on the left side

Parameters

string $help Help file to show
string $title Title of Menu
string $position Side being shown on 'left', 'right'. Though blank works not likely.

See Also

COM_adminMenu()

COM_whatsNewBlock

(glFusion v1.0.0)

string COM_whatsNewBlock( [string $help = ''], [string $title = ''], [string $position = ''])

Shows any new information in a block

Return the HTML that shows any new stories, comments, etc

Parameters

string $help Help file for block
string $title Title used in block header
string $position Position in which block is being rendered 'left', 'right' or blank (for centre)

Return

Return the HTML that shows any new stories, comments, etc

glfusion/development/api/com/functions.txt · Last modified: 2017/04/12 21:15 (external edit)

Page Tools