4 * @file include/contact_widgets.php
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 require_once 'include/contact_selectors.php';
15 function follow_widget($value = "")
17 return replace_macros(get_markup_template('follow.tpl'), array(
18 '$connect' => t('Add New Contact'),
19 '$desc' => t('Enter address or web location'),
20 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
22 '$follow' => t('Connect')
26 function findpeople_widget()
29 $global_dir = Config::get('system', 'directory');
31 if (Config::get('system', 'invitation_only')) {
32 $x = PConfig::get(local_user(), 'system', 'invites_remaining');
33 if ($x || is_site_admin()) {
34 $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
35 . tt('%d invitation available', '%d invitations available', $x)
40 return replace_macros(get_markup_template('peoplefind.tpl'), array(
41 '$findpeople' => t('Find People'),
42 '$desc' => t('Enter name or interest'),
43 '$label' => t('Connect/Follow'),
44 '$hint' => t('Examples: Robert Morgenstein, Fishing'),
45 '$findthem' => t('Find'),
46 '$suggest' => t('Friend Suggestions'),
47 '$similar' => t('Similar Interests'),
48 '$random' => t('Random Profile'),
49 '$inv' => t('Invite Friends'),
50 '$directory' => t('View Global Directory'),
51 '$global_dir' => $global_dir
55 function unavailable_networks()
59 if (!plugin_enabled("appnet")) {
60 $networks[] = NETWORK_APPNET;
63 if (!plugin_enabled("fbpost") && !plugin_enabled("facebook")) {
64 $networks[] = NETWORK_FACEBOOK;
67 if (!plugin_enabled("statusnet")) {
68 $networks[] = NETWORK_STATUSNET;
71 if (!plugin_enabled("pumpio")) {
72 $networks[] = NETWORK_PUMPIO;
75 if (!plugin_enabled("twitter")) {
76 $networks[] = NETWORK_TWITTER;
79 if (Config::get("system", "ostatus_disabled")) {
80 $networks[] = NETWORK_OSTATUS;
83 if (!Config::get("system", "diaspora_enabled")) {
84 $networks[] = NETWORK_DIASPORA;
87 if (!plugin_enabled("pnut")) {
88 $networks[] = NETWORK_PNUT;
91 if (!sizeof($networks)) {
95 $network_filter = implode("','", $networks);
97 $network_filter = "AND `network` NOT IN ('$network_filter')";
99 return $network_filter;
102 function networks_widget($baseurl, $selected = '')
108 if (!Feature::isEnabled(local_user(), 'networks')) {
112 $extra_sql = unavailable_networks();
114 $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
119 while ($rr = dba::fetch($r)) {
120 /// @TODO If 'network' is not there, this triggers an E_NOTICE
121 if ($rr['network']) {
122 $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
127 if (count($nets) < 2) {
131 return replace_macros(get_markup_template('nets.tpl'), array(
132 '$title' => t('Networks'),
134 '$sel_all' => (($selected == '') ? 'selected' : ''),
135 '$all' => t('All Networks'),
141 function fileas_widget($baseurl, $selected = '')
147 if (!Feature::isEnabled(local_user(), 'filing')) {
151 $saved = PConfig::get(local_user(), 'system', 'filetags');
152 if (!strlen($saved)) {
158 $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
160 foreach ($matches as $mtch) {
161 $unescaped = xmlify(file_tag_decode($mtch[1]));
162 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
166 return replace_macros(get_markup_template('fileas_widget.tpl'), array(
167 '$title' => t('Saved Folders'),
169 '$sel_all' => (($selected == '') ? 'selected' : ''),
170 '$all' => t('Everything'),
176 function categories_widget($baseurl, $selected = '')
180 if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
184 $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
185 if (!strlen($saved)) {
191 $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
194 foreach ($matches as $mtch) {
195 $unescaped = xmlify(file_tag_decode($mtch[1]));
196 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
200 return replace_macros(get_markup_template('categories_widget.tpl'), array(
201 '$title' => t('Categories'),
203 '$sel_all' => (($selected == '') ? 'selected' : ''),
204 '$all' => t('Everything'),
210 function common_friends_visitor_widget($profile_uid)
212 if (local_user() == $profile_uid) {
218 if (is_array($_SESSION['remote'])) {
219 foreach ($_SESSION['remote'] as $visitor) {
220 if ($visitor['uid'] == $profile_uid) {
221 $cid = $visitor['cid'];
229 $r = dba::select('contact', array('id'),
230 array('nurl' => normalise_link(get_my_url()), 'uid' => $profile_uid), array('limit' => 1));
231 if (DBM::is_result($r)) {
234 $r = dba::select('gcontact', array('id'), array('nurl' => normalise_link(get_my_url())), array('limit' => 1));
235 if (DBM::is_result($r)) {
242 if ($cid == 0 && $zcid == 0) {
247 $t = GContact::countCommonFriends($profile_uid, $cid);
249 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
257 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
259 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
262 return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
263 '$desc' => tt("%d contact in common", "%d contacts in common", $t),
264 '$base' => System::baseUrl(),
265 '$uid' => $profile_uid,
266 '$cid' => (($cid) ? $cid : '0'),
267 '$linkmore' => (($t > 5) ? 'true' : ''),
268 '$more' => t('show more'),