TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

March 28, 2024, 08:08:50 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,104
  • Total Topics: 21,212
  • Online today: 143
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 127
  • Total: 127

A few questions

Started by [chrisB], January 03, 2023, 09:05:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

@rjen

check this code. This will leave the other avatars alone and it will also respect the settings from the avatar integration mod.

If you check what I changed you'll get a better understanding how to do this yourself.

global $context, $settings, $scripturl, $txt, $user_info;

$bullet = '<img src="'.$settings['tp_images_url'].'/TPdivider.png" alt="" style="margin:0 4px 0 0;" />';
$bullet2 = '<img src="'.$settings['tp_images_url'].'/TPdivider2.png" alt="" style="margin:0 4px 0 0;" />';
$bullet3 = '<img src="'.$settings['tp_images_url'].'/TPdivider3.png" alt="" style="margin:0 4px 0 0;" />';
$bullet4 = '<img src="'.$settings['tp_images_url'].'/TPmodule2.png" alt="" style="margin:0 4px 0 0;" />';
$bullet5 = '<img src="'.$settings['tp_images_url'].'/TPmodule2.png" alt="" style="margin:0 4px 0 0;" />';

// Text strings
$txt['tp-blockinbox'] = 'Inbox:';
$txt['tp-blockposts'] = 'Posts';


echo'

<style>
.tp_userblocknew2 .avatar {
   height: auto;
    width: 80px;
}
.floatdiv {
width:50%;
display:inline-block;
float: left;
text-align: center;
}
</style>

<div class="tp_userblocknew2">';
// If the user is logged in, display stuff like their name, new messages, etc.
if ($context['user']['is_logged'])
{
if (!empty($context['user']['avatar']) &&  isset($context['TPortal']['userbox']['avatar']))
{
echo '
<span class="tpavatar">', $context['user']['avatar']['image'], '</span>';
}
echo '
      <strong><a class="subject"  href="'.$scripturl.'?action=profile;u='.$context['user']['id'].'">', $context['user']['name'], '</a></strong>
      <ul class="reset">';

// Only tell them about their messages if they can read their messages!
if ($context['allow_pm'])
{
echo '
<li><a href="', $scripturl, '?action=pm">' .$bullet.$txt['tp-blockinbox'].' ',  $context['user']['messages'], '</a></li>';
}
echo '
<li><a href="', $scripturl, '?action=profile;u='.$context['user']['id'].';area=showposts">'.$bullet3.$txt['tp-blockposts'].'</a></li>
<li><a href="', $scripturl, '?action=unread">' .$bullet3.$txt['tp-unread'].'</a></li>
<li><a href="', $scripturl, '?action=unreadreplies">'.$bullet3.$txt['tp-replies'].'</a></li>
<hr>';

// Is the forum in maintenance mode?
if ($context['in_maintenance'] && $context['user']['is_admin'])
echo '
<li>' .$bullet2.$txt['tp_maintenace']. '</li>';

// admin parts etc.
         if(!isset($context['TPortal']['can_submit_article']))
            $context['TPortal']['can_submit_article']=0;

// can we submit an article?
        if(allowedTo('tp_submithtml'))
echo '
<li><a href="', $scripturl, '?action=' . (allowedTo('tp_articles') ? 'tpadmin' : 'tportal') . ';sa=addarticle_html">' . $bullet2.$txt['tp-submitarticle']. '</a></li>';
        if(allowedTo('tp_submitbbc'))
echo '
<li><a href="', $scripturl, '?action=' . (allowedTo('tp_articles') ? 'tpadmin' : 'tportal') . ';sa=addarticle_bbc">' . $bullet2.$txt['tp-submitarticlebbc']. '</a></li>';

if(allowedTo('tp_editownarticle'))
echo '
<li><a href="', $scripturl, '?action=tportal;sa=myarticles">' . $bullet2.$txt['tp-myarticles']. '</a></li>';
if (allowedTo('tp_articles'))
{
echo '
<li><a href="' . $scripturl . '?action=tpadmin;sa=articles">' . $bullet4.$txt['permissionname_tp_articles'] . '</a></li>';
// any submissions?
if($context['TPortal']['submitcheck']['articles']>0)
echo '
<li><a href="' . $scripturl . '?action=tpadmin;sa=submission"><b>' . $bullet4 . ' ' .$txt['tp-articlessubmitted'] . ' ' .$context['TPortal']['submitcheck']['articles'] . '</b></a></li>';
}

echo '
<hr>
<div class="floatdiv"><span class="main_icons members"></span><a href="'.$scripturl.'?action=profile;area=forumprofile;u='.$context['user']['id'].'"> Profile</a></div>
<div class="floatdiv"><a href="', $scripturl, '?action=logout;u='.$context['user']['id'].'"><span class="main_icons logout"></span> Log out</a></div>';

echo '
</ul>';
}
// Otherwise they're a guest - so politely ask them to register or login.
else  {
if(TP_SMF21) {
echo '
<div style="line-height: 1.4em;">', sprintf($txt[$context['can_register'] ? 'tp-welcome_guest_register' : 'tp-welcome_guest'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup'), '<br><br>', $context['current_time'], '</div>';
}
else {
echo '
<div style="line-height: 1.4em;">', sprintf($txt['welcome_guest'], $txt['guest_title']), '<br><br>', $context['current_time'], '</div>';
}
    echo '
        <form style="margin-top: 5px;" action="', $scripturl, '?action=login2" method="post" >
            <input type="text" class="input_text" name="user" size="10" style="max-width: 45%!important;"/> <input type="password" class="input_password" name="passwrd" size="10" style="max-width: 45%!important;"/><br>
            <select name="cookielength" style="max-width: 45%!important;">
                <option value="-1" selected="selected">', $txt['forever'], '</option>
                <option value="60">', $txt['one_hour'], '</option>
                <option value="1440">', $txt['one_day'], '</option>
                <option value="10080">', $txt['one_week'], '</option>
                <option value="302400">', $txt['one_month'], '</option>
            </select>
            <input type="submit" class="button_submit" value="', $txt['login'], '" />
            <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />';
