/[drupal]/contributions/modules/content_refresh/content_refresh.module
ViewVC logotype

Contents of /contributions/modules/content_refresh/content_refresh.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.11 - (show annotations) (download) (as text)
Fri Aug 21 20:18:56 2009 UTC (3 months ago) by yaph
Branch: MAIN
CVS Tags: DRUPAL-6--1-5, HEAD
Changes since 1.10: +4 -3 lines
File MIME type: text/x-php
cast uid to int before checking for identity. strict typing has its advantages.
1 <?php
2 // $Id: content_refresh.module,v 1.10 2009/08/21 19:47:13 yaph Exp $
3
4 /**
5 * @file
6 * Author: Ramiro Gómez - http://www.ramiro.org
7 * A Drupal module that provides cache clearing functionality
8 * for various content related actions.
9 */
10
11 /**
12 * Implementation of hook_menu().
13 */
14 function content_refresh_menu() {
15 $items = array();
16 $items['admin/content/content-refresh'] = array(
17 'title' => 'Content Refresh',
18 'description' => 'Set the cache clearing options for content updates.',
19 'page callback' => 'drupal_get_form',
20 'page arguments' => array('content_refresh_admin_settings'),
21 'access arguments' => array('administer site configuration'),
22 'type' => MENU_NORMAL_ITEM,
23 'file' => 'content_refresh.admin.inc'
24 );
25 return $items;
26 }
27
28 /**
29 * Implementation of hook_nodeapi().
30 */
31 function content_refresh_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
32
33 $cache_lifetime = variable_get('cache_lifetime', 0);
34 $cache_enabled = variable_get('cache', CACHE_DISABLED);
35
36 if ($cache_enabled && $cache_lifetime > 0) {
37
38 $clear_front = FALSE;
39 $clear_page = FALSE;
40 $clear_comment_page = FALSE;
41
42 switch ($op) {
43 case 'insert':
44 if ($node->status && $node->promote) {
45 $clear_front = TRUE;
46 }
47 case 'delete':
48 $clear_page = TRUE;
49 if ($node->status && $node->promote) {
50 $clear_front = TRUE;
51 $clear_comment_page = TRUE;
52 }
53 break;
54 case 'update':
55 if ($node->status) {
56 $clear_page = TRUE;
57 if ($node->promote) {
58 $clear_front = TRUE;
59 }
60 }
61 if (!$node->status && $node->promote) {
62 $clear_front = TRUE;
63 }
64 break;
65 }
66
67 if ($clear_page) {
68 $url = url('node/'. $node->nid, array('absolute' => TRUE));
69 cache_clear_all($url, 'cache_page');
70 }
71
72 if ($clear_comment_page && module_exists('comment')) {
73 $url = url('comment/reply/'. $node->nid, array('absolute' => TRUE));
74 cache_clear_all($url, 'cache_page', TRUE);
75 }
76
77 if ($clear_front && variable_get('content_refresh_clear_front_page_cache', 1)) {
78 content_refresh_clear_front_page_cache();
79 }
80 }
81 }
82
83 /**
84 * Clear the cache entry of the front page
85 *
86 * @param Void
87 * @return Void
88 */
89 function content_refresh_clear_front_page_cache() {
90 $front = variable_get('site_frontpage', 'node');
91 $url = url($front, array('absolute' => TRUE));
92 cache_clear_all($url, 'cache_page');
93 // clear pager pages
94 cache_clear_all($url . '?page', 'cache_page', TRUE);
95 // clear cache entry for the front page entry without the site_frontpage value appended
96 $url = preg_replace("%$front$%", '', $url);
97 cache_clear_all($url, 'cache_page', FALSE);
98 }
99
100 /**
101 * Implementation of hook_comment().
102 */
103 function content_refresh_comment($a1, $op) {
104 $nid = false;
105 $uid = false;
106 switch ($op) {
107 case 'insert':
108 case 'update':
109 $nid = $a1['nid'];
110 $uid = (int) $a1['uid'];
111 break;
112 case 'publish':
113 case 'unpublish':
114 case 'delete':
115 $nid = $a1->nid;
116 $uid = (int) $a1->uid;
117 break;
118 }
119
120 if ($nid !== false && 0 === $uid) {
121 // retrieve the absolute url for the node
122 $options = array('absolute' => TRUE);
123 $url = url('node/'. $nid, $options);
124 // delete cache entries for that url
125 cache_clear_all($url, 'cache_page');
126 }
127 }

  ViewVC Help
Powered by ViewVC 1.1.2