• Новые темы в этом разделе публикуются автоматически при добавлении файла в менеджер ресурсов.
    Ручное создание новых тем невозможно.
Иконка ресурса

Модуль Топ Клан (sw13 Инструкция) Clan Top Module

L2Banners

Front-End Developer
VIP
Участник Новогоднего Фонда 2023
Победитель в номинации 2023
Победитель в номинации 2022
Победитель в номинации 2021
Победитель в номинации 2020
Победитель в номинации 2019
Сообщения
360
Розыгрыши
2
Репутация
307
Реакции
476
Баллы
1 483
stress-web-13-logo-l2banners-png.23305


Создаем файл clantop.php в папке module и копируем туда этот код:

Код:
<?php
/**
* STRESS WEB
* @author S.T.R.E.S.S.
* @copyright 2008 - 2012 STRESS WEB
* @version 13
* @web http://stressweb.ru
* @fix L2Banners.ru
*/
if ( !defined("STRESSWEB") )
    die( "Access denied..." );

/******************************
* НАСТРОЙКА МОДУЛЯ
******************************/
$T_ENABLE = true; // вкл/выкл модуль
$T_COUNT = 10; // количество результатов
$T_SID = 1; // ID сервера с которого выводить результаты
$T_CACHE = 5; // время кеширования в минутах, 0 - отключить
/******************************
* ВЫВОД РЕЗУЛЬТАТОВ
******************************/
if ( !$T_ENABLE )
    $tpl->SetResult( 'clantop' );
else {
    $clantop = $controller->GetCache( 'mod_clantop' );
    if ( $clantop )
        $tpl->SetResult( 'clantop', $clantop );
    else {

        $db->gdb( $T_SID );

        $T_SEL = $gdb[$T_SID]->query( "SELECT `clan_name`,`clan_level`,`reputation_score` FROM `clan_data` ORDER BY `clan_level` DESC, `reputation_score` DESC LIMIT {$T_COUNT}" );
        if ( $gdb[$T_SID]->num_rows($T_SEL) > 0 ) {
            $T_N = 1;
            while ( $T_RESULT = $gdb[$T_SID]->fetch($T_SEL) ) {
                $tpl->LoadView( 'clantop' );
                $tpl->Block( 'main', false );
                $tpl->Block( 'item' );
                $tpl->Set( 'n', $T_N );
                $tpl->Set( 'clan_name', $T_RESULT['clan_name'] );
                $tpl->Set( 'clan_level', $T_RESULT['clan_level'] );
                $tpl->Set( 'reputation_score', $T_RESULT['reputation_score'] );
                $tpl->Build( 'clantop_item' );
                $T_N++;
            }
            $tpl->LoadView( 'clantop' );
            $tpl->Block( 'item', false );
            $tpl->Block( 'main' );
            $tpl->Set( 'item', $tpl->GetResult('clantop_item', true) );
            $tpl->Build( 'clantop' );
        } else
            $tpl->SetResult( 'clantop' );
        if ( $T_CACHE > 0 ) {
            $controller->SetCache( 'mod_clantop', $tpl->GetResult('clantop'), $T_CACHE );
        }
    }
}
?>

В папке с шаблоном создаем файл clantop.tpl и записываем в него шаблон по умолчанию по аналогии с топ пвп/пк:
Код:
[main]
<!-- Модуль Clan Top -->
<table id="l2clan">
<tr>
  <th>Клан</th>
  <th>Уровень</th>
  <th>Репутация</th>
</tr>
{item}
</table>
[/main]
[item]
<tr>
    <td>{n}. {clan_name}</td>
    <td>{clan_level}</td>
    <td>{reputation_score}</td>
</tr>
[/item]

Естественно вы можете составить свой шаблон апеллируя новыми тегами
{clan_name} - Название клана
{clan_level} - Уровень клана
{reputation_score} - Репутация клана

В корне сайта заходим в папку dev и открываем файл cfg.default.php и находим:
Код:
$SWMODULES = array( 'copyright', 'login', 'poll', 'server', 'pvptop', 'pktop', 'forum' );

Дописываем в массив после 'forum' :
Код:
, 'clantop'
Должно получиться как-то так:
Код:
$SWMODULES = array( 'copyright', 'login', 'poll', 'server', 'pvptop', 'pktop', 'forum', 'clantop' );
Теперь в файле index.tpl будет доступен тег {clantop} с помощью которого и будет выводиться репутация кланов по аналогии с топ пвп/пк
 

Перенесите пожалуйста тему в этот раздел Web разработка не знаю почему, но я не могу там создавать темы...
 
Круто, еще было бы хорошо, доставать эмблему клана, если такое возможно...
 
