/** * Callback for the cn_delete_log hook which processes the delete action and then redirects back to the current admin page. * * @access private * @since 8.3 * @static * * @uses current_user_can() * @uses check_admin_referer() * @uses cnLog::delete() * @uses cnMessage::set() * @uses add_query_arg() * @uses wp_get_referer() * @uses wp_safe_redirect() */ public static function deleteLog() { if (current_user_can('install_plugins')) { $id = 0; if (isset($_GET['id']) && !empty($_GET['id'])) { $id = absint($_GET['id']); } check_admin_referer('log_delete_' . $id); cnLog::delete($id); cnMessage::set('success', 'log_delete'); $url = add_query_arg(array('type' => isset($_GET['type']) && !empty($_GET['type']) && '-1' !== $_GET['type'] ? $_GET['type'] : FALSE), wp_get_referer()); wp_safe_redirect($url); exit; } }
/** * @access public * @since 8.2.10 * @static * * @uses add_action() * * @return cnLog */ public static function instance() { if (!isset(self::$instance) && !self::$instance instanceof cnLog) { self::$instance = new cnLog(); // Register log post type. add_action('init', array(__CLASS__, 'registerPostType'), 1); // Register types taxonomy and default types. add_action('init', array(__CLASS__, 'registerTaxonomy'), 1); // Register the actions for the logs views. add_action('init', array(__CLASS__, 'registerViews')); // Create a cron job for this hook to start pruning. add_action('cn_log_purge_process', array(__CLASS__, 'purge')); // Register a metabox for debugging purposes. add_action('add_meta_boxes', array(__CLASS__, 'registerMetabox')); } return self::$instance; }
/** * Callback used to render the log view of the log type being viewed. * * @access private * @since 8.3 * @static * * @uses current_user_can() * @uses wp_list_pluck() * @uses esc_url() * @uses self_admin_url() * @uses cnLog::types() * @uses cnLog_Email::types() * @uses cnHTML::select() * @uses submit_button() * @uses do_action() */ public static function logs() { if (!current_user_can('install_plugins')) { return; } $current = cnLog_Email::LOG_TYPE; $views = wp_list_pluck(cnLog::views(), 'id'); if (isset($_GET['view']) && array_key_exists($_GET['view'], $views)) { $current = $_GET['view']; } ?> <div class="wrap" id="cn-logs"> <form id="cn-log-type" method="get" action="<?php echo esc_url(self_admin_url('admin.php')); ?> "> <input type="hidden" name="page" value="connections_tools"/> <input type="hidden" name="tab" value="logs"/> <?php $allLogTypes = wp_list_pluck(cnLog::types(), 'name', 'id'); $emailLogTypes = wp_list_pluck(cnLog_Email::types(), 'name', 'id'); unset($emailLogTypes[cnLog_Email::LOG_TYPE]); cnHTML::select(array('id' => 'view', 'options' => array_diff_assoc($allLogTypes, $emailLogTypes)), $current); submit_button('Switch', 'secondary', 'action', FALSE, array('id' => 'log-type-submit')); ?> </form> <?php do_action('cn_logs_view_' . $current); ?> </div> <?php }
/** * Get the email logs for the type being viewed. * * @access private * @since 8.3 * * @return array */ private function getLogs() { /** If the email log type is @see cnLog_Email::LOG_TYPE, then return all email log types */ if (cnLog_Email::LOG_TYPE == $this->type) { $types = wp_list_pluck(cnLog_Email::types(), 'name', 'id'); $this->type = array_keys($types); } elseif ('' == $this->type || '-1' == $this->type) { $this->type = array_keys(wp_list_pluck(cnLog_Email::types(), 'name', 'id')); } $data = array(); $query = array('post_parent' => null, 'type' => $this->type, 'paged' => $this->offset, 'posts_per_page' => $this->number, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, 's' => $this->search); $logs = cnLog::getConnected($query); if ($logs) { foreach ($logs as $log) { $meta = get_post_custom($log->ID); $data[] = array('id' => $log->ID, 'date' => date_i18n('Y-m-d H:i:s', strtotime($log->post_date)), 'subject' => $log->post_title, 'from' => $meta[cnLog::POST_META_PREFIX . 'from'][0], 'to' => $meta[cnLog::POST_META_PREFIX . 'to'][0], 'cc' => $meta[cnLog::POST_META_PREFIX . 'cc'][0], 'bcc' => $meta[cnLog::POST_META_PREFIX . 'bcc'][0], 'attachments' => $meta[cnLog::POST_META_PREFIX . 'attachments'][0], 'status' => $meta[cnLog::POST_META_PREFIX . 'response'][0]); } } return $data; }
/** * Parse the email headers for the "X-CN-Log-Type" header to set the log type. * * If header does not exist or is set to an invalid type the default type will be set. * * @access private * @since 8.2.10 * @static * * @param array $headers * * @return string */ private static function parseLogType($headers) { $type = self::LOG_TYPE; foreach ($headers as $header) { if (FALSE !== strpos($header, 'X-CN-Log-Type: ')) { $type = str_replace('X-CN-Log-Type: ', '', $header); } } return cnLog::valid($type) ? $type : self::LOG_TYPE; }