Completed
Pull Request — Gutenberg/master (#757)
by Darren
27:11
created
core/helpers/EEH_Class_Tools.helper.php 2 patches
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -11,131 +11,131 @@
 block discarded – undo
11 11
 class EEH_Class_Tools
12 12
 {
13 13
 
14
-    public static $i = 0;
15
-    public static $file_line = null;
14
+	public static $i = 0;
15
+	public static $file_line = null;
16 16
 
17
-    /**
18
-     *  get_called_class - for PHP versions < 5.3
19
-     *
20
-     *  @access     public
21
-     *  @author origins:  http://stackoverflow.com/a/1542045
22
-     *  return string
23
-     */
24
-    public static function get_called_class()
25
-    {
26
-        $backtrace = debug_backtrace();
27
-        if (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['class']) && ! isset($backtrace[2]['file'])) {
28
-            return $backtrace[2]['class'];
29
-        } elseif (isset($backtrace[3]) && is_array($backtrace[3]) && isset($backtrace[3]['class']) && ! isset($backtrace[3]['file'])) {
30
-            return $backtrace[3]['class'];
31
-        } elseif (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['file']) && isset($backtrace[2]['line'])) {
32
-            if (self::$file_line == $backtrace[2]['file'] . $backtrace[2]['line']) {
33
-                self::$i++;
34
-            } else {
35
-                self::$i = 0;
36
-                self::$file_line = $backtrace[2]['file'] . $backtrace[2]['line'];
37
-            }
38
-            // was  class method called via call_user_func ?
39
-            if ($backtrace[2]['function'] == 'call_user_func' && isset($backtrace[2]['args']) && is_array($backtrace[2]['args'])) {
40
-                if (isset($backtrace[2]['args'][0]) && isset($backtrace[2]['args'][0][0])) {
41
-                    $called_class = $backtrace[2]['args'][0][0];
42
-                    // is it an EE function ?
43
-                    if (strpos($called_class, 'EE') === 0) {
44
-                        $prefix_chars = strpos($called_class, '_') + 1;
45
-                        $prefix = substr($called_class, 0, $prefix_chars);
46
-                        $classname = substr($called_class, $prefix_chars, strlen($called_class));
47
-                        $classname = $prefix . str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname))));
48
-                        return $classname;
49
-                    }
50
-                }
51
-            } else {
52
-                $lines = file($backtrace[2]['file']);
53
-                preg_match_all('/([a-zA-Z0-9\_]+)::' . $backtrace[2]['function'] . '/', $lines[ $backtrace[2]['line']-1 ], $matches);
54
-                if (isset($matches[1]) && isset($matches[1][ self::$i ])) {
55
-                    return $matches[1][ self::$i ];
56
-                }
57
-            }
58
-        }
59
-        return false;
60
-    }
17
+	/**
18
+	 *  get_called_class - for PHP versions < 5.3
19
+	 *
20
+	 *  @access     public
21
+	 *  @author origins:  http://stackoverflow.com/a/1542045
22
+	 *  return string
23
+	 */
24
+	public static function get_called_class()
25
+	{
26
+		$backtrace = debug_backtrace();
27
+		if (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['class']) && ! isset($backtrace[2]['file'])) {
28
+			return $backtrace[2]['class'];
29
+		} elseif (isset($backtrace[3]) && is_array($backtrace[3]) && isset($backtrace[3]['class']) && ! isset($backtrace[3]['file'])) {
30
+			return $backtrace[3]['class'];
31
+		} elseif (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['file']) && isset($backtrace[2]['line'])) {
32
+			if (self::$file_line == $backtrace[2]['file'] . $backtrace[2]['line']) {
33
+				self::$i++;
34
+			} else {
35
+				self::$i = 0;
36
+				self::$file_line = $backtrace[2]['file'] . $backtrace[2]['line'];
37
+			}
38
+			// was  class method called via call_user_func ?
39
+			if ($backtrace[2]['function'] == 'call_user_func' && isset($backtrace[2]['args']) && is_array($backtrace[2]['args'])) {
40
+				if (isset($backtrace[2]['args'][0]) && isset($backtrace[2]['args'][0][0])) {
41
+					$called_class = $backtrace[2]['args'][0][0];
42
+					// is it an EE function ?
43
+					if (strpos($called_class, 'EE') === 0) {
44
+						$prefix_chars = strpos($called_class, '_') + 1;
45
+						$prefix = substr($called_class, 0, $prefix_chars);
46
+						$classname = substr($called_class, $prefix_chars, strlen($called_class));
47
+						$classname = $prefix . str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname))));
48
+						return $classname;
49
+					}
50
+				}
51
+			} else {
52
+				$lines = file($backtrace[2]['file']);
53
+				preg_match_all('/([a-zA-Z0-9\_]+)::' . $backtrace[2]['function'] . '/', $lines[ $backtrace[2]['line']-1 ], $matches);
54
+				if (isset($matches[1]) && isset($matches[1][ self::$i ])) {
55
+					return $matches[1][ self::$i ];
56
+				}
57
+			}
58
+		}
59
+		return false;
60
+	}
61 61
 
62 62
 
63 63
 
64 64
 
65
-    /**
66
-     *  get_class_names_for_all_callbacks_on_hook
67
-     * returns an array of names for all classes that have methods registered as callbacks for the given action or filter hook
68
-     *  @access     public
69
-     *  @param  string  $hook
70
-     *  @return     array
71
-     */
72
-    public static function get_class_names_for_all_callbacks_on_hook($hook = null)
73
-    {
74
-        global $wp_filter;
75
-        $class_names = array();
76
-        // are any callbacks registered for this hook ?
77
-        if (isset($wp_filter[ $hook ])) {
78
-            // loop thru all of the callbacks attached to the deprecated hookpoint
79
-            foreach ($wp_filter[ $hook ] as $priority) {
80
-                foreach ($priority as $callback) {
81
-                    // is the callback a non-static class method ?
82
-                    if (isset($callback['function']) && is_array($callback['function'])) {
83
-                        if (isset($callback['function'][0]) && is_object($callback['function'][0])) {
84
-                            $class_names[] = get_class($callback['function'][0]);
85
-                        }
86
-                    // test for static method
87
-                    } elseif (strpos($callback['function'], '::') !== false) {
88
-                        $class = explode('::', $callback['function']);
89
-                        $class_names[] = $class[0];
90
-                    } else {
91
-                        // just a function
92
-                    }
93
-                }
94
-            }
95
-        }
96
-        return $class_names;
97
-    }
65
+	/**
66
+	 *  get_class_names_for_all_callbacks_on_hook
67
+	 * returns an array of names for all classes that have methods registered as callbacks for the given action or filter hook
68
+	 *  @access     public
69
+	 *  @param  string  $hook
70
+	 *  @return     array
71
+	 */
72
+	public static function get_class_names_for_all_callbacks_on_hook($hook = null)
73
+	{
74
+		global $wp_filter;
75
+		$class_names = array();
76
+		// are any callbacks registered for this hook ?
77
+		if (isset($wp_filter[ $hook ])) {
78
+			// loop thru all of the callbacks attached to the deprecated hookpoint
79
+			foreach ($wp_filter[ $hook ] as $priority) {
80
+				foreach ($priority as $callback) {
81
+					// is the callback a non-static class method ?
82
+					if (isset($callback['function']) && is_array($callback['function'])) {
83
+						if (isset($callback['function'][0]) && is_object($callback['function'][0])) {
84
+							$class_names[] = get_class($callback['function'][0]);
85
+						}
86
+					// test for static method
87
+					} elseif (strpos($callback['function'], '::') !== false) {
88
+						$class = explode('::', $callback['function']);
89
+						$class_names[] = $class[0];
90
+					} else {
91
+						// just a function
92
+					}
93
+				}
94
+			}
95
+		}
96
+		return $class_names;
97
+	}
98 98
 
99 99
 
100 100
 
101 101
 
102
-    /**
103
-     *  property_exists() with fallback for PHP versions < 5.3
104
-     *  @access     public
105
-     *  @param      mixed object | string   $class
106
-     *  @param      string  $property
107
-     *  @return         boolean
108
-     */
109
-    public static function has_property($class = null, $property = null)
110
-    {
111
-        // if $class or $property don't exist, then get out, cuz that would be like... fatal dude
112
-        if (empty($class) || empty($property)) {
113
-            return false;
114
-        }
115
-        // if your hosting company doesn't cut the mustard
116
-        if (version_compare(PHP_VERSION, '5.3.0') < 0) {
117
-            // just in case $class is an actual instantiated object
118
-            if (is_object($class)) {
119
-                return isset($class->{$property}) ? true : false;
120
-            } else {
121
-                // use reflection for < PHP 5.3 to get details using just the class name
122
-                $reflector = new ReflectionClass($class);
123
-                return $reflector->hasProperty($property);
124
-            }
125
-        } else {
126
-            // or try regular property exists method which works as expected in PHP 5.3+
127
-            return property_exists($class, $property);
128
-        }
129
-    }
102
+	/**
103
+	 *  property_exists() with fallback for PHP versions < 5.3
104
+	 *  @access     public
105
+	 *  @param      mixed object | string   $class
106
+	 *  @param      string  $property
107
+	 *  @return         boolean
108
+	 */
109
+	public static function has_property($class = null, $property = null)
110
+	{
111
+		// if $class or $property don't exist, then get out, cuz that would be like... fatal dude
112
+		if (empty($class) || empty($property)) {
113
+			return false;
114
+		}
115
+		// if your hosting company doesn't cut the mustard
116
+		if (version_compare(PHP_VERSION, '5.3.0') < 0) {
117
+			// just in case $class is an actual instantiated object
118
+			if (is_object($class)) {
119
+				return isset($class->{$property}) ? true : false;
120
+			} else {
121
+				// use reflection for < PHP 5.3 to get details using just the class name
122
+				$reflector = new ReflectionClass($class);
123
+				return $reflector->hasProperty($property);
124
+			}
125
+		} else {
126
+			// or try regular property exists method which works as expected in PHP 5.3+
127
+			return property_exists($class, $property);
128
+		}
129
+	}
130 130
 }
131 131
 
132 132
 // if PHP version < 5.3
133 133
 if (! function_exists('get_called_class')) {
134
-    /**
135
-     * @return string
136
-     */
137
-    function get_called_class()
138
-    {
139
-        return EEH_Class_Tools::get_called_class();
140
-    }
134
+	/**
135
+	 * @return string
136
+	 */
137
+	function get_called_class()
138
+	{
139
+		return EEH_Class_Tools::get_called_class();
140
+	}
141 141
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
         } elseif (isset($backtrace[3]) && is_array($backtrace[3]) && isset($backtrace[3]['class']) && ! isset($backtrace[3]['file'])) {
30 30
             return $backtrace[3]['class'];
31 31
         } elseif (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['file']) && isset($backtrace[2]['line'])) {
32
-            if (self::$file_line == $backtrace[2]['file'] . $backtrace[2]['line']) {
32
+            if (self::$file_line == $backtrace[2]['file'].$backtrace[2]['line']) {
33 33
                 self::$i++;
34 34
             } else {
35 35
                 self::$i = 0;
36
-                self::$file_line = $backtrace[2]['file'] . $backtrace[2]['line'];
36
+                self::$file_line = $backtrace[2]['file'].$backtrace[2]['line'];
37 37
             }
38 38
             // was  class method called via call_user_func ?
39 39
             if ($backtrace[2]['function'] == 'call_user_func' && isset($backtrace[2]['args']) && is_array($backtrace[2]['args'])) {
@@ -44,15 +44,15 @@  discard block
 block discarded – undo
44 44
                         $prefix_chars = strpos($called_class, '_') + 1;
45 45
                         $prefix = substr($called_class, 0, $prefix_chars);
46 46
                         $classname = substr($called_class, $prefix_chars, strlen($called_class));
47
-                        $classname = $prefix . str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname))));
47
+                        $classname = $prefix.str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname))));
48 48
                         return $classname;
49 49
                     }
50 50
                 }
51 51
             } else {
52 52
                 $lines = file($backtrace[2]['file']);
53
-                preg_match_all('/([a-zA-Z0-9\_]+)::' . $backtrace[2]['function'] . '/', $lines[ $backtrace[2]['line']-1 ], $matches);
54
-                if (isset($matches[1]) && isset($matches[1][ self::$i ])) {
55
-                    return $matches[1][ self::$i ];
53
+                preg_match_all('/([a-zA-Z0-9\_]+)::'.$backtrace[2]['function'].'/', $lines[$backtrace[2]['line'] - 1], $matches);
54
+                if (isset($matches[1]) && isset($matches[1][self::$i])) {
55
+                    return $matches[1][self::$i];
56 56
                 }
57 57
             }
58 58
         }
@@ -74,9 +74,9 @@  discard block
 block discarded – undo
74 74
         global $wp_filter;
75 75
         $class_names = array();
76 76
         // are any callbacks registered for this hook ?
