Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support import of Netscape-style HTML bookmark files.
- Loading branch information
Showing
3 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/** | ||
* Horde_Data implementation for Mozilla's HTML format. | ||
* | ||
* Copyright 2013-2015 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file LICENSE for license information (ASL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/apache. | ||
* | ||
* @author Michael J Rubinsky <mrubinsk@horde.org> | ||
* @package Trean | ||
*/ | ||
class Trean_Data_Html extends Horde_Data_Base | ||
{ | ||
protected $_extension = 'html'; | ||
protected $_contentType = 'text/html'; | ||
protected $_folders = array(); | ||
|
||
public function importData($contents, $header = false) | ||
{ | ||
$data = array(); | ||
$lines = file($contents); | ||
$rows = array(); | ||
foreach ($lines as $line) { | ||
if (strpos($line, '<DT><H3') !== false) { | ||
// Start of a folder. | ||
$this->_folders[] = trim(strip_tags($line)); | ||
} elseif (strpos($line, '</DL>') !== false) { | ||
array_pop($this->_folders); | ||
// End of folder. | ||
} elseif (preg_match("/<DT><A HREF=\"*(.*?)\".*>(.*)<\/A>/", $line, $temp)) { | ||
// Bookmark. | ||
$rows[] = array( | ||
'bookmark_url' => trim($temp[1]), | ||
'bookmark_title' => trim($temp[2]), | ||
'bookmark_description' => '', | ||
'bookmark_tags' => $this->_folders, | ||
'bookmark_dt' => false, // @todo | ||
); | ||
} elseif (strpos($line, '<DD>') !== false) { | ||
// Should be description of previous bookmark. | ||
$rows[count($rows) - 1]['bookmark_description'] = trim(strip_tags($line)); | ||
} | ||
} | ||
|
||
return $rows; | ||
} | ||
|
||
/** | ||
* Takes all necessary actions for the given import step, parameters and | ||
* form values and returns the next necessary step. | ||
* | ||
* @param integer $action The current step. One of the IMPORT_* constants. | ||
* @param array $param An associative array containing needed | ||
* parameters for the current step. | ||
* | ||
* @return mixed Either the next step as an integer constant or imported | ||
* data set after the final step. | ||
* @throws Horde_Data_Exception | ||
*/ | ||
public function nextStep($action, $param = array()) | ||
{ | ||
switch ($action) { | ||
case Horde_Data::IMPORT_FILE: | ||
parent::nextStep($action, $param); | ||
return $this->importData($_FILES['import_file']['tmp_name']); | ||
} | ||
} | ||
|
||
/** | ||
* Stub to return exported data. | ||
*/ | ||
public function exportData($data, $method = 'REQUEST') | ||
{ | ||
// TODO | ||
} | ||
|
||
/** | ||
* Stub to export data to a file. | ||
*/ | ||
public function exportFile($filename, $data) | ||
{ | ||
// TODO | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters