Skip to content

Commit 0c47818

Browse files
committed
changelog version 1.1.7 ready for released
1 parent c960a41 commit 0c47818

18 files changed

+536
-283
lines changed

README.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: codeboxr, manchumahara
33
Tags: changelog,history,release,version,product log
44
Requires at least: 5.3
55
Tested up to: 6.7.1
6-
Stable tag: 1.1.6
6+
Stable tag: 1.1.7
77
Requires PHP: 7.4
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -73,6 +73,11 @@ This helps to write changes log for any digital products, projects releases. Any
7373

7474

7575
== Changelog ==
76+
= 1.1.7 =
77+
* [fixed] Fixed the order issue in changelog edit screen
78+
* [new] Added new order by param 'id', here is release id, please note, release id and dashboard display index is not same.
79+
80+
7681
= 1.1.6 =
7782
* [new] New dashboard style
7883
* [new] Plugin check version V1.3.1 compatible

assets/css/cbxchangelog-admin.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/css/cbxchangelog-listing.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/cbxchangelog-edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105

106106
//var rendered = Mustache.render($release_template, {increment: $counter, incrementplus: ($counter + 1)});
107107
var rendered = Mustache.render($release_template, {increment: ($counter - 1), incrementplus: ($counter)});
108-
$('#cbxchangelog_wrapper').prepend(rendered);
108+
$('#cbxchangelog_wrapper').append(rendered);
109109

110110
$counter++;
111111
$this.attr('data-counter', $counter);

cbxchangelog.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Plugin Name: CBX Changelog
1717
* Plugin URI: http://codeboxr.com/product/cbx-changelog-for-wordpress/
1818
* Description: Easy change log manager for WordPress, use for any product post type or releases notes
19-
* Version: 1.1.6
19+
* Version: 1.1.7
2020
* Author: Codeboxr
2121
* Author URI: http://codeboxr.com
2222
* License: GPL-2.0+
@@ -32,7 +32,7 @@
3232

3333

3434
defined( 'CBXCHANGELOG_PLUGIN_NAME' ) or define( 'CBXCHANGELOG_PLUGIN_NAME', 'cbxchangelog' );
35-
defined( 'CBXCHANGELOG_PLUGIN_VERSION' ) or define( 'CBXCHANGELOG_PLUGIN_VERSION', '1.1.6' );
35+
defined( 'CBXCHANGELOG_PLUGIN_VERSION' ) or define( 'CBXCHANGELOG_PLUGIN_VERSION', '1.1.7' );
3636
defined( 'CBXCHANGELOG_ROOT_PATH' ) or define( 'CBXCHANGELOG_ROOT_PATH', plugin_dir_path( __FILE__ ) );
3737
defined( 'CBXCHANGELOG_ROOT_URL' ) or define( 'CBXCHANGELOG_ROOT_URL', plugin_dir_url( __FILE__ ) );
3838
defined( 'CBXCHANGELOG_BASE_NAME' ) or define( 'CBXCHANGELOG_BASE_NAME', plugin_basename( __FILE__ ) );

