-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid-handler.php
148 lines (115 loc) · 3.62 KB
/
grid-handler.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
add_post_type_support('page', 'grid');
class Paged_Grid_Metabox {
private $metabox_id;
public function __construct() {
$this->metabox_id = 'grid';
}
public function initialize() {
if(isset ($_REQUEST['edit_grid_slot']) ) {
$this->handle_edit_grid_frame();
}
add_action('add_meta_boxes', array($this, '_add_metabox'));
//add the scripts and styles for the metabox
add_action('admin_print_styles-post.php', array($this, '_enqueue_scripts' ) );
add_action('admin_print_styles-post-new.php', array($this, '_enqueue_scripts' ) );
add_action('save_post', array($this, '_update_meta'));
}
public function _add_metabox($post_type) {
if(post_type_supports($post_type, $this->metabox_id)) {
add_meta_box($this->metabox_id, 'Gallery Assets', array($this, '_metabox'), $post_type, 'normal');
}
}
public function _metabox($post) {
?>
<div class="grid-page-frame">
<?php for($i = 1; $i <= 3; $i++) : ?>
<div class="grid-page" id="grid-page-<?php echo $i; ?>">
<?php for($x = 1; $x <= 12; $x++) : ?>
<div class="grid-slot" id="<?php printf("slot_%d_%d", $i, $x); ?>">
<?php
$query_vars = array(
'TB_iframe' => true,
'width' => 400,
'height' => 600,
'edit_grid_slot' => true,
'post_id' => $post->ID,
'grid_page' => $i,
'grid_slot' => $x,
);
$set_url = add_query_arg($query_vars, admin_url());
echo $set_url;
?>
<a href="<?php echo admin_url() . $set_url ?>" class="thickbox">Set Widget</a>
</div>
<?php endfor; ?>
</div>
<?php endfor; ?>
</div>
<?php
}
public function _enqueue_scripts() {
wp_enqueue_style('grid-metabox', Paged_Grid_Handler::Plugins_URL('css/metabox.css', __FILE__));
wp_enqueue_script('grid-metabox', Paged_Grid_Handler::Plugins_URL('js/metabox.js', __FILE__), array('jquery'));
}
public function _update_meta($post_id) {
if(wp_is_post_autosave($post_id) || wp_is_post_revision($post_id)) {
return $post_id;
}
if(!post_type_supports( get_post_type($post_id), $this->metabox_id)) {
return $post_id;
}
if(isset($_REQUEST['$this->metabox_id_nonce']) && wp_verify_nonce($_REQUEST['$this->metabox_id_nonce'], 'update_$this->metabox_id')) {
}
return $post_id;
}
public function handle_edit_grid_frame() {
die("HHHHHHHHEEEEEEEEEEEEEEERRRRRRRRE");
}
}
add_action('init', array(new Paged_Grid_Metabox(), 'initialize'));
class Paged_Grid_Handler {
public static function Plugins_URL($relative_path, $plugin_path) {
$template_dir = get_template_directory();
foreach ( array('template_dir', 'plugin_path') as $var ) {
$$var = str_replace('\\' ,'/', $$var); // sanitize for Win32 installs
$$var = preg_replace('|/+|', '/', $$var);
}
if(0 === strpos($plugin_path, $template_dir)) {
$url = get_template_directory_uri();
$folder = str_replace($template_dir, '', dirname($plugin_path));
if ( '.' != $folder ) {
$url .= '/' . ltrim($folder, '/');
}
if ( !empty($relative_path) && is_string($relative_path) && strpos($relative_path, '..') === false ) {
$url .= '/' . ltrim($relative_path, '/');
}
return $url;
} else {
return plugins_url($relative_path, $plugin_path);
}
}
}
class Paged_Grid_Set {
const MAX_NUM_PAGES = 9;
private $page_data;
public function __construct($page_data) {
}
public function add_page() {
if($this->num_pages() >= self::MAX_NUM_PAGES) {
return false;
}
return true;
}
public function remove_page() {
if($this->num_pages() <= 1) {
return false;
}
return true;
}
public function num_pages() {
}
}
class Grid_Page {
}
//grid page set -> grid page -> grid slot