$Date: 2005-10-10 14:08:54 +0100 (Mon, 10 Oct 2005) $
| > $Revision: 23 $
| > $Author: matt $
+---------------------------------------------------------------------------
|
| > Administration Module
| > Module written by Matt Mecham
| > Date started: 27th January 2004
|
| > Module Version Number: 1.0.0
| > DBA Checked: Mon 24th May 2004
+--------------------------------------------------------------------------
*/
if ( ! defined( 'IN_ACP' ) )
{
print "
Неверный вход
У Вас нет доступа к директиве этого файла. Если Вы проводили обновления, убедитесь, что не забыли обновить 'admin.php'.";
exit();
}
class ad_bbcode {
var $functions = "";
/**
* Section title name
*
* @var string
*/
var $perm_main = "content";
/**
* Section title name
*
* @var string
*/
var $perm_child = "bbcode";
function auto_run()
{
//-----------------------------------------
// Require and RUN !! THERES A BOMB
//-----------------------------------------
$this->ipsclass->admin->page_detail = "Эта секция позволяет вам добавлять новые BB-тэги.";
$this->ipsclass->admin->page_title = "Менеджер настройки BB-кодов";
//-----------------------------------------
// Kill globals - globals bad, Homer good.
//-----------------------------------------
$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
foreach ( $tmp_in as $k => $v )
{
unset($$k);
}
//-----------------------------------------
// What to do...
//-----------------------------------------
switch($this->ipsclass->input['code'])
{
case 'bbcode':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
$this->bbcode_start();
break;
case 'bbcode_add':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
$this->bbcode_form('add');
break;
case 'bbcode_doadd':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
$this->bbcode_save('add');
break;
case 'bbcode_edit':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->bbcode_form('edit');
break;
case 'bbcode_doedit':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->bbcode_save('edit');
break;
case 'bbcode_test':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
$this->bbcode_test();
break;
case 'bbcode_delete':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );
$this->bbcode_delete();
break;
case 'bbcode_export':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':export' );
$this->bbcode_export();
break;
case 'bbcode_import':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':import' );
$this->bbcode_import();
break;
default:
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
$this->bbcode_start();
break;
}
}
//-----------------------------------------
// BBCODE: Import
//-----------------------------------------
function bbcode_import()
{
$content = $this->ipsclass->admin->import_xml( 'ipb_bbcode.xml' );
//-----------------------------------------
// Got anything?
//-----------------------------------------
if ( ! $content )
{
$this->ipsclass->main_msg = "Невозможно загрузить, ipb_bbcode.xml был не найдет или оказался путым";
$this->bbcode_start();
}
//-----------------------------------------
// Get xml mah-do-dah
//-----------------------------------------
require( KERNEL_PATH.'class_xml.php' );
$xml = new class_xml();
//-----------------------------------------
// Unpack the datafile
//-----------------------------------------
$xml->xml_parse_document( $content );
//-----------------------------------------
// Get current badwords
//-----------------------------------------
$tags = array();
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'custom_bbcode' ) );
$this->ipsclass->DB->simple_exec();
while ( $r = $this->ipsclass->DB->fetch_row() )
{
$tags[ $r['bbcode_tag'] ] = 1;
}
//-----------------------------------------
// pArse
//-----------------------------------------
if ( ! is_array( $xml->xml_array['bbcodeexport']['bbcodegroup']['bbcode'][0] ) )
{
$xml->xml_array['bbcodeexport']['bbcodegroup']['bbcode'][0] = $xml->xml_array['bbcodeexport']['bbcodegroup']['bbcode'];
}
foreach( $xml->xml_array['bbcodeexport']['bbcodegroup']['bbcode'] as $idx => $entry )
{
$bbcode_title = $entry['bbcode_title']['VALUE'];
$bbcode_desc = $entry['bbcode_desc']['VALUE'];
$bbcode_tag = $entry['bbcode_tag']['VALUE'];
$bbcode_replace = $entry['bbcode_replace']['VALUE'];
$bbcode_useoption = $entry['bbcode_useoption']['VALUE'];
$bbcode_example = $entry['bbcode_example']['VALUE'];
if ( $tags[ $bbcode_tag ] )
{
continue;
}
if ( $bbcode_tag )
{
$bbarray = array(
'bbcode_title' => $bbcode_title,
'bbcode_desc' => $bbcode_desc,
'bbcode_tag' => $bbcode_tag,
'bbcode_replace' => $this->ipsclass->txt_safeslashes($bbcode_replace),
'bbcode_useoption' => $bbcode_useoption,
'bbcode_example' => $bbcode_example,
);
$this->ipsclass->DB->do_insert( 'custom_bbcode', $bbarray );
}
}
$this->bbcode_rebuildcache();
$this->ipsclass->main_msg = "XML файл BB-кодов был успешно импортирован";
$this->bbcode_start();
}
//-----------------------------------------
// BBCODE: Export
//-----------------------------------------
function bbcode_export()
{
//-----------------------------------------
// Get xml mah-do-dah
//-----------------------------------------
require( KERNEL_PATH.'class_xml.php' );
$xml = new class_xml();
//-----------------------------------------
// Start...
//-----------------------------------------
$xml->xml_set_root( 'bbcodeexport', array( 'exported' => time() ) );
//-----------------------------------------
// Get emo group
//-----------------------------------------
$xml->xml_add_group( 'bbcodegroup' );
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'custom_bbcode' ) );
$this->ipsclass->DB->simple_exec();
while ( $r = $this->ipsclass->DB->fetch_row() )
{
$content = array();
foreach ( $r as $k => $v )
{
$content[] = $xml->xml_build_simple_tag( $k, $v );
}
$entry[] = $xml->xml_build_entry( 'bbcode', $content );
}
$xml->xml_add_entry_to_group( 'bbcodegroup', $entry );
$xml->xml_format_document();
//-----------------------------------------
// Send to browser.
//-----------------------------------------
$this->ipsclass->admin->show_download( $xml->xml_document, 'ipb_bbcode.xml' );
}
//-----------------------------------------
// BBCODE Remove
//-----------------------------------------
function bbcode_delete()
{
if ( ! $this->ipsclass->input['id'] )
{
$this->ipsclass->main_msg = "Нет пригодного ID, попытайтесь заново.";
$this->bbcode_start();
}
$this->ipsclass->DB->simple_exec_query( array( 'delete' => 'custom_bbcode', 'where' => 'bbcode_id='.$this->ipsclass->input['id'] ) );
$this->bbcode_rebuildcache();
$this->bbcode_start();
}
//-----------------------------------------
// BBCODE Rebuild Cache
//-----------------------------------------
function bbcode_rebuildcache()
{
$this->ipsclass->cache['bbcode'] = array();
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'custom_bbcode' ) );
$bbcode = $this->ipsclass->DB->simple_exec();
while ( $r = $this->ipsclass->DB->fetch_row($bbcode) )
{
$this->ipsclass->cache['bbcode'][] = $r;
}
$this->ipsclass->update_cache( array( 'name' => 'bbcode', 'array' => 1, 'deletefirst' => 1 ) );
}
//-----------------------------------------
// BBCODE Test
//-----------------------------------------
function bbcode_test()
{
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'custom_bbcode', 'order' => 'bbcode_title' ) );
$this->ipsclass->DB->simple_exec();
$t = $this->ipsclass->txt_stripslashes($_POST['bbtest']);
while ( $row = $this->ipsclass->DB->fetch_row() )
{
if ( substr_count( $row['bbcode_replace'], '{content}' ) > 1 )
{
//-----------------------------------------
// Slightly slower
//-----------------------------------------
if ( $row['bbcode_useoption'] )
{
preg_match_all( "#(\[".$row['bbcode_tag']."=(?:"|&\#39;)?(.+?)(?:"|&\#39;)?\])(.+?)(\[/".$row['bbcode_tag']."\])#si", $t, $match );
for ($i=0; $i < count($match[0]); $i++)
{
$tmp = $row['bbcode_replace'];
$tmp = str_replace( '{option}' , $match[2][$i], $tmp );
$tmp = str_replace( '{content}', $match[3][$i], $tmp );
$t = str_replace( $match[0][$i], $tmp, $t );
}
}
else
{
preg_match_all( "#(\[".$row['bbcode_tag']."\])(.+?)(\[/".$row['bbcode_tag']."\])#si", $t, $match );
for ($i=0; $i < count($match[0]); $i++)
{
$tmp = $row['bbcode_replace'];
$tmp = str_replace( '{content}', $match[2][$i], $tmp );
$t = str_replace( $match[0][$i], $tmp, $t );
}
}
}
else
{
$replace = explode( '{content}', $row['bbcode_replace'] );
if ( $row['bbcode_useoption'] )
{
$t = preg_replace( "#\[".$row['bbcode_tag']."=(?:"|&\#39;)?(.+?)(?:"|&\#39;)?\]#si", str_replace( '{option}', "\\1", $replace[0] ), $t );
}
else
{
$t = preg_replace( '#\['.$row['bbcode_tag'].'\]#i' , $replace[0], $t );
}
$t = preg_replace( '#\[/'.$row['bbcode_tag'].'\]#i', $replace[1], $t );
}
}
$this->ipsclass->main_msg = "BBCode Test:
".$t;
$this->bbcode_start();
}
//-----------------------------------------
// BBCODE Save Form
//-----------------------------------------
function bbcode_save($type='add')
{
if ( $type == 'edit' )
{
if ( ! $this->ipsclass->input['id'] )
{
$this->ipsclass->main_msg = "Нет пригодного ID, попытайтесь заново ";
$this->bbcode_form($type);
}
}
//-----------------------------------------
// check...
//-----------------------------------------
if ( ! $this->ipsclass->input['bbcode_title'] or ! $this->ipsclass->input['bbcode_tag'] or ! $this->ipsclass->input['bbcode_replace'] )
{
$this->ipsclass->main_msg = "Вы должны заполнить все поля.";
$this->bbcode_form($type);
}
if ( ! strstr( $this->ipsclass->input['bbcode_replace'], '{content}' ) )
{
$this->ipsclass->main_msg = "Вы должны использовать {content}, в тех местах, где происходит замена BB-кодов.";
$this->bbcode_form($type);
}
if ( ! strstr( $this->ipsclass->input['bbcode_replace'], '{option}' ) AND $this->ipsclass->input['bbcode_useoption'] )
{
$this->ipsclass->main_msg = "Вы должны использовать {content}, в тех местах, где происходит замена BB-кодов или в меню 'Использовать настройки в тегах' поставить 'нет'.";
$this->bbcode_form($type);
}
$array = array( 'bbcode_title' => $this->ipsclass->input['bbcode_title'],
'bbcode_desc' => $this->ipsclass->txt_safeslashes( $_POST['bbcode_desc'] ),
'bbcode_tag' => $this->ipsclass->input['bbcode_tag'],
'bbcode_replace' => $this->ipsclass->txt_safeslashes( $_POST['bbcode_replace'] ),
'bbcode_example' => $this->ipsclass->txt_safeslashes( $_POST['bbcode_example'] ),
'bbcode_useoption' => $this->ipsclass->input['bbcode_useoption'] );
if ( $type == 'add' )
{
$this->ipsclass->DB->do_insert( 'custom_bbcode', $array );
$this->ipsclass->main_msg = 'Новый BB-код был добавлен';
}
else
{
$this->ipsclass->DB->do_update( 'custom_bbcode', $array, 'bbcode_id='.$this->ipsclass->input['id'] );
$this->ipsclass->main_msg = 'BB-код отредактирован';
}
$this->bbcode_rebuildcache();
$this->bbcode_start();
}
//-----------------------------------------
// BBCODE Start Form
//-----------------------------------------
function bbcode_form($type='add')
{
$this->ipsclass->admin->page_detail = "Менеджер BB-кодов поможет Вам создать и настроить их деятельность. ";
$this->ipsclass->admin->page_title = "Менеджер настройки BB-кодов";
if ( $type == 'edit' )
{
if ( ! $this->ipsclass->input['id'] )
{
$this->ipsclass->main_msg = "Нет пригодного ID, попытайтесь заново ";
$this->bbcode_start();
}
$bbcode = $this->ipsclass->DB->simple_exec_query( array( 'select' => '*', 'from' => 'custom_bbcode', 'where' => 'bbcode_id='.$this->ipsclass->input['id'] ) );
$button = "Отредактировать";
$code = 'bbcode_doedit';
$title = "Редактирование BB-кода: ".$bbcode['bbcode_title'];
}
else
{
$bbcode = array();
$code = 'bbcode_doadd';
$title = "Добавление нового BB-кода";
$button = "Добавить";
}
//-----------------------------------------
// Show the codes mahn!
//-----------------------------------------
$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'act' , 'bbcode' ),
2 => array( 'code' , $code ),
3 => array( 'id' , $this->ipsclass->input['id'] ),
4 => array( 'section', $this->ipsclass->section_code ),
) );
$this->ipsclass->adskin->td_header[] = array( " " , "40%" );
$this->ipsclass->adskin->td_header[] = array( " " , "60%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( $title );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Название BB-кодаИспользуется во всплывающей подсказке BB-кода
",
$this->ipsclass->adskin->form_input( 'bbcode_title', $this->ipsclass->input['bbcode_title'] ? $this->ipsclass->input['bbcode_title'] : $bbcode['bbcode_title'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Полное описание этого BB-кодаИспользуется во всплывающей подсказке BB-код
",
$this->ipsclass->adskin->form_textarea( 'bbcode_desc', $this->ipsclass->input['bbcode_desc'] ? $this->ipsclass->input['bbcode_desc'] : $bbcode['bbcode_desc'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Пример этого BB-кодаИспользуется во всплывающей подсказке BB-код
Тэг для примера: [tag]Здесь Ваш пример![/tag]
",
$this->ipsclass->adskin->form_textarea( 'bbcode_example', $this->ipsclass->input['bbcode_example'] ? $this->ipsclass->input['bbcode_example'] : $bbcode['bbcode_example'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Тэг этого BB-кодаПример: Для [tag] введите tag
",
'[ '.$this->ipsclass->adskin->form_simple_input( 'bbcode_tag', $this->ipsclass->input['bbcode_tag'] ? $this->ipsclass->input['bbcode_tag'] : $bbcode['bbcode_tag'], 10).' ]'
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Использовать опции в теге?Используется для создания BB-кода с опциями: [tag=option]
",
$this->ipsclass->adskin->form_yes_no( 'bbcode_useoption', $this->ipsclass->input['bbcode_useoption'] ? $this->ipsclass->input['bbcode_useoption'] : $bbcode['bbcode_useoption'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Замена BB-кода<tag>{content}</tag>
<tag thing='{option}'>{content}</tag>
",
$this->ipsclass->adskin->form_textarea( 'bbcode_replace', $this->ipsclass->input['bbcode_replace'] ? $this->ipsclass->input['bbcode_replace'] : $bbcode['bbcode_replace'] )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->end_form( $button );
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->ipsclass->html .= "
Дополнительная информация
Во время добавления замены BB-кода, не забудьте добавить блок {content} там, где это требуется.
Если вы используете опцию BB-кода [tag=option][/tag], не забудьте добавить блок {option} там, где это требуется в замене BB-кода.
";
//-----------------------------------------
$this->ipsclass->admin->output();
}
//-----------------------------------------
// BBCODE Splash
//-----------------------------------------
function bbcode_start()
{
$this->ipsclass->admin->page_detail = "Менеджер BB-кодов позволит Вам добавить новый BB-код. ";
$this->ipsclass->admin->page_title = "Менеджер настроек BB-кода";
//-----------------------------------------
// Show the codes mahn!
//-----------------------------------------
$this->ipsclass->adskin->td_header[] = array( "Заголовок" , "30%" );
$this->ipsclass->adskin->td_header[] = array( "Тег" , "40%" );
$this->ipsclass->adskin->td_header[] = array( "Опции" , "30%" );
$export_button = $this->ipsclass->adskin->js_make_button("Экспорт BB-кода", $this->ipsclass->base_url."&{$this->ipsclass->form_code}&code=bbcode_export");
$table = "
| Ваши BB-коды |
{$export_button} |
";
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( $table );
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'custom_bbcode', 'order' => 'bbcode_title' ) );
$this->ipsclass->DB->simple_exec();
while ( $row = $this->ipsclass->DB->fetch_row() )
{
if ( $row['bbcode_useoption'] )
{
$option = '={option}';
}
else
{
$option = '';
}
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "".$row['bbcode_title']."",
'['.$row['bbcode_tag'].$option.']{content}[/'.$row['bbcode_tag'].']',
"".
$this->ipsclass->adskin->js_make_button("Редактировать" , $this->ipsclass->base_url."&{$this->ipsclass->form_code}&code=bbcode_edit&id={$row['bbcode_id']}").' '.
$this->ipsclass->adskin->js_make_button("Удалить", $this->ipsclass->base_url."&{$this->ipsclass->form_code}&code=bbcode_delete&id={$row['bbcode_id']}")
."
",
) );
}
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->ipsclass->html .= "".$this->ipsclass->adskin->js_make_button("Создать новый BB-код" , $this->ipsclass->base_url."&{$this->ipsclass->form_code}&code=bbcode_add")."
";
$this->ipsclass->html .= "
";
$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'act' , 'bbcode' ),
2 => array( 'code' , 'bbcode_test' ),
4 => array( 'section', $this->ipsclass->section_code ),
) );
$this->ipsclass->adskin->td_header[] = array( " " , "40%" );
$this->ipsclass->adskin->td_header[] = array( " " , "60%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Проверить Ваш BB-код" );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "Проверить Ваш BB-кодe",
$this->ipsclass->adskin->form_textarea( 'bbtest', $_POST['bbtest'] ),
) );
$this->ipsclass->html .= $this->ipsclass->adskin->end_form("Начать проверку");
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
//-----------------------------------------
// IMPORT: Start table
//-----------------------------------------
$this->ipsclass->adskin->td_header[] = array( " " , "60%" );
$this->ipsclass->adskin->td_header[] = array( " " , "40%" );
//-----------------------------------------
// IMPORT: Start output
//-----------------------------------------
$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code' , 'bbcode_import' ),
2 => array( 'act' , 'bbcode' ),
3 => array( 'MAX_FILE_SIZE', '10000000000' ),
4 => array( 'section', $this->ipsclass->section_code ),
) , "uploadform", " enctype='multipart/form-data'" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Импорт список BB-кода" );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array(
"Загрузить XML список BB-кодаВыберите на Вашем компьютере 'ipb_bbcode.xml'. Дублирование [tag] невозможно, импортировать не удастся.
",
$this->ipsclass->adskin->form_upload( )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->end_form("Импорт");
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->ipsclass->admin->output();
}
function perly_length_sort($a, $b)
{
if ( strlen($a['typed']) == strlen($b['typed']) )
{
return 0;
}
return ( strlen($a['typed']) > strlen($b['typed']) ) ? -1 : 1;
}
function perly_word_sort($a, $b)
{
if ( strlen($a['type']) == strlen($b['type']) )
{
return 0;
}
return ( strlen($a['type']) > strlen($b['type']) ) ? -1 : 1;
}
}
?>