Api¶
Class gila¶
-
class
gila
¶ Common methods for Gila CMS
-
controller
($c, $file, $name=null)¶ (static) Register a new controller.
Parameters: - $c (string) – Controllers name
- $file (string) – Controller’s filepath without the php extension
- $name (string) – Optional. Controller’s class name, $c is used by default
Example:
gila::controller('my-ctrl', 'my_package/controllers/ctrl','myctrl');
-
route
($r, $fn)¶ (static) Registers a function call on a specific path.
Parameters: - $r (string) – The path
- $fn (Function) – Callback for the route
Example:
gila::route('some.txt', function(){ echo 'Some text.'; });
-
onController
($c, $fn)¶ (static) Registers a function to run right after the controller class construction.
Parameters: - $c (string) – The controller’s class name
- $fn (Function) – Callback
Example:
gila::route('blog', function(){ blog::ppp = 24; });
-
action
($c, $action, $fn)¶ (static) Registers a new action or replaces an existing for a controller.
Parameters: - $c (string) – The controller’s class name
- $action (string) – The action
- $fn (Function) – Callback
Example:
gila::action('blog', 'topics', function(){ blog::tagsAction(); });
-
before
($c, $action, $fn)¶ (static) Registers a function to run before the function of a specific action.
Parameters: - $c (string) – The controller’s class name
- $action (string) – The action
- $fn (Function) – Callback
Example:
gila::action('blog', 'topics', function(){ blog::tagsAction(); });
-
addLang
($path)¶ (static) Adds language translations from a json file.
Parameters: $path (string) – Path to the folder/prefix of language json files Example:
gila::addLang('mypackages/lang/');
-
widgets
($list)¶ (static) Register new widgets.
Parameters: $list (Array) – Example:
gila::widgets( [‘wdg’=>’my_package/widgets/wdg’] );
-
content
($key, $path)¶ (static) Register new content type.
:param String $key Name of content type :param String $path Path to the table file
Example:
gila::content( 'mytable', 'package_name/content/mytable.php' );
-
contentInit
($key, $init)¶ (static) Make changes on an existing content type.
Parameters: - $key (String) – Name of content type
- $init (Function) – Function to run when initializes the content type object
Example:
gila::contentInit( 'mytable', function(&$table){ // unlist a column from content administration &$table['fields']['column1']['list] = false; } );
-
packages
($list)¶ (static) Returns an array with the active packages names.
(static) Add new elements on administration menu.
Parameters: - $key (Array) – Index name
- $item (Array) –
Example:
gila::amenu('item', ['Item','controller/action','icon'=>'item-icon']);
(static) Add a child element on administration menu.
Parameters: - $key (string) – Index of the parent item.
- $item (Array) –
Example:
gila::amenu_child('item', ['Child Item','controller/action','icon'=>'item-icon']);
-
config
($key, $value = null)¶ (static) Sets or gets the value of configuration element.
Parameters: - $key (string) – Index of the element.
- $value (*) – (optional) The value.
Returns: The value if parameter $value is not sent.
-
setConfig
($key, $value='')¶ (static) Sets the value of configuration element.
Parameters: - $key (string) – Index of the element.
- $value (*) – The value to set.
-
updateConfigFile
()¶ (static) Updates the config.php file.
-
equal
($v1, $v2)¶ (static) Checks if two values are set and have the same value.
Parameters: - $v1 (*) – First value.
- $v2 (*) – Second value.
Returns: True or false.
-
hash
($pass)¶
(static) Generates a hash password from a string.
Parameters: $pass (string) – The string to be hashed. Returns: Hashed password. -
option
($option, $default='')¶ (static) Gets an option value.
Parameters: - $option (string) – Option name.
- $default (string) – (optional) The value to return if there option has not saved value.
Returns: The option value.
-
setOption
($option, $value='')¶ (static) Sets an option value.
Parameters: - $option (string) – Option name.
- $default (string) – The value to set.
-
hasPrivilege
($pri)¶ (static) Checks if logged in user has at least one of the required privileges.
Parameters: $pri (string/Array) – The privilege(s) to check. Returns: True or false.
-
dir
($path)¶ (static) Creates the folder if does not exist and return the path.
Parameters: $path (string) – Folder path. Returns: string
-
make_url
($c, $action='', $args=[])¶ (static) Generates a url.
Parameters: - $c (string) – The controller.
- $action (string) – The action.
- $args (Array) – The parameters in array.
Returns: The full url path to print.
Examples:
$url1 = gila::make_url('blog','post',[1]);`` returns mysite.com/blog/post/1 $url1 = gila::make_url('blog','',['page1']);`` returns mysite.com/blog/page1
-
mt
($arg)¶ (static) Returns modification times in seconds.
Parameters: $arg (string/Array) – Names of keys. Returns: string/Array Example:
gila::mt('my-table')
-
updateMt
($arg)¶ (static) Updates modification time in seconds. You can use this function from your model classes. The cm controller runs updateMt() for any content type in update action.
Parameters: $arg (string/Array) – Names of keys. Returns: string/Array Example:
gila::updateMt('my-table')
-
Class event¶
-
class
event
¶ Registers and fires events (hooks)
-
listen
($event, $handler)¶ (static) Sets a new function to run when an event is triggered later.
Parameters: - $event (string) – The event name.
- $handler (function) – The function to call.
-
fire
(string $event[, Array $params])¶ (static) Fires an event and calls all handling functions.
Parameters: - $event (string) – The event name.
- $params (function) – (optional) Parameters to send to handlers.
-
Class view¶
-
class
view
¶ Have methods that outputs the HTML
-
set
($param, $value)¶ (static) Sets a parameter from a controller action that can be used later from a view file.
Parameters: - $param (string) – The parameter name.
- $handler ((any)) – The value.
-
meta
($meta, $value)¶ (static) Sets a meta value that is printed later from view::head().
Parameters: - $meta (string) – The meta name.
- $value (string) – The value.
-
stylesheet
($href)¶ (static) Adds a new stylesheet link that is printed later from view::head().
Parameters: $href (string) – The href attribute from the link.
-
script
($script, $prop = '')¶ (static) Adds a new script to be included in the output HTML.
Parameters: - $script (string) – The src attribute from the script.
- $prop (string) – Optional. A property for the script.
-
getThemePath
()¶ (static) Returns the path of the current theme.
-
head
($meta=[])¶ (static) Prints all the head information in <head> tag.
Parameters: $file (Array) – (optional) Meta values to be printed.
-
getViewFile
($file, $package = 'core')¶ (static) Returns the path of a file inside theme or package folder.
Parameters: - $file (string) – The file path.
- $package (string) – (optional) The package folder where the file is located if is not found in theme folder.
Returns: False if file is not found.
-
setViewFile
($file, $package)¶ (static) Overrides the path of a view file.
Parameters: - $file (string) – The file path.
- $package (string) – The package folder where the file is located.
Example
view::setViewFile('admin/settings.php','new-package'); /* src/new-package/views/admin/settings.php overrides themes/my-theme/admin/settings.php src/core/views/admin/settings.php */
-
render
($file, $package = 'core')¶ (static) Prints the view file adding the header.php and footer.php from theme.
Parameters: - $file (string) – The file path.
- $package (string) – (optional) The package folder where the file is located if is not found in theme folder.
-
renderAdmin
($file, $package = 'core')¶ (static) Prints the view file adding the admin/header.php and admin/footer.php from theme.
Parameters: - $file (string) – The file path.
- $package (string) – (optional) The package folder where the file is located if is not found in theme folder.
-
renderFile
($file, $package = 'core')¶ (static) Prints the view file alone from theme.
Parameters: - $file (string) – The file path.
- $package (string) – (optional) The package folder where the file is located if is not found in theme folder.
-
includeFile
($file, $package = 'core')¶ (static) Includes the view file without passing the.
Parameters: - $file (string) – The file path.
- $package (string) – (optional) The package folder where the file is located if is not found in theme folder.
(static) Displays a menu.
Parameters: - $menu (string) – Optional. Name of the menu.
- $tpl (string) – Optional. The view template to generate html.
-
widget_area
($area, $div=true)¶ (static) Prints the widgets of a specific area.
Parameters: - $area (string) – The widget area name.
- $div (bool) – (optional) Also print or not the widget inside a <div> tag with its title.
-
thumb
($area, $prefix, $max=180)¶ (static) Returns the path of a thumbnail image of specified dimensions. If thumbnail does not exist it will create one.
Parameters: - $src (string) – The path of original image.
- $prefix (string) – The prefix name of the thumbnail.
- $max (int) – (optional) The maximum width or height of thumbnail in pixels.
-
thumb_stack
($src_array, $file, $max=180)¶ (static) Returns the path of a stacked image. If image does not exist it will be created on the fly.
Parameters: - $src_array (Array) – The images to stack.
- $file (string) – The name of the stucked image. It must have png extension.
- $max (int) – (optional) The maximum width or height of thumbnails in pixels.
Returns: The path to revisioned stucked image and the list of stucked photos.
Example:
$img = ["image1.png","image2.png"]; list($file,$stacked) = view::thumb_stack($img, "tmp/stacked_file.png",80); /* Returned values $file: tmp/stacked_file.png?12 $stacked[0]: ["src"=>"image1.png","src_width"=>200,"src_height"=>150,"width"=>80,"height"=>60,"type"=>2,"top"=>0] $stacked[1]: false (2nd image was not stacked) */
-
Class db¶
-
class
db
¶ Class db prepare statements for mysql queries to the connected database. We use the global
$db
instance to access its methods.-
query
($q, $args)¶ Runs a query and returns the result.
Parameters: - $q (string) – The query.
- $args ((array)) – Optional. Values to prepare the statement.
Examples
$result1 = $db->query("SELECT title,author FROM post;"); $result2 = $db->query("SELECT title,author FROM post WHERE user_id=?;",[session::user_id()]);
-
get
($q, $args)¶ Runs a query and returns the results as an array.
Parameters: - $q (string) – The query.
- $args ((array)) – Optional. Values to prepare the statement.
Example
$result = $db->get("SELECT title,author FROM post;"); // Returns [ 0=>[0=>'Lorem ipsum', 'title'=>'Lorem ipsum', 1=>'John', 'author'=>'John'], 1=>[0=>'Duis aute irure', 'title'=>'Duis aute irure', 1=>'John', 'author'=>'John'], ]
-
gen
($q, $args)¶ Runs a query and returns a generator that yields the rows.
Parameters: - $q (string) – The query.
- $args ((array)) – Optional. Values to prepare the statement.
Example
$generator = $db->gen("SELECT title,author FROM post;");
-
getRows
($q, $args)¶ Runs a query and returns the results as an array. With rows fetched with mysqli_fetch_row().
Parameters: - $q (string) – The query.
- $args ((array)) – Optional. Values to prepare the statement.
Example
$result = $db->get("SELECT title,author FROM post;"); // Returns [ 0=>[0=>'Lorem ipsum',1=>'John'], 1=>[0=>'Duis aute irure',1=>'John'], ]
-
getList
($q, $args)¶ Runs a query and returns an array with the values of the first columns from the results.
param string $q: The query. param (array) $args: Optional. Values to prepare the statement. Example
$titles = $db->get("SELECT title,author FROM post;"); // Returns [0=>'Lorem ipsum', 1=>'Duis aute irure']
-
value
($q, $args)¶ Runs a query and returns the value of the first column of the first row of the results.
param string $q: The query. param (array) $args: Optional. Values to prepare the statement. Example
$res = $db->get("SELECT title FROM post WHERE id=1;"); // returns 'Lorem ipsum'
-
error
()¶ Return an error if exists from the last query executed.
Example
$res = $db->get("SELECT title,author FROM post;"); if ($error = $db->error()) { trigger_error($error); }
-
close
()¶ Closes the connection to the database.
Example$db->close();
-