collapse

* Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

* User Info

 
 
Welcome, Guest. Please login or register.

* Who's Online

  • Dot Guests: 561
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 PM
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 PM
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 PM
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 PM
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 AM
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 AM
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 AM
  • emanuele: [link]
    November 01, 2016, 12:43:50 PM
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 PM
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 AM
  • {OCS}MasterSeal: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 AM
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 PM

* Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]

Installation errors? Mod incompatibilities? Upgrade problems? Make your way over to the Install and Upgrade Support board for all your solutions!

Author Topic: BoardNews block and pagination question  (Read 17016 times)

0 Members and 2 Guests are viewing this topic.

Offline Mick.

  • Comrade
  • *
  • Posts: 77
  • Gender: Male
  • Premium SMF Themes
    • idesignSMF
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
BoardNews block and pagination question
« on: August 01, 2013, 03:59:21 PM »
So I made an HTML page and added a boardnews block to it to show 10 topics. My question is, where is the pagination at the bottom of the page? I mean, I have lots of topics but no pagination to the next 10 topics.

http://idesign360.com/community/index.php/page,tutorials.html

Thanx,
Mick.

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: BoardNews block and pagination question
« Reply #1 on: August 02, 2013, 01:04:52 PM »
Hmm... what is the total number of topics the boardnews block THINKS it is going to have to display in that case?
You can find that just before all the pagination calculations begin, I think.
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: BoardNews block and pagination question
« Reply #2 on: August 02, 2013, 10:23:16 PM »
Try this in a custom PHP block:
Code: [Select]
global $context;

// Adjust your specific parameters
// when/if using the pagination for other blocks on the same page, remember to increment the formId
$parameters['boards'] = 1;
$parameters['limit'] = 50;
$parameters['perPage'] = 5;
$parameters['display'] = 'full';
$parameters['bodyStyle'] = 'windowbg';
$parameters['formId'] = 1;

// Do not bother altering the rest of the code...
$context['current_page' . $parameters['formId']] = !empty($context['current_page' . $parameters['formId']]) ? (int)$context['current_page' . $parameters['formId']] : 1;
$context['current_page' . $parameters['formId']] = (!empty($_REQUEST['current_page' . $parameters['formId']]) ? (int)$_REQUEST['current_page' . $parameters['formId']]-1 : $context['current_page' . $parameters['formId']] - 1);
customRecent($parameters);

function custom_pagination($content, $count=20, $id=1)
{
/* PHP pagination - max 7 visible integers and 6 periods (all links) - current page encircled with square brackets
* This php pagination code was developed by Underdog copyright 2013
* http://webdevelop.comli.com
* Licensed under the GNU Public License: http://www.gnu.org/licenses/gpl.html
*/

// This particular function is only used when opting an entire table else it is not necessary
global $context;

/*  Set the $context variables for the display template  */
$context['current_count' . $id] = count($content);
$context['current_pages' . $id] = (($context['current_count' . $id]) / $count) + 1;

if (count($content) <= $count || $count < 2)
{
$context['current_pages' . $id] = 0;
return $content;
}

if (($context['current_count' . $id] / $count) == (int)($context['current_count' . $id] / $count))
$context['current_pages' . $id] = ($context['current_count' . $id] / $count);

$context['current_showResults' . $id] = array(((int)$context['current_page' . $id] * $count), (((int)$context['current_page' . $id] + 1) * $count) - 1);
       



if ((int)$context['current_page' . $id]+1 == (int)$context['current_pages' . $id])
    $context['current_showResults' . $id][1] = count($content);
else
    $context['current_showResults' . $id][1] = (int)$context['current_page' . $id]*$count + ($count-1);
   
foreach($content as $key => $var)
{
if ((int)$key >= (int)$context['current_showResults' . $id][0] && (int)$key <= (int)$context['current_showResults' . $id][1])
$new_content[] = $var;
}

if (!empty($new_content))
$context['current_showResults' . $id][1] = ((int)$context['current_page' . $id]*$count) + count($new_content);
else
$new_content = $content;

return $new_content;
}

function custom_pages($lang, $anchor, $link, $pages, $sort=false, $order=false, $id=1, $style='windowbg')
{
/* PHP pagination - max 7 visible integers and 6 periods (all links) - current page encircled with square brackets
* This php pagination code was developed by Underdog copyright 2013
* http://webdevelop.comli.com
* Licensed under the GNU Public License: http://www.gnu.org/licenses/gpl.html
*/
global $context, $txt, $scripturl;

$name = 'custom_SpForm' . $id;
$pageCount = 1;
$display = array('page' => false, 'pages' => '0');
$page = !empty($context['current_page' . $id]) ? (int)$context['current_page' . $id] : 0;
$display['pages'] = !empty($pages) ? (int)$pages : 1;

if ($display['pages'] > 1)
{
$display['page'] =  '
<script type="text/javascript"><!-- // --><![CDATA[
function changeColor(s, formId)
{
for (var i=1; i<=3; i++)
                document.getElementById("link"+i+formId).style.color = i==s ? "red" : "blue";
}
function changeColorBack(s, formId)
{
for (var i=1; i<=3; i++)
document.getElementById("link"+i+formId).style.color = i==s ? "blue" : "blue";
}
// ]]></script>
<form name="' . $name .'" action="'.$link.'" method="post" id="' . $name .'">
<span style="text-align:center;position:relative;width:99%;display:inline-block;">
' . $lang . '<br />';

while ($pageCount < (int)$display['pages']+1)
{
$current_page = (int)$page+1;
$total = (int)$display['pages'];
       
if ($pageCount == 1 || $pageCount == $total || $pageCount == $current_page || $pageCount == $current_page+1 ||
    $pageCount == $current_page+2 || $pageCount == $current_page-1 || $pageCount == $current_page-2)
{
                if ((int)$pageCount == (int)$page+1)
$display['page'] .= '
[<input class="' . $style . '" type="button" onclick="this.href=\'javascript: void(0)\';" onmouseout="changeColorBack('. $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="' . $pageCount . '" />] ';
        else
$display['page'] .= '
<input class="' . $style . '" type="submit" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="' . $pageCount . '"  /> ';
}
elseif ($pageCount < $current_page-2 && $pageCount > $current_page-6)
$display['page'] .= '
<input class="' . $style . '" type="submit" onchange="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pagecount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="." onclick="sp_submitPage();" /> ';
elseif ($pageCount > $current_page+2 && $pageCount < $current_page+6)
$display['page'] .= '
<input class="' . $style . '" type="submit" onchange="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pagecount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="." onclick="sp_submitPage();" /> ';

$pageCount++;
}

$display['page'] .= '
</span>   
</form>';
}

return $display;
}

/* Current url */
function currentCustomPage($pageURL = 'http://')
{
if (!empty($_SERVER["HTTPS"]))
$pageURL = "https://";   
   
if ($_SERVER["SERVER_PORT"] != "80")
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
else
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

return $pageURL;
}

function customRecent($parameters)
{
global $txt, $scripturl, $settings, $context, $color_profile;

$boards = !empty($parameters['boards']) ? explode('|', $parameters['boards']) : null;
$limit = !empty($parameters['limit']) ? (int)$parameters['limit'] : 15;
$type = 'ssi_recent' . (empty($parameters['type']) ? 'Posts' : 'Topics');
$display = empty($parameters['display']) ? 'compact' : 'full';
$style = !empty($parameters['bodyStyle']) ? $parameters['bodyStyle'] : 'windowbg';
$id = !empty($parameters['formId']) ? (int)$parameters['formId'] : 1;
$perPage = !empty($parameters['perPage']) ? (int)$parameters['perPage'] : 10;

// $recent_items = $type($limit, null, $boards, 'array');
       
        $items = custom_pagination($type($limit, null, $boards, 'array'), $perPage, $id);       
       
        $context['custom_display' . $id] = array('page' => false, 'pages' => '0');
$context['custom_display' . $id] = custom_pages($txt['pages'], false, currentCustomPage(), $context['current_pages' . $id], false, false, $id, $style);
       
if (empty($items))
{
echo '
', $txt['error_sp_no_posts_found'];
return;
}
else
$items[count($items) - 1]['is_last'] = true;

$colorids = array();
foreach ($items as $item)
$colorids[] = $item['poster']['id'];

if (!empty($colorids) && sp_loadColors($colorids) !== false)
{
foreach ($items as $k => $p)
{
if (!empty($color_profile[$p['poster']['id']]['link']))
$items[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];
}
}

if ($display == 'compact')
{
foreach ($items as $key => $item)
echo '
<a href="', $item['href'], '">', $item['subject'], '</a> <span class="smalltext">', $txt['by'], ' ', $item['poster']['link'], $item['new'] ? '' : ' <a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', $item['time'], ']</span><br />', empty($item['is_last']) ? '<hr />' : '';
}
elseif ($display == 'full')
{
echo '
<table class="sp_fullwidth">';

foreach ($items as $item)
echo '
<tr>
<td class="sp_recent_icon sp_center">
', sp_embed_image(empty($parameters['type']) ? 'post' : 'topic'), '
</td>
<td class="sp_recent_subject">
<a href="', $item['href'], '">', $item['subject'], '</a>
', $item['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', $item['board']['link'], ']
</td>
<td class="sp_recent_info sp_right">
', $item['poster']['link'], '<br />', $item['time'], '
</td>
</tr>';

echo '
</table>';
}
       
        echo $context['custom_display' . $id]['page'];   
}



If recent topics is not what you are after, I can adjust this to show other info with the custom pagination I developed. Just inform me if the type of data displayed is correct or incorrect.

Note: The formId was used in various aspects of the code so the pagination routine can be used with other blocks (possibly showing other output) on the same page if opted.
« Last Edit: August 19, 2013, 10:45:00 AM by Underdog »

Offline Mick.

  • Comrade
  • *
  • Posts: 77
  • Gender: Male
  • Premium SMF Themes
    • idesignSMF
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: BoardNews block and pagination question
« Reply #3 on: August 02, 2013, 11:47:22 PM »
Awesome. Let me try this but it would be Monday or so. I'm away for the weekend with the fam.

Yes, it would be recent topics just like the boardnews block. The pagination I'm after is thine seen at the bottom when adding topics to an article. That would be my front page. I display about 5 article categories there.  Anywho, I'll get back to yas. Thanks guys.

Mick.

Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: BoardNews block and pagination question
« Reply #4 on: August 02, 2013, 11:54:25 PM »
Mick G,

  Just adjust the parameters at the start of the block to your specifics including the specific board id, post/topic limit and amount per page. After which it should display as you wish.

