column
12 years ago
storage_model
12 years ago
column.php
12 years ago
deprecated.php
12 years ago
settings.php
12 years ago
storage_model.php
12 years ago
third_party.php
12 years ago
upgrade.php
12 years ago
utility.php
12 years ago
settings.php
857 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * CPAC_Settings Class |
| 5 | * |
| 6 | * @since 2.0.0 |
| 7 | */ |
| 8 | class CPAC_Settings { |
| 9 | |
| 10 | /** |
| 11 | * CPAC class |
| 12 | * |
| 13 | * @since 2.0.0 |
| 14 | */ |
| 15 | private $cpac; |
| 16 | |
| 17 | /** |
| 18 | * Settings uri |
| 19 | * |
| 20 | * @since 2.0.0 |
| 21 | * @param array URL for general, settings and info screens |
| 22 | */ |
| 23 | private $settings_urls = array(); |
| 24 | |
| 25 | /** |
| 26 | * Constructor |
| 27 | * |
| 28 | * @since 2.0.0 |
| 29 | * @param object CPAC |
| 30 | */ |
| 31 | function __construct( $cpac ) { |
| 32 | |
| 33 | $this->cpac = $cpac; |
| 34 | |
| 35 | // register settings |
| 36 | add_action( 'admin_menu', array( $this, 'settings_menu' ) ); |
| 37 | |
| 38 | // handle requests gets a low priority so it will trigger when all other plugins have loaded their columns |
| 39 | add_action( 'admin_init', array( $this, 'handle_column_request' ), 1000 ); |
| 40 | |
| 41 | // handle addon downloads |
| 42 | add_action( 'admin_init', array( $this, 'handle_download_request' ) ); |
| 43 | |
| 44 | add_action( 'wp_ajax_cpac_column_refresh', array( $this, 'ajax_column_refresh' ) ); |
| 45 | |
| 46 | // Settings Url's |
| 47 | $this->settings_urls = (object) array( |
| 48 | 'admin' => admin_url( 'options-general.php?page=codepress-admin-columns' ), |
| 49 | 'general' => admin_url( 'options-general.php?page=codepress-admin-columns&tab=general' ), |
| 50 | 'settings' => admin_url( 'options-general.php?page=codepress-admin-columns&tab=settings' ), |
| 51 | 'info' => admin_url( 'options-general.php?page=codepress-admin-columns&info=' ), |
| 52 | 'upgrade' => admin_url( 'options-general.php?page=cpac-upgrade' ) |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | public function ajax_column_refresh() { |
| 57 | if ( ! empty( $_POST['formdata'] ) && ! empty( $_POST['column'] ) ) { |
| 58 | parse_str( $_POST['formdata'], $formdata ); |
| 59 | $storagemodel_key = ! empty( $formdata['cpac_key'] ) ? $formdata['cpac_key'] : ''; |
| 60 | |
| 61 | if ( $storagemodel_key && ! empty( $formdata[ $storagemodel_key ][ $_POST['column'] ] ) ) { |
| 62 | $columndata = $formdata[ $formdata['cpac_key'] ][ $_POST['column'] ]; |
| 63 | $storage_model = $this->cpac->get_storage_model( $formdata['cpac_key'] ); |
| 64 | $registered_columns = $storage_model->get_registered_columns(); |
| 65 | |
| 66 | if ( in_array( $columndata['type'], array_keys( $registered_columns ) ) ) { |
| 67 | $column = clone $registered_columns[ $columndata['type'] ]; |
| 68 | $column->set_clone( $columndata['clone'] ); |
| 69 | |
| 70 | foreach ( $columndata as $optionname => $optionvalue ) { |
| 71 | $column->set_options( $optionname, $optionvalue ); |
| 72 | } |
| 73 | |
| 74 | $column->sanitize_label(); |
| 75 | |
| 76 | $columns = array( $column->properties->name => $column ); |
| 77 | |
| 78 | do_action( 'cac/columns', $columns ); |
| 79 | do_action( "cac/columns/storage_key={$storagemodel_key}", $columns ); |
| 80 | |
| 81 | $column->display(); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | exit; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Admin Menu. |
| 91 | * |
| 92 | * Create the admin menu link for the settings page. |
| 93 | * |
| 94 | * @since 1.0.0 |
| 95 | */ |
| 96 | public function settings_menu() { |
| 97 | |
| 98 | // add settings page |
| 99 | $settings_page = add_submenu_page( 'options-general.php', __( 'Admin Columns Settings', 'cpac' ), __( 'Admin Columns', 'cpac' ), 'manage_admin_columns', 'codepress-admin-columns', array( $this, 'display' ), false, 98 ); |
| 100 | |
| 101 | // add help tabs |
| 102 | add_action( "load-{$settings_page}", array( $this, 'help_tabs' ) ); |
| 103 | |
| 104 | // add scripts & styles |
| 105 | add_action( "admin_print_styles-{$settings_page}", array( $this, 'admin_styles' ) ); |
| 106 | add_action( "admin_print_scripts-{$settings_page}", array( $this, 'admin_scripts' ) ); |
| 107 | |
| 108 | // register setting |
| 109 | register_setting( 'cpac-general-settings', 'cpac_general_options' ); |
| 110 | |
| 111 | // add cap to options.php |
| 112 | add_filter( 'option_page_capability_cpac-general-settings', array( $this, 'add_capability' ) ); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Add capability |
| 117 | * |
| 118 | * Allows the capaiblity 'manage_admin_columns' to store data through /wp-admin/options.php |
| 119 | * |
| 120 | * @since 2.0.0 |
| 121 | */ |
| 122 | public function add_capability() { |
| 123 | |
| 124 | return 'manage_admin_columns'; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Register admin css |
| 129 | * |
| 130 | * @since 1.0.0 |
| 131 | */ |
| 132 | public function admin_styles() { |
| 133 | wp_enqueue_style( 'wp-pointer' ); |
| 134 | wp_enqueue_style( 'jquery-ui-lightness', CPAC_URL . 'assets/ui-theme/jquery-ui-1.8.18.custom.css', array(), CPAC_VERSION, 'all' ); |
| 135 | wp_enqueue_style( 'cpac-admin', CPAC_URL . 'assets/css/admin-column.css', array(), CPAC_VERSION, 'all' ); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Register admin scripts |
| 140 | * |
| 141 | * @since 1.0.0 |
| 142 | */ |
| 143 | public function admin_scripts() { |
| 144 | |
| 145 | wp_enqueue_script( 'wp-pointer' ); |
| 146 | wp_enqueue_script( 'jquery-ui-slider' ); |
| 147 | wp_enqueue_script( 'cpac-admin-columns', CPAC_URL . 'assets/js/admin-columns.js', array( 'jquery', 'dashboard', 'jquery-ui-slider', 'jquery-ui-sortable' ), CPAC_VERSION ); |
| 148 | |
| 149 | // javascript translations |
| 150 | wp_localize_script( 'cpac-admin-columns', 'cpac_i18n', array( |
| 151 | 'clone' => __( '%s column is already present and can not be duplicated.', 'cpac' ), |
| 152 | )); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Handle column requests. |
| 157 | * |
| 158 | * @since 1.0.0 |
| 159 | */ |
| 160 | public function handle_column_request() { |
| 161 | |
| 162 | // only handle updates from the admin columns page |
| 163 | if ( ! ( isset($_GET['page'] ) && in_array( $_GET['page'], array( 'codepress-admin-columns' ) ) && isset( $_REQUEST['cpac_action'] ) ) ) |
| 164 | return false; |
| 165 | |
| 166 | // use $_REQUEST because the values are send both over $_GET and $_POST |
| 167 | $action = isset( $_REQUEST['cpac_action'] ) ? $_REQUEST['cpac_action'] : ''; |
| 168 | $nonce = isset( $_REQUEST['_cpac_nonce'] ) ? $_REQUEST['_cpac_nonce'] : ''; |
| 169 | $key = isset( $_REQUEST['cpac_key'] ) ? $_REQUEST['cpac_key'] : ''; |
| 170 | |
| 171 | switch ( $action ) : |
| 172 | |
| 173 | case 'update_by_type' : |
| 174 | |
| 175 | if ( wp_verify_nonce( $nonce, 'update-type' ) ) { |
| 176 | $storage_model = $this->cpac->get_storage_model( $key ); |
| 177 | $storage_model->store(); |
| 178 | } |
| 179 | break; |
| 180 | |
| 181 | case 'restore_by_type' : |
| 182 | if ( wp_verify_nonce( $nonce, 'restore-type' ) ) { |
| 183 | $storage_model = $this->cpac->get_storage_model( $key ); |
| 184 | $storage_model->restore(); |
| 185 | } |
| 186 | break; |
| 187 | |
| 188 | case 'restore_all' : |
| 189 | if ( wp_verify_nonce( $nonce, 'restore-all' ) ) { |
| 190 | $this->restore_all(); |
| 191 | } |
| 192 | break; |
| 193 | |
| 194 | endswitch; |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Restore defaults |
| 199 | * |
| 200 | * @since 1.0.0 |
| 201 | */ |
| 202 | private function restore_all() { |
| 203 | global $wpdb; |
| 204 | |
| 205 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'cpac_options_%'" ); |
| 206 | |
| 207 | cpac_admin_message( __( 'Default settings succesfully restored.', 'cpac' ), 'updated' ); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Add help tabs |
| 212 | * |
| 213 | * @since 1.3.0 |
| 214 | */ |
| 215 | public function help_tabs() { |
| 216 | |
| 217 | $screen = get_current_screen(); |
| 218 | |
| 219 | if ( ! method_exists( $screen,'add_help_tab' ) ) |
| 220 | return; |
| 221 | |
| 222 | // add help content |
| 223 | $tabs = array( |
| 224 | array( |
| 225 | 'title' => __( "Overview", 'cpac' ), |
| 226 | 'content' => |
| 227 | "<h5>Codepress Admin Columns</h5> |
| 228 | <p>". __( "This plugin is for adding and removing additional columns to the administration screens for post(types), pages, media library, comments, links and users. Change the column's label and reorder them.", 'cpac' ) . "</p>" |
| 229 | ), |
| 230 | array( |
| 231 | 'title' => __( "Basics", 'cpac' ), |
| 232 | 'content' => " |
| 233 | <h5>" . __( "Change order", 'cpac' ) . "</h5> |
| 234 | <p>" . __( "By dragging the columns you can change the order which they will appear in.", 'cpac' ) . "</p> |
| 235 | <h5>" . __( "Change label", 'cpac' ) . "</h5> |
| 236 | <p>" . __( "By clicking on the triangle you will see the column options. Here you can change each label of the columns heading.", 'cpac' ) . "</p> |
| 237 | <h5>" . __( "Change column width", 'cpac' ) . "</h5> |
| 238 | <p>" . __( "By clicking on the triangle you will see the column options. By using the draggable slider you can set the width of the columns in percentages.", 'cpac' ) . "</p> |
| 239 | " |
| 240 | ), |
| 241 | array( |
| 242 | 'title' => __( "Custom Field", 'cpac' ), |
| 243 | 'content' => |
| 244 | "<h5>". __( "'Custom Field' column", 'cpac' ) . "</h5> |
| 245 | <p>". __( "The custom field colum uses the custom fields from posts and users. There are 10 types which you can set.", 'cpac' ) . "</p> |
| 246 | <ul> |
| 247 | <li><strong>". __( "Default", 'cpac' ) . "</strong><br/>". __( "Value: Can be either a string or array. Arrays will be flattened and values are seperated by a ',' comma.", 'cpac' ) . "</li> |
| 248 | <li><strong>". __( "Image", 'cpac' ) . "</strong><br/>". __( "Value: should contain an image URL or Attachment IDs ( seperated by a ',' comma ).", 'cpac' ) . "</li> |
| 249 | <li><strong>". __( "Excerpt", 'cpac' ) . "</strong><br/>". __( "Value: This will show the first 20 words of the Post content.", 'cpac' ) . "</li> |
| 250 | <li><strong>". __( "Multiple Values", 'cpac' ) . "</strong><br/>". __( "Value: should be an array. This will flatten any ( multi dimensional ) array.", 'cpac' ) . "</li> |
| 251 | <li><strong>". __( "Numeric", 'cpac' ) . "</strong><br/>". __( "Value: Integers only.<br/>If you have the 'sorting addon' this will be used for sorting, so you can sort your posts on numeric (custom field) values.", 'cpac' ) . "</li> |
| 252 | <li><strong>". __( "Date", 'cpac' ) . "</strong><br/>". sprintf( __( "Value: Can be unix time stamp or a date format as described in the <a href='%s'>Codex</a>. You can change the outputted date format at the <a href='%s'>general settings</a> page.", 'cpac' ), 'http://codex.wordpress.org/Formatting_Date_and_Time', get_admin_url() . 'options-general.php' ) . "</li> |
| 253 | <li><strong>". __( "Post Titles", 'cpac' ) . "</strong><br/>". __( "Value: can be one or more Post ID's (seperated by ',').", 'cpac' ) . "</li> |
| 254 | <li><strong>". __( "Usernames", 'cpac' ) . "</strong><br/>". __( "Value: can be one or more User ID's (seperated by ',').", 'cpac' ) . "</li> |
| 255 | <li><strong>". __( "Checkmark", 'cpac' ) . "</strong><br/>". __( "Value: should be a 1 (one) or 0 (zero).", 'cpac' ) . "</li> |
| 256 | <li><strong>". __( "Color", 'cpac' ) . "</strong><br/>". __( "Value: hex value color, such as #808080.", 'cpac' ) . "</li> |
| 257 | <li><strong>". __( "Counter", 'cpac' ) . "</strong><br/>". __( "Value: Can be either a string or array. This will display a count of the number of times the meta key is used by the item.", 'cpac' ) . "</li> |
| 258 | </ul> |
| 259 | " |
| 260 | ) |
| 261 | ); |
| 262 | |
| 263 | foreach ( $tabs as $k => $tab ) { |
| 264 | $screen->add_help_tab( array( |
| 265 | 'id' => 'cpac-tab-'.$k, |
| 266 | 'title' => $tab['title'], |
| 267 | 'content' => $tab['content'], |
| 268 | )); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * External Urls |
| 274 | * |
| 275 | * @since 1.0.0 |
| 276 | * |
| 277 | * @param string $storage_model URL type. |
| 278 | * @return string Url. |
| 279 | */ |
| 280 | function get_url( $type ) { |
| 281 | |
| 282 | $site_url = 'http://www.codepresshq.com'; |
| 283 | |
| 284 | $urls = array( |
| 285 | 'codepress' => $site_url, |
| 286 | 'admincolumns' => $site_url . '/wordpress-plugins/admin-columns/', |
| 287 | 'pro_addon' => $site_url . '/wordpress-plugins/admin-columns/pro-add-on/', |
| 288 | 'documentation' => $site_url . '/wordpress-plugins/admin-columns/', |
| 289 | 'feedback' => $site_url . '/contact', |
| 290 | 'plugins' => 'http://wordpress.org/extend/plugins/codepress-admin-columns/', |
| 291 | 'support' => 'http://wordpress.org/tags/codepress-admin-columns/', |
| 292 | ); |
| 293 | |
| 294 | if ( ! isset( $urls[ $type ] ) ) |
| 295 | return false; |
| 296 | |
| 297 | return $urls[ $type ]; |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Has Custom Field |
| 302 | * |
| 303 | * @since 2.0.0 |
| 304 | */ |
| 305 | public function uses_custom_fields() { |
| 306 | |
| 307 | $old_columns = get_option('cpac_options'); |
| 308 | |
| 309 | if ( empty( $old_columns['columns'] ) ) return false; |
| 310 | |
| 311 | foreach ( $old_columns['columns'] as $columns ) { |
| 312 | foreach ( $columns as $id => $values ) { |
| 313 | if ( strpos( $id, 'column-meta-' ) !== false ) |
| 314 | return true; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | return false; |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Handle Addon Download |
| 323 | * |
| 324 | * @since 2.0.0 |
| 325 | */ |
| 326 | function handle_download_request() { |
| 327 | |
| 328 | // API domain |
| 329 | $store_url = 'http://codepresshq.com'; |
| 330 | |
| 331 | if ( ! isset( $_REQUEST['cpac_product_id'] ) ) return false; |
| 332 | |
| 333 | $args = array( |
| 334 | 'codepress-wc-api' => 'plugin_updater', |
| 335 | 'secret_key' => '', |
| 336 | 'product_id' => $_REQUEST['cpac_product_id'], |
| 337 | 'licence_key' => isset( $_REQUEST['cpac_license_key'] ) ? $_REQUEST['cpac_license_key'] : '', |
| 338 | 'slug' => '', |
| 339 | 'instance' => 'fresh_install' |
| 340 | ); |
| 341 | |
| 342 | $result = wp_remote_get( add_query_arg( $args, $store_url ), array( 'timeout' => 15, 'sslverify' => false ) ); |
| 343 | |
| 344 | // Call the custom API. |
| 345 | $response = json_decode( wp_remote_retrieve_body( $result ) ); |
| 346 | |
| 347 | if ( ! $response ) { |
| 348 | cpac_admin_message( 'Could not connect to API.', 'error' ); |
| 349 | return; |
| 350 | } |
| 351 | if( isset( $response->error ) ) { |
| 352 | cpac_admin_message( $response->error, 'error' ); |
| 353 | return; |
| 354 | } |
| 355 | if( empty( $response->package ) ) { |
| 356 | cpac_admin_message( 'No File found.', 'error' ); |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | // no @ signs allowed/ |
| 361 | // source: http://wordpress.stackexchange.com/questions/64818/wp-sanitize-redirect-strips-out-signs-even-from-parameters-why |
| 362 | $redirect_url = str_replace( '@', urlencode('@'), $response->package ); |
| 363 | |
| 364 | wp_redirect( $redirect_url ); |
| 365 | exit; |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Welcome screen |
| 370 | * |
| 371 | * @since 2.0.0 |
| 372 | */ |
| 373 | public function welcome_screen() { |
| 374 | |
| 375 | // Should only be set after upgrade |
| 376 | $show_welcome = false !== get_transient('cpac_show_welcome'); |
| 377 | |
| 378 | // Should only be set manual |
| 379 | if ( isset( $_GET['info'] ) ) |
| 380 | $show_welcome = true; |
| 381 | |
| 382 | if ( ! $show_welcome ) |
| 383 | return false; |
| 384 | |
| 385 | // Set check that welcome should not be displayed. |
| 386 | delete_transient('cpac_show_welcome'); |
| 387 | |
| 388 | // Get tab |
| 389 | $tab = !empty( $_GET['info'] ) ? $_GET['info'] : 'whats-new'; |
| 390 | |
| 391 | // check if old site used custom field columns |
| 392 | $uses_customfields = $this->uses_custom_fields(); |
| 393 | $uses_sortorder = get_option( "cpac_sortable_ac" ) && ! class_exists( 'CAC_Addon_Pro' ) ? true : false; |
| 394 | |
| 395 | $installed_customfields = false; |
| 396 | $installed_sortorder = false; |
| 397 | |
| 398 | ?> |
| 399 | |
| 400 | <div id="cpac-welcome" class="wrap about-wrap"> |
| 401 | |
| 402 | <h1><?php _e( "Welcome to Admin Columns",'cpac'); ?> <?php echo CPAC_VERSION; ?></h1> |
| 403 | |
| 404 | <div class="about-text"> |
| 405 | <?php _e( "Thank you for updating to the latest version!", 'cpac' ); ?> |
| 406 | <?php _e( "Admin Columns is more polished and enjoyable than ever before. We hope you like it.", 'cpac' ); ?> |
| 407 | </div> |
| 408 | |
| 409 | <div class="cpac-content-body"> |
| 410 | <h2 class="nav-tab-wrapper"> |
| 411 | <a class="cpac-tab-toggle nav-tab <?php if( $tab == 'whats-new' ){ echo 'nav-tab-active'; } ?>" href="<?php echo $this->settings_urls->info; ?>whats-new"><?php _e( "What’s New", 'cpac' ); ?></a> |
| 412 | <a class="cpac-tab-toggle nav-tab <?php if( $tab == 'changelog' ){ echo 'nav-tab-active'; } ?>" href="<?php echo $this->settings_urls->info; ?>changelog"><?php _e( "Changelog", 'cpac' ); ?></a> |
| 413 | <?php if( $tab == 'download-add-ons' ): ?> |
| 414 | <a class="cpac-tab-toggle nav-tab nav-tab-active" href="<?php echo $this->settings_urls->info; ?>download-add-ons"><?php _e( "Download Addons", 'cpac' ); ?></a> |
| 415 | <?php endif; ?> |
| 416 | </h2> |
| 417 | |
| 418 | <?php if ( 'whats-new' === $tab ) : ?> |
| 419 | |
| 420 | <h3><?php _e( "Addons", 'cpac' ); ?></h3> |
| 421 | <p> |
| 422 | <?php _e( "Addons are now activated by downloading and installing individual plugins. Although these plugins will not be hosted on the wordpress.org repository, each Add-on will continue to receive updates in the usual way.",'cpac'); ?> |
| 423 | </p> |
| 424 | <?php if ( $uses_sortorder ) : ?> |
| 425 | <h4><?php _e( "This website uses the Sortorder Addon. This addon needs to be downloaded." ,'cpac' ); ?></h4> |
| 426 | <div class="cpac-alert cpac-alert-success"> |
| 427 | <p> |
| 428 | <?php _e( "Addons are seperate plugins which need to be downloaded.", 'cpac' ); ?> <a href="<?php echo $this->settings_urls->info; ?>download-add-ons" class="button-primary" style="display: inline-block;"><?php _e( "Download your Addons", 'cpac'); ?></a> |
| 429 | </p> |
| 430 | </div> |
| 431 | <?php else : ?> |
| 432 | <div class="cpac-alert cpac-alert-success"> |
| 433 | <p> |
| 434 | <strong><?php _e( 'This website does not use add-ons', 'cpac' ); ?></strong>. <a target="_blank" href="<?php echo $this->get_url('pro_addon'); ?>"><?php _e( 'See our website for the Pro-addon.', 'cpac' ); ?></a> |
| 435 | </p> |
| 436 | </div> |
| 437 | <?php endif; ?> |
| 438 | |
| 439 | <hr /> |
| 440 | |
| 441 | <h3><?php _e( "Important", 'cpac' ); ?></h3> |
| 442 | |
| 443 | <h4><?php _e( "Database Changes", 'cpac' ); ?></h4> |
| 444 | <p><?php _e("The database has been changed between versions 1 and 2. But we made sure you can still roll back to version 1x without any issues.",'cpac'); ?></p> |
| 445 | |
| 446 | <?php if ( get_option( 'cpac_version', false ) < CPAC_UPGRADE_VERSION ) : ?> |
| 447 | <p><?php _e("Make sure you backup your database and then click",'cpac'); ?> <a href="<?php echo $this->settings_urls->upgrade; ?>" class="button-primary"><?php _e( "Upgrade Database", 'cpac' );?></a></p> |
| 448 | <?php endif; ?> |
| 449 | |
| 450 | <h4><?php _e( "Potential Issues", 'cpac' ); ?></h4> |
| 451 | <p><?php _e( "Do to the sizable refactoring the code, surounding Addons and action/filters, your website may not operate correctly. It is important that you read the full", 'cpac' ); ?> <a href="<?php echo $this->get_url('admincolumns'); ?>migrating-from-v1-to-v2" target="_blank"><?php _e( "Migrating from v1 to v2", 'cpac' ); ?></a> <?php _e( "guide to view the full list of changes.", 'cpac' ); ?> <?php printf( __( 'When you have found a bug please <a href="%s">report them to us</a> so we can fix it in the next release.', 'cpac'), 'mailto:info@codepress.nl' ); ?></p> |
| 452 | |
| 453 | <div class="cpac-alert cpac-alert-error"> |
| 454 | <p><strong><?php _e( "Important!", 'cpac' ); ?></strong> <?php _e( "If you updated the Admin Columns plugin without prior knowledge of such changes, Please roll back to the latest", 'cpac' ); ?> <a href="http://downloads.wordpress.org/plugin/codepress-admin-columns.1.4.9.zip"> <?php _e( "version 1", 'cpac' ); ?></a> <?php _e( "of this plugin.", 'cpac' ); ?></p> |
| 455 | </div> |
| 456 | |
| 457 | <?php endif; ?> |
| 458 | <?php if ( 'changelog' === $tab ) : ?> |
| 459 | |
| 460 | <h3><?php _e("Changelog for", 'cpac'); ?> <?php echo CPAC_VERSION; ?></h3> |
| 461 | <?php |
| 462 | |
| 463 | $items = file_get_contents( CPAC_DIR . 'readme.txt' ); |
| 464 | |
| 465 | $items = end( explode('= ' . CPAC_VERSION . ' =', $items) ); |
| 466 | $items = current( explode("\n\n", $items) ); |
| 467 | $items = current( explode("= ", $items) ); |
| 468 | $items = array_filter( array_map('trim', explode("*", $items)) ); |
| 469 | |
| 470 | ?> |
| 471 | <ul class="cpac-changelog"> |
| 472 | <?php foreach( $items as $item ) : |
| 473 | $item = explode('http', $item); |
| 474 | ?> |
| 475 | <li><?php echo $item[0]; ?><?php if( isset($item[1]) ): ?><a href="http<?php echo $item[1]; ?>" target="_blank"><?php _e("Learn more", 'cpac'); ?></a><?php endif; ?></li> |
| 476 | <?php endforeach; ?> |
| 477 | </ul> |
| 478 | |
| 479 | <?php endif; ?> |
| 480 | <?php if ( 'download-add-ons' === $tab ) : ?> |
| 481 | |
| 482 | <h3><?php _e("Overview",'cpac'); ?></h3> |
| 483 | |
| 484 | <p><?php _e( "New to v2, all Addons act as separate plugins which need to be individually downloaded, installed and updated.", 'cpac' ); ?></p> |
| 485 | <p><?php _e( "This page will assist you in downloading and installing each available Addon.", 'cpac' ); ?></p> |
| 486 | <h3><?php _e( "Available Addons", 'cpac' ); ?></h3> |
| 487 | |
| 488 | <table class="widefat" id="cpac-download-add-ons-table"> |
| 489 | <thead> |
| 490 | <tr> |
| 491 | <th><?php _e("Name",'cpac'); ?></th> |
| 492 | <th><?php _e("Download",'cpac'); ?></th> |
| 493 | </tr> |
| 494 | </thead> |
| 495 | <tbody> |
| 496 | <?php if ( $uses_sortorder ): ?> |
| 497 | <tr> |
| 498 | <th class="td-name"><?php _e("Pro Add-on (includes Sortorder add-on)",'cpac'); ?></th> |
| 499 | <td class="td-download"> |
| 500 | <a class="button" href="<?php echo $this->settings_urls->info; ?>download-add-ons&cpac_product_id=cac-pro&cpac_license_key=<?php echo get_option( "cpac_sortable_ac" ); ?>"><?php _e("Download",'cpac'); ?></a> |
| 501 | </td> |
| 502 | </tr> |
| 503 | <?php endif; ?> |
| 504 | |
| 505 | </tbody> |
| 506 | </table> |
| 507 | |
| 508 | <h3><?php _e("Installation",'cpac'); ?></h3> |
| 509 | |
| 510 | <p><?php _e("For each Add-on available, please perform the following:",'cpac'); ?></p> |
| 511 | <ol> |
| 512 | <li><?php _e("Download the Addon plugin (.zip file) to your desktop",'cpac'); ?></li> |
| 513 | <li><?php _e("Navigate to",'cpac'); ?> <a target="_blank" href="<?php echo admin_url('plugin-install.php?tab=upload'); ?>"><?php _e("Plugins > Add New > Upload",'cpac'); ?></a></li> |
| 514 | <li><?php _e("Use the uploader to browse, select and install your Add-on (.zip file)",'cpac'); ?></li> |
| 515 | <li><?php _e("Once the plugin has been uploaded and installed, click the 'Activate Plugin' link",'cpac'); ?></li> |
| 516 | <li><?php _e("The Add-on is now installed and activated!",'cpac'); ?></li> |
| 517 | <li><?php printf( __("For automatic updates make sure to <a href='%s'>enter your licence key</a>.",'cpac'), $this->settings_urls->settings ); ?></li> |
| 518 | </ol> |
| 519 | |
| 520 | <?php endif; ?> |
| 521 | |
| 522 | <hr/> |
| 523 | |
| 524 | </div><!--.cpac-content-body--> |
| 525 | |
| 526 | <div class="cpac-content-footer"> |
| 527 | <a class="button-primary button-large" href="<?php echo $this->settings_urls->general; ?>"><?php _e("Start using Admin Columns",'cpac'); ?></a> |
| 528 | </div><!--.cpac-content-footer--> |
| 529 | |
| 530 | </div> |
| 531 | <?php |
| 532 | |
| 533 | return true; |
| 534 | } |
| 535 | |
| 536 | /** |
| 537 | * Menu |
| 538 | * |
| 539 | * @since 2.1.2 |
| 540 | */ |
| 541 | function display_menu_by_type( $menu_type = '', $label = '', $active_item = '' ) { |
| 542 | |
| 543 | $storage_models_by_type = array(); |
| 544 | |
| 545 | foreach( $this->cpac->storage_models as $k => $storage_model ) { |
| 546 | if ( $menu_type == $storage_model->menu_type ) { |
| 547 | $storage_models_by_type[ $menu_type ][ $k ] = $storage_model; |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | if ( ! empty( $storage_models_by_type[ $menu_type ] ) ) { $count = 0; ?> |
| 552 | <ul class="subsubsub"> |
| 553 | <li class="first"><?php echo $label; ?>: </li> |
| 554 | <?php foreach ( $storage_models_by_type[ $menu_type ] as $storage_model ) : ?> |
| 555 | <li><?php echo $count++ != 0 ? ' | ' : ''; ?><a href="#cpac-box-<?php echo $storage_model->key; ?>" <?php echo $storage_model->is_menu_type_current( $active_item ) ? ' class="current"' : '';?> ><?php echo $storage_model->label; ?></a></li> |
| 556 | <?php endforeach; ?> |
| 557 | </ul> |
| 558 | <?php |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * General Settings. |
| 564 | * |
| 565 | * @since 1.0.0 |
| 566 | */ |
| 567 | public function display_settings() { |
| 568 | ?> |
| 569 | <table class="form-table cpac-form-table"> |
| 570 | <tbody> |
| 571 | |
| 572 | <tr class="general"> |
| 573 | <th scope="row"> |
| 574 | <h3><?php _e( 'General Settings', 'cpac' ); ?></h3> |
| 575 | <p><?php _e( 'Customize your Admin Columns settings.', 'cpac' ); ?></p> |
| 576 | </th> |
| 577 | <td class="padding-22"> |
| 578 | <div class="cpac_general"> |
| 579 | <form method="post" action="options.php"> |
| 580 | <?php settings_fields( 'cpac-general-settings' ); ?> |
| 581 | <?php $options = get_option( 'cpac_general_options' ); ?> |
| 582 | <p> |
| 583 | <br/> |
| 584 | </p> |
| 585 | <p> |
| 586 | <label for="show_hidden"> |
| 587 | <input name="cpac_general_options[show_hidden]" id="show_hidden" type="checkbox" value="1" <?php checked( isset( $options['show_hidden'] ) ? $options['show_hidden'] : '', '1' ); ?>> |
| 588 | <?php _e( 'Show hidden custom fields. Default is <code>off</code>.', 'cpac' ); ?> |
| 589 | </label> |
| 590 | </p> |
| 591 | <p> |
| 592 | <label for="show_edit_button"> |
| 593 | <input name="cpac_general_options[show_edit_button]" id="show_edit_button" type="checkbox" value="1" <?php checked( isset( $options['show_edit_button'] ) ? $options['show_edit_button'] : '', '1' ); ?>> |
| 594 | <?php _e( 'Show "Edit Columns" button on admin screens. Default is <code>off</code>.', 'cpac' ); ?> |
| 595 | </label> |
| 596 | </p> |
| 597 | |
| 598 | <?php do_action( 'cac/settings/general', $options ); ?> |
| 599 | |
| 600 | <p> |
| 601 | <input type="submit" class="button" value="<?php _e( 'Save' ); ?>" /> |
| 602 | </p> |
| 603 | </form> |
| 604 | </div> |
| 605 | </td> |
| 606 | </tr><!--.general--> |
| 607 | |
| 608 | <?php |
| 609 | |
| 610 | /** Allow plugins to add their own custom settings to the settings page. */ |
| 611 | if ( $groups = apply_filters( 'cac/settings/groups', array() ) ) { |
| 612 | |
| 613 | foreach ( $groups as $id => $group ) { |
| 614 | |
| 615 | $title = isset( $group['title'] ) ? $group['title'] : ''; |
| 616 | $description = isset( $group['description'] ) ? $group['description'] : ''; |
| 617 | |
| 618 | ?> |
| 619 | <tr> |
| 620 | <th scope="row"> |
| 621 | <h3><?php echo $title; ?></h3> |
| 622 | <p><?php echo $description; ?></p> |
| 623 | </th> |
| 624 | <td class="padding-22"> |
| 625 | <?php |
| 626 | |
| 627 | /** Use this Hook to add additonal fields to the group */ |
| 628 | do_action( "cac/settings/groups/row={$id}" ); |
| 629 | |
| 630 | ?> |
| 631 | </td> |
| 632 | </tr> |
| 633 | <?php |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | ?> |
| 638 | |
| 639 | <tr class="restore"> |
| 640 | <th scope="row"> |
| 641 | <h3><?php _e( 'Restore Settings', 'cpac' ); ?></h3> |
| 642 | <p><?php _e( 'This will delete all column settings and restore the default settings.', 'cpac' ); ?></p> |
| 643 | </th> |
| 644 | <td class="padding-22"> |
| 645 | <form method="post" action=""> |
| 646 | <?php wp_nonce_field( 'restore-all','_cpac_nonce'); ?> |
| 647 | <input type="hidden" name="cpac_action" value="restore_all" /> |
| 648 | <input type="submit" class="button" name="cpac-restore-defaults" value="<?php _e( 'Restore default settings', 'cpac' ) ?>" onclick="return confirm('<?php _e("Warning! ALL saved admin columns data will be deleted. This cannot be undone. \'OK\' to delete, \'Cancel\' to stop", 'cpac' ); ?>');" /> |
| 649 | </form> |
| 650 | </td> |
| 651 | </tr><!--.restore--> |
| 652 | |
| 653 | </tbody> |
| 654 | </table> |
| 655 | |
| 656 | <?php |
| 657 | } |
| 658 | |
| 659 | /** |
| 660 | * Column Settings. |
| 661 | * |
| 662 | * @since 1.0.0 |
| 663 | */ |
| 664 | public function display() { |
| 665 | |
| 666 | // Load Welcome screen |
| 667 | if ( $this->welcome_screen() ) return; |
| 668 | |
| 669 | $tabs = array( |
| 670 | 'general' => __( 'Admin Columns', 'cpac' ), |
| 671 | 'settings' => __( 'Settings', 'cpac' ) |
| 672 | ); |
| 673 | |
| 674 | $current_tab = ( empty( $_GET['tab'] ) ) ? 'general' : sanitize_text_field( urldecode( $_GET['tab'] ) ); |
| 675 | |
| 676 | // get first element from post-types |
| 677 | $post_types = array_values( $this->cpac->get_post_types() ); |
| 678 | $first = array_shift( $post_types ); |
| 679 | ?> |
| 680 | |
| 681 | <div id="cpac" class="wrap"> |
| 682 | |
| 683 | <?php screen_icon( 'codepress-admin-columns' ); ?> |
| 684 | |
| 685 | <h2 class="nav-tab-wrapper cpac-nav-tab-wrapper"> |
| 686 | <?php foreach( $tabs as $name => $label ) : ?> |
| 687 | <a href="<?php echo $this->settings_urls->admin . "&tab={$name}"; ?>" class="nav-tab<?php if( $current_tab == $name ) echo ' nav-tab-active'; ?>"><?php echo $label; ?></a> |
| 688 | <?php endforeach; ?> |
| 689 | </h2> |
| 690 | |
| 691 | <?php do_action( 'cpac_messages' ); ?> |
| 692 | |
| 693 | <?php |
| 694 | switch ( $current_tab ) : |
| 695 | |
| 696 | case "general" : |
| 697 | ?> |
| 698 | |
| 699 | <div class="cpac-menu"> |
| 700 | <?php $this->display_menu_by_type( 'post', __( 'Posttypes', 'cpac' ), $first ); ?> |
| 701 | <?php $this->display_menu_by_type( 'other', __( 'Others', 'cpac' ) ); ?> |
| 702 | <?php $this->display_menu_by_type( 'taxonomy', __( 'Taxonomies', 'cpac' ) ); ?> |
| 703 | </div> |
| 704 | |
| 705 | <?php $count = 0; ?> |
| 706 | <?php foreach ( $this->cpac->storage_models as $storage_model ) : ?> |
| 707 | |
| 708 | <div class="columns-container" data-type="<?php echo $storage_model->key ?>"<?php echo $storage_model->is_menu_type_current( $first ) ? '' : ' style="display:none"'; ?>> |
| 709 | |
| 710 | <div class="columns-left"> |
| 711 | <div id="titlediv"> |
| 712 | <h2> |
| 713 | <?php echo $storage_model->label; ?> |
| 714 | <?php $storage_model->screen_link(); ?> |
| 715 | </h2> |
| 716 | </div> |
| 717 | </div> |
| 718 | |
| 719 | <div class="columns-right"> |
| 720 | <div class="columns-right-inside"> |
| 721 | <div class="sidebox" id="form-actions"> |
| 722 | <h3> |
| 723 | <?php _e( 'Store settings', 'cpac' ) ?> |
| 724 | </h3> |
| 725 | <?php $has_been_stored = $storage_model->get_stored_columns() ? true : false; ?> |
| 726 | <div class="form-update"> |
| 727 | <a href="javascript:;" class="button-primary submit-update"><?php echo $has_been_stored ? __( 'Update' ) : __('Save'); ?> <?php echo $storage_model->label; ?></a> |
| 728 | </div> |
| 729 | <?php if ( $has_been_stored ) : ?> |
| 730 | <div class="form-reset"> |
| 731 | <a href="<?php echo add_query_arg( array( '_cpac_nonce' => wp_create_nonce('restore-type'), 'cpac_key' => $storage_model->key, 'cpac_action' => 'restore_by_type' ), $this->settings_urls->admin ); ?>" class="reset-column-type" onclick="return confirm('<?php printf( __( "Warning! The %s columns data will be deleted. This cannot be undone. \'OK\' to delete, \'Cancel\' to stop", 'cpac' ), $storage_model->label ); ?>');"> |
| 732 | <?php _e( 'Restore', 'cpac' ); ?> <?php echo $storage_model->label; ?> <?php _e( 'columns', 'cpac' ); ?> |
| 733 | </a> |
| 734 | </div> |
| 735 | <?php endif; ?> |
| 736 | |
| 737 | <?php do_action( 'cac/settings/form_actions', $storage_model ); ?> |
| 738 | |
| 739 | </div><!--form-actions--> |
| 740 | |
| 741 | <?php if ( ! class_exists( 'CAC_Addon_Pro' ) ) : ?> |
| 742 | <div class="sidebox" id="pro-version"> |
| 743 | <div class="padding-box cta"> |
| 744 | <h3> |
| 745 | <a href="<?php echo $this->get_url('pro_addon'); ?>"><?php _e( 'Get the Pro Add-on', 'cpac' ) ?></a> |
| 746 | </h3> |
| 747 | <div class="inside"> |
| 748 | <ul> |
| 749 | <li><a href="<?php echo $this->get_url('pro_addon'); ?>"><?php _e( 'Add Sorting', 'cpac' ); ?></a></li> |
| 750 | <li><a href="<?php echo $this->get_url('pro_addon'); ?>"><?php _e( 'Add Filtering', 'cpac' ); ?></a></li> |
| 751 | <li><a href="<?php echo $this->get_url('pro_addon'); ?>"><?php _e( 'Add Import/Export', 'cpac' ); ?></a></li> |
| 752 | </ul> |
| 753 | <p> |
| 754 | <?php printf( __( 'Check the <a href="%s">Pro Add-on</a> for more details!', 'cpac' ), $this->get_url('pro_addon') ); ?> |
| 755 | </p> |
| 756 | </div> |
| 757 | </div> |
| 758 | |
| 759 | |
| 760 | <?php |
| 761 | // @todo: add newsletter |
| 762 | /* ?> |
| 763 | <div class="padding-box newsletter"> |
| 764 | <form action="http://codepress.us4.list-manage.com/subscribe/post?u=902ae7f162ce5bc38a0bc8a4f&id=183e843a76" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" target="_blank"> |
| 765 | <?php $user = wp_get_current_user(); ?> |
| 766 | <p> |
| 767 | <?php _e ( "Subscribe to receive news & updates below.", 'cpac' ); ?> |
| 768 | </p> |
| 769 | <div class="mc-field-group"> |
| 770 | <label for="mce-FNAME"><?php _e( 'First Name', 'cpac' ); ?></label> |
| 771 | <input type="text" value="<?php echo trim( esc_attr( $user->first_name ) ); ?>" name="FNAME" class="" id="mce-FNAME"> |
| 772 | </div> |
| 773 | <div class="mc-field-group"> |
| 774 | <label for="mce-EMAIL"><?php _e( 'Your Email', 'cpac' ); ?></label> |
| 775 | <input type="email" value="<?php echo trim( esc_attr( $user->user_email ) ); ?>" name="EMAIL" class="required email" id="mce-EMAIL"> |
| 776 | </div> |
| 777 | <input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"> |
| 778 | </form> |
| 779 | </div> |
| 780 | <?php */ ?> |
| 781 | </div><!--pro-version--> |
| 782 | <?php endif; ?> |
| 783 | |
| 784 | <div class="sidebox" id="plugin-support"> |
| 785 | <h3><?php _e( 'Support', 'cpac' ); ?></h3> |
| 786 | <div class="inside"> |
| 787 | <?php if ( version_compare( get_bloginfo( 'version' ), '3.2', '>' ) ) : ?> |
| 788 | <p><?php _e( 'Check the <strong>Help</strong> section in the top-right screen.', 'cpac' ); ?></p> |
| 789 | <?php endif; ?> |
| 790 | <p> |
| 791 | <?php printf( __("For full documentation, bug reports, feature suggestions and other tips <a href='%s'>visit the Admin Columns website</a>", 'cpac' ), $this->get_url('documentation') ); ?> |
| 792 | </p> |
| 793 | </div> |
| 794 | </div><!--plugin-support--> |
| 795 | |
| 796 | </div><!--.columns-right-inside--> |
| 797 | </div><!--.columns-right--> |
| 798 | |
| 799 | <div class="columns-left"> |
| 800 | <div class="cpac-boxes"> |
| 801 | <div class="cpac-columns"> |
| 802 | |
| 803 | <form method="post" action=""> |
| 804 | <?php wp_nonce_field( 'update-type', '_cpac_nonce'); ?> |
| 805 | |
| 806 | <input type="hidden" name="cpac_key" value="<?php echo $storage_model->key; ?>" /> |
| 807 | <input type="hidden" name="cpac_action" value="update_by_type" /> |
| 808 | |
| 809 | <?php |
| 810 | foreach ( $storage_model->columns as $column ) { |
| 811 | $column->display(); |
| 812 | } |
| 813 | ?> |
| 814 | </form> |
| 815 | |
| 816 | </div><!--.cpac-columns--> |
| 817 | |
| 818 | <div class="column-footer"> |
| 819 | <div class="order-message"><?php _e( 'Drag and drop to reorder', 'cpac' ); ?></div> |
| 820 | |
| 821 | <div class="button-container"> |
| 822 | <a href="javascript:;" class="add_column button button-primary">+ <?php _e( 'Add Column', 'cpac' );?></a><br/> |
| 823 | </div> |
| 824 | |
| 825 | </div><!--.cpac-column-footer--> |
| 826 | </div><!--.cpac-boxes--> |
| 827 | </div><!--.columns-left--> |
| 828 | <div class="clear"></div> |
| 829 | |
| 830 | <div class="for-cloning-only" style="display:none"> |
| 831 | <?php |
| 832 | foreach ( $storage_model->get_registered_columns() as $column ) { |
| 833 | $column->display(); |
| 834 | } |
| 835 | ?> |
| 836 | </div> |
| 837 | |
| 838 | </div><!--.columns-container--> |
| 839 | |
| 840 | <?php endforeach; // storage_models ?> |
| 841 | |
| 842 | <div class="clear"></div> |
| 843 | |
| 844 | <?php |
| 845 | break; // case: general |
| 846 | |
| 847 | case 'settings' : |
| 848 | $this->display_settings(); |
| 849 | break; |
| 850 | |
| 851 | endswitch; |
| 852 | ?> |
| 853 | |
| 854 | </div><!--.wrap--> |
| 855 | <?php |
| 856 | } |
| 857 | } |