PluginProbe
ANAC XML Bandi di Gara / 3
ANAC XML Bandi di Gara v3
7.8 trunk 0.1 1.0.0.1 1.0.1 1.0.2 1.0.3 1.0.4 1.1 1.1.1 1.1.2 2.0 2.0.1 2.0.2 2.0.3 2.1 2.2 2.3 2.3.1 3 3.0.1 3.1 3.1.1 3.1.2 3.1.3 All 57 releases
avcp / avcp.php

avcp.php in ANAC XML Bandi di Gara 3, at avcp.php

306 lines 11.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: AVCP XML
4 Plugin URI: http://www.marcomilesi.ml
5 Description: Generatore XML per l’AVCP (Autorità per la Vigilanza sui Contratti Pubblici di Lavori, Servizi e Forniture) // Art. 1 comma 32 Legge 190/2012.
6 Author: Marco Milesi
7 Version: 3.0
8 Author URI: http://www.marcomilesi.ml
9 */
10
11 add_action( 'init', 'register_cpt_avcp' );
12
13 function register_cpt_avcp() {
14
15 $labels = array(
16 'name' => _x( 'Gare', 'avcp' ),
17 'singular_name' => _x( 'Gara', 'avcp' ),
18 'add_new' => _x( 'Nuova Gara', 'avcp' ),
19 'add_new_item' => _x( 'Nuova Gara', 'avcp' ),
20 'edit_item' => _x( 'Modifica Gara', 'avcp' ),
21 'new_item' => _x( 'Nuova Gara', 'avcp' ),
22 'view_item' => _x( 'Vedi Gara', 'avcp' ),
23 'search_items' => _x( 'Cerca Gara', 'avcp' ),
24 'not_found' => _x( 'Nessuna voce trovata', 'avcp' ),
25 'not_found_in_trash' => _x( 'Nessuna voce trovata', 'avcp' ),
26 'parent_item_colon' => _x( 'Parent Gara:', 'avcp' ),
27 'menu_name' => _x( 'AVCP', 'avcp' ),
28 );
29
30 $get_avcp_abilita_ruoli = get_option('avcp_abilita_ruoli');
31 if ($get_avcp_abilita_ruoli == '1') {
32 $avcp_capability_type = 'gare_avcp';
33 $avcp_map_meta_cap_var = 'true';
34 $avcp_capabilities_array = array(
35 'publish_posts' => 'pubblicare_gara_avcp',
36 'edit_posts' => 'modificare_propri_gara_avcp',
37 'edit_others_posts' => 'modificare_altri_gara_avcp',
38 'delete_posts' => 'eliminare_propri_gara_avcp',
39 'delete_others_posts' => 'modificare_altri_gara_avcp',
40 'read_private_posts' => 'read_private_avcp',
41 'edit_post' => 'modificare_gara_avcp',
42 'delete_post' => 'eliminare_gara_avcp',
43 'read_post' => 'leggere_gara_avcp',
44 );
45 } else {
46 $avcp_capability_type = 'post';
47 $avcp_map_meta_cap_var = 'false';
48 }
49
50 $args = array(
51 'labels' => $labels,
52 'hierarchical' => false,
53 'description' => 'Gare AVCP',
54 'supports' => array( 'title', 'custom-fields', 'revisions' ),
55 'taxonomies' => array( 'ditte' ),
56 'public' => true,
57 'show_ui' => true,
58 'show_in_menu' => true,
59 'menu_position' => 20,
60 'menu_icon' => 'dashicons-portfolio',
61 'show_in_nav_menus' => false,
62 'publicly_queryable' => true,
63 'exclude_from_search' => false,
64 'has_archive' => true,
65 'query_var' => true,
66 'can_export' => true,
67 'rewrite' => true,
68 'capability_type' => $avcp_capability_type,
69 'map_meta_cap' => $avcp_map_meta_cap_var
70 );
71
72 register_post_type( 'avcp', $args );
73 }
74
75 add_action( 'init', 'register_taxonomy_ditte' );
76
77 function register_taxonomy_ditte() {
78
79 $labels = array(
80 'name' => _x( 'Ditta', 'ditte' ),
81 'singular_name' => _x( 'Ditte', 'ditte' ),
82 'search_items' => _x( 'Cerca Ditta', 'ditte' ),
83 'popular_items' => _x( 'Ditte più usate', 'ditte' ),
84 'all_items' => _x( 'Tutte le ditte', 'ditte' ),
85 'parent_item' => _x( 'Parent Ditte', 'ditte' ),
86 'parent_item_colon' => _x( 'Parent Ditte:', 'ditte' ),
87 'edit_item' => _x( 'Edit Ditte', 'ditte' ),
88 'update_item' => _x( 'Update Ditte', 'ditte' ),
89 'add_new_item' => _x( 'Nuova Ditta', 'ditte' ),
90 'new_item_name' => _x( 'Nuova Ditte', 'ditte' ),
91 'separate_items_with_commas' => _x( 'Separate ditta with commas', 'ditte' ),
92 'add_or_remove_items' => _x( 'Add or remove ditta', 'ditte' ),
93 'choose_from_most_used' => _x( 'Choose from the most used ditta', 'ditte' ),
94 'menu_name' => _x( 'Ditte', 'ditte' ),
95 );
96
97 $args = array(
98 'labels' => $labels,
99 'public' => true,
100 'show_in_nav_menus' => false,
101 'show_ui' => true,
102 'show_tagcloud' => false,
103 'show_admin_column' => true,
104 'hierarchical' => true,
105 'rewrite' => true,
106 'query_var' => true
107 );
108
109 register_taxonomy( 'ditte', array('avcp'), $args );
110 }
111
112 add_action( 'init', 'register_taxonomy_annirif' );
113
114 function register_taxonomy_annirif() {
115
116 $labels2 = array(
117 'name' => _x( 'Anno Riferimento', 'annirif' ),
118 'singular_name' => _x( 'Anno Riferimento', 'annirif' ),
119 'search_items' => _x( 'Cerca Anno', 'annirif' ),
120 'popular_items' => _x( 'Anni più Usati', 'annirif' ),
121 'all_items' => _x( 'Tutti gli anni', 'annirif' ),
122 'parent_item' => _x( 'Parent Anni', 'annirif' ),
123 'parent_item_colon' => _x( 'Parent Anno:', 'annirif' ),
124 'edit_item' => _x( 'Modifica Anno', 'annirif' ),
125 'update_item' => _x( 'Aggiorna Anno', 'annirif' ),
126 'add_new_item' => _x( 'Nuovo Anno', 'annirif' ),
127 'new_item_name' => _x( 'Nuovo Anno', 'annirif' ),
128 'separate_items_with_commas' => _x( 'Separate anno with commas', 'annirif' ),
129 'add_or_remove_items' => _x( 'Add or remove anno', 'annirif' ),
130 'choose_from_most_used' => _x( 'Choose from the most used years', 'annirif' ),
131 'menu_name' => _x( 'Anni', 'annirif' ),
132 );
133
134 $args = array(
135 'labels' => $labels2,
136 'public' => true,
137 'show_in_nav_menus' => true,
138 'show_ui' => true,
139 'show_tagcloud' => false,
140 'show_admin_column' => true,
141 'hierarchical' => true,
142 'rewrite' => true,
143 'capabilities' => array('manage_terms' => 'utentealieno','edit_terms' => 'utentealieno','delete_terms' => 'utentealieno'),
144 'query_var' => true
145 );
146
147 register_taxonomy( 'annirif', array('avcp'), $args );
148 $termcheck = term_exists('2013', 'annirif');
149 if ($termcheck == 0 || $termcheck == null) {
150 wp_insert_term('2013', 'annirif');
151 }
152 $termcheck = term_exists('2014', 'annirif');
153 if ($termcheck == 0 || $termcheck == null) {
154 wp_insert_term('2014', 'annirif');
155 }
156 }
157
158 add_action('save_post', 'save_at_gara_posts',10,2);
159 function save_at_gara_posts($post_id) {
160
161 $post = get_post($post_id);
162 // If this isn't a 'book' post, don't update it.
163 $slug = 'avcp'; if ( $slug != $post->post_type ) { return; }
164
165 $get_avcp_autopublish = get_option('avcp_autopublish');
166 if ($get_avcp_autopublish == '1') {
167 $terms = wp_get_post_terms($post_id, 'annirif');
168 $count = count($terms);
169 if (!($count > 0 )){
170 echo '<div class="error"><p>';
171 printf(__('AVCP | Errore: impossibile ricreare il file .xml: la gara inserita non ha ditte collegate' . $verificafilecreati));
172 echo "</p></div>";
173 }
174 require_once(plugin_dir_path(__FILE__) . 'avcp_xml_generator.php');
175 foreach ( $terms as $term ) {
176 creafilexml ($term->name);
177 $verificafilecreati = $term->name . ' - ' . $verificafilecreati;
178 }
179 echo '<div class="updated"><p>';
180 printf(__('AVCP | Generazione automatica del file .xml completata => ' . $verificafilecreati));
181 echo "</p></div>";
182 }
183 }
184
185 /* =========== Cambio Titolo Custom Post =========== */
186 function avcp_default_title($title)
187 {
188 $screen = get_current_screen();
189 if ('avcp' == $screen->post_type) {
190 $title = 'Inserire Oggetto della Gara';
191 }
192 return $title;
193 }
194 add_filter('enter_title_here', 'avcp_default_title');
195
196 function avcp_plugin() {
197 $api_key = 'abt3ep7uq9b2jzohwmefm3y5koqcsxguqx0a';
198 $auth = 'mpu9auof5dh2btpmmn59a0pdqh4w4x95k';
199 // Start of Metrics
200 global $wpdb;
201 $data = get_transient( 'presstrends_cache_data' );
202 if ( !$data || $data == '' ) {
203 $api_base = 'http://api.presstrends.io/index.php/api/pluginsites/update?auth=';
204 $url = $api_base . $auth . '&api=' . $api_key . '';
205 $count_posts = wp_count_posts();
206 $count_pages = wp_count_posts( 'page' );
207 $comments_count = wp_count_comments();
208 if ( function_exists( 'wp_get_theme' ) ) {
209 $theme_data = wp_get_theme();
210 $theme_name = urlencode( $theme_data->Name );
211 } else {
212 $theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' );
213 $theme_name = $theme_data['Name'];
214 }
215 $plugin_name = '&';
216 foreach ( get_plugins() as $plugin_info ) {
217 $plugin_name .= $plugin_info['Name'] . '&';
218 }
219 // CHANGE __FILE__ PATH IF LOCATED OUTSIDE MAIN PLUGIN FILE
220 $plugin_data = get_plugin_data( __FILE__ );
221 $posts_with_comments = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type='post' AND comment_count > 0" );
222 $data = array(
223 'url' => base64_encode(site_url()),
224 'posts' => $count_posts->publish,
225 'pages' => $count_pages->publish,
226 'comments' => $comments_count->total_comments,
227 'approved' => $comments_count->approved,
228 'spam' => $comments_count->spam,
229 'pingbacks' => $wpdb->get_var( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_type = 'pingback'" ),
230 'post_conversion' => ( $count_posts->publish > 0 && $posts_with_comments > 0 ) ? number_format( ( $posts_with_comments / $count_posts->publish ) * 100, 0, '.', '' ) : 0,
231 'theme_version' => $plugin_data['Version'],
232 'theme_name' => $theme_name,
233 'site_name' => str_replace( ' ', '', get_bloginfo( 'name' ) ),
234 'plugins' => count( get_option( 'active_plugins' ) ),
235 'plugin' => urlencode( $plugin_name ),
236 'wpversion' => get_bloginfo( 'version' ),
237 );
238 foreach ( $data as $k => $v ) {
239 $url .= '&' . $k . '=' . $v . '';
240 }
241 wp_remote_get( $url );
242 set_transient( 'presstrends_cache_data', $data, 60 * 60 * 24 );
243 }
244 }
245 // PressTrends WordPress Action
246 add_action('admin_init', 'avcp_plugin');
247
248 // Rimuove "Modifica Rapida" (per evitare di taggare gli anni ad cazzum)
249 add_filter( 'post_row_actions', 'avcp_remove_row_actions', 10, 1 );
250 function avcp_remove_row_actions( $actions )
251 {
252 if( get_post_type() === 'avcp' )
253 unset( $actions['inline hide-if-no-js'] );
254 return $actions;
255 }
256
257 /* =========== SHORTCODE ============ */
258
259 function avcp_func($atts)
260 {
261 extract(shortcode_atts(array(
262 'anno' => 'all',
263 ), $atts));
264 ob_start();
265 include(plugin_dir_path(__FILE__) . 'tablegen.php');
266 $atshortcode = ob_get_clean();
267 return $atshortcode;
268 }
269 add_shortcode('avcp', 'avcp_func');
270
271 add_action( 'init', 'atg_caricamoduli' );
272 function atg_caricamoduli() {
273 include(plugin_dir_path(__FILE__) . 'settings.php');
274 include(plugin_dir_path(__FILE__) . 'avcp_create_taxonomy.php');
275 require_once(plugin_dir_path(__FILE__) . 'meta-box-class/metabox.php');
276 require_once(plugin_dir_path(__FILE__) . 'tax-meta-class/Tax-meta-class.php');
277 require_once(plugin_dir_path(__FILE__) . 'avcp_taxonomy_fields.php');
278 require_once(plugin_dir_path(__FILE__) . 'avcp_metabox_generator.php');
279 require_once(plugin_dir_path(__FILE__) . 'avcp_index_generator.php');
280 require_once(plugin_dir_path(__FILE__) . 'singlehack.php');
281 require_once(plugin_dir_path(__FILE__) . 'avcp_xml_generator.php');
282 include(plugin_dir_path(__FILE__) . 'alerts.php');
283 include(plugin_dir_path(__FILE__) . 'styledbackend.php');
284 require_once(plugin_dir_path(__FILE__) . 'taxfilteringbackend.php');
285 require_once(plugin_dir_path(__FILE__) . 'searchTaxonomy/searchTaxonomyGT.php');
286
287 //Include sistemi di validazione
288 include(plugin_dir_path(__FILE__) . 'valid_check.php');
289 include(plugin_dir_path(__FILE__) . 'valid_page.php');
290
291 global $typenow;
292 if ($typenow == 'avcp') {
293 add_filter( 'manage_posts_custom_column', 'avcp_modify_post_table_row', 10, 2 );
294 add_filter( 'manage_posts_custom_column', 'avcp_modify_post_table' );
295 }
296 }
297
298 function avcp_activate() {
299 $srcfile= ABSPATH . 'wp-content/plugins/avcp/includes/index.php.null';
300 $dstfile= ABSPATH . 'avcp/index.php';
301 mkdir(dirname($dstfile), 0755, true);
302 copy($srcfile, $dstfile);
303 chmod($dstfile, 0755);
304 }
305 register_activation_hook( __FILE__, 'avcp_activate' );
306 ?>