Introduction

This documentation is referring to theme and plugin development, not the core script of CloudArcade CMS.

Don't modify scripts outside of "content" folder, unless there are a documentation reference on it.

If you keep modify internal scripts, there are no guarantee it will work with new updates in the future. In case if there are a structure changes, bug fixes, security improvement or new features.

Theme structures

Theme folder located at "content/themes/"

File list below is important files for a theme:

  • home.php
    Homepage of your site
  • game.php
    Single page for game, or game content page
  • page.php
    Show single page content
  • archive.php
    Show games on a category
  • search.php
    Show game search results
  • 404.php
    Page for "not found" content/page
  • functions.php
    Custom php scripts for its theme
  • thumbnail.png
    Theme thumbnail preview (300x220px), optional.
  • info.json
    Store information about current theme, must be included, if not, this theme will not be listed.
  • includes/header.php.php
    Site header content (used on all page of theme)
  • includes/footer.php
    Site footer content (used on all page of theme)
  • layout.php
    Editable content for "Layout" dashboard.
  • user.php
    Custom user profile page, if not exist, system will use default page.
  • parts (Folder)
    Store all editable files or elements from "Layout"

Global functions

Global functions is a functions that can be called or accessed on all themes and plugins.

get_game_list()

  • type = 'new'
  • type = 'popular'
  • type = 'random'
  • type = 'likes'
  • amount (number of games you want to get)
  • page (optional, 0 default)
Code example:
get_game_list('popular', 20);
get_game_list('new', 50, 2);
Return:
array(
	"results" => (game list on Array),
	"totalRows" => (total games in a row),
	"totalPages" => (total pages),
);
Code example:
$games = get_game_list('popular', 20);
$listgames = $games["results"];

get_game_list_category()

get_game_list_category($name, $amount, $page);

Get game list by category

  • name (category name)
  • amount (number of games you want to get)
  • page (optional, 0 default)
Code example:
get_game_list_category('action', 40);
Return:

array(
	"results" => (game list on Array),
	"totalRows" => (total games in a row),
	"totalPages" => (total pages),
);
Code example:
$games = get_game_list_category('action', 40);
$listgames = $games["results"];

get_all_categories()

get_all_categories();

Return all categories name in Array

commas_to_array()

commas_to_array($string);

Convert string that separated by comma into Array, it's also used to show game categories.

Sample code:


$cats = $game->category; //'Action,Puzzle,Adventure'
$array_cats = commas_to_array($cats); //['Action', 'Puzzle', 'Adventure']

get_permalink()

get_permalink($type, $slug);

Get url for specific content. get_permalink() will return its url, do this instead of using static url.

Types: ($type)
  • game
  • archive
  • search
  • category
  • page

Sample code:


$game_url = get_permalink('game', 'game-title'); // yourdomain.com/game/game-title
$category_url = get_permalink('category', 'adventure'); // yourdomain.com/archive/adventure
//Custom url
$custom_url = get_permalink('test1', 'test2'); // yourdomain.com/test1/test2

get_collection()

get_collection($name, $amount);

Get a collection of games

  • name (collection name)
  • amount (number of games you want to get, optional, default = 12)
Code example:
get_collection('featured', 10);
Return:
array(
	"results" => (game list on Array),
	"totalRows" => (total games in a row)
);
Code example:
$games = get_collection('featured', 10);
$listgames = $games["results"];

Content

( content )

Game

Reference game.php

Code example to get current game title

$game->title;

Code example to get current game plays count

$game->view;

Another sample

$data = get_game_list('new', 20);
$games = $data['results'];
foreach ( $games as $game ) {
	$title = $game->title;
	$views = $game->view;
}

Keys:
  • id
  • createdDate
  • title
  • description
  • instructions
  • category (string, separated by comma)
  • source
  • thumb_1
  • thumb_2
  • url
  • width
  • height
  • tags (string, not used yet)
  • view
  • slug
  • upvote
  • downvote
  • data (string, can be used to stored additional data)

Category

Sample code

$data = get_all_categories();
$categories = $data['results'];
foreach ( $categories as $category ) {
	$name = $category->name;
	$slug = $category->slug;
}

Keys:
  • id
  • name
  • slug
  • description
  • meta_description

Page

Page content can't execute any scripts, page can only load pure HTML content

Reference page.php

Code example to get current page title

$page->title;

Code example to get current page content

$page->content;

Keys:
  • id
  • createdDate
  • title
  • slug
  • content

Plugin

With plugin, you can extend CloudArcade features without touching internal code.
But still be careful developing your custom plugins, wrong plugin code can break your site, and there are no plugin restriction.

