| 1 |
<?php |
| 2 |
// ====== |
| 3 |
// INIT |
| 4 |
// ====== |
| 5 |
|
| 6 |
$availablePages = get_pages(); |
| 7 |
$new_group = false; |
| 8 |
if (empty($props['list_info'])) { |
| 9 |
$props['programs'] = []; |
| 10 |
$networkInfo['link_page_list'] = ''; |
| 11 |
$new_group = true; |
| 12 |
} |
| 13 |
|
| 14 |
// ============= |
| 15 |
// FORM FIELDS |
| 16 |
// ============= |
| 17 |
|
| 18 |
$formId = $new_group ? 'createForm' : 'editForm'; |
| 19 |
$titleName = $new_group ? 'newListTitle' : 'editListTitle'; |
| 20 |
$descName = $new_group ? 'newListDescription' : 'editListDescription'; |
| 21 |
$titleValue = $new_group ? '' : esc_attr(stripslashes($props['list_info']['list_title'])); |
| 22 |
$descValue = $new_group ? '' : esc_html(stripslashes($props['list_info']['list_description'])); |
| 23 |
|
| 24 |
// resolve page link from map |
| 25 |
$networkMap = get_option('powerpress_network_map', []); |
| 26 |
$listMapKey = 'l-' . ($networkInfo['list_id'] ?? ''); |
| 27 |
$linkedPageId = $networkMap[$listMapKey] ?? 0; |
| 28 |
$pageLink = '(not set)'; |
| 29 |
$hasPageLink = false; |
| 30 |
if ($linkedPageId && get_post_status($linkedPageId) === 'publish') { |
| 31 |
$pageLink = get_permalink($linkedPageId); |
| 32 |
$hasPageLink = true; |
| 33 |
} |
| 34 |
|
| 35 |
// ========== |
| 36 |
// BACK URL |
| 37 |
// ========== |
| 38 |
|
| 39 |
$backPage = urlencode(powerpress_admin_get_page()); |
| 40 |
$backUrl = admin_url("admin.php?page={$backPage}&status=Select+Choice&tab=groups"); |
| 41 |
|
| 42 |
// ================ |
| 43 |
// SHOWS IN GROUP |
| 44 |
// ================ |
| 45 |
|
| 46 |
$checkedShows = []; |
| 47 |
foreach ($props['programs'] as $i => $program) { |
| 48 |
$mapKey = "p-{$program['program_id']}"; |
| 49 |
$link = null; |
| 50 |
$pageMissing = false; |
| 51 |
if (isset($networkMap[$mapKey])) { |
| 52 |
if (get_post_status($networkMap[$mapKey]) === 'publish') { |
| 53 |
$link = get_permalink($networkMap[$mapKey]); |
| 54 |
} else { |
| 55 |
$pageMissing = true; |
| 56 |
} |
| 57 |
} |
| 58 |
$props['programs'][$i]['link'] = $link; |
| 59 |
|
| 60 |
if (!empty($program['checked'])) { |
| 61 |
$checkedShows[] = [ |
| 62 |
'title' => $program['program_title'], |
| 63 |
'program_id' => $program['program_id'], |
| 64 |
'has_page' => !empty($link), |
| 65 |
'page_missing' => $pageMissing, |
| 66 |
'link' => $link, |
| 67 |
]; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
// sort programs w/o page to top |
| 72 |
usort($checkedShows, function($a, $b) { |
| 73 |
return $a['has_page'] - $b['has_page']; |
| 74 |
}); |
| 75 |
|
| 76 |
?> |
| 77 |
|
| 78 |
<!-- ============= |
| 79 |
PAGE HEADER |
| 80 |
============= --> |
| 81 |
|
| 82 |
<div class="ppn-page-header"> |
| 83 |
<div> |
| 84 |
<h1 class="ppn-page-title"><?php esc_html_e('Podcast Network', 'powerpress');?></h1> |
| 85 |
<h4 class="ppn-page-subtitle"><?php esc_html_e('Build and manage your podcast network.','powerpress');?></h4> |
| 86 |
</div> |
| 87 |
</div> |
| 88 |
|
| 89 |
<div class="tabs-container"> |
| 90 |
<form method="POST" action="#/" id="manageForm"> <!-- Make sure to keep back slash there for WordPress --> |
| 91 |
|
| 92 |
</form> |
| 93 |
|
| 94 |
<!-- ===================== |
| 95 |
GROUP SETTINGS FORM |
| 96 |
===================== --> |
| 97 |
|
| 98 |
<div class="row"> |
| 99 |
<div class="col-md-6"> |
| 100 |
<div class="flex-row p-2 d-block"> |
| 101 |
<h2 class="ppn-manage__section-title m-0 p-2">Edit Group</h2> |
| 102 |
<h4 class="ppn-manage__section-desc p-2"><?php esc_html_e('Group shows together and showcase them on one page.', 'powerpress');?></h4> |
| 103 |
</div> |
| 104 |
<div class="settingBox w-100"> |
| 105 |
<form method="POST" action="#/" id="<?php echo $formId; ?>"> |
| 106 |
|
| 107 |
<h4 class="ppn-manage__field-label"><?php esc_html_e('Group Name', 'powerpress');?></h4> |
| 108 |
<input id="editListTitle" name="<?php echo $titleName; ?>" type="text" value="<?php echo $titleValue; ?>" class="ppn-manage__page-link"> |
| 109 |
|
| 110 |
<h4 class="ppn-manage__field-label"><?php esc_html_e('Group Description', 'powerpress');?></h4> |
| 111 |
<textarea id="editListDescription" name="<?php echo $descName; ?>" rows="4" maxlength="500" class="ppn-manage__page-link"><?php echo $descValue; ?></textarea> |
| 112 |
<p class="description" style="color: #999;"><?php esc_html_e('500 character limit', 'powerpress'); ?></p> |
| 113 |
|
| 114 |
<?php if (!$new_group) { ?> |
| 115 |
<h4 class="ppn-manage__field-label"><?php esc_html_e('Group Page Link', 'powerpress'); ?></h4> |
| 116 |
<div id="ppn-page-link-row" class="ppn-page-link-row"> |
| 117 |
<input id="ppn-page-link-input" class="ppn-manage__page-link" type="text" value="<?php echo $pageLink; ?>" readonly> |
| 118 |
<?php if ($hasPageLink) { ?> |
| 119 |
<a href="<?php echo esc_url($pageLink); ?>" target="_blank" class="ppn-page-link-view" title="<?php esc_attr_e('View page', 'powerpress'); ?>"><i class="material-icons-outlined">open_in_new</i></a> |
| 120 |
<a href="<?php echo esc_url(get_edit_post_link($linkedPageId)); ?>" target="_blank" class="ppn-page-link-view" title="<?php esc_attr_e('Edit page', 'powerpress'); ?>"><i class="material-icons-outlined">edit</i></a> |
| 121 |
<?php } ?> |
| 122 |
</div> |
| 123 |
<div class="d-flex gap-sm" style="margin-top: 8px;"> |
| 124 |
<?php if ($hasPageLink) { ?> |
| 125 |
<button id="ppn-link-page-btn" type="button" class="button" data-ppn-action="ppnDialog" data-ppn-dialog="selectPageBox"><?php esc_html_e('Change Page', 'powerpress'); ?></button> |
| 126 |
<button type="submit" form="unlinkPageForm" class="button ppn-button-danger" onclick="return confirm('<?php $listTitle = esc_js($props['list_info']['list_title']); echo esc_js("Are you sure you want to unlink this page from {$listTitle}?"); ?>')"><?php esc_html_e('Unlink Page', 'powerpress'); ?></button> |
| 127 |
<?php } else { ?> |
| 128 |
<button id="ppn-link-page-btn" type="button" class="button" data-ppn-action="ppnDialog" data-ppn-dialog="selectPageBox"><?php esc_html_e('Add Page', 'powerpress'); ?></button> |
| 129 |
<?php } ?> |
| 130 |
</div> |
| 131 |
<input id="requestAction" name="requestAction" value="save" hidden> |
| 132 |
<?php } ?> |
| 133 |
|
| 134 |
<!-- ================= |
| 135 |
ADD SHOWS MODAL |
| 136 |
================= --> |
| 137 |
|
| 138 |
<dialog id="programBox" class="ppn-dialog ppn-dialog--lg"> |
| 139 |
<button type="button" class="ppn-dialog__close" data-ppn-action="ppnDialogClose" aria-label="<?php esc_attr_e('Close', 'powerpress'); ?>"><i class="material-icons-outlined">close</i></button> |
| 140 |
<h4 class="ppn-manage__field-label"><?php esc_html_e('Add Shows', 'powerpress'); ?></h4> |
| 141 |
|
| 142 |
<input type="text" id="showSearchInput" class="ppn-manage__page-link mb-2" placeholder="Search shows..." data-ppn-action="filterShows"> |
| 143 |
|
| 144 |
<div class="well-z-depth-1 ppn-manage__scroll-box ppn-manage__scroll-box--modal"> |
| 145 |
<div id="showsTable"> |
| 146 |
<?php for ($i = 0; $i < count($props['programs']); ++$i) { ?> |
| 147 |
<div class="show-row" data-title="<?php echo esc_attr(strtolower($props['programs'][$i]['program_title'])); ?>"> |
| 148 |
<label class="ppn-show-row-label"> |
| 149 |
<input name="program[<?php echo $i; ?>]" class="program" type="checkbox" |
| 150 |
value="<?php echo esc_attr($props['programs'][$i]['program_id']); ?>" |
| 151 |
<?php if ($props['programs'][$i]['checked']) echo ' checked'; ?> |
| 152 |
data-ppn-action="updateListOfShows" |
| 153 |
data-title="<?php echo esc_attr($props['programs'][$i]['program_title']); ?>" |
| 154 |
data-program-id="<?php echo esc_attr($props['programs'][$i]['program_id']); ?>" |
| 155 |
data-has-page="<?php echo !empty($props['programs'][$i]['link']) ? '1' : '0'; ?>"> |
| 156 |
<span class="ppn-manage__show-name" title="<?php echo esc_attr($props['programs'][$i]['program_title']); ?>"><?php echo esc_html($props['programs'][$i]['program_title']); ?></span> |
| 157 |
</label> |
| 158 |
</div> |
| 159 |
<?php } ?> |
| 160 |
</div> |
| 161 |
</div> |
| 162 |
|
| 163 |
<div class="text-right mt-2"> |
| 164 |
<button type="button" class="button button-primary" data-ppn-action="ppnDialogClose"><?php esc_html_e('Done', 'powerpress');?></button> |
| 165 |
</div> |
| 166 |
</dialog> |
| 167 |
|
| 168 |
</form> |
| 169 |
<?php if (!$new_group) { ?> |
| 170 |
<form method="POST" id="unlinkPageForm" action="<?php echo esc_url("?page=" . urlencode(powerpress_admin_get_page()) . "&status=Manage+List&tab=groups"); ?>"> |
| 171 |
<input type="hidden" name="target" value="List" /> |
| 172 |
<input type="hidden" name="targetId" value="<?php echo esc_attr($networkInfo['list_id']); ?>" /> |
| 173 |
<input type="hidden" name="redirectUrl" value="false" /> |
| 174 |
<input type="hidden" name="pageAction" value="unlink" /> |
| 175 |
<?php wp_nonce_field('powerpress', '_ppn_nonce'); ?> |
| 176 |
</form> |
| 177 |
<?php } ?> |
| 178 |
</div> |
| 179 |
</div> |
| 180 |
|
| 181 |
<div class="col-md-6"> |
| 182 |
<?php if (!$new_group) { ?> |
| 183 |
<div class="settingBox w-100 d-flex pp-flex-col ppn-manage__shows-panel"> |
| 184 |
<h4 class="ppn-manage__field-label"><?php esc_html_e('Shows in Group', 'powerpress');?></h4> |
| 185 |
<p class="description"><?php esc_html_e('Shows need a linked page to appear in the grid. If a show is missing from the front end, make sure it has a published page assigned.', 'powerpress'); ?></p> |
| 186 |
<div class="well-z-depth-1 pp-flex-1 ppn-manage__scroll-box" style="overflow-y: auto;"> |
| 187 |
<ul id="shows-in-group" class="ppn-manage__show-list"> |
| 188 |
<?php if (empty($checkedShows)) { ?> |
| 189 |
<li class="ppn-manage__show-item--empty"><?php esc_html_e('No shows in this group yet', 'powerpress'); ?></li> |
| 190 |
<?php } else { ?> |
| 191 |
<?php foreach ($checkedShows as $show) { ?> |
| 192 |
<li class="ppn-manage__show-item" data-title="<?php echo esc_attr($show['title']); ?>"> |
| 193 |
<?php echo esc_html($show['title']); ?> |
| 194 |
|
| 195 |
<?php if ($show['page_missing']): // linked page no longer published (draft/trash) ?> |
| 196 |
<span id="ppn-show-status-<?php echo esc_attr($show['program_id']); ?>" class="ppn-page-status" style="margin-left: auto;"> |
| 197 |
<button type="button" |
| 198 |
class="ppn-page-status--action" |
| 199 |
data-ppn-action="ppnPageAction" |
| 200 |
data-mode="group" |
| 201 |
data-target="Program" |
| 202 |
data-id="<?php echo esc_attr($show['program_id']); ?>" |
| 203 |
data-title="<?php echo esc_attr($show['title']); ?>"> |
| 204 |
<?php esc_html_e('Create Page', 'powerpress'); ?> |
| 205 |
</button> |
| 206 |
</span> |
| 207 |
<?php elseif (!$show['has_page']): // no page ever created ?> |
| 208 |
<span id="ppn-show-status-<?php echo esc_attr($show['program_id']); ?>" class="ppn-page-status" style="margin-left: auto;"> |
| 209 |
<button type="button" |
| 210 |
class="ppn-page-status--action" |
| 211 |
data-ppn-action="ppnPageAction" |
| 212 |
data-mode="group" |
| 213 |
data-target="Program" |
| 214 |
data-id="<?php echo esc_attr($show['program_id']); ?>" |
| 215 |
data-title="<?php echo esc_attr($show['title']); ?>"> |
| 216 |
<?php esc_html_e('Create Page', 'powerpress'); ?> |
| 217 |
</button> |
| 218 |
</span> |
| 219 |
<?php elseif ($show['link']): ?> |
| 220 |
<span class="ppn-page-status" style="margin-left: auto;"> |
| 221 |
<a class="ppn-page-status--linked" target="_blank" href="<?php echo esc_url($show['link']); ?>"> |
| 222 |
<?php esc_html_e('View Page', 'powerpress'); ?> |
| 223 |
</a> |
| 224 |
</span> |
| 225 |
<?php endif; ?> |
| 226 |
</li> |
| 227 |
<?php } ?> |
| 228 |
<?php } ?> |
| 229 |
</ul> |
| 230 |
</div> |
| 231 |
</div> |
| 232 |
<div class="pl-4"> |
| 233 |
<button type="button" class="button" data-ppn-action="ppnDialog" data-ppn-dialog="programBox"> |
| 234 |
<?php esc_html_e('Manage Shows', 'powerpress'); ?> |
| 235 |
</button> |
| 236 |
</div> |
| 237 |
|
| 238 |
<?php } else { ?> |
| 239 |
<div class="settingBox w-100"> |
| 240 |
<h4 class="ppn-manage__field-label"><?php esc_html_e('About Groups', 'powerpress');?></h4> |
| 241 |
<p class="description"><?php esc_html_e('Groups let you organize shows for showcasing and display on your network site. After creating a group you can add shows and link it to a page. The group page will display your show(s) podcast artwork grid.', 'powerpress'); ?></p> |
| 242 |
<h4 class="ppn-manage__field-label" style="margin-top: 16px;"><?php esc_html_e('Available Shortcodes', 'powerpress');?></h4> |
| 243 |
<p class="description"><code>[ppn-gridview id="{group_id}" rows="100" cols="3"]</code><br><?php esc_html_e('Show artwork in a grid layout.', 'powerpress'); ?></p> |
| 244 |
<p class="description"><code>[ppn-list id="{group_id}" style="detailed"]</code><br><?php esc_html_e('Show a detailed list with artwork and descriptions.', 'powerpress'); ?></p> |
| 245 |
<p class="description"><code>[ppn-list id="{group_id}"]</code><br><?php esc_html_e('Show a simple list of show titles.', 'powerpress'); ?></p> |
| 246 |
</div> |
| 247 |
<?php } ?> |
| 248 |
</div> |
| 249 |
</div> |
| 250 |
|
| 251 |
<!-- ============ |
| 252 |
ACTION BAR |
| 253 |
============ --> |
| 254 |
|
| 255 |
<div class="flex-row d-flex justify-content-end gap-md p-3 align-items-center"> |
| 256 |
<span id="ppn-unsaved-indicator" class="ppn-unsaved-indicator" style="display: none;"><?php esc_html_e('Unsaved changes', 'powerpress'); ?></span> |
| 257 |
<a href="<?php echo esc_url($backUrl); ?>" class="button"> |
| 258 |
<?php esc_html_e('Back', 'powerpress');?> |
| 259 |
</a> |
| 260 |
<button type="button" class="button button-primary" data-ppn-action="ppnAction" data-form="<?php echo $formId; ?>" data-navigate="Manage List" data-change="true"> |
| 261 |
<?php esc_html_e('Save Group', 'powerpress');?> |
| 262 |
</button> |
| 263 |
</div> |
| 264 |
|
| 265 |
<!-- ==================== |
| 266 |
PAGE SELECT DIALOG |
| 267 |
==================== --> |
| 268 |
|
| 269 |
<?php if ( !$new_group ) : ?> |
| 270 |
<?php |
| 271 |
powerpress_render_network_page_select([ |
| 272 |
'form_id' => 'pageForm', |
| 273 |
'shortcode_id' => 'ppn-list-shortcode', |
| 274 |
'shortcode' => "[ppn-gridview id=\"{$networkInfo['list_id']}\" rows=\"100\" cols=\"3\"]", |
| 275 |
'target' => 'List', |
| 276 |
'target_id' => $networkInfo['list_id'], |
| 277 |
'create_id' => $networkInfo['list_id'], |
| 278 |
'create_title' => $props['list_info']['list_title'], |
| 279 |
'selected_page' => $linkedPageId, |
| 280 |
'edit_url' => $hasPageLink ? get_edit_post_link($linkedPageId) : '', |
| 281 |
'pages' => $availablePages, |
| 282 |
]); |
| 283 |
?> |
| 284 |
|
| 285 |
<?php endif; ?> |
| 286 |
|
| 287 |
<div class="clear"></div> |
| 288 |
<form method="POST" action="#/" id="manageForm"> <!-- Make sure to keep back slash there for WordPress --> |
| 289 |
</form> |
| 290 |
</div> |
| 291 |
|