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 | add_event_handler('loc_begin_admin_page', 'plugdphrPf2',60); |
---|
21 | |
---|
22 | function plugdphrPf() |
---|
23 | { |
---|
24 | global $template; |
---|
25 | $template->set_prefilter('picture_modify', 'plugdphrPT'); |
---|
26 | } |
---|
27 | |
---|
28 | function plugdphrPT($content, &$smarty) |
---|
29 | { |
---|
30 | load_language('plugin.lang', PDHR_PATH); |
---|
31 | $search = '#</form>#'; |
---|
32 | |
---|
33 | $replacement = ' |
---|
34 | <div> |
---|
35 | <form method="post" > |
---|
36 | <fieldset> |
---|
37 | <legend>{\'Purge - Plugin Delete Hit/Rate\'|@translate}</legend> |
---|
38 | <div style="text-align:center;"> |
---|
39 | <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} /> |
---|
40 | <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} /> |
---|
41 | </div> |
---|
42 | </fieldset> |
---|
43 | </form> |
---|
44 | </div> |
---|
45 | </form>'; |
---|
46 | |
---|
47 | return preg_replace($search, $replacement, $content); |
---|
48 | } |
---|
49 | |
---|
50 | function plugdphrPf2() |
---|
51 | { |
---|
52 | if (isset($_POST['plugdphphoto'])) |
---|
53 | { |
---|
54 | $query = ' |
---|
55 | UPDATE ' . IMAGES_TABLE . ' |
---|
56 | SET hit= \'0\' |
---|
57 | WHERE id = '.$_GET['image_id'].' |
---|
58 | ;'; |
---|
59 | $result = pwg_query($query); |
---|
60 | } |
---|
61 | |
---|
62 | if (isset($_POST['plugdprphoto'])) |
---|
63 | { |
---|
64 | $query = ' |
---|
65 | UPDATE ' . IMAGES_TABLE . ' |
---|
66 | SET rating_score = \'NULL\' |
---|
67 | WHERE id = '.$_GET['image_id'].' |
---|
68 | ;'; |
---|
69 | $result = pwg_query($query); |
---|
70 | |
---|
71 | $query = ' |
---|
72 | DELETE FROM ' . RATE_TABLE . ' |
---|
73 | WHERE element_id = '.$_GET['image_id'].' |
---|
74 | ;'; |
---|
75 | $result = pwg_query($query); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | //add prefiltre album |
---|
80 | add_event_handler('loc_end_cat_modify', 'plugdphrAf'); |
---|
81 | add_event_handler('loc_end_cat_modify', 'plugdphrAf2'); |
---|
82 | |
---|
83 | function plugdphrAf() |
---|
84 | { |
---|
85 | global $template; |
---|
86 | $template->set_prefilter('album_properties', 'plugdphrAT'); |
---|
87 | } |
---|
88 | |
---|
89 | function plugdphrAT($content, &$smarty) |
---|
90 | { |
---|
91 | load_language('plugin.lang', PDHR_PATH); |
---|
92 | $search = '#</form>#'; |
---|
93 | |
---|
94 | $replacement = ' |
---|
95 | <div> |
---|
96 | |
---|
97 | <fieldset> |
---|
98 | <legend>{\'Purge - Plugin Delete Hit/Rate\'|@translate}</legend> |
---|
99 | <div style="text-align:center;"> |
---|
100 | <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} /> |
---|
101 | <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} /> |
---|
102 | </div> |
---|
103 | </fieldset> |
---|
104 | |
---|
105 | </div> |
---|
106 | </form> |
---|
107 | '; |
---|
108 | |
---|
109 | return preg_replace($search, $replacement, $content); |
---|
110 | } |
---|
111 | |
---|
112 | function plugdphrAf2() |
---|
113 | { |
---|
114 | if (isset($_POST['plugdphA'])) |
---|
115 | { |
---|
116 | $query = ' |
---|
117 | select image_id |
---|
118 | FROM ' . IMAGE_CATEGORY_TABLE . ' |
---|
119 | WHERE category_id = '.$_GET['cat_id'].' |
---|
120 | ;'; |
---|
121 | $result = pwg_query($query); |
---|
122 | |
---|
123 | $delval = array(); |
---|
124 | while($row = mysql_fetch_array($result)) |
---|
125 | { |
---|
126 | array_push($delval, $row['image_id']); |
---|
127 | } |
---|
128 | |
---|
129 | foreach ($delval as $delrate) |
---|
130 | { |
---|
131 | $query = ' |
---|
132 | UPDATE ' . IMAGES_TABLE . ' |
---|
133 | SET hit= \'0\' |
---|
134 | WHERE id = \''.$delrate.'\' |
---|
135 | ;'; |
---|
136 | $result = pwg_query($query); |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | if (isset($_POST['plugdprA'])) |
---|
141 | { |
---|
142 | $query = ' |
---|
143 | select image_id |
---|
144 | FROM ' . IMAGE_CATEGORY_TABLE . ' |
---|
145 | WHERE category_id = '.$_GET['cat_id'].' |
---|
146 | ;'; |
---|
147 | $result = pwg_query($query); |
---|
148 | |
---|
149 | $delval = array(); |
---|
150 | while($row = mysql_fetch_array($result)) |
---|
151 | { |
---|
152 | array_push($delval, $row['image_id']); |
---|
153 | } |
---|
154 | |
---|
155 | foreach ($delval as $delrate) |
---|
156 | { |
---|
157 | $query = ' |
---|
158 | UPDATE ' . IMAGES_TABLE . ' |
---|
159 | SET rating_score = \'NULL\' |
---|
160 | WHERE id = \''.$delrate.'\' |
---|
161 | ;'; |
---|
162 | $result = pwg_query($query); |
---|
163 | |
---|
164 | $query = ' |
---|
165 | DELETE FROM ' . RATE_TABLE . ' |
---|
166 | WHERE element_id = \''.$delrate.'\' |
---|
167 | ;'; |
---|
168 | $result = pwg_query($query); |
---|
169 | } |
---|
170 | } |
---|
171 | } |
---|
172 | ?> |
---|