Mecha CMS

Mecha CMS blog and documentation.

Class Get

Updated: Sunday, 07 August 2016

The main functions for calling your site data.

Files and Folders

Returned as array.

Get List of Files Recursively

$files = Get::files('path/to/folder');

Get List of Closest Files

$files = Get::closestFiles('path/to/folder');

Results:

$files
 │
 ├── 0:
 │   ├── path: .\www\path\to\file-1.txt
 │   ├── name: file-1
 │   ├── url: http://mecha-cms.com/2016/path/to/file-1.txt
 │   ├── extension: txt
 │   ├── update_raw: 1404371811
 │   ├── update: 2014-07-03 14:16:51
 │   ├── size_raw: 21114
 │   ├── size: 20.62 KB
 │   └── is:
 │       ├── hidden: false
 │       ├── file: true
 │       └── folder: false
 ├── 1: …
 ├── 2: …
 ├── 3: …
 ├── 4: …
 └── 5: …

Options:

Get::files($folder, $extension, $order, $sorter, $filter);
Get::closestFiles($folder, $extension, $order, $sorter, $filter);
ParameterDescription
$folderPath to the folder which contains your files.
$extensionFile extension(s) as a filter. Example: txt and html,php,txt
$orderResults order. Ascending or descending? ASC or DESC?
$sorterThe key of the resulted array items as a sorting reference.
$filterFilter the resulted array by a keyword.

Get List of Folders Recursively

$files = Get::folders('path/to/folder');

Get List of Closest Folders

$files = Get::closestFolders('path/to/folder');

Tags

Get List of Tags

$tags = Get::tags();

Results:

$tags
 │
 ├── 0:
 │   ├── id: 1
 │   ├── name: Foo
 │   ├── slug: foo
 │   ├── description: Description for `foo`.
 │   └── scope: article
 ├── 1:
 │   ├── id: 2
 │   ├── name: Bar
 │   ├── slug: bar
 │   ├── description: Description for `bar`.
 │   └── scope: article
 ├── 2:
 │   ├── id: 3
 │   ├── name: Baz
 │   ├── slug: baz
 │   ├── description: Description for `baz`.
 │   └── scope: article
 ├── 3: …
 ├── 4: …
 └── 5: …

Options:

Get::tags($order, $sorter);
ParameterDescription
$orderResults order. Ascending or descending? ASC or DESC?
$sorterThe key of the resulted array items as a sorting reference.

Get Tag Data by a Reference

Reference parameter can accept an ID, name or slug of the desired tag.

$tag = Get::tag('id:2'); // by ID
$tag = Get::tag('name:Bar'); // by name
$tag = Get::tag('slug:bar'); // by slug

Results:

$tag
 │
 ├── id: 2
 ├── name: Bar
 ├── slug: bar
 ├── description: Description for `bar`.
 └── scope: article

Pages

Get Page Path

Added since version 1.1.3.

The reference parameter can accept an ID, time, or slug of the page.

$path = Get::pagePath('page-1');

Get List of Pages Path

Returned as array.

$pages = Get::pages();

Results:

$pages
 │
 ├── .\www\lot\posts\page\2014-05-04-01-25-43__page-1.txt
 ├── .\www\lot\posts\page\2014-05-04-01-15-33__page-2.txt
 ├── .\www\lot\posts\page\2014-05-04-01-09-29__page-3.txt
 └── …

Options:

Get::pages($order, $filter, $extension);
ParameterDescription
$orderResults order. Ascending or descending? ASC or DESC?
$filterFilter the resulted array by a keyword 1
$extensionFile extension(s) as a filter. Example: txt, draft and txt,draft

Extract Detail of a Page Path

Extract the detail of a page path without reading the file content. Returned as array.

$data = Get::pageExtract('.\www\lot\posts\page\2014-05-04-01-09-29__page-1.txt');

Results:

$data
 │
 ├── path: .\www\lot\posts\page\2014-05-04-01-09-29__page-1.txt
 ├── time: 2014-05-24 11:23:36
 ├── update_raw: 1403355917
 ├── update: 2014-06-21 20:05:17
 ├── slug: page-1
 └── state: published

Options:

Get::pageExtract($order, $sorter, $filter, $extension);
ParameterDescription
$orderResults order. Ascending or descending? ASC or DESC?
$sorterThe key of the resulted array items as a sorting reference.
$filterFilter the resulted array by a keyword 1
$extensionFile extension(s) as a filter. Example: txt, draft and txt,draft

Get List of Page’s Detail

Combination of Get::pages() and Get::pageExtract() method. Returned as array.

