-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFieldtypeFontIconPicker.module
186 lines (157 loc) · 4.77 KB
/
FieldtypeFontIconPicker.module
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
<?php
/**
* Class FieldtypeFontIconPicker
*
* @author : İskender TOTOĞLU, @ukyo (community), @trk (Github)
* @website : http://altivebir.com.tr
* @projectWebsite : https://github.com/trk/FieldtypeFontIconPicker
*/
class FieldtypeFontIconPicker extends Fieldtype implements Module, ConfigurableModule
{
/**
* @var array $resources
*/
public $resources = array();
/**
* @inheritDoc
*
* @return array
*/
public static function getModuleInfo()
{
return array(
'title' => 'Icon Picker',
'summary' => __('Allow you to use icon picker input field.'),
'version' => 202,
'author' => 'İskender TOTOĞLU | @ukyo(community), @trk (Github), http://altivebir.com.tr',
'icon' => 'hand-pointer-o',
'href' => 'https://github.com/trk/FieldtypeFontIconPicker',
'installs' => array(
'InputfieldFontIconPicker',
'MarkupFontIconPicker'
),
);
}
/**
* Finder: find config files for module
*
* @param string $path
* @param string $filter
*
* @return array
*/
protected function finder(string $path, $filter = "configs/IconPicker.")
{
if ($this->useGlob) {
$paths = glob('{' . $this->config->paths->templates . $filter. '*.php,' . $this->config->paths->siteModules . '*/' . $filter . '*.php}', GLOB_BRACE | GLOB_NOSORT);
} else {
$paths = array();
foreach($this->files->find($path, ["extensions" => ["php"]]) as $path) {
if ($filter && strpos($path, $filter) === false) {
continue;
}
$paths[] = $path;
}
}
return $paths;
}
/**
* @inheritDoc
*
* @return array
*/
public function resources()
{
$resources = array();
$paths = array_merge($this->finder($this->config->paths->siteModules), $this->finder($this->config->paths->templates . "configs" . DIRECTORY_SEPARATOR));
foreach ($paths as $file) {
$dirname = dirname(dirname($file));
$base = strtolower(str_replace([dirname(dirname(dirname($file))), "/", "\\"], "", $dirname));
$filename = str_replace([dirname($file), "/", "\\", "IconPicker.", ".php"], "", $file);
$source = include $file;
if (is_array($source)) {
$name = isset($source["name"]) ? $source["name"] : $filename;
$title = isset($source["title"]) ? $source["title"] : $name;
$version = isset($source["version"]) ? $source["version"] : "";
$styles = isset($source["styles"]) && is_array($source["styles"]) ? $source["styles"] : array();
$scripts = isset($source["scripts"]) && is_array($source["scripts"]) ? $source["scripts"] : array();
$categorized = isset($source["categorized"]) ? $source["categorized"] : false;
$attributes = isset($source["attributes"]) ? $source["attributes"] : array();
$resources["{$base}.{$name}"] = array(
"base" => $base,
"filename" => $filename,
"name" => $name,
"title" => $title,
"version" => $version,
"styles" => $styles,
"scripts" => $scripts,
"categorized" => $categorized,
"attributes" => $attributes,
"icons" => array(),
"file" => $file
);
}
}
return $resources;
}
/**
* Return the associated InputfieldFontIconPicker
*
*/
public function getInputfield(Page $page, Field $field)
{
$inputField = $this->modules->get('InputfieldFontIconPicker');
return $inputField;
}
/**
* @inheritDoc
*
* @param Page $page
* @param Field $field
* @param string $value
*
* @return string
*/
public function sanitizeValue(Page $page, Field $field, $value)
{
$inputField = $this->getInputfield($page, $field);
$resource = $inputField->resource($field->iconLibrary);
$prefix = isset($resource["attributes"]["prefix"]) ? $resource["attributes"]["prefix"] : "";
if($prefix) {
$value = str_replace($prefix, '', $value);
}
return $value;
}
/**
* Return the database schema in specified format
*
*/
public function getDatabaseSchema(Field $field)
{
// get the default schema
$schema = parent::getDatabaseSchema($field);
$schema['data'] = "VARCHAR(255) NOT NULL DEFAULT ''";
return $schema;
}
/**
* Return an InputfieldWrapper of Inputfields used to configure the class
*
* @param array $data Array of config values indexed by field name
*
* @return InputfieldsWrapper
*
*/
public function getModuleConfigInputfields(array $data) {
$wrapper = new InputfieldWrapper();
/**
* @var InputfieldCheckbox $checkbox
*/
$checkbox = wire('modules')->get('InputfieldCheckbox');
$checkbox->attr('name', 'useGlob');
$checkbox->set('label', 'Finder method');
$checkbox->set('checkboxLabel', __('Use `glob` method for find config files'));
$checkbox->attr('checked', $this->useGlob ? 'checked' : '');
$wrapper->add($checkbox);
return $wrapper;
}
}