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(); }
private function listContents($sub_path = '') { $lib = new eatStaticMediaLibrary(DATA_ROOT . '/images/', $sub_path . '/'); $page = new adminPage('images.php'); // handle image upload if (eatStatic::getValue('postback', 'post') == "1") { $image = $lib->upload('images', $sub_path, 'file', 'image'); if ($image != '') { $page->context['message'] = $image . ' uploaded'; } else { $page->context['message'] = 'file not uploaded'; } } // create new folder if (eatStatic::getValue('postback', 'post') == "2") { if (eatStatic::getValue('folder', 'post')) { $folder = $lib->createSubFolder(eatStatic::getValue('folder', 'post')); } } $page->context['contents'] = $lib->getContents(); $page->context['title'] = "Images"; $page->context['sub_path'] = $sub_path; $page->render(); }
// TODO - move this to eatStaticBlog::wpUrls(); // deal with wordpress urls e.g 2006/11/21/this-is-a-slug/ if (is_numeric($path[0]) && is_numeric($path[1]) && is_numeric($path[2])) { $slug = $path[0] . '-' . $path[1] . '-' . $path[2] . '-' . $path[3]; $path[0] = 'posts'; $path[1] = $slug; } // archive urls if (is_numeric($path[0]) && is_numeric($path[1]) && $path[2] == '') { $slug = $path[0] . '-' . $path[1]; $path[0] = 'archive'; $path[1] = $slug; } } // load user object (not a proper eatStaticUser instance) from session $user = unserialize(eatStatic::getValue('user', 'session')); $stub = ''; try { switch ($path[0]) { /** * blog URL handling */ /** * home page */ case "": require EATSTATIC_ROOT . '/eatStaticBlog.class.php'; $blog = new eatStaticBlog(); $blog->getPostFiles(); $posts = $blog->getRecentPosts(); $page_title = BLOG_TITLE . ' :: ' . BLOG_TAG_LINE;
function __construct($path) { require_once EATSTATIC_ROOT . '/eatStaticCSRF.class.php'; $csrf = new eatStaticCSRF(); switch ($path[2]) { case "": $page = new adminPage('login_form.php'); if (eatStatic::getValue('postback', 'post') == '1') { $csrf->verifyRequest(); $email = eatStatic::getValue('email', 'post'); $password = eatStatic::getValue('password', 'post'); if ($this->validUser($email, $password)) { $_SESSION['admin'] = 1; $_SESSION['admin_user'] = $email; eatStaticAdminController::redirect(""); } else { $page->context['error_message'] = 'Invalid username or password'; } } $page->context['title'] = "Log in"; $page->context['show_navbar'] = false; $page->context['body_class'] = 'login-page'; $page->context['csrf'] = $csrf; $page->render(); break; } }
function getImage() { // echo $this->image_path; // die(); if (eatStatic::getValue('debug') == '') { header('Content-type: ' . $this->content_type); } if (file_exists($this->image_path)) { // send the cached image to the output buffer (browser) readfile($this->image_path); } else { //TODO: check orientation from exif data // and rotate if necessary //http://stackoverflow.com/questions/3657023/how-to-detect-shot-angle-of-photo-and-auto-rotate-for-website-display-like-deskt // create a new image using GD functions if (!file_exists($this->source_path)) { // try looking for the same file with an uppercase extension $this->source_path = str_replace($this->extension, strtoupper($this->extension), $this->source_path); //die('source:'.$this->source_path); } if (file_exists($this->source_path)) { //die('source:'.$this->source_path); if ($this->type == 'jpg') { // the original image $src_img = ImageCreateFromJPEG($this->source_path); } if ($this->type == 'png') { $src_img = ImageCreateFromPNG($this->source_path); } //[TODO] - error handling - return placeholder image if above fails // get original image dimensions $old_x = imageSX($src_img); $old_y = imageSY($src_img); if ($old_x >= $old_y) { // landscape/square - rescale to specified width $percent_height = $old_y / $old_x * 100; $new_x = $this->width; $new_y = $this->width * $percent_height / 100; } if ($old_x < $old_y) { // portrait - calculate rescale $percent_height = $old_x / $old_y * 100; $new_y = $this->width; $new_x = $this->width * $percent_height / 100; // to suit thumbnail galleries rescale so that // height matches height of a landscape thumbnail // TODO: make this optional $new_y = $new_x; $new_x = $new_x * $percent_height / 100; } // the new image we will create with GD to the new dimensions $new_image = ImageCreateTrueColor($new_x, $new_y); // copy and re-sample the original image to make the new one ImageCopyResampled($new_image, $src_img, 0, 0, 0, 0, $new_x, $new_y, $old_x, $old_y); // send the new image to the browser if ($this->type == 'jpg') { //print 'yep, jpg'; //die(); ImageJPEG($new_image); } if ($this->type == 'png') { ImagePNG($new_image); } // check gallery directory exists in cache if (!file_exists(ROOT . '/' . $this->image_cache_folder . '/' . $this->cache_sub_folder . '/')) { // create it mkdir(ROOT . '/' . $this->image_cache_folder . '/' . $this->cache_sub_folder . '/'); } // now save a copy of the new image to the cache directory if ($this->type == 'jpg') { ImageJPEG($new_image, $this->image_path); } if ($this->type == 'png') { ImagePNG($new_image, $this->image_path); } // destroy the image in memory to free up server resources ImageDestroy($new_image); } else { //die('source image not found: '.$this->source_path); $this->sendErrorImg(); } } }