1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* About |
4
|
|
|
* |
5
|
|
|
* You may not change or alter any portion of this comment or credits |
6
|
|
|
* of supporting developers from this source code or any supporting source code |
7
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
8
|
|
|
* This program is distributed in the hope that it will be useful, |
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
* |
12
|
|
|
* @copyright The XOOPS Co.Ltd. http://www.xoops.com.cn |
13
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
14
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
15
|
|
|
* @package about |
16
|
|
|
* @since 1.0.0 |
17
|
|
|
* @author Mengjue Shao <[email protected]> |
18
|
|
|
* @author Susheng Yang <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
22
|
|
|
/** |
23
|
|
|
* @return mixed |
24
|
|
|
*/ |
25
|
|
|
function about_block_menu_show() |
26
|
|
|
{ |
27
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
28
|
|
|
xoops_load('constants', $moduleDirName); |
29
|
|
|
|
30
|
|
|
$abtHelper = Xmf\Module\Helper::getHelper($moduleDirName); |
31
|
|
|
$pageHandler = $abtHelper->getHandler('page'); |
32
|
|
|
$menu_criteria = new CriteriaCompo(); |
33
|
|
|
$menu_criteria->add(new Criteria('page_status', AboutConstants::PUBLISHED), 'AND'); |
34
|
|
|
$menu_criteria->add(new Criteria('page_menu_status', AboutConstants::IN_MENU)); |
35
|
|
|
$menu_criteria->setSort('page_order'); |
36
|
|
|
$menu_criteria->order = 'ASC'; |
37
|
|
|
$fields = array( |
38
|
|
|
'page_id', |
39
|
|
|
'page_menu_title', |
40
|
|
|
'page_blank', |
41
|
|
|
'page_menu_status', |
42
|
|
|
'page_status' |
43
|
|
|
); |
44
|
|
|
$page_menu = $pageHandler->getAll($menu_criteria, $fields, false); |
45
|
|
|
foreach ($page_menu as $k => $v) { |
46
|
|
|
$page_menu[$k]['links'] = $abtHelper->url("index.php?page_id={$v['page_id']}"); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $page_menu; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param $options |
54
|
|
|
* @return array|bool |
55
|
|
|
*/ |
56
|
|
|
function about_block_page_show($options) |
57
|
|
|
{ |
58
|
|
|
if (empty($options[0])) { |
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
62
|
|
|
$abtHelper = Xmf\Module\Helper::getHelper($moduleDirName); |
63
|
|
|
|
64
|
|
|
$myts = MyTextSanitizer::getInstance(); |
65
|
|
|
$block = array(); |
66
|
|
|
$pageHandler = $abtHelper->getHandler('page'); |
67
|
|
|
$page = $pageHandler->get($options[0]); |
68
|
|
|
if (!is_object($page)) { |
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
$page_text = strip_tags($page->getVar('page_text', 'n')); |
72
|
|
|
if ($options[1] > 0) { |
73
|
|
|
$url = $abtHelper->url("index.php?page_id={$options[0]}"); |
74
|
|
|
$trimmarker = <<<EOF |
75
|
|
|
<a href="{$url}" class="more">{$options[2]}</a> |
76
|
|
|
EOF; |
77
|
|
|
$page_text = xoops_substr($page_text, 0, $options[1]) . $trimmarker; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$block['page_text'] = $myts->nl2br($page_text); |
81
|
|
|
$block['page_image'] = $options[3] == 1 ? $abtHelper->url($page->getVar('page_image', 's')) : ''; |
82
|
|
|
|
83
|
|
|
return $block; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param $options |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
function about_block_page_edit($options) |
91
|
|
|
{ |
92
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
93
|
|
|
$abtHelper = Xmf\Module\Helper::getHelper($moduleDirName); |
94
|
|
|
xoops_load('constants', $moduleDirName); |
95
|
|
|
|
96
|
|
|
$abtHelper->loadLanguage('blocks'); |
97
|
|
|
$pageHandler = $abtHelper->getHandler('page'); |
98
|
|
|
$criteria = new CriteriaCompo(); |
99
|
|
|
$criteria->add(new Criteria('page_status', AboutConstants::PUBLISHED), 'AND'); |
100
|
|
|
$criteria->add(new Criteria('page_type', AboutConstants::PAGE_TYPE_PAGE)); |
101
|
|
|
$criteria->setSort('page_order'); |
102
|
|
|
$criteria->order = 'ASC'; |
103
|
|
|
$fields = array('page_id', 'page_title', 'page_image'); |
104
|
|
|
$pages = $pageHandler->getAll($criteria, $fields, false); |
105
|
|
|
$page_title = ''; |
|
|
|
|
106
|
|
|
foreach ($pages as $k => $v) { |
107
|
|
|
$page_title = '<a href="' . $abtHelper->url("index.php?page_id={$k}") . '" target="_blank">' . $v['page_title'] . '</a>'; |
108
|
|
|
$options_page[$k] = empty($v['page_image']) ? $page_title : $page_title . '<img src="' . $abtHelper->url('assets/images/picture.png') . '">'; |
|
|
|
|
109
|
|
|
} |
110
|
|
|
// include_once dirname(__DIR__) . '/include/xoopsformloader.php'; |
|
|
|
|
111
|
|
|
xoops_load('blockform', $moduleDirName); |
112
|
|
|
$form = new AboutBlockForm(); |
113
|
|
|
$page_select = new XoopsFormRadio(_MB_ABOUT_BLOCKPAGE, 'options[0]', $options[0], '<br>'); |
114
|
|
|
$page_select->addOptionArray($options_page); |
|
|
|
|
115
|
|
|
$form->addElement($page_select); |
116
|
|
|
$form->addElement(new XoopsFormText(_MB_ABOUT_TEXT_LENGTH, 'options[1]', 5, 5, $options[1])); |
117
|
|
|
$form->addElement(new XoopsFormText(_MB_ABOUT_VIEW_MORELINKTEXT, 'options[2]', 30, 50, $options[2])); |
118
|
|
|
$form->addElement(new XoopsFormRadioYN(_MB_ABOUT_DOTITLEIMAGE, 'options[3]', $options[3])); |
119
|
|
|
|
120
|
|
|
return $form->render(); |
121
|
|
|
} |
122
|
|
|
|
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.