diff --git a/README.md b/README.md index 2947a7d9..74ed9990 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Install HTMLy using the source code: 4. Follow the installer to install HTMLy. 5. The installer will try to delete itself. Please delete the installer manually if the `install.php` still exist. -**Note:** If you don't need to log in to the dashboard right away, just rename `config.ini.example` to `config.ini`, delete `install.php`, and your are set. It's always good practice to set the `site.url` +**Note:** If you don't need to log in to the dashboard, just rename `config.ini.example` to `config.ini`, delete `install.php`, and you are set. It's always good practice to set the `site.url` ### Online install @@ -50,14 +50,14 @@ If you use the dashboard to write your posts, the folder structure and filenames The following is an example of a folder and file structure from HTMLy: ```html -content/my-username/blog/my-category/post/2024-01-10-25-35-45_tag1,tag2_my-post-slug.md +content/my-username/blog/my-category/post/2024-01-10-15-35-45_tag1,tag2_my-post-slug.md ``` Here's the explanation: * `my-username` is the username. * `my-category` is the content category. * `post` is the content type. Available content type `post`, `video`, `audio`, `link`, `quote`. -* `2024-01-10-25-35-45` is the published date. The date format is `Y-m-d-H-i-s` +* `2024-01-10-15-35-45` is the published date. The date format is `Y-m-d-H-i-s` * `tag1,tag2` are the tags, separated by commas * `my-post-slug` is the URL @@ -71,7 +71,7 @@ To claim this content or log in to dashboard, simply create `my-username.ini` in ;Password password = yourpassword -; Encryption: Set to clear, and later it will changed to password_hash automatically during login +;Encryption: Set to clear, and later it will changed to password_hash automatically during login encryption = clear ;Role @@ -102,7 +102,7 @@ This is my category info etc. **Important:** Every time new content added (post, pages, category), or you make changes that change the folder structure or filenames, simply delete the `index` and `widget` folder inside `cache` folder so that the changes detected by HTMLy. -**Post Views Limitations:** HTMLy using the filename path as the ID for the post/page views counter. So if you edit a post/page without using the dashboard which results in changes to the folder structure or filename, then you must edit `views.json` in the `content/data/` folder manually to update to correct path. +**Post Views limitations:** HTMLy using the filename path as the ID for the post/page views counter. So if you edit a post/page without using the dashboard which results in changes to the folder structure or filename, then you must edit `views.json` in the `content/data/` folder manually to update to the correct path. Static pages ------------ @@ -134,6 +134,22 @@ An example pages/subpages content looks like: This is my page info etc. ``` +**Page ordering** + +To sort the pages, you just need to add integer value followed by a period. + +```html +content/static/01.contact.md +content/static/02.about.md +``` + +For static subpages: + +```html +content/static/01.contact/01.us.md +content/static/01.contact/02.me.md +``` + Content Tags ------------- If you are writing locally, you need specify the content tags below: diff --git a/cache/installedVersion.json b/cache/installedVersion.json index 27124a8b..7d3aacfb 100644 --- a/cache/installedVersion.json +++ b/cache/installedVersion.json @@ -1,3 +1,3 @@ { - "tag_name": "v2.9.0" + "tag_name": "v2.9.1" } \ No newline at end of file diff --git a/config/config.ini.example b/config/config.ini.example index 93434c27..cb345f94 100644 --- a/config/config.ini.example +++ b/config/config.ini.example @@ -136,7 +136,7 @@ cache.timestamp = "false" multi.site = "false" ; Set the theme here -views.root = "themes/twentyfifteen" +views.root = "themes/twentysixteen" ; Framework config. No need to edit. views.layout = "layout" diff --git a/config/users/username.ini.example b/config/users/username.ini.example index b2c0fb95..7dd5ec4c 100644 --- a/config/users/username.ini.example +++ b/config/users/username.ini.example @@ -1,7 +1,7 @@ ;Password password = yourpassword -; Encryption. Set to clear, and later it will changed to password_hash automatically during login +;Encryption. Set to clear, and later it will changed to password_hash automatically during login encryption = clear ;Role diff --git a/index.php b/index.php index f81aa7d0..dd5ade16 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,6 @@ convertRequestToConfig(); $configFile = file_get_contents("config/config.ini.example"); $configFile = $this->overwriteINI($config, $configFile); - file_put_contents("config/config.ini", $configFile); + file_put_contents("config/config.ini", $configFile, LOCK_EX); //save users/[Username].ini $userFile = file_get_contents("config/users/username.ini.example"); @@ -152,7 +152,7 @@ protected function saveConfigs() 'role' => 'admin', ), $userFile); } - file_put_contents("config/users/" . $this->user . ".ini", $userFile); + file_put_contents("config/users/" . $this->user . ".ini", $userFile, LOCK_EX); } protected function testTheEnvironment() @@ -438,4 +438,4 @@ function checkCommentSystemSelection(){ } - \ No newline at end of file + diff --git a/system/admin/admin.php b/system/admin/admin.php index bb2e1a3a..0c70f03a 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -23,7 +23,7 @@ function update_user($userName, $password, $role) if (file_exists($file)) { file_put_contents($file, "password = " . password_hash($password, PASSWORD_DEFAULT) . "\n" . "encryption = password_hash\n" . - "role = " . $role . "\n"); + "role = " . $role . "\n", LOCK_EX); return true; } return false; @@ -38,7 +38,7 @@ function create_user($userName, $password, $role = "user") } else { file_put_contents($file, "password = " . password_hash($password, PASSWORD_DEFAULT) . "\n" . "encryption = password_hash\n" . - "role = " . $role . "\n"); + "role = " . $role . "\n", LOCK_EX); return true; } } @@ -119,7 +119,6 @@ function remove_accent($str) // Add content function add_content($title, $tag, $url, $content, $user, $draft, $category, $type, $description = null, $media = null, $dateTime = null) { - $tag = explode(',', preg_replace("/\s*,\s*/", ",", rtrim($tag, ','))); $tag = array_filter(array_unique($tag)); $tagslang = "content/data/tags.lang"; @@ -229,10 +228,10 @@ function add_content($title, $tag, $url, $content, $user, $draft, $category, $ty } if (is_dir($dir)) { - file_put_contents($dir . $filename, print_r($post_content, true)); + file_put_contents($dir . $filename, print_r($post_content, true), LOCK_EX); } else { mkdir($dir, 0775, true); - file_put_contents($dir . $filename, print_r($post_content, true)); + file_put_contents($dir . $filename, print_r($post_content, true), LOCK_EX); } save_tag_i18n($post_tag, $post_tagmd); @@ -257,7 +256,6 @@ function add_content($title, $tag, $url, $content, $user, $draft, $category, $ty // Edit content function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, $type, $destination = null, $description = null, $date = null, $media = null) { - $tag = explode(',', preg_replace("/\s*,\s*/", ",", rtrim($tag, ','))); $tag = array_filter(array_unique($tag)); $tagslang = "content/data/tags.lang"; @@ -377,7 +375,7 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ $newfile = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; } - file_put_contents($newfile, print_r($post_content, true)); + file_put_contents($newfile, print_r($post_content, true), LOCK_EX); unlink($oldfile); } else { @@ -395,10 +393,10 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ } if ($oldfile === $newfile) { - file_put_contents($oldfile, print_r($post_content, true)); + file_put_contents($oldfile, print_r($post_content, true), LOCK_EX); } else { rename($oldfile, $newfile); - file_put_contents($newfile, print_r($post_content, true)); + file_put_contents($newfile, print_r($post_content, true), LOCK_EX); } } else { @@ -412,7 +410,7 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ } } - file_put_contents($newfile, print_r($post_content, true)); + file_put_contents($newfile, print_r($post_content, true), LOCK_EX); unlink($oldfile); } @@ -451,7 +449,7 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ if (file_exists($viewsFile)) { $views = json_decode(file_get_contents($viewsFile), true); $arr = replace_key($views, $oldfile, $newfile); - file_put_contents($viewsFile, json_encode($arr, JSON_UNESCAPED_UNICODE)); + file_put_contents($viewsFile, json_encode($arr, JSON_UNESCAPED_UNICODE), LOCK_EX); } } @@ -489,7 +487,6 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ // Add static page function add_page($title, $url, $content, $draft, $description = null) { - $post_title = safe_html($title); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $description = safe_html($description); @@ -525,12 +522,12 @@ function add_page($title, $url, $content, $draft, $description = null) if (!is_dir($dir)) { mkdir($dir, 0775, true); } - file_put_contents($dir . $filename, print_r($post_content, true)); + file_put_contents($dir . $filename, print_r($post_content, true), LOCK_EX); } else { if (!is_dir($dirDraft)) { mkdir($dirDraft, 0775, true); } - file_put_contents($dirDraft . $filename, print_r($post_content, true)); + file_put_contents($dirDraft . $filename, print_r($post_content, true), LOCK_EX); } rebuilt_cache('all'); @@ -549,7 +546,8 @@ function add_page($title, $url, $content, $draft, $description = null) // Add static sub page function add_sub_page($title, $url, $content, $static, $draft, $description = null) { - + $post = find_page($static); + $static = pathinfo($post['current']->md, PATHINFO_FILENAME); $post_title = safe_html($title); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $description = safe_html($description); @@ -585,12 +583,12 @@ function add_sub_page($title, $url, $content, $static, $draft, $description = nu if (!is_dir($dir)) { mkdir($dir, 0775, true); } - file_put_contents($dir . $filename, print_r($post_content, true)); + file_put_contents($dir . $filename, print_r($post_content, true), LOCK_EX); } else { if (!is_dir($dirDraft)) { mkdir($dirDraft, 0775, true); } - file_put_contents($dirDraft . $filename, print_r($post_content, true)); + file_put_contents($dirDraft . $filename, print_r($post_content, true), LOCK_EX); } rebuilt_cache('all'); @@ -604,10 +602,17 @@ function add_sub_page($title, $url, $content, $static, $draft, $description = nu function edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination = null, $description = null, $static = null) { $dir = pathinfo($oldfile, PATHINFO_DIRNAME); + $fn = explode('.', pathinfo($oldfile, PATHINFO_FILENAME)); + if (isset($fn[1])) { + $num = $fn[0] . '.'; + } else { + $num = null; + } $views = array(); $viewsFile = "content/data/views.json"; $post_title = safe_html($title); - $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + $pUrl = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + $post_url = $num . $pUrl; $description = safe_html($description); if ($description !== null) { if (!empty($description)) { @@ -629,7 +634,7 @@ function edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, mkdir($dirDraft, 0775, true); } $newfile = $dirDraft . '/' . $post_url . '.md'; - file_put_contents($newfile, print_r($post_content, true)); + file_put_contents($newfile, print_r($post_content, true), LOCK_EX); if (empty($static)) { $old = pathinfo($oldfile, PATHINFO_FILENAME); if(is_dir($dir . '/' . $old)) { @@ -639,7 +644,7 @@ function edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, unlink($oldfile); } elseif(!empty($publishDraft)) { $newfile = dirname($dir) . '/' . $post_url . '.md'; - file_put_contents($newfile, print_r($post_content, true)); + file_put_contents($newfile, print_r($post_content, true), LOCK_EX); if (empty($static)) { $old = pathinfo($oldfile, PATHINFO_FILENAME); if(is_dir(dirname($dir) . '/' . $old)) { @@ -650,10 +655,10 @@ function edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, }else { $newfile = $dir . '/' . $post_url . '.md'; if ($oldfile === $newfile) { - file_put_contents($oldfile, print_r($post_content, true)); + file_put_contents($oldfile, print_r($post_content, true), LOCK_EX); } else { rename($oldfile, $newfile); - file_put_contents($newfile, print_r($post_content, true)); + file_put_contents($newfile, print_r($post_content, true), LOCK_EX); if (empty($static)) { $old = pathinfo($oldfile, PATHINFO_FILENAME); if(is_dir($dir . '/' . $old)) { @@ -663,10 +668,16 @@ function edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, } } + $cl = explode('.', $post_url); + if (isset($cl[1])) { + $pu = $cl[1]; + } else { + $pu = $post_url; + } if (!empty($static)) { - $posturl = site_url() . $static .'/'. $post_url; + $posturl = site_url() . $static .'/'. $pu; } else { - $posturl = site_url() . $post_url; + $posturl = site_url() . $pu; } rebuilt_cache('all'); @@ -676,8 +687,24 @@ function edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, if (file_exists($viewsFile)) { $views = json_decode(file_get_contents($viewsFile), true); $arr = replace_key($views, $oldfile, $newfile); - file_put_contents($viewsFile, json_encode($arr, JSON_UNESCAPED_UNICODE)); + file_put_contents($viewsFile, json_encode($arr, JSON_UNESCAPED_UNICODE), LOCK_EX); } + + if (empty($static)) { + $sPage = find_subpage($pu); + $oldSub = 'content/static/' . pathinfo($oldfile, PATHINFO_FILENAME); + $newSub = 'content/static/' . pathinfo($newfile, PATHINFO_FILENAME); + if (!empty($sPage)) { + foreach ($sPage as $sp) { + if (file_exists($viewsFile)) { + $views = json_decode(file_get_contents($viewsFile), true); + $arr = replace_key($views, $oldSub . '/' . $sp->md, $newSub . '/' . $sp->md); + file_put_contents($viewsFile, json_encode($arr, JSON_UNESCAPED_UNICODE), LOCK_EX); + } + } + } + } + } if ($destination == 'post') { @@ -716,10 +743,10 @@ function add_category($title, $url, $content, $description = null) $filename = $post_url . '.md'; $dir = 'content/data/category/'; if (is_dir($dir)) { - file_put_contents($dir . $filename, print_r($post_content, true)); + file_put_contents($dir . $filename, print_r($post_content, true), LOCK_EX); } else { mkdir($dir, 0775, true); - file_put_contents($dir . $filename, print_r($post_content, true)); + file_put_contents($dir . $filename, print_r($post_content, true), LOCK_EX); } rebuilt_cache('all'); @@ -754,13 +781,13 @@ function edit_category($title, $url, $content, $oldfile, $destination = null, $d mkdir($dir, 0775, true); } if ($oldfile === $newfile) { - file_put_contents($oldfile, print_r($post_content, true)); + file_put_contents($oldfile, print_r($post_content, true), LOCK_EX); } else { if (file_exists($oldfile)) { rename($oldfile, $newfile); - file_put_contents($newfile, print_r($post_content, true)); + file_put_contents($newfile, print_r($post_content, true), LOCK_EX); } else { - file_put_contents($newfile, print_r($post_content, true)); + file_put_contents($newfile, print_r($post_content, true), LOCK_EX); } } @@ -787,10 +814,10 @@ function edit_profile($title, $content, $user) $dir = 'content/' . $user . '/'; $filename = 'content/' . $user . '/author.md'; if (is_dir($dir)) { - file_put_contents($filename, print_r($user_content, true)); + file_put_contents($filename, print_r($user_content, true), LOCK_EX); } else { mkdir($dir, 0775, true); - file_put_contents($filename, print_r($user_content, true)); + file_put_contents($filename, print_r($user_content, true), LOCK_EX); } rebuilt_cache('all'); $redirect = site_url() . 'author/' . $user; @@ -809,10 +836,10 @@ function edit_frontpage($title, $content) $dir = 'content/data/frontpage'; $filename = 'content/data/frontpage/frontpage.md'; if (is_dir($dir)) { - file_put_contents($filename, print_r($front_content, true)); + file_put_contents($filename, print_r($front_content, true), LOCK_EX); } else { mkdir($dir, 0775, true); - file_put_contents($filename, print_r($front_content, true)); + file_put_contents($filename, print_r($front_content, true), LOCK_EX); } rebuilt_cache('all'); $redirect = site_url(); @@ -957,16 +984,23 @@ function find_draft_page($static = null) $post = new stdClass; // The static page URL - $url= $v['filename']; + $fn = explode('.', $v['filename']); + + if (isset($fn[1])) { + $url = $fn[1]; + } else { + $url= $v['filename']; + } $post->url = site_url() . $url; $post->file = $v['dirname'] . '/' . $v['basename']; $post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($post->file))); - $post->md = $url; + $post->md = $v['basename']; $post->slug = $url; $post->parent = null; + $post->parentSlug = null; // Get the contents and convert it to HTML $content = file_get_contents($post->file); @@ -1007,25 +1041,35 @@ function find_draft_subpage($static = null, $sub_static = null) foreach ($posts as $index => $v) { if (stripos($v['basename'], $sub_static . '.md') !== false) { - + $post = new stdClass; - - // The static file - $url= $v['filename']; - - if (is_null($static)) { - $parent = str_replace('content/static/', '', dirname($v['dirname'])); - $post->parent = $parent; - $post->url = site_url() . $parent . "/" . $url; + + $fd = str_replace('content/static/', '', dirname($v['dirname'])); + + $pr = explode('.', $fd); + if (isset($pr[1])) { + $ps = $pr[1]; } else { - $post->parent = $static; - $post->url = site_url() . $static . "/" . $url; + $ps = $fd; } + + // The static page URL + $fn = explode('.', $v['filename']); + if (isset($fn[1])) { + $url = $fn[1]; + } else { + $url = $v['filename']; + } + + $post->parent = $fd; + $post->parentSlug = $ps; + $post->url = site_url() . $ps . "/" . $url; + $post->file = $v['dirname'] . '/' . $v['basename']; $post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($post->file))); - - $post->md = $url; + + $post->md = $v['basename']; $post->slug = $url; // Get the contents and convert it to HTML @@ -1103,7 +1147,6 @@ function find_scheduled($year, $month, $name) // Return scheduled list function get_scheduled($profile, $page, $perpage) { - $user = $_SESSION[site_url()]['user']; $role = user('role', $user); $posts = get_scheduled_posts(); @@ -1145,10 +1188,10 @@ function migrate($title, $time, $tags, $content, $url, $user, $source) $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; $dir = 'content/' . $user . '/blog/uncategorized/post/'; if (is_dir($dir)) { - file_put_contents($dir . $filename, print_r($post_content, true)); + file_put_contents($dir . $filename, print_r($post_content, true), LOCK_EX); } else { mkdir($dir, 0775, true); - file_put_contents($dir . $filename, print_r($post_content, true)); + file_put_contents($dir . $filename, print_r($post_content, true), LOCK_EX); } save_tag_i18n($post_tag, $post_tagmd); $redirect = site_url() . 'admin/clear-cache'; @@ -1302,7 +1345,7 @@ function save_tag_i18n($tag,$tagDisplay) } $tmp = serialize($views); - file_put_contents($filename, print_r($tmp, true)); + file_put_contents($filename, print_r($tmp, true), LOCK_EX); } @@ -1438,7 +1481,8 @@ function valueMaker($value) return (string)$value; } -function replace_key($arr, $oldkey, $newkey) { +function replace_key($arr, $oldkey, $newkey) +{ if(array_key_exists($oldkey, $arr)) { $keys = array_keys($arr); $keys[array_search($oldkey, $keys)] = $newkey; @@ -1450,7 +1494,6 @@ function replace_key($arr, $oldkey, $newkey) { // rename category folder function rename_category_folder($new_name, $old_file) { - $old_name = str_replace('.md', '', basename($old_file)); $dir = get_category_folder(); foreach ($dir as $index => $v) { @@ -1461,5 +1504,112 @@ function rename_category_folder($new_name, $old_file) rename($old_folder, $new_folder); } } +} + +// reorder the static page +function reorder_pages($pages = null) +{ + $i = 1; + $arr = array(); + $dir = 'content/static/'; + $viewsFile = "content/data/views.json"; + foreach ($pages as $p) { + $fn = pathinfo($p, PATHINFO_FILENAME); + $num = str_pad($i, 2, 0, STR_PAD_LEFT); + $arr = explode('.' , $fn); + if (isset($arr[1])) { + + $oldSub = find_subpage($arr[1]); + + rename ($dir . $p, $dir . $num . '.' . $arr[1] . '.md'); + + if (file_exists($viewsFile)) { + $views = json_decode(file_get_contents($viewsFile), true); + $mod = replace_key($views, $dir . $p, $dir . $num . '.' . $arr[1] . '.md'); + file_put_contents($viewsFile, json_encode($mod, JSON_UNESCAPED_UNICODE), LOCK_EX); + } + + if (is_dir($dir . $fn)) { + rename($dir . $fn, $dir . $num . '.' . $arr[1]); + + if (!empty($oldSub)) { + foreach ($oldSub as $sp) { + if (file_exists($viewsFile)) { + $views = json_decode(file_get_contents($viewsFile), true); + $mod = replace_key($views, $sp->file, $dir . $num . '.' . $arr[1] . '/' . $sp->md); + file_put_contents($viewsFile, json_encode($mod, JSON_UNESCAPED_UNICODE), LOCK_EX); + } + } + } + + } + + } else { + + $oldSub = find_subpage($fn); + + rename($dir . $p, $dir . $num . '.' . $fn . '.md'); + + if (file_exists($viewsFile)) { + $views = json_decode(file_get_contents($viewsFile), true); + $mod = replace_key($views, $dir . $p, $dir . $num . '.' . $fn . '.md'); + file_put_contents($viewsFile, json_encode($mod, JSON_UNESCAPED_UNICODE), LOCK_EX); + } + + if (is_dir($dir . $fn)) { + rename($dir . $fn, $dir . $num . '.' . $fn); + + if (!empty($oldSub)) { + foreach ($oldSub as $sp) { + if (file_exists($viewsFile)) { + $views = json_decode(file_get_contents($viewsFile), true); + $mod = replace_key($views, $sp->file, $dir . $num . '.' . $fn . '/' . $sp->md); + file_put_contents($viewsFile, json_encode($mod, JSON_UNESCAPED_UNICODE), LOCK_EX); + } + } + } + + } + + } + + $i++; + } + + rebuilt_cache(); +} + +// reorder the subpage +function reorder_subpages($subpages = null) +{ + $i = 1; + $arr = array(); + $dir = 'content/static/'; + $viewsFile = "content/data/views.json"; + foreach ($subpages as $sp) { + $dn = $dir . pathinfo($sp, PATHINFO_DIRNAME) . '/'; + $fn = pathinfo($sp, PATHINFO_FILENAME); + $num = str_pad($i, 2, 0, STR_PAD_LEFT); + $arr = explode('.' , $fn); + if (isset($arr[1])) { + rename ($dir . $sp, $dn . $num . '.' . $arr[1] . '.md'); + if (file_exists($viewsFile)) { + $views = json_decode(file_get_contents($viewsFile), true); + $mod = replace_key($views, $dir . $sp, $dn . $num . '.' . $arr[1] . '.md'); + file_put_contents($viewsFile, json_encode($mod, JSON_UNESCAPED_UNICODE), LOCK_EX); + } + } else { + rename($dir . $sp, $dn . $num . '.' . $fn . '.md'); + if (file_exists($viewsFile)) { + $views = json_decode(file_get_contents($viewsFile), true); + $mod = replace_key($views, $dir . $sp, $dn . $num . '.' . $fn . '.md'); + file_put_contents($viewsFile, json_encode($mod, JSON_UNESCAPED_UNICODE), LOCK_EX); + } + } + + $i++; + + } + rebuilt_cache(); } diff --git a/system/admin/views/add-content.html.php b/system/admin/views/add-content.html.php index b8530bc1..38105cb9 100644 --- a/system/admin/views/add-content.html.php +++ b/system/admin/views/add-content.html.php @@ -21,7 +21,7 @@ $newlang = array_combine($tkey, $tkey); } $tmp = serialize($newlang); - file_put_contents($tagslang, print_r($tmp, true)); + file_put_contents($tagslang, print_r($tmp, true), LOCK_EX); } $images = get_gallery(); @@ -98,7 +98,7 @@ function extractLast( term ) {
@@ -177,7 +177,7 @@ function extractLast( term ) {
- +

diff --git a/system/admin/views/add-page.html.php b/system/admin/views/add-page.html.php index 0d74a4f4..79381a25 100644 --- a/system/admin/views/add-page.html.php +++ b/system/admin/views/add-page.html.php @@ -36,7 +36,7 @@
- +

diff --git a/system/admin/views/categories.html.php b/system/admin/views/categories.html.php index 2e675261..cfe17003 100644 --- a/system/admin/views/categories.html.php +++ b/system/admin/views/categories.html.php @@ -7,20 +7,24 @@

+ + + - + - - md !== 'uncategorized'):?> - - + + slug !== 'uncategorized'):?> + + +
title;?>title;?> body;?>md) + $d->count + get_scheduledcount($d->md); echo $total?> count == 0 && get_draftcount($d->md) == 0 && get_scheduledcount($d->md) == 0){echo '' . i18n('Delete') . '';}?>slug) + $d->count + get_scheduledcount($d->slug); echo $total?> count == 0 && get_draftcount($d->slug) == 0 && get_scheduledcount($d->slug) == 0){echo '' . i18n('Delete') . '';}?>
diff --git a/system/admin/views/category-list.html.php b/system/admin/views/category-list.html.php index b3548dba..c7d1d23f 100644 --- a/system/admin/views/category-list.html.php +++ b/system/admin/views/category-list.html.php @@ -6,18 +6,21 @@

