Skip to content

Commit

Permalink
add import parser
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Steffens <florian.steffens@nextcloud.com>
  • Loading branch information
Florian Steffens committed Jun 22, 2023
1 parent 2ea1158 commit aa7e4b9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/Service/ColumnTypes/TextLinkBusiness.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

namespace OCA\Tables\Service\ColumnTypes;

use OCA\Tables\Db\Column;

class TextLinkBusiness extends SuperBusiness implements IColumnTypeBusiness {

public function parseValue(string $value, ?Column $column = null): string {
// if is import from export in format "[description] ([link])"
preg_match('/(.*) \((http.*)\)/', $value, $matches);
if ($matches[0] && $matches[1]) {
return json_encode(json_encode([
'title' => $matches[1],
'resourceUrl' => $matches[2]
]));
}

preg_match('/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/', $value, $matches);
return json_encode(json_encode([
'title' => $matches[0],
'resourceUrl' => $matches[0]
]));
}
}

0 comments on commit aa7e4b9

Please sign in to comment.