Commit aad0f896 authored by Simonas's avatar Simonas

in progress

parent 80f2e007
...@@ -65,6 +65,8 @@ ERROR: for mysql Cannot start service mysql: error while creating mount source ...@@ -65,6 +65,8 @@ ERROR: for mysql Cannot start service mysql: error while creating mount source
Restart docker (sometimes PC restart may be required) Restart docker (sometimes PC restart may be required)
<!-- - https://tomssl.com/2018/01/11/sharing-your-c-drive-with-docker-for-windows-when-using-azure-active-directory-azuread-aad/ -->
## Other (Commands) ## Other (Commands)
- docker-compose up -d - docker-compose up -d
- docker-compose start - docker-compose start
...@@ -103,7 +105,7 @@ Restart docker (sometimes PC restart may be required) ...@@ -103,7 +105,7 @@ Restart docker (sometimes PC restart may be required)
- docker load --input ourdemo.tar - docker load --input ourdemo.tar
- docker build -t biuro/web:0.0.7 . - docker build -t biuro/web:0.0.8 .
- docker login --username=biuro --password=9Ndtjd2vKsLvGuFOeFq1KdJs - docker login --username=biuro --password=9Ndtjd2vKsLvGuFOeFq1KdJs
- sudo docker login --username=biuro --password=9Ndtjd2vKsLvGuFOeFq1KdJs - sudo docker login --username=biuro --password=9Ndtjd2vKsLvGuFOeFq1KdJs
- docker push biuro/web:0.0.7 - docker push biuro/web:0.0.7
......
...@@ -136,8 +136,39 @@ services: ...@@ -136,8 +136,39 @@ services:
- ./wordpress:/var/www/html - ./wordpress:/var/www/html
- './wp-init.sh:/usr/local/bin/wp-init.sh' - './wp-init.sh:/usr/local/bin/wp-init.sh'
command: # command:
- wp-init.sh # - wp-init.sh
command: >
/bin/sh -c '
sleep 45;
echo "WP CLI init";
wp core update --force;
wp core update-db --network;
wp option update permalink_structure "/%postname%/" --skip-themes --skip-plugins;
wp option update timezone_string "Manual Offsets/UTC+2";
wp option update date_format "Y-m-d";
wp option update time_format "H:i";
wp plugin install permalink-manager --force --activate-network;
wp plugin install pods --activate-network;
wp plugin install polylang --activate-network;
wp plugin install wordpress-seo --activate-network;
wp plugin update --all;
wp plugin activate akismet --network;
wp plugin activate biuro-contacts --network;
wp plugin activate biuro-feedbacks --network;
wp plugin activate biuro-html --network;
wp plugin activate biuro-sections --network;
wp plugin activate biuro-services --network;
wp plugin activate biuro-values --network;
wp plugin activate cookies-warning --network;
wp plugin activate data-controller --network;
wp theme update --all;
wp theme activate biuro;
wp language core update;
wp language theme update --all;
wp language plugin update --all;
echo "WP CLI done. Ready to use.";
'
networks: networks:
front: front:
......
...@@ -41,6 +41,15 @@ class Biuro_Contacts_Loader { ...@@ -41,6 +41,15 @@ class Biuro_Contacts_Loader {
*/ */
protected $filters; protected $filters;
/**
* The array of shortcodes registered with WordPress.
*
* @since 1.0.0
* @access protected
* @var array $shortcodes The shortcodes registered with WordPress to fire when the plugin loads.
*/
protected $shortcodes;
/** /**
* Initialize the collections used to maintain the actions and filters. * Initialize the collections used to maintain the actions and filters.
* *
...@@ -50,6 +59,7 @@ class Biuro_Contacts_Loader { ...@@ -50,6 +59,7 @@ class Biuro_Contacts_Loader {
$this->actions = array(); $this->actions = array();
$this->filters = array(); $this->filters = array();
$this->shortcodes = array();
} }
...@@ -81,6 +91,18 @@ class Biuro_Contacts_Loader { ...@@ -81,6 +91,18 @@ class Biuro_Contacts_Loader {
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
} }
/**
* Add a new shortcode to the collection to be registered with WordPress
*
* @since 1.0.0
* @param string $tag The name of the new shortcode.
* @param object $component A reference to the instance of the object on which the shortcode is defined.
* @param string $callback The name of the function that defines the shortcode.
*/
public function add_shortcode( $tag, $component, $callback, $priority = 10, $accepted_args = 2 ) {
$this->shortcodes = $this->add( $this->shortcodes, $tag, $component, $callback, $priority, $accepted_args );
}
/** /**
* A utility function that is used to register the actions and hooks into a single * A utility function that is used to register the actions and hooks into a single
* collection. * collection.
...@@ -124,6 +146,9 @@ class Biuro_Contacts_Loader { ...@@ -124,6 +146,9 @@ class Biuro_Contacts_Loader {
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
} }
foreach ( $this->shortcodes as $hook ) {
add_shortcode( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
} }
} }
...@@ -156,7 +156,6 @@ class Biuro_Contacts { ...@@ -156,7 +156,6 @@ class Biuro_Contacts {
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
} }
/** /**
...@@ -173,12 +172,30 @@ class Biuro_Contacts { ...@@ -173,12 +172,30 @@ class Biuro_Contacts {
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
$this->loader->add_action( 'init', $plugin_public, 'register_shortcodes' );
$this->loader->add_action('admin_post_nopriv_employees_quick', $plugin_public, 'employeesQuickSubmit'); $this->loader->add_action('admin_post_employees_quick_post', $plugin_public, 'employees_quick_post');
$this->loader->add_action('admin_post_employees_quick', $plugin_public, 'employeesQuickSubmit'); $this->loader->add_action('admin_post_nopriv_employees_quick_post', $plugin_public, 'employees_quick_post');
$this->loader->add_action('admin_post_nopriv_employers_quick', $plugin_public, 'employersQuickSubmit'); $this->loader->add_action('admin_post_employers_quick_post', $plugin_public, 'employers_quick_post');
$this->loader->add_action('admin_post_employers_quick', $plugin_public, 'employersQuickSubmit'); $this->loader->add_action('admin_post_nopriv_employers_quick_post', $plugin_public, 'employers_quick_post');
// $this->loader->add_action( 'init', $plugin_public, 'register_shortcodes' );
/**
* Register shortcode via loader
*
* Use: [short-code-name args]
*
* @link https://github.com/DevinVinson/WordPress-Plugin-Boilerplate/issues/262
*/
$this->loader->add_shortcode( "biuro-contacts--employees-quick", $plugin_public, "employees_quick_form", $priority = 10, $accepted_args = 2 );
$this->loader->add_shortcode( "biuro-contacts--employers-quick", $plugin_public, "employers_quick_form", $priority = 10, $accepted_args = 2 );
// add_shortcode( 'biuro-contacts--employees-quick', array( $this, 'employees_quick_form' ) );
// add_shortcode( 'biuro-contacts--employers-quick', array( $this, 'employers_quick_form' ) );
// add_shortcode( 'biuro-contacts--employees', array( $this, 'employees_form' ) );
// add_shortcode( 'biuro-contacts--employers', array( $this, 'employers_form' ) );
// add_shortcode( 'biuro-contacts--position', array( $this, 'position_form' ) );
} }
/** /**
......
...@@ -108,7 +108,7 @@ class Biuro_Contacts_Public { ...@@ -108,7 +108,7 @@ class Biuro_Contacts_Public {
* *
* @return mixed $output Output of the buffer * @return mixed $output Output of the buffer
*/ */
public function employees_form( $attr = array() ) { public function employees_form( $atts ) {
$response = false; $response = false;
ob_start(); ob_start();
...@@ -133,7 +133,16 @@ class Biuro_Contacts_Public { ...@@ -133,7 +133,16 @@ class Biuro_Contacts_Public {
* *
* @return mixed $output Output of the buffer * @return mixed $output Output of the buffer
*/ */
public function employees_quick_form( $attr = array() ) { public function employers_quick_form( $attr = array() ) {
// $args = shortcode_atts(
// array(
// 'arg1' => 'arg1',
// 'arg2' => 'arg2',
// ),
// $atts
// );
$response = false; $response = false;
ob_start(); ob_start();
...@@ -142,7 +151,7 @@ class Biuro_Contacts_Public { ...@@ -142,7 +151,7 @@ class Biuro_Contacts_Public {
$response = true; $response = true;
endif; endif;
include 'partials/biuro-contacts-public--employees-quick.php'; include 'partials/biuro-contacts-public--employers-quick.php';
$output = ob_get_contents(); $output = ob_get_contents();
...@@ -151,40 +160,40 @@ class Biuro_Contacts_Public { ...@@ -151,40 +160,40 @@ class Biuro_Contacts_Public {
return $output; return $output;
} // employees_form() } // employees_form()
/** /**
* Processes shortcode biuro-contacts--employees * Processes shortcode biuro-contacts--employers
* *
* @param array $attr The attributes from the shortcode * @param array $attr The attributes from the shortcode
* *
* @return mixed $output Output of the buffer * @return mixed $output Output of the buffer
*/ */
public function employers_quick_form( $attr = array() ) { public function employers_form( $attr = array() ) {
$response = false; $response = false;
ob_start(); ob_start();
if ( isset( $_POST['submit'] ) ) : if ( isset( $_POST['action-submit'] ) ) :
$response = true; $response = true;
endif; endif;
include 'partials/biuro-contacts-public--employers-quick.php'; include 'partials/biuro-contacts-public--employers.php';
$output = ob_get_contents(); $output = ob_get_contents();
ob_end_clean(); ob_end_clean();
return $output; return $output;
} // employees_form() } // employers_form()
/** /**
* Processes shortcode biuro-contacts--employers * Processes shortcode biuro-contacts--position
* *
* @param array $attr The attributes from the shortcode * @param array $attr The attributes from the shortcode
* *
* @return mixed $output Output of the buffer * @return mixed $output Output of the buffer
*/ */
public function employers_form( $attr = array() ) { public function position_form( $attr = array() ) {
$response = false; $response = false;
ob_start(); ob_start();
...@@ -193,48 +202,106 @@ class Biuro_Contacts_Public { ...@@ -193,48 +202,106 @@ class Biuro_Contacts_Public {
$response = true; $response = true;
endif; endif;
include 'partials/biuro-contacts-public--employers.php'; include 'partials/biuro-contacts-public--position.php';
$output = ob_get_contents(); $output = ob_get_contents();
ob_end_clean(); ob_end_clean();
return $output; return $output;
} // employers_form() } // position_form()
/** /**
* Processes shortcode biuro-contacts--position * May override the default upload path.
* /wp-content/uploads/{folder}/
*
* @param array $dir
* @return array
*/
function change_upload_dir( $dir ) {
return array(
'path' => $dir['basedir'] . '/{folder}',
'url' => $dir['baseurl'] . '/{folder}',
'subdir' => '/{folder}',
) + $dir;
}
/**
* Processes shortcode biuro-contacts--employees
* *
* @param array $attr The attributes from the shortcode * @param array $attr The attributes from the shortcode
* *
* @return mixed $output Output of the buffer * @return mixed $output Output of the buffer
*/ */
public function position_form( $attr = array() ) { public function employees_quick_form( $attr = array() ) {
$response = false;
// $args = shortcode_atts(
// array(
// 'arg1' => 'arg1',
// 'arg2' => 'arg2',
// ),
// $atts
// );
// $response = false;
ob_start(); ob_start();
if ( isset( $_POST['action-submit'] ) ) : // if ( isset( $_POST['submit'] ) ) :
$response = true; // $response = true;
endif; // endif;
include 'partials/biuro-contacts-public--position.php'; include 'partials/biuro-contacts-public--employees-quick.php';
$output = ob_get_contents(); $output = ob_get_contents();
ob_end_clean(); ob_end_clean();
return $output; return $output;
} // position_form() } // employees_form()
public function employees_quick_post() {
// debug($_POST); //$_POST variables should be accessible now
$nonce = $_POST['_wpnonce'];
$referer = $_POST['_wp_http_referer'];
public function employersQuickSubmit() {
debug($_POST); //$_POST variables should be accessible now
//Optional: Now you can redirect the user to your confirmation page using wp_redirect() if ( !isset( $nonce ) || !wp_verify_nonce($nonce, 'employees_quick_post_nonce' ) ) {
// Nonce not match
// Diplay some error
wp_redirect( $referer );
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(); // ob_start();
// wp_redirect($_POST['_wp_http_referer']); wp_redirect( $referer );
exit; exit;
// wp_redirect(admin_url('admin.php?page=' . $_POST['_wp_http_referer'])); // wp_redirect(admin_url('admin.php?page=' . $_POST['_wp_http_referer']));
...@@ -242,8 +309,8 @@ class Biuro_Contacts_Public { ...@@ -242,8 +309,8 @@ class Biuro_Contacts_Public {
//apparently when finished, die(); is required. //apparently when finished, die(); is required.
} }
public function employeesQuickSubmit() { 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() //Optional: Now you can redirect the user to your confirmation page using wp_redirect()
// ob_start(); // ob_start();
...@@ -254,23 +321,4 @@ class Biuro_Contacts_Public { ...@@ -254,23 +321,4 @@ class Biuro_Contacts_Public {
// die(); // die();
//apparently when finished, die(); is required. //apparently when finished, die(); is required.
} }
/**
* Registers all shortcodes at once
*
* @return [type] [description]
*/
public function register_shortcodes() {
add_shortcode( 'biuro-contacts--employees-quick', array( $this, 'employees_quick_form' ) );
add_shortcode( 'biuro-contacts--employers-quick', array( $this, 'employers_quick_form' ) );
add_shortcode( 'biuro-contacts--employees', array( $this, 'employees_form' ) );
add_shortcode( 'biuro-contacts--employers', array( $this, 'employers_form' ) );
add_shortcode( 'biuro-contacts--position', array( $this, 'position_form' ) );
} // register_shortcodes()
} }
...@@ -11,6 +11,15 @@ ...@@ -11,6 +11,15 @@
* @package Biuro_Contacts * @package Biuro_Contacts
* @subpackage Biuro_Contacts/public/partials * @subpackage Biuro_Contacts/public/partials
*/ */
/**
* @link https://codex.wordpress.org/Creating_Options_Pages
* @link https://www.smashingmagazine.com/2016/04/three-approaches-to-adding-configurable-fields-to-your-plugin/
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) die;
// Generate a custom nonce value.
$_nonce = wp_create_nonce( 'my_post_form_nonce' );
?> ?>
<form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post" enctype="multipart/form-data" class="c-form"> <form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post" enctype="multipart/form-data" class="c-form">
...@@ -69,6 +78,7 @@ ...@@ -69,6 +78,7 @@
<?php endif; ?> <?php endif; ?>
</div><!-- .c-form--row --> </div><!-- .c-form--row -->
<input type="hidden" name="action" value="employees_quick"> <input type="hidden" name="action" value="employees_quick_post">
<?php wp_nonce_field('employees_quick_nonce', 'employees_quick_nonce'); ?> <!-- <input type="hidden" name="_nonce" value="<?php echo $_nonce; ?>" /> -->
<?php wp_nonce_field('employees_quick_post_nonce'); ?>
</form> </form>
...@@ -11,6 +11,15 @@ ...@@ -11,6 +11,15 @@
* @package Biuro_Contacts * @package Biuro_Contacts
* @subpackage Biuro_Contacts/public/partials * @subpackage Biuro_Contacts/public/partials
*/ */
/**
* @link https://codex.wordpress.org/Creating_Options_Pages
* @link https://www.smashingmagazine.com/2016/04/three-approaches-to-adding-configurable-fields-to-your-plugin/
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) die;
// Generate a custom nonce value.
$_nonce = wp_create_nonce( 'my_post_form_nonce' );
?> ?>
<form id="ContactFormEmployee_ContactFormEmployee" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post" enctype="multipart/form-data" class="contact-form"> <form id="ContactFormEmployee_ContactFormEmployee" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post" enctype="multipart/form-data" class="contact-form">
......
...@@ -11,6 +11,15 @@ ...@@ -11,6 +11,15 @@
* @package Biuro_Contacts * @package Biuro_Contacts
* @subpackage Biuro_Contacts/public/partials * @subpackage Biuro_Contacts/public/partials
*/ */
/**
* @link https://codex.wordpress.org/Creating_Options_Pages
* @link https://www.smashingmagazine.com/2016/04/three-approaches-to-adding-configurable-fields-to-your-plugin/
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) die;
// Generate a custom nonce value.
$_nonce = wp_create_nonce( 'my_post_form_nonce' );
?> ?>
<form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post" enctype="multipart/form-data" class="c-form"> <form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post" enctype="multipart/form-data" class="c-form">
......
...@@ -11,6 +11,15 @@ ...@@ -11,6 +11,15 @@
* @package Biuro_Contacts * @package Biuro_Contacts
* @subpackage Biuro_Contacts/public/partials * @subpackage Biuro_Contacts/public/partials
*/ */
/**
* @link https://codex.wordpress.org/Creating_Options_Pages
* @link https://www.smashingmagazine.com/2016/04/three-approaches-to-adding-configurable-fields-to-your-plugin/
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) die;
// Generate a custom nonce value.
$_nonce = wp_create_nonce( 'my_post_form_nonce' );
?> ?>
<form id="ContactForm_ContactForm" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post" enctype="application/x-www-form-urlencoded" class="contact-form"> <form id="ContactForm_ContactForm" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post" enctype="application/x-www-form-urlencoded" class="contact-form">
......
...@@ -11,6 +11,15 @@ ...@@ -11,6 +11,15 @@
* @package Biuro_Contacts * @package Biuro_Contacts
* @subpackage Biuro_Contacts/public/partials * @subpackage Biuro_Contacts/public/partials
*/ */
/**
* @link https://codex.wordpress.org/Creating_Options_Pages
* @link https://www.smashingmagazine.com/2016/04/three-approaches-to-adding-configurable-fields-to-your-plugin/
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) die;
// Generate a custom nonce value.
$_nonce = wp_create_nonce( 'my_post_form_nonce' );
?> ?>
<form id="CVForm_CVForm" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post" enctype="multipart/form-data" class="contact-form"> <form id="CVForm_CVForm" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post" enctype="multipart/form-data" class="contact-form">
......
<?php <?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) { function cc_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml'; $mimes['svg'] = 'image/svg+xml';
return $mimes; return $mimes;
...@@ -412,6 +400,48 @@ add_action('init', 'df_disable_comments_admin_bar'); ...@@ -412,6 +400,48 @@ add_action('init', 'df_disable_comments_admin_bar');
// require_once 'includes/disable_discussion'; // require_once 'includes/disable_discussion';
function getContacts ( $request ) {
$res = array();
array_push($res, array(
'id' => 1,
'date' => '2019-03-15 19:05:44',
'name' => 'Vardenis',
'surname' => 'Pavardenis',
'phone' => '+37060000000',
'email' => 'email@example.com',
'city' => '',
'comment' => '',
'cv' => ''
) );
array_push($res, array(
'id' => 2,
'date' => '2019-04-01 08:08:17',
'name' => 'Jonas',
'surname' => 'Jonaitis Kazlauskaitis',
'phone' => '',
'email' => 'jonas@example.com',
'city' => 'Vilnius',
'comment' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est ducimus iusto modi a, iure. Provident.',
'cv' => '/path/to/000000000000000.pdf'
) );
array_push($res, array(
'id' => 3,
'date' => '2019-04-10 07:43:02',
'name' => 'Eglė',
'surname' => 'Pavardenytė',
'phone' => '',
'email' => 'egle@example.com',
'city' => 'Kaunas',
'comment' => '',
'cv' => ''
) );
return new WP_REST_Response( $res, 200 );
}
function getDivisions ( $request ) { function getDivisions ( $request ) {
$res = array(); $res = array();
$params = $request->get_params(); $params = $request->get_params();
...@@ -466,4 +496,21 @@ add_action( 'rest_api_init', function () { ...@@ -466,4 +496,21 @@ add_action( 'rest_api_init', function () {
) )
)); ));
register_rest_route( 'api/v1', '/contacts', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'getContacts'
));
}); });
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