@@ -105,7 +105,7 @@ |
||
105 | 105 | * @param Process $process The Process |
106 | 106 | * @param callable|null $callback A PHP callable |
107 | 107 | * |
108 | - * @return callable |
|
108 | + * @return \Closure |
|
109 | 109 | */ |
110 | 110 | public function wrapCallback(OutputInterface $output, Process $process, $callback = null) |
111 | 111 | { |
@@ -113,7 +113,7 @@ |
||
113 | 113 | |
114 | 114 | $that = $this; |
115 | 115 | |
116 | - return function ($type, $buffer) use ($output, $process, $callback, $formatter, $that) { |
|
116 | + return function($type, $buffer) use ($output, $process, $callback, $formatter, $that) { |
|
117 | 117 | $output->write($formatter->progress(spl_object_hash($process), $that->escapeString($buffer), Process::ERR === $type)); |
118 | 118 | |
119 | 119 | if (null !== $callback) { |
@@ -138,6 +138,9 @@ discard block |
||
138 | 138 | return isset(self::$formats[$name]) ? self::$formats[$name] : null; |
139 | 139 | } |
140 | 140 | |
141 | + /** |
|
142 | + * @param string $message |
|
143 | + */ |
|
141 | 144 | public function setMessage($message, $name = 'message') |
142 | 145 | { |
143 | 146 | $this->messages[$name] = $message; |
@@ -473,6 +476,7 @@ discard block |
||
473 | 476 | * Sets the progress bar maximal steps. |
474 | 477 | * |
475 | 478 | * @param int The progress bar max steps |
479 | + * @param integer $max |
|
476 | 480 | */ |
477 | 481 | private function setMaxSteps($max) |
478 | 482 | { |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | $self = $this; |
437 | 437 | $output = $this->output; |
438 | 438 | $messages = $this->messages; |
439 | - $this->overwrite(preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) use ($self, $output, $messages) { |
|
439 | + $this->overwrite(preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function($matches) use ($self, $output, $messages) { |
|
440 | 440 | if ($formatter = $self::getPlaceholderFormatterDefinition($matches[1])) { |
441 | 441 | $text = call_user_func($formatter, $self, $output); |
442 | 442 | } elseif (isset($messages[$matches[1]])) { |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | private static function initPlaceholderFormatters() |
539 | 539 | { |
540 | 540 | return array( |
541 | - 'bar' => function (ProgressBar $bar, OutputInterface $output) { |
|
541 | + 'bar' => function(ProgressBar $bar, OutputInterface $output) { |
|
542 | 542 | $completeBars = floor($bar->getMaxSteps() > 0 ? $bar->getProgressPercent() * $bar->getBarWidth() : $bar->getProgress() % $bar->getBarWidth()); |
543 | 543 | $display = str_repeat($bar->getBarCharacter(), $completeBars); |
544 | 544 | if ($completeBars < $bar->getBarWidth()) { |
@@ -548,10 +548,10 @@ discard block |
||
548 | 548 | |
549 | 549 | return $display; |
550 | 550 | }, |
551 | - 'elapsed' => function (ProgressBar $bar) { |
|
551 | + 'elapsed' => function(ProgressBar $bar) { |
|
552 | 552 | return Helper::formatTime(time() - $bar->getStartTime()); |
553 | 553 | }, |
554 | - 'remaining' => function (ProgressBar $bar) { |
|
554 | + 'remaining' => function(ProgressBar $bar) { |
|
555 | 555 | if (!$bar->getMaxSteps()) { |
556 | 556 | throw new \LogicException('Unable to display the remaining time if the maximum number of steps is not set.'); |
557 | 557 | } |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | |
565 | 565 | return Helper::formatTime($remaining); |
566 | 566 | }, |
567 | - 'estimated' => function (ProgressBar $bar) { |
|
567 | + 'estimated' => function(ProgressBar $bar) { |
|
568 | 568 | if (!$bar->getMaxSteps()) { |
569 | 569 | throw new \LogicException('Unable to display the estimated time if the maximum number of steps is not set.'); |
570 | 570 | } |
@@ -577,16 +577,16 @@ discard block |
||
577 | 577 | |
578 | 578 | return Helper::formatTime($estimated); |
579 | 579 | }, |
580 | - 'memory' => function (ProgressBar $bar) { |
|
580 | + 'memory' => function(ProgressBar $bar) { |
|
581 | 581 | return Helper::formatMemory(memory_get_usage(true)); |
582 | 582 | }, |
583 | - 'current' => function (ProgressBar $bar) { |
|
583 | + 'current' => function(ProgressBar $bar) { |
|
584 | 584 | return str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', STR_PAD_LEFT); |
585 | 585 | }, |
586 | - 'max' => function (ProgressBar $bar) { |
|
586 | + 'max' => function(ProgressBar $bar) { |
|
587 | 587 | return $bar->getMaxSteps(); |
588 | 588 | }, |
589 | - 'percent' => function (ProgressBar $bar) { |
|
589 | + 'percent' => function(ProgressBar $bar) { |
|
590 | 590 | return floor($bar->getProgressPercent() * 100); |
591 | 591 | }, |
592 | 592 | ); |
@@ -49,6 +49,9 @@ |
||
49 | 49 | require_once self::$fixturesPath.'/FooSubnamespaced2Command.php'; |
50 | 50 | } |
51 | 51 | |
52 | + /** |
|
53 | + * @param string $text |
|
54 | + */ |
|
52 | 55 | protected function normalizeLineBreaks($text) |
53 | 56 | { |
54 | 57 | return str_replace(PHP_EOL, "\n", $text); |
@@ -708,8 +708,8 @@ discard block |
||
708 | 708 | $application = $this->getMock('Symfony\Component\Console\Application', array('doRun')); |
709 | 709 | $application->setAutoExit(false); |
710 | 710 | $application->expects($this->once()) |
711 | - ->method('doRun') |
|
712 | - ->will($this->throwException($exception)); |
|
711 | + ->method('doRun') |
|
712 | + ->will($this->throwException($exception)); |
|
713 | 713 | |
714 | 714 | $exitCode = $application->run(new ArrayInput(array()), new NullOutput()); |
715 | 715 | |
@@ -723,8 +723,8 @@ discard block |
||
723 | 723 | $application = $this->getMock('Symfony\Component\Console\Application', array('doRun')); |
724 | 724 | $application->setAutoExit(false); |
725 | 725 | $application->expects($this->once()) |
726 | - ->method('doRun') |
|
727 | - ->will($this->throwException($exception)); |
|
726 | + ->method('doRun') |
|
727 | + ->will($this->throwException($exception)); |
|
728 | 728 | |
729 | 729 | $exitCode = $application->run(new ArrayInput(array()), new NullOutput()); |
730 | 730 |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | $application->expects($this->any()) |
563 | 563 | ->method('getTerminalWidth') |
564 | 564 | ->will($this->returnValue(120)); |
565 | - $application->register('foo')->setCode(function () { |
|
565 | + $application->register('foo')->setCode(function() { |
|
566 | 566 | throw new \Exception('エラーメッセージ'); |
567 | 567 | }); |
568 | 568 | $tester = new ApplicationTester($application); |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | $application->expects($this->any()) |
579 | 579 | ->method('getTerminalWidth') |
580 | 580 | ->will($this->returnValue(32)); |
581 | - $application->register('foo')->setCode(function () { |
|
581 | + $application->register('foo')->setCode(function() { |
|
582 | 582 | throw new \Exception('コマンドの実行中にエラーが発生しました。'); |
583 | 583 | }); |
584 | 584 | $tester = new ApplicationTester($application); |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | $application |
744 | 744 | ->register('foo') |
745 | 745 | ->setDefinition(array($def)) |
746 | - ->setCode(function (InputInterface $input, OutputInterface $output) {}) |
|
746 | + ->setCode(function(InputInterface $input, OutputInterface $output) {}) |
|
747 | 747 | ; |
748 | 748 | |
749 | 749 | $input = new ArrayInput(array('command' => 'foo')); |
@@ -878,7 +878,7 @@ discard block |
||
878 | 878 | $application->setAutoExit(false); |
879 | 879 | $application->setDispatcher($this->getDispatcher()); |
880 | 880 | |
881 | - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { |
|
881 | + $application->register('foo')->setCode(function(InputInterface $input, OutputInterface $output) { |
|
882 | 882 | $output->write('foo.'); |
883 | 883 | }); |
884 | 884 | |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | $application->setAutoExit(false); |
899 | 899 | $application->setCatchExceptions(false); |
900 | 900 | |
901 | - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { |
|
901 | + $application->register('foo')->setCode(function(InputInterface $input, OutputInterface $output) { |
|
902 | 902 | throw new \RuntimeException('foo'); |
903 | 903 | }); |
904 | 904 | |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | $application->setDispatcher($this->getDispatcher()); |
913 | 913 | $application->setAutoExit(false); |
914 | 914 | |
915 | - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { |
|
915 | + $application->register('foo')->setCode(function(InputInterface $input, OutputInterface $output) { |
|
916 | 916 | $output->write('foo.'); |
917 | 917 | |
918 | 918 | throw new \RuntimeException('foo'); |
@@ -929,7 +929,7 @@ discard block |
||
929 | 929 | $application->setDispatcher($this->getDispatcher(true)); |
930 | 930 | $application->setAutoExit(false); |
931 | 931 | |
932 | - $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { |
|
932 | + $application->register('foo')->setCode(function(InputInterface $input, OutputInterface $output) { |
|
933 | 933 | $output->write('foo.'); |
934 | 934 | }); |
935 | 935 | |
@@ -957,21 +957,21 @@ discard block |
||
957 | 957 | protected function getDispatcher($skipCommand = false) |
958 | 958 | { |
959 | 959 | $dispatcher = new EventDispatcher(); |
960 | - $dispatcher->addListener('console.command', function (ConsoleCommandEvent $event) use ($skipCommand) { |
|
960 | + $dispatcher->addListener('console.command', function(ConsoleCommandEvent $event) use ($skipCommand) { |
|
961 | 961 | $event->getOutput()->write('before.'); |
962 | 962 | |
963 | 963 | if ($skipCommand) { |
964 | 964 | $event->disableCommand(); |
965 | 965 | } |
966 | 966 | }); |
967 | - $dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use ($skipCommand) { |
|
967 | + $dispatcher->addListener('console.terminate', function(ConsoleTerminateEvent $event) use ($skipCommand) { |
|
968 | 968 | $event->getOutput()->write('after.'); |
969 | 969 | |
970 | 970 | if (!$skipCommand) { |
971 | 971 | $event->setExitCode(113); |
972 | 972 | } |
973 | 973 | }); |
974 | - $dispatcher->addListener('console.exception', function (ConsoleExceptionEvent $event) { |
|
974 | + $dispatcher->addListener('console.exception', function(ConsoleExceptionEvent $event) { |
|
975 | 975 | $event->getOutput()->writeln('caught.'); |
976 | 976 | |
977 | 977 | $event->setException(new \LogicException('caught.', $event->getExitCode(), $event->getException())); |
@@ -177,6 +177,9 @@ |
||
177 | 177 | $this->assertEquals('not yet', $dialog->ask($this->getOutputStream(), 'Do you have a job?', 'not yet')); |
178 | 178 | } |
179 | 179 | |
180 | + /** |
|
181 | + * @param string $input |
|
182 | + */ |
|
180 | 183 | protected function getInputStream($input) |
181 | 184 | { |
182 | 185 | $stream = fopen('php://memory', 'r+', false); |
@@ -144,7 +144,7 @@ |
||
144 | 144 | |
145 | 145 | $question = 'What color was the white horse of Henry IV?'; |
146 | 146 | $error = 'This is not a color!'; |
147 | - $validator = function ($color) use ($error) { |
|
147 | + $validator = function($color) use ($error) { |
|
148 | 148 | if (!in_array($color, array('white', 'black'))) { |
149 | 149 | throw new \InvalidArgumentException($error); |
150 | 150 | } |
@@ -217,6 +217,9 @@ |
||
217 | 217 | |
218 | 218 | protected $lastMessagesLength; |
219 | 219 | |
220 | + /** |
|
221 | + * @param string $expected |
|
222 | + */ |
|
220 | 223 | protected function generateOutput($expected) |
221 | 224 | { |
222 | 225 | $expectedout = $expected; |
@@ -148,7 +148,7 @@ |
||
148 | 148 | { |
149 | 149 | $progress = $this->getMock('Symfony\Component\Console\Helper\ProgressHelper', array('display')); |
150 | 150 | $progress->expects($this->exactly(4)) |
151 | - ->method('display'); |
|
151 | + ->method('display'); |
|
152 | 152 | |
153 | 153 | $progress->setRedrawFrequency(2); |
154 | 154 |
@@ -589,6 +589,9 @@ |
||
589 | 589 | return new StreamOutput(fopen('php://memory', 'r+', false), $verbosity, $decorated); |
590 | 590 | } |
591 | 591 | |
592 | + /** |
|
593 | + * @param string $expected |
|
594 | + */ |
|
592 | 595 | protected function generateOutput($expected) |
593 | 596 | { |
594 | 597 | $count = substr_count($expected, "\n"); |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | |
454 | 454 | public function testAddingPlaceholderFormatter() |
455 | 455 | { |
456 | - ProgressBar::setPlaceholderFormatterDefinition('remaining_steps', function (ProgressBar $bar) { |
|
456 | + ProgressBar::setPlaceholderFormatterDefinition('remaining_steps', function(ProgressBar $bar) { |
|
457 | 457 | return $bar->getMaxSteps() - $bar->getProgress(); |
458 | 458 | }); |
459 | 459 | $bar = new ProgressBar($output = $this->getOutputStream(), 3); |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | public function testAnsiColorsAndEmojis() |
496 | 496 | { |
497 | 497 | $bar = new ProgressBar($output = $this->getOutputStream(), 15); |
498 | - ProgressBar::setPlaceholderFormatterDefinition('memory', function (ProgressBar $bar) { |
|
498 | + ProgressBar::setPlaceholderFormatterDefinition('memory', function(ProgressBar $bar) { |
|
499 | 499 | static $i = 0; |
500 | 500 | $mem = 100000 * $i; |
501 | 501 | $colors = $i++ ? '41;37' : '44;37'; |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | |
32 | 32 | function menu_ul($sel = 'inicio') |
33 | - { |
|
33 | + { |
|
34 | 34 | $items = array( |
35 | 35 | 'inicio' => array( |
36 | 36 | 'id' => 'inicio', |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | function menu_p($sel = 'inicio', $separador = '') |
68 | - { |
|
68 | + { |
|
69 | 69 | //$CI =& get_instance(); |
70 | 70 | $items = array( |
71 | 71 | 'inicio' => array( |
@@ -53,14 +53,14 @@ discard block |
||
53 | 53 | ) |
54 | 54 | ); |
55 | 55 | |
56 | - $menu = '<ul class="inline" >'. PHP_EOL; |
|
57 | - foreach($items as $item) |
|
56 | + $menu = '<ul class="inline" >'.PHP_EOL; |
|
57 | + foreach ($items as $item) |
|
58 | 58 | { |
59 | 59 | $current = (in_array($sel, $item)) ? ' class="current"' : ''; |
60 | 60 | $id = (!empty($item['id'])) ? ' id="'.$item['id'].'"' : ''; |
61 | 61 | $menu .= '<li'.$current.'><a href="'.$item['link'].'"'.$id.'>'.$item['title'].'</a></li>'."\n"; |
62 | 62 | } |
63 | - $menu .= '</ul>'. PHP_EOL . PHP_EOL; |
|
63 | + $menu .= '</ul>'.PHP_EOL.PHP_EOL; |
|
64 | 64 | return $menu; |
65 | 65 | } |
66 | 66 | |
@@ -91,19 +91,19 @@ discard block |
||
91 | 91 | |
92 | 92 | $count = count($items); |
93 | 93 | $i = 0; |
94 | - $menu = PHP_EOL .'<p class="bottom_nav">'; |
|
95 | - foreach($items as $item) |
|
94 | + $menu = PHP_EOL.'<p class="bottom_nav">'; |
|
95 | + foreach ($items as $item) |
|
96 | 96 | { |
97 | 97 | $current = (in_array($sel, $item)) ? ' class="current"' : ''; |
98 | 98 | $id = (!empty($item['id'])) ? ' id="'.$item['id'].'"' : ''; |
99 | 99 | $menu .= '<a'.$current.' href="'.$item['link'].'"'.$id.'>'.$item['title'].'</a>'; |
100 | 100 | $i++; |
101 | - if($count != $i) |
|
101 | + if ($count != $i) |
|
102 | 102 | { |
103 | 103 | $menu .= ' '.$separador.' '; |
104 | 104 | } |
105 | 105 | } |
106 | - $menu .= '</p>'. PHP_EOL ; |
|
106 | + $menu .= '</p>'.PHP_EOL; |
|
107 | 107 | return $menu; |
108 | 108 | } |
109 | 109 |
@@ -39,311 +39,311 @@ |
||
39 | 39 | * (you can pass the most critical GETs manually if you like) |
40 | 40 | */ |
41 | 41 | |
42 | - //Esta clase fue editada por programadores de Cf con la aprobacion de Ruben Arroyo |
|
42 | + //Esta clase fue editada por programadores de Cf con la aprobacion de Ruben Arroyo |
|
43 | 43 | |
44 | 44 | namespace Sistema\Ayudantes; |
45 | 45 | |
46 | 46 | class Cf_PHPPaginator { |
47 | - /* |
|
47 | + /* |
|
48 | 48 | * MAIN Settings (required) |
49 | 49 | */ |
50 | 50 | |
51 | - /** |
|
52 | - * |
|
53 | - * @total_records string Total of records to paginate (specify manually) |
|
54 | - */ |
|
55 | - public $total_records = 0; |
|
51 | + /** |
|
52 | + * |
|
53 | + * @total_records string Total of records to paginate (specify manually) |
|
54 | + */ |
|
55 | + public $total_records = 0; |
|
56 | 56 | |
57 | 57 | |
58 | - /* |
|
58 | + /* |
|
59 | 59 | * MAIN Settings (optional) |
60 | 60 | */ |
61 | 61 | |
62 | - /** |
|
63 | - * @style string Specify Class to define |
|
64 | - * @tutorial If is specified, it would create <div class="style"> otherwise it not create div |
|
65 | - */ |
|
66 | - public $style = ''; |
|
62 | + /** |
|
63 | + * @style string Specify Class to define |
|
64 | + * @tutorial If is specified, it would create <div class="style"> otherwise it not create div |
|
65 | + */ |
|
66 | + public $style = ''; |
|
67 | 67 | |
68 | - /** |
|
69 | - * @records number Max records to show on every page |
|
70 | - */ |
|
71 | - public $records = 20; |
|
68 | + /** |
|
69 | + * @records number Max records to show on every page |
|
70 | + */ |
|
71 | + public $records = 20; |
|
72 | 72 | |
73 | - /** |
|
74 | - * @max_links number Maxium quantity of links to show before and after actual page |
|
75 | - * @example If current page is 4 and MAX is 2, it show "2 3 4 5 6" |
|
76 | - */ |
|
77 | - public $max_links = 3; |
|
73 | + /** |
|
74 | + * @max_links number Maxium quantity of links to show before and after actual page |
|
75 | + * @example If current page is 4 and MAX is 2, it show "2 3 4 5 6" |
|
76 | + */ |
|
77 | + public $max_links = 3; |
|
78 | 78 | |
79 | - /** |
|
80 | - * @get_name string Specify INDEX of GET that is used |
|
81 | - * |
|
82 | - * It will load automatically the current page. |
|
83 | - * If you like, you can specify manually in "$cur_page" |
|
84 | - * (if you like filter previously or the script will not load directly from URL) |
|
85 | - */ |
|
86 | - public $get_name = 'pag'; |
|
79 | + /** |
|
80 | + * @get_name string Specify INDEX of GET that is used |
|
81 | + * |
|
82 | + * It will load automatically the current page. |
|
83 | + * If you like, you can specify manually in "$cur_page" |
|
84 | + * (if you like filter previously or the script will not load directly from URL) |
|
85 | + */ |
|
86 | + public $get_name = 'pag'; |
|
87 | 87 | |
88 | - /** |
|
89 | - * @max_records number Specify maxium quantity of registers will be loaded. "0" disable this |
|
90 | - */ |
|
91 | - public $max_records = 0; |
|
88 | + /** |
|
89 | + * @max_records number Specify maxium quantity of registers will be loaded. "0" disable this |
|
90 | + */ |
|
91 | + public $max_records = 0; |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * @recicle_url boolean If is true, modify directly tue current URL to put the pagination (if not exist any, add &pag= to the end) |
|
96 | - * If is true, $url_start and $url_end will be ignored |
|
97 | - */ |
|
98 | - public $recicle_url = true; |
|
94 | + /** |
|
95 | + * @recicle_url boolean If is true, modify directly tue current URL to put the pagination (if not exist any, add &pag= to the end) |
|
96 | + * If is true, $url_start and $url_end will be ignored |
|
97 | + */ |
|
98 | + public $recicle_url = true; |
|
99 | 99 | |
100 | - /** |
|
101 | - * @specific_get array Specify what GETs (and order) you like recicle. |
|
102 | - * Set array() to ALL (not recomended to avoid atacks DoS) |
|
103 | - * Set '' for any |
|
104 | - * @example array('section', 'pag', 'subsection'); |
|
105 | - * If you don't need 'pag' in the midle, you can ignore it. |
|
106 | - * WARNING: If the order is very important, use the pag at THE END of url |
|
107 | - */ |
|
108 | - public $specific_get = ''; |
|
100 | + /** |
|
101 | + * @specific_get array Specify what GETs (and order) you like recicle. |
|
102 | + * Set array() to ALL (not recomended to avoid atacks DoS) |
|
103 | + * Set '' for any |
|
104 | + * @example array('section', 'pag', 'subsection'); |
|
105 | + * If you don't need 'pag' in the midle, you can ignore it. |
|
106 | + * WARNING: If the order is very important, use the pag at THE END of url |
|
107 | + */ |
|
108 | + public $specific_get = ''; |
|
109 | 109 | |
110 | - /** |
|
111 | - * @url_start string specify how the URL of every link start. IF $recicle_url is TRUE, this will be ignored |
|
112 | - * @example If you use MOD_REWRITE or JAVASCRIPT, you can put "http://mywebsite.com/subdir/pag-" or "javascript:paginate(" |
|
113 | - * |
|
114 | - * This value will auto completed if you leave empty |
|
115 | - */ |
|
116 | - public $url_start = ''; |
|
110 | + /** |
|
111 | + * @url_start string specify how the URL of every link start. IF $recicle_url is TRUE, this will be ignored |
|
112 | + * @example If you use MOD_REWRITE or JAVASCRIPT, you can put "http://mywebsite.com/subdir/pag-" or "javascript:paginate(" |
|
113 | + * |
|
114 | + * This value will auto completed if you leave empty |
|
115 | + */ |
|
116 | + public $url_start = ''; |
|
117 | 117 | |
118 | - /** |
|
119 | - * @url_end string specify how the URL of every link ends. IF $recicle_url is TRUE, this will be ignored |
|
120 | - * @example If you use MOD_REWRITE or JAVASCRIPT, you can put "/" or ");" |
|
121 | - * |
|
122 | - * This value will auto completed if you leave empty |
|
123 | - */ |
|
124 | - public $url_end = ''; |
|
118 | + /** |
|
119 | + * @url_end string specify how the URL of every link ends. IF $recicle_url is TRUE, this will be ignored |
|
120 | + * @example If you use MOD_REWRITE or JAVASCRIPT, you can put "/" or ");" |
|
121 | + * |
|
122 | + * This value will auto completed if you leave empty |
|
123 | + */ |
|
124 | + public $url_end = ''; |
|
125 | 125 | |
126 | 126 | |
127 | 127 | |
128 | - /* |
|
128 | + /* |
|
129 | 129 | * Design settings |
130 | 130 | */ |
131 | 131 | |
132 | - // Icons to show "First | Previous | Next | Last" |
|
133 | - //& laquo; = � | & lt; = < |
|
132 | + // Icons to show "First | Previous | Next | Last" |
|
133 | + //& laquo; = � | & lt; = < |
|
134 | 134 | //& raquo; = � | & gt; = > |
135 | 135 | // Leave empty '' to not show or ' ' to show empty |
136 | - public $first = '[<<]'; |
|
137 | - public $previous = '[<]'; |
|
138 | - public $next = '[>]'; |
|
139 | - public $last = '[>>]'; |
|
136 | + public $first = '[<<]'; |
|
137 | + public $previous = '[<]'; |
|
138 | + public $next = '[>]'; |
|
139 | + public $last = '[>>]'; |
|
140 | 140 | |
141 | 141 | |
142 | - /* |
|
142 | + /* |
|
143 | 143 | * RETURNS FROM PAGINATOR and internal use |
144 | 144 | */ |
145 | - // Return current page (auto loaded) |
|
146 | - public $cur_page; |
|
145 | + // Return current page (auto loaded) |
|
146 | + public $cur_page; |
|
147 | 147 | |
148 | - // original page loaded |
|
149 | - // it contains the real value in GET (ex: -1, 5...) to compare later |
|
150 | - public $original_page; |
|
148 | + // original page loaded |
|
149 | + // it contains the real value in GET (ex: -1, 5...) to compare later |
|
150 | + public $original_page; |
|
151 | 151 | |
152 | - // Return total pages |
|
153 | - public $total_pages; |
|
152 | + // Return total pages |
|
153 | + public $total_pages; |
|
154 | 154 | |
155 | - // LIMIT_START / Specify the first record of the page (ex, in page 3 and 20 records is record num 40) |
|
156 | - // Limit max is $records |
|
157 | - public $first_record; |
|
155 | + // LIMIT_START / Specify the first record of the page (ex, in page 3 and 20 records is record num 40) |
|
156 | + // Limit max is $records |
|
157 | + public $first_record; |
|
158 | 158 | |
159 | - // Specify limit to put directly in mysql query ( LIMIT 0,20 ) |
|
160 | - public $limit; |
|
159 | + // Specify limit to put directly in mysql query ( LIMIT 0,20 ) |
|
160 | + public $limit; |
|
161 | 161 | |
162 | 162 | |
163 | 163 | /* |
164 | 164 | * Functions |
165 | 165 | */ |
166 | - /** |
|
167 | - * @name paginate |
|
168 | - * @tutorial This function is called directly to load all params |
|
169 | - * @example $pag->paginate(); |
|
170 | - */ |
|
171 | - public function paginate() { |
|
172 | - $this->get(); // Filtering and obtaining variables |
|
173 | - $this->calculate(); // Calc current page |
|
174 | - $this->prepareUrl(); // Preparing URL to show |
|
175 | - } |
|
166 | + /** |
|
167 | + * @name paginate |
|
168 | + * @tutorial This function is called directly to load all params |
|
169 | + * @example $pag->paginate(); |
|
170 | + */ |
|
171 | + public function paginate() { |
|
172 | + $this->get(); // Filtering and obtaining variables |
|
173 | + $this->calculate(); // Calc current page |
|
174 | + $this->prepareUrl(); // Preparing URL to show |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * @name show |
|
179 | - * @tutorial Show links of pagination |
|
180 | - * @example $pag->show(); |
|
181 | - */ |
|
182 | - public function show() { |
|
183 | - // Prepare string with links |
|
184 | - // Reading here variables is faster than "$this->var" |
|
185 | - $cur_page = $this->cur_page; |
|
186 | - $url_start = $this->url_start; |
|
187 | - $url_end = $this->url_end; |
|
177 | + /** |
|
178 | + * @name show |
|
179 | + * @tutorial Show links of pagination |
|
180 | + * @example $pag->show(); |
|
181 | + */ |
|
182 | + public function show() { |
|
183 | + // Prepare string with links |
|
184 | + // Reading here variables is faster than "$this->var" |
|
185 | + $cur_page = $this->cur_page; |
|
186 | + $url_start = $this->url_start; |
|
187 | + $url_end = $this->url_end; |
|
188 | 188 | |
189 | - $start = $cur_page - $this->max_links; |
|
190 | - $end = $cur_page + $this->max_links; |
|
189 | + $start = $cur_page - $this->max_links; |
|
190 | + $end = $cur_page + $this->max_links; |
|
191 | 191 | |
192 | - if ($start < 1) $start = 1; |
|
193 | - if ($end > $this->total_pages) $end = $this->total_pages; |
|
192 | + if ($start < 1) $start = 1; |
|
193 | + if ($end > $this->total_pages) $end = $this->total_pages; |
|
194 | 194 | |
195 | - // Showing all clickable pages (create div if class is defined) |
|
196 | - if ($this->style != '') $r = '<div class="'.$this->style.'">'; |
|
197 | - else $r = ''; |
|
195 | + // Showing all clickable pages (create div if class is defined) |
|
196 | + if ($this->style != '') $r = '<div class="'.$this->style.'">'; |
|
197 | + else $r = ''; |
|
198 | 198 | |
199 | 199 | |
200 | - // First / previous |
|
201 | - if ($this->cur_page > 1) { |
|
202 | - if ($this->first != '') $r .= '<a class="first" href="' . $url_start . '1' . $url_end . '">'.$this->first.'</a> '; |
|
203 | - if ($this->previous != '') $r .= '<a class="previous" href="' . $url_start . ($cur_page - 1) . $url_end . '">'.$this->previous.'</a> '; |
|
204 | - } |
|
200 | + // First / previous |
|
201 | + if ($this->cur_page > 1) { |
|
202 | + if ($this->first != '') $r .= '<a class="first" href="' . $url_start . '1' . $url_end . '">'.$this->first.'</a> '; |
|
203 | + if ($this->previous != '') $r .= '<a class="previous" href="' . $url_start . ($cur_page - 1) . $url_end . '">'.$this->previous.'</a> '; |
|
204 | + } |
|
205 | 205 | |
206 | - // You can optimize this separating BEFORE and AFTER current page in two for (to avoid load "if" in each loop) |
|
207 | - // but it would be difficult on changes |
|
208 | - for ($n=$start; $n<=$end; $n++) { |
|
209 | - if ($n != $cur_page) $r .= '<a class="link" href="'. $url_start . $n . $url_end . '">'.$n.'</a> '; |
|
210 | - else $r .= '<a class="current">'.$n.'</a> '; |
|
211 | - } |
|
206 | + // You can optimize this separating BEFORE and AFTER current page in two for (to avoid load "if" in each loop) |
|
207 | + // but it would be difficult on changes |
|
208 | + for ($n=$start; $n<=$end; $n++) { |
|
209 | + if ($n != $cur_page) $r .= '<a class="link" href="'. $url_start . $n . $url_end . '">'.$n.'</a> '; |
|
210 | + else $r .= '<a class="current">'.$n.'</a> '; |
|
211 | + } |
|
212 | 212 | |
213 | - // next / last |
|
214 | - if ($this->cur_page < $this->total_pages) { |
|
215 | - if ($this->next != '') $r .= '<a class="next" href="' . $url_start . ($cur_page + 1) . $url_end . '">'.$this->next.'</a> '; |
|
216 | - if ($this->last != '') $r .= '<a class="last" href="' . $url_start . $this->total_pages . $url_end .'">'.$this->last.'</a> '; |
|
217 | - } |
|
213 | + // next / last |
|
214 | + if ($this->cur_page < $this->total_pages) { |
|
215 | + if ($this->next != '') $r .= '<a class="next" href="' . $url_start . ($cur_page + 1) . $url_end . '">'.$this->next.'</a> '; |
|
216 | + if ($this->last != '') $r .= '<a class="last" href="' . $url_start . $this->total_pages . $url_end .'">'.$this->last.'</a> '; |
|
217 | + } |
|
218 | 218 | |
219 | - // End div (if exist) |
|
220 | - if ($this->style != '') $r .= '</div>'; |
|
219 | + // End div (if exist) |
|
220 | + if ($this->style != '') $r .= '</div>'; |
|
221 | 221 | |
222 | - return $r; |
|
223 | - } |
|
222 | + return $r; |
|
223 | + } |
|
224 | 224 | |
225 | 225 | |
226 | - /** |
|
227 | - * @name get |
|
228 | - * @tutorial This function is autoloaded, it get the current page and filter number to avoid hackers |
|
229 | - */ |
|
230 | - private function get() { |
|
231 | - if (!is_numeric($this->cur_page)) { |
|
232 | - // First get the actual page, by default 1 |
|
233 | - $cur_page = isset($_GET[$this->get_name]) ? $_GET[$this->get_name] : 1; |
|
234 | - $this->original_page = $cur_page; |
|
226 | + /** |
|
227 | + * @name get |
|
228 | + * @tutorial This function is autoloaded, it get the current page and filter number to avoid hackers |
|
229 | + */ |
|
230 | + private function get() { |
|
231 | + if (!is_numeric($this->cur_page)) { |
|
232 | + // First get the actual page, by default 1 |
|
233 | + $cur_page = isset($_GET[$this->get_name]) ? $_GET[$this->get_name] : 1; |
|
234 | + $this->original_page = $cur_page; |
|
235 | 235 | |
236 | - // Filter values |
|
237 | - if (!is_numeric($cur_page) or $cur_page < 1) $cur_page = 1; |
|
236 | + // Filter values |
|
237 | + if (!is_numeric($cur_page) or $cur_page < 1) $cur_page = 1; |
|
238 | 238 | |
239 | - // Set new filtered values (is faster this method) |
|
240 | - $this->cur_page = $cur_page; |
|
241 | - } else { |
|
242 | - $this->original_page = $cur_page; |
|
243 | - } |
|
244 | - } |
|
239 | + // Set new filtered values (is faster this method) |
|
240 | + $this->cur_page = $cur_page; |
|
241 | + } else { |
|
242 | + $this->original_page = $cur_page; |
|
243 | + } |
|
244 | + } |
|
245 | 245 | |
246 | - /** |
|
247 | - * @name calculate |
|
248 | - * @tutorial Do all calcs about current and last page |
|
249 | - */ |
|
250 | - private function calculate() { |
|
251 | - // This vars are very used, so is faster do this |
|
252 | - $max_records = $this->max_records; |
|
253 | - $records = $this->records; |
|
246 | + /** |
|
247 | + * @name calculate |
|
248 | + * @tutorial Do all calcs about current and last page |
|
249 | + */ |
|
250 | + private function calculate() { |
|
251 | + // This vars are very used, so is faster do this |
|
252 | + $max_records = $this->max_records; |
|
253 | + $records = $this->records; |
|
254 | 254 | |
255 | - // Force maxium records loaded (only if is specified by user) |
|
256 | - if ($max_records > 0 and $max_records > $total_records) |
|
257 | - $this->total_records = $max_records; |
|
255 | + // Force maxium records loaded (only if is specified by user) |
|
256 | + if ($max_records > 0 and $max_records > $total_records) |
|
257 | + $this->total_records = $max_records; |
|
258 | 258 | |
259 | - // Calculate total pages that have |
|
260 | - $total_pages = ceil($this->total_records / $records); |
|
259 | + // Calculate total pages that have |
|
260 | + $total_pages = ceil($this->total_records / $records); |
|
261 | 261 | |
262 | - // Is correct current page? |
|
263 | - if ($this->cur_page > $total_pages) $this->cur_page = $total_pages; |
|
264 | - $this->total_pages = $total_pages; |
|
262 | + // Is correct current page? |
|
263 | + if ($this->cur_page > $total_pages) $this->cur_page = $total_pages; |
|
264 | + $this->total_pages = $total_pages; |
|
265 | 265 | |
266 | - // Specify LIMIT to do a query |
|
267 | - $start = ($this->cur_page - 1) * $records; |
|
266 | + // Specify LIMIT to do a query |
|
267 | + $start = ($this->cur_page - 1) * $records; |
|
268 | 268 | |
269 | - // Forcing maixum records to show (only if is specified by user) |
|
270 | - if ($max_records > 0 and $records > $max_records) { |
|
271 | - $records = $max_records; |
|
272 | - $this->records = $records; |
|
273 | - } |
|
269 | + // Forcing maixum records to show (only if is specified by user) |
|
270 | + if ($max_records > 0 and $records > $max_records) { |
|
271 | + $records = $max_records; |
|
272 | + $this->records = $records; |
|
273 | + } |
|
274 | 274 | |
275 | 275 | |
276 | - // Saving changes |
|
277 | - $this->first_record = $start; |
|
278 | - $this->limit = ' LIMIT '.$start.','.$records.' '; |
|
279 | - } |
|
276 | + // Saving changes |
|
277 | + $this->first_record = $start; |
|
278 | + $this->limit = ' LIMIT '.$start.','.$records.' '; |
|
279 | + } |
|
280 | 280 | |
281 | - /** |
|
282 | - * @name prepareUrl |
|
283 | - * @tutorial It prepare the url to show in each link, specified by user |
|
284 | - * If recicle URL is false, it will auto load $url_start and $url_end |
|
285 | - */ |
|
286 | - private function prepareUrl() { |
|
287 | - // This script use three methods to recicle GET depending user selection |
|
288 | - if ($this->recicle_url) { |
|
289 | - // gonna to recicle the URL |
|
290 | - $gets = $this->specific_get; |
|
291 | - $get_name = $this->get_name; |
|
281 | + /** |
|
282 | + * @name prepareUrl |
|
283 | + * @tutorial It prepare the url to show in each link, specified by user |
|
284 | + * If recicle URL is false, it will auto load $url_start and $url_end |
|
285 | + */ |
|
286 | + private function prepareUrl() { |
|
287 | + // This script use three methods to recicle GET depending user selection |
|
288 | + if ($this->recicle_url) { |
|
289 | + // gonna to recicle the URL |
|
290 | + $gets = $this->specific_get; |
|
291 | + $get_name = $this->get_name; |
|
292 | 292 | |
293 | - // If user specified an array |
|
294 | - if (is_array($gets)) { |
|
295 | - if (empty($gets)) { |
|
296 | - // And is empty, we have to Recicle ALL GET |
|
297 | - // To know that page needs to be replaced we will use the "original_page" (the real get) |
|
298 | - // Cortamos "pag=2" para obtener lo que va antes y despues, as� poder modificar directamente ese pag=2 por la pagina actual |
|
299 | - $query_string = explode($this->get_name.'='.$this->original_page, $_SERVER['QUERY_STRING']); |
|
293 | + // If user specified an array |
|
294 | + if (is_array($gets)) { |
|
295 | + if (empty($gets)) { |
|
296 | + // And is empty, we have to Recicle ALL GET |
|
297 | + // To know that page needs to be replaced we will use the "original_page" (the real get) |
|
298 | + // Cortamos "pag=2" para obtener lo que va antes y despues, as� poder modificar directamente ese pag=2 por la pagina actual |
|
299 | + $query_string = explode($this->get_name.'='.$this->original_page, $_SERVER['QUERY_STRING']); |
|
300 | 300 | |
301 | - // How start the new URL? To know it, we need to see the last character from current string |
|
302 | - if (!in_array(substr($query_string[0], -1), array('?', '&'))) { |
|
303 | - // Current string haven't any at end and it isn't "&" or "?" ? |
|
304 | - // If initial string have one character at least it means that not is the first index |
|
305 | - if (isset($query_string[0][0])) $this->url_start = '?'.$query_string[0].'&'; |
|
306 | - else $this->url_start = '?'.$query_string[0]; |
|
307 | - } else { |
|
308 | - // Current string already have ? or &, |
|
309 | - $this->url_start = '?'.$query_string[0]; |
|
310 | - } |
|
301 | + // How start the new URL? To know it, we need to see the last character from current string |
|
302 | + if (!in_array(substr($query_string[0], -1), array('?', '&'))) { |
|
303 | + // Current string haven't any at end and it isn't "&" or "?" ? |
|
304 | + // If initial string have one character at least it means that not is the first index |
|
305 | + if (isset($query_string[0][0])) $this->url_start = '?'.$query_string[0].'&'; |
|
306 | + else $this->url_start = '?'.$query_string[0]; |
|
307 | + } else { |
|
308 | + // Current string already have ? or &, |
|
309 | + $this->url_start = '?'.$query_string[0]; |
|
310 | + } |
|
311 | 311 | |
312 | - $this->url_end = isset($query_string[1]) ? $query_string[1] : ''; |
|
313 | - } else { |
|
314 | - // Only specifics GET, reading all and finally leave in the same order |
|
315 | - // With this we can clean all GET that we don't need (like hacker attempts) |
|
316 | - $tmp = ''; |
|
317 | - $tmp_start = ''; // If we found the current page, we move here all $tmp |
|
318 | - foreach ($gets as $get) { |
|
319 | - if ($get != $get_name) { |
|
320 | - // Trying to get the GET |
|
321 | - if (isset($_GET[$get])) $tmp .= $get.'='.$_GET[$get].'&'; |
|
322 | - } else { |
|
323 | - // Pour the $tmp content to $tmp_start |
|
324 | - if ($tmp_start == '') $tmp_start .= '?'; |
|
325 | - $tmp_start .= $tmp; |
|
326 | - $tmp = ''; |
|
327 | - } |
|
328 | - } |
|
312 | + $this->url_end = isset($query_string[1]) ? $query_string[1] : ''; |
|
313 | + } else { |
|
314 | + // Only specifics GET, reading all and finally leave in the same order |
|
315 | + // With this we can clean all GET that we don't need (like hacker attempts) |
|
316 | + $tmp = ''; |
|
317 | + $tmp_start = ''; // If we found the current page, we move here all $tmp |
|
318 | + foreach ($gets as $get) { |
|
319 | + if ($get != $get_name) { |
|
320 | + // Trying to get the GET |
|
321 | + if (isset($_GET[$get])) $tmp .= $get.'='.$_GET[$get].'&'; |
|
322 | + } else { |
|
323 | + // Pour the $tmp content to $tmp_start |
|
324 | + if ($tmp_start == '') $tmp_start .= '?'; |
|
325 | + $tmp_start .= $tmp; |
|
326 | + $tmp = ''; |
|
327 | + } |
|
328 | + } |
|
329 | 329 | |
330 | - // Finally, write the changes in the object |
|
331 | - if ($tmp_start != '') { |
|
332 | - // If have start and end |
|
333 | - $this->url_start = $tmp_start; |
|
334 | - $this->url_end = $tmp; |
|
335 | - } |
|
336 | - else $this->url_start = '?'.$tmp; |
|
337 | - } |
|
338 | - } else{ |
|
339 | - // Non recicle |
|
340 | - $this->url_start = '?'; |
|
341 | - $this->url_end = ''; |
|
342 | - } |
|
330 | + // Finally, write the changes in the object |
|
331 | + if ($tmp_start != '') { |
|
332 | + // If have start and end |
|
333 | + $this->url_start = $tmp_start; |
|
334 | + $this->url_end = $tmp; |
|
335 | + } |
|
336 | + else $this->url_start = '?'.$tmp; |
|
337 | + } |
|
338 | + } else{ |
|
339 | + // Non recicle |
|
340 | + $this->url_start = '?'; |
|
341 | + $this->url_end = ''; |
|
342 | + } |
|
343 | 343 | |
344 | - // Add the pagination |
|
345 | - $this->url_start .= $this->get_name.'='; |
|
346 | - } |
|
347 | - } |
|
344 | + // Add the pagination |
|
345 | + $this->url_start .= $this->get_name.'='; |
|
346 | + } |
|
347 | + } |
|
348 | 348 | } |
349 | 349 | ?> |
350 | 350 | \ No newline at end of file |
@@ -189,35 +189,55 @@ discard block |
||
189 | 189 | $start = $cur_page - $this->max_links; |
190 | 190 | $end = $cur_page + $this->max_links; |
191 | 191 | |
192 | - if ($start < 1) $start = 1; |
|
193 | - if ($end > $this->total_pages) $end = $this->total_pages; |
|
192 | + if ($start < 1) { |
|
193 | + $start = 1; |
|
194 | + } |
|
195 | + if ($end > $this->total_pages) { |
|
196 | + $end = $this->total_pages; |
|
197 | + } |
|
194 | 198 | |
195 | 199 | // Showing all clickable pages (create div if class is defined) |
196 | - if ($this->style != '') $r = '<div class="'.$this->style.'">'; |
|
197 | - else $r = ''; |
|
200 | + if ($this->style != '') { |
|
201 | + $r = '<div class="'.$this->style.'">'; |
|
202 | + } else { |
|
203 | + $r = ''; |
|
204 | + } |
|
198 | 205 | |
199 | 206 | |
200 | 207 | // First / previous |
201 | 208 | if ($this->cur_page > 1) { |
202 | - if ($this->first != '') $r .= '<a class="first" href="' . $url_start . '1' . $url_end . '">'.$this->first.'</a> '; |
|
203 | - if ($this->previous != '') $r .= '<a class="previous" href="' . $url_start . ($cur_page - 1) . $url_end . '">'.$this->previous.'</a> '; |
|
209 | + if ($this->first != '') { |
|
210 | + $r .= '<a class="first" href="' . $url_start . '1' . $url_end . '">'.$this->first.'</a> '; |
|
211 | + } |
|
212 | + if ($this->previous != '') { |
|
213 | + $r .= '<a class="previous" href="' . $url_start . ($cur_page - 1) . $url_end . '">'.$this->previous.'</a> '; |
|
214 | + } |
|
204 | 215 | } |
205 | 216 | |
206 | 217 | // You can optimize this separating BEFORE and AFTER current page in two for (to avoid load "if" in each loop) |
207 | 218 | // but it would be difficult on changes |
208 | 219 | for ($n=$start; $n<=$end; $n++) { |
209 | - if ($n != $cur_page) $r .= '<a class="link" href="'. $url_start . $n . $url_end . '">'.$n.'</a> '; |
|
210 | - else $r .= '<a class="current">'.$n.'</a> '; |
|
220 | + if ($n != $cur_page) { |
|
221 | + $r .= '<a class="link" href="'. $url_start . $n . $url_end . '">'.$n.'</a> '; |
|
222 | + } else { |
|
223 | + $r .= '<a class="current">'.$n.'</a> '; |
|
224 | + } |
|
211 | 225 | } |
212 | 226 | |
213 | 227 | // next / last |
214 | 228 | if ($this->cur_page < $this->total_pages) { |
215 | - if ($this->next != '') $r .= '<a class="next" href="' . $url_start . ($cur_page + 1) . $url_end . '">'.$this->next.'</a> '; |
|
216 | - if ($this->last != '') $r .= '<a class="last" href="' . $url_start . $this->total_pages . $url_end .'">'.$this->last.'</a> '; |
|
229 | + if ($this->next != '') { |
|
230 | + $r .= '<a class="next" href="' . $url_start . ($cur_page + 1) . $url_end . '">'.$this->next.'</a> '; |
|
231 | + } |
|
232 | + if ($this->last != '') { |
|
233 | + $r .= '<a class="last" href="' . $url_start . $this->total_pages . $url_end .'">'.$this->last.'</a> '; |
|
234 | + } |
|
217 | 235 | } |
218 | 236 | |
219 | 237 | // End div (if exist) |
220 | - if ($this->style != '') $r .= '</div>'; |
|
238 | + if ($this->style != '') { |
|
239 | + $r .= '</div>'; |
|
240 | + } |
|
221 | 241 | |
222 | 242 | return $r; |
223 | 243 | } |
@@ -234,7 +254,9 @@ discard block |
||
234 | 254 | $this->original_page = $cur_page; |
235 | 255 | |
236 | 256 | // Filter values |
237 | - if (!is_numeric($cur_page) or $cur_page < 1) $cur_page = 1; |
|
257 | + if (!is_numeric($cur_page) or $cur_page < 1) { |
|
258 | + $cur_page = 1; |
|
259 | + } |
|
238 | 260 | |
239 | 261 | // Set new filtered values (is faster this method) |
240 | 262 | $this->cur_page = $cur_page; |
@@ -253,14 +275,17 @@ discard block |
||
253 | 275 | $records = $this->records; |
254 | 276 | |
255 | 277 | // Force maxium records loaded (only if is specified by user) |
256 | - if ($max_records > 0 and $max_records > $total_records) |
|
257 | - $this->total_records = $max_records; |
|
278 | + if ($max_records > 0 and $max_records > $total_records) { |
|
279 | + $this->total_records = $max_records; |
|
280 | + } |
|
258 | 281 | |
259 | 282 | // Calculate total pages that have |
260 | 283 | $total_pages = ceil($this->total_records / $records); |
261 | 284 | |
262 | 285 | // Is correct current page? |
263 | - if ($this->cur_page > $total_pages) $this->cur_page = $total_pages; |
|
286 | + if ($this->cur_page > $total_pages) { |
|
287 | + $this->cur_page = $total_pages; |
|
288 | + } |
|
264 | 289 | $this->total_pages = $total_pages; |
265 | 290 | |
266 | 291 | // Specify LIMIT to do a query |
@@ -302,8 +327,11 @@ discard block |
||
302 | 327 | if (!in_array(substr($query_string[0], -1), array('?', '&'))) { |
303 | 328 | // Current string haven't any at end and it isn't "&" or "?" ? |
304 | 329 | // If initial string have one character at least it means that not is the first index |
305 | - if (isset($query_string[0][0])) $this->url_start = '?'.$query_string[0].'&'; |
|
306 | - else $this->url_start = '?'.$query_string[0]; |
|
330 | + if (isset($query_string[0][0])) { |
|
331 | + $this->url_start = '?'.$query_string[0].'&'; |
|
332 | + } else { |
|
333 | + $this->url_start = '?'.$query_string[0]; |
|
334 | + } |
|
307 | 335 | } else { |
308 | 336 | // Current string already have ? or &, |
309 | 337 | $this->url_start = '?'.$query_string[0]; |
@@ -318,10 +346,14 @@ discard block |
||
318 | 346 | foreach ($gets as $get) { |
319 | 347 | if ($get != $get_name) { |
320 | 348 | // Trying to get the GET |
321 | - if (isset($_GET[$get])) $tmp .= $get.'='.$_GET[$get].'&'; |
|
349 | + if (isset($_GET[$get])) { |
|
350 | + $tmp .= $get.'='.$_GET[$get].'&'; |
|
351 | + } |
|
322 | 352 | } else { |
323 | 353 | // Pour the $tmp content to $tmp_start |
324 | - if ($tmp_start == '') $tmp_start .= '?'; |
|
354 | + if ($tmp_start == '') { |
|
355 | + $tmp_start .= '?'; |
|
356 | + } |
|
325 | 357 | $tmp_start .= $tmp; |
326 | 358 | $tmp = ''; |
327 | 359 | } |
@@ -332,8 +364,9 @@ discard block |
||
332 | 364 | // If have start and end |
333 | 365 | $this->url_start = $tmp_start; |
334 | 366 | $this->url_end = $tmp; |
367 | + } else { |
|
368 | + $this->url_start = '?'.$tmp; |
|
335 | 369 | } |
336 | - else $this->url_start = '?'.$tmp; |
|
337 | 370 | } |
338 | 371 | } else{ |
339 | 372 | // Non recicle |
@@ -199,21 +199,21 @@ discard block |
||
199 | 199 | |
200 | 200 | // First / previous |
201 | 201 | if ($this->cur_page > 1) { |
202 | - if ($this->first != '') $r .= '<a class="first" href="' . $url_start . '1' . $url_end . '">'.$this->first.'</a> '; |
|
203 | - if ($this->previous != '') $r .= '<a class="previous" href="' . $url_start . ($cur_page - 1) . $url_end . '">'.$this->previous.'</a> '; |
|
202 | + if ($this->first != '') $r .= '<a class="first" href="'.$url_start.'1'.$url_end.'">'.$this->first.'</a> '; |
|
203 | + if ($this->previous != '') $r .= '<a class="previous" href="'.$url_start.($cur_page - 1).$url_end.'">'.$this->previous.'</a> '; |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | // You can optimize this separating BEFORE and AFTER current page in two for (to avoid load "if" in each loop) |
207 | 207 | // but it would be difficult on changes |
208 | - for ($n=$start; $n<=$end; $n++) { |
|
209 | - if ($n != $cur_page) $r .= '<a class="link" href="'. $url_start . $n . $url_end . '">'.$n.'</a> '; |
|
208 | + for ($n = $start; $n <= $end; $n++) { |
|
209 | + if ($n != $cur_page) $r .= '<a class="link" href="'.$url_start.$n.$url_end.'">'.$n.'</a> '; |
|
210 | 210 | else $r .= '<a class="current">'.$n.'</a> '; |
211 | 211 | } |
212 | 212 | |
213 | 213 | // next / last |
214 | 214 | if ($this->cur_page < $this->total_pages) { |
215 | - if ($this->next != '') $r .= '<a class="next" href="' . $url_start . ($cur_page + 1) . $url_end . '">'.$this->next.'</a> '; |
|
216 | - if ($this->last != '') $r .= '<a class="last" href="' . $url_start . $this->total_pages . $url_end .'">'.$this->last.'</a> '; |
|
215 | + if ($this->next != '') $r .= '<a class="next" href="'.$url_start.($cur_page + 1).$url_end.'">'.$this->next.'</a> '; |
|
216 | + if ($this->last != '') $r .= '<a class="last" href="'.$url_start.$this->total_pages.$url_end.'">'.$this->last.'</a> '; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | // End div (if exist) |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | $records = $this->records; |
254 | 254 | |
255 | 255 | // Force maxium records loaded (only if is specified by user) |
256 | - if ($max_records > 0 and $max_records > $total_records) |
|
256 | + if ($max_records > 0 and $max_records > $total_records) |
|
257 | 257 | $this->total_records = $max_records; |
258 | 258 | |
259 | 259 | // Calculate total pages that have |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | } |
336 | 336 | else $this->url_start = '?'.$tmp; |
337 | 337 | } |
338 | - } else{ |
|
338 | + } else { |
|
339 | 339 | // Non recicle |
340 | 340 | $this->url_start = '?'; |
341 | 341 | $this->url_end = ''; |
@@ -31,5 +31,5 @@ |
||
31 | 31 | |
32 | 32 | $dominio = "http://www.my-site-domain.com/"; |
33 | 33 | return $dominio; |
34 | - } |
|
34 | + } |
|
35 | 35 | } |
36 | 36 | \ No newline at end of file |
@@ -27,7 +27,7 @@ |
||
27 | 27 | |
28 | 28 | class CFPHPVinculos { |
29 | 29 | |
30 | - function get_dominio(){ |
|
30 | + function get_dominio() { |
|
31 | 31 | |
32 | 32 | $dominio = "http://www.my-site-domain.com/"; |
33 | 33 | return $dominio; |