public function userEditorChoice() { if ($this->user_editor_choice !== null) { return $this->user_editor_choice; } if (!$this->getId()) { return false; } $content_template_id = wpv_getget('ct_id'); if ($editor_choice = get_post_meta($content_template_id, $this->option_name_editor_choice, true)) { $this->user_editor_choice = $editor_choice; return $editor_choice; } elseif ($editor_choice = get_post_meta($content_template_id, 'wpv_ct_editor_choice', true)) { $this->user_editor_choice = $editor_choice; update_post_meta($content_template_id, $this->option_name_editor_choice, $editor_choice); delete_post_meta($content_template_id, 'wpv_ct_editor_choice'); return $editor_choice; } elseif (get_post_type($content_template_id) == $this->slug) { update_post_meta($content_template_id, $this->option_name_editor_choice, 'basic'); return 'basic'; } return false; }
function wpv_admin_archive_listing_name( $views_pre_query_data, $current_post_status ) { global $WP_Views, $WPV_settings, $WPV_view_archive_loop; // array of URL modifiers $mod_url = array( 'orderby' => '', 'order' => '', 's' => '', 'items_per_page' => '', 'paged' => '', 'status' => $current_post_status ); // array of WP_Query parameters $wpv_args = array( 'post_type' => 'view', 'post__in' => $views_pre_query_data[ 'post__in' ], 'posts_per_page' => WPV_ITEMS_PER_PAGE, 'order' => 'ASC', 'orderby' => 'title', 'post_status' => $current_post_status ); $search_string = wpv_getget( 's', '' ); $is_search = ( '' != $search_string ); if ( $is_search ) { // perform the search in WPA titles and decriptions and add post__in argument to $wpv_args. $wpv_args = wpv_modify_wpquery_for_search( $search_string, $wpv_args ); $mod_url['s'] = sanitize_text_field( $search_string ); } $search_term = urldecode( sanitize_text_field( $search_string ) ); $items_per_page = (int) wpv_getget( 'items_per_page', 0 ); // 0 means "not set" if ( $items_per_page > 0 || $items_per_page == -1 ) { $wpv_args['posts_per_page'] = $items_per_page; $mod_url['items_per_page'] = $items_per_page; } $orderby = sanitize_text_field( wpv_getget( 'orderby' ) ); $order = sanitize_text_field( wpv_getget( 'order' ) ); if ( '' != $orderby ) { $wpv_args['orderby'] = $orderby; $mod_url['orderby'] = $orderby; if ( '' != $order ) { $wpv_args['order'] = $order; $mod_url['order'] = $order; } } $paged = (int) wpv_getget( 'paged', 0 ); if ( $paged > 0 ) { $wpv_args['paged'] = $paged; $mod_url['paged'] = $paged; } $wpv_query = new WP_Query( $wpv_args ); // The number of WPAs being displayed. $wpv_count_posts = $wpv_query->post_count; // Total number of WPAs matching query parameters. $wpv_found_posts = $wpv_query->found_posts; ?> <!-- links to lists WPA in different statuses --> <ul class="subsubsub"> <li> <?php // Show link to published WPA templates. // We show this link as current only if there is no search. $is_plain_publish_current_status = ( 'publish' == $current_post_status && ! $is_search ); printf( '<a href="%s" %s >%s</a> (%s) |', esc_url( add_query_arg( array( 'page' => 'view-archives', 'status' => 'publish' ), admin_url( 'admin.php' ) ) ), $is_plain_publish_current_status ? 'class="current"' : '', __( 'Published', 'wpv-views' ), $views_pre_query_data['published_count'] ); ?> </li> <li> <?php // Show link to trashed WPA templates. // We show this link as current only if there is no search. $is_plain_trash_current_status = ( 'trash' == $current_post_status && ! $is_search ); printf( '<a href="%s" %s >%s</a> (%s)', esc_url( add_query_arg( array( 'page' => 'view-archives', 'status' => 'trash' ), admin_url( 'admin.php' ) ) ), $is_plain_trash_current_status ? 'class="current"' : '', __( 'Trash', 'wpv-views' ), $views_pre_query_data['trashed_count'] ); ?> </li> </ul> <div style="clear:both;"></div> <?php if ( !$WPV_view_archive_loop->check_archive_loops_exists() ) { ?> <p id="js-wpv-no-archive" class="toolset-alert toolset-alert-success"> <?php _e('All loops have a WordPress Archive assigned','wpv-views'); ?> </p> <?php } if ( $wpv_count_posts > 0 ) { // A nonce for WPA action - used for individual as well as for bulk actions $wpa_action_nonce = wp_create_nonce( 'wpv_view_listing_actions_nonce' ); // === Render "tablenav" section (Bulk actions and Search box) === echo '<div class="tablenav top">'; // Prepare ender bulk actions dropdown. if( 'publish' == $current_post_status ) { $bulk_actions = array( 'trash' => __( 'Move to trash', 'wpv-views' ) ); } else { $bulk_actions = array( 'restore-from-trash' => __( 'Restore from trash', 'wpv-views' ), 'delete' => __( 'Delete permanently', 'wpv-views' ) ); } $bulk_actions_args = array( 'data-viewactionnonce' => $wpa_action_nonce ); $bulk_actions_class = 'js-wpv-wpa-listing-bulk-action'; echo wpv_admin_table_bulk_actions( $bulk_actions, $bulk_actions_class, $bulk_actions_args, 'top' ); // Show search box ?> <div class="alignright"> <form id="posts-filter" action="" method="get"> <p class="search-box"> <label class="screen-reader-text" for="post-search-input"><?php _e('Search WordPress Archives','wpv-views'); ?>:</label> <input type="search" id="post-search-input" name="s" value="<?php echo $search_term; ?>" /> <input type="submit" name="" id="search-submit" class="button" value="<?php echo htmlentities( __( 'Search WordPress Archives', 'wpv-views' ), ENT_QUOTES ); ?>" /> <input type="hidden" name="paged" value="1" /> </p> </form> </div> <?php echo '</div>'; // End of tablenav section ?> <table id="wpv_view_list" class="js-wpv-views-listing wpv-views-listing wpv-views-listing-by-name widefat"> <thead> <?php /* To avoid code duplication, table header is stored in output buffer and echoed twice - within * thead and tfoot tags. */ ob_start(); ?> <tr> <th class="wpv-admin-listing-col-bulkactions check-column"> <input type="checkbox" /> </th> <?php $column_active = ''; $column_sort_to = 'ASC'; $column_sort_now = 'ASC'; if ( $wpv_args['orderby'] === 'title' ) { $column_active = ' views-list-sort-active'; $column_sort_to = ( $wpv_args['order'] === 'ASC' ) ? 'DESC' : 'ASC'; $column_sort_now = $wpv_args['order']; } ?> <th class="wpv-admin-listing-col-title"> <?php // "sort by title" link printf( '<a href="%s" class="%s", data-orderby="title">%s <i class="%s"></i></a>', wpv_maybe_add_query_arg( array( 'page' => 'view-archives', 'orderby' => 'title', 'order' => $column_sort_to, 's' => $mod_url['s'], 'items_per_page' => $mod_url['items_per_page'], 'paged' => $mod_url['paged'], 'status' => $mod_url['status'] ), admin_url( 'admin.php' ) ), 'js-views-list-sort views-list-sort' . $column_active, __( 'Title', 'wpv-views' ), ( 'DESC' === $column_sort_now ) ? 'icon-sort-by-alphabet-alt' : 'icon-sort-by-alphabet' ); ?> </th> <th class="wpv-admin-listing-col-usage"><?php _e('Archive usage','wpv-views') ?></th> <?php $column_active = ''; $column_sort_to = 'DESC'; $column_sort_now = 'DESC'; if ( $wpv_args['orderby'] === 'date' ) { $column_active = ' views-list-sort-active'; $column_sort_to = ( $wpv_args['order'] === 'ASC' ) ? 'DESC' : 'ASC'; $column_sort_now = $wpv_args['order']; } ?> <th class="wpv-admin-listing-col-date"> <?php // "sort by date" link printf( '<a href="%s" class="%s" data-orderby="date">%s <i class="%s"></i></a>', wpv_maybe_add_query_arg( array( 'page' => 'view-archives', 'orderby' => 'date', 'order' => $column_sort_to, 's' => $mod_url['s'], 'items_per_page' => $mod_url['items_per_page'], 'paged' => $mod_url['paged'], 'status' => $mod_url['status'] ), admin_url( 'admin.php' ) ), 'js-views-list-sort views-list-sort ' . $column_active, __( 'Date', 'wpv-views' ), ( 'DESC' === $column_sort_now ) ? 'icon-sort-by-attributes-alt' : 'icon-sort-by-attributes' ); ?> </th> </tr> <?php // Get table header from output buffer and stop buffering $table_header = ob_get_contents(); ob_end_clean(); echo $table_header; ?> </thead> <tfoot> <?php echo $table_header; ?> </tfoot> <tbody class="js-wpv-views-listing-body"> <?php $loops = $WPV_view_archive_loop->_get_post_type_loops(); $builtin_loops = array( 'home-blog-page' => __('Home/Blog', 'wpv-views'), 'search-page' => __('Search results', 'wpv-views'), 'author-page' => __('Author archives', 'wpv-views'), 'year-page' => __('Year archives', 'wpv-views'), 'month-page' => __('Month archives', 'wpv-views'), 'day-page' => __('Day archives', 'wpv-views') ); $taxonomies = get_taxonomies('', 'objects'); $exclude_tax_slugs = array(); $exclude_tax_slugs = apply_filters( 'wpv_admin_exclude_tax_slugs', $exclude_tax_slugs ); $alternate = ''; while ( $wpv_query->have_posts() ) : $wpv_query->the_post(); $post_id = get_the_id(); $post = get_post($post_id); $view_settings = $WP_Views->get_view_settings( $post_id ); $view_description = get_post_meta($post_id, '_wpv_description', true); $alternate = ' alternate' == $alternate ? '' : ' alternate'; ?> <tr id="wpv_view_list_row_<?php echo $post->ID; ?>" class="js-wpv-view-list-row <?php echo $alternate; ?>" > <th class="wpv-admin-listing-col-bulkactions check-column"> <?php printf( '<input type="checkbox" value="%s" name="wpa[]" />', $post->ID ); ?> </th> <td class="wpv-admin-listing-col-title"> <span class="row-title"> <?php if ( 'trash' == $current_post_status ) { echo esc_html( trim( $post->post_title ) ); } else { // Title + edit link printf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'page' => 'view-archives-editor', 'view_id' => $post->ID ), admin_url( 'admin.php' ) ) ), esc_html( trim( $post->post_title ) ) ); } ?> </span> <?php // Show the description if there is any. if ( isset( $view_description ) && '' != $view_description ) { ?> <p class="desc"> <?php echo nl2br( $view_description ); ?> </p> <?php } /* Generate and show row actions. * Note that we want to add also 'simple' action names to the action list because * they get echoed as a class of the span tag and get styled by WordPress core css * accordingly (e.g. trash in different colour than the rest) */ $row_actions = array(); if ( 'publish' == $current_post_status ) { $row_actions['edit'] = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'page' => 'view-archives-editor', 'view_id' => $post->ID ), admin_url( 'admin.php' ) ) ), __( 'Edit', 'wpv-views' ) ); /* Note that hash in <a href="#"> is present so the link behaves like a link. * <a href=""> causes problems with colorbox and with mere <a> the mouse cursor * doesn't change when hovering over the link. */ if ( $view_settings['view-query-mode'] == 'archive' ) { $row_actions['change js-list-views-action-change'] = sprintf( '<a href="#">%s</a>', __( 'Change archive usage', 'wpv-views' ) ); } $row_actions['trash js-list-views-action-trash'] = sprintf( '<a href="#">%s</a>', __( 'Move to trash', 'wpv-views' ) ); } else if ( 'trash' == $current_post_status ) { $row_actions['restore-from-trash js-list-views-action-restore-from-trash'] = sprintf( '<a href="#">%s</a>', __( 'Restore from trash', 'wpv-views' ) ); $row_actions['delete js-list-views-action-delete'] = sprintf( '<a href="#">%s</a>', __( 'Delete', 'wpv-views' ) ); } echo wpv_admin_table_row_actions( $row_actions, array( "data-view-id" => $post->ID, "data-viewactionnonce" => $wpa_action_nonce ) ); ?> </td> <td class="wpv-admin-listing-col-usage"> <?php if ( $view_settings['view-query-mode'] == 'archive' ) { $selected = array(); foreach ( $loops as $loop => $loop_name ) { if ( isset( $WPV_settings[ 'view_' . $loop ] ) && $WPV_settings[ 'view_' . $loop ] == $post->ID ) { $not_built_in = ''; if ( !isset( $builtin_loops[ $loop ] ) ) { $not_built_in = __(' (post type archive)', 'wpv-views' ); } $selected[] = '<li>' . $loop_name . $not_built_in . '</li>'; } } foreach ( $taxonomies as $category_slug => $category ) { if ( in_array( $category_slug, $exclude_tax_slugs ) ) { continue; } // Only show taxonomies with show_ui set to TRUE if ( !$category->show_ui ) { continue; } $name = $category->name; if ( isset ( $WPV_settings[ 'view_taxonomy_loop_' . $name ] ) && $WPV_settings[ 'view_taxonomy_loop_' . $name ] == $post->ID ) { $selected[] = '<li>' . $category->labels->name . __(' (taxonomy archive)', 'wpv-views') . '</li>'; } } if ( !empty( $selected ) ) { ?> <ul class="wpv-taglike-list js-list-views-loops"> <?php echo implode( $selected ); ?> </ul> <?php } else { _e( 'This WordPress Archive isn\'t being used for any loops.', 'wpv-views' ); } } else if ( $view_settings['view-query-mode'] == 'layouts-loop' ) { _e( 'This WordPress Archive is part of a Layout, so it will display the archive(s) to which the Layout is assigned.', 'wpv-views' ); } ?> </td> <td class="wpv-admin-listing-col-date"> <?php echo get_the_time( get_option( 'date_format' ), $post->ID ); ?> </td> </tr> <?php endwhile; ?> </tbody> </table> <div class="tablenav bottom"> <?php echo wpv_admin_table_bulk_actions( $bulk_actions, $bulk_actions_class, $bulk_actions_args, 'bottom' ); ?> </div> <p class="add-new-view js-add-new-view"> <a class="button js-wpv-views-archive-add-new wpv-views-archive-add-new" href="#"> <i class="icon-plus"></i><?php _e('Add new WordPress Archive','wpv-views') ?> </a> </p> <?php wpv_admin_listing_pagination( 'view-archives', $wpv_found_posts, $wpv_args["posts_per_page"], $mod_url ); } else { // No WordPress Archives matches the criteria ?> <div class="wpv-views-listing views-empty-list"> <?php if ( 'trash' == $current_post_status && $is_search ) { printf( '<p>%s</p><p><a class="button-secondary" href="%s">%s</a></p>', __( 'No WordPress Archives in trash matched your criteria.', 'wpv-views' ), wpv_maybe_add_query_arg( array( 'page' => 'view-archives', 'orderby' => $mod_url['orderby'], 'order' => $mod_url['order'], 'items_per_page' => $mod_url['items_per_page'], 'paged' => '1', 'status' => 'trash' ), admin_url( 'admin.php' ) ), __( 'Return', 'wpv-views' ) ); } else if ( 'trash' == $current_post_status ) { printf( '<p>%s</p><p><a class="button-secondary" href="%s">%s</a></p>', __( 'No WordPress Archives in trash.', 'wpv-views' ), wpv_maybe_add_query_arg( array( 'page' => 'view-archives', 'orderby' => $mod_url['orderby'], 'order' => $mod_url['order'], 'items_per_page' => $mod_url['items_per_page'], 'paged' => '1' ), admin_url( 'admin.php' ) ), __( 'Return', 'wpv-views' ) ); } else if ( $is_search ) { printf( '<p>%s</p><p><a class="button-secondary" href="%s">%s</a></p>', __( 'No WordPress Archives matched your criteria.', 'wpv-views' ), wpv_maybe_add_query_arg( array( 'page' => 'view-archives', 'orderby' => $mod_url['orderby'], 'order' => $mod_url['order'], 'items_per_page' => $mod_url['items_per_page'], 'paged' => '1' ), admin_url( 'admin.php' ) ), __( 'Return', 'wpv-views' ) ); } else { ?> <p><?php _e( 'WordPress Archives let you customize the output of standard Archive pages.' );?></p> <p> <?php // "Create your first archive" link printf( '<a href="#" class="button js-wpv-views-archive-create-new"><i class="icon-plus"></i> %s</a>', __( 'Create your first WordPress Archive', 'wpv-views' ) ); ?> </p> <?php } ?> </div> <?php } }
/** * Render HTML for the dialog to change CT assignment. * * Expects following GET parameters: * - wpnonce: A valid work_view_template nonce. * - id: Valid ID of a Content Template * * @since unknown */ function wpv_change_ct_usage_popup() { wpv_ajax_authenticate( 'work_view_template', array( 'parameter_source' => 'get', 'type_of_death' => 'data' ) ); $id = intval( wpv_getget( 'id', 0 ) ); $ct = WPV_Content_Template::get_instance( $id ); if( null == $ct ) { $data = array( 'type' => 'error', 'message' => __( 'Invalid CT ID.', 'wpv-views' ) ); wp_send_json_error( $data ); } ob_start(); ?> <div class="wpv-dialog wpv-shortcode-gui-content-wrapper js-wpv-dialog-add-new-content-template wpv-dialog-add-new-content-template"> <h3><?php _e('What content will this template be for?','wpv-views') ?></h3> <form method="" id="wpv-add-new-content-template-form"> <?php wpv_render_ct_assignment_sections( $ct ); ?> </form> </div> <?php $response = ob_get_clean(); $data = array( 'dialog_content' => $response ); wp_send_json_success( $data ); }
/** * wpv_admin_menu_views_listing_page * * Creates the main structure of the Views admin listing page: wrapper and header * */ function wpv_admin_menu_views_listing_page() { ?> <div class="wrap toolset-views"> <div class="wpv-views-listing-page"> <?php // 'trash' or 'publish' $current_post_status = wpv_getget('status', 'publish', array('trash', 'publish')); $search_term = urldecode(sanitize_text_field(wpv_getget('s'))); // IDs of possible results and counts per post status $views_pre_query_data = wpv_prepare_view_listing_query('normal', $current_post_status); // Do we have any Views at all? $has_views = $views_pre_query_data['total_count'] > 0; // general nonce // TODO please do NOT use this general nonce wp_nonce_field('work_views_listing', 'work_views_listing'); ?> <div id="icon-views" class="icon32"></div> <h2><!-- classname wpv-page-title removed --> <?php _e('Views', 'wpv-views'); printf(' <a href="#" class="add-new-h2 js-wpv-views-add-new-top">%s</a>', __('Add new View', 'wpv-views')); // TODO maybe have this nonce as a data attribute for all buttons opening the popup wp_nonce_field('wp_nonce_create_view_wrapper', 'wp_nonce_create_view_wrapper'); if (!empty($search_term)) { if ('trash' == $current_post_status) { $search_message = __('Search results for "%s" in trashed Views', 'wpv-views'); } else { $search_message = __('Search results for "%s"', 'wpv-views'); } ?> <span class="subtitle"> <?php echo sprintf($search_message, $search_term); ?> </span> <?php } ?> </h2> <?php // Messages: trashed, untrashed, deleted add_filter('wpv_maybe_show_listing_message_undo', 'wpv_admin_view_listing_message_undo', 10, 3); wpv_maybe_show_listing_message('trashed', __('View moved to the Trash.', 'wpv-views'), __('%d Views moved to the Trash.', 'wpv-views'), true); wpv_maybe_show_listing_message('untrashed', __('View restored from the Trash.', 'wpv-views'), __('%d Views restored from the Trash.', 'wpv-views')); wpv_maybe_show_listing_message('deleted', __('View permanently deleted.', 'wpv-views'), __('%d Views permanently deleted.', 'wpv-views')); if ($has_views) { // Display the rest of the content if there are Views to list wpv_admin_view_listing_table($views_pre_query_data, $current_post_status); } else { // Show a message in any other case ?> <div class="wpv-view-not-exist js-wpv-view-not-exist"> <p><?php _e('Views load content from the database and display on the site.'); ?> </p> <p> <a class="button js-wpv-views-add-first" href="#"> <i class="icon-plus"></i> <?php _e('Create your first View', 'wpv-views'); ?> </a> </p> </div> <?php } ?> </div> <!-- .wpv-views-listing-page" --> </div> <!-- .toolset-views" --> <?php wpv_render_view_listing_dialog_templates(); }
function wpv_admin_enqueue_scripts( $hook ) {// echo $hook; TODO this function needs a lot of love parent::wpv_admin_enqueue_scripts( $hook ); $page = wpv_getget( 'page' ); // Basic WordPress scripts & styles if ( ! wp_script_is( 'wp-pointer' ) ) { wp_enqueue_script('wp-pointer'); } if ( ! wp_style_is( 'wp-pointer' ) ) { wp_enqueue_style('wp-pointer'); } if ( ! wp_script_is( 'thickbox' ) ) { wp_enqueue_script('thickbox'); // TODO maybe DEPRECATED } if ( ! wp_style_is( 'thickbox' ) ) { wp_enqueue_style('thickbox'); // TODO maybe DEPRECATED } $wpv_custom_admin_pages = array( 'views', 'view-archives', 'view-templates', 'views-editor', 'view-archives-editor', WPV_CT_EDITOR_PAGE_NAME, 'views-update-help' ); $wpv_custom_admin_pages = apply_filters( 'wpv_filter_wpv_custom_admin_pages', $wpv_custom_admin_pages ); $wpv_custom_admin_edit_pages = array( 'views-editor', 'view-archives-editor', WPV_CT_EDITOR_PAGE_NAME ); $wpv_custom_admin_edit_pages = apply_filters( 'wpv_filter_wpv_custom_admin_edit_pages', $wpv_custom_admin_edit_pages ); if ( in_array( $page, $wpv_custom_admin_pages ) || strpos( $_SERVER['QUERY_STRING'], 'help.php') !== false ) { if ( ! wp_script_is( 'views-utils-script' ) ) { wp_enqueue_script( 'views-utils-script'); } if ( ! wp_style_is( 'views-admin-css' ) ) { wp_enqueue_style( 'views-admin-css' ); } } if ( $page == 'views' && ! wp_script_is( 'views-listing-script' ) ) { wp_enqueue_script( 'views-listing-script' ); } if ( $page == 'view-archives' && ! wp_script_is( 'views-archive-listing-script' ) ) { wp_enqueue_script( 'views-archive-listing-script' ); } if ( $page == 'view-templates' && ! wp_script_is( 'views-content-template-listing-script' ) ) { wp_enqueue_script( 'views-content-template-listing-script' ); } if ( $page == 'views-editor' ) {// TODO WTF is it doing here? delete_transient('wpv_layout_wizard_save_settings'); } if ( in_array( $page, $wpv_custom_admin_edit_pages ) ) { // Custom edit pages need the shortcodes GUI and Codemirror if ( ! wp_script_is( 'views-shortcodes-gui-script' ) ) { wp_enqueue_script( 'views-shortcodes-gui-script' ); } if ( ! wp_script_is( 'views-codemirror-conf-script' ) ) { wp_enqueue_script( 'views-codemirror-conf-script' ); } if ( ! wp_style_is( 'views-codemirror-css' ) ) { wp_enqueue_style( 'views-codemirror-css' ); } if ( ! wp_style_is( 'views-admin-css' ) ) { wp_enqueue_style( 'views-admin-css' ); } // Quicktags styles if ( ! wp_style_is( 'editor-buttons' ) ) { wp_enqueue_style( 'editor-buttons' ); } } // Views help screen // @todo transform this into a real page if ( $hook == 'wp-views/menu/help.php' ) { wp_enqueue_style( 'views-admin-css' ); } if ( 'views-editor' == $page ) { if ( ! wp_script_is( 'views-editor-js' ) ) { wp_enqueue_script( 'views-editor-js' ); } if ( ! wp_script_is( 'views-filters-js' ) ) { wp_enqueue_script( 'views-filters-js' ); } if ( ! wp_script_is( 'views-pagination-js' ) ) { wp_enqueue_script( 'views-pagination-js' ); } if ( ! wp_script_is( 'views-update-js' ) ) { wp_enqueue_script( 'views-update-js' ); } if ( ! wp_script_is( 'views-layout-template-js' ) ) { wp_enqueue_script( 'views-layout-template-js' ); } if ( ! wp_script_is( 'views-layout-wizard-script' ) ) { wp_enqueue_script( 'views-layout-wizard-script' ); } if ( function_exists( 'wp_enqueue_media' ) && ! wp_script_is( 'icl_media-manager-js' ) ) { wp_enqueue_media(); if ( ! wp_script_is( 'views-redesign-media-manager-js' ) ) { wp_enqueue_script( 'views-redesign-media-manager-js' ); } } //Enqueue suggestion script wp_enqueue_script( 'views-suggestion_script' ); wp_enqueue_style ('views_suggestion_style'); wp_enqueue_style ('views_suggestion_style2'); } if ( 'view-archives-editor' == $page ) { if ( ! wp_script_is( 'views-archive-editor-js' ) ) { wp_enqueue_script( 'views-archive-editor-js' ); } if ( ! wp_script_is( 'views-archive-update-js' ) ) { wp_enqueue_script( 'views-archive-update-js' ); } if ( ! wp_script_is( 'views-layout-template-js' ) ) { wp_enqueue_script( 'views-layout-template-js' ); } if ( ! wp_script_is( 'views-layout-wizard-script' ) ) { wp_enqueue_script( 'views-layout-wizard-script' ); } if ( function_exists( 'wp_enqueue_media' ) && ! wp_script_is( 'icl_media-manager-js' ) ) { wp_enqueue_media(); if ( ! wp_script_is( 'views-redesign-media-manager-js' ) ) { wp_enqueue_script( 'views-redesign-media-manager-js' ); } } } if ( $page == 'views-update-help' ) { wp_enqueue_script( 'views-update-help-js' ); } }
function wpv_admin_enqueue_scripts($hook) { $page = wpv_getget('page'); // Assets for the shortcodes GUI $force_load_shortcodes_gui_assets = array('dd_layouts_edit'); $force_load_shortcodes_gui_assets = apply_filters('wpv_filter_wpv_force_load_shortcodes_gui_assets', $force_load_shortcodes_gui_assets); if ($hook == 'post.php' || $hook == 'post-new.php' || in_array($page, $force_load_shortcodes_gui_assets)) { if (!wp_script_is('views-shortcodes-gui-script')) { wp_enqueue_script('views-shortcodes-gui-script'); } if (!wp_script_is('jquery-ui-resizable')) { wp_enqueue_script('jquery-ui-resizable'); } if (!wp_style_is('views-admin-css')) { wp_enqueue_style('views-admin-css'); } } if ($page == 'dd_layouts_edit') { if (!wp_script_is('views-codemirror-conf-script')) { wp_enqueue_script('views-codemirror-conf-script'); } if (!wp_style_is('views-codemirror-css')) { wp_enqueue_style('views-codemirror-css'); } } // Assets for embedded listing pages if (in_array($hook, array('toplevel_page_embedded-views', 'views_page_embedded-views-templates', 'views_page_embedded-views-archives'))) { if (!wp_script_is('views-embedded-listing-pages-script')) { wp_enqueue_script('views-embedded-listing-pages-script'); } if (!wp_style_is('views-admin-css')) { wp_enqueue_style('views-admin-css'); } } // Assets for embedded edit pages if (in_array($page, array('views-embedded', 'view-templates-embedded', 'view-archives-embedded', 'ModuleManager_Modules'))) { if (!wp_script_is('views-codemirror-conf-script')) { wp_enqueue_script('views-codemirror-conf-script'); } if (!wp_style_is('views-codemirror-css')) { wp_enqueue_style('views-codemirror-css'); } if (!wp_script_is('views-embedded-script')) { wp_enqueue_script('views-embedded-script'); } if (!wp_script_is('views-utils-script')) { wp_enqueue_script('views-utils-script'); } if (!wp_style_is('views-admin-css')) { wp_enqueue_style('views-admin-css'); } } // Assets for the Widgets page if ($hook == 'widgets.php') { if (!wp_script_is('views-widgets-gui-script')) { wp_enqueue_script('views-widgets-gui-script'); } if (!wp_style_is('views-admin-css')) { wp_enqueue_style('views-admin-css'); } } }
/** * Print column headers. */ protected function print_column_headers() { $columns = $this->get_column_info(); /* Get the current 'orderby' URL parameter. Obtain it either from $_GET or from column definitions (if there is * a pre-sorted column). If items aren't ordered, it will be an empty string. */ $current_orderby = wpv_getget('orderby', ''); if ('' == $current_orderby) { // Try to get information from column definitions. $current_orderby_column = $this->get_presorted_column(); $current_orderby = $columns[$current_orderby_column]['orderby']; $is_presorted = '' != $current_orderby; } else { $is_presorted = false; $current_orderby_column = $this->get_column_slug_by_orderby($current_orderby); } // Get the current 'order' URL parameter from $_GET or from column definitions. Defaults to 'ASC' if both methods fail. $current_order = wpv_getget('order', '', array('ASC', 'DESC')); if ('' == $current_order) { if ($is_presorted) { $current_order = wpv_getarr($columns[$current_orderby_column], 'default_order', 'ASC', array('ASC', 'DESC')); } else { $current_order = 'ASC'; } } $reverse_order = 'ASC' == $current_order ? 'DESC' : 'ASC'; // URL that will be used to build sorting links. All URL parameters except 'paged' and 'last_page' will be preserved. $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); $current_url = esc_url(remove_query_arg(array('paged', 'last_page'), $current_url)); // Print table header cell for each column foreach ($columns as $column_slug => $column) { $class = array("column-{$column_slug}"); $is_sortable = wpv_getarr($column, 'is_sortable', false); if ($is_sortable) { // Sortable column // URL 'orderby' parameter for this column $column_orderby = wpv_getarr($column, 'orderby', ''); if ($column_orderby == $current_orderby) { // We're sorting by this column. Build link to reverse order. $new_order = $reverse_order; $new_orderby = $current_orderby; // Append to the title according to current order. $title_order = wpv_getarr($column, 'ASC' == $current_order ? 'title_asc' : 'title_desc', ''); } else { // Not sorting by this column. Build link to sort by this column, ascending. $new_order = 'ASC'; $new_orderby = $column_orderby; $title_order = ''; } $title = sprintf('<a href="%s">%s%s</a>', esc_url(add_query_arg(array('order' => $new_order, 'orderby' => $new_orderby), $current_url)), wpv_getarr($column, 'title', $column_slug), $title_order); } else { // Non-sortable column, just print the title text. $title = wpv_getarr($column, 'title', $column_slug); } printf('<th scope="col" class="%s">%s</th>', join(' ', $class), $title); } }
function wpv_admin_content_template_listing_name() { $mod_url = array( // array of URL modifiers 'orderby' => '', 'order' => '', 's' => '', 'items_per_page' => '', 'paged' => '', 'status' => '' ); $wpv_args = array( 'post_type' => 'view-template', 'posts_per_page' => WPV_ITEMS_PER_PAGE, 'order' => 'ASC', 'orderby' => 'title', 'post_status' => 'publish' ); // Apply post_status coming from the URL parameters. $post_status = wpv_getget( 'status', 'publish', array( 'publish', 'trash' ) ); $wpv_args['post_status'] = $post_status; $mod_url['status'] = $post_status; $the_other_post_status = ( 'publish' == $post_status ) ? 'trash' : 'publish'; if ( isset( $_GET["s"] ) && '' != $_GET["s"] ) { $wpv_args = wpv_modify_wpquery_for_search( $_GET["s"], $wpv_args ); $mod_url['s'] = sanitize_text_field( $_GET["s"] ); } if ( isset( $_GET["items_per_page"] ) && '' != $_GET["items_per_page"] ) { $wpv_args['posts_per_page'] = (int) $_GET["items_per_page"]; $mod_url['items_per_page'] = (int) $_GET["items_per_page"]; } if ( isset( $_GET["orderby"] ) && '' != $_GET["orderby"] ) { $wpv_args['orderby'] = sanitize_text_field($_GET["orderby"]); $mod_url['orderby'] = sanitize_text_field($_GET["orderby"]); if ( isset( $_GET["order"] ) && '' != $_GET["order"] ) { $wpv_args['order'] = sanitize_text_field($_GET["order"]); $mod_url['order'] = sanitize_text_field($_GET["order"]); } } if ( isset( $_GET["paged"] ) && '' != $_GET["paged"]) { $wpv_args['paged'] = (int) $_GET["paged"]; $mod_url['paged'] = (int) $_GET["paged"]; } // Build a query for the other post status. We're interested only in post count $other_post_status_args = $wpv_args; $other_post_status_args['post_status'] = $the_other_post_status; $other_post_status_args['fields'] = 'ids'; // All querying must be done between those two switch_lang() calls otherwise CT translations // will be also (wrongly) included. global $sitepress; $default_language = ''; if( isset( $sitepress ) ) { //changes to the default language $default_language = $sitepress->get_default_language(); $sitepress->switch_lang( $default_language ); } $query = new WP_Query( $wpv_args ); $other_post_status_query = new WP_Query( $other_post_status_args ); if( isset( $sitepress ) ) { //changes to the current language $sitepress->switch_lang( ICL_LANGUAGE_CODE ); } // Number of posts that are being displayed. $wpv_count_posts = $query->post_count; // Total number of posts matching the query. $wpv_found_posts = $query->found_posts; // to hold the number of Views in each status $ct_counts_by_post_status = array( $post_status => $wpv_found_posts, $the_other_post_status => $other_post_status_query->found_posts ); // True if some content templates (even those not matching current query) exist. $some_posts_exist = ( $ct_counts_by_post_status['publish'] > 0 || $ct_counts_by_post_status['trash'] > 0 ); $active_nondefault_languages = array(); $add_translation_icon = ''; $edit_translation_icon = ''; $are_cts_translatable = WPV_Content_Template_Embedded::is_translatable(); if( $are_cts_translatable ) { $active_languages = apply_filters( 'wpml_active_languages', array() ); // just remove the default language $active_nondefault_languages = $active_languages; unset( $active_nondefault_languages[ $default_language ] ); // store urls to add/edit translaton icons if( defined( 'ICL_PLUGIN_URL' ) ) { $add_translation_icon = ICL_PLUGIN_URL . '/res/img/add_translation.png'; $edit_translation_icon = ICL_PLUGIN_URL . '/res/img/edit_translation.png'; } } ?> <?php if ( $some_posts_exist ) { ?> <ul class="subsubsub" style="clear:both"><!-- links to lists WPA in different statuses --> <li> <?php $is_plain_publish_current_status = ( $wpv_args['post_status'] == 'publish' && !isset( $_GET["s"] ) ); printf( '<a href="%s" %s>%s</a> (%s) | ', esc_url( add_query_arg( array( 'page' => 'view-templates', 'status' => 'publish' ), admin_url( 'admin.php' ) ) ), $is_plain_publish_current_status ? ' class="current" ' : '', __( 'Published', 'wpv-views' ), $ct_counts_by_post_status['publish'] ); ?> </li> <li> <?php $is_plain_trash_current_status = ( $wpv_args['post_status'] == 'trash' && !isset( $_GET["s"] ) ); printf( '<a href="%s" %s>%s</a> (%s)', esc_url( add_query_arg( array( 'page' => 'view-templates', 'status' => 'trash' ), admin_url( 'admin.php' ) ) ), $is_plain_trash_current_status ? ' class="current" ' : '', __( 'Trash', 'wpv-views' ), $ct_counts_by_post_status['trash'] ); ?> </li> </ul> <?php } else { // No post exist at all ?> <p class="wpv-view-not-exist"> <?php _e('Content Templates let you design single pages.','wpv-views'); ?> </p> <p class="add-new-view"> <button class="button js-add-new-content-template" data-target="<?php echo esc_url( add_query_arg( array( 'action' => 'wpv_ct_create_new' ), admin_url( 'admin-ajax.php' ) ) ); ?>"> <i class="icon-plus"></i><?php _e('Add new Content Template','wpv-views') ?> </button> </p><?php } // A nonce for CT action - used for individual as well as for bulk actions. // It will have a value only if some posts exist. $ct_action_nonce = ''; if( $some_posts_exist ) { $ct_action_nonce = wp_create_nonce( 'wpv_view_listing_actions_nonce' ); // === Render "tablenav" section (Bulk actions and Search box) === echo '<div class="tablenav top">'; if( $wpv_count_posts > 0 ) { // Prepare to render bulk actions dropdown. if( 'publish' == $wpv_args['post_status'] ) { $bulk_actions = array( 'trash' => __( 'Move to trash', 'wpv-views' ) ); } else { $bulk_actions = array( 'restore-from-trash' => __( 'Restore from trash', 'wpv-views' ), 'delete' => __( 'Delete permanently', 'wpv-views' ) ); } $bulk_actions_args = array( 'data-viewactionnonce' => $ct_action_nonce ); $bulk_actions_class = 'js-wpv-ct-listing-bulk-action'; echo wpv_admin_table_bulk_actions( $bulk_actions, $bulk_actions_class, $bulk_actions_args, 'top' ); } // Show search box if ( $wpv_found_posts > 0 ) { ?> <div class="alignright"> <form id="posts-filter" action="" method="get"> <p class="search-box"> <label class="screen-reader-text" for="post-search-input"><?php _e('Search Views:', 'wpv-views') ?></label> <?php $search_term = isset( $_GET["s"] ) ? urldecode( sanitize_text_field($_GET["s"]) ) : ''; ?> <input type="search" id="ct-post-search-input" name="s" value="<?php echo $search_term; ?>"> <input type="submit" name="" id="ct-search-submit" class="button" value="<?php echo htmlentities( __('Search Content Templates', 'wpv-views'), ENT_QUOTES ); ?>"> <input type="hidden" name="paged" value="1" /> </p> </form> </div> <?php } echo '</div>'; // End of tablenav section } if ( $wpv_count_posts == 0 && $some_posts_exist ) { // No posts are displayed, but some exist if ( isset( $_GET["s"] ) && '' != $_GET["s"] ) { if ( $wpv_args['post_status'] == 'trash' ) { // Searching in trash ?> <div class="wpv-views-listing views-empty-list"> <p> <?php printf( '<p>%s</p><p><a class="button-secondary" href="%s">%s</a></p>', __( 'No Content Templates in trash matched your criteria.', 'wpv-views' ), wpv_maybe_add_query_arg( array( 'page' => 'view-templates', 'orderby' => $mod_url['orderby'], 'order' => $mod_url['order'], 'items_per_page' => $mod_url['items_per_page'], 'paged' => '1', 'status' => 'trash' ), admin_url( 'admin.php' ) ), __( 'Return', 'wpv-views' ) ); ?> </p> </div> <?php } else { // Normal search ?> <div class="wpv-views-listing views-empty-list"> <p> <?php printf( '<p>%s</p><p><a class="button-secondary" href="%s">%s</a></p>', __( 'No Content Templates matched your criteria.', 'wpv-views' ), wpv_maybe_add_query_arg( array( 'page' => 'view-templates', 'orderby' => $mod_url['orderby'], 'order' => $mod_url['order'], 'items_per_page' => $mod_url['items_per_page'], 'paged' => '1' ), admin_url( 'admin.php' ) ), __( 'Return', 'wpv-views' ) ); ?> </p> </div> <?php } } else { if ( $wpv_args['post_status'] == 'trash' ) { // No items in trash ?> <div class="wpv-views-listing views-empty-list"> <p> <?php printf( '<p>%s</p><p><a class="button-secondary" href="%s">%s</a></p>', __( 'No Content Templates in trash.', 'wpv-views' ), wpv_maybe_add_query_arg( array( 'page' => 'view-templates', 'orderby' => $mod_url['orderby'], 'order' => $mod_url['order'], 'items_per_page' => $mod_url['items_per_page'], 'paged' => '1' ), admin_url( 'admin.php' ) ), __( 'Return', 'wpv-views' ) ); ?> </p> </div> <?php } else { ?> <p class="wpv-view-not-exist"> <?php _e('Content Templates let you design single pages.','wpv-views'); ?> </p> <p class="add-new-view"> <button class="button js-add-new-content-template" data-target="<?php echo esc_url( add_query_arg( array( 'action' => 'wpv_ct_create_new' ), admin_url( 'admin-ajax.php' ) ) ); ?>"> <i class="icon-plus"></i><?php _e( 'Add new Content Template', 'wpv-views') ?> </button> </p> <?php } } } else if ( $wpv_count_posts != 0 ) { // We have some results to display. global $wpdb; ?> <table class="wpv-views-listing widefat"> <!-- section for: sort by name --> <thead> <?php /* To avoid code duplication, table header is stored in output buffer and echoed twice - within * thead and tfoot tags. */ ob_start(); ?> <tr> <th class="wpv-admin-listing-col-bulkactions check-column"> <input type="checkbox" /> </th> <?php $column_active = ''; $column_sort_to = 'ASC'; $column_sort_now = 'ASC'; $status = ''; if ( $wpv_args['orderby'] === 'title' ) { $column_active = ' views-list-sort-active'; $column_sort_to = ( $wpv_args['order'] === 'ASC' ) ? 'DESC' : 'ASC'; $column_sort_now = $wpv_args['order']; } if ( isset($_GET['status']) && $_GET['status'] == 'trash' ){ $status = 'trash'; } ?> <th class="wpv-admin-listing-col-title"> <?php printf( '<a href="%s" class="%s" data-orderby="title">%s <i class="%s"></i></a>', wpv_maybe_add_query_arg( array( 'page' => 'view-templates', 'status' => $status, 'orderby' => 'title', 'order' => $column_sort_to, 's' => $mod_url['s'], 'items_per_page' => $mod_url['items_per_page'], 'paged' => $mod_url['paged'] ), admin_url( 'admin.php' ) ), 'js-views-list-sort views-list-sort ' . $column_active, __( 'Title', 'wpv-views' ), ( 'DESC' === $column_sort_now ) ? 'icon-sort-by-alphabet-alt' : 'icon-sort-by-alphabet' ); ?> </th> <?php if( $are_cts_translatable ) { $flag_images = array(); foreach( $active_nondefault_languages as $language_info ) { $flag_images[] = sprintf( '<img style="padding: 2px;" src="%s" title="%s" alt="%s" />', $language_info['country_flag_url'], $language_info['translated_name'], $language_info['code'] ); } if( empty( $flag_images ) ) { $translation_column_header = __( 'Translations', 'wpv-views' ); } else { $translation_column_header = implode( '', $flag_images ); } printf( '<th>%s</th>', $translation_column_header ); } ?> <th class="wpv-admin-listing-col-usage js-wpv-col-two"><?php _e('Used on','wpv-views') ?></th> <?php $column_active = ''; $column_sort_to = 'DESC'; $column_sort_now = 'DESC'; if ( $wpv_args['orderby'] === 'date' ) { $column_active = ' views-list-sort-active'; $column_sort_to = ( $wpv_args['order'] === 'ASC' ) ? 'DESC' : 'ASC'; $column_sort_now = $wpv_args['order']; } ?> <th class="wpv-admin-listing-col-date"> <?php printf( '<a href="%s" class="%s" data-orderby="date">%s <i class="%s"></i></a>', wpv_maybe_add_query_arg( array( 'page' => 'view-templates', 'status' => $status, 'orderby' => 'date', 'order' => $column_sort_to, 's' => $mod_url['s'], 'items_per_page' => $mod_url['items_per_page'], 'paged' => $mod_url['paged'] ), admin_url( 'admin.php' ) ), 'js-views-list-sort views-list-sort ' . $column_active, __( 'Date', 'wpv-views' ), ( 'DESC' === $column_sort_now ) ? 'icon-sort-by-attributes-alt' : 'icon-sort-by-attributes' ); ?> </th> </tr> <?php // Get table header from output buffer and stop buffering $table_header = ob_get_contents(); ob_end_clean(); echo $table_header; ?> </thead> <tfoot> <?php echo $table_header; ?> </tfoot> <tbody class="js-wpv-views-listing-body"> <?php $alternate = ''; while ( $query->have_posts() ) : $query->the_post(); $post = get_post( get_the_id() ); $template_id = $post->ID; $ct = WPV_Content_Template::get_instance( $template_id ); $wpv_content_template_decription = get_post_meta( $template_id, '_wpv-content-template-decription', true ); $layout_loop_template_for_view_id = get_post_meta( $template_id, '_view_loop_id', true ); $alternate = ( ' alternate' == $alternate ) ? '' : ' alternate'; ?> <tr id="wpv_ct_list_row_<?php echo $template_id; ?>" class="js-wpv-ct-list-row<?php echo $alternate; ?>"> <th class="wpv-admin-listing-col-bulkactions check-column"> <?php if ( empty( $layout_loop_template_for_view_id ) ) { printf( '<input type="checkbox" value="%s" name="view[]" />', $template_id ); } ?> </th> <td class="wpv-admin-listing-col-title post-title page-title column-title"> <span class="row-title"> <?php if ( $wpv_args['post_status'] == 'trash' ) { echo esc_html( $post->post_title ); } else { wpv_ct_editor_render_link( $template_id, esc_html( $post->post_title ) ); } ?> </span> <?php if ( ! empty( $wpv_content_template_decription ) ) { ?> <p class="desc"> <?php echo nl2br( $wpv_content_template_decription )?> </p> <?php } /* Generate and show row actions. * Note that we want to add also 'simple' action names to the action list because * they get echoed as a class of the span tag and get styled from WordPress core css * accordingly (e.g. trash in different colour than the rest) */ $row_actions = array(); $asigned_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(post_id) FROM {$wpdb->postmeta} JOIN {$wpdb->posts} p WHERE meta_key = '_views_template' AND meta_value = %s AND post_id = p.ID AND p.post_status NOT IN ('auto-draft') AND p.post_type != 'revision'", $template_id ) ); if ( 'publish' == $wpv_args['post_status'] ) { $row_actions['edit'] = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'page' => WPV_CT_EDITOR_PAGE_NAME, 'ct_id' => $template_id ), admin_url( 'admin.php' ) ) ), __( 'Edit', 'wpv-views' ) ); if ( empty( $layout_loop_template_for_view_id ) ) { $row_actions['change js-wpv-ct-change-usage-popup'] = sprintf( '<a href="#">%s</a>', __( 'Change template usage', 'wpv-views' ) ); } $row_actions['duplicate js-list-ct-action-duplicate'] = sprintf( '<a href="#">%s</a>', __( 'Duplicate', 'wpv-views' ) ); if ( empty( $layout_loop_template_for_view_id ) ) { $row_actions['trash js-wpv-ct-action-trash'] = sprintf( '<a href="#">%s</a>', __( 'Move to trash', 'wpv-views' ) ); } } else if ( 'trash' == $wpv_args['post_status'] ) { $row_actions['restore-from-trash js-wpv-ct-action-restore-from-trash'] = sprintf( '<a href="#">%s</a>', __( 'Restore from trash', 'wpv-views' ) ); $row_actions['delete js-list-ct-action-delete'] = sprintf( '<a href="#">%s</a>', __( 'Delete', 'wpv-views' ) ); } echo wpv_admin_table_row_actions( $row_actions, array( "data-ct-id" => $template_id, "data-postcount" => $asigned_count, "data-ct-name" => htmlentities( $post->post_title, ENT_QUOTES ), "data-viewactionnonce" => $ct_action_nonce, // Used by the "duplicate" action "data-msg" => htmlentities( __( 'Enter new title','wpv-views'), ENT_QUOTES ) ) ); ?> </td> <?php if( $are_cts_translatable ) { echo '<td>'; $ct_translations = $ct->wpml_translations; foreach( $active_nondefault_languages as $language_info ) { $translation = wpv_getarr( $ct_translations, $language_info['code'], null ); if( null == $translation ) { $translation_text = __( 'Add translation', 'wpv-views' ); $translation_icon = $add_translation_icon; } else { $translation_text = __( 'Edit translation', 'wpv-views' ); $translation_icon = $edit_translation_icon; } $translation_editor_link = $ct->get_wpml_tm_link( $language_info['code'] ); if( null != $translation_editor_link ) { printf( '<a style="padding: 2px;" href="%s"><img alt="%s" src="%s" title="%s" /></a>', $translation_editor_link, $language_info['code'], $translation_icon, $translation_text ); } else { /** @noinspection CssInvalidFunction */ /** @noinspection CssUnknownProperty */ printf( '<span style="padding: 2px"> <img alt="%s" src="%s" title="%s" style="-webkit-filter: grayscale(100%%); filter: grayscale(100%%)"/> </span>', $language_info['code'], $translation_icon, __( 'WPML Translation Management must be active for this link to work.', 'wpv-view' ) ); } } echo '</td>'; } ?> <td class="wpv-admin-listing-col-usage"> <?php echo wpv_content_template_used_for_list( $template_id ); ?> </td> <td class="wpv-admin-listing-col-date"> <?php echo get_the_time( get_option( 'date_format' ), $template_id ); ?> </td> </tr> <?php endwhile; ?> </tbody> </table> <div class="tablenav bottom"> <?php echo wpv_admin_table_bulk_actions( $bulk_actions, $bulk_actions_class, $bulk_actions_args, 'bottom' ); ?> </div> <p class="add-new-view"> <button class="button js-add-new-content-template" data-target="<?php echo esc_url( add_query_arg( array( 'action' => 'wpv_ct_create_new' ), admin_url( 'admin-ajax.php' ) ) ); ?>"> <i class="icon-plus"></i><?php _e( 'Add new Content Template','wpv-views' ) ?> </button> </p> <?php } wpv_admin_listing_pagination( 'view-templates', $wpv_found_posts, $wpv_args["posts_per_page"], $mod_url ); // Render dialog templates. wpv_render_ct_listing_dialog_templates_arrangeby_name(); }
public function layoutTemplateEnqueueAssets() { $page = wpv_getget('page'); if ('views-editor' == $page || 'view-archives-editor' == $page) { wp_enqueue_script('toolset-user-editors-beaver-layout-template-script'); } }
/** * Optionaly render a message on a listing page. * * If a given URL parameter is present that indicates a finished action, show a message. Value of this parameter is * supposed to be a number of affected posts. * * If more than one post was affected, a plural message is shown, otherwise a singular one. * Plural message is expected to contain one "%d" placeholder for the number of affected posts. * * This function also looks for a list of affected IDs (as comma-separated values in an URL parameter) and * if $has_undo is true, the filter wpv_maybe_show_listing_message_undo is applied to obtain an Undo link for * this action. Since 1.10 an array is also accepted and invalid values are ignored. * * The message will appear below the h2 tag. * * @since 1.7 * * @param string $message_name Name of the URL parameter indicating this message should be rendered. * @param string $text_singular Message text that will be echoed when one post was affected. * @param string $text_plural Message text that will be echoed when more posts were affected. * @param bool $has_undo Indicates whether a filter should be applied to obtain an Undo link. Default is false. * @param string $affected_id_arg Name of the URL parameter possibly containing IDs of affected posts. */ function wpv_maybe_show_listing_message( $message_name, $text_singular, $text_plural, $has_undo = false, $affected_id_arg = 'affected' ) { if ( isset( $_GET[ $message_name ] ) ) { // Number of affected posts $message_value = $_GET[ $message_name ]; // IDs of affected posts (if set) $affected_ids = wpv_getget( $affected_id_arg, array() ); if( is_numeric( $affected_ids ) ) { $affected_ids = array( $affected_ids ); } else if( is_string( $affected_ids ) ) { $affected_ids = explode( ',', $affected_ids ); } else if( !is_array( $affected_ids ) ) { // unexpected value $affected_ids = array(); } if( $has_undo ) { /** * Construct an "Undo" link for a message on listing page. * * Resulting string will be appended after message text. * * @since 1.7 * * @param string $undo_html An Undo link to be appended after the message. * @param string $message_name Name of the message as it was passed to wpv_maybe_show_listing_message(). * @param array $affected_ids IDs of posts affected by the action. */ $undo = ' ' . apply_filters( 'wpv_maybe_show_listing_message_undo', '', $message_name, $affected_ids ); } else { $undo = ''; } // Choose the appropriate message text. if( $message_value > 1 ) { $text = sprintf( $text_plural, $message_value ); } else { $text = $text_singular; } $text .= $undo; ?> <div id="message" class="updated below-h2"> <p><?php echo $text ?></p> </div> <?php } }
/** * CT editor page handler. * * Based on the 'action' GET parameter, either create a new CT and show the edit page for it, * or show the edit page for an existing CT. * * For the 'create' action, following GET parameters are expected: * - title: Title of the new Content Template. * - usage: An associative array that can contains keys "single_post_types", "post_archives" and * "taxonomy_archives" (others will be ignored) with arrays of post type or taxonomy slugs where this Content * Template should be used. Only existing slugs are allowed (see WPV_Content_Template::_set_assigned_* methods). * * @since 1.9 */ function wpv_ct_editor_page() { if( !current_user_can( 'manage_options' ) ) { wpv_die_toolset_alert_error( __( 'You have no permission to acces this page.', 'wpv-views' ) ); } $action = wpv_getget( 'action', 'edit', array( 'edit', 'create' ) ); switch( $action ) { // show edit page case 'edit': $ct_id = (int) wpv_getget( 'ct_id' ); wpv_ct_editor_page_edit( $ct_id ); break; // create a new content template and continue to edit page on success. case 'create': $title = urldecode( wpv_getget( 'title' ) ); $usage = wpv_getget( 'usage' ); if( !is_array( $usage ) ) { $usage = array(); } $ct = wpv_ct_editor_page_create( $title, $usage ); if( $ct instanceof WPV_Content_Template ) { wpv_ct_editor_page_edit( $ct ); } else { wpv_die_toolset_alert_error( __( 'An error ocurred while creating a new Content Template.', 'wpv-views' ) ); } break; } }
/** * Retrieve arguments for listing and querying. * * Read from $_GET or provide default values for ordering and pagination. * Pagination arguments are obtained from the pagination decorator. * * @return array( * Array of arguments for listing and querying. * * @type int $items_per_page Number of items per page. 0 means "not set, use default value" and -1 means "show * all items". The value depends on the pagination decorator. * @type int $paged Number of the current page. 0 means "not set, use default". Obtained from pagination decorator. * @type string $orderby Name of field by which should items be ordered. Arbitrary, not validated here. * @type string $order ASC or DESC. Defaults to ASC. * ) */ function get_args() { $args = array( 'page' => $this->page_name, 'items_per_page' => $this->pagination_decorator->get_items_per_page(), 'paged' => $this->pagination_decorator->get_paged(), 'orderby' => sanitize_text_field( wpv_getget( 'orderby' ) ), 'order' => wpv_getget( 'order', 'ASC', array( 'ASC', 'DESC' ) ), 'search' => urldecode( sanitize_text_field( wpv_getget( 'search', '' ) ) ) ); return $args; }
/** * Class constructor. * * @param $page_name string Name of the page (value of the 'page' parameter) on which the pagination controls are rendered. */ function __construct( $page_name ) { $this->paged = (int) wpv_getget( 'paged', 1 ); $this->items_per_page = (int) wpv_getget( 'items_per_page', WPV_ITEMS_PER_PAGE ); $this->page_name = $page_name; }