|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* My Module 3 module for xoops |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright 2020 XOOPS Project (https://xooops.org) |
|
16
|
|
|
* @license GPL 2.0 or later |
|
17
|
|
|
* @package mymodule3 |
|
18
|
|
|
* @since 1.0 |
|
19
|
|
|
* @min_xoops 2.5.9 |
|
20
|
|
|
* @author TDM XOOPS - Email:<[email protected]> - Website:<http://xoops.org> |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
use XoopsModules\Mymodule3; |
|
24
|
|
|
use XoopsModules\Mymodule3\Helper; |
|
25
|
|
|
use XoopsModules\Mymodule3\Constants; |
|
26
|
|
|
|
|
27
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/mymodule3/include/common.php'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Function show block |
|
31
|
|
|
* @param $options |
|
32
|
|
|
* @return array |
|
33
|
|
|
*/ |
|
34
|
|
|
function b_mymodule3_articles_show($options) |
|
35
|
|
|
{ |
|
36
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/mymodule3/class/articles.php'; |
|
37
|
|
|
$myts = MyTextSanitizer::getInstance(); |
|
38
|
|
|
$GLOBALS['xoopsTpl']->assign('mymodule3_upload_url', MYMODULE3_UPLOAD_URL); |
|
39
|
|
|
$block = []; |
|
40
|
|
|
$typeBlock = $options[0]; |
|
41
|
|
|
$limit = $options[1]; |
|
42
|
|
|
$lenghtTitle = $options[2]; |
|
|
|
|
|
|
43
|
|
|
$helper = Helper::getInstance(); |
|
44
|
|
|
$articlesHandler = $helper->getHandler('articles'); |
|
45
|
|
|
$crArticles = new \CriteriaCompo(); |
|
46
|
|
|
array_shift($options); |
|
47
|
|
|
array_shift($options); |
|
48
|
|
|
array_shift($options); |
|
49
|
|
|
|
|
50
|
|
|
switch($typeBlock) { |
|
51
|
|
|
case 'last': |
|
52
|
|
|
default: |
|
53
|
|
|
// For the block: articles last |
|
54
|
|
|
$crArticles->setSort( 'art_date' ); |
|
55
|
|
|
$crArticles->setOrder( 'DESC' ); |
|
56
|
|
|
break; |
|
57
|
|
|
case 'new': |
|
58
|
|
|
// For the block: articles new |
|
59
|
|
|
$crArticles->add( new \Criteria( 'art_date', strtotime(date(_SHORTDATESTRING)), '>=' ) ); |
|
60
|
|
|
$crArticles->add( new \Criteria( 'art_date', strtotime(date(_SHORTDATESTRING))+86400, '<=' ) ); |
|
61
|
|
|
$crArticles->setSort( 'art_date' ); |
|
62
|
|
|
$crArticles->setOrder( 'ASC' ); |
|
63
|
|
|
break; |
|
64
|
|
|
case 'hits': |
|
65
|
|
|
// For the block: articles hits |
|
66
|
|
|
$crArticles->setSort( 'art_hits' ); |
|
67
|
|
|
$crArticles->setOrder( 'DESC' ); |
|
68
|
|
|
break; |
|
69
|
|
|
case 'top': |
|
70
|
|
|
// For the block: articles top |
|
71
|
|
|
$crArticles->add( new \Criteria( 'art_date', strtotime(date(_SHORTDATESTRING))+86400, '<=' ) ); |
|
72
|
|
|
$crArticles->setSort( 'art_top' ); |
|
73
|
|
|
$crArticles->setOrder( 'ASC' ); |
|
74
|
|
|
break; |
|
75
|
|
|
case 'random': |
|
76
|
|
|
// For the block: articles random |
|
77
|
|
|
$crArticles->add( new \Criteria( 'art_date', strtotime(date(_SHORTDATESTRING))+86400, '<=' ) ); |
|
78
|
|
|
$crArticles->setSort( 'RAND()' ); |
|
79
|
|
|
break; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$crArticles->setLimit( $limit ); |
|
83
|
|
|
$articlesAll = $articlesHandler->getAll($crArticles); |
|
|
|
|
|
|
84
|
|
|
unset($crArticles); |
|
85
|
|
|
if (count($articlesAll) > 0) { |
|
86
|
|
|
foreach(array_keys($articlesAll) as $i) { |
|
87
|
|
|
$block[$i]['cat'] = $articlesAll[$i]->getVar('art_cat'); |
|
88
|
|
|
$block[$i]['title'] = $myts->htmlSpecialChars($articlesAll[$i]->getVar('art_title')); |
|
89
|
|
|
$block[$i]['descr'] = strip_tags($articlesAll[$i]->getVar('art_descr')); |
|
90
|
|
|
$block[$i]['img'] = $articlesAll[$i]->getVar('art_img'); |
|
91
|
|
|
$block[$i]['file'] = $articlesAll[$i]->getVar('art_file'); |
|
92
|
|
|
$block[$i]['created'] = formatTimeStamp($articlesAll[$i]->getVar('art_created')); |
|
93
|
|
|
$block[$i]['submitter'] = \XoopsUser::getUnameFromId($articlesAll[$i]->getVar('art_submitter')); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return $block; |
|
98
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Function edit block |
|
103
|
|
|
* @param $options |
|
104
|
|
|
* @return string |
|
105
|
|
|
*/ |
|
106
|
|
|
function b_mymodule3_articles_edit($options) |
|
107
|
|
|
{ |
|
108
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/mymodule3/class/articles.php'; |
|
109
|
|
|
$helper = Helper::getInstance(); |
|
110
|
|
|
$articlesHandler = $helper->getHandler('articles'); |
|
111
|
|
|
$GLOBALS['xoopsTpl']->assign('mymodule3_upload_url', MYMODULE3_UPLOAD_URL); |
|
112
|
|
|
$form = _MB_MYMODULE3_DISPLAY; |
|
113
|
|
|
$form .= "<input type='hidden' name='options[0]' value='".$options[0]."' />"; |
|
114
|
|
|
$form .= "<input type='text' name='options[1]' size='5' maxlength='255' value='" . $options[1] . "' /> <br>"; |
|
115
|
|
|
$form .= _MB_MYMODULE3_TITLE_LENGTH . " : <input type='text' name='options[2]' size='5' maxlength='255' value='" . $options[2] . "' /><br><br>"; |
|
116
|
|
|
array_shift($options); |
|
117
|
|
|
array_shift($options); |
|
118
|
|
|
array_shift($options); |
|
119
|
|
|
|
|
120
|
|
|
$crArticles = new \CriteriaCompo(); |
|
121
|
|
|
$crArticles->add( new \Criteria( 'art_id', 0, '!=' ) ); |
|
122
|
|
|
$crArticles->setSort( 'art_id' ); |
|
123
|
|
|
$crArticles->setOrder( 'ASC' ); |
|
124
|
|
|
$articlesAll = $articlesHandler->getAll($crArticles); |
|
125
|
|
|
unset($crArticles); |
|
126
|
|
|
$form .= _MB_MYMODULE3_ARTICLES_TO_DISPLAY . "<br><select name='options[]' multiple='multiple' size='5'>"; |
|
127
|
|
|
$form .= "<option value='0' " . (in_array(0, $options) == false ? '' : "selected='selected'") . '>' . _MB_MYMODULE3_ALL_ARTICLES . '</option>'; |
|
|
|
|
|
|
128
|
|
|
foreach(array_keys($articlesAll) as $i) { |
|
129
|
|
|
$art_id = $articlesAll[$i]->getVar('art_id'); |
|
130
|
|
|
$form .= "<option value='" . $art_id . "' " . (in_array($art_id, $options) == false ? '' : "selected='selected'") . '>' . $articlesAll[$i]->getVar('art_title') . '</option>'; |
|
|
|
|
|
|
131
|
|
|
} |
|
132
|
|
|
$form .= '</select>'; |
|
133
|
|
|
|
|
134
|
|
|
return $form; |
|
135
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|