77
-        if (isset($wp_filter[ $hook ])) {
77
+        if (isset($wp_filter[$hook])) {
78 78
             // loop thru all of the callbacks attached to the deprecated hookpoint
79
-            foreach ($wp_filter[ $hook ] as $priority) {
79
+            foreach ($wp_filter[$hook] as $priority) {
80 80
                 foreach ($priority as $callback) {
81 81
                     // is the callback a non-static class method ?
82 82
                     if (isset($callback['function']) && is_array($callback['function'])) {
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 }
131 131
 
132 132
 // if PHP version < 5.3
133
-if (! function_exists('get_called_class')) {
133
+if ( ! function_exists('get_called_class')) {
134 134
     /**
135 135
      * @return string
136 136
      */
Please login to merge, or discard this patch.
core/helpers/EEH_Sideloader.helper.php 2 patches
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -14,152 +14,152 @@
 block discarded – undo
14 14
 class EEH_Sideloader extends EEH_Base
15 15
 {
16 16
 
17
-    private $_upload_to;
18
-    private $_upload_from;
19
-    private $_permissions;
20
-    private $_new_file_name;
21
-
22
-
23
-    /**
24
-     * constructor allows the user to set the properties on the sideloader on construct.  However, there are also setters for doing so.
25
-     *
26
-     * @access public
27
-     * @param array $init array fo initializing the sideloader if keys match the properties.
28
-     */
29
-    public function __construct($init = array())
30
-    {
31
-        $this->_init($init);
32
-    }
33
-
34
-
35
-    /**
36
-     * sets the properties for class either to defaults or using incoming initialization array
37
-     *
38
-     * @access private
39
-     * @param  array  $init array on init (keys match properties others ignored)
40
-     * @return void
41
-     */
42
-    private function _init($init)
43
-    {
44
-        $defaults = array(
45
-            '_upload_to' => $this->_get_wp_uploads_dir(),
46
-            '_upload_from' => '',
47
-            '_permissions' => 0644,
48
-            '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default'
49
-            );
50
-
51
-        $props = array_merge($defaults, $init);
52
-
53
-        foreach ($props as $key => $val) {
54
-            if (EEH_Class_Tools::has_property($this, $key)) {
55
-                $this->{$key} = $val;
56
-            }
57
-        }
58
-
59
-        // make sure we include the required wp file for needed functions
60
-        require_once(ABSPATH . 'wp-admin/includes/file.php');
61
-    }
62
-
63
-
64
-    // utilities
65
-    private function _get_wp_uploads_dir()
66
-    {
67
-    }
68
-
69
-    // setters
70
-    public function set_upload_to($upload_to_folder)
71
-    {
72
-        $this->_upload_to = $upload_to_folder;
73
-    }
74
-    public function set_upload_from($upload_from_folder)
75
-    {
76
-        $this->_upload_from_folder = $upload_from_folder;
77
-    }
78
-    public function set_permissions($permissions)
79
-    {
80
-        $this->_permissions = $permissions;
81
-    }
82
-    public function set_new_file_name($new_file_name)
83
-    {
84
-        $this->_new_file_name = $new_file_name;
85
-    }
86
-
87
-    // getters
88
-    public function get_upload_to()
89
-    {
90
-        return $this->_upload_to;
91
-    }
92
-    public function get_upload_from()
93
-    {
94
-        return $this->_upload_from;
95
-    }
96
-    public function get_permissions()
97
-    {
98
-        return $this->_permissions;
99
-    }
100
-    public function get_new_file_name()
101
-    {
102
-        return $this->_new_file_name;
103
-    }
104
-
105
-
106
-    // upload methods
107
-    public function sideload()
108
-    {
109
-        // setup temp dir
110
-        $temp_file = wp_tempnam($this->_upload_from);
111
-
112
-        if (!$temp_file) {
113
-            EE_Error::add_error(__('Something went wrong with the upload.  Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
114
-            return false;
115
-        }
116
-
117
-        do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file);
118
-
119
-        $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file);
120
-
121
-        $response = wp_safe_remote_get($this->_upload_from, $wp_remote_args);
122
-
123
-        if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) {
124
-            unlink($temp_file);
125
-            if (defined('WP_DEBUG') && WP_DEBUG) {
126
-                EE_Error::add_error(sprintf(__('Unable to upload the file.  Either the path given to upload from is incorrect, or something else happened.  Here is the response returned:<br />%s<br />Here is the path given: %s', 'event_espresso'), var_export($response, true), $this->_upload_from), __FILE__, __FUNCTION__, __LINE__);
127
-            }
128
-            return false;
129
-        }
130
-
131
-        // possible md5 check
132
-        $content_md5 = wp_remote_retrieve_header($response, 'content-md5');
133
-        if ($content_md5) {
134
-            $md5_check = verify_file_md5($temp_file, $content_md5);
135
-            if (is_wp_error($md5_check)) {
136
-                unlink($temp_file);
137
-                EE_Error::add_error($md5_check->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
138
-                return false;
139
-            }
140
-        }
141
-
142
-        $file = $temp_file;
143
-
144
-        // now we have the file, let's get it in the right directory with the right name.
145
-        $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this);
146
-
147
-        // move file in
148
-        if (false === @ rename($file, $path)) {
149
-            unlink($temp_file);
150
-            EE_Error::add_error(sprintf(__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'), $path), __FILE__, __FUNCTION__, __LINE__);
151
-            return false;
152
-        }
153
-
154
-        // set permissions
155
-        $permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this);
156
-        chmod($path, $permissions);
157
-
158
-        // that's it.  let's allow for actions after file uploaded.
159
-        do_action('AHEE__EE_Sideloader__sideload_after', $this, $path);
160
-
161
-        // unlink tempfile
162
-        @unlink($temp_file);
163
-        return true;
164
-    }
17
+	private $_upload_to;
18
+	private $_upload_from;
19
+	private $_permissions;
20
+	private $_new_file_name;
21
+
22
+
23
+	/**
24
+	 * constructor allows the user to set the properties on the sideloader on construct.  However, there are also setters for doing so.
25
+	 *
26
+	 * @access public
27
+	 * @param array $init array fo initializing the sideloader if keys match the properties.
28
+	 */
29
+	public function __construct($init = array())
30
+	{
31
+		$this->_init($init);
32
+	}
33
+
34
+
35
+	/**
36
+	 * sets the properties for class either to defaults or using incoming initialization array
37
+	 *
38
+	 * @access private
39
+	 * @param  array  $init array on init (keys match properties others ignored)
40
+	 * @return void
41
+	 */
42
+	private function _init($init)
43
+	{
44
+		$defaults = array(
45
+			'_upload_to' => $this->_get_wp_uploads_dir(),
46
+			'_upload_from' => '',
47
+			'_permissions' => 0644,
48
+			'_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default'
49
+			);
50
+
51
+		$props = array_merge($defaults, $init);
52
+
53
+		foreach ($props as $key => $val) {
54
+			if (EEH_Class_Tools::has_property($this, $key)) {
55
+				$this->{$key} = $val;
56
+			}
57
+		}
58
+
59
+		// make sure we include the required wp file for needed functions
60
+		require_once(ABSPATH . 'wp-admin/includes/file.php');
61
+	}
62
+
63
+
64
+	// utilities
65
+	private function _get_wp_uploads_dir()
66
+	{
67
+	}
68
+
69
+	// setters
70
+	public function set_upload_to($upload_to_folder)
71
+	{
72
+		$this->_upload_to = $upload_to_folder;
73
+	}
74
+	public function set_upload_from($upload_from_folder)
75
+	{
76
+		$this->_upload_from_folder = $upload_from_folder;
77
+	}
78
+	public function set_permissions($permissions)
79
+	{
80
+		$this->_permissions = $permissions;
81
+	}
82
+	public function set_new_file_name($new_file_name)
83
+	{
84
+		$this->_new_file_name = $new_file_name;
85
+	}
86
+
87
+	// getters
88
+	public function get_upload_to()
89
+	{
90
+		return $this->_upload_to;
91
+	}
92
+	public function get_upload_from()
93
+	{
94
+		return $this->_upload_from;
95
+	}
96
+	public function get_permissions()
97
+	{
98
+		return $this->_permissions;
99
+	}
100
+	public function get_new_file_name()
101
+	{
102
+		return $this->_new_file_name;
103
+	}
104
+
105
+
106
+	// upload methods
107
+	public function sideload()
108
+	{
109
+		// setup temp dir
110
+		$temp_file = wp_tempnam($this->_upload_from);
111
+
112
+		if (!$temp_file) {
113
+			EE_Error::add_error(__('Something went wrong with the upload.  Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
114
+			return false;
115
+		}
116
+
117
+		do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file);
118
+
119
+		$wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file);
120
+
121
+		$response = wp_safe_remote_get($this->_upload_from, $wp_remote_args);
122
+
123
+		if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) {
124
+			unlink($temp_file);
125
+			if (defined('WP_DEBUG') && WP_DEBUG) {
126
+				EE_Error::add_error(sprintf(__('Unable to upload the file.  Either the path given to upload from is incorrect, or something else happened.  Here is the response returned:<br />%s<br />Here is the path given: %s', 'event_espresso'), var_export($response, true), $this->_upload_from), __FILE__, __FUNCTION__, __LINE__);
127
+			}
128
+			return false;
129
+		}
130
+
131
+		// possible md5 check
132
+		$content_md5 = wp_remote_retrieve_header($response, 'content-md5');
133
+		if ($content_md5) {
134
+			$md5_check = verify_file_md5($temp_file, $content_md5);
135
+			if (is_wp_error($md5_check)) {
136
+				unlink($temp_file);
137
+				EE_Error::add_error($md5_check->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
138
+				return false;
139
+			}
140
+		}
141
+
142
+		$file = $temp_file;
143
+
144
+		// now we have the file, let's get it in the right directory with the right name.
145
+		$path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this);
146
+
147
+		// move file in
148
+		if (false === @ rename($file, $path)) {
149
+			unlink($temp_file);
150
+			EE_Error::add_error(sprintf(__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'), $path), __FILE__, __FUNCTION__, __LINE__);
151
+			return false;
152
+		}
153
+
154
+		// set permissions
155
+		$permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this);
156
+		chmod($path, $permissions);
157
+
158
+		// that's it.  let's allow for actions after file uploaded.
159
+		do_action('AHEE__EE_Sideloader__sideload_after', $this, $path);
160
+
161
+		// unlink tempfile
162
+		@unlink($temp_file);
163
+		return true;
164
+	}
165 165
 } //end EEH_Template class
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
             '_upload_to' => $this->_get_wp_uploads_dir(),
46 46
             '_upload_from' => '',
47 47
             '_permissions' => 0644,
48
-            '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default'
48
+            '_new_file_name' => 'EE_Sideloader_'.uniqid().'.default'
49 49
             );
50 50
 
51 51
         $props = array_merge($defaults, $init);
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
         }
58 58
 
59 59
         // make sure we include the required wp file for needed functions
60
-        require_once(ABSPATH . 'wp-admin/includes/file.php');
60
+        require_once(ABSPATH.'wp-admin/includes/file.php');
61 61
     }
62 62
 
63 63
 
@@ -109,14 +109,14 @@  discard block
 block discarded – undo
109 109
         // setup temp dir
110 110
         $temp_file = wp_tempnam($this->_upload_from);
111 111
 
112
-        if (!$temp_file) {
112
+        if ( ! $temp_file) {
113 113
             EE_Error::add_error(__('Something went wrong with the upload.  Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
114 114
             return false;
115 115
         }
116 116
 
117 117
         do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file);
118 118
 
119
-        $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file);
119
+        $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array('timeout' => 500, 'stream' => true, 'filename' => $temp_file), $this, $temp_file);
120 120
 
121 121
         $response = wp_safe_remote_get($this->_upload_from, $wp_remote_args);
122 122
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
         $file = $temp_file;
143 143
 
144 144
         // now we have the file, let's get it in the right directory with the right name.
145
-        $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this);
145
+        $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to.$this->_new_file_name, $this);
146 146
 
147 147
         // move file in
148 148
         if (false === @ rename($file, $path)) {
Please login to merge, or discard this patch.
core/helpers/EEH_Tabbed_Content.helper.php 2 patches
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -21,202 +21,202 @@
 block discarded – undo
21 21
 
22 22
 
23 23
 
24
-    /**
25
-     * assembles and returns the html structure for tabs
26
-     *
27
-     * @static
28
-     * @param  array $tabs_contents an array of the content for each tab [required]
29
-     * @param  array $tabs_names    an unassociative array of names for each tab [optional] - if this isn't included then we use the indexes for $tabs_content as the tab names)
30
-     * @param bool   $small_tabs
31
-     * @param bool   $tabs_content
32
-     * @return string the assembled html string containing the tabbed content for display.
33
-     * @throws \EE_Error
34
-     */
35
-    public static function display($tabs_contents, $tabs_names = array(), $small_tabs = true, $tabs_content = true)
36
-    {
37
-
38
-        // first check if $tabs_names is not empty then the count must match the count of $tabs_content otherwise we've got a problem houston
39
-        if (!empty($tabs_names) && ( count((array) $tabs_names) != count((array) $tabs_content) )) {
40
-            throw new EE_Error(__('The count for $tabs_names and $tabs_content does not match.', 'event_espresso'));
41
-        }
42
-
43
-        // make sure we've got incoming data setup properly
44
-        $tabs = !empty($tabs_names) ? (array) $tabs_names : array_keys((array) $tabs_contents);
45
-        $tabs_content = !empty($tabs_names) ? array_combine((array) $tabs_names, (array) $tabs_content) : $tabs_contents;
46
-
47
-        $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n";
48
-        $all_tabs_content = '';
49
-
50
-        $index = 0;
51
-        foreach ($tabs as $tab) {
52
-            $active = $index === 0 ? true : false;
53
-            $all_tabs .= self::tab($tab, $active);
54
-            $all_tabs_content .= self::tab_content($tab, $tabs_content[ $tab ], $active);
55
-            $index++;
56
-        }
57
-        /*
24
+	/**
25
+	 * assembles and returns the html structure for tabs
26
+	 *
27
+	 * @static
28
+	 * @param  array $tabs_contents an array of the content for each tab [required]
29
+	 * @param  array $tabs_names    an unassociative array of names for each tab [optional] - if this isn't included then we use the indexes for $tabs_content as the tab names)
30
+	 * @param bool   $small_tabs
31
+	 * @param bool   $tabs_content
32
+	 * @return string the assembled html string containing the tabbed content for display.
33
+	 * @throws \EE_Error
34
+	 */
35
+	public static function display($tabs_contents, $tabs_names = array(), $small_tabs = true, $tabs_content = true)
36
+	{
37
+
38
+		// first check if $tabs_names is not empty then the count must match the count of $tabs_content otherwise we've got a problem houston
39
+		if (!empty($tabs_names) && ( count((array) $tabs_names) != count((array) $tabs_content) )) {
40
+			throw new EE_Error(__('The count for $tabs_names and $tabs_content does not match.', 'event_espresso'));
41
+		}
42
+
43
+		// make sure we've got incoming data setup properly
44
+		$tabs = !empty($tabs_names) ? (array) $tabs_names : array_keys((array) $tabs_contents);
45
+		$tabs_content = !empty($tabs_names) ? array_combine((array) $tabs_names, (array) $tabs_content) : $tabs_contents;
46
+
47
+		$all_tabs = '<h2 class="nav-tab-wrapper">' . "\n";
48
+		$all_tabs_content = '';
49
+
50
+		$index = 0;
51
+		foreach ($tabs as $tab) {
52
+			$active = $index === 0 ? true : false;
53
+			$all_tabs .= self::tab($tab, $active);
54
+			$all_tabs_content .= self::tab_content($tab, $tabs_content[ $tab ], $active);
55
+			$index++;
56
+		}
57
+		/*
58 58
         sample content for testing
59 59
 
60 60
         $all_tabs .= '<a class="nav-tab" rel="ee-tab-anothertab" href="#anothertab">Another Tab</a>';
61 61
         $all_tabs_content .= '<div class="nav-tab-content hidden" id="ee-tab-anothertab">This is just some sample content to show another tab<div style="clear:both"></div></div>';
62 62
         //end sample content /**/
63 63
 
64
-        $all_tabs .= '</h2>';
65
-
66
-        $tab_container_class = $small_tabs ? 'ee-nav-tabs ee-nav-tabs-small' : 'ee-nav-tabs';
67
-
68
-        return '<div class="'. $tab_container_class . '">' . "\n\t" . $all_tabs . $all_tabs_content . "\n" . '</div>';
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * display_admin_nav_tabs
75
-     * this returns the properly formatted tab html for EE_Admin_Pages.
76
-     * We are expecting an array of tabs in the following format
77
-     * array(
78
-     *    'nav_tab_name' => array(
79
-     *        'url' => 'url for tab',
80
-     *        'link_text' => 'tab text',
81
-     *        'css_class' => 'tab class' //including the nav-tab-active class if its active
82
-     *    )
83
-     * )
84
-     *
85
-     * @access public
86
-     * @static
87
-     * @param array $nav_tabs tab array for nav tabs
88
-     * @return string
89
-     * @throws \EE_Error
90
-     */
91
-    public static function display_admin_nav_tabs($nav_tabs = array())
92
-    {
93
-        if (empty($nav_tabs)) {
94
-            throw new EE_Error(__('Nav Tabs cannot be generated because the tab array is missing', 'event_espresso'));
95
-        }
96
-
97
-        $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n";
98
-        foreach ($nav_tabs as $slug => $tab) {
99
-            $all_tabs .= self::tab($slug, false, $tab['link_text'], $tab['url'], $tab['css_class']);
100
-        }
101
-        $all_tabs .= '</h2>';
102
-        return $all_tabs;
103
-    }
104
-
105
-    /**
106
-     * this simply returns a single tab given a tab name & content
107
-     * @param  string $name    name of tab
108
-     * @param bool $active true=tab active, false=tab not active
109
-     * @param bool|string $nice_name if string given then this value will be used for the tab link text.
110
-     * @param bool|string $url If url given then tabs will be generated linking to the url.
111
-     * @param bool|string $css If string given then the generated tab will include that as the class.
112
-     * @return string          html for tab
113
-     */
114
-    private static function tab($name, $active = false, $nice_name = false, $url = false, $css = false)
115
-    {
116
-        $name = str_replace(' ', '-', $name);
117
-        $class = $active ? 'nav-tab nav-tab-active' : 'nav-tab';
118
-        $class = $css ? $class . ' ' . $css : $class;
119
-        $nice_name = $nice_name ? $nice_name : ucwords(preg_replace('/(-|_)/', ' ', $name));
120
-        $url = $url ? $url : '#' . $name;
121
-        $tab = '<a class="' . $class . '" rel="ee-tab-' . $name . '" href="' . $url . '">' . $nice_name . '</a>' . "\n\t";
122
-        return $tab;
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * this just returns the properly formatted tab content for our tab box.
129
-     *
130
-     * @param  string $name        name of tab (used for selector)
131
-     * @param  string $tab_content content of tab
132
-     * @param  bool   $active
133
-     * @return string html for content area
134
-     */
135
-    private static function tab_content($name, $tab_content, $active = false)
136
-    {
137
-        $class = $active ? 'nav-tab-content' : 'nav-tab-content hidden';
138
-        $name = str_replace(' ', '-', $name);
139
-        $content = "\t" . '<div class="'. $class . '" id="ee-tab-' . $name . '">' . "\n";
140
-        $content .= "\t" . $tab_content . "\n";
141
-        $content .= '<div style="clear:both"></div></div>';
142
-        return $content;
143
-    }
144
-
145
-
146
-
147
-    /** HORIZONTAL TEXT LINKS **/
148
-
149
-    /**
150
-     * This will take in an array of link items and spit out a formatted list of links that can be used to navigate to items.
151
-     * There is a corresponding js file that can be loaded to dynamically display containers with the same id as the href -ref.
152
-     *
153
-     * @param  array $item_array      formatted array of items.  Format:
154
-     * array(
155
-     *      'label' => __('localized label displayed'),
156
-     *      'class' => 'class_for_item',
157
-     *      'href' => '#some_item_id', //url/bookmark for item.  If you include a bookmark the js will used this to show the container div.
158
-     *      'title' => __('localized text for the title attribute of the link'),
159
-     *      'slug' => 'slug_used_for_reference'
160
-     * )
161
-     * @param  string $container_class class used for main container
162
-     * @param  string $sep              you can add in what is used as a separator between each link (or leave blank for none)
163
-     * @param string $default           You can include a string for the item that will receive the "item_display" class for the js.
164
-     * @return string                  a html snippet of of all the formatted link elements.
165
-     */
166
-    public static function tab_text_links($item_array, $container_class = '', $sep = '|', $default = '')
167
-    {
168
-        $item_array = apply_filters('FHEE__EEH_Tabbed_Content__tab_text_links', $item_array, $container_class);
169
-        if (!is_array($item_array) || empty($item_array)) {
170
-            return false; // get out we don't have even the basic thing we need!
171
-        }
172
-
173
-
174
-        $defaults = array(
175
-            'label' => __('Item', 'event_espresso'),
176
-            'class' => '',
177
-            'href' => '',
178
-            'title' => esc_attr__('Link for Item', 'event_espresso'),
179
-            'slug' => 'item_slug'
180
-        );
181
-        $container_class = !empty($container_class) ? 'ee-text-links ' . $container_class : 'ee-text-links';
182
-        $list = '<ul class="' . $container_class . '">';
183
-
184
-        $ci = 1;
185
-        foreach ($item_array as $item) {
186
-            $item = wp_parse_args($item, $defaults);
187
-            $item['class'] = !empty($default) && $default == $item['slug'] ? 'item_display ' . $item['class'] : $item['class'];
188
-            $list .= self::_text_link_item($item);
189
-            if (!empty($sep) && $ci != count($item_array)) {
190
-                $list .= self::_text_link_item($sep);
191
-            }
192
-            $ci++;
193
-        }
194
-
195
-        $list .= '</ul>';
196
-        return $list;
197
-    }
198
-
199
-
200
-
201
-    private static function _text_link_item($item)
202
-    {
203
-        // if this isn't an array then we're doing a separator
204
-        if (!is_array($item)) {
205
-            $label = $item;
206
-            $class = 'ee-text-link-sep';
207
-            $href = '';
208
-            $title = '';
209
-        } else {
210
-            extract($item);
211
-        }
212
-
213
-        $class = $class != 'ee-text-link-sep'  ? 'class="ee-text-link-li ' . $class . '"' : 'class="ee-text-link-sep"';
214
-
215
-        $content = '<li ' . $class . '>';
216
-        $content .= !empty($href) ? '<a class="ee-text-link" href="#' . $href . '" title="' . $title . '">' : '';
217
-        $content .= $label;
218
-        $content .= !empty($href) ? '</a>' : '';
219
-        $content .= '</li>';
220
-        return $content;
221
-    }
64
+		$all_tabs .= '</h2>';
65
+
66
+		$tab_container_class = $small_tabs ? 'ee-nav-tabs ee-nav-tabs-small' : 'ee-nav-tabs';
67
+
68
+		return '<div class="'. $tab_container_class . '">' . "\n\t" . $all_tabs . $all_tabs_content . "\n" . '</div>';
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * display_admin_nav_tabs
75
+	 * this returns the properly formatted tab html for EE_Admin_Pages.
76
+	 * We are expecting an array of tabs in the following format
77
+	 * array(
78
+	 *    'nav_tab_name' => array(
79
+	 *        'url' => 'url for tab',
80
+	 *        'link_text' => 'tab text',
81
+	 *        'css_class' => 'tab class' //including the nav-tab-active class if its active
82
+	 *    )
83
+	 * )
84
+	 *
85
+	 * @access public
86
+	 * @static
87
+	 * @param array $nav_tabs tab array for nav tabs
88
+	 * @return string
89
+	 * @throws \EE_Error
90
+	 */
91
+	public static function display_admin_nav_tabs($nav_tabs = array())
92
+	{
93
+		if (empty($nav_tabs)) {
94
+			throw new EE_Error(__('Nav Tabs cannot be generated because the tab array is missing', 'event_espresso'));
95
+		}
96
+
97
+		$all_tabs = '<h2 class="nav-tab-wrapper">' . "\n";
98
+		foreach ($nav_tabs as $slug => $tab) {
99
+			$all_tabs .= self::tab($slug, false, $tab['link_text'], $tab['url'], $tab['css_class']);
100
+		}
101
+		$all_tabs .= '</h2>';
102
+		return $all_tabs;
103
+	}
104
+
105
+	/**
106
+	 * this simply returns a single tab given a tab name & content
107
+	 * @param  string $name    name of tab
108
+	 * @param bool $active true=tab active, false=tab not active
109
+	 * @param bool|string $nice_name if string given then this value will be used for the tab link text.
110
+	 * @param bool|string $url If url given then tabs will be generated linking to the url.
111
+	 * @param bool|string $css If string given then the generated tab will include that as the class.
112
+	 * @return string          html for tab
113
+	 */
114
+	private static function tab($name, $active = false, $nice_name = false, $url = false, $css = false)
115
+	{
116
+		$name = str_replace(' ', '-', $name);
117
+		$class = $active ? 'nav-tab nav-tab-active' : 'nav-tab';
118
+		$class = $css ? $class . ' ' . $css : $class;
119
+		$nice_name = $nice_name ? $nice_name : ucwords(preg_replace('/(-|_)/', ' ', $name));
120
+		$url = $url ? $url : '#' . $name;
121
+		$tab = '<a class="' . $class . '" rel="ee-tab-' . $name . '" href="' . $url . '">' . $nice_name . '</a>' . "\n\t";
122
+		return $tab;
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * this just returns the properly formatted tab content for our tab box.
129
+	 *
130
+	 * @param  string $name        name of tab (used for selector)
131
+	 * @param  string $tab_content content of tab
132
+	 * @param  bool   $active
133
+	 * @return string html for content area
134
+	 */
135
+	private static function tab_content($name, $tab_content, $active = false)
136
+	{
137
+		$class = $active ? 'nav-tab-content' : 'nav-tab-content hidden';
138
+		$name = str_replace(' ', '-', $name);
139
+		$content = "\t" . '<div class="'. $class . '" id="ee-tab-' . $name . '">' . "\n";
140
+		$content .= "\t" . $tab_content . "\n";
141
+		$content .= '<div style="clear:both"></div></div>';
142
+		return $content;
143
+	}
144
+
145
+
146
+
147
+	/** HORIZONTAL TEXT LINKS **/
148
+
149
+	/**
150
+	 * This will take in an array of link items and spit out a formatted list of links that can be used to navigate to items.
151
+	 * There is a corresponding js file that can be loaded to dynamically display containers with the same id as the href -ref.
152
+	 *
153
+	 * @param  array $item_array      formatted array of items.  Format:
154
+	 * array(
155
+	 *      'label' => __('localized label displayed'),
156
+	 *      'class' => 'class_for_item',
157
+	 *      'href' => '#some_item_id', //url/bookmark for item.  If you include a bookmark the js will used this to show the container div.
158
+	 *      'title' => __('localized text for the title attribute of the link'),
159
+	 *      'slug' => 'slug_used_for_reference'
160
+	 * )
161
+	 * @param  string $container_class class used for main container
162
+	 * @param  string $sep              you can add in what is used as a separator between each link (or leave blank for none)
163
+	 * @param string $default           You can include a string for the item that will receive the "item_display" class for the js.
164
+	 * @return string                  a html snippet of of all the formatted link elements.
165
+	 */
166
+	public static function tab_text_links($item_array, $container_class = '', $sep = '|', $default = '')
167
+	{
168
+		$item_array = apply_filters('FHEE__EEH_Tabbed_Content__tab_text_links', $item_array, $container_class);
169
+		if (!is_array($item_array) || empty($item_array)) {
170
+			return false; // get out we don't have even the basic thing we need!
171
+		}
172
+
173
+
174
+		$defaults = array(
175
+			'label' => __('Item', 'event_espresso'),
176
+			'class' => '',
177
+			'href' => '',
178
+			'title' => esc_attr__('Link for Item', 'event_espresso'),
179
+			'slug' => 'item_slug'
180
+		);
181
+		$container_class = !empty($container_class) ? 'ee-text-links ' . $container_class : 'ee-text-links';
182
+		$list = '<ul class="' . $container_class . '">';
183
+
184
+		$ci = 1;
185
+		foreach ($item_array as $item) {
186
+			$item = wp_parse_args($item, $defaults);
187
+			$item['class'] = !empty($default) && $default == $item['slug'] ? 'item_display ' . $item['class'] : $item['class'];
188
+			$list .= self::_text_link_item($item);
189
+			if (!empty($sep) && $ci != count($item_array)) {
190
+				$list .= self::_text_link_item($sep);
191
+			}
192
+			$ci++;
193
+		}
194
+
195
+		$list .= '</ul>';
196
+		return $list;
197
+	}
198
+
199
+
200
+
201
+	private static function _text_link_item($item)
202
+	{
203
+		// if this isn't an array then we're doing a separator
204
+		if (!is_array($item)) {
205
+			$label = $item;
206
+			$class = 'ee-text-link-sep';
207
+			$href = '';
208
+			$title = '';
209
+		} else {
210
+			extract($item);
211
+		}
212
+
213
+		$class = $class != 'ee-text-link-sep'  ? 'class="ee-text-link-li ' . $class . '"' : 'class="ee-text-link-sep"';
214
+
215
+		$content = '<li ' . $class . '>';
216
+		$content .= !empty($href) ? '<a class="ee-text-link" href="#' . $href . '" title="' . $title . '">' : '';
217
+		$content .= $label;
218
+		$content .= !empty($href) ? '</a>' : '';
219
+		$content .= '</li>';
220
+		return $content;
221
+	}
222 222
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -36,22 +36,22 @@  discard block
 block discarded – undo
36 36
     {
37 37
 
38 38
         // first check if $tabs_names is not empty then the count must match the count of $tabs_content otherwise we've got a problem houston
39
-        if (!empty($tabs_names) && ( count((array) $tabs_names) != count((array) $tabs_content) )) {
39
+        if ( ! empty($tabs_names) && (count((array) $tabs_names) != count((array) $tabs_content))) {
40 40
             throw new EE_Error(__('The count for $tabs_names and $tabs_content does not match.', 'event_espresso'));
41 41
         }
42 42
 
43 43
         // make sure we've got incoming data setup properly
44
-        $tabs = !empty($tabs_names) ? (array) $tabs_names : array_keys((array) $tabs_contents);
45
-        $tabs_content = !empty($tabs_names) ? array_combine((array) $tabs_names, (array) $tabs_content) : $tabs_contents;
44
+        $tabs = ! empty($tabs_names) ? (array) $tabs_names : array_keys((array) $tabs_contents);
45
+        $tabs_content = ! empty($tabs_names) ? array_combine((array) $tabs_names, (array) $tabs_content) : $tabs_contents;
46 46
 
47
-        $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n";
47
+        $all_tabs = '<h2 class="nav-tab-wrapper">'."\n";
48 48
         $all_tabs_content = '';
49 49
 
50 50
         $index = 0;
51 51
         foreach ($tabs as $tab) {
52 52
             $active = $index === 0 ? true : false;
53 53
             $all_tabs .= self::tab($tab, $active);
54
-            $all_tabs_content .= self::tab_content($tab, $tabs_content[ $tab ], $active);
54
+            $all_tabs_content .= self::tab_content($tab, $tabs_content[$tab], $active);
55 55
             $index++;
56 56
         }
57 57
         /*
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 
66 66
         $tab_container_class = $small_tabs ? 'ee-nav-tabs ee-nav-tabs-small' : 'ee-nav-tabs';
67 67
 
68
-        return '<div class="'. $tab_container_class . '">' . "\n\t" . $all_tabs . $all_tabs_content . "\n" . '</div>';
68
+        return '<div class="'.$tab_container_class.'">'."\n\t".$all_tabs.$all_tabs_content."\n".'</div>';
69 69
     }
70 70
 
71 71
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
             throw new EE_Error(__('Nav Tabs cannot be generated because the tab array is missing', 'event_espresso'));
95 95
         }
96 96
 
97
-        $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n";
97
+        $all_tabs = '<h2 class="nav-tab-wrapper">'."\n";
98 98
         foreach ($nav_tabs as $slug => $tab) {
99 99
             $all_tabs .= self::tab($slug, false, $tab['link_text'], $tab['url'], $tab['css_class']);
100 100
         }
@@ -115,10 +115,10 @@  discard block
 block discarded – undo
115 115
     {
116 116
         $name = str_replace(' ', '-', $name);
117 117
         $class = $active ? 'nav-tab nav-tab-active' : 'nav-tab';
118
-        $class = $css ? $class . ' ' . $css : $class;
118
+        $class = $css ? $class.' '.$css : $class;
119 119
         $nice_name = $nice_name ? $nice_name : ucwords(preg_replace('/(-|_)/', ' ', $name));
120
-        $url = $url ? $url : '#' . $name;
121
-        $tab = '<a class="' . $class . '" rel="ee-tab-' . $name . '" href="' . $url . '">' . $nice_name . '</a>' . "\n\t";
120
+        $url = $url ? $url : '#'.$name;
121
+        $tab = '<a class="'.$class.'" rel="ee-tab-'.$name.'" href="'.$url.'">'.$nice_name.'</a>'."\n\t";
122 122
         return $tab;
123 123
     }
124 124
 
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
     {
137 137
         $class = $active ? 'nav-tab-content' : 'nav-tab-content hidden';
138 138
         $name = str_replace(' ', '-', $name);
139
-        $content = "\t" . '<div class="'. $class . '" id="ee-tab-' . $name . '">' . "\n";
140
-        $content .= "\t" . $tab_content . "\n";
139
+        $content = "\t".'<div class="'.$class.'" id="ee-tab-'.$name.'">'."\n";
140
+        $content .= "\t".$tab_content."\n";
141 141
         $content .= '<div style="clear:both"></div></div>';
142 142
         return $content;
143 143
     }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
     public static function tab_text_links($item_array, $container_class = '', $sep = '|', $default = '')
167 167
     {
168 168
         $item_array = apply_filters('FHEE__EEH_Tabbed_Content__tab_text_links', $item_array, $container_class);
169
-        if (!is_array($item_array) || empty($item_array)) {
169
+        if ( ! is_array($item_array) || empty($item_array)) {
170 170
             return false; // get out we don't have even the basic thing we need!
171 171
         }
172 172
 
@@ -178,15 +178,15 @@  discard block
 block discarded – undo
178 178
             'title' => esc_attr__('Link for Item', 'event_espresso'),
179 179
             'slug' => 'item_slug'
180 180
         );
181
-        $container_class = !empty($container_class) ? 'ee-text-links ' . $container_class : 'ee-text-links';
182
-        $list = '<ul class="' . $container_class . '">';
181
+        $container_class = ! empty($container_class) ? 'ee-text-links '.$container_class : 'ee-text-links';
182
+        $list = '<ul class="'.$container_class.'">';
183 183
 
184 184
         $ci = 1;
185 185
         foreach ($item_array as $item) {
186 186
             $item = wp_parse_args($item, $defaults);
187
-            $item['class'] = !empty($default) && $default == $item['slug'] ? 'item_display ' . $item['class'] : $item['class'];
187
+            $item['class'] = ! empty($default) && $default == $item['slug'] ? 'item_display '.$item['class'] : $item['class'];
188 188
             $list .= self::_text_link_item($item);
189
-            if (!empty($sep) && $ci != count($item_array)) {
189
+            if ( ! empty($sep) && $ci != count($item_array)) {
190 190
                 $list .= self::_text_link_item($sep);
191 191
             }
192 192
             $ci++;
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
     private static function _text_link_item($item)
202 202
     {
203 203
         // if this isn't an array then we're doing a separator
204
-        if (!is_array($item)) {
204
+        if ( ! is_array($item)) {
205 205
             $label = $item;
206 206
             $class = 'ee-text-link-sep';
207 207
             $href = '';
@@ -210,12 +210,12 @@  discard block
 block discarded – undo
210 210
             extract($item);
211 211
         }
212 212
 
213
-        $class = $class != 'ee-text-link-sep'  ? 'class="ee-text-link-li ' . $class . '"' : 'class="ee-text-link-sep"';
213
+        $class = $class != 'ee-text-link-sep' ? 'class="ee-text-link-li '.$class.'"' : 'class="ee-text-link-sep"';
214 214
 
215
-        $content = '<li ' . $class . '>';
216
-        $content .= !empty($href) ? '<a class="ee-text-link" href="#' . $href . '" title="' . $title . '">' : '';
215
+        $content = '<li '.$class.'>';
216
+        $content .= ! empty($href) ? '<a class="ee-text-link" href="#'.$href.'" title="'.$title.'">' : '';
217 217
         $content .= $label;
218
-        $content .= !empty($href) ? '</a>' : '';
218
+        $content .= ! empty($href) ? '</a>' : '';
219 219
         $content .= '</li>';
220 220
         return $content;
221 221
     }
Please login to merge, or discard this patch.
core/helpers/EEH_Money.helper.php 2 patches
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -12,221 +12,221 @@
 block discarded – undo
12 12
 class EEH_Money extends EEH_Base
13 13
 {
14 14
 
15
-    /**
16
-     * This removes all localized money formatting from the incoming value
17
-     * Note: uses this site's currency settings for deciding what is considered a
18
-     * "thousands separator" (usually the character "," )
19
-     * and what is a "decimal mark" (usually the character ".")
20
-     *
21
-     * @param int|float|string $money_value
22
-     * @param string           $CNT_ISO
23
-     * @return float
24
-     * @throws EE_Error
25
-     */
26
-    public static function strip_localized_money_formatting($money_value, $CNT_ISO = '')
27
-    {
28
-        $currency_config = EEH_Money::get_currency_config($CNT_ISO);
29
-        $money_value     = str_replace(
30
-            array(
31
-                $currency_config->thsnds,
32
-                $currency_config->dec_mrk,
33
-            ),
34
-            array(
35
-                '', // remove thousands separator
36
-                '.', // convert decimal mark to what PHP expects
37
-            ),
38
-            $money_value
39
-        );
40
-        $money_value     = filter_var(
41
-            $money_value,
42
-            FILTER_SANITIZE_NUMBER_FLOAT,
43
-            FILTER_FLAG_ALLOW_FRACTION
44
-        );
45
-        return $money_value;
46
-    }
15
+	/**
16
+	 * This removes all localized money formatting from the incoming value
17
+	 * Note: uses this site's currency settings for deciding what is considered a
18
+	 * "thousands separator" (usually the character "," )
19
+	 * and what is a "decimal mark" (usually the character ".")
20
+	 *
21
+	 * @param int|float|string $money_value
22
+	 * @param string           $CNT_ISO
23
+	 * @return float
24
+	 * @throws EE_Error
25
+	 */
26
+	public static function strip_localized_money_formatting($money_value, $CNT_ISO = '')
27
+	{
28
+		$currency_config = EEH_Money::get_currency_config($CNT_ISO);
29
+		$money_value     = str_replace(
30
+			array(
31
+				$currency_config->thsnds,
32
+				$currency_config->dec_mrk,
33
+			),
34
+			array(
35
+				'', // remove thousands separator
36
+				'.', // convert decimal mark to what PHP expects
37
+			),
38
+			$money_value
39
+		);
40
+		$money_value     = filter_var(
41
+			$money_value,
42
+			FILTER_SANITIZE_NUMBER_FLOAT,
43
+			FILTER_FLAG_ALLOW_FRACTION
44
+		);
45
+		return $money_value;
46
+	}
47 47
 
48 48
 
49
-    /**
50
-     * This converts an incoming localized money value into a standard float item (to three decimal places)
51
-     * Only use this if you know the $money_value follows your currency configuration's
52
-     * settings. Note: this uses this site's currency settings for deciding what is considered a
53
-     * "thousands separator" (usually the character "," )
54
-     * and what is a "decimal mark" (usually the character ".")
55
-     *
56
-     * @param int|string $money_value
57
-     * @return float
58
-     * @throws EE_Error
59
-     */
60
-    public static function convert_to_float_from_localized_money($money_value)
61
-    {
62
-        // float it! and round to three decimal places
63
-        return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3);
64
-    }
49
+	/**
50
+	 * This converts an incoming localized money value into a standard float item (to three decimal places)
51
+	 * Only use this if you know the $money_value follows your currency configuration's
52
+	 * settings. Note: this uses this site's currency settings for deciding what is considered a
53
+	 * "thousands separator" (usually the character "," )
54
+	 * and what is a "decimal mark" (usually the character ".")
55
+	 *
56
+	 * @param int|string $money_value
57
+	 * @return float
58
+	 * @throws EE_Error
59
+	 */
60
+	public static function convert_to_float_from_localized_money($money_value)
61
+	{
62
+		// float it! and round to three decimal places
63
+		return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3);
64
+	}
65 65
 
66 66
 
67
-    /**
68
-     * For comparing floats. Default operator is '=', but see the $operator below for all options.
69
-     * This should be used to compare floats instead of normal '==' because floats
70
-     * are inherently imprecise, and so you can sometimes have two floats that appear to be identical
71
-     * but actually differ by 0.00000001.
72
-     *
73
-     * @see http://biostall.com/php-function-to-compare-floating-point-numbers
74
-     * @param float  $float1
75
-     * @param float  $float2
76
-     * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne
77
-     * @return bool whether the equation is true or false
78
-     * @throws EE_Error
79
-     */
80
-    public static function compare_floats($float1, $float2, $operator = '=')
81
-    {
82
-        // Check numbers to 5 digits of precision
83
-        $epsilon = 0.00001;
84
-        $float1 = (float) $float1;
85
-        $float2 = (float) $float2;
86
-        switch ($operator) {
87
-            // equal
88
-            case "=":
89
-            case "==":
90
-            case "===":
91
-            case "eq":
92
-                if (abs($float1 - $float2) < $epsilon) {
93
-                    return true;
94
-                }
95
-                break;
96
-            // less than
97
-            case "<":
98
-            case "lt":
99
-                if (abs($float1 - $float2) < $epsilon) {
100
-                    return false;
101
-                } else {
102
-                    if ($float1 < $float2) {
103
-                        return true;
104
-                    }
105
-                }
106
-                break;
107
-            // less than or equal
108
-            case "<=":
109
-            case "lte":
110
-                if (self::compare_floats($float1, $float2, '<') || self::compare_floats($float1, $float2, '=')) {
111
-                    return true;
112
-                }
113
-                break;
114
-            // greater than
115
-            case ">":
116
-            case "gt":
117
-                if (abs($float1 - $float2) < $epsilon) {
118
-                    return false;
119
-                } else {
120
-                    if ($float1 > $float2) {
121
-                        return true;
122
-                    }
123
-                }
124
-                break;
125
-            // greater than or equal
126
-            case ">=":
127
-            case "gte":
128
-                if (self::compare_floats($float1, $float2, '>') || self::compare_floats($float1, $float2, '=')) {
129
-                    return true;
130
-                }
131
-                break;
132
-            case "<>":
133
-            case "!=":
134
-            case "ne":
135
-                if (abs($float1 - $float2) > $epsilon) {
136
-                    return true;
137
-                }
138
-                break;
139
-            default:
140
-                throw new EE_Error(
141
-                    sprintf(
142
-                        __(
143
-                            "Unknown operator %s in EEH_Money::compare_floats()",
144
-                            'event_espresso'
145
-                        ),
146
-                        $operator
147
-                    )
148
-                );
149
-        }
150
-        return false;
151
-    }
67
+	/**
68
+	 * For comparing floats. Default operator is '=', but see the $operator below for all options.
69
+	 * This should be used to compare floats instead of normal '==' because floats
70
+	 * are inherently imprecise, and so you can sometimes have two floats that appear to be identical
71
+	 * but actually differ by 0.00000001.
72
+	 *
73
+	 * @see http://biostall.com/php-function-to-compare-floating-point-numbers
74
+	 * @param float  $float1
75
+	 * @param float  $float2
76
+	 * @param string $operator The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne
77
+	 * @return bool whether the equation is true or false
78
+	 * @throws EE_Error
79
+	 */
80
+	public static function compare_floats($float1, $float2, $operator = '=')
81
+	{
82
+		// Check numbers to 5 digits of precision
83
+		$epsilon = 0.00001;
84
+		$float1 = (float) $float1;
85
+		$float2 = (float) $float2;
86
+		switch ($operator) {
87
+			// equal
88
+			case "=":
89
+			case "==":
90
+			case "===":
91
+			case "eq":
92
+				if (abs($float1 - $float2) < $epsilon) {
93
+					return true;
94
+				}
95
+				break;
96
+			// less than
97
+			case "<":
98
+			case "lt":
99
+				if (abs($float1 - $float2) < $epsilon) {
100
+					return false;
101
+				} else {
102
+					if ($float1 < $float2) {
103
+						return true;
104
+					}
105
+				}
106
+				break;
107
+			// less than or equal
108
+			case "<=":
109
+			case "lte":
110
+				if (self::compare_floats($float1, $float2, '<') || self::compare_floats($float1, $float2, '=')) {
111
+					return true;
112
+				}
113
+				break;
114
+			// greater than
115
+			case ">":
116
+			case "gt":
117
+				if (abs($float1 - $float2) < $epsilon) {
118
+					return false;
119
+				} else {
120
+					if ($float1 > $float2) {
121
+						return true;
122
+					}
123
+				}
124
+				break;
125
+			// greater than or equal
126
+			case ">=":
127
+			case "gte":
128
+				if (self::compare_floats($float1, $float2, '>') || self::compare_floats($float1, $float2, '=')) {
129
+					return true;
130
+				}
131
+				break;
132
+			case "<>":
133
+			case "!=":
134
+			case "ne":
135
+				if (abs($float1 - $float2) > $epsilon) {
136
+					return true;
137
+				}
138
+				break;
139
+			default:
140
+				throw new EE_Error(
141
+					sprintf(
142
+						__(
143
+							"Unknown operator %s in EEH_Money::compare_floats()",
144
+							'event_espresso'
145
+						),
146
+						$operator
147
+					)
148
+				);
149
+		}
150
+		return false;
151
+	}
152 152
 
153 153
 
154
-    /**
155
-     * This returns a localized format string suitable for jQplot.
156
-     *
157
-     * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
158
-     *                         Otherwise will use currency settings for current active country on site.
159
-     * @return string
160
-     * @throws EE_Error
161
-     */
162
-    public static function get_format_for_jqplot($CNT_ISO = '')
163
-    {
164
-        // default format
165
-        $format          = 'f';
166
-        $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
167
-        // first get the decimal place and number of places
168
-        $format = "%'." . $currency_config->dec_plc . $format;
169
-        // currency symbol on right side.
170
-        $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
171
-        return $format;
172
-    }
154
+	/**
155
+	 * This returns a localized format string suitable for jQplot.
156
+	 *
157
+	 * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
158
+	 *                         Otherwise will use currency settings for current active country on site.
159
+	 * @return string
160
+	 * @throws EE_Error
161
+	 */
162
+	public static function get_format_for_jqplot($CNT_ISO = '')
163
+	{
164
+		// default format
165
+		$format          = 'f';
166
+		$currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
167
+		// first get the decimal place and number of places
168
+		$format = "%'." . $currency_config->dec_plc . $format;
169
+		// currency symbol on right side.
170
+		$format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
171
+		return $format;
172
+	}
173 173
 
174 174
 
175
-    /**
176
-     * This returns a localized format string suitable for usage with the Google Charts API format param.
177
-     *
178
-     * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
179
-     *                         Otherwise will use currency settings for current active country on site.
180
-     *                         Note: GoogleCharts uses ICU pattern set
181
-     *                         (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details)
182
-     * @return string
183
-     * @throws EE_Error
184
-     */
185
-    public static function get_format_for_google_charts($CNT_ISO = '')
186
-    {
187
-        $currency_config            = EEH_Money::get_currency_config($CNT_ISO);
188
-        $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0');
189
-        // first get the decimal place and number of places
190
-        $format = '#,##0.' . $decimal_places_placeholder;
191
-        // currency symbol on right side.
192
-        $format          = $currency_config->sign_b4
193
-            ? $currency_config->sign . $format
194
-            : $format
195
-              . $currency_config->sign;
196
-        $formatterObject = array(
197
-            'decimalSymbol'  => $currency_config->dec_mrk,
198
-            'groupingSymbol' => $currency_config->thsnds,
199
-            'fractionDigits' => $currency_config->dec_plc,
200
-        );
201
-        if ($currency_config->sign_b4) {
202
-            $formatterObject['prefix'] = $currency_config->sign;
203
-        } else {
204
-            $formatterObject['suffix'] = $currency_config->sign;
205
-        }
206
-        return array(
207
-            'format'          => $format,
208
-            'formatterObject' => $formatterObject,
209
-        );
210
-    }
175
+	/**
176
+	 * This returns a localized format string suitable for usage with the Google Charts API format param.
177
+	 *
178
+	 * @param string $CNT_ISO  If this is provided, then will attempt to get the currency settings for the country.
179
+	 *                         Otherwise will use currency settings for current active country on site.
180
+	 *                         Note: GoogleCharts uses ICU pattern set
181
+	 *                         (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details)
182
+	 * @return string
183
+	 * @throws EE_Error
184
+	 */
185
+	public static function get_format_for_google_charts($CNT_ISO = '')
186
+	{
187
+		$currency_config            = EEH_Money::get_currency_config($CNT_ISO);
188
+		$decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0');
189
+		// first get the decimal place and number of places
190
+		$format = '#,##0.' . $decimal_places_placeholder;
191
+		// currency symbol on right side.
192
+		$format          = $currency_config->sign_b4
193
+			? $currency_config->sign . $format
194
+			: $format
195
+			  . $currency_config->sign;
196
+		$formatterObject = array(
197
+			'decimalSymbol'  => $currency_config->dec_mrk,
198
+			'groupingSymbol' => $currency_config->thsnds,
199
+			'fractionDigits' => $currency_config->dec_plc,
200
+		);
201
+		if ($currency_config->sign_b4) {
202
+			$formatterObject['prefix'] = $currency_config->sign;
203
+		} else {
204
+			$formatterObject['suffix'] = $currency_config->sign;
205
+		}
206
+		return array(
207
+			'format'          => $format,
208
+			'formatterObject' => $formatterObject,
209
+		);
210
+	}
211 211
 
212 212
 
213
-    /**
214
-     * @param string $CNT_ISO
215
-     * @return EE_Currency_Config|null
216
-     * @throws EE_Error
217
-     */
218
-    public static function get_currency_config($CNT_ISO = '')
219
-    {
220
-        // if CNT_ISO passed lets try to get currency settings for it.
221
-        $currency_config = $CNT_ISO !== ''
222
-            ? new EE_Currency_Config($CNT_ISO)
223
-            : null;
224
-        // default currency settings for site if not set
225
-        if (! $currency_config instanceof EE_Currency_Config) {
226
-            $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
227
-                ? EE_Registry::instance()->CFG->currency
228
-                : new EE_Currency_Config();
229
-        }
230
-        return $currency_config;
231
-    }
213
+	/**
214
+	 * @param string $CNT_ISO
215
+	 * @return EE_Currency_Config|null
216
+	 * @throws EE_Error
217
+	 */
218
+	public static function get_currency_config($CNT_ISO = '')
219
+	{
220
+		// if CNT_ISO passed lets try to get currency settings for it.
221
+		$currency_config = $CNT_ISO !== ''
222
+			? new EE_Currency_Config($CNT_ISO)
223
+			: null;
224
+		// default currency settings for site if not set
225
+		if (! $currency_config instanceof EE_Currency_Config) {
226
+			$currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
227
+				? EE_Registry::instance()->CFG->currency
228
+				: new EE_Currency_Config();
229
+		}
230
+		return $currency_config;
231
+	}
232 232
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
             ),
38 38
             $money_value
39 39
         );
40
-        $money_value     = filter_var(
40
+        $money_value = filter_var(
41 41
             $money_value,
42 42
             FILTER_SANITIZE_NUMBER_FLOAT,
43 43
             FILTER_FLAG_ALLOW_FRACTION
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
         $format          = 'f';
166 166
         $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO);
167 167
         // first get the decimal place and number of places
168
-        $format = "%'." . $currency_config->dec_plc . $format;
168
+        $format = "%'.".$currency_config->dec_plc.$format;
169 169
         // currency symbol on right side.
170
-        $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign;
170
+        $format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign;
171 171
         return $format;
172 172
     }
173 173
 
@@ -187,10 +187,10 @@  discard block
 block discarded – undo
187 187
         $currency_config            = EEH_Money::get_currency_config($CNT_ISO);
188 188
         $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0');
189 189
         // first get the decimal place and number of places
190
-        $format = '#,##0.' . $decimal_places_placeholder;
190
+        $format = '#,##0.'.$decimal_places_placeholder;
191 191
         // currency symbol on right side.
192
-        $format          = $currency_config->sign_b4
193
-            ? $currency_config->sign . $format
192
+        $format = $currency_config->sign_b4
193
+            ? $currency_config->sign.$format
194 194
             : $format
195 195
               . $currency_config->sign;
196 196
         $formatterObject = array(
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
             ? new EE_Currency_Config($CNT_ISO)
223 223
             : null;
224 224
         // default currency settings for site if not set
225
-        if (! $currency_config instanceof EE_Currency_Config) {
225
+        if ( ! $currency_config instanceof EE_Currency_Config) {
226 226
             $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
227 227
                 ? EE_Registry::instance()->CFG->currency
228 228
                 : new EE_Currency_Config();
Please login to merge, or discard this patch.
core/CPTs/EE_CPT_Default_Strategy.core.php 2 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -13,70 +13,70 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * $CPT - the current page, if it utilizes CPTs
18
-     *
19
-     * @var    object
20
-     * @access    protected
21
-     */
22
-    protected $CPT = null;
16
+	/**
17
+	 * $CPT - the current page, if it utilizes CPTs
18
+	 *
19
+	 * @var    object
20
+	 * @access    protected
21
+	 */
22
+	protected $CPT = null;
23 23
 
24 24
 
25
-    /**
26
-     *    class constructor
27
-     *
28
-     * @access    private
29
-     * @param    array $arguments
30
-     * @return    \EE_CPT_Default_Strategy
31
-     */
32
-    public function __construct($arguments = array())
33
-    {
34
-        $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null;
35
-    }
25
+	/**
26
+	 *    class constructor
27
+	 *
28
+	 * @access    private
29
+	 * @param    array $arguments
30
+	 * @return    \EE_CPT_Default_Strategy
31
+	 */
32
+	public function __construct($arguments = array())
33
+	{
34
+		$this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null;
35
+	}
36 36
 
37 37
 
38
-    /**
39
-     *    pre_get_posts
40
-     *
41
-     * @access    public
42
-     * @param    \WP_Query $WP_Query
43
-     * @return    \WP_Query
44
-     */
45
-    public function pre_get_posts(WP_Query $WP_Query)
46
-    {
47
-        if (! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) {
48
-            return $WP_Query;
49
-        }
50
-        return $WP_Query;
51
-    }
38
+	/**
39
+	 *    pre_get_posts
40
+	 *
41
+	 * @access    public
42
+	 * @param    \WP_Query $WP_Query
43
+	 * @return    \WP_Query
44
+	 */
45
+	public function pre_get_posts(WP_Query $WP_Query)
46
+	{
47
+		if (! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) {
48
+			return $WP_Query;
49
+		}
50
+		return $WP_Query;
51
+	}
52 52
 
53 53
 
54
-    /**
55
-     *    wp
56
-     *
57
-     * @access    public
58
-     * @param    \WP_Post[] $posts
59
-     * @param    \WP_Query  $WP_Query
60
-     * @return    \WP_Post[]
61
-     */
62
-    public function the_posts($posts, WP_Query $WP_Query)
63
-    {
64
-        return $posts;
65
-    }
54
+	/**
55
+	 *    wp
56
+	 *
57
+	 * @access    public
58
+	 * @param    \WP_Post[] $posts
59
+	 * @param    \WP_Query  $WP_Query
60
+	 * @return    \WP_Post[]
61
+	 */
62
+	public function the_posts($posts, WP_Query $WP_Query)
63
+	{
64
+		return $posts;
65
+	}
66 66
 
67 67
 
68
-    /**
69
-     *    get_EE_post_type_metadata
70
-     *
71
-     * @access    public
72
-     * @param mixed     $meta_value
73
-     * @param    int    $post_id
74
-     * @param    string $meta_key
75
-     * @param    string $single
76
-     * @return    mixed
77
-     */
78
-    public function get_EE_post_type_metadata($meta_value = null, $post_id, $meta_key, $single)
79
-    {
80
-        return $meta_value;
81
-    }
68
+	/**
69
+	 *    get_EE_post_type_metadata
70
+	 *
71
+	 * @access    public
72
+	 * @param mixed     $meta_value
73
+	 * @param    int    $post_id
74
+	 * @param    string $meta_key
75
+	 * @param    string $single
76
+	 * @return    mixed
77
+	 */
78
+	public function get_EE_post_type_metadata($meta_value = null, $post_id, $meta_key, $single)
79
+	{
80
+		return $meta_value;
81
+	}
82 82
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
      */
45 45
     public function pre_get_posts(WP_Query $WP_Query)
46 46
     {
47
-        if (! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) {
47
+        if ( ! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) {
48 48
             return $WP_Query;
49 49
         }
50 50
         return $WP_Query;
Please login to merge, or discard this patch.
core/CPTs/EE_CPT_Attendee_Strategy.core.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -24,39 +24,39 @@
 block discarded – undo
24 24
 class EE_CPT_Attendee_Strategy
25 25
 {
26 26
 
27
-    /**
28
-     * $CPT - the current page, if it utilizes CPTs
29
-     *
30
-     * @var    array
31
-     * @access    protected
32
-     */
33
-    protected $CPT = null;
27
+	/**
28
+	 * $CPT - the current page, if it utilizes CPTs
29
+	 *
30
+	 * @var    array
31
+	 * @access    protected
32
+	 */
33
+	protected $CPT = null;
34 34
 
35 35
 
36
-    /**
37
-     *    class constructor
38
-     *
39
-     * @access    public
40
-     * @param    array $arguments
41
-     * @return \EE_CPT_Attendee_Strategy
42
-     */
43
-    public function __construct($arguments = array())
44
-    {
45
-        $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null;
46
-        $WP_Query = isset($arguments['WP_Query']) ? $arguments['WP_Query'] : null;
47
-    }
36
+	/**
37
+	 *    class constructor
38
+	 *
39
+	 * @access    public
40
+	 * @param    array $arguments
41
+	 * @return \EE_CPT_Attendee_Strategy
42
+	 */
43
+	public function __construct($arguments = array())
44
+	{
45
+		$this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null;
46
+		$WP_Query = isset($arguments['WP_Query']) ? $arguments['WP_Query'] : null;
47
+	}
48 48
 
49 49
 
50
-    /**
51
-     *    the_posts
52
-     *
53
-     * @access    public
54
-     * @param          $posts
55
-     * @param WP_Query $wp_query
56
-     * @return    void
57
-     */
58
-    public function the_posts($posts, WP_Query $wp_query)
59
-    {
60
-        return $posts;
61
-    }
50
+	/**
51
+	 *    the_posts
52
+	 *
53
+	 * @access    public
54
+	 * @param          $posts
55
+	 * @param WP_Query $wp_query
56
+	 * @return    void
57
+	 */
58
+	public function the_posts($posts, WP_Query $wp_query)
59
+	{
60
+		return $posts;
61
+	}
62 62
 }
Please login to merge, or discard this patch.
core/CPTs/EE_CPT_Venue_Strategy.core.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -12,54 +12,54 @@
 block discarded – undo
12 12
 class EE_CPT_Venue_Strategy
13 13
 {
14 14
 
15
-    /**
16
-     * $CPT - the current page, if it utilizes CPTs
17
-     *
18
-     * @var    array
19
-     * @access    protected
20
-     */
21
-    protected $CPT = null;
15
+	/**
16
+	 * $CPT - the current page, if it utilizes CPTs
17
+	 *
18
+	 * @var    array
19
+	 * @access    protected
20
+	 */
21
+	protected $CPT = null;
22 22
 
23 23
 
24
-    /**
25
-     *    class constructor
26
-     *
27
-     * @access    public
28
-     * @param    array $arguments
29
-     * @return \EE_CPT_Venue_Strategy
30
-     */
31
-    public function __construct($arguments = array())
32
-    {
33
-        $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null;
34
-        $WP_Query = isset($arguments['WP_Query']) ? $arguments['WP_Query'] : null;
35
-        if ($WP_Query instanceof WP_Query && ! $WP_Query->is_tag) {
36
-            $WP_Query->is_espresso_venue_single = is_singular()
37
-                                                  && isset($WP_Query->query->post_type)
38
-                                                  && $WP_Query->query->post_type == 'espresso_venues';
39
-            $WP_Query->is_espresso_venue_archive = is_post_type_archive('espresso_venues') ? true : false;
40
-            $WP_Query->is_espresso_venue_taxonomy = is_tax('espresso_venue_categories') ? true : false;
41
-        }
42
-        add_filter('the_posts', array($this, 'the_posts'), 1, 2);
43
-    }
24
+	/**
25
+	 *    class constructor
26
+	 *
27
+	 * @access    public
28
+	 * @param    array $arguments
29
+	 * @return \EE_CPT_Venue_Strategy
30
+	 */
31
+	public function __construct($arguments = array())
32
+	{
33
+		$this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null;
34
+		$WP_Query = isset($arguments['WP_Query']) ? $arguments['WP_Query'] : null;
35
+		if ($WP_Query instanceof WP_Query && ! $WP_Query->is_tag) {
36
+			$WP_Query->is_espresso_venue_single = is_singular()
37
+												  && isset($WP_Query->query->post_type)
38
+												  && $WP_Query->query->post_type == 'espresso_venues';
39
+			$WP_Query->is_espresso_venue_archive = is_post_type_archive('espresso_venues') ? true : false;
40
+			$WP_Query->is_espresso_venue_taxonomy = is_tax('espresso_venue_categories') ? true : false;
41
+		}
42
+		add_filter('the_posts', array($this, 'the_posts'), 1, 2);
43
+	}
44 44
 
45 45
 
46
-    /**
47
-     *    the_posts
48
-     *
49
-     * @access    public
50
-     * @param          $posts
51
-     * @param WP_Query $wp_query
52
-     * @return    void
53
-     */
54
-    public function the_posts($posts, WP_Query $wp_query)
55
-    {
56
-        // automagically load the EEH_Venue_View helper so that it's functions are available
57
-        if (isset(EE_Registry::instance()->CFG->map_settings->use_google_maps)
58
-            && EE_Registry::instance()->CFG->map_settings->use_google_maps
59
-        ) {
60
-            EEH_Maps::espresso_google_map_js();
61
-        }
62
-        remove_filter('the_posts', array($this, 'the_posts'), 1, 2);
63
-        return $posts;
64
-    }
46
+	/**
47
+	 *    the_posts
48
+	 *
49
+	 * @access    public
50
+	 * @param          $posts
51
+	 * @param WP_Query $wp_query
52
+	 * @return    void
53
+	 */
54
+	public function the_posts($posts, WP_Query $wp_query)
55
+	{
56
+		// automagically load the EEH_Venue_View helper so that it's functions are available
57
+		if (isset(EE_Registry::instance()->CFG->map_settings->use_google_maps)
58
+			&& EE_Registry::instance()->CFG->map_settings->use_google_maps
59
+		) {
60
+			EEH_Maps::espresso_google_map_js();
61
+		}
62
+		remove_filter('the_posts', array($this, 'the_posts'), 1, 2);
63
+		return $posts;
64
+	}
65 65
 }
Please login to merge, or discard this patch.
core/EE_Payment_Processor.core.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     public static function instance()
34 34
     {
35 35
         // check if class object is instantiated
36
-        if (! self::$_instance instanceof EE_Payment_Processor) {
36
+        if ( ! self::$_instance instanceof EE_Payment_Processor) {
37 37
             self::$_instance = new self();
38 38
         }
39 39
         return self::$_instance;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
         /** @type \EE_Transaction $transaction */
171 171
         $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
172 172
         $primary_reg = $transaction->primary_registration();
173
-        if (! $primary_reg instanceof EE_Registration) {
173
+        if ( ! $primary_reg instanceof EE_Registration) {
174 174
             throw new EE_Error(
175 175
                 sprintf(
176 176
                     __(
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
                         EEM_Change_Log::instance()->log(
266 266
                             EEM_Change_Log::type_gateway,
267 267
                             array(
268
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
268
+                                'message'     => 'IPN Exception: '.$e->getMessage(),
269 269
                                 'current_url' => EEH_URL::current_url(),
270 270
                                 'payment'     => $e->getPaymentProperties(),
271 271
                                 'IPN_data'    => $e->getIpnData(),
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
                         EEM_Change_Log::instance()->log(
310 310
                             EEM_Change_Log::type_gateway,
311 311
                             array(
312
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
312
+                                'message'     => 'IPN Exception: '.$e->getMessage(),
313 313
                                 'current_url' => EEH_URL::current_url(),
314 314
                                 'payment'     => $e->getPaymentProperties(),
315 315
                                 'IPN_data'    => $e->getIpnData(),
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
     {
381 381
         $return_data = array();
382 382
         foreach ($request_data as $key => $value) {
383
-            $return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters(
383
+            $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters(
384 384
                 $value
385 385
             );
386 386
         }
Please login to merge, or discard this patch.
Indentation   +838 added lines, -838 removed lines patch added patch discarded remove patch
@@ -18,842 +18,842 @@
 block discarded – undo
18 18
 class EE_Payment_Processor extends EE_Processor_Base implements ResettableInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @var EE_Payment_Processor $_instance
23
-     * @access    private
24
-     */
25
-    private static $_instance;
26
-
27
-
28
-    /**
29
-     * @singleton method used to instantiate class object
30
-     * @access    public
31
-     * @return EE_Payment_Processor instance
32
-     */
33
-    public static function instance()
34
-    {
35
-        // check if class object is instantiated
36
-        if (! self::$_instance instanceof EE_Payment_Processor) {
37
-            self::$_instance = new self();
38
-        }
39
-        return self::$_instance;
40
-    }
41
-
42
-
43
-    /**
44
-     * @return EE_Payment_Processor
45
-     */
46
-    public static function reset()
47
-    {
48
-        self::$_instance = null;
49
-        return self::instance();
50
-    }
51
-
52
-
53
-    /**
54
-     *private constructor to prevent direct creation
55
-     *
56
-     * @Constructor
57
-     * @access private
58
-     */
59
-    private function __construct()
60
-    {
61
-        do_action('AHEE__EE_Payment_Processor__construct');
62
-        add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
63
-    }
64
-
65
-
66
-    /**
67
-     * Using the selected gateway, processes the payment for that transaction, and updates the transaction
68
-     * appropriately. Saves the payment that is generated
69
-     *
70
-     * @param EE_Payment_Method    $payment_method
71
-     * @param EE_Transaction       $transaction
72
-     * @param float                $amount       if only part of the transaction is to be paid for, how much.
73
-     *                                           Leave null if payment is for the full amount owing
74
-     * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
75
-     *                                           Receive_form_submission() should have
76
-     *                                           already been called on the billing form
77
-     *                                           (ie, its inputs should have their normalized values set).
78
-     * @param string               $return_url   string used mostly by offsite gateways to specify
79
-     *                                           where to go AFTER the offsite gateway
80
-     * @param string               $method       like 'CART', indicates who the client who called this was
81
-     * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
82
-     * @param boolean              $update_txn   whether or not to call
83
-     *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
84
-     * @param string               $cancel_url   URL to return to if off-site payments are cancelled
85
-     * @return EE_Payment
86
-     * @throws EE_Error
87
-     * @throws InvalidArgumentException
88
-     * @throws ReflectionException
89
-     * @throws RuntimeException
90
-     * @throws InvalidDataTypeException
91
-     * @throws InvalidInterfaceException
92
-     */
93
-    public function process_payment(
94
-        EE_Payment_Method $payment_method,
95
-        EE_Transaction $transaction,
96
-        $amount = null,
97
-        $billing_form = null,
98
-        $return_url = null,
99
-        $method = 'CART',
100
-        $by_admin = false,
101
-        $update_txn = true,
102
-        $cancel_url = ''
103
-    ) {
104
-        if ((float) $amount < 0) {
105
-            throw new EE_Error(
106
-                sprintf(
107
-                    __(
108
-                        'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
109
-                        'event_espresso'
110
-                    ),
111
-                    $amount,
112
-                    $transaction->ID()
113
-                )
114
-            );
115
-        }
116
-        // verify payment method
117
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
118
-            $payment_method,
119
-            true
120
-        );
121
-        // verify transaction
122
-        EEM_Transaction::instance()->ensure_is_obj($transaction);
123
-        $transaction->set_payment_method_ID($payment_method->ID());
124
-        // verify payment method type
125
-        if ($payment_method->type_obj() instanceof EE_PMT_Base) {
126
-            $payment = $payment_method->type_obj()->process_payment(
127
-                $transaction,
128
-                min($amount, $transaction->remaining()), // make sure we don't overcharge
129
-                $billing_form,
130
-                $return_url,
131
-                add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
132
-                $method,
133
-                $by_admin
134
-            );
135
-            // check if payment method uses an off-site gateway
136
-            if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
137
-                // don't process payments for off-site gateways yet because no payment has occurred yet
138
-                $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
139
-            }
140
-            return $payment;
141
-        }
142
-        EE_Error::add_error(
143
-            sprintf(
144
-                __(
145
-                    'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
146
-                    'event_espresso'
147
-                ),
148
-                '<br/>',
149
-                EE_Registry::instance()->CFG->organization->get_pretty('email')
150
-            ),
151
-            __FILE__,
152
-            __FUNCTION__,
153
-            __LINE__
154
-        );
155
-        return null;
156
-    }
157
-
158
-
159
-    /**
160
-     * @param EE_Transaction|int $transaction
161
-     * @param EE_Payment_Method  $payment_method
162
-     * @return string
163
-     * @throws EE_Error
164
-     * @throws InvalidArgumentException
165
-     * @throws InvalidDataTypeException
166
-     * @throws InvalidInterfaceException
167
-     */
168
-    public function get_ipn_url_for_payment_method($transaction, $payment_method)
169
-    {
170
-        /** @type \EE_Transaction $transaction */
171
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
172
-        $primary_reg = $transaction->primary_registration();
173
-        if (! $primary_reg instanceof EE_Registration) {
174
-            throw new EE_Error(
175
-                sprintf(
176
-                    __(
177
-                        'Cannot get IPN URL for transaction with ID %d because it has no primary registration',
178
-                        'event_espresso'
179
-                    ),
180
-                    $transaction->ID()
181
-                )
182
-            );
183
-        }
184
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
185
-            $payment_method,
186
-            true
187
-        );
188
-        $url = add_query_arg(
189
-            array(
190
-                'e_reg_url_link'    => $primary_reg->reg_url_link(),
191
-                'ee_payment_method' => $payment_method->slug(),
192
-            ),
193
-            EE_Registry::instance()->CFG->core->txn_page_url()
194
-        );
195
-        return $url;
196
-    }
197
-
198
-
199
-    /**
200
-     * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
201
-     * we can easily find what registration the IPN is for and what payment method.
202
-     * However, if not, we'll give all payment methods a chance to claim it and process it.
203
-     * If a payment is found for the IPN info, it is saved.
204
-     *
205
-     * @param array              $_req_data            eg $_REQUEST
206
-     * @param EE_Transaction|int $transaction          optional (or a transactions id)
207
-     * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
208
-     * @param boolean            $update_txn           whether or not to call
209
-     *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
210
-     * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
211
-     *                                                 or is processed manually ( false like Mijireh )
212
-     * @throws EE_Error
213
-     * @throws Exception
214
-     * @return EE_Payment
215
-     * @throws \RuntimeException
216
-     * @throws \ReflectionException
217
-     * @throws \InvalidArgumentException
218
-     * @throws InvalidInterfaceException
219
-     * @throws InvalidDataTypeException
220
-     */
221
-    public function process_ipn(
222
-        $_req_data,
223
-        $transaction = null,
224
-        $payment_method = null,
225
-        $update_txn = true,
226
-        $separate_IPN_request = true
227
-    ) {
228
-        EE_Registry::instance()->load_model('Change_Log');
229
-        $_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data);
230
-        EE_Processor_Base::set_IPN($separate_IPN_request);
231
-        $obj_for_log = null;
232
-        if ($transaction instanceof EE_Transaction) {
233
-            $obj_for_log = $transaction;
234
-            if ($payment_method instanceof EE_Payment_Method) {
235
-                $obj_for_log = EEM_Payment::instance()->get_one(
236
-                    array(
237
-                        array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
238
-                        'order_by' => array('PAY_timestamp' => 'desc'),
239
-                    )
240
-                );
241
-            }
242
-        } elseif ($payment_method instanceof EE_Payment) {
243
-            $obj_for_log = $payment_method;
244
-        }
245
-        $log = EEM_Change_Log::instance()->log(
246
-            EEM_Change_Log::type_gateway,
247
-            array('IPN data received' => $_req_data),
248
-            $obj_for_log
249
-        );
250
-        try {
251
-            /**
252
-             * @var EE_Payment $payment
253
-             */
254
-            $payment = null;
255
-            if ($transaction && $payment_method) {
256
-                /** @type EE_Transaction $transaction */
257
-                $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
258
-                /** @type EE_Payment_Method $payment_method */
259
-                $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
260
-                if ($payment_method->type_obj() instanceof EE_PMT_Base) {
261
-                    try {
262
-                        $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
263
-                        $log->set_object($payment);
264
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
265
-                        EEM_Change_Log::instance()->log(
266
-                            EEM_Change_Log::type_gateway,
267
-                            array(
268
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
269
-                                'current_url' => EEH_URL::current_url(),
270
-                                'payment'     => $e->getPaymentProperties(),
271
-                                'IPN_data'    => $e->getIpnData(),
272
-                            ),
273
-                            $obj_for_log
274
-                        );
275
-                        return $e->getPayment();
276
-                    }
277
-                } else {
278
-                    // not a payment
279
-                    EE_Error::add_error(
280
-                        sprintf(
281
-                            __(
282
-                                'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.',
283
-                                'event_espresso'
284
-                            ),
285
-                            '<br/>',
286
-                            EE_Registry::instance()->CFG->organization->get_pretty('email')
287
-                        ),
288
-                        __FILE__,
289
-                        __FUNCTION__,
290
-                        __LINE__
291
-                    );
292
-                }
293
-            } else {
294
-                // that's actually pretty ok. The IPN just wasn't able
295
-                // to identify which transaction or payment method this was for
296
-                // give all active payment methods a chance to claim it
297
-                $active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
298
-                foreach ($active_payment_methods as $active_payment_method) {
299
-                    try {
300
-                        $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
301
-                        $payment_method = $active_payment_method;
302
-                        EEM_Change_Log::instance()->log(
303
-                            EEM_Change_Log::type_gateway,
304
-                            array('IPN data' => $_req_data),
305
-                            $payment
306
-                        );
307
-                        break;
308
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
309
-                        EEM_Change_Log::instance()->log(
310
-                            EEM_Change_Log::type_gateway,
311
-                            array(
312
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
313
-                                'current_url' => EEH_URL::current_url(),
314
-                                'payment'     => $e->getPaymentProperties(),
315
-                                'IPN_data'    => $e->getIpnData(),
316
-                            ),
317
-                            $obj_for_log
318
-                        );
319
-                        return $e->getPayment();
320
-                    } catch (EE_Error $e) {
321
-                        // that's fine- it apparently couldn't handle the IPN
322
-                    }
323
-                }
324
-            }
325
-            // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
326
-            if ($payment instanceof EE_Payment) {
327
-                $payment->save();
328
-                //  update the TXN
329
-                $this->update_txn_based_on_payment(
330
-                    $transaction,
331
-                    $payment,
332
-                    $update_txn,
333
-                    $separate_IPN_request
334
-                );
335
-            } else {
336
-                // we couldn't find the payment for this IPN... let's try and log at least SOMETHING
337
-                if ($payment_method) {
338
-                    EEM_Change_Log::instance()->log(
339
-                        EEM_Change_Log::type_gateway,
340
-                        array('IPN data' => $_req_data),
341
-                        $payment_method
342
-                    );
343
-                } elseif ($transaction) {
344
-                    EEM_Change_Log::instance()->log(
345
-                        EEM_Change_Log::type_gateway,
346
-                        array('IPN data' => $_req_data),
347
-                        $transaction
348
-                    );
349
-                }
350
-            }
351
-            return $payment;
352
-        } catch (EE_Error $e) {
353
-            do_action(
354
-                'AHEE__log',
355
-                __FILE__,
356
-                __FUNCTION__,
357
-                sprintf(
358
-                    __(
359
-                        'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"',
360
-                        'event_espresso'
361
-                    ),
362
-                    print_r($transaction, true),
363
-                    print_r($_req_data, true),
364
-                    $e->getMessage()
365
-                )
366
-            );
367
-            throw $e;
368
-        }
369
-    }
370
-
371
-
372
-    /**
373
-     * Removes any non-printable illegal characters from the input,
374
-     * which might cause a raucous when trying to insert into the database
375
-     *
376
-     * @param  array $request_data
377
-     * @return array
378
-     */
379
-    protected function _remove_unusable_characters_from_array(array $request_data)
380
-    {
381
-        $return_data = array();
382
-        foreach ($request_data as $key => $value) {
383
-            $return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters(
384
-                $value
385
-            );
386
-        }
387
-        return $return_data;
388
-    }
389
-
390
-
391
-    /**
392
-     * Removes any non-printable illegal characters from the input,
393
-     * which might cause a raucous when trying to insert into the database
394
-     *
395
-     * @param string $request_data
396
-     * @return string
397
-     */
398
-    protected function _remove_unusable_characters($request_data)
399
-    {
400
-        return preg_replace('/[^[:print:]]/', '', $request_data);
401
-    }
402
-
403
-
404
-    /**
405
-     * Should be called just before displaying the payment attempt results to the user,
406
-     * when the payment attempt has finished. Some payment methods may have special
407
-     * logic to perform here. For example, if process_payment() happens on a special request
408
-     * and then the user is redirected to a page that displays the payment's status, this
409
-     * should be called while loading the page that displays the payment's status. If the user is
410
-     * sent to an offsite payment provider, this should be called upon returning from that offsite payment
411
-     * provider.
412
-     *
413
-     * @param EE_Transaction|int $transaction
414
-     * @param bool               $update_txn whether or not to call
415
-     *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
416
-     * @return EE_Payment
417
-     * @throws EE_Error
418
-     * @throws InvalidArgumentException
419
-     * @throws ReflectionException
420
-     * @throws RuntimeException
421
-     * @throws InvalidDataTypeException
422
-     * @throws InvalidInterfaceException
423
-     * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
424
-     *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
425
-     */
426
-    public function finalize_payment_for($transaction, $update_txn = true)
427
-    {
428
-        /** @var $transaction EE_Transaction */
429
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
430
-        $last_payment_method = $transaction->payment_method();
431
-        if ($last_payment_method instanceof EE_Payment_Method) {
432
-            $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
433
-            $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
434
-            return $payment;
435
-        }
436
-        return null;
437
-    }
438
-
439
-
440
-    /**
441
-     * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
442
-     *
443
-     * @param EE_Payment_Method $payment_method
444
-     * @param EE_Payment        $payment_to_refund
445
-     * @param array             $refund_info
446
-     * @return EE_Payment
447
-     * @throws EE_Error
448
-     * @throws InvalidArgumentException
449
-     * @throws ReflectionException
450
-     * @throws RuntimeException
451
-     * @throws InvalidDataTypeException
452
-     * @throws InvalidInterfaceException
453
-     */
454
-    public function process_refund(
455
-        EE_Payment_Method $payment_method,
456
-        EE_Payment $payment_to_refund,
457
-        array $refund_info = array()
458
-    ) {
459
-        if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
460
-            $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
461
-            $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
462
-        }
463
-        return $payment_to_refund;
464
-    }
465
-
466
-
467
-    /**
468
-     * This should be called each time there may have been an update to a
469
-     * payment on a transaction (ie, we asked for a payment to process a
470
-     * payment for a transaction, or we told a payment method about an IPN, or
471
-     * we told a payment method to
472
-     * "finalize_payment_for" (a transaction), or we told a payment method to
473
-     * process a refund. This should handle firing the correct hooks to
474
-     * indicate
475
-     * what exactly happened and updating the transaction appropriately). This
476
-     * could be integrated directly into EE_Transaction upon save, but we want
477
-     * this logic to be separate from 'normal' plain-jane saving and updating
478
-     * of transactions and payments, and to be tied to payment processing.
479
-     * Note: this method DOES NOT save the payment passed into it. It is the responsibility
480
-     * of previous code to decide whether or not to save (because the payment passed into
481
-     * this method might be a temporary, never-to-be-saved payment from an offline gateway,
482
-     * in which case we only want that payment object for some temporary usage during this request,
483
-     * but we don't want it to be saved).
484
-     *
485
-     * @param EE_Transaction|int $transaction
486
-     * @param EE_Payment         $payment
487
-     * @param boolean            $update_txn
488
-     *                        whether or not to call
489
-     *                        EE_Transaction_Processor::
490
-     *                        update_transaction_and_registrations_after_checkout_or_payment()
491
-     *                        (you can save 1 DB query if you know you're going
492
-     *                        to save it later instead)
493
-     * @param bool               $IPN
494
-     *                        if processing IPNs or other similar payment
495
-     *                        related activities that occur in alternate
496
-     *                        requests than the main one that is processing the
497
-     *                        TXN, then set this to true to check whether the
498
-     *                        TXN is locked before updating
499
-     * @throws EE_Error
500
-     * @throws InvalidArgumentException
501
-     * @throws ReflectionException
502
-     * @throws RuntimeException
503
-     * @throws InvalidDataTypeException
504
-     * @throws InvalidInterfaceException
505
-     */
506
-    public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
507
-    {
508
-        $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
509
-        /** @type EE_Transaction $transaction */
510
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
511
-        // can we freely update the TXN at this moment?
512
-        if ($IPN && $transaction->is_locked()) {
513
-            // don't update the transaction at this exact moment
514
-            // because the TXN is active in another request
515
-            EE_Cron_Tasks::schedule_update_transaction_with_payment(
516
-                time(),
517
-                $transaction->ID(),
518
-                $payment->ID()
519
-            );
520
-        } else {
521
-            // verify payment and that it has been saved
522
-            if ($payment instanceof EE_Payment && $payment->ID()) {
523
-                if ($payment->payment_method() instanceof EE_Payment_Method
524
-                    && $payment->payment_method()->type_obj() instanceof EE_PMT_Base
525
-                ) {
526
-                    $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
527
-                    // update TXN registrations with payment info
528
-                    $this->process_registration_payments($transaction, $payment);
529
-                }
530
-                $do_action = $payment->just_approved()
531
-                    ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
532
-                    : $do_action;
533
-            } else {
534
-                // send out notifications
535
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
536
-                $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
537
-            }
538
-            if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
539
-                /** @type EE_Transaction_Payments $transaction_payments */
540
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
541
-                // set new value for total paid
542
-                $transaction_payments->calculate_total_payments_and_update_status($transaction);
543
-                // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
544
-                if ($update_txn) {
545
-                    $this->_post_payment_processing($transaction, $payment, $IPN);
546
-                }
547
-            }
548
-            // granular hook for others to use.
549
-            do_action($do_action, $transaction, $payment);
550
-            do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
551
-            // global hook for others to use.
552
-            do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
553
-        }
554
-    }
555
-
556
-
557
-    /**
558
-     * update registrations REG_paid field after successful payment and link registrations with payment
559
-     *
560
-     * @param EE_Transaction    $transaction
561
-     * @param EE_Payment        $payment
562
-     * @param EE_Registration[] $registrations
563
-     * @throws EE_Error
564
-     * @throws InvalidArgumentException
565
-     * @throws RuntimeException
566
-     * @throws InvalidDataTypeException
567
-     * @throws InvalidInterfaceException
568
-     */
569
-    public function process_registration_payments(
570
-        EE_Transaction $transaction,
571
-        EE_Payment $payment,
572
-        array $registrations = array()
573
-    ) {
574
-        // only process if payment was successful
575
-        if ($payment->status() !== EEM_Payment::status_id_approved) {
576
-            return;
577
-        }
578
-        // EEM_Registration::instance()->show_next_x_db_queries();
579
-        if (empty($registrations)) {
580
-            // find registrations with monies owing that can receive a payment
581
-            $registrations = $transaction->registrations(
582
-                array(
583
-                    array(
584
-                        // only these reg statuses can receive payments
585
-                        'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
586
-                        'REG_final_price'  => array('!=', 0),
587
-                        'REG_final_price*' => array('!=', 'REG_paid', true),
588
-                    ),
589
-                )
590
-            );
591
-        }
592
-        // still nothing ??!??
593
-        if (empty($registrations)) {
594
-            return;
595
-        }
596
-        // todo: break out the following logic into a separate strategy class
597
-        // todo: named something like "Sequential_Reg_Payment_Strategy"
598
-        // todo: which would apply payments using the capitalist "first come first paid" approach
599
-        // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
600
-        // todo: which would be the socialist "everybody gets a piece of pie" approach,
601
-        // todo: which would be better for deposits, where you want a bit of the payment applied to each registration
602
-        $refund = $payment->is_a_refund();
603
-        // how much is available to apply to registrations?
604
-        $available_payment_amount = abs($payment->amount());
605
-        foreach ($registrations as $registration) {
606
-            if ($registration instanceof EE_Registration) {
607
-                // nothing left?
608
-                if ($available_payment_amount <= 0) {
609
-                    break;
610
-                }
611
-                if ($refund) {
612
-                    $available_payment_amount = $this->process_registration_refund(
613
-                        $registration,
614
-                        $payment,
615
-                        $available_payment_amount
616
-                    );
617
-                } else {
618
-                    $available_payment_amount = $this->process_registration_payment(
619
-                        $registration,
620
-                        $payment,
621
-                        $available_payment_amount
622
-                    );
623
-                }
624
-            }
625
-        }
626
-        if ($available_payment_amount > 0
627
-            && apply_filters(
628
-                'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications',
629
-                false
630
-            )) {
631
-            EE_Error::add_attention(
632
-                sprintf(
633
-                    __(
634
-                        'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).',
635
-                        'event_espresso'
636
-                    ),
637
-                    EEH_Template::format_currency($available_payment_amount),
638
-                    implode(', ', array_keys($registrations)),
639
-                    '<br/>',
640
-                    EEH_Template::format_currency($payment->amount())
641
-                ),
642
-                __FILE__,
643
-                __FUNCTION__,
644
-                __LINE__
645
-            );
646
-        }
647
-    }
648
-
649
-
650
-    /**
651
-     * update registration REG_paid field after successful payment and link registration with payment
652
-     *
653
-     * @param EE_Registration $registration
654
-     * @param EE_Payment      $payment
655
-     * @param float           $available_payment_amount
656
-     * @return float
657
-     * @throws EE_Error
658
-     * @throws InvalidArgumentException
659
-     * @throws RuntimeException
660
-     * @throws InvalidDataTypeException
661
-     * @throws InvalidInterfaceException
662
-     */
663
-    public function process_registration_payment(
664
-        EE_Registration $registration,
665
-        EE_Payment $payment,
666
-        $available_payment_amount = 0.00
667
-    ) {
668
-        $owing = $registration->final_price() - $registration->paid();
669
-        if ($owing > 0) {
670
-            // don't allow payment amount to exceed the available payment amount, OR the amount owing
671
-            $payment_amount = min($available_payment_amount, $owing);
672
-            // update $available_payment_amount
673
-            $available_payment_amount -= $payment_amount;
674
-            // calculate and set new REG_paid
675
-            $registration->set_paid($registration->paid() + $payment_amount);
676
-            // now save it
677
-            $this->_apply_registration_payment($registration, $payment, $payment_amount);
678
-        }
679
-        return $available_payment_amount;
680
-    }
681
-
682
-
683
-    /**
684
-     * update registration REG_paid field after successful payment and link registration with payment
685
-     *
686
-     * @param EE_Registration $registration
687
-     * @param EE_Payment      $payment
688
-     * @param float           $payment_amount
689
-     * @return void
690
-     * @throws EE_Error
691
-     * @throws InvalidArgumentException
692
-     * @throws InvalidDataTypeException
693
-     * @throws InvalidInterfaceException
694
-     */
695
-    protected function _apply_registration_payment(
696
-        EE_Registration $registration,
697
-        EE_Payment $payment,
698
-        $payment_amount = 0.00
699
-    ) {
700
-        // find any existing reg payment records for this registration and payment
701
-        $existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
702
-            array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
703
-        );
704
-        // if existing registration payment exists
705
-        if ($existing_reg_payment instanceof EE_Registration_Payment) {
706
-            // then update that record
707
-            $existing_reg_payment->set_amount($payment_amount);
708
-            $existing_reg_payment->save();
709
-        } else {
710
-            // or add new relation between registration and payment and set amount
711
-            $registration->_add_relation_to(
712
-                $payment,
713
-                'Payment',
714
-                array('RPY_amount' => $payment_amount)
715
-            );
716
-            // make it stick
717
-            $registration->save();
718
-        }
719
-    }
720
-
721
-
722
-    /**
723
-     * update registration REG_paid field after refund and link registration with payment
724
-     *
725
-     * @param EE_Registration $registration
726
-     * @param EE_Payment      $payment
727
-     * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
728
-     * @return float
729
-     * @throws EE_Error
730
-     * @throws InvalidArgumentException
731
-     * @throws RuntimeException
732
-     * @throws InvalidDataTypeException
733
-     * @throws InvalidInterfaceException
734
-     */
735
-    public function process_registration_refund(
736
-        EE_Registration $registration,
737
-        EE_Payment $payment,
738
-        $available_refund_amount = 0.00
739
-    ) {
740
-        // EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
741
-        if ($registration->paid() > 0) {
742
-            // ensure $available_refund_amount is NOT negative
743
-            $available_refund_amount = (float) abs($available_refund_amount);
744
-            // don't allow refund amount to exceed the available payment amount, OR the amount paid
745
-            $refund_amount = min($available_refund_amount, (float) $registration->paid());
746
-            // update $available_payment_amount
747
-            $available_refund_amount -= $refund_amount;
748
-            // calculate and set new REG_paid
749
-            $registration->set_paid($registration->paid() - $refund_amount);
750
-            // convert payment amount back to a negative value for storage in the db
751
-            $refund_amount = (float) abs($refund_amount) * -1;
752
-            // now save it
753
-            $this->_apply_registration_payment($registration, $payment, $refund_amount);
754
-        }
755
-        return $available_refund_amount;
756
-    }
757
-
758
-
759
-    /**
760
-     * Process payments and transaction after payment process completed.
761
-     * ultimately this will send the TXN and payment details off so that notifications can be sent out.
762
-     * if this request happens to be processing an IPN,
763
-     * then we will also set the Payment Options Reg Step to completed,
764
-     * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
765
-     *
766
-     * @param EE_Transaction $transaction
767
-     * @param EE_Payment     $payment
768
-     * @param bool           $IPN
769
-     * @throws EE_Error
770
-     * @throws InvalidArgumentException
771
-     * @throws ReflectionException
772
-     * @throws RuntimeException
773
-     * @throws InvalidDataTypeException
774
-     * @throws InvalidInterfaceException
775
-     */
776
-    protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
777
-    {
778
-        /** @type EE_Transaction_Processor $transaction_processor */
779
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
780
-        // is the Payment Options Reg Step completed ?
781
-        $payment_options_step_completed = $transaction->reg_step_completed('payment_options');
782
-        // if the Payment Options Reg Step is completed...
783
-        $revisit = $payment_options_step_completed === true;
784
-        // then this is kinda sorta a revisit with regards to payments at least
785
-        $transaction_processor->set_revisit($revisit);
786
-        // if this is an IPN, let's consider the Payment Options Reg Step completed if not already
787
-        if ($IPN
788
-            && $payment_options_step_completed !== true
789
-            && ($payment->is_approved() || $payment->is_pending())
790
-        ) {
791
-            $payment_options_step_completed = $transaction->set_reg_step_completed(
792
-                'payment_options'
793
-            );
794
-        }
795
-        // maybe update status, but don't save transaction just yet
796
-        $transaction->update_status_based_on_total_paid(false);
797
-        // check if 'finalize_registration' step has been completed...
798
-        $finalized = $transaction->reg_step_completed('finalize_registration');
799
-        //  if this is an IPN and the final step has not been initiated
800
-        if ($IPN && $payment_options_step_completed && $finalized === false) {
801
-            // and if it hasn't already been set as being started...
802
-            $finalized = $transaction->set_reg_step_initiated('finalize_registration');
803
-        }
804
-        $transaction->save();
805
-        // because the above will return false if the final step was not fully completed, we need to check again...
806
-        if ($IPN && $finalized !== false) {
807
-            // and if we are all good to go, then send out notifications
808
-            add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
809
-            // ok, now process the transaction according to the payment
810
-            $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
811
-                $transaction,
812
-                $payment
813
-            );
814
-        }
815
-        // DEBUG LOG
816
-        $payment_method = $payment->payment_method();
817
-        if ($payment_method instanceof EE_Payment_Method) {
818
-            $payment_method_type_obj = $payment_method->type_obj();
819
-            if ($payment_method_type_obj instanceof EE_PMT_Base) {
820
-                $gateway = $payment_method_type_obj->get_gateway();
821
-                if ($gateway instanceof EE_Gateway) {
822
-                    $gateway->log(
823
-                        array(
824
-                            'message'               => __('Post Payment Transaction Details', 'event_espresso'),
825
-                            'transaction'           => $transaction->model_field_array(),
826
-                            'finalized'             => $finalized,
827
-                            'IPN'                   => $IPN,
828
-                            'deliver_notifications' => has_filter(
829
-                                'FHEE__EED_Messages___maybe_registration__deliver_notifications'
830
-                            ),
831
-                        ),
832
-                        $payment
833
-                    );
834
-                }
835
-            }
836
-        }
837
-    }
838
-
839
-
840
-    /**
841
-     * Force posts to PayPal to use TLS v1.2. See:
842
-     * https://core.trac.wordpress.org/ticket/36320
843
-     * https://core.trac.wordpress.org/ticket/34924#comment:15
844
-     * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
845
-     * This will affect PayPal standard, pro, express, and Payflow.
846
-     *
847
-     * @param $handle
848
-     * @param $r
849
-     * @param $url
850
-     */
851
-    public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
852
-    {
853
-        if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) {
854
-            // Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
855
-            // instead of the constant because it might not be defined
856
-            curl_setopt($handle, CURLOPT_SSLVERSION, 6);
857
-        }
858
-    }
21
+	/**
22
+	 * @var EE_Payment_Processor $_instance
23
+	 * @access    private
24
+	 */
25
+	private static $_instance;
26
+
27
+
28
+	/**
29
+	 * @singleton method used to instantiate class object
30
+	 * @access    public
31
+	 * @return EE_Payment_Processor instance
32
+	 */
33
+	public static function instance()
34
+	{
35
+		// check if class object is instantiated
36
+		if (! self::$_instance instanceof EE_Payment_Processor) {
37
+			self::$_instance = new self();
38
+		}
39
+		return self::$_instance;
40
+	}
41
+
42
+
43
+	/**
44
+	 * @return EE_Payment_Processor
45
+	 */
46
+	public static function reset()
47
+	{
48
+		self::$_instance = null;
49
+		return self::instance();
50
+	}
51
+
52
+
53
+	/**
54
+	 *private constructor to prevent direct creation
55
+	 *
56
+	 * @Constructor
57
+	 * @access private
58
+	 */
59
+	private function __construct()
60
+	{
61
+		do_action('AHEE__EE_Payment_Processor__construct');
62
+		add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
63
+	}
64
+
65
+
66
+	/**
67
+	 * Using the selected gateway, processes the payment for that transaction, and updates the transaction
68
+	 * appropriately. Saves the payment that is generated
69
+	 *
70
+	 * @param EE_Payment_Method    $payment_method
71
+	 * @param EE_Transaction       $transaction
72
+	 * @param float                $amount       if only part of the transaction is to be paid for, how much.
73
+	 *                                           Leave null if payment is for the full amount owing
74
+	 * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
75
+	 *                                           Receive_form_submission() should have
76
+	 *                                           already been called on the billing form
77
+	 *                                           (ie, its inputs should have their normalized values set).
78
+	 * @param string               $return_url   string used mostly by offsite gateways to specify
79
+	 *                                           where to go AFTER the offsite gateway
80
+	 * @param string               $method       like 'CART', indicates who the client who called this was
81
+	 * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
82
+	 * @param boolean              $update_txn   whether or not to call
83
+	 *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
84
+	 * @param string               $cancel_url   URL to return to if off-site payments are cancelled
85
+	 * @return EE_Payment
86
+	 * @throws EE_Error
87
+	 * @throws InvalidArgumentException
88
+	 * @throws ReflectionException
89
+	 * @throws RuntimeException
90
+	 * @throws InvalidDataTypeException
91
+	 * @throws InvalidInterfaceException
92
+	 */
93
+	public function process_payment(
94
+		EE_Payment_Method $payment_method,
95
+		EE_Transaction $transaction,
96
+		$amount = null,
97
+		$billing_form = null,
98
+		$return_url = null,
99
+		$method = 'CART',
100
+		$by_admin = false,
101
+		$update_txn = true,
102
+		$cancel_url = ''
103
+	) {
104
+		if ((float) $amount < 0) {
105
+			throw new EE_Error(
106
+				sprintf(
107
+					__(
108
+						'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
109
+						'event_espresso'
110
+					),
111
+					$amount,
112
+					$transaction->ID()
113
+				)
114
+			);
115
+		}
116
+		// verify payment method
117
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
118
+			$payment_method,
119
+			true
120
+		);
121
+		// verify transaction
122
+		EEM_Transaction::instance()->ensure_is_obj($transaction);
123
+		$transaction->set_payment_method_ID($payment_method->ID());
124
+		// verify payment method type
125
+		if ($payment_method->type_obj() instanceof EE_PMT_Base) {
126
+			$payment = $payment_method->type_obj()->process_payment(
127
+				$transaction,
128
+				min($amount, $transaction->remaining()), // make sure we don't overcharge
129
+				$billing_form,
130
+				$return_url,
131
+				add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
132
+				$method,
133
+				$by_admin
134
+			);
135
+			// check if payment method uses an off-site gateway
136
+			if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
137
+				// don't process payments for off-site gateways yet because no payment has occurred yet
138
+				$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
139
+			}
140
+			return $payment;
141
+		}
142
+		EE_Error::add_error(
143
+			sprintf(
144
+				__(
145
+					'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
146
+					'event_espresso'
147
+				),
148
+				'<br/>',
149
+				EE_Registry::instance()->CFG->organization->get_pretty('email')
150
+			),
151
+			__FILE__,
152
+			__FUNCTION__,
153
+			__LINE__
154
+		);
155
+		return null;
156
+	}
157
+
158
+
159
+	/**
160
+	 * @param EE_Transaction|int $transaction
161
+	 * @param EE_Payment_Method  $payment_method
162
+	 * @return string
163
+	 * @throws EE_Error
164
+	 * @throws InvalidArgumentException
165
+	 * @throws InvalidDataTypeException
166
+	 * @throws InvalidInterfaceException
167
+	 */
168
+	public function get_ipn_url_for_payment_method($transaction, $payment_method)
169
+	{
170
+		/** @type \EE_Transaction $transaction */
171
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
172
+		$primary_reg = $transaction->primary_registration();
173
+		if (! $primary_reg instanceof EE_Registration) {
174
+			throw new EE_Error(
175
+				sprintf(
176
+					__(
177
+						'Cannot get IPN URL for transaction with ID %d because it has no primary registration',
178
+						'event_espresso'
179
+					),
180
+					$transaction->ID()
181
+				)
182
+			);
183
+		}
184
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
185
+			$payment_method,
186
+			true
187
+		);
188
+		$url = add_query_arg(
189
+			array(
190
+				'e_reg_url_link'    => $primary_reg->reg_url_link(),
191
+				'ee_payment_method' => $payment_method->slug(),
192
+			),
193
+			EE_Registry::instance()->CFG->core->txn_page_url()
194
+		);
195
+		return $url;
196
+	}
197
+
198
+
199
+	/**
200
+	 * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
201
+	 * we can easily find what registration the IPN is for and what payment method.
202
+	 * However, if not, we'll give all payment methods a chance to claim it and process it.
203
+	 * If a payment is found for the IPN info, it is saved.
204
+	 *
205
+	 * @param array              $_req_data            eg $_REQUEST
206
+	 * @param EE_Transaction|int $transaction          optional (or a transactions id)
207
+	 * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
208
+	 * @param boolean            $update_txn           whether or not to call
209
+	 *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
210
+	 * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
211
+	 *                                                 or is processed manually ( false like Mijireh )
212
+	 * @throws EE_Error
213
+	 * @throws Exception
214
+	 * @return EE_Payment
215
+	 * @throws \RuntimeException
216
+	 * @throws \ReflectionException
217
+	 * @throws \InvalidArgumentException
218
+	 * @throws InvalidInterfaceException
219
+	 * @throws InvalidDataTypeException
220
+	 */
221
+	public function process_ipn(
222
+		$_req_data,
223
+		$transaction = null,
224
+		$payment_method = null,
225
+		$update_txn = true,
226
+		$separate_IPN_request = true
227
+	) {
228
+		EE_Registry::instance()->load_model('Change_Log');
229
+		$_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data);
230
+		EE_Processor_Base::set_IPN($separate_IPN_request);
231
+		$obj_for_log = null;
232
+		if ($transaction instanceof EE_Transaction) {
233
+			$obj_for_log = $transaction;
234
+			if ($payment_method instanceof EE_Payment_Method) {
235
+				$obj_for_log = EEM_Payment::instance()->get_one(
236
+					array(
237
+						array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
238
+						'order_by' => array('PAY_timestamp' => 'desc'),
239
+					)
240
+				);
241
+			}
242
+		} elseif ($payment_method instanceof EE_Payment) {
243
+			$obj_for_log = $payment_method;
244
+		}
245
+		$log = EEM_Change_Log::instance()->log(
246
+			EEM_Change_Log::type_gateway,
247
+			array('IPN data received' => $_req_data),
248
+			$obj_for_log
249
+		);
250
+		try {
251
+			/**
252
+			 * @var EE_Payment $payment
253
+			 */
254
+			$payment = null;
255
+			if ($transaction && $payment_method) {
256
+				/** @type EE_Transaction $transaction */
257
+				$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
258
+				/** @type EE_Payment_Method $payment_method */
259
+				$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
260
+				if ($payment_method->type_obj() instanceof EE_PMT_Base) {
261
+					try {
262
+						$payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
263
+						$log->set_object($payment);
264
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
265
+						EEM_Change_Log::instance()->log(
266
+							EEM_Change_Log::type_gateway,
267
+							array(
268
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
269
+								'current_url' => EEH_URL::current_url(),
270
+								'payment'     => $e->getPaymentProperties(),
271
+								'IPN_data'    => $e->getIpnData(),
272
+							),
273
+							$obj_for_log
274
+						);
275
+						return $e->getPayment();
276
+					}
277
+				} else {
278
+					// not a payment
279
+					EE_Error::add_error(
280
+						sprintf(
281
+							__(
282
+								'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.',
283
+								'event_espresso'
284
+							),
285
+							'<br/>',
286
+							EE_Registry::instance()->CFG->organization->get_pretty('email')
287
+						),
288
+						__FILE__,
289
+						__FUNCTION__,
290
+						__LINE__
291
+					);
292
+				}
293
+			} else {
294
+				// that's actually pretty ok. The IPN just wasn't able
295
+				// to identify which transaction or payment method this was for
296
+				// give all active payment methods a chance to claim it
297
+				$active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
298
+				foreach ($active_payment_methods as $active_payment_method) {
299
+					try {
300
+						$payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
301
+						$payment_method = $active_payment_method;
302
+						EEM_Change_Log::instance()->log(
303
+							EEM_Change_Log::type_gateway,
304
+							array('IPN data' => $_req_data),
305
+							$payment
306
+						);
307
+						break;
308
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
309
+						EEM_Change_Log::instance()->log(
310
+							EEM_Change_Log::type_gateway,
311
+							array(
312
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
313
+								'current_url' => EEH_URL::current_url(),
314
+								'payment'     => $e->getPaymentProperties(),
315
+								'IPN_data'    => $e->getIpnData(),
316
+							),
317
+							$obj_for_log
318
+						);
319
+						return $e->getPayment();
320
+					} catch (EE_Error $e) {
321
+						// that's fine- it apparently couldn't handle the IPN
322
+					}
323
+				}
324
+			}
325
+			// EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
326
+			if ($payment instanceof EE_Payment) {
327
+				$payment->save();
328
+				//  update the TXN
329
+				$this->update_txn_based_on_payment(
330
+					$transaction,
331
+					$payment,
332
+					$update_txn,
333
+					$separate_IPN_request
334
+				);
335
+			} else {
336
+				// we couldn't find the payment for this IPN... let's try and log at least SOMETHING
337
+				if ($payment_method) {
338
+					EEM_Change_Log::instance()->log(
339
+						EEM_Change_Log::type_gateway,
340
+						array('IPN data' => $_req_data),
341
+						$payment_method
342
+					);
343
+				} elseif ($transaction) {
344
+					EEM_Change_Log::instance()->log(
345
+						EEM_Change_Log::type_gateway,
346
+						array('IPN data' => $_req_data),
347
+						$transaction
348
+					);
349
+				}
350
+			}
351
+			return $payment;
352
+		} catch (EE_Error $e) {
353
+			do_action(
354
+				'AHEE__log',
355
+				__FILE__,
356
+				__FUNCTION__,
357
+				sprintf(
358
+					__(
359
+						'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"',
360
+						'event_espresso'
361
+					),
362
+					print_r($transaction, true),
363
+					print_r($_req_data, true),
364
+					$e->getMessage()
365
+				)
366
+			);
367
+			throw $e;
368
+		}
369
+	}
370
+
371
+
372
+	/**
373
+	 * Removes any non-printable illegal characters from the input,
374
+	 * which might cause a raucous when trying to insert into the database
375
+	 *
376
+	 * @param  array $request_data
377
+	 * @return array
378
+	 */
379
+	protected function _remove_unusable_characters_from_array(array $request_data)
380
+	{
381
+		$return_data = array();
382
+		foreach ($request_data as $key => $value) {
383
+			$return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters(
384
+				$value
385
+			);
386
+		}
387
+		return $return_data;
388
+	}
389
+
390
+
391
+	/**
392
+	 * Removes any non-printable illegal characters from the input,
393
+	 * which might cause a raucous when trying to insert into the database
394
+	 *
395
+	 * @param string $request_data
396
+	 * @return string
397
+	 */
398
+	protected function _remove_unusable_characters($request_data)
399
+	{
400
+		return preg_replace('/[^[:print:]]/', '', $request_data);
401
+	}
402
+
403
+
404
+	/**
405
+	 * Should be called just before displaying the payment attempt results to the user,
406
+	 * when the payment attempt has finished. Some payment methods may have special
407
+	 * logic to perform here. For example, if process_payment() happens on a special request
408
+	 * and then the user is redirected to a page that displays the payment's status, this
409
+	 * should be called while loading the page that displays the payment's status. If the user is
410
+	 * sent to an offsite payment provider, this should be called upon returning from that offsite payment
411
+	 * provider.
412
+	 *
413
+	 * @param EE_Transaction|int $transaction
414
+	 * @param bool               $update_txn whether or not to call
415
+	 *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
416
+	 * @return EE_Payment
417
+	 * @throws EE_Error
418
+	 * @throws InvalidArgumentException
419
+	 * @throws ReflectionException
420
+	 * @throws RuntimeException
421
+	 * @throws InvalidDataTypeException
422
+	 * @throws InvalidInterfaceException
423
+	 * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
424
+	 *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
425
+	 */
426
+	public function finalize_payment_for($transaction, $update_txn = true)
427
+	{
428
+		/** @var $transaction EE_Transaction */
429
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
430
+		$last_payment_method = $transaction->payment_method();
431
+		if ($last_payment_method instanceof EE_Payment_Method) {
432
+			$payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
433
+			$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
434
+			return $payment;
435
+		}
436
+		return null;
437
+	}
438
+
439
+
440
+	/**
441
+	 * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
442
+	 *
443
+	 * @param EE_Payment_Method $payment_method
444
+	 * @param EE_Payment        $payment_to_refund
445
+	 * @param array             $refund_info
446
+	 * @return EE_Payment
447
+	 * @throws EE_Error
448
+	 * @throws InvalidArgumentException
449
+	 * @throws ReflectionException
450
+	 * @throws RuntimeException
451
+	 * @throws InvalidDataTypeException
452
+	 * @throws InvalidInterfaceException
453
+	 */
454
+	public function process_refund(
455
+		EE_Payment_Method $payment_method,
456
+		EE_Payment $payment_to_refund,
457
+		array $refund_info = array()
458
+	) {
459
+		if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
460
+			$payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
461
+			$this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
462
+		}
463
+		return $payment_to_refund;
464
+	}
465
+
466
+
467
+	/**
468
+	 * This should be called each time there may have been an update to a
469
+	 * payment on a transaction (ie, we asked for a payment to process a
470
+	 * payment for a transaction, or we told a payment method about an IPN, or
471
+	 * we told a payment method to
472
+	 * "finalize_payment_for" (a transaction), or we told a payment method to
473
+	 * process a refund. This should handle firing the correct hooks to
474
+	 * indicate
475
+	 * what exactly happened and updating the transaction appropriately). This
476
+	 * could be integrated directly into EE_Transaction upon save, but we want
477
+	 * this logic to be separate from 'normal' plain-jane saving and updating
478
+	 * of transactions and payments, and to be tied to payment processing.
479
+	 * Note: this method DOES NOT save the payment passed into it. It is the responsibility
480
+	 * of previous code to decide whether or not to save (because the payment passed into
481
+	 * this method might be a temporary, never-to-be-saved payment from an offline gateway,
482
+	 * in which case we only want that payment object for some temporary usage during this request,
483
+	 * but we don't want it to be saved).
484
+	 *
485
+	 * @param EE_Transaction|int $transaction
486
+	 * @param EE_Payment         $payment
487
+	 * @param boolean            $update_txn
488
+	 *                        whether or not to call
489
+	 *                        EE_Transaction_Processor::
490
+	 *                        update_transaction_and_registrations_after_checkout_or_payment()
491
+	 *                        (you can save 1 DB query if you know you're going
492
+	 *                        to save it later instead)
493
+	 * @param bool               $IPN
494
+	 *                        if processing IPNs or other similar payment
495
+	 *                        related activities that occur in alternate
496
+	 *                        requests than the main one that is processing the
497
+	 *                        TXN, then set this to true to check whether the
498
+	 *                        TXN is locked before updating
499
+	 * @throws EE_Error
500
+	 * @throws InvalidArgumentException
501
+	 * @throws ReflectionException
502
+	 * @throws RuntimeException
503
+	 * @throws InvalidDataTypeException
504
+	 * @throws InvalidInterfaceException
505
+	 */
506
+	public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
507
+	{
508
+		$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
509
+		/** @type EE_Transaction $transaction */
510
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
511
+		// can we freely update the TXN at this moment?
512
+		if ($IPN && $transaction->is_locked()) {
513
+			// don't update the transaction at this exact moment
514
+			// because the TXN is active in another request
515
+			EE_Cron_Tasks::schedule_update_transaction_with_payment(
516
+				time(),
517
+				$transaction->ID(),
518
+				$payment->ID()
519
+			);
520
+		} else {
521
+			// verify payment and that it has been saved
522
+			if ($payment instanceof EE_Payment && $payment->ID()) {
523
+				if ($payment->payment_method() instanceof EE_Payment_Method
524
+					&& $payment->payment_method()->type_obj() instanceof EE_PMT_Base
525
+				) {
526
+					$payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
527
+					// update TXN registrations with payment info
528
+					$this->process_registration_payments($transaction, $payment);
529
+				}
530
+				$do_action = $payment->just_approved()
531
+					? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
532
+					: $do_action;
533
+			} else {
534
+				// send out notifications
535
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
536
+				$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
537
+			}
538
+			if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
539
+				/** @type EE_Transaction_Payments $transaction_payments */
540
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
541
+				// set new value for total paid
542
+				$transaction_payments->calculate_total_payments_and_update_status($transaction);
543
+				// call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
544
+				if ($update_txn) {
545
+					$this->_post_payment_processing($transaction, $payment, $IPN);
546
+				}
547
+			}
548
+			// granular hook for others to use.
549
+			do_action($do_action, $transaction, $payment);
550
+			do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
551
+			// global hook for others to use.
552
+			do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
553
+		}
554
+	}
555
+
556
+
557
+	/**
558
+	 * update registrations REG_paid field after successful payment and link registrations with payment
559
+	 *
560
+	 * @param EE_Transaction    $transaction
561
+	 * @param EE_Payment        $payment
562
+	 * @param EE_Registration[] $registrations
563
+	 * @throws EE_Error
564
+	 * @throws InvalidArgumentException
565
+	 * @throws RuntimeException
566
+	 * @throws InvalidDataTypeException
567
+	 * @throws InvalidInterfaceException
568
+	 */
569
+	public function process_registration_payments(
570
+		EE_Transaction $transaction,
571
+		EE_Payment $payment,
572
+		array $registrations = array()
573
+	) {
574
+		// only process if payment was successful
575
+		if ($payment->status() !== EEM_Payment::status_id_approved) {
576
+			return;
577
+		}
578
+		// EEM_Registration::instance()->show_next_x_db_queries();
579
+		if (empty($registrations)) {
580
+			// find registrations with monies owing that can receive a payment
581
+			$registrations = $transaction->registrations(
582
+				array(
583
+					array(
584
+						// only these reg statuses can receive payments
585
+						'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
586
+						'REG_final_price'  => array('!=', 0),
587
+						'REG_final_price*' => array('!=', 'REG_paid', true),
588
+					),
589
+				)
590
+			);
591
+		}
592
+		// still nothing ??!??
593
+		if (empty($registrations)) {
594
+			return;
595
+		}
596
+		// todo: break out the following logic into a separate strategy class
597
+		// todo: named something like "Sequential_Reg_Payment_Strategy"
598
+		// todo: which would apply payments using the capitalist "first come first paid" approach
599
+		// todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
600
+		// todo: which would be the socialist "everybody gets a piece of pie" approach,
601
+		// todo: which would be better for deposits, where you want a bit of the payment applied to each registration
602
+		$refund = $payment->is_a_refund();
603
+		// how much is available to apply to registrations?
604
+		$available_payment_amount = abs($payment->amount());
605
+		foreach ($registrations as $registration) {
606
+			if ($registration instanceof EE_Registration) {
607
+				// nothing left?
608
+				if ($available_payment_amount <= 0) {
609
+					break;
610
+				}
611
+				if ($refund) {
612
+					$available_payment_amount = $this->process_registration_refund(
613
+						$registration,
614
+						$payment,
615
+						$available_payment_amount
616
+					);
617
+				} else {
618
+					$available_payment_amount = $this->process_registration_payment(
619
+						$registration,
620
+						$payment,
621
+						$available_payment_amount
622
+					);
623
+				}
624
+			}
625
+		}
626
+		if ($available_payment_amount > 0
627
+			&& apply_filters(
628
+				'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications',
629
+				false
630
+			)) {
631
+			EE_Error::add_attention(
632
+				sprintf(
633
+					__(
634
+						'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).',
635
+						'event_espresso'
636
+					),
637
+					EEH_Template::format_currency($available_payment_amount),
638
+					implode(', ', array_keys($registrations)),
639
+					'<br/>',
640
+					EEH_Template::format_currency($payment->amount())
641
+				),
642
+				__FILE__,
643
+				__FUNCTION__,
644
+				__LINE__
645
+			);
646
+		}
647
+	}
648
+
649
+
650
+	/**
651
+	 * update registration REG_paid field after successful payment and link registration with payment
652
+	 *
653
+	 * @param EE_Registration $registration
654
+	 * @param EE_Payment      $payment
655
+	 * @param float           $available_payment_amount
656
+	 * @return float
657
+	 * @throws EE_Error
658
+	 * @throws InvalidArgumentException
659
+	 * @throws RuntimeException
660
+	 * @throws InvalidDataTypeException
661
+	 * @throws InvalidInterfaceException
662
+	 */
663
+	public function process_registration_payment(
664
+		EE_Registration $registration,
665
+		EE_Payment $payment,
666
+		$available_payment_amount = 0.00
667
+	) {
668
+		$owing = $registration->final_price() - $registration->paid();
669
+		if ($owing > 0) {
670
+			// don't allow payment amount to exceed the available payment amount, OR the amount owing
671
+			$payment_amount = min($available_payment_amount, $owing);
672
+			// update $available_payment_amount
673
+			$available_payment_amount -= $payment_amount;
674
+			// calculate and set new REG_paid
675
+			$registration->set_paid($registration->paid() + $payment_amount);
676
+			// now save it
677
+			$this->_apply_registration_payment($registration, $payment, $payment_amount);
678
+		}
679
+		return $available_payment_amount;
680
+	}
681
+
682
+
683
+	/**
684
+	 * update registration REG_paid field after successful payment and link registration with payment
685
+	 *
686
+	 * @param EE_Registration $registration
687
+	 * @param EE_Payment      $payment
688
+	 * @param float           $payment_amount
689
+	 * @return void
690
+	 * @throws EE_Error
691
+	 * @throws InvalidArgumentException
692
+	 * @throws InvalidDataTypeException
693
+	 * @throws InvalidInterfaceException
694
+	 */
695
+	protected function _apply_registration_payment(
696
+		EE_Registration $registration,
697
+		EE_Payment $payment,
698
+		$payment_amount = 0.00
699
+	) {
700
+		// find any existing reg payment records for this registration and payment
701
+		$existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
702
+			array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
703
+		);
704
+		// if existing registration payment exists
705
+		if ($existing_reg_payment instanceof EE_Registration_Payment) {
706
+			// then update that record
707
+			$existing_reg_payment->set_amount($payment_amount);
708
+			$existing_reg_payment->save();
709
+		} else {
710
+			// or add new relation between registration and payment and set amount
711
+			$registration->_add_relation_to(
712
+				$payment,
713
+				'Payment',
714
+				array('RPY_amount' => $payment_amount)
715
+			);
716
+			// make it stick
717
+			$registration->save();
718
+		}
719
+	}
720
+
721
+
722
+	/**
723
+	 * update registration REG_paid field after refund and link registration with payment
724
+	 *
725
+	 * @param EE_Registration $registration
726
+	 * @param EE_Payment      $payment
727
+	 * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
728
+	 * @return float
729
+	 * @throws EE_Error
730
+	 * @throws InvalidArgumentException
731
+	 * @throws RuntimeException
732
+	 * @throws InvalidDataTypeException
733
+	 * @throws InvalidInterfaceException
734
+	 */
735
+	public function process_registration_refund(
736
+		EE_Registration $registration,
737
+		EE_Payment $payment,
738
+		$available_refund_amount = 0.00
739
+	) {
740
+		// EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
741
+		if ($registration->paid() > 0) {
742
+			// ensure $available_refund_amount is NOT negative
743
+			$available_refund_amount = (float) abs($available_refund_amount);
744
+			// don't allow refund amount to exceed the available payment amount, OR the amount paid
745
+			$refund_amount = min($available_refund_amount, (float) $registration->paid());
746
+			// update $available_payment_amount
747
+			$available_refund_amount -= $refund_amount;
748
+			// calculate and set new REG_paid
749
+			$registration->set_paid($registration->paid() - $refund_amount);
750
+			// convert payment amount back to a negative value for storage in the db
751
+			$refund_amount = (float) abs($refund_amount) * -1;
752
+			// now save it
753
+			$this->_apply_registration_payment($registration, $payment, $refund_amount);
754
+		}
755
+		return $available_refund_amount;
756
+	}
757
+
758
+
759
+	/**
760
+	 * Process payments and transaction after payment process completed.
761
+	 * ultimately this will send the TXN and payment details off so that notifications can be sent out.
762
+	 * if this request happens to be processing an IPN,
763
+	 * then we will also set the Payment Options Reg Step to completed,
764
+	 * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
765
+	 *
766
+	 * @param EE_Transaction $transaction
767
+	 * @param EE_Payment     $payment
768
+	 * @param bool           $IPN
769
+	 * @throws EE_Error
770
+	 * @throws InvalidArgumentException
771
+	 * @throws ReflectionException
772
+	 * @throws RuntimeException
773
+	 * @throws InvalidDataTypeException
774
+	 * @throws InvalidInterfaceException
775
+	 */
776
+	protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
777
+	{
778
+		/** @type EE_Transaction_Processor $transaction_processor */
779
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
780
+		// is the Payment Options Reg Step completed ?
781
+		$payment_options_step_completed = $transaction->reg_step_completed('payment_options');
782
+		// if the Payment Options Reg Step is completed...
783
+		$revisit = $payment_options_step_completed === true;
784
+		// then this is kinda sorta a revisit with regards to payments at least
785
+		$transaction_processor->set_revisit($revisit);
786
+		// if this is an IPN, let's consider the Payment Options Reg Step completed if not already
787
+		if ($IPN
788
+			&& $payment_options_step_completed !== true
789
+			&& ($payment->is_approved() || $payment->is_pending())
790
+		) {
791
+			$payment_options_step_completed = $transaction->set_reg_step_completed(
792
+				'payment_options'
793
+			);
794
+		}
795
+		// maybe update status, but don't save transaction just yet
796
+		$transaction->update_status_based_on_total_paid(false);
797
+		// check if 'finalize_registration' step has been completed...
798
+		$finalized = $transaction->reg_step_completed('finalize_registration');
799
+		//  if this is an IPN and the final step has not been initiated
800
+		if ($IPN && $payment_options_step_completed && $finalized === false) {
801
+			// and if it hasn't already been set as being started...
802
+			$finalized = $transaction->set_reg_step_initiated('finalize_registration');
803
+		}
804
+		$transaction->save();
805
+		// because the above will return false if the final step was not fully completed, we need to check again...
806
+		if ($IPN && $finalized !== false) {
807
+			// and if we are all good to go, then send out notifications
808
+			add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
809
+			// ok, now process the transaction according to the payment
810
+			$transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
811
+				$transaction,
812
+				$payment
813
+			);
814
+		}
815
+		// DEBUG LOG
816
+		$payment_method = $payment->payment_method();
817
+		if ($payment_method instanceof EE_Payment_Method) {
818
+			$payment_method_type_obj = $payment_method->type_obj();
819
+			if ($payment_method_type_obj instanceof EE_PMT_Base) {
820
+				$gateway = $payment_method_type_obj->get_gateway();
821
+				if ($gateway instanceof EE_Gateway) {
822
+					$gateway->log(
823
+						array(
824
+							'message'               => __('Post Payment Transaction Details', 'event_espresso'),
825
+							'transaction'           => $transaction->model_field_array(),
826
+							'finalized'             => $finalized,
827
+							'IPN'                   => $IPN,
828
+							'deliver_notifications' => has_filter(
829
+								'FHEE__EED_Messages___maybe_registration__deliver_notifications'
830
+							),
831
+						),
832
+						$payment
833
+					);
834
+				}
835
+			}
836
+		}
837
+	}
838
+
839
+
840
+	/**
841
+	 * Force posts to PayPal to use TLS v1.2. See:
842
+	 * https://core.trac.wordpress.org/ticket/36320
843
+	 * https://core.trac.wordpress.org/ticket/34924#comment:15
844
+	 * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
845
+	 * This will affect PayPal standard, pro, express, and Payflow.
846
+	 *
847
+	 * @param $handle
848
+	 * @param $r
849
+	 * @param $url
850
+	 */
851
+	public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
852
+	{
853
+		if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) {
854
+			// Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
855
+			// instead of the constant because it might not be defined
856
+			curl_setopt($handle, CURLOPT_SSLVERSION, 6);
857
+		}
858
+	}
859 859
 }
Please login to merge, or discard this patch.
modules/event_single/EED_Event_Single.module.php 2 patches
Indentation   +467 added lines, -467 removed lines patch added patch discarded remove patch
@@ -14,472 +14,472 @@  discard block
 block discarded – undo
14 14
 class EED_Event_Single extends EED_Module
15 15
 {
16 16
 
17
-    const EVENT_DETAILS_PRIORITY = 100;
18
-    const EVENT_DATETIMES_PRIORITY = 110;
19
-    const EVENT_TICKETS_PRIORITY = 120;
20
-    const EVENT_VENUES_PRIORITY = 130;
21
-
22
-    /**
23
-     * @type bool $using_get_the_excerpt
24
-     */
25
-    protected static $using_get_the_excerpt = false;
26
-
27
-
28
-    /**
29
-     * @type EE_Template_Part_Manager $template_parts
30
-     */
31
-    protected $template_parts;
32
-
33
-
34
-    /**
35
-     * @return EED_Module|EED_Event_Single
36
-     */
37
-    public static function instance()
38
-    {
39
-        return parent::get_instance(__CLASS__);
40
-    }
41
-
42
-
43
-    /**
44
-     * set_hooks - for hooking into EE Core, other modules, etc
45
-     *
46
-     * @return void
47
-     * @throws InvalidArgumentException
48
-     * @throws InvalidDataTypeException
49
-     * @throws InvalidInterfaceException
50
-     */
51
-    public static function set_hooks()
52
-    {
53
-        add_filter('FHEE_run_EE_wp', '__return_true');
54
-        add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
55
-        /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */
56
-        $custom_post_type_definitions = LoaderFactory::getLoader()->getShared(
57
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
58
-        );
59
-        $custom_post_types = $custom_post_type_definitions->getDefinitions();
60
-        EE_Config::register_route(
61
-            $custom_post_types['espresso_events']['singular_slug'],
62
-            'Event_Single',
63
-            'run'
64
-        );
65
-    }
66
-
67
-    /**
68
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
69
-     *
70
-     * @return    void
71
-     */
72
-    public static function set_hooks_admin()
73
-    {
74
-        add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
75
-    }
76
-
77
-
78
-    /**
79
-     * set_definitions
80
-     *
81
-     * @static
82
-     * @return void
83
-     */
84
-    public static function set_definitions()
85
-    {
86
-        define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
87
-        define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates' . DS);
88
-    }
89
-
90
-
91
-    /**
92
-     * set_config
93
-     *
94
-     * @void
95
-     */
96
-    protected function set_config()
97
-    {
98
-        $this->set_config_section('template_settings');
99
-        $this->set_config_class('EE_Event_Single_Config');
100
-        $this->set_config_name('EED_Event_Single');
101
-    }
102
-
103
-
104
-    /**
105
-     * initialize_template_parts
106
-     *
107
-     * @param EE_Config_Base|EE_Event_Single_Config $config
108
-     * @return EE_Template_Part_Manager
109
-     */
110
-    public function initialize_template_parts(EE_Event_Single_Config $config = null)
111
-    {
112
-        /** @type EE_Event_Single_Config $config */
113
-        $config = $config instanceof EE_Event_Single_Config ? $config : $this->config();
114
-        EEH_Autoloader::instance()->register_template_part_autoloaders();
115
-        $template_parts = new EE_Template_Part_Manager();
116
-        $template_parts->add_template_part(
117
-            'tickets',
118
-            __('Ticket Selector', 'event_espresso'),
119
-            'content-espresso_events-tickets.php',
120
-            $config->display_order_tickets
121
-        );
122
-        $template_parts->add_template_part(
123
-            'datetimes',
124
-            __('Dates and Times', 'event_espresso'),
125
-            'content-espresso_events-datetimes.php',
126
-            $config->display_order_datetimes
127
-        );
128
-        $template_parts->add_template_part(
129
-            'event',
130
-            __('Event Description', 'event_espresso'),
131
-            'content-espresso_events-details.php',
132
-            $config->display_order_event
133
-        );
134
-        $template_parts->add_template_part(
135
-            'venue',
136
-            __('Venue Information', 'event_espresso'),
137
-            'content-espresso_events-venues.php',
138
-            $config->display_order_venue
139
-        );
140
-        do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts);
141
-        return $template_parts;
142
-    }
143
-
144
-
145
-    /**
146
-     * run - initial module setup
147
-     *
148
-     * @param WP $WP
149
-     * @return    void
150
-     */
151
-    public function run($WP)
152
-    {
153
-        // ensure valid EE_Events_Single_Config() object exists
154
-        $this->set_config();
155
-        // check what template is loaded
156
-        add_filter('template_include', array($this, 'template_include'), 999, 1);
157
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
158
-        // load css
159
-        add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
160
-    }
161
-
162
-
163
-    /**
164
-     * template_include
165
-     *
166
-     * @param    string $template
167
-     * @return    string
168
-     */
169
-    public function template_include($template)
170
-    {
171
-        global $post;
172
-        /** @type EE_Event_Single_Config $config */
173
-        $config = $this->config();
174
-        if ($config->display_status_banner_single) {
175
-            add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2);
176
-        }
177
-        // not a custom template?
178
-        if (! post_password_required($post)
179
-            && (
180
-                apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false)
181
-                || EE_Registry::instance()
182
-                              ->load_core('Front_Controller')
183
-                              ->get_selected_template() !== 'single-espresso_events.php'
184
-            )
185
-
186
-        ) {
187
-            EEH_Template::load_espresso_theme_functions();
188
-            // then add extra event data via hooks
189
-            add_action('loop_start', array('EED_Event_Single', 'loop_start'));
190
-            add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1);
191
-            add_filter(
192
-                'the_content',
193
-                array('EED_Event_Single', 'event_details'),
194
-                EED_Event_Single::EVENT_DETAILS_PRIORITY
195
-            );
196
-            add_action('loop_end', array('EED_Event_Single', 'loop_end'));
197
-            // don't display entry meta because the existing theme will take car of that
198
-            add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
199
-        }
200
-        return $template;
201
-    }
202
-
203
-
204
-    /**
205
-     * loop_start
206
-     *
207
-     * @param    array $wp_query_array an array containing the WP_Query object
208
-     * @return    void
209
-     */
210
-    public static function loop_start($wp_query_array)
211
-    {
212
-        global $post;
213
-        do_action('AHEE_event_details_before_post', $post, $wp_query_array);
214
-    }
215
-
216
-
217
-    /**
218
-     * the_title
219
-     *
220
-     * @param    string $title
221
-     * @param    int    $id
222
-     * @return    string
223
-     */
224
-    public static function the_title($title = '', $id = 0)
225
-    {
226
-        global $post;
227
-        return in_the_loop() && $post->ID === (int) $id
228
-            ? espresso_event_status_banner($post->ID) . $title
229
-            : $title;
230
-    }
231
-
232
-
233
-    /**
234
-     * get_the_excerpt
235
-     * kinda hacky, but if a theme is using get_the_excerpt(),
236
-     * then we need to remove our filters on the_content()
237
-     *
238
-     * @param        string $excerpt
239
-     * @return        string
240
-     */
241
-    public static function get_the_excerpt($excerpt = '')
242
-    {
243
-        EED_Event_Single::$using_get_the_excerpt = true;
244
-        add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1);
245
-        return $excerpt;
246
-    }
247
-
248
-
249
-    /**
250
-     * end_get_the_excerpt
251
-     *
252
-     * @param  string $text
253
-     * @return string
254
-     */
255
-    public static function end_get_the_excerpt($text = '')
256
-    {
257
-        EED_Event_Single::$using_get_the_excerpt = false;
258
-        return $text;
259
-    }
260
-
261
-
262
-    /**
263
-     * event_details
264
-     *
265
-     * @param    string $content
266
-     * @return    string
267
-     */
268
-    public static function event_details($content)
269
-    {
270
-        global $post;
271
-        static $current_post_ID = 0;
272
-        if ($current_post_ID !== $post->ID
273
-            && $post->post_type === 'espresso_events'
274
-            && ! EED_Event_Single::$using_get_the_excerpt
275
-            && ! post_password_required()
276
-        ) {
277
-            // Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
278
-            // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
279
-            // BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
280
-            // We want to allow those plugins to still do their thing and have access to our content, but depending on
281
-            // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
282
-            // so the following allows this filter to be applied multiple times, but only once for real
283
-            $current_post_ID = did_action('loop_start') ? $post->ID : 0;
284
-            if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) {
285
-                // we need to first remove this callback from being applied to the_content()
286
-                // (otherwise it will recurse and blow up the interweb)
287
-                remove_filter(
288
-                    'the_content',
289
-                    array('EED_Event_Single', 'event_details'),
290
-                    EED_Event_Single::EVENT_DETAILS_PRIORITY
291
-                );
292
-                EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts(
293
-                );
294
-                $content = EEH_Template::locate_template('content-espresso_events-details.php');
295
-                $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content);
296
-                add_filter(
297
-                    'the_content',
298
-                    array('EED_Event_Single', 'event_details'),
299
-                    EED_Event_Single::EVENT_DETAILS_PRIORITY
300
-                );
301
-            } else {
302
-                $content = EED_Event_Single::use_filterable_display_order();
303
-            }
304
-        }
305
-        return $content;
306
-    }
307
-
308
-
309
-    /**
310
-     * use_filterable_display_order
311
-     *
312
-     * @return string
313
-     */
314
-    protected static function use_filterable_display_order()
315
-    {
316
-        // since the 'content-espresso_events-details.php' template might be used directly from within a theme,
317
-        // it uses the_content() for displaying the $post->post_content
318
-        // so in order to load a template that uses the_content()
319
-        // from within a callback being used to filter the_content(),
320
-        // we need to first remove this callback from being applied to the_content()
321
-        // (otherwise it will recurse and blow up the interweb)
322
-        remove_filter(
323
-            'the_content',
324
-            array('EED_Event_Single', 'event_details'),
325
-            EED_Event_Single::EVENT_DETAILS_PRIORITY
326
-        );
327
-        // now add additional content
328
-        add_filter(
329
-            'the_content',
330
-            array('EED_Event_Single', 'event_datetimes'),
331
-            EED_Event_Single::EVENT_DATETIMES_PRIORITY,
332
-            1
333
-        );
334
-        add_filter(
335
-            'the_content',
336
-            array('EED_Event_Single', 'event_tickets'),
337
-            EED_Event_Single::EVENT_TICKETS_PRIORITY,
338
-            1
339
-        );
340
-        add_filter(
341
-            'the_content',
342
-            array('EED_Event_Single', 'event_venues'),
343
-            EED_Event_Single::EVENT_VENUES_PRIORITY,
344
-            1
345
-        );
346
-        do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters');
347
-        // now load our template
348
-        $content = EEH_Template::locate_template('content-espresso_events-details.php');
349
-        // now add our filter back in, plus some others
350
-        add_filter(
351
-            'the_content',
352
-            array('EED_Event_Single', 'event_details'),
353
-            EED_Event_Single::EVENT_DETAILS_PRIORITY
354
-        );
355
-        remove_filter(
356
-            'the_content',
357
-            array('EED_Event_Single', 'event_datetimes'),
358
-            EED_Event_Single::EVENT_DATETIMES_PRIORITY
359
-        );
360
-        remove_filter(
361
-            'the_content',
362
-            array('EED_Event_Single', 'event_tickets'),
363
-            EED_Event_Single::EVENT_TICKETS_PRIORITY
364
-        );
365
-        remove_filter(
366
-            'the_content',
367
-            array('EED_Event_Single', 'event_venues'),
368
-            EED_Event_Single::EVENT_VENUES_PRIORITY
369
-        );
370
-        do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters');
371
-        // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
372
-        return $content;
373
-    }
374
-
375
-
376
-    /**
377
-     * event_datetimes - adds datetimes ABOVE content
378
-     *
379
-     * @param        string $content
380
-     * @return        string
381
-     */
382
-    public static function event_datetimes($content)
383
-    {
384
-        return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
385
-    }
386
-
387
-
388
-    /**
389
-     * event_tickets - adds tickets ABOVE content (which includes datetimes)
390
-     *
391
-     * @param        string $content
392
-     * @return        string
393
-     */
394
-    public static function event_tickets($content)
395
-    {
396
-        return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
397
-    }
398
-
399
-
400
-    /**
401
-     * event_venues
402
-     *
403
-     * @param    string $content
404
-     * @return    string
405
-     */
406
-    public static function event_venue($content)
407
-    {
408
-        return EED_Event_Single::event_venues($content);
409
-    }
410
-
411
-
412
-    /**
413
-     * event_venues - adds venues BELOW content
414
-     *
415
-     * @param        string $content
416
-     * @return        string
417
-     */
418
-    public static function event_venues($content)
419
-    {
420
-        return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
421
-    }
422
-
423
-
424
-    /**
425
-     * loop_end
426
-     *
427
-     * @param        array $wp_query_array an array containing the WP_Query object
428
-     * @return        void
429
-     */
430
-    public static function loop_end($wp_query_array)
431
-    {
432
-        global $post;
433
-        do_action('AHEE_event_details_after_post', $post, $wp_query_array);
434
-    }
435
-
436
-
437
-    /**
438
-     * wp_enqueue_scripts
439
-     *
440
-     * @return    void
441
-     */
442
-    public function wp_enqueue_scripts()
443
-    {
444
-        // get some style
445
-        if (apply_filters('FHEE_enable_default_espresso_css', true)
446
-            && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true)
447
-        ) {
448
-            // first check uploads folder
449
-            if (is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) {
450
-                wp_register_style(
451
-                    $this->theme,
452
-                    get_stylesheet_directory_uri() . $this->theme . DS . 'style.css',
453
-                    array('dashicons', 'espresso_default')
454
-                );
455
-            } else {
456
-                wp_register_style(
457
-                    $this->theme,
458
-                    EE_TEMPLATES_URL . $this->theme . DS . 'style.css',
459
-                    array('dashicons', 'espresso_default')
460
-                );
461
-            }
462
-            wp_enqueue_script($this->theme);
463
-            if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
464
-                add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
465
-            }
466
-        }
467
-    }
468
-
469
-
470
-    /**
471
-     * display_venue
472
-     *
473
-     * @return    bool
474
-     */
475
-    public static function display_venue()
476
-    {
477
-        /** @type EE_Event_Single_Config $config */
478
-        $config = EED_Event_Single::instance()->config();
479
-        $display_venue = $config->display_venue === null ? true : $config->display_venue;
480
-        $venue_name = EEH_Venue_View::venue_name();
481
-        return $display_venue && ! empty($venue_name);
482
-    }
17
+	const EVENT_DETAILS_PRIORITY = 100;
18
+	const EVENT_DATETIMES_PRIORITY = 110;
19
+	const EVENT_TICKETS_PRIORITY = 120;
20
+	const EVENT_VENUES_PRIORITY = 130;
21
+
22
+	/**
23
+	 * @type bool $using_get_the_excerpt
24
+	 */
25
+	protected static $using_get_the_excerpt = false;
26
+
27
+
28
+	/**
29
+	 * @type EE_Template_Part_Manager $template_parts
30
+	 */
31
+	protected $template_parts;
32
+
33
+
34
+	/**
35
+	 * @return EED_Module|EED_Event_Single
36
+	 */
37
+	public static function instance()
38
+	{
39
+		return parent::get_instance(__CLASS__);
40
+	}
41
+
42
+
43
+	/**
44
+	 * set_hooks - for hooking into EE Core, other modules, etc
45
+	 *
46
+	 * @return void
47
+	 * @throws InvalidArgumentException
48
+	 * @throws InvalidDataTypeException
49
+	 * @throws InvalidInterfaceException
50
+	 */
51
+	public static function set_hooks()
52
+	{
53
+		add_filter('FHEE_run_EE_wp', '__return_true');
54
+		add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
55
+		/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */
56
+		$custom_post_type_definitions = LoaderFactory::getLoader()->getShared(
57
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
58
+		);
59
+		$custom_post_types = $custom_post_type_definitions->getDefinitions();
60
+		EE_Config::register_route(
61
+			$custom_post_types['espresso_events']['singular_slug'],
62
+			'Event_Single',
63
+			'run'
64
+		);
65
+	}
66
+
67
+	/**
68
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
69
+	 *
70
+	 * @return    void
71
+	 */
72
+	public static function set_hooks_admin()
73
+	{
74
+		add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
75
+	}
76
+
77
+
78
+	/**
79
+	 * set_definitions
80
+	 *
81
+	 * @static
82
+	 * @return void
83
+	 */
84
+	public static function set_definitions()
85
+	{
86
+		define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
87
+		define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates' . DS);
88
+	}
89
+
90
+
91
+	/**
92
+	 * set_config
93
+	 *
94
+	 * @void
95
+	 */
96
+	protected function set_config()
97
+	{
98
+		$this->set_config_section('template_settings');
99
+		$this->set_config_class('EE_Event_Single_Config');
100
+		$this->set_config_name('EED_Event_Single');
101
+	}
102
+
103
+
104
+	/**
105
+	 * initialize_template_parts
106
+	 *
107
+	 * @param EE_Config_Base|EE_Event_Single_Config $config
108
+	 * @return EE_Template_Part_Manager
109
+	 */
110
+	public function initialize_template_parts(EE_Event_Single_Config $config = null)
111
+	{
112
+		/** @type EE_Event_Single_Config $config */
113
+		$config = $config instanceof EE_Event_Single_Config ? $config : $this->config();
114
+		EEH_Autoloader::instance()->register_template_part_autoloaders();
115
+		$template_parts = new EE_Template_Part_Manager();
116
+		$template_parts->add_template_part(
117
+			'tickets',
118
+			__('Ticket Selector', 'event_espresso'),
119
+			'content-espresso_events-tickets.php',
120
+			$config->display_order_tickets
121
+		);
122
+		$template_parts->add_template_part(
123
+			'datetimes',
124
+			__('Dates and Times', 'event_espresso'),
125
+			'content-espresso_events-datetimes.php',
126
+			$config->display_order_datetimes
127
+		);
128
+		$template_parts->add_template_part(
129
+			'event',
130
+			__('Event Description', 'event_espresso'),
131
+			'content-espresso_events-details.php',
132
+			$config->display_order_event
133
+		);
134
+		$template_parts->add_template_part(
135
+			'venue',
136
+			__('Venue Information', 'event_espresso'),
137
+			'content-espresso_events-venues.php',
138
+			$config->display_order_venue
139
+		);
140
+		do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts);
141
+		return $template_parts;
142
+	}
143
+
144
+
145
+	/**
146
+	 * run - initial module setup
147
+	 *
148
+	 * @param WP $WP
149
+	 * @return    void
150
+	 */
151
+	public function run($WP)
152
+	{
153
+		// ensure valid EE_Events_Single_Config() object exists
154
+		$this->set_config();
155
+		// check what template is loaded
156
+		add_filter('template_include', array($this, 'template_include'), 999, 1);
157
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
158
+		// load css
159
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
160
+	}
161
+
162
+
163
+	/**
164
+	 * template_include
165
+	 *
166
+	 * @param    string $template
167
+	 * @return    string
168
+	 */
169
+	public function template_include($template)
170
+	{
171
+		global $post;
172
+		/** @type EE_Event_Single_Config $config */
173
+		$config = $this->config();
174
+		if ($config->display_status_banner_single) {
175
+			add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2);
176
+		}
177
+		// not a custom template?
178
+		if (! post_password_required($post)
179
+			&& (
180
+				apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false)
181
+				|| EE_Registry::instance()
182
+							  ->load_core('Front_Controller')
183
+							  ->get_selected_template() !== 'single-espresso_events.php'
184
+			)
185
+
186
+		) {
187
+			EEH_Template::load_espresso_theme_functions();
188
+			// then add extra event data via hooks
189
+			add_action('loop_start', array('EED_Event_Single', 'loop_start'));
190
+			add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1);
191
+			add_filter(
192
+				'the_content',
193
+				array('EED_Event_Single', 'event_details'),
194
+				EED_Event_Single::EVENT_DETAILS_PRIORITY
195
+			);
196
+			add_action('loop_end', array('EED_Event_Single', 'loop_end'));
197
+			// don't display entry meta because the existing theme will take car of that
198
+			add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
199
+		}
200
+		return $template;
201
+	}
202
+
203
+
204
+	/**
205
+	 * loop_start
206
+	 *
207
+	 * @param    array $wp_query_array an array containing the WP_Query object
208
+	 * @return    void
209
+	 */
210
+	public static function loop_start($wp_query_array)
211
+	{
212
+		global $post;
213
+		do_action('AHEE_event_details_before_post', $post, $wp_query_array);
214
+	}
215
+
216
+
217
+	/**
218
+	 * the_title
219
+	 *
220
+	 * @param    string $title
221
+	 * @param    int    $id
222
+	 * @return    string
223
+	 */
224
+	public static function the_title($title = '', $id = 0)
225
+	{
226
+		global $post;
227
+		return in_the_loop() && $post->ID === (int) $id
228
+			? espresso_event_status_banner($post->ID) . $title
229
+			: $title;
230
+	}
231
+
232
+
233
+	/**
234
+	 * get_the_excerpt
235
+	 * kinda hacky, but if a theme is using get_the_excerpt(),
236
+	 * then we need to remove our filters on the_content()
237
+	 *
238
+	 * @param        string $excerpt
239
+	 * @return        string
240
+	 */
241
+	public static function get_the_excerpt($excerpt = '')
242
+	{
243
+		EED_Event_Single::$using_get_the_excerpt = true;
244
+		add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1);
245
+		return $excerpt;
246
+	}
247
+
248
+
249
+	/**
250
+	 * end_get_the_excerpt
251
+	 *
252
+	 * @param  string $text
253
+	 * @return string
254
+	 */
255
+	public static function end_get_the_excerpt($text = '')
256
+	{
257
+		EED_Event_Single::$using_get_the_excerpt = false;
258
+		return $text;
259
+	}
260
+
261
+
262
+	/**
263
+	 * event_details
264
+	 *
265
+	 * @param    string $content
266
+	 * @return    string
267
+	 */
268
+	public static function event_details($content)
269
+	{
270
+		global $post;
271
+		static $current_post_ID = 0;
272
+		if ($current_post_ID !== $post->ID
273
+			&& $post->post_type === 'espresso_events'
274
+			&& ! EED_Event_Single::$using_get_the_excerpt
275
+			&& ! post_password_required()
276
+		) {
277
+			// Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
278
+			// Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
279
+			// BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
280
+			// We want to allow those plugins to still do their thing and have access to our content, but depending on
281
+			// how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
282
+			// so the following allows this filter to be applied multiple times, but only once for real
283
+			$current_post_ID = did_action('loop_start') ? $post->ID : 0;
284
+			if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) {
285
+				// we need to first remove this callback from being applied to the_content()
286
+				// (otherwise it will recurse and blow up the interweb)
287
+				remove_filter(
288
+					'the_content',
289
+					array('EED_Event_Single', 'event_details'),
290
+					EED_Event_Single::EVENT_DETAILS_PRIORITY
291
+				);
292
+				EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts(
293
+				);
294
+				$content = EEH_Template::locate_template('content-espresso_events-details.php');
295
+				$content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content);
296
+				add_filter(
297
+					'the_content',
298
+					array('EED_Event_Single', 'event_details'),
299
+					EED_Event_Single::EVENT_DETAILS_PRIORITY
300
+				);
301
+			} else {
302
+				$content = EED_Event_Single::use_filterable_display_order();
303
+			}
304
+		}
305
+		return $content;
306
+	}
307
+
308
+
309
+	/**
310
+	 * use_filterable_display_order
311
+	 *
312
+	 * @return string
313
+	 */
314
+	protected static function use_filterable_display_order()
315
+	{
316
+		// since the 'content-espresso_events-details.php' template might be used directly from within a theme,
317
+		// it uses the_content() for displaying the $post->post_content
318
+		// so in order to load a template that uses the_content()
319
+		// from within a callback being used to filter the_content(),
320
+		// we need to first remove this callback from being applied to the_content()
321
+		// (otherwise it will recurse and blow up the interweb)
322
+		remove_filter(
323
+			'the_content',
324
+			array('EED_Event_Single', 'event_details'),
325
+			EED_Event_Single::EVENT_DETAILS_PRIORITY
326
+		);
327
+		// now add additional content
328
+		add_filter(
329
+			'the_content',
330
+			array('EED_Event_Single', 'event_datetimes'),
331
+			EED_Event_Single::EVENT_DATETIMES_PRIORITY,
332
+			1
333
+		);
334
+		add_filter(
335
+			'the_content',
336
+			array('EED_Event_Single', 'event_tickets'),
337
+			EED_Event_Single::EVENT_TICKETS_PRIORITY,
338
+			1
339
+		);
340
+		add_filter(
341
+			'the_content',
342
+			array('EED_Event_Single', 'event_venues'),
343
+			EED_Event_Single::EVENT_VENUES_PRIORITY,
344
+			1
345
+		);
346
+		do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters');
347
+		// now load our template
348
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
349
+		// now add our filter back in, plus some others
350
+		add_filter(
351
+			'the_content',
352
+			array('EED_Event_Single', 'event_details'),
353
+			EED_Event_Single::EVENT_DETAILS_PRIORITY
354
+		);
355
+		remove_filter(
356
+			'the_content',
357
+			array('EED_Event_Single', 'event_datetimes'),
358
+			EED_Event_Single::EVENT_DATETIMES_PRIORITY
359
+		);
360
+		remove_filter(
361
+			'the_content',
362
+			array('EED_Event_Single', 'event_tickets'),
363
+			EED_Event_Single::EVENT_TICKETS_PRIORITY
364
+		);
365
+		remove_filter(
366
+			'the_content',
367
+			array('EED_Event_Single', 'event_venues'),
368
+			EED_Event_Single::EVENT_VENUES_PRIORITY
369
+		);
370
+		do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters');
371
+		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
372
+		return $content;
373
+	}
374
+
375
+
376
+	/**
377
+	 * event_datetimes - adds datetimes ABOVE content
378
+	 *
379
+	 * @param        string $content
380
+	 * @return        string
381
+	 */
382
+	public static function event_datetimes($content)
383
+	{
384
+		return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
385
+	}
386
+
387
+
388
+	/**
389
+	 * event_tickets - adds tickets ABOVE content (which includes datetimes)
390
+	 *
391
+	 * @param        string $content
392
+	 * @return        string
393
+	 */
394
+	public static function event_tickets($content)
395
+	{
396
+		return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
397
+	}
398
+
399
+
400
+	/**
401
+	 * event_venues
402
+	 *
403
+	 * @param    string $content
404
+	 * @return    string
405
+	 */
406
+	public static function event_venue($content)
407
+	{
408
+		return EED_Event_Single::event_venues($content);
409
+	}
410
+
411
+
412
+	/**
413
+	 * event_venues - adds venues BELOW content
414
+	 *
415
+	 * @param        string $content
416
+	 * @return        string
417
+	 */
418
+	public static function event_venues($content)
419
+	{
420
+		return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
421
+	}
422
+
423
+
424
+	/**
425
+	 * loop_end
426
+	 *
427
+	 * @param        array $wp_query_array an array containing the WP_Query object
428
+	 * @return        void
429
+	 */
430
+	public static function loop_end($wp_query_array)
431
+	{
432
+		global $post;
433
+		do_action('AHEE_event_details_after_post', $post, $wp_query_array);
434
+	}
435
+
436
+
437
+	/**
438
+	 * wp_enqueue_scripts
439
+	 *
440
+	 * @return    void
441
+	 */
442
+	public function wp_enqueue_scripts()
443
+	{
444
+		// get some style
445
+		if (apply_filters('FHEE_enable_default_espresso_css', true)
446
+			&& apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true)
447
+		) {
448
+			// first check uploads folder
449
+			if (is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) {
450
+				wp_register_style(
451
+					$this->theme,
452
+					get_stylesheet_directory_uri() . $this->theme . DS . 'style.css',
453
+					array('dashicons', 'espresso_default')
454
+				);
455
+			} else {
456
+				wp_register_style(
457
+					$this->theme,
458
+					EE_TEMPLATES_URL . $this->theme . DS . 'style.css',
459
+					array('dashicons', 'espresso_default')
460
+				);
461
+			}
462
+			wp_enqueue_script($this->theme);
463
+			if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
464
+				add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
465
+			}
466
+		}
467
+	}
468
+
469
+
470
+	/**
471
+	 * display_venue
472
+	 *
473
+	 * @return    bool
474
+	 */
475
+	public static function display_venue()
476
+	{
477
+		/** @type EE_Event_Single_Config $config */
478
+		$config = EED_Event_Single::instance()->config();
479
+		$display_venue = $config->display_venue === null ? true : $config->display_venue;
480
+		$venue_name = EEH_Venue_View::venue_name();
481
+		return $display_venue && ! empty($venue_name);
482
+	}
483 483
 }
