Core functions and variables

Enano's core API consists of a set of functions that enable basic functionality, such as redirecting the user, creating links, and basic data storage.

Site configuration


mixed getConfig(string $config_name, mixed $default_value)

This function is very simple: it allows you to fetch a value from the site configuration. The $default_value parameter can be used to either indicate to your script that an entry is missing (by specifying false or null) or silently ignoring a missing configuration value and using a default.


void setConfig(string $config_name, mixed $config_value)

Stores a value in the site configuration. If $config_value is false, the entry will be deleted from the site configuration; any other value will be cast to a string.

URL creation


This is a constant that should be prepended to all your links to Enano PHP files such as cron.php and ajax.php. It never has a trailing slash.

echo '<a href="' . scriptPath . '/ajax.php">A link to ajax.php.</a>';


A constant. The functional equivalent of scriptPath but for static files such as images.

echo '<img alt="Lock icon" src="' . cdnPath . '/images/lock48.png" />';


A constant. The prefix for all page URLs. Avoid using this - you want makeUrl() and makeUrlNS() instead. Included here only for completeness.


string makeUrl(string $url_part, string $query_string = false, bool $htmlspecialchars = false)

Generates a relative URL. $url_part is the page ID including the namespace prefix. Most of the time you'll use this only when parsing text entered by the user; the rest of the time you will want to use makeUrlNS(). The query string should not contain a question mark.


string makeUrlNS(string $namespace, string $page_id, string $query_string = false, bool $htmlspecialchars = false)

Generates a relative URL, but allows you to specify the namespace and page ID separately. More convenient than makeUrl() in most cases.


string makeUrlComplete(string $namespace, string $page_id, string $query_string = false, bool $htmlspecialchars = false)

Generates an absolute URL. The parameters are exactly the same as makeUrlNS().

Database access

Always use the database abstraction layer ($db) to access the database, to maintain code portability.

All of these require you to import the $db global instance.

global $db;


A string constant, this is the prefix for all the tables in Enano's database. You should plan to use it before all tables in your SQL queries. Be sure to test any plugins you write on Enano installations that use different table prefixes so that you can identify places where you might have missed this.

$urlname = $db->escape($urlname);
$q = $db->sql_query('SELECT urlname, namespace FROM ' . table_prefix . "pages WHERE urlname = '$urlname';");


resource sql_query(string $query, bool $process_first = true)

Sends a query to the database. If the query fails, the return will cast to false. If $process_first is false, the query will not be heuristically checked for vulnerabilities. NEVER set $process_first to false unless you are planning to do lots of queries in your page (200 or more).


resource sql_unbuffered_query(string $query, bool $process_first = true)

Sends a query to the database but does not immediately fetch all results. This is good for queries that may produce many results that you do not plan to fetch. If the query fails, the return will cast to false. The behaviour and related admonishment for $process_first are the same as for $db->sql_query().


void _die(string $message = false)

Exits the script, showing the optional message if specified. Always check every single query for errors and call this method if your query fails.


array fetchrow(resource $result = false)

Fetches one row of the result as an associative array. If $result is not specified, the last return from $db->sql_query() is used.


array fetchrow_num(resource $result = false)

Fetches one row of the result as a numbered array. If $result is not specified, the last return from $db->sql_query() is used.


int numrows(resource $result = false)

Tells you how many rows were returned in the given result resource, or the last query's result if $result is not specified. Does not work on unbuffered queries.


string escape(string $value)

Escapes a string value so that it can safely be sent through a SQL query.

Other DBAL methods

The database abstraction layer is documented in significant part; you may wish to generate your own documentation with phpDoc to see documentation for more advanced database functionality.

Displaying the page


void header()

Displays the first half of the page up to and including the page title.


void footer()

Displays the second half of the page once you are done writing your content.


void set_title(string $title)

Set the page title.

User information

string $session->username

The current user's username, or an IP address if not logged in.

bool $session->user_logged_in

Set to true if the user is logged in, and false otherwise.

int $session->user_id

The numeric ID (the primary key in the users table) of the current user.

int $session->user_level

The highest authentication level the user is allowed to go. One of USER_LEVEL_GUEST, USER_LEVEL_CHPREF, USER_LEVEL_MOD, or USER_LEVEL_ADMIN.

int $session->auth_level

The current level at which the user is authenticated. One of USER_LEVEL_GUEST, USER_LEVEL_MEMBER, USER_LEVEL_CHPREF, USER_LEVEL_MOD, or USER_LEVEL_ADMIN.

Categories: (Uncategorized)