XoopsModules25x /
about
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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 (http://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 | $page_handler = $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('page_id', 'page_menu_title', 'page_blank', |
||
| 38 | 'page_menu_status', 'page_status' |
||
| 39 | ); |
||
| 40 | $page_menu = $page_handler->getAll($menu_criteria, $fields, false); |
||
| 41 | foreach ($page_menu as $k => $v) { |
||
| 42 | $page_menu[$k]['links'] = $abtHelper->url("index.php?page_id={$v['page_id']}"); |
||
| 43 | } |
||
| 44 | |||
| 45 | return $page_menu; |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param $options |
||
| 50 | * @return array|bool |
||
| 51 | */ |
||
| 52 | function about_block_page_show($options) |
||
| 53 | { |
||
| 54 | if (empty($options[0])) { |
||
| 55 | return false; |
||
| 56 | } |
||
| 57 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 58 | $abtHelper = Xmf\Module\Helper::getHelper($moduleDirName); |
||
| 59 | |||
| 60 | $myts = MyTextSanitizer::getInstance(); |
||
| 61 | $block = array(); |
||
| 62 | $page_handler = $abtHelper->getHandler('page'); |
||
| 63 | $page = $page_handler->get($options[0]); |
||
| 64 | if (!is_object($page)) { |
||
| 65 | return false; |
||
| 66 | } |
||
| 67 | $page_text = strip_tags($page->getVar('page_text', 'n')); |
||
| 68 | if ($options[1] > 0) { |
||
| 69 | $url = $abtHelper->url("index.php?page_id={$options[0]}"); |
||
| 70 | $trimmarker = <<<EOF |
||
| 71 | <a href="{$url}" class="more">{$options[2]}</a> |
||
| 72 | EOF; |
||
| 73 | $page_text = xoops_substr($page_text, 0, $options[1]) . $trimmarker; |
||
| 74 | } |
||
| 75 | |||
| 76 | $block['page_text'] = $myts->nl2br($page_text); |
||
| 77 | $block['page_image'] = $options[3] == 1 ? $abtHelper->url($page->getVar('page_image', 's')) : ''; |
||
| 78 | |||
| 79 | return $block; |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @param $options |
||
| 84 | * @return string |
||
| 85 | */ |
||
| 86 | function about_block_page_edit($options) |
||
| 87 | { |
||
| 88 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 89 | $abtHelper = Xmf\Module\Helper::getHelper($moduleDirName); |
||
| 90 | xoops_load('constants', $moduleDirName); |
||
| 91 | |||
| 92 | $abtHelper->loadLanguage('blocks'); |
||
| 93 | $page_handler = $abtHelper->getHandler('page'); |
||
| 94 | $criteria = new CriteriaCompo(); |
||
| 95 | $criteria->add(new Criteria('page_status', AboutConstants::PUBLISHED), 'AND'); |
||
| 96 | $criteria->add(new Criteria('page_type', AboutConstants::PAGE_TYPE_PAGE)); |
||
| 97 | $criteria->setSort('page_order'); |
||
| 98 | $criteria->order = 'ASC'; |
||
| 99 | $fields = array('page_id', 'page_title', 'page_image'); |
||
| 100 | $pages = $page_handler->getAll($criteria, $fields, false); |
||
| 101 | $page_title = ''; |
||
| 102 | foreach ($pages as $k => $v) { |
||
| 103 | $page_title = '<a href="' . $abtHelper->url("index.php?page_id={$k}") . '" target="_blank">' . $v['page_title'] . '</a>'; |
||
| 104 | $options_page[$k] = empty($v['page_image']) ? $page_title : $page_title . '<img src="' . $abtHelper->url("assets/images/picture.png") . '">'; |
||
|
0 ignored issues
–
show
|
|||
| 105 | } |
||
| 106 | // include_once dirname(__DIR__) . '/include/xoopsformloader.php'; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
50% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 107 | xoops_load('blockform', $moduleDirName); |
||
| 108 | $form = new AboutBlockForm(); |
||
| 109 | $page_select = new XoopsFormRadio(_MB_ABOUT_BLOCKPAGE, 'options[0]', $options[0], '<br>'); |
||
| 110 | $page_select->addOptionArray($options_page); |
||
| 111 | $form->addElement($page_select); |
||
| 112 | $form->addElement(new XoopsFormText(_MB_ABOUT_TEXT_LENGTH, 'options[1]', 5, 5, $options[1])); |
||
| 113 | $form->addElement(new XoopsFormText(_MB_ABOUT_VIEW_MORELINKTEXT, 'options[2]', 30, 50, $options[2])); |
||
| 114 | $form->addElement(new XoopsFormRadioYN(_MB_ABOUT_DOTITLEIMAGE, 'options[3]', $options[3])); |
||
| 115 | |||
| 116 | return $form->render(); |
||
| 117 | } |
||
| 118 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.