Offline Mick.

  • Comrade
  • *
  • Posts: 77
  • Gender: Male
  • Premium SMF Themes
    • idesignSMF
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: BoardNews block and pagination question
« Reply #5 on: August 04, 2013, 09:38:56 AM »
Oh man, not quite what i was looking for. This seems to be a list of articles like seen in the sp admin block chooser but with pagination. What im looking for is pagination in a boardnews block.

Offline Mick.

  • Comrade
  • *
  • Posts: 77
  • Gender: Male
  • Premium SMF Themes
    • idesignSMF
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: BoardNews block and pagination question
« Reply #6 on: August 04, 2013, 10:43:25 AM »
This is what im getting at...

My categories with boardnews block that shows 10 topics.

http://idesign360.com/community/index.php/page,web_development.html
http://idesign360.com/community/index.php/page,tutorials.html
http://idesign360.com/community/index.php/page,freebies.html

They pull the topics from such boards from the forum using the bordnews block but as you can see, it doesnt show pagination at the bottom.

Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: BoardNews block and pagination question
« Reply #7 on: August 04, 2013, 03:25:37 PM »

Custom PHP block -> no title and no body.
If the number submits are the wrong color, simply select a css class from your theme that matches the foreground (or create one and use it).

Code: [Select]
// Custom News
global $context;

// Adjust your specific parameters
// when/if using the pagination for other blocks on the same page, remember to increment the formId
$parameters['board'] = '1';
$parameters['limit'] = 50;
$parameters['perPage'] = 5;
$parameters['bodyStyle'] = 'clear';
$parameters['formId'] = 2;

// Do not bother altering the rest of the code...
$context['current_page' . $parameters['formId']] = !empty($context['current_page' . $parameters['formId']]) ? (int)$context['current_page' . $parameters['formId']] : 1;
$context['current_page' . $parameters['formId']] = (!empty($_REQUEST['current_page' . $parameters['formId']]) ? (int)$_REQUEST['current_page' . $parameters['formId']]-1 : $context['current_page' . $parameters['formId']] - 1);
customNews($parameters);

function custom_newsPages($lang, $anchor, $link, $pages, $sort=false, $order=false, $id=1, $style='windowbg')
{
/* PHP pagination - max 7 visible integers and 6 periods (all links) - current page encircled with square brackets
* This php pagination code was developed by Underdog copyright 2013
* http://webdevelop.comli.com
* Licensed under the GNU Public License: http://www.gnu.org/licenses/gpl.html
*/
global $context, $txt, $scripturl;

$name = 'custom_SpForm' . $id;
$pageCount = 1;
$display = array('page' => false, 'pages' => '0');
$page = !empty($context['current_page' . $id]) ? (int)$context['current_page' . $id] : 0;
$display['pages'] = !empty($pages) ? (int)$pages : 1;
$class = !empty($style) ? 'class="' . $style . '"' : '';

if ($display['pages'] > 1)
{
$display['page'] =  '
<script type="text/javascript"><!-- // --><![CDATA[
function changeColor(s, formId)
{
for (var i=1; i<=3; i++)
                document.getElementById("link"+i+formId).style.color = i==s ? "red" : "blue";
}
function changeColorBack(s, formId)
{
for (var i=1; i<=3; i++)
document.getElementById("link"+i+formId).style.color = i==s ? "blue" : "blue";
}
// ]]></script>
<form name="' . $name .'" action="'.$link.'" method="post" id="' . $name .'">
<span style="text-align:center;position:relative;width:99%;display:inline-block;">
' . $lang . '<br />';

while ($pageCount < (int)$display['pages']+1)
{
$current_page = (int)$page+1;
$total = (int)$display['pages'];
       
if ($pageCount == 1 || $pageCount == $total || $pageCount == $current_page || $pageCount == $current_page+1 ||
    $pageCount == $current_page+2 || $pageCount == $current_page-1 || $pageCount == $current_page-2)
{
                if ((int)$pageCount == (int)$page+1)
$display['page'] .= '
[<input ' . $class . ' type="button" onclick="this.href=\'javascript: void(0)\';" onmouseout="changeColorBack('. $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="' . $pageCount . '" />] ';
        else
$display['page'] .= '
<input ' . $class . ' type="submit" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="' . $pageCount . '"  /> ';
}
elseif ($pageCount < $current_page-2 && $pageCount > $current_page-6)
$display['page'] .= '
<input ' . $class . ' type="submit" onchange="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pagecount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="." onclick="sp_submitPage();" /> ';
elseif ($pageCount > $current_page+2 && $pageCount < $current_page+6)
$display['page'] .= '
<input ' . $class . ' type="submit" onchange="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pagecount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="." onclick="sp_submitPage();" /> ';

$pageCount++;
}

$display['page'] .= '
</span>   
</form>';
}

return $display;
}

/* Current url */
function currentCustomNewsPage($pageURL = 'http://')
{
if (!empty($_SERVER["HTTPS"]))
$pageURL = "https://";   
   
if ($_SERVER["SERVER_PORT"] != "80")
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
else
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

return $pageURL;
}

function customNews($parameters)
{
global $scripturl, $txt, $settings, $modSettings, $context, $smcFunc, $color_profile;

$board = !empty($parameters['board']) ? explode('|', $parameters['board']) : null;
$limit = !empty($parameters['limit']) ? (int) $parameters['limit'] : 5;
$start = !empty($parameters['start']) ? (int) $parameters['start'] : 0;
$length = isset($parameters['length']) ? (int) $parameters['length'] : 250;
$avatars = !empty($parameters['avatar']);
$style = !empty($parameters['bodyStyle']) ? $parameters['bodyStyle'] : 'windowbg';
$id = !empty($parameters['formId']) ? (int)$parameters['formId'] : 1;
$perPage = !empty($parameters['perPage']) ? (int)$parameters['perPage'] : 10;
$page = $context['current_page' . $id] * $perPage;
$context['custom_display' . $id] = array('page' => false, 'pages' => '0');

$limit = max(0, $limit);
$start = max(0, $start);

loadLanguage('Stats');

$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';

$request = $smcFunc['db_query']('', '
SELECT t.id_first_msg
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
WHERE ' . (empty($board) ? '{query_see_board}
AND t.id_first_msg >= {int:min_msg_id}' : 't.id_board IN ({array_int:current_board})') . ($modSettings['postmod_active'] ? '
AND t.approved = {int:is_approved}' : '') . '
AND (t.locked != {int:locked} OR m.icon != {string:icon})
ORDER BY t.id_first_msg DESC
LIMIT {int:limit}',
array(
'current_board' => $board,
'min_msg_id' => $modSettings['maxMsgID'] - 45 * min($limit, 5),
'is_approved' => 1,
'locked' => 1,
'icon' => 'moved',
'limit' => $limit,
)
);
$posts = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$posts[] = $row['id_first_msg'];
$smcFunc['db_free_result']($request);
$nRows = array_shift(array_values($posts));

if (empty($posts))
{
echo '
', $txt['error_sp_no_posts_found'];
return;
}
elseif (!empty($perPage))
{
$limit = count($posts);
$start = !empty($_REQUEST['news' . $id]) ? (int) $_REQUEST['news' . $id] : 0;

$clean_url = preg_replace('~news' . $id . '=\d+;?~', '', $_SERVER['REQUEST_URL']);
$current_url = $clean_url . (strpos($clean_url, '?') !== false ? (in_array(substr($clean_url, -1), array(';', '?')) ? '' : ';') : '?');

// $page_index = constructPageIndex($current_url . 'news' . $id . '=%1$d', $start, $limit, $perPage, true);
}

$request = $smcFunc['db_query']('', '
SELECT
m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, mem.avatar,
a.id_attach, a.attachment_type, a.filename, t.num_views
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
WHERE t.id_first_msg IN ({array_int:post_list})
ORDER BY t.id_first_msg DESC
LIMIT ' . (!empty($perPage) ? '{int:start}, ' : '') . '{int:limit}',
array(
'post_list' => $posts,
'start' => $page,
'limit' => !empty($perPage) ? $perPage : $limit,
)
);
$return = array();
$colorids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$limited = false;
if (($cutoff = $smcFunc['strpos']($row['body'], '')) !== false)
{
$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
$limited = true;
}
elseif (!empty($length) && $smcFunc['strlen']($row['body']) > $length)
{
$row['body'] = $smcFunc['substr']($row['body'], 0, $length);
$limited = true;
}

$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);

// Only place an ellipsis if the body has been shortened.
if ($limited)
$row['body'] .= '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0" title="' . $row['subject'] . '">...</a>';

if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
{
$avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '';
$avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '';
}
else
{
$avatar_width = '';
$avatar_height = '';
}

if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

censorText($row['subject']);
censorText($row['body']);

if ($modSettings['sp_resize_images'])
$row['body'] = preg_replace('~class="bbc_img~i', 'class="bbc_img sp_article', $row['body']);

if (!empty($row['id_member']))
$colorids[$row['id_member']] = $row['id_member'];

$return[] = array(
'id' => $row['id_topic'],
'message_id' => $row['id_msg'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['subject'],
'time' => timeformat($row['poster_time']),
'views' => $row['num_views'],
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $txt['sp-read_more'] . '</a>',
'replies' => $row['num_replies'],
'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'],
'comment_link' => !empty($row['locked']) ? '' : '| <a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
'new_comment' => !empty($row['locked']) ? '' : '| <a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
'poster' => array(
'id' => $row['id_member'],
'name' => $row['poster_name'],
'href' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
'link' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name']
),
'locked' => !empty($row['locked']),
'is_last' => false,
'avatar' => array(
'name' => $row['avatar'],
'image' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? '<img src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
'href' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar'])
),
);
}
$smcFunc['db_free_result']($request);

if (empty($return))
{
echo '
', $txt['error_sp_no_posts_found'];
return;
}

$return[count($return) - 1]['is_last'] = true;

if (!empty($colorids) && sp_loadColors($colorids) !== false)
{
foreach ($return as $k => $p)
{
if (!empty($color_profile[$p['poster']['id']]['link']))
$return[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];
}
}

if ($context['SPortal']['core_compat'])
{
foreach ($return as $news)
{
echo '
<div class="tborder sp_article_content">
<table class="sp_block">
<tr class="catbg">
<td class="sp_middle">', $news['icon'], '</td>
<td class="sp_middle sp_regular_padding sp_fullwidth"><a href="', $news['href'], '" >', $news['subject'], '</a></td>
</tr>
<tr class="windowbg">
<td class="sp_regular_padding" colspan="2">';

if ($avatars && $news['avatar']['name'] !== null && !empty($news['avatar']['href']))
echo '
<a href="', $scripturl, '?action=profile;u=', $news['poster']['id'], '"><img src="', $news['avatar']['href'], '" alt="', $news['poster']['name'], '" width="30" style="float: right;" /></a>
<div class="middletext">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], '<br />', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';
else
echo '
<div class="middletext">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], ' | ', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';

