Recent Posts?

Started by Zozma at Mar 17, 2021 at 8:47 pm
476 Views
9 Posts


Zozma

Trash Mammal

Client

36Years Young
37 Posts

Hey, it's me again! I know there is a block for recent topics, but is there one for recent posts? If not, how would I go about getting a recent post listing going? Recent posts are the only thing I'm missing from this software, everything else has been lovely to work with. <3


user posted image



Arceus

codemancer

Admin

31Years Young
133 Posts

Just because you lost me as a friend, doesn't mean you gained me as an enemy. I'm bigger than that. I still want to see you eat, just not at my table.


I have to mod it in as a page, which means you'll probably have to edit one of the core files and upload another one, so... idk how realistic it'd be to get that done judging by how hard it was to get it done before. Unfortunately because of how Vesta works I can't give you a way to do it in the templates or anything you can edit through the admin panel.

It'll be a default feature in Salerno at least.


Watching you bloom in the light of the moon;

Check out my writing blog! All of my fanfiction and eventually my original stories are published here.



Zozma

Trash Mammal

Client

36Years Young
37 Posts

Well that's cool that it's going to be default!

One of the reasons I dislike Jcink is having to thread hop to read all the new stuff. Whyyyy!

But until then, thread hop I shall do. I've already put too much time into this site to put is aside now.


user posted image



Zozma

Trash Mammal

Client

36Years Young
37 Posts

Oh I kept meaning to ask, since you said it wasn’t something to

do from

admin panel but it would be doable elsewhere, yes? Could

you help us or point us in the right direction to make this happen? It’s honestly the one thing I am really missing. Recent posts or die! Haha. 

edit: sorry for formatting errors. On phone real quick and getting ready for a doc appointment so I’m scattered 


user posted image



Arceus

codemancer

Admin

31Years Young
133 Posts

Just because you lost me as a friend, doesn't mean you gained me as an enemy. I'm bigger than that. I still want to see you eat, just not at my table.


Yeah, like I said you'll have to upload a new file to sources, add a new function to one of the core files, and a new template in. I can send you the stuff to do it with, it's actually pretty simple, if you think you can get it done.


Watching you bloom in the light of the moon;

Check out my writing blog! All of my fanfiction and eventually my original stories are published here.



Zozma

Trash Mammal

Client

36Years Young
37 Posts

Sure! I'll give it a go. :D


user posted image



Arceus

codemancer

Admin

31Years Young
133 Posts

Just because you lost me as a friend, doesn't mean you gained me as an enemy. I'm bigger than that. I still want to see you eat, just not at my table.


Alright, so first we'll make recent.php in application/sources:

<?php
/*
	Vesta by Kendra Alvares (Arceus).
*/

if(!defined('Vesta'))
	die('Hekkkk what u doin heer?');

class recent
{
	public function index($data = [])
	{
		global $settings, $page, $text;
		$chronos = new chronos;
		$ananke = new ananke;
		
		$ananke->load_language( (!empty($user->language) ? $user->language : $settings->language), 'forums');
		$page->recent = $chronos->recent_posts( (!empty($data['extra'][0]) ? $data['extra'][0] : 1) );
		
		$page->tree[] = [
                  'label' => $text->forums->recent,
                  'href' => $settings->url.'/recent'
            ];
		
		$page->title = $text->forums->recent;
		$ananke->view('forum', 'recent', array('page' => 'recent'));
	}
}

?>

Real simple, just makes the page work right and trigger the things to make it load it.

Add this before the ending ?> in application/languages/en/forums.php:

$text->forums->recent = 'Recent Posts';

