]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - index.php
Merge pull request #554 from virtualtam/fix/bookmark-export
[github/shaarli/Shaarli.git] / index.php
index 456d93c24ccd920ee284cac6d988da174703ec82..408aeae9ca7bcf6cde2b6c8190cabd56bc9fc761 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1277,11 +1277,15 @@ function renderPage()
     {
         if (!empty($_POST['title']) )
         {
-            if (!tokenOk($_POST['token'])) die('Wrong token.'); // Go away!
+            if (!tokenOk($_POST['token'])) {
+                die('Wrong token.'); // Go away!
+            }
             $tz = 'UTC';
-            if (!empty($_POST['continent']) && !empty($_POST['city']))
-                if (isTimeZoneValid($_POST['continent'],$_POST['city']))
-                    $tz = $_POST['continent'].'/'.$_POST['city'];
+            if (!empty($_POST['continent']) && !empty($_POST['city'])
+                && isTimeZoneValid($_POST['continent'], $_POST['city'])
+            ) {
+                $tz = $_POST['continent'] . '/' . $_POST['city'];
+            }
             $GLOBALS['timezone'] = $tz;
             $GLOBALS['title']=$_POST['title'];
             $GLOBALS['titleLink']=$_POST['titleLink'];
@@ -1519,7 +1523,7 @@ function renderPage()
 
     // -------- User want to post a new link: Display link edit form.
     if (isset($_GET['post'])) {
-        $url = cleanup_url(escape($_GET['post']));
+        $url = cleanup_url($_GET['post']);
 
         $link_is_new = false;
         // Check if URL is not already in database (in this case, we will edit the existing link)
@@ -1544,8 +1548,8 @@ function renderPage()
                     // Extract title.
                     $title = html_extract_title($content);
                     // Re-encode title in utf-8 if necessary.
-                    if (! empty($title) && $charset != 'utf-8') {
-                        $title = mb_convert_encoding($title, $charset, 'utf-8');
+                    if (! empty($title) && strtolower($charset) != 'utf-8') {
+                        $title = mb_convert_encoding($title, 'utf-8', $charset);
                     }
                 }
             }
@@ -1554,6 +1558,8 @@ function renderPage()
                 $url = '?' . smallHash($linkdate);
                 $title = 'Note: ';
             }
+            $url = escape($url);
+            $title = escape($title);
 
             $link = array(
                 'linkdate' => $linkdate,
@@ -1584,8 +1590,9 @@ function renderPage()
         exit;
     }
 
-    // -------- Export as Netscape Bookmarks HTML file.
     if ($targetPage == Router::$PAGE_EXPORT) {
+        // Export links as a Netscape Bookmarks file
+
         if (empty($_GET['selection'])) {
             $PAGE->assign('linkcount',count($LINKSDB));
             $PAGE->renderPage('export');
@@ -1594,10 +1601,21 @@ function renderPage()
 
         // export as bookmarks_(all|private|public)_YYYYmmdd_HHMMSS.html
         $selection = $_GET['selection'];
+        if (isset($_GET['prepend_note_url'])) {
+            $prependNoteUrl = $_GET['prepend_note_url'];
+        } else {
+            $prependNoteUrl = false;
+        }
+
         try {
             $PAGE->assign(
                 'links',
-                NetscapeBookmarkUtils::filterAndFormat($LINKSDB, $selection)
+                NetscapeBookmarkUtils::filterAndFormat(
+                    $LINKSDB,
+                    $selection,
+                    $prependNoteUrl,
+                    index_url($_SERVER)
+                )
             );
         } catch (Exception $exc) {
             header('Content-Type: text/plain; charset=utf-8');
@@ -2106,10 +2124,10 @@ function install()
     if (!empty($_POST['setlogin']) && !empty($_POST['setpassword']))
     {
         $tz = 'UTC';
-        if (!empty($_POST['continent']) && !empty($_POST['city'])) {
-            if (isTimeZoneValid($_POST['continent'], $_POST['city'])) {
-                $tz = $_POST['continent'].'/'.$_POST['city'];
-            }
+        if (!empty($_POST['continent']) && !empty($_POST['city'])
+            && isTimeZoneValid($_POST['continent'], $_POST['city'])
+        ) {
+            $tz = $_POST['continent'].'/'.$_POST['city'];
         }
         $GLOBALS['timezone'] = $tz;
         // Everything is ok, let's create config file.