3 * @file src/Content/Widget.php
5 namespace Friendica\Content;
7 use Friendica\Content\ContactSelector;
8 use Friendica\Content\Feature;
9 use Friendica\Core\Addon;
10 use Friendica\Core\Config;
11 use Friendica\Core\L10n;
12 use Friendica\Core\PConfig;
13 use Friendica\Core\System;
14 use Friendica\Database\DBM;
15 use Friendica\Model\GContact;
16 use Friendica\Model\Profile;
20 require_once 'boot.php';
25 * Return the follow widget
27 * @param string $value optional, default empty
29 public static function follow($value = "")
31 return replace_macros(get_markup_template('follow.tpl'), array(
32 '$connect' => L10n::t('Add New Contact'),
33 '$desc' => L10n::t('Enter address or web location'),
34 '$hint' => L10n::t('Example: bob@example.com, http://example.com/barbara'),
36 '$follow' => L10n::t('Connect')
41 * Return Find People widget
43 public static function findPeople()
46 $global_dir = Config::get('system', 'directory');
48 if (Config::get('system', 'invitation_only')) {
49 $x = PConfig::get(local_user(), 'system', 'invites_remaining');
50 if ($x || is_site_admin()) {
51 $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
52 . L10n::tt('%d invitation available', '%d invitations available', $x)
57 return replace_macros(get_markup_template('peoplefind.tpl'), array(
58 '$findpeople' => L10n::t('Find People'),
59 '$desc' => L10n::t('Enter name or interest'),
60 '$label' => L10n::t('Connect/Follow'),
61 '$hint' => L10n::t('Examples: Robert Morgenstein, Fishing'),
62 '$findthem' => L10n::t('Find'),
63 '$suggest' => L10n::t('Friend Suggestions'),
64 '$similar' => L10n::t('Similar Interests'),
65 '$random' => L10n::t('Random Profile'),
66 '$inv' => L10n::t('Invite Friends'),
67 '$directory' => L10n::t('View Global Directory'),
68 '$global_dir' => $global_dir
73 * Return unavailable networks
75 public static function unavailableNetworks()
79 if (!Addon::isEnabled("appnet")) {
80 $networks[] = NETWORK_APPNET;
83 if (!Addon::isEnabled("fbpost") && !Addon::isEnabled("facebook")) {
84 $networks[] = NETWORK_FACEBOOK;
87 if (!Addon::isEnabled("statusnet")) {
88 $networks[] = NETWORK_STATUSNET;
91 if (!Addon::isEnabled("pumpio")) {
92 $networks[] = NETWORK_PUMPIO;
95 if (!Addon::isEnabled("twitter")) {
96 $networks[] = NETWORK_TWITTER;
99 if (Config::get("system", "ostatus_disabled")) {
100 $networks[] = NETWORK_OSTATUS;
103 if (!Config::get("system", "diaspora_enabled")) {
104 $networks[] = NETWORK_DIASPORA;
107 if (!Addon::isEnabled("pnut")) {
108 $networks[] = NETWORK_PNUT;
111 if (!sizeof($networks)) {
115 $network_filter = implode("','", $networks);
117 $network_filter = "AND `network` NOT IN ('$network_filter')";
119 return $network_filter;
123 * Return networks widget
125 * @param string $baseurl baseurl
126 * @param string $selected optional, default empty
128 public static function networks($baseurl, $selected = '')
134 if (!Feature::isEnabled(local_user(), 'networks')) {
138 $extra_sql = self::unavailableNetworks();
140 $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
145 while ($rr = dba::fetch($r)) {
146 /// @TODO If 'network' is not there, this triggers an E_NOTICE
147 if ($rr['network']) {
148 $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
153 if (count($nets) < 2) {
157 return replace_macros(get_markup_template('nets.tpl'), array(
158 '$title' => L10n::t('Networks'),
160 '$sel_all' => (($selected == '') ? 'selected' : ''),
161 '$all' => L10n::t('All Networks'),
168 * Return file as widget
170 * @param string $baseurl baseurl
171 * @param string $selected optional, default empty
173 public static function fileAs($baseurl, $selected = '')
179 if (!Feature::isEnabled(local_user(), 'filing')) {
183 $saved = PConfig::get(local_user(), 'system', 'filetags');
184 if (!strlen($saved)) {
190 $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('fileas_widget.tpl'), array(
199 '$title' => L10n::t('Saved Folders'),
201 '$sel_all' => (($selected == '') ? 'selected' : ''),
202 '$all' => L10n::t('Everything'),
209 * Return categories widget
211 * @param string $baseurl baseurl
212 * @param string $selected optional, default empty
214 public static function categories($baseurl, $selected = '')
218 if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
222 $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
223 if (!strlen($saved)) {
229 $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
232 foreach ($matches as $mtch) {
233 $unescaped = xmlify(file_tag_decode($mtch[1]));
234 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
238 return replace_macros(get_markup_template('categories_widget.tpl'), array(
239 '$title' => L10n::t('Categories'),
241 '$sel_all' => (($selected == '') ? 'selected' : ''),
242 '$all' => L10n::t('Everything'),
249 * Return common friends visitor widget
251 * @param string $profile_uid uid
253 public static function commonFriendsVisitor($profile_uid)
255 if (local_user() == $profile_uid) {
261 if (is_array($_SESSION['remote'])) {
262 foreach ($_SESSION['remote'] as $visitor) {
263 if ($visitor['uid'] == $profile_uid) {
264 $cid = $visitor['cid'];
271 if (Profile::getMyURL()) {
272 $contact = dba::selectFirst('contact', ['id'],
273 ['nurl' => normalise_link(Profile::getMyURL()), 'uid' => $profile_uid]);
274 if (DBM::is_result($contact)) {
275 $cid = $contact['id'];
277 $gcontact = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Profile::getMyURL())]);
278 if (DBM::is_result($gcontact)) {
279 $zcid = $gcontact['id'];
285 if ($cid == 0 && $zcid == 0) {
290 $t = GContact::countCommonFriends($profile_uid, $cid);
292 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
300 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
302 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
305 return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
306 '$desc' => L10n::tt("%d contact in common", "%d contacts in common", $t),
307 '$base' => System::baseUrl(),
308 '$uid' => $profile_uid,
309 '$cid' => (($cid) ? $cid : '0'),
310 '$linkmore' => (($t > 5) ? 'true' : ''),
311 '$more' => L10n::t('show more'),