-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsinglehack.php
More file actions
388 lines (311 loc) · 13.7 KB
/
singlehack.php
File metadata and controls
388 lines (311 loc) · 13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<?php
/**
* AVCP Single Post Content Filter
*
* Enhances the content display for AVCP post types with additional metadata
* and contractor information.
*
* @package AVCP
* @since 1.0.0
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
/**
* AVCP Single Post Content Filter
*
* Enhances the content display for AVCP post types with additional metadata
* and contractor information.
*
* @package AVCP
* @since 1.0.0
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
/**
* Generates the basic contract information table
*
* @param int $post_id The post ID
* @param array $options Cached options array
* @return string HTML table content
*/
function avcp_generate_contract_info_table($post_id, $options) {
$html = '<table>';
// CIG
$html .= '<tr><td><acronym title="' . esc_attr__('Codice Identificativo Gara', 'avcp') . '">CIG:</acronym></td><td>' . esc_html(get_post_meta($post_id, 'avcp_cig', true)) . '</td></tr>';
// Proposing structure
$html .= '<tr><td>' . esc_html__('Struttura proponente:', 'avcp') . '</td><td>' . esc_html($options['denominazione_ente']);
// Area sectors
$html .= avcp_generate_area_sectors($post_id);
$html .= '<br/>' . esc_html($options['codicefiscale_ente']) . '</td></tr>';
// Contract details
$html .= '<tr><td>' . esc_html__('Oggetto del bando:', 'avcp') . '</td><td>' . esc_html(get_the_title($post_id)) . '</td></tr>';
// Check if avcp_get_contraente function exists
if (function_exists('avcp_get_contraente')) {
$contraente = avcp_get_contraente(get_post_meta($post_id, 'avcp_contraente', true));
$html .= '<tr><td>' . esc_html__('Procedura di scelta del contraente:', 'avcp') . '</td><td>' . esc_html(strtolower($contraente)) . '</td></tr>';
}
// Award amount
$aggiudicazione_amount = get_post_meta($post_id, 'avcp_aggiudicazione', true);
$html .= '<tr><td>' . esc_html__('Importo di aggiudicazione:', 'avcp') . '</td><td>€ <strong>' . esc_html($aggiudicazione_amount) . '</strong></td></tr>';
// Dates
$html .= avcp_generate_contract_dates($post_id);
// Liquidated amounts
$html .= avcp_generate_liquidated_amounts($post_id);
// Reference year
$html .= avcp_generate_reference_year($post_id, $options);
$html .= '</table>';
return $html;
}
/**
* Generates area sectors information
*
* @param int $post_id The post ID
* @return string HTML content for area sectors
*/
function avcp_generate_area_sectors($post_id) {
$html = '';
$terms = get_the_terms($post_id, 'areesettori');
if ($terms && !is_wp_error($terms)) {
foreach($terms as $term) {
if (!is_object($term) || empty($term->name)) {
continue;
}
$get_term = get_term_by('name', $term->name, 'areesettori');
if (!$get_term || is_wp_error($get_term)) {
continue;
}
$tsr_id = absint($get_term->term_id);
// Check if get_tax_meta function exists before using it
if (function_exists('get_tax_meta')) {
$id_sec_red_var = get_tax_meta($tsr_id, 'aree_settori_cc_url');
if ($id_sec_red_var) {
$permalink = get_permalink(absint($id_sec_red_var));
if ($permalink) {
$html .= ' - <a href="' . esc_url($permalink) . '">' . esc_html($term->name) . '</a>';
}
}
$id_sec_cc_var = get_tax_meta($tsr_id, 'aree_settori_cc_responsabile');
if (!empty($id_sec_cc_var)) {
$html .= ' - [<acronym title="' . esc_attr__('Responsabile del Centro di Costo', 'avcp') . '">resp. <b>' . esc_html($id_sec_cc_var) . '</b></acronym>]';
}
} else {
// Fallback if get_tax_meta doesn't exist
$html .= ' - ' . esc_html($term->name);
}
}
}
return $html;
}
/**
* Generates contract dates section
*
* @param int $post_id The post ID
* @return string HTML content for dates
*/
function avcp_generate_contract_dates($post_id) {
$d_inizio = sanitize_text_field(get_post_meta($post_id, 'avcp_data_inizio', true));
$d_fine = sanitize_text_field(get_post_meta($post_id, 'avcp_data_fine', true));
$avcp_data_inizio = $d_inizio ? date_i18n("d/m/Y", strtotime($d_inizio)) : esc_html__('n.d.', 'avcp');
$avcp_data_fine = $d_fine ? date_i18n("d/m/Y", strtotime($d_fine)) : esc_html__('n.d.', 'avcp');
$html = '<tr><td>' . esc_html__('Data di effettivo inizio:', 'avcp') . '</td><td>' . esc_html($avcp_data_inizio) . '</td></tr>';
$html .= '<tr><td>' . esc_html__('Data di ultimazione:', 'avcp') . '</td><td>' . esc_html($avcp_data_fine) . '</td></tr>';
return $html;
}
/**
* Generates liquidated amounts section
*
* @param int $post_id The post ID
* @return string HTML content for liquidated amounts
*/
function avcp_generate_liquidated_amounts($post_id) {
$html = '<tr><td>' . esc_html__('Importo delle somme liquidate:', 'avcp') . '</td><td>';
$current_year = date('Y');
for ($i = 2013; $i <= $current_year + 10; $i++) {
$amount = get_post_meta($post_id, 'avcp_s_l_' . absint($i), true);
if ($amount && floatval($amount) > 0) {
$html .= '<strong>' . absint($i) . '</strong>: ' . esc_html($amount) . '<br>';
}
}
$html .= '</td></tr>';
return $html;
}
/**
* Generates reference year section
*
* @param int $post_id The post ID
* @param array $options Cached options array
* @return string HTML content for reference year
*/
function avcp_generate_reference_year($post_id, $options) {
global $post;
$html = '<tr><td>' . esc_html__('Anno di riferimento:', 'avcp') . '</td><td>';
if ($options['dis_archivioanni'] == '1') {
$term_list = get_the_term_list($post->ID, 'annirif', '', ' - ', '');
$html .= wp_strip_all_tags($term_list);
} else {
$html .= get_the_term_list($post->ID, 'annirif', '', ' - ', '');
}
$html .= '</td></tr>';
return $html;
}
/**
* Generates the participating operators table
*
* @param int $post_id The post ID
* @param array $options Cached options array
* @return string HTML table content
*/
function avcp_generate_participating_operators($post_id, $options) {
global $post;
$html = '<h3>' . esc_html__('Elenco degli operatori partecipanti', 'avcp') . '</h3>';
$html .= '<table>';
$terms = get_the_terms($post->ID, 'ditte');
if ($terms && !is_wp_error($terms)) {
foreach($terms as $term) {
if (!is_object($term) || empty($term->name)) {
continue;
}
$get_term = get_term_by('name', $term->name, 'ditte');
if (!$get_term || is_wp_error($get_term)) {
continue;
}
$t_id = absint($get_term->term_id);
$term_meta = get_option("taxonomy_$t_id");
$term_return = '';
if (is_array($term_meta) && isset($term_meta['avcp_codice_fiscale'])) {
$term_return = esc_attr($term_meta['avcp_codice_fiscale']);
}
$is_estera = '<acronym title="' . esc_attr__('Identificativo Fiscale Italiano', 'avcp') . '">IT</acronym>';
// Check if get_tax_meta function exists before using it
if (function_exists('get_tax_meta')) {
$stato_var = get_tax_meta($t_id, 'avcp_is_ditta_estera');
$is_estera = empty($stato_var) ?
'<acronym title="' . esc_attr__('Identificativo Fiscale Italiano', 'avcp') . '">IT</acronym>' :
'<acronym title="' . esc_attr__('Identificativo Fiscale Estero', 'avcp') . '">EE</acronym>';
}
$html .= '<tr><td>';
if ($options['dis_archivioditte'] == '1') {
$html .= esc_html($term->name);
} else {
$term_link = get_term_link($t_id, 'ditte');
if (!is_wp_error($term_link)) {
$html .= '<a href="' . esc_url($term_link) . '" title="' . esc_attr($term->name) . '">' . esc_html($term->name) . '</a>';
} else {
$html .= esc_html($term->name);
}
}
$html .= '</td><td>' . esc_html($term_return) . ' - <b>' . $is_estera . '</b></td></tr>';
}
}
$html .= '</table>';
return $html;
}
/**
* Generates the winning operators table
*
* @param int $post_id The post ID
* @param array $options Cached options array
* @return string HTML table content
*/
function avcp_generate_winning_operators($post_id, $options) {
global $post;
$html = '<h3>' . esc_html__('Elenco degli operatori aggiudicatari', 'avcp') . '</h3>';
$html .= '<table>';
$dittepartecipanti = get_the_terms($post->ID, 'ditte');
$cats = get_post_meta($post->ID, 'avcp_aggiudicatari', true);
if (is_array($dittepartecipanti) && !is_wp_error($dittepartecipanti)) {
$has_winners = false;
foreach ($dittepartecipanti as $term) {
if (!is_object($term) || empty($term->name)) {
continue;
}
$cterm = get_term_by('name', $term->name, 'ditte');
if (!$cterm || is_wp_error($cterm)) {
continue;
}
$cat_id = absint($cterm->term_id);
$term_meta = get_option("taxonomy_$cat_id");
$term_return = '';
if (is_array($term_meta) && isset($term_meta['avcp_codice_fiscale'])) {
$term_return = esc_attr($term_meta['avcp_codice_fiscale']);
}
$checked = (in_array($cat_id, (array)$cats) ? ' checked="checked"' : "");
$is_estera = '<acronym title="' . esc_attr__('Identificativo Fiscale Italiano', 'avcp') . '">IT</acronym>';
// Check if get_tax_meta function exists before using it
if (function_exists('get_tax_meta')) {
$stato_var = get_tax_meta($cat_id, 'avcp_is_ditta_estera');
$is_estera = empty($stato_var) ?
'<acronym title="' . esc_attr__('Identificativo Fiscale Italiano', 'avcp') . '">IT</acronym>' :
'<acronym title="' . esc_attr__('Identificativo Fiscale Estero', 'avcp') . '">EE</acronym>';
}
if ($checked) {
$has_winners = true;
$html .= '<tr><td>';
if ($options['dis_archivioditte'] != '1') {
$term_link = get_term_link($cterm->term_id, 'ditte');
if (!is_wp_error($term_link)) {
$html .= '<a href="' . esc_url($term_link) . '" title="' . esc_attr($term->name) . '">';
}
}
$html .= esc_html($term->name);
if ($options['dis_archivioditte'] != '1' && !is_wp_error($term_link)) {
$html .= '</a>';
}
$html .= '</td><td>' . esc_html($term_return) . ' - <b>' . $is_estera . '</b></td></tr>';
}
}
if (!$has_winners) {
$html .= '<tr><td>' . esc_html__('Nessun aggiudicatario...', 'avcp') . '</td></tr>';
}
} else {
$html .= '<tr><td>' . esc_html__('Nessun aggiudicatario...', 'avcp') . '</td></tr>';
}
$html .= '</table>';
return $html;
}
/**
* Generates the WPGov footer if enabled
*
* @param array $options Cached options array
* @return string HTML content for footer
*/
function avcp_generate_footer($options) {
$html = '';
if ($options['wpgov_show_love']) {
$html .= '<center><a href="http://www.wpgov.it" target="_blank" title="' . esc_attr__('Software © WPGov', 'avcp') . '"><img style="margin:5px;" src="' . esc_url(plugin_dir_url(__FILE__) . 'images/wpgov.png') . '" alt="' . esc_attr__('WPGov Logo', 'avcp') . '" /></a></center>';
}
return $html;
}
add_filter('the_content', function($content) {
global $post;
// Validate post object and type
if (!is_object($post) || empty($post->post_type) || $post->post_type !== 'avcp') {
return $content;
}
// Validate post ID
$post_id = absint($post->ID);
if (!$post_id || !get_post($post_id)) {
return $content;
}
// Cache options to avoid multiple queries
$options = array(
'denominazione_ente' => get_option('avcp_denominazione_ente', ''),
'codicefiscale_ente' => get_option('avcp_codicefiscale_ente', ''),
'dis_archivioanni' => get_option('avcp_dis_archivioanni'),
'dis_archivioditte' => get_option('avcp_dis_archivioditte'),
'wpgov_show_love' => get_option('wpgov_show_love')
);
// Build the content
$prev = '<br/>';
$prev .= avcp_generate_contract_info_table($post_id, $options);
$prev .= avcp_generate_participating_operators($post_id, $options);
$prev .= avcp_generate_winning_operators($post_id, $options);
$prev .= avcp_generate_footer($options);
return $prev . $content;
}
);
?>