mirror of
https://github.com/danpros/htmly.git
synced 2026-04-19 03:56:21 +05:30
Improve offline writing
The username.ini and category files not mandatory anymore.
This commit is contained in:
parent
2a6d94fc5e
commit
afcddb2979
4 changed files with 91 additions and 52 deletions
|
|
@ -2,7 +2,6 @@
|
||||||
<?php
|
<?php
|
||||||
$desc = get_category_info(null);
|
$desc = get_category_info(null);
|
||||||
asort($desc);
|
asort($desc);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<h2><?php echo i18n("Categories");?></h2>
|
<h2><?php echo i18n("Categories");?></h2>
|
||||||
<br>
|
<br>
|
||||||
|
|
|
||||||
|
|
@ -11,20 +11,8 @@
|
||||||
<th><?php echo i18n('Published');?></th>
|
<th><?php echo i18n('Published');?></th>
|
||||||
<th><?php echo i18n('Operations');?></th>
|
<th><?php echo i18n('Operations');?></th>
|
||||||
</tr>
|
</tr>
|
||||||
<?php $i = 0;
|
|
||||||
$len = count($posts); ?>
|
|
||||||
<?php foreach ($posts as $p): ?>
|
<?php foreach ($posts as $p): ?>
|
||||||
<?php
|
<tr>
|
||||||
if ($i == 0) {
|
|
||||||
$class = 'item first';
|
|
||||||
} elseif ($i == $len - 1) {
|
|
||||||
$class = 'item last';
|
|
||||||
} else {
|
|
||||||
$class = 'item';
|
|
||||||
}
|
|
||||||
$i++;
|
|
||||||
?>
|
|
||||||
<tr class="<?php echo $class ?>">
|
|
||||||
<td><a target="_blank" href="<?php echo $p->url ?>"><?php echo $p->title ?></a></td>
|
<td><a target="_blank" href="<?php echo $p->url ?>"><?php echo $p->title ?></a></td>
|
||||||
<td><?php echo format_date($p->date) ?></td>
|
<td><?php echo format_date($p->date) ?></td>
|
||||||
<?php if ($category->url !== site_url() . 'category/uncategorized') {?>
|
<?php if ($category->url !== site_url() . 'category/uncategorized') {?>
|
||||||
|
|
|
||||||
|
|
@ -1826,8 +1826,8 @@ get('/admin/categories/:category', function ($category) {
|
||||||
|
|
||||||
$desc = get_category_info($category);
|
$desc = get_category_info($category);
|
||||||
|
|
||||||
if(strtolower($category) !== 'uncategorized') {
|
if(!empty($desc)) {
|
||||||
$desc = $desc[0];
|
$desc = $desc[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$total = $desc->count;
|
$total = $desc->count;
|
||||||
|
|
@ -1885,10 +1885,9 @@ get('/category/:category', function ($category) {
|
||||||
|
|
||||||
$desc = get_category_info($category);
|
$desc = get_category_info($category);
|
||||||
|
|
||||||
if(strtolower($category) !== 'uncategorized') {
|
|
||||||
if(!empty($desc)) {
|
if(!empty($desc)) {
|
||||||
$desc = $desc[0];
|
$desc = $desc[0];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$total = $desc->count;
|
$total = $desc->count;
|
||||||
|
|
@ -1953,10 +1952,8 @@ get('/category/:category/feed', function ($category) {
|
||||||
|
|
||||||
$data = get_category_info($category);
|
$data = get_category_info($category);
|
||||||
|
|
||||||
if(strtolower($category) !== 'uncategorized') {
|
if(!empty($data)) {
|
||||||
if(!empty($data)) {
|
$data = $data[0];
|
||||||
$data = $data[0];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show an RSS feed
|
// Show an RSS feed
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ function get_category_files()
|
||||||
{
|
{
|
||||||
static $_desc = array();
|
static $_desc = array();
|
||||||
if (empty($_desc)) {
|
if (empty($_desc)) {
|
||||||
$url = 'cache/index/index-category.txt';
|
$url = 'cache/index/index-category-files.txt';
|
||||||
if (!file_exists($url)) {
|
if (!file_exists($url)) {
|
||||||
rebuilt_cache('all');
|
rebuilt_cache('all');
|
||||||
}
|
}
|
||||||
|
|
@ -198,6 +198,20 @@ function get_category_folder()
|
||||||
return $_dfolder;
|
return $_dfolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get category info files.
|
||||||
|
function get_category_slug()
|
||||||
|
{
|
||||||
|
static $_cslug = array();
|
||||||
|
if (empty($_cslug)) {
|
||||||
|
$url = 'cache/index/index-category.txt';
|
||||||
|
if (!file_exists($url)) {
|
||||||
|
rebuilt_cache('all');
|
||||||
|
}
|
||||||
|
$_cslug = unserialize(file_get_contents($url));
|
||||||
|
}
|
||||||
|
return $_cslug;
|
||||||
|
}
|
||||||
|
|
||||||
// Get images in content/images folder
|
// Get images in content/images folder
|
||||||
function get_gallery() {
|
function get_gallery() {
|
||||||
static $_gallery = array();
|
static $_gallery = array();
|
||||||
|
|
@ -241,6 +255,8 @@ function rebuilt_cache($type = null)
|
||||||
$subpage_cache = array();
|
$subpage_cache = array();
|
||||||
$author_cache = array();
|
$author_cache = array();
|
||||||
$scheduled = array();
|
$scheduled = array();
|
||||||
|
$category_cache = array();
|
||||||
|
$ctmp = array();
|
||||||
|
|
||||||
if (is_dir($dir) === false) {
|
if (is_dir($dir) === false) {
|
||||||
mkdir($dir, 0775, true);
|
mkdir($dir, 0775, true);
|
||||||
|
|
@ -260,6 +276,13 @@ function rebuilt_cache($type = null)
|
||||||
$string_posts = serialize($posts_cache);
|
$string_posts = serialize($posts_cache);
|
||||||
file_put_contents('cache/index/index-posts.txt', print_r($string_posts, true));
|
file_put_contents('cache/index/index-posts.txt', print_r($string_posts, true));
|
||||||
|
|
||||||
|
// Collect category slug
|
||||||
|
foreach ($posts_cache as $key => $c) {
|
||||||
|
$cd = explode('/', $c['dirname']);
|
||||||
|
$ctmp[] = $cd[3];
|
||||||
|
}
|
||||||
|
file_put_contents('cache/index/index-category.txt', print_r(serialize(array_unique($ctmp, SORT_REGULAR)), true));
|
||||||
|
|
||||||
// Rebuilt static page index
|
// Rebuilt static page index
|
||||||
$ptmp = array();
|
$ptmp = array();
|
||||||
$ptmp = glob('content/static/*.md', GLOB_NOSORT);
|
$ptmp = glob('content/static/*.md', GLOB_NOSORT);
|
||||||
|
|
@ -300,7 +323,7 @@ function rebuilt_cache($type = null)
|
||||||
$author_string = serialize($author_cache);
|
$author_string = serialize($author_cache);
|
||||||
file_put_contents('cache/index/index-author.txt', print_r($author_string, true));
|
file_put_contents('cache/index/index-author.txt', print_r($author_string, true));
|
||||||
|
|
||||||
// Rebuilt category index
|
// Rebuilt category files index
|
||||||
$ctmp = array();
|
$ctmp = array();
|
||||||
$ctmp = glob('content/data/category/*.md', GLOB_NOSORT);
|
$ctmp = glob('content/data/category/*.md', GLOB_NOSORT);
|
||||||
if (is_array($ctmp)) {
|
if (is_array($ctmp)) {
|
||||||
|
|
@ -310,7 +333,7 @@ function rebuilt_cache($type = null)
|
||||||
}
|
}
|
||||||
usort($category_cache, "sortfile_a");
|
usort($category_cache, "sortfile_a");
|
||||||
$category_string = serialize($category_cache);
|
$category_string = serialize($category_cache);
|
||||||
file_put_contents('cache/index/index-category.txt', print_r($category_string, true));
|
file_put_contents('cache/index/index-category-files.txt', print_r($category_string, true));
|
||||||
|
|
||||||
// Rebuilt scheduled posts index
|
// Rebuilt scheduled posts index
|
||||||
$stmp = array();
|
$stmp = array();
|
||||||
|
|
@ -837,21 +860,44 @@ function get_category($category, $page, $perpage, $random = null)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return category info.
|
// Return category info.
|
||||||
function get_category_info($category)
|
function get_category_info($category = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
$tmp = array();
|
$tmp = array();
|
||||||
if (is_null($category)) {
|
$cslug= get_category_slug();
|
||||||
$tmp[] = default_category();
|
|
||||||
} elseif (strtolower($category) == 'uncategorized') {
|
if (!empty($cslug)) {
|
||||||
return default_category();
|
if (is_null($category)) {
|
||||||
|
foreach ($cslug as $key => $c){
|
||||||
|
$ctmp = read_category_info($c);
|
||||||
|
if (!empty($ctmp[0])) {
|
||||||
|
$tmp[] = $ctmp[0];
|
||||||
|
} else {
|
||||||
|
$tmp[] = default_category($c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach ($cslug as $key => $c){
|
||||||
|
if ($c === $category) {
|
||||||
|
$ctmp = read_category_info($category);
|
||||||
|
if (!empty($ctmp[0])) {
|
||||||
|
$tmp[] = $ctmp[0];
|
||||||
|
} else {
|
||||||
|
$tmp[] = default_category($category);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return $tmp;
|
||||||
$posts = get_category_files();
|
}
|
||||||
|
|
||||||
if (!empty($posts)) {
|
function read_category_info($category)
|
||||||
|
{
|
||||||
foreach ($posts as $index => $v) {
|
$cFiles = get_category_files();
|
||||||
|
$tmp = array();
|
||||||
|
if (!empty($cFiles)) {
|
||||||
|
foreach ($cFiles as $index => $v) {
|
||||||
if (stripos($v['basename'], $category . '.md') !== false) {
|
if (stripos($v['basename'], $category . '.md') !== false) {
|
||||||
|
|
||||||
$desc = new stdClass;
|
$desc = new stdClass;
|
||||||
|
|
@ -883,27 +929,37 @@ function get_category_info($category)
|
||||||
$desc->description = get_content_tag("d", $content, get_description($desc->body));
|
$desc->description = get_content_tag("d", $content, get_description($desc->body));
|
||||||
|
|
||||||
$tmp[] = $desc;
|
$tmp[] = $desc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return $tmp;
|
||||||
return $tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return default category
|
// Return default category
|
||||||
function default_category()
|
function default_category($category = null)
|
||||||
{
|
{
|
||||||
$tmp = array();
|
$tmp = array();
|
||||||
$desc = new stdClass;
|
$desc = new stdClass;
|
||||||
|
|
||||||
$desc->title = i18n("Uncategorized");
|
if ($category == 'uncategorized') {
|
||||||
$desc->url = site_url() . 'category/uncategorized';
|
$desc->title = i18n("Uncategorized");
|
||||||
$desc->slug = 'uncategorized';
|
$desc->url = site_url() . 'category/uncategorized';
|
||||||
$desc->body = '<p>' . i18n('Uncategorized_comment') . '</p>';
|
$desc->slug = 'uncategorized';
|
||||||
$desc->md = 'uncategorized';
|
$desc->body = '<p>' . i18n('Uncategorized_comment') . '</p>';
|
||||||
$desc->description = i18n('Uncategorized_comment');
|
$desc->md = 'uncategorized';
|
||||||
$desc->file = '';
|
$desc->description = i18n('Uncategorized_comment');
|
||||||
$desc->count = get_categorycount($desc->md);
|
$desc->file = '';
|
||||||
|
$desc->count = get_categorycount($desc->md);
|
||||||
|
} else {
|
||||||
|
$desc->title = $category;
|
||||||
|
$desc->url = site_url() . 'category/' . $category;
|
||||||
|
$desc->slug = $category;
|
||||||
|
$desc->body = '<p>' . i18n('All_blog_posts') . ': ' . $category . '</p>';
|
||||||
|
$desc->md = $category;
|
||||||
|
$desc->description = i18n('All_blog_posts') . ': ' . $category;
|
||||||
|
$desc->file = '';
|
||||||
|
$desc->count = get_categorycount($category);
|
||||||
|
}
|
||||||
|
|
||||||
return $tmp[] = $desc;
|
return $tmp[] = $desc;
|
||||||
}
|
}
|
||||||
|
|
@ -925,11 +981,10 @@ function category_list($custom = null) {
|
||||||
$cat = unserialize(file_get_contents($filename));
|
$cat = unserialize(file_get_contents($filename));
|
||||||
} else {
|
} else {
|
||||||
$arr = get_category_info(null);
|
$arr = get_category_info(null);
|
||||||
foreach ($arr as $a) {
|
foreach ($arr as $i => $a) {
|
||||||
$cat[] = array($a->md, $a->title, $a->count);
|
$cat[] = array($a->md, $a->title, $a->count, $a->description);
|
||||||
}
|
}
|
||||||
|
|
||||||
asort($cat);
|
|
||||||
$tmp = serialize($cat);
|
$tmp = serialize($cat);
|
||||||
file_put_contents($filename, print_r($tmp, true));
|
file_put_contents($filename, print_r($tmp, true));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue