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\Strings;
22 use Friendica\Util\XML;
27 * Return the follow widget
29 * @param string $value optional, default empty
31 public static function follow($value = "")
33 return Renderer::replaceMacros(Renderer::getMarkupTemplate('follow.tpl'), array(
34 '$connect' => L10n::t('Add New Contact'),
35 '$desc' => L10n::t('Enter address or web location'),
36 '$hint' => L10n::t('Example: bob@example.com, http://example.com/barbara'),
38 '$follow' => L10n::t('Connect')
43 * Return Find People widget
45 public static function findPeople()
48 $global_dir = Config::get('system', 'directory');
50 if (Config::get('system', 'invitation_only')) {
51 $x = PConfig::get(local_user(), 'system', 'invites_remaining');
52 if ($x || is_site_admin()) {
53 $a->page['aside'] .= '<div class="side-link widget" id="side-invite-remain">'
54 . L10n::tt('%d invitation available', '%d invitations available', $x)
60 $nv['findpeople'] = L10n::t('Find People');
61 $nv['desc'] = L10n::t('Enter name or interest');
62 $nv['label'] = L10n::t('Connect/Follow');
63 $nv['hint'] = L10n::t('Examples: Robert Morgenstein, Fishing');
64 $nv['findthem'] = L10n::t('Find');
65 $nv['suggest'] = L10n::t('Friend Suggestions');
66 $nv['similar'] = L10n::t('Similar Interests');
67 $nv['random'] = L10n::t('Random Profile');
68 $nv['inv'] = L10n::t('Invite Friends');
69 $nv['directory'] = L10n::t('Global Directory');
70 $nv['global_dir'] = $global_dir;
71 $nv['local_directory'] = L10n::t('Local Directory');
76 return Renderer::replaceMacros(Renderer::getMarkupTemplate('peoplefind.tpl'), $aside);
80 * Return unavailable networks
82 public static function unavailableNetworks()
84 // Always hide content from these networks
85 $networks = ['face', 'apdn'];
87 if (!Addon::isEnabled("statusnet")) {
88 $networks[] = Protocol::STATUSNET;
91 if (!Addon::isEnabled("pumpio")) {
92 $networks[] = Protocol::PUMPIO;
95 if (!Addon::isEnabled("twitter")) {
96 $networks[] = Protocol::TWITTER;
99 if (Config::get("system", "ostatus_disabled")) {
100 $networks[] = Protocol::OSTATUS;
103 if (!Config::get("system", "diaspora_enabled")) {
104 $networks[] = Protocol::DIASPORA;
107 if (!Addon::isEnabled("pnut")) {
108 $networks[] = Protocol::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 $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
150 if (count($nets) < 2) {
154 return Renderer::replaceMacros(Renderer::getMarkupTemplate('nets.tpl'), array(
155 '$title' => L10n::t('Protocols'),
157 '$sel_all' => (($selected == '') ? 'selected' : ''),
158 '$all' => L10n::t('All Protocols'),
165 * Return file as widget
167 * @param string $baseurl baseurl
168 * @param string $selected optional, default empty
170 public static function fileAs($baseurl, $selected = '')
176 $saved = PConfig::get(local_user(), 'system', 'filetags');
177 if (!strlen($saved)) {
183 $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
185 foreach ($matches as $mtch)
187 $unescaped = XML::escape(FileTag::decode($mtch[1]));
188 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
192 return Renderer::replaceMacros(Renderer::getMarkupTemplate('fileas_widget.tpl'), array(
193 '$title' => L10n::t('Saved Folders'),
195 '$sel_all' => (($selected == '') ? 'selected' : ''),
196 '$all' => L10n::t('Everything'),
203 * Return categories widget
205 * @param string $baseurl baseurl
206 * @param string $selected optional, default empty
208 public static function categories($baseurl, $selected = '')
212 if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
216 $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
217 if (!strlen($saved)) {
223 $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
226 foreach ($matches as $mtch) {
227 $unescaped = XML::escape(FileTag::decode($mtch[1]));
228 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
232 return Renderer::replaceMacros(Renderer::getMarkupTemplate('categories_widget.tpl'), array(
233 '$title' => L10n::t('Categories'),
235 '$sel_all' => (($selected == '') ? 'selected' : ''),
236 '$all' => L10n::t('Everything'),
243 * Return common friends visitor widget
245 * @param string $profile_uid uid
247 public static function commonFriendsVisitor($profile_uid)
249 if (local_user() == $profile_uid) {
255 if (!empty($_SESSION['remote'])) {
256 foreach ($_SESSION['remote'] as $visitor) {
257 if ($visitor['uid'] == $profile_uid) {
258 $cid = $visitor['cid'];
265 if (Profile::getMyURL()) {
266 $contact = DBA::selectFirst('contact', ['id'],
267 ['nurl' => Strings::normaliseLink(Profile::getMyURL()), 'uid' => $profile_uid]);
268 if (DBA::isResult($contact)) {
269 $cid = $contact['id'];
271 $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(Profile::getMyURL())]);
272 if (DBA::isResult($gcontact)) {
273 $zcid = $gcontact['id'];
279 if ($cid == 0 && $zcid == 0) {
284 $t = GContact::countCommonFriends($profile_uid, $cid);
286 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
294 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
296 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
299 return Renderer::replaceMacros(Renderer::getMarkupTemplate('remote_friends_common.tpl'), array(
300 '$desc' => L10n::tt("%d contact in common", "%d contacts in common", $t),
301 '$base' => System::baseUrl(),
302 '$uid' => $profile_uid,
303 '$cid' => (($cid) ? $cid : '0'),
304 '$linkmore' => (($t > 5) ? 'true' : ''),
305 '$more' => L10n::t('show more'),
311 * Insert a tag cloud widget for the present profile.
313 * @brief Insert a tag cloud widget for the present profile.
314 * @param int $limit Max number of displayed tags.
315 * @return string HTML formatted output.
317 public static function tagCloud($limit = 50)
321 if (!$a->profile['profile_uid'] || !$a->profile['url']) {
325 if (Feature::isEnabled($a->profile['profile_uid'], 'tagadelic')) {
326 $owner_id = Contact::getIdForURL($a->profile['url'], 0, true);
331 return Widget\TagCloud::getHTML($a->profile['profile_uid'], $limit, $owner_id, 'wall');