public function store($folder, $object_id, $object) { if (STORAGE_TYPE == 'ES_JSON') { if (SQL_FS) { eatStaticFakeFS::store($folder, $object_id, $object); } else { $file_path = DATA_ROOT . '/' . $folder . '/' . $object_id . '.json'; if (SNAPSHOT && file_exists($file_path)) { // check for snapshot sub directory if (!is_dir(DATA_ROOT . '/' . $folder . '/snapshots/')) { mkdir(DATA_ROOT . '/' . $folder . '/snapshots/'); } // check for snapshot directory named as per file $snapshot_folder = DATA_ROOT . '/' . $folder . '/snapshots/' . $object_id; if (!is_dir($snapshot_folder)) { mkdir($snapshot_folder, 0775); } $snapshot_path = $snapshot_folder . '/' . date("Y-m-d-His") . '.json'; // take a copy of the existing file copy($file_path, $snapshot_path); } // write file out to filesystem if (eatStatic::write_file(json_encode($object), $file_path)) { return true; } } } }
public function getPostFiles($use_cache = USE_CACHE) { // reset post files array $this->post_files = array(); if ($use_cache) { // see if cache file exists if (file_exists(CACHE_ROOT . '/all_posts.json')) { $this->post_files = json_decode(eatStatic::read_file(CACHE_ROOT . '/all_posts.json')); } else { // load posts from disk $this->getPostFilesFromDisk(); // write array of post files to disk as JSON eatStatic::write_file(json_encode($this->post_files), CACHE_ROOT . '/all_posts.json'); } } else { $this->getPostFilesFromDisk(); } }
<?php require '../eatStatic_config.php'; // check data folder exists if (file_exists(DATA_ROOT)) { echo 'Data folder exists at: ' . DATA_ROOT . '<br />'; } else { echo 'Data folder does not exist at: ' . DATA_ROOT . '<br />'; } // check data folder is writable if (eatStatic::write_file('setup test (written by /scripts/setup.php)', DATA_ROOT . '/.setup-test.txt')) { echo 'Data folder is writeable <br />'; } else { echo 'Data folder is not writeable <br />'; } if (unlink(DATA_ROOT . '/.setup-test.txt')) { echo 'Data folder content can be deleted <br />'; } // check cache folder exists if (file_exists(DATA_ROOT . '/cache')) { echo 'Cache folder exists <br />'; } else { echo 'Cache folder does not exist - creating.. <br />'; if (mkdir(DATA_ROOT . '/cache', 0775)) { echo 'Cache folder created <br />'; } } // check cache/tags folder exists if (file_exists(DATA_ROOT . '/cache/tags')) { echo 'Tag cache folder exists <br />'; } else {
private function editRawPost($slug, $draft = false) { $post_folder = DATA_ROOT . '/posts/'; if ($draft) { $post_folder = $post_folder . 'draft/'; } //die($post_folder); $page = new adminPage('post_raw_edit.php'); $post = new eatStaticBlogPost(); if (file_exists($post_folder . $slug . '.txt')) { $post->data_file_path = $post_folder . $slug . '.txt'; } if (file_exists($post_folder . $slug . '.md')) { $post->data_file_path = $post_folder . $slug . '.md'; } if (file_exists($post->data_file_path)) { $page->context['title'] = "Edit Post"; $post->hydrate(); } else { $page->context['title'] = "New Post"; } if (eatStatic::getValue('postback') == '1') { //die($slug); $post->raw_data = trim(eatStatic::getValue('raw_data', 'post')); $post->file_name = trim(eatStatic::getValue('file_name', 'post')); $post->original_file_name = trim(eatStatic::getValue('original_file_name', 'post')); //die($slug); // copy current file data to backups if ($slug != 'new') { copy($post->data_file_path, DATA_ROOT . '/posts/backup/' . $post->file_name . '.' . eatStatic::timestamp() . '.bak'); if ($post->original_file_name != $post->file_name) { //die($post->data_file_path); // remove original unlink($post->data_file_path); $new_data_file_path = $post_folder . $post->file_name; eatStatic::write_file($post->raw_data, $new_data_file_path); } else { eatStatic::write_file($post->raw_data, $post->data_file_path); } } else { $post->data_file_path = $post_folder . $post->file_name; eatStatic::write_file($post->raw_data, $post->data_file_path); header('location:' . ADMIN_ROOT . 'posts/drafts/'); die; } } $page->context['post'] = $post; //print_r($page); //die(); $page->render(); }
public function save() { $json_file = CACHE_ROOT . '/tags/' . $this->fileNameFromName(); if (file_exists($json_file)) { // TODO make backup - timestamp + username in filename } eatStatic::write_file(json_encode($this), $json_file); }