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\System;
15 use Friendica\Database\DBA;
16 use Friendica\Model\Contact;
17 use Friendica\Model\FileTag;
18 use Friendica\Model\GContact;
19 use Friendica\Model\Profile;
21 require_once 'boot.php';
22 require_once 'include/dba.php';
27 * Return the follow widget
29 * @param string $value optional, default empty
31 public static function follow($value = "")
33 return replace_macros(get_markup_template('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 replace_macros(get_markup_template('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 replace_macros(get_markup_template('nets.tpl'), array(
155 '$title' => L10n::t('Networks'),
157 '$sel_all' => (($selected == '') ? 'selected' : ''),
158 '$all' => L10n::t('All Networks'),
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 if (!Feature::isEnabled(local_user(), 'filing')) {
180 $saved = PConfig::get(local_user(), 'system', 'filetags');
181 if (!strlen($saved)) {
187 $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
189 foreach ($matches as $mtch)
191 $unescaped = xmlify(FileTag::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' => L10n::t('Saved Folders'),
199 '$sel_all' => (($selected == '') ? 'selected' : ''),
200 '$all' => L10n::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(FileTag::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' => L10n::t('Categories'),
239 '$sel_all' => (($selected == '') ? 'selected' : ''),
240 '$all' => L10n::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 (!empty($_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 (DBA::isResult($contact)) {
273 $cid = $contact['id'];
275 $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Profile::getMyURL())]);
276 if (DBA::isResult($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' => L10n::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' => L10n::t('show more'),
315 * Insert a tag cloud widget for the present profile.
317 * @brief Insert a tag cloud widget for the present profile.
318 * @param int $limit Max number of displayed tags.
319 * @return string HTML formatted output.
321 public static function tagCloud($limit = 50)
325 if (!$a->profile['profile_uid'] || !$a->profile['url']) {
329 if (Feature::isEnabled($a->profile['profile_uid'], 'tagadelic')) {
330 $owner_id = Contact::getIdForURL($a->profile['url'], 0, true);
335 return Widget\TagCloud::getHTML($a->profile['profile_uid'], $limit, $owner_id, 'wall');