AbstractGenerator.php
3.5 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
<?php
namespace Nextend\SmartSlider3\Generator;
use Nextend\Framework\Data\Data;
use Nextend\Framework\Form\ContainerInterface;
use Nextend\SmartSlider3\Platform\WordPress\Shortcode\Shortcode;
abstract class AbstractGenerator {
protected $name = '';
protected $label = '';
protected $layout = '';
/** @var AbstractGeneratorGroup */
protected $group;
/** @var Data */
protected $data;
/**
*
* @param AbstractGeneratorGroup $group
* @param string $name
* @param string $label
*/
public function __construct($group, $name, $label) {
$this->group = $group;
$this->name = $name;
$this->label = $label;
$this->group->addSource($name, $this);
}
/**
*
* @param ContainerInterface $container
*/
public function renderFields($container) {
}
public function setData($data) {
$this->data = $data;
}
public final function getData($slides, $startIndex, $group) {
Shortcode::shortcodeModeToNoop();
$this->resetState();
$data = array();
$linearData = $this->_getData($slides * $group, $startIndex - 1);
if ($linearData != null) {
$keys = array();
for ($i = 0; $i < count($linearData); $i++) {
$keys = array_merge($keys, array_keys($linearData[$i]));
}
$columns = array_fill_keys($keys, '');
for ($i = 0; $i < count($linearData); $i++) {
$firstIndex = intval($i / $group);
if (!isset($data[$firstIndex])) {
$data[$firstIndex] = array();
}
$data[$firstIndex][$i % $group] = array_merge($columns, $linearData[$i]);
}
if (count($data) && count($data[count($data) - 1]) != $group) {
if (count($data) - 1 == 0 && count($data[count($data) - 1]) > 0) {
while (count($data[0]) < $group) {
$data[0][] = $columns;
}
} else {
array_pop($data);
}
}
}
Shortcode::shortcodeModeToNormal();
return $data;
}
protected function resetState() {
}
protected abstract function _getData($count, $startIndex);
function makeClickableLinks($s) {
return preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '<a href="$1" target="_blank">$1</a>', $s);
}
protected function getIDs($field = 'ids') {
return array_map('intval', explode("\n", str_replace(array(
"\r\n",
"\n\r",
"\r"
), "\n", $this->data->get($field))));
}
public function filterName($name) {
return $name;
}
public function hash($key) {
return md5($key);
}
public static function cacheKey($params) {
return '';
}
/**
* @return string
*/
public function getLabel() {
return $this->label;
}
/**
* @return string
*/
public function getDescription() {
return n2_('No description.');
}
/**
* @return string
*/
public function getLayout() {
return $this->layout;
}
/**
* @return string
*/
public function getName() {
return $this->name;
}
/**
* @return AbstractGeneratorGroup
*/
public function getGroup() {
return $this->group;
}
}