@@ -7,283 +7,283 @@ |
||
| 7 | 7 | |
| 8 | 8 | final class Application extends Container |
| 9 | 9 | { |
| 10 | - const CAPABILITY = 'edit_others_posts'; |
|
| 11 | - const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
| 12 | - const ID = 'site-reviews'; |
|
| 13 | - const PAGED_QUERY_VAR = 'reviews-page'; |
|
| 14 | - const POST_TYPE = 'site-review'; |
|
| 15 | - const PREFIX = 'glsr_'; |
|
| 16 | - const TAXONOMY = 'site-review-category'; |
|
| 10 | + const CAPABILITY = 'edit_others_posts'; |
|
| 11 | + const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
| 12 | + const ID = 'site-reviews'; |
|
| 13 | + const PAGED_QUERY_VAR = 'reviews-page'; |
|
| 14 | + const POST_TYPE = 'site-review'; |
|
| 15 | + const PREFIX = 'glsr_'; |
|
| 16 | + const TAXONOMY = 'site-review-category'; |
|
| 17 | 17 | |
| 18 | - public $defaults; |
|
| 19 | - public $deprecated = []; |
|
| 20 | - public $file; |
|
| 21 | - public $languages; |
|
| 22 | - public $mceShortcodes = []; //defined elsewhere |
|
| 23 | - public $name; |
|
| 24 | - public $reviewTypes; |
|
| 25 | - public $schemas = []; //defined elsewhere |
|
| 26 | - public $version; |
|
| 18 | + public $defaults; |
|
| 19 | + public $deprecated = []; |
|
| 20 | + public $file; |
|
| 21 | + public $languages; |
|
| 22 | + public $mceShortcodes = []; //defined elsewhere |
|
| 23 | + public $name; |
|
| 24 | + public $reviewTypes; |
|
| 25 | + public $schemas = []; //defined elsewhere |
|
| 26 | + public $version; |
|
| 27 | 27 | |
| 28 | - public function __construct() |
|
| 29 | - { |
|
| 30 | - static::$instance = $this; |
|
| 31 | - $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
| 32 | - $plugin = get_file_data($this->file, [ |
|
| 33 | - 'languages' => 'Domain Path', |
|
| 34 | - 'name' => 'Plugin Name', |
|
| 35 | - 'version' => 'Version', |
|
| 36 | - ], 'plugin'); |
|
| 37 | - array_walk($plugin, function ($value, $key) { |
|
| 38 | - $this->$key = $value; |
|
| 39 | - }); |
|
| 40 | - } |
|
| 28 | + public function __construct() |
|
| 29 | + { |
|
| 30 | + static::$instance = $this; |
|
| 31 | + $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
| 32 | + $plugin = get_file_data($this->file, [ |
|
| 33 | + 'languages' => 'Domain Path', |
|
| 34 | + 'name' => 'Plugin Name', |
|
| 35 | + 'version' => 'Version', |
|
| 36 | + ], 'plugin'); |
|
| 37 | + array_walk($plugin, function ($value, $key) { |
|
| 38 | + $this->$key = $value; |
|
| 39 | + }); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return void |
|
| 44 | - */ |
|
| 45 | - public function activate() |
|
| 46 | - { |
|
| 47 | - $this->make(DefaultsManager::class)->set(); |
|
| 48 | - $this->scheduleCronJob(); |
|
| 49 | - $this->upgrade(); |
|
| 50 | - } |
|
| 42 | + /** |
|
| 43 | + * @return void |
|
| 44 | + */ |
|
| 45 | + public function activate() |
|
| 46 | + { |
|
| 47 | + $this->make(DefaultsManager::class)->set(); |
|
| 48 | + $this->scheduleCronJob(); |
|
| 49 | + $this->upgrade(); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return void |
|
| 54 | - */ |
|
| 55 | - public function catchFatalError() |
|
| 56 | - { |
|
| 57 | - $error = error_get_last(); |
|
| 58 | - if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) { |
|
| 59 | - return; |
|
| 60 | - } |
|
| 61 | - glsr_log()->error($error['message']); |
|
| 62 | - } |
|
| 52 | + /** |
|
| 53 | + * @return void |
|
| 54 | + */ |
|
| 55 | + public function catchFatalError() |
|
| 56 | + { |
|
| 57 | + $error = error_get_last(); |
|
| 58 | + if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) { |
|
| 59 | + return; |
|
| 60 | + } |
|
| 61 | + glsr_log()->error($error['message']); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param string $name |
|
| 66 | - * @return array |
|
| 67 | - */ |
|
| 68 | - public function config($name) |
|
| 69 | - { |
|
| 70 | - $configFile = $this->path('config/'.$name.'.php'); |
|
| 71 | - $config = file_exists($configFile) |
|
| 72 | - ? include $configFile |
|
| 73 | - : []; |
|
| 74 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
| 75 | - } |
|
| 64 | + /** |
|
| 65 | + * @param string $name |
|
| 66 | + * @return array |
|
| 67 | + */ |
|
| 68 | + public function config($name) |
|
| 69 | + { |
|
| 70 | + $configFile = $this->path('config/'.$name.'.php'); |
|
| 71 | + $config = file_exists($configFile) |
|
| 72 | + ? include $configFile |
|
| 73 | + : []; |
|
| 74 | + return apply_filters('site-reviews/config/'.$name, $config); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @param string $property |
|
| 79 | - * @return string |
|
| 80 | - */ |
|
| 81 | - public function constant($property, $className = 'static') |
|
| 82 | - { |
|
| 83 | - $constant = $className.'::'.$property; |
|
| 84 | - return defined($constant) |
|
| 85 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
| 86 | - : ''; |
|
| 87 | - } |
|
| 77 | + /** |
|
| 78 | + * @param string $property |
|
| 79 | + * @return string |
|
| 80 | + */ |
|
| 81 | + public function constant($property, $className = 'static') |
|
| 82 | + { |
|
| 83 | + $constant = $className.'::'.$property; |
|
| 84 | + return defined($constant) |
|
| 85 | + ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
| 86 | + : ''; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * @return void |
|
| 91 | - */ |
|
| 92 | - public function deactivate() |
|
| 93 | - { |
|
| 94 | - $this->unscheduleCronJob(); |
|
| 95 | - } |
|
| 89 | + /** |
|
| 90 | + * @return void |
|
| 91 | + */ |
|
| 92 | + public function deactivate() |
|
| 93 | + { |
|
| 94 | + $this->unscheduleCronJob(); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @param string $view |
|
| 99 | - * @return void|string |
|
| 100 | - */ |
|
| 101 | - public function file($view) |
|
| 102 | - { |
|
| 103 | - $view.= '.php'; |
|
| 104 | - $filePaths = []; |
|
| 105 | - if (glsr(Helper::class)->startsWith('templates/', $view)) { |
|
| 106 | - $filePaths[] = $this->themePath(glsr(Helper::class)->removePrefix('templates/', $view)); |
|
| 107 | - } |
|
| 108 | - $filePaths[] = $this->path($view); |
|
| 109 | - $filePaths[] = $this->path('views/'.$view); |
|
| 110 | - foreach ($filePaths as $file) { |
|
| 111 | - if (!file_exists($file)) { |
|
| 112 | - continue; |
|
| 113 | - } |
|
| 114 | - return $file; |
|
| 115 | - } |
|
| 116 | - } |
|
| 97 | + /** |
|
| 98 | + * @param string $view |
|
| 99 | + * @return void|string |
|
| 100 | + */ |
|
| 101 | + public function file($view) |
|
| 102 | + { |
|
| 103 | + $view.= '.php'; |
|
| 104 | + $filePaths = []; |
|
| 105 | + if (glsr(Helper::class)->startsWith('templates/', $view)) { |
|
| 106 | + $filePaths[] = $this->themePath(glsr(Helper::class)->removePrefix('templates/', $view)); |
|
| 107 | + } |
|
| 108 | + $filePaths[] = $this->path($view); |
|
| 109 | + $filePaths[] = $this->path('views/'.$view); |
|
| 110 | + foreach ($filePaths as $file) { |
|
| 111 | + if (!file_exists($file)) { |
|
| 112 | + continue; |
|
| 113 | + } |
|
| 114 | + return $file; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * @return array |
|
| 120 | - */ |
|
| 121 | - public function getDefaults() |
|
| 122 | - { |
|
| 123 | - if (empty($this->defaults)) { |
|
| 124 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
| 125 | - $this->upgrade(); |
|
| 126 | - } |
|
| 127 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
| 128 | - } |
|
| 118 | + /** |
|
| 119 | + * @return array |
|
| 120 | + */ |
|
| 121 | + public function getDefaults() |
|
| 122 | + { |
|
| 123 | + if (empty($this->defaults)) { |
|
| 124 | + $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
| 125 | + $this->upgrade(); |
|
| 126 | + } |
|
| 127 | + return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * @return bool |
|
| 132 | - */ |
|
| 133 | - public function getPermission($page = '') |
|
| 134 | - { |
|
| 135 | - $permissions = [ |
|
| 136 | - 'addons' => 'install_plugins', |
|
| 137 | - 'settings' => 'manage_options', |
|
| 138 | - ]; |
|
| 139 | - return glsr_get($permissions, $page, $this->constant('CAPABILITY')); |
|
| 140 | - } |
|
| 130 | + /** |
|
| 131 | + * @return bool |
|
| 132 | + */ |
|
| 133 | + public function getPermission($page = '') |
|
| 134 | + { |
|
| 135 | + $permissions = [ |
|
| 136 | + 'addons' => 'install_plugins', |
|
| 137 | + 'settings' => 'manage_options', |
|
| 138 | + ]; |
|
| 139 | + return glsr_get($permissions, $page, $this->constant('CAPABILITY')); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * @return bool |
|
| 144 | - */ |
|
| 145 | - public function hasPermission($page = '') |
|
| 146 | - { |
|
| 147 | - $isAdmin = $this->isAdmin(); |
|
| 148 | - return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
| 149 | - } |
|
| 142 | + /** |
|
| 143 | + * @return bool |
|
| 144 | + */ |
|
| 145 | + public function hasPermission($page = '') |
|
| 146 | + { |
|
| 147 | + $isAdmin = $this->isAdmin(); |
|
| 148 | + return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * @return void |
|
| 153 | - */ |
|
| 154 | - public function init() |
|
| 155 | - { |
|
| 156 | - $this->make(Actions::class)->run(); |
|
| 157 | - $this->make(Filters::class)->run(); |
|
| 158 | - } |
|
| 151 | + /** |
|
| 152 | + * @return void |
|
| 153 | + */ |
|
| 154 | + public function init() |
|
| 155 | + { |
|
| 156 | + $this->make(Actions::class)->run(); |
|
| 157 | + $this->make(Filters::class)->run(); |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * @return bool |
|
| 162 | - */ |
|
| 163 | - public function isAdmin() |
|
| 164 | - { |
|
| 165 | - return is_admin() && !wp_doing_ajax(); |
|
| 166 | - } |
|
| 160 | + /** |
|
| 161 | + * @return bool |
|
| 162 | + */ |
|
| 163 | + public function isAdmin() |
|
| 164 | + { |
|
| 165 | + return is_admin() && !wp_doing_ajax(); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * @param string $file |
|
| 170 | - * @return string |
|
| 171 | - */ |
|
| 172 | - public function path($file = '', $realpath = true) |
|
| 173 | - { |
|
| 174 | - $path = plugin_dir_path($this->file); |
|
| 175 | - if (!$realpath) { |
|
| 176 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
| 177 | - } |
|
| 178 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
| 179 | - return apply_filters('site-reviews/path', $path, $file); |
|
| 180 | - } |
|
| 168 | + /** |
|
| 169 | + * @param string $file |
|
| 170 | + * @return string |
|
| 171 | + */ |
|
| 172 | + public function path($file = '', $realpath = true) |
|
| 173 | + { |
|
| 174 | + $path = plugin_dir_path($this->file); |
|
| 175 | + if (!$realpath) { |
|
| 176 | + $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
| 177 | + } |
|
| 178 | + $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
| 179 | + return apply_filters('site-reviews/path', $path, $file); |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * @return void |
|
| 184 | - */ |
|
| 185 | - public function registerAddons() |
|
| 186 | - { |
|
| 187 | - do_action('site-reviews/addon/register', $this); |
|
| 188 | - } |
|
| 182 | + /** |
|
| 183 | + * @return void |
|
| 184 | + */ |
|
| 185 | + public function registerAddons() |
|
| 186 | + { |
|
| 187 | + do_action('site-reviews/addon/register', $this); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * @return void |
|
| 192 | - */ |
|
| 193 | - public function registerLanguages() |
|
| 194 | - { |
|
| 195 | - load_plugin_textdomain(static::ID, false, |
|
| 196 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
| 197 | - ); |
|
| 198 | - } |
|
| 190 | + /** |
|
| 191 | + * @return void |
|
| 192 | + */ |
|
| 193 | + public function registerLanguages() |
|
| 194 | + { |
|
| 195 | + load_plugin_textdomain(static::ID, false, |
|
| 196 | + trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
| 197 | + ); |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - /** |
|
| 201 | - * @return void |
|
| 202 | - */ |
|
| 203 | - public function registerReviewTypes() |
|
| 204 | - { |
|
| 205 | - $types = apply_filters('site-reviews/addon/types', []); |
|
| 206 | - $this->reviewTypes = wp_parse_args($types, [ |
|
| 207 | - 'local' => __('Local', 'site-reviews'), |
|
| 208 | - ]); |
|
| 209 | - } |
|
| 200 | + /** |
|
| 201 | + * @return void |
|
| 202 | + */ |
|
| 203 | + public function registerReviewTypes() |
|
| 204 | + { |
|
| 205 | + $types = apply_filters('site-reviews/addon/types', []); |
|
| 206 | + $this->reviewTypes = wp_parse_args($types, [ |
|
| 207 | + 'local' => __('Local', 'site-reviews'), |
|
| 208 | + ]); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * @param string $view |
|
| 213 | - * @return void |
|
| 214 | - */ |
|
| 215 | - public function render($view, array $data = []) |
|
| 216 | - { |
|
| 217 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
| 218 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
| 219 | - if (!file_exists($file)) { |
|
| 220 | - glsr_log()->error('File not found: '.$file); |
|
| 221 | - return; |
|
| 222 | - } |
|
| 223 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
| 224 | - extract($data); |
|
| 225 | - include $file; |
|
| 226 | - } |
|
| 211 | + /** |
|
| 212 | + * @param string $view |
|
| 213 | + * @return void |
|
| 214 | + */ |
|
| 215 | + public function render($view, array $data = []) |
|
| 216 | + { |
|
| 217 | + $view = apply_filters('site-reviews/render/view', $view, $data); |
|
| 218 | + $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
| 219 | + if (!file_exists($file)) { |
|
| 220 | + glsr_log()->error('File not found: '.$file); |
|
| 221 | + return; |
|
| 222 | + } |
|
| 223 | + $data = apply_filters('site-reviews/views/data', $data, $view); |
|
| 224 | + extract($data); |
|
| 225 | + include $file; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - /** |
|
| 229 | - * @return void |
|
| 230 | - */ |
|
| 231 | - public function scheduleCronJob() |
|
| 232 | - { |
|
| 233 | - if (wp_next_scheduled(static::CRON_EVENT)) { |
|
| 234 | - return; |
|
| 235 | - } |
|
| 236 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
| 237 | - } |
|
| 228 | + /** |
|
| 229 | + * @return void |
|
| 230 | + */ |
|
| 231 | + public function scheduleCronJob() |
|
| 232 | + { |
|
| 233 | + if (wp_next_scheduled(static::CRON_EVENT)) { |
|
| 234 | + return; |
|
| 235 | + } |
|
| 236 | + wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * @param string $file |
|
| 241 | - * @return string |
|
| 242 | - */ |
|
| 243 | - public function themePath($file = '') |
|
| 244 | - { |
|
| 245 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
| 246 | - } |
|
| 239 | + /** |
|
| 240 | + * @param string $file |
|
| 241 | + * @return string |
|
| 242 | + */ |
|
| 243 | + public function themePath($file = '') |
|
| 244 | + { |
|
| 245 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * @return void |
|
| 250 | - */ |
|
| 251 | - public function unscheduleCronJob() |
|
| 252 | - { |
|
| 253 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
| 254 | - } |
|
| 248 | + /** |
|
| 249 | + * @return void |
|
| 250 | + */ |
|
| 251 | + public function unscheduleCronJob() |
|
| 252 | + { |
|
| 253 | + wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - /** |
|
| 257 | - * @return void |
|
| 258 | - */ |
|
| 259 | - public function upgrade() |
|
| 260 | - { |
|
| 261 | - $this->make(Upgrader::class)->run(); |
|
| 262 | - } |
|
| 256 | + /** |
|
| 257 | + * @return void |
|
| 258 | + */ |
|
| 259 | + public function upgrade() |
|
| 260 | + { |
|
| 261 | + $this->make(Upgrader::class)->run(); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - /** |
|
| 265 | - * @param mixed $upgrader |
|
| 266 | - * @return void |
|
| 267 | - * @action upgrader_process_complete |
|
| 268 | - */ |
|
| 269 | - public function upgraded($upgrader, array $data) |
|
| 270 | - { |
|
| 271 | - if (array_key_exists('plugins', $data) |
|
| 272 | - && in_array(plugin_basename($this->file), $data['plugins']) |
|
| 273 | - && 'update' === $data['action'] |
|
| 274 | - && 'plugin' === $data['type'] |
|
| 275 | - ) { |
|
| 276 | - $this->upgrade(); |
|
| 277 | - } |
|
| 278 | - } |
|
| 264 | + /** |
|
| 265 | + * @param mixed $upgrader |
|
| 266 | + * @return void |
|
| 267 | + * @action upgrader_process_complete |
|
| 268 | + */ |
|
| 269 | + public function upgraded($upgrader, array $data) |
|
| 270 | + { |
|
| 271 | + if (array_key_exists('plugins', $data) |
|
| 272 | + && in_array(plugin_basename($this->file), $data['plugins']) |
|
| 273 | + && 'update' === $data['action'] |
|
| 274 | + && 'plugin' === $data['type'] |
|
| 275 | + ) { |
|
| 276 | + $this->upgrade(); |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - /** |
|
| 281 | - * @param string $path |
|
| 282 | - * @return string |
|
| 283 | - */ |
|
| 284 | - public function url($path = '') |
|
| 285 | - { |
|
| 286 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
| 287 | - return apply_filters('site-reviews/url', $url, $path); |
|
| 288 | - } |
|
| 280 | + /** |
|
| 281 | + * @param string $path |
|
| 282 | + * @return string |
|
| 283 | + */ |
|
| 284 | + public function url($path = '') |
|
| 285 | + { |
|
| 286 | + $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
| 287 | + return apply_filters('site-reviews/url', $url, $path); |
|
| 288 | + } |
|
| 289 | 289 | } |
@@ -28,13 +28,13 @@ discard block |
||
| 28 | 28 | public function __construct() |
| 29 | 29 | { |
| 30 | 30 | static::$instance = $this; |
| 31 | - $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
| 32 | - $plugin = get_file_data($this->file, [ |
|
| 31 | + $this->file = realpath( trailingslashit( dirname( __DIR__ ) ).static::ID.'.php' ); |
|
| 32 | + $plugin = get_file_data( $this->file, [ |
|
| 33 | 33 | 'languages' => 'Domain Path', |
| 34 | 34 | 'name' => 'Plugin Name', |
| 35 | 35 | 'version' => 'Version', |
| 36 | - ], 'plugin'); |
|
| 37 | - array_walk($plugin, function ($value, $key) { |
|
| 36 | + ], 'plugin' ); |
|
| 37 | + array_walk( $plugin, function( $value, $key ) { |
|
| 38 | 38 | $this->$key = $value; |
| 39 | 39 | }); |
| 40 | 40 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function activate() |
| 46 | 46 | { |
| 47 | - $this->make(DefaultsManager::class)->set(); |
|
| 47 | + $this->make( DefaultsManager::class )->set(); |
|
| 48 | 48 | $this->scheduleCronJob(); |
| 49 | 49 | $this->upgrade(); |
| 50 | 50 | } |
@@ -55,34 +55,34 @@ discard block |
||
| 55 | 55 | public function catchFatalError() |
| 56 | 56 | { |
| 57 | 57 | $error = error_get_last(); |
| 58 | - if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) { |
|
| 58 | + if( E_ERROR !== $error['type'] || false === strpos( $error['message'], $this->path() ) ) { |
|
| 59 | 59 | return; |
| 60 | 60 | } |
| 61 | - glsr_log()->error($error['message']); |
|
| 61 | + glsr_log()->error( $error['message'] ); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * @param string $name |
| 66 | 66 | * @return array |
| 67 | 67 | */ |
| 68 | - public function config($name) |
|
| 68 | + public function config( $name ) |
|
| 69 | 69 | { |
| 70 | - $configFile = $this->path('config/'.$name.'.php'); |
|
| 71 | - $config = file_exists($configFile) |
|
| 70 | + $configFile = $this->path( 'config/'.$name.'.php' ); |
|
| 71 | + $config = file_exists( $configFile ) |
|
| 72 | 72 | ? include $configFile |
| 73 | 73 | : []; |
| 74 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
| 74 | + return apply_filters( 'site-reviews/config/'.$name, $config ); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * @param string $property |
| 79 | 79 | * @return string |
| 80 | 80 | */ |
| 81 | - public function constant($property, $className = 'static') |
|
| 81 | + public function constant( $property, $className = 'static' ) |
|
| 82 | 82 | { |
| 83 | 83 | $constant = $className.'::'.$property; |
| 84 | - return defined($constant) |
|
| 85 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
| 84 | + return defined( $constant ) |
|
| 85 | + ? apply_filters( 'site-reviews/const/'.$property, constant( $constant ) ) |
|
| 86 | 86 | : ''; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -98,17 +98,17 @@ discard block |
||
| 98 | 98 | * @param string $view |
| 99 | 99 | * @return void|string |
| 100 | 100 | */ |
| 101 | - public function file($view) |
|
| 101 | + public function file( $view ) |
|
| 102 | 102 | { |
| 103 | - $view.= '.php'; |
|
| 103 | + $view .= '.php'; |
|
| 104 | 104 | $filePaths = []; |
| 105 | - if (glsr(Helper::class)->startsWith('templates/', $view)) { |
|
| 106 | - $filePaths[] = $this->themePath(glsr(Helper::class)->removePrefix('templates/', $view)); |
|
| 105 | + if( glsr( Helper::class )->startsWith( 'templates/', $view ) ) { |
|
| 106 | + $filePaths[] = $this->themePath( glsr( Helper::class )->removePrefix( 'templates/', $view ) ); |
|
| 107 | 107 | } |
| 108 | - $filePaths[] = $this->path($view); |
|
| 109 | - $filePaths[] = $this->path('views/'.$view); |
|
| 110 | - foreach ($filePaths as $file) { |
|
| 111 | - if (!file_exists($file)) { |
|
| 108 | + $filePaths[] = $this->path( $view ); |
|
| 109 | + $filePaths[] = $this->path( 'views/'.$view ); |
|
| 110 | + foreach( $filePaths as $file ) { |
|
| 111 | + if( !file_exists( $file ) ) { |
|
| 112 | 112 | continue; |
| 113 | 113 | } |
| 114 | 114 | return $file; |
@@ -120,32 +120,32 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public function getDefaults() |
| 122 | 122 | { |
| 123 | - if (empty($this->defaults)) { |
|
| 124 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
| 123 | + if( empty($this->defaults) ) { |
|
| 124 | + $this->defaults = $this->make( DefaultsManager::class )->get(); |
|
| 125 | 125 | $this->upgrade(); |
| 126 | 126 | } |
| 127 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
| 127 | + return apply_filters( 'site-reviews/get/defaults', $this->defaults ); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | 131 | * @return bool |
| 132 | 132 | */ |
| 133 | - public function getPermission($page = '') |
|
| 133 | + public function getPermission( $page = '' ) |
|
| 134 | 134 | { |
| 135 | 135 | $permissions = [ |
| 136 | 136 | 'addons' => 'install_plugins', |
| 137 | 137 | 'settings' => 'manage_options', |
| 138 | 138 | ]; |
| 139 | - return glsr_get($permissions, $page, $this->constant('CAPABILITY')); |
|
| 139 | + return glsr_get( $permissions, $page, $this->constant( 'CAPABILITY' ) ); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
| 143 | 143 | * @return bool |
| 144 | 144 | */ |
| 145 | - public function hasPermission($page = '') |
|
| 145 | + public function hasPermission( $page = '' ) |
|
| 146 | 146 | { |
| 147 | 147 | $isAdmin = $this->isAdmin(); |
| 148 | - return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
| 148 | + return !$isAdmin || ($isAdmin && current_user_can( $this->getPermission( $page ) )); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -153,8 +153,8 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | public function init() |
| 155 | 155 | { |
| 156 | - $this->make(Actions::class)->run(); |
|
| 157 | - $this->make(Filters::class)->run(); |
|
| 156 | + $this->make( Actions::class )->run(); |
|
| 157 | + $this->make( Filters::class )->run(); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -169,14 +169,14 @@ discard block |
||
| 169 | 169 | * @param string $file |
| 170 | 170 | * @return string |
| 171 | 171 | */ |
| 172 | - public function path($file = '', $realpath = true) |
|
| 172 | + public function path( $file = '', $realpath = true ) |
|
| 173 | 173 | { |
| 174 | - $path = plugin_dir_path($this->file); |
|
| 175 | - if (!$realpath) { |
|
| 176 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
| 174 | + $path = plugin_dir_path( $this->file ); |
|
| 175 | + if( !$realpath ) { |
|
| 176 | + $path = trailingslashit( WP_PLUGIN_DIR ).basename( dirname( $this->file ) ); |
|
| 177 | 177 | } |
| 178 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
| 179 | - return apply_filters('site-reviews/path', $path, $file); |
|
| 178 | + $path = trailingslashit( $path ).ltrim( trim( $file ), '/' ); |
|
| 179 | + return apply_filters( 'site-reviews/path', $path, $file ); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | public function registerAddons() |
| 186 | 186 | { |
| 187 | - do_action('site-reviews/addon/register', $this); |
|
| 187 | + do_action( 'site-reviews/addon/register', $this ); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -192,8 +192,8 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | public function registerLanguages() |
| 194 | 194 | { |
| 195 | - load_plugin_textdomain(static::ID, false, |
|
| 196 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
| 195 | + load_plugin_textdomain( static::ID, false, |
|
| 196 | + trailingslashit( plugin_basename( $this->path() ).'/'.$this->languages ) |
|
| 197 | 197 | ); |
| 198 | 198 | } |
| 199 | 199 | |
@@ -202,26 +202,26 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | public function registerReviewTypes() |
| 204 | 204 | { |
| 205 | - $types = apply_filters('site-reviews/addon/types', []); |
|
| 206 | - $this->reviewTypes = wp_parse_args($types, [ |
|
| 207 | - 'local' => __('Local', 'site-reviews'), |
|
| 208 | - ]); |
|
| 205 | + $types = apply_filters( 'site-reviews/addon/types', [] ); |
|
| 206 | + $this->reviewTypes = wp_parse_args( $types, [ |
|
| 207 | + 'local' => __( 'Local', 'site-reviews' ), |
|
| 208 | + ] ); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | 212 | * @param string $view |
| 213 | 213 | * @return void |
| 214 | 214 | */ |
| 215 | - public function render($view, array $data = []) |
|
| 215 | + public function render( $view, array $data = [] ) |
|
| 216 | 216 | { |
| 217 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
| 218 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
| 219 | - if (!file_exists($file)) { |
|
| 220 | - glsr_log()->error('File not found: '.$file); |
|
| 217 | + $view = apply_filters( 'site-reviews/render/view', $view, $data ); |
|
| 218 | + $file = apply_filters( 'site-reviews/views/file', $this->file( $view ), $view, $data ); |
|
| 219 | + if( !file_exists( $file ) ) { |
|
| 220 | + glsr_log()->error( 'File not found: '.$file ); |
|
| 221 | 221 | return; |
| 222 | 222 | } |
| 223 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
| 224 | - extract($data); |
|
| 223 | + $data = apply_filters( 'site-reviews/views/data', $data, $view ); |
|
| 224 | + extract( $data ); |
|
| 225 | 225 | include $file; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -230,19 +230,19 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | public function scheduleCronJob() |
| 232 | 232 | { |
| 233 | - if (wp_next_scheduled(static::CRON_EVENT)) { |
|
| 233 | + if( wp_next_scheduled( static::CRON_EVENT ) ) { |
|
| 234 | 234 | return; |
| 235 | 235 | } |
| 236 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
| 236 | + wp_schedule_event( time(), 'twicedaily', static::CRON_EVENT ); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
| 240 | 240 | * @param string $file |
| 241 | 241 | * @return string |
| 242 | 242 | */ |
| 243 | - public function themePath($file = '') |
|
| 243 | + public function themePath( $file = '' ) |
|
| 244 | 244 | { |
| 245 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
| 245 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim( trim( $file ), '/' ); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | public function unscheduleCronJob() |
| 252 | 252 | { |
| 253 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
| 253 | + wp_unschedule_event( intval( wp_next_scheduled( static::CRON_EVENT ) ), static::CRON_EVENT ); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | public function upgrade() |
| 260 | 260 | { |
| 261 | - $this->make(Upgrader::class)->run(); |
|
| 261 | + $this->make( Upgrader::class )->run(); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -266,10 +266,10 @@ discard block |
||
| 266 | 266 | * @return void |
| 267 | 267 | * @action upgrader_process_complete |
| 268 | 268 | */ |
| 269 | - public function upgraded($upgrader, array $data) |
|
| 269 | + public function upgraded( $upgrader, array $data ) |
|
| 270 | 270 | { |
| 271 | - if (array_key_exists('plugins', $data) |
|
| 272 | - && in_array(plugin_basename($this->file), $data['plugins']) |
|
| 271 | + if( array_key_exists( 'plugins', $data ) |
|
| 272 | + && in_array( plugin_basename( $this->file ), $data['plugins'] ) |
|
| 273 | 273 | && 'update' === $data['action'] |
| 274 | 274 | && 'plugin' === $data['type'] |
| 275 | 275 | ) { |
@@ -281,9 +281,9 @@ discard block |
||
| 281 | 281 | * @param string $path |
| 282 | 282 | * @return string |
| 283 | 283 | */ |
| 284 | - public function url($path = '') |
|
| 284 | + public function url( $path = '' ) |
|
| 285 | 285 | { |
| 286 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
| 287 | - return apply_filters('site-reviews/url', $url, $path); |
|
| 286 | + $url = esc_url( plugin_dir_url( $this->file ).ltrim( trim( $path ), '/' ) ); |
|
| 287 | + return apply_filters( 'site-reviews/url', $url, $path ); |
|
| 288 | 288 | } |
| 289 | 289 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @param string $sessionCookiePrefix |
| 20 | 20 | * @return int|false |
| 21 | 21 | */ |
| 22 | - public function deleteAllSessions($sessionCookiePrefix) |
|
| 22 | + public function deleteAllSessions($sessionCookiePrefix) |
|
| 23 | 23 | { |
| 24 | 24 | return $this->db->query(" |
| 25 | 25 | DELETE |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @param string $expiredSessions |
| 33 | 33 | * @return int|false |
| 34 | 34 | */ |
| 35 | - public function deleteExpiredSessions($expiredSessions) |
|
| 35 | + public function deleteExpiredSessions($expiredSessions) |
|
| 36 | 36 | { |
| 37 | 37 | return $this->db->query(" |
| 38 | 38 | DELETE |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @param int $limit |
| 47 | 47 | * @return array |
| 48 | 48 | */ |
| 49 | - public function getExpiredSessions($sessionCookiePrefix, $limit) |
|
| 49 | + public function getExpiredSessions($sessionCookiePrefix, $limit) |
|
| 50 | 50 | { |
| 51 | 51 | return (array) $this->db->get_results(" |
| 52 | 52 | SELECT option_name AS name, option_value AS expiration |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @param string $metaReviewId |
| 62 | 62 | * @return int |
| 63 | 63 | */ |
| 64 | - public function getPostIdFromReviewId($metaReviewId) |
|
| 64 | + public function getPostIdFromReviewId($metaReviewId) |
|
| 65 | 65 | { |
| 66 | 66 | $postId = $this->db->get_var(" |
| 67 | 67 | SELECT p.ID |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | AND m.meta_key = 'review_id' |
| 72 | 72 | AND m.meta_value = '{$metaReviewId}' |
| 73 | 73 | "); |
| 74 | - return intval($postId); |
|
| 74 | + return intval($postId); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @param int $limit |
| 80 | 80 | * @return array |
| 81 | 81 | */ |
| 82 | - public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
| 82 | + public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
| 83 | 83 | { |
| 84 | 84 | return (array) $this->db->get_results(" |
| 85 | 85 | SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @param string $metaKey |
| 104 | 104 | * @return array |
| 105 | 105 | */ |
| 106 | - public function getReviewCountsFor($metaKey) |
|
| 106 | + public function getReviewCountsFor($metaKey) |
|
| 107 | 107 | { |
| 108 | 108 | return (array) $this->db->get_results(" |
| 109 | 109 | SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * @param string $reviewType |
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | - public function getReviewIdsByType($reviewType) |
|
| 123 | + public function getReviewIdsByType($reviewType) |
|
| 124 | 124 | { |
| 125 | 125 | $results = $this->db->get_col(" |
| 126 | 126 | SELECT DISTINCT m1.meta_value AS review_id |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | AND m2.meta_key = 'review_type' |
| 133 | 133 | AND m2.meta_value = '{$reviewType}' |
| 134 | 134 | "); |
| 135 | - return array_keys(array_flip($results)); |
|
| 135 | + return array_keys(array_flip($results)); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -140,11 +140,11 @@ discard block |
||
| 140 | 140 | * @param int $limit |
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | - public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
| 143 | + public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
| 144 | 144 | { |
| 145 | - sort($postIds); |
|
| 146 | - $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
| 147 | - $postIds = implode(',', $postIds); |
|
| 145 | + sort($postIds); |
|
| 146 | + $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
| 147 | + $postIds = implode(',', $postIds); |
|
| 148 | 148 | return (array) $this->db->get_results(" |
| 149 | 149 | SELECT p.ID, m.meta_value AS rating |
| 150 | 150 | FROM {$this->db->posts} AS p |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @param string $status |
| 166 | 166 | * @return array |
| 167 | 167 | */ |
| 168 | - public function getReviewsMeta($key, $status = 'publish') |
|
| 168 | + public function getReviewsMeta($key, $status = 'publish') |
|
| 169 | 169 | { |
| 170 | 170 | $values = $this->db->get_col(" |
| 171 | 171 | SELECT DISTINCT m.meta_value |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | GROUP BY p.ID -- remove duplicate meta_value entries |
| 179 | 179 | ORDER BY m.meta_id ASC -- sort by oldest meta_value |
| 180 | 180 | "); |
| 181 | - sort($values); |
|
| 181 | + sort($values); |
|
| 182 | 182 | return $values; |
| 183 | 183 | } |
| 184 | 184 | |
@@ -186,34 +186,34 @@ discard block |
||
| 186 | 186 | * @param string $and |
| 187 | 187 | * @return string |
| 188 | 188 | */ |
| 189 | - protected function getAndForCounts(array $args, $and = '') |
|
| 189 | + protected function getAndForCounts(array $args, $and = '') |
|
| 190 | 190 | { |
| 191 | - $postIds = implode(',', array_filter(glsr_get($args, 'post_ids'))); |
|
| 192 | - $termIds = implode(',', array_filter(glsr_get($args, 'term_ids'))); |
|
| 193 | - if (!empty($args['type'])) { |
|
| 194 | - $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
| 191 | + $postIds = implode(',', array_filter(glsr_get($args, 'post_ids'))); |
|
| 192 | + $termIds = implode(',', array_filter(glsr_get($args, 'term_ids'))); |
|
| 193 | + if (!empty($args['type'])) { |
|
| 194 | + $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
| 195 | 195 | } |
| 196 | - if ($postIds) { |
|
| 197 | - $and.= "AND m3.meta_key = 'assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
| 196 | + if ($postIds) { |
|
| 197 | + $and.= "AND m3.meta_key = 'assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
| 198 | 198 | } |
| 199 | - if ($termIds) { |
|
| 200 | - $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
| 199 | + if ($termIds) { |
|
| 200 | + $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
| 201 | 201 | } |
| 202 | - return apply_filters('site-reviews/query/and-for-counts', $and); |
|
| 202 | + return apply_filters('site-reviews/query/and-for-counts', $and); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
| 206 | 206 | * @param string $innerJoin |
| 207 | 207 | * @return string |
| 208 | 208 | */ |
| 209 | - protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
| 209 | + protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
| 210 | 210 | { |
| 211 | - if (!empty(glsr_get($args, 'post_ids'))) { |
|
| 212 | - $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
| 211 | + if (!empty(glsr_get($args, 'post_ids'))) { |
|
| 212 | + $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
| 213 | 213 | } |
| 214 | - if (!empty(glsr_get($args, 'term_ids'))) { |
|
| 215 | - $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
| 214 | + if (!empty(glsr_get($args, 'term_ids'))) { |
|
| 215 | + $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
| 216 | 216 | } |
| 217 | - return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
| 217 | + return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
| 218 | 218 | } |
| 219 | 219 | } |
@@ -19,26 +19,26 @@ discard block |
||
| 19 | 19 | * @param string $sessionCookiePrefix |
| 20 | 20 | * @return int|false |
| 21 | 21 | */ |
| 22 | - public function deleteAllSessions($sessionCookiePrefix) |
|
| 22 | + public function deleteAllSessions( $sessionCookiePrefix ) |
|
| 23 | 23 | { |
| 24 | - return $this->db->query(" |
|
| 24 | + return $this->db->query( " |
|
| 25 | 25 | DELETE |
| 26 | 26 | FROM {$this->db->options} |
| 27 | 27 | WHERE option_name LIKE '{$sessionCookiePrefix}_%' |
| 28 | - "); |
|
| 28 | + " ); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * @param string $expiredSessions |
| 33 | 33 | * @return int|false |
| 34 | 34 | */ |
| 35 | - public function deleteExpiredSessions($expiredSessions) |
|
| 35 | + public function deleteExpiredSessions( $expiredSessions ) |
|
| 36 | 36 | { |
| 37 | - return $this->db->query(" |
|
| 37 | + return $this->db->query( " |
|
| 38 | 38 | DELETE |
| 39 | 39 | FROM {$this->db->options} |
| 40 | 40 | WHERE option_name IN ('{$expiredSessions}') |
| 41 | - "); |
|
| 41 | + " ); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -46,32 +46,32 @@ discard block |
||
| 46 | 46 | * @param int $limit |
| 47 | 47 | * @return array |
| 48 | 48 | */ |
| 49 | - public function getExpiredSessions($sessionCookiePrefix, $limit) |
|
| 49 | + public function getExpiredSessions( $sessionCookiePrefix, $limit ) |
|
| 50 | 50 | { |
| 51 | - return (array) $this->db->get_results(" |
|
| 51 | + return (array)$this->db->get_results( " |
|
| 52 | 52 | SELECT option_name AS name, option_value AS expiration |
| 53 | 53 | FROM {$this->db->options} |
| 54 | 54 | WHERE option_name LIKE '{$sessionCookiePrefix}_expires_%' |
| 55 | 55 | ORDER BY option_value ASC |
| 56 | 56 | LIMIT 0, {$limit} |
| 57 | - "); |
|
| 57 | + " ); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * @param string $metaReviewId |
| 62 | 62 | * @return int |
| 63 | 63 | */ |
| 64 | - public function getPostIdFromReviewId($metaReviewId) |
|
| 64 | + public function getPostIdFromReviewId( $metaReviewId ) |
|
| 65 | 65 | { |
| 66 | - $postId = $this->db->get_var(" |
|
| 66 | + $postId = $this->db->get_var( " |
|
| 67 | 67 | SELECT p.ID |
| 68 | 68 | FROM {$this->db->posts} AS p |
| 69 | 69 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
| 70 | 70 | WHERE p.post_type = '{$this->postType}' |
| 71 | 71 | AND m.meta_key = 'review_id' |
| 72 | 72 | AND m.meta_value = '{$metaReviewId}' |
| 73 | - "); |
|
| 74 | - return intval($postId); |
|
| 73 | + " ); |
|
| 74 | + return intval( $postId ); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -79,23 +79,23 @@ discard block |
||
| 79 | 79 | * @param int $limit |
| 80 | 80 | * @return array |
| 81 | 81 | */ |
| 82 | - public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
| 82 | + public function getReviewCounts( array $args, $lastPostId = 0, $limit = 500 ) |
|
| 83 | 83 | { |
| 84 | - return (array) $this->db->get_results(" |
|
| 84 | + return (array)$this->db->get_results( " |
|
| 85 | 85 | SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
| 86 | 86 | FROM {$this->db->posts} AS p |
| 87 | 87 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
| 88 | 88 | INNER JOIN {$this->db->postmeta} AS m2 ON p.ID = m2.post_id |
| 89 | - {$this->getInnerJoinForCounts($args)} |
|
| 89 | + {$this->getInnerJoinForCounts( $args )} |
|
| 90 | 90 | WHERE p.ID > {$lastPostId} |
| 91 | 91 | AND p.post_status = 'publish' |
| 92 | 92 | AND p.post_type = '{$this->postType}' |
| 93 | 93 | AND m1.meta_key = 'rating' |
| 94 | 94 | AND m2.meta_key = 'review_type' |
| 95 | - {$this->getAndForCounts($args)} |
|
| 95 | + {$this->getAndForCounts( $args )} |
|
| 96 | 96 | ORDER By p.ID ASC |
| 97 | 97 | LIMIT {$limit} |
| 98 | - "); |
|
| 98 | + " ); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -103,16 +103,16 @@ discard block |
||
| 103 | 103 | * @param string $metaKey |
| 104 | 104 | * @return array |
| 105 | 105 | */ |
| 106 | - public function getReviewCountsFor($metaKey) |
|
| 106 | + public function getReviewCountsFor( $metaKey ) |
|
| 107 | 107 | { |
| 108 | - return (array) $this->db->get_results(" |
|
| 108 | + return (array)$this->db->get_results( " |
|
| 109 | 109 | SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts |
| 110 | 110 | FROM {$this->db->posts} AS p |
| 111 | 111 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
| 112 | 112 | WHERE p.post_type = '{$this->postType}' |
| 113 | 113 | AND m.meta_key = '{$metaKey}' |
| 114 | 114 | GROUP BY name |
| 115 | - "); |
|
| 115 | + " ); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -120,9 +120,9 @@ discard block |
||
| 120 | 120 | * @param string $reviewType |
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | - public function getReviewIdsByType($reviewType) |
|
| 123 | + public function getReviewIdsByType( $reviewType ) |
|
| 124 | 124 | { |
| 125 | - $results = $this->db->get_col(" |
|
| 125 | + $results = $this->db->get_col( " |
|
| 126 | 126 | SELECT DISTINCT m1.meta_value AS review_id |
| 127 | 127 | FROM {$this->db->posts} AS p |
| 128 | 128 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -131,8 +131,8 @@ discard block |
||
| 131 | 131 | AND m1.meta_key = 'review_id' |
| 132 | 132 | AND m2.meta_key = 'review_type' |
| 133 | 133 | AND m2.meta_value = '{$reviewType}' |
| 134 | - "); |
|
| 135 | - return array_keys(array_flip($results)); |
|
| 134 | + " ); |
|
| 135 | + return array_keys( array_flip( $results ) ); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -140,12 +140,12 @@ discard block |
||
| 140 | 140 | * @param int $limit |
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | - public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
| 143 | + public function getReviewRatingsFromIds( array $postIds, $greaterThanId = 0, $limit = 100 ) |
|
| 144 | 144 | { |
| 145 | - sort($postIds); |
|
| 146 | - $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
| 147 | - $postIds = implode(',', $postIds); |
|
| 148 | - return (array) $this->db->get_results(" |
|
| 145 | + sort( $postIds ); |
|
| 146 | + $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds ) ), $limit ); |
|
| 147 | + $postIds = implode( ',', $postIds ); |
|
| 148 | + return (array)$this->db->get_results( " |
|
| 149 | 149 | SELECT p.ID, m.meta_value AS rating |
| 150 | 150 | FROM {$this->db->posts} AS p |
| 151 | 151 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | GROUP BY p.ID |
| 158 | 158 | ORDER By p.ID ASC |
| 159 | 159 | LIMIT {$limit} |
| 160 | - "); |
|
| 160 | + " ); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | * @param string $status |
| 166 | 166 | * @return array |
| 167 | 167 | */ |
| 168 | - public function getReviewsMeta($key, $status = 'publish') |
|
| 168 | + public function getReviewsMeta( $key, $status = 'publish' ) |
|
| 169 | 169 | { |
| 170 | - $values = $this->db->get_col(" |
|
| 170 | + $values = $this->db->get_col( " |
|
| 171 | 171 | SELECT DISTINCT m.meta_value |
| 172 | 172 | FROM {$this->db->postmeta} m |
| 173 | 173 | LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id |
@@ -177,8 +177,8 @@ discard block |
||
| 177 | 177 | AND p.post_status = '{$status}' |
| 178 | 178 | GROUP BY p.ID -- remove duplicate meta_value entries |
| 179 | 179 | ORDER BY m.meta_id ASC -- sort by oldest meta_value |
| 180 | - "); |
|
| 181 | - sort($values); |
|
| 180 | + " ); |
|
| 181 | + sort( $values ); |
|
| 182 | 182 | return $values; |
| 183 | 183 | } |
| 184 | 184 | |
@@ -186,34 +186,34 @@ discard block |
||
| 186 | 186 | * @param string $and |
| 187 | 187 | * @return string |
| 188 | 188 | */ |
| 189 | - protected function getAndForCounts(array $args, $and = '') |
|
| 189 | + protected function getAndForCounts( array $args, $and = '' ) |
|
| 190 | 190 | { |
| 191 | - $postIds = implode(',', array_filter(glsr_get($args, 'post_ids'))); |
|
| 192 | - $termIds = implode(',', array_filter(glsr_get($args, 'term_ids'))); |
|
| 193 | - if (!empty($args['type'])) { |
|
| 194 | - $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
| 191 | + $postIds = implode( ',', array_filter( glsr_get( $args, 'post_ids' ) ) ); |
|
| 192 | + $termIds = implode( ',', array_filter( glsr_get( $args, 'term_ids' ) ) ); |
|
| 193 | + if( !empty($args['type']) ) { |
|
| 194 | + $and .= "AND m2.meta_value = '{$args['type']}' "; |
|
| 195 | 195 | } |
| 196 | - if ($postIds) { |
|
| 197 | - $and.= "AND m3.meta_key = 'assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
| 196 | + if( $postIds ) { |
|
| 197 | + $and .= "AND m3.meta_key = 'assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
| 198 | 198 | } |
| 199 | - if ($termIds) { |
|
| 200 | - $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
| 199 | + if( $termIds ) { |
|
| 200 | + $and .= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
| 201 | 201 | } |
| 202 | - return apply_filters('site-reviews/query/and-for-counts', $and); |
|
| 202 | + return apply_filters( 'site-reviews/query/and-for-counts', $and ); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
| 206 | 206 | * @param string $innerJoin |
| 207 | 207 | * @return string |
| 208 | 208 | */ |
| 209 | - protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
| 209 | + protected function getInnerJoinForCounts( array $args, $innerJoin = '' ) |
|
| 210 | 210 | { |
| 211 | - if (!empty(glsr_get($args, 'post_ids'))) { |
|
| 212 | - $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
| 211 | + if( !empty(glsr_get( $args, 'post_ids' )) ) { |
|
| 212 | + $innerJoin .= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
| 213 | 213 | } |
| 214 | - if (!empty(glsr_get($args, 'term_ids'))) { |
|
| 215 | - $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
| 214 | + if( !empty(glsr_get( $args, 'term_ids' )) ) { |
|
| 215 | + $innerJoin .= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
| 216 | 216 | } |
| 217 | - return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
| 217 | + return apply_filters( 'site-reviews/query/inner-join-for-counts', $innerJoin ); |
|
| 218 | 218 | } |
| 219 | 219 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @return int|false |
| 21 | 21 | */ |
| 22 | 22 | public function deleteAllSessions($sessionCookiePrefix) |
| 23 | - { |
|
| 23 | + { |
|
| 24 | 24 | return $this->db->query(" |
| 25 | 25 | DELETE |
| 26 | 26 | FROM {$this->db->options} |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @return int|false |
| 34 | 34 | */ |
| 35 | 35 | public function deleteExpiredSessions($expiredSessions) |
| 36 | - { |
|
| 36 | + { |
|
| 37 | 37 | return $this->db->query(" |
| 38 | 38 | DELETE |
| 39 | 39 | FROM {$this->db->options} |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @return array |
| 48 | 48 | */ |
| 49 | 49 | public function getExpiredSessions($sessionCookiePrefix, $limit) |
| 50 | - { |
|
| 50 | + { |
|
| 51 | 51 | return (array) $this->db->get_results(" |
| 52 | 52 | SELECT option_name AS name, option_value AS expiration |
| 53 | 53 | FROM {$this->db->options} |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @return int |
| 63 | 63 | */ |
| 64 | 64 | public function getPostIdFromReviewId($metaReviewId) |
| 65 | - { |
|
| 65 | + { |
|
| 66 | 66 | $postId = $this->db->get_var(" |
| 67 | 67 | SELECT p.ID |
| 68 | 68 | FROM {$this->db->posts} AS p |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @return array |
| 81 | 81 | */ |
| 82 | 82 | public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
| 83 | - { |
|
| 83 | + { |
|
| 84 | 84 | return (array) $this->db->get_results(" |
| 85 | 85 | SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
| 86 | 86 | FROM {$this->db->posts} AS p |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @return array |
| 105 | 105 | */ |
| 106 | 106 | public function getReviewCountsFor($metaKey) |
| 107 | - { |
|
| 107 | + { |
|
| 108 | 108 | return (array) $this->db->get_results(" |
| 109 | 109 | SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts |
| 110 | 110 | FROM {$this->db->posts} AS p |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | 123 | public function getReviewIdsByType($reviewType) |
| 124 | - { |
|
| 124 | + { |
|
| 125 | 125 | $results = $this->db->get_col(" |
| 126 | 126 | SELECT DISTINCT m1.meta_value AS review_id |
| 127 | 127 | FROM {$this->db->posts} AS p |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | 143 | public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
| 144 | - { |
|
| 144 | + { |
|
| 145 | 145 | sort($postIds); |
| 146 | 146 | $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
| 147 | 147 | $postIds = implode(',', $postIds); |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @return array |
| 167 | 167 | */ |
| 168 | 168 | public function getReviewsMeta($key, $status = 'publish') |
| 169 | - { |
|
| 169 | + { |
|
| 170 | 170 | $values = $this->db->get_col(" |
| 171 | 171 | SELECT DISTINCT m.meta_value |
| 172 | 172 | FROM {$this->db->postmeta} m |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * @return string |
| 188 | 188 | */ |
| 189 | 189 | protected function getAndForCounts(array $args, $and = '') |
| 190 | - { |
|
| 190 | + { |
|
| 191 | 191 | $postIds = implode(',', array_filter(glsr_get($args, 'post_ids'))); |
| 192 | 192 | $termIds = implode(',', array_filter(glsr_get($args, 'term_ids'))); |
| 193 | 193 | if (!empty($args['type'])) { |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | * @return string |
| 208 | 208 | */ |
| 209 | 209 | protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
| 210 | - { |
|
| 210 | + { |
|
| 211 | 211 | if (!empty(glsr_get($args, 'post_ids'))) { |
| 212 | 212 | $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
| 213 | 213 | } |
@@ -10,165 +10,165 @@ |
||
| 10 | 10 | |
| 11 | 11 | class QueryBuilder |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Build a WP_Query meta_query/tax_query. |
|
| 15 | - * @return array |
|
| 16 | - */ |
|
| 17 | - public function buildQuery(array $keys = [], array $values = []) |
|
| 18 | - { |
|
| 19 | - $queries = []; |
|
| 20 | - foreach ($keys as $key) { |
|
| 21 | - if (!array_key_exists($key, $values)) { |
|
| 22 | - continue; |
|
| 23 | - } |
|
| 24 | - $methodName = glsr(Helper::class)->buildMethodName($key, __FUNCTION__); |
|
| 25 | - if (!method_exists($this, $methodName)) { |
|
| 26 | - continue; |
|
| 27 | - } |
|
| 28 | - $query = call_user_func([$this, $methodName], $values[$key]); |
|
| 29 | - if (is_array($query)) { |
|
| 30 | - $queries[] = $query; |
|
| 31 | - } |
|
| 32 | - } |
|
| 33 | - return $queries; |
|
| 34 | - } |
|
| 13 | + /** |
|
| 14 | + * Build a WP_Query meta_query/tax_query. |
|
| 15 | + * @return array |
|
| 16 | + */ |
|
| 17 | + public function buildQuery(array $keys = [], array $values = []) |
|
| 18 | + { |
|
| 19 | + $queries = []; |
|
| 20 | + foreach ($keys as $key) { |
|
| 21 | + if (!array_key_exists($key, $values)) { |
|
| 22 | + continue; |
|
| 23 | + } |
|
| 24 | + $methodName = glsr(Helper::class)->buildMethodName($key, __FUNCTION__); |
|
| 25 | + if (!method_exists($this, $methodName)) { |
|
| 26 | + continue; |
|
| 27 | + } |
|
| 28 | + $query = call_user_func([$this, $methodName], $values[$key]); |
|
| 29 | + if (is_array($query)) { |
|
| 30 | + $queries[] = $query; |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | + return $queries; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - public function buildSqlLines(array $values, array $conditions) |
|
| 40 | - { |
|
| 41 | - $string = ''; |
|
| 42 | - $values = array_filter($values); |
|
| 43 | - foreach ($conditions as $key => $value) { |
|
| 44 | - if (!isset($values[$key])) { |
|
| 45 | - continue; |
|
| 46 | - } |
|
| 47 | - $values[$key] = implode(',', (array) $values[$key]); |
|
| 48 | - $string.= false !== strpos($value, '%s') |
|
| 49 | - ? sprintf($value, strval($values[$key])) |
|
| 50 | - : $value; |
|
| 51 | - } |
|
| 52 | - return $string; |
|
| 53 | - } |
|
| 36 | + /** |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + public function buildSqlLines(array $values, array $conditions) |
|
| 40 | + { |
|
| 41 | + $string = ''; |
|
| 42 | + $values = array_filter($values); |
|
| 43 | + foreach ($conditions as $key => $value) { |
|
| 44 | + if (!isset($values[$key])) { |
|
| 45 | + continue; |
|
| 46 | + } |
|
| 47 | + $values[$key] = implode(',', (array) $values[$key]); |
|
| 48 | + $string.= false !== strpos($value, '%s') |
|
| 49 | + ? sprintf($value, strval($values[$key])) |
|
| 50 | + : $value; |
|
| 51 | + } |
|
| 52 | + return $string; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Build a SQL 'OR' string from an array. |
|
| 57 | - * @param string|array $values |
|
| 58 | - * @param string $sprintfFormat |
|
| 59 | - * @return string |
|
| 60 | - */ |
|
| 61 | - public function buildSqlOr($values, $sprintfFormat) |
|
| 62 | - { |
|
| 63 | - if (!is_array($values)) { |
|
| 64 | - $values = explode(',', $values); |
|
| 65 | - } |
|
| 66 | - $values = array_filter(array_map('trim', (array) $values)); |
|
| 67 | - $values = array_map(function ($value) use ($sprintfFormat) { |
|
| 68 | - return sprintf($sprintfFormat, $value); |
|
| 69 | - }, $values); |
|
| 70 | - return implode(' OR ', $values); |
|
| 71 | - } |
|
| 55 | + /** |
|
| 56 | + * Build a SQL 'OR' string from an array. |
|
| 57 | + * @param string|array $values |
|
| 58 | + * @param string $sprintfFormat |
|
| 59 | + * @return string |
|
| 60 | + */ |
|
| 61 | + public function buildSqlOr($values, $sprintfFormat) |
|
| 62 | + { |
|
| 63 | + if (!is_array($values)) { |
|
| 64 | + $values = explode(',', $values); |
|
| 65 | + } |
|
| 66 | + $values = array_filter(array_map('trim', (array) $values)); |
|
| 67 | + $values = array_map(function ($value) use ($sprintfFormat) { |
|
| 68 | + return sprintf($sprintfFormat, $value); |
|
| 69 | + }, $values); |
|
| 70 | + return implode(' OR ', $values); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Search SQL filter for matching against post title only. |
|
| 75 | - * @see http://wordpress.stackexchange.com/a/11826/1685 |
|
| 76 | - * @param string $search |
|
| 77 | - * @return string |
|
| 78 | - * @filter posts_search |
|
| 79 | - */ |
|
| 80 | - public function filterSearchByTitle($search, WP_Query $query) |
|
| 81 | - { |
|
| 82 | - if (empty($search) || empty($query->get('search_terms'))) { |
|
| 83 | - return $search; |
|
| 84 | - } |
|
| 85 | - global $wpdb; |
|
| 86 | - $n = empty($query->get('exact')) |
|
| 87 | - ? '%' |
|
| 88 | - : ''; |
|
| 89 | - $search = []; |
|
| 90 | - foreach ((array) $query->get('search_terms') as $term) { |
|
| 91 | - $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
| 92 | - } |
|
| 93 | - if (!is_user_logged_in()) { |
|
| 94 | - $search[] = "{$wpdb->posts}.post_password = ''"; |
|
| 95 | - } |
|
| 96 | - return ' AND '.implode(' AND ', $search); |
|
| 97 | - } |
|
| 73 | + /** |
|
| 74 | + * Search SQL filter for matching against post title only. |
|
| 75 | + * @see http://wordpress.stackexchange.com/a/11826/1685 |
|
| 76 | + * @param string $search |
|
| 77 | + * @return string |
|
| 78 | + * @filter posts_search |
|
| 79 | + */ |
|
| 80 | + public function filterSearchByTitle($search, WP_Query $query) |
|
| 81 | + { |
|
| 82 | + if (empty($search) || empty($query->get('search_terms'))) { |
|
| 83 | + return $search; |
|
| 84 | + } |
|
| 85 | + global $wpdb; |
|
| 86 | + $n = empty($query->get('exact')) |
|
| 87 | + ? '%' |
|
| 88 | + : ''; |
|
| 89 | + $search = []; |
|
| 90 | + foreach ((array) $query->get('search_terms') as $term) { |
|
| 91 | + $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
| 92 | + } |
|
| 93 | + if (!is_user_logged_in()) { |
|
| 94 | + $search[] = "{$wpdb->posts}.post_password = ''"; |
|
| 95 | + } |
|
| 96 | + return ' AND '.implode(' AND ', $search); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Get the current page number from the global query. |
|
| 101 | - * @param bool $isEnabled |
|
| 102 | - * @return int |
|
| 103 | - */ |
|
| 104 | - public function getPaged($isEnabled = true) |
|
| 105 | - { |
|
| 106 | - $pagedQuery = !is_front_page() |
|
| 107 | - ? glsr()->constant('PAGED_QUERY_VAR') |
|
| 108 | - : 'page'; |
|
| 109 | - return $isEnabled |
|
| 110 | - ? max(1, intval(get_query_var($pagedQuery))) |
|
| 111 | - : 1; |
|
| 112 | - } |
|
| 99 | + /** |
|
| 100 | + * Get the current page number from the global query. |
|
| 101 | + * @param bool $isEnabled |
|
| 102 | + * @return int |
|
| 103 | + */ |
|
| 104 | + public function getPaged($isEnabled = true) |
|
| 105 | + { |
|
| 106 | + $pagedQuery = !is_front_page() |
|
| 107 | + ? glsr()->constant('PAGED_QUERY_VAR') |
|
| 108 | + : 'page'; |
|
| 109 | + return $isEnabled |
|
| 110 | + ? max(1, intval(get_query_var($pagedQuery))) |
|
| 111 | + : 1; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * @param string $value |
|
| 116 | - * @return void|array |
|
| 117 | - */ |
|
| 118 | - protected function buildQueryAssignedTo($value) |
|
| 119 | - { |
|
| 120 | - if (!empty($value)) { |
|
| 121 | - $postIds = glsr(Helper::class)->convertStringToArray($value, 'is_numeric'); |
|
| 122 | - return [ |
|
| 123 | - 'compare' => 'IN', |
|
| 124 | - 'key' => 'assigned_to', |
|
| 125 | - 'value' => glsr(Polylang::class)->getPostIds($postIds), |
|
| 126 | - ]; |
|
| 127 | - } |
|
| 128 | - } |
|
| 114 | + /** |
|
| 115 | + * @param string $value |
|
| 116 | + * @return void|array |
|
| 117 | + */ |
|
| 118 | + protected function buildQueryAssignedTo($value) |
|
| 119 | + { |
|
| 120 | + if (!empty($value)) { |
|
| 121 | + $postIds = glsr(Helper::class)->convertStringToArray($value, 'is_numeric'); |
|
| 122 | + return [ |
|
| 123 | + 'compare' => 'IN', |
|
| 124 | + 'key' => 'assigned_to', |
|
| 125 | + 'value' => glsr(Polylang::class)->getPostIds($postIds), |
|
| 126 | + ]; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * @param array $value |
|
| 132 | - * @return void|array |
|
| 133 | - */ |
|
| 134 | - protected function buildQueryCategory($value) |
|
| 135 | - { |
|
| 136 | - if (!empty($value)) { |
|
| 137 | - return [ |
|
| 138 | - 'field' => 'term_id', |
|
| 139 | - 'taxonomy' => Application::TAXONOMY, |
|
| 140 | - 'terms' => $value, |
|
| 141 | - ]; |
|
| 142 | - } |
|
| 143 | - } |
|
| 130 | + /** |
|
| 131 | + * @param array $value |
|
| 132 | + * @return void|array |
|
| 133 | + */ |
|
| 134 | + protected function buildQueryCategory($value) |
|
| 135 | + { |
|
| 136 | + if (!empty($value)) { |
|
| 137 | + return [ |
|
| 138 | + 'field' => 'term_id', |
|
| 139 | + 'taxonomy' => Application::TAXONOMY, |
|
| 140 | + 'terms' => $value, |
|
| 141 | + ]; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * @param string $value |
|
| 147 | - * @return void|array |
|
| 148 | - */ |
|
| 149 | - protected function buildQueryRating($value) |
|
| 150 | - { |
|
| 151 | - if (is_numeric($value) |
|
| 152 | - && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
| 153 | - return [ |
|
| 154 | - 'compare' => '>=', |
|
| 155 | - 'key' => 'rating', |
|
| 156 | - 'value' => $value, |
|
| 157 | - ]; |
|
| 158 | - } |
|
| 159 | - } |
|
| 145 | + /** |
|
| 146 | + * @param string $value |
|
| 147 | + * @return void|array |
|
| 148 | + */ |
|
| 149 | + protected function buildQueryRating($value) |
|
| 150 | + { |
|
| 151 | + if (is_numeric($value) |
|
| 152 | + && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
| 153 | + return [ |
|
| 154 | + 'compare' => '>=', |
|
| 155 | + 'key' => 'rating', |
|
| 156 | + 'value' => $value, |
|
| 157 | + ]; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * @param string $value |
|
| 163 | - * @return void|array |
|
| 164 | - */ |
|
| 165 | - protected function buildQueryType($value) |
|
| 166 | - { |
|
| 167 | - if (!in_array($value, ['', 'all'])) { |
|
| 168 | - return [ |
|
| 169 | - 'key' => 'review_type', |
|
| 170 | - 'value' => $value, |
|
| 171 | - ]; |
|
| 172 | - } |
|
| 173 | - } |
|
| 161 | + /** |
|
| 162 | + * @param string $value |
|
| 163 | + * @return void|array |
|
| 164 | + */ |
|
| 165 | + protected function buildQueryType($value) |
|
| 166 | + { |
|
| 167 | + if (!in_array($value, ['', 'all'])) { |
|
| 168 | + return [ |
|
| 169 | + 'key' => 'review_type', |
|
| 170 | + 'value' => $value, |
|
| 171 | + ]; |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | 174 | } |
@@ -14,19 +14,19 @@ discard block |
||
| 14 | 14 | * Build a WP_Query meta_query/tax_query. |
| 15 | 15 | * @return array |
| 16 | 16 | */ |
| 17 | - public function buildQuery(array $keys = [], array $values = []) |
|
| 17 | + public function buildQuery( array $keys = [], array $values = [] ) |
|
| 18 | 18 | { |
| 19 | 19 | $queries = []; |
| 20 | - foreach ($keys as $key) { |
|
| 21 | - if (!array_key_exists($key, $values)) { |
|
| 20 | + foreach( $keys as $key ) { |
|
| 21 | + if( !array_key_exists( $key, $values ) ) { |
|
| 22 | 22 | continue; |
| 23 | 23 | } |
| 24 | - $methodName = glsr(Helper::class)->buildMethodName($key, __FUNCTION__); |
|
| 25 | - if (!method_exists($this, $methodName)) { |
|
| 24 | + $methodName = glsr( Helper::class )->buildMethodName( $key, __FUNCTION__ ); |
|
| 25 | + if( !method_exists( $this, $methodName ) ) { |
|
| 26 | 26 | continue; |
| 27 | 27 | } |
| 28 | - $query = call_user_func([$this, $methodName], $values[$key]); |
|
| 29 | - if (is_array($query)) { |
|
| 28 | + $query = call_user_func( [$this, $methodName], $values[$key] ); |
|
| 29 | + if( is_array( $query ) ) { |
|
| 30 | 30 | $queries[] = $query; |
| 31 | 31 | } |
| 32 | 32 | } |
@@ -36,17 +36,17 @@ discard block |
||
| 36 | 36 | /** |
| 37 | 37 | * @return string |
| 38 | 38 | */ |
| 39 | - public function buildSqlLines(array $values, array $conditions) |
|
| 39 | + public function buildSqlLines( array $values, array $conditions ) |
|
| 40 | 40 | { |
| 41 | 41 | $string = ''; |
| 42 | - $values = array_filter($values); |
|
| 43 | - foreach ($conditions as $key => $value) { |
|
| 44 | - if (!isset($values[$key])) { |
|
| 42 | + $values = array_filter( $values ); |
|
| 43 | + foreach( $conditions as $key => $value ) { |
|
| 44 | + if( !isset($values[$key]) ) { |
|
| 45 | 45 | continue; |
| 46 | 46 | } |
| 47 | - $values[$key] = implode(',', (array) $values[$key]); |
|
| 48 | - $string.= false !== strpos($value, '%s') |
|
| 49 | - ? sprintf($value, strval($values[$key])) |
|
| 47 | + $values[$key] = implode( ',', (array)$values[$key] ); |
|
| 48 | + $string .= false !== strpos( $value, '%s' ) |
|
| 49 | + ? sprintf( $value, strval( $values[$key] ) ) |
|
| 50 | 50 | : $value; |
| 51 | 51 | } |
| 52 | 52 | return $string; |
@@ -58,16 +58,16 @@ discard block |
||
| 58 | 58 | * @param string $sprintfFormat |
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | - public function buildSqlOr($values, $sprintfFormat) |
|
| 61 | + public function buildSqlOr( $values, $sprintfFormat ) |
|
| 62 | 62 | { |
| 63 | - if (!is_array($values)) { |
|
| 64 | - $values = explode(',', $values); |
|
| 63 | + if( !is_array( $values ) ) { |
|
| 64 | + $values = explode( ',', $values ); |
|
| 65 | 65 | } |
| 66 | - $values = array_filter(array_map('trim', (array) $values)); |
|
| 67 | - $values = array_map(function ($value) use ($sprintfFormat) { |
|
| 68 | - return sprintf($sprintfFormat, $value); |
|
| 69 | - }, $values); |
|
| 70 | - return implode(' OR ', $values); |
|
| 66 | + $values = array_filter( array_map( 'trim', (array)$values ) ); |
|
| 67 | + $values = array_map( function( $value ) use ($sprintfFormat) { |
|
| 68 | + return sprintf( $sprintfFormat, $value ); |
|
| 69 | + }, $values ); |
|
| 70 | + return implode( ' OR ', $values ); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -77,23 +77,23 @@ discard block |
||
| 77 | 77 | * @return string |
| 78 | 78 | * @filter posts_search |
| 79 | 79 | */ |
| 80 | - public function filterSearchByTitle($search, WP_Query $query) |
|
| 80 | + public function filterSearchByTitle( $search, WP_Query $query ) |
|
| 81 | 81 | { |
| 82 | - if (empty($search) || empty($query->get('search_terms'))) { |
|
| 82 | + if( empty($search) || empty($query->get( 'search_terms' )) ) { |
|
| 83 | 83 | return $search; |
| 84 | 84 | } |
| 85 | 85 | global $wpdb; |
| 86 | - $n = empty($query->get('exact')) |
|
| 86 | + $n = empty($query->get( 'exact' )) |
|
| 87 | 87 | ? '%' |
| 88 | 88 | : ''; |
| 89 | 89 | $search = []; |
| 90 | - foreach ((array) $query->get('search_terms') as $term) { |
|
| 91 | - $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
| 90 | + foreach( (array)$query->get( 'search_terms' ) as $term ) { |
|
| 91 | + $search[] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like( $term ).$n ); |
|
| 92 | 92 | } |
| 93 | - if (!is_user_logged_in()) { |
|
| 93 | + if( !is_user_logged_in() ) { |
|
| 94 | 94 | $search[] = "{$wpdb->posts}.post_password = ''"; |
| 95 | 95 | } |
| 96 | - return ' AND '.implode(' AND ', $search); |
|
| 96 | + return ' AND '.implode( ' AND ', $search ); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -101,13 +101,13 @@ discard block |
||
| 101 | 101 | * @param bool $isEnabled |
| 102 | 102 | * @return int |
| 103 | 103 | */ |
| 104 | - public function getPaged($isEnabled = true) |
|
| 104 | + public function getPaged( $isEnabled = true ) |
|
| 105 | 105 | { |
| 106 | 106 | $pagedQuery = !is_front_page() |
| 107 | - ? glsr()->constant('PAGED_QUERY_VAR') |
|
| 107 | + ? glsr()->constant( 'PAGED_QUERY_VAR' ) |
|
| 108 | 108 | : 'page'; |
| 109 | 109 | return $isEnabled |
| 110 | - ? max(1, intval(get_query_var($pagedQuery))) |
|
| 110 | + ? max( 1, intval( get_query_var( $pagedQuery ) ) ) |
|
| 111 | 111 | : 1; |
| 112 | 112 | } |
| 113 | 113 | |
@@ -115,14 +115,14 @@ discard block |
||
| 115 | 115 | * @param string $value |
| 116 | 116 | * @return void|array |
| 117 | 117 | */ |
| 118 | - protected function buildQueryAssignedTo($value) |
|
| 118 | + protected function buildQueryAssignedTo( $value ) |
|
| 119 | 119 | { |
| 120 | - if (!empty($value)) { |
|
| 121 | - $postIds = glsr(Helper::class)->convertStringToArray($value, 'is_numeric'); |
|
| 120 | + if( !empty($value) ) { |
|
| 121 | + $postIds = glsr( Helper::class )->convertStringToArray( $value, 'is_numeric' ); |
|
| 122 | 122 | return [ |
| 123 | 123 | 'compare' => 'IN', |
| 124 | 124 | 'key' => 'assigned_to', |
| 125 | - 'value' => glsr(Polylang::class)->getPostIds($postIds), |
|
| 125 | + 'value' => glsr( Polylang::class )->getPostIds( $postIds ), |
|
| 126 | 126 | ]; |
| 127 | 127 | } |
| 128 | 128 | } |
@@ -131,9 +131,9 @@ discard block |
||
| 131 | 131 | * @param array $value |
| 132 | 132 | * @return void|array |
| 133 | 133 | */ |
| 134 | - protected function buildQueryCategory($value) |
|
| 134 | + protected function buildQueryCategory( $value ) |
|
| 135 | 135 | { |
| 136 | - if (!empty($value)) { |
|
| 136 | + if( !empty($value) ) { |
|
| 137 | 137 | return [ |
| 138 | 138 | 'field' => 'term_id', |
| 139 | 139 | 'taxonomy' => Application::TAXONOMY, |
@@ -146,10 +146,10 @@ discard block |
||
| 146 | 146 | * @param string $value |
| 147 | 147 | * @return void|array |
| 148 | 148 | */ |
| 149 | - protected function buildQueryRating($value) |
|
| 149 | + protected function buildQueryRating( $value ) |
|
| 150 | 150 | { |
| 151 | - if (is_numeric($value) |
|
| 152 | - && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
| 151 | + if( is_numeric( $value ) |
|
| 152 | + && in_array( intval( $value ), range( 1, glsr()->constant( 'MAX_RATING', Rating::class ) ) ) ) { |
|
| 153 | 153 | return [ |
| 154 | 154 | 'compare' => '>=', |
| 155 | 155 | 'key' => 'rating', |
@@ -162,9 +162,9 @@ discard block |
||
| 162 | 162 | * @param string $value |
| 163 | 163 | * @return void|array |
| 164 | 164 | */ |
| 165 | - protected function buildQueryType($value) |
|
| 165 | + protected function buildQueryType( $value ) |
|
| 166 | 166 | { |
| 167 | - if (!in_array($value, ['', 'all'])) { |
|
| 167 | + if( !in_array( $value, ['', 'all'] ) ) { |
|
| 168 | 168 | return [ |
| 169 | 169 | 'key' => 'review_type', |
| 170 | 170 | 'value' => $value, |
@@ -7,342 +7,342 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Helper |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @param string $name |
|
| 12 | - * @param string $path |
|
| 13 | - * @return string |
|
| 14 | - */ |
|
| 15 | - public function buildClassName($name, $path = '') |
|
| 16 | - { |
|
| 17 | - $className = $this->camelCase($name); |
|
| 18 | - $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
| 19 | - return !empty($path) |
|
| 20 | - ? __NAMESPACE__.'\\'.$path.'\\'.$className |
|
| 21 | - : $className; |
|
| 22 | - } |
|
| 10 | + /** |
|
| 11 | + * @param string $name |
|
| 12 | + * @param string $path |
|
| 13 | + * @return string |
|
| 14 | + */ |
|
| 15 | + public function buildClassName($name, $path = '') |
|
| 16 | + { |
|
| 17 | + $className = $this->camelCase($name); |
|
| 18 | + $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
| 19 | + return !empty($path) |
|
| 20 | + ? __NAMESPACE__.'\\'.$path.'\\'.$className |
|
| 21 | + : $className; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @param string $name |
|
| 26 | - * @param string $prefix |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function buildMethodName($name, $prefix = '') |
|
| 30 | - { |
|
| 31 | - return lcfirst($prefix.$this->buildClassName($name)); |
|
| 32 | - } |
|
| 24 | + /** |
|
| 25 | + * @param string $name |
|
| 26 | + * @param string $prefix |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function buildMethodName($name, $prefix = '') |
|
| 30 | + { |
|
| 31 | + return lcfirst($prefix.$this->buildClassName($name)); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param string $name |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public function buildPropertyName($name) |
|
| 39 | - { |
|
| 40 | - return lcfirst($this->buildClassName($name)); |
|
| 41 | - } |
|
| 34 | + /** |
|
| 35 | + * @param string $name |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public function buildPropertyName($name) |
|
| 39 | + { |
|
| 40 | + return lcfirst($this->buildClassName($name)); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param string $string |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public function camelCase($string) |
|
| 48 | - { |
|
| 49 | - $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
| 50 | - return str_replace(' ', '', $string); |
|
| 51 | - } |
|
| 43 | + /** |
|
| 44 | + * @param string $string |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public function camelCase($string) |
|
| 48 | + { |
|
| 49 | + $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
| 50 | + return str_replace(' ', '', $string); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return bool |
|
| 55 | - */ |
|
| 56 | - public function compareArrays(array $arr1, array $arr2) |
|
| 57 | - { |
|
| 58 | - sort($arr1); |
|
| 59 | - sort($arr2); |
|
| 60 | - return $arr1 == $arr2; |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * @return bool |
|
| 55 | + */ |
|
| 56 | + public function compareArrays(array $arr1, array $arr2) |
|
| 57 | + { |
|
| 58 | + sort($arr1); |
|
| 59 | + sort($arr2); |
|
| 60 | + return $arr1 == $arr2; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @param mixed $array |
|
| 65 | - * @return array |
|
| 66 | - */ |
|
| 67 | - public function consolidateArray($array) |
|
| 68 | - { |
|
| 69 | - return is_array($array) || is_object($array) |
|
| 70 | - ? (array) $array |
|
| 71 | - : []; |
|
| 72 | - } |
|
| 63 | + /** |
|
| 64 | + * @param mixed $array |
|
| 65 | + * @return array |
|
| 66 | + */ |
|
| 67 | + public function consolidateArray($array) |
|
| 68 | + { |
|
| 69 | + return is_array($array) || is_object($array) |
|
| 70 | + ? (array) $array |
|
| 71 | + : []; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @return array |
|
| 76 | - */ |
|
| 77 | - public function convertDotNotationArray(array $array) |
|
| 78 | - { |
|
| 79 | - $results = []; |
|
| 80 | - foreach ($array as $path => $value) { |
|
| 81 | - $results = $this->dataSet($results, $path, $value); |
|
| 82 | - } |
|
| 83 | - return $results; |
|
| 84 | - } |
|
| 74 | + /** |
|
| 75 | + * @return array |
|
| 76 | + */ |
|
| 77 | + public function convertDotNotationArray(array $array) |
|
| 78 | + { |
|
| 79 | + $results = []; |
|
| 80 | + foreach ($array as $path => $value) { |
|
| 81 | + $results = $this->dataSet($results, $path, $value); |
|
| 82 | + } |
|
| 83 | + return $results; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * @param string $name |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - public function convertPathToId($path, $prefix = '') |
|
| 91 | - { |
|
| 92 | - return str_replace(['[', ']'], ['-', ''], $this->convertPathToName($path, $prefix)); |
|
| 93 | - } |
|
| 86 | + /** |
|
| 87 | + * @param string $name |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + public function convertPathToId($path, $prefix = '') |
|
| 91 | + { |
|
| 92 | + return str_replace(['[', ']'], ['-', ''], $this->convertPathToName($path, $prefix)); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * @param string $path |
|
| 97 | - * @return string |
|
| 98 | - */ |
|
| 99 | - public function convertPathToName($path, $prefix = '') |
|
| 100 | - { |
|
| 101 | - $levels = explode('.', $path); |
|
| 102 | - return array_reduce($levels, function ($result, $value) { |
|
| 103 | - return $result.= '['.$value.']'; |
|
| 104 | - }, $prefix); |
|
| 105 | - } |
|
| 95 | + /** |
|
| 96 | + * @param string $path |
|
| 97 | + * @return string |
|
| 98 | + */ |
|
| 99 | + public function convertPathToName($path, $prefix = '') |
|
| 100 | + { |
|
| 101 | + $levels = explode('.', $path); |
|
| 102 | + return array_reduce($levels, function ($result, $value) { |
|
| 103 | + return $result.= '['.$value.']'; |
|
| 104 | + }, $prefix); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @param string $string |
|
| 109 | - * @param mixed $callback |
|
| 110 | - * @return array |
|
| 111 | - */ |
|
| 112 | - public function convertStringToArray($string, $callback = null) |
|
| 113 | - { |
|
| 114 | - $array = array_map('trim', explode(',', $string)); |
|
| 115 | - return $callback |
|
| 116 | - ? array_filter($array, $callback) |
|
| 117 | - : array_filter($array); |
|
| 118 | - } |
|
| 107 | + /** |
|
| 108 | + * @param string $string |
|
| 109 | + * @param mixed $callback |
|
| 110 | + * @return array |
|
| 111 | + */ |
|
| 112 | + public function convertStringToArray($string, $callback = null) |
|
| 113 | + { |
|
| 114 | + $array = array_map('trim', explode(',', $string)); |
|
| 115 | + return $callback |
|
| 116 | + ? array_filter($array, $callback) |
|
| 117 | + : array_filter($array); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * @param string $string |
|
| 122 | - * @return string |
|
| 123 | - */ |
|
| 124 | - public function dashCase($string) |
|
| 125 | - { |
|
| 126 | - return str_replace('_', '-', $this->snakeCase($string)); |
|
| 127 | - } |
|
| 120 | + /** |
|
| 121 | + * @param string $string |
|
| 122 | + * @return string |
|
| 123 | + */ |
|
| 124 | + public function dashCase($string) |
|
| 125 | + { |
|
| 126 | + return str_replace('_', '-', $this->snakeCase($string)); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Get a value from an array of values using a dot-notation path as reference. |
|
| 131 | - * @param array $data |
|
| 132 | - * @param string $path |
|
| 133 | - * @param mixed $fallback |
|
| 134 | - * @return mixed |
|
| 135 | - */ |
|
| 136 | - public function dataGet($data, $path = '', $fallback = '') |
|
| 137 | - { |
|
| 138 | - $data = $this->consolidateArray($data); |
|
| 139 | - $keys = explode('.', $path); |
|
| 140 | - foreach ($keys as $key) { |
|
| 141 | - if (!isset($data[$key])) { |
|
| 142 | - return $fallback; |
|
| 143 | - } |
|
| 144 | - $data = $data[$key]; |
|
| 145 | - } |
|
| 146 | - return $data; |
|
| 147 | - } |
|
| 129 | + /** |
|
| 130 | + * Get a value from an array of values using a dot-notation path as reference. |
|
| 131 | + * @param array $data |
|
| 132 | + * @param string $path |
|
| 133 | + * @param mixed $fallback |
|
| 134 | + * @return mixed |
|
| 135 | + */ |
|
| 136 | + public function dataGet($data, $path = '', $fallback = '') |
|
| 137 | + { |
|
| 138 | + $data = $this->consolidateArray($data); |
|
| 139 | + $keys = explode('.', $path); |
|
| 140 | + foreach ($keys as $key) { |
|
| 141 | + if (!isset($data[$key])) { |
|
| 142 | + return $fallback; |
|
| 143 | + } |
|
| 144 | + $data = $data[$key]; |
|
| 145 | + } |
|
| 146 | + return $data; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * Set a value to an array of values using a dot-notation path as reference. |
|
| 151 | - * @param string $path |
|
| 152 | - * @param mixed $value |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 155 | - public function dataSet(array $data, $path = '', $value) |
|
| 156 | - { |
|
| 157 | - $token = strtok($path, '.'); |
|
| 158 | - $ref = &$data; |
|
| 159 | - while (false !== $token) { |
|
| 160 | - $ref = $this->consolidateArray($ref); |
|
| 161 | - $ref = &$ref[$token]; |
|
| 162 | - $token = strtok('.'); |
|
| 163 | - } |
|
| 164 | - $ref = $value; |
|
| 165 | - return $data; |
|
| 166 | - } |
|
| 149 | + /** |
|
| 150 | + * Set a value to an array of values using a dot-notation path as reference. |
|
| 151 | + * @param string $path |
|
| 152 | + * @param mixed $value |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | + public function dataSet(array $data, $path = '', $value) |
|
| 156 | + { |
|
| 157 | + $token = strtok($path, '.'); |
|
| 158 | + $ref = &$data; |
|
| 159 | + while (false !== $token) { |
|
| 160 | + $ref = $this->consolidateArray($ref); |
|
| 161 | + $ref = &$ref[$token]; |
|
| 162 | + $token = strtok('.'); |
|
| 163 | + } |
|
| 164 | + $ref = $value; |
|
| 165 | + return $data; |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * @param string $needle |
|
| 170 | - * @param string $haystack |
|
| 171 | - * @return bool |
|
| 172 | - */ |
|
| 173 | - public function endsWith($needle, $haystack) |
|
| 174 | - { |
|
| 175 | - $length = strlen($needle); |
|
| 176 | - return 0 != $length |
|
| 177 | - ? substr($haystack, -$length) === $needle |
|
| 178 | - : true; |
|
| 179 | - } |
|
| 168 | + /** |
|
| 169 | + * @param string $needle |
|
| 170 | + * @param string $haystack |
|
| 171 | + * @return bool |
|
| 172 | + */ |
|
| 173 | + public function endsWith($needle, $haystack) |
|
| 174 | + { |
|
| 175 | + $length = strlen($needle); |
|
| 176 | + return 0 != $length |
|
| 177 | + ? substr($haystack, -$length) === $needle |
|
| 178 | + : true; |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * @param string $key |
|
| 183 | - * @return mixed |
|
| 184 | - */ |
|
| 185 | - public function filterInput($key, array $request = []) |
|
| 186 | - { |
|
| 187 | - if (isset($request[$key])) { |
|
| 188 | - return $request[$key]; |
|
| 189 | - } |
|
| 190 | - $variable = filter_input(INPUT_POST, $key); |
|
| 191 | - if (is_null($variable) && isset($_POST[$key])) { |
|
| 192 | - $variable = $_POST[$key]; |
|
| 193 | - } |
|
| 194 | - return $variable; |
|
| 195 | - } |
|
| 181 | + /** |
|
| 182 | + * @param string $key |
|
| 183 | + * @return mixed |
|
| 184 | + */ |
|
| 185 | + public function filterInput($key, array $request = []) |
|
| 186 | + { |
|
| 187 | + if (isset($request[$key])) { |
|
| 188 | + return $request[$key]; |
|
| 189 | + } |
|
| 190 | + $variable = filter_input(INPUT_POST, $key); |
|
| 191 | + if (is_null($variable) && isset($_POST[$key])) { |
|
| 192 | + $variable = $_POST[$key]; |
|
| 193 | + } |
|
| 194 | + return $variable; |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * @param string $key |
|
| 199 | - * @return array |
|
| 200 | - */ |
|
| 201 | - public function filterInputArray($key) |
|
| 202 | - { |
|
| 203 | - $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 204 | - if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
| 205 | - $variable = $_POST[$key]; |
|
| 206 | - } |
|
| 207 | - return (array) $variable; |
|
| 208 | - } |
|
| 197 | + /** |
|
| 198 | + * @param string $key |
|
| 199 | + * @return array |
|
| 200 | + */ |
|
| 201 | + public function filterInputArray($key) |
|
| 202 | + { |
|
| 203 | + $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 204 | + if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
| 205 | + $variable = $_POST[$key]; |
|
| 206 | + } |
|
| 207 | + return (array) $variable; |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * @param bool $flattenValue |
|
| 212 | - * @param string $prefix |
|
| 213 | - * @return array |
|
| 214 | - */ |
|
| 215 | - public function flattenArray(array $array, $flattenValue = false, $prefix = '') |
|
| 216 | - { |
|
| 217 | - $result = []; |
|
| 218 | - foreach ($array as $key => $value) { |
|
| 219 | - $newKey = ltrim($prefix.'.'.$key, '.'); |
|
| 220 | - if ($this->isIndexedFlatArray($value)) { |
|
| 221 | - if ($flattenValue) { |
|
| 222 | - $value = '['.implode(', ', $value).']'; |
|
| 223 | - } |
|
| 224 | - } elseif (is_array($value)) { |
|
| 225 | - $result = array_merge($result, $this->flattenArray($value, $flattenValue, $newKey)); |
|
| 226 | - continue; |
|
| 227 | - } |
|
| 228 | - $result[$newKey] = $value; |
|
| 229 | - } |
|
| 230 | - return $result; |
|
| 231 | - } |
|
| 210 | + /** |
|
| 211 | + * @param bool $flattenValue |
|
| 212 | + * @param string $prefix |
|
| 213 | + * @return array |
|
| 214 | + */ |
|
| 215 | + public function flattenArray(array $array, $flattenValue = false, $prefix = '') |
|
| 216 | + { |
|
| 217 | + $result = []; |
|
| 218 | + foreach ($array as $key => $value) { |
|
| 219 | + $newKey = ltrim($prefix.'.'.$key, '.'); |
|
| 220 | + if ($this->isIndexedFlatArray($value)) { |
|
| 221 | + if ($flattenValue) { |
|
| 222 | + $value = '['.implode(', ', $value).']'; |
|
| 223 | + } |
|
| 224 | + } elseif (is_array($value)) { |
|
| 225 | + $result = array_merge($result, $this->flattenArray($value, $flattenValue, $newKey)); |
|
| 226 | + continue; |
|
| 227 | + } |
|
| 228 | + $result[$newKey] = $value; |
|
| 229 | + } |
|
| 230 | + return $result; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * @return string |
|
| 235 | - */ |
|
| 236 | - public function getIpAddress() |
|
| 237 | - { |
|
| 238 | - $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
| 239 | - $ipv6 = defined('AF_INET6') |
|
| 240 | - ? $cloudflareIps['v6'] |
|
| 241 | - : []; |
|
| 242 | - $whitelist = apply_filters('site-reviews/whip/whitelist', [ |
|
| 243 | - Whip::CLOUDFLARE_HEADERS => [ |
|
| 244 | - Whip::IPV4 => $cloudflareIps['v4'], |
|
| 245 | - Whip::IPV6 => $ipv6, |
|
| 246 | - ], |
|
| 247 | - ]); |
|
| 248 | - $whip = new Whip(Whip::ALL_METHODS, $whitelist); |
|
| 249 | - do_action_ref_array('site-reviews/whip', [&$whip]); |
|
| 250 | - return (string) $whip->getValidIpAddress(); |
|
| 251 | - } |
|
| 233 | + /** |
|
| 234 | + * @return string |
|
| 235 | + */ |
|
| 236 | + public function getIpAddress() |
|
| 237 | + { |
|
| 238 | + $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
| 239 | + $ipv6 = defined('AF_INET6') |
|
| 240 | + ? $cloudflareIps['v6'] |
|
| 241 | + : []; |
|
| 242 | + $whitelist = apply_filters('site-reviews/whip/whitelist', [ |
|
| 243 | + Whip::CLOUDFLARE_HEADERS => [ |
|
| 244 | + Whip::IPV4 => $cloudflareIps['v4'], |
|
| 245 | + Whip::IPV6 => $ipv6, |
|
| 246 | + ], |
|
| 247 | + ]); |
|
| 248 | + $whip = new Whip(Whip::ALL_METHODS, $whitelist); |
|
| 249 | + do_action_ref_array('site-reviews/whip', [&$whip]); |
|
| 250 | + return (string) $whip->getValidIpAddress(); |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * @param string $key |
|
| 255 | - * @param string $position |
|
| 256 | - * @return array |
|
| 257 | - */ |
|
| 258 | - public function insertInArray(array $array, array $insert, $key, $position = 'before') |
|
| 259 | - { |
|
| 260 | - $keyPosition = intval(array_search($key, array_keys($array))); |
|
| 261 | - if ('after' == $position) { |
|
| 262 | - ++$keyPosition; |
|
| 263 | - } |
|
| 264 | - if (false !== $keyPosition) { |
|
| 265 | - $result = array_slice($array, 0, $keyPosition); |
|
| 266 | - $result = array_merge($result, $insert); |
|
| 267 | - return array_merge($result, array_slice($array, $keyPosition)); |
|
| 268 | - } |
|
| 269 | - return array_merge($array, $insert); |
|
| 270 | - } |
|
| 253 | + /** |
|
| 254 | + * @param string $key |
|
| 255 | + * @param string $position |
|
| 256 | + * @return array |
|
| 257 | + */ |
|
| 258 | + public function insertInArray(array $array, array $insert, $key, $position = 'before') |
|
| 259 | + { |
|
| 260 | + $keyPosition = intval(array_search($key, array_keys($array))); |
|
| 261 | + if ('after' == $position) { |
|
| 262 | + ++$keyPosition; |
|
| 263 | + } |
|
| 264 | + if (false !== $keyPosition) { |
|
| 265 | + $result = array_slice($array, 0, $keyPosition); |
|
| 266 | + $result = array_merge($result, $insert); |
|
| 267 | + return array_merge($result, array_slice($array, $keyPosition)); |
|
| 268 | + } |
|
| 269 | + return array_merge($array, $insert); |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | - /** |
|
| 273 | - * @param mixed $array |
|
| 274 | - * @return bool |
|
| 275 | - */ |
|
| 276 | - public function isIndexedFlatArray($array) |
|
| 277 | - { |
|
| 278 | - if (!is_array($array) || array_filter($array, 'is_array')) { |
|
| 279 | - return false; |
|
| 280 | - } |
|
| 281 | - return wp_is_numeric_array($array); |
|
| 282 | - } |
|
| 272 | + /** |
|
| 273 | + * @param mixed $array |
|
| 274 | + * @return bool |
|
| 275 | + */ |
|
| 276 | + public function isIndexedFlatArray($array) |
|
| 277 | + { |
|
| 278 | + if (!is_array($array) || array_filter($array, 'is_array')) { |
|
| 279 | + return false; |
|
| 280 | + } |
|
| 281 | + return wp_is_numeric_array($array); |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - /** |
|
| 285 | - * @param string $string |
|
| 286 | - * @param string $prefix |
|
| 287 | - * @return string |
|
| 288 | - */ |
|
| 289 | - public function prefixString($string, $prefix = '') |
|
| 290 | - { |
|
| 291 | - return $prefix.str_replace($prefix, '', trim($string)); |
|
| 292 | - } |
|
| 284 | + /** |
|
| 285 | + * @param string $string |
|
| 286 | + * @param string $prefix |
|
| 287 | + * @return string |
|
| 288 | + */ |
|
| 289 | + public function prefixString($string, $prefix = '') |
|
| 290 | + { |
|
| 291 | + return $prefix.str_replace($prefix, '', trim($string)); |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - /** |
|
| 295 | - * @return array |
|
| 296 | - */ |
|
| 297 | - public function removeEmptyArrayValues(array $array) |
|
| 298 | - { |
|
| 299 | - $result = []; |
|
| 300 | - foreach ($array as $key => $value) { |
|
| 301 | - if (!$value) { |
|
| 302 | - continue; |
|
| 303 | - } |
|
| 304 | - $result[$key] = is_array($value) |
|
| 305 | - ? $this->removeEmptyArrayValues($value) |
|
| 306 | - : $value; |
|
| 307 | - } |
|
| 308 | - return $result; |
|
| 309 | - } |
|
| 294 | + /** |
|
| 295 | + * @return array |
|
| 296 | + */ |
|
| 297 | + public function removeEmptyArrayValues(array $array) |
|
| 298 | + { |
|
| 299 | + $result = []; |
|
| 300 | + foreach ($array as $key => $value) { |
|
| 301 | + if (!$value) { |
|
| 302 | + continue; |
|
| 303 | + } |
|
| 304 | + $result[$key] = is_array($value) |
|
| 305 | + ? $this->removeEmptyArrayValues($value) |
|
| 306 | + : $value; |
|
| 307 | + } |
|
| 308 | + return $result; |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - /** |
|
| 312 | - * @param string $prefix |
|
| 313 | - * @param string $text |
|
| 314 | - * @return string |
|
| 315 | - */ |
|
| 316 | - public function removePrefix($prefix, $text) |
|
| 317 | - { |
|
| 318 | - return 0 === strpos($text, $prefix) |
|
| 319 | - ? substr($text, strlen($prefix)) |
|
| 320 | - : $text; |
|
| 321 | - } |
|
| 311 | + /** |
|
| 312 | + * @param string $prefix |
|
| 313 | + * @param string $text |
|
| 314 | + * @return string |
|
| 315 | + */ |
|
| 316 | + public function removePrefix($prefix, $text) |
|
| 317 | + { |
|
| 318 | + return 0 === strpos($text, $prefix) |
|
| 319 | + ? substr($text, strlen($prefix)) |
|
| 320 | + : $text; |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - /** |
|
| 324 | - * @param string $string |
|
| 325 | - * @return string |
|
| 326 | - */ |
|
| 327 | - public function snakeCase($string) |
|
| 328 | - { |
|
| 329 | - if (!ctype_lower($string)) { |
|
| 330 | - $string = preg_replace('/\s+/u', '', $string); |
|
| 331 | - $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
| 332 | - $string = function_exists('mb_strtolower') |
|
| 333 | - ? mb_strtolower($string, 'UTF-8') |
|
| 334 | - : strtolower($string); |
|
| 335 | - } |
|
| 336 | - return str_replace('-', '_', $string); |
|
| 337 | - } |
|
| 323 | + /** |
|
| 324 | + * @param string $string |
|
| 325 | + * @return string |
|
| 326 | + */ |
|
| 327 | + public function snakeCase($string) |
|
| 328 | + { |
|
| 329 | + if (!ctype_lower($string)) { |
|
| 330 | + $string = preg_replace('/\s+/u', '', $string); |
|
| 331 | + $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
| 332 | + $string = function_exists('mb_strtolower') |
|
| 333 | + ? mb_strtolower($string, 'UTF-8') |
|
| 334 | + : strtolower($string); |
|
| 335 | + } |
|
| 336 | + return str_replace('-', '_', $string); |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - /** |
|
| 340 | - * @param string $needle |
|
| 341 | - * @param string $haystack |
|
| 342 | - * @return bool |
|
| 343 | - */ |
|
| 344 | - public function startsWith($needle, $haystack) |
|
| 345 | - { |
|
| 346 | - return substr($haystack, 0, strlen($needle)) === $needle; |
|
| 347 | - } |
|
| 339 | + /** |
|
| 340 | + * @param string $needle |
|
| 341 | + * @param string $haystack |
|
| 342 | + * @return bool |
|
| 343 | + */ |
|
| 344 | + public function startsWith($needle, $haystack) |
|
| 345 | + { |
|
| 346 | + return substr($haystack, 0, strlen($needle)) === $needle; |
|
| 347 | + } |
|
| 348 | 348 | } |
@@ -12,10 +12,10 @@ discard block |
||
| 12 | 12 | * @param string $path |
| 13 | 13 | * @return string |
| 14 | 14 | */ |
| 15 | - public function buildClassName($name, $path = '') |
|
| 15 | + public function buildClassName( $name, $path = '' ) |
|
| 16 | 16 | { |
| 17 | - $className = $this->camelCase($name); |
|
| 18 | - $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
| 17 | + $className = $this->camelCase( $name ); |
|
| 18 | + $path = ltrim( str_replace( __NAMESPACE__, '', $path ), '\\' ); |
|
| 19 | 19 | return !empty($path) |
| 20 | 20 | ? __NAMESPACE__.'\\'.$path.'\\'.$className |
| 21 | 21 | : $className; |
@@ -26,37 +26,37 @@ discard block |
||
| 26 | 26 | * @param string $prefix |
| 27 | 27 | * @return string |
| 28 | 28 | */ |
| 29 | - public function buildMethodName($name, $prefix = '') |
|
| 29 | + public function buildMethodName( $name, $prefix = '' ) |
|
| 30 | 30 | { |
| 31 | - return lcfirst($prefix.$this->buildClassName($name)); |
|
| 31 | + return lcfirst( $prefix.$this->buildClassName( $name ) ); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * @param string $name |
| 36 | 36 | * @return string |
| 37 | 37 | */ |
| 38 | - public function buildPropertyName($name) |
|
| 38 | + public function buildPropertyName( $name ) |
|
| 39 | 39 | { |
| 40 | - return lcfirst($this->buildClassName($name)); |
|
| 40 | + return lcfirst( $this->buildClassName( $name ) ); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * @param string $string |
| 45 | 45 | * @return string |
| 46 | 46 | */ |
| 47 | - public function camelCase($string) |
|
| 47 | + public function camelCase( $string ) |
|
| 48 | 48 | { |
| 49 | - $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
| 50 | - return str_replace(' ', '', $string); |
|
| 49 | + $string = ucwords( str_replace( ['-', '_'], ' ', trim( $string ) ) ); |
|
| 50 | + return str_replace( ' ', '', $string ); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * @return bool |
| 55 | 55 | */ |
| 56 | - public function compareArrays(array $arr1, array $arr2) |
|
| 56 | + public function compareArrays( array $arr1, array $arr2 ) |
|
| 57 | 57 | { |
| 58 | - sort($arr1); |
|
| 59 | - sort($arr2); |
|
| 58 | + sort( $arr1 ); |
|
| 59 | + sort( $arr2 ); |
|
| 60 | 60 | return $arr1 == $arr2; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -64,21 +64,21 @@ discard block |
||
| 64 | 64 | * @param mixed $array |
| 65 | 65 | * @return array |
| 66 | 66 | */ |
| 67 | - public function consolidateArray($array) |
|
| 67 | + public function consolidateArray( $array ) |
|
| 68 | 68 | { |
| 69 | - return is_array($array) || is_object($array) |
|
| 70 | - ? (array) $array |
|
| 69 | + return is_array( $array ) || is_object( $array ) |
|
| 70 | + ? (array)$array |
|
| 71 | 71 | : []; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | - public function convertDotNotationArray(array $array) |
|
| 77 | + public function convertDotNotationArray( array $array ) |
|
| 78 | 78 | { |
| 79 | 79 | $results = []; |
| 80 | - foreach ($array as $path => $value) { |
|
| 81 | - $results = $this->dataSet($results, $path, $value); |
|
| 80 | + foreach( $array as $path => $value ) { |
|
| 81 | + $results = $this->dataSet( $results, $path, $value ); |
|
| 82 | 82 | } |
| 83 | 83 | return $results; |
| 84 | 84 | } |
@@ -87,21 +87,21 @@ discard block |
||
| 87 | 87 | * @param string $name |
| 88 | 88 | * @return string |
| 89 | 89 | */ |
| 90 | - public function convertPathToId($path, $prefix = '') |
|
| 90 | + public function convertPathToId( $path, $prefix = '' ) |
|
| 91 | 91 | { |
| 92 | - return str_replace(['[', ']'], ['-', ''], $this->convertPathToName($path, $prefix)); |
|
| 92 | + return str_replace( ['[', ']'], ['-', ''], $this->convertPathToName( $path, $prefix ) ); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * @param string $path |
| 97 | 97 | * @return string |
| 98 | 98 | */ |
| 99 | - public function convertPathToName($path, $prefix = '') |
|
| 99 | + public function convertPathToName( $path, $prefix = '' ) |
|
| 100 | 100 | { |
| 101 | - $levels = explode('.', $path); |
|
| 102 | - return array_reduce($levels, function ($result, $value) { |
|
| 103 | - return $result.= '['.$value.']'; |
|
| 104 | - }, $prefix); |
|
| 101 | + $levels = explode( '.', $path ); |
|
| 102 | + return array_reduce( $levels, function( $result, $value ) { |
|
| 103 | + return $result .= '['.$value.']'; |
|
| 104 | + }, $prefix ); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -109,21 +109,21 @@ discard block |
||
| 109 | 109 | * @param mixed $callback |
| 110 | 110 | * @return array |
| 111 | 111 | */ |
| 112 | - public function convertStringToArray($string, $callback = null) |
|
| 112 | + public function convertStringToArray( $string, $callback = null ) |
|
| 113 | 113 | { |
| 114 | - $array = array_map('trim', explode(',', $string)); |
|
| 114 | + $array = array_map( 'trim', explode( ',', $string ) ); |
|
| 115 | 115 | return $callback |
| 116 | - ? array_filter($array, $callback) |
|
| 117 | - : array_filter($array); |
|
| 116 | + ? array_filter( $array, $callback ) |
|
| 117 | + : array_filter( $array ); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
| 121 | 121 | * @param string $string |
| 122 | 122 | * @return string |
| 123 | 123 | */ |
| 124 | - public function dashCase($string) |
|
| 124 | + public function dashCase( $string ) |
|
| 125 | 125 | { |
| 126 | - return str_replace('_', '-', $this->snakeCase($string)); |
|
| 126 | + return str_replace( '_', '-', $this->snakeCase( $string ) ); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -133,12 +133,12 @@ discard block |
||
| 133 | 133 | * @param mixed $fallback |
| 134 | 134 | * @return mixed |
| 135 | 135 | */ |
| 136 | - public function dataGet($data, $path = '', $fallback = '') |
|
| 136 | + public function dataGet( $data, $path = '', $fallback = '' ) |
|
| 137 | 137 | { |
| 138 | - $data = $this->consolidateArray($data); |
|
| 139 | - $keys = explode('.', $path); |
|
| 140 | - foreach ($keys as $key) { |
|
| 141 | - if (!isset($data[$key])) { |
|
| 138 | + $data = $this->consolidateArray( $data ); |
|
| 139 | + $keys = explode( '.', $path ); |
|
| 140 | + foreach( $keys as $key ) { |
|
| 141 | + if( !isset($data[$key]) ) { |
|
| 142 | 142 | return $fallback; |
| 143 | 143 | } |
| 144 | 144 | $data = $data[$key]; |
@@ -152,14 +152,14 @@ discard block |
||
| 152 | 152 | * @param mixed $value |
| 153 | 153 | * @return array |
| 154 | 154 | */ |
| 155 | - public function dataSet(array $data, $path = '', $value) |
|
| 155 | + public function dataSet( array $data, $path = '', $value ) |
|
| 156 | 156 | { |
| 157 | - $token = strtok($path, '.'); |
|
| 157 | + $token = strtok( $path, '.' ); |
|
| 158 | 158 | $ref = &$data; |
| 159 | - while (false !== $token) { |
|
| 160 | - $ref = $this->consolidateArray($ref); |
|
| 159 | + while( false !== $token ) { |
|
| 160 | + $ref = $this->consolidateArray( $ref ); |
|
| 161 | 161 | $ref = &$ref[$token]; |
| 162 | - $token = strtok('.'); |
|
| 162 | + $token = strtok( '.' ); |
|
| 163 | 163 | } |
| 164 | 164 | $ref = $value; |
| 165 | 165 | return $data; |
@@ -170,11 +170,11 @@ discard block |
||
| 170 | 170 | * @param string $haystack |
| 171 | 171 | * @return bool |
| 172 | 172 | */ |
| 173 | - public function endsWith($needle, $haystack) |
|
| 173 | + public function endsWith( $needle, $haystack ) |
|
| 174 | 174 | { |
| 175 | - $length = strlen($needle); |
|
| 175 | + $length = strlen( $needle ); |
|
| 176 | 176 | return 0 != $length |
| 177 | - ? substr($haystack, -$length) === $needle |
|
| 177 | + ? substr( $haystack, -$length ) === $needle |
|
| 178 | 178 | : true; |
| 179 | 179 | } |
| 180 | 180 | |
@@ -182,13 +182,13 @@ discard block |
||
| 182 | 182 | * @param string $key |
| 183 | 183 | * @return mixed |
| 184 | 184 | */ |
| 185 | - public function filterInput($key, array $request = []) |
|
| 185 | + public function filterInput( $key, array $request = [] ) |
|
| 186 | 186 | { |
| 187 | - if (isset($request[$key])) { |
|
| 187 | + if( isset($request[$key]) ) { |
|
| 188 | 188 | return $request[$key]; |
| 189 | 189 | } |
| 190 | - $variable = filter_input(INPUT_POST, $key); |
|
| 191 | - if (is_null($variable) && isset($_POST[$key])) { |
|
| 190 | + $variable = filter_input( INPUT_POST, $key ); |
|
| 191 | + if( is_null( $variable ) && isset($_POST[$key]) ) { |
|
| 192 | 192 | $variable = $_POST[$key]; |
| 193 | 193 | } |
| 194 | 194 | return $variable; |
@@ -198,13 +198,13 @@ discard block |
||
| 198 | 198 | * @param string $key |
| 199 | 199 | * @return array |
| 200 | 200 | */ |
| 201 | - public function filterInputArray($key) |
|
| 201 | + public function filterInputArray( $key ) |
|
| 202 | 202 | { |
| 203 | - $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 204 | - if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
| 203 | + $variable = filter_input( INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
| 204 | + if( empty($variable) && !empty($_POST[$key]) && is_array( $_POST[$key] ) ) { |
|
| 205 | 205 | $variable = $_POST[$key]; |
| 206 | 206 | } |
| 207 | - return (array) $variable; |
|
| 207 | + return (array)$variable; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -212,17 +212,17 @@ discard block |
||
| 212 | 212 | * @param string $prefix |
| 213 | 213 | * @return array |
| 214 | 214 | */ |
| 215 | - public function flattenArray(array $array, $flattenValue = false, $prefix = '') |
|
| 215 | + public function flattenArray( array $array, $flattenValue = false, $prefix = '' ) |
|
| 216 | 216 | { |
| 217 | 217 | $result = []; |
| 218 | - foreach ($array as $key => $value) { |
|
| 219 | - $newKey = ltrim($prefix.'.'.$key, '.'); |
|
| 220 | - if ($this->isIndexedFlatArray($value)) { |
|
| 221 | - if ($flattenValue) { |
|
| 222 | - $value = '['.implode(', ', $value).']'; |
|
| 218 | + foreach( $array as $key => $value ) { |
|
| 219 | + $newKey = ltrim( $prefix.'.'.$key, '.' ); |
|
| 220 | + if( $this->isIndexedFlatArray( $value ) ) { |
|
| 221 | + if( $flattenValue ) { |
|
| 222 | + $value = '['.implode( ', ', $value ).']'; |
|
| 223 | 223 | } |
| 224 | - } elseif (is_array($value)) { |
|
| 225 | - $result = array_merge($result, $this->flattenArray($value, $flattenValue, $newKey)); |
|
| 224 | + } elseif( is_array( $value ) ) { |
|
| 225 | + $result = array_merge( $result, $this->flattenArray( $value, $flattenValue, $newKey ) ); |
|
| 226 | 226 | continue; |
| 227 | 227 | } |
| 228 | 228 | $result[$newKey] = $value; |
@@ -235,19 +235,19 @@ discard block |
||
| 235 | 235 | */ |
| 236 | 236 | public function getIpAddress() |
| 237 | 237 | { |
| 238 | - $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
| 239 | - $ipv6 = defined('AF_INET6') |
|
| 238 | + $cloudflareIps = glsr( Cache::class )->getCloudflareIps(); |
|
| 239 | + $ipv6 = defined( 'AF_INET6' ) |
|
| 240 | 240 | ? $cloudflareIps['v6'] |
| 241 | 241 | : []; |
| 242 | - $whitelist = apply_filters('site-reviews/whip/whitelist', [ |
|
| 242 | + $whitelist = apply_filters( 'site-reviews/whip/whitelist', [ |
|
| 243 | 243 | Whip::CLOUDFLARE_HEADERS => [ |
| 244 | 244 | Whip::IPV4 => $cloudflareIps['v4'], |
| 245 | 245 | Whip::IPV6 => $ipv6, |
| 246 | 246 | ], |
| 247 | - ]); |
|
| 248 | - $whip = new Whip(Whip::ALL_METHODS, $whitelist); |
|
| 249 | - do_action_ref_array('site-reviews/whip', [&$whip]); |
|
| 250 | - return (string) $whip->getValidIpAddress(); |
|
| 247 | + ] ); |
|
| 248 | + $whip = new Whip( Whip::ALL_METHODS, $whitelist ); |
|
| 249 | + do_action_ref_array( 'site-reviews/whip', [&$whip] ); |
|
| 250 | + return (string)$whip->getValidIpAddress(); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -255,30 +255,30 @@ discard block |
||
| 255 | 255 | * @param string $position |
| 256 | 256 | * @return array |
| 257 | 257 | */ |
| 258 | - public function insertInArray(array $array, array $insert, $key, $position = 'before') |
|
| 258 | + public function insertInArray( array $array, array $insert, $key, $position = 'before' ) |
|
| 259 | 259 | { |
| 260 | - $keyPosition = intval(array_search($key, array_keys($array))); |
|
| 261 | - if ('after' == $position) { |
|
| 260 | + $keyPosition = intval( array_search( $key, array_keys( $array ) ) ); |
|
| 261 | + if( 'after' == $position ) { |
|
| 262 | 262 | ++$keyPosition; |
| 263 | 263 | } |
| 264 | - if (false !== $keyPosition) { |
|
| 265 | - $result = array_slice($array, 0, $keyPosition); |
|
| 266 | - $result = array_merge($result, $insert); |
|
| 267 | - return array_merge($result, array_slice($array, $keyPosition)); |
|
| 264 | + if( false !== $keyPosition ) { |
|
| 265 | + $result = array_slice( $array, 0, $keyPosition ); |
|
| 266 | + $result = array_merge( $result, $insert ); |
|
| 267 | + return array_merge( $result, array_slice( $array, $keyPosition ) ); |
|
| 268 | 268 | } |
| 269 | - return array_merge($array, $insert); |
|
| 269 | + return array_merge( $array, $insert ); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
| 273 | 273 | * @param mixed $array |
| 274 | 274 | * @return bool |
| 275 | 275 | */ |
| 276 | - public function isIndexedFlatArray($array) |
|
| 276 | + public function isIndexedFlatArray( $array ) |
|
| 277 | 277 | { |
| 278 | - if (!is_array($array) || array_filter($array, 'is_array')) { |
|
| 278 | + if( !is_array( $array ) || array_filter( $array, 'is_array' ) ) { |
|
| 279 | 279 | return false; |
| 280 | 280 | } |
| 281 | - return wp_is_numeric_array($array); |
|
| 281 | + return wp_is_numeric_array( $array ); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -286,23 +286,23 @@ discard block |
||
| 286 | 286 | * @param string $prefix |
| 287 | 287 | * @return string |
| 288 | 288 | */ |
| 289 | - public function prefixString($string, $prefix = '') |
|
| 289 | + public function prefixString( $string, $prefix = '' ) |
|
| 290 | 290 | { |
| 291 | - return $prefix.str_replace($prefix, '', trim($string)); |
|
| 291 | + return $prefix.str_replace( $prefix, '', trim( $string ) ); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
| 295 | 295 | * @return array |
| 296 | 296 | */ |
| 297 | - public function removeEmptyArrayValues(array $array) |
|
| 297 | + public function removeEmptyArrayValues( array $array ) |
|
| 298 | 298 | { |
| 299 | 299 | $result = []; |
| 300 | - foreach ($array as $key => $value) { |
|
| 301 | - if (!$value) { |
|
| 300 | + foreach( $array as $key => $value ) { |
|
| 301 | + if( !$value ) { |
|
| 302 | 302 | continue; |
| 303 | 303 | } |
| 304 | - $result[$key] = is_array($value) |
|
| 305 | - ? $this->removeEmptyArrayValues($value) |
|
| 304 | + $result[$key] = is_array( $value ) |
|
| 305 | + ? $this->removeEmptyArrayValues( $value ) |
|
| 306 | 306 | : $value; |
| 307 | 307 | } |
| 308 | 308 | return $result; |
@@ -313,10 +313,10 @@ discard block |
||
| 313 | 313 | * @param string $text |
| 314 | 314 | * @return string |
| 315 | 315 | */ |
| 316 | - public function removePrefix($prefix, $text) |
|
| 316 | + public function removePrefix( $prefix, $text ) |
|
| 317 | 317 | { |
| 318 | - return 0 === strpos($text, $prefix) |
|
| 319 | - ? substr($text, strlen($prefix)) |
|
| 318 | + return 0 === strpos( $text, $prefix ) |
|
| 319 | + ? substr( $text, strlen( $prefix ) ) |
|
| 320 | 320 | : $text; |
| 321 | 321 | } |
| 322 | 322 | |
@@ -324,16 +324,16 @@ discard block |
||
| 324 | 324 | * @param string $string |
| 325 | 325 | * @return string |
| 326 | 326 | */ |
| 327 | - public function snakeCase($string) |
|
| 327 | + public function snakeCase( $string ) |
|
| 328 | 328 | { |
| 329 | - if (!ctype_lower($string)) { |
|
| 330 | - $string = preg_replace('/\s+/u', '', $string); |
|
| 331 | - $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
| 332 | - $string = function_exists('mb_strtolower') |
|
| 333 | - ? mb_strtolower($string, 'UTF-8') |
|
| 334 | - : strtolower($string); |
|
| 329 | + if( !ctype_lower( $string ) ) { |
|
| 330 | + $string = preg_replace( '/\s+/u', '', $string ); |
|
| 331 | + $string = preg_replace( '/(.)(?=[A-Z])/u', '$1_', $string ); |
|
| 332 | + $string = function_exists( 'mb_strtolower' ) |
|
| 333 | + ? mb_strtolower( $string, 'UTF-8' ) |
|
| 334 | + : strtolower( $string ); |
|
| 335 | 335 | } |
| 336 | - return str_replace('-', '_', $string); |
|
| 336 | + return str_replace( '-', '_', $string ); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -341,8 +341,8 @@ discard block |
||
| 341 | 341 | * @param string $haystack |
| 342 | 342 | * @return bool |
| 343 | 343 | */ |
| 344 | - public function startsWith($needle, $haystack) |
|
| 344 | + public function startsWith( $needle, $haystack ) |
|
| 345 | 345 | { |
| 346 | - return substr($haystack, 0, strlen($needle)) === $needle; |
|
| 346 | + return substr( $haystack, 0, strlen( $needle ) ) === $needle; |
|
| 347 | 347 | } |
| 348 | 348 | } |
@@ -9,148 +9,148 @@ |
||
| 9 | 9 | |
| 10 | 10 | class EnqueuePublicAssets |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @return void |
|
| 14 | - */ |
|
| 15 | - public function handle() |
|
| 16 | - { |
|
| 17 | - $this->enqueueAssets(); |
|
| 18 | - $this->enqueuePolyfillService(); |
|
| 19 | - $this->enqueueRecaptchaScript(); |
|
| 20 | - $this->inlineScript(); |
|
| 21 | - $this->inlineStyles(); |
|
| 22 | - } |
|
| 12 | + /** |
|
| 13 | + * @return void |
|
| 14 | + */ |
|
| 15 | + public function handle() |
|
| 16 | + { |
|
| 17 | + $this->enqueueAssets(); |
|
| 18 | + $this->enqueuePolyfillService(); |
|
| 19 | + $this->enqueueRecaptchaScript(); |
|
| 20 | + $this->inlineScript(); |
|
| 21 | + $this->inlineStyles(); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @return void |
|
| 26 | - */ |
|
| 27 | - public function enqueueAssets() |
|
| 28 | - { |
|
| 29 | - if (apply_filters('site-reviews/assets/css', true)) { |
|
| 30 | - wp_enqueue_style( |
|
| 31 | - Application::ID, |
|
| 32 | - $this->getStylesheet(), |
|
| 33 | - [], |
|
| 34 | - glsr()->version |
|
| 35 | - ); |
|
| 36 | - } |
|
| 37 | - if (apply_filters('site-reviews/assets/js', true)) { |
|
| 38 | - $dependencies = apply_filters('site-reviews/assets/polyfill', true) |
|
| 39 | - ? [Application::ID.'/polyfill'] |
|
| 40 | - : []; |
|
| 41 | - $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies); |
|
| 42 | - wp_enqueue_script( |
|
| 43 | - Application::ID, |
|
| 44 | - glsr()->url('assets/scripts/'.Application::ID.'.js'), |
|
| 45 | - $dependencies, |
|
| 46 | - glsr()->version, |
|
| 47 | - true |
|
| 48 | - ); |
|
| 49 | - } |
|
| 50 | - } |
|
| 24 | + /** |
|
| 25 | + * @return void |
|
| 26 | + */ |
|
| 27 | + public function enqueueAssets() |
|
| 28 | + { |
|
| 29 | + if (apply_filters('site-reviews/assets/css', true)) { |
|
| 30 | + wp_enqueue_style( |
|
| 31 | + Application::ID, |
|
| 32 | + $this->getStylesheet(), |
|
| 33 | + [], |
|
| 34 | + glsr()->version |
|
| 35 | + ); |
|
| 36 | + } |
|
| 37 | + if (apply_filters('site-reviews/assets/js', true)) { |
|
| 38 | + $dependencies = apply_filters('site-reviews/assets/polyfill', true) |
|
| 39 | + ? [Application::ID.'/polyfill'] |
|
| 40 | + : []; |
|
| 41 | + $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies); |
|
| 42 | + wp_enqueue_script( |
|
| 43 | + Application::ID, |
|
| 44 | + glsr()->url('assets/scripts/'.Application::ID.'.js'), |
|
| 45 | + $dependencies, |
|
| 46 | + glsr()->version, |
|
| 47 | + true |
|
| 48 | + ); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return void |
|
| 54 | - */ |
|
| 55 | - public function enqueuePolyfillService() |
|
| 56 | - { |
|
| 57 | - if (!apply_filters('site-reviews/assets/polyfill', true)) { |
|
| 58 | - return; |
|
| 59 | - } |
|
| 60 | - wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([ |
|
| 61 | - 'features' => 'CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver', |
|
| 62 | - 'flags' => 'gated', |
|
| 63 | - ], 'https://polyfill.io/v3/polyfill.min.js')); |
|
| 64 | - } |
|
| 52 | + /** |
|
| 53 | + * @return void |
|
| 54 | + */ |
|
| 55 | + public function enqueuePolyfillService() |
|
| 56 | + { |
|
| 57 | + if (!apply_filters('site-reviews/assets/polyfill', true)) { |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | + wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([ |
|
| 61 | + 'features' => 'CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver', |
|
| 62 | + 'flags' => 'gated', |
|
| 63 | + ], 'https://polyfill.io/v3/polyfill.min.js')); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @return void |
|
| 68 | - */ |
|
| 69 | - public function enqueueRecaptchaScript() |
|
| 70 | - { |
|
| 71 | - // wpforms-recaptcha |
|
| 72 | - // google-recaptcha |
|
| 73 | - // nf-google-recaptcha |
|
| 74 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
| 75 | - return; |
|
| 76 | - } |
|
| 77 | - $language = apply_filters('site-reviews/recaptcha/language', get_locale()); |
|
| 78 | - wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([ |
|
| 79 | - 'hl' => $language, |
|
| 80 | - 'render' => 'explicit', |
|
| 81 | - ], 'https://www.google.com/recaptcha/api.js')); |
|
| 82 | - } |
|
| 66 | + /** |
|
| 67 | + * @return void |
|
| 68 | + */ |
|
| 69 | + public function enqueueRecaptchaScript() |
|
| 70 | + { |
|
| 71 | + // wpforms-recaptcha |
|
| 72 | + // google-recaptcha |
|
| 73 | + // nf-google-recaptcha |
|
| 74 | + if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
| 75 | + return; |
|
| 76 | + } |
|
| 77 | + $language = apply_filters('site-reviews/recaptcha/language', get_locale()); |
|
| 78 | + wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([ |
|
| 79 | + 'hl' => $language, |
|
| 80 | + 'render' => 'explicit', |
|
| 81 | + ], 'https://www.google.com/recaptcha/api.js')); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * @return void |
|
| 86 | - */ |
|
| 87 | - public function inlineScript() |
|
| 88 | - { |
|
| 89 | - $variables = [ |
|
| 90 | - 'action' => Application::PREFIX.'action', |
|
| 91 | - 'ajaxpagination' => $this->getFixedSelectorsForPagination(), |
|
| 92 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
| 93 | - 'nameprefix' => Application::ID, |
|
| 94 | - 'validationconfig' => glsr(Style::class)->validation, |
|
| 95 | - 'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(), |
|
| 96 | - ]; |
|
| 97 | - $variables = apply_filters('site-reviews/enqueue/public/localize', $variables); |
|
| 98 | - wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before'); |
|
| 99 | - } |
|
| 84 | + /** |
|
| 85 | + * @return void |
|
| 86 | + */ |
|
| 87 | + public function inlineScript() |
|
| 88 | + { |
|
| 89 | + $variables = [ |
|
| 90 | + 'action' => Application::PREFIX.'action', |
|
| 91 | + 'ajaxpagination' => $this->getFixedSelectorsForPagination(), |
|
| 92 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
| 93 | + 'nameprefix' => Application::ID, |
|
| 94 | + 'validationconfig' => glsr(Style::class)->validation, |
|
| 95 | + 'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(), |
|
| 96 | + ]; |
|
| 97 | + $variables = apply_filters('site-reviews/enqueue/public/localize', $variables); |
|
| 98 | + wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before'); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * @return void |
|
| 103 | - */ |
|
| 104 | - public function inlineStyles() |
|
| 105 | - { |
|
| 106 | - $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css'); |
|
| 107 | - if (!apply_filters('site-reviews/assets/css', true)) { |
|
| 108 | - return; |
|
| 109 | - } |
|
| 110 | - if (!file_exists($inlineStylesheetPath)) { |
|
| 111 | - glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath); |
|
| 112 | - return; |
|
| 113 | - } |
|
| 114 | - $inlineStylesheetValues = glsr()->config('inline-styles'); |
|
| 115 | - $stylesheet = str_replace( |
|
| 116 | - array_keys($inlineStylesheetValues), |
|
| 117 | - array_values($inlineStylesheetValues), |
|
| 118 | - file_get_contents($inlineStylesheetPath) |
|
| 119 | - ); |
|
| 120 | - wp_add_inline_style(Application::ID, $stylesheet); |
|
| 121 | - } |
|
| 101 | + /** |
|
| 102 | + * @return void |
|
| 103 | + */ |
|
| 104 | + public function inlineStyles() |
|
| 105 | + { |
|
| 106 | + $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css'); |
|
| 107 | + if (!apply_filters('site-reviews/assets/css', true)) { |
|
| 108 | + return; |
|
| 109 | + } |
|
| 110 | + if (!file_exists($inlineStylesheetPath)) { |
|
| 111 | + glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath); |
|
| 112 | + return; |
|
| 113 | + } |
|
| 114 | + $inlineStylesheetValues = glsr()->config('inline-styles'); |
|
| 115 | + $stylesheet = str_replace( |
|
| 116 | + array_keys($inlineStylesheetValues), |
|
| 117 | + array_values($inlineStylesheetValues), |
|
| 118 | + file_get_contents($inlineStylesheetPath) |
|
| 119 | + ); |
|
| 120 | + wp_add_inline_style(Application::ID, $stylesheet); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * @return string |
|
| 125 | - */ |
|
| 126 | - protected function buildInlineScript(array $variables) |
|
| 127 | - { |
|
| 128 | - $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});'; |
|
| 129 | - foreach ($variables as $key => $value) { |
|
| 130 | - $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); |
|
| 131 | - } |
|
| 132 | - $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys |
|
| 133 | - $optimizedScript = preg_replace($pattern, '$1$2', $script); |
|
| 134 | - return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables); |
|
| 135 | - } |
|
| 123 | + /** |
|
| 124 | + * @return string |
|
| 125 | + */ |
|
| 126 | + protected function buildInlineScript(array $variables) |
|
| 127 | + { |
|
| 128 | + $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});'; |
|
| 129 | + foreach ($variables as $key => $value) { |
|
| 130 | + $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); |
|
| 131 | + } |
|
| 132 | + $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys |
|
| 133 | + $optimizedScript = preg_replace($pattern, '$1$2', $script); |
|
| 134 | + return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * @return array |
|
| 139 | - */ |
|
| 140 | - protected function getFixedSelectorsForPagination() |
|
| 141 | - { |
|
| 142 | - $selectors = ['#wpadminbar', '.site-navigation-fixed']; |
|
| 143 | - return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors); |
|
| 144 | - } |
|
| 137 | + /** |
|
| 138 | + * @return array |
|
| 139 | + */ |
|
| 140 | + protected function getFixedSelectorsForPagination() |
|
| 141 | + { |
|
| 142 | + $selectors = ['#wpadminbar', '.site-navigation-fixed']; |
|
| 143 | + return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors); |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * @return string |
|
| 148 | - */ |
|
| 149 | - protected function getStylesheet() |
|
| 150 | - { |
|
| 151 | - $currentStyle = glsr(Style::class)->style; |
|
| 152 | - return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css')) |
|
| 153 | - ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css') |
|
| 154 | - : glsr()->url('assets/styles/'.Application::ID.'.css'); |
|
| 155 | - } |
|
| 146 | + /** |
|
| 147 | + * @return string |
|
| 148 | + */ |
|
| 149 | + protected function getStylesheet() |
|
| 150 | + { |
|
| 151 | + $currentStyle = glsr(Style::class)->style; |
|
| 152 | + return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css')) |
|
| 153 | + ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css') |
|
| 154 | + : glsr()->url('assets/styles/'.Application::ID.'.css'); |
|
| 155 | + } |
|
| 156 | 156 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public function enqueueAssets() |
| 28 | 28 | { |
| 29 | - if (apply_filters('site-reviews/assets/css', true)) { |
|
| 29 | + if( apply_filters( 'site-reviews/assets/css', true ) ) { |
|
| 30 | 30 | wp_enqueue_style( |
| 31 | 31 | Application::ID, |
| 32 | 32 | $this->getStylesheet(), |
@@ -34,14 +34,14 @@ discard block |
||
| 34 | 34 | glsr()->version |
| 35 | 35 | ); |
| 36 | 36 | } |
| 37 | - if (apply_filters('site-reviews/assets/js', true)) { |
|
| 38 | - $dependencies = apply_filters('site-reviews/assets/polyfill', true) |
|
| 37 | + if( apply_filters( 'site-reviews/assets/js', true ) ) { |
|
| 38 | + $dependencies = apply_filters( 'site-reviews/assets/polyfill', true ) |
|
| 39 | 39 | ? [Application::ID.'/polyfill'] |
| 40 | 40 | : []; |
| 41 | - $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies); |
|
| 41 | + $dependencies = apply_filters( 'site-reviews/enqueue/public/dependencies', $dependencies ); |
|
| 42 | 42 | wp_enqueue_script( |
| 43 | 43 | Application::ID, |
| 44 | - glsr()->url('assets/scripts/'.Application::ID.'.js'), |
|
| 44 | + glsr()->url( 'assets/scripts/'.Application::ID.'.js' ), |
|
| 45 | 45 | $dependencies, |
| 46 | 46 | glsr()->version, |
| 47 | 47 | true |
@@ -54,13 +54,13 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public function enqueuePolyfillService() |
| 56 | 56 | { |
| 57 | - if (!apply_filters('site-reviews/assets/polyfill', true)) { |
|
| 57 | + if( !apply_filters( 'site-reviews/assets/polyfill', true ) ) { |
|
| 58 | 58 | return; |
| 59 | 59 | } |
| 60 | - wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([ |
|
| 60 | + wp_enqueue_script( Application::ID.'/polyfill', add_query_arg( [ |
|
| 61 | 61 | 'features' => 'CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver', |
| 62 | 62 | 'flags' => 'gated', |
| 63 | - ], 'https://polyfill.io/v3/polyfill.min.js')); |
|
| 63 | + ], 'https://polyfill.io/v3/polyfill.min.js' ) ); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -71,14 +71,14 @@ discard block |
||
| 71 | 71 | // wpforms-recaptcha |
| 72 | 72 | // google-recaptcha |
| 73 | 73 | // nf-google-recaptcha |
| 74 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
| 74 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
| 75 | 75 | return; |
| 76 | 76 | } |
| 77 | - $language = apply_filters('site-reviews/recaptcha/language', get_locale()); |
|
| 78 | - wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([ |
|
| 77 | + $language = apply_filters( 'site-reviews/recaptcha/language', get_locale() ); |
|
| 78 | + wp_enqueue_script( Application::ID.'/google-recaptcha', add_query_arg( [ |
|
| 79 | 79 | 'hl' => $language, |
| 80 | 80 | 'render' => 'explicit', |
| 81 | - ], 'https://www.google.com/recaptcha/api.js')); |
|
| 81 | + ], 'https://www.google.com/recaptcha/api.js' ) ); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -89,13 +89,13 @@ discard block |
||
| 89 | 89 | $variables = [ |
| 90 | 90 | 'action' => Application::PREFIX.'action', |
| 91 | 91 | 'ajaxpagination' => $this->getFixedSelectorsForPagination(), |
| 92 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
| 92 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
| 93 | 93 | 'nameprefix' => Application::ID, |
| 94 | - 'validationconfig' => glsr(Style::class)->validation, |
|
| 95 | - 'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(), |
|
| 94 | + 'validationconfig' => glsr( Style::class )->validation, |
|
| 95 | + 'validationstrings' => glsr( ValidationStringsDefaults::class )->defaults(), |
|
| 96 | 96 | ]; |
| 97 | - $variables = apply_filters('site-reviews/enqueue/public/localize', $variables); |
|
| 98 | - wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before'); |
|
| 97 | + $variables = apply_filters( 'site-reviews/enqueue/public/localize', $variables ); |
|
| 98 | + wp_add_inline_script( Application::ID, $this->buildInlineScript( $variables ), 'before' ); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -103,35 +103,35 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function inlineStyles() |
| 105 | 105 | { |
| 106 | - $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css'); |
|
| 107 | - if (!apply_filters('site-reviews/assets/css', true)) { |
|
| 106 | + $inlineStylesheetPath = glsr()->path( 'assets/styles/inline-styles.css' ); |
|
| 107 | + if( !apply_filters( 'site-reviews/assets/css', true ) ) { |
|
| 108 | 108 | return; |
| 109 | 109 | } |
| 110 | - if (!file_exists($inlineStylesheetPath)) { |
|
| 111 | - glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath); |
|
| 110 | + if( !file_exists( $inlineStylesheetPath ) ) { |
|
| 111 | + glsr_log()->error( 'Inline stylesheet is missing: '.$inlineStylesheetPath ); |
|
| 112 | 112 | return; |
| 113 | 113 | } |
| 114 | - $inlineStylesheetValues = glsr()->config('inline-styles'); |
|
| 114 | + $inlineStylesheetValues = glsr()->config( 'inline-styles' ); |
|
| 115 | 115 | $stylesheet = str_replace( |
| 116 | - array_keys($inlineStylesheetValues), |
|
| 117 | - array_values($inlineStylesheetValues), |
|
| 118 | - file_get_contents($inlineStylesheetPath) |
|
| 116 | + array_keys( $inlineStylesheetValues ), |
|
| 117 | + array_values( $inlineStylesheetValues ), |
|
| 118 | + file_get_contents( $inlineStylesheetPath ) |
|
| 119 | 119 | ); |
| 120 | - wp_add_inline_style(Application::ID, $stylesheet); |
|
| 120 | + wp_add_inline_style( Application::ID, $stylesheet ); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
| 124 | 124 | * @return string |
| 125 | 125 | */ |
| 126 | - protected function buildInlineScript(array $variables) |
|
| 126 | + protected function buildInlineScript( array $variables ) |
|
| 127 | 127 | { |
| 128 | 128 | $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});'; |
| 129 | - foreach ($variables as $key => $value) { |
|
| 130 | - $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); |
|
| 129 | + foreach( $variables as $key => $value ) { |
|
| 130 | + $script .= sprintf( 'GLSR.%s=%s;', $key, json_encode( $value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ); |
|
| 131 | 131 | } |
| 132 | 132 | $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys |
| 133 | - $optimizedScript = preg_replace($pattern, '$1$2', $script); |
|
| 134 | - return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables); |
|
| 133 | + $optimizedScript = preg_replace( $pattern, '$1$2', $script ); |
|
| 134 | + return apply_filters( 'site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables ); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | protected function getFixedSelectorsForPagination() |
| 141 | 141 | { |
| 142 | 142 | $selectors = ['#wpadminbar', '.site-navigation-fixed']; |
| 143 | - return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors); |
|
| 143 | + return apply_filters( 'site-reviews/enqueue/public/localize/ajax-pagination', $selectors ); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | protected function getStylesheet() |
| 150 | 150 | { |
| 151 | - $currentStyle = glsr(Style::class)->style; |
|
| 152 | - return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css')) |
|
| 153 | - ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css') |
|
| 154 | - : glsr()->url('assets/styles/'.Application::ID.'.css'); |
|
| 151 | + $currentStyle = glsr( Style::class )->style; |
|
| 152 | + return file_exists( glsr()->path( 'assets/styles/custom/'.$currentStyle.'.css' ) ) |
|
| 153 | + ? glsr()->url( 'assets/styles/custom/'.$currentStyle.'.css' ) |
|
| 154 | + : glsr()->url( 'assets/styles/'.Application::ID.'.css' ); |
|
| 155 | 155 | } |
| 156 | 156 | } |
@@ -13,190 +13,190 @@ |
||
| 13 | 13 | |
| 14 | 14 | class MenuController extends Controller |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @return void |
|
| 18 | - * @action admin_menu |
|
| 19 | - */ |
|
| 20 | - public function registerMenuCount() |
|
| 21 | - { |
|
| 22 | - global $menu, $typenow; |
|
| 23 | - foreach ($menu as $key => $value) { |
|
| 24 | - if (!isset($value[2]) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE) { |
|
| 25 | - continue; |
|
| 26 | - } |
|
| 27 | - $postCount = wp_count_posts(Application::POST_TYPE); |
|
| 28 | - $pendingCount = glsr(Builder::class)->span(number_format_i18n($postCount->pending), [ |
|
| 29 | - 'class' => 'pending-count', |
|
| 30 | - ]); |
|
| 31 | - $awaitingModeration = glsr(Builder::class)->span($pendingCount, [ |
|
| 32 | - 'class' => 'awaiting-mod count-'.$postCount->pending, |
|
| 33 | - ]); |
|
| 34 | - $menu[$key][0].= ' '.$awaitingModeration; |
|
| 35 | - if (Application::POST_TYPE === $typenow) { |
|
| 36 | - $menu[$key][4].= ' current'; |
|
| 37 | - } |
|
| 38 | - break; |
|
| 39 | - } |
|
| 40 | - } |
|
| 16 | + /** |
|
| 17 | + * @return void |
|
| 18 | + * @action admin_menu |
|
| 19 | + */ |
|
| 20 | + public function registerMenuCount() |
|
| 21 | + { |
|
| 22 | + global $menu, $typenow; |
|
| 23 | + foreach ($menu as $key => $value) { |
|
| 24 | + if (!isset($value[2]) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE) { |
|
| 25 | + continue; |
|
| 26 | + } |
|
| 27 | + $postCount = wp_count_posts(Application::POST_TYPE); |
|
| 28 | + $pendingCount = glsr(Builder::class)->span(number_format_i18n($postCount->pending), [ |
|
| 29 | + 'class' => 'pending-count', |
|
| 30 | + ]); |
|
| 31 | + $awaitingModeration = glsr(Builder::class)->span($pendingCount, [ |
|
| 32 | + 'class' => 'awaiting-mod count-'.$postCount->pending, |
|
| 33 | + ]); |
|
| 34 | + $menu[$key][0].= ' '.$awaitingModeration; |
|
| 35 | + if (Application::POST_TYPE === $typenow) { |
|
| 36 | + $menu[$key][4].= ' current'; |
|
| 37 | + } |
|
| 38 | + break; |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return void |
|
| 44 | - * @action admin_menu |
|
| 45 | - */ |
|
| 46 | - public function registerSubMenus() |
|
| 47 | - { |
|
| 48 | - $pages = $this->parseWithFilter('submenu/pages', [ |
|
| 49 | - 'settings' => __('Settings', 'site-reviews'), |
|
| 50 | - 'tools' => __('Tools', 'site-reviews'), |
|
| 51 | - 'addons' => __('Add-ons', 'site-reviews'), |
|
| 52 | - 'documentation' => __('Documentation', 'site-reviews'), |
|
| 53 | - ]); |
|
| 54 | - foreach ($pages as $slug => $title) { |
|
| 55 | - $method = glsr(Helper::class)->buildMethodName('render-'.$slug.'-menu'); |
|
| 56 | - $callback = apply_filters('site-reviews/addon/submenu/callback', [$this, $method], $slug); |
|
| 57 | - if (!is_callable($callback)) { |
|
| 58 | - continue; |
|
| 59 | - } |
|
| 60 | - add_submenu_page('edit.php?post_type='.Application::POST_TYPE, $title, $title, glsr()->getPermission($slug), $slug, $callback); |
|
| 61 | - } |
|
| 62 | - } |
|
| 42 | + /** |
|
| 43 | + * @return void |
|
| 44 | + * @action admin_menu |
|
| 45 | + */ |
|
| 46 | + public function registerSubMenus() |
|
| 47 | + { |
|
| 48 | + $pages = $this->parseWithFilter('submenu/pages', [ |
|
| 49 | + 'settings' => __('Settings', 'site-reviews'), |
|
| 50 | + 'tools' => __('Tools', 'site-reviews'), |
|
| 51 | + 'addons' => __('Add-ons', 'site-reviews'), |
|
| 52 | + 'documentation' => __('Documentation', 'site-reviews'), |
|
| 53 | + ]); |
|
| 54 | + foreach ($pages as $slug => $title) { |
|
| 55 | + $method = glsr(Helper::class)->buildMethodName('render-'.$slug.'-menu'); |
|
| 56 | + $callback = apply_filters('site-reviews/addon/submenu/callback', [$this, $method], $slug); |
|
| 57 | + if (!is_callable($callback)) { |
|
| 58 | + continue; |
|
| 59 | + } |
|
| 60 | + add_submenu_page('edit.php?post_type='.Application::POST_TYPE, $title, $title, glsr()->getPermission($slug), $slug, $callback); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @return void |
|
| 66 | - * @see $this->registerSubMenus() |
|
| 67 | - * @callback add_submenu_page |
|
| 68 | - */ |
|
| 69 | - public function renderAddonsMenu() |
|
| 70 | - { |
|
| 71 | - $this->renderPage('addons', [ |
|
| 72 | - 'template' => glsr(Template::class), |
|
| 73 | - ]); |
|
| 74 | - } |
|
| 64 | + /** |
|
| 65 | + * @return void |
|
| 66 | + * @see $this->registerSubMenus() |
|
| 67 | + * @callback add_submenu_page |
|
| 68 | + */ |
|
| 69 | + public function renderAddonsMenu() |
|
| 70 | + { |
|
| 71 | + $this->renderPage('addons', [ |
|
| 72 | + 'template' => glsr(Template::class), |
|
| 73 | + ]); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * @return void |
|
| 78 | - * @see $this->registerSubMenus() |
|
| 79 | - * @callback add_submenu_page |
|
| 80 | - */ |
|
| 81 | - public function renderDocumentationMenu() |
|
| 82 | - { |
|
| 83 | - $tabs = $this->parseWithFilter('documentation/tabs', [ |
|
| 84 | - 'support' => __('Support', 'site-reviews'), |
|
| 85 | - 'faq' => __('FAQ', 'site-reviews'), |
|
| 86 | - 'shortcodes' => __('Shortcodes', 'site-reviews'), |
|
| 87 | - 'hooks' => __('Hooks', 'site-reviews'), |
|
| 88 | - 'functions' => __('Functions', 'site-reviews'), |
|
| 89 | - 'addons' => __('Addons', 'site-reviews'), |
|
| 90 | - ]); |
|
| 91 | - $addons = apply_filters('site-reviews/addon/documentation', []); |
|
| 92 | - ksort($addons); |
|
| 93 | - if (empty($addons)) { |
|
| 94 | - unset($tabs['addons']); |
|
| 95 | - } |
|
| 96 | - $this->renderPage('documentation', [ |
|
| 97 | - 'addons' => $addons, |
|
| 98 | - 'tabs' => $tabs, |
|
| 99 | - ]); |
|
| 100 | - } |
|
| 76 | + /** |
|
| 77 | + * @return void |
|
| 78 | + * @see $this->registerSubMenus() |
|
| 79 | + * @callback add_submenu_page |
|
| 80 | + */ |
|
| 81 | + public function renderDocumentationMenu() |
|
| 82 | + { |
|
| 83 | + $tabs = $this->parseWithFilter('documentation/tabs', [ |
|
| 84 | + 'support' => __('Support', 'site-reviews'), |
|
| 85 | + 'faq' => __('FAQ', 'site-reviews'), |
|
| 86 | + 'shortcodes' => __('Shortcodes', 'site-reviews'), |
|
| 87 | + 'hooks' => __('Hooks', 'site-reviews'), |
|
| 88 | + 'functions' => __('Functions', 'site-reviews'), |
|
| 89 | + 'addons' => __('Addons', 'site-reviews'), |
|
| 90 | + ]); |
|
| 91 | + $addons = apply_filters('site-reviews/addon/documentation', []); |
|
| 92 | + ksort($addons); |
|
| 93 | + if (empty($addons)) { |
|
| 94 | + unset($tabs['addons']); |
|
| 95 | + } |
|
| 96 | + $this->renderPage('documentation', [ |
|
| 97 | + 'addons' => $addons, |
|
| 98 | + 'tabs' => $tabs, |
|
| 99 | + ]); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * @return void |
|
| 104 | - * @see $this->registerSubMenus() |
|
| 105 | - * @callback add_submenu_page |
|
| 106 | - */ |
|
| 107 | - public function renderSettingsMenu() |
|
| 108 | - { |
|
| 109 | - $tabs = $this->parseWithFilter('settings/tabs', [ |
|
| 110 | - 'general' => __('General', 'site-reviews'), |
|
| 111 | - 'reviews' => __('Reviews', 'site-reviews'), |
|
| 112 | - 'submissions' => __('Submissions', 'site-reviews'), |
|
| 113 | - 'schema' => __('Schema', 'site-reviews'), |
|
| 114 | - 'translations' => __('Translations', 'site-reviews'), |
|
| 115 | - 'addons' => __('Addons', 'site-reviews'), |
|
| 116 | - 'licenses' => __('Licenses', 'site-reviews'), |
|
| 117 | - ]); |
|
| 118 | - if (empty(glsr(Helper::class)->dataGet(glsr()->defaults, 'settings.addons'))) { |
|
| 119 | - unset($tabs['addons']); |
|
| 120 | - } |
|
| 121 | - if (empty(glsr(Helper::class)->dataGet(glsr()->defaults, 'settings.licenses'))) { |
|
| 122 | - unset($tabs['licenses']); |
|
| 123 | - } |
|
| 124 | - $this->renderPage('settings', [ |
|
| 125 | - 'notices' => $this->getNotices(), |
|
| 126 | - 'settings' => glsr(Settings::class), |
|
| 127 | - 'tabs' => $tabs, |
|
| 128 | - ]); |
|
| 129 | - } |
|
| 102 | + /** |
|
| 103 | + * @return void |
|
| 104 | + * @see $this->registerSubMenus() |
|
| 105 | + * @callback add_submenu_page |
|
| 106 | + */ |
|
| 107 | + public function renderSettingsMenu() |
|
| 108 | + { |
|
| 109 | + $tabs = $this->parseWithFilter('settings/tabs', [ |
|
| 110 | + 'general' => __('General', 'site-reviews'), |
|
| 111 | + 'reviews' => __('Reviews', 'site-reviews'), |
|
| 112 | + 'submissions' => __('Submissions', 'site-reviews'), |
|
| 113 | + 'schema' => __('Schema', 'site-reviews'), |
|
| 114 | + 'translations' => __('Translations', 'site-reviews'), |
|
| 115 | + 'addons' => __('Addons', 'site-reviews'), |
|
| 116 | + 'licenses' => __('Licenses', 'site-reviews'), |
|
| 117 | + ]); |
|
| 118 | + if (empty(glsr(Helper::class)->dataGet(glsr()->defaults, 'settings.addons'))) { |
|
| 119 | + unset($tabs['addons']); |
|
| 120 | + } |
|
| 121 | + if (empty(glsr(Helper::class)->dataGet(glsr()->defaults, 'settings.licenses'))) { |
|
| 122 | + unset($tabs['licenses']); |
|
| 123 | + } |
|
| 124 | + $this->renderPage('settings', [ |
|
| 125 | + 'notices' => $this->getNotices(), |
|
| 126 | + 'settings' => glsr(Settings::class), |
|
| 127 | + 'tabs' => $tabs, |
|
| 128 | + ]); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * @return void |
|
| 133 | - * @see $this->registerSubMenus() |
|
| 134 | - * @callback add_submenu_page |
|
| 135 | - */ |
|
| 136 | - public function renderToolsMenu() |
|
| 137 | - { |
|
| 138 | - $tabs = $this->parseWithFilter('tools/tabs', [ |
|
| 139 | - 'general' => __('General', 'site-reviews'), |
|
| 140 | - 'sync' => __('Sync Reviews', 'site-reviews'), |
|
| 141 | - 'console' => __('Console', 'site-reviews'), |
|
| 142 | - 'system-info' => __('System Info', 'site-reviews'), |
|
| 143 | - ]); |
|
| 144 | - if (!apply_filters('site-reviews/addon/sync/enable', false)) { |
|
| 145 | - unset($tabs['sync']); |
|
| 146 | - } |
|
| 147 | - $this->renderPage('tools', [ |
|
| 148 | - 'data' => [ |
|
| 149 | - 'context' => [ |
|
| 150 | - 'base_url' => admin_url('edit.php?post_type='.Application::POST_TYPE), |
|
| 151 | - 'console' => strval(glsr(Console::class)), |
|
| 152 | - 'id' => Application::ID, |
|
| 153 | - 'system' => strval(glsr(System::class)), |
|
| 154 | - ], |
|
| 155 | - 'services' => apply_filters('site-reviews/addon/sync/services', []), |
|
| 156 | - ], |
|
| 157 | - 'notices' => $this->getNotices(), |
|
| 158 | - 'tabs' => $tabs, |
|
| 159 | - 'template' => glsr(Template::class), |
|
| 160 | - ]); |
|
| 161 | - } |
|
| 131 | + /** |
|
| 132 | + * @return void |
|
| 133 | + * @see $this->registerSubMenus() |
|
| 134 | + * @callback add_submenu_page |
|
| 135 | + */ |
|
| 136 | + public function renderToolsMenu() |
|
| 137 | + { |
|
| 138 | + $tabs = $this->parseWithFilter('tools/tabs', [ |
|
| 139 | + 'general' => __('General', 'site-reviews'), |
|
| 140 | + 'sync' => __('Sync Reviews', 'site-reviews'), |
|
| 141 | + 'console' => __('Console', 'site-reviews'), |
|
| 142 | + 'system-info' => __('System Info', 'site-reviews'), |
|
| 143 | + ]); |
|
| 144 | + if (!apply_filters('site-reviews/addon/sync/enable', false)) { |
|
| 145 | + unset($tabs['sync']); |
|
| 146 | + } |
|
| 147 | + $this->renderPage('tools', [ |
|
| 148 | + 'data' => [ |
|
| 149 | + 'context' => [ |
|
| 150 | + 'base_url' => admin_url('edit.php?post_type='.Application::POST_TYPE), |
|
| 151 | + 'console' => strval(glsr(Console::class)), |
|
| 152 | + 'id' => Application::ID, |
|
| 153 | + 'system' => strval(glsr(System::class)), |
|
| 154 | + ], |
|
| 155 | + 'services' => apply_filters('site-reviews/addon/sync/services', []), |
|
| 156 | + ], |
|
| 157 | + 'notices' => $this->getNotices(), |
|
| 158 | + 'tabs' => $tabs, |
|
| 159 | + 'template' => glsr(Template::class), |
|
| 160 | + ]); |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - /** |
|
| 164 | - * @return void |
|
| 165 | - * @action admin_init |
|
| 166 | - */ |
|
| 167 | - public function setCustomPermissions() |
|
| 168 | - { |
|
| 169 | - foreach (wp_roles()->roles as $role => $value) { |
|
| 170 | - wp_roles()->remove_cap($role, 'create_'.Application::POST_TYPE); |
|
| 171 | - } |
|
| 172 | - } |
|
| 163 | + /** |
|
| 164 | + * @return void |
|
| 165 | + * @action admin_init |
|
| 166 | + */ |
|
| 167 | + public function setCustomPermissions() |
|
| 168 | + { |
|
| 169 | + foreach (wp_roles()->roles as $role => $value) { |
|
| 170 | + wp_roles()->remove_cap($role, 'create_'.Application::POST_TYPE); |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - /** |
|
| 175 | - * @return string |
|
| 176 | - */ |
|
| 177 | - protected function getNotices() |
|
| 178 | - { |
|
| 179 | - return glsr(Builder::class)->div(glsr(Notice::class)->get(), [ |
|
| 180 | - 'id' => 'glsr-notices', |
|
| 181 | - ]); |
|
| 182 | - } |
|
| 174 | + /** |
|
| 175 | + * @return string |
|
| 176 | + */ |
|
| 177 | + protected function getNotices() |
|
| 178 | + { |
|
| 179 | + return glsr(Builder::class)->div(glsr(Notice::class)->get(), [ |
|
| 180 | + 'id' => 'glsr-notices', |
|
| 181 | + ]); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * @param string $hookSuffix |
|
| 186 | - * @return array |
|
| 187 | - */ |
|
| 188 | - protected function parseWithFilter($hookSuffix, array $args = []) |
|
| 189 | - { |
|
| 190 | - return apply_filters('site-reviews/addon/'.$hookSuffix, $args); |
|
| 191 | - } |
|
| 184 | + /** |
|
| 185 | + * @param string $hookSuffix |
|
| 186 | + * @return array |
|
| 187 | + */ |
|
| 188 | + protected function parseWithFilter($hookSuffix, array $args = []) |
|
| 189 | + { |
|
| 190 | + return apply_filters('site-reviews/addon/'.$hookSuffix, $args); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * @param string $page |
|
| 195 | - * @return void |
|
| 196 | - */ |
|
| 197 | - protected function renderPage($page, array $data = []) |
|
| 198 | - { |
|
| 199 | - $data['http_referer'] = (string) wp_get_referer(); |
|
| 200 | - glsr()->render('pages/'.$page.'/index', $data); |
|
| 201 | - } |
|
| 193 | + /** |
|
| 194 | + * @param string $page |
|
| 195 | + * @return void |
|
| 196 | + */ |
|
| 197 | + protected function renderPage($page, array $data = []) |
|
| 198 | + { |
|
| 199 | + $data['http_referer'] = (string) wp_get_referer(); |
|
| 200 | + glsr()->render('pages/'.$page.'/index', $data); |
|
| 201 | + } |
|
| 202 | 202 | } |
@@ -20,20 +20,20 @@ discard block |
||
| 20 | 20 | public function registerMenuCount() |
| 21 | 21 | { |
| 22 | 22 | global $menu, $typenow; |
| 23 | - foreach ($menu as $key => $value) { |
|
| 24 | - if (!isset($value[2]) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE) { |
|
| 23 | + foreach( $menu as $key => $value ) { |
|
| 24 | + if( !isset($value[2]) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE ) { |
|
| 25 | 25 | continue; |
| 26 | 26 | } |
| 27 | - $postCount = wp_count_posts(Application::POST_TYPE); |
|
| 28 | - $pendingCount = glsr(Builder::class)->span(number_format_i18n($postCount->pending), [ |
|
| 27 | + $postCount = wp_count_posts( Application::POST_TYPE ); |
|
| 28 | + $pendingCount = glsr( Builder::class )->span( number_format_i18n( $postCount->pending ), [ |
|
| 29 | 29 | 'class' => 'pending-count', |
| 30 | - ]); |
|
| 31 | - $awaitingModeration = glsr(Builder::class)->span($pendingCount, [ |
|
| 30 | + ] ); |
|
| 31 | + $awaitingModeration = glsr( Builder::class )->span( $pendingCount, [ |
|
| 32 | 32 | 'class' => 'awaiting-mod count-'.$postCount->pending, |
| 33 | - ]); |
|
| 34 | - $menu[$key][0].= ' '.$awaitingModeration; |
|
| 35 | - if (Application::POST_TYPE === $typenow) { |
|
| 36 | - $menu[$key][4].= ' current'; |
|
| 33 | + ] ); |
|
| 34 | + $menu[$key][0] .= ' '.$awaitingModeration; |
|
| 35 | + if( Application::POST_TYPE === $typenow ) { |
|
| 36 | + $menu[$key][4] .= ' current'; |
|
| 37 | 37 | } |
| 38 | 38 | break; |
| 39 | 39 | } |
@@ -45,19 +45,19 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function registerSubMenus() |
| 47 | 47 | { |
| 48 | - $pages = $this->parseWithFilter('submenu/pages', [ |
|
| 49 | - 'settings' => __('Settings', 'site-reviews'), |
|
| 50 | - 'tools' => __('Tools', 'site-reviews'), |
|
| 51 | - 'addons' => __('Add-ons', 'site-reviews'), |
|
| 52 | - 'documentation' => __('Documentation', 'site-reviews'), |
|
| 53 | - ]); |
|
| 54 | - foreach ($pages as $slug => $title) { |
|
| 55 | - $method = glsr(Helper::class)->buildMethodName('render-'.$slug.'-menu'); |
|
| 56 | - $callback = apply_filters('site-reviews/addon/submenu/callback', [$this, $method], $slug); |
|
| 57 | - if (!is_callable($callback)) { |
|
| 48 | + $pages = $this->parseWithFilter( 'submenu/pages', [ |
|
| 49 | + 'settings' => __( 'Settings', 'site-reviews' ), |
|
| 50 | + 'tools' => __( 'Tools', 'site-reviews' ), |
|
| 51 | + 'addons' => __( 'Add-ons', 'site-reviews' ), |
|
| 52 | + 'documentation' => __( 'Documentation', 'site-reviews' ), |
|
| 53 | + ] ); |
|
| 54 | + foreach( $pages as $slug => $title ) { |
|
| 55 | + $method = glsr( Helper::class )->buildMethodName( 'render-'.$slug.'-menu' ); |
|
| 56 | + $callback = apply_filters( 'site-reviews/addon/submenu/callback', [$this, $method], $slug ); |
|
| 57 | + if( !is_callable( $callback ) ) { |
|
| 58 | 58 | continue; |
| 59 | 59 | } |
| 60 | - add_submenu_page('edit.php?post_type='.Application::POST_TYPE, $title, $title, glsr()->getPermission($slug), $slug, $callback); |
|
| 60 | + add_submenu_page( 'edit.php?post_type='.Application::POST_TYPE, $title, $title, glsr()->getPermission( $slug ), $slug, $callback ); |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function renderAddonsMenu() |
| 70 | 70 | { |
| 71 | - $this->renderPage('addons', [ |
|
| 72 | - 'template' => glsr(Template::class), |
|
| 73 | - ]); |
|
| 71 | + $this->renderPage( 'addons', [ |
|
| 72 | + 'template' => glsr( Template::class ), |
|
| 73 | + ] ); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -80,23 +80,23 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public function renderDocumentationMenu() |
| 82 | 82 | { |
| 83 | - $tabs = $this->parseWithFilter('documentation/tabs', [ |
|
| 84 | - 'support' => __('Support', 'site-reviews'), |
|
| 85 | - 'faq' => __('FAQ', 'site-reviews'), |
|
| 86 | - 'shortcodes' => __('Shortcodes', 'site-reviews'), |
|
| 87 | - 'hooks' => __('Hooks', 'site-reviews'), |
|
| 88 | - 'functions' => __('Functions', 'site-reviews'), |
|
| 89 | - 'addons' => __('Addons', 'site-reviews'), |
|
| 90 | - ]); |
|
| 91 | - $addons = apply_filters('site-reviews/addon/documentation', []); |
|
| 92 | - ksort($addons); |
|
| 93 | - if (empty($addons)) { |
|
| 83 | + $tabs = $this->parseWithFilter( 'documentation/tabs', [ |
|
| 84 | + 'support' => __( 'Support', 'site-reviews' ), |
|
| 85 | + 'faq' => __( 'FAQ', 'site-reviews' ), |
|
| 86 | + 'shortcodes' => __( 'Shortcodes', 'site-reviews' ), |
|
| 87 | + 'hooks' => __( 'Hooks', 'site-reviews' ), |
|
| 88 | + 'functions' => __( 'Functions', 'site-reviews' ), |
|
| 89 | + 'addons' => __( 'Addons', 'site-reviews' ), |
|
| 90 | + ] ); |
|
| 91 | + $addons = apply_filters( 'site-reviews/addon/documentation', [] ); |
|
| 92 | + ksort( $addons ); |
|
| 93 | + if( empty($addons) ) { |
|
| 94 | 94 | unset($tabs['addons']); |
| 95 | 95 | } |
| 96 | - $this->renderPage('documentation', [ |
|
| 96 | + $this->renderPage( 'documentation', [ |
|
| 97 | 97 | 'addons' => $addons, |
| 98 | 98 | 'tabs' => $tabs, |
| 99 | - ]); |
|
| 99 | + ] ); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -106,26 +106,26 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | public function renderSettingsMenu() |
| 108 | 108 | { |
| 109 | - $tabs = $this->parseWithFilter('settings/tabs', [ |
|
| 110 | - 'general' => __('General', 'site-reviews'), |
|
| 111 | - 'reviews' => __('Reviews', 'site-reviews'), |
|
| 112 | - 'submissions' => __('Submissions', 'site-reviews'), |
|
| 113 | - 'schema' => __('Schema', 'site-reviews'), |
|
| 114 | - 'translations' => __('Translations', 'site-reviews'), |
|
| 115 | - 'addons' => __('Addons', 'site-reviews'), |
|
| 116 | - 'licenses' => __('Licenses', 'site-reviews'), |
|
| 117 | - ]); |
|
| 118 | - if (empty(glsr(Helper::class)->dataGet(glsr()->defaults, 'settings.addons'))) { |
|
| 109 | + $tabs = $this->parseWithFilter( 'settings/tabs', [ |
|
| 110 | + 'general' => __( 'General', 'site-reviews' ), |
|
| 111 | + 'reviews' => __( 'Reviews', 'site-reviews' ), |
|
| 112 | + 'submissions' => __( 'Submissions', 'site-reviews' ), |
|
| 113 | + 'schema' => __( 'Schema', 'site-reviews' ), |
|
| 114 | + 'translations' => __( 'Translations', 'site-reviews' ), |
|
| 115 | + 'addons' => __( 'Addons', 'site-reviews' ), |
|
| 116 | + 'licenses' => __( 'Licenses', 'site-reviews' ), |
|
| 117 | + ] ); |
|
| 118 | + if( empty(glsr( Helper::class )->dataGet( glsr()->defaults, 'settings.addons' )) ) { |
|
| 119 | 119 | unset($tabs['addons']); |
| 120 | 120 | } |
| 121 | - if (empty(glsr(Helper::class)->dataGet(glsr()->defaults, 'settings.licenses'))) { |
|
| 121 | + if( empty(glsr( Helper::class )->dataGet( glsr()->defaults, 'settings.licenses' )) ) { |
|
| 122 | 122 | unset($tabs['licenses']); |
| 123 | 123 | } |
| 124 | - $this->renderPage('settings', [ |
|
| 124 | + $this->renderPage( 'settings', [ |
|
| 125 | 125 | 'notices' => $this->getNotices(), |
| 126 | - 'settings' => glsr(Settings::class), |
|
| 126 | + 'settings' => glsr( Settings::class ), |
|
| 127 | 127 | 'tabs' => $tabs, |
| 128 | - ]); |
|
| 128 | + ] ); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -135,29 +135,29 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | public function renderToolsMenu() |
| 137 | 137 | { |
| 138 | - $tabs = $this->parseWithFilter('tools/tabs', [ |
|
| 139 | - 'general' => __('General', 'site-reviews'), |
|
| 140 | - 'sync' => __('Sync Reviews', 'site-reviews'), |
|
| 141 | - 'console' => __('Console', 'site-reviews'), |
|
| 142 | - 'system-info' => __('System Info', 'site-reviews'), |
|
| 143 | - ]); |
|
| 144 | - if (!apply_filters('site-reviews/addon/sync/enable', false)) { |
|
| 138 | + $tabs = $this->parseWithFilter( 'tools/tabs', [ |
|
| 139 | + 'general' => __( 'General', 'site-reviews' ), |
|
| 140 | + 'sync' => __( 'Sync Reviews', 'site-reviews' ), |
|
| 141 | + 'console' => __( 'Console', 'site-reviews' ), |
|
| 142 | + 'system-info' => __( 'System Info', 'site-reviews' ), |
|
| 143 | + ] ); |
|
| 144 | + if( !apply_filters( 'site-reviews/addon/sync/enable', false ) ) { |
|
| 145 | 145 | unset($tabs['sync']); |
| 146 | 146 | } |
| 147 | - $this->renderPage('tools', [ |
|
| 147 | + $this->renderPage( 'tools', [ |
|
| 148 | 148 | 'data' => [ |
| 149 | 149 | 'context' => [ |
| 150 | - 'base_url' => admin_url('edit.php?post_type='.Application::POST_TYPE), |
|
| 151 | - 'console' => strval(glsr(Console::class)), |
|
| 150 | + 'base_url' => admin_url( 'edit.php?post_type='.Application::POST_TYPE ), |
|
| 151 | + 'console' => strval( glsr( Console::class ) ), |
|
| 152 | 152 | 'id' => Application::ID, |
| 153 | - 'system' => strval(glsr(System::class)), |
|
| 153 | + 'system' => strval( glsr( System::class ) ), |
|
| 154 | 154 | ], |
| 155 | - 'services' => apply_filters('site-reviews/addon/sync/services', []), |
|
| 155 | + 'services' => apply_filters( 'site-reviews/addon/sync/services', [] ), |
|
| 156 | 156 | ], |
| 157 | 157 | 'notices' => $this->getNotices(), |
| 158 | 158 | 'tabs' => $tabs, |
| 159 | - 'template' => glsr(Template::class), |
|
| 160 | - ]); |
|
| 159 | + 'template' => glsr( Template::class ), |
|
| 160 | + ] ); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -166,8 +166,8 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | public function setCustomPermissions() |
| 168 | 168 | { |
| 169 | - foreach (wp_roles()->roles as $role => $value) { |
|
| 170 | - wp_roles()->remove_cap($role, 'create_'.Application::POST_TYPE); |
|
| 169 | + foreach( wp_roles()->roles as $role => $value ) { |
|
| 170 | + wp_roles()->remove_cap( $role, 'create_'.Application::POST_TYPE ); |
|
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | |
@@ -176,27 +176,27 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | protected function getNotices() |
| 178 | 178 | { |
| 179 | - return glsr(Builder::class)->div(glsr(Notice::class)->get(), [ |
|
| 179 | + return glsr( Builder::class )->div( glsr( Notice::class )->get(), [ |
|
| 180 | 180 | 'id' => 'glsr-notices', |
| 181 | - ]); |
|
| 181 | + ] ); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | 185 | * @param string $hookSuffix |
| 186 | 186 | * @return array |
| 187 | 187 | */ |
| 188 | - protected function parseWithFilter($hookSuffix, array $args = []) |
|
| 188 | + protected function parseWithFilter( $hookSuffix, array $args = [] ) |
|
| 189 | 189 | { |
| 190 | - return apply_filters('site-reviews/addon/'.$hookSuffix, $args); |
|
| 190 | + return apply_filters( 'site-reviews/addon/'.$hookSuffix, $args ); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
| 194 | 194 | * @param string $page |
| 195 | 195 | * @return void |
| 196 | 196 | */ |
| 197 | - protected function renderPage($page, array $data = []) |
|
| 197 | + protected function renderPage( $page, array $data = [] ) |
|
| 198 | 198 | { |
| 199 | - $data['http_referer'] = (string) wp_get_referer(); |
|
| 200 | - glsr()->render('pages/'.$page.'/index', $data); |
|
| 199 | + $data['http_referer'] = (string)wp_get_referer(); |
|
| 200 | + glsr()->render( 'pages/'.$page.'/index', $data ); |
|
| 201 | 201 | } |
| 202 | 202 | } |
@@ -12,58 +12,58 @@ |
||
| 12 | 12 | |
| 13 | 13 | class RestReviewController extends RestController |
| 14 | 14 | { |
| 15 | - public function __construct() |
|
| 16 | - { |
|
| 17 | - $this->meta = new WP_REST_Post_Meta_Fields(Application::POST_TYPE); |
|
| 18 | - $this->namespace = Application::ID.'/v1'; |
|
| 19 | - $this->post_type = Application::POST_TYPE; |
|
| 20 | - $this->rest_base = 'reviews'; |
|
| 21 | - } |
|
| 15 | + public function __construct() |
|
| 16 | + { |
|
| 17 | + $this->meta = new WP_REST_Post_Meta_Fields(Application::POST_TYPE); |
|
| 18 | + $this->namespace = Application::ID.'/v1'; |
|
| 19 | + $this->post_type = Application::POST_TYPE; |
|
| 20 | + $this->rest_base = 'reviews'; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @return void |
|
| 25 | - */ |
|
| 26 | - public function register_routes() |
|
| 27 | - { |
|
| 28 | - // register_rest_route($this->namespace, '/'.$this->rest_base, [ |
|
| 29 | - // ['callback' => [$this, 'createReview'], 'methods' => Server::CREATABLE], |
|
| 30 | - // ['callback' => [$this, 'getReviews'], 'methods' => Server::READABLE], |
|
| 31 | - // ]); |
|
| 32 | - register_rest_route($this->namespace, '/types', [ |
|
| 33 | - ['callback' => [$this, 'getReviewTypes'], 'methods' => Server::READABLE], |
|
| 34 | - ]); |
|
| 35 | - } |
|
| 23 | + /** |
|
| 24 | + * @return void |
|
| 25 | + */ |
|
| 26 | + public function register_routes() |
|
| 27 | + { |
|
| 28 | + // register_rest_route($this->namespace, '/'.$this->rest_base, [ |
|
| 29 | + // ['callback' => [$this, 'createReview'], 'methods' => Server::CREATABLE], |
|
| 30 | + // ['callback' => [$this, 'getReviews'], 'methods' => Server::READABLE], |
|
| 31 | + // ]); |
|
| 32 | + register_rest_route($this->namespace, '/types', [ |
|
| 33 | + ['callback' => [$this, 'getReviewTypes'], 'methods' => Server::READABLE], |
|
| 34 | + ]); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return WP_Error|Response|mixed |
|
| 39 | - */ |
|
| 40 | - public function createReview() |
|
| 41 | - { |
|
| 42 | - $response = []; |
|
| 43 | - return rest_ensure_response($response); |
|
| 44 | - } |
|
| 37 | + /** |
|
| 38 | + * @return WP_Error|Response|mixed |
|
| 39 | + */ |
|
| 40 | + public function createReview() |
|
| 41 | + { |
|
| 42 | + $response = []; |
|
| 43 | + return rest_ensure_response($response); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @return WP_Error|Response|mixed |
|
| 48 | - */ |
|
| 49 | - public function getReviews() |
|
| 50 | - { |
|
| 51 | - $response = []; |
|
| 52 | - return rest_ensure_response($response); |
|
| 53 | - } |
|
| 46 | + /** |
|
| 47 | + * @return WP_Error|Response|mixed |
|
| 48 | + */ |
|
| 49 | + public function getReviews() |
|
| 50 | + { |
|
| 51 | + $response = []; |
|
| 52 | + return rest_ensure_response($response); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @return WP_Error|Response|mixed |
|
| 57 | - */ |
|
| 58 | - public function getReviewTypes() |
|
| 59 | - { |
|
| 60 | - $response = []; |
|
| 61 | - foreach (glsr()->reviewTypes as $slug => $name) { |
|
| 62 | - $response[] = [ |
|
| 63 | - 'name' => $name, |
|
| 64 | - 'slug' => $slug, |
|
| 65 | - ]; |
|
| 66 | - } |
|
| 67 | - return rest_ensure_response($response); |
|
| 68 | - } |
|
| 55 | + /** |
|
| 56 | + * @return WP_Error|Response|mixed |
|
| 57 | + */ |
|
| 58 | + public function getReviewTypes() |
|
| 59 | + { |
|
| 60 | + $response = []; |
|
| 61 | + foreach (glsr()->reviewTypes as $slug => $name) { |
|
| 62 | + $response[] = [ |
|
| 63 | + 'name' => $name, |
|
| 64 | + 'slug' => $slug, |
|
| 65 | + ]; |
|
| 66 | + } |
|
| 67 | + return rest_ensure_response($response); |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -10,136 +10,136 @@ |
||
| 10 | 10 | |
| 11 | 11 | class Database |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @param int $postId |
|
| 15 | - * @param string $assignedTo |
|
| 16 | - * @return void|WP_Post |
|
| 17 | - */ |
|
| 18 | - public function getAssignedToPost($postId, $assignedTo = '') |
|
| 19 | - { |
|
| 20 | - if (empty($assignedTo)) { |
|
| 21 | - $assignedTo = get_post_meta($postId, 'assigned_to', true); |
|
| 22 | - } |
|
| 23 | - if (empty($assignedTo)) { |
|
| 24 | - return; |
|
| 25 | - } |
|
| 26 | - $assignedPost = get_post($assignedTo); |
|
| 27 | - if ($assignedPost instanceof WP_Post && $assignedPost->ID != $postId) { |
|
| 28 | - return $assignedPost; |
|
| 29 | - } |
|
| 30 | - } |
|
| 13 | + /** |
|
| 14 | + * @param int $postId |
|
| 15 | + * @param string $assignedTo |
|
| 16 | + * @return void|WP_Post |
|
| 17 | + */ |
|
| 18 | + public function getAssignedToPost($postId, $assignedTo = '') |
|
| 19 | + { |
|
| 20 | + if (empty($assignedTo)) { |
|
| 21 | + $assignedTo = get_post_meta($postId, 'assigned_to', true); |
|
| 22 | + } |
|
| 23 | + if (empty($assignedTo)) { |
|
| 24 | + return; |
|
| 25 | + } |
|
| 26 | + $assignedPost = get_post($assignedTo); |
|
| 27 | + if ($assignedPost instanceof WP_Post && $assignedPost->ID != $postId) { |
|
| 28 | + return $assignedPost; |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @param string $metaKey |
|
| 34 | - * @param string $metaValue |
|
| 35 | - * @return array|int |
|
| 36 | - */ |
|
| 37 | - public function getReviewCount($metaKey = '', $metaValue = '') |
|
| 38 | - { |
|
| 39 | - if (!$metaKey) { |
|
| 40 | - return (array) wp_count_posts(Application::POST_TYPE); |
|
| 41 | - } |
|
| 42 | - $counts = glsr(Cache::class)->getReviewCountsFor($metaKey); |
|
| 43 | - if (!$metaValue) { |
|
| 44 | - return $counts; |
|
| 45 | - } |
|
| 46 | - return glsr_get($counts, $metaValue, 0); |
|
| 47 | - } |
|
| 32 | + /** |
|
| 33 | + * @param string $metaKey |
|
| 34 | + * @param string $metaValue |
|
| 35 | + * @return array|int |
|
| 36 | + */ |
|
| 37 | + public function getReviewCount($metaKey = '', $metaValue = '') |
|
| 38 | + { |
|
| 39 | + if (!$metaKey) { |
|
| 40 | + return (array) wp_count_posts(Application::POST_TYPE); |
|
| 41 | + } |
|
| 42 | + $counts = glsr(Cache::class)->getReviewCountsFor($metaKey); |
|
| 43 | + if (!$metaValue) { |
|
| 44 | + return $counts; |
|
| 45 | + } |
|
| 46 | + return glsr_get($counts, $metaValue, 0); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param string $metaReviewType |
|
| 51 | - * @return array |
|
| 52 | - */ |
|
| 53 | - public function getReviewIdsByType($metaReviewType) |
|
| 54 | - { |
|
| 55 | - return glsr(SqlQueries::class)->getReviewIdsByType($metaReviewType); |
|
| 56 | - } |
|
| 49 | + /** |
|
| 50 | + * @param string $metaReviewType |
|
| 51 | + * @return array |
|
| 52 | + */ |
|
| 53 | + public function getReviewIdsByType($metaReviewType) |
|
| 54 | + { |
|
| 55 | + return glsr(SqlQueries::class)->getReviewIdsByType($metaReviewType); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @param string $key |
|
| 60 | - * @param string $status |
|
| 61 | - * @return array |
|
| 62 | - */ |
|
| 63 | - public function getReviewsMeta($key, $status = 'publish') |
|
| 64 | - { |
|
| 65 | - if ('all' == $status || empty($status)) { |
|
| 66 | - $status = get_post_stati(['exclude_from_search' => false]); |
|
| 67 | - } |
|
| 68 | - return glsr(SqlQueries::class)->getReviewsMeta($key, $status); |
|
| 69 | - } |
|
| 58 | + /** |
|
| 59 | + * @param string $key |
|
| 60 | + * @param string $status |
|
| 61 | + * @return array |
|
| 62 | + */ |
|
| 63 | + public function getReviewsMeta($key, $status = 'publish') |
|
| 64 | + { |
|
| 65 | + if ('all' == $status || empty($status)) { |
|
| 66 | + $status = get_post_stati(['exclude_from_search' => false]); |
|
| 67 | + } |
|
| 68 | + return glsr(SqlQueries::class)->getReviewsMeta($key, $status); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @param string $field |
|
| 73 | - * @return array |
|
| 74 | - */ |
|
| 75 | - public function getTermIds(array $values, $field) |
|
| 76 | - { |
|
| 77 | - $termIds = []; |
|
| 78 | - foreach ($values as $value) { |
|
| 79 | - $term = get_term_by($field, $value, Application::TAXONOMY); |
|
| 80 | - if (!isset($term->term_id)) { |
|
| 81 | - continue; |
|
| 82 | - } |
|
| 83 | - $termIds[] = $term->term_id; |
|
| 84 | - } |
|
| 85 | - return $termIds; |
|
| 86 | - } |
|
| 71 | + /** |
|
| 72 | + * @param string $field |
|
| 73 | + * @return array |
|
| 74 | + */ |
|
| 75 | + public function getTermIds(array $values, $field) |
|
| 76 | + { |
|
| 77 | + $termIds = []; |
|
| 78 | + foreach ($values as $value) { |
|
| 79 | + $term = get_term_by($field, $value, Application::TAXONOMY); |
|
| 80 | + if (!isset($term->term_id)) { |
|
| 81 | + continue; |
|
| 82 | + } |
|
| 83 | + $termIds[] = $term->term_id; |
|
| 84 | + } |
|
| 85 | + return $termIds; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * @return array |
|
| 90 | - */ |
|
| 91 | - public function getTerms(array $args = []) |
|
| 92 | - { |
|
| 93 | - $args = wp_parse_args($args, [ |
|
| 94 | - 'count' => false, |
|
| 95 | - 'fields' => 'id=>name', |
|
| 96 | - 'hide_empty' => false, |
|
| 97 | - 'taxonomy' => Application::TAXONOMY, |
|
| 98 | - ]); |
|
| 99 | - $terms = get_terms($args); |
|
| 100 | - if (is_wp_error($terms)) { |
|
| 101 | - glsr_log()->error($terms->get_error_message()); |
|
| 102 | - return []; |
|
| 103 | - } |
|
| 104 | - return $terms; |
|
| 105 | - } |
|
| 88 | + /** |
|
| 89 | + * @return array |
|
| 90 | + */ |
|
| 91 | + public function getTerms(array $args = []) |
|
| 92 | + { |
|
| 93 | + $args = wp_parse_args($args, [ |
|
| 94 | + 'count' => false, |
|
| 95 | + 'fields' => 'id=>name', |
|
| 96 | + 'hide_empty' => false, |
|
| 97 | + 'taxonomy' => Application::TAXONOMY, |
|
| 98 | + ]); |
|
| 99 | + $terms = get_terms($args); |
|
| 100 | + if (is_wp_error($terms)) { |
|
| 101 | + glsr_log()->error($terms->get_error_message()); |
|
| 102 | + return []; |
|
| 103 | + } |
|
| 104 | + return $terms; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @param string $searchTerm |
|
| 109 | - * @return void|string |
|
| 110 | - */ |
|
| 111 | - public function searchPosts($searchTerm) |
|
| 112 | - { |
|
| 113 | - $args = [ |
|
| 114 | - 'post_status' => 'publish', |
|
| 115 | - 'post_type' => 'any', |
|
| 116 | - ]; |
|
| 117 | - if (is_numeric($searchTerm)) { |
|
| 118 | - $args['post__in'] = [$searchTerm]; |
|
| 119 | - } else { |
|
| 120 | - $args['orderby'] = 'relevance'; |
|
| 121 | - $args['posts_per_page'] = 10; |
|
| 122 | - $args['s'] = $searchTerm; |
|
| 123 | - } |
|
| 124 | - $queryBuilder = glsr(QueryBuilder::class); |
|
| 125 | - add_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2); |
|
| 126 | - $search = new WP_Query($args); |
|
| 127 | - remove_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500); |
|
| 128 | - if (!$search->have_posts()) { |
|
| 129 | - return; |
|
| 130 | - } |
|
| 131 | - $results = ''; |
|
| 132 | - while ($search->have_posts()) { |
|
| 133 | - $search->the_post(); |
|
| 134 | - ob_start(); |
|
| 135 | - glsr()->render('partials/editor/search-result', [ |
|
| 136 | - 'ID' => get_the_ID(), |
|
| 137 | - 'permalink' => esc_url((string) get_permalink()), |
|
| 138 | - 'title' => esc_attr(get_the_title()), |
|
| 139 | - ]); |
|
| 140 | - $results.= ob_get_clean(); |
|
| 141 | - } |
|
| 142 | - wp_reset_postdata(); |
|
| 143 | - return $results; |
|
| 144 | - } |
|
| 107 | + /** |
|
| 108 | + * @param string $searchTerm |
|
| 109 | + * @return void|string |
|
| 110 | + */ |
|
| 111 | + public function searchPosts($searchTerm) |
|
| 112 | + { |
|
| 113 | + $args = [ |
|
| 114 | + 'post_status' => 'publish', |
|
| 115 | + 'post_type' => 'any', |
|
| 116 | + ]; |
|
| 117 | + if (is_numeric($searchTerm)) { |
|
| 118 | + $args['post__in'] = [$searchTerm]; |
|
| 119 | + } else { |
|
| 120 | + $args['orderby'] = 'relevance'; |
|
| 121 | + $args['posts_per_page'] = 10; |
|
| 122 | + $args['s'] = $searchTerm; |
|
| 123 | + } |
|
| 124 | + $queryBuilder = glsr(QueryBuilder::class); |
|
| 125 | + add_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2); |
|
| 126 | + $search = new WP_Query($args); |
|
| 127 | + remove_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500); |
|
| 128 | + if (!$search->have_posts()) { |
|
| 129 | + return; |
|
| 130 | + } |
|
| 131 | + $results = ''; |
|
| 132 | + while ($search->have_posts()) { |
|
| 133 | + $search->the_post(); |
|
| 134 | + ob_start(); |
|
| 135 | + glsr()->render('partials/editor/search-result', [ |
|
| 136 | + 'ID' => get_the_ID(), |
|
| 137 | + 'permalink' => esc_url((string) get_permalink()), |
|
| 138 | + 'title' => esc_attr(get_the_title()), |
|
| 139 | + ]); |
|
| 140 | + $results.= ob_get_clean(); |
|
| 141 | + } |
|
| 142 | + wp_reset_postdata(); |
|
| 143 | + return $results; |
|
| 144 | + } |
|
| 145 | 145 | } |
@@ -15,16 +15,16 @@ discard block |
||
| 15 | 15 | * @param string $assignedTo |
| 16 | 16 | * @return void|WP_Post |
| 17 | 17 | */ |
| 18 | - public function getAssignedToPost($postId, $assignedTo = '') |
|
| 18 | + public function getAssignedToPost( $postId, $assignedTo = '' ) |
|
| 19 | 19 | { |
| 20 | - if (empty($assignedTo)) { |
|
| 21 | - $assignedTo = get_post_meta($postId, 'assigned_to', true); |
|
| 20 | + if( empty($assignedTo) ) { |
|
| 21 | + $assignedTo = get_post_meta( $postId, 'assigned_to', true ); |
|
| 22 | 22 | } |
| 23 | - if (empty($assignedTo)) { |
|
| 23 | + if( empty($assignedTo) ) { |
|
| 24 | 24 | return; |
| 25 | 25 | } |
| 26 | - $assignedPost = get_post($assignedTo); |
|
| 27 | - if ($assignedPost instanceof WP_Post && $assignedPost->ID != $postId) { |
|
| 26 | + $assignedPost = get_post( $assignedTo ); |
|
| 27 | + if( $assignedPost instanceof WP_Post && $assignedPost->ID != $postId ) { |
|
| 28 | 28 | return $assignedPost; |
| 29 | 29 | } |
| 30 | 30 | } |
@@ -34,25 +34,25 @@ discard block |
||
| 34 | 34 | * @param string $metaValue |
| 35 | 35 | * @return array|int |
| 36 | 36 | */ |
| 37 | - public function getReviewCount($metaKey = '', $metaValue = '') |
|
| 37 | + public function getReviewCount( $metaKey = '', $metaValue = '' ) |
|
| 38 | 38 | { |
| 39 | - if (!$metaKey) { |
|
| 40 | - return (array) wp_count_posts(Application::POST_TYPE); |
|
| 39 | + if( !$metaKey ) { |
|
| 40 | + return (array)wp_count_posts( Application::POST_TYPE ); |
|
| 41 | 41 | } |
| 42 | - $counts = glsr(Cache::class)->getReviewCountsFor($metaKey); |
|
| 43 | - if (!$metaValue) { |
|
| 42 | + $counts = glsr( Cache::class )->getReviewCountsFor( $metaKey ); |
|
| 43 | + if( !$metaValue ) { |
|
| 44 | 44 | return $counts; |
| 45 | 45 | } |
| 46 | - return glsr_get($counts, $metaValue, 0); |
|
| 46 | + return glsr_get( $counts, $metaValue, 0 ); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * @param string $metaReviewType |
| 51 | 51 | * @return array |
| 52 | 52 | */ |
| 53 | - public function getReviewIdsByType($metaReviewType) |
|
| 53 | + public function getReviewIdsByType( $metaReviewType ) |
|
| 54 | 54 | { |
| 55 | - return glsr(SqlQueries::class)->getReviewIdsByType($metaReviewType); |
|
| 55 | + return glsr( SqlQueries::class )->getReviewIdsByType( $metaReviewType ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -60,24 +60,24 @@ discard block |
||
| 60 | 60 | * @param string $status |
| 61 | 61 | * @return array |
| 62 | 62 | */ |
| 63 | - public function getReviewsMeta($key, $status = 'publish') |
|
| 63 | + public function getReviewsMeta( $key, $status = 'publish' ) |
|
| 64 | 64 | { |
| 65 | - if ('all' == $status || empty($status)) { |
|
| 66 | - $status = get_post_stati(['exclude_from_search' => false]); |
|
| 65 | + if( 'all' == $status || empty($status) ) { |
|
| 66 | + $status = get_post_stati( ['exclude_from_search' => false] ); |
|
| 67 | 67 | } |
| 68 | - return glsr(SqlQueries::class)->getReviewsMeta($key, $status); |
|
| 68 | + return glsr( SqlQueries::class )->getReviewsMeta( $key, $status ); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * @param string $field |
| 73 | 73 | * @return array |
| 74 | 74 | */ |
| 75 | - public function getTermIds(array $values, $field) |
|
| 75 | + public function getTermIds( array $values, $field ) |
|
| 76 | 76 | { |
| 77 | 77 | $termIds = []; |
| 78 | - foreach ($values as $value) { |
|
| 79 | - $term = get_term_by($field, $value, Application::TAXONOMY); |
|
| 80 | - if (!isset($term->term_id)) { |
|
| 78 | + foreach( $values as $value ) { |
|
| 79 | + $term = get_term_by( $field, $value, Application::TAXONOMY ); |
|
| 80 | + if( !isset($term->term_id) ) { |
|
| 81 | 81 | continue; |
| 82 | 82 | } |
| 83 | 83 | $termIds[] = $term->term_id; |
@@ -88,17 +88,17 @@ discard block |
||
| 88 | 88 | /** |
| 89 | 89 | * @return array |
| 90 | 90 | */ |
| 91 | - public function getTerms(array $args = []) |
|
| 91 | + public function getTerms( array $args = [] ) |
|
| 92 | 92 | { |
| 93 | - $args = wp_parse_args($args, [ |
|
| 93 | + $args = wp_parse_args( $args, [ |
|
| 94 | 94 | 'count' => false, |
| 95 | 95 | 'fields' => 'id=>name', |
| 96 | 96 | 'hide_empty' => false, |
| 97 | 97 | 'taxonomy' => Application::TAXONOMY, |
| 98 | - ]); |
|
| 99 | - $terms = get_terms($args); |
|
| 100 | - if (is_wp_error($terms)) { |
|
| 101 | - glsr_log()->error($terms->get_error_message()); |
|
| 98 | + ] ); |
|
| 99 | + $terms = get_terms( $args ); |
|
| 100 | + if( is_wp_error( $terms ) ) { |
|
| 101 | + glsr_log()->error( $terms->get_error_message() ); |
|
| 102 | 102 | return []; |
| 103 | 103 | } |
| 104 | 104 | return $terms; |
@@ -108,36 +108,36 @@ discard block |
||
| 108 | 108 | * @param string $searchTerm |
| 109 | 109 | * @return void|string |
| 110 | 110 | */ |
| 111 | - public function searchPosts($searchTerm) |
|
| 111 | + public function searchPosts( $searchTerm ) |
|
| 112 | 112 | { |
| 113 | 113 | $args = [ |
| 114 | 114 | 'post_status' => 'publish', |
| 115 | 115 | 'post_type' => 'any', |
| 116 | 116 | ]; |
| 117 | - if (is_numeric($searchTerm)) { |
|
| 117 | + if( is_numeric( $searchTerm ) ) { |
|
| 118 | 118 | $args['post__in'] = [$searchTerm]; |
| 119 | 119 | } else { |
| 120 | 120 | $args['orderby'] = 'relevance'; |
| 121 | 121 | $args['posts_per_page'] = 10; |
| 122 | 122 | $args['s'] = $searchTerm; |
| 123 | 123 | } |
| 124 | - $queryBuilder = glsr(QueryBuilder::class); |
|
| 125 | - add_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2); |
|
| 126 | - $search = new WP_Query($args); |
|
| 127 | - remove_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500); |
|
| 128 | - if (!$search->have_posts()) { |
|
| 124 | + $queryBuilder = glsr( QueryBuilder::class ); |
|
| 125 | + add_filter( 'posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2 ); |
|
| 126 | + $search = new WP_Query( $args ); |
|
| 127 | + remove_filter( 'posts_search', [$queryBuilder, 'filterSearchByTitle'], 500 ); |
|
| 128 | + if( !$search->have_posts() ) { |
|
| 129 | 129 | return; |
| 130 | 130 | } |
| 131 | 131 | $results = ''; |
| 132 | - while ($search->have_posts()) { |
|
| 132 | + while( $search->have_posts() ) { |
|
| 133 | 133 | $search->the_post(); |
| 134 | 134 | ob_start(); |
| 135 | - glsr()->render('partials/editor/search-result', [ |
|
| 135 | + glsr()->render( 'partials/editor/search-result', [ |
|
| 136 | 136 | 'ID' => get_the_ID(), |
| 137 | - 'permalink' => esc_url((string) get_permalink()), |
|
| 138 | - 'title' => esc_attr(get_the_title()), |
|
| 139 | - ]); |
|
| 140 | - $results.= ob_get_clean(); |
|
| 137 | + 'permalink' => esc_url( (string)get_permalink() ), |
|
| 138 | + 'title' => esc_attr( get_the_title() ), |
|
| 139 | + ] ); |
|
| 140 | + $results .= ob_get_clean(); |
|
| 141 | 141 | } |
| 142 | 142 | wp_reset_postdata(); |
| 143 | 143 | return $results; |
@@ -5,23 +5,23 @@ |
||
| 5 | 5 | require_once ABSPATH.WPINC.'/class-phpass.php'; |
| 6 | 6 | |
| 7 | 7 | spl_autoload_register(function ($className) { |
| 8 | - $namespaces = [ |
|
| 9 | - 'GeminiLabs\\SiteReviews\\' => __DIR__.'/plugin/', |
|
| 10 | - 'GeminiLabs\\SiteReviews\\Tests\\' => __DIR__.'/tests/', |
|
| 11 | - 'GeminiLabs\\Sepia\\PoParser\\' => __DIR__.'/vendors/sepia/po-parser/', |
|
| 12 | - 'GeminiLabs\\Sinergi\\BrowserDetector\\' => __DIR__.'/vendors/sinergi/browser-detector/', |
|
| 13 | - 'GeminiLabs\\Vectorface\\Whip\\' => __DIR__.'/vendors/vectorface/whip/', |
|
| 14 | - ]; |
|
| 15 | - foreach ($namespaces as $prefix => $baseDir) { |
|
| 16 | - $len = strlen($prefix); |
|
| 17 | - if (0 !== strncmp($prefix, $className, $len)) { |
|
| 18 | - continue; |
|
| 19 | - } |
|
| 20 | - $file = $baseDir.str_replace('\\', '/', substr($className, $len)).'.php'; |
|
| 21 | - if (!file_exists($file)) { |
|
| 22 | - continue; |
|
| 23 | - } |
|
| 24 | - require $file; |
|
| 25 | - break; |
|
| 26 | - } |
|
| 8 | + $namespaces = [ |
|
| 9 | + 'GeminiLabs\\SiteReviews\\' => __DIR__.'/plugin/', |
|
| 10 | + 'GeminiLabs\\SiteReviews\\Tests\\' => __DIR__.'/tests/', |
|
| 11 | + 'GeminiLabs\\Sepia\\PoParser\\' => __DIR__.'/vendors/sepia/po-parser/', |
|
| 12 | + 'GeminiLabs\\Sinergi\\BrowserDetector\\' => __DIR__.'/vendors/sinergi/browser-detector/', |
|
| 13 | + 'GeminiLabs\\Vectorface\\Whip\\' => __DIR__.'/vendors/vectorface/whip/', |
|
| 14 | + ]; |
|
| 15 | + foreach ($namespaces as $prefix => $baseDir) { |
|
| 16 | + $len = strlen($prefix); |
|
| 17 | + if (0 !== strncmp($prefix, $className, $len)) { |
|
| 18 | + continue; |
|
| 19 | + } |
|
| 20 | + $file = $baseDir.str_replace('\\', '/', substr($className, $len)).'.php'; |
|
| 21 | + if (!file_exists($file)) { |
|
| 22 | + continue; |
|
| 23 | + } |
|
| 24 | + require $file; |
|
| 25 | + break; |
|
| 26 | + } |
|
| 27 | 27 | }); |
@@ -1,10 +1,10 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -defined('WPINC') || die; |
|
| 3 | +defined( 'WPINC' ) || die; |
|
| 4 | 4 | |
| 5 | 5 | require_once ABSPATH.WPINC.'/class-phpass.php'; |
| 6 | 6 | |
| 7 | -spl_autoload_register(function ($className) { |
|
| 7 | +spl_autoload_register( function( $className ) { |
|
| 8 | 8 | $namespaces = [ |
| 9 | 9 | 'GeminiLabs\\SiteReviews\\' => __DIR__.'/plugin/', |
| 10 | 10 | 'GeminiLabs\\SiteReviews\\Tests\\' => __DIR__.'/tests/', |
@@ -12,13 +12,13 @@ discard block |
||
| 12 | 12 | 'GeminiLabs\\Sinergi\\BrowserDetector\\' => __DIR__.'/vendors/sinergi/browser-detector/', |
| 13 | 13 | 'GeminiLabs\\Vectorface\\Whip\\' => __DIR__.'/vendors/vectorface/whip/', |
| 14 | 14 | ]; |
| 15 | - foreach ($namespaces as $prefix => $baseDir) { |
|
| 16 | - $len = strlen($prefix); |
|
| 17 | - if (0 !== strncmp($prefix, $className, $len)) { |
|
| 15 | + foreach( $namespaces as $prefix => $baseDir ) { |
|
| 16 | + $len = strlen( $prefix ); |
|
| 17 | + if( 0 !== strncmp( $prefix, $className, $len ) ) { |
|
| 18 | 18 | continue; |
| 19 | 19 | } |
| 20 | - $file = $baseDir.str_replace('\\', '/', substr($className, $len)).'.php'; |
|
| 21 | - if (!file_exists($file)) { |
|
| 20 | + $file = $baseDir.str_replace( '\\', '/', substr( $className, $len ) ).'.php'; |
|
| 21 | + if( !file_exists( $file ) ) { |
|
| 22 | 22 | continue; |
| 23 | 23 | } |
| 24 | 24 | require $file; |