From 0663880cfbf4efdfc33b0a31e376e1ba54127fa6 Mon Sep 17 00:00:00 2001 From: danpros Date: Mon, 1 Jan 2024 23:09:28 +0700 Subject: [PATCH] Add offline message --- system/admin/admin.php | 49 +++++++++++++++++++++----------------- system/admin/views/update.html.php | 49 +++++++++++++++++++++----------------- 2 files changed, 54 insertions(+), 44 deletions(-) diff --git a/system/admin/admin.php b/system/admin/admin.php index d02d831..70d24f7 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -1275,39 +1275,44 @@ function find_draft_subpage($sub_static = null) foreach ($posts as $index => $v) { if (stripos($v['basename'], $sub_static . '.md') !== false) { - - $post = new stdClass; $static = str_replace('content/static/', '', dirname($v['dirname'])); - - // The static page URL - $url= $v['filename']; - $post->url = site_url() . $static . "/" . $url; - - $post->file = $v['dirname'] . '/' . $v['basename']; - $post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($post->file))); - $post->md = $url; + $spage = find_page($static); - $post->parent = $static; + if ($spage) { + + $post = new stdClass; + + // The static page URL + $url= $v['filename']; + $post->url = site_url() . $static . "/" . $url; - // Get the contents and convert it to HTML - $content = file_get_contents($post->file); + $post->file = $v['dirname'] . '/' . $v['basename']; + $post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($post->file))); + + $post->md = $url; + + $post->parent = $static; - // Extract the title and body - $post->title = get_content_tag('t', $content, 'Untitled static subpage: ' . format_date($post->lastMod, 'l, j F Y, H:i')); + // Get the contents and convert it to HTML + $content = file_get_contents($post->file); - // Get the contents and convert it to HTML - $post->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); + // Extract the title and body + $post->title = get_content_tag('t', $content, 'Untitled static subpage: ' . format_date($post->lastMod, 'l, j F Y, H:i')); - $post->views = get_views($post->file); + // Get the contents and convert it to HTML + $post->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); - $post->description = get_content_tag("d", $content, get_description($post->body)); + $post->views = get_views($post->file); - $word_count = str_word_count(strip_tags($post->body)); - $post->readTime = ceil($word_count / 200); + $post->description = get_content_tag("d", $content, get_description($post->body)); - $tmp[] = $post; + $word_count = str_word_count(strip_tags($post->body)); + $post->readTime = ceil($word_count / 200); + + $tmp[] = $post; + } } } } diff --git a/system/admin/views/update.html.php b/system/admin/views/update.html.php index ea4d8db..e57d685 100644 --- a/system/admin/views/update.html.php +++ b/system/admin/views/update.html.php @@ -9,26 +9,31 @@ $updater = new HubUpdater(array( 'name' => 'danpros/htmly', 'prerelease' => !!config("prerelease"), )); - -if ($updater->able()) { - $info = $updater->getNewestInfo(); - echo '

'.i18n('Update_Available').'


'; - echo '

'. $info['name'] .'

'; - echo '

Version: '. $info['tag_name'] .'

'; - echo '
Release Notes
'; - echo '
'; - echo \Michelf\MarkdownExtra::defaultTransform($info['body']); - echo '
'; - echo '

Important: Please always backup your files before upgrading to newer version.

'; - echo '

'.i18n('Update_to').' '. $info['tag_name'] . ' '.i18n('now').'

'; -} else { - echo '

'.i18n('Congrats_You_have_the_latest_version_of_HTMLy').'


'; - $info = $updater->getCurrentInfo(); - echo '

'. $info['name'] .'

'; - echo '

Installed Version: '. $info['tag_name'] .'

'; - echo '
Release Notes:
'; - echo '
'; - echo \Michelf\MarkdownExtra::defaultTransform($info['body']); - echo '
'; - echo '

Read on Github

'; + +if (empty($updater->getNewestInfo())) { + echo '

'.i18n('Update').'


'; + echo "Can't check Github server for latest version. You are probably offline."; +} else { + if ($updater->able()) { + $info = $updater->getNewestInfo(); + echo '

'.i18n('Update_Available').'


'; + echo '

'. $info['name'] .'

'; + echo '

Version: '. $info['tag_name'] .'

'; + echo '
Release Notes
'; + echo '
'; + echo \Michelf\MarkdownExtra::defaultTransform($info['body']); + echo '
'; + echo '

Important: Please always backup your files before upgrading to newer version.

'; + echo '

'.i18n('Update_to').' '. $info['tag_name'] . ' '.i18n('now').'

'; + } else { + echo '

'.i18n('Congrats_You_have_the_latest_version_of_HTMLy').'


'; + $info = $updater->getCurrentInfo(); + echo '

'. $info['name'] .'

'; + echo '

Installed Version: '. $info['tag_name'] .'

'; + echo '
Release Notes:
'; + echo '
'; + echo \Michelf\MarkdownExtra::defaultTransform($info['body']); + echo '
'; + echo '

Read on Github

'; + } } \ No newline at end of file