1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Dynamic Recent Period |
---|
4 | Version: auto |
---|
5 | Description: Computes a dynamic recent period |
---|
6 | Plugin URI: auto |
---|
7 | Author: Ruben ARNAUD |
---|
8 | */ |
---|
9 | |
---|
10 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
11 | |
---|
12 | define('DYNARECEPERIO_ID', basename(dirname(__FILE__))); |
---|
13 | define('DYNARECEPERIO_PATH', PHPWG_PLUGINS_PATH . DYNARECEPERIO_ID . '/'); |
---|
14 | |
---|
15 | |
---|
16 | global $conf; |
---|
17 | $conf['dynareceperio'] = unserialize($conf['dynareceperio']); |
---|
18 | |
---|
19 | |
---|
20 | // ADMIN MENU LINK |
---|
21 | if (defined('IN_ADMIN')) |
---|
22 | { |
---|
23 | add_event_handler('get_admin_plugin_menu_links', 'dynareceperio_get_admin_plugin_menu_links'); |
---|
24 | |
---|
25 | function dynareceperio_get_admin_plugin_menu_links($menu) |
---|
26 | { |
---|
27 | $menu[] = array( |
---|
28 | 'NAME' => 'Dynamic Recent Period', |
---|
29 | 'URL' => get_root_url() . 'admin.php?page=plugin-' . DYNARECEPERIO_ID, |
---|
30 | ); |
---|
31 | |
---|
32 | return $menu; |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | // REMOVE INPUT ON PROFILE AND USERS LIST |
---|
37 | if (script_basename() == 'profile' || defined('IN_ADMIN')) |
---|
38 | { |
---|
39 | if ($conf['dynareceperio']['force']) |
---|
40 | { |
---|
41 | add_event_handler('loc_end_page_tail', 'dynareceperio_hide_recent_period'); |
---|
42 | |
---|
43 | function dynareceperio_hide_recent_period() |
---|
44 | { |
---|
45 | global $template, $page; |
---|
46 | |
---|
47 | if (@$page['page'] == 'user_list') |
---|
48 | { |
---|
49 | $template->set_prefilter('user_list', 'dynareceperio_user_list'); |
---|
50 | } |
---|
51 | else if (@$page['body_id']=='theProfilePage' || (@$page['page'] == 'configuration' && @$_GET['section'] == 'default')) |
---|
52 | { |
---|
53 | $template->block_footer_script(array('require'=>'jquery'), 'jQuery("#recent_period").parent().hide();'); |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | function dynareceperio_user_list($content) |
---|
58 | { |
---|
59 | $search = '<div class="userProperty"><strong>{\'Recent period\'|translate}'; |
---|
60 | $replace = '<div class="userProperty" style="display:none;"><strong>{\'Recent period\'|translate}'; |
---|
61 | return str_replace($search, $replace, $content); |
---|
62 | } |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | // APPLY DYNAMIC PERIOD |
---|
67 | else |
---|
68 | { |
---|
69 | add_event_handler('init', 'dynareceperio_user_init'); |
---|
70 | |
---|
71 | function dynareceperio_user_init() |
---|
72 | { |
---|
73 | global $conf, $user; |
---|
74 | |
---|
75 | $default_period = get_default_user_value('recent_period', $user['recent_period']); |
---|
76 | |
---|
77 | if ($conf['dynareceperio']['force'] or $default_period == $user['recent_period']) |
---|
78 | { |
---|
79 | $query = ' |
---|
80 | SELECT MAX(D) |
---|
81 | FROM ( |
---|
82 | SELECT D |
---|
83 | FROM ( |
---|
84 | SELECT DATEDIFF(CURRENT_DATE, date_available) AS D |
---|
85 | FROM '.IMAGES_TABLE.' AS i |
---|
86 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=image_id |
---|
87 | '.get_sql_condition_FandF( |
---|
88 | array( |
---|
89 | 'forbidden_categories' => 'ic.category_id', |
---|
90 | 'visible_categories' => 'ic.category_id', |
---|
91 | 'visible_images' => 'id' |
---|
92 | ), |
---|
93 | 'WHERE', |
---|
94 | true |
---|
95 | ).' |
---|
96 | ) AS ListDate |
---|
97 | WHERE D >= 0 |
---|
98 | GROUP BY D |
---|
99 | ORDER BY D ASC |
---|
100 | LIMIT '.$conf['dynareceperio']['day_number'].' |
---|
101 | ) AS MaxD |
---|
102 | ;'; |
---|
103 | $result = pwg_query($query); |
---|
104 | |
---|
105 | if (list($period) = pwg_db_fetch_row($result)) |
---|
106 | { |
---|
107 | $user['recent_period'] = max($period, $default_period); |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|
111 | } |
---|