форум vBSupport.ru > vBulletin > vBulletin 4.2.x > Made in vBSupport.org 4.2.x
  • »
VBsupport перешел с домена .ORG на родной .RU Ура! Пожалуйста, обновите свои закладки - VBsupport.ru
 
 
 
 
DJ Kukstyler
Знаток
 
DJ Kukstyler's Avatar
Default Изменение порядка кастомных ББ-кодов в тулбаре редактора сообщений
1

И так дамы и господа, у меня была проблема касамео кастомных ББ-кодов, а точнее в порядке их отображения в редакторе. Порыскав чуток, ничего рабочего для 4-ки я не нашёл. За сим, подумал поюзать код и в итоге нашёл, может и не очень хорошее/элегантное решение, но рабочее, и как я понял не затратное. Может кому и пригодится.

В 2 файлах есть SQL запросы:

1. class_bbcode_alt.php
PHP Code:
function append_custom_tags()
    {
        if (
$this->custom_fetched == true)
        {
            return;
        }

        
$this->custom_fetched true;
        
// this code would make nice use of an interator
        
if ($this->registry->bbcodecache !== null// get bbcodes from the datastore
        
{
            foreach(
$this->registry->bbcodecache AS $customtag)
            {
                
$has_option $customtag['twoparams'] ? 'option' 'no_option';
                
$customtag['bbcodetag'] = strtolower($customtag['bbcodetag']);
        
                
//str_replace is stop gap until custom tags are updated to the new format
                
$this->tag_list["$has_option"]["$customtag[bbcodetag]"] = array(
                    
'callback' => 'handle_wysiwyg_unparsable',
                    
'strip_empty'         => $customtag['strip_empty'],
                    
'stop_parse'        => $customtag['stop_parse'],
                    
'disable_smilies'    => $customtag['disable_smilies'],
                    
'disable_wordwrap'    => $customtag['disable_wordwrap'],
                );
            }
        }
        else 
// query bbcodes out of the database
        
{
            
$bbcodes $this->registry->db->query_read_slave("
                SELECT bbcodetag, bbcodereplacement, twoparams
                FROM " 
TABLE_PREFIX "bbcode
            "
);
            while (
$customtag $this->registry->db->fetch_array($bbcodes))
            {
                
$has_option $customtag['twoparams'] ? 'option' 'no_option';

                
// str_replace is stop gap until custom tags are updated to the new format
                
$this->tag_list["$has_option"]["$customtag[bbcodetag]"] = array(
                    
'callback' => 'handle_wysiwyg_unparsable',
                    
'strip_empty'        => intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['strip_empty'],
                    
'stop_parse'         => intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['stop_parse'],
                    
'disable_smilies'    => intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['disable_smilies'],
                    
'disable_wordwrap'    => intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['disable_wordwrap']
                );
            }
        }
    } 
2. class_bbcode.php

PHP Code:
    function append_custom_tags()
    {
        if (
$this->custom_fetched == true)
        {
            return;
        }

        
$this->custom_fetched true;
         
this code would make nice use of an interator
        
if ($this->registry->bbcodecache !== null// get bbcodes from the datastore
        
{
            foreach(
$this->registry->bbcodecache AS $customtag)
            {
                
$has_option $customtag['twoparams'] ? 'option' 'no_option';
                
$customtag['bbcodetag'] = strtolower($customtag['bbcodetag']);
        
                
$this->tag_list["$has_option"]["$customtag[bbcodetag]"] = array(
                    
'html'             => $customtag['bbcodereplacement'],
                    
'strip_empty'      => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['strip_empty']) ? ,
                    
'stop_parse'       => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['stop_parse']) ? 0,
                    
'disable_smilies'  => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['disable_smilies']) ? 0,
                    
'disable_wordwrap' => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['disable_wordwrap']) ? 0,
                );
            }
        }
        else 
// query bbcodes out of the database
        
{
            
$this->registry->bbcodecache = array();

            
$bbcodes $this->registry->db->query_read_slave("
                SELECT *
                FROM " 
TABLE_PREFIX "bbcode
            "
);
            while (
$customtag $this->registry->db->fetch_array($bbcodes))
            {
                
$has_option $customtag['twoparams'] ? 'option' 'no_option';
                
$customtag['bbcodetag'] = strtolower($customtag['bbcodetag']);
                
$this->tag_list["$has_option"]["$customtag[bbcodetag]"] = array(
                    
'html'             => $customtag['bbcodereplacement'],
                    
'strip_empty'      => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['strip_empty']) ? ,
                    
'stop_parse'       => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['stop_parse']) ? ,
                    
'disable_smilies'  => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['disable_smilies']) ? ,
                    
'disable_wordwrap' => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['disable_wordwrap']) ? 0
                
);

                
$this->registry->bbcodecache["$customtag[bbcodeid]"] = $customtag;
            }
        }
    } 
Первое что я сделал это добавил order by bbcodeid в оба запроса. Но оно, естественно, не сработало.
Затем я обратил внимание на код в IF-е, что там есть некий хэш, и просто закомментил эту часть кода. Сработало.
Затем просто выставил в bbcodeid ту очерёдность которую хотел. Теперь всё так, как я хотел.

ЗЫ: я не знаком с веб языками/технологиями и тем более фактически ничего не знаю о недрах движка. Поэтому возможно я что-то упустил, возможно даже важное. По-этому здоровая критика приветствуется.
Однако насколько я понял, неиспользование cache добавляет 1 лишний запрос в базу при загрузке редактора сообщений, что на мой взгляд не является критичным.

