<commit_before><?php
/**
 * Tatoeba Project, free collaborative creation of multilingual corpuses project
 * Copyright (C) 2009-2010  <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 to display buttons in sentences menu.
 *
 * @category Sentences
 * @package  Helpers
 * @author   <NAME> <<EMAIL>>
 * @license  Affero General Public License
 * @link     http://tatoeba.org
 */
class MenuHelper extends AppHelper
{

    public $helpers = array(
        'Html',
        'Javascript',
        'Form',
        'Session',
        'Images'
    );


    /**
     * Display button to add a translation.
     *
     * @param int    $sentenceId Id of the original sentence.
     * @param bool   $isLogged   True if user is logged in, false otherwise.
     * @param bool   $enabled    True if sentence can be translated .Only sentences
     *                           that are not "unapproved" can be translated.
     *
     * @return void
     */
    public function translateButton($sentenceId, $isLogged, $enabled)
    {
        $translateButton = $this->Images->svgIcon(
            'translate',
            array(
                'width' => 16,
                'height' => 16
            )
        );

        echo $this->Html->tag('li', null, array(
            'class' => 'option translateLink',
            'data-sentence-id' => $sentenceId,
            'title' => __('Translate', true)
        ));

        if (!$enabled) {

            echo '<a class="disabled">';
            echo $this->Images->svgIcon(
                'translate',
                array(
                    'alt'=>__('Translate', true),
                    'title'=>__(
                        'This sentence is currently marked as unapproved. '.
                        'Unapproved sentences cannot be translated.',
                        true
                    ),
                    'width' => 16,
                    'height' => 16
                )
            );
            echo '</a>';

        } else if ($isLogged) {
            $this->Javascript->link('sentences.add_translation.js', false);
            ?>
            <a><?php echo $translateButton;?></a>
           <?php
        } else {
            echo $this->Html->link(
                $translateButton,
                array(
                    "controller" => "users",
                    "action" => "login",
                    "?" => array("redirectTo" => Router::reverse($this->params)),
                ),
                array(
                    "escape" => false
                ),
                null
            );
        }

        echo $this->Html->tag('/li');
    }


    /**
     * Display button to notify the chinese sentence is in
     * simplified script
     *
     * @return void
     */
    public function simplifiedButton()
    {
        ?>
        <li class="option simplified">
        <?php
        echo $this->Html->image(
            IMG_PATH . 'simplified_chinese.png',
            array(
                'alt'=>__('This sentence is in simplified Chinese.', true),
                'title'=>__('This sentence is in simplified Chinese.', true),
                'width' => 18,
                'height' => 16
            )
        );
        ?>
        </li>
    <?php
    }

    /**
     * Display button to indicate that the Chinese sentence is in
     * traditional script
     *
     * @return void
     */
    public function traditionalButton()
    {
        ?>
        <li class="option traditional">
        <?php
        echo $this->Html->image(
            IMG_PATH . 'traditional_chinese.png',
            array(
                'alt'=>__('This sentence is in traditional Chinese.', true),
                'title'=>__('This sentence is in traditional Chinese.', true),
                'width' => 18,
                'height' => 16
            )
        );
        ?>
        </li>
    <?php
    }



