$id]); if ($url) { $this->redirect($url->url); } else { throw new AccessDeniedException(_('Die Kurz-URL ist ungültig!')); } } public function create_action() { if (!Request::isPost()) { throw new AccessDeniedException(); } $user = User::findCurrent(); $path = Request::get('path'); //Check if the user has already created such a short-URL: $short_url = ShortURL::findOneBySql( 'url = :path AND user_id = :user_id', [ 'path' => $path, 'user_id' => $user->id ] ); if (!$short_url) { $short_url = new ShortURL(); $short_url->url = $path; $short_url->user_id = $user->id; $short_url->store(); } $this->render_json( [ 'full_short_url' => URLHelper::getURL('dispatch.php/u/r/' . $short_url->alias), 'url_id' => $short_url->id ] ); } public function alias_action($url_id) { PageLayout::setTitle(_('Bezeichnung ändern')); $short_url = new ShortURL($url_id); $this->form = \Studip\Forms\Form::fromSORM( $short_url, [ 'fields' => [ 'alias' => [ 'label' => _('Bezeichnung'), 'type' => 'text', 'pattern' => '[a-záæäéèôøöü0-9\-]{4,256}' ] ] ] ); $this->form->autoStore(); } public function overview_action() { PageLayout::setTitle(_('Meine Kurz-URLs')); if (Navigation::hasItem('/contents/short_urls')) { Navigation::activateItem('/contents/short_urls'); } $this->short_urls = ShortURL::findBySql('user_id = :user_id ORDER BY `alias` ASC', ['user_id' => $GLOBALS['user']->id]); } }