В общем, всё. Просто хотел поделиться. Возможно, узнать, что почесал левое ухо правой ногой, и всё это делается намного проще.

DJ Kukstyler добавил 07-23-2022 в 08:16 PM
Ну и да, сейчас функции выглядят следующим образом:

1. class_bbcode_alt.php
PHP Code:
    /**
    * Loads any user specified custom BB code tags into the $tag_list. These tags
    * will not be parsed. They are loaded simply for directive parsing.
    */
    
function append_custom_tags()
    {
        if (
$this->custom_fetched == true)
        {
            return;
        }

        
$this->custom_fetched true;
        
//// this code would make nice use of an interator
        //if ($this->registry->bbcodecache !== null) // get bbcodes from the datastore
        //{
        //    foreach($this->registry->bbcodecache AS $customtag)
        //    {
        //        $has_option = $customtag['twoparams'] ? 'option' : 'no_option';
        //        $customtag['bbcodetag'] = strtolower($customtag['bbcodetag']);
        //
        //        // str_replace is stop gap until custom tags are updated to the new format
        //        $this->tag_list["$has_option"]["$customtag[bbcodetag]"] = array(
        //            'callback' => 'handle_wysiwyg_unparsable',
        //            'strip_empty'         => $customtag['strip_empty'],
        //            'stop_parse'        => $customtag['stop_parse'],
        //            'disable_smilies'    => $customtag['disable_smilies'],
        //            'disable_wordwrap'    => $customtag['disable_wordwrap'],
        //        );
        //    }
        //}
        //else // query bbcodes out of the database
        //{
            
$bbcodes $this->registry->db->query_read_slave("
                SELECT bbcodetag, bbcodereplacement, twoparams
                FROM " 
TABLE_PREFIX "bbcode order by bbcodeid
            "
);
            while (
$customtag $this->registry->db->fetch_array($bbcodes))
            {
                
$has_option $customtag['twoparams'] ? 'option' 'no_option';

                
// str_replace is stop gap until custom tags are updated to the new format
                
$this->tag_list["$has_option"]["$customtag[bbcodetag]"] = array(
                    
'callback' => 'handle_wysiwyg_unparsable',
                    
'strip_empty'        => intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['strip_empty'],
                    
'stop_parse'         => intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['stop_parse'],
                    
'disable_smilies'    => intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['disable_smilies'],
                    
'disable_wordwrap'    => intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['disable_wordwrap']
                );
            }
        
//}
    

2. class_bbcode.php
PHP Code:
    /**
    * Loads any user specified custom BB code tags into the $tag_list
    */
    
function append_custom_tags()
    {
        if (
$this->custom_fetched == true)
        {
            return;
        }

        
$this->custom_fetched true;
        
// this code would make nice use of an interator
        //if ($this->registry->bbcodecache !== null) // get bbcodes from the datastore
        //{
        //    foreach($this->registry->bbcodecache AS $customtag)
        //    {
        //        $has_option = $customtag['twoparams'] ? 'option' : 'no_option';
        //        $customtag['bbcodetag'] = strtolower($customtag['bbcodetag']);
        //
        //        $this->tag_list["$has_option"]["$customtag[bbcodetag]"] = array(
        //            'html'             => $customtag['bbcodereplacement'],
        //            'strip_empty'      => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['strip_empty']) ? 1 : 0 ,
        //            'stop_parse'       => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['stop_parse']) ? 1 : 0,
        //            'disable_smilies'  => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['disable_smilies']) ? 1 : 0,
        //            'disable_wordwrap' => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['disable_wordwrap']) ? 1 : 0,
        //        );
        //    }
        //}
        //else // query bbcodes out of the database
        //{
            
$this->registry->bbcodecache = array();

            
$bbcodes $this->registry->db->query_read_slave("
                SELECT *
                FROM " 
TABLE_PREFIX "bbcode order by bbcodeid
            "
);
            while (
$customtag $this->registry->db->fetch_array($bbcodes))
            {
                
$has_option $customtag['twoparams'] ? 'option' 'no_option';
                
$customtag['bbcodetag'] = strtolower($customtag['bbcodetag']);
                
$this->tag_list["$has_option"]["$customtag[bbcodetag]"] = array(
                    
'html'             => $customtag['bbcodereplacement'],
                    
'strip_empty'      => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['strip_empty']) ? ,
                    
'stop_parse'       => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['stop_parse']) ? ,
                    
'disable_smilies'  => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['disable_smilies']) ? ,
                    
'disable_wordwrap' => (intval($customtag['options']) & $this->registry->bf_misc['bbcodeoptions']['disable_wordwrap']) ? 0
                
);

                
$this->registry->bbcodecache["$customtag[bbcodeid]"] = $customtag;
            }
        
//}
    


Last edited by DJ Kukstyler : 07-24-2022 at 12:17 AM. Reason: Добавлено сообщение
Bot
Yandex Bot Yandex Bot is online now
 
Join Date: 05.05.2005
Реклама на форуме А что у нас тут интересного? =)
 
 
DJ Kukstyler
Знаток
 
DJ Kukstyler's Avatar
Default
0

Единственное где не работает (только заметил), это при создании новой темы...

Вроде везде проставил ORDER BY

Bезде кэш закомментил...

Last edited by DJ Kukstyler : 08-09-2022 at 07:16 PM. Reason: Добавлено сообщение
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT +4. The time now is 12:34 AM.


Powered by vBulletin® Version 3.7.6
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Loading...