Browse Source

Add ODT note export, add more metadata to HTML export

master
Skylar Ittner 6 months ago
parent
commit
3ff8a9389a
8 changed files with 100 additions and 14 deletions
  1. 23
    3
      action.php
  2. 2
    1
      composer.json
  3. 27
    1
      composer.lock
  4. 9
    2
      langs/en/notes.json
  5. 6
    1
      lib/Note.lib.php
  6. 27
    4
      pages/home.php
  7. 3
    0
      settings.template.php
  8. 3
    2
      static/css/home.css

+ 23
- 3
action.php View File

@@ -70,9 +70,29 @@ switch ($VARS['action']) {
70 70
         if (!$note->hasReadAccess(new User($_SESSION['uid']))) {
71 71
             die($Strings->get("invalid parameters", false));
72 72
         }
73
-        header("Content-Type: text/markdown; charset=UTF-8");
74
-        header("Content-disposition: attachment; filename=\"" . $note->getCleanTitle() . "_" . $note->getModified() . ".md\"");
75
-        echo $note->getText();
73
+        if (empty($VARS['type'])) {
74
+            $VARS['type'] = "markdown";
75
+        }
76
+
77
+        switch ($VARS['type']) {
78
+            case "html":
79
+                header("Content-Type: text/html; charset=UTF-8");
80
+                header("Content-disposition: attachment; filename=\"" . $note->getCleanTitle() . "_" . $note->getModified() . ".html\"");
81
+                echo $note->getHTML(false);
82
+                break;
83
+            case "odt":
84
+                if (PANDOC_BIN != "") {
85
+                    header("Content-Type: application/vnd.oasis.opendocument.text");
86
+                    header("Content-disposition: attachment; filename=\"" . $note->getCleanTitle() . "_" . $note->getModified() . ".odt\"");
87
+                    $pandoc = new Pandoc\Pandoc();
88
+                    echo $pandoc->convert($note->getText(), "markdown_github", "odt");
89
+                    break;
90
+                }
91
+            default:
92
+                header("Content-Type: text/markdown; charset=UTF-8");
93
+                header("Content-disposition: attachment; filename=\"" . $note->getCleanTitle() . "_" . $note->getModified() . ".md\"");
94
+                echo $note->getText();
95
+        }
76 96
         break;
77 97
     case "favoritenote":
78 98
         if (empty($VARS['noteid'])) {

+ 2
- 1
composer.json View File

@@ -8,7 +8,8 @@
8 8
         "erusev/parsedown": "^1.7",
9 9
         "leblanc-simon/parsedown-checkbox": "^0.0.2",
10 10
         "erusev/parsedown-extra": "^0.7.1",
11
-        "vanilla/htmlawed": "v2.2.4.1"
11
+        "vanilla/htmlawed": "v2.2.4.1",
12
+        "ryakad/pandoc-php": "^1.0"
12 13
     },
13 14
     "license": "MPL-2.0",
14 15
     "authors": [

+ 27
- 1
composer.lock View File

@@ -4,7 +4,7 @@
4 4
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5 5
         "This file is @generated automatically"
6 6
     ],
7
-    "content-hash": "b50c578394552657e0fcab936a4b1a01",
7
+    "content-hash": "cd5ba5d882b72c49f91fbc1a6bd97095",
8 8
     "packages": [
9 9
         {
10 10
             "name": "catfan/medoo",
@@ -431,6 +431,32 @@
431 431
             ],
432 432
             "time": "2016-08-06T14:39:51+00:00"
433 433
         },
434
+        {
435
+            "name": "ryakad/pandoc-php",
436
+            "version": "v1.0.0",
437
+            "source": {
438
+                "type": "git",
439
+                "url": "https://github.com/ryakad/pandoc-php.git",
440
+                "reference": "0cfdf959408e4c481db942b26785d94b9fe46672"
441
+            },
442
+            "dist": {
443
+                "type": "zip",
444
+                "url": "https://api.github.com/repos/ryakad/pandoc-php/zipball/0cfdf959408e4c481db942b26785d94b9fe46672",
445
+                "reference": "0cfdf959408e4c481db942b26785d94b9fe46672",
446
+                "shasum": ""
447
+            },
448
+            "type": "library",
449
+            "autoload": {
450
+                "psr-0": {
451
+                    "Pandoc": "src"
452
+                }
453
+            },
454
+            "notification-url": "https://packagist.org/downloads/",
455
+            "license": [
456
+                "MIT"
457
+            ],
458
+            "time": "2015-01-07T05:07:16+00:00"
459
+        },
434 460
         {
435 461
             "name": "vanilla/htmlawed",
436 462
             "version": "v2.2.4.1",

+ 9
- 2
langs/en/notes.json View File

@@ -4,7 +4,6 @@
4 4
     "Note": "Note",
5 5
     "Edit": "Edit",
6 6
     "Delete": "Delete",
7
-    "Download": "Download",
8 7
     "Note deleted": "Note deleted",
9 8
     "Favorite": "Favorite",
10 9
     "Set color": "Set color",
@@ -14,5 +13,13 @@
14 13
     "Close": "Close",
15 14
     "Refresh": "Refresh",
16 15
     "Make a List": "Make a List",
17
-    "More": "More"
16
+    "More": "More",
17
+    "More Options": "More Options",
18
+    "Download": "Download",
19
+    "Text": "Text",
20
+    "HTML": "HTML",
21
+    "Office": "Office",
22
+    "Download (Text)": "Download (Text)",
23
+    "Download (HTML)": "Download (HTML)",
24
+    "Download (Office)": "Download (Office)"
18 25
 }

+ 6
- 1
lib/Note.lib.php View File

@@ -125,7 +125,12 @@ class Note {
125 125
         $document = "<!DOCTYPE html>\n"
126 126
                 . "<meta charset=\"UTF-8\">\n"
127 127
                 . "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
128
-                . "<title>" . $this->getCleanTitle() . " (" . $note->getModified() . ")</title>\n"
128
+                . "<meta name=\"author\" content=\"" . htmlentities($this->getOwner()->getName()) . "\">\n"
129
+                . "<meta name=\"generator\" content=\"" . SITE_TITLE . "\">\n"
130
+                . "<link rel=\"schema.dcterms\" href=\"http://purl.org/dc/terms/\">\n"
131
+                . "<meta name=\"dcterms.modified\" content=\"" . date("Y-m-d", strtotime($this->getModified())) . "\">\n"
132
+                . "\n"
133
+                . "<title>" . $this->getCleanTitle() . "</title>\n"
129 134
                 . "\n"
130 135
                 . $safehtml;
131 136
         return $document;

+ 27
- 4
pages/home.php View File

@@ -135,12 +135,35 @@ foreach ($colors as $c) {
135 135
                                 </a>
136 136
                             </span>
137 137
                             <div class="dropdown-menu dropdown-menu-right" aria-labelledby="moreoptionsbtn_<?php echo $note->getID(); ?>">
138
+                                <!--<h4 class="dropdown-header"><?php $Strings->get("More Options"); ?></h4>-->
138 139
                                 <a class="dropdown-item" href="./action.php?action=deletenote&noteid=<?php echo $note->getID(); ?>">
139
-                                    <i class="fas fa-trash"></i> <?php $Strings->get('Delete'); ?>
140
-                                </a>
141
-                                <a class="dropdown-item" href="./action.php?action=downloadnote&noteid=<?php echo $note->getID(); ?>">
142
-                                    <i class="fas fa-download"></i> <?php $Strings->get('Download'); ?>
140
+                                    <i class="fas fa-trash fa-fw"></i> <?php $Strings->get('Delete'); ?>
143 141
                                 </a>
142
+                                <div class="dropdown-divider"></div>
143
+                                <h4 class="dropdown-header"><i class="fas fa-cloud-download-alt fa-fw"></i> <?php $Strings->get('Download'); ?></h4>
144
+                                <div class="dropdown-item d-flex justify-content-between">
145
+                                    <a class="p-2" href="./action.php?action=downloadnote&noteid=<?php echo $note->getID(); ?>&type=markdown">
146
+                                        <i class="fas fa-align-left"></i> <?php $Strings->get('Text'); ?>
147
+                                    </a>
148
+                                    <a class="p-2" href="./action.php?action=downloadnote&noteid=<?php echo $note->getID(); ?>&type=html">
149
+                                        <i class="fab fa-html5"></i> <?php $Strings->get('HTML'); ?>
150
+                                    </a>
151
+                                    <?php
152
+                                    // Additional export formats
153
+                                    if (PANDOC_BIN != "") {
154
+                                        ?>
155
+                                        <a class="p-2" href="./action.php?action=downloadnote&noteid=<?php echo $note->getID(); ?>&type=odt">
156
+                                            <i class="fas fa-file-alt"></i> <?php $Strings->get('Office'); ?>
157
+                                        </a>
158
+                                        <?php
159
+                                    } else {
160
+                                        // Fillin' space
161
+                                        ?>
162
+                                        <span class="px-4">&nbsp;</span>
163
+                                        <?php
164
+                                    }
165
+                                    ?>
166
+                                </div>
144 167
                             </div>
145 168
                         </div>
146 169
                     </div>

+ 3
- 0
settings.template.php View File

@@ -20,6 +20,9 @@ define("DB_CHARSET", "utf8");
20 20
 // Name of the app.
21 21
 define("SITE_TITLE", "NotePost");
22 22
 
23
+// Location of the pandoc binary.  Enables exporting notes as ODT.
24
+// Leave as an empty string to hide/disable this feature in the GUI.
25
+define("PANDOC_BIN", "/usr/bin/pandoc");
23 26
 
24 27
 // URL of the AccountHub API endpoint
25 28
 define("PORTAL_API", "http://localhost/accounthub/api.php");

+ 3
- 2
static/css/home.css View File

@@ -28,11 +28,12 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
28 28
 
29 29
 .dropdown-menu {
30 30
     z-index: 9999999;
31
-    transform: translate3d(-100px, -85px, 0px) !important;
31
+    transform: translate3d(-180px, -125px, 0px) !important;
32 32
 }
33 33
 
34
-.dropdown-item {
34
+.dropdown-item, .dropdown-item a, .dropdown-item a:hover {
35 35
     color: #212121 !important;
36
+    text-decoration: none;
36 37
 }
37 38
 
38 39
 .parsedown-task-list-close {

Loading…
Cancel
Save