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.

246 lines
5.8 KiB

9 years ago
9 years ago
  1. <?php
  2. function follow_widget($value = "") {
  3. return replace_macros(get_markup_template('follow.tpl'),array(
  4. '$connect' => t('Add New Contact'),
  5. '$desc' => t('Enter address or web location'),
  6. '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
  7. '$value' => $value,
  8. '$follow' => t('Connect')
  9. ));
  10. }
  11. function findpeople_widget() {
  12. require_once('include/Contact.php');
  13. $a = get_app();
  14. if(get_config('system','invitation_only')) {
  15. $x = get_pconfig(local_user(),'system','invites_remaining');
  16. if($x || is_site_admin()) {
  17. $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
  18. . sprintf( tt('%d invitation available','%d invitations available',$x), $x)
  19. . '</div>' . $inv;
  20. }
  21. }
  22. return replace_macros(get_markup_template('peoplefind.tpl'),array(
  23. '$findpeople' => t('Find People'),
  24. '$desc' => t('Enter name or interest'),
  25. '$label' => t('Connect/Follow'),
  26. '$hint' => t('Examples: Robert Morgenstein, Fishing'),
  27. '$findthem' => t('Find'),
  28. '$suggest' => t('Friend Suggestions'),
  29. '$similar' => t('Similar Interests'),
  30. '$random' => t('Random Profile'),
  31. '$inv' => t('Invite Friends')
  32. ));
  33. }
  34. function unavailable_networks() {
  35. $network_filter = "";
  36. $networks = array();
  37. if (!plugin_enabled("appnet"))
  38. $networks[] = NETWORK_APPNET;
  39. if (!plugin_enabled("fbpost") AND !plugin_enabled("facebook"))
  40. $networks[] = NETWORK_FACEBOOK;
  41. if (!plugin_enabled("statusnet"))
  42. $networks[] = NETWORK_STATUSNET;
  43. if (!plugin_enabled("pumpio"))
  44. $networks[] = NETWORK_PUMPIO;
  45. if (!plugin_enabled("twitter"))
  46. $networks[] = NETWORK_TWITTER;
  47. if (get_config("system","ostatus_disabled"))
  48. $networks[] = NETWORK_OSTATUS;
  49. if (!get_config("system","diaspora_enabled"))
  50. $networks[] = NETWORK_DIASPORA;
  51. if (!sizeof($networks))
  52. return "";
  53. $network_filter = implode("','", $networks);
  54. $network_filter = "AND `network` NOT IN ('$network_filter')";
  55. return $network_filter;
  56. }
  57. function networks_widget($baseurl,$selected = '') {
  58. $a = get_app();
  59. if(!local_user())
  60. return '';
  61. if(!feature_enabled(local_user(),'networks'))
  62. return '';
  63. $extra_sql = unavailable_networks();
  64. $r = q("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = %d AND NOT `self` $extra_sql ORDER BY `network`",
  65. intval(local_user())
  66. );
  67. $nets = array();
  68. if(count($r)) {
  69. require_once('include/contact_selectors.php');
  70. foreach($r as $rr) {
  71. if($rr['network'])
  72. $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
  73. }
  74. }
  75. if(count($nets) < 2)
  76. return '';
  77. return replace_macros(get_markup_template('nets.tpl'),array(
  78. '$title' => t('Networks'),
  79. '$desc' => '',
  80. '$sel_all' => (($selected == '') ? 'selected' : ''),
  81. '$all' => t('All Networks'),
  82. '$nets' => $nets,
  83. '$base' => $baseurl,
  84. ));
  85. }
  86. function fileas_widget($baseurl,$selected = '') {
  87. $a = get_app();
  88. if(! local_user())
  89. return '';
  90. if(! feature_enabled(local_user(),'filing'))
  91. return '';
  92. $saved = get_pconfig(local_user(),'system','filetags');
  93. if(! strlen($saved))
  94. return;
  95. $matches = false;
  96. $terms = array();
  97. $cnt = preg_match_all('/\[(.*?)\]/',$saved,$matches,PREG_SET_ORDER);
  98. if($cnt) {
  99. foreach($matches as $mtch) {
  100. $unescaped = xmlify(file_tag_decode($mtch[1]));
  101. $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : ''));
  102. }
  103. }
  104. return replace_macros(get_markup_template('fileas_widget.tpl'),array(
  105. '$title' => t('Saved Folders'),
  106. '$desc' => '',
  107. '$sel_all' => (($selected == '') ? 'selected' : ''),
  108. '$all' => t('Everything'),
  109. '$terms' => $terms,
  110. '$base' => $baseurl,
  111. ));
  112. }
  113. function categories_widget($baseurl,$selected = '') {
  114. $a = get_app();
  115. if(! feature_enabled($a->profile['profile_uid'],'categories'))
  116. return '';
  117. $saved = get_pconfig($a->profile['profile_uid'],'system','filetags');
  118. if(! strlen($saved))
  119. return;
  120. $matches = false;
  121. $terms = array();
  122. $cnt = preg_match_all('/<(.*?)>/',$saved,$matches,PREG_SET_ORDER);
  123. if($cnt) {
  124. foreach($matches as $mtch) {
  125. $unescaped = xmlify(file_tag_decode($mtch[1]));
  126. $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : ''));
  127. }
  128. }
  129. return replace_macros(get_markup_template('categories_widget.tpl'),array(
  130. '$title' => t('Categories'),
  131. '$desc' => '',
  132. '$sel_all' => (($selected == '') ? 'selected' : ''),
  133. '$all' => t('Everything'),
  134. '$terms' => $terms,
  135. '$base' => $baseurl,
  136. ));
  137. }
  138. function common_friends_visitor_widget($profile_uid) {
  139. $a = get_app();
  140. if(local_user() == $profile_uid)
  141. return;
  142. $cid = $zcid = 0;
  143. if(is_array($_SESSION['remote'])) {
  144. foreach($_SESSION['remote'] as $visitor) {
  145. if($visitor['uid'] == $profile_uid) {
  146. $cid = $visitor['cid'];
  147. break;
  148. }
  149. }
  150. }
  151. if(! $cid) {
  152. if(get_my_url()) {
  153. $r = q("select id from contact where nurl = '%s' and uid = %d limit 1",
  154. dbesc(normalise_link(get_my_url())),
  155. intval($profile_uid)
  156. );
  157. if(count($r))
  158. $cid = $r[0]['id'];
  159. else {
  160. $r = q("select id from gcontact where nurl = '%s' limit 1",
  161. dbesc(normalise_link(get_my_url()))
  162. );
  163. if(count($r))
  164. $zcid = $r[0]['id'];
  165. }
  166. }
  167. }
  168. if($cid == 0 && $zcid == 0)
  169. return;
  170. require_once('include/socgraph.php');
  171. if($cid)
  172. $t = count_common_friends($profile_uid,$cid);
  173. else
  174. $t = count_common_friends_zcid($profile_uid,$zcid);
  175. if(! $t)
  176. return;
  177. if($cid)
  178. $r = common_friends($profile_uid,$cid,0,5,true);
  179. else
  180. $r = common_friends_zcid($profile_uid,$zcid,0,5,true);
  181. return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
  182. '$desc' => sprintf( tt("%d contact in common", "%d contacts in common", $t), $t),
  183. '$base' => $a->get_baseurl(),
  184. '$uid' => $profile_uid,
  185. '$cid' => (($cid) ? $cid : '0'),
  186. '$linkmore' => (($t > 5) ? 'true' : ''),
  187. '$more' => t('show more'),
  188. '$items' => $r
  189. ));
  190. };