+ + + url !== site_url() . 'category/uncategorized') {?> - + @@ -25,6 +28,7 @@ class="btn btn-danger btn-xs" href="url ?>/delete?destination=adm +
title ?> date) ?>

diff --git a/system/admin/views/edit-content.html.php b/system/admin/views/edit-content.html.php index 7fda7b21..f90ffa51 100644 --- a/system/admin/views/edit-content.html.php +++ b/system/admin/views/edit-content.html.php @@ -66,7 +66,7 @@ $newlang = array_combine($tkey, $tkey); } $tmp = serialize($newlang); - file_put_contents($tagslang, print_r($tmp, true)); + file_put_contents($tagslang, print_r($tmp, true), LOCK_EX); } $images = get_gallery(); @@ -143,7 +143,7 @@ function extractLast( term ) {
@@ -224,7 +224,7 @@ function extractLast( term ) {
- +

diff --git a/system/admin/views/edit-page.html.php b/system/admin/views/edit-page.html.php index 9ac3455b..dc032667 100644 --- a/system/admin/views/edit-page.html.php +++ b/system/admin/views/edit-page.html.php @@ -34,8 +34,8 @@ $oldtitle = $p->title; $olddescription = $p->description; $oldcontent = $p->body; - $oldmd = $p->md; - $url = 'content/data/category/'. $p->md . '.md'; + $oldmd = $p->slug; + $url = 'content/data/category/'. $p->slug . '.md'; } else { if (isset($p->file)) { @@ -55,7 +55,13 @@ } $dir = pathinfo($url, PATHINFO_DIRNAME); $oldurl = pathinfo($url, PATHINFO_BASENAME); - $oldmd = pathinfo($url, PATHINFO_FILENAME); + + $fn = explode('.', pathinfo($url, PATHINFO_FILENAME)); + if (isset($fn[1])) { + $oldmd = $fn[1]; + } else { + $oldmd = pathinfo($url, PATHINFO_FILENAME); + } if (isset($p->url)) { $delete = $p->url . '/delete?destination=' . $destination; @@ -95,7 +101,7 @@
- +


@@ -113,7 +119,7 @@
- +

diff --git a/system/admin/views/layout.html.php b/system/admin/views/layout.html.php index 691fa188..ba3eb73b 100644 --- a/system/admin/views/layout.html.php +++ b/system/admin/views/layout.html.php @@ -10,6 +10,7 @@ + diff --git a/system/admin/views/menu.html.php b/system/admin/views/menu.html.php index a0304b59..966094c0 100644 --- a/system/admin/views/menu.html.php +++ b/system/admin/views/menu.html.php @@ -107,6 +107,7 @@ function parseMenu($menu) { data: {'json': js}, success: function (response) { alert(response.message); + location.reload(); }, }); }); diff --git a/system/admin/views/popular-posts.html.php b/system/admin/views/popular-posts.html.php index 5bce88c2..177a93b1 100644 --- a/system/admin/views/popular-posts.html.php +++ b/system/admin/views/popular-posts.html.php @@ -5,6 +5,7 @@

