Merge branch 'develop' into feature/activities-page
This commit is contained in:
commit
63599c417a
|
@ -134,7 +134,7 @@ class Admin {
|
|||
* Also used by DevInterface
|
||||
*/
|
||||
function get_admin_js_localization_params() {
|
||||
global $TAINACAN_BASE_URL;
|
||||
global $TAINACAN_BASE_URL, $TAINACAN_API_MAX_ITEMS_PER_PAGE;
|
||||
|
||||
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
|
||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||
|
@ -171,8 +171,8 @@ class Admin {
|
|||
}
|
||||
|
||||
$settings = [
|
||||
'root' => esc_url_raw( rest_url() ) . 'tainacan/v2',
|
||||
'root_wp_api' => esc_url_raw( rest_url() ) . 'wp/v2/',
|
||||
'tainacan_api_url' => esc_url_raw( rest_url() ) . 'tainacan/v2',
|
||||
'wp_api_url' => esc_url_raw( rest_url() ) . 'wp/v2/',
|
||||
'wp_ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'nonce' => wp_create_nonce( 'wp_rest' ),
|
||||
'components' => $components,
|
||||
|
@ -184,9 +184,10 @@ class Admin {
|
|||
'theme_collection_list_url' => get_post_type_archive_link( 'tainacan-collection' ),
|
||||
'custom_header_support' => get_theme_support('custom-header'),
|
||||
'registered_view_modes' => \Tainacan\Theme_Helper::get_instance()->get_registered_view_modes(),
|
||||
'exposer_mapper_param' => \Tainacan\Exposers\Exposers::MAPPER_PARAM,
|
||||
'exposer_type_param' => \Tainacan\Exposers\Exposers::TYPE_PARAM,
|
||||
'repository_name' => get_bloginfo('name')
|
||||
'exposer_mapper_param' => \Tainacan\Mappers_Handler::MAPPER_PARAM,
|
||||
'exposer_type_param' => \Tainacan\Exposers_Handler::TYPE_PARAM,
|
||||
'repository_name' => get_bloginfo('name'),
|
||||
'api_max_items_per_page' => $TAINACAN_API_MAX_ITEMS_PER_PAGE,
|
||||
];
|
||||
|
||||
$maps = [
|
||||
|
|
|
@ -35,17 +35,19 @@
|
|||
Object.keys(exporterSession.mapping_accept).length &&
|
||||
exporterSession.mapping_accept.any"
|
||||
:label="$i18n.get('mapping')">
|
||||
<div
|
||||
v-for="(mapping, key) in exporterSession.mapping_list"
|
||||
:key="key">
|
||||
<b-checkbox
|
||||
|
||||
<b-select
|
||||
@input="updateExporter('mapping_selected')"
|
||||
class="is-capitalized"
|
||||
:native-value="key"
|
||||
v-model="selectedMappings">
|
||||
{{ key.replace(/-/, ' ') }}
|
||||
</b-checkbox>
|
||||
</div>
|
||||
v-model="selectedMappings"
|
||||
>
|
||||
<option
|
||||
v-for="(mapping, key) in exporterSession.mapping_list"
|
||||
:value="key"
|
||||
:key="key">
|
||||
{{ key.replace(/-/, ' ') }}
|
||||
</option>
|
||||
</b-select>
|
||||
|
||||
</b-field>
|
||||
|
||||
<b-field :label="$i18n.get('label_send_email')">
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
</span>
|
||||
</div>
|
||||
|
||||
<div class="field is-pulled-right">
|
||||
<div class="field">
|
||||
<b-dropdown
|
||||
:mobile-modal="true"
|
||||
position="is-bottom-left"
|
||||
|
@ -64,16 +64,21 @@
|
|||
</b-dropdown-item>
|
||||
</b-dropdown>
|
||||
</div>
|
||||
|
||||
<!-- Exposers or alternativa links modal button -->
|
||||
<div class="field">
|
||||
<button
|
||||
class="button is-white"
|
||||
@click="openExposersModal()">
|
||||
<span class="gray-icon">
|
||||
<i class="tainacan-icon tainacan-icon-20px tainacan-icon-url"/>
|
||||
</span>
|
||||
<span class="is-hidden-touch">{{ $i18n.get('label_urls') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-wrapper">
|
||||
<div
|
||||
v-show="isLoading"
|
||||
class="loading-container">
|
||||
<b-loading
|
||||
:is-full-page="false"
|
||||
:active.sync="isLoading"/>
|
||||
</div>
|
||||
|
||||
<!-- GRID (THUMBNAILS) VIEW MODE -->
|
||||
<div
|
||||
|
@ -168,7 +173,9 @@
|
|||
<div
|
||||
:key="index"
|
||||
v-for="(item, index) of items"
|
||||
:class="{ 'selected-masonry-item': selectedItems[index] }"
|
||||
:class="{
|
||||
'selected-masonry-item': selectedItems[index],
|
||||
}"
|
||||
class="tainacan-masonry-item">
|
||||
|
||||
<!-- Checkbox -->
|
||||
|
@ -666,6 +673,7 @@
|
|||
import { mapActions, mapGetters } from 'vuex';
|
||||
import CustomDialog from '../other/custom-dialog.vue';
|
||||
import BulkEditionModal from '../bulk-edition/bulk-edition-modal.vue';
|
||||
import ExposersModal from '../other/exposers-modal.vue';
|
||||
|
||||
export default {
|
||||
name: 'ItemsList',
|
||||
|
@ -711,15 +719,13 @@ export default {
|
|||
this.queryAllItemsSelected = {};
|
||||
} else if(item === true) {
|
||||
isSelecting = true;
|
||||
|
||||
this.selectedItemsIDs.splice(index, 1, this.items[index].id);
|
||||
}
|
||||
});
|
||||
|
||||
if(!allSelected) {
|
||||
if (!allSelected)
|
||||
this.isAllItemsSelected = allSelected;
|
||||
}
|
||||
|
||||
|
||||
this.allItemsOnPageSelected = allSelected;
|
||||
this.isSelectingItems = isSelecting;
|
||||
},
|
||||
|
@ -930,7 +936,18 @@ export default {
|
|||
getLimitedDescription(description) {
|
||||
let maxCharacter = (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) <= 480 ? 100 : 210;
|
||||
return description.length > maxCharacter ? description.substring(0, maxCharacter - 3) + '...' : description;
|
||||
}
|
||||
},
|
||||
openExposersModal() {
|
||||
this.$modal.open({
|
||||
parent: this,
|
||||
component: ExposersModal,
|
||||
hasModalCard: true,
|
||||
props: {
|
||||
collectionId: this.collectionId,
|
||||
totalItems: this.totalItems
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -938,9 +955,9 @@ export default {
|
|||
<style lang="scss" scoped>
|
||||
|
||||
@import "../../scss/_variables.scss";
|
||||
@import "../../scss/_view-mode-cards.scss";
|
||||
@import "../../scss/_view-mode-masonry.scss";
|
||||
@import "../../scss/_view-mode-grid.scss";
|
||||
@import "../../scss/_view-mode-cards.scss";
|
||||
@import "../../scss/_view-mode-records.scss";
|
||||
|
||||
.selection-control {
|
||||
|
@ -948,10 +965,13 @@ export default {
|
|||
padding: 6px 0px 0px 12px;
|
||||
background: white;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
|
||||
.select-all {
|
||||
color: $gray4;
|
||||
font-size: 0.875rem;
|
||||
margin-right: auto;
|
||||
|
||||
&:hover {
|
||||
color: $gray4;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,237 @@
|
|||
<template>
|
||||
<form action="">
|
||||
<div
|
||||
class="tainacan-modal-content"
|
||||
style="width: auto">
|
||||
<header class="tainacan-modal-title">
|
||||
<h2>{{ this.$i18n.get('label_urls') }}</h2>
|
||||
<hr>
|
||||
</header>
|
||||
<section class="tainacan-form">
|
||||
<p>{{ $i18n.get('instruction_select_an_importer_type') }}</p>
|
||||
<div class="exposer-types-container">
|
||||
<b-field
|
||||
:addons="false"
|
||||
class="exposer-type"
|
||||
v-for="(exposerType, index) in availableExposers"
|
||||
:key="index">
|
||||
<span
|
||||
@click="collapse(index)"
|
||||
class="collapse-handle">
|
||||
<span class="icon">
|
||||
<i
|
||||
:class="{ 'tainacan-icon-arrowdown' : !exposerType.collapsed, 'tainacan-icon-arrowright' : exposerType.collapsed }"
|
||||
class="has-text-secondary tainacan-icon tainacan-icon-20px"/>
|
||||
</span>
|
||||
<label
|
||||
v-tooltip="{
|
||||
content: exposerType.name,
|
||||
autoHide: false,
|
||||
placement: 'auto-end'
|
||||
}"
|
||||
class="label">
|
||||
{{ exposerType.name }}
|
||||
</label>
|
||||
<span class="has-text-gray">{{ exposerType.description }}</span>
|
||||
</span>
|
||||
<transition name="filter-item">
|
||||
<div v-show="!exposerType.collapsed">
|
||||
<div>
|
||||
<div
|
||||
:key="pagedLink"
|
||||
v-for="pagedLink in totalPages"
|
||||
class="exposer-item">
|
||||
<span>{{ $i18n.get('label_exposer') + ": " + exposerType.name + ", " + $i18n.get('label_page') + " " + pagedLink }}</span>
|
||||
<span class="exposer-item-actions">
|
||||
<a
|
||||
target="_blank"
|
||||
:href="exposerBaseURL + '&exposer=' + exposerType.slug + '&paged=' + pagedLink">
|
||||
<span class="gray-icon">
|
||||
<i class="tainacan-icon tainacan-icon-20px tainacan-icon-url"/>
|
||||
</span>
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-for="(exposerMapper, index) of exposerType.mappers"
|
||||
:key="index">
|
||||
<div
|
||||
:key="pagedLink"
|
||||
v-for="pagedLink in totalPages"
|
||||
class="exposer-item">
|
||||
<span>{{ $i18n.get('label_exposer') + ": " +
|
||||
exposerType.name + ", " + $i18n.get('label_mapper') + ": " +
|
||||
exposerMapper + ", " + $i18n.get('label_page') + " " + pagedLink }}</span>
|
||||
<span class="exposer-item-actions">
|
||||
<a
|
||||
target="_blank"
|
||||
:href="exposerBaseURL + '&exposer=' + exposerType.slug + '&mapper=' + exposerMapper + '&paged=' + pagedLink">
|
||||
<span class="gray-icon">
|
||||
<i class="tainacan-icon tainacan-icon-20px tainacan-icon-url"/>
|
||||
</span>
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</transition>
|
||||
</b-field>
|
||||
</div>
|
||||
|
||||
<b-loading
|
||||
:active.sync="isLoading"
|
||||
:can-cancel="false"/>
|
||||
<!-- <footer class="field is-grouped form-submit">
|
||||
<div class="control">
|
||||
<button
|
||||
class="button is-outlined"
|
||||
type="button"
|
||||
@click="$parent.close()">Close</button>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button class="button is-success">Confirm</button>
|
||||
</div>
|
||||
</footer> -->
|
||||
</section>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapActions, mapGetters } from 'vuex';
|
||||
import qs from 'qs';
|
||||
|
||||
export default {
|
||||
name: 'ExposersModal',
|
||||
props: {
|
||||
collectionId: Number,
|
||||
totalItems: Number
|
||||
},
|
||||
data(){
|
||||
return {
|
||||
isLoading: false,
|
||||
availableExposers: [],
|
||||
maxItemsPerPage: tainacan_plugin.api_max_items_per_page
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
totalPages() {
|
||||
return Math.ceil(Number(this.totalItems)/Number(this.maxItemsPerPage));
|
||||
},
|
||||
exposerBaseURL() {
|
||||
let baseURL = this.collectionId != undefined ? '/collection/' + this.collectionId + '/items/' : 'items';
|
||||
let currentParams = this.$route.query;
|
||||
|
||||
// Removes Fetch Only
|
||||
if (currentParams.fetch_only != undefined)
|
||||
delete currentParams.fetch_only;
|
||||
|
||||
// Handles pagination of this link
|
||||
delete currentParams.paged;
|
||||
currentParams.perpage = this.maxItemsPerPage;
|
||||
|
||||
return tainacan_plugin.tainacan_api_url + baseURL + '?' + qs.stringify(currentParams);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions('exposer', [
|
||||
'fetchAvailableExposers'
|
||||
]),
|
||||
...mapGetters('exposer', [
|
||||
'getAvailableExposers'
|
||||
]),
|
||||
collapse(index) {
|
||||
let exposer = this.availableExposers[index];
|
||||
this.$set(exposer, 'collapsed', !exposer.collapsed);
|
||||
this.$set(this.availableExposers, index, exposer);
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.isLoading = true;
|
||||
this.fetchAvailableExposers()
|
||||
.then((res) => {
|
||||
let exposers = JSON.parse(JSON.stringify(res));
|
||||
exposers.forEach(item => this.$set(item, 'collapsed', true));
|
||||
this.availableExposers = exposers;
|
||||
|
||||
this.isLoading = false;
|
||||
}).catch((error) => {
|
||||
this.$console.log(error);
|
||||
this.isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@import "../../scss/_variables.scss";
|
||||
|
||||
.exposer-types-container {
|
||||
|
||||
.exposer-type {
|
||||
border-bottom: 1px solid $gray2;
|
||||
padding: 0.75rem $page-side-padding;
|
||||
margin: 0;
|
||||
|
||||
&:first-child {
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
.collapse-handler:hover {
|
||||
cursor: pointer;
|
||||
background-color: $gray1;
|
||||
}
|
||||
.collapse-handle {
|
||||
.label {
|
||||
margin: 3px 0.75rem 0 0;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
}
|
||||
.has-text-gray {
|
||||
font-size: 0.75rem;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
p {
|
||||
padding: 0.5rem 0.75rem;
|
||||
}
|
||||
|
||||
.exposer-item {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
&:first-of-type {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
&>span {
|
||||
padding: 0.5rem 0.75rem;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
&:hover {
|
||||
background-color: $gray1;
|
||||
.exposer-item-actions {
|
||||
background-color: $gray2;
|
||||
}
|
||||
}
|
||||
.exposer-item-actions a {
|
||||
cursor: pointer;
|
||||
margin: 0 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,255 @@
|
|||
<template>
|
||||
<div class="table-container">
|
||||
<div class="selection-control">
|
||||
<div class="field select-all is-pulled-left">
|
||||
<span>
|
||||
<b-checkbox disabled>{{ $i18n.get('label_select_all_items_page') }}</b-checkbox>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="field is-pulled-right">
|
||||
<b-dropdown
|
||||
position="is-bottom-left"
|
||||
disabled>
|
||||
<button
|
||||
class="button is-white"
|
||||
slot="trigger">
|
||||
<span>{{ $i18n.get('label_bulk_actions') }}</span>
|
||||
<span class="icon">
|
||||
<i class="tainacan-icon tainacan-icon-20px tainacan-icon-arrowdown"/>
|
||||
</span>
|
||||
</button>
|
||||
</b-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-wrapper">
|
||||
<table
|
||||
v-if="viewMode == 'table'"
|
||||
class="tainacan-table">
|
||||
<thead>
|
||||
<th class="skeleton column-default-width" />
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
class="skeleton"
|
||||
:key="item"
|
||||
v-for="item in itemsPerPage">
|
||||
<td class="column-default-width"/>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div
|
||||
v-if="viewMode == 'cards' || viewMode == 'grid'"
|
||||
:class="{
|
||||
'tainacan-cards-container': viewMode == 'cards',
|
||||
'tainacan-grid-container': viewMode == 'grid'
|
||||
}">
|
||||
<div
|
||||
:key="item"
|
||||
v-for="item in itemsPerPage"
|
||||
class="skeleton"
|
||||
:class="{
|
||||
'tainacan-card': viewMode == 'cards',
|
||||
'tainacan-grid-item': viewMode == 'grid'
|
||||
}"/>
|
||||
</div>
|
||||
<masonry
|
||||
:cols="getMasonryColsSettings()"
|
||||
:gutter="viewMode == 'masonry' ? 25 : 30"
|
||||
v-if="viewMode == 'masonry' || viewMode == 'records'"
|
||||
:class="{
|
||||
'tainacan-masonry-container': viewMode == 'masonry',
|
||||
'tainacan-records-container': viewMode == 'records'
|
||||
}">
|
||||
<div
|
||||
:key="item"
|
||||
v-for="item in itemsPerPage"
|
||||
:style="{'min-height': randomHeightForMasonryItem() + 'px' }"
|
||||
class="skeleton"
|
||||
:class="{
|
||||
'tainacan-masonry-item': viewMode == 'masonry',
|
||||
'tainacan-record': viewMode == 'records'
|
||||
}"/>
|
||||
</masonry>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapGetters } from 'vuex';
|
||||
|
||||
export default {
|
||||
name: 'SkeletonItemsList',
|
||||
computed: {
|
||||
itemsPerPage(){
|
||||
return this.getItemsPerPage();
|
||||
},
|
||||
viewMode() {
|
||||
return this.getAdminViewMode();
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
...mapGetters('search', [
|
||||
'getItemsPerPage',
|
||||
'getAdminViewMode',
|
||||
]),
|
||||
getMasonryColsSettings() {
|
||||
if (this.viewMode == 'masonry')
|
||||
return { default: 7, 1919: 6, 1407: 5, 1215: 4, 1023: 3, 767: 2, 343: 1 }
|
||||
else
|
||||
return { default: 4, 1919: 3, 1407: 2, 1215: 2, 1023: 1, 767: 1, 343: 1 }
|
||||
|
||||
},
|
||||
randomHeightForMasonryItem() {
|
||||
let min = 255;
|
||||
let max = 255;
|
||||
|
||||
if (this.viewMode == 'masonry') {
|
||||
min = 140;
|
||||
max = 420;
|
||||
} else if (this.viewMode == 'records') {
|
||||
min = 380;
|
||||
max = 480;
|
||||
}
|
||||
|
||||
return Math.floor(Math.random()*(max-min+1)+min);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@import '../../scss/_variables.scss';
|
||||
|
||||
// Selection Area
|
||||
.selection-control {
|
||||
|
||||
padding: 6px 0px 0px 12px;
|
||||
background: white;
|
||||
height: 40px;
|
||||
|
||||
.select-all {
|
||||
color: $gray4;
|
||||
font-size: 0.875rem;
|
||||
&:hover {
|
||||
color: $gray4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cards View Mode
|
||||
.tainacan-cards-container {
|
||||
min-height: 50vh;
|
||||
padding: 0;
|
||||
display: -ms-grid;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, 455px);
|
||||
grid-gap: 0px;
|
||||
justify-content: space-evenly;
|
||||
animation-name: item-appear;
|
||||
animation-duration: 0.5s;
|
||||
|
||||
@media screen and (max-width: 480px) {
|
||||
width: 91.666666667%;
|
||||
grid-template-columns: repeat(auto-fill, 100%);
|
||||
}
|
||||
|
||||
.tainacan-card {
|
||||
padding: 0px;
|
||||
flex-basis: 0;
|
||||
margin: 15px;
|
||||
max-width: 425px;
|
||||
min-width: 425px;
|
||||
min-height: 210px;
|
||||
max-height: 210px;
|
||||
|
||||
@media screen and (max-width: 480px) {
|
||||
max-width: 100%;
|
||||
min-width: 100%;
|
||||
min-height: 171px;
|
||||
max-height: 171px;
|
||||
|
||||
img {
|
||||
width: 130px !important;
|
||||
height: 130px !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Thumbnails (Grid) View Mode
|
||||
.tainacan-grid-container {
|
||||
min-height: 50vh;
|
||||
padding: 0;
|
||||
display: -ms-grid;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, 285px);
|
||||
grid-gap: 0px;
|
||||
justify-content: space-evenly;
|
||||
animation-name: appear;
|
||||
animation-duration: 0.5s;
|
||||
|
||||
.tainacan-grid-item {
|
||||
max-width: 255px;
|
||||
min-height: 300px;
|
||||
flex-basis: 0;
|
||||
margin: 15px;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
// Masonry View Mode
|
||||
.tainacan-masonry-container {
|
||||
min-height: 50vh;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
flex-grow: 1;
|
||||
flex-shrink: 1;
|
||||
justify-content: space-evenly;
|
||||
animation-name: item-appear;
|
||||
animation-duration: 0.5s;
|
||||
|
||||
.tainacan-masonry-item {
|
||||
display: block;
|
||||
width: 100%;
|
||||
flex-basis: 0;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
}
|
||||
|
||||
// Records View Mode
|
||||
.tainacan-records-container {
|
||||
min-height: 50vh;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
flex-grow: 1;
|
||||
flex-shrink: 1;
|
||||
justify-content: space-evenly;
|
||||
animation-name: item-appear;
|
||||
animation-duration: 0.5s;
|
||||
|
||||
.tainacan-record {
|
||||
background-color: #f6f6f6;
|
||||
padding: 0px;
|
||||
flex-basis: 0;
|
||||
margin: 0 auto 30px auto;
|
||||
width: 100%;
|
||||
max-width: 425px;
|
||||
min-height: 100px;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
// Table View Mode
|
||||
table.tainacan-table {
|
||||
border-spacing: 6px !important;
|
||||
th { height: 38px; }
|
||||
td { height: 52px; }
|
||||
}
|
||||
|
||||
</style>
|
|
@ -2,7 +2,7 @@ import qs from 'qs';
|
|||
import axios from 'axios';
|
||||
|
||||
const wpApi = axios.create({
|
||||
baseURL: tainacan_plugin.root_wp_api
|
||||
baseURL: tainacan_plugin.wp_api_url
|
||||
});
|
||||
|
||||
wpApi.defaults.headers.common['X-WP-Nonce'] = tainacan_plugin.nonce;
|
||||
|
|
|
@ -100,14 +100,14 @@
|
|||
|
||||
<filters-items-list
|
||||
v-if="!isLoadingFilters &&
|
||||
((filters.length >= 0 &&
|
||||
isRepositoryLevel) || filters.length > 0)"
|
||||
((filters.length >= 0 && isRepositoryLevel) || filters.length > 0)"
|
||||
:filters="filters"
|
||||
:collapsed="collapseAll"
|
||||
:is-repository-level="isRepositoryLevel"/>
|
||||
|
||||
<section
|
||||
v-else
|
||||
v-if="!isLoadingFilters &&
|
||||
!((filters.length >= 0 && isRepositoryLevel) || filters.length > 0)"
|
||||
class="is-grouped-centered section">
|
||||
<div class="content has-text-gray has-text-centered">
|
||||
<p>
|
||||
|
@ -445,6 +445,20 @@
|
|||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Exposers or alternativa links modal button -->
|
||||
<div
|
||||
v-if="isOnTheme"
|
||||
class="search-control-item">
|
||||
<button
|
||||
class="button is-white"
|
||||
@click="openExposersModal()">
|
||||
<span class="gray-icon">
|
||||
<i class="tainacan-icon tainacan-icon-20px tainacan-icon-url"/>
|
||||
</span>
|
||||
<span class="is-hidden-touch">{{ $i18n.get('label_urls') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Text simple search (used on mobile, instead of the one from filter list)-->
|
||||
<div class="is-hidden-tablet search-control-item">
|
||||
<div class="search-area">
|
||||
|
@ -545,12 +559,13 @@
|
|||
<div class="above-search-control">
|
||||
|
||||
<div
|
||||
v-show="isLoadingItems &&
|
||||
!(registeredViewModes[viewMode] != undefined && registeredViewModes[viewMode].full_screen)"
|
||||
v-show="(isLoadingItems &&
|
||||
!(registeredViewModes[viewMode] != undefined && registeredViewModes[viewMode].full_screen))"
|
||||
class="loading-container">
|
||||
<b-loading
|
||||
<!--<b-loading
|
||||
:is-full-page="false"
|
||||
:active="showLoading"/>
|
||||
:active="showLoading"/>-->
|
||||
<skeleton-items-list v-if="!isOnTheme"/>
|
||||
</div>
|
||||
|
||||
<!-- <div
|
||||
|
@ -560,7 +575,6 @@
|
|||
<hr>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<!-- When advanced search -->
|
||||
<items-list
|
||||
v-if="!isOnTheme &&
|
||||
|
@ -579,11 +593,11 @@
|
|||
|
||||
<!-- Admin View Modes-->
|
||||
<items-list
|
||||
v-else-if="!isOnTheme &&
|
||||
!isLoadingItems &&
|
||||
v-else-if="!isOnTheme &&
|
||||
!isLoadingItems &&
|
||||
totalItems > 0 &&
|
||||
!openAdvancedSearch"
|
||||
|
||||
|
||||
:collection-id="collectionId"
|
||||
:table-metadata="displayedMetadata"
|
||||
:items="items"
|
||||
|
@ -708,14 +722,14 @@
|
|||
|
||||
<filters-items-list
|
||||
v-if="!isLoadingFilters &&
|
||||
((filters.length >= 0 &&
|
||||
isRepositoryLevel) || filters.length > 0)"
|
||||
((filters.length >= 0 && isRepositoryLevel) || filters.length > 0)"
|
||||
:filters="filters"
|
||||
:collapsed="collapseAll"
|
||||
:is-repository-level="isRepositoryLevel"/>
|
||||
|
||||
<section
|
||||
v-else
|
||||
v-if="!isLoadingFilters &&
|
||||
!((filters.length >= 0 && isRepositoryLevel) || filters.length > 0)"
|
||||
class="is-grouped-centered section">
|
||||
<div class="content has-text-gray has-text-centered">
|
||||
<p>
|
||||
|
@ -744,8 +758,10 @@
|
|||
import FiltersTagsList from '../../components/search/filters-tags-list.vue';
|
||||
import FiltersItemsList from '../../components/search/filters-items-list.vue';
|
||||
import Pagination from '../../components/search/pagination.vue'
|
||||
import SkeletonItemsList from '../../components/search/skeleton-items-list.vue'
|
||||
import AdvancedSearch from '../../components/advanced-search/advanced-search.vue';
|
||||
import AvailableImportersModal from '../../components/other/available-importers-modal.vue';
|
||||
import ExposersModal from '../../components/other/exposers-modal.vue';
|
||||
import CollectionsModal from '../../components/other/collections-modal.vue';
|
||||
import { mapActions, mapGetters } from 'vuex';
|
||||
|
||||
|
@ -842,8 +858,10 @@
|
|||
ItemsList,
|
||||
FiltersTagsList,
|
||||
FiltersItemsList,
|
||||
SkeletonItemsList,
|
||||
Pagination,
|
||||
AdvancedSearch,
|
||||
ExposersModal
|
||||
},
|
||||
watch: {
|
||||
displayedMetadata() {
|
||||
|
@ -915,6 +933,17 @@
|
|||
}
|
||||
});
|
||||
},
|
||||
openExposersModal() {
|
||||
this.$modal.open({
|
||||
parent: this,
|
||||
component: ExposersModal,
|
||||
hasModalCard: true,
|
||||
props: {
|
||||
collectionId: this.collectionId,
|
||||
totalItems: this.totalItems
|
||||
}
|
||||
})
|
||||
},
|
||||
onOpenCollectionsModal() {
|
||||
this.$modal.open({
|
||||
parent: this,
|
||||
|
|
|
@ -73,10 +73,10 @@
|
|||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<a
|
||||
<!-- <a
|
||||
@click="openAdvancedSearch = !openAdvancedSearch"
|
||||
class="is-size-7 is-pulled-right is-hidden-mobile">{{ $i18n.get('advanced_search') }}</a>
|
||||
|
||||
-->
|
||||
<h3 class="has-text-weight-semibold">{{ $i18n.get('filters') }}</h3>
|
||||
<a
|
||||
v-if="!isLoadingFilters &&
|
||||
|
@ -444,9 +444,9 @@
|
|||
<i class="tainacan-icon tainacan-icon-20px tainacan-icon-search"/>
|
||||
</span>
|
||||
</div>
|
||||
<a
|
||||
<!-- <a
|
||||
@click="openAdvancedSearch = !openAdvancedSearch"
|
||||
class="is-size-7 has-text-secondary is-pulled-right">{{ $i18n.get('advanced_search') }}</a>
|
||||
class="is-size-7 has-text-secondary is-pulled-right">{{ $i18n.get('advanced_search') }}</a> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -470,8 +470,8 @@
|
|||
</div>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<advanced-search
|
||||
:is-repository-level="isRepositoryLevel"
|
||||
:collection-id="collectionId"
|
||||
|
@ -479,6 +479,7 @@
|
|||
:open-form-advanced-search="openFormAdvancedSearch"
|
||||
:is-do-search="isDoSearch"
|
||||
:metadata="metadata"/>
|
||||
|
||||
<div class="advanced-searh-form-submit">
|
||||
<p
|
||||
v-if="advancedSearchResults"
|
||||
|
@ -520,7 +521,8 @@
|
|||
<div class="above-search-control">
|
||||
|
||||
<div
|
||||
v-show="isLoadingItems"
|
||||
v-show="(isLoadingItems &&
|
||||
!(registeredViewModes[viewMode] != undefined && registeredViewModes[viewMode].full_screen))"
|
||||
class="loading-container">
|
||||
<b-loading
|
||||
:is-full-page="false"
|
||||
|
@ -896,7 +898,8 @@
|
|||
|
||||
// Updates searchControlHeight before in case we need to adjust filters position on mobile
|
||||
setTimeout(() => {
|
||||
this.searchControlHeight = this.$refs['search-control'].clientHeight;
|
||||
if (this.$refs['search-control'] != undefined)
|
||||
this.searchControlHeight = this.$refs['search-control'].clientHeight;
|
||||
}, 500);
|
||||
},
|
||||
onChangeAdminViewMode(adminViewMode) {
|
||||
|
|
|
@ -597,13 +597,19 @@ $modal-z: 9999999;
|
|||
100%{background-position:0% 94%}
|
||||
}
|
||||
|
||||
// .skeleton:nth-child(even) {
|
||||
// background: linear-gradient(105deg, #f0f0f0, #fbfbfb, #eeeeee);
|
||||
// }
|
||||
// .skeleton:nth-child(odd) {
|
||||
// background: linear-gradient(235deg, #f0f0f0, #fbfbfb, #eeeeee);
|
||||
// }
|
||||
.skeleton {
|
||||
border-radius: 6px;
|
||||
background: linear-gradient(235deg, #fbfbfb, #ffffff, #eeeeee);
|
||||
border-radius: 4px;
|
||||
background: linear-gradient(235deg, #f0f0f0, #fbfbfb, #eeeeee);
|
||||
background-size: 600% 600%;
|
||||
|
||||
-webkit-animation: skeleton-animation 1s ease infinite;
|
||||
-moz-animation: skeleton-animation 1s ease infinite;
|
||||
-o-animation: skeleton-animation 1s ease infinite;
|
||||
animation: skeleton-animation 1s ease infinite;
|
||||
-webkit-animation: skeleton-animation 1.5s ease infinite;
|
||||
-moz-animation: skeleton-animation 1.5s ease infinite;
|
||||
-o-animation: skeleton-animation 1.5s ease infinite;
|
||||
animation: skeleton-animation 1.5s ease infinite;
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
grid-template-columns: repeat(auto-fill, 455px);
|
||||
grid-gap: 0px;
|
||||
justify-content: space-evenly;
|
||||
animation-name: item-appear;
|
||||
animation-name: appear;
|
||||
animation-duration: 0.5s;
|
||||
|
||||
@media screen and (max-width: 480px) {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
grid-template-columns: repeat(auto-fill, 285px);
|
||||
grid-gap: 0px;
|
||||
justify-content: space-evenly;
|
||||
animation-name: item-appear;
|
||||
animation-name: appear;
|
||||
animation-duration: 0.5s;
|
||||
|
||||
.selected-grid-item {
|
||||
|
@ -15,6 +15,7 @@
|
|||
|
||||
.tainacan-grid-item {
|
||||
max-width: 255px;
|
||||
min-height: 300px;
|
||||
flex-basis: 0;
|
||||
margin: 15px;
|
||||
text-align: center;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
flex-grow: 1;
|
||||
flex-shrink: 1;
|
||||
justify-content: space-evenly;
|
||||
animation-name: item-appear;
|
||||
animation-name: appear;
|
||||
animation-duration: 0.5s;
|
||||
|
||||
.selected-masonry-item {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
flex-grow: 1;
|
||||
flex-shrink: 1;
|
||||
justify-content: space-evenly;
|
||||
animation-name: item-appear;
|
||||
animation-name: appear;
|
||||
animation-duration: 0.5s;
|
||||
|
||||
.selected-record {
|
||||
|
|
|
@ -51,6 +51,9 @@ html {
|
|||
}
|
||||
|
||||
// Tainacan Loading
|
||||
.loading-overlay {
|
||||
z-index: 9999999999;
|
||||
}
|
||||
.loading-overlay .loading-icon::after {
|
||||
background-image: url('../../admin/images/tainacan_loading.gif');
|
||||
border: none;
|
||||
|
|
|
@ -338,6 +338,8 @@ return apply_filters( 'tainacan-admin-i18n', [
|
|||
'label_available_exporters' => __( 'Available Exporters', 'tainacan' ),
|
||||
'label_origin_collection' => __( 'Origin collection', 'tainacan'),
|
||||
'label_send_email' => __( 'Send a email after exportation completed', 'tainacan' ),
|
||||
'label_urls' => __( 'URLs', 'tainacan' ),
|
||||
'label_page' => __( 'Page', 'tainacan' ),
|
||||
'label_activity_description' => __( 'Activity description', 'tainacan' ),
|
||||
'label_activity_creation_date' => __( 'Activity creation date', 'tainacan' ),
|
||||
'label_activity_author' => __( 'Activity author', 'tainacan' ),
|
||||
|
|
|
@ -302,6 +302,8 @@ class REST_Collections_Controller extends REST_Controller {
|
|||
$collection = $this->collections_repository->insert( $prepared_post );
|
||||
|
||||
$response = $this->prepare_item_for_response($collection, $request);
|
||||
|
||||
do_action('tainacan-api-collection-created', $response, $request);
|
||||
|
||||
return new \WP_REST_Response($response, 201);
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ class REST_Export_Controller extends REST_Controller {
|
|||
*/
|
||||
public function export($request, $query, $args) {
|
||||
|
||||
$type = \Tainacan\Exposers\Exposers::request_has_type($request);
|
||||
$type = \Tainacan\Exposers_Handler::request_has_type($request);
|
||||
$path = wp_upload_dir();
|
||||
$path = $path['path'];
|
||||
$filename = $path.date('YmdHis').'-tainacan-export.'.$type->get_extension();
|
||||
|
@ -170,8 +170,8 @@ class REST_Export_Controller extends REST_Controller {
|
|||
[],
|
||||
'error'
|
||||
);
|
||||
remove_filter( 'rest_request_after_callbacks', [\Tainacan\Exposers\Exposers::get_instance(), 'rest_request_after_callbacks'], 10, 3 ); //exposer mapping
|
||||
remove_filter( 'tainacan-rest-response', [\Tainacan\Exposers\Exposers::get_instance(), 'rest_response'], 10, 2 ); // exposer types
|
||||
remove_filter( 'rest_request_after_callbacks', [\Tainacan\Exposers_Handler::get_instance(), 'rest_request_after_callbacks'], 10, 3 ); //exposer mapping
|
||||
remove_filter( 'tainacan-rest-response', [\Tainacan\Exposers_Handler::get_instance(), 'rest_response'], 10, 2 ); // exposer types
|
||||
return $log;
|
||||
} elseif ($pid) { // we are the parent or run at foreground
|
||||
try {
|
||||
|
@ -265,8 +265,8 @@ class REST_Export_Controller extends REST_Controller {
|
|||
}
|
||||
} else { // we are the child
|
||||
|
||||
remove_filter( 'rest_request_after_callbacks', [\Tainacan\Exposers\Exposers::get_instance(), 'rest_request_after_callbacks'], 10, 3 ); //exposer mapping
|
||||
remove_filter( 'tainacan-rest-response', [\Tainacan\Exposers\Exposers::get_instance(), 'rest_response'], 10, 2 ); // exposer types
|
||||
remove_filter( 'rest_request_after_callbacks', [\Tainacan\Exposers_Handler::get_instance(), 'rest_request_after_callbacks'], 10, 3 ); //exposer mapping
|
||||
remove_filter( 'tainacan-rest-response', [\Tainacan\Exposers_Handler::get_instance(), 'rest_response'], 10, 2 ); // exposer types
|
||||
return $log;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\API\EndPoints;
|
||||
|
||||
use Tainacan\Exposers_Handler;
|
||||
use Tainacan\Mappers_Handler;
|
||||
use \Tainacan\API\REST_Controller;
|
||||
|
||||
class REST_Exposers_Controller extends REST_Controller {
|
||||
|
||||
|
||||
private $metadatum_repository;
|
||||
|
||||
/**
|
||||
* REST_Facets_Controller constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->rest_base = 'exposers';
|
||||
parent::__construct();
|
||||
add_action('init', array(&$this, 'init_objects'), 11);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize objects after post_type register
|
||||
*/
|
||||
public function init_objects() {
|
||||
$this->exposers = Exposers_Handler::get_instance();
|
||||
$this->mappers = Mappers_Handler::get_instance();
|
||||
}
|
||||
|
||||
public function register_routes() {
|
||||
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check')
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
|
||||
$exposers = $this->exposers->get_exposers();
|
||||
|
||||
$response = [];
|
||||
|
||||
|
||||
foreach ($exposers as $exposer) {
|
||||
if ( class_exists($exposer) ) {
|
||||
$e = new $exposer();
|
||||
$response[] = $e->_toArray();
|
||||
}
|
||||
}
|
||||
|
||||
$rest_response = new \WP_REST_Response($response, 200);
|
||||
|
||||
$rest_response->header('X-WP-Total', count($response));
|
||||
|
||||
return $rest_response;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
public function get_items_permissions_check( $request ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -54,6 +54,9 @@ class REST_Facets_Controller extends REST_Controller {
|
|||
*/
|
||||
public function get_items( $request ) {
|
||||
|
||||
// Free php session early so simultaneous requests dont get queued
|
||||
session_write_close();
|
||||
|
||||
$metadatum_id = $request['metadatum_id'];
|
||||
|
||||
if( !empty($metadatum_id) ) {
|
||||
|
|
|
@ -119,12 +119,13 @@ class REST_Items_Controller extends REST_Controller {
|
|||
$item_array['metadata'][ $slug ]['name'] = $metadatum->get_name();
|
||||
if($metadatum->get_metadata_type_object()->get_primitive_type() === 'date') {
|
||||
$item_array['metadata'][ $slug ]['date_i18n'] = $item_metadata_array['date_i18n'];
|
||||
} else {
|
||||
$item_array['metadata'][ $slug ]['value'] = $item_metadata_array['value'];
|
||||
$item_array['metadata'][ $slug ]['value_as_html'] = $item_metadata_array['value_as_html'];
|
||||
$item_array['metadata'][ $slug ]['value_as_string'] = $item_metadata_array['value_as_string'];
|
||||
}
|
||||
$item_array['metadata'][ $slug ]['value'] = $item_metadata_array['value'];
|
||||
$item_array['metadata'][ $slug ]['value_as_html'] = $item_metadata_array['value_as_html'];
|
||||
$item_array['metadata'][ $slug ]['value_as_string'] = $item_metadata_array['value_as_string'];
|
||||
|
||||
$item_array['metadata'][ $slug ]['multiple'] = $metadatum->get_multiple();
|
||||
$item_array['metadata'][ $slug ]['mapping'] = $metadatum->get_exposer_mapping();
|
||||
}
|
||||
|
||||
return $item_array;
|
||||
|
@ -169,37 +170,41 @@ class REST_Items_Controller extends REST_Controller {
|
|||
}
|
||||
|
||||
$item_arr['document_as_html'] = $item->get_document_html($img_size);
|
||||
$item_arr['exposer_urls'] = \Tainacan\Exposers\Exposers::get_exposer_urls(rest_url("{$this->namespace}/{$this->rest_base}/{$item->get_id()}/"));
|
||||
return $this->add_metadata_to_item( $item, $item_arr );
|
||||
}
|
||||
|
||||
$attributes_to_filter = $request['fetch_only'];
|
||||
|
||||
# Always returns id and collection id
|
||||
if(is_array($attributes_to_filter)) {
|
||||
$attributes_to_filter[] = 'id';
|
||||
$attributes_to_filter[] = 'collection_id';
|
||||
$item_arr['exposer_urls'] = \Tainacan\Exposers_Handler::get_exposer_urls(rest_url("{$this->namespace}/{$this->rest_base}/{$item->get_id()}/"));
|
||||
$item_arr = $this->add_metadata_to_item( $item, $item_arr );
|
||||
} else {
|
||||
$attributes_to_filter = array($attributes_to_filter, 'id', 'collection_id');
|
||||
|
||||
$attributes_to_filter = $request['fetch_only'];
|
||||
|
||||
# Always returns id and collection id
|
||||
if(is_array($attributes_to_filter)) {
|
||||
$attributes_to_filter[] = 'id';
|
||||
$attributes_to_filter[] = 'collection_id';
|
||||
} else {
|
||||
$attributes_to_filter = array($attributes_to_filter, 'id', 'collection_id');
|
||||
}
|
||||
|
||||
$item_arr = $this->filter_object_by_attributes($item, $attributes_to_filter);
|
||||
|
||||
$item_arr = array_merge($extra_metadata_values, $item_arr);
|
||||
|
||||
if(is_array($attributes_to_filter) && array_key_exists('meta', $attributes_to_filter)){
|
||||
|
||||
$args = array('post__in' => $attributes_to_filter['meta']);
|
||||
|
||||
$item_arr = $this->add_metadata_to_item($item, $item_arr, $args);
|
||||
}
|
||||
|
||||
if ( $request['context'] === 'edit' ) {
|
||||
$item_arr['current_user_can_edit'] = $item->can_edit();
|
||||
}
|
||||
|
||||
$item_arr['url'] = get_permalink( $item_arr['id'] );
|
||||
$item_arr['exposer_urls'] = \Tainacan\Exposers_Handler::get_exposer_urls(get_rest_url(null, "{$this->namespace}/{$this->rest_base}/{$item->get_id()}/"));
|
||||
|
||||
}
|
||||
|
||||
$item_arr = $this->filter_object_by_attributes($item, $attributes_to_filter);
|
||||
|
||||
$item_arr = array_merge($extra_metadata_values, $item_arr);
|
||||
|
||||
if(is_array($attributes_to_filter) && array_key_exists('meta', $attributes_to_filter)){
|
||||
|
||||
$args = array('post__in' => $attributes_to_filter['meta']);
|
||||
|
||||
$item_arr = $this->add_metadata_to_item($item, $item_arr, $args);
|
||||
}
|
||||
|
||||
if ( $request['context'] === 'edit' ) {
|
||||
$item_arr['current_user_can_edit'] = $item->can_edit();
|
||||
}
|
||||
|
||||
$item_arr['url'] = get_permalink( $item_arr['id'] );
|
||||
$item_arr['exposer_urls'] = \Tainacan\Exposers\Exposers::get_exposer_urls(get_rest_url(null, "{$this->namespace}/{$this->rest_base}/{$item->get_id()}/"));
|
||||
$item_arr = apply_filters('tainacan-api-items-prepare-for-response', $item_arr, $item, $request);
|
||||
|
||||
return $item_arr;
|
||||
}
|
||||
|
@ -229,13 +234,36 @@ class REST_Items_Controller extends REST_Controller {
|
|||
* @throws \Exception
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
|
||||
global $TAINACAN_API_MAX_ITEMS_PER_PAGE;
|
||||
|
||||
// Free php session early so simultaneous requests dont get queued
|
||||
session_write_close();
|
||||
|
||||
$args = $this->prepare_filters($request);
|
||||
|
||||
/**
|
||||
* allow plugins to hijack the process.
|
||||
*
|
||||
* If it returns a \WP_REST_Response, the method will return it and ignore the rest of the script
|
||||
*/
|
||||
$alternate_response = apply_filters('tainacan-api-get-items-alternate', false, $request);
|
||||
if ( $alternate_response instanceof \WP_REST_Response ) {
|
||||
return $alternate_response;
|
||||
}
|
||||
|
||||
$collection_id = [];
|
||||
if($request['collection_id']) {
|
||||
$collection_id = $request['collection_id'];
|
||||
}
|
||||
|
||||
$max_items_per_page = $TAINACAN_API_MAX_ITEMS_PER_PAGE;
|
||||
if ( $max_items_per_page > -1 ) {
|
||||
if ( isset($args['posts_per_page']) && (int) $args['posts_per_page'] > $max_items_per_page ) {
|
||||
$args['posts_per_page'] = $max_items_per_page;
|
||||
}
|
||||
}
|
||||
|
||||
$query_start = microtime(true);
|
||||
|
||||
$items = $this->items_repository->fetch($args, $collection_id, 'WP_Query');
|
||||
|
@ -297,6 +325,7 @@ class REST_Items_Controller extends REST_Controller {
|
|||
|
||||
$rest_response->header('X-WP-Total', (int) $total_items);
|
||||
$rest_response->header('X-WP-TotalPages', (int) $max_pages);
|
||||
$rest_response->header('X-WP-ItemsPerPage', (int) $items->query_vars['posts_per_page']);
|
||||
$rest_response->header('X-Tainacan-Query-Time', $query_end - $query_start);
|
||||
$rest_response->header('X-Tainacan-Elapsed-Time', microtime(true) - $query_start);
|
||||
|
||||
|
|
|
@ -65,9 +65,9 @@ class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
|||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$Tainacan_Exposers = \Tainacan\Exposers\Exposers::get_instance();
|
||||
$Tainacan_Mappers = \Tainacan\Mappers_Handler::get_instance();
|
||||
|
||||
$metadatum_mappers = $Tainacan_Exposers->get_mappers( 'OBJECT' );
|
||||
$metadatum_mappers = $Tainacan_Mappers->get_mappers( 'OBJECT' );
|
||||
|
||||
$prepared = [];
|
||||
foreach ($metadatum_mappers as $metadatum_mapper){
|
||||
|
@ -101,7 +101,7 @@ class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
|||
array_key_exists('metadata_mappers', $body) &&
|
||||
is_array($body['metadata_mappers']) &&
|
||||
count($body['metadata_mappers']) > 0 &&
|
||||
\Tainacan\Exposers\Exposers::request_has_mapper($request)
|
||||
\Tainacan\Mappers_Handler::get_mapper_from_request($request)
|
||||
) {
|
||||
$metadatum_mapper = $body['metadata_mappers'][0];
|
||||
$metadatum = \Tainacan\Repositories\Repository::get_entity_by_post($metadatum_mapper['metadatum_id']);
|
||||
|
@ -118,10 +118,10 @@ class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
|||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function update_item( $request ) {
|
||||
$Tainacan_Exposers = \Tainacan\Exposers\Exposers::get_instance();
|
||||
$Tainacan_Mappers = \Tainacan\Mappers_Handler::get_instance();
|
||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||
$body = json_decode( $request->get_body(), true );
|
||||
if($mapper = $Tainacan_Exposers::request_has_mapper($request)) {
|
||||
if($mapper = $Tainacan_Mappers::get_mapper_from_request($request)) {
|
||||
if(count($body['metadata_mappers']) > 0) {
|
||||
$response = [];
|
||||
$saved = [];
|
||||
|
|
|
@ -17,6 +17,7 @@ $rest_importers_controller = new \Tainacan\API\EndPoints\REST_Importers_Contr
|
|||
$rest_exporters_controller = new \Tainacan\API\EndPoints\REST_Exporters_Controller();
|
||||
$rest_background_processes_controller = new \Tainacan\API\EndPoints\REST_Background_Processes_Controller();
|
||||
$rest_bulkedit_controller = new \Tainacan\API\EndPoints\REST_Bulkedit_Controller();
|
||||
$rest_exposers_controller = new \Tainacan\API\EndPoints\REST_Exposers_Controller();
|
||||
new \Tainacan\API\EndPoints\REST_Export_Controller();
|
||||
new \Tainacan\API\EndPoints\REST_Metadatum_Mappers_Controller();
|
||||
$rest_facets_controller = new \Tainacan\API\EndPoints\REST_Facets_Controller();
|
||||
|
|
|
@ -102,9 +102,9 @@ class Item_Metadata_Entity extends Entity {
|
|||
|
||||
$total = sizeof($value);
|
||||
$count = 0;
|
||||
$prefix = $item_metadata->get_multivalue_prefix();
|
||||
$suffix = $item_metadata->get_multivalue_suffix();
|
||||
$separator = $item_metadata->get_multivalue_separator();
|
||||
$prefix = $this->get_multivalue_prefix();
|
||||
$suffix = $this->get_multivalue_suffix();
|
||||
$separator = $this->get_multivalue_separator();
|
||||
|
||||
foreach ($value as $v) {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<div
|
||||
:style="{ 'height': isLoadingOptions ? (options.length*28) + 'px' : 'auto' }"
|
||||
:style="{ 'height': isLoadingOptions ? (Number(filter.max_options)*28) + 'px' : 'auto' }"
|
||||
:class="{ 'skeleton': isLoadingOptions }"
|
||||
class="block">
|
||||
<!-- <span
|
||||
|
|
|
@ -192,7 +192,7 @@
|
|||
},
|
||||
cleanSearchFromTags(filterTag) {
|
||||
if (filterTag.filterId == this.filter.id)
|
||||
this.cleanSearch();
|
||||
this.clearSearch();
|
||||
},
|
||||
clearSearch(){
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<div
|
||||
:style="{ 'height': isLoading ? (options.length*28) + 'px' : 'auto' }"
|
||||
:style="{ 'height': isLoading ? (Number(filter.max_options)*28) + 'px' : 'auto' }"
|
||||
:class="{ 'skeleton': isLoading }"
|
||||
class="block">
|
||||
<!-- <span
|
||||
|
@ -68,7 +68,7 @@
|
|||
},
|
||||
data(){
|
||||
return {
|
||||
isLoading: false,
|
||||
isLoading: true,
|
||||
options: [],
|
||||
type: '',
|
||||
collection: '',
|
||||
|
|
|
@ -677,9 +677,6 @@ class Metadata extends Repository {
|
|||
'collection_id' => $collection->get_id(),
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Core_Description',
|
||||
'status' => 'publish',
|
||||
'exposer_mapping' => [
|
||||
'dublin-core' => 'description'
|
||||
]
|
||||
],
|
||||
'core_title' => [
|
||||
'name' => 'Title',
|
||||
|
@ -688,9 +685,6 @@ class Metadata extends Repository {
|
|||
'metadata_type' => 'Tainacan\Metadata_Types\Core_Title',
|
||||
'status' => 'publish',
|
||||
'display' => 'yes',
|
||||
'exposer_mapping' => [
|
||||
'dublin-core' => 'title'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
|
|
|
@ -135,7 +135,9 @@ class Taxonomies extends Repository {
|
|||
|
||||
$new_taxonomy = parent::insert( $taxonomy );
|
||||
$new_taxonomy->tainacan_register_taxonomy();
|
||||
|
||||
|
||||
flush_rewrite_rules( false ); // needed to activate taxonomy archive url
|
||||
|
||||
// return a brand new object
|
||||
return $new_taxonomy;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ const TAINACAN_ENDPOINTS_DIR = __DIR__ . '/../api/endpoints/';
|
|||
const TAINACAN_IMPORTER_DIR = __DIR__ . '/../importer/';
|
||||
const TAINACAN_EXPORTER_DIR = __DIR__ . '/../exporter/';
|
||||
const TAINACAN_EXPOSERS_DIR = __DIR__ . '/../exposers/';
|
||||
const TAINACAN_MAPPERS_DIR = __DIR__ . '/../mappers/';
|
||||
|
||||
const DIRS = [
|
||||
TAINACAN_CLASSES_DIR,
|
||||
|
@ -23,7 +24,8 @@ const DIRS = [
|
|||
TAINACAN_ENDPOINTS_DIR,
|
||||
TAINACAN_IMPORTER_DIR,
|
||||
TAINACAN_EXPORTER_DIR,
|
||||
TAINACAN_EXPOSERS_DIR
|
||||
TAINACAN_EXPOSERS_DIR,
|
||||
TAINACAN_MAPPERS_DIR
|
||||
];
|
||||
|
||||
require_once('libs/wp-async-request.php');
|
||||
|
@ -35,7 +37,8 @@ require_once(TAINACAN_IMPORTER_DIR . 'class-tainacan-bg-importer.php');
|
|||
require_once(TAINACAN_VENDOR_DIR . 'autoload.php');
|
||||
require_once(TAINACAN_IMPORTER_DIR . 'class-tainacan-importer.php');
|
||||
require_once(TAINACAN_IMPORTER_DIR . 'class-tainacan-importer-handler.php');
|
||||
require_once(TAINACAN_EXPOSERS_DIR . 'class-tainacan-exposers.php');
|
||||
require_once(TAINACAN_EXPOSERS_DIR . 'class-tainacan-exposers-handler.php');
|
||||
require_once(TAINACAN_MAPPERS_DIR . 'class-tainacan-mappers-handler.php');
|
||||
|
||||
require_once(TAINACAN_EXPORTER_DIR . 'class-tainacan-bg-exporter.php');
|
||||
require_once(TAINACAN_EXPORTER_DIR . 'class-tainacan-export-handler.php');
|
||||
|
@ -68,6 +71,9 @@ function tainacan_autoload($class_name){
|
|||
} else if( isset( $class_path[1] ) && $class_path[1] === 'Exposers' ){
|
||||
$dir = TAINACAN_EXPOSERS_DIR;
|
||||
if(count($class_path) > 3) $dir .= strtolower($class_path[2]).DIRECTORY_SEPARATOR;
|
||||
} else if( isset( $class_path[1] ) && $class_path[1] === 'Mappers' ){
|
||||
$dir = TAINACAN_MAPPERS_DIR;
|
||||
if(count($class_path) > 3) $dir .= strtolower($class_path[2]).DIRECTORY_SEPARATOR;
|
||||
} else if( isset( $class_path[1] ) && $class_path[1] === 'API' ){
|
||||
$dir = TAINACAN_TAPI_DIR;
|
||||
if(count($class_path) > 3) $dir .= strtolower($class_path[2]).DIRECTORY_SEPARATOR;
|
||||
|
@ -133,7 +139,9 @@ $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
|
|||
|
||||
$Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
|
||||
|
||||
$Tainacan_Exposers = \Tainacan\Exposers\Exposers::get_instance();
|
||||
$Tainacan_Exposers = \Tainacan\Exposers_Handler::get_instance();
|
||||
|
||||
$Tainacan_Mappers = \Tainacan\Mappers_Handler::get_instance();
|
||||
|
||||
$Tainacan_Embed = \Tainacan\Embed::get_instance();
|
||||
|
||||
|
|
|
@ -58,11 +58,104 @@ class CSV extends Exporter {
|
|||
|
||||
public function options_form() {
|
||||
ob_start();
|
||||
?>
|
||||
<div class="field">
|
||||
<p>Priemiro teste da construção de um Exporter! </p>
|
||||
?>
|
||||
<div class="field">
|
||||
<label class="label"><?php _e('CSV Delimiter', 'tainacan'); ?></label>
|
||||
<span class="help-wrapper">
|
||||
<a class="help-button has-text-secondary">
|
||||
<span class="icon is-small">
|
||||
<i class="mdi mdi-help-circle-outline" ></i>
|
||||
</span>
|
||||
</a>
|
||||
<div class="help-tooltip">
|
||||
<div class="help-tooltip-header">
|
||||
<h5><?php _e('CSV Delimiter', 'tainacan'); ?></h5>
|
||||
</div>
|
||||
<div class="help-tooltip-body">
|
||||
<p><?php _e('The character used to separate each column in your CSV (e.g. , or ;)', 'tainacan'); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
<div class="control is-clearfix">
|
||||
<input class="input" type="text" name="delimiter" value="<?php echo $this->get_option('delimiter'); ?>">
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label"><?php _e('Multivalued metadata delimiter', 'tainacan'); ?></label>
|
||||
<span class="help-wrapper">
|
||||
<a class="help-button has-text-secondary">
|
||||
<span class="icon is-small">
|
||||
<i class="mdi mdi-help-circle-outline" ></i>
|
||||
</span>
|
||||
</a>
|
||||
<div class="help-tooltip">
|
||||
<div class="help-tooltip-header">
|
||||
<h5><?php _e('Multivalued metadata delimiter', 'tainacan'); ?></h5>
|
||||
</div>
|
||||
<div class="help-tooltip-body">
|
||||
<p><?php _e('The character used to separate each value inside a cell with multiple values (e.g. ||). Note that the target metadatum must accept multiple values.', 'tainacan'); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
<div class="control is-clearfix">
|
||||
<input class="input" type="text" name="multivalued_delimiter" value="<?php echo $this->get_option('multivalued_delimiter'); ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label"><?php _e('Enclosure', 'tainacan'); ?></label>
|
||||
<span class="help-wrapper">
|
||||
<a class="help-button has-text-secondary">
|
||||
<span class="icon is-small">
|
||||
<i class="mdi mdi-help-circle-outline" ></i>
|
||||
</span>
|
||||
</a>
|
||||
<div class="help-tooltip">
|
||||
<div class="help-tooltip-header">
|
||||
<h5><?php _e('Enclosure', 'tainacan'); ?></h5>
|
||||
</div>
|
||||
<div class="help-tooltip-body">
|
||||
<p><?php _e('The character that wraps the content of each cell in your CSV. (e.g. ")', 'tainacan'); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
<div class="control is-clearfix">
|
||||
<input class="input" type="text" name="enclosure" value="<?php echo $this->get_option('enclosure'); ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label"><?php _e('File Encoding', 'tainacan'); ?></label>
|
||||
<span class="help-wrapper">
|
||||
<a class="help-button has-text-secondary">
|
||||
<span class="icon is-small">
|
||||
<i class="mdi mdi-help-circle-outline" ></i>
|
||||
</span>
|
||||
</a>
|
||||
<div class="help-tooltip">
|
||||
<div class="help-tooltip-header">
|
||||
<h5><?php _e('File Encoding', 'tainacan'); ?></h5>
|
||||
</div>
|
||||
<div class="help-tooltip-body">
|
||||
<p><?php _e('The encoding of the CSV file.', 'tainacan'); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
<div class="control is-clearfix">
|
||||
<div class="select">
|
||||
<select name="encode">
|
||||
<option value="utf8" <?php selected($this->get_option('encode'), 'utf8'); ?> >UTF-8</option>
|
||||
<option value="iso88591" <?php selected($this->get_option('encode'), 'iso88591'); ?> >ISO-88591</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
return ob_get_clean();
|
||||
|
||||
}
|
||||
}
|
|
@ -91,6 +91,7 @@ abstract class CommunImportExport {
|
|||
if (isset($collection['id'])) {
|
||||
$this->remove_collection($collection['id']);
|
||||
$this->collections[] = $collection;
|
||||
$this->collections = array_values($this->collections);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -532,26 +533,49 @@ class Exporter extends CommunImportExport {
|
|||
|
||||
public function add_collection(array $collection) {
|
||||
parent::add_collection($collection);
|
||||
$this->update_collection_mapping($collection['id']);
|
||||
$this->update_collections_mapping();
|
||||
}
|
||||
|
||||
private function update_collection_mapping($collection_id) {
|
||||
private function update_collections_mapping() {
|
||||
$mapper_handler = Tainacan\Mappers_Handler::get_instance();
|
||||
$collection_repo = Tainacan\Repositories\Collections::get_instance();
|
||||
$collection = $collection_repo->fetch((int)$collection_id);
|
||||
$metas = $collection->get_metadata();
|
||||
|
||||
$mapping = [];
|
||||
foreach ($metas as $key => $value) {
|
||||
$mapper = $this->mapping_list[$this->mapping_selected];
|
||||
$instance_mapper = new $mapper();
|
||||
$metadatum_mapping = $value->get_exposer_mapping();
|
||||
if(array_key_exists($instance_mapper->slug, $metadatum_mapping)) {
|
||||
$mapping[$value->get_name()] = $metadatum_mapping[$instance_mapper->slug];
|
||||
} else if ($instance_mapper->slug == 'value'){
|
||||
$mapping[$value->get_name()] = $value->get_name();
|
||||
foreach ($this->get_collections() as $index => $col) {
|
||||
|
||||
$collection_id = $col['id'];
|
||||
|
||||
$collection = $collection_repo->fetch((int)$collection_id);
|
||||
|
||||
if ( ! $collection instanceof \Tainacan\Entities\Collection ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$metas = $collection->get_metadata();
|
||||
|
||||
$mapping = [];
|
||||
$current_mapping = isset($col['mapping']) ? $col['mapping'] : [];
|
||||
|
||||
if ( $mapper = $mapper_handler->get_mapper($this->mapping_selected) ) {
|
||||
|
||||
foreach ($metas as $meta) {
|
||||
|
||||
$metadatum_mapping = $meta->get_exposer_mapping();
|
||||
//var_dump($metadatum_mapping);
|
||||
|
||||
if(array_key_exists($mapper->slug, $metadatum_mapping)) {
|
||||
$mapping[$meta->get_name()] = $metadatum_mapping[$mapper->slug];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$col['mapping'] = $mapping;
|
||||
if ($col['mapping'] !== $current_mapping) {
|
||||
$this->add_collection($col);
|
||||
}
|
||||
|
||||
}
|
||||
$this->collections[$collection_id]['mapping'] = $mapping;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -733,7 +757,7 @@ class Exporter extends CommunImportExport {
|
|||
}
|
||||
$this->mapping_accept[$method] = true;
|
||||
if($method == 'any') {
|
||||
$Tainacan_Exposers = \Tainacan\Exposers\Exposers::get_instance();
|
||||
$Tainacan_Exposers = \Tainacan\Mappers_Handler::get_instance();
|
||||
$metadatum_mappers = $Tainacan_Exposers->get_mappers();
|
||||
$this->mapping_list = $metadatum_mappers;
|
||||
} else if(!empty($list)) {
|
||||
|
@ -747,6 +771,7 @@ class Exporter extends CommunImportExport {
|
|||
|
||||
public function set_mapping_selected($mapping_selected) {
|
||||
$this->mapping_selected = $mapping_selected;
|
||||
$this->update_collections_mapping();
|
||||
}
|
||||
|
||||
public function set_send_email($email) {
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers;
|
||||
|
||||
/**
|
||||
* Generate a Csv formated response
|
||||
*
|
||||
*/
|
||||
class Csv extends Exposer {
|
||||
|
||||
public $slug = 'csv'; // type slug for url safe
|
||||
|
||||
function __construct() {
|
||||
$this->set_name( __('CSV', 'tainacan') );
|
||||
$this->set_description( __('Comma-separated values', 'tainacan') );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* {@inheritDoc}
|
||||
* @see \Tainacan\Exposers\Types\Type::rest_request_after_callbacks()
|
||||
*/
|
||||
public function rest_request_after_callbacks( $response, $handler, $request ) {
|
||||
$response->set_headers( [
|
||||
'Content-Type: text/csv; charset=' . get_option( 'blog_charset' ),
|
||||
'Content-disposition: attachment;filename=tainacan.csv'] // TODO filter/optional
|
||||
);
|
||||
|
||||
$items = $response->get_data();
|
||||
|
||||
if (sizeof($items) > 0) {
|
||||
|
||||
$csv = fopen('php://memory', 'r+');
|
||||
|
||||
$headers = array_map(function($a) {
|
||||
return $a['name'];
|
||||
}, $items[0]['metadata']);
|
||||
|
||||
fputcsv($csv, $headers, ';', '"' );
|
||||
|
||||
foreach ($items as $item) {
|
||||
$values = array_map(function($a) {
|
||||
return $a['value_as_string'];
|
||||
}, $item['metadata']);
|
||||
|
||||
fputcsv($csv, $values, ';', '"' );
|
||||
|
||||
}
|
||||
rewind($csv);
|
||||
$ret_csv = stream_get_contents($csv);
|
||||
fclose($csv);
|
||||
$response->set_data($ret_csv);
|
||||
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers;
|
||||
|
||||
use Tainacan\Mappers_Handler;
|
||||
|
||||
/**
|
||||
* abstract class for implement exposer types
|
||||
*
|
||||
*/
|
||||
abstract class Exposer {
|
||||
|
||||
protected $mappers = true; // List of supported mappers, leave true for all
|
||||
public $accept_no_mapper = true;
|
||||
public $slug = ''; // type slug for url safe
|
||||
private $name = ''; // User friendly Name
|
||||
private $description = ''; // User friendly Description
|
||||
|
||||
/**
|
||||
* Returns i18n exposer name
|
||||
*
|
||||
* Must be implemented by Exposer class
|
||||
*
|
||||
* @param string Name
|
||||
* @return string
|
||||
*/
|
||||
protected function set_name($name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets i18n exposer description
|
||||
*
|
||||
* @param string Description
|
||||
* @return string
|
||||
*/
|
||||
protected function set_description($description) {
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the exposer name
|
||||
* @return string exposer name
|
||||
*/
|
||||
public function get_name() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the exposer description
|
||||
* @return string exposer description
|
||||
*/
|
||||
public function get_description() {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* return exposer object as an array
|
||||
* @return array
|
||||
*/
|
||||
public function _toArray() {
|
||||
return [
|
||||
'slug' => $this->slug,
|
||||
'name' => $this->get_name(),
|
||||
'description' => $this->get_description(),
|
||||
'mappers' => $this->get_mappers(),
|
||||
'accept_no_mapper' => $this->accept_no_mapper,
|
||||
'class_name' => get_class($this)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Change response after api callbacks
|
||||
* @param \WP_REST_Response $response
|
||||
* @param \WP_REST_Server $handler
|
||||
* @param \WP_REST_Request $request
|
||||
* @return \WP_REST_Response
|
||||
*/
|
||||
public abstract function rest_request_after_callbacks( $response, $handler, $request );
|
||||
|
||||
/**
|
||||
* Return list of supported mappers for this type
|
||||
* @return array List of mappers
|
||||
*/
|
||||
public function get_mappers() {
|
||||
$mappers = apply_filters('tainacan-exporser-type-mappers', $this->mappers, $this);
|
||||
if ( true === $mappers ) {
|
||||
$mappers_handler = Mappers_Handler::get_instance();
|
||||
$registered_mappers = $mappers_handler->get_mappers();
|
||||
return array_keys($registered_mappers);
|
||||
} elseif (is_array($mappers)) {
|
||||
return $mappers;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,302 @@
|
|||
<?php
|
||||
namespace Tainacan;
|
||||
|
||||
use Tainacan\Mappers_Hanlder;
|
||||
use Tainacan\Mappers\Mapper;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Load exposers classes
|
||||
*/
|
||||
class Exposers_Handler {
|
||||
|
||||
protected $exposers = [];
|
||||
|
||||
private static $instance = null;
|
||||
private static $request = null;
|
||||
|
||||
|
||||
const TYPE_PARAM = 'exposer';
|
||||
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
self::$instance = $this;
|
||||
//$this->register_exposer('Tainacan\Exposers\Xml');
|
||||
//$this->register_exposer('Tainacan\Exposers\Txt');
|
||||
$this->register_exposer('Tainacan\Exposers\Html');
|
||||
$this->register_exposer('Tainacan\Exposers\Csv');
|
||||
//$this->register_exposer('Tainacan\Exposers\OAI_PMH');
|
||||
//$this->register_exposer('Tainacan\Exposers\JSON_LD');
|
||||
do_action('tainacan-register-exposer', $this);
|
||||
|
||||
add_filter( 'rest_request_after_callbacks', [$this, 'rest_request_after_callbacks'], 10, 3 ); //exposer types
|
||||
|
||||
add_filter( 'tainacan-api-get-items-alternate', [$this, 'filter_check_items_request'], 10, 2 );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* register exposers type
|
||||
*
|
||||
* @param $class_name string | object The class name or the instance
|
||||
*/
|
||||
public function register_exposer( $class_name ){
|
||||
$obj = $class_name;
|
||||
if( is_object( $class_name ) ){
|
||||
$class_name = get_class( $class_name );
|
||||
} else {
|
||||
$obj = new $class_name;
|
||||
}
|
||||
|
||||
if(!in_array( $class_name, $this->exposers)){
|
||||
$this->exposers[$obj->slug] = $class_name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* unregister exposers type
|
||||
*
|
||||
* @param $class_name string | object The class name or the instance
|
||||
*/
|
||||
public function unregister_exposer( $class_name ){
|
||||
$obj = $class_name;
|
||||
if( is_object( $class_name ) ){
|
||||
$class_name = get_class( $class_name );
|
||||
} else {
|
||||
$obj = new $class_name;
|
||||
}
|
||||
|
||||
if ( array_key_exists($obj->slug, $this->exposers) ) {
|
||||
unset($this->exposers[$obj->slug]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return namespaced class name
|
||||
* @param string $class_name
|
||||
* @param boolean $root
|
||||
* @param string $prefix
|
||||
* @return string
|
||||
*/
|
||||
public function check_class_name($class_name, $root = false, $prefix = 'Tainacan\Exposer\\') {
|
||||
if(is_string($class_name)) {
|
||||
if(array_key_exists($class_name, $this->exposers)) {
|
||||
$class_name = $this->exposers[$class_name];
|
||||
$prefix = '';
|
||||
}
|
||||
}
|
||||
$class = $prefix.sanitize_text_field($class_name);
|
||||
$class = str_replace(['-', ' '], ['_', '_'], $class);
|
||||
|
||||
return ($root ? '\\' : '').$class;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* check if is a tainacan request
|
||||
* @param \WP_REST_Request $request
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_tainacan_request($request) {
|
||||
return substr($request->get_route(), 0, strlen('/tainacan/v2')) == '/tainacan/v2';
|
||||
}
|
||||
|
||||
/**
|
||||
* check if query came from url
|
||||
* @param \WP_REST_Request $request
|
||||
*/
|
||||
public static function request_has_url_param($request) {
|
||||
$Tainacan_Exposers = self::get_instance();
|
||||
$query_url_params = $request->get_query_params();
|
||||
if (
|
||||
is_array($query_url_params) && array_key_exists(self::TYPE_PARAM, $query_url_params) &&
|
||||
$Tainacan_Exposers->exposer_exists($query_url_params[self::TYPE_PARAM])
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* adapt request response to exposer type
|
||||
* @param \WP_REST_Response $response
|
||||
* @param \WP_REST_Server $handler
|
||||
* @param \WP_REST_Request $request
|
||||
* @return \WP_REST_Response
|
||||
*/
|
||||
public function rest_request_after_callbacks( $response, $handler, $request ) {
|
||||
if($this->is_tainacan_request($request) && $response instanceof \WP_REST_Response ) {
|
||||
if($request->get_method() == 'GET') {
|
||||
if($exposer = $this->request_has_exposer($request)) {
|
||||
$type_responde = $exposer->rest_request_after_callbacks($response, $handler, $request);
|
||||
if(self::request_has_url_param($request)) {
|
||||
header(implode('', $response->get_headers()));
|
||||
echo stripcslashes($response->get_data());
|
||||
exit();
|
||||
}
|
||||
return $type_responde;
|
||||
}
|
||||
}
|
||||
}
|
||||
// default JSON response
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if exposer is registered
|
||||
* @param string $exposer
|
||||
* @return boolean
|
||||
*/
|
||||
public function exposer_exists($exposer) {
|
||||
return in_array($this->check_class_name($exposer), $this->exposers);
|
||||
}
|
||||
/**
|
||||
* Return Exposer if request has exposer, false otherwise
|
||||
* @param \WP_REST_Request $request
|
||||
* @return Exposers\Exposer|boolean false
|
||||
*/
|
||||
public static function request_has_exposer($request) {
|
||||
$body = json_decode( $request->get_body(), true );
|
||||
$query_url_params = $request->get_query_params();
|
||||
$Tainacan_Exposers = self::get_instance();
|
||||
if(
|
||||
is_array($body) && array_key_exists(self::TYPE_PARAM, $body) &&
|
||||
$Tainacan_Exposers->exposer_exists($body[self::TYPE_PARAM])
|
||||
) {
|
||||
$exposer = $Tainacan_Exposers->check_class_name($body[self::TYPE_PARAM], true);
|
||||
return new $exposer;
|
||||
} elseif (
|
||||
is_array($query_url_params) && array_key_exists(self::TYPE_PARAM, $query_url_params) &&
|
||||
$Tainacan_Exposers->exposer_exists($query_url_params[self::TYPE_PARAM])
|
||||
){
|
||||
$exposer = $Tainacan_Exposers->check_class_name($query_url_params[self::TYPE_PARAM], true);
|
||||
return new $exposer;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return list of registered exposers
|
||||
* @param string $output output format, ARRAY_N or OBJECT
|
||||
* @return array of slug or array of \Tainacan\Exposers\Exposer
|
||||
*/
|
||||
public function get_exposers($output = \ARRAY_N) {
|
||||
$ret = [];
|
||||
switch ($output) {
|
||||
case \OBJECT:
|
||||
foreach ($this->exposers as $type) {
|
||||
$ret[] = new $type;
|
||||
}
|
||||
break;
|
||||
case \ARRAY_N:
|
||||
default:
|
||||
return $this->exposers;
|
||||
break;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters Items request
|
||||
* and checks if current exposer (if any) supports this mapper.
|
||||
*
|
||||
* If it does not, return 404
|
||||
*/
|
||||
public function filter_check_items_request($response, $request) {
|
||||
$exposer = $this->request_has_exposer($request);
|
||||
$mapper = Mappers_Handler::get_instance()->get_mapper_from_request($request);
|
||||
if ( false === $exposer ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$accpeted_mappers = $exposer->get_mappers();
|
||||
|
||||
if ( $exposer->accept_no_mapper ) {
|
||||
// translators: To be displayed in a list of supported mappers of a exposer. Example: Supported mappers: No mapper, Dublin Core
|
||||
array_unshift($accpeted_mappers, __('No mapper', 'tainacan'));
|
||||
}
|
||||
|
||||
$accpeted_mappers_string = implode(', ', $accpeted_mappers);
|
||||
|
||||
$return404 = false;
|
||||
|
||||
if ( $mapper == false ) {
|
||||
|
||||
if ( $exposer->accept_no_mapper ) {
|
||||
return $response;
|
||||
} else {
|
||||
$return404 = true;
|
||||
// translators: 1: Exposer name, 2: List of accepted mappers. example: CSV exposer requires one of the following mappers: dublin-core, other-mapper
|
||||
$error_message = sprintf( __('%1$s exposer requires one of the following mappers: %2$s', 'tainacan'), $exposer->get_name(), $accpeted_mappers_string);
|
||||
}
|
||||
} else {
|
||||
|
||||
if ( in_array($mapper->slug, $accpeted_mappers) ) {
|
||||
return $response;
|
||||
} else {
|
||||
$return404 = true;
|
||||
// translators: 1: Exposer name. 2: List of accpeted mappers. example: CSV exposer does not support current mapper. Supported mappers are: dublin-core, other-mapper
|
||||
$error_message = sprintf( __('%1$s exposer does not support current mapper. Supported mappers are: %2$s', 'tainacan'), $exposer->get_name(), $accpeted_mappers_string);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( $return404 ) {
|
||||
$response = new \WP_REST_Response([
|
||||
'error_message' => $error_message,
|
||||
], 404);
|
||||
remove_filter( 'rest_request_after_callbacks', [$this, 'rest_request_after_callbacks']);
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $base_url url base for exposer parameters append
|
||||
* @return string|string[][]
|
||||
*/
|
||||
public static function get_exposer_urls($base_url = '') {
|
||||
return [];
|
||||
$Tainacan_Exposers = self::get_instance();
|
||||
$mappers = $Tainacan_Exposers->get_mappers(\OBJECT);
|
||||
$types = $Tainacan_Exposers->get_types(\OBJECT);
|
||||
$urls = [];
|
||||
foreach ($types as $type) {
|
||||
$url = $base_url.(strpos($base_url, '?') === false ? '?' : '&').self::TYPE_PARAM.'='.$type->slug;
|
||||
$urls[$type->slug] = [$url];
|
||||
if(is_array($type->get_mappers())) {
|
||||
$first = true; // first is default, jump
|
||||
foreach ($type->get_mappers() as $type_mapper) {
|
||||
if($first) {
|
||||
$first = false;
|
||||
continue;
|
||||
}
|
||||
$urls[$type->slug][] = $url.'&'.self::MAPPER_PARAM.'='.$type_mapper;
|
||||
}
|
||||
} else {
|
||||
foreach ($mappers as $mapper) {
|
||||
$urls[$type->slug][] = $url.'&'.self::MAPPER_PARAM.'='.$mapper->slug;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $urls;
|
||||
}
|
||||
}
|
|
@ -1,453 +0,0 @@
|
|||
<?php
|
||||
namespace Tainacan\Exposers;
|
||||
|
||||
use Tainacan\Exposers\Mappers\Mapper;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Load exposers classes
|
||||
*/
|
||||
class Exposers {
|
||||
|
||||
protected $types = [];
|
||||
protected $mappers = [];
|
||||
private static $instance = null;
|
||||
private static $request = null;
|
||||
|
||||
const MAPPER_CLASS_PREFIX = 'Tainacan\Exposers\Mappers\\';
|
||||
const MAPPER_PARAM = 'mapper';
|
||||
const TYPE_PARAM = 'exposer';
|
||||
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
self::$instance = $this;
|
||||
$this->register_exposer_type('Tainacan\Exposers\Types\Xml');
|
||||
$this->register_exposer_type('Tainacan\Exposers\Types\Txt');
|
||||
$this->register_exposer_type('Tainacan\Exposers\Types\Html');
|
||||
$this->register_exposer_type('Tainacan\Exposers\Types\Csv');
|
||||
$this->register_exposer_type('Tainacan\Exposers\Types\OAI_PMH');
|
||||
$this->register_exposer_type('Tainacan\Exposers\Types\JSON_LD');
|
||||
do_action('tainacan-register-exposer-types', $this);
|
||||
$this->register_exposer_mapper('Tainacan\Exposers\Mappers\Dublin_Core');
|
||||
$this->register_exposer_mapper('Tainacan\Exposers\Mappers\Value');
|
||||
do_action('tainacan-register-exposer-mappers', $this);
|
||||
|
||||
|
||||
add_filter( 'rest_request_after_callbacks', [$this, 'rest_request_after_callbacks'], 10, 3 ); //exposer types
|
||||
add_filter( 'tainacan-rest-response', [$this, 'rest_response'], 10, 2 ); // exposer mapper
|
||||
add_filter( 'tainacan-admin-i18n', [$this, 'mappers_i18n']);
|
||||
}
|
||||
|
||||
/**
|
||||
* register exposers types class on array of types
|
||||
*
|
||||
* @param $class_name string | object The class name or the instance
|
||||
*/
|
||||
public function register_exposer_type( $class_name ){
|
||||
$obj = $class_name;
|
||||
if( is_object( $class_name ) ){
|
||||
$class_name = get_class( $class_name );
|
||||
} else {
|
||||
$obj = new $class_name;
|
||||
}
|
||||
|
||||
if(!in_array( $class_name, $this->types)){
|
||||
$this->types[$obj->slug] = $class_name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* register exposers mappers class on array of types
|
||||
*
|
||||
* @param $class_name string | object The class name or the object instance
|
||||
*/
|
||||
public function register_exposer_mapper( $class_name ){
|
||||
$obj = $class_name;
|
||||
if( is_object( $class_name ) ){
|
||||
$class_name = get_class( $class_name );
|
||||
} else {
|
||||
$obj = new $class_name;
|
||||
}
|
||||
|
||||
if(!in_array( $class_name, $this->mappers)){
|
||||
$this->mappers[$obj->slug] = $class_name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return namespaced class name
|
||||
* @param string $class_name
|
||||
* @param boolean $root
|
||||
* @param string $prefix
|
||||
* @return string
|
||||
*/
|
||||
public function check_class_name($class_name, $root = false, $prefix = 'Tainacan\Exposers\Types\\') {
|
||||
if(is_string($class_name)) {
|
||||
if(array_key_exists($class_name, $this->types)) {
|
||||
$class_name = $this->types[$class_name];
|
||||
$prefix = '';
|
||||
} elseif( array_key_exists($class_name, $this->mappers)) {
|
||||
$class_name = $this->mappers[$class_name];
|
||||
$prefix = '';
|
||||
}
|
||||
}
|
||||
$class = $prefix.sanitize_text_field($class_name);
|
||||
$class = str_replace(['-', ' '], ['_', '_'], $class);
|
||||
|
||||
return ($root ? '\\' : '').$class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if rest response need mapper
|
||||
* @param array $item_arr
|
||||
* @param \WP_REST_Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function rest_response($item_arr, $request) {
|
||||
if($request->get_method() == 'GET' && $this->is_tainacan_request($request)) {
|
||||
if($exposer = $this->request_has_mapper($request)) {
|
||||
if(substr($request->get_route(), 0, strlen('/tainacan/v2/items')) == '/tainacan/v2/items') { //TODO do it at rest not here
|
||||
$repos_items = \Tainacan\Repositories\Items::get_instance();
|
||||
$item = $repos_items->fetch($item_arr['id']);
|
||||
$items_metadata = $item->get_metadata();
|
||||
$prepared_item = [];
|
||||
foreach ($items_metadata as $item_metadata){
|
||||
array_push($prepared_item, $item_metadata->_toArray());
|
||||
}
|
||||
$item_arr = $prepared_item;
|
||||
}
|
||||
return $this->map($item_arr, $exposer, $request); //TODO request -> args
|
||||
}
|
||||
}
|
||||
return $item_arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of mapped metadatum
|
||||
* @param array $item_arr
|
||||
* @param Mappers\Mapper $mapper
|
||||
* @return array
|
||||
*/
|
||||
protected function map_metadatum($item_arr, $mapper) {
|
||||
$ret = $item_arr;
|
||||
$metadatum_mapping = $item_arr['metadatum']['exposer_mapping'];
|
||||
if(array_key_exists($mapper->slug, $metadatum_mapping)) {
|
||||
if(
|
||||
is_string($metadatum_mapping[$mapper->slug]) && is_array($mapper->metadata) && !array_key_exists( $metadatum_mapping[$mapper->slug], $mapper->metadata) ||
|
||||
is_array($metadatum_mapping[$mapper->slug]) && $mapper->allow_extra_metadata != true
|
||||
) {
|
||||
throw new \Exception('Invalid Mapper Option');
|
||||
}
|
||||
$slug = '';
|
||||
if(is_string($metadatum_mapping[$mapper->slug])) {
|
||||
$slug = $metadatum_mapping[$mapper->slug];
|
||||
} else {
|
||||
$slug = $metadatum_mapping[$mapper->slug]['slug'];
|
||||
}
|
||||
$ret = [$mapper->prefix.$slug.$mapper->sufix => $item_arr['value']]; //TODO Validate option
|
||||
} elseif($mapper->slug == 'value') {
|
||||
$ret = [$item_arr['metadatum']['name'] => $item_arr['value']];
|
||||
} else {
|
||||
$ret = [];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $item_arr
|
||||
* @param Mappers\Mapper $mapper
|
||||
* @param \WP_REST_Request $resquest
|
||||
* @return array
|
||||
*/
|
||||
protected function map($item_arr, $mapper, $resquest) {
|
||||
$ret = $item_arr;
|
||||
if(array_key_exists('metadatum', $item_arr)){ // getting a unique metadatum
|
||||
$ret = $this->map_metadatum($item_arr, $mapper);
|
||||
} else { // array of elements
|
||||
$ret = [];
|
||||
foreach ($item_arr as $item) {
|
||||
if(array_key_exists('metadatum', $item)) {
|
||||
$ret = array_merge($ret, $this->map($item, $mapper, $resquest) );
|
||||
} else {
|
||||
$ret[] = $this->map($item, $mapper, $resquest);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if is a tainacan request
|
||||
* @param \WP_REST_Request $request
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_tainacan_request($request) {
|
||||
return substr($request->get_route(), 0, strlen('/tainacan/v2')) == '/tainacan/v2';
|
||||
}
|
||||
|
||||
/**
|
||||
* check if query came from url
|
||||
* @param \WP_REST_Request $request
|
||||
*/
|
||||
public static function request_has_url_param($request) {
|
||||
$Tainacan_Exposers = self::get_instance();
|
||||
$query_url_params = $request->get_query_params();
|
||||
if (
|
||||
is_array($query_url_params) && array_key_exists(self::TYPE_PARAM, $query_url_params) &&
|
||||
$Tainacan_Exposers->has_type($query_url_params[self::TYPE_PARAM])
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* adapt request response to exposer type
|
||||
* @param \WP_REST_Response $response
|
||||
* @param \WP_REST_Server $handler
|
||||
* @param \WP_REST_Request $request
|
||||
* @return \WP_REST_Response
|
||||
*/
|
||||
public function rest_request_after_callbacks( $response, $handler, $request ) {
|
||||
if($this->is_tainacan_request($request) && $response instanceof \WP_REST_Response ) {
|
||||
if($request->get_method() == 'GET') {
|
||||
if($exposer = $this->request_has_type($request)) {
|
||||
$type_responde = $exposer->rest_request_after_callbacks($response, $handler, $request);
|
||||
if(self::request_has_url_param($request)) {
|
||||
header(implode('', $response->get_headers()));
|
||||
echo stripcslashes($response->get_data());
|
||||
exit();
|
||||
}
|
||||
return $type_responde;
|
||||
}
|
||||
} elseif($request->get_method() == 'POST') {
|
||||
if($mapper = $this->request_has_mapper($request)) {
|
||||
return $this->create_mapped_metadata( $response, $handler, $request, $mapper );
|
||||
}
|
||||
}
|
||||
}
|
||||
// default JSON response
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if type is registered
|
||||
* @param string $type
|
||||
* @return boolean
|
||||
*/
|
||||
public function has_type($type) {
|
||||
return in_array($this->check_class_name($type), $this->types);
|
||||
}
|
||||
/**
|
||||
* Return Type if request has type, false otherwise
|
||||
* @param \WP_REST_Request $request
|
||||
* @return Types\Type|boolean false
|
||||
*/
|
||||
public static function request_has_type($request) {
|
||||
$body = json_decode( $request->get_body(), true );
|
||||
$query_url_params = $request->get_query_params();
|
||||
$Tainacan_Exposers = self::get_instance();
|
||||
if(
|
||||
is_array($body) && array_key_exists(self::TYPE_PARAM, $body) &&
|
||||
$Tainacan_Exposers->has_type($body[self::TYPE_PARAM])
|
||||
) {
|
||||
$type = $Tainacan_Exposers->check_class_name($body[self::TYPE_PARAM], true);
|
||||
return new $type;
|
||||
} elseif (
|
||||
is_array($query_url_params) && array_key_exists(self::TYPE_PARAM, $query_url_params) &&
|
||||
$Tainacan_Exposers->has_type($query_url_params[self::TYPE_PARAM])
|
||||
){
|
||||
$type = $Tainacan_Exposers->check_class_name($query_url_params[self::TYPE_PARAM], true);
|
||||
return new $type;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if mapper is registered
|
||||
* @param string $mapper
|
||||
* @return boolean
|
||||
*/
|
||||
public function has_mapper($mapper) {
|
||||
return in_array($this->check_class_name($mapper, false, self::MAPPER_CLASS_PREFIX), $this->mappers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is a mapper
|
||||
* @param \WP_REST_Request $request
|
||||
* @return Mappers\Mapper|boolean false
|
||||
*/
|
||||
public static function request_has_mapper($request) {
|
||||
$body = json_decode( $request->get_body(), true );
|
||||
$Tainacan_Exposers = self::get_instance();
|
||||
$query_url_params = $request->get_query_params();
|
||||
|
||||
$type = self::request_has_type($request);
|
||||
if( // There are a defined mapper
|
||||
is_array($body) && array_key_exists(self::MAPPER_PARAM, $body) &&
|
||||
$Tainacan_Exposers->has_mapper($body[self::MAPPER_PARAM])
|
||||
) {
|
||||
if(
|
||||
$type === false || // do not have a exposer type
|
||||
$type->get_mappers() === true || // the type accept all mappers
|
||||
( is_array($type->get_mappers()) && in_array($body[self::MAPPER_PARAM], $type->get_mappers()) )
|
||||
) { // the current mapper is accepted by type
|
||||
$mapper = $Tainacan_Exposers->check_class_name($body[self::MAPPER_PARAM], true, self::MAPPER_CLASS_PREFIX);
|
||||
return new $mapper;
|
||||
}
|
||||
} elseif(
|
||||
is_array($query_url_params) && array_key_exists(self::MAPPER_PARAM, $query_url_params) &&
|
||||
$Tainacan_Exposers->has_mapper($query_url_params[self::MAPPER_PARAM])
|
||||
) {
|
||||
if(
|
||||
$type === false || // do not have a exposer type
|
||||
$type->get_mappers() === true || // the type accept all mappers
|
||||
( is_array($type->get_mappers()) && in_array($query_url_params[self::MAPPER_PARAM], $type->get_mappers()) )
|
||||
) { // the current mapper is accepted by type
|
||||
$mapper = $Tainacan_Exposers->check_class_name($query_url_params[self::MAPPER_PARAM], true, self::MAPPER_CLASS_PREFIX);
|
||||
return new $mapper;
|
||||
}
|
||||
} elseif( is_object($type) && is_array($type->get_mappers()) && count($type->get_mappers()) > 0 ) { //there are no defined mapper, let use the first one o list if has a list
|
||||
$mapper = $Tainacan_Exposers->check_class_name($type->get_mappers()[0], true, self::MAPPER_CLASS_PREFIX);
|
||||
return new $mapper;
|
||||
}
|
||||
return false; // No mapper need, using Tainacan defautls
|
||||
}
|
||||
|
||||
/**
|
||||
* Add mappers data to translations
|
||||
* @param array $i18n_strings
|
||||
* @return array
|
||||
*/
|
||||
public function mappers_i18n($i18n_strings) {
|
||||
foreach ($this->mappers as $mapper) {
|
||||
$obj = new $mapper;
|
||||
$i18n_strings[$obj->slug] = $obj->slug; // For url breadcrumb translations
|
||||
$i18n_strings[$obj->name] = $obj->name;
|
||||
}
|
||||
return $i18n_strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of registered mappers
|
||||
* @param string $output output format, ARRAY_N or OBJECT
|
||||
*/
|
||||
public function get_mappers($output = ARRAY_N) {
|
||||
$ret = [];
|
||||
switch ($output) {
|
||||
case OBJECT:
|
||||
foreach ($this->mappers as $mapper) {
|
||||
$ret[] = new $mapper;
|
||||
}
|
||||
break;
|
||||
case ARRAY_N:
|
||||
default:
|
||||
return $this->mappers;
|
||||
break;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of registered types
|
||||
* @param string $output output format, ARRAY_N or OBJECT
|
||||
* @return array of slug or array of \Tainacan\Exposers\Types\Type
|
||||
*/
|
||||
public function get_types($output = \ARRAY_N) {
|
||||
$ret = [];
|
||||
switch ($output) {
|
||||
case \OBJECT:
|
||||
foreach ($this->types as $type) {
|
||||
$ret[] = new $type;
|
||||
}
|
||||
break;
|
||||
case \ARRAY_N:
|
||||
default:
|
||||
return $this->types;
|
||||
break;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \WP_REST_Response $response
|
||||
* @param \WP_REST_Server $handler
|
||||
* @param \WP_REST_Request $request
|
||||
* @param Mapper $mapper
|
||||
*/
|
||||
public function create_mapped_metadata( $response, $handler, $request, $mapper ) {
|
||||
if($response instanceof \WP_REST_Response && $response->get_status() == 201) {
|
||||
$collection_array = $response->get_data();
|
||||
$id = $collection_array['id'];
|
||||
$mapper_metadata = $mapper->metadata;
|
||||
if(is_array($mapper_metadata) ) {
|
||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||
foreach ($mapper_metadata as $slug => $mapper_metadatum) {
|
||||
if(array_key_exists('core_metadatum', $mapper_metadatum) && $mapper_metadatum['core_metadatum'] != false) continue;
|
||||
|
||||
$metadatum = new \Tainacan\Entities\Metadatum();
|
||||
if(
|
||||
array_key_exists('metadata_type', $mapper_metadatum) &&
|
||||
$mapper_metadatum['metadata_type'] != false &&
|
||||
class_exists($mapper_metadatum['metadata_type'])
|
||||
) {
|
||||
$metadatum->set_metadata_type($mapper_metadatum['metadata_type']);
|
||||
} else {
|
||||
$metadatum->set_metadata_type('Tainacan\Metadata_Types\Text');
|
||||
}
|
||||
$metadatum->set_name($mapper_metadatum['label']);
|
||||
$metadatum->set_semantic_uri($mapper_metadatum['URI']);
|
||||
$metadatum->set_exposer_mapping([
|
||||
$mapper->slug => $slug
|
||||
]);
|
||||
$metadatum->set_status('publish');
|
||||
$metadatum->set_collection_id($id);
|
||||
$metadatum->set_slug($slug);
|
||||
if($metadatum->validate()) $Tainacan_Metadata->insert($metadatum);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $base_url url base for exposer parameters append
|
||||
* @return string|string[][]
|
||||
*/
|
||||
public static function get_exposer_urls($base_url = '') {
|
||||
$Tainacan_Exposers = self::get_instance();
|
||||
$mappers = $Tainacan_Exposers->get_mappers(\OBJECT);
|
||||
$types = $Tainacan_Exposers->get_types(\OBJECT);
|
||||
$urls = [];
|
||||
foreach ($types as $type) {
|
||||
$url = $base_url.(strpos($base_url, '?') === false ? '?' : '&').self::TYPE_PARAM.'='.$type->slug;
|
||||
$urls[$type->slug] = [$url];
|
||||
if(is_array($type->get_mappers())) {
|
||||
$first = true; // first is default, jump
|
||||
foreach ($type->get_mappers() as $type_mapper) {
|
||||
if($first) {
|
||||
$first = false;
|
||||
continue;
|
||||
}
|
||||
$urls[$type->slug][] = $url.'&'.self::MAPPER_PARAM.'='.$type_mapper;
|
||||
}
|
||||
} else {
|
||||
foreach ($mappers as $mapper) {
|
||||
$urls[$type->slug][] = $url.'&'.self::MAPPER_PARAM.'='.$mapper->slug;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $urls;
|
||||
}
|
||||
}
|
|
@ -1,16 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Types;
|
||||
namespace Tainacan\Exposers;
|
||||
|
||||
/**
|
||||
* Generate a Html formated response
|
||||
*
|
||||
*/
|
||||
class Html extends Type {
|
||||
class Html extends Exposer {
|
||||
|
||||
public $mappers = ['Value'];
|
||||
public $slug = 'html'; // type slug for url safe
|
||||
public $name = 'HyperText Markup Language';
|
||||
protected $mappers = true;
|
||||
public $accept_no_mapper = true;
|
||||
|
||||
function __construct() {
|
||||
$this->set_name( 'HTML' );
|
||||
$this->set_description( __('A simple HTML table', 'tainacan') );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -19,14 +25,55 @@ class Html extends Type {
|
|||
*/
|
||||
public function rest_request_after_callbacks( $response, $handler, $request ) {
|
||||
$response->set_headers( ['Content-Type: text/html; charset=' . get_option( 'blog_charset' )] );
|
||||
|
||||
$items = $response->get_data();
|
||||
|
||||
$html = '
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<table>
|
||||
<table border="1">
|
||||
';
|
||||
$html .= $this->array_to_html($response->get_data());
|
||||
$html .= '
|
||||
|
||||
if (sizeof($items) > 0) {
|
||||
|
||||
$headers = array_map(function($a) {
|
||||
return $a['name'];
|
||||
}, $items[0]['metadata']);
|
||||
|
||||
$html .= '<thead><tr>';
|
||||
|
||||
foreach ( $items[0]['metadata'] as $slug => $meta ) {
|
||||
$html .= '<th>' . $meta['name'] . '</th>';
|
||||
}
|
||||
|
||||
$html .= '</tr></thead>' . "\n";
|
||||
|
||||
$html .= '<tbody>';
|
||||
|
||||
foreach ($items as $item) {
|
||||
$values = array_map(function($a) {
|
||||
return $a['value_as_string'];
|
||||
}, $item['metadata']);
|
||||
|
||||
$html .= '<tr>';
|
||||
|
||||
foreach ( $item['metadata'] as $slug => $meta ) {
|
||||
$html .= '<td>' . $meta['value_as_html'] . '</td>';
|
||||
}
|
||||
|
||||
$html .= '</tr>' . "\n";
|
||||
|
||||
|
||||
}
|
||||
|
||||
$html .= '</tbody>' . "\n";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
$html .= '
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Types;
|
||||
namespace Tainacan\Exposers;
|
||||
|
||||
/**
|
||||
* Generate a text formated response
|
||||
*
|
||||
*/
|
||||
class JSON_LD extends Type {
|
||||
class JSON_LD extends Exposer {
|
||||
|
||||
public $mappers = ['value', 'dublin-core'];
|
||||
public $slug = 'json-ld'; // type slug for url safe
|
||||
|
@ -24,7 +24,7 @@ class JSON_LD extends Type {
|
|||
'Content-Type: application/json; charset=' . get_option( 'blog_charset' ),
|
||||
'Link: <'.get_bloginfo('url').'/item.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"'
|
||||
]);
|
||||
$mapper = \Tainacan\Exposers\Exposers::request_has_mapper($request);
|
||||
$mapper = \Tainacan\Exposers_Handler::get_mapper_from_request($request);
|
||||
if(property_exists($mapper, 'XML_namespace') && !empty($mapper->XML_namespace)) {
|
||||
$namespace = $mapper->XML_namespace;
|
||||
$context_slug = str_replace(':', '', $mapper->prefix);
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Types;
|
||||
namespace Tainacan\Exposers;
|
||||
|
||||
/**
|
||||
* Generate a OAI_PMH/oai_dc formated response
|
||||
*
|
||||
*/
|
||||
class OAI_PMH extends Xml {
|
||||
class OAI_PMH extends Exposer {
|
||||
|
||||
public $mappers = ['Dublin Core'];
|
||||
public $slug = 'oai-pmh'; // type slug for url safe
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Types;
|
||||
namespace Tainacan\Exposers;
|
||||
|
||||
/**
|
||||
* Generate a text formated response
|
||||
*
|
||||
*/
|
||||
class Txt extends Type {
|
||||
class Txt extends Exposer {
|
||||
|
||||
public $mappers = ['Value'];
|
||||
public $slug = 'txt'; // type slug for url safe
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Types;
|
||||
namespace Tainacan\Exposers;
|
||||
|
||||
/**
|
||||
* Generate a Csv formated response
|
||||
*
|
||||
*/
|
||||
class Xml extends Type {
|
||||
class Xml extends Exposer {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @see \Tainacan\Exposers\Types\Type::extension
|
||||
|
@ -23,7 +23,7 @@ class Xml extends Type {
|
|||
*/
|
||||
public function rest_request_after_callbacks( $response, $handler, $request ) {
|
||||
$response->set_headers( ['Content-Type: application/xml; charset=' . get_option( 'blog_charset' )] );
|
||||
$mapper = \Tainacan\Exposers\Exposers::request_has_mapper($request);
|
||||
$mapper = \Tainacan\Exposers_Handler::get_mapper_from_request($request);
|
||||
$xml = new \SimpleXMLElement( '<?xml version="1.0"?><data></data>' );
|
||||
$namespace = null;
|
||||
$xml_root = $xml;
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Mappers;
|
||||
|
||||
/**
|
||||
* Mapper class for export metadata in key => value format where key can be defined
|
||||
*
|
||||
*/
|
||||
class Value extends Mapper {
|
||||
public $slug = 'value';
|
||||
public $name = 'Value';
|
||||
public $allow_extra_metadata = true;
|
||||
public $context_url = '';
|
||||
public $header = '';
|
||||
public $metadata = false;
|
||||
public $show_ui = false;
|
||||
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Types;
|
||||
|
||||
/**
|
||||
* Generate a Csv formated response
|
||||
*
|
||||
*/
|
||||
class Csv extends Type {
|
||||
|
||||
/**
|
||||
* List of supported mappers
|
||||
* @var array
|
||||
*/
|
||||
public $mappers = ['Value'];
|
||||
public $slug = 'csv'; // type slug for url safe
|
||||
public $name = 'Comma-separated values';
|
||||
|
||||
/**
|
||||
*
|
||||
* {@inheritDoc}
|
||||
* @see \Tainacan\Exposers\Types\Type::rest_request_after_callbacks()
|
||||
*/
|
||||
public function rest_request_after_callbacks( $response, $handler, $request ) {
|
||||
$response->set_headers( [
|
||||
'Content-Type: text/csv; charset=' . get_option( 'blog_charset' ),
|
||||
'Content-disposition: attachment;filename=tainacan.csv'] // TODO filter/optional
|
||||
);
|
||||
|
||||
$csv = fopen('php://memory', 'w');
|
||||
$this->array_to_csv($response->get_data(), apply_filters('tainacan-exposer-csv', $csv));
|
||||
rewind($csv);
|
||||
$ret_csv = stream_get_contents($csv);
|
||||
fclose($csv);
|
||||
$response->set_data($ret_csv);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Array to Csv
|
||||
* @param array $data
|
||||
* @param string $csv
|
||||
* @return string
|
||||
*/
|
||||
protected function array_to_csv( $data, $csv ) {
|
||||
fputcsv($csv, array_keys($data), apply_filters('tainacan-exposer-csv-delimiter', ';') );
|
||||
fputcsv($csv, array_values($data), apply_filters('tainacan-exposer-csv-delimiter', ';') );
|
||||
return $csv;
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Types;
|
||||
|
||||
/**
|
||||
* abstract class for implement exposer types
|
||||
*
|
||||
*/
|
||||
abstract class Type {
|
||||
|
||||
protected $mappers = true; // List of supported mapper, leave true for all
|
||||
protected $extension = 'tnc'; // extension sufix for multi operation system compatibility
|
||||
public $slug = ''; // type slug for url safe
|
||||
public $name = ''; // User friend Name
|
||||
|
||||
/**
|
||||
* Change response after api callbacks
|
||||
* @param \WP_REST_Response $response
|
||||
* @param \WP_REST_Server $handler
|
||||
* @param \WP_REST_Request $request
|
||||
* @return \WP_REST_Response
|
||||
*/
|
||||
public abstract function rest_request_after_callbacks( $response, $handler, $request );
|
||||
|
||||
/**
|
||||
* Return list of supported mappers for this type
|
||||
*/
|
||||
public function get_mappers() {
|
||||
return apply_filters('tainacan-exporser-type-mappers', $this->mappers, $this);
|
||||
}
|
||||
|
||||
public function get_extension() {
|
||||
return $this->extension;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import axios from 'axios';
|
||||
|
||||
const tainacan = axios.create({
|
||||
baseURL: tainacan_plugin.root
|
||||
baseURL: tainacan_plugin.tainacan_api_url
|
||||
});
|
||||
|
||||
tainacan.defaults.headers.common['X-WP-Nonce'] = tainacan_plugin.nonce;
|
||||
|
|
|
@ -9,10 +9,22 @@ class Background_Importer extends Background_Process {
|
|||
*/
|
||||
protected $action = 'import';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $finish_status = 1;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->set_name( __('Importer', 'tainacan') );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $status
|
||||
*/
|
||||
private function set_finish_status( $status ){
|
||||
$this->finish_status = $status;
|
||||
}
|
||||
|
||||
function task($batch) {
|
||||
|
||||
|
@ -26,8 +38,14 @@ class Background_Importer extends Background_Process {
|
|||
|
||||
$this->write_log($key, $object->get_log());
|
||||
$this->write_error_log($key, $object->get_error_log());
|
||||
|
||||
if( count($object->get_error_log()) > 0 ){
|
||||
$this->set_finish_status(2);
|
||||
}
|
||||
|
||||
if (true === $object->get_abort()) {
|
||||
$this->set_finish_status(3);
|
||||
$this->close($key);
|
||||
throw new \Exception('Process aborted by Importer');
|
||||
}
|
||||
|
||||
|
@ -46,6 +64,48 @@ class Background_Importer extends Background_Process {
|
|||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a process as done
|
||||
*
|
||||
* @param string $key Key.
|
||||
* @param array $data Data.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function close( $key ) {
|
||||
global $wpdb;
|
||||
|
||||
switch ($this->finish_status){
|
||||
case 1:
|
||||
$label = __('Process completed','tainacan');
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$label = __('Process completed with errors','tainacan');
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$label = __('Process aborted by Importer','tainacan');
|
||||
break;
|
||||
|
||||
default:
|
||||
$label = __('Process completed','tainacan');
|
||||
break;
|
||||
}
|
||||
|
||||
$wpdb->update(
|
||||
$this->table,
|
||||
[
|
||||
'done' => 1,
|
||||
'progress_label' => $label,
|
||||
'progress_value' => 100
|
||||
],
|
||||
['ID' => $key]
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import axios from 'axios';
|
||||
|
||||
export const tainacan = axios.create({
|
||||
baseURL: tainacan_plugin.root
|
||||
baseURL: tainacan_plugin.tainacan_api_url
|
||||
});
|
||||
|
||||
tainacan.defaults.headers.common['X-WP-Nonce'] = tainacan_plugin.nonce;
|
||||
|
||||
export const wp = axios.create({
|
||||
baseURL: tainacan_plugin.root_wp_api
|
||||
baseURL: tainacan_plugin.wp_api_url
|
||||
});
|
||||
|
||||
wp.defaults.headers.common['X-WP-Nonce'] = tainacan_plugin.nonce;
|
||||
|
|
|
@ -82,7 +82,8 @@ export const fetchItems = ({ rootGetters, dispatch, commit }, { collectionId, is
|
|||
'itemsListTemplate': items,
|
||||
'total': res.headers['x-wp-total'],
|
||||
hasFiltered: hasFiltered,
|
||||
advancedSearchResults: advancedSearchResults});
|
||||
advancedSearchResults: advancedSearchResults,
|
||||
itemsPerPage: res.headers['x-wp-itemperpage']});
|
||||
} else {
|
||||
commit('setItems', items);
|
||||
resolve({
|
||||
|
@ -90,10 +91,12 @@ export const fetchItems = ({ rootGetters, dispatch, commit }, { collectionId, is
|
|||
'total': res.headers['x-wp-total'],
|
||||
totalPages: res.headers['x-wp-totalpages'],
|
||||
hasFiltered: hasFiltered,
|
||||
advancedSearchResults: advancedSearchResults });
|
||||
advancedSearchResults: advancedSearchResults ,
|
||||
itemsPerPage: res.headers['x-wp-itemperpage'] });
|
||||
}
|
||||
dispatch('search/setTotalItems', res.headers['x-wp-total'], { root: true } );
|
||||
dispatch('search/setTotalPages', res.headers['x-wp-totalpages'], { root: true } );
|
||||
dispatch('search/setItemsPerPage', res.headers['x-wp-itemsperpage'], { root: true } );
|
||||
})
|
||||
.catch((thrown) => {
|
||||
if (axios.isCancel(thrown)) {
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import { tainacan } from '../../../axios/axios.js';
|
||||
|
||||
export const fetchAvailableExposers = ({ commit }) => {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
tainacan.get('/exposers/' )
|
||||
.then(res => {
|
||||
commit('setAvailableExposers', res.data);
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
})
|
||||
});
|
||||
};
|
|
@ -0,0 +1,3 @@
|
|||
export const getAvailableExposers = state => {
|
||||
return state.availableExposers;
|
||||
};
|
|
@ -0,0 +1,15 @@
|
|||
import * as actions from './actions.js';
|
||||
import * as mutations from './mutations.js';
|
||||
import * as getters from './getters.js';
|
||||
|
||||
const state = {
|
||||
availableExposers: []
|
||||
};
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
actions,
|
||||
mutations,
|
||||
getters,
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export const setAvailableExposers = (state, availableExposers) => {
|
||||
state.availableExposers = availableExposers;
|
||||
};
|
|
@ -64,6 +64,7 @@ export const setPage = ({ commit }, page ) => {
|
|||
|
||||
export const setItemsPerPage = ({ commit }, page ) => {
|
||||
commit('setPostQueryAttribute', { attr: 'perpage', value: page } );
|
||||
commit('setItemsPerPage', page );
|
||||
};
|
||||
|
||||
export const setStatus= ({ commit }, status ) => {
|
||||
|
|
|
@ -30,10 +30,11 @@ export const getPage = state => {
|
|||
};
|
||||
|
||||
export const getItemsPerPage = state => {
|
||||
if (state.postquery.paged == undefined)
|
||||
if (state.itemsPerPage == undefined)
|
||||
return 12;
|
||||
else
|
||||
return Number(state.postquery.perpage);
|
||||
else {
|
||||
return Number(state.itemsPerPage);
|
||||
}
|
||||
};
|
||||
|
||||
export const getOrder = state => {
|
||||
|
|
|
@ -24,7 +24,8 @@ const state = {
|
|||
},
|
||||
filter_tags: [],
|
||||
totalItems: 0,
|
||||
totalPages: 0
|
||||
totalPages: 0,
|
||||
itemsPerPage: 12 // Not the same as postquery.perpage as API may have limited it's value
|
||||
};
|
||||
|
||||
export default {
|
||||
|
|
|
@ -127,6 +127,10 @@ export const setTotalPages = ( state, totalPages ) => {
|
|||
state.totalPages = totalPages;
|
||||
};
|
||||
|
||||
export const setItemsPerPage = ( state, itemsPerPage ) => {
|
||||
state.itemsPerPage = itemsPerPage;
|
||||
};
|
||||
|
||||
export const setSearchQuery = ( state, searchQuery ) => {
|
||||
|
||||
if (searchQuery != '') {
|
||||
|
|
|
@ -12,6 +12,7 @@ import importer from './modules/importer';
|
|||
import bgprocess from './modules/bgprocess';
|
||||
import bulkedition from './modules/bulk-edition';
|
||||
import exporter from './modules/exporter';
|
||||
import exposer from './modules/exposer';
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
|
@ -35,6 +36,7 @@ export default new Vuex.Store({
|
|||
importer,
|
||||
bgprocess,
|
||||
bulkedition,
|
||||
exporter
|
||||
exporter,
|
||||
exposer
|
||||
}
|
||||
})
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Mappers;
|
||||
namespace Tainacan\Mappers;
|
||||
|
||||
/**
|
||||
* Support Dublin Core Mapping
|
||||
|
@ -13,69 +13,56 @@ class Dublin_Core extends Mapper {
|
|||
public $allow_extra_metadata = true;
|
||||
public $context_url = 'http://dublincore.org/documents/dcmi-terms/';
|
||||
public $header = '<?xml version="1.0"?><!DOCTYPE rdf:RDF SYSTEM "http://dublincore.org/2000/12/01-dcmes-xml-dtd.dtd"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" ></rdf:RDF>';
|
||||
public $prefix = 'dc:';
|
||||
public $prefixes = [
|
||||
'dc' => 'http://purl.org/dc/elements/1.1/'
|
||||
];
|
||||
public $metadata = [
|
||||
'contributor' => [
|
||||
'URI' => 'http://purl.org/dc/elements/1.1/contributor',
|
||||
'dc:contributor' => [
|
||||
'label' => 'Contributor'
|
||||
],
|
||||
'coverage' => [
|
||||
'URI' => 'http://purl.org/dc/elements/1.1/coverage',
|
||||
'dc:coverage' => [
|
||||
'label' => 'Coverage'
|
||||
],
|
||||
'creator' => [
|
||||
'URI' => 'http://purl.org/dc/elements/1.1/creator',
|
||||
'dc:creator' => [
|
||||
'label' => 'Creator'
|
||||
],
|
||||
'date' => [
|
||||
'URI' => 'http://purl.org/dc/elements/1.1/date',
|
||||
'dc:date' => [
|
||||
'label' => 'Date',
|
||||
'metadata_type' => 'date'
|
||||
],
|
||||
'description' => [
|
||||
'URI' => 'http://purl.org/dc/elements/1.1/description',
|
||||
'dc:description' => [
|
||||
'label' => 'Description',
|
||||
'core_metadatum' => 'description'
|
||||
],
|
||||
'format' => [
|
||||
'URI' => 'http://purl.org/dc/elements/1.1/format',
|
||||
'dc:format' => [
|
||||
'label' => 'Format',
|
||||
],
|
||||
'identifier' => [
|
||||
'URI' => 'http://purl.org/dc/elements/1.1/identifier',
|
||||
'dc:identifier' => [
|
||||
'label' => 'Identifier'
|
||||
],
|
||||
'language' => [
|
||||
'URI' => 'http://purl.org/dc/elements/1.1/language',
|
||||
'dc:language' => [
|
||||
'label' => 'Language'
|
||||
],
|
||||
'publisher' => [
|
||||
'URI' => 'http://purl.org/dc/elements/1.1/publisher',
|
||||
'dc:publisher' => [
|
||||
'label' => 'Publisher'
|
||||
],
|
||||
'relation' => [
|
||||
'URI' => 'http://purl.org/dc/elements/1.1/relation',
|
||||
'dc:relation' => [
|
||||
'label' => 'Relation'
|
||||
],
|
||||
'rights' => [
|
||||
'URI' => 'http://purl.org/dc/elements/1.1/rights',
|
||||
'dc:rights' => [
|
||||
'label' => 'Rights'
|
||||
],
|
||||
'source' => [
|
||||
'URI' => 'http://purl.org/dc/elements/1.1/source',
|
||||
'dc:source' => [
|
||||
'label' => 'Source'
|
||||
],
|
||||
'subject' => [
|
||||
'URI' => 'http://purl.org/dc/elements/1.1/subject',
|
||||
'dc:subject' => [
|
||||
'label' => 'Subject'
|
||||
],
|
||||
'title' => [
|
||||
'URI' => 'http://purl.org/dc/elements/1.1/title',
|
||||
'dc:title' => [
|
||||
'label' => 'Title',
|
||||
'core_metadatum' => 'title'
|
||||
],
|
||||
'type' => [
|
||||
'URI' => 'http://purl.org/dc/elements/1.1/type',
|
||||
'dc:type' => [
|
||||
'label' => 'Type'
|
||||
]
|
||||
];
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Mappers;
|
||||
namespace Tainacan\Mappers;
|
||||
|
||||
abstract class Mapper {
|
||||
public $slug = null; // Slug of Mapper, used as option on api call
|
||||
|
@ -47,4 +47,23 @@ abstract class Mapper {
|
|||
'header' => $this->header
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the semantic URL for a given metadatum of this mapper.
|
||||
* Basically it identifies the property prefix and replace it with the URL of that prefix
|
||||
*
|
||||
* @param string $meta_slug The slug of the metadata present in this mapper to get the URL from
|
||||
* @return string The semantic URL for this metadata. Empty string in case of failure
|
||||
*/
|
||||
public function get_url($meta_slug) {
|
||||
$parts = explode(':', $meta_slug);
|
||||
$url = '';
|
||||
if (sizeof($parts) == 2) {
|
||||
if (isset($this->prefixes[$parts[0]])) {
|
||||
$url = trailingslashit( $this->prefixes[$parts[0]] ) . $parts[1];
|
||||
}
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,342 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan;
|
||||
|
||||
class Mappers_Handler {
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
protected $mappers = [];
|
||||
|
||||
const MAPPER_CLASS_PREFIX = 'Tainacan\Mappers\\';
|
||||
const MAPPER_PARAM = 'mapper';
|
||||
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
self::$instance = $this;
|
||||
|
||||
$this->register_mapper('Tainacan\Mappers\Dublin_Core');
|
||||
|
||||
do_action('tainacan-register-mappers', $this);
|
||||
|
||||
add_filter( 'tainacan-admin-i18n', [$this, 'mappers_i18n']);
|
||||
|
||||
add_action('tainacan-api-collection-created', [$this, 'create_mapped_collection'], 10, 2);
|
||||
|
||||
add_filter('tainacan-api-items-prepare-for-response', [$this, 'filter_item_api_response'], 10, 3);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* register mappers class
|
||||
*
|
||||
* @param $class_name string | object The class name or the object instance
|
||||
*/
|
||||
public function register_mapper( $class_name ){
|
||||
$obj = $class_name;
|
||||
if( is_object( $class_name ) ){
|
||||
$class_name = get_class( $class_name );
|
||||
} else {
|
||||
$obj = new $class_name;
|
||||
}
|
||||
|
||||
if(!in_array( $class_name, $this->mappers)){
|
||||
$this->mappers[$obj->slug] = $class_name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* unregister mappers class
|
||||
*
|
||||
* @param $class_name string | object The class name or the object instance
|
||||
*/
|
||||
public function unregister_mapper( $class_name ){
|
||||
$obj = $class_name;
|
||||
if( is_object( $class_name ) ){
|
||||
$class_name = get_class( $class_name );
|
||||
} else {
|
||||
$obj = new $class_name;
|
||||
}
|
||||
|
||||
if ( array_key_exists($obj->slug, $this->mappers) ) {
|
||||
unset($this->mappers[$obj->slug]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return list of registered mappers
|
||||
* @param string $output output format, ARRAY_N or OBJECT
|
||||
*/
|
||||
public function get_mappers($output = ARRAY_N) {
|
||||
$ret = [];
|
||||
switch ($output) {
|
||||
case OBJECT:
|
||||
foreach ($this->mappers as $mapper) {
|
||||
$ret[] = new $mapper;
|
||||
}
|
||||
break;
|
||||
case ARRAY_N:
|
||||
default:
|
||||
return $this->mappers;
|
||||
break;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mapper object by its slug
|
||||
* @param false|\Tainacan\Mappers\Mapper False or Object
|
||||
*/
|
||||
public function get_mapper($slug) {
|
||||
|
||||
if ( $this->mapper_exists($slug) ) {
|
||||
|
||||
$mappers = $this->get_mappers();
|
||||
|
||||
$className = $mappers[$slug];
|
||||
|
||||
return new $className();
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add mappers data to translations
|
||||
* @param array $i18n_strings
|
||||
* @return array
|
||||
*/
|
||||
public function mappers_i18n($i18n_strings) {
|
||||
foreach ($this->mappers as $mapper) {
|
||||
$obj = new $mapper;
|
||||
$i18n_strings[$obj->slug] = $obj->slug; // For url breadcrumb translations
|
||||
$i18n_strings[$obj->name] = $obj->name;
|
||||
}
|
||||
return $i18n_strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is a mapper
|
||||
* @param \WP_REST_Request $request
|
||||
* @return Mappers\Mapper|boolean false
|
||||
*/
|
||||
public static function get_mapper_from_request($request) {
|
||||
$body = json_decode( $request->get_body(), true );
|
||||
$Tainacan_Mappers = self::get_instance();
|
||||
$query_url_params = $request->get_query_params();
|
||||
|
||||
$return_mapper = false;
|
||||
|
||||
if( // There is a defined mapper
|
||||
is_array($body) && array_key_exists(self::MAPPER_PARAM, $body) &&
|
||||
$Tainacan_Mappers->mapper_exists($body[self::MAPPER_PARAM])
|
||||
) {
|
||||
$mapper = $Tainacan_Mappers->check_class_name($body[self::MAPPER_PARAM], true, self::MAPPER_CLASS_PREFIX);
|
||||
$return_mapper = new $mapper;
|
||||
} elseif(
|
||||
is_array($query_url_params) && array_key_exists(self::MAPPER_PARAM, $query_url_params) &&
|
||||
$Tainacan_Mappers->mapper_exists($query_url_params[self::MAPPER_PARAM])
|
||||
) {
|
||||
$mapper = $Tainacan_Mappers->check_class_name($query_url_params[self::MAPPER_PARAM], true, self::MAPPER_CLASS_PREFIX);
|
||||
$return_mapper = new $mapper;
|
||||
}
|
||||
return apply_filters('tainacan-get-mapper-from-request', $return_mapper, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of mapped metadatum
|
||||
* @param array $item_arr
|
||||
* @param Mappers\Mapper $mapper
|
||||
* @return array
|
||||
*/
|
||||
protected function map_metadatum($item_arr, $mapper) {
|
||||
$ret = $item_arr;
|
||||
$metadatum_mapping = $item_arr['metadatum']['exposer_mapping'];
|
||||
if(array_key_exists($mapper->slug, $metadatum_mapping)) {
|
||||
if(
|
||||
is_string($metadatum_mapping[$mapper->slug]) && is_array($mapper->metadata) && !array_key_exists( $metadatum_mapping[$mapper->slug], $mapper->metadata) ||
|
||||
is_array($metadatum_mapping[$mapper->slug]) && $mapper->allow_extra_metadata != true
|
||||
) {
|
||||
throw new \Exception('Invalid Mapper Option');
|
||||
}
|
||||
$slug = '';
|
||||
if(is_string($metadatum_mapping[$mapper->slug])) {
|
||||
$slug = $metadatum_mapping[$mapper->slug];
|
||||
} else {
|
||||
$slug = $metadatum_mapping[$mapper->slug]['slug'];
|
||||
}
|
||||
$ret = [$mapper->prefix.$slug.$mapper->sufix => $item_arr['value']]; //TODO Validate option
|
||||
} elseif($mapper->slug == 'value') {
|
||||
$ret = [$item_arr['metadatum']['name'] => $item_arr['value']];
|
||||
} else {
|
||||
$ret = [];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $item_arr
|
||||
* @param Mappers\Mapper $mapper
|
||||
* @param \WP_REST_Request $resquest
|
||||
* @return array
|
||||
*/
|
||||
protected function map($item_arr, $mapper, $resquest) {
|
||||
$ret = $item_arr;
|
||||
if(array_key_exists('metadatum', $item_arr)){ // getting a unique metadatum
|
||||
$ret = $this->map_metadatum($item_arr, $mapper);
|
||||
} else { // array of elements
|
||||
$ret = [];
|
||||
foreach ($item_arr as $item) {
|
||||
if(array_key_exists('metadatum', $item)) {
|
||||
$ret = array_merge($ret, $this->map($item, $mapper, $resquest) );
|
||||
} else {
|
||||
$ret[] = $this->map($item, $mapper, $resquest);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if mapper is registered
|
||||
* @param string $mapper
|
||||
* @return boolean
|
||||
*/
|
||||
public function mapper_exists($mapper) {
|
||||
return in_array($this->check_class_name($mapper, false, self::MAPPER_CLASS_PREFIX), $this->mappers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return namespaced class name
|
||||
* @param string $class_name
|
||||
* @param boolean $root
|
||||
* @param string $prefix
|
||||
* @return string
|
||||
*/
|
||||
public function check_class_name($class_name, $root = false, $prefix = 'Tainacan\Mapper\\') {
|
||||
if(is_string($class_name)) {
|
||||
if( array_key_exists($class_name, $this->mappers)) {
|
||||
$class_name = $this->mappers[$class_name];
|
||||
$prefix = '';
|
||||
}
|
||||
}
|
||||
$class = $prefix.sanitize_text_field($class_name);
|
||||
$class = str_replace(['-', ' '], ['_', '_'], $class);
|
||||
|
||||
return ($root ? '\\' : '').$class;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $collection collection passed by the collections API endpoint
|
||||
* @param \WP_REST_Request $request
|
||||
*/
|
||||
public function create_mapped_collection( $collection, $request ) {
|
||||
|
||||
|
||||
if ($mapper = $this->get_mapper_from_request($request)) {
|
||||
|
||||
$mapper_metadata = $mapper->metadata;
|
||||
if(is_array($mapper_metadata) ) {
|
||||
|
||||
$id = $collection['id'];
|
||||
$collection_object = \Tainacan\Repositories\Collections::get_instance()->fetch($id);
|
||||
|
||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||
foreach ($mapper_metadata as $slug => $mapper_metadatum) {
|
||||
if( array_key_exists('core_metadatum', $mapper_metadatum) ) {
|
||||
$method = 'get_core_' . $mapper_metadatum['core_metadatum'] . '_metadatum';
|
||||
if (method_exists($collection_object, $method)) {
|
||||
$core_meta = $collection_object->$method();
|
||||
$_meta_mapping = $core_meta->get_exposer_mapping();
|
||||
$_meta_mapping[$mapper->slug] = $slug;
|
||||
$core_meta->set_exposer_mapping($_meta_mapping);
|
||||
if ($core_meta->validate()) {
|
||||
$Tainacan_Metadata->insert($core_meta);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$metadatum = new \Tainacan\Entities\Metadatum();
|
||||
if(
|
||||
array_key_exists('metadata_type', $mapper_metadatum) &&
|
||||
$mapper_metadatum['metadata_type'] != false &&
|
||||
class_exists($mapper_metadatum['metadata_type'])
|
||||
) {
|
||||
$metadatum->set_metadata_type($mapper_metadatum['metadata_type']);
|
||||
} else {
|
||||
$metadatum->set_metadata_type('Tainacan\Metadata_Types\Text');
|
||||
}
|
||||
$metadatum->set_name($mapper_metadatum['label']);
|
||||
$metadatum->set_semantic_uri($mapper->get_url($slug));
|
||||
$metadatum->set_exposer_mapping([
|
||||
$mapper->slug => $slug
|
||||
]);
|
||||
$metadatum->set_status('publish');
|
||||
$metadatum->set_collection_id($id);
|
||||
$metadatum->set_slug($slug);
|
||||
if($metadatum->validate()) $Tainacan_Metadata->insert($metadatum);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function filter_item_api_response($item_arr, $item, $request) {
|
||||
|
||||
$mapper = $this->get_mapper_from_request($request);
|
||||
|
||||
if (!$mapper) {
|
||||
return $item_arr;
|
||||
}
|
||||
|
||||
$mapper_meta = $mapper->metadata;
|
||||
$mapped_meta = [];
|
||||
|
||||
foreach ($item_arr['metadata'] as $slug => $meta) {
|
||||
|
||||
if ( array_key_exists($mapper->slug, $meta['mapping']) ) {
|
||||
$mapped_slug = $meta['mapping'][$mapper->slug];
|
||||
|
||||
// Extra metadata
|
||||
if ( is_array($mapped_slug) ) {
|
||||
$url = $mapped_slug['uri'];
|
||||
$label = $mapped_slug['label'];
|
||||
$mapped_slug = $mapped_slug['slug'];
|
||||
} else {
|
||||
$url = $mapper->get_url( $mapped_slug );
|
||||
$label = $mapper->metadata[$mapped_slug]['label'];
|
||||
}
|
||||
|
||||
|
||||
$mapped_meta[ $mapped_slug ] = $meta;
|
||||
$mapped_meta[ $mapped_slug ]['semantic_url'] = $url;
|
||||
$mapped_meta[ $mapped_slug ]['name'] = $label;
|
||||
$mapped_meta[ $mapped_slug ]['slug'] = $mapped_slug;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$item_arr['metadata'] = $mapped_meta;
|
||||
|
||||
return $item_arr;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -14,6 +14,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
|||
$TAINACAN_BASE_URL = plugins_url('', __FILE__);
|
||||
const TAINACAN_API_DIR = __DIR__ . '/api/';
|
||||
const TAINACAN_CLASSES_DIR = __DIR__ . '/classes/';
|
||||
$TAINACAN_API_MAX_ITEMS_PER_PAGE = defined('TAINACAN_API_MAX_ITEMS_PER_PAGE') ? TAINACAN_API_MAX_ITEMS_PER_PAGE : 96;
|
||||
require_once(TAINACAN_CLASSES_DIR . 'tainacan-creator.php');
|
||||
require_once(TAINACAN_API_DIR . 'tainacan-rest-creator.php');
|
||||
require_once('migrations.php');
|
||||
|
|
|
@ -179,7 +179,7 @@ function tainacan_the_faceted_search() {
|
|||
$props = ' ';
|
||||
|
||||
$default_view_mode = apply_filters( 'tainacan-default-view-mode-for-themes', 'masonry' );
|
||||
$enabled_view_modes = apply_filters( 'tainacan-enabled-view-modes-for-themes', ['table', 'cards', 'masonry'] );
|
||||
$enabled_view_modes = apply_filters( 'tainacan-enabled-view-modes-for-themes', ['table', 'cards', 'masonry', 'slideshow'] );
|
||||
|
||||
// if in a collection page
|
||||
$collection_id = tainacan_get_collection_id();
|
||||
|
|
|
@ -379,7 +379,8 @@ export default {
|
|||
this.slideIndex = updatedSlideIndex;
|
||||
|
||||
// console.log("Após: " + this.slideIndex + " " + this.$refs.mySwiper.swiper.activeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -413,9 +414,9 @@ export default {
|
|||
this.$refs.mySwiper.swiper.activeIndex = this.slideIndex + 0;
|
||||
|
||||
} else if (this.slideItems.length > 0) {
|
||||
if (this.$refs.mySwiper.swiper.activeIndex == this.slideItems.length - 1 && this.page < this.totalPages)
|
||||
if (this.$refs.mySwiper.swiper.activeIndex == this.slideItems.length - 1 && this.page < this.totalPages) {
|
||||
oldVal == undefined ? this.$eventBusSearch.setPage(this.page + 1) : this.$eventBusSearch.setPage(this.maxPage + 1);
|
||||
else if (this.$refs.mySwiper.swiper.activeIndex == 0 && this.page > 1 && this.slideItems.length < this.totalItems) {
|
||||
} else if (this.$refs.mySwiper.swiper.activeIndex == 0 && this.page > 1 && this.slideItems.length < this.totalItems) {
|
||||
oldVal == undefined ? this.$eventBusSearch.setPage(this.page - 1) : this.$eventBusSearch.setPage(this.minPage - 1);
|
||||
}
|
||||
}
|
||||
|
@ -478,18 +479,14 @@ export default {
|
|||
|
||||
this.$nextTick(() => {
|
||||
if (this.readjustedSlideIndex != undefined) {
|
||||
this.slideIndex = this.readjustedSlideIndex;
|
||||
// if (this.slideIndex != undefined && this.$refs.mySwiper.swiper.slides[this.slideIndex] != undefined)
|
||||
// this.$refs.mySwiper.swiper.slides[this.slideIndex].click();
|
||||
this.$refs.mySwiper.swiper.activeIndex = this.slideIndex + 0;
|
||||
|
||||
if (this.slideIndex != undefined && this.$refs.mySwiper.swiper.slides[this.readjustedSlideIndex] != undefined)
|
||||
this.$refs.mySwiper.swiper.slides[this.readjustedSlideIndex].click();
|
||||
|
||||
this.readjustedSlideIndex = undefined;
|
||||
|
||||
if (this.slideIndex != undefined && this.$refs.mySwiper.swiper.slides[this.slideIndex] != undefined)
|
||||
this.$refs.mySwiper.swiper.slides[this.slideIndex].click();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
nextSlide() {
|
||||
if (this.$refs.mySwiper.swiper != undefined)
|
||||
|
@ -536,7 +533,6 @@ export default {
|
|||
}
|
||||
},
|
||||
loadCurrentItem() {
|
||||
|
||||
if ((this.slideItems && this.slideItems[this.slideIndex] && this.slideItems[this.slideIndex].id != undefined)) {
|
||||
|
||||
this.isLoadingItem = true;
|
||||
|
|
|
@ -193,8 +193,8 @@ class TAINACAN_REST_Export_Controller extends TAINACAN_UnitApiTestCase {
|
|||
extract($this->create_requirements());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
\Tainacan\Exposers\Exposers::TYPE_PARAM => 'Xml',
|
||||
\Tainacan\Exposers\Exposers::MAPPER_PARAM => 'Value',
|
||||
\Tainacan\Exposers_Handler::TYPE_PARAM => 'Xml',
|
||||
\Tainacan\Exposers_Handler::MAPPER_PARAM => 'Value',
|
||||
'export-background' => false
|
||||
]);
|
||||
|
||||
|
@ -232,7 +232,7 @@ class TAINACAN_REST_Export_Controller extends TAINACAN_UnitApiTestCase {
|
|||
extract($this->create_requirements());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
\Tainacan\Exposers\Exposers::TYPE_PARAM => 'Xml',
|
||||
\Tainacan\Exposers_Handler::TYPE_PARAM => 'Xml',
|
||||
'exposer-map' => 'Value',
|
||||
'export-background' => false
|
||||
]);
|
|
@ -38,7 +38,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
'collection' => $collection,
|
||||
'metadata_type' => $type,
|
||||
'exposer_mapping' => [
|
||||
'dublin-core' => 'language'
|
||||
'dublin-core' => 'dc:language'
|
||||
]
|
||||
),
|
||||
true,
|
||||
|
@ -53,7 +53,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
'collection' => $collection,
|
||||
'metadata_type' => $type,
|
||||
'exposer_mapping' => [
|
||||
'dublin-core' => 'subject'
|
||||
'dublin-core' => 'dc:subject'
|
||||
]
|
||||
),
|
||||
true,
|
||||
|
@ -101,11 +101,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals($this->item->get_id(), $data['item']['id']);
|
||||
$this->assertEquals('TestValues_exposers', $data['value']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
\Tainacan\Exposers\Exposers::MAPPER_PARAM => 'Value',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/'. $this->metadatum->get_id() );
|
||||
$request->set_body($item_exposer_json);
|
||||
$response = $this->server->dispatch($request);
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$data = $response->get_data();
|
||||
|
@ -159,7 +155,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
\Tainacan\Exposers\Exposers::TYPE_PARAM => 'Xml',
|
||||
\Tainacan\Exposers_Handler::TYPE_PARAM => 'Xml',
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/'. $this->metadatum->get_id() );
|
||||
|
@ -179,7 +175,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertInstanceOf('SimpleXMLElement', @simplexml_load_string($data));
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
\Tainacan\Exposers\Exposers::MAPPER_PARAM => 'Dublin Core',
|
||||
\Tainacan\Exposers_Handler::MAPPER_PARAM => 'Dublin Core',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/'. $this->metadatum->get_id() );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -189,8 +185,8 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('TestValues_exposers', $data['dc:language']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
\Tainacan\Exposers\Exposers::TYPE_PARAM => 'Xml',
|
||||
\Tainacan\Exposers\Exposers::MAPPER_PARAM => 'Dublin Core',
|
||||
\Tainacan\Exposers_Handler::TYPE_PARAM => 'Xml',
|
||||
\Tainacan\Exposers_Handler::MAPPER_PARAM => 'Dublin Core',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -233,7 +229,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('TestValues_exposers_slug', $data['value']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
\Tainacan\Exposers\Exposers::MAPPER_PARAM => 'dublin-core',
|
||||
\Tainacan\Exposers_Handler::MAPPER_PARAM => 'dublin-core',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/'. $this->metadatum->get_id() );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -243,8 +239,8 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('TestValues_exposers_slug', $data['dc:language']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
\Tainacan\Exposers\Exposers::TYPE_PARAM => 'xml',
|
||||
\Tainacan\Exposers\Exposers::MAPPER_PARAM => 'dublin-core',
|
||||
\Tainacan\Exposers_Handler::TYPE_PARAM => 'xml',
|
||||
\Tainacan\Exposers_Handler::MAPPER_PARAM => 'dublin-core',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -270,7 +266,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
extract($this->create_meta_requirements());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
\Tainacan\Exposers\Exposers::TYPE_PARAM => 'OAI-PMH',
|
||||
\Tainacan\Exposers_Handler::TYPE_PARAM => 'OAI-PMH',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -293,8 +289,8 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
extract($this->create_meta_requirements());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
\Tainacan\Exposers\Exposers::TYPE_PARAM => 'Html',
|
||||
\Tainacan\Exposers\Exposers::MAPPER_PARAM => 'Value'
|
||||
\Tainacan\Exposers_Handler::TYPE_PARAM => 'Html',
|
||||
\Tainacan\Exposers_Handler::MAPPER_PARAM => 'Value'
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -353,7 +349,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
\Tainacan\Exposers\Exposers::TYPE_PARAM => 'Csv',
|
||||
\Tainacan\Exposers_Handler::TYPE_PARAM => 'Csv',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -426,7 +422,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
\Tainacan\Exposers\Exposers::MAPPER_PARAM => 'Value',
|
||||
\Tainacan\Exposers_Handler::MAPPER_PARAM => 'Value',
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/items/' . $this->item->get_id() );
|
||||
|
@ -445,7 +441,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
*/
|
||||
public function test_mapped_new_collection() {
|
||||
$collection_JSON = json_encode([
|
||||
\Tainacan\Exposers\Exposers::MAPPER_PARAM => 'Dublin Core',
|
||||
\Tainacan\Exposers_Handler::MAPPER_PARAM => 'Dublin Core',
|
||||
'name' => 'TesteJsonAddDublin_Core',
|
||||
'description' => 'Teste JSON Dublin Core mapped',
|
||||
'status' => 'publish'
|
||||
|
@ -501,8 +497,8 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('TestValues_exposers', $data['value']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
\Tainacan\Exposers\Exposers::TYPE_PARAM => 'json-ld',
|
||||
\Tainacan\Exposers\Exposers::MAPPER_PARAM => 'dublin-core',
|
||||
\Tainacan\Exposers_Handler::TYPE_PARAM => 'json-ld',
|
||||
\Tainacan\Exposers_Handler::MAPPER_PARAM => 'dublin-core',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -528,7 +524,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
|
||||
$id = $item->get_id();
|
||||
$base_url = "{$this->namespace}/items/{$id}/";
|
||||
$urls = \Tainacan\Exposers\Exposers::get_exposer_urls($base_url);
|
||||
$urls = \Tainacan\Exposers_Handler::get_exposer_urls($base_url);
|
||||
var_dump($urls);return;
|
||||
foreach ($urls as $type => $type_urls) {
|
||||
foreach ($type_urls as $url) {
|
|
@ -18,17 +18,15 @@ class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCas
|
|||
true
|
||||
);
|
||||
|
||||
$type = $this->tainacan_metadatum_factory->create_metadatum('text');
|
||||
|
||||
$metadatum = $this->tainacan_entity_factory->create_entity(
|
||||
'metadatum',
|
||||
array(
|
||||
'name' => 'test_MetadatumMappers',
|
||||
'description' => 'descricao',
|
||||
'collection' => $collection,
|
||||
'metadata_type' => $type,
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
||||
'exposer_mapping' => [
|
||||
'dublin-core' => 'language'
|
||||
'dublin-core' => 'dc:language'
|
||||
]
|
||||
),
|
||||
true,
|
||||
|
@ -41,7 +39,22 @@ class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCas
|
|||
'name' => 'test_MetadatumMappers2',
|
||||
'description' => 'descricao2',
|
||||
'collection' => $collection,
|
||||
'metadata_type' => $type
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Text'
|
||||
),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$metadatum3 = $this->tainacan_entity_factory->create_entity(
|
||||
'metadatum',
|
||||
array(
|
||||
'name' => 'test_MetadatumMappers3',
|
||||
'description' => 'descricao3',
|
||||
'collection' => $collection,
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
||||
'exposer_mapping' => [
|
||||
'dublin-core' => 'dc:creator'
|
||||
]
|
||||
),
|
||||
true,
|
||||
true
|
||||
|
@ -60,6 +73,8 @@ class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCas
|
|||
$this->collection = $collection;
|
||||
$this->item = $item;
|
||||
$this->metadatum = $metadatum;
|
||||
$this->metadatum2 = $metadatum2;
|
||||
$this->metadatum3 = $metadatum3;
|
||||
return ['collection' => $collection, 'item' => $item, 'metadatum' => $metadatum, 'metadatum2' => $metadatum2];
|
||||
}
|
||||
|
||||
|
@ -71,10 +86,10 @@ class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCas
|
|||
|
||||
$data = $metadatum_mapper_response->get_data();
|
||||
|
||||
$Tainacan_Metadata = \Tainacan\Exposers\Exposers::get_instance();
|
||||
$Tainacan_Metadata = \Tainacan\Mappers_Handler::get_instance();
|
||||
|
||||
$metadatum_mappers = $Tainacan_Metadata->get_mappers("OBJECT");
|
||||
/** @var \Tainacan\Exposers\Mappers\Mapper $metadatum_mapper **/
|
||||
/** @var \Tainacan\Mappers\Mapper $metadatum_mapper **/
|
||||
foreach ($metadatum_mappers as $k => $metadatum_mapper) {
|
||||
if(!$metadatum_mapper->show_ui) unset($metadatum_mappers[$k]);
|
||||
}
|
||||
|
@ -96,7 +111,7 @@ class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCas
|
|||
public function test_update_metadatum_mappers(){
|
||||
extract($this->create_meta_requirements());
|
||||
|
||||
$dc = new \Tainacan\Exposers\Mappers\Dublin_Core();
|
||||
$dc = new \Tainacan\Mappers\Dublin_Core();
|
||||
|
||||
$metadatum_mapper_request = new \WP_REST_Request('POST', $this->namespace . '/metadatum-mappers');
|
||||
$metadatum_mapper_json = json_encode([
|
||||
|
@ -104,7 +119,7 @@ class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCas
|
|||
['metadatum_id' => $metadatum->get_id(), 'mapper_metadata' => 'contributor'],
|
||||
['metadatum_id' => $metadatum2->get_id(), 'mapper_metadata' => 'coverage']
|
||||
],
|
||||
\Tainacan\Exposers\Exposers::MAPPER_PARAM => $dc->slug
|
||||
\Tainacan\Mappers_Handler::MAPPER_PARAM => $dc->slug
|
||||
]);
|
||||
$metadatum_mapper_request->set_body($metadatum_mapper_json);
|
||||
$metadatum_mapper_response = $this->server->dispatch($metadatum_mapper_request);
|
||||
|
@ -132,7 +147,7 @@ class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCas
|
|||
public function test_update_metadatum_mappers_new_meta(){
|
||||
extract($this->create_meta_requirements());
|
||||
|
||||
$dc = new \Tainacan\Exposers\Mappers\Dublin_Core();
|
||||
$dc = new \Tainacan\Mappers\Dublin_Core();
|
||||
|
||||
$metadatum_mapper_request = new \WP_REST_Request('POST', $this->namespace . '/metadatum-mappers');
|
||||
$new_metadatum_mapper = new \stdClass();
|
||||
|
@ -144,7 +159,7 @@ class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCas
|
|||
['metadatum_id' => $metadatum->get_id(), 'mapper_metadata' => 'contributor'],
|
||||
['metadatum_id' => $metadatum2->get_id(), 'mapper_metadata' => $new_metadatum_mapper ]
|
||||
],
|
||||
\Tainacan\Exposers\Exposers::MAPPER_PARAM => $dc->slug
|
||||
\Tainacan\Mappers_Handler::MAPPER_PARAM => $dc->slug
|
||||
]);
|
||||
$metadatum_mapper_request->set_body($metadatum_mapper_json);
|
||||
$metadatum_mapper_response = $this->server->dispatch($metadatum_mapper_request);
|
||||
|
@ -167,24 +182,111 @@ class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCas
|
|||
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
\Tainacan\Exposers\Exposers::TYPE_PARAM => 'OAI-PMH',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
$response = $this->server->dispatch($request);
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$data = $response->get_data();
|
||||
|
||||
$xml = new \SimpleXMLElement($data);
|
||||
$dc = $xml->children(\Tainacan\Exposers\Mappers\Dublin_Core::XML_DC_NAMESPACE);
|
||||
$this->assertEquals('adasdasdsaadsf', $dc->description);
|
||||
$this->assertEquals('item_teste_MetadatumMappers', $dc->title);
|
||||
$this->assertEquals('', $dc->contributor);
|
||||
$this->assertEquals('TestValues_exposersCustomMeta', $dc->TesteNewMeta);
|
||||
// $item_exposer_json = json_encode([
|
||||
// \Tainacan\Exposers_Handler::TYPE_PARAM => 'OAI-PMH',
|
||||
// ]);
|
||||
// $request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata' );
|
||||
// $request->set_body($item_exposer_json);
|
||||
// $response = $this->server->dispatch($request);
|
||||
// $this->assertEquals(200, $response->get_status());
|
||||
// $data = $response->get_data();
|
||||
//
|
||||
// $xml = new \SimpleXMLElement($data);
|
||||
// $dc = $xml->children(\Tainacan\Exposers\Mappers\Dublin_Core::XML_DC_NAMESPACE);
|
||||
// $this->assertEquals('adasdasdsaadsf', $dc->description);
|
||||
// $this->assertEquals('item_teste_MetadatumMappers', $dc->title);
|
||||
// $this->assertEquals('', $dc->contributor);
|
||||
// $this->assertEquals('TestValues_exposersCustomMeta', $dc->TesteNewMeta);
|
||||
|
||||
}
|
||||
|
||||
function test_create_new_mapped_collection() {
|
||||
|
||||
$dc = new \Tainacan\Mappers\Dublin_Core();
|
||||
|
||||
$metadatum_mapper_request = new \WP_REST_Request('POST', $this->namespace . '/collections');
|
||||
$metadatum_mapper_request->set_body(json_encode([
|
||||
\Tainacan\Mappers_Handler::MAPPER_PARAM => $dc->slug,
|
||||
'name' => 'Test Collection'
|
||||
]));
|
||||
$metadatum_mapper_response = $this->server->dispatch($metadatum_mapper_request);
|
||||
$this->assertEquals(201, $metadatum_mapper_response->get_status());
|
||||
$data = $metadatum_mapper_response->get_data();
|
||||
|
||||
$collection = \Tainacan\Repositories\Collections::get_instance()->fetch( $data['id'] );
|
||||
|
||||
$mapper_meta = $dc->metadata;
|
||||
|
||||
$metadata = $collection->get_metadata();
|
||||
|
||||
$this->assertEquals(sizeof($metadata), sizeof($mapper_meta));
|
||||
|
||||
foreach ($metadata as $meta) {
|
||||
|
||||
$map = $meta->get_exposer_mapping();
|
||||
|
||||
if (isset($map[$dc->slug]) && isset($mapper_meta[$map[$dc->slug]])) {
|
||||
unset($mapper_meta[$map[$dc->slug]]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->assertEmpty($mapper_meta);
|
||||
|
||||
}
|
||||
|
||||
function test_api_get_items_from_mapped_collection() {
|
||||
|
||||
$this->create_meta_requirements();
|
||||
|
||||
$dc = new \Tainacan\Mappers\Dublin_Core();
|
||||
|
||||
$itemMeta1 = $this->tainacan_item_metadata_factory->create_item_metadata(
|
||||
$this->item,
|
||||
$this->metadatum,
|
||||
'Value for meta 1');
|
||||
|
||||
$itemMeta2 = $this->tainacan_item_metadata_factory->create_item_metadata(
|
||||
$this->item,
|
||||
$this->metadatum2,
|
||||
'Value for meta 2');
|
||||
|
||||
$itemMeta3 = $this->tainacan_item_metadata_factory->create_item_metadata(
|
||||
$this->item,
|
||||
$this->metadatum3,
|
||||
'Value for meta 3');
|
||||
|
||||
$item_request = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $this->collection->get_id() . '/items');
|
||||
$item_request->set_body(json_encode([
|
||||
\Tainacan\Mappers_Handler::MAPPER_PARAM => $dc->slug
|
||||
]));
|
||||
$response = $this->server->dispatch($item_request);
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals(1, sizeof($data), 'Response should contain 1 item');
|
||||
|
||||
$item = $data[0];
|
||||
|
||||
$this->assertEquals(2, sizeof($item['metadata']), 'Item should contain only 2 mapped metadata');
|
||||
//var_dump($item['metadata']);
|
||||
$this->assertTrue( array_key_exists('dc:language', $item['metadata']), 'metadatum language should be present' );
|
||||
$this->assertTrue( array_key_exists('dc:creator', $item['metadata']), 'metadatum creator should be present' );
|
||||
|
||||
$this->assertEquals('Value for meta 1', $item['metadata']['dc:language']['value']);
|
||||
$this->assertEquals('Value for meta 3', $item['metadata']['dc:creator']['value']);
|
||||
|
||||
$this->assertEquals($dc->get_url('dc:language'), $item['metadata']['dc:language']['semantic_url']);
|
||||
$this->assertEquals($dc->get_url('dc:creator'), $item['metadata']['dc:creator']['semantic_url']);
|
||||
|
||||
$this->assertEquals($dc->metadata['dc:language']['label'], $item['metadata']['dc:language']['name']);
|
||||
$this->assertEquals($dc->metadata['dc:creator']['label'], $item['metadata']['dc:creator']['name']);
|
||||
|
||||
$this->assertEquals('dc:language', $item['metadata']['dc:language']['slug']);
|
||||
$this->assertEquals('dc:creator', $item['metadata']['dc:creator']['slug']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue