Import legacy nurinda.co.id website

This commit is contained in:
dirga committed 2026-10-01 14:27:19 +07:00
1 parent 3f59bb9038
commit 6e21646ac4
13389 files changed
+3246690

No files matched your search

@@ -0,0 +1,21 @@
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
/**
* Ajax method for wooCommerce cart.
*/
add_action( 'wp_ajax_nopriv_us_ajax_cart', 'us_ajax_cart' );
add_action( 'wp_ajax_us_ajax_cart', 'us_ajax_cart' );
function us_ajax_cart() {
if ( ! class_exists( 'woocommerce' ) ) {
wp_send_json_error();
}
global $woocommerce;
$count = $woocommerce->cart->cart_contents_count;
$result = array( 'count' => $count );
wp_send_json_success( $result );
}
@@ -0,0 +1,211 @@
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
/**
* Ajax method for sending contact form via us_cform shortcode
*/
add_action( 'wp_ajax_nopriv_us_ajax_cform', 'us_ajax_cform' );
add_action( 'wp_ajax_us_ajax_cform', 'us_ajax_cform' );
function us_ajax_cform() {
$post_id = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : 0;
if ( $post_id <= 0 ) {
wp_send_json_error();
}
$post = get_post( $post_id );
if ( empty( $post ) ) {
wp_send_json_error();
}
$form_index = isset( $_POST['form_index'] ) ? intval( $_POST['form_index'] ) : 1;
// Retrieving the relevant shortcode from the page to get options
$post_content = $post->post_content;
preg_match_all( '~(\[us_cform(.*?)\])((.*?)\[/us_cform\])?~', $post_content, $matches );
if ( ! isset( $matches[0][ $form_index - 1 ] ) ) {
wp_send_json_error();
}
// Getting the relevant shortcode options
$shortcode = $matches[1][ $form_index - 1 ];
// For proper shortcode_parse_atts behaviour
$shortcode = substr_replace( $shortcode, ' ]', - 1 );
$shortcode_atts = shortcode_parse_atts( $shortcode );
// Compatibility with older versions (applying migrations)
if ( class_exists( 'US_Migration' ) ) {
foreach ( US_Migration::instance()->translators as $version => $translator ) {
if ( method_exists( $translator, 'translate_us_cform' ) ) {
$translator->translate_us_cform( 'us_cform', $shortcode_atts );
}
}
}
// Take all field types from config
$available_fields = us_config( 'elements/cform.params.items.params.type.options' );
$field_types = is_array( $available_fields ) ? array_keys( $available_fields ) : array();
// Decode shortcode items
$shortcode_items = json_decode( urldecode( $shortcode_atts['items'] ), TRUE );
$shortcode_items = $shortcode_items ? $shortcode_items : array();
// Default shortcode has no content, take it from config
if ( empty( $shortcode_items ) ) {
$shortcode_items = json_decode( urldecode( us_config( 'elements/cform.params.items.std' ) ), TRUE );
$shortcode_items = $shortcode_items ? $shortcode_items : array();
}
$sorted_fields = array();
// Sort shortcode fields
foreach ( $shortcode_items as $shortcode_item_key => $shortcode_item ) {
if ( in_array( $shortcode_item['type'], $field_types ) ) {
// Pass info field
if ( $shortcode_item['type'] == 'info' ) {
continue;
}
// Set Agreement Box and Captcha to be required
if ( $shortcode_item['type'] == 'agreement' OR $shortcode_item['type'] == 'captcha' ) {
$shortcode_item['required'] = 1;
}
$existing_fields = isset( $sorted_fields[ $shortcode_item['type'] ] ) ? $sorted_fields[ $shortcode_item['type'] ] : array();
$field_id = count( $existing_fields ) + 1;
$shortcode_item['name'] = 'us_form_' . $form_index . '_' . $shortcode_item['type'] . '_' . $field_id;
$sorted_fields[ $shortcode_item['type'] ][] = $shortcode_item;
}
}
function us_cform_is_valid_captcha( $captcha = NULL ) {
$fields = array();
foreach ( $_POST as $key => $field ) {
if ( preg_match( '~^us_form_\d_([^_]+_)\d_(\w+)$~', $key, $matches ) ) {
$fields[ $matches[1] . $matches[2] ] = $field;
} elseif ( preg_match( '~^us_form_\d_([^_]+)_\d$~', $key, $matches ) ) {
$fields[ $matches[1] ] = $field;
}
}
$captcha_hash = isset( $fields['captcha_hash'] ) ? stripslashes( $fields['captcha_hash'] ) : NULL;
if ( $captcha_hash === md5( $captcha . NONCE_SALT ) ) {
return TRUE;
}
return FALSE;
}
$errors = $headers = array();
$body_content = '';
// Validate fields and compose a message
foreach ( $sorted_fields as $sorted_field_key => $sorted_field ) {
foreach ( $sorted_field as $field ) {
$name = isset( $field['name'] ) ? $field['name'] : '';
$field_type = isset( $field['type'] ) ? $field['type'] : '';
// Validate fields
if ( isset( $field['required'] ) ) {
// Validate Captcha
if ( $field_type == 'captcha' ) {
$captcha = isset( $_POST[ $name ] ) ? esc_attr( $_POST[ $name ] ) : NULL;
if ( ! us_cform_is_valid_captcha( $captcha ) ) {
if ( ! empty( $name ) ) {
$errors[ $field['type'] ]['name'][] = $name;
}
}
} elseif ( ! isset( $_POST[ $name ] ) OR ( isset( $_POST[ $name ] ) AND empty( $_POST[ $name ] ) ) ) {
if ( ! empty( $name ) ) {
$errors[ $field['type'] ]['name'][] = $name;
}
}
}
$email_content = isset( $_POST[ $name ] ) ? $_POST[ $name ] : '';
$skipped_fields = array(
'captcha',
);
// Skip empty and skipped fields
if ( empty( $email_content ) OR in_array( $field_type, $skipped_fields ) ) {
continue;
}
// Take message body
if ( $field['type'] == 'agreement' AND ! empty( $field['value'] ) ) {
$agreement = '<p>' . __( 'The sender has given his consent.', 'us' ) . '<br>';
$agreement .= __( 'Agreement text', 'us' ) . ': <strong>' . strip_tags( $field['value'], '<a>' ) . '</strong><br>';
$agreement .= __( 'Agreement date and time', 'us' ) . ': <strong>' . gmdate( 'Y-m-d H:i:s' ) . ' GMT</strong><br>';
$agreement .= __( 'IP address', 'us' ) . ': <strong>' . us_get_ip() . '</strong></p>';
} else {
$body_content .= '<p>';
if ( ! empty( $field['label'] ) ) {
$body_content .= sanitize_text_field( $field['label'] ) . ':<br>';
} elseif ( ! empty( $field['placeholder'] ) ) {
$body_content .= sanitize_text_field( $field['placeholder'] ) . ':<br>';
}
if ( is_array( $email_content ) ) {
$values_length = count( $email_content );
$counter = 0;
foreach ( $email_content as $value ) {
$body_content .= '<strong>' . sanitize_text_field( stripslashes( $value ) ) . '</strong>';
$counter ++;
if ( $counter < $values_length ) {
$body_content .= '<br>';
}
}
} elseif ( $field['type'] == 'email' ) {
$body_content .= '<strong>' . sanitize_email( stripslashes( $email_content ) ) . '</strong>';
$headers[] = 'Reply-To: ' . sanitize_email( stripslashes( $email_content ) );
} else {
$body_content .= '<strong>' . sanitize_text_field( stripslashes( $email_content ) ) . '</strong>';
}
$body_content .= '</p>';
}
}
}
if ( ! empty( $errors ) ) {
wp_send_json_error( $errors );
}
// Get email receiver
$email_to = get_option( 'admin_email' );
if ( ! empty( $shortcode_atts['receiver_email'] ) ) {
$email_to = array_map( 'sanitize_email', explode( ',', $shortcode_atts['receiver_email'] ) );
}
$email_body = '<p>' . __( 'You received a message from', 'us' ) . ' <a href="' . site_url() . '">' . get_bloginfo( 'name' ) . '</a></p>';
$email_body .= $body_content;
if ( isset( $agreement ) ) {
$email_body .= $agreement;
}
$email_subject = sprintf( __( 'Message from %s', 'us' ), get_bloginfo( 'name' ) );
if ( empty( $body_content ) ) {
wp_send_json_error( __( 'Cannot send empty message. Please fill any of the fields.', 'us' ) );
}
if ( is_rtl() ) {
$email_body = '<div style="direction: rtl; unicode-bidi: embed;">' . $email_body . '</div>';
}
add_filter( 'wp_mail_content_type', 'us_set_html_content_type' );
function us_set_html_content_type() {
return 'text/html';
}
// Send attempt
$success = wp_mail( $email_to, $email_subject, $email_body, $headers );
if ( $success ) {
if ( isset( $shortcode_atts['success_message'] ) AND ! empty( $shortcode_atts['success_message'] ) ) {
$success_message = trim( strip_tags( $shortcode_atts['success_message'], '<a><br><strong>' ) );
} else {
$success_message = us_config( 'elements/cform.params.success_message.std' );
}
wp_send_json_success( $success_message );
} else {
wp_send_json_error( __( 'Cannot send the message. Please contact the website administrator.', 'us' ) );
}
}
@@ -0,0 +1,187 @@
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
/**
* Ajax method for grids ajax pagination.
*/
add_action( 'wp_ajax_nopriv_us_ajax_grid', 'us_ajax_grid' );
add_action( 'wp_ajax_us_ajax_grid', 'us_ajax_grid' );
function us_ajax_grid() {
if ( class_exists( 'WPBMap' ) AND method_exists( 'WPBMap', 'addAllMappedShortcodes' ) ) {
WPBMap::addAllMappedShortcodes();
}
// Filtering $template_vars, as is will be extracted to the template as local variables
$template_vars = shortcode_atts(
array(
'query_args' => array(),
'post_id' => FALSE,
'us_grid_index' => FALSE,
'us_grid_ajax_index' => FALSE,
'exclude_items' => 'none',
'items_offset' => 0,
'items_layout' => 'blog_1',
'type' => 'grid',
'columns' => 2,
'img_size' => 'default',
'lang' => FALSE,
'overriding_link' => 'none',
), us_maybe_get_post_json( 'template_vars' )
);
if ( class_exists( 'SitePress' ) AND $template_vars['lang'] ) {
global $sitepress;
$sitepress->switch_lang( $template_vars['lang'] );
}
$post_id = isset( $template_vars['post_id'] ) ? intval( $template_vars['post_id'] ) : 0;
if ( $post_id > 0 ) {
$post = get_post( $post_id );
if ( empty( $post ) ) {
wp_send_json_error();
}
$us_grid_ajax_index = isset( $template_vars['us_grid_ajax_index'] ) ? intval( $template_vars['us_grid_ajax_index'] ) : 1;
// Retrieving the relevant shortcode from the page to get options
$post_content = $post->post_content;
preg_match_all( '~\[us_grid(.*?)\]~', $post_content, $matches );
if ( ! isset( $matches[0][ $us_grid_ajax_index - 1 ] ) ) {
wp_send_json_error();
}
// Getting the relevant shortcode options
$shortcode = $matches[0][ $us_grid_ajax_index - 1 ];
// For proper shortcode_parse_atts behaviour
$shortcode = substr_replace( $shortcode, ' ]', - 1 );
$shortcode_atts = shortcode_parse_atts( $shortcode );
$shortcode_atts = shortcode_atts(
array(
'post_type' => '',
), $shortcode_atts
);
if ( $shortcode_atts['post_type'] == '' ) {
$shortcode_atts['post_type'] = 'post';
}
$allowed_post_types = ( $shortcode_atts['post_type'] == 'current_query' ) ? NULL : array( $shortcode_atts['post_type'] );
if ( $shortcode_atts['post_type'] == 'current_query'
AND $template_vars['query_args']['post_type'] == 'product'
AND ! empty( $template_vars['query_args']['orderby'] ) ) {
$add_wc_hooks = TRUE;
}
}
// Filtering query_args
if ( isset( $template_vars['query_args'] ) AND is_array( $template_vars['query_args'] ) ) {
// Query Args keys, that won't be filtered
$allowed_query_keys = array(
// Grid listing shortcode requests
'author_name',
'us_portfolio_category',
'us_portfolio_tag',
'category_name',
'tax_query',
// Archive requests
'year',
'monthnum',
'day',
'cat',
'tag',
'product_cat',
'product_tag',
// Search requests
's',
// Pagination
'paged',
'order',
'orderby',
'posts_per_page',
'post__not_in',
'post__in',
// For excluding 'out of stock' products
'meta_query',
// For products sorting
'order',
'meta_key',
// Custom users' queries
'post_type',
);
$public_cpt = array_keys( us_get_public_cpt() );
if ( ! isset( $allowed_post_types ) OR ! is_array( $allowed_post_types ) ) {
// TODO: make static part of this list to be detected dynamically
$allowed_post_types = array_merge(
array( 'us_portfolio', 'post', 'attachment', 'page', 'product' ), $public_cpt
);
}
foreach ( $template_vars['query_args'] as $query_key => $query_val ) {
if ( ! in_array( $query_key, $allowed_query_keys ) ) {
unset( $template_vars['query_args'][ $query_key ] );
}
}
if ( isset( $template_vars['query_args']['post_type'] ) ) {
$is_allowed_post_type = TRUE;
if ( is_array( $template_vars['query_args']['post_type'] ) ) {
foreach ( $template_vars['query_args']['post_type'] as $post_type ) {
if ( ! in_array( $post_type, $allowed_post_types ) ) {
$is_allowed_post_type = FALSE;
break;
}
}
} elseif ( ! in_array( $template_vars['query_args']['post_type'], $allowed_post_types ) ) {
$is_allowed_post_type = FALSE;
}
if ( ! $is_allowed_post_type ) {
unset( $template_vars['query_args']['post_type'] );
}
}
if ( ! isset( $template_vars['query_args']['s'] ) AND ! isset( $template_vars['query_args']['post_type'] ) ) {
$template_vars['query_args']['post_type'] = 'post';
}
// Providing proper post statuses
if ( ! empty( $post_type ) AND ( $template_vars['query_args']['post_type'] == 'attachment' ) OR ( is_array( $template_vars['query_args']['post_type'] ) AND in_array( 'attachment', $template_vars['query_args']['post_type'] ) AND count( $template_vars['query_args']['post_type'] ) == 1 ) ) {
$template_vars['query_args']['post_status'] = 'inherit';
$template_vars['query_args']['post_mime_type'] = 'image';
} else {
$template_vars['query_args']['post_status'] = array( 'publish' => 'publish' );
$template_vars['query_args']['post_status'] += (array) get_post_stati( array( 'public' => TRUE ) );
// Add private states if user is capable to view them
if ( is_user_logged_in() AND current_user_can( 'read_private_posts' ) ) {
$template_vars['query_args']['post_status'] += (array) get_post_stati( array( 'private' => TRUE ) );
}
$template_vars['query_args']['post_status'] = array_values( $template_vars['query_args']['post_status'] );
}
// Exclude sticky posts from rand query after 1 page
if ( isset( $template_vars['query_args']['orderby'] ) AND ! ( is_array( $template_vars['query_args']['orderby'] ) ) ) {
if ( ( substr( $template_vars['query_args']['orderby'], 0, 4 ) == 'rand' ) AND ( $template_vars['query_args']['paged'] > '1' ) ) {
$sticky_posts = get_option( 'sticky_posts' );
$template_vars['query_args']['ignore_sticky_posts'] = TRUE;
foreach ( $sticky_posts as $post_id ) {
$template_vars['query_args']['post__not_in'][] = $post_id;
}
}
}
}
// Passing values that were filtered due to post protocol
global $us_grid_loop_running;
$us_grid_loop_running = TRUE;
// Apply WooCommerce product ordering if set
if ( ! empty( $add_wc_hooks ) AND class_exists( 'woocommerce' ) AND is_object( wc() ) ) {
$_GET['orderby'] = $template_vars['query_args']['orderby'];
add_action( 'pre_get_posts', array( wc()->query, 'product_query' ) );
}
us_load_template( 'templates/us_grid/listing', $template_vars );
$us_grid_loop_running = FALSE;
// We don't use JSON to reduce data size
die;
}
@@ -0,0 +1,142 @@
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
/**
* Load elements list HTML to choose from
*/
add_action( 'wp_ajax_usgb_get_elist_html', 'ajax_usgb_get_elist_html' );
function ajax_usgb_get_elist_html() {
us_load_template( 'templates/elist', array(
'elements' => us_config( 'grid-settings.elements', array() ),
) );
// We don't use JSON to reduce data size
die;
}
/**
* Load shortcode builder elements forms
*/
add_action( 'wp_ajax_usgb_get_ebuilder_html', 'ajax_usgb_get_ebuilder_html' );
function ajax_usgb_get_ebuilder_html() {
$template_vars = array(
'titles' => array(),
'body' => '',
);
// Loading all the forms HTML
foreach ( us_config( 'grid-settings.elements', array() ) as $type ) {
$elm = us_config( 'elements/' . $type, array() );
$template_vars['titles'][ $type ] = isset( $elm['title'] ) ? $elm['title'] : $type;
$template_vars['body'] .= us_get_template( 'templates/eform', array(
'type' => $type,
'params' => $elm['params'],
'context' => 'grid',
) );
}
us_load_template( 'templates/ebuilder', $template_vars );
// We don't use JSON to reduce data size
die;
}
/**
* Load grid template selector forms
*/
add_action( 'wp_ajax_usgb_get_gtemplates_html', 'ajax_usgb_get_gtemplates_html' );
function ajax_usgb_get_gtemplates_html() {
us_load_template( 'templates/gtemplates' );
// We don't use JSON to reduce data size
die;
}
/**
* Save header
*/
add_action( 'wp_ajax_usgb_save', 'ajax_usgb_save' );
function ajax_usgb_save() {
$post = array(
'ID' => isset( $_POST['ID'] ) ? intval( $_POST['ID'] ) : NULL,
'post_title' => isset( $_POST['post_title'] ) ? $_POST['post_title'] : NULL,
'post_content' => isset( $_POST['post_content'] ) ? $_POST['post_content'] : NULL,
);
if ( ! check_admin_referer( 'usgb-update' ) OR ! current_user_can( 'edit_post', $post['ID'] ) ) {
wp_send_json_error(
array(
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
)
);
}
if ( ! $post['ID'] ) {
wp_send_json_error(
array(
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
)
);
}
if ( wp_update_post( $post ) !== $post['ID'] ) {
wp_send_json_error(
array(
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
)
);
}
wp_send_json_success(
array(
'message' => us_translate( 'Changes saved.' ),
)
);
}
add_action( 'wp_ajax_usgb_add_group_params', 'usgb_ajax_add_group_params' );
function usgb_ajax_add_group_params() {
$element = sanitize_text_field( $_POST['element'] );
$group = sanitize_text_field( $_POST['group'] );
$index = sanitize_text_field( $_POST['index'] );
$config = us_config( 'grid-settings', array() );
$element_config = us_config( 'elements/' . $element );
if ( isset( $element_config['params'][$group] ) ) {
$field = $element_config['params'][$group];
$result_html = '<div class="usof-form-group-item">';
$result_html .= '<div class="usof-form-group-item-content">';
ob_start();
foreach ( $field['params'] as $param_name => $param ) {
if ( isset( $param['show_if'] ) AND is_array( $param['show_if'] ) ) {
$param['show_if'][0] = $group . '_' . $index . '_' . $param['show_if'][0];
}
us_load_template(
'vendor/usof/templates/field', array(
'name' => $group . '_' . $index . '_' . $param_name,
'id' => 'usof_' . $group . '_' . $index . '_' . $param_name,
'field' => $param,
'values' => array(),
)
);
}
$result_html .= ob_get_clean();
$result_html .= '</div>';
$result_html .= '<div class="usof-form-group-delete" title="' . us_translate( 'Delete' ) . '"></div>';
$result_html .= '</div>';
wp_send_json_success(
array(
'paramsHtml' => $result_html,
)
);
} else {
wp_send_json_error(
array(
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
)
);
}
}
@@ -0,0 +1,57 @@
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
/**
* Ajax methods for us_login widget
*/
add_action( 'wp_ajax_nopriv_us_ajax_user_info', 'us_ajax_user_info' );
add_action( 'wp_ajax_us_ajax_user_info', 'us_ajax_user_info' );
function us_ajax_user_info() {
if ( ! is_user_logged_in() ) {
wp_send_json_error();
}
$current_user = wp_get_current_user();
$logout_redirect = ( isset( $_POST['logout_redirect'] ) ) ? $_POST['logout_redirect'] : '';
$logout_redirect = str_replace( '&amp;', '&', wp_logout_url( esc_url( $logout_redirect ) ) );
$result = array(
'name' => $current_user->display_name,
'avatar' => get_avatar( get_current_user_id(), '64' ),
'logout_url' => $logout_redirect,
);
wp_send_json_success( $result );
}
if ( ! is_user_logged_in() ) {
add_action( 'wp_ajax_nopriv_us_ajax_login', 'us_ajax_login' );
add_action( 'wp_ajax_us_ajax_login', 'us_ajax_login' );
}
function us_ajax_login() {
// Check form nonce
check_ajax_referer( 'us_ajax_login_nonce', 'us_login_nonce' );
// Get form data
$info = array(
'user_login' => sanitize_user( $_POST['username'] ),
'user_password' => strip_tags( $_POST['password'] ),
'remember' => TRUE,
);
// Logging
$user_signon = wp_signon( $info, is_ssl() );
$message = $user_signon->get_error_message();
$error_code = $user_signon->get_error_code();
// Format error message to cut a link and leading ERROR, NOTICE etc words
$pattern = '#^(<strong>[^>]+>:\s)?((?:(?! <a href).)+)([\s\S]+)#i';
$message = ucfirst( preg_replace( $pattern, '$2', $message ) );
$result = array(
'message' => $message,
'code' => $error_code,
);
if ( is_wp_error( $user_signon ) ) {
wp_send_json_error( $result );
} else {
wp_send_json_success();
}
}