Commit 99eccbaf authored by Simon's avatar Simon

Salary type added

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