Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

412 lines
11 KiB

  1. <?php
  2. require_once('include/items.php');
  3. require_once('include/acl_selectors.php');
  4. require_once('include/bbcode.php');
  5. require_once('include/security.php');
  6. require_once('include/redir.php');
  7. function videos_init(App $a) {
  8. if($a->argc > 1)
  9. auto_redir($a, $a->argv[1]);
  10. if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
  11. return;
  12. }
  13. nav_set_selected('home');
  14. $o = '';
  15. if($a->argc > 1) {
  16. $nick = $a->argv[1];
  17. $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
  18. dbesc($nick)
  19. );
  20. if(! count($user))
  21. return;
  22. $a->data['user'] = $user[0];
  23. $a->profile_uid = $user[0]['uid'];
  24. $profile = get_profiledata_by_nick($nick, $a->profile_uid);
  25. $account_type = account_type($profile);
  26. $tpl = get_markup_template("vcard-widget.tpl");
  27. $vcard_widget .= replace_macros($tpl, array(
  28. '$name' => $profile['name'],
  29. '$photo' => $profile['photo'],
  30. '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""),
  31. '$account_type' => $account_type,
  32. '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
  33. ));
  34. /*$sql_extra = permissions_sql($a->data['user']['uid']);
  35. $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
  36. intval($a->data['user']['uid'])
  37. );
  38. if(count($albums)) {
  39. $a->data['albums'] = $albums;
  40. $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
  41. if($albums_visible) {
  42. $o .= '<div id="sidebar-photos-albums" class="widget">';
  43. $o .= '<h3>' . '<a href="' . App::get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
  44. $o .= '<ul>';
  45. foreach($albums as $album) {
  46. // don't show contact photos. We once translated this name, but then you could still access it under
  47. // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
  48. if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
  49. continue;
  50. $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
  51. }
  52. $o .= '</ul>';
  53. }
  54. if(local_user() && $a->data['user']['uid'] == local_user()) {
  55. $o .= '<div id="photo-albums-upload-link"><a href="' . App::get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
  56. }
  57. $o .= '</div>';
  58. }*/
  59. if(! x($a->page,'aside'))
  60. $a->page['aside'] = '';
  61. $a->page['aside'] .= $vcard_widget;
  62. $tpl = get_markup_template("videos_head.tpl");
  63. $a->page['htmlhead'] .= replace_macros($tpl,array(
  64. '$baseurl' => App::get_baseurl(),
  65. ));
  66. $tpl = get_markup_template("videos_end.tpl");
  67. $a->page['end'] .= replace_macros($tpl,array(
  68. '$baseurl' => App::get_baseurl(),
  69. ));
  70. }
  71. return;
  72. }
  73. function videos_post(App $a) {
  74. $owner_uid = $a->data['user']['uid'];
  75. if (local_user() != $owner_uid) {
  76. goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
  77. }
  78. if (($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
  79. // Check if we should do HTML-based delete confirmation
  80. if (!x($_REQUEST,'confirm')) {
  81. if (x($_REQUEST,'canceled')) {
  82. goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
  83. }
  84. $drop_url = $a->query_string;
  85. $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
  86. '$method' => 'post',
  87. '$message' => t('Do you really want to delete this video?'),
  88. '$extra_inputs' => array(
  89. array('name'=>'id', 'value'=> $_POST['id']),
  90. array('name'=>'delete', 'value'=>'x')
  91. ),
  92. '$confirm' => t('Delete Video'),
  93. '$confirm_url' => $drop_url,
  94. '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
  95. '$cancel' => t('Cancel'),
  96. ));
  97. $a->error = 1; // Set $a->error so the other module functions don't execute
  98. return;
  99. }
  100. $video_id = $_POST['id'];
  101. $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
  102. intval(local_user()),
  103. dbesc($video_id)
  104. );
  105. if (dbm::is_result($r)) {
  106. q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
  107. intval(local_user()),
  108. dbesc($video_id)
  109. );
  110. $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
  111. dbesc($video_id),
  112. intval(local_user())
  113. );
  114. //echo "<pre>"; var_dump($i); killme();
  115. if (dbm::is_result($i)) {
  116. q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
  117. dbesc(datetime_convert()),
  118. dbesc(datetime_convert()),
  119. dbesc($i[0]['uri']),
  120. intval(local_user())
  121. );
  122. create_tags_from_itemuri($i[0]['uri'], local_user());
  123. delete_thread_uri($i[0]['uri'], local_user());
  124. $url = App::get_baseurl();
  125. $drop_id = intval($i[0]['id']);
  126. if ($i[0]['visible']) {
  127. proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
  128. }
  129. }
  130. }
  131. goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
  132. return; // NOTREACHED
  133. }
  134. goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
  135. }
  136. function videos_content(App $a) {
  137. // URLs (most aren't currently implemented):
  138. // videos/name
  139. // videos/name/upload
  140. // videos/name/upload/xxxxx (xxxxx is album name)
  141. // videos/name/album/xxxxx
  142. // videos/name/album/xxxxx/edit
  143. // videos/name/video/xxxxx
  144. // videos/name/video/xxxxx/edit
  145. if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
  146. notice( t('Public access denied.') . EOL);
  147. return;
  148. }
  149. require_once('include/bbcode.php');
  150. require_once('include/security.php');
  151. require_once('include/conversation.php');
  152. if(! x($a->data,'user')) {
  153. notice( t('No videos selected') . EOL );
  154. return;
  155. }
  156. //$phototypes = Photo::supportedTypes();
  157. $_SESSION['video_return'] = $a->cmd;
  158. //
  159. // Parse arguments
  160. //
  161. if($a->argc > 3) {
  162. $datatype = $a->argv[2];
  163. $datum = $a->argv[3];
  164. }
  165. elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
  166. $datatype = 'upload';
  167. else
  168. $datatype = 'summary';
  169. if($a->argc > 4)
  170. $cmd = $a->argv[4];
  171. else
  172. $cmd = 'view';
  173. //
  174. // Setup permissions structures
  175. //
  176. $can_post = false;
  177. $visitor = 0;
  178. $contact = null;
  179. $remote_contact = false;
  180. $contact_id = 0;
  181. $owner_uid = $a->data['user']['uid'];
  182. $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
  183. if((local_user()) && (local_user() == $owner_uid))
  184. $can_post = true;
  185. else {
  186. if($community_page && remote_user()) {
  187. if(is_array($_SESSION['remote'])) {
  188. foreach($_SESSION['remote'] as $v) {
  189. if($v['uid'] == $owner_uid) {
  190. $contact_id = $v['cid'];
  191. break;
  192. }
  193. }
  194. }
  195. if($contact_id) {
  196. $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
  197. intval($contact_id),
  198. intval($owner_uid)
  199. );
  200. if (dbm::is_result($r)) {
  201. $can_post = true;
  202. $contact = $r[0];
  203. $remote_contact = true;
  204. $visitor = $contact_id;
  205. }
  206. }
  207. }
  208. }
  209. // perhaps they're visiting - but not a community page, so they wouldn't have write access
  210. if(remote_user() && (! $visitor)) {
  211. $contact_id = 0;
  212. if(is_array($_SESSION['remote'])) {
  213. foreach($_SESSION['remote'] as $v) {
  214. if($v['uid'] == $owner_uid) {
  215. $contact_id = $v['cid'];
  216. break;
  217. }
  218. }
  219. }
  220. if($contact_id) {
  221. $groups = init_groups_visitor($contact_id);
  222. $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
  223. intval($contact_id),
  224. intval($owner_uid)
  225. );
  226. if (dbm::is_result($r)) {
  227. $contact = $r[0];
  228. $remote_contact = true;
  229. }
  230. }
  231. }
  232. if(! $remote_contact) {
  233. if(local_user()) {
  234. $contact_id = $_SESSION['cid'];
  235. $contact = $a->contact;
  236. }
  237. }
  238. if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
  239. notice( t('Access to this item is restricted.') . EOL);
  240. return;
  241. }
  242. $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
  243. $o = "";
  244. // tabs
  245. $_is_owner = (local_user() && (local_user() == $owner_uid));
  246. $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
  247. //
  248. // dispatch request
  249. //
  250. if($datatype === 'upload') {
  251. return; // no uploading for now
  252. // DELETED -- look at mod/photos.php if you want to implement
  253. }
  254. if($datatype === 'album') {
  255. return; // no albums for now
  256. // DELETED -- look at mod/photos.php if you want to implement
  257. }
  258. if($datatype === 'video') {
  259. return; // no single video view for now
  260. // DELETED -- look at mod/photos.php if you want to implement
  261. }
  262. // Default - show recent videos (no upload link for now)
  263. //$o = '';
  264. $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
  265. $sql_extra GROUP BY hash",
  266. intval($a->data['user']['uid'])
  267. );
  268. if (dbm::is_result($r)) {
  269. $a->set_pager_total(count($r));
  270. $a->set_pager_itemspage(20);
  271. }
  272. $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
  273. ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
  274. FROM `attach`
  275. WHERE `uid` = %d AND filetype LIKE '%%video%%'
  276. $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
  277. intval($a->data['user']['uid']),
  278. intval($a->pager['start']),
  279. intval($a->pager['itemspage'])
  280. );
  281. $videos = array();
  282. if (dbm::is_result($r)) {
  283. foreach ($r as $rr) {
  284. if ($a->theme['template_engine'] === 'internal') {
  285. $alt_e = template_escape($rr['filename']);
  286. $name_e = template_escape($rr['album']);
  287. }
  288. else {
  289. $alt_e = $rr['filename'];
  290. $name_e = $rr['album'];
  291. }
  292. $videos[] = array(
  293. 'id' => $rr['id'],
  294. 'link' => App::get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
  295. 'title' => t('View Video'),
  296. 'src' => App::get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0',
  297. 'alt' => $alt_e,
  298. 'mime' => $rr['filetype'],
  299. 'album' => array(
  300. 'link' => App::get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
  301. 'name' => $name_e,
  302. 'alt' => t('View Album'),
  303. ),
  304. );
  305. }
  306. }
  307. $tpl = get_markup_template('videos_recent.tpl');
  308. $o .= replace_macros($tpl, array(
  309. '$title' => t('Recent Videos'),
  310. '$can_post' => $can_post,
  311. '$upload' => array(t('Upload New Videos'), App::get_baseurl().'/videos/'.$a->data['user']['nickname'].'/upload'),
  312. '$videos' => $videos,
  313. '$delete_url' => (($can_post)?App::get_baseurl().'/videos/'.$a->data['user']['nickname']:False)
  314. ));
  315. $o .= paginate($a);
  316. return $o;
  317. }