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