yf_module class

Modules template class.

Fileclasses/yf_module.class.php
Use_class('module')

Public properties

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

PropertyDefaultDescription
$CAPTCHA null
$FORCE_STRIPSLASHES
bool
false Force stripslashes on '_format_text' method
$USER_GROUP null
$USER_ID null
$USE_BB_CODES null
$USE_CAPTCHA
bool
true
$USE_PREVIEW
bool
false Use post preview or not
$_boxes null
$_comments_params
array
[] @conf_skip
$_poll_params
array
[] @conf_skip
$_tags_params
array
[] @conf_skip

Public methods 27

add_comment

public function add_comment($params = [])
    public function add_comment($params = [])
    {
        if (($_POST['submit'] ?? null) == 'Preview') {
            return module('preview')->_display_preview(['text' => ($_POST['text'] ?? null)]);
        }
        return module('comments')->_add((array) $this->_comments_params + (array) $params);
    }

captcha_image

public function captcha_image()

Show captcha image.

    public function captcha_image()
    {
        $this->_captcha_load_code();
        if (is_object($this->CAPTCHA)) {
            $this->CAPTCHA->show_image();
        }
    }

create_poll

public function create_poll()
    public function create_poll()
    {
        return module_safe('poll')->_create($this->_poll_params);
    }
public function delete_comment($params = [])
    public function delete_comment($params = [])
    {
        return module_safe('comments')->_delete((array) $this->_comments_params + (array) $params);
    }

delete_poll

public function delete_poll()
    public function delete_poll()
    {
        return module_safe('poll')->delete($this->_poll_params);
    }
public function display_preview($params = [], $template = '')

Display preview of current module (usually popup window).

    public function display_preview($params = [], $template = '')
    {
        if ($_POST != null) {
            return _class_safe('preview')->_display_preview(['replace' => $this->_prepare_preview()]);
        }
    }

edit_comment

public function edit_comment($params = [])
    public function edit_comment($params = [])
    {
        return module_safe('comments')->_edit((array) $this->_comments_params + (array) $params);
    }

edit_tag

public function edit_tag()
    public function edit_tag()
    {
        return module_safe('tags')->_edit_tags($_GET['id'] ?? null);
    }

tag

public function tag()

Search by tag in a current module.

    public function tag()
    {
        return module_safe('tags')->search();
    }
public function view_poll_results()
    public function view_poll_results()
    {
        return module_safe('poll')->owner_view($this->_poll_params);
    }

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

__call

public function __call($name, $args)

Catch missing method call.

    public function __call($name, $args)
    {
        return main()->extend_call($this, $name, $args);
    }

_box

public function _box($name = '', $selected = '')

Process custom box.

    public function _box($name = '', $selected = '')
    {
        if (empty($name) || empty($this->_boxes[$name])) {
            return false;
        }
        return eval('return common()->' . $this->_boxes[$name] . ';');
    }
public function _captcha_block()

Display captcha html block code.

    public function _captcha_block()
    {
        $this->_captcha_load_code();
        if (is_object($this->CAPTCHA)) {
            return $this->CAPTCHA->show_block('./?object=' . ($_GET['object'] ?? null) . '&action=captcha_image');
        }
    }
public function _captcha_check()

Validate captcha (posted code).

    public function _captcha_check()
    {
        $this->_captcha_load_code();
        if (is_object($this->CAPTCHA)) {
            $this->CAPTCHA->check('captcha');
        }
    }
public function _captcha_load_code()

Load captcha code.

    public function _captcha_load_code()
    {
        if ( ! $this->USE_CAPTCHA) {
            return false;
        }
        if (is_object($this->CAPTCHA)) {
            return false;
        }
        $this->CAPTCHA = _class('captcha');
    }
public function _comment_delete_allowed($params = [])
    public function _comment_delete_allowed($params = [])
    {
        return (bool) $this->USER_ID && $params['user_id'] && $params['user_id'] == $this->USER_ID;
    }
public function _comment_edit_allowed($params = [])
    public function _comment_edit_allowed($params = [])
    {
        return (bool) ($this->USER_ID && $params['user_id'] && $params['user_id'] == $this->USER_ID);
    }
public function _comment_is_allowed($params = [])
    public function _comment_is_allowed($params = [])
    {
        return true;
    }
public function _display_submit_buttons($params = [], $template = '')
    public function _display_submit_buttons($params = [], $template = '')
    {
        return $this->USE_PREVIEW ? _class_safe('preview')->_display_buttons() : '';
    }

_format_text

public function _format_text($body = '')

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

    public function _format_text($body = '')
    {
        // Stop here if text is empty
        if (empty($body)) {
            return '';
        }
        if ($this->FORCE_STRIPSLASHES) {
            $body = stripslashes($body);
        }
        if ($this->USE_BB_CODES) {
            $body = _class('bb_codes')->_process_text($body);
        } else {
            $body = nl2br(_prepare_html($body, 0));
        }
        return $body;
    }
public function _get_num_comments($params = [])
    public function _get_num_comments($params = [])
    {
        if ( ! is_array($params)) {
            $params = ['objects_ids' => $params];
        }
        return module_safe('comments')->_get_num_comments((array) $params + (array) $this->_comments_params);
    }

_poll

public function _poll($object_id, $object_name = '')

Shows poll block.

    public function _poll($object_id, $object_name = '')
    {
        return module_safe('poll')->_show_poll_block($object_id, $object_name);
    }
public function _prefetch_rate_infos($params = [])

Display rate box (stars etx).

    public function _prefetch_rate_infos($params = [])
    {
        return module_safe('rate')->_prefetch_rate_infos($params);
    }
public function _prepare_preview()
    public function _prepare_preview()
    {
        return false;
    }
public function _show_rate_box($params = [])

Display rate box (stars etx).

    public function _show_rate_box($params = [])
    {
        return module_safe('rate')->_show_for_object($params);
    }

_show_tags

public function _show_tags($ids = [], $params = [])
    public function _show_tags($ids = [], $params = [])
    {
        return module_safe('tags')->_show($ids, (array) $this->_tags_params + (array) $params);
    }
public function _view_comments($params = [])
    public function _view_comments($params = [])
    {
        return module_safe('comments')->_show_for_object((array) $params + (array) $this->_comments_params);
    }