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.
 
 
 
 
 
 

1234 lines
37 KiB

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