yf_static_pages user module

Static pages display module.

Fileplugins/static_pages/modules/yf_static_pages.class.php
Usemodule('static_pages'), URL ?object=static_pages

Public properties

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

PropertyDefaultDescription
$ALLOW_HTML_IN_TEXT
bool
true Allow HTML in text
$PAGE_HEADING null
$PAGE_NAME
string
null @conf_skip
$PAGE_TITLE
string
null @conf_skip
$_cache []
$_current null

Constants

table'static_pages'

Public methods 14

email_page

public function email_page()

Email Page.

    public function email_page()
    {
        $a = $this->_get_page_from_db();
        $this->_set_global_info($a);
        // Show error message
        if (empty($a)) {
            _re('No such page!');
            $body = _e();
        } else {
            $body = common()->email_page($a['text']);
        }
        return $body;
    }

get_rss_page

public function get_rss_page()

Display RSS channels contents.

    public function get_rss_page()
    {
        $params = [];
        $body = common()->fetch_rss($params);
        return $body;
    }

pdf_view

public function pdf_view()

Pdf View.

    public function pdf_view()
    {
        $a = $this->_get_page_from_db();
        if ( ! $a) {
            return _404();
        }
        $this->_set_global_info($a);
        $text = $this->ALLOW_HTML_IN_TEXT ? $a['text'] : _prepare_html($a['text']);
        return common()->pdf_page($text, 'page_' . $a['name']);
    }

print_view

public function print_view()

Print View.

    public function print_view()
    {
        $a = $this->_get_page_from_db();
        if ( ! $a) {
            return _404();
        }
        $this->_set_global_info($a);
        $text = $this->ALLOW_HTML_IN_TEXT ? $a['text'] : _prepare_html($a['text']);
        return common()->pdf_page($text, 'page_' . $a['name']);
    }

rss_page

public function rss_page()

Rss Page.

    public function rss_page()
    {
        $data = [];
        $params = [];
        $body = common()->rss_page($data, $params);
        return $body;
    }

show

public function show()

Display page contents.

    public function show()
    {
        $a = $this->_get_page_from_db();
        if ( ! $a) {
            return _404();
        }
        $this->_set_global_info($a);
        // Get sub-pages (from menu)
        $sub_pages = [];
        $menus = main()->get_data('menus');

        $cur_menu_id = 0;
        // Find first user menu
        if ( ! $cur_menu_id) {
            foreach ((array) $menus as $_info) {
                if ($_info['type'] == 'user' && $_info['active']) {
                    $cur_menu_id = $_info['id'];
                    break;
                }
            }
        }
        $cur_menu_item_id = 0;
        if ($cur_menu_id) {
            $menu_items = main()->get_data('menu_items');
            foreach ((array) $menu_items[$cur_menu_id] as $item_info) {
                if ( ! $item_info['active'] || $item_info['parent_id']) {
                    continue;
                }
                if ($item_info['location'] == 'object=' . ($_GET['object'] ?? null) . '&action=' . ($_GET['action'] ?? null) . '&id=' . ($_GET['id'] ?? null)) {
                    $cur_menu_item_id = $item_info['parent_id'] ? $item_info['parent_id'] : $item_info['id'];
                    break;
                }
            }
        }
        if ($cur_menu_id && $cur_menu_item_id) {
            foreach ((array) $menu_items[$cur_menu_id] as $item_info) {
                if ( ! $item_info['active'] || $item_info['parent_id'] != $cur_menu_item_id) {
                    continue;
                }
                $sub_pages[$item_info['id']] = [
                    'name' => _prepare_html($item_info['name']),
                    'link' => process_url('./?' . $item_info['location']),
                ];
            }
        }
        $content = tpl()->parse_string(stripslashes($a['text']), [], 'static_page__' . $a['id']);
        // Process template
        $replace = [
            'id' => (int) ($a['id']),
            'name' => stripslashes($a['name']),
//			'content'			=> stripslashes($a['text']), // DO NOT ADD _prepare_html here!
            'content' => $content,
            'page_heading' => _prepare_html(_ucfirst($a['page_heading'])),
            'page_page_title' => _prepare_html(_ucfirst($a['page_title'])),
            'print_link' => './?object=' . ($_GET['object'] ?? null) . '&action=print_view&id=' . $a['id'],
            'pdf_link' => './?object=' . ($_GET['object'] ?? null) . '&action=pdf_view&id=' . $a['id'],
            'email_link' => './?object=' . ($_GET['object'] ?? null) . '&action=email_page&id=' . $a['id'],
            'sub_pages' => $sub_pages,
        ];
        return tpl()->parse(($_GET['object'] ?? null) . '/main', $replace);
    }

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