And before the last
}
?>
in application/core/chronos.php add this function:

      public function recent_posts($cpage = 1)
      {
            global $metis, $settings, $user, $page;
            $erebos = new erebos;
            $ananke = new ananke;
            
            $page->pages = new stdclass;
            $current_page = !empty($cpage) ? ($cpage > 10 ? 10 : $cpage) : 1;
            $page->pages = $ananke->generate_pages($current_page, '{db_prefix}messages', 'recent');
            $page->pages->total = $page->pages->total > 10 ? 10 : $page->pages->total;
            $page->pages->next = ($page->pages->current != $page->pages->total && $page->pages->next <= $page->pages->total) ? $page->pages->next : false;
            
            $start = $page->pages->start;
            $limit = $page->pages->limit;
            
            $return = [];
            $posts = $metis->db_query(
                  "SELECT
                        ms.id_message, ms.id_registered, ms.id_character, ms.mes_content,
                        ms.mes_posip, ms.mes_posname, ms.mes_time, ms.id_thread, th.thr_name, fo.for_groups,
                        rg.reg_displayname, rg.reg_avatar, rg.reg_content, rg.reg_reputation, rg.reg_title, rg.id_group,
                        mg.gro_name, mg.gro_color,
                        ch.id_alliance, ch.id_department, ch.id_rank,
                        ch.cha_name_fi, ch.cha_name_la, ch.cha_content, ch.cha_title, al.all_name,
                        al.all_color, dp.dep_name, dp.dep_color, rn.ran_name
                  FROM {db_prefix}messages AS ms
                        LEFT JOIN {db_prefix}threads AS th ON (ms.id_thread = th.id_thread)
                        LEFT JOIN {db_prefix}forums AS fo ON (th.id_forum = fo.id_forum)
                        LEFT JOIN {db_prefix}registered AS rg ON (ms.id_registered = rg.id_registered)
                        LEFT JOIN {db_prefix}membergroups AS mg ON (rg.id_group = mg.id_group)
                        LEFT JOIN {db_prefix}characters AS ch ON (ms.id_character = ch.id_character)
                        LEFT JOIN {db_prefix}ch_alliances AS al ON (ch.id_alliance = al.id_alliance)
                        LEFT JOIN {db_prefix}ch_departments AS dp ON (ch.id_department = dp.id_department)
                        LEFT JOIN {db_prefix}ch_ranks AS rn ON (ch.id_rank = rn.id_rank)
                  ".(!$user->mature ? " WHERE th.thr_mature = 0" : "")."
                  ORDER BY ms.id_message DESC
                  LIMIT {$start}, {$limit}",
                  array()
            );
            if($posts)
            {
                  foreach($posts as $msg)
                  {
                        $access = explode(',', $msg->for_groups);
                        if(!in_array($user->group, $access))
                              continue;
                              
                        if(!empty($msg->id_character))
                        {
                              $name = false;
                              $seoname = false;
                              $color = false;
                              $avatar = false;
                              $avatar_tiny = false;
                              $link = false;
                              
                              $name = $msg->cha_name_fi.(!empty($msg->cha_name_la) ? ' '.$msg->cha_name_la : '');
                              $seoname = $erebos->seo_string($name);
                              $color = !empty($msg->dep_color) ? $msg->dep_color : (!empty($msg->all_color) ? $msg->all_color : false);
                              $avatars = $metis->db_query("SELECT ima_filename FROM {db_prefix}ch_images WHERE id_character = {id} AND ima_type = 0", array('id' => $msg->id_character));
                              if($avatars)
                              {
                                    if($settings->allow_avatars && $settings->allow_multipleav && isset($avatars[1]))
                                    {
                                          $avatar = '<img src="'.$settings->images.'/avatar/'.$avatars[array_rand($avatars, 1)]->ima_filename.'" alt="">';
                                          $avatar_tiny = '<img src="'.$settings->images.'/avatar/'.$avatars[array_rand($avatars, 1)]->ima_filename.'" alt="" width="40px" height="auto">';
                                    }
                                    elseif($settings->allow_avatars)
                                    {
                                          $avatar = '<img src="'.$settings->images.'/avatar/'.$avatars[0]->ima_filename.'" alt="">';
                                          $avatar_tiny = '<img src="'.$settings->images.'/avatar/'.$avatars[0]->ima_filename.'" alt="" width="40px" height="auto">';
                                    }
                              }
                              else
                              {
                                    $avatar = '<img src="https://placehold.it/'.$settings->avatar_size.'" alt="">';
                                    $avatar_tiny = '<img src="https://placehold.it/'.$settings->avatar_size.'" alt="" width="40px" height="auto">';
                              }
                              $link = '<a href="'.$settings->url.'/character/'.$msg->id_character.'-'.$seoname.'"'.(!empty($color) ? ' style="color: '.$color.'"' : '').'>'.$name.'</a>';
                        }
                        else
                        {
                              $name = false;
                              $seoname = false;
                              $color = false;
                              $avatar = false;
                              $avatar_tiny = false;
                              $link = false;
                              
                              $name = !empty($msg->reg_displayname) ? $msg->reg_displayname : $msg->mes_posname;
                              $seoname = $erebos->seo_string($msg->reg_displayname);
                              $color = !empty($msg->gro_color) ? $msg->gro_color : false;
                              if($settings->allow_avatars && !empty($msg->reg_avatar))
                              {
                                    $avatar = '<img src="'.$settings->images.'/avatar/'.$msg->reg_avatar.'" alt="">';
                                    $avatar_tiny = '<img src="'.$settings->images.'/avatar/'.$msg->reg_avatar.'" alt="" width="40px" height="auto">';
                              }
                              $link = '<a href="'.$settings->url.'/profile/'.$msg->id_registered.'-'.$seoname.'"'.(!empty($color) ? ' style="color: '.$color.'"' : '').'>'.$name.'</a>';
                        }
                        
                        $return[$msg->id_message] = new stdclass;
                        $return[$msg->id_message]->id = $msg->id_message;
                        $return[$msg->id_message]->content = $msg->mes_content;
                        $return[$msg->id_message]->time = $erebos->formattime($msg->mes_time);
                        $return[$msg->id_message]->ip = $msg->mes_posip;
                        
                        $linkseo = $erebos->seo_string($msg->thr_name);
                        $postcount = $metis->db_query("SELECT count(id_message) AS total FROM {db_prefix}messages WHERE id_thread = {thr}", array('thr' => $msg->id_thread));
                        $postcount = $postcount[0]->total;
                        $pages = floor($postcount/10);
                        if($pages == 0) $pages = 1;
                        
                        $return[$msg->id_message]->link = '<a href="'.$settings->url.'/topic/'.$msg->id_thread.'-'.$linkseo.($pages > 1 ? '/'.$pages : '').'/#msg'.$msg->id_message.'">'.$msg->thr_name.'</a>';
                        $return[$msg->id_message]->poster = new stdclass;
                        $return[$msg->id_message]->poster->name = $name;
                        $return[$msg->id_message]->poster->color = $color;
                        $return[$msg->id_message]->poster->avatar = $avatar;
                        $return[$msg->id_message]->poster->avatar_tiny = $avatar_tiny;
                        $return[$msg->id_message]->poster->link = $link;
                        $return[$msg->id_message]->poster->content = !empty($msg->id_character) ? $msg->cha_content : $msg->reg_content;
                        $return[$msg->id_message]->poster->reputation = $msg->reg_reputation;
                  }
            }
            return $return;
      }

