blogger
Revision | b851101ac5625aadc7fee98fd7e7c6e7c605e2b9 (tree) |
---|---|
Time | 2018-03-07 03:15:10 |
Author | umorigu <umorigu@gmai...> |
Commiter | umorigu |
BugTrack/2460 Sublist of tracker_list with range(start-last)
Now tracker_list supports range format as limit parameter.
ex: limit:"101-200" means that name numbers are (101 <= x and x <=200)
@@ -602,20 +602,29 @@ class Tracker_field_past extends Tracker_field | ||
602 | 602 | function plugin_tracker_list_convert() |
603 | 603 | { |
604 | 604 | global $vars, $_title_cannotread; |
605 | - | |
606 | 605 | $config = 'default'; |
607 | 606 | $page = $refer = $vars['page']; |
608 | 607 | $field = '_page'; |
609 | 608 | $order = ''; |
610 | 609 | $list = 'list'; |
611 | 610 | $limit = NULL; |
611 | + $start_n = NULL; | |
612 | + $last_n = NULL; | |
612 | 613 | if (func_num_args()) |
613 | 614 | { |
614 | 615 | $args = func_get_args(); |
615 | 616 | switch (count($args)) |
616 | 617 | { |
617 | 618 | case 4: |
618 | - $limit = is_numeric($args[3]) ? $args[3] : $limit; | |
619 | + $range_m = null; | |
620 | + if (is_numeric($args[3])) { | |
621 | + $limit = $args[3]; | |
622 | + } else { | |
623 | + if (preg_match('#^(\d+)-(\d+)$#', $args[3], $range_m)) { | |
624 | + $start_n = intval($range_m[1]); | |
625 | + $last_n = intval($range_m[2]); | |
626 | + } | |
627 | + } | |
619 | 628 | case 3: |
620 | 629 | $order = $args[2]; |
621 | 630 | case 2: |
@@ -630,7 +639,7 @@ function plugin_tracker_list_convert() | ||
630 | 639 | $body = str_replace('$1', htmlsc($page), $_title_cannotread); |
631 | 640 | return $body; |
632 | 641 | } |
633 | - return plugin_tracker_getlist($page,$refer,$config,$list,$order,$limit); | |
642 | + return plugin_tracker_getlist($page,$refer,$config,$list,$order,$limit,$start_n,$last_n); | |
634 | 643 | } |
635 | 644 | function plugin_tracker_list_action() |
636 | 645 | { |
@@ -655,10 +664,9 @@ function plugin_tracker_list_action() | ||
655 | 664 | plugin_tracker_getlist($page,$refer,$config,$list,$order) |
656 | 665 | ); |
657 | 666 | } |
658 | -function plugin_tracker_getlist($page,$refer,$config_name,$list,$order='',$limit=NULL) | |
667 | +function plugin_tracker_getlist($page,$refer,$config_name,$list,$order='',$limit=NULL,$start_n=NULL,$last_n=NULL) | |
659 | 668 | { |
660 | 669 | global $whatsdeleted; |
661 | - | |
662 | 670 | $config = new Config('plugin/tracker/'.$config_name); |
663 | 671 | if (!$config->read()) |
664 | 672 | { |
@@ -670,13 +678,14 @@ function plugin_tracker_getlist($page,$refer,$config_name,$list,$order='',$limit | ||
670 | 678 | { |
671 | 679 | return "<p>config file '".make_pagelink($config->page.'/'.$list)."' not found.</p>"; |
672 | 680 | } |
673 | - | |
674 | 681 | $cache_enabled = defined('TRACKER_LIST_USE_CACHE') && TRACKER_LIST_USE_CACHE && |
675 | 682 | defined('JSON_UNESCAPED_UNICODE') && defined('PKWK_UTF8_ENABLE'); |
676 | - if (is_null($limit)) { | |
683 | + if (is_null($limit) && is_null($start_n)) { | |
677 | 684 | $cache_filepath = CACHE_DIR . encode($page) . '.tracker'; |
678 | 685 | } else if (pkwk_ctype_digit($limit) && 0 < $limit && $limit <= 1000) { |
679 | 686 | $cache_filepath = CACHE_DIR . encode($page) . '.' . $limit . '.tracker'; |
687 | + } else if (!is_null($start_n) && !is_null($last_n)) { | |
688 | + $cache_filepath = CACHE_DIR . encode($page) . '.' . $start_n . '-' . $last_n . '.tracker'; | |
680 | 689 | } else { |
681 | 690 | $cache_enabled = false; |
682 | 691 | } |
@@ -728,11 +737,12 @@ function plugin_tracker_getlist($page,$refer,$config_name,$list,$order='',$limit | ||
728 | 737 | if ($order === $cache_holder['order'] && |
729 | 738 | empty($tracker_list->newly_deleted_pages) && |
730 | 739 | empty($tracker_list->newly_updated_pages) && |
731 | - !$tracker_list->link_update_required) { | |
740 | + !$tracker_list->link_update_required && | |
741 | + is_null($start_n) && is_null($last_n)) { | |
732 | 742 | $result = $cache_holder['html']; |
733 | 743 | } else { |
734 | 744 | $tracker_list->sort($order); |
735 | - $result = $tracker_list->toString($limit); | |
745 | + $result = $tracker_list->toString($limit,$start_n,$last_n); | |
736 | 746 | } |
737 | 747 | if ($cache_enabled) { |
738 | 748 | $refreshed_at = time(); |
@@ -1172,7 +1182,7 @@ class Tracker_list | ||
1172 | 1182 | $script = get_base_uri(PKWK_URI_ABSOLUTE); |
1173 | 1183 | return "[[$title$arrow>$script?plugin=tracker_list&refer=$r_page&config=$r_config&list=$r_list&order=$r_order]]"; |
1174 | 1184 | } |
1175 | - function toString($limit=NULL) | |
1185 | + function toString($limit=NULL,$start_n=NULL,$last_n=NULL) | |
1176 | 1186 | { |
1177 | 1187 | global $_tracker_messages; |
1178 | 1188 |
@@ -1186,6 +1196,15 @@ class Tracker_list | ||
1186 | 1196 | array(count($this->rows),$limit), |
1187 | 1197 | $_tracker_messages['msg_limit'])."\n"; |
1188 | 1198 | $this->rows = array_splice($this->rows,0,$limit); |
1199 | + } else if (!is_null($start_n) && !is_null($last_n)) { | |
1200 | + // sublist (range "start-last") | |
1201 | + $sublist = array(); | |
1202 | + foreach ($this->rows as $row) { | |
1203 | + if ($start_n <= $row['_real'] && $row['_real'] <= $last_n) { | |
1204 | + $sublist[] = $row; | |
1205 | + } | |
1206 | + } | |
1207 | + $this->rows = $sublist; | |
1189 | 1208 | } |
1190 | 1209 | if (count($this->rows) == 0) |
1191 | 1210 | { |