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("appnet")) {
85 $networks[] = NETWORK_APPNET;
88 if (!Addon::isEnabled("fbpost") && !Addon::isEnabled("facebook")) {
89 $networks[] = NETWORK_FACEBOOK;
92 if (!Addon::isEnabled("statusnet")) {
93 $networks[] = NETWORK_STATUSNET;
96 if (!Addon::isEnabled("pumpio")) {
97 $networks[] = NETWORK_PUMPIO;
100 if (!Addon::isEnabled("twitter")) {
101 $networks[] = NETWORK_TWITTER;
104 if (Config::get("system", "ostatus_disabled")) {
105 $networks[] = NETWORK_OSTATUS;
108 if (!Config::get("system", "diaspora_enabled")) {
109 $networks[] = NETWORK_DIASPORA;
112 if (!Addon::isEnabled("pnut")) {
113 $networks[] = NETWORK_PNUT;
116 if (!sizeof($networks)) {
120 $network_filter = implode("','", $networks);
122 $network_filter = "AND `network` NOT IN ('$network_filter')";
124 return $network_filter;
128 * Return networks widget
130 * @param string $baseurl baseurl
131 * @param string $selected optional, default empty
133 public static function networks($baseurl, $selected = '')
139 if (!Feature::isEnabled(local_user(), 'networks')) {
143 $extra_sql = self::unavailableNetworks();
145 $r = DBA::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
150 while ($rr = DBA::fetch($r)) {
151 /// @TODO If 'network' is not there, this triggers an E_NOTICE
152 if ($rr['network']) {
153 $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
158 if (count($nets) < 2) {
162 return replace_macros(get_markup_template('nets.tpl'), array(
163 '$title' => L10n::t('Networks'),
165 '$sel_all' => (($selected == '') ? 'selected' : ''),
166 '$all' => L10n::t('All Networks'),
173 * Return file as widget
175 * @param string $baseurl baseurl
176 * @param string $selected optional, default empty
178 public static function fileAs($baseurl, $selected = '')
184 if (!Feature::isEnabled(local_user(), 'filing')) {
188 $saved = PConfig::get(local_user(), 'system', 'filetags');
189 if (!strlen($saved)) {
195 $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
197 foreach ($matches as $mtch) {
198 $unescaped = xmlify(file_tag_decode($mtch[1]));
199 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
203 return replace_macros(get_markup_template('fileas_widget.tpl'), array(
204 '$title' => L10n::t('Saved Folders'),
206 '$sel_all' => (($selected == '') ? 'selected' : ''),
207 '$all' => L10n::t('Everything'),
214 * Return categories widget
216 * @param string $baseurl baseurl
217 * @param string $selected optional, default empty
219 public static function categories($baseurl, $selected = '')
223 if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
227 $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
228 if (!strlen($saved)) {
234 $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
237 foreach ($matches as $mtch) {
238 $unescaped = xmlify(file_tag_decode($mtch[1]));
239 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
243 return replace_macros(get_markup_template('categories_widget.tpl'), array(
244 '$title' => L10n::t('Categories'),
246 '$sel_all' => (($selected == '') ? 'selected' : ''),
247 '$all' => L10n::t('Everything'),
254 * Return common friends visitor widget
256 * @param string $profile_uid uid
258 public static function commonFriendsVisitor($profile_uid)
260 if (local_user() == $profile_uid) {
266 if (!empty($_SESSION['remote'])) {
267 foreach ($_SESSION['remote'] as $visitor) {
268 if ($visitor['uid'] == $profile_uid) {
269 $cid = $visitor['cid'];
276 if (Profile::getMyURL()) {
277 $contact = DBA::selectFirst('contact', ['id'],
278 ['nurl' => normalise_link(Profile::getMyURL()), 'uid' => $profile_uid]);
279 if (DBA::isResult($contact)) {
280 $cid = $contact['id'];
282 $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Profile::getMyURL())]);
283 if (DBA::isResult($gcontact)) {
284 $zcid = $gcontact['id'];
290 if ($cid == 0 && $zcid == 0) {
295 $t = GContact::countCommonFriends($profile_uid, $cid);
297 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
305 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
307 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
310 return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
311 '$desc' => L10n::tt("%d contact in common", "%d contacts in common", $t),
312 '$base' => System::baseUrl(),
313 '$uid' => $profile_uid,
314 '$cid' => (($cid) ? $cid : '0'),
315 '$linkmore' => (($t > 5) ? 'true' : ''),
316 '$more' => L10n::t('show more'),
322 * Insert a tag cloud widget for the present profile.
324 * @brief Insert a tag cloud widget for the present profile.
325 * @param int $limit Max number of displayed tags.
326 * @return string HTML formatted output.
328 public static function tagCloud($limit = 50)
332 if (!$a->profile['profile_uid'] || !$a->profile['url']) {
336 if (Feature::isEnabled($a->profile['profile_uid'], 'tagadelic')) {
337 $owner_id = Contact::getIdForURL($a->profile['url'], 0, true);
342 return Widget\TagCloud::getHTML($a->profile['profile_uid'], $limit, $owner_id, 'wall');