<commit_before><?php
/**
 * @package     Mautic
 * @copyright   2014 Mautic Contributors. All rights reserved.
 * @author      Mautic
 * @link        http://mautic.org
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */

$target = (!empty($target)) ? $target : '.page-list';
$tmpl   = (!empty($tmpl)) ? $tmpl : 'list';

$limit  = (!isset($limit)) ? 30 : (int) $limit;

if (!isset($range)) {
    $range = 4;
}

if ($page <= 0) {
    $page = 1;
} else {
    $page = (int) $page;
}

$totalPages = ($limit) ? (int) ceil($totalItems / $limit) : 1;

$pageClass = (!isset($paginationClass)) ? "" : " pagination-$paginationClass";
$menuLink  = (!empty($menuLinkId)) ? " data-menu-link=\"$menuLinkId\"" : "";
$paginationWrapper = isset($paginationWrapper) ? $paginationWrapper :  "pagination-wrapper pull-left ml-md mr-md";

$queryString = '?tmpl=' . $tmpl . (isset($queryString) ? $queryString : '');

$limitOptions = array(
    5   => '5',
    10  => '10',
    15  => '15',
    20  => '20',
    25  => '25',
    30  => '30',
    50  => '50',
    100 => '100',
    0   => 'all'
);

$formExit = (!empty($ignoreFormExit)) ? ' data-ignore-formexit="true"' : '';

$responsiveViewports = array('desktop', 'mobile');

foreach ($responsiveViewports as $viewport):

if ($viewport == 'mobile'):
    $paginationClass   = 'sm';
    $pageClass         = 'pagination-sm';
    $responsiveClass   = 'visible-xs hidden-sm hidden-md hidden-lg';
    $paginationWrapper = "pagination-wrapper pull-left nm";
else:
    $responsiveClass = 'hidden-xs visible-sm visible-md visible-lg';
endif;

?>
<div class="<?php echo $responsiveClass; ?>">
    <?php if (empty($fixedLimit)): ?>
        <div class="pull-right">
            <?php $class = (!empty($paginationClass)) ? " input-{$paginationClass}" : ""; ?>
            <select autocomplete="off" class="form-control not-chosen pagination-limit<?php echo $class; ?>" onchange="Mautic.limitTableData('<?php echo $sessionVar; ?>',this.value,'<?php echo $tmpl; ?>','<?php echo $target; ?>'<?php if (!empty($baseUrl)): ?>, '<?php echo $baseUrl; ?>'<?php endif; ?>);">
                <?php foreach ($limitOptions as $value => $label): ?>
                <?php $selected = ($limit === $value) ? ' selected="selected"': '';?>
                <option<?php echo $selected; ?> value="<?php echo $value; ?>"><?php echo $view['translator']->trans('mautic.core.pagination.'.$label); ?></option>
                <?php endforeach; ?>
            </select>
        </div>
    <?php endif; ?>

    <div class="<?php echo $paginationWrapper; ?>">
        <ul class="pagination nm <?php echo $pageClass; ?>">
            <?php
            $urlPage = "/" . $page - $range;
            $url     = ($urlPage > 0) ? $baseUrl . $urlPage . $queryString : 'javascript: void(0);';
            $data    = ($url == 'javascript: void(0);') ? '' : ' data-toggle="ajax" data-target="' . $target . '"' . $menuLink;
            $class   = ($urlPage <= 0) ? ' class="disabled"' : '';
            ?>
            <li<?php echo $class; ?>>
                <?php  ?>
                <a href="<?php echo $url; ?>"<?php echo $data.$formExit; ?>>
                    <i class="fa fa-angle-double-left"></i>
                </a>
            </li>

            <?php
            $urlPage = "/" . $page - 1;
            $url     = ($urlPage >= 1) ? $baseUrl . $urlPage . $queryString : 'javascript: void(0);';
            $data    = ($url == 'javascript: void(0);') ? '' : ' data-toggle="ajax" data-target="' . $target . '"' . $menuLink;
            $class   = ($urlPage <= 0) ? ' class="disabled"' : '';
            ?>
            <li<?php echo $class; ?>>
                <?php  ?>
                <a href="<?php echo $url; ?>"<?php echo $data.$formExit; ?>>
                    <i class="fa fa-angle-left"></i>
                </a>
            </li>

            <?php
            $startPage = $page - $range + 1;
            if ($startPage <= 0) {
                $startPage = 1;
            }
            $lastPage = $startPage + $range - 1;
            if ($lastPage > $totalPages) {
                $lastPage = $totalPages;
            }
            ?>
            <?php for ($i=$startPage; $i<=$lastPage; $i++): ?>
            <?php
            $class = ($page === (int) $i) ? ' class="active"' : '';
            $url   = ($page === (int) $i) ? 'javascript: void(0);' : $baseUrl . "/" . $i . $queryString;
            $data  = ($url == 'javascript: void(0);') ? '' : ' data-toggle="ajax" data-target="' . $target . '"' . $menuLink;
            ?>
            <li<?php echo $class; ?>>
                <a href="<?php echo $url; ?>"<?php echo $data.$formExit; ?>>
                    <span><?php echo $i; ?></span>
                </a>
            </li>
            <?php endfor; ?>

            <?php
            $urlPage = "/" . $page + 1;
            $url     = ($urlPage <= $totalPages) ? $baseUrl . $urlPage . $queryString : 'javascript: void(0);';
            $data    = ($url == 'javascript: void(0);') ? '' : 'data-toggle="ajax" data-target="' . $target . '"' . $menuLink;
            $class   = ($urlPage > $totalPages) ? ' class="disabled"' : '';
            ?>
            <li<?php echo $class; ?>>
                <?php  ?>
                <a href="<?php echo $url; ?>" <?php echo $data.$formExit; ?>>
                    <i class="fa fa-angle-right"></i>
                </a>
            </li>

            <?php
            $urlPage = "/" . $page + $range;
            if ($urlPage > $totalPages)
                $urlPage = $totalPages;
            $url     = ($page < $totalPages && $totalPages > $range) ? $baseUrl . $urlPage . $queryString : 'javascript: void(0);';
            $data    = ($url == 'javascript: void(0);') ? '' : ' data-toggle="ajax" data-target="' . $target . '"' . $menuLink;
            $class   = ($urlPage == $totalPages || $page === $totalPages) ? ' class="disabled"' : '';
            ?>
            <li<?php echo $class; ?>>
                <?php  ?>
                <a href="<?php echo $url; ?>"<?php echo $data.$formExit; ?>>
                    <i class="fa fa-angle-double-right"></i>
                </a>
            </li>
        </ul>
        <div class="clearfix"></div>
    </div>
