XoopsModules25x /
news
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
|
0 ignored issues
–
show
|
|||
| 2 | // |
||
| 3 | // ------------------------------------------------------------------------ // |
||
| 4 | // XOOPS - PHP Content Management System // |
||
| 5 | // Copyright (c) 2000-2016 XOOPS.org // |
||
| 6 | // <http://xoops.org/> // |
||
| 7 | // ------------------------------------------------------------------------- // |
||
| 8 | // This program is free software; you can redistribute it and/or modify // |
||
| 9 | // it under the terms of the GNU General Public License as published by // |
||
| 10 | // the Free Software Foundation; either version 2 of the License, or // |
||
| 11 | // (at your option) any later version. // |
||
| 12 | // // |
||
| 13 | // You may not change or alter any portion of this comment or credits // |
||
| 14 | // of supporting developers from this source code or any supporting // |
||
| 15 | // source code which is considered copyrighted (c) material of the // |
||
| 16 | // original comment or credit authors. // |
||
| 17 | // // |
||
| 18 | // This program is distributed in the hope that it will be useful, // |
||
| 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
||
| 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
||
| 21 | // GNU General Public License for more details. // |
||
| 22 | // // |
||
| 23 | // You should have received a copy of the GNU General Public License // |
||
| 24 | // along with this program; if not, write to the Free Software // |
||
| 25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
||
| 26 | // ------------------------------------------------------------------------ // |
||
| 27 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
||
| 28 | |||
| 29 | include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param $options |
||
| 33 | * |
||
| 34 | * @return array |
||
| 35 | */ |
||
| 36 | function b_news_randomnews_show($options) |
||
| 37 | { |
||
| 38 | include_once XOOPS_ROOT_PATH . '/modules/news/include/functions.php'; |
||
| 39 | $myts = MyTextSanitizer::getInstance(); |
||
| 40 | $block = array(); |
||
| 41 | $block['sort'] = $options[0]; |
||
| 42 | |||
| 43 | $tmpstory = new NewsStory; |
||
| 44 | $restricted = news_getmoduleoption('restrictindex'); |
||
| 45 | $dateformat = news_getmoduleoption('dateformat'); |
||
| 46 | $infotips = news_getmoduleoption('infotips'); |
||
| 47 | if ($dateformat == '') { |
||
| 48 | $dateformat = 's'; |
||
| 49 | } |
||
| 50 | if ($options[4] == 0) { |
||
| 51 | $stories = $tmpstory->getRandomNews($options[1], 0, $restricted, 0, 1, $options[0]); |
||
| 52 | } else { |
||
| 53 | $topics = array_slice($options, 4); |
||
| 54 | $stories = $tmpstory->getRandomNews($options[1], 0, $restricted, $topics, 1, $options[0]); |
||
| 55 | } |
||
| 56 | unset($tmpstory); |
||
| 57 | if (count($stories) == 0) { |
||
| 58 | return ''; |
||
| 59 | } |
||
| 60 | foreach ($stories as $story) { |
||
| 61 | $news = array(); |
||
| 62 | $title = $story->title(); |
||
| 63 | View Code Duplication | if (strlen($title) > $options[2]) { |
|
| 64 | $title = xoops_substr($title, 0, $options[2] + 3); |
||
| 65 | } |
||
| 66 | $news['title'] = $title; |
||
| 67 | $news['id'] = $story->storyid(); |
||
| 68 | $news['date'] = formatTimestamp($story->published(), $dateformat); |
||
| 69 | $news['hits'] = $story->counter(); |
||
| 70 | $news['rating'] = $story->rating(); |
||
| 71 | $news['votes'] = $story->votes(); |
||
| 72 | $news['author'] = sprintf('%s %s', _POSTEDBY, $story->uname()); |
||
| 73 | $news['topic_title'] = $story->topic_title(); |
||
| 74 | $news['topic_color'] = '#' . $myts->displayTarea($story->topic_color); |
||
| 75 | $news['picture'] = XOOPS_URL . '/uploads/news/image/' . $story->picture(); |
||
| 76 | $news['pictureinfo'] = $story->pictureinfo(); |
||
| 77 | |||
| 78 | if ($options[3] > 0) { |
||
| 79 | $html = $story->nohtml() == 1 ? 0 : 1; |
||
| 80 | $news['teaser'] = news_truncate_tagsafe($myts->displayTarea($story->hometext, $html), $options[3] + 3); |
||
| 81 | $news['infotips'] = ' title="' . $story->title() . '"'; |
||
| 82 | View Code Duplication | } else { |
|
| 83 | $news['teaser'] = ''; |
||
| 84 | if ($infotips > 0) { |
||
| 85 | $news['infotips'] = ' title="' . news_make_infotips($story->hometext()) . '"'; |
||
| 86 | } else { |
||
| 87 | $news['infotips'] = ' title="' . $story->title() . '"'; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | $block['stories'][] = $news; |
||
| 91 | } |
||
| 92 | $block['lang_read_more'] = _MB_READMORE; |
||
| 93 | |||
| 94 | return $block; |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @param $options |
||
| 99 | * |
||
| 100 | * @return string |
||
| 101 | */ |
||
| 102 | function b_news_randomnews_edit($options) |
||
| 103 | { |
||
| 104 | global $xoopsDB; |
||
| 105 | $form = _MB_NEWS_ORDER . " <select name='options[]'>"; |
||
| 106 | $form .= "<option value='published'"; |
||
| 107 | if ($options[0] === 'published') { |
||
| 108 | $form .= " selected='selected'"; |
||
| 109 | } |
||
| 110 | $form .= '>' . _MB_NEWS_DATE . "</option>\n"; |
||
| 111 | |||
| 112 | $form .= "<option value='counter'"; |
||
| 113 | if ($options[0] === 'counter') { |
||
| 114 | $form .= " selected='selected'"; |
||
| 115 | } |
||
| 116 | $form .= '>' . _MB_NEWS_HITS . '</option>'; |
||
| 117 | |||
| 118 | $form .= "<option value='rating'"; |
||
| 119 | if ($options[0] === 'rating') { |
||
| 120 | $form .= " selected='selected'"; |
||
| 121 | } |
||
| 122 | $form .= '>' . _MB_NEWS_RATE . '</option>'; |
||
| 123 | |||
| 124 | $form .= "</select>\n"; |
||
| 125 | $form .= ' ' . _MB_NEWS_DISP . " <input type='text' name='options[]' value='" . $options[1] . "'/> " . _MB_NEWS_ARTCLS; |
||
| 126 | $form .= ' <br><br />' . _MB_NEWS_CHARS . " <input type='text' name='options[]' value='" . $options[2] . "'/> " . _MB_NEWS_LENGTH . '<br /><br />'; |
||
| 127 | |||
| 128 | $form .= _MB_NEWS_TEASER . " <input type='text' name='options[]' value='" . $options[3] . "' />" . _MB_NEWS_LENGTH; |
||
| 129 | $form .= '<br /><br />' . _MB_SPOTLIGHT_TOPIC . "<br /><select id='options[4]' name='options[]' multiple='multiple'>"; |
||
| 130 | |||
| 131 | include_once XOOPS_ROOT_PATH . '/modules/news/class/xoopsstory.php'; |
||
| 132 | $xt = new MyXoopsTopic($xoopsDB->prefix('news_topics')); |
||
| 133 | $alltopics = $xt->getTopicsList(); |
||
| 134 | $alltopics[0]['title'] = _MB_SPOTLIGHT_ALL_TOPICS; |
||
| 135 | ksort($alltopics); |
||
| 136 | $size = count($options); |
||
| 137 | foreach ($alltopics as $topicid => $topic) { |
||
| 138 | $sel = ''; |
||
| 139 | for ($i = 4; $i < $size; ++$i) { |
||
| 140 | if ($options[$i] == $topicid) { |
||
| 141 | $sel = " selected='selected'"; |
||
| 142 | } |
||
| 143 | } |
||
| 144 | $form .= "<option value='$topicid'$sel>" . $topic['title'] . '</option>'; |
||
| 145 | } |
||
| 146 | $form .= '</select><br />'; |
||
| 147 | |||
| 148 | return $form; |
||
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @param $options |
||
| 153 | */ |
||
| 154 | View Code Duplication | function b_news_randomnews_onthefly($options) |
|
| 155 | { |
||
| 156 | $options = explode('|', $options); |
||
| 157 | $block = &b_news_randomnews_show($options); |
||
| 158 | |||
| 159 | $tpl = new XoopsTpl(); |
||
| 160 | $tpl->assign('block', $block); |
||
| 161 | $tpl->display('db:news_block_moderate.tpl'); |
||
| 162 | } |
||
| 163 |
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.