1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | define('PDHR_DIR' , basename(dirname(__FILE__))); |
---|
5 | define('PDHR_PATH' , PHPWG_PLUGINS_PATH . PDHR_DIR . '/'); |
---|
6 | load_language('plugin.lang', PDHR_PATH); |
---|
7 | |
---|
8 | add_event_handler('get_admin_plugin_menu_links', 'dphr_admin_menu'); |
---|
9 | function dphr_admin_menu($menu) |
---|
10 | { |
---|
11 | array_push($menu, array( |
---|
12 | 'NAME' => 'Delete Hit Rate', |
---|
13 | 'URL' => get_admin_plugin_menu_link(PDHR_PATH . 'admin/admin.php'))); |
---|
14 | return $menu; |
---|
15 | } |
---|
16 | |
---|
17 | |
---|
18 | //add prefiltre photo |
---|
19 | add_event_handler('loc_begin_admin', 'plugdphrPf',60); |
---|
20 | |
---|
21 | function plugdphrPf() |
---|
22 | { |
---|
23 | global $template; |
---|
24 | $template->set_prefilter('picture_modify', 'plugdphrPT'); |
---|
25 | } |
---|
26 | |
---|
27 | function plugdphrPT($content, &$smarty) |
---|
28 | { |
---|
29 | load_language('plugin.lang', PDHR_PATH); |
---|
30 | $search = '#<form id="associations"#'; |
---|
31 | |
---|
32 | $replacement = ' |
---|
33 | <div> |
---|
34 | <form method="post" > |
---|
35 | <fieldset> |
---|
36 | <legend>{\'Purge - Plugin Delete Hit/Rate\'|@translate}</legend> |
---|
37 | <div style="text-align:center;"> |
---|
38 | <input class="submit" name="plugdphphoto" type="submit" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:\'javascript\'}\');" value="{\'Purge hit of the photo\'|@translate}" {$TAG_INPUT_ENABLED} /> |
---|
39 | <input class="submit" name="plugdprphoto" type="submit" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:\'javascript\'}\');" value="{\'Purge rate of the photo\'|@translate}" {$TAG_INPUT_ENABLED} /> |
---|
40 | </div> |
---|
41 | </fieldset> |
---|
42 | </form> |
---|
43 | </div> |
---|
44 | <form id="associations"'; |
---|
45 | |
---|
46 | return preg_replace($search, $replacement, $content); |
---|
47 | } |
---|
48 | |
---|
49 | if (isset($_POST['plugdphphoto'])) |
---|
50 | { |
---|
51 | $query = ' |
---|
52 | UPDATE ' . IMAGES_TABLE . ' |
---|
53 | SET hit= \'0\' |
---|
54 | WHERE id = '.$_GET['image_id'].' |
---|
55 | ;'; |
---|
56 | $result = pwg_query($query); |
---|
57 | } |
---|
58 | |
---|
59 | if (isset($_POST['plugdprphoto'])) |
---|
60 | { |
---|
61 | $query = ' |
---|
62 | UPDATE ' . IMAGES_TABLE . ' |
---|
63 | SET rating_score = \'NULL\' |
---|
64 | WHERE id = '.$_GET['image_id'].' |
---|
65 | ;'; |
---|
66 | $result = pwg_query($query); |
---|
67 | |
---|
68 | $query = ' |
---|
69 | DELETE FROM ' . RATE_TABLE . ' |
---|
70 | WHERE element_id = '.$_GET['image_id'].' |
---|
71 | ;'; |
---|
72 | $result = pwg_query($query); |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | //add prefiltre album |
---|
77 | add_event_handler('loc_end_cat_modify', 'plugdphrAf'); |
---|
78 | |
---|
79 | function plugdphrAf() |
---|
80 | { |
---|
81 | global $template; |
---|
82 | $template->set_prefilter('categories', 'plugdphrAT'); |
---|
83 | } |
---|
84 | |
---|
85 | function plugdphrAT($content, &$smarty) |
---|
86 | { |
---|
87 | load_language('plugin.lang', PDHR_PATH); |
---|
88 | $search = '#name="reset"> |
---|
89 | </p>#'; |
---|
90 | |
---|
91 | $replacement = 'name="reset"> |
---|
92 | </p> |
---|
93 | |
---|
94 | <div> |
---|
95 | <form method="post" > |
---|
96 | <fieldset> |
---|
97 | <legend>{\'Purge - Plugin Delete Hit/Rate\'|@translate}</legend> |
---|
98 | <div style="text-align:center;"> |
---|
99 | <input class="submit" name="plugdphA" type="submit" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:\'javascript\'}\');" value="{\'Purge hits on all pictures album\'|@translate}" {$TAG_INPUT_ENABLED} /> |
---|
100 | <input class="submit" name="plugdprA" type="submit" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:\'javascript\'}\');" value="{\'Purge rates on all pictures album\'|@translate}" {$TAG_INPUT_ENABLED} /> |
---|
101 | </div> |
---|
102 | </fieldset> |
---|
103 | </form> |
---|
104 | </div> |
---|
105 | '; |
---|
106 | |
---|
107 | return preg_replace($search, $replacement, $content); |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | if (isset($_POST['plugdphA'])) |
---|
112 | { |
---|
113 | $query = ' |
---|
114 | select image_id |
---|
115 | FROM ' . IMAGE_CATEGORY_TABLE . ' |
---|
116 | WHERE category_id = '.$_GET['cat_id'].' |
---|
117 | ;'; |
---|
118 | $result = pwg_query($query); |
---|
119 | |
---|
120 | $delval = array(); |
---|
121 | while($row = mysql_fetch_array($result)) |
---|
122 | { |
---|
123 | array_push($delval, $row['image_id']); |
---|
124 | } |
---|
125 | |
---|
126 | foreach ($delval as $delrate) |
---|
127 | { |
---|
128 | $query = ' |
---|
129 | UPDATE ' . IMAGES_TABLE . ' |
---|
130 | SET hit= \'0\' |
---|
131 | WHERE id = \''.$delrate.'\' |
---|
132 | ;'; |
---|
133 | $result = pwg_query($query); |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | if (isset($_POST['plugdprA'])) |
---|
138 | { |
---|
139 | $query = ' |
---|
140 | select image_id |
---|
141 | FROM ' . IMAGE_CATEGORY_TABLE . ' |
---|
142 | WHERE category_id = '.$_GET['cat_id'].' |
---|
143 | ;'; |
---|
144 | $result = pwg_query($query); |
---|
145 | |
---|
146 | $delval = array(); |
---|
147 | while($row = mysql_fetch_array($result)) |
---|
148 | { |
---|
149 | array_push($delval, $row['image_id']); |
---|
150 | } |
---|
151 | |
---|
152 | foreach ($delval as $delrate) |
---|
153 | { |
---|
154 | $query = ' |
---|
155 | UPDATE ' . IMAGES_TABLE . ' |
---|
156 | SET rating_score = \'NULL\' |
---|
157 | WHERE id = \''.$delrate.'\' |
---|
158 | ;'; |
---|
159 | $result = pwg_query($query); |
---|
160 | |
---|
161 | $query = ' |
---|
162 | DELETE FROM ' . RATE_TABLE . ' |
---|
163 | WHERE element_id = \''.$delrate.'\' |
---|
164 | ;'; |
---|
165 | $result = pwg_query($query); |
---|
166 | } |
---|
167 | } |
---|
168 | |
---|
169 | ?> |
---|