And finally, we'll add this template before the last ?> in application/themes/yourtheme/forum.template.php:

function template_recent()
{
      global $page, $user;
      
      echo '
      ',template_pages(),'
      <div class="category_block">';
      
      if(!empty($page->recent))
      {
            foreach($page->recent as $recent)
            {
                  echo '
                  <div class="forum_box">
                        <div class="postheader mobileflex flexcenter">
                              <div class="flex01">
                                    ',$recent->poster->avatar_tiny,'
                              </div>
                              
                              <div class="flex1">
                                    <h2 class="margin0">',$recent->link,'</h2>
                                    <h5 class="margin0">',$recent->poster->link,'</h5>
                              </div>
                              
                              <div class="flex1 righttext">
                                    ',$recent->time,'
                              </div>
                        </div>
                        
                        <hr>
                        
                        <div class="postbody">
                              ',$recent->content,'
                        </div>
                  </div>';
            }
      }
      
      echo '
      </div>
      ',template_pages();
}

If you get errors, lemme know, I might've forgotten a file, but I don't think I did. xD And that'll give you a recent posts list at /recent. c:


Watching you bloom in the light of the moon;

Check out my writing blog! All of my fanfiction and eventually my original stories are published here.



Arceus

codemancer

Admin

31Years Young
133 Posts

Just because you lost me as a friend, doesn't mean you gained me as an enemy. I'm bigger than that. I still want to see you eat, just not at my table.


You'll probably have to change some HTML classes in that last one because it's using the ones from Messiah's Remember, not Eros lol


Watching you bloom in the light of the moon;

Check out my writing blog! All of my fanfiction and eventually my original stories are published here.



Zozma

Trash Mammal

Client

36Years Young
37 Posts

It works! I love it! Thank youuuu~! <3


user posted image