add( utils::post('texte'), utils::post('titre'), utils::post('nom'), utils::post('contact') ); utils::redirect('/ecrire/forum.php?id='.$id); } } if ($id = (int)utils::get('edit')) { $message = $forum->getPost($id); if (!$message) { throw new userException('Ce message n\'existe pas.'); } if (utils::post('save')) { if (!utils::CSRF_check('edit_'.$id)) { $msg = 'OTHER'; } elseif (!trim(utils::post('texte'))) { $msg = 'EMPTY_TEXT'; } else { $forum->editPost($id, utils::post('texte'), $message['parent'], utils::post('titre'), utils::post('nom'), utils::post('contact'), utils::post('status') ? true : false ); $id = (int)$message['parent'] ?: $id; utils::redirect('/ecrire/forum.php?id='.$id.'&msg=SAVED'); } } $tpl->assign('edit', $id); $tpl->assign('message', $message); } elseif ($id = (int)utils::get('id')) { $message = $forum->getPost($id); if (!$message) { throw new userException('Ce message n\'existe pas.'); } if (utils::post('reply')) { if (!utils::CSRF_check('reply_'.$id)) { $msg = 'OTHER'; } elseif (!trim(utils::post('texte'))) { $msg = 'EMPTY_TEXT'; } else { $new = $forum->reply($id, utils::post('texte'), utils::post('nom'), utils::post('contact') ); utils::redirect('/ecrire/forum.php?id='.$id.'#msg-'.(int)$new); } } if (utils::post('delete') && is_array(utils::post('delete'))) { if (utils::post('confirm_delete')) { if (!utils::CSRF_check('confirm_delete_thread_'.$id)) { $msg = 'OTHER'; } else { foreach (utils::post('delete') as $pid=>$confirm) { $forum->deletePost($pid); } utils::redirect('/ecrire/forum.php?id='.$id.'&msg=DELETED'); } } $tpl->assign('confirm_delete', utils::post('delete')); } $tpl->assign('view', true); $tpl->assign('message', $message); $tpl->assign('replies', $forum->getReplies($id)); } else { if (utils::post('delete') && is_array(utils::post('delete'))) { if (utils::post('confirm_delete')) { if (!utils::CSRF_check('confirm_delete_threads')) { $msg = 'OTHER'; } else { foreach (utils::post('delete') as $id=>$confirm) { $forum->deleteThread($id); } utils::redirect('/ecrire/forum.php?msg=DELETED'); } } $tpl->assign('confirm_delete', utils::post('delete')); } $page = (int) utils::get('page') ?: 1; $tpl->assign('page', $page); $tpl->assign('bypage', Forum::NB_THREADS_PER_PAGE); $tpl->assign('total', $forum->countThreads()); $tpl->assign('list', $forum->listPerPage($page)); } function tpl_forum_contact_lien($str) { $str = htmlspecialchars(trim($str), ENT_QUOTES, 'UTF-8'); if (preg_match('!^https?://!', $str)) { return ''.$str.''; } else { return ''.$str.''; } } $tpl->register_modifier('forum_contact_lien', 'tpl_forum_contact_lien'); $tpl->assign('msg', $msg ?: utils::get('msg')); $tpl->display('ecrire/forum.tpl'); ?>