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\PConfig;
12 use Friendica\Core\System;
13 use Friendica\Database\DBM;
14 use Friendica\Model\GContact;
15 use Friendica\Model\Profile;
19 require_once 'boot.php';
24 * Return the follow widget
26 * @param string $value optional, default empty
28 public static function follow($value = "")
30 return replace_macros(get_markup_template('follow.tpl'), array(
31 '$connect' => t('Add New Contact'),
32 '$desc' => t('Enter address or web location'),
33 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
35 '$follow' => t('Connect')
40 * Return Find People widget
42 public static function findPeople()
45 $global_dir = Config::get('system', 'directory');
47 if (Config::get('system', 'invitation_only')) {
48 $x = PConfig::get(local_user(), 'system', 'invites_remaining');
49 if ($x || is_site_admin()) {
50 $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
51 . tt('%d invitation available', '%d invitations available', $x)
56 return replace_macros(get_markup_template('peoplefind.tpl'), array(
57 '$findpeople' => t('Find People'),
58 '$desc' => t('Enter name or interest'),
59 '$label' => t('Connect/Follow'),
60 '$hint' => t('Examples: Robert Morgenstein, Fishing'),
61 '$findthem' => t('Find'),
62 '$suggest' => t('Friend Suggestions'),
63 '$similar' => t('Similar Interests'),
64 '$random' => t('Random Profile'),
65 '$inv' => t('Invite Friends'),
66 '$directory' => t('View Global Directory'),
67 '$global_dir' => $global_dir
72 * Return unavailable networks
74 public static function unavailableNetworks()
78 if (!Addon::isEnabled("appnet")) {
79 $networks[] = NETWORK_APPNET;
82 if (!Addon::isEnabled("fbpost") && !Addon::isEnabled("facebook")) {
83 $networks[] = NETWORK_FACEBOOK;
86 if (!Addon::isEnabled("statusnet")) {
87 $networks[] = NETWORK_STATUSNET;
90 if (!Addon::isEnabled("pumpio")) {
91 $networks[] = NETWORK_PUMPIO;
94 if (!Addon::isEnabled("twitter")) {
95 $networks[] = NETWORK_TWITTER;
98 if (Config::get("system", "ostatus_disabled")) {
99 $networks[] = NETWORK_OSTATUS;
102 if (!Config::get("system", "diaspora_enabled")) {
103 $networks[] = NETWORK_DIASPORA;
106 if (!Addon::isEnabled("pnut")) {
107 $networks[] = NETWORK_PNUT;
110 if (!sizeof($networks)) {
114 $network_filter = implode("','", $networks);
116 $network_filter = "AND `network` NOT IN ('$network_filter')";
118 return $network_filter;
122 * Return networks widget
124 * @param string $baseurl baseurl
125 * @param string $selected optional, default empty
127 public static function networks($baseurl, $selected = '')
133 if (!Feature::isEnabled(local_user(), 'networks')) {
137 $extra_sql = self::unavailableNetworks();
139 $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
144 while ($rr = dba::fetch($r)) {
145 /// @TODO If 'network' is not there, this triggers an E_NOTICE
146 if ($rr['network']) {
147 $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
152 if (count($nets) < 2) {
156 return replace_macros(get_markup_template('nets.tpl'), array(
157 '$title' => t('Networks'),
159 '$sel_all' => (($selected == '') ? 'selected' : ''),
160 '$all' => 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) {
192 $unescaped = xmlify(file_tag_decode($mtch[1]));
193 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
197 return replace_macros(get_markup_template('fileas_widget.tpl'), array(
198 '$title' => t('Saved Folders'),
200 '$sel_all' => (($selected == '') ? 'selected' : ''),
201 '$all' => t('Everything'),
208 * Return categories widget
210 * @param string $baseurl baseurl
211 * @param string $selected optional, default empty
213 public static function categories($baseurl, $selected = '')
217 if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
221 $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
222 if (!strlen($saved)) {
228 $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
231 foreach ($matches as $mtch) {
232 $unescaped = xmlify(file_tag_decode($mtch[1]));
233 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
237 return replace_macros(get_markup_template('categories_widget.tpl'), array(
238 '$title' => t('Categories'),
240 '$sel_all' => (($selected == '') ? 'selected' : ''),
241 '$all' => t('Everything'),
248 * Return common friends visitor widget
250 * @param string $profile_uid uid
252 public static function commonFriendsVisitor($profile_uid)
254 if (local_user() == $profile_uid) {
260 if (is_array($_SESSION['remote'])) {
261 foreach ($_SESSION['remote'] as $visitor) {
262 if ($visitor['uid'] == $profile_uid) {
263 $cid = $visitor['cid'];
270 if (Profile::getMyURL()) {
271 $contact = dba::selectFirst('contact', ['id'],
272 ['nurl' => normalise_link(Profile::getMyURL()), 'uid' => $profile_uid]);
273 if (DBM::is_result($contact)) {
274 $cid = $contact['id'];
276 $gcontact = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Profile::getMyURL())]);
277 if (DBM::is_result($gcontact)) {
278 $zcid = $gcontact['id'];
284 if ($cid == 0 && $zcid == 0) {
289 $t = GContact::countCommonFriends($profile_uid, $cid);
291 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
299 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
301 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
304 return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
305 '$desc' => tt("%d contact in common", "%d contacts in common", $t),
306 '$base' => System::baseUrl(),
307 '$uid' => $profile_uid,
308 '$cid' => (($cid) ? $cid : '0'),
309 '$linkmore' => (($t > 5) ? 'true' : ''),
310 '$more' => t('show more'),