options = get_option( 'amber_options' ); ?>

Amber Settings

options['amber_enable_netclerk']) && $this->options['amber_enable_netclerk']) { add_settings_field( 'amber_external_availability', 'Use a third-party database to check site availability', array( $this, 'amber_external_availability_callback' ), 'amber-settings-admin', 'amber_services_section' ); add_settings_field( 'amber_report_availability', 'Inform a third-party database of site availability', array( $this, 'amber_report_availability_callback' ), 'amber-settings-admin', 'amber_services_section' ); } add_settings_field( 'amber_timegate', 'Check a TimeGate server for additional snapshots', array( $this, 'amber_timegate_callback' ), 'amber-settings-admin', 'amber_services_section' ); register_setting( 'amber_option_group', // Option group 'amber_options', // Option name array( $this, 'sanitize' ) // Sanitize ); Amber::disk_space_purge(); } /** * Sanitize each setting field as needed * * @param array $input Contains all settings fields as array keys */ public function sanitize( $input ) { $new_input = array(); $valid_integer_options = array( 'amber_backend', 'amber_max_file', 'amber_max_disk', 'amber_available_action', 'amber_unavailable_action', 'amber_available_action_hover', 'amber_unavailable_action_hover', 'amber_country_available_action', 'amber_country_unavailable_action', 'amber_country_available_action_hover', 'amber_country_unavailable_action_hover', 'amber_update_strategy', 'amber_external_availability', 'amber_report_availability', ); foreach ($valid_integer_options as $opt) { if( isset( $input[$opt] ) ) $new_input[$opt] = absint( $input[$opt] ); } $valid_string_options = array( 'amber_storage_location', 'amber_excluded_formats', 'amber_timegate', 'amber_country_id', 'amber_perma_api_key', 'amber_perma_server_url', 'amber_perma_api_server_url', 'amber_aws_access_key', 'amber_aws_secret_key', 'amber_aws_bucket', 'amber_aws_region', ); foreach ($valid_string_options as $opt) { if( isset( $input[$opt] ) ) $new_input[$opt] = sanitize_text_field( $input[$opt] ); } if (isset($input['amber_alternate_backends'])) { foreach ($input['amber_alternate_backends'] as $key => $value) { $new_input['amber_alternate_backends'][$key] = sanitize_text_field($value); } } /* Process selected post types */ $crawled_post_types = $input['amber_post_types']; $stringified_post_types = implode(',', $crawled_post_types); $new_input['amber_post_types'] = $stringified_post_types; /* Validate excluded sites regular expressions */ $excluded_sites = explode( ',' , $input['amber_excluded_sites'] ); $sanitized_excluded_sites = array(); foreach ($excluded_sites as $site) { $blacklistitem = preg_replace("/https?:\\/\\//i", "", trim($site)); if ($blacklistitem) { $blacklistitem = str_replace("@", "\@", $blacklistitem); $blacklistitem = '@' . $blacklistitem . '@'; /* Hide warning messages from preg_match() that can be generated by invalid user-entered regular expressions. */ $default_error_logging_level = error_reporting(); error_reporting(0); $match_result = preg_match($blacklistitem, "foobar"); error_reporting($default_error_logging_level); if ($match_result === FALSE) { add_settings_error('amber_excluded_sites', 'amber_excluded_sites', "'${site}' is not a valid regular expression for Excluded URL Patterns"); } else { $sanitized_excluded_sites[] = $site; } } } $new_input['amber_excluded_sites'] = sanitize_text_field( implode( ",", $sanitized_excluded_sites ) ); /* Validate backend settings */ if (($input['amber_backend'] == AMBER_BACKEND_PERMA) || (isset($input['amber_alternate_backends']) && in_array(AMBER_BACKEND_PERMA, $input['amber_alternate_backends']))) { foreach (array('amber_perma_api_key', 'amber_perma_server_url', 'amber_perma_api_server_url') as $key) if (empty($input[$key]) ) { add_settings_error($key, $key, "API key is required for Perma storage"); break; } } if (($input['amber_backend'] == AMBER_BACKEND_AMAZON_S3) || (isset($input['amber_alternate_backends']) && in_array(AMBER_BACKEND_AMAZON_S3, $input['amber_alternate_backends']))) { foreach (array('amber_aws_access_key', 'amber_aws_secret_key', 'amber_aws_bucket', 'amber_aws_region') as $key) if (empty($input[$key]) ) { add_settings_error($key, $key, "AWS Access Key, Secret Key, Bucket, and Region are required for Amazon S3 storage"); break; } /* Attempt to connect to AWS with provided credentials */ try { require_once("vendor/aws/aws-autoloader.php"); $storage = new AmazonS3Storage(array( 'access_key' => $input['amber_aws_access_key'], 'secret_key' => $input['amber_aws_secret_key'], 'bucket' => $input['amber_aws_bucket'], 'region' => $input['amber_aws_region'], )); } catch (Exception $e) { add_settings_error('amber_backend', 'amber_backend', "There is a problem with the provided Amazon configuration. Check that the access key and secret key are correct, and that they provide write access to the selected bucket. Ensure that your bucket name is unique - it cannot have the same name as any other bucket in S3."); } } return $new_input; } /** * Print the Section text */ public function print_cache_section_info() { print 'Control how Amber stores snapshots'; } /* As well as printing the section text for the delivery info, add some javscript to show and hide fields as appropriate. */ public function print_delivery_section_info() { print ' Settings that control the user experience '; } public function print_services_section_info() { print 'Connect to academic efforts to retrieve more accurate data and additional snapshots'; } /** * Get the settings option array and print one of its values */ public function amber_backend_callback() { $option = isset($this->options['amber_backend']) ? $this->options['amber_backend'] : 0; ?>

Amber can store snapshots locally, in your website's storage space. If you prefer, you can store snapshots in an alternative backend. At this time, Amber is compatible with the following services: Perma.cc, the Internet Archive, and Amazon S3.

options['amber_alternate_backends']) ? $this->options['amber_alternate_backends'] : 0; ?>

