forked from k0a1a/hotglue2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_object.inc.php
151 lines (134 loc) · 3.82 KB
/
module_object.inc.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
<?php
/*
* module_object.inc.php
* Module for handling general object properties
*
* Copyright Gottfried Haider, Danja Vasiliev 2010.
* This source code is licensed under the GNU General Public License.
* See the file COPYING for more details.
*/
@require_once('config.inc.php');
require_once('common.inc.php');
require_once('html.inc.php');
require_once('util.inc.php');
// module_image.inc.php has more information on what's going on inside modules
// (they can be easier than that one though)
function object_alter_render_early($args)
{
$elem = &$args['elem'];
$obj = $args['obj'];
if (!elem_has_class($elem, 'object')) {
return false;
}
if (!empty($obj['object-height'])) {
elem_css($elem, 'height', $obj['object-height']);
}
if (!empty($obj['object-left'])) {
elem_css($elem, 'left', $obj['object-left']);
}
if (!empty($obj['object-opacity'])) {
elem_css($elem, 'opacity', $obj['object-opacity']);
}
elem_css($elem, 'position', 'absolute');
if (!empty($obj['object-top'])) {
elem_css($elem, 'top', $obj['object-top']);
}
if (!empty($obj['object-width'])) {
elem_css($elem, 'width', $obj['object-width']);
}
if (!empty($obj['object-zindex'])) {
elem_css($elem, 'z-index', $obj['object-zindex']);
}
return true;
}
function object_alter_render_late($args)
{
$elem = $args['elem'];
$html = &$args['html'];
$obj = $args['obj'];
if (!elem_has_class($args['elem'], 'object')) {
return false;
}
if (!$args['edit']) {
// add links only for viewing
if (!empty($obj['object-link'])) {
$link = $obj['object-link'];
if(!empty($obj['object-target'])) {
$target = $obj['object-target'];
}
// resolve any aliases
$link = resolve_aliases($link, $obj['name']);
if (!is_url($link) && substr($link, 0, 1) != '#') {
// add base url for relative links that are not directed towards anchors
if (SHORT_URLS) {
$link = base_url().urlencode($link);
} else {
$link = base_url().'?'.urlencode($link);
}
}
// <a> can include block elements in html5
if (substr($html, -1) == "\n") {
$html = substr($html, 0, -1);
}
// if target is specified use it in link
if (isset($target)) {
$html = '<a href="'.htmlspecialchars($link, ENT_COMPAT, 'UTF-8').'" target="'.htmlspecialchars($target, ENT_COMPAT, 'UTF-8').'">'."\n\t".str_replace("\n", "\n\t", $html)."\n".'</a>'."\n";
} else {
$html = '<a href="'.htmlspecialchars($link, ENT_COMPAT, 'UTF-8').'">'."\n\t".str_replace("\n", "\n\t", $html)."\n".'</a>'."\n";
}
return true;
}
}
return false;
}
function object_alter_save($args)
{
$elem = $args['elem'];
$obj = &$args['obj'];
if (!elem_has_class($elem, 'object')) {
return false;
}
if (elem_css($elem, 'height') !== NULL) {
$obj['object-height'] = elem_css($elem, 'height');
} else {
unset($obj['object-height']);
}
if (elem_css($elem, 'left') !== NULL) {
$obj['object-left'] = elem_css($elem, 'left');
} else {
unset($obj['object-left']);
}
if (elem_css($elem, 'opacity') !== NULL) {
$obj['object-opacity'] = elem_css($elem, 'opacity');
} else {
unset($obj['object-opacity']);
}
if (elem_css($elem, 'top') !== NULL) {
$obj['object-top'] = elem_css($elem, 'top');
} else {
unset($obj['object-top']);
}
if (elem_css($elem, 'width') !== NULL) {
$obj['object-width'] = elem_css($elem, 'width');
} else {
unset($obj['object-width']);
}
if (elem_css($elem, 'z-index') !== NULL) {
$obj['object-zindex'] = elem_css($elem, 'z-index');
} else {
unset($obj['object-zindex']);
}
return true;
}
function object_render_page_early($args)
{
if ($args['edit']) {
if (USE_MIN_FILES) {
html_add_js(base_url().'modules/object/object-edit.min.js');
} else {
html_add_js(base_url().'modules/object/object-edit.js');
}
// add default colors
html_add_js_var('$.glue.conf.object.default_colors', expl(' ', OBJECT_DEFAULT_COLORS));
}
}