Commit 99eccbaf authored by Simon's avatar Simon

Salary type added

parent 06bd4cc3
<?php <?php
/* /*
Plugin Name: Biuro Jobs importer Plugin Name: Biuro Jobs importer
description: A plugin for import jobs ads from Biuro endpoint description: A plugin for import jobs ads from Biuro endpoint
Version: 1.0.0 Version: 1.0.0
*/ */
set_time_limit(300); set_time_limit(300);
// Data collector: prepare data for import // Data collector: prepare data for import
require_once 'JsonDataCollector.php'; require_once 'JsonDataCollector.php';
// Data importer: imports data to WP posts // Data importer: imports data to WP posts
require_once 'JobsImporter.php'; require_once 'JobsImporter.php';
// Initial data importer // Initial data importer
require_once 'importInitData.php'; require_once 'importInitData.php';
if (function_exists('importer_admin_menu')) { if (function_exists('importer_admin_menu')) {
// Add item to admin menu // Add item to admin menu
add_action('admin_menu', 'importer_admin_menu'); add_action('admin_menu', 'importer_admin_menu');
} }
/** /**
* Set admin menu item for plugin * Set admin menu item for plugin
*/ */
function importer_admin_menu() function importer_admin_menu()
{ {
add_submenu_page( add_submenu_page(
'options-general.php', 'options-general.php',
'Biuro Jobs importer', 'Biuro Jobs importer',
'Biuro Jobs importer', 'Biuro Jobs importer',
'data_importer', 'data_importer',
'jobs-importer', 'jobs-importer',
'do_import' 'do_import'
); );
} }
/** /**
* Imports posts from Biuro endpoint * Imports posts from Biuro endpoint
*/ */
function do_import() function do_import()
{ {
$env = getEnvironment(); $env = getEnvironment();
$inputFile = getSource($env); $inputFile = getSource($env);
print_r("<div style='background: lightgrey;'> print_r("<div style='background: lightgrey;'>
<small style='float: right;'>Working in <strong>$env</strong> mode</small> <small style='float: right;'>Working in <strong>$env</strong> mode</small>
<div style='clear: both;'></div> <div style='clear: both;'></div>
</div>"); </div>");
echo "<pre>"; echo "<pre>";
print_r('<h4>Biuro Jobs importer</h4>'); print_r('<h4>Biuro Jobs importer</h4>');
// if (pll_current_language() != '') // if (pll_current_language() != '')
// { // {
// print_r("<h5 class='warning'>Polylang must be set in 'All languages' mode.</h5>"); // print_r("<h5 class='warning'>Polylang must be set in 'All languages' mode.</h5>");
// pll_the_languages( array( 'dropdown' => 1 ) ); // pll_the_languages( array( 'dropdown' => 1 ) );
// exit(); // exit();
// } // }
print_r("Data source: $inputFile<br><br>"); print_r("Data source: $inputFile<br><br>");
// JSON reader // JSON reader
$ads = (new JsonDataCollector($inputFile))->getData(); $ads = (new JsonDataCollector($inputFile))->getData();
// print_r($ads); // print_r($ads);
print_r("Found " . count($ads) . " ads from Biuro.<br>"); print_r("Found " . count($ads) . " ads from Biuro.<br>");
if (count($ads) > 0) { if (count($ads) > 0) {
if (empty($_POST)) { if (empty($_POST)) {
// Form for import start, set polylang to 'All lang.' for action // Form for import start, set polylang to 'All lang.' for action
print_r("<form method='post' action='" . current_location() . "&lang=all'>"); print_r("<form method='post' action='" . current_location() . "&lang=all'>");
print_r("<div style='margin-top: 10px;'><button name='import' value='true'>Import</button></div>"); print_r("<div style='margin-top: 10px;'><button name='import' value='true'>Import</button></div>");
print_r("</form>"); print_r("</form>");
} }
// for cron, needs add to url ...&lang=all&proceed=1 // for cron, needs add to url ...&lang=all&proceed=1
if (isset($_POST['import']) || isset($_GET['proceed'])) { if (isset($_POST['import']) || isset($_GET['proceed'])) {
print_r("importing....<br><br>"); print_r("importing....<br><br>");
// Posts (via Pods framework) creator // Posts (via Pods framework) creator
(new JobsImporter($ads))->import(); (new JobsImporter($ads))->import();
} }
} else { } else {
print_r("<br>There is nothing more to do."); print_r("<br>There is nothing more to do.");
} }
if (isset($_GET['init'])) { if (isset($_GET['init'])) {
print_r("<p><h3>Importing initial data:</h3>"); print_r("<p><h3>Importing initial data:</h3>");
(new importInitData())->import(); (new importInitData())->import();
print_r("</p>"); print_r("</p>");
} }
echo "</pre>"; echo "</pre>";
} }
function getSource($env) function getSource($env)
{ {
$url = parse_url(site_url()); $url = parse_url(site_url());
$exploded = explode('.', $url['host']); $exploded = explode('.', $url['host']);
$site = strtoupper(end($exploded)); $site = strtoupper(end($exploded));
switch ($site) { switch ($site) {
case 'LT': case 'LT':
$script = 'new_wp.php'; $script = 'new_wp.php';
break; break;
case 'LV': case 'LV':
$script = 'new_wp_lv.php'; $script = 'new_wp_lv.php';
break; break;
case 'EE': case 'EE':
$script = 'new_wp_ee.php'; $script = 'new_wp_ee.php';
break; break;
} }
// Set data source path by environment type // Set data source path by environment type
if ($env === 'dev') { if ($env === 'dev') {
// $inputFile = plugin_dir_path(__FILE__) . "source_data/wp_biuro.php.xml"; // $inputFile = plugin_dir_path(__FILE__) . "source_data/wp_biuro.php.xml";
// $inputFile = "https://base.biuro.lt/_export/wp_biuro.php"; // $inputFile = "https://base.biuro.lt/_export/wp_biuro.php";
$inputFile = "https://base.biuro.lt/_export/{$script}"; $inputFile = "https://base.biuro.lt/_export/{$script}";
} elseif ($env === 'prod') { } elseif ($env === 'prod') {
// $inputFile = "http://export.biuro.lt/wp_biuro.php"; // $inputFile = "http://export.biuro.lt/wp_biuro.php";
$inputFile = "http://export.biuro.lt/{$script}"; $inputFile = "http://export.biuro.lt/{$script}";
} }
return $inputFile; return $inputFile;
} }
function getEnvironment() function getEnvironment()
{ {
// Set environment type // Set environment type
$env = 'prod'; $env = 'prod';
//Set dev env. only on dev subdomain //Set dev env. only on dev subdomain
$subDomain = strstr($_SERVER['SERVER_NAME'], '.biuro', true); $subDomain = strstr($_SERVER['SERVER_NAME'], '.biuro', true);
if ($subDomain == 'dev') { if ($subDomain == 'dev') {
$env = 'dev'; $env = 'dev';
} }
return $env; return $env;
} }
function current_location() function current_location()
{ {
if (isset($_SERVER['HTTPS']) && if (isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$protocol = 'https://'; $protocol = 'https://';
} else { } else {
$protocol = 'http://'; $protocol = 'http://';
} }
return $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; return $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
} }
...@@ -276,7 +276,23 @@ get_header(); ...@@ -276,7 +276,23 @@ get_header();
echo __('to', 'biuro') . ' ' . $pod->field( 'salary_to' ) . ' '; echo __('to', 'biuro') . ' ' . $pod->field( 'salary_to' ) . ' ';
endif; endif;
_e('(neto)', 'biuro'); switch ($pod->field('salary_type')):
case 'neto_month':
_e('(neto per month)', 'biuro');
break;
case 'bruto_month':
_e('(bruto per month)', 'biuro');
break;
case 'neto_hour':
_e('(neto per hour)', 'biuro');
break;
case 'bruto_hour':
_e('(bruto per hour)', 'biuro');
break;
default:
_e('(neto)', 'biuro');
break;
endswitch;
endif; endif;
......
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