Browse Source

Add features CRUD Authors via Admin panel

pull/475/head
Yaya Laressa 4 years ago
parent
commit
6879f09ff8
12 changed files with 897 additions and 63 deletions
  1. +210
    -10
      system/admin/admin.php
  2. +95
    -0
      system/admin/views/add-author.html.php
  3. +8
    -8
      system/admin/views/add-content.html.php
  4. +2
    -2
      system/admin/views/add-page.html.php
  5. +61
    -0
      system/admin/views/authors-list.html.php
  6. +31
    -0
      system/admin/views/delete-author.html.php
  7. +115
    -0
      system/admin/views/edit-author.html.php
  8. +8
    -8
      system/admin/views/edit-content.html.php
  9. +2
    -2
      system/admin/views/edit-page.html.php
  10. +16
    -0
      system/admin/views/layout.html.php
  11. +290
    -33
      system/htmly.php
  12. +59
    -0
      system/includes/functions.php

+ 210
- 10
system/admin/admin.php View File

@ -39,37 +39,149 @@ function create_user($userName, $password, $role = "user")
}
}
// Create a session
function session($user, $pass)
// Add author
function add_author($title, $user, $password, $content)
{
$user_file = 'config/users/' . $user . '.ini';
if (!file_exists($user_file)) {
return $str = '<div class="error-message"><ul><li class="alert alert-danger">ERROR: Invalid username or password.</li></li></div>';
create_user($user, $password);
$user_title = safe_html($title);
$user_content = '<!--t ' . $user_title . ' t-->' . "\n\n" . $content;
if (!empty($user_title) && !empty($user_content)) {
$user_content = stripslashes($user_content);
$dir = 'content/' . $user . '/';
$filename = 'content/' . $user . '/author.md';
if (is_dir($dir)) {
file_put_contents($filename, print_r($user_content, true));
} else {
mkdir($dir, 0775, true);
file_put_contents($filename, print_r($user_content, true));
}
rebuilt_cache('all');
$redirect = site_url() . 'admin/authors';
header("Location: $redirect");
}
}
// Edit author
function edit_author($name, $title, $user, $password, $content)
{
$name = get_author_info($name);
$name = $name[0];
create_user($user, $password, $name->role);
$user_title = safe_html($title);
$user_content = '<!--t ' . $user_title . ' t-->' . "\n\n" . $content;
if (!empty($user_title) && !empty($user_content)) {
$user_content = stripslashes($user_content);
$dir = 'content/' . $user . '/';
$filename = 'content/' . $user . '/author.md';
if (is_dir($dir)) {
file_put_contents($filename, print_r($user_content, true));
} else {
mkdir($dir, 0775, true);
file_put_contents($filename, print_r($user_content, true));
}
// Jika username lama tidak sama dengan yang baru maka file username lama akan dihapus
if($name->username !== $user) {
copy_folders('content/' . $name->username, 'content/' . $user);
remove_folders('content/' . $name->username);
// Memastikan kalau username sesi sama dengan username lama
if($_SESSION[config("site.url")]['user'] === $name->username) {
if (session_status() == PHP_SESSION_NONE) session_start();
$_SESSION[config("site.url")]['user'] = $user;
}
unlink($name->file);
}
rebuilt_cache('all');
$redirect = site_url() . 'admin/authors';
header("Location: $redirect");
}
}
// Check old password
function valid_password($user, $pass)
{
$user_enc = user('encryption', $user);
$user_pass = user('password', $user);
$user_role = user('role', $user);
if ($user_enc == "password_hash") {
if (password_verify($pass, $user_pass)) {
if (session_status() == PHP_SESSION_NONE) session_start();
if (password_needs_rehash($user_pass, PASSWORD_DEFAULT)) {
update_user($user, $pass, $user_role);
}
$_SESSION[config("site.url")]['user'] = $user;
header('location: admin');
return true;
} else {
return $str = '<div class="error-message"><ul><li class="alert alert-danger">ERROR: Invalid username or password.</li></li></div>';
return false;
}
} else if (old_password_verify($pass, $user_enc, $user_pass)) {
if (session_status() == PHP_SESSION_NONE) session_start();
update_user($user, $pass, $user_role);
return true;
} else {
return false;
}
}
// Check username exists
function username_exists($username, $user = null)
{
// Jika username baru tidak sama dengan username lama
if($username !== $user || $user === null) {
$file = 'config/users/' . $username . '.ini';
if(file_exists($file))
{
return true;
} else {
return false;
}
} else { // Jika username baru sama dengan username lama
$file = 'config/users/' . $username . '.ini';
if(!file_exists($file))
{
return true;
} else {
return false;
}
}
}
// Matching password and password confirm
function password_match($password, $confirm)
{
if($password === $confirm)
{
return true;
} else {
return false;
}
}
// Create a session
function session($user, $pass)
{
$user_file = 'config/users/' . $user . '.ini';
if (!file_exists($user_file)) {
return $str = '<div class="error-message"><ul><li class="alert alert-danger">ERROR: Invalid username or password.</li></li></div>';
}
if(valid_password($user, $pass))
{
if (session_status() == PHP_SESSION_NONE) session_start();
$_SESSION[config("site.url")]['user'] = $user;
header('location: admin');
} else {
return $str = '<div class="error-message"><ul><li class="alert alert-danger">ERROR: Invalid username or password.</li></li></div>';
}
}
function old_password_verify($pass, $user_enc, $user_pass)
@ -702,6 +814,94 @@ function edit_frontpage($title, $content)
}
}
// Move folder and files
function copy_folders($oldfolder, $newfolder)
{
if (is_dir($oldfolder))
{
$dir = opendir($oldfolder);
if (!is_dir($newfolder))
{
mkdir($newfolder, 0775, true);
}
while (($file = readdir($dir)))
{
if (($file != '.') && ($file != '..'))
{
if (is_dir($oldfolder . '/' . $file))
{
copy_folders($oldfolder . '/' . $file, $newfolder . '/' . $file);
}
else
{
copy($oldfolder . '/' . $file, $newfolder . '/' . $file);
}
}
}
closedir($dir);
}
}
// Delete folder and files
function remove_folders($dir)
{
if (false === file_exists($dir)) {
return false;
}
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($files as $fileinfo) {
if ($fileinfo->isDir()) {
if (false === rmdir($fileinfo->getRealPath())) {
return false;
}
} else {
if (false === unlink($fileinfo->getRealPath())) {
return false;
}
}
}
return rmdir($dir);
}
// Delete author
function delete_author($file, $destination)
{
if (!login())
return null;
$deleted_content = $file;
if (!empty($deleted_content)) {
$str = explode('/', $file);
$str = str_replace('.ini', '', $str);
$username = $str[2];
$dir = 'content/' . $username . '/';
$user = $_SESSION[config("site.url")]['user'];
// Melarang untuk menghapus diri sendiri, karena bunuh diri itu dosa :D
if($user !== $username) {
remove_folders($dir);
unlink($deleted_content);
rebuilt_cache('all');
}
if ($destination == 'author') {
$redirect = site_url();
header("Location: $redirect");
} else {
$redirect = site_url() . $destination;
header("Location: $redirect");
}
}
}
// Delete blog post
function delete_post($file, $destination)
{


+ 95
- 0
system/admin/views/add-author.html.php View File

@ -0,0 +1,95 @@
<?php if (!defined('HTMLY')) die('HTMLy'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/editor.css"/>
<script src="<?php echo site_url() ?>system/resources/js/jquery.min.js"></script>
<script src="<?php echo site_url() ?>system/resources/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Converter.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Sanitizer.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Editor.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Extra.js"></script>
<link rel="stylesheet" href="<?php echo site_url() ?>system/resources/css/jquery-ui.css">
<?php if (isset($error)) { ?>
<div class="error-message"><?php echo $error ?></div>
<?php } ?>
<div class="row">
<div class="wmd-panel" style="width:100%;">
<form method="POST">
<div class="row">
<div class="col-sm-6">
<label for="aTitle"><?php echo i18n('Title');?> <span class="required">*</span></label>
<input type="text" class="form-control <?php if (isset($aTitle)) {if (empty($aTitle)) {echo 'is-invalid';}} ?>" id="aTitle" name="title" value="<?php if (isset($aTitle)) {echo $aTitle;} ?>"/>
<br>
</div>
<div class="col-sm-6">
<label for="aUsername"><?php echo i18n('Username');?> <span class="required">*</span></label>
<input type="text" class="form-control text text-lowercase <?php if (isset($aUsername)) {if (empty($aUsername)) {echo 'is-invalid';}} ?>" id="aUsername" name="username" value="<?php if (isset($aUsername)) {echo $aUsername;} ?>" placeholder="<?php if (isset($aUsername)) {echo $aUsername;} ?>"/>
<br>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<label for="aPassword"><?php echo i18n('Password');?> <span class="required">*</span></label>
<input type="password" class="form-control text <?php if (isset($aPassword)) {if (empty($aPassword)) {echo 'is-invalid';}} ?>" id="aPassword" name="password" value="<?php if (isset($aPassword)) {echo $aPassword;} ?>"/>
<br>
</div>
<div class="col-sm-6">
<label for="aPassConfirm"><?php echo i18n('Password_confirm');?> <span class="required">*</span></label>
<input type="password" class="form-control text <?php if (isset($aPassConfirm)) {if (empty($aPassConfirm)) {echo 'is-invalid';}} ?>" id="aPassConfirm" name="passconfirm" value="<?php if (isset($aPassConfirm)) {echo $aPassConfirm;} ?>" placeholder="<?php if (isset($aPassConfirm)) {echo $aPassConfirm;} ?>"/>
<br>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<label for="wmd-input"><?php echo i18n('Content');?></label>
<div id="wmd-button-bar" class="wmd-button-bar"></div>
<textarea id="wmd-input" class="form-control wmd-input" name="content" cols="20" rows="10"><?php if (isset($aContent)) {echo $aContent;} ?></textarea>
<br>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Add_author');?>"/>
</div>
<div class="col-sm-6">
<label><?php echo i18n('Preview');?></label>
<br>
<div id="wmd-preview" class="wmd-panel wmd-preview" style="width:100%;overflow:auto;"></div>
</div>
</div>
</form>
</div>
<style>
.wmd-prompt-background {z-index:10!important;}
#wmd-preview img {max-width:100%;}
</style>
<div class="modal fade" id="insertImageDialog" tabindex="-1" role="dialog" aria-labelledby="insertImageDialogTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="insertImageDialogTitle"><?php echo i18n('Insert_Image');?></h5>
<button type="button" class="close" id="insertImageDialogClose" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="insertImageDialogURL">URL</label>
<input type="text" class="form-control" id="insertImageDialogURL" size="48" placeholder="<?php echo i18n('Enter_image_URL');?>" />
</div>
<hr>
<div class="form-group">
<label for="insertImageDialogFile"><?php echo i18n('Upload');?></label>
<input type="file" class="form-control-file" name="file" id="insertImageDialogFile" accept="image/png,image/jpeg,image/gif" />
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="insertImageDialogInsert"><?php echo i18n('Insert_Image');?></button>
<button type="button" class="btn btn-secondary" id="insertImageDialogCancel" data-dismiss="modal"><?php echo i18n('Cancel');?></button>
</div>
</div>
</div>
</div>
</div>
<!-- Declare the base path. Important -->
<script type="text/javascript">var base_path = '<?php echo site_url() ?>';</script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/editor.js"></script>

+ 8
- 8
system/admin/views/add-content.html.php View File

@ -87,7 +87,7 @@ $( function() {
<div class="row">
<div class="col-sm-6">
<label for="pTitle"><?php echo i18n('Title');?> <span class="required">*</span></label>
<input autofocus type="text" class="form-control text <?php if (isset($postTitle)) { if (empty($postTitle)) { echo 'error';}} ?>" id="pTitle" name="title" value="<?php if (isset($postTitle)) { echo $postTitle;} ?>"/>
<input autofocus type="text" class="form-control text <?php if (isset($postTitle)) { if (empty($postTitle)) { echo 'is-invalid';}} ?>" id="pTitle" name="title" value="<?php if (isset($postTitle)) { echo $postTitle;} ?>"/>
<br>
<label for="pCategory"><?php echo i18n('Category');?> <span class="required">*</span></label>
<select id="pCategory" class="form-control" name="category">
@ -98,7 +98,7 @@ $( function() {
</select>
<br>
<label for="pTag">Tag <span class="required">*</span></label>
<input type="text" class="form-control text <?php if (isset($postTag)) { if (empty($postTag)) { echo 'error';}} ?>" id="pTag" name="tag" value="<?php if (isset($postTag)) { echo $postTag; } ?>" placeholder="<?php echo i18n('Comma_separated_values');?>"/>
<input type="text" class="form-control text <?php if (isset($postTag)) { if (empty($postTag)) { echo 'is-invalid';}} ?>" id="pTag" name="tag" value="<?php if (isset($postTag)) { echo $postTag; } ?>" placeholder="<?php echo i18n('Comma_separated_values');?>"/>
<br>
<label for="pMeta"><?php echo i18n('Meta_description');?> (<?php echo i18n('optional');?>)</label>
<textarea id="pMeta" class="form-control" name="description" rows="3" cols="20" placeholder="<?php echo i18n('If_leave_empty_we_will_excerpt_it_from_the_content_below');?>"><?php if (isset($p->description)) { echo $p->description;} ?></textarea>
@ -113,35 +113,35 @@ $( function() {
<?php if ($type == 'is_audio'):?>
<label for="pAudio"><?php echo i18n('Featured_Audio');?> <span class="required">*</span> (e.g Soundcloud)</label>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postAudio)) { if (empty($postAudio)) { echo 'error';} } ?>" id="pAudio" name="audio"><?php if (isset($postAudio)) { echo $postAudio;} ?></textarea>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postAudio)) { if (empty($postAudio)) { echo 'is-invalid';} } ?>" id="pAudio" name="audio"><?php if (isset($postAudio)) { echo $postAudio;} ?></textarea>
<input type="hidden" name="is_audio" value="is_audio">
<br>
<?php endif;?>
<?php if ($type == 'is_video'):?>
<label for="pVideo"><?php echo i18n('Featured_Video');?> <span class="required">*</span> (e.g Youtube)</label>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postVideo)) { if (empty($postVideo)) { echo 'error';} } ?>" id="pVideo" name="video"><?php if (isset($postVideo)) { echo $postVideo;} ?></textarea>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postVideo)) { if (empty($postVideo)) { echo 'is-invalid';} } ?>" id="pVideo" name="video"><?php if (isset($postVideo)) { echo $postVideo;} ?></textarea>
<input type="hidden" name="is_video" value="is_video">
<br>
<?php endif;?>
<?php if ($type == 'is_image'):?>
<label for="pImage"><?php echo i18n('Featured_Image');?> <span class="required">*</span></label>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postImage)) { if (empty($postImage)) { echo 'error';} } ?>" id="pImage" name="image"><?php if (isset($postImage)) { echo $postImage;} ?></textarea>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postImage)) { if (empty($postImage)) { echo 'is-invalid';} } ?>" id="pImage" name="image"><?php if (isset($postImage)) { echo $postImage;} ?></textarea>
<input type="hidden" name="is_image" value="is_image">
<br>
<?php endif;?>
<?php if ($type == 'is_quote'):?>
<label for="pQuote"><?php echo i18n('Featured_Quote');?> <span class="required">*</span></label>
<textarea rows="3" cols="20" class="form-control text <?php if (isset($postQuote)) { if (empty($postQuote)) { echo 'error';} } ?>" id="pQuote" name="quote"><?php if (isset($postQuote)) { echo $postQuote;} ?></textarea>
<textarea rows="3" cols="20" class="form-control text <?php if (isset($postQuote)) { if (empty($postQuote)) { echo 'is-invalid';} } ?>" id="pQuote" name="quote"><?php if (isset($postQuote)) { echo $postQuote;} ?></textarea>
<input type="hidden" name="is_quote" value="is_quote">
<br>
<?php endif;?>
<?php if ($type == 'is_link'):?>
<label for="pLink"><?php echo i18n('Featured_Link');?> <span class="required">*</span></label>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postLink)) { if (empty($postLink)) { echo 'error';} } ?>" id="pLink" name="link"><?php if (isset($postLink)) { echo $postLink;} ?></textarea>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postLink)) { if (empty($postLink)) { echo 'is-invalid';} } ?>" id="pLink" name="link"><?php if (isset($postLink)) { echo $postLink;} ?></textarea>
<input type="hidden" name="is_link" value="is_link">
<br>
<?php endif;?>
@ -157,7 +157,7 @@ $( function() {
<div>
<label for="wmd-input"><?php echo i18n('Content');?></label>
<div id="wmd-button-bar" class="wmd-button-bar"></div>
<textarea id="wmd-input" class="form-control wmd-input <?php if (isset($postContent)) { if (empty($postContent)) { echo 'error'; } } ?>" name="content" cols="20" rows="15"><?php if (isset($postContent)) { echo $postContent;} ?></textarea><br>
<textarea id="wmd-input" class="form-control wmd-input <?php if (isset($postContent)) { if (empty($postContent)) { echo 'is-invalid'; } } ?>" name="content" cols="20" rows="15"><?php if (isset($postContent)) { echo $postContent;} ?></textarea><br>
<input type="submit" name="publish" class="btn btn-primary submit" value="<?php echo i18n('Publish');?>"/> <input type="submit" name="draft" class="btn btn-primary draft" value="<?php echo i18n('Save_as_draft');?>"/>
<br><br>
</div>


+ 2
- 2
system/admin/views/add-page.html.php View File

@ -18,7 +18,7 @@
<div class="row">
<div class="col-sm-6">
<label for="pTitle"><?php echo i18n('Title');?> <span class="required">*</span></label>
<input type="text" class="form-control text <?php if (isset($postTitle)) {if (empty($postTitle)) {echo 'error';}} ?>" id="pTitle" name="title" value="<?php if (isset($postTitle)) {echo $postTitle;} ?>"/>
<input type="text" class="form-control text <?php if (isset($postTitle)) {if (empty($postTitle)) {echo 'is-invalid';}} ?>" id="pTitle" name="title" value="<?php if (isset($postTitle)) {echo $postTitle;} ?>"/>
<br>
<?php if ($type == 'is_page') :?>
<label for="pMeta"><?php echo i18n('Meta_description');?> (<?php echo i18n('optional');?>)</label>
@ -40,7 +40,7 @@
<div class="col-sm-6">
<label for="wmd-input"><?php echo i18n('Content');?></label>
<div id="wmd-button-bar" class="wmd-button-bar"></div>
<textarea id="wmd-input" class="form-control wmd-input <?php if (isset($postContent)) {if (empty($postContent)) {echo 'error';}} ?>" name="content" cols="20" rows="10"><?php if (isset($postContent)) {echo $postContent;} ?></textarea>
<textarea id="wmd-input" class="form-control wmd-input <?php if (isset($postContent)) {if (empty($postContent)) {echo 'is-invalid';}} ?>" name="content" cols="20" rows="10"><?php if (isset($postContent)) {echo $postContent;} ?></textarea>
<br>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<?php if ($type == 'is_page') :?>


+ 61
- 0
system/admin/views/authors-list.html.php View File

@ -0,0 +1,61 @@
<?php if (!defined('HTMLY')) die('HTMLy'); ?>
<h2 class="post-index"><?php echo $heading ?></h2>
<br>
<a class="btn btn-primary right" href="<?php echo site_url();?>add/author"><?php echo i18n('Add_author');?></a>
<br><br>
<?php if (!empty($authors)) { ?>
<table id="htmly-table" class="table post-list" style="width:100%">
<thead>
<tr class="head">
<th><?php echo i18n('Title');?></th>
<th><?php echo i18n('Username');?></th>
<th><?php echo i18n('Operations');?></th>
</tr>
</thead>
<tbody>
<?php $i = 0;
$len = count($authors); ?>
<?php foreach ($authors as $a): ?>
<?php
if ($i == 0) {
$class = 'item first';
} elseif ($i == $len - 1) {
$class = 'item last';
} else {
$class = 'item';
}
$i++;
?>
<?php
$user = $_SESSION[config("site.url")]['user'];
?>
<tr class="<?php echo $class ?>">
<td><a target="_blank" href="<?php echo $a->url ?>"><?php echo $a->title ?></a></td>
<td><?php echo $a->username ?></td>
<td><a class="btn btn-primary btn-sm" href="<?php echo $a->url ?>/edit?destination=admin/authors"><?php echo i18n('Edit');?></a> <?php if($user !== $a->username): ?><a
class="btn btn-danger btn-sm" href="<?php echo $a->url ?>/delete?destination=admin/authors"><?php echo i18n('Delete');?></a><?php endif; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php if (!empty($pagination['prev']) || !empty($pagination['next'])): ?>
<br>
<div class="pager">
<ul class="pagination">
<?php if (!empty($pagination['prev'])) { ?>
<li class="newer page-item"><a class="page-link" href="?page=<?php echo $page - 1 ?>" rel="prev">&#8592; <?php echo i18n('Newer');?></a></li>
<?php } else { ?>
<li class="page-item disabled" ><span class="page-link">&#8592; <?php echo i18n('Newer');?></span></li>
<?php } ?>
<li class="page-number page-item disabled"><span class="page-link"><?php echo $pagination['pagenum'];?></span></li>
<?php if (!empty($pagination['next'])) { ?>
<li class="older page-item" ><a class="page-link" href="?page=<?php echo $page + 1 ?>" rel="next"><?php echo i18n('Older');?> &#8594;</a></li>
<?php } else { ?>
<li class="page-item disabled" ><span class="page-link"><?php echo i18n('Older');?> &#8594;</span></li>
<?php } ?>
</ul>
</div>
<?php endif; ?>
<?php } else {
echo i18n('No_authors_found') . '!';
} ?>

+ 31
- 0
system/admin/views/delete-author.html.php View File

@ -0,0 +1,31 @@
<?php if (!defined('HTMLY')) die('HTMLy'); ?>
<?php
if (isset($_GET['destination'])) {
$destination = _h($_GET['destination']);
}
$url = $a->file;
$dir = substr($url, 0, strrpos($url, '/'));
$oldurl = str_replace($dir . '/', '', $url);
$oldmd = str_replace('.md', '', $oldurl);
$author = $a->url;
if (isset($destination)) {
if ($destination == 'author') {
$back = $author;
} else {
$back = site_url() . $destination;
}
} else {
$back = site_url();
}
?>
<p><?php echo sprintf(i18n('Are_you_sure_you_want_to_delete_'), $a->title);?></p>
<form method="POST">
<input type="hidden" name="file" value="<?php echo $a->file ?>"/><br>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<input type="submit" class="btn btn-danger" name="submit" value="<?php echo i18n('Delete');?>"/>
<span><a class="btn btn-primary" href="<?php echo $back . '">' . i18n('Cancel');?></a></span>
</form>

+ 115
- 0
system/admin/views/edit-author.html.php View File

@ -0,0 +1,115 @@
<?php if (!defined('HTMLY')) die('HTMLy'); ?>
<?php
if(!empty($username)) {
$author = get_author_info($username);
$a = $author[0];
$aTitle = $a->title;
$aUsername = $a->username;
$aContent = $a->content;
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/editor.css"/>
<script src="<?php echo site_url() ?>system/resources/js/jquery.min.js"></script>
<script src="<?php echo site_url() ?>system/resources/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Converter.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Sanitizer.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Editor.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Extra.js"></script>
<link rel="stylesheet" href="<?php echo site_url() ?>system/resources/css/jquery-ui.css">
<?php if (isset($error)) { ?>
<div class="error-message"><?php echo $error ?></div>
<?php } ?>
<div class="row">
<div class="wmd-panel" style="width:100%;">
<form method="POST">
<div class="row">
<div class="col-sm-6">
<label for="aTitle"><?php echo i18n('Title');?> <span class="required">*</span></label>
<input type="text" class="form-control <?php if (isset($aTitle)) {if (empty($aTitle)) {echo 'is-invalid';}} ?>" id="aTitle" name="title" value="<?php if (isset($aTitle)) {echo $aTitle;} ?>"/>
<br>
</div>
<div class="col-sm-6">
<label for="aUsername"><?php echo i18n('Username');?> <span class="required">*</span></label>
<input type="text" class="form-control text text-lowercase <?php if (isset($aUsername)) {if (empty($aUsername)) {echo 'is-invalid';}} ?>" id="aUsername" name="username" value="<?php if (isset($aUsername)) {echo $aUsername;} ?>" placeholder="<?php if (isset($aUsername)) {echo $aUsername;} ?>"/>
<br>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<label for="aOldPassword"><?php echo i18n('Old_Password');?> <span class="required">*</span></label>
<input type="password" class="form-control text <?php if (isset($aOldPassword)) {if (empty($aOldPassword)) {echo 'is-invalid';}} ?>" id="aOldPassword" name="oldpassword" value="<?php if (isset($aOldPassword)) {echo $aOldPassword;} ?>"/>
<br>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<label for="aPassword"><?php echo i18n('New_Password');?> <span class="required">*</span></label>
<input type="password" class="form-control text <?php if (isset($aPassword)) {if (empty($aPassword)) {echo 'is-invalid';}} ?>" id="aPassword" name="password" value="<?php if (isset($aPassword)) {echo $aPassword;} ?>"/>
<br>
</div>
<div class="col-sm-6">
<label for="aPassConfirm"><?php echo i18n('Password_confirm');?> <span class="required">*</span></label>
<input type="password" class="form-control text <?php if (isset($aPassConfirm)) {if (empty($aPassConfirm)) {echo 'is-invalid';}} ?>" id="aPassConfirm" name="passconfirm" value="<?php if (isset($aPassConfirm)) {echo $aPassConfirm;} ?>" placeholder="<?php if (isset($aPassConfirm)) {echo $aPassConfirm;} ?>"/>
<br>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<label for="wmd-input"><?php echo i18n('Content');?></label>
<div id="wmd-button-bar" class="wmd-button-bar"></div>
<textarea id="wmd-input" class="form-control wmd-input" name="content" cols="20" rows="10"><?php if (isset($aContent)) {echo $aContent;} ?></textarea>
<br>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Add_author');?>"/>
</div>
<div class="col-sm-6">
<label><?php echo i18n('Preview');?></label>
<br>
<div id="wmd-preview" class="wmd-panel wmd-preview" style="width:100%;overflow:auto;"></div>
</div>
</div>
</form>
</div>
<style>
.wmd-prompt-background {z-index:10!important;}
#wmd-preview img {max-width:100%;}
</style>
<div class="modal fade" id="insertImageDialog" tabindex="-1" role="dialog" aria-labelledby="insertImageDialogTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="insertImageDialogTitle"><?php echo i18n('Insert_Image');?></h5>
<button type="button" class="close" id="insertImageDialogClose" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="insertImageDialogURL">URL</label>
<input type="text" class="form-control" id="insertImageDialogURL" size="48" placeholder="<?php echo i18n('Enter_image_URL');?>" />
</div>
<hr>
<div class="form-group">
<label for="insertImageDialogFile"><?php echo i18n('Upload');?></label>
<input type="file" class="form-control-file" name="file" id="insertImageDialogFile" accept="image/png,image/jpeg,image/gif" />
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="insertImageDialogInsert"><?php echo i18n('Insert_Image');?></button>
<button type="button" class="btn btn-secondary" id="insertImageDialogCancel" data-dismiss="modal"><?php echo i18n('Cancel');?></button>
</div>
</div>
</div>
</div>
</div>
<!-- Declare the base path. Important -->
<script type="text/javascript">var base_path = '<?php echo site_url() ?>';</script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/editor.js"></script>

+ 8
- 8
system/admin/views/edit-content.html.php View File

@ -132,7 +132,7 @@ $( function() {
<div class="row">
<div class="col-sm-6">
<label for="pTitle"><?php echo i18n('Title');?> <span class="required">*</span></label>
<input autofocus type="text" id="pTitle" name="title" class="form-control text <?php if (isset($postTitle)) { if (empty($postTitle)) { echo 'error';} } ?>" value="<?php echo $oldtitle ?>"/>
<input autofocus type="text" id="pTitle" name="title" class="form-control text <?php if (isset($postTitle)) { if (empty($postTitle)) { echo 'is-invalid';} } ?>" value="<?php echo $oldtitle ?>"/>
<br>
<label for="pCategory"><?php echo i18n('Category');?> <span class="required">*</span></label>
<select id="pCategory" class="form-control" name="category">
@ -143,7 +143,7 @@ $( function() {
</select>
<br>
<label for="pTag">Tag <span class="required">*</span></label>
<input type="text" id="pTag" name="tag" class="form-control text <?php if (isset($postTag)) { if (empty($postTag)) { echo 'error'; } } ?>" value="<?php echo $oldtag ?>" placeholder="<?php echo i18n('Comma_separated_values');?>"/>
<input type="text" id="pTag" name="tag" class="form-control text <?php if (isset($postTag)) { if (empty($postTag)) { echo 'is-invalid'; } } ?>" value="<?php echo $oldtag ?>" placeholder="<?php echo i18n('Comma_separated_values');?>"/>
<br>
<label for="pMeta"><?php echo i18n('Meta_description');?> (<?php echo i18n('optional');?>)</label>
@ -169,35 +169,35 @@ $( function() {
<?php if ($type == 'is_audio'):?>
<label for="pAudio"><?php echo i18n('Featured_Audio');?> <span class="required">*</span> (e.g Soundcloud)</label>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postAudio)) { if (empty($postAudio)) { echo 'error';} } ?>" id="pAudio" name="audio"><?php echo $oldaudio; ?></textarea>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postAudio)) { if (empty($postAudio)) { echo 'is-invalid';} } ?>" id="pAudio" name="audio"><?php echo $oldaudio; ?></textarea>
<input type="hidden" name="is_audio" value="is_audio">
<br>
<?php endif;?>
<?php if ($type == 'is_video'):?>
<label for="pVideo"><?php echo i18n('Featured_Video');?> <span class="required">*</span> (e.g Youtube)</label>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postVideo)) { if (empty($postVideo)) { echo 'error';} } ?>" id="pVideo" name="video"><?php echo $oldvideo ?></textarea>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postVideo)) { if (empty($postVideo)) { echo 'is-invalid';} } ?>" id="pVideo" name="video"><?php echo $oldvideo ?></textarea>
<input type="hidden" name="is_video" value="is_video">
<br>
<?php endif;?>
<?php if ($type == 'is_image'):?>
<label for="pImage"><?php echo i18n('Featured_Image');?> <span class="required">*</span></label>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postImage)) { if (empty($postImage)) { echo 'error';} } ?>" id="pImage" name="image"><?php echo $oldimage; ?></textarea>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postImage)) { if (empty($postImage)) { echo 'is-invalid';} } ?>" id="pImage" name="image"><?php echo $oldimage; ?></textarea>
<input type="hidden" name="is_image" value="is_image">
<br>
<?php endif;?>
<?php if ($type == 'is_quote'):?>
<label for="pQuote"><?php echo i18n('Featured_Quote');?> <span class="required">*</span></label>
<textarea rows="3" cols="20" class="form-control text <?php if (isset($postQuote)) { if (empty($postQuote)) { echo 'error';} } ?>" id="pQuote" name="quote"><?php echo $oldquote ?></textarea>
<textarea rows="3" cols="20" class="form-control text <?php if (isset($postQuote)) { if (empty($postQuote)) { echo 'is-invalid';} } ?>" id="pQuote" name="quote"><?php echo $oldquote ?></textarea>
<input type="hidden" name="is_quote" value="is_quote">
<br>
<?php endif;?>
<?php if ($type == 'is_link'):?>
<label for="pLink"><?php echo i18n('Featured_Link');?> <span class="required">*</span></label>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postLink)) { if (empty($postLink)) { echo 'error';} } ?>" id="pLink" name="link"><?php echo $oldlink ?></textarea>
<textarea rows="2" cols="20" class="form-control text <?php if (isset($postLink)) { if (empty($postLink)) { echo 'is-invalid';} } ?>" id="pLink" name="link"><?php echo $oldlink ?></textarea>
<input type="hidden" name="is_link" value="is_link">
<br>
<?php endif;?>
@ -214,7 +214,7 @@ $( function() {
<div>
<label for="wmd-input"><?php echo i18n('Content');?></label>
<div id="wmd-button-bar" class="wmd-button-bar"></div>
<textarea id="wmd-input" class="form-control wmd-input <?php if (isset($postContent)) { if (empty($postContent)) { echo 'error'; } } ?>" name="content" cols="20" rows="15"><?php echo $oldcontent ?></textarea><br>
<textarea id="wmd-input" class="form-control wmd-input <?php if (isset($postContent)) { if (empty($postContent)) { echo 'is-invalid'; } } ?>" name="content" cols="20" rows="15"><?php echo $oldcontent ?></textarea><br>
<?php if ($isdraft[4] == 'draft') { ?>
<input type="submit" name="publishdraft" class="btn btn-primary submit" value="<?php echo i18n('Publish_draft');?>"/> <input type="submit" name="updatedraft" class="btn btn-primary draft" value="<?php echo i18n('Update_draft');?>"/> <a class="btn btn-danger" href="<?php echo $delete ?>"><?php echo i18n('Delete');?></a>
<?php } else { ?>


+ 2
- 2
system/admin/views/edit-page.html.php View File

@ -83,7 +83,7 @@ if ($type == 'is_frontpage') {
<div class="row">
<div class="col-sm-6">
<label for="pTitle"><?php echo i18n('Title');?> <span class="required">*</span></label>
<input type="text" id="pTitle" name="title" class="form-control text <?php if (isset($postTitle)) { if (empty($postTitle)) { echo 'error'; } } ?>" value="<?php echo $oldtitle ?>"/>
<input type="text" id="pTitle" name="title" class="form-control text <?php if (isset($postTitle)) { if (empty($postTitle)) { echo 'is-invalid'; } } ?>" value="<?php echo $oldtitle ?>"/>
<br>
<?php if($type != 'is_frontpage' && $type != 'is_profile') { ?>
<label for="pMeta"><?php echo i18n('Meta_description');?> (optional)</label>
@ -106,7 +106,7 @@ if ($type == 'is_frontpage') {
<div class="col-sm-6">
<label for="wmd-input"><?php echo i18n('Content');?></label>
<div id="wmd-button-bar" class="wmd-button-bar"></div>
<textarea id="wmd-input" class="form-control wmd-input <?php if (isset($postContent)) {if (empty($postContent)) {echo 'error';}} ?>" name="content" cols="20" rows="10"><?php echo $oldcontent ?></textarea>
<textarea id="wmd-input" class="form-control wmd-input <?php if (isset($postContent)) {if (empty($postContent)) {echo 'is-invalid';}} ?>" name="content" cols="20" rows="10"><?php echo $oldcontent ?></textarea>
<br>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<?php if($type == 'is_frontpage' || $type == 'is_profile') { ?>


+ 16
- 0
system/admin/views/layout.html.php View File

@ -95,6 +95,22 @@
</li>
</ul>
</li>
<li class="nav-item has-treeview menu-open">
<a href="#" class="nav-link">
<i class="nav-icon fa fa-users"></i>
<p>
<?php echo i18n('Authors'); ?> <sup class="font-weight-bold text-danger"><?php echo i18n('Beta'); ?></sup>
<i class="right fa fa-angle-left"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="<?php echo site_url(); ?>admin/authors" class="nav-link">
<p><?php echo i18n('Authors_list'); ?></p>
</a>
</li>
</ul>
</li>
<li class="nav-item has-treeview menu-open">
<a href="#" class="nav-link">
<i class="nav-icon fa fa-cogs"></i>


+ 290
- 33
system/htmly.php View File

@ -270,6 +270,287 @@ get('/author/:name', function ($name) {
), $layout);
});
// Add author
get('/add/author', function () {
if (login()) {
config('views.root', 'system/admin/views');
if (is_admin()) {
render('add-author', array(
'title' => 'Add author - ' . blog_title(),
'description' => strip_tags(blog_description()),
'canonical' => site_url(),
'heading' => 'Add author',
'is_admin' => true,
'bodyclass' => 'add-author',
'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; Add author'
));
} else {
render('denied', array(
'title' => 'Add author - ' . blog_title(),
'description' => strip_tags(blog_description()),
'canonical' => site_url(),
'heading' => 'Add author',
'is_admin' => true,
'bodyclass' => 'add-author',
'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; Add author'
));
}
} else {
$login = site_url() . 'login';
header("location: $login");
}
});
// Get data Add author
post('/add/author', function () {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
if (!login()) {
$login = site_url() . 'login';
header("location: $login");
}
$title = from($_REQUEST, 'title');
$username = strtolower(from($_REQUEST, 'username'));
$password = from($_REQUEST, 'password');
$passconfirm = from($_REQUEST, 'passconfirm');
$content = from($_REQUEST, 'content');
if ($proper && !empty($title) && !empty($username) && preg_match('/(?=.{6})^[a-z0-9]+$/', $username) && !username_exists($username) && !empty($password) && !empty($passconfirm) && password_match($password, $passconfirm) && login()) {
add_author($title, $username, $password, $content);
} else {
$message['error'] = '';
if (empty($title)) {
$message['error'] .= '<li class="alert alert-danger">Title field is required.</li>';
}
if (empty($username)) {
$message['error'] .= '<li class="alert alert-danger">Username field is required.</li>';
}
if (!preg_match('/(?=.{6})^[a-z0-9]+$/', $username)) {
$message['error'] .= '<li class="alert alert-danger">Username only letters, numbers, and must be 6 or more.</li>';
}
if (username_exists($username)) {
$message['error'] .= '<li class="alert alert-danger">Username is already exist.</li>';
}
if (empty($password)) {
$message['error'] .= '<li class="alert alert-danger">Password field is required.</li>';
}
if (empty($passconfirm)) {
$message['error'] .= '<li class="alert alert-danger">Password Confirm field is required.</li>';
}
if (!password_match($password, $passconfirm)) {
$message['error'] .= '<li class="alert alert-danger">Password and Password Confirm is not match.</li>';
}
if (!$proper) {
$message['error'] .= '<li class="alert alert-danger">CSRF Token not correct.</li>';
}
config('views.root', 'system/admin/views');
render('add-author', array(
'title' => 'Add author - ' . blog_title(),
'description' => strip_tags(blog_description()),
'canonical' => site_url(),
'error' => '<ul>' . $message['error'] . '</ul>',
'aTitle' => $title,
'aUsername' => $username,
'aPassword' => $password,
'aPassConfirm' => $passconfirm,
'aContent' => $content,
'heading' => 'Add author',
'is_admin' => true,
'bodyclass' => 'add-author',
'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; Add author'
));
}
});
// Edit author
get('/author/:name/edit', function ($name) {
if (login()) {
config('views.root', 'system/admin/views');
if (is_admin()) {
render('edit-author', array(
'title' => 'Edit author - ' . blog_title(),
'description' => strip_tags(blog_description()),
'canonical' => site_url(),
'username' => $name,
'is_admin' => true,
'bodyclass' => 'edit-author',
'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; Edit author'
));
} else {
render('denied', array(
'title' => 'Edit author - ' . blog_title(),
'description' => strip_tags(blog_description()),
'canonical' => site_url(),
'is_admin' => true,
'bodyclass' => 'edit-author',
'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; Edit author'
));
}
} else {
$login = site_url() . 'login';
header("location: $login");
}
});
// Get data Edit author
post('/author/:name/edit', function ($name) {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
if (!login()) {
$login = site_url() . 'login';
header("location: $login");
}
$title = from($_REQUEST, 'title');
$username = strtolower(from($_REQUEST, 'username'));
$oldpassword = from($_REQUEST, 'oldpassword');
$password = from($_REQUEST, 'password');
$passconfirm = from($_REQUEST, 'passconfirm');
$content = from($_REQUEST, 'content');
if ($proper && !empty($title) && !empty($username) && preg_match('/(?=.{6})^[a-z0-9]+$/', $username) && !username_exists($username, $name) && !empty($password) && !empty($passconfirm) && password_match($password, $passconfirm) && valid_password($name, $oldpassword) && login()) {
edit_author($name, $title, $username, $password, $content);
} else {
$message['error'] = '';
if (empty($title)) {
$message['error'] .= '<li class="alert alert-danger">Title field is required.</li>';
}
if (empty($username)) {
$message['error'] .= '<li class="alert alert-danger">Username field is required.</li>';
}
if (!preg_match('/(?=.{6})^[a-z0-9]+$/', $username)) {
$message['error'] .= '<li class="alert alert-danger">Username only letters, numbers, and must be 6 or more.</li>';
}
if (username_exists($username, $name)) {
$message['error'] .= '<li class="alert alert-danger">Username is already exist.</li>';
}
if (empty($password)) {
$message['error'] .= '<li class="alert alert-danger">Password field is required.</li>';
}
if (empty($passconfirm)) {
$message['error'] .= '<li class="alert alert-danger">Password Confirm field is required.</li>';
}
if (!password_match($password, $passconfirm)) {
$message['error'] .= '<li class="alert alert-danger">Password and Password Confirm is not match.</li>';
}
if (!valid_password($name, $oldpassword)) {
$message['error'] .= '<li class="alert alert-danger">Old Password is not valid.</li>';
}
if (!$proper) {
$message['error'] .= '<li class="alert alert-danger">CSRF Token not correct.</li>';
}
config('views.root', 'system/admin/views');
render('edit-author', array(
'title' => 'Edit author - ' . blog_title(),
'description' => strip_tags(blog_description()),
'canonical' => site_url(),
'error' => '<ul>' . $message['error'] . '</ul>',
'aTitle' => $title,
'aUsername' => $username,
'aOldPassword' => $oldpassword,
'aPassword' => $password,
'aPassConfirm' => $passconfirm,
'aContent' => $content,
'heading' => 'Edit author',
'is_admin' => true,
'bodyclass' => 'edit-author',
'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; Edit author'
));
}
});
// Delete author
get('/author/:name/delete', function ($name) {
if (login()) {
if (is_admin()) {
config('views.root', 'system/admin/views');
$author = get_author_info($name);
if (!$author) {
not_found();
}
$author = $author[0];
render('delete-author', array(
'title' => 'Delete author - ' . blog_title(),
'description' => strip_tags(blog_description()),
'canonical' => site_url(),
'a' => $author,
'is_admin' => true,
'bodyclass' => 'delete-author',
'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; Delete author'
));
} else {
render('denied', array(
'title' => 'Delete author - ' . blog_title(),
'description' => strip_tags(blog_description()),
'canonical' => site_url(),
'is_admin' => true,
'bodyclass' => 'delete-author',
'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; Delete author'
));
}
} else {
$login = site_url() . 'login';
header("location: $login");
}
});
// Get data Delete author
post('/author/:name/delete', function () {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
if ($proper && login()) {
$file = from($_REQUEST, 'file');
$destination = from($_GET, 'destination');
delete_author($file, $destination);
}
});
// Show authors page
get('/admin/authors', function () {
if (login()) {
config('views.root', 'system/admin/views');
if (is_admin()) {
$authors = get_authors();
render('authors-list', array(
'title' => 'Authors list - ' . blog_title(),
'description' => strip_tags(blog_description()),
'canonical' => site_url(),
'heading' => 'Authors',
'authors' => $authors,
'is_admin' => true,
'bodyclass' => 'authors-list',
'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; Authors list'
));
} else {
render('denied', array(
'title' => 'Authors list - ' . blog_title(),
'description' => strip_tags(blog_description()),
'canonical' => site_url(),
'heading' => 'Authors',
'is_admin' => true,
'bodyclass' => 'authors-list',
'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; Authors list'
));
}
} else {
$login = site_url() . 'login';
header("location: $login");
}
});
// Edit the profile
get('/edit/profile', function () {
@ -710,12 +991,10 @@ post('/add/category', function () {
// Show admin/posts
get('/admin/posts', function () {
$user = $_SESSION[config("site.url")]['user'];
$role = user('role', $user);
if (login()) {
config('views.root', 'system/admin/views');
if ($role === 'admin') {
if (is_admin()) {
config('views.root', 'system/admin/views');
$page = from($_GET, 'page');
@ -781,12 +1060,10 @@ get('/admin/posts', function () {
// Show admin/popular
get('/admin/popular', function () {
$user = $_SESSION[config("site.url")]['user'];
$role = user('role', $user);
if (login()) {
config('views.root', 'system/admin/views');
if ($role === 'admin') {
if (is_admin()) {
config('views.root', 'system/admin/views');
$page = from($_GET, 'page');
$page = $page ? (int)$page : 1;
@ -1092,12 +1369,9 @@ post('/admin/import', function () {
// Show Config page
get('/admin/config', function () {
$user = $_SESSION[config("site.url")]['user'];
$role = user('role', $user);
if (login()) {
config('views.root', 'system/admin/views');
if ($role === 'admin') {
if (is_admin()) {
render('config', array(
'title' => 'Config - ' . blog_title(),
'description' => strip_tags(blog_description()),
@ -1158,12 +1432,9 @@ post('/admin/config', function () {
// Show Config page
get('/admin/config/custom', function () {
$user = $_SESSION[config("site.url")]['user'];
$role = user('role', $user);
if (login()) {
config('views.root', 'system/admin/views');
if ($role === 'admin') {
if (is_admin()) {
render('config-custom', array(
'title' => 'Config - ' . blog_title(),
'description' => strip_tags(blog_description()),
@ -1226,12 +1497,9 @@ post('/admin/config/custom', function () {
// Show Config page
get('/admin/config/reading', function () {
$user = $_SESSION[config("site.url")]['user'];
$role = user('role', $user);
if (login()) {
config('views.root', 'system/admin/views');
if ($role === 'admin') {
if (is_admin()) {
render('config-reading', array(
'title' => 'Config - ' . blog_title(),
'description' => strip_tags(blog_description()),
@ -1293,12 +1561,9 @@ post('/admin/config/reading', function () {
// Show Config page
get('/admin/config/widget', function () {
$user = $_SESSION[config("site.url")]['user'];
$role = user('role', $user);
if (login()) {
config('views.root', 'system/admin/views');
if ($role === 'admin') {
if (is_admin()) {
render('config-widget', array(
'title' => 'Config - ' . blog_title(),
'description' => strip_tags(blog_description()),
@ -1360,12 +1625,9 @@ post('/admin/config/widget', function () {
// Show Config page
get('/admin/config/metatags', function () {
$user = $_SESSION[config("site.url")]['user'];
$role = user('role', $user);
if (login()) {
config('views.root', 'system/admin/views');
if ($role === 'admin') {
if (is_admin()) {
render('config-metatags', array(
'title' => 'Config - ' . blog_title(),
'description' => strip_tags(blog_description()),
@ -1427,12 +1689,9 @@ post('/admin/config/metatags', function () {
// Show Config page
get('/admin/config/performance', function () {
$user = $_SESSION[config("site.url")]['user'];
$role = user('role', $user);
if (login()) {
config('views.root', 'system/admin/views');
if ($role === 'admin') {
if (is_admin()) {
render('config-performance', array(
'title' => 'Config - ' . blog_title(),
'description' => strip_tags(blog_description()),
@ -1658,12 +1917,10 @@ get('/admin/categories', function () {
// Show the category page
get('/admin/categories/:category', function ($category) {
$user = $_SESSION[config("site.url")]['user'];
$role = user('role', $user);
if (login()) {
config('views.root', 'system/admin/views');
if ($role === 'admin') {
if (is_admin()) {
$page = from($_GET, 'page');
$page = $page ? (int)$page : 1;


+ 59
- 0
system/includes/functions.php View File

@ -6,6 +6,65 @@ use \Suin\RSSWriter\Feed;
use \Suin\RSSWriter\Channel;
use \Suin\RSSWriter\Item;
// Get all authors
function get_authors()
{
$tmp = array();
foreach (glob('config/users/*.ini', GLOB_NOSORT) as $key => $value) {
if(preg_match('/config\/users\/(.*)\.ini/i', $value, $matches)) {
$user = new stdClass;
$user->username = $matches[1];
$user->password = user('password', $matches[1]);
$user->role = user('role', $matches[1]);
$user->url = site_url() . 'author/' . $matches[1];
$user->file = $value;
$filename = 'content/' . $matches[1] . '/author.md';
if (file_exists($filename)) {
$content = file_get_contents($filename);
$user->title = get_content_tag('t', $content, 'user');
$user->content = remove_html_comments($content);
} else {
$user->title = $matches[1];
$user->content = 'Just another HTMLy user.';
}
$tmp[] = $user;
}
}
return $tmp;
}
// Get author info
function get_author_info($author)
{
$tmp = array();
$value = 'config/users/' . $author . '.ini';
if(preg_match('/config\/users\/(.*)\.ini/i', $value, $matches)) {
$user = new stdClass;
$user->username = $matches[1];
$user->password = user('password', $matches[1]);
$user->role = user('role', $matches[1]);
$user->url = site_url() . 'author/' . $matches[1];
$user->file = $value;
$filename = 'content/' . $matches[1] . '/author.md';
if (file_exists($filename)) {
$content = file_get_contents($filename);
$user->title = get_content_tag('t', $content, 'user');
$user->content = remove_html_comments($content);
} else {
$user->title = $matches[1];
$user->content = 'Just another HTMLy user.';
}
$tmp[] = $user;
}
return $tmp;
}
// Get blog post path. Unsorted. Mostly used on widget.
function get_post_unsorted()
{


Loading…
Cancel
Save