|
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 2 module for xoops |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright 2020 XOOPS Project (https://xooops.org) |
|
16
|
|
|
* @license GPL 2.0 or later |
|
17
|
|
|
* @package mymodule2 |
|
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\Mymodule2; |
|
24
|
|
|
use XoopsModules\Mymodule2\Helper; |
|
25
|
|
|
use XoopsModules\Mymodule2\Constants; |
|
26
|
|
|
|
|
27
|
|
|
include_once XOOPS_ROOT_PATH.'/modules/mymodule2/include/common.php'; |
|
28
|
|
|
// Function show block |
|
29
|
|
|
function b_mymodule2_articles_show($options) |
|
30
|
|
|
{ |
|
31
|
|
|
include_once XOOPS_ROOT_PATH.'/modules/mymodule2/class/articles.php'; |
|
32
|
|
|
$myts = MyTextSanitizer::getInstance(); |
|
33
|
|
|
$GLOBALS['xoopsTpl']->assign('mymodule2_upload_url', MYMODULE2_UPLOAD_URL); |
|
34
|
|
|
$block = array(); |
|
35
|
|
|
$typeBlock = $options[0]; |
|
36
|
|
|
$limit = $options[1]; |
|
37
|
|
|
$lenghtTitle = $options[2]; |
|
|
|
|
|
|
38
|
|
|
$helper = Helper::getInstance(); |
|
39
|
|
|
$articlesHandler = $helper->getHandler('articles'); |
|
40
|
|
|
$criteria = new \CriteriaCompo(); |
|
41
|
|
|
array_shift($options); |
|
42
|
|
|
array_shift($options); |
|
43
|
|
|
array_shift($options); |
|
44
|
|
|
switch($typeBlock) |
|
45
|
|
|
{ |
|
46
|
|
|
// For the block: articles last |
|
47
|
|
|
case 'last': |
|
48
|
|
|
//$criteria->add(new \Criteria('art_display', 1)); |
|
49
|
|
|
$criteria->setSort('art_created'); |
|
50
|
|
|
$criteria->setOrder('DESC'); |
|
51
|
|
|
break; |
|
52
|
|
|
// For the block: articles new |
|
53
|
|
|
case 'new': |
|
54
|
|
|
//$criteria->add(new \Criteria('art_display', 1)); |
|
55
|
|
|
$criteria->add(new \Criteria('art_created', strtotime(date(_SHORTDATESTRING)), '>=')); |
|
56
|
|
|
$criteria->add(new \Criteria('art_created', strtotime(date(_SHORTDATESTRING))+86400, '<=')); |
|
57
|
|
|
$criteria->setSort('art_created'); |
|
58
|
|
|
$criteria->setOrder('ASC'); |
|
59
|
|
|
break; |
|
60
|
|
|
// For the block: articles hits |
|
61
|
|
|
case 'hits': |
|
62
|
|
|
$criteria->setSort('art_hits'); |
|
63
|
|
|
$criteria->setOrder('DESC'); |
|
64
|
|
|
break; |
|
65
|
|
|
// For the block: articles top |
|
66
|
|
|
case 'top': |
|
67
|
|
|
$criteria->setSort('art_top'); |
|
68
|
|
|
$criteria->setOrder('ASC'); |
|
69
|
|
|
break; |
|
70
|
|
|
// For the block: articles random |
|
71
|
|
|
case 'random': |
|
72
|
|
|
//$criteria->add(new \Criteria('art_display', 1)); |
|
73
|
|
|
$criteria->setSort('RAND()'); |
|
74
|
|
|
break; |
|
75
|
|
|
} |
|
76
|
|
|
$criteria->setLimit($limit); |
|
77
|
|
|
$articlesAll = $articlesHandler->getAll($criteria); |
|
|
|
|
|
|
78
|
|
|
unset($criteria); |
|
79
|
|
|
if (count($articlesAll) > 0) { |
|
80
|
|
|
foreach(array_keys($articlesAll) as $i) |
|
81
|
|
|
{ |
|
82
|
|
|
$block[$i]['cat'] = $articlesAll[$i]->getVar('art_cat'); |
|
83
|
|
|
$block[$i]['title'] = $myts->htmlSpecialChars($articlesAll[$i]->getVar('art_title')); |
|
84
|
|
|
$block[$i]['descr'] = strip_tags($articlesAll[$i]->getVar('art_descr')); |
|
85
|
|
|
$block[$i]['img'] = $articlesAll[$i]->getVar('art_img'); |
|
86
|
|
|
$block[$i]['file'] = $articlesAll[$i]->getVar('art_file'); |
|
87
|
|
|
$block[$i]['created'] = formatTimeStamp($articlesAll[$i]->getVar('art_created')); |
|
88
|
|
|
$block[$i]['submitter'] = \XoopsUser::getUnameFromId($articlesAll[$i]->getVar('art_submitter')); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
return $block; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
// Function edit block |
|
95
|
|
|
function b_mymodule2_articles_edit($options) |
|
96
|
|
|
{ |
|
97
|
|
|
include_once XOOPS_ROOT_PATH.'/modules/mymodule2/class/articles.php'; |
|
98
|
|
|
$helper = Helper::getInstance(); |
|
99
|
|
|
$articlesHandler = $helper->getHandler('articles'); |
|
100
|
|
|
$GLOBALS['xoopsTpl']->assign('mymodule2_upload_url', MYMODULE2_UPLOAD_URL); |
|
101
|
|
|
$form = _MB_MYMODULE2_DISPLAY; |
|
102
|
|
|
$form .= "<input type='hidden' name='options[0]' value='".$options[0]."' />"; |
|
103
|
|
|
$form .= "<input type='text' name='options[1]' size='5' maxlength='255' value='" . $options[1] . "' /> <br>"; |
|
104
|
|
|
$form .= _MB_MYMODULE2_TITLE_LENGTH." : <input type='text' name='options[2]' size='5' maxlength='255' value='" . $options[2] . "' /><br><br>"; |
|
105
|
|
|
array_shift($options); |
|
106
|
|
|
array_shift($options); |
|
107
|
|
|
array_shift($options); |
|
108
|
|
|
$criteria = new \CriteriaCompo(); |
|
109
|
|
|
$criteria->add(new \Criteria('art_id', 0, '!=')); |
|
110
|
|
|
$criteria->setSort('art_id'); |
|
111
|
|
|
$criteria->setOrder('ASC'); |
|
112
|
|
|
$articlesAll = $articlesHandler->getAll($criteria); |
|
113
|
|
|
unset($criteria); |
|
114
|
|
|
$form .= _MB_MYMODULE2_ARTICLES_TO_DISPLAY."<br><select name='options[]' multiple='multiple' size='5'>"; |
|
115
|
|
|
$form .= "<option value='0' " . (in_array(0, $options) === false ? '' : "selected='selected'") . '>' . _MB_MYMODULE2_ALL_ARTICLES . '</option>'; |
|
116
|
|
|
foreach (array_keys($articlesAll) as $i) { |
|
117
|
|
|
$art_id = $articlesAll[$i]->getVar('art_id'); |
|
118
|
|
|
$form .= "<option value='" . $art_id . "' " . (in_array($art_id, $options) === false ? '' : "selected='selected'") . '>' . $articlesAll[$i]->getVar('art_title') . '</option>'; |
|
119
|
|
|
} |
|
120
|
|
|
$form .= '</select>'; |
|
121
|
|
|
return $form; |
|
122
|
|
|
} |