yf_preview class

Class to handle output caching.

Fileplugins/common/classes/common/yf_preview.class.php
Use_class('preview', 'classes/common/')

Public properties

A site sets them in its config with $PROJECT_CONF['preview']['NAME'] = ...;

PropertyDefaultDescription
$USE_BB_CODES
bool
true
$skip_fields
array
['mode', 'f_family_text', 'f_size_text', 'f_color_text', 'helpbox_text', 'tag_count_text', ... (9 items)]
array (
  0 => 'mode',
  1 => 'f_family_text',
  2 => 'f_size_text',
  3 => 'f_color_text',
  4 => 'helpbox_text',
  5 => 'tag_count_text',
  6 => 'parent_object',
  7 => 'parent_action',
  8 => 'form_action',
)
These variables will not be displayed in preview

Public methods 3

None without a leading underscore.

Methods starting with _ hooks and helpers; not routable as page actions

public function _display_buttons($params = [])

Display buttons code.

    public function _display_buttons($params = []/*, $template = ""*/)
    {
        $replace = [
            'preview_link' => './?object=' . ($_GET['object'] ?? null) . '&action=display_preview',
            'width' => ! empty($params['width']) ? (int) ($params['width']) : 400,
            'height' => ! empty($params['height']) ? ($params['height']) : 300,
            'default_action' => '',
            'parent_object' => ($_GET['object'] ?? null),
            'parent_action' => ($_GET['action'] ?? null),
        ];
        return tpl()->parse(__CLASS__ . '/buttons', $replace);
    }
public function _display_preview($params = [], $template = '')

Display preview method.

NOTE : parent_object & parent_action are used to determine

    public function _display_preview($params = [], $template = '')
    {
        $replace = $params['replace'];
        $PARENT_OBJECT = ($_REQUEST['parent_object'] ?? null);
        $PARENT_ACTION = ($_REQUEST['parent_action'] ?? null);
        // If no custom replace given, try to make own
        if (empty($replace)) {
            foreach ((array) $_POST as $k => $v) {
                if (in_array($v, $this->skip_fields)) {
                    continue;
                }
                if ($k != 'category_id') {
                    $replace[$k] = $this->_format_text($v);
                } else {
                    // Try to get category_id based on parent object
                    $categories = cache_get($PARENT_OBJECT . '_categories');
                    $replace['category_id'] = $categories[$v];
                }
            }
        }
        // Try to get template
        if (false !== strpos(($_POST['preview_form_action'] ?? ''), 'add_comment')) {
            $body = tpl()->parse('comments/preview', $replace);
        } else {
            $stpl_name = $PARENT_OBJECT . '/' . $PARENT_ACTION . '_preview';
            $body = tpl()->_stpl_exists($stpl_name) ? tpl()->parse($stpl_name, $replace) : '';
        }
        // Default body
        if (empty($body)) {
            $body = tpl()->parse(__CLASS__ . '/default', $replace);
        }
        // Process template
        $replace2 = [
            'template' => $body,
        ];
        return common()->show_empty_page(tpl()->parse('preview/main', $replace2), ['title' => t('Preview')]);
    }

_format_text

public function _format_text($body = '')

Format given text (convert BB Codes, new lines etc).

Returns string

    public function _format_text($body = '')
    {
        // Stop here if text is empty
        if (empty($body)) {
            return '';
        }
        // If special code is "on" - process it
        if ($this->USE_BB_CODES) {
            $BB_CODES_OBJ = _class('bb_codes');
        }
        // We cannot die, need to be safe
        if ($this->USE_BB_CODES && is_object($BB_CODES_OBJ)) {
            $body = $BB_CODES_OBJ->_process_text($body);
        } else {
            $body = nl2br(_prepare_html($body, 0));
        }
        return $body;
    }