<commit_before><?php
/**
 * Tatoeba Project, free collaborative creation of multilingual corpuses project
 * Copyright (C) 2009  <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * PHP version 5
 *
 * @category PHP
 * @package  Tatoeba
 * @author   <NAME> <<EMAIL>>
 * @license  Affero General Public License
 * @link     http://tatoeba.org
 */

/**
 * Helper for contributions.
 *
 * @category SentenceComments
 * @package  Helpers
 * @author   <NAME> <<EMAIL>>
 * @license  Affero General Public License
 * @link     http://tatoeba.org
 */
class CommentsHelper extends AppHelper
{

    public $helpers = array('Form', 'Html', 'Sentences', 'Messages');


    /**
     * Display form to post a comment.
     *
     * @param int $sentenceId   Id of the sentence.
     * @param int $sentenceText Text of the sentence.
     *
     * @return void
     */
    public function displayCommentForm($sentenceId, $sentenceText)
    {
        echo $this->Form->create(
            'SentenceComment',
            array(
                "url" => array("action" => "save"),
                "class" => "message form"
            )
        );

        echo $this->Form->hidden('sentence_id', array("value"=>$sentenceId));

        // Text of the sentence is used for notification email, to avoid doing
        // another query.
        echo $this->Form->hidden('sentence_text', array("value"=>$sentenceText));
        ?>

        <div class="header">
            <div class="info">
            <?php
            $user = CurrentUser::get('User');
            $this->Messages->displayAvatar($user['User']);
            ?>
            </div>
            <div class="title">
            <?php echo __('Add a comment'); ?>
            </div>
        </div>

        <div class="body">
            <div class="textarea">
            <?php
            echo $this->Form->textarea(
                'text',
                array(
                    "label"=> "",
                    "lang" => "",
                    "dir" => "auto",
                )
            );
            ?>
            </div>

            <div layout="row" layout-align="end center" layout-padding>
                <md-button type="submit" class="md-raised md-primary">
                    <?php echo __('Submit comment'); ?>
                </md-button>
            </div>
        </div>
        <?php
        echo $this->Form->end();
        ?>


        <h3><?php echo __('Good practices'); ?></h3>
        <ul>
            <li>
            <?php
            echo __(
                'Say "welcome" to new users.'
            );
            ?>
            </li>

            <li>
            <?php
            echo __(
                'Use private messages to discuss things unrelated to the sentence.'
            );
            ?>
            </li>
        </ul>
        <?php
    }


    /**
     * Display sentence (for edit sentence_comment view)
     *
     * @param $sentence       Sentence to display.
     *
     * @return void
     */
    public function displaySentence($sentence)
    {
        $sentence['Translation'] = array();
        $this->Sentences->displaySimpleSentencesGroup($sentence);
    }