$pages = Get::pagesExtract();

Results:

$pages
 │
 ├── 0:
 │   ├── path: .\www\lot\posts\page\2014-05-04-01-09-29__page-1.txt
 │   ├── time: 2014-05-24 11:23:36
 │   ├── update_raw: 1403355917
 │   ├── update: 2014-06-21 20:05:17
 │   ├── slug: page-1
 │   └── state: published
 ├── 1: …
 ├── 2: …
 └── 3: …

Get Page Data by a Reference

Get complete page data by a reference. Returned as object. The reference parameter can accept an ID, time, slug or file path of the page.

$page = Get::page('page-1');

Results:

$page
 │
 ├── path: .\www\lot\posts\page\2014-05-24-11-17-06__page-1.txt
 ├── time: 2014-05-24 11:17:06
 ├── update_raw: 1403355917
 ├── update: 2014-06-21 20:05:17
 ├── slug: page-1
 ├── state: published
 ├── title: My Sample Page
 ├── description: Description for my sample page.
 ├── author: Taufik Nurrohman
 ├── content_type: Markdown Extra
 ├── fields: (your custom fields data)
 ├── content_raw: Lorem ipsum dolor **sit** amet.
 ├── content: <p>Lorem ipsum dolor <strong>sit</strong> amet.</p>
 ├── excerpt: <p>Lorem ipsum dolor <strong>sit</strong> amet.</p>
 ├── date:
 │   ├── unix: 1400905026
 │   ├── W3C: 2014-05-24T11:17:06+07:00
 │   ├── GMT: 2014-05-24 04:17:06
 │   ├── year: 2014
 │   ├── year_short: 14
 │   ├── month: 05
 │   ├── day: 24
 │   ├── month_number: 5
 │   ├── day_number: 24
 │   ├── month_name: May
 │   ├── day_name: Saturday
 │   ├── month_name_short: May
 │   ├── day_name_short: Sat
 │   ├── hour: 11
 │   ├── hour_12: 11
 │   ├── hour_24: 11
 │   ├── minute: 17
 │   ├── second: 06
 │   ├── AM_PM: AM
 │   ├── FORMAT_1: Saturday, 24 May 2014
 │   ├── FORMAT_2: Saturday, May 24, 2014
 │   ├── FORMAT_3: 2014/05/24 11:17:06
 │   ├── FORMAT_4: 2014/05/24 11:17:06 AM
 │   ├── FORMAT_5: 11:17
 │   └── FORMAT_6: 11:17 AM
 ├── url: http://mecha-cms.com/2016/page-1
 ├── link: http://latitudu.com
 ├── id: 1399140933
 ├── js_raw: …
 ├── css_raw: …
 ├── js: …
 ├── css: …
 ├── images:
 │   ├── http://mecha-cms.com/2016/lot/assets/object/image-1.png
 │   ├── http://mecha-cms.com/2016/lot/assets/object/image-2.png
 │   ├── http://mecha-cms.com/2016/lot/assets/object/image-3.png
 │   └── …
 └── image: http://mecha-cms.com/2016/lot/assets/object/image-1.png
Get::page($reference, $excludes);
ParameterDescription
$referenceThe page reference. It can accept an ID, slug or file path of the page.
$excludesExcludes some fields from the resulted page data. Example: Get::page('page-1', array('content', 'fields'))

Get Page Headers Only

Added since version 1.0.2.

This method will takes only the header data of a page with better performance. Returned as object:

$page = Get::pageHeader('page-1');

Results:

$page
 │
 ├── path: .\www\lot\posts\page\2014-05-24-11-17-06__page-1.txt
 ├── time: 2014-05-24 11:17:06
 ├── update_raw: 1403355917
 ├── update: 2014-06-21 20:05:17
 ├── slug: page-1
 ├── state: published
 ├── title: My Sample Page
 ├── description: Description for my sample page.
 ├── author: Taufik Nurrohman
 ├── content_type: Markdown Extra
 ├── fields: (your custom fields data)
 ├── date: …
 ├── id: 1400905026
 ├── url: http://mecha-cms.com/2016/page-1
 └── link: http://latitudu.com

Get Minimum Data of a Page

Added since version 1.0.2.

Used to improve the web performance. In some cases, you may just want to take some of the page data such as the title and the URL (for example, you want to make a link list widget). This method will takes the minimum data of a page to suit your minimum needs. Returned as object:

$page = Get::pageAnchor('page-1');

Results:

