mirror of
https://github.com/owncloud/bookmarks.git
synced 2025-02-17 14:54:33 +01:00
First try for a Bookmark import
This commit is contained in:
parent
b6d4274abe
commit
2328cc1ec8
@ -309,4 +309,28 @@ class OC_Bookmarks_Bookmarks{
|
||||
public static function searchBookmarks($search_words) {
|
||||
return self::findBookmarks(0, 'id', $search_words, false);
|
||||
}
|
||||
|
||||
public static function importFile($file){
|
||||
libxml_use_internal_errors(true);
|
||||
$dom = new domDocument();
|
||||
|
||||
$dom->loadHTMLFile($file);
|
||||
$links = $dom->getElementsByTagName('a');
|
||||
$things = array();
|
||||
|
||||
OCP\DB::beginTransaction();
|
||||
foreach($links as $link) {
|
||||
$title = $link->nodeValue;
|
||||
$ref = $link->getAttribute("href");
|
||||
$tag_str = '';
|
||||
if($link->hasAttribute("tags"))
|
||||
$tag_str = $link->getAttribute("tags");
|
||||
$tags = explode(',' , $tag_str);
|
||||
|
||||
self::addBookmark($ref, $title, $tags);
|
||||
//$things[] = array('title' => $title, 'ref'=>$ref, 'tags' => $tags);
|
||||
}
|
||||
OCP\DB::commit();
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
29
settings.php
29
settings.php
@ -6,6 +6,31 @@
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
$tmpl = new OCP\Template( 'bookmarks', 'settings');
|
||||
OCP\App::checkAppEnabled('bookmarks');
|
||||
|
||||
return $tmpl->fetchPage();
|
||||
if (isset($_POST['bm_import'])) {
|
||||
$error = array();
|
||||
|
||||
$file = $_FILES['bm_import']['tmp_name'];
|
||||
if($_FILES['bm_import']['type'] =='text/html') {
|
||||
$error = OC_Bookmarks_Bookmarks::importFile($file);
|
||||
|
||||
} else {
|
||||
$error[]= array('error' => 'Unsupported file type for import',
|
||||
'hint' => '');
|
||||
}
|
||||
|
||||
// Any problems?
|
||||
if(count($error)){
|
||||
$tmpl = new OCP\Template('bookmarks', 'settings');
|
||||
$tmpl->assign('error',$error);
|
||||
//return $tmpl->fetchPage();
|
||||
} else {
|
||||
// Went swimmingly!
|
||||
$tmpl = new OCP\Template('bookmarks', 'settings');
|
||||
//return $tmpl->fetchPage();
|
||||
}
|
||||
} else {
|
||||
$tmpl = new OCP\Template( 'bookmarks', 'settings');
|
||||
return $tmpl->fetchPage();
|
||||
}
|
||||
|
@ -15,3 +15,18 @@
|
||||
?>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
<form id="import_bookmark" action="#" method="post" enctype="multipart/form-data">
|
||||
<fieldset class="personalblock">
|
||||
<?php if(isset($_['error'])): ?>
|
||||
<h3><?php echo $_['error']['error']; ?></h3>
|
||||
<p><?php echo $_['error']['hint']; ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<legend><strong><?php echo $l->t('Import bookmarks');?></strong></legend>
|
||||
</p>
|
||||
<p><input type="file" id="bm_import" name="bm_import" style="width:180px;"><label for="bm_import"> <?php echo $l->t('Bookmark html file');?></label>
|
||||
</p>
|
||||
<input type="submit" name="bm_import" value="<?php echo $l->t('Import'); ?>" />
|
||||
</fieldset>
|
||||
</form>
|
||||
|
Loading…
x
Reference in New Issue
Block a user