44 * The dashboard-specific functionality of the plugin.
55 *
66 * @link http://3five.com
7- * @since 1.0 .0
7+ * @since 1.1 .0
88 *
99 * @package Threefive_Support
1010 * @subpackage Threefive_Support/admin
@@ -27,7 +27,7 @@ class Threefive_Support_Admin {
2727 *
2828 * @since 1.0.0
2929 * @access private
30- * @var string $threefive_support The ID of this plugin.
30+ * @var string $threefive_support The ID of this plugin.
3131 */
3232 private $ threefive_support ;
3333
@@ -36,110 +36,166 @@ class Threefive_Support_Admin {
3636 *
3737 * @since 1.0.0
3838 * @access private
39- * @var string $version The current version of this plugin.
39+ * @var string $version The current version of this plugin.
4040 */
4141 private $ version ;
4242
4343 /**
4444 * Initialize the class and set its properties.
4545 *
4646 * @since 1.0.0
47- * @param string $threefive_support The name of this plugin.
48- * @param string $version The version of this plugin.
47+ *
48+ * @param string $threefive_support The name of this plugin.
49+ * @param string $version The version of this plugin.
4950 */
5051 public function __construct ( $ threefive_support , $ version ) {
5152
5253 $ this ->threefive_support = $ threefive_support ;
53- $ this ->version = $ version ;
54- add_action ('wp_dashboard_setup ' , array ($ this , 'load_admin_form_widget ' ) );
54+ $ this ->version = $ version ;
55+ add_action ( 'wp_dashboard_setup ' , array ( $ this , 'load_admin_form_widget ' ) );
5556
5657 }
5758
5859 /**
5960 * Create the admin support form widget
6061 *
6162 * @since 1.0.0
62- * @access public
63+ * @access public
6364 */
6465 public function load_admin_form_widget () {
6566
6667 /**
6768 * The class responsible for defining all actions that occur in the Dashboard.
6869 */
69- add_meta_box ('threefive_support_widget ' , 'Get 3five Support ' , array ($ this , 'threefive_support_dashboard_widget ' ), 'dashboard ' , 'normal ' , 'high ' );
70+ add_meta_box ( 'threefive_support_widget ' , 'Get 3five Support ' , array (
71+ $ this ,
72+ 'threefive_support_dashboard_widget ' ,
73+ ), 'dashboard ' , 'normal ' , 'high ' );
7074 }
7175
7276 /**
7377 * Support form callback function
74- *
78+ *
7579 * - Used as a callback function in load_admin_form_widget()
76- *
80+ *
7781 * @return void
7882 * @since 1.0.0
7983 * @access public
8084 */
8185 public function threefive_support_dashboard_widget () {
8286 /**
8387 * Load the dashboard widget form and widget contents.
84- */
88+ */
8589 require_once plugin_dir_path ( dirname ( __FILE__ ) ) . 'admin/partials/threefive-support-admin-display.php ' ;
8690 }
8791
8892 /**
8993 * Support form data handling and mail sender
9094 *
9195 * - Used as the form POST handler
92- *
96+ *
9397 * @since 1.0.0
9498 * @access public
9599 */
96100 public function threefive_support_dashboard_widget_handler () {
97101 global $ get_updates , $ wp_version ;
98-
99- // $_POST vars
100- $ email = esc_html ($ _POST ['email ' ]);
101- $ name = esc_html ($ _POST ['name ' ]);
102- $ message_body = esc_html ($ _POST ['message ' ]);
103-
102+
103+ // $_POST vars.
104+ $ email = esc_html ( $ _POST ['email ' ] ); // @codingStandardsIgnoreStart
105+ $ name = esc_html ( $ _POST ['name ' ] );
106+ $ message_body = esc_html ( $ _POST ['message ' ] );
107+ $ files = $ _FILES ['files ' ]; // @codingStandardsIgnoreEnd
108+
109+ // Must have email parameters.
110+ $ to = 'wpsupport@3five.com ' ;
111+ $ subject = 'Support Request From ' . $ name . ' at ' . get_bloginfo ( 'name ' ) . '. ' ;
112+ $ headers [] = 'Content-Type: text/html; charset=UTF-8 ' ;
113+ $ headers [] = 'From: ' . $ name . ' < ' . $ email . '> ' ;
114+ $ attachments = array ();
115+
104116 // Add WP Stats to the message field.
105- $ plugins = $ get_updates ['counts ' ]['plugins ' ];
106- $ themes = $ get_updates ['counts ' ]['themes ' ];
117+ $ plugins = $ get_updates ['counts ' ]['plugins ' ];
118+ $ themes = $ get_updates ['counts ' ]['themes ' ];
107119 $ wordpress = $ get_updates ['counts ' ]['wordpress ' ];
108120
109- // Additional Stats
110- $ browser = $ _SERVER ['HTTP_USER_AGENT ' ];
111-
112- // Build the message body
121+ // Build the message body.
113122 $ message = 'Support Request Details: ' . PHP_EOL ;
114123 $ message .= $ message_body . PHP_EOL . PHP_EOL ;
115124 $ message .= 'WordPress Site Statistics: ' . PHP_EOL ;
116- $ message .= 'Site URL: ' . get_bloginfo ('url ' ) . PHP_EOL ;
125+ $ message .= 'Site URL: ' . get_bloginfo ( 'url ' ) . PHP_EOL ;
117126 $ message .= 'WordPress Version: ' . $ wp_version . PHP_EOL ;
118127 $ message .= 'Core Updates available: ' . $ wordpress . PHP_EOL ;
119128 $ message .= 'Plugin Updates available: ' . $ plugins . PHP_EOL ;
120129 $ message .= 'Theme Updates available: ' . $ themes . PHP_EOL ;
121- $ message .= 'Using Browser: ' . $ browser . PHP_EOL ;
122130
123- echo $ message ;
131+ if ( ! function_exists ( 'wp_handle_upload ' ) ) {
132+ require_once ( ABSPATH . 'wp-admin/includes/file.php ' );
133+ }
134+
135+ // Change the upload directory for these files.
136+ add_filter ( 'upload_dir ' , array ( $ this , 'tf_support_upload_dir ' ) );
137+
138+ $ uploadedfiles = $ files ;
139+ $ upload_overrides = array ( 'test_form ' => false );
140+
141+ foreach ( $ uploadedfiles ['name ' ] as $ key => $ value ) {
142+ if ( $ uploadedfiles ['name ' ][ $ key ] ) {
143+ $ uploadedfile = array (
144+ 'name ' => $ files ['name ' ][ $ key ],
145+ 'type ' => $ files ['type ' ][ $ key ],
146+ 'tmp_name ' => $ files ['tmp_name ' ][ $ key ],
147+ 'error ' => $ files ['error ' ][ $ key ],
148+ 'size ' => $ files ['size ' ][ $ key ],
149+ );
150+
151+ $ movefile = wp_handle_upload ( $ uploadedfile , $ upload_overrides );
152+
153+ if ( $ movefile && ! isset ( $ movefile ['error ' ] ) ) {
154+ $ attachments [] = $ movefile ['file ' ];
155+ } else {
156+ echo 'yo ' ;
157+ }
158+ }
159+ }
124160
125- // Constants
126- $ to = 'support@3five.com ' ;
127- $ subject = 'Support Request From ' .$ name . ' at ' .get_bloginfo ('name ' ). '. ' ;
128- $ headers [] = 'From: ' .$ name .' < ' .$ email .'> ' ;
161+ // Send the email out.
162+ wp_mail ( $ to , $ subject , $ message , $ headers , $ attachments );
129163
130- wp_mail ($ to , $ subject , $ message , $ headers );
164+ // Change the upload directory back to the original directory.
165+ remove_filter ( 'upload_dir ' , array ( $ this , 'tf_support_upload_dir ' ) );
131166
132- die ('Great Success! ' );
167+ die ( 'Great Success! ' );
133168 }
134169
170+ /**
171+ * Get a any available update for this site and add it to the email body.
172+ *
173+ * @return array
174+ */
135175 public function get_wp_updates () {
136- if ( function_exists ('wp_get_update_data ' ) ) {
176+ if ( function_exists ( 'wp_get_update_data ' ) ) {
137177 global $ get_updates ;
138178 $ get_updates = wp_get_update_data ();
179+
139180 return $ get_updates ;
140181 }
141182 }
142183
184+ /**
185+ * Change the upload directory for support attachments.
186+ *
187+ * @param array $dirs an array of paths for uploads to go to.
188+ *
189+ * @return mixed
190+ */
191+ public function tf_support_upload_dir ( $ dirs ) {
192+ $ tf_support_dir = '/tf-support-uploads ' ;
193+
194+ $ dirs ['path ' ] = $ dirs ['basedir ' ] . $ tf_support_dir ;
195+ $ dirs ['url ' ] = $ dirs ['baseurl ' ] . $ tf_support_dir ;
196+
197+ return $ dirs ;
198+ }
143199 /**
144200 * Register the stylesheets for the Dashboard.
145201 *
@@ -186,5 +242,4 @@ public function enqueue_scripts() {
186242 wp_localize_script ( $ this ->threefive_support , 'wpAdminAjax ' , array ( 'ajaxurl ' => admin_url ( 'admin-ajax.php ' ) ) );
187243
188244 }
189-
190245}
0 commit comments