Preserve snapshots in multiple storage locations by selecting one or more alternates above. Amber will show your visitors only the storage location selected in the dropdown menu.

options['amber_post_types']) ? $this->options['amber_post_types'] : "post,page"; $all_post_types = get_post_types( array(), 'objects', 'and' ); $crawled_post_types = explode( ',', $options ); $ignored_post_types = array( 'revision', 'attachment', 'nav_menu_item'); printf('

Preserve snapshots from particular post types, including custom post types.

'); } public function amber_max_file_callback() { printf( ' ' . '

Amber will store snapshots up to a specified size. Links to pages that exceed this size will not be preserved.

', isset( $this->options['amber_max_file'] ) ? esc_attr( $this->options['amber_max_file']) : '' ); } public function amber_max_disk_callback() { printf( '' . '

The maximum amount of disk space to be used for all preserved content. If this disk space usage is exceeded, old snapshots will be removed.

', isset( $this->options['amber_max_disk'] ) ? esc_attr( $this->options['amber_max_disk']) : '' ); } public function amber_storage_location_callback() { printf( '' . '

Path to the location where snapshots are stored on disk, relative to the uploads directory.

', isset( $this->options['amber_storage_location'] ) ? esc_attr( $this->options['amber_storage_location']) : '' ); } public function amber_update_strategy_callback() { $option = $this->options['amber_update_strategy']; ?>

Select "Do not update" if you want to preserve links at the time the content is published. Otherwise, link storage will be periodically updated.

%s' . '

A list of URL patterns, separated by commas. Amber will not preserve any link that matches one of these patterns. Regular expressions may be used.

', isset( $this->options['amber_excluded_sites'] ) ? esc_textarea( $this->options['amber_excluded_sites']) : '' ); } public function amber_excluded_formats_callback() { printf( '' . '

A list of of MIME types, separated by commas. Amber will not preserve any link containing an excluded MIME type.

', isset( $this->options['amber_excluded_formats'] ) ? esc_textarea( $this->options['amber_excluded_formats']) : '' ); } public function amber_perma_api_key_callback() { printf( '' . '

Generate an API key in your Perma.cc Dashboard under Settings > Tools

', isset( $this->options['amber_perma_api_key'] ) ? esc_attr( $this->options['amber_perma_api_key']) : '' ); } public function amber_perma_server_url_callback() { printf( '' . '

This should not need to be changed

', isset( $this->options['amber_perma_server_url'] ) ? esc_attr( $this->options['amber_perma_server_url']) : '' ); } public function amber_perma_api_server_url_callback() { printf( '' . '

This should not need to be changed

', isset( $this->options['amber_perma_api_server_url'] ) ? esc_attr( $this->options['amber_perma_api_server_url']) : '' ); } public function amber_aws_access_key_callback() { printf( '' . '

Visit Managing Access Keys for your AWS Account for instructions to generate an access key.

', isset( $this->options['amber_aws_access_key'] ) ? esc_attr( $this->options['amber_aws_access_key']) : '' ); } public function amber_aws_secret_key_callback() { printf( '' . '

Visit Managing Access Keys for your AWS Account for instructions to generate a secret access key.

', isset( $this->options['amber_aws_secret_key'] ) ? esc_attr( $this->options['amber_aws_secret_key']) : '' ); } public function amber_aws_bucket_callback() { printf( '' . '

Name of the Bucket where snapshots will be stored

', isset( $this->options['amber_aws_bucket'] ) ? esc_attr( $this->options['amber_aws_bucket']) : '' ); } public function amber_aws_region_callback() { printf( '' . '

Your snapshots will be stored in this S3 region. Unless you are an advanced user, do not modify this setting.

', isset( $this->options['amber_aws_region'] ) ? esc_attr( $this->options['amber_aws_region']) : '' ); } public function amber_available_action_callback() { $option = isset($this->options['amber_available_action']) ? $this->options['amber_available_action'] : AMBER_ACTION_NONE; ?>

How a visitor to your site will experience links to pages that are currently available.

options['amber_unavailable_action']) ? $this->options['amber_unavailable_action'] : AMBER_ACTION_NONE; ?>

