Ответить в теме

[spoiler="bbcode.php"]

<?php


if (!defined('BB_ROOT')) die(basename(__FILE__));


$datastore->enqueue(array(

    'smile_replacements',

));


$page_cfg['include_bbcode_js'] = true;


//

// BBCode templates

//

function get_bbcode_tpl ()

{

$bbcode_tpl = array();


// Quote

$bbcode_tpl['quote_open'] = <<<HTML

    <div class="q-wrap">

        <div class="q">

HTML;


$bbcode_tpl['quote_username_open'] = <<<HTML

    <div class="q-wrap">

        <div class="q" head="\\1">

HTML;


$bbcode_tpl['quote_close'] = <<<HTML

        </div>

    </div>

HTML;


// Code

$bbcode_tpl['code_open'] = <<<HTML

    <div class="c-wrap">

        <div class="c-body">

HTML;


$bbcode_tpl['code_close'] = <<<HTML

        </div>

    </div>

HTML;


// Spoiler

$bbcode_tpl['spoiler_open'] = <<<HTML

    <div class="sp-wrap">

        <div class="sp-body">

HTML;


$bbcode_tpl['spoiler_title_open'] = <<<HTML

    <div class="sp-wrap">

        <div class="sp-body" title="\\1">

        <h3 class="sp-title">\\1</h3>

HTML;


$bbcode_tpl['spoiler_close'] = <<<HTML

        </div>

    </div>

HTML;


// Thumb

$bbcode_tpl['thumb'] = <<<HTML

<a href="\\1" onclick="return hs.expand(this)" rel="topic" class="highslide"><img src="\\1" border="0" style="max-width:200px; max-height:120px;" class="thumb"/></a>

HTML;


// Image

$bbcode_tpl['img'] = <<<HTML

    <var class="postImg" title="$1">&#10;</var>

HTML;


$bbcode_tpl['img_aligned'] = <<<HTML

    <var class="postImg postImgAligned img-\\1" title="\\2">&#10;</var>

HTML;


// HR

$bbcode_tpl['hr'] = <<<HTML

    <span class="post-hr">-</span>

HTML;


array_deep($bbcode_tpl, 'bbcode_tpl_compact');

return $bbcode_tpl;

}


function bbcode_tpl_compact ($text)

{

    $text = str_compact($text);

    $text = str_replace('> <', '><', $text);

    return $text;

}


// prepare a posted message for entry into the database

function prepare_message ($message)

{

    $message = bbcode::clean_up($message);

    $message = htmlCHR($message, false, ENT_NOQUOTES);

    return $message;

}


// Fill smiley templates (or just the variables) with smileys

// Either in a window or inline

function generate_smilies($mode)

{

    global $bb_cfg, $template, $lang, $user, $datastore;


    $inline_columns = 4;

    $inline_rows = 7;

    $window_columns = 8;


    if ($mode == 'window')

    {

        $user->session_start();

    }


    $data = $datastore->get('smile_replacements');


    if ($sql = $data['smile'])

    {

        $num_smilies = 0;

        $rowset = array();

        foreach ($sql as $row)

        {

            if (empty($rowset[$row['smile_url']]))

            {

                $rowset[$row['smile_url']]['code'] = addslashes($row['code']);

                $rowset[$row['smile_url']]['emoticon'] = $row['emoticon'];

                $num_smilies++;

            }

        }


        if ($num_smilies)

        {

            $smilies_count = ($mode == 'inline') ? min(19, $num_smilies) : $num_smilies;

            $smilies_split_row = ($mode == 'inline') ? $inline_columns - 1 : $window_columns - 1;


            $s_colspan = 0;

            $row = 0;

            $col = 0;


            while (list($smile_url, $data) = @each($rowset))

            {

                if (!$col)

                {

                    $template->assign_block_vars('smilies_row', array());

                }


                $template->assign_block_vars('smilies_row.smilies_col', array(

                    'SMILEY_CODE' => $data['code'],

                    'SMILEY_IMG' => $bb_cfg['smilies_path'] . '/' . $smile_url,

                    'SMILEY_DESC' => $data['emoticon'],

                ));


                $s_colspan = max($s_colspan, $col + 1);


                if ($col == $smilies_split_row)

                {

                    if ($mode == 'inline' && $row == $inline_rows - 1)

                    {

                        break;

                    }

                    $col = 0;

                    $row++;

                }

                else

                {

                    $col++;

                }

            }


            if ($mode == 'inline' && $num_smilies > $inline_rows * $inline_columns)

            {

                $template->assign_block_vars('switch_smilies_extra', array());


                $template->assign_vars(array(

                    'U_MORE_SMILIES' => POSTING_URL ."?mode=smilies",

                ));

            }


            $template->assign_vars(array(

                'PAGE_TITLE' => $lang['EMOTICONS'],

                'S_SMILIES_COLSPAN' => $s_colspan,

            ));

        }

    }


    if ($mode == 'window')

    {

        print_page('posting_smilies.tpl', 'simple');

    }

}


// some functions from vB

// #############################################################################

/**

* Strips away  tags

    $end_pos = array();

    $curpos = 0;

    do

    {

        $pos = strpos($lowertext, '[/quote', $curpos);

        if ($pos !== false)

        {

            $end_pos["$pos"] = 'end';

            $curpos = $pos + 8;

        }

    }

    while ($pos !== false);


    if (sizeof($end_pos) == 0)

    {

        return $text;

    }


    // merge them together and sort based on position in string

    $pos_list = $start_pos + $end_pos;

    ksort($pos_list);


    do

    {

        // build a stack that represents when a quote tag is opened

        // and add non-quote text to the new string

        $stack = array();

        $newtext = '[...] ';

        $substr_pos = 0;

        foreach ($pos_list AS $pos => $type)

        {

            $stacksize = sizeof($stack);

            if ($type == 'start')

            {

                // empty stack, so add from the last close tag or the beginning of the string

                if ($stacksize == 0)

                {

                    $newtext .= substr($text, $substr_pos, $pos - $substr_pos);

                }

                array_push($stack, $pos);

            }

            else

            {

                // pop off the latest opened tag

                if ($stacksize)

                {

                    array_pop($stack);

                    $substr_pos = $pos + 8;

                }

            }

        }


        // add any trailing text

        $newtext .= substr($text, $substr_pos);


        // check to see if there's a stack remaining, remove those points

        // as key points, and repeat. Allows emulation of a non-greedy-type

        // recursion.

        if ($stack)

        {

            foreach ($stack AS $pos)

            {

                unset($pos_list["$pos"]);

            }

        }

    }

    while ($stack);


    return $newtext;

}


// #############################################################################

/**

 * Strips away bbcode from a given string, leaving plain text

 *

 * @param    string    Text to be stripped of bbcode tags

 * @param    boolean    If true, strip away quote tags AND their contents

 * @param    boolean    If true, use the fast-and-dirty method rather than the shiny and nice method

 *

 * @return    string

 */

function strip_bbcode ($message, $stripquotes = true, $fast_and_dirty = false, $showlinks = true)

{

    $find = array();

    $replace = array();


    if ($stripquotes)

    {

        // [/spoiler]


Сверху