Merge branch 'master' of github.com:tainacan/tainacan
This commit is contained in:
commit
9d3e21c32f
|
@ -1,2 +1,2 @@
|
|||
# the destination folder, inside the plugins folder of some WordPress installation
|
||||
destination=~/devel/wordpress/wp-content/plugins/test-tainacan
|
||||
destination=~/devel/wordpress/wp-content/plugins/tainacan
|
5
build.sh
5
build.sh
|
@ -2,14 +2,13 @@
|
|||
|
||||
#source build-config.cfg
|
||||
source build-config.cfg
|
||||
#destination=~/devel/wordpress/wp-content/plugins/test-tainacan
|
||||
#destination=~/devel/wordpress/wp-content/plugins/tainacan
|
||||
|
||||
sh compile-sass.sh
|
||||
composer install
|
||||
|
||||
echo "Atualizando arquivos em $destination"
|
||||
rm -r $destination
|
||||
rm -rf $destination
|
||||
mkdir $destination
|
||||
cp -R src/ $destination/
|
||||
cp -R vendor/ $destination/
|
||||
rm -rf $destination/scss
|
||||
|
|
|
@ -5,5 +5,8 @@
|
|||
"require": {
|
||||
"respect/validation": "^1.1"
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
"minimum-stability": "dev",
|
||||
"config": {
|
||||
"vendor-dir": "src/vendor"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
use Tainacan\Repositories;
|
||||
|
||||
class TAINACAN_REST_Collections_Controller extends WP_REST_Controller {
|
||||
private $collections_respository;
|
||||
|
||||
public function __construct(){
|
||||
$this->namespace = 'tainacan/v2';
|
||||
$this->rest_base = 'collections';
|
||||
$this->collections_respository = new Repositories\Collections();
|
||||
|
||||
add_action('rest_api_init', array($this, 'register_routes'));
|
||||
}
|
||||
|
||||
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_permission_check'),
|
||||
),
|
||||
));
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item'),
|
||||
//'permission_callback' => array($this, 'get_item_permission_check'),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
public function get_items($request){
|
||||
$collections = $this->collections_respository->fetch();
|
||||
|
||||
$response = $this->prepare_item_for_response($collections, $request);
|
||||
|
||||
return new WP_REST_Response($response, 200);
|
||||
}
|
||||
|
||||
public function get_item($request){
|
||||
$collection_id = $request['id'];
|
||||
$collection = $this->collections_respository->fetch($collection_id);
|
||||
|
||||
$response = $this->prepare_item_for_response($collection, $request);
|
||||
|
||||
return new WP_REST_Response($response, 200);
|
||||
}
|
||||
|
||||
public function prepare_item_for_response($item, $request){
|
||||
if(is_array($item)){
|
||||
|
||||
$collections_as_json = [];
|
||||
foreach ($item as $wp_post){
|
||||
array_push($posts_as_json, $wp_post->__toJSON());
|
||||
}
|
||||
|
||||
return $collections_as_json;
|
||||
}
|
||||
else {
|
||||
return $item->__toJSON();
|
||||
}
|
||||
}
|
||||
|
||||
public function get_item_schema(){
|
||||
|
||||
}
|
||||
|
||||
public function get_items_permissions_check($request){
|
||||
return parent::get_items_permissions_check($request); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
public function get_item_permissions_check($request){
|
||||
return parent::get_item_permissions_check($request); // TODO: Change the autogenerated stub
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -31,6 +31,19 @@ class Collection extends Entity {
|
|||
}
|
||||
}
|
||||
|
||||
public function __toString(){
|
||||
return 'Hello, I\'m the Collection Entity';
|
||||
}
|
||||
|
||||
public function __toJSON(){
|
||||
return json_encode(
|
||||
[
|
||||
'name' => $this->get_name(),
|
||||
'description' => $this->get_description(),
|
||||
'items_per_page' => $this->get_itens_per_page(),
|
||||
]
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Register the post type for this collection
|
||||
*
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
Plugin Name: Tainacan
|
||||
Plugin URI:
|
||||
Description: Lorem Ipsum
|
||||
Author: MediaLab UFG
|
||||
Version: 10.9.8.7.6.5.4
|
||||
* Plugin Name: Tainacan
|
||||
* Plugin URI: https://github.com/tainacan/tainacan
|
||||
* Description: Transforme seu site Wordpress em um repositório digital
|
||||
* Author: Media Lab / UFG
|
||||
* Version: 1.0
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||||
|
@ -15,7 +16,8 @@ const FILTER_TYPES_DIR = __DIR__ . '/classes/filter-types/';
|
|||
const REPOSITORIES_DIR = __DIR__ . '/classes/repositories/';
|
||||
const TRAITS_DIR = __DIR__ . '/classes/traits/';
|
||||
const CLASSES_DIR = __DIR__ . '/classes/';
|
||||
const VENDOR_DIR = __DIR__ . '/../vendor/';
|
||||
const VENDOR_DIR = __DIR__ . '/vendor/';
|
||||
const ENDPOINTS_DIR = __DIR__ . '/api/endpoints/';
|
||||
|
||||
const DIRS = [
|
||||
CLASSES_DIR,
|
||||
|
@ -28,16 +30,16 @@ const DIRS = [
|
|||
|
||||
require_once(VENDOR_DIR . 'autoload.php');
|
||||
|
||||
spl_autoload_register('tainacan_autoload');
|
||||
spl_autoload_register('tainacan_autoload');
|
||||
|
||||
function tainacan_autoload($class_name){
|
||||
$class_path = explode('\\', $class_name);
|
||||
$class_name = end($class_path);
|
||||
|
||||
|
||||
if(count($class_path) == 1 ) {
|
||||
foreach(DIRS as $dir) {
|
||||
$file = $dir . 'class-'. strtolower(str_replace('_', '-' , $class_name)) . '.php';
|
||||
|
||||
|
||||
if(file_exists($file)) {
|
||||
require_once($file);
|
||||
}
|
||||
|
@ -46,7 +48,7 @@ function tainacan_autoload($class_name){
|
|||
elseif ($class_path[0] == 'Tainacan') {
|
||||
$dir = strtolower(CLASSES_DIR.implode(DIRECTORY_SEPARATOR, array_slice($class_path, 1, count($class_path) -2) )).'/';
|
||||
$dir = str_replace('_', '-', $dir);
|
||||
|
||||
|
||||
$file = $dir . 'class-tainacan-'. strtolower(str_replace('_', '-' , $class_name)) . '.php';
|
||||
|
||||
if(file_exists($file)) {
|
||||
|
@ -79,6 +81,10 @@ $Tainacan_Terms = new \Tainacan\Repositories\Terms();
|
|||
global $Tainacan_Logs;
|
||||
$Tainacan_Logs = new \Tainacan\Repositories\Logs();
|
||||
|
||||
|
||||
require_once(ENDPOINTS_DIR . 'class-tainacan-rest-collections-controller.php');
|
||||
$rest_collections_controller = new TAINACAN_REST_Collections_Controller();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
|
|
@ -32,8 +32,7 @@ class Collections extends \WP_UnitTestCase {
|
|||
//
|
||||
|
||||
$test = $Tainacan_Collections->fetch($col->get_id());
|
||||
|
||||
|
||||
|
||||
$this->assertEquals($test->get_name(), 'teste');
|
||||
$this->assertEquals($test->get_description(), 'adasdasdsa');
|
||||
$this->assertEquals($test->get_itens_per_page(), 23);
|
||||
|
|
Loading…
Reference in New Issue