How a visitor to your site will experience links to pages that are currently unavailable.

' . '

Delay before "Site Available" notification appears to a visitor on your site.

', isset( $this->options['amber_available_action_hover'] ) ? esc_attr( $this->options['amber_available_action_hover']) : '' ); } public function amber_unavailable_action_hover_callback() { printf( '' . '

Delay before "Site Unavailable" notification appears to a visitor on your site.

', isset( $this->options['amber_unavailable_action_hover'] ) ? esc_attr( $this->options['amber_unavailable_action_hover']) : '' ); } public function amber_external_availability_callback() { $option = isset($this->options['amber_external_availability']) ? $this->options['amber_external_availability'] : AMBER_EXTERNAL_AVAILABILITY_NONE; ?>

Optional: Use site accessibility data from the Berkman Center for Internet & Society at Harvard University

options['amber_report_availability']) ? $this->options['amber_report_availability'] : AMBER_REPORT_AVAILABILITY_NONE; ?>

Optional: Contribute site accessibility data for research as part of the Berkman Center for Internet & Society at Harvard University

' . '

Optional: Request additional snapshots from the Internet Archive, the Library of Congress web archive, archive.today, and more.

', isset( $this->options['amber_timegate'] ) ? esc_attr( $this->options['amber_timegate']) : '' ); } public function amber_country_id_callback() { $option = isset($this->options['amber_country_id']) ? $this->options['amber_country_id'] : ""; ?>

Visitors to your website with browser IP addresses originating in this country will experience specified behavior.

options['amber_country_available_action']) ? $this->options['amber_country_available_action'] : AMBER_ACTION_NONE; ?>

How a visitor to your site will experience links to pages that are currently available.

options['amber_country_unavailable_action']) ? $this->options['amber_country_unavailable_action'] : AMBER_ACTION_NONE; ?>

How a visitor to your site will experience links to pages that are currently unavailable.

' . '

Delay before "Site Available" notification appears to a visitor on your site.

', isset( $this->options['amber_country_available_action_hover'] ) ? esc_attr( $this->options['amber_country_available_action_hover']) : '' ); } public function amber_country_unavailable_action_hover_callback() { printf( '' . '

Delay before "Site Unavailable" notification appears to a visitor on your site.

