| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit( 'Direct\'s not allowed' ); |
| 4 |
} |
| 5 |
// add View Database link to page install plugin |
| 6 |
add_filter( 'plugin_action_links_' . CF7D_PLUGIN_BASENAME, 'wpcf7db_plugin_action_links', 10, 2 ); |
| 7 |
function wpcf7db_plugin_action_links( $links, $file ) { |
| 8 |
if ( $file != CF7D_PLUGIN_BASENAME ) { |
| 9 |
return $links; |
| 10 |
} |
| 11 |
|
| 12 |
if ( ! current_user_can( 'wpcf7_read_contact_forms' ) ) { |
| 13 |
return $links; |
| 14 |
} |
| 15 |
|
| 16 |
$view_database_link = wpcf7_link( |
| 17 |
menu_page_url( 'cf7-data', false ), |
| 18 |
__( 'View Database', 'cf7-database' ) |
| 19 |
); |
| 20 |
|
| 21 |
array_unshift( $links, $view_database_link ); |
| 22 |
|
| 23 |
return $links; |
| 24 |
} |
| 25 |
|
| 26 |
// add go pro link to page install plugin |
| 27 |
add_filter( 'plugin_action_links_' . CF7D_PLUGIN_BASENAME, 'wpcf7db_plugin_action_links_gopro' ); |
| 28 |
function wpcf7db_plugin_action_links_gopro( $links ) { |
| 29 |
$links[] = '<a target="_blank" href="https://1.envato.market/Contact-Form-7-Database-GoPro" style="color: #43B854; font-weight: bold">' . __( 'Go Pro', 'cf7-database' ) . '</a>'; |
| 30 |
return $links; |
| 31 |
} |
| 32 |
// add js, css |
| 33 |
add_action( 'admin_enqueue_scripts', 'cf7d_custom_wp_admin_style' ); |
| 34 |
if ( ! function_exists( 'cf7d_custom_wp_admin_style' ) ) { |
| 35 |
function cf7d_custom_wp_admin_style( $hook_suffix ) { |
| 36 |
// Check page admin current for Language right to left. |
| 37 |
$check_page_cur = false; |
| 38 |
$is_rtl = apply_filters( 'cf7d_is_rtl', is_rtl() ); |
| 39 |
$check_character = strrpos( $hook_suffix, 'page_cf7-data' ); |
| 40 |
if ( $is_rtl == '1' && $check_character ) { |
| 41 |
$check_page_cur = true; |
| 42 |
} |
| 43 |
|
| 44 |
// $hook_suffix Check page admin current for Language left to right. |
| 45 |
if ( $hook_suffix === $GLOBALS['njt_cf7d_hook_suffix'] || $check_page_cur ) { |
| 46 |
// list formArr |
| 47 |
$forms = get_posts( |
| 48 |
array( |
| 49 |
'post_status' => 'any', |
| 50 |
'posts_per_page' => -1, |
| 51 |
'offset' => 0, |
| 52 |
'orderby' => apply_filters( 'cf7-db-forms-orderby', 'ID' ), |
| 53 |
'order' => apply_filters( 'cf7-db-forms-order', 'ASC' ), |
| 54 |
'post_type' => 'wpcf7_contact_form', |
| 55 |
) |
| 56 |
); |
| 57 |
$list_formArr = array(); |
| 58 |
foreach ( $forms as $k => $v ) { |
| 59 |
if ( ! empty( $v->ID ) ) { |
| 60 |
$list_formArr[] = array( |
| 61 |
'id_form' => $v->ID, |
| 62 |
'title_form' => $v->post_title, |
| 63 |
); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
global $wpdb; |
| 68 |
$list_field_settingArr = array(); |
| 69 |
|
| 70 |
foreach ( $list_formArr as $key_list_form => $list_form ) { |
| 71 |
$sql = sprintf( 'SELECT `name` FROM `' . $wpdb->prefix . 'cf7_data_entry` WHERE cf7_id = %d GROUP BY `name`', $list_form['id_form'] ); |
| 72 |
$data = $wpdb->get_results( $sql ); |
| 73 |
|
| 74 |
$fields = array(); |
| 75 |
foreach ( $data as $k => $v ) { |
| 76 |
$fields[ $v->name ] = $v->name; |
| 77 |
} |
| 78 |
|
| 79 |
$field_settings = get_option( 'cf7d_settings_field_' . $list_form['id_form'], array() ); |
| 80 |
if ( $field_settings == '' ) { |
| 81 |
$field_settings = array(); |
| 82 |
} |
| 83 |
|
| 84 |
if ( count( $field_settings ) == 0 ) { // no settings found |
| 85 |
foreach ( $fields as $k => $v ) { |
| 86 |
$show = 1; |
| 87 |
$label = $v; |
| 88 |
$id_form = $list_form['id_form']; |
| 89 |
$list_field_settingArr[ $id_form ][ $k ] = array( |
| 90 |
'label' => $label, |
| 91 |
'show' => $show, |
| 92 |
); |
| 93 |
} |
| 94 |
} else { |
| 95 |
foreach ( $field_settings as $k => $v ) { |
| 96 |
if ( isset( $fields[ $k ] ) ) { |
| 97 |
$show = $field_settings[ $k ]['show']; |
| 98 |
$label = $field_settings[ $k ]['label']; |
| 99 |
$id_form = $list_form['id_form']; |
| 100 |
|
| 101 |
$list_field_settingArr[ $id_form ][ $k ] = array( |
| 102 |
'label' => $label, |
| 103 |
'show' => $show, |
| 104 |
); |
| 105 |
unset( $fields[ $k ] ); |
| 106 |
} |
| 107 |
} |
| 108 |
if ( count( $fields ) > 0 ) { |
| 109 |
foreach ( $fields as $k => $v ) { |
| 110 |
$show = 1; |
| 111 |
$label = $v; |
| 112 |
$id_form = $list_form['id_form']; |
| 113 |
|
| 114 |
$list_field_settingArr[ $id_form ][ $k ] = array( |
| 115 |
'label' => $label, |
| 116 |
'show' => $show, |
| 117 |
); |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
if ( isset( $_GET['fid'] ) || ! empty( $_GET['fid'] ) ) { |
| 123 |
$fid = (int) sanitize_text_field( $_GET['fid'] ); |
| 124 |
} else { |
| 125 |
$fid = $list_formArr[0]['id_form']; |
| 126 |
} |
| 127 |
|
| 128 |
$setting_nav_arr = get_option( 'cf7d_settings_nav_table' . $fid ); |
| 129 |
$navDefault = array( |
| 130 |
'bordered' => 1, |
| 131 |
'loading' => 0, |
| 132 |
'title' => 0, |
| 133 |
'colHeader' => 1, |
| 134 |
'expandedRowRender' => 0, |
| 135 |
'checkbox' => 1, |
| 136 |
'fixedHeader' => 1, |
| 137 |
'hasData' => 1, |
| 138 |
'ellipsis' => 1, |
| 139 |
'footer' => 1, |
| 140 |
'size' => 'default', |
| 141 |
'tableScroll' => 'fixedColumn', |
| 142 |
'tableLayout' => 'unset', |
| 143 |
'paginationTop' => 'topRight', |
| 144 |
'paginationBottom' => 'bottomRight', |
| 145 |
); |
| 146 |
if ( $setting_nav_arr === false ) { |
| 147 |
$setting_nav_arr = $navDefault; |
| 148 |
add_option( 'cf7d_settings_nav_table' . $fid, cf7d_sanitize_arr( $setting_nav_arr ), '', 'no' ); |
| 149 |
} |
| 150 |
|
| 151 |
if ( is_array( $setting_nav_arr ) === false ) { |
| 152 |
$setting_nav_arr = $navDefault; |
| 153 |
} |
| 154 |
|
| 155 |
// convert to number |
| 156 |
$pro_set_navArr = array( 'bordered', 'loading', 'title', 'colHeader', 'expandedRowRender', 'checkbox', 'fixedHeader', 'hasData', 'ellipsis', 'footer' ); |
| 157 |
|
| 158 |
foreach ( $pro_set_navArr as $pro_set_nav ) { |
| 159 |
if ( isset( $setting_nav_arr[ $pro_set_nav ] ) ) { |
| 160 |
$setting_nav_arr[ $pro_set_nav ] = (int) $setting_nav_arr[ $pro_set_nav ]; |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
wp_enqueue_script( 'cf7d_apps_js', CF7D_PLUGIN_URL . '/admin/assets/dist/js/main.js', array(), '', true ); |
| 165 |
wp_localize_script( |
| 166 |
'cf7d_apps_js', |
| 167 |
'njt_cfd_data', |
| 168 |
array( |
| 169 |
'home_url' => home_url(), |
| 170 |
'cf7d_page_url' => admin_url( 'admin.php?page=cf7-data&fid=' ), |
| 171 |
'list_formArr' => $list_formArr, |
| 172 |
'list_field_settingArr' => $list_field_settingArr, |
| 173 |
'id_form_current' => $fid, |
| 174 |
'page' => 1, |
| 175 |
'per_page' => 15, |
| 176 |
'setting_nav_arr' => $setting_nav_arr, |
| 177 |
'nonce' => wp_create_nonce( 'cf7d-nonce' ), |
| 178 |
'is_rtl' => apply_filters( 'cf7d_is_rtl', is_rtl() ), |
| 179 |
'html_fields' => apply_filters( 'cf7d_html_fields', array() ), |
| 180 |
'translate' => getTranslation() |
| 181 |
) |
| 182 |
); |
| 183 |
// File css of ant design. |
| 184 |
// wp_register_style( 'cf7d_apps_css_ant', CF7D_PLUGIN_URL . '/admin/assets/css/ant/antd.min.css' ); |
| 185 |
// wp_enqueue_style( 'cf7d_apps_css_ant' ); |
| 186 |
|
| 187 |
// File css of apps. |
| 188 |
wp_register_style( 'cf7d_apps_css', CF7D_PLUGIN_URL . '/admin/assets/dist/css/main.css' ); |
| 189 |
wp_enqueue_style( 'cf7d_apps_css' ); |
| 190 |
|
| 191 |
// css for language right to left. |
| 192 |
if ( is_rtl() == '1' ) { |
| 193 |
// File support for language right to left. |
| 194 |
wp_register_style( 'cf7d_apps_css_su_rtl', CF7D_PLUGIN_URL . '/admin/assets/css/css_support_rtl.css' ); |
| 195 |
wp_enqueue_style( 'cf7d_apps_css_su_rtl' ); |
| 196 |
|
| 197 |
// File for language right to left. |
| 198 |
wp_style_add_data( 'cf7d_apps_css', 'rtl', 'replace' ); |
| 199 |
|
| 200 |
// File for language right to left. |
| 201 |
wp_style_add_data( 'cf7d_apps_css_ant', 'rtl', 'replace' ); |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
} |
| 206 |
} |
| 207 |
// add admin menu page |
| 208 |
add_action( 'admin_menu', 'cf7d_register_custom_submenu_page' ); |
| 209 |
if ( ! function_exists( 'cf7d_register_custom_submenu_page' ) ) { |
| 210 |
function cf7d_register_custom_submenu_page() { |
| 211 |
$GLOBALS['njt_cf7d_hook_suffix'] = add_submenu_page( 'wpcf7', 'Database', 'Database', apply_filters( 'cf7d_options_page_capabilities', 'manage_options' ), 'cf7-data', 'cf7d_custom_submenu_page_callback' ); |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
if ( ! function_exists( 'cf7d_custom_submenu_page_callback' ) ) { |
| 216 |
function cf7d_custom_submenu_page_callback() { |
| 217 |
?> |
| 218 |
<div id="cf7d-apps"></div> |
| 219 |
<?php |
| 220 |
} |
| 221 |
} |
| 222 |
|