Skip to content

Commit

Permalink
Added new HTML export format. Supports the Netscape HTML export spec,…
Browse files Browse the repository at this point in the history
… the same spec that Unmark already imports. Export include titles, tags, and notes. Addresses #263
  • Loading branch information
cdevroe committed Jun 24, 2020
1 parent 76ff92d commit edad681
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 4 deletions.
109 changes: 109 additions & 0 deletions application/controllers/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,113 @@ public function index()
}
}

/**
* Generate HTML export file for current user
* Spec: Based on Netscape / Firefox export HTML
*/
public function html()
{

$html = "<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file.
It will be read and overwritten.
DO NOT EDIT! -->
<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">
<TITLE>Unmark Export</TITLE>
<H1>Bookmarks</H1>" . "\n\n";

$html .= "<DL>" . "\n";
// Enable export library
$this->load->library('JSONExport');
// Add import version info
//$this->jsonexport->addMeta('export_version', self::EXPORT_FILE_VERSION);
//$this->jsonexport->addMeta('export_date', date('Y-m-d H:i:s'));
// Retrieve user marks
$this->load->model('users_to_marks_model', 'user_marks');
$where = 'users_to_marks.user_id='. $this->user_id;
$marksCount = $this->user_marks->count($where);
// Number of marks
//$this->jsonexport->addMeta('marks_count', $marksCount);
$pages = ceil((double) $marksCount / (double) self::PAGE_SIZE);
// Get page of data
for($curPage=1;$curPage<=$pages;$curPage++){
$pageResults = $this->user_marks->readComplete($where, self::PAGE_SIZE, $curPage);

// Add all retrieved marks
if(is_array($pageResults)){
foreach($pageResults as $key=>$singleMark){

//$this->jsonexport->addMark($singleMark);
//print_r($key);
//print_r($singleMark);
$html .= "<DT><A
HREF=\"" . $singleMark->url . "\"
ADD_DATE=\"" . strtotime( $singleMark->created_on ) . "\"";
if ( !empty($singleMark->tags) && count($singleMark->tags) > 0 ) :
//print_r($singleMark->tags);
$tags = "";

foreach($singleMark->tags as $tag=>$meta) {
$tags .= $tag . ",";
}

$html .= " TAGS=" . $tags;
endif;

$html .= ">" . $singleMark->title . "</A>" . "\n";

if ( !empty($singleMark->notes) ) :
$html .= "<DD>" . $singleMark->notes . "\n\n";
else :
$html .= "\n";
endif;
}
// Add single mark
} else if(!empty($pageResults)){

//$this->jsonexport->addMark($pageResults);
$singleMark = $pageResults;
//$this->jsonexport->addMark($singleMark);
//print_r($key);
//print_r($singleMark);
$html .= "<DT><A
HREF=\"" . $singleMark->url . "\"
ADD_DATE=\"" . strtotime( $singleMark->created_on ) . "\"";
if ( !empty($singleMark->tags) && count($singleMark->tags) > 0 ) :
//print_r($singleMark->tags);
$tags = "";

foreach($singleMark->tags as $tag=>$meta) {
$tags .= $tag . ",";
}

$html .= " TAGS=" . $tags;
endif;

$html .= ">" . $singleMark->title . "</A>" . "\n";

if ( !empty($singleMark->notes) ) :
$html .= "<DD>" . $singleMark->notes . "\n\n";
else :
$html .= "\n";
endif;
}
}

$html .= "</DL>" . "\n\n";

echo $html;
exit;

// Write the file as attachment
//$file = $this->jsonexport->getFileForOutput();
header('Content-type: text/html');
header('Content-Disposition: attachment; filename=' . 'unmark-export.html');

echo $html;
//while (!$file->eof()) {
// $this->output->append_output($file->fgets());
//}
}

}
9 changes: 7 additions & 2 deletions application/views/layouts/userforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@
<div class="loginInner">
<div class="export">
<header>
<h1><?php echo unmark_phrase('Export All Marks') ?></h1>
<h1><?php echo unmark_phrase('Exporting Marks') ?></h1>
</header>
<a data-action="export_data" class="exportbtn action" href="#"><?php echo unmark_phrase('Export File') ?></a>
<div class="to-unmark">
<a data-action="export_data" class="exportbtn action" href="#"><?php echo unmark_phrase('Export Unmark File') ?></a>
</div>
<div class="to-html">
<a data-action="export_data_html" class="exportbtn action" href="#"><?php echo unmark_phrase('Export HTML File') ?></a>
</div>
</div>
<div class="import">
<header>
Expand Down
2 changes: 1 addition & 1 deletion assets/css/partials/_overlays.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
padding-bottom: 20px;
}
}
.from-unmark, .from-other {
.from-unmark, .from-other, .to-html, .to-unmark {
padding: 0 0 12px;
p {
font-size: 12px;
Expand Down
7 changes: 6 additions & 1 deletion assets/js/unmark.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,16 @@
}
};

// Export Data
// Export Data to Unmark
unmark.export_data = function () {
return window.location.href = "/export";
};

// Export Data to HTML
unmark.export_data_html = function () {
return window.location.href = "/export/html";
};

// Import Data
unmark.import_data = function () {
return $('#importerUnmark').trigger('click');
Expand Down

0 comments on commit edad681

Please sign in to comment.