__( 'Magazine', 'aip_magazine' ), 'name' => __( 'Articles', 'aip_magazine' ), 'singular_name' => __( 'Article', 'aip_magazine' ), 'all_items' => __( 'Articles', 'aip_magazine' ), 'add_new' => __( 'Add New Article', 'aip_magazine' ), 'add_new_item' => __( 'Add New Article', 'aip_magazine' ), 'edit_item' => __( 'Edit Article', 'aip_magazine' ), 'new_item' => __( 'New Article', 'aip_magazine' ), 'view_item' => __( 'View Article', 'aip_magazine' ), 'search_items' => __( 'Search Articles', 'aip_magazine' ), 'not_found' => __( 'No articles found', 'aip_magazine' ), 'not_found_in_trash' => __( 'No articles found in trash', 'aip_magazine' ), 'parent_item_colon' => __( 'Parent Item', 'aip_magazine' ), ); $args = array( 'label' => __( 'article', 'aip_magazine' ), 'labels' => $labels, 'description' => __( 'AipMagazine Articles', 'aip_magazine' ), 'public' => true, 'publicly_queryable' => true, 'exclude_fromsearch' => false, 'show_ui' => true, 'show_in_menu' => true, 'capability_type' => array( 'article', 'articles' ), 'map_meta_cap' => true, 'hierarchical' => false, 'supports' => array( 'title', 'author', 'editor', 'comments', 'revisions', 'thumbnail', 'excerpt', 'trackbacks', 'page-attributes'), 'register_meta_box_cb' => 'add_aip_magazine_articles_metaboxes', 'has_archive' => true, 'rewrite' => array( 'slug' => 'article' ), 'taxonomies' => $taxonomies, 'menu_icon' => AIPMAGAZINE_URL . '/images/aip_magazine-16x16.png', 'show_in_admin_bar' => true, 'show_in_nav_menus' => false, 'menu_position' => 25, ); register_post_type( 'aip_article', $args ); if ( 'true' === get_option( 'aip_magazine_flush_rewrite_rules' ) ) { // ATTENTION: This is *only* done during plugin activation hook in this example! // You should *NEVER EVER* do this on every page load!! flush_rewrite_rules(); delete_option( 'aip_magazine_flush_rewrite_rules' ); } } add_action( 'init', 'create_article_post_type' ); } if ( !function_exists( 'aip_magazine_article_columns' ) ) { /** * Registers metaboxes for AipMagazine Articles * * @since 1.0.0 */ function aip_magazine_article_columns($columns) { $columns['aip_magazine-fascicolo'] = __( 'Issue', 'aip_magazine' ); $columns['aip_magazine-rubrica'] = __( 'Category', 'aip_magazine' ); $columns['menu_order'] = __( 'Sorting', 'aip_magazine' ); unset($columns['author']); unset($columns['comments']); return $columns; } add_filter('manage_edit-aip_article_columns', 'aip_magazine_article_columns',10,1); } if ( !function_exists( 'aip_magazine_article_custom_column' ) ) { function aip_magazine_article_custom_column( $column) { global $post; $post_custom = get_post( $post->ID); if ('aip_magazine-fascicolo' == $column){ $term = wp_get_post_terms( $post_custom->ID, 'aip_magazine_issue' ); if (isset($term[0]->name)) $fascicolo = $term[0]->name; else $fascicolo = ''; echo esc_attr( htmlspecialchars($fascicolo)); } if ('aip_magazine-rubrica' == $column){ $term = wp_get_post_terms( $post_custom->ID, 'aip_magazine_issue_categories' ); if (isset($term[0]->name)) $rubrica = $term[0]->name; else $rubrica = ''; echo esc_attr( htmlspecialchars($rubrica)); } if ('menu_order' == $column){ echo esc_attr(htmlspecialchars($post_custom->menu_order)); } } add_action( 'manage_posts_custom_column' , 'aip_magazine_article_custom_column'); } if ( !function_exists( 'aip_magazine_aip_article_sortable_columns' ) ) { /** * Filters sortable columns * * @since 1.0.0 * * @param array $columns * @return array $columns */ function aip_magazine_article_sortable_columns( $columns ) { $columns['menu_order'] = 'menu_order'; return $columns; } add_filter( 'manage_edit-aip_article_sortable_columns', 'aip_magazine_article_sortable_columns', 10, 1 ); } if ( !function_exists( 'aip_magazine_article_add_post_thumbnails' ) ) { function aip_magazine_article_add_post_thumbnails() { $supported_post_types = get_theme_support( 'post-thumbnails' ); if( false === $supported_post_types ) { $post_types = array( 'aip_article' ); add_theme_support( 'post-thumbnails', $post_types ); } else if ( is_array( $supported_post_types ) ) { $post_types = $supported_post_types[0]; $post_types[] = 'aip_article'; add_theme_support( 'post-thumbnails', $post_types ); } } add_action( 'after_setup_theme', 'aip_magazine_article_add_post_thumbnails', 99 ); } if ( !function_exists( 'add_aip_magazine_articles_metaboxes' ) ) { /** * Registers metaboxes for AipMagazine Articles * * @since 1.0.0 */ function add_aip_magazine_articles_metaboxes() { add_meta_box( 'aip_magazine_article_meta_box', __( 'AipMagazine Article Options', 'aip_magazine' ), 'aip_magazine_article_meta_box', 'aip_article', 'normal', 'high' ); do_action( 'add_aip_magazine_articles_metaboxes' ); } } if ( !function_exists( 'aip_magazine_article_meta_box' ) ) { /** * Outputs Article HTML for options metabox * * @since 1.0.0 * * @param object $post WordPress post object */ function aip_magazine_article_meta_box( $post ) { global $pagenow; /**/ $autori = get_post_meta( $post->ID, '_autori', true ); // funzioni per visualizzare un pdf $pdf_post = get_post_meta($post->ID, '_wp_custom_attachment', true); $first_page = get_post_meta( $post->ID, '_first_page', true ); $last_page = get_post_meta( $post->ID, '_last_page', true ); $teaser_text = get_post_meta( $post->ID, '_teaser_text', true ); $featured_rotator = get_post_meta( $post->ID, '_featured_rotator', true ); $featured_thumb = get_post_meta( $post->ID, '_featured_thumb', true ); ?>

/>

/>



​

' . __( 'View PDF Version', 'aip_magazine' ) . '

'; if(strlen(trim($pdf_post['url'])) > 0) { $remove_pdf = '

' . __( 'Remove PDF Version', 'aip_magazine' ) . '

'; } // end if } else { $view_pdf = ''; $remove_pdf = ''; } ?>




term_id; } wp_set_object_terms( $post_id, $termId, 'aip_magazine_issue_categories' ); } } if ( !empty( $_POST['teaser_text'] ) ) update_post_meta( $post_id, '_teaser_text', sanitize_text_field($_POST['teaser_text']) ); else delete_post_meta( $post_id, '_teaser_text' ); if ( !empty( $_POST['featured_rotator'] ) ) update_post_meta( $post_id, '_featured_rotator', sanitize_text_field($_POST['featured_rotator'] )); else delete_post_meta( $post_id, '_featured_rotator' ); if ( !empty( $_POST['featured_thumb'] ) ) update_post_meta( $post_id, '_featured_thumb', sanitize_text_field($_POST['featured_thumb']) ); else delete_post_meta( $post_id, '_featured_thumb' ); if ( !empty( $_POST['autori'] ) ) update_post_meta( $post_id, '_autori', wp_specialchars_decode(sanitize_textarea_field($_POST['autori'])) ); else delete_post_meta( $post_id, '_autori' ); // Make sure the file array isn't empty if(!empty($_FILES['wp_custom_attachment']['name'])) { // Setup the array of supported file types. In this case, it's just PDF. $supported_types = array('application/pdf'); // Get the file type of the upload $arr_file_type = wp_check_filetype(basename(sanitize_textarea_field($_FILES['wp_custom_attachment']['name']))); $uploaded_type = $arr_file_type['type']; // Check if the type is supported. If not, throw an error. if(in_array($uploaded_type, $supported_types)) { // Use the WordPress API to upload the file $upload = wp_upload_bits($_FILES['wp_custom_attachment']['name'], null, file_get_contents(sanitize_textarea_field($_FILES['wp_custom_attachment']['tmp_name']))); if(isset($upload['error']) && $upload['error'] != 0) { wp_die('There was an error uploading your file. The error is: ' . $upload['error']); } else { update_post_meta( $post_id, '_wp_custom_attachment', $upload); } // end if/else } else { wp_die("The file type that you've uploaded is not a PDF."); } // end if/else }else{ // Grab a reference to the file associated with this post $doc = get_post_meta($post_id, '_wp_custom_attachment', true); // Determine if a file is associated with this post and if the delete flag has been set (by clearing out the input box) if(isset($_POST['_view_pdf'])){ if ($_POST['_view_pdf'] == '0'){ // Attempt to remove the file. If deleting it fails, print a WordPress error. if(unlink($doc['file'])) { // Delete succeeded so reset the WordPress meta data delete_post_meta($post_id, '_wp_custom_attachment'); } else { wp_die('There was an error trying to delete your file.'); } // end if/el;se } // end if } } // end if/else if ( !empty( $_POST['first_page'] ) ) update_post_meta( $post_id, '_first_page', wp_specialchars_decode(sanitize_text_field($_POST['first_page'])) ); else delete_post_meta( $post_id, '_first_page' ); if ( !empty( $_POST['last_page'] ) ) update_post_meta( $post_id, '_last_page', wp_specialchars_decode(sanitize_text_field($_POST['last_page'])) ); else delete_post_meta( $post_id, '_last_page' ); do_action( 'save_aip_magazine_aip_article_meta', $post_id ); } add_action( 'save_post', 'save_aip_magazine_aip_article_meta' ); } //funzione per inserire un filtro di ricerca relativo alle riviste nella lista degli articoli if ( !function_exists( 'aip_magazine_filter_list_journals' ) ) { /** * Registers fliter for AipMagazine Articles * * @since 1.0.0 */ function aip_magazine_filter_list_journals() { $screen = get_current_screen(); global $wp_query; if ( $screen->post_type == 'aip_article' ) { wp_dropdown_categories( array( 'show_option_all' => __('Show All Journals','aip_magazine'), 'taxonomy' => 'aip_magazine_issue_journals', 'name' => 'aip_magazine_issue_journals', 'orderby' => 'name', 'order' => 'desc', 'selected' => ( isset( $wp_query->query['aip_magazine_issue_journals'] ) ? $wp_query->query['aip_magazine_issue_journals'] : '' ), 'hierarchical' => true, 'depth' => 3, 'show_count' => false, 'hide_empty' => true, 'parent' => '-1', ) ); } } add_action( 'restrict_manage_posts', 'aip_magazine_filter_list_journals' ); } if ( !function_exists( 'aip_magazine_perform_filtering_journals' ) ) { /** * Registers fliter for AipMagazine Articles * * @since 1.0.0 */ function aip_magazine_perform_filtering_journals($query) { global $pagenow; $qv = &$query->query_vars; if( $pagenow=='edit.php' && isset($qv['aip_magazine_issue_journals']) && is_numeric($qv['aip_magazine_issue_journals']) ){ if ($qv['aip_magazine_issue_journals'] != 0){ $term = get_term_by( 'id', $qv['aip_magazine_issue_journals'], 'aip_magazine_issue_journals' ); $qv['aip_magazine_issue_journals'] = $term->slug; } } } add_filter( 'parse_query','aip_magazine_perform_filtering_journals' ); } //funzione per inserire un filtro di ricerca relativo al fascicolo nella lista degli articoli if ( !function_exists( 'aip_magazine_filter_list_issue' ) ) { /** * Registers fliter for AipMagazine Articles * * @since 1.0.0 */ function aip_magazine_filter_list_issue() { $screen = get_current_screen(); global $wp_query; if ( $screen->post_type == 'aip_article' ) { if (isset($_REQUEST['aip_magazine_issue_journals'])){ wp_dropdown_categories( array( 'show_option_all' => __('Show All Issues','aip_magazine'), 'taxonomy' => 'aip_magazine_issue', 'name' => 'aip_magazine_issue', 'orderby' => 'name', 'order' => 'desc', 'selected' => ( isset( $wp_query->query['aip_magazine_issue'] ) ? $wp_query->query['aip_magazine_issue'] : '' ), 'hierarchical' => true, 'depth' => 3, 'show_count' => false, 'hide_empty' => true, 'exclude' => get_ids_issue_journals(sanitize_key($_REQUEST['aip_magazine_issue_journals'])), ) ); } } } add_action( 'restrict_manage_posts', 'aip_magazine_filter_list_issue' ); } if ( !function_exists( 'aip_magazine_perform_filtering_issue' ) ) { /** * Registers fliter for AipMagazine Articles * * @since 1.0.0 */ function aip_magazine_perform_filtering_issue($query) { global $pagenow; $qv = &$query->query_vars; if( $pagenow=='edit.php' && isset($qv['aip_magazine_issue']) && is_numeric($qv['aip_magazine_issue']) ){ if ($qv['aip_magazine_issue'] != 0){ $term = get_term_by( 'id', $qv['aip_magazine_issue'], 'aip_magazine_issue' ); $qv['aip_magazine_issue'] = $term->slug; } } } add_filter( 'parse_query','aip_magazine_perform_filtering_issue' ); } //funzione per inserire un filtro di ricerca relativo alle rubriche nella lista degli articoli if ( !function_exists( 'aip_magazine_filter_list_categories' ) ) { /** * Registers fliter for AipMagazine Articles * * @since 1.0.0 */ function aip_magazine_filter_list_categories() { $screen = get_current_screen(); global $wp_query; if ( $screen->post_type == 'aip_article' ) { if (isset( $_REQUEST['aip_magazine_issue_journals'] )){ wp_dropdown_categories( array( 'show_option_all' => __('Show All Categories','aip_magazine'), 'taxonomy' => 'aip_magazine_issue_categories', 'name' => 'aip_magazine_issue_categories', 'orderby' => 'name', 'order' => 'desc', 'selected' => ( isset( $wp_query->query['aip_magazine_issue_categories'] ) ? $wp_query->query['aip_magazine_issue_categories'] : '' ), 'hierarchical' => true, 'depth' => 3, 'show_count' => false, 'hide_empty' => true, 'exclude' => get_ids_issue_journals(sanitize_key($_REQUEST['aip_magazine_issue_journals'])), ) ); } } } add_action( 'restrict_manage_posts', 'aip_magazine_filter_list_categories' ); } if ( !function_exists( 'aip_magazine_perform_filtering_categories' ) ) { /** * Registers fliter for AipMagazine Articles * * @since 1.0.0 */ function aip_magazine_perform_filtering_categories($query) { global $pagenow; $qv = &$query->query_vars; if( $pagenow=='edit.php' && isset($qv['aip_magazine_issue_categories']) && is_numeric($qv['aip_magazine_issue_categories']) ){ if ($qv['aip_magazine_issue_categories'] != 0){ $term = get_term_by( 'id', $qv['aip_magazine_issue_categories'], 'aip_magazine_issue_categories' ); $qv['aip_magazine_issue_categories'] = $term->slug; } } } add_filter( 'parse_query','aip_magazine_perform_filtering_categories' ); } if ( !function_exists( 'get_ids_issue_journals' ) ) { function get_ids_issue_journals($parent) { global $wpdb; $term_ids = array(); $term_taxonomy_children = $wpdb->get_col( 'SELECT term_id FROM ' . $wpdb->term_taxonomy . ' WHERE parent <> '.$parent); foreach( $term_taxonomy_children as $children_id ) $term_ids[] = $children_id; if (isset($term_ids)) return $term_ids; } } if ( !function_exists( 'get_ids_issue_journals_hidden' ) ) { function get_ids_issue_journals_hidden() { global $wpdb; $term_ids_hidden = array(); $term_taxonomy_children = $wpdb->get_col( 'SELECT term_id FROM ' . $wpdb->term_taxonomy . ' WHERE taxonomy ="aip_magazine_issue_journals"' ); foreach( $term_taxonomy_children as $children_id ) $term_ids_hidden[] = $children_id; if (isset($term_ids_hidden)) return $term_ids_hidden; } } if ( !function_exists( 'get_ids_issue_hidden' ) ) { function get_ids_issue_hidden($parent) { global $wpdb; $term_ids_issue_hidden = array(); $term_taxonomy_children = $wpdb->get_col( 'SELECT term_id FROM ' . $wpdb->term_taxonomy . ' WHERE taxonomy ="aip_magazine_issue" AND parent = '.$parent ); foreach( $term_taxonomy_children as $children_id ) $term_ids_issue_hidden[] = $children_id; if (isset($term_ids_issue_hidden)) return $term_ids_issue_hidden; } } if ( !function_exists( 'get_ids_categories_hidden' ) ) { function get_ids_categories_hidden($parent) { global $wpdb; $term_ids_categories_hidden = array(); $term_taxonomy_children = $wpdb->get_col( 'SELECT term_id FROM ' . $wpdb->term_taxonomy . ' WHERE taxonomy ="aip_magazine_issue_categories" AND parent = '.$parent ); foreach( $term_taxonomy_children as $children_id ) $term_ids_categories_hidden[] = $children_id; if (isset($term_ids_categories_hidden)) return $term_ids_categories_hidden; } } if ( !function_exists( 'get_last_menu_order' ) ) { /** * Return last article in an issue * @since 2.1.0 * */ function get_last_menu_order($term_taxonomy_id) { global $wpdb; $query = 'SELECT MAX(' . $wpdb->posts . '.menu_order) FROM ' . $wpdb->posts . ' INNER JOIN '. $wpdb->term_relationships .' ON ' . $wpdb->posts . '.ID = '. $wpdb->term_relationships .'.object_id WHERE ' . $wpdb->posts . '.post_type = "aip_article" AND ' . $wpdb->posts . '.post_status = "publish" AND '. $wpdb->term_relationships .'.term_taxonomy_id = '.$term_taxonomy_id; $last_menu_order = $wpdb->get_col( $query ); return $last_menu_order[0]; } }