', isset( $this->options['amber_country_unavailable_action_hover'] ) ? esc_attr( $this->options['amber_country_unavailable_action_hover']) : '' ); } private function get_countries() { $countries = array( 'AD' => 'Andorra', 'AE' => 'United Arab Emirates', 'AF' => 'Afghanistan', 'AG' => 'Antigua and Barbuda', 'AI' => 'Anguilla', 'AL' => 'Albania', 'AM' => 'Armenia', 'AN' => 'Netherlands Antilles', 'AO' => 'Angola', 'AQ' => 'Antarctica', 'AR' => 'Argentina', 'AS' => 'American Samoa', 'AT' => 'Austria', 'AU' => 'Australia', 'AW' => 'Aruba', 'AX' => 'Aland Islands', 'AZ' => 'Azerbaijan', 'BA' => 'Bosnia and Herzegovina', 'BB' => 'Barbados', 'BD' => 'Bangladesh', 'BE' => 'Belgium', 'BF' => 'Burkina Faso', 'BG' => 'Bulgaria', 'BH' => 'Bahrain', 'BI' => 'Burundi', 'BJ' => 'Benin', 'BL' => 'Saint Barthélemy', 'BM' => 'Bermuda', 'BN' => 'Brunei', 'BO' => 'Bolivia', 'BR' => 'Brazil', 'BS' => 'Bahamas', 'BT' => 'Bhutan', 'BV' => 'Bouvet Island', 'BW' => 'Botswana', 'BY' => 'Belarus', 'BZ' => 'Belize', 'CA' => 'Canada', 'CC' => 'Cocos (Keeling) Islands', 'CD' => 'Congo (Kinshasa)', 'CF' => 'Central African Republic', 'CG' => 'Congo (Brazzaville)', 'CH' => 'Switzerland', 'CI' => 'Ivory Coast', 'CK' => 'Cook Islands', 'CL' => 'Chile', 'CM' => 'Cameroon', 'CN' => 'China', 'CO' => 'Colombia', 'CR' => 'Costa Rica', 'CU' => 'Cuba', 'CW' => 'Curaçao', 'CV' => 'Cape Verde', 'CX' => 'Christmas Island', 'CY' => 'Cyprus', 'CZ' => 'Czech Republic', 'DE' => 'Germany', 'DJ' => 'Djibouti', 'DK' => 'Denmark', 'DM' => 'Dominica', 'DO' => 'Dominican Republic', 'DZ' => 'Algeria', 'EC' => 'Ecuador', 'EE' => 'Estonia', 'EG' => 'Egypt', 'EH' => 'Western Sahara', 'ER' => 'Eritrea', 'ES' => 'Spain', 'ET' => 'Ethiopia', 'FI' => 'Finland', 'FJ' => 'Fiji', 'FK' => 'Falkland Islands', 'FM' => 'Micronesia', 'FO' => 'Faroe Islands', 'FR' => 'France', 'GA' => 'Gabon', 'GB' => 'United Kingdom', 'GD' => 'Grenada', 'GE' => 'Georgia', 'GF' => 'French Guiana', 'GG' => 'Guernsey', 'GH' => 'Ghana', 'GI' => 'Gibraltar', 'GL' => 'Greenland', 'GM' => 'Gambia', 'GN' => 'Guinea', 'GP' => 'Guadeloupe', 'GQ' => 'Equatorial Guinea', 'GR' => 'Greece', 'GS' => 'South Georgia and the South Sandwich Islands', 'GT' => 'Guatemala', 'GU' => 'Guam', 'GW' => 'Guinea-Bissau', 'GY' => 'Guyana', 'HK' => 'Hong Kong S.A.R., China', 'HM' => 'Heard Island and McDonald Islands', 'HN' => 'Honduras', 'HR' => 'Croatia', 'HT' => 'Haiti', 'HU' => 'Hungary', 'ID' => 'Indonesia', 'IE' => 'Ireland', 'IL' => 'Israel', 'IM' => 'Isle of Man', 'IN' => 'India', 'IO' => 'British Indian Ocean Territory', 'IQ' => 'Iraq', 'IR' => 'Iran', 'IS' => 'Iceland', 'IT' => 'Italy', 'JE' => 'Jersey', 'JM' => 'Jamaica', 'JO' => 'Jordan', 'JP' => 'Japan', 'KE' => 'Kenya', 'KG' => 'Kyrgyzstan', 'KH' => 'Cambodia', 'KI' => 'Kiribati', 'KM' => 'Comoros', 'KN' => 'Saint Kitts and Nevis', 'KP' => 'North Korea', 'KR' => 'South Korea', 'KW' => 'Kuwait', 'KY' => 'Cayman Islands', 'KZ' => 'Kazakhstan', 'LA' => 'Laos', 'LB' => 'Lebanon', 'LC' => 'Saint Lucia', 'LI' => 'Liechtenstein', 'LK' => 'Sri Lanka', 'LR' => 'Liberia', 'LS' => 'Lesotho', 'LT' => 'Lithuania', 'LU' => 'Luxembourg', 'LV' => 'Latvia', 'LY' => 'Libya', 'MA' => 'Morocco', 'MC' => 'Monaco', 'MD' => 'Moldova', 'ME' => 'Montenegro', 'MF' => 'Saint Martin (French part)', 'MG' => 'Madagascar', 'MH' => 'Marshall Islands', 'MK' => 'Macedonia', 'ML' => 'Mali', 'MM' => 'Myanmar', 'MN' => 'Mongolia', 'MO' => 'Macao S.A.R., China', 'MP' => 'Northern Mariana Islands', 'MQ' => 'Martinique', 'MR' => 'Mauritania', 'MS' => 'Montserrat', 'MT' => 'Malta', 'MU' => 'Mauritius', 'MV' => 'Maldives', 'MW' => 'Malawi', 'MX' => 'Mexico', 'MY' => 'Malaysia', 'MZ' => 'Mozambique', 'NA' => 'Namibia', 'NC' => 'New Caledonia', 'NE' => 'Niger', 'NF' => 'Norfolk Island', 'NG' => 'Nigeria', 'NI' => 'Nicaragua', 'NL' => 'Netherlands', 'NO' => 'Norway', 'NP' => 'Nepal', 'NR' => 'Nauru', 'NU' => 'Niue', 'NZ' => 'New Zealand', 'OM' => 'Oman', 'PA' => 'Panama', 'PE' => 'Peru', 'PF' => 'French Polynesia', 'PG' => 'Papua New Guinea', 'PH' => 'Philippines', 'PK' => 'Pakistan', 'PL' => 'Poland', 'PM' => 'Saint Pierre and Miquelon', 'PN' => 'Pitcairn', 'PR' => 'Puerto Rico', 'PS' => 'Palestinian Territory', 'PT' => 'Portugal', 'PW' => 'Palau', 'PY' => 'Paraguay', 'QA' => 'Qatar', 'RE' => 'Reunion', 'RO' => 'Romania', 'RS' => 'Serbia', 'RU' => 'Russia', 'RW' => 'Rwanda', 'SA' => 'Saudi Arabia', 'SB' => 'Solomon Islands', 'SC' => 'Seychelles', 'SD' => 'Sudan', 'SE' => 'Sweden', 'SG' => 'Singapore', 'SH' => 'Saint Helena', 'SI' => 'Slovenia', 'SJ' => 'Svalbard and Jan Mayen', 'SK' => 'Slovakia', 'SL' => 'Sierra Leone', 'SM' => 'San Marino', 'SN' => 'Senegal', 'SO' => 'Somalia', 'SR' => 'Suriname', 'ST' => 'Sao Tome and Principe', 'SV' => 'El Salvador', 'SY' => 'Syria', 'SZ' => 'Swaziland', 'TC' => 'Turks and Caicos Islands', 'TD' => 'Chad', 'TF' => 'French Southern Territories', 'TG' => 'Togo', 'TH' => 'Thailand', 'TJ' => 'Tajikistan', 'TK' => 'Tokelau', 'TL' => 'Timor-Leste', 'TM' => 'Turkmenistan', 'TN' => 'Tunisia', 'TO' => 'Tonga', 'TR' => 'Turkey', 'TT' => 'Trinidad and Tobago', 'TV' => 'Tuvalu', 'TW' => 'Taiwan', 'TZ' => 'Tanzania', 'UA' => 'Ukraine', 'UG' => 'Uganda', 'UM' => 'United States Minor Outlying Islands', 'US' => 'United States', 'UY' => 'Uruguay', 'UZ' => 'Uzbekistan', 'VA' => 'Vatican', 'VC' => 'Saint Vincent and the Grenadines', 'VE' => 'Venezuela', 'VG' => 'British Virgin Islands', 'VI' => 'U.S. Virgin Islands', 'VN' => 'Vietnam', 'VU' => 'Vanuatu', 'WF' => 'Wallis and Futuna', 'WS' => 'Samoa', 'YE' => 'Yemen', 'YT' => 'Mayotte', 'ZA' => 'South Africa', 'ZM' => 'Zambia', 'ZW' => 'Zimbabwe', ); natcasesort($countries); return $countries; } } include_once dirname( __FILE__ ) . '/amber.php'; if( is_admin() ) $my_settings_page = new AmberSettingsPage();