-
Notifications
You must be signed in to change notification settings - Fork 3
/
plugin.php
159 lines (148 loc) · 4.47 KB
/
plugin.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
class MHerbstInsertThumbPlugin extends KokenPlugin {
function __construct() {
$this->register_shortcode('mherbst_thumbs', 'render');
}
function render($attributes) {
$query = $_SERVER['QUERY_STRING'];
/* $handle = fopen("/test.log","a");
fwrite($handle, ">>".$query."<<\n");
fwrite($handle, "StriPos:".stripos($query, "/text/slug:")."--".stripos($query, "/type:essay/")."\n");
fwrite($handle, "Stripos2:".stripos($query, "/type:page/"));
*/
if ((stripos($query, "/text/slug:") === false && !$this->data->show_in_index) && stripos($query, "/type:page/") === false)
return "";
$class = $attributes['class'];
if ($class === "") {
$class = $this->data->default_css;
}
$style="";
$margin = false;
if (is_numeric($attributes['margin']) && !empty($attributes['margin'])) {
$margin = $attributes['margin'];
}
if ($attributes['floating'] == "l") {
$style = 'style="float:left;';
if ($margin) {
$style .= ' margin-right: ' . $margin . 'px;';
}
$style .= '"'; // close style attribute
} else if ($attributes['floating'] == "r") {
$style = 'style="float:right;';
if ($margin) {
$style .= ' margin-left: ' . $margin . 'px;';
}
$style .= '"'; // close style attribute
}
if (!empty($attributes['size'])) {
$size = ' size="' . $attributes['size'] . '"';
}
else {
$size = "";
}
$width = "";
$presetVal = $attributes['preset'];
if ($attributes['width'] != "") {
$width = 'width="'.$attributes['width'].'"';
$wi = intval($attributes['width']);
// Tiny" (60px), "small" (100px), "medium" (480px), "medium_large" (800)
if ($presetVal != "no") {
if ($wi > 800) {
$presetVal = "no";
} else if ($wi > 480 && $presetVal != "ml") {
$presetVal = "ml";
} else if ($wi > 100 && ($presetVal == "t" || $presetVal == "s")) {
$presetVal = "m";
} else if ($wi > 60 && $presetVal == "t") {
$presetVal = "s";
}
}
}
$height = ($attributes['height'] != "") ? 'height="'.$attributes['height'].'"' : "";
$crop = "";
$preset = "";
if ($attributes['crop'] == "true") {
$crop = 'crop="true"';
}
if ($crop == "" && $size == "") { // ignore preset if crop is set to true or size is given
switch($presetVal) {
case "t":
$preset = 'preset="tiny"';
break;
case "s":
$preset = 'preset="small"';
break;
case "m":
$preset = 'preset="medium"';
break;
case "ml":
$preset = 'preset="medium_large"';
break;
}
}
switch($attributes['caption'])
{
case "t":
$caption = '<span class="k-content-title">{{ content.title }}</span>';
break;
case "c":
$caption = '<span class="k-content-caption">{{ content.caption }}</span>';
break;
case "b":
$caption = '<span class="k-content-title">{{ content.title }}</span> - <span class="k-content-caption">{{ content.caption }}</span>';
break;
default:
$caption = "";
break;
}
if ($caption != "")
{
$caption = '<figcaption class="k-content-text">'.$caption.'</figcaption>';
}
$addStyle = "";
if ($width != "" && $size != "") { // in this case the width must be set on the surrounding tag otherwise Koken would ignore size
$addStyle = 'style="width: '.$attributes['width'].'px"';
$width = "";
}
if ($this->data->lazy_load) {
$lazy = 'lazy="true"';
}
if ($preset == "" && $width == "" && $addStyle == "") {
$lazy = "";
$addStyle = 'style="width: 100%;"';
}
switch($attributes['link'])
{
case "lightbox":
$linkbegin = '<koken:link lightbox="true">';
break;
case "detail":
$linkbegin = "<koken:link>";
break;
case "album";
$linkbegin = '<koken:link to="album" filter:id="'.$attributes['album'].'">';
$imgdata = 'data="content.context"';
break;
case "custom";
$linkbegin = '<koken:link url="'.$attributes['custom_url'].'" target="_blank">';
break;
default:
$linkbegin = "";
}
$linkend = ($linkbegin != "") ? "</koken:link>" : "";
if ($this->data->add_link_to_caption && $caption != "" && $linkbegin != "") {
$caption = $linkbegin.$caption.$linkend;
}
return <<<HTML
<!-- koken:img {$size} {$preset} {$width} {$height} {$lazy} {$crop} add: {$addStyle} -->
<div class="k-content {$class}" {$style}>
<koken:load source="content" filter:id="{$attributes['id']}">
<figure class="k-content-embed" {$addStyle}>
{$linkbegin}<koken:img {$size} {$preset} {$width} {$height} {$lazy} {$crop} />{$linkend}
{$caption}
</figure>
</koken:load>
</div>
HTML;
}
}