Extension · Mecha CMS

Add extra functionality to the core engine.

User

Author: Taufik Nurrohman · 622 Views

Tweet

Rich user data.

Download Version 1.4.0 Download Development Version

File 

Without User Extension 

The page:

---
title: Page Title
author: Taufik Nurrohman
...

Page content.

The property call:

<?php echo $page->author; ?>

With User Extension 

The page:

---
title: Page Title
author: @ta-tau-taufik
...

Page content.

The user file as lot\user\ta-tau-taufik.page:

---
$: Taufik Nurrohman
link: http://example.com
...

Page content.

The property call:

<a href="<?php echo $page->author->link; ?>" id="<?php echo $page->author->key; ?>">
  <?php echo $page->author; ?>
</a>

or:

<?php echo $page->author; ?>

Page 

User page is accessible through http://mecha-cms.com/user/{$key} where {$key} is the user key/name without the @ prefix. Example:

http://mecha-cms.com/user/ta-tau-taufik

To go to the log in page, remove the user key/name part from URL:

http://mecha-cms.com/user

Constant 

This extension automatically adds a user folder within the lot folder, which will also automatically set a new constant based on the folder name with a value of the folder path:

USER

Method 

There are some methods added to the default classes:

Is 

Is::user($key = null, $fail = false);

Example:

Check whether a user is logged in:

if (Is::user()) { … }

Check whether user @ta-tau-taufik is logged in:

if (Is::user('ta-tau-taufik')) { … }

Users 

Get::users($folder = USER, …, $sort = [1, 'slug'], …);

Arguments are the same with Get::pages(), except the $folder parameter that uses USER constant value by default, and the $sort parameter that uses slug as the default sort key instead of time.