if (TP_SMF21) {
echo '
<input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '">';
}
echo '
        </form>
        <div style="line-height: 1.4em;" class="middletext">', $txt['tp-quick_login_dec'], '</div>';
}
echo '
</div>';
Running Latest TP on SMF2.1 at: www.fjr-club.nl

[chrisB]

rjen you're awesome! Thank you very much.

[chrisB]

I am using this block to show content from two main sections of my forum on the home page of my site. I would like to include the forum location of where the posts are. Could someone tell me how to make this edit please?

Post Title - By
Forum Location
Time of Post

// blocktype 12: Recent Topics
function TPortal_recentbox()
{
   global $scripturl, $context, $settings, $txt, $modSettings, $user_info;

   // if no guest access to forum, then no recent topics
   if($modSettings['allow_guestAccess'] == '0' && $user_info['is_guest']) {
      echo '' .$txt['tp-noguest_access'] .'';
   }
   else {
   // is it a number?
   if(is_numeric($context['TPortal']['recentlength']))
      $recentlength = $context['TPortal']['recentlength'];
   else
      $recentlength = '25';
   // exclude boards
   if (isset($context['TPortal']['recentboards']) && $context['TPortal']['boardmode'] == 0)
      $exclude_boards = $context['TPortal']['recentboards'];
   else {
   // leave out the recycle board, if any
      if(isset($modSettings['recycle_board']) && $modSettings['recycle_enable'] = 1 )
      $bb = array($modSettings['recycle_board']);
      $exclude_boards = $bb;
   }

   // include boards
   if (isset($context['TPortal']['recentboards']) && !$context['TPortal']['boardmode'] == 0)
      $include_boards = $context['TPortal']['recentboards'];
   else
      $include_boards = null;

   $what = ssi_recentTopics($num_recent = $context['TPortal']['recentboxnum'] , $exclude_boards,  $include_boards, $output_method = 'array');
   if($context['TPortal']['useavatar'] == 0)
   {
      // Output the topics
      echo '
      <ul class="recent_topics" style="' , isset($context['TPortal']['recentboxscroll']) && $context['TPortal']['recentboxscroll'] == 1 ? 'overflow: auto; height: 20ex;' : '' , 'margin: 0; padding: 0;">';
      $coun = 1;
      foreach($what as $wi => $w)
      {
         $tpshortsubject = $w['subject'];
         $w['readmore'] = '';
         if(TPUtil::shortenString($tpshortsubject, $recentlength)) {
            $w['readmore'] = '...';
         }
         echo '
         <li' , $coun<count($what) ? '' : ' style="border: none; margin-bottom: 0;padding-bottom: 0;"'  , '>';
         if ((TP_SMF21) && ($w['is_new']))
            echo ' <a href="' . $scripturl . '?topic=' . $w['topic'] . '.msg' . $w['new_from'] . ';topicseen#new" rel="nofollow" class="new_posts" style="margin:0px;">' . $txt['new'] . '</a> ';
         echo '
            <a href="' . $w['href'] . '" title="' . $w['subject'] . '">'. $tpshortsubject .''. $w['readmore'] .'</a>
             ', $txt['by'], ' <b>', $w['poster']['link'],'</b> ';
         if (!(TP_SMF21) && ($w['is_new']))
            echo ' <a href="' . $scripturl . '?topic=' . $w['topic'] . '.msg' . $w['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" /></a>';
         echo '<br><span class="smalltext">['.$w['time'].']</span>
         </li>';
         $coun++;
      }
      echo '
      </ul>';
   }
   else
   {
      $member_ids = array();
      foreach($what as $wi => $w)
      {
         $member_ids[] = $w['poster']['id'];
      }

      if(!empty($member_ids))
         $avatars = progetAvatars($member_ids);
      else
         $avatars = array();

      // Output the topics
      $coun = 1;
      echo '
      <ul class="recent_topics" style="' , isset($context['TPortal']['recentboxscroll']) && $context['TPortal']['recentboxscroll']==1 ? 'overflow: auto; height: 20ex;' : '' , 'margin: 0; padding: 0;">';

      foreach($what as $wi => $w)
      {
         $tpshortsubject = $w['subject'];
         $w['readmore'] = '';
         if(TPUtil::shortenString($tpshortsubject, $recentlength)) {
            $w['readmore'] = '...';
         }
         echo '
         <li' , $coun<count($what) ? '' : ' style="border: none; margin-bottom: 0;padding-bottom: 0;"'  , '>';
         if ((TP_SMF21) && ($w['is_new']))
            echo ' <a href="' . $scripturl . '?topic=' . $w['topic'] . '.msg' . $w['new_from'] . ';topicseen#new" rel="nofollow" class="new_posts" style="margin:0px;">' . $txt['new'] . '</a> ';
         echo '
               <span class="tpavatar"><a href="' . $scripturl. '?action=profile;u=' . $w['poster']['id'] . '">' , empty($avatars[$w['poster']['id']]) ? '<img src="' . $settings['tp_images_url'] . '/TPguest.png" alt="" />' : $avatars[$w['poster']['id']] , '</a></span><a href="'.$w['href'].'" title="' . $w['subject'] . '">'. $tpshortsubject .''. $w['readmore'] .'</a>
             ', $txt['by'], ' <b>', $w['poster']['link'],'</b> ';
         if (!(TP_SMF21) && ($w['is_new']))
            echo ' <a href="' . $scripturl . '?topic=' . $w['topic'] . '.msg' . $w['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" /></a>';
         echo '<br><span class="smalltext">['.$w['time'].']</span>
         </li>';
         $coun++;
      }
      echo '
      </ul>';
      }
   }
}

@rjen

What do you mean with forum location?

The board?
Running Latest TP on SMF2.1 at: www.fjr-club.nl

[chrisB]


@rjen

Quote from: [chrisB] on January 21, 2023, 09:40:15 PM
I am using this block to show content from two main sections of my forum on the home page of my site. I would like to include the forum location of where the posts are. Could someone tell me how to make this edit please?

Post Title - By
Forum Location
Time of Post

// blocktype 12: Recent Topics
function TPortal_recentbox()
{
   global $scripturl, $context, $settings, $txt, $modSettings, $user_info;

   // if no guest access to forum, then no recent topics
   if($modSettings['allow_guestAccess'] == '0' && $user_info['is_guest']) {
      echo '' .$txt['tp-noguest_access'] .'';
   }
   else {
   // is it a number?
   if(is_numeric($context['TPortal']['recentlength']))
      $recentlength = $context['TPortal']['recentlength'];
   else
      $recentlength = '25';
   // exclude boards
   if (isset($context['TPortal']['recentboards']) && $context['TPortal']['boardmode'] == 0)
      $exclude_boards = $context['TPortal']['recentboards'];
   else {
   // leave out the recycle board, if any
      if(isset($modSettings['recycle_board']) && $modSettings['recycle_enable'] = 1 )
      $bb = array($modSettings['recycle_board']);
      $exclude_boards = $bb;
   }

   // include boards
   if (isset($context['TPortal']['recentboards']) && !$context['TPortal']['boardmode'] == 0)
      $include_boards = $context['TPortal']['recentboards'];
   else
      $include_boards = null;

   $what = ssi_recentTopics($num_recent = $context['TPortal']['recentboxnum'] , $exclude_boards,  $include_boards, $output_method = 'array');
   if($context['TPortal']['useavatar'] == 0)
   {
      // Output the topics
      echo '
      <ul class="recent_topics" style="' , isset($context['TPortal']['recentboxscroll']) && $context['TPortal']['recentboxscroll'] == 1 ? 'overflow: auto; height: 20ex;' : '' , 'margin: 0; padding: 0;">';
      $coun = 1;
      foreach($what as $wi => $w)
      {
         $tpshortsubject = $w['subject'];
         $w['readmore'] = '';
         if(TPUtil::shortenString($tpshortsubject, $recentlength)) {
            $w['readmore'] = '...';
         }
         echo '
         <li' , $coun<count($what) ? '' : ' style="border: none; margin-bottom: 0;padding-bottom: 0;"'  , '>';
         if ((TP_SMF21) && ($w['is_new']))
            echo ' <a href="' . $scripturl . '?topic=' . $w['topic'] . '.msg' . $w['new_from'] . ';topicseen#new" rel="nofollow" class="new_posts" style="margin:0px;">' . $txt['new'] . '</a> ';
         echo '
            <a href="' . $w['href'] . '" title="' . $w['subject'] . '">'. $tpshortsubject .''. $w['readmore'] .'</a>
             ', $txt['by'], ' <b>', $w['poster']['link'],'</b> ';
         if (!(TP_SMF21) && ($w['is_new']))
            echo ' <a href="' . $scripturl . '?topic=' . $w['topic'] . '.msg' . $w['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" /></a>';
         echo '<br><span class="smalltext">['.$w['time'].']</span>
         </li>';
         $coun++;
      }
      echo '
      </ul>';
   }
   else
   {
      $member_ids = array();
      foreach($what as $wi => $w)
      {
         $member_ids[] = $w['poster']['id'];
      }

      if(!empty($member_ids))
         $avatars = progetAvatars($member_ids);
      else
         $avatars = array();

      // Output the topics
      $coun = 1;
      echo '
      <ul class="recent_topics" style="' , isset($context['TPortal']['recentboxscroll']) && $context['TPortal']['recentboxscroll']==1 ? 'overflow: auto; height: 20ex;' : '' , 'margin: 0; padding: 0;">';

      foreach($what as $wi => $w)
      {
         $tpshortsubject = $w['subject'];
         $w['readmore'] = '';
         if(TPUtil::shortenString($tpshortsubject, $recentlength)) {
            $w['readmore'] = '...';
         }
         echo '
         <li' , $coun<count($what) ? '' : ' style="border: none; margin-bottom: 0;padding-bottom: 0;"'  , '>';
         if ((TP_SMF21) && ($w['is_new']))
            echo ' <a href="' . $scripturl . '?topic=' . $w['topic'] . '.msg' . $w['new_from'] . ';topicseen#new" rel="nofollow" class="new_posts" style="margin:0px;">' . $txt['new'] . '</a> ';
         echo '
               <span class="tpavatar"><a href="' . $scripturl. '?action=profile;u=' . $w['poster']['id'] . '">' , empty($avatars[$w['poster']['id']]) ? '<img src="' . $settings['tp_images_url'] . '/TPguest.png" alt="" />' : $avatars[$w['poster']['id']] , '</a></span><a href="'.$w['href'].'" title="' . $w['subject'] . '">'. $tpshortsubject .''. $w['readmore'] .'</a>
             ', $txt['by'], ' <b>', $w['poster']['link'],'</b> ';
         if (!(TP_SMF21) && ($w['is_new']))
            echo ' <a href="' . $scripturl . '?topic=' . $w['topic'] . '.msg' . $w['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" /></a>';
         echo '<br><span class="smalltext">['.$w['time'].']</span>
         </li>';
         $coun++;
      }
      echo '
      </ul>';
      }
   }
}


Maybe it is just me, but when you suggested that you are using this code I expected you to post the actual working code you are using in a php block.

In trying to help you, I copied the exact code you provided to a php block on my test site, just to find that this code is non functional. This leads me to believe that you just copied php code from TPsubs.template.php?

I am sorry, but to help you I need you to put as much effort in the question as you expect us to put into the answer.
Please be as complete as possible in your question and do not expect us to figure it out..

Please be clear: do you have a functioning PHP block code?
If yes, please provide the functioning code, and I can check it

If no, what exactly do you have that you want to adjust?
Please describe how I can reproducte the situation you wish to improve...
Running Latest TP on SMF2.1 at: www.fjr-club.nl

[chrisB]

You're correct about where I found the code; I took it from the template.

It's also fair what you wrote; I forgot what was mentioned regarding blocks previously. In previous things I have used the code is exactly the same, so you can copy, and it works [you may have to fill in parts such as amounts etc. I need to remember that Tiny Portal is different. I apologise rjen.


@rjen

Thanks, since I figured as much I had look already. Next time please specify the block type you are using.

You are in luck that the SMF SSI_recenttopics function also delivers the board.

In TPsubs.template.php code

find

echo '<br><span class="smalltext">['.$w['time'].']</span>


and replace by

echo '<br>'. $txt['tp-fromcategory'].'<a href="'.$w['board']['href'].'" title="'.$w['board']['name'].'">'.$w['board']['name'].'</a>
<br><span class="smalltext">['.$w['time'].']</span>


It is in the code twice, make sure to fix both
Running Latest TP on SMF2.1 at: www.fjr-club.nl

[chrisB]

QuoteThanks, since I figured as much I had look already. Next time please specify the block type you are using.
Noted. 👍🏻

Thank you rjen.

[chrisB]

Block Type: Code PHP

Can a limit of articles be added to this block?

echo ' <div style="float:left;padding-right: 5px;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></div><strong>Articles</strong></br>' ;
echo ' <hr>' ;

// Configuration
// Specify your categories, comma separated if more than one category.
$categories = array(5,2);

// End Config

global $scripturl, $smcFunc;

$request = $smcFunc['db_query']('', '
     SELECT shortname, id, subject, parse
     FROM {db_prefix}tp_articles
     WHERE category IN ({array_int:cats})
          AND approved = {int:approved}
     ORDER BY parse ASC',
     array('cats' => $categories,
          'approved' => 1,
     )
);
echo '
<ul style="list-style-type:disc; margin: 0pt; padding: 0pt 15px;">
';
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (!empty($row['shortname']))
{
     echo '<li><a href="', $scripturl, '?page=', $row['shortname'], '">', $row['subject'], '</a></li>';
}
else
{
     echo '<li><a href="', $scripturl, '?page=', $row['id'], '">', $row['subject'], '</a></li>';
}
}
echo '</ul>';
$smcFunc['db_free_result']($request);


I've done basic tweaks from the source, such as removing empty space and adding the font awesome icon instead of the large article image.

What I would like to do is now limit the amount of articles the block shows to 10.