И так дамы и господа, у меня была проблема касамео кастомных ББ-кодов, а точнее в порядке их отображения в редакторе. Порыскав чуток, ничего рабочего для 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']) ? 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
");
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']) ? 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
);
$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']) ? 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
);
$this->registry->bbcodecache["$customtag[bbcodeid]"] = $customtag;
}
//}
}