| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * FeaturePresenter class |
|---|
| 4 | * |
|---|
| 5 | * @package multisyde |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | namespace Syde\MultiSyde; |
|---|
| 9 | |
|---|
| 10 | /** |
|---|
| 11 | * This class is responsible for presenting the features of the plugin in the network admin menu. |
|---|
| 12 | */ |
|---|
| 13 | final class Presenter { |
|---|
| 14 | |
|---|
| 15 | const MENU_SLUG = 'multisyde'; |
|---|
| 16 | |
|---|
| 17 | const CAPABILITY = 'manage_network'; |
|---|
| 18 | |
|---|
| 19 | const ICON_URL = 'dashicons-heart'; |
|---|
| 20 | |
|---|
| 21 | /** |
|---|
| 22 | * Instance of Modules class to access the features. |
|---|
| 23 | * |
|---|
| 24 | * @var Modules $modules |
|---|
| 25 | */ |
|---|
| 26 | protected Modules $modules; |
|---|
| 27 | |
|---|
| 28 | /** |
|---|
| 29 | * Constructor for Presenter class. |
|---|
| 30 | * |
|---|
| 31 | * @param Modules $modules Instance of Modules class to access the features. |
|---|
| 32 | */ |
|---|
| 33 | public function __construct( Modules $modules ) { |
|---|
| 34 | $this->modules = $modules; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | /** |
|---|
| 38 | * Initializes the feature presenter. |
|---|
| 39 | * |
|---|
| 40 | * @param Modules $modules Instance of Modules class to access the features. |
|---|
| 41 | * @return void |
|---|
| 42 | */ |
|---|
| 43 | public static function init( Modules $modules ) { |
|---|
| 44 | $obj = new self( $modules ); |
|---|
| 45 | |
|---|
| 46 | add_action( 'network_admin_menu', array( $obj, 'add_network_admin_menu' ) ); |
|---|
| 47 | |
|---|
| 48 | add_filter( 'admin_footer_text', array( $obj, 'get_admin_footer_text' ) ); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | /** |
|---|
| 52 | * Adds the feature overview page to the menu. |
|---|
| 53 | * |
|---|
| 54 | * @return void |
|---|
| 55 | */ |
|---|
| 56 | public function add_network_admin_menu(): void { |
|---|
| 57 | add_menu_page( |
|---|
| 58 | __( 'MultiSyde', 'multisyde' ), |
|---|
| 59 | __( 'MultiSyde', 'multisyde' ), |
|---|
| 60 | self::CAPABILITY, |
|---|
| 61 | self::MENU_SLUG, |
|---|
| 62 | array( $this, 'render_overview_page' ), |
|---|
| 63 | self::ICON_URL, |
|---|
| 64 | ); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | /** |
|---|
| 68 | * Renders the feature overview page. |
|---|
| 69 | * |
|---|
| 70 | * @return void |
|---|
| 71 | */ |
|---|
| 72 | public function render_overview_page(): void { |
|---|
| 73 | echo '<div class="wrap">'; |
|---|
| 74 | echo '<h1>' . esc_html__( 'MultiSyde', 'multisyde' ) . '</h1>'; |
|---|
| 75 | echo '<p>' . esc_html__( 'This plugin provides various improvements for WordPress multisite installations.', 'multisyde' ) . '</p>'; |
|---|
| 76 | |
|---|
| 77 | echo '<h2>' . esc_html__( 'Available Features', 'multisyde' ) . '</h2>'; |
|---|
| 78 | |
|---|
| 79 | $features_abouts = $this->modules->features(); |
|---|
| 80 | if ( ! empty( $features_abouts ) ) { |
|---|
| 81 | echo '<table class="wp-list-table widefat striped">'; |
|---|
| 82 | echo '<thead>'; |
|---|
| 83 | echo '<tr>'; |
|---|
| 84 | echo '<th scope="col" id="title" class="manage-column column-title" abbr="Title">' . esc_html__( 'Title', 'multisyde' ) . '</th>'; |
|---|
| 85 | echo '<th scope="col" id="description" class="manage-column column-description" abbr="Description">' . esc_html__( 'Description', 'multisyde' ) . '</th>'; |
|---|
| 86 | echo '<th scope="col" id="tickets" class="manage-column column-tickets" abbr="Tickets">' . esc_html__( 'Tickets', 'multisyde' ) . '</th>'; |
|---|
| 87 | echo '</tr>'; |
|---|
| 88 | echo '</thead>'; |
|---|
| 89 | echo '<tbody>'; |
|---|
| 90 | |
|---|
| 91 | foreach ( $features_abouts as $about ) { |
|---|
| 92 | $feature = $about::get(); |
|---|
| 93 | |
|---|
| 94 | echo '<tr>'; |
|---|
| 95 | echo '<td class="title column-title column-primary" data-colname="Title"><strong>' . esc_html( $feature->title ) . '</strong></td>'; |
|---|
| 96 | echo '<td class="description column-description" data-colname="Description">' . esc_html( $feature->description ) . '</td>'; |
|---|
| 97 | echo '<td class="tickets column-tickets has-row-actions" data-colname="Tickets">'; |
|---|
| 98 | |
|---|
| 99 | foreach ( $feature->tickets as $ticket ) { |
|---|
| 100 | echo '<span class="ticket"><a href="' . esc_url( $ticket ) . '" target="_blank">' . esc_html( $ticket ) . '</a></span><br>'; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | echo '</td>'; |
|---|
| 104 | echo '</tr>'; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | echo '</tbody>'; |
|---|
| 108 | echo '</table>'; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | echo '</div>'; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | /** |
|---|
| 115 | * Overrides the admin footer text. |
|---|
| 116 | * |
|---|
| 117 | * @param string $text The original footer text. |
|---|
| 118 | * |
|---|
| 119 | * @return string |
|---|
| 120 | */ |
|---|
| 121 | public static function get_admin_footer_text( string $text ): string { |
|---|
| 122 | $screen = get_current_screen(); |
|---|
| 123 | if ( is_null( $screen ) || 'toplevel_page_multisyde-network' !== $screen->id ) { |
|---|
| 124 | return $text; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | /* translators: 1: Dashicon, 2: Opening HTML tag for a link, 3: Closing HTML tags for a link. */ |
|---|
| 128 | $translation = __( 'Made with %1$s by %2$sSyde%3$s.', 'multisyde' ); |
|---|
| 129 | |
|---|
| 130 | return sprintf( $translation, '<span class="dashicons dashicons-heart"></span>', '<a href="https://syde.com" target="_blank" rel="noopener noreferrer">', '</a>' ); |
|---|
| 131 | } |
|---|
| 132 | } |
|---|