echo '
<div class="post"><hr />', $news['body'], '<br /><br /></div>
</td>
</tr>
<tr>
<td class="windowbg2" colspan="2">
<div class="sp_right sp_regular_padding">', $news['link'], ' ',  $news['new_comment'], '</div>
</td>
</tr>
</table>
</div>';
}
}
else
{
foreach ($return as $news)
{
echo '
<div class="cat_bar">
<h3 class="catbg">
<span class="sp_float_left sp_article_icon">', $news['icon'], '</span><a href="', $news['href'], '" >', $news['subject'], '</a>
</h3>
</div>
<div class="windowbg sp_article_content">
<span class="topslice"><span></span></span>
<div class="sp_content_padding">';

if ($avatars && $news['avatar']['name'] !== null && !empty($news['avatar']['href']))
echo '
<a href="', $scripturl, '?action=profile;u=', $news['poster']['id'], '"><img src="', $news['avatar']['href'], '" alt="', $news['poster']['name'], '" width="30" class="sp_float_right" /></a>
<div class="middletext">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], '<br />', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';
else
echo '
<div class="middletext">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], ' | ', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';

echo '
<div class="post"><hr />', $news['body'], '</div>
<div class="sp_right">', $news['link'], ' ',  $news['new_comment'], '</div>
</div>
<span class="botslice"><span></span></span>
</div>';
}
}

if (!empty($per_page))
echo '
<div class="sp_page_index">', $txt['sp-articlesPages'], ': ', $page_index, '</div>';

$context['current_pages' . $id] = (($nRows-1) / $perPage) + 1;
$context['custom_display' . $id] = custom_newsPages($txt['pages'], false, currentCustomNewsPage(), $context['current_pages' . $id], false, false, $id, $style);
       
echo $context['custom_display' . $id]['page'];
}

Offline Mick.

  • Comrade
  • *
  • Posts: 77
  • Gender: Male
  • Premium SMF Themes
    • idesignSMF
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: BoardNews block and pagination question
« Reply #8 on: August 04, 2013, 03:44:57 PM »
Now we're talking. Exactly what i wanted. Just needs some TLC  for the pagination with css and such.

One thing tho, the pagination displays more pages than actual.

http://idesign360.com/community/index.php/page,page693.html

It shows 175 pages when in fact i should 2-3 pages.

Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: BoardNews block and pagination question
« Reply #9 on: August 05, 2013, 12:09:23 AM »
Mick.,

  I do not see this behavior when testing locally although I will have a look to see if I configured something incorrectly in error. Did you set your limit?

For example:

  If you want to display the last 30 topics with 10 topics per page for board id#1, configure the following settings as such:
Code: [Select]
$parameters['board'] = '1';
$parameters['limit'] = 30;
$parameters['perPage'] = 10;
$parameters['bodyStyle'] = 'clear';
$parameters['formId'] = 2;

.. if you want more than 1 board, use a vertical bar to separate each board id.

ie.
Code: [Select]
$parameters['board'] = '1|2|3';
« Last Edit: August 05, 2013, 12:29:40 AM by Underdog »

Offline Mick.

  • Comrade
  • *
  • Posts: 77
  • Gender: Male
  • Premium SMF Themes
    • idesignSMF
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: BoardNews block and pagination question
« Reply #10 on: August 05, 2013, 07:54:23 AM »
Do you have any errors?

I get 2.

Undefined variable: pagecount
Undefined offset: 0

Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: BoardNews block and pagination question
« Reply #11 on: August 05, 2013, 08:56:39 AM »
Mick,

  No I do not see any errors. btw it is $pageCount that is used in one of the functions (not $pagecount), did you alter the code in any way? Please try the default code. 

Offline Mick.

  • Comrade
  • *
  • Posts: 77
  • Gender: Male
  • Premium SMF Themes
    • idesignSMF
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: BoardNews block and pagination question
« Reply #12 on: August 05, 2013, 10:06:27 AM »
Mick,

  No I do not see any errors. btw it is $pageCount that is used in one of the functions (not $pagecount), did you alter the code in any way? Please try the default code.

I did at the very bottom to suit my needs.
Code: [Select]
// Custom News
global $context;

// Adjust your specific parameters
// when/if using the pagination for other blocks on the same page, remember to increment the formId
$parameters['board'] = '78';
$parameters['limit'] = 50;
$parameters['perPage'] = 10;
$parameters['bodyStyle'] = 'clear';
$parameters['formId'] = 2;

// Do not bother altering the rest of the code...
$context['current_page' . $parameters['formId']] = !empty($context['current_page' . $parameters['formId']]) ? (int)$context['current_page' . $parameters['formId']] : 1;
$context['current_page' . $parameters['formId']] = (!empty($_REQUEST['current_page' . $parameters['formId']]) ? (int)$_REQUEST['current_page' . $parameters['formId']]-1 : $context['current_page' . $parameters['formId']] - 1);
customNews($parameters);

function custom_newsPages($lang, $anchor, $link, $pages, $sort=false, $order=false, $id=1, $style='windowbg')
{
/* PHP pagination - max 7 visible integers and 6 periods (all links) - current page encircled with square brackets
* This php pagination code was developed by Underdog copyright 2013
* http://webdevelop.comli.com
* Licensed under the GNU Public License: http://www.gnu.org/licenses/gpl.html
*/
global $context, $txt, $scripturl;

$name = 'custom_SpForm' . $id;
$pageCount = 1;
$display = array('page' => false, 'pages' => '0');
$page = !empty($context['current_page' . $id]) ? (int)$context['current_page' . $id] : 0;
$display['pages'] = !empty($pages) ? (int)$pages : 1;
$class = !empty($style) ? 'class="' . $style . '"' : '';

if ($display['pages'] > 1)
{
$display['page'] =  '
<script type="text/javascript"><!-- // --><![CDATA[
function changeColor(s, formId)
{
for (var i=1; i<=3; i++)
                document.getElementById("link"+i+formId).style.color = i==s ? "red" : "blue";
}
function changeColorBack(s, formId)
{
for (var i=1; i<=3; i++)
document.getElementById("link"+i+formId).style.color = i==s ? "blue" : "blue";
}
// ]]></script>
<form name="' . $name .'" action="'.$link.'" method="post" id="' . $name .'">
<span style="text-align:center;position:relative;width:99%;display:inline-block;">
' . $lang . '';

while ($pageCount < (int)$display['pages']+1)
{
$current_page = (int)$page+1;
$total = (int)$display['pages'];
       
if ($pageCount == 1 || $pageCount == $total || $pageCount == $current_page || $pageCount == $current_page+1 ||
    $pageCount == $current_page+2 || $pageCount == $current_page-1 || $pageCount == $current_page-2)
{
                if ((int)$pageCount == (int)$page+1)
$display['page'] .= '
[<input ' . $class . ' type="button" onclick="this.href=\'javascript: void(0)\';" onmouseout="changeColorBack('. $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="' . $pageCount . '" />] ';
        else
$display['page'] .= '
<input ' . $class . ' type="submit" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="' . $pageCount . '"  /> ';
}
elseif ($pageCount < $current_page-2 && $pageCount > $current_page-6)
$display['page'] .= '
<input ' . $class . ' type="submit" onchange="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pagecount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="." onclick="sp_submitPage();" /> ';
elseif ($pageCount > $current_page+2 && $pageCount < $current_page+6)
$display['page'] .= '
<input ' . $class . ' type="submit" onchange="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pagecount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="." onclick="sp_submitPage();" /> ';

$pageCount++;
}

$display['page'] .= '
</span>   
</form>';
}

return $display;
}

/* Current url */
function currentCustomNewsPage($pageURL = 'http://')
{
if (!empty($_SERVER["HTTPS"]))
$pageURL = "https://";   
   
if ($_SERVER["SERVER_PORT"] != "80")
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
else
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

return $pageURL;
}

function customNews($parameters)
{
global $scripturl, $txt, $settings, $modSettings, $context, $smcFunc, $color_profile;

$board = !empty($parameters['board']) ? explode('|', $parameters['board']) : null;
$limit = !empty($parameters['limit']) ? (int) $parameters['limit'] : 5;
$start = !empty($parameters['start']) ? (int) $parameters['start'] : 0;
$length = isset($parameters['length']) ? (int) $parameters['length'] : 350;
$avatars = !empty($parameters['avatar']);
$style = !empty($parameters['bodyStyle']) ? $parameters['bodyStyle'] : 'windowbg';
$id = !empty($parameters['formId']) ? (int)$parameters['formId'] : 1;
$perPage = !empty($parameters['perPage']) ? (int)$parameters['perPage'] : 10;
$page = $context['current_page' . $id] * $perPage;
$context['custom_display' . $id] = array('page' => false, 'pages' => '0');

$limit = max(0, $limit);
$start = max(0, $start);

loadLanguage('Stats');

$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';

$request = $smcFunc['db_query']('', '
SELECT t.id_first_msg
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
WHERE ' . (empty($board) ? '{query_see_board}
AND t.id_first_msg >= {int:min_msg_id}' : 't.id_board IN ({array_int:current_board})') . ($modSettings['postmod_active'] ? '
AND t.approved = {int:is_approved}' : '') . '
AND (t.locked != {int:locked} OR m.icon != {string:icon})
ORDER BY t.id_first_msg DESC
LIMIT {int:limit}',
array(
'current_board' => $board,
'min_msg_id' => $modSettings['maxMsgID'] - 45 * min($limit, 5),
'is_approved' => 1,
'locked' => 1,
'icon' => 'moved',
'limit' => $limit,
)
);
$posts = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$posts[] = $row['id_first_msg'];
$smcFunc['db_free_result']($request);
$nRows = array_shift(array_values($posts));

if (empty($posts))
{
echo '
', $txt['error_sp_no_posts_found'];
return;
}
elseif (!empty($perPage))
{
$limit = count($posts);
$start = !empty($_REQUEST['news' . $id]) ? (int) $_REQUEST['news' . $id] : 0;

$clean_url = preg_replace('~news' . $id . '=\d+;?~', '', $_SERVER['REQUEST_URL']);
$current_url = $clean_url . (strpos($clean_url, '?') !== false ? (in_array(substr($clean_url, -1), array(';', '?')) ? '' : ';') : '?');

// $page_index = constructPageIndex($current_url . 'news' . $id . '=%1$d', $start, $limit, $perPage, true);
}

$request = $smcFunc['db_query']('', '
SELECT
m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, mem.avatar,
a.id_attach, a.attachment_type, a.filename, t.num_views
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
WHERE t.id_first_msg IN ({array_int:post_list})
ORDER BY t.id_first_msg DESC
LIMIT ' . (!empty($perPage) ? '{int:start}, ' : '') . '{int:limit}',
array(
'post_list' => $posts,
'start' => $page,
'limit' => !empty($perPage) ? $perPage : $limit,
)
);
$return = array();
$colorids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$limited = false;
if (($cutoff = $smcFunc['strpos']($row['body'], '')) !== false)
{
$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
$limited = true;
}
elseif (!empty($length) && $smcFunc['strlen']($row['body']) > $length)
{
$row['body'] = $smcFunc['substr']($row['body'], 0, $length);
$limited = true;
}

$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);

// Only place an ellipsis if the body has been shortened.
if ($limited)
$row['body'] .= '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0" title="' . $row['subject'] . '">...</a>';

if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
{
$avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '';
$avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '';
}
else
{
$avatar_width = '';
$avatar_height = '';
}

if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

censorText($row['subject']);
censorText($row['body']);

if ($modSettings['sp_resize_images'])
$row['body'] = preg_replace('~class="bbc_img~i', 'class="bbc_img sp_article', $row['body']);

if (!empty($row['id_member']))
$colorids[$row['id_member']] = $row['id_member'];

$return[] = array(
'id' => $row['id_topic'],
'message_id' => $row['id_msg'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['subject'],
'time' => timeformat($row['poster_time']),
'views' => $row['num_views'],
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $txt['sp-read_more'] . '</a>',
'replies' => $row['num_replies'],
'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'],
'comment_link' => !empty($row['locked']) ? '' : '| <a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
'new_comment' => !empty($row['locked']) ? '' : '| <a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
'poster' => array(
'id' => $row['id_member'],
'name' => $row['poster_name'],
'href' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
'link' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name']
),
'locked' => !empty($row['locked']),
'is_last' => false,
'avatar' => array(
'name' => $row['avatar'],
'image' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? '<img src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
'href' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar'])
),
);
}
$smcFunc['db_free_result']($request);

