Corefunctions.php
From Efiction
(→accessDenied) |
(→format_story) |
||
Line 41: | Line 41: | ||
==format_story== | ==format_story== | ||
This function is used to display text information including story chapters, notes, and news items. The function | This function is used to display text information including story chapters, notes, and news items. The function | ||
- | determines if there are already | + | determines if there are already <p> or <br /> tags present in the text. If these tags are not present, the function runs nl2br on the text to add the proper formatting. The function also strips slashes from the text |
- | function runs nl2br on the text to add the proper formatting. The function also strips slashes from the text | + | |
and attempts to correct some common bad characters created by MS Word. | and attempts to correct some common bad characters created by MS Word. | ||
Example: | Example: | ||
+ | |||
+ | <pre> | ||
+ | $text = format_story($text); | ||
+ | </pre> | ||
==escapestring== | ==escapestring== |
Revision as of 15:18, 27 July 2006
This file describes the functions contained in corefunctions.php and used throughout the eFiction 3.0 script. Those developing mods, blocks, and modules for the script are encouraged to use these functions.
Contents |
recurseCategories
This function creates an array of categories and sub-categories. You may pass either an array of multiple categories or a single category to this function. Given the following category structure:
1 -> Top Category
- 2 -> Sub-Category to 1
3 -> 2nd Top Category
- 4 -> Sub-Category of 3
- 5 -> 2nd Sub-Category of 3
If passed the category 3, recurseCategories would return an array containing: 3, 4, and 5.
If passed an array containing 3 and 2, recurseCategories would return an array containing: 2, 3, 4 and 5.
Example:
if($catid) { $categories = recurseCategories($catid); foreach($categories as $cat) { $categorysql[] = "FIND_IN_SET('$cat', stories.catid) > 0"; } $storyquery = _STORYQUERY.(is_array($categorysql) ? implode(" OR ", $categorysql); }
descript
Use this function to sanitize form input.
accessDenied
If you must check for permissions, use this function when the check fails and the user is denied permission. This will output the message that the user does not have permission to access this feature and exit the script.
Example:
if(!$loggedin) accessDenied( );
format_story
This function is used to display text information including story chapters, notes, and news items. The function determines if there are already <p> or <br /> tags present in the text. If these tags are not present, the function runs nl2br on the text to add the proper formatting. The function also strips slashes from the text and attempts to correct some common bad characters created by MS Word.
Example:
$text = format_story($text);
escapestring
Use this function when adding data to the database to escape characters.
Example:
$result = dbquery("INSERT INTO testtable(`id`, `val`) VALUES('1', '".escapestring("my text")."')");
format_email
This function displays emails replacing the @ and . symbols with [at] and [dot] to help foil spam bots.
title_link
This function takes an array of information about a story and formats the link to the title with the appropriate javascript for age consent and member only ratings and dependent on the visitors login and age consent status.
Example:
$title = title_link($stories);
author_link
This function takes an array of information about a story and formats the authors link to include both author and co-authors with links to their profiles.
Example:
$authors = author_link($stories);
truncate_text
This function takes a piece of text and truncates it to the desired length truncating at the end of the word instead of in the middle as previous versions of eFiction did.
Example:
find_naughty
This function when passed a piece of text returns true if words from the forbidden words list are found in the text. Nothing is done to the original text. Returns false if no forbidden words are found.
Example:
if(find_naughty($dirtywords)) $output .= write_message("Bad words!"); else $output .= write_message("What an angel!");
replace_naughty
This function when passed a piece of text replaces words from the forbidden word list with the first letter and trailing asterisks: f***.
Example:
$cleaned = replace_naughty($dirty);
write_message
This function is used whenever a message needs to be output to the screen. This allows a uniform look for all messages on the site.
Example:
$output .= write_message(_ACTIONSUCCESSFUL);
write_error
This function is used whenever an error needs to be output to the screen. This allows a uniform look for all error messages on the site.
Example:
$output .= write_error(_ERROR);
isNumber
This function is passed a variable and returns true if the variable is an integer number. Use this to check input from uses, especially id numbers passed via $_GET.
Example:
$sid = isset($_GET['sid']) && isNumber($_GET['sid']) ? $_GET['sid'] : 0;
check_prefs
This function is passed a uid and checks that that uid is present in the author_prefs table. This function is necessary in a couple places because of bridging.
Example:
build_alphalinks
This function is used to build the alphabet links list on pages such as Browse Titles and Authors. Two arguments are passed to the function: the page url and the current letter (if any).
Example: