3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Update;
24 use Friendica\BaseModule;
25 use Friendica\Content\Pager;
26 use Friendica\Core\Session;
27 use Friendica\Database\DBA;
29 use Friendica\Model\Item;
30 use Friendica\Model\Profile as ProfileModel;
31 use Friendica\Network\HTTPException\ForbiddenException;
32 use Friendica\Util\DateTimeFormat;
34 class Profile extends BaseModule
36 public static function rawContent(array $parameters = [])
40 if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->profile['uid'])) {
41 throw new ForbiddenException();
46 $profile_uid = intval($_GET['p'] ?? 0);
48 // Ensure we've got a profile owner if updating.
49 $a->profile['uid'] = $profile_uid;
51 $remote_contact = Session::getRemoteContactID($a->profile['uid']);
52 $is_owner = local_user() == $a->profile['uid'];
53 $last_updated_key = "profile:" . $a->profile['uid'] . ":" . local_user() . ":" . $remote_contact;
55 if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact) {
56 throw new ForbiddenException(DI::l10n()->t('Access to this profile has been restricted.'));
59 // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
60 $sql_extra = Item::getPermissionsSQLByUserId($a->profile['uid']);
62 $last_updated_array = Session::get('last_updated', []);
64 $last_updated = $last_updated_array[$last_updated_key] ?? 0;
66 // If the page user is the owner of the page we should query for unseen
67 // items. Otherwise use a timestamp of the last succesful update request.
68 if ($is_owner || !$last_updated) {
69 $sql_extra4 = " AND `item`.`unseen`";
71 $gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated);
72 $sql_extra4 = " AND `item`.`received` > '" . $gmupdate . "'";
76 "SELECT DISTINCT(`parent-uri`) AS `uri`, `item`.`created`
79 ON `contact`.`id` = `item`.`contact-id`
80 AND NOT `contact`.`blocked`
81 AND NOT `contact`.`pending`
82 WHERE `item`.`uid` = ?
84 AND (NOT `item`.`deleted` OR `item`.`gravity` = ?)
85 AND NOT `item`.`moderated`
89 ORDER BY `item`.`received` DESC",
94 if (!DBA::isResult($items_stmt)) {
98 $pager = new Pager(DI::args()->getQueryString());
100 // Set a time stamp for this page. We will make use of it when we
101 // search for new items (update routine)
102 $last_updated_array[$last_updated_key] = time();
103 Session::set('last_updated', $last_updated_array);
105 if ($is_owner && !$profile_uid && !DI::config()->get('theme', 'hide_eventlist')) {
106 $o .= ProfileModel::getBirthdays();
107 $o .= ProfileModel::getEventsReminderHTML();
111 $unseen = Item::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
113 Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
117 $items = DBA::toArray($items_stmt);
119 $o .= conversation($a, $items, $pager, 'profile', $profile_uid, false, 'received', $a->profile['uid']);
121 header("Content-type: text/html");
122 echo "<!DOCTYPE html><html><body>\r\n";
123 // We can remove this hack once Internet Explorer recognises HTML5 natively
126 if (DI::pConfig()->get(local_user(), "system", "bandwidth_saver")) {
127 $replace = "<br />".DI::l10n()->t("[Embedded content - reload page to view]")."<br />";
128 $pattern = "/<\s*audio[^>]*>(.*?)<\s*\/\s*audio>/i";
129 $o = preg_replace($pattern, $replace, $o);
130 $pattern = "/<\s*video[^>]*>(.*?)<\s*\/\s*video>/i";
131 $o = preg_replace($pattern, $replace, $o);
132 $pattern = "/<\s*embed[^>]*>(.*?)<\s*\/\s*embed>/i";
133 $o = preg_replace($pattern, $replace, $o);
134 $pattern = "/<\s*iframe[^>]*>(.*?)<\s*\/\s*iframe>/i";
135 $o = preg_replace($pattern, $replace, $o);
138 // reportedly some versions of MSIE don't handle tabs in XMLHttpRequest documents very well
139 echo str_replace("\t", " ", $o);
141 echo "</body></html>\r\n";