if (empty($return))
{
echo '
', $txt['error_sp_no_posts_found'];
return;
}

$return[count($return) - 1]['is_last'] = true;

if (!empty($colorids) && sp_loadColors($colorids) !== false)
{
foreach ($return as $k => $p)
{
if (!empty($color_profile[$p['poster']['id']]['link']))
$return[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];
}
}

if ($context['SPortal']['core_compat'])
{
foreach ($return as $news)
{
echo '
<div class="tborder sp_article_content">
<table class="sp_block">
<tr class="catbg">
<td class="sp_middle">', $news['icon'], '</td>
<td class="sp_middle sp_regular_padding sp_fullwidth"><a href="', $news['href'], '" >', $news['subject'], '</a></td>
</tr>
<tr class="windowbg">
<td class="sp_regular_padding" colspan="2">';

if ($avatars && $news['avatar']['name'] !== null && !empty($news['avatar']['href']))
echo '
<a href="', $scripturl, '?action=profile;u=', $news['poster']['id'], '"><img src="', $news['avatar']['href'], '" alt="', $news['poster']['name'], '" width="30" style="float: right;" /></a>
<div class="middletext">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], '<br />', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';
else
echo '
<div class="middletext">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], ' | ', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';

echo '
<div class="post"><hr />', $news['body'], '<br /><br /></div>
</td>
</tr>
<tr>
<td class="windowbg2" colspan="2">
<div class="sp_right sp_regular_padding">', $news['link'], ' ',  $news['new_comment'], '</div>
</td>
</tr>
</table>
</div>';
}
}
else
{
foreach ($return as $news)
{
echo '
                 <div class="windowbg sp_article_content">
                 <span class="topslice"><span></span></span>
                 <div class="sp_content_padding">
                 <div class="portal_title"><a href="', $news['href'], '" >', $news['subject'], '</a></div>
                 <div class="middletext" style="font-size: 14px; color: #555555;"><div class="icon-pencil1" style="margin-bottom:.25em; vertical-align:middle;"></div> ', $news['time'], '</div>
                 <div class="post">', $news['body'], '</div>     
                 <br />
                 <div class="button9">', $news['link'], '</div>
                 <br />
                 <br />
                 </div>
                 <span class="botslice"><span></span></span>
                 </div>';
}
}

if (!empty($per_page))
echo '
<div class="sp_page_index">', $txt['sp-articlesPages'], ': ', $page_index, '</div>';

$context['current_pages' . $id] = (($nRows-1) / $perPage) + 1;
$context['custom_display' . $id] = custom_newsPages($txt['pages'], false, currentCustomNewsPage(), $context['current_pages' . $id], false, false, $id, $style);
       
echo $context['custom_display' . $id]['page'];
}

http://idesign360.com/community/index.php/page,web_development.html

Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: BoardNews block and pagination question
« Reply #13 on: August 05, 2013, 10:20:00 AM »
Mick,

  I will take a look at your code later this afternoon. Does the pagination work correctly without your edits and in its default state that I provided?

Offline Mick.

  • Comrade
  • *
  • Posts: 77
  • Gender: Male
  • Premium SMF Themes
    • idesignSMF
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: BoardNews block and pagination question
« Reply #14 on: August 05, 2013, 12:34:40 PM »
This is the original state http://idesign360.com/community/index.php/page,page693.html

and code:
Code: [Select]
// Custom News
global $context;

// Adjust your specific parameters
// when/if using the pagination for other blocks on the same page, remember to increment the formId
$parameters['board'] = '78';
$parameters['limit'] = 350;
$parameters['perPage'] = 10;
$parameters['bodyStyle'] = 'clear';
$parameters['formId'] = 2;

// Do not bother altering the rest of the code...
$context['current_page' . $parameters['formId']] = !empty($context['current_page' . $parameters['formId']]) ? (int)$context['current_page' . $parameters['formId']] : 1;
$context['current_page' . $parameters['formId']] = (!empty($_REQUEST['current_page' . $parameters['formId']]) ? (int)$_REQUEST['current_page' . $parameters['formId']]-1 : $context['current_page' . $parameters['formId']] - 1);
customNews($parameters);

function custom_newsPages($lang, $anchor, $link, $pages, $sort=false, $order=false, $id=1, $style='windowbg')
{
/* PHP pagination - max 7 visible integers and 6 periods (all links) - current page encircled with square brackets
* This php pagination code was developed by Underdog copyright 2013
* http://webdevelop.comli.com
* Licensed under the GNU Public License: http://www.gnu.org/licenses/gpl.html
*/
global $context, $txt, $scripturl;

$name = 'custom_SpForm' . $id;
$pageCount = 1;
$display = array('page' => false, 'pages' => '0');
$page = !empty($context['current_page' . $id]) ? (int)$context['current_page' . $id] : 0;
$display['pages'] = !empty($pages) ? (int)$pages : 1;
$class = !empty($style) ? 'class="' . $style . '"' : '';

if ($display['pages'] > 1)
{
$display['page'] =  '
<script type="text/javascript"><!-- // --><![CDATA[
function changeColor(s, formId)
{
for (var i=1; i<=3; i++)
                document.getElementById("link"+i+formId).style.color = i==s ? "red" : "blue";
}
function changeColorBack(s, formId)
{
for (var i=1; i<=3; i++)
document.getElementById("link"+i+formId).style.color = i==s ? "blue" : "blue";
}
// ]]></script>
<form name="' . $name .'" action="'.$link.'" method="post" id="' . $name .'">
<span style="text-align:center;position:relative;width:99%;display:inline-block;">
' . $lang . '<br />';

while ($pageCount < (int)$display['pages']+1)
{
$current_page = (int)$page+1;
$total = (int)$display['pages'];
       
if ($pageCount == 1 || $pageCount == $total || $pageCount == $current_page || $pageCount == $current_page+1 ||
    $pageCount == $current_page+2 || $pageCount == $current_page-1 || $pageCount == $current_page-2)
{
                if ((int)$pageCount == (int)$page+1)
$display['page'] .= '
[<input ' . $class . ' type="button" onclick="this.href=\'javascript: void(0)\';" onmouseout="changeColorBack('. $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="' . $pageCount . '" />] ';
        else
$display['page'] .= '
<input ' . $class . ' type="submit" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="' . $pageCount . '"  /> ';
}
elseif ($pageCount < $current_page-2 && $pageCount > $current_page-6)
$display['page'] .= '
<input ' . $class . ' type="submit" onchange="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pagecount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="." onclick="sp_submitPage();" /> ';
elseif ($pageCount > $current_page+2 && $pageCount < $current_page+6)
$display['page'] .= '
<input ' . $class . ' type="submit" onchange="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pagecount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="." onclick="sp_submitPage();" /> ';

$pageCount++;
}

$display['page'] .= '
</span>   
</form>';
}

return $display;
}

/* Current url */
function currentCustomNewsPage($pageURL = 'http://')
{
if (!empty($_SERVER["HTTPS"]))
$pageURL = "https://";   
   
if ($_SERVER["SERVER_PORT"] != "80")
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
else
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

return $pageURL;
}

function customNews($parameters)
{
global $scripturl, $txt, $settings, $modSettings, $context, $smcFunc, $color_profile;

$board = !empty($parameters['board']) ? explode('|', $parameters['board']) : null;
$limit = !empty($parameters['limit']) ? (int) $parameters['limit'] : 5;
$start = !empty($parameters['start']) ? (int) $parameters['start'] : 0;
$length = isset($parameters['length']) ? (int) $parameters['length'] : 250;
$avatars = !empty($parameters['avatar']);
$style = !empty($parameters['bodyStyle']) ? $parameters['bodyStyle'] : 'windowbg';
$id = !empty($parameters['formId']) ? (int)$parameters['formId'] : 1;
$perPage = !empty($parameters['perPage']) ? (int)$parameters['perPage'] : 10;
$page = $context['current_page' . $id] * $perPage;
$context['custom_display' . $id] = array('page' => false, 'pages' => '0');

$limit = max(0, $limit);
$start = max(0, $start);

loadLanguage('Stats');

$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';

$request = $smcFunc['db_query']('', '
SELECT t.id_first_msg
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
WHERE ' . (empty($board) ? '{query_see_board}
AND t.id_first_msg >= {int:min_msg_id}' : 't.id_board IN ({array_int:current_board})') . ($modSettings['postmod_active'] ? '
AND t.approved = {int:is_approved}' : '') . '
AND (t.locked != {int:locked} OR m.icon != {string:icon})
ORDER BY t.id_first_msg DESC
LIMIT {int:limit}',
array(
'current_board' => $board,
'min_msg_id' => $modSettings['maxMsgID'] - 45 * min($limit, 5),
'is_approved' => 1,
'locked' => 1,
'icon' => 'moved',
'limit' => $limit,
)
);
$posts = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$posts[] = $row['id_first_msg'];
$smcFunc['db_free_result']($request);
$nRows = array_shift(array_values($posts));

if (empty($posts))
{
echo '
', $txt['error_sp_no_posts_found'];
return;
}
elseif (!empty($perPage))
{
$limit = count($posts);
$start = !empty($_REQUEST['news' . $id]) ? (int) $_REQUEST['news' . $id] : 0;

$clean_url = preg_replace('~news' . $id . '=\d+;?~', '', $_SERVER['REQUEST_URL']);
$current_url = $clean_url . (strpos($clean_url, '?') !== false ? (in_array(substr($clean_url, -1), array(';', '?')) ? '' : ';') : '?');

// $page_index = constructPageIndex($current_url . 'news' . $id . '=%1$d', $start, $limit, $perPage, true);
}

$request = $smcFunc['db_query']('', '
SELECT
m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, mem.avatar,
a.id_attach, a.attachment_type, a.filename, t.num_views
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
WHERE t.id_first_msg IN ({array_int:post_list})
ORDER BY t.id_first_msg DESC
LIMIT ' . (!empty($perPage) ? '{int:start}, ' : '') . '{int:limit}',
array(
'post_list' => $posts,
'start' => $page,
'limit' => !empty($perPage) ? $perPage : $limit,
)
);
$return = array();
$colorids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$limited = false;
if (($cutoff = $smcFunc['strpos']($row['body'], '')) !== false)
{
$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
$limited = true;
}
elseif (!empty($length) && $smcFunc['strlen']($row['body']) > $length)
{
$row['body'] = $smcFunc['substr']($row['body'], 0, $length);
$limited = true;
}

$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);

// Only place an ellipsis if the body has been shortened.
if ($limited)
$row['body'] .= '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0" title="' . $row['subject'] . '">...</a>';

if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
{
$avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '';
$avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '';
}
else
{
$avatar_width = '';
$avatar_height = '';
}

if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

censorText($row['subject']);
censorText($row['body']);

if ($modSettings['sp_resize_images'])
$row['body'] = preg_replace('~class="bbc_img~i', 'class="bbc_img sp_article', $row['body']);

if (!empty($row['id_member']))
$colorids[$row['id_member']] = $row['id_member'];

$return[] = array(
'id' => $row['id_topic'],
'message_id' => $row['id_msg'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['subject'],
'time' => timeformat($row['poster_time']),
'views' => $row['num_views'],
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $txt['sp-read_more'] . '</a>',
'replies' => $row['num_replies'],
'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'],
'comment_link' => !empty($row['locked']) ? '' : '| <a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
'new_comment' => !empty($row['locked']) ? '' : '| <a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
'poster' => array(
'id' => $row['id_member'],
'name' => $row['poster_name'],
'href' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
'link' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name']
),
'locked' => !empty($row['locked']),
'is_last' => false,
'avatar' => array(
'name' => $row['avatar'],
'image' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? '<img src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
'href' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar'])
),
);
}
$smcFunc['db_free_result']($request);

