| 1 |
<?php |
| 2 |
/** |
| 3 |
* Agency knowledge and record review. |
| 4 |
* |
| 5 |
* @package MainWP\Dashboard |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace MainWP\Dashboard; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Knowledge page controller. |
| 16 |
*/ |
| 17 |
class MainWP_Knowledge { |
| 18 |
|
| 19 |
/** |
| 20 |
* The Knowledge screen needs the Dashboard parent to load its assets. |
| 21 |
* |
| 22 |
* @return void |
| 23 |
*/ |
| 24 |
public static function init_menu() { |
| 25 |
if ( ! MainWP_System_Utility::is_admin() || true !== MainWP_Abilities_Util::check_rest_api_permission() || MainWP_Menu::is_disable_menu_item( 2, 'ai' ) ) { |
| 26 |
return; |
| 27 |
} |
| 28 |
add_submenu_page( |
| 29 |
'mainwp_tab', |
| 30 |
esc_html__( 'Knowledge', 'mainwp' ), |
| 31 |
'<span id="mainwp-knowledge">' . esc_html__( 'Knowledge', 'mainwp' ) . '</span>', |
| 32 |
'manage_options', |
| 33 |
'Knowledge', |
| 34 |
array( static::class, 'render' ) |
| 35 |
); |
| 36 |
MainWP_Menu::add_left_menu( |
| 37 |
array( |
| 38 |
'title' => esc_html__( 'Knowledge', 'mainwp' ), |
| 39 |
'parent_key' => 'ai', |
| 40 |
'slug' => 'Knowledge', |
| 41 |
'href' => 'admin.php?page=Knowledge', |
| 42 |
'leftsub_order_level2' => 1, |
| 43 |
), |
| 44 |
2 |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Dashboard page access is required even when the base permission passes. |
| 50 |
* |
| 51 |
* @return void |
| 52 |
*/ |
| 53 |
public static function render() { |
| 54 |
if ( ! MainWP_System_Utility::is_admin() || true !== MainWP_Abilities_Util::check_rest_api_permission() ) { |
| 55 |
echo '<div class="ui message">' . esc_html__( 'You do not have permission to access this knowledge.', 'mainwp' ) . '</div>'; |
| 56 |
return; |
| 57 |
} |
| 58 |
$tab = isset( $_GET['tab'] ) && is_string( $_GET['tab'] ) && 'agency' === sanitize_key( wp_unslash( $_GET['tab'] ) ) ? 'agency' : 'review'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Navigation is read-only. |
| 59 |
MainWP_UI::render_top_header( array( 'title' => esc_html__( 'Knowledge', 'mainwp' ) ) ); |
| 60 |
self::render_navigation( $tab ); |
| 61 |
?> |
| 62 |
<div id="mainwp-knowledge-page" class="ui padded segment"> |
| 63 |
<?php if ( 'agency' === $tab ) : ?> |
| 64 |
<?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-knowledge-agency-info-message' ) ) : ?> |
| 65 |
<div class="ui blue message"> |
| 66 |
<i class="close icon mainwp-notice-dismiss" notice-id="mainwp-knowledge-agency-info-message"></i> |
| 67 |
<?php esc_html_e( 'Agency records reach the AI agents working on every site in this Dashboard. Every Dashboard user can read them, so keep client-specific details on the client.', 'mainwp' ); ?> |
| 68 |
</div> |
| 69 |
<?php endif; ?> |
| 70 |
<?php MainWP_Knowledge_UI::render_panel( 'agency', 0 ); ?> |
| 71 |
<?php else : ?> |
| 72 |
<?php self::render_review(); ?> |
| 73 |
<?php endif; ?> |
| 74 |
</div> |
| 75 |
<?php |
| 76 |
add_action( 'admin_footer', array( MainWP_Knowledge_UI::class, 'render_modal' ) ); |
| 77 |
// The shared header opens the page container, as on the Tags page. |
| 78 |
echo '</div>'; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Render the Knowledge page tabular navigation. |
| 83 |
* |
| 84 |
* @param string $active Active tab. |
| 85 |
* |
| 86 |
* @return void |
| 87 |
*/ |
| 88 |
private static function render_navigation( $active ) { |
| 89 |
?> |
| 90 |
<div class="ui labeled icon inverted menu mainwp-sub-submenu" id="mainwp-knowledge-tabular-menu"> |
| 91 |
<a class="item <?php echo esc_attr( 'review' === $active ? 'active' : '' ); ?>" data-tab="review" href="<?php echo esc_url( 'admin.php?page=Knowledge&tab=review' ); ?>"> |
| 92 |
<i class="check circle icon"></i> |
| 93 |
<?php esc_html_e( 'Review', 'mainwp' ); ?> |
| 94 |
</a> |
| 95 |
<a class="item <?php echo esc_attr( 'agency' === $active ? 'active' : '' ); ?>" data-tab="agency" href="<?php echo esc_url( 'admin.php?page=Knowledge&tab=agency' ); ?>"> |
| 96 |
<i class="building icon"></i> |
| 97 |
<?php esc_html_e( 'Agency', 'mainwp' ); ?> |
| 98 |
</a> |
| 99 |
</div> |
| 100 |
<?php |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Render the review filters, empty states, and grouped record accordions. |
| 105 |
* |
| 106 |
* @return void |
| 107 |
*/ |
| 108 |
private static function render_review() { |
| 109 |
$filters = array( |
| 110 |
'status' => array( |
| 111 |
'label' => __( 'Status', 'mainwp' ), |
| 112 |
'options' => array( |
| 113 |
'all' => __( 'All', 'mainwp' ), |
| 114 |
'unverified' => __( 'Unverified', 'mainwp' ), |
| 115 |
'verified' => __( 'Verified', 'mainwp' ), |
| 116 |
), |
| 117 |
), |
| 118 |
'level' => array( |
| 119 |
'label' => __( 'Level', 'mainwp' ), |
| 120 |
'options' => array( |
| 121 |
'all' => __( 'All levels', 'mainwp' ), |
| 122 |
'agency' => __( 'Agency', 'mainwp' ), |
| 123 |
'client' => __( 'Client', 'mainwp' ), |
| 124 |
'site' => __( 'Site', 'mainwp' ), |
| 125 |
), |
| 126 |
), |
| 127 |
); |
| 128 |
?> |
| 129 |
<div class="mainwp-actions-bar" id="mainwp-knowledge-review-filters"> |
| 130 |
<div class="ui mini form stackable grid"> |
| 131 |
<div class="ui two column row"> |
| 132 |
<div class="left aligned middle aligned column"> |
| 133 |
<?php foreach ( $filters as $key => $filter ) : ?> |
| 134 |
<select id="mainwp-knowledge-filter-<?php echo esc_attr( $key ); ?>" class="ui mini selection dropdown" aria-label="<?php echo esc_attr( $filter['label'] ); ?>"> |
| 135 |
<?php foreach ( $filter['options'] as $value => $label ) : ?> |
| 136 |
<option value="<?php echo esc_attr( $value ); ?>" <?php selected( 'status' === $key ? 'unverified' : 'all', $value ); ?>><?php echo esc_html( $label ); ?></option> |
| 137 |
<?php endforeach; ?> |
| 138 |
</select> |
| 139 |
<?php endforeach; ?> |
| 140 |
</div> |
| 141 |
<div class="right aligned middle aligned column"></div> |
| 142 |
</div> |
| 143 |
</div> |
| 144 |
</div> |
| 145 |
<?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-knowledge-review-info-message' ) ) : ?> |
| 146 |
<div class="ui blue message"> |
| 147 |
<i class="close icon mainwp-notice-dismiss" notice-id="mainwp-knowledge-review-info-message"></i> |
| 148 |
<?php esc_html_e( 'Records saved by AI agents stay unverified until a person reviews them. Check each record, then verify, edit, or delete it.', 'mainwp' ); ?> |
| 149 |
</div> |
| 150 |
<?php endif; ?> |
| 151 |
<div class="ui hidden message" id="mainwp-knowledge-review-message"></div> |
| 152 |
<div class="hidden" id="mainwp-knowledge-review-empty" aria-hidden="true"> |
| 153 |
<?php MainWP_UI::render_empty_page_placeholder( __( 'Nothing to review yet', 'mainwp' ), __( 'Knowledge records saved by AI agents will appear here until a person reviews them.', 'mainwp' ), '<em data-emoji=":bulb:" class="big"></em>' ); ?> |
| 154 |
</div> |
| 155 |
<div class="ui dimmable segment" id="mainwp-knowledge-review" style="padding:0!important;" data-empty-filtered="<?php esc_attr_e( 'No knowledge records match the selected filters.', 'mainwp' ); ?>"> |
| 156 |
<div class="ui dimmer mainwp-knowledge-loader" aria-hidden="true"> |
| 157 |
<div class="ui loader" role="status" aria-label="<?php esc_attr_e( 'Loading...', 'mainwp' ); ?>"></div> |
| 158 |
</div> |
| 159 |
<div class="hidden" id="mainwp-knowledge-review-filtered-empty" aria-hidden="true"> |
| 160 |
<?php MainWP_UI::render_empty_element_placeholder( __( 'No matching records', 'mainwp' ), __( 'Try changing the status or level filters.', 'mainwp' ), '<em data-emoji=":mag:" class="medium"></em>' ); ?> |
| 161 |
</div> |
| 162 |
<?php |
| 163 |
MainWP_Knowledge_UI::render_sections( |
| 164 |
'review', |
| 165 |
array( |
| 166 |
'container_class' => 'mainwp-knowledge-review-sections', |
| 167 |
'section_class' => 'mainwp-knowledge-review-section', |
| 168 |
'show_add' => false, |
| 169 |
'empty_title' => __( 'No matching records', 'mainwp' ), |
| 170 |
'empty_description' => __( 'No records of this type match the selected filters.', 'mainwp' ), |
| 171 |
) |
| 172 |
); |
| 173 |
?> |
| 174 |
</div> |
| 175 |
<?php |
| 176 |
} |
| 177 |
} |
| 178 |
|