|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/** |
|
3
|
|
|
* **************************************************************************** |
|
4
|
|
|
* MYIFRAME - MODULE FOR XOOPS |
|
5
|
|
|
* Copyright (c) Hervé Thouzard of Instant Zero (http://www.instant-zero.com) |
|
6
|
|
|
* **************************************************************************** |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
if (!defined('XOOPS_ROOT_PATH')) { |
|
10
|
|
|
die('XOOPS root path not defined'); |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Returns a module's option |
|
15
|
|
|
* |
|
16
|
|
|
* Return's a module's option (for the myiframe module) |
|
17
|
|
|
* |
|
18
|
|
|
* @package Myiframe |
|
19
|
|
|
* @author Instant Zero (http://www.instant-zero.com) |
|
20
|
|
|
* @copyright Instant Zero (http://www.instant-zero.com) |
|
21
|
|
|
* @param string $option module option's name |
|
22
|
|
|
* @param string $repmodule |
|
23
|
|
|
* @return bool |
|
24
|
|
|
*/ |
|
25
|
|
|
function myiframe_getmoduleoption($option, $repmodule = 'myiframe') |
|
26
|
|
|
{ |
|
27
|
|
|
global $xoopsModuleConfig, $xoopsModule; |
|
|
|
|
|
|
28
|
|
|
static $tbloptions = []; |
|
29
|
|
|
if (is_array($tbloptions) && array_key_exists($option, $tbloptions)) { |
|
30
|
|
|
return $tbloptions[$option]; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
$retval = false; |
|
34
|
|
|
if (isset($xoopsModuleConfig) && (is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $repmodule && $xoopsModule->getVar('isactive'))) { |
|
35
|
|
|
if (isset($xoopsModuleConfig[$option])) { |
|
36
|
|
|
$retval = $xoopsModuleConfig[$option]; |
|
37
|
|
|
} |
|
38
|
|
|
} else { |
|
39
|
|
|
/** @var \XoopsModuleHandler $moduleHandler */ |
|
40
|
|
|
$moduleHandler = xoops_getHandler('module'); |
|
41
|
|
|
$module = $moduleHandler->getByDirname($repmodule); |
|
42
|
|
|
/** @var \XoopsConfigHandler $configHandler */ |
|
43
|
|
|
$configHandler = xoops_getHandler('config'); |
|
44
|
|
|
if ($module) { |
|
45
|
|
|
$moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
|
46
|
|
|
if (isset($moduleConfig[$option])) { |
|
47
|
|
|
$retval = $moduleConfig[$option]; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
$tbloptions[$option] = $retval; |
|
52
|
|
|
return $retval; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Verify that a field exists inside a mysql table |
|
57
|
|
|
* |
|
58
|
|
|
* @package Myiframe |
|
59
|
|
|
* @author Instant Zero (http://www.instant-zero.com) |
|
60
|
|
|
* @copyright Instant Zero (http://www.instant-zero.com) |
|
61
|
|
|
* @param $fieldname |
|
62
|
|
|
* @param $table |
|
63
|
|
|
* @return bool |
|
64
|
|
|
*/ |
|
65
|
|
|
function myiframe_FieldExists($fieldname, $table) |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
$result = $GLOBALS['xoopsDB']->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
|
68
|
|
|
return ($GLOBALS['xoopsDB']->getRowsNum($result) > 0); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Set the page's title, meta description and meta keywords |
|
73
|
|
|
* Datas are supposed to be sanitized |
|
74
|
|
|
* |
|
75
|
|
|
* @package Myiframe |
|
76
|
|
|
* @author Instant Zero http://www.instant-zero.com |
|
77
|
|
|
* @copyright (c) Instant Zero http://www.instant-zero.com |
|
78
|
|
|
* |
|
79
|
|
|
* @param string $page_title Page's Title |
|
80
|
|
|
* @param string $meta_description Page's meta description |
|
81
|
|
|
* @param string $meta_keywords Page's meta keywords |
|
82
|
|
|
* @return none |
|
|
|
|
|
|
83
|
|
|
*/ |
|
84
|
|
|
function myiframe_set_metas($page_title = '', $meta_description = '', $meta_keywords = '') |
|
85
|
|
|
{ |
|
86
|
|
|
global $xoTheme, $xoTheme, $xoopsTpl; |
|
|
|
|
|
|
87
|
|
|
$xoopsTpl->assign('xoops_pagetitle', $page_title); |
|
88
|
|
|
if (isset($xoTheme) && is_object($xoTheme)) { |
|
89
|
|
|
if (!empty($meta_keywords)) { |
|
90
|
|
|
$xoTheme->addMeta('meta', 'keywords', $meta_keywords); |
|
91
|
|
|
} |
|
92
|
|
|
if (!empty($meta_description)) { |
|
93
|
|
|
$xoTheme->addMeta('meta', 'description', $meta_description); |
|
94
|
|
|
} |
|
95
|
|
|
} elseif (isset($xoopsTpl) && is_object($xoopsTpl)) { // Compatibility for old Xoops versions |
|
96
|
|
|
if (!empty($meta_keywords)) { |
|
97
|
|
|
$xoopsTpl->assign('xoops_meta_keywords', $meta_keywords); |
|
98
|
|
|
} |
|
99
|
|
|
if (!empty($meta_description)) { |
|
100
|
|
|
$xoopsTpl->assign('xoops_meta_description', $meta_description); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.