attach-file
7 months ago
additional-preview-images.php
4 years ago
attach-file.php
6 months ago
changelog.php
6 months ago
icons.php
2 weeks ago
lock-options.php
2 weeks ago
package-settings.php
2 weeks ago
changelog.php
627 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Changelog Metabox Template |
| 4 | * Displays and manages package changelog entries |
| 5 | */ |
| 6 | if (!defined('ABSPATH')) die('!'); |
| 7 | |
| 8 | $changelog = get_post_meta($post->ID, '__wpdm_changelog', true); |
| 9 | if (!is_array($changelog)) { |
| 10 | $changelog = []; |
| 11 | } |
| 12 | |
| 13 | // Sort by timestamp descending (newest first) |
| 14 | usort($changelog, function($a, $b) { |
| 15 | $ts_a = isset($a['timestamp']) ? $a['timestamp'] : 0; |
| 16 | $ts_b = isset($b['timestamp']) ? $b['timestamp'] : 0; |
| 17 | return $ts_b - $ts_a; |
| 18 | }); |
| 19 | ?> |
| 20 | |
| 21 | <style> |
| 22 | .wpdm-changelog-metabox { |
| 23 | --cl-text: #1e293b; |
| 24 | --cl-text-muted: #64748b; |
| 25 | --cl-border: #e2e8f0; |
| 26 | --cl-bg: #f8fafc; |
| 27 | --cl-radius: 4px; |
| 28 | } |
| 29 | |
| 30 | .wpdm-changelog-metabox * { |
| 31 | box-sizing: border-box; |
| 32 | } |
| 33 | |
| 34 | /* Existing Changelogs List */ |
| 35 | .wpdm-changelog-list { |
| 36 | margin-bottom: 20px; |
| 37 | } |
| 38 | |
| 39 | .wpdm-changelog-item { |
| 40 | background: #fff; |
| 41 | border: 1px solid var(--cl-border); |
| 42 | border-radius: var(--cl-radius); |
| 43 | margin-bottom: 12px; |
| 44 | overflow: hidden; |
| 45 | } |
| 46 | |
| 47 | .wpdm-changelog-header { |
| 48 | display: flex; |
| 49 | align-items: center; |
| 50 | gap: 12px; |
| 51 | padding: 12px 16px; |
| 52 | background: var(--cl-bg); |
| 53 | border-bottom: 1px solid var(--cl-border); |
| 54 | cursor: pointer; |
| 55 | } |
| 56 | |
| 57 | .wpdm-changelog-header:hover { |
| 58 | background: #f1f5f9; |
| 59 | } |
| 60 | |
| 61 | .wpdm-changelog-version { |
| 62 | display: inline-flex; |
| 63 | align-items: center; |
| 64 | gap: 4px; |
| 65 | background: var(--admin-color, #6366f1); |
| 66 | color: #fff; |
| 67 | padding: 4px 10px; |
| 68 | border-radius: 3px; |
| 69 | font-size: 12px; |
| 70 | font-weight: 600; |
| 71 | } |
| 72 | |
| 73 | .wpdm-changelog-date { |
| 74 | font-size: 13px; |
| 75 | color: var(--cl-text-muted); |
| 76 | } |
| 77 | |
| 78 | .wpdm-changelog-actions { |
| 79 | margin-left: auto; |
| 80 | display: flex; |
| 81 | gap: 6px; |
| 82 | } |
| 83 | |
| 84 | /* Action buttons (edit/delete) */ |
| 85 | .wpdm-changelog-action-btn { |
| 86 | width: 28px; |
| 87 | height: 28px; |
| 88 | padding: 0; |
| 89 | display: flex; |
| 90 | align-items: center; |
| 91 | justify-content: center; |
| 92 | background: #f8fafc; |
| 93 | border: 1px solid #e2e8f0; |
| 94 | border-radius: 6px; |
| 95 | color: #64748b; |
| 96 | cursor: pointer; |
| 97 | opacity: 0; |
| 98 | transform: scale(0.9); |
| 99 | transition: all 150ms ease; |
| 100 | } |
| 101 | |
| 102 | .wpdm-changelog-action-btn svg { |
| 103 | width: 14px; |
| 104 | height: 14px; |
| 105 | } |
| 106 | |
| 107 | .wpdm-changelog-header:hover .wpdm-changelog-action-btn { |
| 108 | opacity: 1; |
| 109 | transform: scale(1); |
| 110 | } |
| 111 | |
| 112 | .wpdm-changelog-action-btn:hover { |
| 113 | background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%); |
| 114 | border-color: #a5b4fc; |
| 115 | color: #4f46e5; |
| 116 | box-shadow: 0 2px 8px rgba(79, 70, 229, 0.15); |
| 117 | } |
| 118 | |
| 119 | .wpdm-changelog-action-btn--delete:hover { |
| 120 | background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%); |
| 121 | border-color: #fca5a5; |
| 122 | color: #dc2626; |
| 123 | box-shadow: 0 2px 8px rgba(220, 38, 38, 0.15); |
| 124 | } |
| 125 | |
| 126 | .wpdm-changelog-btn--toggle { |
| 127 | background: transparent; |
| 128 | border: none; |
| 129 | color: var(--cl-text-muted); |
| 130 | padding: 4px; |
| 131 | cursor: pointer; |
| 132 | display: flex; |
| 133 | align-items: center; |
| 134 | justify-content: center; |
| 135 | } |
| 136 | |
| 137 | .wpdm-changelog-btn--toggle svg { |
| 138 | width: 16px; |
| 139 | height: 16px; |
| 140 | transition: transform 150ms ease; |
| 141 | } |
| 142 | |
| 143 | .wpdm-changelog-item.is-collapsed .wpdm-changelog-btn--toggle svg { |
| 144 | transform: rotate(-90deg); |
| 145 | } |
| 146 | |
| 147 | .wpdm-changelog-body { |
| 148 | padding: 16px; |
| 149 | display: block; |
| 150 | } |
| 151 | |
| 152 | .wpdm-changelog-item.is-collapsed .wpdm-changelog-body { |
| 153 | display: none; |
| 154 | } |
| 155 | |
| 156 | .wpdm-changelog-content { |
| 157 | font-size: 14px; |
| 158 | line-height: 1.6; |
| 159 | color: var(--cl-text); |
| 160 | } |
| 161 | |
| 162 | .wpdm-changelog-content ul, |
| 163 | .wpdm-changelog-content ol { |
| 164 | margin: 8px 0; |
| 165 | padding-left: 20px; |
| 166 | } |
| 167 | |
| 168 | .wpdm-changelog-content li { |
| 169 | margin-bottom: 4px; |
| 170 | } |
| 171 | |
| 172 | /* Edit Form (hidden by default) */ |
| 173 | .wpdm-changelog-edit-form { |
| 174 | padding: 16px; |
| 175 | background: #fffbeb; |
| 176 | border-top: 1px solid #fef3c7; |
| 177 | display: none; |
| 178 | } |
| 179 | |
| 180 | .wpdm-changelog-item.is-editing .wpdm-changelog-edit-form { |
| 181 | display: block; |
| 182 | } |
| 183 | |
| 184 | .wpdm-changelog-item.is-editing .wpdm-changelog-body { |
| 185 | display: none; |
| 186 | } |
| 187 | |
| 188 | /* Add New Form */ |
| 189 | .wpdm-changelog-add { |
| 190 | background: #fff; |
| 191 | border: 2px dashed var(--cl-border); |
| 192 | border-radius: var(--cl-radius); |
| 193 | padding: 20px; |
| 194 | } |
| 195 | |
| 196 | .wpdm-changelog-add-title { |
| 197 | font-size: 14px; |
| 198 | font-weight: 600; |
| 199 | color: var(--cl-text); |
| 200 | margin-bottom: 16px; |
| 201 | display: flex; |
| 202 | align-items: center; |
| 203 | gap: 8px; |
| 204 | } |
| 205 | |
| 206 | .wpdm-changelog-add-title svg { |
| 207 | width: 18px; |
| 208 | height: 18px; |
| 209 | color: var(--admin-color, #6366f1); |
| 210 | } |
| 211 | |
| 212 | .wpdm-changelog-form-row { |
| 213 | display: grid; |
| 214 | grid-template-columns: 1fr 1fr; |
| 215 | gap: 12px; |
| 216 | margin-bottom: 12px; |
| 217 | } |
| 218 | |
| 219 | .wpdm-changelog-form-group { |
| 220 | display: flex; |
| 221 | flex-direction: column; |
| 222 | gap: 4px; |
| 223 | } |
| 224 | |
| 225 | .wpdm-changelog-form-group--full { |
| 226 | grid-column: 1 / -1; |
| 227 | } |
| 228 | |
| 229 | .wpdm-changelog-label { |
| 230 | font-size: 12px; |
| 231 | font-weight: 500; |
| 232 | color: var(--cl-text-muted); |
| 233 | text-transform: uppercase; |
| 234 | letter-spacing: 0.5px; |
| 235 | } |
| 236 | |
| 237 | .wpdm-changelog-metabox .form-control { |
| 238 | width: 100%; |
| 239 | } |
| 240 | |
| 241 | .wpdm-changelog-metabox textarea.form-control { |
| 242 | min-height: 120px; |
| 243 | resize: vertical; |
| 244 | } |
| 245 | |
| 246 | .wpdm-changelog-empty { |
| 247 | text-align: center; |
| 248 | padding: 24px; |
| 249 | color: var(--cl-text-muted); |
| 250 | font-size: 14px; |
| 251 | background: var(--cl-bg); |
| 252 | border-radius: var(--cl-radius); |
| 253 | margin-bottom: 20px; |
| 254 | } |
| 255 | |
| 256 | .wpdm-changelog-empty svg { |
| 257 | width: 32px; |
| 258 | height: 32px; |
| 259 | margin-bottom: 8px; |
| 260 | opacity: 0.5; |
| 261 | } |
| 262 | |
| 263 | .wpdm-changelog-hint { |
| 264 | font-size: 12px; |
| 265 | color: var(--cl-text-muted); |
| 266 | margin-top: 8px; |
| 267 | } |
| 268 | |
| 269 | .wpdm-changelog-metabox .btn i { |
| 270 | margin-right: 5px; |
| 271 | } |
| 272 | |
| 273 | .wpdm-changelog-metabox .btn-group-actions { |
| 274 | margin-top: 12px; |
| 275 | } |
| 276 | |
| 277 | @media (max-width: 782px) { |
| 278 | .wpdm-changelog-form-row { |
| 279 | grid-template-columns: 1fr; |
| 280 | } |
| 281 | } |
| 282 | </style> |
| 283 | |
| 284 | <div class="wpdm-changelog-metabox w3eden"> |
| 285 | |
| 286 | <!-- Existing Changelogs --> |
| 287 | <?php if (!empty($changelog)): ?> |
| 288 | <div class="wpdm-changelog-list"> |
| 289 | <?php foreach ($changelog as $index => $entry): |
| 290 | $entry_id = isset($entry['id']) ? $entry['id'] : 'cl_' . $index; |
| 291 | $version = isset($entry['version']) ? esc_attr($entry['version']) : ''; |
| 292 | $date = isset($entry['date']) ? esc_attr($entry['date']) : ''; |
| 293 | $changes = isset($entry['changes']) ? $entry['changes'] : ''; |
| 294 | $timestamp = isset($entry['timestamp']) ? $entry['timestamp'] : 0; |
| 295 | ?> |
| 296 | <div class="wpdm-changelog-item" data-id="<?php echo esc_attr($entry_id); ?>"> |
| 297 | <div class="wpdm-changelog-header" onclick="wpdmToggleChangelog(this)"> |
| 298 | <button type="button" class="wpdm-changelog-btn wpdm-changelog-btn--toggle"> |
| 299 | <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"> |
| 300 | <path stroke-linecap="round" stroke-linejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /> |
| 301 | </svg> |
| 302 | </button> |
| 303 | <span class="wpdm-changelog-version"> |
| 304 | <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:12px;height:12px"> |
| 305 | <path stroke-linecap="round" stroke-linejoin="round" d="M9.568 3H5.25A2.25 2.25 0 0 0 3 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 0 0 5.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 0 0 9.568 3Z" /> |
| 306 | <path stroke-linecap="round" stroke-linejoin="round" d="M6 6h.008v.008H6V6Z" /> |
| 307 | </svg> |
| 308 | v<?php echo esc_html($version); ?> |
| 309 | </span> |
| 310 | <span class="wpdm-changelog-date"><?php echo esc_html($date); ?></span> |
| 311 | <div class="wpdm-changelog-actions" onclick="event.stopPropagation()"> |
| 312 | <button type="button" class="wpdm-changelog-action-btn" onclick="wpdmEditChangelog('<?php echo esc_attr($entry_id); ?>')" title="<?php esc_attr_e('Edit', 'download-manager'); ?>"> |
| 313 | <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"> |
| 314 | <path stroke-linecap="round" stroke-linejoin="round" d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125" /> |
| 315 | </svg> |
| 316 | </button> |
| 317 | <button type="button" class="wpdm-changelog-action-btn wpdm-changelog-action-btn--delete" onclick="wpdmDeleteChangelog('<?php echo esc_attr($entry_id); ?>')" title="<?php esc_attr_e('Delete', 'download-manager'); ?>"> |
| 318 | <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"> |
| 319 | <path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" /> |
| 320 | </svg> |
| 321 | </button> |
| 322 | </div> |
| 323 | </div> |
| 324 | |
| 325 | <!-- View Mode --> |
| 326 | <div class="wpdm-changelog-body"> |
| 327 | <div class="wpdm-changelog-content"> |
| 328 | <?php echo wp_kses_post($changes); ?> |
| 329 | </div> |
| 330 | </div> |
| 331 | |
| 332 | <!-- Edit Mode --> |
| 333 | <div class="wpdm-changelog-edit-form"> |
| 334 | <div class="wpdm-changelog-form-row"> |
| 335 | <div class="wpdm-changelog-form-group"> |
| 336 | <label class="wpdm-changelog-label"><?php _e('Version', 'download-manager'); ?></label> |
| 337 | <input type="text" class="form-control wpdm-edit-version" value="<?php echo esc_attr($version); ?>" placeholder="1.0.0"> |
| 338 | </div> |
| 339 | <div class="wpdm-changelog-form-group"> |
| 340 | <label class="wpdm-changelog-label"><?php _e('Date', 'download-manager'); ?></label> |
| 341 | <input type="date" class="form-control wpdm-edit-date" value="<?php echo esc_attr($date); ?>"> |
| 342 | </div> |
| 343 | </div> |
| 344 | <div class="wpdm-changelog-form-group wpdm-changelog-form-group--full"> |
| 345 | <label class="wpdm-changelog-label"><?php _e('Changes', 'download-manager'); ?></label> |
| 346 | <textarea class="form-control wpdm-edit-changes"><?php echo esc_textarea($changes); ?></textarea> |
| 347 | </div> |
| 348 | <div class="btn-group-actions"> |
| 349 | <button type="button" class="btn btn-primary" onclick="wpdmSaveEditChangelog('<?php echo esc_attr($entry_id); ?>')"> |
| 350 | <i class="fas fa-check"></i> <?php _e('Save Changes', 'download-manager'); ?> |
| 351 | </button> |
| 352 | <button type="button" class="btn btn-secondary" onclick="wpdmCancelEditChangelog('<?php echo esc_attr($entry_id); ?>')"> |
| 353 | <?php _e('Cancel', 'download-manager'); ?> |
| 354 | </button> |
| 355 | </div> |
| 356 | </div> |
| 357 | |
| 358 | <!-- Hidden inputs for form submission --> |
| 359 | <input type="hidden" name="file[changelog][<?php echo $index; ?>][id]" value="<?php echo esc_attr($entry_id); ?>" class="wpdm-cl-id"> |
| 360 | <input type="hidden" name="file[changelog][<?php echo $index; ?>][version]" value="<?php echo esc_attr($version); ?>" class="wpdm-cl-version"> |
| 361 | <input type="hidden" name="file[changelog][<?php echo $index; ?>][date]" value="<?php echo esc_attr($date); ?>" class="wpdm-cl-date"> |
| 362 | <input type="hidden" name="file[changelog][<?php echo $index; ?>][changes]" value="<?php echo esc_attr($changes); ?>" class="wpdm-cl-changes"> |
| 363 | <input type="hidden" name="file[changelog][<?php echo $index; ?>][timestamp]" value="<?php echo esc_attr($timestamp); ?>" class="wpdm-cl-timestamp"> |
| 364 | </div> |
| 365 | <?php endforeach; ?> |
| 366 | </div> |
| 367 | <?php else: ?> |
| 368 | <div class="wpdm-changelog-empty"> |
| 369 | <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"> |
| 370 | <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z" /> |
| 371 | </svg> |
| 372 | <p><?php _e('No changelog entries yet', 'download-manager'); ?></p> |
| 373 | </div> |
| 374 | <?php endif; ?> |
| 375 | |
| 376 | <!-- Add New Changelog --> |
| 377 | <div class="wpdm-changelog-add"> |
| 378 | <div class="wpdm-changelog-add-title"> |
| 379 | <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"> |
| 380 | <path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" /> |
| 381 | </svg> |
| 382 | <?php _e('Add New Changelog Entry', 'download-manager'); ?> |
| 383 | </div> |
| 384 | |
| 385 | <div class="wpdm-changelog-form-row"> |
| 386 | <div class="wpdm-changelog-form-group"> |
| 387 | <label class="wpdm-changelog-label"><?php _e('Version', 'download-manager'); ?></label> |
| 388 | <input type="text" id="wpdm-new-cl-version" class="form-control" value="" placeholder="1.0.0"> |
| 389 | </div> |
| 390 | <div class="wpdm-changelog-form-group"> |
| 391 | <label class="wpdm-changelog-label"><?php _e('Date', 'download-manager'); ?></label> |
| 392 | <input type="date" id="wpdm-new-cl-date" class="form-control" value="<?php echo wp_date('Y-m-d'); ?>"> |
| 393 | </div> |
| 394 | </div> |
| 395 | |
| 396 | <div class="wpdm-changelog-form-group wpdm-changelog-form-group--full form-group"> |
| 397 | <label class="wpdm-changelog-label"><?php _e('Changes', 'download-manager'); ?></label> |
| 398 | <?php |
| 399 | wp_editor('', 'wpdm-new-cl-changes', array( |
| 400 | 'textarea_name' => 'wpdm_changelog_changes_temp', |
| 401 | 'textarea_rows' => 8, |
| 402 | 'media_buttons' => false, |
| 403 | 'teeny' => true, |
| 404 | 'quicktags' => array('buttons' => 'strong,em,ul,ol,li,link'), |
| 405 | 'tinymce' => array( |
| 406 | 'toolbar1' => 'bold,italic,bullist,numlist,link,unlink,undo,redo', |
| 407 | 'toolbar2' => '', |
| 408 | ), |
| 409 | )); |
| 410 | ?> |
| 411 | </div> |
| 412 | |
| 413 | <div> |
| 414 | <button type="button" class="btn btn-primary" onclick="wpdmAddChangelog()"> |
| 415 | <i class="fas fa-plus"></i> <?php _e('Add Changelog Entry', 'download-manager'); ?> |
| 416 | </button> |
| 417 | </div> |
| 418 | |
| 419 | </div> |
| 420 | |
| 421 | <!-- Hidden container for new entries (will be populated by JS) --> |
| 422 | <div id="wpdm-changelog-new-entries"></div> |
| 423 | |
| 424 | </div> |
| 425 | |
| 426 | <script> |
| 427 | (function($) { |
| 428 | 'use strict'; |
| 429 | |
| 430 | var newEntryIndex = <?php echo count($changelog); ?>; |
| 431 | var $versionField = $('input[name="file[version]"]'); |
| 432 | var $clVersionField = $('#wpdm-new-cl-version'); |
| 433 | |
| 434 | // Sync version from Package Settings |
| 435 | function syncVersion() { |
| 436 | var version = $versionField.val(); |
| 437 | if (version && !$clVersionField.data('user-modified')) { |
| 438 | $clVersionField.val(version); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | // Initial sync |
| 443 | syncVersion(); |
| 444 | |
| 445 | // Sync on version field change |
| 446 | $versionField.on('input change', syncVersion); |
| 447 | |
| 448 | // Track if user manually modified the changelog version |
| 449 | $clVersionField.on('input', function() { |
| 450 | $(this).data('user-modified', true); |
| 451 | }); |
| 452 | |
| 453 | // Toggle changelog item expand/collapse |
| 454 | window.wpdmToggleChangelog = function(header) { |
| 455 | var $item = $(header).closest('.wpdm-changelog-item'); |
| 456 | if (!$item.hasClass('is-editing')) { |
| 457 | $item.toggleClass('is-collapsed'); |
| 458 | } |
| 459 | }; |
| 460 | |
| 461 | // Edit changelog entry |
| 462 | window.wpdmEditChangelog = function(id) { |
| 463 | var $item = $('.wpdm-changelog-item[data-id="' + id + '"]'); |
| 464 | $item.removeClass('is-collapsed').addClass('is-editing'); |
| 465 | }; |
| 466 | |
| 467 | // Cancel edit |
| 468 | window.wpdmCancelEditChangelog = function(id) { |
| 469 | var $item = $('.wpdm-changelog-item[data-id="' + id + '"]'); |
| 470 | $item.removeClass('is-editing'); |
| 471 | |
| 472 | // Restore original values |
| 473 | var $hidden = $item.find('input[type="hidden"]'); |
| 474 | $item.find('.wpdm-edit-version').val($item.find('.wpdm-cl-version').val()); |
| 475 | $item.find('.wpdm-edit-date').val($item.find('.wpdm-cl-date').val()); |
| 476 | $item.find('.wpdm-edit-changes').val($item.find('.wpdm-cl-changes').val()); |
| 477 | }; |
| 478 | |
| 479 | // Save edited changelog |
| 480 | window.wpdmSaveEditChangelog = function(id) { |
| 481 | var $item = $('.wpdm-changelog-item[data-id="' + id + '"]'); |
| 482 | |
| 483 | var version = $item.find('.wpdm-edit-version').val(); |
| 484 | var date = $item.find('.wpdm-edit-date').val(); |
| 485 | var changes = $item.find('.wpdm-edit-changes').val(); |
| 486 | |
| 487 | // Update hidden fields |
| 488 | $item.find('.wpdm-cl-version').val(version); |
| 489 | $item.find('.wpdm-cl-date').val(date); |
| 490 | $item.find('.wpdm-cl-changes').val(changes); |
| 491 | |
| 492 | // Update display |
| 493 | $item.find('.wpdm-changelog-version').html( |
| 494 | '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:12px;height:12px"><path stroke-linecap="round" stroke-linejoin="round" d="M9.568 3H5.25A2.25 2.25 0 0 0 3 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 0 0 5.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 0 0 9.568 3Z" /><path stroke-linecap="round" stroke-linejoin="round" d="M6 6h.008v.008H6V6Z" /></svg> v' + $('<div>').text(version).html() |
| 495 | ); |
| 496 | $item.find('.wpdm-changelog-date').text(date); |
| 497 | $item.find('.wpdm-changelog-content').html(changes); |
| 498 | |
| 499 | $item.removeClass('is-editing'); |
| 500 | }; |
| 501 | |
| 502 | // Delete changelog entry |
| 503 | window.wpdmDeleteChangelog = function(id) { |
| 504 | if (confirm('<?php echo esc_js(__('Are you sure you want to delete this changelog entry?', 'download-manager')); ?>')) { |
| 505 | $('.wpdm-changelog-item[data-id="' + id + '"]').fadeOut(300, function() { |
| 506 | $(this).remove(); |
| 507 | reindexChangelogs(); |
| 508 | }); |
| 509 | } |
| 510 | }; |
| 511 | |
| 512 | // Helper function to get TinyMCE content |
| 513 | function getEditorContent(editorId) { |
| 514 | var content = ''; |
| 515 | if (typeof tinymce !== 'undefined' && tinymce.get(editorId)) { |
| 516 | content = tinymce.get(editorId).getContent(); |
| 517 | } else { |
| 518 | content = $('#' + editorId).val(); |
| 519 | } |
| 520 | return content.trim(); |
| 521 | } |
| 522 | |
| 523 | // Helper function to set TinyMCE content |
| 524 | function setEditorContent(editorId, content) { |
| 525 | if (typeof tinymce !== 'undefined' && tinymce.get(editorId)) { |
| 526 | tinymce.get(editorId).setContent(content); |
| 527 | } |
| 528 | $('#' + editorId).val(content); |
| 529 | } |
| 530 | |
| 531 | // Add new changelog entry |
| 532 | window.wpdmAddChangelog = function() { |
| 533 | var version = $('#wpdm-new-cl-version').val().trim(); |
| 534 | var date = $('#wpdm-new-cl-date').val(); |
| 535 | var changes = getEditorContent('wpdm-new-cl-changes'); |
| 536 | |
| 537 | if (!version) { |
| 538 | alert('<?php echo esc_js(__('Please enter a version number', 'download-manager')); ?>'); |
| 539 | $('#wpdm-new-cl-version').focus(); |
| 540 | return; |
| 541 | } |
| 542 | |
| 543 | if (!changes) { |
| 544 | alert('<?php echo esc_js(__('Please describe the changes', 'download-manager')); ?>'); |
| 545 | if (typeof tinymce !== 'undefined' && tinymce.get('wpdm-new-cl-changes')) { |
| 546 | tinymce.get('wpdm-new-cl-changes').focus(); |
| 547 | } else { |
| 548 | $('#wpdm-new-cl-changes').focus(); |
| 549 | } |
| 550 | return; |
| 551 | } |
| 552 | |
| 553 | var id = 'cl_new_' + Date.now(); |
| 554 | var timestamp = Math.floor(Date.now() / 1000); |
| 555 | |
| 556 | // Create new entry HTML |
| 557 | var html = createChangelogItemHtml(id, version, date, changes, timestamp, newEntryIndex); |
| 558 | |
| 559 | // Prepend to list or create list |
| 560 | if ($('.wpdm-changelog-list').length) { |
| 561 | $('.wpdm-changelog-list').prepend(html); |
| 562 | } else { |
| 563 | $('.wpdm-changelog-empty').replaceWith('<div class="wpdm-changelog-list">' + html + '</div>'); |
| 564 | } |
| 565 | |
| 566 | newEntryIndex++; |
| 567 | |
| 568 | // Clear form and reset version sync |
| 569 | setEditorContent('wpdm-new-cl-changes', ''); |
| 570 | $clVersionField.data('user-modified', false); |
| 571 | syncVersion(); |
| 572 | |
| 573 | // Reindex all entries |
| 574 | reindexChangelogs(); |
| 575 | }; |
| 576 | |
| 577 | function createChangelogItemHtml(id, version, date, changes, timestamp, index) { |
| 578 | var versionEscaped = $('<div>').text(version).html(); |
| 579 | var dateEscaped = $('<div>').text(date).html(); |
| 580 | |
| 581 | return '<div class="wpdm-changelog-item" data-id="' + id + '">' + |
| 582 | '<div class="wpdm-changelog-header" onclick="wpdmToggleChangelog(this)">' + |
| 583 | '<button type="button" class="wpdm-changelog-btn wpdm-changelog-btn--toggle">' + |
| 584 | '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>' + |
| 585 | '</button>' + |
| 586 | '<span class="wpdm-changelog-version">' + |
| 587 | '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width:12px;height:12px"><path stroke-linecap="round" stroke-linejoin="round" d="M9.568 3H5.25A2.25 2.25 0 0 0 3 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 0 0 5.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 0 0 9.568 3Z" /><path stroke-linecap="round" stroke-linejoin="round" d="M6 6h.008v.008H6V6Z" /></svg>' + |
| 588 | ' v' + versionEscaped + |
| 589 | '</span>' + |
| 590 | '<span class="wpdm-changelog-date">' + dateEscaped + '</span>' + |
| 591 | '<div class="wpdm-changelog-actions" onclick="event.stopPropagation()">' + |
| 592 | '<button type="button" class="wpdm-changelog-action-btn" onclick="wpdmEditChangelog(\'' + id + '\')" title="Edit"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125" /></svg></button>' + |
| 593 | '<button type="button" class="wpdm-changelog-action-btn wpdm-changelog-action-btn--delete" onclick="wpdmDeleteChangelog(\'' + id + '\')" title="Delete"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" /></svg></button>' + |
| 594 | '</div>' + |
| 595 | '</div>' + |
| 596 | '<div class="wpdm-changelog-body"><div class="wpdm-changelog-content">' + changes + '</div></div>' + |
| 597 | '<div class="wpdm-changelog-edit-form">' + |
| 598 | '<div class="wpdm-changelog-form-row">' + |
| 599 | '<div class="wpdm-changelog-form-group"><label class="wpdm-changelog-label">Version</label><input type="text" class="form-control wpdm-edit-version" value="' + versionEscaped + '"></div>' + |
| 600 | '<div class="wpdm-changelog-form-group"><label class="wpdm-changelog-label">Date</label><input type="date" class="form-control wpdm-edit-date" value="' + dateEscaped + '"></div>' + |
| 601 | '</div>' + |
| 602 | '<div class="wpdm-changelog-form-group wpdm-changelog-form-group--full"><label class="wpdm-changelog-label">Changes</label><textarea class="form-control wpdm-edit-changes">' + $('<div>').text(changes).html() + '</textarea></div>' + |
| 603 | '<div class="btn-group-actions"><button type="button" class="btn btn-primary" onclick="wpdmSaveEditChangelog(\'' + id + '\')"><i class="fas fa-check"></i> Save Changes</button> <button type="button" class="btn btn-secondary" onclick="wpdmCancelEditChangelog(\'' + id + '\')">Cancel</button></div>' + |
| 604 | '</div>' + |
| 605 | '<input type="hidden" name="file[changelog][' + index + '][id]" value="' + id + '" class="wpdm-cl-id">' + |
| 606 | '<input type="hidden" name="file[changelog][' + index + '][version]" value="' + versionEscaped + '" class="wpdm-cl-version">' + |
| 607 | '<input type="hidden" name="file[changelog][' + index + '][date]" value="' + dateEscaped + '" class="wpdm-cl-date">' + |
| 608 | '<input type="hidden" name="file[changelog][' + index + '][changes]" value="' + $('<div>').text(changes).html() + '" class="wpdm-cl-changes">' + |
| 609 | '<input type="hidden" name="file[changelog][' + index + '][timestamp]" value="' + timestamp + '" class="wpdm-cl-timestamp">' + |
| 610 | '</div>'; |
| 611 | } |
| 612 | |
| 613 | function reindexChangelogs() { |
| 614 | $('.wpdm-changelog-item').each(function(index) { |
| 615 | $(this).find('input[type="hidden"]').each(function() { |
| 616 | var name = $(this).attr('name'); |
| 617 | if (name) { |
| 618 | name = name.replace(/\[changelog\]\[\d+\]/, '[changelog][' + index + ']'); |
| 619 | $(this).attr('name', name); |
| 620 | } |
| 621 | }); |
| 622 | }); |
| 623 | } |
| 624 | |
| 625 | })(jQuery); |
| 626 | </script> |
| 627 |