Changeset 2378212
- Timestamp:
- 09/09/2020 05:45:02 PM (6 years ago)
- Location:
- easy-prayer/trunk
- Files:
-
- 4 edited
-
easy-prayer.php (modified) (10 diffs)
-
help/readme.php (modified) (3 diffs)
-
js/adminpanel.js (modified) (1 diff)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
easy-prayer/trunk/easy-prayer.php
r2267045 r2378212 1 1 <?php 2 3 /* 4 Plugin Name: Easy Prayer 5 Plugin URI: http://prayer-plugin.com 6 description: a plugin to create, collect, store, and display prayer requests 7 Version: 1.0 8 Author: Cameron C. 9 Author URI: http://cameronc.com 10 */ 11 if ( !defined( 'ABSPATH' ) ) { 12 exit; 2 /* 3 Plugin Name: Easy Prayer 4 Plugin URI: http://prayer-plugin.com 5 description: a plugin to create, collect, store, and display prayer requests 6 Version: 1.1 7 Author: Cameron C. 8 Author URI: http://cameronc.com 9 */ 10 11 if ( ! function_exists( 'ep_fs' ) ) { 12 // Create a helper function for easy SDK access. 13 function ep_fs() { 14 global $ep_fs; 15 16 if ( ! isset( $ep_fs ) ) { 17 // Include Freemius SDK. 18 require_once dirname(__FILE__) . '/freemius/start.php'; 19 20 $ep_fs = fs_dynamic_init( array( 21 'id' => '5756', 22 'slug' => 'easy-prayer', 23 'type' => 'plugin', 24 'public_key' => 'pk_24ce60a8ae366b3eff0f74bffcaeb', 25 'is_premium' => false, 26 'has_addons' => false, 27 'has_paid_plans' => false, 28 'menu' => array( 29 'slug' => 'easy-prayer/php/adminpage.php', 30 'support' => false, 31 ), 32 ) ); 33 } 34 35 return $ep_fs; 36 } 37 38 // Init Freemius. 39 ep_fs(); 40 // Signal that SDK was initiated. 41 do_action( 'ep_fs_loaded' ); 13 42 } 14 43 15 if ( function_exists( 'ep_fs' ) ) { 16 ep_fs()->set_basename( false, __FILE__ ); 17 } else { 18 // DO NOT REMOVE THIS IF, IT IS ESSENTIAL FOR THE `function_exists` CALL ABOVE TO PROPERLY WORK. 19 if ( !function_exists( 'ep_fs' ) ) { 20 21 if ( !function_exists( 'ep_fs' ) ) { 22 // Create a helper function for easy SDK access. 23 function ep_fs() 24 { 25 global $ep_fs ; 26 27 if ( !isset( $ep_fs ) ) { 28 // Include Freemius SDK. 29 require_once dirname( __FILE__ ) . '/freemius/start.php'; 30 $ep_fs = fs_dynamic_init( array( 31 'id' => '5756', 32 'slug' => 'easy-prayer', 33 'type' => 'plugin', 34 'public_key' => 'pk_24ce60a8ae366b3eff0f74bffcaeb', 35 'is_premium' => false, 36 'premium_suffix' => 'Premium', 37 'has_addons' => false, 38 'has_paid_plans' => true, 39 'trial' => array( 40 'days' => 7, 41 'is_require_payment' => false, 42 ), 43 'menu' => array( 44 'slug' => 'easy-prayer/php/adminpage.php', 45 'support' => false, 46 ), 47 'is_live' => true, 48 ) ); 49 } 50 51 return $ep_fs; 52 } 53 54 // Init Freemius. 55 ep_fs(); 56 // Signal that SDK was initiated. 57 do_action( 'ep_fs_loaded' ); 58 } 59 60 } 61 global $easy_prayer_db_version ; 44 global $easy_prayer_db_version; 62 45 $easy_prayer_db_version = '1.0'; 46 63 47 //create tables and check for updates 64 function easy_prayer_install() 65 { 66 global $wpdb ; 67 global $easy_prayer_db_version ; 48 function easy_prayer_install() { 49 global $wpdb; 50 global $easy_prayer_db_version; 68 51 $installed_ver = get_option( "easy_prayer_db_version" ); 52 69 53 //Requests 70 54 $table_name = $wpdb->prefix . 'easy_prayer_requests'; 55 71 56 $charset_collate = $wpdb->get_charset_collate(); 72 $sql = "CREATE TABLE " . $table_name . " (\n id INT NOT NULL AUTO_INCREMENT,\n date DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL,\n fname TEXT NOT NULL,\n lname TEXT NOT NULL,\n request TEXT NOT NULL,\n email TEXT NOT NULL,\n location TEXT NOT NULL,\n status TEXT NOT NULL,\n category TEXT NOT NULL,\n ip TEXT NOT NULL,\n PRIMARY KEY (id)\n ) " . $charset_collate . ";"; 73 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 57 58 $sql = "CREATE TABLE " . $table_name . " ( 59 id INT NOT NULL AUTO_INCREMENT, 60 date DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL, 61 fname TEXT NOT NULL, 62 lname TEXT NOT NULL, 63 request TEXT NOT NULL, 64 email TEXT NOT NULL, 65 location TEXT NOT NULL, 66 status TEXT NOT NULL, 67 category TEXT NOT NULL, 68 ip TEXT NOT NULL, 69 PRIMARY KEY (id) 70 ) ". $charset_collate .";"; 71 72 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 74 73 dbDelta( $sql ); 74 75 75 //Categories 76 76 $table_name = $wpdb->prefix . 'easy_prayer_categories'; 77 $sql = "CREATE TABLE " . $table_name . " (\n id INT NOT NULL AUTO_INCREMENT,\n name TEXT NOT NULL,\n status TEXT NOT NULL,\n PRIMARY KEY (id)\n ) " . $charset_collate . ";"; 78 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 77 78 $sql = "CREATE TABLE " . $table_name . " ( 79 id INT NOT NULL AUTO_INCREMENT, 80 name TEXT NOT NULL, 81 status TEXT NOT NULL, 82 PRIMARY KEY (id) 83 ) ". $charset_collate .";"; 84 85 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 79 86 dbDelta( $sql ); 87 80 88 //settings 81 89 $table_name = $wpdb->prefix . 'easy_prayer_settings'; 82 $sql = "CREATE TABLE " . $table_name . " (\n id INT NOT NULL AUTO_INCREMENT,\n name TEXT NOT NULL,\n status TEXT NOT NULL,\n PRIMARY KEY (id)\n ) " . $charset_collate . ";"; 83 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 90 91 $sql = "CREATE TABLE " . $table_name . " ( 92 id INT NOT NULL AUTO_INCREMENT, 93 name TEXT NOT NULL, 94 status TEXT NOT NULL, 95 PRIMARY KEY (id) 96 ) ". $charset_collate .";"; 97 98 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 84 99 dbDelta( $sql ); 100 85 101 add_option( 'easy_prayer_db_version', $easy_prayer_db_version ); 102 103 86 104 if ( $installed_ver != $easy_prayer_db_version ) { 105 87 106 //updates go here 88 107 } 89 108 } 90 109 91 110 //put init data in database for user 92 function easy_prayer_install_data() 93 {94 global $wpdb ; 95 $exist = $wpdb->get_var( "SELECT COUNT(*) FROM " . $wpdb->prefix . "easy_prayer_requests");96 97 if ( $exist == '0' ){111 function easy_prayer_install_data() { 112 global $wpdb; 113 114 $exist = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix ."easy_prayer_requests"); 115 116 if($exist == '0'){ 98 117 $welcome_fname = 'John'; 99 118 $welcome_lname = 'Smith'; … … 106 125 $welcome_category = '1'; 107 126 $welcome_ip = '0.0.0.0'; 127 108 128 $table_name = $wpdb->prefix . 'easy_prayer_requests'; 109 129 //insert into requests 110 $wpdb->insert( $table_name, array( 111 'date' => current_time( 'mysql' ), 112 'fname' => $welcome_fname, 113 'lname' => $welcome_lname, 114 'request' => $welcome_request, 115 'email' => $welcome_email, 116 'location' => $welcome_location, 117 'status' => $welcome_status, 118 'category' => $welcome_category, 119 'ip' => $welcome_ip, 120 ) ); 121 } 122 123 $exist = $wpdb->get_var( "SELECT COUNT(*) FROM " . $wpdb->prefix . "easy_prayer_categories" ); 124 125 if ( $exist == '0' ) { 130 $wpdb->insert( 131 $table_name, 132 array( 133 'date' => current_time( 'mysql' ), 134 'fname' => $welcome_fname, 135 'lname' => $welcome_lname, 136 'request' => $welcome_request, 137 'email' => $welcome_email, 138 'location' => $welcome_location, 139 'status' => $welcome_status, 140 'category' => $welcome_category, 141 'ip' => $welcome_ip 142 ) 143 ); 144 } 145 146 $exist = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix ."easy_prayer_categories"); 147 148 if($exist == '0'){ 126 149 //insert category 127 150 $table_name = $wpdb->prefix . 'easy_prayer_categories'; 128 $wpdb->insert( $table_name, array( 129 'name' => 'Personal', 130 'status' => '1', 131 ) ); 132 } 133 134 $exist = $wpdb->get_var( "SELECT COUNT(*) FROM " . $wpdb->prefix . "easy_prayer_settings" ); 135 136 if ( $exist == '0' ) { 151 152 $wpdb->insert( 153 $table_name, 154 array( 155 'name' => 'Personal', 156 'status' => '1' 157 ) 158 ); 159 } 160 161 $exist = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix ."easy_prayer_settings"); 162 163 if($exist == '0'){ 137 164 //insert setting 138 165 $table_name = $wpdb->prefix . 'easy_prayer_settings'; 139 $wpdb->insert( $table_name, array( 140 'name' => 'ip', 141 'status' => '0', 142 ) ); 143 } else { 166 167 $wpdb->insert( 168 $table_name, 169 array( 170 'name' => 'ip', 171 'status' => '0' 172 ) 173 ); 174 }else{ 144 175 // empty settings table 145 $delete = $wpdb->query( "TRUNCATE TABLE " . $wpdb->prefix . "easy_prayer_settings" ); 176 $delete = $wpdb->query("TRUNCATE TABLE ". $wpdb->prefix."easy_prayer_settings"); 177 146 178 //insert settings 147 179 $table_name = $wpdb->prefix . 'easy_prayer_settings'; 148 $wpdb->insert( $table_name, array( 149 'name' => 'ip', 150 'status' => '0', 151 ) ); 152 } 153 154 } 155 180 181 $wpdb->insert( 182 $table_name, 183 array( 184 'name' => 'ip', 185 'status' => '0' 186 ) 187 ); 188 } 189 190 191 } 192 193 194 156 195 register_activation_hook( __FILE__, 'easy_prayer_install' ); 157 196 register_activation_hook( __FILE__, 'easy_prayer_install_data' ); 197 198 158 199 //shortcode function to create request form; will need some how get post 159 function easy_prayer_form_output() 160 {161 global $wpdb ; 200 function easy_prayer_form_output() { 201 global $wpdb; 202 162 203 //get all active categories from the database 163 $arr = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}" . "easy_prayer_categories WHERE status != 2 AND status != 0");204 $arr = $wpdb->get_results("SELECT * FROM $wpdb->prefix"."easy_prayer_categories WHERE status != 2 AND status != 0"); 164 205 $output = ' 165 206 <form action="" method="post"> … … 179 220 Category:<select name="category" required> 180 221 '; 181 $outputmid = ''; 182 foreach ( $arr as $results ) { 183 $output .= '<option value="' . esc_attr( $results->id ) . '" id="' . esc_attr( $results->id ) . '" name="' . esc_attr( $results->id ) . '">' . esc_attr( $results->name ) . '</option>'; 184 } 185 $outputend = ' 222 223 $outputmid = ''; 224 foreach ($arr as $results){ 225 $output .= '<option value="'.esc_attr($results->id).'" id="'.esc_attr($results->id).'" name="'. esc_attr($results->id).'">'.esc_attr($results->name) .'</option>'; 226 } 227 228 $outputend = ' 186 229 </select> 187 230 </div> … … 191 234 </form> 192 235 '; 193 194 if ( isset( $_POST['sub'] ) ){195 global $wpdb;196 197 if ( !easyPrayerbadword( $_POST['fname'] ) ){198 $fname = filter_var( $_POST['fname'], FILTER_SANITIZE_STRING);199 $fname = sanitize_text_field( $fname);200 } else{236 237 if ( isset( $_POST['sub'])){ 238 global $wpdb; 239 240 if(!easyPrayerbadword($_POST['fname'])){ 241 $fname = filter_var($_POST['fname'], FILTER_SANITIZE_STRING); 242 $fname = sanitize_text_field($fname); 243 }else{ 201 244 exit; 202 245 } 203 204 205 if ( !easyPrayerbadword( $_POST['lname'] ) ) { 206 $lname = filter_var( $_POST['lname'], FILTER_SANITIZE_STRING ); 207 $lname = sanitize_text_field( $lname ); 208 } else { 246 if(!easyPrayerbadword($_POST['lname'])){ 247 $lname = filter_var($_POST['lname'], FILTER_SANITIZE_STRING); 248 $lname = sanitize_text_field($lname); 249 }else{ 209 250 exit; 210 251 } 211 212 213 if ( !easyPrayerbadword( $_POST['request'] ) ) { 214 $request = filter_var( $_POST['request'], FILTER_SANITIZE_STRING ); 215 $request = sanitize_textarea_field( $request ); 216 } else { 252 if(!easyPrayerbadword($_POST['request'])){ 253 $request = filter_var($_POST['request'], FILTER_SANITIZE_STRING); 254 $request = sanitize_textarea_field($request); 255 }else{ 217 256 exit; 218 257 } 219 220 221 if ( !easyPrayerbadword( $_POST['email'] ) ) { 222 $email = filter_var( $_POST['email'], FILTER_SANITIZE_STRING ); 223 $email = sanitize_text_field( $email ); 224 } else { 258 if(!easyPrayerbadword($_POST['email'])){ 259 $email = filter_var($_POST['email'], FILTER_SANITIZE_STRING); 260 $email = sanitize_text_field($email); 261 }else{ 225 262 exit; 226 263 } 227 228 229 if ( !easyPrayerbadword( $_POST['location'] ) ) { 230 $location = filter_var( $_POST['location'], FILTER_SANITIZE_STRING ); 231 $location = sanitize_text_field( $location ); 232 } else { 264 if(!easyPrayerbadword($_POST['location'])){ 265 $location = filter_var($_POST['location'], FILTER_SANITIZE_STRING); 266 $location = sanitize_text_field($location); 267 }else{ 233 268 exit; 234 269 } 235 270 236 271 //if ip is set, check database for currently approved requests by ip (status = 1)or previously approved requests by ip (status = 3) 237 272 //if query return results, auto approve request 238 239 if ( isset( $_POST['ip'] ) && $_POST['ip'] != "0.0.0.0" ) { 240 $settings = $wpdb->get_results( 'SELECT * FROM $wpdb->prefix' . 'easy_prayer_settings WHERE name = "ip"' ); 241 foreach ( $setting as $result ) { 242 if ( $setting->status == 1 ) { 273 if(isset($_POST['ip']) && $_POST['ip'] != "0.0.0.0"){ 274 $settings = $wpdb->get_results('SELECT * FROM $wpdb->prefix'.'easy_prayer_settings WHERE name = "ip"'); 275 foreach($setting as $result){ 276 if($setting->status == 1){ 243 277 $settings = 1; 244 278 } 245 279 } 246 247 if ( $settings == 1 ) { 248 $ip = filter_var( $_POST['ip'], FILTER_SANITIZE_STRING ); 249 $ip = sanitize_text_field( $ip ); 250 $check = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}" . "easy_prayer_requests WHERE status = 1 OR status = 3 AND ip = " . $ip ); 251 252 if ( $check != 0 ) { 280 if($settings == 1){ 281 $ip = filter_var($_POST['ip'], FILTER_SANITIZE_STRING); 282 $ip = sanitize_text_field($ip); 283 $check = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->prefix"."easy_prayer_requests WHERE status = 1 OR status = 3 AND ip = ".$ip ); 284 if($check != 0){ 253 285 $status = 1; 254 } else{286 }else{ 255 287 $status = 0; 256 288 } 257 258 } else { 289 }else{ 259 290 $status = 0; 260 291 } 261 262 } else { 292 }else{ 263 293 $status = 0; 264 294 $ip = '0.0.0.0'; 265 295 } 266 296 267 297 //may allow custom categories 268 269 if ( !easyPrayerbadword( $_POST['category'] ) ) { 270 $category = filter_var( $_POST['category'], FILTER_SANITIZE_STRING ); 271 $category = sanitize_text_field( $category ); 272 } else { 298 if(!easyPrayerbadword($_POST['category'])){ 299 $category = filter_var($_POST['category'], FILTER_SANITIZE_STRING); 300 $category = sanitize_text_field($category); 301 }else{ 273 302 exit; 274 303 } 275 304 276 305 $table_name = $wpdb->prefix . 'easy_prayer_requests'; 277 $wpdb->insert( $table_name, array( 278 'date' => current_time( 'mysql' ), 279 'fname' => $fname, 280 'lname' => $lname, 281 'request' => $request, 282 'email' => $email, 283 'location' => $location, 284 'status' => $status, 285 'category' => $category, 286 'ip' => $ip, 287 ) ); 306 307 $wpdb->insert( 308 $table_name, 309 array( 310 'date' => current_time( 'mysql' ), 311 'fname' => $fname, 312 'lname' => $lname, 313 'request' => $request, 314 'email' => $email, 315 'location' => $location, 316 'status' => $status, 317 'category' => $category, 318 'ip' => $ip 319 ) 320 ); 288 321 $_POST = array(); 289 322 return $output . $outputmid . $outputend; 290 } else { 323 324 }else{ 291 325 return $output . $outputmid . $outputend; 292 326 } 293 294 } 295 327 } 296 328 add_shortcode( 'easy_prayer_form', 'easy_prayer_form_output' ); 329 297 330 //shortcode function to create request form 298 299 if ( ep_fs()->can_use_premium_code() ) { 300 function easy_prayer_requests_output() 301 { 302 global $wpdb ; 303 $arr = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}" . "easy_prayer_requests WHERE status = 1" ); 304 $cate = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}" . "easy_prayer_categories WHERE status = 1" ); 305 $string = ""; 306 //alter rows here 307 foreach ( $arr as $request ) { 308 $string = $string . "<div id='easy_prayer'>"; 309 foreach ( $cate as $category ) { 310 311 if ( $request->category == $category->id ) { 312 $string = $string . "<span id='fname'>" . esc_attr( $request->fname ) . "</span> "; 313 $string = $string . "<span id='lname'>" . esc_attr( $request->lname ) . "</span>"; 314 $string = $string . "<span id='category' style='float: right'>" . esc_attr( $category->name ) . "</span>"; 315 $string = $string . "<div id='request' style='text-align: center'>" . esc_attr( $request->request ) . "</div>"; 316 $string = $string . "<span id='location'>" . esc_attr( $request->location ) . "</span>"; 317 $string = $string . "</div>"; 318 $string = $string . "<hr>"; 319 } 320 331 function easy_prayer_requests_output() { 332 global $wpdb; 333 334 $arr = $wpdb->get_results("SELECT * FROM $wpdb->prefix"."easy_prayer_requests WHERE status = 1"); 335 $cate = $wpdb->get_results("SELECT * FROM $wpdb->prefix"."easy_prayer_categories WHERE status = 1"); 336 $string = ""; 337 //alter rows here 338 foreach($arr as $request){ 339 $string = $string . "<div id='easy_prayer'>"; 340 foreach($cate as $category){ 341 if($request->category == $category->id){ 342 $string = $string . "<span id='fname'>". esc_attr($request->fname) ."</span> "; 343 $string = $string . "<span id='lname'>". esc_attr($request->lname) ."</span>"; 344 $string = $string . "<span id='category' style='float: right'>". esc_attr($category->name) ."</span>"; 345 $string = $string . "<div id='request' style='text-align: center'>". esc_attr($request->request) ."</div>"; 346 $string = $string . "<span id='location'>". esc_attr($request->location) ."</span>"; 347 $string = $string . "</div>"; 348 $string = $string . "<hr>"; 321 349 } 322 350 } 323 return $string; 324 } 325 326 add_shortcode( 'easy_prayer_requests', 'easy_prayer_requests_output' ); 327 } else { 328 function easy_prayer_requests_output() 329 { 330 $string = "<p>Easy Prayer Requests shortcode is a Premium Feature</p>"; 331 return $string; 332 } 333 334 add_shortcode( 'easy_prayer_requests', 'easy_prayer_requests_output' ); 335 } 336 351 } 352 return $string; 353 } 354 add_shortcode( 'easy_prayer_requests', 'easy_prayer_requests_output' ); 355 356 357 358 359 337 360 //checks for updates 338 function easy_prayer_update_db_check() 339 { 340 global $easy_prayer_db_version ; 361 function easy_prayer_update_db_check() { 362 global $easy_prayer_db_version; 341 363 if ( get_site_option( 'easy_prayer_db_version' ) != $easy_prayer_db_version ) { 342 364 easy_prayer_install(); 343 365 } 344 366 } 345 346 367 add_action( 'plugins_loaded', 'easy_prayer_update_db_check' ); 368 369 370 347 371 //add admin panel 348 function easy_prayer_setup_menu() 349 { 350 add_menu_page( 351 'Easy Prayer Page', 352 'Easy Prayer', 353 'manage_options', 354 'easy-prayer/php/adminpage.php', 355 '', 356 'dashicons-format-status' 357 ); 358 add_submenu_page( 359 'easy-prayer/php/adminpage.php', 360 'Help', 361 'Easy Prayer Help', 362 'manage_options', 363 'easy-prayer/help/readme.php', 364 '' 365 ); 366 } 367 368 add_action( 'admin_menu', 'easy_prayer_setup_menu' ); 372 function easy_prayer_setup_menu(){ 373 374 add_menu_page( 'Easy Prayer Page', 'Easy Prayer', 'manage_options', 'easy-prayer/php/adminpage.php', '', 'dashicons-format-status'); 375 add_submenu_page('easy-prayer/php/adminpage.php', 'Help', 'Easy Prayer Help', 'manage_options', 'easy-prayer/help/readme.php', ''); 376 } 377 add_action('admin_menu', 'easy_prayer_setup_menu'); 378 369 379 //loads css and JS for admin panel 370 function easyPrayerAdmin_enqueue( $hook ) 371 { 380 function easyPrayerAdmin_enqueue($hook){ 372 381 //only for our special plugin admin page 373 if ( 'easy-prayer/php/adminpage.php' != $hook ) { 374 return; 375 } 382 383 if( 'easy-prayer/php/adminpage.php' != $hook ){ 384 return; 385 } 386 376 387 //include jquery and free $ 377 388 //if not done on this level, datatables has an uncaught type error $. 378 389 //if the inline script is added to the datatables, it has no affect 379 wp_enqueue_script( 'jquery' ); 380 wp_add_inline_script( 'jquery', '$ = jQuery.noConflict();' ); 390 wp_enqueue_script('jquery'); 391 wp_add_inline_script( 'jquery', '$ = jQuery.noConflict();'); 392 381 393 //admin css 382 wp_register_style( 'easyPrayerAdminPanelCss', plugins_url( '/easy-prayer/css/pluginpage.css' ) ); 383 wp_enqueue_style( 'easyPrayerAdminPanelCss' ); 394 wp_register_style('easyPrayerAdminPanelCss', plugins_url('/easy-prayer/css/pluginpage.css')); 395 wp_enqueue_style('easyPrayerAdminPanelCss'); 396 384 397 //adding datatables js 385 wp_register_style( 'easyPrayerDataTableCss', plugins_url( '/easy-prayer/js/DataTables/datatables.min.css' ) ); 386 wp_enqueue_style( 'easyPrayerDataTableCss' ); 387 wp_enqueue_script( 'easyPrayerDataTable', plugins_url( '/easy-prayer/js/DataTables/datatables.min.js' ), array( 'jquery' ) ); 398 wp_register_style('easyPrayerDataTableCss', plugins_url('/easy-prayer/js/DataTables/datatables.min.css')); 399 wp_enqueue_style('easyPrayerDataTableCss'); 400 wp_enqueue_script('easyPrayerDataTable',plugins_url('/easy-prayer/js/DataTables/datatables.min.js'), array('jquery')); 401 402 388 403 //modal js 389 wp_register_style( 'easyPrayerModalCss', plugins_url( '/easy-prayer/js/modal/jquery.modal.min.css' ) ); 390 wp_enqueue_style( 'easyPrayerModalCss' ); 391 wp_enqueue_script( 'easyPrayerModal', plugins_url( '/easy-prayer/js/modal/jquery.modal.min.js' ), array( 'jquery' ) ); 392 $location = plugins_url( '/easy-prayer/' ); 404 wp_register_style('easyPrayerModalCss', plugins_url('/easy-prayer/js/modal/jquery.modal.min.css')); 405 wp_enqueue_style('easyPrayerModalCss'); 406 wp_enqueue_script('easyPrayerModal',plugins_url('/easy-prayer/js/modal/jquery.modal.min.js'), array('jquery')); 407 408 $location = plugins_url('/easy-prayer/'); 393 409 $params = array( 394 'filepath' => $location,395 'adminpath' => admin_url() ,410 'filepath' => $location, 411 'adminpath' => admin_url() 396 412 ); 397 //load free 398 wp_enqueue_script( 'easyPrayeradminpanel', plugins_url( 'easy-prayer/js/adminpanelfree.js' ), array( 'jquery' ) ); 413 414 //load premium 415 wp_enqueue_script('easyPrayeradminpanel',plugins_url('easy-prayer/js/adminpanel.js'), array('jquery')); 416 399 417 wp_localize_script( 'easyPrayeradminpanel', 'easyPrayerParams', $params ); 400 418 $easyprayernonce = wp_create_nonce( 'easyprayernonce' ); 401 wp_localize_script( 'easyPrayeradminpanel', 'my_ajax_obj', array( 402 'ajax_url' => admin_url( 'admin-ajax.php' ), 403 'nonce' => $easyprayernonce, 404 ) ); 405 } 406 407 add_action( 'admin_enqueue_scripts', 'easyPrayerAdmin_enqueue' ); 408 //functions begin 419 wp_localize_script( 'easyPrayeradminpanel', 'my_ajax_obj', array( 420 'ajax_url' => admin_url( 'admin-ajax.php' ), 421 'nonce' => $easyprayernonce, // It is common practice to comma after 422 ) ); 423 } 424 425 add_action( 'admin_enqueue_scripts', 'easyPrayerAdmin_enqueue' ); 426 427 //functions begin 428 409 429 //pull from categories table to create list of categories 410 function easyPrayerlistCate() 411 {412 global $wpdb ; 413 $arr = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}" . "easy_prayer_categories WHERE status != 2");430 function easyPrayerlistCate(){ 431 global $wpdb; 432 433 $arr = $wpdb->get_results("SELECT * FROM $wpdb->prefix"."easy_prayer_categories WHERE status != 2"); 414 434 $string = ''; 415 foreach ( $arr as $results ){416 $string .= '<option value="' . esc_attr( $results->id ) . '" id="' . esc_attr( $results->id ) . '" name="' . esc_attr( $results->id ) . '">' . esc_attr( $results->name) . '</option>';435 foreach ($arr as $results){ 436 $string .= '<option value="' . esc_attr($results->id) . '" id="' . esc_attr($results->id) .'" name="'. esc_attr($results->id) .'">' . esc_attr($results->name) . '</option>'; 417 437 } 418 438 return $string; 419 439 } 420 421 add_action( 'init', 'easyPrayerlistCate', 0 ); 440 add_action( 'init', 'easyPrayerlistCate', 0); 441 422 442 /****************************Misc Stuff****************/ 423 443 //class that enables badword checks 424 require_once 'php/badwords.php';444 require_once('php/badwords.php'); 425 445 //check for bad words 426 function easyPrayerbadword( $text ) 427 { 446 function easyPrayerbadword($text){ 428 447 $myDictionary = array( 429 448 "ass", … … 473 492 "Snatch", 474 493 "Twat", 475 "fuck" 494 "fuck", 476 495 ); 496 497 477 498 $badwords = new EasyPrayerPhpBadWords(); 478 $badwords->setDictionaryFromArray( $myDictionary )->setText( $text ); 499 $badwords->setDictionaryFromArray( $myDictionary ) 500 ->setText( $text ); 501 479 502 $response = $badwords->check(); 480 503 return $response; 481 504 } 482 483 add_action( 'init', 'easyPrayerbadword' ); 505 add_action( 'init', 'easyPrayerbadword'); 506 507 484 508 /**************************Requests****************/ 485 509 //accepts only 1 request at a time, called by adminpanel.php: "approve request" button 486 function easyPrayerApproveRequest() 487 { 488 check_ajax_referer( 'easyprayernonce' ); 489 global $wpdb ; 490 $table = $wpdb->prefix . "easy_prayer_requests"; 491 $data = [ 492 "status" => "1", 493 ]; 494 $where = [ 495 "id" => sanitize_text_field( $_POST['id'] ), 496 ]; 510 function easyPrayerApproveRequest(){ 511 check_ajax_referer( 'easyprayernonce' ); 512 513 global $wpdb; 514 $table = $wpdb->prefix."easy_prayer_requests"; 515 $data = ["status" => "1"]; 516 $where = ["id" => sanitize_text_field($_POST['id'])]; 497 517 //approve request based on id 498 518 //set status to 1 499 519 //echo "Updating data"; 500 $wpdb->update( $table, $data, $where);501 wp_die(); 502 // All ajax handlers die when finished503 } 504 505 add_action( 'wp_ajax_easy_prayer_approve', 'easyPrayerApproveRequest' ); 520 $wpdb->update($table, $data, $where); 521 522 wp_die(); // All ajax handlers die when finished 523 } 524 add_action( 'wp_ajax_easy_prayer_approve', 'easyPrayerApproveRequest'); 525 506 526 //accepts only 1 request at a time, called by adminpanel.php: "trash request" button 507 function easyPrayerTrashRequest() 508 { 509 check_ajax_referer( 'easyprayernonce' ); 510 global $wpdb ; 511 $id = sanitize_text_field( $_POST['id'] ); 527 function easyPrayerTrashRequest(){ 528 check_ajax_referer( 'easyprayernonce' ); 529 global $wpdb; 530 $id = sanitize_text_field($_POST['id']); 512 531 //get specific request, check approval, if approved mark status 3 513 $count = $wpdb->get_var( "SELECT COUNT(*) FROM " . $wpdb->prefix . "easy_prayer_requests WHERE status = 1 AND id = " . $id ); 532 $count = $wpdb->get_var("SELECT COUNT(*) FROM ". $wpdb->prefix."easy_prayer_requests WHERE status = 1 AND id = ".$id); 533 514 534 //for future approval 515 535 $status = 2; 516 if ( $count != 0 ){536 if($count != 0){ 517 537 $status = 3; 518 538 } 519 $table = $wpdb->prefix . "easy_prayer_requests"; 520 $data = [ 521 "status" => $status, 522 ]; 523 $where = [ 524 "id" => $id, 525 ]; 539 540 $table = $wpdb->prefix."easy_prayer_requests"; 541 $data = ["status" => $status]; 542 $where = ["id" => $id]; 526 543 //approve request based on id 527 544 //set status to 1 528 $wpdb->update( $table, $data, $where);529 wp_die(); 530 // All ajax handlers die when finished531 } 532 533 add_action( 'wp_ajax_easy_prayer_trash', 'easyPrayerTrashRequest' ); 545 $wpdb->update($table, $data, $where); 546 547 wp_die(); // All ajax handlers die when finished 548 } 549 add_action( 'wp_ajax_easy_prayer_trash', 'easyPrayerTrashRequest'); 550 534 551 //create backend form to create request, called by createform.php. posts data to createrequestinternal.php 535 function easyPrayerCreateForm() 536 { 552 function easyPrayerCreateForm(){ 537 553 check_ajax_referer( 'easyprayernonce' ); 538 554 $string = ''; … … 559 575 $string .= '<div style="text-align: right; float: right;">'; 560 576 $string .= ' Category:<select name="category" id="createcate" required>'; 561 $string .= easyPrayerlistCate();577 $string .= easyPrayerlistCate(); 562 578 $string .= ' </select>'; 563 579 $string .= '</div>'; … … 566 582 $string .= '<div style="text-align: center"><input type="submit" value="Create Request" /></div>'; 567 583 $string .= '</form>'; 568 echo $string ; 584 echo $string; 585 586 wp_die(); // All ajax handlers die when finished 587 } 588 add_action( 'wp_ajax_easy_prayer_create_form', 'easyPrayerCreateForm'); 589 590 //create request from internal 591 function easyPrayerCreateRequestInternal(){ 592 check_ajax_referer( 'easyprayernonce' ); 593 global $wpdb; 594 595 if(!easyPrayerbadword($_POST['fname'])){ 596 $fname = filter_var($_POST['fname'], FILTER_SANITIZE_STRING); 597 $fname = sanitize_text_field($fname); 598 }else{ 599 exit; 600 } 601 if(!easyPrayerbadword($_POST['lname'])){ 602 $lname = filter_var($_POST['lname'], FILTER_SANITIZE_STRING); 603 $lname = sanitize_text_field($lname); 604 }else{ 605 exit; 606 } 607 if(!easyPrayerbadword($_POST['request'])){ 608 $request = filter_var($_POST['request'], FILTER_SANITIZE_STRING); 609 $request = sanitize_text_field($request); 610 }else{ 611 exit; 612 } 613 if(!easyPrayerbadword($_POST['email'])){ 614 $email = sanitize_email($_POST['email']); 615 $email = sanitize_text_field($email); 616 }else{ 617 exit; 618 } 619 if(!easyPrayerbadword($_POST['loca'])){ 620 $location = filter_var($_POST['loca'], FILTER_SANITIZE_STRING); 621 $location = sanitize_text_field($location); 622 }else{ 623 exit; 624 } 625 626 if(isset($_POST['ip'])){ 627 $ip = filter_var($_POST['ip'], FILTER_SANITIZE_STRING); 628 $ip = sanitize_text_field($ip); 629 }else{ 630 $ip = '0.0.0.0'; 631 } 632 633 //0 for unapproved, 1 for approved, 2 for trashed, if statement accounts for 0 634 if (filter_var($_POST['status'], FILTER_VALIDATE_INT) === 0 || !filter_var($_POST['status'], FILTER_VALIDATE_INT) === false) { 635 $status = filter_var($_POST['status'], FILTER_SANITIZE_STRING); 636 $status = sanitize_text_field($status); 637 }else{ 638 $status = 0; 639 } 640 641 //may allow custom categories 642 if(!easyPrayerbadword($_POST['category'])){ 643 $category = filter_var($_POST['category'], FILTER_SANITIZE_STRING); 644 $category = sanitize_text_field($category); 645 }else{ 646 exit; 647 } 648 649 $table_name = $wpdb->prefix . 'easy_prayer_requests'; 650 651 $wpdb->insert( 652 $table_name, 653 array( 654 'date' => current_time( 'mysql' ), 655 'fname' => $fname, 656 'lname' => $lname, 657 'request' => $request, 658 'email' => $email, 659 'location' => $location, 660 'status' => $status, 661 'category' => $category, 662 'ip' => $ip 663 ) 664 ); 569 665 wp_die(); 570 // All ajax handlers die when finished 571 } 572 573 add_action( 'wp_ajax_easy_prayer_create_form', 'easyPrayerCreateForm' ); 574 //create request from internal 575 function easyPrayerCreateRequestInternal() 576 { 577 check_ajax_referer( 'easyprayernonce' ); 578 global $wpdb ; 579 580 if ( !easyPrayerbadword( $_POST['fname'] ) ) { 581 $fname = filter_var( $_POST['fname'], FILTER_SANITIZE_STRING ); 582 $fname = sanitize_text_field( $fname ); 583 } else { 584 exit; 585 } 586 587 588 if ( !easyPrayerbadword( $_POST['lname'] ) ) { 589 $lname = filter_var( $_POST['lname'], FILTER_SANITIZE_STRING ); 590 $lname = sanitize_text_field( $lname ); 591 } else { 592 exit; 593 } 594 595 596 if ( !easyPrayerbadword( $_POST['request'] ) ) { 597 $request = filter_var( $_POST['request'], FILTER_SANITIZE_STRING ); 598 $request = sanitize_text_field( $request ); 599 } else { 600 exit; 601 } 602 603 604 if ( !easyPrayerbadword( $_POST['email'] ) ) { 605 $email = sanitize_email( $_POST['email'] ); 606 $email = sanitize_text_field( $email ); 607 } else { 608 exit; 609 } 610 611 612 if ( !easyPrayerbadword( $_POST['loca'] ) ) { 613 $location = filter_var( $_POST['loca'], FILTER_SANITIZE_STRING ); 614 $location = sanitize_text_field( $location ); 615 } else { 616 exit; 617 } 618 619 620 if ( isset( $_POST['ip'] ) ) { 621 $ip = filter_var( $_POST['ip'], FILTER_SANITIZE_STRING ); 622 $ip = sanitize_text_field( $ip ); 623 } else { 624 $ip = '0.0.0.0'; 625 } 626 627 //0 for unapproved, 1 for approved, 2 for trashed, if statement accounts for 0 628 629 if ( filter_var( $_POST['status'], FILTER_VALIDATE_INT ) === 0 || !filter_var( $_POST['status'], FILTER_VALIDATE_INT ) === false ) { 630 $status = filter_var( $_POST['status'], FILTER_SANITIZE_STRING ); 631 $status = sanitize_text_field( $status ); 632 } else { 633 $status = 0; 634 } 635 636 //may allow custom categories 637 638 if ( !easyPrayerbadword( $_POST['category'] ) ) { 639 $category = filter_var( $_POST['category'], FILTER_SANITIZE_STRING ); 640 $category = sanitize_text_field( $category ); 641 } else { 642 exit; 643 } 644 645 $table_name = $wpdb->prefix . 'easy_prayer_requests'; 646 $wpdb->insert( $table_name, array( 647 'date' => current_time( 'mysql' ), 648 'fname' => $fname, 649 'lname' => $lname, 650 'request' => $request, 651 'email' => $email, 652 'location' => $location, 653 'status' => $status, 654 'category' => $category, 655 'ip' => $ip, 656 ) ); 657 wp_die(); 658 } 659 660 add_action( 'wp_ajax_easy_prayer_create_request', 'easyPrayerCreateRequestInternal' ); 666 667 } 668 add_action('wp_ajax_easy_prayer_create_request', 'easyPrayerCreateRequestInternal'); 669 661 670 //gets one request by id; called by getrequest.php 662 function easyPrayerGetRequest() 663 { 664 check_ajax_referer( 'easyprayernonce' ); 665 global $wpdb ; 671 function easyPrayerGetRequest(){ 672 check_ajax_referer( 'easyprayernonce' ); 673 global $wpdb; 666 674 //query data 667 $query = "SELECT * FROM " . $wpdb->prefix . "easy_prayer_requests WHERE id = " . sanitize_text_field( $_POST['id']);668 $arr = $wpdb->get_results( $query);675 $query = "SELECT * FROM ". $wpdb->prefix."easy_prayer_requests WHERE id = ". sanitize_text_field($_POST['id']); 676 $arr = $wpdb->get_results($query); 669 677 $string = ''; 678 670 679 //create return string 671 foreach ( $arr as $result ){680 foreach($arr as $result){ 672 681 $string .= '<form action="" method="post" class="ajax" 673 682 enctype="multipart/form-data" id="editRequest">'; 674 $string .= '<input type=text style="display: none" name="id" id="editid" value="' . esc_attr( $result->id ) .'">';683 $string .= '<input type=text style="display: none" name="id" id="editid" value="'.esc_attr($result->id).'">'; 675 684 $string .= '<div style="text-align: center;"><h1>Edit Request</h1></div>'; 676 685 $string .= '<br>'; 677 $string .= 'First Name:<input type="text" name="fname" id="editfname" value="' . esc_attr( $result->fname ) .'">';678 $string .= 'Last Name:<input type="text" name="lname" id="editlname" value="' . esc_attr( $result->lname ) .'">';679 $string .= 'Email:<input type="email" name="email" id="editemail" value="' . esc_attr( $result->email ) .'">';686 $string .= 'First Name:<input type="text" name="fname" id="editfname" value="'.esc_attr($result->fname).'">'; 687 $string .= 'Last Name:<input type="text" name="lname" id="editlname" value="'.esc_attr($result->lname).'">'; 688 $string .= 'Email:<input type="email" name="email" id="editemail" value="'.esc_attr($result->email).'">'; 680 689 $string .= '<br>'; 681 690 $string .= '<br>'; 682 $string .= 'Request:<textarea type="text" name="request" id="editrequest" placeholder="Request here..." rows=3 style="width: 100%">' . $result->request .'</textarea>';691 $string .= 'Request:<textarea type="text" name="request" id="editrequest" placeholder="Request here..." rows=3 style="width: 100%">'.$result->request.'</textarea>'; 683 692 $string .= '<br>'; 684 693 $string .= '<br>'; 685 $string .= 'Location:<input type="text" name="location" id="editlocation" value="' . esc_attr( $result->location ) .'">';694 $string .= 'Location:<input type="text" name="location" id="editlocation" value="'.esc_attr($result->location).'">'; 686 695 $string .= '<div style="text-align: right; float: right;">'; 687 696 $string .= ' Status:<select name="status" id="editstatus">'; 688 689 if ( $result->status == 1 ) { 690 $string .= ' <option value="1" selected>Approved</option>'; 691 $string .= ' <option value="0">Unapproved</option>'; 692 } else { 693 $string .= ' <option value="1">Approved</option>'; 694 $string .= ' <option value="0" selected>Unapproved</option>'; 695 } 696 697 if($result->status == 1){ 698 $string .=' <option value="1" selected>Approved</option>'; 699 $string .=' <option value="0">Unapproved</option>'; 700 }else{ 701 $string .=' <option value="1">Approved</option>'; 702 $string .=' <option value="0" selected>Unapproved</option>'; 703 } 697 704 $string .= ' </select>'; 698 705 $string .= '</div>'; … … 700 707 $string .= 'Category:<select name="category" id="editcate">'; 701 708 //add js to sort thisy 702 $string .= easyPrayerListCateActive( $result->category);709 $string .= easyPrayerListCateActive($result->category); 703 710 $string .= ' </select>'; 704 711 $string .= '</div>'; … … 709 716 } 710 717 //return string 711 echo $string;718 echo $string; 712 719 wp_die(); 713 720 } 714 715 add_action( 'wp_ajax_easy_prayer_get_request', 'easyPrayerGetRequest' ); 721 add_action('wp_ajax_easy_prayer_get_request', 'easyPrayerGetRequest'); 722 723 716 724 //posts edited data to request; called by editrequest.php 717 function easyPrayerEditRequest() 718 { 719 check_ajax_referer( 'easyprayernonce' ); 720 global $wpdb ; 721 722 if ( !easyPrayerbadword( $_POST['fname'] ) ) { 723 $fname = filter_var( $_POST['fname'], FILTER_SANITIZE_STRING ); 724 $fname = sanitize_text_field( $fname ); 725 } else { 726 exit; 727 } 728 729 730 if ( !easyPrayerbadword( $_POST['lname'] ) ) { 731 $lname = filter_var( $_POST['lname'], FILTER_SANITIZE_STRING ); 732 $lname = sanitize_text_field( $lname ); 733 } else { 734 exit; 735 } 736 737 738 if ( !easyPrayerbadword( $_POST['request'] ) ) { 739 $request = filter_var( $_POST['request'], FILTER_SANITIZE_STRING ); 740 $request = sanitize_text_field( $request ); 741 } else { 742 exit; 743 } 744 745 746 if ( !easyPrayerbadword( $_POST['email'] ) ) { 747 $email = sanitize_email( $_POST['email'] ); 748 } else { 749 exit; 750 } 751 752 753 if ( !easyPrayerbadword( $_POST['loca'] ) ) { 754 $location = filter_var( $_POST['loca'], FILTER_SANITIZE_STRING ); 755 $location = sanitize_text_field( $location ); 756 } else { 757 exit; 758 } 759 725 function easyPrayerEditRequest(){ 726 check_ajax_referer( 'easyprayernonce' ); 727 global $wpdb; 728 729 if(!easyPrayerbadword($_POST['fname'])){ 730 $fname = filter_var($_POST['fname'], FILTER_SANITIZE_STRING); 731 $fname = sanitize_text_field($fname); 732 }else{ 733 exit; 734 } 735 if(!easyPrayerbadword($_POST['lname'])){ 736 $lname = filter_var($_POST['lname'], FILTER_SANITIZE_STRING); 737 $lname = sanitize_text_field($lname); 738 }else{ 739 exit; 740 } 741 if(!easyPrayerbadword($_POST['request'])){ 742 $request = filter_var($_POST['request'], FILTER_SANITIZE_STRING); 743 $request = sanitize_text_field($request); 744 }else{ 745 exit; 746 } 747 if(!easyPrayerbadword($_POST['email'])){ 748 $email = sanitize_email($_POST['email']); 749 }else{ 750 exit; 751 } 752 if(!easyPrayerbadword($_POST['loca'])){ 753 $location = filter_var($_POST['loca'], FILTER_SANITIZE_STRING); 754 $location = sanitize_text_field($location); 755 }else{ 756 exit; 757 } 758 760 759 //0 for unapproved, 1 for approved, 2 for trashed, if statement accounts for 0 761 762 if ( filter_var( $_POST['status'], FILTER_VALIDATE_INT ) === 0 || !filter_var( $_POST['status'], FILTER_VALIDATE_INT ) === false ) { 760 if (filter_var($_POST['status'], FILTER_VALIDATE_INT) === 0 || !filter_var($_POST['status'], FILTER_VALIDATE_INT) === false) { 763 761 $status = $_POST['status']; 764 $status = sanitize_text_field( $status);765 } else{762 $status = sanitize_text_field($status); 763 }else{ 766 764 $status = 0; 767 765 } 768 766 769 767 //may allow custom categories 770 771 if ( !easyPrayerbadword( $_POST['category'] ) ) { 772 $category = filter_var( $_POST['category'], FILTER_SANITIZE_STRING ); 773 $category = sanitize_text_field( $category ); 774 } else { 775 exit; 776 } 777 768 if(!easyPrayerbadword($_POST['category'])){ 769 $category = filter_var($_POST['category'], FILTER_SANITIZE_STRING); 770 $category = sanitize_text_field($category); 771 }else{ 772 exit; 773 } 774 778 775 $table_name = $wpdb->prefix . 'easy_prayer_requests'; 776 779 777 $data = array( 780 'fname' => $fname,781 'lname' => $lname,782 'request' => $request,783 'email' => $email,778 'fname' => $fname, 779 'lname' => $lname, 780 'request' => $request, 781 'email' => $email, 784 782 'location' => $location, 785 'status' => $status,786 'category' => $category ,783 'status' => $status, 784 'category' => $category 787 785 ); 786 788 787 $where = array( 789 'id' => sanitize_text_field( $_POST['id'] ),788 'id' => sanitize_text_field($_POST['id']) 790 789 ); 790 791 791 $updated = $wpdb->update( $table_name, $data, $where ); 792 792 wp_die(); 793 793 } 794 795 add_action( 'wp_ajax_easy_prayer_edit_request', 'easyPrayerEditRequest' ); 794 add_action('wp_ajax_easy_prayer_edit_request', 'easyPrayerEditRequest'); 795 796 796 /************************************CATEGORY****************************************/ 797 797 798 //pull from categories table to create list of categories, Selects active category 798 function easyPrayerListCateActive( $id )799 {800 global $wpdb ; 801 $arr = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}" . "easy_prayer_categories WHERE status != 2");799 function easyPrayerListCateActive($id){ 800 global $wpdb; 801 802 $arr = $wpdb->get_results("SELECT * FROM $wpdb->prefix"."easy_prayer_categories WHERE status != 2"); 802 803 $string = ''; 803 foreach ( $arr as $results ) { 804 805 if ( $results->id == $id ) { 806 $string .= '<option value="' . esc_attr( $results->id ) . '" id="' . esc_attr( $results->id ) . '" name="' . esc_attr( $results->id ) . '" selected>' . esc_attr( $results->name ) . '</option>'; 807 } else { 808 $string .= '<option value="' . esc_attr( $results->id ) . '" id="' . esc_attr( $results->id ) . '" name="' . esc_attr( $results->id ) . '">' . esc_attr( $results->name ) . '</option>'; 809 } 810 804 foreach ($arr as $results){ 805 if($results->id == $id){ 806 $string .= '<option value="' . esc_attr($results->id) . '" id="' . esc_attr($results->id) .'" name="'. esc_attr($results->id) .'" selected>' . esc_attr($results->name) . '</option>'; 807 }else{ 808 $string .= '<option value="' . esc_attr($results->id) . '" id="' . esc_attr($results->id) .'" name="'. esc_attr($results->id) .'">' . esc_attr($results->name) . '</option>'; 809 } 811 810 } 812 811 return $string; 813 812 } 814 815 add_action( 'init', 'easyPrayerListCateActive' ); 813 add_action('init', 'easyPrayerListCateActive'); 814 816 815 //form that is loaded into cateogry modal; 817 function easyPrayerGetCategories() 818 { 819 check_ajax_referer( 'easyprayernonce' ); 820 global $wpdb ; 821 $arr = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}" . "easy_prayer_categories WHERE status != 2" ); 816 function easyPrayerGetCategories(){ 817 check_ajax_referer( 'easyprayernonce' ); 818 global $wpdb; 819 $arr = $wpdb->get_results("SELECT * FROM $wpdb->prefix"."easy_prayer_categories WHERE status != 2"); 822 820 $string = ""; 823 821 $string .= '<span style="text-align: center;"><h1>Category</h1></span>'; 824 822 $string .= '<div style="text-align: left;"><button class="create_cate">Create</button></div>'; 825 823 $string .= '<br>'; 826 foreach ( $arr as $result ) { 827 $string .= '<div id=' . esc_attr( $result->id ) . '>'; 828 $string .= 'Name:<input type="text" name="fname" value="' . esc_attr( $result->name ) . '">'; 824 825 foreach($arr as $result){ 826 $string .= '<div id='.esc_attr($result->id).'>'; 827 828 $string .= 'Name:<input type="text" name="fname" value="'.esc_attr($result->name).'">'; 829 829 $string .= 'Status:<select name="status">'; 830 831 if ( $result->status == 1 ) { 830 if($result->status == 1){ 832 831 $string .= '<option value="1" selected>Active</option>'; 833 832 $string .= '<option value="0">Inactive</option>'; 834 } else{833 }else{ 835 834 $string .= '<option value="1">Active</option>'; 836 835 $string .= '<option value="0" selected>Inactive</option>'; 837 836 } 838 839 837 $string .= '</select>'; 840 $string .= '<div style="text-align: right; float: right"><button class="delete" id="' . esc_attr( $result->id ) .'">Delete</button></div>';838 $string .= '<div style="text-align: right; float: right"><button class="delete" id="'.esc_attr($result->id).'">Delete</button></div>'; 841 839 $string .= '<br>'; 842 840 $string .= '<hr>'; 843 841 $string .= '</div>'; 844 842 } 845 echo $string ; 843 844 echo $string; 846 845 wp_die(); 847 846 } 848 849 add_action( 'wp_ajax_easy_prayer_get_categories', 'easyPrayerGetCategories' ); 847 add_action('wp_ajax_easy_prayer_get_categories', 'easyPrayerGetCategories'); 848 850 849 //updates category based off id 851 function easyPrayerEditCategory() 852 {853 check_ajax_referer( 'easyprayernonce' );854 global $wpdb ; 850 function easyPrayerEditCategory(){ 851 check_ajax_referer( 'easyprayernonce' ); 852 global $wpdb; 853 855 854 //updated new name in cata 856 855 $table_name = $wpdb->prefix . 'easy_prayer_categories'; 856 857 857 $data = array( 858 'name' => sanitize_text_field( $_POST['name']),859 'status' => sanitize_text_field( $_POST['status'] ),858 'name' => sanitize_text_field($_POST['name']), 859 'status' => sanitize_text_field($_POST['status']) 860 860 ); 861 861 862 $where = array( 862 'id' => sanitize_text_field( $_POST['id'] ),863 'id' => sanitize_text_field($_POST['id']) 863 864 ); 865 864 866 $updated = $wpdb->update( $table_name, $data, $where ); 865 867 wp_die(); 866 868 } 867 868 add_action( 'wp_ajax_easy_prayer_edit_categories', 'easyPrayerEditCategory' ); 869 add_action('wp_ajax_easy_prayer_edit_categories', 'easyPrayerEditCategory'); 870 869 871 //deletes category based off id 870 function easyPrayerDeleteCategory() 871 { 872 check_ajax_referer( 'easyprayernonce' ); 873 global $wpdb ; 874 $table = $wpdb->prefix . "easy_prayer_categories"; 875 $data = [ 876 "status" => "2", 877 ]; 878 $where = [ 879 "id" => sanitize_text_field( $_POST['id'] ), 880 ]; 872 function easyPrayerDeleteCategory(){ 873 check_ajax_referer( 'easyprayernonce' ); 874 global $wpdb; 875 876 $table = $wpdb->prefix."easy_prayer_categories"; 877 $data = ["status" => "2"]; 878 $where = ["id" => sanitize_text_field($_POST['id'])]; 881 879 //approve request based on id 882 880 //set status to 1 883 $wpdb->update( $table, $data, $where);881 $wpdb->update($table, $data, $where); 884 882 wp_die(); 885 883 } 886 887 add_action( 'wp_ajax_easy_prayer_delete_categories', 'easyPrayerDeleteCategory' ); 884 add_action('wp_ajax_easy_prayer_delete_categories', 'easyPrayerDeleteCategory'); 885 888 886 //form that allows creation of category 889 function easyPrayerCreateCategoryForm() 890 { 887 function easyPrayerCreateCategoryForm(){ 891 888 check_ajax_referer( 'easyprayernonce' ); 892 889 $string = ''; … … 896 893 $string .= 'Name:<input type="text" name="name" value="">'; 897 894 $string .= 'Status:<select id="category_option" name="status">'; 898 $string .= '<option value="1" selected>Active</option>';899 $string .= '<option value="0">Inactive</option>';895 $string .= '<option value="1" selected>Active</option>'; 896 $string .= '<option value="0">Inactive</option>'; 900 897 $string .= '</select>'; 901 898 $string .= '<div style="float: right"><button id="create_category">Create</button></div>'; 902 899 $string .= '</div>'; 903 echo $string;900 echo $string; 904 901 wp_die(); 905 902 } 906 907 add_action( 'wp_ajax_easy_prayer_create_categories_form', 'easyPrayerCreateCategoryForm' ); 903 add_action('wp_ajax_easy_prayer_create_categories_form', 'easyPrayerCreateCategoryForm'); 904 905 906 908 907 //posts data to category table; called by createcategory.php 909 function easyPrayerCreateCategory() 910 {911 check_ajax_referer( 'easyprayernonce' );912 global $wpdb ; 908 function easyPrayerCreateCategory(){ 909 check_ajax_referer( 'easyprayernonce' ); 910 global $wpdb; 911 913 912 //updated new name in cata 914 913 $table_name = $wpdb->prefix . 'easy_prayer_categories'; 914 915 915 $data = array( 916 'name' => sanitize_text_field( $_POST['name']),917 'status' => sanitize_text_field( $_POST['status'] ),916 'name' => sanitize_text_field($_POST['name']), 917 'status' => sanitize_text_field($_POST['status']) 918 918 ); 919 919 920 $updated = $wpdb->insert( $table_name, $data ); 920 921 wp_die(); 921 922 } 922 923 add_action( 'wp_ajax_easy_prayer_create_categories', 'easyPrayerCreateCategory' ); 923 add_action('wp_ajax_easy_prayer_create_categories', 'easyPrayerCreateCategory'); 924 925 924 926 //lists settings; called by getsettings.php 925 function easyPrayerGetSettings() 926 {927 check_ajax_referer( 'easyprayernonce' );928 global $wpdb ; 929 $arr = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}" . "easy_prayer_settings");927 function easyPrayerGetSettings(){ 928 check_ajax_referer( 'easyprayernonce' ); 929 global $wpdb; 930 931 $arr = $wpdb->get_results("SELECT * FROM $wpdb->prefix"."easy_prayer_settings"); 930 932 $string = ''; 931 foreach ( $arr as $results ) { 933 934 foreach($arr as $results){ 932 935 $string .= '<span style="text-align: center;"><h1>Settings</h1></span>'; 933 936 $string .= '<br>'; 934 937 $string .= '<div>'; 935 $string .= '<div class="setting" id="' . esc_attr( $results->id ) . '">Setting: ' . esc_attr( $results->name ) .'</div>';938 $string .= '<div class="setting" id="' . esc_attr($results->id) . '">Setting: ' . esc_attr($results->name) .'</div>'; 936 939 $string .= 'Status:<select id="settings_option" name="status">'; 937 938 if ( $results->status == 1 ) { 940 if($results->status == 1){ 939 941 $string .= '<option value="1" selected>Active</option>'; 940 942 $string .= '<option value="0">Inactive</option>'; 941 } else{943 }else{ 942 944 $string .= '<option value="1">Active</option>'; 943 945 $string .= '<option value="0" selected>Inactive</option>'; 944 946 } 945 946 947 $string .= '</select>'; 947 948 $string .= '</div>'; 948 949 } 949 echo $string ; 950 951 echo $string; 950 952 wp_die(); 951 953 } 952 953 add_action( 'wp_ajax_easy_prayer_get_settings', 'easyPrayerGetSettings' ); 954 add_action('wp_ajax_easy_prayer_get_settings', 'easyPrayerGetSettings'); 955 956 954 957 //updates settings; called by getsettings.php 955 function easyPrayerUpdateSettings() 956 { 957 check_ajax_referer( 'easyprayernonce' ); 958 global $wpdb ; 959 $table = $wpdb->prefix . "easy_prayer_settings"; 960 $data = [ 961 "status" => sanitize_text_field( $_POST['status'] ), 962 ]; 963 $where = [ 964 "id" => sanitize_text_field( $_POST['id'] ), 965 ]; 958 function easyPrayerUpdateSettings(){ 959 check_ajax_referer( 'easyprayernonce' ); 960 global $wpdb; 961 962 $table = $wpdb->prefix."easy_prayer_settings"; 963 $data = ["status" => sanitize_text_field($_POST['status'])]; 964 $where = ["id" => sanitize_text_field($_POST['id'])]; 966 965 //approve request based on id 967 966 //set status to 1 968 $wpdb->update( $table, $data, $where);967 $wpdb->update($table, $data, $where); 969 968 wp_die(); 970 969 } 971 972 add_action( 'wp_ajax_easy_prayer_update_settings', 'easyPrayerUpdateSettings' ); 973 } 970 add_action('wp_ajax_easy_prayer_update_settings', 'easyPrayerUpdateSettings'); 971 972 ?> -
easy-prayer/trunk/help/readme.php
r2267045 r2378212 1 1 <?php 2 3 if ( !defined( 'ABSPATH' ) ) { 2 if ( ! defined( 'ABSPATH' ) ) { 4 3 exit; 5 4 } … … 8 7 <h3>Hello and thank you for downloading Easy Prayer!</h3> 9 8 <p>Easy Prayer Upload form shortcode: [easy_prayer_form] </p> 10 <p>Easy Prayer Upload form shortcode: <?php 11 echo "<b><i><a href='" . esc_url( admin_url( 'admin.php?page=easy-prayer%2Fphp%2Fadminpage.php-pricing', __FILE__ ) ) . "'>Premium Feature</a></i></b>" ; 12 ?></p> 9 <p>Easy Prayer Display Request shortcode: <?php 10 echo '[easy_prayer_requests] , for styling info see below!'; 11 12 ?></p> 13 13 <p>You can create and turn categories on and off to change what type of requests are displayed on the front-end. The feed is <b><i>LIVE</i></b>, So any updates you make on the back-end will show up in real time on the front-end.</p> 14 14 <hr> 15 <?php16 if ( ep_fs()->can_use_premium_code() ) {17 ?>18 15 <h3>Styling for [easy_prayer_requests]</h3> 19 16 <p>If you would to style the information from [easy_prayer_requests], all elements outputted by the short code have unqiue ids</p> … … 30 27 </ul> 31 28 <hr> 32 <?php33 }34 ?>35 29 36 30 <h4><b><i>Below is the required information that is required to upload a Request:</i></b></h4> -
easy-prayer/trunk/js/adminpanel.js
r2267045 r2378212 1 2 /* Premium Code Stripped by Freemius */ 1 jQuery.noConflict(); 2 var reload = false; 3 jQuery(document).on(jQuery.modal.AFTER_CLOSE, function () { 4 if (reload == true) { 5 location.reload(); 6 } 7 }); 8 9 var easy_prayer_filepath = easyPrayerParams.filepath; 10 jQuery(document).ready(function (jQuery) { 11 var table = jQuery('#prayerTable').DataTable({ 12 dom: 'Blfrtip', 13 "paging": true, 14 "lengthMenu": [ 15 [10, 25, 50, 75, 100, -1], 16 [10, 25, 50, 75, 100, "All"] 17 ], 18 "columnDefs": [{ 19 "visible": false, 20 "targets": 0 21 }], 22 select: { 23 toggleable: false 24 }, 25 buttons: [{ 26 text: 'Approve Request', 27 action: function (e, dt, node, conf) { 28 //update status to approved based on comment id 29 30 //get selected rows and their id value 31 var ids = jQuery(".selected"); 32 33 //update loop 34 for (i = 0; i < ids.length; i++) { 35 var updateid = ids[i].id; 36 //post data through prepared statement 37 jQuery.post(my_ajax_obj.ajax_url, { //POST request 38 _ajax_nonce: my_ajax_obj.nonce, //nonce 39 action: "easy_prayer_approve", //action 40 id: updateid //data 41 }, function (data) { //callback 42 //console.log(result); 43 location.reload(); 44 }); 45 46 } 47 48 } 49 }, 50 { 51 text: 'Trash Request', 52 action: function (e, dt, node, conf) { 53 //update status to approved based on comment id 54 //get selected rows and their id value 55 var ids = jQuery(".selected"); 56 57 //update loop 58 for (i = 0; i < ids.length; i++) { 59 var updateid = ids[i].id; 60 //post data through prepared statement 61 jQuery.post(my_ajax_obj.ajax_url, { //POST request 62 _ajax_nonce: my_ajax_obj.nonce, //nonce 63 action: "easy_prayer_trash", //action 64 id: updateid //data 65 }, function (data) { //callback 66 //console.log(result); 67 location.reload(); 68 }); 69 } 70 } 71 }, 72 { 73 text: 'Create Request', 74 action: function (e, dt, node, conf) { 75 jQuery.post(my_ajax_obj.ajax_url, { //POST request 76 _ajax_nonce: my_ajax_obj.nonce, //nonce 77 action: "easy_prayer_create_form", //action 78 }, function (data) { //callback 79 // Add response in Modal body 80 jQuery('.create_modal-body').html(data); 81 82 // Display Modal 83 jQuery('#create_request').modal({ 84 fadeDuration: 150 85 }); 86 87 jQuery('form#createNew').on('submit', function (e) { 88 e.preventDefault(); 89 var that = jQuery(this); 90 var fname = jQuery('#createfname').val(); 91 var lname = jQuery('#createlname').val(); 92 var email = jQuery('#createemail').val(); 93 var request = jQuery('#createrequest').val(); 94 var date = jQuery('#createdate').val(); 95 var loca = jQuery('#createlocation').val(); 96 var category = jQuery('#createcate').val(); 97 var status = jQuery('#createstatus').val(); 98 jQuery.post(my_ajax_obj.ajax_url, { 99 _ajax_nonce: my_ajax_obj.nonce, //nonce 100 action: "easy_prayer_create_request", //action 101 fname: fname, 102 lname: lname, 103 email: email, 104 request: request, 105 date: date, 106 loca: loca, 107 category: category, 108 status: status, 109 }, function (response) { 110 location.reload(); 111 }); 112 }); 113 }); 114 } 115 }, 116 { 117 text: 'Edit Request', 118 action: function (e, dt, node, conf) { 119 120 var id = jQuery(".selected"); 121 122 if (id.length == 1) { 123 jQuery.post(my_ajax_obj.ajax_url, { //POST request 124 _ajax_nonce: my_ajax_obj.nonce, //nonce 125 action: "easy_prayer_get_request", //action 126 id: id[0].id //data 127 }, function (data) { //callback 128 // Add response in Modal body 129 jQuery('.edit_modal-body').html(data); 130 131 // Display Modal 132 jQuery('#edit_request').modal({ 133 fadeDuration: 150 134 }); 135 136 jQuery('form#editRequest').on('submit', function (e) { 137 e.preventDefault(); 138 139 var that = jQuery(this); 140 var fname = jQuery('#editfname').val(); 141 var lname = jQuery('#editlname').val(); 142 var email = jQuery('#editemail').val(); 143 var request = jQuery('#editrequest').val(); 144 var loca = jQuery('#editlocation').val(); 145 var category = jQuery('#editcate').val(); 146 var status = jQuery('#editstatus').val(); 147 var editid = jQuery('#editid').val(); 148 jQuery.post(my_ajax_obj.ajax_url, { 149 _ajax_nonce: my_ajax_obj.nonce, //nonce 150 action: "easy_prayer_edit_request", //action 151 fname: fname, 152 lname: lname, 153 email: email, 154 request: request, 155 loca: loca, 156 category: category, 157 status: status, 158 id: editid, 159 }, function (response) { 160 location.reload(); 161 }); 162 }); 163 }); 164 } else { 165 alert("Please Select a Prayer Request"); 166 } 167 } 168 }, 169 { 170 extend: 'collection', 171 text: 'Export', 172 buttons: [ 173 'csv', 174 'excel', 175 'pdf', 176 'print' 177 ] 178 }, 179 { 180 extend: 'collection', 181 text: 'Categories and Settings', 182 buttons: [{ 183 text: 'Categories', 184 action: function (e, dt, node, conf) { 185 jQuery.post(my_ajax_obj.ajax_url, { //POST request 186 _ajax_nonce: my_ajax_obj.nonce, //nonce 187 action: "easy_prayer_get_categories", //action 188 }, function (data) { //callback 189 // Add response in Modal body 190 191 jQuery('.cate_modal-body').html(data); 192 193 // Display Modal 194 jQuery('#category').modal({ 195 fadeDuration: 150 196 }); 197 198 jQuery('#category').click(); 199 200 //listener for text change 201 var divlistener = jQuery("#category div").change(function (event) { 202 var optionSelected = jQuery("option:selected", this); 203 var nameSelected = jQuery("input:text", this); 204 jQuery.post(my_ajax_obj.ajax_url, { //POST request 205 _ajax_nonce: my_ajax_obj.nonce, //nonce 206 action: "easy_prayer_edit_categories", //action 207 id: event.currentTarget.id, 208 status: optionSelected[0].value, 209 name: nameSelected[0].value, 210 }, function (data) { //callback 211 reload = true; 212 }); 213 }); 214 215 //listener for delete button 216 var buttonSelected = jQuery(".delete").on('click', function (event) { 217 jQuery.post(my_ajax_obj.ajax_url, { //POST request 218 _ajax_nonce: my_ajax_obj.nonce, //nonce 219 action: "easy_prayer_delete_categories", //action 220 id: event.currentTarget.id, 221 }, function (data) { //callback 222 }); 223 224 jQuery(this).text("DELETED"); 225 jQuery(this).css("background-color", "red"); 226 jQuery(this).css("border: 2px solid", "red"); 227 jQuery(this).css("border-radius", "5px"); 228 jQuery(this).parent().parent().fadeOut(); 229 }); 230 231 //listener for create button 232 var create = jQuery(".create_cate").on('click', function (event) { 233 jQuery("#category div").unbind(); 234 jQuery.post(my_ajax_obj.ajax_url, { //POST request 235 _ajax_nonce: my_ajax_obj.nonce, //nonce 236 action: "easy_prayer_create_categories_form", //action 237 }, function (data) { //callback 238 // Add response in Modal body 239 jQuery('.cate_modal-body').html(data); 240 //listener for create category button 241 var createCategory = jQuery("#create_category").on('click', function (event) { 242 var name = jQuery('input:text'); 243 var status = jQuery('#category_option'); 244 //post data, and reload edit screen 245 jQuery.post(my_ajax_obj.ajax_url, { //POST request 246 _ajax_nonce: my_ajax_obj.nonce, //nonce 247 action: "easy_prayer_create_categories", //action 248 name: name[0].value, 249 status: status[0].value 250 }, function (data) { //callback 251 location.reload(); 252 }); 253 }); 254 }); 255 }); 256 257 258 //bottom of get_categories 259 }); 260 } 261 }, 262 /*{ 263 text: 'Auto Approve Settings', 264 action: function (e, dt, node, conf) { 265 jQuery.post(my_ajax_obj.ajax_url, { //POST request 266 _ajax_nonce: my_ajax_obj.nonce, //nonce 267 action: "easy_prayer_get_settings", //action 268 }, function (data) { //callback 269 // Add response in Modal body 270 jQuery('.settings_modal-body').html(data); 271 272 // Display Modal 273 jQuery('#settings').modal({ 274 fadeDuration: 150 275 }); 276 277 278 jQuery('#settings').click(); 279 280 var div = jQuery("#settings div").change(function (event) { 281 var optionSelected = jQuery("option:selected", this); 282 var id = jQuery(".setting"); 283 284 jQuery.post(my_ajax_obj.ajax_url, { //POST request 285 _ajax_nonce: my_ajax_obj.nonce, //nonce 286 action: "easy_prayer_update_settings", //action 287 id: id[0].id, 288 status: optionSelected[0].value, 289 }, function (data) { //callback 290 }); 291 }); 292 }); 293 } 294 },*/ 295 ] 296 }, 297 ], 298 "fnInitComplete": function (oSettings, json) { 299 jQuery("#overlay").fadeOut(400); 300 } 301 }); 302 }); -
easy-prayer/trunk/readme.txt
r2267524 r2378212 8 8 Tested up to: 5.3.2 9 9 Requires at least: 5.3.0 10 Stable tag: 1. 011 Version: 1. 010 Stable tag: 1.1 11 Version: 1.1 12 12 Requires PHP: 7.1 13 13
Note: See TracChangeset
for help on using the changeset viewer.