collapse 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.

* User Info

 
 
Welcome, Guest. Please login or register.

* Who's Online

  • Dot Guests: 222
  • 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]

Blocks speak! Do you have an interest in getting more blocks - or even making your own? The Blocks Board is for you!

Author Topic: A few custom blocks I have need some fixes  (Read 2358 times)

0 Members and 1 Guest are viewing this topic.

Offline owenenene

  • Semi Newbie
  • *
  • Posts: 5
  • SMF Version: None
  • SP Version: 2.3.6
  • Elkarte Version: None
A few custom blocks I have need some fixes
« on: January 13, 2017, 04:46:58 AM »
Hi guys, I'm no good a coder, but I tried and I've got a few custom blocks to work :)

They work the way I'd like them to work, however they have allot of excess code in them and I was wondering if someone could remove the excess code for me.

Number 1:
Code: [Select]
/* Display Frequent Posters for SMF 2.0x by Underdog @http://askusaquestion.net */
/* Format: Horizontal javascript pages */
/* v1.1 */

global $smcFunc, $scripturl, $boardurl;

/* Adjust these */
$number_users = 25;
$lang = ' Posts';
$show_posts = 'Show posts from this user';
$show_profile = '';
$none = 'No users selected';
$show_name = true;
$avatar_width = 50;
$avatar_height = 50;
$row_height = 50; /* <-- adjust depending on amount of text shown under avatar */
$user_name_max = 35; /* <-- max chars for user name display */
$per_row = 5;
$rows = 5;
$prev = 'Prev';
$next = 'Next';

/* Do not edit below this line */

$query = '(users.posts > 0 AND is_activated = 1)';
$datum = array( 'id_member', 'posts', 'real_name', 'avatar', 'filename', 'id_attach');
$x = 0;
$count = 0;
$users = array();
$limit = !empty($number_users) ? (int)$number_users : 20;
$cell_width = 100 / (int)$per_row;

$pages = '<script type="text/javascript"><!--
        var pager = new frequentPager("new", '.(int)$rows.');
        pager.init();
        pager.showPageNav("pager", "l8stPagePosition");
        pager.showPage(1);
    //--></script>';

/* Some js to control the pages */
echo '<script type="text/javascript">
function frequentPager(tableName, itemsPerPage) {
    this.tableName = tableName;
    this.itemsPerPage = itemsPerPage;
    this.currentPage = 1;
    this.pages = 0;
    this.initiated = false;
   
    this.showRecords = function(from, to) {       
        var rows = document.getElementById(tableName).rows;
        // i starts from 1 to skip table header row';
echo "
        for (var i = 1; i < rows.length; i++) {
            if (i < from || i > to) 
                rows[i].style.display = 'none';
            else
                rows[i].style.display = '';
        }";
echo '
    }
   
    this.showPage = function(pageNumberFrequent) {
    if (! this.initiated) {
    alert("not initiated");
    return;
    }';
echo "
        var oldPageAnchor = document.getElementById('pg'+this.currentPage);
        oldPageAnchor.className = 'smalltext pg-normal';
       
        this.currentPage = pageNumberFrequent;
        var newPageAnchor = document.getElementById('pg'+this.currentPage);
        newPageAnchor.className = 'largetext pg-selected';
       
        var from = (pageNumberFrequent - 1) * itemsPerPage + 1;
        var to = from + itemsPerPage - 1;
        this.showRecords(from, to);
    }   
   
    this.prev = function() {
        if (this.currentPage > 1)
            this.showPage(this.currentPage - 1);
    }
   
    this.next = function() {
        if (this.currentPage < this.pages) {
            this.showPage(this.currentPage + 1);
        }
    }                       
   
    this.init = function() {
        var rows = document.getElementById(tableName).rows;
        var records = (rows.length - 1);
        this.pages = Math.ceil(records / itemsPerPage);
        this.initiated = true;
    }";
echo '
    this.showPageNav = function(pagerName, positionId) {
    if (! this.initiated) {
    alert("not initiated");
    return;
    }
    var element = document.getElementById(positionId);';
echo "
    var pagerHtml = '<span onclick=";
echo '"';
echo "' + pagerName + '.prev();";
echo '" class="smalltext pg-normal"> « ', $prev, ' </span> | ';
echo "';
        for (var page = 1; page <= this.pages; page++)
            pagerHtml += '<span id=";
echo '"';
echo "pg' + page + '";
echo '" class="smalltext pg-normal" onclick="';
echo "' + pagerName + '.showPage(' + page + ');";
echo '">';
echo "' + page + '</span> | ';
        pagerHtml += '<span onclick=";
echo '"';
echo "'+pagerName+'.next();";
echo '" class="smalltext pg-normal"> ', $next,' »</span>';
echo "';           
       
        element.innerHTML = pagerHtml;
    }
}
function regenerateFrequent()
{
window.location.reload()
}

