| @@ -67,8 +67,148 @@ | ||
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | + * Displays the search form. | |
| 72 | + */ | |
| 73 | + private function getDisplayForm() { | |
| 74 | + echo '<div class="visualizer-library-form"> | |
| 75 | + <form action="' . admin_url( 'admin.php' ) . '"> | |
| 76 | + <input type="hidden" name="page" value="' . Visualizer_Plugin::NAME . '"/> | |
| 77 | + <select class="viz-filter" name="type"> | |
| 78 | + '; | |
| 79 | + | |
| 80 | + echo '<option value="" selected>' . __( 'All types', 'visualizer' ) . '</option>'; | |
| 81 | + | |
| 82 | + $type = isset( $_GET['type'] ) ? $_GET['type'] : ''; | |
| 83 | + $enabled = array(); | |
| 84 | + $disabled = array(); | |
| 85 | + foreach ( $this->types as $id => $array ) { | |
| 86 | + if ( ! is_array( $array ) ) { | |
| 87 | + // support for old pro | |
| 88 | + $array = array( 'enabled' => true, 'name' => $array ); | |
| 89 | + } | |
| 90 | + if ( ! $array['enabled'] ) { | |
| 91 | + $disabled[ $id ] = $array['name']; | |
| 92 | + continue; | |
| 93 | + } | |
| 94 | + $enabled[ $id ] = $array['name']; | |
| 95 | + } | |
| 96 | + | |
| 97 | + asort( $enabled ); | |
| 98 | + asort( $disabled ); | |
| 99 | + | |
| 100 | + foreach ( $enabled as $id => $name ) { | |
| 101 | + echo '<option value="' . esc_attr( $id ) . '" ' . selected( $type, $id ) . '>' . $name . '</option>'; | |
| 102 | + } | |
| 103 | + | |
| 104 | + if ( $disabled ) { | |
| 105 | + echo '<optgroup label="' . __( 'Not available', 'visualizer' ) . '">'; | |
| 106 | + foreach ( $disabled as $id => $name ) { | |
| 107 | + echo '<option value="' . esc_attr( $id ) . '" ' . selected( $type, $id ) . ' disabled>' . $name . '</option>'; | |
| 108 | + } | |
| 109 | + echo '</optgroup>'; | |
| 110 | + } | |
| 111 | + | |
| 112 | + echo ' | |
| 113 | + </select> | |
| 114 | + <select class="viz-filter" name="library"> | |
| 115 | + '; | |
| 116 | + | |
| 117 | + $libraries = array( '', 'ChartJS', 'DataTable', 'GoogleCharts' ); | |
| 118 | + $library = isset( $_GET['library'] ) ? $_GET['library'] : ''; | |
| 119 | + foreach ( $libraries as $lib ) { | |
| 120 | + echo '<option value="' . esc_attr( $lib ) . '" ' . selected( $library, $lib ) . '>' . ( $lib === '' ? __( 'All libraries', 'visualizer' ) : $lib ) . '</option>'; | |
| 121 | + } | |
| 122 | + | |
| 123 | + echo ' | |
| 124 | + </select> | |
| 125 | + <select class="viz-filter" name="date"> | |
| 126 | + '; | |
| 127 | + | |
| 128 | + $dates = Visualizer_Plugin::getSupportedDateFilter(); | |
| 129 | + $date = isset( $_GET['date'] ) ? $_GET['date'] : ''; | |
| 130 | + foreach ( Visualizer_Plugin::getSupportedDateFilter() as $dt => $label ) { | |
| 131 | + echo '<option value="' . esc_attr( $dt ) . '" ' . selected( $date, $dt ) . '>' . $label . '</option>'; | |
| 132 | + } | |
| 133 | + | |
| 134 | + echo ' | |
| 135 | + </select> | |
| 136 | + <select class="viz-filter" name="source"> | |
| 137 | + '; | |
| 138 | + | |
| 139 | + $disabled = array(); | |
| 140 | + $sources = array( 'json' => __( 'JSON', 'visualizer' ), 'csv' => __( 'Local CSV', 'visualizer' ), 'csv_remote' => __( 'Remote CSV', 'visualizer' ), 'query' => __( 'Database', 'visualizer' ), 'query_wp' => __( 'WordPress', 'visualizer' ) ); | |
| 141 | + if ( ! Visualizer_Module::is_pro() ) { | |
| 142 | + $disabled['query'] = $sources['query']; | |
| 143 | + unset( $sources['query'] ); | |
| 144 | + } | |
| 145 | + if ( ! apply_filters( 'visualizer_is_business', false ) ) { | |
| 146 | + $disabled['query_wp'] = $sources['query_wp']; | |
| 147 | + unset( $sources['query_wp'] ); | |
| 148 | + } | |
| 149 | + $sources = array_filter( $sources ); | |
| 150 | + uasort( | |
| 151 | + $sources, function( $a, $b ) { | |
| 152 | + if ( $a === $b ) { | |
| 153 | + return 0; | |
| 154 | + } | |
| 155 | + return ( $a < $b ) ? -1 : 1; | |
| 156 | + } | |
| 157 | + ); | |
| 158 | + | |
| 159 | + $source = isset( $_GET['source'] ) ? $_GET['source'] : ''; | |
| 160 | + echo '<option value="">' . __( 'All sources', 'visualizer' ) . '</option>'; | |
| 161 | + foreach ( $sources as $field => $label ) { | |
| 162 | + echo '<option value="' . esc_attr( $field ) . '" ' . selected( $source, $field ) . '>' . $label . '</option>'; | |
| 163 | + } | |
| 164 | + | |
| 165 | + if ( $disabled ) { | |
| 166 | + echo '<optgroup label="' . __( 'Not available', 'visualizer' ) . '">'; | |
| 167 | + foreach ( $disabled as $id => $name ) { | |
| 168 | + echo '<option value="' . esc_attr( $id ) . '" ' . selected( $type, $id ) . ' disabled>' . $name . '</option>'; | |
| 169 | + } | |
| 170 | + echo '</optgroup>'; | |
| 171 | + } | |
| 172 | + | |
| 173 | + $name = isset( $_GET['s'] ) ? $_GET['s'] : ''; | |
| 174 | + echo ' | |
| 175 | + </select> | |
| 176 | + <input class="viz-filter" type="text" name="s" placeholder="' . __( 'Enter title', 'visualizer' ) . '" value="' . esc_attr( $name ) . '"> | |
| 177 | + '; | |
| 178 | + | |
| 179 | + echo ' | |
| 180 | + <span class="viz-filter">|</span> | |
| 181 | + <select class="viz-filter" name="orderby"> | |
| 182 | + '; | |
| 183 | + | |
| 184 | + $order_by_fields = apply_filters( 'visualizer_filter_order_by', array( 'date' => __( 'Date', 'visualizer' ), 's' => __( 'Title', 'visualizer' ) ) ); | |
| 185 | + $order_by = isset( $_GET['orderby'] ) ? $_GET['orderby'] : ''; | |
| 186 | + echo '<option value="">' . __( 'Order By', 'visualizer' ) . '</option>'; | |
| 187 | + foreach ( $order_by_fields as $field => $label ) { | |
| 188 | + echo '<option value="' . esc_attr( $field ) . '" ' . selected( $order_by, $field ) . '>' . $label . '</option>'; | |
| 189 | + } | |
| 190 | + | |
| 191 | + echo ' | |
| 192 | + </select> | |
| 193 | + <select class="viz-filter" name="order"> | |
| 194 | + '; | |
| 195 | + | |
| 196 | + $order_type = array( 'desc' => __( 'Descending', 'visualizer' ), 'asc' => __( 'Ascending', 'visualizer' ) ); | |
| 197 | + $order = isset( $_GET['order'] ) ? $_GET['order'] : 'desc'; | |
| 198 | + foreach ( $order_type as $field => $label ) { | |
| 199 | + echo '<option value="' . esc_attr( $field ) . '" ' . selected( $order, $field ) . '>' . $label . '</option>'; | |
| 200 | + } | |
| 201 | + | |
| 202 | + echo ' | |
| 203 | + </select> | |
| 204 | + <input type="submit" class="viz-filter button button-secondary" value="' . __( 'Apply Filters', 'visualizer' ) . '"> | |
| 205 | + <input type="button" id="viz-lib-reset" class="viz-filter button button-secondary" value="' . __( 'Clear Filters', 'visualizer' ) . '"> | |
| 206 | + </form> | |
| 207 | + </div>'; | |
| 208 | + } | |
| 209 | + | |
| 210 | + /** | |
| 71 | 211 | * Renders library content. |
| 72 | 212 | * |
| 73 | 213 | * @since 1.0.0 |
| 74 | 214 | * |
| @@ -82,50 +222,9 @@ | ||
| 82 | 222 | } |
| 83 | 223 | // Added by Ash/Upwork |
| 84 | 224 | echo $this->custom_css; |
| 85 | 225 | echo '<div id="visualizer-types" class="visualizer-clearfix">'; |
| 86 | - echo '<ul class="subsubsub">'; | |
| 87 | - // All tab. | |
| 88 | - echo '<li class="visualizer-list-item all"><a class="' . ( ! isset( $_GET['type'] ) || empty( $_GET['type'] ) ? 'current' : '' ) . '" href="', esc_url( add_query_arg( array( 'vpage' => false, 'type' => false, 'vaction' => false, 's' => false ) ) ), '">' . __( 'All', 'visualizer' ) . '</a> | </li>'; | |
| 89 | - foreach ( $this->types as $type => $array ) { | |
| 90 | - if ( ! is_array( $array ) ) { | |
| 91 | - // support for old pro | |
| 92 | - $array = array( 'enabled' => true, 'name' => $array ); | |
| 93 | - } | |
| 94 | - $label = $array['name']; | |
| 95 | - $link = '<a class=" " href="' . esc_url( | |
| 96 | - add_query_arg( | |
| 97 | - array( | |
| 98 | - 'type' => $type, | |
| 99 | - 'vpage' => false, | |
| 100 | - 'vaction' => false, | |
| 101 | - 's' => false, | |
| 102 | - ) | |
| 103 | - ) | |
| 104 | - ) . '">'; | |
| 105 | - if ( ! $array['enabled'] ) { | |
| 106 | - $link = "<a class=' visualizer-pro-only' href='" . Visualizer_Plugin::PRO_TEASER_URL . "' target='_blank'>"; | |
| 107 | - } | |
| 108 | - echo '<li class="visualizer-list-item ' . esc_attr( $this->type ) . '">'; | |
| 109 | - if ( $type === $this->type ) { | |
| 110 | - echo '<a class="current" href="', esc_url( add_query_arg( 'vpage', false ) ), '">'; | |
| 111 | - echo $label; | |
| 112 | - echo '</a>'; | |
| 113 | - } else { | |
| 114 | - echo $link; | |
| 115 | - echo $label; | |
| 116 | - echo '</a>'; | |
| 117 | - } | |
| 118 | - echo ' | </li>'; | |
| 119 | - } | |
| 120 | - echo '</ul>'; | |
| 121 | - | |
| 122 | - echo '<form action="" method="get"><p id="visualizer-search" class="search-box"> | |
| 123 | - <input type="search" placeholder="' . __( 'Enter title', 'visualizer' ) . '" name="s" value="' . $filterBy . '"> | |
| 124 | - <input type="hidden" name="page" value="visualizer"> | |
| 125 | - <button type="submit" id="search-submit" title="' . __( 'Search', 'visualizer' ) . '"><i class="dashicons dashicons-search"></i></button> | |
| 126 | - </p> </form>'; | |
| 127 | - | |
| 226 | + $this->getDisplayForm(); | |
| 128 | 227 | echo '</div>'; |
| 129 | 228 | echo '<div id="visualizer-content-wrapper">'; |
| 130 | 229 | if ( ! empty( $this->charts ) ) { |
| 131 | 230 | echo '<div id="visualizer-library" class="visualizer-clearfix">'; |