aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php180
1 files changed, 22 insertions, 158 deletions
diff --git a/index.php b/index.php
index 00e4a40b..fb528eeb 100644
--- a/index.php
+++ b/index.php
@@ -519,69 +519,20 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
519 519
520 // -------- User wants to rename a tag or delete it 520 // -------- User wants to rename a tag or delete it
521 if ($targetPage == Router::$PAGE_CHANGETAG) { 521 if ($targetPage == Router::$PAGE_CHANGETAG) {
522 header('./manage-tags'); 522 header('Location: ./manage-tags');
523 exit; 523 exit;
524 } 524 }
525 525
526 // -------- User wants to add a link without using the bookmarklet: Show form. 526 // -------- User wants to add a link without using the bookmarklet: Show form.
527 if ($targetPage == Router::$PAGE_ADDLINK) { 527 if ($targetPage == Router::$PAGE_ADDLINK) {
528 $PAGE->assign('pagetitle', t('Shaare a new link') .' - '. $conf->get('general.title', 'Shaarli')); 528 header('Location: ./shaare');
529 $PAGE->renderPage('addlink');
530 exit; 529 exit;
531 } 530 }
532 531
533 // -------- User clicked the "Save" button when editing a link: Save link to database. 532 // -------- User clicked the "Save" button when editing a link: Save link to database.
534 if (isset($_POST['save_edit'])) { 533 if (isset($_POST['save_edit'])) {
535 // Go away! 534 // This route is no longer supported in legacy mode
536 if (! $sessionManager->checkToken($_POST['token'])) { 535 header('Location: ./');
537 die(t('Wrong token.'));
538 }
539
540 // lf_id should only be present if the link exists.
541 $id = isset($_POST['lf_id']) ? intval(escape($_POST['lf_id'])) : null;
542 if ($id && $bookmarkService->exists($id)) {
543 // Edit
544 $bookmark = $bookmarkService->get($id);
545 } else {
546 // New link
547 $bookmark = new Bookmark();
548 }
549
550 $bookmark->setTitle($_POST['lf_title']);
551 $bookmark->setDescription($_POST['lf_description']);
552 $bookmark->setUrl($_POST['lf_url'], $conf->get('security.allowed_protocols'));
553 $bookmark->setPrivate(isset($_POST['lf_private']));
554 $bookmark->setTagsString($_POST['lf_tags']);
555
556 if ($conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE
557 && ! $bookmark->isNote()
558 ) {
559 $thumbnailer = new Thumbnailer($conf);
560 $bookmark->setThumbnail($thumbnailer->get($bookmark->getUrl()));
561 }
562 $bookmarkService->addOrSet($bookmark, false);
563
564 // To preserve backward compatibility with 3rd parties, plugins still use arrays
565 $factory = new FormatterFactory($conf, $loginManager->isLoggedIn());
566 $formatter = $factory->getFormatter('raw');
567 $data = $formatter->format($bookmark);
568 $pluginManager->executeHooks('save_link', $data);
569
570 $bookmark->fromArray($data);
571 $bookmarkService->set($bookmark);
572
573 // If we are called from the bookmarklet, we must close the popup:
574 if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) {
575 echo '<script>self.close();</script>';
576 exit;
577 }
578
579 $returnurl = !empty($_POST['returnurl']) ? $_POST['returnurl'] : '?';
580 $location = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link'));
581 // Scroll to the link which has been edited.
582 $location .= '#' . $bookmark->getShortUrl();
583 // After saving the link, redirect to the page the user was on.
584 header('Location: '. $location);
585 exit; 536 exit;
586 } 537 }
587 538
@@ -695,110 +646,13 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
695 // -------- User clicked the "EDIT" button on a link: Display link edit form. 646 // -------- User clicked the "EDIT" button on a link: Display link edit form.
696 if (isset($_GET['edit_link'])) { 647 if (isset($_GET['edit_link'])) {
697 $id = (int) escape($_GET['edit_link']); 648 $id = (int) escape($_GET['edit_link']);
698 try { 649 header('Location: ./shaare-' . $id);
699 $link = $bookmarkService->get($id); // Read database
700 } catch (BookmarkNotFoundException $e) {
701 // Link not found in database.
702 header('Location: ?');
703 exit;
704 }
705
706 $factory = new FormatterFactory($conf, $loginManager->isLoggedIn());
707 $formatter = $factory->getFormatter('raw');
708 $formattedLink = $formatter->format($link);
709 $tags = $bookmarkService->bookmarksCountPerTag();
710 if ($conf->get('formatter') === 'markdown') {
711 $tags[BookmarkMarkdownFormatter::NO_MD_TAG] = 1;
712 }
713 $data = array(
714 'link' => $formattedLink,
715 'link_is_new' => false,
716 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''),
717 'tags' => $tags,
718 );
719 $pluginManager->executeHooks('render_editlink', $data);
720
721 foreach ($data as $key => $value) {
722 $PAGE->assign($key, $value);
723 }
724
725 $PAGE->assign('pagetitle', t('Edit') .' '. t('Shaare') .' - '. $conf->get('general.title', 'Shaarli'));
726 $PAGE->renderPage('editlink');
727 exit; 650 exit;
728 } 651 }
729 652
730 // -------- User want to post a new link: Display link edit form. 653 // -------- User want to post a new link: Display link edit form.
731 if (isset($_GET['post'])) { 654 if (isset($_GET['post'])) {
732 $url = cleanup_url($_GET['post']); 655 header('Location: ./shaare?' . http_build_query($_GET));
733
734 $link_is_new = false;
735 // Check if URL is not already in database (in this case, we will edit the existing link)
736 $bookmark = $bookmarkService->findByUrl($url);
737 if (! $bookmark) {
738 $link_is_new = true;
739 // Get title if it was provided in URL (by the bookmarklet).
740 $title = empty($_GET['title']) ? '' : escape($_GET['title']);
741 // Get description if it was provided in URL (by the bookmarklet). [Bronco added that]
742 $description = empty($_GET['description']) ? '' : escape($_GET['description']);
743 $tags = empty($_GET['tags']) ? '' : escape($_GET['tags']);
744 $private = !empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0;
745
746 // If this is an HTTP(S) link, we try go get the page to extract
747 // the title (otherwise we will to straight to the edit form.)
748 if (empty($title) && strpos(get_url_scheme($url), 'http') !== false) {
749 $retrieveDescription = $conf->get('general.retrieve_description');
750 // Short timeout to keep the application responsive
751 // The callback will fill $charset and $title with data from the downloaded page.
752 get_http_response(
753 $url,
754 $conf->get('general.download_timeout', 30),
755 $conf->get('general.download_max_size', 4194304),
756 get_curl_download_callback($charset, $title, $description, $tags, $retrieveDescription)
757 );
758 if (! empty($title) && strtolower($charset) != 'utf-8') {
759 $title = mb_convert_encoding($title, 'utf-8', $charset);
760 }
761 }
762
763 if ($url == '') {
764 $title = $conf->get('general.default_note_title', t('Note: '));
765 }
766 $url = escape($url);
767 $title = escape($title);
768
769 $link = [
770 'title' => $title,
771 'url' => $url,
772 'description' => $description,
773 'tags' => $tags,
774 'private' => $private,
775 ];
776 } else {
777 $factory = new FormatterFactory($conf, $loginManager->isLoggedIn());
778 $formatter = $factory->getFormatter('raw');
779 $link = $formatter->format($bookmark);
780 }
781
782 $tags = $bookmarkService->bookmarksCountPerTag();
783 if ($conf->get('formatter') === 'markdown') {
784 $tags[BookmarkMarkdownFormatter::NO_MD_TAG] = 1;
785 }
786 $data = [
787 'link' => $link,
788 'link_is_new' => $link_is_new,
789 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''),
790 'source' => (isset($_GET['source']) ? $_GET['source'] : ''),
791 'tags' => $tags,
792 'default_private_links' => $conf->get('privacy.default_private_links', false),
793 ];
794 $pluginManager->executeHooks('render_editlink', $data);
795
796 foreach ($data as $key => $value) {
797 $PAGE->assign($key, $value);
798 }
799
800 $PAGE->assign('pagetitle', t('Shaare') .' - '. $conf->get('general.title', 'Shaarli'));
801 $PAGE->renderPage('editlink');
802 exit; 656 exit;
803 } 657 }
804 658
@@ -1351,19 +1205,29 @@ $app->group('', function () {
1351 $this->post('/configure', '\Shaarli\Front\Controller\Admin\ConfigureController:save')->setName('saveConfigure'); 1205 $this->post('/configure', '\Shaarli\Front\Controller\Admin\ConfigureController:save')->setName('saveConfigure');
1352 $this->get('/manage-tags', '\Shaarli\Front\Controller\Admin\ManageTagController:index')->setName('manageTag'); 1206 $this->get('/manage-tags', '\Shaarli\Front\Controller\Admin\ManageTagController:index')->setName('manageTag');
1353 $this->post('/manage-tags', '\Shaarli\Front\Controller\Admin\ManageTagController:save')->setName('saveManageTag'); 1207 $this->post('/manage-tags', '\Shaarli\Front\Controller\Admin\ManageTagController:save')->setName('saveManageTag');
1208 $this->get('/add-shaare', '\Shaarli\Front\Controller\Admin\PostBookmarkController:addShaare')->setName('addShaare');
1209 $this
1210 ->get('/shaare', '\Shaarli\Front\Controller\Admin\PostBookmarkController:displayCreateForm')
1211 ->setName('newShaare');
1212 $this
1213 ->get('/shaare-{id}', '\Shaarli\Front\Controller\Admin\PostBookmarkController:displayEditForm')
1214 ->setName('editShaare');
1215 $this
1216 ->post('/shaare', '\Shaarli\Front\Controller\Admin\PostBookmarkController:save')
1217 ->setName('saveShaare');
1218 $this
1219 ->get('/delete-shaare', '\Shaarli\Front\Controller\Admin\PostBookmarkController:deleteBookmark')
1220 ->setName('deleteShaare');
1354 1221
1355 $this 1222 $this
1356 ->get('/links-per-page', '\Shaarli\Front\Controller\Admin\SessionFilterController:linksPerPage') 1223 ->get('/links-per-page', '\Shaarli\Front\Controller\Admin\SessionFilterController:linksPerPage')
1357 ->setName('filter-links-per-page') 1224 ->setName('filter-links-per-page');
1358 ;
1359 $this 1225 $this
1360 ->get('/visibility/{visibility}', '\Shaarli\Front\Controller\Admin\SessionFilterController:visibility') 1226 ->get('/visibility/{visibility}', '\Shaarli\Front\Controller\Admin\SessionFilterController:visibility')
1361 ->setName('visibility') 1227 ->setName('visibility');
1362 ;
1363 $this 1228 $this
1364 ->get('/untagged-only', '\Shaarli\Front\Controller\Admin\SessionFilterController:untaggedOnly') 1229 ->get('/untagged-only', '\Shaarli\Front\Controller\Admin\SessionFilterController:untaggedOnly')
1365 ->setName('untagged-only') 1230 ->setName('untagged-only');
1366 ;
1367})->add('\Shaarli\Front\ShaarliMiddleware'); 1231})->add('\Shaarli\Front\ShaarliMiddleware');
1368 1232
1369$response = $app->run(true); 1233$response = $app->run(true);