-
Notifications
You must be signed in to change notification settings - Fork 1
/
wp-civitai-page.php
41 lines (37 loc) · 1.23 KB
/
wp-civitai-page.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
<?php
class WpCivitaiPage {
protected $data;
protected $component_name;
protected $type;
public function __construct($type, $data) {
$this->data = $data;
switch ($type) {
case 'model':
$this->component_name = 'SingleModelPage';
break;
default:
$this->component_name = null;
break;
}
}
public function process_and_render() {
if ($this->component_name == null) {
return 'Invalid shortcode. Please specify a valid type';
}
// description is formatted html, render it
ob_start();
?>
<script>
/** wp-civitai - <?php echo $this->component_name;?>*/
if (typeof window.__CIVITAI_DATA__ === 'undefined') {
window.__CIVITAI_DATA__ = {};
}
if (typeof window.__CIVITAI_DATA__.<?php echo $this->component_name; ?> === 'undefined') {
window.__CIVITAI_DATA__.<?php echo $this->component_name; ?> = <?php echo json_encode($this->data); ?>;
}
</script>
<div id="wp-civitai-<?php echo $this->component_name ?>"></div>
<?php
return ob_get_clean();
}
}