use Friendica\App;
use Friendica\Content\Feature;
use Friendica\Content\Nav;
+use Friendica\Content\Text\BBCode;
+use Friendica\Core\ACL;
use Friendica\Core\Addon;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Model\Item;
use Friendica\Model\Photo;
use Friendica\Model\Profile;
-use Friendica\Model\Term;
+use Friendica\Model\User;
use Friendica\Network\Probe;
use Friendica\Object\Image;
use Friendica\Protocol\DFRN;
use Friendica\Util\Temporal;
require_once 'include/items.php';
-require_once 'include/acl_selectors.php';
-require_once 'include/bbcode.php';
require_once 'include/security.php';
function photos_init(App $a) {
if (local_user() && $a->data['user']['uid'] == local_user()) {
$can_post = true;
+ } else {
+ $can_post = false;
}
if ($ret['success']) {
}
if (!$can_post) {
- notice(L10n::t('Permission denied.') . EOL );
+ notice(L10n::t('Permission denied.') . EOL);
killme();
}
- $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
- WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
- intval($page_owner_uid)
- );
+ $owner_record = User::getOwnerDataById($page_owner_uid);
- if (!DBM::is_result($r)) {
+ if (!$owner_record) {
notice(L10n::t('Contact information unavailable') . EOL);
logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
killme();
}
- $owner_record = $r[0];
-
if ($a->argc > 3 && $a->argv[2] === 'album') {
$album = hex2bin($a->argv[3]);
$str_res = implode(',', $res);
// remove the associated photos
- q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
+ q("DELETE FROM `photo` WHERE `resource-id` IN ($str_res) AND `uid` = %d",
intval($page_owner_uid)
);
// find and delete the corresponding item with all the comments and likes/dislikes
- $r = q("SELECT `id`, `parent-uri`, `visible` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
- intval($page_owner_uid)
- );
- if (DBM::is_result($r)) {
- foreach ($r as $rr) {
- q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
- dbesc(DateTimeFormat::utcNow()),
- dbesc($rr['parent-uri']),
- intval($page_owner_uid)
- );
- Term::insertFromTagFieldByItemUri($rr['parent-uri'], $page_owner_uid);
- Item::deleteThreadByUri($rr['parent-uri'], $page_owner_uid);
-
- $drop_id = intval($rr['id']);
-
- // send the notification upstream/downstream as the case may be
- if ($rr['visible']) {
- Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
- }
- }
- }
+ Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
// Update the photo albums cache
Photo::clearAlbumCache($page_owner_uid);
intval($page_owner_uid),
dbesc($r[0]['resource-id'])
);
- $i = q("SELECT `id`, `uri`, `visible` FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($r[0]['resource-id']),
- intval($page_owner_uid)
- );
- if (DBM::is_result($i)) {
- q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
- dbesc(DateTimeFormat::utcNow()),
- dbesc(DateTimeFormat::utcNow()),
- dbesc($i[0]['uri']),
- intval($page_owner_uid)
- );
- Term::insertFromTagFieldByItemUri($i[0]['uri'], $page_owner_uid);
- Item::deleteThreadByUri($i[0]['uri'], $page_owner_uid);
- $url = System::baseUrl();
- $drop_id = intval($i[0]['id']);
+ Item::deleteForUser(['resource-id' => $r[0]['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
- // Update the photo albums cache
- Photo::clearAlbumCache($page_owner_uid);
-
- if ($i[0]['visible']) {
- Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
- }
- }
+ // Update the photo albums cache
+ Photo::clearAlbumCache($page_owner_uid);
}
goaway('photos/' . $a->data['user']['nickname']);
if (DBM::is_result($r)) {
$Image = new Image($r[0]['data'], $r[0]['type']);
if ($Image->isValid()) {
- $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
+ $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
$Image->rotate($rotate_deg);
$width = $Image->getWidth();
if (!$item_id) {
// Create item container
$title = '';
- $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
+ $uri = Item::newURI($page_owner_uid);
$arr = [];
- $arr['guid'] = get_guid(32);
+ $arr['guid'] = System::createGUID(32);
$arr['uid'] = $page_owner_uid;
$arr['uri'] = $uri;
$arr['parent-uri'] = $uri;
}
if ($item_id) {
- $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
- intval($item_id),
- intval($page_owner_uid)
- );
+ $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
}
- if (DBM::is_result($r)) {
- $old_tag = $r[0]['tag'];
- $old_inform = $r[0]['inform'];
+ if (DBM::is_result($item)) {
+ $old_tag = $item['tag'];
+ $old_inform = $item['inform'];
}
if (strlen($rawtags)) {
}
$newinform .= $inform;
- $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
- dbesc($newtag),
- dbesc($newinform),
- dbesc(DateTimeFormat::utcNow()),
- dbesc(DateTimeFormat::utcNow()),
- intval($item_id),
- intval($page_owner_uid)
- );
- Term::insertFromTagFieldByItemId($item_id);
- Item::updateThread($item_id);
+ $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
+ $condition = ['id' => $item_id];
+ Item::update($fields, $condition);
$best = 0;
foreach ($p as $scales) {
if (count($taginfo)) {
foreach ($taginfo as $tagged) {
- $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
+ $uri = Item::newURI($page_owner_uid);
$arr = [];
- $arr['guid'] = get_guid(32);
+ $arr['guid'] = System::createGUID(32);
$arr['uid'] = $page_owner_uid;
$arr['uri'] = $uri;
$arr['parent-uri'] = $uri;
$arr['deny_gid'] = $p[0]['deny_gid'];
$arr['visible'] = 1;
$arr['verb'] = ACTIVITY_TAG;
+ $arr['gravity'] = GRAVITY_PARENT;
$arr['object-type'] = ACTIVITY_OBJ_PERSON;
$arr['target-type'] = ACTIVITY_OBJ_IMAGE;
$arr['tag'] = $tagged[4];
$smallest = 0;
- $photo_hash = photo_new_resource();
+ $photo_hash = Photo::newResource();
$r = Photo::store($Image, $page_owner_uid, $visitor, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
$smallest = 2;
}
- $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
+ $uri = Item::newURI($page_owner_uid);
// Create item container
$lat = $lon = null;
- if ($exif && $exif['GPS'] && Feature::isEnabled($channel_id, 'photo_location')) {
+ if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
$lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
$lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
}
$arr['coord'] = $lat . ' ' . $lon;
}
- $arr['guid'] = get_guid(32);
+ $arr['guid'] = System::createGUID(32);
$arr['uid'] = $page_owner_uid;
$arr['uri'] = $uri;
$arr['parent-uri'] = $uri;
return;
}
- require_once 'include/bbcode.php';
require_once 'include/security.php';
require_once 'include/conversation.php';
if (!x($a->data,'user')) {
- notice(L10n::t('No photos selected') . EOL );
+ notice(L10n::t('No photos selected') . EOL);
return;
}
$contact = null;
$remote_contact = false;
$contact_id = 0;
+ $edit = false;
$owner_uid = $a->data['user']['uid'];
$tpl = get_markup_template('photos_upload.tpl');
- $aclselect_e = ($visitor ? '' : populate_acl($a->user));
+ $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->user));
$o .= replace_macros($tpl,[
'$pagename' => L10n::t('Upload Photos'),
if (DBM::is_result($ph)) {
notice(L10n::t('Permission denied. Access to this item may be restricted.'));
} else {
- notice(L10n::t('Photo not available') . EOL );
+ notice(L10n::t('Photo not available') . EOL);
}
return;
}
$prevlink = '';
$nextlink = '';
- /// @todo This query is totally bad, the whole functionality has to be changed
- // The query leads to a really intense used index.
- // By now we hide it if someone wants to.
+ /*
+ * @todo This query is totally bad, the whole functionality has to be changed
+ * The query leads to a really intense used index.
+ * By now we hide it if someone wants to.
+ */
if (!Config::get('system', 'no_count', false)) {
$order_field = defaults($_GET, 'order', '');
+
if ($order_field === 'posted') {
$order = 'ASC';
} else {
}
}
- if (count($ph) == 1)
+ if (count($ph) == 1) {
$hires = $lores = $ph[0];
+ }
+
if (count($ph) > 1) {
if ($ph[1]['scale'] == 2) {
// original is 640 or less, we can display it directly
}
$album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
+
$tools = null;
$lock = null;
];
// lock
- $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
- || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
+ $lock = ((($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
+ || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])))
? L10n::t('Private Message')
: Null);
}
- if ( $cmd === 'edit') {
+ if ($cmd === 'edit') {
$tpl = get_markup_template('photo_edit_head.tpl');
$a->page['htmlhead'] .= replace_macros($tpl,[
'$prevlink' => $prevlink,
]);
}
- if ($prevlink)
+ if ($prevlink) {
$prevlink = [$prevlink, '<div class="icon prev"></div>'] ;
+ }
$photo = [
'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
// The difference is that we won't be displaying the conversation head item
// as a "post" but displaying instead the photo it is linked to
- $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
+ /// @todo Rewrite this query. To do so, $sql_extra must be changed
+ $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
dbesc($datum)
);
$link_item = [];
if (DBM::is_result($linked_items)) {
- $link_item = $linked_items[0];
-
- $r = q("SELECT COUNT(*) AS `total`
- FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
- WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
- AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
- AND `item`.`uid` = %d
- $sql_extra ",
- dbesc($link_item['uri']),
- dbesc($link_item['uri']),
- intval($link_item['uid'])
-
- );
-
- if (DBM::is_result($r)) {
- $a->set_pager_total($r[0]['total']);
- }
+ // This is a workaround to not being forced to rewrite the while $sql_extra handling
+ $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
+ $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']];
+ $a->set_pager_total(dba::count('item', $condition));
- $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
- `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
- `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
- `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
- FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
- WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
- AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
- AND `item`.`uid` = %d
- $sql_extra
- ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
- dbesc($link_item['uri']),
- dbesc($link_item['uri']),
- intval($link_item['uid']),
- intval($a->pager['start']),
- intval($a->pager['itemspage'])
-
- );
+ $params = ['order' => ['id'], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
+ $result = Item::selectForUser($link_item['uid'], [], $condition, $params);
+ $items = Item::inArray($result);
if (local_user() && (local_user() == $link_item['uid'])) {
- q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
- intval($link_item['parent']),
- intval(local_user())
- );
- Item::updateThread($link_item['parent']);
+ Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
}
if ($link_item['coord']) {
if (strlen($tag_str)) {
$tag_str .= ', ';
}
- $tag_str .= bbcode($t);
+ $tag_str .= BBCode::convert($t);
}
$tags = [L10n::t('Tags: '), $tag_str];
if ($cmd === 'edit') {
$album_e = $ph[0]['album'];
$caption_e = $ph[0]['desc'];
- $aclselect_e = populate_acl($ph[0]);
+ $aclselect_e = ACL::getFullSelectorHTML($ph[0]);
$edit = replace_macros($edit_tpl, [
'$id' => $ph[0]['id'],
]);
}
- if (!DBM::is_result($r)) {
+ if (!DBM::is_result($items)) {
if (($can_post || can_write_wall($owner_uid))) {
$comments .= replace_macros($cmnt_tpl, [
'$return_path' => '',
];
// display comments
- if (DBM::is_result($r)) {
- foreach ($r as $item) {
+ if (DBM::is_result($items)) {
+ foreach ($items as $item) {
builtin_activity_puller($item, $conv_responses);
}
]);
}
- foreach ($r as $item) {
+ foreach ($items as $item) {
$comment = '';
$template = $tpl;
$sparkle = '';
continue;
}
- $redirect_url = 'redir/' . $item['cid'];
-
- if (local_user() && ($item['contact-uid'] == local_user())
- && ($item['network'] == NETWORK_DFRN) && !$item['self']) {
- $profile_url = $redirect_url;
+ $profile_url = Contact::MagicLinkById($item['author-id']);
+ if (strpos($profile_url, 'redir/') === 0) {
$sparkle = ' sparkle';
} else {
- $profile_url = $item['url'];
$sparkle = '';
}
- $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
-
- $profile_name = ((strlen($item['author-name']) && $diff_author) ? $item['author-name'] : $item['name']);
- $profile_avatar = ((strlen($item['author-avatar']) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
-
- $profile_link = $profile_url;
-
$dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
$drop = [
'dropping' => $dropping,
'delete' => L10n::t('Delete'),
];
- $name_e = $profile_name;
$title_e = $item['title'];
- $body_e = bbcode($item['body']);
+ $body_e = BBCode::convert($item['body']);
$comments .= replace_macros($template,[
'$id' => $item['item_id'],
- '$profile_url' => $profile_link,
- '$name' => $name_e,
- '$thumb' => $profile_avatar,
+ '$profile_url' => $profile_url,
+ '$name' => $item['author-name'],
+ '$thumb' => $item['author-avatar'],
'$sparkle' => $sparkle,
'$title' => $title_e,
'$body' => $body_e,
$twist = false;
foreach ($r as $rr) {
//hide profile photos to others
- if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos')))
+ if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos'))) {
continue;
+ }
$twist = !$twist;