= 1 && $path_components[0] == 'feed') { header('Content-type: application/atom+xml;'); $template = 'atom'; } else if (count($path_components) >= 1 && $path_components[0] == 'cx') { if (count($path_components) >= 2 && $path_components[1] == 'login') { if (cx_admin_logged_in()) { cx_http_redirect(cx_url_admin('/')); exit(0); } else { $username = cx_form_input_sanitized('id'); $password = cx_form_input_sanitized('password'); if ($username != null && $password != null && cx_admin_login($username, $password)) { cx_http_redirect(cx_url_admin('/')); exit(0); } $template_class = 'admin'; $template = 'login'; } } else { if (cx_admin_logged_in() == false) { cx_http_redirect(cx_url_admin('/login/')); exit(0); } else { if (count($path_components) >= 2 && $path_components[1] == 'logout') { cx_admin_logout(); cx_http_redirect(cx_url_admin('/')); exit(0); } else if (count($path_components) >= 3 && $path_components[1] == 'posts' && $path_components[2] == 'add') { $template_variables['post_id'] = '0'; $template_variables['post_title'] = ''; $template_variables['post_slug'] = ''; $template_variables['post_date'] = ''; $template_variables['post_data'] = ''; $template_variables['post_is_draft'] = true; $template_class = 'admin'; $template = 'post'; } else if (count($path_components) >= 3 && $path_components[1] == 'posts' && $path_components[2] == 'edit') { $post = cx_posts_find_post($_GET['id']); $template_variables['post_id'] = $post->id; $template_variables['post_title'] = $post->title; $template_variables['post_slug'] = $post->slug; $template_variables['post_date'] = $post->date; $template_variables['post_data'] = $post->data; $template_variables['post_is_draft'] = $post->is_draft; $template_class = 'admin'; $template = 'post'; } else if (count($path_components) >= 3 && $path_components[1] == 'posts' && $path_components[2] == 'update') { $title = cx_form_input_sanitized('post_title'); $slug = cx_form_input_sanitized('post_slug'); if (isset($slug) == false) $slug = null; $date = cx_form_input_sanitized_date_time('post_date'); if (isset($date) == false) $date = null; $draft = cx_form_input_sanitized('post_is_draft') == 'draft'; $data = cx_form_input_sanitized_allowing_html('post_data'); if (isset($_GET['id']) == false or $_GET['id'] == 0) { cx_posts_add_post(1, $title, $slug, $date, $draft, $data); } else { $id = $_GET['id']; cx_posts_update_post($id, $title, $slug, $date, $draft, $data); } cx_http_redirect(cx_url_admin('/')); exit(0); } else if (count($path_components) >= 3 && $path_components[1] == 'posts' && $path_components[2] == 'delete') { cx_posts_delete_post($_GET['id']); cx_http_redirect(cx_url_admin('/')); exit(0); } else if (count($path_components) >= 3 && $path_components[1] == 'images' && $path_components[2] == 'add') { $template_variables['image_id'] = '0'; $template_variables['image_alt_text'] = ''; $template_class = 'admin'; $template = 'image'; } else if (count($path_components) >= 3 && $path_components[1] == 'images' && $path_components[2] == 'update') { $alt_text = cx_form_input_sanitized('image_alt_text'); $filename = $_FILES['image_file']['tmp_name']; $original_filename = $_FILES['image_file']['name']; cx_images_add_image(1, $alt_text, $filename, $original_filename); cx_http_redirect(cx_url_admin('/')); exit(0); } else { $template_class = 'admin'; $template = 'main'; } } } } else if (count($path_components) >= 3) { // FIXME sometime, needs more flexibility... $year = $path_components[0]; $month = $path_components[1]; $slug = $path_components[2]; $template = 'post'; $template_variables['post_id'] = cx_posts_find_post_id($slug); } if ($template != null) { $output = cx_template_render($template_class, $template, $template_variables); echo($output); } else { http_response_code(404); exit(0); } }