+ @@ -14,6 +15,8 @@ + + file, '/scheduled/') == false && strpos($p->file, '/draft/') == false) { ?> @@ -29,6 +32,7 @@ class="btn btn-danger btn-xs" href="url ?>/delete?destination=adm +

+ @@ -14,6 +15,8 @@ + + @@ -27,6 +30,7 @@ class="btn btn-danger btn-xs" href="url ?>/delete?destination=admin/posts"> +
title ?>

diff --git a/system/admin/views/scheduled.html.php b/system/admin/views/scheduled.html.php index b321daaa..1ee6a41e 100644 --- a/system/admin/views/scheduled.html.php +++ b/system/admin/views/scheduled.html.php @@ -5,6 +5,7 @@

+ @@ -12,6 +13,8 @@ + + @@ -21,6 +24,7 @@ +
title ?>

diff --git a/system/admin/views/static-pages.html.php b/system/admin/views/static-pages.html.php index 64cc9a72..9470ffa1 100644 --- a/system/admin/views/static-pages.html.php +++ b/system/admin/views/static-pages.html.php @@ -3,52 +3,70 @@


+ - - +
+ + - - - + + + - + + + - md); ?> - md);?> - - - - - - + slug); ?> + slug);?> + + + + - +
title;?> views;?>
title;?>views;?> - - md); - foreach ($subPages as $sp):?> - -
-
- title;?> -
-
- - views;?> -
-
- -
-
- - - -
+ +
+
+ title;?> +
+
views;?>
+
+ +
+
+
+
+ \ No newline at end of file diff --git a/system/admin/views/static-subpages.html.php b/system/admin/views/static-subpages.html.php new file mode 100644 index 00000000..0b43a209 --- /dev/null +++ b/system/admin/views/static-subpages.html.php @@ -0,0 +1,71 @@ + + +
+
+