__call

public function __call($name, $arguments)

Catch missing method call.

    public function __call($name, $arguments)
    {
        trigger_error(__CLASS__ . ': No method ' . $name, E_USER_WARNING);
        return false;
    }
public function _get_page_from_db($id = null)
    public function _get_page_from_db($id = null)
    {
        $lang = null;
        $id = $id ?: ($_GET['id'] ?? null);
        if (empty($id)) {
            return [];
        }
        $lang = conf('language');
        $cache_name = $id . '|' . $lang;
        $a = $this->_cache[$cache_name];
        if ($a !== null) {
            return $a;
        }
        $q = db()->from(self::table)->where('active', '1');
        if (is_numeric($id)) {
            $q->where('id', (int) $id);
        } else {
            $q->where('name', _strtolower($id));
        }
        $q->where('locale', $lang);
        $a = $q->get();
        $this->_cache[$cache_name] = $a;
        return $a;
    }

_hook_sitemap

public function _hook_sitemap($sitemap = false)

Hook for the site_map.

    public function _hook_sitemap($sitemap = false)
    {
        if ( ! is_object($sitemap)) {
            return false;
        }
        foreach ((array) db()->from(self::table)->where('active', '1')->where('locale', conf('language'))->get_all() as $a) {
            $sitemap->_add('/static_pages/show/' . $a['name']);
        }
        return true;
    }
public function _module_action_handler($name)
    public function _module_action_handler($name)
    {
        if (method_exists($this, $name) && substr($name, 0, 1) !== '_') {
            return $this->$name();
        }
        $_GET['action'] = 'show';
        $_GET['id'] = $name;
        return $this->show();
    }
public function _set_global_info($a = [])

Set page infor for global use.

    public function _set_global_info($a = [])
    {
        $this->PAGE_NAME = _prepare_html($a['name']);
        $this->PAGE_HEADING = _prepare_html(_ucfirst($a['page_heading']));
        $this->PAGE_TITLE = _prepare_html(_ucfirst($a['title'] ? $a['title'] : $a['page_title']));
        conf('meta_keywords', _prepare_html($a['meta_keywords']));
        conf('meta_description', _prepare_html($a['meta_desc']));
    }

_show_header

public function _show_header()

Page header hook.

    public function _show_header()
    {
        $pheader = $this->PAGE_HEADING ? $this->PAGE_HEADING : $this->PAGE_NAME;
        // Default subheader get from action name
        $subheader = '';
        // Array of replacements
        $cases = [
            //$_GET['action'] => {string to replace}
            'show' => '',
        ];
        if (isset($cases[$_GET['action']])) {
            // Rewrite default subheader
            $subheader = $cases[$_GET['action']];
        }
        return [
            'header' => $pheader,
            'subheader' => $subheader ? _prepare_html($subheader) : '',
        ];
    }

_site_title

public function _site_title($title)

Title hook.

    public function _site_title($title)
    {
        $subtitle = '';

        $subtitle = $this->PAGE_TITLE ? $this->PAGE_TITLE : $this->PAGE_NAME;
        if ($subtitle) {
            $title .= ' : ' . t($subtitle);
        }
        return $title;
    }