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.

452 lines
14 KiB

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
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
11 years ago
10 years ago
11 years ago
11 years ago
10 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
10 years ago
11 years ago
10 years ago
11 years ago
10 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
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 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
  1. <?php
  2. require_once('include/Contact.php');
  3. require_once('include/socgraph.php');
  4. function contacts_init(&$a) {
  5. if(! local_user())
  6. return;
  7. $contact_id = 0;
  8. if(($a->argc == 2) && intval($a->argv[1])) {
  9. $contact_id = intval($a->argv[1]);
  10. $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
  11. intval(local_user()),
  12. intval($contact_id)
  13. );
  14. if(! count($r)) {
  15. $contact_id = 0;
  16. }
  17. }
  18. require_once('include/group.php');
  19. require_once('include/contact_widgets.php');
  20. if(! x($a->page,'aside'))
  21. $a->page['aside'] = '';
  22. if($contact_id) {
  23. $a->data['contact'] = $r[0];
  24. $o .= '<div class="vcard">';
  25. $o .= '<div class="fn">' . $a->data['contact']['name'] . '</div>';
  26. $o .= '<div id="profile-photo-wrapper"><img class="photo" style="width: 175px; height: 175px;" src="' . $a->data['contact']['photo'] . '" alt="' . $a->data['contact']['name'] . '" /></div>';
  27. $o .= '</div>';
  28. $a->page['aside'] .= $o;
  29. }
  30. else
  31. $a->page['aside'] .= follow_widget();
  32. $a->page['aside'] .= group_side('contacts','group',false,0,$contact_id);
  33. $a->page['aside'] .= findpeople_widget();
  34. }
  35. function contacts_post(&$a) {
  36. if(! local_user())
  37. return;
  38. $contact_id = intval($a->argv[1]);
  39. if(! $contact_id)
  40. return;
  41. $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  42. intval($contact_id),
  43. intval(local_user())
  44. );
  45. if(! count($orig_record)) {
  46. notice( t('Could not access contact record.') . EOL);
  47. goaway($a->get_baseurl() . '/contacts');
  48. return; // NOTREACHED
  49. }
  50. call_hooks('contact_edit_post', $_POST);
  51. $profile_id = intval($_POST['profile-assign']);
  52. if($profile_id) {
  53. $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  54. intval($profile_id),
  55. intval(local_user())
  56. );
  57. if(! count($r)) {
  58. notice( t('Could not locate selected profile.') . EOL);
  59. return;
  60. }
  61. }
  62. $hidden = intval($_POST['hidden']);
  63. $priority = intval($_POST['poll']);
  64. if($priority > 5 || $priority < 0)
  65. $priority = 0;
  66. $info = escape_tags(trim($_POST['info']));
  67. $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
  68. `hidden` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
  69. intval($profile_id),
  70. intval($priority),
  71. dbesc($info),
  72. intval($hidden),
  73. intval($contact_id),
  74. intval(local_user())
  75. );
  76. if($r)
  77. info( t('Contact updated.') . EOL);
  78. else
  79. notice( t('Failed to update contact record.') . EOL);
  80. return;
  81. }
  82. function contacts_content(&$a) {
  83. $sort_type = 0;
  84. $o = '';
  85. nav_set_selected('contacts');
  86. $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
  87. if(! local_user()) {
  88. notice( t('Permission denied.') . EOL);
  89. return;
  90. }
  91. if($a->argc == 3) {
  92. $contact_id = intval($a->argv[1]);
  93. if(! $contact_id)
  94. return;
  95. $cmd = $a->argv[2];
  96. $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
  97. intval($contact_id),
  98. intval(local_user())
  99. );
  100. if(! count($orig_record)) {
  101. notice( t('Could not access contact record.') . EOL);
  102. goaway($a->get_baseurl() . '/contacts');
  103. return; // NOTREACHED
  104. }
  105. if($cmd === 'update') {
  106. // pull feed and consume it, which should subscribe to the hub.
  107. proc_run('php',"include/poller.php","$contact_id");
  108. goaway($a->get_baseurl() . '/contacts/' . $contact_id);
  109. // NOTREACHED
  110. }
  111. if($cmd === 'block') {
  112. $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
  113. $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
  114. intval($blocked),
  115. intval($contact_id),
  116. intval(local_user())
  117. );
  118. if($r) {
  119. //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
  120. info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
  121. }
  122. goaway($a->get_baseurl() . '/contacts/' . $contact_id);
  123. return; // NOTREACHED
  124. }
  125. if($cmd === 'ignore') {
  126. $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
  127. $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
  128. intval($readonly),
  129. intval($contact_id),
  130. intval(local_user())
  131. );
  132. if($r) {
  133. info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
  134. }
  135. goaway($a->get_baseurl() . '/contacts/' . $contact_id);
  136. return; // NOTREACHED
  137. }
  138. if($cmd === 'drop') {
  139. // create an unfollow slap
  140. if($orig_record[0]['network'] === NETWORK_OSTATUS) {
  141. $tpl = get_markup_template('follow_slap.tpl');
  142. $slap = replace_macros($tpl, array(
  143. '$name' => $a->user['username'],
  144. '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
  145. '$photo' => $a->contact['photo'],
  146. '$thumb' => $a->contact['thumb'],
  147. '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
  148. '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
  149. '$title' => '',
  150. '$type' => 'text',
  151. '$content' => t('stopped following'),
  152. '$nick' => $a->user['nickname'],
  153. '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
  154. '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
  155. ));
  156. if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
  157. require_once('include/salmon.php');
  158. slapper($a->user,$orig_record[0]['notify'],$slap);
  159. }
  160. }
  161. elseif($orig_record[0]['network'] === NETWORK_DIASPORA) {
  162. require_once('include/diaspora.php');
  163. diaspora_unshare($a->user,$orig_record[0]);
  164. }
  165. elseif($orig_record[0]['network'] === NETWORK_DFRN) {
  166. require_once('include/items.php');
  167. dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
  168. }
  169. contact_remove($orig_record[0]['id']);
  170. info( t('Contact has been removed.') . EOL );
  171. goaway($a->get_baseurl() . '/contacts');
  172. return; // NOTREACHED
  173. }
  174. }
  175. if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
  176. $contact_id = $a->data['contact']['id'];
  177. $contact = $a->data['contact'];
  178. $tpl = get_markup_template('contact_head.tpl');
  179. $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
  180. require_once('include/contact_selectors.php');
  181. $tpl = get_markup_template("contact_edit.tpl");
  182. switch($contact['rel']) {
  183. case CONTACT_IS_FRIEND:
  184. $dir_icon = 'images/lrarrow.gif';
  185. $relation_text = t('You are mutual friends with %s');
  186. break;
  187. case CONTACT_IS_FOLLOWER;
  188. $dir_icon = 'images/larrow.gif';
  189. $relation_text = t('You are sharing with %s');
  190. break;
  191. case CONTACT_IS_SHARING;
  192. $dir_icon = 'images/rarrow.gif';
  193. $relation_text = t('%s is sharing with you');
  194. break;
  195. default:
  196. break;
  197. }
  198. $relation_text = sprintf($relation_text,$contact['name']);
  199. if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
  200. $url = "redir/{$contact['id']}";
  201. $sparkle = ' class="sparkle" ';
  202. }
  203. else {
  204. $url = $contact['url'];
  205. $sparkle = '';
  206. }
  207. $insecure = t('Private communications are not available for this contact.');
  208. $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
  209. ? t('Never')
  210. : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
  211. if($contact['last-update'] !== '0000-00-00 00:00:00')
  212. $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
  213. $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
  214. $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
  215. $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
  216. $common = count_common_friends(local_user(),$contact['id']);
  217. $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
  218. $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
  219. $x = count_all_friends(local_user(), $contact['id']);
  220. $all_friends = (($x) ? t('View all contacts') : '');
  221. // tabs
  222. $tabs = array(
  223. array(
  224. 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
  225. 'url' => $a->get_baseurl() . '/contacts/' . $contact_id . '/block',
  226. 'sel' => '',
  227. ),
  228. array(
  229. 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
  230. 'url' => $a->get_baseurl() . '/contacts/' . $contact_id . '/ignore',
  231. 'sel' => '',
  232. ),
  233. array(
  234. 'label' => t('Repair'),
  235. 'url' => $a->get_baseurl() . '/crepair/' . $contact_id,
  236. 'sel' => '',
  237. )
  238. );
  239. $tab_tpl = get_markup_template('common_tabs.tpl');
  240. $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
  241. $o .= replace_macros($tpl,array(
  242. '$header' => t('Contact Editor'),
  243. '$tab_str' => $tab_str,
  244. '$submit' => t('Submit'),
  245. '$lbl_vis1' => t('Profile Visibility'),
  246. '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
  247. '$lbl_info1' => t('Contact Information / Notes'),
  248. '$infedit' => t('Edit contact notes'),
  249. '$common_text' => $common_text,
  250. '$common_link' => $a->get_baseurl() . '/common/' . $contact['id'],
  251. '$all_friends' => $all_friends,
  252. '$relation_text' => $relation_text,
  253. '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
  254. '$blockunblock' => t('Block/Unblock contact'),
  255. '$ignorecont' => t('Ignore contact'),
  256. '$lblcrepair' => t("Repair URL settings"),
  257. '$lblrecent' => t('View conversations'),
  258. '$lblsuggest' => $lblsuggest,
  259. '$delete' => t('Delete contact'),
  260. '$nettype' => $nettype,
  261. '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
  262. '$poll_enabled' => $poll_enabled,
  263. '$lastupdtext' => t('Last update:'),
  264. '$updpub' => t('Update public posts'),
  265. '$last_update' => $last_update,
  266. '$udnow' => t('Update now'),
  267. '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
  268. '$contact_id' => $contact['id'],
  269. '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
  270. '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
  271. '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
  272. '$info' => $contact['info'],
  273. '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
  274. '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
  275. '$hidden' => array('hidden', t('Hide this contact from others'), ($contact['hidden'] == 1), t('Replies/likes to your public posts <strong>may</strong> still be visible')),
  276. '$photo' => $contact['photo'],
  277. '$name' => $contact['name'],
  278. '$dir_icon' => $dir_icon,
  279. '$alt_text' => $alt_text,
  280. '$sparkle' => $sparkle,
  281. '$url' => $url
  282. ));
  283. $arr = array('contact' => $contact,'output' => $o);
  284. call_hooks('contact_edit', $arr);
  285. return $arr['output'];
  286. }
  287. if(($a->argc == 2) && ($a->argv[1] === 'all'))
  288. $sql_extra = '';
  289. else
  290. $sql_extra = " AND `blocked` = 0 ";
  291. $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
  292. $tpl = get_markup_template("contacts-top.tpl");
  293. $o .= replace_macros($tpl,array(
  294. '$header' => t('Contacts'),
  295. '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
  296. '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
  297. '$search' => $search,
  298. '$desc' => t('Search your contacts'),
  299. '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
  300. '$submit' => t('Find'),
  301. '$cmd' => $a->cmd
  302. ));
  303. if($search)
  304. $search = dbesc($search.'*');
  305. $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
  306. $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
  307. $r = q("SELECT COUNT(*) AS `total` FROM `contact`
  308. WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
  309. intval($_SESSION['uid']));
  310. if(count($r))
  311. $a->set_pager_total($r[0]['total']);
  312. $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
  313. intval($_SESSION['uid']),
  314. intval($a->pager['start']),
  315. intval($a->pager['itemspage'])
  316. );
  317. if(count($r)) {
  318. $tpl = get_markup_template("contact_template.tpl");
  319. foreach($r as $rr) {
  320. if($rr['self'])
  321. continue;
  322. switch($rr['rel']) {
  323. case CONTACT_IS_FRIEND:
  324. $dir_icon = 'images/lrarrow.gif';
  325. $alt_text = t('Mutual Friendship');
  326. break;
  327. case CONTACT_IS_FOLLOWER;
  328. $dir_icon = 'images/larrow.gif';
  329. $alt_text = t('is a fan of yours');
  330. break;
  331. case CONTACT_IS_SHARING;
  332. $dir_icon = 'images/rarrow.gif';
  333. $alt_text = t('you are a fan of');
  334. break;
  335. default:
  336. break;
  337. }
  338. if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
  339. $url = "redir/{$rr['id']}";
  340. $sparkle = ' class="sparkle" ';
  341. }
  342. else {
  343. $url = $rr['url'];
  344. $sparkle = '';
  345. }
  346. $o .= replace_macros($tpl, array(
  347. '$img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
  348. '$edit_hover' => t('Edit contact'),
  349. '$contact_photo_menu' => contact_photo_menu($rr),
  350. '$id' => $rr['id'],
  351. '$alt_text' => $alt_text,
  352. '$dir_icon' => $dir_icon,
  353. '$thumb' => $rr['thumb'],
  354. '$name' => $rr['name'],
  355. '$username' => $rr['name'],
  356. '$sparkle' => $sparkle,
  357. '$url' => $url
  358. ));
  359. }
  360. $o .= '<div id="contact-edit-end"></div>';
  361. }
  362. $o .= paginate($a);
  363. return $o;
  364. }