PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/wp-email/email-manager.php

https://bitbucket.org/JoeKyy/r-dio-animix
PHP | 366 lines | 311 code | 27 blank | 28 comment | 72 complexity | ec0071c5bd4540c8b7daf7abf4ab697f MD5 | raw file
  1. <?php
  2. /**
  3. * WordPress Plugin: WP-EMail
  4. * Copyright (c) 2012 Lester "GaMerZ" Chan
  5. *
  6. * File Written By:
  7. * - Lester "GaMerZ" Chan
  8. * - http://lesterchan.net
  9. *
  10. * File Information:
  11. * - Manages Your E-Mail Logs
  12. * - wp-content/plugins/wp-email/email-manager.php
  13. */
  14. ### Check Whether User Can Manage EMail
  15. if(!current_user_can('manage_email')) {
  16. die('Access Denied');
  17. }
  18. ### E-Mail Variables
  19. $base_name = plugin_basename('wp-email/email-manager.php');
  20. $base_page = 'admin.php?page='.$base_name;
  21. $email_page = empty($_GET['emailpage'])? 1 : max(intval($_GET['emailpage']), 1);
  22. $email_sortby = empty($_GET['by'])? '' : trim($_GET['by']);
  23. $email_sortby_text = '';
  24. $email_sortorder = empty($_GET['order'])? 'DESC':trim($_GET['order']);
  25. $email_sortorder_text = '';
  26. $email_log_perpage = (empty($_GET['perpage']) || intval($_GET['perpage']) < 1)? 20 : intval($_GET['perpage']);
  27. $email_sort_url = '';
  28. ### Form Sorting URL
  29. if(!empty($email_sortby)) {
  30. $email_sort_url .= '&amp;by='.$email_sortby;
  31. }
  32. if(!empty($email_sortorder)) {
  33. $email_sort_url .= '&amp;order='.$email_sortorder;
  34. }
  35. if(!empty($email_log_perpage)) {
  36. $email_sort_url .= '&amp;perpage='.$email_log_perpage;
  37. }
  38. ### Get Order By
  39. switch($email_sortby) {
  40. case 'id':
  41. $email_sortby = 'email_id';
  42. $email_sortby_text = __('ID', 'wp-email');
  43. break;
  44. case 'fromname':
  45. $email_sortby = 'email_yourname';
  46. $email_sortby_text = __('From Name', 'wp-email');
  47. break;
  48. case 'fromemail':
  49. $email_sortby = 'email_youremail';
  50. $email_sortby_text = __('From E-Mail', 'wp-email');
  51. break;
  52. case 'toname':
  53. $email_sortby = 'email_friendname';
  54. $email_sortby_text = __('To Name', 'wp-email');
  55. break;
  56. case 'toemail':
  57. $email_sortby = 'email_friendemail';
  58. $email_sortby_text = __('To E-Mail', 'wp-email');
  59. break;
  60. case 'postid':
  61. $email_sortby = 'email_postid';
  62. $email_sortby_text = __('Post ID', 'wp-email');
  63. break;
  64. case 'posttitle':
  65. $email_sortby = 'email_posttitle';
  66. $email_sortby_text = __('Post Title', 'wp-email');
  67. break;
  68. case 'ip':
  69. $email_sortby = 'email_ip';
  70. $email_sortby_text = __('IP', 'wp-email');
  71. break;
  72. case 'host':
  73. $email_sortby = 'email_host';
  74. $email_sortby_text = __('Host', 'wp-email');
  75. break;
  76. case 'status':
  77. $email_sortby = 'email_status';
  78. $email_sortby_text = __('Status', 'wp-email');
  79. break;
  80. case 'date':
  81. default:
  82. $email_sortby = 'email_timestamp';
  83. $email_sortby_text = __('Date', 'wp-email');
  84. }
  85. ### Get Sort Order
  86. switch($email_sortorder) {
  87. case 'asc':
  88. $email_sortorder = 'ASC';
  89. $email_sortorder_text = __('Ascending', 'wp-email');
  90. break;
  91. case 'desc':
  92. default:
  93. $email_sortorder = 'DESC';
  94. $email_sortorder_text = __('Descending', 'wp-email');
  95. }
  96. ### Form Processing
  97. if(!empty($_POST['delete_logs'])) {
  98. if(trim($_POST['delete_logs_yes']) == 'yes') {
  99. $delete_logs = $wpdb->query("DELETE FROM $wpdb->email");
  100. if($delete_logs) {
  101. $text = '<font color="green">'.__('All E-Mail Logs Have Been Deleted.', 'wp-email').'</font>';
  102. } else {
  103. $text = '<font color="red">'.__('An Error Has Occured While Deleting All E-Mail Logs.', 'wp-email').'</font>';
  104. }
  105. }
  106. }
  107. ### Get E-Mail Logs Data
  108. $total_email_success = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email WHERE email_status = '".__('Success', 'wp-email')."'");
  109. $total_email_failed = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email WHERE email_status = '".__('Failed', 'wp-email')."'");
  110. $total_email = $total_email_success+$total_email_failed;
  111. ### Checking $email_page and $offset
  112. //if(empty($email_page) || $email_page == 0) { $email_page = 1; }
  113. //if(empty($offset)) { $offset = 0; }
  114. //if(empty($email_log_perpage) || $email_log_perpage == 0) { $email_log_perpage = 20; }
  115. ### Determin $offset
  116. $offset = ($email_page-1) * $email_log_perpage;
  117. ### Determine Max Number Of Polls To Display On Page
  118. if(($offset + $email_log_perpage) > $total_email) {
  119. $max_on_page = $total_email;
  120. } else {
  121. $max_on_page = ($offset + $email_log_perpage);
  122. }
  123. ### Determine Number Of Polls To Display On Page
  124. if (($offset + 1) > ($total_email)) {
  125. $display_on_page = $total_email;
  126. } else {
  127. $display_on_page = ($offset + 1);
  128. }
  129. ### Determing Total Amount Of Pages
  130. $total_pages = ceil($total_email / $email_log_perpage);
  131. ### Get The Logs
  132. $email_logs = $wpdb->get_results("SELECT * FROM $wpdb->email ORDER BY $email_sortby $email_sortorder LIMIT $offset, $email_log_perpage");
  133. ?>
  134. <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
  135. <!-- Manage E-Mail -->
  136. <div class="wrap">
  137. <div id="icon-wp-email" class="icon32"><br /></div>
  138. <h2><?php _e('Manage E-Mail', 'wp-email'); ?></h2>
  139. <h3><?php _e('E-Mail Logs', 'wp-email'); ?></h3>
  140. <p><?php printf(__('Displaying <strong>%s</strong> To <strong>%s</strong> Of <strong>%s</strong> E-Mail Logs', 'wp-email'), number_format_i18n($display_on_page), number_format_i18n($max_on_page), number_format_i18n($total_email)); ?></p>
  141. <p><?php printf(__('Sorted By <strong>%s</strong> In <strong>%s</strong> Order', 'wp-email'), $email_sortby_text, $email_sortorder_text); ?></p>
  142. <?php
  143. $colspan = 7;
  144. if(EMAIL_SHOW_REMARKS) {
  145. $colspan++;
  146. }
  147. ?>
  148. <table class="widefat">
  149. <thead>
  150. <tr>
  151. <th><?php _e('ID', 'wp-email'); ?></th>
  152. <th><?php _e('From', 'wp-email'); ?></th>
  153. <th><?php _e('To', 'wp-email'); ?></th>
  154. <th><?php _e('Date / Time', 'wp-email'); ?></th>
  155. <th><?php _e('IP / Host', 'wp-email'); ?></th>
  156. <?php
  157. if(EMAIL_SHOW_REMARKS) {
  158. echo '<th>'.__('Remarks', 'wp-email').'</th>';
  159. }
  160. ?>
  161. <th><?php _e('Post Title', 'wp-email'); ?></th>
  162. <th><?php _e('Status', 'wp-email'); ?></th>
  163. </tr>
  164. </thead>
  165. <?php
  166. if($email_logs) {
  167. $i = 0;
  168. foreach($email_logs as $email_log) {
  169. if($i%2 == 0) {
  170. $style = '';
  171. } else {
  172. $style = 'class="alternate"';
  173. }
  174. $email_id = intval($email_log->email_id);
  175. $email_yourname = stripslashes($email_log->email_yourname);
  176. $email_youremail = stripslashes($email_log->email_youremail);
  177. $email_friendname = stripslashes($email_log->email_friendname);
  178. $email_friendemail = stripslashes($email_log->email_friendemail);
  179. $email_postid = intval($email_log->email_postid);
  180. $email_remarks = htmlspecialchars(stripslashes($email_log->email_yourremarks));
  181. $email_posttitle = htmlspecialchars(stripslashes($email_log->email_posttitle));
  182. $email_date = mysql2date(sprintf(__('%s @ %s', 'wp-email'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $email_log->email_timestamp));
  183. $email_ip = $email_log->email_ip;
  184. $email_host = $email_log->email_host;
  185. $email_status = stripslashes($email_log->email_status);
  186. echo "<tr $style>\n";
  187. echo "<td>".number_format_i18n($email_id)."</td>\n";
  188. echo "<td>$email_yourname<br />$email_youremail</td>\n";
  189. echo "<td>$email_friendname<br />$email_friendemail</td>\n";
  190. echo "<td>$email_date</td>\n";
  191. echo "<td>$email_ip<br />$email_host</td>\n";
  192. if(EMAIL_SHOW_REMARKS) {
  193. echo '<td>'.$email_remarks.'</td>';
  194. }
  195. echo "<td>$email_posttitle</td>\n";
  196. echo "<td>$email_status</td>\n";
  197. echo '</tr>';
  198. $i++;
  199. }
  200. } else {
  201. echo '<tr><td colspan="'.$colspan.'" align="center"><strong>'.__('No E-Mail Logs Found', 'wp-email').'</strong></td></tr>';
  202. }
  203. ?>
  204. </table>
  205. <!-- <Paging> -->
  206. <?php
  207. if($total_pages > 1) {
  208. ?>
  209. <br />
  210. <table class="widefat">
  211. <tr>
  212. <td align="<?php echo ('rtl' == $text_direction) ? 'right' : 'left'; ?>" width="50%">
  213. <?php
  214. if($email_page > 1 && ((($email_page*$email_log_perpage)-($email_log_perpage-1)) <= $total_email)) {
  215. echo '<strong>&laquo;</strong> <a href="'.$base_page.'&amp;emailpage='.($email_page-1).$email_sort_url.'" title="&laquo; '.__('Previous Page', 'wp-email').'">'.__('Previous Page', 'wp-email').'</a>';
  216. } else {
  217. echo '&nbsp;';
  218. }
  219. ?>
  220. </td>
  221. <td align="<?php echo ('rtl' == $text_direction) ? 'left' : 'right'; ?>" width="50%">
  222. <?php
  223. if($email_page >= 1 && ((($email_page*$email_log_perpage)+1) <= $total_email)) {
  224. echo '<a href="'.$base_page.'&amp;emailpage='.($email_page+1).$email_sort_url.'" title="'.__('Next Page', 'wp-email').' &raquo;">'.__('Next Page', 'wp-email').'</a> <strong>&raquo;</strong>';
  225. } else {
  226. echo '&nbsp;';
  227. }
  228. ?>
  229. </td>
  230. </tr>
  231. <tr class="alternate">
  232. <td colspan="2" align="center">
  233. <?php printf(__('Pages (%s): ', 'wp-postratings'), number_format_i18n($total_pages)); ?>
  234. <?php
  235. if ($email_page >= 4) {
  236. echo '<strong><a href="'.$base_page.'&amp;emailpage=1'.$email_sort_url.'" title="'.__('Go to First Page', 'wp-email').'">&laquo; '.__('First', 'wp-email').'</a></strong> ... ';
  237. }
  238. if($email_page > 1) {
  239. echo ' <strong><a href="'.$base_page.'&amp;emailpage='.($email_page-1).$email_sort_url.'" title="&laquo; '.__('Go to Page', 'wp-email').' '.number_format_i18n($email_page-1).'">&laquo;</a></strong> ';
  240. }
  241. for($i = $email_page - 2 ; $i <= $email_page +2; $i++) {
  242. if ($i >= 1 && $i <= $total_pages) {
  243. if($i == $email_page) {
  244. echo '<strong>['.number_format_i18n($i).']</strong> ';
  245. } else {
  246. echo '<a href="'.$base_page.'&amp;emailpage='.($i).$email_sort_url.'" title="'.__('Page', 'wp-email').' '.number_format_i18n($i).'">'.number_format_i18n($i).'</a> ';
  247. }
  248. }
  249. }
  250. if($email_page < $total_pages) {
  251. echo ' <strong><a href="'.$base_page.'&amp;emailpage='.($email_page+1).$email_sort_url.'" title="'.__('Go to Page', 'wp-email').' '.number_format_i18n($email_page+1).' &raquo;">&raquo;</a></strong> ';
  252. }
  253. if (($email_page+2) < $total_pages) {
  254. echo ' ... <strong><a href="'.$base_page.'&amp;emailpage='.($total_pages).$email_sort_url.'" title="'.__('Go to Last Page', 'wp-email'), 'wp-email'.'">'.__('Last', 'wp-email').' &raquo;</a></strong>';
  255. }
  256. ?>
  257. </td>
  258. </tr>
  259. </table>
  260. <!-- </Paging> -->
  261. <?php
  262. }
  263. ?>
  264. <br />
  265. <form action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>" method="get">
  266. <table class="widefat">
  267. <tr>
  268. <td>
  269. <input type="hidden" name="page" value="<?php echo $base_name; ?>" />
  270. <?php _e('Sort Options:', 'wp-email'); ?>&nbsp;&nbsp;&nbsp;
  271. <select name="by" size="1">
  272. <option value="id"<?php if($email_sortby == 'email_id') { echo ' selected="selected"'; }?>><?php _e('ID', 'wp-email'); ?></option>
  273. <option value="fromname"<?php if($email_sortby == 'email_yourname') { echo ' selected="selected"'; }?>><?php _e('From Name', 'wp-email'); ?></option>
  274. <option value="fromemail"<?php if($email_sortby == 'email_youremail') { echo ' selected="selected"'; }?>><?php _e('From E-Mail', 'wp-email'); ?></option>
  275. <option value="toname"<?php if($email_sortby == 'email_friendname') { echo ' selected="selected"'; }?>><?php _e('To Name', 'wp-email'); ?></option>
  276. <option value="toemail"<?php if($email_sortby == 'email_friendemail') { echo ' selected="selected"'; }?>><?php _e('To E-Mail', 'wp-email'); ?></option>
  277. <option value="date"<?php if($email_sortby == 'email_timestamp') { echo ' selected="selected"'; }?>><?php _e('Date', 'wp-email'); ?></option>
  278. <option value="postid"<?php if($email_sortby == 'email_postid') { echo ' selected="selected"'; }?>><?php _e('Post ID', 'wp-email'); ?></option>
  279. <option value="posttitle"<?php if($email_sortby == 'email_posttitle') { echo ' selected="selected"'; }?>><?php _e('Post Title', 'wp-email'); ?></option>
  280. <option value="ip"<?php if($email_sortby == 'email_ip') { echo ' selected="selected"'; }?>><?php _e('IP', 'wp-email'); ?></option>
  281. <option value="host"<?php if($email_sortby == 'email_host') { echo ' selected="selected"'; }?>><?php _e('Host', 'wp-email'); ?></option>
  282. <option value="status"<?php if($email_sortby == 'email_status') { echo ' selected="selected"'; }?>><?php _e('Status', 'wp-email'); ?></option>
  283. </select>
  284. &nbsp;&nbsp;&nbsp;
  285. <select name="order" size="1">
  286. <option value="asc"<?php if($email_sortorder == 'ASC') { echo ' selected="selected"'; }?>><?php _e('Ascending', 'wp-email'); ?></option>
  287. <option value="desc"<?php if($email_sortorder == 'DESC') { echo ' selected="selected"'; } ?>><?php _e('Descending', 'wp-email'); ?></option>
  288. </select>
  289. &nbsp;&nbsp;&nbsp;
  290. <select name="perpage" size="1">
  291. <?php
  292. for($i=10; $i <= 100; $i+=10) {
  293. if($email_log_perpage == $i) {
  294. echo "<option value=\"$i\" selected=\"selected\">".__('Per Page', 'wp-email').": ".number_format_i18n($i)."</option>\n";
  295. } else {
  296. echo "<option value=\"$i\">".__('Per Page', 'wp-email').": ".number_format_i18n($i)."</option>\n";
  297. }
  298. }
  299. ?>
  300. </select>
  301. <input type="submit" value="<?php _e('Sort', 'wp-email'); ?>" class="button" />
  302. </td>
  303. </tr>
  304. </table>
  305. </form>
  306. </div>
  307. <p>&nbsp;</p>
  308. <!-- E-Mail Stats -->
  309. <div class="wrap">
  310. <h3><?php _e('E-Mail Logs Stats', 'wp-email'); ?></h3>
  311. <br style="clear" />
  312. <table class="widefat">
  313. <tr>
  314. <th><?php _e('Total E-Mails:', 'wp-email'); ?></th>
  315. <td><?php echo number_format_i18n($total_email); ?></td>
  316. </tr>
  317. <tr class="alternate">
  318. <th><?php _e('Total E-Mail Sent:', 'wp-email'); ?></th>
  319. <td><?php echo number_format_i18n($total_email_success); ?></td>
  320. </tr>
  321. <tr>
  322. <th><?php _e('Total E-Mail Failed:', 'wp-email'); ?></th>
  323. <td><?php echo number_format_i18n($total_email_failed); ?></td>
  324. </tr>
  325. </table>
  326. </div>
  327. <p>&nbsp;</p>
  328. <!-- Delete E-Mail Logs -->
  329. <div class="wrap">
  330. <h3><?php _e('Delete E-Mail Logs', 'wp-email'); ?></h3>
  331. <br style="clear" />
  332. <div align="center">
  333. <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
  334. <strong><?php _e('Are You Sure You Want To Delete All E-Mail Logs?', 'wp-email'); ?></strong><br /><br />
  335. <input type="checkbox" name="delete_logs_yes" value="yes" />&nbsp;<?php _e('Yes', 'wp-email'); ?><br /><br />
  336. <input type="submit" name="delete_logs" value="<?php _e('Delete', 'wp-email'); ?>" class="button" onclick="return confirm('<?php _e('You Are About To Delete All E-Mail Logs\nThis Action Is Not Reversible.\n\n Choose [Cancel] to stop, [OK] to delete.', 'wp-email'); ?>')" />
  337. </form>
  338. </div>
  339. </div>