<commit_before><?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * Handler for posting new notices
 *
 * PHP version 5
 *
 * LICENCE: 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/>.
 *
 * @category  Personal
 * @package   StatusNet
 * @author    <NAME> <<EMAIL>>
 * @author    <NAME> <<EMAIL>>
 * @author    <NAME> <<EMAIL>>
 * @copyright 2008-2009 StatusNet, Inc.
 * @copyright 2013 Free Software Foundation, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

if (!defined('GNUSOCIAL')) { exit(1); }

/**
 * Action for posting new notices
 *
 * @category Personal
 * @package  StatusNet
 * @author   <NAME> <<EMAIL>>
 * @author   <NAME> <<EMAIL>>
 * @author   <NAME> <<EMAIL>>
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link     http://status.net/
 */
class NewnoticeAction extends FormAction
{
    protected $form = 'Notice';

    /**
     * Title of the page
     *
     * Note that this usually doesn't get called unless something went wrong
     *
     * @return string page title
     */
    function title()
    {
        if ($this->getInfo() && $this->stored instanceof Notice) {
            // TRANS: Page title after sending a notice.
            return _('Notice posted');
        }
        if ($this->int('inreplyto')) {
            return _m('TITLE', 'New reply');
        }
        // TRANS: Page title for sending a new notice.
        return _m('TITLE','New notice');
    }

    protected function doPreparation()
    {
        foreach(array('inreplyto') as $opt) {
            if ($this->trimmed($opt)) {
                $this->formOpts[$opt] = $this->trimmed($opt);
            }
        }

        // Backwards compatibility for "share this" widget things.
        // If no 'content', use 'status_textarea'
        $this->formOpts['content'] = $this->trimmed('content') ?: $this->trimmed('status_textarea');
    }

    /**
     * This doPost saves a new notice, based on arguments
     *
     * If successful, will show the notice, or return an Ajax-y result.
     * If not, it will show an error message -- possibly Ajax-y.
     *
     * Also, if the notice input looks like a command, it will run the
     * command and show the results -- again, possibly ajaxy.
     *
     * @return void
     */
    protected function doPost()
    {
        assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
        $user = $this->scoped->getUser();
        $content = $this->formOpts['content'];
        $options = array('source' => 'web');
        Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));

        $upload = null;
        try {
            // throws exception on failure
            $upload = MediaFile::fromUpload('attach', $this->scoped);
            if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options))) {
                $content .= ' ' . $upload->shortUrl();
            }
            Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options));<commit_msg>Don't add space if there's no string in new notice content<commit_after><?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * Handler for posting new notices
 *
 * PHP version 5
 *
 * LICENCE: 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/>.
 *
 * @category  Personal
 * @package   StatusNet
 * @author    <NAME> <<EMAIL>>
 * @author    <NAME> <<EMAIL>>
 * @author    <NAME> <<EMAIL>>
 * @copyright 2008-2009 StatusNet, Inc.
 * @copyright 2013 Free Software Foundation, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

if (!defined('GNUSOCIAL')) { exit(1); }

/**
 * Action for posting new notices
 *
 * @category Personal
 * @package  StatusNet
 * @author   <NAME> <<EMAIL>>
 * @author   <NAME> <<EMAIL>>
 * @author   <NAME> <<EMAIL>>
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link     http://status.net/
 */
class NewnoticeAction extends FormAction
{
    protected $form = 'Notice';

    /**
     * Title of the page
     *
     * Note that this usually doesn't get called unless something went wrong
     *
     * @return string page title
     */
    function title()
    {
        if ($this->getInfo() && $this->stored instanceof Notice) {
            // TRANS: Page title after sending a notice.
            return _('Notice posted');
        }
        if ($this->int('inreplyto')) {
            return _m('TITLE', 'New reply');
        }
        // TRANS: Page title for sending a new notice.
        return _m('TITLE','New notice');
    }

    protected function doPreparation()
    {
        foreach(array('inreplyto') as $opt) {
            if ($this->trimmed($opt)) {
                $this->formOpts[$opt] = $this->trimmed($opt);
            }
        }

        // Backwards compatibility for "share this" widget things.
        // If no 'content', use 'status_textarea'
        $this->formOpts['content'] = $this->trimmed('content') ?: $this->trimmed('status_textarea');
    }

    /**
     * This doPost saves a new notice, based on arguments
     *
     * If successful, will show the notice, or return an Ajax-y result.
     * If not, it will show an error message -- possibly Ajax-y.
     *
     * Also, if the notice input looks like a command, it will run the
     * command and show the results -- again, possibly ajaxy.
     *
     * @return void
     */
    protected function doPost()
    {
        assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
        $user = $this->scoped->getUser();
        $content = $this->formOpts['content'];
        $options = array('source' => 'web');
        Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));

        $upload = null;
        try {
            // throws exception on failure
            $upload = MediaFile::fromUpload('attach', $this->scoped);
            if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options))) {
                $content = ($content==='' ? '' : ' ') . $upload->shortUrl();
            }
            Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options));
{'fraction_non_alphanumeric': 0.13053582956746287, 'fraction_numerical': 0.005939315687540349, 'mean_word_length': 2.612873134328358, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '3909119', 'n_tokens_mistral': 2235, 'n_tokens_neox': 2148, 'n_words': 746}