However, you can't override existing features, only add new feature with plugin.

Plugin folder located at "content/plugins/".

Plugin structures:

  • page.php
  • main.php (optional)
  • info.json

Sample info.json structure:

{
	"name": "Backup Restore",
	"version": "1.0.0",
	"author": "RedFoc",
	"description": "Backup and restore for CloudArcade CMS.",
	"website": "https://redfoc.com",
	"require_version": "1.2.0",
	"tested_version": "1.2.0",
	"last_update": "18/01/2021",
	"type": "plugin",
	"target": "admin",
	"require_login": true
}

There are only 2 values of "target", "admin" and "index". what it's mean ? if "target" value is "index", a Plugin must have main.php

page.php is a page for plugin page (Admin dashboard).

Mostly, page.php is used to configure a plugin or do any admin actions.

main.php will be loaded before main site generated and this script only be loaded on visitor page, not admin page, it's similar to "functions.php" in Theme.

If your plugin is only targeted for Admin dashboard, main.php is not required.

Player

( Updated later )

Ranks

What is player ranks ? Player ranks is a level of player, player can upgrade their rank by increasing their XP.

How to get more XP ? Player can get additional XP by liking or comment a game. currently you can't change XP values.

You can change Rank name and Rank XP requirement by editing rank.json, located on "includes" folder. You can add more ranks, there are no limitation.

Rank badges/icons is located on "images/ranks", image format must be .png, the name of it's number is related to rank array position.

User registration

You can restrict user username or decline if username contains specific words. for the list, you can modify "banned-username.json" or "banner-words.json" on "includes" folder.

Utilities

Here is a list of variable and arrays that useful for theme or plugin development.

  • USER_ADMIN (Constant, true / false)

    Detects whether the current user is an admin or not.

    Code:

    if(USER_ADMIN){ //Current user is admin
    	//Do something
    }
  • $login_user (Object)

    Get current logged in user. if current user is not logged in, it will return "null".

    Keys:
    • id
    • username
    • password
    • email
    • birth_date
    • join_date
    • gender
    • data
    • bio
    • rank
    • level

    Code:

    if($login_user){ //Logged in user
    	echo $login_user->username; //Get username
    }

Translation

Site Translation or localization is introduced on v1.2.3. With site localization, you can translate sentences or words easily without modifying internal code.

Almost all words and sentences is translateable, including button, alert, warning and info. You can translate both Admin area and Visitor area (Theme)

How to create a translation ?
  • Admin area

    First step, create folder "locales" on root if not exist (CloudArcade Installation directory).


    Then create json file, with your language ID, ex: en, es, id, ru.etc. If you want to create Russian translation, name it with "ru.json".
    On this sample, I want to create English translation, so, I name it "en.json".
    Image below is what it's look like inside JSON file:

    Make sure the last (line 6) translation don't have a comma, or the translation will not work.

  • Visitor area

    User profile, registartion, login is also the part of visitor area, the method is similar with "Admin area", the difference is you need to create "locales" folder on your theme folder (content/themes/your-theme/locales).


Last step after after create translation file. Open "Settings" then change site language to your json file name, if your translation file is "en.json", fill it with "en", if file name is "id.json" fill it with "id", then save it.

How translation feature works ? on each page request, system will search a json translation file related to your language settings, if not exist, it will be skipped and use default language instead.

You can also put variable on translation.

Code example:
$text1 = _t('Page %a of %b', 11, 20); //Halaman 11 dari 20
$text2 = _t('%a games found.', 55); //ABCD 55
$text3 = _t('%a is not equal to %b', 'Apple', 'Orange'); //Orange is not Apple

It's case sensitive, so "NEW GAMES" with "New games" is different.
There are 2 method to get a translation.

_t('New games');
and
_e('New games');
"_e(...)" is similar to "echo _t('...')"

Maximum number of parameter is 2, %a stand for first parameter and %b is stand for second parameter.

Custom page

Custom page is introduced on v1.2.3. what is Custom page ? and what the difference with regular page?

You don't have full control over regular page, even HTML tag is limited here for security reason.

With custom page, you have full control over it, from first html element until the end of page. However, this method require coding experience.

First step, open your theme folder (content/themes/your-theme). then create php file called "page-yourpage.php", replace "yourpage" with your custom page name.

Ex: "page-hello.php", you can access it with url "domain.com/hello/" (put a slash after page name), you can also put a parameter on it, "domain.com/hello/word" ($_GET['slug'] to get page parameter)

All built-in CloudArcade functions and features can be accessed here.