-
Notifications
You must be signed in to change notification settings - Fork 37
/
functions.php
93 lines (79 loc) · 2.68 KB
/
functions.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
91
92
93
<?php
ini_set("error_reporting", "E_ALL & ~E_NOTICE");
// 解析文章:暂只是添加 h3,h4 锚点,为 <img> 添加 data-action
function parseContent($content)
{
// 添加 h3,h4 锚点
$ftitle = array();
preg_match_all('/<h([3-4])>(.*?)<\/h[3-4]>/', $content, $title);
$num = count($title[0]);
for ($i = 0; $i < $num; $i++) {
$f = $title[2][$i];
$type = $title[1][$i];
if ($type == '3') {
$ff = '<h3 id="anchor-' . $i . '" class="torAn">' . $f . '</h3>';
}
if ($type == '4') {
$ff = '<h4 id="anchor-' . $i . '" class="torAn">' . $f . '</h4>';
}
array_push($ftitle, $ff);
}
for ($i = 0; $i < $num; $i++) {
$content = str_replace_limit($title[0][$i], $ftitle[$i], $content);
}
// <img> 添加 data-action
$fimg = array();
preg_match_all('/<img (.*?)>/', $content, $img);
$num = count($img[0]);
for ($i = 0; $i < $num; $i++) {
$f = $img[1][$i];
$ff = '<img data-action="zoom" ' . $f . '>';
array_push($fimg, $ff);
}
for ($i = 0; $i < $num; $i++) {
$content = str_replace_limit($img[0][$i], $fimg[$i], $content);
}
print_r($content);
}
function str_replace_limit($search, $replace, $subject, $limit = 1)
{
if (is_array($search)) {
foreach ($search as $k => $v) {
$search[$k] = '`' . preg_quote($search[$k], '`') . '`';
}
} else {
$search = '`' . preg_quote($search, '`') . '`';
}
return preg_replace($search, $replace, $subject, $limit);
}
function post_tor($content)
{
$f = '';
preg_match_all('/<h[3-4]>(.*?)<\/h[3-4]>/', $content, $tor_i);
$num = count($tor_i[0]);
if ($num == 0) {
return '';
} else {
for ($i = 0; $i < $num; $i++) {
$a = '<a id="tor-' . $i . '" class="torList" href="#anchor-' . $i . '">' . $tor_i[0][$i] . '</a>';
$f = $f . $a;
}
$f = str_replace('<h3>', '<span class="tori">', $f);
$f = str_replace('</h3>', '</span><br>', $f);
$f = str_replace('<h4>', '<span class="torii">', $f);
$f = str_replace('</h4>', '</span><br>', $f);
return '<a href="#main">Title</a><br>' . $f . '<a href="javascript:goToComment();">Comment</a>';
}
}
function post_config($thiss)
{
$content = $thiss->content;
$rst = ['isTorTree' => (($GLOBALS['isTorTree'] == 'on') ? 1 : 0)];
preg_match_all('/<!-- isTorTree:(.*?); -->/', $content, $isTor);
if (@$thiss->fields->tor == 'on' || $isTor[1][0] == 'on') {
$rst['isTorTree'] = 1;
} else if (@$thiss->fields->tor == 'off' || $isTor[1][0] == 'off') {
$rst['isTorTree'] = 0;
}
return $rst;
}