if (empty($return))
{
echo '
', $txt['error_sp_no_posts_found'];
return;
}

$return[count($return) - 1]['is_last'] = true;

if (!empty($colorids) && sp_loadColors($colorids) !== false)
{
foreach ($return as $k => $p)
{
if (!empty($color_profile[$p['poster']['id']]['link']))
$return[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];
}
}

if ($context['SPortal']['core_compat'])
{
foreach ($return as $news)
{
echo '
<div class="tborder sp_article_content">
<table class="sp_block">
<tr class="catbg">
<td class="sp_middle">', $news['icon'], '</td>
<td class="sp_middle sp_regular_padding sp_fullwidth"><a href="', $news['href'], '" >', $news['subject'], '</a></td>
</tr>
<tr class="windowbg">
<td class="sp_regular_padding" colspan="2">';

if ($avatars && $news['avatar']['name'] !== null && !empty($news['avatar']['href']))
echo '
<a href="', $scripturl, '?action=profile;u=', $news['poster']['id'], '"><img src="', $news['avatar']['href'], '" alt="', $news['poster']['name'], '" width="30" style="float: right;" /></a>
<div class="middletext">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], '<br />', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';
else
echo '
<div class="middletext">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], ' | ', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';

echo '
<div class="post"><hr />', $news['body'], '<br /><br /></div>
</td>
</tr>
<tr>
<td class="windowbg2" colspan="2">
<div class="sp_right sp_regular_padding">', $news['link'], ' ',  $news['new_comment'], '</div>
</td>
</tr>
</table>
</div>';
}
}
else
{
foreach ($return as $news)
{
echo '
<div class="cat_bar">
<h3 class="catbg">
<span class="sp_float_left sp_article_icon">', $news['icon'], '</span><a href="', $news['href'], '" >', $news['subject'], '</a>
</h3>
</div>
<div class="windowbg sp_article_content">
<span class="topslice"><span></span></span>
<div class="sp_content_padding">';

if ($avatars && $news['avatar']['name'] !== null && !empty($news['avatar']['href']))
echo '
<a href="', $scripturl, '?action=profile;u=', $news['poster']['id'], '"><img src="', $news['avatar']['href'], '" alt="', $news['poster']['name'], '" width="30" class="sp_float_right" /></a>
<div class="middletext">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], '<br />', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';
else
echo '
<div class="middletext">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], ' | ', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';

echo '
<div class="post"><hr />', $news['body'], '</div>
<div class="sp_right">', $news['link'], ' ',  $news['new_comment'], '</div>
</div>
<span class="botslice"><span></span></span>
</div>';
}
}

if (!empty($per_page))
echo '
<div class="sp_page_index">', $txt['sp-articlesPages'], ': ', $page_index, '</div>';

$context['current_pages' . $id] = (($nRows-1) / $perPage) + 1;
$context['custom_display' . $id] = custom_newsPages($txt['pages'], false, currentCustomNewsPage(), $context['current_pages' . $id], false, false, $id, $style);
       
echo $context['custom_display' . $id]['page'];
}

$parameters['limit'] = 350; seems to not have any effect.

 But if i change it directly here from 250 to 350, it works:
Code: [Select]
global $scripturl, $txt, $settings, $modSettings, $context, $smcFunc, $color_profile;

$board = !empty($parameters['board']) ? explode('|', $parameters['board']) : null;
$limit = !empty($parameters['limit']) ? (int) $parameters['limit'] : 5;
$start = !empty($parameters['start']) ? (int) $parameters['start'] : 0;
$length = isset($parameters['length']) ? (int) $parameters['length'] : 250;
$avatars = !empty($parameters['avatar']);
$style = !empty($parameters['bodyStyle']) ? $parameters['bodyStyle'] : 'windowbg';
$id = !empty($parameters['formId']) ? (int)$parameters['formId'] : 1;
$perPage = !empty($parameters['perPage']) ? (int)$parameters['perPage'] : 10;
$page = $context['current_page' . $id] * $perPage;
$context['custom_display' . $id] = array('page' => false, 'pages' => '0');


Offline Mick.

  • Comrade
  • *
  • Posts: 77
  • Gender: Male
  • Premium SMF Themes
    • idesignSMF
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: BoardNews block and pagination question
« Reply #15 on: August 05, 2013, 12:37:25 PM »
Also i found the pagecount error.

Code: [Select]
<input ' . $class . ' type="submit" onchange="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pagecount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="." onclick="sp_submitPage();" /> ';
elseif ($pageCount > $current_page+2 && $pageCount < $current_page+6)
$display['page'] .= '
<input ' . $class . ' type="submit" onchange="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pagecount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="." onclick="sp_submitPage();" /> ';

2 instances are pagecount instead of pageCount.

I have yet to find this error:

Undefined offset: 0
/Sources/Load.php(237) : runtime-created function
« Last Edit: August 05, 2013, 12:53:11 PM by Mick. »

Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: BoardNews block and pagination question
« Reply #16 on: August 05, 2013, 02:55:47 PM »
Mick,

  Yes I see I made an err for the last 2 inputs of the form for the pagination. They also had an onclick call I neglected to remove when I was originally testing it.

  I found what was causing the offset error which was the use of smcFunc['substr'] when the code attempts to use smcFunc['strpos'] to find the last position in the body and then smcFunc]'strpos'] to set the last character position for the body when the preset length value is greater for each post. smcFunc['strpos'] must have been returning a null value for some reason I gather so I edited the routine to use smcFunc['strlen'] to determine the last position of the message body. I also edited the value of $nRows to just count the $posts array and it seems to work without error now.

Code: [Select]
// Custom News
global $context;

// Adjust your specific parameters
// when/if using the pagination for other blocks on the same page, remember to increment the formId
$parameters['board'] = '78';
$parameters['limit'] = 50;
$parameters['perPage'] = 10;
$parameters['length'] = 350;
$parameters['bodyStyle'] = 'clear';
$parameters['formId'] = 2;

// Do not bother altering the rest of the code...
$context['current_page' . $parameters['formId']] = !empty($context['current_page' . $parameters['formId']]) ? (int)$context['current_page' . $parameters['formId']] : 1;
$context['current_page' . $parameters['formId']] = (!empty($_REQUEST['current_page' . $parameters['formId']]) ? (int)$_REQUEST['current_page' . $parameters['formId']]-1 : $context['current_page' . $parameters['formId']] - 1);
customNews($parameters);

