From 79aea38c699d6aa1647c44bc913ce3488dc493a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9EAndrei?= Date: Mon, 26 May 2025 10:24:06 +0300 Subject: [PATCH] fix --- .../modules/footer/module-controller.php | 375 +++++++++--------- .../templates/front-page/front-page.twig | 1 - .../themes/cosmopet/templates/pet-card.twig | 296 ++------------ .../cosmopet/templates/profile/profile.twig | 308 +++++++++++++- 4 files changed, 532 insertions(+), 448 deletions(-) diff --git a/wp-content/themes/cosmopet/modules/footer/module-controller.php b/wp-content/themes/cosmopet/modules/footer/module-controller.php index e1d0f4a..82f4e99 100644 --- a/wp-content/themes/cosmopet/modules/footer/module-controller.php +++ b/wp-content/themes/cosmopet/modules/footer/module-controller.php @@ -1,188 +1,189 @@ -Hello, {$first_name} {$last_name}!"; - } else { - $html = "

Hello, {$first_name} {$last_name}!

"; - } - if (isset($tg_user['photo_url'])) { - $photo_url = htmlspecialchars($tg_user['photo_url']); - $html .= ""; - } - $html .= "

Log out

"; - } else { - $bot_username = BOT_USERNAME; - $html = ''; - } - if(!is_user_logged_in()) { - echo $html; - } -} - -add_action( 'wp_ajax_ontelegramauth', 'onTelegramAuth' ); -add_action( 'wp_ajax_nopriv_ontelegramauth', 'onTelegramAuth' ); - -function onTelegramAuth(){ - $tg_id = $_POST['userid']; - $tg_username = $_POST['username']; - $user = get_users( - array( - 'meta_key' => 'tg_account', - 'meta_value' => $tg_id - ) - ); - // $user = get_users( - // array( - // 'meta_key' => 'tg_username', - // 'meta_value' => $tg_username - // ) - // ); - - // Генерация пароля - $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@#!()'; - $pass = array(); - $alphaLength = strlen($alphabet) - 1; - for ($i = 0; $i < 12; $i++) { - $n = rand(0, $alphaLength); - $pass[] = $alphabet[$n]; - } - $pass = implode($pass); - - if($user) { - $user_login = $user[0]->data->user_login; - $user_id = get_user_by( 'login', $user_login )->ID; - wp_set_password( $pass, get_user_by( 'login', $user_login )->ID ); - wp_signon( - array( - 'user_login' => $user_login, - 'user_password' => $pass, - 'remember' => 'on', - ) - ); - } else { - $user_id = wp_create_user( $tg_username, $pass, ''); - add_user_meta( $user_id, 'tg_account', $tg_id); - add_user_meta( $user_id, 'tg_username', $tg_username); - wp_update_user( [ - 'ID' => $user_id, - 'first_name' => $_POST['fname'], - 'last_name' => $_POST['lname'] - ] ); - wp_set_auth_cookie( $user_id, true ); - } - -} - -add_action( 'wp_ajax_linktelegram', 'linkTelegram' ); -add_action( 'wp_ajax_nopriv_linktelegram', 'linkTelegram' ); - -function linkTelegram(){ - $tg_id = $_POST['userid']; - $user_id = get_current_user_id(); - - add_user_meta( $user_id, 'tg_account', $tg_id); - wp_update_user( [ - 'ID' => $user_id, - 'first_name' => $_POST['fname'], - 'last_name' => $_POST['lname'] - ] ); -} - -add_action( 'wp_ajax_email_link', 'emailLink' ); -add_action( 'wp_ajax_nopriv_email_link', 'emailLink' ); -function emailLink(){ - - $email = $_POST['email']; - $user_id = get_current_user_id(); - - if(email_exists($email)){ - header("Content-Type: application/json"); - echo json_encode(array( - 'error' => esc_html__( 'Email is already registered', 'woodmart' ) - )); - exit(); - } else { - wp_update_user( [ - 'ID' => $user_id, - 'user_email' => $email - ] ); - } - - -} - - - -// Добавляем колонку Telegram в список пользователей -add_filter('manage_users_columns', 'add_tg_account_column'); -function add_tg_account_column($columns) { - $columns['tg_username'] = 'Telegram'; - return $columns; -} - -// Заполняем колонку данными -add_filter('manage_users_custom_column', 'add_tg_account_column_content', 10, 3); -function add_tg_account_column_content($value, $column_name, $user_id) { - if ('tg_username' == $column_name) { - $tg_account = get_user_meta($user_id, 'tg_username', true); - if ($tg_account) { - return '@' . esc_html($tg_account) . ''; - } - return 'не указан'; - } - return $value; -} - -// Делаем колонку сортируемой -add_filter('manage_users_sortable_columns', 'make_tg_account_column_sortable'); -function make_tg_account_column_sortable($columns) { - $columns['tg_username'] = 'tg_username'; - return $columns; -} - -// Обрабатываем сортировку -add_action('pre_get_users', 'handle_tg_account_sorting'); -function handle_tg_account_sorting($query) { - if (!is_admin() || !$query->is_main_query()) { - return; - } - - if ('tg_username' === $query->get('orderby')) { - $query->set('meta_key', 'tg_username'); - $query->set('orderby', 'meta_value'); - } -} - +<<<<<<< Updated upstream +Hello, {$first_name} {$last_name}!"; + } else { + $html = "

Hello, {$first_name} {$last_name}!

"; + } + if (isset($tg_user['photo_url'])) { + $photo_url = htmlspecialchars($tg_user['photo_url']); + $html .= ""; + } + $html .= "

Log out

"; + } else { + $bot_username = BOT_USERNAME; + $html = ''; + } + if(!is_user_logged_in()) { + echo $html; + } +} + +add_action( 'wp_ajax_ontelegramauth', 'onTelegramAuth' ); +add_action( 'wp_ajax_nopriv_ontelegramauth', 'onTelegramAuth' ); + +function onTelegramAuth(){ + $tg_id = $_POST['userid']; + $tg_username = $_POST['username']; + $user = get_users( + array( + 'meta_key' => 'tg_account', + 'meta_value' => $tg_id + ) + ); + // $user = get_users( + // array( + // 'meta_key' => 'tg_username', + // 'meta_value' => $tg_username + // ) + // ); + + // Генерация пароля + $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@#!()'; + $pass = array(); + $alphaLength = strlen($alphabet) - 1; + for ($i = 0; $i < 12; $i++) { + $n = rand(0, $alphaLength); + $pass[] = $alphabet[$n]; + } + $pass = implode($pass); + + if($user) { + $user_login = $user[0]->data->user_login; + $user_id = get_user_by( 'login', $user_login )->ID; + wp_set_password( $pass, get_user_by( 'login', $user_login )->ID ); + wp_signon( + array( + 'user_login' => $user_login, + 'user_password' => $pass, + 'remember' => 'on', + ) + ); + } else { + $user_id = wp_create_user( $tg_username, $pass, ''); + add_user_meta( $user_id, 'tg_account', $tg_id); + add_user_meta( $user_id, 'tg_username', $tg_username); + wp_update_user( [ + 'ID' => $user_id, + 'first_name' => $_POST['fname'], + 'last_name' => $_POST['lname'] + ] ); + wp_set_auth_cookie( $user_id, true ); + } + +} + +add_action( 'wp_ajax_linktelegram', 'linkTelegram' ); +add_action( 'wp_ajax_nopriv_linktelegram', 'linkTelegram' ); + +function linkTelegram(){ + $tg_id = $_POST['userid']; + $user_id = get_current_user_id(); + + add_user_meta( $user_id, 'tg_account', $tg_id); + wp_update_user( [ + 'ID' => $user_id, + 'first_name' => $_POST['fname'], + 'last_name' => $_POST['lname'] + ] ); +} + +add_action( 'wp_ajax_email_link', 'emailLink' ); +add_action( 'wp_ajax_nopriv_email_link', 'emailLink' ); +function emailLink(){ + + $email = $_POST['email']; + $user_id = get_current_user_id(); + + if(email_exists($email)){ + header("Content-Type: application/json"); + echo json_encode(array( + 'error' => esc_html__( 'Email is already registered', 'woodmart' ) + )); + exit(); + } else { + wp_update_user( [ + 'ID' => $user_id, + 'user_email' => $email + ] ); + } + + +} + + + +// Добавляем колонку Telegram в список пользователей +add_filter('manage_users_columns', 'add_tg_account_column'); +function add_tg_account_column($columns) { + $columns['tg_username'] = 'Telegram'; + return $columns; +} + +// Заполняем колонку данными +add_filter('manage_users_custom_column', 'add_tg_account_column_content', 10, 3); +function add_tg_account_column_content($value, $column_name, $user_id) { + if ('tg_username' == $column_name) { + $tg_account = get_user_meta($user_id, 'tg_username', true); + if ($tg_account) { + return '@' . esc_html($tg_account) . ''; + } + return 'не указан'; + } + return $value; +} + +// Делаем колонку сортируемой +add_filter('manage_users_sortable_columns', 'make_tg_account_column_sortable'); +function make_tg_account_column_sortable($columns) { + $columns['tg_username'] = 'tg_username'; + return $columns; +} + +// Обрабатываем сортировку +add_action('pre_get_users', 'handle_tg_account_sorting'); +function handle_tg_account_sorting($query) { + if (!is_admin() || !$query->is_main_query()) { + return; + } + + if ('tg_username' === $query->get('orderby')) { + $query->set('meta_key', 'tg_username'); + $query->set('orderby', 'meta_value'); + } +} + ?> \ No newline at end of file diff --git a/wp-content/themes/cosmopet/templates/front-page/front-page.twig b/wp-content/themes/cosmopet/templates/front-page/front-page.twig index 98865e0..cd2f9f6 100644 --- a/wp-content/themes/cosmopet/templates/front-page/front-page.twig +++ b/wp-content/themes/cosmopet/templates/front-page/front-page.twig @@ -6,7 +6,6 @@ {% block content %}
-

FOOD OF THE FUTURE FOR YOUR PET

diff --git a/wp-content/themes/cosmopet/templates/pet-card.twig b/wp-content/themes/cosmopet/templates/pet-card.twig index 43d7fa3..f1d642c 100644 --- a/wp-content/themes/cosmopet/templates/pet-card.twig +++ b/wp-content/themes/cosmopet/templates/pet-card.twig @@ -1,34 +1,3 @@ -{% set weight_translations = { - 'below_1_5': __('from 0,5 kg to 1,5 kg', 'woodmart'), - '1_5-3': __('from 1.5 to 3 kg', 'woodmart'), - '3-5': __('from 3 to 5 kg', 'woodmart'), - '5-8': __('from 5 to 8 kg', 'woodmart'), - '8-11': __('from 8 to 11 kg', 'woodmart'), - '11-15': __('from 11 to 15 kg', 'woodmart'), - '15-20': __('from 15 to 20 kg', 'woodmart'), - '20-25': __('from 20 to 25 kg', 'woodmart'), - '25-35': __('from 25 to 35 kg', 'woodmart'), - 'more_35': __('More than 35 kg', 'woodmart') -} %} - -{% set old_translations = { - 'normal': __('Adult (from 1 year to 7 years)', 'woodmart'), - 'old': __('Elderly (from 7 to 12 years)', 'woodmart'), - 'very_old': __('Aging (12 years and older)', 'woodmart'), - 'baby': __('Baby (from 0 to 1 year)', 'woodmart') -} %} - -{% set activity_translations = { - 'low': __('Low', 'woodmart'), - 'moderate': __('Moderate', 'woodmart'), - 'high': __('High', 'woodmart') -} %} - -{% set pet_id = item.ID %} -{% set w = weight_translations[function('get_field', 'weight', pet_id)] ?? '' %} -{% set old = old_translations[function('get_field', 'old', pet_id)] ?? '' %} -{% set act = activity_translations[function('get_field', 'activity', pet_id)] ?? '' %} -
@@ -41,25 +10,45 @@
-

{{ __('Breed', 'woodmart') }}:

+

{{ pll_e('Breed') }}:

{{ function('get_field', 'breed', pet_id) }}

-

{{ __('Weight', 'woodmart') }}:

-

{{ w }}

+

{{ pll_e('Weight') }}:

+

+ {% set weight_key = function('get_field', 'weight', pet_id) %} + {% if weight_key == 'below_1_5' %}{{ pll_e('from 0,5 kg to 1,5 kg') }} + {% elseif weight_key == '1_5-3' %}{{ pll_e('from 1.5 to 3 kg') }} + {% elseif weight_key == '3-5' %}{{ pll_e('from 3 to 5 kg') }} + {% elseif weight_key == '5-8' %}{{ pll_e('from 5 to 8 kg') }} + {% elseif weight_key == '8-11' %}{{ pll_e('from 8 to 11 kg') }} + {% elseif weight_key == '11-15' %}{{ pll_e('from 11 to 15 kg') }} + {% elseif weight_key == '15-20' %}{{ pll_e('from 15 to 20 kg') }} + {% elseif weight_key == '20-25' %}{{ pll_e('from 20 to 25 kg') }} + {% elseif weight_key == '25-35' %}{{ pll_e('from 25 to 35 kg') }} + {% elseif weight_key == 'more_35' %}{{ pll_e('More than 35 kg') }} + {% endif %} +

- {% if old %} + {% if function('get_field', 'old', pet_id) %}
-

{{ __('Age', 'woodmart') }}:

-

{{ old }}

+

{{ pll_e('Age') }}:

+

+ {% set age_key = function('get_field', 'old', pet_id) %} + {% if age_key == 'normal' %}{{ pll_e('Adult (from 1 year to 7 years)') }} + {% elseif age_key == 'old' %}{{ pll_e('Elderly (from 7 to 12 years)') }} + {% elseif age_key == 'very_old' %}{{ pll_e('Aging (12 years and older)') }} + {% elseif age_key == 'baby' %}{{ pll_e('Baby (from 0 to 1 year)') }} + {% endif %} +

{% else %} {% set month = function('get_field', 'month', pet_id) %} {% set zero = month < 10 ? '0' : '' %}
-

{{ __('Birhtday', 'woodmart') }}:

+

{{ pll_e('Birthday') }}:

{{ function('get_field', 'day', pet_id) }}.{{ zero }}{{ month }}.{{ function('get_field', 'year', pet_id) }}

@@ -67,237 +56,26 @@ {% endif %}
-

{{ __('Activity', 'woodmart') }}:

-

{{ act }}

+

{{ pll_e('Activity') }}:

+

+ {% set activity_key = function('get_field', 'activity', pet_id) %} + {% if activity_key == 'low' %}{{ pll_e('Low') }} + {% elseif activity_key == 'moderate' %}{{ pll_e('Moderate') }} + {% elseif activity_key == 'high' %}{{ pll_e('High') }} + {% endif %} +

{% if function('get_field', 'type', pet_id) == 'cat' and function('get_field', 'sterilized', pet_id) %}
-

{{ __('Sterilized', 'woodmart') }}

+

{{ pll_e('Sterilized') }}

{% endif %}
-
- -{% set months = [ - __('january', 'woodmart'), - __('february', 'woodmart'), - __('march', 'woodmart'), - __('april', 'woodmart'), - __('mail', 'woodmart'), - __('june', 'woodmart'), - __('july', 'woodmart'), - __('august', 'woodmart'), - __('september', 'woodmart'), - __('october', 'woodmart'), - __('november', 'woodmart'), - __('december', 'woodmart') -] %} - -
-
\ No newline at end of file diff --git a/wp-content/themes/cosmopet/templates/profile/profile.twig b/wp-content/themes/cosmopet/templates/profile/profile.twig index 340fe3a..cdbff07 100644 --- a/wp-content/themes/cosmopet/templates/profile/profile.twig +++ b/wp-content/themes/cosmopet/templates/profile/profile.twig @@ -105,4 +105,310 @@ {% endif %}
-{% endblock %} \ No newline at end of file + +{% endblock %} + + + + + + + +
+ +
+ +
+ +
+ +
+ +
+