-
Notifications
You must be signed in to change notification settings - Fork 1
/
mcwp-list-entities.php
132 lines (115 loc) · 3.08 KB
/
mcwp-list-entities.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/*
Plugin Name: Mapas Builder Plugin
Plugin URI: http://plugins.redelivre.org.br/mapas-builder
Description: List entities from mapas culturais in shortcode and Divi Module formats.
Author: Caipira Lab
Version: 0.1
Text Domain:
*/
Class MCWP_Entities_List
{
function MCWP_Entities_list()
{
add_shortcode('list_entities', array(&$this, 'shortcode'));
add_action( 'wp_enqueue_scripts', array(&$this, 'addScripts') );
add_action( 'admin_enqueue_scripts', array(&$this, 'addAdminScripts') );
}
function addScripts() {
global $post;
if( is_a( $post, 'WP_Post' ) && !has_shortcode( $post->post_content, 'list_entities') && !has_shortcode($post->post_content, 'et_pb_mcwp_list_entities') ) {
return;
}
wp_enqueue_script('list-entities-ajax-script', plugin_dir_url( __FILE__ ) . 'js/app.js', array('jquery'));
wp_enqueue_script('mustache', plugin_dir_url( __FILE__ ) . 'bower_components/mustache.js/mustache.min.js');
wp_enqueue_style('list-entities-shortcode', plugin_dir_url( __FILE__ ) . 'css/mcwp-list-entities.css' );
}
function addAdminScripts() {
wp_enqueue_style('list-entities-shortcode-admin', plugin_dir_url( __FILE__ ) . 'css/mcwp-list-entities-admin.css' );
}
function shortcode($atts, $content) {
if (!is_array($atts))
{
echo "Error! No arguments found.";
return;
}
if (!isset($atts['url']) || (empty($atts['url'])))
{
echo "Error! Url not found.";
return;
}
$atts['url'] = rtrim($atts['url'],"/");
$select = 'name,shortDescription,singleUrl';
if (isset($atts['select']))
{
$select = $atts['select'];
}
$files = '(header.header,avatar.avatarBig):url';
if (isset($atts['files']))
{
$files = $atts['files'];
}
$entity = 'space';
if (isset($atts['entity'])) {
$entity = $atts['entity'];
}
$order = 'id ASC';
if (isset($atts['order'])) {
$order = $atts['order'];
}
if (isset($atts['pagination'])) {
$pagination = "data-pagination='true'";
}
$limit = "data-limit='10'";
if (isset($atts['limit'])) {
$limit = "data-limit='".$atts['limit']."'";
}
if (isset($atts['seals'])) {
//$seals = $atts['seals'];
}
if (isset($atts['profiles'])) {
//$profiles = $atts['profiles'];
}
if (isset($atts['filters'])) {
$filters = $atts['filters'];
}
if (isset($atts['filters_input'])) {
$filters_input = $atts['filters_input'];
}
if (isset($content))
{
$mtemplate = $content;
}
$params = [
'@files' => $files,
'@select' => $select,
'@order' => $order,
];
if (isset($seals))
{
$saux = [
'@seals' => $seals
];
$params = array_merge($params, $saux);
}
if (isset($profiles))
{
$paux = [
'@profiles' => $profiles
];
$params = array_merge($params, $paux);
}
$url = add_query_arg($params, $atts['url'] . '/api/'.$entity.'/find');
ob_start();
include('template.php');
$html = ob_get_clean();
return $html;
}
}
add_action('init', function() {
$MCWP_Entities_List = new MCWP_Entities_List;
});
add_action('et_builder_ready', 'mcwp_load_the_module');
function mcwp_load_the_module() {
require 'mcwp_entities_module.php';
}