예제 #1
0
파일: comment.php 프로젝트: neovictor/test
//form of comment
if (!empty($_POST['rating'])) {
    if (!empty($_POST['commenttext'])) {
        include "addtocomment.php";
        $id_articles = $_POST['id_articles'];
        $text_comment = clearData($_POST['commenttext']);
        if (empty($_POST['commenttitle'])) {
            $title_comment = substr($text_comment, 0, 15);
        } else {
            $title_comment = clearData($_POST['commenttitle']);
        }
        $profile = getProfile($_SESSION['name']);
        $id_user_of_comment = $profile[0]['id'];
        $date_of_public = time();
        $user_rating = $_POST['case'];
        setComment($id_articles, $title_comment, $text_comment, $id_user_of_comment, $date_of_public);
    } else {
        echo "<div>" . $lang['comment field is not filled'] . "</div>";
    }
}
//comment
if (isset($_GET['id'])) {
    $articles = getComment($_GET['id']);
    if (!empty($articles)) {
        foreach ($articles as $article) {
            echo "<hr><div><a href='index.php?profile=" . getName($article['id_user_of_comment']) . "'>" . getName($article['id_user_of_comment']) . "</a></div>";
            if (!empty($_SESSION['status']) and $_SESSION['status'] == '3') {
                echo "<div align='right'><a href='comment.php?comment&del=" . $article['id'] . "'>" . $lang['delete'] . "</a></div>";
            }
            echo "<div><b>" . $article['title_comment'] . "</b></div>";
            echo "<div>" . $article['text_comment'] . "</div>";
function setTranslatorComment(&$strings, $text, $hint)
{
    addString($strings, $text);
    $hint = trim($hint);
    if (!$hint) {
        return;
    }
    setComment($strings, $text, '', $hint);
}
/**
 * createComment that uses setComment to insert into database.
 * @author Oliver Rosander
 * @param PDO $dbh, string|null $lbl Post index default "comment"
 * @return int Id of last inserted row -1 if fail
 */
function createComment($dbh, $lbl = null)
{
    // Check for label to retrieve data from session
    if ($lbl == null && isset($_POST["comment"])) {
        $comment = $_POST["comment"];
    } elseif (isset($_POST[$lbl])) {
        $comment = $_POST[$lbl];
    } else {
        return -1;
    }
    // Check data
    if ($comment != null && strlen($comment) < 256) {
        $comment = strip_tags($comment);
        $subcomments = serialize(array());
        $ret = setComment(0, $comment, $subcomments, $dbh);
        //TODO MISSING USER AND SUBCOMMENT
        if ($ret != -1) {
            return $ret;
        } else {
            return -1;
        }
    } else {
        return -1;
    }
}