title ?>

+
description;?>
+
+
+ +

+ +slug);?> + + + + + + + + + + + + + + + + + + + + + + + +
title ?>description;?>views;?>
+
+ + \ No newline at end of file diff --git a/system/admin/views/update.html.php b/system/admin/views/update.html.php index 1ce341dd..f312eb33 100644 --- a/system/admin/views/update.html.php +++ b/system/admin/views/update.html.php @@ -19,14 +19,13 @@ 'cache/installedVersion.json', json_encode(array( "tag_name" => constant('HTMLY_VERSION') - ), JSON_PRETTY_PRINT) - ); + ), JSON_PRETTY_PRINT), LOCK_EX); } else { file_put_contents( 'cache/installedVersion.json', json_encode(array( "tag_name" => constant('HTMLY_VERSION') - )) + )), LOCK_EX ); } diff --git a/system/admin/views/user-draft.html.php b/system/admin/views/user-draft.html.php index 70a18fde..87bd8fe9 100644 --- a/system/admin/views/user-draft.html.php +++ b/system/admin/views/user-draft.html.php @@ -5,6 +5,7 @@

+ @@ -12,6 +13,8 @@ + + @@ -21,6 +24,7 @@ +
title ?>

@@ -51,11 +55,11 @@ - + - md)); ?> + slug)); ?> @@ -68,21 +72,21 @@


