Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1281 lines
39 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. <?php
  2. require_once('include/Photo.php');
  3. require_once('include/items.php');
  4. require_once('include/acl_selectors.php');
  5. require_once('include/bbcode.php');
  6. function photos_init(&$a) {
  7. $o = '';
  8. if($a->argc > 1) {
  9. $nick = $a->argv[1];
  10. $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
  11. dbesc($nick)
  12. );
  13. if(! count($r))
  14. return;
  15. $a->data['user'] = $r[0];
  16. $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d",
  17. intval($a->data['user']['uid'])
  18. );
  19. if(count($albums)) {
  20. $a->data['albums'] = $albums;
  21. $o .= '<h4><a href="' . $a->get_baseurl() . '/profile/' . $a->data['user']['nickname'] . '">' . $a->data['user']['username'] . '</a></h4>';
  22. $o .= '<h4>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h4>';
  23. $o .= '<ul>';
  24. foreach($albums as $album) {
  25. if((! strlen($album['album'])) || ($album['album'] == t('Contact Photos')))
  26. continue;
  27. $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" />' . $album['album'] . '</a></li>';
  28. }
  29. $o .= '</ul>';
  30. }
  31. if(! x($a->page,'aside'))
  32. $a->page['aside'] = '';
  33. $a->page['aside'] .= $o;
  34. }
  35. return;
  36. }
  37. function photos_post(&$a) {
  38. logger('mod/photos.php: photos_post(): begin' , 'LOGGER_DEBUG');
  39. foreach($_REQUEST AS $key => $val) {
  40. logger('mod/photos.php: photos_post(): $_REQUEST key: ' . $key . ' val: ' . $val , 'LOGGER_DEBUG');
  41. }
  42. foreach($_FILES AS $key => $val) {
  43. logger('mod/photos.php: photos_post(): $_FILES key: ' . $key . ' val: ' . $val , 'LOGGER_DEBUG');
  44. }
  45. $can_post = false;
  46. $visitor = 0;
  47. $page_owner_uid = $a->data['user']['uid'];
  48. $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
  49. if((local_user()) && (local_user() == $page_owner_uid))
  50. $can_post = true;
  51. else {
  52. if($community_page && remote_user()) {
  53. $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
  54. intval(remote_user()),
  55. intval($page_owner_uid)
  56. );
  57. if(count($r)) {
  58. $can_post = true;
  59. $visitor = remote_user();
  60. }
  61. }
  62. }
  63. if(! $can_post) {
  64. notice( t('Permission denied.') . EOL );
  65. killme();
  66. }
  67. $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
  68. WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
  69. intval($page_owner_uid)
  70. );
  71. if(! count($r)) {
  72. notice( t('Contact information unavailable') . EOL);
  73. logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
  74. killme();
  75. }
  76. $owner_record = $r[0];
  77. if(($a->argc > 3) && ($a->argv[2] === 'album')) {
  78. $album = hex2bin($a->argv[3]);
  79. if($album == t('Profile Photos') || $album == t('Contact Photos')) {
  80. goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
  81. return; // NOTREACHED
  82. }
  83. $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
  84. dbesc($album),
  85. intval($page_owner_uid)
  86. );
  87. if(! count($r)) {
  88. notice( t('Album not found.') . EOL);
  89. goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
  90. return; // NOTREACHED
  91. }
  92. $newalbum = notags(trim($_POST['albumname']));
  93. if($newalbum != $album) {
  94. q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
  95. dbesc($newalbum),
  96. dbesc($album),
  97. intval($page_owner_uid)
  98. );
  99. $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
  100. goaway($a->get_baseurl() . '/' . $newurl);
  101. return; // NOTREACHED
  102. }
  103. if($_POST['dropalbum'] == t('Delete Album')) {
  104. $res = array();
  105. // get the list of photos we are about to delete
  106. if($visitor) {
  107. $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
  108. intval($visitor),
  109. intval($page_owner_uid),
  110. dbesc($album)
  111. );
  112. }
  113. else {
  114. $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
  115. intval(local_user()),
  116. dbesc($album)
  117. );
  118. }
  119. if(count($r)) {
  120. foreach($r as $rr) {
  121. $res[] = "'" . dbesc($rr['rid']) . "'" ;
  122. }
  123. }
  124. else {
  125. goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
  126. return; // NOTREACHED
  127. }
  128. $str_res = implode(',', $res);
  129. // remove the associated photos
  130. q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
  131. intval($page_owner_uid)
  132. );
  133. // find and delete the corresponding item with all the comments and likes/dislikes
  134. $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
  135. intval($page_owner_uid)
  136. );
  137. if(count($r)) {
  138. foreach($r as $rr) {
  139. q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
  140. dbesc(datetime_convert()),
  141. dbesc($rr['parent-uri']),
  142. intval($page_owner_uid)
  143. );
  144. $drop_id = intval($rr['id']);
  145. // send the notification upstream/downstream as the case may be
  146. if($rr['visible'])
  147. proc_run('php',"include/notifier.php","drop","$drop_id");
  148. }
  149. }
  150. }
  151. goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
  152. return; // NOTREACHED
  153. }
  154. if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
  155. // same as above but remove single photo
  156. if($visitor) {
  157. $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
  158. intval($visitor),
  159. intval($page_owner_uid),
  160. dbesc($a->argv[2])
  161. );
  162. }
  163. else {
  164. $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
  165. intval(local_user()),
  166. dbesc($a->argv[2])
  167. );
  168. }
  169. if(count($r)) {
  170. q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
  171. intval($page_owner_uid),
  172. dbesc($r[0]['resource-id'])
  173. );
  174. $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
  175. dbesc($r[0]['resource-id']),
  176. intval($page_owner_uid)
  177. );
  178. if(count($i)) {
  179. q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
  180. dbesc(datetime_convert()),
  181. dbesc(datetime_convert()),
  182. dbesc($i[0]['uri']),
  183. intval($page_owner_uid)
  184. );
  185. $url = $a->get_baseurl();
  186. $drop_id = intval($i[0]['id']);
  187. if($i[0]['visible'])
  188. proc_run('php',"include/notifier.php","drop","$drop_id");
  189. }
  190. }
  191. goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
  192. return; // NOTREACHED
  193. }
  194. if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
  195. $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
  196. $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
  197. $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
  198. $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
  199. $str_group_allow = perms2str($_POST['group_allow']);
  200. $str_contact_allow = perms2str($_POST['contact_allow']);
  201. $str_group_deny = perms2str($_POST['group_deny']);
  202. $str_contact_deny = perms2str($_POST['contact_deny']);
  203. $resource_id = $a->argv[2];
  204. if(! strlen($albname))
  205. $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
  206. $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
  207. dbesc($resource_id),
  208. intval($page_owner_uid)
  209. );
  210. if(count($p)) {
  211. $r = q("UPDATE `photo` SET `desc` = '%s', `album` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
  212. dbesc($desc),
  213. dbesc($albname),
  214. dbesc($str_contact_allow),
  215. dbesc($str_group_allow),
  216. dbesc($str_contact_deny),
  217. dbesc($str_group_deny),
  218. dbesc($resource_id),
  219. intval($page_owner_uid)
  220. );
  221. }
  222. /* Don't make the item visible if the only change was the album name */
  223. $visibility = 0;
  224. if($p[0]['desc'] !== $desc || strlen($rawtags))
  225. $visibility = 1;
  226. if(! $item_id) {
  227. // Create item container
  228. $title = '';
  229. $basename = basename($filename);
  230. $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
  231. $arr = array();
  232. $arr['uid'] = $page_owner_uid;
  233. $arr['uri'] = $uri;
  234. $arr['parent-uri'] = $uri;
  235. $arr['type'] = 'photo';
  236. $arr['wall'] = 1;
  237. $arr['resource-id'] = $p[0]['resource-id'];
  238. $arr['contact-id'] = $owner_record['id'];
  239. $arr['owner-name'] = $owner_record['name'];
  240. $arr['owner-link'] = $owner_record['url'];
  241. $arr['owner-avatar'] = $owner_record['thumb'];
  242. $arr['author-name'] = $owner_record['name'];
  243. $arr['author-link'] = $owner_record['url'];
  244. $arr['author-avatar'] = $owner_record['thumb'];
  245. $arr['title'] = $title;
  246. $arr['allow_cid'] = $p[0]['allow_cid'];
  247. $arr['allow_gid'] = $p[0]['allow_gid'];
  248. $arr['deny_cid'] = $p[0]['deny_cid'];
  249. $arr['deny_gid'] = $p[0]['deny_gid'];
  250. $arr['last-child'] = 1;
  251. $arr['visible'] = $visibility;
  252. $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
  253. . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
  254. . '[/url]';
  255. $item_id = item_store($arr);
  256. }
  257. if($item_id) {
  258. $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  259. intval($item_id),
  260. intval($page_owner_uid)
  261. );
  262. }
  263. if(count($r)) {
  264. $old_tag = $r[0]['tag'];
  265. $old_inform = $r[0]['inform'];
  266. }
  267. if(strlen($rawtags)) {
  268. $str_tags = '';
  269. $inform = '';
  270. // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
  271. $x = substr($rawtags,0,1);
  272. if($x !== '@' && $x !== '#')
  273. $rawtags = '#' . $rawtags;
  274. $taginfo = array();
  275. $tags = get_tags($rawtags);
  276. if(count($tags)) {
  277. foreach($tags as $tag) {
  278. if(strpos($tag,'@') === 0) {
  279. $name = substr($tag,1);
  280. if((strpos($name,'@')) || (strpos($name,'http://'))) {
  281. $newname = $name;
  282. $links = @lrdd($name);
  283. if(count($links)) {
  284. foreach($links as $link) {
  285. if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
  286. $profile = $link['@attributes']['href'];
  287. if($link['@attributes']['rel'] === 'salmon') {
  288. $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
  289. if(strlen($inform))
  290. $inform .= ',';
  291. $inform .= $salmon;
  292. }
  293. }
  294. }
  295. $taginfo[] = array($newname,$profile,$salmon);
  296. }
  297. else {
  298. $newname = $name;
  299. if(strstr($name,'_')) {
  300. $newname = str_replace('_',' ',$name);
  301. $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
  302. dbesc($newname),
  303. intval($page_owner_uid)
  304. );
  305. }
  306. else {
  307. $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
  308. dbesc($name),
  309. intval($page_owner_uid)
  310. );
  311. }
  312. if(count($r)) {
  313. $newname = $r[0]['name'];
  314. $profile = $r[0]['url'];
  315. $notify = 'cid:' . $r[0]['id'];
  316. if(strlen($inform))
  317. $inform .= ',';
  318. $inform .= $notify;
  319. }
  320. }
  321. if($profile) {
  322. if(substr($notify,0,4) === 'cid:')
  323. $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
  324. else
  325. $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
  326. if(strlen($str_tags))
  327. $str_tags .= ',';
  328. $profile = str_replace(',','%2c',$profile);
  329. $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
  330. }
  331. }
  332. }
  333. }
  334. $newtag = $old_tag;
  335. if(strlen($newtag) && strlen($str_tags))
  336. $newtag .= ',';
  337. $newtag .= $str_tags;
  338. $newinform = $old_inform;
  339. if(strlen($newinform) && strlen($inform))
  340. $newinform .= ',';
  341. $newinform .= $inform;
  342. $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
  343. dbesc($newtag),
  344. dbesc($newinform),
  345. dbesc(datetime_convert()),
  346. dbesc(datetime_convert()),
  347. intval($item_id),
  348. intval($page_owner_uid)
  349. );
  350. $best = 0;
  351. foreach($p as $scales) {
  352. if(intval($scales['scale']) == 2) {
  353. $best = 2;
  354. break;
  355. }
  356. if(intval($scales['scale']) == 4) {
  357. $best = 4;
  358. break;
  359. }
  360. }
  361. if(count($taginfo)) {
  362. foreach($taginfo as $tagged) {
  363. $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
  364. $arr = array();
  365. $arr['uid'] = $page_owner_uid;
  366. $arr['uri'] = $uri;
  367. $arr['parent-uri'] = $uri;
  368. $arr['type'] = 'activity';
  369. $arr['wall'] = 1;
  370. $arr['contact-id'] = $owner_record['id'];
  371. $arr['owner-name'] = $owner_record['name'];
  372. $arr['owner-link'] = $owner_record['url'];
  373. $arr['owner-avatar'] = $owner_record['thumb'];
  374. $arr['author-name'] = $owner_record['name'];
  375. $arr['author-link'] = $owner_record['url'];
  376. $arr['author-avatar'] = $owner_record['thumb'];
  377. $arr['title'] = '';
  378. $arr['allow_cid'] = $p[0]['allow_cid'];
  379. $arr['allow_gid'] = $p[0]['allow_gid'];
  380. $arr['deny_cid'] = $p[0]['deny_cid'];
  381. $arr['deny_gid'] = $p[0]['deny_gid'];
  382. $arr['last-child'] = 1;
  383. $arr['visible'] = 1;
  384. $arr['verb'] = ACTIVITY_TAG;
  385. $arr['object-type'] = ACTIVITY_OBJ_PERSON;
  386. $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
  387. $arr['tag'] = $tagged[4];
  388. $arr['inform'] = $tagged[2];
  389. $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]' ;
  390. $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 . '.jpg' . '[/img][/url]' . "\n" ;
  391. $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
  392. $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
  393. if($tagged[3])
  394. $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $tagged[3]['photo'] . '" />' . "\n");
  395. $arr['object'] .= '</link></object>' . "\n";
  396. $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
  397. . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
  398. $arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="image/jpeg" href="' . $a->get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.jpg' . '" />') . '</link></target>';
  399. $item_id = item_store($arr);
  400. if($item_id)
  401. proc_run('php',"include/notifier.php","tag","$item_id");
  402. }
  403. }
  404. }
  405. goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
  406. return; // NOTREACHED
  407. }
  408. /**
  409. * default post action - upload a photo
  410. */
  411. call_hooks('photo_post_init', $_POST);
  412. /**
  413. * Determine the album to use
  414. */
  415. $album = notags(trim($_REQUEST['album']));
  416. $newalbum = notags(trim($_REQUEST['newalbum']));
  417. logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , 'LOGGER_DEBUG');
  418. if(! strlen($album)) {
  419. if(strlen($newalbum))
  420. $album = $newalbum;
  421. else
  422. $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
  423. }
  424. /**
  425. *
  426. * We create a wall item for every photo, but we don't want to
  427. * overwhelm the data stream with a hundred newly uploaded photos.
  428. * So we will make one photo (the first one uploaded to this album)
  429. * visible by default, the rest will become visible over time when and if
  430. * they acquire comments, likes, dislikes, and/or tags
  431. *
  432. */
  433. $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
  434. dbesc($album),
  435. intval($page_owner_uid)
  436. );
  437. if((! count($r)) || ($album == t('Profile Photos')))
  438. $visible = 1;
  439. else
  440. $visible = 0;
  441. $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
  442. $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
  443. $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
  444. $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
  445. $ret = array('src' => '', 'filename' => '', 'filesize' => 0);
  446. call_hooks('photo_post_file',$ret);
  447. if(x($ret,'src') && x($ret,'filesize')) {
  448. $src = $ret['src'];
  449. $filename = $ret['filename'];
  450. $filesize = $ret['filesize'];
  451. }
  452. else {
  453. $src = $_FILES['userfile']['tmp_name'];
  454. $filename = basename($_FILES['userfile']['name']);
  455. $filesize = intval($_FILES['userfile']['size']);
  456. }
  457. $maximagesize = get_config('system','maximagesize');
  458. if(($maximagesize) && ($filesize > $maximagesize)) {
  459. notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
  460. @unlink($src);
  461. return;
  462. }
  463. logger('mod/photos.php: photos_post(): loading the contents of ' . $src , 'LOGGER_DEBUG');
  464. $imagedata = @file_get_contents($src);
  465. $ph = new Photo($imagedata);
  466. if(! $ph->is_valid()) {
  467. logger('mod/photos.php: photos_post(): unable to process image' , 'LOGGER_DEBUG');
  468. notice( t('Unable to process image.') . EOL );
  469. @unlink($src);
  470. killme();
  471. }
  472. @unlink($src);
  473. $width = $ph->getWidth();
  474. $height = $ph->getHeight();
  475. $smallest = 0;
  476. $photo_hash = photo_new_resource();
  477. $r = $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
  478. if(! $r) {
  479. logger('mod/photos.php: photos_post(): image store failed' , 'LOGGER_DEBUG');
  480. notice( t('Image upload failed.') . EOL );
  481. killme();
  482. }
  483. if($width > 640 || $height > 640) {
  484. $ph->scaleImage(640);
  485. $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
  486. $smallest = 1;
  487. }
  488. if($width > 320 || $height > 320) {
  489. $ph->scaleImage(320);
  490. $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
  491. $smallest = 2;
  492. }
  493. $basename = basename($filename);
  494. $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
  495. // Create item container
  496. $arr = array();
  497. $arr['uid'] = $page_owner_uid;
  498. $arr['uri'] = $uri;
  499. $arr['parent-uri'] = $uri;
  500. $arr['type'] = 'photo';
  501. $arr['wall'] = 1;
  502. $arr['resource-id'] = $photo_hash;
  503. $arr['contact-id'] = $owner_record['id'];
  504. $arr['owner-name'] = $owner_record['name'];
  505. $arr['owner-link'] = $owner_record['url'];
  506. $arr['owner-avatar'] = $owner_record['thumb'];
  507. $arr['author-name'] = $owner_record['name'];
  508. $arr['author-link'] = $owner_record['url'];
  509. $arr['author-avatar'] = $owner_record['thumb'];
  510. $arr['title'] = '';
  511. $arr['allow_cid'] = $str_contact_allow;
  512. $arr['allow_gid'] = $str_group_allow;
  513. $arr['deny_cid'] = $str_contact_deny;
  514. $arr['deny_gid'] = $str_group_deny;
  515. $arr['last-child'] = 1;
  516. $arr['visible'] = $visible;
  517. $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
  518. . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
  519. . '[/url]';
  520. $item_id = item_store($arr);
  521. call_hooks('photo_post_end',intval($item_id));
  522. // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
  523. // if they do not wish to be redirected
  524. goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
  525. // NOTREACHED
  526. }
  527. function photos_content(&$a) {
  528. // URLs:
  529. // photos/name
  530. // photos/name/upload
  531. // photos/name/album/xxxxx
  532. // photos/name/album/xxxxx/edit
  533. // photos/name/image/xxxxx
  534. // photos/name/image/xxxxx/edit
  535. if(! x($a->data,'user')) {
  536. notice( t('No photos selected') . EOL );
  537. return;
  538. }
  539. $_SESSION['photo_return'] = $a->cmd;
  540. //
  541. // Parse arguments
  542. //
  543. if($a->argc > 3) {
  544. $datatype = $a->argv[2];
  545. $datum = $a->argv[3];
  546. }
  547. elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
  548. $datatype = 'upload';
  549. else
  550. $datatype = 'summary';
  551. if($a->argc > 4)
  552. $cmd = $a->argv[4];
  553. else
  554. $cmd = 'view';
  555. //
  556. // Setup permissions structures
  557. //
  558. $can_post = false;
  559. $visitor = 0;
  560. $contact = null;
  561. $remote_contact = false;
  562. $owner_uid = $a->data['user']['uid'];
  563. $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
  564. if((local_user()) && (local_user() == $owner_uid))
  565. $can_post = true;
  566. else {
  567. if($community_page && remote_user()) {
  568. $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
  569. intval(remote_user()),
  570. intval($owner_uid)
  571. );
  572. if(count($r)) {
  573. $can_post = true;
  574. $contact = $r[0];
  575. $remote_contact = true;
  576. $visitor = remote_user();
  577. }
  578. }
  579. }
  580. // perhaps they're visiting - but not a community page, so they wouldn't have write access
  581. if(remote_user() && (! $visitor)) {
  582. $contact_id = $_SESSION['visitor_id'];
  583. $groups = init_groups_visitor($contact_id);
  584. $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
  585. intval(remote_user()),
  586. intval($owner_uid)
  587. );
  588. if(count($r)) {
  589. $contact = $r[0];
  590. $remote_contact = true;
  591. }
  592. }
  593. if(! $remote_contact) {
  594. if(local_user()) {
  595. $contact_id = $_SESSION['cid'];
  596. $contact = $a->contact;
  597. }
  598. }
  599. // default permissions - anonymous user
  600. $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
  601. // Profile owner - everything is visible
  602. if(local_user() && (local_user() == $owner_uid)) {
  603. $sql_extra = '';
  604. }
  605. elseif(remote_user()) {
  606. // authenticated visitor - here lie dragons
  607. $gs = '<<>>'; // should be impossible to match
  608. if(count($groups)) {
  609. foreach($groups as $g)
  610. $gs .= '|<' . intval($g) . '>';
  611. }
  612. $sql_extra = sprintf(
  613. " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
  614. AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
  615. AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
  616. AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
  617. intval(remote_user()),
  618. intval(remote_user()),
  619. dbesc($gs),
  620. dbesc($gs)
  621. );
  622. }
  623. //
  624. // dispatch request
  625. //
  626. if($datatype === 'upload') {
  627. if(! ($can_post)) {
  628. notice( t('Permission denied.'));
  629. return;
  630. }
  631. $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
  632. $albumselect .= '<option value="" selected="selected" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
  633. if(count($a->data['albums'])) {
  634. foreach($a->data['albums'] as $album) {
  635. if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
  636. continue;
  637. $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
  638. }
  639. }
  640. $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
  641. $albumselect .= '</select>';
  642. $uploader = '';
  643. $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
  644. 'addon_text' => $uploader,
  645. 'default_upload' => true);
  646. call_hooks('photo_upload_form',$ret);
  647. $default_upload = '<input type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" >
  648. <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
  649. $tpl = load_view_file('view/photos_upload.tpl');
  650. $o .= replace_macros($tpl,array(
  651. '$pagename' => t('Upload Photos'),
  652. '$sessid' => session_id(),
  653. '$nickname' => $a->data['user']['nickname'],
  654. '$newalbum' => t('New album name: '),
  655. '$existalbumtext' => t('or existing album name: '),
  656. '$albumselect' => $albumselect,
  657. '$permissions' => t('Permissions'),
  658. '$aclselect' => (($visitor) ? '' : populate_acl($a->user, $celeb)),
  659. '$uploader' => $ret['addon_text'],
  660. '$default' => (($ret['default_upload']) ? $default_upload : ''),
  661. '$uploadurl' => $ret['post_url']
  662. ));
  663. return $o;
  664. }
  665. if($datatype === 'album') {
  666. $album = hex2bin($datum);
  667. $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
  668. $sql_extra GROUP BY `resource-id`",
  669. intval($owner_uid),
  670. dbesc($album)
  671. );
  672. if(count($r)) {
  673. $a->set_pager_total(count($r));
  674. $a->set_pager_itemspage(20);
  675. }
  676. $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
  677. $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
  678. intval($owner_uid),
  679. dbesc($album),
  680. intval($a->pager['start']),
  681. intval($a->pager['itemspage'])
  682. );
  683. $o .= '<h3>' . $album . '</h3>';
  684. if($cmd === 'edit') {
  685. if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
  686. if($can_post) {
  687. $edit_tpl = load_view_file('view/album_edit.tpl');
  688. $o .= replace_macros($edit_tpl,array(
  689. '$nametext' => t('New album name: '),
  690. '$nickname' => $a->data['user']['nickname'],
  691. '$album' => $album,
  692. '$hexalbum' => bin2hex($album),
  693. '$submit' => t('Submit'),
  694. '$dropsubmit' => t('Delete Album')
  695. ));
  696. }
  697. }
  698. }
  699. else {
  700. if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
  701. if($can_post) {
  702. $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
  703. . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
  704. . t('Edit Album') . '</a></div>';
  705. }
  706. }
  707. }
  708. $tpl = load_view_file('view/photo_album.tpl');
  709. if(count($r))
  710. foreach($r as $rr) {
  711. $o .= replace_macros($tpl,array(
  712. '$id' => $rr['id'],
  713. '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
  714. '$phototitle' => t('View Photo'),
  715. '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
  716. '$imgalt' => $rr['filename'],
  717. '$desc'=> $rr['desc']
  718. ));
  719. }
  720. $o .= '<div id="photo-album-end"></div>';
  721. $o .= paginate($a);
  722. return $o;
  723. }
  724. if($datatype === 'image') {
  725. require_once('security.php');
  726. require_once('bbcode.php');
  727. $o = '<div id="live-display"></div>' . "\r\n";
  728. // fetch image, item containing image, then comments
  729. $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
  730. $sql_extra ORDER BY `scale` ASC ",
  731. intval($owner_uid),
  732. dbesc($datum)
  733. );
  734. if(! count($ph)) {
  735. notice( t('Photo not available') . EOL );
  736. return;
  737. }
  738. $prevlink = '';
  739. $nextlink = '';
  740. $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
  741. $sql_extra ORDER BY `created` DESC ",
  742. dbesc($ph[0]['album']),
  743. intval($owner_uid)
  744. );
  745. if(count($prvnxt)) {
  746. for($z = 0; $z < count($prvnxt); $z++) {
  747. if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
  748. $prv = $z - 1;
  749. $nxt = $z + 1;
  750. if($prv < 0)
  751. $prv = count($prvnxt) - 1;
  752. if($nxt >= count($prvnxt))
  753. $nxt = 0;
  754. break;
  755. }
  756. }
  757. $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] ;
  758. $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] ;
  759. }
  760. if(count($ph) == 1)
  761. $hires = $lores = $ph[0];
  762. if(count($ph) > 1) {
  763. if($ph[1]['scale'] == 2) {
  764. // original is 640 or less, we can display it directly
  765. $hires = $lores = $ph[0];
  766. }
  767. else {
  768. $hires = $ph[0];
  769. $lores = $ph[1];
  770. }
  771. }
  772. $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']) . '">' . $ph[0]['album'] . '</a></h3>';
  773. if($can_post && ($ph[0]['uid'] == $owner_uid)) {
  774. $o .= '<div id="photo-edit-link-wrap" ><a id="photo-edit-link" href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit' . '">' . t('Edit photo') . '</a>';
  775. $o .= ' - <a id="photo-toprofile-link" href="' . $a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'].'">'.t('Use as profile photo').'</a>';
  776. // lock
  777. $o .= ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
  778. || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
  779. ? ' - <img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,\'photo/' . $ph[0]['id'] . '\');" />'
  780. : '');
  781. $o .= '</div>';
  782. }
  783. if($prevlink)
  784. $o .= '<div id="photo-prev-link"><a href="' . $prevlink .'">' . t('<< Prev') . '</a></div>' ;
  785. $o .= '<div id="photo-photo"><a href="' . $a->get_baseurl() . '/photo/'
  786. . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg" title="'
  787. . t('View Full Size') . '" ><img src="' . $a->get_baseurl() . '/photo/'
  788. . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '" /></a></div>';
  789. if($nextlink)
  790. $o .= '<div id="photo-next-link"><a href="' . $nextlink .'">' . t('Next >>') . '</a></div>';
  791. $o .= '<div id="photo-photo-end"></div>';
  792. // Do we have an item for this photo?
  793. $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
  794. dbesc($datum)
  795. );
  796. if(count($linked_items)) {
  797. $link_item = $linked_items[0];
  798. $r = q("SELECT COUNT(*) AS `total`
  799. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  800. WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
  801. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  802. AND `item`.`uid` = %d
  803. $sql_extra ",
  804. dbesc($link_item['uri']),
  805. dbesc($link_item['uri']),
  806. intval($link_item['uid'])
  807. );
  808. if(count($r))
  809. $a->set_pager_total($r[0]['total']);
  810. $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  811. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
  812. `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
  813. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  814. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  815. WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
  816. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  817. AND `item`.`uid` = %d
  818. $sql_extra
  819. ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
  820. dbesc($link_item['uri']),
  821. dbesc($link_item['uri']),
  822. intval($link_item['uid']),
  823. intval($a->pager['start']),
  824. intval($a->pager['itemspage'])
  825. );
  826. if((local_user()) && (local_user() == $link_item['uid'])) {
  827. q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
  828. intval($link_item['parent']),
  829. intval(local_user())
  830. );
  831. }
  832. }
  833. $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
  834. if(count($linked_items) && strlen($link_item['tag'])) {
  835. $arr = explode(',',$link_item['tag']);
  836. // parse tags and add links
  837. $o .= '<div id="in-this-photo-text">' . t('Tags: ') . '</div>';
  838. $o .= '<div id="in-this-photo">';
  839. $tag_str = '';
  840. foreach($arr as $t) {
  841. if(strlen($tag_str))
  842. $tag_str .= ', ';
  843. $tag_str .= bbcode($t);
  844. }
  845. $o .= $tag_str . '</div>';
  846. if($cmd === 'edit')
  847. $o .= '<div id="tag-remove"><a href="' . $a->get_baseurl() . '/tagrm/' . $link_item['id'] . '">' . t('[Remove any tag]') . '</a></div>';
  848. }
  849. if(($cmd === 'edit') && ($can_post)) {
  850. $edit_tpl = load_view_file('view/photo_edit.tpl');
  851. $o .= replace_macros($edit_tpl, array(
  852. '$id' => $ph[0]['id'],
  853. '$album' => $ph[0]['album'],
  854. '$newalbum' => t('New album name'),
  855. '$nickname' => $a->data['user']['nickname'],
  856. '$resource_id' => $ph[0]['resource-id'],
  857. '$capt_label' => t('Caption'),
  858. '$caption' => $ph[0]['desc'],
  859. '$tag_label' => t('Add a Tag'),
  860. '$tags' => $link_item['tag'],
  861. '$permissions' => t('Permissions'),
  862. '$aclselect' => populate_acl($ph[0]),
  863. '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
  864. '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
  865. '$submit' => t('Submit'),
  866. '$delete' => t('Delete Photo')
  867. ));
  868. }
  869. if(count($linked_items)) {
  870. $cmnt_tpl = load_view_file('view/comment_item.tpl');
  871. $tpl = load_view_file('view/photo_item.tpl');
  872. $return_url = $a->cmd;
  873. $like_tpl = load_view_file('view/like_noshare.tpl');
  874. $likebuttons = '';
  875. if($can_post || can_write_wall($a,$owner_uid)) {
  876. $likebuttons = replace_macros($like_tpl,array(
  877. '$id' => $item['id'],
  878. '$likethis' => t("I like this \x28toggle\x29"),
  879. '$nolike' => t("I don't like this \x28toggle\x29"),
  880. '$share' => t('Share'),
  881. '$wait' => t('Please wait')
  882. ));
  883. }
  884. if(! count($r)) {
  885. $o .= '<div id="photo-like-div">';
  886. $o .= $likebuttons;
  887. $o .= '</div>';
  888. if($can_post || can_write_wall($a,$owner_uid)) {
  889. if($link_item['last-child']) {
  890. $o .= replace_macros($cmnt_tpl,array(
  891. '$return_path' => '',
  892. '$jsreload' => $return_url,
  893. '$type' => 'wall-comment',
  894. '$id' => $link_item['id'],
  895. '$parent' => $link_item['id'],
  896. '$profile_uid' => $owner_uid,
  897. '$mylink' => $contact['url'],
  898. '$mytitle' => t('This is you'),
  899. '$myphoto' => $contact['thumb'],
  900. '$comment' => t('Comment'),
  901. '$submit' => t('Submit'),
  902. '$ww' => ''
  903. ));
  904. }
  905. }
  906. }
  907. $alike = array();
  908. $dlike = array();
  909. // display comments
  910. if(count($r)) {
  911. foreach($r as $item) {
  912. like_puller($a,$item,$alike,'like');
  913. like_puller($a,$item,$dlike,'dislike');
  914. }
  915. $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
  916. $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
  917. $o .= '<div id="photo-like-div">';
  918. $o .= $likebuttons;
  919. $o .= $like;
  920. $o .= $dislike;
  921. $o .= '</div>';
  922. if($can_post || can_write_wall($a,$owner_uid)) {
  923. if($link_item['last-child']) {
  924. $o .= replace_macros($cmnt_tpl,array(
  925. '$return_path' => '',
  926. '$jsreload' => $return_url,
  927. '$type' => 'wall-comment',
  928. '$id' => $link_item['id'],
  929. '$parent' => $link_item['id'],
  930. '$profile_uid' => $owner_uid,
  931. '$mylink' => $contact['url'],
  932. '$mytitle' => t('This is you'),
  933. '$myphoto' => $contact['thumb'],
  934. '$ww' => ''
  935. ));
  936. }
  937. }
  938. foreach($r as $item) {
  939. $comment = '';
  940. $template = $tpl;
  941. $sparkle = '';
  942. if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
  943. continue;
  944. $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
  945. if($can_post || can_write_wall($a,$owner_uid)) {
  946. if($item['last-child']) {
  947. $comment = replace_macros($cmnt_tpl,array(
  948. '$return_path' => '',
  949. '$jsreload' => $return_url,
  950. '$type' => 'wall-comment',
  951. '$id' => $item['item_id'],
  952. '$parent' => $item['parent'],
  953. '$profile_uid' => $owner_uid,
  954. '$mylink' => $contact['url'],
  955. '$mytitle' => t('This is you'),
  956. '$myphoto' => $contact['thumb'],
  957. '$ww' => ''
  958. ));
  959. }
  960. }
  961. if(local_user() && ($item['contact-uid'] == local_user())
  962. && ($item['network'] == 'dfrn') && (! $item['self'] )) {
  963. $profile_url = $redirect_url;
  964. $sparkle = ' sparkle';
  965. }
  966. else {
  967. $profile_url = $item['url'];
  968. $sparkle = '';
  969. }
  970. $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
  971. $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
  972. $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
  973. $profile_link = $profile_url;
  974. $drop = '';
  975. if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
  976. $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
  977. $o .= replace_macros($template,array(
  978. '$id' => $item['item_id'],
  979. '$profile_url' => $profile_link,
  980. '$name' => $profile_name,
  981. '$thumb' => $profile_avatar,
  982. '$sparkle' => $sparkle,
  983. '$title' => $item['title'],
  984. '$body' => bbcode($item['body']),
  985. '$ago' => relative_date($item['created']),
  986. '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
  987. '$drop' => $drop,
  988. '$comment' => $comment
  989. ));
  990. }
  991. }
  992. $o .= paginate($a);
  993. }
  994. return $o;
  995. }
  996. // Default - show recent photos with upload link (if applicable)
  997. $o = '';
  998. $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
  999. $sql_extra GROUP BY `resource-id`",
  1000. intval($a->data['user']['uid']),
  1001. dbesc( t('Contact Photos'))
  1002. );
  1003. if(count($r)) {
  1004. $a->set_pager_total(count($r));
  1005. $a->set_pager_itemspage(20);
  1006. }
  1007. $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
  1008. WHERE `uid` = %d AND `album` != '%s'
  1009. $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
  1010. intval($a->data['user']['uid']),
  1011. dbesc( t('Contact Photos')),
  1012. intval($a->pager['start']),
  1013. intval($a->pager['itemspage'])
  1014. );
  1015. $o .= '<h3>' . t('Recent Photos') . '</h3>';
  1016. if($can_post) {
  1017. $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
  1018. . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
  1019. }
  1020. $tpl = load_view_file('view/photo_top.tpl');
  1021. if(count($r)) {
  1022. foreach($r as $rr) {
  1023. $o .= replace_macros($tpl,array(
  1024. '$id' => $rr['id'],
  1025. '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname']
  1026. . '/image/' . $rr['resource-id'],
  1027. '$phototitle' => t('View Photo'),
  1028. '$imgsrc' => $a->get_baseurl() . '/photo/'
  1029. . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.jpg',
  1030. '$albumlink' => $a->get_baseurl() . '/photos/'
  1031. . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
  1032. '$albumname' => $rr['album'],
  1033. '$albumalt' => t('View Album'),
  1034. '$imgalt' => $rr['filename']
  1035. ));
  1036. }
  1037. $o .= '<div id="photo-top-end"></div>';
  1038. }
  1039. $o .= paginate($a);
  1040. return $o;
  1041. }