-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexportnote.php
More file actions
executable file
·36 lines (28 loc) · 1.07 KB
/
exportnote.php
File metadata and controls
executable file
·36 lines (28 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php $sqlpath = $_SERVER['DOCUMENT_ROOT'];
$sqlpath .= "/sql-connect.php";
include_once($sqlpath);
$exportID = $_REQUEST['exportID'];
$sql = "SELECT title,body,lineage FROM notes WHERE id LIKE '$exportID'";
$sqldata = mysqli_query($dbcon, $sql) or die('error getting data');
while($row = mysqli_fetch_array($sqldata, MYSQLI_ASSOC)) {
$title = $row['title'];
$remtitle = '# '.$row['title'];
$body = ltrim(substr($row['body'],strlen($remtitle)));
$path = explode('-', $row['lineage']);
array_pop($path);
$newpath = '';
foreach($path as $x){
$sql = "SELECT title FROM notes WHERE id LIKE '$x'";
$sqldata = mysqli_query($dbcon, $sql) or die('error getting data');
while($row = mysqli_fetch_array($sqldata, MYSQLI_ASSOC)) {
$newpath = $newpath.$row['title'].'/';
}
}
if (!is_dir('exports/'.$newpath)) {
// dir doesn't exist, make it
mkdir('exports/'.$newpath, 0777, true);
}
echo file_put_contents('exports/'.$newpath.$title.'.md', $body);
// echo file_put_contents('exports/test.md', $newpath);
}
?>