-

: Subpages

+

: Sub

title ?> lastMod) ?>
- + - + - parent);?> + parentSlug);?> - +
title ?> lastMod) ?> title;?>title;?>
diff --git a/system/admin/views/user-posts.html.php b/system/admin/views/user-posts.html.php index 4e2b70c0..853966d8 100644 --- a/system/admin/views/user-posts.html.php +++ b/system/admin/views/user-posts.html.php @@ -5,6 +5,7 @@

+ @@ -15,6 +16,8 @@ + + @@ -27,6 +30,7 @@ +
title ?>

diff --git a/system/htmly.php b/system/htmly.php index c9bf520a..468bc16f 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -428,8 +428,12 @@ // Show the "Add content" page get('/add/content', function () { - $req = _h($_GET['type']); - + if (isset($_GET['type'])) { + $req = _h($_GET['type']); + } else { + $req = 'post'; + } + $type = 'is_' . $req; if (login()) { @@ -443,7 +447,7 @@ 'type' => $type, 'is_admin' => true, 'bodyclass' => 'add-content', - 'breadcrumb' => '' . config('breadcrumb.home') . ' »' . i18n('Add_new_post') + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . i18n('Add_new_post') )); } else { $login = site_url() . 'login'; @@ -1122,6 +1126,87 @@ die; }); +post('/admin/pages', function () { + + if (login()) { + $json = from($_REQUEST, 'json'); + reorder_pages($json); + echo json_encode(array( + 'message' => 'Page order saved successfully!', + )); + } +}); + +// Show admin/pages +get('/admin/pages/:static', function ($static) +{ + $user = $_SESSION[site_url()]['user']; + $role = user('role', $user); + if (login()) { + + config('views.root', 'system/admin/views'); + if ($role === 'admin') { + + $post = find_page($static); + + if (!$post) { + not_found(); + } + + if (array_key_exists('prev', $post)) { + $prev = $post['prev']; + } else { + $prev = array(); + } + + if (array_key_exists('next', $post)) { + $next = $post['next']; + } else { + $next = array(); + } + + $post = $post['current']; + + render('static-subpages', array( + 'title' => $post->title . ' - ' . blog_title(), + 'description' => $post->description, + 'canonical' => $post->url, + 'bodyclass' => 'in-page ' . strtolower($static), + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . '' .i18n('pages').' » ' . $post->title, + 'p' => $post, + 'static' => $post, + 'type' => 'staticSubpage', + 'prev' => static_prev($prev), + 'next' => static_next($next), + 'is_page' => true + )); + } else { + render('denied', array( + 'title' => 'Pages - ' . blog_title(), + 'description' => strip_tags(blog_description()), + 'canonical' => site_url(), + 'type' => 'is_admin-pages', + 'is_admin' => true, + 'bodyclass' => 'denied', + 'breadcrumb' => '', + )); + } + } else { + $login = site_url() . 'login'; + } +}); + +post('/admin/pages/:static', function ($static) { + + if (login()) { + $json = from($_REQUEST, 'json'); + reorder_subpages($json); + echo json_encode(array( + 'message' => 'Page order saved successfully!', + )); + } +}); + // Show import page get('/admin/import', function () { if (login()) { @@ -2969,7 +3054,7 @@ if (!$post) { not_found(); } - + if (array_key_exists('prev', $post)) { $prev = $post['prev']; } else { @@ -3048,7 +3133,7 @@ 'type' => 'is_page', 'is_admin' => true, 'bodyclass' => 'add-page', - 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' » ' . i18n('Add_new_page') + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' » ' . i18n('Add_new_page') )); } else { $login = site_url() . 'login'; @@ -3126,7 +3211,7 @@ 'canonical' => site_url(), 'bodyclass' => 'edit-page', 'is_admin' => true, - 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title, + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' .i18n('pages').' » ' . $post->title, 'p' => $post, 'static' => $post, 'type' => 'staticPage', @@ -3355,7 +3440,7 @@ 'canonical' => site_url(), 'bodyclass' => 'edit-page', 'is_admin' => true, - 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' » ' . $page->title, + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' » ' . $page->title, 'p' => $page, 'static' => $page, 'type' => 'subPage', @@ -3457,7 +3542,7 @@ 'canonical' => site_url(), 'bodyclass' => 'delete-page', 'is_admin' => true, - 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' » ' . $page->title, + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' » ' . $page->title, 'p' => $page, 'static' => $page, 'type' => 'subPage', diff --git a/system/includes/dispatch.php b/system/includes/dispatch.php index 4c5a3aff..6dd9b07a 100644 --- a/system/includes/dispatch.php +++ b/system/includes/dispatch.php @@ -51,12 +51,10 @@ function site_path() function theme_path() { - if (config('views.root') == null) error(500, '[views.root] is not set'); return site_url() . rtrim(config('views.root'), '/') . '/'; - } function error($code, $message) @@ -68,7 +66,6 @@ function error($code, $message) // Set the language function get_language() { - $langID = config('language'); $langFile = 'lang/'. $langID . '.ini'; @@ -80,7 +77,6 @@ function get_language() i18n('source', 'lang/en_US.ini'); // Load the English language file setlocale(LC_ALL, 'en_US.utf8'); // Change locale to English } - } // i18n provides strings in the current language @@ -95,7 +91,7 @@ function i18n($key, $value = null) else $_i18n = parse_ini_file('lang/en_US.ini', true); } elseif ($value == null) - return (isset($_i18n[$key]) ? $_i18n[$key] : '_i18n_' . $key . '_i18n_'); + return (isset($_i18n[$key]) ? $_i18n[$key] : $key); else $_i18n[$key] = $value; } @@ -128,7 +124,7 @@ function save_config($data = array(), $new = array()) $string .= "\n" . $word . ' = "' . $value . '"' . "\n"; } $string = rtrim($string); - return file_put_contents($config_file, $string); + return file_put_contents($config_file, $string, LOCK_EX); } function to_b64($str) @@ -381,7 +377,12 @@ function render($view, $locals = null, $layout = null) if (($view_root = config('views.root')) == null) error(500, "[views.root] is not set"); + $fnc = "{$view_root}/functions.php"; + ob_start(); + if (file_exists($fnc)) { + include $fnc; + } include "{$view_root}/{$view}.html.php"; content(trim(ob_get_clean())); @@ -406,7 +407,7 @@ function render($view, $locals = null, $layout = null) if (config('cache.timestamp') == 'true') { echo "\n" . ''; } - file_put_contents($cachefile, ob_get_contents()); + file_put_contents($cachefile, ob_get_contents(), LOCK_EX); } echo trim(ob_get_clean()); } else { diff --git a/system/includes/functions.php b/system/includes/functions.php index 3904a451..1b126cff 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -51,8 +51,14 @@ function get_static_subpages($static = null) if ($static != null) { $stringLen = strlen($static); return array_filter($_sub_page, function ($sub_page) use ($static, $stringLen) { - $x = explode("/", $sub_page['dirname']); - if ($x[2] == $static) { + $x = str_replace('content/static/', '', $sub_page['dirname']); + $y = explode('.', $x); + if (isset($y[1])) { + $z = $y[1]; + } else { + $z = $x; + } + if ($z == $static) { return true; } return false; @@ -125,8 +131,14 @@ function get_draft_subpages($static = null) if ($static != null) { $stringLen = strlen($static); return array_filter($_draftSubpage, function ($sub_page) use ($static, $stringLen) { - $x = explode("/", $sub_page['dirname']); - if ($x[2] == $static) { + $x = explode('/', $sub_page['dirname']); + $y = explode('.', $x[2]); + if (isset($y[1])) { + $z = $y[1]; + } else { + $z = $y[0]; + } + if ($z == $static) { return true; } return false; @@ -274,7 +286,7 @@ function rebuilt_cache($type = null) } usort($posts_cache, "sortfile_d"); $posts_string = serialize($posts_cache); - file_put_contents('cache/index/index-posts.txt', print_r($posts_string, true)); + file_put_contents('cache/index/index-posts.txt', print_r($posts_string, true), LOCK_EX); // Rebuilt scheduled posts index $stmp = array(); @@ -288,7 +300,7 @@ function rebuilt_cache($type = null) } usort($scheduled_cache, "sortfile_d"); $scheduled_string = serialize($scheduled_cache); - file_put_contents('cache/index/index-scheduled.txt', print_r($scheduled_string, true)); + file_put_contents('cache/index/index-scheduled.txt', print_r($scheduled_string, true), LOCK_EX); // Rebuilt draft posts index $drf = array(); @@ -302,7 +314,7 @@ function rebuilt_cache($type = null) } usort($draft_cache, "sortfile_d"); $draft_string = serialize($draft_cache); - file_put_contents('cache/index/index-draft.txt', print_r($draft_string, true)); + file_put_contents('cache/index/index-draft.txt', print_r($draft_string, true), LOCK_EX); // Rebuilt category files index $ftmp = array(); @@ -315,12 +327,12 @@ function rebuilt_cache($type = null) } usort($category_cache, "sortfile_a"); $category_string = serialize($category_cache); - file_put_contents('cache/index/index-category-files.txt', print_r($category_string, true)); + file_put_contents('cache/index/index-category-files.txt', print_r($category_string, true), LOCK_EX); // Rebuilt category slug index $dirc = array(); $dirc = array_unique($ctmp, SORT_REGULAR); - file_put_contents('cache/index/index-category.txt', print_r(serialize($dirc), true)); + file_put_contents('cache/index/index-category.txt', print_r(serialize($dirc), true), LOCK_EX); // Rebuilt static page index $ptmp = array(); @@ -334,7 +346,7 @@ function rebuilt_cache($type = null) } usort($page_cache, "sortfile_a"); $page_string = serialize($page_cache); - file_put_contents('cache/index/index-pages.txt', print_r($page_string, true)); + file_put_contents('cache/index/index-pages.txt', print_r($page_string, true), LOCK_EX); // Rebuilt subpage index $sptmp = array(); @@ -348,7 +360,7 @@ function rebuilt_cache($type = null) } usort($subpage_cache, "sortfile_a"); $subpage_string = serialize($subpage_cache); - file_put_contents('cache/index/index-subpages.txt', print_r($subpage_string, true)); + file_put_contents('cache/index/index-subpages.txt', print_r($subpage_string, true), LOCK_EX); // Rebuilt user profile index $atmp = array(); @@ -360,7 +372,7 @@ function rebuilt_cache($type = null) } usort($author_cache, "sortfile_a"); $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), LOCK_EX); // Remove the widget cache foreach (glob('cache/widget/*.cache', GLOB_NOSORT) as $file) { @@ -544,16 +556,23 @@ function get_pages($pages, $page = 1, $perpage = 0) $post = new stdClass; // The static page URL - $url= $v['filename']; + $fn = explode('.', $v['filename']); + + if (isset($fn[1])) { + $url = $fn[1]; + } else { + $url= $v['filename']; + } $post->url = site_url() . $url; $post->file = $v['dirname'] . '/' . $v['basename']; $post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($post->file))); - $post->md = $url; + $post->md = $v['basename']; $post->slug = $url; $post->parent = null; + $post->parentSlug = null; // Get the contents and convert it to HTML $content = file_get_contents($post->file); @@ -597,18 +616,33 @@ function get_subpages($sub_pages, $page = 1, $perpage = 0) $post = new stdClass; - $static = str_replace(dirname($v['dirname']) . '/', '', $v['dirname']); + $fd = str_replace(dirname($v['dirname']) . '/', '', $v['dirname']); + + $st = explode('.', $fd); + if (isset($st[1])) { + $static = $st[1]; + } else { + $static = $fd; + } // The static page URL - $url= $v['filename']; + $fn = explode('.', $v['filename']); + + if (isset($fn[1])) { + $url = $fn[1]; + } else { + $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; + $post->md = $v['basename']; $post->slug = $url; - $post->parent = $static; + $post->parent = $fd; + $post->parentSlug = $static; // Get the contents and convert it to HTML $content = file_get_contents($post->file); @@ -692,42 +726,9 @@ function find_page($static = null) foreach ($pages as $index => $v) { if (is_null($static)) { - $post = new stdClass; - - // The static page URL - $url= $v['filename']; - - $post->url = site_url() . $url; - $post->file = $v['dirname'] . '/' . $v['basename']; - $post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($post->file))); - - $post->md = $url; - $post->slug = $url; - $post->parent = null; - - // Get the contents and convert it to HTML - $content = file_get_contents($post->file); - - // Extract the title and body - $post->title = get_content_tag('t', $content, 'Untitled static page: ' . format_date($post->lastMod, 'l, j F Y, H:i')); + return get_pages($pages, 1, null); - // Get the contents and convert it to HTML - $post->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); - - if (config('views.counter') == 'true') { - $post->views = get_views($post->file); - } else { - $post->views = null; - } - - $post->description = get_content_tag("d", $content, get_description($post->body)); - - $word_count = str_word_count(strip_tags($post->body)); - $post->readTime = ceil($word_count / 200); - - $tmp[] = $post; - } elseif (stripos($v['basename'], $static . '.md') !== false) { // Use the get_posts method to return @@ -781,40 +782,7 @@ function find_subpage($static, $sub_static = null) if (is_null($sub_static)) { - $post = new stdClass; - - // 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; - $post->slug = $url; - $post->parent = $static; - - // Get the contents and convert it to HTML - $content = file_get_contents($post->file); - - // 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 - $post->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); - - if (config('views.counter') == 'true') { - $post->views = get_views($post->file); - } else { - $post->views = null; - } - - $post->description = get_content_tag("d", $content, get_description($post->body)); - - $word_count = str_word_count(strip_tags($post->body)); - $post->readTime = ceil($word_count / 200); - - $tmp[] = $post; + return get_subpages($sub_pages, 1, null); } elseif (stripos($v['basename'], $sub_static . '.md') !== false) { @@ -921,6 +889,8 @@ function get_category_info($category = null) } } } + } else { + $tmp[] = default_category($category); } return $tmp; } @@ -943,7 +913,7 @@ function read_category_info($category) $desc->url = site_url() . 'category/' . $url; - $desc->md = $url; + $desc->md = $v['basename']; $desc->slug = $url; @@ -975,21 +945,21 @@ function default_category($category = null) $tmp = array(); $desc = new stdClass; - if ($category == 'uncategorized') { + if (is_null($category) || $category == 'uncategorized') { $desc->title = i18n("Uncategorized"); $desc->url = site_url() . 'category/uncategorized'; $desc->slug = 'uncategorized'; $desc->body = '

