|
- <?php
-
- class freaParsedown extends Parsedown {
-
- function get_BlockTypes() {
-
- return $this->BlockTypes;
-
- }
-
- function deactivate_ol() {
- $ol_triggers= array(
- "0",
- "1",
- "2",
- "3",
- "4",
- "5",
- "6",
- "7",
- "8",
- "9"
- );
-
- foreach ($ol_triggers as $key) {
- unset($this->BlockTypes[$key]);
- }
- }
-
-
- function add_language_to_link_target($href) {
- $f3 = \Base::instance();
- $data = [];
- $base = substr($href,0,strpos($href,'?') ? : strlen($href));
- parse_str(parse_url($href,PHP_URL_QUERY),$data);
- $fragment = parse_url($href,PHP_URL_FRAGMENT);
-
- if ($f3->get('LANG') != $f3->get('default_lang')) {
- if (!array_key_exists('lang',$data)) {
- $data['lang'] = $f3->get('LANG');
- }
- }
-
- $new = $base;
- if (count($data) > 0) {
- $new .= "?" . http_build_query($data);
- }
- if ($fragment) {
- $new .= "#" . $fragment;
- }
-
- return $new;
- }
-
-
- 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],
- ),
- ),
- );
- }
- }
-
- 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'];
- }
-
- $Element['attributes']['data-link-text'] = $Element['text'];
- $url=&$Element['attributes']['href'];
- if (strpos($url,':') === FALSE) {
- $url = $this->add_language_to_link_target($url);
- }
-
-
-
- return array(
- 'extent' => $extent,
- 'element' => $Element,
- );
- }
-
- 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;
- }
- }
-
- 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,
- ),
- ),
- );
- }
- }
-
-
-
- }
|