Guide Category

134

API for module development

API is designed for create modules and write modifications that are compatible with older and future versions of Datalife Engine script. If you use an API to retrieve or query data from the database, you can be sure that the code will work in future versions, so you can create and alter testing module and adapt the code to use with a new version. Also, when using the API you don't need to write your own functions to retrieve data, there is no need to include and declare needed to work with the database classes. Simply include the API file with your module and start using its features, everything else will work just fine and functions of the classes will control your modules to get it to fit together.
dlestarter
API for module development API is designed for create modules and write modifications that are compatible with older and future versions of Datalife Engine script. If you use an API to retrieve or query data from the database, you can be sure that the code will work in future versions, so you can create and alter testing module and adapt the code to use with a new version. Also, when using the API you don't need to write your own functions to retrieve data, there is no need to include and declare needed to work with the database classes. Simply include the API file with your module and start using its features, everything else will work just fine and functions of the classes will control your modules to get it to fit together.

To use the API in module, you have to include the line of code to your module file:

include ('engine/api/api.class.php');
In this case you do not need to worry whether there is a connection to the database or not connected or include required classes or not. This code you can use inside the files within DLE and just the other scripts that are not related to DLE. This what you can organize the standard integration of DLE with other scripts ex. forums.

List of API functions:

  • $dle_api->take_user_by_id( int $id [, string $select_list] );
    Receiving array with information about the user by ID. The optional parameter $select_list points to a list of database fields to be obtained, or * for all. Returns an array of information about the user or false if the user is not found.
  • $dle_api->take_user_by_name( string $name [, string $select_list]);
    Receiving array with information about the user by username. The optional parameter $select_list points to a list of database fields to be obtained, or * for all. Returns an array of information or false, if the user is not found.
  • $dle_api->take_user_by_email( string $email [, string $select_list]);
    Receiving array with information about the user by E-Mail. The optional parameter $select_list points to a list of database fields to be obtained, or * for all. Returns an array of information or false, if the user is not found.
  • $dle_api->take_users_by_group( int $group_id [, string $select_list [, int $limit]]);
    Receiving array with information about the users by user group number. The optional parameter $select_list points to a list of database fields to retrieve. The optional parameter $limit limit the number of points to user groups. Returns an array of information or false, if user groups are not found.
  • $dle_api->take_users_by_ip( string $ip, [, bool $like [, string $select_list [, int $limit]]]);
    Get a list of users by IP, the second parameter specifies the $like to use when searching for an exact match or inaccurate. The optional parameter $select_list points to a list of database fields to retrieve. The optional parameter $limit limit the number of points to user groups. Returns an array of information or false, if user groups are not found.
  • $dle_api->change_user_name( int $user_id, string $new_name);
    Change the user's login name. user_id ID is user ID to be changed. new_name is new user login. Return value: true if successfully completed, false if the new name is already taken by another user.
  • $dle_api->change_user_pass( int $user_id, string $new_pass);
    Changing the password of the user. user_id is user ID to get new password changed. new_pass is new password to change.
  • $dle_api->change_user_email( int $user_id, string $new_email);
    Changing user E-Mail. user_id is ID user which will change the E-Mail. new_email is new E-Mail to change. Return Values​​: 1 - successful, -1 - The new E-Mail already exists, -2 - Incorrect E-mail.
  • $dle_api->change_user_group( int $user_id, int $new_group);
    Changing a user group. user_id is user group to be changed. new_group is the ID of the new user group. Return value: true if successfully completed, false if you specify a non-existing group ID.
  • $dle_api->external_auth( string $login, string $password);
    Log in using username and password. Return values​​: true - authorization is successful, false - password or username is not valid.
  • $dle_api->external_register( string $login, string $password, string $email, int $group);
    User registration in the database. The function is passed through: Login (username), Password, E-mail and group ID number which registered user will be added to. Return Values​​: 1 - successful, -1 - a new username already exists, -2 - the new E-Mail already exists, -3 - Incorrect E-Mail, -4 - given the non-existing group.
  • $dle_api->send_pm_to_user ( int $user_id, string $subject, string $text, string $from);
    Sending a message to the user. $user_id is recipient user ID. $subject is subject of the message. $text is text messages. $from is sender username. Return Values​​: 1 - successful, -1 - recipient is not found, 0 - Database Error.
  • $dle_api->load_table ( string $table [, string $fields [, string $where [, bool $multirow [, int $start [, int $limit [, string $sort [, string $sort_order]]]]]]]);

    Getting information from a database table.
    • - $table - name of the table
    • - $fields - required fields separated by commas or * for all
    • - $where - condition to get data
    • - $multirow - a data row number or multiple rows
    • - $start - initial value to get data
    • - $limit - the number of records to get data, 0 - select all
    • - $sort - field, which is used for sorting
    • - $sort_order - direction of the sort
  • Returns an array with the data, or false if the database on the specified criteria did not match.
  • $dle_api->save_to_cache ( string $fname, mixed $vars);
    Writing data to cache file. $fname parameter specifies the name of the cache file without its extension. $vars - data to be written to the cache.
  • $dle_api->load_from_cache ( string $fname,  [, int $timeout [, string $type]]);
    Reading data from the cache file. $fname parameter specifies the name of the cache file without its extension. The optional parameter $timeout specifies the number of seconds during the information is cached consider relevant. If the cache file is outdated, then the function returns false. The optional parameter $type indicates the type of data that is stored in the cache, if not 'text' - will generate the stored array and returns an array of data.
  • $dle_api->clean_cache (  [string $name] );
    Deleting the cache. The optional parameter $name indicates a specific file name without an extension to be removed
  • $dle_api->get_cached_files();
    Getting an array containing the cache file name.
  • $dle_api->edit_config ( mixed $key,  [, string $new_value]);
    Edit, and save the script settings.
  • parameter  $key string or array
                    string: name of parameter
                    array: alternative array of parameters

    The parameter $new_value - the parameter value. Not used if specified $key array
  • $dle_api->take_news ( string $cat,  [, string $fields [, int $start [, int $limit [, string $sort [, string $sort_order]]]]]);
    Getting the news data

        - $cat  - news category, separated by commas
        - $fields - list of fields received news or * for all
        - $start - initial value to get data
        - $limit - the number of stories for the data, 0 - select all news
        - $sort - field, which is used for sorting
        - $sort_order - direction of the sort

    Returns the associated or alternative 2-х array with the news

  • $dle_api->checkGroup ( int $group );
    Checks if the group specified or not. Return value: true if the group exists, false if the group does not exist.
  • $dle_api->install_admin_module ( string $name, string $title, string $descr, string $icon [, string $perm] );
    Install or add the module in Admin Control Panel.

        - $name - name of the module, normally the .php file in folder engine/inc/, but without the file extension
        - $title - title of the module
        - $descr - description of the module
        - $icon - icon name for the module, no path. Icon must be added and located in the engine/skins/images/
        - $perm - information about groups who are allowed to display or access this module. This field may take the following values: group ID or all group ID or specify group ID separated by comma. For example: 1,2,3. if you specify "all" then the module will display all users who have access to admin control panel
  • $dle_api->uninstall_admin_module ( string $name );
    Removing the module from the Admin Control Panel.
  • $name - the name of the module to be removed removed
  • $dle_api->change_admin_module_perms ( string $name, string $perm );
    Change the group of users who are allowed to access to the module in the Admin Control Panel.

        - $name - name of the module
        - $perm - information about groups who are allowed to access to this module. This field may take the following values: group ID or all group ID or specify group ID separated by comma. For example: 1,2,3. if you specify all the module will display all users who have access to admin control panel

Develop a full API, and only started at the moment until API has a limited set of functions. We therefore ask all those interested in this API developers to visit this topic and leave your suggestions on what new features you want to see in new versions. Because only based on your needs, you can create a full API to cover all functions and all aspects of your request and features.

Related Tutorials

Review/Leave Comment

comments powered by Disqus