]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - index.php
Merge pull request #532 from ArthurHoaro/hotfix/title-retrieve-the-return
[github/shaarli/Shaarli.git] / index.php
index 41a42cf6736b95ba60a45e71e322ace7bb56c0a0..e9b0bf4058e52f9843a9ecfd3408211abe3724b3 100644 (file)
--- a/index.php
+++ b/index.php
@@ -100,6 +100,7 @@ $GLOBALS['config']['ENABLE_LOCALCACHE'] = true;
 $GLOBALS['config']['UPDATECHECK_BRANCH'] = 'stable';
 $GLOBALS['config']['UPDATECHECK_INTERVAL'] = 86400;
 
+$GLOBALS['config']['REDIRECTOR_URLENCODE'] = true;
 
 /*
  * Plugin configuration
@@ -160,6 +161,7 @@ require_once 'application/HttpUtils.php';
 require_once 'application/LinkDB.php';
 require_once 'application/LinkFilter.php';
 require_once 'application/LinkUtils.php';
+require_once 'application/NetscapeBookmarkUtils.php';
 require_once 'application/TimeZone.php';
 require_once 'application/Url.php';
 require_once 'application/Utils.php';
@@ -706,7 +708,8 @@ function showDailyRSS() {
         $GLOBALS['config']['DATASTORE'],
         isLoggedIn(),
         $GLOBALS['config']['HIDE_PUBLIC_LINKS'],
-        $GLOBALS['redirector']
+        $GLOBALS['redirector'],
+        $GLOBALS['config']['REDIRECTOR_URLENCODE']
     );
 
     /* Some Shaarlies may have very few links, so we need to look
@@ -791,16 +794,10 @@ function showDailyRSS() {
  * Show the 'Daily' page.
  *
  * @param PageBuilder $pageBuilder Template engine wrapper.
+ * @param LinkDB $LINKSDB LinkDB instance.
  */
-function showDaily($pageBuilder)
+function showDaily($pageBuilder, $LINKSDB)
 {
-    $LINKSDB = new LinkDB(
-        $GLOBALS['config']['DATASTORE'],
-        isLoggedIn(),
-        $GLOBALS['config']['HIDE_PUBLIC_LINKS'],
-        $GLOBALS['redirector']
-    );
-
     $day=Date('Ymd',strtotime('-1 day')); // Yesterday, in format YYYYMMDD.
     if (isset($_GET['day'])) $day=$_GET['day'];
 
@@ -892,7 +889,8 @@ function renderPage()
         $GLOBALS['config']['DATASTORE'],
         isLoggedIn(),
         $GLOBALS['config']['HIDE_PUBLIC_LINKS'],
-        $GLOBALS['redirector']
+        $GLOBALS['redirector'],
+        $GLOBALS['config']['REDIRECTOR_URLENCODE']
     );
 
     $updater = new Updater(
@@ -1015,11 +1013,16 @@ function renderPage()
             return strcasecmp($a, $b);
         });
 
