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;
13 function follow_widget($value = "")
15 return replace_macros(get_markup_template('follow.tpl'), array(
16 '$connect' => t('Add New Contact'),
17 '$desc' => t('Enter address or web location'),
18 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
20 '$follow' => t('Connect')
24 function findpeople_widget()
27 $global_dir = Config::get('system', 'directory');
29 if (Config::get('system', 'invitation_only')) {
30 $x = PConfig::get(local_user(), 'system', 'invites_remaining');
31 if ($x || is_site_admin()) {
32 $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
33 . tt('%d invitation available', '%d invitations available', $x)
38 return replace_macros(get_markup_template('peoplefind.tpl'), array(
39 '$findpeople' => t('Find People'),
40 '$desc' => t('Enter name or interest'),
41 '$label' => t('Connect/Follow'),
42 '$hint' => t('Examples: Robert Morgenstein, Fishing'),
43 '$findthem' => t('Find'),
44 '$suggest' => t('Friend Suggestions'),
45 '$similar' => t('Similar Interests'),
46 '$random' => t('Random Profile'),
47 '$inv' => t('Invite Friends'),
48 '$directory' => t('View Global Directory'),
49 '$global_dir' => $global_dir
53 function unavailable_networks()
57 if (!plugin_enabled("appnet")) {
58 $networks[] = NETWORK_APPNET;
61 if (!plugin_enabled("fbpost") && !plugin_enabled("facebook")) {
62 $networks[] = NETWORK_FACEBOOK;
65 if (!plugin_enabled("statusnet")) {
66 $networks[] = NETWORK_STATUSNET;
69 if (!plugin_enabled("pumpio")) {
70 $networks[] = NETWORK_PUMPIO;
73 if (!plugin_enabled("twitter")) {
74 $networks[] = NETWORK_TWITTER;
77 if (Config::get("system", "ostatus_disabled")) {
78 $networks[] = NETWORK_OSTATUS;
81 if (!Config::get("system", "diaspora_enabled")) {
82 $networks[] = NETWORK_DIASPORA;
85 if (!plugin_enabled("pnut")) {
86 $networks[] = NETWORK_PNUT;
89 if (!sizeof($networks)) {
93 $network_filter = implode("','", $networks);
95 $network_filter = "AND `network` NOT IN ('$network_filter')";
97 return $network_filter;
100 function networks_widget($baseurl, $selected = '')
106 if (!Feature::isEnabled(local_user(), 'networks')) {
110 $extra_sql = unavailable_networks();
112 $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
117 while ($rr = dba::fetch($r)) {
118 /// @TODO If 'network' is not there, this triggers an E_NOTICE
119 if ($rr['network']) {
120 $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
125 if (count($nets) < 2) {
129 return replace_macros(get_markup_template('nets.tpl'), array(
130 '$title' => t('Networks'),
132 '$sel_all' => (($selected == '') ? 'selected' : ''),
133 '$all' => t('All Networks'),
139 function fileas_widget($baseurl, $selected = '')
145 if (!Feature::isEnabled(local_user(), 'filing')) {
149 $saved = PConfig::get(local_user(), 'system', 'filetags');
150 if (!strlen($saved)) {
156 $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
158 foreach ($matches as $mtch) {
159 $unescaped = xmlify(file_tag_decode($mtch[1]));
160 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
164 return replace_macros(get_markup_template('fileas_widget.tpl'), array(
165 '$title' => t('Saved Folders'),
167 '$sel_all' => (($selected == '') ? 'selected' : ''),
168 '$all' => t('Everything'),
174 function categories_widget($baseurl, $selected = '')
178 if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
182 $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
183 if (!strlen($saved)) {
189 $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
192 foreach ($matches as $mtch) {
193 $unescaped = xmlify(file_tag_decode($mtch[1]));
194 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
198 return replace_macros(get_markup_template('categories_widget.tpl'), array(
199 '$title' => t('Categories'),
201 '$sel_all' => (($selected == '') ? 'selected' : ''),
202 '$all' => t('Everything'),
208 function common_friends_visitor_widget($profile_uid)
210 if (local_user() == $profile_uid) {
216 if (is_array($_SESSION['remote'])) {
217 foreach ($_SESSION['remote'] as $visitor) {
218 if ($visitor['uid'] == $profile_uid) {
219 $cid = $visitor['cid'];
227 $r = dba::selectFirst('contact', ['id'],
228 ['nurl' => normalise_link(get_my_url()), 'uid' => $profile_uid]);
229 if (DBM::is_result($r)) {
232 $r = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(get_my_url())]);
233 if (DBM::is_result($r)) {
240 if ($cid == 0 && $zcid == 0) {
245 $t = GContact::countCommonFriends($profile_uid, $cid);
247 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
255 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
257 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
260 return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
261 '$desc' => tt("%d contact in common", "%d contacts in common", $t),
262 '$base' => System::baseUrl(),
263 '$uid' => $profile_uid,
264 '$cid' => (($cid) ? $cid : '0'),
265 '$linkmore' => (($t > 5) ? 'true' : ''),
266 '$more' => t('show more'),