Changeset 3699 for sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/budget-tool.php
- Timestamp:
- 07/20/2016 04:51:48 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/budget-tool.php
r3302 r3699 9 9 add_submenu_page( 'wordcamp-budget', __( 'WordCamp Budget', 'wordcamporg' ), __( 'Budget', 'wordcamporg' ), 'manage_options', 'wordcamp-budget' ); 10 10 add_action( 'wcb_render_budget_page', array( __CLASS__, 'render' ) ); 11 register_setting( 'wcb_budget_noop', 'wcb_budget_noop', array( __CLASS__, 'validate' ) ); 12 } 13 14 public static function validate( $noop ) { 15 if ( empty( $_POST['_wcb_budget_data'] ) ) 16 return; 17 18 if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'wcb_budget_noop-options' ) ) 19 return; 20 21 $budget = get_option( 'wcb_budget', array() ); 22 23 // TODO: Add prelim, approved, current logic here. 24 $data = json_decode( wp_unslash( $_POST['_wcb_budget_data'] ), true ); 25 $valid_attributes = array( 'type', 'category', 'amount', 'note', 'link', 'name', 'value' ); 26 foreach ( $data as &$item ) { 27 $_item = array(); 28 foreach ( $item as $key => $value ) { 29 if ( ! in_array( $key, $valid_attributes ) ) 30 continue; 31 32 if ( $key == 'amount' ) 33 $value = round( floatval( $value ), 2 ); 34 35 $_item[ $key ] = $value; 36 } 37 38 $item = $_item; 39 print_r( $item ); 40 } 41 42 $budget['current'] = $data; 43 $budget['updated'] = time(); 44 update_option( 'wcb_budget', $budget, 'no' ); 45 return; 11 46 } 12 47 … … 14 49 $screen = get_current_screen(); 15 50 if ( $screen->id == 'toplevel_page_wordcamp-budget' ) { 16 wp_enqueue_script( 'backbone' ); 51 wp_enqueue_script( 'wcb-budget-tool', 52 plugins_url( 'javascript/budget-tool.js', __DIR__ ), 53 array( 'backbone', 'jquery', 'underscore' ), 1 , true ); 17 54 } 18 55 } 19 56 57 private static function _get_default_budget() { 58 return array( 59 array( 'type' => 'meta', 'name' => 'attendees', 'value' => 300 ), 60 array( 'type' => 'meta', 'name' => 'days', 'value' => 2 ), 61 array( 'type' => 'meta', 'name' => 'tracks', 'value' => 4 ), 62 array( 'type' => 'meta', 'name' => 'speakers', 'value' => 25 ), 63 array( 'type' => 'meta', 'name' => 'volunteers', 'value' => 10 ), 64 array( 'type' => 'meta', 'name' => 'currency', 'value' => 'USD' ), 65 array( 'type' => 'meta', 'name' => 'ticket-price', 'value' => 20.00 ), 66 67 array( 'type' => 'income', 'category' => 'other', 'note' => 'Tickets Income', 'amount' => 0, 'link' => 'ticket-price-x-attendees' ), 68 array( 'type' => 'income', 'category' => 'other', 'note' => 'Community Sponsorships', 'amount' => 4300 ), 69 array( 'type' => 'income', 'category' => 'other', 'note' => 'Local Sponsorships', 'amount' => 7000 ), 70 array( 'type' => 'income', 'category' => 'other', 'note' => 'Microsponsors', 'amount' => 500 ), 71 72 array( 'type' => 'expense', 'category' => 'venue', 'note' => 'Venue', 'amount' => 7500 ), 73 array( 'type' => 'expense', 'category' => 'venue', 'note' => 'Wifi Costs', 'amount' => 300, 'link' => 'per-day' ), 74 array( 'type' => 'expense', 'category' => 'other', 'note' => 'Comped Tickets', 'amount' => 300 ), 75 array( 'type' => 'expense', 'category' => 'audio-visual', 'note' => 'Video recording', 'amount' => 500 ), 76 array( 'type' => 'expense', 'category' => 'audio-visual', 'note' => 'Projector rental', 'amount' => 300 ), 77 array( 'type' => 'expense', 'category' => 'audio-visual', 'note' => 'Livestream', 'amount' => 200 ), 78 array( 'type' => 'expense', 'category' => 'signage-badges', 'note' => 'Printing', 'amount' => 800 ), 79 array( 'type' => 'expense', 'category' => 'signage-badges', 'note' => 'Badges', 'amount' => 8.21, 'link' => 'per-attendee' ), 80 array( 'type' => 'expense', 'category' => 'food-beverage', 'note' => 'Snacks', 'amount' => 300 ), 81 array( 'type' => 'expense', 'category' => 'food-beverage', 'note' => 'Lunch', 'amount' => 2350 ), 82 array( 'type' => 'expense', 'category' => 'food-beverage', 'note' => 'Coffee', 'amount' => 500 ), 83 array( 'type' => 'expense', 'category' => 'swag', 'note' => 'T-shirts', 'amount' => 780 ), 84 array( 'type' => 'expense', 'category' => 'speaker-event', 'note' => 'Speakers Dinner', 'amount' => 20, 'link' => 'per-speaker' ), 85 ); 86 } 87 20 88 public static function render() { 89 $budget = get_option( 'wcb_budget' ); 90 $budget = ! empty( $budget['current'] ) ? $budget['current'] : self::_get_default_budget(); 91 92 if ( ! $inspire_urls = get_site_transient( 'wcb-inspire-urls' ) ) { 93 $urls = array( 'https://jawordpressorg.github.io/wapuu/wapuu-archive/original-wapuu.png' ); 94 $r = wp_remote_get( 'https://jawordpressorg.github.io/wapuu-api/v1/wapuu.json' ); 95 if ( ! is_wp_error( $r ) && wp_remote_retrieve_response_code( $r ) == 200 ) { 96 $body = json_decode( wp_remote_retrieve_body( $r ), true ); 97 $maybe_urls = wp_list_pluck( wp_list_pluck( $body, 'wapuu' ), 'src' ); 98 if ( count( $maybe_urls ) > 0 ) { 99 $inspire_urls = $maybe_urls; 100 } 101 } 102 103 set_site_transient( 'wcb-inspire-urls', $inspire_urls, 30 * DAY_IN_SECONDS ); 104 } 105 21 106 require( dirname( __DIR__ ) . '/views/budget-tool/main.php' ); 22 107 }
Note: See TracChangeset
for help on using the changeset viewer.