3 * @file include/contact_widgets.php
5 use Friendica\Content\ContactSelector;
6 use Friendica\Content\Feature;
7 use Friendica\Core\System;
8 use Friendica\Core\Config;
9 use Friendica\Core\PConfig;
10 use Friendica\Database\DBM;
11 use Friendica\Model\GContact;
12 use Friendica\Model\Profile;
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')
25 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 . tt('%d invitation available', '%d invitations available', $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
54 function unavailable_networks()
58 if (!plugin_enabled("appnet")) {
59 $networks[] = NETWORK_APPNET;
62 if (!plugin_enabled("fbpost") && !plugin_enabled("facebook")) {
63 $networks[] = NETWORK_FACEBOOK;
66 if (!plugin_enabled("statusnet")) {
67 $networks[] = NETWORK_STATUSNET;
70 if (!plugin_enabled("pumpio")) {
71 $networks[] = NETWORK_PUMPIO;
74 if (!plugin_enabled("twitter")) {
75 $networks[] = NETWORK_TWITTER;
78 if (Config::get("system", "ostatus_disabled")) {
79 $networks[] = NETWORK_OSTATUS;
82 if (!Config::get("system", "diaspora_enabled")) {
83 $networks[] = NETWORK_DIASPORA;
86 if (!plugin_enabled("pnut")) {
87 $networks[] = NETWORK_PNUT;
90 if (!sizeof($networks)) {
94 $network_filter = implode("','", $networks);
96 $network_filter = "AND `network` NOT IN ('$network_filter')";
98 return $network_filter;
101 function networks_widget($baseurl, $selected = '')
107 if (!Feature::isEnabled(local_user(), 'networks')) {
111 $extra_sql = unavailable_networks();
113 $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
118 while ($rr = dba::fetch($r)) {
119 /// @TODO If 'network' is not there, this triggers an E_NOTICE
120 if ($rr['network']) {
121 $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
126 if (count($nets) < 2) {
130 return replace_macros(get_markup_template('nets.tpl'), array(
131 '$title' => t('Networks'),
133 '$sel_all' => (($selected == '') ? 'selected' : ''),
134 '$all' => t('All Networks'),
140 function fileas_widget($baseurl, $selected = '')
146 if (!Feature::isEnabled(local_user(), 'filing')) {
150 $saved = PConfig::get(local_user(), 'system', 'filetags');
151 if (!strlen($saved)) {
157 $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
159 foreach ($matches as $mtch) {
160 $unescaped = xmlify(file_tag_decode($mtch[1]));
161 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
165 return replace_macros(get_markup_template('fileas_widget.tpl'), array(
166 '$title' => t('Saved Folders'),
168 '$sel_all' => (($selected == '') ? 'selected' : ''),
169 '$all' => t('Everything'),
175 function categories_widget($baseurl, $selected = '')
179 if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
183 $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
184 if (!strlen($saved)) {
190 $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
193 foreach ($matches as $mtch) {
194 $unescaped = xmlify(file_tag_decode($mtch[1]));
195 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
199 return replace_macros(get_markup_template('categories_widget.tpl'), array(
200 '$title' => t('Categories'),
202 '$sel_all' => (($selected == '') ? 'selected' : ''),
203 '$all' => t('Everything'),
209 function common_friends_visitor_widget($profile_uid)
211 if (local_user() == $profile_uid) {
217 if (is_array($_SESSION['remote'])) {
218 foreach ($_SESSION['remote'] as $visitor) {
219 if ($visitor['uid'] == $profile_uid) {
220 $cid = $visitor['cid'];
227 if (Profile::getMyURL()) {
228 $contact = dba::selectFirst('contact', ['id'],
229 ['nurl' => normalise_link(Profile::getMyURL()), 'uid' => $profile_uid]);
230 if (DBM::is_result($contact)) {
231 $cid = $contact['id'];
233 $gcontact = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Profile::getMyURL())]);
234 if (DBM::is_result($gcontact)) {
235 $zcid = $gcontact['id'];
241 if ($cid == 0 && $zcid == 0) {
246 $t = GContact::countCommonFriends($profile_uid, $cid);
248 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
256 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
258 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
261 return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
262 '$desc' => tt("%d contact in common", "%d contacts in common", $t),
263 '$base' => System::baseUrl(),
264 '$uid' => $profile_uid,
265 '$cid' => (($cid) ? $cid : '0'),
266 '$linkmore' => (($t > 5) ? 'true' : ''),
267 '$more' => t('show more'),