-
Notifications
You must be signed in to change notification settings - Fork 0
/
QRMarkDown.class.php
90 lines (72 loc) · 2.94 KB
/
QRMarkDown.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
require_once('vendor/autoload.php');
use Endroid\QrCode\QrCode;
class QRMarkDown extends \cebe\markdown\GithubMarkdown{
protected function renderLink($block)
{
if (isset($block['refkey'])) {
if (($ref = $this->lookupReference($block['refkey'])) !== false) {
$block = array_merge($block, $ref);
} else {
if (strncmp($block['orig'], '[', 1) === 0) {
return '[' . $this->renderAbsy($this->parseInline(substr($block['orig'], 1)));
}
return $block['orig'];
}
}
$old_url = '<a href="' . htmlspecialchars($block['url'], ENT_COMPAT | ENT_HTML401, 'UTF-8') . '"'
. (empty($block['title']) ? '' : ' title="' . htmlspecialchars($block['title'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE, 'UTF-8') . '"')
. '>' . $this->renderAbsy($block['text']) . '</a>';
$text = $this->renderAbsy($block['text']);
$url = htmlspecialchars($block['url'], ENT_COMPAT | ENT_HTML401, 'UTF-8');
$alt = '';
if(!empty($block['title'])){
$alt = 'alt="'. htmlspecialchars($block['title'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE, 'UTF-8') .'"';
}
$parse = parse_url($url);
if(isset($parse['host'])){
$domain = $parse['host'];
}else{
$domain = '';
}
$md5_url = md5($url); //this will be our qrcode filename
$qr_code_file = "qrcode_images/".$md5_url . ".png";
$qr_code_save_to_file = __DIR__ . "/html_out/$qr_code_file";;
$qrCode = new QrCode($url);
$qrCode->writeFile($qr_code_save_to_file);
$qr_link = "<b>$text</b> <img width='100px' $alt src='$qr_code_file'>";
return($qr_link);
}
protected function renderUrl($block)
{
$url = htmlspecialchars($block[1], ENT_COMPAT | ENT_HTML401, 'UTF-8');
$decodedUrl = urldecode($block[1]);
$secureUrlText = preg_match('//u', $decodedUrl) ? $decodedUrl : $block[1];
$text = htmlspecialchars($secureUrlText, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8');
$normal_link = "<a href=\"$url\">$text</a>";
$md5_url = md5($url); //this will be our qrcode filename
$qr_code_file = "qrcode_images/".$md5_url . ".png";
$qr_code_save_to_file = __DIR__ . "/html_out/$qr_code_file";;
$qrCode = new QrCode($url);
$qrCode->writeFile($qr_code_save_to_file);
$qr_link = "<b>$text</b> <img width='100px' $alt src='$qr_code_file'>";
return($qr_link);
}
protected function renderAutoUrl($block)
{
$href = htmlspecialchars($block[1], ENT_COMPAT | ENT_HTML401, 'UTF-8');
$decodedUrl = urldecode($block[1]);
$secureUrlText = preg_match('//u', $decodedUrl) ? $decodedUrl : $block[1];
$text = htmlspecialchars($secureUrlText, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8');
$old_link = "<a href=\"$href\">$text</a>";
$url = $href;
$alt = '';
$md5_url = md5($url); //this will be our qrcode filename
$qr_code_file = "qrcode_images/".$md5_url . ".png";
$qr_code_save_to_file = __DIR__ . "/html_out/$qr_code_file";;
$qrCode = new QrCode($url);
$qrCode->writeFile($qr_code_save_to_file);
$qr_link = "<b>$text</b> <img width='100px' $alt src='$qr_code_file'>";
return($qr_link);
}
}