Handle null value

This commit is contained in:
Dan 2025-03-27 09:21:25 +07:00
commit e2ba3fb06b
3 changed files with 43 additions and 25 deletions

View file

@ -1264,16 +1264,16 @@ function get_draft($profile, $page, $perpage)
foreach ($posts as $index => $v) { foreach ($posts as $index => $v) {
$str = explode('/', $v['dirname']); $str = explode('/', $v['dirname']);
if (strtolower($profile) === strtolower($str[1]) || $role === 'admin') { if (strtolower($profile) === strtolower($str[1]) || $role === 'editor' || $role === 'admin') {
$tmp[] = $v; $tmp[] = $v;
} }
} }
if (empty($tmp)) { if (empty($tmp)) {
return false; return $tmp;
} }
return $tmp = get_posts($tmp, $page, $perpage); return $tmp = array(get_posts($tmp, $page, $perpage), count($tmp));
} }
// Return draft static page. // Return draft static page.
@ -1480,16 +1480,16 @@ function get_scheduled($profile, $page, $perpage)
foreach ($posts as $index => $v) { foreach ($posts as $index => $v) {
$str = explode('/', $v['dirname']); $str = explode('/', $v['dirname']);
if (strtolower($profile) === strtolower($str[1]) || $role === 'admin') { if (strtolower($profile) === strtolower($str[1]) || $role === 'editor' || $role === 'admin') {
$tmp[] = $v; $tmp[] = $v;
} }
} }
if (empty($tmp)) { if (empty($tmp)) {
return false; return $tmp;
} }
return $tmp = get_posts($tmp, $page, $perpage); return $tmp = array(get_posts($tmp, $page, $perpage), count($tmp));
} }
// Import RSS feed // Import RSS feed

View file

