helper.php
4.31 KB
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
<?php
class N2ImageHelperAbstract {
public static $imagePaths = array();
public static $imageUrls = array();
public static $siteKeywords = array();
public static $protocolRelative = 1;
public static function init() {
$parameters = array(
'siteKeywords' => self::$siteKeywords,
'imageUrls' => self::$imageUrls,
'protocolRelative' => intval(self::$protocolRelative)
);
$parameters['placeholderImage'] = '$system$/images/placeholder/image.png';
$parameters['placeholderRepeatedImage'] = '$system$/images/placeholder/image.png';
N2JS::addFirstCode('new NextendImageHelper(' . json_encode($parameters) . ', ' . N2ImageHelper::getLightboxFunction() . ',' . N2ImageHelper::getLightboxMultipleFunction() . ', ' . N2ImageHelper::getLightboxFoldersFunction() . ');');
}
public static function dynamic($image) {
$_image = self::protocolRelative($image);
foreach (self::$imageUrls AS $i => $imageUrl) {
if (strpos($_image, $imageUrl) === 0) {
$image = self::$siteKeywords[$i] . substr($_image, strlen($imageUrl));
break;
}
}
return $image;
}
public static function fixed($image, $needPath = false) {
foreach (self::$imageUrls AS $i => $imageUrl) {
if (strpos($image, self::$siteKeywords[$i]) === 0) {
$image = ($needPath ? self::$imagePaths[$i] : $imageUrl) . substr($image, strlen(self::$siteKeywords[$i]));
break;
}
}
return $image;
}
public static function addKeyword($keyword, $path, $url) {
array_unshift(self::$siteKeywords, $keyword);
array_unshift(self::$imagePaths, $path);
if (N2Settings::get('protocol-relative', '1')) {
$url = self::protocolRelative($url);
}
array_unshift(self::$imageUrls, $url);
}
public static function protocolRelative($url) {
if (self::$protocolRelative) {
return preg_replace('/^http(s)?:\/\//', '//', $url);
}
return $url;
}
public static function export() {
$def = array();
for ($i = 0; $i < count(self::$siteKeywords); $i++) {
$def[self::$siteKeywords[$i]] = self::$imageUrls[$i];
}
return $def;
}
public static function getLightboxFoldersFunction() {
return 'function (callback) {
this.joomlaModal = new NextendModal({
zero: {
fit: true,
size: [
980,
680
],
title: "' . n2_('Images') . '",
controlsClass: "n2-modal-controls-side",
controls: [\'<a href="#" class="n2-button n2-button-normal n2-button-l n2-radius-s n2-button-green n2-uc n2-h4">' . n2_('Select') . '</a>\'],
content: \'\',
fn: {
show: function () {
this.content.append(nextend.browse.getNode("folder"));
this.controls.find(".n2-button-green")
.on("click", $.proxy(function (e) {
e.preventDefault();
this.hide(e);
callback(nextend.browse.getCurrentFolder());
}, this));
}
}
}
}, true);
}';
}
public static function SVGToBase64($image) {
$ext = pathinfo($image, PATHINFO_EXTENSION);
if (substr($image, 0, 1) == '$' && $ext == 'svg') {
return 'data:image/svg+xml;base64,' . n2_base64_encode(N2Filesystem::readFile(N2ImageHelper::fixed($image, true)));
}
return N2ImageHelper::fixed($image);
}
public static function readSVG($image) {
return N2Filesystem::readFile(N2ImageHelper::fixed($image, true));
}
public static function onImageUploaded($filename) {
}
}
N2Loader::import('libraries.image.helper', 'platform');
N2ImageHelper::$protocolRelative = intval(N2Settings::get('protocol-relative', '1'));
N2ImageHelper::addKeyword('$', N2Filesystem::getBasePath(), N2Uri::getBaseUri());