';
- foreach($albums as $album) {
+ $albums = q("SELECT count(distinct `resource-id`) AS `total`, `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
+ $sql_extra group by album order by created desc",
+ intval($a->data['user']['uid']),
+ dbesc('Contact Photos'),
+ dbesc( t('Contact Photos'))
+ );
- // 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).
+ $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
- if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
- continue;
- $o .= '
';
- }
+ // add various encodings to the array so we can just loop through and pick them out in a template
+ $ret = array('success' => false);
- $o .= '
';
+ if($albums) {
+ $a->data['albums'] = $albums;
+ if ($albums_visible)
+ $ret['success'] = true;
+
+ $ret['albums'] = array();
+ foreach($albums as $k => $album) {
+ $entry = array(
+ 'text' => $album['album'],
+ 'total' => $album['total'],
+ 'url' => z_root() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
+ 'urlencode' => urlencode($album['album']),
+ 'bin2hex' => bin2hex($album['album'])
+ );
+ $ret['albums'][] = $entry;
+ }
}
- if(! x($a->page,'aside'))
- $a->page['aside'] = '';
- $a->page['aside'] .= $o;
+ $albums = $ret;
+ if(local_user() && $a->data['user']['uid'] == local_user())
+ $can_post = true;
- $a->page['htmlhead'] .= "
-EOT;
}
return;
@@ -120,13 +129,25 @@ function photos_post(&$a) {
$can_post = true;
else {
if($community_page && remote_user()) {
- $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
- intval(remote_user()),
- intval($page_owner_uid)
- );
- if(count($r)) {
- $can_post = true;
- $visitor = remote_user();
+ $cid = 0;
+ if(is_array($_SESSION['remote'])) {
+ foreach($_SESSION['remote'] as $v) {
+ if($v['uid'] == $page_owner_uid) {
+ $cid = $v['cid'];
+ break;
+ }
+ }
+ }
+ if($cid) {
+
+ $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
+ intval($cid),
+ intval($page_owner_uid)
+ );
+ if(count($r)) {
+ $can_post = true;
+ $visitor = $cid;
+ }
}
}
}
@@ -136,7 +157,7 @@ function photos_post(&$a) {
killme();
}
- $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
+ $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)
);
@@ -147,7 +168,7 @@ function photos_post(&$a) {
killme();
}
- $owner_record = $r[0];
+ $owner_record = $r[0];
if(($a->argc > 3) && ($a->argv[2] === 'album')) {
@@ -168,6 +189,11 @@ function photos_post(&$a) {
return; // NOTREACHED
}
+ // Check if the user has responded to a delete confirmation query
+ if($_REQUEST['canceled']) {
+ goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
+ }
+
$newalbum = notags(trim($_POST['albumname']));
if($newalbum != $album) {
q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
@@ -183,6 +209,25 @@ function photos_post(&$a) {
if($_POST['dropalbum'] == t('Delete Album')) {
+ // Check if we should do HTML-based delete confirmation
+ if($_REQUEST['confirm']) {
+ $drop_url = $a->query_string;
+ $extra_inputs = array(
+ array('name' => 'albumname', 'value' => $_POST['albumname']),
+ );
+ $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
+ '$method' => 'post',
+ '$message' => t('Do you really want to delete this photo album and all its photos?'),
+ '$extra_inputs' => $extra_inputs,
+ '$confirm' => t('Delete Album'),
+ '$confirm_url' => $drop_url,
+ '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
+ '$cancel' => t('Cancel'),
+ ));
+ $a->error = 1; // Set $a->error so the other module functions don't execute
+ return;
+ }
+
$res = array();
// get the list of photos we are about to delete
@@ -230,6 +275,8 @@ function photos_post(&$a) {
dbesc($rr['parent-uri']),
intval($page_owner_uid)
);
+ create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid);
+ delete_thread_uri($rr['parent-uri'], $page_owner_uid);
$drop_id = intval($rr['id']);
@@ -244,10 +291,32 @@ function photos_post(&$a) {
return; // NOTREACHED
}
+
+ // Check if the user has responded to a delete confirmation query for a single photo
+ if(($a->argc > 2) && $_REQUEST['canceled']) {
+ goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
+ }
+
if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
// same as above but remove single photo
+ // Check if we should do HTML-based delete confirmation
+ if($_REQUEST['confirm']) {
+ $drop_url = $a->query_string;
+ $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
+ '$method' => 'post',
+ '$message' => t('Do you really want to delete this photo?'),
+ '$extra_inputs' => array(),
+ '$confirm' => t('Delete Photo'),
+ '$confirm_url' => $drop_url,
+ '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
+ '$cancel' => t('Cancel'),
+ ));
+ $a->error = 1; // Set $a->error so the other module functions don't execute
+ return;
+ }
+
if($visitor) {
$r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
intval($visitor),
@@ -277,6 +346,8 @@ function photos_post(&$a) {
dbesc($i[0]['uri']),
intval($page_owner_uid)
);
+ create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
+ delete_thread_uri($i[0]['uri'], $page_owner_uid);
$url = $a->get_baseurl();
$drop_id = intval($i[0]['id']);
@@ -286,13 +357,12 @@ function photos_post(&$a) {
}
}
- goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
+ goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
return; // NOTREACHED
}
if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
-
$desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
$rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
$item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
@@ -308,7 +378,7 @@ function photos_post(&$a) {
$albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
- if((x($_POST,'rotate') !== false) &&
+ if((x($_POST,'rotate') !== false) &&
( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) {
logger('rotate');
@@ -325,7 +395,7 @@ function photos_post(&$a) {
$width = $ph->getWidth();
$height = $ph->getHeight();
- $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0 limit 1",
+ $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0",
dbesc($ph->imageString()),
intval($height),
intval($width),
@@ -337,8 +407,8 @@ function photos_post(&$a) {
$ph->scaleImage(640);
$width = $ph->getWidth();
$height = $ph->getHeight();
-
- $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1 limit 1",
+
+ $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1",
dbesc($ph->imageString()),
intval($height),
intval($width),
@@ -352,14 +422,14 @@ function photos_post(&$a) {
$width = $ph->getWidth();
$height = $ph->getHeight();
- $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2 limit 1",
+ $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2",
dbesc($ph->imageString()),
intval($height),
intval($width),
dbesc($resource_id),
intval($page_owner_uid)
);
- }
+ }
}
}
}
@@ -387,19 +457,19 @@ function photos_post(&$a) {
$visibility = 0;
if($p[0]['desc'] !== $desc || strlen($rawtags))
$visibility = 1;
-
+
if(! $item_id) {
// Create item container
$title = '';
$uri = item_new_uri($a->get_hostname(),$page_owner_uid);
-
+
$arr = array();
$arr['uid'] = $page_owner_uid;
$arr['uri'] = $uri;
- $arr['parent-uri'] = $uri;
+ $arr['parent-uri'] = $uri;
$arr['type'] = 'photo';
$arr['wall'] = 1;
$arr['resource-id'] = $p[0]['resource-id'];
@@ -418,11 +488,11 @@ function photos_post(&$a) {
$arr['last-child'] = 1;
$arr['visible'] = $visibility;
$arr['origin'] = 1;
-
- $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
- . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
+
+ $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
+ . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
. '[/url]';
-
+
$item_id = item_store($arr);
}
@@ -488,7 +558,25 @@ function photos_post(&$a) {
intval($profile_uid)
);
}
- elseif(strstr($name,'_') || strstr($name,' ')) {
+ else {
+ $newname = str_replace('_',' ',$name);
+
+ //select someone from this user's contacts by name
+ $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
+ dbesc($newname),
+ intval($page_owner_uid)
+ );
+
+ if(! $r) {
+ //select someone by attag or nick and the name passed in
+ $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
+ dbesc($name),
+ dbesc($name),
+ intval($page_owner_uid)
+ );
+ }
+ }
+/* elseif(strstr($name,'_') || strstr($name,' ')) {
$newname = str_replace('_',' ',$name);
$r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
dbesc($newname),
@@ -501,7 +589,7 @@ function photos_post(&$a) {
dbesc($name),
intval($page_owner_uid)
);
- }
+ }*/
if(count($r)) {
$newname = $r[0]['name'];
$profile = $r[0]['url'];
@@ -519,14 +607,17 @@ function photos_post(&$a) {
if(strlen($str_tags))
$str_tags .= ',';
$profile = str_replace(',','%2c',$profile);
- $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
+ $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
}
+ } elseif (strpos($tag,'#') === 0) {
+ $tagname = substr($tag, 1);
+ $str_tags .= '#[url='.$a->get_baseurl()."/search?tag=".$tagname.']'.$tagname.'[/url]';
}
}
}
$newtag = $old_tag;
- if(strlen($newtag) && strlen($str_tags))
+ if(strlen($newtag) && strlen($str_tags))
$newtag .= ',';
$newtag .= $str_tags;
@@ -535,7 +626,7 @@ function photos_post(&$a) {
$newinform .= ',';
$newinform .= $inform;
- $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
+ $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
dbesc($newtag),
dbesc($newinform),
dbesc(datetime_convert()),
@@ -543,6 +634,8 @@ function photos_post(&$a) {
intval($item_id),
intval($page_owner_uid)
);
+ create_tags_from_item($item_id);
+ update_thread($item_id);
$best = 0;
foreach($p as $scales) {
@@ -558,7 +651,7 @@ function photos_post(&$a) {
if(count($taginfo)) {
foreach($taginfo as $tagged) {
-
+
$uri = item_new_uri($a->get_hostname(),$page_owner_uid);
$arr = array();
@@ -588,7 +681,7 @@ function photos_post(&$a) {
$arr['tag'] = $tagged[4];
$arr['inform'] = $tagged[2];
$arr['origin'] = 1;
- $arr['body'] = '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]' . ' ' . t('was tagged in a') . ' ' . '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('photo') . '[/url]' . ' ' . t('by') . ' ' . '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]' ;
+ $arr['body'] = sprintf( t('%1$s was tagged in %2$s by %3$s'), '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ;
$arr['body'] .= "\n\n" . '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . $a->get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ;
$arr['object'] = '