function regenerateFrequentPosters()
{
if (document.layers)
{
appearFrequent()
setTimeout(";
echo '"window.onresize=regenerateFrequent",450)
}
}

function changeFrequentText(whichcontent)
{
if (document.all||document.getElementById)
{
cross_el=document.getElementById? document.getElementById("descriptions"):document.all.descriptions
cross_el.innerHTML=';
echo "'<div style=";
echo '"font-family:Arial Narrow Bold;font-size:small;">';
echo "'+whichcontent+'</div>'
}
else if (document.layers)
{
document.d1.document.d2.document.write('<div style=";
echo '"font-family:Arial Narrow Bold;font-size:small;">';
echo "'+whichcontent+'</div>')
document.d1.document.d2.document.close()
}

}

function appearFrequent()
{
document.d1.visibility='show'
}
</script>";
/* end of js controller */

$result = $smcFunc['db_query']('', "SELECT users.id_member, users.posts, users.real_name, users.avatar, users.is_activated, att.id_attach, att.filename FROM {db_prefix}members AS users
LEFT JOIN {db_prefix}attachments AS att ON (att.id_member = users.id_member)
WHERE {$query} ORDER BY users.posts DESC LIMIT {$limit}");
while ($val = $smcFunc['db_fetch_assoc']($result))
{                     
foreach ($datum as $data)
{
if (empty($val[$data]))
$val[$data] = false;

$users[$count][$data] = $val[$data];                                               
}
$count++;
}
$smcFunc['db_free_result']($result);
echo '
<script type="text/javascript">
<!--
window.onload=regenerateFrequentPosters
//-->
</script>';
if ($count == 0)
echo '
<div style="text-align:center">', $none, '</div>';
else
{
echo '
<style style="text/css">
img.opacity {
opacity: 1;
filter: alpha(opacity=100);
}

img.opacity:hover {
opacity: 0.5;
filter: alpha(opacity=50);
}
</style>
<table id ="new" style="width:100%;">
';
foreach ($users as $user)
{
if ((empty($user['posts'])) || !$user['posts'])
continue;
if ($x == 0)
echo '
<tr>';

$x++;
 
if (!$user['avatar'] && !$user['filename'])
$user['avatar'] = $boardurl . '/avatars/noavatar.gif';
elseif (!$user['avatar'])
$user['avatar'] = $scripturl . '?action=dlattach;attach='.$user['id_attach'].';type=avatar';
elseif (substr($user['avatar'], 0, 4) != 'http')
$user['avatar'] = $boardurl .'/avatars/' . $user['avatar'];

$name = strlen($user['real_name']) >= (int)$user_name_max ? $name = substr($user['real_name'],0,(int)$user_name_max).'...':$user['real_name'];
echo '
<td style="text-align:center;width:'.(int)$cell_width.'%;">
<div style="height:'.$row_height.'px;overflow:hidden;">
<a href="'.$scripturl.'?action=profile;u='.$user['id_member'].'" title="'.$show_profile,$user['real_name'].'">
<img src="'. $user['avatar'] . '" style="max-height:'.$avatar_height.'px;max-width:'.$avatar_width.'px;" alt="" class="opacity" />
</a>
</div>
</td>';
if ($x > ((int)$per_row -1))
{
$x=0;
echo '
</tr>';
}
}
echo '
</table>';

if (((int)$per_row * (int)$rows) != (int)$number_users)
echo '
<br />
<div id="l8stPagePosition" style="text-align:center;"> </div>
<div style="text-align:center;">', $pages, '</div>';
}
This is the top posters block, you can find a live example at: www.gameguides.pro/f right side, near the bottom titled "TOP POSTERS"

Instead of going for the same old boring "list" style of top posters, nearly every forum has, I went for a more unique approach. I went and made it into a "wall" of profile pictures, 5 in each row, 5 collumns, total of 25 profile pictures will be displayed. Hovering over a display picture will highlight it, and clicking it will redirect to the  profile. The profiles are in order, from left to right.

The code has allot of excess, from what I can see.. :s



Number 2.

This is a recent topics block I changed about.

Code: [Select]
<?php
/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.7
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?
$exclude_boards null; // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?
$default_avatar 'http://www.gameguides.pro/f/Themes/default/images/default_avatar.png';

// Scroll Enable? Height and Speed?
$scrolling 2;       // ENABLE - 1 | DISABLE - 2
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20
$height "150px";
$scrollbar 2;       // ENABLE - 1 | DISABLE - 2

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' '
IFNULL(u.real_name, m.poster_name) AS poster_name,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'], 
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' '
IFNULL(u.real_name, m.poster_name) AS poster_name,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],  
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

if (
$scrollbar == 1)
echo 
'<div style="height:' $height '; overflow-y: scroll; overflow-x: hidden;">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'
<style style="text/css">
   .hoverTable{
width:100%; 
border-collapse:collapse;
}
/* Define the hover highlight color for the table row */
    .hoverTable tr:hover {
          background-color: #1C1C1C;
    }
.img-circle {
    border-radius: 50%;
}
</style>
<table class="hoverTable">
<tr>
<td style="width: 40px;">'
;
if (!empty(
$post['avatar'])){
echo '<img class="img-circle" src="' $post['avatar'] .'" alt="" width="40px" height="40px" />';
} else {
echo '<img class="img-circle" src="' $default_avatar .'" alt="" width="40px" height="40px" />';
}

echo 
'</td>
<td>
&nbsp;' 
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '<br />
&nbsp;' 
$text['who'] . '&nbsp;' $post['username'] . '
</td>
</tr>
</table>'
;

echo 
'';
}


        
//Scrolling xD
if ($scrollbar == 1)
echo 
'</div>'

if (
$scrolling == 1)
echo 
'</marquee></div>';
?>

Again, live example at gameguides.pro/f right side.

The block hasn't been changed much, but again, it does have allot of exess code such as the scrollbar feature.



Like i said, I aint got much experience or whatever, but I'm sure excess code isn't a good thing? right? like does it slow it down by a few miliseconds? add some extra load? :P

If someone can let me know if it is okay for me to continue using the blocks in the current state it would be great, and if someone could remove the excess code it would be even better!

ps: i will be creating a few topics on my forum on all the coding i've used, from on the pages to the blocks themselves. So i will be referencing back to this website if it's okay as allot of the code is from this webiste :)