<commit_before><?php
/**
 * @file mod/events.php
 * @brief The events module
 */

use Friendica\App;
use Friendica\Content\Nav;
use Friendica\Content\Widget\CalendarExport;
use Friendica\Core\ACL;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Model\Event;
use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal;
use Friendica\Module\Login;

require_once 'include/items.php';

function events_init(App $a)
{
	if (!local_user()) {
		return;
	}

	// If it's a json request abort here because we don't
	// need the widget data
	if ($a->argc > 1 && $a->argv[1] === 'json') {
		return;
	}

	if (empty($a->page['aside'])) {
		$a->page['aside'] = '';
	}

	$cal_widget = CalendarExport::getHTML();

	$a->page['aside'] .= $cal_widget;

	return;
}

function events_post(App $a)
{

	logger('post: ' . print_r($_REQUEST, true), LOGGER_DATA);

	if (!local_user()) {
		return;
	}

	$event_id = !empty($_POST['event_id']) ? intval($_POST['event_id']) : 0;
	$cid = !empty($_POST['cid']) ? intval($_POST['cid']) : 0;
	$uid = local_user();

	$start_text  = escape_tags(defaults($_REQUEST, 'start_text', ''));
	$finish_text = escape_tags(defaults($_REQUEST, 'finish_text', ''));

	$adjust   = intval(defaults($_POST, 'adjust', 0));
	$nofinish = intval(defaults($_POST, 'nofinish', 0));

	// The default setting for the `private` field in event_store() is false, so mirror that
	$private_event = false;

	$start  = NULL_DATE;
	$finish = NULL_DATE;

	if ($start_text) {
		$start = $start_text;
	}

	if ($finish_text) {
		$finish = $finish_text;
	}

	if ($adjust) {
		$start = DateTimeFormat::convert($start, 'UTC', date_default_timezone_get());
		if (!$nofinish) {
			$finish = DateTimeFormat::convert($finish, 'UTC', date_default_timezone_get());
		}
	} else {
		$start = DateTimeFormat::utc($start);
		if (!$nofinish) {
			$finish = DateTimeFormat::utc($finish);
		}
	}

	// Don't allow the event to finish before it begins.
	// It won't hurt anything, but somebody will file a bug report
	// and we'll waste a bunch of time responding to it. Time that
	// could've been spent doing something else.

	$summary  = escape_tags(trim(defaults($_POST, 'summary', '')));
	$desc     = escape_tags(trim(defaults($_POST, 'desc', '')));
	$location = escape_tags(trim(defaults($_POST, 'location', '')));
	$type     = 'event';

	$action = ($event_id == '') ? 'new' : "event/" . $event_id;
	$onerror_url = "events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish";

	if (strcmp($finish, $start) < 0 && !$nofinish) {
		notice(L10n::t('Event can not end before it has started.') . EOL);
		if (intval($_REQUEST['preview'])) {
			echo L10n::t('Event can not end before it has started.');
			killme();
		}
		$a->internalRedirect($onerror_url);
	}

	if (!$summary || ($start === NULL_DATE)) {
		notice(L10n::t('Event title and start time are required.') . EOL);
		if (intval($_REQUEST['preview'])) {
			echo L10n::t('Event title and start time are required.');
			killme();
		}
		$a->internalRedirect($onerror_url);
	}

	$share = intval(defaults($_POST, 'share', 0));
<commit_msg>replaced onerror_url with onerror_path<commit_after><?php
/**
 * @file mod/events.php
 * @brief The events module
 */

use Friendica\App;
use Friendica\Content\Nav;
use Friendica\Content\Widget\CalendarExport;
use Friendica\Core\ACL;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Model\Event;
use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal;
use Friendica\Module\Login;

require_once 'include/items.php';

function events_init(App $a)
{
	if (!local_user()) {
		return;
	}

	// If it's a json request abort here because we don't
	// need the widget data
	if ($a->argc > 1 && $a->argv[1] === 'json') {
		return;
	}

	if (empty($a->page['aside'])) {
		$a->page['aside'] = '';
	}

	$cal_widget = CalendarExport::getHTML();

	$a->page['aside'] .= $cal_widget;

	return;
}

function events_post(App $a)
{

	logger('post: ' . print_r($_REQUEST, true), LOGGER_DATA);

	if (!local_user()) {
		return;
	}

	$event_id = !empty($_POST['event_id']) ? intval($_POST['event_id']) : 0;
	$cid = !empty($_POST['cid']) ? intval($_POST['cid']) : 0;
	$uid = local_user();

	$start_text  = escape_tags(defaults($_REQUEST, 'start_text', ''));
	$finish_text = escape_tags(defaults($_REQUEST, 'finish_text', ''));

	$adjust   = intval(defaults($_POST, 'adjust', 0));
	$nofinish = intval(defaults($_POST, 'nofinish', 0));

	// The default setting for the `private` field in event_store() is false, so mirror that
	$private_event = false;

	$start  = NULL_DATE;
	$finish = NULL_DATE;

	if ($start_text) {
		$start = $start_text;
	}

	if ($finish_text) {
		$finish = $finish_text;
	}

	if ($adjust) {
		$start = DateTimeFormat::convert($start, 'UTC', date_default_timezone_get());
		if (!$nofinish) {
			$finish = DateTimeFormat::convert($finish, 'UTC', date_default_timezone_get());
		}
	} else {
		$start = DateTimeFormat::utc($start);
		if (!$nofinish) {
			$finish = DateTimeFormat::utc($finish);
		}
	}

	// Don't allow the event to finish before it begins.
	// It won't hurt anything, but somebody will file a bug report
	// and we'll waste a bunch of time responding to it. Time that
	// could've been spent doing something else.

	$summary  = escape_tags(trim(defaults($_POST, 'summary', '')));
	$desc     = escape_tags(trim(defaults($_POST, 'desc', '')));
	$location = escape_tags(trim(defaults($_POST, 'location', '')));
	$type     = 'event';

	$action = ($event_id == '') ? 'new' : "event/" . $event_id;
	$onerror_path = "events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish";

	if (strcmp($finish, $start) < 0 && !$nofinish) {
		notice(L10n::t('Event can not end before it has started.') . EOL);
		if (intval($_REQUEST['preview'])) {
			echo L10n::t('Event can not end before it has started.');
			killme();
		}
		$a->internalRedirect($onerror_path);
	}

	if (!$summary || ($start === NULL_DATE)) {
		notice(L10n::t('Event title and start time are required.') . EOL);
		if (intval($_REQUEST['preview'])) {
			echo L10n::t('Event title and start time are required.');
			killme();
		}
		$a->internalRedirect($onerror_path);
	}

	$share = intval(defaults($_POST, 'share', 0));

{'fraction_non_alphanumeric': 0.18381010346926355, 'fraction_numerical': 0.005477784540474742, 'mean_word_length': 4.666379310344827, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '1623746', 'n_tokens_mistral': 2444, 'n_tokens_neox': 2314, 'n_words': 533}