<commit_before><?php
/**
 * @file mod/videos.php
 */

use Friendica\App;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Protocol\DFRN;
use Friendica\Util\Security;

function videos_init(App $a)
{
	if ($a->argc > 1) {
		DFRN::autoRedir($a, $a->argv[1]);
	}

	if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
		return;
	}

	Nav::setSelected('home');

	$o = '';

	if ($a->argc > 1) {
		$nick = $a->argv[1];
		$user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
			DBA::escape($nick)
		);

		if (!DBA::isResult($user)) {
			return;
		}

		$a->data['user'] = $user[0];
		$a->profile_uid = $user[0]['uid'];

		$profile = Profile::getByNickname($nick, $a->profile_uid);

		$account_type = Contact::getAccountType($profile);

		$tpl = Renderer::getMarkupTemplate("vcard-widget.tpl");

		$vcard_widget = Renderer::replaceMacros($tpl, [
			'$name' => $profile['name'],
			'$photo' => $profile['photo'],
			'$addr' => defaults($profile, 'addr', ''),
			'$account_type' => $account_type,
			'$pdesc' => defaults($profile, 'pdesc', ''),
		]);

		/// @TODO Old-lost code?
		/*$sql_extra = Security::getPermissionsSQLByUserId($a->data['user']['uid']);

		$albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
			intval($a->data['user']['uid'])
		);

		if(count($albums)) {
			$a->data['albums'] = $albums;

			$albums_visible = ((intval($a->data['user']['hidewall']) && (!local_user()) && (!remote_user())) ? false : true);

			if($albums_visible) {
				$o .= '<div id="sidebar-photos-albums" class="widget">';
				$o .= '<h3>' . '<a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '">' . L10n::t('Photo Albums') . '</a></h3>';

				$o .= '<ul>';
				foreach($albums as $album) {

					// don't show contact photos. We once translated this name, but then you could still access it under
					// a different language setting. Now we store the name in English and check in English (and translated for legacy albums).

					if((!strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos')))
						continue;
					$o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
				}
				$o .= '</ul>';
			}
			if(local_user() && $a->data['user']['uid'] == local_user()) {
				$o .= '<div id="photo-albums-upload-link"><a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .L10n::t('Upload New Photos') . '</a></div>';
			}

			$o .= '</div>';
		}*/

		// If not there, create 'aside' empty
		if (!isset($a->page['aside'])) {
			$a->page['aside'] = '';
		}

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

		$tpl = Renderer::getMarkupTemplate("videos_head.tpl");
		$a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
			'$baseurl' => System::baseUrl(),
		]);
	}

	return;
}

function videos_post(App $a)
{
	$owner_uid = $a->data['user']['uid'];

	if (local_user() != $owner_uid) {
		$a->internalRedirect('videos/' . $a->data['user']['nickname']);
	}

	if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
		// Check if we should do HTML-based delete confirmation
		if (empty($_REQUEST['confirm'])) {
			if (!empty($_REQUEST['canceled'])) {
				$a->internalRedirect('videos/' . $a->data['user']['nickname']);
			}

			$drop_url = $a->query_string;

			$a->page['content'] = Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
				'$method' => 'post',
				'$message' => L10n::t('Do you really want to delete this video?'),
				'$extra_inputs' => [
					['name' => 'id'    , 'value' => $_POST['id']],
					['name' => 'delete', 'value' => 'x']
				],
				'$confirm' => L10n::t('Delete Video'),
				'$confirm_url' => $drop_url,
				'$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
				'$cancel' => L10n::t('Cancel'),

			]);

			$a->error = 1; // Set $a->error so the other module functions don't execute

			return;
		}

		$video_id = $_POST['id'];

		$r = q("SELECT `id`  FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
			intval(local_user()),
			DBA::escape($video_id)
		);

		if (DBA::isResult($r)) {
			q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
				intval(local_user()),
				DBA::escape($video_id)
			);

			$i = q("SELECT `id` FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
				DBA::escape($video_id),
				intval(local_user())
			);

			if (DBA::isResult($i)) {
				Item::deleteForUser(['id' => $i[0]['id']], local_user());
			}
		}

		$a->internalRedirect('videos/' . $a->data['user']['nickname']);
		return; // NOTREACHED<commit_msg>Use Attach model while deleting in video tab<commit_after><?php
/**
 * @file mod/videos.php
 */

use Friendica\App;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Attach;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Protocol\DFRN;
use Friendica\Util\Security;

function videos_init(App $a)
{
	if ($a->argc > 1) {
		DFRN::autoRedir($a, $a->argv[1]);
	}

	if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
		return;
	}

	Nav::setSelected('home');

	$o = '';

	if ($a->argc > 1) {
		$nick = $a->argv[1];
		$user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
			DBA::escape($nick)
		);

		if (!DBA::isResult($user)) {
			return;
		}

		$a->data['user'] = $user[0];
		$a->profile_uid = $user[0]['uid'];

		$profile = Profile::getByNickname($nick, $a->profile_uid);

		$account_type = Contact::getAccountType($profile);

		$tpl = Renderer::getMarkupTemplate("vcard-widget.tpl");

		$vcard_widget = Renderer::replaceMacros($tpl, [
			'$name' => $profile['name'],
			'$photo' => $profile['photo'],
			'$addr' => defaults($profile, 'addr', ''),
			'$account_type' => $account_type,
			'$pdesc' => defaults($profile, 'pdesc', ''),
		]);

		// If not there, create 'aside' empty
		if (!isset($a->page['aside'])) {
			$a->page['aside'] = '';
		}

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

		$tpl = Renderer::getMarkupTemplate("videos_head.tpl");
		$a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
			'$baseurl' => System::baseUrl(),
		]);
	}

	return;
}

function videos_post(App $a)
{
	$owner_uid = $a->data['user']['uid'];

	if (local_user() != $owner_uid) {
		$a->internalRedirect('videos/' . $a->data['user']['nickname']);
	}

	if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
		// Check if we should do HTML-based delete confirmation
		if (empty($_REQUEST['confirm'])) {
			if (!empty($_REQUEST['canceled'])) {
				$a->internalRedirect('videos/' . $a->data['user']['nickname']);
			}

			$drop_url = $a->query_string;

			$a->page['content'] = Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
				'$method' => 'post',
				'$message' => L10n::t('Do you really want to delete this video?'),
				'$extra_inputs' => [
					['name' => 'id'    , 'value' => $_POST['id']],
					['name' => 'delete', 'value' => 'x']
				],
				'$confirm' => L10n::t('Delete Video'),
				'$confirm_url' => $drop_url,
				'$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
				'$cancel' => L10n::t('Cancel'),

			]);

			$a->error = 1; // Set $a->error so the other module functions don't execute

			return;
		}

		$video_id = $_POST['id'];

		$r = Attach::exists(['id' => $video_id, 'uid' => local_user()]);
		if ($r === true) {
			// delete the attachment
			Attach::delete(['id' => $video_id, 'uid' => local_user()]);

			// delete items where the attach is used
			Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
				'%attach/' . $video_id . '%',
				local_user()
			], local_user());
		}

		$a->internalRedirect('videos/' . $a->data['user']['nickname']);
		return; // NOTREACHED
{'fraction_non_alphanumeric': 0.23828775267538643, 'fraction_numerical': 0.005826397146254459, 'mean_word_length': 3.968103957471943, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 116, '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': '3253151', 'n_tokens_mistral': 3424, 'n_tokens_neox': 3025, 'n_words': 616}