3 * @file include/contact_widgets.php
5 use Friendica\Content\Feature;
6 use Friendica\Core\System;
7 use Friendica\Core\Config;
8 use Friendica\Core\PConfig;
9 use Friendica\Database\DBM;
10 use Friendica\Model\GContact;
12 require_once 'include/contact_selectors.php';
14 function follow_widget($value = "") {
16 return replace_macros(get_markup_template('follow.tpl'), array(
17 '$connect' => t('Add New Contact'),
18 '$desc' => t('Enter address or web location'),
19 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
21 '$follow' => t('Connect')
26 function findpeople_widget() {
28 $global_dir = Config::get('system', 'directory');
30 if (Config::get('system', 'invitation_only')) {
31 $x = PConfig::get(local_user(), 'system', 'invites_remaining');
32 if ($x || is_site_admin()) {
33 $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
34 . sprintf( tt('%d invitation available', '%d invitations available', $x), $x)
39 return replace_macros(get_markup_template('peoplefind.tpl'), array(
40 '$findpeople' => t('Find People'),
41 '$desc' => t('Enter name or interest'),
42 '$label' => t('Connect/Follow'),
43 '$hint' => t('Examples: Robert Morgenstein, Fishing'),
44 '$findthem' => t('Find'),
45 '$suggest' => t('Friend Suggestions'),
46 '$similar' => t('Similar Interests'),
47 '$random' => t('Random Profile'),
48 '$inv' => t('Invite Friends'),
49 '$directory' => t('View Global Directory'),
50 '$global_dir' => $global_dir
55 function unavailable_networks() {
60 if (!plugin_enabled("appnet")) {
61 $networks[] = NETWORK_APPNET;
64 if (!plugin_enabled("fbpost") && !plugin_enabled("facebook")) {
65 $networks[] = NETWORK_FACEBOOK;
68 if (!plugin_enabled("statusnet")) {
69 $networks[] = NETWORK_STATUSNET;
72 if (!plugin_enabled("pumpio")) {
73 $networks[] = NETWORK_PUMPIO;
76 if (!plugin_enabled("twitter")) {
77 $networks[] = NETWORK_TWITTER;
80 if (Config::get("system", "ostatus_disabled")) {
81 $networks[] = NETWORK_OSTATUS;
84 if (!Config::get("system", "diaspora_enabled")) {
85 $networks[] = NETWORK_DIASPORA;
88 if (!plugin_enabled("pnut")) {
89 $networks[] = NETWORK_PNUT;
92 if (!sizeof($networks)) {
96 $network_filter = implode("','", $networks);
98 $network_filter = "AND `network` NOT IN ('$network_filter')";
100 return $network_filter;
103 function networks_widget($baseurl, $selected = '') {
111 if (!Feature::isEnabled(local_user(), 'networks')) {
115 $extra_sql = unavailable_networks();
117 $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
122 while ($rr = dba::fetch($r)) {
123 /// @TODO If 'network' is not there, this triggers an E_NOTICE
124 if ($rr['network']) {
125 $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
130 if (count($nets) < 2) {
134 return replace_macros(get_markup_template('nets.tpl'), array(
135 '$title' => t('Networks'),
137 '$sel_all' => (($selected == '') ? 'selected' : ''),
138 '$all' => t('All Networks'),
145 function fileas_widget($baseurl, $selected = '') {
146 if (! local_user()) {
150 if (! Feature::isEnabled(local_user(), 'filing')) {
154 $saved = PConfig::get(local_user(), 'system', 'filetags');
155 if (! strlen($saved)) {
161 $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
163 foreach ($matches as $mtch) {
164 $unescaped = xmlify(file_tag_decode($mtch[1]));
165 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
169 return replace_macros(get_markup_template('fileas_widget.tpl'), array(
170 '$title' => t('Saved Folders'),
172 '$sel_all' => (($selected == '') ? 'selected' : ''),
173 '$all' => t('Everything'),
180 function categories_widget($baseurl, $selected = '') {
184 if (! Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
188 $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
189 if (! strlen($saved)) {
195 $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
198 foreach ($matches as $mtch) {
199 $unescaped = xmlify(file_tag_decode($mtch[1]));
200 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
204 return replace_macros(get_markup_template('categories_widget.tpl'), array(
205 '$title' => t('Categories'),
207 '$sel_all' => (($selected == '') ? 'selected' : ''),
208 '$all' => t('Everything'),
215 function common_friends_visitor_widget($profile_uid) {
219 if (local_user() == $profile_uid) {
225 if (is_array($_SESSION['remote'])) {
226 foreach ($_SESSION['remote'] as $visitor) {
227 if ($visitor['uid'] == $profile_uid) {
228 $cid = $visitor['cid'];
236 $r = dba::select('contact', array('id'),
237 array('nurl' => normalise_link(get_my_url()), 'uid' => $profile_uid), array('limit' => 1));
238 if (DBM::is_result($r)) {
241 $r = dba::select('gcontact', array('id'), array('nurl' => normalise_link(get_my_url())), array('limit' => 1));
242 if (DBM::is_result($r))
248 if ($cid == 0 && $zcid == 0) {
253 $t = GContact::countCommonFriends($profile_uid, $cid);
255 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
262 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
264 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
267 return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
268 '$desc' => sprintf(tt("%d contact in common", "%d contacts in common", $t), $t),
269 '$base' => System::baseUrl(),
270 '$uid' => $profile_uid,
271 '$cid' => (($cid) ? $cid : '0'),
272 '$linkmore' => (($t > 5) ? 'true' : ''),
273 '$more' => t('show more'),