Commit 9f8d8242 authored by Simonas's avatar Simonas

in progress

parent aad0f896
......@@ -64,8 +64,11 @@ ERROR: for mysql Cannot start service mysql: error while creating mount source
### Solution
Restart docker (sometimes PC restart may be required)
### Error
Can't share C drive
<!-- - https://tomssl.com/2018/01/11/sharing-your-c-drive-with-docker-for-windows-when-using-azure-active-directory-azuread-aad/ -->
### Solution
- https://tomssl.com/2018/01/11/sharing-your-c-drive-with-docker-for-windows-when-using-azure-active-directory-azuread-aad/
## Other (Commands)
- docker-compose up -d
......@@ -114,6 +117,7 @@ Restart docker (sometimes PC restart may be required)
### DB preview
- `docker exec -it dev-biuro-nginx sh`
- `docker exec -it dev-biuro-wordpress bash`
- `docker exec -it dev-biuro-mysql bash`
- `mysql -uroot -pIiIjnsLi2wR9i1kWVbVpUAzP --default-character-set=utf8`
......
......@@ -75,6 +75,7 @@ services:
- '80:80'
- '443:443'
volumes:
- ./nginx/.htpasswd:/etc/nginx/.htpasswd
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/h5bp:/etc/nginx/h5bp
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
......
alice:$apr1$Q9qBLkLy$YQNxI8/GYuHLmoOUkbjN70
bob:$apr1$5rz0Qz20$Xuo4c3yrZRjkAk89il7Us/
......@@ -15,8 +15,16 @@ index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
# auth_basic "Restricted Content";
# auth_basic_user_file /etc/nginx/.htpasswd;
}
# location /wp-json/api/v1/contacts {
# try_files $uri $uri/ =404;
# auth_basic "Restricted Content";
# auth_basic_user_file /etc/nginx/.htpasswd;
# }
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
......
......@@ -100,4 +100,77 @@ class Biuro_Contacts_Admin {
}
// date DEFAULT '0000-00-00 00:00:00',
// name tinytext,
// surname tinytext,
// email varchar(128) DEFAULT '',
// phone varchar(128) DEFAULT '',
// city varchar(255) DEFAULT '',
// comment longtext DEFAULT '',
// cv text DEFAULT '',
public function get_rows_from_db_as_associative_array() {
global $wpdb;
$sql = "SELECT * FROM `" . $wpdb->prefix . "biuro_employees` ORDER BY id DESC";
return $wpdb->get_results( $sql, ARRAY_A );
}
public function insert_row_to_db() {
global $wpdb;
$table = $wpdb->prefix . 'biuro_employees';
$data = array(
'db_field_tinytext' => 'SOME TEXT',
'db_field_datetime' => date( 'Y-m-d H:i:s' ),
'db_field_varchar' => 'SOME OTHER TEXT',
'db_field_mediumint' => 123,
'db_field_text' => 'LONGER TEXT',
);
$format = array( '%s','%s', '%s', '%d', '%s' );
$wpdb->insert( $table, $data, $format );
return $wpdb->insert_id;
}
public function update_row_in_db() {
global $wpdb;
$table = $wpdb->prefix . 'biuro_employees';
$data = array(
'db_field_tinytext' => 'SOME TEXT',
'db_field_datetime' => date( 'Y-m-d H:i:s' ),
'db_field_varchar' => 'SOME OTHER TEXT',
'db_field_mediumint' => 123,
'db_field_text' => 'LONGER TEXT',
);
$format = array( '%s','%s', '%s', '%d', '%s' );
$where = array(
'ID' => 1
);
$where_format = array(
'%d'
);
return $wpdb->insert( $table, $data, $where, $format, $where_format );
}
public function delete_row_from_db() {
global $wpdb;
$table = $wpdb->prefix . 'biuro_employees';
$where = array(
'ID' => 1
);
$where_format = array(
'%d'
);
return $wpdb->delete( $table, $where, $where_format );
}
public function use_prepare_db_query() {
global $wpdb;
$sql = "UPDATE $wpdb->posts SET post_parent = %d WHERE ID = %d AND post_status = %s";
return $wpdb->query( $wpdb->prepare( $sql, 7, 15, 'static' ) );
}
}
......@@ -30,7 +30,56 @@ class Biuro_Contacts_Activator {
* @since 1.0.0
*/
public static function activate() {
global $wpdb;
if ( is_multisite() ) {
// Get all blogs in the network and activate plugin on each one
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
self::create_db_employees();
restore_current_blog();
}
} else {
// create_table();
self::create_db_employees();
}
}
public static function create_db_employees() {
global $wpdb;
$table_name = $wpdb->prefix . "biuro_employees";
$plugin_name_db_version = get_option( 'biuro-contacts_db_version', '1.0' );
if( $wpdb->get_var( "show tables like '{$table_name}'" ) != $table_name ||
version_compare( $version, '1.0' ) < 0 ) {
$charset_collate = $wpdb->get_charset_collate();
$sql[] = "CREATE TABLE " . $table_name . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
created datetime DEFAULT '0000-00-00 00:00:00',
name tinytext,
surname tinytext,
email varchar(128) DEFAULT '',
phone varchar(128) DEFAULT '',
city varchar(255) DEFAULT '',
comment longtext DEFAULT '',
cv text DEFAULT '',
PRIMARY KEY (id)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
/**
* It seems IF NOT EXISTS isn't needed if you're using dbDelta - if the table already exists it'll
* compare the schema and update it instead of overwriting the whole table.
*
* @link https://code.tutsplus.com/tutorials/custom-database-tables-maintaining-the-database--wp-28455
*/
dbDelta( $sql );
add_option( 'biuro-contacts_db_version', $plugin_name_db_version );
}
}
}
......@@ -117,7 +117,7 @@ class Biuro_Contacts_Public {
$response = true;
endif;
include 'partials/biuro-contacts-public--employees.php';
include_once('partials/biuro-contacts-public--employees.php');
$output = ob_get_contents();
......@@ -151,7 +151,7 @@ class Biuro_Contacts_Public {
$response = true;
endif;
include 'partials/biuro-contacts-public--employers-quick.php';
include_once('partials/biuro-contacts-public--employers-quick.php');
$output = ob_get_contents();
......@@ -177,7 +177,7 @@ class Biuro_Contacts_Public {
$response = true;
endif;
include 'partials/biuro-contacts-public--employers.php';
include_once('partials/biuro-contacts-public--employers.php');
$output = ob_get_contents();
......@@ -202,7 +202,7 @@ class Biuro_Contacts_Public {
$response = true;
endif;
include 'partials/biuro-contacts-public--position.php';
include_once('partials/biuro-contacts-public--position.php');
$output = ob_get_contents();
......@@ -212,8 +212,6 @@ class Biuro_Contacts_Public {
} // position_form()
/**
* May override the default upload path.
* /wp-content/uploads/{folder}/
......@@ -255,7 +253,7 @@ class Biuro_Contacts_Public {
// $response = true;
// endif;
include 'partials/biuro-contacts-public--employees-quick.php';
include_once('partials/biuro-contacts-public--employees-quick.php');
$output = ob_get_contents();
......@@ -265,12 +263,10 @@ class Biuro_Contacts_Public {
} // employees_form()
public function employees_quick_post() {
// debug($_POST); //$_POST variables should be accessible now
$nonce = $_POST['_wpnonce'];
$referer = $_POST['_wp_http_referer'];
if ( !isset( $nonce ) || !wp_verify_nonce($nonce, 'employees_quick_post_nonce' ) ) {
// Nonce not match
// Diplay some error
......@@ -278,31 +274,34 @@ class Biuro_Contacts_Public {
exit;
}
/*
* May prehandle file upload
*/
// Set an array containing a list of acceptable formats
// $allowed_file_types = array('image/jpg','image/jpeg','image/gif','image/png');
// $allowed_file_types = array('doc','docx','pdf', 'rtf', 'jpg', 'jpeg', 'gif', 'png');
// $allowed_file_types = array('doc','docx','pdf');
$allowed_file_types = array('application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document');
// Check file types
foreach( $_FILES as $file ) {
// Get the type of the uploaded file. This is returned as "type/extension"
$arr_file_type = wp_check_filetype( basename( $file['name'] ) );
$uploaded_file_type = $arr_file_type['type'];
if( ! in_array( $uploaded_file_type, $allowed_file_types ) ) {
// Diplay some error
wp_redirect( $referer );
exit;
}
}
// delog($nonce, 'nonce');
// Optional: Now you can redirect the user to your confirmation page using wp_redirect()
// ob_start();
wp_redirect( $referer );
exit;
debug($_POST); //$_POST variables should be accessible now
// /*
// * May prehandle file upload
// */
// // Set an array containing a list of acceptable formats
// // $allowed_file_types = array('image/jpg','image/jpeg','image/gif','image/png');
// // $allowed_file_types = array('doc','docx','pdf', 'rtf', 'jpg', 'jpeg', 'gif', 'png');
// // $allowed_file_types = array('doc','docx','pdf');
// $allowed_file_types = array('application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document');
// // Check file types
// foreach( $_FILES as $file ) {
// // Get the type of the uploaded file. This is returned as "type/extension"
// $arr_file_type = wp_check_filetype( basename( $file['name'] ) );
// $uploaded_file_type = $arr_file_type['type'];
// if( ! in_array( $uploaded_file_type, $allowed_file_types ) ) {
// // Diplay some error
// wp_redirect( $referer );
// exit;
// }
// }
// // delog($nonce, 'nonce');
// // Optional: Now you can redirect the user to your confirmation page using wp_redirect()
// // ob_start();
// wp_redirect( $referer );
// exit;
// wp_redirect(admin_url('admin.php?page=' . $_POST['_wp_http_referer']));
// die();
......@@ -310,7 +309,7 @@ class Biuro_Contacts_Public {
}
public function employers_quick_post() {
// debug($_POST); //$_POST variables should be accessible now
debug($_POST); //$_POST variables should be accessible now
//Optional: Now you can redirect the user to your confirmation page using wp_redirect()
// ob_start();
......
<?php
function debug($arr) {
echo '<pre>';
print_r( $arr );
echo '</pre>';
}
function delog($str, $label = 'Label') {
echo '<h1 style="white-space: nowrap;">' . $label . ': ' . $str . '</h1>';
}
function cc_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
......@@ -502,15 +513,3 @@ add_action( 'rest_api_init', function () {
));
});
function debug($arr) {
echo '<pre>';
print_r( $arr );
echo '</pre>';
}
function delog($str, $label = 'Label') {
echo '<h1 style="white-space: nowrap;">' . $label . ': ' . $str . '</h1>';
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment