T
T
timers2019-01-30 12:54:32
DLE
timers, 2019-01-30 12:54:32

How to display latest comments in DLE module?

There is a DLE Board module
I want to display the latest comments on the main page (Not the main page of the module).
All functions are actually there, but this function displays comments on the main page of the module, and I need it in the main.tpl of the main template.

And so, the function itself: inc/board/board.class.php
function LastCommentsBlock(){
    global $db, $config, $lang, $tpl, $_TIME;
    
    $return = $this->OpenCache( "", "block.last_comm.tmp" );
    if( !$return )
      {
        $template = file_get_contents( $tpl->dir."/board/main/last.comments.tpl" );
        $result = $db->query( "SELECT ".PREFIX."_board_comments.id as com_id, ".PREFIX."_board_comments.board_id, ".PREFIX."_board_comments.author_id, ".PREFIX."_board_comments.author, ".PREFIX."_board_comments.text, ".PREFIX."_board_comments.ip, ".PREFIX."_board_comments.date, ".PREFIX."_board_post.id, ".PREFIX."_board_post.title, ".PREFIX."_board_post.alt_name, ".PREFIX."_board_post.category FROM ".PREFIX."_board_comments LEFT JOIN ".PREFIX."_board_post ON ".PREFIX."_board_comments.board_id=".PREFIX."_board_post.id WHERE ".PREFIX."_board_comments.del!='1' ORDER BY `date` DESC LIMIT 0,15" );
        if( $db->num_rows( $result ) > 0 )
          {
            while( $row = $db->get_row( $result ) )
              {
                $id = $row['id'];
                $title = stripslashes( $row['title'] );
                $alt_name = $row['alt_name'];
                $category = $row['category'];
                $author = stripslashes( $row['author'] );
                $author_id = intval( $row['author_id'] );
                $text = stripslashes( $row['text'] );
                $date = strtotime( $row['date'] );
                $full_link = $this->ReturnLinkPost( $id, $alt_name, $category );
                $authorLink = $config['allow_alt_url'] ? "/user/".urldecode( $author )."/" : "/index.php?subaction=userinfo&user={$author}";
                
                // Работаем с датой
                if( date( "Ymd", $date ) == date( "Ymd", $_TIME ) )
                  $date = $lang['time_heute'].langdate( ", H:i", $date );
                elseif( date( "Ymd", $date ) == date( "Ymd", ( $_TIME - 86400 ) ) )
                  $date = $lang['time_gestern'].langdate( ", H:i", $date );
                else
                  $date = langdate( $config['timestamp_comment'], $date );
                
                $forReturn = $template;
                $forReturn = str_replace( "{title}", $title, $forReturn );
                $forReturn = str_replace( "{author}", $author, $forReturn );
                $forReturn = str_replace( "{authorLink}", $authorLink, $forReturn );
                $forReturn = str_replace( "{text}", $text, $forReturn );
                $forReturn = str_replace( "{date}", $date, $forReturn );
                $forReturn = str_replace( "{full_link}", $full_link, $forReturn );
                
                $return .= $forReturn;
              }
          }
            else
          {
            $return = "Нет комментариев";	
          }
        
        $this->CreateCache( "", "block.last_comm.tmp", $return );
      }
    
    return $return;
  }

Это код главного файла в modules/board.php
if( !defined( "DATALIFEENGINE" ) ) die( "Hacking attempt!" );

//--------------------------------------------------=-=-=-=-=
//	Запускаем класс
//--------------------------------------------------=-=-=-=-=

if( !class_exists( "Board" ) ) require_once( DLEPlugins::Check(ENGINE_DIR."/inc/board/board.class.php") );

//--------------------------------------------------=-=-=-=-=
//	Настройки модуля
//--------------------------------------------------=-=-=-=-=

$MainLink = $Board->AltUrl ? "/board/" : "/index.php?do=board";
$module['title'] = array( $Board->Config['main_title'] );
$module['speedbar'] = array( "<a href=\"{$MainLink}\">{$Board->Config['main_title']}</a>" );

