Repository navigation
Expand file tree
/
Copy pathImagePickerList.module
More file actions
159 lines (133 loc) · 5.24 KB
/
Copy pathImagePickerList.module
File metadata and controls
159 lines (133 loc) · 5.24 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
<?php
class ImagePickerList extends Process implements Module {
const adminPageName = 'ImagePickerList';
/**
* getModuleInfo is a module required by all modules to tell ProcessWire about them
*
* @return array
*
*/
public static function getModuleInfo() {
return array(
'title' => 'ImagePicker Lister',
'version' => 90,
'summary' => 'ImagePicker Lister',
'singular' => true,
'autoload' => false,
'permission' => 'imagepicker'
);
}
public function ___execute() {
$admin = $this->pages->get($this->config->adminRootPageID);
$parent = $admin->child("name=setup");
if (!$parent->id)
$parent = $admin;
$page = $parent->child("name=" . self::adminPageName);
$sid = $this->input->get('sid');
$config = $this->session->get($sid);
$usid = urlencode($sid);
$selectors = $config["sele"];
$thumbw = $config["thumbw"];
if (substr($selectors, 0, 1) != ',')
$selectors = ',' . $selectors;
if ($thumbw < 50)
$thumbw = 150;
$get = $this->input->get('id');
$filter = '';
$showimages = false;
if (!$get) {
$get = $this->session->get('lastid' . $sid);
} else
$this->session->set('lastid' . $sid, $get);
if ($get) {
if ($get != 'over') {
if ($get !== 'all')
$filter = ",id=$get";
$showimages = true;
}
}
$out = '<style>.flex-container>div {width:' . $thumbw . 'px;height:' . $thumbw . 'px;}</style>';
if ($showimages)
$out .= '<h4 class="sys"><a href="' . $page->url . '?sid=' . $usid . '&id=over&modal=1"><i class="fa fa-arrow-left"></i> ' . $this->_('Overview') . '</a></h4>';
$out .= '<h4 class="sys"><a href="' . $page->url . '?sid=' . $usid . '&id=all&modal=1"><i class="fa fa-th"></i> ' . $this->_('Open All') . '</a></h4>';
$filter .= $selectors;
foreach ($this->fields->find("type=FieldtypeImage") as $f) {
foreach ($this->pages->find("$f.count>0$filter") as $p) {
$ofstatus=$p->of();
$p->of(false);
$out .= '<h4><a href="' . $page->url . '?sid=' . $usid . '&id=' . $p->id . '&modal=1">' . $p->title . '</a> (' . count($p->$f) . ')</h4>';
if ($showimages) {
$out .= '<div class="flex-container">';
foreach ($p->$f as $i) {
if ($i->width > 260) {
$origurl = $i->url;
$i = $i->width(260);
} else
$origurl = $i->url;
$out .= '<div class="imgcont"><img title="' . ($i->description ? $i . '
'.$i->description.'' : $i) . '" class="selectableimg lazyload" data-origurl=' . $origurl . ' data-src="' . $i->url . '"></div>';
}
$out .= '</div>';
}
$p->of($ofstatus);
}
}
return $out;
}
public function ___install() {
if (ProcessWire::versionMajor == 2 && ProcessWire::versionMinor < 1) {
throw new WireException("This module requires ProcessWire 2.1 or newer");
}
$page = $this->getInstalledPage();
$this->message("Installed to {$page->path}");
if ($page->parent->name == 'setup')
$this->message("ImageSelector installed.");
// create imagepicker permission
$permission = $this->permissions->get("imagepicker");
if (!$permission->id) {
$permission = new Permission();
$permission->name = "imagepicker";
$permission->title = $this->_("Access Image Picker");
$permission->save();
$this->message("Created Permission: {$permission->name}");
}
}
/**
* Return the page that this Process is installed on
*
*/
protected function getInstalledPage() {
$admin = $this->pages->get($this->config->adminRootPageID);
$parent = $admin->child("name=setup");
if (!$parent->id)
$parent = $admin;
$page = $parent->child("name=" . self::adminPageName);
if (!$page->id) {
$page = new Page();
$page->parent = $parent;
$page->template = $this->templates->get('admin');
$page->name = self::adminPageName;
$page->title = "Image Picker List";
$page->process = $this;
$page->sort = $parent->numChildren;
$page->save();
}
return $page;
}
/**
* Uninstall the module
*
*/
public function ___uninstall() {
$page = $this->getInstalledPage();
if ($page->id) {
$this->message("Removed {$page->path}");
$this->pages->delete($page);
}
// delete permission
$permission = $this->permissions->get("imagepicker");
if ($permission->id) {
$permission->delete();
$this->message("Deleted Permission: {$permission->name}");
}
}
}