<?php
# Script by seg0ro http://mobilarts.ru
# Not for sale!!!

defined('_IN_JOHNCMS') or die('Error: restricted access');

$forum = isset ($_GET['forum']) ? abs(intval($_GET['forum'])) : false;
$topic = isset ($_REQUEST['topic']) ? abs(intval($_REQUEST['topic'])) : false;
$post = isset ($_REQUEST['post']) ? abs(intval($_REQUEST['post'])) : false;
$file = isset ($_REQUEST['file']) ? abs(intval($_REQUEST['file'])) : false;

$set_forum = $user_id && !empty($datauser['set_forum']) ? unserialize($datauser['set_forum']) : array('farea' => 0, 'upfp' => 0);

if ($rights || $datauser['postforum'] >= 100) $set['flsz'] = 10000;
elseif ($datauser['postforum'] >= 50) $set['flsz'] = 5000;
else $set['flsz'] = $set['flsz'];

function forum_counter($num = 0){
 
}

function quote ($text = ''){
  return preg_replace('#\[quote=(.+?)](.+?)\[/quote]#is', '<div class="quotehead">$1 писал(а)</div><div class="quotebody">$2</div>', $text);
}

function forum_log ($string = ''){
  if ($string && core::$user_data['name']){
    mysql_query("INSERT INTO `forum_logs` SET
    `time` = '".time()."',
    `user_id` = '".core::$user_id."',
    `text` = '".mysql_real_escape_string($string)."',
    `browser` = '".core::$user_agent."',
    `ip` = '".core::$ip."',
    `ip_via_proxy` = '".core::$ip_via_proxy."'
    ");
  }
}

function show_file($file = array()){
  $imgext = array('gif', 'jpg', 'jpeg', 'png');
  $ext = array_pop(explode(".", $file['filename']));
  $fls = round(filesize('../files/forum/'.$file['filename']) / 1024, 2);
  if (in_array($ext, $imgext)){
    $out = '<a href="index.php?act=download&amp;file='.$file['file'].'"><img src="image.php?image='.$file['filename'].'" alt="'.$file['filename'].'" /></a>';
  }else{
    $out = '<img src="'.core::$system_set['homeurl'].'/forum/images/attach.png" alt="+" /><a href="index.php?act=download&amp;file='.$file['file'].'">'.$file['filename'].'</a>';
    if ($ext == 'jar')
      $out .= ' | <a href="'.core::$system_set['homeurl'].'/forum/index.php?act=download&amp;file='.$file['file'].'&amp;jad">jad</a>';
  }
  return $out.' ('.$fls.' кб.) Скачали: '.$file['down'].' раз.';
}

function show_topic($res, $sub = 0, $new = 0){
  global $kmess;
  $out = '<img src="'.core::$system_set['homeurl'].'/forum/images/topic';
  
  if (core::$user_id && !$new){
    $readed = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_readed` WHERE `time` >= '".$res['time']."' AND `topic` = '".$res['topic']."' AND `user_id` = '".core::$user_id."' LIMIT 1 "), 0);
    $out .= $readed ? '' : '.new';
  }
  $out .= ($res['sticky'] ? '.sticky' : '').'.png" alt="-" /> ';
  
  if ($res['close'])
    $out .= '<img src="'.core::$system_set['homeurl'].'/forum/images/close.png" alt="#" title="Тема закрыта" /> ';
  if ($res['poll_name'])
    $out .= '<img src="'.core::$system_set['homeurl'].'/forum/images/poll.png" alt="*" title="Голосование" /> ';

  $out .= '<a href="'.core::$system_set['homeurl'].'/forum/index.php?topic='.$res['topic'].'"><strong>'.functions::checkout($res['topicname']).'</strong></a> ('.$res['count'].')';
 
  //if (core::$user_id && (!$readed || $new))
   // $out .= ' <a href="'.core::$system_set['homeurl'].'/forum/index.php?topic='.$res['topic'].'&amp;unread">Новые</a>';

  if ($res['count'] > $kmess){
    $go = ceil($res['count'] / $kmess);
    $out .= ' <a href="'.core::$system_set['homeurl'].'/forum/index.php?topic='.$res['topic'].'&amp;page='.$go.'" title="К последней странице">&gt;&gt;</a>';
  }
  if ($sub)
    $out .= '<div class="sub">'.$sub.'</div>';
  return $out;
}

function show_topic2($res, $sub = 0, $new = 0){
  global $kmess;
  $out = '<i class="fa fa-comments" aria-hidden="true"></i> ';
  

  
  
  $out .= '<a href="'.core::$system_set['homeurl'].'/forum/index.php?topic='.$res['topic'].'">'.functions::checkout($res['topicname']).'</a> <br /><i class="fa fa-comments" aria-hidden="true"></i> '.$res['count'].'';
 
  //if (core::$user_id && (!$readed || $new))
   // $out .= ' <a href="'.core::$system_set['homeurl'].'/forum/index.php?topic='.$res['topic'].'&amp;unread">Новые</a>';

  if ($res['count'] > $kmess){
    $go = ceil($res['count'] / $kmess);
    $out .= ' <a href="'.core::$system_set['homeurl'].'/forum/index.php?topic='.$res['topic'].'&amp;page='.$go.'" title="К последней странице">&gt;&gt;</a>';
  }
  if ($sub)
    $out .= ''.$sub.'';
  return $out;
}
function text($text){
  return htmlentities($text, ENT_QUOTES, 'UTF-8');
}

function title($string){
  $out = strtr($string, array('&quot;' => '', '&amp;' => '', '&lt;' => '', '&gt;' => '', '&#039;' => ''));
  $out = mb_strlen($string) > 50 ? mb_substr($out, 0, 50).'...' : $out;
  return functions::checkout($out);
}

function translit($str, $direction = 0){
  $ru = array('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ь','ы','ъ','э','ю','я','А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ь','Ы','Ъ','Э','Ю','Я',' ','ґ','ї','є','Ґ','Ї','Є');
  $en = array('a','b','v','g','d','e','yo','zh','z','i','y','k','l','m','n','o','p','r','s','t','u','f','h','c','ch','sh','sh','','y','','e','u','ya','A','B','V','G','D','E','YO','ZH','Z','I','Y','K','L','M','N','O','P','R','S','T','U','F','H','C','CH','SH','SH','','Y','','E','U','YA','_','gg','ji','ye','GG','JI','YE');
  if ($direction == 0)
	  return str_replace($ru, $en, $str);
	else
	  return str_replace($en, $ru, $str);
}