if( $Board->Config['on'] == "yes" )
  {
    $action = totranslit( $_REQUEST['action'] );
    

    //--------------------------------------------------=-=-=-=-=
    //	Грузим файлы
    //--------------------------------------------------=-=-=-=-=
    
    $BoardLoadMainTpl = false;
    $BoardAllowSearch = true;
    switch( $action ){
      
      case "post":
        include( DLEPlugins::Check(ENGINE_DIR."/modules/board/full.post.php") );
        break;
        
      case "add":
        include( DLEPlugins::Check(ENGINE_DIR."/modules/board/add.post.php") );
        break;
        
      case "edit":
        include( DLEPlugins::Check(ENGINE_DIR."/modules/board/edit.post.php") );
        break;
        
      case "del":
        include( DLEPlugins::Check(ENGINE_DIR."/modules/board/del.post.php") );
        break;
        
      case "my":
        include( DLEPlugins::Check(ENGINE_DIR."/modules/board/my.post.php") );
        break;
        
      case "userpost":
        include( DLEPlugins::Check(ENGINE_DIR."/modules/board/user.post.php") );
        break;
        
      case "notepad":
        include( DLEPlugins::Check(ENGINE_DIR."/modules/board/notepad.post.php") );
        break;
        
      case "boardcat":
        include( DLEPlugins::Check(ENGINE_DIR."/modules/board/category.php") );
        break;
        
      case "fullsearch":
        include( DLEPlugins::Check(ENGINE_DIR."/modules/board/fullsearch.php") );
        break;
        
      case "rss":
        include( DLEPlugins::Check(ENGINE_DIR."/modules/board/rss.php") );
        break;
        
      default:
        $action = "main";
        include( DLEPlugins::Check(ENGINE_DIR."/modules/board/main.php") );
        break;
    }
    
    //--------------------------------------------------=-=-=-=-=
    //	Обработка сгенерированного
    //--------------------------------------------------=-=-=-=-=
    
    if( $BoardLoadMainTpl === true )
      {
        $SelectBoardType = $Board->ReturnSelectBoardType( $BoardType, $BoardCategory );
        $MyBoardPost = $Board->AltUrl ? "/board/my" : "/index.php?do=board&action=my";
        $MyBoardNotepad = $Board->AltUrl ? "/board/notepad" : "/index.php?do=board&action=notepad";
        $AddBoardPost = $Board->ReturnLinkAddPost();
        $FullBoardSearch = "/index.php?do=board&action=fullsearch";
        $SelectCountry = $Board->ReturnSelectCountry( $_SESSION['BoardCountry'] );
        $SelectCity = $Board->ReturnSelectCity( $_SESSION['BoardCountry'], $_SESSION['BoardCity'] );
        
        $LastComm = $Board->LastCommentsBlock();
        
        $Folder = $Folder != "" ? $Folder : "default";
        $tpl->Load_Template( "board/{$Folder}/main.tpl" );
        $tpl->set( "{cats}", $cats );
        $tpl->set( "{my_board}", $MyBoardPost );
        $tpl->set( "{my_notepad}", $MyBoardNotepad );
        $tpl->set( "{add_post}", $AddBoardPost );
        $tpl->set( "{full_search_link}", $FullBoardSearch );
        $tpl->set( "{content}", $tpl->result['board_content'] );
        $tpl->set( "{Search:boardtype}", "<select name=\"board_type\">{$SelectBoardType}</select>" );
        $tpl->set( "{MainLink}", $MainLink );
        $tpl->set( "{rssLink}", $rssLink );
        $tpl->set( "{UserCountry}", $UserCountry );
        $tpl->set( "{UserCity}", $UserCity );
        $tpl->set( "{UserCityID}", intval( $_SESSION['BoardCity'] ) );
        
        $tpl->set( "{LastComm}", $LastComm );
        
        $tpl->set( "{SelectCountry}", "<select name=\"country\" id=\"SelectListCountry\" onkeyup=\"SelectCountry( '', 'Выберите' );\" onkeydown=\"SelectCountry( '', 'Выберите' );\" onchange=\"SelectCountry( '', 'Выберите' );\"><option value=\"\">- Без разницы -</option>{$SelectCountry}</select>" );
        $tpl->set( "{SelectCity}", "<span id=\"FormSelectCity\"><select name=\"city\" id=\"SelectCity\"><option value=\"\">- Без разницы -</option>{$SelectCity}</select> <span id=\"FormSelectCityStatus\"></span></span>" );
        $tpl->set_block( "'\\[SelectRegion\\](.*?)\\[/SelectRegion\\]'si", "<form method=\"post\" action=\"\">\\1</form>" );
        
        $tpl->set_block( "'\\[cats\\](.*?)\\[/cats\\]'si", ( $cats ? "\\1" : "" ) );
        $tpl->set_block( "'\\[rss\\](.*?)\\[/rss\\]'si", ( $rssLink ? "\\1" : "" ) );
        $tpl->set_block( "'\\[allow_search\\](.*?)\\[/allow_search\\]'si", ( $BoardAllowSearch === true ? "\\1" : "" ) );
        
        $SearchTextForm = htmlspecialchars( $SearchTextForm, ENT_QUOTES, $config['charset'] );
        $tpl->set_block( "#{search:text->(.+?)}#is", ( ( $SearchTextForm != "" ) ? $SearchTextForm : "\\1" ) );
        
        $tpl->compile( "board" );
        $tpl->clear();
      }
    
    $tpl->result['content'] = $tpl->result['content'].$tpl->result['board'];
    $tpl->result['content'] = preg_replace_callback( "#\\[(Not|Yes)BoardAllow:(.+?)\\](.+?)\\[/(Not|Yes)BoardAllow\\]#is", function( $matches ) use ( $Board ){
      return $Board->ReplaceTagBlock( $matches[2], $matches[3], $matches[1] );
    }, $tpl->result['content'] );
    $tpl->result['content'] = preg_replace_callback( "#\\[(Not|Yes)BoardAllowCat:(.+?)\\](.+?)\\[/(Not|Yes)BoardAllowCat\\]#is", function( $matches ) use ( $Board ){
      return $Board->ReplaceTagBlockCat( $matches[2], $matches[3], $matches[1] );
    }, $tpl->result['content'] );
    
    if( $Board->Config['region_on'] == "on" )
      {
        $tpl->result['content'] = preg_replace( "#\\[allow_region\\]([^\\[]*)\\[/allow_region\\]#is", "\\1", $tpl->result['content'] );
        $tpl->result['content'] = preg_replace( "#\\[not-allow_region\\]([^\\[]*)\\[/not-allow_region\\]#is", "", $tpl->result['content'] );
      }
        else
      {
        $tpl->result['content'] = preg_replace( "#\\[allow_region\\]([^\\[]*)\\[/allow_region\\]#is", "", $tpl->result['content'] );
        $tpl->result['content'] = preg_replace( "#\\[not-allow_region\\]([^\\[]*)\\[/not-allow_region\\]#is", "\\1", $tpl->result['content'] );
      }
    
    unset( $tpl->result['board'] );
  }
    else
  {
    msgbox( "Информация", "Объявления в данный момент отключены администрацией сайта." );	
  }

//--------------------------------------------------=-=-=-=-=
//	Метатег <title> и модуль SpeedBar
//--------------------------------------------------=-=-=-=-=

$NewTitle = array();
for( $i = count( $module['title'] ); $i > 0; $i-- ) $NewTitle[] = $module['title'][ $i - 1 ];
$metatags['header_title'] = implode( " &raquo; ", $NewTitle )." &raquo; ".$config['home_title'];
$module['speedbar'] = implode( " &raquo; ", $module['speedbar'] );
$module['title'] = "";

?>

Actually - {LastComm} displays comments on the main module, how to make it work on the main engine itself?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question