| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | class WP_SYND_logger { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | 	private static $instance; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | 	public static function get_instance() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | 		if ( isset( self::$instance ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | 			return self::$instance; } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 		self::$instance = new WP_SYND_logger; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 		return self::$instance; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | 	private function __construct() {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	public function success( $title, $msg ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 		return $this->create_log( 'success', $title, $msg ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	public function error( $title, $msg ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 		return $this->create_log( 'error', $title, $msg ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 	private function create_log( $status, $title, $msg ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		$args = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 					'post_title'    => $title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 					'post_content'  => $msg, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 					'post_author'   => 1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 					'post_status'   => 'publish', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 					'post_type'     => 'wp-syndicate-log', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 				); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 		$post_id = wp_insert_post( $args ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		$post_id && wp_set_object_terms( $post_id, $status, 'log-category', true ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		return $post_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | class WP_SYND_Log_Operator { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	private $event = 'wp_syndicate_log_delete_log'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	private $key = 'twicedaily'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	public function __construct() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		add_action( 'init', array( $this, 'init' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		add_action( $this->event, array( $this, 'delete_log' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		add_action( 'restrict_manage_posts', array( $this, 'restrict_manage_posts' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	public function init() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		$capabilities = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 			'read_feed_log', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 			'edit_feed_log', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 			'delete_feed_log', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 			'edit_feed_logs', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 			'edit_others_feed_logs', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			'publish_feed_logs', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 			'read_private_feed_logs', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 			'delete_feed_logs', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 			'delete_private_feed_logs', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 			'delete_published_feed_logs', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 			'delete_others_feed_logs', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 			'edit_private_feed_logs', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 			'edit_published_feed_logs', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		$role = get_role( 'administrator' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		foreach ( $capabilities as $cap ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 			$role->add_cap( $cap ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		register_post_type( 'wp-syndicate-log', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 			array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 										'labels' => array( 'name' => __( 'Syndication Log', WPSYND_DOMAIN ) ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 										'public' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 										'publicly_queryable' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 										'has_archive' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 										'hierarchical' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 										'supports' => array( 'title', 'editor' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 										'rewrite' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 										'can_export' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 										'menu_position' => 27, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 										'capability_type' => 'feed_log', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 										'capabilities'    => $capabilities, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 										'map_meta_cap' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 										'exclude_from_search' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 									)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 									register_taxonomy( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 										'log-category', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 										'wp-syndicate-log', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 										array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 										'label' => __( 'status', WPSYND_DOMAIN ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 										'public' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 										'query_var' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 										'show_ui' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 										'hierarchical' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 										'show_admin_column' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 										)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 	public function set_event() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 		$action_time = time() + 60; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 		wp_schedule_event( $action_time, $this->key, $this->event ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		spawn_cron( $action_time ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 	public function delete_event() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 		wp_clear_scheduled_hook( $this->event ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	public function delete_log() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 		$args = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 				'posts_per_page'   => 1000, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 				'post_type'        => 'wp-syndicate-log', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 				'suppress_filters' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 		add_filter( 'post_where', array( $this, 'post_where' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		$results = get_posts( $args ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 		remove_filter( 'post_where', array( $this, 'post_where' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 		if ( ! empty( $results ) && is_array( $results ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 			foreach ( $results as $result ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 				wp_delete_post( $result->ID, true ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	public function post_where($where) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 		$options = get_option( 'wp_syndicate_options', 14 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 		$term_day = ! empty( $options['delete_log_term'] ) ? $options['delete_log_term'] : 7; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 		$date = date_i18n( 'Y/m/d H:i:s', strtotime( '-' . $term_day . ' day' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 		$where .= " AND post_date < '" . $date . "'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 		return $where; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 	public function restrict_manage_posts() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 		global $post_type; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 		if ( is_object_in_taxonomy( $post_type, 'log-category' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 			$terms = get_terms( 'log-category' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 			$get = isset( $_GET['term'] ) ? $_GET['term'] : ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | <select name="term"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 	<option value="0"></option> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 	<?php foreach ( $terms as $term ) : ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 		<option <?php selected( $get, $term->slug ); ?> value="<?php echo esc_attr( $term->slug ); ?>"><?php echo esc_html( $term->name ); ?></option> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 	<?php endforeach; ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | </select> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | <input type="hidden" name="taxonomy" value="log-category" /> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 154 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 155 |  |  |  |