function custom_newsPages($lang, $anchor, $link, $pages, $sort=false, $order=false, $id=1, $style='windowbg')
{
/* PHP pagination - max 7 visible integers and 6 periods (all links) - current page encircled with square brackets
* This php pagination code was developed by Underdog copyright 2013
* http://webdevelop.comli.com
* Licensed under the GNU Public License: http://www.gnu.org/licenses/gpl.html
*/
global $context, $txt, $scripturl;

$name = 'custom_SpForm' . $id;
$pageCount = 1;
$display = array('page' => false, 'pages' => '0');
$page = !empty($context['current_page' . $id]) ? (int)$context['current_page' . $id] : 0;
$display['pages'] = !empty($pages) ? (int)$pages : 1;
$class = !empty($style) ? 'class="' . $style . '"' : '';

if ($display['pages'] > 1)
{
$display['page'] =  '
<script type="text/javascript"><!-- // --><![CDATA[
function changeColor(s, formId)
{
for (var i=1; i<=3; i++)
                document.getElementById("link"+i+formId).style.color = i==s ? "red" : "blue";
}
function changeColorBack(s, formId)
{
for (var i=1; i<=3; i++)
document.getElementById("link"+i+formId).style.color = i==s ? "blue" : "blue";
}
// ]]></script>
<form name="' . $name .'" action="'.$link.'" method="post" id="' . $name .'">
<span style="text-align:center;position:relative;width:99%;display:inline-block;">
' . $lang . '';

while ($pageCount < (int)$display['pages']+1)
{
$current_page = (int)$page+1;
$total = (int)$display['pages'];
       
if ($pageCount == 1 || $pageCount == $total || $pageCount == $current_page || $pageCount == $current_page+1 ||
    $pageCount == $current_page+2 || $pageCount == $current_page-1 || $pageCount == $current_page-2)
{
                if ((int)$pageCount == (int)$page+1)
$display['page'] .= '
[<input ' . $class . ' type="button" onclick="this.href=\'javascript: void(0)\';" onmouseout="changeColorBack('. $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="' . $pageCount . '" />] ';
        else
$display['page'] .= '
<input ' . $class . ' type="submit" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="' . $pageCount . '"  /> ';
}
elseif ($pageCount < $current_page-2 && $pageCount > $current_page-6)
$display['page'] .= '
<input ' . $class . ' type="submit" onchange="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pageCount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="." /> ';
elseif ($pageCount > $current_page+2 && $pageCount < $current_page+6)
$display['page'] .= '
<input ' . $class . ' type="submit" onchange="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pageCount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="." /> ';

$pageCount++;
}

$display['page'] .= '
</span>   
</form>';
}

return $display;
}

/* Current url */
function currentCustomNewsPage($pageURL = 'http://')
{
if (!empty($_SERVER["HTTPS"]))
$pageURL = "https://";   
   
if ($_SERVER["SERVER_PORT"] != "80")
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
else
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

return $pageURL;
}

function customNews($parameters)
{
global $scripturl, $txt, $settings, $modSettings, $context, $smcFunc, $color_profile;

$board = !empty($parameters['board']) ? explode('|', $parameters['board']) : null;
$limit = !empty($parameters['limit']) ? (int) $parameters['limit'] : 30;
$start = !empty($parameters['start']) ? (int) $parameters['start'] : 0;
$length = isset($parameters['length']) ? (int) $parameters['length'] : 250;
$avatars = !empty($parameters['avatar']);
$style = !empty($parameters['bodyStyle']) ? $parameters['bodyStyle'] : 'windowbg';
$id = !empty($parameters['formId']) ? (int)$parameters['formId'] : 1;
$perPage = !empty($parameters['perPage']) ? (int)$parameters['perPage'] : 10;
$page = $context['current_page' . $id] * $perPage;
$context['custom_display' . $id] = array('page' => false, 'pages' => '0');

// $limit = max(0, $limit);
// $start = max(0, $start);

loadLanguage('Stats');

$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';

$request = $smcFunc['db_query']('', '
SELECT t.id_first_msg
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
WHERE ' . (empty($board) ? '{query_see_board}
AND t.id_first_msg >= {int:min_msg_id}' : 't.id_board IN ({array_int:current_board})') . ($modSettings['postmod_active'] ? '
AND t.approved = {int:is_approved}' : '') . '
AND (t.locked != {int:locked} OR m.icon != {string:icon})
ORDER BY t.id_first_msg DESC
LIMIT {int:limit}',
array(
'current_board' => $board,
'min_msg_id' => $modSettings['maxMsgID'] - 45 * min($limit, 5),
'is_approved' => 1,
'locked' => 1,
'icon' => 'moved',
'limit' => $limit,
)
);
$posts = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$posts[] = $row['id_first_msg'];
$smcFunc['db_free_result']($request);
$nRows = count($posts);

if (empty($posts))
{
echo '
', $txt['error_sp_no_posts_found'];
return;
}
elseif (!empty($perPage))
{
$limit = count($posts);
$start = !empty($_REQUEST['news' . $id]) ? (int) $_REQUEST['news' . $id] : 0;

$clean_url = preg_replace('~news' . $id . '=\d+;?~', '', $_SERVER['REQUEST_URL']);
$current_url = $clean_url . (strpos($clean_url, '?') !== false ? (in_array(substr($clean_url, -1), array(';', '?')) ? '' : ';') : '?');

// $page_index = constructPageIndex($current_url . 'news' . $id . '=%1$d', $start, $limit, $perPage, true);
}

$request = $smcFunc['db_query']('', '
SELECT
m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, mem.avatar,
a.id_attach, a.attachment_type, a.filename, t.num_views
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
WHERE t.id_first_msg IN ({array_int:post_list})
ORDER BY t.id_first_msg DESC
LIMIT {int:start}, {int:limit}',
array(
'post_list' => $posts,
'start' => $page,
'limit' => $perPage,
)
);
$return = array();
$colorids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$limited = false;
if (($cutoff = $smcFunc['strlen']($row['body'])) < $length)
{
$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
$limited = true;
}
elseif (!empty($length) && $smcFunc['strlen']($row['body']) > $length)
{
$row['body'] = $smcFunc['substr']($row['body'], 0, $length);
$limited = true;
}

$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);

// Only place an ellipsis if the body has been shortened.
if ($limited)
$row['body'] .= '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0" title="' . $row['subject'] . '">...</a>';

if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
{
$avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '';
$avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '';
}
else
{
$avatar_width = '';
$avatar_height = '';
}

if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

censorText($row['subject']);
censorText($row['body']);

if ($modSettings['sp_resize_images'])
$row['body'] = preg_replace('~class="bbc_img~i', 'class="bbc_img sp_article', $row['body']);

if (!empty($row['id_member']))
$colorids[$row['id_member']] = $row['id_member'];

$return[] = array(
'id' => $row['id_topic'],
'message_id' => $row['id_msg'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['subject'],
'time' => timeformat($row['poster_time']),
'views' => $row['num_views'],
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $txt['sp-read_more'] . '</a>',
'replies' => $row['num_replies'],
'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'],
'comment_link' => !empty($row['locked']) ? '' : '| <a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
'new_comment' => !empty($row['locked']) ? '' : '| <a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
'poster' => array(
'id' => $row['id_member'],
'name' => $row['poster_name'],
'href' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
'link' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name']
),
'locked' => !empty($row['locked']),
'is_last' => false,
'avatar' => array(
'name' => $row['avatar'],
'image' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? '<img src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
'href' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar'])
),
);
}
$smcFunc['db_free_result']($request);

if (empty($return))
{
echo '
', $txt['error_sp_no_posts_found'];
return;
}

$return[count($return) - 1]['is_last'] = true;

if (!empty($colorids) && sp_loadColors($colorids) !== false)
{
foreach ($return as $k => $p)
{
if (!empty($color_profile[$p['poster']['id']]['link']))
$return[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];
}
}

if ($context['SPortal']['core_compat'])
{
foreach ($return as $news)
{
echo '
<div class="tborder sp_article_content">
<table class="sp_block">
<tr class="catbg">
<td class="sp_middle">', $news['icon'], '</td>
<td class="sp_middle sp_regular_padding sp_fullwidth"><a href="', $news['href'], '" >', $news['subject'], '</a></td>
</tr>
<tr class="windowbg">
<td class="sp_regular_padding" colspan="2">';

if ($avatars && $news['avatar']['name'] !== null && !empty($news['avatar']['href']))
echo '
<a href="', $scripturl, '?action=profile;u=', $news['poster']['id'], '"><img src="', $news['avatar']['href'], '" alt="', $news['poster']['name'], '" width="30" style="float: right;" /></a>
<div class="middletext">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], '<br />', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';
else
echo '
<div class="middletext">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], ' | ', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';

echo '
<div class="post"><hr />', $news['body'], '<br /><br /></div>
</td>
</tr>
<tr>
<td class="windowbg2" colspan="2">
<div class="sp_right sp_regular_padding">', $news['link'], ' ',  $news['new_comment'], '</div>
</td>
</tr>
</table>
</div>';
}
}
else
{
foreach ($return as $news)
{
echo '
                 <div class="windowbg sp_article_content">
                 <span class="topslice"><span></span></span>
                 <div class="sp_content_padding">
                 <div class="portal_title"><a href="', $news['href'], '" >', $news['subject'], '</a></div>
                 <div class="middletext" style="font-size: 14px; color: #555555;"><div class="icon-pencil1" style="margin-bottom:.25em; vertical-align:middle;"></div> ', $news['time'], '</div>
                 <div class="post">', $news['body'], '</div>     
                 <br />
                 <div class="button9">', $news['link'], '</div>
                 <br />
                 <br />
                 </div>
                 <span class="botslice"><span></span></span>
                 </div>';
}
}

if (!empty($per_page))
echo '
<div class="sp_page_index">', $txt['sp-articlesPages'], ': ', $page_index, '</div>';

$context['current_pages' . $id] = (($nRows-1) / $perPage) + 1;
$context['custom_display' . $id] = custom_newsPages($txt['pages'], false, currentCustomNewsPage(), $context['current_pages' . $id], false, false, $id, $style);
       
echo $context['custom_display' . $id]['page'];
}
   

Offline Mick.

  • Comrade
  • *
  • Posts: 77
  • Gender: Male
  • Premium SMF Themes
    • idesignSMF
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: BoardNews block and pagination question
« Reply #17 on: August 05, 2013, 03:47:23 PM »
Awesome. I'll check back later on as I'm sitting at the pub having a few. ;)

Offline Mick.

  • Comrade
  • *
  • Posts: 77
  • Gender: Male
  • Premium SMF Themes
    • idesignSMF
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: BoardNews block and pagination question
« Reply #18 on: August 05, 2013, 05:19:45 PM »
Awesome. This works sweet now. All i need to do is figure the pagination css so it uses the same css used in PortalArticles.template.php

http://idesign360.com/community/index.php/page,web_development.html
http://idesign360.com/community/index.php/page,tutorials.html
http://idesign360.com/community/index.php/page,freebies.html

Thanx brother, rock on!
Mick.

Offline Chen Zhen

  • The Underdog
  • Operations Manager
  • *
  • Posts: 1350
  • Gender: Male
  • Kinesis
    • WebDev
  • SMF Version: 2.1
  • EhPortal Version: 1.22
Re: BoardNews block and pagination question
« Reply #19 on: August 05, 2013, 10:08:27 PM »
Mick,

  No problem. That pagination can be adjusted to work with any display that feeds its data into an array.

Here is another block that has the button class, button style and javascript onmouseout/onmouseover colors at the beginning of the block code. Adjust those 3 attributes to style those buttons the way you want it. You should also use the code block below as I made a fix for the dots which were not working properly with the previous block code.

Code: [Select]
// Custom News
global $context;

// Adjust your specific parameters
// when/if using the pagination for other blocks on the same page, remember to increment the formId
$parameters['formId'] = 2;
$parameters['board'] = '78';
$parameters['limit'] = 50;
$parameters['perPage'] = 10;
$parameters['length'] = 350;
$parameters['buttonClass'] = 'clear';
$parameters['buttonStyle'] = 'border:0;padding:0;margin:0;color:blue;text-decoration:none;';
$paramters['hoverColors'] = array('red', 'blue');

