Author Topic: Neat SSI functions (SMF 1.1.x)  (Read 1680 times)

0 Members and 1 Guest are viewing this topic.

Offline tyty1234

  • V.I.P.
  • *
  • Posts: 823
  • Karma: 1109
  • Gender: Male
    • tytyweb
  • SMF Version: 2.0.2
Neat SSI functions (SMF 1.1.x)
« on: March 28, 2009, 09:50:52 PM »
Here are a few SSI functions I created. All tested with SMF 1.1.8, but should work with 1.1.x. Will test it with SMF 2.0 in the near future. :)

(All functions go in the SSI.php file)

<?php ssi_loginWelcome(); ?>
This function displays a login box and a welcome message for guests, and users not logged in.
:
// Shows a login box+welcome message.
function ssi_loginWelcome($redirect_to = '', $output_method = 'echo')
{
    global $scripturl, $txt, $user_info, $context;

    if ($redirect_to != '')
        $_SESSION['login_url'] = $redirect_to;

    if ($output_method != 'echo' || !$user_info['is_guest'])
        return $user_info['is_guest'];

    echo '
    ', $txt['welcome_guest'], '<br/>
    ', $context['current_time'], '<br/>
    <form action="', $scripturl, '?action=login2" method="post" >
    <table border="0" cellspacing="1" cellpadding="0" class="ssi_table">
    <tr>
        <td align="right"><label for="user">', $txt[35], ':</label>&nbsp;</td>
        <td><input type="text" name="user" id="user" size="10" /></td>
    </tr>
    <tr>
        <td align="right"><label for="passwrd">', $txt[36], ':</label>&nbsp;</td>
        <td><input type="password" name="passwrd" id="passwrd" size="10" /></td>
    </tr>
    <tr>
        <td align="right"><label for="cookielength">Length:</label>&nbsp;</td>
        <td>
        <select name="cookielength" id="cookielength">
            <option value="60">', $txt['smf53'], '</option>
            <option value="1440">', $txt['smf47'], '</option>
            <option value="10080">', $txt['smf48'], '</option>
            <option value="302400">', $txt['smf49'], '</option>
            <option value="-1" selected="selected">', $txt['smf50'], '</option>
        </select>
        </td>
    </tr>
    <tr>
        <td align="right"><input type="submit" value="', $txt[34], '" /></td>
    </tr>
    <tr>
        <td colspan="2">', $txt['smf52'], '</td>
    </tr>
    </table>
    </form>';
}

<?php ssi_recentTopics2(); ?>
This function will show the most recent topics made to the board, just like the first one, but has a nicer layout. Works well in a left or right column.

:
// Recent topic list, with a nice layout to it.
function ssi_recentTopics2($output_method = 'echo')
{
    global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER;
    global $user_info, $modSettings, $func;

    $recentPosts = ssi_recentTopics(8, null, 'array');

    echo '
        <div style="width: 100%; ">';

        $count = 1; $max = 9;

    foreach ($recentPosts as $post){
                $count++;
        echo '
            <div class="smalltext">
                <a href="', $post['href'], '">', $post['short_subject'], '[/url]
                        </div>
                        <div class="smalltext">
                ', $txt[525], ' ', $post['poster']['link'], '
                ', $post['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt[302] . '" border="0" /></a>', '
            </div>
                       <div class="smalltext">
                    [', $post['time'], ']
            </div>';

        if($count != $max){
                echo '
                        ';
          }
    }
    echo '
        </div>';
}

<?php ssi_statsFull(); ?>
This function will display a full list of stats, including Total Members, Latest Members, Total Posts, Total Topics, Most Online Today, Most Online Ever, and users online. It also includes the current date and time, and will need this bullet.

