View file super2/bbcode/demo.php

File size: 3.09Kb
<?php

/******************************************************************************
 *                                                                            *
 *   demo.php, v 0.01 2007/03/08 - This is part of xBB library                *
 *   Copyright (C) 2006-2007  Dmitriy Skorobogatov  dima@pc.uz                *
 *                                                                            *
 *   This program is free software; you can redistribute it and/or modify     *
 *   it under the terms of the GNU General Public License as published by     *
 *   the Free Software Foundation; either version 2 of the License, or        *
 *   (at your option) any later version.                                      *
 *                                                                            *
 *   This program is distributed in the hope that it will be useful,          *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *   GNU General Public License for more details.                             *
 *                                                                            *
 *   You should have received a copy of the GNU General Public License        *
 *   along with this program; if not, write to the Free Software              *
 *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
 *                                                                            *
 ******************************************************************************/

// Указываем тип содержимого этой страницы
header('Content-type: text/html; charset=utf-8');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Тест BBCode</title>
<meta name="author" content="Дмитрий Скоробогатов" />
<link href="./style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="postbody">
<?php
// Подключаем библиотеку с классом
require_once 'bbcode.lib.php';
// получаем текст BBCode методом POST
$text = isset($_POST['text']) ? $_POST['text'] : '';
// Формируем набор смайликов
$pak = file('./smilies/Set_Smiles_YarNET.pak');
$smiles = array();
foreach ( $pak as $val ) {
    $val = trim($val);
    if (! $val || '#' == $val{0}) { continue; }
    list($gif, $alt, $symbol) = explode('=+:',$val);
    $smiles[$symbol] = '<img src="smilies/'.htmlspecialchars($gif)
        .'" alt="'.htmlspecialchars($alt).'" />';
}
// Создаем объект и парсим $text
$bb = new bbcode($text);
// Задаем набор смайликов
$bb -> mnemonics = $smiles;
if (isset($_POST['highlight'])) {    // Подсвечиваем и выводим BBCode
    echo $bb -> highlight();
} else {
    // Конвертируем BBCode в HTML и выводим его
    echo $bb -> get_html();
}
?>
</div>
</body>
</html>