// Do not bother altering the rest of the code...
$context['current_page' . $parameters['formId']] = !empty($context['current_page' . $parameters['formId']]) ? (int)$context['current_page' . $parameters['formId']] : 1;
$context['current_page' . $parameters['formId']] = (!empty($_REQUEST['current_page' . $parameters['formId']]) ? (int)$_REQUEST['current_page' . $parameters['formId']]-1 : $context['current_page' . $parameters['formId']] - 1);
customNews($parameters);

function custom_newsPages($lang, $anchor, $link, $pages, $sort=false, $order=false, $id=1, $buttonClass='windowbg', $buttonStyle='border:0;padding:0;margin:0;color:blue;text-decoration:none;', $hoverColors)
{
/* PHP pagination - max 7 visible integers and 6 periods (all links) - current page encircled with square brackets
* This php pagination code was developed by Underdog copyright 2013
* http://webdevelop.comli.com
* Licensed under the GNU Public License: http://www.gnu.org/licenses/gpl.html
*/
global $context, $txt, $scripturl;

$name = 'custom_SpForm' . $id;
$pageCount = 1;
$display = array('page' => false, 'pages' => '0');
$page = !empty($context['current_page' . $id]) ? (int)$context['current_page' . $id] : 0;
$display['pages'] = !empty($pages) ? (int)$pages : 1;
$buttonClass = !empty($buttonClass) ? 'class="' . $buttonClass . '"' : '';
$buttonStyle = !empty($buttonStyle) ? 'style="' . $buttonStyle . '"' : '';

if ($display['pages'] > 1)
{
$display['page'] =  '
<script type="text/javascript"><!-- // --><![CDATA[
function changeColor(s, formId)
{
for (var i=1; i<=3; i++)
                document.getElementById("link"+i+formId).style.color = i==s ? "' . $hoverColors[0] . '" : "' . $hoverColors[1] . '";
}
function changeColorBack(s, formId)
{
for (var i=1; i<=3; i++)
document.getElementById("link"+i+formId).style.color = i==s ? "' . $hoverColors[1] . '" : "' . $hoverColors[1] . '";
}
// ]]></script>
<form name="' . $name .'" action="'.$link.'" method="post" id="' . $name .'">
<span style="text-align:center;position:relative;width:99%;display:inline-block;">
' . $lang . '';

while ($pageCount < (int)$display['pages']+1)
{
$current_page = (int)$page+1;
$total = (int)$display['pages'];
       
if ($pageCount == 1 || $pageCount == $total || $pageCount == $current_page || $pageCount == $current_page+1 ||
    $pageCount == $current_page+2 || $pageCount == $current_page-1 || $pageCount == $current_page-2)
{
                if ((int)$pageCount == (int)$page+1)
$display['page'] .= '
[<input ' . $buttonClass . ' type="button" onclick="this.href=\'javascript: void(0)\';" onmouseout="changeColorBack('. $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" ' . $buttonStyle . ' name="current_page' . $id . '" value="' . $pageCount . '" />] ';
        else
$display['page'] .= '
<input ' . $buttonClass . ' type="submit" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" ' . $buttonStyle . ' name="current_page' . $id . '" value="' . $pageCount . '"  /> ';
}
elseif ($pageCount < $current_page-2 && $pageCount > $current_page-6)
$display['page'] .= '
<input ' . $buttonClass . ' type="submit" onclick="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pageCount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ');" id="link' . $pageCount . $id . '" ' . $buttonStyle . ' name="current_page' . $id . '" value="." /> ';
elseif ($pageCount > $current_page+2 && $pageCount < $current_page+6)
$display['page'] .= '
<input ' . $buttonClass . ' type="submit" onclick="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pageCount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ');" id="link' . $pageCount . $id . '" ' . $buttonStyle . ' name="current_page' . $id . '" value="." /> ';

$pageCount++;
}

$display['page'] .= '
</span>   
</form>';
}

return $display;
}

/* Current url */
function currentCustomNewsPage($pageURL = 'http://')
{
if (!empty($_SERVER["HTTPS"]))
$pageURL = "https://";   
   
if ($_SERVER["SERVER_PORT"] != "80")
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
else
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

return $pageURL;
}

function customNews($parameters)
{
global $scripturl, $txt, $settings, $modSettings, $context, $smcFunc, $color_profile;

$board = !empty($parameters['board']) ? explode('|', $parameters['board']) : null;
$limit = !empty($parameters['limit']) ? (int) $parameters['limit'] : 30;
$start = !empty($parameters['start']) ? (int) $parameters['start'] : 0;
$length = isset($parameters['length']) ? (int) $parameters['length'] : 250;
$avatars = !empty($parameters['avatar']);
$buttonClass = !empty($parameters['buttonClass']) ? $parameters['buttonClass'] : 'windowbg';
$buttonStyle = !empty($parameters['buttonStyle']) ? $parameters['buttonStyle'] : 'border:0;padding:0;margin:0;color:blue;text-decoration:none;';
$id = !empty($parameters['formId']) ? (int)$parameters['formId'] : 1;
$perPage = !empty($parameters['perPage']) ? (int)$parameters['perPage'] : 10;
$page = $context['current_page' . $id] * $perPage;
$context['custom_display' . $id] = array('page' => false, 'pages' => '0');
$hoverColors = !empty($paramters['hoverColors']) ? $paramters['hoverColors'] : array('red', 'blue');

// $limit = max(0, $limit);
// $start = max(0, $start);

loadLanguage('Stats');

$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';

$request = $smcFunc['db_query']('', '
SELECT t.id_first_msg
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
WHERE ' . (empty($board) ? '{query_see_board}
AND t.id_first_msg >= {int:min_msg_id}' : 't.id_board IN ({array_int:current_board})') . ($modSettings['postmod_active'] ? '
AND t.approved = {int:is_approved}' : '') . '
AND (t.locked != {int:locked} OR m.icon != {string:icon})
ORDER BY t.id_first_msg DESC
LIMIT {int:limit}',
array(
'current_board' => $board,
'min_msg_id' => $modSettings['maxMsgID'] - 45 * min($limit, 5),
'is_approved' => 1,
'locked' => 1,
'icon' => 'moved',
'limit' => $limit,
)
);
$posts = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$posts[] = $row['id_first_msg'];
$smcFunc['db_free_result']($request);
$nRows = count($posts);

if (empty($posts))
{
echo '
', $txt['error_sp_no_posts_found'];
return;
}
elseif (!empty($perPage))
{
$limit = count($posts);
$start = !empty($_REQUEST['news' . $id]) ? (int) $_REQUEST['news' . $id] : 0;

$clean_url = preg_replace('~news' . $id . '=\d+;?~', '', $_SERVER['REQUEST_URL']);
$current_url = $clean_url . (strpos($clean_url, '?') !== false ? (in_array(substr($clean_url, -1), array(';', '?')) ? '' : ';') : '?');

// $page_index = constructPageIndex($current_url . 'news' . $id . '=%1$d', $start, $limit, $perPage, true);
}

$request = $smcFunc['db_query']('', '
SELECT
m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, mem.avatar,
a.id_attach, a.attachment_type, a.filename, t.num_views
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
WHERE t.id_first_msg IN ({array_int:post_list})
ORDER BY t.id_first_msg DESC
LIMIT {int:start}, {int:limit}',
array(
'post_list' => $posts,
'start' => $page,
'limit' => $perPage,
)
);
$return = array();
$colorids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$limited = false;
if (($cutoff = $smcFunc['strlen']($row['body'])) < $length)
{
$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
$limited = true;
}
elseif (!empty($length) && $smcFunc['strlen']($row['body']) > $length)
{
$row['body'] = $smcFunc['substr']($row['body'], 0, $length);
$limited = true;
}

$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);

// Only place an ellipsis if the body has been shortened.
if ($limited)
$row['body'] .= '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0" title="' . $row['subject'] . '">...</a>';

if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
{
$avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '';
$avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '';
}
else
{
$avatar_width = '';
$avatar_height = '';
}

if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

censorText($row['subject']);
censorText($row['body']);

if ($modSettings['sp_resize_images'])
$row['body'] = preg_replace('~class="bbc_img~i', 'class="bbc_img sp_article', $row['body']);

if (!empty($row['id_member']))
$colorids[$row['id_member']] = $row['id_member'];

$return[] = array(
'id' => $row['id_topic'],
'message_id' => $row['id_msg'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['subject'],
'time' => timeformat($row['poster_time']),
'views' => $row['num_views'],
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $txt['sp-read_more'] . '</a>',
'replies' => $row['num_replies'],
'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'],
'comment_link' => !empty($row['locked']) ? '' : '| <a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
'new_comment' => !empty($row['locked']) ? '' : '| <a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
'poster' => array(
'id' => $row['id_member'],
'name' => $row['poster_name'],
'href' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
'link' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name']
),
'locked' => !empty($row['locked']),
'is_last' => false,
'avatar' => array(
'name' => $row['avatar'],
'image' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? '<img src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
'href' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar'])
),
);
}
$smcFunc['db_free_result']($request);

if (empty($return))
{
echo '
', $txt['error_sp_no_posts_found'];
return;
}

$return[count($return) - 1]['is_last'] = true;

if (!empty($colorids) && sp_loadColors($colorids) !== false)
{
foreach ($return as $k => $p)
{
if (!empty($color_profile[$p['poster']['id']]['link']))
$return[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];
}
}

if ($context['SPortal']['core_compat'])
{
foreach ($return as $news)
{
echo '
<div class="tborder sp_article_content">
<table class="sp_block">
<tr class="catbg">
<td class="sp_middle">', $news['icon'], '</td>
<td class="sp_middle sp_regular_padding sp_fullwidth"><a href="', $news['href'], '" >', $news['subject'], '</a></td>
</tr>
<tr class="windowbg">
<td class="sp_regular_padding" colspan="2">';

if ($avatars && $news['avatar']['name'] !== null && !empty($news['avatar']['href']))
echo '
<a href="', $scripturl, '?action=profile;u=', $news['poster']['id'], '"><img src="', $news['avatar']['href'], '" alt="', $news['poster']['name'], '" width="30" style="float: right;" /></a>
<div class="middletext">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], '<br />', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';
else
echo '
<div class="middletext">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], ' | ', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';

