path_url = Ithemes_Updater_Functions::get_url( $GLOBALS['ithemes_updater_path'] ); list( $this->self_url ) = explode( '?', $_SERVER['REQUEST_URI'] ); $this->self_url .= '?page=' . $this->page_name; add_action( 'ithemes_updater_settings_page_index', array( $this, 'index' ) ); add_action( 'admin_print_styles', array( $this, 'add_styles' ) ); } public function add_styles() { wp_enqueue_style( 'ithemes-updater-settings-page-style', "{$this->path_url}/css/settings-page.css" ); } public function index() { $post_data = Ithemes_Updater_Functions::get_post_data( array( 'it-updater-username', 'it-updater-password', 'packages', 'action' ), true ); if ( empty( $post_data['packages'] ) ) $post_data['packages'] = array(); $action = $post_data['action']; if ( 'license_packages' == $action ) $this->license_packages( $post_data ); else if ( 'unlicense_packages' == $action ) $this->unlicense_packages( $post_data ); else if ( 'save_settings' == $action ) $this->save_settings(); $this->list_packages( $action, $post_data ); } private function save_settings() { check_admin_referer( 'save_settings', 'ithemes_updater_nonce' ); $settings_defaults = array( 'quick_releases' => false, ); $settings = array(); foreach ( $settings_defaults as $var => $val ) { if ( isset( $_POST[$var] ) ) $settings[$var] = $_POST[$var]; else $settings[$var] = $val; } if ( $settings['quick_releases'] ) $settings['quick_releases'] = true; $GLOBALS['ithemes-updater-settings']->update_options( $settings ); $GLOBALS['ithemes-updater-settings']->flush( 'settings saved' ); $this->messages[] = __( 'Settings saved', 'it-l10n-ithemes-sync' ); } private function license_packages( $data ) { check_admin_referer( 'license_packages', 'ithemes_updater_nonce' ); if ( empty( $data['username'] ) && empty( $data['password'] ) ) $this->errors[] = __( 'You must supply an iThemes membership username and password in order to license products.', 'it-l10n-ithemes-sync' ); else if ( empty( $data['username'] ) ) $this->errors[] = __( 'You must supply an iThemes membership username in order to license products.', 'it-l10n-ithemes-sync' ); else if ( empty( $data['password'] ) ) $this->errors[] = __( 'You must supply an iThemes membership password in order to license products.', 'it-l10n-ithemes-sync' ); else if ( empty( $data['packages'] ) ) $this->errors[] = __( 'You must select at least one product to license. Ensure that you select the products that you wish to license in the listing below.', 'it-l10n-ithemes-sync' ); if ( ! empty( $this->errors ) ) return; $response = Ithemes_Updater_API::activate_package( $data['username'], $data['password'], $data['packages'] ); if ( is_wp_error( $response ) ) { $this->errors[] = Ithemes_Updater_API::get_error_explanation( $response ); return; } if ( empty( $response['packages'] ) ) { $this->errors[] = __( 'An unknown server error occurred. Please try to license your products again at another time.', 'it-l10n-ithemes-sync' ); return; } uksort( $response['packages'], 'strnatcasecmp' ); $success = array(); $warn = array(); $fail = array(); foreach ( $response['packages'] as $package => $data ) { if ( preg_match( '/ \|\|\| \d+$/', $package ) ) continue; $name = Ithemes_Updater_Functions::get_package_name( $package ); if ( ! empty( $data['key'] ) ) $success[] = $name; else if ( ! empty( $data['status'] ) && ( 'expired' == $data['status'] ) ) $warn[$name] = __( 'Your product subscription has expired', 'it-l10n-ithemes-sync' ); else $fail[$name] = $data['error']['message']; } if ( ! empty( $success ) ) $this->messages[] = wp_sprintf( __( 'Successfully licensed %l.', 'it-l10n-ithemes-sync' ), $success ); if ( ! empty( $fail ) ) { foreach ( $fail as $name => $reason ) $this->errors[] = sprintf( __( 'Unable to license %1$s. Reason: %2$s', 'it-l10n-ithemes-sync' ), $name, $reason ); } if ( ! empty( $warn ) ) { foreach ( $warn as $name => $reason ) $this->soft_errors[] = sprintf( __( 'Unable to license %1$s. Reason: %2$s', 'it-l10n-ithemes-sync' ), $name, $reason ); } } private function unlicense_packages( $data ) { check_admin_referer( 'unlicense_packages', 'ithemes_updater_nonce' ); if ( empty( $data['username'] ) && empty( $data['password'] ) ) $this->errors[] = __( 'You must supply an iThemes membership username and password in order to remove licenses.', 'it-l10n-ithemes-sync' ); else if ( empty( $data['username'] ) ) $this->errors[] = __( 'You must supply an iThemes membership username in order to remove licenses.', 'it-l10n-ithemes-sync' ); else if ( empty( $data['password'] ) ) $this->errors[] = __( 'You must supply an iThemes membership password in order to remove licenses.', 'it-l10n-ithemes-sync' ); else if ( empty( $data['packages'] ) ) $this->errors[] = __( 'You must select at least one license to remove. Ensure that you select the licenses that you wish to remove in the listing below.', 'it-l10n-ithemes-sync' ); if ( ! empty( $this->errors ) ) return; $response = Ithemes_Updater_API::deactivate_package( $data['username'], $data['password'], $data['packages'] ); if ( is_wp_error( $response ) ) { $this->errors[] = Ithemes_Updater_API::get_error_explanation( $response ); return; } if ( empty( $response['packages'] ) ) { $this->errors[] = __( 'An unknown server error occurred. Please try to remove licenses from your products again at another time.', 'it-l10n-ithemes-sync' ); return; } uksort( $response['packages'], 'strnatcasecmp' ); $success = array(); $fail = array(); foreach ( $response['packages'] as $package => $data ) { if ( preg_match( '/ \|\|\| \d+$/', $package ) ) continue; $name = Ithemes_Updater_Functions::get_package_name( $package ); if ( isset( $data['status'] ) && ( 'inactive' == $data['status'] ) ) $success[] = $name; else if ( isset( $data['error'] ) && isset( $data['error']['message'] ) ) $fail[$name] = $data['error']['message']; else $fail[$name] = __( 'Unknown server error.', 'it-l10n-ithemes-sync' ); } if ( ! empty( $success ) ) $this->messages[] = wp_sprintf( _n( 'Successfully removed license from %l.', 'Successfully removed licenses from %l.', count( $success ), 'it-l10n-ithemes-sync' ), $success ); if ( ! empty( $fail ) ) { foreach ( $fail as $name => $reason ) $this->errors[] = sprintf( __( 'Unable to remove license from %1$s. Reason: %2$s', 'it-l10n-ithemes-sync' ), $name, $reason ); } } public function list_packages( $action, $post_data ) { require_once( $GLOBALS['ithemes_updater_path'] . '/packages.php' ); $details = Ithemes_Updater_Packages::get_full_details(); $packages = $details['packages']; $licensed = array(); $unlicensed = array(); $unrecognized = array(); foreach ( $packages as $path => $data ) { $name = Ithemes_Updater_Functions::get_package_name( $data['package'] ); $data['path'] = $path; if ( 'unlicensed' == $data['status'] ) $unlicensed[$name] = $data; else if ( in_array( $data['status'], array( 'active', 'expired' ) ) ) $licensed[$name] = $data; else $unrecognized[$name] = $data; } if ( ! empty( $this->messages ) ) { foreach ( $this->messages as $message ) echo "

$message

\n"; } if ( ! empty( $this->errors ) ) { foreach ( $this->errors as $error ) echo "

$error

\n"; } if ( ! empty( $this->soft_errors ) ) { foreach ( $this->soft_errors as $error ) echo "

$error

\n"; } ?>

list_licensed_products( $licensed, $post_data, $action ); ?> list_unlicensed_products( $unlicensed, $post_data, $action ); ?> list_unrecognized_products( $unrecognized ); ?> show_settings(); ?>
get_option( 'quick_releases' ); ?>

errors ) ) { $post_data = array( 'username' => '', 'password' => '', 'packages' => array(), ); } ?>

