public function add_new_question() { if (isset($_POST['add_question'])) { include_once "/../models/model_test.php"; save_question($_POST['theme'], $_POST['question_title'], $_POST['answer_title'], $_POST['corect_num']); header('Location: ' . $_SESSION['base_url'] . '/home'); } header('Location: ' . $_SESSION['base_url'] . '/home'); }
</tbody> </table> </form> <?php } } } } ?> </div> <?php } else { if (isset($_POST['save'])) { $question = $_POST['question_text']; $id = $_POST['question_id']; save_question($id, $question); } else { if (isset($_POST['delete'])) { delete_question($_POST['question_id']); } else { if (isset($_POST['add']) && !empty($_POST['question'])) { add_question($_POST['question'], $_POST['category']); } else { ?> <div id="questions"> <?php $categories = get_categories(); if ($categories) { foreach ($categories as $category) { ?> <table>
<?php // only logged in users can add blog posts // gatekeeper $question_id = get_input('question_id'); $endpoint = 'http://api.stackoverflow.com/1.1/questions/' . $question_id . '?type=jsontext&body=true&answers=true&comments=true'; $response = json_decode(http_inflate(file_get_contents($endpoint))); $questions = $response->questions[0]; $question_title = $questions->title; $question_body = add_link_to_original($questions->body, $question_id); $answers = $questions->answers; $elgg_question = save_question($question_title, $question_body); foreach ($answers as $answer) { $answer_body = $answer->body; $elgg_answer = save_answer($elgg_question, $answer_body); $comments = $answer->comments; foreach ($comments as $comment) { $comment = $comment->body; save_comment($elgg_answer, $comment); } } echo json_encode(array('success' => true)); die; function add_link_to_original($body, $question_id) { $url = 'http://www.stackoverflow.com/questions/' . $question_id; $message = "<div style='border:2px solid green;'>See the original question at <a href='{$url}'>Stackoverflow</a></div>"; return "{$message}{$body}"; } function save_answer($elgg_question, $answer_body) {
} } handle_error(); default: handle_error(); } break; case 'DELETE': switch ($request[0]) { case 'questions': exit(delete_question($request[1])); case 'particlesystems': exit(delete_particlesystem($request[1])); default: handle_error(); } break; case 'POST': switch ($request[0]) { case 'particlesystems': save_particle_system(); exit(""); case 'questions': save_question(); exit(""); default: handle_error(); } default: handle_error(); }