yf_graphics classCore content-related methods stored here.
| File | classes/yf_graphics.class.php |
|---|---|
| Use | _class('graphics') |
A site sets them in its config with $PROJECT_CONF['graphics']['NAME'] = ...;
| Property | Default | Description |
|---|---|---|
$ADD_TITLE_PAGESbool |
true |
Add pages names to the title |
$HEADER_POWERED_BYbool |
false |
|
$ICONS_PATHstring |
'uploads/icons/' |
Path to icons |
$IFRAME_CENTER |
null |
|
$JS_CONSOLE_ALLOWbool |
true |
|
$MEDIA_PATHstring |
'' |
Required for the compatibility with old main class |
$MENU_HIDE_INACTIVE_MODULESbool |
false |
Menu hide links to disabled modules |
$META_ADD |
null |
|
$META_DEFAULT |
null |
|
$META_DESCRIPTIONstring |
'' |
Default HTML Meta tag 'description' |
$META_KEYWORDSstring |
'' |
Default HTML Meta tag 'keywords' |
$META_TITLEstring |
'' |
Default HTML Title tag contents |
$NOT_FOUND_RAISE_WARNINGbool |
true |
|
$QUICK_MENU_ENABLEDbool |
true |
Enable quick menu |
$SHOW_AUTO_TASK_NAMEbool |
false |
Show auto-parsed (and tried to translate) task name |
$SUB_MODULES_PATHstring |
'classes/graphics/' |
Sub-modules dir |
$TIPS_STRIP_TAGS |
null |
|
$_tips |
null |
public function prefetch_center()
Try to run center block module/method if allowed.
public function prefetch_center()
{
return _class('core_blocks')->prefetch_center();
}
public function show_block($params = [])
Alias for the '_show_block'.
public function show_block($params = [])
{
return $this->_show_block($params);
}
public function show_center()
Display main 'center' block contents.
public function show_center()
{
return _class('core_blocks')->show_center();
}
public function show_help()
Prepare help for show.
public function show_help()
{
$module_name = ($_GET['object'] ?? null);
$action_name = ($_GET['action'] ?? null);
$replace = [
'action' => $action_name,
];
$STPL_NAME = $module_name . '/help';
$body = '';
if (tpl()->_stpl_exists($STPL_NAME)) {
$body = tpl()->parse($STPL_NAME, $replace);
}
return tpl()->parse('system/help_wrapper', ['body' => nl2br(trim($body))]);
}
public function show_metatags($meta = [])
Show metatags.
public function show_site_title()
Show site title.
public function show_site_title()
{
$title = null;
if (defined('SITE_ADVERT_NAME')) {
$title = SITE_ADVERT_NAME;
}
if (conf('SITE_ADVERT_NAME')) {
$title = conf('SITE_ADVERT_NAME');
}
if (defined('SITE_TITLE')) {
$title = SITE_TITLE;
}
if ( ! empty($this->META_TITLE)) {
$title = $this->META_TITLE;
}
// For compatibility with old versions
$website_name = conf('website_name');
if (($website_name ?? false) && strlen($website_name)) {
$title = $website_name;
}
// Add pages names to the title
if ($this->ADD_TITLE_PAGES) {
if (strlen($_GET['object'] ?? '') && ($_GET['object'] ?? null) != 'static_pages') {
$title .= ' :: ' . _ucfirst(t($_GET['object']));
$title = _ucfirst(t($_GET['object'])) . ' : ' . $title;
}
}
// Override by hook method
// TODO: maybe need to check permissions at first
$obj = module_safe(($_GET['object'] ?? null));
if (is_object($obj)) {
$hook_names = ['_hook_title', '_site_title'];
foreach ($hook_names as $method_name) {
if (is_object($obj) && method_exists($obj, $method_name)) {
$title = $obj->$method_name($title);
break;
}
}
}
// Force by global var
$conf_title = conf('site_title');
if ($conf_title) {
$title = $conf_title;
}
$title = preg_replace('~\s+~ims', ' ', $title);
return _prepare_html($title);
}
public function show_welcome()
Welcome message method.
public function show_welcome()
{
$body = '';
// For authorized admins only
if (MAIN_TYPE_ADMIN) {
$login_time = ($_SESSION['admin_login_time'] ?? null);
$admin_id = (int) main()->ADMIN_ID;
$admin_group = (int) main()->ADMIN_GROUP;
if ($admin_id && $admin_group) {
$admin_info = db()->query_fetch('SELECT * FROM ' . db('admin') . ' WHERE id=' . $admin_id);
$admin_groups = main()->get_data('admin_groups');
$body .= tpl()->parse('system/admin_welcome', [
'id' => (int) $admin_id,
'name' => _prepare_html($admin_info['first_name'] . ' ' . $admin_info['last_name']),
'group' => _prepare_html(t($admin_groups[$admin_group])),
'time' => _format_date($login_time),
'edit_link' => './?object=admin_account',
]);
if ($_SESSION['admin_prev_info']) {
// the bs5 admin layout already wraps show_welcome() in an <li> of its dropdown
$body .= conf('css_framework') === 'bs5'
? '<a class="dropdown-item" href="./?task=login&id=prev_info"><i class="fa fa-arrow-up"></i> ' . t('Login back') . '</a>'
: '<li><a href="./?task=login&id=prev_info"><i class="icon icon-arrow-up fa fa-arrow-up"></i> ' . t('Login back') . '</a></li>';
}
}
// For authorized users only
} elseif (MAIN_TYPE_USER) {
$login_time = ($_SESSION['user_login_time'] ?? null);
$user_id = (int) main()->USER_ID;
$user_group = (int) main()->USER_GROUP;
if ($user_id && $user_group) {
$user_info = user($user_id);
$user_groups = main()->get_data('user_groups');
$body .= tpl()->parse('system/user_welcome', [
'id' => (int) ($user_info['id']),
'name' => _prepare_html(_display_name($user_info)),
'group' => _prepare_html(t($user_groups[$user_group])),
'time' => _format_date($login_time),
'user_info' => $user_info,
]);
}
}
return $body;
}
public function show_welcome2()
Welcome message for the admin section.
public function show_welcome2()
{
$body = null;
if (MAIN_TYPE_ADMIN) {
$body = t('You logged in as %user at %date', ['%date' => date('H:i:s', ($_SESSION['admin_login_time'] ?? null)), '%user' => t('admin')]);
}
return $body;
}
public function tasks($allowed_check = false)
Main $_GET tasks handler.
public function tasks($allowed_check = false)
{
return _class('core_blocks')->tasks($allowed_check);
}
public function tip($in = null, $extra = [])
New unified method to display tooltips, all others should be deprecated. Examples: tip('register.login') tpl version: {tip('register.login')} tip('Some inline help text') tpl version: {tip('Some inline help text')} tip('Some inline help text';'fa-eye') tpl version: {tip('Some inline help text';'fa-eye')} tip(array('raw' => '\'Some inline help text\';\'fa-eye\'')) tip(array('text' => 'Some inline help text', 'icon' => 'fa-eye')) tip('Some inline help text', array('icon' => 'fa-eye')).
public function tip($in = null, $extra = [])
{
if ( ! is_array($extra)) {
$extra = [];
}
$return_text = false;
if (is_array($in) && isset($in['text'])) {
$extra = (array) $extra + $in;
} elseif (is_array($in) && isset($in['raw'])) {
// Some inline help text
// Some inline help text;fa-eye;my_tip_class'
// Some inline help text; fa-eye; my_tip_class
// 'Some inline help text'
// 'Some inline help text';'fa-eye'
// 'Some inline help text';'fa-eye';'my_tip_class'
$raw = explode(';', str_replace(['\'', '"'], '', $in['raw']));
$extra['text'] = trim($raw[0]);
if (($raw[1] ?? '') === 'return_text=1' || ($raw[1] ?? '') === 'text=1') {
$return_text = true;
}
$extra['icon'] = trim($raw[1] ?? '');
$extra['class'] = trim($raw[1] ?? '');
if (isset($in['replace']) && $extra['text'] && substr($extra['text'], 0, 1) === '@') {
$replace_var = substr($extra['text'], 1);
if (isset($in['replace'][$replace_var])) {
$extra['text'] = $in['replace'][$replace_var];
}
}
}
$extra['text'] = trim(($extra['text'] ?? '') ?: (is_string($in) ? $in : ''));
if ( ! strlen($extra['text'])) {
return false;
}
$strip_tags = $extra['strip_tags'] ?? $this->TIPS_STRIP_TAGS;
if ( ! isset($this->_tips)) {
$this->_tips = (array) main()->get_data('tips');
}
$tip = [];
if (isset($this->_tips[$extra['text']])) {
$lang = conf('language');
// Exact match for current language
if (isset($this->_tips[$extra['text']][$lang])) {
$tip = $this->_tips[$extra['text']][$lang];
} else {
// Try to get first record and translate it
$tip = current($this->_tips[$extra['text']]) ?: [];
if ($strip_tags) {
$tip['text'] = strip_tags((string) ($tip['text'] ?? '')); // Needed for correct translation
}
$tip['text'] = t((string) ($tip['text'] ?? ''));
}
if ( ! ($tip['active'] ?? null)) {
return false;
}
$extra['text'] = (string) ($tip['text'] ?? '');
}
if ($strip_tags) {
$extra['text'] = strip_tags($extra['text']);
}
if ( ! strlen($extra['text'])) {
return false;
}
// Thinking that we have template variables or tags inside tip contents, try to replace them
if (isset($in['replace']) && false !== strpos($extra['text'], '{')) {
$extra['text'] = tpl()->parse_string($extra['text'], $in['replace'], 'html_tip_auto__' . crc32($extra['text']));
}
if ($return_text || ($extra['return_text'] ?? null)) {
return $extra['text'];
}
$extra['icon'] = ($extra['icon'] ?? null) ?: ($tip['icon'] ?? null);
$extra['class_add'] = ($extra['class_add'] ?? null) ?: ($tip['class_add'] ?? null);
return html()->tooltip($extra['text'], $extra);
}
_ hooks and helpers; not routable as page actionspublic function __call($name, $args)
Catch missing method call.
public function __call($name, $args)
{
return main()->extend_call($this, $name, $args);
}
public function _action_on_block_denied($block_name = '')
Action to on denied block.
public function _action_on_block_denied($block_name = '')
{
return _class('core_blocks')->_action_on_block_denied($block_name);
}
public function _check_block_rights($block_id = 0, $OBJECT = '', $ACTION = '')
Check rights for blocks.
public function _check_block_rights($block_id = 0, $OBJECT = '', $ACTION = '')
{
return _class('core_blocks')->_check_block_rights($block_id, $OBJECT, $ACTION);
}
public function _generate_typos($params = [])
Generate typos for the given text.
public function _generate_typos($params = [])
{
return _class('graphics_typos', $this->SUB_MODULES_PATH)->get_all_with_stpl($params['text'], $params);
}
public function _get_center_block_id()
Try to find id of the center block.
public function _get_center_block_id()
{
return _class('core_blocks')->_get_center_block_id();
}
public function _init()
Framework constructor.
public function _init()
{
// Default user group
if (empty($_SESSION['user_group'])) {
$_SESSION['user_group'] = 1;
}
// Try to assign class properties from global settings
$add_title_pages = conf('add_title_pages');
if (isset($add_title_pages)) {
$this->ADD_TITLE_PAGES = $add_title_pages;
}
// Force hide inactive menu items inside admin section
if (MAIN_TYPE_ADMIN) {
$this->MENU_HIDE_INACTIVE_MODULES = true;
}
$this->MEDIA_PATH = WEB_PATH;
if (defined('MEDIA_PATH')) {
$this->MEDIA_PATH = MEDIA_PATH;
}
}
public function _load_blocks_rules()
Load array of blocks rules.
public function _load_blocks_rules()
{
return _class('core_blocks')->_load_blocks_rules();
}
public function _route_request()
Method that allows to change standard tasks mapping (if needed).
public function _route_request()
{
return _class('router')->_route_request();
}
public function _send_custom_http_headers()
public function _send_custom_http_headers()
{
// Override headers
$conf_headers = conf('http_headers');
if (is_array($conf_headers)) {
foreach ($conf_headers as $name => $value) {
$name = trim($name);
if ( ! $name) {
continue;
}
$value = str_replace(PHP_EOL, ' ', trim($value));
header($name . ': ' . $value, true);
}
}
}
public function _send_main_headers($content_length = 0)
Send main headers.
public function _send_main_headers($content_length = 0)
{
if (headers_sent($file, $line) || conf('no_headers')) {
return false;
}
if ($this->HEADER_POWERED_BY) {
header('X-Powered-By: YF');
}
header('Content-Type:text/html; charset=' . conf('charset'));
header('Content-language: ' . conf('language'));
if (tpl()->REWRITE_MODE && MAIN_TYPE_USER && ! main()->NO_CACHE_HEADERS) {
// To emulate static pages need these headers (Tells that page is modified only one time per day)
header('Last-Modified: ' . gmdate('D, d M Y 00:01:01') . ' GMT');
header('Content-Length: ' . (int) $content_length);
} else {
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0');
header('Pragma: no-cache'); // HTTP/1.0
}
$robots_no_index = (main()->is_ajax() || MAIN_TYPE_ADMIN || conf('ROBOTS_NO_INDEX') || DEBUG_MODE || (defined('DEVELOP') && DEVELOP) || (defined('TEST_MODE') && TEST_MODE));
if ($robots_no_index) {
header('X-Robots-Tag: noindex,nofollow,noarchive,nosnippet');
}
// We need this to make nginx cache correctly working
if ($uid = main()->USER_ID) {
header('X-Logged-In: 1');
header('X-Member-Id: ' . $uid);
}
// TODO: unify headers sending for 301, 302, 403, 404, also chech php_sapi_name() for strpos "cgi"
// http://stackoverflow.com/questions/3258634/php-how-to-send-http-response-code
$this->_send_custom_http_headers();
}
public function _set_se_keywords()
public function _set_se_keywords()
{
return false;
}
public function _show_block($input = [])
Show custom block contents.
public function _show_block($input = [])
{
return _class('core_blocks')->_show_block($input);
}
public function _show_bookmarks_button($title = '', $url = '', $only_links = 1)
Get html code for external bookmarking (Yahoo, Digg, etc).
public function _show_header()
Display header content (hook).
public function _show_header()
{
$obj = null;
if (conf('no_page_header')) {
return false;
}
$page_header = '';
$page_subheader = '';
// Display hook contents
// TODO: need to check permissions at first
// the module lookup was disabled upstream, so the hook never runs
$obj = null;
if (is_object($obj) && method_exists($obj, '_show_header')) {
$result = $obj->_show_header();
if (is_array($result)) {
$page_header = $result['header'];
$page_subheader = $result['subheader'];
} else {
return (string) $result;
}
}
// Show default header
if ( ! isset($page_header)) {
$page_header = _ucwords(str_replace('_', ' ', $_GET['object']));
}
if ( ! isset($page_subheader)) {
if (($_GET['action'] ?? null) != 'show') {
$page_subheader = _ucwords(str_replace('_', ' ', $_GET['action']));
}
}
$replace = [
'header' => $page_header ? t($page_header) : '',
'subheader' => $page_subheader ? t($page_subheader) : '',
];
return tpl()->parse('system/page_header', $replace);
}
public function _show_rss_button($feed_name = '', $feed_link = '', $only_links = 1)
Get html code for external bookmarking (Yahoo, Digg, etc).
public function _show_se_keywords($input = '')
public function _show_se_keywords($input = '')
{
return false;
}
public function _show_user_geo_block($params = [])
Display user geo location block.
public function _show_user_geo_block($params = [])
{
if ( ! main()->USE_GEO_IP) {
return false;
}
$geo_data = main()->_USER_GEO_DATA;
if (empty($geo_data)) {
return false;
}
$replace = [
'country_name' => _prepare_html($geo_data['country_name']),
'country_code_lower' => _escape_tpl_braces(strtolower($geo_data['country_code'])),
'region_code' => _prepare_html($geo_data['region_code']),
'region_name' => _prepare_html(_region_name($geo_data['region_code'], $geo_data['country_code'])),
'city_name' => _prepare_html($geo_data['city_name']),
'change_link' => './?object=geo_content&action=change_location',
];
return tpl()->parse('user_geo_block', $replace);
}