@@ -12,151 +12,151 @@ |
||
12 | 12 | */ |
13 | 13 | class EEH_Export |
14 | 14 | { |
15 | - /** |
|
16 | - * Gets the 'normal' column named for fields |
|
17 | - * @param EE_Model_Field_Base $field |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public static function get_column_name_for_field(EE_Model_Field_Base $field) |
|
21 | - { |
|
22 | - return wp_specialchars_decode($field->get_nicename(), ENT_QUOTES) |
|
23 | - . "[" . wp_specialchars_decode($field->get_name(), ENT_QUOTES) |
|
24 | - . "]"; |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * Writes $data to the csv file open in $filehandle. uses the array indices of $data for column headers |
|
29 | - * |
|
30 | - * @param string $filepath |
|
31 | - * @param array $data 2D array, first numerically-indexed, |
|
32 | - * and next-level-down preferably indexed by string |
|
33 | - * @param boolean $write_column_headers whether or not we should add the keys in the bottom-most array |
|
34 | - * as a row for headers in the CSV. |
|
35 | - * Eg, if $data looked like: |
|
36 | - * array( |
|
37 | - * 0=>array('EVT_ID'=>1,'EVT_name'=>'monkey'...), |
|
38 | - * 1=>array(...,...) |
|
39 | - * ) |
|
40 | - * |
|
41 | - * @return boolean if we successfully wrote to the CSV or not. If there's no $data, |
|
42 | - * we consider that a success (because we wrote everything there was...nothing) |
|
43 | - * @throws EE_Error |
|
44 | - */ |
|
45 | - public static function write_data_array_to_csv($filepath, $data, $write_column_headers = true) |
|
46 | - { |
|
47 | - |
|
48 | - $new_file_contents = ''; |
|
49 | - // determine if $data is actually a 2d array |
|
50 | - if ($data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))) { |
|
51 | - // make sure top level is numerically indexed, |
|
52 | - |
|
53 | - if (EEH_Array::is_associative_array($data)) { |
|
54 | - throw new EE_Error(sprintf(__("top-level array must be numerically indexed. Does these look like numbers to you? %s", "event_espresso"), implode(",", array_keys($data)))); |
|
55 | - } |
|
56 | - $item_in_top_level_array = EEH_Array::get_one_item_from_array($data); |
|
57 | - // now, is the last item in the top-level array of $data an associative or numeric array? |
|
58 | - if ($write_column_headers && |
|
59 | - EEH_Array::is_associative_array($item_in_top_level_array)) { |
|
60 | - // its associative, so we want to output its keys as column headers |
|
61 | - $keys = array_keys($item_in_top_level_array); |
|
62 | - $new_file_contents .= EEH_Export::get_csv_row($keys); |
|
63 | - } |
|
64 | - // start writing data |
|
65 | - foreach ($data as $data_row) { |
|
66 | - $new_file_contents .= EEH_Export::get_csv_row($data_row); |
|
67 | - } |
|
68 | - return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath) . $new_file_contents); |
|
69 | - } else { |
|
70 | - // no data TO write... so we can assume that's a success |
|
71 | - return true; |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * |
|
79 | - * Writes a row to the csv file |
|
80 | - * @param array $row - individual row of csv data |
|
81 | - * @param string $delimiter - csv delimiter |
|
82 | - * @param string $enclosure - csv enclosure |
|
83 | - * @param bool $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
|
84 | - * @return string of text for teh csv file |
|
85 | - */ |
|
86 | - public static function get_csv_row(array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false) |
|
87 | - { |
|
88 | - // Allow user to filter the csv delimiter and enclosure for other countries csv standards |
|
89 | - $delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter); |
|
90 | - $enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure); |
|
91 | - |
|
92 | - $delimiter_esc = preg_quote($delimiter, '/'); |
|
93 | - $enclosure_esc = preg_quote($enclosure, '/'); |
|
94 | - |
|
95 | - $output = array(); |
|
96 | - foreach ($row as $field_value) { |
|
97 | - if (is_object($field_value) || is_array($field_value)) { |
|
98 | - $field_value = serialize($field_value); |
|
99 | - } |
|
100 | - if ($field_value === null && $mysql_null) { |
|
101 | - $output[] = 'NULL'; |
|
102 | - continue; |
|
103 | - } |
|
104 | - |
|
105 | - $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ? |
|
106 | - ( $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure ) : $field_value; |
|
107 | - } |
|
108 | - |
|
109 | - return implode($delimiter, $output) . PHP_EOL; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * Shortcut for preparing a database result for display |
|
116 | - * @param EEM_Base $model |
|
117 | - * @param string $field_name |
|
118 | - * @param string $raw_db_value |
|
119 | - * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to NOT display pretty |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public static function prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true) |
|
123 | - { |
|
124 | - $field_obj = $model->field_settings_for($field_name); |
|
125 | - $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
126 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
127 | - $field_obj->set_date_format(EEH_Export::get_date_format_for_export($field_obj->get_date_format($pretty_schema)), $pretty_schema); |
|
128 | - $field_obj->set_time_format(EEH_Export::get_time_format_for_export($field_obj->get_time_format($pretty_schema)), $pretty_schema); |
|
129 | - } |
|
130 | - if ($pretty_schema === true) { |
|
131 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
132 | - } elseif (is_string($pretty_schema)) { |
|
133 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
134 | - } else { |
|
135 | - return $field_obj->prepare_for_get($value_on_model_obj); |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * Gets the date format to use in exports. filterable |
|
143 | - * @param string $current_format |
|
144 | - * @return string |
|
145 | - */ |
|
146 | - public static function get_date_format_for_export($current_format = null) |
|
147 | - { |
|
148 | - return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * Gets the time format we want to use in exports. Filterable |
|
155 | - * @param string $current_format |
|
156 | - * @return string |
|
157 | - */ |
|
158 | - public static function get_time_format_for_export($current_format = null) |
|
159 | - { |
|
160 | - return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format); |
|
161 | - } |
|
15 | + /** |
|
16 | + * Gets the 'normal' column named for fields |
|
17 | + * @param EE_Model_Field_Base $field |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public static function get_column_name_for_field(EE_Model_Field_Base $field) |
|
21 | + { |
|
22 | + return wp_specialchars_decode($field->get_nicename(), ENT_QUOTES) |
|
23 | + . "[" . wp_specialchars_decode($field->get_name(), ENT_QUOTES) |
|
24 | + . "]"; |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * Writes $data to the csv file open in $filehandle. uses the array indices of $data for column headers |
|
29 | + * |
|
30 | + * @param string $filepath |
|
31 | + * @param array $data 2D array, first numerically-indexed, |
|
32 | + * and next-level-down preferably indexed by string |
|
33 | + * @param boolean $write_column_headers whether or not we should add the keys in the bottom-most array |
|
34 | + * as a row for headers in the CSV. |
|
35 | + * Eg, if $data looked like: |
|
36 | + * array( |
|
37 | + * 0=>array('EVT_ID'=>1,'EVT_name'=>'monkey'...), |
|
38 | + * 1=>array(...,...) |
|
39 | + * ) |
|
40 | + * |
|
41 | + * @return boolean if we successfully wrote to the CSV or not. If there's no $data, |
|
42 | + * we consider that a success (because we wrote everything there was...nothing) |
|
43 | + * @throws EE_Error |
|
44 | + */ |
|
45 | + public static function write_data_array_to_csv($filepath, $data, $write_column_headers = true) |
|
46 | + { |
|
47 | + |
|
48 | + $new_file_contents = ''; |
|
49 | + // determine if $data is actually a 2d array |
|
50 | + if ($data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))) { |
|
51 | + // make sure top level is numerically indexed, |
|
52 | + |
|
53 | + if (EEH_Array::is_associative_array($data)) { |
|
54 | + throw new EE_Error(sprintf(__("top-level array must be numerically indexed. Does these look like numbers to you? %s", "event_espresso"), implode(",", array_keys($data)))); |
|
55 | + } |
|
56 | + $item_in_top_level_array = EEH_Array::get_one_item_from_array($data); |
|
57 | + // now, is the last item in the top-level array of $data an associative or numeric array? |
|
58 | + if ($write_column_headers && |
|
59 | + EEH_Array::is_associative_array($item_in_top_level_array)) { |
|
60 | + // its associative, so we want to output its keys as column headers |
|
61 | + $keys = array_keys($item_in_top_level_array); |
|
62 | + $new_file_contents .= EEH_Export::get_csv_row($keys); |
|
63 | + } |
|
64 | + // start writing data |
|
65 | + foreach ($data as $data_row) { |
|
66 | + $new_file_contents .= EEH_Export::get_csv_row($data_row); |
|
67 | + } |
|
68 | + return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath) . $new_file_contents); |
|
69 | + } else { |
|
70 | + // no data TO write... so we can assume that's a success |
|
71 | + return true; |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * |
|
79 | + * Writes a row to the csv file |
|
80 | + * @param array $row - individual row of csv data |
|
81 | + * @param string $delimiter - csv delimiter |
|
82 | + * @param string $enclosure - csv enclosure |
|
83 | + * @param bool $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
|
84 | + * @return string of text for teh csv file |
|
85 | + */ |
|
86 | + public static function get_csv_row(array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false) |
|
87 | + { |
|
88 | + // Allow user to filter the csv delimiter and enclosure for other countries csv standards |
|
89 | + $delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter); |
|
90 | + $enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure); |
|
91 | + |
|
92 | + $delimiter_esc = preg_quote($delimiter, '/'); |
|
93 | + $enclosure_esc = preg_quote($enclosure, '/'); |
|
94 | + |
|
95 | + $output = array(); |
|
96 | + foreach ($row as $field_value) { |
|
97 | + if (is_object($field_value) || is_array($field_value)) { |
|
98 | + $field_value = serialize($field_value); |
|
99 | + } |
|
100 | + if ($field_value === null && $mysql_null) { |
|
101 | + $output[] = 'NULL'; |
|
102 | + continue; |
|
103 | + } |
|
104 | + |
|
105 | + $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ? |
|
106 | + ( $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure ) : $field_value; |
|
107 | + } |
|
108 | + |
|
109 | + return implode($delimiter, $output) . PHP_EOL; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * Shortcut for preparing a database result for display |
|
116 | + * @param EEM_Base $model |
|
117 | + * @param string $field_name |
|
118 | + * @param string $raw_db_value |
|
119 | + * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to NOT display pretty |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public static function prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true) |
|
123 | + { |
|
124 | + $field_obj = $model->field_settings_for($field_name); |
|
125 | + $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
126 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
127 | + $field_obj->set_date_format(EEH_Export::get_date_format_for_export($field_obj->get_date_format($pretty_schema)), $pretty_schema); |
|
128 | + $field_obj->set_time_format(EEH_Export::get_time_format_for_export($field_obj->get_time_format($pretty_schema)), $pretty_schema); |
|
129 | + } |
|
130 | + if ($pretty_schema === true) { |
|
131 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
132 | + } elseif (is_string($pretty_schema)) { |
|
133 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
134 | + } else { |
|
135 | + return $field_obj->prepare_for_get($value_on_model_obj); |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * Gets the date format to use in exports. filterable |
|
143 | + * @param string $current_format |
|
144 | + * @return string |
|
145 | + */ |
|
146 | + public static function get_date_format_for_export($current_format = null) |
|
147 | + { |
|
148 | + return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * Gets the time format we want to use in exports. Filterable |
|
155 | + * @param string $current_format |
|
156 | + * @return string |
|
157 | + */ |
|
158 | + public static function get_time_format_for_export($current_format = null) |
|
159 | + { |
|
160 | + return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format); |
|
161 | + } |
|
162 | 162 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | public static function get_column_name_for_field(EE_Model_Field_Base $field) |
21 | 21 | { |
22 | 22 | return wp_specialchars_decode($field->get_nicename(), ENT_QUOTES) |
23 | - . "[" . wp_specialchars_decode($field->get_name(), ENT_QUOTES) |
|
23 | + . "[".wp_specialchars_decode($field->get_name(), ENT_QUOTES) |
|
24 | 24 | . "]"; |
25 | 25 | } |
26 | 26 | |
@@ -59,13 +59,13 @@ discard block |
||
59 | 59 | EEH_Array::is_associative_array($item_in_top_level_array)) { |
60 | 60 | // its associative, so we want to output its keys as column headers |
61 | 61 | $keys = array_keys($item_in_top_level_array); |
62 | - $new_file_contents .= EEH_Export::get_csv_row($keys); |
|
62 | + $new_file_contents .= EEH_Export::get_csv_row($keys); |
|
63 | 63 | } |
64 | 64 | // start writing data |
65 | 65 | foreach ($data as $data_row) { |
66 | 66 | $new_file_contents .= EEH_Export::get_csv_row($data_row); |
67 | 67 | } |
68 | - return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath) . $new_file_contents); |
|
68 | + return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath).$new_file_contents); |
|
69 | 69 | } else { |
70 | 70 | // no data TO write... so we can assume that's a success |
71 | 71 | return true; |
@@ -103,10 +103,10 @@ discard block |
||
103 | 103 | } |
104 | 104 | |
105 | 105 | $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ? |
106 | - ( $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure ) : $field_value; |
|
106 | + ($enclosure.str_replace($enclosure, $enclosure.$enclosure, $field_value).$enclosure) : $field_value; |
|
107 | 107 | } |
108 | 108 | |
109 | - return implode($delimiter, $output) . PHP_EOL; |
|
109 | + return implode($delimiter, $output).PHP_EOL; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 |
@@ -13,203 +13,203 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays |
|
18 | - * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects |
|
19 | - * |
|
20 | - * @uses array_udiff core php function for setting up our own array comparison |
|
21 | - * @uses self::_compare_objects as the custom method for array_udiff |
|
22 | - * @param array $array1 an array of objects |
|
23 | - * @param array $array2 an array of objects |
|
24 | - * @return array an array of objects found in array 1 that aren't found in array 2. |
|
25 | - */ |
|
26 | - public static function object_array_diff($array1, $array2) |
|
27 | - { |
|
28 | - return array_udiff($array1, $array2, array('self', '_compare_objects')); |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed |
|
33 | - * |
|
34 | - * @param array $array |
|
35 | - * @return boolean |
|
36 | - */ |
|
37 | - public static function is_associative_array(array $array) |
|
38 | - { |
|
39 | - return array_keys($array) !== range(0, count($array) - 1); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Gets an item from the array and leave the array intact. Use in place of end() |
|
44 | - * when you don't want to change the array |
|
45 | - * |
|
46 | - * @param array $arr |
|
47 | - * @return mixed what ever is in the array |
|
48 | - */ |
|
49 | - public static function get_one_item_from_array($arr) |
|
50 | - { |
|
51 | - $item = end($arr); |
|
52 | - reset($arr); |
|
53 | - return $item; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Detects if this is a multi-dimensional array (meaning that the top-level |
|
58 | - * values are themselves array. Eg array(array(...),...) |
|
59 | - * |
|
60 | - * @param mixed $arr |
|
61 | - * @return boolean |
|
62 | - */ |
|
63 | - public static function is_multi_dimensional_array($arr) |
|
64 | - { |
|
65 | - if (is_array($arr)) { |
|
66 | - $first_item = reset($arr); |
|
67 | - if (is_array($first_item)) { |
|
68 | - return true;// yep, there's at least 2 levels to this array |
|
69 | - } else { |
|
70 | - return false;// nope, only 1 level |
|
71 | - } |
|
72 | - } else { |
|
73 | - return false;// its not an array at all! |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default |
|
79 | - * |
|
80 | - * @param array $arr |
|
81 | - * @param mixed $index |
|
82 | - * @param mixed $default |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - public static function is_set($arr, $index, $default) |
|
86 | - { |
|
87 | - return isset($arr[ $index ]) ? $arr[ $index ] : $default; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118 |
|
92 | - * |
|
93 | - * @param mixed $value usually a string, but could be an array or object |
|
94 | - * @return mixed the UN-serialized data |
|
95 | - */ |
|
96 | - public static function maybe_unserialize($value) |
|
97 | - { |
|
98 | - $data = maybe_unserialize($value); |
|
99 | - // it's possible that this still has serialized data if its the session. WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesnt' unserialize this automatically. |
|
100 | - $token = 'C'; |
|
101 | - $data = is_string($data) ? trim($data) : $data; |
|
102 | - if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) { |
|
103 | - return unserialize($data); |
|
104 | - } else { |
|
105 | - return $data; |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * insert_into_array |
|
112 | - * |
|
113 | - * @param array $target_array the array to insert new data into |
|
114 | - * @param array $array_to_insert the new data to be inserted |
|
115 | - * @param int | string $offset a known key within $target_array where new data will be inserted |
|
116 | - * @param bool $add_before whether to add new data before or after the offset key |
|
117 | - * @param bool $preserve_keys whether or not to reset numerically indexed arrays |
|
118 | - * @return array |
|
119 | - */ |
|
120 | - public static function insert_into_array( |
|
121 | - $target_array = array(), |
|
122 | - $array_to_insert = array(), |
|
123 | - $offset = null, |
|
124 | - $add_before = true, |
|
125 | - $preserve_keys = true |
|
126 | - ) { |
|
127 | - // ensure incoming arrays are actually arrays |
|
128 | - $target_array = (array) $target_array; |
|
129 | - $array_to_insert = (array) $array_to_insert; |
|
130 | - // if no offset key was supplied |
|
131 | - if (empty($offset)) { |
|
132 | - // use start or end of $target_array based on whether we are adding before or not |
|
133 | - $offset = $add_before ? 0 : count($target_array); |
|
134 | - } |
|
135 | - // if offset key is a string, then find the corresponding numeric location for that element |
|
136 | - $offset = is_int($offset) ? $offset : array_search($offset, array_keys($target_array)); |
|
137 | - // add one to the offset if adding after |
|
138 | - $offset = $add_before ? $offset : $offset + 1; |
|
139 | - // but ensure offset does not exceed the length of the array |
|
140 | - $offset = $offset > count($target_array) ? count($target_array) : $offset; |
|
141 | - // reindex array ??? |
|
142 | - if ($preserve_keys) { |
|
143 | - // take a slice of the target array from the beginning till the offset, |
|
144 | - // then add the new data |
|
145 | - // then add another slice that starts at the offset and goes till the end |
|
146 | - return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice( |
|
147 | - $target_array, |
|
148 | - $offset, |
|
149 | - null, |
|
150 | - true |
|
151 | - ); |
|
152 | - } else { |
|
153 | - // since we don't want to preserve keys, we can use array_splice |
|
154 | - array_splice($target_array, $offset, 0, $array_to_insert); |
|
155 | - return $target_array; |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * array_merge() is slow and should never be used while looping over data |
|
162 | - * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster |
|
163 | - * so really this acts more like array_replace( $array1, $array2 ) |
|
164 | - * or a union with the arrays flipped ( $array2 + $array1 ) |
|
165 | - * this saves a few lines of code and improves readability |
|
166 | - * |
|
167 | - * @param array $array1 |
|
168 | - * @param array $array2 |
|
169 | - * @return array |
|
170 | - */ |
|
171 | - public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) |
|
172 | - { |
|
173 | - foreach ($array2 as $key => $value) { |
|
174 | - $array1[ $key ] = $value; |
|
175 | - } |
|
176 | - return $array1; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * given a flat array like $array = array('A', 'B', 'C') |
|
182 | - * will convert into a multidimensional array like $array[A][B][C] |
|
183 | - * if $final_value is provided and is anything other than null, |
|
184 | - * then that will be set as the value for the innermost array key |
|
185 | - * like so: $array[A][B][C] = $final_value |
|
186 | - * |
|
187 | - * @param array $flat_array |
|
188 | - * @param mixed $final_value |
|
189 | - * @return array |
|
190 | - */ |
|
191 | - public static function convert_array_values_to_keys(array $flat_array, $final_value = null) |
|
192 | - { |
|
193 | - $multidimensional = array(); |
|
194 | - $reference = &$multidimensional; |
|
195 | - foreach ($flat_array as $key) { |
|
196 | - $reference[ $key ] = array(); |
|
197 | - $reference = &$reference[ $key ]; |
|
198 | - } |
|
199 | - if ($final_value !== null) { |
|
200 | - $reference = $final_value; |
|
201 | - } |
|
202 | - return $multidimensional; |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
208 | - * @param array $array |
|
209 | - * @return bool |
|
210 | - */ |
|
211 | - public static function is_array_numerically_and_sequentially_indexed(array $array) |
|
212 | - { |
|
213 | - return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
214 | - } |
|
16 | + /** |
|
17 | + * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays |
|
18 | + * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects |
|
19 | + * |
|
20 | + * @uses array_udiff core php function for setting up our own array comparison |
|
21 | + * @uses self::_compare_objects as the custom method for array_udiff |
|
22 | + * @param array $array1 an array of objects |
|
23 | + * @param array $array2 an array of objects |
|
24 | + * @return array an array of objects found in array 1 that aren't found in array 2. |
|
25 | + */ |
|
26 | + public static function object_array_diff($array1, $array2) |
|
27 | + { |
|
28 | + return array_udiff($array1, $array2, array('self', '_compare_objects')); |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed |
|
33 | + * |
|
34 | + * @param array $array |
|
35 | + * @return boolean |
|
36 | + */ |
|
37 | + public static function is_associative_array(array $array) |
|
38 | + { |
|
39 | + return array_keys($array) !== range(0, count($array) - 1); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Gets an item from the array and leave the array intact. Use in place of end() |
|
44 | + * when you don't want to change the array |
|
45 | + * |
|
46 | + * @param array $arr |
|
47 | + * @return mixed what ever is in the array |
|
48 | + */ |
|
49 | + public static function get_one_item_from_array($arr) |
|
50 | + { |
|
51 | + $item = end($arr); |
|
52 | + reset($arr); |
|
53 | + return $item; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Detects if this is a multi-dimensional array (meaning that the top-level |
|
58 | + * values are themselves array. Eg array(array(...),...) |
|
59 | + * |
|
60 | + * @param mixed $arr |
|
61 | + * @return boolean |
|
62 | + */ |
|
63 | + public static function is_multi_dimensional_array($arr) |
|
64 | + { |
|
65 | + if (is_array($arr)) { |
|
66 | + $first_item = reset($arr); |
|
67 | + if (is_array($first_item)) { |
|
68 | + return true;// yep, there's at least 2 levels to this array |
|
69 | + } else { |
|
70 | + return false;// nope, only 1 level |
|
71 | + } |
|
72 | + } else { |
|
73 | + return false;// its not an array at all! |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default |
|
79 | + * |
|
80 | + * @param array $arr |
|
81 | + * @param mixed $index |
|
82 | + * @param mixed $default |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + public static function is_set($arr, $index, $default) |
|
86 | + { |
|
87 | + return isset($arr[ $index ]) ? $arr[ $index ] : $default; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118 |
|
92 | + * |
|
93 | + * @param mixed $value usually a string, but could be an array or object |
|
94 | + * @return mixed the UN-serialized data |
|
95 | + */ |
|
96 | + public static function maybe_unserialize($value) |
|
97 | + { |
|
98 | + $data = maybe_unserialize($value); |
|
99 | + // it's possible that this still has serialized data if its the session. WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesnt' unserialize this automatically. |
|
100 | + $token = 'C'; |
|
101 | + $data = is_string($data) ? trim($data) : $data; |
|
102 | + if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) { |
|
103 | + return unserialize($data); |
|
104 | + } else { |
|
105 | + return $data; |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * insert_into_array |
|
112 | + * |
|
113 | + * @param array $target_array the array to insert new data into |
|
114 | + * @param array $array_to_insert the new data to be inserted |
|
115 | + * @param int | string $offset a known key within $target_array where new data will be inserted |
|
116 | + * @param bool $add_before whether to add new data before or after the offset key |
|
117 | + * @param bool $preserve_keys whether or not to reset numerically indexed arrays |
|
118 | + * @return array |
|
119 | + */ |
|
120 | + public static function insert_into_array( |
|
121 | + $target_array = array(), |
|
122 | + $array_to_insert = array(), |
|
123 | + $offset = null, |
|
124 | + $add_before = true, |
|
125 | + $preserve_keys = true |
|
126 | + ) { |
|
127 | + // ensure incoming arrays are actually arrays |
|
128 | + $target_array = (array) $target_array; |
|
129 | + $array_to_insert = (array) $array_to_insert; |
|
130 | + // if no offset key was supplied |
|
131 | + if (empty($offset)) { |
|
132 | + // use start or end of $target_array based on whether we are adding before or not |
|
133 | + $offset = $add_before ? 0 : count($target_array); |
|
134 | + } |
|
135 | + // if offset key is a string, then find the corresponding numeric location for that element |
|
136 | + $offset = is_int($offset) ? $offset : array_search($offset, array_keys($target_array)); |
|
137 | + // add one to the offset if adding after |
|
138 | + $offset = $add_before ? $offset : $offset + 1; |
|
139 | + // but ensure offset does not exceed the length of the array |
|
140 | + $offset = $offset > count($target_array) ? count($target_array) : $offset; |
|
141 | + // reindex array ??? |
|
142 | + if ($preserve_keys) { |
|
143 | + // take a slice of the target array from the beginning till the offset, |
|
144 | + // then add the new data |
|
145 | + // then add another slice that starts at the offset and goes till the end |
|
146 | + return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice( |
|
147 | + $target_array, |
|
148 | + $offset, |
|
149 | + null, |
|
150 | + true |
|
151 | + ); |
|
152 | + } else { |
|
153 | + // since we don't want to preserve keys, we can use array_splice |
|
154 | + array_splice($target_array, $offset, 0, $array_to_insert); |
|
155 | + return $target_array; |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * array_merge() is slow and should never be used while looping over data |
|
162 | + * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster |
|
163 | + * so really this acts more like array_replace( $array1, $array2 ) |
|
164 | + * or a union with the arrays flipped ( $array2 + $array1 ) |
|
165 | + * this saves a few lines of code and improves readability |
|
166 | + * |
|
167 | + * @param array $array1 |
|
168 | + * @param array $array2 |
|
169 | + * @return array |
|
170 | + */ |
|
171 | + public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) |
|
172 | + { |
|
173 | + foreach ($array2 as $key => $value) { |
|
174 | + $array1[ $key ] = $value; |
|
175 | + } |
|
176 | + return $array1; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * given a flat array like $array = array('A', 'B', 'C') |
|
182 | + * will convert into a multidimensional array like $array[A][B][C] |
|
183 | + * if $final_value is provided and is anything other than null, |
|
184 | + * then that will be set as the value for the innermost array key |
|
185 | + * like so: $array[A][B][C] = $final_value |
|
186 | + * |
|
187 | + * @param array $flat_array |
|
188 | + * @param mixed $final_value |
|
189 | + * @return array |
|
190 | + */ |
|
191 | + public static function convert_array_values_to_keys(array $flat_array, $final_value = null) |
|
192 | + { |
|
193 | + $multidimensional = array(); |
|
194 | + $reference = &$multidimensional; |
|
195 | + foreach ($flat_array as $key) { |
|
196 | + $reference[ $key ] = array(); |
|
197 | + $reference = &$reference[ $key ]; |
|
198 | + } |
|
199 | + if ($final_value !== null) { |
|
200 | + $reference = $final_value; |
|
201 | + } |
|
202 | + return $multidimensional; |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
208 | + * @param array $array |
|
209 | + * @return bool |
|
210 | + */ |
|
211 | + public static function is_array_numerically_and_sequentially_indexed(array $array) |
|
212 | + { |
|
213 | + return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
214 | + } |
|
215 | 215 | } |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | if (is_array($arr)) { |
66 | 66 | $first_item = reset($arr); |
67 | 67 | if (is_array($first_item)) { |
68 | - return true;// yep, there's at least 2 levels to this array |
|
68 | + return true; // yep, there's at least 2 levels to this array |
|
69 | 69 | } else { |
70 | - return false;// nope, only 1 level |
|
70 | + return false; // nope, only 1 level |
|
71 | 71 | } |
72 | 72 | } else { |
73 | - return false;// its not an array at all! |
|
73 | + return false; // its not an array at all! |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public static function is_set($arr, $index, $default) |
86 | 86 | { |
87 | - return isset($arr[ $index ]) ? $arr[ $index ] : $default; |
|
87 | + return isset($arr[$index]) ? $arr[$index] : $default; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) |
172 | 172 | { |
173 | 173 | foreach ($array2 as $key => $value) { |
174 | - $array1[ $key ] = $value; |
|
174 | + $array1[$key] = $value; |
|
175 | 175 | } |
176 | 176 | return $array1; |
177 | 177 | } |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | $multidimensional = array(); |
194 | 194 | $reference = &$multidimensional; |
195 | 195 | foreach ($flat_array as $key) { |
196 | - $reference[ $key ] = array(); |
|
197 | - $reference = &$reference[ $key ]; |
|
196 | + $reference[$key] = array(); |
|
197 | + $reference = &$reference[$key]; |
|
198 | 198 | } |
199 | 199 | if ($final_value !== null) { |
200 | 200 | $reference = $final_value; |
@@ -15,673 +15,673 @@ |
||
15 | 15 | class EEH_Event_Query |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Start Date |
|
20 | - * |
|
21 | - * @var $_event_query_month |
|
22 | - */ |
|
23 | - protected static $_event_query_month; |
|
24 | - |
|
25 | - /** |
|
26 | - * Category |
|
27 | - * |
|
28 | - * @var $_event_query_category |
|
29 | - */ |
|
30 | - protected static $_event_query_category; |
|
31 | - |
|
32 | - /** |
|
33 | - * whether to display expired events in the event list |
|
34 | - * |
|
35 | - * @var bool $_show_expired |
|
36 | - */ |
|
37 | - protected static $_event_query_show_expired = false; |
|
38 | - |
|
39 | - /** |
|
40 | - * list of params for controlling how the query results are ordered |
|
41 | - * |
|
42 | - * @var array $_event_query_orderby |
|
43 | - */ |
|
44 | - protected static $_event_query_orderby = array(); |
|
45 | - |
|
46 | - /** |
|
47 | - * direction list is sorted |
|
48 | - * |
|
49 | - * @var string $_event_query_sort |
|
50 | - */ |
|
51 | - protected static $_event_query_sort; |
|
52 | - |
|
53 | - /** |
|
54 | - * list of params used to build the query's various clauses |
|
55 | - * |
|
56 | - * @var $_query_params |
|
57 | - */ |
|
58 | - protected static $_query_params = array(); |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public static function add_query_filters() |
|
66 | - { |
|
67 | - // add query filters |
|
68 | - add_action('pre_get_posts', array('EEH_Event_Query', 'filter_query_parts'), 10, 1); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param WP_Query $WP_Query |
|
75 | - * @return bool |
|
76 | - */ |
|
77 | - public static function apply_query_filters(WP_Query $WP_Query) |
|
78 | - { |
|
79 | - return ( |
|
80 | - isset($WP_Query->query['post_type']) |
|
81 | - && $WP_Query->query['post_type'] === 'espresso_events' |
|
82 | - ) |
|
83 | - || apply_filters('FHEE__EEH_Event_Query__apply_query_filters', false); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @param WP_Query $WP_Query |
|
89 | - */ |
|
90 | - public static function filter_query_parts(WP_Query $WP_Query) |
|
91 | - { |
|
92 | - // ONLY add our filters if this isn't the main wp_query, |
|
93 | - // because if this is the main wp_query we already have |
|
94 | - // our cpt strategies take care of adding things in. |
|
95 | - if ($WP_Query instanceof WP_Query && ! $WP_Query->is_main_query()) { |
|
96 | - // build event list query |
|
97 | - add_filter('posts_fields', array('EEH_Event_Query', 'posts_fields'), 10, 2); |
|
98 | - add_filter('posts_join', array('EEH_Event_Query', 'posts_join'), 10, 2); |
|
99 | - add_filter('posts_where', array('EEH_Event_Query', 'posts_where'), 10, 2); |
|
100 | - add_filter('posts_orderby', array('EEH_Event_Query', 'posts_orderby'), 10, 2); |
|
101 | - add_filter('posts_clauses_request', array('EEH_Event_Query', 'posts_clauses'), 10, 2); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @param string $month |
|
109 | - * @param string $category |
|
110 | - * @param bool $show_expired |
|
111 | - * @param string $orderby |
|
112 | - * @param string $sort |
|
113 | - * @throws InvalidArgumentException |
|
114 | - * @throws InvalidDataTypeException |
|
115 | - * @throws InvalidInterfaceException |
|
116 | - */ |
|
117 | - public static function set_query_params( |
|
118 | - $month = '', |
|
119 | - $category = '', |
|
120 | - $show_expired = false, |
|
121 | - $orderby = 'start_date', |
|
122 | - $sort = 'ASC' |
|
123 | - ) { |
|
124 | - self::$_query_params = array(); |
|
125 | - EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month($month); |
|
126 | - EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug($category); |
|
127 | - EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired($show_expired); |
|
128 | - EEH_Event_Query::$_event_query_orderby = EEH_Event_Query::_orderby($orderby); |
|
129 | - EEH_Event_Query::$_event_query_sort = EEH_Event_Query::_sort($sort); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * what month should the event list display events for? |
|
136 | - * |
|
137 | - * @param string $month |
|
138 | - * @return string |
|
139 | - * @throws InvalidArgumentException |
|
140 | - * @throws InvalidDataTypeException |
|
141 | - * @throws InvalidInterfaceException |
|
142 | - */ |
|
143 | - private static function _display_month($month = '') |
|
144 | - { |
|
145 | - return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month)); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @param string $category |
|
152 | - * @return string |
|
153 | - * @throws InvalidArgumentException |
|
154 | - * @throws InvalidDataTypeException |
|
155 | - * @throws InvalidInterfaceException |
|
156 | - */ |
|
157 | - private static function _event_category_slug($category = '') |
|
158 | - { |
|
159 | - return sanitize_title_with_dashes(EE_Registry::instance()->REQ->get('event_query_category', $category)); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * @param bool $show_expired |
|
166 | - * @return bool |
|
167 | - * @throws InvalidArgumentException |
|
168 | - * @throws InvalidDataTypeException |
|
169 | - * @throws InvalidInterfaceException |
|
170 | - */ |
|
171 | - private static function _show_expired($show_expired = false) |
|
172 | - { |
|
173 | - // override default expired option if set via filter |
|
174 | - return filter_var( |
|
175 | - EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired), |
|
176 | - FILTER_VALIDATE_BOOLEAN |
|
177 | - ); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @param string $orderby |
|
184 | - * @return array |
|
185 | - * @throws InvalidArgumentException |
|
186 | - * @throws InvalidDataTypeException |
|
187 | - * @throws InvalidInterfaceException |
|
188 | - */ |
|
189 | - private static function _orderby($orderby = 'start_date') |
|
190 | - { |
|
191 | - $event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby); |
|
192 | - $event_query_orderby = is_array($event_query_orderby) |
|
193 | - ? $event_query_orderby |
|
194 | - : explode(',', $event_query_orderby); |
|
195 | - $event_query_orderby = array_map('trim', $event_query_orderby); |
|
196 | - $event_query_orderby = array_map('sanitize_text_field', $event_query_orderby); |
|
197 | - return $event_query_orderby; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @param string $sort |
|
204 | - * @return string |
|
205 | - * @throws InvalidArgumentException |
|
206 | - * @throws InvalidDataTypeException |
|
207 | - * @throws InvalidInterfaceException |
|
208 | - */ |
|
209 | - private static function _sort($sort = 'ASC') |
|
210 | - { |
|
211 | - $sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort); |
|
212 | - return in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true) |
|
213 | - ? strtoupper($sort) |
|
214 | - : 'ASC'; |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - |
|
219 | - /** |
|
220 | - * Filters the clauses for the WP_Query object |
|
221 | - * |
|
222 | - * @param array $clauses array of clauses |
|
223 | - * @param WP_Query $wp_query |
|
224 | - * @return array array of clauses |
|
225 | - */ |
|
226 | - public static function posts_clauses($clauses, WP_Query $wp_query) |
|
227 | - { |
|
228 | - if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
229 | - global $wpdb; |
|
230 | - $clauses['groupby'] = $wpdb->posts . '.ID '; |
|
231 | - } |
|
232 | - return $clauses; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @param string $SQL |
|
239 | - * @param WP_Query $wp_query |
|
240 | - * @return string |
|
241 | - * @throws EE_Error |
|
242 | - * @throws InvalidArgumentException |
|
243 | - * @throws InvalidDataTypeException |
|
244 | - * @throws InvalidInterfaceException |
|
245 | - */ |
|
246 | - public static function posts_fields($SQL, WP_Query $wp_query) |
|
247 | - { |
|
248 | - if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
249 | - // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement |
|
250 | - $SQL .= EEH_Event_Query::posts_fields_sql_for_orderby(EEH_Event_Query::$_event_query_orderby); |
|
251 | - } |
|
252 | - return $SQL; |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * @param array $orderby_params |
|
259 | - * @return string |
|
260 | - * @throws EE_Error |
|
261 | - * @throws InvalidArgumentException |
|
262 | - * @throws InvalidDataTypeException |
|
263 | - * @throws InvalidInterfaceException |
|
264 | - */ |
|
265 | - public static function posts_fields_sql_for_orderby(array $orderby_params = array()) |
|
266 | - { |
|
267 | - $SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date '; |
|
268 | - foreach ($orderby_params as $orderby) { |
|
269 | - switch ($orderby) { |
|
270 | - case 'ticket_start': |
|
271 | - $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date'; |
|
272 | - break; |
|
273 | - case 'ticket_end': |
|
274 | - $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date'; |
|
275 | - break; |
|
276 | - case 'venue_title': |
|
277 | - $SQL .= ', Venue.post_title AS venue_title'; |
|
278 | - break; |
|
279 | - case 'city': |
|
280 | - $SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city'; |
|
281 | - break; |
|
282 | - case 'state': |
|
283 | - $SQL .= ', ' . EEM_State::instance()->table() . '.STA_name'; |
|
284 | - break; |
|
285 | - } |
|
286 | - } |
|
287 | - return $SQL; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * @param string $SQL |
|
294 | - * @param WP_Query $wp_query |
|
295 | - * @return string |
|
296 | - * @throws EE_Error |
|
297 | - * @throws InvalidArgumentException |
|
298 | - * @throws InvalidDataTypeException |
|
299 | - * @throws InvalidInterfaceException |
|
300 | - */ |
|
301 | - public static function posts_join($SQL = '', WP_Query $wp_query) |
|
302 | - { |
|
303 | - if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
304 | - // Category |
|
305 | - $SQL = EEH_Event_Query::posts_join_sql_for_show_expired($SQL, EEH_Event_Query::$_event_query_show_expired); |
|
306 | - $SQL = EEH_Event_Query::posts_join_sql_for_terms($SQL, EEH_Event_Query::$_event_query_category); |
|
307 | - $SQL = EEH_Event_Query::posts_join_for_orderby($SQL, EEH_Event_Query::$_event_query_orderby); |
|
308 | - } |
|
309 | - return $SQL; |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * @param string $SQL |
|
316 | - * @param boolean $show_expired if TRUE, then displayed past events |
|
317 | - * @return string |
|
318 | - * @throws EE_Error |
|
319 | - * @throws InvalidArgumentException |
|
320 | - * @throws InvalidDataTypeException |
|
321 | - * @throws InvalidInterfaceException |
|
322 | - */ |
|
323 | - public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = false) |
|
324 | - { |
|
325 | - if (! $show_expired) { |
|
326 | - $join = EEM_Event::instance()->table() . '.ID = '; |
|
327 | - $join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
328 | - // don't add if this is already in the SQL |
|
329 | - if (strpos($SQL, $join) === false) { |
|
330 | - $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) '; |
|
331 | - } |
|
332 | - } |
|
333 | - return $SQL; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * @param string $SQL |
|
340 | - * @param string $join_terms pass TRUE or term string, doesn't really matter since this value doesn't really get |
|
341 | - * used for anything yet |
|
342 | - * @return string |
|
343 | - */ |
|
344 | - public static function posts_join_sql_for_terms($SQL = '', $join_terms = '') |
|
345 | - { |
|
346 | - if (! empty($join_terms)) { |
|
347 | - global $wpdb; |
|
348 | - $SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)"; |
|
349 | - $SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"; |
|
350 | - $SQL .= " LEFT JOIN $wpdb->terms ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id) "; |
|
351 | - } |
|
352 | - return $SQL; |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * usage: $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params ); |
|
359 | - * |
|
360 | - * @param string $SQL |
|
361 | - * @param array $orderby_params |
|
362 | - * @return string |
|
363 | - * @throws EE_Error |
|
364 | - * @throws InvalidArgumentException |
|
365 | - * @throws InvalidDataTypeException |
|
366 | - * @throws InvalidInterfaceException |
|
367 | - */ |
|
368 | - public static function posts_join_for_orderby($SQL = '', array $orderby_params = array()) |
|
369 | - { |
|
370 | - foreach ($orderby_params as $orderby) { |
|
371 | - switch ($orderby) { |
|
372 | - case 'ticket_start': |
|
373 | - case 'ticket_end': |
|
374 | - $SQL .= EEH_Event_Query::_posts_join_for_datetime( |
|
375 | - $SQL, |
|
376 | - EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() |
|
377 | - ); |
|
378 | - $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table(); |
|
379 | - $SQL .= ' ON ('; |
|
380 | - $SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
381 | - $SQL .= ' = '; |
|
382 | - $SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
383 | - $SQL .= ' )'; |
|
384 | - break; |
|
385 | - case 'venue_title': |
|
386 | - case 'city': |
|
387 | - $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL); |
|
388 | - break; |
|
389 | - case 'state': |
|
390 | - $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL); |
|
391 | - $SQL .= EEH_Event_Query::_posts_join_for_venue_state($SQL); |
|
392 | - break; |
|
393 | - case 'start_date': |
|
394 | - default: |
|
395 | - $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table() . '.ID'); |
|
396 | - break; |
|
397 | - } |
|
398 | - } |
|
399 | - return $SQL; |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * @param string $SQL |
|
406 | - * @param string $join |
|
407 | - * @return string |
|
408 | - * @throws EE_Error |
|
409 | - * @throws InvalidArgumentException |
|
410 | - * @throws InvalidDataTypeException |
|
411 | - * @throws InvalidInterfaceException |
|
412 | - */ |
|
413 | - protected static function _posts_join_for_datetime($SQL = '', $join = '') |
|
414 | - { |
|
415 | - if (! empty($join)) { |
|
416 | - $join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
417 | - if (strpos($SQL, $join) === false) { |
|
418 | - return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )'; |
|
419 | - } |
|
420 | - } |
|
421 | - return ''; |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * @param string $SQL |
|
428 | - * @return string |
|
429 | - * @throws EE_Error |
|
430 | - * @throws InvalidArgumentException |
|
431 | - * @throws InvalidDataTypeException |
|
432 | - * @throws InvalidInterfaceException |
|
433 | - */ |
|
434 | - protected static function _posts_join_for_event_venue($SQL = '') |
|
435 | - { |
|
436 | - // Event Venue table name |
|
437 | - $event_venue_table = EEM_Event_Venue::instance()->table(); |
|
438 | - // generate conditions for: Event <=> Event Venue JOIN clause |
|
439 | - $event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = '; |
|
440 | - $event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name(); |
|
441 | - // don't add joins if they have already been added |
|
442 | - if (strpos($SQL, $event_to_event_venue_join) === false) { |
|
443 | - // Venue table name |
|
444 | - $venue_table = EEM_Venue::instance()->table(); |
|
445 | - // Venue table pk |
|
446 | - $venue_table_pk = EEM_Venue::instance()->primary_key_name(); |
|
447 | - // Venue Meta table name |
|
448 | - $venue_meta_table = EEM_Venue::instance()->second_table(); |
|
449 | - // generate JOIN clause for: Event <=> Event Venue |
|
450 | - $venue_SQL = " LEFT JOIN $event_venue_table ON ( $event_to_event_venue_join )"; |
|
451 | - // generate JOIN clause for: Event Venue <=> Venue |
|
452 | - $venue_SQL .= " LEFT JOIN $venue_table as Venue ON ( $event_venue_table.$venue_table_pk = Venue.ID )"; |
|
453 | - // generate JOIN clause for: Venue <=> Venue Meta |
|
454 | - $venue_SQL .= " LEFT JOIN $venue_meta_table ON ( Venue.ID = $venue_meta_table.$venue_table_pk )"; |
|
455 | - unset($event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table); |
|
456 | - return $venue_SQL; |
|
457 | - } |
|
458 | - unset($event_venue_table, $event_to_event_venue_join); |
|
459 | - return ''; |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * @param string $SQL |
|
466 | - * @return string |
|
467 | - * @throws EE_Error |
|
468 | - * @throws InvalidArgumentException |
|
469 | - * @throws InvalidDataTypeException |
|
470 | - * @throws InvalidInterfaceException |
|
471 | - */ |
|
472 | - protected static function _posts_join_for_venue_state($SQL = '') |
|
473 | - { |
|
474 | - // Venue Meta table name |
|
475 | - $venue_meta_table = EEM_Venue::instance()->second_table(); |
|
476 | - // State table name |
|
477 | - $state_table = EEM_State::instance()->table(); |
|
478 | - // State table pk |
|
479 | - $state_table_pk = EEM_State::instance()->primary_key_name(); |
|
480 | - // verify vars |
|
481 | - if ($venue_meta_table && $state_table && $state_table_pk) { |
|
482 | - // like: wp_esp_venue_meta.STA_ID = wp_esp_state.STA_ID |
|
483 | - $join = "$venue_meta_table.$state_table_pk = $state_table.$state_table_pk"; |
|
484 | - // don't add join if it has already been added |
|
485 | - if (strpos($SQL, $join) === false) { |
|
486 | - unset($state_table_pk, $venue_meta_table, $venue_table_pk); |
|
487 | - return " LEFT JOIN $state_table ON ( $join )"; |
|
488 | - } |
|
489 | - } |
|
490 | - unset($join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk); |
|
491 | - return ''; |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - |
|
496 | - /** |
|
497 | - * @param string $SQL |
|
498 | - * @param WP_Query $wp_query |
|
499 | - * @return string |
|
500 | - * @throws EE_Error |
|
501 | - * @throws InvalidArgumentException |
|
502 | - * @throws InvalidDataTypeException |
|
503 | - * @throws InvalidInterfaceException |
|
504 | - */ |
|
505 | - public static function posts_where($SQL = '', WP_Query $wp_query) |
|
506 | - { |
|
507 | - if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
508 | - // Show Expired ? |
|
509 | - $SQL .= EEH_Event_Query::posts_where_sql_for_show_expired(EEH_Event_Query::$_event_query_show_expired); |
|
510 | - // Category |
|
511 | - $SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug(EEH_Event_Query::$_event_query_category); |
|
512 | - // Start Date |
|
513 | - $SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month(EEH_Event_Query::$_event_query_month); |
|
514 | - } |
|
515 | - return $SQL; |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * @param boolean $show_expired if TRUE, then displayed past events |
|
522 | - * @return string |
|
523 | - * @throws EE_Error |
|
524 | - * @throws InvalidArgumentException |
|
525 | - * @throws InvalidDataTypeException |
|
526 | - * @throws InvalidInterfaceException |
|
527 | - */ |
|
528 | - public static function posts_where_sql_for_show_expired($show_expired = false) |
|
529 | - { |
|
530 | - return ! $show_expired |
|
531 | - ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time('mysql', true) . '\' ' |
|
532 | - : ''; |
|
533 | - } |
|
534 | - |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * @param boolean $event_category_slug |
|
539 | - * @return string |
|
540 | - */ |
|
541 | - public static function posts_where_sql_for_event_category_slug($event_category_slug = null) |
|
542 | - { |
|
543 | - global $wpdb; |
|
544 | - return ! empty($event_category_slug) |
|
545 | - ? $wpdb->prepare(" AND {$wpdb->terms}.slug = %s ", $event_category_slug) |
|
546 | - : ''; |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * @param boolean $month |
|
553 | - * @return string |
|
554 | - * @throws EE_Error |
|
555 | - * @throws InvalidArgumentException |
|
556 | - * @throws InvalidDataTypeException |
|
557 | - * @throws InvalidInterfaceException |
|
558 | - */ |
|
559 | - public static function posts_where_sql_for_event_list_month($month = null) |
|
560 | - { |
|
561 | - $SQL = ''; |
|
562 | - if (! empty($month)) { |
|
563 | - $datetime_table = EEM_Datetime::instance()->table(); |
|
564 | - // event start date is LESS than the end of the month ( so nothing that doesn't start until next month ) |
|
565 | - $SQL = " AND {$datetime_table}.DTT_EVT_start <= '"; |
|
566 | - $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'"; |
|
567 | - // event end date is GREATER than the start of the month ( so nothing that ended before this month ) |
|
568 | - $SQL .= " AND {$datetime_table}.DTT_EVT_end >= '"; |
|
569 | - $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' "; |
|
570 | - } |
|
571 | - return $SQL; |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - |
|
576 | - /** |
|
577 | - * @param string $SQL |
|
578 | - * @param WP_Query $wp_query |
|
579 | - * @return string |
|
580 | - * @throws EE_Error |
|
581 | - * @throws InvalidArgumentException |
|
582 | - * @throws InvalidDataTypeException |
|
583 | - * @throws InvalidInterfaceException |
|
584 | - */ |
|
585 | - public static function posts_orderby($SQL = '', WP_Query $wp_query) |
|
586 | - { |
|
587 | - if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
588 | - $SQL = EEH_Event_Query::posts_orderby_sql( |
|
589 | - EEH_Event_Query::$_event_query_orderby, |
|
590 | - EEH_Event_Query::$_event_query_sort |
|
591 | - ); |
|
592 | - } |
|
593 | - return $SQL; |
|
594 | - } |
|
595 | - |
|
596 | - |
|
597 | - |
|
598 | - /** |
|
599 | - * posts_orderby_sql |
|
600 | - * possible parameters: |
|
601 | - * ID |
|
602 | - * start_date |
|
603 | - * end_date |
|
604 | - * event_name |
|
605 | - * category_slug |
|
606 | - * ticket_start |
|
607 | - * ticket_end |
|
608 | - * venue_title |
|
609 | - * city |
|
610 | - * state |
|
611 | - * **IMPORTANT** |
|
612 | - * make sure to also send the $orderby_params array to the posts_join_for_orderby() method |
|
613 | - * or else some of the table references below will result in MySQL errors |
|
614 | - * |
|
615 | - * @param array $orderby_params |
|
616 | - * @param string $sort |
|
617 | - * @return string |
|
618 | - * @throws EE_Error |
|
619 | - * @throws InvalidArgumentException |
|
620 | - * @throws InvalidDataTypeException |
|
621 | - * @throws InvalidInterfaceException |
|
622 | - */ |
|
623 | - public static function posts_orderby_sql(array $orderby_params = array(), $sort = 'ASC') |
|
624 | - { |
|
625 | - global $wpdb; |
|
626 | - $SQL = ''; |
|
627 | - $counter = 0; |
|
628 | - $sort = in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true) |
|
629 | - ? strtoupper($sort) |
|
630 | - : 'ASC'; |
|
631 | - // make sure 'orderby' is set in query params |
|
632 | - if (! isset(self::$_query_params['orderby'])) { |
|
633 | - self::$_query_params['orderby'] = array(); |
|
634 | - } |
|
635 | - // loop thru $orderby_params (type cast as array) |
|
636 | - foreach ($orderby_params as $orderby) { |
|
637 | - // check if we have already added this param |
|
638 | - if (isset(self::$_query_params['orderby'][ $orderby ])) { |
|
639 | - // if so then remove from the $orderby_params so that the count() method below is accurate |
|
640 | - unset($orderby_params[ $orderby ]); |
|
641 | - // then bump ahead to the next param |
|
642 | - continue; |
|
643 | - } |
|
644 | - // this will ad a comma depending on whether this is the first or last param |
|
645 | - $glue = $counter === 0 || $counter === count($orderby_params) ? ' ' : ', '; |
|
646 | - // ok what's we dealing with? |
|
647 | - switch ($orderby) { |
|
648 | - case 'id': |
|
649 | - case 'ID': |
|
650 | - $SQL .= $glue . $wpdb->posts . '.ID ' . $sort; |
|
651 | - break; |
|
652 | - case 'end_date': |
|
653 | - $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort; |
|
654 | - break; |
|
655 | - case 'event_name': |
|
656 | - $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort; |
|
657 | - break; |
|
658 | - case 'category_slug': |
|
659 | - $SQL .= $glue . $wpdb->terms . '.slug ' . $sort; |
|
660 | - break; |
|
661 | - case 'ticket_start': |
|
662 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort; |
|
663 | - break; |
|
664 | - case 'ticket_end': |
|
665 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort; |
|
666 | - break; |
|
667 | - case 'venue_title': |
|
668 | - $SQL .= $glue . 'venue_title ' . $sort; |
|
669 | - break; |
|
670 | - case 'city': |
|
671 | - $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort; |
|
672 | - break; |
|
673 | - case 'state': |
|
674 | - $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort; |
|
675 | - break; |
|
676 | - case 'start_date': |
|
677 | - default: |
|
678 | - $SQL .= $glue . ' event_start_date ' . $sort; |
|
679 | - break; |
|
680 | - } |
|
681 | - // add to array of orderby params that have been added |
|
682 | - self::$_query_params['orderby'][ $orderby ] = true; |
|
683 | - $counter++; |
|
684 | - } |
|
685 | - return $SQL; |
|
686 | - } |
|
18 | + /** |
|
19 | + * Start Date |
|
20 | + * |
|
21 | + * @var $_event_query_month |
|
22 | + */ |
|
23 | + protected static $_event_query_month; |
|
24 | + |
|
25 | + /** |
|
26 | + * Category |
|
27 | + * |
|
28 | + * @var $_event_query_category |
|
29 | + */ |
|
30 | + protected static $_event_query_category; |
|
31 | + |
|
32 | + /** |
|
33 | + * whether to display expired events in the event list |
|
34 | + * |
|
35 | + * @var bool $_show_expired |
|
36 | + */ |
|
37 | + protected static $_event_query_show_expired = false; |
|
38 | + |
|
39 | + /** |
|
40 | + * list of params for controlling how the query results are ordered |
|
41 | + * |
|
42 | + * @var array $_event_query_orderby |
|
43 | + */ |
|
44 | + protected static $_event_query_orderby = array(); |
|
45 | + |
|
46 | + /** |
|
47 | + * direction list is sorted |
|
48 | + * |
|
49 | + * @var string $_event_query_sort |
|
50 | + */ |
|
51 | + protected static $_event_query_sort; |
|
52 | + |
|
53 | + /** |
|
54 | + * list of params used to build the query's various clauses |
|
55 | + * |
|
56 | + * @var $_query_params |
|
57 | + */ |
|
58 | + protected static $_query_params = array(); |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public static function add_query_filters() |
|
66 | + { |
|
67 | + // add query filters |
|
68 | + add_action('pre_get_posts', array('EEH_Event_Query', 'filter_query_parts'), 10, 1); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param WP_Query $WP_Query |
|
75 | + * @return bool |
|
76 | + */ |
|
77 | + public static function apply_query_filters(WP_Query $WP_Query) |
|
78 | + { |
|
79 | + return ( |
|
80 | + isset($WP_Query->query['post_type']) |
|
81 | + && $WP_Query->query['post_type'] === 'espresso_events' |
|
82 | + ) |
|
83 | + || apply_filters('FHEE__EEH_Event_Query__apply_query_filters', false); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @param WP_Query $WP_Query |
|
89 | + */ |
|
90 | + public static function filter_query_parts(WP_Query $WP_Query) |
|
91 | + { |
|
92 | + // ONLY add our filters if this isn't the main wp_query, |
|
93 | + // because if this is the main wp_query we already have |
|
94 | + // our cpt strategies take care of adding things in. |
|
95 | + if ($WP_Query instanceof WP_Query && ! $WP_Query->is_main_query()) { |
|
96 | + // build event list query |
|
97 | + add_filter('posts_fields', array('EEH_Event_Query', 'posts_fields'), 10, 2); |
|
98 | + add_filter('posts_join', array('EEH_Event_Query', 'posts_join'), 10, 2); |
|
99 | + add_filter('posts_where', array('EEH_Event_Query', 'posts_where'), 10, 2); |
|
100 | + add_filter('posts_orderby', array('EEH_Event_Query', 'posts_orderby'), 10, 2); |
|
101 | + add_filter('posts_clauses_request', array('EEH_Event_Query', 'posts_clauses'), 10, 2); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @param string $month |
|
109 | + * @param string $category |
|
110 | + * @param bool $show_expired |
|
111 | + * @param string $orderby |
|
112 | + * @param string $sort |
|
113 | + * @throws InvalidArgumentException |
|
114 | + * @throws InvalidDataTypeException |
|
115 | + * @throws InvalidInterfaceException |
|
116 | + */ |
|
117 | + public static function set_query_params( |
|
118 | + $month = '', |
|
119 | + $category = '', |
|
120 | + $show_expired = false, |
|
121 | + $orderby = 'start_date', |
|
122 | + $sort = 'ASC' |
|
123 | + ) { |
|
124 | + self::$_query_params = array(); |
|
125 | + EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month($month); |
|
126 | + EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug($category); |
|
127 | + EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired($show_expired); |
|
128 | + EEH_Event_Query::$_event_query_orderby = EEH_Event_Query::_orderby($orderby); |
|
129 | + EEH_Event_Query::$_event_query_sort = EEH_Event_Query::_sort($sort); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * what month should the event list display events for? |
|
136 | + * |
|
137 | + * @param string $month |
|
138 | + * @return string |
|
139 | + * @throws InvalidArgumentException |
|
140 | + * @throws InvalidDataTypeException |
|
141 | + * @throws InvalidInterfaceException |
|
142 | + */ |
|
143 | + private static function _display_month($month = '') |
|
144 | + { |
|
145 | + return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month)); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @param string $category |
|
152 | + * @return string |
|
153 | + * @throws InvalidArgumentException |
|
154 | + * @throws InvalidDataTypeException |
|
155 | + * @throws InvalidInterfaceException |
|
156 | + */ |
|
157 | + private static function _event_category_slug($category = '') |
|
158 | + { |
|
159 | + return sanitize_title_with_dashes(EE_Registry::instance()->REQ->get('event_query_category', $category)); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * @param bool $show_expired |
|
166 | + * @return bool |
|
167 | + * @throws InvalidArgumentException |
|
168 | + * @throws InvalidDataTypeException |
|
169 | + * @throws InvalidInterfaceException |
|
170 | + */ |
|
171 | + private static function _show_expired($show_expired = false) |
|
172 | + { |
|
173 | + // override default expired option if set via filter |
|
174 | + return filter_var( |
|
175 | + EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired), |
|
176 | + FILTER_VALIDATE_BOOLEAN |
|
177 | + ); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @param string $orderby |
|
184 | + * @return array |
|
185 | + * @throws InvalidArgumentException |
|
186 | + * @throws InvalidDataTypeException |
|
187 | + * @throws InvalidInterfaceException |
|
188 | + */ |
|
189 | + private static function _orderby($orderby = 'start_date') |
|
190 | + { |
|
191 | + $event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby); |
|
192 | + $event_query_orderby = is_array($event_query_orderby) |
|
193 | + ? $event_query_orderby |
|
194 | + : explode(',', $event_query_orderby); |
|
195 | + $event_query_orderby = array_map('trim', $event_query_orderby); |
|
196 | + $event_query_orderby = array_map('sanitize_text_field', $event_query_orderby); |
|
197 | + return $event_query_orderby; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @param string $sort |
|
204 | + * @return string |
|
205 | + * @throws InvalidArgumentException |
|
206 | + * @throws InvalidDataTypeException |
|
207 | + * @throws InvalidInterfaceException |
|
208 | + */ |
|
209 | + private static function _sort($sort = 'ASC') |
|
210 | + { |
|
211 | + $sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort); |
|
212 | + return in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true) |
|
213 | + ? strtoupper($sort) |
|
214 | + : 'ASC'; |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + |
|
219 | + /** |
|
220 | + * Filters the clauses for the WP_Query object |
|
221 | + * |
|
222 | + * @param array $clauses array of clauses |
|
223 | + * @param WP_Query $wp_query |
|
224 | + * @return array array of clauses |
|
225 | + */ |
|
226 | + public static function posts_clauses($clauses, WP_Query $wp_query) |
|
227 | + { |
|
228 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
229 | + global $wpdb; |
|
230 | + $clauses['groupby'] = $wpdb->posts . '.ID '; |
|
231 | + } |
|
232 | + return $clauses; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @param string $SQL |
|
239 | + * @param WP_Query $wp_query |
|
240 | + * @return string |
|
241 | + * @throws EE_Error |
|
242 | + * @throws InvalidArgumentException |
|
243 | + * @throws InvalidDataTypeException |
|
244 | + * @throws InvalidInterfaceException |
|
245 | + */ |
|
246 | + public static function posts_fields($SQL, WP_Query $wp_query) |
|
247 | + { |
|
248 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
249 | + // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement |
|
250 | + $SQL .= EEH_Event_Query::posts_fields_sql_for_orderby(EEH_Event_Query::$_event_query_orderby); |
|
251 | + } |
|
252 | + return $SQL; |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * @param array $orderby_params |
|
259 | + * @return string |
|
260 | + * @throws EE_Error |
|
261 | + * @throws InvalidArgumentException |
|
262 | + * @throws InvalidDataTypeException |
|
263 | + * @throws InvalidInterfaceException |
|
264 | + */ |
|
265 | + public static function posts_fields_sql_for_orderby(array $orderby_params = array()) |
|
266 | + { |
|
267 | + $SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date '; |
|
268 | + foreach ($orderby_params as $orderby) { |
|
269 | + switch ($orderby) { |
|
270 | + case 'ticket_start': |
|
271 | + $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date'; |
|
272 | + break; |
|
273 | + case 'ticket_end': |
|
274 | + $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date'; |
|
275 | + break; |
|
276 | + case 'venue_title': |
|
277 | + $SQL .= ', Venue.post_title AS venue_title'; |
|
278 | + break; |
|
279 | + case 'city': |
|
280 | + $SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city'; |
|
281 | + break; |
|
282 | + case 'state': |
|
283 | + $SQL .= ', ' . EEM_State::instance()->table() . '.STA_name'; |
|
284 | + break; |
|
285 | + } |
|
286 | + } |
|
287 | + return $SQL; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * @param string $SQL |
|
294 | + * @param WP_Query $wp_query |
|
295 | + * @return string |
|
296 | + * @throws EE_Error |
|
297 | + * @throws InvalidArgumentException |
|
298 | + * @throws InvalidDataTypeException |
|
299 | + * @throws InvalidInterfaceException |
|
300 | + */ |
|
301 | + public static function posts_join($SQL = '', WP_Query $wp_query) |
|
302 | + { |
|
303 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
304 | + // Category |
|
305 | + $SQL = EEH_Event_Query::posts_join_sql_for_show_expired($SQL, EEH_Event_Query::$_event_query_show_expired); |
|
306 | + $SQL = EEH_Event_Query::posts_join_sql_for_terms($SQL, EEH_Event_Query::$_event_query_category); |
|
307 | + $SQL = EEH_Event_Query::posts_join_for_orderby($SQL, EEH_Event_Query::$_event_query_orderby); |
|
308 | + } |
|
309 | + return $SQL; |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * @param string $SQL |
|
316 | + * @param boolean $show_expired if TRUE, then displayed past events |
|
317 | + * @return string |
|
318 | + * @throws EE_Error |
|
319 | + * @throws InvalidArgumentException |
|
320 | + * @throws InvalidDataTypeException |
|
321 | + * @throws InvalidInterfaceException |
|
322 | + */ |
|
323 | + public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = false) |
|
324 | + { |
|
325 | + if (! $show_expired) { |
|
326 | + $join = EEM_Event::instance()->table() . '.ID = '; |
|
327 | + $join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
328 | + // don't add if this is already in the SQL |
|
329 | + if (strpos($SQL, $join) === false) { |
|
330 | + $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) '; |
|
331 | + } |
|
332 | + } |
|
333 | + return $SQL; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * @param string $SQL |
|
340 | + * @param string $join_terms pass TRUE or term string, doesn't really matter since this value doesn't really get |
|
341 | + * used for anything yet |
|
342 | + * @return string |
|
343 | + */ |
|
344 | + public static function posts_join_sql_for_terms($SQL = '', $join_terms = '') |
|
345 | + { |
|
346 | + if (! empty($join_terms)) { |
|
347 | + global $wpdb; |
|
348 | + $SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)"; |
|
349 | + $SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"; |
|
350 | + $SQL .= " LEFT JOIN $wpdb->terms ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id) "; |
|
351 | + } |
|
352 | + return $SQL; |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * usage: $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params ); |
|
359 | + * |
|
360 | + * @param string $SQL |
|
361 | + * @param array $orderby_params |
|
362 | + * @return string |
|
363 | + * @throws EE_Error |
|
364 | + * @throws InvalidArgumentException |
|
365 | + * @throws InvalidDataTypeException |
|
366 | + * @throws InvalidInterfaceException |
|
367 | + */ |
|
368 | + public static function posts_join_for_orderby($SQL = '', array $orderby_params = array()) |
|
369 | + { |
|
370 | + foreach ($orderby_params as $orderby) { |
|
371 | + switch ($orderby) { |
|
372 | + case 'ticket_start': |
|
373 | + case 'ticket_end': |
|
374 | + $SQL .= EEH_Event_Query::_posts_join_for_datetime( |
|
375 | + $SQL, |
|
376 | + EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() |
|
377 | + ); |
|
378 | + $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table(); |
|
379 | + $SQL .= ' ON ('; |
|
380 | + $SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
381 | + $SQL .= ' = '; |
|
382 | + $SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
383 | + $SQL .= ' )'; |
|
384 | + break; |
|
385 | + case 'venue_title': |
|
386 | + case 'city': |
|
387 | + $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL); |
|
388 | + break; |
|
389 | + case 'state': |
|
390 | + $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL); |
|
391 | + $SQL .= EEH_Event_Query::_posts_join_for_venue_state($SQL); |
|
392 | + break; |
|
393 | + case 'start_date': |
|
394 | + default: |
|
395 | + $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table() . '.ID'); |
|
396 | + break; |
|
397 | + } |
|
398 | + } |
|
399 | + return $SQL; |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * @param string $SQL |
|
406 | + * @param string $join |
|
407 | + * @return string |
|
408 | + * @throws EE_Error |
|
409 | + * @throws InvalidArgumentException |
|
410 | + * @throws InvalidDataTypeException |
|
411 | + * @throws InvalidInterfaceException |
|
412 | + */ |
|
413 | + protected static function _posts_join_for_datetime($SQL = '', $join = '') |
|
414 | + { |
|
415 | + if (! empty($join)) { |
|
416 | + $join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
417 | + if (strpos($SQL, $join) === false) { |
|
418 | + return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )'; |
|
419 | + } |
|
420 | + } |
|
421 | + return ''; |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * @param string $SQL |
|
428 | + * @return string |
|
429 | + * @throws EE_Error |
|
430 | + * @throws InvalidArgumentException |
|
431 | + * @throws InvalidDataTypeException |
|
432 | + * @throws InvalidInterfaceException |
|
433 | + */ |
|
434 | + protected static function _posts_join_for_event_venue($SQL = '') |
|
435 | + { |
|
436 | + // Event Venue table name |
|
437 | + $event_venue_table = EEM_Event_Venue::instance()->table(); |
|
438 | + // generate conditions for: Event <=> Event Venue JOIN clause |
|
439 | + $event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = '; |
|
440 | + $event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name(); |
|
441 | + // don't add joins if they have already been added |
|
442 | + if (strpos($SQL, $event_to_event_venue_join) === false) { |
|
443 | + // Venue table name |
|
444 | + $venue_table = EEM_Venue::instance()->table(); |
|
445 | + // Venue table pk |
|
446 | + $venue_table_pk = EEM_Venue::instance()->primary_key_name(); |
|
447 | + // Venue Meta table name |
|
448 | + $venue_meta_table = EEM_Venue::instance()->second_table(); |
|
449 | + // generate JOIN clause for: Event <=> Event Venue |
|
450 | + $venue_SQL = " LEFT JOIN $event_venue_table ON ( $event_to_event_venue_join )"; |
|
451 | + // generate JOIN clause for: Event Venue <=> Venue |
|
452 | + $venue_SQL .= " LEFT JOIN $venue_table as Venue ON ( $event_venue_table.$venue_table_pk = Venue.ID )"; |
|
453 | + // generate JOIN clause for: Venue <=> Venue Meta |
|
454 | + $venue_SQL .= " LEFT JOIN $venue_meta_table ON ( Venue.ID = $venue_meta_table.$venue_table_pk )"; |
|
455 | + unset($event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table); |
|
456 | + return $venue_SQL; |
|
457 | + } |
|
458 | + unset($event_venue_table, $event_to_event_venue_join); |
|
459 | + return ''; |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * @param string $SQL |
|
466 | + * @return string |
|
467 | + * @throws EE_Error |
|
468 | + * @throws InvalidArgumentException |
|
469 | + * @throws InvalidDataTypeException |
|
470 | + * @throws InvalidInterfaceException |
|
471 | + */ |
|
472 | + protected static function _posts_join_for_venue_state($SQL = '') |
|
473 | + { |
|
474 | + // Venue Meta table name |
|
475 | + $venue_meta_table = EEM_Venue::instance()->second_table(); |
|
476 | + // State table name |
|
477 | + $state_table = EEM_State::instance()->table(); |
|
478 | + // State table pk |
|
479 | + $state_table_pk = EEM_State::instance()->primary_key_name(); |
|
480 | + // verify vars |
|
481 | + if ($venue_meta_table && $state_table && $state_table_pk) { |
|
482 | + // like: wp_esp_venue_meta.STA_ID = wp_esp_state.STA_ID |
|
483 | + $join = "$venue_meta_table.$state_table_pk = $state_table.$state_table_pk"; |
|
484 | + // don't add join if it has already been added |
|
485 | + if (strpos($SQL, $join) === false) { |
|
486 | + unset($state_table_pk, $venue_meta_table, $venue_table_pk); |
|
487 | + return " LEFT JOIN $state_table ON ( $join )"; |
|
488 | + } |
|
489 | + } |
|
490 | + unset($join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk); |
|
491 | + return ''; |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + |
|
496 | + /** |
|
497 | + * @param string $SQL |
|
498 | + * @param WP_Query $wp_query |
|
499 | + * @return string |
|
500 | + * @throws EE_Error |
|
501 | + * @throws InvalidArgumentException |
|
502 | + * @throws InvalidDataTypeException |
|
503 | + * @throws InvalidInterfaceException |
|
504 | + */ |
|
505 | + public static function posts_where($SQL = '', WP_Query $wp_query) |
|
506 | + { |
|
507 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
508 | + // Show Expired ? |
|
509 | + $SQL .= EEH_Event_Query::posts_where_sql_for_show_expired(EEH_Event_Query::$_event_query_show_expired); |
|
510 | + // Category |
|
511 | + $SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug(EEH_Event_Query::$_event_query_category); |
|
512 | + // Start Date |
|
513 | + $SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month(EEH_Event_Query::$_event_query_month); |
|
514 | + } |
|
515 | + return $SQL; |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * @param boolean $show_expired if TRUE, then displayed past events |
|
522 | + * @return string |
|
523 | + * @throws EE_Error |
|
524 | + * @throws InvalidArgumentException |
|
525 | + * @throws InvalidDataTypeException |
|
526 | + * @throws InvalidInterfaceException |
|
527 | + */ |
|
528 | + public static function posts_where_sql_for_show_expired($show_expired = false) |
|
529 | + { |
|
530 | + return ! $show_expired |
|
531 | + ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time('mysql', true) . '\' ' |
|
532 | + : ''; |
|
533 | + } |
|
534 | + |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * @param boolean $event_category_slug |
|
539 | + * @return string |
|
540 | + */ |
|
541 | + public static function posts_where_sql_for_event_category_slug($event_category_slug = null) |
|
542 | + { |
|
543 | + global $wpdb; |
|
544 | + return ! empty($event_category_slug) |
|
545 | + ? $wpdb->prepare(" AND {$wpdb->terms}.slug = %s ", $event_category_slug) |
|
546 | + : ''; |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * @param boolean $month |
|
553 | + * @return string |
|
554 | + * @throws EE_Error |
|
555 | + * @throws InvalidArgumentException |
|
556 | + * @throws InvalidDataTypeException |
|
557 | + * @throws InvalidInterfaceException |
|
558 | + */ |
|
559 | + public static function posts_where_sql_for_event_list_month($month = null) |
|
560 | + { |
|
561 | + $SQL = ''; |
|
562 | + if (! empty($month)) { |
|
563 | + $datetime_table = EEM_Datetime::instance()->table(); |
|
564 | + // event start date is LESS than the end of the month ( so nothing that doesn't start until next month ) |
|
565 | + $SQL = " AND {$datetime_table}.DTT_EVT_start <= '"; |
|
566 | + $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'"; |
|
567 | + // event end date is GREATER than the start of the month ( so nothing that ended before this month ) |
|
568 | + $SQL .= " AND {$datetime_table}.DTT_EVT_end >= '"; |
|
569 | + $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' "; |
|
570 | + } |
|
571 | + return $SQL; |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + |
|
576 | + /** |
|
577 | + * @param string $SQL |
|
578 | + * @param WP_Query $wp_query |
|
579 | + * @return string |
|
580 | + * @throws EE_Error |
|
581 | + * @throws InvalidArgumentException |
|
582 | + * @throws InvalidDataTypeException |
|
583 | + * @throws InvalidInterfaceException |
|
584 | + */ |
|
585 | + public static function posts_orderby($SQL = '', WP_Query $wp_query) |
|
586 | + { |
|
587 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
588 | + $SQL = EEH_Event_Query::posts_orderby_sql( |
|
589 | + EEH_Event_Query::$_event_query_orderby, |
|
590 | + EEH_Event_Query::$_event_query_sort |
|
591 | + ); |
|
592 | + } |
|
593 | + return $SQL; |
|
594 | + } |
|
595 | + |
|
596 | + |
|
597 | + |
|
598 | + /** |
|
599 | + * posts_orderby_sql |
|
600 | + * possible parameters: |
|
601 | + * ID |
|
602 | + * start_date |
|
603 | + * end_date |
|
604 | + * event_name |
|
605 | + * category_slug |
|
606 | + * ticket_start |
|
607 | + * ticket_end |
|
608 | + * venue_title |
|
609 | + * city |
|
610 | + * state |
|
611 | + * **IMPORTANT** |
|
612 | + * make sure to also send the $orderby_params array to the posts_join_for_orderby() method |
|
613 | + * or else some of the table references below will result in MySQL errors |
|
614 | + * |
|
615 | + * @param array $orderby_params |
|
616 | + * @param string $sort |
|
617 | + * @return string |
|
618 | + * @throws EE_Error |
|
619 | + * @throws InvalidArgumentException |
|
620 | + * @throws InvalidDataTypeException |
|
621 | + * @throws InvalidInterfaceException |
|
622 | + */ |
|
623 | + public static function posts_orderby_sql(array $orderby_params = array(), $sort = 'ASC') |
|
624 | + { |
|
625 | + global $wpdb; |
|
626 | + $SQL = ''; |
|
627 | + $counter = 0; |
|
628 | + $sort = in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true) |
|
629 | + ? strtoupper($sort) |
|
630 | + : 'ASC'; |
|
631 | + // make sure 'orderby' is set in query params |
|
632 | + if (! isset(self::$_query_params['orderby'])) { |
|
633 | + self::$_query_params['orderby'] = array(); |
|
634 | + } |
|
635 | + // loop thru $orderby_params (type cast as array) |
|
636 | + foreach ($orderby_params as $orderby) { |
|
637 | + // check if we have already added this param |
|
638 | + if (isset(self::$_query_params['orderby'][ $orderby ])) { |
|
639 | + // if so then remove from the $orderby_params so that the count() method below is accurate |
|
640 | + unset($orderby_params[ $orderby ]); |
|
641 | + // then bump ahead to the next param |
|
642 | + continue; |
|
643 | + } |
|
644 | + // this will ad a comma depending on whether this is the first or last param |
|
645 | + $glue = $counter === 0 || $counter === count($orderby_params) ? ' ' : ', '; |
|
646 | + // ok what's we dealing with? |
|
647 | + switch ($orderby) { |
|
648 | + case 'id': |
|
649 | + case 'ID': |
|
650 | + $SQL .= $glue . $wpdb->posts . '.ID ' . $sort; |
|
651 | + break; |
|
652 | + case 'end_date': |
|
653 | + $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort; |
|
654 | + break; |
|
655 | + case 'event_name': |
|
656 | + $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort; |
|
657 | + break; |
|
658 | + case 'category_slug': |
|
659 | + $SQL .= $glue . $wpdb->terms . '.slug ' . $sort; |
|
660 | + break; |
|
661 | + case 'ticket_start': |
|
662 | + $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort; |
|
663 | + break; |
|
664 | + case 'ticket_end': |
|
665 | + $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort; |
|
666 | + break; |
|
667 | + case 'venue_title': |
|
668 | + $SQL .= $glue . 'venue_title ' . $sort; |
|
669 | + break; |
|
670 | + case 'city': |
|
671 | + $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort; |
|
672 | + break; |
|
673 | + case 'state': |
|
674 | + $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort; |
|
675 | + break; |
|
676 | + case 'start_date': |
|
677 | + default: |
|
678 | + $SQL .= $glue . ' event_start_date ' . $sort; |
|
679 | + break; |
|
680 | + } |
|
681 | + // add to array of orderby params that have been added |
|
682 | + self::$_query_params['orderby'][ $orderby ] = true; |
|
683 | + $counter++; |
|
684 | + } |
|
685 | + return $SQL; |
|
686 | + } |
|
687 | 687 | } |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | { |
228 | 228 | if (EEH_Event_Query::apply_query_filters($wp_query)) { |
229 | 229 | global $wpdb; |
230 | - $clauses['groupby'] = $wpdb->posts . '.ID '; |
|
230 | + $clauses['groupby'] = $wpdb->posts.'.ID '; |
|
231 | 231 | } |
232 | 232 | return $clauses; |
233 | 233 | } |
@@ -264,23 +264,23 @@ discard block |
||
264 | 264 | */ |
265 | 265 | public static function posts_fields_sql_for_orderby(array $orderby_params = array()) |
266 | 266 | { |
267 | - $SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date '; |
|
267 | + $SQL = ', MIN( '.EEM_Datetime::instance()->table().'.DTT_EVT_start ) as event_start_date '; |
|
268 | 268 | foreach ($orderby_params as $orderby) { |
269 | 269 | switch ($orderby) { |
270 | 270 | case 'ticket_start': |
271 | - $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date'; |
|
271 | + $SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_start_date'; |
|
272 | 272 | break; |
273 | 273 | case 'ticket_end': |
274 | - $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date'; |
|
274 | + $SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_end_date'; |
|
275 | 275 | break; |
276 | 276 | case 'venue_title': |
277 | 277 | $SQL .= ', Venue.post_title AS venue_title'; |
278 | 278 | break; |
279 | 279 | case 'city': |
280 | - $SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city'; |
|
280 | + $SQL .= ', '.EEM_Venue::instance()->second_table().'.VNU_city'; |
|
281 | 281 | break; |
282 | 282 | case 'state': |
283 | - $SQL .= ', ' . EEM_State::instance()->table() . '.STA_name'; |
|
283 | + $SQL .= ', '.EEM_State::instance()->table().'.STA_name'; |
|
284 | 284 | break; |
285 | 285 | } |
286 | 286 | } |
@@ -322,12 +322,12 @@ discard block |
||
322 | 322 | */ |
323 | 323 | public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = false) |
324 | 324 | { |
325 | - if (! $show_expired) { |
|
326 | - $join = EEM_Event::instance()->table() . '.ID = '; |
|
327 | - $join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
325 | + if ( ! $show_expired) { |
|
326 | + $join = EEM_Event::instance()->table().'.ID = '; |
|
327 | + $join .= EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name(); |
|
328 | 328 | // don't add if this is already in the SQL |
329 | 329 | if (strpos($SQL, $join) === false) { |
330 | - $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) '; |
|
330 | + $SQL .= ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' ) '; |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | return $SQL; |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | */ |
344 | 344 | public static function posts_join_sql_for_terms($SQL = '', $join_terms = '') |
345 | 345 | { |
346 | - if (! empty($join_terms)) { |
|
346 | + if ( ! empty($join_terms)) { |
|
347 | 347 | global $wpdb; |
348 | 348 | $SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)"; |
349 | 349 | $SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"; |
@@ -373,13 +373,13 @@ discard block |
||
373 | 373 | case 'ticket_end': |
374 | 374 | $SQL .= EEH_Event_Query::_posts_join_for_datetime( |
375 | 375 | $SQL, |
376 | - EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() |
|
376 | + EEM_Datetime_Ticket::instance()->table().'.'.EEM_Datetime::instance()->primary_key_name() |
|
377 | 377 | ); |
378 | - $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table(); |
|
378 | + $SQL .= ' LEFT JOIN '.EEM_Ticket::instance()->table(); |
|
379 | 379 | $SQL .= ' ON ('; |
380 | - $SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
380 | + $SQL .= EEM_Datetime_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name(); |
|
381 | 381 | $SQL .= ' = '; |
382 | - $SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
382 | + $SQL .= EEM_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name(); |
|
383 | 383 | $SQL .= ' )'; |
384 | 384 | break; |
385 | 385 | case 'venue_title': |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | break; |
393 | 393 | case 'start_date': |
394 | 394 | default: |
395 | - $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table() . '.ID'); |
|
395 | + $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table().'.ID'); |
|
396 | 396 | break; |
397 | 397 | } |
398 | 398 | } |
@@ -412,10 +412,10 @@ discard block |
||
412 | 412 | */ |
413 | 413 | protected static function _posts_join_for_datetime($SQL = '', $join = '') |
414 | 414 | { |
415 | - if (! empty($join)) { |
|
416 | - $join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
415 | + if ( ! empty($join)) { |
|
416 | + $join .= ' = '.EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name(); |
|
417 | 417 | if (strpos($SQL, $join) === false) { |
418 | - return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )'; |
|
418 | + return ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' )'; |
|
419 | 419 | } |
420 | 420 | } |
421 | 421 | return ''; |
@@ -436,8 +436,8 @@ discard block |
||
436 | 436 | // Event Venue table name |
437 | 437 | $event_venue_table = EEM_Event_Venue::instance()->table(); |
438 | 438 | // generate conditions for: Event <=> Event Venue JOIN clause |
439 | - $event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = '; |
|
440 | - $event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name(); |
|
439 | + $event_to_event_venue_join = EEM_Event::instance()->table().'.ID = '; |
|
440 | + $event_to_event_venue_join .= $event_venue_table.'.'.EEM_Event::instance()->primary_key_name(); |
|
441 | 441 | // don't add joins if they have already been added |
442 | 442 | if (strpos($SQL, $event_to_event_venue_join) === false) { |
443 | 443 | // Venue table name |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | public static function posts_where_sql_for_show_expired($show_expired = false) |
529 | 529 | { |
530 | 530 | return ! $show_expired |
531 | - ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time('mysql', true) . '\' ' |
|
531 | + ? ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end > \''.current_time('mysql', true).'\' ' |
|
532 | 532 | : ''; |
533 | 533 | } |
534 | 534 | |
@@ -559,14 +559,14 @@ discard block |
||
559 | 559 | public static function posts_where_sql_for_event_list_month($month = null) |
560 | 560 | { |
561 | 561 | $SQL = ''; |
562 | - if (! empty($month)) { |
|
562 | + if ( ! empty($month)) { |
|
563 | 563 | $datetime_table = EEM_Datetime::instance()->table(); |
564 | 564 | // event start date is LESS than the end of the month ( so nothing that doesn't start until next month ) |
565 | 565 | $SQL = " AND {$datetime_table}.DTT_EVT_start <= '"; |
566 | - $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'"; |
|
566 | + $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month))."'"; |
|
567 | 567 | // event end date is GREATER than the start of the month ( so nothing that ended before this month ) |
568 | 568 | $SQL .= " AND {$datetime_table}.DTT_EVT_end >= '"; |
569 | - $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' "; |
|
569 | + $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month))."' "; |
|
570 | 570 | } |
571 | 571 | return $SQL; |
572 | 572 | } |
@@ -629,15 +629,15 @@ discard block |
||
629 | 629 | ? strtoupper($sort) |
630 | 630 | : 'ASC'; |
631 | 631 | // make sure 'orderby' is set in query params |
632 | - if (! isset(self::$_query_params['orderby'])) { |
|
632 | + if ( ! isset(self::$_query_params['orderby'])) { |
|
633 | 633 | self::$_query_params['orderby'] = array(); |
634 | 634 | } |
635 | 635 | // loop thru $orderby_params (type cast as array) |
636 | 636 | foreach ($orderby_params as $orderby) { |
637 | 637 | // check if we have already added this param |
638 | - if (isset(self::$_query_params['orderby'][ $orderby ])) { |
|
638 | + if (isset(self::$_query_params['orderby'][$orderby])) { |
|
639 | 639 | // if so then remove from the $orderby_params so that the count() method below is accurate |
640 | - unset($orderby_params[ $orderby ]); |
|
640 | + unset($orderby_params[$orderby]); |
|
641 | 641 | // then bump ahead to the next param |
642 | 642 | continue; |
643 | 643 | } |
@@ -647,39 +647,39 @@ discard block |
||
647 | 647 | switch ($orderby) { |
648 | 648 | case 'id': |
649 | 649 | case 'ID': |
650 | - $SQL .= $glue . $wpdb->posts . '.ID ' . $sort; |
|
650 | + $SQL .= $glue.$wpdb->posts.'.ID '.$sort; |
|
651 | 651 | break; |
652 | 652 | case 'end_date': |
653 | - $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort; |
|
653 | + $SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_end '.$sort; |
|
654 | 654 | break; |
655 | 655 | case 'event_name': |
656 | - $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort; |
|
656 | + $SQL .= $glue.$wpdb->posts.'.post_title '.$sort; |
|
657 | 657 | break; |
658 | 658 | case 'category_slug': |
659 | - $SQL .= $glue . $wpdb->terms . '.slug ' . $sort; |
|
659 | + $SQL .= $glue.$wpdb->terms.'.slug '.$sort; |
|
660 | 660 | break; |
661 | 661 | case 'ticket_start': |
662 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort; |
|
662 | + $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_start_date '.$sort; |
|
663 | 663 | break; |
664 | 664 | case 'ticket_end': |
665 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort; |
|
665 | + $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_end_date '.$sort; |
|
666 | 666 | break; |
667 | 667 | case 'venue_title': |
668 | - $SQL .= $glue . 'venue_title ' . $sort; |
|
668 | + $SQL .= $glue.'venue_title '.$sort; |
|
669 | 669 | break; |
670 | 670 | case 'city': |
671 | - $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort; |
|
671 | + $SQL .= $glue.EEM_Venue::instance()->second_table().'.VNU_city '.$sort; |
|
672 | 672 | break; |
673 | 673 | case 'state': |
674 | - $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort; |
|
674 | + $SQL .= $glue.EEM_State::instance()->table().'.STA_name '.$sort; |
|
675 | 675 | break; |
676 | 676 | case 'start_date': |
677 | 677 | default: |
678 | - $SQL .= $glue . ' event_start_date ' . $sort; |
|
678 | + $SQL .= $glue.' event_start_date '.$sort; |
|
679 | 679 | break; |
680 | 680 | } |
681 | 681 | // add to array of orderby params that have been added |
682 | - self::$_query_params['orderby'][ $orderby ] = true; |
|
682 | + self::$_query_params['orderby'][$orderby] = true; |
|
683 | 683 | $counter++; |
684 | 684 | } |
685 | 685 | return $SQL; |
@@ -15,286 +15,286 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * instance of the EE_System object |
|
20 | - * |
|
21 | - * @var $_instance |
|
22 | - * @access private |
|
23 | - */ |
|
24 | - private static $_instance = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * $_autoloaders |
|
28 | - * @var array $_autoloaders |
|
29 | - * @access private |
|
30 | - */ |
|
31 | - private static $_autoloaders; |
|
32 | - |
|
33 | - /** |
|
34 | - * set to "paths" to display autoloader class => path mappings |
|
35 | - * set to "times" to display autoloader loading times |
|
36 | - * set to "all" to display both |
|
37 | - * |
|
38 | - * @var string $debug |
|
39 | - * @access private |
|
40 | - */ |
|
41 | - public static $debug = false; |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * class constructor |
|
47 | - * |
|
48 | - * @access private |
|
49 | - * @return \EEH_Autoloader |
|
50 | - */ |
|
51 | - private function __construct() |
|
52 | - { |
|
53 | - if (self::$_autoloaders === null) { |
|
54 | - self::$_autoloaders = array(); |
|
55 | - $this->_register_custom_autoloaders(); |
|
56 | - spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @access public |
|
64 | - * @return EEH_Autoloader |
|
65 | - */ |
|
66 | - public static function instance() |
|
67 | - { |
|
68 | - // check if class object is instantiated |
|
69 | - if (! self::$_instance instanceof EEH_Autoloader) { |
|
70 | - self::$_instance = new self(); |
|
71 | - } |
|
72 | - return self::$_instance; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * espresso_autoloader |
|
79 | - * |
|
80 | - * @access public |
|
81 | - * @param $class_name |
|
82 | - * @internal param $className |
|
83 | - * @internal param string $class_name - simple class name ie: session |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public static function espresso_autoloader($class_name) |
|
87 | - { |
|
88 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
89 | - require_once(self::$_autoloaders[ $class_name ]); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * register_autoloader |
|
97 | - * |
|
98 | - * @access public |
|
99 | - * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
100 | - * @param bool $read_check true if we need to check whether the file is readable or not. |
|
101 | - * @param bool $debug **deprecated** |
|
102 | - * @throws \EE_Error |
|
103 | - */ |
|
104 | - public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
|
105 | - { |
|
106 | - $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
107 | - foreach ($class_paths as $class => $path) { |
|
108 | - // don't give up! you gotta... |
|
109 | - // get some class |
|
110 | - if (empty($class)) { |
|
111 | - throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path)); |
|
112 | - } |
|
113 | - // one day you will find the path young grasshopper |
|
114 | - if (empty($path)) { |
|
115 | - throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class)); |
|
116 | - } |
|
117 | - // is file readable ? |
|
118 | - if ($read_check && ! is_readable($path)) { |
|
119 | - throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
|
120 | - } |
|
121 | - if (! isset(self::$_autoloaders[ $class ])) { |
|
122 | - self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), DS, $path); |
|
123 | - if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
124 | - EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * get_autoloaders |
|
135 | - * |
|
136 | - * @access public |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - public static function get_autoloaders() |
|
140 | - { |
|
141 | - return self::$_autoloaders; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * register core, model and class 'autoloaders' |
|
149 | - * |
|
150 | - * @access private |
|
151 | - * @return void |
|
152 | - */ |
|
153 | - private function _register_custom_autoloaders() |
|
154 | - { |
|
155 | - EEH_Autoloader::$debug = ''; |
|
156 | - \EEH_Autoloader::register_helpers_autoloaders(); |
|
157 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
158 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
159 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
160 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
161 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
162 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
163 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
164 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
165 | - EEH_Debug_Tools::instance()->show_times(); |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * register core, model and class 'autoloaders' |
|
173 | - * |
|
174 | - * @access public |
|
175 | - */ |
|
176 | - public static function register_helpers_autoloaders() |
|
177 | - { |
|
178 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * register core, model and class 'autoloaders' |
|
186 | - * |
|
187 | - * @access public |
|
188 | - * @return void |
|
189 | - */ |
|
190 | - public static function register_form_sections_autoloaders() |
|
191 | - { |
|
192 | - // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * register core, model and class 'autoloaders' |
|
200 | - * |
|
201 | - * @access public |
|
202 | - * @return void |
|
203 | - */ |
|
204 | - public static function register_line_item_display_autoloaders() |
|
205 | - { |
|
206 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * register core, model and class 'autoloaders' |
|
214 | - * |
|
215 | - * @access public |
|
216 | - * @return void |
|
217 | - */ |
|
218 | - public static function register_line_item_filter_autoloaders() |
|
219 | - { |
|
220 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * register template part 'autoloaders' |
|
228 | - * |
|
229 | - * @access public |
|
230 | - * @return void |
|
231 | - */ |
|
232 | - public static function register_template_part_autoloaders() |
|
233 | - { |
|
234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
241 | - * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
242 | - * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly. |
|
243 | - * Yes this has to scan the directory for files, but it only does it once -- not on EACH |
|
244 | - * time the autoloader is used |
|
245 | - * |
|
246 | - * @param string $folder name, with or without trailing /, doesn't matter |
|
247 | - * @param bool $recursive |
|
248 | - * @param bool $debug **deprecated** |
|
249 | - * @throws \EE_Error |
|
250 | - */ |
|
251 | - public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false) |
|
252 | - { |
|
253 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
254 | - EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
|
255 | - } |
|
256 | - // make sure last char is a / |
|
257 | - $folder .= $folder[ strlen($folder)-1 ] !== DS ? DS : ''; |
|
258 | - $class_to_filepath_map = array(); |
|
259 | - $exclude = array( 'index' ); |
|
260 | - // get all the files in that folder that end in php |
|
261 | - $filepaths = glob($folder.'*'); |
|
262 | - |
|
263 | - if (empty($filepaths)) { |
|
264 | - return; |
|
265 | - } |
|
266 | - |
|
267 | - foreach ($filepaths as $filepath) { |
|
268 | - if (substr($filepath, -4, 4) === '.php') { |
|
269 | - $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
270 | - if (! in_array($class_name, $exclude)) { |
|
271 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
272 | - } |
|
273 | - } elseif ($recursive) { |
|
274 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
275 | - } |
|
276 | - } |
|
277 | - // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
278 | - self::register_autoloader($class_to_filepath_map, false, $debug); |
|
279 | - if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
280 | - EEH_Debug_Tools::instance()->stop_timer(basename($folder)); |
|
281 | - } |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * add_alias |
|
288 | - * register additional autoloader based on variation of the classname for an existing autoloader |
|
289 | - * |
|
290 | - * @access public |
|
291 | - * @param string $class_name - simple class name ie: EE_Session |
|
292 | - * @param string $alias - variation on class name ie: EE_session, session, etc |
|
293 | - */ |
|
294 | - public static function add_alias($class_name, $alias) |
|
295 | - { |
|
296 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
297 | - self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
298 | - } |
|
299 | - } |
|
18 | + /** |
|
19 | + * instance of the EE_System object |
|
20 | + * |
|
21 | + * @var $_instance |
|
22 | + * @access private |
|
23 | + */ |
|
24 | + private static $_instance = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * $_autoloaders |
|
28 | + * @var array $_autoloaders |
|
29 | + * @access private |
|
30 | + */ |
|
31 | + private static $_autoloaders; |
|
32 | + |
|
33 | + /** |
|
34 | + * set to "paths" to display autoloader class => path mappings |
|
35 | + * set to "times" to display autoloader loading times |
|
36 | + * set to "all" to display both |
|
37 | + * |
|
38 | + * @var string $debug |
|
39 | + * @access private |
|
40 | + */ |
|
41 | + public static $debug = false; |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * class constructor |
|
47 | + * |
|
48 | + * @access private |
|
49 | + * @return \EEH_Autoloader |
|
50 | + */ |
|
51 | + private function __construct() |
|
52 | + { |
|
53 | + if (self::$_autoloaders === null) { |
|
54 | + self::$_autoloaders = array(); |
|
55 | + $this->_register_custom_autoloaders(); |
|
56 | + spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @access public |
|
64 | + * @return EEH_Autoloader |
|
65 | + */ |
|
66 | + public static function instance() |
|
67 | + { |
|
68 | + // check if class object is instantiated |
|
69 | + if (! self::$_instance instanceof EEH_Autoloader) { |
|
70 | + self::$_instance = new self(); |
|
71 | + } |
|
72 | + return self::$_instance; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * espresso_autoloader |
|
79 | + * |
|
80 | + * @access public |
|
81 | + * @param $class_name |
|
82 | + * @internal param $className |
|
83 | + * @internal param string $class_name - simple class name ie: session |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public static function espresso_autoloader($class_name) |
|
87 | + { |
|
88 | + if (isset(self::$_autoloaders[ $class_name ])) { |
|
89 | + require_once(self::$_autoloaders[ $class_name ]); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * register_autoloader |
|
97 | + * |
|
98 | + * @access public |
|
99 | + * @param array | string $class_paths - array of key => value pairings between class names and paths |
|
100 | + * @param bool $read_check true if we need to check whether the file is readable or not. |
|
101 | + * @param bool $debug **deprecated** |
|
102 | + * @throws \EE_Error |
|
103 | + */ |
|
104 | + public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
|
105 | + { |
|
106 | + $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
107 | + foreach ($class_paths as $class => $path) { |
|
108 | + // don't give up! you gotta... |
|
109 | + // get some class |
|
110 | + if (empty($class)) { |
|
111 | + throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path)); |
|
112 | + } |
|
113 | + // one day you will find the path young grasshopper |
|
114 | + if (empty($path)) { |
|
115 | + throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class)); |
|
116 | + } |
|
117 | + // is file readable ? |
|
118 | + if ($read_check && ! is_readable($path)) { |
|
119 | + throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
|
120 | + } |
|
121 | + if (! isset(self::$_autoloaders[ $class ])) { |
|
122 | + self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), DS, $path); |
|
123 | + if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
124 | + EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * get_autoloaders |
|
135 | + * |
|
136 | + * @access public |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + public static function get_autoloaders() |
|
140 | + { |
|
141 | + return self::$_autoloaders; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * register core, model and class 'autoloaders' |
|
149 | + * |
|
150 | + * @access private |
|
151 | + * @return void |
|
152 | + */ |
|
153 | + private function _register_custom_autoloaders() |
|
154 | + { |
|
155 | + EEH_Autoloader::$debug = ''; |
|
156 | + \EEH_Autoloader::register_helpers_autoloaders(); |
|
157 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
158 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
|
159 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
|
160 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
|
161 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
|
162 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
|
163 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
164 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
165 | + EEH_Debug_Tools::instance()->show_times(); |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * register core, model and class 'autoloaders' |
|
173 | + * |
|
174 | + * @access public |
|
175 | + */ |
|
176 | + public static function register_helpers_autoloaders() |
|
177 | + { |
|
178 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * register core, model and class 'autoloaders' |
|
186 | + * |
|
187 | + * @access public |
|
188 | + * @return void |
|
189 | + */ |
|
190 | + public static function register_form_sections_autoloaders() |
|
191 | + { |
|
192 | + // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true ); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * register core, model and class 'autoloaders' |
|
200 | + * |
|
201 | + * @access public |
|
202 | + * @return void |
|
203 | + */ |
|
204 | + public static function register_line_item_display_autoloaders() |
|
205 | + { |
|
206 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * register core, model and class 'autoloaders' |
|
214 | + * |
|
215 | + * @access public |
|
216 | + * @return void |
|
217 | + */ |
|
218 | + public static function register_line_item_filter_autoloaders() |
|
219 | + { |
|
220 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * register template part 'autoloaders' |
|
228 | + * |
|
229 | + * @access public |
|
230 | + * @return void |
|
231 | + */ |
|
232 | + public static function register_template_part_autoloaders() |
|
233 | + { |
|
234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Assumes all the files in this folder have the normal naming scheme (namely that their classname |
|
241 | + * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. |
|
242 | + * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly. |
|
243 | + * Yes this has to scan the directory for files, but it only does it once -- not on EACH |
|
244 | + * time the autoloader is used |
|
245 | + * |
|
246 | + * @param string $folder name, with or without trailing /, doesn't matter |
|
247 | + * @param bool $recursive |
|
248 | + * @param bool $debug **deprecated** |
|
249 | + * @throws \EE_Error |
|
250 | + */ |
|
251 | + public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false) |
|
252 | + { |
|
253 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { |
|
254 | + EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
|
255 | + } |
|
256 | + // make sure last char is a / |
|
257 | + $folder .= $folder[ strlen($folder)-1 ] !== DS ? DS : ''; |
|
258 | + $class_to_filepath_map = array(); |
|
259 | + $exclude = array( 'index' ); |
|
260 | + // get all the files in that folder that end in php |
|
261 | + $filepaths = glob($folder.'*'); |
|
262 | + |
|
263 | + if (empty($filepaths)) { |
|
264 | + return; |
|
265 | + } |
|
266 | + |
|
267 | + foreach ($filepaths as $filepath) { |
|
268 | + if (substr($filepath, -4, 4) === '.php') { |
|
269 | + $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
|
270 | + if (! in_array($class_name, $exclude)) { |
|
271 | + $class_to_filepath_map [ $class_name ] = $filepath; |
|
272 | + } |
|
273 | + } elseif ($recursive) { |
|
274 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
|
275 | + } |
|
276 | + } |
|
277 | + // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. |
|
278 | + self::register_autoloader($class_to_filepath_map, false, $debug); |
|
279 | + if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
|
280 | + EEH_Debug_Tools::instance()->stop_timer(basename($folder)); |
|
281 | + } |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * add_alias |
|
288 | + * register additional autoloader based on variation of the classname for an existing autoloader |
|
289 | + * |
|
290 | + * @access public |
|
291 | + * @param string $class_name - simple class name ie: EE_Session |
|
292 | + * @param string $alias - variation on class name ie: EE_session, session, etc |
|
293 | + */ |
|
294 | + public static function add_alias($class_name, $alias) |
|
295 | + { |
|
296 | + if (isset(self::$_autoloaders[ $class_name ])) { |
|
297 | + self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
298 | + } |
|
299 | + } |
|
300 | 300 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | if (self::$_autoloaders === null) { |
54 | 54 | self::$_autoloaders = array(); |
55 | 55 | $this->_register_custom_autoloaders(); |
56 | - spl_autoload_register(array( $this, 'espresso_autoloader' )); |
|
56 | + spl_autoload_register(array($this, 'espresso_autoloader')); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public static function instance() |
67 | 67 | { |
68 | 68 | // check if class object is instantiated |
69 | - if (! self::$_instance instanceof EEH_Autoloader) { |
|
69 | + if ( ! self::$_instance instanceof EEH_Autoloader) { |
|
70 | 70 | self::$_instance = new self(); |
71 | 71 | } |
72 | 72 | return self::$_instance; |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public static function espresso_autoloader($class_name) |
87 | 87 | { |
88 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
89 | - require_once(self::$_autoloaders[ $class_name ]); |
|
88 | + if (isset(self::$_autoloaders[$class_name])) { |
|
89 | + require_once(self::$_autoloaders[$class_name]); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public static function register_autoloader($class_paths, $read_check = true, $debug = false) |
105 | 105 | { |
106 | - $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths ); |
|
106 | + $class_paths = is_array($class_paths) ? $class_paths : array($class_paths); |
|
107 | 107 | foreach ($class_paths as $class => $path) { |
108 | 108 | // don't give up! you gotta... |
109 | 109 | // get some class |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | if ($read_check && ! is_readable($path)) { |
119 | 119 | throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); |
120 | 120 | } |
121 | - if (! isset(self::$_autoloaders[ $class ])) { |
|
122 | - self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), DS, $path); |
|
123 | - if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) { |
|
124 | - EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__); |
|
121 | + if ( ! isset(self::$_autoloaders[$class])) { |
|
122 | + self::$_autoloaders[$class] = str_replace(array('/', '\\'), DS, $path); |
|
123 | + if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) { |
|
124 | + EEH_Debug_Tools::printr(self::$_autoloaders[$class], $class, __FILE__, __LINE__); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | } |
@@ -154,13 +154,13 @@ discard block |
||
154 | 154 | { |
155 | 155 | EEH_Autoloader::$debug = ''; |
156 | 156 | \EEH_Autoloader::register_helpers_autoloaders(); |
157 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces'); |
|
157 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces'); |
|
158 | 158 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE); |
159 | 159 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true); |
160 | 160 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true); |
161 | 161 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES); |
162 | 162 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true); |
163 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages'); |
|
163 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'messages'); |
|
164 | 164 | if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { |
165 | 165 | EEH_Debug_Tools::instance()->show_times(); |
166 | 166 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | */ |
204 | 204 | public static function register_line_item_display_autoloaders() |
205 | 205 | { |
206 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true); |
|
206 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_display', true); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | */ |
218 | 218 | public static function register_line_item_filter_autoloaders() |
219 | 219 | { |
220 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true); |
|
220 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_filters', true); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | */ |
232 | 232 | public static function register_template_part_autoloaders() |
233 | 233 | { |
234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true); |
|
234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'template_parts', true); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | EEH_Debug_Tools::instance()->start_timer(basename($folder)); |
255 | 255 | } |
256 | 256 | // make sure last char is a / |
257 | - $folder .= $folder[ strlen($folder)-1 ] !== DS ? DS : ''; |
|
257 | + $folder .= $folder[strlen($folder) - 1] !== DS ? DS : ''; |
|
258 | 258 | $class_to_filepath_map = array(); |
259 | - $exclude = array( 'index' ); |
|
259 | + $exclude = array('index'); |
|
260 | 260 | // get all the files in that folder that end in php |
261 | 261 | $filepaths = glob($folder.'*'); |
262 | 262 | |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | foreach ($filepaths as $filepath) { |
268 | 268 | if (substr($filepath, -4, 4) === '.php') { |
269 | 269 | $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); |
270 | - if (! in_array($class_name, $exclude)) { |
|
271 | - $class_to_filepath_map [ $class_name ] = $filepath; |
|
270 | + if ( ! in_array($class_name, $exclude)) { |
|
271 | + $class_to_filepath_map [$class_name] = $filepath; |
|
272 | 272 | } |
273 | 273 | } elseif ($recursive) { |
274 | 274 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); |
@@ -293,8 +293,8 @@ discard block |
||
293 | 293 | */ |
294 | 294 | public static function add_alias($class_name, $alias) |
295 | 295 | { |
296 | - if (isset(self::$_autoloaders[ $class_name ])) { |
|
297 | - self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ]; |
|
296 | + if (isset(self::$_autoloaders[$class_name])) { |
|
297 | + self::$_autoloaders[$alias] = self::$_autoloaders[$class_name]; |
|
298 | 298 | } |
299 | 299 | } |
300 | 300 | } |
@@ -11,131 +11,131 @@ |
||
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 | } |
@@ -29,11 +29,11 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | */ |
@@ -14,152 +14,152 @@ |
||
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 |
@@ -45,7 +45,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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)) { |
@@ -21,202 +21,202 @@ |
||
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 | } |
@@ -36,22 +36,22 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -12,221 +12,221 @@ |
||
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 | } |
@@ -37,7 +37,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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(); |
@@ -12,262 +12,262 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * generates JSON-based linked data for an event |
|
17 | - * |
|
18 | - * @param EE_Event $event |
|
19 | - * @throws EE_Error |
|
20 | - */ |
|
21 | - public static function add_json_linked_data_for_event(EE_Event $event) |
|
22 | - { |
|
23 | - // Check we have a valid datetime for the event |
|
24 | - if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | - return; |
|
26 | - } |
|
27 | - |
|
28 | - $template_args = array( |
|
29 | - 'event_permalink' => '', |
|
30 | - 'event_name' => '', |
|
31 | - 'event_description' => '', |
|
32 | - 'event_start' => '', |
|
33 | - 'event_end' => '', |
|
34 | - 'currency' => '', |
|
35 | - 'event_tickets' => array(), |
|
36 | - 'venue_name' => '', |
|
37 | - 'venue_url' => '', |
|
38 | - 'venue_locality' => '', |
|
39 | - 'venue_region' => '', |
|
40 | - 'event_image' => '', |
|
41 | - ); |
|
42 | - $template_args['event_permalink'] = $event->get_permalink(); |
|
43 | - $template_args['event_name'] = $event->name(); |
|
44 | - $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
45 | - // clone datetime so that date formats don't override those for the original datetime |
|
46 | - $primary_datetime = clone $event->primary_datetime(); |
|
47 | - $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
48 | - $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
49 | - unset($primary_datetime); |
|
50 | - $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
51 | - foreach ($event->tickets() as $original_ticket) { |
|
52 | - // clone tickets so that date formats don't override those for the original ticket |
|
53 | - $ticket= clone $original_ticket; |
|
54 | - $ID = $ticket->ID(); |
|
55 | - $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
56 | - $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
57 | - $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
58 | - $ticket->price(), |
|
59 | - EE_Registry::instance()->CFG->currency->dec_plc, |
|
60 | - EE_Registry::instance()->CFG->currency->dec_mrk, |
|
61 | - EE_Registry::instance()->CFG->currency->thsnds |
|
62 | - ); |
|
63 | - unset($ticket); |
|
64 | - } |
|
65 | - $VNU_ID = espresso_venue_id(); |
|
66 | - if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
67 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
68 | - $template_args['venue_name'] = get_the_title($VNU_ID); |
|
69 | - $template_args['venue_url'] = get_permalink($VNU_ID); |
|
70 | - $template_args['venue_locality'] = $venue->city(); |
|
71 | - $template_args['venue_region'] = $venue->state_name(); |
|
72 | - } |
|
73 | - $template_args['event_image'] = $event->feature_image_url(); |
|
74 | - $template_args = apply_filters( |
|
75 | - 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
76 | - $template_args, |
|
77 | - $event, |
|
78 | - $VNU_ID |
|
79 | - ); |
|
80 | - extract($template_args, EXTR_OVERWRITE); |
|
81 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * location |
|
87 | - * The location of the event, organization or action. |
|
88 | - * Should include the Venue name AND schema formatted address info |
|
89 | - * |
|
90 | - * @access public |
|
91 | - * @param string $location |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public static function location($location = null) |
|
95 | - { |
|
96 | - return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
97 | - . $location |
|
98 | - . '</div>' : ''; |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * name |
|
105 | - * The name of the Event or Venue. |
|
106 | - * |
|
107 | - * @access public |
|
108 | - * @param string $name |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - public static function name($name = null) |
|
112 | - { |
|
113 | - return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * streetAddress |
|
120 | - * The street address. For example, 1600 Amphitheatre Pkwy. |
|
121 | - * |
|
122 | - * @access public |
|
123 | - * @param EEI_Address $obj_with_address |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - public static function streetAddress(EEI_Address $obj_with_address = null) |
|
127 | - { |
|
128 | - return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
|
129 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * postOfficeBoxNumber |
|
136 | - * The post office box number for PO box addresses. |
|
137 | - * |
|
138 | - * @access public |
|
139 | - * @param EEI_Address $obj_with_address |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) |
|
143 | - { |
|
144 | - // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
145 | - if (preg_match( |
|
146 | - "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
147 | - $obj_with_address->address2() |
|
148 | - ) ) { |
|
149 | - return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
|
150 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
151 | - } else { |
|
152 | - return $obj_with_address->address2(); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * addressLocality |
|
160 | - * The locality (city, town, etc). For example, Mountain View. |
|
161 | - * |
|
162 | - * @access public |
|
163 | - * @param EEI_Address $obj_with_address |
|
164 | - * @return string |
|
165 | - */ |
|
166 | - public static function addressLocality(EEI_Address $obj_with_address = null) |
|
167 | - { |
|
168 | - return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
|
169 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * addressRegion |
|
176 | - * The region (state, province, etc). For example, CA. |
|
177 | - * |
|
178 | - * @access public |
|
179 | - * @param EEI_Address $obj_with_address |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public static function addressRegion(EEI_Address $obj_with_address = null) |
|
183 | - { |
|
184 | - $state = $obj_with_address->state_name(); |
|
185 | - if (! empty($state)) { |
|
186 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
187 | - } else { |
|
188 | - return ''; |
|
189 | - } |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * addressCountry |
|
196 | - * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
197 | - * |
|
198 | - * @access public |
|
199 | - * @param EEI_Address $obj_with_address |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public static function addressCountry(EEI_Address $obj_with_address = null) |
|
203 | - { |
|
204 | - $country = $obj_with_address->country_name(); |
|
205 | - if (! empty($country)) { |
|
206 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
207 | - } else { |
|
208 | - return ''; |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * postalCode |
|
216 | - * The postal code. For example, 94043. |
|
217 | - * |
|
218 | - * @access public |
|
219 | - * @param EEI_Address $obj_with_address |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public static function postalCode(EEI_Address $obj_with_address = null) |
|
223 | - { |
|
224 | - return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
|
225 | - . $obj_with_address->zip() |
|
226 | - . '</span>' : ''; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * telephone |
|
233 | - * The telephone number. |
|
234 | - * |
|
235 | - * @access public |
|
236 | - * @param string $phone_nmbr |
|
237 | - * @return string |
|
238 | - */ |
|
239 | - public static function telephone($phone_nmbr = null) |
|
240 | - { |
|
241 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
242 | - : ''; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * URL |
|
249 | - * URL of the item as a clickable link |
|
250 | - * |
|
251 | - * @access public |
|
252 | - * @param string $url - the URL that the link will resolve to |
|
253 | - * @param string $text - the text that will be used for the visible link |
|
254 | - * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
|
255 | - * @return string (link) |
|
256 | - */ |
|
257 | - public static function url($url = null, $text = null, $attributes = array()) |
|
258 | - { |
|
259 | - // Check the URL includes a scheme |
|
260 | - $parsed_url = parse_url($url); |
|
261 | - if (empty($parsed_url['scheme'])) { |
|
262 | - $url = 'http://' . ltrim($url, '/'); |
|
263 | - } |
|
264 | - |
|
265 | - $atts = ''; |
|
266 | - foreach ($attributes as $attribute => $value) { |
|
267 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
268 | - } |
|
269 | - $text = $text !== null && $text !== '' ? $text : $url; |
|
270 | - return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
271 | - : ''; |
|
272 | - } |
|
15 | + /** |
|
16 | + * generates JSON-based linked data for an event |
|
17 | + * |
|
18 | + * @param EE_Event $event |
|
19 | + * @throws EE_Error |
|
20 | + */ |
|
21 | + public static function add_json_linked_data_for_event(EE_Event $event) |
|
22 | + { |
|
23 | + // Check we have a valid datetime for the event |
|
24 | + if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | + return; |
|
26 | + } |
|
27 | + |
|
28 | + $template_args = array( |
|
29 | + 'event_permalink' => '', |
|
30 | + 'event_name' => '', |
|
31 | + 'event_description' => '', |
|
32 | + 'event_start' => '', |
|
33 | + 'event_end' => '', |
|
34 | + 'currency' => '', |
|
35 | + 'event_tickets' => array(), |
|
36 | + 'venue_name' => '', |
|
37 | + 'venue_url' => '', |
|
38 | + 'venue_locality' => '', |
|
39 | + 'venue_region' => '', |
|
40 | + 'event_image' => '', |
|
41 | + ); |
|
42 | + $template_args['event_permalink'] = $event->get_permalink(); |
|
43 | + $template_args['event_name'] = $event->name(); |
|
44 | + $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
45 | + // clone datetime so that date formats don't override those for the original datetime |
|
46 | + $primary_datetime = clone $event->primary_datetime(); |
|
47 | + $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
48 | + $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
49 | + unset($primary_datetime); |
|
50 | + $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
51 | + foreach ($event->tickets() as $original_ticket) { |
|
52 | + // clone tickets so that date formats don't override those for the original ticket |
|
53 | + $ticket= clone $original_ticket; |
|
54 | + $ID = $ticket->ID(); |
|
55 | + $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
56 | + $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
57 | + $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
58 | + $ticket->price(), |
|
59 | + EE_Registry::instance()->CFG->currency->dec_plc, |
|
60 | + EE_Registry::instance()->CFG->currency->dec_mrk, |
|
61 | + EE_Registry::instance()->CFG->currency->thsnds |
|
62 | + ); |
|
63 | + unset($ticket); |
|
64 | + } |
|
65 | + $VNU_ID = espresso_venue_id(); |
|
66 | + if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
67 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
68 | + $template_args['venue_name'] = get_the_title($VNU_ID); |
|
69 | + $template_args['venue_url'] = get_permalink($VNU_ID); |
|
70 | + $template_args['venue_locality'] = $venue->city(); |
|
71 | + $template_args['venue_region'] = $venue->state_name(); |
|
72 | + } |
|
73 | + $template_args['event_image'] = $event->feature_image_url(); |
|
74 | + $template_args = apply_filters( |
|
75 | + 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
76 | + $template_args, |
|
77 | + $event, |
|
78 | + $VNU_ID |
|
79 | + ); |
|
80 | + extract($template_args, EXTR_OVERWRITE); |
|
81 | + include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * location |
|
87 | + * The location of the event, organization or action. |
|
88 | + * Should include the Venue name AND schema formatted address info |
|
89 | + * |
|
90 | + * @access public |
|
91 | + * @param string $location |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public static function location($location = null) |
|
95 | + { |
|
96 | + return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
97 | + . $location |
|
98 | + . '</div>' : ''; |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * name |
|
105 | + * The name of the Event or Venue. |
|
106 | + * |
|
107 | + * @access public |
|
108 | + * @param string $name |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + public static function name($name = null) |
|
112 | + { |
|
113 | + return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * streetAddress |
|
120 | + * The street address. For example, 1600 Amphitheatre Pkwy. |
|
121 | + * |
|
122 | + * @access public |
|
123 | + * @param EEI_Address $obj_with_address |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + public static function streetAddress(EEI_Address $obj_with_address = null) |
|
127 | + { |
|
128 | + return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
|
129 | + ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * postOfficeBoxNumber |
|
136 | + * The post office box number for PO box addresses. |
|
137 | + * |
|
138 | + * @access public |
|
139 | + * @param EEI_Address $obj_with_address |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) |
|
143 | + { |
|
144 | + // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
145 | + if (preg_match( |
|
146 | + "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
147 | + $obj_with_address->address2() |
|
148 | + ) ) { |
|
149 | + return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
|
150 | + ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
151 | + } else { |
|
152 | + return $obj_with_address->address2(); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * addressLocality |
|
160 | + * The locality (city, town, etc). For example, Mountain View. |
|
161 | + * |
|
162 | + * @access public |
|
163 | + * @param EEI_Address $obj_with_address |
|
164 | + * @return string |
|
165 | + */ |
|
166 | + public static function addressLocality(EEI_Address $obj_with_address = null) |
|
167 | + { |
|
168 | + return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
|
169 | + ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * addressRegion |
|
176 | + * The region (state, province, etc). For example, CA. |
|
177 | + * |
|
178 | + * @access public |
|
179 | + * @param EEI_Address $obj_with_address |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public static function addressRegion(EEI_Address $obj_with_address = null) |
|
183 | + { |
|
184 | + $state = $obj_with_address->state_name(); |
|
185 | + if (! empty($state)) { |
|
186 | + return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
187 | + } else { |
|
188 | + return ''; |
|
189 | + } |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * addressCountry |
|
196 | + * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
197 | + * |
|
198 | + * @access public |
|
199 | + * @param EEI_Address $obj_with_address |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public static function addressCountry(EEI_Address $obj_with_address = null) |
|
203 | + { |
|
204 | + $country = $obj_with_address->country_name(); |
|
205 | + if (! empty($country)) { |
|
206 | + return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
207 | + } else { |
|
208 | + return ''; |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * postalCode |
|
216 | + * The postal code. For example, 94043. |
|
217 | + * |
|
218 | + * @access public |
|
219 | + * @param EEI_Address $obj_with_address |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public static function postalCode(EEI_Address $obj_with_address = null) |
|
223 | + { |
|
224 | + return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
|
225 | + . $obj_with_address->zip() |
|
226 | + . '</span>' : ''; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * telephone |
|
233 | + * The telephone number. |
|
234 | + * |
|
235 | + * @access public |
|
236 | + * @param string $phone_nmbr |
|
237 | + * @return string |
|
238 | + */ |
|
239 | + public static function telephone($phone_nmbr = null) |
|
240 | + { |
|
241 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
242 | + : ''; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * URL |
|
249 | + * URL of the item as a clickable link |
|
250 | + * |
|
251 | + * @access public |
|
252 | + * @param string $url - the URL that the link will resolve to |
|
253 | + * @param string $text - the text that will be used for the visible link |
|
254 | + * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
|
255 | + * @return string (link) |
|
256 | + */ |
|
257 | + public static function url($url = null, $text = null, $attributes = array()) |
|
258 | + { |
|
259 | + // Check the URL includes a scheme |
|
260 | + $parsed_url = parse_url($url); |
|
261 | + if (empty($parsed_url['scheme'])) { |
|
262 | + $url = 'http://' . ltrim($url, '/'); |
|
263 | + } |
|
264 | + |
|
265 | + $atts = ''; |
|
266 | + foreach ($attributes as $attribute => $value) { |
|
267 | + $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
268 | + } |
|
269 | + $text = $text !== null && $text !== '' ? $text : $url; |
|
270 | + return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
271 | + : ''; |
|
272 | + } |
|
273 | 273 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | public static function add_json_linked_data_for_event(EE_Event $event) |
22 | 22 | { |
23 | 23 | // Check we have a valid datetime for the event |
24 | - if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
24 | + if ( ! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | 25 | return; |
26 | 26 | } |
27 | 27 | |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
51 | 51 | foreach ($event->tickets() as $original_ticket) { |
52 | 52 | // clone tickets so that date formats don't override those for the original ticket |
53 | - $ticket= clone $original_ticket; |
|
53 | + $ticket = clone $original_ticket; |
|
54 | 54 | $ID = $ticket->ID(); |
55 | - $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
56 | - $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
57 | - $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
55 | + $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
56 | + $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
57 | + $template_args['event_tickets'][$ID]['price'] = number_format( |
|
58 | 58 | $ticket->price(), |
59 | 59 | EE_Registry::instance()->CFG->currency->dec_plc, |
60 | 60 | EE_Registry::instance()->CFG->currency->dec_mrk, |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | unset($ticket); |
64 | 64 | } |
65 | 65 | $VNU_ID = espresso_venue_id(); |
66 | - if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
66 | + if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
67 | 67 | $venue = EEH_Venue_View::get_venue($VNU_ID); |
68 | 68 | $template_args['venue_name'] = get_the_title($VNU_ID); |
69 | 69 | $template_args['venue_url'] = get_permalink($VNU_ID); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $VNU_ID |
79 | 79 | ); |
80 | 80 | extract($template_args, EXTR_OVERWRITE); |
81 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
81 | + include EE_TEMPLATES.'json_linked_data_for_event.template.php'; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public static function name($name = null) |
112 | 112 | { |
113 | - return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
113 | + return ! empty($name) ? '<span itemprop="name">'.$name.'</span>' : ''; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | public static function streetAddress(EEI_Address $obj_with_address = null) |
127 | 127 | { |
128 | 128 | return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
129 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
129 | + ? '<span itemprop="streetAddress">'.$obj_with_address->address().'</span>' : ''; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | if (preg_match( |
146 | 146 | "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
147 | 147 | $obj_with_address->address2() |
148 | - ) ) { |
|
148 | + )) { |
|
149 | 149 | return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
150 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
150 | + ? '<span itemprop="postOfficeBoxNumber">'.$obj_with_address->address2().'</span>' : ''; |
|
151 | 151 | } else { |
152 | 152 | return $obj_with_address->address2(); |
153 | 153 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | public static function addressLocality(EEI_Address $obj_with_address = null) |
167 | 167 | { |
168 | 168 | return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
169 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
169 | + ? '<span itemprop="addressLocality">'.$obj_with_address->city().'</span>' : ''; |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | |
@@ -182,8 +182,8 @@ discard block |
||
182 | 182 | public static function addressRegion(EEI_Address $obj_with_address = null) |
183 | 183 | { |
184 | 184 | $state = $obj_with_address->state_name(); |
185 | - if (! empty($state)) { |
|
186 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
185 | + if ( ! empty($state)) { |
|
186 | + return '<span itemprop="addressRegion">'.$state.'</span>'; |
|
187 | 187 | } else { |
188 | 188 | return ''; |
189 | 189 | } |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | public static function addressCountry(EEI_Address $obj_with_address = null) |
203 | 203 | { |
204 | 204 | $country = $obj_with_address->country_name(); |
205 | - if (! empty($country)) { |
|
206 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
205 | + if ( ! empty($country)) { |
|
206 | + return '<span itemprop="addressCountry">'.$country.'</span>'; |
|
207 | 207 | } else { |
208 | 208 | return ''; |
209 | 209 | } |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | */ |
239 | 239 | public static function telephone($phone_nmbr = null) |
240 | 240 | { |
241 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
241 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">'.$phone_nmbr.'</span>' |
|
242 | 242 | : ''; |
243 | 243 | } |
244 | 244 | |
@@ -259,15 +259,15 @@ discard block |
||
259 | 259 | // Check the URL includes a scheme |
260 | 260 | $parsed_url = parse_url($url); |
261 | 261 | if (empty($parsed_url['scheme'])) { |
262 | - $url = 'http://' . ltrim($url, '/'); |
|
262 | + $url = 'http://'.ltrim($url, '/'); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | $atts = ''; |
266 | 266 | foreach ($attributes as $attribute => $value) { |
267 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
267 | + $atts .= ' '.$attribute.'="'.$value.'"'; |
|
268 | 268 | } |
269 | 269 | $text = $text !== null && $text !== '' ? $text : $url; |
270 | - return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
270 | + return $url !== null && $url !== '' ? '<a itemprop="url" href="'.$url.'"'.$atts.'>'.$text.'</a>' |
|
271 | 271 | : ''; |
272 | 272 | } |
273 | 273 | } |