' . i18n('Uncategorized_comment') . '

'; - $desc->md = 'uncategorized'; + $desc->md = 'uncategorized.md'; $desc->description = i18n('Uncategorized_comment'); $desc->file = ''; - $desc->count = get_categorycount($desc->md); - } else { + $desc->count = get_categorycount($desc->slug); + } else{ $desc->title = $category; $desc->url = site_url() . 'category/' . $category; $desc->slug = $category; $desc->body = '

' . i18n('All_blog_posts') . ': ' . $category . '

'; - $desc->md = $category; + $desc->md = $category . '.md'; $desc->description = i18n('All_blog_posts') . ': ' . $category; $desc->file = ''; $desc->count = get_categorycount($category); @@ -999,8 +969,8 @@ function default_category($category = null) } // Return category list -function category_list($custom = null) { - +function category_list($custom = null) +{ $dir = "cache/widget"; $filename = "cache/widget/category.list.cache"; $tmp = array(); @@ -1016,11 +986,11 @@ function category_list($custom = null) { } else { $arr = get_category_info(null); foreach ($arr as $i => $a) { - $cat[] = array($a->md, $a->title, $a->count, $a->description); + $cat[] = array($a->slug, $a->title, $a->count, $a->description); } $tmp = serialize($cat); - file_put_contents($filename, print_r($tmp, true)); + file_put_contents($filename, print_r($tmp, true), LOCK_EX); } if(!empty($custom)) { @@ -1275,7 +1245,6 @@ function get_keyword($keyword, $page, $perpage) // Get related posts base on post category. function get_related($tag, $custom = null, $count = null) { - if (empty($count)) { $count = config('related.count'); if (empty($count)) { @@ -1478,12 +1447,12 @@ function recent_posts($custom = null, $count = null) if (count($posts) != $count) { $posts = get_posts(null, 1, $count); $tmp = serialize($posts); - file_put_contents($filename, print_r($tmp, true)); + file_put_contents($filename, print_r($tmp, true), LOCK_EX); } } else { $posts = get_posts(null, 1, $count); $tmp = serialize($posts); - file_put_contents($filename, print_r($tmp, true)); + file_put_contents($filename, print_r($tmp, true), LOCK_EX); } if (!empty($custom)) { @@ -1525,12 +1494,12 @@ function recent_type($type, $custom = null, $count = null) if (count($posts) != $count) { $posts = get_type($type, 1, $count); $tmp = serialize($posts); - file_put_contents($filename, print_r($tmp, true)); + file_put_contents($filename, print_r($tmp, true), LOCK_EX); } } else { $posts = get_type($type, 1, $count); $tmp = serialize($posts); - file_put_contents($filename, print_r($tmp, true)); + file_put_contents($filename, print_r($tmp, true), LOCK_EX); } if (!empty($custom)) { @@ -1551,7 +1520,6 @@ function recent_type($type, $custom = null, $count = null) // Return popular posts lists function popular_posts($custom = null, $count = null) { - static $_views = array(); $tmp = array(); @@ -1595,12 +1563,12 @@ function popular_posts($custom = null, $count = null) if (count($posts) != $count) { $posts = get_posts($tmp, 1, $count); $ar = serialize($posts); - file_put_contents($filecache, print_r($ar, true)); + file_put_contents($filecache, print_r($ar, true), LOCK_EX); } } else { $posts = get_posts($tmp, 1, $count); $ar = serialize($posts); - file_put_contents($filecache, print_r($ar, true)); + file_put_contents($filecache, print_r($ar, true), LOCK_EX); } if (empty($custom)) { @@ -1640,7 +1608,6 @@ function popular_posts($custom = null, $count = null) // Return an archive list, categorized by year and month. function archive_list($custom = null) { - $dir = "cache/widget"; $filename = "cache/widget/archive.cache"; $ar = array(); @@ -1673,7 +1640,7 @@ function archive_list($custom = null) } $ar = serialize($by_year); - file_put_contents($filename, print_r($ar, true)); + file_put_contents($filename, print_r($ar, true), LOCK_EX); } else { $by_year = unserialize(file_get_contents($filename)); @@ -1747,7 +1714,6 @@ function archive_list($custom = null) // Return tag cloud. function tag_cloud($custom = null) { - $dir = "cache/widget"; $filename = "cache/widget/tags.cache"; $tg = array(); @@ -1778,7 +1744,7 @@ function tag_cloud($custom = null) $tag_collection = array_count_values($tags); ksort($tag_collection); $tg = serialize($tag_collection); - file_put_contents($filename, print_r($tg, true)); + file_put_contents($filename, print_r($tg, true), LOCK_EX); } else { $tag_collection = unserialize(file_get_contents($filename)); } @@ -1908,6 +1874,7 @@ function static_prev($prev) 'md' => $prev->md, 'slug' => $prev->slug, 'parent' => $prev->parent, + 'parentSlug' => $prev->parentSlug, 'file' => $prev->file, 'readTime' => $prev->readTime, 'lastMod' => $prev->lastMod @@ -1927,6 +1894,7 @@ function static_next($next) 'md' => $next->md, 'slug' => $next->slug, 'parent' => $next->parent, + 'parentSlug' => $next->parentSlug, 'file' => $next->file, 'readTime' => $next->readTime, 'lastMod' => $next->lastMod @@ -2078,7 +2046,6 @@ function get_description($string, $char = null) // Get the teaser function get_teaser($string, $url = null, $char = null) { - $teaserType = config('teaser.type'); $more = config('read.more'); @@ -2392,11 +2359,13 @@ function gtag(){dataLayer.push(arguments);} } } -function slashUrl($url) { +function slashUrl($url) +{ return rtrim($url, '/') . '/'; } -function parseNodes($nodes, $child = null, $class = null) { +function parseNodes($nodes, $child = null, $class = null) +{ if (empty($child)) { $ul = '
"),i=e.children()[0];return x("body").append(e),t=i.offsetWidth,e.css("overflow","scroll"),t===(i=i.offsetWidth)&&(i=e[0].clientWidth),e.remove(),s=t-i},getScrollInfo:function(t){var e=t.isWindow||t.isDocument?"":t.element.css("overflow-x"),i=t.isWindow||t.isDocument?"":t.element.css("overflow-y"),e="scroll"===e||"auto"===e&&t.widthC(E(s),E(n))?o.important="horizontal":o.important="vertical",c.using.call(this,t,o)}),l.offset(x.extend(u,{using:t}))})},x.ui.position={fit:{left:function(t,e){var i=e.within,s=i.isWindow?i.scrollLeft:i.offset.left,n=i.width,o=t.left-e.collisionPosition.marginLeft,l=s-o,a=o+e.collisionWidth-n-s;e.collisionWidth>n?0n?0",delay:300,options:{icons:{submenu:"ui-icon-caret-1-e"},items:"> *",menus:"ul",position:{my:"left top",at:"right top"},role:"menu",blur:null,focus:null,select:null},_create:function(){this.activeMenu=this.element,this.mouseHandled=!1,this.element.uniqueId().attr({role:this.options.role,tabIndex:0}),this._addClass("ui-menu","ui-widget ui-widget-content"),this._on({"mousedown .ui-menu-item":function(t){t.preventDefault()},"click .ui-menu-item":function(t){var e=x(t.target),i=x(x.ui.safeActiveElement(this.document[0]));!this.mouseHandled&&e.not(".ui-state-disabled").length&&(this.select(t),t.isPropagationStopped()||(this.mouseHandled=!0),e.has(".ui-menu").length?this.expand(t):!this.element.is(":focus")&&i.closest(".ui-menu").length&&(this.element.trigger("focus",[!0]),this.active&&1===this.active.parents(".ui-menu").length&&clearTimeout(this.timer)))},"mouseenter .ui-menu-item":function(t){var e,i;this.previousFilter||(e=x(t.target).closest(".ui-menu-item"),i=x(t.currentTarget),e[0]===i[0]&&(this._removeClass(i.siblings().children(".ui-state-active"),null,"ui-state-active"),this.focus(t,i)))},mouseleave:"collapseAll","mouseleave .ui-menu":"collapseAll",focus:function(t,e){var i=this.active||this.element.find(this.options.items).eq(0);e||this.focus(t,i)},blur:function(t){this._delay(function(){x.contains(this.element[0],x.ui.safeActiveElement(this.document[0]))||this.collapseAll(t)})},keydown:"_keydown"}),this.refresh(),this._on(this.document,{click:function(t){this._closeOnDocumentClick(t)&&this.collapseAll(t),this.mouseHandled=!1}})},_destroy:function(){var t=this.element.find(".ui-menu-item").removeAttr("role aria-disabled").children(".ui-menu-item-wrapper").removeUniqueId().removeAttr("tabIndex role aria-haspopup");this.element.removeAttr("aria-activedescendant").find(".ui-menu").addBack().removeAttr("role aria-labelledby aria-expanded aria-hidden aria-disabled tabIndex").removeUniqueId().show(),t.children().each(function(){var t=x(this);t.data("ui-menu-submenu-caret")&&t.remove()})},_keydown:function(t){var e,i,s,n=!0;switch(t.keyCode){case x.ui.keyCode.PAGE_UP:this.previousPage(t);break;case x.ui.keyCode.PAGE_DOWN:this.nextPage(t);break;case x.ui.keyCode.HOME:this._move("first","first",t);break;case x.ui.keyCode.END:this._move("last","last",t);break;case x.ui.keyCode.UP:this.previous(t);break;case x.ui.keyCode.DOWN:this.next(t);break;case x.ui.keyCode.LEFT:this.collapse(t);break;case x.ui.keyCode.RIGHT:this.active&&!this.active.is(".ui-state-disabled")&&this.expand(t);break;case x.ui.keyCode.ENTER:case x.ui.keyCode.SPACE:this._activate(t);break;case x.ui.keyCode.ESCAPE:this.collapse(t);break;default:n=!1,e=this.previousFilter||"",s=!1,i=96<=t.keyCode&&t.keyCode<=105?(t.keyCode-96).toString():String.fromCharCode(t.keyCode),clearTimeout(this.filterTimer),i===e?s=!0:i=e+i,e=this._filterMenuItems(i),(e=s&&-1!==e.index(this.active.next())?this.active.nextAll(".ui-menu-item"):e).length||(i=String.fromCharCode(t.keyCode),e=this._filterMenuItems(i)),e.length?(this.focus(t,e),this.previousFilter=i,this.filterTimer=this._delay(function(){delete this.previousFilter},1e3)):delete this.previousFilter}n&&t.preventDefault()},_activate:function(t){this.active&&!this.active.is(".ui-state-disabled")&&(this.active.children("[aria-haspopup='true']").length?this.expand(t):this.select(t))},refresh:function(){var t,e,s=this,n=this.options.icons.submenu,i=this.element.find(this.options.menus);this._toggleClass("ui-menu-icons",null,!!this.element.find(".ui-icon").length),e=i.filter(":not(.ui-menu)").hide().attr({role:this.options.role,"aria-hidden":"true","aria-expanded":"false"}).each(function(){var t=x(this),e=t.prev(),i=x("").data("ui-menu-submenu-caret",!0);s._addClass(i,"ui-menu-icon","ui-icon "+n),e.attr("aria-haspopup","true").prepend(i),t.attr("aria-labelledby",e.attr("id"))}),this._addClass(e,"ui-menu","ui-widget ui-widget-content ui-front"),(t=i.add(this.element).find(this.options.items)).not(".ui-menu-item").each(function(){var t=x(this);s._isDivider(t)&&s._addClass(t,"ui-menu-divider","ui-widget-content")}),i=(e=t.not(".ui-menu-item, .ui-menu-divider")).children().not(".ui-menu").uniqueId().attr({tabIndex:-1,role:this._itemRole()}),this._addClass(e,"ui-menu-item")._addClass(i,"ui-menu-item-wrapper"),t.filter(".ui-state-disabled").attr("aria-disabled","true"),this.active&&!x.contains(this.element[0],this.active[0])&&this.blur()},_itemRole:function(){return{menu:"menuitem",listbox:"option"}[this.options.role]},_setOption:function(t,e){var i;"icons"===t&&(i=this.element.find(".ui-menu-icon"),this._removeClass(i,null,this.options.icons.submenu)._addClass(i,null,e.submenu)),this._super(t,e)},_setOptionDisabled:function(t){this._super(t),this.element.attr("aria-disabled",String(t)),this._toggleClass(null,"ui-state-disabled",!!t)},focus:function(t,e){var i;this.blur(t,t&&"focus"===t.type),this._scrollIntoView(e),this.active=e.first(),i=this.active.children(".ui-menu-item-wrapper"),this._addClass(i,null,"ui-state-active"),this.options.role&&this.element.attr("aria-activedescendant",i.attr("id")),i=this.active.parent().closest(".ui-menu-item").children(".ui-menu-item-wrapper"),this._addClass(i,null,"ui-state-active"),t&&"keydown"===t.type?this._close():this.timer=this._delay(function(){this._close()},this.delay),(i=e.children(".ui-menu")).length&&t&&/^mouse/.test(t.type)&&this._startOpening(i),this.activeMenu=e.parent(),this._trigger("focus",t,{item:e})},_scrollIntoView:function(t){var e,i,s;this._hasScroll()&&(i=parseFloat(x.css(this.activeMenu[0],"borderTopWidth"))||0,s=parseFloat(x.css(this.activeMenu[0],"paddingTop"))||0,e=t.offset().top-this.activeMenu.offset().top-i-s,i=this.activeMenu.scrollTop(),s=this.activeMenu.height(),t=t.outerHeight(),e<0?this.activeMenu.scrollTop(i+e):s",options:{appendTo:null,autoFocus:!1,delay:300,minLength:1,position:{my:"left top",at:"left bottom",collision:"none"},source:null,change:null,close:null,focus:null,open:null,response:null,search:null,select:null},requestIndex:0,pending:0,_create:function(){var i,s,n,t=this.element[0].nodeName.toLowerCase(),e="textarea"===t,t="input"===t;this.isMultiLine=e||!t&&this._isContentEditable(this.element),this.valueMethod=this.element[e||t?"val":"text"],this.isNewMenu=!0,this._addClass("ui-autocomplete-input"),this.element.attr("autocomplete","off"),this._on(this.element,{keydown:function(t){if(this.element.prop("readOnly"))s=n=i=!0;else{s=n=i=!1;var e=x.ui.keyCode;switch(t.keyCode){case e.PAGE_UP:i=!0,this._move("previousPage",t);break;case e.PAGE_DOWN:i=!0,this._move("nextPage",t);break;case e.UP:i=!0,this._keyEvent("previous",t);break;case e.DOWN:i=!0,this._keyEvent("next",t);break;case e.ENTER:this.menu.active&&(i=!0,t.preventDefault(),this.menu.select(t));break;case e.TAB:this.menu.active&&this.menu.select(t);break;case e.ESCAPE:this.menu.element.is(":visible")&&(this.isMultiLine||this._value(this.term),this.close(t),t.preventDefault());break;default:s=!0,this._searchTimeout(t)}}},keypress:function(t){if(i)return i=!1,void(this.isMultiLine&&!this.menu.element.is(":visible")||t.preventDefault());if(!s){var e=x.ui.keyCode;switch(t.keyCode){case e.PAGE_UP:this._move("previousPage",t);break;case e.PAGE_DOWN:this._move("nextPage",t);break;case e.UP:this._keyEvent("previous",t);break;case e.DOWN:this._keyEvent("next",t)}}},input:function(t){if(n)return n=!1,void t.preventDefault();this._searchTimeout(t)},focus:function(){this.selectedItem=null,this.previous=this._value()},blur:function(t){this.cancelBlur?delete this.cancelBlur:(clearTimeout(this.searching),this.close(t),this._change(t))}}),this._initSource(),this.menu=x("