    /**
     * Display button to adopt a sentence.
     *
     * @param int    $sentenceId Id of the sentence on which this button
     *                           is displayed
     * @param string $ownerName  Indicates whether the sentence is adopted by current
     *                           user or not.
     * @param bool   $isNative   'true' if the owner is a native speaker in the
     *                           language of the sentence.
     *
     * @return void
     */
    public function adoptButton($sentenceId, $owner)
    {
        $ownerName = $owner['username'];
        $isNative = isset($owner['is_native']) ? $owner['is_native'] : false;
        $isAdopted = !empty($ownerName);
        $userAccountDeactivated = isset($owner['group_id']) ?
            $owner['group_id'] > 4 : false;
        $isAdoptable = !$isAdopted || $userAccountDeactivated;
        $currentUserName = CurrentUser::get('username');
        $isOwnedByCurrentUser = $isAdopted && $ownerName == $currentUserName;

        $tooltip = null;<commit_msg>#744 Restrict adoption for advanced contributors and higher.<commit_after><?php
/**
 * Tatoeba Project, free collaborative creation of multilingual corpuses project
 * Copyright (C) 2009-2010  <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 to display buttons in sentences menu.
 *
 * @category Sentences
 * @package  Helpers
 * @author   <NAME> <<EMAIL>>
 * @license  Affero General Public License
 * @link     http://tatoeba.org
 */
class MenuHelper extends AppHelper
{

    public $helpers = array(
        'Html',
        'Javascript',
        'Form',
        'Session',
        'Images'
    );


    /**
     * Display button to add a translation.
     *
     * @param int    $sentenceId Id of the original sentence.
     * @param bool   $isLogged   True if user is logged in, false otherwise.
     * @param bool   $enabled    True if sentence can be translated .Only sentences
     *                           that are not "unapproved" can be translated.
     *
     * @return void
     */
    public function translateButton($sentenceId, $isLogged, $enabled)
    {
        $translateButton = $this->Images->svgIcon(
            'translate',
            array(
                'width' => 16,
                'height' => 16
            )
        );

        echo $this->Html->tag('li', null, array(
            'class' => 'option translateLink',
            'data-sentence-id' => $sentenceId,
            'title' => __('Translate', true)
        ));

        if (!$enabled) {

            echo '<a class="disabled">';
            echo $this->Images->svgIcon(
                'translate',
                array(
                    'alt'=>__('Translate', true),
                    'title'=>__(
                        'This sentence is currently marked as unapproved. '.
                        'Unapproved sentences cannot be translated.',
                        true
                    ),
                    'width' => 16,
                    'height' => 16
                )
            );
            echo '</a>';

        } else if ($isLogged) {
            $this->Javascript->link('sentences.add_translation.js', false);
            ?>
            <a><?php echo $translateButton;?></a>
           <?php
        } else {
            echo $this->Html->link(
                $translateButton,
                array(
                    "controller" => "users",
                    "action" => "login",
                    "?" => array("redirectTo" => Router::reverse($this->params)),
                ),
                array(
                    "escape" => false
                ),
                null
            );
        }

        echo $this->Html->tag('/li');
    }


    /**
     * Display button to notify the chinese sentence is in
     * simplified script
     *
     * @return void
     */
    public function simplifiedButton()
    {
        ?>
        <li class="option simplified">
        <?php
        echo $this->Html->image(
            IMG_PATH . 'simplified_chinese.png',
            array(
                'alt'=>__('This sentence is in simplified Chinese.', true),
                'title'=>__('This sentence is in simplified Chinese.', true),
                'width' => 18,
                'height' => 16
            )
        );
        ?>
        </li>
    <?php
    }

    /**
     * Display button to indicate that the Chinese sentence is in
     * traditional script
     *
     * @return void
     */
    public function traditionalButton()
    {
        ?>
        <li class="option traditional">
        <?php
        echo $this->Html->image(
            IMG_PATH . 'traditional_chinese.png',
            array(
                'alt'=>__('This sentence is in traditional Chinese.', true),
                'title'=>__('This sentence is in traditional Chinese.', true),
                'width' => 18,
                'height' => 16
            )
        );
        ?>
        </li>
    <?php
    }



    /**
     * Display button to adopt a sentence.
     *
     * @param int    $sentenceId Id of the sentence on which this button
     *                           is displayed
     * @param string $ownerName  Indicates whether the sentence is adopted by current
     *                           user or not.
     * @param bool   $isNative   'true' if the owner is a native speaker in the
     *                           language of the sentence.
     *
     * @return void
     */
    public function adoptButton($sentenceId, $owner)
    {
        $ownerName = $owner['username'];
        $isNative = isset($owner['is_native']) ? $owner['is_native'] : false;
        $isAdopted = !empty($ownerName);
        $userAccountDeactivated = isset($owner['group_id']) ?
            $owner['group_id'] > 4 : false;
        $currentUserIsAdvanced = in_array(CurrentUser::get('group_id'), range(1, 3));
        $isAdoptable = !$isAdopted || ($userAccountDeactivated
                && $currentUserIsAdvanced);
        $currentUserName = CurrentUser::get('username');
        $isOwnedByCurrentUser = $isAdopted && $ownerName == $currentUserName;

        $tooltip = null;
{'fraction_non_alphanumeric': 0.11475550226941851, 'fraction_numerical': 0.005052667637235591, 'mean_word_length': 1.6113595706618962, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 131, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6928562', 'n_tokens_mistral': 3161, 'n_tokens_neox': 2963, 'n_words': 943}