is_screen( 'tribe_events_page_tribe-help' ) || Tribe__Admin__Helpers::instance()->is_screen( 'settings_page_tribe-common-help-network' ); } /** * Register the Admin assets for the help page * * @since 4.9.12 * * @return void */ public function register_assets() { $plugin = Tribe__Main::instance(); tribe_asset( $plugin, 'tribe-admin-help-page', 'admin/help-page.js', [ 'tribe-clipboard', 'tribe-common' ], 'admin_enqueue_scripts', [ 'conditionals' => [ $this, 'is_current_page' ], 'localize' => [ 'name' => 'tribe_system_info', 'data' => [ 'sysinfo_optin_nonce' => wp_create_nonce( 'sysinfo_optin_nonce' ), 'clipboard_btn_text' => __( 'Copy to clipboard', 'tribe-common' ), 'clipboard_copied_text' => __( 'System info copied', 'tribe-common' ), 'clipboard_fail_text' => __( 'Press "Cmd + C" to copy', 'tribe-common' ), ], ], ] ); } /** * Get the list of plugins * * @since 4.0 * * @param string $plugin_name Should get only one plugin? * @param boolean $is_active Only get active plugins? * @return array */ public function get_plugins( $plugin_name = null, $is_active = true ) { $plugins = []; $plugins['the-events-calendar'] = [ 'name' => 'the-events-calendar', 'title' => esc_html__( 'The Events Calendar', 'tribe-common' ), 'repo' => 'https://wordpress.org/plugins/the-events-calendar/', 'forum' => 'https://wordpress.org/support/plugin/the-events-calendar/', 'stars_url' => 'https://wordpress.org/support/plugin/the-events-calendar/reviews/?filter=5', 'description' => esc_html__( 'The Events Calendar is a carefully crafted, extensible plugin that lets you easily share your events.', 'tribe-common' ), 'is_active' => false, 'version' => null, ]; if ( class_exists( 'Tribe__Events__Main' ) ) { $plugins['the-events-calendar']['version'] = Tribe__Events__Main::VERSION; $plugins['the-events-calendar']['is_active'] = true; } $plugins['event-tickets'] = [ 'name' => 'event-tickets', 'title' => esc_html__( 'Event Tickets', 'tribe-common' ), 'repo' => 'https://wordpress.org/plugins/event-tickets/', 'forum' => 'https://wordpress.org/support/plugin/event-tickets', 'stars_url' => 'https://wordpress.org/support/plugin/event-tickets/reviews/?filter=5', 'description' => esc_html__( 'Events Tickets is a carefully crafted, extensible plugin that lets you easily sell tickets for your events.', 'tribe-common' ), 'is_active' => false, 'version' => null, ]; if ( class_exists( 'Tribe__Tickets__Main' ) ) { $plugins['event-tickets']['version'] = Tribe__Tickets__Main::VERSION; $plugins['event-tickets']['is_active'] = true; } $plugins['advanced-post-manager'] = [ 'name' => 'advanced-post-manager', 'title' => esc_html__( 'Advanced Post Manager', 'tribe-common' ), 'repo' => 'https://wordpress.org/plugins/advanced-post-manager/', 'forum' => 'https://wordpress.org/support/plugin/advanced-post-manager/', 'stars_url' => 'https://wordpress.org/support/plugin/advanced-post-manager/reviews/?filter=5', 'description' => esc_html__( 'Turbo charge your posts admin for any custom post type with sortable filters and columns, and auto-registration of metaboxes.', 'tribe-common' ), 'is_active' => false, 'version' => null, ]; if ( class_exists( 'Tribe_APM' ) ) { $plugins['advanced-post-manager']['version'] = 1; $plugins['advanced-post-manager']['is_active'] = true; } $plugins = (array) apply_filters( 'tribe_help_plugins', $plugins ); // Only active ones? if ( true === $is_active ) { foreach ( $plugins as $key => $plugin ) { if ( true !== $plugin['is_active'] ) { unset( $plugins[ $key ] ); } } } // Do the search if ( is_string( $plugin_name ) ) { if ( isset( $plugins[ $plugin_name ] ) ) { return $plugins[ $plugin_name ]; } else { return false; } } else { return $plugins; } } /** * Get the formatted links of the possible plugins * * @since 4.0 * * @param boolean $is_active Filter only active plugins * @return array */ public function get_plugin_forum_links( $is_active = true ) { $plugins = $this->get_plugins( null, $is_active ); $list = []; foreach ( $plugins as $plugin ) { $list[] = '' . $plugin['title'] . ''; } return $list; } /** * Get the formatted text of the possible plugins * * @since 4.0 * * @param boolean $is_active Filter only active plugins * @return string */ public function get_plugins_text( $is_active = true ) { $plugins = array_merge( $this->get_plugins( null, $is_active ), $this->get_addons( null, $is_active, true ) ); $plugins_text = ''; $i = 0; $count = count( $plugins ); foreach ( $plugins as $plugin ) { $i++; if ( ! isset( $plugin['is_active'] ) || $plugin['is_active'] !== $is_active ) { continue; } $plugins_text .= $plugin['title']; if ( $i === $count - 1 ) { $plugins_text .= esc_html__( ' and ', 'tribe-common' ); } elseif ( $i !== $count ) { $plugins_text .= ', '; } } return $plugins_text; } /** * Get the Addons * * @since 4.0 * * @param string $plugin Plugin Name to filter * @param string $is_active Filter if it's active * @param string $is_important filter if the plugin is important * @return array */ public function get_addons( $plugin = null, $is_active = null, $is_important = null ) { $addons = []; $addons['events-calendar-pro'] = [ 'id' => 'events-calendar-pro', 'title' => esc_html__( 'Events Calendar PRO', 'tribe-common' ), 'link' => 'http://evnt.is/dr', 'plugin' => [ 'the-events-calendar' ], 'is_active' => class_exists( 'Tribe__Events__Pro__Main' ), 'is_important' => true, ]; $addons['eventbrite-tickets'] = [ 'id' => 'eventbrite-tickets', 'title' => esc_html__( 'Eventbrite Tickets', 'tribe-common' ), 'link' => 'http://evnt.is/ds', 'plugin' => [ 'the-events-calendar' ], 'is_active' => class_exists( 'Tribe__Events__Tickets__Eventbrite__Main' ), ]; $addons['community-events'] = [ 'id' => 'community-events', 'title' => esc_html__( 'Community Events', 'tribe-common' ), 'link' => 'http://evnt.is/dt', 'plugin' => [ 'the-events-calendar' ], 'is_active' => class_exists( 'Tribe__Events__Community__Main' ), ]; $addons['event-aggregator'] = [ 'id' => 'event-aggregator', 'title' => esc_html__( 'Event Aggregator', 'tribe-common' ), 'link' => 'http://evnt.is/19mk', 'plugin' => [ 'the-events-calendar' ], 'is_active' => class_exists( 'Tribe__Events__Aggregator' ) && tribe( 'events-aggregator.main' )->is_service_active(), ]; $addons['events-filter-bar'] = [ 'id' => 'events-filter-bar', 'title' => esc_html__( 'Filter Bar', 'tribe-common' ), 'link' => 'http://evnt.is/hu', 'plugin' => [ 'the-events-calendar' ], 'is_active' => class_exists( 'Tribe__Events__Filterbar__View' ), ]; $addons['events-virtual'] = [ 'id' => 'events-virtual', 'title' => esc_html__( 'Virtual Events', 'tribe-common' ), 'link' => 'http://evnt.is/1alb', 'plugin' => [ 'the-events-calendar' ], 'is_active' => class_exists( '\Tribe\Events\Virtual\Plugin' ), ]; $addons['event-tickets-plus'] = [ 'id' => 'event-tickets-plus', 'title' => esc_html__( 'Event Tickets Plus', 'tribe-common' ), 'link' => 'http://evnt.is/18wa', 'plugin' => [ 'event-tickets' ], 'is_active' => class_exists( 'Tribe__Tickets_Plus__Main' ), 'is_important' => true, ]; $addons['event-community-tickets'] = [ 'id' => 'event-community-tickets', 'title' => esc_html__( 'Community Tickets', 'tribe-common' ), 'link' => 'http://evnt.is/18m2', 'plugin' => [ 'event-tickets' ], 'is_active' => class_exists( 'Tribe__Events__Community__Tickets__Main' ), ]; /** * Filter the array of premium addons upsold on the sidebar of the Settings > Help tab * * @param array $addons */ $addons = (array) apply_filters( 'tribe_help_addons', $addons ); // Should I filter something if ( is_null( $plugin ) && is_null( $is_active ) && is_null( $is_important ) ) { return $addons; } // Allow for easily grab the addons for a plugin $filtered = []; foreach ( $addons as $id => $addon ) { if ( ! is_null( $plugin ) && ! in_array( $plugin, (array) $addon['plugin'] ) ) { continue; } // Filter by is_active if ( ! is_null( $is_active ) && ( ! isset( $addon['is_active'] ) || $is_active !== $addon['is_active'] ) ) { continue; } // Filter by is_important if ( ! is_null( $is_important ) && ( ! isset( $addon['is_important'] ) || $is_important !== $addon['is_important'] ) ) { continue; } $filtered[ $id ] = $addon; } return $filtered; } public function is_active( $should_be_active ) { $plugins = $this->get_plugins( null, true ); $addons = $this->get_addons( null, true ); $actives = array_merge( $plugins, $addons ); $is_active = []; foreach ( $actives as $id => $active ) { if ( in_array( $id, (array) $should_be_active ) ) { $is_active[] = $id; } } return count( array_filter( $is_active ) ) === 0 ? false : true; } /** * From a Given link returns it with a GA arguments * * @since 4.0 * * @param string $link An absolute or a Relative link * @param boolean $relative Is the Link absolute or relative? * @return string Link with the GA arguments */ public function get_ga_link( $link = null, $relative = true ) { $query_args = [ 'utm_source' => 'helptab', 'utm_medium' => 'plugin-tec', 'utm_campaign' => 'in-app', ]; if ( true === $relative ) { $link = trailingslashit( Tribe__Main::$tec_url . $link ); } return esc_url( add_query_arg( $query_args, $link ) ); } /** * Gets the Feed items from The Events Calendar's Blog * * @since 4.0 * * @return array Feed Title and Link */ public function get_feed_items() { $news_rss = fetch_feed( Tribe__Main::FEED_URL ); $news_feed = []; if ( ! is_wp_error( $news_rss ) ) { /** * Filter the maximum number of items returned from the tribe news feed * * @param int $max_items default 5 */ $maxitems = $news_rss->get_item_quantity( apply_filters( 'tribe_help_rss_max_items', 5 ) ); $rss_items = $news_rss->get_items( 0, $maxitems ); if ( $maxitems > 0 ) { foreach ( $rss_items as $item ) { $item = [ 'title' => esc_html( $item->get_title() ), 'link' => esc_url( $item->get_permalink() ), ]; $news_feed[] = $item; } } } return $news_feed; } /** * Get the information from the Plugin API data * * @since 4.0 * * @param object $plugin Plugin Object to be used * @return object An object with the API data */ private function get_plugin_api_data( $plugin = null ) { if ( is_scalar( $plugin ) ) { return false; } $plugin = (object) $plugin; /** * Filter the amount of time (seconds) we will keep api data to avoid too many external calls * @var int */ $timeout = apply_filters( 'tribe_help_api_data_timeout', 3 * HOUR_IN_SECONDS ); $transient = 'tribe_help_api_data-' . $plugin->name; $data = get_transient( $transient ); if ( false === $data ) { if ( ! function_exists( 'plugins_api' ) ) { include_once ABSPATH . '/wp-admin/includes/plugin-install.php'; } // Fetch the data $data = plugins_api( 'plugin_information', [ 'slug' => $plugin->name, 'is_ssl' => is_ssl(), 'fields' => [ 'banners' => true, 'reviews' => true, 'downloaded' => true, 'active_installs' => true, ], ] ); if ( ! is_wp_error( $data ) ) { // Format Downloaded Infomation $data->downloaded = $data->downloaded ? number_format( $data->downloaded ) : _x( 'n/a', 'not available', 'tribe-common' ); } else { // If there was a bug on the Current Request just leave return false; } set_transient( $transient, $data, $timeout ); } $data->up_to_date = ( version_compare( $plugin->version, $data->version, '<' ) ) ? esc_html__( 'You need to upgrade!', 'tribe-common' ) : esc_html__( 'You are up to date!', 'tribe-common' ); /** * Filters the API data that was stored in the Transient option * * @var array * @var object The plugin object, check `$this->get_plugins()` for more info */ return (object) apply_filters( 'tribe_help_api_data', $data, $plugin ); } /** * Parses the help text from an Array to the final HTML. * * It is the responsibility of code calling this function to ensure proper escaping * within any HTML. * * @since 4.0 * * @param string|array $mixed The mixed value to create the HTML from * @return string */ public function get_content_html( $mixed = '' ) { // If it's an StdObj or String it will be converted $mixed = (array) $mixed; // Loop to start the HTML foreach ( $mixed as &$line ) { // If we have content we use that if ( isset( $line->content ) ) { $line = $line->content; } if ( is_string( $line ) ) { continue; } elseif ( is_array( $line ) ) { // Allow the developer to pass some configuration if ( empty( $line['type'] ) ) { $line['type'] = 'ul'; } $text = '<' . $line['type'] . '>' . "\n"; foreach ( $line as $key => $item ) { // Don't add non-numeric items (a.k.a.: configuration) if ( ! is_numeric( $key ) ) { continue; } // Only add List Item if is a UL or OL if ( in_array( $line['type'], [ 'ul', 'ol' ] ) ) { $text .= '