yf_preview classClass to handle output caching.
| File | plugins/common/classes/common/yf_preview.class.php |
|---|---|
| Use | _class('preview', 'classes/common/') |
A site sets them in its config with $PROJECT_CONF['preview']['NAME'] = ...;
| Property | Default | Description |
|---|---|---|
$USE_BB_CODESbool |
true |
|
$skip_fieldsarray |
|
These variables will not be displayed in preview |
None without a leading underscore.
_ hooks and helpers; not routable as page actionspublic function _display_buttons($params = [])
Display buttons code.
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')]);
}
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;
}