includes/CBXChangelogAdmin.php

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public function shortcode_metabox_display( $post ) {
268268

269269

270270
/**
271-
* Save meta box for cbxchangelog
271+
* Save meta box
272272
*
273273
* @param $post_id
274274
* @param $post
@@ -321,7 +321,8 @@ public function metabox_save( $post_id, $post, $update ) {
321321

322322
$meta_data = CBXChangelogHelper::get_changelog_data( $post_id );
323323
$used_keys = $meta_data->getUsedKeys();
324-
324+
//let's reset as we need to honor the index order to display
325+
$meta_data->resetRows();
325326

326327
foreach ( $submitted_values as $value ) {
327328
$valid_change_log = [];
@@ -333,11 +334,6 @@ public function metabox_save( $post_id, $post, $update ) {
333334
$valid_change_log['date'] = isset( $value['date'] ) ? sanitize_text_field( wp_unslash( $value['date'] ) ) : '';
334335
$valid_change_log['note'] = isset( $value['note'] ) ? sanitize_textarea_field( wp_unslash( $value['note'] ) ) : '';
335336

336-
//$valid_change_log['version'] = $version;
337-
//$valid_change_log['url'] = $url;
338-
//$valid_change_log['date'] = $date;
339-
//$valid_change_log['note'] = $note;
340-
341337
//labels
342338
if ( isset( $value['label'] ) && is_array( $value['label'] ) ) {
343339
$value['label'] = array_filter( $value['label'] );
@@ -378,15 +374,23 @@ public function metabox_save( $post_id, $post, $update ) {
378374
//end features
379375

380376
//if ( $id > 0 && in_array( $id, $used_keys ) ) {
381-
if ( $id > 0 ) {
377+
/*if ( $id > 0 ) {
382378
//update
383379
$meta_data->update( $id, $valid_change_log );
384380
} else {
385381
//add
386382
$meta_data->insert( $valid_change_log );
387383
//$used_keys = $meta_data->getUsedKeys();
384+
}*/
385+
386+
387+
if($id > 0){
388+
$valid_change_log['id'] = $id;
388389
}
389390

391+
$meta_data->insert( $valid_change_log );
392+
393+
390394
unset( $valid_change_log );
391395
//$valid_change_logs[] = $valid_change_log;
392396
}//end for each
@@ -406,9 +410,17 @@ public function metabox_save( $post_id, $post, $update ) {
406410
$extras['show_label'] = isset( $extras['show_label'] ) ? intval( $extras['show_label'] ) : 1;
407411
$extras['show_date'] = isset( $extras['show_date'] ) ? intval( $extras['show_date'] ) : 1;
408412
$extras['relative_date'] = isset( $extras['relative_date'] ) ? intval( $extras['relative_date'] ) : 0;
409-
$extras['layout'] = isset( $extras['layout'] ) ? esc_attr( wp_unslash( $extras['layout'] ) ) : 'prepros';
410-
$extras['order'] = isset( $extras['order'] ) ? esc_attr( wp_unslash( $extras['order'] ) ) : 'desc';
411-
$extras['orderby'] = isset( $extras['orderby'] ) ? esc_attr( wp_unslash( $extras['orderby'] ) ) : 'order';
413+
$extras['layout'] = isset( $extras['layout'] ) ? sanitize_text_field( wp_unslash( $extras['layout'] ) ) : 'prepros';
414+
$extras['order'] = isset( $extras['order'] ) ? sanitize_text_field( wp_unslash( $extras['order'] ) ) : 'desc';
415+
$extras['orderby'] = isset( $extras['orderby'] ) ? sanitize_text_field( wp_unslash( $extras['orderby'] ) ) : 'order'; //'order' == 'default'
416+
417+
if(!in_array($extras['orderby'], ['order', 'id', 'date'])){
418+
$extras['orderby'] = 'order';
419+
}
420+
421+
if(!in_array($extras['order'], ['desc', 'asc'])){
422+
$extras['order'] = 'desc';
423+
}
412424

413425
//now update post meta
414426
update_post_meta( $post_id, '_cbxchangelog_extra', $extras );
@@ -420,7 +432,6 @@ public function metabox_save( $post_id, $post, $update ) {
420432

421433

422434
do_action( 'cbxchangelog_meta_save', $post_id, $post, $update );
423-
424435
}//end metabox_save
425436

426437
/**
@@ -961,15 +972,16 @@ public function custom_message_after_plugin_row_proaddon( $plugin_file, $plugin_
961972
}
962973

963974
$pro_addon_version = CBXChangelogHelper::get_any_plugin_version( 'cbxchangelogpro/cbxchangelogpro.php' );
975+
$pro_latest_version = '1.1.6';
964976

965977

966-
if ( $pro_addon_version != '' && version_compare( $pro_addon_version, '1.1.6', '<' ) ) {
978+
if ( $pro_addon_version != '' && version_compare( $pro_addon_version, $pro_latest_version, '<' ) ) {
967979
// Custom message to display
968980
$plugin_manual_update = 'https://codeboxr.com/manual-update-pro-addon/';
969981

970982
/* translators:translators: %s: plugin setting url for licence */
971-
$custom_message = wp_kses( sprintf( __( '<strong>Note:</strong> CBX Changelog Pro Addon is custom plugin. This plugin can not be auto update from dashboard/plugin manager. For manual update please check <a target="_blank" href="%1$s">documentation</a>. <strong style="color: red;">It seems this plugin\'s current version is older than 1.1.6 . To get the latest pro addon features, this plugin needs to upgrade to 1.1.6 or later.</strong>', 'cbxchangelog' ),
972-
esc_url( $plugin_manual_update ) ), [ 'strong' => [ 'style' => [] ], 'a' => [ 'href' => [], 'target' => [] ] ] );
983+
$custom_message = wp_kses( sprintf( __( '<strong>Note:</strong> CBX Changelog Pro Addon is custom plugin. This plugin can not be auto update from dashboard/plugin manager. For manual update please check <a target="_blank" href="%1$s">documentation</a>. <strong style="color: red;">It seems this plugin\'s current version is older than %2$s . To get the latest pro addon features, this plugin needs to upgrade to %2$s or later.</strong>', 'cbxchangelog' ),
984+
esc_url( $plugin_manual_update ), $pro_latest_version ), [ 'strong' => [ 'style' => [] ], 'a' => [ 'href' => [], 'target' => [] ] ] );
973985

974986
// Output a row with custom content
975987
echo '<tr class="plugin-update-tr">
@@ -1165,6 +1177,11 @@ public function init_changelog_shortcode_block() {
11651177
'value' => 'order',
11661178
];
11671179

1180+
$orderby_options[] = [
1181+
'label' => esc_html__( 'Release No/ID', 'cbxchangelog' ),
1182+
'value' => 'id',
1183+
];
1184+
11681185
$orderby_options[] = [
11691186
'label' => esc_html__( 'Date', 'cbxchangelog' ),
11701187
'value' => 'date',
@@ -1301,9 +1318,14 @@ public function cbxchangelog_block_render( $attr ) {
13011318
$params['relative_date'] = ( $params['relative_date'] == 'true' ) ? 1 : 0;
13021319

13031320

1304-
$params['layout'] = isset( $attr['layout'] ) ? sanitize_text_field( $attr['layout'] ) : 'prepros';
1305-
$params['order'] = isset( $attr['order'] ) ? sanitize_text_field( $attr['order'] ) : 'desc';
1306-
$params['orderby'] = isset( $attr['orderby'] ) ? sanitize_text_field( $attr['orderby'] ) : 'default';
1321+
$params['layout'] = isset( $attr['layout'] ) ? sanitize_text_field( wp_unslash($attr['layout']) ) : 'prepros';
1322+
$params['order'] = isset( $attr['order'] ) ? sanitize_text_field( wp_unslash($attr['order']) ) : 'desc';
1323+
$params['orderby'] = isset( $attr['orderby'] ) ? sanitize_text_field( wp_unslash($attr['orderby']) ) : 'default';
1324+
1325+
if($params['orderby'] === 'order'){
1326+
$params['orderby'] = 'default';
1327+
}
1328+
13071329

13081330
$params = apply_filters( 'cbxchangelog_shortcode_builder_block_attr', $params, $attr );
13091331

includes/CBXChangelogHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ public static function get_order_keys() {
544544
*
545545
*/
546546
public static function get_orderby_keys() {
547-
return [ 'default', 'date' ];
547+
return [ 'default', 'date', 'id' ];
548548
}//end method get_orderby_keys
549549

550550
/**

includes/CBXChangelogMetaAsArray.php

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function delete($key) {
132132
}//end method delete
133133

134134
// Get all rows with optional sorting
135-
public function getAll( $orderBy = null, $order = 'asc' ) {
135+
/*public function getAll( $orderBy = null, $order = 'asc' ) {
136136
$data = $this->data;
137137
138138
// Apply sorting if column is provided
@@ -148,7 +148,39 @@ public function getAll( $orderBy = null, $order = 'asc' ) {
148148
}
149149
150150
return array_values( $data );
151-
}//end method getAll
151+
}//end method getAll*/
152+
153+
// Get paginated rows with sorting
154+
/*public function getPaginatedRows( $page = 1, $perPage = 10, $orderBy = null, $order = 'asc' ) {
155+
$data = $this->data;
156+
157+
// Apply sorting if column is provided
158+
if ( $orderBy !== null ) {
159+
usort( $data, function ( $a, $b ) use ( $orderBy, $order ) {
160+
if ( ! isset( $a[ $orderBy ] ) || ! isset( $b[ $orderBy ] ) ) {
161+
return 0; // Skip sorting if column doesn't exist
162+
}
163+
$comparison = $a[ $orderBy ] <=> $b[ $orderBy ];
164+
165+
return $order === 'desc' ? - $comparison : $comparison;
166+
} );
167+
}
168+
169+
// Paginate the data
170+
$totalRows = count( $data );
171+
$start = ( $page - 1 ) * $perPage;
172+
$paginatedData = array_slice( $data, $start, $perPage );
173+
174+
return [
175+
'data' => $paginatedData,
176+
'totalRows' => $totalRows,
177+
'currentPage' => $page,
178+
'perPage' => $perPage,
179+
'totalPages' => ceil( $totalRows / $perPage ),
180+
];
181+
}//end method getPaginatedRows*/
182+
183+
152184

153185
// Get the total number of rows
154186
public function getTotalRows() {
@@ -199,6 +231,37 @@ public function getPrevRow($key) {
199231
return null; // No previous row
200232
}//end method getPrevRow
201233

234+
// Get all rows with optional sorting
235+
public function getAll( $orderBy = null, $order = 'asc' ) {
236+
$data = $this->data;
237+
238+
// Apply sorting if column is provided
239+
if ( $orderBy !== null ) {
240+
usort( $data, function ( $a, $b ) use ( $orderBy, $order ) {
241+
if ( ! isset( $a[ $orderBy ] ) || ! isset( $b[ $orderBy ] ) ) {
242+
return 0; // Skip sorting if column doesn't exist
243+
}
244+
245+
// Check if the field is a date type
246+
$isDate = ($orderBy === 'date' || preg_match('/^\d{4}-\d{2}-\d{2}$/', $a[ $orderBy ]) && preg_match('/^\d{4}-\d{2}-\d{2}$/', $b[ $orderBy ]));
247+
248+
if ( $isDate ) {
249+
$comparison = strtotime( $a[ $orderBy ] ) <=> strtotime( $b[ $orderBy ] );
250+
} else {
251+
$comparison = $a[ $orderBy ] <=> $b[ $orderBy ];
252+
}
253+
254+
return $order === 'desc' ? - $comparison : $comparison;
255+
} );
256+
}
257+
else{
258+
// Sort by natural index if no column is provided
259+
$data = $order === 'desc' ? array_reverse( $data ) : $data;
260+
}
261+
262+
return array_values( $data );
263+
}//end method getAll
264+
202265
// Get paginated rows with sorting
203266
public function getPaginatedRows( $page = 1, $perPage = 10, $orderBy = null, $order = 'asc' ) {
204267
$data = $this->data;
@@ -209,11 +272,23 @@ public function getPaginatedRows( $page = 1, $perPage = 10, $orderBy = null, $or
209272
if ( ! isset( $a[ $orderBy ] ) || ! isset( $b[ $orderBy ] ) ) {
210273
return 0; // Skip sorting if column doesn't exist
211274
}
212-
$comparison = $a[ $orderBy ] <=> $b[ $orderBy ];
275+
276+
// Check if the field is a date type
277+
$isDate = ($orderBy === 'date' || preg_match('/^\d{4}-\d{2}-\d{2}$/', $a[ $orderBy ]) && preg_match('/^\d{4}-\d{2}-\d{2}$/', $b[ $orderBy ]));
278+
279+
if ( $isDate ) {
280+
$comparison = strtotime( $a[ $orderBy ] ) <=> strtotime( $b[ $orderBy ] );
281+
} else {
282+
$comparison = $a[ $orderBy ] <=> $b[ $orderBy ];
283+
}
213284

214285
return $order === 'desc' ? - $comparison : $comparison;
215286
} );
216287
}
288+
else{
289+
// Sort by natural index if no column is provided
290+
$data = $order === 'desc' ? array_reverse( $data ) : $data;
291+
}
217292

218293
// Paginate the data
219294
$totalRows = count( $data );
@@ -238,4 +313,12 @@ public function setPrimaryKeyFromIndex() {
238313
// Save the updated data
239314
$this->saveData();
240315
}
316+
317+
// Reset all rows and properties to their initial state
318+
public function resetRows() {
319+
$this->data = [];
320+
$this->usedKeys = [];
321+
$this->nextIndex = 1;
322+
$this->saveData();
323+
}//end method resetRows
241324
}//end class CBXChangelogMetaAsArray

0 commit comments

Comments
 (0)