|
@@ -39,9 +39,10 @@ |
39 |
39 |
|
if( isset( $_GET["type"] ) && !empty( $_GET["type"] ) ) |
40 |
40 |
|
{ |
41 |
41 |
|
$type = explode("-",$_GET["type"]); |
42 |
|
- |
$location = $type[0]; |
|
42 |
+ |
$type = sanitize_text_field($type[0]); |
43 |
43 |
|
$title = $_GET["title"]; |
44 |
|
- |
$this->get_post_by_title_and_type("actuaciones-".$location, $title); |
|
44 |
+ |
$lang = sanitize_text_field($_GET["language"]); |
|
45 |
+ |
new GalleryActuacionsFactory( $lang, $title, $type ); |
45 |
46 |
|
die(); |
46 |
47 |
|
} |
47 |
48 |
|
} |
|
@@ -79,6 +80,108 @@ |
79 |
80 |
|
} |
80 |
81 |
|
} |
81 |
82 |
|
|
|
83 |
+ |
class GalleryActuacionsFactory |
|
84 |
+ |
{ |
|
85 |
+ |
public function __construct( $lang, $title, $type ) |
|
86 |
+ |
{ |
|
87 |
+ |
global $wpdb; |
|
88 |
+ |
|
|
89 |
+ |
$querystr = " |
|
90 |
+ |
SELECT wposts.ID, wposts.post_title, wposts.post_type |
|
91 |
+ |
FROM $wpdb->posts wposts |
|
92 |
+ |
WHERE wposts.post_type = 'actuaciones-{$type}' |
|
93 |
+ |
AND wposts.post_title = '{$title}' |
|
94 |
+ |
AND wposts.post_status = 'publish' |
|
95 |
+ |
"; |
|
96 |
+ |
|
|
97 |
+ |
$post = $wpdb->get_results($querystr, OBJECT); |
|
98 |
+ |
|
|
99 |
+ |
$qry = " |
|
100 |
+ |
SELECT p.ID, pm.meta_key, pm.meta_value, p.post_date, p.post_type, p.post_title, p.post_content |
|
101 |
+ |
FROM $wpdb->posts p |
|
102 |
+ |
JOIN $wpdb->postmeta pm on p.ID = pm.post_id |
|
103 |
+ |
WHERE p.post_status = 'publish' |
|
104 |
+ |
AND p.post_parent = {$post[0]->ID} |
|
105 |
+ |
AND ( |
|
106 |
+ |
meta_key = 'wpcf-img-gallery' |
|
107 |
+ |
OR meta_key = 'wpcf-title-{$lang}-gallery' |
|
108 |
+ |
OR meta_key = 'wpcf-desc-{$lang}-gallery' |
|
109 |
+ |
OR meta_key = 'wpcf-videos-gallery' |
|
110 |
+ |
OR meta_key = 'wpcf-date-gallery' |
|
111 |
+ |
) |
|
112 |
+ |
ORDER BY p.ID DESC |
|
113 |
+ |
"; |
|
114 |
+ |
|
|
115 |
+ |
$childrens = $wpdb->get_results($qry, OBJECT); |
|
116 |
+ |
|
|
117 |
+ |
if( $post != NULL && $childrens != NULL ) |
|
118 |
+ |
{ |
|
119 |
+ |
$metaChildrens = array(); |
|
120 |
+ |
foreach( $childrens as $children ) |
|
121 |
+ |
{ |
|
122 |
+ |
$key = str_replace( |
|
123 |
+ |
array( "wpcf-title-{$lang}-gallery", "wpcf-desc-{$lang}-gallery", "wpcf-img-gallery", "wpcf-videos-gallery", "wpcf-date-gallery"), |
|
124 |
+ |
array( "title", "desc", "img", "video", "date"), |
|
125 |
+ |
$children->meta_key |
|
126 |
+ |
); |
|
127 |
+ |
|
|
128 |
+ |
if( count(explode("<!--:-->", $children->post_title)) > 1) |
|
129 |
+ |
{ |
|
130 |
+ |
$title = explode("<!--:-->", $children->post_title); |
|
131 |
+ |
if ( $lang === "CA" ) |
|
132 |
+ |
{ |
|
133 |
+ |
$title = str_replace( |
|
134 |
+ |
array( "<!--:CA-->", "<!--:es-->"), |
|
135 |
+ |
array( "", ""), |
|
136 |
+ |
$title[0] |
|
137 |
+ |
); |
|
138 |
+ |
} |
|
139 |
+ |
else |
|
140 |
+ |
{ |
|
141 |
+ |
$title = str_replace( |
|
142 |
+ |
array( "<!--:CA-->", "<!--:es-->"), |
|
143 |
+ |
array( "", ""), |
|
144 |
+ |
$title[1] |
|
145 |
+ |
); |
|
146 |
+ |
} |
|
147 |
+ |
} |
|
148 |
+ |
|
|
149 |
+ |
if( count(explode("<!--:-->", $children->post_content)) > 1) |
|
150 |
+ |
{ |
|
151 |
+ |
$content = explode("<!--:-->", $children->post_content); |
|
152 |
+ |
if ( $lang === "CA" ) |
|
153 |
+ |
{ |
|
154 |
+ |
$content = str_replace( |
|
155 |
+ |
array( "<!--:CA-->", "<!--:es-->"), |
|
156 |
+ |
array( "", ""), |
|
157 |
+ |
$content[0] |
|
158 |
+ |
); |
|
159 |
+ |
} |
|
160 |
+ |
else |
|
161 |
+ |
{ |
|
162 |
+ |
$content = str_replace( |
|
163 |
+ |
array( "<!--:CA-->", "<!--:es-->"), |
|
164 |
+ |
array( "", ""), |
|
165 |
+ |
$content[1] |
|
166 |
+ |
); |
|
167 |
+ |
} |
|
168 |
+ |
} |
|
169 |
+ |
|
|
170 |
+ |
$metaChildrens[$children->ID][$key] = array( "value" => $children->meta_value ); |
|
171 |
+ |
$metaChildrens[$children->ID]["post_type"] = $children->post_type; |
|
172 |
+ |
$metaChildrens[$children->ID]["title"] = array( "value" => $title); |
|
173 |
+ |
$metaChildrens[$children->ID]["desc"] = array( "value" => $content); |
|
174 |
+ |
} |
|
175 |
+ |
wp_send_json_success( array( "parent" => $post, "childrens" => $metaChildrens ) ); |
|
176 |
+ |
} |
|
177 |
+ |
else |
|
178 |
+ |
{ |
|
179 |
+ |
wp_send_json_error(); |
|
180 |
+ |
} |
|
181 |
+ |
die(); |
|
182 |
+ |
} |
|
183 |
+ |
} |
|
184 |
+ |
|
82 |
185 |
|
class GalleryVideoFactory |
83 |
186 |
|
{ |
84 |
187 |
|
public function __construct( $type, $lang, $id ) |