$page
 │
 ├── path: .\www\lot\posts\page\2014-05-24-11-17-06__page-1.txt
 ├── time: 2014-05-24 11:17:06
 ├── update_raw: 1403355917
 ├── update: 2014-06-21 20:05:17
 ├── slug: page-1
 ├── state: published
 ├── id: 1400905026
 ├── url: http://mecha-cms.com/2016/page-1
 └── title: My Sample Page

Articles

Get Article Path

Added since version 1.1.3.

The reference parameter can accept an ID, time, or slug of the article.

$path = Get::articlePath('article-3');

Get List of Articles Path

Returned as array.

$articles = Get::articles();

Results:

$articles
 │
 ├── .\www\lot\posts\article\2014-07-02-17-17-19_5_article-1.txt
 ├── .\www\lot\posts\article\2014-06-04-09-19-56_6,2_article-2.txt
 ├── .\www\lot\posts\article\2014-05-29-01-02-42_3,2_article-3.txt
 └── …

Options:

See Get::pages().

Extract Detail of an Article Path

Extract the detail of an article path without reading the file content. Returned as array.

$data = Get::articleExtract('.\www\lot\posts\article\2014-05-04-01-09-29_3,2_article-3.txt');

Results:

$data
 │
 ├── path: .\www\lot\posts\article\2014-05-04-01-09-29_3,2_article-3.txt
 ├── time: 2014-05-24 11:23:36
 ├── update_raw: 1403355917
 ├── update: 2014-06-21 20:05:17
 ├── kind:
 │   ├── 2
 │   └── 3
 ├── slug: article-3
 └── state: published

Options:

See Get::pageExtract().

Get List of Article’s Detail

Combination of Get::articles() and Get::articleExtract() method. Returned as array.

$articles = Get::articlesExtract();

Results:

$articles
 │
 ├── 0:
 │   ├── path: .\www\lot\posts\article\2014-05-29-01-02-42_3,2_article-3.txt
 │   ├── time: 2014-05-29 01:02:42
 │   ├── update_raw: 1405683130
 │   ├── update: 2014-07-18 18:32:10
 │   ├── kind:
 │   │   ├── 2
 │   │   └── 3
 │   ├── slug: article-3
 │   └── state: published
 ├── 1: …
 ├── 2: …
 └── 3: …

Get Article Data by a Reference

Returned as object. The reference parameter can accept an ID, slug or file path of the article.

$article = Get::article('article-3');

Results:

$article
 │
 ├── path: .\www\lot\posts\article\2014-05-29-01-02-42_3,2_article-3.txt
 ├── time: 2014-05-29 01:02:42
 ├── update_raw: 1405683130
 ├── update: 2014-07-18 18:32:10
 ├── kind:
 │   ├── 2
 │   └── 3
 ├── slug: article-3
 ├── title: My Sample Page
 ├── description: Description for my sample page.
 ├── author: Taufik Nurrohman
 ├── content_type: Markdown Extra
 ├── fields: (your custom fields data)
 ├── content_raw: Lorem ipsum **dolor** sit amet, consectetuer adipiscing elit, sed diam …
 ├── content: <p>Lorem ipsum <strong>dolor</strong> sit amet, consectetuer adipiscing elit, sed diam …
 ├── excerpt: <p>Lorem ipsum <strong>dolor</strong> sit amet, consectetuer adipiscing elit, sed diam …
 ├── date:
 │   ├── unix: 1401300162
 │   ├── W3C: 2014-05-29T01:02:42+07:00
 │   ├── GMT: 2014-05-28 18:02:42
 │   ├── year: 2014
 │   ├── year_short: 14
 │   ├── month: 05
 │   ├── day: 29
 │   ├── month_number: 5
 │   ├── day_number: 29
 │   ├── month_name: May
 │   ├── day_name: Thursday
 │   ├── month_name_short: May
 │   ├── day_name_short: Thu
 │   ├── hour: 01
 │   ├── hour_12: 01
 │   ├── hour_24: 01
 │   ├── minute: 02
 │   ├── second: 42
 │   ├── AM_PM: AM
 │   ├── FORMAT_1: Thursday, 29 May 2014
 │   ├── FORMAT_2: Thursday, May 29, 2014
 │   ├── FORMAT_3: 2014/05/29 01:02:42
 │   ├── FORMAT_4: 2014/05/29 01:02:42 AM
 │   ├── FORMAT_5: 01:02
 │   └── FORMAT_6: 01:02 AM
 ├── url: http://mecha-cms.com/2016/article/article-3
 ├── link: http://latitudu.com
 ├── id: 1398840008
 ├── tags
 │   ├── 0:
 │   │   ├── id: 2
 │   │   ├── name: Bar
 │   │   ├── slug: bar
 │   │   └── description: Description for `bar`.
 │   └── 1:
 │       ├── id: 3
 │       ├── name: Baz
 │       ├── slug: baz
 │       └── description: Description for `baz`.
 ├── css_raw: …
 ├── css: …
 ├── js_raw: …
 ├── js: …
 ├── images:
 │   ├── http://mecha-cms.com/2016/lot/assets/object/image-1.png
 │   ├── http://mecha-cms.com/2016/lot/assets/object/image-2.png
 │   ├── http://mecha-cms.com/2016/lot/assets/object/image-3.png
 │   └── …
 ├── image: http://mecha-cms.com/2016/lot/assets/object/image-1.png
 ├── total_comments: 3
 ├── total_comments_text: 3 Comments
 └── comments:
     ├── 0:
     │   ├── path: .\www\lot\responses\comment\2014-04-01-17-57-36_2014-05-05-09-07-14_0000-00-00-00-00-00.txt
     │   ├── time: 2014-05-05 09:07:14
     │   ├── update_raw: 1404374583
     │   ├── update: 2014-07-03 15:03:03
     │   ├── post: 1398840008
     │   ├── id: 1399255634
     │   ├── parent: null
     │   ├── state: approved
     │   ├── date: …
     │   ├── name: Taufik Nurrohman
     │   ├── email: email@domain.com
     │   ├── url: http://latitudu.com
     │   ├── status: pilot
     │   ├── content_type: Markdown Extra
     │   ├── message_raw: Test comment.
     │   ├── message: <p>Test comment.</p>
     │   └── permalink: http://mecha-cms.com/2016/article/article-3#comment-1399255634
     ├── 1: …
     └── 2: …

