Commit 6ecb3821 authored by Simonas's avatar Simonas

pre release-0.0.0

parent 54e600b1
This diff is collapsed.
var/
ssh/
wordpress/
node_modules/
logs/nginx/*.log
......
......@@ -12,18 +12,17 @@
- Clone [dev.biuro](http://git.biuro.lt/biuro/dev.biuro) repository
- in Command Prompt run `docker-compose up -d`
- `docker ps` command should output existing docker containers (nginx, mysql, wordpress)
- restore DB as written in *DB restore* section
- set dev.biuro.lt, dev.biuro.lv, dev.biuro.ee to 127.0.0.1 in hosts
- check if dev.biuro.lt, dev.biuro.lv, dev.biuro.ee works
### DB backup
- `C:\web\dev.biuro> docker exec -i mysql mysqldump -uroot -pIiIjnsLi2wR9i1kWVbVpUAzP --default-character-set=utf8 wordpress > docker/mariadb/db_011.sql`
- `C:\web\dev.biuro> docker exec -i dev-biuro-mysql mysqldump -udev_user -pY6V6bFkD6@GyD!wTShgFmWz! --default-character-set=utf8 dev_biuro > docker/mariadb/data-001.sql`
### DB restore
- `C:\web\dev.biuro> docker exec -i mysql mysql -uroot -pIiIjnsLi2wR9i1kWVbVpUAzP --default-character-set=utf8 wordpress < docker/mariadb/db_010.sql`
- `C:\web\dev.biuro> docker exec -i dev-biuro-mysql mysql -udev_user -pY6V6bFkD6@GyD!wTShgFmWz! --default-character-set=utf8 dev_biuro < docker/mariadb/data-000.sql`
## Development
- `C:\web\dev.biuro\wordpress>npm install`
- `C:\web\dev.biuro\ npm install`
## Wordpress
- Regions created using [Wordpress Network](https://codex.wordpress.org/Create_A_Network)
......@@ -37,7 +36,7 @@
#### Akismet Anti-Spam
#### Cookies warning
#### Data controller
#### Gutenberg (not yet)
#### Jobs importer
#### Permalink Manager Lite
#### Pods - Custom Content Types and Fields
#### Polylang
......
......@@ -19,6 +19,8 @@ services:
- ./wp-content/plugins/cookies-warning:/var/www/html/wp-content/plugins/cookies-warning
- ./wp-content/plugins/data-controller:/var/www/html/wp-content/plugins/data-controller
- ./wp-content/plugins/jobs-importer:/var/www/html/wp-content/plugins/jobs-importer
- ./wp-content/plugins/permalink-manager:/var/www/html/wp-content/plugins/permalink-manager
- ./wp-content/plugins/pods:/var/www/html/wp-content/plugins/pods
- ./wp-content/plugins/polylang:/var/www/html/wp-content/plugins/polylang
......@@ -60,6 +62,8 @@ services:
- ./wp-content/plugins/cookies-warning:/var/www/html/wp-content/plugins/cookies-warning
- ./wp-content/plugins/data-controller:/var/www/html/wp-content/plugins/data-controller
- ./wp-content/plugins/jobs-importer:/var/www/html/wp-content/plugins/jobs-importer
- ./wp-content/plugins/permalink-manager:/var/www/html/wp-content/plugins/permalink-manager
- ./wp-content/plugins/pods:/var/www/html/wp-content/plugins/pods
- ./wp-content/plugins/polylang:/var/www/html/wp-content/plugins/polylang
......
This diff is collapsed.
<?php
/**
* Class DataCollector - Prepare data for import into WP posts
*
* @package Biuro Jobs importer
* @used-by \jobs-importer\job-importer.php
*/
class DataCollector
{
// Data mapping
protected $dataMap = [
'livas-id' => '@livas_id',
'valid' => '@valid',
'division' => 'division',
'name' => 'title',
// 'position' => 'PAREIGOS',
'post_content' => 'content',
// 'tag' => 'other_info',
'type' => 'type',
'field' => 'field',
'city' => 'city',
'company' => 'company',
'email' => 'email',
'contact' => 'contact',
'post_date' => '@published_date',
'post_modified' => '@updated',
'lang' => '@lang',
];
// Relations mapping
protected $relationsMap = [
'division' => 'division-id'
];
// Fields, witch separates in metalanguages environment
protected $multilingual = ['city', 'division', /*'position',*/ 'company', 'type', 'field'];
// Records container's node tag name
protected $containerTag = 'ads';
// Item's node tag name
protected $elementTag = 'ad';
// Initial options for xml parser
private $parserDefaults = [
'namespaceSeparator' => ':',//you may want this to be something other than a colon
'attributePrefix' => '@', //to distinguish between attributes and nodes with the same name
'alwaysArray' => array(), //array of xml tag names which should always become arrays
'autoArray' => true, //only create arrays for tags which appear more than once
'textContent' => '$', //key used for the text content of elements
'autoText' => true, //skip textContent key if node has no attributes or child nodes
'keySearch' => false, //optional search and replace on tag and attribute names
'keyReplace' => false //replace values for above search values (as passed to str_replace())
];
// Source data
protected $sourceData;
protected $data;
public function __construct($source)
{
$this->setData($source);
$this->transformData();
}
/**
* Set data source:
* get data from source and transform into array
*
* @param $source
*/
protected function setData($source)
{
$this->sourceData = $this->xmlToArray($this->loadData($source));
}
/**
* Parse xml data
*
* @param $source
*
* @return SimpleXMLElement
*/
protected function loadData($source)
{
$context = stream_context_create([
'http' => [
'header' => 'Accept: application/xml',
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
$xml = file_get_contents($source, false, $context);
return simplexml_load_string($xml);
}
/**
* Get data
*
* @return mixed
*/
public function getData()
{
return $this->data;
}
/**
* Transform data for import
*/
protected function transformData()
{
$transformed = [];
$parsedData = $this->sourceData;
if (array_key_exists($this->containerTag, $parsedData)) {
$container = $parsedData[$this->containerTag];
if (array_key_exists($this->elementTag, $container)) {
foreach ($container[$this->elementTag] as $elementData) {
$lang = $elementData['@lang'];
$element = [];
foreach ($this->dataMap as $key => $item) {
$itemValue = (empty($elementData[$item])) ? '' : $elementData[$item];
$value = (is_array($itemValue))
? [$this->getKey($key, $itemValue, $lang) => html_entity_decode($this->getValue($itemValue))]
: html_entity_decode($itemValue);
$element[$key] = $value;
if (array_key_exists($key, $this->relationsMap)) {
$element['related_items'][$key] = $this->relationsMap[$key];
}
}
$transformed[] = $element;
}
}
}
$this->data = $transformed;
}
/**
* Get value
*
* @param $value
*
* @return mixed|string
*/
private function getValue($value)
{
if (is_array($value)) {
if (array_key_exists('@key', $value)) {
return (isset($value['$'])) ? $value['$'] : '';
}
}
return $value;
}
/**
* Get key
*
* @param $key
* @param $value
* @param $lang
*
* @return string
*/
private function getKey($key, $value, $lang)
{
if (is_array($value)) {
if (array_key_exists('@key', $value)) {
$key_id = '-' . $value['@key'];
return $key . $key_id . $this->addLang($key, $lang);
}
}
return $key . $this->addLang($key, $lang);
}
/**
* Adds language slug
*
* @param $key
* @param $lang
*
* @return string
*/
private function addLang($key, $lang)
{
if (in_array($key, $this->multilingual)) {
return '-' . $lang;
}
return '';
}
/**
* XML parser, return array
*
* @param $xml
* @param array $options
*
* @return array
*/
function xmlToArray($xml, $options = array())
{
$options = array_merge($this->parserDefaults, $options);
$namespaces = $xml->getDocNamespaces();
$namespaces[''] = null; //add base (empty) namespace
//get attributes from all namespaces
$attributesArray = array();
foreach ($namespaces as $prefix => $namespace) {
foreach ($xml->attributes($namespace) as $attributeName => $attribute) {
//replace characters in attribute name
if ($options['keySearch']) {
$attributeName =
str_replace($options['keySearch'], $options['keyReplace'], $attributeName);
}
$attributeKey = $options['attributePrefix']
. ($prefix ? $prefix . $options['namespaceSeparator'] : '')
. $attributeName;
$attributesArray[$attributeKey] = (string)$attribute;
}
}
//get child nodes from all namespaces
$tagsArray = array();
foreach ($namespaces as $prefix => $namespace) {
foreach ($xml->children($namespace) as $childXml) {
//recurse into child nodes
$childArray = $this->xmlToArray($childXml, $options);
// list($childTagName, $childProperties) = each($childArray);
foreach ($childArray as $key => $item) {
$childTagName = $key;
$childProperties = $item;
}
//replace characters in tag name
if ($options['keySearch']) {
$childTagName =
str_replace($options['keySearch'], $options['keyReplace'], $childTagName);
}
//add namespace prefix, if any
if ($prefix) {
$childTagName = $prefix . $options['namespaceSeparator'] . $childTagName;
}
if (!isset($tagsArray[$childTagName])) {
//only entry with this key
//test if tags of this type should always be arrays, no matter the element count
$tagsArray[$childTagName] =
in_array($childTagName, $options['alwaysArray']) || !$options['autoArray']
? array($childProperties) : $childProperties;
} elseif (
is_array($tagsArray[$childTagName]) && array_keys($tagsArray[$childTagName])
=== range(0, count($tagsArray[$childTagName]) - 1)
) {
//key already exists and is integer indexed array
$tagsArray[$childTagName][] = $childProperties;
} else {
//key exists so convert to integer indexed array with previous value in position 0
$tagsArray[$childTagName] = array($tagsArray[$childTagName], $childProperties);
}
}
}
//get text content of node
$textContentArray = array();
$plainText = trim((string)$xml);
if ($plainText !== '') {
$textContentArray[$options['textContent']] = $plainText;
}
//stick it all together
$propertiesArray = !$options['autoText'] || $attributesArray || $tagsArray || ($plainText === '')
? array_merge($attributesArray, $tagsArray, $textContentArray) : $plainText;
//return node as array
return array(
$xml->getName() => $propertiesArray
);
}
}
<?php
/**
* Class JobsImporter - Import data to WP posts with custom fields
*
* @uses Pods framework
* @package Biuro Jobs importer
* @used-by \jobs-importer\job-importer.php
*/
class JobsImporter {
private $data;
// Biuro record unique key
protected $primaryKey = 'livas-id';
// Pods instance
protected $pods;
// Posts container in WP
protected $podsType = 'job';
// Additional post fields
protected $postProperties = [
'post_status' => 'publish',
'comment_status' => 'closed'
];
public function __construct($data)
{
$this->data = $data;
$this->setPods();
}
/**
* Set Pods instance
*/
private function setPods()
{
$this->pods = pods($this->podsType);
}
/**
* Get related items mapping array and remove it from data array
*
* @param $data
*
* @return array
*/
private function getRelations(&$data)
{
$relations = [];
if (array_key_exists('related_items', $data)) {
$relations = $data['related_items'];
unset($data['related_items']);
}
return $relations;
}
/**
* Import posts from provided data: if post with given Id exists, it rewrites
*/
public function import()
{
foreach ($this->data as $ad) {
// Get related items
$relations = $this->getRelations($ad);
// Prepare data array fro importing
$this->prepare($ad, $relations);
// Unique key of post
$primaryKey = $ad[$this->primaryKey];
$pod = $this->getPod($primaryKey);
if ($pod->total_found() > 0) {
try {
$podId = $pod->save(array_merge($ad, $this->postProperties));
print_r("Old record ($this->idKey: $primaryKey) has been updated. <br>");
} catch (Exception $e) {
print_r("Error while updating record ($this->idKey: $primaryKey). Error: $e->getMessage()<br>");
}
} else {
try {
$podId = $this->pods->add(array_merge($ad, $this->postProperties));
print_r("New record ($this->idKey: $primaryKey) has been created. <br>");
} catch (Exception $e) {
print_r("Error while creating record ($this->idKey: $primaryKey). Error: $e->getMessage()<br>");
}
}
if (isset($podId)) {
// Set post language
$this->setPostLang($podId, $ad['lang']);
}
}
}
/**
* Creates related pods if needed and prepare data array fro import
*
* @param $ad
* @param $relations
*/
private function prepare(&$ad, $relations)
{
foreach ($ad as $key => $item) {
$lang = $ad['lang'];
if (is_array($item)) {
$slug = array_keys($item)[0];
$value = array_values($item)[0];
$termId = $this->getTerm($key, $slug, $value, $lang);
$ad[$key] = $slug;
// Adding related item if exists
if (array_key_exists($key, $relations)) {
$ad[$relations[$key]] = $termId;
}
}
}
}
/**
* Find and return pod id, if not exist, create it
*
* @param $key
* @param $slug
* @param $value
* @param $lang
*
* @return int
*/
private function getTerm($key, $slug, $value, $lang)
{
$term = pods($key, $slug);
if ( ! $term->exists()) {
try {
$termId = pods($key)->add([
'name' => $value,
'slug' => $slug,
]);
if ($termId) {
$this->setTermLang($termId, $lang);
return $termId;
}
} catch (Exception $e) {
print_r("Error while adding taxonomies ($key => $slug). Error: $e->getMessage()<br>");
}
}
return $term->id();
}
/**
* Set language param for given pod, using Polylang library
*
* @param $termId
* @param $lang
*/
private function setPostLang($termId, $lang)
{
try {
PLL()->model->post->set_language($termId, $lang);
print_r("Set language code '$lang' for item. <br>");
} catch (Exception $e) {
print_r("Error while setting language code for item, error: $e->getMessage().<br>");
}
}
/**
* Set language param for given taxonomy, using Polylang library
*
* @param $termId
* @param $lang
*/
private function setTermLang($termId, $lang)
{
try {
// PLL()->model->post->set_language($termId, $lang);
PLL()->model->term->save_translations($termId, $lang);
print_r("Set language code '$lang' for item. <br>");
} catch (Exception $e) {
print_r("Error while setting language code for item, error: $e->getMessage().<br>");
}
}
/**
* Get pod by given id
*
* @param $id
*
* @return mixed
*/
private function getPod($id)
{
$params = [
'where' => [
'relation' => 'AND',
[
'value' => (int) $id,
'key' => $this->idKey,
'compare' => '=',
]
]
];
return $this->pods->find($params);
}
}
<?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 'DataCollector.php';
// Data importer: imports data to WP posts
require_once 'JobsImporter.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()
{
// Set environment type
// $env = 'prod';
$env = 'dev';
// 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";
} elseif ($env === 'prod') {
$inputFile = "http://export.biuro.lt/wp_biuro.php";
}
echo "<pre>";
print_r('<h4>Biuro Jobs importer</h4>');
print_r("Running in <strong>$env</strong> environment.");
echo "<br><br>";
print_r("Data source: $inputFile<br>");
// XML reader
$ads = (new DataCollector($inputFile))->getData();
print_r("Found " . count($ads) . " ads from Biuro.<br>");
if (count($ads) > 0) {
print_r("importing....<br><br>");
// Posts (via Pods framework) creator
(new JobsImporter($ads))->import();
} else {
print_r("<br>There is nothing more to do.");
}
echo "</pre>";
}
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<SKELBIMAI>
<SKELBIMAS ID="13138" KALBA="en" TIPAS="1" PASKELBTA="0000-00-00" GALIOJA="2018-11-30" ATNAUJINTA="2018-11-29 10:13:24">
<IMONE>BIURO - padedame, kai labiausiai reikia. Paprastas ir greitas laikinasis įdarbinimas.</IMONE>
<LOGO></LOGO>
<RUSIS>Pastovus darbas</RUSIS>
<SRITIS>Administravimas </SRITIS>
<PAREIGOS>DIREKTORIUS</PAREIGOS>
<APRASYMAS><![CDATA[
&lt;div class="biuro-ti"&gt;
&lt;div class="biuro-ti-img"&gt;
&lt;img src="http://biuro.lt/job-ads/job-description.jpg" alt="" width="40" height="51"&gt;
&lt;/div&gt;
&lt;div class="biuro-ti-text"&gt;
&lt;h3&gt;Užduotys būsimam (-ai) darbuotojui (-ai):&lt;/h3&gt;
&lt;p&gt;Gerai vadovaut&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="biuro-ti"&gt;
&lt;div class="biuro-ti-img"&gt;
&lt;img src="http://biuro.lt/job-ads/job-requirements.jpg" alt="" width="39" height="46"&gt;
&lt;/div&gt;
&lt;div class="biuro-ti-text"&gt;
&lt;h3&gt;Tikimės šių savybių ir įgūdžių:&lt;/h3&gt;
&lt;p&gt;Vadovavimo&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="biuro-ti"&gt;
&lt;div class="biuro-ti-img"&gt;
&lt;img src="http://biuro.lt/job-ads/job-offer-eu.jpg" alt="" width="38" height="52"&gt;
&lt;/div&gt;
&lt;div class="biuro-ti-text"&gt;
&lt;h3&gt;Siūlome:&lt;/h3&gt;
&lt;p&gt;Maisto&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
]]></APRASYMAS>
<KITA><![CDATA[
&lt;div class="biuro-ti"&gt;
&lt;div class="biuro-ti-img"&gt;
&lt;img src="https://biuro.lt/job-ads/job-contacts.jpg" alt="" width="33" height="48"&gt;
&lt;/div&gt;
&lt;div class="biuro-ti-text"&gt;
&lt;h3&gt;Kontaktinė informacija:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;skambinkite &lt;a class="gtm-b2c-phone-click" href="tel:866611222"&gt;866611222&lt;/a&gt;;&lt;/li&gt;
&lt;li&gt;rašykite &lt;a class="gtm-b2c-email-click" href="mailto:andrius.mickus@biuro.eu"&gt;andrius.mickus@biuro.eu&lt;/a&gt; laiško pavadinime nurodant „Direktorius“;&lt;/li&gt;
&lt;li&gt;registruokitės internetu per 30 sekundžių: &lt;a href="https://www.biuro.lt/darbo-paieska/klauskite/"&gt;https://www.biuro.lt/darbo-paieska/klauskite/&lt;/a&gt;;&lt;/li&gt;
&lt;li&gt;atvykite: &lt;a href="https://maps.google.com/?q=Gedimino pr. 26, Vilnius" target="_blank" rel="noopener"&gt;Gedimino pr. 26, Vilnius&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Sekite naujienas prisijungę prie BIURO Facebook puslapio: &lt;a href="https://www.facebook.com/biuro.lietuva" target="_blank" rel="noopener" onclick="dataLayer.push({'event': 'socialClick', 'socialLabel': 'FB click'});"&gt;https://www.facebook.com/biuro.lietuva&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;]]></KITA>
<VIETA>Vilnius</VIETA>
<RODYTI>
<LANG ID="lt"/>
<LANG ID="en"/>
<LANG ID="ru"/>
</RODYTI>
<EPASTAS>andrius.mickus@biuro.eu</EPASTAS>
<PADALINYS></PADALINYS>
<DARBOLAIKAS></DARBOLAIKAS>
<KONTAKTASMUO></KONTAKTASMUO>
</SKELBIMAS>
<SKELBIMAS ID="12998" KALBA="lt" TIPAS="1" PASKELBTA="0000-00-00" GALIOJA="2018-11-29" ATNAUJINTA="2018-11-29 09:47:56">
<IMONE>BIURO - padedame, kai labiausiai reikia. Paprastas ir greitas laikinasis įdarbinimas.</IMONE>
<LOGO>http://export.biuro.lt/logo/182110322.png</LOGO>
<RUSIS>Pastovus darbas</RUSIS>
<SRITIS>Pramonė / Gamyba </SRITIS>
<PAREIGOS>STALIUS - MONTUOTOJAS</PAREIGOS>
<APRASYMAS><![CDATA[
&lt;div class="biuro-ti"&gt;
&lt;div class="biuro-ti-img"&gt;
&lt;img src="http://biuro.lt/job-ads/job-description.jpg" alt="" width="40" height="51"&gt;
&lt;/div&gt;
&lt;div class="biuro-ti-text"&gt;
&lt;h3&gt;Užduotys būsimam (-ai) darbuotojui (-ai):&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;gaminių paruošimas išvežimui į objektus ir jų montavimas;&lt;/li&gt;
&lt;li&gt;medžio-stiklo konstrukcijų montavimas;&lt;/li&gt;
&lt;li&gt;langų-durų montavimas.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Darbo vieta: Klaipėda&lt;/p&gt;
&lt;p&gt;Darbo grafikas: 8-17, I-V.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="biuro-ti"&gt;
&lt;div class="biuro-ti-img"&gt;
&lt;img src="http://biuro.lt/job-ads/job-requirements.jpg" alt="" width="39" height="46"&gt;
&lt;/div&gt;
&lt;div class="biuro-ti-text"&gt;
&lt;h3&gt;Tikimės šių savybių ir įgūdžių:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;gebėjimo skaityti brėžinius;&lt;/li&gt;
&lt;li&gt;techninio supratimo;&lt;/li&gt;
&lt;li&gt;B kategorijos vairuotojo pažymėjimo;&lt;/li&gt;
&lt;li&gt;panaši darbo patirtis privalumas.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="biuro-ti"&gt;
&lt;div class="biuro-ti-img"&gt;
&lt;img src="http://biuro.lt/job-ads/job-offer-eu.jpg" alt="" width="38" height="52"&gt;
&lt;/div&gt;
&lt;div class="biuro-ti-text"&gt;
&lt;h3&gt;Siūlome:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;pastovų darbo grafiką;&lt;/li&gt;
&lt;li&gt;priedus pagal atlikto darbo rezultatus;&lt;/li&gt;
&lt;li&gt;socialines garantijas ir laiku mokamą darbo užmokestį.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
]]></APRASYMAS>
<KITA><![CDATA[
&lt;div class="biuro-ti"&gt;
&lt;div class="biuro-ti-img"&gt;
&lt;img src="https://biuro.lt/job-ads/job-contacts.jpg" alt="" width="33" height="48"&gt;
&lt;/div&gt;
&lt;div class="biuro-ti-text"&gt;
&lt;h3&gt;Kontaktinė informacija:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;skambinkite &lt;a class="gtm-b2c-phone-click" href="tel:+370 46 246648"&gt;+370 46 246648&lt;/a&gt;;&lt;/li&gt;
&lt;li&gt;rašykite &lt;a class="gtm-b2c-email-click" href="mailto:klaipedacv@biuro.lt"&gt;klaipedacv@biuro.lt&lt;/a&gt; laiško pavadinime nurodant „Stalius - montuotojas“;&lt;/li&gt;
&lt;li&gt;registruokitės internetu per 30 sekundžių: &lt;a href="https://www.biuro.lt/darbo-paieska/klauskite/"&gt;https://www.biuro.lt/darbo-paieska/klauskite/&lt;/a&gt;;&lt;/li&gt;
&lt;li&gt;atvykite: &lt;a href="https://maps.google.com/?q=Pilies g. 8 - 101, Klaipėda" target="_blank" rel="noopener"&gt;Pilies g. 8 - 101, Klaipėda&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Sekite naujienas prisijungę prie BIURO Facebook puslapio: &lt;a href="https://www.facebook.com/biuro.lietuva" target="_blank" rel="noopener" onclick="dataLayer.push({'event': 'socialClick', 'socialLabel': 'FB click'});"&gt;https://www.facebook.com/biuro.lietuva&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;]]></KITA>
<VIETA>Klaipėda</VIETA>
<RODYTI>
<LANG ID="lt"/>
</RODYTI>
<EPASTAS>klaipedacv@biuro.lt</EPASTAS>
<PADALINYS></PADALINYS>
<DARBOLAIKAS></DARBOLAIKAS>
<KONTAKTASMUO></KONTAKTASMUO>
</SKELBIMAS>
</SKELBIMAI>
......@@ -8,8 +8,9 @@ class Permalink_Manager_Actions extends Permalink_Manager_Class {
add_action('admin_init', array($this, 'trigger_action'), 9);
add_action('admin_init', array($this, 'extra_actions'));
// Ajax-based bulk tools
// Ajax-based functions
add_action('wp_ajax_pm_bulk_tools', array($this, 'pm_bulk_tools'));
add_action('wp_ajax_pm_save_permalink', array($this, 'pm_save_permalink'));
add_action('clean_permalinks_event', array($this, 'clean_permalinks_hook'));
add_action('init', array($this, 'clean_permalinks_cronjob'));
......@@ -189,6 +190,24 @@ class Permalink_Manager_Actions extends Permalink_Manager_Class {
die();
}
/**
* Save permalink via AJAX
*/
public function pm_save_permalink() {
$element_id = (!empty($_POST['permalink-manager-edit-uri-element-id'])) ? sanitize_text_field($_POST['permalink-manager-edit-uri-element-id']) : '';
if(!empty($element_id) && is_numeric($element_id)) {
Permalink_Manager_URI_Functions_Post::update_post_uri($element_id);
// Reload URI Editor
$element = get_post($element_id);
$html = Permalink_Manager_Admin_Functions::display_uri_box($element, true);
echo $html;
die();
}
}
/**
* Update all permalinks in "Permalink Editor"
*/
......
......@@ -420,7 +420,7 @@ class Permalink_Manager_Core_Functions extends Permalink_Manager_Class {
global $wp_query, $permalink_manager_uris, $permalink_manager_redirects, $permalink_manager_external_redirects, $permalink_manager_options, $wp, $pm_query, $pm_uri_parts;
// Do not redirect on author pages & front page
if(is_author() || is_front_page() || is_home()) { return false; }
if(is_author() || is_front_page() || is_home() || is_feed()) { return false; }
// Unset 404 if custom URI is detected
if(isset($pm_query['id'])) {
......@@ -497,6 +497,7 @@ class Permalink_Manager_Core_Functions extends Permalink_Manager_Class {
* 1C. Enhance native redirect
*/
if(empty($wp_query->query_vars['do_not_redirect']) && $redirect_mode && !empty($queried_object) && empty($correct_permalink)) {
// Affect only posts with custom URI and old URIs
if(!empty($queried_object->ID) && isset($permalink_manager_uris[$queried_object->ID]) && empty($wp_query->query['preview'])) {
// Ignore posts with specific statuses
......@@ -601,17 +602,20 @@ class Permalink_Manager_Core_Functions extends Permalink_Manager_Class {
}
// Do nothing for posts and terms without custom URIs (when canonical redirect is enabled)
$element = get_queried_object();
if(!empty($element->ID)) {
$custom_uri = (!empty($permalink_manager_uris[$element->ID])) ? $permalink_manager_uris[$element->ID] : "";
} else if(!empty($element->term_id)) {
$custom_uri = (!empty($permalink_manager_uris["tax-{$element->term_id}"])) ? $permalink_manager_uris["tax-{$element->term_id}"] : "";
if(is_singular() || is_tax() || is_category() || is_tag()) {
$element = get_queried_object();
if(!empty($element->ID)) {
$custom_uri = (!empty($permalink_manager_uris[$element->ID])) ? $permalink_manager_uris[$element->ID] : "";
} else if(!empty($element->term_id)) {
$custom_uri = (!empty($permalink_manager_uris["tax-{$element->term_id}"])) ? $permalink_manager_uris["tax-{$element->term_id}"] : "";
}
}
//if(empty($custom_uri) && !empty($permalink_manager_options['general']['canonical_redirect'])) { return; }
if(!empty($permalink_manager_options['general']['canonical_redirect'])) { return; }
if(!($permalink_manager_options['general']['canonical_redirect']) || !empty($wp->query_vars['do_not_redirect'])) {
remove_action('template_redirect', 'wp_old_slug_redirect');
remove_action('template_redirect', 'redirect_canonical');
add_filter('wpml_is_redirected', '__return_false', 99, 2);
add_filter('pll_check_canonical_url', '__return_false', 99, 2);
......
<?php
/**
* Additional hooks for "Permalink Manager Pro"
*/
class Permalink_Manager_Gutenberg extends Permalink_Manager_Class {
public function __construct() {
add_action('enqueue_block_editor_assets', array($this, 'init'));
}
public function init() {
// add_action('enqueue_block_editor_assets', array($this, 'pm_gutenberg_scripts'));
add_meta_box('permalink-manager', __('Permalink Manager', 'permalink-manager'), array($this, 'meta_box'), 'post', 'side', 'high' );
}
public function pm_gutenberg_scripts() {
wp_enqueue_script( 'permalink-manager-gutenberg', PERMALINK_MANAGER_URL . '/out/permalink-manager-gutenberg.js', array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-i18n', ), PERMALINK_MANAGER_VERSION, true );
}
public function meta_box($post) {
global $permalink_manager_uris;
if(empty($post->ID)) {
return '';
}
// Display URI Editor
echo Permalink_Manager_Admin_Functions::display_uri_box($post, true);
}
}
?>
......@@ -433,9 +433,10 @@ class Permalink_Manager_Helper_Functions extends Permalink_Manager_Class {
$clean = ($force_lowercase) ? strtolower(trim($clean, '-')) : trim($clean, '-');
// Remove special characters
if($sanitize_slugs) {
if($sanitize_slugs !== false) {
$clean = preg_replace("/[\s_|+-]+/", "-", $clean);
$clean = preg_replace("/[\.]+/", "", $clean);
$clean = preg_replace('/([-\s+]\/[-\s+])/', '-', $clean);
} else {
$clean = preg_replace("/[\s]+/", "-", $clean);
}
......@@ -447,13 +448,23 @@ class Permalink_Manager_Helper_Functions extends Permalink_Manager_Class {
* Clear the URI
*/
public static function clear_single_uri($uri) {
$uri = preg_replace('/\s+/', '', $uri);
$uri = str_replace('//', '/', $uri);
$uri = preg_replace("/[\s_|+-]+/", "-", $uri);
$uri = preg_replace('/([-\s+]\/[-\s+])/', '-', $uri);
$uri = str_replace(array('-/', '/-', '//'), '/', $uri);
$uri = trim($uri, "/");
return $uri;
}
/**
* Remove all slashes
*/
public static function remove_slashes($uri) {
$uri = preg_replace("/[\/]+/", "", $uri);
return $uri;
}
/**
* Force custom slugs
*/
......@@ -462,6 +473,7 @@ class Permalink_Manager_Helper_Functions extends Permalink_Manager_Class {
if(!empty($permalink_manager_options['general']['force_custom_slugs'])) {
$title = (!empty($object->name)) ? $object->name : $object->post_title;
$title = self::remove_slashes($title);
$old_slug = basename($slug);
$new_slug = self::sanitize_title($title, false, null, true);
......
......@@ -32,11 +32,6 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
add_filter('template_redirect', array($this, 'wpml_redirect'), 0, 998 );
} else if(isset($sitepress_settings['language_negotiation_type']) && $sitepress_settings['language_negotiation_type'] == 3) {
add_filter('permalink-manager-detect-uri', array($this, 'wpml_ignore_lang_query_parameter'), 9);
// Append query parameter
add_filter('permalink_manager_filter_final_term_permalink', array($this, 'wpml_append_lang_query_parameter'), 9, 2);
add_filter('permalink_manager_filter_final_post_permalink', array($this, 'wpml_append_lang_query_parameter'), 9, 2);
add_filter('permalink_manager_filter_post_sample_permalink', array($this, 'wpml_append_lang_query_parameter'), 9, 2);
}
// Translate slugs
......@@ -53,10 +48,7 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
add_filter('request', array($this, 'enable_amp'), 10, 1);
}
// 4. WP All Import
add_action('pmxi_after_xml_import', array($this, 'pmxi_fix_permalinks'), 10);
// 5. WooCommerce
// 3. WooCommerce
if(class_exists('WooCommerce')) {
add_filter('request', array($this, 'woocommerce_detect'), 9, 1);
add_filter('template_redirect', array($this, 'woocommerce_checkout_fix'), 9);
......@@ -72,27 +64,27 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
}
}
// 6. Theme My Login
// 4. Theme My Login
if(class_exists('Theme_My_Login')) {
add_filter('permalink_manager_filter_final_post_permalink', array($this, 'tml_keep_query_parameters'), 9, 3);
}
// 7. Yoast SEO
// 5. Yoast SEO
add_filter('wpseo_xml_sitemap_post_url', array($this, 'yoast_fix_sitemap_urls'));
// 8. WooCommerce Wishlist Plugin
// 6. WooCommerce Wishlist Plugin
if(function_exists('tinv_get_option')) {
add_filter('permalink-manager-detect-uri', array($this, 'ti_woocommerce_wishlist_uris'), 15, 3);
}
// 9. Revisionize
// 7. Revisionize
if(defined('REVISIONIZE_ROOT')) {
add_action('revisionize_after_create_revision', array($this, 'revisionize_keep_post_uri'), 9, 2);
add_action('revisionize_before_publish', array($this,'revisionize_clone_uri'), 9, 2);
}
// 10. WP All Import
if(class_exists('PMXI_Plugin')) {
// 8. WP All Import
if(class_exists('PMXI_Plugin') && (empty($permalink_manager_options['general']['pmxi_import_support']))) {
add_action('pmxi_extend_options_featured', array($this, 'wpaiextra_uri_display'), 9, 2);
add_filter('pmxi_options_options', array($this, 'wpai_api_options'));
add_filter('pmxi_addons', array($this, 'wpai_api_register'));
......@@ -115,6 +107,10 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
if(!empty($query_vars['image_id']) && !empty($query_vars['gallery_id'])) {
$wp_query->query_vars['do_not_redirect'] = 1;
}
// Ultimate member
else if(!empty($query_vars['um_user']) && !empty($query_vars['um_user'])) {
$wp_query->query_vars['do_not_redirect'] = 1;
}
}
}
......@@ -205,7 +201,7 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
}
foreach($domains as &$domain) {
$domain = preg_replace("/(http(s)?:\/\/(www\.)?)?(.+?)\/?$/", "http://$4", $domain);
$domain = preg_replace('/((http(s)?:\/\/(www\.)?)|(www\.))?(.+?)\/?$/', 'http://$6', $domain);
}
$request_url = trim(str_replace($domains, "", $request_url), "/");
......@@ -279,21 +275,6 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
return $base;
}
function wpml_append_lang_query_parameter($permalink, $element) {
$lang = self::wpml_get_language_code($element);
$def_lang = self::get_default_language();
if(!empty($lang) && ($def_lang != $lang)) {
if(filter_var($permalink, FILTER_VALIDATE_URL)) {
$permalink = add_query_arg('lang', $lang, $permalink);
} else {
$permalink .= "?lang={$lang}";
}
}
return $permalink;
}
function wpml_translate_post_type_slug($post_type_slug, $element, $post_type) {
$post = (is_integer($element)) ? get_post($element) : $element;
$language_code = self::wpml_get_language_code($post);
......@@ -365,7 +346,7 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
}
/**
* 3. Custom Permalinks
* Parse Custom Permalinks
*/
public static function custom_permalinks_uris() {
global $wpdb;
......@@ -421,32 +402,7 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
}
/**
* 4. WP All Import
*/
function pmxi_fix_permalinks($import_id) {
global $permalink_manager_uris, $wpdb;
$post_ids = $wpdb->get_col($wpdb->prepare("SELECT post_id FROM {$wpdb->prefix}pmxi_posts WHERE import_id = %s", $import_id));
// Just in case
sleep(3);
if(array($post_ids)) {
foreach($post_ids as $id) {
// Continue only if no custom URI is already assigned
if(!empty($permalink_manager_uris[$id])) { continue; }
// Get default post URI
$new_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($id);
$permalink_manager_uris[$id] = $new_uri;
}
}
update_option('permalink-manager-uris', $permalink_manager_uris);
}
/**
* 5. WooCommerce
* 3. WooCommerce
*/
function woocommerce_detect($query) {
global $woocommerce, $pm_query;
......@@ -501,7 +457,7 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
}
/**
* 6. Theme My Login
* 4. Theme My Login
*/
function tml_keep_query_parameters($permalink, $post, $old_permalink) {
// Get the query string from old permalink
......@@ -511,7 +467,7 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
}
/**
* 7. Fix Yoast's homepage URL
* 5. Fix Yoast's homepage URL
*/
function yoast_fix_sitemap_urls($permalink) {
if(class_exists('WPSEO_Utils')) {
......@@ -525,7 +481,7 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
}
/**
* 8. Support WooCommerce Wishlist Plugin
* 6. Support WooCommerce Wishlist Plugin
*/
function ti_woocommerce_wishlist_uris($uri_parts, $request_url, $endpoints) {
global $permalink_manager_uris, $wp;
......@@ -550,7 +506,7 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
}
/**
* 9. Revisionize
* 7. Revisionize
*/
function revisionize_keep_post_uri($old_id, $new_id) {
global $permalink_manager_uris;
......@@ -576,7 +532,7 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
}
/**
* 10. WP All Import
* 8. WP All Import
*/
function wpaiextra_uri_display($post_type, $current_values) {
......@@ -663,27 +619,25 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
function wpai_api_import_function($importData, $parsedData) {
global $permalink_manager_uris;
// Check if post type is disabled
if(empty($parsedData) || Permalink_Manager_Helper_Functions::is_disabled($importData['post_type'], 'post_type')) { return; }
// Get the parsed custom URI
$index = (!empty($importData['i'])) ? $importData['i'] : false;
$pid = (!empty($importData['pid'])) ? $importData['pid'] : false;
if($pid && $index && !empty($parsedData['custom_uri'][$index])) {
$custom_uri = $parsedData['custom_uri'][$index];
// Store only URIs
$custom_uri = parse_url($custom_uri, PHP_URL_PATH);
// Sanitize the output
$custom_uri = Permalink_Manager_Helper_Functions::sanitize_title($custom_uri);
if($index && $pid && !empty($parsedData['custom_uri'][$index])) {
$custom_uri = Permalink_Manager_Helper_Functions::sanitize_title($parsedData['custom_uri'][$index]);
$permalink_manager_uris[$pid] = $custom_uri;
update_option('permalink-manager-uris', $permalink_manager_uris);
if(!empty($custom_uri)) {
$permalink_manager_uris[$pid] = $custom_uri;
update_option('permalink-manager-uris', $permalink_manager_uris);
}
}
}
function wpai_save_redirects($pid) {
global $permalink_manager_external_redirects;
global $permalink_manager_external_redirects, $permalink_manager_uris;
$external_url = get_post_meta($pid, '_external_redirect', true);
$external_url = (empty($external_url)) ? get_post_meta($pid, 'external_redirect', true) : $external_url;
......@@ -691,6 +645,16 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
if($external_url && class_exists('Permalink_Manager_Pro_Functions')) {
Permalink_Manager_Pro_Functions::save_external_redirect($external_url, $pid);
}
// Save custom URI only if the post type is not disabled (third parameter in get_default_post_uri() function)
if(empty($permalink_manager_uris[$pid])) {
$custom_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($pid, false, true);
if(!empty($custom_uri)) {
$permalink_manager_uris[$pid] = $custom_uri;
update_option('permalink-manager-uris', $permalink_manager_uris);
}
}
}
}
......
......@@ -85,10 +85,8 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
$permalink = "{$home_url}/" . urldecode("/{$permalink}");
}
// 6. Additional filter
$permalink = apply_filters('permalink_manager_filter_final_post_permalink', user_trailingslashit($permalink), $post, $old_permalink);
return $permalink;
// 5. Allow to filter
return apply_filters('permalink_manager_filter_final_post_permalink', user_trailingslashit($permalink), $post, $old_permalink);
}
/**
......@@ -110,12 +108,19 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
/**
* Get the active URI
*/
public static function get_post_uri($post_id, $native_uri = false) {
public static function get_post_uri($post_id, $native_uri = false, $is_draft = false) {
global $permalink_manager_uris;
// Check if input is post object
$post_id = (isset($post_id->ID)) ? $post_id->ID : $post_id;
$final_uri = (!empty($permalink_manager_uris[$post_id])) ? $permalink_manager_uris[$post_id] : self::get_default_post_uri($post_id, $native_uri);
if(!empty($permalink_manager_uris[$post_id])) {
$final_uri = $permalink_manager_uris[$post_id];
} else if(!$is_draft) {
$final_uri = self::get_default_post_uri($post_id, $native_uri);
} else {
$final_uri = '';
}
return $final_uri;
}
......@@ -123,7 +128,7 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
/**
* Get the default (not overwritten by the user) or native URI (unfiltered)
*/
public static function get_default_post_uri($post, $native_uri = false) {
public static function get_default_post_uri($post, $native_uri = false, $check_if_disabled = false) {
global $permalink_manager_options, $permalink_manager_uris, $permalink_manager_permastructs, $wp_post_types;
// Load all bases & post
......@@ -135,6 +140,9 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
$post_type = $post->post_type;
$post_name = (empty($post->post_name)) ? Permalink_Manager_Helper_Functions::sanitize_title($post->post_title) : $post->post_name;
// 1A. Check if post type is allowed
if($check_if_disabled && Permalink_Manager_Helper_Functions::is_disabled($post_type, 'post_type')) { return ''; }
// 1. Get the permastruct
if($post_type == 'attachment') {
$parent_page = ($post->post_parent > 0 && $post->post_parent != $post->ID) ? get_post($post->post_parent) : false;
......@@ -182,10 +190,11 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
$post_type_slug = $post_type;
}
$post_type_slug = apply_filters('permalink_manager_filter_post_type_slug', $post_type_slug, $post, $post_type);
$post_type_slug = preg_replace('/(%([^%]+)%\/?)/', '', $post_type_slug);
// 3B. Get the full slug
$custom_slug = Permalink_Manager_Helper_Functions::force_custom_slugs($post_name, $post);
$full_custom_slug = Permalink_Manager_Helper_Functions::force_custom_slugs($post_name, $post);
$post_name = Permalink_Manager_Helper_Functions::remove_slashes($post_name);
$custom_slug = $full_custom_slug = Permalink_Manager_Helper_Functions::force_custom_slugs($post_name, $post);
$full_native_slug = $post_name;
// 3A. Fix for hierarchical CPT (start)
......@@ -381,8 +390,9 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
// Get default & native URL
$native_uri = self::get_default_post_uri($row['ID'], true);
$default_uri = self::get_default_post_uri($row['ID']);
$old_post_name = $row['post_name'];
$old_uri = (isset($permalink_manager_uris[$row['ID']])) ? $permalink_manager_uris[$row['ID']] : $default_uri;
$old_uri = (isset($permalink_manager_uris[$row['ID']])) ? $permalink_manager_uris[$row['ID']] : $native_uri;
// Do replacement on slugs (non-REGEX)
if(preg_match("/^\/.+\/[a-z]*$/i", $old_string)) {
......@@ -397,7 +407,7 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
$new_uri = ($mode != 'slugs') ? str_replace($old_string, $new_string, $old_uri) : $old_uri;
}
//print_r("{$old_uri} - {$new_uri} - {$native_uri} - {$default_uri} \n");
// echo "{$old_uri} - {$new_uri} - {$native_uri} - {$default_uri} \n";
// Check if native slug should be changed
if(($mode == 'slugs') && ($old_post_name != $new_post_name)) {
......@@ -448,7 +458,7 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
$native_uri = self::get_default_post_uri($row['ID'], true);
$default_uri = self::get_default_post_uri($row['ID']);
$old_post_name = $row['post_name'];
$old_uri = isset($permalink_manager_uris[$row['ID']]) ? trim($permalink_manager_uris[$row['ID']], "/") : $native_uri;
$old_uri = isset($permalink_manager_uris[$row['ID']]) ? trim($permalink_manager_uris[$row['ID']], "/") : '';
$correct_slug = ($mode == 'slugs') ? sanitize_title($row['post_title']) : Permalink_Manager_Helper_Functions::sanitize_title($row['post_title']);
// Process URI & slug
......@@ -457,7 +467,7 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
// Prepare the new URI
if($mode == 'slugs') {
$new_uri = $old_uri;
$new_uri = ($old_uri) ? $old_uri : $native_uri;
} else if($mode == 'native') {
$new_uri = $native_uri;
} else {
......@@ -575,12 +585,12 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
// Do not change anything if post is not saved yet (display sample permalink instead)
if(get_option('page_on_front') == $id) {
$uri = $sample_permalink_uri = "";
$$sample_permalink_uri = "";
}
else if($autosave || empty($post->post_status)) {
$uri = $sample_permalink_uri = $default_uri;
$sample_permalink_uri = $default_uri;
} else {
$uri = $sample_permalink_uri = (!empty($permalink_manager_uris[$id])) ? $permalink_manager_uris[$id] : $native_uri;
$sample_permalink_uri = (!empty($permalink_manager_uris[$id])) ? $permalink_manager_uris[$id] : $native_uri;
}
// Decode URI & allow to filter it
......@@ -594,12 +604,10 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
// Append new HTML output
$html .= sprintf("<span class=\"sample-permalink-span\"><a id=\"sample-permalink\" href=\"%s\">%s</a></span>&nbsp;", strip_tags($sample_permalink), $sample_permalink);
$html .= (!$autosave) ? Permalink_Manager_Admin_Functions::display_uri_box($post, $default_uri, $uri, $native_uri) : "";
$html .= (!$autosave) ? Permalink_Manager_Admin_Functions::display_uri_box($post) : "";
// Append hidden field with native slug
// $html .= (!empty($post->post_name)) ? "<input id=\"new-post-slug\" value=\"{$post->post_name}\" autocomplete=\"off\" type=\"hidden\">" : "";
$html .= (!empty($post->post_name)) ? "<span id=\"editable-post-name-full\">{$post->post_name}</span>" : "";
// $html .= (!empty($post->post_name)) ? "<span id=\"editable-post-name-full\">{$uri}</span>" : "";
return $html;
}
......@@ -639,8 +647,8 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
function new_post_uri($post_id) {
global $post, $permalink_manager_uris, $permalink_manager_options, $permalink_manager_before_sections_html;
// Do not trigger if post is a revision
if(wp_is_post_revision($post_id)) { return $post_id; }
// Do not trigger if post is a revision or imported via WP All Import (URI should be set after the post meta is added)
if(wp_is_post_revision($post_id) || (!empty($_REQUEST['page']) && $_REQUEST['page'] == 'pmxi-admin-import')) { return $post_id; }
// Prevent language mismatch in MultilingualPress plugin
if(is_admin() && !empty($post->ID) && $post->ID != $post_id) { return $post_id; }
......@@ -681,7 +689,7 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
/**
* Update URI from "Edit Post" admin page
*/
function update_post_uri($post_id) {
static public function update_post_uri($post_id) {
global $permalink_manager_uris, $permalink_manager_options, $permalink_manager_before_sections_html;
// Verify nonce at first
......@@ -690,8 +698,8 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
// Do not do anything if post is autosaved
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; }
// Do not do anything on in "Bulk Edit"
if(!empty($_REQUEST['bulk_edit'])) { return $post_id; }
// Do not do anything on in "Bulk Edit" or when the post is imported via WP All Import
if(!empty($_REQUEST['bulk_edit']) || (!empty($_REQUEST['page']) && $_REQUEST['page'] == 'pmxi-admin-import')) { return $post_id; }
// Do not do anything if the field with URI or element ID are not present
if(!isset($_POST['custom_uri']) || empty($_POST['permalink-manager-edit-uri-element-id'])) { return $post_id; }
......@@ -739,10 +747,8 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
}
// Save only changed URIs
//if($new_uri != $old_uri) {
$permalink_manager_uris[$post_id] = $new_uri;
update_option('permalink-manager-uris', $permalink_manager_uris);
//}
$permalink_manager_uris[$post_id] = $new_uri;
update_option('permalink-manager-uris', $permalink_manager_uris);
// Update the slug (if changed)
if(!empty($_POST['post_name']) && isset($_POST['native_slug']) && ($_POST['native_slug'] !== $_POST['post_name'])) {
......
......@@ -106,6 +106,12 @@ class Permalink_Manager_Settings extends Permalink_Manager_Class {
'input_class' => '',
'description' => __('If enabled, the plugin will load the adjacent translation of post when the custom permalink is detected, but the language code in the URL does not match the language code assigned to the post/term.', 'permalink-manager')
),
'pmxi_import_support' => array(
'type' => 'single_checkbox',
'label' => __('Disable support for WP All Import', 'permalink-manager'),
'input_class' => '',
'description' => __('If checked, the custom URIs will not be assigned to the posts imported by Wp All Import Pro plugin.', 'permalink-manager')
),
'force_custom_slugs' => array(
'type' => 'select',
'label' => __('Force custom slugs', 'permalink-manager'),
......
......@@ -200,7 +200,7 @@ class Permalink_Manager_Tools extends Permalink_Manager_Class {
$sidebar = '<h3>' . __('Important notices', 'permalink-manager') . '</h3>';
$sidebar .= self::display_instructions();
$output = Permalink_Manager_Admin_Functions::get_the_form($fields, 'columns-3', array('text' => __('Find and replace', 'permalink-manager'), 'class' => 'primary margin-top'), $sidebar, array('action' => 'permalink-manager', 'name' => 'find_and_replace'), true);
$output = Permalink_Manager_Admin_Functions::get_the_form($fields, 'columns-3', array('text' => __('Find and replace', 'permalink-manager'), 'class' => 'primary margin-top'), $sidebar, array('action' => 'permalink-manager', 'name' => 'find_and_replace'), true, 'form-ajax');
return $output;
}
......@@ -270,7 +270,7 @@ class Permalink_Manager_Tools extends Permalink_Manager_Class {
$sidebar = '<h3>' . __('Important notices', 'permalink-manager') . '</h3>';
$sidebar .= self::display_instructions();
$output = Permalink_Manager_Admin_Functions::get_the_form($fields, 'columns-3', array('text' => __( 'Regenerate', 'permalink-manager' ), 'class' => 'primary margin-top'), $sidebar, array('action' => 'permalink-manager', 'name' => 'regenerate'), true);
$output = Permalink_Manager_Admin_Functions::get_the_form($fields, 'columns-3', array('text' => __( 'Regenerate', 'permalink-manager' ), 'class' => 'primary margin-top'), $sidebar, array('action' => 'permalink-manager', 'name' => 'regenerate'), true, 'form-ajax');
return $output;
}
......
......@@ -4,7 +4,7 @@
* Plugin Name: Permalink Manager Lite
* Plugin URI: https://permalinkmanager.pro?utm_source=plugin
* Description: Advanced plugin that allows to set-up custom permalinks (bulk editors included), slugs and permastructures (WooCommerce compatible).
* Version: 2.1.1
* Version: 2.1.2
* Author: Maciej Bis
* Author URI: http://maciejbis.net/
* License: GPL-2.0+
......@@ -21,7 +21,7 @@ if (!defined('WPINC')) {
// Define the directories used to load plugin files.
define( 'PERMALINK_MANAGER_PLUGIN_NAME', 'Permalink Manager' );
define( 'PERMALINK_MANAGER_PLUGIN_SLUG', 'permalink-manager' );
define( 'PERMALINK_MANAGER_VERSION', '2.1.1' );
define( 'PERMALINK_MANAGER_VERSION', '2.1.2' );
define( 'PERMALINK_MANAGER_FILE', __FILE__ );
define( 'PERMALINK_MANAGER_DIR', untrailingslashit(dirname(__FILE__)) );
define( 'PERMALINK_MANAGER_BASENAME', dirname(plugin_basename(__FILE__)));
......@@ -182,18 +182,18 @@ class Permalink_Manager_Class {
*/
public function default_alerts($alerts) {
$default_alerts = apply_filters('permalink-manager-default-alerts', array(
'october2018' => array(
'spring' => array(
'txt' => sprintf(
__("Get access to extra features: full taxonomy and WooCommerce support, possibility to use custom fields inside the permalinks and more!<br /><strong>Buy Permalink Manager Pro <a href=\"%s\" target=\"_blank\">here</a> and save %s using \"%s\" coupon code!</strong> Valid until %s!", "permalink-manager"),
PERMALINK_MANAGER_WEBSITE,
'30&#37;',
'OCTOBER',
'31st October'
'20&#37;',
'SPRING',
'31.03'
),
'type' => 'notice-info',
'show' => 'pro_hide',
'plugin_only' => true,
'until' => '2018-11-01'
'until' => '2018-04-01'
)
));
......
<?php
/**
* The front page template file
*
* If the user has selected a static page for their homepage, this is what will
* appear.
* Learn more: https://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage Biuro
* @since 1.0
* @version 1.0
*/
get_header(); ?>
<?php
while ( have_posts() ) :
the_post();
the_content();
endwhile;
?>
<br>
<br>
<h1>Svetainės medis:</h1>
<h2>Darbas + Miestas</h2>
<?php
getSiteTree( 'city' );
?>
<h2>Darbas + Tag'as</h2>
<ul>
<li style="color: red">ToDo: aptarti kaip turi būti LIVAS</li>
</ul>
<h2>Darbas + Sritis</h2>
<?php
getSiteTree( 'field' );
?>
<h2>Darbas + Įmonė</h2>
<?php
getSiteTree( 'company' );
?>
<br>
<br>
<?php get_footer();
......@@ -230,3 +230,28 @@ $m = $l ? wp_get_nav_menu_object( $l[ 'main-menu' ] ) : null;
$items = $m ? wp_get_nav_menu_items( $m->term_id, array( 'order' => 'DESC' ) ) : array();
$searchPageURL = $items[0] ? $items[0]->url : '/';
function getSiteTree($taxonomy)
{
$terms = get_terms( array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
));
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ):
echo '<ul>';
foreach ( $terms as $term ):
$page = get_term_meta( $term->term_id, 'page-id', true);
if ( $page ) :
?>
<li><a href="<?php echo get_page_link( $page['ID'] ); ?>"><?php echo $page['post_title']; ?></a></li>
<?
endif;
endforeach;
echo '</ul>';
endif;
}
......@@ -31,6 +31,8 @@ get_header(); ?>
$ID = get_the_ID();
$keys = get_post_custom_keys();
$where = 'valid.meta_value > "' . date('Y-m-d', strtotime('-1 days')) . '"';
$taxonomies = array();
foreach ( $keys as $key => $value ) {
......@@ -53,24 +55,46 @@ get_header(); ?>
continue;
}
$taxonomies[] = array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $term
);
$where = $where . ' AND ' . $taxonomy . '.slug = "' . $term . '"';
}
$jobs = get_posts( array(
'posts_per_page' => -1,
'post_type' => 'job',
'tax_query' => $taxonomies
) );
$params = array(
'orderby' => 'date DESC',
'where' => $where,
'limit' => 9
);
$jobs = pods( 'job', $params );
// debug($jobs->fetch());
// $jobs = get_posts( array(
// 'posts_per_page' => -1,
// 'post_type' => 'job',
// 'tax_query' => $taxonomies
// ) );
// the_posts_pagination(
// array(
// 'mid_size' => 2,
// 'prev_text' => sprintf( '%s <span class="nav-prev-text">%s</span>', $prev_icon, __( 'Newer posts', 'twentynineteen' ) ),
// 'next_text' => sprintf( '<span class="nav-next-text">%s</span> %s', __( 'Older posts', 'twentynineteen' ), $next_icon ),
// )
// );
if ( 0 < $jobs->total() ):
get_template_part( 'template-parts/jobs/jobs', 'list' );
else:
get_template_part( 'template-parts/jobs/jobs', 'none' );
// debug($jobs);
endif;
foreach ($jobs as $job) :
echo '<h3><a href="' . get_post_permalink( $job->ID ) . '" target="_blank">' . $job->post_title . '</a></h3>';
endforeach;
// foreach ($jobs as $job) :
// echo '<h3><a href="' . get_post_permalink( $job->ID ) . '" target="_blank">' . $job->post_title . '</a></h3>';
// endforeach;
?>
......
......@@ -18,24 +18,6 @@
$periodID = get_query_var('period');
$fieldID = get_query_var('field');
$typeID = get_query_var('type');
// function print()
// $cities = get_terms( 'city', array(
// 'hide_empty' => false,
// ));
// debug($cityID)
// if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
// echo '<ul>';
// foreach ( $terms as $term ) {
// echo '<li>' . $term->name . '</li>';
// }
// echo '</ul>';
// }
?>
<form id="filter-form" action="<?php echo esc_url( $searchPageURL ); ?>" method="get" enctype="application/x-www-form-urlencoded">
......@@ -52,7 +34,8 @@
<select name="city" id="city" class="el_130">
<option value="">Visi miestai</option>
<?php
$cities = get_terms( 'city', array(
$cities = get_terms( array(
'taxonomy' => 'city',
'hide_empty' => false,
));
......@@ -81,7 +64,8 @@
<select name="field" id="field" class="el_130">
<option value="">Visos sritys</option>
<?php
$fields = get_terms( 'field', array(
$fields = get_terms( array(
'taxonomy' => 'field',
'hide_empty' => false,
));
......@@ -101,7 +85,8 @@
<select name="type" id="type" class="el_130">
<option value="">Visos rūšys</option>
<?php
$types = get_terms( 'type', array(
$types = get_terms( array(
'taxonomy' => 'type',
'hide_empty' => false,
));
......@@ -127,7 +112,7 @@
// Use for search
// https://pods.io/docs/code/pods/find/
$where = 't.post_title LIKE "%' . $search . '%"';
$where = 'valid.meta_value > "' . date('Y-m-d', strtotime('-1 days')) . '" AND t.post_title LIKE "%' . $search . '%"';
// 'where' => 't.post_title LIKE "%' . $keyword . '%" OR my_field.meta_value LIKE "%' . $keyword . '%"'
if ($cityID):
......@@ -144,52 +129,21 @@
$params = array(
'orderby' => 'date DESC',
'where' => $where,
'limit' => -1
'limit' => 9
);
$jobs = pods( 'job', $params );
if ( 0 < $jobs->total() ):
$i = 0;
?>
<table cellspacing="0" cellpadding="0" class="advert_table">
<tr>
<th>Pozicija </th>
<th>Vietovė</th>
<th>Data</th>
<th>Rūšis</th>
</tr>
get_template_part( 'template-parts/jobs/jobs', 'list' );
<?php
while ( $jobs->fetch() ) :
$i++;
?>
<tr <?php if ( $i % 2 == 0 ) { echo 'class="bg"'; } ?>>
<td>
<a href="<?php echo get_post_permalink( $jobs->display( 'ID' ) ); ?>" target="_blank" title="<?php echo $jobs->display( 'name' ); ?>">
<strong><?php echo $jobs->display( 'name' ); ?></strong>
</a>
</td>
<td>
<span style="opacity: 0.25;">Šiauliai</span>
</td>
<td>
<span style="opacity: 0.25;">Paskelbta: 2018 11 30 <br> Galioja iki: 2018 12 28</span>
</td>
<td>
<span style="opacity: 0.25;">Nuolatinis darbas</span>
</td>
</tr>
<?php
endwhile;
?>
else:
</table>
get_template_part( 'template-parts/jobs/jobs', 'none' );
<?php
endif;
?>
......
<?php
/**
* Template part for displaying a list of jobs
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package WordPress
* @subpackage Biuro
* @since 1.0.0
*/
global $jobs;
?>
<table cellspacing="0" cellpadding="0" class="advert_table">
<tr>
<th>Pozicija </th>
<th>Vietovė</th>
<th>Data</th>
<th>Rūšis</th>
</tr>
<?php
while ( $jobs->fetch() ) :
$ID = $jobs->display( 'ID' );
$i++;
?>
<tr <?php if ( $i % 2 != 0 ) { echo 'class="bg"'; } ?>>
<td>
<a href="<?php echo get_post_permalink( $ID ); ?>" target="_blank" title="<?php echo $jobs->display( 'name' ); ?>">
<strong><?php echo $jobs->display( 'name' ); ?></strong>
</a>
</td>
<td>
<?php echo $jobs->display( 'city' ); ?>
</td>
<td>
Paskelbta: <?php echo get_the_date( 'Y-m-d', $ID ); ?> <br>Galioja iki: <?php echo get_the_date( $jobs->display( 'valid' ) ); ?>
</td>
<td>
<?php echo $jobs->display( 'type' ); ?>
</td>
</tr>
<?php
endwhile;
?>
</table>
<?php
echo $jobs->pagination( array( 'type' => 'paginate' ) );
?>
<?php
/**
* Template part for displaying a message that jobs cannot be found
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package WordPress
* @subpackage Twenty_Nineteen
* @since 1.0.0
*/
?>
<p>Pagal Jūsų paiešką rezultatų neradome.</p>
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