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.

257 lines
6.0 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 (!plugin_enabled("pnut"))
  52. $networks[] = NETWORK_PNUT;
  53. if (!sizeof($networks))
  54. return "";
  55. $network_filter = implode("','", $networks);
  56. $network_filter = "AND `network` NOT IN ('$network_filter')";
  57. return $network_filter;
  58. }
  59. function networks_widget($baseurl,$selected = '') {
  60. $a = get_app();
  61. if (!local_user()) {
  62. return '';
  63. }
  64. if (!feature_enabled(local_user(),'networks')) {
  65. return '';
  66. }
  67. $extra_sql = unavailable_networks();
  68. $r = q("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = %d AND `network` != '' $extra_sql ORDER BY `network`",
  69. intval(local_user())
  70. );
  71. $nets = array();
  72. if (dbm::is_result($r)) {
  73. require_once('include/contact_selectors.php');
  74. foreach ($r as $rr) {
  75. /// @TODO If 'network' is not there, this triggers an E_NOTICE
  76. if ($rr['network']) {
  77. $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
  78. }
  79. }
  80. }
  81. if(count($nets) < 2)
  82. return '';
  83. return replace_macros(get_markup_template('nets.tpl'),array(
  84. '$title' => t('Networks'),
  85. '$desc' => '',
  86. '$sel_all' => (($selected == '') ? 'selected' : ''),
  87. '$all' => t('All Networks'),
  88. '$nets' => $nets,
  89. '$base' => $baseurl,
  90. ));
  91. }
  92. function fileas_widget($baseurl,$selected = '') {
  93. if (! local_user()) {
  94. return '';
  95. }
  96. if (! feature_enabled(local_user(),'filing')) {
  97. return '';
  98. }
  99. $saved = get_pconfig(local_user(),'system','filetags');
  100. if (! strlen($saved)) {
  101. return;
  102. }
  103. $matches = false;
  104. $terms = array();
  105. $cnt = preg_match_all('/\[(.*?)\]/',$saved,$matches,PREG_SET_ORDER);
  106. if ($cnt) {
  107. foreach($matches as $mtch) {
  108. $unescaped = xmlify(file_tag_decode($mtch[1]));
  109. $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : ''));
  110. }
  111. }
  112. return replace_macros(get_markup_template('fileas_widget.tpl'),array(
  113. '$title' => t('Saved Folders'),
  114. '$desc' => '',
  115. '$sel_all' => (($selected == '') ? 'selected' : ''),
  116. '$all' => t('Everything'),
  117. '$terms' => $terms,
  118. '$base' => $baseurl,
  119. ));
  120. }
  121. function categories_widget($baseurl,$selected = '') {
  122. $a = get_app();
  123. if (! feature_enabled($a->profile['profile_uid'],'categories')) {
  124. return '';
  125. }
  126. $saved = get_pconfig($a->profile['profile_uid'],'system','filetags');
  127. if (! strlen($saved)) {
  128. return;
  129. }
  130. $matches = false;
  131. $terms = array();
  132. $cnt = preg_match_all('/<(.*?)>/',$saved,$matches,PREG_SET_ORDER);
  133. if($cnt) {
  134. foreach($matches as $mtch) {
  135. $unescaped = xmlify(file_tag_decode($mtch[1]));
  136. $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : ''));
  137. }
  138. }
  139. return replace_macros(get_markup_template('categories_widget.tpl'),array(
  140. '$title' => t('Categories'),
  141. '$desc' => '',
  142. '$sel_all' => (($selected == '') ? 'selected' : ''),
  143. '$all' => t('Everything'),
  144. '$terms' => $terms,
  145. '$base' => $baseurl,
  146. ));
  147. }
  148. function common_friends_visitor_widget($profile_uid) {
  149. $a = get_app();
  150. if(local_user() == $profile_uid)
  151. return;
  152. $cid = $zcid = 0;
  153. if(is_array($_SESSION['remote'])) {
  154. foreach($_SESSION['remote'] as $visitor) {
  155. if($visitor['uid'] == $profile_uid) {
  156. $cid = $visitor['cid'];
  157. break;
  158. }
  159. }
  160. }
  161. if(! $cid) {
  162. if(get_my_url()) {
  163. $r = q("select id from contact where nurl = '%s' and uid = %d limit 1",
  164. dbesc(normalise_link(get_my_url())),
  165. intval($profile_uid)
  166. );
  167. if (dbm::is_result($r))
  168. $cid = $r[0]['id'];
  169. else {
  170. $r = q("select id from gcontact where nurl = '%s' limit 1",
  171. dbesc(normalise_link(get_my_url()))
  172. );
  173. if (dbm::is_result($r))
  174. $zcid = $r[0]['id'];
  175. }
  176. }
  177. }
  178. if($cid == 0 && $zcid == 0)
  179. return;
  180. require_once('include/socgraph.php');
  181. if($cid)
  182. $t = count_common_friends($profile_uid,$cid);
  183. else
  184. $t = count_common_friends_zcid($profile_uid,$zcid);
  185. if(! $t)
  186. return;
  187. if($cid)
  188. $r = common_friends($profile_uid,$cid,0,5,true);
  189. else
  190. $r = common_friends_zcid($profile_uid,$zcid,0,5,true);
  191. return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
  192. '$desc' => sprintf( tt("%d contact in common", "%d contacts in common", $t), $t),
  193. '$base' => App::get_baseurl(),
  194. '$uid' => $profile_uid,
  195. '$cid' => (($cid) ? $cid : '0'),
  196. '$linkmore' => (($t > 5) ? 'true' : ''),
  197. '$more' => t('show more'),
  198. '$items' => $r
  199. ));
  200. };