. // }}} /** * Handle network public feed * * @package GNUsocial * @category Controller * * @author Hugo Sales * @author Eliseu Amaro * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ namespace App\Controller; use App\Core\Controller; use App\Core\DB\DB; use App\Core\Event; use App\Core\NoteScope; use App\Util\Common; use App\Util\Exception\ClientException; use function App\Core\I18n\_m; use Symfony\Component\HttpFoundation\Request; class Network extends Controller { // Can't have constanst inside herestring private $public_scope = NoteScope::PUBLIC; private $instance_scope = NoteScope::PUBLIC | NoteScope::SITE; private $message_scope = NoteScope::MESSAGE; private $follower_scope = NoteScope::PUBLIC | NoteScope::FOLLOWER; public function public(Request $request) { $notes = DB::sql('select * from note n ' . "where (n.scope & {$this->instance_scope}) <> 0 " . 'order by n.created DESC', ['n' => 'App\Entity\Note']); Event::handle('FormatNoteList', [&$notes]); return [ '_template' => 'network/public.html.twig', 'notes' => $notes, ]; } public function home(Request $request, string $nickname) { $target = DB::findOneBy('gsactor', ['nickname' => $nickname]); if ($target == null) { throw new ClientException(_m('User {nickname} doesn\'t exist', ['{nickname}' => $nickname])); } $query = << {$this->message_scope} order by note.modified DESC END; $notes = DB::sql($query, ['note' => 'App\Entity\Note'], ['target_actor_id' => $target->getId()]); return [ '_template' => 'network/public.html.twig', 'notes' => $notes, ]; } public function network(Request $request) { return [ '_template' => 'network/public.html.twig', 'notes' => DB::dql('select n from App\Entity\Note n ' . "where n.scope = {$this->public_scope} " . 'order by n.created DESC' ), ]; } public function replies(Request $request) { $actor_id = Common::ensureLoggedIn()->getId(); return [ '_template' => 'network/public.html.twig', 'notes' => DB::dql('select n from App\Entity\Note n ' . 'where n.reply_to is not null and n.gsactor_id = :id ' . 'order by n.created DESC', ['id' => $actor_id]), ]; } public function favourites(Request $request) { $actor_id = Common::ensureLoggedIn()->getId(); return [ '_template' => 'network/public.html.twig', 'notes' => DB::dql('select f from App\Entity\Favourite f ' . 'where f.gsactor_id = :id ' . 'order by f.created DESC', ['id' => $actor_id]), ]; } }