3 * @file src/Content/Widget.php
5 namespace Friendica\Content;
7 use Friendica\Content\ContactSelector;
8 use Friendica\Content\Feature;
9 use Friendica\Core\System;
10 use Friendica\Core\Config;
11 use Friendica\Core\PConfig;
12 use Friendica\Database\DBM;
13 use Friendica\Model\GContact;
14 use Friendica\Model\Profile;
16 require_once 'boot.php';
21 * Return the follow widget
23 * @param string $value optional, default empty
25 public static function follow($value = "")
27 return replace_macros(get_markup_template('follow.tpl'), array(
28 '$connect' => t('Add New Contact'),
29 '$desc' => t('Enter address or web location'),
30 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
32 '$follow' => t('Connect')
37 * Return Find People widget
39 public static function findPeople()
42 $global_dir = Config::get('system', 'directory');
44 if (Config::get('system', 'invitation_only')) {
45 $x = PConfig::get(local_user(), 'system', 'invites_remaining');
46 if ($x || is_site_admin()) {
47 $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
48 . tt('%d invitation available', '%d invitations available', $x)
53 return replace_macros(get_markup_template('peoplefind.tpl'), array(
54 '$findpeople' => t('Find People'),
55 '$desc' => t('Enter name or interest'),
56 '$label' => t('Connect/Follow'),
57 '$hint' => t('Examples: Robert Morgenstein, Fishing'),
58 '$findthem' => t('Find'),
59 '$suggest' => t('Friend Suggestions'),
60 '$similar' => t('Similar Interests'),
61 '$random' => t('Random Profile'),
62 '$inv' => t('Invite Friends'),
63 '$directory' => t('View Global Directory'),
64 '$global_dir' => $global_dir
69 * Return unavailable networks
71 public static function unavailableNetworks()
75 if (!plugin_enabled("appnet")) {
76 $networks[] = NETWORK_APPNET;
79 if (!plugin_enabled("fbpost") && !plugin_enabled("facebook")) {
80 $networks[] = NETWORK_FACEBOOK;
83 if (!plugin_enabled("statusnet")) {
84 $networks[] = NETWORK_STATUSNET;
87 if (!plugin_enabled("pumpio")) {
88 $networks[] = NETWORK_PUMPIO;
91 if (!plugin_enabled("twitter")) {
92 $networks[] = NETWORK_TWITTER;
95 if (Config::get("system", "ostatus_disabled")) {
96 $networks[] = NETWORK_OSTATUS;
99 if (!Config::get("system", "diaspora_enabled")) {
100 $networks[] = NETWORK_DIASPORA;
103 if (!plugin_enabled("pnut")) {
104 $networks[] = NETWORK_PNUT;
107 if (!sizeof($networks)) {
111 $network_filter = implode("','", $networks);
113 $network_filter = "AND `network` NOT IN ('$network_filter')";
115 return $network_filter;
119 * Return networks widget
121 * @param string $baseurl baseurl
122 * @param string $selected optional, default empty
124 public static function networks($baseurl, $selected = '')
130 if (!Feature::isEnabled(local_user(), 'networks')) {
134 $extra_sql = self::unavailableNetworks();
136 $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
141 while ($rr = dba::fetch($r)) {
142 /// @TODO If 'network' is not there, this triggers an E_NOTICE
143 if ($rr['network']) {
144 $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
149 if (count($nets) < 2) {
153 return replace_macros(get_markup_template('nets.tpl'), array(
154 '$title' => t('Networks'),
156 '$sel_all' => (($selected == '') ? 'selected' : ''),
157 '$all' => t('All Networks'),
164 * Return file as widget
166 * @param string $baseurl baseurl
167 * @param string $selected optional, default empty
169 public static function fileAs($baseurl, $selected = '')
175 if (!Feature::isEnabled(local_user(), 'filing')) {
179 $saved = PConfig::get(local_user(), 'system', 'filetags');
180 if (!strlen($saved)) {
186 $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
188 foreach ($matches as $mtch) {
189 $unescaped = xmlify(file_tag_decode($mtch[1]));
190 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
194 return replace_macros(get_markup_template('fileas_widget.tpl'), array(
195 '$title' => t('Saved Folders'),
197 '$sel_all' => (($selected == '') ? 'selected' : ''),
198 '$all' => t('Everything'),
205 * Return categories widget
207 * @param string $baseurl baseurl
208 * @param string $selected optional, default empty
210 public static function categories($baseurl, $selected = '')
214 if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
218 $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
219 if (!strlen($saved)) {
225 $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
228 foreach ($matches as $mtch) {
229 $unescaped = xmlify(file_tag_decode($mtch[1]));
230 $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
234 return replace_macros(get_markup_template('categories_widget.tpl'), array(
235 '$title' => t('Categories'),
237 '$sel_all' => (($selected == '') ? 'selected' : ''),
238 '$all' => t('Everything'),
245 * Return common friends visitor widget
247 * @param string $profile_uid uid
249 public static function commonFriendsVisitor($profile_uid)
251 if (local_user() == $profile_uid) {
257 if (is_array($_SESSION['remote'])) {
258 foreach ($_SESSION['remote'] as $visitor) {
259 if ($visitor['uid'] == $profile_uid) {
260 $cid = $visitor['cid'];
267 if (Profile::getMyURL()) {
268 $contact = dba::selectFirst('contact', ['id'],
269 ['nurl' => normalise_link(Profile::getMyURL()), 'uid' => $profile_uid]);
270 if (DBM::is_result($contact)) {
271 $cid = $contact['id'];
273 $gcontact = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Profile::getMyURL())]);
274 if (DBM::is_result($gcontact)) {
275 $zcid = $gcontact['id'];
281 if ($cid == 0 && $zcid == 0) {
286 $t = GContact::countCommonFriends($profile_uid, $cid);
288 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
296 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
298 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
301 return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
302 '$desc' => tt("%d contact in common", "%d contacts in common", $t),
303 '$base' => System::baseUrl(),
304 '$uid' => $profile_uid,
305 '$cid' => (($cid) ? $cid : '0'),
306 '$linkmore' => (($t > 5) ? 'true' : ''),
307 '$more' => t('show more'),