init commit
This commit is contained in:
64
client_webapp/code-snippets/HelperFunctions.php
Normal file
64
client_webapp/code-snippets/HelperFunctions.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
class HelperFunctions {
|
||||
function declareGlobalsFn () {
|
||||
|
||||
// Functions declared inside a function have global scope
|
||||
function page_id() {
|
||||
global $wp_query;
|
||||
return $wp_query->post->ID;
|
||||
}
|
||||
|
||||
function php_console_log($data) {
|
||||
$output = $data;
|
||||
if (is_array($output)) {
|
||||
$output = implode(',', $output);
|
||||
}
|
||||
echo "<script>console.log( '" . $output . "' );</script>";
|
||||
}
|
||||
|
||||
function current_url() {
|
||||
return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
|
||||
}
|
||||
|
||||
function redirect($url, $statusCode = 303) {
|
||||
header('Location: ' . $url, true, $statusCode);
|
||||
die();
|
||||
}
|
||||
|
||||
function connect_to_server($server) {
|
||||
if ($server == 'zinomedia') {
|
||||
return new wpdb('pkrstarsbot','ichpkrstarsbot#1337','pkrstarsbot','localhost');
|
||||
}
|
||||
}
|
||||
|
||||
function generateHiddenInputsFromArray( $data = array(), $namePrefix = '' ) {
|
||||
if(!is_array($data) || empty($data)) {
|
||||
return '';
|
||||
}
|
||||
$html = "";
|
||||
$namePrefix = trim($namePrefix);
|
||||
|
||||
if ( is_array( $data ) && !empty($data) ) {
|
||||
foreach ( $data as $key => $value) {
|
||||
$keyEsc = htmlentities($key);
|
||||
if($namePrefix != '') {
|
||||
$keyEsc = $namePrefix."[{$keyEsc}]";
|
||||
}
|
||||
|
||||
if(is_array($value)) {
|
||||
$html .= generateHiddenInputsFromArray($value,$keyEsc);
|
||||
} else {
|
||||
$valueEsc = htmlentities($value);
|
||||
$html .= "<input type='hidden' name='{$keyEsc}' value='{$valueEsc}' />".PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$ob = new HelperFunctions();
|
||||
$ob->declareGlobalsFn();
|
||||
60
client_webapp/code-snippets/add_user_metadata.1.php
Normal file
60
client_webapp/code-snippets/add_user_metadata.1.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
add_filter( 'wp_enqueue_scripts', 'add_user_metadata' );
|
||||
|
||||
function add_user_metadata() {
|
||||
if (!is_user_logged_in()) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $current_user;
|
||||
wp_get_current_user();
|
||||
|
||||
// Check if user exists
|
||||
$is_registered = get_user_meta( $current_user->ID, 'is_registered', true );
|
||||
|
||||
php_console_log('is_registered: ' . $is_registered);
|
||||
if ($is_registered) {
|
||||
$db_user_id = get_user_meta( $current_user->ID, 'db_user_id', true );
|
||||
php_console_log('db_user_id: ' . $db_user_id);
|
||||
|
||||
|
||||
$db_user_id = get_user_meta( $current_user->ID, 'db_user_id', true );
|
||||
echo generateHiddenInputsFromArray(array(
|
||||
"user_email" => $current_user->user_email,
|
||||
"user_id" => $current_user->ID,
|
||||
"db_user_id" => $db_user_id,
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
php_console_log("Registering user in external db...");
|
||||
|
||||
$wpdb = connect_to_server('zinomedia');
|
||||
|
||||
// Register user in external db
|
||||
$wpdb->insert('reg_users', array(
|
||||
'UserName' => $current_user->user_email,
|
||||
'EMail' => $current_user->user_email,
|
||||
'Password' => '',
|
||||
'Registered' => date("Y-m-d H:i:s"),
|
||||
));
|
||||
$db_user_id = $wpdb->insert_id;
|
||||
|
||||
// Create streamdelay
|
||||
$wpdb->insert('config_user', array(
|
||||
'Key' => "DelaySeconds",
|
||||
'Value' => 0,
|
||||
'UserID' => $db_user_id,
|
||||
));
|
||||
|
||||
// To DOM
|
||||
echo generateHiddenInputsFromArray(array(
|
||||
"user_email" => $current_user->user_email,
|
||||
"user_id" => $current_user->ID,
|
||||
"db_user_id" => $db_user_id,
|
||||
));
|
||||
|
||||
// Save
|
||||
update_user_meta( $current_user->ID, 'db_user_id', $db_user_id );
|
||||
update_user_meta( $current_user->ID, 'is_registered', 1 );
|
||||
}
|
||||
50
client_webapp/code-snippets/add_user_metadata.php
Normal file
50
client_webapp/code-snippets/add_user_metadata.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
add_filter( 'wp_enqueue_scripts', 'add_user_metadata' );
|
||||
|
||||
function add_user_metadata() {
|
||||
if (!is_user_logged_in()) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $current_user;
|
||||
wp_get_current_user();
|
||||
|
||||
// Check if user exists
|
||||
$is_registered = get_user_meta( $current_user->ID, 'is_registered', true );
|
||||
|
||||
php_console_log('is_registered: ' . $is_registered);
|
||||
|
||||
if ($is_registered) {
|
||||
echo generateHiddenInputsFromArray(array(
|
||||
"wp_user_id" => $current_user->ID,
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
php_console_log("Registering user in external db...");
|
||||
|
||||
$wpdb = connect_to_server('zinomedia');
|
||||
|
||||
// Register user in external db
|
||||
$wpdb->insert('reg_users', array(
|
||||
'UserName' => $current_user->user_email,
|
||||
'EMail' => $current_user->user_email,
|
||||
'Registered' => date("Y-m-d H:i:s"),
|
||||
'WP_ID' => $current_user->ID,
|
||||
));
|
||||
$db_user_id = $wpdb->insert_id;
|
||||
|
||||
// Create streamdelay
|
||||
$wpdb->insert('config_user', array(
|
||||
'Key' => "DelaySeconds",
|
||||
'Value' => 0,
|
||||
'UserID' => $db_user_id,
|
||||
));
|
||||
|
||||
update_user_meta( $current_user->ID, 'is_registered', 1 );
|
||||
|
||||
echo generateHiddenInputsFromArray(array(
|
||||
"user_id" => $current_user->ID,
|
||||
));
|
||||
}
|
||||
116
client_webapp/code-snippets/api.php
Normal file
116
client_webapp/code-snippets/api.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
add_action( 'rest_api_init', 'register_api_client' );
|
||||
function register_api_client() {
|
||||
register_rest_route('client/v1', 'streamdelay', [
|
||||
'methods' => 'POST',
|
||||
'callback' => 'streamdelay',
|
||||
'args' => array(
|
||||
'delay' => array(
|
||||
'validate_callback' => 'validate_numeric',
|
||||
'required' => true,
|
||||
),
|
||||
'dbuserid' => array(
|
||||
'validate_callback' => 'validate_numeric',
|
||||
'required' => true,
|
||||
),
|
||||
),
|
||||
'permission_callback' => function() {
|
||||
return is_user_logged_in();
|
||||
},
|
||||
] );
|
||||
|
||||
register_rest_route('client/v1', 'dbuserid', [
|
||||
'methods' => 'POST',
|
||||
'callback' => 'dbuserid',
|
||||
'args' => array(
|
||||
'email' => array(
|
||||
'validate_callback' => 'validate_emailaddress',
|
||||
'required' => true,
|
||||
),
|
||||
),
|
||||
'permission_callback' => function() {
|
||||
return is_user_logged_in();
|
||||
},
|
||||
] );
|
||||
|
||||
register_rest_route('client/v1', 'dbuseridwp', [
|
||||
'methods' => 'POST',
|
||||
'callback' => 'dbuseridwp',
|
||||
'args' => array(
|
||||
'wp_user_id' => array(
|
||||
'validate_callback' => 'validate_numeric',
|
||||
'required' => true,
|
||||
),
|
||||
),
|
||||
'permission_callback' => function() {
|
||||
return is_user_logged_in();
|
||||
},
|
||||
] );
|
||||
|
||||
register_rest_route('client/v1', 'logoutuser', [
|
||||
'methods' => 'POST',
|
||||
'callback' => 'logoutuser',
|
||||
'permission_callback' => function() {
|
||||
return is_user_logged_in();
|
||||
},
|
||||
] );
|
||||
}
|
||||
|
||||
function validate_emailaddress($param, $request, $key) {
|
||||
return filter_var($param, FILTER_VALIDATE_EMAIL) !== false;
|
||||
}
|
||||
|
||||
function validate_numeric($param, $request, $key) {
|
||||
return is_numeric($param);
|
||||
}
|
||||
|
||||
function logoutuser() {
|
||||
wp_logout();
|
||||
$response = new WP_REST_Response("foobar");
|
||||
$response->set_status(200);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
function dbuseridwp($request) {
|
||||
$wp_user_id = $request->get_param('wp_user_id');
|
||||
|
||||
$wpdb = connect_to_server('zinomedia');
|
||||
$db_user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID from reg_users where WP_ID = %d", $wp_user_id ) );
|
||||
$response = new WP_REST_Response($db_user_id);
|
||||
$response->set_status(200);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
function dbuserid($request) {
|
||||
$email = $request->get_param('email');
|
||||
|
||||
$wpdb = connect_to_server('zinomedia');
|
||||
$db_user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID from reg_users where EMail = %s", $email ) );
|
||||
$response = new WP_REST_Response($db_user_id);
|
||||
$response->set_status(200);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
function streamdelay($request) {
|
||||
$parameter = $request->get_params();
|
||||
$delay = $request->get_param('delay');
|
||||
$db_user_id = $request->get_param('db_user_id');
|
||||
|
||||
$wpdb = connect_to_server('zinomedia');
|
||||
$wpdb->update('config_user',
|
||||
array(
|
||||
'Value' => $delay,
|
||||
),
|
||||
array(
|
||||
"UserID" => $db_user_id,
|
||||
)
|
||||
);
|
||||
|
||||
$response = new WP_REST_Response($parameter);
|
||||
$response->set_status(200);
|
||||
|
||||
return $response;
|
||||
}
|
||||
12
client_webapp/code-snippets/generate_nonce.php
Normal file
12
client_webapp/code-snippets/generate_nonce.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
add_action( 'wp_enqueue_scripts', 'my_enqueue_scripts' );
|
||||
function my_enqueue_scripts() {
|
||||
if (!is_user_logged_in()) {
|
||||
return;
|
||||
}
|
||||
// Register custom variables for the AJAX script.
|
||||
wp_localize_script( 'script', 'myScriptVars', [
|
||||
'root' => esc_url_raw( rest_url() ),
|
||||
'nonce' => wp_create_nonce( 'wp_rest' ),
|
||||
] );
|
||||
}
|
||||
34
client_webapp/code-snippets/hide_mpr_activation_error.php
Normal file
34
client_webapp/code-snippets/hide_mpr_activation_error.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
add_action( 'admin_enqueue_scripts', 'my_hide_memberpressactivate' );
|
||||
function my_hide_memberpressactivate() {
|
||||
?>
|
||||
<script>
|
||||
// START JAVASCRIPT
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
console.log('executing now');
|
||||
//wait_for_class('error', 'hide_mbpr_error');
|
||||
hide_mbpr_error();
|
||||
});
|
||||
|
||||
function hide_mbpr_error() {
|
||||
if( jQuery('.error').length ) {
|
||||
if( jQuery('.error')[0].textContent == "MemberPress doesn't have a valid license key installed. Go to the MemberPress activation page to activate your license or go to memberpress.com to get one." ) {
|
||||
jQuery('.error')[0].outerHTML = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function wait_for_class(selector, fnName) {
|
||||
if (jQuery('.' + selector).length) {
|
||||
console.log('ready');
|
||||
window[fnName](selector);
|
||||
} else {
|
||||
setTimeout(function() {
|
||||
wait_for_class(selector, fnName);
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
// END JAVASCRIPT
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
18
client_webapp/code-snippets/inject_jqueryuijs.php
Normal file
18
client_webapp/code-snippets/inject_jqueryuijs.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
add_filter( 'wp_enqueue_scripts', 'js_inject_jqueryui' );
|
||||
function js_inject_jqueryui() {
|
||||
if (!is_user_logged_in()) {
|
||||
return;
|
||||
}
|
||||
if(page_id() === 2) {
|
||||
?>
|
||||
<script>
|
||||
var script = document.createElement('script');
|
||||
script.setAttribute('src', 'https://code.jquery.com/ui/1.12.1/jquery-ui.min.js');
|
||||
script.setAttribute('integrity', 'sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=');
|
||||
script.setAttribute('crossorigin', 'anonymous');
|
||||
document.getElementsByTagName('head')[0].appendChild(script);
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
5
client_webapp/code-snippets/inject_scriptjs.php
Normal file
5
client_webapp/code-snippets/inject_scriptjs.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
if (!is_user_logged_in()) {
|
||||
return;
|
||||
}
|
||||
wp_enqueue_script( 'script', 'https://pkrstarsbot.zinomedia.de/www/client_webapp/src/file-system-access-api.js', 'jQuery', 1.0, true);
|
||||
2
client_webapp/code-snippets/inject_stylecss.php
Normal file
2
client_webapp/code-snippets/inject_stylecss.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
wp_enqueue_style( 'style', 'https://pkrstarsbot.zinomedia.de/www/client_webapp/css/style.css',false,'1.0','all');
|
||||
29
client_webapp/code-snippets/loggedInAs.php
Normal file
29
client_webapp/code-snippets/loggedInAs.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
add_action( 'wp_enqueue_scripts', 'my_getUserInfo' );
|
||||
function my_getUserInfo() {
|
||||
if (!is_user_logged_in()) {
|
||||
return;
|
||||
}
|
||||
if(page_id() === 2) {
|
||||
global $current_user;
|
||||
wp_get_current_user();
|
||||
js_manipulate($current_user);
|
||||
}
|
||||
}
|
||||
|
||||
function js_manipulate($current_user) {
|
||||
?>
|
||||
<script>
|
||||
// START JAVASCRIPT
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
const email = "<?php echo $current_user->user_email ?>";
|
||||
|
||||
jQuery('#textLoggedInAs .fl-rich-text p').ready(function() {
|
||||
jQuery("#textEmail .fl-rich-text")[0].textContent = email;
|
||||
});
|
||||
});
|
||||
// END JAVASCRIPT
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user