</div>
<?php endforeach; ?><commit_msg>Fix gh-20 - Pagination errors<commit_after><?php
/**
 * @package     Mautic
 * @copyright   2014 Mautic Contributors. All rights reserved.
 * @author      Mautic
 * @link        http://mautic.org
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */

$target = (!empty($target)) ? $target : '.page-list';
$tmpl   = (!empty($tmpl)) ? $tmpl : 'list';

$limit  = (!isset($limit)) ? 30 : (int) $limit;

if (!isset($range)) {
    $range = 4;
}

if ($page <= 0) {
    $page = 1;
} else {
    $page = (int) $page;
}

$totalPages = ($limit) ? (int) ceil($totalItems / $limit) : 1;

$pageClass = (!isset($paginationClass)) ? "" : " pagination-$paginationClass";
$menuLink  = (!empty($menuLinkId)) ? " data-menu-link=\"$menuLinkId\"" : "";
$paginationWrapper = isset($paginationWrapper) ? $paginationWrapper :  "pagination-wrapper pull-left ml-md mr-md";

$queryString = '?tmpl=' . $tmpl . (isset($queryString) ? $queryString : '');

$limitOptions = array(
    5   => '5',
    10  => '10',
    15  => '15',
    20  => '20',
    25  => '25',
    30  => '30',
    50  => '50',
    100 => '100',
    0   => 'all'
);

$formExit = (!empty($ignoreFormExit)) ? ' data-ignore-formexit="true"' : '';

$responsiveViewports = array('desktop', 'mobile');

foreach ($responsiveViewports as $viewport):

if ($viewport == 'mobile'):
    $paginationClass   = 'sm';
    $pageClass         = 'pagination-sm';
    $responsiveClass   = 'visible-xs hidden-sm hidden-md hidden-lg';
    $paginationWrapper = "pagination-wrapper pull-left nm";
else:
    $responsiveClass = 'hidden-xs visible-sm visible-md visible-lg';
endif;

