forked from DiscipleTools/disciple-tools-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
single-template.php
376 lines (339 loc) · 21.7 KB
/
single-template.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<?php
declare( strict_types=1 );
dt_please_log_in();
$dt_post_type = get_post_type();
if ( ! current_user_can( 'access_' . $dt_post_type ) ) {
wp_safe_redirect( '/settings' );
exit();
}
( function () {
$post_type = get_post_type();
$post_id = get_the_ID();
if ( !DT_Posts::can_view( $post_type, $post_id ) ){
get_template_part( '403' );
die();
}
$current_user_id = get_current_user_id();
$post_settings = DT_Posts::get_post_settings( $post_type );
$dt_post = DT_Posts::get_post( $post_type, $post_id );
$tiles = DT_Posts::get_post_tiles( $post_type );
$following = DT_Posts::get_users_following_post( $post_type, $post_id );
Disciple_Tools_Notifications::process_new_notifications( get_the_ID() ); // removes new notifications for this post
get_header();
dt_print_details_bar(
true,
true,
isset( $post_settings['fields']['requires_update'] ) && current_user_can( 'assign_any_contacts' ),
isset( $dt_post['requires_update'] ) && $dt_post['requires_update'] === true,
in_array( $current_user_id, $following ),
isset( $dt_post['assigned_to']['id'] ) ? $dt_post['assigned_to']['id'] == $current_user_id : false,
true
);
?>
<div id="content" class="single-template">
<div id="inner-content" class="grid-x grid-margin-x grid-margin-y">
<?php do_action( 'dt_record_top_full_with', $post_type, $dt_post ) ?>
<main id="main" class="large-7 medium-12 small-12 cell" role="main" style="padding:0">
<div class="cell grid-y grid-margin-y">
<!-- Requires update block -->
<section class="cell small-12 update-needed-notification"
style="display: <?php echo esc_html( ( isset( $dt_post['requires_update'] ) && $dt_post['requires_update'] === true ) ? 'block' : 'none' ) ?> ">
<a href="#comment-activity-section" class="hide-for-large">
<div class="bordered-box detail-notification-box" style="background-color:#F43636">
<h4>
<img class="dt-white-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/alert-circle-exc.svg?v=2' ) ?>"/>
<?php echo esc_html( sprintf( __( 'This %s needs an update.', 'disciple_tools' ), strtolower( $post_settings['label_singular'] ) ) ) ?>
</h4>
<p><?php esc_html_e( 'Please provide an update by posting a comment.', 'disciple_tools' )?></p>
</div>
</a>
<div class="bordered-box detail-notification-box show-for-large" style="background-color:#F43636">
<h4>
<img class="dt-white-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/alert-circle-exc.svg?v=2' ) ?>"/>
<?php echo esc_html( sprintf( __( 'This %s needs an update.', 'disciple_tools' ), strtolower( $post_settings['label_singular'] ) ) ) ?>
</h4>
<p><?php esc_html_e( 'Please provide an update by posting a comment.', 'disciple_tools' )?></p>
</div>
</section>
<?php do_action( 'dt_record_notifications_section', $post_type, $dt_post ); ?>
<?php do_action( 'dt_record_top_above_details', $post_type, $dt_post ); ?>
<!--
Status section
-->
<?php if ( isset( $tiles['status'] ) && empty( $tiles['status']['hidden'] ) ) : ?>
<section id="contact-status" class="small-12 cell bordered-box">
<h3 class="section-header">
<?php echo esc_html__( 'Status', 'disciple_tools' )?>
<button class="help-button-tile" data-tile="status">
<img class="help-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/help.svg' ) ?>"/>
</button>
</h3>
<div class="grid-x grid-margin-x">
<?php
//setup the order of the tile fields
$order = $tiles['status']['order'] ?? [];
foreach ( $post_settings['fields'] as $key => $option ){
if ( isset( $option['tile'] ) && $option['tile'] === 'status' ){
if ( !in_array( $key, $order ) ){
$order[] = $key;
}
}
}
foreach ( $order as $field_key ) {
if ( !isset( $post_settings['fields'][$field_key] ) ){
continue;
}
$field = $post_settings['fields'][$field_key];
$enabled_for_type = dt_field_enabled_for_record_type( $field, $dt_post );
if ( isset( $field['tile'] ) && $field['tile'] === 'status' && $enabled_for_type && empty( $field['hidden'] ) ) {
?>
<div class="cell small-12 medium-4">
<?php render_field_for_display( $field_key, $post_settings['fields'], $dt_post, true ); ?>
</div>
<?php }
}
?>
<?php do_action( 'dt_details_additional_section', 'status', $post_type ); ?>
</div>
</section>
<?php endif; ?>
<!--
Main details section
-->
<section id="details-tile" class="small-12 cell bordered-box collapsed" >
<h3 class="section-header">
<?php echo esc_html__( 'Details', 'disciple_tools' )?>
<button class="help-button-tile" data-tile="details">
<img class="help-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/help.svg' ) ?>"/>
</button>
<div class="details-title-section"></div>
<button class="section-chevron chevron_down show-details-section">
<img src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/chevron_down.svg' ) ?>"/>
</button>
<button class="section-chevron chevron_up show-details-section">
<img src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/chevron_up.svg' ) ?>"/>
</button>
</h3>
<!--
Details section
-->
<div class="collapsed-details-section">
<!-- row for communication channel elements -->
<div class="detail-snippet-row">
<?php
//setup the order of the tile fields
$order = $tiles['details']['order'] ?? [];
foreach ( $post_settings['fields'] as $key => $option ){
if ( isset( $option['tile'] ) && $option['tile'] === 'details' && $option['type'] === 'communication_channel' ){
if ( !in_array( $key, $order ) ){
$order[] = $key;
}
}
}
foreach ( $order as $field_key ) {
if ( !isset( $post_settings['fields'][$field_key] ) ){
continue;
}
$field = $post_settings['fields'][$field_key];
if ( isset( $field['tile'] ) && $field['tile'] === 'details' ){
?>
<div class="detail-snippet" id="collapsed-detail-<?php echo esc_html( $field_key ); ?>">
<?php dt_render_field_icon( $field, 'dt-icon', true ); ?>
<span class="collapsed-items" dir="auto"></span>
</div>
<?php
}
}
?>
</div>
<!-- row for misc elements -->
<div class="detail-snippet-row">
<?php
$order = $tiles['details']['order'] ?? [];
foreach ( $post_settings['fields'] as $key => $option ){
if ( isset( $option['tile'] ) && $option['tile'] === 'details' && $option['type'] !== 'communication_channel' ){
if ( !in_array( $key, $order ) ) {
$order[] = $key;
}
}
}
foreach ( $order as $field_key ) {
if ( !isset( $post_settings['fields'][$field_key] ) ){
continue;
}
$field = $post_settings['fields'][$field_key];
if ( !dt_field_enabled_for_record_type( $field, $dt_post ) ) {
continue;
}
if ( isset( $field['tile'] ) && $field['tile'] === 'details' ){
?>
<div class="detail-snippet" id="collapsed-detail-<?php echo esc_html( $field_key ); ?>">
<?php dt_render_field_icon( $field, 'dt-icon', true ); ?>
<span class="collapsed-items" dir="auto"></span>
</div>
<?php
}
}
?>
</div>
</div> <!-- end collapse details section -->
<div id="show-details-edit-button" class="show-details-section" style="text-align: center; background-color:rgb(236, 245, 252);margin: 3px -15px -15px -15px; border-radius: 0 0 10px 10px;">
<a class="button clear " style="margin:0;padding:3px 0; width:100%">
<?php esc_html_e( 'Edit all details fields', 'disciple_tools' ); ?>
</a></div>
<div id="details-section" class="display-fields" style="display: none; margin-top:20px">
<div class="grid-x grid-margin-x">
<?php
//setup the order of the tile fields
$order = $tiles['details']['order'] ?? [];
foreach ( $post_settings['fields'] as $key => $option ){
if ( isset( $option['tile'] ) && $option['tile'] === 'details' ){
if ( !in_array( $key, $order ) ){
$order[] = $key;
}
}
}
foreach ( $order as $field_key ) {
if ( !isset( $post_settings['fields'][$field_key] ) ){
continue;
}
$field = $post_settings['fields'][$field_key];
$enabled_for_type = dt_field_enabled_for_record_type( $field, $dt_post );
if ( isset( $post_settings['fields'][$field_key]['hidden'] ) && true === $post_settings['fields'][$field_key]['hidden']
|| !$enabled_for_type ){
continue;
}
if ( isset( $field['tile'] ) && $field['tile'] === 'details' ){ ?>
<div class="cell small-12 medium-6">
<?php render_field_for_display( $field_key, $post_settings['fields'], $dt_post ); ?>
</div>
<?php }
}
// let the plugin add section content
do_action( 'dt_details_additional_section', 'details', $post_type );
?>
</div>
</div>
</section>
<!--
Tiles Section
-->
<div class="cell small-12">
<div class="grid-x grid-margin-x grid-margin-y grid">
<?php
foreach ( $tiles as $tile_key => $tile_options ){
if ( ( isset( $tile_options['hidden'] ) && $tile_options['hidden'] == true ) || in_array( $tile_key, [ 'details', 'status' ] ) ) {
continue;
}
if ( isset( $tile_options['display_for']['type'], $dt_post['type']['key'] ) && !in_array( $dt_post['type']['key'], $tile_options['display_for']['type'] ) ){
continue;
}
if ( !isset( $tile_options['label'] ) ) {
continue;
}
?>
<section id="<?php echo esc_html( $tile_key ) ?>" class="xlarge-6 large-12 medium-6 cell grid-item">
<div class="bordered-box" id="<?php echo esc_html( $tile_key ) ?>-tile">
<?php
//setup tile label if see by customizations
if ( isset( $tile_options['label'] ) ){ ?>
<h3 class="section-header">
<?php echo esc_html( $tile_options['label'] )?>
<button class="help-button-tile" data-tile="<?php echo esc_html( $tile_key ) ?>">
<img class="help-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/help.svg' ) ?>"/>
</button>
<button class="section-chevron chevron_down">
<img src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/chevron_down.svg' ) ?>"/>
</button>
<button class="section-chevron chevron_up">
<img src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/chevron_up.svg' ) ?>"/>
</button>
</h3>
<?php } ?>
<div class="section-body">
<?php
// let the plugin add section content
add_action( 'dt_details_additional_section', function ( $t_key, $pt ) use ( $post_type, $tile_key, $post_settings, $dt_post, $tile_options ){
if ( $pt !== $post_type || $tile_key !== $t_key ){
return;
}
//setup the order of the tile fields
$order = $tile_options['order'] ?? [];
foreach ( $post_settings['fields'] as $key => $option ){
if ( isset( $option['tile'] ) && $option['tile'] === $tile_key && !in_array( $key, $order ) ){
$order[] = $key;
}
}
foreach ( $order as $field_key ) {
if ( !isset( $post_settings['fields'][$field_key] ) ){
continue;
}
$field = $post_settings['fields'][$field_key];
if ( isset( $field['tile'] ) && $field['tile'] === $tile_key ){
render_field_for_display( $field_key, $post_settings['fields'], $dt_post, true );
}
}
}, 20, 2 );
do_action( 'dt_details_additional_section', $tile_key, $post_type );
?>
</div>
</div>
</section>
<?php }
do_action( 'dt_record_bottom_after_tiles', $post_type, $dt_post ); ?>
</div>
</div>
<?php do_action( 'dt_record_bottom_below_tiles', $post_type, $dt_post ); ?>
</div>
</main>
<aside class="auto cell grid-x">
<section class="comment-activity-section cell"
id="comment-activity-section">
<?php get_template_part( 'dt-assets/parts/loop', 'activity-comment' ); ?>
</section>
</aside>
</div>
</div>
<?php get_template_part( 'dt-assets/parts/modals/modal', 'share' ); ?>
<?php get_template_part( 'dt-assets/parts/modals/modal', 'tasks' ); ?>
<?php get_template_part( 'dt-assets/parts/modals/modal', 'new-contact' ); ?>
<div class="reveal" id="create-tag-modal" data-reveal data-reset-on-close>
<h3><?php esc_html_e( 'Create Tag', 'disciple_tools' )?></h3>
<p><?php esc_html_e( 'Create a tag and apply it to this record.', 'disciple_tools' )?></p>
<form class="js-create-tag">
<label for="title">
<?php esc_html_e( 'Tag', 'disciple_tools' ); ?>
</label>
<input name="title" id="new-tag" type="text" placeholder="<?php esc_html_e( 'Tag', 'disciple_tools' ); ?>" required aria-describedby="name-help-text">
<p class="help-text" id="name-help-text"><?php esc_html_e( 'This is required', 'disciple_tools' ); ?></p>
</form>
<div class="grid-x">
<button class="button button-cancel clear" data-close aria-label="Close reveal" type="button">
<?php echo esc_html__( 'Cancel', 'disciple_tools' )?>
</button>
<button class="button" data-close type="button" id="create-tag-return">
<?php esc_html_e( 'Create and apply tag', 'disciple_tools' ); ?>
</button>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
</div>
<div class="reveal" id="delete-record-modal" data-reveal data-reset-on-close>
<h3><?php echo esc_html( sprintf( _x( 'Delete %s', 'Delete Contact', 'disciple_tools' ), DT_Posts::get_post_settings( $post_type )['label_singular'] ) ) ?></h3>
<p><?php echo esc_html( sprintf( _x( 'Are you sure you want to delete %s?', 'Are you sure you want to delete name?', 'disciple_tools' ), $dt_post['name'] ) ) ?></p>
<div class="grid-x">
<button class="button button-cancel clear" data-close aria-label="Close reveal" type="button">
<?php echo esc_html__( 'Cancel', 'disciple_tools' )?>
</button>
<button class="button alert loader" type="button" id="delete-record">
<?php esc_html_e( 'Delete', 'disciple_tools' ); ?>
</button>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
</div>
<?php do_action( 'dt_record_footer', $post_type, $post_id ) ?>
<?php get_footer();
} )();