PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-landing-page.php

https://gitlab.com/thisishayat/itv-2016
PHP | 299 lines | 187 code | 41 blank | 71 comment | 20 complexity | 59cd8920225a26757d30581834b3687b MD5 | raw file
  1. <?php
  2. include_once( 'class.jetpack-admin-page.php' );
  3. // Builds the landing page and its menu
  4. class Jetpack_Landing_Page extends Jetpack_Admin_Page {
  5. protected $dont_show_if_not_active = false;
  6. function get_page_hook() {
  7. $title = _x( 'Jetpack', 'The menu item label', 'jetpack' );
  8. list( $jetpack_version ) = explode( ':', Jetpack_Options::get_option( 'version' ) );
  9. if (
  10. $jetpack_version
  11. &&
  12. $jetpack_version != JETPACK__VERSION
  13. &&
  14. ( $new_modules = Jetpack::get_default_modules( $jetpack_version, JETPACK__VERSION ) )
  15. &&
  16. is_array( $new_modules )
  17. &&
  18. ( $new_modules_count = count( $new_modules ) )
  19. &&
  20. ( Jetpack::is_active() || Jetpack::is_development_mode() )
  21. ) {
  22. $new_count_i18n = number_format_i18n( $new_modules_count );
  23. $span_title = esc_attr( sprintf( _n( 'One New Jetpack Module', '%s New Jetpack Modules', $new_modules_count, 'jetpack' ), $new_count_i18n ) );
  24. $format = _x( 'Jetpack %s', 'The menu item label with a new module count as %s', 'jetpack' );
  25. $update_markup = "<span class='update-plugins count-{$new_modules_count}' title='$span_title'><span class='update-count'>$new_count_i18n</span></span>";
  26. $title = sprintf( $format, $update_markup );
  27. }
  28. // Add the main admin Jetpack menu with possible information about new
  29. // modules
  30. add_menu_page( 'Jetpack', $title, 'jetpack_admin_page', 'jetpack', array( $this, 'render' ), 'div' );
  31. // also create the submenu
  32. return add_submenu_page( 'jetpack', $title, $title, 'jetpack_admin_page', 'jetpack' );
  33. }
  34. function add_page_actions( $hook ) {
  35. // Add landing page specific underscore templates
  36. /**
  37. * Filters the js_templates callback value
  38. *
  39. * @since 3.6.0
  40. *
  41. * @param array array( $this, 'js_templates' ) js_templates callback.
  42. * @param string $hook Specific admin page.
  43. */
  44. add_action( "admin_footer-$hook", apply_filters( 'jetpack_landing_page_js_templates_callback', array( $this, 'js_templates' ), $hook ) );
  45. /** This action is documented in class.jetpack.php */
  46. do_action( 'jetpack_admin_menu', $hook );
  47. // Place the Jetpack menu item on top and others in the order they
  48. // appear
  49. add_filter( 'custom_menu_order', '__return_true' );
  50. add_filter( 'menu_order', array( $this, 'jetpack_menu_order' ) );
  51. add_action( 'jetpack_notices_update_settings', array( $this, 'show_notices_update_settings' ), 10, 1 );
  52. }
  53. /*
  54. * Build an array of a specific module tag.
  55. *
  56. * @param string Name of the module tag
  57. * @return array The module slug, config url, and name of each Jump Start module
  58. */
  59. function jumpstart_module_tag( $tag ) {
  60. $modules = Jetpack_Admin::init()->get_modules();
  61. $module_info = array();
  62. foreach ( $modules as $module => $value ) {
  63. if ( in_array( $tag, $value['feature'] ) ) {
  64. $module_info[] = array(
  65. 'module_slug' => $value['module'],
  66. 'module_name' => $value['name'],
  67. 'configure_url' => $value['configure_url'],
  68. );
  69. }
  70. }
  71. return $module_info;
  72. }
  73. /*
  74. * Only show Jump Start on first activation.
  75. * Any option 'jumpstart' other than 'new connection' will hide it.
  76. *
  77. * The option can be of 4 things, and will be stored as such:
  78. * new_connection : Brand new connection - Show
  79. * jumpstart_activated : Jump Start has been activated - dismiss
  80. * jetpack_action_taken: Manual activation of a module already happened - dismiss
  81. * jumpstart_dismissed : Manual dismissal of Jump Start - dismiss
  82. *
  83. * @return bool | show or hide
  84. */
  85. function jetpack_show_jumpstart() {
  86. $jumpstart_option = Jetpack_Options::get_option( 'jumpstart' );
  87. $hide_options = array(
  88. 'jumpstart_activated',
  89. 'jetpack_action_taken',
  90. 'jumpstart_dismissed'
  91. );
  92. if ( ! $jumpstart_option || in_array( $jumpstart_option, $hide_options ) ) {
  93. return false;
  94. }
  95. return true;
  96. }
  97. /*
  98. * List of recommended modules for the Jump Start paragraph text.
  99. * Will only show up in the paragraph if they are not active.
  100. *
  101. * @return string | comma-separated recommended modules that are not active
  102. */
  103. function jumpstart_list_modules() {
  104. $jumpstart_recommended = $this->jumpstart_module_tag( 'Jumpstart' );
  105. $module_name = array();
  106. foreach ( $jumpstart_recommended as $module => $val ) {
  107. if ( ! Jetpack::is_module_active( $val['module_slug'] ) ) {
  108. $module_name[] = $val['module_name'];
  109. }
  110. }
  111. return $module_name;
  112. }
  113. function jetpack_menu_order( $menu_order ) {
  114. $jp_menu_order = array();
  115. foreach ( $menu_order as $index => $item ) {
  116. if ( $item != 'jetpack' )
  117. $jp_menu_order[] = $item;
  118. if ( $index == 0 )
  119. $jp_menu_order[] = 'jetpack';
  120. }
  121. return $jp_menu_order;
  122. }
  123. function js_templates() {
  124. Jetpack::init()->load_view( 'admin/landing-page-templates.php' );
  125. }
  126. function page_render() {
  127. // Handle redirects to configuration pages
  128. if ( ! empty( $_GET['configure'] ) ) {
  129. return $this->render_nojs_configurable();
  130. }
  131. global $current_user;
  132. $is_connected = Jetpack::is_active();
  133. $user_token = Jetpack_Data::get_access_token( $current_user->ID );
  134. $is_user_connected = $user_token && ! is_wp_error( $user_token );
  135. $is_master_user = $current_user->ID == Jetpack_Options::get_option( 'master_user' );
  136. if ( Jetpack::is_development_mode() ) {
  137. $is_connected = true;
  138. $is_user_connected = true;
  139. $is_master_user = false;
  140. }
  141. // Set template data for the admin page template
  142. $data = array(
  143. 'is_connected' => $is_connected,
  144. 'is_user_connected' => $is_user_connected,
  145. 'is_master_user' => $is_master_user,
  146. 'show_jumpstart' => $this->jetpack_show_jumpstart(),
  147. 'jumpstart_list' => $this->jumpstart_list_modules(),
  148. 'recommended_list' => $this->jumpstart_module_tag( 'Recommended' ),
  149. );
  150. Jetpack::init()->load_view( 'admin/admin-page.php', $data );
  151. }
  152. /**
  153. * Shows a notice message to users after they save Module config settings
  154. * @param string $module_id
  155. * @return null
  156. */
  157. function show_notices_update_settings( $module_id ) {
  158. $state = Jetpack::state( 'message' );
  159. switch( $state ) {
  160. case 'module_activated' :
  161. if ( $module = Jetpack::get_module( Jetpack::state( 'module' ) ) ) {
  162. $message = sprintf( __( '<strong>%s Activated!</strong> You can change the setting of it here.', 'jetpack' ), $module['name'] );
  163. }
  164. break;
  165. case 'module_configured':
  166. $message = __( '<strong>Module settings were saved.</strong> ', 'jetpack' );
  167. break;
  168. case 'no_message' :
  169. break;
  170. }
  171. if ( isset( $message ) ) {
  172. ?>
  173. <div id="message" class="jetpack-message">
  174. <div class="squeezer">
  175. <h2><?php echo wp_kses( $message, array( 'strong' => array(), 'a' => array( 'href' => true ), 'br' => true ) ); ?></h2>
  176. <?php
  177. /**
  178. * Fires within the displayed message when a feature configuation is updated.
  179. *
  180. * This is a dynamic hook with `$module_id` being the slug of the module being updated.
  181. *
  182. * @since 3.4.0
  183. */
  184. do_action( 'jetpack_notices_update_settings_' . $module_id ); ?>
  185. </div>
  186. </div>
  187. <?php
  188. }
  189. add_action( 'jetpack_notices', array( Jetpack::init(), 'admin_notices' ) );
  190. }
  191. // Render the configuration page for the module if it exists and an error
  192. // screen if the module is not configurable
  193. function render_nojs_configurable() {
  194. echo '<div class="clouds-sm"></div>';
  195. echo '<div class="wrap configure-module">';
  196. $module_name = preg_replace( '/[^\da-z\-]+/', '', $_GET['configure'] );
  197. if ( Jetpack::is_module( $module_name ) && current_user_can( 'jetpack_configure_modules' ) ) {
  198. Jetpack::admin_screen_configure_module( $module_name );
  199. } else {
  200. echo '<h2>' . esc_html__( 'Error, bad module.', 'jetpack' ) . '</h2>';
  201. }
  202. echo '</div><!-- /wrap -->';
  203. }
  204. /*
  205. * Build an array of Jump Start stats urls.
  206. * requires the build URL args passed as an array
  207. *
  208. * @param array $jumpstart_stats
  209. * @return (array) of built stats urls
  210. */
  211. function build_jumpstart_stats_urls( $jumpstart_stats ) {
  212. $jumpstart_urls = array();
  213. foreach ( $jumpstart_stats as $value) {
  214. $jumpstart_urls[$value] = Jetpack::build_stats_url( array( 'x_jetpack-jumpstart' => $value ) );
  215. }
  216. return $jumpstart_urls;
  217. }
  218. /*
  219. * Build an array of NUX admin stats urls.
  220. * requires the build URL args passed as an array
  221. *
  222. * @param array $nux_admin_stats
  223. * @return (array) of built stats urls
  224. */
  225. function build_nux_admin_stats_urls( $nux_admin_stats ) {
  226. $nux_admin_urls = array();
  227. foreach ( $nux_admin_stats as $value) {
  228. $nux_admin_urls[ $value ] = Jetpack::build_stats_url( array( 'x_jetpack-nux' => $value ) );
  229. }
  230. return $nux_admin_urls;
  231. }
  232. function page_admin_scripts() {
  233. // Enqueue jp.js and localize it
  234. wp_enqueue_script( 'jetpack-js', plugins_url( '_inc/jp.js', JETPACK__PLUGIN_FILE ),
  235. array( 'jquery', 'wp-util' ), JETPACK__VERSION . '-20121111' );
  236. wp_localize_script(
  237. 'jetpack-js',
  238. 'jetpackL10n',
  239. array(
  240. 'ays_disconnect' => __( "This will deactivate all Jetpack modules.\nAre you sure you want to disconnect?", 'jetpack' ),
  241. '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' ),
  242. 'ays_dismiss' => __( "This will deactivate Jetpack.\nAre you sure you want to deactivate Jetpack?", 'jetpack' ),
  243. 'view_all_features' => __( 'View all Jetpack features', 'jetpack' ),
  244. 'no_modules_found' => sprintf( __( 'Sorry, no modules were found for the search term "%s"', 'jetpack' ), '{term}' ),
  245. 'modules' => Jetpack::get_translated_modules( array_values( Jetpack_Admin::init()->get_modules() ) ),
  246. 'currentVersion' => JETPACK__VERSION,
  247. 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  248. 'jumpstart_modules' => $this->jumpstart_module_tag( 'Jumpstart' ),
  249. 'show_jumpstart' => $this->jetpack_show_jumpstart(),
  250. 'activate_nonce' => wp_create_nonce( 'jetpack-jumpstart-nonce' ),
  251. 'admin_nonce' => wp_create_nonce( 'jetpack-admin-nonce' ),
  252. 'jumpstart_stats_urls' => $this->build_jumpstart_stats_urls( array( 'dismiss', 'jumpstarted', 'learnmore', 'viewed', 'manual' ) ),
  253. 'admin_stats_urls' => $this->build_nux_admin_stats_urls( array( 'enabled', 'deactivated', 'learnmore' ) ),
  254. 'site_url_manage' => Jetpack::build_raw_urls( get_site_url() ),
  255. )
  256. );
  257. }
  258. }