mirror of
https://github.com/danpros/htmly.git
synced 2026-04-18 19:46:21 +05:30
File lock
This commit is contained in:
parent
54823b1003
commit
4e2b136b49
7 changed files with 57 additions and 58 deletions
|
|
@ -135,7 +135,7 @@ class Settings
|
|||
$config += $this->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 @@ class Settings
|
|||
'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(){
|
|||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -228,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);
|
||||
|
|
@ -375,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 {
|
||||
|
|
@ -393,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 {
|
||||
|
||||
|
|
@ -410,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);
|
||||
|
||||
}
|
||||
|
|
@ -449,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -522,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');
|
||||
|
|
@ -583,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');
|
||||
|
|
@ -634,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)) {
|
||||
|
|
@ -644,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)) {
|
||||
|
|
@ -655,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)) {
|
||||
|
|
@ -687,7 +687,7 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -727,10 +727,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');
|
||||
|
|
@ -765,13 +765,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -798,10 +798,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;
|
||||
|
|
@ -820,10 +820,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();
|
||||
|
|
@ -1172,10 +1172,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';
|
||||
|
|
@ -1329,7 +1329,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);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ if (file_exists($tagslang)) {
|
|||
$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();
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ if (file_exists($tagslang)) {
|
|||
$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();
|
||||
|
|
|
|||
|
|
@ -19,14 +19,13 @@ if (defined("JSON_PRETTY_PRINT")) {
|
|||
'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
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -128,7 +128,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)
|
||||
|
|
@ -411,7 +411,7 @@ function render($view, $locals = null, $layout = null)
|
|||
if (config('cache.timestamp') == 'true') {
|
||||
echo "\n" . '<!-- Cached page generated on '.date('Y-m-d H:i:s').' -->';
|
||||
}
|
||||
file_put_contents($cachefile, ob_get_contents());
|
||||
file_put_contents($cachefile, ob_get_contents(), LOCK_EX);
|
||||
}
|
||||
echo trim(ob_get_clean());
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -286,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();
|
||||
|
|
@ -300,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();
|
||||
|
|
@ -314,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();
|
||||
|
|
@ -327,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();
|
||||
|
|
@ -346,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();
|
||||
|
|
@ -360,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();
|
||||
|
|
@ -372,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) {
|
||||
|
|
@ -990,7 +990,7 @@ function category_list($custom = null)
|
|||
}
|
||||
|
||||
$tmp = serialize($cat);
|
||||
file_put_contents($filename, print_r($tmp, true));
|
||||
file_put_contents($filename, print_r($tmp, true), LOCK_EX);
|
||||
}
|
||||
|
||||
if(!empty($custom)) {
|
||||
|
|
@ -1447,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)) {
|
||||
|
|
@ -1494,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)) {
|
||||
|
|
@ -1563,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 +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));
|
||||
|
|
@ -1744,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));
|
||||
}
|
||||
|
|
@ -3213,7 +3213,7 @@ function add_view($page)
|
|||
} else {
|
||||
$views[$page] = 1;
|
||||
}
|
||||
file_put_contents($filename, json_encode($views, JSON_UNESCAPED_UNICODE));
|
||||
file_put_contents($filename, json_encode($views, JSON_UNESCAPED_UNICODE), LOCK_EX);
|
||||
}
|
||||
|
||||
// Get the page views count
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue