mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
clickable urls in task title and v1 note supports IDN (fixes GH-12)
This commit is contained in:
parent
c4873ff3d3
commit
9fcafb7f8a
3 changed files with 36 additions and 5 deletions
|
|
@ -532,7 +532,8 @@ function prepareTaskRow($r)
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'id' => $r['id'],
|
'id' => $r['id'],
|
||||||
'title' => htmlspecialchars( $r['title'] ),
|
'title' => titleMarkup( $r['title'] ),
|
||||||
|
'titleText' => (string)$r['title'],
|
||||||
'listId' => $r['list_id'],
|
'listId' => $r['list_id'],
|
||||||
'date' => htmlarray($dCreated),
|
'date' => htmlarray($dCreated),
|
||||||
'dateInt' => (int)$r['d_created'],
|
'dateInt' => (int)$r['d_created'],
|
||||||
|
|
|
||||||
|
|
@ -31,17 +31,47 @@ function mttMarkup_v1($s)
|
||||||
$s = preg_replace("~<i>([\s\S]*?)</i>~i", "${c1}i${c2}\$1${c1}/i${c2}", $s);
|
$s = preg_replace("~<i>([\s\S]*?)</i>~i", "${c1}i${c2}\$1${c1}/i${c2}", $s);
|
||||||
$s = preg_replace("~<u>([\s\S]*?)</u>~i", "${c1}u${c2}\$1${c1}/u${c2}", $s);
|
$s = preg_replace("~<u>([\s\S]*?)</u>~i", "${c1}u${c2}\$1${c1}/u${c2}", $s);
|
||||||
$s = preg_replace("~<s>([\s\S]*?)</s>~i", "${c1}s${c2}\$1${c1}/s${c2}", $s);
|
$s = preg_replace("~<s>([\s\S]*?)</s>~i", "${c1}s${c2}\$1${c1}/s${c2}", $s);
|
||||||
$s = htmlspecialchars($s); //escape all elements, except above
|
$s = htmlspecialchars($s, ENT_QUOTES); //escape all elements, except above
|
||||||
$s = str_replace( [$c1, $c2], ['<','>'], $s ); //unhide
|
$s = str_replace( [$c1, $c2], ['<','>'], $s ); //unhide
|
||||||
$s = nl2br($s);
|
$s = nl2br($s);
|
||||||
|
|
||||||
// make links from text starting with 'www.'
|
// make links from text starting with 'www.'
|
||||||
$s = preg_replace( "/(^|\s|>)(www\.([\w\#$%&~\/.\-\+;:=,\?\[\]@]+?))(,|\.|:|)?(?=\s|"|<|>|\"|<|>|$)/i" , '$1<a href="http://$2" target="_blank">$2</a>$4' , $s );
|
$s = preg_replace(
|
||||||
|
"/(^|\s|>)(www\.([\w\#$%&~\/.\-\+;:=,\?\[\]@]+?))(,|\.|:|)?(?=\s|"|<|>|\"|<|>|$)/iu" ,
|
||||||
|
'$1<a href="http://$2" target="_blank">$2</a>$4' ,
|
||||||
|
$s
|
||||||
|
);
|
||||||
|
|
||||||
// make link from text starting with protocol like 'http://'
|
// make link from text starting with protocol like 'http://'
|
||||||
$s = preg_replace( "/(^|\s|>)([a-z]+:\/\/([\w\#$%&~\/.\-\+;:=,\?\[\]@]+?))(,|\.|:|)?(?=\s|"|<|>|\"|<|>|$)/i" , '$1<a href="$2" target="_blank">$2</a>$4' , $s);
|
$s = preg_replace(
|
||||||
|
"/(^|\s|>)([a-z]+:\/\/([\w\#$%&~\/.\-\+;:=,\?\[\]@]+?))(,|\.|:|)?(?=\s|"|<|>|\"|<|>|$)/iu" ,
|
||||||
|
'$1<a href="$2" target="_blank">$2</a>$4' ,
|
||||||
|
$s
|
||||||
|
);
|
||||||
|
|
||||||
return $s;
|
return $s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert raw title to html with allowed urls
|
||||||
|
function titleMarkup($title)
|
||||||
|
{
|
||||||
|
//escape all unsafe
|
||||||
|
$title = htmlspecialchars($title, ENT_QUOTES);
|
||||||
|
|
||||||
|
// make links from text starting with 'www.'
|
||||||
|
$title = preg_replace(
|
||||||
|
"/(^|\s|>)(www\.([\w\#$%&~\/.\-\+;:=,\?\[\]@]+?))(,|\.|:|)?(?=\s|"|<|>|\"|<|>|$)/iu" ,
|
||||||
|
'$1<a href="http://$2" target="_blank">$2</a>$4' ,
|
||||||
|
$title
|
||||||
|
);
|
||||||
|
|
||||||
|
// make link from text starting with protocol like 'http://'
|
||||||
|
$title = preg_replace(
|
||||||
|
"/(^|\s|>)([a-z]+:\/\/([\w\#$%&~\/.\-\+;:=,\?\[\]@]+?))(,|\.|:|)?(?=\s|"|<|>|\"|<|>|$)/iu" ,
|
||||||
|
'$1<a href="$2" target="_blank">$2</a>$4' ,
|
||||||
|
$title
|
||||||
|
);
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
@ -1496,7 +1496,7 @@ function editTask(id)
|
||||||
if(!item) return false;
|
if(!item) return false;
|
||||||
// no need to clear form
|
// no need to clear form
|
||||||
var form = document.getElementById('taskedit_form');
|
var form = document.getElementById('taskedit_form');
|
||||||
form.task.value = dehtml(item.title);
|
form.task.value = item.titleText;
|
||||||
form.note.value = item.noteText;
|
form.note.value = item.noteText;
|
||||||
form.id.value = item.id;
|
form.id.value = item.id;
|
||||||
form.tags.value = item.tags.split(',').join(', ');
|
form.tags.value = item.tags.split(',').join(', ');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue