Merge branch 'develop' of https://github.com/tainacan/tainacan into develop
This commit is contained in:
commit
69d4409c04
|
@ -21,4 +21,5 @@ src/assets/css/tainacan-admin.css
|
|||
src/assets/css/tainacan-admin.css.map
|
||||
cypress/videos
|
||||
cypress/screenshots
|
||||
.vscode
|
||||
.vscode
|
||||
src/pdf-viewer/pdfjs-dist
|
9
build.sh
9
build.sh
|
@ -51,6 +51,15 @@ then
|
|||
fi
|
||||
### END npm build ###
|
||||
|
||||
## Fetch PDF.js
|
||||
if [ ! -d "src/pdf-viewer/pdfjs-dist" ]; then
|
||||
echo "Fething PDF.js"
|
||||
mkdir -p src/pdf-viewer/pdfjs-dist
|
||||
wget https://github.com/mozilla/pdf.js/releases/download/v1.9.426/pdfjs-1.9.426-dist.zip
|
||||
unzip pdfjs-1.9.426-dist.zip -d src/pdf-viewer/pdfjs-dist/
|
||||
rm pdfjs-1.9.426-dist.zip
|
||||
fi
|
||||
|
||||
|
||||
echo "Updating files in $wp_plugin_dir"
|
||||
rm -rf $wp_plugin_dir
|
||||
|
|
|
@ -149,7 +149,6 @@ export default {
|
|||
}
|
||||
},
|
||||
created() {
|
||||
this.$console.log(this.collectionId);
|
||||
this.finalCollectionId = (this.collectionId != undefined && this.collectionId != null && this.collectionId != '' ) ? this.collectionId : this.$route.params.collectionId;
|
||||
this.isRepositoryLevel = (this.finalCollectionId == undefined);
|
||||
|
||||
|
|
|
@ -259,10 +259,11 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
|
|||
|
||||
// If is a multidimensional array (array of array)
|
||||
if($this->contains_array($request_meta_query, $query)) {
|
||||
|
||||
foreach ( $request_meta_query as $index1 => $a ) {
|
||||
|
||||
// handle core field
|
||||
if( array_key_exists("key", $a) ){
|
||||
if( is_array($a) && array_key_exists("key", $a) ){
|
||||
$field = new Tainacan\Entities\Field($a['key']);
|
||||
if( strpos( $field->get_field_type(), 'Core_Title') !== false ){
|
||||
$args[ 'post_title_in' ] = [
|
||||
|
@ -284,7 +285,9 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
|
|||
$args[ $mapped_v ][ $index1 ][ $meta_v ] = $request[ $mapped ][ $index1 ][ $meta_v ];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
foreach ( $query as $mapped_meta => $meta_v ) {
|
||||
if(isset($request[$mapped][$meta_v])) {
|
||||
|
|
|
@ -123,7 +123,7 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
$prepared_item[$index-1]['field']['field_type_object'] = $this->prepare_item_for_response( $item_metadata->get_field()->get_field_type_object(), $request);
|
||||
}
|
||||
|
||||
return new WP_REST_Response($prepared_item, 200);
|
||||
return new WP_REST_Response(apply_filters('tainacan-rest-response', $prepared_item, $request), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,7 +149,7 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
return new WP_REST_Response($prepared_item, 200);
|
||||
return new WP_REST_Response(apply_filters('tainacan-rest-response', $prepared_item, $request), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -150,7 +150,7 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
|
|||
|
||||
$response = $this->prepare_item_for_response($item, $request);
|
||||
|
||||
return new WP_REST_Response($response, 200);
|
||||
return new WP_REST_Response(apply_filters('tainacan-rest-response', $response, $request), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
namespace Tainacan;
|
||||
|
||||
class Embed {
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
public static function get_instance() {
|
||||
if(!isset(self::$instance)) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
protected function __construct() {
|
||||
|
||||
/**
|
||||
* Replace default WordPress embedders with HTML 5 tags instead of shortcodes
|
||||
*/
|
||||
add_filter('wp_embed_handler_video', [&$this, 'filter_video_embed'], 10, 4);
|
||||
add_filter('wp_embed_handler_audio', [&$this, 'filter_audio_embed'], 10, 4);
|
||||
|
||||
/**
|
||||
* ADD PDF Embed handler using PDF.js
|
||||
* @var [type]
|
||||
*/
|
||||
wp_embed_register_handler( 'pdf', '#^https?://.+?\.(pdf)$#i', [&$this, 'pdf_embed_handler'] );
|
||||
|
||||
}
|
||||
|
||||
public function filter_video_embed($video, $attr, $url, $rawattr) {
|
||||
|
||||
|
||||
$dimensions = '';
|
||||
if ( ! empty( $attr['width'] ) && ! empty( $attr['height'] ) ) {
|
||||
$dimensions .= sprintf( 'width="%d" ', (int) $attr['width'] );
|
||||
//$dimensions .= sprintf( 'height="%d" ', (int) $attr['height'] );
|
||||
}
|
||||
$video = sprintf( '<video controls="" %s src="%s"></video>', $dimensions, esc_url( $url ) );
|
||||
|
||||
return $video;
|
||||
|
||||
}
|
||||
|
||||
public function filter_audio_embed($audio, $attr, $url, $rawattr) {
|
||||
|
||||
|
||||
if ( ! empty( $attr['width'] ) ) {
|
||||
$dimensions = sprintf( 'width="%d" ', (int) $attr['width'] );
|
||||
}
|
||||
|
||||
$audio = sprintf('<audio controls="" src="%s" %s></audio>', $url, $dimensions);
|
||||
|
||||
return $audio;
|
||||
|
||||
}
|
||||
|
||||
public function pdf_embed_handler($matches, $attr, $url, $rawattr) {
|
||||
global $TAINACAN_BASE_URL;
|
||||
$viewer_url = $TAINACAN_BASE_URL . '/pdf-viewer/pdf-viewer.html?file=' . $url;
|
||||
//$viewer_url = $TAINACAN_BASE_URL . '/assets/pdfjs-dist/web/viewer.html?file=' . $url;
|
||||
|
||||
$defaults = array(
|
||||
'width' => 800,
|
||||
'height' => 1000
|
||||
);
|
||||
|
||||
$args = array_merge($defaults, $attr);
|
||||
|
||||
$dimensions = '';
|
||||
if ( ! empty( $args['width'] ) && ! empty( $args['height'] ) ) {
|
||||
$dimensions .= sprintf( "width='%d' ", (int) $args['width'] );
|
||||
$dimensions .= sprintf( "height='%d' ", (int) $args['height'] );
|
||||
}
|
||||
|
||||
$pdf = "<iframe id='iframePDF' name='iframePDF' src='$viewer_url' $dimensions allowfullscreen webkitallowfullscreen></iframe>";
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
}
|
|
@ -169,6 +169,21 @@ class Field extends Entity {
|
|||
return $this->get_mapped_property('field_type_options');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this field allow community suggestions, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
function get_accept_suggestion() {
|
||||
return $this->get_mapped_property('accept_suggestion');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of exposer mapping configurations
|
||||
* @return array
|
||||
*/
|
||||
public function get_exposer_mapping() {
|
||||
return $this->get_mapped_property('exposer_mapping');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field name
|
||||
|
@ -180,14 +195,6 @@ class Field extends Entity {
|
|||
$this->set_mapped_property('name', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this field allow community suggestions, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
function get_accept_suggestion() {
|
||||
return $this->get_mapped_property('accept_suggestion');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field slug
|
||||
*
|
||||
|
@ -320,6 +327,14 @@ class Field extends Entity {
|
|||
function set_field_type_options( $value ){
|
||||
$this->set_mapped_property('field_type_options', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set exposers mapping configuration for this field
|
||||
* @param array $value
|
||||
*/
|
||||
public function set_exposer_mapping( $value ) {
|
||||
$this->set_mapped_property('exposer_mapping', $value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -494,4 +494,49 @@ class Item extends Entity {
|
|||
|
||||
}
|
||||
|
||||
public function get_document_html($img_size = 'large') {
|
||||
|
||||
$type = $this->get_document_type();
|
||||
|
||||
$output = '';
|
||||
|
||||
if ( $type == 'url' ) {
|
||||
$output .= apply_filters('the_content', $this->get_document());
|
||||
} elseif ( $type == 'text' ) {
|
||||
$output .= $this->get_document();
|
||||
} elseif ( $type == 'attachment' ) {
|
||||
|
||||
if ( wp_attachment_is_image($this->get_document()) ) {
|
||||
|
||||
$img = wp_get_attachment_image($this->get_document(), $img_size);
|
||||
$img_full = wp_get_attachment_image($this->get_document(), 'full');
|
||||
|
||||
$output .= sprintf("<a href='%s' target='blank'>%s</a>", $url, $img);
|
||||
|
||||
} else {
|
||||
|
||||
global $wp_embed;
|
||||
|
||||
$url = wp_get_attachment_url($this->get_document());
|
||||
|
||||
$embed = $wp_embed->autoembed($url);
|
||||
|
||||
if ( $embed == $url ) {
|
||||
|
||||
// No embed handler found
|
||||
// TODO: Add filter to allow customization
|
||||
$output .= sprintf("<a href='%s' target='blank'>%s</a>", $url, $url);
|
||||
} else {
|
||||
$output .= $embed;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -22,7 +22,7 @@
|
|||
if( this.field.value ){
|
||||
let query = qs.stringify({ postin: ( Array.isArray( this.field.value ) ) ? this.field.value : [ this.field.value ] });
|
||||
|
||||
axios.get('/collection/'+collectionId+'/items?' + query)
|
||||
axios.get('/collection/'+collectionId+'/items?' + query + '?nopaging=1')
|
||||
.then( res => {
|
||||
for (let item of res.data) {
|
||||
this.selected.push({ label: item.title, value: item.id, img: '' });
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
|
||||
this.field = ( this.field_id ) ? this.field_id : this.filter.field.field_id;
|
||||
const vm = this;
|
||||
axios.get('/collection/' + this.collection + '/fields/' + this.field )
|
||||
axios.get('/collection/' + this.collection + '/fields/' + this.field + '?nopaging=1')
|
||||
.then( res => {
|
||||
let result = res.data;
|
||||
if( result && result.field_type ){
|
||||
|
|
|
@ -30,13 +30,13 @@ export const filter_type_mixin = {
|
|||
});
|
||||
},
|
||||
getValuesRelationship(collectionTarget, search) {
|
||||
let url = '/collection/' + collectionTarget + '/items';
|
||||
let url = '/collection/' + collectionTarget + '/items?';
|
||||
|
||||
if( search ){
|
||||
url += "?search=" + search;
|
||||
url += "search=" + search;
|
||||
}
|
||||
|
||||
return axios.get( url )
|
||||
return axios.get( url + '&nopaging=1')
|
||||
.then(res => {
|
||||
if (res.data.length > 0) {
|
||||
for (let item of res.data) {
|
||||
|
|
|
@ -156,12 +156,21 @@ class Fields extends Repository {
|
|||
//'validation' => ''
|
||||
],
|
||||
'accept_suggestion' => [
|
||||
'map' => 'meta',
|
||||
'title' => __('Field Value Accepts Suggestions', 'tainacan'),
|
||||
'type' => 'bool',
|
||||
'description'=> __('Allow the community suggest a different values for that field', 'tainacan'),
|
||||
'default' => false,
|
||||
'validation' => v::boolType()
|
||||
'map' => 'meta',
|
||||
'title' => __('Field Value Accepts Suggestions', 'tainacan'),
|
||||
'type' => 'bool',
|
||||
'description'=> __('Allow the community suggest a different values for that field', 'tainacan'),
|
||||
'default' => false,
|
||||
'validation' => v::boolType()
|
||||
],
|
||||
'exposer_mapping' => [
|
||||
'map' => 'meta',
|
||||
'title' => __('exposer_mapping', 'tainacan'),
|
||||
'type' => 'array',
|
||||
'description'=> __('The field mapping options', 'tainacan'),
|
||||
'on_error' => __('Invalid Field Mapping', 'tainacan'),
|
||||
'validation' => v::arrayType(),
|
||||
'default' => []
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
@ -490,14 +499,28 @@ class Fields extends Repository {
|
|||
'description' => 'description',
|
||||
'collection_id' => $collection->get_id(),
|
||||
'field_type' => 'Tainacan\Field_Types\Core_Description',
|
||||
'status' => 'publish'
|
||||
'status' => 'publish',
|
||||
'exposer_mapping' => [
|
||||
'dublin-core' => [
|
||||
'name' => 'description',
|
||||
'label' => __('Description', 'tainacan'),
|
||||
'URI' => 'http://purl.org/dc/terms/description',
|
||||
]
|
||||
]
|
||||
],
|
||||
'core_title' => [
|
||||
'name' => 'Title',
|
||||
'description' => 'title',
|
||||
'collection_id' => $collection->get_id(),
|
||||
'field_type' => 'Tainacan\Field_Types\Core_Title',
|
||||
'status' => 'publish'
|
||||
'status' => 'publish',
|
||||
'exposer_mapping' => [
|
||||
'dublin-core' => [
|
||||
'name' => 'title',
|
||||
'label' => __('Title', 'tainacan'),
|
||||
'URI' => 'http://purl.org/dc/terms/title',
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Tainacan\Repositories;
|
|||
|
||||
use Tainacan\Entities;
|
||||
use \Respect\Validation\Validator as v;
|
||||
use Tainacan\Entities\Item;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
|
@ -250,7 +251,7 @@ class Items extends Repository {
|
|||
* @param array $collections Array Entities\Collection || Array int collections IDs || int collection id || Entities\Collection collection object
|
||||
* @param string $output The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
|
||||
*
|
||||
* @return \WP_Query|Array an instance of wp query OR array of entities;
|
||||
* @return \WP_Query|Array|Item an instance of wp query OR array of entities OR a Item;
|
||||
*/
|
||||
public function fetch( $args = [], $collections = [], $output = null ) {
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ const TAPI_DIR = __DIR__ . '/../api/';
|
|||
const ENDPOINTS_DIR = __DIR__ . '/../api/endpoints/';
|
||||
const HELPERS_DIR = __DIR__ . '/../helpers/';
|
||||
const IMPORTER_DIR = __DIR__ . '/../importer/';
|
||||
const EXPOSERS_DIR = __DIR__ . '/../exposers/';
|
||||
|
||||
const DIRS = [
|
||||
CLASSES_DIR,
|
||||
|
@ -20,12 +21,14 @@ const DIRS = [
|
|||
TRAITS_DIR,
|
||||
TAPI_DIR,
|
||||
ENDPOINTS_DIR,
|
||||
IMPORTER_DIR
|
||||
IMPORTER_DIR,
|
||||
EXPOSERS_DIR
|
||||
];
|
||||
|
||||
require_once(VENDOR_DIR . 'autoload.php');
|
||||
require_once(HELPERS_DIR . 'class-tainacan-helpers-html.php');
|
||||
require_once(IMPORTER_DIR . 'class-tainacan-importer.php');
|
||||
require_once(EXPOSERS_DIR . 'class-tainacan-exposers.php');
|
||||
|
||||
spl_autoload_register('tainacan_autoload');
|
||||
|
||||
|
@ -47,11 +50,14 @@ function tainacan_autoload($class_name){
|
|||
|
||||
if( isset( $class_path[1] ) && $class_path[1] === 'Importer' ){
|
||||
$dir = IMPORTER_DIR;
|
||||
} else if($sliced) {
|
||||
} else if( isset( $class_path[1] ) && $class_path[1] === 'Exposers' ){
|
||||
$dir = EXPOSERS_DIR;
|
||||
if(count($class_path) > 3) $dir .= strtolower($class_path[2]).DIRECTORY_SEPARATOR;
|
||||
} else if($sliced) {
|
||||
$lower = $sliced[0];
|
||||
$sliced[0] = strtolower( $lower );
|
||||
|
||||
$dir = implode( DIRECTORY_SEPARATOR, $sliced ) . '/';
|
||||
$dir = implode( DIRECTORY_SEPARATOR, $sliced ) . DIRECTORY_SEPARATOR;
|
||||
$dir = CLASSES_DIR . str_replace( '_', '-', $dir );
|
||||
} else {
|
||||
$dir = CLASSES_DIR;
|
||||
|
@ -110,4 +116,8 @@ $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
|
|||
|
||||
$Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
|
||||
|
||||
?>
|
||||
$Tainacan_Exposers = \Tainacan\Exposers\Exposers::get_instance();
|
||||
|
||||
$Tainacan_Embed = \Tainacan\Embed::get_instance();
|
||||
|
||||
?>
|
||||
|
|
|
@ -0,0 +1,227 @@
|
|||
<?php
|
||||
namespace Tainacan\Exposers;
|
||||
|
||||
use Tainacan\Exposers\Mappers\Mapper;
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
||||
/**
|
||||
* Load exposers classes
|
||||
*/
|
||||
class Exposers {
|
||||
|
||||
private $types = [];
|
||||
private $mappers = [];
|
||||
private static $instance = null;
|
||||
const MAPPER_CLASS_PREFIX = 'Tainacan\Exposers\Mappers\\';
|
||||
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
$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');
|
||||
do_action('tainacan-register-exposer-types');
|
||||
$this->register_exposer_mapper('Tainacan\Exposers\Mappers\Dublin_Core');
|
||||
$this->register_exposer_mapper('Tainacan\Exposers\Mappers\Value');
|
||||
do_action('tainacan-register-exposer-mappers');
|
||||
|
||||
|
||||
add_filter( 'rest_request_after_callbacks', [$this, 'rest_request_after_callbacks'], 10, 3 ); //exposer mapping
|
||||
add_filter( 'tainacan-rest-response', [$this, 'rest_response'], 10, 2 ); // exposer types
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ){
|
||||
if( is_object( $class_name ) ){
|
||||
$class_name = get_class( $class_name );
|
||||
}
|
||||
|
||||
if(!in_array( $class_name, $this->types)){
|
||||
$this->types[] = $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 ){
|
||||
if( is_object( $class_name ) ){
|
||||
$class_name = get_class( $class_name );
|
||||
}
|
||||
|
||||
if(!in_array( $class_name, $this->mappers)){
|
||||
$this->mappers[] = $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\\') {
|
||||
$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' && substr($request->get_route(), 0, strlen('/tainacan/v2')) == '/tainacan/v2') {
|
||||
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_fields();
|
||||
$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 field
|
||||
* @param array $item_arr
|
||||
* @param Mappers\Mapper $mapper
|
||||
* @return array
|
||||
*/
|
||||
protected function map_field($item_arr, $mapper) {
|
||||
$ret = $item_arr;
|
||||
$field_mapping = $item_arr['field']['exposer_mapping'];
|
||||
if(array_key_exists($mapper->slug, $field_mapping)) {
|
||||
$ret = [$mapper->prefix.$field_mapping[$mapper->slug]['name'].$mapper->sufix => $item_arr['value']];
|
||||
} else if($mapper->slug == 'value') {
|
||||
$ret = [$item_arr['field']['name'] => $item_arr['value']];
|
||||
}
|
||||
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('field', $item_arr)){ // getting a unique field
|
||||
$ret = $this->map_field($item_arr, $mapper);
|
||||
} else { // array of elements
|
||||
$ret = [];
|
||||
foreach ($item_arr as $item) {
|
||||
$ret = array_merge($ret, $this->map($item, $mapper, $resquest) );
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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($request->get_method() == 'GET' && substr($request->get_route(), 0, strlen('/tainacan/v2')) == '/tainacan/v2') {
|
||||
if($exposer = $this->request_has_type($request)) {
|
||||
return $exposer->rest_request_after_callbacks($response, $handler, $request);
|
||||
}
|
||||
}
|
||||
// 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 with 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 );
|
||||
$Tainacan_Exposers = self::get_instance();
|
||||
if(
|
||||
is_array($body) && array_key_exists('exposer-type', $body) &&
|
||||
$Tainacan_Exposers->has_type($body['exposer-type'])
|
||||
) {
|
||||
$type = $Tainacan_Exposers->check_class_name($body['exposer-type'], 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();
|
||||
|
||||
$type = self::request_has_type($request);
|
||||
if( // There are a defined mapper
|
||||
is_array($body) && array_key_exists('exposer-map', $body) &&
|
||||
$Tainacan_Exposers->has_mapper($body['exposer-map'])
|
||||
) {
|
||||
if(
|
||||
$type === false || // do not have a exposer type
|
||||
$type->mappers === true || // the type accept all mappers
|
||||
( is_array($type->mappers) && in_array($body['exposer-map'], $type->mappers) ) ) { // the current mapper is accepted by type
|
||||
$mapper = $Tainacan_Exposers->check_class_name($body['exposer-map'], true, self::MAPPER_CLASS_PREFIX);
|
||||
return new $mapper;
|
||||
}
|
||||
} elseif( is_object($type) && is_array($type->mappers) && count($type->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->mappers[0], true, self::MAPPER_CLASS_PREFIX);
|
||||
return new $mapper;
|
||||
}
|
||||
return false; // No mapper need, using Tainacan defautls
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Mappers;
|
||||
|
||||
class Dublin_Core extends Mapper {
|
||||
public $slug = 'dublin-core';
|
||||
public $name = 'Dublin Core';
|
||||
public $allow_extra_fields = 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 $options = [];
|
||||
|
||||
/** XML especial case **/
|
||||
const XML_DC_NAMESPACE = 'http://purl.org/dc/elements/1.1/';
|
||||
const XML_RDF_NAMESPACE = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
|
||||
public $XML_namespace = 'http://purl.org/dc/elements/1.1/';
|
||||
public $XML_append_root = 'rdf:Description';
|
||||
/** END: XML especial case **/
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Mappers;
|
||||
|
||||
abstract class Mapper {
|
||||
public $slug = null;
|
||||
public $name = null;
|
||||
public $allow_extra_fields = true;
|
||||
public $context_url = null;
|
||||
public $opstions = false;
|
||||
public $prefix = '';
|
||||
public $sufix = '';
|
||||
public $header = false;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Mappers;
|
||||
|
||||
class Value extends Mapper {
|
||||
public $slug = 'value';
|
||||
public $name = 'Value';
|
||||
public $allow_extra_fields = true;
|
||||
public $context_url = '';
|
||||
public $header = '';
|
||||
public $options = [];
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Types;
|
||||
|
||||
class Csv extends Type {
|
||||
|
||||
public $mappers = ['Value'];
|
||||
|
||||
/**
|
||||
*
|
||||
* {@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 Txt
|
||||
* @param array $data
|
||||
* @param string $csv
|
||||
* @return string
|
||||
*/
|
||||
protected function array_to_csv( $data, $csv ) {
|
||||
$values = [];
|
||||
fputcsv($csv, array_keys($data), apply_filters('tainacan-exposer-csv-delimiter', ';') );
|
||||
fputcsv($csv, array_values($data), apply_filters('tainacan-exposer-csv-delimiter', ';') );
|
||||
return $csv;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Types;
|
||||
|
||||
class Html extends Type {
|
||||
|
||||
public $mappers = ['Value'];
|
||||
|
||||
/**
|
||||
*
|
||||
* {@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/html; charset=' . get_option( 'blog_charset' )] );
|
||||
$html = '
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<table>
|
||||
';
|
||||
$html .= $this->array_to_html($response->get_data());
|
||||
$html .= '
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
';
|
||||
|
||||
$html = apply_filters('tainacan-exposer-html', $html);
|
||||
|
||||
$response->set_data($html);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Array to Html
|
||||
* @param array $data
|
||||
* @param string $html
|
||||
* @return string
|
||||
*/
|
||||
protected function array_to_html( $data ) {
|
||||
$heads = [];
|
||||
$html = '';
|
||||
foreach( $data as $key => $value ) {
|
||||
if( is_numeric($key) ){
|
||||
$key = apply_filters('tainacan-exposer-numeric-item-prefix', __('item', 'tainacan').'-', get_class($this)).$key; //dealing with <0/>..<n/> issues
|
||||
}
|
||||
$heads[] = $key;
|
||||
if( is_array($value) ) {
|
||||
$html .= '<td>'.$this->array_to_html($value).'</td>';
|
||||
} else {
|
||||
$html .= '<td>'.htmlspecialchars($value).'</td>';
|
||||
}
|
||||
}
|
||||
if(count($data > 0)) $html = '<th>'.implode('</th><th>', $heads).'</th><tr>'.$html.'</tr>';
|
||||
return $html;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Types;
|
||||
|
||||
class OAI_PMH extends Xml {
|
||||
|
||||
public $mappers = ['Dublin Core'];
|
||||
|
||||
const XML_OAI_DC_NAMESPACE = "http://www.openarchives.org/OAI/2.0/oai_dc/";
|
||||
/**
|
||||
*
|
||||
* {@inheritDoc}
|
||||
* @see \Tainacan\Exposers\Types\Type::rest_request_after_callbacks()
|
||||
*/
|
||||
public function rest_request_after_callbacks( $response, $handler, $request ) {
|
||||
$response->set_headers( ['Content-Type: application/xml; charset=' . get_option( 'blog_charset' )] );
|
||||
$xml = new \SimpleXMLElement(apply_filters('tainacan-exposer-head', '<?xml version="1.0" encoding="UTF-8"?>
|
||||
<oai_dc:dc
|
||||
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/
|
||||
http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
|
||||
</oai_dc:dc>'
|
||||
));
|
||||
$namespace = apply_filters('tainacan-oai-pmh-namespace', \Tainacan\Exposers\Mappers\Dublin_Core::XML_DC_NAMESPACE);
|
||||
$this->array_to_xml($response->get_data(), apply_filters('tainacan-oai-pmh-root', $xml), $namespace);
|
||||
$response->set_data($xml->asXml());
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Types;
|
||||
|
||||
class Txt extends Type {
|
||||
|
||||
public $mappers = ['Value'];
|
||||
|
||||
/**
|
||||
*
|
||||
* {@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/plain; charset=' . get_option( 'blog_charset' )] );
|
||||
$txt = '';
|
||||
$txt = $this->array_to_txt($response->get_data(), apply_filters('tainacan-exposer-txt', $txt));
|
||||
$response->set_data($txt);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Array to Txt
|
||||
* @param array $data
|
||||
* @param string $txt
|
||||
* @return string
|
||||
*/
|
||||
protected function array_to_txt( $data, $txt ) {
|
||||
foreach( $data as $key => $value ) {
|
||||
if( is_numeric($key) ){
|
||||
$key = apply_filters('tainacan-exposer-numeric-item-prefix', __('item', 'tainacan').'-', get_class($this)).$key; //dealing with <0/>..<n/> issues
|
||||
}
|
||||
if( is_array($value) ) {
|
||||
$txt .= $key.": ".$this->array_to_txt($value, '['.$txt.']\n');
|
||||
} else {
|
||||
$txt .= $key.": ".$value .'\n';
|
||||
}
|
||||
}
|
||||
return $txt;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Types;
|
||||
|
||||
abstract class Type {
|
||||
|
||||
public $mappers = true; // List of supported mapper, leave true for all
|
||||
|
||||
/**
|
||||
* @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 );
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Types;
|
||||
|
||||
class Xml extends Type {
|
||||
/**
|
||||
*
|
||||
* {@inheritDoc}
|
||||
* @see \Tainacan\Exposers\Types\Type::rest_request_after_callbacks()
|
||||
*/
|
||||
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);
|
||||
$xml = new \SimpleXMLElement( '<?xml version="1.0"?><data></data>' );
|
||||
$namespace = null;
|
||||
$xml_root = $xml;
|
||||
|
||||
if($mapper) {
|
||||
if(!empty($mapper->header)) {
|
||||
$xml = new \SimpleXMLElement( $mapper->header );
|
||||
}
|
||||
if(property_exists($mapper, 'XML_namespace') && !empty($mapper->XML_namespace)) {
|
||||
$namespace = $mapper->XML_namespace;
|
||||
}
|
||||
if(property_exists($mapper, 'XML_append_root') && !empty($mapper->XML_append_root)) {
|
||||
$xml_root = $xml->addChild($mapper->XML_append_root);
|
||||
}
|
||||
}
|
||||
|
||||
$this->array_to_xml($response->get_data(), $xml_root, $namespace);
|
||||
$response->set_data($xml->asXml());
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Array to Xml
|
||||
* @param array $data
|
||||
* @param \SimpleXMLElement $xml_data
|
||||
* @return \SimpleXMLElement
|
||||
*/
|
||||
protected function array_to_xml( $data, $xml_data, $namespace = null ) {
|
||||
foreach( $data as $key => $value ) {
|
||||
if( is_numeric($key) ){
|
||||
$key = apply_filters('tainacan-exposer-numeric-item-prefix', __('item', 'tainacan').'-', get_class($this)).$key; //dealing with <0/>..<n/> issues
|
||||
}
|
||||
if( is_array($value) ) {
|
||||
$subnode = $xml_data->addChild($key, null, $namespace);
|
||||
$this->array_to_xml($value, $subnode, $namespace);
|
||||
} else {
|
||||
$xml_data->addChild($key,htmlspecialchars("$value"), $namespace);
|
||||
}
|
||||
}
|
||||
return $xml_data;
|
||||
}
|
||||
}
|
|
@ -20,6 +20,58 @@ class Old_Tainacan extends Importer
|
|||
$this->import_structure_and_mapping = $import_structure_and_mapping;
|
||||
}
|
||||
|
||||
public function fetch_from_remote( $url ){
|
||||
$url_json = explode('/colecao/', $url)[0] . "/wp-json/tainacan/v1/collections";
|
||||
$all_collections_info = wp_remote_get($url_json);
|
||||
|
||||
if(isset($all_collections_info['body']))
|
||||
{
|
||||
$all_collections_array = json_decode($all_collections_info['body']);
|
||||
|
||||
$collection_name = explode('/', $url);
|
||||
$collection_name = array_filter($collection_name, function($item){
|
||||
if(empty($item)) return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
$collection_name = end($collection_name);
|
||||
|
||||
foreach($all_collections_array as $collection)
|
||||
{
|
||||
if(strcmp($collection->post_name, $collection_name) === 0)
|
||||
{
|
||||
$link = $collection->link[0]->href;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!empty($link))
|
||||
{
|
||||
$items = wp_remote_get( $link."/items/?includeMetadata=1" );
|
||||
|
||||
if(isset($items['body']))
|
||||
{
|
||||
$items_array = json_decode($items['body']);
|
||||
|
||||
//Get Metatype
|
||||
$meta_type = wp_remote_get($link."/metadata");
|
||||
if(isset($meta_type['body']))
|
||||
{
|
||||
$meta_type_array = json_decode($meta_type['body']);
|
||||
$file_info['items'] = $items_array;
|
||||
$file_info['meta'] = $meta_type_array;
|
||||
|
||||
$file = fopen( $this->get_id().'.txt', 'w' );
|
||||
fwrite( $file, serialize($file_info) );
|
||||
fclose( $file );
|
||||
return $this->set_file( $this->get_id().'.txt' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the fields of file/url to allow mapping
|
||||
* should return an array
|
||||
|
@ -29,10 +81,18 @@ class Old_Tainacan extends Importer
|
|||
public function get_fields()
|
||||
{
|
||||
$file = new \SplFileObject( $this->tmp_file, 'r' );
|
||||
$json = json_decode($file->fread($file->getSize()), true);
|
||||
$file_content = unserialize($file->fread($file->getSize()));
|
||||
|
||||
$item = $json['items'][0]['item'];
|
||||
return array_keys($item);
|
||||
|
||||
foreach($file_content['meta'] as $tab)
|
||||
{
|
||||
foreach($tab->{"tab-properties"} as $meta)
|
||||
{
|
||||
$fields[] = ['name' => $meta->name, 'type' => $meta->type];
|
||||
}
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,16 +111,17 @@ class Old_Tainacan extends Importer
|
|||
|
||||
// search the index in the file and get values
|
||||
$file = new \SplFileObject( $this->tmp_file, 'r' );
|
||||
$json = json_decode($file->fread($file->getSize()), true);
|
||||
$file_content = unserialize($file->fread($file->getSize()));
|
||||
|
||||
$values = $json['items'][$index]['item'];
|
||||
/*to fix this*/
|
||||
$values = $file_content['items']->items[$index]->item;
|
||||
|
||||
if( count( $headers ) !== count( $values ) ){
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($headers as $header) {
|
||||
$processedItem[ $header ] = $values[ $header ];
|
||||
$processedItem[ $header['name'] ] = $values[ $header['name'] ];
|
||||
}
|
||||
|
||||
return $processedItem;
|
||||
|
@ -68,12 +129,10 @@ class Old_Tainacan extends Importer
|
|||
|
||||
function create_fields_and_mapping() {
|
||||
|
||||
$file = new \SplFileObject( $this->tmp_file, 'r' );
|
||||
$json = json_decode($file->fread($file->getSize()), true);
|
||||
$item = $json['items'][0]['item'];
|
||||
$fields_repository = \Tainacan\Repositories\Fields::get_instance();
|
||||
|
||||
$avoid = [
|
||||
$file_fields = $this->get_fields();
|
||||
/*$avoid = [
|
||||
'ID',
|
||||
'post_author',
|
||||
'post_date',
|
||||
|
@ -94,29 +153,27 @@ class Old_Tainacan extends Importer
|
|||
'filter',
|
||||
'link',
|
||||
'thumbnail'
|
||||
];
|
||||
];*/
|
||||
|
||||
foreach($item as $field_name => $value)
|
||||
foreach($file_fields as $index => $meta_info)
|
||||
{
|
||||
if(!in_array($field_name, $avoid))
|
||||
{
|
||||
$newField = new \Tainacan\Entities\Field();
|
||||
$newField = new \Tainacan\Entities\Field();
|
||||
|
||||
$newField->set_name($field_name);
|
||||
$newField->set_field_type('Tainacan\Field_Types\Text');
|
||||
$newField->set_name($meta_info['name']);
|
||||
|
||||
$newField->set_collection($this->collection);
|
||||
$newField->validate(); // there is no user input here, so we can be sure it will validate.
|
||||
$type = 'Text';
|
||||
|
||||
$newField = $fields_repository->insert($newField);
|
||||
$newField->set_field_type('Tainacan\Field_Types\\'.$type);
|
||||
|
||||
$source_fields = $this->get_fields();
|
||||
$newField->set_collection($this->collection);
|
||||
$newField->validate(); // there is no user input here, so we can be sure it will validate.
|
||||
|
||||
$source_id = array_search($field_name, $source_fields);
|
||||
$this->set_mapping([
|
||||
$newField->get_id() => $source_fields[$source_id]
|
||||
]);
|
||||
}
|
||||
$newField = $fields_repository->insert($newField);
|
||||
|
||||
|
||||
$this->set_mapping([
|
||||
$newField->get_id() => $file_fields[$index]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,8 +185,8 @@ class Old_Tainacan extends Importer
|
|||
public function get_total_items_from_source()
|
||||
{
|
||||
$file = new \SplFileObject( $this->tmp_file, 'r' );
|
||||
$json = json_decode($file->fread($file->getSize()), true);
|
||||
$file_content = unserialize($file->fread($file->getSize()));
|
||||
|
||||
return $this->total_items = $json['found_items'];
|
||||
return $this->total_items = $file_content['items']->found_items;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,359 @@
|
|||
<!DOCTYPE html>
|
||||
<!--
|
||||
Copyright 2012 Mozilla Foundation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Adobe CMap resources are covered by their own copyright but the same license:
|
||||
|
||||
Copyright 1990-2015 Adobe Systems Incorporated.
|
||||
|
||||
See https://github.com/adobe-type-tools/cmap-resources
|
||||
-->
|
||||
<html dir="ltr" mozdisallowselectionprint moznomarginboxes>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<meta name="google" content="notranslate">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>PDF.js viewer</title>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="pdfjs-dist/web/viewer.css">
|
||||
|
||||
|
||||
|
||||
<!-- This snippet is used in production (included from viewer.html) -->
|
||||
<link rel="resource" type="application/l10n" href="pdfjs-dist/web/locale/locale.properties">
|
||||
<script src="pdfjs-dist/build/pdf.js"></script>
|
||||
|
||||
|
||||
<script src="pdf-viewer.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body tabindex="1" class="loadingInProgress">
|
||||
<div id="outerContainer">
|
||||
|
||||
<div id="sidebarContainer">
|
||||
<div id="toolbarSidebar">
|
||||
<div class="splitToolbarButton toggled">
|
||||
<button id="viewThumbnail" class="toolbarButton toggled" title="Show Thumbnails" tabindex="2" data-l10n-id="thumbs">
|
||||
<span data-l10n-id="thumbs_label">Thumbnails</span>
|
||||
</button>
|
||||
<button id="viewOutline" class="toolbarButton" title="Show Document Outline (double-click to expand/collapse all items)" tabindex="3" data-l10n-id="document_outline">
|
||||
<span data-l10n-id="document_outline_label">Document Outline</span>
|
||||
</button>
|
||||
<button id="viewAttachments" class="toolbarButton" title="Show Attachments" tabindex="4" data-l10n-id="attachments">
|
||||
<span data-l10n-id="attachments_label">Attachments</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="sidebarContent">
|
||||
<div id="thumbnailView">
|
||||
</div>
|
||||
<div id="outlineView" class="hidden">
|
||||
</div>
|
||||
<div id="attachmentsView" class="hidden">
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- sidebarContainer -->
|
||||
|
||||
<div id="mainContainer">
|
||||
<div class="findbar hidden doorHanger" id="findbar">
|
||||
<div id="findbarInputContainer">
|
||||
<input id="findInput" class="toolbarField" title="Find" placeholder="Find in document…" tabindex="91" data-l10n-id="find_input">
|
||||
<div class="splitToolbarButton">
|
||||
<button id="findPrevious" class="toolbarButton findPrevious" title="Find the previous occurrence of the phrase" tabindex="92" data-l10n-id="find_previous">
|
||||
<span data-l10n-id="find_previous_label">Previous</span>
|
||||
</button>
|
||||
<div class="splitToolbarButtonSeparator"></div>
|
||||
<button id="findNext" class="toolbarButton findNext" title="Find the next occurrence of the phrase" tabindex="93" data-l10n-id="find_next">
|
||||
<span data-l10n-id="find_next_label">Next</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="findbarOptionsContainer">
|
||||
<input type="checkbox" id="findHighlightAll" class="toolbarField" tabindex="94">
|
||||
<label for="findHighlightAll" class="toolbarLabel" data-l10n-id="find_highlight">Highlight all</label>
|
||||
<input type="checkbox" id="findMatchCase" class="toolbarField" tabindex="95">
|
||||
<label for="findMatchCase" class="toolbarLabel" data-l10n-id="find_match_case_label">Match case</label>
|
||||
<span id="findResultsCount" class="toolbarLabel hidden"></span>
|
||||
</div>
|
||||
|
||||
<div id="findbarMessageContainer">
|
||||
<span id="findMsg" class="toolbarLabel"></span>
|
||||
</div>
|
||||
</div> <!-- findbar -->
|
||||
|
||||
<div id="secondaryToolbar" class="secondaryToolbar hidden doorHangerRight">
|
||||
<div id="secondaryToolbarButtonContainer">
|
||||
<button id="secondaryPresentationMode" class="secondaryToolbarButton presentationMode visibleLargeView" title="Switch to Presentation Mode" tabindex="51" data-l10n-id="presentation_mode">
|
||||
<span data-l10n-id="presentation_mode_label">Presentation Mode</span>
|
||||
</button>
|
||||
|
||||
<button id="secondaryOpenFile" class="secondaryToolbarButton openFile visibleLargeView" title="Open File" tabindex="52" data-l10n-id="open_file">
|
||||
<span data-l10n-id="open_file_label">Open</span>
|
||||
</button>
|
||||
|
||||
<button id="secondaryPrint" class="secondaryToolbarButton print visibleMediumView" title="Print" tabindex="53" data-l10n-id="print">
|
||||
<span data-l10n-id="print_label">Print</span>
|
||||
</button>
|
||||
|
||||
<button id="secondaryDownload" class="secondaryToolbarButton download visibleMediumView" title="Download" tabindex="54" data-l10n-id="download">
|
||||
<span data-l10n-id="download_label">Download</span>
|
||||
</button>
|
||||
|
||||
<a href="#" id="secondaryViewBookmark" class="secondaryToolbarButton bookmark visibleSmallView" title="Current view (copy or open in new window)" tabindex="55" data-l10n-id="bookmark">
|
||||
<span data-l10n-id="bookmark_label">Current View</span>
|
||||
</a>
|
||||
|
||||
<div class="horizontalToolbarSeparator visibleLargeView"></div>
|
||||
|
||||
<button id="firstPage" class="secondaryToolbarButton firstPage" title="Go to First Page" tabindex="56" data-l10n-id="first_page">
|
||||
<span data-l10n-id="first_page_label">Go to First Page</span>
|
||||
</button>
|
||||
<button id="lastPage" class="secondaryToolbarButton lastPage" title="Go to Last Page" tabindex="57" data-l10n-id="last_page">
|
||||
<span data-l10n-id="last_page_label">Go to Last Page</span>
|
||||
</button>
|
||||
|
||||
<div class="horizontalToolbarSeparator"></div>
|
||||
|
||||
<button id="pageRotateCw" class="secondaryToolbarButton rotateCw" title="Rotate Clockwise" tabindex="58" data-l10n-id="page_rotate_cw">
|
||||
<span data-l10n-id="page_rotate_cw_label">Rotate Clockwise</span>
|
||||
</button>
|
||||
<button id="pageRotateCcw" class="secondaryToolbarButton rotateCcw" title="Rotate Counterclockwise" tabindex="59" data-l10n-id="page_rotate_ccw">
|
||||
<span data-l10n-id="page_rotate_ccw_label">Rotate Counterclockwise</span>
|
||||
</button>
|
||||
|
||||
<div class="horizontalToolbarSeparator"></div>
|
||||
|
||||
<button id="cursorSelectTool" class="secondaryToolbarButton selectTool toggled" title="Enable Text Selection Tool" tabindex="60" data-l10n-id="cursor_text_select_tool">
|
||||
<span data-l10n-id="cursor_text_select_tool_label">Text Selection Tool</span>
|
||||
</button>
|
||||
<button id="cursorHandTool" class="secondaryToolbarButton handTool" title="Enable Hand Tool" tabindex="61" data-l10n-id="cursor_hand_tool">
|
||||
<span data-l10n-id="cursor_hand_tool_label">Hand Tool</span>
|
||||
</button>
|
||||
|
||||
<div class="horizontalToolbarSeparator"></div>
|
||||
|
||||
<button id="documentProperties" class="secondaryToolbarButton documentProperties" title="Document Properties…" tabindex="62" data-l10n-id="document_properties">
|
||||
<span data-l10n-id="document_properties_label">Document Properties…</span>
|
||||
</button>
|
||||
</div>
|
||||
</div> <!-- secondaryToolbar -->
|
||||
|
||||
<div class="toolbar">
|
||||
<div id="toolbarContainer">
|
||||
<div id="toolbarViewer">
|
||||
<div id="toolbarViewerLeft">
|
||||
<button id="sidebarToggle" class="toolbarButton" title="Toggle Sidebar" tabindex="11" data-l10n-id="toggle_sidebar">
|
||||
<span data-l10n-id="toggle_sidebar_label">Toggle Sidebar</span>
|
||||
</button>
|
||||
<div class="toolbarButtonSpacer"></div>
|
||||
<button id="viewFind" class="toolbarButton" title="Find in Document" tabindex="12" data-l10n-id="findbar">
|
||||
<span data-l10n-id="findbar_label">Find</span>
|
||||
</button>
|
||||
<div class="splitToolbarButton hiddenSmallView">
|
||||
<button class="toolbarButton pageUp" title="Previous Page" id="previous" tabindex="13" data-l10n-id="previous">
|
||||
<span data-l10n-id="previous_label">Previous</span>
|
||||
</button>
|
||||
<div class="splitToolbarButtonSeparator"></div>
|
||||
<button class="toolbarButton pageDown" title="Next Page" id="next" tabindex="14" data-l10n-id="next">
|
||||
<span data-l10n-id="next_label">Next</span>
|
||||
</button>
|
||||
</div>
|
||||
<input type="number" id="pageNumber" class="toolbarField pageNumber" title="Page" value="1" size="4" min="1" tabindex="15" data-l10n-id="page">
|
||||
<span id="numPages" class="toolbarLabel"></span>
|
||||
</div>
|
||||
<div id="toolbarViewerRight">
|
||||
<button id="presentationMode" class="toolbarButton presentationMode hiddenLargeView" title="Switch to Presentation Mode" tabindex="31" data-l10n-id="presentation_mode">
|
||||
<span data-l10n-id="presentation_mode_label">Presentation Mode</span>
|
||||
</button>
|
||||
|
||||
<button id="openFile" class="toolbarButton openFile hiddenLargeView" title="Open File" tabindex="32" data-l10n-id="open_file">
|
||||
<span data-l10n-id="open_file_label">Open</span>
|
||||
</button>
|
||||
|
||||
<button id="print" class="toolbarButton print hiddenMediumView" title="Print" tabindex="33" data-l10n-id="print">
|
||||
<span data-l10n-id="print_label">Print</span>
|
||||
</button>
|
||||
|
||||
<button id="download" class="toolbarButton download hiddenMediumView" title="Download" tabindex="34" data-l10n-id="download">
|
||||
<span data-l10n-id="download_label">Download</span>
|
||||
</button>
|
||||
<a href="#" id="viewBookmark" class="toolbarButton bookmark hiddenSmallView" title="Current view (copy or open in new window)" tabindex="35" data-l10n-id="bookmark">
|
||||
<span data-l10n-id="bookmark_label">Current View</span>
|
||||
</a>
|
||||
|
||||
<div class="verticalToolbarSeparator hiddenSmallView"></div>
|
||||
|
||||
<button id="secondaryToolbarToggle" class="toolbarButton" title="Tools" tabindex="36" data-l10n-id="tools">
|
||||
<span data-l10n-id="tools_label">Tools</span>
|
||||
</button>
|
||||
</div>
|
||||
<div id="toolbarViewerMiddle">
|
||||
<div class="splitToolbarButton">
|
||||
<button id="zoomOut" class="toolbarButton zoomOut" title="Zoom Out" tabindex="21" data-l10n-id="zoom_out">
|
||||
<span data-l10n-id="zoom_out_label">Zoom Out</span>
|
||||
</button>
|
||||
<div class="splitToolbarButtonSeparator"></div>
|
||||
<button id="zoomIn" class="toolbarButton zoomIn" title="Zoom In" tabindex="22" data-l10n-id="zoom_in">
|
||||
<span data-l10n-id="zoom_in_label">Zoom In</span>
|
||||
</button>
|
||||
</div>
|
||||
<span id="scaleSelectContainer" class="dropdownToolbarButton">
|
||||
<select id="scaleSelect" title="Zoom" tabindex="23" data-l10n-id="zoom">
|
||||
<option id="pageAutoOption" title="" value="auto" selected="selected" data-l10n-id="page_scale_auto">Automatic Zoom</option>
|
||||
<option id="pageActualOption" title="" value="page-actual" data-l10n-id="page_scale_actual">Actual Size</option>
|
||||
<option id="pageFitOption" title="" value="page-fit" data-l10n-id="page_scale_fit">Page Fit</option>
|
||||
<option id="pageWidthOption" title="" value="page-width" data-l10n-id="page_scale_width">Page Width</option>
|
||||
<option id="customScaleOption" title="" value="custom" disabled="disabled" hidden="true"></option>
|
||||
<option title="" value="0.5" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 50 }'>50%</option>
|
||||
<option title="" value="0.75" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 75 }'>75%</option>
|
||||
<option title="" value="1" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 100 }'>100%</option>
|
||||
<option title="" value="1.25" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 125 }'>125%</option>
|
||||
<option title="" value="1.5" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 150 }'>150%</option>
|
||||
<option title="" value="2" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 200 }'>200%</option>
|
||||
<option title="" value="3" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 300 }'>300%</option>
|
||||
<option title="" value="4" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 400 }'>400%</option>
|
||||
</select>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="loadingBar">
|
||||
<div class="progress">
|
||||
<div class="glimmer">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<menu type="context" id="viewerContextMenu">
|
||||
<menuitem id="contextFirstPage" label="First Page"
|
||||
data-l10n-id="first_page"></menuitem>
|
||||
<menuitem id="contextLastPage" label="Last Page"
|
||||
data-l10n-id="last_page"></menuitem>
|
||||
<menuitem id="contextPageRotateCw" label="Rotate Clockwise"
|
||||
data-l10n-id="page_rotate_cw"></menuitem>
|
||||
<menuitem id="contextPageRotateCcw" label="Rotate Counter-Clockwise"
|
||||
data-l10n-id="page_rotate_ccw"></menuitem>
|
||||
</menu>
|
||||
|
||||
<div id="viewerContainer" tabindex="0">
|
||||
<div id="viewer" class="pdfViewer"></div>
|
||||
</div>
|
||||
|
||||
<div id="errorWrapper" hidden='true'>
|
||||
<div id="errorMessageLeft">
|
||||
<span id="errorMessage"></span>
|
||||
<button id="errorShowMore" data-l10n-id="error_more_info">
|
||||
More Information
|
||||
</button>
|
||||
<button id="errorShowLess" data-l10n-id="error_less_info" hidden='true'>
|
||||
Less Information
|
||||
</button>
|
||||
</div>
|
||||
<div id="errorMessageRight">
|
||||
<button id="errorClose" data-l10n-id="error_close">
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
<div class="clearBoth"></div>
|
||||
<textarea id="errorMoreInfo" hidden='true' readonly="readonly"></textarea>
|
||||
</div>
|
||||
</div> <!-- mainContainer -->
|
||||
|
||||
<div id="overlayContainer" class="hidden">
|
||||
<div id="passwordOverlay" class="container hidden">
|
||||
<div class="dialog">
|
||||
<div class="row">
|
||||
<p id="passwordText" data-l10n-id="password_label">Enter the password to open this PDF file:</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<input type="password" id="password" class="toolbarField">
|
||||
</div>
|
||||
<div class="buttonRow">
|
||||
<button id="passwordCancel" class="overlayButton"><span data-l10n-id="password_cancel">Cancel</span></button>
|
||||
<button id="passwordSubmit" class="overlayButton"><span data-l10n-id="password_ok">OK</span></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="documentPropertiesOverlay" class="container hidden">
|
||||
<div class="dialog">
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_file_name">File name:</span> <p id="fileNameField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_file_size">File size:</span> <p id="fileSizeField">-</p>
|
||||
</div>
|
||||
<div class="separator"></div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_title">Title:</span> <p id="titleField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_author">Author:</span> <p id="authorField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_subject">Subject:</span> <p id="subjectField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_keywords">Keywords:</span> <p id="keywordsField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_creation_date">Creation Date:</span> <p id="creationDateField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_modification_date">Modification Date:</span> <p id="modificationDateField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_creator">Creator:</span> <p id="creatorField">-</p>
|
||||
</div>
|
||||
<div class="separator"></div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_producer">PDF Producer:</span> <p id="producerField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_version">PDF Version:</span> <p id="versionField">-</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span data-l10n-id="document_properties_page_count">Page Count:</span> <p id="pageCountField">-</p>
|
||||
</div>
|
||||
<div class="buttonRow">
|
||||
<button id="documentPropertiesClose" class="overlayButton"><span data-l10n-id="document_properties_close">Close</span></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="printServiceOverlay" class="container hidden">
|
||||
<div class="dialog">
|
||||
<div class="row">
|
||||
<span data-l10n-id="print_progress_message">Preparing document for printing…</span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<progress value="0" max="100"></progress>
|
||||
<span data-l10n-id="print_progress_percent" data-l10n-args='{ "progress": 0 }' class="relative-progress">0%</span>
|
||||
</div>
|
||||
<div class="buttonRow">
|
||||
<button id="printCancel" class="overlayButton"><span data-l10n-id="print_progress_close">Cancel</span></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- overlayContainer -->
|
||||
|
||||
</div> <!-- outerContainer -->
|
||||
<div id="printContainer"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,354 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Tests;
|
||||
|
||||
/**
|
||||
* @group api_exposers
|
||||
*/
|
||||
class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
||||
protected $item;
|
||||
protected $collection;
|
||||
protected $field;
|
||||
|
||||
protected function create_meta_requirements() {
|
||||
$collection = $this->tainacan_entity_factory->create_entity(
|
||||
'collection',
|
||||
array(
|
||||
'name' => 'testeItemExpose',
|
||||
'description' => 'No description',
|
||||
),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$type = $this->tainacan_field_factory->create_field('text');
|
||||
|
||||
$field = $this->tainacan_entity_factory->create_entity(
|
||||
'field',
|
||||
array(
|
||||
'name' => 'teste_Expose',
|
||||
'description' => 'descricao',
|
||||
'collection' => $collection,
|
||||
'field_type' => $type,
|
||||
'exposer_mapping' => [
|
||||
'dublin-core' => [
|
||||
'name' => 'language',
|
||||
'label' => 'language',
|
||||
'URI' => 'http://purl.org/dc/terms/language',
|
||||
]
|
||||
]
|
||||
),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$item = $this->tainacan_entity_factory->create_entity(
|
||||
'item',
|
||||
array(
|
||||
'title' => 'item_teste_Expose',
|
||||
'description' => 'adasdasdsa',
|
||||
'collection' => $collection
|
||||
),
|
||||
true,
|
||||
true
|
||||
);
|
||||
$this->collection = $collection;
|
||||
$this->item = $item;
|
||||
$this->field = $field;
|
||||
return ['collection' => $collection, 'item' => $item, 'field' => $field];
|
||||
}
|
||||
|
||||
/**
|
||||
* @group value_exposer
|
||||
*/
|
||||
public function test_value_exposer() {
|
||||
global $Tainacan_Fields, $Tainacan_Item_Metadata;
|
||||
|
||||
extract($this->create_meta_requirements());
|
||||
|
||||
$item__metadata_json = json_encode([
|
||||
'values' => 'TestValues_exposers',
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $item->get_id() . '/metadata/' . $field->get_id() );
|
||||
$request->set_body($item__metadata_json);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals($item->get_id(), $data['item']['id']);
|
||||
$this->assertEquals('TestValues_exposers', $data['value']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-map' => 'Value',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata/'. $field->get_id() );
|
||||
$request->set_body($item_exposer_json);
|
||||
$response = $this->server->dispatch($request);
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals('TestValues_exposers', $data['teste_Expose']);
|
||||
|
||||
$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();
|
||||
|
||||
$this->assertEquals('adasdasdsa', $data['Description']);
|
||||
$this->assertEquals('item_teste_Expose', $data['Title']);
|
||||
$this->assertEquals('TestValues_exposers', $data['teste_Expose']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group xml_exposer
|
||||
*/
|
||||
public function test_xml_exposer() {
|
||||
global $Tainacan_Fields, $Tainacan_Item_Metadata;
|
||||
|
||||
extract($this->create_meta_requirements());
|
||||
|
||||
$item__metadata_json = json_encode([
|
||||
'values' => 'TestValues_exposers',
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $item->get_id() . '/metadata/' . $field->get_id() );
|
||||
$request->set_body($item__metadata_json);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals($item->get_id(), $data['item']['id']);
|
||||
$this->assertEquals('TestValues_exposers', $data['value']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'Xml',
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata/'. $field->get_id() );
|
||||
$request->set_body($item_exposer_json);
|
||||
$response = $this->server->dispatch($request);
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertInstanceOf('SimpleXMLElement', @simplexml_load_string($data));
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-map' => 'Dublin Core',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata/'. $field->get_id() );
|
||||
$request->set_body($item_exposer_json);
|
||||
$response = $this->server->dispatch($request);
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals('TestValues_exposers', $data['dc:language']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'Xml',
|
||||
'exposer-map' => 'Dublin Core',
|
||||
]);
|
||||
$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);
|
||||
$rdf = $xml->children(\Tainacan\Exposers\Mappers\Dublin_Core::XML_RDF_NAMESPACE);
|
||||
$dc = $rdf->children(\Tainacan\Exposers\Mappers\Dublin_Core::XML_DC_NAMESPACE);
|
||||
|
||||
$this->assertEquals('adasdasdsa', $dc->description);
|
||||
$this->assertEquals('item_teste_Expose', $dc->title);
|
||||
$this->assertEquals('TestValues_exposers', $dc->language);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group oai-pmh
|
||||
*/
|
||||
public function test_oai_pmh() {
|
||||
global $Tainacan_Fields, $Tainacan_Item_Metadata;
|
||||
|
||||
extract($this->create_meta_requirements());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => '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('adasdasdsa', $dc->description);
|
||||
$this->assertEquals('item_teste_Expose', $dc->title);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group exposer-type-html
|
||||
*/
|
||||
public function test_html_type() {
|
||||
global $Tainacan_Fields, $Tainacan_Item_Metadata;
|
||||
|
||||
extract($this->create_meta_requirements());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'Html',
|
||||
'exposer-map' => 'Value'
|
||||
]);
|
||||
$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();
|
||||
// Parse HTML reponse
|
||||
$doc = new \DOMDocument();
|
||||
$this->assertTrue($doc->loadHTML($data));
|
||||
|
||||
$headers = $doc->getElementsByTagName('th');
|
||||
$values = $doc->getElementsByTagName('td');
|
||||
|
||||
$htmlheaders = [];
|
||||
|
||||
foreach($headers as $nodeHeader) {
|
||||
$htmlheaders[] = trim($nodeHeader->textContent);
|
||||
}
|
||||
|
||||
$htmlValues = [];
|
||||
$row = 0;
|
||||
$col = 0;
|
||||
foreach ($values as $nodeValue) {
|
||||
if(!array_key_exists($row, $htmlValues)) $htmlValues[$row] = [];
|
||||
$htmlValues[$row][$htmlheaders[$col]] = trim($nodeValue->textContent);
|
||||
$col++;
|
||||
if(count($htmlValues[$row]) == count($htmlheaders)) {
|
||||
$row++;
|
||||
$col = 0;
|
||||
}
|
||||
}
|
||||
// End of Parse HTML reponse
|
||||
|
||||
$this->assertEquals('adasdasdsa', $htmlValues[0]['Description']);
|
||||
$this->assertEquals('', $htmlValues[0]['teste_Expose']);
|
||||
$this->assertEquals('item_teste_Expose', $htmlValues[0]['Title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group exposer-type-csv
|
||||
*/
|
||||
public function test_csv_type() {
|
||||
global $Tainacan_Fields, $Tainacan_Item_Metadata;
|
||||
|
||||
extract($this->create_meta_requirements());
|
||||
|
||||
$item__metadata_json = json_encode([
|
||||
'values' => 'TestValues_exposers',
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $item->get_id() . '/metadata/' . $field->get_id() );
|
||||
$request->set_body($item__metadata_json);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'Csv',
|
||||
]);
|
||||
$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();
|
||||
file_put_contents('/tmp/1.csv', $data);
|
||||
|
||||
$lines = explode(PHP_EOL, $data);
|
||||
$csv_lines = [];
|
||||
foreach ($lines as $line) {
|
||||
$csv_lines[] = str_getcsv($line, ';');
|
||||
}
|
||||
array_walk($csv_lines, function(&$a) use ($csv_lines) {
|
||||
if(count($a) == count($csv_lines)) {
|
||||
$a = array_combine($csv_lines[0], $a);
|
||||
}
|
||||
});
|
||||
array_shift($csv_lines);
|
||||
|
||||
$this->assertEquals('adasdasdsa', $csv_lines[0]['Description']);
|
||||
$this->assertEquals('TestValues_exposers', $csv_lines[0]['teste_Expose']);
|
||||
$this->assertEquals('item_teste_Expose', $csv_lines[0]['Title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group items_exposer
|
||||
*/
|
||||
public function test_items_exposer() {
|
||||
global $Tainacan_Fields, $Tainacan_Item_Metadata;
|
||||
|
||||
extract($this->create_meta_requirements());
|
||||
|
||||
$item__metadata_json = json_encode([
|
||||
'values' => 'TestValues_exposers',
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $item->get_id() . '/metadata/' . $field->get_id() );
|
||||
$request->set_body($item__metadata_json);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals($item->get_id(), $data['item']['id']);
|
||||
$this->assertEquals('TestValues_exposers', $data['value']);
|
||||
|
||||
$item2 = $this->tainacan_entity_factory->create_entity(
|
||||
'item',
|
||||
array(
|
||||
'title' => 'item_teste_Expose2',
|
||||
'description' => 'adasdasdsa2',
|
||||
'collection' => $collection
|
||||
),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$item3 = $this->tainacan_entity_factory->create_entity(
|
||||
'item',
|
||||
array(
|
||||
'title' => 'item_teste_Expose3',
|
||||
'description' => 'adasdasdsa3',
|
||||
'collection' => $collection
|
||||
),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-map' => 'Value',
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/items/' . $item->get_id() );
|
||||
$request->set_body($item_exposer_json);
|
||||
$response = $this->server->dispatch($request);
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals('adasdasdsa', $data['Description']);
|
||||
$this->assertEquals('item_teste_Expose', $data['Title']);
|
||||
$this->assertEquals('TestValues_exposers', $data['teste_Expose']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -29,7 +29,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
$this->assertEquals( $collection->get_id(), $_SESSION['tainacan_importer'][$id]->collection->get_id() );
|
||||
}
|
||||
|
||||
public function test_automapping_old_tainacan()
|
||||
/*public function test_automapping_old_tainacan()
|
||||
{
|
||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
|
||||
|
@ -47,7 +47,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
$_SESSION['tainacan_importer'][$id]->set_file( './tests/attachment/json_old_tainacan.txt' );
|
||||
|
||||
$_SESSION['tainacan_importer'][$id]->run();
|
||||
}
|
||||
}*/
|
||||
|
||||
public function test_file_old_tainacan () {
|
||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||
|
@ -63,14 +63,16 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
return false;
|
||||
}
|
||||
|
||||
$_SESSION['tainacan_importer'][$id]->set_file( './tests/attachment/json_old_tainacan.txt' );
|
||||
//$_SESSION['tainacan_importer'][$id]->set_file( './tests/attachment/json_old_tainacan.txt' );
|
||||
|
||||
//$_SESSION['tainacan_importer'][$id]->fetch_from_remote( 'http://localhost/wp-json/tainacan/v1/collections/970/items' );
|
||||
$_SESSION['tainacan_importer'][$id]->fetch_from_remote( 'http://localhost/colecao/colecao-to-import/' );
|
||||
|
||||
// file isset on importer
|
||||
$this->assertTrue( isset( $_SESSION['tainacan_importer'][$id]->tmp_file ) );
|
||||
|
||||
// count size of old tainacan file
|
||||
$_SESSION['tainacan_importer'][$id]->run();
|
||||
/*// count size of old tainacan file
|
||||
$this->assertEquals( 5, $_SESSION['tainacan_importer'][$id]->get_total_items() );
|
||||
|
||||
// get fields to mapping
|
||||
|
@ -117,7 +119,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
|
||||
$items = $Tainacan_Items->fetch( [], $collection, 'OBJECT' );
|
||||
|
||||
$this->assertEquals( $_SESSION['tainacan_importer'][$id]->get_total_items(), count( $items ) );
|
||||
$this->assertEquals( $_SESSION['tainacan_importer'][$id]->get_total_items(), count( $items ) );*/
|
||||
}
|
||||
/**
|
||||
* @group importer
|
||||
|
|
Loading…
Reference in New Issue