@@ -8,7 +8,6 @@ |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | use XoopsModules\Wfdownloads; |
11 | -use XoopsModules\Smartobject; |
|
12 | 11 | |
13 | 12 | require_once __DIR__ . '/admin_header.php'; |
14 | 13 | require_once SMARTCONTENT_ROOT_PATH . 'class/dbupdater.php'; |
@@ -21,188 +21,188 @@ discard block |
||
21 | 21 | // ========================================================================================= |
22 | 22 | function update_tables_to_300() |
23 | 23 | { |
24 | - $dbupdater = new Wfdownloads\Dbupdater(); |
|
24 | + $dbupdater = new Wfdownloads\Dbupdater(); |
|
25 | 25 | |
26 | - if (!wfdownloads_TableExists('wfdownloads_meta')) { |
|
27 | - // Create table wfdownloads_meta |
|
28 | - $table = new Wfdownloads\DbupdaterTable('wfdownloads_meta'); |
|
29 | - $table->setStructure("CREATE TABLE `%s` ( |
|
26 | + if (!wfdownloads_TableExists('wfdownloads_meta')) { |
|
27 | + // Create table wfdownloads_meta |
|
28 | + $table = new Wfdownloads\DbupdaterTable('wfdownloads_meta'); |
|
29 | + $table->setStructure("CREATE TABLE `%s` ( |
|
30 | 30 | metakey varchar(50) NOT NULL default '', |
31 | 31 | metavalue varchar(255) NOT NULL default '', |
32 | 32 | PRIMARY KEY (metakey)) |
33 | 33 | ENGINE=MyISAM;"); |
34 | 34 | |
35 | - $table->setData(sprintf("'version', %s", round($GLOBALS['xoopsModule']->getVar('version') / 100, 2))); |
|
36 | - if ($dbupdater->updateTable($table)) { |
|
37 | - echo 'wfdownloads_meta table created<br>'; |
|
38 | - } |
|
39 | - } |
|
40 | - |
|
41 | - $download_fields = [ |
|
42 | - 'lid' => ['Type' => 'int(11) unsigned NOT NULL auto_increment', 'Default' => false], |
|
43 | - 'cid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
44 | - 'title' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
45 | - 'url' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
46 | - 'filename' => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true], |
|
47 | - 'filetype' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
48 | - 'homepage' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
49 | - 'version' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
50 | - 'size' => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true], |
|
51 | - 'platform' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
52 | - 'screenshot' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
53 | - 'submitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
54 | - 'publisher' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
55 | - 'status' => ['Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true], |
|
56 | - 'date' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
57 | - 'hits' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
58 | - 'rating' => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true], |
|
59 | - 'votes' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
60 | - 'comments' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
61 | - 'license' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
62 | - 'mirror' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
63 | - 'price' => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true], |
|
64 | - 'paypalemail' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
65 | - 'features' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
66 | - 'requirements' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
67 | - 'homepagetitle' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
68 | - 'forumid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
69 | - 'limitations' => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true], |
|
70 | - 'dhistory' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
71 | - 'published' => ['Type' => "int(11) NOT NULL default '1089662528'", 'Default' => true], |
|
72 | - 'expired' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
73 | - 'updated' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
74 | - 'offline' => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true], |
|
75 | - 'description' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
76 | - 'ipaddress' => ['Type' => "varchar(120) NOT NULL default '0'", 'Default' => true], |
|
77 | - 'notifypub' => ['Type' => "int(1) NOT NULL default '0'", 'Default' => true], |
|
78 | - 'summary' => ['Type' => 'text NOT NULL', 'Default' => false] |
|
79 | - ]; |
|
80 | - |
|
81 | - $renamed_fields = [ |
|
82 | - 'logourl' => 'screenshot' |
|
83 | - ]; |
|
84 | - |
|
85 | - echo '<br><b>Checking Download table</b><br>'; |
|
86 | - $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
87 | - $downloadHandler = $helperWfdownloads->getHandler('Download'); |
|
88 | - $download_table = new Wfdownloads\DbupdaterTable('wfdownloads_downloads'); |
|
89 | - $fields = get_table_info($downloadHandler->table, $download_fields); |
|
90 | - // Check for renamed fields |
|
91 | - rename_fields($download_table, $renamed_fields, $fields, $download_fields); |
|
92 | - update_table($download_fields, $fields, $download_table); |
|
93 | - if ($dbupdater->updateTable($download_table)) { |
|
94 | - echo 'Downloads table updated<br>'; |
|
95 | - } |
|
96 | - unset($fields); |
|
97 | - |
|
98 | - $mod_fields = [ |
|
99 | - 'requestid' => ['Type' => 'int(11) NOT NULL auto_increment', 'Default' => false], |
|
100 | - 'lid' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
101 | - 'cid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
102 | - 'title' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
103 | - 'url' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
104 | - 'filename' => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true], |
|
105 | - 'filetype' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
106 | - 'homepage' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
107 | - 'version' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
108 | - 'size' => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true], |
|
109 | - 'platform' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
110 | - 'screenshot' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
111 | - 'submitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
112 | - 'publisher' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
113 | - 'status' => ['Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true], |
|
114 | - 'date' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
115 | - 'hits' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
116 | - 'rating' => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true], |
|
117 | - 'votes' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
118 | - 'comments' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
119 | - 'license' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
120 | - 'mirror' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
121 | - 'price' => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true], |
|
122 | - 'paypalemail' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
123 | - 'features' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
124 | - 'requirements' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
125 | - 'homepagetitle' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
126 | - 'forumid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
127 | - 'limitations' => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true], |
|
128 | - 'dhistory' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
129 | - 'published' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
130 | - 'expired' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
131 | - 'updated' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
132 | - 'offline' => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true], |
|
133 | - 'summary' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
134 | - 'description' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
135 | - 'modifysubmitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
136 | - 'requestdate' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true] |
|
137 | - ]; |
|
138 | - |
|
139 | - $renamed_fields = [ |
|
140 | - 'logourl' => 'screenshot' |
|
141 | - ]; |
|
142 | - |
|
143 | - echo '<br><b>Checking Modified Downloads table</b><br>'; |
|
35 | + $table->setData(sprintf("'version', %s", round($GLOBALS['xoopsModule']->getVar('version') / 100, 2))); |
|
36 | + if ($dbupdater->updateTable($table)) { |
|
37 | + echo 'wfdownloads_meta table created<br>'; |
|
38 | + } |
|
39 | + } |
|
40 | + |
|
41 | + $download_fields = [ |
|
42 | + 'lid' => ['Type' => 'int(11) unsigned NOT NULL auto_increment', 'Default' => false], |
|
43 | + 'cid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
44 | + 'title' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
45 | + 'url' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
46 | + 'filename' => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true], |
|
47 | + 'filetype' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
48 | + 'homepage' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
49 | + 'version' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
50 | + 'size' => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true], |
|
51 | + 'platform' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
52 | + 'screenshot' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
53 | + 'submitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
54 | + 'publisher' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
55 | + 'status' => ['Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true], |
|
56 | + 'date' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
57 | + 'hits' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
58 | + 'rating' => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true], |
|
59 | + 'votes' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
60 | + 'comments' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
61 | + 'license' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
62 | + 'mirror' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
63 | + 'price' => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true], |
|
64 | + 'paypalemail' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
65 | + 'features' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
66 | + 'requirements' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
67 | + 'homepagetitle' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
68 | + 'forumid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
69 | + 'limitations' => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true], |
|
70 | + 'dhistory' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
71 | + 'published' => ['Type' => "int(11) NOT NULL default '1089662528'", 'Default' => true], |
|
72 | + 'expired' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
73 | + 'updated' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
74 | + 'offline' => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true], |
|
75 | + 'description' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
76 | + 'ipaddress' => ['Type' => "varchar(120) NOT NULL default '0'", 'Default' => true], |
|
77 | + 'notifypub' => ['Type' => "int(1) NOT NULL default '0'", 'Default' => true], |
|
78 | + 'summary' => ['Type' => 'text NOT NULL', 'Default' => false] |
|
79 | + ]; |
|
80 | + |
|
81 | + $renamed_fields = [ |
|
82 | + 'logourl' => 'screenshot' |
|
83 | + ]; |
|
84 | + |
|
85 | + echo '<br><b>Checking Download table</b><br>'; |
|
86 | + $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
87 | + $downloadHandler = $helperWfdownloads->getHandler('Download'); |
|
88 | + $download_table = new Wfdownloads\DbupdaterTable('wfdownloads_downloads'); |
|
89 | + $fields = get_table_info($downloadHandler->table, $download_fields); |
|
90 | + // Check for renamed fields |
|
91 | + rename_fields($download_table, $renamed_fields, $fields, $download_fields); |
|
92 | + update_table($download_fields, $fields, $download_table); |
|
93 | + if ($dbupdater->updateTable($download_table)) { |
|
94 | + echo 'Downloads table updated<br>'; |
|
95 | + } |
|
96 | + unset($fields); |
|
97 | + |
|
98 | + $mod_fields = [ |
|
99 | + 'requestid' => ['Type' => 'int(11) NOT NULL auto_increment', 'Default' => false], |
|
100 | + 'lid' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
101 | + 'cid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
102 | + 'title' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
103 | + 'url' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
104 | + 'filename' => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true], |
|
105 | + 'filetype' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
|
106 | + 'homepage' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
107 | + 'version' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
108 | + 'size' => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true], |
|
109 | + 'platform' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
110 | + 'screenshot' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
111 | + 'submitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
112 | + 'publisher' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
113 | + 'status' => ['Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true], |
|
114 | + 'date' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
115 | + 'hits' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
116 | + 'rating' => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true], |
|
117 | + 'votes' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
118 | + 'comments' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
|
119 | + 'license' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
120 | + 'mirror' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
121 | + 'price' => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true], |
|
122 | + 'paypalemail' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
123 | + 'features' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
124 | + 'requirements' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
125 | + 'homepagetitle' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
126 | + 'forumid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
127 | + 'limitations' => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true], |
|
128 | + 'dhistory' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
129 | + 'published' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
130 | + 'expired' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
|
131 | + 'updated' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
132 | + 'offline' => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true], |
|
133 | + 'summary' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
134 | + 'description' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
135 | + 'modifysubmitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
136 | + 'requestdate' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true] |
|
137 | + ]; |
|
138 | + |
|
139 | + $renamed_fields = [ |
|
140 | + 'logourl' => 'screenshot' |
|
141 | + ]; |
|
142 | + |
|
143 | + echo '<br><b>Checking Modified Downloads table</b><br>'; |
|
144 | 144 | // $moduleHandler = xoops_getModuleHandler('modification', 'wfdownloads'); |
145 | - $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
146 | - $moduleHandler = $helperWfdownloads->getHandler('Modification'); |
|
147 | - $mod_table = new Wfdownloads\DbupdaterTable('wfdownloads_mod'); |
|
148 | - $fields = get_table_info($moduleHandler->table, $mod_fields); |
|
149 | - rename_fields($mod_table, $renamed_fields, $fields, $mod_fields); |
|
150 | - update_table($mod_fields, $fields, $mod_table); |
|
151 | - if ($dbupdater->updateTable($mod_table)) { |
|
152 | - echo 'Modified Downloads table updated <br>'; |
|
153 | - } |
|
154 | - unset($fields); |
|
155 | - |
|
156 | - $cat_fields = [ |
|
157 | - 'cid' => ['Type' => 'int(5) unsigned NOT NULL auto_increment', 'Default' => false], |
|
158 | - 'pid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
159 | - 'title' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
160 | - 'imgurl' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
161 | - 'description' => ['Type' => 'text NULL', 'Default' => true], |
|
162 | - 'total' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
163 | - 'summary' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
164 | - 'spotlighttop' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
165 | - 'spotlighthis' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
166 | - 'dohtml' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
167 | - 'dosmiley' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
168 | - 'doxcode' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
169 | - 'doimage' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
170 | - 'dobr' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
171 | - 'weight' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true] |
|
172 | - ]; |
|
173 | - echo '<br><b>Checking Category table</b><br>'; |
|
145 | + $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
146 | + $moduleHandler = $helperWfdownloads->getHandler('Modification'); |
|
147 | + $mod_table = new Wfdownloads\DbupdaterTable('wfdownloads_mod'); |
|
148 | + $fields = get_table_info($moduleHandler->table, $mod_fields); |
|
149 | + rename_fields($mod_table, $renamed_fields, $fields, $mod_fields); |
|
150 | + update_table($mod_fields, $fields, $mod_table); |
|
151 | + if ($dbupdater->updateTable($mod_table)) { |
|
152 | + echo 'Modified Downloads table updated <br>'; |
|
153 | + } |
|
154 | + unset($fields); |
|
155 | + |
|
156 | + $cat_fields = [ |
|
157 | + 'cid' => ['Type' => 'int(5) unsigned NOT NULL auto_increment', 'Default' => false], |
|
158 | + 'pid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
|
159 | + 'title' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
|
160 | + 'imgurl' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
|
161 | + 'description' => ['Type' => 'text NULL', 'Default' => true], |
|
162 | + 'total' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
163 | + 'summary' => ['Type' => 'text NOT NULL', 'Default' => false], |
|
164 | + 'spotlighttop' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
165 | + 'spotlighthis' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
166 | + 'dohtml' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
167 | + 'dosmiley' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
168 | + 'doxcode' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
169 | + 'doimage' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
170 | + 'dobr' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
|
171 | + 'weight' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true] |
|
172 | + ]; |
|
173 | + echo '<br><b>Checking Category table</b><br>'; |
|
174 | 174 | // $catHandler = xoops_getModuleHandler('category', 'wfdownloads'); |
175 | - $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
176 | - $catHandler = $helperWfdownloads->getHandler('Report'); |
|
177 | - |
|
178 | - $cat_table = new Wfdownloads\DbupdaterTable('wfdownloads_cat'); |
|
179 | - $fields = get_table_info($catHandler->table, $cat_fields); |
|
180 | - update_table($cat_fields, $fields, $cat_table); |
|
181 | - if ($dbupdater->updateTable($cat_table)) { |
|
182 | - echo 'Category table updated<br>'; |
|
183 | - } |
|
184 | - unset($fields); |
|
185 | - |
|
186 | - $broken_fields = [ |
|
187 | - 'reportid' => ['Type' => 'int(5) NOT NULL auto_increment', 'Default' => false], |
|
188 | - 'lid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
189 | - 'sender' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
190 | - 'ip' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
191 | - 'date' => ['Type' => "varchar(11) NOT NULL default '0'", 'Default' => true], |
|
192 | - 'confirmed' => ['Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true], |
|
193 | - 'acknowledged' => ['Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true] |
|
194 | - ]; |
|
195 | - echo '<br><b>Checking Broken Report table</b><br>'; |
|
196 | - $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
197 | - $brokenHandler = $helperWfdownloads->getHandler('Report'); |
|
175 | + $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
176 | + $catHandler = $helperWfdownloads->getHandler('Report'); |
|
177 | + |
|
178 | + $cat_table = new Wfdownloads\DbupdaterTable('wfdownloads_cat'); |
|
179 | + $fields = get_table_info($catHandler->table, $cat_fields); |
|
180 | + update_table($cat_fields, $fields, $cat_table); |
|
181 | + if ($dbupdater->updateTable($cat_table)) { |
|
182 | + echo 'Category table updated<br>'; |
|
183 | + } |
|
184 | + unset($fields); |
|
185 | + |
|
186 | + $broken_fields = [ |
|
187 | + 'reportid' => ['Type' => 'int(5) NOT NULL auto_increment', 'Default' => false], |
|
188 | + 'lid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
189 | + 'sender' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
|
190 | + 'ip' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
|
191 | + 'date' => ['Type' => "varchar(11) NOT NULL default '0'", 'Default' => true], |
|
192 | + 'confirmed' => ['Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true], |
|
193 | + 'acknowledged' => ['Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true] |
|
194 | + ]; |
|
195 | + echo '<br><b>Checking Broken Report table</b><br>'; |
|
196 | + $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
197 | + $brokenHandler = $helperWfdownloads->getHandler('Report'); |
|
198 | 198 | // $brokenHandler = xoops_getModuleHandler('report', 'wfdownloads'); |
199 | - $broken_table = new Wfdownloads\DbupdaterTable('wfdownloads_broken'); |
|
200 | - $fields = get_table_info($brokenHandler->table, $broken_fields); |
|
201 | - update_table($broken_fields, $fields, $broken_table); |
|
202 | - if ($dbupdater->updateTable($broken_table)) { |
|
203 | - echo 'Broken Reports table updated<br>'; |
|
204 | - } |
|
205 | - unset($fields); |
|
199 | + $broken_table = new Wfdownloads\DbupdaterTable('wfdownloads_broken'); |
|
200 | + $fields = get_table_info($brokenHandler->table, $broken_fields); |
|
201 | + update_table($broken_fields, $fields, $broken_table); |
|
202 | + if ($dbupdater->updateTable($broken_table)) { |
|
203 | + echo 'Broken Reports table updated<br>'; |
|
204 | + } |
|
205 | + unset($fields); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | // ========================================================================================= |
@@ -215,49 +215,49 @@ discard block |
||
215 | 215 | */ |
216 | 216 | function invert_nohtm_dohtml_values() |
217 | 217 | { |
218 | - $ret = []; |
|
219 | - global $xoopsDB; |
|
220 | - $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
221 | - $catHandler = $helperWfdownloads->getHandler('Category'); |
|
222 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $catHandler->table); |
|
223 | - while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
224 | - $fields[$existing_field['field']] = $existing_field['type']; |
|
225 | - } |
|
226 | - if (in_array('nohtml', array_keys($fields))) { |
|
227 | - $dbupdater = new Wfdownloads\Dbupdater(); |
|
228 | - //Invert column values |
|
229 | - // alter options in wfdownloads_cat |
|
230 | - $table = new Wfdownloads\DbupdaterTable('wfdownloads_cat'); |
|
231 | - $table->addAlteredField('nohtml', "dohtml tinyint(1) NOT NULL DEFAULT '1'"); |
|
232 | - $table->addAlteredField('nosmiley', "dosmiley tinyint(1) NOT NULL DEFAULT '1'"); |
|
233 | - $table->addAlteredField('noxcodes', "doxcode tinyint(1) NOT NULL DEFAULT '1'"); |
|
234 | - $table->addAlteredField('noimages', "doimage tinyint(1) NOT NULL DEFAULT '1'"); |
|
235 | - $table->addAlteredField('nobreak', "dobr tinyint(1) NOT NULL DEFAULT '1'"); |
|
236 | - |
|
237 | - //inverting values no=1 <=> do=0 |
|
238 | - // have to store teporarly as value = 2 to |
|
239 | - // avoid putting everithing to same value |
|
240 | - // if you change 1 to 0, then 0 to one, |
|
241 | - // every value will be 1, follow me? |
|
242 | - $table->addUpdatedWhere('dohtml', 2, '=1'); |
|
243 | - $table->addUpdatedWhere('dohtml', 1, '=0'); |
|
244 | - $table->addUpdatedWhere('dohtml', 0, '=2'); |
|
245 | - |
|
246 | - $table->addUpdatedWhere('dosmiley', 2, '=1'); |
|
247 | - $table->addUpdatedWhere('dosmiley', 1, '=0'); |
|
248 | - $table->addUpdatedWhere('dosmiley', 0, '=2'); |
|
249 | - |
|
250 | - $table->addUpdatedWhere('doxcode', 2, '=1'); |
|
251 | - $table->addUpdatedWhere('doxcode', 1, '=0'); |
|
252 | - $table->addUpdatedWhere('doxcode', 0, '=2'); |
|
253 | - |
|
254 | - $table->addUpdatedWhere('doimage', 2, '=1'); |
|
255 | - $table->addUpdatedWhere('doimage', 1, '=0'); |
|
256 | - $table->addUpdatedWhere('doimage', 0, '=2'); |
|
257 | - $ret = $dbupdater->updateTable($table); |
|
258 | - } |
|
259 | - |
|
260 | - return $ret; |
|
218 | + $ret = []; |
|
219 | + global $xoopsDB; |
|
220 | + $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
|
221 | + $catHandler = $helperWfdownloads->getHandler('Category'); |
|
222 | + $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $catHandler->table); |
|
223 | + while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
224 | + $fields[$existing_field['field']] = $existing_field['type']; |
|
225 | + } |
|
226 | + if (in_array('nohtml', array_keys($fields))) { |
|
227 | + $dbupdater = new Wfdownloads\Dbupdater(); |
|
228 | + //Invert column values |
|
229 | + // alter options in wfdownloads_cat |
|
230 | + $table = new Wfdownloads\DbupdaterTable('wfdownloads_cat'); |
|
231 | + $table->addAlteredField('nohtml', "dohtml tinyint(1) NOT NULL DEFAULT '1'"); |
|
232 | + $table->addAlteredField('nosmiley', "dosmiley tinyint(1) NOT NULL DEFAULT '1'"); |
|
233 | + $table->addAlteredField('noxcodes', "doxcode tinyint(1) NOT NULL DEFAULT '1'"); |
|
234 | + $table->addAlteredField('noimages', "doimage tinyint(1) NOT NULL DEFAULT '1'"); |
|
235 | + $table->addAlteredField('nobreak', "dobr tinyint(1) NOT NULL DEFAULT '1'"); |
|
236 | + |
|
237 | + //inverting values no=1 <=> do=0 |
|
238 | + // have to store teporarly as value = 2 to |
|
239 | + // avoid putting everithing to same value |
|
240 | + // if you change 1 to 0, then 0 to one, |
|
241 | + // every value will be 1, follow me? |
|
242 | + $table->addUpdatedWhere('dohtml', 2, '=1'); |
|
243 | + $table->addUpdatedWhere('dohtml', 1, '=0'); |
|
244 | + $table->addUpdatedWhere('dohtml', 0, '=2'); |
|
245 | + |
|
246 | + $table->addUpdatedWhere('dosmiley', 2, '=1'); |
|
247 | + $table->addUpdatedWhere('dosmiley', 1, '=0'); |
|
248 | + $table->addUpdatedWhere('dosmiley', 0, '=2'); |
|
249 | + |
|
250 | + $table->addUpdatedWhere('doxcode', 2, '=1'); |
|
251 | + $table->addUpdatedWhere('doxcode', 1, '=0'); |
|
252 | + $table->addUpdatedWhere('doxcode', 0, '=2'); |
|
253 | + |
|
254 | + $table->addUpdatedWhere('doimage', 2, '=1'); |
|
255 | + $table->addUpdatedWhere('doimage', 1, '=0'); |
|
256 | + $table->addUpdatedWhere('doimage', 0, '=2'); |
|
257 | + $ret = $dbupdater->updateTable($table); |
|
258 | + } |
|
259 | + |
|
260 | + return $ret; |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
@@ -270,22 +270,22 @@ discard block |
||
270 | 270 | */ |
271 | 271 | function update_table($new_fields, $existing_fields, &$table) |
272 | 272 | { |
273 | - foreach ($new_fields as $field => $fieldinfo) { |
|
274 | - $type = $fieldinfo['Type']; |
|
275 | - if (!in_array($field, array_keys($existing_fields))) { |
|
276 | - //Add field as it is missing |
|
277 | - $table->addNewField($field, $type); |
|
278 | - //$xoopsDB->query("ALTER TABLE ".$table." ADD ".$field." ".$type); |
|
279 | - //echo $field."(".$type.") <FONT COLOR='##22DD51'>Added</FONT><br>"; |
|
280 | - } elseif ($existing_fields[$field] != $type) { |
|
281 | - $table->addAlteredField($field, $field . ' ' . $type); |
|
282 | - // check $fields[$field]['type'] for things like "int(10) unsigned" |
|
283 | - //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$field." ".$type); |
|
284 | - //echo $field." <FONT COLOR='#FF6600'>Changed to</FONT> ".$type."<br>"; |
|
285 | - } else { |
|
286 | - //echo $field." <FONT COLOR='#0033FF'>Uptodate</FONT><br>"; |
|
287 | - } |
|
288 | - } |
|
273 | + foreach ($new_fields as $field => $fieldinfo) { |
|
274 | + $type = $fieldinfo['Type']; |
|
275 | + if (!in_array($field, array_keys($existing_fields))) { |
|
276 | + //Add field as it is missing |
|
277 | + $table->addNewField($field, $type); |
|
278 | + //$xoopsDB->query("ALTER TABLE ".$table." ADD ".$field." ".$type); |
|
279 | + //echo $field."(".$type.") <FONT COLOR='##22DD51'>Added</FONT><br>"; |
|
280 | + } elseif ($existing_fields[$field] != $type) { |
|
281 | + $table->addAlteredField($field, $field . ' ' . $type); |
|
282 | + // check $fields[$field]['type'] for things like "int(10) unsigned" |
|
283 | + //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$field." ".$type); |
|
284 | + //echo $field." <FONT COLOR='#FF6600'>Changed to</FONT> ".$type."<br>"; |
|
285 | + } else { |
|
286 | + //echo $field." <FONT COLOR='#0033FF'>Uptodate</FONT><br>"; |
|
287 | + } |
|
288 | + } |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -298,22 +298,22 @@ discard block |
||
298 | 298 | */ |
299 | 299 | function get_table_info($table, $default_fields) |
300 | 300 | { |
301 | - global $xoopsDB; |
|
302 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $table); |
|
303 | - while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
304 | - $fields[$existing_field['Field']] = $existing_field['Type']; |
|
305 | - if ('YES' !== $existing_field['Null']) { |
|
306 | - $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
307 | - } |
|
308 | - if ($existing_field['Extra']) { |
|
309 | - $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
310 | - } |
|
311 | - if ($default_fields[$existing_field['Field']]['Default']) { |
|
312 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
313 | - } |
|
314 | - } |
|
315 | - |
|
316 | - return $fields; |
|
301 | + global $xoopsDB; |
|
302 | + $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $table); |
|
303 | + while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
304 | + $fields[$existing_field['Field']] = $existing_field['Type']; |
|
305 | + if ('YES' !== $existing_field['Null']) { |
|
306 | + $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
307 | + } |
|
308 | + if ($existing_field['Extra']) { |
|
309 | + $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
310 | + } |
|
311 | + if ($default_fields[$existing_field['Field']]['Default']) { |
|
312 | + $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
313 | + } |
|
314 | + } |
|
315 | + |
|
316 | + return $fields; |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -327,60 +327,60 @@ discard block |
||
327 | 327 | */ |
328 | 328 | function rename_fields(&$table, $renamed_fields, &$fields, $new_fields) |
329 | 329 | { |
330 | - foreach (array_keys($fields) as $field) { |
|
331 | - if (in_array($field, array_keys($renamed_fields))) { |
|
332 | - $new_field_name = $renamed_fields[$field]; |
|
333 | - $new_field_type = $new_fields[$new_field_name]['Type']; |
|
334 | - $table->addAltered($field, $new_field_name . ' ' . $new_field_type); |
|
335 | - //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$new_field_name." ".$new_field_type); |
|
336 | - //echo $field." Renamed to ".$new_field_name."<br>"; |
|
337 | - $fields[$new_field_name] = $new_field_type; |
|
338 | - } |
|
339 | - } |
|
340 | - //return $fields; |
|
330 | + foreach (array_keys($fields) as $field) { |
|
331 | + if (in_array($field, array_keys($renamed_fields))) { |
|
332 | + $new_field_name = $renamed_fields[$field]; |
|
333 | + $new_field_type = $new_fields[$new_field_name]['Type']; |
|
334 | + $table->addAltered($field, $new_field_name . ' ' . $new_field_type); |
|
335 | + //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$new_field_name." ".$new_field_type); |
|
336 | + //echo $field." Renamed to ".$new_field_name."<br>"; |
|
337 | + $fields[$new_field_name] = $new_field_type; |
|
338 | + } |
|
339 | + } |
|
340 | + //return $fields; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | $op = isset($_REQUEST['op']) ? (int)$_REQUEST['op'] : 0; |
344 | 344 | switch ($op) { |
345 | - case 1: |
|
346 | - // Make sure that nohtml is properly changed to dohtml |
|
347 | - invert_nohtm_dohtml_values(); |
|
348 | - // Ensure that the proper tables are present |
|
349 | - update_tables_to_300(); |
|
350 | - // Import data from MyDownloads |
|
351 | - import_mydownloads_to_wfdownloads(); |
|
352 | - break; |
|
353 | - |
|
354 | - case 2: |
|
355 | - // Update WF-Downloads |
|
356 | - $log = invert_nohtm_dohtml_values(); |
|
357 | - update_tables_to_300(); |
|
358 | - break; |
|
359 | - |
|
360 | - default: |
|
361 | - //ask what to do |
|
362 | - include XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
363 | - $form = new \XoopsThemeForm('Upgrade WF-Downloads', 'form', $_SERVER['REQUEST_URI']); |
|
364 | - |
|
365 | - //Is MyDownloads installed? |
|
366 | - /** @var XoopsModuleHandler $moduleHandler */ |
|
367 | - $moduleHandler = xoops_getHandler('module'); |
|
368 | - $mydownloadsModule = $moduleHandler->getByDirname('mydownloads'); |
|
369 | - if (is_object($mydownloadsModule)) { |
|
370 | - $mydownloadsButton = new \XoopsFormButton('Import data from MyDownloads', 'myd_button', 'Import', 'submit'); |
|
371 | - $mydownloadsButton->setExtra("onclick='document.forms.form.op.value=\"1\"'"); |
|
372 | - $form->addElement($mydownloadsButton); |
|
373 | - } |
|
374 | - |
|
375 | - if (!wfdownloads_TableExists('wfdownloads_meta')) { |
|
376 | - $updateButton = new \XoopsFormButton('Update WF-Downloads', 'upd_button', 'Update', 'submit'); |
|
377 | - $updateButton->setExtra("onclick='document.forms.form.op.value=\"2\"'"); |
|
378 | - $form->addElement($updateButton); |
|
379 | - } |
|
380 | - |
|
381 | - $form->addElement(new \XoopsFormHidden('op', 0)); |
|
382 | - $form->display(); |
|
383 | - break; |
|
345 | + case 1: |
|
346 | + // Make sure that nohtml is properly changed to dohtml |
|
347 | + invert_nohtm_dohtml_values(); |
|
348 | + // Ensure that the proper tables are present |
|
349 | + update_tables_to_300(); |
|
350 | + // Import data from MyDownloads |
|
351 | + import_mydownloads_to_wfdownloads(); |
|
352 | + break; |
|
353 | + |
|
354 | + case 2: |
|
355 | + // Update WF-Downloads |
|
356 | + $log = invert_nohtm_dohtml_values(); |
|
357 | + update_tables_to_300(); |
|
358 | + break; |
|
359 | + |
|
360 | + default: |
|
361 | + //ask what to do |
|
362 | + include XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
363 | + $form = new \XoopsThemeForm('Upgrade WF-Downloads', 'form', $_SERVER['REQUEST_URI']); |
|
364 | + |
|
365 | + //Is MyDownloads installed? |
|
366 | + /** @var XoopsModuleHandler $moduleHandler */ |
|
367 | + $moduleHandler = xoops_getHandler('module'); |
|
368 | + $mydownloadsModule = $moduleHandler->getByDirname('mydownloads'); |
|
369 | + if (is_object($mydownloadsModule)) { |
|
370 | + $mydownloadsButton = new \XoopsFormButton('Import data from MyDownloads', 'myd_button', 'Import', 'submit'); |
|
371 | + $mydownloadsButton->setExtra("onclick='document.forms.form.op.value=\"1\"'"); |
|
372 | + $form->addElement($mydownloadsButton); |
|
373 | + } |
|
374 | + |
|
375 | + if (!wfdownloads_TableExists('wfdownloads_meta')) { |
|
376 | + $updateButton = new \XoopsFormButton('Update WF-Downloads', 'upd_button', 'Update', 'submit'); |
|
377 | + $updateButton->setExtra("onclick='document.forms.form.op.value=\"2\"'"); |
|
378 | + $form->addElement($updateButton); |
|
379 | + } |
|
380 | + |
|
381 | + $form->addElement(new \XoopsFormHidden('op', 0)); |
|
382 | + $form->display(); |
|
383 | + break; |
|
384 | 384 | } |
385 | 385 | //wfdownloads_modFooter(); |
386 | 386 | //xoops_cp_footer(); |
@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | use XoopsModules\Wfdownloads; |
11 | 11 | use XoopsModules\Smartobject; |
12 | 12 | |
13 | -require_once __DIR__ . '/admin_header.php'; |
|
14 | -require_once SMARTCONTENT_ROOT_PATH . 'class/dbupdater.php'; |
|
13 | +require_once __DIR__.'/admin_header.php'; |
|
14 | +require_once SMARTCONTENT_ROOT_PATH.'class/dbupdater.php'; |
|
15 | 15 | |
16 | 16 | smartcontent_xoops_cp_header(); |
17 | 17 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | global $xoopsDB; |
220 | 220 | $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
221 | 221 | $catHandler = $helperWfdownloads->getHandler('Category'); |
222 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $catHandler->table); |
|
222 | + $result = $xoopsDB->query('SHOW COLUMNS FROM '.$catHandler->table); |
|
223 | 223 | while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
224 | 224 | $fields[$existing_field['field']] = $existing_field['type']; |
225 | 225 | } |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | //$xoopsDB->query("ALTER TABLE ".$table." ADD ".$field." ".$type); |
279 | 279 | //echo $field."(".$type.") <FONT COLOR='##22DD51'>Added</FONT><br>"; |
280 | 280 | } elseif ($existing_fields[$field] != $type) { |
281 | - $table->addAlteredField($field, $field . ' ' . $type); |
|
281 | + $table->addAlteredField($field, $field.' '.$type); |
|
282 | 282 | // check $fields[$field]['type'] for things like "int(10) unsigned" |
283 | 283 | //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$field." ".$type); |
284 | 284 | //echo $field." <FONT COLOR='#FF6600'>Changed to</FONT> ".$type."<br>"; |
@@ -299,17 +299,17 @@ discard block |
||
299 | 299 | function get_table_info($table, $default_fields) |
300 | 300 | { |
301 | 301 | global $xoopsDB; |
302 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $table); |
|
302 | + $result = $xoopsDB->query('SHOW COLUMNS FROM '.$table); |
|
303 | 303 | while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
304 | 304 | $fields[$existing_field['Field']] = $existing_field['Type']; |
305 | 305 | if ('YES' !== $existing_field['Null']) { |
306 | 306 | $fields[$existing_field['Field']] .= ' NOT NULL'; |
307 | 307 | } |
308 | 308 | if ($existing_field['Extra']) { |
309 | - $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
309 | + $fields[$existing_field['Field']] .= ' '.$existing_field['Extra']; |
|
310 | 310 | } |
311 | 311 | if ($default_fields[$existing_field['Field']]['Default']) { |
312 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
312 | + $fields[$existing_field['Field']] .= " default '".$existing_field['Default']."'"; |
|
313 | 313 | } |
314 | 314 | } |
315 | 315 | |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | if (in_array($field, array_keys($renamed_fields))) { |
332 | 332 | $new_field_name = $renamed_fields[$field]; |
333 | 333 | $new_field_type = $new_fields[$new_field_name]['Type']; |
334 | - $table->addAltered($field, $new_field_name . ' ' . $new_field_type); |
|
334 | + $table->addAltered($field, $new_field_name.' '.$new_field_type); |
|
335 | 335 | //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$new_field_name." ".$new_field_type); |
336 | 336 | //echo $field." Renamed to ".$new_field_name."<br>"; |
337 | 337 | $fields[$new_field_name] = $new_field_type; |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | //return $fields; |
341 | 341 | } |
342 | 342 | |
343 | -$op = isset($_REQUEST['op']) ? (int)$_REQUEST['op'] : 0; |
|
343 | +$op = isset($_REQUEST['op']) ? (int) $_REQUEST['op'] : 0; |
|
344 | 344 | switch ($op) { |
345 | 345 | case 1: |
346 | 346 | // Make sure that nohtml is properly changed to dohtml |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | |
360 | 360 | default: |
361 | 361 | //ask what to do |
362 | - include XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
362 | + include XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; |
|
363 | 363 | $form = new \XoopsThemeForm('Upgrade WF-Downloads', 'form', $_SERVER['REQUEST_URI']); |
364 | 364 | |
365 | 365 | //Is MyDownloads installed? |
@@ -384,4 +384,4 @@ discard block |
||
384 | 384 | } |
385 | 385 | //wfdownloads_modFooter(); |
386 | 386 | //xoops_cp_footer(); |
387 | -require_once __DIR__ . '/admin_footer.php'; |
|
387 | +require_once __DIR__.'/admin_footer.php'; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | /** |
144 | 144 | * Use to update a table |
145 | 145 | * |
146 | - * @param object $table {@link SmartDbTable} that will be updated |
|
146 | + * @param DbTable $table {@link SmartDbTable} that will be updated |
|
147 | 147 | * |
148 | 148 | * @see DbTable |
149 | 149 | * |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | /** |
246 | 246 | * @param $module |
247 | 247 | * @param $item |
248 | - * @return bool |
|
248 | + * @return false|null |
|
249 | 249 | */ |
250 | 250 | public function upgradeObjectItem($module, $item) |
251 | 251 | { |
@@ -25,7 +25,6 @@ discard block |
||
25 | 25 | * Contains the classes for updating database tables |
26 | 26 | * |
27 | 27 | * @license GNU |
28 | - |
|
29 | 28 | */ |
30 | 29 | /** |
31 | 30 | * SmartDbTable class |
@@ -38,7 +37,7 @@ discard block |
||
38 | 37 | */ |
39 | 38 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
40 | 39 | if (!defined('SMARTOBJECT_ROOT_PATH')) { |
41 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
40 | + require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
42 | 41 | } |
43 | 42 | /** |
44 | 43 | * Include the language constants for the SmartObjectDBUpdater |
@@ -46,7 +45,7 @@ discard block |
||
46 | 45 | global $xoopsConfig; |
47 | 46 | $common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php'; |
48 | 47 | if (!file_exists($common_file)) { |
49 | - $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
48 | + $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
50 | 49 | } |
51 | 50 | include $common_file; |
52 | 51 | |
@@ -62,328 +61,328 @@ discard block |
||
62 | 61 | */ |
63 | 62 | class Dbupdater |
64 | 63 | { |
65 | - public $_dbTypesArray; |
|
66 | - |
|
67 | - /** |
|
68 | - * SmartobjectDbupdater constructor. |
|
69 | - */ |
|
70 | - public function __construct() |
|
71 | - { |
|
72 | - $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX] = 'varchar(255)'; |
|
73 | - $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA] = 'text'; |
|
74 | - $this->_dbTypesArray[XOBJ_DTYPE_INT] = 'int(11)'; |
|
75 | - $this->_dbTypesArray[XOBJ_DTYPE_URL] = 'varchar(255)'; |
|
76 | - $this->_dbTypesArray[XOBJ_DTYPE_EMAIL] = 'varchar(255)'; |
|
77 | - $this->_dbTypesArray[XOBJ_DTYPE_ARRAY] = 'text'; |
|
78 | - $this->_dbTypesArray[XOBJ_DTYPE_OTHER] = 'text'; |
|
79 | - $this->_dbTypesArray[XOBJ_DTYPE_SOURCE] = 'text'; |
|
80 | - $this->_dbTypesArray[XOBJ_DTYPE_STIME] = 'int(11)'; |
|
81 | - $this->_dbTypesArray[XOBJ_DTYPE_MTIME] = 'int(11)'; |
|
82 | - $this->_dbTypesArray[XOBJ_DTYPE_LTIME] = 'int(11)'; |
|
83 | - $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text'; |
|
84 | - $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY] = 'text'; |
|
85 | - $this->_dbTypesArray[XOBJ_DTYPE_FLOAT] = 'float'; |
|
86 | - $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY] = 'int(11)'; |
|
87 | - $this->_dbTypesArray[XOBJ_DTYPE_URLLINK] = 'int(11)'; |
|
88 | - $this->_dbTypesArray[XOBJ_DTYPE_FILE] = 'int(11)'; |
|
89 | - $this->_dbTypesArray[XOBJ_DTYPE_IMAGE] = 'varchar(255)'; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Use to execute a general query |
|
94 | - * |
|
95 | - * @param string $query query that will be executed |
|
96 | - * @param string $goodmsg message displayed on success |
|
97 | - * @param string $badmsg message displayed on error |
|
98 | - * |
|
99 | - * @return bool true if success, false if an error occured |
|
100 | - * |
|
101 | - */ |
|
102 | - public function runQuery($query, $goodmsg, $badmsg) |
|
103 | - { |
|
104 | - global $xoopsDB; |
|
105 | - $ret = $xoopsDB->query($query); |
|
106 | - if (!$ret) { |
|
107 | - echo " $badmsg<br>"; |
|
108 | - |
|
109 | - return false; |
|
110 | - } else { |
|
111 | - echo " $goodmsg<br>"; |
|
112 | - |
|
113 | - return true; |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Use to rename a table |
|
119 | - * |
|
120 | - * @param string $from name of the table to rename |
|
121 | - * @param string $to new name of the renamed table |
|
122 | - * |
|
123 | - * @return bool true if success, false if an error occured |
|
124 | - */ |
|
125 | - public function renameTable($from, $to) |
|
126 | - { |
|
127 | - global $xoopsDB; |
|
128 | - $from = $xoopsDB->prefix($from); |
|
129 | - $to = $xoopsDB->prefix($to); |
|
130 | - $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
|
131 | - $ret = $xoopsDB->query($query); |
|
132 | - if (!$ret) { |
|
133 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>'; |
|
134 | - |
|
135 | - return false; |
|
136 | - } else { |
|
137 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>'; |
|
138 | - |
|
139 | - return true; |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Use to update a table |
|
145 | - * |
|
146 | - * @param object $table {@link SmartDbTable} that will be updated |
|
147 | - * |
|
148 | - * @see DbTable |
|
149 | - * |
|
150 | - * @return bool true if success, false if an error occured |
|
151 | - */ |
|
152 | - public function updateTable($table) |
|
153 | - { |
|
154 | - global $xoopsDB; |
|
155 | - $ret = true; |
|
156 | - // If table has a structure, create the table |
|
157 | - if ($table->getStructure()) { |
|
158 | - $ret = $table->createTable() && $ret; |
|
159 | - } |
|
160 | - // If table is flag for drop, drop it |
|
161 | - if ($table->_flagForDrop) { |
|
162 | - $ret = $table->dropTable() && $ret; |
|
163 | - } |
|
164 | - // If table has data, insert it |
|
165 | - if ($table->getData()) { |
|
166 | - $ret = $table->addData() && $ret; |
|
167 | - } |
|
168 | - // If table has new fields to be added, add them |
|
169 | - if ($table->getNewFields()) { |
|
170 | - $ret = $table->addNewFields() && $ret; |
|
171 | - } |
|
172 | - // If table has altered field, alter the table |
|
173 | - if ($table->getAlteredFields()) { |
|
174 | - $ret = $table->alterTable() && $ret; |
|
175 | - } |
|
176 | - // If table has updated field values, update the table |
|
177 | - if ($table->getUpdatedFields()) { |
|
178 | - $ret = $table->updateFieldsValues($table) && $ret; |
|
179 | - } |
|
180 | - // If table has dropped field, alter the table |
|
181 | - if ($table->getDroppedFields()) { |
|
182 | - $ret = $table->dropFields($table) && $ret; |
|
183 | - } |
|
184 | - //felix |
|
185 | - // If table has updated field values, update the table |
|
186 | - if ($table->getUpdatedWhere()) { |
|
187 | - $ret = $table->UpdateWhereValues($table) && $ret; |
|
188 | - } |
|
189 | - |
|
190 | - return $ret; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * @param $module |
|
195 | - * @param $item |
|
196 | - */ |
|
197 | - public function automaticUpgrade($module, $item) |
|
198 | - { |
|
199 | - if (is_array($item)) { |
|
200 | - foreach ($item as $v) { |
|
201 | - $this->upgradeObjectItem($module, $v); |
|
202 | - } |
|
203 | - } else { |
|
204 | - $this->upgradeObjectItem($module, $item); |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * @param $var |
|
210 | - * @return string |
|
211 | - */ |
|
212 | - public function getFieldTypeFromVar($var) |
|
213 | - { |
|
214 | - $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text'; |
|
215 | - |
|
216 | - return $ret; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @param $var |
|
221 | - * @param bool $key |
|
222 | - * @return string |
|
223 | - */ |
|
224 | - public function getFieldDefaultFromVar($var, $key = false) |
|
225 | - { |
|
226 | - if ($var['value']) { |
|
227 | - return $var['value']; |
|
228 | - } else { |
|
229 | - if (in_array($var['data_type'], [ |
|
230 | - XOBJ_DTYPE_INT, |
|
231 | - XOBJ_DTYPE_STIME, |
|
232 | - XOBJ_DTYPE_MTIME, |
|
233 | - XOBJ_DTYPE_LTIME, |
|
234 | - XOBJ_DTYPE_TIME_ONLY, |
|
235 | - XOBJ_DTYPE_URLLINK, |
|
236 | - XOBJ_DTYPE_FILE |
|
237 | - ])) { |
|
238 | - return '0'; |
|
239 | - } else { |
|
240 | - return ''; |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * @param $module |
|
247 | - * @param $item |
|
248 | - * @return bool |
|
249 | - */ |
|
250 | - public function upgradeObjectItem($module, $item) |
|
251 | - { |
|
252 | - $moduleHandler = xoops_getModuleHandler($item, $module); |
|
253 | - if (!$moduleHandler) { |
|
254 | - return false; |
|
255 | - } |
|
256 | - |
|
257 | - $table = new DbTable($module . '_' . $item); |
|
258 | - $object = $moduleHandler->create(); |
|
259 | - $objectVars = $object->getVars(); |
|
260 | - |
|
261 | - if (!$table->exists()) { |
|
262 | - // table was never created, let's do it |
|
263 | - $structure = ''; |
|
264 | - foreach ($objectVars as $key => $var) { |
|
265 | - if ($var['persistent']) { |
|
266 | - $type = $this->getFieldTypeFromVar($var); |
|
267 | - if ($key == $moduleHandler->keyName) { |
|
268 | - $extra = 'auto_increment'; |
|
269 | - } else { |
|
270 | - $default = $this->getFieldDefaultFromVar($var); |
|
271 | - $extra = "default '$default' |
|
64 | + public $_dbTypesArray; |
|
65 | + |
|
66 | + /** |
|
67 | + * SmartobjectDbupdater constructor. |
|
68 | + */ |
|
69 | + public function __construct() |
|
70 | + { |
|
71 | + $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX] = 'varchar(255)'; |
|
72 | + $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA] = 'text'; |
|
73 | + $this->_dbTypesArray[XOBJ_DTYPE_INT] = 'int(11)'; |
|
74 | + $this->_dbTypesArray[XOBJ_DTYPE_URL] = 'varchar(255)'; |
|
75 | + $this->_dbTypesArray[XOBJ_DTYPE_EMAIL] = 'varchar(255)'; |
|
76 | + $this->_dbTypesArray[XOBJ_DTYPE_ARRAY] = 'text'; |
|
77 | + $this->_dbTypesArray[XOBJ_DTYPE_OTHER] = 'text'; |
|
78 | + $this->_dbTypesArray[XOBJ_DTYPE_SOURCE] = 'text'; |
|
79 | + $this->_dbTypesArray[XOBJ_DTYPE_STIME] = 'int(11)'; |
|
80 | + $this->_dbTypesArray[XOBJ_DTYPE_MTIME] = 'int(11)'; |
|
81 | + $this->_dbTypesArray[XOBJ_DTYPE_LTIME] = 'int(11)'; |
|
82 | + $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text'; |
|
83 | + $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY] = 'text'; |
|
84 | + $this->_dbTypesArray[XOBJ_DTYPE_FLOAT] = 'float'; |
|
85 | + $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY] = 'int(11)'; |
|
86 | + $this->_dbTypesArray[XOBJ_DTYPE_URLLINK] = 'int(11)'; |
|
87 | + $this->_dbTypesArray[XOBJ_DTYPE_FILE] = 'int(11)'; |
|
88 | + $this->_dbTypesArray[XOBJ_DTYPE_IMAGE] = 'varchar(255)'; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Use to execute a general query |
|
93 | + * |
|
94 | + * @param string $query query that will be executed |
|
95 | + * @param string $goodmsg message displayed on success |
|
96 | + * @param string $badmsg message displayed on error |
|
97 | + * |
|
98 | + * @return bool true if success, false if an error occured |
|
99 | + * |
|
100 | + */ |
|
101 | + public function runQuery($query, $goodmsg, $badmsg) |
|
102 | + { |
|
103 | + global $xoopsDB; |
|
104 | + $ret = $xoopsDB->query($query); |
|
105 | + if (!$ret) { |
|
106 | + echo " $badmsg<br>"; |
|
107 | + |
|
108 | + return false; |
|
109 | + } else { |
|
110 | + echo " $goodmsg<br>"; |
|
111 | + |
|
112 | + return true; |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Use to rename a table |
|
118 | + * |
|
119 | + * @param string $from name of the table to rename |
|
120 | + * @param string $to new name of the renamed table |
|
121 | + * |
|
122 | + * @return bool true if success, false if an error occured |
|
123 | + */ |
|
124 | + public function renameTable($from, $to) |
|
125 | + { |
|
126 | + global $xoopsDB; |
|
127 | + $from = $xoopsDB->prefix($from); |
|
128 | + $to = $xoopsDB->prefix($to); |
|
129 | + $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
|
130 | + $ret = $xoopsDB->query($query); |
|
131 | + if (!$ret) { |
|
132 | + echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>'; |
|
133 | + |
|
134 | + return false; |
|
135 | + } else { |
|
136 | + echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>'; |
|
137 | + |
|
138 | + return true; |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Use to update a table |
|
144 | + * |
|
145 | + * @param object $table {@link SmartDbTable} that will be updated |
|
146 | + * |
|
147 | + * @see DbTable |
|
148 | + * |
|
149 | + * @return bool true if success, false if an error occured |
|
150 | + */ |
|
151 | + public function updateTable($table) |
|
152 | + { |
|
153 | + global $xoopsDB; |
|
154 | + $ret = true; |
|
155 | + // If table has a structure, create the table |
|
156 | + if ($table->getStructure()) { |
|
157 | + $ret = $table->createTable() && $ret; |
|
158 | + } |
|
159 | + // If table is flag for drop, drop it |
|
160 | + if ($table->_flagForDrop) { |
|
161 | + $ret = $table->dropTable() && $ret; |
|
162 | + } |
|
163 | + // If table has data, insert it |
|
164 | + if ($table->getData()) { |
|
165 | + $ret = $table->addData() && $ret; |
|
166 | + } |
|
167 | + // If table has new fields to be added, add them |
|
168 | + if ($table->getNewFields()) { |
|
169 | + $ret = $table->addNewFields() && $ret; |
|
170 | + } |
|
171 | + // If table has altered field, alter the table |
|
172 | + if ($table->getAlteredFields()) { |
|
173 | + $ret = $table->alterTable() && $ret; |
|
174 | + } |
|
175 | + // If table has updated field values, update the table |
|
176 | + if ($table->getUpdatedFields()) { |
|
177 | + $ret = $table->updateFieldsValues($table) && $ret; |
|
178 | + } |
|
179 | + // If table has dropped field, alter the table |
|
180 | + if ($table->getDroppedFields()) { |
|
181 | + $ret = $table->dropFields($table) && $ret; |
|
182 | + } |
|
183 | + //felix |
|
184 | + // If table has updated field values, update the table |
|
185 | + if ($table->getUpdatedWhere()) { |
|
186 | + $ret = $table->UpdateWhereValues($table) && $ret; |
|
187 | + } |
|
188 | + |
|
189 | + return $ret; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * @param $module |
|
194 | + * @param $item |
|
195 | + */ |
|
196 | + public function automaticUpgrade($module, $item) |
|
197 | + { |
|
198 | + if (is_array($item)) { |
|
199 | + foreach ($item as $v) { |
|
200 | + $this->upgradeObjectItem($module, $v); |
|
201 | + } |
|
202 | + } else { |
|
203 | + $this->upgradeObjectItem($module, $item); |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * @param $var |
|
209 | + * @return string |
|
210 | + */ |
|
211 | + public function getFieldTypeFromVar($var) |
|
212 | + { |
|
213 | + $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text'; |
|
214 | + |
|
215 | + return $ret; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * @param $var |
|
220 | + * @param bool $key |
|
221 | + * @return string |
|
222 | + */ |
|
223 | + public function getFieldDefaultFromVar($var, $key = false) |
|
224 | + { |
|
225 | + if ($var['value']) { |
|
226 | + return $var['value']; |
|
227 | + } else { |
|
228 | + if (in_array($var['data_type'], [ |
|
229 | + XOBJ_DTYPE_INT, |
|
230 | + XOBJ_DTYPE_STIME, |
|
231 | + XOBJ_DTYPE_MTIME, |
|
232 | + XOBJ_DTYPE_LTIME, |
|
233 | + XOBJ_DTYPE_TIME_ONLY, |
|
234 | + XOBJ_DTYPE_URLLINK, |
|
235 | + XOBJ_DTYPE_FILE |
|
236 | + ])) { |
|
237 | + return '0'; |
|
238 | + } else { |
|
239 | + return ''; |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * @param $module |
|
246 | + * @param $item |
|
247 | + * @return bool |
|
248 | + */ |
|
249 | + public function upgradeObjectItem($module, $item) |
|
250 | + { |
|
251 | + $moduleHandler = xoops_getModuleHandler($item, $module); |
|
252 | + if (!$moduleHandler) { |
|
253 | + return false; |
|
254 | + } |
|
255 | + |
|
256 | + $table = new DbTable($module . '_' . $item); |
|
257 | + $object = $moduleHandler->create(); |
|
258 | + $objectVars = $object->getVars(); |
|
259 | + |
|
260 | + if (!$table->exists()) { |
|
261 | + // table was never created, let's do it |
|
262 | + $structure = ''; |
|
263 | + foreach ($objectVars as $key => $var) { |
|
264 | + if ($var['persistent']) { |
|
265 | + $type = $this->getFieldTypeFromVar($var); |
|
266 | + if ($key == $moduleHandler->keyName) { |
|
267 | + $extra = 'auto_increment'; |
|
268 | + } else { |
|
269 | + $default = $this->getFieldDefaultFromVar($var); |
|
270 | + $extra = "default '$default' |
|
272 | 271 | "; |
273 | - } |
|
274 | - $structure .= "`$key` $type not null $extra, |
|
272 | + } |
|
273 | + $structure .= "`$key` $type not null $extra, |
|
275 | 274 | "; |
276 | - } |
|
277 | - } |
|
278 | - $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
275 | + } |
|
276 | + } |
|
277 | + $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
279 | 278 | '; |
280 | - $table->setStructure($structure); |
|
281 | - if (!$this->updateTable($table)) { |
|
282 | - /** |
|
283 | - * @todo trap the errors |
|
284 | - */ |
|
285 | - } |
|
286 | - } else { |
|
287 | - $existingFieldsArray = $table->getExistingFieldsArray(); |
|
288 | - foreach ($objectVars as $key => $var) { |
|
289 | - if ($var['persistent']) { |
|
290 | - if (!isset($existingFieldsArray[$key])) { |
|
291 | - // the fiels does not exist, let's create it |
|
292 | - $type = $this->getFieldTypeFromVar($var); |
|
293 | - $default = $this->getFieldDefaultFromVar($var); |
|
294 | - $table->addNewField($key, "$type not null default '$default'"); |
|
295 | - } else { |
|
296 | - // if field already exists, let's check if the definition is correct |
|
297 | - $definition = strtolower($existingFieldsArray[$key]); |
|
298 | - $type = $this->getFieldTypeFromVar($var); |
|
299 | - if ($key == $moduleHandler->keyName) { |
|
300 | - $extra = 'auto_increment'; |
|
301 | - } else { |
|
302 | - $default = $this->getFieldDefaultFromVar($var, $key); |
|
303 | - $extra = "default '$default'"; |
|
304 | - } |
|
305 | - $actual_definition = "$type not null $extra"; |
|
306 | - if ($definition != $actual_definition) { |
|
307 | - $table->addAlteredField($key, $actual_definition); |
|
308 | - } |
|
309 | - } |
|
310 | - } |
|
311 | - } |
|
312 | - |
|
313 | - // check to see if there are some unused fields left in the table |
|
314 | - foreach ($existingFieldsArray as $key => $v) { |
|
315 | - if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) { |
|
316 | - $table->addDroppedField($key); |
|
317 | - } |
|
318 | - } |
|
319 | - |
|
320 | - if (!$this->updateTable($table)) { |
|
321 | - /** |
|
322 | - * @todo trap the errors |
|
323 | - */ |
|
324 | - } |
|
325 | - } |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * @param $module |
|
330 | - * @return bool |
|
331 | - */ |
|
332 | - public function moduleUpgrade(\XoopsModule $module) |
|
333 | - { |
|
334 | - $dirname = $module->getVar('dirname'); |
|
335 | - |
|
336 | - ob_start(); |
|
337 | - |
|
338 | - $table = new DbTable($dirname . '_meta'); |
|
339 | - if (!$table->exists()) { |
|
340 | - $table->setStructure(" |
|
279 | + $table->setStructure($structure); |
|
280 | + if (!$this->updateTable($table)) { |
|
281 | + /** |
|
282 | + * @todo trap the errors |
|
283 | + */ |
|
284 | + } |
|
285 | + } else { |
|
286 | + $existingFieldsArray = $table->getExistingFieldsArray(); |
|
287 | + foreach ($objectVars as $key => $var) { |
|
288 | + if ($var['persistent']) { |
|
289 | + if (!isset($existingFieldsArray[$key])) { |
|
290 | + // the fiels does not exist, let's create it |
|
291 | + $type = $this->getFieldTypeFromVar($var); |
|
292 | + $default = $this->getFieldDefaultFromVar($var); |
|
293 | + $table->addNewField($key, "$type not null default '$default'"); |
|
294 | + } else { |
|
295 | + // if field already exists, let's check if the definition is correct |
|
296 | + $definition = strtolower($existingFieldsArray[$key]); |
|
297 | + $type = $this->getFieldTypeFromVar($var); |
|
298 | + if ($key == $moduleHandler->keyName) { |
|
299 | + $extra = 'auto_increment'; |
|
300 | + } else { |
|
301 | + $default = $this->getFieldDefaultFromVar($var, $key); |
|
302 | + $extra = "default '$default'"; |
|
303 | + } |
|
304 | + $actual_definition = "$type not null $extra"; |
|
305 | + if ($definition != $actual_definition) { |
|
306 | + $table->addAlteredField($key, $actual_definition); |
|
307 | + } |
|
308 | + } |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + // check to see if there are some unused fields left in the table |
|
313 | + foreach ($existingFieldsArray as $key => $v) { |
|
314 | + if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) { |
|
315 | + $table->addDroppedField($key); |
|
316 | + } |
|
317 | + } |
|
318 | + |
|
319 | + if (!$this->updateTable($table)) { |
|
320 | + /** |
|
321 | + * @todo trap the errors |
|
322 | + */ |
|
323 | + } |
|
324 | + } |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * @param $module |
|
329 | + * @return bool |
|
330 | + */ |
|
331 | + public function moduleUpgrade(\XoopsModule $module) |
|
332 | + { |
|
333 | + $dirname = $module->getVar('dirname'); |
|
334 | + |
|
335 | + ob_start(); |
|
336 | + |
|
337 | + $table = new DbTable($dirname . '_meta'); |
|
338 | + if (!$table->exists()) { |
|
339 | + $table->setStructure(" |
|
341 | 340 | `metakey` varchar(50) NOT NULL default '', |
342 | 341 | `metavalue` varchar(255) NOT NULL default '', |
343 | 342 | PRIMARY KEY (`metakey`)"); |
344 | - $table->setData("'version',0"); |
|
345 | - if (!$this->updateTable($table)) { |
|
346 | - /** |
|
347 | - * @todo trap the errors |
|
348 | - */ |
|
349 | - } |
|
350 | - } |
|
351 | - |
|
352 | - $dbVersion = Smartobject\Utility::getMeta('version', $dirname); |
|
353 | - if (!$dbVersion) { |
|
354 | - $dbVersion = 0; |
|
355 | - } |
|
356 | - $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
357 | - echo 'Database version: ' . $dbVersion . '<br>'; |
|
358 | - echo 'New database version: ' . $newDbVersion . '<br>'; |
|
359 | - |
|
360 | - if ($newDbVersion > $dbVersion) { |
|
361 | - for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
|
362 | - $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
363 | - if (function_exists($upgrade_function)) { |
|
364 | - $upgrade_function(); |
|
365 | - } |
|
366 | - } |
|
367 | - } |
|
368 | - |
|
369 | - echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
370 | - |
|
371 | - // if there is a function to execute for this DB version, let's do it |
|
372 | - //$function_ |
|
373 | - |
|
374 | - $module_info = Smartobject\Utility::getModuleInfo($dirname); |
|
375 | - $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']); |
|
376 | - |
|
377 | - echo '</code>'; |
|
378 | - |
|
379 | - $feedback = ob_get_clean(); |
|
380 | - if (method_exists($module, 'setMessage')) { |
|
381 | - $module->setMessage($feedback); |
|
382 | - } else { |
|
383 | - echo $feedback; |
|
384 | - } |
|
385 | - Smartobject\Utility::setMeta('version', $newDbVersion, $dirname); //Set meta version to current |
|
386 | - |
|
387 | - return true; |
|
388 | - } |
|
343 | + $table->setData("'version',0"); |
|
344 | + if (!$this->updateTable($table)) { |
|
345 | + /** |
|
346 | + * @todo trap the errors |
|
347 | + */ |
|
348 | + } |
|
349 | + } |
|
350 | + |
|
351 | + $dbVersion = Smartobject\Utility::getMeta('version', $dirname); |
|
352 | + if (!$dbVersion) { |
|
353 | + $dbVersion = 0; |
|
354 | + } |
|
355 | + $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
356 | + echo 'Database version: ' . $dbVersion . '<br>'; |
|
357 | + echo 'New database version: ' . $newDbVersion . '<br>'; |
|
358 | + |
|
359 | + if ($newDbVersion > $dbVersion) { |
|
360 | + for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
|
361 | + $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
362 | + if (function_exists($upgrade_function)) { |
|
363 | + $upgrade_function(); |
|
364 | + } |
|
365 | + } |
|
366 | + } |
|
367 | + |
|
368 | + echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
369 | + |
|
370 | + // if there is a function to execute for this DB version, let's do it |
|
371 | + //$function_ |
|
372 | + |
|
373 | + $module_info = Smartobject\Utility::getModuleInfo($dirname); |
|
374 | + $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']); |
|
375 | + |
|
376 | + echo '</code>'; |
|
377 | + |
|
378 | + $feedback = ob_get_clean(); |
|
379 | + if (method_exists($module, 'setMessage')) { |
|
380 | + $module->setMessage($feedback); |
|
381 | + } else { |
|
382 | + echo $feedback; |
|
383 | + } |
|
384 | + Smartobject\Utility::setMeta('version', $newDbVersion, $dirname); //Set meta version to current |
|
385 | + |
|
386 | + return true; |
|
387 | + } |
|
389 | 388 | } |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | */ |
39 | 39 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
40 | 40 | if (!defined('SMARTOBJECT_ROOT_PATH')) { |
41 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
41 | + require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php'; |
|
42 | 42 | } |
43 | 43 | /** |
44 | 44 | * Include the language constants for the SmartObjectDBUpdater |
45 | 45 | */ |
46 | 46 | global $xoopsConfig; |
47 | -$common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php'; |
|
47 | +$common_file = SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/smartdbupdater.php'; |
|
48 | 48 | if (!file_exists($common_file)) { |
49 | - $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
49 | + $common_file = SMARTOBJECT_ROOT_PATH.'language/english/smartdbupdater.php'; |
|
50 | 50 | } |
51 | 51 | include $common_file; |
52 | 52 | |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
131 | 131 | $ret = $xoopsDB->query($query); |
132 | 132 | if (!$ret) { |
133 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>'; |
|
133 | + echo ' '.sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from).'<br>'; |
|
134 | 134 | |
135 | 135 | return false; |
136 | 136 | } else { |
137 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>'; |
|
137 | + echo ' '.sprintf(_SDU_MSG_RENAME_TABLE, $from, $to).'<br>'; |
|
138 | 138 | |
139 | 139 | return true; |
140 | 140 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | return false; |
255 | 255 | } |
256 | 256 | |
257 | - $table = new DbTable($module . '_' . $item); |
|
257 | + $table = new DbTable($module.'_'.$item); |
|
258 | 258 | $object = $moduleHandler->create(); |
259 | 259 | $objectVars = $object->getVars(); |
260 | 260 | |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | "; |
276 | 276 | } |
277 | 277 | } |
278 | - $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
278 | + $structure .= 'PRIMARY KEY (`'.$moduleHandler->keyName.'`) |
|
279 | 279 | '; |
280 | 280 | $table->setStructure($structure); |
281 | 281 | if (!$this->updateTable($table)) { |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | |
336 | 336 | ob_start(); |
337 | 337 | |
338 | - $table = new DbTable($dirname . '_meta'); |
|
338 | + $table = new DbTable($dirname.'_meta'); |
|
339 | 339 | if (!$table->exists()) { |
340 | 340 | $table->setStructure(" |
341 | 341 | `metakey` varchar(50) NOT NULL default '', |
@@ -353,20 +353,20 @@ discard block |
||
353 | 353 | if (!$dbVersion) { |
354 | 354 | $dbVersion = 0; |
355 | 355 | } |
356 | - $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
357 | - echo 'Database version: ' . $dbVersion . '<br>'; |
|
358 | - echo 'New database version: ' . $newDbVersion . '<br>'; |
|
356 | + $newDbVersion = constant(strtoupper($dirname.'_db_version')) ?: 0; |
|
357 | + echo 'Database version: '.$dbVersion.'<br>'; |
|
358 | + echo 'New database version: '.$newDbVersion.'<br>'; |
|
359 | 359 | |
360 | 360 | if ($newDbVersion > $dbVersion) { |
361 | 361 | for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
362 | - $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
362 | + $upgrade_function = $dirname.'_db_upgrade_'.$i; |
|
363 | 363 | if (function_exists($upgrade_function)) { |
364 | 364 | $upgrade_function(); |
365 | 365 | } |
366 | 366 | } |
367 | 367 | } |
368 | 368 | |
369 | - echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
|
369 | + echo '<code>'._SDU_UPDATE_UPDATING_DATABASE.'<br>'; |
|
370 | 370 | |
371 | 371 | // if there is a function to execute for this DB version, let's do it |
372 | 372 | //$function_ |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | |
127 | 127 | /** |
128 | 128 | * @param $smartObj |
129 | - * @param $objectid |
|
130 | - * @param $created_success_msg |
|
131 | - * @param $modified_success_msg |
|
129 | + * @param integer $objectid |
|
130 | + * @param string $created_success_msg |
|
131 | + * @param string $modified_success_msg |
|
132 | 132 | * @param bool $redirect_page |
133 | 133 | * @param bool $debug |
134 | 134 | * @return mixed |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | } |
441 | 441 | |
442 | 442 | /** |
443 | - * @param $smartObj |
|
443 | + * @param MlObject $smartObj |
|
444 | 444 | * @param bool $onlyUrl |
445 | 445 | * @param bool $withimage |
446 | 446 | * @return string |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | } |
499 | 499 | |
500 | 500 | /** |
501 | - * @param $smartObj |
|
501 | + * @param BaseSmartObject $smartObj |
|
502 | 502 | * @return string |
503 | 503 | */ |
504 | 504 | public function getPrintAndMailLink($smartObj) |
@@ -33,511 +33,511 @@ |
||
33 | 33 | */ |
34 | 34 | class ObjectController |
35 | 35 | { |
36 | - public $handler; |
|
37 | - |
|
38 | - /** |
|
39 | - * SmartObjectController constructor. |
|
40 | - * @param $handler |
|
41 | - */ |
|
42 | - public function __construct($handler) |
|
43 | - { |
|
44 | - $this->handler = $handler; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * @param $smartObj |
|
49 | - */ |
|
50 | - public function postDataToObject(&$smartObj) |
|
51 | - { |
|
52 | - foreach (array_keys($smartObj->vars) as $key) { |
|
53 | - switch ($smartObj->vars[$key]['data_type']) { |
|
54 | - case XOBJ_DTYPE_IMAGE: |
|
55 | - if (isset($_POST['url_' . $key]) && '' !== $_POST['url_' . $key]) { |
|
56 | - $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
57 | - $smartObj->setVar($key, $_POST['url_' . $key]); |
|
58 | - if (file_exists($oldFile)) { |
|
59 | - unlink($oldFile); |
|
60 | - } |
|
61 | - } |
|
62 | - if (isset($_POST['delete_' . $key]) && '1' == $_POST['delete_' . $key]) { |
|
63 | - $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
64 | - $smartObj->setVar($key, ''); |
|
65 | - if (file_exists($oldFile)) { |
|
66 | - unlink($oldFile); |
|
67 | - } |
|
68 | - } |
|
69 | - break; |
|
70 | - |
|
71 | - case XOBJ_DTYPE_URLLINK: |
|
72 | - $linkObj = $smartObj->getUrlLinkObj($key); |
|
73 | - $linkObj->setVar('caption', $_POST['caption_' . $key]); |
|
74 | - $linkObj->setVar('description', $_POST['desc_' . $key]); |
|
75 | - $linkObj->setVar('target', $_POST['target_' . $key]); |
|
76 | - $linkObj->setVar('url', $_POST['url_' . $key]); |
|
77 | - if ('' !== $linkObj->getVar('url')) { |
|
78 | - $smartObj->storeUrlLinkObj($linkObj); |
|
79 | - } |
|
80 | - //todo: catch errors |
|
81 | - $smartObj->setVar($key, $linkObj->getVar('urllinkid')); |
|
82 | - break; |
|
83 | - |
|
84 | - case XOBJ_DTYPE_FILE: |
|
85 | - if (!isset($_FILES['upload_' . $key]['name']) || '' === $_FILES['upload_' . $key]['name']) { |
|
86 | - $fileObj = $smartObj->getFileObj($key); |
|
87 | - $fileObj->setVar('caption', $_POST['caption_' . $key]); |
|
88 | - $fileObj->setVar('description', $_POST['desc_' . $key]); |
|
89 | - $fileObj->setVar('url', $_POST['url_' . $key]); |
|
90 | - if (!('' === $fileObj->getVar('url') && '' === $fileObj->getVar('url') |
|
91 | - && '' === $fileObj->getVar('url'))) { |
|
92 | - $res = $smartObj->storeFileObj($fileObj); |
|
93 | - if ($res) { |
|
94 | - $smartObj->setVar($key, $fileObj->getVar('fileid')); |
|
95 | - } else { |
|
96 | - //error setted, but no error message (to be improved) |
|
97 | - $smartObj->setErrors($fileObj->getErrors()); |
|
98 | - } |
|
99 | - } |
|
100 | - } |
|
101 | - break; |
|
102 | - |
|
103 | - case XOBJ_DTYPE_STIME: |
|
104 | - case XOBJ_DTYPE_MTIME: |
|
105 | - case XOBJ_DTYPE_LTIME: |
|
106 | - // check if this field's value is available in the POST array |
|
107 | - if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) { |
|
108 | - $value = strtotime($_POST[$key]['date']) + $_POST[$key]['time']; |
|
109 | - } else { |
|
110 | - $value = strtotime($_POST[$key]); |
|
111 | - //if strtotime returns false, the value is already a time stamp |
|
112 | - if (!$value) { |
|
113 | - $value = (int)$_POST[$key]; |
|
114 | - } |
|
115 | - } |
|
116 | - $smartObj->setVar($key, $value); |
|
117 | - |
|
118 | - break; |
|
119 | - |
|
120 | - default: |
|
121 | - $smartObj->setVar($key, $_POST[$key]); |
|
122 | - break; |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @param $smartObj |
|
129 | - * @param $objectid |
|
130 | - * @param $created_success_msg |
|
131 | - * @param $modified_success_msg |
|
132 | - * @param bool $redirect_page |
|
133 | - * @param bool $debug |
|
134 | - * @return mixed |
|
135 | - */ |
|
136 | - public function doStoreFromDefaultForm( |
|
137 | - &$smartObj, |
|
138 | - $objectid, |
|
139 | - $created_success_msg, |
|
140 | - $modified_success_msg, |
|
141 | - $redirect_page = false, |
|
142 | - $debug = false |
|
143 | - ) { |
|
144 | - global $smart_previous_page; |
|
145 | - |
|
146 | - $this->postDataToObject($smartObj); |
|
147 | - |
|
148 | - if ($smartObj->isNew()) { |
|
149 | - $redirect_msg = $created_success_msg; |
|
150 | - } else { |
|
151 | - $redirect_msg = $modified_success_msg; |
|
152 | - } |
|
153 | - |
|
154 | - // Check if there were uploaded files |
|
155 | - if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) { |
|
36 | + public $handler; |
|
37 | + |
|
38 | + /** |
|
39 | + * SmartObjectController constructor. |
|
40 | + * @param $handler |
|
41 | + */ |
|
42 | + public function __construct($handler) |
|
43 | + { |
|
44 | + $this->handler = $handler; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * @param $smartObj |
|
49 | + */ |
|
50 | + public function postDataToObject(&$smartObj) |
|
51 | + { |
|
52 | + foreach (array_keys($smartObj->vars) as $key) { |
|
53 | + switch ($smartObj->vars[$key]['data_type']) { |
|
54 | + case XOBJ_DTYPE_IMAGE: |
|
55 | + if (isset($_POST['url_' . $key]) && '' !== $_POST['url_' . $key]) { |
|
56 | + $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
57 | + $smartObj->setVar($key, $_POST['url_' . $key]); |
|
58 | + if (file_exists($oldFile)) { |
|
59 | + unlink($oldFile); |
|
60 | + } |
|
61 | + } |
|
62 | + if (isset($_POST['delete_' . $key]) && '1' == $_POST['delete_' . $key]) { |
|
63 | + $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
64 | + $smartObj->setVar($key, ''); |
|
65 | + if (file_exists($oldFile)) { |
|
66 | + unlink($oldFile); |
|
67 | + } |
|
68 | + } |
|
69 | + break; |
|
70 | + |
|
71 | + case XOBJ_DTYPE_URLLINK: |
|
72 | + $linkObj = $smartObj->getUrlLinkObj($key); |
|
73 | + $linkObj->setVar('caption', $_POST['caption_' . $key]); |
|
74 | + $linkObj->setVar('description', $_POST['desc_' . $key]); |
|
75 | + $linkObj->setVar('target', $_POST['target_' . $key]); |
|
76 | + $linkObj->setVar('url', $_POST['url_' . $key]); |
|
77 | + if ('' !== $linkObj->getVar('url')) { |
|
78 | + $smartObj->storeUrlLinkObj($linkObj); |
|
79 | + } |
|
80 | + //todo: catch errors |
|
81 | + $smartObj->setVar($key, $linkObj->getVar('urllinkid')); |
|
82 | + break; |
|
83 | + |
|
84 | + case XOBJ_DTYPE_FILE: |
|
85 | + if (!isset($_FILES['upload_' . $key]['name']) || '' === $_FILES['upload_' . $key]['name']) { |
|
86 | + $fileObj = $smartObj->getFileObj($key); |
|
87 | + $fileObj->setVar('caption', $_POST['caption_' . $key]); |
|
88 | + $fileObj->setVar('description', $_POST['desc_' . $key]); |
|
89 | + $fileObj->setVar('url', $_POST['url_' . $key]); |
|
90 | + if (!('' === $fileObj->getVar('url') && '' === $fileObj->getVar('url') |
|
91 | + && '' === $fileObj->getVar('url'))) { |
|
92 | + $res = $smartObj->storeFileObj($fileObj); |
|
93 | + if ($res) { |
|
94 | + $smartObj->setVar($key, $fileObj->getVar('fileid')); |
|
95 | + } else { |
|
96 | + //error setted, but no error message (to be improved) |
|
97 | + $smartObj->setErrors($fileObj->getErrors()); |
|
98 | + } |
|
99 | + } |
|
100 | + } |
|
101 | + break; |
|
102 | + |
|
103 | + case XOBJ_DTYPE_STIME: |
|
104 | + case XOBJ_DTYPE_MTIME: |
|
105 | + case XOBJ_DTYPE_LTIME: |
|
106 | + // check if this field's value is available in the POST array |
|
107 | + if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) { |
|
108 | + $value = strtotime($_POST[$key]['date']) + $_POST[$key]['time']; |
|
109 | + } else { |
|
110 | + $value = strtotime($_POST[$key]); |
|
111 | + //if strtotime returns false, the value is already a time stamp |
|
112 | + if (!$value) { |
|
113 | + $value = (int)$_POST[$key]; |
|
114 | + } |
|
115 | + } |
|
116 | + $smartObj->setVar($key, $value); |
|
117 | + |
|
118 | + break; |
|
119 | + |
|
120 | + default: |
|
121 | + $smartObj->setVar($key, $_POST[$key]); |
|
122 | + break; |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @param $smartObj |
|
129 | + * @param $objectid |
|
130 | + * @param $created_success_msg |
|
131 | + * @param $modified_success_msg |
|
132 | + * @param bool $redirect_page |
|
133 | + * @param bool $debug |
|
134 | + * @return mixed |
|
135 | + */ |
|
136 | + public function doStoreFromDefaultForm( |
|
137 | + &$smartObj, |
|
138 | + $objectid, |
|
139 | + $created_success_msg, |
|
140 | + $modified_success_msg, |
|
141 | + $redirect_page = false, |
|
142 | + $debug = false |
|
143 | + ) { |
|
144 | + global $smart_previous_page; |
|
145 | + |
|
146 | + $this->postDataToObject($smartObj); |
|
147 | + |
|
148 | + if ($smartObj->isNew()) { |
|
149 | + $redirect_msg = $created_success_msg; |
|
150 | + } else { |
|
151 | + $redirect_msg = $modified_success_msg; |
|
152 | + } |
|
153 | + |
|
154 | + // Check if there were uploaded files |
|
155 | + if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) { |
|
156 | 156 | // require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartuploader.php'; |
157 | - $uploaderObj = new Uploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight); |
|
158 | - foreach ($_FILES as $name => $file_array) { |
|
159 | - if (isset($file_array['name']) && '' !== $file_array['name'] |
|
160 | - && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) { |
|
161 | - if ($uploaderObj->fetchMedia($name)) { |
|
162 | - $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName()); |
|
163 | - if ($uploaderObj->upload()) { |
|
164 | - // Find the related field in the SmartObject |
|
165 | - $related_field = str_replace('upload_', '', $name); |
|
166 | - $uploadedArray[] = $related_field; |
|
167 | - //si c'est un fichier Rich |
|
168 | - if (XOBJ_DTYPE_FILE === $smartObj->vars[$related_field]['data_type']) { |
|
169 | - $object_fileurl = $smartObj->getUploadDir(); |
|
170 | - $fileObj = $smartObj->getFileObj($related_field); |
|
171 | - $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName()); |
|
172 | - $fileObj->setVar('caption', $_POST['caption_' . $related_field]); |
|
173 | - $fileObj->setVar('description', $_POST['desc_' . $related_field]); |
|
174 | - $smartObj->storeFileObj($fileObj); |
|
175 | - //todo: catch errors |
|
176 | - $smartObj->setVar($related_field, $fileObj->getVar('fileid')); |
|
177 | - } else { |
|
178 | - $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field); |
|
179 | - unlink($old_file); |
|
180 | - $smartObj->setVar($related_field, $uploaderObj->getSavedFileName()); |
|
181 | - } |
|
182 | - } else { |
|
183 | - $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
184 | - } |
|
185 | - } else { |
|
186 | - $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
187 | - } |
|
188 | - } |
|
189 | - } |
|
190 | - } |
|
191 | - |
|
192 | - if ($debug) { |
|
193 | - $storeResult = $this->handler->insertD($smartObj); |
|
194 | - } else { |
|
195 | - $storeResult = $this->handler->insert($smartObj); |
|
196 | - } |
|
197 | - |
|
198 | - if ($storeResult) { |
|
199 | - if ($this->handler->getPermissions()) { |
|
200 | - $smartPermissionsHandler = new PermissionHandler($this->handler); |
|
201 | - $smartPermissionsHandler->storeAllPermissionsForId($smartObj->id()); |
|
202 | - } |
|
203 | - } |
|
204 | - |
|
205 | - if (null === $redirect_page) { |
|
206 | - return $smartObj; |
|
207 | - } else { |
|
208 | - if (!$storeResult) { |
|
209 | - redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors()); |
|
210 | - } |
|
211 | - |
|
212 | - $redirect_page = $redirect_page ?: Smartobject\Utility::getPageBeforeForm(); |
|
213 | - |
|
214 | - redirect_header($redirect_page, 2, $redirect_msg); |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Store the object in the database autmatically from a form sending POST data |
|
220 | - * |
|
221 | - * @param string $created_success_msg message to display if new object was created |
|
222 | - * @param string $modified_success_msg message to display if object was successfully edited |
|
223 | - * @param bool|string $redirect_page redirect page, if not set, then we backup once |
|
224 | - * @param bool $debug |
|
225 | - * @param bool $x_param |
|
226 | - * @return bool |
|
227 | - * @internal param string $created_redir_page redirect page after creating the object |
|
228 | - * @internal param string $modified_redir_page redirect page after editing the object |
|
229 | - * @internal param bool $exit if set to TRUE then the script ends |
|
230 | - */ |
|
231 | - public function storeFromDefaultForm( |
|
232 | - $created_success_msg, |
|
233 | - $modified_success_msg, |
|
234 | - $redirect_page = false, |
|
235 | - $debug = false, |
|
236 | - $x_param = false |
|
237 | - ) { |
|
238 | - $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0; |
|
239 | - if ($debug) { |
|
240 | - if ($x_param) { |
|
241 | - $smartObj = $this->handler->getD($objectid, true, $x_param); |
|
242 | - } else { |
|
243 | - $smartObj = $this->handler->getD($objectid); |
|
244 | - } |
|
245 | - } else { |
|
246 | - if ($x_param) { |
|
247 | - $smartObj = $this->handler->get($objectid, true, false, false, $x_param); |
|
248 | - } else { |
|
249 | - $smartObj = $this->handler->get($objectid); |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - // if handler is the Multilanguage handler, we will need to treat this for multilanguage |
|
254 | - if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) { |
|
255 | - if ($smartObj->isNew()) { |
|
256 | - // This is a new object. We need to store the meta data and then the language data |
|
257 | - // First, we will get rid of the multilanguage data to only store the meta data |
|
258 | - $smartObj->stripMultilanguageFields(); |
|
259 | - $newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
260 | - /** |
|
261 | - * @todo we need to trap potential errors here |
|
262 | - */ |
|
263 | - |
|
264 | - // ok, the meta daa is stored. Let's recreate the object and then |
|
265 | - // get rid of anything not multilanguage |
|
266 | - unset($smartObj); |
|
267 | - $smartObj = $this->handler->get($objectid); |
|
268 | - $smartObj->stripNonMultilanguageFields(); |
|
269 | - |
|
270 | - $smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName)); |
|
271 | - $this->handler->changeTableNameForML(); |
|
272 | - $ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
273 | - |
|
274 | - return $ret; |
|
275 | - } |
|
276 | - } else { |
|
277 | - return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
278 | - } |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * @return bool |
|
283 | - */ |
|
284 | - public function storeSmartObjectD() |
|
285 | - { |
|
286 | - return $this->storeSmartObject(true); |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * @param bool $debug |
|
291 | - * @param bool $xparam |
|
292 | - * @return bool |
|
293 | - */ |
|
294 | - public function storeSmartObject($debug = false, $xparam = false) |
|
295 | - { |
|
296 | - $ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam); |
|
297 | - |
|
298 | - return $ret; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * Handles deletion of an object which keyid is passed as a GET param |
|
303 | - * |
|
304 | - * @param bool $confirm_msg |
|
305 | - * @param string $op |
|
306 | - * @param bool $userSide |
|
307 | - * @return void |
|
308 | - * @internal param string $redir_page redirect page after deleting the object |
|
309 | - */ |
|
310 | - public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false) |
|
311 | - { |
|
312 | - global $smart_previous_page; |
|
313 | - |
|
314 | - $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
315 | - $smartObj = $this->handler->get($objectid); |
|
316 | - |
|
317 | - if ($smartObj->isNew()) { |
|
318 | - redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
319 | - } |
|
320 | - |
|
321 | - $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
|
322 | - if ($confirm) { |
|
323 | - if (!$this->handler->delete($smartObj)) { |
|
324 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
325 | - } |
|
326 | - |
|
327 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
328 | - } else { |
|
329 | - // no confirm: show deletion condition |
|
330 | - |
|
331 | - xoops_cp_header(); |
|
332 | - |
|
333 | - if (!$confirm_msg) { |
|
334 | - $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
335 | - } |
|
336 | - |
|
337 | - xoops_confirm([ |
|
338 | - 'op' => $op, |
|
339 | - $this->handler->keyName => $smartObj->getVar($this->handler->keyName), |
|
340 | - 'confirm' => 1, |
|
341 | - 'redirect_page' => $smart_previous_page |
|
342 | - ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
343 | - |
|
344 | - xoops_cp_footer(); |
|
345 | - } |
|
346 | - exit(); |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * @param bool $confirm_msg |
|
351 | - * @param string $op |
|
352 | - */ |
|
353 | - public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del') |
|
354 | - { |
|
355 | - global $smart_previous_page, $xoopsTpl; |
|
356 | - |
|
357 | - $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
358 | - $smartObj = $this->handler->get($objectid); |
|
359 | - |
|
360 | - if ($smartObj->isNew()) { |
|
361 | - redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
362 | - } |
|
363 | - |
|
364 | - $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
|
365 | - if ($confirm) { |
|
366 | - if (!$this->handler->delete($smartObj)) { |
|
367 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
368 | - } |
|
369 | - |
|
370 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
371 | - } else { |
|
372 | - // no confirm: show deletion condition |
|
373 | - if (!$confirm_msg) { |
|
374 | - $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
375 | - } |
|
376 | - |
|
377 | - ob_start(); |
|
378 | - xoops_confirm([ |
|
379 | - 'op' => $op, |
|
380 | - $this->handler->keyName => $smartObj->getVar($this->handler->keyName), |
|
381 | - 'confirm' => 1, |
|
382 | - 'redirect_page' => $smart_previous_page |
|
383 | - ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
384 | - $smartobjectDeleteConfirm = ob_get_clean(); |
|
385 | - $xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm); |
|
386 | - } |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Retreive the object admin side link for a {@link SmartObjectSingleView} page |
|
391 | - * |
|
392 | - * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
393 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
394 | - * @param bool $withimage |
|
395 | - * @return string admin side link to the object |
|
396 | - */ |
|
397 | - public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false) |
|
398 | - { |
|
399 | - $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
400 | - if ($onlyUrl) { |
|
401 | - return $ret; |
|
402 | - } elseif ($withimage) { |
|
403 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "viewmag.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_ADMIN_VIEW . "' title='" . _CO_SOBJECT_ADMIN_VIEW . "'></a>"; |
|
404 | - } |
|
405 | - |
|
406 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Retreive the object user side link |
|
411 | - * |
|
412 | - * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
413 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
414 | - * @return string user side link to the object |
|
415 | - */ |
|
416 | - public function getItemLink(SmartObject $smartObj, $onlyUrl = false) |
|
417 | - { |
|
418 | - $seoMode = Smartobject\Utility::getModuleModeSEO($this->handler->_moduleName); |
|
419 | - $seoModuleName = Smartobject\Utility::getModuleNameForSEO($this->handler->_moduleName); |
|
420 | - |
|
421 | - /** |
|
422 | - * $seoIncludeId feature is not finished yet, so let's put it always to true |
|
423 | - */ |
|
424 | - //$seoIncludeId = Smartobject\Utility::getModuleIncludeIdSEO($this->handler->_moduleName); |
|
425 | - $seoIncludeId = true; |
|
426 | - |
|
427 | - if ('rewrite' === $seoMode) { |
|
428 | - $ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
429 | - } elseif ('pathinfo' === $seoMode) { |
|
430 | - $ret = SMARTOBJECT_URL . 'seo.php/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
431 | - } else { |
|
432 | - $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
433 | - } |
|
434 | - |
|
435 | - if (!$onlyUrl) { |
|
436 | - $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
437 | - } |
|
438 | - |
|
439 | - return $ret; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * @param $smartObj |
|
444 | - * @param bool $onlyUrl |
|
445 | - * @param bool $withimage |
|
446 | - * @return string |
|
447 | - */ |
|
448 | - public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true) |
|
449 | - { |
|
450 | - $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language'); |
|
451 | - if ($onlyUrl) { |
|
452 | - return $ret; |
|
453 | - } elseif ($withimage) { |
|
454 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "wizard.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_LANGUAGE_MODIFY . "' title='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'></a>"; |
|
455 | - } |
|
456 | - |
|
457 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
458 | - } |
|
459 | - |
|
460 | - /** |
|
461 | - * @param $smartObj |
|
462 | - * @param bool $onlyUrl |
|
463 | - * @param bool $withimage |
|
464 | - * @param bool $userSide |
|
465 | - * @return string |
|
466 | - */ |
|
467 | - public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
468 | - { |
|
469 | - $admin_side = $userSide ? '' : 'admin/'; |
|
470 | - $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
471 | - if ($onlyUrl) { |
|
472 | - return $ret; |
|
473 | - } elseif ($withimage) { |
|
474 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "edit.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_MODIFY . "' title='" . _CO_SOBJECT_MODIFY . "'></a>"; |
|
475 | - } |
|
476 | - |
|
477 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * @param $smartObj |
|
482 | - * @param bool $onlyUrl |
|
483 | - * @param bool $withimage |
|
484 | - * @param bool $userSide |
|
485 | - * @return string |
|
486 | - */ |
|
487 | - public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
488 | - { |
|
489 | - $admin_side = $userSide ? '' : 'admin/'; |
|
490 | - $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
491 | - if ($onlyUrl) { |
|
492 | - return $ret; |
|
493 | - } elseif ($withimage) { |
|
494 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "editdelete.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_DELETE . "' title='" . _CO_SOBJECT_DELETE . "'></a>"; |
|
495 | - } |
|
496 | - |
|
497 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
498 | - } |
|
499 | - |
|
500 | - /** |
|
501 | - * @param $smartObj |
|
502 | - * @return string |
|
503 | - */ |
|
504 | - public function getPrintAndMailLink($smartObj) |
|
505 | - { |
|
506 | - global $xoopsConfig; |
|
507 | - |
|
508 | - $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
509 | - $js = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);"; |
|
510 | - $printlink = '<a href="' . $js . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"></a>'; |
|
511 | - |
|
512 | - $smartModule = Smartobject\Utility::getModuleInfo($smartObj->handler->_moduleName); |
|
513 | - $link = Smartobject\Utility::getCurrentPage(); |
|
514 | - $mid = $smartModule->getVar('mid'); |
|
515 | - $friendlink = "<a href=\"javascript:openWithSelfMain('" |
|
516 | - . SMARTOBJECT_URL |
|
517 | - . 'sendlink.php?link=' |
|
518 | - . $link |
|
519 | - . '&mid=' |
|
520 | - . $mid |
|
521 | - . "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" |
|
522 | - . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
523 | - . 'mail_send.png" alt="' |
|
524 | - . _CO_SOBJECT_EMAIL |
|
525 | - . '" title="' |
|
526 | - . _CO_SOBJECT_EMAIL |
|
527 | - . '" style="vertical-align: middle;"></a>'; |
|
528 | - |
|
529 | - $ret = '<span id="smartobject_print_button">' . $printlink . ' </span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>'; |
|
530 | - |
|
531 | - return $ret; |
|
532 | - } |
|
533 | - |
|
534 | - /** |
|
535 | - * @return string |
|
536 | - */ |
|
537 | - public function getModuleItemString() |
|
538 | - { |
|
539 | - $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname; |
|
540 | - |
|
541 | - return $ret; |
|
542 | - } |
|
157 | + $uploaderObj = new Uploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight); |
|
158 | + foreach ($_FILES as $name => $file_array) { |
|
159 | + if (isset($file_array['name']) && '' !== $file_array['name'] |
|
160 | + && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) { |
|
161 | + if ($uploaderObj->fetchMedia($name)) { |
|
162 | + $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName()); |
|
163 | + if ($uploaderObj->upload()) { |
|
164 | + // Find the related field in the SmartObject |
|
165 | + $related_field = str_replace('upload_', '', $name); |
|
166 | + $uploadedArray[] = $related_field; |
|
167 | + //si c'est un fichier Rich |
|
168 | + if (XOBJ_DTYPE_FILE === $smartObj->vars[$related_field]['data_type']) { |
|
169 | + $object_fileurl = $smartObj->getUploadDir(); |
|
170 | + $fileObj = $smartObj->getFileObj($related_field); |
|
171 | + $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName()); |
|
172 | + $fileObj->setVar('caption', $_POST['caption_' . $related_field]); |
|
173 | + $fileObj->setVar('description', $_POST['desc_' . $related_field]); |
|
174 | + $smartObj->storeFileObj($fileObj); |
|
175 | + //todo: catch errors |
|
176 | + $smartObj->setVar($related_field, $fileObj->getVar('fileid')); |
|
177 | + } else { |
|
178 | + $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field); |
|
179 | + unlink($old_file); |
|
180 | + $smartObj->setVar($related_field, $uploaderObj->getSavedFileName()); |
|
181 | + } |
|
182 | + } else { |
|
183 | + $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
184 | + } |
|
185 | + } else { |
|
186 | + $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
187 | + } |
|
188 | + } |
|
189 | + } |
|
190 | + } |
|
191 | + |
|
192 | + if ($debug) { |
|
193 | + $storeResult = $this->handler->insertD($smartObj); |
|
194 | + } else { |
|
195 | + $storeResult = $this->handler->insert($smartObj); |
|
196 | + } |
|
197 | + |
|
198 | + if ($storeResult) { |
|
199 | + if ($this->handler->getPermissions()) { |
|
200 | + $smartPermissionsHandler = new PermissionHandler($this->handler); |
|
201 | + $smartPermissionsHandler->storeAllPermissionsForId($smartObj->id()); |
|
202 | + } |
|
203 | + } |
|
204 | + |
|
205 | + if (null === $redirect_page) { |
|
206 | + return $smartObj; |
|
207 | + } else { |
|
208 | + if (!$storeResult) { |
|
209 | + redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors()); |
|
210 | + } |
|
211 | + |
|
212 | + $redirect_page = $redirect_page ?: Smartobject\Utility::getPageBeforeForm(); |
|
213 | + |
|
214 | + redirect_header($redirect_page, 2, $redirect_msg); |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Store the object in the database autmatically from a form sending POST data |
|
220 | + * |
|
221 | + * @param string $created_success_msg message to display if new object was created |
|
222 | + * @param string $modified_success_msg message to display if object was successfully edited |
|
223 | + * @param bool|string $redirect_page redirect page, if not set, then we backup once |
|
224 | + * @param bool $debug |
|
225 | + * @param bool $x_param |
|
226 | + * @return bool |
|
227 | + * @internal param string $created_redir_page redirect page after creating the object |
|
228 | + * @internal param string $modified_redir_page redirect page after editing the object |
|
229 | + * @internal param bool $exit if set to TRUE then the script ends |
|
230 | + */ |
|
231 | + public function storeFromDefaultForm( |
|
232 | + $created_success_msg, |
|
233 | + $modified_success_msg, |
|
234 | + $redirect_page = false, |
|
235 | + $debug = false, |
|
236 | + $x_param = false |
|
237 | + ) { |
|
238 | + $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0; |
|
239 | + if ($debug) { |
|
240 | + if ($x_param) { |
|
241 | + $smartObj = $this->handler->getD($objectid, true, $x_param); |
|
242 | + } else { |
|
243 | + $smartObj = $this->handler->getD($objectid); |
|
244 | + } |
|
245 | + } else { |
|
246 | + if ($x_param) { |
|
247 | + $smartObj = $this->handler->get($objectid, true, false, false, $x_param); |
|
248 | + } else { |
|
249 | + $smartObj = $this->handler->get($objectid); |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + // if handler is the Multilanguage handler, we will need to treat this for multilanguage |
|
254 | + if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) { |
|
255 | + if ($smartObj->isNew()) { |
|
256 | + // This is a new object. We need to store the meta data and then the language data |
|
257 | + // First, we will get rid of the multilanguage data to only store the meta data |
|
258 | + $smartObj->stripMultilanguageFields(); |
|
259 | + $newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
260 | + /** |
|
261 | + * @todo we need to trap potential errors here |
|
262 | + */ |
|
263 | + |
|
264 | + // ok, the meta daa is stored. Let's recreate the object and then |
|
265 | + // get rid of anything not multilanguage |
|
266 | + unset($smartObj); |
|
267 | + $smartObj = $this->handler->get($objectid); |
|
268 | + $smartObj->stripNonMultilanguageFields(); |
|
269 | + |
|
270 | + $smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName)); |
|
271 | + $this->handler->changeTableNameForML(); |
|
272 | + $ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
273 | + |
|
274 | + return $ret; |
|
275 | + } |
|
276 | + } else { |
|
277 | + return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
278 | + } |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * @return bool |
|
283 | + */ |
|
284 | + public function storeSmartObjectD() |
|
285 | + { |
|
286 | + return $this->storeSmartObject(true); |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * @param bool $debug |
|
291 | + * @param bool $xparam |
|
292 | + * @return bool |
|
293 | + */ |
|
294 | + public function storeSmartObject($debug = false, $xparam = false) |
|
295 | + { |
|
296 | + $ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam); |
|
297 | + |
|
298 | + return $ret; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * Handles deletion of an object which keyid is passed as a GET param |
|
303 | + * |
|
304 | + * @param bool $confirm_msg |
|
305 | + * @param string $op |
|
306 | + * @param bool $userSide |
|
307 | + * @return void |
|
308 | + * @internal param string $redir_page redirect page after deleting the object |
|
309 | + */ |
|
310 | + public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false) |
|
311 | + { |
|
312 | + global $smart_previous_page; |
|
313 | + |
|
314 | + $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
315 | + $smartObj = $this->handler->get($objectid); |
|
316 | + |
|
317 | + if ($smartObj->isNew()) { |
|
318 | + redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
319 | + } |
|
320 | + |
|
321 | + $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
|
322 | + if ($confirm) { |
|
323 | + if (!$this->handler->delete($smartObj)) { |
|
324 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
325 | + } |
|
326 | + |
|
327 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
328 | + } else { |
|
329 | + // no confirm: show deletion condition |
|
330 | + |
|
331 | + xoops_cp_header(); |
|
332 | + |
|
333 | + if (!$confirm_msg) { |
|
334 | + $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
335 | + } |
|
336 | + |
|
337 | + xoops_confirm([ |
|
338 | + 'op' => $op, |
|
339 | + $this->handler->keyName => $smartObj->getVar($this->handler->keyName), |
|
340 | + 'confirm' => 1, |
|
341 | + 'redirect_page' => $smart_previous_page |
|
342 | + ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
343 | + |
|
344 | + xoops_cp_footer(); |
|
345 | + } |
|
346 | + exit(); |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * @param bool $confirm_msg |
|
351 | + * @param string $op |
|
352 | + */ |
|
353 | + public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del') |
|
354 | + { |
|
355 | + global $smart_previous_page, $xoopsTpl; |
|
356 | + |
|
357 | + $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
358 | + $smartObj = $this->handler->get($objectid); |
|
359 | + |
|
360 | + if ($smartObj->isNew()) { |
|
361 | + redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
362 | + } |
|
363 | + |
|
364 | + $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
|
365 | + if ($confirm) { |
|
366 | + if (!$this->handler->delete($smartObj)) { |
|
367 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
368 | + } |
|
369 | + |
|
370 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
371 | + } else { |
|
372 | + // no confirm: show deletion condition |
|
373 | + if (!$confirm_msg) { |
|
374 | + $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
375 | + } |
|
376 | + |
|
377 | + ob_start(); |
|
378 | + xoops_confirm([ |
|
379 | + 'op' => $op, |
|
380 | + $this->handler->keyName => $smartObj->getVar($this->handler->keyName), |
|
381 | + 'confirm' => 1, |
|
382 | + 'redirect_page' => $smart_previous_page |
|
383 | + ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
384 | + $smartobjectDeleteConfirm = ob_get_clean(); |
|
385 | + $xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm); |
|
386 | + } |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Retreive the object admin side link for a {@link SmartObjectSingleView} page |
|
391 | + * |
|
392 | + * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
393 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
394 | + * @param bool $withimage |
|
395 | + * @return string admin side link to the object |
|
396 | + */ |
|
397 | + public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false) |
|
398 | + { |
|
399 | + $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
400 | + if ($onlyUrl) { |
|
401 | + return $ret; |
|
402 | + } elseif ($withimage) { |
|
403 | + return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "viewmag.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_ADMIN_VIEW . "' title='" . _CO_SOBJECT_ADMIN_VIEW . "'></a>"; |
|
404 | + } |
|
405 | + |
|
406 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Retreive the object user side link |
|
411 | + * |
|
412 | + * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
413 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
414 | + * @return string user side link to the object |
|
415 | + */ |
|
416 | + public function getItemLink(SmartObject $smartObj, $onlyUrl = false) |
|
417 | + { |
|
418 | + $seoMode = Smartobject\Utility::getModuleModeSEO($this->handler->_moduleName); |
|
419 | + $seoModuleName = Smartobject\Utility::getModuleNameForSEO($this->handler->_moduleName); |
|
420 | + |
|
421 | + /** |
|
422 | + * $seoIncludeId feature is not finished yet, so let's put it always to true |
|
423 | + */ |
|
424 | + //$seoIncludeId = Smartobject\Utility::getModuleIncludeIdSEO($this->handler->_moduleName); |
|
425 | + $seoIncludeId = true; |
|
426 | + |
|
427 | + if ('rewrite' === $seoMode) { |
|
428 | + $ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
429 | + } elseif ('pathinfo' === $seoMode) { |
|
430 | + $ret = SMARTOBJECT_URL . 'seo.php/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
431 | + } else { |
|
432 | + $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
433 | + } |
|
434 | + |
|
435 | + if (!$onlyUrl) { |
|
436 | + $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
437 | + } |
|
438 | + |
|
439 | + return $ret; |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * @param $smartObj |
|
444 | + * @param bool $onlyUrl |
|
445 | + * @param bool $withimage |
|
446 | + * @return string |
|
447 | + */ |
|
448 | + public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true) |
|
449 | + { |
|
450 | + $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language'); |
|
451 | + if ($onlyUrl) { |
|
452 | + return $ret; |
|
453 | + } elseif ($withimage) { |
|
454 | + return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "wizard.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_LANGUAGE_MODIFY . "' title='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'></a>"; |
|
455 | + } |
|
456 | + |
|
457 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
458 | + } |
|
459 | + |
|
460 | + /** |
|
461 | + * @param $smartObj |
|
462 | + * @param bool $onlyUrl |
|
463 | + * @param bool $withimage |
|
464 | + * @param bool $userSide |
|
465 | + * @return string |
|
466 | + */ |
|
467 | + public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
468 | + { |
|
469 | + $admin_side = $userSide ? '' : 'admin/'; |
|
470 | + $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
471 | + if ($onlyUrl) { |
|
472 | + return $ret; |
|
473 | + } elseif ($withimage) { |
|
474 | + return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "edit.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_MODIFY . "' title='" . _CO_SOBJECT_MODIFY . "'></a>"; |
|
475 | + } |
|
476 | + |
|
477 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * @param $smartObj |
|
482 | + * @param bool $onlyUrl |
|
483 | + * @param bool $withimage |
|
484 | + * @param bool $userSide |
|
485 | + * @return string |
|
486 | + */ |
|
487 | + public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
488 | + { |
|
489 | + $admin_side = $userSide ? '' : 'admin/'; |
|
490 | + $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
491 | + if ($onlyUrl) { |
|
492 | + return $ret; |
|
493 | + } elseif ($withimage) { |
|
494 | + return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "editdelete.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_DELETE . "' title='" . _CO_SOBJECT_DELETE . "'></a>"; |
|
495 | + } |
|
496 | + |
|
497 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
498 | + } |
|
499 | + |
|
500 | + /** |
|
501 | + * @param $smartObj |
|
502 | + * @return string |
|
503 | + */ |
|
504 | + public function getPrintAndMailLink($smartObj) |
|
505 | + { |
|
506 | + global $xoopsConfig; |
|
507 | + |
|
508 | + $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
509 | + $js = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);"; |
|
510 | + $printlink = '<a href="' . $js . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"></a>'; |
|
511 | + |
|
512 | + $smartModule = Smartobject\Utility::getModuleInfo($smartObj->handler->_moduleName); |
|
513 | + $link = Smartobject\Utility::getCurrentPage(); |
|
514 | + $mid = $smartModule->getVar('mid'); |
|
515 | + $friendlink = "<a href=\"javascript:openWithSelfMain('" |
|
516 | + . SMARTOBJECT_URL |
|
517 | + . 'sendlink.php?link=' |
|
518 | + . $link |
|
519 | + . '&mid=' |
|
520 | + . $mid |
|
521 | + . "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" |
|
522 | + . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
523 | + . 'mail_send.png" alt="' |
|
524 | + . _CO_SOBJECT_EMAIL |
|
525 | + . '" title="' |
|
526 | + . _CO_SOBJECT_EMAIL |
|
527 | + . '" style="vertical-align: middle;"></a>'; |
|
528 | + |
|
529 | + $ret = '<span id="smartobject_print_button">' . $printlink . ' </span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>'; |
|
530 | + |
|
531 | + return $ret; |
|
532 | + } |
|
533 | + |
|
534 | + /** |
|
535 | + * @return string |
|
536 | + */ |
|
537 | + public function getModuleItemString() |
|
538 | + { |
|
539 | + $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname; |
|
540 | + |
|
541 | + return $ret; |
|
542 | + } |
|
543 | 543 | } |
@@ -52,15 +52,15 @@ discard block |
||
52 | 52 | foreach (array_keys($smartObj->vars) as $key) { |
53 | 53 | switch ($smartObj->vars[$key]['data_type']) { |
54 | 54 | case XOBJ_DTYPE_IMAGE: |
55 | - if (isset($_POST['url_' . $key]) && '' !== $_POST['url_' . $key]) { |
|
56 | - $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
57 | - $smartObj->setVar($key, $_POST['url_' . $key]); |
|
55 | + if (isset($_POST['url_'.$key]) && '' !== $_POST['url_'.$key]) { |
|
56 | + $oldFile = $smartObj->getUploadDir(true).$smartObj->getVar($key, 'e'); |
|
57 | + $smartObj->setVar($key, $_POST['url_'.$key]); |
|
58 | 58 | if (file_exists($oldFile)) { |
59 | 59 | unlink($oldFile); |
60 | 60 | } |
61 | 61 | } |
62 | - if (isset($_POST['delete_' . $key]) && '1' == $_POST['delete_' . $key]) { |
|
63 | - $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
62 | + if (isset($_POST['delete_'.$key]) && '1' == $_POST['delete_'.$key]) { |
|
63 | + $oldFile = $smartObj->getUploadDir(true).$smartObj->getVar($key, 'e'); |
|
64 | 64 | $smartObj->setVar($key, ''); |
65 | 65 | if (file_exists($oldFile)) { |
66 | 66 | unlink($oldFile); |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | |
71 | 71 | case XOBJ_DTYPE_URLLINK: |
72 | 72 | $linkObj = $smartObj->getUrlLinkObj($key); |
73 | - $linkObj->setVar('caption', $_POST['caption_' . $key]); |
|
74 | - $linkObj->setVar('description', $_POST['desc_' . $key]); |
|
75 | - $linkObj->setVar('target', $_POST['target_' . $key]); |
|
76 | - $linkObj->setVar('url', $_POST['url_' . $key]); |
|
73 | + $linkObj->setVar('caption', $_POST['caption_'.$key]); |
|
74 | + $linkObj->setVar('description', $_POST['desc_'.$key]); |
|
75 | + $linkObj->setVar('target', $_POST['target_'.$key]); |
|
76 | + $linkObj->setVar('url', $_POST['url_'.$key]); |
|
77 | 77 | if ('' !== $linkObj->getVar('url')) { |
78 | 78 | $smartObj->storeUrlLinkObj($linkObj); |
79 | 79 | } |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | break; |
83 | 83 | |
84 | 84 | case XOBJ_DTYPE_FILE: |
85 | - if (!isset($_FILES['upload_' . $key]['name']) || '' === $_FILES['upload_' . $key]['name']) { |
|
85 | + if (!isset($_FILES['upload_'.$key]['name']) || '' === $_FILES['upload_'.$key]['name']) { |
|
86 | 86 | $fileObj = $smartObj->getFileObj($key); |
87 | - $fileObj->setVar('caption', $_POST['caption_' . $key]); |
|
88 | - $fileObj->setVar('description', $_POST['desc_' . $key]); |
|
89 | - $fileObj->setVar('url', $_POST['url_' . $key]); |
|
87 | + $fileObj->setVar('caption', $_POST['caption_'.$key]); |
|
88 | + $fileObj->setVar('description', $_POST['desc_'.$key]); |
|
89 | + $fileObj->setVar('url', $_POST['url_'.$key]); |
|
90 | 90 | if (!('' === $fileObj->getVar('url') && '' === $fileObj->getVar('url') |
91 | 91 | && '' === $fileObj->getVar('url'))) { |
92 | 92 | $res = $smartObj->storeFileObj($fileObj); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $value = strtotime($_POST[$key]); |
111 | 111 | //if strtotime returns false, the value is already a time stamp |
112 | 112 | if (!$value) { |
113 | - $value = (int)$_POST[$key]; |
|
113 | + $value = (int) $_POST[$key]; |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | $smartObj->setVar($key, $value); |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | if (isset($file_array['name']) && '' !== $file_array['name'] |
160 | 160 | && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) { |
161 | 161 | if ($uploaderObj->fetchMedia($name)) { |
162 | - $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName()); |
|
162 | + $uploaderObj->setTargetFileName(time().'_'.$uploaderObj->getMediaName()); |
|
163 | 163 | if ($uploaderObj->upload()) { |
164 | 164 | // Find the related field in the SmartObject |
165 | 165 | $related_field = str_replace('upload_', '', $name); |
@@ -168,14 +168,14 @@ discard block |
||
168 | 168 | if (XOBJ_DTYPE_FILE === $smartObj->vars[$related_field]['data_type']) { |
169 | 169 | $object_fileurl = $smartObj->getUploadDir(); |
170 | 170 | $fileObj = $smartObj->getFileObj($related_field); |
171 | - $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName()); |
|
172 | - $fileObj->setVar('caption', $_POST['caption_' . $related_field]); |
|
173 | - $fileObj->setVar('description', $_POST['desc_' . $related_field]); |
|
171 | + $fileObj->setVar('url', $object_fileurl.$uploaderObj->getSavedFileName()); |
|
172 | + $fileObj->setVar('caption', $_POST['caption_'.$related_field]); |
|
173 | + $fileObj->setVar('description', $_POST['desc_'.$related_field]); |
|
174 | 174 | $smartObj->storeFileObj($fileObj); |
175 | 175 | //todo: catch errors |
176 | 176 | $smartObj->setVar($related_field, $fileObj->getVar('fileid')); |
177 | 177 | } else { |
178 | - $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field); |
|
178 | + $old_file = $smartObj->getUploadDir(true).$smartObj->getVar($related_field); |
|
179 | 179 | unlink($old_file); |
180 | 180 | $smartObj->setVar($related_field, $uploaderObj->getSavedFileName()); |
181 | 181 | } |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | return $smartObj; |
207 | 207 | } else { |
208 | 208 | if (!$storeResult) { |
209 | - redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors()); |
|
209 | + redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR.$smartObj->getHtmlErrors()); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | $redirect_page = $redirect_page ?: Smartobject\Utility::getPageBeforeForm(); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $debug = false, |
236 | 236 | $x_param = false |
237 | 237 | ) { |
238 | - $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0; |
|
238 | + $objectid = isset($_POST[$this->handler->keyName]) ? (int) $_POST[$this->handler->keyName] : 0; |
|
239 | 239 | if ($debug) { |
240 | 240 | if ($x_param) { |
241 | 241 | $smartObj = $this->handler->getD($objectid, true, $x_param); |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | { |
312 | 312 | global $smart_previous_page; |
313 | 313 | |
314 | - $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
314 | + $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int) $_REQUEST[$this->handler->keyName] : 0; |
|
315 | 315 | $smartObj = $this->handler->get($objectid); |
316 | 316 | |
317 | 317 | if ($smartObj->isNew()) { |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
322 | 322 | if ($confirm) { |
323 | 323 | if (!$this->handler->delete($smartObj)) { |
324 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
324 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR.$smartObj->getHtmlErrors()); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | { |
355 | 355 | global $smart_previous_page, $xoopsTpl; |
356 | 356 | |
357 | - $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
357 | + $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int) $_REQUEST[$this->handler->keyName] : 0; |
|
358 | 358 | $smartObj = $this->handler->get($objectid); |
359 | 359 | |
360 | 360 | if ($smartObj->isNew()) { |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
365 | 365 | if ($confirm) { |
366 | 366 | if (!$this->handler->delete($smartObj)) { |
367 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
367 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR.$smartObj->getHtmlErrors()); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
@@ -396,14 +396,14 @@ discard block |
||
396 | 396 | */ |
397 | 397 | public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false) |
398 | 398 | { |
399 | - $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
399 | + $ret = $this->handler->_moduleUrl.'admin/'.$this->handler->_page.'?op=view&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName); |
|
400 | 400 | if ($onlyUrl) { |
401 | 401 | return $ret; |
402 | 402 | } elseif ($withimage) { |
403 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "viewmag.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_ADMIN_VIEW . "' title='" . _CO_SOBJECT_ADMIN_VIEW . "'></a>"; |
|
403 | + return "<a href='".$ret."'><img src='".SMARTOBJECT_IMAGES_ACTIONS_URL."viewmag.png' style='vertical-align: middle;' alt='"._CO_SOBJECT_ADMIN_VIEW."' title='"._CO_SOBJECT_ADMIN_VIEW."'></a>"; |
|
404 | 404 | } |
405 | 405 | |
406 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
406 | + return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>'; |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -425,15 +425,15 @@ discard block |
||
425 | 425 | $seoIncludeId = true; |
426 | 426 | |
427 | 427 | if ('rewrite' === $seoMode) { |
428 | - $ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
428 | + $ret = XOOPS_URL.'/'.$seoModuleName.'.'.$this->handler->_itemname.($seoIncludeId ? '.'.$smartObj->getVar($this->handler->keyName) : '').'/'.$smartObj->getVar('short_url').'.html'; |
|
429 | 429 | } elseif ('pathinfo' === $seoMode) { |
430 | - $ret = SMARTOBJECT_URL . 'seo.php/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html'; |
|
430 | + $ret = SMARTOBJECT_URL.'seo.php/'.$seoModuleName.'.'.$this->handler->_itemname.($seoIncludeId ? '.'.$smartObj->getVar($this->handler->keyName) : '').'/'.$smartObj->getVar('short_url').'.html'; |
|
431 | 431 | } else { |
432 | - $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
432 | + $ret = $this->handler->_moduleUrl.$this->handler->_page.'?'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | if (!$onlyUrl) { |
436 | - $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
436 | + $ret = "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>'; |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | return $ret; |
@@ -447,14 +447,14 @@ discard block |
||
447 | 447 | */ |
448 | 448 | public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true) |
449 | 449 | { |
450 | - $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language'); |
|
450 | + $ret = $this->handler->_moduleUrl.'admin/'.$this->handler->_page.'?op=mod&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName).'&language='.$smartObj->getVar('language'); |
|
451 | 451 | if ($onlyUrl) { |
452 | 452 | return $ret; |
453 | 453 | } elseif ($withimage) { |
454 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "wizard.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_LANGUAGE_MODIFY . "' title='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'></a>"; |
|
454 | + return "<a href='".$ret."'><img src='".SMARTOBJECT_IMAGES_ACTIONS_URL."wizard.png' style='vertical-align: middle;' alt='"._CO_SOBJECT_LANGUAGE_MODIFY."' title='"._CO_SOBJECT_LANGUAGE_MODIFY."'></a>"; |
|
455 | 455 | } |
456 | 456 | |
457 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
457 | + return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>'; |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
@@ -467,14 +467,14 @@ discard block |
||
467 | 467 | public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
468 | 468 | { |
469 | 469 | $admin_side = $userSide ? '' : 'admin/'; |
470 | - $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
470 | + $ret = $this->handler->_moduleUrl.$admin_side.$this->handler->_page.'?op=mod&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName); |
|
471 | 471 | if ($onlyUrl) { |
472 | 472 | return $ret; |
473 | 473 | } elseif ($withimage) { |
474 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "edit.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_MODIFY . "' title='" . _CO_SOBJECT_MODIFY . "'></a>"; |
|
474 | + return "<a href='".$ret."'><img src='".SMARTOBJECT_IMAGES_ACTIONS_URL."edit.png' style='vertical-align: middle;' alt='"._CO_SOBJECT_MODIFY."' title='"._CO_SOBJECT_MODIFY."'></a>"; |
|
475 | 475 | } |
476 | 476 | |
477 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
477 | + return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>'; |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | /** |
@@ -487,14 +487,14 @@ discard block |
||
487 | 487 | public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
488 | 488 | { |
489 | 489 | $admin_side = $userSide ? '' : 'admin/'; |
490 | - $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
490 | + $ret = $this->handler->_moduleUrl.$admin_side.$this->handler->_page.'?op=del&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName); |
|
491 | 491 | if ($onlyUrl) { |
492 | 492 | return $ret; |
493 | 493 | } elseif ($withimage) { |
494 | - return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "editdelete.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_DELETE . "' title='" . _CO_SOBJECT_DELETE . "'></a>"; |
|
494 | + return "<a href='".$ret."'><img src='".SMARTOBJECT_IMAGES_ACTIONS_URL."editdelete.png' style='vertical-align: middle;' alt='"._CO_SOBJECT_DELETE."' title='"._CO_SOBJECT_DELETE."'></a>"; |
|
495 | 495 | } |
496 | 496 | |
497 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
497 | + return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>'; |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | /** |
@@ -505,9 +505,9 @@ discard block |
||
505 | 505 | { |
506 | 506 | global $xoopsConfig; |
507 | 507 | |
508 | - $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
509 | - $js = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);"; |
|
510 | - $printlink = '<a href="' . $js . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"></a>'; |
|
508 | + $printlink = $this->handler->_moduleUrl.'print.php?'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName); |
|
509 | + $js = "javascript:openWithSelfMain('".$printlink."', 'smartpopup', 700, 519);"; |
|
510 | + $printlink = '<a href="'.$js.'"><img src="'.SMARTOBJECT_IMAGES_ACTIONS_URL.'fileprint.png" alt="" style="vertical-align: middle;"></a>'; |
|
511 | 511 | |
512 | 512 | $smartModule = Smartobject\Utility::getModuleInfo($smartObj->handler->_moduleName); |
513 | 513 | $link = Smartobject\Utility::getCurrentPage(); |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | . _CO_SOBJECT_EMAIL |
527 | 527 | . '" style="vertical-align: middle;"></a>'; |
528 | 528 | |
529 | - $ret = '<span id="smartobject_print_button">' . $printlink . ' </span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>'; |
|
529 | + $ret = '<span id="smartobject_print_button">'.$printlink.' </span>'.'<span id="smartobject_mail_button">'.$friendlink.'</span>'; |
|
530 | 530 | |
531 | 531 | return $ret; |
532 | 532 | } |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | */ |
537 | 537 | public function getModuleItemString() |
538 | 538 | { |
539 | - $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname; |
|
539 | + $ret = $this->handler->_moduleName.'_'.$this->handler->_itemname; |
|
540 | 540 | |
541 | 541 | return $ret; |
542 | 542 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Constructor |
35 | - * @param $object |
|
35 | + * @param BaseSmartObject $object |
|
36 | 36 | * @param bool $userSide |
37 | 37 | * @param array $actions |
38 | 38 | * @param bool $headerAsRow |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | - * @param $rowObj |
|
49 | + * @param ObjectRow $rowObj |
|
50 | 50 | */ |
51 | 51 | public function addRow($rowObj) |
52 | 52 | { |
@@ -23,94 +23,94 @@ |
||
23 | 23 | */ |
24 | 24 | class SingleView |
25 | 25 | { |
26 | - public $_object; |
|
27 | - public $_userSide; |
|
28 | - public $_tpl; |
|
29 | - public $_rows; |
|
30 | - public $_actions; |
|
31 | - public $_headerAsRow = true; |
|
26 | + public $_object; |
|
27 | + public $_userSide; |
|
28 | + public $_tpl; |
|
29 | + public $_rows; |
|
30 | + public $_actions; |
|
31 | + public $_headerAsRow = true; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor |
|
35 | - * @param $object |
|
36 | - * @param bool $userSide |
|
37 | - * @param array $actions |
|
38 | - * @param bool $headerAsRow |
|
39 | - */ |
|
40 | - public function __construct($object, $userSide = false, $actions = [], $headerAsRow = true) |
|
41 | - { |
|
42 | - $this->_object = $object; |
|
43 | - $this->_userSide = $userSide; |
|
44 | - $this->_actions = $actions; |
|
45 | - $this->_headerAsRow = $headerAsRow; |
|
46 | - } |
|
33 | + /** |
|
34 | + * Constructor |
|
35 | + * @param $object |
|
36 | + * @param bool $userSide |
|
37 | + * @param array $actions |
|
38 | + * @param bool $headerAsRow |
|
39 | + */ |
|
40 | + public function __construct($object, $userSide = false, $actions = [], $headerAsRow = true) |
|
41 | + { |
|
42 | + $this->_object = $object; |
|
43 | + $this->_userSide = $userSide; |
|
44 | + $this->_actions = $actions; |
|
45 | + $this->_headerAsRow = $headerAsRow; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param $rowObj |
|
50 | - */ |
|
51 | - public function addRow($rowObj) |
|
52 | - { |
|
53 | - $this->_rows[] = $rowObj; |
|
54 | - } |
|
48 | + /** |
|
49 | + * @param $rowObj |
|
50 | + */ |
|
51 | + public function addRow($rowObj) |
|
52 | + { |
|
53 | + $this->_rows[] = $rowObj; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param bool $fetchOnly |
|
58 | - * @param bool $debug |
|
59 | - * @return mixed|string|void |
|
60 | - */ |
|
61 | - public function render($fetchOnly = false, $debug = false) |
|
62 | - { |
|
63 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
56 | + /** |
|
57 | + * @param bool $fetchOnly |
|
58 | + * @param bool $debug |
|
59 | + * @return mixed|string|void |
|
60 | + */ |
|
61 | + public function render($fetchOnly = false, $debug = false) |
|
62 | + { |
|
63 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
64 | 64 | |
65 | - $this->_tpl = new \XoopsTpl(); |
|
66 | - $vars = $this->_object->vars; |
|
67 | - $smartobjectObjectArray = []; |
|
65 | + $this->_tpl = new \XoopsTpl(); |
|
66 | + $vars = $this->_object->vars; |
|
67 | + $smartobjectObjectArray = []; |
|
68 | 68 | |
69 | - foreach ($this->_rows as $row) { |
|
70 | - $key = $row->getKeyName(); |
|
71 | - if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) { |
|
72 | - $method = $row->_customMethodForValue; |
|
73 | - $value = $this->_object->$method(); |
|
74 | - } else { |
|
75 | - $value = $this->_object->getVar($row->getKeyName()); |
|
76 | - } |
|
77 | - if ($row->isHeader()) { |
|
78 | - $this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']); |
|
79 | - $this->_tpl->assign('smartobject_single_view_header_value', $value); |
|
80 | - } else { |
|
81 | - $smartobjectObjectArray[$key]['value'] = $value; |
|
82 | - $smartobjectObjectArray[$key]['header'] = $row->isHeader(); |
|
83 | - $smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption']; |
|
84 | - } |
|
85 | - } |
|
86 | - $action_row = ''; |
|
87 | - if (in_array('edit', $this->_actions)) { |
|
88 | - $action_row .= $this->_object->getEditItemLink(false, true, true); |
|
89 | - } |
|
90 | - if (in_array('delete', $this->_actions)) { |
|
91 | - $action_row .= $this->_object->getDeleteItemLink(false, true, true); |
|
92 | - } |
|
93 | - if ($action_row) { |
|
94 | - $smartobjectObjectArray['zaction']['value'] = $action_row; |
|
95 | - $smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS; |
|
96 | - } |
|
69 | + foreach ($this->_rows as $row) { |
|
70 | + $key = $row->getKeyName(); |
|
71 | + if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) { |
|
72 | + $method = $row->_customMethodForValue; |
|
73 | + $value = $this->_object->$method(); |
|
74 | + } else { |
|
75 | + $value = $this->_object->getVar($row->getKeyName()); |
|
76 | + } |
|
77 | + if ($row->isHeader()) { |
|
78 | + $this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']); |
|
79 | + $this->_tpl->assign('smartobject_single_view_header_value', $value); |
|
80 | + } else { |
|
81 | + $smartobjectObjectArray[$key]['value'] = $value; |
|
82 | + $smartobjectObjectArray[$key]['header'] = $row->isHeader(); |
|
83 | + $smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption']; |
|
84 | + } |
|
85 | + } |
|
86 | + $action_row = ''; |
|
87 | + if (in_array('edit', $this->_actions)) { |
|
88 | + $action_row .= $this->_object->getEditItemLink(false, true, true); |
|
89 | + } |
|
90 | + if (in_array('delete', $this->_actions)) { |
|
91 | + $action_row .= $this->_object->getDeleteItemLink(false, true, true); |
|
92 | + } |
|
93 | + if ($action_row) { |
|
94 | + $smartobjectObjectArray['zaction']['value'] = $action_row; |
|
95 | + $smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS; |
|
96 | + } |
|
97 | 97 | |
98 | - $this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow); |
|
99 | - $this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray); |
|
98 | + $this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow); |
|
99 | + $this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray); |
|
100 | 100 | |
101 | - if ($fetchOnly) { |
|
102 | - return $this->_tpl->fetch('db:smartobject_singleview_display.tpl'); |
|
103 | - } else { |
|
104 | - $this->_tpl->display('db:smartobject_singleview_display.tpl'); |
|
105 | - } |
|
106 | - } |
|
101 | + if ($fetchOnly) { |
|
102 | + return $this->_tpl->fetch('db:smartobject_singleview_display.tpl'); |
|
103 | + } else { |
|
104 | + $this->_tpl->display('db:smartobject_singleview_display.tpl'); |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * @param bool $debug |
|
110 | - * @return mixed|string|void |
|
111 | - */ |
|
112 | - public function fetch($debug = false) |
|
113 | - { |
|
114 | - return $this->render(true, $debug); |
|
115 | - } |
|
108 | + /** |
|
109 | + * @param bool $debug |
|
110 | + * @return mixed|string|void |
|
111 | + */ |
|
112 | + public function fetch($debug = false) |
|
113 | + { |
|
114 | + return $this->render(true, $debug); |
|
115 | + } |
|
116 | 116 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
104 | - * @param $columnObj |
|
104 | + * @param ObjectColumn $columnObj |
|
105 | 105 | */ |
106 | 106 | public function addColumn($columnObj) |
107 | 107 | { |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
112 | - * @param $name |
|
113 | - * @param $location |
|
112 | + * @param string $name |
|
113 | + * @param string $location |
|
114 | 114 | * @param $value |
115 | 115 | */ |
116 | 116 | public function addIntroButton($name, $location, $value) |
@@ -25,800 +25,800 @@ |
||
25 | 25 | */ |
26 | 26 | class Table |
27 | 27 | { |
28 | - public $_id; |
|
29 | - public $_objectHandler; |
|
30 | - public $_columns; |
|
31 | - public $_criteria; |
|
32 | - public $_actions; |
|
33 | - public $_objects = false; |
|
34 | - public $_aObjects; |
|
35 | - public $_custom_actions; |
|
36 | - public $_sortsel; |
|
37 | - public $_ordersel; |
|
38 | - public $_limitsel; |
|
39 | - public $_filtersel; |
|
40 | - public $_filterseloptions; |
|
41 | - public $_filtersel2; |
|
42 | - public $_filtersel2options; |
|
43 | - public $_filtersel2optionsDefault; |
|
44 | - |
|
45 | - public $_tempObject; |
|
46 | - public $_tpl; |
|
47 | - public $_introButtons; |
|
48 | - public $_quickSearch = false; |
|
49 | - public $_actionButtons = false; |
|
50 | - public $_head_css_class = 'bg3'; |
|
51 | - public $_hasActions = false; |
|
52 | - public $_userSide = false; |
|
53 | - public $_printerFriendlyPage = false; |
|
54 | - public $_tableHeader = false; |
|
55 | - public $_tableFooter = false; |
|
56 | - public $_showActionsColumnTitle = true; |
|
57 | - public $_isTree = false; |
|
58 | - public $_showFilterAndLimit = true; |
|
59 | - public $_enableColumnsSorting = true; |
|
60 | - public $_customTemplate = false; |
|
61 | - public $_withSelectedActions = []; |
|
62 | - |
|
63 | - /** |
|
64 | - * Constructor |
|
65 | - * |
|
66 | - * @param Smartobject\PersistableObjectHandler $objectHandler {@link Smartobject\SmartPersistableObjectHandler} |
|
67 | - * @param \CriteriaElement $criteria |
|
68 | - * @param array $actions array representing the actions to offer |
|
69 | - * |
|
70 | - * @param bool $userSide |
|
71 | - */ |
|
72 | - public function __construct(Smartobject\PersistableObjectHandler $objectHandler, \CriteriaElement $criteria = null, $actions = ['edit', 'delete'], $userSide = false) { |
|
73 | - $this->_id = $objectHandler->className; |
|
74 | - $this->_objectHandler = $objectHandler; |
|
75 | - |
|
76 | - if (!$criteria) { |
|
77 | - $criteria = new \CriteriaCompo(); |
|
78 | - } |
|
79 | - $this->_criteria = $criteria; |
|
80 | - $this->_actions = $actions; |
|
81 | - $this->_custom_actions = []; |
|
82 | - $this->_userSide = $userSide; |
|
83 | - if ($userSide) { |
|
84 | - $this->_head_css_class = 'head'; |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @param $op |
|
90 | - * @param bool $caption |
|
91 | - * @param bool $text |
|
92 | - */ |
|
93 | - public function addActionButton($op, $caption = false, $text = false) |
|
94 | - { |
|
95 | - $action = [ |
|
96 | - 'op' => $op, |
|
97 | - 'caption' => $caption, |
|
98 | - 'text' => $text |
|
99 | - ]; |
|
100 | - $this->_actionButtons[] = $action; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param $columnObj |
|
105 | - */ |
|
106 | - public function addColumn($columnObj) |
|
107 | - { |
|
108 | - $this->_columns[] = $columnObj; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @param $name |
|
113 | - * @param $location |
|
114 | - * @param $value |
|
115 | - */ |
|
116 | - public function addIntroButton($name, $location, $value) |
|
117 | - { |
|
118 | - $introButton = []; |
|
119 | - $introButton['name'] = $name; |
|
120 | - $introButton['location'] = $location; |
|
121 | - $introButton['value'] = $value; |
|
122 | - $this->_introButtons[] = $introButton; |
|
123 | - unset($introButton); |
|
124 | - } |
|
125 | - |
|
126 | - public function addPrinterFriendlyLink() |
|
127 | - { |
|
128 | - $current_urls = Smartobject\Utility::getCurrentUrls(); |
|
129 | - $current_url = $current_urls['full']; |
|
130 | - $this->_printerFriendlyPage = $current_url . '&print'; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * @param $fields |
|
135 | - * @param string $caption |
|
136 | - */ |
|
137 | - public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
138 | - { |
|
139 | - $this->_quickSearch = ['fields' => $fields, 'caption' => $caption]; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * @param $content |
|
144 | - */ |
|
145 | - public function addHeader($content) |
|
146 | - { |
|
147 | - $this->_tableHeader = $content; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @param $content |
|
152 | - */ |
|
153 | - public function addFooter($content) |
|
154 | - { |
|
155 | - $this->_tableFooter = $content; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @param $caption |
|
160 | - */ |
|
161 | - public function addDefaultIntroButton($caption) |
|
162 | - { |
|
163 | - $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param $method |
|
168 | - */ |
|
169 | - public function addCustomAction($method) |
|
170 | - { |
|
171 | - $this->_custom_actions[] = $method; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * @param $default_sort |
|
176 | - */ |
|
177 | - public function setDefaultSort($default_sort) |
|
178 | - { |
|
179 | - $this->_sortsel = $default_sort; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * @return string |
|
184 | - */ |
|
185 | - public function getDefaultSort() |
|
186 | - { |
|
187 | - if ($this->_sortsel) { |
|
188 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
189 | - } else { |
|
190 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @param $default_order |
|
196 | - */ |
|
197 | - public function setDefaultOrder($default_order) |
|
198 | - { |
|
199 | - $this->_ordersel = $default_order; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - public function getDefaultOrder() |
|
206 | - { |
|
207 | - if ($this->_ordersel) { |
|
208 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
209 | - } else { |
|
210 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * @param array $actions |
|
216 | - */ |
|
217 | - public function addWithSelectedActions($actions = []) |
|
218 | - { |
|
219 | - $this->addColumn(new ObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
220 | - $this->_withSelectedActions = $actions; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Adding a filter in the table |
|
225 | - * |
|
226 | - * @param string $key key to the field that will be used for sorting |
|
227 | - * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
228 | - * @param bool $default |
|
229 | - */ |
|
230 | - public function addFilter($key, $method, $default = false) |
|
231 | - { |
|
232 | - $this->_filterseloptions[$key] = $method; |
|
233 | - $this->_filtersel2optionsDefault = $default; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * @param $default_filter |
|
238 | - */ |
|
239 | - public function setDefaultFilter($default_filter) |
|
240 | - { |
|
241 | - $this->_filtersel = $default_filter; |
|
242 | - } |
|
243 | - |
|
244 | - public function isForUserSide() |
|
245 | - { |
|
246 | - $this->_userSide = true; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * @param $template |
|
251 | - */ |
|
252 | - public function setCustomTemplate($template) |
|
253 | - { |
|
254 | - $this->_customTemplate = $template; |
|
255 | - } |
|
256 | - |
|
257 | - public function setSortOrder() |
|
258 | - { |
|
259 | - $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
260 | - //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
261 | - Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
262 | - $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
263 | - |
|
264 | - if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
|
265 | - && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
266 | - $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
267 | - } else { |
|
268 | - $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
269 | - } |
|
270 | - |
|
271 | - $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
272 | - //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
273 | - Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
274 | - $ordersArray = $this->getOrdersArray(); |
|
275 | - $this->_criteria->setOrder($this->_ordersel); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * @param $id |
|
280 | - */ |
|
281 | - public function setTableId($id) |
|
282 | - { |
|
283 | - $this->_id = $id; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * @param $objects |
|
288 | - */ |
|
289 | - public function setObjects($objects) |
|
290 | - { |
|
291 | - $this->_objects = $objects; |
|
292 | - } |
|
293 | - |
|
294 | - public function createTableRows() |
|
295 | - { |
|
296 | - $this->_aObjects = []; |
|
297 | - |
|
298 | - $doWeHaveActions = false; |
|
299 | - |
|
300 | - $objectclass = 'odd'; |
|
301 | - if (count($this->_objects) > 0) { |
|
302 | - foreach ($this->_objects as $object) { |
|
303 | - $aObject = []; |
|
304 | - |
|
305 | - $i = 0; |
|
306 | - |
|
307 | - $aColumns = []; |
|
308 | - |
|
309 | - foreach ($this->_columns as $column) { |
|
310 | - $aColumn = []; |
|
311 | - |
|
312 | - if (0 == $i) { |
|
313 | - $class = 'head'; |
|
314 | - } elseif (0 == $i % 2) { |
|
315 | - $class = 'even'; |
|
316 | - } else { |
|
317 | - $class = 'odd'; |
|
318 | - } |
|
319 | - if (method_exists($object, 'initiateCustomFields')) { |
|
320 | - //$object->initiateCustomFields(); |
|
321 | - } |
|
322 | - if ('checked' === $column->_keyname) { |
|
323 | - $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
324 | - } elseif ($column->_customMethodForValue |
|
325 | - && method_exists($object, $column->_customMethodForValue)) { |
|
326 | - $method = $column->_customMethodForValue; |
|
327 | - if ($column->_param) { |
|
328 | - $value = $object->$method($column->_param); |
|
329 | - } else { |
|
330 | - $value = $object->$method(); |
|
331 | - } |
|
332 | - } else { |
|
333 | - /** |
|
334 | - * If the column is the identifier, then put a link on it |
|
335 | - */ |
|
336 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
337 | - $value = $object->getItemLink(); |
|
338 | - } else { |
|
339 | - $value = $object->getVar($column->getKeyName()); |
|
340 | - } |
|
341 | - } |
|
342 | - |
|
343 | - $aColumn['value'] = $value; |
|
344 | - $aColumn['class'] = $class; |
|
345 | - $aColumn['width'] = $column->getWidth(); |
|
346 | - $aColumn['align'] = $column->getAlign(); |
|
347 | - |
|
348 | - $aColumns[] = $aColumn; |
|
349 | - ++$i; |
|
350 | - } |
|
351 | - |
|
352 | - $aObject['columns'] = $aColumns; |
|
353 | - $aObject['id'] = $object->id(); |
|
354 | - |
|
355 | - $objectclass = ('even' === $objectclass) ? 'odd' : 'even'; |
|
356 | - |
|
357 | - $aObject['class'] = $objectclass; |
|
358 | - |
|
359 | - $actions = []; |
|
360 | - |
|
361 | - // Adding the custom actions if any |
|
362 | - foreach ($this->_custom_actions as $action) { |
|
363 | - if (method_exists($object, $action)) { |
|
364 | - $actions[] = $object->$action(); |
|
365 | - } |
|
366 | - } |
|
28 | + public $_id; |
|
29 | + public $_objectHandler; |
|
30 | + public $_columns; |
|
31 | + public $_criteria; |
|
32 | + public $_actions; |
|
33 | + public $_objects = false; |
|
34 | + public $_aObjects; |
|
35 | + public $_custom_actions; |
|
36 | + public $_sortsel; |
|
37 | + public $_ordersel; |
|
38 | + public $_limitsel; |
|
39 | + public $_filtersel; |
|
40 | + public $_filterseloptions; |
|
41 | + public $_filtersel2; |
|
42 | + public $_filtersel2options; |
|
43 | + public $_filtersel2optionsDefault; |
|
44 | + |
|
45 | + public $_tempObject; |
|
46 | + public $_tpl; |
|
47 | + public $_introButtons; |
|
48 | + public $_quickSearch = false; |
|
49 | + public $_actionButtons = false; |
|
50 | + public $_head_css_class = 'bg3'; |
|
51 | + public $_hasActions = false; |
|
52 | + public $_userSide = false; |
|
53 | + public $_printerFriendlyPage = false; |
|
54 | + public $_tableHeader = false; |
|
55 | + public $_tableFooter = false; |
|
56 | + public $_showActionsColumnTitle = true; |
|
57 | + public $_isTree = false; |
|
58 | + public $_showFilterAndLimit = true; |
|
59 | + public $_enableColumnsSorting = true; |
|
60 | + public $_customTemplate = false; |
|
61 | + public $_withSelectedActions = []; |
|
62 | + |
|
63 | + /** |
|
64 | + * Constructor |
|
65 | + * |
|
66 | + * @param Smartobject\PersistableObjectHandler $objectHandler {@link Smartobject\SmartPersistableObjectHandler} |
|
67 | + * @param \CriteriaElement $criteria |
|
68 | + * @param array $actions array representing the actions to offer |
|
69 | + * |
|
70 | + * @param bool $userSide |
|
71 | + */ |
|
72 | + public function __construct(Smartobject\PersistableObjectHandler $objectHandler, \CriteriaElement $criteria = null, $actions = ['edit', 'delete'], $userSide = false) { |
|
73 | + $this->_id = $objectHandler->className; |
|
74 | + $this->_objectHandler = $objectHandler; |
|
75 | + |
|
76 | + if (!$criteria) { |
|
77 | + $criteria = new \CriteriaCompo(); |
|
78 | + } |
|
79 | + $this->_criteria = $criteria; |
|
80 | + $this->_actions = $actions; |
|
81 | + $this->_custom_actions = []; |
|
82 | + $this->_userSide = $userSide; |
|
83 | + if ($userSide) { |
|
84 | + $this->_head_css_class = 'head'; |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @param $op |
|
90 | + * @param bool $caption |
|
91 | + * @param bool $text |
|
92 | + */ |
|
93 | + public function addActionButton($op, $caption = false, $text = false) |
|
94 | + { |
|
95 | + $action = [ |
|
96 | + 'op' => $op, |
|
97 | + 'caption' => $caption, |
|
98 | + 'text' => $text |
|
99 | + ]; |
|
100 | + $this->_actionButtons[] = $action; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param $columnObj |
|
105 | + */ |
|
106 | + public function addColumn($columnObj) |
|
107 | + { |
|
108 | + $this->_columns[] = $columnObj; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @param $name |
|
113 | + * @param $location |
|
114 | + * @param $value |
|
115 | + */ |
|
116 | + public function addIntroButton($name, $location, $value) |
|
117 | + { |
|
118 | + $introButton = []; |
|
119 | + $introButton['name'] = $name; |
|
120 | + $introButton['location'] = $location; |
|
121 | + $introButton['value'] = $value; |
|
122 | + $this->_introButtons[] = $introButton; |
|
123 | + unset($introButton); |
|
124 | + } |
|
125 | + |
|
126 | + public function addPrinterFriendlyLink() |
|
127 | + { |
|
128 | + $current_urls = Smartobject\Utility::getCurrentUrls(); |
|
129 | + $current_url = $current_urls['full']; |
|
130 | + $this->_printerFriendlyPage = $current_url . '&print'; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * @param $fields |
|
135 | + * @param string $caption |
|
136 | + */ |
|
137 | + public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
138 | + { |
|
139 | + $this->_quickSearch = ['fields' => $fields, 'caption' => $caption]; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * @param $content |
|
144 | + */ |
|
145 | + public function addHeader($content) |
|
146 | + { |
|
147 | + $this->_tableHeader = $content; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @param $content |
|
152 | + */ |
|
153 | + public function addFooter($content) |
|
154 | + { |
|
155 | + $this->_tableFooter = $content; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @param $caption |
|
160 | + */ |
|
161 | + public function addDefaultIntroButton($caption) |
|
162 | + { |
|
163 | + $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @param $method |
|
168 | + */ |
|
169 | + public function addCustomAction($method) |
|
170 | + { |
|
171 | + $this->_custom_actions[] = $method; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * @param $default_sort |
|
176 | + */ |
|
177 | + public function setDefaultSort($default_sort) |
|
178 | + { |
|
179 | + $this->_sortsel = $default_sort; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * @return string |
|
184 | + */ |
|
185 | + public function getDefaultSort() |
|
186 | + { |
|
187 | + if ($this->_sortsel) { |
|
188 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
189 | + } else { |
|
190 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * @param $default_order |
|
196 | + */ |
|
197 | + public function setDefaultOrder($default_order) |
|
198 | + { |
|
199 | + $this->_ordersel = $default_order; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + public function getDefaultOrder() |
|
206 | + { |
|
207 | + if ($this->_ordersel) { |
|
208 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
209 | + } else { |
|
210 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * @param array $actions |
|
216 | + */ |
|
217 | + public function addWithSelectedActions($actions = []) |
|
218 | + { |
|
219 | + $this->addColumn(new ObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
220 | + $this->_withSelectedActions = $actions; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Adding a filter in the table |
|
225 | + * |
|
226 | + * @param string $key key to the field that will be used for sorting |
|
227 | + * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
228 | + * @param bool $default |
|
229 | + */ |
|
230 | + public function addFilter($key, $method, $default = false) |
|
231 | + { |
|
232 | + $this->_filterseloptions[$key] = $method; |
|
233 | + $this->_filtersel2optionsDefault = $default; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * @param $default_filter |
|
238 | + */ |
|
239 | + public function setDefaultFilter($default_filter) |
|
240 | + { |
|
241 | + $this->_filtersel = $default_filter; |
|
242 | + } |
|
243 | + |
|
244 | + public function isForUserSide() |
|
245 | + { |
|
246 | + $this->_userSide = true; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * @param $template |
|
251 | + */ |
|
252 | + public function setCustomTemplate($template) |
|
253 | + { |
|
254 | + $this->_customTemplate = $template; |
|
255 | + } |
|
256 | + |
|
257 | + public function setSortOrder() |
|
258 | + { |
|
259 | + $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
260 | + //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
261 | + Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
262 | + $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
263 | + |
|
264 | + if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
|
265 | + && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
266 | + $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
267 | + } else { |
|
268 | + $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
269 | + } |
|
270 | + |
|
271 | + $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
272 | + //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
273 | + Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
274 | + $ordersArray = $this->getOrdersArray(); |
|
275 | + $this->_criteria->setOrder($this->_ordersel); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * @param $id |
|
280 | + */ |
|
281 | + public function setTableId($id) |
|
282 | + { |
|
283 | + $this->_id = $id; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * @param $objects |
|
288 | + */ |
|
289 | + public function setObjects($objects) |
|
290 | + { |
|
291 | + $this->_objects = $objects; |
|
292 | + } |
|
293 | + |
|
294 | + public function createTableRows() |
|
295 | + { |
|
296 | + $this->_aObjects = []; |
|
297 | + |
|
298 | + $doWeHaveActions = false; |
|
299 | + |
|
300 | + $objectclass = 'odd'; |
|
301 | + if (count($this->_objects) > 0) { |
|
302 | + foreach ($this->_objects as $object) { |
|
303 | + $aObject = []; |
|
304 | + |
|
305 | + $i = 0; |
|
306 | + |
|
307 | + $aColumns = []; |
|
308 | + |
|
309 | + foreach ($this->_columns as $column) { |
|
310 | + $aColumn = []; |
|
311 | + |
|
312 | + if (0 == $i) { |
|
313 | + $class = 'head'; |
|
314 | + } elseif (0 == $i % 2) { |
|
315 | + $class = 'even'; |
|
316 | + } else { |
|
317 | + $class = 'odd'; |
|
318 | + } |
|
319 | + if (method_exists($object, 'initiateCustomFields')) { |
|
320 | + //$object->initiateCustomFields(); |
|
321 | + } |
|
322 | + if ('checked' === $column->_keyname) { |
|
323 | + $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
324 | + } elseif ($column->_customMethodForValue |
|
325 | + && method_exists($object, $column->_customMethodForValue)) { |
|
326 | + $method = $column->_customMethodForValue; |
|
327 | + if ($column->_param) { |
|
328 | + $value = $object->$method($column->_param); |
|
329 | + } else { |
|
330 | + $value = $object->$method(); |
|
331 | + } |
|
332 | + } else { |
|
333 | + /** |
|
334 | + * If the column is the identifier, then put a link on it |
|
335 | + */ |
|
336 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
337 | + $value = $object->getItemLink(); |
|
338 | + } else { |
|
339 | + $value = $object->getVar($column->getKeyName()); |
|
340 | + } |
|
341 | + } |
|
342 | + |
|
343 | + $aColumn['value'] = $value; |
|
344 | + $aColumn['class'] = $class; |
|
345 | + $aColumn['width'] = $column->getWidth(); |
|
346 | + $aColumn['align'] = $column->getAlign(); |
|
347 | + |
|
348 | + $aColumns[] = $aColumn; |
|
349 | + ++$i; |
|
350 | + } |
|
351 | + |
|
352 | + $aObject['columns'] = $aColumns; |
|
353 | + $aObject['id'] = $object->id(); |
|
354 | + |
|
355 | + $objectclass = ('even' === $objectclass) ? 'odd' : 'even'; |
|
356 | + |
|
357 | + $aObject['class'] = $objectclass; |
|
358 | + |
|
359 | + $actions = []; |
|
360 | + |
|
361 | + // Adding the custom actions if any |
|
362 | + foreach ($this->_custom_actions as $action) { |
|
363 | + if (method_exists($object, $action)) { |
|
364 | + $actions[] = $object->$action(); |
|
365 | + } |
|
366 | + } |
|
367 | 367 | |
368 | 368 | // require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
369 | - $controller = new ObjectController($this->_objectHandler); |
|
370 | - |
|
371 | - if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
372 | - $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
373 | - } |
|
374 | - if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
375 | - $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
376 | - } |
|
377 | - $aObject['actions'] = $actions; |
|
378 | - |
|
379 | - $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
380 | - |
|
381 | - $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
382 | - |
|
383 | - $this->_aObjects[] = $aObject; |
|
384 | - } |
|
385 | - $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
386 | - } else { |
|
387 | - $colspan = count($this->_columns) + 1; |
|
388 | - $this->_tpl->assign('smartobject_colspan', $colspan); |
|
389 | - } |
|
390 | - $this->_hasActions = $doWeHaveActions; |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * @param bool $debug |
|
395 | - * @return mixed |
|
396 | - */ |
|
397 | - public function fetchObjects($debug = false) |
|
398 | - { |
|
399 | - return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * @return string |
|
404 | - */ |
|
405 | - public function getDefaultFilter() |
|
406 | - { |
|
407 | - if ($this->_filtersel) { |
|
408 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
409 | - } else { |
|
410 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
411 | - } |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * @return array|bool |
|
416 | - */ |
|
417 | - public function getFiltersArray() |
|
418 | - { |
|
419 | - $ret = []; |
|
420 | - $field = []; |
|
421 | - $field['caption'] = _CO_OBJ_NONE; |
|
422 | - $field['selected'] = ''; |
|
423 | - $ret['default'] = $field; |
|
424 | - unset($field); |
|
425 | - |
|
426 | - if ($this->_filterseloptions) { |
|
427 | - foreach ($this->_filterseloptions as $key => $value) { |
|
428 | - $field = []; |
|
429 | - if (is_array($value)) { |
|
430 | - $field['caption'] = $key; |
|
431 | - $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
432 | - } else { |
|
433 | - $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
434 | - $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
435 | - } |
|
436 | - $ret[$key] = $field; |
|
437 | - unset($field); |
|
438 | - } |
|
439 | - } else { |
|
440 | - $ret = false; |
|
441 | - } |
|
442 | - |
|
443 | - return $ret; |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * @param $default_filter2 |
|
448 | - */ |
|
449 | - public function setDefaultFilter2($default_filter2) |
|
450 | - { |
|
451 | - $this->_filtersel2 = $default_filter2; |
|
452 | - } |
|
453 | - |
|
454 | - /** |
|
455 | - * @return string |
|
456 | - */ |
|
457 | - public function getDefaultFilter2() |
|
458 | - { |
|
459 | - if ($this->_filtersel2) { |
|
460 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
461 | - } else { |
|
462 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
463 | - } |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * @return array |
|
468 | - */ |
|
469 | - public function getFilters2Array() |
|
470 | - { |
|
471 | - $ret = []; |
|
472 | - |
|
473 | - foreach ($this->_filtersel2options as $key => $value) { |
|
474 | - $field = []; |
|
475 | - $field['caption'] = $value; |
|
476 | - $field['selected'] = $this->_filtersel2 == $key ? 'selected' : ''; |
|
477 | - $ret[$key] = $field; |
|
478 | - unset($field); |
|
479 | - } |
|
480 | - |
|
481 | - return $ret; |
|
482 | - } |
|
483 | - |
|
484 | - /** |
|
485 | - * @param $limitsArray |
|
486 | - * @param $params_of_the_options_sel |
|
487 | - */ |
|
488 | - public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
489 | - { |
|
490 | - // Rendering the form to select options on the table |
|
491 | - $current_urls = Smartobject\Utility::getCurrentUrls(); |
|
492 | - $current_url = $current_urls['full']; |
|
493 | - |
|
494 | - /** |
|
495 | - * What was $params_of_the_options_sel doing again ? |
|
496 | - */ |
|
497 | - //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
498 | - $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
499 | - $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * @return array |
|
504 | - */ |
|
505 | - public function getLimitsArray() |
|
506 | - { |
|
507 | - $ret = []; |
|
508 | - $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
509 | - $ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : ''; |
|
510 | - |
|
511 | - $ret['5']['caption'] = '5'; |
|
512 | - $ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : ''; |
|
513 | - |
|
514 | - $ret['10']['caption'] = '10'; |
|
515 | - $ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : ''; |
|
516 | - |
|
517 | - $ret['15']['caption'] = '15'; |
|
518 | - $ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : ''; |
|
519 | - |
|
520 | - $ret['20']['caption'] = '20'; |
|
521 | - $ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : ''; |
|
522 | - |
|
523 | - $ret['25']['caption'] = '25'; |
|
524 | - $ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : ''; |
|
525 | - |
|
526 | - $ret['30']['caption'] = '30'; |
|
527 | - $ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : ''; |
|
528 | - |
|
529 | - $ret['35']['caption'] = '35'; |
|
530 | - $ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : ''; |
|
531 | - |
|
532 | - $ret['40']['caption'] = '40'; |
|
533 | - $ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : ''; |
|
534 | - |
|
535 | - return $ret; |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * @return bool |
|
540 | - */ |
|
541 | - public function getObjects() |
|
542 | - { |
|
543 | - return $this->_objects; |
|
544 | - } |
|
545 | - |
|
546 | - public function hideActionColumnTitle() |
|
547 | - { |
|
548 | - $this->_showActionsColumnTitle = false; |
|
549 | - } |
|
550 | - |
|
551 | - public function hideFilterAndLimit() |
|
552 | - { |
|
553 | - $this->_showFilterAndLimit = false; |
|
554 | - } |
|
555 | - |
|
556 | - /** |
|
557 | - * @return array |
|
558 | - */ |
|
559 | - public function getOrdersArray() |
|
560 | - { |
|
561 | - $ret = []; |
|
562 | - $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
563 | - $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : ''; |
|
564 | - |
|
565 | - $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
566 | - $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : ''; |
|
567 | - |
|
568 | - return $ret; |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * @return mixed|string|void |
|
573 | - */ |
|
574 | - public function renderD() |
|
575 | - { |
|
576 | - return $this->render(false, true); |
|
577 | - } |
|
578 | - |
|
579 | - public function renderForPrint() |
|
580 | - { |
|
581 | - } |
|
582 | - |
|
583 | - /** |
|
584 | - * @param bool $fetchOnly |
|
585 | - * @param bool $debug |
|
586 | - * @return mixed|string|void |
|
587 | - */ |
|
588 | - public function render($fetchOnly = false, $debug = false) |
|
589 | - { |
|
590 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
591 | - |
|
592 | - $this->_tpl = new \XoopsTpl(); |
|
593 | - |
|
594 | - /** |
|
595 | - * We need access to the vars of the SmartObject for a few things in the table creation. |
|
596 | - * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
597 | - * and we will free it after |
|
598 | - */ |
|
599 | - $this->_tempObject = $this->_objectHandler->create(); |
|
600 | - |
|
601 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
602 | - |
|
603 | - $this->setSortOrder(); |
|
604 | - |
|
605 | - if (!$this->_isTree) { |
|
606 | - $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
607 | - } else { |
|
608 | - $this->_limitsel = 'all'; |
|
609 | - } |
|
610 | - |
|
611 | - $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
612 | - Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
613 | - $limitsArray = $this->getLimitsArray(); |
|
614 | - $this->_criteria->setLimit($this->_limitsel); |
|
615 | - |
|
616 | - $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
617 | - $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
618 | - Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
619 | - $filtersArray = $this->getFiltersArray(); |
|
620 | - |
|
621 | - if ($filtersArray) { |
|
622 | - $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
623 | - } |
|
624 | - |
|
625 | - // Check if the selected filter is defined and if so, create the selfilter2 |
|
626 | - if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
627 | - // check if method associate with this filter exists in the handler |
|
628 | - if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
629 | - $filter = $this->_filterseloptions[$this->_filtersel]; |
|
630 | - $this->_criteria->add($filter['criteria']); |
|
631 | - } else { |
|
632 | - if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
633 | - |
|
634 | - // then we will create the selfilter2 options by calling this method |
|
635 | - $method = $this->_filterseloptions[$this->_filtersel]; |
|
636 | - $this->_filtersel2options = $this->_objectHandler->$method(); |
|
637 | - |
|
638 | - $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
639 | - $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
640 | - |
|
641 | - $filters2Array = $this->getFilters2Array(); |
|
642 | - $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
643 | - |
|
644 | - Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
645 | - if ('default' !== $this->_filtersel2) { |
|
646 | - $this->_criteria->add(new \Criteria($this->_filtersel, $this->_filtersel2)); |
|
647 | - } |
|
648 | - } |
|
649 | - } |
|
650 | - } |
|
651 | - // Check if we have a quicksearch |
|
652 | - |
|
653 | - if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) { |
|
654 | - $quicksearch_criteria = new \CriteriaCompo(); |
|
655 | - if (is_array($this->_quickSearch['fields'])) { |
|
656 | - foreach ($this->_quickSearch['fields'] as $v) { |
|
657 | - $quicksearch_criteria->add(new \Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
658 | - } |
|
659 | - } else { |
|
660 | - $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
661 | - } |
|
662 | - $this->_criteria->add($quicksearch_criteria); |
|
663 | - } |
|
664 | - |
|
665 | - $this->_objects = $this->fetchObjects($debug); |
|
666 | - |
|
667 | - require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
668 | - if ($this->_criteria->getLimit() > 0) { |
|
669 | - |
|
670 | - /** |
|
671 | - * Geeting rid of the old params |
|
672 | - * $new_get_array is an array containing the new GET parameters |
|
673 | - */ |
|
674 | - $new_get_array = []; |
|
675 | - |
|
676 | - /** |
|
677 | - * $params_of_the_options_sel is an array with all the parameters of the page |
|
678 | - * but without the pagenave parameters. This array will be used in the |
|
679 | - * OptionsSelection |
|
680 | - */ |
|
681 | - $params_of_the_options_sel = []; |
|
682 | - |
|
683 | - $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName]; |
|
684 | - foreach ($_GET as $k => $v) { |
|
685 | - if (!in_array($k, $not_needed_params)) { |
|
686 | - $new_get_array[] = "$k=$v"; |
|
687 | - $params_of_the_options_sel[] = "$k=$v"; |
|
688 | - } |
|
689 | - } |
|
690 | - |
|
691 | - /** |
|
692 | - * Adding the new params of the pagenav |
|
693 | - */ |
|
694 | - $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
695 | - $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
696 | - $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
697 | - $otherParams = implode('&', $new_get_array); |
|
698 | - |
|
699 | - $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
700 | - $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
701 | - } |
|
702 | - $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
703 | - |
|
704 | - // retreive the current url and the query string |
|
705 | - $current_urls = Smartobject\Utility::getCurrentUrls(); |
|
706 | - $current_url = $current_urls['full_phpself']; |
|
707 | - $query_string = $current_urls['querystring']; |
|
708 | - if ($query_string) { |
|
709 | - $query_string = str_replace('?', '', $query_string); |
|
710 | - } |
|
711 | - $query_stringArray = explode('&', $query_string); |
|
712 | - $new_query_stringArray = []; |
|
713 | - foreach ($query_stringArray as $query_string) { |
|
714 | - if (false === strpos($query_string, 'sortsel') && false === strpos($query_string, 'ordersel')) { |
|
715 | - $new_query_stringArray[] = $query_string; |
|
716 | - } |
|
717 | - } |
|
718 | - $new_query_string = implode('&', $new_query_stringArray); |
|
719 | - |
|
720 | - $orderArray = []; |
|
721 | - $orderArray['ASC']['image'] = 'desc.png'; |
|
722 | - $orderArray['ASC']['neworder'] = 'DESC'; |
|
723 | - $orderArray['DESC']['image'] = 'asc.png'; |
|
724 | - $orderArray['DESC']['neworder'] = 'ASC'; |
|
725 | - |
|
726 | - $aColumns = []; |
|
727 | - |
|
728 | - foreach ($this->_columns as $column) { |
|
729 | - $qs_param = ''; |
|
730 | - $aColumn = []; |
|
731 | - $aColumn['width'] = $column->getWidth(); |
|
732 | - $aColumn['align'] = $column->getAlign(); |
|
733 | - $aColumn['key'] = $column->getKeyName(); |
|
734 | - if ('checked' === $column->_keyname) { |
|
735 | - $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
736 | - } elseif ($column->getCustomCaption()) { |
|
737 | - $aColumn['caption'] = $column->getCustomCaption(); |
|
738 | - } else { |
|
739 | - $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
740 | - } |
|
741 | - // Are we doing a GET sort on this column ? |
|
742 | - $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
743 | - && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
744 | - || ($this->_sortsel == $column->getKeyName()); |
|
745 | - $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
746 | - |
|
747 | - if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) { |
|
748 | - $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
749 | - } |
|
750 | - if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) { |
|
751 | - $aColumn['caption'] = $aColumn['caption']; |
|
752 | - } elseif ($getSort) { |
|
753 | - $aColumn['caption'] = '<a href="' |
|
754 | - . $current_url |
|
755 | - . '?' |
|
756 | - . $this->_objectHandler->_itemname |
|
757 | - . '_' |
|
758 | - . 'sortsel=' |
|
759 | - . $column->getKeyName() |
|
760 | - . '&' |
|
761 | - . $this->_objectHandler->_itemname |
|
762 | - . '_' |
|
763 | - . 'ordersel=' |
|
764 | - . $orderArray[$order]['neworder'] |
|
765 | - . $qs_param |
|
766 | - . '&' |
|
767 | - . $new_query_string |
|
768 | - . '">' |
|
769 | - . $aColumn['caption'] |
|
770 | - . ' <img src="' |
|
771 | - . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
772 | - . $orderArray[$order]['image'] |
|
773 | - . '" alt="ASC"></a>'; |
|
774 | - } else { |
|
775 | - $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
776 | - } |
|
777 | - $aColumns[] = $aColumn; |
|
778 | - } |
|
779 | - $this->_tpl->assign('smartobject_columns', $aColumns); |
|
780 | - |
|
781 | - if ($this->_quickSearch) { |
|
782 | - $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
783 | - } |
|
784 | - |
|
785 | - $this->createTableRows(); |
|
786 | - |
|
787 | - $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
788 | - $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
789 | - $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
790 | - $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
791 | - $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
792 | - $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
793 | - $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
794 | - $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
795 | - $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
796 | - $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
797 | - $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
798 | - $this->_tpl->assign('smartobject_id', $this->_id); |
|
799 | - if (!empty($this->_withSelectedActions)) { |
|
800 | - $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
801 | - } |
|
802 | - |
|
803 | - $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
804 | - if ($fetchOnly) { |
|
805 | - return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
806 | - } else { |
|
807 | - $this->_tpl->display('db:' . $smartobjectTable_template); |
|
808 | - } |
|
809 | - } |
|
810 | - |
|
811 | - public function disableColumnsSorting() |
|
812 | - { |
|
813 | - $this->_enableColumnsSorting = false; |
|
814 | - } |
|
815 | - |
|
816 | - /** |
|
817 | - * @param bool $debug |
|
818 | - * @return mixed|string|void |
|
819 | - */ |
|
820 | - public function fetch($debug = false) |
|
821 | - { |
|
822 | - return $this->render(true, $debug); |
|
823 | - } |
|
369 | + $controller = new ObjectController($this->_objectHandler); |
|
370 | + |
|
371 | + if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
372 | + $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
373 | + } |
|
374 | + if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
375 | + $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
376 | + } |
|
377 | + $aObject['actions'] = $actions; |
|
378 | + |
|
379 | + $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
380 | + |
|
381 | + $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
382 | + |
|
383 | + $this->_aObjects[] = $aObject; |
|
384 | + } |
|
385 | + $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
386 | + } else { |
|
387 | + $colspan = count($this->_columns) + 1; |
|
388 | + $this->_tpl->assign('smartobject_colspan', $colspan); |
|
389 | + } |
|
390 | + $this->_hasActions = $doWeHaveActions; |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * @param bool $debug |
|
395 | + * @return mixed |
|
396 | + */ |
|
397 | + public function fetchObjects($debug = false) |
|
398 | + { |
|
399 | + return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * @return string |
|
404 | + */ |
|
405 | + public function getDefaultFilter() |
|
406 | + { |
|
407 | + if ($this->_filtersel) { |
|
408 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
409 | + } else { |
|
410 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
411 | + } |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * @return array|bool |
|
416 | + */ |
|
417 | + public function getFiltersArray() |
|
418 | + { |
|
419 | + $ret = []; |
|
420 | + $field = []; |
|
421 | + $field['caption'] = _CO_OBJ_NONE; |
|
422 | + $field['selected'] = ''; |
|
423 | + $ret['default'] = $field; |
|
424 | + unset($field); |
|
425 | + |
|
426 | + if ($this->_filterseloptions) { |
|
427 | + foreach ($this->_filterseloptions as $key => $value) { |
|
428 | + $field = []; |
|
429 | + if (is_array($value)) { |
|
430 | + $field['caption'] = $key; |
|
431 | + $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
432 | + } else { |
|
433 | + $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
434 | + $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
435 | + } |
|
436 | + $ret[$key] = $field; |
|
437 | + unset($field); |
|
438 | + } |
|
439 | + } else { |
|
440 | + $ret = false; |
|
441 | + } |
|
442 | + |
|
443 | + return $ret; |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * @param $default_filter2 |
|
448 | + */ |
|
449 | + public function setDefaultFilter2($default_filter2) |
|
450 | + { |
|
451 | + $this->_filtersel2 = $default_filter2; |
|
452 | + } |
|
453 | + |
|
454 | + /** |
|
455 | + * @return string |
|
456 | + */ |
|
457 | + public function getDefaultFilter2() |
|
458 | + { |
|
459 | + if ($this->_filtersel2) { |
|
460 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
461 | + } else { |
|
462 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
463 | + } |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * @return array |
|
468 | + */ |
|
469 | + public function getFilters2Array() |
|
470 | + { |
|
471 | + $ret = []; |
|
472 | + |
|
473 | + foreach ($this->_filtersel2options as $key => $value) { |
|
474 | + $field = []; |
|
475 | + $field['caption'] = $value; |
|
476 | + $field['selected'] = $this->_filtersel2 == $key ? 'selected' : ''; |
|
477 | + $ret[$key] = $field; |
|
478 | + unset($field); |
|
479 | + } |
|
480 | + |
|
481 | + return $ret; |
|
482 | + } |
|
483 | + |
|
484 | + /** |
|
485 | + * @param $limitsArray |
|
486 | + * @param $params_of_the_options_sel |
|
487 | + */ |
|
488 | + public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
489 | + { |
|
490 | + // Rendering the form to select options on the table |
|
491 | + $current_urls = Smartobject\Utility::getCurrentUrls(); |
|
492 | + $current_url = $current_urls['full']; |
|
493 | + |
|
494 | + /** |
|
495 | + * What was $params_of_the_options_sel doing again ? |
|
496 | + */ |
|
497 | + //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
498 | + $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
499 | + $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * @return array |
|
504 | + */ |
|
505 | + public function getLimitsArray() |
|
506 | + { |
|
507 | + $ret = []; |
|
508 | + $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
509 | + $ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : ''; |
|
510 | + |
|
511 | + $ret['5']['caption'] = '5'; |
|
512 | + $ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : ''; |
|
513 | + |
|
514 | + $ret['10']['caption'] = '10'; |
|
515 | + $ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : ''; |
|
516 | + |
|
517 | + $ret['15']['caption'] = '15'; |
|
518 | + $ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : ''; |
|
519 | + |
|
520 | + $ret['20']['caption'] = '20'; |
|
521 | + $ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : ''; |
|
522 | + |
|
523 | + $ret['25']['caption'] = '25'; |
|
524 | + $ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : ''; |
|
525 | + |
|
526 | + $ret['30']['caption'] = '30'; |
|
527 | + $ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : ''; |
|
528 | + |
|
529 | + $ret['35']['caption'] = '35'; |
|
530 | + $ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : ''; |
|
531 | + |
|
532 | + $ret['40']['caption'] = '40'; |
|
533 | + $ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : ''; |
|
534 | + |
|
535 | + return $ret; |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * @return bool |
|
540 | + */ |
|
541 | + public function getObjects() |
|
542 | + { |
|
543 | + return $this->_objects; |
|
544 | + } |
|
545 | + |
|
546 | + public function hideActionColumnTitle() |
|
547 | + { |
|
548 | + $this->_showActionsColumnTitle = false; |
|
549 | + } |
|
550 | + |
|
551 | + public function hideFilterAndLimit() |
|
552 | + { |
|
553 | + $this->_showFilterAndLimit = false; |
|
554 | + } |
|
555 | + |
|
556 | + /** |
|
557 | + * @return array |
|
558 | + */ |
|
559 | + public function getOrdersArray() |
|
560 | + { |
|
561 | + $ret = []; |
|
562 | + $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
563 | + $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : ''; |
|
564 | + |
|
565 | + $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
566 | + $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : ''; |
|
567 | + |
|
568 | + return $ret; |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * @return mixed|string|void |
|
573 | + */ |
|
574 | + public function renderD() |
|
575 | + { |
|
576 | + return $this->render(false, true); |
|
577 | + } |
|
578 | + |
|
579 | + public function renderForPrint() |
|
580 | + { |
|
581 | + } |
|
582 | + |
|
583 | + /** |
|
584 | + * @param bool $fetchOnly |
|
585 | + * @param bool $debug |
|
586 | + * @return mixed|string|void |
|
587 | + */ |
|
588 | + public function render($fetchOnly = false, $debug = false) |
|
589 | + { |
|
590 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
591 | + |
|
592 | + $this->_tpl = new \XoopsTpl(); |
|
593 | + |
|
594 | + /** |
|
595 | + * We need access to the vars of the SmartObject for a few things in the table creation. |
|
596 | + * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
597 | + * and we will free it after |
|
598 | + */ |
|
599 | + $this->_tempObject = $this->_objectHandler->create(); |
|
600 | + |
|
601 | + $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
602 | + |
|
603 | + $this->setSortOrder(); |
|
604 | + |
|
605 | + if (!$this->_isTree) { |
|
606 | + $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
607 | + } else { |
|
608 | + $this->_limitsel = 'all'; |
|
609 | + } |
|
610 | + |
|
611 | + $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
612 | + Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
613 | + $limitsArray = $this->getLimitsArray(); |
|
614 | + $this->_criteria->setLimit($this->_limitsel); |
|
615 | + |
|
616 | + $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
617 | + $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
618 | + Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
619 | + $filtersArray = $this->getFiltersArray(); |
|
620 | + |
|
621 | + if ($filtersArray) { |
|
622 | + $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
623 | + } |
|
624 | + |
|
625 | + // Check if the selected filter is defined and if so, create the selfilter2 |
|
626 | + if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
627 | + // check if method associate with this filter exists in the handler |
|
628 | + if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
629 | + $filter = $this->_filterseloptions[$this->_filtersel]; |
|
630 | + $this->_criteria->add($filter['criteria']); |
|
631 | + } else { |
|
632 | + if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
633 | + |
|
634 | + // then we will create the selfilter2 options by calling this method |
|
635 | + $method = $this->_filterseloptions[$this->_filtersel]; |
|
636 | + $this->_filtersel2options = $this->_objectHandler->$method(); |
|
637 | + |
|
638 | + $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
639 | + $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
640 | + |
|
641 | + $filters2Array = $this->getFilters2Array(); |
|
642 | + $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
643 | + |
|
644 | + Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
645 | + if ('default' !== $this->_filtersel2) { |
|
646 | + $this->_criteria->add(new \Criteria($this->_filtersel, $this->_filtersel2)); |
|
647 | + } |
|
648 | + } |
|
649 | + } |
|
650 | + } |
|
651 | + // Check if we have a quicksearch |
|
652 | + |
|
653 | + if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) { |
|
654 | + $quicksearch_criteria = new \CriteriaCompo(); |
|
655 | + if (is_array($this->_quickSearch['fields'])) { |
|
656 | + foreach ($this->_quickSearch['fields'] as $v) { |
|
657 | + $quicksearch_criteria->add(new \Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
658 | + } |
|
659 | + } else { |
|
660 | + $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
661 | + } |
|
662 | + $this->_criteria->add($quicksearch_criteria); |
|
663 | + } |
|
664 | + |
|
665 | + $this->_objects = $this->fetchObjects($debug); |
|
666 | + |
|
667 | + require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
668 | + if ($this->_criteria->getLimit() > 0) { |
|
669 | + |
|
670 | + /** |
|
671 | + * Geeting rid of the old params |
|
672 | + * $new_get_array is an array containing the new GET parameters |
|
673 | + */ |
|
674 | + $new_get_array = []; |
|
675 | + |
|
676 | + /** |
|
677 | + * $params_of_the_options_sel is an array with all the parameters of the page |
|
678 | + * but without the pagenave parameters. This array will be used in the |
|
679 | + * OptionsSelection |
|
680 | + */ |
|
681 | + $params_of_the_options_sel = []; |
|
682 | + |
|
683 | + $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName]; |
|
684 | + foreach ($_GET as $k => $v) { |
|
685 | + if (!in_array($k, $not_needed_params)) { |
|
686 | + $new_get_array[] = "$k=$v"; |
|
687 | + $params_of_the_options_sel[] = "$k=$v"; |
|
688 | + } |
|
689 | + } |
|
690 | + |
|
691 | + /** |
|
692 | + * Adding the new params of the pagenav |
|
693 | + */ |
|
694 | + $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
695 | + $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
696 | + $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
697 | + $otherParams = implode('&', $new_get_array); |
|
698 | + |
|
699 | + $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
700 | + $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
701 | + } |
|
702 | + $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
703 | + |
|
704 | + // retreive the current url and the query string |
|
705 | + $current_urls = Smartobject\Utility::getCurrentUrls(); |
|
706 | + $current_url = $current_urls['full_phpself']; |
|
707 | + $query_string = $current_urls['querystring']; |
|
708 | + if ($query_string) { |
|
709 | + $query_string = str_replace('?', '', $query_string); |
|
710 | + } |
|
711 | + $query_stringArray = explode('&', $query_string); |
|
712 | + $new_query_stringArray = []; |
|
713 | + foreach ($query_stringArray as $query_string) { |
|
714 | + if (false === strpos($query_string, 'sortsel') && false === strpos($query_string, 'ordersel')) { |
|
715 | + $new_query_stringArray[] = $query_string; |
|
716 | + } |
|
717 | + } |
|
718 | + $new_query_string = implode('&', $new_query_stringArray); |
|
719 | + |
|
720 | + $orderArray = []; |
|
721 | + $orderArray['ASC']['image'] = 'desc.png'; |
|
722 | + $orderArray['ASC']['neworder'] = 'DESC'; |
|
723 | + $orderArray['DESC']['image'] = 'asc.png'; |
|
724 | + $orderArray['DESC']['neworder'] = 'ASC'; |
|
725 | + |
|
726 | + $aColumns = []; |
|
727 | + |
|
728 | + foreach ($this->_columns as $column) { |
|
729 | + $qs_param = ''; |
|
730 | + $aColumn = []; |
|
731 | + $aColumn['width'] = $column->getWidth(); |
|
732 | + $aColumn['align'] = $column->getAlign(); |
|
733 | + $aColumn['key'] = $column->getKeyName(); |
|
734 | + if ('checked' === $column->_keyname) { |
|
735 | + $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
736 | + } elseif ($column->getCustomCaption()) { |
|
737 | + $aColumn['caption'] = $column->getCustomCaption(); |
|
738 | + } else { |
|
739 | + $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
740 | + } |
|
741 | + // Are we doing a GET sort on this column ? |
|
742 | + $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
743 | + && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
744 | + || ($this->_sortsel == $column->getKeyName()); |
|
745 | + $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
746 | + |
|
747 | + if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) { |
|
748 | + $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
749 | + } |
|
750 | + if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) { |
|
751 | + $aColumn['caption'] = $aColumn['caption']; |
|
752 | + } elseif ($getSort) { |
|
753 | + $aColumn['caption'] = '<a href="' |
|
754 | + . $current_url |
|
755 | + . '?' |
|
756 | + . $this->_objectHandler->_itemname |
|
757 | + . '_' |
|
758 | + . 'sortsel=' |
|
759 | + . $column->getKeyName() |
|
760 | + . '&' |
|
761 | + . $this->_objectHandler->_itemname |
|
762 | + . '_' |
|
763 | + . 'ordersel=' |
|
764 | + . $orderArray[$order]['neworder'] |
|
765 | + . $qs_param |
|
766 | + . '&' |
|
767 | + . $new_query_string |
|
768 | + . '">' |
|
769 | + . $aColumn['caption'] |
|
770 | + . ' <img src="' |
|
771 | + . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
772 | + . $orderArray[$order]['image'] |
|
773 | + . '" alt="ASC"></a>'; |
|
774 | + } else { |
|
775 | + $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
776 | + } |
|
777 | + $aColumns[] = $aColumn; |
|
778 | + } |
|
779 | + $this->_tpl->assign('smartobject_columns', $aColumns); |
|
780 | + |
|
781 | + if ($this->_quickSearch) { |
|
782 | + $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
783 | + } |
|
784 | + |
|
785 | + $this->createTableRows(); |
|
786 | + |
|
787 | + $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
788 | + $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
789 | + $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
790 | + $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
791 | + $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
792 | + $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
793 | + $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
794 | + $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
795 | + $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
796 | + $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
797 | + $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
798 | + $this->_tpl->assign('smartobject_id', $this->_id); |
|
799 | + if (!empty($this->_withSelectedActions)) { |
|
800 | + $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
801 | + } |
|
802 | + |
|
803 | + $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
804 | + if ($fetchOnly) { |
|
805 | + return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
806 | + } else { |
|
807 | + $this->_tpl->display('db:' . $smartobjectTable_template); |
|
808 | + } |
|
809 | + } |
|
810 | + |
|
811 | + public function disableColumnsSorting() |
|
812 | + { |
|
813 | + $this->_enableColumnsSorting = false; |
|
814 | + } |
|
815 | + |
|
816 | + /** |
|
817 | + * @param bool $debug |
|
818 | + * @return mixed|string|void |
|
819 | + */ |
|
820 | + public function fetch($debug = false) |
|
821 | + { |
|
822 | + return $this->render(true, $debug); |
|
823 | + } |
|
824 | 824 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function addActionButton($op, $caption = false, $text = false) |
94 | 94 | { |
95 | - $action = [ |
|
95 | + $action = [ |
|
96 | 96 | 'op' => $op, |
97 | 97 | 'caption' => $caption, |
98 | 98 | 'text' => $text |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | { |
128 | 128 | $current_urls = Smartobject\Utility::getCurrentUrls(); |
129 | 129 | $current_url = $current_urls['full']; |
130 | - $this->_printerFriendlyPage = $current_url . '&print'; |
|
130 | + $this->_printerFriendlyPage = $current_url.'&print'; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | public function addDefaultIntroButton($caption) |
162 | 162 | { |
163 | - $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
163 | + $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page.'?op=mod', $caption); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | public function getDefaultSort() |
186 | 186 | { |
187 | 187 | if ($this->_sortsel) { |
188 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
188 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_sortsel); |
|
189 | 189 | } else { |
190 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
190 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_objectHandler->identifierName); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -205,9 +205,9 @@ discard block |
||
205 | 205 | public function getDefaultOrder() |
206 | 206 | { |
207 | 207 | if ($this->_ordersel) { |
208 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
208 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', $this->_ordersel); |
|
209 | 209 | } else { |
210 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
210 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', 'ASC'); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
@@ -256,21 +256,21 @@ discard block |
||
256 | 256 | |
257 | 257 | public function setSortOrder() |
258 | 258 | { |
259 | - $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
259 | + $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname.'_'.'sortsel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'sortsel'] : $this->getDefaultSort(); |
|
260 | 260 | //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
261 | - Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
261 | + Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_sortsel); |
|
262 | 262 | $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
263 | 263 | |
264 | 264 | if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
265 | 265 | && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
266 | - $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
266 | + $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'].'.'.$this->_sortsel); |
|
267 | 267 | } else { |
268 | - $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
268 | + $this->_criteria->setSort($this->_objectHandler->_itemname.'.'.$this->_sortsel); |
|
269 | 269 | } |
270 | 270 | |
271 | - $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
271 | + $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname.'_'.'ordersel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'ordersel'] : $this->getDefaultOrder(); |
|
272 | 272 | //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
273 | - Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
273 | + Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', $this->_ordersel); |
|
274 | 274 | $ordersArray = $this->getOrdersArray(); |
275 | 275 | $this->_criteria->setOrder($this->_ordersel); |
276 | 276 | } |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | //$object->initiateCustomFields(); |
321 | 321 | } |
322 | 322 | if ('checked' === $column->_keyname) { |
323 | - $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
323 | + $value = '<input type ="checkbox" name="selected_smartobjects[]" value="'.$object->id().'">'; |
|
324 | 324 | } elseif ($column->_customMethodForValue |
325 | 325 | && method_exists($object, $column->_customMethodForValue)) { |
326 | 326 | $method = $column->_customMethodForValue; |
@@ -405,9 +405,9 @@ discard block |
||
405 | 405 | public function getDefaultFilter() |
406 | 406 | { |
407 | 407 | if ($this->_filtersel) { |
408 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
408 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', $this->_filtersel); |
|
409 | 409 | } else { |
410 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
410 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', 'default'); |
|
411 | 411 | } |
412 | 412 | } |
413 | 413 | |
@@ -457,9 +457,9 @@ discard block |
||
457 | 457 | public function getDefaultFilter2() |
458 | 458 | { |
459 | 459 | if ($this->_filtersel2) { |
460 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
460 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'].'_filtersel2', $this->_filtersel2); |
|
461 | 461 | } else { |
462 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
462 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'].'_filtersel2', 'default'); |
|
463 | 463 | } |
464 | 464 | } |
465 | 465 | |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | */ |
588 | 588 | public function render($fetchOnly = false, $debug = false) |
589 | 589 | { |
590 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
590 | + require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|
591 | 591 | |
592 | 592 | $this->_tpl = new \XoopsTpl(); |
593 | 593 | |
@@ -598,24 +598,24 @@ discard block |
||
598 | 598 | */ |
599 | 599 | $this->_tempObject = $this->_objectHandler->create(); |
600 | 600 | |
601 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
601 | + $this->_criteria->setStart(isset($_GET['start'.$this->_objectHandler->keyName]) ? (int) $_GET['start'.$this->_objectHandler->keyName] : 0); |
|
602 | 602 | |
603 | 603 | $this->setSortOrder(); |
604 | 604 | |
605 | 605 | if (!$this->_isTree) { |
606 | - $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
606 | + $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'].'_limitsel', '15'); |
|
607 | 607 | } else { |
608 | 608 | $this->_limitsel = 'all'; |
609 | 609 | } |
610 | 610 | |
611 | 611 | $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
612 | - Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
612 | + Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'].'_limitsel', $this->_limitsel); |
|
613 | 613 | $limitsArray = $this->getLimitsArray(); |
614 | 614 | $this->_criteria->setLimit($this->_limitsel); |
615 | 615 | |
616 | 616 | $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
617 | 617 | $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
618 | - Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
618 | + Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', $this->_filtersel); |
|
619 | 619 | $filtersArray = $this->getFiltersArray(); |
620 | 620 | |
621 | 621 | if ($filtersArray) { |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | $filters2Array = $this->getFilters2Array(); |
642 | 642 | $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
643 | 643 | |
644 | - Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
644 | + Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'].'_filtersel2', $this->_filtersel2); |
|
645 | 645 | if ('default' !== $this->_filtersel2) { |
646 | 646 | $this->_criteria->add(new \Criteria($this->_filtersel, $this->_filtersel2)); |
647 | 647 | } |
@@ -650,21 +650,21 @@ discard block |
||
650 | 650 | } |
651 | 651 | // Check if we have a quicksearch |
652 | 652 | |
653 | - if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) { |
|
653 | + if (isset($_POST['quicksearch_'.$this->_id]) && '' != $_POST['quicksearch_'.$this->_id]) { |
|
654 | 654 | $quicksearch_criteria = new \CriteriaCompo(); |
655 | 655 | if (is_array($this->_quickSearch['fields'])) { |
656 | 656 | foreach ($this->_quickSearch['fields'] as $v) { |
657 | - $quicksearch_criteria->add(new \Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
657 | + $quicksearch_criteria->add(new \Criteria($v, '%'.$_POST['quicksearch_'.$this->_id].'%', 'LIKE'), 'OR'); |
|
658 | 658 | } |
659 | 659 | } else { |
660 | - $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
660 | + $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%'.$_POST['quicksearch_'.$this->_id].'%', 'LIKE')); |
|
661 | 661 | } |
662 | 662 | $this->_criteria->add($quicksearch_criteria); |
663 | 663 | } |
664 | 664 | |
665 | 665 | $this->_objects = $this->fetchObjects($debug); |
666 | 666 | |
667 | - require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
667 | + require_once XOOPS_ROOT_PATH.'/class/pagenav.php'; |
|
668 | 668 | if ($this->_criteria->getLimit() > 0) { |
669 | 669 | |
670 | 670 | /** |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | */ |
681 | 681 | $params_of_the_options_sel = []; |
682 | 682 | |
683 | - $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName]; |
|
683 | + $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start'.$this->_objectHandler->keyName]; |
|
684 | 684 | foreach ($_GET as $k => $v) { |
685 | 685 | if (!in_array($k, $not_needed_params)) { |
686 | 686 | $new_get_array[] = "$k=$v"; |
@@ -691,12 +691,12 @@ discard block |
||
691 | 691 | /** |
692 | 692 | * Adding the new params of the pagenav |
693 | 693 | */ |
694 | - $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
695 | - $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
696 | - $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
694 | + $new_get_array[] = 'sortsel='.$this->_sortsel; |
|
695 | + $new_get_array[] = 'ordersel='.$this->_ordersel; |
|
696 | + $new_get_array[] = 'limitsel='.$this->_limitsel; |
|
697 | 697 | $otherParams = implode('&', $new_get_array); |
698 | 698 | |
699 | - $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
699 | + $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start'.$this->_objectHandler->keyName, $otherParams); |
|
700 | 700 | $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
701 | 701 | } |
702 | 702 | $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
@@ -732,20 +732,20 @@ discard block |
||
732 | 732 | $aColumn['align'] = $column->getAlign(); |
733 | 733 | $aColumn['key'] = $column->getKeyName(); |
734 | 734 | if ('checked' === $column->_keyname) { |
735 | - $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
735 | + $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"'.' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_'.$this->_id.', \'selected_smartobjects\');">'; |
|
736 | 736 | } elseif ($column->getCustomCaption()) { |
737 | 737 | $aColumn['caption'] = $column->getCustomCaption(); |
738 | 738 | } else { |
739 | 739 | $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
740 | 740 | } |
741 | 741 | // Are we doing a GET sort on this column ? |
742 | - $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
743 | - && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
742 | + $getSort = (isset($_GET[$this->_objectHandler->_itemname.'_'.'sortsel']) |
|
743 | + && $_GET[$this->_objectHandler->_itemname.'_'.'sortsel'] == $column->getKeyName()) |
|
744 | 744 | || ($this->_sortsel == $column->getKeyName()); |
745 | - $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
745 | + $order = isset($_GET[$this->_objectHandler->_itemname.'_'.'ordersel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'ordersel'] : 'DESC'; |
|
746 | 746 | |
747 | - if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) { |
|
748 | - $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
747 | + if (isset($_REQUEST['quicksearch_'.$this->_id]) && '' != $_REQUEST['quicksearch_'.$this->_id]) { |
|
748 | + $qs_param = '&quicksearch_'.$this->_id.'='.$_REQUEST['quicksearch_'.$this->_id]; |
|
749 | 749 | } |
750 | 750 | if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) { |
751 | 751 | $aColumn['caption'] = $aColumn['caption']; |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | . $orderArray[$order]['image'] |
773 | 773 | . '" alt="ASC"></a>'; |
774 | 774 | } else { |
775 | - $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
775 | + $aColumn['caption'] = '<a href="'.$current_url.'?'.$this->_objectHandler->_itemname.'_'.'sortsel='.$column->getKeyName().'&'.$this->_objectHandler->_itemname.'_'.'ordersel=ASC'.$qs_param.'&'.$new_query_string.'">'.$aColumn['caption'].'</a>'; |
|
776 | 776 | } |
777 | 777 | $aColumns[] = $aColumn; |
778 | 778 | } |
@@ -802,9 +802,9 @@ discard block |
||
802 | 802 | |
803 | 803 | $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
804 | 804 | if ($fetchOnly) { |
805 | - return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
805 | + return $this->_tpl->fetch('db:'.$smartobjectTable_template); |
|
806 | 806 | } else { |
807 | - $this->_tpl->display('db:' . $smartobjectTable_template); |
|
807 | + $this->_tpl->display('db:'.$smartobjectTable_template); |
|
808 | 808 | } |
809 | 809 | } |
810 | 810 |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
339 | - * @param $key |
|
339 | + * @param string $key |
|
340 | 340 | * @param bool $moduleName |
341 | 341 | * @param string $default |
342 | 342 | * @return null|string |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | |
399 | 399 | /** |
400 | 400 | * Thanks to the NewBB2 Development Team |
401 | - * @param $target |
|
401 | + * @param string $target |
|
402 | 402 | * @return bool |
403 | 403 | */ |
404 | 404 | public static function mkdirAsAdmin($target) |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | |
552 | 552 | /** |
553 | 553 | * @param $dirname |
554 | - * @return bool |
|
554 | + * @return boolean|null |
|
555 | 555 | */ |
556 | 556 | public static function deleteFile($dirname) |
557 | 557 | { |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | } |
745 | 745 | |
746 | 746 | /** |
747 | - * @param $name |
|
747 | + * @param string $name |
|
748 | 748 | */ |
749 | 749 | public static function closeCollapsable($name) |
750 | 750 | { |
@@ -754,7 +754,7 @@ discard block |
||
754 | 754 | } |
755 | 755 | |
756 | 756 | /** |
757 | - * @param $name |
|
757 | + * @param string $name |
|
758 | 758 | * @param $value |
759 | 759 | * @param int $time |
760 | 760 | */ |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | } |
769 | 769 | |
770 | 770 | /** |
771 | - * @param $name |
|
771 | + * @param string $name |
|
772 | 772 | * @param string $default |
773 | 773 | * @return string |
774 | 774 | */ |
@@ -917,7 +917,7 @@ discard block |
||
917 | 917 | } |
918 | 918 | |
919 | 919 | /** |
920 | - * @param $src |
|
920 | + * @param string $src |
|
921 | 921 | */ |
922 | 922 | public static function addScript($src) |
923 | 923 | { |
@@ -1096,8 +1096,8 @@ discard block |
||
1096 | 1096 | } |
1097 | 1097 | |
1098 | 1098 | /** |
1099 | - * @param $module |
|
1100 | - * @param $file |
|
1099 | + * @param string $module |
|
1100 | + * @param string $file |
|
1101 | 1101 | */ |
1102 | 1102 | public static function loadLanguageFile($module, $file) |
1103 | 1103 | { |
@@ -1215,7 +1215,7 @@ discard block |
||
1215 | 1215 | * This function should be able to cover almost all floats that appear in an european environment. |
1216 | 1216 | * @param $str |
1217 | 1217 | * @param bool $set |
1218 | - * @return float|int |
|
1218 | + * @return double |
|
1219 | 1219 | */ |
1220 | 1220 | public static function getFloat($str, $set = false) |
1221 | 1221 | { |
@@ -1250,7 +1250,7 @@ discard block |
||
1250 | 1250 | /** |
1251 | 1251 | * @param $var |
1252 | 1252 | * @param bool $currencyObj |
1253 | - * @return float|int|mixed|string |
|
1253 | + * @return string |
|
1254 | 1254 | */ |
1255 | 1255 | public static function getCurrency($var, $currencyObj = false) |
1256 | 1256 | { |
@@ -1278,7 +1278,7 @@ discard block |
||
1278 | 1278 | |
1279 | 1279 | /** |
1280 | 1280 | * @param $var |
1281 | - * @return float|int|mixed|string |
|
1281 | + * @return string |
|
1282 | 1282 | */ |
1283 | 1283 | public static function float($var) |
1284 | 1284 | { |
@@ -1326,7 +1326,7 @@ discard block |
||
1326 | 1326 | /** |
1327 | 1327 | * @param $moduleName |
1328 | 1328 | * @param $items |
1329 | - * @return array |
|
1329 | + * @return string[] |
|
1330 | 1330 | */ |
1331 | 1331 | public static function getTablesArray($moduleName, $items) |
1332 | 1332 | { |
@@ -1,6 +1,5 @@ |
||
1 | 1 | <?php namespace XoopsModules\Smartobject; |
2 | 2 | |
3 | -use Xmf\Request; |
|
4 | 3 | use XoopsModules\Smartobject; |
5 | 4 | use XoopsModules\Smartobject\Common; |
6 | 5 |
@@ -9,186 +9,186 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class Utility |
11 | 11 | { |
12 | - use Common\VersionChecks; //checkVerXoops, checkVerPhp Traits |
|
13 | - |
|
14 | - use Common\ServerStats; // getServerStats Trait |
|
15 | - |
|
16 | - use Common\FilesManagement; // Files Management Trait |
|
17 | - |
|
18 | - //--------------- Custom module methods ----------------------------- |
|
19 | - |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * @param $cssfile |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public static function getCssLink($cssfile) |
|
27 | - { |
|
28 | - $ret = '<link rel="stylesheet" type="text/css" href="' . $cssfile . '">'; |
|
29 | - |
|
30 | - return $ret; |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - public static function getPageBeforeForm() |
|
37 | - { |
|
38 | - global $smart_previous_page; |
|
39 | - |
|
40 | - return isset($_POST['smart_page_before_form']) ? $_POST['smart_page_before_form'] : $smart_previous_page; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Checks if a user is admin of $module |
|
45 | - * |
|
46 | - * @param bool $module |
|
47 | - * @return bool: true if user is admin |
|
48 | - */ |
|
49 | - public static function userIsAdmin($module = false) |
|
50 | - { |
|
51 | - global $xoopsUser; |
|
52 | - static $smart_isAdmin; |
|
53 | - if (!$module) { |
|
54 | - global $xoopsModule; |
|
55 | - $module = $xoopsModule->getVar('dirname'); |
|
56 | - } |
|
57 | - if (isset($smart_isAdmin[$module])) { |
|
58 | - return $smart_isAdmin[$module]; |
|
59 | - } |
|
60 | - if (!$xoopsUser) { |
|
61 | - $smart_isAdmin[$module] = false; |
|
62 | - |
|
63 | - return $smart_isAdmin[$module]; |
|
64 | - } |
|
65 | - $smart_isAdmin[$module] = false; |
|
66 | - $smartModule = static::getModuleInfo($module); |
|
67 | - if (!is_object($smartModule)) { |
|
68 | - return false; |
|
69 | - } |
|
70 | - $module_id = $smartModule->getVar('mid'); |
|
71 | - $smart_isAdmin[$module] = $xoopsUser->isAdmin($module_id); |
|
72 | - |
|
73 | - return $smart_isAdmin[$module]; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @return bool |
|
78 | - */ |
|
79 | - public static function isXoops22() |
|
80 | - { |
|
81 | - $xoops22 = false; |
|
82 | - $xv = str_replace('XOOPS ', '', XOOPS_VERSION); |
|
83 | - if ('2' == substr($xv, 2, 1)) { |
|
84 | - $xoops22 = true; |
|
85 | - } |
|
86 | - |
|
87 | - return $xoops22; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @param bool $withLink |
|
92 | - * @param bool $forBreadCrumb |
|
93 | - * @param bool $moduleName |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public static function getModuleName($withLink = true, $forBreadCrumb = false, $moduleName = false) |
|
97 | - { |
|
98 | - if (!$moduleName) { |
|
99 | - global $xoopsModule; |
|
100 | - $moduleName = $xoopsModule->getVar('dirname'); |
|
101 | - } |
|
102 | - $smartModule = static::getModuleInfo($moduleName); |
|
103 | - $smartModuleConfig = static::getModuleConfig($moduleName); |
|
104 | - if (!isset($smartModule)) { |
|
105 | - return ''; |
|
106 | - } |
|
107 | - |
|
108 | - if ($forBreadCrumb |
|
109 | - && (isset($smartModuleConfig['show_mod_name_breadcrumb']) |
|
110 | - && !$smartModuleConfig['show_mod_name_breadcrumb'])) { |
|
111 | - return ''; |
|
112 | - } |
|
113 | - if (!$withLink) { |
|
114 | - return $smartModule->getVar('name'); |
|
115 | - } else { |
|
116 | - $seoMode = static::getModuleModeSEO($moduleName); |
|
117 | - if ('rewrite' === $seoMode) { |
|
118 | - $seoModuleName = static::getModuleNameForSEO($moduleName); |
|
119 | - $ret = XOOPS_URL . '/' . $seoModuleName . '/'; |
|
120 | - } elseif ('pathinfo' === $seoMode) { |
|
121 | - $ret = XOOPS_URL . '/modules/' . $moduleName . '/seo.php/' . $seoModuleName . '/'; |
|
122 | - } else { |
|
123 | - $ret = XOOPS_URL . '/modules/' . $moduleName . '/'; |
|
124 | - } |
|
125 | - |
|
126 | - return '<a href="' . $ret . '">' . $smartModule->getVar('name') . '</a>'; |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @param bool $moduleName |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public static function getModuleNameForSEO($moduleName = false) |
|
135 | - { |
|
136 | - $smartModule = static::getModuleInfo($moduleName); |
|
137 | - $smartModuleConfig = static::getModuleConfig($moduleName); |
|
138 | - if (isset($smartModuleConfig['seo_module_name'])) { |
|
139 | - return $smartModuleConfig['seo_module_name']; |
|
140 | - } |
|
141 | - $ret = static::getModuleName(false, false, $moduleName); |
|
142 | - |
|
143 | - return strtolower($ret); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @param bool $moduleName |
|
148 | - * @return bool |
|
149 | - */ |
|
150 | - public static function getModuleModeSEO($moduleName = false) |
|
151 | - { |
|
152 | - $smartModule = static::getModuleInfo($moduleName); |
|
153 | - $smartModuleConfig = static::getModuleConfig($moduleName); |
|
154 | - |
|
155 | - return isset($smartModuleConfig['seo_mode']) ? $smartModuleConfig['seo_mode'] : false; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @param bool $moduleName |
|
160 | - * @return bool |
|
161 | - */ |
|
162 | - public static function getModuleIncludeIdSEO($moduleName = false) |
|
163 | - { |
|
164 | - $smartModule = static::getModuleInfo($moduleName); |
|
165 | - $smartModuleConfig = static::getModuleConfig($moduleName); |
|
166 | - |
|
167 | - return !empty($smartModuleConfig['seo_inc_id']); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @param $key |
|
172 | - * @return string |
|
173 | - */ |
|
174 | - public static function getEnv($key) |
|
175 | - { |
|
176 | - $ret = ''; |
|
177 | - $ret = isset($_SERVER[$key]) ? $_SERVER[$key] : (isset($_ENV[$key]) ? $_ENV[$key] : ''); |
|
178 | - |
|
179 | - return $ret; |
|
180 | - } |
|
181 | - |
|
182 | - public static function getXoopsCpHeader() |
|
183 | - { |
|
184 | - xoops_cp_header(); |
|
185 | - global $xoopsModule, $xoopsConfig; |
|
186 | - /** |
|
187 | - * include SmartObject admin language file |
|
188 | - */ |
|
189 | - /** @var Smartobject\Helper $helper */ |
|
190 | - $helper = Smartobject\Helper::getInstance(); |
|
191 | - $helper->loadLanguage('admin'); ?> |
|
12 | + use Common\VersionChecks; //checkVerXoops, checkVerPhp Traits |
|
13 | + |
|
14 | + use Common\ServerStats; // getServerStats Trait |
|
15 | + |
|
16 | + use Common\FilesManagement; // Files Management Trait |
|
17 | + |
|
18 | + //--------------- Custom module methods ----------------------------- |
|
19 | + |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * @param $cssfile |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public static function getCssLink($cssfile) |
|
27 | + { |
|
28 | + $ret = '<link rel="stylesheet" type="text/css" href="' . $cssfile . '">'; |
|
29 | + |
|
30 | + return $ret; |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + public static function getPageBeforeForm() |
|
37 | + { |
|
38 | + global $smart_previous_page; |
|
39 | + |
|
40 | + return isset($_POST['smart_page_before_form']) ? $_POST['smart_page_before_form'] : $smart_previous_page; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Checks if a user is admin of $module |
|
45 | + * |
|
46 | + * @param bool $module |
|
47 | + * @return bool: true if user is admin |
|
48 | + */ |
|
49 | + public static function userIsAdmin($module = false) |
|
50 | + { |
|
51 | + global $xoopsUser; |
|
52 | + static $smart_isAdmin; |
|
53 | + if (!$module) { |
|
54 | + global $xoopsModule; |
|
55 | + $module = $xoopsModule->getVar('dirname'); |
|
56 | + } |
|
57 | + if (isset($smart_isAdmin[$module])) { |
|
58 | + return $smart_isAdmin[$module]; |
|
59 | + } |
|
60 | + if (!$xoopsUser) { |
|
61 | + $smart_isAdmin[$module] = false; |
|
62 | + |
|
63 | + return $smart_isAdmin[$module]; |
|
64 | + } |
|
65 | + $smart_isAdmin[$module] = false; |
|
66 | + $smartModule = static::getModuleInfo($module); |
|
67 | + if (!is_object($smartModule)) { |
|
68 | + return false; |
|
69 | + } |
|
70 | + $module_id = $smartModule->getVar('mid'); |
|
71 | + $smart_isAdmin[$module] = $xoopsUser->isAdmin($module_id); |
|
72 | + |
|
73 | + return $smart_isAdmin[$module]; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @return bool |
|
78 | + */ |
|
79 | + public static function isXoops22() |
|
80 | + { |
|
81 | + $xoops22 = false; |
|
82 | + $xv = str_replace('XOOPS ', '', XOOPS_VERSION); |
|
83 | + if ('2' == substr($xv, 2, 1)) { |
|
84 | + $xoops22 = true; |
|
85 | + } |
|
86 | + |
|
87 | + return $xoops22; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @param bool $withLink |
|
92 | + * @param bool $forBreadCrumb |
|
93 | + * @param bool $moduleName |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public static function getModuleName($withLink = true, $forBreadCrumb = false, $moduleName = false) |
|
97 | + { |
|
98 | + if (!$moduleName) { |
|
99 | + global $xoopsModule; |
|
100 | + $moduleName = $xoopsModule->getVar('dirname'); |
|
101 | + } |
|
102 | + $smartModule = static::getModuleInfo($moduleName); |
|
103 | + $smartModuleConfig = static::getModuleConfig($moduleName); |
|
104 | + if (!isset($smartModule)) { |
|
105 | + return ''; |
|
106 | + } |
|
107 | + |
|
108 | + if ($forBreadCrumb |
|
109 | + && (isset($smartModuleConfig['show_mod_name_breadcrumb']) |
|
110 | + && !$smartModuleConfig['show_mod_name_breadcrumb'])) { |
|
111 | + return ''; |
|
112 | + } |
|
113 | + if (!$withLink) { |
|
114 | + return $smartModule->getVar('name'); |
|
115 | + } else { |
|
116 | + $seoMode = static::getModuleModeSEO($moduleName); |
|
117 | + if ('rewrite' === $seoMode) { |
|
118 | + $seoModuleName = static::getModuleNameForSEO($moduleName); |
|
119 | + $ret = XOOPS_URL . '/' . $seoModuleName . '/'; |
|
120 | + } elseif ('pathinfo' === $seoMode) { |
|
121 | + $ret = XOOPS_URL . '/modules/' . $moduleName . '/seo.php/' . $seoModuleName . '/'; |
|
122 | + } else { |
|
123 | + $ret = XOOPS_URL . '/modules/' . $moduleName . '/'; |
|
124 | + } |
|
125 | + |
|
126 | + return '<a href="' . $ret . '">' . $smartModule->getVar('name') . '</a>'; |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @param bool $moduleName |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public static function getModuleNameForSEO($moduleName = false) |
|
135 | + { |
|
136 | + $smartModule = static::getModuleInfo($moduleName); |
|
137 | + $smartModuleConfig = static::getModuleConfig($moduleName); |
|
138 | + if (isset($smartModuleConfig['seo_module_name'])) { |
|
139 | + return $smartModuleConfig['seo_module_name']; |
|
140 | + } |
|
141 | + $ret = static::getModuleName(false, false, $moduleName); |
|
142 | + |
|
143 | + return strtolower($ret); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @param bool $moduleName |
|
148 | + * @return bool |
|
149 | + */ |
|
150 | + public static function getModuleModeSEO($moduleName = false) |
|
151 | + { |
|
152 | + $smartModule = static::getModuleInfo($moduleName); |
|
153 | + $smartModuleConfig = static::getModuleConfig($moduleName); |
|
154 | + |
|
155 | + return isset($smartModuleConfig['seo_mode']) ? $smartModuleConfig['seo_mode'] : false; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @param bool $moduleName |
|
160 | + * @return bool |
|
161 | + */ |
|
162 | + public static function getModuleIncludeIdSEO($moduleName = false) |
|
163 | + { |
|
164 | + $smartModule = static::getModuleInfo($moduleName); |
|
165 | + $smartModuleConfig = static::getModuleConfig($moduleName); |
|
166 | + |
|
167 | + return !empty($smartModuleConfig['seo_inc_id']); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @param $key |
|
172 | + * @return string |
|
173 | + */ |
|
174 | + public static function getEnv($key) |
|
175 | + { |
|
176 | + $ret = ''; |
|
177 | + $ret = isset($_SERVER[$key]) ? $_SERVER[$key] : (isset($_ENV[$key]) ? $_ENV[$key] : ''); |
|
178 | + |
|
179 | + return $ret; |
|
180 | + } |
|
181 | + |
|
182 | + public static function getXoopsCpHeader() |
|
183 | + { |
|
184 | + xoops_cp_header(); |
|
185 | + global $xoopsModule, $xoopsConfig; |
|
186 | + /** |
|
187 | + * include SmartObject admin language file |
|
188 | + */ |
|
189 | + /** @var Smartobject\Helper $helper */ |
|
190 | + $helper = Smartobject\Helper::getInstance(); |
|
191 | + $helper->loadLanguage('admin'); ?> |
|
192 | 192 | |
193 | 193 | <script type='text/javascript'> |
194 | 194 | <!-- |
@@ -202,504 +202,504 @@ discard block |
||
202 | 202 | src='<?php echo SMARTOBJECT_URL ?>include/smart.js'></script> |
203 | 203 | <?php |
204 | 204 | |
205 | - /** |
|
206 | - * Include the admin language constants for the SmartObject Framework |
|
207 | - */ |
|
208 | - /** @var Smartobject\Helper $helper */ |
|
209 | - $helper = Smartobject\Helper::getInstance(); |
|
210 | - $helper->loadLanguage('admin'); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Detemines if a table exists in the current db |
|
215 | - * |
|
216 | - * @param string $table the table name (without XOOPS prefix) |
|
217 | - * @return bool True if table exists, false if not |
|
218 | - * |
|
219 | - * @access public |
|
220 | - * @author xhelp development team |
|
221 | - */ |
|
222 | - public static function isTable($table) |
|
223 | - { |
|
224 | - $bRetVal = false; |
|
225 | - //Verifies that a MySQL table exists |
|
226 | - $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
227 | - $realname = $xoopsDB->prefix($table); |
|
228 | - $sql = 'SHOW TABLES FROM ' . XOOPS_DB_NAME; |
|
229 | - $ret = $xoopsDB->queryF($sql); |
|
230 | - while (false !== (list($m_table) = $xoopsDB->fetchRow($ret))) { |
|
231 | - if ($m_table == $realname) { |
|
232 | - $bRetVal = true; |
|
233 | - break; |
|
234 | - } |
|
235 | - } |
|
236 | - $xoopsDB->freeRecordSet($ret); |
|
237 | - |
|
238 | - return $bRetVal; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Gets a value from a key in the xhelp_meta table |
|
243 | - * |
|
244 | - * @param string $key |
|
245 | - * @param bool $moduleName |
|
246 | - * @return string $value |
|
247 | - * |
|
248 | - * @access public |
|
249 | - * @author xhelp development team |
|
250 | - */ |
|
251 | - public static function getMeta($key, $moduleName = false) |
|
252 | - { |
|
253 | - if (!$moduleName) { |
|
254 | - $moduleName = static::getCurrentModuleName(); |
|
255 | - } |
|
256 | - $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
257 | - $sql = sprintf('SELECT metavalue FROM `%s` WHERE metakey=%s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key)); |
|
258 | - $ret = $xoopsDB->query($sql); |
|
259 | - if (!$ret) { |
|
260 | - $value = false; |
|
261 | - } else { |
|
262 | - list($value) = $xoopsDB->fetchRow($ret); |
|
263 | - } |
|
264 | - |
|
265 | - return $value; |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * @return bool |
|
270 | - */ |
|
271 | - public static function getCurrentModuleName() |
|
272 | - { |
|
273 | - global $xoopsModule; |
|
274 | - if (is_object($xoopsModule)) { |
|
275 | - return $xoopsModule->getVar('dirname'); |
|
276 | - } else { |
|
277 | - return false; |
|
278 | - } |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Sets a value for a key in the xhelp_meta table |
|
283 | - * |
|
284 | - * @param string $key |
|
285 | - * @param string $value |
|
286 | - * @param bool $moduleName |
|
287 | - * @return bool TRUE if success, FALSE if failure |
|
288 | - * |
|
289 | - * @access public |
|
290 | - * @author xhelp development team |
|
291 | - */ |
|
292 | - public static function setMeta($key, $value, $moduleName = false) |
|
293 | - { |
|
294 | - if (!$moduleName) { |
|
295 | - $moduleName = static::getCurrentModuleName(); |
|
296 | - } |
|
297 | - $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
298 | - $ret = static::getMeta($key, $moduleName); |
|
299 | - if ('0' === $ret || $ret > 0) { |
|
300 | - $sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key)); |
|
301 | - } else { |
|
302 | - $sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value)); |
|
303 | - } |
|
304 | - $ret = $xoopsDB->queryF($sql); |
|
305 | - if (!$ret) { |
|
306 | - return false; |
|
307 | - } |
|
308 | - |
|
309 | - return true; |
|
310 | - } |
|
311 | - |
|
312 | - // Thanks to Mithrandir:-) |
|
313 | - /** |
|
314 | - * @param $str |
|
315 | - * @param $start |
|
316 | - * @param $length |
|
317 | - * @param string $trimmarker |
|
318 | - * @return string |
|
319 | - */ |
|
320 | - public static function getSubstr($str, $start, $length, $trimmarker = '...') |
|
321 | - { |
|
322 | - // if the string is empty, let's get out ;-) |
|
323 | - if ('' === $str) { |
|
324 | - return $str; |
|
325 | - } |
|
326 | - // reverse a string that is shortened with '' as trimmarker |
|
327 | - $reversed_string = strrev(xoops_substr($str, $start, $length, '')); |
|
328 | - // find first space in reversed string |
|
329 | - $position_of_space = strpos($reversed_string, ' ', 0); |
|
330 | - // truncate the original string to a length of $length |
|
331 | - // minus the position of the last space |
|
332 | - // plus the length of the $trimmarker |
|
333 | - $truncated_string = xoops_substr($str, $start, $length - $position_of_space + strlen($trimmarker), $trimmarker); |
|
334 | - |
|
335 | - return $truncated_string; |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * @param $key |
|
340 | - * @param bool $moduleName |
|
341 | - * @param string $default |
|
342 | - * @return null|string |
|
343 | - */ |
|
344 | - public static function getConfig($key, $moduleName = false, $default = 'default_is_undefined') |
|
345 | - { |
|
346 | - if (!$moduleName) { |
|
347 | - $moduleName = static::getCurrentModuleName(); |
|
348 | - } |
|
349 | - $configs = static::getModuleConfig($moduleName); |
|
350 | - if (isset($configs[$key])) { |
|
351 | - return $configs[$key]; |
|
352 | - } else { |
|
353 | - if ('default_is_undefined' === $default) { |
|
354 | - return null; |
|
355 | - } else { |
|
356 | - return $default; |
|
357 | - } |
|
358 | - } |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Copy a file, or a folder and its contents |
|
363 | - * |
|
364 | - * @author Aidan Lister <[email protected]> |
|
365 | - * @param string $source The source |
|
366 | - * @param string $dest The destination |
|
367 | - * @return bool Returns true on success, false on failure |
|
368 | - */ |
|
369 | - public static function copyr($source, $dest) |
|
370 | - { |
|
371 | - // Simple copy for a file |
|
372 | - if (is_file($source)) { |
|
373 | - return copy($source, $dest); |
|
374 | - } |
|
375 | - // Make destination directory |
|
376 | - if (!is_dir($dest)) { |
|
377 | - mkdir($dest); |
|
378 | - } |
|
379 | - // Loop through the folder |
|
380 | - $dir = dir($source); |
|
381 | - while (false !== $entry = $dir->read()) { |
|
382 | - // Skip pointers |
|
383 | - if ('.' === $entry || '..' === $entry) { |
|
384 | - continue; |
|
385 | - } |
|
386 | - // Deep copy directories |
|
387 | - if (is_dir("$source/$entry") && ("$source/$entry" !== $dest)) { |
|
388 | - static::copyr("$source/$entry", "$dest/$entry"); |
|
389 | - } else { |
|
390 | - copy("$source/$entry", "$dest/$entry"); |
|
391 | - } |
|
392 | - } |
|
393 | - // Clean up |
|
394 | - $dir->close(); |
|
395 | - |
|
396 | - return true; |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * Thanks to the NewBB2 Development Team |
|
401 | - * @param $target |
|
402 | - * @return bool |
|
403 | - */ |
|
404 | - public static function mkdirAsAdmin($target) |
|
405 | - { |
|
406 | - // http://www.php.net/manual/en/function.mkdir.php |
|
407 | - // saint at corenova.com |
|
408 | - // bart at cdasites dot com |
|
409 | - if (is_dir($target) || empty($target)) { |
|
410 | - return true; // best case check first |
|
411 | - } |
|
412 | - if (file_exists($target) && !is_dir($target)) { |
|
413 | - return false; |
|
414 | - } |
|
415 | - if (Smartobject\Utility::mkdirAsAdmin(substr($target, 0, strrpos($target, '/')))) { |
|
416 | - if (!file_exists($target)) { |
|
417 | - $res = mkdir($target, 0777); // crawl back up & create dir tree |
|
418 | - static::chmodAsAdmin($target); |
|
419 | - |
|
420 | - return $res; |
|
421 | - } |
|
422 | - } |
|
423 | - $res = is_dir($target); |
|
424 | - |
|
425 | - return $res; |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Thanks to the NewBB2 Development Team |
|
430 | - * @param $target |
|
431 | - * @param int $mode |
|
432 | - * @return bool |
|
433 | - */ |
|
434 | - public static function chmodAsAdmin($target, $mode = 0777) |
|
435 | - { |
|
436 | - return @ chmod($target, $mode); |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * @param $src |
|
441 | - * @param $maxWidth |
|
442 | - * @param $maxHeight |
|
443 | - * @return array |
|
444 | - */ |
|
445 | - public static function imageResize($src, $maxWidth, $maxHeight) |
|
446 | - { |
|
447 | - $width = ''; |
|
448 | - $height = ''; |
|
449 | - $type = ''; |
|
450 | - $attr = ''; |
|
451 | - if (file_exists($src)) { |
|
452 | - list($width, $height, $type, $attr) = getimagesize($src); |
|
453 | - if ($width > $maxWidth) { |
|
454 | - $originalWidth = $width; |
|
455 | - $width = $maxWidth; |
|
456 | - $height = $width * $height / $originalWidth; |
|
457 | - } |
|
458 | - if ($height > $maxHeight) { |
|
459 | - $originalHeight = $height; |
|
460 | - $height = $maxHeight; |
|
461 | - $width = $height * $width / $originalHeight; |
|
462 | - } |
|
463 | - $attr = " width='$width' height='$height'"; |
|
464 | - } |
|
465 | - |
|
466 | - return [ |
|
467 | - $width, |
|
468 | - $height, |
|
469 | - $type, |
|
470 | - $attr |
|
471 | - ]; |
|
472 | - } |
|
473 | - |
|
474 | - /** |
|
475 | - * @param bool $moduleName |
|
476 | - * @return mixed |
|
477 | - */ |
|
478 | - public static function getModuleInfo($moduleName = false) |
|
479 | - { |
|
480 | - static $smartModules; |
|
481 | - if (isset($smartModules[$moduleName])) { |
|
482 | - $ret =& $smartModules[$moduleName]; |
|
483 | - |
|
484 | - return $ret; |
|
485 | - } |
|
486 | - global $xoopsModule; |
|
487 | - if (!$moduleName) { |
|
488 | - if (isset($xoopsModule) && is_object($xoopsModule)) { |
|
489 | - $smartModules[$xoopsModule->getVar('dirname')] = $xoopsModule; |
|
490 | - |
|
491 | - return $smartModules[$xoopsModule->getVar('dirname')]; |
|
492 | - } |
|
493 | - } |
|
494 | - if (!isset($smartModules[$moduleName])) { |
|
495 | - if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) { |
|
496 | - $smartModules[$moduleName] = $xoopsModule; |
|
497 | - } else { |
|
498 | - $hModule = xoops_getHandler('module'); |
|
499 | - if ('xoops' !== $moduleName) { |
|
500 | - $smartModules[$moduleName] = $hModule->getByDirname($moduleName); |
|
501 | - } else { |
|
502 | - $smartModules[$moduleName] = $hModule->getByDirname('system'); |
|
503 | - } |
|
504 | - } |
|
505 | - } |
|
506 | - |
|
507 | - return $smartModules[$moduleName]; |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * @param bool $moduleName |
|
512 | - * @return bool |
|
513 | - */ |
|
514 | - public static function getModuleConfig($moduleName = false) |
|
515 | - { |
|
516 | - static $smartConfigs; |
|
517 | - if (isset($smartConfigs[$moduleName])) { |
|
518 | - $ret =& $smartConfigs[$moduleName]; |
|
519 | - |
|
520 | - return $ret; |
|
521 | - } |
|
522 | - global $xoopsModule, $xoopsModuleConfig; |
|
523 | - if (!$moduleName) { |
|
524 | - if (isset($xoopsModule) && is_object($xoopsModule)) { |
|
525 | - $smartConfigs[$xoopsModule->getVar('dirname')] = $xoopsModuleConfig; |
|
526 | - |
|
527 | - return $smartConfigs[$xoopsModule->getVar('dirname')]; |
|
528 | - } |
|
529 | - } |
|
530 | - // if we still did not found the xoopsModule, this is because there is none |
|
531 | - if (!$moduleName) { |
|
532 | - $ret = false; |
|
533 | - |
|
534 | - return $ret; |
|
535 | - } |
|
536 | - if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) { |
|
537 | - $smartConfigs[$moduleName] = $xoopsModuleConfig; |
|
538 | - } else { |
|
539 | - $module = static::getModuleInfo($moduleName); |
|
540 | - if (!is_object($module)) { |
|
541 | - $ret = false; |
|
542 | - |
|
543 | - return $ret; |
|
544 | - } |
|
545 | - $hModConfig = xoops_getHandler('config'); |
|
546 | - $smartConfigs[$moduleName] =& $hModConfig->getConfigsByCat(0, $module->getVar('mid')); |
|
547 | - } |
|
548 | - |
|
549 | - return $smartConfigs[$moduleName]; |
|
550 | - } |
|
551 | - |
|
552 | - /** |
|
553 | - * @param $dirname |
|
554 | - * @return bool |
|
555 | - */ |
|
556 | - public static function deleteFile($dirname) |
|
557 | - { |
|
558 | - // Simple delete for a file |
|
559 | - if (is_file($dirname)) { |
|
560 | - return unlink($dirname); |
|
561 | - } |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * @param array $errors |
|
566 | - * @return string |
|
567 | - */ |
|
568 | - public static function formatErrors($errors = []) |
|
569 | - { |
|
570 | - $ret = ''; |
|
571 | - foreach ($errors as $key => $value) { |
|
572 | - $ret .= '<br> - ' . $value; |
|
573 | - } |
|
574 | - |
|
575 | - return $ret; |
|
576 | - } |
|
577 | - |
|
578 | - /** |
|
579 | - * getLinkedUnameFromId() |
|
580 | - * |
|
581 | - * @param integer $userid Userid of poster etc |
|
582 | - * @param integer $name : 0 Use Usenamer 1 Use realname |
|
583 | - * @param array $users |
|
584 | - * @param bool $withContact |
|
585 | - * @return string |
|
586 | - */ |
|
587 | - public static function getLinkedUnameFromId($userid = 0, $name = 0, $users = [], $withContact = false) |
|
588 | - { |
|
589 | - if (!is_numeric($userid)) { |
|
590 | - return $userid; |
|
591 | - } |
|
592 | - $userid = (int)$userid; |
|
593 | - if ($userid > 0) { |
|
594 | - if ($users == []) { |
|
595 | - //fetching users |
|
596 | - $memberHandler = xoops_getHandler('member'); |
|
597 | - $user =& $memberHandler->getUser($userid); |
|
598 | - } else { |
|
599 | - if (!isset($users[$userid])) { |
|
600 | - return $GLOBALS['xoopsConfig']['anonymous']; |
|
601 | - } |
|
602 | - $user =& $users[$userid]; |
|
603 | - } |
|
604 | - if (is_object($user)) { |
|
605 | - $ts = \MyTextSanitizer:: getInstance(); |
|
606 | - $username = $user->getVar('uname'); |
|
607 | - $fullname = ''; |
|
608 | - $fullname2 = $user->getVar('name'); |
|
609 | - if ($name && !empty($fullname2)) { |
|
610 | - $fullname = $user->getVar('name'); |
|
611 | - } |
|
612 | - if (!empty($fullname)) { |
|
613 | - $linkeduser = "$fullname [<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . $ts->htmlSpecialChars($username) . '</a>]'; |
|
614 | - } else { |
|
615 | - $linkeduser = "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . ucwords($ts->htmlSpecialChars($username)) . '</a>'; |
|
616 | - } |
|
617 | - // add contact info: email + PM |
|
618 | - if ($withContact) { |
|
619 | - $linkeduser .= ' <a href="mailto:' . $user->getVar('email') . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/email.gif' . '" alt="' . _CO_SOBJECT_SEND_EMAIL . '" title="' . _CO_SOBJECT_SEND_EMAIL . '"></a>'; |
|
620 | - $js = "javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $userid . "', 'pmlite',450,370);"; |
|
621 | - $linkeduser .= ' <a href="' . $js . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/pm.gif' . '" alt="' . _CO_SOBJECT_SEND_PM . '" title="' . _CO_SOBJECT_SEND_PM . '"></a>'; |
|
622 | - } |
|
623 | - |
|
624 | - return $linkeduser; |
|
625 | - } |
|
626 | - } |
|
627 | - |
|
628 | - return $GLOBALS['xoopsConfig']['anonymous']; |
|
629 | - } |
|
630 | - |
|
631 | - /** |
|
632 | - * @param int $currentoption |
|
633 | - * @param string $breadcrumb |
|
634 | - * @param bool $submenus |
|
635 | - * @param int $currentsub |
|
636 | - */ |
|
637 | - public static function getAdminMenu($currentoption = 0, $breadcrumb = '', $submenus = false, $currentsub = -1) |
|
638 | - { |
|
639 | - global $xoopsModule, $xoopsConfig; |
|
640 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
641 | - |
|
642 | - |
|
643 | - /** @var Smartobject\Helper $helper */ |
|
644 | - $helper = Smartobject\Helper::getInstance(); |
|
645 | - $helper->loadLanguage('admin'); |
|
646 | - $helper->loadLanguage('modinfo'); |
|
647 | - $headermenu = []; |
|
648 | - $adminObject = []; |
|
649 | - include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/menu.php'; |
|
650 | - $tpl = new \XoopsTpl(); |
|
651 | - $tpl->assign([ |
|
652 | - 'headermenu' => $headermenu, |
|
653 | - 'adminmenu' => $adminObject, |
|
654 | - 'current' => $currentoption, |
|
655 | - 'breadcrumb' => $breadcrumb, |
|
656 | - 'headermenucount' => count($headermenu), |
|
657 | - 'submenus' => $submenus, |
|
658 | - 'currentsub' => $currentsub, |
|
659 | - 'submenuscount' => count($submenus) |
|
660 | - ]); |
|
661 | - $tpl->display('db:smartobject_admin_menu.tpl'); |
|
662 | - } |
|
663 | - |
|
664 | - /** |
|
665 | - * @param string $id |
|
666 | - * @param string $title |
|
667 | - * @param string $dsc |
|
668 | - */ |
|
669 | - public static function getCollapsableBar($id = '', $title = '', $dsc = '') |
|
670 | - { |
|
671 | - global $xoopsModule; |
|
672 | - echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"togglecollapse('" . $id . "'); toggleIcon('" . $id . "_icon')\";>"; |
|
673 | - echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a> " . $title . '</h3>'; |
|
674 | - echo "<div id='" . $id . "'>"; |
|
675 | - if ('' !== $dsc) { |
|
676 | - echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . $dsc . '</span>'; |
|
677 | - } |
|
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * @param string $id |
|
682 | - * @param string $title |
|
683 | - * @param string $dsc |
|
684 | - */ |
|
685 | - public static function getAjaxCollapsableBar($id = '', $title = '', $dsc = '') |
|
686 | - { |
|
687 | - global $xoopsModule; |
|
688 | - $onClick = "ajaxtogglecollapse('$id')"; |
|
689 | - //$onClick = "togglecollapse('$id'); toggleIcon('" . $id . "_icon')"; |
|
690 | - echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="' . $onClick . '">'; |
|
691 | - echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a> " . $title . '</h3>'; |
|
692 | - echo "<div id='" . $id . "'>"; |
|
693 | - if ('' !== $dsc) { |
|
694 | - echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . $dsc . '</span>'; |
|
695 | - } |
|
696 | - } |
|
697 | - |
|
698 | - /** |
|
699 | - * Ajax testing...... |
|
700 | - * @param $name |
|
701 | - */ |
|
702 | - /* |
|
205 | + /** |
|
206 | + * Include the admin language constants for the SmartObject Framework |
|
207 | + */ |
|
208 | + /** @var Smartobject\Helper $helper */ |
|
209 | + $helper = Smartobject\Helper::getInstance(); |
|
210 | + $helper->loadLanguage('admin'); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Detemines if a table exists in the current db |
|
215 | + * |
|
216 | + * @param string $table the table name (without XOOPS prefix) |
|
217 | + * @return bool True if table exists, false if not |
|
218 | + * |
|
219 | + * @access public |
|
220 | + * @author xhelp development team |
|
221 | + */ |
|
222 | + public static function isTable($table) |
|
223 | + { |
|
224 | + $bRetVal = false; |
|
225 | + //Verifies that a MySQL table exists |
|
226 | + $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
227 | + $realname = $xoopsDB->prefix($table); |
|
228 | + $sql = 'SHOW TABLES FROM ' . XOOPS_DB_NAME; |
|
229 | + $ret = $xoopsDB->queryF($sql); |
|
230 | + while (false !== (list($m_table) = $xoopsDB->fetchRow($ret))) { |
|
231 | + if ($m_table == $realname) { |
|
232 | + $bRetVal = true; |
|
233 | + break; |
|
234 | + } |
|
235 | + } |
|
236 | + $xoopsDB->freeRecordSet($ret); |
|
237 | + |
|
238 | + return $bRetVal; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Gets a value from a key in the xhelp_meta table |
|
243 | + * |
|
244 | + * @param string $key |
|
245 | + * @param bool $moduleName |
|
246 | + * @return string $value |
|
247 | + * |
|
248 | + * @access public |
|
249 | + * @author xhelp development team |
|
250 | + */ |
|
251 | + public static function getMeta($key, $moduleName = false) |
|
252 | + { |
|
253 | + if (!$moduleName) { |
|
254 | + $moduleName = static::getCurrentModuleName(); |
|
255 | + } |
|
256 | + $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
257 | + $sql = sprintf('SELECT metavalue FROM `%s` WHERE metakey=%s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key)); |
|
258 | + $ret = $xoopsDB->query($sql); |
|
259 | + if (!$ret) { |
|
260 | + $value = false; |
|
261 | + } else { |
|
262 | + list($value) = $xoopsDB->fetchRow($ret); |
|
263 | + } |
|
264 | + |
|
265 | + return $value; |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * @return bool |
|
270 | + */ |
|
271 | + public static function getCurrentModuleName() |
|
272 | + { |
|
273 | + global $xoopsModule; |
|
274 | + if (is_object($xoopsModule)) { |
|
275 | + return $xoopsModule->getVar('dirname'); |
|
276 | + } else { |
|
277 | + return false; |
|
278 | + } |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Sets a value for a key in the xhelp_meta table |
|
283 | + * |
|
284 | + * @param string $key |
|
285 | + * @param string $value |
|
286 | + * @param bool $moduleName |
|
287 | + * @return bool TRUE if success, FALSE if failure |
|
288 | + * |
|
289 | + * @access public |
|
290 | + * @author xhelp development team |
|
291 | + */ |
|
292 | + public static function setMeta($key, $value, $moduleName = false) |
|
293 | + { |
|
294 | + if (!$moduleName) { |
|
295 | + $moduleName = static::getCurrentModuleName(); |
|
296 | + } |
|
297 | + $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
298 | + $ret = static::getMeta($key, $moduleName); |
|
299 | + if ('0' === $ret || $ret > 0) { |
|
300 | + $sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key)); |
|
301 | + } else { |
|
302 | + $sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value)); |
|
303 | + } |
|
304 | + $ret = $xoopsDB->queryF($sql); |
|
305 | + if (!$ret) { |
|
306 | + return false; |
|
307 | + } |
|
308 | + |
|
309 | + return true; |
|
310 | + } |
|
311 | + |
|
312 | + // Thanks to Mithrandir:-) |
|
313 | + /** |
|
314 | + * @param $str |
|
315 | + * @param $start |
|
316 | + * @param $length |
|
317 | + * @param string $trimmarker |
|
318 | + * @return string |
|
319 | + */ |
|
320 | + public static function getSubstr($str, $start, $length, $trimmarker = '...') |
|
321 | + { |
|
322 | + // if the string is empty, let's get out ;-) |
|
323 | + if ('' === $str) { |
|
324 | + return $str; |
|
325 | + } |
|
326 | + // reverse a string that is shortened with '' as trimmarker |
|
327 | + $reversed_string = strrev(xoops_substr($str, $start, $length, '')); |
|
328 | + // find first space in reversed string |
|
329 | + $position_of_space = strpos($reversed_string, ' ', 0); |
|
330 | + // truncate the original string to a length of $length |
|
331 | + // minus the position of the last space |
|
332 | + // plus the length of the $trimmarker |
|
333 | + $truncated_string = xoops_substr($str, $start, $length - $position_of_space + strlen($trimmarker), $trimmarker); |
|
334 | + |
|
335 | + return $truncated_string; |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * @param $key |
|
340 | + * @param bool $moduleName |
|
341 | + * @param string $default |
|
342 | + * @return null|string |
|
343 | + */ |
|
344 | + public static function getConfig($key, $moduleName = false, $default = 'default_is_undefined') |
|
345 | + { |
|
346 | + if (!$moduleName) { |
|
347 | + $moduleName = static::getCurrentModuleName(); |
|
348 | + } |
|
349 | + $configs = static::getModuleConfig($moduleName); |
|
350 | + if (isset($configs[$key])) { |
|
351 | + return $configs[$key]; |
|
352 | + } else { |
|
353 | + if ('default_is_undefined' === $default) { |
|
354 | + return null; |
|
355 | + } else { |
|
356 | + return $default; |
|
357 | + } |
|
358 | + } |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Copy a file, or a folder and its contents |
|
363 | + * |
|
364 | + * @author Aidan Lister <[email protected]> |
|
365 | + * @param string $source The source |
|
366 | + * @param string $dest The destination |
|
367 | + * @return bool Returns true on success, false on failure |
|
368 | + */ |
|
369 | + public static function copyr($source, $dest) |
|
370 | + { |
|
371 | + // Simple copy for a file |
|
372 | + if (is_file($source)) { |
|
373 | + return copy($source, $dest); |
|
374 | + } |
|
375 | + // Make destination directory |
|
376 | + if (!is_dir($dest)) { |
|
377 | + mkdir($dest); |
|
378 | + } |
|
379 | + // Loop through the folder |
|
380 | + $dir = dir($source); |
|
381 | + while (false !== $entry = $dir->read()) { |
|
382 | + // Skip pointers |
|
383 | + if ('.' === $entry || '..' === $entry) { |
|
384 | + continue; |
|
385 | + } |
|
386 | + // Deep copy directories |
|
387 | + if (is_dir("$source/$entry") && ("$source/$entry" !== $dest)) { |
|
388 | + static::copyr("$source/$entry", "$dest/$entry"); |
|
389 | + } else { |
|
390 | + copy("$source/$entry", "$dest/$entry"); |
|
391 | + } |
|
392 | + } |
|
393 | + // Clean up |
|
394 | + $dir->close(); |
|
395 | + |
|
396 | + return true; |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * Thanks to the NewBB2 Development Team |
|
401 | + * @param $target |
|
402 | + * @return bool |
|
403 | + */ |
|
404 | + public static function mkdirAsAdmin($target) |
|
405 | + { |
|
406 | + // http://www.php.net/manual/en/function.mkdir.php |
|
407 | + // saint at corenova.com |
|
408 | + // bart at cdasites dot com |
|
409 | + if (is_dir($target) || empty($target)) { |
|
410 | + return true; // best case check first |
|
411 | + } |
|
412 | + if (file_exists($target) && !is_dir($target)) { |
|
413 | + return false; |
|
414 | + } |
|
415 | + if (Smartobject\Utility::mkdirAsAdmin(substr($target, 0, strrpos($target, '/')))) { |
|
416 | + if (!file_exists($target)) { |
|
417 | + $res = mkdir($target, 0777); // crawl back up & create dir tree |
|
418 | + static::chmodAsAdmin($target); |
|
419 | + |
|
420 | + return $res; |
|
421 | + } |
|
422 | + } |
|
423 | + $res = is_dir($target); |
|
424 | + |
|
425 | + return $res; |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Thanks to the NewBB2 Development Team |
|
430 | + * @param $target |
|
431 | + * @param int $mode |
|
432 | + * @return bool |
|
433 | + */ |
|
434 | + public static function chmodAsAdmin($target, $mode = 0777) |
|
435 | + { |
|
436 | + return @ chmod($target, $mode); |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * @param $src |
|
441 | + * @param $maxWidth |
|
442 | + * @param $maxHeight |
|
443 | + * @return array |
|
444 | + */ |
|
445 | + public static function imageResize($src, $maxWidth, $maxHeight) |
|
446 | + { |
|
447 | + $width = ''; |
|
448 | + $height = ''; |
|
449 | + $type = ''; |
|
450 | + $attr = ''; |
|
451 | + if (file_exists($src)) { |
|
452 | + list($width, $height, $type, $attr) = getimagesize($src); |
|
453 | + if ($width > $maxWidth) { |
|
454 | + $originalWidth = $width; |
|
455 | + $width = $maxWidth; |
|
456 | + $height = $width * $height / $originalWidth; |
|
457 | + } |
|
458 | + if ($height > $maxHeight) { |
|
459 | + $originalHeight = $height; |
|
460 | + $height = $maxHeight; |
|
461 | + $width = $height * $width / $originalHeight; |
|
462 | + } |
|
463 | + $attr = " width='$width' height='$height'"; |
|
464 | + } |
|
465 | + |
|
466 | + return [ |
|
467 | + $width, |
|
468 | + $height, |
|
469 | + $type, |
|
470 | + $attr |
|
471 | + ]; |
|
472 | + } |
|
473 | + |
|
474 | + /** |
|
475 | + * @param bool $moduleName |
|
476 | + * @return mixed |
|
477 | + */ |
|
478 | + public static function getModuleInfo($moduleName = false) |
|
479 | + { |
|
480 | + static $smartModules; |
|
481 | + if (isset($smartModules[$moduleName])) { |
|
482 | + $ret =& $smartModules[$moduleName]; |
|
483 | + |
|
484 | + return $ret; |
|
485 | + } |
|
486 | + global $xoopsModule; |
|
487 | + if (!$moduleName) { |
|
488 | + if (isset($xoopsModule) && is_object($xoopsModule)) { |
|
489 | + $smartModules[$xoopsModule->getVar('dirname')] = $xoopsModule; |
|
490 | + |
|
491 | + return $smartModules[$xoopsModule->getVar('dirname')]; |
|
492 | + } |
|
493 | + } |
|
494 | + if (!isset($smartModules[$moduleName])) { |
|
495 | + if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) { |
|
496 | + $smartModules[$moduleName] = $xoopsModule; |
|
497 | + } else { |
|
498 | + $hModule = xoops_getHandler('module'); |
|
499 | + if ('xoops' !== $moduleName) { |
|
500 | + $smartModules[$moduleName] = $hModule->getByDirname($moduleName); |
|
501 | + } else { |
|
502 | + $smartModules[$moduleName] = $hModule->getByDirname('system'); |
|
503 | + } |
|
504 | + } |
|
505 | + } |
|
506 | + |
|
507 | + return $smartModules[$moduleName]; |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * @param bool $moduleName |
|
512 | + * @return bool |
|
513 | + */ |
|
514 | + public static function getModuleConfig($moduleName = false) |
|
515 | + { |
|
516 | + static $smartConfigs; |
|
517 | + if (isset($smartConfigs[$moduleName])) { |
|
518 | + $ret =& $smartConfigs[$moduleName]; |
|
519 | + |
|
520 | + return $ret; |
|
521 | + } |
|
522 | + global $xoopsModule, $xoopsModuleConfig; |
|
523 | + if (!$moduleName) { |
|
524 | + if (isset($xoopsModule) && is_object($xoopsModule)) { |
|
525 | + $smartConfigs[$xoopsModule->getVar('dirname')] = $xoopsModuleConfig; |
|
526 | + |
|
527 | + return $smartConfigs[$xoopsModule->getVar('dirname')]; |
|
528 | + } |
|
529 | + } |
|
530 | + // if we still did not found the xoopsModule, this is because there is none |
|
531 | + if (!$moduleName) { |
|
532 | + $ret = false; |
|
533 | + |
|
534 | + return $ret; |
|
535 | + } |
|
536 | + if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) { |
|
537 | + $smartConfigs[$moduleName] = $xoopsModuleConfig; |
|
538 | + } else { |
|
539 | + $module = static::getModuleInfo($moduleName); |
|
540 | + if (!is_object($module)) { |
|
541 | + $ret = false; |
|
542 | + |
|
543 | + return $ret; |
|
544 | + } |
|
545 | + $hModConfig = xoops_getHandler('config'); |
|
546 | + $smartConfigs[$moduleName] =& $hModConfig->getConfigsByCat(0, $module->getVar('mid')); |
|
547 | + } |
|
548 | + |
|
549 | + return $smartConfigs[$moduleName]; |
|
550 | + } |
|
551 | + |
|
552 | + /** |
|
553 | + * @param $dirname |
|
554 | + * @return bool |
|
555 | + */ |
|
556 | + public static function deleteFile($dirname) |
|
557 | + { |
|
558 | + // Simple delete for a file |
|
559 | + if (is_file($dirname)) { |
|
560 | + return unlink($dirname); |
|
561 | + } |
|
562 | + } |
|
563 | + |
|
564 | + /** |
|
565 | + * @param array $errors |
|
566 | + * @return string |
|
567 | + */ |
|
568 | + public static function formatErrors($errors = []) |
|
569 | + { |
|
570 | + $ret = ''; |
|
571 | + foreach ($errors as $key => $value) { |
|
572 | + $ret .= '<br> - ' . $value; |
|
573 | + } |
|
574 | + |
|
575 | + return $ret; |
|
576 | + } |
|
577 | + |
|
578 | + /** |
|
579 | + * getLinkedUnameFromId() |
|
580 | + * |
|
581 | + * @param integer $userid Userid of poster etc |
|
582 | + * @param integer $name : 0 Use Usenamer 1 Use realname |
|
583 | + * @param array $users |
|
584 | + * @param bool $withContact |
|
585 | + * @return string |
|
586 | + */ |
|
587 | + public static function getLinkedUnameFromId($userid = 0, $name = 0, $users = [], $withContact = false) |
|
588 | + { |
|
589 | + if (!is_numeric($userid)) { |
|
590 | + return $userid; |
|
591 | + } |
|
592 | + $userid = (int)$userid; |
|
593 | + if ($userid > 0) { |
|
594 | + if ($users == []) { |
|
595 | + //fetching users |
|
596 | + $memberHandler = xoops_getHandler('member'); |
|
597 | + $user =& $memberHandler->getUser($userid); |
|
598 | + } else { |
|
599 | + if (!isset($users[$userid])) { |
|
600 | + return $GLOBALS['xoopsConfig']['anonymous']; |
|
601 | + } |
|
602 | + $user =& $users[$userid]; |
|
603 | + } |
|
604 | + if (is_object($user)) { |
|
605 | + $ts = \MyTextSanitizer:: getInstance(); |
|
606 | + $username = $user->getVar('uname'); |
|
607 | + $fullname = ''; |
|
608 | + $fullname2 = $user->getVar('name'); |
|
609 | + if ($name && !empty($fullname2)) { |
|
610 | + $fullname = $user->getVar('name'); |
|
611 | + } |
|
612 | + if (!empty($fullname)) { |
|
613 | + $linkeduser = "$fullname [<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . $ts->htmlSpecialChars($username) . '</a>]'; |
|
614 | + } else { |
|
615 | + $linkeduser = "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . ucwords($ts->htmlSpecialChars($username)) . '</a>'; |
|
616 | + } |
|
617 | + // add contact info: email + PM |
|
618 | + if ($withContact) { |
|
619 | + $linkeduser .= ' <a href="mailto:' . $user->getVar('email') . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/email.gif' . '" alt="' . _CO_SOBJECT_SEND_EMAIL . '" title="' . _CO_SOBJECT_SEND_EMAIL . '"></a>'; |
|
620 | + $js = "javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $userid . "', 'pmlite',450,370);"; |
|
621 | + $linkeduser .= ' <a href="' . $js . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/pm.gif' . '" alt="' . _CO_SOBJECT_SEND_PM . '" title="' . _CO_SOBJECT_SEND_PM . '"></a>'; |
|
622 | + } |
|
623 | + |
|
624 | + return $linkeduser; |
|
625 | + } |
|
626 | + } |
|
627 | + |
|
628 | + return $GLOBALS['xoopsConfig']['anonymous']; |
|
629 | + } |
|
630 | + |
|
631 | + /** |
|
632 | + * @param int $currentoption |
|
633 | + * @param string $breadcrumb |
|
634 | + * @param bool $submenus |
|
635 | + * @param int $currentsub |
|
636 | + */ |
|
637 | + public static function getAdminMenu($currentoption = 0, $breadcrumb = '', $submenus = false, $currentsub = -1) |
|
638 | + { |
|
639 | + global $xoopsModule, $xoopsConfig; |
|
640 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
641 | + |
|
642 | + |
|
643 | + /** @var Smartobject\Helper $helper */ |
|
644 | + $helper = Smartobject\Helper::getInstance(); |
|
645 | + $helper->loadLanguage('admin'); |
|
646 | + $helper->loadLanguage('modinfo'); |
|
647 | + $headermenu = []; |
|
648 | + $adminObject = []; |
|
649 | + include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/menu.php'; |
|
650 | + $tpl = new \XoopsTpl(); |
|
651 | + $tpl->assign([ |
|
652 | + 'headermenu' => $headermenu, |
|
653 | + 'adminmenu' => $adminObject, |
|
654 | + 'current' => $currentoption, |
|
655 | + 'breadcrumb' => $breadcrumb, |
|
656 | + 'headermenucount' => count($headermenu), |
|
657 | + 'submenus' => $submenus, |
|
658 | + 'currentsub' => $currentsub, |
|
659 | + 'submenuscount' => count($submenus) |
|
660 | + ]); |
|
661 | + $tpl->display('db:smartobject_admin_menu.tpl'); |
|
662 | + } |
|
663 | + |
|
664 | + /** |
|
665 | + * @param string $id |
|
666 | + * @param string $title |
|
667 | + * @param string $dsc |
|
668 | + */ |
|
669 | + public static function getCollapsableBar($id = '', $title = '', $dsc = '') |
|
670 | + { |
|
671 | + global $xoopsModule; |
|
672 | + echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"togglecollapse('" . $id . "'); toggleIcon('" . $id . "_icon')\";>"; |
|
673 | + echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a> " . $title . '</h3>'; |
|
674 | + echo "<div id='" . $id . "'>"; |
|
675 | + if ('' !== $dsc) { |
|
676 | + echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . $dsc . '</span>'; |
|
677 | + } |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * @param string $id |
|
682 | + * @param string $title |
|
683 | + * @param string $dsc |
|
684 | + */ |
|
685 | + public static function getAjaxCollapsableBar($id = '', $title = '', $dsc = '') |
|
686 | + { |
|
687 | + global $xoopsModule; |
|
688 | + $onClick = "ajaxtogglecollapse('$id')"; |
|
689 | + //$onClick = "togglecollapse('$id'); toggleIcon('" . $id . "_icon')"; |
|
690 | + echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="' . $onClick . '">'; |
|
691 | + echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a> " . $title . '</h3>'; |
|
692 | + echo "<div id='" . $id . "'>"; |
|
693 | + if ('' !== $dsc) { |
|
694 | + echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . $dsc . '</span>'; |
|
695 | + } |
|
696 | + } |
|
697 | + |
|
698 | + /** |
|
699 | + * Ajax testing...... |
|
700 | + * @param $name |
|
701 | + */ |
|
702 | + /* |
|
703 | 703 | public static function getCollapsableBar($id = '', $title = '', $dsc='') |
704 | 704 | { |
705 | 705 | |
@@ -717,22 +717,22 @@ discard block |
||
717 | 717 | } |
718 | 718 | } |
719 | 719 | */ |
720 | - public static function opencloseCollapsable($name) |
|
721 | - { |
|
722 | - $urls = static::getCurrentUrls(); |
|
723 | - $path = $urls['phpself']; |
|
724 | - $cookie_name = $path . '_smart_collaps_' . $name; |
|
725 | - $cookie_name = str_replace('.', '_', $cookie_name); |
|
726 | - $cookie = static::getCookieVar($cookie_name, ''); |
|
727 | - if ('none' === $cookie) { |
|
728 | - echo ' |
|
720 | + public static function opencloseCollapsable($name) |
|
721 | + { |
|
722 | + $urls = static::getCurrentUrls(); |
|
723 | + $path = $urls['phpself']; |
|
724 | + $cookie_name = $path . '_smart_collaps_' . $name; |
|
725 | + $cookie_name = str_replace('.', '_', $cookie_name); |
|
726 | + $cookie = static::getCookieVar($cookie_name, ''); |
|
727 | + if ('none' === $cookie) { |
|
728 | + echo ' |
|
729 | 729 | <script type="text/javascript"><!-- |
730 | 730 | togglecollapse("' . $name . '"); toggleIcon("' . $name . '_icon"); |
731 | 731 | //--> |
732 | 732 | </script> |
733 | 733 | '; |
734 | - } |
|
735 | - /* if ($cookie == 'none') { |
|
734 | + } |
|
735 | + /* if ($cookie == 'none') { |
|
736 | 736 | echo ' |
737 | 737 | <script type="text/javascript"><!-- |
738 | 738 | hideElement("' . $name . '"); |
@@ -741,96 +741,96 @@ discard block |
||
741 | 741 | '; |
742 | 742 | } |
743 | 743 | */ |
744 | - } |
|
745 | - |
|
746 | - /** |
|
747 | - * @param $name |
|
748 | - */ |
|
749 | - public static function closeCollapsable($name) |
|
750 | - { |
|
751 | - echo '</div>'; |
|
752 | - static::opencloseCollapsable($name); |
|
753 | - echo '<br>'; |
|
754 | - } |
|
755 | - |
|
756 | - /** |
|
757 | - * @param $name |
|
758 | - * @param $value |
|
759 | - * @param int $time |
|
760 | - */ |
|
761 | - public static function setCookieVar($name, $value, $time = 0) |
|
762 | - { |
|
763 | - if (0 == $time) { |
|
764 | - $time = time() + 3600 * 24 * 365; |
|
765 | - //$time = ''; |
|
766 | - } |
|
767 | - setcookie($name, $value, $time, '/'); |
|
768 | - } |
|
769 | - |
|
770 | - /** |
|
771 | - * @param $name |
|
772 | - * @param string $default |
|
773 | - * @return string |
|
774 | - */ |
|
775 | - public static function getCookieVar($name, $default = '') |
|
776 | - { |
|
777 | - $name = str_replace('.', '_', $name); |
|
778 | - if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) { |
|
779 | - return $_COOKIE[$name]; |
|
780 | - } else { |
|
781 | - return $default; |
|
782 | - } |
|
783 | - } |
|
784 | - |
|
785 | - /** |
|
786 | - * @return array |
|
787 | - */ |
|
788 | - public static function getCurrentUrls() |
|
789 | - { |
|
790 | - $urls = []; |
|
791 | - $http = (false === strpos(XOOPS_URL, 'https://')) ? 'http://' : 'https://'; |
|
792 | - $phpself = $_SERVER['PHP_SELF']; |
|
793 | - $httphost = $_SERVER['HTTP_HOST']; |
|
794 | - $querystring = $_SERVER['QUERY_STRING']; |
|
795 | - if ('' !== $querystring) { |
|
796 | - $querystring = '?' . $querystring; |
|
797 | - } |
|
798 | - $currenturl = $http . $httphost . $phpself . $querystring; |
|
799 | - $urls = []; |
|
800 | - $urls['http'] = $http; |
|
801 | - $urls['httphost'] = $httphost; |
|
802 | - $urls['phpself'] = $phpself; |
|
803 | - $urls['querystring'] = $querystring; |
|
804 | - $urls['full_phpself'] = $http . $httphost . $phpself; |
|
805 | - $urls['full'] = $currenturl; |
|
806 | - $urls['isHomePage'] = (XOOPS_URL . '/index.php') == ($http . $httphost . $phpself); |
|
807 | - |
|
808 | - return $urls; |
|
809 | - } |
|
810 | - |
|
811 | - /** |
|
812 | - * @return mixed |
|
813 | - */ |
|
814 | - public static function getCurrentPage() |
|
815 | - { |
|
816 | - $urls = static::getCurrentUrls(); |
|
817 | - |
|
818 | - return $urls['full']; |
|
819 | - } |
|
820 | - |
|
821 | - /** |
|
822 | - * Create a title for the short_url field of an article |
|
823 | - * |
|
824 | - * @credit psylove |
|
825 | - * |
|
826 | - * @var string $title title of the article |
|
827 | - * @var string $withExt do we add an html extension or not |
|
828 | - * @return string sort_url for the article |
|
829 | - */ |
|
830 | - /** |
|
831 | - * Moved in SmartMetaGenClass |
|
832 | - */ |
|
833 | - /* |
|
744 | + } |
|
745 | + |
|
746 | + /** |
|
747 | + * @param $name |
|
748 | + */ |
|
749 | + public static function closeCollapsable($name) |
|
750 | + { |
|
751 | + echo '</div>'; |
|
752 | + static::opencloseCollapsable($name); |
|
753 | + echo '<br>'; |
|
754 | + } |
|
755 | + |
|
756 | + /** |
|
757 | + * @param $name |
|
758 | + * @param $value |
|
759 | + * @param int $time |
|
760 | + */ |
|
761 | + public static function setCookieVar($name, $value, $time = 0) |
|
762 | + { |
|
763 | + if (0 == $time) { |
|
764 | + $time = time() + 3600 * 24 * 365; |
|
765 | + //$time = ''; |
|
766 | + } |
|
767 | + setcookie($name, $value, $time, '/'); |
|
768 | + } |
|
769 | + |
|
770 | + /** |
|
771 | + * @param $name |
|
772 | + * @param string $default |
|
773 | + * @return string |
|
774 | + */ |
|
775 | + public static function getCookieVar($name, $default = '') |
|
776 | + { |
|
777 | + $name = str_replace('.', '_', $name); |
|
778 | + if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) { |
|
779 | + return $_COOKIE[$name]; |
|
780 | + } else { |
|
781 | + return $default; |
|
782 | + } |
|
783 | + } |
|
784 | + |
|
785 | + /** |
|
786 | + * @return array |
|
787 | + */ |
|
788 | + public static function getCurrentUrls() |
|
789 | + { |
|
790 | + $urls = []; |
|
791 | + $http = (false === strpos(XOOPS_URL, 'https://')) ? 'http://' : 'https://'; |
|
792 | + $phpself = $_SERVER['PHP_SELF']; |
|
793 | + $httphost = $_SERVER['HTTP_HOST']; |
|
794 | + $querystring = $_SERVER['QUERY_STRING']; |
|
795 | + if ('' !== $querystring) { |
|
796 | + $querystring = '?' . $querystring; |
|
797 | + } |
|
798 | + $currenturl = $http . $httphost . $phpself . $querystring; |
|
799 | + $urls = []; |
|
800 | + $urls['http'] = $http; |
|
801 | + $urls['httphost'] = $httphost; |
|
802 | + $urls['phpself'] = $phpself; |
|
803 | + $urls['querystring'] = $querystring; |
|
804 | + $urls['full_phpself'] = $http . $httphost . $phpself; |
|
805 | + $urls['full'] = $currenturl; |
|
806 | + $urls['isHomePage'] = (XOOPS_URL . '/index.php') == ($http . $httphost . $phpself); |
|
807 | + |
|
808 | + return $urls; |
|
809 | + } |
|
810 | + |
|
811 | + /** |
|
812 | + * @return mixed |
|
813 | + */ |
|
814 | + public static function getCurrentPage() |
|
815 | + { |
|
816 | + $urls = static::getCurrentUrls(); |
|
817 | + |
|
818 | + return $urls['full']; |
|
819 | + } |
|
820 | + |
|
821 | + /** |
|
822 | + * Create a title for the short_url field of an article |
|
823 | + * |
|
824 | + * @credit psylove |
|
825 | + * |
|
826 | + * @var string $title title of the article |
|
827 | + * @var string $withExt do we add an html extension or not |
|
828 | + * @return string sort_url for the article |
|
829 | + */ |
|
830 | + /** |
|
831 | + * Moved in SmartMetaGenClass |
|
832 | + */ |
|
833 | + /* |
|
834 | 834 | public static function smart_seo_title($title='', $withExt=true) |
835 | 835 | { |
836 | 836 | // Transformation de la chaine en minuscule |
@@ -876,468 +876,468 @@ discard block |
||
876 | 876 | return ''; |
877 | 877 | } |
878 | 878 | */ |
879 | - public static function getModFooter() |
|
880 | - { |
|
881 | - global $xoopsConfig, $xoopsModule, $xoopsModuleConfig; |
|
882 | - |
|
883 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
884 | - $tpl = new \XoopsTpl(); |
|
885 | - |
|
886 | - $hModule = xoops_getHandler('module'); |
|
887 | - $versioninfo =& $hModule->get($xoopsModule->getVar('mid')); |
|
888 | - $modfootertxt = 'Module ' . $versioninfo->getInfo('name') . ' - Version ' . $versioninfo->getInfo('version') . ''; |
|
889 | - $modfooter = "<a href='" . $versioninfo->getInfo('support_site_url') . "' target='_blank'><img src='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/assets/images/cssbutton.gif' title='" . $modfootertxt . "' alt='" . $modfootertxt . "'></a>"; |
|
890 | - $tpl->assign('modfooter', $modfooter); |
|
891 | - |
|
892 | - if (!defined('_AM_SOBJECT_XOOPS_PRO')) { |
|
893 | - define('_AM_SOBJECT_XOOPS_PRO', 'Do you need help with this module ?<br>Do you need new features not yet available?'); |
|
894 | - } |
|
895 | - $smartobjectConfig = static::getModuleConfig('smartobject'); |
|
896 | - $tpl->assign('smartobject_enable_admin_footer', $smartobjectConfig['enable_admin_footer']); |
|
897 | - $tpl->display(SMARTOBJECT_ROOT_PATH . 'templates/smartobject_admin_footer.tpl'); |
|
898 | - } |
|
899 | - |
|
900 | - public static function getXoopsCpFooter() |
|
901 | - { |
|
902 | - static::getModFooter(); |
|
903 | - xoops_cp_footer(); |
|
904 | - } |
|
905 | - |
|
906 | - /** |
|
907 | - * @param $text |
|
908 | - * @return mixed |
|
909 | - */ |
|
910 | - public static function sanitizeForCommonTags($text) |
|
911 | - { |
|
912 | - global $xoopsConfig; |
|
913 | - $text = str_replace('{X_SITENAME}', $xoopsConfig['sitename'], $text); |
|
914 | - $text = str_replace('{X_ADMINMAIL}', $xoopsConfig['adminmail'], $text); |
|
915 | - |
|
916 | - return $text; |
|
917 | - } |
|
918 | - |
|
919 | - /** |
|
920 | - * @param $src |
|
921 | - */ |
|
922 | - public static function addScript($src) |
|
923 | - { |
|
924 | - echo '<script src="' . $src . '" type="text/javascript"></script>'; |
|
925 | - } |
|
926 | - |
|
927 | - /** |
|
928 | - * @param $src |
|
929 | - */ |
|
930 | - public static function addStyle($src) |
|
931 | - { |
|
932 | - if ('smartobject' === $src) { |
|
933 | - $src = SMARTOBJECT_URL . 'assets/css/module.css'; |
|
934 | - } |
|
935 | - echo static::getCssLink($src); |
|
936 | - } |
|
937 | - |
|
938 | - public static function addAdminAjaxSupport() |
|
939 | - { |
|
940 | - static::addScript(SMARTOBJECT_URL . 'include/scriptaculous/lib/prototype.js'); |
|
941 | - static::addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/scriptaculous.js'); |
|
942 | - static::addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/smart.js'); |
|
943 | - } |
|
944 | - |
|
945 | - /** |
|
946 | - * @param $text |
|
947 | - * @return mixed |
|
948 | - */ |
|
949 | - public static function sanitizeForSmartpopupLink($text) |
|
950 | - { |
|
951 | - $patterns[] = "/\[smartpopup=(['\"]?)([^\"'<>]*)\\1](.*)\[\/smartpopup\]/sU"; |
|
952 | - $replacements[] = "<a href=\"javascript:openWithSelfMain('\\2', 'smartpopup', 700, 519);\">\\3</a>"; |
|
953 | - $ret = preg_replace($patterns, $replacements, $text); |
|
954 | - |
|
955 | - return $ret; |
|
956 | - } |
|
957 | - |
|
958 | - /** |
|
959 | - * Finds the width and height of an image (can also be a flash file) |
|
960 | - * |
|
961 | - * @credit phppp |
|
962 | - * |
|
963 | - * @var string $url path of the image file |
|
964 | - * @var string $width reference to the width |
|
965 | - * @var string $height reference to the height |
|
966 | - * @return bool false if impossible to find dimension |
|
967 | - */ |
|
968 | - public static function getImageSize($url, & $width, & $height) |
|
969 | - { |
|
970 | - if (empty($width) || empty($height)) { |
|
971 | - if (!$dimension = @ getimagesize($url)) { |
|
972 | - return false; |
|
973 | - } |
|
974 | - if (!empty($width)) { |
|
975 | - $height = $dimension[1] * $width / $dimension[0]; |
|
976 | - } elseif (!empty($height)) { |
|
977 | - $width = $dimension[0] * $height / $dimension[1]; |
|
978 | - } else { |
|
979 | - list($width, $height) = [ |
|
980 | - $dimension[0], |
|
981 | - $dimension[1] |
|
982 | - ]; |
|
983 | - } |
|
984 | - |
|
985 | - return true; |
|
986 | - } else { |
|
987 | - return true; |
|
988 | - } |
|
989 | - } |
|
990 | - |
|
991 | - /** |
|
992 | - * Convert characters to decimal values |
|
993 | - * |
|
994 | - * @author eric.wallet at yahoo.fr |
|
995 | - * @link http://ca.php.net/manual/en/function.htmlentities.php#69913 |
|
996 | - * @param $str |
|
997 | - * @return mixed |
|
998 | - */ |
|
999 | - public static function getHtmlnumericentities($str) |
|
1000 | - { |
|
1001 | - // return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str); |
|
1002 | - return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function ($m) { |
|
1003 | - return '&#' . ord($m[0]) . chr(59); |
|
1004 | - }, $str); |
|
1005 | - } |
|
1006 | - |
|
1007 | - /** |
|
1008 | - * @param $name |
|
1009 | - * @param bool $optional |
|
1010 | - * @return mixed |
|
1011 | - */ |
|
1012 | - public static function getCoreHandler($name, $optional = false) |
|
1013 | - { |
|
1014 | - static $handlers; |
|
1015 | - $name = strtolower(trim($name)); |
|
1016 | - if (!isset($handlers[$name])) { |
|
1017 | - if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) { |
|
1018 | - require_once $hnd_file; |
|
1019 | - } |
|
1020 | - $class = 'Xoops' . ucfirst($name) . 'Handler'; |
|
1021 | - if (class_exists($class)) { |
|
1022 | - $handlers[$name] = new $class($GLOBALS['xoopsDB'], 'xoops'); |
|
1023 | - } |
|
1024 | - } |
|
1025 | - if (!isset($handlers[$name]) && !$optional) { |
|
1026 | - trigger_error('Class <b>' . $class . '</b> does not exist<br>Handler Name: ' . $name, E_USER_ERROR); |
|
1027 | - } |
|
1028 | - if (isset($handlers[$name])) { |
|
1029 | - return $handlers[$name]; |
|
1030 | - } |
|
1031 | - $inst = false; |
|
1032 | - } |
|
1033 | - |
|
1034 | - /** |
|
1035 | - * @param $matches |
|
1036 | - * @return string |
|
1037 | - */ |
|
1038 | - public static function sanitizeAdsenses_callback($matches) |
|
1039 | - { |
|
1040 | - global $smartobjectAdsenseHandler; |
|
1041 | - if (isset($smartobjectAdsenseHandler->objects[$matches[1]])) { |
|
1042 | - $adsenseObj = $smartobjectAdsenseHandler->objects[$matches[1]]; |
|
1043 | - $ret = $adsenseObj->render(); |
|
1044 | - |
|
1045 | - return $ret; |
|
1046 | - } else { |
|
1047 | - return ''; |
|
1048 | - } |
|
1049 | - } |
|
1050 | - |
|
1051 | - /** |
|
1052 | - * @param $text |
|
1053 | - * @return mixed |
|
1054 | - */ |
|
1055 | - public static function sanitizeAdsenses($text) |
|
1056 | - { |
|
1057 | - $patterns = []; |
|
1058 | - $replacements = []; |
|
1059 | - |
|
1060 | - $patterns[] = "/\[adsense](.*)\[\/adsense\]/sU"; |
|
1061 | - $text = preg_replace_callback($patterns, 'Smartobject\Utility::sanitizeAdsenses_callback', $text); |
|
1062 | - |
|
1063 | - return $text; |
|
1064 | - } |
|
1065 | - |
|
1066 | - /** |
|
1067 | - * @param $matches |
|
1068 | - * @return string |
|
1069 | - */ |
|
1070 | - public static function sanitizeCustomtags_callback($matches) |
|
1071 | - { |
|
1072 | - global $smartobjectCustomtagHandler; |
|
1073 | - if (isset($smartobjectCustomtagHandler->objects[$matches[1]])) { |
|
1074 | - $customObj = $smartobjectCustomtagHandler->objects[$matches[1]]; |
|
1075 | - $ret = $customObj->renderWithPhp(); |
|
1076 | - |
|
1077 | - return $ret; |
|
1078 | - } else { |
|
1079 | - return ''; |
|
1080 | - } |
|
1081 | - } |
|
1082 | - |
|
1083 | - /** |
|
1084 | - * @param $text |
|
1085 | - * @return mixed |
|
1086 | - */ |
|
1087 | - public static function sanitizeCustomtags($text) |
|
1088 | - { |
|
1089 | - $patterns = []; |
|
1090 | - $replacements = []; |
|
1091 | - |
|
1092 | - $patterns[] = "/\[customtag](.*)\[\/customtag\]/sU"; |
|
1093 | - $text = preg_replace_callback($patterns, 'Smartobject\Utility::sanitizeCustomtags_callback', $text); |
|
1094 | - |
|
1095 | - return $text; |
|
1096 | - } |
|
1097 | - |
|
1098 | - /** |
|
1099 | - * @param $module |
|
1100 | - * @param $file |
|
1101 | - */ |
|
1102 | - public static function loadLanguageFile($module, $file) |
|
1103 | - { |
|
1104 | - global $xoopsConfig; |
|
1105 | - |
|
1106 | - $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/' . $xoopsConfig['language'] . '/' . $file . '.php'; |
|
1107 | - if (!file_exists($filename)) { |
|
1108 | - $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/english/' . $file . '.php'; |
|
1109 | - } |
|
1110 | - if (file_exists($filename)) { |
|
1111 | - require_once $filename; |
|
1112 | - } |
|
1113 | - } |
|
1114 | - |
|
1115 | - public static function loadCommonLanguageFile() |
|
1116 | - { |
|
1117 | - static::loadLanguageFile('smartobject', 'common'); |
|
1118 | - } |
|
1119 | - |
|
1120 | - /** |
|
1121 | - * @param $text |
|
1122 | - * @param bool $keyword |
|
1123 | - * @return mixed|string |
|
1124 | - */ |
|
1125 | - public static function purifyText($text, $keyword = false) |
|
1126 | - { |
|
1127 | - global $myts; |
|
1128 | - $text = str_replace(' ', ' ', $text); |
|
1129 | - $text = str_replace('<br>', ' ', $text); |
|
1130 | - $text = str_replace('<br>', ' ', $text); |
|
1131 | - $text = str_replace('<br', ' ', $text); |
|
1132 | - $text = strip_tags($text); |
|
1133 | - $text = html_entity_decode($text); |
|
1134 | - $text = $myts->undoHtmlSpecialChars($text); |
|
1135 | - $text = str_replace(')', ' ', $text); |
|
1136 | - $text = str_replace('(', ' ', $text); |
|
1137 | - $text = str_replace(':', ' ', $text); |
|
1138 | - $text = str_replace('&euro', ' euro ', $text); |
|
1139 | - $text = str_replace('&hellip', '...', $text); |
|
1140 | - $text = str_replace('&rsquo', ' ', $text); |
|
1141 | - $text = str_replace('!', ' ', $text); |
|
1142 | - $text = str_replace('?', ' ', $text); |
|
1143 | - $text = str_replace('"', ' ', $text); |
|
1144 | - $text = str_replace('-', ' ', $text); |
|
1145 | - $text = str_replace('\n', ' ', $text); |
|
1146 | - $text = str_replace('―', ' ', $text); |
|
1147 | - |
|
1148 | - if ($keyword) { |
|
1149 | - $text = str_replace('.', ' ', $text); |
|
1150 | - $text = str_replace(',', ' ', $text); |
|
1151 | - $text = str_replace('\'', ' ', $text); |
|
1152 | - } |
|
1153 | - $text = str_replace(';', ' ', $text); |
|
1154 | - |
|
1155 | - return $text; |
|
1156 | - } |
|
1157 | - |
|
1158 | - /** |
|
1159 | - * @param $document |
|
1160 | - * @return mixed |
|
1161 | - */ |
|
1162 | - public static function getHtml2text($document) |
|
1163 | - { |
|
1164 | - // PHP Manual:: function preg_replace |
|
1165 | - // $document should contain an HTML document. |
|
1166 | - // This will remove HTML tags, javascript sections |
|
1167 | - // and white space. It will also convert some |
|
1168 | - // common HTML entities to their text equivalent. |
|
1169 | - // Credits: newbb2 |
|
1170 | - $search = [ |
|
1171 | - "'<script[^>]*?>.*?</script>'si", // Strip out javascript |
|
1172 | - "'<img.*?>'si", // Strip out img tags |
|
1173 | - "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags |
|
1174 | - "'([\r\n])[\s]+'", // Strip out white space |
|
1175 | - "'&(quot|#34);'i", // Replace HTML entities |
|
1176 | - "'&(amp|#38);'i", |
|
1177 | - "'&(lt|#60);'i", |
|
1178 | - "'&(gt|#62);'i", |
|
1179 | - "'&(nbsp|#160);'i", |
|
1180 | - "'&(iexcl|#161);'i", |
|
1181 | - "'&(cent|#162);'i", |
|
1182 | - "'&(pound|#163);'i", |
|
1183 | - "'&(copy|#169);'i" |
|
1184 | - ]; // evaluate as php |
|
1185 | - |
|
1186 | - $replace = [ |
|
1187 | - '', |
|
1188 | - '', |
|
1189 | - '', |
|
1190 | - "\\1", |
|
1191 | - '"', |
|
1192 | - '&', |
|
1193 | - '<', |
|
1194 | - '>', |
|
1195 | - ' ', |
|
1196 | - chr(161), |
|
1197 | - chr(162), |
|
1198 | - chr(163), |
|
1199 | - chr(169), |
|
1200 | - ]; |
|
1201 | - |
|
1202 | - $text = preg_replace($search, $replace, $document); |
|
1203 | - |
|
1204 | - preg_replace_callback('/&#(\d+);/', function ($matches) { |
|
1205 | - return chr($matches[1]); |
|
1206 | - }, $document); |
|
1207 | - |
|
1208 | - return $text; |
|
1209 | - } |
|
1210 | - |
|
1211 | - /** |
|
1212 | - * @author pillepop2003 at yahoo dot de |
|
1213 | - * |
|
1214 | - * Use this snippet to extract any float out of a string. You can choose how a single dot is treated with the (bool) 'single_dot_as_decimal' directive. |
|
1215 | - * This function should be able to cover almost all floats that appear in an european environment. |
|
1216 | - * @param $str |
|
1217 | - * @param bool $set |
|
1218 | - * @return float|int |
|
1219 | - */ |
|
1220 | - public static function getFloat($str, $set = false) |
|
1221 | - { |
|
1222 | - if (preg_match("/([0-9\.,-]+)/", $str, $match)) { |
|
1223 | - // Found number in $str, so set $str that number |
|
1224 | - $str = $match[0]; |
|
1225 | - if (false !== strpos($str, ',')) { |
|
1226 | - // A comma exists, that makes it easy, cos we assume it separates the decimal part. |
|
1227 | - $str = str_replace('.', '', $str); // Erase thousand seps |
|
1228 | - $str = str_replace(',', '.', $str); // Convert , to . for floatval command |
|
1229 | - |
|
1230 | - return (float)$str; |
|
1231 | - } else { |
|
1232 | - // No comma exists, so we have to decide, how a single dot shall be treated |
|
1233 | - if (true === preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) && true === $set['single_dot_as_decimal']) { |
|
1234 | - // Treat single dot as decimal separator |
|
1235 | - return (float)$str; |
|
1236 | - } else { |
|
1237 | - //echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br><br> "; |
|
1238 | - // Else, treat all dots as thousand seps |
|
1239 | - $str = str_replace('.', '', $str); // Erase thousand seps |
|
1240 | - |
|
1241 | - return (float)$str; |
|
1242 | - } |
|
1243 | - } |
|
1244 | - } else { |
|
1245 | - // No number found, return zero |
|
1246 | - return 0; |
|
1247 | - } |
|
1248 | - } |
|
1249 | - |
|
1250 | - /** |
|
1251 | - * @param $var |
|
1252 | - * @param bool $currencyObj |
|
1253 | - * @return float|int|mixed|string |
|
1254 | - */ |
|
1255 | - public static function getCurrency($var, $currencyObj = false) |
|
1256 | - { |
|
1257 | - $ret = static::getFloat($var, ['single_dot_as_decimal' => true]); |
|
1258 | - $ret = round($ret, 2); |
|
1259 | - // make sur we have at least .00 in the $var |
|
1260 | - $decimal_section_original = strstr($ret, '.'); |
|
1261 | - $decimal_section = $decimal_section_original; |
|
1262 | - if ($decimal_section) { |
|
1263 | - if (1 == strlen($decimal_section)) { |
|
1264 | - $decimal_section = '.00'; |
|
1265 | - } elseif (2 == strlen($decimal_section)) { |
|
1266 | - $decimal_section .= '0'; |
|
1267 | - } |
|
1268 | - $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
1269 | - } else { |
|
1270 | - $ret .= '.00'; |
|
1271 | - } |
|
1272 | - if ($currencyObj) { |
|
1273 | - $ret = $ret . ' ' . $currencyObj->getCode(); |
|
1274 | - } |
|
1275 | - |
|
1276 | - return $ret; |
|
1277 | - } |
|
1278 | - |
|
1279 | - /** |
|
1280 | - * @param $var |
|
1281 | - * @return float|int|mixed|string |
|
1282 | - */ |
|
1283 | - public static function float($var) |
|
1284 | - { |
|
1285 | - return static::getCurrency($var); |
|
1286 | - } |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * @param bool $moduleName |
|
1290 | - * @return string |
|
1291 | - */ |
|
1292 | - public static function getModuleAdminLink($moduleName = false) |
|
1293 | - { |
|
1294 | - global $xoopsModule; |
|
1295 | - if (!$moduleName && (isset($xoopsModule) && is_object($xoopsModule))) { |
|
1296 | - $moduleName = $xoopsModule->getVar('dirname'); |
|
1297 | - } |
|
1298 | - $ret = ''; |
|
1299 | - if ($moduleName) { |
|
1300 | - $ret = "<a href='" . XOOPS_URL . "/modules/$moduleName/admin/index.php'>" . _CO_SOBJECT_ADMIN_PAGE . '</a>'; |
|
1301 | - } |
|
1302 | - |
|
1303 | - return $ret; |
|
1304 | - } |
|
1305 | - |
|
1306 | - /** |
|
1307 | - * @return array|bool |
|
1308 | - */ |
|
1309 | - public static function getEditors() |
|
1310 | - { |
|
1311 | - $filename = XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php'; |
|
1312 | - if (!file_exists($filename)) { |
|
1313 | - return false; |
|
1314 | - } |
|
1315 | - require_once $filename; |
|
1316 | - $xoopseditorHandler = \XoopsEditorHandler::getInstance(); |
|
1317 | - $aList = $xoopseditorHandler->getList(); |
|
1318 | - $ret = []; |
|
1319 | - foreach ($aList as $k => $v) { |
|
1320 | - $ret[$v] = $k; |
|
1321 | - } |
|
1322 | - |
|
1323 | - return $ret; |
|
1324 | - } |
|
1325 | - |
|
1326 | - /** |
|
1327 | - * @param $moduleName |
|
1328 | - * @param $items |
|
1329 | - * @return array |
|
1330 | - */ |
|
1331 | - public static function getTablesArray($moduleName, $items) |
|
1332 | - { |
|
1333 | - $ret = []; |
|
1334 | - foreach ($items as $item) { |
|
1335 | - $ret[] = $moduleName . '_' . $item; |
|
1336 | - } |
|
1337 | - $ret[] = $moduleName . '_meta'; |
|
1338 | - |
|
1339 | - return $ret; |
|
1340 | - } |
|
879 | + public static function getModFooter() |
|
880 | + { |
|
881 | + global $xoopsConfig, $xoopsModule, $xoopsModuleConfig; |
|
882 | + |
|
883 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
884 | + $tpl = new \XoopsTpl(); |
|
885 | + |
|
886 | + $hModule = xoops_getHandler('module'); |
|
887 | + $versioninfo =& $hModule->get($xoopsModule->getVar('mid')); |
|
888 | + $modfootertxt = 'Module ' . $versioninfo->getInfo('name') . ' - Version ' . $versioninfo->getInfo('version') . ''; |
|
889 | + $modfooter = "<a href='" . $versioninfo->getInfo('support_site_url') . "' target='_blank'><img src='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/assets/images/cssbutton.gif' title='" . $modfootertxt . "' alt='" . $modfootertxt . "'></a>"; |
|
890 | + $tpl->assign('modfooter', $modfooter); |
|
891 | + |
|
892 | + if (!defined('_AM_SOBJECT_XOOPS_PRO')) { |
|
893 | + define('_AM_SOBJECT_XOOPS_PRO', 'Do you need help with this module ?<br>Do you need new features not yet available?'); |
|
894 | + } |
|
895 | + $smartobjectConfig = static::getModuleConfig('smartobject'); |
|
896 | + $tpl->assign('smartobject_enable_admin_footer', $smartobjectConfig['enable_admin_footer']); |
|
897 | + $tpl->display(SMARTOBJECT_ROOT_PATH . 'templates/smartobject_admin_footer.tpl'); |
|
898 | + } |
|
899 | + |
|
900 | + public static function getXoopsCpFooter() |
|
901 | + { |
|
902 | + static::getModFooter(); |
|
903 | + xoops_cp_footer(); |
|
904 | + } |
|
905 | + |
|
906 | + /** |
|
907 | + * @param $text |
|
908 | + * @return mixed |
|
909 | + */ |
|
910 | + public static function sanitizeForCommonTags($text) |
|
911 | + { |
|
912 | + global $xoopsConfig; |
|
913 | + $text = str_replace('{X_SITENAME}', $xoopsConfig['sitename'], $text); |
|
914 | + $text = str_replace('{X_ADMINMAIL}', $xoopsConfig['adminmail'], $text); |
|
915 | + |
|
916 | + return $text; |
|
917 | + } |
|
918 | + |
|
919 | + /** |
|
920 | + * @param $src |
|
921 | + */ |
|
922 | + public static function addScript($src) |
|
923 | + { |
|
924 | + echo '<script src="' . $src . '" type="text/javascript"></script>'; |
|
925 | + } |
|
926 | + |
|
927 | + /** |
|
928 | + * @param $src |
|
929 | + */ |
|
930 | + public static function addStyle($src) |
|
931 | + { |
|
932 | + if ('smartobject' === $src) { |
|
933 | + $src = SMARTOBJECT_URL . 'assets/css/module.css'; |
|
934 | + } |
|
935 | + echo static::getCssLink($src); |
|
936 | + } |
|
937 | + |
|
938 | + public static function addAdminAjaxSupport() |
|
939 | + { |
|
940 | + static::addScript(SMARTOBJECT_URL . 'include/scriptaculous/lib/prototype.js'); |
|
941 | + static::addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/scriptaculous.js'); |
|
942 | + static::addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/smart.js'); |
|
943 | + } |
|
944 | + |
|
945 | + /** |
|
946 | + * @param $text |
|
947 | + * @return mixed |
|
948 | + */ |
|
949 | + public static function sanitizeForSmartpopupLink($text) |
|
950 | + { |
|
951 | + $patterns[] = "/\[smartpopup=(['\"]?)([^\"'<>]*)\\1](.*)\[\/smartpopup\]/sU"; |
|
952 | + $replacements[] = "<a href=\"javascript:openWithSelfMain('\\2', 'smartpopup', 700, 519);\">\\3</a>"; |
|
953 | + $ret = preg_replace($patterns, $replacements, $text); |
|
954 | + |
|
955 | + return $ret; |
|
956 | + } |
|
957 | + |
|
958 | + /** |
|
959 | + * Finds the width and height of an image (can also be a flash file) |
|
960 | + * |
|
961 | + * @credit phppp |
|
962 | + * |
|
963 | + * @var string $url path of the image file |
|
964 | + * @var string $width reference to the width |
|
965 | + * @var string $height reference to the height |
|
966 | + * @return bool false if impossible to find dimension |
|
967 | + */ |
|
968 | + public static function getImageSize($url, & $width, & $height) |
|
969 | + { |
|
970 | + if (empty($width) || empty($height)) { |
|
971 | + if (!$dimension = @ getimagesize($url)) { |
|
972 | + return false; |
|
973 | + } |
|
974 | + if (!empty($width)) { |
|
975 | + $height = $dimension[1] * $width / $dimension[0]; |
|
976 | + } elseif (!empty($height)) { |
|
977 | + $width = $dimension[0] * $height / $dimension[1]; |
|
978 | + } else { |
|
979 | + list($width, $height) = [ |
|
980 | + $dimension[0], |
|
981 | + $dimension[1] |
|
982 | + ]; |
|
983 | + } |
|
984 | + |
|
985 | + return true; |
|
986 | + } else { |
|
987 | + return true; |
|
988 | + } |
|
989 | + } |
|
990 | + |
|
991 | + /** |
|
992 | + * Convert characters to decimal values |
|
993 | + * |
|
994 | + * @author eric.wallet at yahoo.fr |
|
995 | + * @link http://ca.php.net/manual/en/function.htmlentities.php#69913 |
|
996 | + * @param $str |
|
997 | + * @return mixed |
|
998 | + */ |
|
999 | + public static function getHtmlnumericentities($str) |
|
1000 | + { |
|
1001 | + // return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str); |
|
1002 | + return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function ($m) { |
|
1003 | + return '&#' . ord($m[0]) . chr(59); |
|
1004 | + }, $str); |
|
1005 | + } |
|
1006 | + |
|
1007 | + /** |
|
1008 | + * @param $name |
|
1009 | + * @param bool $optional |
|
1010 | + * @return mixed |
|
1011 | + */ |
|
1012 | + public static function getCoreHandler($name, $optional = false) |
|
1013 | + { |
|
1014 | + static $handlers; |
|
1015 | + $name = strtolower(trim($name)); |
|
1016 | + if (!isset($handlers[$name])) { |
|
1017 | + if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) { |
|
1018 | + require_once $hnd_file; |
|
1019 | + } |
|
1020 | + $class = 'Xoops' . ucfirst($name) . 'Handler'; |
|
1021 | + if (class_exists($class)) { |
|
1022 | + $handlers[$name] = new $class($GLOBALS['xoopsDB'], 'xoops'); |
|
1023 | + } |
|
1024 | + } |
|
1025 | + if (!isset($handlers[$name]) && !$optional) { |
|
1026 | + trigger_error('Class <b>' . $class . '</b> does not exist<br>Handler Name: ' . $name, E_USER_ERROR); |
|
1027 | + } |
|
1028 | + if (isset($handlers[$name])) { |
|
1029 | + return $handlers[$name]; |
|
1030 | + } |
|
1031 | + $inst = false; |
|
1032 | + } |
|
1033 | + |
|
1034 | + /** |
|
1035 | + * @param $matches |
|
1036 | + * @return string |
|
1037 | + */ |
|
1038 | + public static function sanitizeAdsenses_callback($matches) |
|
1039 | + { |
|
1040 | + global $smartobjectAdsenseHandler; |
|
1041 | + if (isset($smartobjectAdsenseHandler->objects[$matches[1]])) { |
|
1042 | + $adsenseObj = $smartobjectAdsenseHandler->objects[$matches[1]]; |
|
1043 | + $ret = $adsenseObj->render(); |
|
1044 | + |
|
1045 | + return $ret; |
|
1046 | + } else { |
|
1047 | + return ''; |
|
1048 | + } |
|
1049 | + } |
|
1050 | + |
|
1051 | + /** |
|
1052 | + * @param $text |
|
1053 | + * @return mixed |
|
1054 | + */ |
|
1055 | + public static function sanitizeAdsenses($text) |
|
1056 | + { |
|
1057 | + $patterns = []; |
|
1058 | + $replacements = []; |
|
1059 | + |
|
1060 | + $patterns[] = "/\[adsense](.*)\[\/adsense\]/sU"; |
|
1061 | + $text = preg_replace_callback($patterns, 'Smartobject\Utility::sanitizeAdsenses_callback', $text); |
|
1062 | + |
|
1063 | + return $text; |
|
1064 | + } |
|
1065 | + |
|
1066 | + /** |
|
1067 | + * @param $matches |
|
1068 | + * @return string |
|
1069 | + */ |
|
1070 | + public static function sanitizeCustomtags_callback($matches) |
|
1071 | + { |
|
1072 | + global $smartobjectCustomtagHandler; |
|
1073 | + if (isset($smartobjectCustomtagHandler->objects[$matches[1]])) { |
|
1074 | + $customObj = $smartobjectCustomtagHandler->objects[$matches[1]]; |
|
1075 | + $ret = $customObj->renderWithPhp(); |
|
1076 | + |
|
1077 | + return $ret; |
|
1078 | + } else { |
|
1079 | + return ''; |
|
1080 | + } |
|
1081 | + } |
|
1082 | + |
|
1083 | + /** |
|
1084 | + * @param $text |
|
1085 | + * @return mixed |
|
1086 | + */ |
|
1087 | + public static function sanitizeCustomtags($text) |
|
1088 | + { |
|
1089 | + $patterns = []; |
|
1090 | + $replacements = []; |
|
1091 | + |
|
1092 | + $patterns[] = "/\[customtag](.*)\[\/customtag\]/sU"; |
|
1093 | + $text = preg_replace_callback($patterns, 'Smartobject\Utility::sanitizeCustomtags_callback', $text); |
|
1094 | + |
|
1095 | + return $text; |
|
1096 | + } |
|
1097 | + |
|
1098 | + /** |
|
1099 | + * @param $module |
|
1100 | + * @param $file |
|
1101 | + */ |
|
1102 | + public static function loadLanguageFile($module, $file) |
|
1103 | + { |
|
1104 | + global $xoopsConfig; |
|
1105 | + |
|
1106 | + $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/' . $xoopsConfig['language'] . '/' . $file . '.php'; |
|
1107 | + if (!file_exists($filename)) { |
|
1108 | + $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/english/' . $file . '.php'; |
|
1109 | + } |
|
1110 | + if (file_exists($filename)) { |
|
1111 | + require_once $filename; |
|
1112 | + } |
|
1113 | + } |
|
1114 | + |
|
1115 | + public static function loadCommonLanguageFile() |
|
1116 | + { |
|
1117 | + static::loadLanguageFile('smartobject', 'common'); |
|
1118 | + } |
|
1119 | + |
|
1120 | + /** |
|
1121 | + * @param $text |
|
1122 | + * @param bool $keyword |
|
1123 | + * @return mixed|string |
|
1124 | + */ |
|
1125 | + public static function purifyText($text, $keyword = false) |
|
1126 | + { |
|
1127 | + global $myts; |
|
1128 | + $text = str_replace(' ', ' ', $text); |
|
1129 | + $text = str_replace('<br>', ' ', $text); |
|
1130 | + $text = str_replace('<br>', ' ', $text); |
|
1131 | + $text = str_replace('<br', ' ', $text); |
|
1132 | + $text = strip_tags($text); |
|
1133 | + $text = html_entity_decode($text); |
|
1134 | + $text = $myts->undoHtmlSpecialChars($text); |
|
1135 | + $text = str_replace(')', ' ', $text); |
|
1136 | + $text = str_replace('(', ' ', $text); |
|
1137 | + $text = str_replace(':', ' ', $text); |
|
1138 | + $text = str_replace('&euro', ' euro ', $text); |
|
1139 | + $text = str_replace('&hellip', '...', $text); |
|
1140 | + $text = str_replace('&rsquo', ' ', $text); |
|
1141 | + $text = str_replace('!', ' ', $text); |
|
1142 | + $text = str_replace('?', ' ', $text); |
|
1143 | + $text = str_replace('"', ' ', $text); |
|
1144 | + $text = str_replace('-', ' ', $text); |
|
1145 | + $text = str_replace('\n', ' ', $text); |
|
1146 | + $text = str_replace('―', ' ', $text); |
|
1147 | + |
|
1148 | + if ($keyword) { |
|
1149 | + $text = str_replace('.', ' ', $text); |
|
1150 | + $text = str_replace(',', ' ', $text); |
|
1151 | + $text = str_replace('\'', ' ', $text); |
|
1152 | + } |
|
1153 | + $text = str_replace(';', ' ', $text); |
|
1154 | + |
|
1155 | + return $text; |
|
1156 | + } |
|
1157 | + |
|
1158 | + /** |
|
1159 | + * @param $document |
|
1160 | + * @return mixed |
|
1161 | + */ |
|
1162 | + public static function getHtml2text($document) |
|
1163 | + { |
|
1164 | + // PHP Manual:: function preg_replace |
|
1165 | + // $document should contain an HTML document. |
|
1166 | + // This will remove HTML tags, javascript sections |
|
1167 | + // and white space. It will also convert some |
|
1168 | + // common HTML entities to their text equivalent. |
|
1169 | + // Credits: newbb2 |
|
1170 | + $search = [ |
|
1171 | + "'<script[^>]*?>.*?</script>'si", // Strip out javascript |
|
1172 | + "'<img.*?>'si", // Strip out img tags |
|
1173 | + "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags |
|
1174 | + "'([\r\n])[\s]+'", // Strip out white space |
|
1175 | + "'&(quot|#34);'i", // Replace HTML entities |
|
1176 | + "'&(amp|#38);'i", |
|
1177 | + "'&(lt|#60);'i", |
|
1178 | + "'&(gt|#62);'i", |
|
1179 | + "'&(nbsp|#160);'i", |
|
1180 | + "'&(iexcl|#161);'i", |
|
1181 | + "'&(cent|#162);'i", |
|
1182 | + "'&(pound|#163);'i", |
|
1183 | + "'&(copy|#169);'i" |
|
1184 | + ]; // evaluate as php |
|
1185 | + |
|
1186 | + $replace = [ |
|
1187 | + '', |
|
1188 | + '', |
|
1189 | + '', |
|
1190 | + "\\1", |
|
1191 | + '"', |
|
1192 | + '&', |
|
1193 | + '<', |
|
1194 | + '>', |
|
1195 | + ' ', |
|
1196 | + chr(161), |
|
1197 | + chr(162), |
|
1198 | + chr(163), |
|
1199 | + chr(169), |
|
1200 | + ]; |
|
1201 | + |
|
1202 | + $text = preg_replace($search, $replace, $document); |
|
1203 | + |
|
1204 | + preg_replace_callback('/&#(\d+);/', function ($matches) { |
|
1205 | + return chr($matches[1]); |
|
1206 | + }, $document); |
|
1207 | + |
|
1208 | + return $text; |
|
1209 | + } |
|
1210 | + |
|
1211 | + /** |
|
1212 | + * @author pillepop2003 at yahoo dot de |
|
1213 | + * |
|
1214 | + * Use this snippet to extract any float out of a string. You can choose how a single dot is treated with the (bool) 'single_dot_as_decimal' directive. |
|
1215 | + * This function should be able to cover almost all floats that appear in an european environment. |
|
1216 | + * @param $str |
|
1217 | + * @param bool $set |
|
1218 | + * @return float|int |
|
1219 | + */ |
|
1220 | + public static function getFloat($str, $set = false) |
|
1221 | + { |
|
1222 | + if (preg_match("/([0-9\.,-]+)/", $str, $match)) { |
|
1223 | + // Found number in $str, so set $str that number |
|
1224 | + $str = $match[0]; |
|
1225 | + if (false !== strpos($str, ',')) { |
|
1226 | + // A comma exists, that makes it easy, cos we assume it separates the decimal part. |
|
1227 | + $str = str_replace('.', '', $str); // Erase thousand seps |
|
1228 | + $str = str_replace(',', '.', $str); // Convert , to . for floatval command |
|
1229 | + |
|
1230 | + return (float)$str; |
|
1231 | + } else { |
|
1232 | + // No comma exists, so we have to decide, how a single dot shall be treated |
|
1233 | + if (true === preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) && true === $set['single_dot_as_decimal']) { |
|
1234 | + // Treat single dot as decimal separator |
|
1235 | + return (float)$str; |
|
1236 | + } else { |
|
1237 | + //echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br><br> "; |
|
1238 | + // Else, treat all dots as thousand seps |
|
1239 | + $str = str_replace('.', '', $str); // Erase thousand seps |
|
1240 | + |
|
1241 | + return (float)$str; |
|
1242 | + } |
|
1243 | + } |
|
1244 | + } else { |
|
1245 | + // No number found, return zero |
|
1246 | + return 0; |
|
1247 | + } |
|
1248 | + } |
|
1249 | + |
|
1250 | + /** |
|
1251 | + * @param $var |
|
1252 | + * @param bool $currencyObj |
|
1253 | + * @return float|int|mixed|string |
|
1254 | + */ |
|
1255 | + public static function getCurrency($var, $currencyObj = false) |
|
1256 | + { |
|
1257 | + $ret = static::getFloat($var, ['single_dot_as_decimal' => true]); |
|
1258 | + $ret = round($ret, 2); |
|
1259 | + // make sur we have at least .00 in the $var |
|
1260 | + $decimal_section_original = strstr($ret, '.'); |
|
1261 | + $decimal_section = $decimal_section_original; |
|
1262 | + if ($decimal_section) { |
|
1263 | + if (1 == strlen($decimal_section)) { |
|
1264 | + $decimal_section = '.00'; |
|
1265 | + } elseif (2 == strlen($decimal_section)) { |
|
1266 | + $decimal_section .= '0'; |
|
1267 | + } |
|
1268 | + $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
1269 | + } else { |
|
1270 | + $ret .= '.00'; |
|
1271 | + } |
|
1272 | + if ($currencyObj) { |
|
1273 | + $ret = $ret . ' ' . $currencyObj->getCode(); |
|
1274 | + } |
|
1275 | + |
|
1276 | + return $ret; |
|
1277 | + } |
|
1278 | + |
|
1279 | + /** |
|
1280 | + * @param $var |
|
1281 | + * @return float|int|mixed|string |
|
1282 | + */ |
|
1283 | + public static function float($var) |
|
1284 | + { |
|
1285 | + return static::getCurrency($var); |
|
1286 | + } |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * @param bool $moduleName |
|
1290 | + * @return string |
|
1291 | + */ |
|
1292 | + public static function getModuleAdminLink($moduleName = false) |
|
1293 | + { |
|
1294 | + global $xoopsModule; |
|
1295 | + if (!$moduleName && (isset($xoopsModule) && is_object($xoopsModule))) { |
|
1296 | + $moduleName = $xoopsModule->getVar('dirname'); |
|
1297 | + } |
|
1298 | + $ret = ''; |
|
1299 | + if ($moduleName) { |
|
1300 | + $ret = "<a href='" . XOOPS_URL . "/modules/$moduleName/admin/index.php'>" . _CO_SOBJECT_ADMIN_PAGE . '</a>'; |
|
1301 | + } |
|
1302 | + |
|
1303 | + return $ret; |
|
1304 | + } |
|
1305 | + |
|
1306 | + /** |
|
1307 | + * @return array|bool |
|
1308 | + */ |
|
1309 | + public static function getEditors() |
|
1310 | + { |
|
1311 | + $filename = XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php'; |
|
1312 | + if (!file_exists($filename)) { |
|
1313 | + return false; |
|
1314 | + } |
|
1315 | + require_once $filename; |
|
1316 | + $xoopseditorHandler = \XoopsEditorHandler::getInstance(); |
|
1317 | + $aList = $xoopseditorHandler->getList(); |
|
1318 | + $ret = []; |
|
1319 | + foreach ($aList as $k => $v) { |
|
1320 | + $ret[$v] = $k; |
|
1321 | + } |
|
1322 | + |
|
1323 | + return $ret; |
|
1324 | + } |
|
1325 | + |
|
1326 | + /** |
|
1327 | + * @param $moduleName |
|
1328 | + * @param $items |
|
1329 | + * @return array |
|
1330 | + */ |
|
1331 | + public static function getTablesArray($moduleName, $items) |
|
1332 | + { |
|
1333 | + $ret = []; |
|
1334 | + foreach ($items as $item) { |
|
1335 | + $ret[] = $moduleName . '_' . $item; |
|
1336 | + } |
|
1337 | + $ret[] = $moduleName . '_meta'; |
|
1338 | + |
|
1339 | + return $ret; |
|
1340 | + } |
|
1341 | 1341 | |
1342 | 1342 | |
1343 | 1343 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public static function getCssLink($cssfile) |
27 | 27 | { |
28 | - $ret = '<link rel="stylesheet" type="text/css" href="' . $cssfile . '">'; |
|
28 | + $ret = '<link rel="stylesheet" type="text/css" href="'.$cssfile.'">'; |
|
29 | 29 | |
30 | 30 | return $ret; |
31 | 31 | } |
@@ -116,14 +116,14 @@ discard block |
||
116 | 116 | $seoMode = static::getModuleModeSEO($moduleName); |
117 | 117 | if ('rewrite' === $seoMode) { |
118 | 118 | $seoModuleName = static::getModuleNameForSEO($moduleName); |
119 | - $ret = XOOPS_URL . '/' . $seoModuleName . '/'; |
|
119 | + $ret = XOOPS_URL.'/'.$seoModuleName.'/'; |
|
120 | 120 | } elseif ('pathinfo' === $seoMode) { |
121 | - $ret = XOOPS_URL . '/modules/' . $moduleName . '/seo.php/' . $seoModuleName . '/'; |
|
121 | + $ret = XOOPS_URL.'/modules/'.$moduleName.'/seo.php/'.$seoModuleName.'/'; |
|
122 | 122 | } else { |
123 | - $ret = XOOPS_URL . '/modules/' . $moduleName . '/'; |
|
123 | + $ret = XOOPS_URL.'/modules/'.$moduleName.'/'; |
|
124 | 124 | } |
125 | 125 | |
126 | - return '<a href="' . $ret . '">' . $smartModule->getVar('name') . '</a>'; |
|
126 | + return '<a href="'.$ret.'">'.$smartModule->getVar('name').'</a>'; |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | //Verifies that a MySQL table exists |
226 | 226 | $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
227 | 227 | $realname = $xoopsDB->prefix($table); |
228 | - $sql = 'SHOW TABLES FROM ' . XOOPS_DB_NAME; |
|
228 | + $sql = 'SHOW TABLES FROM '.XOOPS_DB_NAME; |
|
229 | 229 | $ret = $xoopsDB->queryF($sql); |
230 | 230 | while (false !== (list($m_table) = $xoopsDB->fetchRow($ret))) { |
231 | 231 | if ($m_table == $realname) { |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | $moduleName = static::getCurrentModuleName(); |
255 | 255 | } |
256 | 256 | $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
257 | - $sql = sprintf('SELECT metavalue FROM `%s` WHERE metakey=%s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key)); |
|
257 | + $sql = sprintf('SELECT metavalue FROM `%s` WHERE metakey=%s', $xoopsDB->prefix($moduleName.'_meta'), $xoopsDB->quoteString($key)); |
|
258 | 258 | $ret = $xoopsDB->query($sql); |
259 | 259 | if (!$ret) { |
260 | 260 | $value = false; |
@@ -297,9 +297,9 @@ discard block |
||
297 | 297 | $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
298 | 298 | $ret = static::getMeta($key, $moduleName); |
299 | 299 | if ('0' === $ret || $ret > 0) { |
300 | - $sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key)); |
|
300 | + $sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName.'_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key)); |
|
301 | 301 | } else { |
302 | - $sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value)); |
|
302 | + $sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName.'_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value)); |
|
303 | 303 | } |
304 | 304 | $ret = $xoopsDB->queryF($sql); |
305 | 305 | if (!$ret) { |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | { |
480 | 480 | static $smartModules; |
481 | 481 | if (isset($smartModules[$moduleName])) { |
482 | - $ret =& $smartModules[$moduleName]; |
|
482 | + $ret = & $smartModules[$moduleName]; |
|
483 | 483 | |
484 | 484 | return $ret; |
485 | 485 | } |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | { |
516 | 516 | static $smartConfigs; |
517 | 517 | if (isset($smartConfigs[$moduleName])) { |
518 | - $ret =& $smartConfigs[$moduleName]; |
|
518 | + $ret = & $smartConfigs[$moduleName]; |
|
519 | 519 | |
520 | 520 | return $ret; |
521 | 521 | } |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | return $ret; |
544 | 544 | } |
545 | 545 | $hModConfig = xoops_getHandler('config'); |
546 | - $smartConfigs[$moduleName] =& $hModConfig->getConfigsByCat(0, $module->getVar('mid')); |
|
546 | + $smartConfigs[$moduleName] = & $hModConfig->getConfigsByCat(0, $module->getVar('mid')); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | return $smartConfigs[$moduleName]; |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | { |
570 | 570 | $ret = ''; |
571 | 571 | foreach ($errors as $key => $value) { |
572 | - $ret .= '<br> - ' . $value; |
|
572 | + $ret .= '<br> - '.$value; |
|
573 | 573 | } |
574 | 574 | |
575 | 575 | return $ret; |
@@ -589,17 +589,17 @@ discard block |
||
589 | 589 | if (!is_numeric($userid)) { |
590 | 590 | return $userid; |
591 | 591 | } |
592 | - $userid = (int)$userid; |
|
592 | + $userid = (int) $userid; |
|
593 | 593 | if ($userid > 0) { |
594 | 594 | if ($users == []) { |
595 | 595 | //fetching users |
596 | 596 | $memberHandler = xoops_getHandler('member'); |
597 | - $user =& $memberHandler->getUser($userid); |
|
597 | + $user = & $memberHandler->getUser($userid); |
|
598 | 598 | } else { |
599 | 599 | if (!isset($users[$userid])) { |
600 | 600 | return $GLOBALS['xoopsConfig']['anonymous']; |
601 | 601 | } |
602 | - $user =& $users[$userid]; |
|
602 | + $user = & $users[$userid]; |
|
603 | 603 | } |
604 | 604 | if (is_object($user)) { |
605 | 605 | $ts = \MyTextSanitizer:: getInstance(); |
@@ -610,15 +610,15 @@ discard block |
||
610 | 610 | $fullname = $user->getVar('name'); |
611 | 611 | } |
612 | 612 | if (!empty($fullname)) { |
613 | - $linkeduser = "$fullname [<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . $ts->htmlSpecialChars($username) . '</a>]'; |
|
613 | + $linkeduser = "$fullname [<a href='".XOOPS_URL.'/userinfo.php?uid='.$userid."'>".$ts->htmlSpecialChars($username).'</a>]'; |
|
614 | 614 | } else { |
615 | - $linkeduser = "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . ucwords($ts->htmlSpecialChars($username)) . '</a>'; |
|
615 | + $linkeduser = "<a href='".XOOPS_URL.'/userinfo.php?uid='.$userid."'>".ucwords($ts->htmlSpecialChars($username)).'</a>'; |
|
616 | 616 | } |
617 | 617 | // add contact info: email + PM |
618 | 618 | if ($withContact) { |
619 | - $linkeduser .= ' <a href="mailto:' . $user->getVar('email') . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/email.gif' . '" alt="' . _CO_SOBJECT_SEND_EMAIL . '" title="' . _CO_SOBJECT_SEND_EMAIL . '"></a>'; |
|
620 | - $js = "javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $userid . "', 'pmlite',450,370);"; |
|
621 | - $linkeduser .= ' <a href="' . $js . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/pm.gif' . '" alt="' . _CO_SOBJECT_SEND_PM . '" title="' . _CO_SOBJECT_SEND_PM . '"></a>'; |
|
619 | + $linkeduser .= ' <a href="mailto:'.$user->getVar('email').'"><img style="vertical-align: middle;" src="'.XOOPS_URL.'/images/icons/email.gif'.'" alt="'._CO_SOBJECT_SEND_EMAIL.'" title="'._CO_SOBJECT_SEND_EMAIL.'"></a>'; |
|
620 | + $js = "javascript:openWithSelfMain('".XOOPS_URL.'/pmlite.php?send2=1&to_userid='.$userid."', 'pmlite',450,370);"; |
|
621 | + $linkeduser .= ' <a href="'.$js.'"><img style="vertical-align: middle;" src="'.XOOPS_URL.'/images/icons/pm.gif'.'" alt="'._CO_SOBJECT_SEND_PM.'" title="'._CO_SOBJECT_SEND_PM.'"></a>'; |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | return $linkeduser; |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | public static function getAdminMenu($currentoption = 0, $breadcrumb = '', $submenus = false, $currentsub = -1) |
638 | 638 | { |
639 | 639 | global $xoopsModule, $xoopsConfig; |
640 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
640 | + require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|
641 | 641 | |
642 | 642 | |
643 | 643 | /** @var Smartobject\Helper $helper */ |
@@ -646,7 +646,7 @@ discard block |
||
646 | 646 | $helper->loadLanguage('modinfo'); |
647 | 647 | $headermenu = []; |
648 | 648 | $adminObject = []; |
649 | - include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/menu.php'; |
|
649 | + include XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/admin/menu.php'; |
|
650 | 650 | $tpl = new \XoopsTpl(); |
651 | 651 | $tpl->assign([ |
652 | 652 | 'headermenu' => $headermenu, |
@@ -669,11 +669,11 @@ discard block |
||
669 | 669 | public static function getCollapsableBar($id = '', $title = '', $dsc = '') |
670 | 670 | { |
671 | 671 | global $xoopsModule; |
672 | - echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"togglecollapse('" . $id . "'); toggleIcon('" . $id . "_icon')\";>"; |
|
673 | - echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a> " . $title . '</h3>'; |
|
674 | - echo "<div id='" . $id . "'>"; |
|
672 | + echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"togglecollapse('".$id."'); toggleIcon('".$id."_icon')\";>"; |
|
673 | + echo "<img id='".$id."_icon' src=".SMARTOBJECT_URL."assets/images/close12.gif alt=''></a> ".$title.'</h3>'; |
|
674 | + echo "<div id='".$id."'>"; |
|
675 | 675 | if ('' !== $dsc) { |
676 | - echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . $dsc . '</span>'; |
|
676 | + echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">'.$dsc.'</span>'; |
|
677 | 677 | } |
678 | 678 | } |
679 | 679 | |
@@ -687,11 +687,11 @@ discard block |
||
687 | 687 | global $xoopsModule; |
688 | 688 | $onClick = "ajaxtogglecollapse('$id')"; |
689 | 689 | //$onClick = "togglecollapse('$id'); toggleIcon('" . $id . "_icon')"; |
690 | - echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="' . $onClick . '">'; |
|
691 | - echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a> " . $title . '</h3>'; |
|
692 | - echo "<div id='" . $id . "'>"; |
|
690 | + echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="'.$onClick.'">'; |
|
691 | + echo "<img id='".$id."_icon' src=".SMARTOBJECT_URL."assets/images/close12.gif alt=''></a> ".$title.'</h3>'; |
|
692 | + echo "<div id='".$id."'>"; |
|
693 | 693 | if ('' !== $dsc) { |
694 | - echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . $dsc . '</span>'; |
|
694 | + echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">'.$dsc.'</span>'; |
|
695 | 695 | } |
696 | 696 | } |
697 | 697 | |
@@ -721,13 +721,13 @@ discard block |
||
721 | 721 | { |
722 | 722 | $urls = static::getCurrentUrls(); |
723 | 723 | $path = $urls['phpself']; |
724 | - $cookie_name = $path . '_smart_collaps_' . $name; |
|
724 | + $cookie_name = $path.'_smart_collaps_'.$name; |
|
725 | 725 | $cookie_name = str_replace('.', '_', $cookie_name); |
726 | 726 | $cookie = static::getCookieVar($cookie_name, ''); |
727 | 727 | if ('none' === $cookie) { |
728 | 728 | echo ' |
729 | 729 | <script type="text/javascript"><!-- |
730 | - togglecollapse("' . $name . '"); toggleIcon("' . $name . '_icon"); |
|
730 | + togglecollapse("' . $name.'"); toggleIcon("'.$name.'_icon"); |
|
731 | 731 | //--> |
732 | 732 | </script> |
733 | 733 | '; |
@@ -793,17 +793,17 @@ discard block |
||
793 | 793 | $httphost = $_SERVER['HTTP_HOST']; |
794 | 794 | $querystring = $_SERVER['QUERY_STRING']; |
795 | 795 | if ('' !== $querystring) { |
796 | - $querystring = '?' . $querystring; |
|
796 | + $querystring = '?'.$querystring; |
|
797 | 797 | } |
798 | - $currenturl = $http . $httphost . $phpself . $querystring; |
|
798 | + $currenturl = $http.$httphost.$phpself.$querystring; |
|
799 | 799 | $urls = []; |
800 | 800 | $urls['http'] = $http; |
801 | 801 | $urls['httphost'] = $httphost; |
802 | 802 | $urls['phpself'] = $phpself; |
803 | 803 | $urls['querystring'] = $querystring; |
804 | - $urls['full_phpself'] = $http . $httphost . $phpself; |
|
804 | + $urls['full_phpself'] = $http.$httphost.$phpself; |
|
805 | 805 | $urls['full'] = $currenturl; |
806 | - $urls['isHomePage'] = (XOOPS_URL . '/index.php') == ($http . $httphost . $phpself); |
|
806 | + $urls['isHomePage'] = (XOOPS_URL.'/index.php') == ($http.$httphost.$phpself); |
|
807 | 807 | |
808 | 808 | return $urls; |
809 | 809 | } |
@@ -880,13 +880,13 @@ discard block |
||
880 | 880 | { |
881 | 881 | global $xoopsConfig, $xoopsModule, $xoopsModuleConfig; |
882 | 882 | |
883 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
883 | + require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|
884 | 884 | $tpl = new \XoopsTpl(); |
885 | 885 | |
886 | 886 | $hModule = xoops_getHandler('module'); |
887 | - $versioninfo =& $hModule->get($xoopsModule->getVar('mid')); |
|
888 | - $modfootertxt = 'Module ' . $versioninfo->getInfo('name') . ' - Version ' . $versioninfo->getInfo('version') . ''; |
|
889 | - $modfooter = "<a href='" . $versioninfo->getInfo('support_site_url') . "' target='_blank'><img src='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/assets/images/cssbutton.gif' title='" . $modfootertxt . "' alt='" . $modfootertxt . "'></a>"; |
|
887 | + $versioninfo = & $hModule->get($xoopsModule->getVar('mid')); |
|
888 | + $modfootertxt = 'Module '.$versioninfo->getInfo('name').' - Version '.$versioninfo->getInfo('version').''; |
|
889 | + $modfooter = "<a href='".$versioninfo->getInfo('support_site_url')."' target='_blank'><img src='".XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/assets/images/cssbutton.gif' title='".$modfootertxt."' alt='".$modfootertxt."'></a>"; |
|
890 | 890 | $tpl->assign('modfooter', $modfooter); |
891 | 891 | |
892 | 892 | if (!defined('_AM_SOBJECT_XOOPS_PRO')) { |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | } |
895 | 895 | $smartobjectConfig = static::getModuleConfig('smartobject'); |
896 | 896 | $tpl->assign('smartobject_enable_admin_footer', $smartobjectConfig['enable_admin_footer']); |
897 | - $tpl->display(SMARTOBJECT_ROOT_PATH . 'templates/smartobject_admin_footer.tpl'); |
|
897 | + $tpl->display(SMARTOBJECT_ROOT_PATH.'templates/smartobject_admin_footer.tpl'); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | public static function getXoopsCpFooter() |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | */ |
922 | 922 | public static function addScript($src) |
923 | 923 | { |
924 | - echo '<script src="' . $src . '" type="text/javascript"></script>'; |
|
924 | + echo '<script src="'.$src.'" type="text/javascript"></script>'; |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | /** |
@@ -930,16 +930,16 @@ discard block |
||
930 | 930 | public static function addStyle($src) |
931 | 931 | { |
932 | 932 | if ('smartobject' === $src) { |
933 | - $src = SMARTOBJECT_URL . 'assets/css/module.css'; |
|
933 | + $src = SMARTOBJECT_URL.'assets/css/module.css'; |
|
934 | 934 | } |
935 | 935 | echo static::getCssLink($src); |
936 | 936 | } |
937 | 937 | |
938 | 938 | public static function addAdminAjaxSupport() |
939 | 939 | { |
940 | - static::addScript(SMARTOBJECT_URL . 'include/scriptaculous/lib/prototype.js'); |
|
941 | - static::addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/scriptaculous.js'); |
|
942 | - static::addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/smart.js'); |
|
940 | + static::addScript(SMARTOBJECT_URL.'include/scriptaculous/lib/prototype.js'); |
|
941 | + static::addScript(SMARTOBJECT_URL.'include/scriptaculous/src/scriptaculous.js'); |
|
942 | + static::addScript(SMARTOBJECT_URL.'include/scriptaculous/src/smart.js'); |
|
943 | 943 | } |
944 | 944 | |
945 | 945 | /** |
@@ -999,8 +999,8 @@ discard block |
||
999 | 999 | public static function getHtmlnumericentities($str) |
1000 | 1000 | { |
1001 | 1001 | // return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str); |
1002 | - return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function ($m) { |
|
1003 | - return '&#' . ord($m[0]) . chr(59); |
|
1002 | + return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function($m) { |
|
1003 | + return '&#'.ord($m[0]).chr(59); |
|
1004 | 1004 | }, $str); |
1005 | 1005 | } |
1006 | 1006 | |
@@ -1014,16 +1014,16 @@ discard block |
||
1014 | 1014 | static $handlers; |
1015 | 1015 | $name = strtolower(trim($name)); |
1016 | 1016 | if (!isset($handlers[$name])) { |
1017 | - if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) { |
|
1017 | + if (file_exists($hnd_file = XOOPS_ROOT_PATH.'/kernel/'.$name.'.php')) { |
|
1018 | 1018 | require_once $hnd_file; |
1019 | 1019 | } |
1020 | - $class = 'Xoops' . ucfirst($name) . 'Handler'; |
|
1020 | + $class = 'Xoops'.ucfirst($name).'Handler'; |
|
1021 | 1021 | if (class_exists($class)) { |
1022 | 1022 | $handlers[$name] = new $class($GLOBALS['xoopsDB'], 'xoops'); |
1023 | 1023 | } |
1024 | 1024 | } |
1025 | 1025 | if (!isset($handlers[$name]) && !$optional) { |
1026 | - trigger_error('Class <b>' . $class . '</b> does not exist<br>Handler Name: ' . $name, E_USER_ERROR); |
|
1026 | + trigger_error('Class <b>'.$class.'</b> does not exist<br>Handler Name: '.$name, E_USER_ERROR); |
|
1027 | 1027 | } |
1028 | 1028 | if (isset($handlers[$name])) { |
1029 | 1029 | return $handlers[$name]; |
@@ -1103,9 +1103,9 @@ discard block |
||
1103 | 1103 | { |
1104 | 1104 | global $xoopsConfig; |
1105 | 1105 | |
1106 | - $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/' . $xoopsConfig['language'] . '/' . $file . '.php'; |
|
1106 | + $filename = XOOPS_ROOT_PATH.'/modules/'.$module.'/language/'.$xoopsConfig['language'].'/'.$file.'.php'; |
|
1107 | 1107 | if (!file_exists($filename)) { |
1108 | - $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/english/' . $file . '.php'; |
|
1108 | + $filename = XOOPS_ROOT_PATH.'/modules/'.$module.'/language/english/'.$file.'.php'; |
|
1109 | 1109 | } |
1110 | 1110 | if (file_exists($filename)) { |
1111 | 1111 | require_once $filename; |
@@ -1201,7 +1201,7 @@ discard block |
||
1201 | 1201 | |
1202 | 1202 | $text = preg_replace($search, $replace, $document); |
1203 | 1203 | |
1204 | - preg_replace_callback('/&#(\d+);/', function ($matches) { |
|
1204 | + preg_replace_callback('/&#(\d+);/', function($matches) { |
|
1205 | 1205 | return chr($matches[1]); |
1206 | 1206 | }, $document); |
1207 | 1207 | |
@@ -1224,21 +1224,21 @@ discard block |
||
1224 | 1224 | $str = $match[0]; |
1225 | 1225 | if (false !== strpos($str, ',')) { |
1226 | 1226 | // A comma exists, that makes it easy, cos we assume it separates the decimal part. |
1227 | - $str = str_replace('.', '', $str); // Erase thousand seps |
|
1228 | - $str = str_replace(',', '.', $str); // Convert , to . for floatval command |
|
1227 | + $str = str_replace('.', '', $str); // Erase thousand seps |
|
1228 | + $str = str_replace(',', '.', $str); // Convert , to . for floatval command |
|
1229 | 1229 | |
1230 | - return (float)$str; |
|
1230 | + return (float) $str; |
|
1231 | 1231 | } else { |
1232 | 1232 | // No comma exists, so we have to decide, how a single dot shall be treated |
1233 | 1233 | if (true === preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) && true === $set['single_dot_as_decimal']) { |
1234 | 1234 | // Treat single dot as decimal separator |
1235 | - return (float)$str; |
|
1235 | + return (float) $str; |
|
1236 | 1236 | } else { |
1237 | 1237 | //echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br><br> "; |
1238 | 1238 | // Else, treat all dots as thousand seps |
1239 | - $str = str_replace('.', '', $str); // Erase thousand seps |
|
1239 | + $str = str_replace('.', '', $str); // Erase thousand seps |
|
1240 | 1240 | |
1241 | - return (float)$str; |
|
1241 | + return (float) $str; |
|
1242 | 1242 | } |
1243 | 1243 | } |
1244 | 1244 | } else { |
@@ -1270,7 +1270,7 @@ discard block |
||
1270 | 1270 | $ret .= '.00'; |
1271 | 1271 | } |
1272 | 1272 | if ($currencyObj) { |
1273 | - $ret = $ret . ' ' . $currencyObj->getCode(); |
|
1273 | + $ret = $ret.' '.$currencyObj->getCode(); |
|
1274 | 1274 | } |
1275 | 1275 | |
1276 | 1276 | return $ret; |
@@ -1297,7 +1297,7 @@ discard block |
||
1297 | 1297 | } |
1298 | 1298 | $ret = ''; |
1299 | 1299 | if ($moduleName) { |
1300 | - $ret = "<a href='" . XOOPS_URL . "/modules/$moduleName/admin/index.php'>" . _CO_SOBJECT_ADMIN_PAGE . '</a>'; |
|
1300 | + $ret = "<a href='".XOOPS_URL."/modules/$moduleName/admin/index.php'>"._CO_SOBJECT_ADMIN_PAGE.'</a>'; |
|
1301 | 1301 | } |
1302 | 1302 | |
1303 | 1303 | return $ret; |
@@ -1308,7 +1308,7 @@ discard block |
||
1308 | 1308 | */ |
1309 | 1309 | public static function getEditors() |
1310 | 1310 | { |
1311 | - $filename = XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php'; |
|
1311 | + $filename = XOOPS_ROOT_PATH.'/class/xoopseditor/xoopseditor.php'; |
|
1312 | 1312 | if (!file_exists($filename)) { |
1313 | 1313 | return false; |
1314 | 1314 | } |
@@ -1332,9 +1332,9 @@ discard block |
||
1332 | 1332 | { |
1333 | 1333 | $ret = []; |
1334 | 1334 | foreach ($items as $item) { |
1335 | - $ret[] = $moduleName . '_' . $item; |
|
1335 | + $ret[] = $moduleName.'_'.$item; |
|
1336 | 1336 | } |
1337 | - $ret[] = $moduleName . '_meta'; |
|
1337 | + $ret[] = $moduleName.'_meta'; |
|
1338 | 1338 | |
1339 | 1339 | return $ret; |
1340 | 1340 | } |
@@ -28,82 +28,82 @@ |
||
28 | 28 | $op = isset($_POST['op']) ? $_POST['op'] : ''; |
29 | 29 | |
30 | 30 | switch ($op) { |
31 | - case 'sendlink': |
|
31 | + case 'sendlink': |
|
32 | 32 | |
33 | 33 | // require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php'; |
34 | - $controller = new XoopsModules\Smartobject\ObjectController($smartobjectLinkHandler); |
|
35 | - |
|
36 | - $linkObj = $controller->storeSmartObject(); |
|
37 | - if ($linkObj->hasError()) { |
|
38 | - /** |
|
39 | - * @todo inform user and propose to close the window if a problem occured when saving the link |
|
40 | - */ |
|
41 | - } |
|
42 | - |
|
43 | - $xoopsMailer = xoops_getMailer(); |
|
44 | - $xoopsMailer->useMail(); |
|
45 | - $xoopsMailer->setTemplateDir('language/' . $xoopsConfig['language'] . '/mail_template'); |
|
46 | - |
|
47 | - $xoopsMailer->setTemplate('sendlink.tpl'); |
|
48 | - $xoopsMailer->assign('X_SITENAME', $xoopsConfig['sitename']); |
|
49 | - $xoopsMailer->assign('TO_NAME', $linkObj->getVar('to_name')); |
|
50 | - $xoopsMailer->assign('FROM_NAME', $linkObj->getVar('from_name')); |
|
51 | - $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
52 | - $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
53 | - $xoopsMailer->assign('MESSAGE', $_POST['body']); |
|
54 | - $xoopsMailer->setToEmails($linkObj->getVar('to_email')); |
|
55 | - $xoopsMailer->setFromEmail($linkObj->getVar('from_email')); |
|
56 | - $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
57 | - $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_SUBJECT_DEFAULT, $myts->oopsStripSlashesGPC($xoopsConfig['sitename']))); |
|
58 | - |
|
59 | - if (!$xoopsMailer->send(true)) { |
|
60 | - $xoopsTpl->assign('send_error', sprintf(_CO_SOBJECT_SEND_ERROR, $xoopsConfig['adminmail']) . '<br>' . $xoopsMailer->getErrors(true)); |
|
61 | - } else { |
|
62 | - $xoopsTpl->assign('send_success', _CO_SOBJECT_SEND_SUCCESS); |
|
63 | - } |
|
64 | - |
|
65 | - break; |
|
66 | - |
|
67 | - default: |
|
68 | - if (isset($_GET['mid'])) { |
|
69 | - $mid = $_GET['mid']; |
|
70 | - } else { |
|
71 | - /** |
|
72 | - * @todo close the window if no mid is passed as GET |
|
73 | - */ |
|
74 | - } |
|
75 | - |
|
76 | - $hModule = xoops_getHandler('module'); |
|
77 | - $module = $hModule->get($mid); |
|
78 | - $linkObj->setVar('mid', $module->getVar('mid')); |
|
79 | - $linkObj->setVar('mid_name', $module->getVar('name')); |
|
80 | - |
|
81 | - if (isset($_GET['link'])) { |
|
82 | - $link = $_GET['link']; |
|
83 | - } else { |
|
84 | - /** |
|
85 | - * @todo close the window if no link is passed as GET |
|
86 | - */ |
|
87 | - } |
|
88 | - $linkObj->setVar('link', $link); |
|
89 | - |
|
90 | - if (is_object($xoopsUser)) { |
|
91 | - $linkObj->setVar('from_uid', $xoopsUser->getVar('uid')); |
|
92 | - $linkObj->setVar('from_name', '' !== $xoopsUser->getVar('name') ? $xoopsUser->getVar('name') : $xoopsUser->getVar('uname')); |
|
93 | - $linkObj->setVar('from_email', $xoopsUser->getVar('email')); |
|
94 | - } |
|
95 | - |
|
96 | - $linkObj->setVar('subject', sprintf(_CO_SOBJECT_SUBJECT_DEFAULT, $xoopsConfig['sitename'])); |
|
97 | - $linkObj->setVar('body', sprintf(_CO_SOBJECT_BODY_DEFAULT, $xoopsConfig['sitename'], $link)); |
|
98 | - $linkObj->setVar('date', time()); |
|
99 | - $linkObj->hideFieldFromForm(['from_uid', 'to_uid', 'link', 'mid', 'mid_name']); |
|
100 | - |
|
101 | - $form = $linkObj->getForm(_CO_SOBJECT_SEND_LINK_FORM, 'sendlink', false, _SEND, 'javascript:window.close();'); |
|
102 | - |
|
103 | - $form->assign($xoopsTpl); |
|
104 | - |
|
105 | - $xoopsTpl->assign('showform', true); |
|
106 | - break; |
|
34 | + $controller = new XoopsModules\Smartobject\ObjectController($smartobjectLinkHandler); |
|
35 | + |
|
36 | + $linkObj = $controller->storeSmartObject(); |
|
37 | + if ($linkObj->hasError()) { |
|
38 | + /** |
|
39 | + * @todo inform user and propose to close the window if a problem occured when saving the link |
|
40 | + */ |
|
41 | + } |
|
42 | + |
|
43 | + $xoopsMailer = xoops_getMailer(); |
|
44 | + $xoopsMailer->useMail(); |
|
45 | + $xoopsMailer->setTemplateDir('language/' . $xoopsConfig['language'] . '/mail_template'); |
|
46 | + |
|
47 | + $xoopsMailer->setTemplate('sendlink.tpl'); |
|
48 | + $xoopsMailer->assign('X_SITENAME', $xoopsConfig['sitename']); |
|
49 | + $xoopsMailer->assign('TO_NAME', $linkObj->getVar('to_name')); |
|
50 | + $xoopsMailer->assign('FROM_NAME', $linkObj->getVar('from_name')); |
|
51 | + $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
52 | + $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
53 | + $xoopsMailer->assign('MESSAGE', $_POST['body']); |
|
54 | + $xoopsMailer->setToEmails($linkObj->getVar('to_email')); |
|
55 | + $xoopsMailer->setFromEmail($linkObj->getVar('from_email')); |
|
56 | + $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
57 | + $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_SUBJECT_DEFAULT, $myts->oopsStripSlashesGPC($xoopsConfig['sitename']))); |
|
58 | + |
|
59 | + if (!$xoopsMailer->send(true)) { |
|
60 | + $xoopsTpl->assign('send_error', sprintf(_CO_SOBJECT_SEND_ERROR, $xoopsConfig['adminmail']) . '<br>' . $xoopsMailer->getErrors(true)); |
|
61 | + } else { |
|
62 | + $xoopsTpl->assign('send_success', _CO_SOBJECT_SEND_SUCCESS); |
|
63 | + } |
|
64 | + |
|
65 | + break; |
|
66 | + |
|
67 | + default: |
|
68 | + if (isset($_GET['mid'])) { |
|
69 | + $mid = $_GET['mid']; |
|
70 | + } else { |
|
71 | + /** |
|
72 | + * @todo close the window if no mid is passed as GET |
|
73 | + */ |
|
74 | + } |
|
75 | + |
|
76 | + $hModule = xoops_getHandler('module'); |
|
77 | + $module = $hModule->get($mid); |
|
78 | + $linkObj->setVar('mid', $module->getVar('mid')); |
|
79 | + $linkObj->setVar('mid_name', $module->getVar('name')); |
|
80 | + |
|
81 | + if (isset($_GET['link'])) { |
|
82 | + $link = $_GET['link']; |
|
83 | + } else { |
|
84 | + /** |
|
85 | + * @todo close the window if no link is passed as GET |
|
86 | + */ |
|
87 | + } |
|
88 | + $linkObj->setVar('link', $link); |
|
89 | + |
|
90 | + if (is_object($xoopsUser)) { |
|
91 | + $linkObj->setVar('from_uid', $xoopsUser->getVar('uid')); |
|
92 | + $linkObj->setVar('from_name', '' !== $xoopsUser->getVar('name') ? $xoopsUser->getVar('name') : $xoopsUser->getVar('uname')); |
|
93 | + $linkObj->setVar('from_email', $xoopsUser->getVar('email')); |
|
94 | + } |
|
95 | + |
|
96 | + $linkObj->setVar('subject', sprintf(_CO_SOBJECT_SUBJECT_DEFAULT, $xoopsConfig['sitename'])); |
|
97 | + $linkObj->setVar('body', sprintf(_CO_SOBJECT_BODY_DEFAULT, $xoopsConfig['sitename'], $link)); |
|
98 | + $linkObj->setVar('date', time()); |
|
99 | + $linkObj->hideFieldFromForm(['from_uid', 'to_uid', 'link', 'mid', 'mid_name']); |
|
100 | + |
|
101 | + $form = $linkObj->getForm(_CO_SOBJECT_SEND_LINK_FORM, 'sendlink', false, _SEND, 'javascript:window.close();'); |
|
102 | + |
|
103 | + $form->assign($xoopsTpl); |
|
104 | + |
|
105 | + $xoopsTpl->assign('showform', true); |
|
106 | + break; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | $xoopsTpl->display('db:smartobject_sendlink.tpl'); |
@@ -9,17 +9,17 @@ discard block |
||
9 | 9 | |
10 | 10 | use XoopsModules\Smartobject\ObjectController; |
11 | 11 | |
12 | -require_once __DIR__ . '/header.php'; |
|
12 | +require_once __DIR__.'/header.php'; |
|
13 | 13 | //require_once SMARTOBJECT_ROOT_PATH . 'class/smartloader.php'; |
14 | 14 | //require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectlink.php'; |
15 | -require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
15 | +require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|
16 | 16 | |
17 | 17 | $xoopsTpl = new \XoopsTpl(); |
18 | 18 | $myts = \MyTextSanitizer::getInstance(); |
19 | 19 | $xoopsConfig['sitename'] = $myts->displayTarea($xoopsConfig['sitename']); |
20 | 20 | |
21 | 21 | xoops_header(false); |
22 | -echo Smartobject\Utility::getCssLink(SMARTOBJECT_URL . 'assets/css/module.css'); |
|
22 | +echo Smartobject\Utility::getCssLink(SMARTOBJECT_URL.'assets/css/module.css'); |
|
23 | 23 | echo '</head><body>'; |
24 | 24 | |
25 | 25 | $smartobjectLinkHandler = Smartobject\Helper::getInstance()->getHandler('link', 'smartobject'); |
@@ -42,13 +42,13 @@ discard block |
||
42 | 42 | |
43 | 43 | $xoopsMailer = xoops_getMailer(); |
44 | 44 | $xoopsMailer->useMail(); |
45 | - $xoopsMailer->setTemplateDir('language/' . $xoopsConfig['language'] . '/mail_template'); |
|
45 | + $xoopsMailer->setTemplateDir('language/'.$xoopsConfig['language'].'/mail_template'); |
|
46 | 46 | |
47 | 47 | $xoopsMailer->setTemplate('sendlink.tpl'); |
48 | 48 | $xoopsMailer->assign('X_SITENAME', $xoopsConfig['sitename']); |
49 | 49 | $xoopsMailer->assign('TO_NAME', $linkObj->getVar('to_name')); |
50 | 50 | $xoopsMailer->assign('FROM_NAME', $linkObj->getVar('from_name')); |
51 | - $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
51 | + $xoopsMailer->assign('SITEURL', XOOPS_URL.'/'); |
|
52 | 52 | $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
53 | 53 | $xoopsMailer->assign('MESSAGE', $_POST['body']); |
54 | 54 | $xoopsMailer->setToEmails($linkObj->getVar('to_email')); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_SUBJECT_DEFAULT, $myts->oopsStripSlashesGPC($xoopsConfig['sitename']))); |
58 | 58 | |
59 | 59 | if (!$xoopsMailer->send(true)) { |
60 | - $xoopsTpl->assign('send_error', sprintf(_CO_SOBJECT_SEND_ERROR, $xoopsConfig['adminmail']) . '<br>' . $xoopsMailer->getErrors(true)); |
|
60 | + $xoopsTpl->assign('send_error', sprintf(_CO_SOBJECT_SEND_ERROR, $xoopsConfig['adminmail']).'<br>'.$xoopsMailer->getErrors(true)); |
|
61 | 61 | } else { |
62 | 62 | $xoopsTpl->assign('send_success', _CO_SOBJECT_SEND_SUCCESS); |
63 | 63 | } |
@@ -31,12 +31,12 @@ |
||
31 | 31 | */ |
32 | 32 | class FileHandler extends Smartobject\PersistableObjectHandler |
33 | 33 | { |
34 | - /** |
|
35 | - * SmartobjectFileHandler constructor. |
|
36 | - * @param \XoopsDatabase $db |
|
37 | - */ |
|
38 | - public function __construct(\XoopsDatabase $db) |
|
39 | - { |
|
40 | - parent::__construct($db, File::class, 'fileid', 'caption', 'desc', 'smartobject'); |
|
41 | - } |
|
34 | + /** |
|
35 | + * SmartobjectFileHandler constructor. |
|
36 | + * @param \XoopsDatabase $db |
|
37 | + */ |
|
38 | + public function __construct(\XoopsDatabase $db) |
|
39 | + { |
|
40 | + parent::__construct($db, File::class, 'fileid', 'caption', 'desc', 'smartobject'); |
|
41 | + } |
|
42 | 42 | } |
@@ -29,29 +29,29 @@ |
||
29 | 29 | */ |
30 | 30 | class BasedUrl extends Smartobject\BaseSmartObject |
31 | 31 | { |
32 | - /** |
|
33 | - * SmartobjectBasedUrl constructor. |
|
34 | - */ |
|
35 | - public function __construct() |
|
36 | - { |
|
37 | - $this->quickInitVar('caption', XOBJ_DTYPE_TXTBOX, false); |
|
38 | - $this->quickInitVar('description', XOBJ_DTYPE_TXTBOX, false); |
|
39 | - $this->quickInitVar('url', XOBJ_DTYPE_TXTBOX, false); |
|
40 | - } |
|
32 | + /** |
|
33 | + * SmartobjectBasedUrl constructor. |
|
34 | + */ |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + $this->quickInitVar('caption', XOBJ_DTYPE_TXTBOX, false); |
|
38 | + $this->quickInitVar('description', XOBJ_DTYPE_TXTBOX, false); |
|
39 | + $this->quickInitVar('url', XOBJ_DTYPE_TXTBOX, false); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param string $key |
|
44 | - * @param string $format |
|
45 | - * @return mixed |
|
46 | - */ |
|
47 | - public function getVar($key, $format = 'e') |
|
48 | - { |
|
49 | - if (0 === strpos($key, 'url_')) { |
|
50 | - return parent::getVar('url', $format); |
|
51 | - } elseif (0 === strpos($key, 'caption_')) { |
|
52 | - return parent::getVar('caption', $format); |
|
53 | - } else { |
|
54 | - return parent::getVar($key, $format); |
|
55 | - } |
|
56 | - } |
|
42 | + /** |
|
43 | + * @param string $key |
|
44 | + * @param string $format |
|
45 | + * @return mixed |
|
46 | + */ |
|
47 | + public function getVar($key, $format = 'e') |
|
48 | + { |
|
49 | + if (0 === strpos($key, 'url_')) { |
|
50 | + return parent::getVar('url', $format); |
|
51 | + } elseif (0 === strpos($key, 'caption_')) { |
|
52 | + return parent::getVar('caption', $format); |
|
53 | + } else { |
|
54 | + return parent::getVar($key, $format); |
|
55 | + } |
|
56 | + } |
|
57 | 57 | } |