Index: branches/liquidthreads/extensions/LqtExtension.php |
— | — | @@ -668,19 +668,19 @@ |
669 | 669 | $ignore_dates = ! $r->getVal('lqt_archive_filter_by_date', true); |
670 | 670 | $s = $r->getVal('lqt_archive_start'); |
671 | 671 | if ($s && ctype_digit($s) && strlen($s) == 6 && !$ignore_dates) { |
672 | | - $start = "{$s}00000000"; |
673 | | - $where[] = 'thread_touched >= ' . $start; |
| 672 | + $this->start = "{$s}00000000"; |
| 673 | + $where[] = 'thread_touched >= ' . $this->start; |
674 | 674 | } |
675 | 675 | $e = $r->getVal('lqt_archive_end'); |
676 | 676 | if ($e && ctype_digit($e) && strlen($e) == 6 && !$ignore_dates) { |
677 | | - $end = "{$e}31235959"; |
678 | | - $where[] = 'thread_touched <= ' . $end; |
| 677 | + $this->end = "{$e}31235959"; |
| 678 | + $where[] = 'thread_touched <= ' . $this->end; |
679 | 679 | } |
680 | | - if ( isset($start) && isset($end) ) { |
| 680 | + if ( isset($this->start) && isset($this->end) ) { |
681 | 681 | $annotations[] = "from $start to $end"; |
682 | | - } else if (isset($start)) { |
| 682 | + } else if (isset($this->start)) { |
683 | 683 | $annotations[] = "after $start"; |
684 | | - } else if (isset($end)) { |
| 684 | + } else if (isset($this->end)) { |
685 | 685 | $annotations[] = "before $end"; |
686 | 686 | } |
687 | 687 | |
— | — | @@ -714,6 +714,24 @@ |
715 | 715 | $result .= "</select>"; |
716 | 716 | return $result; |
717 | 717 | } |
| 718 | + |
| 719 | + /** |
| 720 | + * Return a URL for the current page, including Title and query vars, |
| 721 | + * with the given replacements made. |
| 722 | + * @param $repls array( 'name'=>new_value, ... ) |
| 723 | + */ |
| 724 | + function queryReplace( $repls ) { |
| 725 | + $vs = $this->request->getValues(); |
| 726 | + $rs = array(); |
| 727 | + foreach ($vs as $k => $v) { |
| 728 | + if ( array_key_exists( $k, $repls ) ) { |
| 729 | + $rs[$k] = $repls[$k]; |
| 730 | + } else { |
| 731 | + $rs[$k] = $vs[$k]; |
| 732 | + } |
| 733 | + } |
| 734 | + return $this->title->getFullURL($this->queryStringFromArray($rs)); |
| 735 | + } |
718 | 736 | |
719 | 737 | function showSearchForm() { |
720 | 738 | $months = Thread::monthsWhereArticleHasThreads($this->article); |
— | — | @@ -726,6 +744,25 @@ |
727 | 745 | $any_date_check = !$use_dates ? 'checked="1"' : ''; |
728 | 746 | $these_dates_check = $use_dates ? 'checked="1"' : ''; |
729 | 747 | |
| 748 | + // bcsub() and bcadd() do arithmetic on strings. |
| 749 | + // wouldn't want to overflow any puny 32-bit machines with these |
| 750 | + // giants numbers that reperesent dates. |
| 751 | + |
| 752 | + if( isset($this->start, $this->end) ) { |
| 753 | + var_dump($this->start, $this->end); |
| 754 | + $delta = bcsub($this->end, $this->start); |
| 755 | + $older_start = bcsub($this->start, $delta); |
| 756 | + $newer_start = bcadd($this->start, $delta); |
| 757 | + $older_end = bcsub($this->end, $delta); |
| 758 | + $newer_end = bcadd($this->end, $delta); |
| 759 | + } |
| 760 | + |
| 761 | + var_dump($older_start, $older_end); |
| 762 | + |
| 763 | + $older = $this->queryReplace(array('lqt_archive_filter_by_date'=>'1', |
| 764 | + 'lqt_archive_start' => substr($older_start, 0, 6), |
| 765 | + 'lqt_archive_end' => substr($older_end, 0, 6) )); |
| 766 | + |
730 | 767 | $this->output->addHTML(<<<HTML |
731 | 768 | <form id="lqt_archive_search_form" action="{$this->title->getLocalURL()}"> |
732 | 769 | <input type="hidden" name="lqt_show_archive" value="1"> |
— | — | @@ -742,6 +779,9 @@ |
743 | 780 | <label for="lqt_archive_end">End</label> |
744 | 781 | {$this->monthSelect($months, 'lqt_archive_end')} |
745 | 782 | <input type="submit"> |
| 783 | + |
| 784 | + <a href="$older">«older</a> |
| 785 | + <a href="$newer">newer»</a> |
746 | 786 | </form> |
747 | 787 | HTML |
748 | 788 | ); |