Options:

Get::article($reference, $excludes);
ParameterDescription
$referenceThe article reference. It can accept an ID, slug or file path of the article.
$excludesExcludes some fields from the resulted article data. Example: Get::article('article-3', array('content', 'fields'))

Get Article Headers Only

Added since version 1.0.2.

See Get::pageHeader()

$article = Get::articleHeader('article-3');

Results:

$article
 │
 ├── path: .\www\lot\posts\article\2014-05-29-01-02-42_3,2_article-3.txt
 ├── time: 2014-05-29 01:02:42
 ├── update_raw: 1405683130
 ├── update: 2014-07-18 18:32:10
 ├── kind:
 │   ├── 2
 │   └── 3
 ├── slug: article-3
 ├── state: published
 ├── title: My Sample Page
 ├── description: Description for my sample page.
 ├── author: Taufik Nurrohman
 ├── content_type: Markdown Extra
 ├── fields: (your custom fields data)
 ├── date: …
 ├── id: 1401300162
 ├── url: http://mecha-cms.com/2016/article/article-3
 └── link: http://latitudu.com

Get Minimum Data of an Article

Added since version 1.0.2.

See Get::pageAnchor():

$article = Get::articleAnchor('article-3');

Results:

$article
 │
 ├── path: .\www\lot\posts\article\2014-05-29-01-02-42_3,2_article-3.txt
 ├── time: 2014-05-29 01:02:42
 ├── update_raw: 1405683130
 ├── update: 2014-07-18 18:32:10
 ├── kind:
 │   ├── 2
 │   └── 3
 ├── slug: article-3
 ├── state: published
 ├── id: 1401300162
 ├── url: http://mecha-cms.com/2016/article/article-3
 └── title: My Sample Page

Comments

Get List of Comments Path

Returned as array.

Get All Comments
$comments = Get::comments();
Get Comments of Specific Article
$comments = Get::comments('ASC', 'post:2014-04-01-17-57-36');

2014-04-01-17-57-36 is the article time, you can also use article ID.

Results:

$comments
 │
 ├── 0: .\www\lot\responses\comment\2014-04-01-17-57-36_2014-05-05-18-44-29_0000-00-00-00-00-00.txt
 ├── 1: .\www\lot\responses\comment\2014-04-01-17-57-36_2014-07-01-11-22-20_0000-00-00-00-00-00.txt
 ├── 2: .\www\lot\responses\comment\2014-04-01-17-57-36_2014-01-02-16-41-05_0000-00-00-00-00-00.txt
 ├── 3: .\www\lot\responses\comment\2014-04-01-17-57-36_2014-11-01-17-30-00_2014-07-01-11-22-20.txt
 └── 4: .\www\lot\responses\comment\2014-04-01-17-57-36_2014-03-02-16-13-21_0000-00-00-00-00-00.txt

Options:

