1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of postExpired, a plugin for Dotclear 2. |
---|
4 | # |
---|
5 | # Copyright (c) 2009-2010 JC Denis and contributors |
---|
6 | # jcdenis@gdwd.com |
---|
7 | # |
---|
8 | # Licensed under the GPL version 2.0 license. |
---|
9 | # A copy of this license is available in LICENSE file or at |
---|
10 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | |
---|
13 | if (!defined('DC_RC_PATH')){return;} |
---|
14 | if (!$core->plugins->moduleExists('metadata') || !in_array($core->url->type,array('default','feed'))) {return;} |
---|
15 | |
---|
16 | $core->addBehavior('publicBeforeDocument',array('publicBehaviorPostExpired','unpublishExpiredEntries')); |
---|
17 | |
---|
18 | class publicBehaviorPostExpired |
---|
19 | { |
---|
20 | public static function unpublishExpiredEntries($core) |
---|
21 | { |
---|
22 | # Get expired dates |
---|
23 | $params['columns'][] = 'meta_id'; |
---|
24 | $params['no_content'] = true; |
---|
25 | $params['post_status'] = 1; |
---|
26 | $params['from'] = ', '.$core->prefix.'meta META '; |
---|
27 | $params['sql'] = 'AND META.post_id = P.post_id '; |
---|
28 | $params['sql'] .= "AND META.meta_type = 'postexpired' "; |
---|
29 | $posts = $core->auth->sudo(array($core->blog,'getPosts'),$params); |
---|
30 | # No expired date |
---|
31 | if ($posts->isEmpty()) { |
---|
32 | return; |
---|
33 | } |
---|
34 | # Get curent timestamp |
---|
35 | $now = dt::toUTC(time()); |
---|
36 | # Prepared post cursor |
---|
37 | $post_cur = $core->con->openCursor($core->prefix.'post'); |
---|
38 | # Loop through marked posts |
---|
39 | while($posts->fetch()) |
---|
40 | { |
---|
41 | # Check if post is outdated |
---|
42 | $now_tz = $now + dt::getTimeOffset($posts->post_tz,$now); |
---|
43 | $meta_tz = strtotime($posts->meta_id); |
---|
44 | if ($now_tz > $meta_tz) |
---|
45 | { |
---|
46 | # Update post |
---|
47 | $post_cur->clean(); |
---|
48 | $post_cur->post_upddt = date('Y-m-d H:i:s',$now_tz); |
---|
49 | $post_cur->post_status = 0; |
---|
50 | $post_cur->update( |
---|
51 | 'WHERE post_id = '.$posts->post_id.' '. |
---|
52 | "AND blog_id = '".$core->con->escape($core->blog->id)."' " |
---|
53 | ); |
---|
54 | # Remove expired date |
---|
55 | $meta = new dcMeta($core); |
---|
56 | $core->auth->sudo(array($meta,'delPostMeta'),$posts->post_id,'postexpired'); |
---|
57 | # Say blog is updated |
---|
58 | $core->blog->triggerBlog(); |
---|
59 | } |
---|
60 | } |
---|
61 | } |
---|
62 | } |
---|
63 | ?> |
---|