:
// A list of combined stats from board stats,to member stats.
function ssi_statsFull($output_method = 'echo')
{
    global $context, $settings, $options, $scripturl, $txt, $modSettings;

    $bullet = '<img src="'.$settings['images_url'].'/divider.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
    $bullet2 = '<img src="'.$settings['images_url'].'/divider2.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
      echo'<div class="smalltext">';

       // Members stats.
            echo '
                 <img src="'.$settings['images_url'].'/icons/members.gif" style="margin: 0;" align="bottom" alt="" />
                 <a href="'.$scripturl.'?action=mlist">'.$txt[19].'</a>
                 <br/>'.$bullet.$txt[488].': ' , isset($modSettings['memberCount']) ? $modSettings['memberCount'] : $modSettings['totalMembers'] , '
                 <br/>'.$bullet.$txt[656]. ': <a href="', $scripturl, '?action=profile;u=', $modSettings['latestMember'], '">', $modSettings['latestRealName'], '</a>';
                 
       // More stats.
            echo '
                  <img src="'.$settings['images_url'].'/icons/info.gif" style="margin: 0;" align="bottom" alt="" />
                 <a href="'.$scripturl.'?action=stats">'.$txt['stats'].'[/url]
                 <br/>'.$bullet.$txt[489].': '.$modSettings['totalMessages']. '
                  <br/>'.$bullet. $txt[490].': '.$modSettings['totalTopics']. '
                  <br/>'.$bullet.$txt['most_online_today'].': '.$modSettings['mostOnlineToday'].'
                  <br/>'.$bullet.$txt['most_online_ever'].': '.$modSettings['mostOnline'].'<br/>
                      ('.timeformat($modSettings['mostDate']).')
                  ';

       // Add online users.
            echo '<img src="'.$settings['images_url'].'/icons/online.gif" style="margin: 0;" align="bottom" alt="" />
                 <a href="'.$scripturl.'?action=who">'.$txt[158].'</a><br/>';

            $online = ssi_whosOnline('array');
       echo $bullet.$txt['users'].': '.$online['num_users'];
       echo '<br/>'.$bullet.$txt['guests'].': '.$online['guests'];
       echo '<br/>'.$bullet.$txt[94].': '.$online['total_users'].'            <div style="width: 100%; ' , $online['num_users']>14 ? 'height: 23ex;overflow: auto;' : '' ,'">';

      foreach($online['users'] as $user){
        echo $bullet2 , $user['hidden'] ? '' . $user['link'] . '' : $user['link'];
        echo '[br /]';
       }
        echo '</div>';
    echo '</div>';
}

<?php ssi_boardNews2(); ?>
This function will display the topic name, and the date the topic was posted, in a neat table. This function does not display the body of the content of the topic. Useful when you want to display a few topics, and when you're not using pagination.

:
// Show the latest news, with a nice template... by board.
function ssi_boardNews2($board = null, $limit = null, $output_method = 'echo')
{
    global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
    global $func;

    $boardNews = ssi_boardNews($board, $limit, null, null, 'array');

    foreach ($boardNews as $news)
    {
        echo '
            <div>
                <a href="', $news['href'], '"><strong>', $news['subject'], '</strong></a><br/>
                <div class="smalltext"><strong>', $news['time'], '</strong></div>
            </div>';

        if (!$news['is_last'])
            echo '
            <hr style="margin: 2ex 0;" width="100%" />';
    }
}

<?php ssi_boardPoll(); ?>
This function will grab the most recent poll from a specified board. Just like recent poll, but will grab it from a one board.