echo '
<div class="post"><hr />', $news['body'], '<br /><br /></div>
</td>
</tr>
<tr>
<td class="windowbg2" colspan="2">
<div class="sp_right sp_regular_padding">', $news['link'], ' ',  $news['new_comment'], '</div>
</td>
</tr>
</table>
</div>';
}
}
else
{
foreach ($return as $news)
{
echo '
                 <div class="windowbg sp_article_content">
                 <span class="topslice"><span></span></span>
                 <div class="sp_content_padding">
                 <div class="portal_title"><a href="', $news['href'], '" >', $news['subject'], '</a></div>
                 <div class="middletext" style="font-size: 14px; color: #555555;"><div class="icon-pencil1" style="margin-bottom:.25em; vertical-align:middle;"></div> ', $news['time'], '</div>
                 <div class="post">', $news['body'], '</div>     
                 <br />
                 <div class="button9">', $news['link'], '</div>
                 <br />
                 <br />
                 </div>
                 <span class="botslice"><span></span></span>
                 </div>';
}
}

if (!empty($per_page))
echo '
<div class="sp_page_index">', $txt['sp-articlesPages'], ': ', $page_index, '</div>';

$context['current_pages' . $id] = (($nRows-1) / $perPage) + 1;
$context['custom_display' . $id] = custom_newsPages($txt['pages'], false, currentCustomNewsPage(), $context['current_pages' . $id], false, false, $id, $buttonClass, $buttonStyle, $hoverColors);
       
echo $context['custom_display' . $id]['page'];
}

 
« Last Edit: August 06, 2013, 12:20:44 AM by Underdog »

Offline Mick.

  • Comrade
  • *
  • Posts: 77
  • Gender: Male
  • Premium SMF Themes
    • idesignSMF
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: BoardNews block and pagination question
« Reply #20 on: August 06, 2013, 11:27:56 AM »
Awseome, Thank you.  Got your PM, looking into it.

 Thanx.
Mick.

Offline sub5

  • Semi Newbie
  • *
  • Posts: 25
    • All student forum
  • SMF Version: 2.0.9
  • SP Version: 2.3.6
Re: BoardNews block and pagination question
« Reply #21 on: February 15, 2015, 07:28:24 AM »
Code: [Select]
global $context;

// Adjust your specific parameters
// when/if using the pagination for other blocks on the same page, remember to increment the formId
$parameters['boards'] = 1;
$parameters['limit'] = 50;
$parameters['perPage'] = 5;
$parameters['display'] = 'full';
$parameters['bodyStyle'] = 'windowbg';
$parameters['formId'] = 1;

// Do not bother altering the rest of the code...
$context['current_page' . $parameters['formId']] = !empty($context['current_page' . $parameters['formId']]) ? (int)$context['current_page' . $parameters['formId']] : 1;
$context['current_page' . $parameters['formId']] = (!empty($_REQUEST['current_page' . $parameters['formId']]) ? (int)$_REQUEST['current_page' . $parameters['formId']]-1 : $context['current_page' . $parameters['formId']] - 1);
customRecent($parameters);

function custom_pagination($content, $count=20, $id=1)
{
/* PHP pagination - max 7 visible integers and 6 periods (all links) - current page encircled with square brackets
* This php pagination code was developed by Underdog copyright 2013
* http://webdevelop.comli.com
* Licensed under the GNU Public License: http://www.gnu.org/licenses/gpl.html
*/

// This particular function is only used when opting an entire table else it is not necessary
global $context;

/*  Set the $context variables for the display template  */
$context['current_count' . $id] = count($content);
$context['current_pages' . $id] = (($context['current_count' . $id]) / $count) + 1;

if (count($content) <= $count || $count < 2)
{
$context['current_pages' . $id] = 0;
return $content;
}

if (($context['current_count' . $id] / $count) == (int)($context['current_count' . $id] / $count))
$context['current_pages' . $id] = ($context['current_count' . $id] / $count);

$context['current_showResults' . $id] = array(((int)$context['current_page' . $id] * $count), (((int)$context['current_page' . $id] + 1) * $count) - 1);
       



if ((int)$context['current_page' . $id]+1 == (int)$context['current_pages' . $id])
    $context['current_showResults' . $id][1] = count($content);
else
    $context['current_showResults' . $id][1] = (int)$context['current_page' . $id]*$count + ($count-1);
   
foreach($content as $key => $var)
{
if ((int)$key >= (int)$context['current_showResults' . $id][0] && (int)$key <= (int)$context['current_showResults' . $id][1])
$new_content[] = $var;
}

if (!empty($new_content))
$context['current_showResults' . $id][1] = ((int)$context['current_page' . $id]*$count) + count($new_content);
else
$new_content = $content;

return $new_content;
}

function custom_pages($lang, $anchor, $link, $pages, $sort=false, $order=false, $id=1, $style='windowbg')
{
/* PHP pagination - max 7 visible integers and 6 periods (all links) - current page encircled with square brackets
* This php pagination code was developed by Underdog copyright 2013
* http://webdevelop.comli.com
* Licensed under the GNU Public License: http://www.gnu.org/licenses/gpl.html
*/
global $context, $txt, $scripturl;

$name = 'custom_SpForm' . $id;
$pageCount = 1;
$display = array('page' => false, 'pages' => '0');
$page = !empty($context['current_page' . $id]) ? (int)$context['current_page' . $id] : 0;
$display['pages'] = !empty($pages) ? (int)$pages : 1;

if ($display['pages'] > 1)
{
$display['page'] =  '
<script type="text/javascript"><!-- // --><![CDATA[
function changeColor(s, formId)
{
for (var i=1; i<=3; i++)
                document.getElementById("link"+i+formId).style.color = i==s ? "red" : "blue";
}
function changeColorBack(s, formId)
{
for (var i=1; i<=3; i++)
document.getElementById("link"+i+formId).style.color = i==s ? "blue" : "blue";
}
// ]]></script>
<form name="' . $name .'" action="'.$link.'" method="post" id="' . $name .'">
<span style="text-align:center;position:relative;width:99%;display:inline-block;">
' . $lang . '<br />';

while ($pageCount < (int)$display['pages']+1)
{
$current_page = (int)$page+1;
$total = (int)$display['pages'];
       
if ($pageCount == 1 || $pageCount == $total || $pageCount == $current_page || $pageCount == $current_page+1 ||
    $pageCount == $current_page+2 || $pageCount == $current_page-1 || $pageCount == $current_page-2)
{
                if ((int)$pageCount == (int)$page+1)
$display['page'] .= '
[<input class="' . $style . '" type="button" onclick="this.href=\'javascript: void(0)\';" onmouseout="changeColorBack('. $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="' . $pageCount . '" />] ';
        else
$display['page'] .= '
<input class="' . $style . '" type="submit" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="' . $pageCount . '"  /> ';
}
elseif ($pageCount < $current_page-2 && $pageCount > $current_page-6)
$display['page'] .= '
<input class="' . $style . '" type="submit" onchange="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pagecount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="." onclick="sp_submitPage();" /> ';
elseif ($pageCount > $current_page+2 && $pageCount < $current_page+6)
$display['page'] .= '
<input class="' . $style . '" type="submit" onchange="document.getElementById(\'link' . $pageCount . $id . '\').value='.$pagecount.'" onmouseout="changeColorBack(' . $pageCount . ', ' . $id . ')" onmouseover="changeColor(' . $pageCount . ', ' . $id . ')" id="link' . $pageCount . $id . '" style="border:0;padding:0;margin:0;color:blue;text-decoration:none;" name="current_page' . $id . '" value="." onclick="sp_submitPage();" /> ';

$pageCount++;
}

$display['page'] .= '
</span>   
</form>';
}

return $display;
}

/* Current url */
function currentCustomPage($pageURL = 'http://')
{
if (!empty($_SERVER["HTTPS"]))
$pageURL = "https://";   
   
if ($_SERVER["SERVER_PORT"] != "80")
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
else
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

return $pageURL;
}

function customRecent($parameters)
{
global $txt, $scripturl, $settings, $context, $color_profile;

$boards = !empty($parameters['boards']) ? explode('|', $parameters['boards']) : null;
$limit = !empty($parameters['limit']) ? (int)$parameters['limit'] : 15;
$type = 'ssi_recent' . (empty($parameters['type']) ? 'Posts' : 'Topics');
$display = empty($parameters['display']) ? 'compact' : 'full';
$style = !empty($parameters['bodyStyle']) ? $parameters['bodyStyle'] : 'windowbg';
$id = !empty($parameters['formId']) ? (int)$parameters['formId'] : 1;
$perPage = !empty($parameters['perPage']) ? (int)$parameters['perPage'] : 10;

// $recent_items = $type($limit, null, $boards, 'array');
       
        $items = custom_pagination($type($limit, null, $boards, 'array'), $perPage, $id);       
       
        $context['custom_display' . $id] = array('page' => false, 'pages' => '0');
$context['custom_display' . $id] = custom_pages($txt['pages'], false, currentCustomPage(), $context['current_pages' . $id], false, false, $id, $style);
       
if (empty($items))
{
echo '
', $txt['error_sp_no_posts_found'];
return;
}
else
$items[count($items) - 1]['is_last'] = true;

$colorids = array();
foreach ($items as $item)
$colorids[] = $item['poster']['id'];

if (!empty($colorids) && sp_loadColors($colorids) !== false)
{
foreach ($items as $k => $p)
{
if (!empty($color_profile[$p['poster']['id']]['link']))
$items[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];
}
}

if ($display == 'compact')
{
foreach ($items as $key => $item)
echo '
<a href="', $item['href'], '">', $item['subject'], '</a> <span class="smalltext">', $txt['by'], ' ', $item['poster']['link'], $item['new'] ? '' : ' <a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', $item['time'], ']</span><br />', empty($item['is_last']) ? '<hr />' : '';
}
elseif ($display == 'full')
{
echo '
<table class="sp_fullwidth">';

foreach ($items as $item)
echo '
<tr>
<td class="sp_recent_icon sp_center">
', sp_embed_image(empty($parameters['type']) ? 'post' : 'topic'), '
</td>
<td class="sp_recent_subject">
<a href="', $item['href'], '">', $item['subject'], '</a>
', $item['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', $item['board']['link'], ']
</td>
<td class="sp_recent_info sp_right">
', $item['poster']['link'], '<br />', $item['time'], '
</td>
</tr>';

echo '
</table>';
}
       
        echo $context['custom_display' . $id]['page'];   
}

First thanks for the above code,  i will like to add one or two things to it and i need your help.

I. i want to add something like a border on each news seperting each from another,

2. i will like to add this bellow the each news.



3. to give boder to the images that the board news will display.

Currently i am using a this code i got here at http://simpleportal.net/index.php?topic=10766.msg68082#msg68082 on my forum, but required editing of the portalblocks.php, but i will like to use this one since i wont loss any thing during upgrade. My issue now is how to do the above, i tried editing an i got some Syntax error.
« Last Edit: February 15, 2015, 07:31:01 AM by sub5 »