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.

279 lines
6.4KB

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