public function edit($id) { // find article if (($article = Posts::find(array('id' => $id))) === false) { return Response::redirect($this->admin_url . '/posts'); } // process post request if (Input::method() == 'POST') { if (Posts::update($id)) { // redirect path return Response::redirect($this->admin_url . '/posts/edit/' . $id); } } // get comments $comments = Comments::list_all(array('post' => $id)); $pending = array(); foreach ($comments as $comment) { if ($comment->status == 'pending') { $pending[] = $comment->id; } } $pending = count($pending); // get posts page $page = Pages::find(array('id' => Config::get('metadata.posts_page'))); Template::render('posts/edit', array('article' => $article, 'comments' => $comments, 'page' => $page, 'pending' => $pending)); }
/** * @param int $post_id * @param string $post_type * @param string $key * * @return \WP_Post */ public static function get($post_id = 0, $post_type = 'post', $key = '') { $args = ['ignore_sticky_posts' => true]; if (defined('DOING_AJAX') && DOING_AJAX) { $args['post_type'] = array_keys(static::$_post_types); if ($post_id) { $args['p'] = $post_id; $post = current((new \WP_Query($args))->get_posts()); } else { Posts::update($key, $post_id); $post = null; } } else { if (is_null(static::$_posts)) { $args['post_type'] = array_keys(static::$_post_types); $args['posts_per_page'] = -1; $ids = array_values(static::get_ids()); if (!empty($ids)) { $args['post__in'] = $ids; $the_query = new \WP_Query($args); while ($the_query->have_posts()) { $the_query->the_post(); $_post_type = get_post_type(); if (!isset(static::$_posts[$_post_type])) { static::$_posts[$_post_type] = []; } static::$_posts[$_post_type][get_the_ID()] = get_post(); } wp_reset_postdata(); $args['post__not_in'] = $ids; unset($args['post__in']); } foreach (static::$_post_types as $_post_type => $_posts_per_page) { if (!isset(static::$_posts[$_post_type])) { static::$_posts[$_post_type] = []; } $_found_posts = count(static::$_posts[$_post_type]); if ($_found_posts < $_posts_per_page) { $args['post_type'] = $_post_type; $args['posts_per_page'] = $_posts_per_page - $_found_posts; $the_query = new \WP_Query($args); static::$_query_args[$_post_type] = ['offset' => $the_query->post_count]; static::$_posts[$_post_type]['recent'] = $the_query->get_posts(); } } } if ($post_id && isset(static::$_posts[$post_type][$post_id])) { $post = static::$_posts[$post_type][$post_id]; unset(static::$_posts[$post_type][$post_id]); } else { $post_id = key(static::$_posts[$post_type]['recent']); $post = isset(static::$_posts[$post_type]['recent'][$post_id]) ? static::$_posts[$post_type]['recent'][$post_id] : null; unset(static::$_posts[$post_type]['recent'][$post_id]); } } return $post; }
if (!isset($_POST['title']) || $_POST['title'] == "") { $alertred[] = TITLE_CANNOT_EMPTY; } if (isset($alertred)) { $data['alertred'] = $alertred; } else { if (!isset($_POST['date']) || $_POST['date'] == "") { # code... $date = date("Y-m-d H:i:s"); } else { $date = $_POST['date']; } $moddate = date("Y-m-d H:i:s"); $vars = array('title' => $title, 'content' => $content, 'modified' => $moddate, 'date' => $date, 'status' => Typo::int($_POST['status'])); //print_r($vars); Posts::update($vars); $data['alertgreen'][] = PAGE . " {$_POST['title']} " . MSG_PAGE_UPDATED; Token::remove($_POST['token']); } break; default: # code... //System::inc('posts_form', $data); break; } $id = Typo::int($_GET['id']); $data['post'] = Db::result("SELECT * FROM `posts` AS A \n LEFT JOIN `posts_param` AS B\n ON A.`id` = B.`post_id` \n WHERE A.`id` = '{$id}' "); Theme::admin('header', $data); System::inc('pages_form', $data); Theme::admin('footer'); break;