@ -71,7 +71,7 @@ get('/index', function () {
$posts = get_posts(null, $page, $perpage); $posts = get_posts(null, $page, $perpage);
$total = ''; $total = count(get_blog_posts());
$pv = $vroot . '/main--front.html.php'; $pv = $vroot . '/main--front.html.php';
if (file_exists($pv)) { if (file_exists($pv)) {
@ -1235,7 +1235,7 @@ get('/admin/posts', function () {
$posts = get_posts(null, $page, $perpage); $posts = get_posts(null, $page, $perpage);
$total = ''; $total = count(get_blog_posts());
if (empty($posts) || $page < 1) { if (empty($posts) || $page < 1) {
@ -1426,6 +1426,7 @@ get('/admin/draft', function () {
$page = from($_GET, 'page'); $page = from($_GET, 'page');
$page = $page ? (int)$page : 1; $page = $page ? (int)$page : 1;
$perpage = config('profile.perpage'); $perpage = config('profile.perpage');
$total = '';
$posts = get_draft($name, $page, $perpage); $posts = get_draft($name, $page, $perpage);
@ -1433,7 +1434,9 @@ get('/admin/draft', function () {
$draftSubpages = find_draft_subpage(); $draftSubpages = find_draft_subpage();
$total = get_draftcount($name); if ($posts) {
$total = $posts[1];
}
$author = get_author($name); $author = get_author($name);
@ -1472,7 +1475,7 @@ get('/admin/draft', function () {
'metatags' => generate_meta(null, null), 'metatags' => generate_meta(null, null),
'heading' => i18n('My_draft'), 'heading' => i18n('My_draft'),
'page' => $page, 'page' => $page,
'posts' => $posts, 'posts' => $posts[0],
'draftPages' => $draftPages, 'draftPages' => $draftPages,
'draftSubpages' => $draftSubpages, 'draftSubpages' => $draftSubpages,
'about' => $author->about, 'about' => $author->about,
@ -1501,10 +1504,13 @@ get('/admin/scheduled', function () {
$page = from($_GET, 'page'); $page = from($_GET, 'page');
$page = $page ? (int)$page : 1; $page = $page ? (int)$page : 1;
$perpage = config('profile.perpage'); $perpage = config('profile.perpage');
$total = '';
$posts = get_scheduled($name, $page, $perpage); $posts = get_scheduled($name, $page, $perpage);
$total = get_scheduledcount($name); if ($posts) {
$total = $posts[1];
}
$author = get_author($name); $author = get_author($name);
@ -1541,7 +1547,7 @@ get('/admin/scheduled', function () {
'metatags' => generate_meta(null, null), 'metatags' => generate_meta(null, null),
'heading' => i18n('Scheduled_posts'), 'heading' => i18n('Scheduled_posts'),
'page' => $page, 'page' => $page,
'posts' => $posts, 'posts' => $posts[0],
'about' => $author->about, 'about' => $author->about,
'name' => $author->name, 'name' => $author->name,
'type' => 'is_admin-scheduled', 'type' => 'is_admin-scheduled',
@ -4432,7 +4438,7 @@ get('/:static', function ($static) {
$posts = get_posts(null, $page, $perpage); $posts = get_posts(null, $page, $perpage);
$total = ''; $total = count(get_blog_posts());
$vroot = rtrim(config('views.root'), '/'); $vroot = rtrim(config('views.root'), '/');

View file

@ -873,6 +873,9 @@ function find_subpage($static, $sub_static = null)
// Return category page. // Return category page.
function get_category($category, $page, $perpage, $random = null) function get_category($category, $page, $perpage, $random = null)
{ {
if (is_null($category)) return array();
$posts = get_blog_posts(); $posts = get_blog_posts();
if ($random === true) { if ($random === true) {
@ -898,7 +901,7 @@ function get_category($category, $page, $perpage, $random = null)
} }
if (empty($tmp)) { if (empty($tmp)) {
return false; return $tmp;
} }
$tmp = array_unique($tmp, SORT_REGULAR); $tmp = array_unique($tmp, SORT_REGULAR);
@ -1073,6 +1076,8 @@ function category_list($custom = null)
// Return type page. // Return type page.
function get_type($type, $page, $perpage) function get_type($type, $page, $perpage)
{ {
if (is_null($type)) return array();
$posts = get_blog_posts(); $posts = get_blog_posts();
$tmp = array(); $tmp = array();
@ -1105,6 +1110,8 @@ function get_type($type, $page, $perpage)
// Return tag page. // Return tag page.
function get_tag($tag, $page, $perpage, $random = null) function get_tag($tag, $page, $perpage, $random = null)
{ {
if (is_null($tag)) return array();
$posts = get_blog_posts(); $posts = get_blog_posts();
if ($random === true) { if ($random === true) {
@ -1139,6 +1146,8 @@ function get_tag($tag, $page, $perpage, $random = null)
// Return archive page. // Return archive page.
function get_archive($req, $page, $perpage) function get_archive($req, $page, $perpage)
{ {
if (is_null($req)) return array();
$posts = get_blog_posts(); $posts = get_blog_posts();
$tmp = array(); $tmp = array();
@ -1151,7 +1160,7 @@ function get_archive($req, $page, $perpage)
} }
if (empty($tmp)) { if (empty($tmp)) {
return false; return $tmp;
} }
return $tmp = get_posts($tmp, $page, $perpage); return $tmp = get_posts($tmp, $page, $perpage);
@ -1160,6 +1169,8 @@ function get_archive($req, $page, $perpage)
// Return posts list on profile. // Return posts list on profile.
function get_profile_posts($name, $page, $perpage) function get_profile_posts($name, $page, $perpage)
{ {
if (is_null($name)) return array();
$posts = get_blog_posts(); $posts = get_blog_posts();
$tmp = array(); $tmp = array();
@ -1172,7 +1183,7 @@ function get_profile_posts($name, $page, $perpage)
} }
if (empty($tmp)) { if (empty($tmp)) {
return false; return $tmp;
} }
return $tmp = get_posts($tmp, $page, $perpage); return $tmp = get_posts($tmp, $page, $perpage);
@ -1181,6 +1192,8 @@ function get_profile_posts($name, $page, $perpage)
// Return author info. // Return author info.
function get_author($name) function get_author($name)
{ {
if (is_null($name)) return array();
$names = get_author_name(); $names = get_author_name();
$tmp = array(); $tmp = array();
@ -1237,11 +1250,7 @@ function get_author($name)
} }
} }
if (!empty($tmp)) { return $tmp;
return $tmp;
} else {
return false;
}
} }
// Return default profile // Return default profile
@ -1314,7 +1323,7 @@ function get_keyword($keyword, $page, $perpage)
{ {
if (strlen($keyword) < 3) { if (strlen($keyword) < 3) {
return false; return array();
} }
$posts = get_blog_posts(); $posts = get_blog_posts();
@ -1347,7 +1356,7 @@ function get_keyword($keyword, $page, $perpage)
} }
if (empty($tmp)) { if (empty($tmp)) {
return false; return $tmp;
} }
return $tmp = array(get_posts($tmp, $page, $perpage), count($tmp)); return $tmp = array(get_posts($tmp, $page, $perpage), count($tmp));
@ -1357,6 +1366,7 @@ function get_keyword($keyword, $page, $perpage)
// Get related posts base on post category. // Get related posts base on post category.
function get_related($tag, $custom = null, $count = null) function get_related($tag, $custom = null, $count = null)
{ {
if (empty($count)) { if (empty($count)) {
$count = config('related.count'); $count = config('related.count');
if (empty($count)) { if (empty($count)) {
@ -1551,7 +1561,7 @@ function get_tagcount($var)
function keyword_count($keyword) function keyword_count($keyword)
{ {
if (strlen($keyword) < 3) { if (strlen($keyword) < 3) {
return false; return array();
} }
$posts = get_blog_posts(); $posts = get_blog_posts();
@ -1620,6 +1630,8 @@ function recent_profile_posts($name, $count = null, $custom = null)
function get_recent($filter, $var, $count = null, $custom = null) function get_recent($filter, $var, $count = null, $custom = null)
{ {
if (is_null($var)) return array();
if (empty($count)) { if (empty($count)) {
$count = config('recent.count'); $count = config('recent.count');
if (empty($count)) { if (empty($count)) {
@ -2156,7 +2168,7 @@ function static_next($next)
function has_pagination($total, $perpage, $page = 1) function has_pagination($total, $perpage, $page = 1)
{ {
if (!$total) { if (!$total) {
$total = count(get_blog_posts()); return;
} }
$totalPage = ceil($total / $perpage); $totalPage = ceil($total / $perpage);
$number = i18n('Page') . ' ' . $page . ' ' . i18n('of') . ' ' . $totalPage; $number = i18n('Page') . ' ' . $page . ' ' . i18n('of') . ' ' . $totalPage;