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\Protocol;
14 use Friendica\Core\Renderer;
15 use Friendica\Core\System;
16 use Friendica\Database\DBA;
17 use Friendica\Model\Contact;
18 use Friendica\Model\FileTag;
19 use Friendica\Model\GContact;
20 use Friendica\Model\Profile;
21 use Friendica\Util\Proxy as ProxyUtils;
22 use Friendica\Util\Strings;
23 use Friendica\Util\XML;
28 * Return the follow widget
30 * @param string $value optional, default empty
32 public static function follow($value = "")
34 return Renderer::replaceMacros(Renderer::getMarkupTemplate('follow.tpl'), array(
35 '$connect' => L10n::t('Add New Contact'),
36 '$desc' => L10n::t('Enter address or web location'),
37 '$hint' => L10n::t('Example: bob@example.com, http://example.com/barbara'),
39 '$follow' => L10n::t('Connect')
44 * Return Find People widget
46 public static function findPeople()
49 $global_dir = Config::get('system', 'directory');
51 if (Config::get('system', 'invitation_only')) {
52 $x = PConfig::get(local_user(), 'system', 'invites_remaining');
53 if ($x || is_site_admin()) {
54 $a->page['aside'] .= '<div class="side-link widget" id="side-invite-remain">'
55 . L10n::tt('%d invitation available', '%d invitations available', $x)
61 $nv['findpeople'] = L10n::t('Find People');
62 $nv['desc'] = L10n::t('Enter name or interest');
63 $nv['label'] = L10n::t('Connect/Follow');
64 $nv['hint'] = L10n::t('Examples: Robert Morgenstein, Fishing');
65 $nv['findthem'] = L10n::t('Find');
66 $nv['suggest'] = L10n::t('Friend Suggestions');
67 $nv['similar'] = L10n::t('Similar Interests');
68 $nv['random'] = L10n::t('Random Profile');
69 $nv['inv'] = L10n::t('Invite Friends');
70 $nv['directory'] = L10n::t('Global Directory');
71 $nv['global_dir'] = $global_dir;
72 $nv['local_directory'] = L10n::t('Local Directory');
77 return Renderer::replaceMacros(Renderer::getMarkupTemplate('peoplefind.tpl'), $aside);
81 * Return unavailable networks
83 public static function unavailableNetworks()
85 // Always hide content from these networks
86 $networks = ['face', 'apdn'];
88 if (!Addon::isEnabled("statusnet")) {
89 $networks[] = Protocol::STATUSNET;
92 if (!Addon::isEnabled("pumpio")) {
93 $networks[] = Protocol::PUMPIO;
96 if (!Addon::isEnabled("twitter")) {
97 $networks[] = Protocol::TWITTER;
100 if (Config::get("system", "ostatus_disabled")) {
101 $networks[] = Protocol::OSTATUS;
104 if (!Config::get("system", "diaspora_enabled")) {
105 $networks[] = Protocol::DIASPORA;
108 if (!Addon::isEnabled("pnut")) {
109 $networks[] = Protocol::PNUT;
112 if (!sizeof($networks)) {
116 $network_filter = implode("','", $networks);
118 $network_filter = "AND `network` NOT IN ('$network_filter')";
120 return $network_filter;
124 * Return networks widget
126 * @param string $baseurl baseurl
127 * @param string $selected optional, default empty
129 public static function networks($baseurl, $selected = '')
135 if (!Feature::isEnabled(local_user(), 'networks')) {
139 $extra_sql = self::unavailableNetworks();
141 $r = DBA::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND NOT `deleted` AND `network` != '' $extra_sql ORDER BY `network`",
146 while ($rr = DBA::fetch($r)) {
147 $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
151 if (count($nets) < 2) {
155 return Renderer::replaceMacros(Renderer::getMarkupTemplate('nets.tpl'), array(
156 '$title' => L10n::t('Protocols'),
158 '$sel_all' => (($selected == '') ? 'selected' : ''),
159 '$all' => L10n::t('All Protocols'),
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 $saved = PConfig::get(local_user(), 'system', 'filetags');
178 if (!strlen($saved)) {
184 $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
186 foreach ($matches as $mtch)
188 $unescaped = XML::escape(FileTag::decode($mtch[1]));
189 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
193 return Renderer::replaceMacros(Renderer::getMarkupTemplate('fileas_widget.tpl'), array(
194 '$title' => L10n::t('Saved Folders'),
196 '$sel_all' => (($selected == '') ? 'selected' : ''),
197 '$all' => L10n::t('Everything'),
204 * Return categories widget
206 * @param string $baseurl baseurl
207 * @param string $selected optional, default empty
209 public static function categories($baseurl, $selected = '')
213 if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
217 $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
218 if (!strlen($saved)) {
224 $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
227 foreach ($matches as $mtch) {
228 $unescaped = XML::escape(FileTag::decode($mtch[1]));
229 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
233 return Renderer::replaceMacros(Renderer::getMarkupTemplate('categories_widget.tpl'), array(
234 '$title' => L10n::t('Categories'),
236 '$sel_all' => (($selected == '') ? 'selected' : ''),
237 '$all' => L10n::t('Everything'),
244 * Return common friends visitor widget
246 * @param string $profile_uid uid
248 public static function commonFriendsVisitor($profile_uid)
250 if (local_user() == $profile_uid) {
256 if (!empty($_SESSION['remote'])) {
257 foreach ($_SESSION['remote'] as $visitor) {
258 if ($visitor['uid'] == $profile_uid) {
259 $cid = $visitor['cid'];
266 if (Profile::getMyURL()) {
267 $contact = DBA::selectFirst('contact', ['id'],
268 ['nurl' => Strings::normaliseLink(Profile::getMyURL()), 'uid' => $profile_uid]);
269 if (DBA::isResult($contact)) {
270 $cid = $contact['id'];
272 $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(Profile::getMyURL())]);
273 if (DBA::isResult($gcontact)) {
274 $zcid = $gcontact['id'];
280 if ($cid == 0 && $zcid == 0) {
285 $t = GContact::countCommonFriends($profile_uid, $cid);
287 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
295 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
297 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
300 if (!DBA::isResult($r)) {
305 foreach ($r as $rr) {
307 'url' => Contact::magicLink($rr['url']),
308 'name' => $rr['name'],
309 'photo' => ProxyUtils::proxifyUrl($rr['photo'], false, ProxyUtils::SIZE_THUMB),
314 $tpl = Renderer::getMarkupTemplate('remote_friends_common.tpl');
315 return Renderer::replaceMacros($tpl, [
316 '$desc' => L10n::tt("%d contact in common", "%d contacts in common", $t),
317 '$base' => System::baseUrl(),
318 '$uid' => $profile_uid,
319 '$cid' => (($cid) ? $cid : '0'),
320 '$linkmore' => (($t > 5) ? 'true' : ''),
321 '$more' => L10n::t('show more'),
327 * Insert a tag cloud widget for the present profile.
329 * @brief Insert a tag cloud widget for the present profile.
330 * @param int $limit Max number of displayed tags.
331 * @return string HTML formatted output.
333 public static function tagCloud($limit = 50)
337 if (!$a->profile['profile_uid'] || !$a->profile['url']) {
341 if (Feature::isEnabled($a->profile['profile_uid'], 'tagadelic')) {
342 $owner_id = Contact::getIdForURL($a->profile['url'], 0, true);
347 return Widget\TagCloud::getHTML($a->profile['profile_uid'], $limit, $owner_id, 'wall');