-
Notifications
You must be signed in to change notification settings - Fork 4
/
action.admin_copymodule.php
109 lines (78 loc) · 2.84 KB
/
action.admin_copymodule.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
<?php
#-------------------------------------------------------------------------
#
# Author: Ben Malen, <[email protected]>
# Co-Maintainer: Simon Radford, <[email protected]>
# Web: www.conceptfactory.com.au
#
#-------------------------------------------------------------------------
#
# Maintainer since 2011: Jonathan Schmid, <[email protected]>
# Web: www.jonathanschmid.de
#
#-------------------------------------------------------------------------
#
# ListIt is a CMS Made Simple module that enables the web developer to create
# multiple lists throughout a site. It can be duplicated and given friendly
# names for easier client maintenance.
#
#-------------------------------------------------------------------------
if (!is_object(cmsms())) exit;
#---------------------
# Check params
#---------------------
if (isset($params['cancel'])) {
$params = array('active_tab' => 'instancestab');
$this->Redirect($id, 'defaultadmin', $returnid, $params);
}
$module_name = '';
if(isset($params['module_name'])) {
$module_name = $params['module_name'];
}
$invalid_names = array('listit2', 'original', 'xdefs', 'loader');
$modules = $this->ListModules();
foreach($modules as $mod) {
$mod->module_name = substr($mod->module_name, strlen(ListIt2Duplicator::MOD_PREFIX));
$invalid_names[] = strtolower($mod->module_name);
}
#---------------------
# Submit
#---------------------
if (isset($params['submit'])) {
$errors = array();
if(empty($module_name)) {
$errors[] = $this->ModLang('module_name_empty');
}
if(preg_match('/[^0-9a-zA-Z]/', $module_name)) {
$errors[] = $this->ModLang('module_name_invalid');
}
if(in_array(strtolower($module_name), $invalid_names)) {
$errors[] = $this->ModLang('module_name_invalid');
}
if (empty($errors)) {
$duplicator = new ListIt2Duplicator($module_name);
$module_fullname = $duplicator->Run();
if($this->GetPreference('allow_autoinstall')) {
$modops = cmsms()->GetModuleOperations();
$modops->InstallModule($module_fullname);
}
$params = array('message' => 'modulecopied','active_tab' => 'instancestab');
$this->Redirect($id, 'defaultadmin', '', $params);
}
}
#---------------------
# Error handling
#---------------------
if (!empty($errors)) {
echo $this->ShowErrors($errors);
}
#---------------------
# Smarty processing
#---------------------
$smarty->assign('startform', $this->CreateFormStart ($id, 'admin_copymodule', $returnid, 'post', 'multipart/form-data', false, '', $params));
$smarty->assign('endform', $this->CreateFormEnd());
$smarty->assign('input_module_name', $this->CreateInputText($id, 'module_name', $module_name, 40));
$smarty->assign('submit', $this->CreateInputSubmit($id, 'submit', lang('submit')));
$smarty->assign('cancel', $this->CreateInputSubmit($id, 'cancel', lang('cancel')));
echo $this->ProcessTemplate('copymodule.tpl');
?>