CFLib.org – Common Function Library Project

Byline(names[, editors][, extrasMode])

Last updated October 10, 2002

author

Gyrus

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Generate a byline from a comma-delimited list of one or more names, in the format 'by X[, Y & Z]'. Also extensible to perform extra functions: currently included is the ability to generate links to iMDB for each name.

Return Values:
Returns a string.

Example:

<cfoutput>
Naked Lunch, #Byline("William S. Burroughs")#<br />
Boring Book, #Byline("F.P. Morden,B.J. Smith,A.B.Q. Forsythe", TRUE)#<br />
Santa Sangre, directed #Byline("Alejandro Jodorowsky", FALSE, "imdb")#<br />
</cfoutput>

Parameters:

Name Description Required
names List of Names. Yes
editors Boolean signifying that the list is a list of editors. Defaults to false. No
extrasMode String signifying extrasMode to use. Currently "IMDB" is support. Defaults to "none". No

Full UDF Source:

/**
 * Generates a byline from a list of names.
 * 
 * @param names      List of Names. (Required)
 * @param editors      Boolean signifying that the list is a list of editors. Defaults to false. (Optional)
 * @param extrasMode      String signifying extrasMode to use. Currently "IMDB" is support. Defaults to "none". (Optional)
 * @return Returns a string. 
 * @author Gyrus (gyrus@norlonto.net) 
 * @version 1, October 10, 2002 
 */
function Byline(names) {
    // Initialise
    var i = 0;
    var name = "";
    var bylineString = "";
    var edited = FALSE;
    var extrasMode = "none";
    if (ArrayLen(Arguments) GT 1) {
        edited = Arguments[2];
    }
    if (ArrayLen(Arguments) GT 2) {
        extrasMode = Arguments[3];
    }
    // Loop through names
    if (ListLen(names)) {
        for (i=1; i LTE ListLen(names); i=i+1) {
            name = ListGetAt(names, i);
            // Edited?
            if (edited) {
                name = "#name# (ed.)";
            }
            // Perform extras
            switch (extrasMode) {
                case "imdb": {
                    name = "<a href=""http://uk.imdb.com/Name?#Replace(name,' ','+','ALL')#"" title=""check for information on this person on the Internet Movie Database"">#name#</a>";
                    break;
                }
            }
            if (i EQ 1) {
                bylineString = "by #name#";
            } else if (i EQ ListLen(names)) {
                bylineString = "#bylineString# &amp; #name#";
            } else {
                bylineString = "#bylineString#, #name#";
            }
        }
    }
    return bylineString;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson