| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Client Info Widget |
| 4 |
* |
| 5 |
* Displays the Client Info. |
| 6 |
* |
| 7 |
* @package MainWP/MainWP_Client_Info |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace MainWP\Dashboard; |
| 11 |
|
| 12 |
/** |
| 13 |
* Class MainWP_Client_Info |
| 14 |
* |
| 15 |
* Displays the Client info. |
| 16 |
*/ |
| 17 |
class MainWP_Client_Info { //phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR - complexity. |
| 18 |
|
| 19 |
/** |
| 20 |
* Method get_class_name() |
| 21 |
* |
| 22 |
* @return string __CLASS__ Class name. |
| 23 |
*/ |
| 24 |
public static function get_class_name() { |
| 25 |
return __CLASS__; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Method render() |
| 30 |
* |
| 31 |
* @return mixed render_site_info() |
| 32 |
*/ |
| 33 |
public static function render() { |
| 34 |
static::render_site_info(); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Method render_site_info() |
| 39 |
* |
| 40 |
* Grab Child Site Info and render. |
| 41 |
* |
| 42 |
* @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() |
| 43 |
* @uses \MainWP\Dashboard\MainWP_DB::get_website_option() |
| 44 |
* @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid() |
| 45 |
* @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() |
| 46 |
*/ |
| 47 |
public static function render_site_info() { |
| 48 |
$current_wpid = MainWP_System_Utility::get_current_wpid(); |
| 49 |
if ( empty( $current_wpid ) ) { |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
$website = MainWP_DB::instance()->get_website_by_id( $current_wpid, true ); |
| 54 |
|
| 55 |
static::render_info( $website ); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Render Sites Info. |
| 60 |
* |
| 61 |
* @param object $website Object containing the child site info. |
| 62 |
*/ |
| 63 |
public static function render_info( $website ) { //phpcs:ignore -- NOSONAR - complex. |
| 64 |
|
| 65 |
$client_info = $website->client_id ? MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $website->client_id, ARRAY_A ) : false; |
| 66 |
|
| 67 |
?> |
| 68 |
<h3 class="ui header handle-drag"> |
| 69 |
<?php |
| 70 |
/** |
| 71 |
* Filter: mainwp_clients_info_widget_title |
| 72 |
* |
| 73 |
* Filters the Site info widget title text. |
| 74 |
* |
| 75 |
* @param object $website Object containing the child site info. |
| 76 |
* |
| 77 |
* @since 4.1 |
| 78 |
*/ |
| 79 |
echo esc_html( apply_filters( 'mainwp_clients_info_widget_title', esc_html__( 'Client Info', 'mainwp' ), $website ) ); |
| 80 |
?> |
| 81 |
<div class="sub header"><?php esc_html_e( 'Client Information', 'mainwp' ); ?></div> |
| 82 |
</h3> |
| 83 |
<div class="mainwp-widget-site-info mainwp-scrolly-overflow"> |
| 84 |
<?php |
| 85 |
/** |
| 86 |
* Actoin: mainwp_clients_info_widget_top |
| 87 |
* |
| 88 |
* Fires at the top of the Site Info widget on the Individual site overview page. |
| 89 |
* |
| 90 |
* @param object $website Object containing the child site info. |
| 91 |
* |
| 92 |
* @since 4.0 |
| 93 |
*/ |
| 94 |
do_action( 'mainwp_clients_info_widget_top', $website ); |
| 95 |
?> |
| 96 |
<?php |
| 97 |
if ( $client_info ) { |
| 98 |
$default_client_fields = MainWP_Client_Handler::get_default_client_fields(); |
| 99 |
$custom_fields = MainWP_DB_Client::instance()->get_client_fields( true, $website->client_id ); |
| 100 |
|
| 101 |
?> |
| 102 |
<table class="ui celled striped table"> |
| 103 |
<tbody> |
| 104 |
<?php |
| 105 |
/** |
| 106 |
* Action: mainwp_clients_info_table_top |
| 107 |
* |
| 108 |
* Fires at the top of the Site Info table in Site Info widget on the Individual site overview page. |
| 109 |
* |
| 110 |
* @param object $website Object containing the child site info. |
| 111 |
* |
| 112 |
* @since 4.0 |
| 113 |
*/ |
| 114 |
do_action( 'mainwp_clients_info_table_top', $website ); |
| 115 |
?> |
| 116 |
<?php |
| 117 |
|
| 118 |
foreach ( $default_client_fields as $field ) { |
| 119 |
|
| 120 |
$db_field = isset( $field['db_field'] ) ? $field['db_field'] : ''; |
| 121 |
$val = ( ! empty( $db_field ) && isset( $client_info[ $db_field ] ) ) ? $client_info[ $db_field ] : ''; |
| 122 |
|
| 123 |
if ( empty( $val ) ) { |
| 124 |
continue; |
| 125 |
} |
| 126 |
|
| 127 |
?> |
| 128 |
<tr> |
| 129 |
<td><?php echo esc_html( $field['title'] ); ?></td> |
| 130 |
<td> |
| 131 |
<?php |
| 132 |
if ( 'name' === $db_field ) { |
| 133 |
?> |
| 134 |
<a class="item" href="admin.php?page=ClientAddNew&client_id=<?php echo intval( $client_info['client_id'] ); ?>"><?php echo esc_html( $client_info['name'] ); ?></a> |
| 135 |
<?php |
| 136 |
} elseif ( 'email' === $db_field ) { |
| 137 |
?> |
| 138 |
<a class="item" href="admin.php?page=ClientAddNew&client_id=<?php echo intval( $client_info['client_id'] ); ?>"><?php echo esc_html( $client_info['email'] ); ?></a> |
| 139 |
<?php |
| 140 |
|
| 141 |
} elseif ( 'created' === $db_field ) { |
| 142 |
?> |
| 143 |
<?php echo MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( esc_html( $client_info['created'] ) ) ); //phpcs:ignore ?> |
| 144 |
<?php |
| 145 |
|
| 146 |
} elseif ( 'note' === $db_field ) { |
| 147 |
$note = html_entity_decode( $client_info['note'] ); |
| 148 |
$esc_note = MainWP_Utility::esc_content( $note ); |
| 149 |
$strip_note = wp_strip_all_tags( $esc_note ); |
| 150 |
|
| 151 |
if ( empty( $client_info['note'] ) ) : |
| 152 |
?> |
| 153 |
<a href="javascript:void(0)" class="mainwp-edit-client-note" id="mainwp-notes-<?php echo intval( $client_info['client_id'] ); ?>" data-tooltip="<?php esc_attr_e( 'Edit client notes.', 'mainwp' ); ?>" data-position="left center" data-inverted=""><i class="sticky note outline icon"></i></a> |
| 154 |
<?php else : ?> |
| 155 |
<a href="javascript:void(0)" class="mainwp-edit-client-note" id="mainwp-notes-<?php echo intval( $client_info['client_id'] ); ?>" data-tooltip="<?php echo substr( wp_unslash( $strip_note ), 0, 100 ); // phpcs:ignore WordPress.Security.EscapeOutput ?>" data-position="left center" data-inverted=""><i class="sticky green note icon"></i></a> |
| 156 |
<?php endif; ?> |
| 157 |
<span style="display: none" id="mainwp-notes-<?php echo intval( $client_info['client_id'] ); ?>-note"><?php echo wp_unslash( $esc_note ); // phpcs:ignore WordPress.Security.EscapeOutput ?></span> |
| 158 |
<?php |
| 159 |
} else { |
| 160 |
echo esc_html( $val ); |
| 161 |
} |
| 162 |
|
| 163 |
?> |
| 164 |
</td> |
| 165 |
</tr> |
| 166 |
<?php } ?> |
| 167 |
|
| 168 |
<?php |
| 169 |
|
| 170 |
if ( is_array( $custom_fields ) && ! empty( $custom_fields ) ) { |
| 171 |
foreach ( $custom_fields as $field ) { |
| 172 |
if ( empty( $field->field_value ) ) { |
| 173 |
continue; |
| 174 |
} |
| 175 |
?> |
| 176 |
<tr> |
| 177 |
<td><?php echo esc_html( $field->field_desc ); ?></td> |
| 178 |
<td><?php echo esc_html( $field->field_value ); ?></td> |
| 179 |
</tr> |
| 180 |
<?php |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
?> |
| 185 |
<?php |
| 186 |
/** |
| 187 |
* Action: mainwp_clients_info_table_bottom |
| 188 |
* |
| 189 |
* Fires at the bottom of the Site Info table in Site Info widget on the Individual site overview page. |
| 190 |
* |
| 191 |
* @param object $website Object containing the child site info. |
| 192 |
* |
| 193 |
* @since 4.0 |
| 194 |
*/ |
| 195 |
do_action( 'mainwp_clients_info_table_bottom', $website ); |
| 196 |
?> |
| 197 |
</tbody> |
| 198 |
</table> |
| 199 |
<?php |
| 200 |
} else { |
| 201 |
MainWP_UI::render_empty_element_placeholder(); |
| 202 |
} |
| 203 |
?> |
| 204 |
<?php |
| 205 |
/** |
| 206 |
* Action: mainwp_clients_info_widget_bottom |
| 207 |
* |
| 208 |
* Fires at the bottom of the Site Info widget on the Individual site overview page. |
| 209 |
* |
| 210 |
* @param object $website Object containing the child site info. |
| 211 |
* |
| 212 |
* @since 4.0 |
| 213 |
*/ |
| 214 |
do_action( 'mainwp_clients_info_widget_bottom', $website ); |
| 215 |
?> |
| 216 |
</div> |
| 217 |
<div class="ui stackable two columns grid mainwp-widget-footer"> |
| 218 |
<div class="middle aligned column"> |
| 219 |
<?php if ( $client_info ) { ?> |
| 220 |
<a href="admin.php?page=ClientAddNew&client_id=<?php echo intval( $client_info['client_id'] ); ?>" title="" class="ui mini fluid button green basic"><?php echo esc_html__( 'Edit Client', 'mainwp' ); ?></a> |
| 221 |
<?php } ?> |
| 222 |
</div> |
| 223 |
<div class="middle aligned column"> |
| 224 |
<a href="admin.php?page=ClientAddNew" title="" class="ui mini fluid button green"><?php echo esc_html__( 'Add New Client', 'mainwp' ); ?></a> |
| 225 |
</div> |
| 226 |
</div> |
| 227 |
<?php |
| 228 |
} |
| 229 |
} |
| 230 |
|