-        $tagList=array();
-        foreach($tags as $key=>$value)
-        // Tag font size scaling: default 15 and 30 logarithm bases affect scaling, 22 and 6 are arbitrary font sizes for max and min sizes.
-        {
-            $tagList[$key] = array('count'=>$value,'size'=>log($value, 15) / log($maxcount, 30) * (22-6) + 6);
+        $tagList = array();
+        foreach($tags as $key => $value) {
+            // Tag font size scaling:
+            //   default 15 and 30 logarithm bases affect scaling,
+            //   22 and 6 are arbitrary font sizes for max and min sizes.
+            $size = log($value, 15) / log($maxcount, 30) * 2.2 + 0.8;
+            $tagList[$key] = array(
+                'count' => $value,
+                'size' => number_format($size, 2, '.', ''),
+            );
         }
 
         $data = array(
@@ -1038,7 +1041,7 @@ function renderPage()
 
     // Daily page.
     if ($targetPage == Router::$PAGE_DAILY) {
-        showDaily($PAGE);
+        showDaily($PAGE, $LINKSDB);
     }
 
     // ATOM and RSS feed.
@@ -1584,44 +1587,36 @@ function renderPage()
     }
 
     // -------- Export as Netscape Bookmarks HTML file.
-    if ($targetPage == Router::$PAGE_EXPORT)
-    {
-        if (empty($_GET['what']))
-        {
+    if ($targetPage == Router::$PAGE_EXPORT) {
+        if (empty($_GET['selection'])) {
             $PAGE->assign('linkcount',count($LINKSDB));
             $PAGE->renderPage('export');
             exit;
         }
-        $exportWhat=$_GET['what'];
-        if (!array_intersect(array('all','public','private'),array($exportWhat))) die('What are you trying to export???');
 
-        header('Content-Type: text/html; charset=utf-8');
-        header('Content-disposition: attachment; filename=bookmarks_'.$exportWhat.'_'.strval(date('Ymd_His')).'.html');
-        $currentdate=date('Y/m/d H:i:s');
-        echo <<<HTML
-<!DOCTYPE NETSCAPE-Bookmark-file-1>
-<!-- This is an automatically generated file.
-     It will be read and overwritten.
-     DO NOT EDIT! -->
-<!-- Shaarli {$exportWhat} bookmarks export on {$currentdate} -->
-<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
-<TITLE>Bookmarks</TITLE>
-<H1>Bookmarks</H1>
-HTML;
-        foreach($LINKSDB as $link)
-        {
-            if ($exportWhat=='all' ||
-               ($exportWhat=='private' && $link['private']!=0) ||
-               ($exportWhat=='public' && $link['private']==0))
-            {
-                $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
-                echo '<DT><A HREF="'.$link['url'].'" ADD_DATE="'.$date->getTimestamp().'" PRIVATE="'.$link['private'].'"';
-                if ($link['tags']!='') echo ' TAGS="'.str_replace(' ',',',$link['tags']).'"';
-                echo '>'.$link['title']."</A>\n";
-                if ($link['description']!='') echo '<DD>'.$link['description']."\n";
-            }
+        // export as bookmarks_(all|private|public)_YYYYmmdd_HHMMSS.html
+        $selection = $_GET['selection'];
+        try {
+            $PAGE->assign(
+                'links',
+                NetscapeBookmarkUtils::filterAndFormat($LINKSDB, $selection)
+            );
+        } catch (Exception $exc) {
+            header('Content-Type: text/plain; charset=utf-8');
+            echo $exc->getMessage();
+            exit;
         }
-                exit;
+        $now = new DateTime();
+        header('Content-Type: text/html; charset=utf-8');
+        header(
+            'Content-disposition: attachment; filename=bookmarks_'
+           .$selection.'_'.$now->format(LinkDB::LINK_DATE_FORMAT).'.html'
+        );
+        $PAGE->assign('date', $now->format(DateTime::RFC822));
+        $PAGE->assign('eol', PHP_EOL);
+        $PAGE->assign('selection', $selection);
+        $PAGE->renderPage('export.bookmarks');
+        exit;
     }
 
     // -------- User is uploading a file for import
@@ -1635,7 +1630,7 @@ HTML;
             exit;
         }
         if (!tokenOk($_POST['token'])) die('Wrong token.');
-        importFile();
+        importFile($LINKSDB);
         exit;
     }
 
@@ -1704,15 +1699,10 @@ HTML;
 
 // -----------------------------------------------------------------------------------------------
 // Process the import file form.
-function importFile()
+function importFile($LINKSDB)
 {
     if (!isLoggedIn()) { die('Not allowed.'); }
-    $LINKSDB = new LinkDB(
-        $GLOBALS['config']['DATASTORE'],
-        isLoggedIn(),
-        $GLOBALS['config']['HIDE_PUBLIC_LINKS'],
-        $GLOBALS['redirector']
-    );
+
     $filename=$_FILES['filetoupload']['name'];
     $filesize=$_FILES['filetoupload']['size'];
     $data=file_get_contents($_FILES['filetoupload']['tmp_name']);