-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTwitterCarousel.php
More file actions
executable file
·265 lines (194 loc) · 6.23 KB
/
TwitterCarousel.php
File metadata and controls
executable file
·265 lines (194 loc) · 6.23 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
defined('is_running') or die('Not an entry point...');
class TwitterCarousel{
const content_key = 'Carousel232';
/**
* Determine if the $type matches this content key
*
*/
static function ContentKeyMatch($type){
global $addonFolderName;
if( $addonFolderName === $type ){ //legacy support
return true;
}
if( $type === self::content_key ){
return true;
}
}
/**
* @static
*
*/
static function SectionTypes($section_types, $generated_key = false ){
$section_types[self::content_key] = array('label' => 'Bootstrap Carousel Gallery');
return $section_types;
}
/**
* @static
*
*/
static function SectionToContent($section_data){
global $dataDir;
if( !self::ContentKeyMatch($section_data['type']) ){
return $section_data;
}
//update content
if( !isset($section_data['content_version']) ){
$section_data['content'] = self::GenerateContent($section_data);
}
self::AddComponents();
return $section_data;
}
static function GenerateContent($section_data){
global $dataDir;
$section_data += array('images'=>array(),'height'=>'400');
$id = 'carousel_'.time();
$images = '';
$indicators = '';
$j = 0;
foreach($section_data['images'] as $i => $img){
if( empty($img) ){
continue;
}
$caption = trim($section_data['captions'][$i]);
$class = '';
if( $j == 0 ){
$class = 'active';
}
//images
$caption_class = '';
if( empty($caption) ){
$caption_class = 'no_caption';
}
$images .= '<div class="item '.$class.'">'
.'<img src="'.common::GetDir('/include/imgs/blank.gif').'" style="background-image:url('.$img.')" alt="">'
.'<div class="caption carousel-caption '.$caption_class.'">'.$caption.'</div>'
.'</div>';
//indicators
$thumb_path = common::ThumbnailPath($img);
$indicators .= '<li data-target="#'.$id.'" data-slide-to="'.$j.'" class="'.$class.'">'
.'<a href="'.$img.'">'
.'<img src="'.$thumb_path.'" alt="">'
.'</a>'
.'</li>';
$j++;
}
ob_start();
$class = 'gp_twitter_carousel carousel slide';
if( !$section_data['auto_start'] ){
$class .= ' start_paused';
}
$attr = ' data-speed="5000"';
if( isset($section_data['interval_speed']) && is_numeric($section_data['interval_speed']) ){
$attr = ' data-speed="'.$section_data['interval_speed'].'"';
}
echo '<div id="'.$id.'" class="'.$class.'"'.$attr.'>';
echo '<div style="padding-bottom:'.$section_data['height'].'">';
// Indicators
echo '<ol class="carousel-indicators">';
echo $indicators;
echo '</ol>';
// Carousel items
echo '<div class="carousel-inner">';
echo $images;
echo '</div>';
// Carousel nav
echo '<a class="carousel-control left" data-target="#'.$id.'" data-slide="prev">‹</a>';
echo '<a class="carousel-control right" data-target="#'.$id.'" data-slide="next">›</a>';
echo '<span class="gp_blank_img" data-src="'.common::GetDir('/include/imgs/blank.gif').'" style="display:none"></span>';
echo '</div></div>';
return ob_get_clean();
}
/**
* @static
*/
static function DefaultContent($default_content,$type){
if( !self::ContentKeyMatch($type) ){
return $default_content;
}
$section = array();
ob_start();
$id = 'carousel_'.time();
echo '<div id="'.$id.'" class="gp_twitter_carousel carousel slide">';
echo '<div style="padding-bottom:30%">';
echo '<ol class="carousel-indicators">';
echo '<li class="active gp_to_remove"></li>';
echo '</ol>';
//<!-- Carousel items -->
echo '<div class="carousel-inner">';
echo '<div class="item active gp_to_remove"><img/></div>';
echo '</div>';
//<!-- Carousel nav -->
echo '<a class="carousel-control left" data-target="#'.$id.'" data-slide="prev">‹</a>';
echo '<a class="carousel-control right" data-target="#'.$id.'" data-slide="next">›</a>';
echo '<span class="gp_blank_img" data-src="'.common::GetDir('/include/imgs/blank.gif').'" style="display:none"></span>';
echo '</div></div>';
$section['content'] = ob_get_clean();
$section['height'] = '30%';
$section['auto_start'] = false;
$section['interval_speed'] = 5000;
return $section;
}
/**
* @static
*
*/
static function SaveSection($return, $section, $type){
global $page;
if( !self::ContentKeyMatch($type) ){
return $return;
}
$_POST += array('auto_start'=>'','images'=>array());
$page->file_sections[$section]['auto_start'] = ($_POST['auto_start'] == 'true');
$page->file_sections[$section]['images'] = $_POST['images'];
$page->file_sections[$section]['captions'] = $_POST['captions'];
$page->file_sections[$section]['height'] = $_POST['height'];
$page->file_sections[$section]['content_version'] = 2;
if( isset($_POST['interval_speed']) && is_numeric($_POST['interval_speed']) ){
$page->file_sections[$section]['interval_speed'] = $_POST['interval_speed'];
}
$page->file_sections[$section]['content'] = self::GenerateContent($page->file_sections[$section]);
return true;
}
/**
* Make sure the .js and .css is available to admins
*
* @static
*
*/
static function GenerateContent_Admin(){
global $addonFolderName, $page, $addonRelativeCode;
//$page->head_script .= "\nvar SLIDESHOW_BASE = '".$addonRelativeCode."';\n";
self::AddComponents();
}
static function AddComponents(){
global $addonFolderName, $page, $addonRelativeCode;
static $done = false;
if( $done ) return;
if( version_compare(gpversion,'4.3b2','>=') ){
common::LoadComponents( 'bootstrap3-carousel' );
}else{
common::LoadComponents( 'bootstrap-carousel' );
}
$page->head_js[] = '/data/_addoncode/'.$addonFolderName.'/jquery.mobile.custom.js';
$page->head_js[] = '/data/_addoncode/'.$addonFolderName.'/carousel.js';
$page->css_user[] = '/data/_addoncode/'.$addonFolderName.'/carousel.css';
$done = true;
}
/**
*
*
*/
static function InlineEdit_Scripts($scripts,$type){
global $addonRelativeCode;
if( !self::ContentKeyMatch($type) ){
return $scripts;
}
//$scripts[] = '/include/js/inline_edit/inline_editing.js';
$scripts[] = '/include/js/inline_edit/image_common.js';
$scripts[] = '/include/js/inline_edit/gallery_edit_202.js';
$scripts[] = $addonRelativeCode.'/gallery_options.js';
$scripts[] = '/include/js/jquery.auto_upload.js';
return $scripts;
}
}