Get::comments($order, $filter, $extension);
ParameterDescription
$orderResults order. Ascending or descending? ASC or DESC?
$filterFilter the resulted array by a keyword 2
$extensionFile extension(s) as a filter. Example: txt, hold and txt,hold

Extract Detail of a Comment Path

Extract the detail of a comment file without reading the content. Returned as array.

$comment = Get::commentExtract('.\www\lot\responses\comment\2014-04-01-17-57-36_2014-05-05-09-07-14_0000-00-00-00-00-00.txt');

Results:

$comment
 │
 ├── path: .\www\lot\responses\comment\2014-04-01-17-57-36_2014-05-05-09-07-14_0000-00-00-00-00-00.txt
 ├── time: 2014-05-05 09:07:14
 ├── update_raw: 1404374583
 ├── update: 2014-07-03 15:03:03
 ├── post: 1396349856
 ├── id: 1399255634
 ├── parent: null
 └── state: approved

Get List of Comment’s Detail

Combination of Get::comment() and Get::commentExtract() method. Returned as array.

$comments = Get::commentsExtract();
$comments = Get::commentsExtract('DESC', 'time', 'post:1396349856');

Results:

$comments
 │
 ├── 0:
 │   ├── path: .\www\lot\responses\comment\2014-04-01-17-57-36_2014-05-05-09-07-14_0000-00-00-00-00-00.txt
 │   ├── time: 2014-05-05 09:07:14
 │   ├── update_raw: 1404374583
 │   ├── update: 2014-07-03 15:03:03
 │   ├── post: 1396349856
 │   ├── id: 1399255634
 │   ├── parent: null
 │   └── state: approved
 ├── 1:
 │   ├── path: .\www\lot\responses\comment\2014-04-01-17-57-36_2014-05-05-09-07-49_0000-00-00-00-00-00.hold
 │   ├── time: 2014-05-05 09:07:49
 │   ├── update_raw: 1404374583
 │   ├── update: 2014-07-03 15:03:03
 │   ├── post: 1396349856
 │   ├── id: 1399255669
 │   ├── parent: null
 │   └── state: pending
 ├── 2: …
 ├── 3: …
 └── 4: …

Options:

Get::commentExtract($order, $sorter, $filter, $extension);
ParameterDescription
$orderResults order. Ascending or descending? ASC or DESC?
$sorterThe key of the resulted array items as a sorting reference.
$filterFilter the resulted array by a keyword 2
$extensionFile extension(s) as a filter. Example: txt, hold and txt,hold

Get Comment Data by a Reference

Get complete comment data by a reference. Returned as object. The reference parameter can accept a comment path, comment ID, or comment time.

$comment = Get::comment('2014-05-05-09-07-14');

Results:

$comment
 │
 ├── path: .\www\lot\responses\comment\2014-04-01-17-57-36_2014-05-05-09-07-14_0000-00-00-00-00-00.txt
 ├── time: 2014-05-05 09:07:14
 ├── update_raw: 1404374583
 ├── update: 2014-07-03 15:03:03
 ├── post: 1396349856
 ├── id: 1399255634
 ├── parent: null
 ├── state: approved
 ├── date: …
 ├── name: Taufik Nurrohman
 ├── email: email@domain.com
 ├── url: http://latitudu.com
 ├── status: pilot
 ├── content_type: Markdown Extra
 ├── message_raw: Lorem ipsum **dolor** sit amet.
 ├── message: <p>Lorem ipsum <strong>dolor</strong> sit amet.</p>
 └── permalink: http://mecha-cms.com/2016/article/article-3#comment-1399255634

Extras

Get User IP Address

$IP = Get::IP();

Get User Agent Info

$UA = Get::UA();

Get Time Zone List

Added since version 1.1.3.

$tz = Get::timezone();
$tz_local_1 = Get::timezone('Asia/Jakarta', false);
$tz_local_2 = Get::timezone('Universe/Planet_Namec', false);
$tz_local_offset = Get::timezone('Asia/Jakarta', false, '%1$s');

Results:

$tz = array(
    'Africa/Abidjan' => '(UTC+00:00) Africa/Abidjan – 10:10 AM',
    'Africa/Accra' => '(UTC+00:00) Africa/Accra – 10:10 AM',
    'Africa/Addis_Ababa' => '(UTC+03:00) Africa/Addis Ababa – 1:10 PM',
     …
);

$tz_local_1 = '(UTC+07:00) Asia/Jakarta – 5:10 PM';
$tz_local_2 = false;
$tz_local_offset = '+07:00';
Donation and Email Subscription