<commit_before><?php

lock();

// Comment API
define('API_COMMENT_ADD', 'comment.add');
define('API_COMMENT_REMOVE', 'comment.remove');
define('API_COMMENT_MOVE', 'comment.move');
define('API_COMMENT_CLEAR', 'comment.clear');
define('API_COMMENT_RESIZE', 'comment.resize');
define('API_COMMENT_UPDATE', 'comment.update');
define('API_COMMENT_GET', 'comment.get');

switch ($action) {
    
    case API_COMMENT_ADD:
        $screen = intval($route[4]);
        $x = intval($route[5]);
        $y = intval($route[6]);

        if ($screen < 1) { die('Please provide a screen id'); }
        $screen = $db->single("SELECT id, project FROM screen WHERE id = '" . $screen . "'");
        permission($screen['project'], 'EDIT');
        $max = $db->single("SELECT MAX(nr) as current FROM comment WHERE screen = '" . $screen['id'] . "'");
        if ($max === null) { die(); }
        $nr = $max['current'] + 1;
        $comment = array(
            'created' => date('Y-m-d H:i:s'),
            'creator' => userid(),
            'screen' => $screen['id'],
            'nr' => intval($nr),
            'x' => $x,
            'y' => $y
        );
        $id = $db->insert('comment', $comment);
        $db->query("UPDATE screen SET count_comment = count_comment + 1 WHERE id = " . $screen['id'] . "");
        $comment['creator_name'] = user('name');
        $comment['id'] = $id;

        // add to activity stream
        activity_add(
            '{actor} left a comment on screen {target}', 
            userid(), OBJECT_TYPE_USER, user('name'), 
            ACTIVITY_VERB_COMMENT, 
            $id, OBJECT_TYPE_COMMENT, "", 
            $screen['id'], OBJECT_TYPE_SCREEN, 'Title'
        );

        echo json_encode($comment);
        break;
    
    case API_COMMENT_REMOVE:
        $id = intval($route[4]);
        if ($id < 1) { die('Please provide a comment id'); }
        $comment = $db->single('SELECT screen FROM comment WHERE id = ' . $id . ' AND creator = ' . userid());
        if (!$comment) { die(); }
        $db->delete('comment', array('id' => $id));
        $db->query("UPDATE screen SET count_comment = count_comment - 1 WHERE id = " . $comment['screen'] . "");
        break;
    
    case API_COMMENT_MOVE:
        $id = intval($route[4]);
        $x = intval($route[5]);
        $y = intval($route[6]);
        if ($id < 1) { die('Please provide a comment id'); }
        $data = array(
            'modified' => date('Y-m-d H:i:s'),<commit_msg>fixed avatar image on comment.add.<commit_after><?php

lock();

// Comment API
define('API_COMMENT_ADD', 'comment.add');
define('API_COMMENT_REMOVE', 'comment.remove');
define('API_COMMENT_MOVE', 'comment.move');
define('API_COMMENT_CLEAR', 'comment.clear');
define('API_COMMENT_RESIZE', 'comment.resize');
define('API_COMMENT_UPDATE', 'comment.update');
define('API_COMMENT_GET', 'comment.get');

switch ($action) {
    
    case API_COMMENT_ADD:
        $screen = intval($route[4]);
        $x = intval($route[5]);
        $y = intval($route[6]);

        if ($screen < 1) { die('Please provide a screen id'); }
        $screen = $db->single("SELECT id, project FROM screen WHERE id = '" . $screen . "'");
        permission($screen['project'], 'EDIT');
        $max = $db->single("SELECT MAX(nr) as current FROM comment WHERE screen = '" . $screen['id'] . "'");
        if ($max === null) { die(); }
        $nr = $max['current'] + 1;
        $comment = array(
            'created' => date('Y-m-d H:i:s'),
            'creator' => userid(),
            'screen' => $screen['id'],
            'nr' => intval($nr),
            'x' => $x,
            'y' => $y
        );
        $id = $db->insert('comment', $comment);
        $db->query("UPDATE screen SET count_comment = count_comment + 1 WHERE id = " . $screen['id'] . "");
        $comment['creator_name'] = user('name');
        $comment['creator_image'] = gravatar(user('email'), null);
        $comment['id'] = $id;

        // add to activity stream
        activity_add(
            '{actor} left a comment on screen {target}', 
            userid(), OBJECT_TYPE_USER, user('name'), 
            ACTIVITY_VERB_COMMENT, 
            $id, OBJECT_TYPE_COMMENT, "", 
            $screen['id'], OBJECT_TYPE_SCREEN, 'Title'
        );

        echo json_encode($comment);
        break;
    
    case API_COMMENT_REMOVE:
        $id = intval($route[4]);
        if ($id < 1) { die('Please provide a comment id'); }
        $comment = $db->single('SELECT screen FROM comment WHERE id = ' . $id . ' AND creator = ' . userid());
        if (!$comment) { die(); }
        $db->delete('comment', array('id' => $id));
        $db->query("UPDATE screen SET count_comment = count_comment - 1 WHERE id = " . $comment['screen'] . "");
        break;
    
    case API_COMMENT_MOVE:
        $id = intval($route[4]);
        $x = intval($route[5]);
        $y = intval($route[6]);
        if ($id < 1) { die('Please provide a comment id'); }
        $data = array(
            'modified' => date('Y-m-d H:i:s'),
{'fraction_non_alphanumeric': 0.19123505976095617, 'fraction_numerical': 0.0051792828685258965, 'mean_word_length': 2.413324269204623, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6326219', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1592, 'n_words': 364}