4 use Friendica\Core\System;
5 use Friendica\Core\Config;
6 use Friendica\Core\PConfig;
7 use Friendica\Database\DBM;
9 require_once 'include/contact_selectors.php';
11 function follow_widget($value = "") {
13 return replace_macros(get_markup_template('follow.tpl'), array(
14 '$connect' => t('Add New Contact'),
15 '$desc' => t('Enter address or web location'),
16 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
18 '$follow' => t('Connect')
23 function findpeople_widget() {
24 require_once 'include/Contact.php';
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 . sprintf( tt('%d invitation available', '%d invitations available', $x), $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
54 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 = '') {
110 if (!feature_enabled(local_user(), 'networks')) {
114 $extra_sql = unavailable_networks();
116 $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
121 while ($rr = dba::fetch($r)) {
122 /// @TODO If 'network' is not there, this triggers an E_NOTICE
123 if ($rr['network']) {
124 $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
129 if (count($nets) < 2) {
133 return replace_macros(get_markup_template('nets.tpl'), array(
134 '$title' => t('Networks'),
136 '$sel_all' => (($selected == '') ? 'selected' : ''),
137 '$all' => t('All Networks'),
144 function fileas_widget($baseurl, $selected = '') {
145 if (! local_user()) {
149 if (! feature_enabled(local_user(), 'filing')) {
153 $saved = PConfig::get(local_user(), 'system', 'filetags');
154 if (! strlen($saved)) {
160 $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
162 foreach ($matches as $mtch) {
163 $unescaped = xmlify(file_tag_decode($mtch[1]));
164 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
168 return replace_macros(get_markup_template('fileas_widget.tpl'), array(
169 '$title' => t('Saved Folders'),
171 '$sel_all' => (($selected == '') ? 'selected' : ''),
172 '$all' => t('Everything'),
179 function categories_widget($baseurl, $selected = '') {
183 if (! feature_enabled($a->profile['profile_uid'], 'categories')) {
187 $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
188 if (! strlen($saved)) {
194 $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
197 foreach ($matches as $mtch) {
198 $unescaped = xmlify(file_tag_decode($mtch[1]));
199 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
203 return replace_macros(get_markup_template('categories_widget.tpl'), array(
204 '$title' => t('Categories'),
206 '$sel_all' => (($selected == '') ? 'selected' : ''),
207 '$all' => t('Everything'),
214 function common_friends_visitor_widget($profile_uid) {
218 if (local_user() == $profile_uid) {
224 if (is_array($_SESSION['remote'])) {
225 foreach ($_SESSION['remote'] as $visitor) {
226 if ($visitor['uid'] == $profile_uid) {
227 $cid = $visitor['cid'];
235 $r = dba::select('contact', array('id'),
236 array('nurl' => normalise_link(get_my_url()), 'uid' => $profile_uid), array('limit' => 1));
237 if (DBM::is_result($r)) {
240 $r = dba::select('gcontact', array('id'), array('nurl' => normalise_link(get_my_url())), array('limit' => 1));
241 if (DBM::is_result($r))
247 if ($cid == 0 && $zcid == 0) {
251 require_once 'include/socgraph.php';
254 $t = count_common_friends($profile_uid, $cid);
256 $t = count_common_friends_zcid($profile_uid, $zcid);
263 $r = common_friends($profile_uid, $cid, 0, 5, true);
265 $r = common_friends_zcid($profile_uid, $zcid, 0, 5, true);
268 return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
269 '$desc' => sprintf( tt("%d contact in common", "%d contacts in common", $t), $t),
270 '$base' => System::baseUrl(),
271 '$uid' => $profile_uid,
272 '$cid' => (($cid) ? $cid : '0'),
273 '$linkmore' => (($t > 5) ? 'true' : ''),
274 '$more' => t('show more'),