Browse Source

fix: parsedown-extra dependency, typo in email.php width attribute in CEimage

master
Dom SP 3 years ago
parent
commit
9508d835f2
4 changed files with 46 additions and 151 deletions
  1. +1
    -1
      app/controller/email.php
  2. +28
    -142
      app/freaParsedown.php
  3. +15
    -7
      app/modules/filesinfolders.php
  4. +2
    -1
      composer.json

+ 1
- 1
app/controller/email.php View File

@@ -96,7 +96,7 @@ class Email {
}

if ($success) {
$f3->reroute("/email/success?email=".urlsafe_b64encode($email)."&lang="$f3->get('LANG'));
$f3->reroute("/email/success?email=".urlsafe_b64encode($email)."&lang=".$f3->get('LANG'));
} else {
#$f3->reroute("/email/error");
echo \Template::instance()->render($template,'text/html');

+ 28
- 142
app/freaParsedown.php View File

@@ -1,6 +1,6 @@
<?php

class freaParsedown extends Parsedown {
class freaParsedown extends ParsedownExtra {
function get_BlockTypes() {

@@ -55,163 +55,49 @@ class freaParsedown extends Parsedown {
protected function inlineEmailTag($Excerpt)
{
$hostnameLabel = '[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?';

$commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]++@'
. $hostnameLabel . '(?:\.' . $hostnameLabel . ')*';

if (strpos($Excerpt['text'], '>') !== false
and preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt['text'], $matches)
){
$url = $matches[1];

if ( ! isset($matches[2]))
{
$url = 'mailto:' . $url;
}

return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'a',
'text' => $matches[1],
'attributes' => array(
'href' => $url,
'data-link-text' => $matches[1],
),
),
);
$Link = parent::inlineEmailTag($Excerpt);
if (isset($Link)) {
$Link['element']['attributes'] += ['data-link-text' => $Link['element']['text']];
}
return $Link;
}

protected function inlineLink($Excerpt)
{
$Element = array(
'name' => 'a',
'handler' => 'line',
'nonNestables' => array('Url', 'Link'),
'text' => null,
'attributes' => array(
'href' => null,
'title' => null,
),
);

$extent = 0;

$remainder = $Excerpt['text'];

if (preg_match('/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches))
{
$Element['text'] = $matches[1];

$extent += strlen($matches[0]);

$remainder = substr($remainder, $extent);
}
else
{
return;
}

if (preg_match('/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*"|\'[^\']*\'))?\s*[)]/', $remainder, $matches))
{
$Element['attributes']['href'] = $matches[1];

if (isset($matches[2]))
{
$Element['attributes']['title'] = substr($matches[2], 1, - 1);
}

$extent += strlen($matches[0]);
}
else
{
if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches))
{
$definition = strlen($matches[1]) ? $matches[1] : $Element['text'];
$definition = strtolower($definition);

$extent += strlen($matches[0]);
}
else
{
$definition = strtolower($Element['text']);
}

if ( ! isset($this->DefinitionData['Reference'][$definition]))
{
return;
}

$Definition = $this->DefinitionData['Reference'][$definition];

$Element['attributes']['href'] = $Definition['url'];
$Element['attributes']['title'] = $Definition['title'];
}
$Link = parent::inlineLink($Excerpt);
$Element['attributes']['data-link-text'] = $Element['text'];
$url=&$Element['attributes']['href'];
if (strpos($url,':') === FALSE) {
$url = $this->add_language_to_link_target($url);
if (isset($Link)) {
$Link['element']['attributes'] += ['data-link-text' => $Link['element']['text']];
$url=&$Link['element']['attributes']['href'];
if (strpos($url,':') === FALSE) {
$url = $this->add_language_to_link_target($url);
}
$Link['extent'] = $Link['extent'];
}
return array(
'extent' => $extent,
'element' => $Element,
);
return $Link;
}

protected function inlineUrl($Excerpt)
{
if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/')
{
return;
}

if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE))
{
$url = $matches[0][0];

$Inline = array(
'extent' => strlen($matches[0][0]),
'position' => $matches[0][1],
'element' => array(
'name' => 'a',
'text' => $url,
'attributes' => array(
'href' => $url,
'data-link-text' => $url,
),
),
);

return $Inline;
$Link = parent::inlineUrl($Excerpt);
if (isset($Link)) {
$Link['element']['attributes'] += ['data-link-text' => $Link['element']['text']];
}
return $Link;
}
protected function inlineUrlTag($Excerpt)
{
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\w+:\/{2}[^ >]+)>/i', $Excerpt['text'], $matches))
{
$url = $matches[1];

return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'a',
'text' => $url,
'attributes' => array(
'href' => $url,
'data-link-text' => $url,
),
),
);
$Link = parent::inlineUrlTag($Excerpt);
if (isset($Link)) {
$Link['element']['attributes'] += ['data-link-text' => $Link['element']['text']];
}
return $Link;
}
}

+ 15
- 7
app/modules/filesinfolders.php View File

@@ -399,7 +399,7 @@ class FilesInFolders {
case 'small-text':
if(count($body)) {
$new=sprintf("<div class=\"smalltext\">%s</div>",
implode("\n",$body)
$md->text(implode("\n",$body))
);
} else {
$new=sprintf("<span class=\"smalltext\">%s</span>",
@@ -867,7 +867,15 @@ class CEimage
$this->structs = &$structs;
$this->content = &$content;
}

function is_width($string) {
$pattern="/^[0-9]+%$/";
if (preg_match($pattern,$string)) {
return true;
} else {
return false;
}
}
function index() {
$md = new \freaParsedown();
$request = $this->r;
@@ -899,10 +907,9 @@ class CEimage
$class = 'full';
}
if (isset($request[3])) {
$gallery = 'gallery';
} else {
$gallery = 'fl';
}
$width=self::is_width($request[3]) ? $request[3] : false;
}
$gallery = "gallery";
// image orientation?
$img = new \Image($image);
// $ratio = "landscape";
@@ -923,12 +930,13 @@ class CEimage
}
$new=sprintf("<div class='content_element_image %s'>"
."<div class=\"media %s\"><a href=\"%s\" class=\"$gallery\"><img src=\"%s\" alt=\"user supplied image\" /></a></div>"
."<div class=\"media %s\" %s><a href=\"%s\" class=\"$gallery\"><img src=\"%s\" alt=\"user supplied image\" /></a></div>"
."<img src=\"%s\" style=\"display:none;\" alt=\"user supplied image\" />"
."<div class=\"caption\">%s</div>"
."</div>",
$class,
$ratio,
($width ? "style=\"flex-basis:$width;\"" : ''),
$cached->get_src(1600),
$cached->get_src(1600),
$cached->get_src(1600),

+ 2
- 1
composer.json View File

@@ -5,6 +5,7 @@
"vendor-dir":"lib"
},
"require": {
"bcosca/fatfree-core": "dev-master"
"bcosca/fatfree-core": "dev-master",
"erusev/parsedown-extra": "^0.8.1"
}
}

Loading…
Cancel
Save