JCUSTOM MOD

an arcadem pro script mod system

Contents:

  1. About JCustom Mod & Version History
  2. Installation & Requirements
  3. Codex
    1. Games
    2. Users
    3. Favorites
    4. System
    5. Filters
    6. Event Hooks
    7. Cache & Page Cache
    8. URI Requests
    9. Utilities
    10. Errors
  4. Plugins
  5. Theme Development

1. About JCustom Mod

JCustom Mod is a mod system to improve your arcade site experience through the use of the newest web technology. This mod is actually just a subsystem or a container to handle various supported mod plugins in the best and most user friendly way.

Version History:

2. Installation & Requirements

Requirements:

Installation:
Installing a mod has never been this easy.

  1. Upload the mod system files & folders at /admin/ through your ftp.
  2. Open the page at /admin/jcustom_mod/ to start the installation (ex. http://example.com/admin/jcustom_mod/), click the proceeding buttons to install.
  3. After installation restart your admin panel. A new menu (labeled “jC”) shall be available containing JcMod Plugins and JcMod Settings.

3. Codex

3.i. Games

game_get_data( $gid, $force_all = false )

Gets a game's data.

Parameters

$gid:Int - the game ID
$force_all:Boolean - include the unpublished games; requires Game Meta plugin

Returns

Object - the game's data object

get_games( $args = array() )

Get a list of games data via optional arguments.

Parameters

$args:Array - game arguments for query; if omitted, returns all games

Default argument key fields primkey, gamename, description, tags, width, height, filename, category, totalplays, sponsor, swftype, highscore, userkey, imagesmall, imagelarge and gameurl can be a array of it's respective data type or the actual data type value itself. Same keys can be apended with "_exclude" so that the provided value shall be excluded, "_rel" so that the relationship of provided value is specified (>, >=, <, <=, !=, LIKE) other than equal (=), or "_end" so that the provided value is the higher limit for query comparison.

sql arguments
key data Type/possible values description
order String ASC, DESC, NONE, RAND the sorting order; defaults to DESC
orderby String the table field to sort by
limit Int the number of rows to return
offset Int the offset row

Returns

Array - a list of game's data objects that matched the arguments

Example

// this argument shall get 10 games from action category where
// primkeys should not be 1, 2 or 3 and is sorted by total plays
$args = array( "primkey_exclude" => array(1, 2, 3), "category" => "action", "orderby" => "totalplays", "limit" => 10 );
get_games( $args );

// this argument shall get 6 games from action & puzzle category
// where game name's have "ball" and width is less than 800
$args2 = array( "gamename" => "ball", "gamename_rel" => "LIKE", "category" => array("action", "puzzle"), "width_end" => 800, "limit" => 6 );
get_games( $args2 );

get_games_count( $args = array() )

Gets the number of games via optional arguments.

Parameters

$args:Array - game arguments for query; if omitted, returns number of all games

Returns

Int - number of games that matched arguments

get_game_categories( $args )

Gets a list of distinct game categories.

Parameters

$args:Array - game arguements for query but limited to keys: category, category_exclude, order, limit and force_all

Returns

Array - list of game categories that matched the arguments

get_similar_games( $gid_exclude, $category, $limit = 5 )

Gets a list of games from the same category.

Parameters

$gid_exclude:Int |Array - game ID's to exclude
$category:String - the category to relate from
$limit:Int - the number of games to get

Returns

Array - a list of game's data objects

Note: If the result from the category is less than the limit, random games will be included to fill the limit.

3.ii. Users

user_get_data( $userkey = NULL )

Gets the user data.

Parameters

$userkey:Int - the user's ID. If omitted, the currently logged in user's ID will be used.

Returns

Object - the user data

Filter Hooks

user-data - function( $userData ) - applies filters on the user data

user_get_id( $user = null )

Gets the user ID.

Parameters

$user:String | Int |Object - the user name, user ID or user data. If omitted, the currently logged in user's ID will be returned.

Returns

Int - the user ID

get_users( $args = array() )

Gets a list of users data via optional arguments

Parameters

$args:Array - user arguments for query; if omitted, returns all users

Default argument key fields userkey, username, permissions, ip, datereg, email, gamesplayed, avatar and academpoints can be a array of it's respective data type or the actual data type value itself. Same keys can be apended with "_exclude" so that the provided value shall be excluded, "_rel" so that the relationship of provided value is specified (>, >=, <, <=, !=, LIKE) other than equal (=), or "_end" so that the provided value is the higher limit for query comparison.

sql arguments
key data Type/possible values description
order String ASC, DESC, NONE, RAND the sorting order; defaults to DESC
orderby String the table field to sort by
limit Int the number of rows to return
offset Int the offset row

Returns

Array - a list of user's data objects that matched the arguments

user_add_points( $userkey, $points = 1 )

Adds arcadem points to the user

Parameters

$userkey:Int - the user's ID
$points:Int - [default = 1] the points to add

Returns

Boolean - true on success; otherwise false

user_form_loginout( $return_hash = false )

A shortcut to either call user_form_logout() or user_form_login() if the user is already logged in or not respectively.

Paramters

$return_hash:Boolean - [default = false] if true, nothing will be printed, instead will return the input hash value. Note that the POST request would require the hash in a variable named either "user-logout" or "user-login" repectively.

Returns

String - the request hash only if $return_hash is set to true; otherwise null

user_form_login( $return_hash = false )

Prints a hidden input field or returns the variable hash for logging in on if the user is not already logged in.

Parameters

$return_hash:Boolean - [default = false] if true, nothing will be printed, instead will return the input hash value. Note that the POST request would require the hash in a variable named "user-login"

Returns

String - the request hash only if $return_hash is set to true; otherwise null

Event Hooks

login_success - function( $userkey ) - triggered if user was successfully logged in. The logged in user's ID is passed.
login_user_pending - function( $userData ) - triggered if the user's account is not yet activated (through email activation or admin approval). The user's data is passed.
login_fail - function() - triggered if the user name & password does not match or exist

Example

<form method="post" action="<?php echo get_my_url();?>">
<?php user_form_login();
/* output:
<input type="hidden" name="user-login" value="80b39353a93c99f0eaeefb94f627e585" />
*/ ?>
<strong>Login: </strong><br/>
<label for="username">Username</label>:
<input type="text" id="username" name="name" title="User Name" /><br/>
<label for="username">Password</label>:
<input type="password" id="password" name="pass" title="Password" />
<input type="submit" value="Log in" />
<input type="checkbox" value="1" id="remember" name="rememb" title="Remeber" checked="checked" />
<label for="remember">Remember</label>
</form>

user_form_logout( $return_hash = false )

Prints a hidden input field or returns the variable hash for logging out only if the user is currently logged in.

Parameters

$return_hash:Boolean - [default = false] if true, nothing will be printed, instead will return the input hash value. Note that the POST request would require the hash in a variable named "user-logout"

Returns

String - the request hash only if $return_hash is set to true; otherwise null

Event & Filter Hooks

logout_success - function( $userID ) - triggered on successful log out. The just logged out user's ID is passed.

Example

<form method="post" action="<?php echo get_my_url();?>">
  <?php user_form_logout();
    /* output:
      <input type="hidden" name="user-logout" value="518e72e4106c6f7255d12f90ccd8f6a3" />
    */ ?>
  <input type="submit" value="Log out" />
</form>

user_form_new_account( $return_hash = false )

Prints a hidden input field or returns the variable hash for new user account form.

Parameters

$return_hash:Boolean - [default = false] if true, nothing will be printed, instead will return the input hash value. Note that the POST request would require the hash in a variable named "new-user-account"

Returns

String - returns the request hash only if $return_hash is set to true; otherwise null

Event Hooks

new-user-account - function( $userkey ) - triggered on successful new account submission. The new user's ID is passed.

Filter Hooks

user-data-default-avatar - function( $avatar ) - applies a filter to alter the default avatar image

System Messages

user/event/new_account/error/required_username - A unique username is required
user/event/new_account/error/invalid_username - Username must be at least 3 and maximum 50 charaters
user/event/new_account/error/required_password - A strong (recommended) password is required
user/event/new_account/error/invalid_password - Password must be at least 3 and maximum 50 charaters
user/event/new_account/error/inconsistent_password - Password was not consistent, please re-type your password
user/event/new_account/error/required_email - An email address is required
user/event/new_account/error/invalid_email - A valid email address is required
user/event/new_account/error/invalid_email_taken - The email address you provided has already been used to register an account

user_eval_new_account( $echo = false )

Evaluates the new user account submission request. Prints or returns a corresponding message if new account is successful, otherwise errors are printed or returned. The new account is automatically proccessed on "post_init" custom event only if the POST variable "new-user-account" hash is valid (retrieved from this user_form_new_account() method). Field names defaultly required are "username", "password", "password2", "email" and "new-user-account" which determines that the request is for new user accounts.

Parameters

$echo:Boolean - set to true to print the response

Returns

String - the corresponding text on success
Array - an array list of jc_error on fail

System Messages

user/event/new_account/success - <h3>Account Successfully Created!</h3>\n<p>Your account was successfully created, you can now start by logging in and editting your profile.<br/><br/>Thank your for signing up &amp; enjoy!</p>\n
user/event/new_account/wait_admin_approval - <h3>Waiting Admin Approval</h3>\n<p>Your new account is now waiting approval from the admins. Please wait for a confirmation within 48hrs.<br/><br/>Thank you for signing up!</p>\n
user/event/new_account/wait_activation - <h3>Waiting Activation</h3>\n<p>Your new account is now waiting activation, we have already sent you an email containing details on how to activate your account.</p>\n

user_account_status( $userkey )

Gets a text, that can be printed, about the current account status of the user. If however the actual user permission variable is needed, use the user data variable permissions instead.

Parameters

$userkey:String - the user ID

Returns

String - a text about the current user account status; otherwise null if user does not exists or is already activated

System Messages

user/event/account_status/wait_activation - <h3>Waiting Activation</h3>\n<p>We have already sent you an email containing details on how to activate your account.<br/><br/><u><a href=\"%s\">RESEND ACTIVATION EMAIL</a></u></p>\n
user/event/account_status/wait_admin_approval - <h3>Waiting Admin Approval</h3>\n<p>Your account is now waiting approval from the admins. Please wait for a confirmation within 48hrs.

user_send_email_activation( $userkey, $return = false )

Sends an email containing account activation details for the pending user and displays a success text.

Parameters

$userkey:String - the user ID
$return:String - [default = false] if true will return the success text

Returns

Boolean - true on success
jc_error - a jc_error corresponding on why send email failed

System Messages

user/event/send_email_acct_activate/success - <h3>Waiting Activation</h3>\n<p>We have sent you an email containing details on how to activate your account, you should receive it shortly.</p>\n
user/event/send_email_acct_activate/error - <h3>Sending Activation Email Failed</h3>\n<p>An error occured while trying to send the activation details to your email. It is required to activate your account to experience registered member's benifits.<br/><br/><u><a href=\"%s\">RESEND ACTIVATION EMAIL</a></u></p><br/><br/>\n

Note: If file %theme_path%/templates/email_accnt_activate.php exists, this will be used as email contents template.

user_validate_activation( $return = false )

Validates activation and prints or returns a correspoding message on the user account page.

Parameters

$return:String - [default = false] if true will return the success text

Returns

Boolean - true on success; otherwise null
String - if $return is true, will return the corresponding message instead

user_form_update_account( $return_hash = false )

Displays a request input field for updating user account. This method should be called within the html form.

Parameters

$return_hash:Boolean - [default = fase] if true, nothing will be printed, instead will return the input hash value. Note that the POST request would require the hash in a variable named "user-update-account"

Returns

String - returns the request hash only if $return_hash is set to true; otherwise null

user_update_avatar( $return_hash = false )

Displays a request input field for updating user avatar. This method should be called within the html form.

Parameters

$return_hash:Boolean - [default = fase] if true, nothing will be printed, instead will return the input hash value. Note that the POST request would require the hash in a variable named "user-update-avatar"

Returns

String - returns the request hash only if $return_hash is set to true; otherwise null

user_evaluate_update( $echo = false )

Evaluates whether the request for update account/avatar is successful else displays corresponding errors.

Parameters

$echo:Boolean - set to true to print the response

Returns

Boolean - true on success
Array - an array list of jc_error on fail

Example

<?php if ( user_evaluate_update() === true ) echo "<strong>Updated Avatar</strong>"; ?>
<form method="post" enctype="multipart/form-data">
  <?php user_update_avatar();
    // output: <input type="hidden" name="user-update-avatar" value="5633d4514152f0965773eb033f87c7ed"/>
    user_update_account();
    // output: <input type="hidden" name="user-update-account" value="ccca259545458400c39528e3042d6afa"/>
  ?>
  <input type="file" name="avatar"/>
  <input type="submit" value="submit"/>
</form>

user_form_forgot_password( $return_hash = false )

Sends an email containing details on how to reset the user's password and displays a corresponding message if a reset password POST request exists, else displays an input field for reset password request (call this method within the form).

Parameters

$return_hash:Boolean - [default = fase] if true, nothing will be printed, instead will return the input hash value. Note that the POST request would require the hash in a variable named "user-update-avatar"

Returns

Boolean - true if successful
jc_error - a jc_error corresponding why the update failed

user_get_reset_password()

Resets the password and displays the new password if a reset POST request exists.

Returns

Boolean - true if successful
jc_error - a jc_error corresponding why the update failed

Example

	<form method="post">
<?php
if ( is_jc_error($new_password = user_get_reset_password()) || ! $new_password ):
if ( true === $forgot = user_forgot_password() ):
echo "<br/><br/><br/>";
else:
?>
<p>If you have already registered but forgot your<br/>password use this to reset your password.</p>
<label for="email">Email address:</label><br />
<input type="text" name="email" id="email" size="30" /><br />
<input type="submit" value="Submit" /><br />
<?php endif; // end user_forgot_password() ?>
<?php else: // if there is new password ?>
<h3>Reset Password Successful</h3>
<p>Your request was validated and accepted. Your new password was reset, so PLEASE NOTE your new password:</p>
<h1><?php echo $new_password;?></h1>
<p><small>This new password is randomly generated so it is highly recommended to login now and change your password into something else you could remember.</small></p>
<?php endif; ?>
</form>

Parameters

Returns

3.iv. System

get_table_name( $name )

Gets the corresponding sql table name from given name

Parameters

$name:String - the specified nickname for the sql table

Returns

String - the sql table name

Pre-Defined Table Values:

name sql table name
optionsjc_options
gamesAMCMS_games
usersAMCMS_users
favoritesAMCMS_favs
categoriesAMCMS_cat
highscoresAMCMS_highscores
challengesAMCMS_challenges
old_prefAMCMS_pref

add_table_name( $name, $value )

Adds a database table name with a nickname

Parameters

$name:String - the specified nickname for the sql table
$value:String - the actual sql table name

Returns

Boolean - true on success; false otherwise

table_name_exists( $name )

Determines whether the table is already defined

Parameters

$name:String - the specified name for the sql table

Returns

Boolean - true if it exists; null otherwise

get_info( $name )

Gets the information value

Parameters

$name:String - the information name to get

Returns

String - the information data

Information Summary:

name description
script_version the version of the running script
arcade_url the url where aracdem is running
uploads_url url of upload directory
cache_url url of cache directory
games_url url of game media directory
games_imgs_url url of game images directory
admin_url url of admin panel
mod_url url of jcustom mod area
mod_plugin_url url of jcustom mod plugins
arcade_path the absolute path of the arcadem script
uploads_path the absolute path for uploads
cache_path the absolute path for cache files
games_path the absolute path for game media files
games_imgs_path the absolute path for game images files
admin_path the absolute path of admin panel
mod_path the absolute path of jcustom mod
mod_plugin_path the absolute path of jcustom mod plugins
current_theme the currently selected theme name
theme_url the url of the selected theme
theme_path the absolute path of the selected theme
arcade_title the specified arcade title
html_title the HTML title to use for the current page
html_meta_desc the HTML meta description to use for the current page
html_meta_tags the HTML meta tags to use for the current page

remember_var( $location, $use_session = false)

Gets the stored data from a path variable

Parameters

$location:String - path on how the data is loaded as container name & var name
$use_session:Boolean - whether the data is stored as a $_SESSION variable, else data is temporarily stored on page load session

Returns

Mixed - the corresponding data if variable exist; null otherwise

remember_var( $location, $use_session = false, $value )

Stores data on a path variable

Parameters

$location:String - path on how the data is saved as container name & var name
$use_session:Boolean - whether the data is stored as a $_SESSION variable, else data is temporarily stored on page load session
$value:Mixed - the data to be stored

Returns

$value:Mixed - the stored data on success; false otherwise

Example

remember_var( "games/my_var", false, "apple" );
echo remember_var( "games/my_var" );
  /* output:
    apple
  */

forget_var( $location, $use_session = false)

Deletes a path or path variable

Parameters

$location:String - path on how the data is loaded as container name & var name
$use_session:Boolean - whether the data is stored as a $_SESSION variable, else data is temporarily stored on page load session

Returns

Boolean - true on success; false otherwise

get_option( $name )

Gets the corresponding system option value

Parameters

$name:String - the option name to get, must NOT be sql escaped

Returns

Mixed - the option value; null otherwise

add_option( $name, $value, $autoload = false )

Saves a given data value as a system option

Parameters

$name:String - the option name to add, must NOT be sql escaped
$value:Mixed - the data to save, can be any data type except resource, must NOT be sql escaped
$autoload:Boolean - whether the option should be loaded as initial options on system start

Returns

Int - the sql insert ID on success
jc_error - a jc_error corresponding on why insert failed

Note: Option name must not exists as this would return a jc_error. SQL sanitation occurs on the insert method.

add_options( $list )

Saves an array list of given data values as a system options

Parameters

$list:Array - list of given data values as system options

Returns

Int - sql insert ID on success
jc_error - a jc_error corresponding on why insert failed

Note: The option is added only if the option name does not exists yet. SQL sanitation occurs on the insert method.

Example

$options = array(
  array( "name"=>"my_var", "value"=>"my_val","autoload"=>true ),
  array( "name"=>"my_var2","value"=>"another_value","autoload"=>false) );

add_options( $options );

update_option( $name, $value, $add_autoload = false )

Updates a given data value as a system option

Parameters

$name:String - the option name to update, must NOT be sql escaped
$value:Mixed - the data to save, can be any data type except resource, must NOT be sql escaped
$autoload:Boolean - whether the option should be loaded as initial options on system start, only applies if option does not exist

Returns

Boolean - true on success
jc_error - a jc_error corresponding on why update failed

update_options( $list )

Updates an array list of given data values as system options

Parameters

$list:Array - array of options to add

Returns

Boolean - true on success
jc_error - a jc_error corresponding on why update failed

delete_option( $name )

Deletes a system option

Parameters

$name:String - the option name to delete, must NOT be sql escaped

Returns

Int - the number of deleted rows on success
jc_error - a jc_error corresponding on why delete failed

delete_options( list )

Deletes an array list of system options

Parameters

$list:Array - array of option names to delete

Returns

Int - the number of deleted rows on success
jc_error - a jc_error corresponding on why delete failed

get_system_message( $path, $msg )

Recovers the appropriate message string if designated language file is set else if not, the default message is returned

Parameters

$path:String - path on how the string is saved as container name & var name
$msg:String - the default message string

Returns

String - the appropriate message

generate_hash( $str )

Generates an MD5 hash for the session. Useful for enforcing POST securities.

Parameters

$str:String - the key string

Returns

String - the hash value

3.v. Filters

add_filter( $name, $callback, $priority = 4, $args = array() )

Adds a data filter for the specified filter name.

Parameters

$name:String - the filter name
$callback:Callback - a callback that has to recieve the passed data to filter then return it
$priority:Int - [default = 4] the execution priority of the filter (min = 0, max = 9)
$args:Array - [optional] an array of arguments that would be passed along the data

Returns

Boolean - true on success
jc_error - a jc_error corresponding why the method failed

Example

function my_filter( $data ){
  return str_replace( "a", "e", $data );
}

add_filter( "custom_filter", "my_filter" );

echo apply_filter( "custom_filter", "apple and banana" );
  /* output:
    epple end benene
  */

remove_filter( $name, $callback, $priority = 4 )

Removes an already defined filter for the specified filter name

Parameters

$name:String - the filter name
$callback:Callback - the callback to recieve the passed data to filter
$priority:Int - [default = 4] the execution priority of the filter (min = 0, max = 9)

Returns

Boolean - true on success; otherwise false

clear_filters( $name )

Removes all the defined filters for the specified filter name

Parameters

$name:String - the filter name

Returns

Boolean - true on success; otherwise false

has_filters( $name )

Determines whether the speicified filter name has defined filters

Parameters

$name:String - the filter name

Returns

Boolean - true if it has defined filter; otherwise false

has_filter( $name, $callback, $priority = 4 )

Determines whether the specified filter name has the callback defined as one of it's filters

Parameters

$name:String - the filter name
$callback:Callback - the callback to recieve the passed data to filter
$priority:Int - [default = 4] the execution priority of the filter (min = 0, max = 9)

Returns

Boolean - true if the callback is a defined filter; otherwise false

apply_filter( $name, &$data )

Applies the specified name filters on the data

Parameters

$name:String - the filter name
&$name:Mixed - the data to filter; passed by reference

Returns

Mixed - the filtered data

get_filters( $name )

Gets all the filters & arguments on the specified filter name

Parameters

$name:String - the filter name

Returns

Array - the list of filters and their arguments

add_filters_from( $source_name, $dest_name )

Copies all the filters & arguments of a specific filter name to another filter name

Parameters

$source_name:String - the filter nameto copy from
$dest_name:String - the filter nameto copy to

Returns

Boolean - true on success; otherwise false

3.vi. Event Hooks

add_action( $name, $callback, $priority = 4 )

Adds a listener on a custom event

Parameters

$name:String - the event name
$callback:Callback - callback to be called when custom event is triggered
$priority:Int - [default = 4] the execution priority of the event (min = 0, max = 9)

Returns

Boolean - true on success
jc_error - a jc_error corresponding why the method failed

Example

function my_action(){
  echo "beep beep";
}

add_action( "custom_event", "my_action" );

execute_action( "custom_event" );
  /* output:
    beep beep
  */

remove_action( $name, $callback, $priority = 4 )

Removes the listener on the custom event

Parameters

$name:String - the event name
$callback:Callback - the callback
$priority:Int - [default = 4] the execution priority of the event (min = 0, max = 9)

Returns

Boolean - true on success; otherwise false

clear_actions( $name )

Removes all defined listeners on the custom event

Parameters

$name:String - the event name

Returns

Boolean - true on success; otherwise false

has_actions( $name )

Determines whether the custom event name has definedlisteners

Parameters

$name:String - the event name

Returns

Boolean - true if it has defined listeners; otherwise false

has_action( $name, $callback, $priority = 4 )

Determines whethere the callback defined as a listener of the custom event

Parameters

$name:String - the event name
$callback:Callback - the callback
$priority:Int - [default = 4] the execution priority of the event (min = 0, max = 9)

Returns

Boolean - true if callback is a defined listener; otherwise false

execute_action( $name, $data = NULL )

Triggers the custom event

Parameters

$name:String - the event name
$data:Mixed - [optional] an argument to be passed on each listener callback

has_executed_action( $name )

Determines if the custom event has already been triggered

Parameters

$name:String - the event name

Returns

Int - the number of times the event has been triggered; otherwise false

get_actions( $name )

Gets all the callback listeners of the custom event

Parameters

$name:String - the event name

Returns

Array - the list of callback listeners

3.vii. Cache & Page Cache

cache_save( $path, $data )

Parameters

:String -

Returns

Parameters

:String -

Returns