484 484
 
485 485
 
@@ -491,5 +491,5 @@  discard block
 block discarded – undo
491 491
  */
492 492
 function espresso_display_venue_in_event_details()
493 493
 {
494
-    return EED_Event_Single::display_venue();
494
+	return EED_Event_Single::display_venue();
495 495
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
      */
84 84
     public static function set_definitions()
85 85
     {
86
-        define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
87
-        define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates' . DS);
86
+        define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
87
+        define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__).'templates'.DS);
88 88
     }
89 89
 
90 90
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
             add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2);
176 176
         }
177 177
         // not a custom template?
178
-        if (! post_password_required($post)
178
+        if ( ! post_password_required($post)
179 179
             && (
180 180
                 apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false)
181 181
                 || EE_Registry::instance()
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
     {
226 226
         global $post;
227 227
         return in_the_loop() && $post->ID === (int) $id
228
-            ? espresso_event_status_banner($post->ID) . $title
228
+            ? espresso_event_status_banner($post->ID).$title
229 229
             : $title;
230 230
     }
231 231
 
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
      */
382 382
     public static function event_datetimes($content)
383 383
     {
384
-        return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
384
+        return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content;
385 385
     }
386 386
 
387 387
 
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
      */
394 394
     public static function event_tickets($content)
395 395
     {
396
-        return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
396
+        return EEH_Template::locate_template('content-espresso_events-tickets.php').$content;
397 397
     }
398 398
 
399 399
 
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
      */
418 418
     public static function event_venues($content)
419 419
     {
420
-        return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
420
+        return $content.EEH_Template::locate_template('content-espresso_events-venues.php');
421 421
     }
422 422
 
423 423
 
@@ -446,16 +446,16 @@  discard block
 block discarded – undo
446 446
             && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true)
447 447
         ) {
448 448
             // first check uploads folder
449
-            if (is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) {
449
+            if (is_readable(get_stylesheet_directory().$this->theme.DS.'style.css')) {
450 450
                 wp_register_style(
451 451
                     $this->theme,
452
-                    get_stylesheet_directory_uri() . $this->theme . DS . 'style.css',
452
+                    get_stylesheet_directory_uri().$this->theme.DS.'style.css',
453 453
                     array('dashicons', 'espresso_default')
454 454
                 );
455 455
             } else {
456 456
                 wp_register_style(
457 457
                     $this->theme,
458
-                    EE_TEMPLATES_URL . $this->theme . DS . 'style.css',
458
+                    EE_TEMPLATES_URL.$this->theme.DS.'style.css',
459 459
                     array('dashicons', 'espresso_default')
460 460
                 );
461 461
             }
Please login to merge, or discard this patch.