4 use Friendica\Core\System;
5 use Friendica\Core\Config;
6 use Friendica\Core\PConfig;
8 require_once 'include/contact_selectors.php';
10 function follow_widget($value = "") {
12 return replace_macros(get_markup_template('follow.tpl'), array(
13 '$connect' => t('Add New Contact'),
14 '$desc' => t('Enter address or web location'),
15 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
17 '$follow' => t('Connect')
22 function findpeople_widget() {
23 require_once 'include/Contact.php';
26 $global_dir = Config::get('system', 'directory');
28 if (Config::get('system', 'invitation_only')) {
29 $x = PConfig::get(local_user(), 'system', 'invites_remaining');
30 if ($x || is_site_admin()) {
31 $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
32 . sprintf( tt('%d invitation available', '%d invitations available', $x), $x)
37 return replace_macros(get_markup_template('peoplefind.tpl'), array(
38 '$findpeople' => t('Find People'),
39 '$desc' => t('Enter name or interest'),
40 '$label' => t('Connect/Follow'),
41 '$hint' => t('Examples: Robert Morgenstein, Fishing'),
42 '$findthem' => t('Find'),
43 '$suggest' => t('Friend Suggestions'),
44 '$similar' => t('Similar Interests'),
45 '$random' => t('Random Profile'),
46 '$inv' => t('Invite Friends'),
47 '$directory' => t('View Global Directory'),
48 '$global_dir' => $global_dir
53 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 = '') {
109 if (!feature_enabled(local_user(), 'networks')) {
113 $extra_sql = unavailable_networks();
115 $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
120 while ($rr = dba::fetch($r)) {
121 /// @TODO If 'network' is not there, this triggers an E_NOTICE
122 if ($rr['network']) {
123 $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
128 if (count($nets) < 2) {
132 return replace_macros(get_markup_template('nets.tpl'), array(
133 '$title' => t('Networks'),
135 '$sel_all' => (($selected == '') ? 'selected' : ''),
136 '$all' => t('All Networks'),
143 function fileas_widget($baseurl, $selected = '') {
144 if (! local_user()) {
148 if (! feature_enabled(local_user(), 'filing')) {
152 $saved = PConfig::get(local_user(), 'system', 'filetags');
153 if (! strlen($saved)) {
159 $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
161 foreach ($matches as $mtch) {
162 $unescaped = xmlify(file_tag_decode($mtch[1]));
163 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
167 return replace_macros(get_markup_template('fileas_widget.tpl'), array(
168 '$title' => t('Saved Folders'),
170 '$sel_all' => (($selected == '') ? 'selected' : ''),
171 '$all' => t('Everything'),
178 function categories_widget($baseurl, $selected = '') {
182 if (! feature_enabled($a->profile['profile_uid'], 'categories')) {
186 $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
187 if (! strlen($saved)) {
193 $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
196 foreach ($matches as $mtch) {
197 $unescaped = xmlify(file_tag_decode($mtch[1]));
198 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
202 return replace_macros(get_markup_template('categories_widget.tpl'), array(
203 '$title' => t('Categories'),
205 '$sel_all' => (($selected == '') ? 'selected' : ''),
206 '$all' => t('Everything'),
213 function common_friends_visitor_widget($profile_uid) {
217 if (local_user() == $profile_uid) {
223 if (is_array($_SESSION['remote'])) {
224 foreach ($_SESSION['remote'] as $visitor) {
225 if ($visitor['uid'] == $profile_uid) {
226 $cid = $visitor['cid'];
234 $r = dba::select('contact', array('id'),
235 array('nurl' => normalise_link(get_my_url()), 'uid' => $profile_uid), array('limit' => 1));
236 if (dbm::is_result($r)) {
239 $r = dba::select('gcontact', array('id'), array('nurl' => normalise_link(get_my_url())), array('limit' => 1));
240 if (dbm::is_result($r))
246 if ($cid == 0 && $zcid == 0) {
250 require_once 'include/socgraph.php';
253 $t = count_common_friends($profile_uid, $cid);
255 $t = count_common_friends_zcid($profile_uid, $zcid);
262 $r = common_friends($profile_uid, $cid, 0, 5, true);
264 $r = common_friends_zcid($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'),