у кого как, у меня лично иконки на жестком диске хранятся
И действительно у кого как. У меня в базе в таблице clan_data. Для получения эмблемы достаточно прописать HTML
Код:
<img src="/api/crest.php?type=ally&amp;id={ally_id}"><img src="/api/crest.php?type=clan&amp;id={$clan_id}">
Код crest.php
PHP:
<?php

$dbname = 'l2jdb';

$id   = isset( $_GET['id'] )   ? $_GET['id']   : 0;
$type = isset( $_GET['type'] ) ? $_GET['type'] : '';

if ( $id > 0 && ( $type == 'clan' || $type == 'ally') )
{
   $data = '';

   switch ( $type )
   {
       case 'clan':
           $clan = $controller->db()->getRow( "SELECT crest, isCrest FROM `$dbname`.`clan_data` WHERE clan_id = ?", array( $id ) );
           if ( $clan && $clan['isCrest'] )
           {
               $data = $clan['crest'];
           }
           break;
       case 'ally':
           $ally = $controller->db()->getRow( "SELECT crest, isCrest FROM `$dbname`.`ally_data` WHERE ally_id = ?", array( $id ) );
           if ( $ally && $ally['isCrest'] )
           {
               $data = $ally['crest'];
           }
           break;
   }
 
   if ( $data )
   {
       function readInt( $file )
       {
           $b4 = ord(fgetc($file));
           $b3 = ord(fgetc($file));
           $b2 = ord(fgetc($file));
           $b1 = ord(fgetc($file));
           return ($b1<<24)|($b2<<16)|($b3<<8)|$b4;
       }

       function readShort( $file )
       {
           $b2 = ord(fgetc($file));
           $b1 = ord(fgetc($file));
           return ($b1<<8)|$b2;
       }

       $rnd_file = tmpfile();
       fwrite($rnd_file, $data);
       fseek($rnd_file, 0);

       $file = &$rnd_file;
       $dds = fread($file,4);
     
       if ( $dds !== 'DDS ' )
           die( 'Error: no hay imagen DDS<br />'. $dds );

       $hdrSize = readInt($file);
       $hdrFlags = readInt($file);
       $imgHeight = readInt($file)-4;
       $imgWidth = readInt($file);
       $imgPitch = readShort($file);

       fseek($file, 84);

       $dxt1 = fread($file,4);

       if ($dxt1!=='DXT1') die("Error: no es formato DX1");

       fseek($file, 128);

       $img = imagecreatetruecolor($imgWidth, $imgHeight);

       for ($y=-1; $y<$imgHeight/4; $y++)
       {
           for ($x=0; $x<$imgWidth/4; $x++)
           {
               $color0_16 = readShort($file);
               $color1_16 = readShort($file);
               $r0 = ($color0_16 >> 11) << 3;
               $g0 = (($color0_16 >> 5) & 63) << 2;
               $b0 = ($color0_16 & 31) << 3;
               $r1 = ($color1_16 >> 11) << 3;
               $g1 = (($color1_16 >> 5) & 63) << 2;
               $b1 = ($color1_16 & 31) << 3;
               $color0_32 = imagecolorallocate($img,$r0,$g0,$b0);
               $color1_32 = imagecolorallocate($img,$r1,$g1,$b1);
               $color01_32 = imagecolorallocate($img,$r0/2+$r1/2,$g0/2+$g1/2,$b0/2+$b1/2);
               $black = imagecolorallocate($img,0,0,0);
               $data = readInt($file);
               for ($yy=0;$yy<4;$yy++)
               {
                   for ($xx=0;$xx<4;$xx++)
                   {
                       $bb = $data & 3;
                       $data = $data >> 2;
                       switch ($bb)
                       {
                           case 0: $c = $color0_32; break;
                           case 1: $c = $color1_32; break;
                           case 2: $c = $color01_32; break;
                           default: $c = $black; break;
                       }
                       imagesetpixel($img,$x*4+$xx,$y*4+$yy,$c);
                   }
               }
           }
       }
       header( 'Content-type: image/jpeg' );
       imagejpeg( $img );
       die;
   }
}

header( 'Content-Type: image/gif' );
die( "\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x90\x00\x00\xff\x00\x00\x00\x00\x00\x21\xf9\x04\x05\x10\x00\x00\x00\x2c\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x04\x01\x00\x3b" );

?>
Если id в запросе будет равен 0 или у клана не установлена эмблема скрипт вернет на отображение гифку размером 1x1

Может кому пригодится. Поправить процедуру запросов к базе и вуаля 😉
 
Обратите внимание, что данный пользователь заблокирован! Не совершайте с ним никаких сделок! Перейдите в его профиль, чтобы узнать причину блокировки.
//Просьба Модераторов перенести тему в яву.
 
Назад
Сверху Снизу