| @@ -59,11 +59,13 @@ | ||
| 59 | 59 | $this->_addFilter( 'media_view_strings', 'setupMediaViewStrings' ); |
| 60 | 60 | $this->_addFilter( 'plugin_action_links', 'getPluginActionLinks', 10, 2 ); |
| 61 | 61 | $this->_addFilter( 'plugin_row_meta', 'getPluginMetaLinks', 10, 2 ); |
| 62 | 62 | $this->_addFilter( 'visualizer_logger_data', 'getLoggerData' ); |
| 63 | - $this->_addFilter( 'visualizer_get_chart_counts', 'getChartCountsByTypeAndMeta' ); | |
| 64 | 63 | $this->_addFilter( 'visualizer_feedback_review_trigger', 'feedbackReviewTrigger' ); |
| 65 | 64 | |
| 65 | + // screen pagination | |
| 66 | + $this->_addFilter( 'set-screen-option', 'setScreenOptions', 10, 3 ); | |
| 67 | + | |
| 66 | 68 | // revision support. |
| 67 | 69 | $this->_addFilter( 'wp_revisions_to_keep', 'limitRevisions', null, 10, 2 ); |
| 68 | 70 | $this->_addAction( '_wp_put_post_revision', 'addRevision', null, 10, 1 ); |
| 69 | 71 | $this->_addAction( 'wp_restore_post_revision', 'restoreRevision', null, 10, 2 ); |
| @@ -706,11 +708,99 @@ | ||
| 706 | 708 | 'viz-support', |
| 707 | 709 | array( $this, 'renderSupportPage' ) |
| 708 | 710 | ); |
| 709 | 711 | remove_submenu_page( Visualizer_Plugin::NAME, Visualizer_Plugin::NAME ); |
| 712 | + | |
| 713 | + add_action( "load-{$this->_libraryPage}", array( $this, 'addScreenOptions' ) ); | |
| 710 | 714 | } |
| 711 | 715 | |
| 712 | 716 | /** |
| 717 | + * Adds the screen options for pagination. | |
| 718 | + */ | |
| 719 | + function addScreenOptions() { | |
| 720 | + $screen = get_current_screen(); | |
| 721 | + | |
| 722 | + // bail if it's some other page. | |
| 723 | + if ( ! is_object( $screen ) || $screen->id !== $this->_libraryPage ) { | |
| 724 | + return; | |
| 725 | + } | |
| 726 | + | |
| 727 | + $args = array( | |
| 728 | + 'label' => __( 'Number of charts per page:', 'visualizer' ), | |
| 729 | + 'default' => 6, | |
| 730 | + 'option' => 'visualizer_per_page_library', | |
| 731 | + ); | |
| 732 | + add_screen_option( 'per_page', $args ); | |
| 733 | + } | |
| 734 | + | |
| 735 | + /** | |
| 736 | + * Returns the screen option for pagination. | |
| 737 | + */ | |
| 738 | + function setScreenOptions( $status, $option, $value ) { | |
| 739 | + if ( 'visualizer_per_page_library' === $option ) { | |
| 740 | + return $value; | |
| 741 | + } | |
| 742 | + } | |
| 743 | + | |
| 744 | + /** | |
| 745 | + * Adds the display filters to be used in the meta_query while displaying the charts. | |
| 746 | + */ | |
| 747 | + private function getDisplayFilters( &$query_args ) { | |
| 748 | + $query = array(); | |
| 749 | + | |
| 750 | + // add chart type filter to the query arguments | |
| 751 | + $type = filter_input( INPUT_GET, 'type' ); | |
| 752 | + if ( $type && in_array( $type, Visualizer_Plugin::getChartTypes(), true ) ) { | |
| 753 | + $query[] = array( | |
| 754 | + 'key' => Visualizer_Plugin::CF_CHART_TYPE, | |
| 755 | + 'value' => $type, | |
| 756 | + 'compare' => '=', | |
| 757 | + ); | |
| 758 | + } | |
| 759 | + | |
| 760 | + // add chart library filter to the query arguments | |
| 761 | + $library = filter_input( INPUT_GET, 'library' ); | |
| 762 | + if ( $library ) { | |
| 763 | + $query[] = array( | |
| 764 | + 'key' => Visualizer_Plugin::CF_CHART_LIBRARY, | |
| 765 | + 'value' => $library, | |
| 766 | + 'compare' => '=', | |
| 767 | + ); | |
| 768 | + } | |
| 769 | + | |
| 770 | + // add date filter to the query arguments | |
| 771 | + $date = filter_input( INPUT_GET, 'date' ); | |
| 772 | + $possible = array_keys( Visualizer_Plugin::getSupportedDateFilter() ); | |
| 773 | + if ( $date && in_array( $date, $possible, true ) ) { | |
| 774 | + $query_args['date_query'] = array( | |
| 775 | + 'after' => "$date -1 day", | |
| 776 | + 'inclusive' => true, | |
| 777 | + ); | |
| 778 | + } | |
| 779 | + | |
| 780 | + // add source filter to the query arguments | |
| 781 | + $source = filter_input( INPUT_GET, 'source' ); | |
| 782 | + if ( $source ) { | |
| 783 | + $source = ucwords( $source ); | |
| 784 | + $source = "Visualizer_Source_{$source}"; | |
| 785 | + $query[] = array( | |
| 786 | + 'key' => Visualizer_Plugin::CF_SOURCE, | |
| 787 | + 'value' => $source, | |
| 788 | + 'compare' => '=', | |
| 789 | + ); | |
| 790 | + } | |
| 791 | + | |
| 792 | + $query_args['meta_query'] = $query; | |
| 793 | + | |
| 794 | + $orderby = filter_input( INPUT_GET, 'orderby' ); | |
| 795 | + $order = filter_input( INPUT_GET, 'order' ); | |
| 796 | + if ( $orderby ) { | |
| 797 | + $query_args['order_by'] = $orderby; | |
| 798 | + } | |
| 799 | + $query_args['order'] = empty( $order ) ? 'desc' : $order; | |
| 800 | + } | |
| 801 | + | |
| 802 | + /** | |
| 713 | 803 | * Get the instance of WP_Query that fetches the charts as per the given criteria. |
| 714 | 804 | */ |
| 715 | 805 | private function getQuery() { |
| 716 | 806 | static $q; |
| @@ -729,27 +819,32 @@ | ||
| 729 | 819 | 'default' => 1, |
| 730 | 820 | ), |
| 731 | 821 | ) |
| 732 | 822 | ); |
| 823 | + | |
| 824 | + $per_page = 6; | |
| 825 | + $screen = get_current_screen(); | |
| 826 | + if ( $screen ) { | |
| 827 | + // retrieve the per_page option | |
| 828 | + $screen_option = $screen->get_option( 'per_page', 'option' ); | |
| 829 | + // retrieve the value stored for the current user | |
| 830 | + $user = get_current_user_id(); | |
| 831 | + $per_page = get_user_meta( $user, $screen_option, true ); | |
| 832 | + if ( empty( $per_page ) || $per_page < 1 ) { | |
| 833 | + // nothing set, get the default value | |
| 834 | + $per_page = $screen->get_option( 'per_page', 'default' ); | |
| 835 | + } | |
| 836 | + } | |
| 837 | + | |
| 733 | 838 | // the initial query arguments to fetch charts |
| 734 | 839 | $query_args = array( |
| 735 | 840 | 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, |
| 736 | - 'posts_per_page' => 6, | |
| 841 | + 'posts_per_page' => $per_page, | |
| 737 | 842 | 'paged' => $page, |
| 738 | 843 | ); |
| 739 | - // add chart type filter to the query arguments | |
| 740 | - $filter = filter_input( INPUT_GET, 'type' ); | |
| 741 | - if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes(), true ) ) { | |
| 742 | - $query_args['meta_query'] = array( | |
| 743 | - array( | |
| 744 | - 'key' => Visualizer_Plugin::CF_CHART_TYPE, | |
| 745 | - 'value' => $filter, | |
| 746 | - 'compare' => '=', | |
| 747 | - ), | |
| 748 | - ); | |
| 749 | - } else { | |
| 750 | - $filter = 'all'; | |
| 751 | - } | |
| 844 | + | |
| 845 | + $this->getDisplayFilters( $query_args ); | |
| 846 | + | |
| 752 | 847 | // Added by Ash/Upwork |
| 753 | 848 | $filterByMeta = filter_input( INPUT_GET, 's', FILTER_SANITIZE_STRING ); |
| 754 | 849 | if ( $filterByMeta ) { |
| 755 | 850 | $query = array( |
| @@ -829,9 +924,9 @@ | ||
| 829 | 924 | unset( $settings['height'], $settings['width'], $settings['chartArea'] ); |
| 830 | 925 | } |
| 831 | 926 | |
| 832 | 927 | $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type ); |
| 833 | - $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( $chart->post_content ) ), $chart->ID, $type ); | |
| 928 | + $data = self::get_chart_data( $chart, $type ); | |
| 834 | 929 | |
| 835 | 930 | $library = $this->load_chart_type( $chart->ID ); |
| 836 | 931 | |
| 837 | 932 | $id = 'visualizer-' . $chart->ID; |