column
12 years ago
storage_model
12 years ago
api.php
12 years ago
column.php
12 years ago
deprecated.php
12 years ago
export_import.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
768 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 | // Settings Url's |
| 45 | $this->settings_urls = (object) array( |
| 46 | 'admin' => admin_url( 'options-general.php?page=codepress-admin-columns' ), |
| 47 | 'general' => admin_url( 'options-general.php?page=codepress-admin-columns&tab=general' ), |
| 48 | 'settings' => admin_url( 'options-general.php?page=codepress-admin-columns&tab=settings' ), |
| 49 | 'info' => admin_url( 'options-general.php?page=codepress-admin-columns&info=' ), |
| 50 | 'upgrade' => admin_url( 'options-general.php?page=cpac-upgrade' ) |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Admin Menu. |
| 56 | * |
| 57 | * Create the admin menu link for the settings page. |
| 58 | * |
| 59 | * @since 1.0.0 |
| 60 | */ |
| 61 | public function settings_menu() { |
| 62 | |
| 63 | // add pages @remove |
| 64 | //$this->admin_page = add_menu_page( __( 'Admin Columns Settings', 'cpac' ), __( 'Admin Columns', 'cpac' ), 'manage_admin_columns', 'codepress-admin-columns', array( $this, 'column_settings' ), false, 98 ); |
| 65 | //$settings_page = add_submenu_page( 'codepress-admin-columns', __( 'Settings', 'cpac' ), __( 'Settings', 'cpac' ), 'manage_admin_columns', 'cpac-settings', array( $this, 'general_settings' ) ); |
| 66 | |
| 67 | // add settings page |
| 68 | $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 ); |
| 69 | |
| 70 | // add help tabs |
| 71 | add_action( "load-{$settings_page}", array( $this, 'help_tabs' ) ); |
| 72 | |
| 73 | // add scripts & styles |
| 74 | add_action( "admin_print_styles-{$settings_page}", array( $this, 'admin_styles' ) ); |
| 75 | add_action( "admin_print_scripts-{$settings_page}", array( $this, 'admin_scripts' ) ); |
| 76 | |
| 77 | // register setting |
| 78 | register_setting( 'cpac-general-settings', 'cpac_general_options' ); |
| 79 | |
| 80 | // add capabilty to administrator to manage admin columns |
| 81 | // note to devs: you can use this to grant other roles this privilidge as well. |
| 82 | $role = get_role( 'administrator' ); |
| 83 | $role->add_cap( 'manage_admin_columns' ); |
| 84 | |
| 85 | // add cap to options.php |
| 86 | add_filter( 'option_page_capability_cpac-general-settings', array( $this, 'add_capability' ) ); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Add capability |
| 91 | * |
| 92 | * Allows the capaiblity 'manage_admin_columns' to store data through /wp-admin/options.php |
| 93 | * |
| 94 | * @since 2.0.0 |
| 95 | */ |
| 96 | public function add_capability() { |
| 97 | |
| 98 | return 'manage_admin_columns'; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Register admin css |
| 103 | * |
| 104 | * @since 1.0.0 |
| 105 | */ |
| 106 | public function admin_styles() { |
| 107 | wp_enqueue_style( 'wp-pointer' ); |
| 108 | wp_enqueue_style( 'jquery-ui-lightness', CPAC_URL . 'assets/ui-theme/jquery-ui-1.8.18.custom.css', array(), CPAC_VERSION, 'all' ); |
| 109 | wp_enqueue_style( 'cpac-admin', CPAC_URL . 'assets/css/admin-column.css', array(), CPAC_VERSION, 'all' ); |
| 110 | wp_enqueue_style( 'cpac-custom-fields-css', CPAC_URL . 'assets/css/custom-fields.css', array(), CPAC_VERSION, 'all' ); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Register admin scripts |
| 115 | * |
| 116 | * @since 1.0.0 |
| 117 | */ |
| 118 | public function admin_scripts() { |
| 119 | |
| 120 | wp_enqueue_script( 'wp-pointer' ); |
| 121 | wp_enqueue_script( 'jquery-ui-slider' ); |
| 122 | |
| 123 | // columns |
| 124 | wp_enqueue_script( 'cpac-admin-columns', CPAC_URL . 'assets/js/admin-columns.js', array( 'jquery', 'dashboard', 'jquery-ui-slider', 'jquery-ui-sortable' ), CPAC_VERSION ); |
| 125 | wp_enqueue_script( 'cpac-custom-fields-js', CPAC_URL . 'assets/js/custom-fields.js', array( 'jquery' ), CPAC_VERSION ); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Handle column requests. |
| 130 | * |
| 131 | * @since 1.0.0 |
| 132 | */ |
| 133 | public function handle_column_request() { |
| 134 | |
| 135 | // only handle updates from the admin columns page |
| 136 | if ( ! ( isset($_GET['page'] ) && in_array( $_GET['page'], array( 'codepress-admin-columns', 'cpac-settings' ) ) && isset( $_REQUEST['cpac_action'] ) ) ) |
| 137 | return false; |
| 138 | |
| 139 | // use $_REQUEST because the values are send both over $_GET and $_POST |
| 140 | $action = isset( $_REQUEST['cpac_action'] ) ? $_REQUEST['cpac_action'] : ''; |
| 141 | $nonce = isset( $_REQUEST['_cpac_nonce'] ) ? $_REQUEST['_cpac_nonce'] : ''; |
| 142 | $key = isset( $_REQUEST['cpac_key'] ) ? $_REQUEST['cpac_key'] : ''; |
| 143 | |
| 144 | switch ( $action ) : |
| 145 | |
| 146 | case 'update_by_type' : |
| 147 | if ( wp_verify_nonce( $nonce, 'update-type' ) ) { |
| 148 | $storage_model = $this->cpac->get_storage_model( $key ); |
| 149 | $storage_model->store(); |
| 150 | } |
| 151 | break; |
| 152 | |
| 153 | case 'restore_by_type' : |
| 154 | if ( wp_verify_nonce( $nonce, 'restore-type' ) ) { |
| 155 | $storage_model = $this->cpac->get_storage_model( $key ); |
| 156 | $storage_model->restore(); |
| 157 | } |
| 158 | break; |
| 159 | |
| 160 | case 'restore_all' : |
| 161 | if ( wp_verify_nonce( $nonce, 'restore-all' ) ) { |
| 162 | $this->restore_all(); |
| 163 | } |
| 164 | break; |
| 165 | |
| 166 | endswitch; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Restore defaults |
| 171 | * |
| 172 | * @since 1.0.0 |
| 173 | */ |
| 174 | private function restore_all() { |
| 175 | global $wpdb; |
| 176 | |
| 177 | $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'cpac_options_%'" ); |
| 178 | |
| 179 | cpac_admin_message( __( 'Default settings succesfully restored.', 'cpac' ), 'updated' ); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Add help tabs |
| 184 | * |
| 185 | * @since 1.3.0 |
| 186 | */ |
| 187 | public function help_tabs() { |
| 188 | |
| 189 | $screen = get_current_screen(); |
| 190 | |
| 191 | if ( ! method_exists( $screen,'add_help_tab' ) ) |
| 192 | return; |
| 193 | |
| 194 | // add help content |
| 195 | $tabs = array( |
| 196 | array( |
| 197 | 'title' => __( "Overview", 'cpac' ), |
| 198 | 'content' => |
| 199 | "<h5>Codepress Admin Columns</h5> |
| 200 | <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>" |
| 201 | ), |
| 202 | array( |
| 203 | 'title' => __( "Basics", 'cpac' ), |
| 204 | 'content' => |
| 205 | "<h5>". __( "Show / Hide", 'cpac' ) . "</h5> |
| 206 | <p>". __( "You can switch columns on or off by clicking on the checkbox. This will show or hide each column heading.", 'cpac' ) . "</p> |
| 207 | <h5>". __( "Change order", 'cpac' ) . "</h5> |
| 208 | <p>". __( "By dragging the columns you can change the order which they will appear in.", 'cpac' ) . "</p> |
| 209 | <h5>". __( "Change label", 'cpac' ) . "</h5> |
| 210 | <p>". __( "By clicking on the triangle you will see the column options. Here you can change each label of the columns heading.", 'cpac' ) . "</p> |
| 211 | <h5>". __( "Change column width", 'cpac' ) . "</h5> |
| 212 | <p>". __( "By clicking on the triangle you will see the column options. By using the draggable slider yo can set the width of the columns in percentages.", 'cpac' ) . "</p>" |
| 213 | ), |
| 214 | array( |
| 215 | 'title' => __( "Custom Field", 'cpac' ), |
| 216 | 'content' => |
| 217 | "<h5>". __( "'Custom Field' column", 'cpac' ) . "</h5> |
| 218 | <p>". __( "The custom field colum uses the custom fields from posts and users. There are 10 types which you can set.", 'cpac' ) . "</p> |
| 219 | <ul> |
| 220 | <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> |
| 221 | <li><strong>". __( "Image", 'cpac' ) . "</strong><br/>". __( "Value: should contain an image URL or Attachment IDs ( seperated by a ',' comma ).", 'cpac' ) . "</li> |
| 222 | <li><strong>". __( "Excerpt", 'cpac' ) . "</strong><br/>". __( "Value: This will show the first 20 words of the Post content.", 'cpac' ) . "</li> |
| 223 | <li><strong>". __( "Multiple Values", 'cpac' ) . "</strong><br/>". __( "Value: should be an array. This will flatten any ( multi dimensional ) array.", 'cpac' ) . "</li> |
| 224 | <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> |
| 225 | <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> |
| 226 | <li><strong>". __( "Post Titles", 'cpac' ) . "</strong><br/>". __( "Value: can be one or more Post ID's (seperated by ',').", 'cpac' ) . "</li> |
| 227 | <li><strong>". __( "Usernames", 'cpac' ) . "</strong><br/>". __( "Value: can be one or more User ID's (seperated by ',').", 'cpac' ) . "</li> |
| 228 | <li><strong>". __( "Checkmark", 'cpac' ) . "</strong><br/>". __( "Value: should be a 1 (one) or 0 (zero).", 'cpac' ) . "</li> |
| 229 | <li><strong>". __( "Color", 'cpac' ) . "</strong><br/>". __( "Value: hex value color, such as #808080.", 'cpac' ) . "</li> |
| 230 | </ul> |
| 231 | " |
| 232 | ) |
| 233 | ); |
| 234 | |
| 235 | foreach ( $tabs as $k => $tab ) { |
| 236 | $screen->add_help_tab( array( |
| 237 | 'id' => 'cpac-tab-'.$k, |
| 238 | 'title' => $tab['title'], |
| 239 | 'content' => $tab['content'], |
| 240 | )); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * External Urls |
| 246 | * |
| 247 | * @since 1.0.0 |
| 248 | * |
| 249 | * @param string $storage_model URL type. |
| 250 | * @return string Url. |
| 251 | */ |
| 252 | function get_url( $type ) { |
| 253 | |
| 254 | $site_url = 'http://www.codepresshq.com'; |
| 255 | |
| 256 | $urls = array( |
| 257 | 'codepress' => $site_url, |
| 258 | 'admincolumns' => $site_url . '/wordpress-plugins/admin-columns/', |
| 259 | 'pro_addon' => $site_url . '/wordpress-plugins/admin-columns/pro-add-on/', |
| 260 | 'documentation' => $site_url . '/wordpress-plugins/admin-columns/', |
| 261 | 'feedback' => $site_url . '/contact', |
| 262 | 'plugins' => 'http://wordpress.org/extend/plugins/codepress-admin-columns/', |
| 263 | 'support' => 'http://wordpress.org/tags/codepress-admin-columns/', |
| 264 | ); |
| 265 | |
| 266 | if ( ! isset( $urls[ $type ] ) ) |
| 267 | return false; |
| 268 | |
| 269 | return $urls[ $type ]; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Has Custom Field |
| 274 | * |
| 275 | * @since 2.0.0 |
| 276 | */ |
| 277 | public function uses_custom_fields() { |
| 278 | |
| 279 | $old_columns = get_option('cpac_options'); |
| 280 | |
| 281 | if ( empty( $old_columns['columns'] ) ) return false; |
| 282 | |
| 283 | foreach ( $old_columns['columns'] as $columns ) { |
| 284 | foreach ( $columns as $id => $values ) { |
| 285 | if ( strpos( $id, 'column-meta-' ) !== false ) |
| 286 | return true; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | return false; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Handle Addon Download |
| 295 | * |
| 296 | * @since 2.0.0 |
| 297 | */ |
| 298 | function handle_download_request() { |
| 299 | |
| 300 | // API domain |
| 301 | $store_url = 'http://codepresshq.com'; |
| 302 | |
| 303 | if ( ! isset( $_REQUEST['cpac_product_id'] ) ) return false; |
| 304 | |
| 305 | $args = array( |
| 306 | 'codepress-wc-api' => 'plugin_updater', |
| 307 | 'secret_key' => '', |
| 308 | 'product_id' => $_REQUEST['cpac_product_id'], |
| 309 | 'licence_key' => isset( $_REQUEST['cpac_license_key'] ) ? $_REQUEST['cpac_license_key'] : '', |
| 310 | 'slug' => '', |
| 311 | 'instance' => 'fresh_install' |
| 312 | ); |
| 313 | |
| 314 | $result = wp_remote_get( add_query_arg( $args, $store_url ), array( 'timeout' => 15, 'sslverify' => false ) ); |
| 315 | |
| 316 | // Call the custom API. |
| 317 | $response = json_decode( wp_remote_retrieve_body( $result ) ); |
| 318 | |
| 319 | if ( ! $response ) { |
| 320 | cpac_admin_message( 'Could not connect to API.', 'error' ); |
| 321 | return; |
| 322 | } |
| 323 | if( isset( $response->error ) ) { |
| 324 | cpac_admin_message( $response->error, 'error' ); |
| 325 | return; |
| 326 | } |
| 327 | if( empty( $response->package ) ) { |
| 328 | cpac_admin_message( 'No File found.', 'error' ); |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | // no @ signs allowed/ |
| 333 | // source: http://wordpress.stackexchange.com/questions/64818/wp-sanitize-redirect-strips-out-signs-even-from-parameters-why |
| 334 | $redirect_url = str_replace( '@', urlencode('@'), $response->package ); |
| 335 | |
| 336 | wp_redirect( $redirect_url ); |
| 337 | exit; |
| 338 | } |
| 339 | |
| 340 | /** |
| 341 | * Welcome screen |
| 342 | * |
| 343 | * @since 2.0.0 |
| 344 | */ |
| 345 | public function welcome_screen() { |
| 346 | |
| 347 | // Should only be set after upgrade |
| 348 | $show_welcome = false !== get_transient('cpac_show_welcome'); |
| 349 | |
| 350 | // Should only be set manual |
| 351 | if ( isset( $_GET['info'] ) ) |
| 352 | $show_welcome = true; |
| 353 | |
| 354 | if ( ! $show_welcome ) |
| 355 | return false; |
| 356 | |
| 357 | // Set check that welcome should not be displayed. |
| 358 | delete_transient('cpac_show_welcome'); |
| 359 | |
| 360 | // Get tab |
| 361 | $tab = !empty( $_GET['info'] ) ? $_GET['info'] : 'whats-new'; |
| 362 | |
| 363 | // check if old site used custom field columns |
| 364 | $uses_customfields = $this->uses_custom_fields(); |
| 365 | $uses_sortorder = get_option( "cpac_sortable_ac" ) && ! class_exists( 'CAC_Addon_Pro' ) ? true : false; |
| 366 | |
| 367 | $installed_customfields = false; |
| 368 | $installed_sortorder = false; |
| 369 | |
| 370 | ?> |
| 371 | <div id="cpac-welcome" class="wrap about-wrap"> |
| 372 | |
| 373 | <h1><?php _e( "Welcome to Admin Columns",'cpac'); ?> <?php echo CPAC_VERSION; ?></h1> |
| 374 | |
| 375 | <div class="about-text"> |
| 376 | <?php _e( "Thank you for updating to the latest version!", 'cpac' ); ?> |
| 377 | <?php _e( "Admin Columns is more polished and enjoyable than ever before. We hope you like it.", 'cpac' ); ?> |
| 378 | </div> |
| 379 | |
| 380 | <div class="cpac-content-body"> |
| 381 | <h2 class="nav-tab-wrapper"> |
| 382 | <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> |
| 383 | <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> |
| 384 | <?php if( $tab == 'download-add-ons' ): ?> |
| 385 | <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> |
| 386 | <?php endif; ?> |
| 387 | </h2> |
| 388 | |
| 389 | <?php if ( 'whats-new' === $tab ) : ?> |
| 390 | |
| 391 | <h3><?php _e( "Addons", 'cpac' ); ?></h3> |
| 392 | <p> |
| 393 | <?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'); ?> |
| 394 | </p> |
| 395 | <?php if ( $uses_sortorder ) : ?> |
| 396 | <h4><?php _e( "This website uses the Sortorder Addon. This addon needs to be downloaded." ,'cpac' ); ?></h4> |
| 397 | <div class="cpac-alert cpac-alert-success"> |
| 398 | <p> |
| 399 | <?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> |
| 400 | </p> |
| 401 | </div> |
| 402 | <?php else : ?> |
| 403 | <div class="cpac-alert cpac-alert-success"> |
| 404 | <p> |
| 405 | <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> |
| 406 | </p> |
| 407 | </div> |
| 408 | <?php endif; ?> |
| 409 | |
| 410 | <hr /> |
| 411 | |
| 412 | <h3><?php _e( "Important", 'cpac' ); ?></h3> |
| 413 | |
| 414 | <h4><?php _e( "Database Changes", 'cpac' ); ?></h4> |
| 415 | <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> |
| 416 | |
| 417 | <?php if ( get_option( 'cpac_version', false ) < CPAC_UPGRADE_VERSION ) : ?> |
| 418 | <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> |
| 419 | <?php endif; ?> |
| 420 | |
| 421 | <h4><?php _e( "Potential Issues", 'cpac' ); ?></h4> |
| 422 | <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> |
| 423 | |
| 424 | <div class="cpac-alert cpac-alert-error"> |
| 425 | <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> |
| 426 | </div> |
| 427 | |
| 428 | <?php endif; ?> |
| 429 | <?php if ( 'changelog' === $tab ) : ?> |
| 430 | |
| 431 | <h3><?php _e("Changelog for", 'cpac'); ?> <?php echo CPAC_VERSION; ?></h3> |
| 432 | <?php |
| 433 | |
| 434 | $items = file_get_contents( CPAC_DIR . 'readme.txt' ); |
| 435 | |
| 436 | $items = end( explode('= ' . CPAC_VERSION . ' =', $items) ); |
| 437 | $items = current( explode("\n\n", $items) ); |
| 438 | $items = current( explode("= ", $items) ); |
| 439 | $items = array_filter( array_map('trim', explode("*", $items)) ); |
| 440 | |
| 441 | ?> |
| 442 | <ul class="cpac-changelog"> |
| 443 | <?php foreach( $items as $item ) : |
| 444 | $item = explode('http', $item); |
| 445 | ?> |
| 446 | <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> |
| 447 | <?php endforeach; ?> |
| 448 | </ul> |
| 449 | |
| 450 | <?php endif; ?> |
| 451 | <?php if ( 'download-add-ons' === $tab ) : ?> |
| 452 | |
| 453 | <h3><?php _e("Overview",'cpac'); ?></h3> |
| 454 | |
| 455 | <p><?php _e( "New to v2, all Addons act as separate plugins which need to be individually downloaded, installed and updated.", 'cpac' ); ?></p> |
| 456 | <p><?php _e( "This page will assist you in downloading and installing each available Addon.", 'cpac' ); ?></p> |
| 457 | <h3><?php _e( "Available Addons", 'cpac' ); ?></h3> |
| 458 | |
| 459 | <table class="widefat" id="cpac-download-add-ons-table"> |
| 460 | <thead> |
| 461 | <tr> |
| 462 | <th><?php _e("Name",'cpac'); ?></th> |
| 463 | <th><?php _e("Download",'cpac'); ?></th> |
| 464 | </tr> |
| 465 | </thead> |
| 466 | <tbody> |
| 467 | <?php if ( $uses_sortorder ): ?> |
| 468 | <tr> |
| 469 | <th class="td-name"><?php _e("Pro Add-on (includes Sortorder add-on)",'cpac'); ?></th> |
| 470 | <td class="td-download"> |
| 471 | <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> |
| 472 | </td> |
| 473 | </tr> |
| 474 | <?php endif; ?> |
| 475 | |
| 476 | </tbody> |
| 477 | </table> |
| 478 | |
| 479 | <h3><?php _e("Installation",'cpac'); ?></h3> |
| 480 | |
| 481 | <p><?php _e("For each Add-on available, please perform the following:",'cpac'); ?></p> |
| 482 | <ol> |
| 483 | <li><?php _e("Download the Addon plugin (.zip file) to your desktop",'cpac'); ?></li> |
| 484 | <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> |
| 485 | <li><?php _e("Use the uploader to browse, select and install your Add-on (.zip file)",'cpac'); ?></li> |
| 486 | <li><?php _e("Once the plugin has been uploaded and installed, click the 'Activate Plugin' link",'cpac'); ?></li> |
| 487 | <li><?php _e("The Add-on is now installed and activated!",'cpac'); ?></li> |
| 488 | <li><?php printf( __("For automatic updates make sure to <a href='%s'>enter your licence key</a>.",'cpac'), $this->settings_urls->settings ); ?></li> |
| 489 | </ol> |
| 490 | |
| 491 | <?php endif; ?> |
| 492 | |
| 493 | <hr/> |
| 494 | |
| 495 | </div><!--.cpac-content-body--> |
| 496 | |
| 497 | <div class="cpac-content-footer"> |
| 498 | <a class="button-primary button-large" href="<?php echo $this->settings_urls->general; ?>"><?php _e("Start using Admin Columns",'cpac'); ?></a> |
| 499 | </div><!--.cpac-content-footer--> |
| 500 | |
| 501 | </div> |
| 502 | <?php |
| 503 | |
| 504 | return true; |
| 505 | } |
| 506 | |
| 507 | /** |
| 508 | * Column Settings. |
| 509 | * |
| 510 | * @since 1.0.0 |
| 511 | */ |
| 512 | public function display() { |
| 513 | |
| 514 | // Load Welcome screen |
| 515 | if ( $this->welcome_screen() ) return; |
| 516 | |
| 517 | $current_tab = ( empty( $_GET['tab'] ) ) ? 'general' : sanitize_text_field( urldecode( $_GET['tab'] ) ); |
| 518 | |
| 519 | // get first element from post-types |
| 520 | $post_types = array_values( $this->cpac->get_post_types() ); |
| 521 | $first = array_shift( $post_types ); |
| 522 | ?> |
| 523 | <div id="cpac" class="wrap"> |
| 524 | |
| 525 | <?php screen_icon( 'codepress-admin-columns' ); ?> |
| 526 | |
| 527 | <h2 class="nav-tab-wrapper cpac-nav-tab-wrapper"> |
| 528 | <?php |
| 529 | $tabs = array( |
| 530 | 'general' => __( 'Admin Columns', 'cpac' ), |
| 531 | 'settings' => __( 'Settings', 'cpac' ) |
| 532 | ); |
| 533 | foreach( $tabs as $name => $label ) : ?> |
| 534 | <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> |
| 535 | <?php endforeach; ?> |
| 536 | </h2> |
| 537 | |
| 538 | <?php do_action( 'cpac_messages' ); ?> |
| 539 | |
| 540 | <?php |
| 541 | switch ($current_tab) : |
| 542 | |
| 543 | case "general" : |
| 544 | ?> |
| 545 | |
| 546 | <div class="cpac-menu"> |
| 547 | <ul class="subsubsub"> |
| 548 | <?php $count = 0; ?> |
| 549 | <?php foreach ( $this->cpac->storage_models as $storage_model ) : ?> |
| 550 | <li><?php echo $count++ != 0 ? ' | ' : ''; ?><a href="#cpac-box-<?php echo $storage_model->key; ?>" <?php echo $storage_model->is_menu_type_current( $first ) ? ' class="current"' : '';?> ><?php echo $storage_model->label; ?></a></li> |
| 551 | <?php endforeach; ?> |
| 552 | </ul> |
| 553 | </div> |
| 554 | |
| 555 | <?php foreach ( $this->cpac->storage_models as $storage_model ) : ?> |
| 556 | |
| 557 | <div class="columns-container" data-type="<?php echo $storage_model->key ?>"<?php echo $storage_model->is_menu_type_current( $first ) ? '' : ' style="display:none"'; ?>> |
| 558 | <form method="post" action=""> |
| 559 | |
| 560 | <?php wp_nonce_field( 'update-type', '_cpac_nonce'); ?> |
| 561 | <input type="hidden" name="cpac_key" value="<?php echo $storage_model->key; ?>" /> |
| 562 | |
| 563 | <div class="columns-left"> |
| 564 | <div id="titlediv"> |
| 565 | <h2> |
| 566 | <?php echo $storage_model->label; ?> |
| 567 | <?php $storage_model->screen_link(); ?> |
| 568 | </h2> |
| 569 | </div> |
| 570 | </div> |
| 571 | |
| 572 | <div class="columns-right"> |
| 573 | <div class="columns-right-inside"> |
| 574 | <div class="sidebox" id="form-actions"> |
| 575 | <h3> |
| 576 | <?php _e( 'Store settings', 'cpac' ) ?> |
| 577 | </h3> |
| 578 | <?php $has_been_stored = $storage_model->get_stored_columns() ? true : false; ?> |
| 579 | <div class="form-update"> |
| 580 | <input type="hidden" name="cpac_action" value="update_by_type" /> |
| 581 | <input type="submit" class="button-primary submit-update" value="<?php echo $has_been_stored ? __( 'Update' ) : __('Publish'); ?>" accesskey="u" > |
| 582 | </div> |
| 583 | <?php if ( $has_been_stored ) : ?> |
| 584 | <div class="form-reset"> |
| 585 | <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 ); ?>');"> |
| 586 | <?php _e( 'Restore', 'cpac' ); ?> <?php echo $storage_model->label; ?> <?php _e( 'columns', 'cpac' ); ?> |
| 587 | </a> |
| 588 | </div> |
| 589 | <?php endif; ?> |
| 590 | </div><!--form-actions--> |
| 591 | |
| 592 | <?php if ( ! class_exists( 'CAC_Addon_Pro' ) ) : ?> |
| 593 | <div class="sidebox" id="pro-version"> |
| 594 | <div class="padding-box"> |
| 595 | <h3> |
| 596 | <a href="<?php echo $this->get_url('pro_addon'); ?>"><?php _e( 'Get the Pro Add-on', 'cpac' ) ?></a> |
| 597 | </h3> |
| 598 | <div class="inside"> |
| 599 | <ul> |
| 600 | <li><a href="<?php echo $this->get_url('pro_addon'); ?>"><?php _e( 'Add Sorting', 'cpac' ); ?></a></li> |
| 601 | <li><a href="<?php echo $this->get_url('pro_addon'); ?>"><?php _e( 'Add Filtering', 'cpac' ); ?></a></li> |
| 602 | <li><a href="<?php echo $this->get_url('pro_addon'); ?>"><?php _e( 'Add Import/Export', 'cpac' ); ?></a></li> |
| 603 | </ul> |
| 604 | <p> |
| 605 | <?php printf( __( 'Check the <a href="%s">Pro Add-on</a> for more details!', 'cpac' ), $this->get_url('pro_addon') ); ?> |
| 606 | </p> |
| 607 | </div> |
| 608 | </div> |
| 609 | </div> |
| 610 | <?php endif; ?> |
| 611 | |
| 612 | <div class="sidebox" id="plugin-support"> |
| 613 | <h3><?php _e( 'Support', 'cpac' ); ?></h3> |
| 614 | <div class="inside"> |
| 615 | <?php if ( version_compare( get_bloginfo( 'version' ), '3.2', '>' ) ) : ?> |
| 616 | <p><?php _e( 'Check the <strong>Help</strong> section in the top-right screen.', 'cpac' ); ?></p> |
| 617 | <?php endif; ?> |
| 618 | <p><?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') ); ?></p> |
| 619 | </div> |
| 620 | </div><!--.form-actions--> |
| 621 | |
| 622 | </div><!--.columns-right-inside--> |
| 623 | </div><!--.columns-right--> |
| 624 | |
| 625 | <div class="columns-left"> |
| 626 | <div class="cpac-boxes"> |
| 627 | <div class="cpac-columns"> |
| 628 | |
| 629 | <?php |
| 630 | foreach ( $storage_model->get_columns() as $column ) { |
| 631 | $column->display(); |
| 632 | } |
| 633 | ?> |
| 634 | |
| 635 | </div><!--.cpac-columns--> |
| 636 | |
| 637 | <div class="column-footer"> |
| 638 | <div class="order-message"><?php _e( 'Drag and drop to reorder', 'cpac' ); ?></div> |
| 639 | |
| 640 | <div class="button-container"> |
| 641 | <a href="javascript:;" class="add_column button button-primary">+ <?php _e( 'Add Column', 'cpac' );?></a><br/> |
| 642 | </div> |
| 643 | |
| 644 | </div><!--.cpac-column-footer--> |
| 645 | </div><!--.cpac-boxes--> |
| 646 | </div><!--.columns-left--> |
| 647 | <div class="clear"></div> |
| 648 | |
| 649 | </form> |
| 650 | |
| 651 | <div class="for-cloning-only" style="display:none"> |
| 652 | <?php |
| 653 | foreach ( $storage_model->get_registered_columns() as $column ) { |
| 654 | $column->display(); |
| 655 | } |
| 656 | ?> |
| 657 | </div> |
| 658 | |
| 659 | </div><!--.columns-container--> |
| 660 | |
| 661 | <?php endforeach; // storage_models ?> |
| 662 | |
| 663 | <div class="clear"></div> |
| 664 | |
| 665 | <?php |
| 666 | break; // case: general |
| 667 | |
| 668 | case 'settings' : |
| 669 | |
| 670 | $this->display_settings(); |
| 671 | break; // case: settings |
| 672 | |
| 673 | endswitch; |
| 674 | ?> |
| 675 | |
| 676 | </div><!--.wrap--> |
| 677 | <?php |
| 678 | } |
| 679 | |
| 680 | /** |
| 681 | * General Settings. |
| 682 | * |
| 683 | * @since 1.0.0 |
| 684 | */ |
| 685 | public function display_settings() { |
| 686 | ?> |
| 687 | <table class="form-table cpac-form-table"> |
| 688 | <tbody> |
| 689 | |
| 690 | <tr class="general"> |
| 691 | <th scope="row"> |
| 692 | <h3><?php _e( 'General Settings', 'cpac' ); ?></h3> |
| 693 | <p><?php _e( 'Customize your Admin Columns settings.', 'cpac' ); ?></p> |
| 694 | </th> |
| 695 | <td class="padding-22"> |
| 696 | <div class="cpac_general"> |
| 697 | <form method="post" action="options.php"> |
| 698 | <?php settings_fields( 'cpac-general-settings' ); ?> |
| 699 | <?php $options = get_option( 'cpac_general_options' ); ?> |
| 700 | <strong><?php _e( 'Custom field settings', 'cpac' ); ?></strong> |
| 701 | <p> |
| 702 | <label for="show_hidden"> |
| 703 | <input name="cpac_general_options[show_hidden]" id="show_hidden" type="checkbox" value="1" <?php checked( isset( $options['show_hidden'] ) ? $options['show_hidden'] : '', '1' ); ?>> |
| 704 | <?php _e( 'Show hidden custom fields. Default is <code>off</code>.', 'cpac' ); ?> |
| 705 | </label> |
| 706 | </p> |
| 707 | |
| 708 | <?php do_action( 'cac/settings/general', $options ); ?> |
| 709 | |
| 710 | <p> |
| 711 | <input type="submit" class="button" value="<?php _e( 'Save' ); ?>" /> |
| 712 | </p> |
| 713 | </form> |
| 714 | </div> |
| 715 | </td> |
| 716 | </tr><!--.general--> |
| 717 | |
| 718 | <?php |
| 719 | |
| 720 | /** Allow plugins to add their own custom settings to the settings page. */ |
| 721 | if ( $groups = apply_filters( 'cac/settings/groups', array() ) ) { |
| 722 | |
| 723 | foreach ( $groups as $id => $group ) { |
| 724 | |
| 725 | $title = isset( $group['title'] ) ? $group['title'] : ''; |
| 726 | $description = isset( $group['description'] ) ? $group['description'] : ''; |
| 727 | |
| 728 | ?> |
| 729 | <tr> |
| 730 | <th scope="row"> |
| 731 | <h3><?php echo $title; ?></h3> |
| 732 | <p><?php echo $description; ?></p> |
| 733 | </th> |
| 734 | <td class="padding-22"> |
| 735 | <?php |
| 736 | |
| 737 | /** Use this Hook to add additonal fields to the group */ |
| 738 | do_action( "cac/settings/groups/row={$id}" ); |
| 739 | |
| 740 | ?> |
| 741 | </td> |
| 742 | </tr> |
| 743 | <?php |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | ?> |
| 748 | |
| 749 | <tr class="restore"> |
| 750 | <th scope="row"> |
| 751 | <h3><?php _e( 'Restore Settings', 'cpac' ); ?></h3> |
| 752 | <p><?php _e( 'This will delete all column settings and restore the default settings.', 'cpac' ); ?></p> |
| 753 | </th> |
| 754 | <td class="padding-22"> |
| 755 | <form method="post" action=""> |
| 756 | <?php wp_nonce_field( 'restore-all','_cpac_nonce'); ?> |
| 757 | <input type="hidden" name="cpac_action" value="restore_all" /> |
| 758 | <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' ); ?>');" /> |
| 759 | </form> |
| 760 | </td> |
| 761 | </tr><!--.restore--> |
| 762 | |
| 763 | </tbody> |
| 764 | </table> |
| 765 | |
| 766 | <?php |
| 767 | } |
| 768 | } |