:
// Show the recent poll from a board.
function ssi_boardPoll($board = null, $output_method = 'echo')
{
    global $db_prefix, $txt, $ID_MEMBER, $settings, $boardurl, $sc, $user_info;
    global $context;
   
    $request = db_query("
        SELECT p.ID_POLL, p.question, p.votingLocked, p.hideResults, p.expireTime, p.maxVotes, b.ID_BOARD
        FROM ({$db_prefix}topics AS t, {$db_prefix}polls AS p, {$db_prefix}boards AS b)
            LEFT JOIN {$db_prefix}log_polls AS lp ON (lp.ID_POLL = p.ID_POLL AND lp.ID_MEMBER = $ID_MEMBER)
        WHERE p.votingLocked = 0
            AND lp.ID_CHOICE IS NULL
            AND t.ID_POLL = p.ID_POLL
            AND t.ID_BOARD = $board
            AND $user_info[query_see_board]
        ORDER BY p.ID_POLL DESC
        LIMIT 1", __FILE__, __LINE__);

    $row = mysql_fetch_assoc($request);
    mysql_free_result($request);

    // Check if they can vote.
    if (!empty($row['expireTime']) && $row['expireTime'] < time())
        $allow_vote = false;
    elseif (!empty($row['votingLocked']))
        $allow_vote = false;
    else
    {
        $request = db_query("
            SELECT ID_MEMBER
            FROM {$db_prefix}log_polls
            WHERE ID_POLL = $row[ID_POLL]
                AND ID_MEMBER = $ID_MEMBER
            LIMIT 1", __FILE__, __LINE__);
        $allow_vote = mysql_num_rows($request) == 0;
        mysql_free_result($request);
    }

    $request = db_query("
        SELECT COUNT(DISTINCT ID_MEMBER)
        FROM {$db_prefix}log_polls
        WHERE ID_POLL = $row[ID_POLL]", __FILE__, __LINE__);
    list ($total) = mysql_fetch_row($request);
    mysql_free_result($request);

    $request = db_query("
        SELECT ID_CHOICE, label, votes
        FROM {$db_prefix}poll_choices
        WHERE ID_POLL = $row[ID_POLL]", __FILE__, __LINE__);
    $options = array();
    $total_votes = 0;
    while ($rowChoice = mysql_fetch_assoc($request))
    {
        censorText($rowChoice['label']);

        $options[$rowChoice['ID_CHOICE']] = array($rowChoice['label'], $rowChoice['votes']);
        $total_votes += $rowChoice['votes'];
    }
    mysql_free_result($request);

    $return = array(
        'id' => $row['ID_POLL'],
        'image' => empty($pollinfo['votingLocked']) ? 'poll' : 'locked_poll',
        'question' => $row['question'],
        'total_votes' => $total,
        'is_locked' => !empty($pollinfo['votingLocked']),
        'allow_vote' => $allow_vote,
        'options' => array()
    );

    // Calculate the percentages and bar lengths...
    $divisor = $total_votes == 0 ? 1 : $total_votes;
    foreach ($options as $i => $option)
    {
        $bar = floor(($option[1] * 100) / $divisor);
        $barWide = $bar == 0 ? 1 : floor(($bar * 5) / 3);
        $return['options'][$i] = array(
            'id' => 'options-' . $i,
            'percent' => $bar,
            'votes' => $option[1],
            'bar' => '<span style="white-space: nowrap;"><img src="' . $settings['images_url'] . '/poll_left.gif" alt="" /><img src="' . $settings['images_url'] . '/poll_middle.gif" width="' . $barWide . '" height="12" alt="-" /><img src="' . $settings['images_url'] . '/poll_right.gif" alt="" /></span>',
            'option' => parse_bbc($option[0]),
            'vote_button' => '<input type="' . ($row['maxVotes'] > 1 ? 'checkbox' : 'radio') . '" name="options[]" id="options-' . $i . '" value="' . $i . '" class="check" />'
        );
    }

    $return['allowed_warning'] = $row['maxVotes'] > 1 ? sprintf($txt['poll_options6'], $row['maxVotes']) : '';

    if ($output_method != 'echo')
        return $return;

    if ($return['allow_vote'])
    {
        echo '
            <form action="', $boardurl, '/SSI.php?ssi_function=pollVote" method="post" accept-charset="', $context['character_set'], '">
                <input type="hidden" name="poll" value="', $return['id'], '" />
                <table border="0" cellspacing="1" cellpadding="0" class="ssi_table">
                    <tr>
                        <td>', $return['question'], '</td>
                    </tr>
                    <tr>
                        <td>', $return['allowed_warning'], '</td>
                    </tr>';
        foreach ($return['options'] as $option)
            echo '
                    <tr>
                        <td><label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label></td>
                    </tr>';
        echo '
                    <tr>
                        <td>';
                       
                        if ($user_info['is_guest'])
                        {
                            echo '<strong>Please login or register to vote.</strong>';
                        } else {
                            echo '<input type="submit" value="', $txt['smf23'], '" />';
                        }
                       
        echo '</td>
                    </tr>
                </table>
                <input type="hidden" name="sc" value="', $sc, '" />
            </form>';
    }
    else
    {
        echo '
                <table border="0" cellspacing="1" cellpadding="0" class="ssi_table">
                    <tr>
                        <td colspan="2">', $return['question'], '</td>
                    </tr>';
        foreach ($return['options'] as $option)
            echo '
                    <tr>
                        <td align="right" valign="top">', $option['option'], '</td>
                        <td align="left">', $option['bar'], ' ', $option['votes'], ' (', $option['percent'], '%)</td>
                    </tr>';
        echo '
                    <tr>
                        <td colspan="2">', $txt['smf24'], ': ', $return['total_votes'], '</td>
                    </tr>
                </table>';
    }
}

Hope you guys find some of these functions useful, and helpful! If you have any questions, drop a comment here. :)
« Last Edit: April 01, 2009, 07:53:58 PM by tyty1234 »

Offline Cholo

  • Global Moderator
  • *
  • Posts: 1737
  • Karma: 681
  • Gender: Male
    • The Tarheel Forum
Re: Neat SSI functions (SMF 1.1.x)
« Reply #1 on: March 29, 2009, 01:59:05 AM »
Coool.  Thanks very much for sharing that with us.   Too bad I'm upgrading to RC1 lol.

Offline tyty1234

  • V.I.P.
  • *
  • Posts: 823
  • Karma: 1109
  • Gender: Male
    • tytyweb
  • SMF Version: 2.0.2
Re: Neat SSI functions (SMF 1.1.x)
« Reply #2 on: March 29, 2009, 03:10:25 AM »
Well, it might just work with RC1, but not sure. I'll have to test it out. :)

Offline brianjw

  • Guru
  • *
  • Posts: 2346
  • Karma: 1408
  • Gender: Male
  • What?!?! You mean they're sold out!
Re: Neat SSI functions (SMF 1.1.x)
« Reply #3 on: March 29, 2009, 10:43:34 PM »
TyTy, those are great! Everything you've posted is actually something I have been looking for at one time or another. You might get lots of downloads if you package it up and put it on the SMF modsite.

And if you can get those working for 2.0 RC1 too, that'd be great! :)

Offline tyty1234

  • V.I.P.
  • *
  • Posts: 823
  • Karma: 1109
  • Gender: Male
    • tytyweb
  • SMF Version: 2.0.2
Re: Neat SSI functions (SMF 1.1.x)
« Reply #4 on: March 29, 2009, 11:57:49 PM »
TyTy, those are great! Everything you've posted is actually something I have been looking for at one time or another. You might get lots of downloads if you package it up and put it on the SMF modsite.

And if you can get those working for 2.0 RC1 too, that'd be great! :)
Yeah, I've been thinking of putting it on the mod site, but I'd rather just stick to it being snippets instead of mods. (even though technically it's considered a mod, but oh well :))

Offline shadownexusruler

  • Hero Member
  • *
  • Posts: 424
  • Karma: 19
    • RMSanctum
  • SMF Version: smf 1.1.7
Re: Neat SSI functions (SMF 1.1.x)
« Reply #5 on: March 31, 2009, 04:20:21 PM »
does the code in the code box goes in ssi.php and you place this in your webpage

<?php ssi_loginWelcome(); ?>

Site with SMFH Hosting: RMSanctum.com

Offline tyty1234

  • V.I.P.
  • *
  • Posts: 823
  • Karma: 1109
  • Gender: Male
    • tytyweb
  • SMF Version: 2.0.2
Re: Neat SSI functions (SMF 1.1.x)
« Reply #6 on: March 31, 2009, 04:47:28 PM »
that's correct. :)

Offline shadownexusruler

  • Hero Member
  • *
  • Posts: 424
  • Karma: 19
    • RMSanctum
  • SMF Version: smf 1.1.7
Re: Neat SSI functions (SMF 1.1.x)
« Reply #7 on: March 31, 2009, 04:49:23 PM »
where in the ssi.php should i place the code for ssi_loginwelcome()

Site with SMFH Hosting: RMSanctum.com

Offline tyty1234

  • V.I.P.
  • *
  • Posts: 823
  • Karma: 1109
  • Gender: Male
    • tytyweb
  • SMF Version: 2.0.2
Re: Neat SSI functions (SMF 1.1.x)
« Reply #8 on: March 31, 2009, 05:01:24 PM »
If anything, add it to the end of the file.

Offline ccbtimewiz

  • Dreamer
  • Guru
  • *
  • Posts: 1304
  • Karma: 2100
  • Gender: Male
  • $info->close();
    • Dream Portal
  • SMF Version: SMF 2.0 RC4

Offline shadownexusruler

  • Hero Member
  • *
  • Posts: 424
  • Karma: 19
    • RMSanctum
  • SMF Version: smf 1.1.7
Re: Neat SSI functions (SMF 1.1.x)
« Reply #10 on: April 01, 2009, 12:29:09 AM »
in the pictures below am i missing some images

Site with SMFH Hosting: RMSanctum.com

Offline tyty1234

  • V.I.P.
  • *
  • Posts: 823
  • Karma: 1109
  • Gender: Male
    • tytyweb
  • SMF Version: 2.0.2
Re: Neat SSI functions (SMF 1.1.x)
« Reply #11 on: April 01, 2009, 02:21:17 PM »
Shadow, I edited the OP so that every "br" and "url" is actually a <br > tag and a </a > tag.

Plus, there was one image you needed for the ssi_statsFull() function, which was this bullet. Which I specifically said up above.

Offline shadownexusruler

  • Hero Member
  • *
  • Posts: 424
  • Karma: 19
    • RMSanctum
  • SMF Version: smf 1.1.7
Re: Neat SSI functions (SMF 1.1.x)
« Reply #12 on: April 02, 2009, 01:07:05 AM »
oh ok thanks tyty should upload the corrections you made

Site with SMFH Hosting: RMSanctum.com

Offline I AM Legend

  • Elite Member
  • *
  • Posts: 781
  • Karma: 330
  • Gender: Male
Re: Neat SSI functions (SMF 1.1.x)
« Reply #13 on: April 02, 2009, 03:17:20 AM »
Can these be used with T P  ???

Offline tyty1234

  • V.I.P.
  • *
  • Posts: 823
  • Karma: 1109
  • Gender: Male
    • tytyweb
  • SMF Version: 2.0.2
Re: Neat SSI functions (SMF 1.1.x)
« Reply #14 on: April 02, 2009, 04:18:49 AM »
Can these be used with T P  ???
Well, I did base most of them off TP...don't see why it won't work. :)