corefunctions.php
 
Notifications
Clear all

corefunctions.php

27 Posts
2 Users
0 Reactions
6,383 Views
(@tammy)
Posts: 2577
Member Moderator
Topic starter
 

This thread 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.  It'll hopefully make things easier for you and for those who use your work. 

This thread will be locked to keep it uncluttered.  If you have questions about any of these functions, please start a new thread.


 
Posted : 02/01/2007 11:28 pm
(@tammy)
Posts: 2577
Member Moderator
Topic starter
 

==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);
}


 
Posted : 02/01/2007 11:30 pm
(@tammy)
Posts: 2577
Member Moderator
Topic starter
 

==descript==

Use this function to sanitize form input to keep people from posting scripts and other dangerous content.

Example:

$summary = descript($_POST['summary']);


 
Posted : 02/01/2007 11:32 pm
(@tammy)
Posts: 2577
Member Moderator
Topic starter
 

==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( );


 
Posted : 02/01/2007 11:33 pm
(@tammy)
Posts: 2577
Member Moderator
Topic starter
 

==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:

$story = format_story($story);


 
Posted : 02/01/2007 11:34 pm
(@tammy)
Posts: 2577
Member Moderator
Topic starter
 

==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")."')");


 
Posted : 02/01/2007 11:34 pm
(@tammy)
Posts: 2577
Member Moderator
Topic starter
 

==format_email==
This function displays emails replacing the @ and . symbols with [at] and [dot] to help foil spam bots.

Example:

$email = format_email($user['email']);


 
Posted : 02/01/2007 11:35 pm
(@tammy)
Posts: 2577
Member Moderator
Topic starter
 

==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);


 
Posted : 02/01/2007 11:38 pm
(@tammy)
Posts: 2577
Member Moderator
Topic starter
 

==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);


 
Posted : 02/01/2007 11:38 pm
(@tammy)
Posts: 2577
Member Moderator
Topic starter
 

==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.  The default length is 75 characters and the default delimiter is "..."

truncate_text(string string[, int length][, string delimiter])

Examples:

$shortSummary = truncate_text($summary);
$longerSummary = truncate_text($summary, 300);
$customDelimitedSummary = truncate_text($summary, 75, "---");


 
Posted : 02/01/2007 11:43 pm
(@tammy)
Posts: 2577
Member Moderator
Topic starter
 

==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!");


 
Posted : 02/01/2007 11:44 pm
(@tammy)
Posts: 2577
Member Moderator
Topic starter
 

==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);


 
Posted : 02/01/2007 11:44 pm
(@tammy)
Posts: 2577
Member Moderator
Topic starter
 

==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);


 
Posted : 02/01/2007 11:45 pm
(@tammy)
Posts: 2577
Member Moderator
Topic starter
 

==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);


 
Posted : 02/01/2007 11:45 pm
(@tammy)
Posts: 2577
Member Moderator
Topic starter
 

==isNumber==
This function is passed a variable and returns true if the variable is an integer number.  Use this to check
input from users, especially id numbers passed via $_GET.

Example:

$sid = isset($_GET['sid']) && isNumber($_GET['sid']) ? $_GET['sid'] : 0;


 
Posted : 02/01/2007 11:46 pm
Page 1 / 2
Share: