-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwrapper_class.php
162 lines (136 loc) · 4.24 KB
/
wrapper_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
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
160
161
162
<?php
/*
* Wrapper - an e107 plugin by Tijn Kuyper
*
* Copyright (C) 2015-2022 Tijn Kuyper (http://www.tijnkuyper.nl)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*/
class Wrapper
{
public int $id;
public $errorMessage = '';
public $frontpageTitle;
public $frontpageText;
public function __construct(int $id)
{
// Set ID property
$this->id = $id;
// Check and set frontpage title
if(e107::pref('wrapper', 'frontpage_title'))
{
$this->frontpageTitle = e107::pref('wrapper', 'frontpage_title');
}
// Check and set frontpage title
if(e107::pref('wrapper', 'frontpage_text'))
{
$this->frontpageText = e107::pref('wrapper', 'frontpage_text');
}
$this->checkErrors($id);
}
private function checkErrors($id)
{
// Check if ID is filled in
if(empty($id))
{
// Check if frontpage title is set. If not set, show error message. Otherwise continue without error message.
if($this->frontpageTitle == "")
{
$this->errorMessage = LAN_WRAPPER_ERR1;
return;
}
return;
}
// Check for ID validity - display error if ID is not found in the database
if(!e107::getDb()->select("wrapper", "*", "wrapper_id='$id'"))
{
$this->errorMessage = LAN_WRAPPER_ERR2;
return;
}
// Wrapper exists - get all the info
$wrapper_query = e107::getDb()->retrieve('wrapper', '*', 'wrapper_id='.$id);
// Check for userclass access
if(!check_class($wrapper_query['wrapper_userclass']))
{
$this->errorMessage = LAN_WRAPPER_ERR3;
return;
}
// Check if wrapper is active
if(!$wrapper_query['wrapper_active'])
{
$this->errorMessage = LAN_WRAPPER_ERR4;
return;
}
}
public function getCaption($id)
{
// Return LAN_ERROR is error is detected
if($this->errorMessage)
{
return LAN_ERROR;
}
// Check if no ID entered, but no errorMessage. Likely there's a frontpage title set. Check, and show that. Otherwise fallback to LAN_ERROR.
if(empty($id))
{
if($this->frontpageTitle)
{
return $this->frontpageTitle;
}
else
{
return LAN_ERROR;
}
}
// No errors, no frontpage title/text, so return wrapper title as stored in DB
return e107::getDb()->retrieve('wrapper', 'wrapper_title', 'wrapper_id='.$id);
}
public function showWrapper($id = '', $wrap_pass = '')
{
if($this->errorMessage)
{
return e107::getMessage()->addError($this->errorMessage)->render();
}
// Check if no ID entered, but no errorMessage. Likely there's a frontpage text set. Check, and show that. Otherwise fallback to LAN_WRAPPER_ERR1.
if(empty($id))
{
if($this->frontpageText)
{
return e107::getParser()->toHTML($this->frontpageText, true);
}
else
{
return e107::getMessage()->addError(LAN_WRAPPER_ERR1)->render();
}
}
// No erorr, wrapper exists - get all the info
$wrapper_query = e107::getDb()->retrieve('wrapper', '*', 'wrapper_id='.$id);
// Convert scrollbars DB value to HTML values used in iframe tag
$scrollbars = ($wrapper_query['wrapper_scrollbars'] == 1 ? 'yes' : 'no');
//print_a("w: ".$wrapper_query['wrapper_width']." h:".$wrapper_query['wrapper_height']);
// Specific values set for width and height, nothing special needed
if($wrapper_query['wrapper_width'] != 0 && $wrapper_query['wrapper_height'] != 0)
{
$width = $wrapper_query['wrapper_width'];
$height = $wrapper_query['wrapper_height'];
$size = "width='".$width."' height='".$height."'";
}
// Width = fullscreen, Height = specific
if($wrapper_query['wrapper_width'] == 0 && $wrapper_query['wrapper_height'] !== 0)
{
$size = "width='100%' height='".$wrapper_query['wrapper_height']."'";
}
// Width = specific, Height = fullscreen
if($wrapper_query['wrapper_width'] == 0 && $wrapper_query['wrapper_height'] !== 0)
{
$size = "width='".$wrapper_query['wrapper_width']."' style='height: 100em;'";
}
// Completely fullscreen
if($wrapper_query['wrapper_width'] == 0 && $wrapper_query['wrapper_height'] == 0)
{
$size = "width='100%' style='height: 100em;'";
}
$iframe = "<iframe id='wrapper-".$wrapper_query['wrapper_id']."' src='".$wrapper_query['wrapper_url'].$wrap_pass."' ".$size." scrolling='".$scrollbars."' frameborder='0'></iframe>";
return $iframe;
}
}