3 * @file src/Content/Widget.php
5 namespace Friendica\Content;
7 use Friendica\Content\ContactSelector;
8 use Friendica\Content\Feature;
9 use Friendica\Core\Config;
10 use Friendica\Core\PConfig;
11 use Friendica\Core\System;
12 use Friendica\Database\DBM;
13 use Friendica\Model\GContact;
14 use Friendica\Model\Profile;
18 require_once 'boot.php';
23 * Return the follow widget
25 * @param string $value optional, default empty
27 public static function follow($value = "")
29 return replace_macros(get_markup_template('follow.tpl'), array(
30 '$connect' => t('Add New Contact'),
31 '$desc' => t('Enter address or web location'),
32 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
34 '$follow' => t('Connect')
39 * Return Find People widget
41 public static function findPeople()
44 $global_dir = Config::get('system', 'directory');
46 if (Config::get('system', 'invitation_only')) {
47 $x = PConfig::get(local_user(), 'system', 'invites_remaining');
48 if ($x || is_site_admin()) {
49 $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
50 . tt('%d invitation available', '%d invitations available', $x)
55 return replace_macros(get_markup_template('peoplefind.tpl'), array(
56 '$findpeople' => t('Find People'),
57 '$desc' => t('Enter name or interest'),
58 '$label' => t('Connect/Follow'),
59 '$hint' => t('Examples: Robert Morgenstein, Fishing'),
60 '$findthem' => t('Find'),
61 '$suggest' => t('Friend Suggestions'),
62 '$similar' => t('Similar Interests'),
63 '$random' => t('Random Profile'),
64 '$inv' => t('Invite Friends'),
65 '$directory' => t('View Global Directory'),
66 '$global_dir' => $global_dir
71 * Return unavailable networks
73 public static function unavailableNetworks()
77 if (!plugin_enabled("appnet")) {
78 $networks[] = NETWORK_APPNET;
81 if (!plugin_enabled("fbpost") && !plugin_enabled("facebook")) {
82 $networks[] = NETWORK_FACEBOOK;
85 if (!plugin_enabled("statusnet")) {
86 $networks[] = NETWORK_STATUSNET;
89 if (!plugin_enabled("pumpio")) {
90 $networks[] = NETWORK_PUMPIO;
93 if (!plugin_enabled("twitter")) {
94 $networks[] = NETWORK_TWITTER;
97 if (Config::get("system", "ostatus_disabled")) {
98 $networks[] = NETWORK_OSTATUS;
101 if (!Config::get("system", "diaspora_enabled")) {
102 $networks[] = NETWORK_DIASPORA;
105 if (!plugin_enabled("pnut")) {
106 $networks[] = NETWORK_PNUT;
109 if (!sizeof($networks)) {
113 $network_filter = implode("','", $networks);
115 $network_filter = "AND `network` NOT IN ('$network_filter')";
117 return $network_filter;
121 * Return networks widget
123 * @param string $baseurl baseurl
124 * @param string $selected optional, default empty
126 public static function networks($baseurl, $selected = '')
132 if (!Feature::isEnabled(local_user(), 'networks')) {
136 $extra_sql = self::unavailableNetworks();
138 $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
143 while ($rr = dba::fetch($r)) {
144 /// @TODO If 'network' is not there, this triggers an E_NOTICE
145 if ($rr['network']) {
146 $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
151 if (count($nets) < 2) {
155 return replace_macros(get_markup_template('nets.tpl'), array(
156 '$title' => t('Networks'),
158 '$sel_all' => (($selected == '') ? 'selected' : ''),
159 '$all' => t('All Networks'),
166 * Return file as widget
168 * @param string $baseurl baseurl
169 * @param string $selected optional, default empty
171 public static function fileAs($baseurl, $selected = '')
177 if (!Feature::isEnabled(local_user(), 'filing')) {
181 $saved = PConfig::get(local_user(), 'system', 'filetags');
182 if (!strlen($saved)) {
188 $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
190 foreach ($matches as $mtch) {
191 $unescaped = xmlify(file_tag_decode($mtch[1]));
192 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
196 return replace_macros(get_markup_template('fileas_widget.tpl'), array(
197 '$title' => t('Saved Folders'),
199 '$sel_all' => (($selected == '') ? 'selected' : ''),
200 '$all' => t('Everything'),
207 * Return categories widget
209 * @param string $baseurl baseurl
210 * @param string $selected optional, default empty
212 public static function categories($baseurl, $selected = '')
216 if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
220 $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
221 if (!strlen($saved)) {
227 $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
230 foreach ($matches as $mtch) {
231 $unescaped = xmlify(file_tag_decode($mtch[1]));
232 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
236 return replace_macros(get_markup_template('categories_widget.tpl'), array(
237 '$title' => t('Categories'),
239 '$sel_all' => (($selected == '') ? 'selected' : ''),
240 '$all' => t('Everything'),
247 * Return common friends visitor widget
249 * @param string $profile_uid uid
251 public static function commonFriendsVisitor($profile_uid)
253 if (local_user() == $profile_uid) {
259 if (is_array($_SESSION['remote'])) {
260 foreach ($_SESSION['remote'] as $visitor) {
261 if ($visitor['uid'] == $profile_uid) {
262 $cid = $visitor['cid'];
269 if (Profile::getMyURL()) {
270 $contact = dba::selectFirst('contact', ['id'],
271 ['nurl' => normalise_link(Profile::getMyURL()), 'uid' => $profile_uid]);
272 if (DBM::is_result($contact)) {
273 $cid = $contact['id'];
275 $gcontact = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Profile::getMyURL())]);
276 if (DBM::is_result($gcontact)) {
277 $zcid = $gcontact['id'];
283 if ($cid == 0 && $zcid == 0) {
288 $t = GContact::countCommonFriends($profile_uid, $cid);
290 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
298 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
300 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
303 return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
304 '$desc' => tt("%d contact in common", "%d contacts in common", $t),
305 '$base' => System::baseUrl(),
306 '$uid' => $profile_uid,
307 '$cid' => (($cid) ? $cid : '0'),
308 '$linkmore' => (($t > 5) ? 'true' : ''),
309 '$more' => t('show more'),