-
Notifications
You must be signed in to change notification settings - Fork 1
/
ajax.php
executable file
·173 lines (151 loc) · 7 KB
/
ajax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* News index file
*
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @author Hossein Azizabadi (AKA Voltan)
* @version $Id$
*/
// Include module header
require dirname(__FILE__) . '/header.php';
error_reporting(0);
$GLOBALS['xoopsLogger']->activated = false;
// Set option
$op = NewsUtils::NewsUtilityCleanVars($_REQUEST, 'op', '', 'string');
if (!empty($op)) {
switch ($op) {
// Get last story as json
case 'liststory':
case 'story':
$story_infos = [];
$story_infos['topics'] = $topic_handler->getAll();
$story_infos['story_start'] = NewsUtils::NewsUtilityCleanVars($_REQUEST, 'start', 0, 'int');
$story_infos['story_topic'] = NewsUtils::NewsUtilityCleanVars($_REQUEST, 'storytopic', 0, 'int');
$story_infos['story_limit'] = NewsUtils::NewsUtilityCleanVars($_REQUEST, 'limit', 10, 'int');
$story_infos['story_type'] = NewsUtils::NewsUtilityCleanVars($_REQUEST, 'storytype', '', 'string');
$return = $story_handler->NewsStoryJson($story_infos);
break;
// Get single story as json
case 'singlestory':
$ret = [];
$story_id = NewsUtils::NewsUtilityCleanVars($_REQUEST, 'storyid', 0, 'int');
$obj = $story_handler->get($story_id);
$story = $obj->toArray();
// Update content hits
$story_handler->NewsStoryUpdateHits($story_id);
$json['story_id'] = $story['story_id'];
$json['story_alias'] = $story['story_alias'];
$json['story_publish'] = $story['story_publish'];
$json['story_topic'] = $story['story_topic'];
$json['story_img'] = $story['story_img'];
$json['story_hits'] = $story['story_hits'];
if ($story['story_topic'] > 0) {
$topicObj = $topic_handler->get($story['story_topic']);
$json['story_topic_title'] = $topicObj->getVar('topic_title');
} else {
$json['story_topic_title'] = '';
}
$text = $story['story_title'];
$text = strip_tags($text);
//$text = preg_replace("`\[.*\]`U", "", $text);
$text = preg_replace('`&(amp;)?#?[a-z0-9]+;`i', '', $text);
$text = htmlentities($text, ENT_COMPAT, 'utf-8');
$text = preg_replace("`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i", "\\1", $text);
$text = stripslashes($text);
$json['story_title'] = $text;
$text = $story['story_short'] . ' ' . $story['story_text'];
$text = strip_tags($text, '<br /><br>');
$text = preg_replace('#<br\s*/?>#i', "\n", $text);
//$text = preg_replace("`\[.*\]`U", "", $text);
$text = preg_replace('`&(amp;)?#?[a-z0-9]+;`i', "'", $text);
$text = htmlentities($text, ENT_COMPAT, 'utf-8');
$text = preg_replace("`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i", "\\1", $text);
$text = stripslashes($text);
$json['story_body'] = $text;
if ($story['story_file'] > 0) {
$fileInfo = [];
$fileInfo['order'] = 'DESC';
$fileInfo['sort'] = 'file_id';
$fileInfo['start'] = 0;
$fileInfo['content'] = $story['story_id'];
$allfile = $file_handler->NewsFileList($fileInfo);
foreach ($allfile as $myfile) {
if ($myfile['file_type'] == 'mp4') {
$json['story_video'] = $myfile['fileurl'];
} elseif ($myfile['file_type'] == 'mp3') {
$json['story_audio'] = $myfile['fileurl'];
}
}
}
$ret[] = $json;
$return = json_encode($ret);
unset($story);
break;
case 'singlegallery':
$ret = [];
$story_id = NewsUtils::NewsUtilityCleanVars($_REQUEST, 'storyid', 0, 'int');
$obj = $story_handler->get($story_id);
$story = $obj->toArray();
// Update content hits
$story_handler->NewsStoryUpdateHits($story_id);
$json['story_id'] = $story['story_id'];
$json['story_alias'] = $story['story_alias'];
$json['story_publish'] = $story['story_publish'];
$json['story_topic'] = $story['story_topic'];
$json['story_img'] = $story['story_img'];
$json['story_hits'] = $story['story_hits'];
if ($story['story_topic'] > 0) {
$topicObj = $topic_handler->get($story['story_topic']);
$json['story_topic_title'] = $topicObj->getVar('topic_title');
} else {
$json['story_topic_title'] = '';
}
$text = $story['story_title'];
$text = strip_tags($text);
$text = preg_replace("`\[.*\]`U", "", $text);
$text = preg_replace('`&(amp;)?#?[a-z0-9]+;`i', '', $text);
$text = htmlentities($text, ENT_COMPAT, 'utf-8');
$text = preg_replace("`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i", "\\1", $text);
$text = stripslashes($text);
$json['story_title'] = $text;
$text = $story['story_short'] . ' ' . $story['story_text'];
$text = strip_tags($text, '<img><a><br>');
$text = preg_replace("/<a[^>]+\>(<img[^>]+\>)<\/a>/i", '$1', $text);
$text = explode('<br />', $text);
foreach ($text as $img) {
$doc = new DOMDocument();
$doc->loadHTML($img);
$imageTags = $doc->getElementsByTagName('img');
foreach ($imageTags as $tag) {
$image[] = $tag->getAttribute('src');
}
}
$json['story_body'] = $image;
$ret[] = $json;
$return = json_encode($ret);
unset($story);
break;
// vote to story
case 'rate':
if (xoops_getModuleOption('vote_active', 'news')) {
$info = [];
$info['story'] = NewsUtils::NewsUtilityCleanVars($_POST, 'story', 0, 'int');
$info['rate'] = NewsUtils::NewsUtilityCleanVars($_POST, 'rate', 0, 'int');
if ($info['story'] && $info['rate']) {
$return = $rate_handler->NewsRateDo($info);
}
}
break;
}
echo $return;
}
?>