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.

439 lines
13 KiB

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