Procedural File: dpfunctions.php
SOURCE LOCATION: /lib/dpfunctions.php
File Overview
Common functions available to all objects in the universe
DutchPIPE version 0.4; PHP version 5 LICENSE: This source file is subject to version 1.0 of the DutchPIPE license. If you did not receive a copy of the DutchPIPE license, you can obtain one at http://dutchpipe.org/license/1_0.txt or by sending a note to license@dutchpipe.org, in which case you will be mailed a copy immediately.
Functions
dp_file_get_contents [line 184]
mixed dp_file_get_contents(
string $path
)
|
|
Reads entire file within the universe directory into a string
Reads and returns the given file. The file should be within the directory defined by DPUNIVERSE_PATH, for example /page/foo.txt. When translations are enabled an alternative file can be created and used instead. For this to work, the file must be placed in the directory defined by DPSERVER_LOCALE in the directory defined by DPSERVER_GETTEXT_LOCALE_PATH, for example /home/dutchpipe/locale/nl_NL/page/foo.txt.
PARAMETERS:
|
string |
$path: |
path within the universe directory |
dp_upload_image [line 296]
boolean dp_upload_image(
string &$object , string $from , string $to
)
|
|
Copies and processes an uploaded image for a given object
Copies an image for a given user with the given file path to a given destination. Resizes the image if the width in pixels exceeds DPSERVER_OBJECT_IMAGE_MAX_WIDTH and/or the height exceeds DPSERVER_OBJECT_IMAGE_MAX_HEIGHT. The image type must defined in DPSERVER_OBJECT_IMAGE_VALID_TYPES ("gif", "jpg" or "png" by default).
PARAMETERS:
|
string |
&$object: |
user who will use yhis avatar |
|
string |
$from: |
path to uploaded avatar image |
|
string |
$to: |
path of copied/resulting image |
get_age2string [line 234]
string get_age2string(
int $age
)
|
|
Gets a short, descriptive string for an age in seconds
This method is used for example to show the age of users. A new user could just be "1 minute and 15 seconds" old, while addicts could be hanging around for "2 years, 74 days and 20 hours".
PARAMETERS:
|
int |
$age: |
number of seconds |
| RETURNS: | string | Short, descriptive age string |
get_current_dpobject [line 52]
object Reference &get_current_dpobject(
)
|
|
Gets the current object performing an action
This can also be a computer controlled character. If the chain of execution that caused this function to be called isn't the result of a user or npc performing an action, FALSE is returned. If the current object is a user performing an action, get_current_dpobject doesn't necessarily equal get_current_dpuser. Someone or something might force the user the perform an action.
| RETURNS: | object Reference | to user object of FALSE for no current user |
get_current_dpuniverse [line 69]
object Reference &get_current_dpuniverse(
)
|
|
Gets the current universe handling the current user
The universe object keeps track of all objects and provides methods such as newDpObject. Usually and currently there's just the one universe object. In the future there might be more, for instance to allow users to switch between different worlds without having to log in again.
| RETURNS: | object Reference | to user object of FALSE for no current user |
get_current_dpuser [line 32]
object Reference &get_current_dpuser(
)
|
|
Gets the current user connected to the server
If a user page or AJAX request caused the current chain of execution that caused this function to be called, that user object is returned. Otherwise FALSE is returned. For example, if the chain of execution if caused by a setTimeout, this will return FALSE.
| RETURNS: | object Reference | to user object of FALSE for no current user |
void inherit(
string $path
)
|
|
Includes universe object
This is a wrapper around require_once. You can only inherit in DPUNIVERSE_PREFIX_PATH (dpuniverse/ in the standard distribution), which is the top directory for this function. Use the constants from config/dpuniverse.ini to form paths. Examples (from dpuniverse/page/login.php): inherit(DPUNIVERSE_STD_PATH . 'DpPage.php'); inherit(DPUNIVERSE_INCLUDE_PATH . 'events.php');
PARAMETERS:
|
string |
$path: |
path to class file within dpuniverse/ |
is_dp_callable [line 139]
boolean is_dp_callable(
mixed &$var
)
|
|
Verifies that the contents of a variable can be called as a method
Identical to the PHP is_callable method, except that it can be not be the name of a function stored in a string variable, it must be an object and the name of a method within the object, like this: array($SomeObject, 'MethodName')
PARAMETERS:
|
mixed |
&$var: |
variable to check |
is_whole_number [line 212]
boolean is_whole_number(
mixed $var
)
|
|
Is the given integer or string a whole positive number?
PARAMETERS:
|
mixed |
$var: |
the integer of string to check |
| RETURNS: | boolean | TRUE for a whole positive number, FALSE otherwise |
make_random_id [line 200]
string make_random_id(
[ $base = 16] , string $length
)
|
|
Gets a 32-character random string
PARAMETERS:
|
string |
$length: |
optional different length <= 32 |
|
|
$base: |
|
| RETURNS: | string | random characters |
new_dp_property [line 86]
array new_dp_property(
[mixed $value = NULL] , [string $setter = NULL] , [string $getter = NULL]
)
|
|
Initializes a new DutchPIPE property in an object
Initializes a property which can be accessed in various ways.
PARAMETERS:
|
mixed |
$value: |
the initial value of the property if any |
|
string |
$setter: |
optional method to call when setting value |
|
string |
$getter: |
optional method to clal for retreival |
| RETURNS: | array | A custom data structure, don't tamper with it |
parse_dp_callable [line 153]
void parse_dp_callable(
mixed &$var
)
|
|
Replaces the contents of a callable variable
Checks if the given variable can be called as a method with is_dp_callable. If it is, calls the method and replaces the variable with the result.
PARAMETERS:
|
mixed |
&$var: |
variable to check |
|
|