Elgg 1.8 Pagination: Add last page to be listed and dotted spacer (like 1.9)

Due to some reasons (plugins not working for the new elgg version), we decided to stay to Elgg 1.8 for now. I'm trying to adapt the nice pagination from 1.9 for example adding the last page and dotted spacer, but can't seem to code it correctly (as 1.8 does not use elgg_format_element function). Is there a way we could code the 1.9 pagination for 1.8 users?

So far, below doesn't seem to work:

// added dotted spacer
if (1 < ($start_page - 2)) {
    $pages[] = ['text' => '...'];
} elseif ($start_page == 3) {
    $pages[2] = [];
}

............

// add last page to be listed
if ($total_pages >= ($start_page + 5)) {
    $pages[$total_pages] = [];
}

............

echo '<ul class="elgg-pagination">';

if ($pages->prev['href']) {
    $link = elgg_view('output/url', $pages->prev);
    echo "<li>$link</li>";
} else {
    echo "<li class=\"elgg-state-disabled\"><span>{$pages->prev['text']}</span></li>";
}

foreach ($pages as $page_num => $page) {
    if ($page_num == $current_page) {
        echo "<li class=\"elgg-state-selected\"><span>$page_num</span></li>";
    } else {
        $href = elgg_extract('href', $page);
        $text = elgg_extract('text', $page, $page_num);
        
        if (!$href) {
            $page_offset = (($page_num - $current_page) * $limit) + $offset;
            if ($page_offset <= 0) {
                // don't include offset=0
                $page_offset = null;
            }
            $href = elgg_http_add_url_query_elements($base_url, array($offset_key => $page_offset));
        }
        
        if ($href) {
            $link = elgg_view('output/url', array(
                'href' => $href,
                'text' => $text,
                'is_trusted' => true,
            ));
            echo "<li>$link</li>";
        } else {
            echo "<li class=\"elgg-state-disabled\"><span>{$page['text']}</span></li>";
        }
    }
}

echo '</ul>';

 

 

 

  • cant seem to make it work, really... any help?

  • looks like the dev team is too busy with elgg 1.9 and 1.0 and completely abandoned 1.8 version. fixed this myself after a great deal of research. anyone who is interested, just send me a private message. 

     

    • Are you aware that it's currently weekend? Everyone here is a volunteer. So, it might happen that people want to relax at least a little bit on weekends instead of being on duty all around the clock to answer questions.
    • It's not about "abandoning Elgg 1.8". But you should understand that the idea is rather to move forward with Elgg instead of backporting new features of later versions of Elgg to older versions. After all, you do have the code of the new Elgg versions for reference, if you really need to backport a feature. Generally speaking (not necessarily the case with the pagination here), there could be unwanted side-effects when backporting features. Giving you some hints how to do it might not be that time-consuming. But it might not be that easy in some cases to say for sure if other parts of Elgg might get broken when backporting stuff.
    • If you are so keen on prompt support, why don't you post your solution in public right away instead of requiring people to ask for it? After all, that's what you were interesting in here, too. Giving a solution - even if you found it on your own in the end - is always helpful not only for people who are looking for a solution for the same problem but maybe also for people who just want to learn more about Elgg in general.
  • thanks iionly... thanks for spending time to explain rather than help. I'm not so keen about prompt support. for the record, it was posted 2 days ago. anyway, i felt like everyone is so quick at answering related support request for 1.9 and above, but not for 1.8 users who is rather stuck at the moment due to risks and complexity of the update and unsupported plugins that we're currently using. 

    again, thank you for taking time to elaborate the reasons why support was not provided. i'm pretty impressed of of the length of your answer.

  • thanks RvR.. strangely though this gives a blank page instead. something might be broken in the code... could it be the php version perhaps?

  • could it be the php version perhaps?

    Yepp. PHP version >= 5.4 only