Use Attach model while deleting in video tab
This commit is contained in:
parent
b640024b51
commit
19b55f5f8d
|
@ -11,6 +11,7 @@ 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;
|
||||
|
@ -59,41 +60,6 @@ function videos_init(App $a)
|
|||
'$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'] = '';
|
||||
|
@ -148,25 +114,16 @@ function videos_post(App $a)
|
|||
|
||||
$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)
|
||||
);
|
||||
$r = Attach::exists(['id' => $video_id, 'uid' => local_user()]);
|
||||
if ($r === true) {
|
||||
// delete the attachment
|
||||
Attach::delete(['id' => $video_id, 'uid' => local_user()]);
|
||||
|
||||
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());
|
||||
}
|
||||
// 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']);
|
||||
|
|
Loading…
Reference in a new issue