?>
<div class="<?php echo $responsiveClass; ?>">
    <?php if (empty($fixedLimit)): ?>
        <div class="pull-right">
            <?php $class = (!empty($paginationClass)) ? " input-{$paginationClass}" : ""; ?>
            <select autocomplete="off" class="form-control not-chosen pagination-limit<?php echo $class; ?>" onchange="Mautic.limitTableData('<?php echo $sessionVar; ?>',this.value,'<?php echo $tmpl; ?>','<?php echo $target; ?>'<?php if (!empty($baseUrl)): ?>, '<?php echo $baseUrl; ?>'<?php endif; ?>);">
                <?php foreach ($limitOptions as $value => $label): ?>
                <?php $selected = ($limit === $value) ? ' selected="selected"': '';?>
                <option<?php echo $selected; ?> value="<?php echo $value; ?>"><?php echo $view['translator']->trans('mautic.core.pagination.'.$label); ?></option>
                <?php endforeach; ?>
            </select>
        </div>
    <?php endif; ?>

    <div class="<?php echo $paginationWrapper; ?>">
        <ul class="pagination nm <?php echo $pageClass; ?>">
            <?php
            $urlPage = "/" . ($page - $range);
            $url     = (($page - $range) > 0) ? $baseUrl . $urlPage . $queryString : 'javascript: void(0);';
            $data    = ($url == 'javascript: void(0);') ? '' : ' data-toggle="ajax" data-target="' . $target . '"' . $menuLink;
            $class   = (($page - $range) <= 0) ? ' class="disabled"' : '';
            ?>
            <li<?php echo $class; ?>>
                <?php  ?>
                <a href="<?php echo $url; ?>"<?php echo $data.$formExit; ?>>
                    <i class="fa fa-angle-double-left"></i>
                </a>
            </li>

            <?php
            $urlPage = "/" . ($page - 1);
            $url     = (($page - 1) >= 1) ? $baseUrl . $urlPage . $queryString : 'javascript: void(0);';
            $data    = ($url == 'javascript: void(0);') ? '' : ' data-toggle="ajax" data-target="' . $target . '"' . $menuLink;
            $class   = (($page - 1) <= 0) ? ' class="disabled"' : '';
            ?>
            <li<?php echo $class; ?>>
                <?php  ?>
                <a href="<?php echo $url; ?>"<?php echo $data.$formExit; ?>>
                    <i class="fa fa-angle-left"></i>
                </a>
            </li>

            <?php
            $startPage = $page - $range + 1;
            if ($startPage <= 0) {
                $startPage = 1;
            }
            $lastPage = $startPage + $range - 1;
            if ($lastPage > $totalPages) {
                $lastPage = $totalPages;
            }
            ?>
            <?php for ($i=$startPage; $i<=$lastPage; $i++): ?>
            <?php
            $class = ($page === (int) $i) ? ' class="active"' : '';
            $url   = ($page === (int) $i) ? 'javascript: void(0);' : $baseUrl . "/" . $i . $queryString;
            $data  = ($url == 'javascript: void(0);') ? '' : ' data-toggle="ajax" data-target="' . $target . '"' . $menuLink;
            ?>
            <li<?php echo $class; ?>>
                <a href="<?php echo $url; ?>"<?php echo $data.$formExit; ?>>
                    <span><?php echo $i; ?></span>
                </a>
            </li>
            <?php endfor; ?>

            <?php
            $urlPage = "/" . ($page + 1);
            $url     = (($page + 1) <= $totalPages) ? $baseUrl . $urlPage . $queryString : 'javascript: void(0);';
            $data    = ($url == 'javascript: void(0);') ? '' : 'data-toggle="ajax" data-target="' . $target . '"' . $menuLink;
            $class   = (($page + 1) > $totalPages) ? ' class="disabled"' : '';
            ?>
            <li<?php echo $class; ?>>
                <?php  ?>
                <a href="<?php echo $url; ?>" <?php echo $data.$formExit; ?>>
                    <i class="fa fa-angle-right"></i>
                </a>
            </li>

            <?php
            $urlPage = "/" . ($page + $range);
            if (($page + $range) > $totalPages)
                $urlPage = "/" . $totalPages;
            $url     = ($page < $totalPages && $totalPages > $range) ? $baseUrl . $urlPage . $queryString : 'javascript: void(0);';
            $data    = ($url == 'javascript: void(0);') ? '' : ' data-toggle="ajax" data-target="' . $target . '"' . $menuLink;
            $class   = (($page + $range) == $totalPages || $page === $totalPages) ? ' class="disabled"' : '';
            ?>
            <li<?php echo $class; ?>>
                <?php  ?>
                <a href="<?php echo $url; ?>"<?php echo $data.$formExit; ?>>
                    <i class="fa fa-angle-double-right"></i>
                </a>
            </li>
        </ul>
        <div class="clearfix"></div>
    </div>
</div>
<?php endforeach; ?>
{'fraction_non_alphanumeric': 0.21725340945131622, 'fraction_numerical': 0.010941960038058992, 'mean_word_length': 1.9055517161944253, 'pattern_counts': {'":': 0, '<': 203, '<?xml version=': 0, '>': 223, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '369322', 'n_tokens_mistral': 4156, 'n_tokens_neox': 3998, 'n_words': 881}