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;
23 require_once 'boot.php';
24 require_once 'include/dba.php';
29 * Return the follow widget
31 * @param string $value optional, default empty
33 public static function follow($value = "")
35 return Renderer::replaceMacros(Renderer::getMarkupTemplate('follow.tpl'), array(
36 '$connect' => L10n::t('Add New Contact'),
37 '$desc' => L10n::t('Enter address or web location'),
38 '$hint' => L10n::t('Example: bob@example.com, http://example.com/barbara'),
40 '$follow' => L10n::t('Connect')
45 * Return Find People widget
47 public static function findPeople()
50 $global_dir = Config::get('system', 'directory');
52 if (Config::get('system', 'invitation_only')) {
53 $x = PConfig::get(local_user(), 'system', 'invites_remaining');
54 if ($x || is_site_admin()) {
55 $a->page['aside'] .= '<div class="side-link widget" id="side-invite-remain">'
56 . L10n::tt('%d invitation available', '%d invitations available', $x)
62 $nv['findpeople'] = L10n::t('Find People');
63 $nv['desc'] = L10n::t('Enter name or interest');
64 $nv['label'] = L10n::t('Connect/Follow');
65 $nv['hint'] = L10n::t('Examples: Robert Morgenstein, Fishing');
66 $nv['findthem'] = L10n::t('Find');
67 $nv['suggest'] = L10n::t('Friend Suggestions');
68 $nv['similar'] = L10n::t('Similar Interests');
69 $nv['random'] = L10n::t('Random Profile');
70 $nv['inv'] = L10n::t('Invite Friends');
71 $nv['directory'] = L10n::t('Global Directory');
72 $nv['global_dir'] = $global_dir;
73 $nv['local_directory'] = L10n::t('Local Directory');
78 return Renderer::replaceMacros(Renderer::getMarkupTemplate('peoplefind.tpl'), $aside);
82 * Return unavailable networks
84 public static function unavailableNetworks()
86 // Always hide content from these networks
87 $networks = ['face', 'apdn'];
89 if (!Addon::isEnabled("statusnet")) {
90 $networks[] = Protocol::STATUSNET;
93 if (!Addon::isEnabled("pumpio")) {
94 $networks[] = Protocol::PUMPIO;
97 if (!Addon::isEnabled("twitter")) {
98 $networks[] = Protocol::TWITTER;
101 if (Config::get("system", "ostatus_disabled")) {
102 $networks[] = Protocol::OSTATUS;
105 if (!Config::get("system", "diaspora_enabled")) {
106 $networks[] = Protocol::DIASPORA;
109 if (!Addon::isEnabled("pnut")) {
110 $networks[] = Protocol::PNUT;
113 if (!sizeof($networks)) {
117 $network_filter = implode("','", $networks);
119 $network_filter = "AND `network` NOT IN ('$network_filter')";
121 return $network_filter;
125 * Return networks widget
127 * @param string $baseurl baseurl
128 * @param string $selected optional, default empty
130 public static function networks($baseurl, $selected = '')
136 if (!Feature::isEnabled(local_user(), 'networks')) {
140 $extra_sql = self::unavailableNetworks();
142 $r = DBA::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
147 while ($rr = DBA::fetch($r)) {
148 $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
152 if (count($nets) < 2) {
156 return Renderer::replaceMacros(Renderer::getMarkupTemplate('nets.tpl'), array(
157 '$title' => L10n::t('Networks'),
159 '$sel_all' => (($selected == '') ? 'selected' : ''),
160 '$all' => L10n::t('All Networks'),
167 * Return file as widget
169 * @param string $baseurl baseurl
170 * @param string $selected optional, default empty
172 public static function fileAs($baseurl, $selected = '')
178 if (!Feature::isEnabled(local_user(), 'filing')) {
182 $saved = PConfig::get(local_user(), 'system', 'filetags');
183 if (!strlen($saved)) {
189 $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
191 foreach ($matches as $mtch)
193 $unescaped = Strings::escape(FileTag::decode($mtch[1]));
194 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
198 return Renderer::replaceMacros(Renderer::getMarkupTemplate('fileas_widget.tpl'), array(
199 '$title' => L10n::t('Saved Folders'),
201 '$sel_all' => (($selected == '') ? 'selected' : ''),
202 '$all' => L10n::t('Everything'),
209 * Return categories widget
211 * @param string $baseurl baseurl
212 * @param string $selected optional, default empty
214 public static function categories($baseurl, $selected = '')
218 if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
222 $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
223 if (!strlen($saved)) {
229 $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
232 foreach ($matches as $mtch) {
233 $unescaped = Strings::escape(FileTag::decode($mtch[1]));
234 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
238 return Renderer::replaceMacros(Renderer::getMarkupTemplate('categories_widget.tpl'), array(
239 '$title' => L10n::t('Categories'),
241 '$sel_all' => (($selected == '') ? 'selected' : ''),
242 '$all' => L10n::t('Everything'),
249 * Return common friends visitor widget
251 * @param string $profile_uid uid
253 public static function commonFriendsVisitor($profile_uid)
255 if (local_user() == $profile_uid) {
261 if (!empty($_SESSION['remote'])) {
262 foreach ($_SESSION['remote'] as $visitor) {
263 if ($visitor['uid'] == $profile_uid) {
264 $cid = $visitor['cid'];
271 if (Profile::getMyURL()) {
272 $contact = DBA::selectFirst('contact', ['id'],
273 ['nurl' => normalise_link(Profile::getMyURL()), 'uid' => $profile_uid]);
274 if (DBA::isResult($contact)) {
275 $cid = $contact['id'];
277 $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Profile::getMyURL())]);
278 if (DBA::isResult($gcontact)) {
279 $zcid = $gcontact['id'];
285 if ($cid == 0 && $zcid == 0) {
290 $t = GContact::countCommonFriends($profile_uid, $cid);
292 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
300 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
302 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
305 return Renderer::replaceMacros(Renderer::getMarkupTemplate('remote_friends_common.tpl'), array(
306 '$desc' => L10n::tt("%d contact in common", "%d contacts in common", $t),
307 '$base' => System::baseUrl(),
308 '$uid' => $profile_uid,
309 '$cid' => (($cid) ? $cid : '0'),
310 '$linkmore' => (($t > 5) ? 'true' : ''),
311 '$more' => L10n::t('show more'),
317 * Insert a tag cloud widget for the present profile.
319 * @brief Insert a tag cloud widget for the present profile.
320 * @param int $limit Max number of displayed tags.
321 * @return string HTML formatted output.
323 public static function tagCloud($limit = 50)
327 if (!$a->profile['profile_uid'] || !$a->profile['url']) {
331 if (Feature::isEnabled($a->profile['profile_uid'], 'tagadelic')) {
332 $owner_id = Contact::getIdForURL($a->profile['url'], 0, true);
337 return Widget\TagCloud::getHTML($a->profile['profile_uid'], $limit, $owner_id, 'wall');