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\DBA;
15 use Friendica\Model\Contact;
16 use Friendica\Model\GContact;
17 use Friendica\Model\Profile;
19 require_once 'boot.php';
20 require_once 'include/dba.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)
58 $nv['findpeople'] = L10n::t('Find People');
59 $nv['desc'] = L10n::t('Enter name or interest');
60 $nv['label'] = L10n::t('Connect/Follow');
61 $nv['hint'] = L10n::t('Examples: Robert Morgenstein, Fishing');
62 $nv['findthem'] = L10n::t('Find');
63 $nv['suggest'] = L10n::t('Friend Suggestions');
64 $nv['similar'] = L10n::t('Similar Interests');
65 $nv['random'] = L10n::t('Random Profile');
66 $nv['inv'] = L10n::t('Invite Friends');
67 $nv['directory'] = L10n::t('Global Directory');
68 $nv['global_dir'] = $global_dir;
69 $nv['local_directory'] = L10n::t('Local Directory');
74 return replace_macros(get_markup_template('peoplefind.tpl'), $aside);
78 * Return unavailable networks
80 public static function unavailableNetworks()
84 if (!Addon::isEnabled("statusnet")) {
85 $networks[] = NETWORK_STATUSNET;
88 if (!Addon::isEnabled("pumpio")) {
89 $networks[] = NETWORK_PUMPIO;
92 if (!Addon::isEnabled("twitter")) {
93 $networks[] = NETWORK_TWITTER;
96 if (Config::get("system", "ostatus_disabled")) {
97 $networks[] = NETWORK_OSTATUS;
100 if (!Config::get("system", "diaspora_enabled")) {
101 $networks[] = NETWORK_DIASPORA;
104 if (!Addon::isEnabled("pnut")) {
105 $networks[] = NETWORK_PNUT;
108 if (!sizeof($networks)) {
112 $network_filter = implode("','", $networks);
114 $network_filter = "AND `network` NOT IN ('$network_filter')";
116 return $network_filter;
120 * Return networks widget
122 * @param string $baseurl baseurl
123 * @param string $selected optional, default empty
125 public static function networks($baseurl, $selected = '')
131 if (!Feature::isEnabled(local_user(), 'networks')) {
135 $extra_sql = self::unavailableNetworks();
137 $r = DBA::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
142 while ($rr = DBA::fetch($r)) {
143 /// @TODO If 'network' is not there, this triggers an E_NOTICE
144 if ($rr['network']) {
145 $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) {
190 $unescaped = xmlify(file_tag_decode($mtch[1]));
191 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
195 return replace_macros(get_markup_template('fileas_widget.tpl'), array(
196 '$title' => L10n::t('Saved Folders'),
198 '$sel_all' => (($selected == '') ? 'selected' : ''),
199 '$all' => L10n::t('Everything'),
206 * Return categories widget
208 * @param string $baseurl baseurl
209 * @param string $selected optional, default empty
211 public static function categories($baseurl, $selected = '')
215 if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
219 $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
220 if (!strlen($saved)) {
226 $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
229 foreach ($matches as $mtch) {
230 $unescaped = xmlify(file_tag_decode($mtch[1]));
231 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
235 return replace_macros(get_markup_template('categories_widget.tpl'), array(
236 '$title' => L10n::t('Categories'),
238 '$sel_all' => (($selected == '') ? 'selected' : ''),
239 '$all' => L10n::t('Everything'),
246 * Return common friends visitor widget
248 * @param string $profile_uid uid
250 public static function commonFriendsVisitor($profile_uid)
252 if (local_user() == $profile_uid) {
258 if (!empty($_SESSION['remote'])) {
259 foreach ($_SESSION['remote'] as $visitor) {
260 if ($visitor['uid'] == $profile_uid) {
261 $cid = $visitor['cid'];
268 if (Profile::getMyURL()) {
269 $contact = DBA::selectFirst('contact', ['id'],
270 ['nurl' => normalise_link(Profile::getMyURL()), 'uid' => $profile_uid]);
271 if (DBA::isResult($contact)) {
272 $cid = $contact['id'];
274 $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Profile::getMyURL())]);
275 if (DBA::isResult($gcontact)) {
276 $zcid = $gcontact['id'];
282 if ($cid == 0 && $zcid == 0) {
287 $t = GContact::countCommonFriends($profile_uid, $cid);
289 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
297 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
299 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
302 return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
303 '$desc' => L10n::tt("%d contact in common", "%d contacts in common", $t),
304 '$base' => System::baseUrl(),
305 '$uid' => $profile_uid,
306 '$cid' => (($cid) ? $cid : '0'),
307 '$linkmore' => (($t > 5) ? 'true' : ''),
308 '$more' => L10n::t('show more'),
314 * Insert a tag cloud widget for the present profile.
316 * @brief Insert a tag cloud widget for the present profile.
317 * @param int $limit Max number of displayed tags.
318 * @return string HTML formatted output.
320 public static function tagCloud($limit = 50)
324 if (!$a->profile['profile_uid'] || !$a->profile['url']) {
328 if (Feature::isEnabled($a->profile['profile_uid'], 'tagadelic')) {
329 $owner_id = Contact::getIdForURL($a->profile['url'], 0, true);
334 return Widget\TagCloud::getHTML($a->profile['profile_uid'], $limit, $owner_id, 'wall');