1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* RooCMS - Open Source Free Content Managment System
|
4
|
|
|
* @copyright © 2010-2020 alexandr Belov aka alex Roosso. All rights reserved.
|
5
|
|
|
* @author alex Roosso <[email protected]>
|
6
|
|
|
* @link http://www.roocms.com
|
7
|
|
|
* @license http://www.gnu.org/licenses/gpl-3.0.html
|
8
|
|
|
*
|
9
|
|
|
* You should have received a copy of the GNU General Public License v3
|
10
|
|
|
* along with this program. If not, see http://www.gnu.org/licenses/
|
11
|
|
|
*/
|
12
|
|
|
|
13
|
|
|
|
14
|
|
|
//#########################################################
|
15
|
|
|
// Anti Hack
|
16
|
|
|
//---------------------------------------------------------
|
17
|
|
|
if(!defined('RooCMS') || !defined('ACP')) {
|
18
|
|
|
die('Access Denied');
|
19
|
|
|
}
|
20
|
|
|
//#########################################################
|
21
|
|
|
|
22
|
|
|
|
23
|
|
|
/**
|
24
|
|
|
* Load Feed Extends
|
25
|
|
|
*/
|
26
|
|
|
require_once _CLASS."/trait_feedExtends.php";
|
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/**
|
30
|
|
|
* Class ACP_Feeds
|
31
|
|
|
*/
|
32
|
|
|
class ACP_Feeds {
|
33
|
|
|
|
34
|
|
|
# extends
|
35
|
|
|
use FeedExtends;
|
36
|
|
|
|
37
|
|
|
# objects
|
38
|
|
|
private $engine; # ... object global structure operations
|
39
|
|
|
|
40
|
|
|
# vars
|
41
|
|
|
private $feed = []; # structure parametrs
|
42
|
|
|
private $userlist = [];
|
43
|
|
|
|
44
|
|
|
|
45
|
|
|
|
46
|
|
|
/**
|
47
|
|
|
* Show must go on ...
|
48
|
|
|
*/
|
49
|
|
|
public function __construct() {
|
50
|
|
|
|
51
|
|
|
global $tpl;
|
52
|
|
|
|
53
|
|
|
require_once _CLASS."/class_structure.php";
|
54
|
|
|
$this->engine = new Structure();
|
55
|
|
|
|
56
|
|
|
# initialise
|
57
|
|
|
$this->init();
|
58
|
|
|
|
59
|
|
|
# output
|
60
|
|
|
$tpl->load_template("feeds");
|
61
|
|
|
}
|
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/**
|
65
|
|
|
* init action
|
66
|
|
|
*/
|
67
|
|
|
private function init() {
|
68
|
|
|
|
69
|
|
|
global $roocms, $get, $post, $db;
|
70
|
|
|
|
71
|
|
|
# set object for works content
|
72
|
|
|
if(isset($get->_page) && array_key_exists($this->engine->page_type, $this->engine->content_types)) {
|
73
|
|
|
|
74
|
|
|
# get settings
|
75
|
|
|
$this->feed = $this->get_settings();
|
76
|
|
|
|
77
|
|
|
# action
|
78
|
|
|
switch($roocms->part) {
|
79
|
|
|
# edit feed option
|
80
|
|
|
case 'settings':
|
81
|
|
|
$this->settings();
|
82
|
|
|
break;
|
83
|
|
|
|
84
|
|
|
# update feed option
|
85
|
|
|
case 'update_settings':
|
86
|
|
|
$this->update_settings();
|
87
|
|
|
break;
|
88
|
|
|
|
89
|
|
|
# cp feed items
|
90
|
|
|
case 'control':
|
91
|
|
|
$this->control();
|
92
|
|
|
break;
|
93
|
|
|
|
94
|
|
|
# create new item in feed
|
95
|
|
|
case 'create_item':
|
96
|
|
|
$this->create_item();
|
97
|
|
|
break;
|
98
|
|
|
|
99
|
|
|
|
100
|
|
|
# modify
|
101
|
|
|
case 'edit_item':
|
102
|
|
|
case 'update_item':
|
103
|
|
|
case 'migrate_item':
|
104
|
|
|
case 'status_on_item':
|
105
|
|
|
case 'status_off_item':
|
106
|
|
|
case 'delete_item':
|
107
|
|
|
if($db->check_id($get->_item, PAGES_FEED_TABLE)) {
|
108
|
|
|
switch($roocms->part) {
|
109
|
|
|
# edit item in feed
|
110
|
|
|
case 'edit_item':
|
111
|
|
|
$this->edit_item($get->_item);
|
112
|
|
|
break;
|
113
|
|
|
|
114
|
|
|
# update item in feed
|
115
|
|
|
case 'update_item':
|
116
|
|
|
if(isset($post->update_item)) {
|
117
|
|
|
$this->update_item($get->_item);
|
118
|
|
|
}
|
119
|
|
|
goback();
|
120
|
|
|
break;
|
121
|
|
|
|
122
|
|
|
# migrate item in feeds
|
123
|
|
|
case 'migrate_item':
|
124
|
|
|
$this->migrate_item($get->_item);
|
125
|
|
|
break;
|
126
|
|
|
|
127
|
|
|
# update status item in feed to on
|
128
|
|
|
case 'status_on_item':
|
129
|
|
|
$this->change_item_status($get->_item, 1);
|
130
|
|
|
break;
|
131
|
|
|
|
132
|
|
|
# update status item in feed to off
|
133
|
|
|
case 'status_off_item':
|
134
|
|
|
$this->change_item_status($get->_item, 0);
|
135
|
|
|
break;
|
136
|
|
|
|
137
|
|
|
# delete item from feed
|
138
|
|
|
case 'delete_item':
|
139
|
|
|
$this->delete_item($get->_item);
|
140
|
|
|
break;
|
141
|
|
|
}
|
142
|
|
|
|
143
|
|
|
}
|
144
|
|
|
else {
|
145
|
|
|
goback();
|
146
|
|
|
}
|
147
|
|
|
break;
|
148
|
|
|
|
149
|
|
|
default:
|
150
|
|
|
go(CP."?act=structure");
|
151
|
|
|
break;
|
152
|
|
|
}
|
153
|
|
|
}
|
154
|
|
|
else {
|
155
|
|
|
# go
|
156
|
|
|
go(CP."?act=structure");
|
157
|
|
|
}
|
158
|
|
|
}
|
159
|
|
|
|
160
|
|
|
|
161
|
|
|
/**
|
162
|
|
|
* feed view
|
163
|
|
|
*/
|
164
|
|
|
public function control() {
|
165
|
|
|
|
166
|
|
|
global $db, $parse, $tags, $tpl, $smarty;
|
167
|
|
|
|
168
|
|
|
# order request
|
169
|
|
|
$order = $this->feed_order($this->feed['items_sorting']);
|
170
|
|
|
|
171
|
|
|
$smarty->assign("feed", $this->feed);
|
172
|
|
|
|
173
|
|
|
|
174
|
|
|
# feed items
|
175
|
|
|
$taglinks = [];
|
176
|
|
|
$feedlist = [];
|
177
|
|
|
$q = $db->query("SELECT id, status, group_access, title, date_publications, date_end_publications, date_update, views FROM ".PAGES_FEED_TABLE." WHERE sid='".$this->feed['id']."' ORDER BY ".$order);
|
178
|
|
|
while($row = $db->fetch_assoc($q)) {
|
179
|
|
|
|
180
|
|
|
# flag future publications
|
181
|
|
|
$row['publication_future'] = ($row['date_publications'] > time()) ? true : false ;
|
182
|
|
|
|
183
|
|
|
# flag show/hide
|
184
|
|
|
$row['publication_status'] = "show";
|
185
|
|
|
|
186
|
|
|
if($row['date_end_publications'] != 0) {
|
187
|
|
|
|
188
|
|
|
# hide publications if ending period
|
189
|
|
|
if($row['date_end_publications'] < time()) {
|
190
|
|
|
$row['publication_status'] = "hide";
|
191
|
|
|
}
|
192
|
|
|
|
193
|
|
|
# formated date
|
194
|
|
|
$row['date_end_publications'] = $parse->date->unix_to_rus($row['date_end_publications']);
|
195
|
|
|
}
|
196
|
|
|
|
197
|
|
|
# formated date
|
198
|
|
|
$row['date_publications'] = $parse->date->unix_to_rus($row['date_publications']);
|
199
|
|
|
$row['date_update'] = $parse->date->unix_to_rus($row['date_update'], false, true, true);
|
200
|
|
|
|
201
|
|
|
$taglinks[$row['id']] = "feeditemid=".$row['id'];
|
202
|
|
|
$feedlist[$row['id']] = $row;
|
203
|
|
|
}
|
204
|
|
|
|
205
|
|
|
|
206
|
|
|
# tags collect
|
207
|
|
|
$feedlist = $tags->collect_tags($feedlist, $taglinks);
|
208
|
|
|
|
209
|
|
|
# smarty
|
210
|
|
|
$smarty->assign("subfeeds", $this->feed['subfeeds']);
|
211
|
|
|
$smarty->assign("feedlist", $feedlist);
|
212
|
|
|
|
213
|
|
|
$content = $tpl->load_template("feeds_control", true);
|
214
|
|
|
$smarty->assign("content", $content);
|
215
|
|
|
}
|
216
|
|
|
|
217
|
|
|
|
218
|
|
|
/**
|
219
|
|
|
* Create new record to feed
|
220
|
|
|
*/
|
221
|
|
|
public function create_item() {
|
222
|
|
|
|
223
|
|
|
global $db, $users, $logger, $tags, $files, $img, $post, $tpl, $smarty;
|
224
|
|
|
|
225
|
|
|
# insert db
|
226
|
|
|
if(isset($post->create_item)) {
|
227
|
|
|
|
228
|
|
|
# Check post data
|
229
|
|
|
$this->check_post_data_fields();
|
230
|
|
|
$this->control_post_data_date();
|
231
|
|
|
|
232
|
|
|
if(!isset($_SESSION['error'])) {
|
233
|
|
|
|
234
|
|
|
# Check secondary fields
|
235
|
|
|
$this->correct_post_fields();
|
236
|
|
|
|
237
|
|
|
# insert
|
238
|
|
|
$db->query("INSERT INTO ".PAGES_FEED_TABLE." (title, meta_title, meta_description, meta_keywords,
|
239
|
|
|
brief_item, full_item, author_id,
|
240
|
|
|
date_create, date_update, date_publications, date_end_publications,
|
241
|
|
|
group_access,
|
242
|
|
|
sort, sid)
|
243
|
|
|
VALUES ('".$post->title."', '".$post->meta_title."', '".$post->meta_description."', '".$post->meta_keywords."',
|
244
|
|
|
'".$post->brief_item."', '".$post->full_item."', '".$post->author_id."',
|
245
|
|
|
'".time()."', '".time()."', '".$post->date_publications."', '".$post->date_end_publications."',
|
246
|
|
|
'".$post->gids."',
|
247
|
|
|
'".$post->itemsort."', '".$this->feed['id']."')");
|
248
|
|
|
|
249
|
|
|
# get feed item id
|
250
|
|
|
$fiid = $db->insert_id();
|
251
|
|
|
|
252
|
|
|
# save tags
|
253
|
|
|
$tags->save_tags($post->tags, "feeditemid=".$fiid);
|
254
|
|
|
|
255
|
|
|
|
256
|
|
|
# attachment images
|
257
|
|
|
$images = $img->upload_image("images", "", array($this->feed['thumb_img_width'], $this->feed['thumb_img_height']));
|
258
|
|
|
if($images) {
|
259
|
|
|
foreach($images AS $image) {
|
260
|
|
|
$img->insert_images($image, "feeditemid=".$fiid, $post->title);
|
261
|
|
|
}
|
262
|
|
|
}
|
263
|
|
|
|
264
|
|
|
# attachment files
|
265
|
|
|
$files->upload("files", "feeditemid=".$fiid);
|
266
|
|
|
|
267
|
|
|
# recount items
|
268
|
|
|
$this->count_items($this->feed['id']);
|
269
|
|
|
|
270
|
|
|
# notice
|
271
|
|
|
$logger->info("Запись #".$fiid." <".$post->title."> успешно создана.");
|
272
|
|
|
|
273
|
|
|
// TODO: Переделать!
|
274
|
|
|
# mailling
|
275
|
|
|
if($post->date_publications <= time() && $post->mailing == 1) {
|
276
|
|
|
$this->mailing($fiid, $post->title, $post->brief_item);
|
277
|
|
|
}
|
278
|
|
|
}
|
279
|
|
|
|
280
|
|
|
# go
|
281
|
|
|
go(CP."?act=feeds&part=control&page=".$this->feed['id']);
|
282
|
|
|
}
|
283
|
|
|
|
284
|
|
|
# userlist
|
285
|
|
|
$this->userlist = $users->get_userlist();
|
286
|
|
|
|
287
|
|
|
# grouplist
|
288
|
|
|
$groups = $users->get_usergroups();
|
289
|
|
|
|
290
|
|
|
# popular tags
|
291
|
|
|
$poptags = $tags->list_tags(true);
|
292
|
|
|
|
293
|
|
|
# show upload files & images form
|
294
|
|
|
$tpl->load_image_upload_tpl("imagesupload");
|
295
|
|
|
$tpl->load_files_upload_tpl("filesupload");
|
296
|
|
|
|
297
|
|
|
# smarty vars
|
298
|
|
|
$smarty->assign("feed", $this->feed); # feed data
|
299
|
|
|
$smarty->assign("poptags", $poptags); # tags
|
300
|
|
|
$smarty->assign("userlist", $this->userlist); # users
|
301
|
|
|
$smarty->assign("groups", $groups); # groups
|
302
|
|
|
|
303
|
|
|
# tpl
|
304
|
|
|
$content = $tpl->load_template("feeds_create_item", true);
|
305
|
|
|
$smarty->assign("content", $content);
|
306
|
|
|
}
|
307
|
|
|
|
308
|
|
|
|
309
|
|
|
/**
|
310
|
|
|
* Edit record from feed
|
311
|
|
|
*
|
312
|
|
|
* @param int $id - record identificator from feed
|
313
|
|
|
*/
|
314
|
|
|
public function edit_item($id) {
|
315
|
|
|
|
316
|
|
|
global $db, $users, $tags, $files, $img, $tpl, $smarty, $parse;
|
317
|
|
|
|
318
|
|
|
# userlist
|
319
|
|
|
$this->userlist = $users->get_userlist();
|
320
|
|
|
|
321
|
|
|
# grouplist
|
322
|
|
|
$groups = $users->get_usergroups();
|
323
|
|
|
|
324
|
|
|
# get data
|
325
|
|
|
$q = $db->query("SELECT id, sid, status, group_access, sort, title, meta_title, meta_description, meta_keywords, brief_item, full_item, author_id, date_publications, date_end_publications FROM ".PAGES_FEED_TABLE." WHERE id='".$id."'");
|
326
|
|
|
$item = $db->fetch_assoc($q);
|
327
|
|
|
|
328
|
|
|
$item['date_publications'] = $parse->date->unix_to_rusint($item['date_publications']);
|
329
|
|
|
|
330
|
|
|
if($item['date_end_publications'] != 0) {
|
331
|
|
|
$item['date_end_publications'] = $parse->date->unix_to_rusint($item['date_end_publications']);
|
332
|
|
|
}
|
333
|
|
|
|
334
|
|
|
# check access granted for groups
|
335
|
|
|
$gids = $users->get_gid_access_granted($item['group_access']);
|
336
|
|
|
|
337
|
|
|
# item tags
|
338
|
|
|
$item['tags'] = implode(", ", array_map(array("Tags", "get_tag_title"), $tags->read_tags("feeditemid=".$id)));
|
339
|
|
|
|
340
|
|
|
# popular tags
|
341
|
|
|
$poptags = $tags->list_tags(true);
|
342
|
|
|
|
343
|
|
|
|
344
|
|
|
# download attached images
|
345
|
|
|
$attachimg = $img->load_images("feeditemid=".$id);
|
346
|
|
|
$smarty->assign("attachimg", $attachimg);
|
347
|
|
|
|
348
|
|
|
# show attached images
|
349
|
|
|
$attachedimages = $tpl->load_template("attached_images", true);
|
350
|
|
|
$smarty->assign("attachedimages", $attachedimages);
|
351
|
|
|
|
352
|
|
|
|
353
|
|
|
# download attached files
|
354
|
|
|
$attachfile = $files->load_files("feeditemid=".$id);
|
355
|
|
|
$smarty->assign("attachfile", $attachfile);
|
356
|
|
|
|
357
|
|
|
# show attached files
|
358
|
|
|
$attachedfiles = $tpl->load_template("attached_files", true);
|
359
|
|
|
$smarty->assign("attachedfiles", $attachedfiles);
|
360
|
|
|
|
361
|
|
|
|
362
|
|
|
# show upload files & images form
|
363
|
|
|
$tpl->load_image_upload_tpl("imagesupload");
|
364
|
|
|
$tpl->load_files_upload_tpl("filesupload");
|
365
|
|
|
|
366
|
|
|
|
367
|
|
|
# smarty vars
|
368
|
|
|
$smarty->assign("item", $item); # item data
|
369
|
|
|
$smarty->assign("feed", $this->feed); # feed data
|
370
|
|
|
$smarty->assign("poptags", $poptags); # tags
|
371
|
|
|
$smarty->assign("userlist", $this->userlist); # users list
|
372
|
|
|
$smarty->assign("gids", $gids); # group id access granted
|
373
|
|
|
$smarty->assign("groups", $groups); # group list
|
374
|
|
|
|
375
|
|
|
# tpl
|
376
|
|
|
$content = $tpl->load_template("feeds_edit_item", true);
|
377
|
|
|
$smarty->assign("content", $content);
|
378
|
|
|
}
|
379
|
|
|
|
380
|
|
|
|
381
|
|
|
/**
|
382
|
|
|
* Update record
|
383
|
|
|
*
|
384
|
|
|
* @param int $id - record identificator from feed
|
385
|
|
|
*/
|
386
|
|
|
public function update_item($id) {
|
387
|
|
|
|
388
|
|
|
global $db, $logger, $tags, $files, $img, $post, $get;
|
389
|
|
|
|
390
|
|
|
# Проверяем вводимые поля на ошибки
|
391
|
|
|
$this->check_post_data_fields();
|
392
|
|
|
$this->control_post_data_date();
|
393
|
|
|
|
394
|
|
|
# update
|
395
|
|
|
if(!isset($_SESSION['error'])) {
|
396
|
|
|
|
397
|
|
|
# Check secondary fields
|
398
|
|
|
$this->correct_post_fields();
|
399
|
|
|
|
400
|
|
|
# update
|
401
|
|
|
$db->query("UPDATE ".PAGES_FEED_TABLE."
|
402
|
|
|
SET
|
403
|
|
|
status = '".$post->status."',
|
404
|
|
|
group_access = '".$post->gids."',
|
405
|
|
|
sort = '".$post->itemsort."',
|
406
|
|
|
title = '".$post->title."',
|
407
|
|
|
meta_title = '".$post->meta_title."',
|
408
|
|
|
meta_description = '".$post->meta_description."',
|
409
|
|
|
meta_keywords = '".$post->meta_keywords."',
|
410
|
|
|
brief_item = '".$post->brief_item."',
|
411
|
|
|
full_item = '".$post->full_item."',
|
412
|
|
|
date_publications = '".$post->date_publications."',
|
413
|
|
|
date_end_publications = '".$post->date_end_publications."',
|
414
|
|
|
date_update = '".time()."',
|
415
|
|
|
author_id = '".$post->author_id."'
|
416
|
|
|
WHERE
|
417
|
|
|
id = '".$id."'");
|
418
|
|
|
|
419
|
|
|
# save tags
|
420
|
|
|
$tags->save_tags($post->tags, "feeditemid=".$id);
|
421
|
|
|
|
422
|
|
|
# notice
|
423
|
|
|
$logger->info("Запись #".$id." <".$post->title."> успешно отредактирована.");
|
424
|
|
|
|
425
|
|
|
# update images
|
426
|
|
|
$img->update_images_info("feeditemid", $id);
|
427
|
|
|
|
428
|
|
|
# attachment images
|
429
|
|
|
$images = $img->upload_image("images", "", array($this->feed['thumb_img_width'], $this->feed['thumb_img_height']));
|
430
|
|
|
if($images) {
|
431
|
|
|
foreach($images AS $image) {
|
432
|
|
|
$img->insert_images($image, "feeditemid=".$id, $post->title);
|
433
|
|
|
}
|
434
|
|
|
}
|
435
|
|
|
|
436
|
|
|
# attachment files
|
437
|
|
|
$files->upload("files", "feeditemid=".$id);
|
438
|
|
|
|
439
|
|
|
# go
|
440
|
|
|
go(CP."?act=feeds&part=control&page=".$get->_page);
|
441
|
|
|
}
|
442
|
|
|
|
443
|
|
|
# back
|
444
|
|
|
goback();
|
445
|
|
|
}
|
446
|
|
|
|
447
|
|
|
|
448
|
|
|
/**
|
449
|
|
|
* Migrate record to another feed
|
450
|
|
|
*
|
451
|
|
|
* @param int $id - record identificator from feed
|
452
|
|
|
*/
|
453
|
|
|
public function migrate_item($id) {
|
454
|
|
|
|
455
|
|
|
global $db, $logger, $tpl, $smarty, $post;
|
456
|
|
|
|
457
|
|
|
# Migrate
|
458
|
|
|
if(isset($post->from) && isset($post->to) && $db->check_id($post->from, STRUCTURE_TABLE, "id", "page_type='feed'") && $db->check_id($post->to, STRUCTURE_TABLE, "id", "page_type='feed'")) {
|
459
|
|
|
|
460
|
|
|
$db->query("UPDATE ".PAGES_FEED_TABLE."
|
461
|
|
|
SET sid = '".$post->to."',
|
462
|
|
|
date_update = '".time()."'
|
463
|
|
|
WHERE id = '".$id."'");
|
464
|
|
|
|
465
|
|
|
# recount items
|
466
|
|
|
$this->count_items($post->from);
|
467
|
|
|
$this->count_items($post->to);
|
468
|
|
|
|
469
|
|
|
|
470
|
|
|
# notice
|
471
|
|
|
$logger->info("Элемент #".$id." успешно перемещен.");
|
472
|
|
|
|
473
|
|
|
#go
|
474
|
|
|
go(CP."?act=feeds&part=control&page=".$post->to);
|
475
|
|
|
}
|
476
|
|
|
|
477
|
|
|
|
478
|
|
|
# get data item from db
|
479
|
|
|
$q = $db->query("SELECT id, sid, title FROM ".PAGES_FEED_TABLE." WHERE id='".$id."'");
|
480
|
|
|
$data = $db->fetch_assoc($q);
|
481
|
|
|
|
482
|
|
|
# smarty vars
|
483
|
|
|
$smarty->assign("item", $data);
|
484
|
|
|
|
485
|
|
|
|
486
|
|
|
# get data feeds from db
|
487
|
|
|
$feeds = [];
|
488
|
|
|
$q = $db->query("SELECT id, title, alias FROM ".STRUCTURE_TABLE." WHERE page_type='feed' ORDER BY id ASC");
|
489
|
|
|
while($row = $db->fetch_assoc($q)) {
|
490
|
|
|
$feeds[$row['id']] = $row;
|
491
|
|
|
}
|
492
|
|
|
|
493
|
|
|
# smarty vars
|
494
|
|
|
$smarty->assign("feeds", $feeds);
|
495
|
|
|
|
496
|
|
|
# tpl
|
497
|
|
|
$content = $tpl->load_template("feeds_migrate_item", true);
|
498
|
|
|
$smarty->assign("content", $content);
|
499
|
|
|
}
|
500
|
|
|
|
501
|
|
|
|
502
|
|
|
/**
|
503
|
|
|
* Change status to record feed
|
504
|
|
|
*
|
505
|
|
|
* @param int $id - record id
|
506
|
|
|
* @param int $status - 1=show , 0=hide
|
507
|
|
|
*/
|
508
|
|
|
public function change_item_status($id, $status = 1) {
|
509
|
|
|
|
510
|
|
|
global $db, $logger;
|
511
|
|
|
|
512
|
|
|
$status = (int) filter_var($status, FILTER_VALIDATE_BOOLEAN);
|
513
|
|
|
|
514
|
|
|
# update data in db
|
515
|
|
|
$db->query("UPDATE ".PAGES_FEED_TABLE." SET status='".$status."' WHERE id='".$id."'");
|
516
|
|
|
|
517
|
|
|
# notice
|
518
|
|
|
$mstatus = ($status) ? "Видимый" : "Скрытый" ;
|
519
|
|
|
$logger->info("Запись #".$id." успешно изменила свой статус на <".$mstatus.">.");
|
520
|
|
|
|
521
|
|
|
# go
|
522
|
|
|
goback();
|
523
|
|
|
}
|
524
|
|
|
|
525
|
|
|
|
526
|
|
|
/**
|
527
|
|
|
* Remove record from feed
|
528
|
|
|
*
|
529
|
|
|
* @param int $id - record id
|
530
|
|
|
*/
|
531
|
|
|
public function delete_item($id) {
|
532
|
|
|
|
533
|
|
|
global $db, $logger, $img, $files, $tags;
|
534
|
|
|
|
535
|
|
|
# get sid
|
536
|
|
|
$q = $db->query("SELECT sid FROM ".PAGES_FEED_TABLE." WHERE id='".$id."'");
|
537
|
|
|
$row = $db->fetch_assoc($q);
|
538
|
|
|
|
539
|
|
|
# del attached images
|
540
|
|
|
$img->remove_images("feeditemid=".$id);
|
541
|
|
|
|
542
|
|
|
# del attached files
|
543
|
|
|
$files->remove_files("feeditemid=".$id);
|
544
|
|
|
|
545
|
|
|
# del tags
|
546
|
|
|
$tags->save_tags("", "feeditemid=".$id);
|
547
|
|
|
|
548
|
|
|
# delete item
|
549
|
|
|
$db->query("DELETE FROM ".PAGES_FEED_TABLE." WHERE id='".$id."'");
|
550
|
|
|
|
551
|
|
|
# recount items
|
552
|
|
|
$this->count_items($row['sid']);
|
553
|
|
|
|
554
|
|
|
# notice
|
555
|
|
|
$logger->info("Элемент #".$id." успешно удален.");
|
556
|
|
|
|
557
|
|
|
# go
|
558
|
|
|
goback();
|
559
|
|
|
}
|
560
|
|
|
|
561
|
|
|
|
562
|
|
|
/**
|
563
|
|
|
* Remove feed
|
564
|
|
|
*
|
565
|
|
|
* @param int $sid - structure element id
|
566
|
|
|
*/
|
567
|
|
|
public function delete_feed($sid) {
|
568
|
|
|
|
569
|
|
|
global $db, $img, $files, $tags;
|
570
|
|
|
|
571
|
|
|
$cond = "";
|
572
|
|
|
$f = $db->query("SELECT id FROM ".PAGES_FEED_TABLE." WHERE sid='".$sid."'");
|
573
|
|
|
while($fid = $db->fetch_assoc($f)) {
|
574
|
|
|
# del tags
|
575
|
|
|
$tags->save_tags("", "feeditemid=".$fid['id']);
|
576
|
|
|
# cond
|
577
|
|
|
$cond = $db->qcond_or($cond);
|
578
|
|
|
$cond .= " attachedto='feeditemid=".$fid['id']."' " ;
|
579
|
|
|
}
|
580
|
|
|
|
581
|
|
|
# del attached images
|
582
|
|
|
if(trim($cond) != "") {
|
583
|
|
|
$img->remove_images($cond, true);
|
584
|
|
|
$files->remove_files($cond, true);
|
585
|
|
|
}
|
586
|
|
|
|
587
|
|
|
$db->query("DELETE FROM ".PAGES_FEED_TABLE." WHERE sid='".$sid."'");
|
588
|
|
|
}
|
589
|
|
|
|
590
|
|
|
|
591
|
|
|
/**
|
592
|
|
|
* Settings feed
|
593
|
|
|
*/
|
594
|
|
|
public function settings() {
|
595
|
|
|
|
596
|
|
|
global $config, $tpl, $smarty;
|
597
|
|
|
|
598
|
|
|
# Уведомление о глобальном отключении RSS лент
|
599
|
|
|
$this->feed['rss_warn'] = (!$config->rss_power) ? true : false ;
|
600
|
|
|
|
601
|
|
|
# глобальное значение количества элементов на страницу
|
602
|
|
|
$this->feed['global_items_per_page'] =& $config->feed_items_per_page;
|
603
|
|
|
|
604
|
|
|
# default thumb size
|
605
|
|
|
$default_thumb_size = array('width' => $config->gd_thumb_image_width,
|
606
|
|
|
'height' => $config->gd_thumb_image_height);
|
607
|
|
|
|
608
|
|
|
# smarty vars
|
609
|
|
|
$smarty->assign("feed",$this->feed);
|
610
|
|
|
$smarty->assign("default_thumb_size", $default_thumb_size);
|
611
|
|
|
|
612
|
|
|
# tpl
|
613
|
|
|
$content = $tpl->load_template("feeds_settings_feed", true);
|
614
|
|
|
$smarty->assign("content", $content);
|
615
|
|
|
}
|
616
|
|
|
|
617
|
|
|
|
618
|
|
|
/**
|
619
|
|
|
* Settings update to feed
|
620
|
|
|
*/
|
621
|
|
|
public function update_settings() {
|
622
|
|
|
|
623
|
|
|
global $db, $img, $post, $logger;
|
624
|
|
|
|
625
|
|
|
if(isset($post->update_settings)) {
|
626
|
|
|
# update buffer
|
627
|
|
|
$update = "";
|
628
|
|
|
|
629
|
|
|
# RSS flag
|
630
|
|
|
$rss = 0;
|
631
|
|
|
if($post->rss == "1") {
|
632
|
|
|
$rss = 1;
|
633
|
|
|
}
|
634
|
|
|
$update .= " rss='".$rss."', ";
|
635
|
|
|
|
636
|
|
|
# items per page
|
637
|
|
|
$items_per_page = 0;
|
638
|
|
|
if(round($post->items_per_page) >= 0) {
|
639
|
|
|
$items_per_page = round($post->items_per_page);
|
640
|
|
|
}
|
641
|
|
|
$update .= " items_per_page='".$items_per_page."', " ;
|
642
|
|
|
|
643
|
|
|
# thumbnail check
|
644
|
|
|
$img->check_post_thumb_parametrs();
|
645
|
|
|
|
646
|
|
|
# items sorting in feed
|
647
|
|
|
$items_sorting = "datepublication";
|
648
|
|
|
if(isset($post->items_sorting)) {
|
649
|
|
|
switch($post->items_sorting) {
|
650
|
|
|
case 'title_asc':
|
651
|
|
|
$items_sorting = "title_asc";
|
652
|
|
|
break;
|
653
|
|
|
|
654
|
|
|
case 'title_desc':
|
655
|
|
|
$items_sorting = "title_desc";
|
656
|
|
|
break;
|
657
|
|
|
|
658
|
|
|
case 'manual_sorting':
|
659
|
|
|
$items_sorting = "manual_sorting";
|
660
|
|
|
break;
|
661
|
|
|
}
|
662
|
|
|
}
|
663
|
|
|
$update .= " items_sorting = '".$items_sorting."', ";
|
664
|
|
|
|
665
|
|
|
# show_child_feeds
|
666
|
|
|
$show_child_feeds = "none";
|
667
|
|
|
if(isset($post->show_child_feeds)) {
|
668
|
|
|
switch($post->show_child_feeds) {
|
669
|
|
|
case 'default':
|
670
|
|
|
$show_child_feeds = "default";
|
671
|
|
|
break;
|
672
|
|
|
|
673
|
|
|
case 'forced':
|
674
|
|
|
$show_child_feeds = "forced";
|
675
|
|
|
break;
|
676
|
|
|
}
|
677
|
|
|
}
|
678
|
|
|
|
679
|
|
|
|
680
|
|
|
# up data to db
|
681
|
|
|
$db->query("UPDATE ".STRUCTURE_TABLE."
|
682
|
|
|
SET
|
683
|
|
|
".$update."
|
684
|
|
|
show_child_feeds='".$show_child_feeds."',
|
685
|
|
|
thumb_img_width='".$post->thumb_img_width."',
|
686
|
|
|
thumb_img_height='".$post->thumb_img_height."',
|
687
|
|
|
append_info_before='".$post->append_info_before."',
|
688
|
|
|
append_info_after='".$post->append_info_after."',
|
689
|
|
|
date_modified='".time()."'
|
690
|
|
|
WHERE
|
691
|
|
|
id='".$this->feed['id']."'");
|
692
|
|
|
|
693
|
|
|
$logger->info("Настройки ленты #".$this->feed['id']." успешно обновлены.");
|
694
|
|
|
}
|
695
|
|
|
|
696
|
|
|
# go
|
697
|
|
|
goback();
|
698
|
|
|
}
|
699
|
|
|
|
700
|
|
|
|
701
|
|
|
/**
|
702
|
|
|
* Recount records in feed
|
703
|
|
|
*
|
704
|
|
|
* @param int $sid - feed id
|
705
|
|
|
*/
|
706
|
|
|
public function count_items($sid) {
|
707
|
|
|
|
708
|
|
|
global $db;
|
709
|
|
|
|
710
|
|
|
# count
|
711
|
|
|
$items = $db->count(PAGES_FEED_TABLE, "sid='".$sid."'");
|
712
|
|
|
|
713
|
|
|
# save
|
714
|
|
|
$db->query("UPDATE ".STRUCTURE_TABLE." SET items='".$items."' WHERE id='".$sid."'");
|
715
|
|
|
}
|
716
|
|
|
|
717
|
|
|
|
718
|
|
|
/**
|
719
|
|
|
* Check data post
|
720
|
|
|
*/
|
721
|
|
|
private function check_post_data_fields() {
|
722
|
|
|
|
723
|
|
|
global $post, $logger;
|
724
|
|
|
|
725
|
|
|
# title
|
726
|
|
|
if(!isset($post->title)) {
|
727
|
|
|
$logger->error("Не заполнен заголовок элемента", false);
|
728
|
|
|
}
|
729
|
|
|
|
730
|
|
|
# full desc item
|
731
|
|
|
if(!isset($post->full_item)) {
|
732
|
|
|
$logger->error("Не заполнен подробный текст элемента", false);
|
733
|
|
|
}
|
734
|
|
|
|
735
|
|
|
# status
|
736
|
|
|
$post->status = (int) filter_var($post->status, FILTER_VALIDATE_BOOLEAN);
|
737
|
|
|
}
|
738
|
|
|
|
739
|
|
|
|
740
|
|
|
/**
|
741
|
|
|
* Check dates from data post
|
742
|
|
|
*/
|
743
|
|
|
private function control_post_data_date() {
|
744
|
|
|
|
745
|
|
|
global $post, $parse;
|
746
|
|
|
|
747
|
|
|
# check isset date publication
|
748
|
|
|
if(!isset($post->date_publications)) {
|
749
|
|
|
$post->date_publications = date("d.m.Y",time());
|
750
|
|
|
}
|
751
|
|
|
|
752
|
|
|
# check isset date end publication
|
753
|
|
|
if(!isset($post->date_end_publications)) {
|
754
|
|
|
$post->date_end_publications = 0;
|
755
|
|
|
}
|
756
|
|
|
|
757
|
|
|
# date publications
|
758
|
|
|
$post->date_publications = $parse->date->rusint_to_unix($post->date_publications);
|
759
|
|
|
|
760
|
|
|
# date end publications
|
761
|
|
|
if($post->date_end_publications != 0) {
|
762
|
|
|
$post->date_end_publications = $parse->date->rusint_to_unix($post->date_end_publications);
|
763
|
|
|
}
|
764
|
|
|
|
765
|
|
|
if($post->date_end_publications <= $post->date_publications) {
|
766
|
|
|
$post->date_end_publications = 0;
|
767
|
|
|
}
|
768
|
|
|
}
|
769
|
|
|
|
770
|
|
|
|
771
|
|
|
/**
|
772
|
|
|
* Check and correct secondary fields
|
773
|
|
|
*/
|
774
|
|
|
private function correct_post_fields() {
|
775
|
|
|
|
776
|
|
|
global $users, $post;
|
777
|
|
|
|
778
|
|
|
# tags
|
779
|
|
|
if(!isset($post->tags)) {
|
780
|
|
|
$post->tags = NULL;
|
781
|
|
|
}
|
782
|
|
|
|
783
|
|
|
# sort
|
784
|
|
|
if(!isset($post->itemsort) || round($post->itemsort) < 0) {
|
785
|
|
|
$post->itemsort = 0;
|
786
|
|
|
}
|
787
|
|
|
else {
|
788
|
|
|
$post->itemsort = round($post->itemsort);
|
789
|
|
|
}
|
790
|
|
|
|
791
|
|
|
# group ids with access
|
792
|
|
|
if(isset($post->gids) && is_array($post->gids)) {
|
793
|
|
|
$post->gids = implode(",", $post->gids);
|
794
|
|
|
}
|
795
|
|
|
else {
|
796
|
|
|
$post->gids = 0;
|
797
|
|
|
}
|
798
|
|
|
|
799
|
|
|
# userlist
|
800
|
|
|
$this->userlist = $users->get_userlist();
|
801
|
|
|
|
802
|
|
|
# author
|
803
|
|
|
if(!isset($post->author_id) || !array_key_exists($post->author_id, $this->userlist)) {
|
804
|
|
|
$post->author_id = 0;
|
805
|
|
|
}
|
806
|
|
|
}
|
807
|
|
|
|
808
|
|
|
|
809
|
|
|
/**
|
810
|
|
|
* Это временная функция
|
811
|
|
|
*
|
812
|
|
|
* @param int $id
|
813
|
|
|
* @param string $title
|
814
|
|
|
* @param string $subject
|
815
|
|
|
*/
|
816
|
|
|
private function mailing($id, $title, $subject) {
|
817
|
|
|
|
818
|
|
|
global $parse, $mailer, $logger, $users, $mailer, $site;
|
819
|
|
|
|
820
|
|
|
# get userlist
|
821
|
|
|
$userlist = $users->get_userlist(1, 0, 1);
|
822
|
|
|
|
823
|
|
|
# html
|
824
|
|
|
$subject = $parse->text->html($subject);
|
825
|
|
|
$subject = "<h1>".$title."</h1>
|
826
|
|
|
".$subject."
|
827
|
|
|
<br /><br /><a href=\"http://".$site['domain']."/index.php?page=".$this->feed['alias']."&id=".$id."\">Читать полностью</a>";
|
828
|
|
|
|
829
|
|
|
# send to email
|
830
|
|
|
if(count($userlist) != 0) {
|
831
|
|
|
$mailer->spread($userlist, $title, $subject);
|
832
|
|
|
}
|
833
|
|
|
else {
|
834
|
|
|
$logger->error("Сообщение не отправлено! Не обнаружены подписчики подходящие под заданные критерии.", false);
|
835
|
|
|
}
|
836
|
|
|
}
|
837
|
|
|
|
838
|
|
|
|
839
|
|
|
/**
|
840
|
|
|
* get array with feed settings
|
841
|
|
|
*
|
842
|
|
|
* @return array<integer|string|boolean|array>
|
843
|
|
|
*/
|
844
|
|
|
private function get_settings() {
|
845
|
|
|
|
846
|
|
|
$setting = array(
|
847
|
|
|
'id' => $this->engine->page_id,
|
848
|
|
|
'alias' => $this->engine->page_alias,
|
849
|
|
|
'title' => $this->engine->page_title,
|
850
|
|
|
'rss' => $this->engine->page_rss,
|
851
|
|
|
'show_child_feeds' => $this->engine->page_show_child_feeds,
|
852
|
|
|
'items_per_page' => $this->engine->page_items_per_page,
|
853
|
|
|
'items_sorting' => $this->engine->page_items_sorting,
|
854
|
|
|
'thumb_img_width' => $this->engine->page_thumb_img_width,
|
855
|
|
|
'thumb_img_height' => $this->engine->page_thumb_img_height,
|
856
|
|
|
'append_info_before' => $this->engine->page_append_info_before,
|
857
|
|
|
'append_info_after' => $this->engine->page_append_info_after,
|
858
|
|
|
'subfeeds' => $this->engine->load_tree($this->engine->page_id)
|
859
|
|
|
);
|
860
|
|
|
|
861
|
|
|
return $setting;
|
862
|
|
|
}
|
863
|
|
|
}
|
864
|
|
|
|
865
|
|
|
/**
|
866
|
|
|
* Init Class
|
867
|
|
|
*/
|
868
|
|
|
$acp_feeds = new ACP_Feeds;
|
869
|
|
|
|