    /**
     *
     *
     *
     */
    public function displayCommentEditForm($message, $author) {
        $created = $message['created'];
        $modified = null;
        if (isset($message['modified'])) {
            $modified = $message['modified'];
        }

        $content = $message['text'];
        $authorId = $author['id'];

        // Hack. This was the only way I knew to get the proper
        // action value for this form
        // The form in users/edit also has the same problem
        echo $this->Form->create(
            false,
            array(
                "url" => array(
                    "controller" => "sentence_comments",
                    "action" => "edit",
                    $message['id']
                ),
                "class" => "message form"
            )
        );

        echo $this->Form->hidden('SentenceComment.id');
        echo $this->Form->hidden('SentenceComment.sentence_id');

        $this->Messages->displayHeader($author, $created, $modified, null);
        ?>

        <div class="body">
            <div class="textarea">
            <?php
            echo $this->Form->textarea('SentenceComment.text');
            ?>
            </div>

            <?php
            $cancelUrl = $this->Html->url(
                array(
                    "controller" => "sentences",
                    "action" => "show",
                    $message['sentence_id']."#comment-".$message['id']
                )
            );
            ?>
            <div layout="row" layout-align="end center" layout-padding>
                <md-button class="md-raised" href="<?= $cancelUrl; ?>">
                    <?php echo __('Cancel'); ?>
                </md-button>
<commit_msg>Fix sentence comment cancel link (#1573)<commit_after><?php
/**
 * Tatoeba Project, free collaborative creation of multilingual corpuses project
 * Copyright (C) 2009  <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * PHP version 5
 *
 * @category PHP
 * @package  Tatoeba
 * @author   <NAME> <<EMAIL>>
 * @license  Affero General Public License
 * @link     http://tatoeba.org
 */

/**
 * Helper for contributions.
 *
 * @category SentenceComments
 * @package  Helpers
 * @author   <NAME> <<EMAIL>>
 * @license  Affero General Public License
 * @link     http://tatoeba.org
 */
class CommentsHelper extends AppHelper
{

    public $helpers = array('Form', 'Html', 'Sentences', 'Messages');


    /**
     * Display form to post a comment.
     *
     * @param int $sentenceId   Id of the sentence.
     * @param int $sentenceText Text of the sentence.
     *
     * @return void
     */
    public function displayCommentForm($sentenceId, $sentenceText)
    {
        echo $this->Form->create(
            'SentenceComment',
            array(
                "url" => array("action" => "save"),
                "class" => "message form"
            )
        );

        echo $this->Form->hidden('sentence_id', array("value"=>$sentenceId));

        // Text of the sentence is used for notification email, to avoid doing
        // another query.
        echo $this->Form->hidden('sentence_text', array("value"=>$sentenceText));
        ?>

        <div class="header">
            <div class="info">
            <?php
            $user = CurrentUser::get('User');
            $this->Messages->displayAvatar($user['User']);
            ?>
            </div>
            <div class="title">
            <?php echo __('Add a comment'); ?>
            </div>
        </div>

        <div class="body">
            <div class="textarea">
            <?php
            echo $this->Form->textarea(
                'text',
                array(
                    "label"=> "",
                    "lang" => "",
                    "dir" => "auto",
                )
            );
            ?>
            </div>

            <div layout="row" layout-align="end center" layout-padding>
                <md-button type="submit" class="md-raised md-primary">
                    <?php echo __('Submit comment'); ?>
                </md-button>
            </div>
        </div>
        <?php
        echo $this->Form->end();
        ?>


        <h3><?php echo __('Good practices'); ?></h3>
        <ul>
            <li>
            <?php
            echo __(
                'Say "welcome" to new users.'
            );
            ?>
            </li>

            <li>
            <?php
            echo __(
                'Use private messages to discuss things unrelated to the sentence.'
            );
            ?>
            </li>
        </ul>
        <?php
    }


    /**
     * Display sentence (for edit sentence_comment view)
     *
     * @param $sentence       Sentence to display.
     *
     * @return void
     */
    public function displaySentence($sentence)
    {
        $sentence['Translation'] = array();
        $this->Sentences->displaySimpleSentencesGroup($sentence);
    }


    /**
     *
     *
     *
     */
    public function displayCommentEditForm($message, $author) {
        $created = $message['created'];
        $modified = null;
        if (isset($message['modified'])) {
            $modified = $message['modified'];
        }

        $content = $message['text'];
        $authorId = $author['id'];

        // Hack. This was the only way I knew to get the proper
        // action value for this form
        // The form in users/edit also has the same problem
        echo $this->Form->create(
            false,
            array(
                "url" => array(
                    "controller" => "sentence_comments",
                    "action" => "edit",
                    $message['id']
                ),
                "class" => "message form"
            )
        );

        echo $this->Form->hidden('SentenceComment.id');
        echo $this->Form->hidden('SentenceComment.sentence_id');

        $this->Messages->displayHeader($author, $created, $modified, null);
        ?>

        <div class="body">
            <div class="textarea">
            <?php
            echo $this->Form->textarea('SentenceComment.text');
            ?>
            </div>

            <?php
            $cancelUrl = $this->Html->url(
                array(
                    "controller" => "sentences",
                    "action" => "show",
                    $message['sentence_id'],
                    "#" => "comment-".$message['id'],
                )
            );
            ?>
            <div layout="row" layout-align="end center" layout-padding>
                <md-button class="md-raised" href="<?= $cancelUrl; ?>">
                    <?php echo __('Cancel'); ?>
                </md-button>

{'fraction_non_alphanumeric': 0.1341343136375863, 'fraction_numerical': 0.0017932394871335068, 'mean_word_length': 1.5688622754491017, 'pattern_counts': {'":': 0, '<': 107, '<?xml version=': 0, '>': 188, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7466933', 'n_tokens_mistral': 3019, 'n_tokens_neox': 2850, 'n_words': 830}