diff options
author | Jorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto@gentoo.org> | 2015-05-01 00:40:49 +0000 |
---|---|---|
committer | Jorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto@gentoo.org> | 2015-05-01 00:40:49 +0000 |
commit | c64ce3ae8de09092f9570ab88a68fe920b0fd970 (patch) | |
tree | a9959002055a8bdff0ee46bf82ca6a2a39bf00cd /plugins/jetpack/_inc/lib/admin-pages | |
parent | Add easy-table plugin, requested by hwoarang (diff) | |
download | blogs-gentoo-c64ce3ae8de09092f9570ab88a68fe920b0fd970.tar.gz blogs-gentoo-c64ce3ae8de09092f9570ab88a68fe920b0fd970.tar.bz2 blogs-gentoo-c64ce3ae8de09092f9570ab88a68fe920b0fd970.zip |
Update plugins and themes to the latest versions.
Signed-off-by: Jorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto@gentoo.org>
Diffstat (limited to 'plugins/jetpack/_inc/lib/admin-pages')
3 files changed, 468 insertions, 0 deletions
diff --git a/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-admin-page.php b/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-admin-page.php new file mode 100644 index 00000000..f072891b --- /dev/null +++ b/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-admin-page.php @@ -0,0 +1,109 @@ +<?php + +// Shared logic between Jetpack admin pages +abstract class Jetpack_Admin_Page { + // Add page specific actions given the page hook + abstract function add_page_actions( $hook ); + + // Create a menu item for the page and returns the hook + abstract function get_page_hook(); + + // Enqueue and localize page specific scripts + abstract function page_admin_scripts(); + + // Render page specific HTML + abstract function page_render(); + + function __construct() { + $this->jetpack = Jetpack::init(); + } + + function add_actions() { + /** + * Don't add in the modules page unless modules are available! + */ + if ( $this->dont_show_if_not_active && ! Jetpack::is_active() && ! Jetpack::is_development_mode() ) { + return; + } + + // Initialize menu item for the page in the admin + $hook = $this->get_page_hook(); + + // Attach hooks common to all Jetpack admin pages based on the created + // hook + add_action( "load-$hook", array( $this, 'admin_help' ) ); + add_action( "load-$hook", array( $this, 'admin_page_load' ) ); + add_action( "admin_head-$hook", array( $this, 'admin_head' ) ); + + add_action( "admin_footer-$hook", array( $this, 'module_modal_js_template' ) ); + + add_action( "admin_print_styles-$hook", array( $this, 'admin_styles' ) ); + add_action( "admin_print_scripts-$hook", array( $this, 'admin_scripts' ) ); + + // Attach page specific actions in addition to the above + $this->add_page_actions( $hook ); + } + + function admin_head() { + if ( isset( $_GET['configure'] ) && Jetpack::is_module( $_GET['configure'] ) && current_user_can( 'manage_options' ) ) { + /** + * Fires in the <head> of a particular Jetpack configuation page. + * + * The dynamic portion of the hook name, `$_GET['configure']`, + * refers to the slug of module, such as 'stats', 'sso', etc. + * A complete hook for the latter would be + * 'jetpack_module_configuation_head_sso'. + * + * @since 3.0.0 + */ + do_action( 'jetpack_module_configuration_head_' . $_GET['configure'] ); + } + } + + // Render the page with a common top and bottom part, and page specific + // content + function render() { + $this->admin_page_top(); + $this->page_render(); + $this->admin_page_bottom(); + } + + function admin_help() { + $this->jetpack->admin_help(); + } + + function admin_page_load() { + // This is big. For the moment, just call the existing one. + $this->jetpack->admin_page_load(); + } + + // Load underscore template for the landing page and settings page modal + function module_modal_js_template() { + Jetpack::init()->load_view( 'admin/module-modal-template.php' ); + } + + function admin_page_top() { + include_once( JETPACK__PLUGIN_DIR . '_inc/header.php' ); + } + + function admin_page_bottom() { + include_once( JETPACK__PLUGIN_DIR . '_inc/footer.php' ); + } + + // Add page specific scripts and jetpack stats for all menu pages + function admin_scripts() { + $this->page_admin_scripts(); // Delegate to inheriting class + add_action( 'admin_footer', array( $this->jetpack, 'do_stats' ) ); + } + + // Enqueue the Jetpack admin stylesheet + function admin_styles() { + $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; + + wp_enqueue_style( 'jetpack-google-fonts', '//fonts.googleapis.com/css?family=Open+Sans:400italic,400,700,600,800' ); + + wp_enqueue_style( 'jetpack-admin', plugins_url( "css/jetpack-admin{$min}.css", JETPACK__PLUGIN_FILE ), array( 'genericons' ), JETPACK__VERSION . '-20121016' ); + wp_style_add_data( 'jetpack-admin', 'rtl', 'replace' ); + wp_style_add_data( 'jetpack-admin', 'suffix', $min ); + } +} diff --git a/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-landing-page.php b/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-landing-page.php new file mode 100644 index 00000000..ff54b29d --- /dev/null +++ b/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-landing-page.php @@ -0,0 +1,272 @@ +<?php +include_once( 'class.jetpack-admin-page.php' ); + +// Builds the landing page and its menu +class Jetpack_Landing_Page extends Jetpack_Admin_Page { + protected $dont_show_if_not_active = false; + + function get_page_hook() { + $title = _x( 'Jetpack', 'The menu item label', 'jetpack' ); + + list( $jetpack_version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); + if ( + $jetpack_version + && + $jetpack_version != JETPACK__VERSION + && + ( $new_modules = Jetpack::get_default_modules( $jetpack_version, JETPACK__VERSION ) ) + && + is_array( $new_modules ) + && + ( $new_modules_count = count( $new_modules ) ) + && + ( Jetpack::is_active() || Jetpack::is_development_mode() ) + ) { + $new_count_i18n = number_format_i18n( $new_modules_count ); + $span_title = esc_attr( sprintf( _n( 'One New Jetpack Module', '%s New Jetpack Modules', $new_modules_count, 'jetpack' ), $new_count_i18n ) ); + $format = _x( 'Jetpack %s', 'The menu item label with a new module count as %s', 'jetpack' ); + $update_markup = "<span class='update-plugins count-{$new_modules_count}' title='$span_title'><span class='update-count'>$new_count_i18n</span></span>"; + $title = sprintf( $format, $update_markup ); + } + + // Add the main admin Jetpack menu with possible information about new + // modules + add_menu_page( 'Jetpack', $title, 'jetpack_admin_page', 'jetpack', array( $this, 'render' ), 'div' ); + // also create the submenu + return add_submenu_page( 'jetpack', $title, $title, 'jetpack_admin_page', 'jetpack' ); + } + + function add_page_actions( $hook ) { + // Add landing page specific underscore templates + add_action( "admin_footer-$hook", array( $this, 'js_templates' ) ); + /** This action is documented in class.jetpack.php */ + do_action( 'jetpack_admin_menu', $hook ); + + // Place the Jetpack menu item on top and others in the order they + // appear + add_filter( 'custom_menu_order', '__return_true' ); + add_filter( 'menu_order', array( $this, 'jetpack_menu_order' ) ); + + add_action( 'jetpack_notices_update_settings', array( $this, 'show_notices_update_settings' ), 10, 1 ); + } + + /* + * Build an array of a specific module tag. + * + * @param string Name of the module tag + * @return array The module slug, config url, and name of each Jump Start module + */ + function jumpstart_module_tag( $tag ) { + $modules = Jetpack_Admin::init()->get_modules(); + + $module_info = array(); + foreach ( $modules as $module => $value ) { + if ( in_array( $tag, $value['feature'] ) ) { + $module_info[] = array( + 'module_slug' => $value['module'], + 'module_name' => $value['name'], + 'configure_url' => $value['configure_url'], + ); + } + } + return $module_info; + } + + /* + * Only show Jump Start on first activation. + * Any option 'jumpstart' other than 'new connection' will hide it. + * + * The option can be of 4 things, and will be stored as such: + * new_connection : Brand new connection - Show + * jumpstart_activated : Jump Start has been activated - dismiss + * jetpack_action_taken: Manual activation of a module already happened - dismiss + * jumpstart_dismissed : Manual dismissal of Jump Start - dismiss + * + * @return bool | show or hide + */ + function jetpack_show_jumpstart() { + $jumpstart_option = Jetpack_Options::get_option( 'jumpstart' ); + + $hide_options = array( + 'jumpstart_activated', + 'jetpack_action_taken', + 'jumpstart_dismissed' + ); + + if ( ! $jumpstart_option || in_array( $jumpstart_option, $hide_options ) ) { + return false; + } + + return true; + } + + /* + * List of recommended modules for the Jump Start paragraph text. + * Will only show up in the paragraph if they are not active. + * + * @return string | comma-separated recommended modules that are not active + */ + function jumpstart_list_modules() { + $jumpstart_recommended = $this->jumpstart_module_tag( 'Jumpstart' ); + + $module_name = array(); + foreach ( $jumpstart_recommended as $module => $val ) { + if ( ! Jetpack::is_module_active( $val['module_slug'] ) ) { + $module_name[] = $val['module_name']; + } + } + $jumpstart_module_list = implode( $module_name, ', ' ); + + return $jumpstart_module_list; + } + + function jetpack_menu_order( $menu_order ) { + $jp_menu_order = array(); + + foreach ( $menu_order as $index => $item ) { + if ( $item != 'jetpack' ) + $jp_menu_order[] = $item; + + if ( $index == 0 ) + $jp_menu_order[] = 'jetpack'; + } + + return $jp_menu_order; + } + + function js_templates() { + Jetpack::init()->load_view( 'admin/landing-page-templates.php' ); + } + + function page_render() { + // Handle redirects to configuration pages + if ( ! empty( $_GET['configure'] ) ) { + return $this->render_nojs_configurable(); + } + + global $current_user; + + $is_connected = Jetpack::is_active(); + $user_token = Jetpack_Data::get_access_token( $current_user->ID ); + $is_user_connected = $user_token && ! is_wp_error( $user_token ); + $is_master_user = $current_user->ID == Jetpack_Options::get_option( 'master_user' ); + + if ( Jetpack::is_development_mode() ) { + $is_connected = true; + $is_user_connected = true; + $is_master_user = false; + } + + // Set template data for the admin page template + $data = array( + 'is_connected' => $is_connected, + 'is_user_connected' => $is_user_connected, + 'is_master_user' => $is_master_user, + 'show_jumpstart' => $this->jetpack_show_jumpstart(), + 'jumpstart_list' => $this->jumpstart_list_modules(), + 'recommended_list' => $this->jumpstart_module_tag( 'Recommended' ), + ); + Jetpack::init()->load_view( 'admin/admin-page.php', $data ); + } + + /** + * Shows a notice message to users after they save Module config settings + * @param string $module_id + * @return null + */ + function show_notices_update_settings( $module_id ) { + $state = Jetpack::state( 'message' ); + + switch( $state ) { + case 'module_activated' : + if ( $module = Jetpack::get_module( Jetpack::state( 'module' ) ) ) { + $message = sprintf( __( '<strong>%s Activated!</strong> You can change the setting of it here.', 'jetpack' ), $module['name'] ); + } + break; + case 'module_configured': + $message = __( '<strong>Module settings were saved.</strong> ', 'jetpack' ); + break; + case 'no_message' : + break; + } + + if ( isset( $message ) ) { + ?> + <div id="message" class="jetpack-message"> + <div class="squeezer"> + <h4><?php echo wp_kses( $message, array( 'strong' => array(), 'a' => array( 'href' => true ), 'br' => true ) ); ?></h4> + <?php + /** + * Fires within the displayed message when a feature configuation is updated. + * + * This is a dynamic hook with `$module_id` being the slug of the module being updated. + * + * @since 3.4.0 + */ + do_action( 'jetpack_notices_update_settings_' . $module_id ); ?> + </div> + </div> + <?php + } + add_action( 'jetpack_notices', array( Jetpack::init(), 'admin_notices' ) ); + } + + // Render the configuration page for the module if it exists and an error + // screen if the module is not configurable + function render_nojs_configurable() { + echo '<div class="clouds-sm"></div>'; + echo '<div class="wrap configure-module">'; + + $module_name = preg_replace( '/[^\da-z\-]+/', '', $_GET['configure'] ); + if ( Jetpack::is_module( $module_name ) && current_user_can( 'jetpack_configure_modules' ) ) { + Jetpack::admin_screen_configure_module( $module_name ); + } else { + echo '<h2>' . esc_html__( 'Error, bad module.', 'jetpack' ) . '</h2>'; + } + + echo '</div><!-- /wrap -->'; + } + + /* + * Build an array of Jump Start stats urls. + * requires the build URL args passed as an array + * + * @param array $jumpstart_stats + * @return (array) of built stats urls + */ + function build_jumpstart_stats_urls( $jumpstart_stats ) { + $jumpstart_urls = array(); + + foreach ( $jumpstart_stats as $value) { + $jumpstart_urls[$value] = Jetpack::build_stats_url( array( 'x_jetpack-jumpstart' => $value ) ); + } + + return $jumpstart_urls; + + } + + function page_admin_scripts() { + // Enqueue jp.js and localize it + wp_enqueue_script( 'jetpack-js', plugins_url( '_inc/jp.js', JETPACK__PLUGIN_FILE ), + array( 'jquery', 'wp-util' ), JETPACK__VERSION . '-20121111' ); + wp_localize_script( + 'jetpack-js', + 'jetpackL10n', + array( + 'ays_disconnect' => __( "This will deactivate all Jetpack modules.\nAre you sure you want to disconnect?", 'jetpack' ), + 'ays_unlink' => __( "This will prevent user-specific modules such as Publicize, Notifications and Post By Email from working.\nAre you sure you want to unlink?", 'jetpack' ), + 'ays_dismiss' => __( "This will deactivate Jetpack.\nAre you sure you want to deactivate Jetpack?", 'jetpack' ), + 'view_all_features' => __( 'View all Jetpack features', 'jetpack' ), + 'no_modules_found' => sprintf( __( 'Sorry, no modules were found for the search term "%s"', 'jetpack' ), '{term}' ), + 'modules' => array_values( Jetpack_Admin::init()->get_modules() ), + 'currentVersion' => JETPACK__VERSION, + 'ajaxurl' => admin_url( 'admin-ajax.php' ), + 'jumpstart_modules' => $this->jumpstart_module_tag( 'Jumpstart' ), + 'show_jumpstart' => $this->jetpack_show_jumpstart(), + 'activate_nonce' => wp_create_nonce( 'jetpack-jumpstart-nonce' ), + 'jumpstart_stats_urls' => $this->build_jumpstart_stats_urls( array( 'dismiss', 'jumpstarted', 'learnmore', 'viewed', 'manual' ) ), + 'site_url_manage' => Jetpack::build_raw_urls( get_site_url() ), + ) + ); + } +} diff --git a/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-settings-page.php b/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-settings-page.php new file mode 100644 index 00000000..0204aaf6 --- /dev/null +++ b/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-settings-page.php @@ -0,0 +1,87 @@ +<?php +include_once( 'class.jetpack-admin-page.php' ); +include_once( JETPACK__PLUGIN_DIR . 'class.jetpack-modules-list-table.php' ); + +// Builds the settings page and its menu +class Jetpack_Settings_Page extends Jetpack_Admin_Page { + // Show the settings page only when Jetpack is connected or in dev mode + protected $dont_show_if_not_active = true; + function add_page_actions( $hook ) {} // There are no page specific actions to attach to the menu + + // Adds the Settings sub menu + function get_page_hook() { + return add_submenu_page( 'jetpack', __( 'Jetpack Settings', 'jetpack' ), __( 'Settings', 'jetpack' ), 'jetpack_manage_modules', 'jetpack_modules', array( $this, 'render' ) ); + } + + // Renders the module list table where you can use bulk action or row + // actions to activate/deactivate and configure modules + function page_render() { + $list_table = new Jetpack_Modules_List_Table; + ?> + <div class="clouds-sm"></div> + <?php /** This action is documented in class.jetpack.php */ + do_action( 'jetpack_notices' ) ?> + <div class="page-content configure"> + <div class="frame top hide-if-no-js"> + <div class="wrap"> + <div class="manage-left"> + <table class="table table-bordered fixed-top"> + <thead> + <tr> + <th class="check-column"><input type="checkbox" class="checkall"></th> + <th colspan="2"> + <?php $list_table->unprotected_display_tablenav( 'top' ); ?> + <span class="filter-search"> + <button type="button" class="button">Filter</button> + </span> + </th> + </tr> + </thead> + </table> + </div> + </div><!-- /.wrap --> + </div><!-- /.frame --> + <div class="frame bottom"> + <div class="wrap"> + <div class="manage-right"> + <div class="bumper"> + <form class="navbar-form" role="search"> + <input type="hidden" name="page" value="jetpack_modules" /> + <?php $list_table->search_box( __( 'Search', 'jetpack' ), 'srch-term' ); ?> + <p><?php esc_html_e( 'View:', 'jetpack' ); ?></p> + <div class="button-group filter-active"> + <button type="button" class="button <?php if ( empty( $_GET['activated'] ) ) echo 'active'; ?>"><?php esc_html_e( 'All', 'jetpack' ); ?></button> + <button type="button" class="button <?php if ( ! empty( $_GET['activated'] ) && 'true' == $_GET['activated'] ) echo 'active'; ?>" data-filter-by="activated" data-filter-value="true"><?php esc_html_e( 'Active', 'jetpack' ); ?></button> + <button type="button" class="button <?php if ( ! empty( $_GET['activated'] ) && 'false' == $_GET['activated'] ) echo 'active'; ?>" data-filter-by="activated" data-filter-value="false"><?php esc_html_e( 'Inactive', 'jetpack' ); ?></button> + </div> + <p><?php esc_html_e( 'Sort by:', 'jetpack' ); ?></p> + <div class="button-group sort"> + <button type="button" class="button <?php if ( empty( $_GET['sort_by'] ) ) echo 'active'; ?>" data-sort-by="name"><?php esc_html_e( 'Alphabetical', 'jetpack' ); ?></button> + <button type="button" class="button <?php if ( ! empty( $_GET['sort_by'] ) && 'introduced' == $_GET['sort_by'] ) echo 'active'; ?>" data-sort-by="introduced" data-sort-order="reverse"><?php esc_html_e( 'Newest', 'jetpack' ); ?></button> + <button type="button" class="button <?php if ( ! empty( $_GET['sort_by'] ) && 'sort' == $_GET['sort_by'] ) echo 'active'; ?>" data-sort-by="sort"><?php esc_html_e( 'Popular', 'jetpack' ); ?></button> + </div> + <p><?php esc_html_e( 'Show:', 'jetpack' ); ?></p> + <?php $list_table->views(); ?> + </form> + </div> + </div> + <div class="manage-left"> + <form class="jetpack-modules-list-table-form" onsubmit="return false;"> + <table class="<?php echo implode( ' ', $list_table->get_table_classes() ); ?>"> + <tbody id="the-list"> + <?php $list_table->display_rows_or_placeholder(); ?> + </tbody> + </table> + </form> + </div> + </div><!-- /.wrap --> + </div><!-- /.frame --> + </div><!-- /.content --> + <?php + } + + // Javascript logic specific to the list table + function page_admin_scripts() { + wp_enqueue_script( 'jetpack-admin-js', plugins_url( '_inc/jetpack-admin.js', JETPACK__PLUGIN_FILE ), array( 'jquery' ), JETPACK__VERSION . '-20121111' ); + } +} |