$data ) : ?> ' . __( 'Upgrade', 'it-l10n-ithemes-sync' ) . ''; $expiration = $this->get_expiration_string( $data['expiration'] ); $expiration = ''; $time_left = $data['expiration'] - $time; $class = 'expiring'; if ( $time_left > ( 86400 * 30 ) ) $class = 'active'; else if ( $time_left <= 0 ) $class = 'expired'; if ( 'expired' == $data['status'] ) { $class = 'expired'; $remaining = ' '; } $status = ucfirst( $class ); if ( ++$count % 2 ) { $class .= ' alt'; } $check_id = "cb-select-{$data['package']}"; $checked = ( in_array( $data['package'], $post_data['packages'] ) ) ? ' checked' : ''; ?>
errors ) ) { $post_data = array( 'username' => '', 'password' => '', 'packages' => array(), ); foreach ( $products as $name => $data ) $post_data['packages'][] = $data['package']; } ?>

Click here for a quick video tutorial.', 'it-l10n-ithemes-sync' ), 'http://ithemes.com/2013/04/11/introducing-the-new-and-improved-ithemes-licensing-system/' ); ?>

$data ) : ?>

iThemes support and provide them with the details given below.', 'it-l10n-ithemes-sync' ), 'http://ithemes.com/support/' ); ?>

$data ) : ?>
( 86400 * 30 ) ) $expiration = date( 'Y-m-d', $expiration_timestamp ); else { if ( $time_left > 86400 ) $expiration = sprintf( _n( '%d day', '%d days', intval( $time_left / 86400 ), 'it-l10n-ithemes-sync' ), intval( $time_left / 86400 ) ); else if ( $time_left > 3600 ) $expiration = sprintf( _n( '%d hour', '%d hours', intval( $time_left / 3600 ), 'it-l10n-ithemes-sync' ), intval( $time_left / 3600 ) ); else if ( $time_left > 60 ) $expiration = sprintf( _n( '%d minute', '%d minutes', intval( $time_left / 60 ), 'it-l10n-ithemes-sync' ), intval( $time_left / 60 ) ); else $expiration = sprintf( _n( '%d second', '%d seconds', $time_left, 'it-l10n-ithemes-sync' ), intval( $time_left / 60 ) ); if ( $expired ) $expiration = sprintf( __( '%s ago', 'it-l10n-ithemes-sync' ), $expiration ); } return $expiration; } } new Ithemes_Updater_Settings_Page();