@@ -6,174 +6,174 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Str |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @param string $string |
|
| 11 | - * @return string |
|
| 12 | - */ |
|
| 13 | - public static function camelCase($string) |
|
| 14 | - { |
|
| 15 | - $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
| 16 | - return str_replace(' ', '', $string); |
|
| 17 | - } |
|
| 9 | + /** |
|
| 10 | + * @param string $string |
|
| 11 | + * @return string |
|
| 12 | + */ |
|
| 13 | + public static function camelCase($string) |
|
| 14 | + { |
|
| 15 | + $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
| 16 | + return str_replace(' ', '', $string); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param string $haystack |
|
| 21 | - * @param string $needle |
|
| 22 | - * @return bool |
|
| 23 | - */ |
|
| 24 | - public static function contains($haystack, $needle) |
|
| 25 | - { |
|
| 26 | - return false !== strpos($haystack, $needle); |
|
| 27 | - } |
|
| 19 | + /** |
|
| 20 | + * @param string $haystack |
|
| 21 | + * @param string $needle |
|
| 22 | + * @return bool |
|
| 23 | + */ |
|
| 24 | + public static function contains($haystack, $needle) |
|
| 25 | + { |
|
| 26 | + return false !== strpos($haystack, $needle); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @param string $name |
|
| 31 | - * @param string $nameType first|first_initial|initials|last|last_initial |
|
| 32 | - * @param string $initialType period|period_space|space |
|
| 33 | - * @return string |
|
| 34 | - */ |
|
| 35 | - public static function convertName($name, $nameType = '', $initialType = '') |
|
| 36 | - { |
|
| 37 | - $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY); |
|
| 38 | - $firstName = array_shift($names); |
|
| 39 | - $lastName = array_pop($names); |
|
| 40 | - $initialTypes = [ |
|
| 41 | - 'period' => '.', |
|
| 42 | - 'period_space' => '. ', |
|
| 43 | - 'space' => ' ', |
|
| 44 | - ]; |
|
| 45 | - $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' '); |
|
| 46 | - if ('initials' == $nameType) { |
|
| 47 | - return static::convertToInitials($name, $initialPunctuation); |
|
| 48 | - } |
|
| 49 | - $nameTypes = [ |
|
| 50 | - 'first' => $firstName, |
|
| 51 | - 'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName, |
|
| 52 | - 'last' => $lastName, |
|
| 53 | - 'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation, |
|
| 54 | - ]; |
|
| 55 | - return trim((string) Arr::get($nameTypes, $nameType, $name)); |
|
| 56 | - } |
|
| 29 | + /** |
|
| 30 | + * @param string $name |
|
| 31 | + * @param string $nameType first|first_initial|initials|last|last_initial |
|
| 32 | + * @param string $initialType period|period_space|space |
|
| 33 | + * @return string |
|
| 34 | + */ |
|
| 35 | + public static function convertName($name, $nameType = '', $initialType = '') |
|
| 36 | + { |
|
| 37 | + $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY); |
|
| 38 | + $firstName = array_shift($names); |
|
| 39 | + $lastName = array_pop($names); |
|
| 40 | + $initialTypes = [ |
|
| 41 | + 'period' => '.', |
|
| 42 | + 'period_space' => '. ', |
|
| 43 | + 'space' => ' ', |
|
| 44 | + ]; |
|
| 45 | + $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' '); |
|
| 46 | + if ('initials' == $nameType) { |
|
| 47 | + return static::convertToInitials($name, $initialPunctuation); |
|
| 48 | + } |
|
| 49 | + $nameTypes = [ |
|
| 50 | + 'first' => $firstName, |
|
| 51 | + 'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName, |
|
| 52 | + 'last' => $lastName, |
|
| 53 | + 'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation, |
|
| 54 | + ]; |
|
| 55 | + return trim((string) Arr::get($nameTypes, $nameType, $name)); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @param string $path |
|
| 60 | - * @param string $prefix |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public static function convertPathToId($path, $prefix = '') |
|
| 64 | - { |
|
| 65 | - return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix)); |
|
| 66 | - } |
|
| 58 | + /** |
|
| 59 | + * @param string $path |
|
| 60 | + * @param string $prefix |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public static function convertPathToId($path, $prefix = '') |
|
| 64 | + { |
|
| 65 | + return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix)); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @param string $path |
|
| 70 | - * @param string $prefix |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public static function convertPathToName($path, $prefix = '') |
|
| 74 | - { |
|
| 75 | - $levels = explode('.', $path); |
|
| 76 | - return array_reduce($levels, function ($result, $value) { |
|
| 77 | - return $result .= '['.$value.']'; |
|
| 78 | - }, $prefix); |
|
| 79 | - } |
|
| 68 | + /** |
|
| 69 | + * @param string $path |
|
| 70 | + * @param string $prefix |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public static function convertPathToName($path, $prefix = '') |
|
| 74 | + { |
|
| 75 | + $levels = explode('.', $path); |
|
| 76 | + return array_reduce($levels, function ($result, $value) { |
|
| 77 | + return $result .= '['.$value.']'; |
|
| 78 | + }, $prefix); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @param string $name |
|
| 83 | - * @param string $initialPunctuation |
|
| 84 | - * @return string |
|
| 85 | - */ |
|
| 86 | - public static function convertToInitials($name, $initialPunctuation = '') |
|
| 87 | - { |
|
| 88 | - preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches); |
|
| 89 | - return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) { |
|
| 90 | - return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation; |
|
| 91 | - }); |
|
| 92 | - } |
|
| 81 | + /** |
|
| 82 | + * @param string $name |
|
| 83 | + * @param string $initialPunctuation |
|
| 84 | + * @return string |
|
| 85 | + */ |
|
| 86 | + public static function convertToInitials($name, $initialPunctuation = '') |
|
| 87 | + { |
|
| 88 | + preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches); |
|
| 89 | + return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) { |
|
| 90 | + return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation; |
|
| 91 | + }); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @param string $string |
|
| 96 | - * @return string |
|
| 97 | - */ |
|
| 98 | - public static function dashCase($string) |
|
| 99 | - { |
|
| 100 | - return str_replace('_', '-', static::snakeCase($string)); |
|
| 101 | - } |
|
| 94 | + /** |
|
| 95 | + * @param string $string |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 98 | + public static function dashCase($string) |
|
| 99 | + { |
|
| 100 | + return str_replace('_', '-', static::snakeCase($string)); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * @param string $needle |
|
| 105 | - * @param string $haystack |
|
| 106 | - * @return bool |
|
| 107 | - */ |
|
| 108 | - public static function endsWith($needle, $haystack) |
|
| 109 | - { |
|
| 110 | - $length = strlen($needle); |
|
| 111 | - return 0 != $length |
|
| 112 | - ? substr($haystack, -$length) === $needle |
|
| 113 | - : true; |
|
| 114 | - } |
|
| 103 | + /** |
|
| 104 | + * @param string $needle |
|
| 105 | + * @param string $haystack |
|
| 106 | + * @return bool |
|
| 107 | + */ |
|
| 108 | + public static function endsWith($needle, $haystack) |
|
| 109 | + { |
|
| 110 | + $length = strlen($needle); |
|
| 111 | + return 0 != $length |
|
| 112 | + ? substr($haystack, -$length) === $needle |
|
| 113 | + : true; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * @param string $prefix |
|
| 118 | - * @param string $string |
|
| 119 | - * @param string|null $trim |
|
| 120 | - * @return string |
|
| 121 | - */ |
|
| 122 | - public static function prefix($prefix, $string, $trim = null) |
|
| 123 | - { |
|
| 124 | - if (null === $trim) { |
|
| 125 | - $trim = $prefix; |
|
| 126 | - } |
|
| 127 | - return $prefix.trim(static::removePrefix($trim, $string)); |
|
| 128 | - } |
|
| 116 | + /** |
|
| 117 | + * @param string $prefix |
|
| 118 | + * @param string $string |
|
| 119 | + * @param string|null $trim |
|
| 120 | + * @return string |
|
| 121 | + */ |
|
| 122 | + public static function prefix($prefix, $string, $trim = null) |
|
| 123 | + { |
|
| 124 | + if (null === $trim) { |
|
| 125 | + $trim = $prefix; |
|
| 126 | + } |
|
| 127 | + return $prefix.trim(static::removePrefix($trim, $string)); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * @param string $prefix |
|
| 132 | - * @param string $string |
|
| 133 | - * @return string |
|
| 134 | - */ |
|
| 135 | - public static function removePrefix($prefix, $string) |
|
| 136 | - { |
|
| 137 | - return static::startsWith($prefix, $string) |
|
| 138 | - ? substr($string, strlen($prefix)) |
|
| 139 | - : $string; |
|
| 140 | - } |
|
| 130 | + /** |
|
| 131 | + * @param string $prefix |
|
| 132 | + * @param string $string |
|
| 133 | + * @return string |
|
| 134 | + */ |
|
| 135 | + public static function removePrefix($prefix, $string) |
|
| 136 | + { |
|
| 137 | + return static::startsWith($prefix, $string) |
|
| 138 | + ? substr($string, strlen($prefix)) |
|
| 139 | + : $string; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * @param string $string |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - public static function snakeCase($string) |
|
| 147 | - { |
|
| 148 | - if (!ctype_lower($string)) { |
|
| 149 | - $string = preg_replace('/\s+/u', '', $string); |
|
| 150 | - $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
| 151 | - $string = function_exists('mb_strtolower') |
|
| 152 | - ? mb_strtolower($string, 'UTF-8') |
|
| 153 | - : strtolower($string); |
|
| 154 | - } |
|
| 155 | - return str_replace('-', '_', $string); |
|
| 156 | - } |
|
| 142 | + /** |
|
| 143 | + * @param string $string |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + public static function snakeCase($string) |
|
| 147 | + { |
|
| 148 | + if (!ctype_lower($string)) { |
|
| 149 | + $string = preg_replace('/\s+/u', '', $string); |
|
| 150 | + $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
| 151 | + $string = function_exists('mb_strtolower') |
|
| 152 | + ? mb_strtolower($string, 'UTF-8') |
|
| 153 | + : strtolower($string); |
|
| 154 | + } |
|
| 155 | + return str_replace('-', '_', $string); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * @param string $needle |
|
| 160 | - * @param string $haystack |
|
| 161 | - * @return bool |
|
| 162 | - */ |
|
| 163 | - public static function startsWith($needle, $haystack) |
|
| 164 | - { |
|
| 165 | - return substr($haystack, 0, strlen($needle)) === $needle; |
|
| 166 | - } |
|
| 158 | + /** |
|
| 159 | + * @param string $needle |
|
| 160 | + * @param string $haystack |
|
| 161 | + * @return bool |
|
| 162 | + */ |
|
| 163 | + public static function startsWith($needle, $haystack) |
|
| 164 | + { |
|
| 165 | + return substr($haystack, 0, strlen($needle)) === $needle; |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * @param string $string |
|
| 170 | - * @param int $length |
|
| 171 | - * @return string |
|
| 172 | - */ |
|
| 173 | - public static function truncate($string, $length) |
|
| 174 | - { |
|
| 175 | - return strlen($string) > $length |
|
| 176 | - ? substr($string, 0, $length) |
|
| 177 | - : $string; |
|
| 178 | - } |
|
| 168 | + /** |
|
| 169 | + * @param string $string |
|
| 170 | + * @param int $length |
|
| 171 | + * @return string |
|
| 172 | + */ |
|
| 173 | + public static function truncate($string, $length) |
|
| 174 | + { |
|
| 175 | + return strlen($string) > $length |
|
| 176 | + ? substr($string, 0, $length) |
|
| 177 | + : $string; |
|
| 178 | + } |
|
| 179 | 179 | } |
@@ -10,228 +10,228 @@ |
||
| 10 | 10 | |
| 11 | 11 | class TranslationController |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @var Translator |
|
| 15 | - */ |
|
| 16 | - public $translator; |
|
| 17 | - |
|
| 18 | - public function __construct(Translator $translator) |
|
| 19 | - { |
|
| 20 | - $this->translator = $translator; |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @param array $messages |
|
| 25 | - * @return array |
|
| 26 | - * @filter bulk_post_updated_messages |
|
| 27 | - */ |
|
| 28 | - public function filterBulkUpdateMessages($messages, array $counts) |
|
| 29 | - { |
|
| 30 | - $messages = Arr::consolidateArray($messages); |
|
| 31 | - $messages[Application::POST_TYPE] = [ |
|
| 32 | - 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
| 33 | - 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
| 34 | - 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
| 35 | - 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
| 36 | - 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
| 37 | - ]; |
|
| 38 | - return $messages; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @param string $translation |
|
| 43 | - * @param string $text |
|
| 44 | - * @param string $domain |
|
| 45 | - * @return string |
|
| 46 | - * @filter gettext |
|
| 47 | - */ |
|
| 48 | - public function filterGettext($translation, $text, $domain) |
|
| 49 | - { |
|
| 50 | - return apply_filters('site-reviews/gettext/'.$domain, $translation, $text); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param string $translation |
|
| 55 | - * @param string $text |
|
| 56 | - * @return string |
|
| 57 | - * @filter site-reviews/gettext/site-reviews |
|
| 58 | - */ |
|
| 59 | - public function filterGettextSiteReviews($translation, $text) |
|
| 60 | - { |
|
| 61 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 62 | - 'single' => $text, |
|
| 63 | - ]); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @param string $translation |
|
| 68 | - * @param string $text |
|
| 69 | - * @param string $context |
|
| 70 | - * @param string $domain |
|
| 71 | - * @return string |
|
| 72 | - * @filter gettext_with_context |
|
| 73 | - */ |
|
| 74 | - public function filterGettextWithContext($translation, $text, $context, $domain) |
|
| 75 | - { |
|
| 76 | - return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param string $translation |
|
| 81 | - * @param string $text |
|
| 82 | - * @param string $context |
|
| 83 | - * @return string |
|
| 84 | - * @filter site-reviews/gettext_with_context/site-reviews |
|
| 85 | - */ |
|
| 86 | - public function filterGettextWithContextSiteReviews($translation, $text, $context) |
|
| 87 | - { |
|
| 88 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 89 | - 'context' => $context, |
|
| 90 | - 'single' => $text, |
|
| 91 | - ]); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param string $translation |
|
| 96 | - * @param string $single |
|
| 97 | - * @param string $plural |
|
| 98 | - * @param int $number |
|
| 99 | - * @param string $domain |
|
| 100 | - * @return string |
|
| 101 | - * @filter ngettext |
|
| 102 | - */ |
|
| 103 | - public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
| 104 | - { |
|
| 105 | - return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param string $translation |
|
| 110 | - * @param string $single |
|
| 111 | - * @param string $plural |
|
| 112 | - * @param int $number |
|
| 113 | - * @return string |
|
| 114 | - * @filter site-reviews/ngettext/site-reviews |
|
| 115 | - */ |
|
| 116 | - public function filterNgettextSiteReviews($translation, $single, $plural, $number) |
|
| 117 | - { |
|
| 118 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 119 | - 'number' => $number, |
|
| 120 | - 'plural' => $plural, |
|
| 121 | - 'single' => $single, |
|
| 122 | - ]); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @param string $translation |
|
| 127 | - * @param string $single |
|
| 128 | - * @param string $plural |
|
| 129 | - * @param int $number |
|
| 130 | - * @param string $context |
|
| 131 | - * @param string $domain |
|
| 132 | - * @return string |
|
| 133 | - * @filter ngettext_with_context |
|
| 134 | - */ |
|
| 135 | - public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
| 136 | - { |
|
| 137 | - return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param string $translation |
|
| 142 | - * @param string $single |
|
| 143 | - * @param string $plural |
|
| 144 | - * @param int $number |
|
| 145 | - * @param string $context |
|
| 146 | - * @return string |
|
| 147 | - * @filter site-reviews/ngettext_with_context/site-reviews |
|
| 148 | - */ |
|
| 149 | - public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context) |
|
| 150 | - { |
|
| 151 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 152 | - 'context' => $context, |
|
| 153 | - 'number' => $number, |
|
| 154 | - 'plural' => $plural, |
|
| 155 | - 'single' => $single, |
|
| 156 | - ]); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @param array $postStates |
|
| 161 | - * @param \WP_Post $post |
|
| 162 | - * @return array |
|
| 163 | - * @filter display_post_states |
|
| 164 | - */ |
|
| 165 | - public function filterPostStates($postStates, $post) |
|
| 166 | - { |
|
| 167 | - $postStates = Arr::consolidateArray($postStates); |
|
| 168 | - if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
| 169 | - $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
| 170 | - } |
|
| 171 | - return $postStates; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @param string $translation |
|
| 176 | - * @param string $text |
|
| 177 | - * @return string |
|
| 178 | - * @filter site-reviews/gettext/default |
|
| 179 | - * @filter site-reviews/gettext_with_context/default |
|
| 180 | - */ |
|
| 181 | - public function filterPostStatusLabels($translation, $text) |
|
| 182 | - { |
|
| 183 | - return $this->canModifyTranslation() |
|
| 184 | - ? glsr(Labels::class)->filterPostStatusLabels($translation, $text) |
|
| 185 | - : $translation; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * @param string $translation |
|
| 190 | - * @param string $single |
|
| 191 | - * @param string $plural |
|
| 192 | - * @param int $number |
|
| 193 | - * @return string |
|
| 194 | - * @filter site-reviews/ngettext/default |
|
| 195 | - */ |
|
| 196 | - public function filterPostStatusText($translation, $single, $plural, $number) |
|
| 197 | - { |
|
| 198 | - if ($this->canModifyTranslation()) { |
|
| 199 | - $strings = [ |
|
| 200 | - 'Published' => __('Approved', 'site-reviews'), |
|
| 201 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
| 202 | - ]; |
|
| 203 | - foreach ($strings as $search => $replace) { |
|
| 204 | - if (!Str::contains($single, $search)) { |
|
| 205 | - continue; |
|
| 206 | - } |
|
| 207 | - return $this->translator->getTranslation([ |
|
| 208 | - 'number' => $number, |
|
| 209 | - 'plural' => str_replace($search, $replace, $plural), |
|
| 210 | - 'single' => str_replace($search, $replace, $single), |
|
| 211 | - ]); |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - return $translation; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * @return void |
|
| 219 | - * @action admin_enqueue_scripts |
|
| 220 | - */ |
|
| 221 | - public function translatePostStatusLabels() |
|
| 222 | - { |
|
| 223 | - if ($this->canModifyTranslation()) { |
|
| 224 | - glsr(Labels::class)->translatePostStatusLabels(); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * @return bool |
|
| 230 | - */ |
|
| 231 | - protected function canModifyTranslation() |
|
| 232 | - { |
|
| 233 | - $screen = glsr_current_screen(); |
|
| 234 | - return Application::POST_TYPE == $screen->post_type |
|
| 235 | - && in_array($screen->base, ['edit', 'post']); |
|
| 236 | - } |
|
| 13 | + /** |
|
| 14 | + * @var Translator |
|
| 15 | + */ |
|
| 16 | + public $translator; |
|
| 17 | + |
|
| 18 | + public function __construct(Translator $translator) |
|
| 19 | + { |
|
| 20 | + $this->translator = $translator; |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @param array $messages |
|
| 25 | + * @return array |
|
| 26 | + * @filter bulk_post_updated_messages |
|
| 27 | + */ |
|
| 28 | + public function filterBulkUpdateMessages($messages, array $counts) |
|
| 29 | + { |
|
| 30 | + $messages = Arr::consolidateArray($messages); |
|
| 31 | + $messages[Application::POST_TYPE] = [ |
|
| 32 | + 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
| 33 | + 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
| 34 | + 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
| 35 | + 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
| 36 | + 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
| 37 | + ]; |
|
| 38 | + return $messages; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @param string $translation |
|
| 43 | + * @param string $text |
|
| 44 | + * @param string $domain |
|
| 45 | + * @return string |
|
| 46 | + * @filter gettext |
|
| 47 | + */ |
|
| 48 | + public function filterGettext($translation, $text, $domain) |
|
| 49 | + { |
|
| 50 | + return apply_filters('site-reviews/gettext/'.$domain, $translation, $text); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param string $translation |
|
| 55 | + * @param string $text |
|
| 56 | + * @return string |
|
| 57 | + * @filter site-reviews/gettext/site-reviews |
|
| 58 | + */ |
|
| 59 | + public function filterGettextSiteReviews($translation, $text) |
|
| 60 | + { |
|
| 61 | + return $this->translator->translate($translation, Application::ID, [ |
|
| 62 | + 'single' => $text, |
|
| 63 | + ]); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @param string $translation |
|
| 68 | + * @param string $text |
|
| 69 | + * @param string $context |
|
| 70 | + * @param string $domain |
|
| 71 | + * @return string |
|
| 72 | + * @filter gettext_with_context |
|
| 73 | + */ |
|
| 74 | + public function filterGettextWithContext($translation, $text, $context, $domain) |
|
| 75 | + { |
|
| 76 | + return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param string $translation |
|
| 81 | + * @param string $text |
|
| 82 | + * @param string $context |
|
| 83 | + * @return string |
|
| 84 | + * @filter site-reviews/gettext_with_context/site-reviews |
|
| 85 | + */ |
|
| 86 | + public function filterGettextWithContextSiteReviews($translation, $text, $context) |
|
| 87 | + { |
|
| 88 | + return $this->translator->translate($translation, Application::ID, [ |
|
| 89 | + 'context' => $context, |
|
| 90 | + 'single' => $text, |
|
| 91 | + ]); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param string $translation |
|
| 96 | + * @param string $single |
|
| 97 | + * @param string $plural |
|
| 98 | + * @param int $number |
|
| 99 | + * @param string $domain |
|
| 100 | + * @return string |
|
| 101 | + * @filter ngettext |
|
| 102 | + */ |
|
| 103 | + public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
| 104 | + { |
|
| 105 | + return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param string $translation |
|
| 110 | + * @param string $single |
|
| 111 | + * @param string $plural |
|
| 112 | + * @param int $number |
|
| 113 | + * @return string |
|
| 114 | + * @filter site-reviews/ngettext/site-reviews |
|
| 115 | + */ |
|
| 116 | + public function filterNgettextSiteReviews($translation, $single, $plural, $number) |
|
| 117 | + { |
|
| 118 | + return $this->translator->translate($translation, Application::ID, [ |
|
| 119 | + 'number' => $number, |
|
| 120 | + 'plural' => $plural, |
|
| 121 | + 'single' => $single, |
|
| 122 | + ]); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @param string $translation |
|
| 127 | + * @param string $single |
|
| 128 | + * @param string $plural |
|
| 129 | + * @param int $number |
|
| 130 | + * @param string $context |
|
| 131 | + * @param string $domain |
|
| 132 | + * @return string |
|
| 133 | + * @filter ngettext_with_context |
|
| 134 | + */ |
|
| 135 | + public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
| 136 | + { |
|
| 137 | + return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param string $translation |
|
| 142 | + * @param string $single |
|
| 143 | + * @param string $plural |
|
| 144 | + * @param int $number |
|
| 145 | + * @param string $context |
|
| 146 | + * @return string |
|
| 147 | + * @filter site-reviews/ngettext_with_context/site-reviews |
|
| 148 | + */ |
|
| 149 | + public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context) |
|
| 150 | + { |
|
| 151 | + return $this->translator->translate($translation, Application::ID, [ |
|
| 152 | + 'context' => $context, |
|
| 153 | + 'number' => $number, |
|
| 154 | + 'plural' => $plural, |
|
| 155 | + 'single' => $single, |
|
| 156 | + ]); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @param array $postStates |
|
| 161 | + * @param \WP_Post $post |
|
| 162 | + * @return array |
|
| 163 | + * @filter display_post_states |
|
| 164 | + */ |
|
| 165 | + public function filterPostStates($postStates, $post) |
|
| 166 | + { |
|
| 167 | + $postStates = Arr::consolidateArray($postStates); |
|
| 168 | + if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
| 169 | + $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
| 170 | + } |
|
| 171 | + return $postStates; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @param string $translation |
|
| 176 | + * @param string $text |
|
| 177 | + * @return string |
|
| 178 | + * @filter site-reviews/gettext/default |
|
| 179 | + * @filter site-reviews/gettext_with_context/default |
|
| 180 | + */ |
|
| 181 | + public function filterPostStatusLabels($translation, $text) |
|
| 182 | + { |
|
| 183 | + return $this->canModifyTranslation() |
|
| 184 | + ? glsr(Labels::class)->filterPostStatusLabels($translation, $text) |
|
| 185 | + : $translation; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * @param string $translation |
|
| 190 | + * @param string $single |
|
| 191 | + * @param string $plural |
|
| 192 | + * @param int $number |
|
| 193 | + * @return string |
|
| 194 | + * @filter site-reviews/ngettext/default |
|
| 195 | + */ |
|
| 196 | + public function filterPostStatusText($translation, $single, $plural, $number) |
|
| 197 | + { |
|
| 198 | + if ($this->canModifyTranslation()) { |
|
| 199 | + $strings = [ |
|
| 200 | + 'Published' => __('Approved', 'site-reviews'), |
|
| 201 | + 'Pending' => __('Unapproved', 'site-reviews'), |
|
| 202 | + ]; |
|
| 203 | + foreach ($strings as $search => $replace) { |
|
| 204 | + if (!Str::contains($single, $search)) { |
|
| 205 | + continue; |
|
| 206 | + } |
|
| 207 | + return $this->translator->getTranslation([ |
|
| 208 | + 'number' => $number, |
|
| 209 | + 'plural' => str_replace($search, $replace, $plural), |
|
| 210 | + 'single' => str_replace($search, $replace, $single), |
|
| 211 | + ]); |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + return $translation; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * @return void |
|
| 219 | + * @action admin_enqueue_scripts |
|
| 220 | + */ |
|
| 221 | + public function translatePostStatusLabels() |
|
| 222 | + { |
|
| 223 | + if ($this->canModifyTranslation()) { |
|
| 224 | + glsr(Labels::class)->translatePostStatusLabels(); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * @return bool |
|
| 230 | + */ |
|
| 231 | + protected function canModifyTranslation() |
|
| 232 | + { |
|
| 233 | + $screen = glsr_current_screen(); |
|
| 234 | + return Application::POST_TYPE == $screen->post_type |
|
| 235 | + && in_array($screen->base, ['edit', 'post']); |
|
| 236 | + } |
|
| 237 | 237 | } |
@@ -10,52 +10,52 @@ |
||
| 10 | 10 | |
| 11 | 11 | class Pagination implements PartialContract |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @var array |
|
| 15 | - */ |
|
| 16 | - protected $args; |
|
| 13 | + /** |
|
| 14 | + * @var array |
|
| 15 | + */ |
|
| 16 | + protected $args; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @return void|string |
|
| 20 | - */ |
|
| 21 | - public function build(array $args = []) |
|
| 22 | - { |
|
| 23 | - $this->args = $this->normalize($args); |
|
| 24 | - if ($this->args['total'] < 2) { |
|
| 25 | - return; |
|
| 26 | - } |
|
| 27 | - return glsr(Template::class)->build('templates/pagination', [ |
|
| 28 | - 'context' => [ |
|
| 29 | - 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
| 30 | - 'loader' => '<div class="glsr-loader"></div>', |
|
| 31 | - 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
| 32 | - ], |
|
| 33 | - ]); |
|
| 34 | - } |
|
| 18 | + /** |
|
| 19 | + * @return void|string |
|
| 20 | + */ |
|
| 21 | + public function build(array $args = []) |
|
| 22 | + { |
|
| 23 | + $this->args = $this->normalize($args); |
|
| 24 | + if ($this->args['total'] < 2) { |
|
| 25 | + return; |
|
| 26 | + } |
|
| 27 | + return glsr(Template::class)->build('templates/pagination', [ |
|
| 28 | + 'context' => [ |
|
| 29 | + 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
| 30 | + 'loader' => '<div class="glsr-loader"></div>', |
|
| 31 | + 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
| 32 | + ], |
|
| 33 | + ]); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - protected function buildLinks() |
|
| 40 | - { |
|
| 41 | - $args = glsr(Style::class)->paginationArgs($this->args); |
|
| 42 | - if ('array' == $args['type']) { |
|
| 43 | - $args['type'] = 'plain'; |
|
| 44 | - } |
|
| 45 | - return paginate_links($args); |
|
| 46 | - } |
|
| 36 | + /** |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + protected function buildLinks() |
|
| 40 | + { |
|
| 41 | + $args = glsr(Style::class)->paginationArgs($this->args); |
|
| 42 | + if ('array' == $args['type']) { |
|
| 43 | + $args['type'] = 'plain'; |
|
| 44 | + } |
|
| 45 | + return paginate_links($args); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @return array |
|
| 50 | - */ |
|
| 51 | - protected function normalize(array $args) |
|
| 52 | - { |
|
| 53 | - if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
| 54 | - $args['base'] = $baseUrl.'%_%'; |
|
| 55 | - } |
|
| 56 | - return wp_parse_args(array_filter($args), [ |
|
| 57 | - 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
| 58 | - 'total' => 1, |
|
| 59 | - ]); |
|
| 60 | - } |
|
| 48 | + /** |
|
| 49 | + * @return array |
|
| 50 | + */ |
|
| 51 | + protected function normalize(array $args) |
|
| 52 | + { |
|
| 53 | + if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
| 54 | + $args['base'] = $baseUrl.'%_%'; |
|
| 55 | + } |
|
| 56 | + return wp_parse_args(array_filter($args), [ |
|
| 57 | + 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
| 58 | + 'total' => 1, |
|
| 59 | + ]); |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -8,135 +8,135 @@ |
||
| 8 | 8 | |
| 9 | 9 | class ReviewsHtml extends ArrayObject |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @var array |
|
| 13 | - */ |
|
| 14 | - public $args; |
|
| 11 | + /** |
|
| 12 | + * @var array |
|
| 13 | + */ |
|
| 14 | + public $args; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var int |
|
| 18 | - */ |
|
| 19 | - public $max_num_pages; |
|
| 16 | + /** |
|
| 17 | + * @var int |
|
| 18 | + */ |
|
| 19 | + public $max_num_pages; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - public $pagination; |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + public $pagination; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - public $reviews; |
|
| 26 | + /** |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + public $reviews; |
|
| 30 | 30 | |
| 31 | - public function __construct(array $renderedReviews, $maxPageCount, array $args) |
|
| 32 | - { |
|
| 33 | - $this->args = $args; |
|
| 34 | - $this->max_num_pages = $maxPageCount; |
|
| 35 | - $this->reviews = $renderedReviews; |
|
| 36 | - $this->pagination = $this->buildPagination(); |
|
| 37 | - parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
| 38 | - } |
|
| 31 | + public function __construct(array $renderedReviews, $maxPageCount, array $args) |
|
| 32 | + { |
|
| 33 | + $this->args = $args; |
|
| 34 | + $this->max_num_pages = $maxPageCount; |
|
| 35 | + $this->reviews = $renderedReviews; |
|
| 36 | + $this->pagination = $this->buildPagination(); |
|
| 37 | + parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @return string |
|
| 42 | - */ |
|
| 43 | - public function __toString() |
|
| 44 | - { |
|
| 45 | - return glsr(Template::class)->build('templates/reviews', [ |
|
| 46 | - 'args' => $this->args, |
|
| 47 | - 'context' => [ |
|
| 48 | - 'assigned_to' => $this->args['assigned_to'], |
|
| 49 | - 'category' => $this->args['category'], |
|
| 50 | - 'class' => $this->getClass(), |
|
| 51 | - 'id' => $this->args['id'], |
|
| 52 | - 'pagination' => $this->getPagination(), |
|
| 53 | - 'reviews' => $this->getReviews(), |
|
| 54 | - ], |
|
| 55 | - ]); |
|
| 56 | - } |
|
| 40 | + /** |
|
| 41 | + * @return string |
|
| 42 | + */ |
|
| 43 | + public function __toString() |
|
| 44 | + { |
|
| 45 | + return glsr(Template::class)->build('templates/reviews', [ |
|
| 46 | + 'args' => $this->args, |
|
| 47 | + 'context' => [ |
|
| 48 | + 'assigned_to' => $this->args['assigned_to'], |
|
| 49 | + 'category' => $this->args['category'], |
|
| 50 | + 'class' => $this->getClass(), |
|
| 51 | + 'id' => $this->args['id'], |
|
| 52 | + 'pagination' => $this->getPagination(), |
|
| 53 | + 'reviews' => $this->getReviews(), |
|
| 54 | + ], |
|
| 55 | + ]); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @return string |
|
| 60 | - */ |
|
| 61 | - public function getPagination() |
|
| 62 | - { |
|
| 63 | - return wp_validate_boolean($this->args['pagination']) |
|
| 64 | - ? $this->pagination |
|
| 65 | - : ''; |
|
| 66 | - } |
|
| 58 | + /** |
|
| 59 | + * @return string |
|
| 60 | + */ |
|
| 61 | + public function getPagination() |
|
| 62 | + { |
|
| 63 | + return wp_validate_boolean($this->args['pagination']) |
|
| 64 | + ? $this->pagination |
|
| 65 | + : ''; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @return string |
|
| 70 | - */ |
|
| 71 | - public function getReviews() |
|
| 72 | - { |
|
| 73 | - $html = empty($this->reviews) |
|
| 74 | - ? $this->getReviewsFallback() |
|
| 75 | - : implode(PHP_EOL, $this->reviews); |
|
| 76 | - $wrapper = '<div class="glsr-reviews">%s</div>'; |
|
| 77 | - $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
| 78 | - return sprintf($wrapper, $html); |
|
| 79 | - } |
|
| 68 | + /** |
|
| 69 | + * @return string |
|
| 70 | + */ |
|
| 71 | + public function getReviews() |
|
| 72 | + { |
|
| 73 | + $html = empty($this->reviews) |
|
| 74 | + ? $this->getReviewsFallback() |
|
| 75 | + : implode(PHP_EOL, $this->reviews); |
|
| 76 | + $wrapper = '<div class="glsr-reviews">%s</div>'; |
|
| 77 | + $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
| 78 | + return sprintf($wrapper, $html); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @param mixed $key |
|
| 83 | - * @return mixed |
|
| 84 | - */ |
|
| 85 | - public function offsetGet($key) |
|
| 86 | - { |
|
| 87 | - if ('navigation' == $key) { |
|
| 88 | - glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
|
| 89 | - return $this->pagination; |
|
| 90 | - } |
|
| 91 | - if (property_exists($this, $key)) { |
|
| 92 | - return $this->$key; |
|
| 93 | - } |
|
| 94 | - return array_key_exists($key, $this->reviews) |
|
| 95 | - ? $this->reviews[$key] |
|
| 96 | - : null; |
|
| 97 | - } |
|
| 81 | + /** |
|
| 82 | + * @param mixed $key |
|
| 83 | + * @return mixed |
|
| 84 | + */ |
|
| 85 | + public function offsetGet($key) |
|
| 86 | + { |
|
| 87 | + if ('navigation' == $key) { |
|
| 88 | + glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
|
| 89 | + return $this->pagination; |
|
| 90 | + } |
|
| 91 | + if (property_exists($this, $key)) { |
|
| 92 | + return $this->$key; |
|
| 93 | + } |
|
| 94 | + return array_key_exists($key, $this->reviews) |
|
| 95 | + ? $this->reviews[$key] |
|
| 96 | + : null; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - protected function buildPagination() |
|
| 103 | - { |
|
| 104 | - $html = glsr(Partial::class)->build('pagination', [ |
|
| 105 | - 'baseUrl' => Arr::get($this->args, 'pagedUrl'), |
|
| 106 | - 'current' => Arr::get($this->args, 'paged'), |
|
| 107 | - 'total' => $this->max_num_pages, |
|
| 108 | - ]); |
|
| 109 | - $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
| 110 | - $wrapper = '<div class="glsr-pagination">%s</div>'; |
|
| 111 | - $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
| 112 | - return sprintf($wrapper, $html); |
|
| 113 | - } |
|
| 99 | + /** |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + protected function buildPagination() |
|
| 103 | + { |
|
| 104 | + $html = glsr(Partial::class)->build('pagination', [ |
|
| 105 | + 'baseUrl' => Arr::get($this->args, 'pagedUrl'), |
|
| 106 | + 'current' => Arr::get($this->args, 'paged'), |
|
| 107 | + 'total' => $this->max_num_pages, |
|
| 108 | + ]); |
|
| 109 | + $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
| 110 | + $wrapper = '<div class="glsr-pagination">%s</div>'; |
|
| 111 | + $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
| 112 | + return sprintf($wrapper, $html); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * @return string |
|
| 117 | - */ |
|
| 118 | - protected function getClass() |
|
| 119 | - { |
|
| 120 | - $defaults = [ |
|
| 121 | - 'glsr-default', |
|
| 122 | - ]; |
|
| 123 | - if ('ajax' == $this->args['pagination']) { |
|
| 124 | - $defaults[] = 'glsr-ajax-pagination'; |
|
| 125 | - } |
|
| 126 | - $classes = explode(' ', $this->args['class']); |
|
| 127 | - $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
| 128 | - return implode(' ', $classes); |
|
| 129 | - } |
|
| 115 | + /** |
|
| 116 | + * @return string |
|
| 117 | + */ |
|
| 118 | + protected function getClass() |
|
| 119 | + { |
|
| 120 | + $defaults = [ |
|
| 121 | + 'glsr-default', |
|
| 122 | + ]; |
|
| 123 | + if ('ajax' == $this->args['pagination']) { |
|
| 124 | + $defaults[] = 'glsr-ajax-pagination'; |
|
| 125 | + } |
|
| 126 | + $classes = explode(' ', $this->args['class']); |
|
| 127 | + $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
| 128 | + return implode(' ', $classes); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * @return string |
|
| 133 | - */ |
|
| 134 | - protected function getReviewsFallback() |
|
| 135 | - { |
|
| 136 | - if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
| 137 | - $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
| 138 | - } |
|
| 139 | - $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
|
| 140 | - return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
| 141 | - } |
|
| 131 | + /** |
|
| 132 | + * @return string |
|
| 133 | + */ |
|
| 134 | + protected function getReviewsFallback() |
|
| 135 | + { |
|
| 136 | + if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
| 137 | + $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
| 138 | + } |
|
| 139 | + $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
|
| 140 | + return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
| 141 | + } |
|
| 142 | 142 | } |
@@ -15,72 +15,72 @@ |
||
| 15 | 15 | |
| 16 | 16 | class Filters implements HooksContract |
| 17 | 17 | { |
| 18 | - protected $admin; |
|
| 19 | - protected $app; |
|
| 20 | - protected $basename; |
|
| 21 | - protected $blocks; |
|
| 22 | - protected $editor; |
|
| 23 | - protected $listtable; |
|
| 24 | - protected $public; |
|
| 25 | - protected $rebusify; |
|
| 26 | - protected $translator; |
|
| 27 | - protected $welcome; |
|
| 18 | + protected $admin; |
|
| 19 | + protected $app; |
|
| 20 | + protected $basename; |
|
| 21 | + protected $blocks; |
|
| 22 | + protected $editor; |
|
| 23 | + protected $listtable; |
|
| 24 | + protected $public; |
|
| 25 | + protected $rebusify; |
|
| 26 | + protected $translator; |
|
| 27 | + protected $welcome; |
|
| 28 | 28 | |
| 29 | - public function __construct(Application $app) |
|
| 30 | - { |
|
| 31 | - $this->app = $app; |
|
| 32 | - $this->admin = $app->make(AdminController::class); |
|
| 33 | - $this->basename = plugin_basename($app->file); |
|
| 34 | - $this->blocks = $app->make(BlocksController::class); |
|
| 35 | - $this->editor = $app->make(EditorController::class); |
|
| 36 | - $this->listtable = $app->make(ListTableController::class); |
|
| 37 | - $this->public = $app->make(PublicController::class); |
|
| 38 | - $this->rebusify = $app->make(RebusifyController::class); |
|
| 39 | - $this->translator = $app->make(TranslationController::class); |
|
| 40 | - $this->welcome = $app->make(WelcomeController::class); |
|
| 41 | - } |
|
| 29 | + public function __construct(Application $app) |
|
| 30 | + { |
|
| 31 | + $this->app = $app; |
|
| 32 | + $this->admin = $app->make(AdminController::class); |
|
| 33 | + $this->basename = plugin_basename($app->file); |
|
| 34 | + $this->blocks = $app->make(BlocksController::class); |
|
| 35 | + $this->editor = $app->make(EditorController::class); |
|
| 36 | + $this->listtable = $app->make(ListTableController::class); |
|
| 37 | + $this->public = $app->make(PublicController::class); |
|
| 38 | + $this->rebusify = $app->make(RebusifyController::class); |
|
| 39 | + $this->translator = $app->make(TranslationController::class); |
|
| 40 | + $this->welcome = $app->make(WelcomeController::class); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @return void |
|
| 45 | - */ |
|
| 46 | - public function run() |
|
| 47 | - { |
|
| 48 | - add_filter('map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2); |
|
| 49 | - add_filter('mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15); |
|
| 50 | - add_filter('plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks']); |
|
| 51 | - add_filter('dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems']); |
|
| 52 | - add_filter('block_categories', [$this->blocks, 'filterBlockCategories']); |
|
| 53 | - add_filter('classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2); |
|
| 54 | - add_filter('use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2); |
|
| 55 | - add_filter('wp_editor_settings', [$this->editor, 'filterEditorSettings']); |
|
| 56 | - add_filter('the_editor', [$this->editor, 'filterEditorTextarea']); |
|
| 57 | - add_filter('is_protected_meta', [$this->editor, 'filterIsProtectedMeta'], 10, 3); |
|
| 58 | - add_filter('post_updated_messages', [$this->editor, 'filterUpdateMessages']); |
|
| 59 | - add_filter('manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType']); |
|
| 60 | - add_filter('post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2); |
|
| 61 | - add_filter('default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2); |
|
| 62 | - add_filter('post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2); |
|
| 63 | - add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns']); |
|
| 64 | - add_filter('script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2); |
|
| 65 | - add_filter('site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11); |
|
| 66 | - add_filter('site-reviews/render/view', [$this->public, 'filterRenderView']); |
|
| 67 | - add_filter('site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback']); |
|
| 68 | - add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3); |
|
| 69 | - add_filter('bulk_post_updated_messages', [$this->translator, 'filterBulkUpdateMessages'], 10, 2); |
|
| 70 | - add_filter('gettext', [$this->translator, 'filterGettext'], 9, 3); |
|
| 71 | - add_filter('site-reviews/gettext/site-reviews', [$this->translator, 'filterGettextSiteReviews'], 10, 2); |
|
| 72 | - add_filter('gettext_with_context', [$this->translator, 'filterGettextWithContext'], 9, 4); |
|
| 73 | - add_filter('site-reviews/gettext_with_context/site-reviews', [$this->translator, 'filterGettextWithContextSiteReviews'], 10, 3); |
|
| 74 | - add_filter('ngettext', [$this->translator, 'filterNgettext'], 9, 5); |
|
| 75 | - add_filter('site-reviews/ngettext/site-reviews', [$this->translator, 'filterNgettextSiteReviews'], 10, 4); |
|
| 76 | - add_filter('ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 9, 6); |
|
| 77 | - add_filter('site-reviews/ngettext_with_context/site-reviews', [$this->translator, 'filterNgettextWithContextSiteReviews'], 10, 5); |
|
| 78 | - add_filter('display_post_states', [$this->translator, 'filterPostStates'], 10, 2); |
|
| 79 | - add_filter('site-reviews/gettext/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
| 80 | - add_filter('site-reviews/gettext_with_context/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
| 81 | - add_filter('site-reviews/ngettext/default', [$this->translator, 'filterPostStatusText'], 10, 4); |
|
| 82 | - add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
| 83 | - add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
| 84 | - add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
|
| 85 | - } |
|
| 43 | + /** |
|
| 44 | + * @return void |
|
| 45 | + */ |
|
| 46 | + public function run() |
|
| 47 | + { |
|
| 48 | + add_filter('map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2); |
|
| 49 | + add_filter('mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15); |
|
| 50 | + add_filter('plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks']); |
|
| 51 | + add_filter('dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems']); |
|
| 52 | + add_filter('block_categories', [$this->blocks, 'filterBlockCategories']); |
|
| 53 | + add_filter('classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2); |
|
| 54 | + add_filter('use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2); |
|
| 55 | + add_filter('wp_editor_settings', [$this->editor, 'filterEditorSettings']); |
|
| 56 | + add_filter('the_editor', [$this->editor, 'filterEditorTextarea']); |
|
| 57 | + add_filter('is_protected_meta', [$this->editor, 'filterIsProtectedMeta'], 10, 3); |
|
| 58 | + add_filter('post_updated_messages', [$this->editor, 'filterUpdateMessages']); |
|
| 59 | + add_filter('manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType']); |
|
| 60 | + add_filter('post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2); |
|
| 61 | + add_filter('default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2); |
|
| 62 | + add_filter('post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2); |
|
| 63 | + add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns']); |
|
| 64 | + add_filter('script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2); |
|
| 65 | + add_filter('site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11); |
|
| 66 | + add_filter('site-reviews/render/view', [$this->public, 'filterRenderView']); |
|
| 67 | + add_filter('site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback']); |
|
| 68 | + add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3); |
|
| 69 | + add_filter('bulk_post_updated_messages', [$this->translator, 'filterBulkUpdateMessages'], 10, 2); |
|
| 70 | + add_filter('gettext', [$this->translator, 'filterGettext'], 9, 3); |
|
| 71 | + add_filter('site-reviews/gettext/site-reviews', [$this->translator, 'filterGettextSiteReviews'], 10, 2); |
|
| 72 | + add_filter('gettext_with_context', [$this->translator, 'filterGettextWithContext'], 9, 4); |
|
| 73 | + add_filter('site-reviews/gettext_with_context/site-reviews', [$this->translator, 'filterGettextWithContextSiteReviews'], 10, 3); |
|
| 74 | + add_filter('ngettext', [$this->translator, 'filterNgettext'], 9, 5); |
|
| 75 | + add_filter('site-reviews/ngettext/site-reviews', [$this->translator, 'filterNgettextSiteReviews'], 10, 4); |
|
| 76 | + add_filter('ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 9, 6); |
|
| 77 | + add_filter('site-reviews/ngettext_with_context/site-reviews', [$this->translator, 'filterNgettextWithContextSiteReviews'], 10, 5); |
|
| 78 | + add_filter('display_post_states', [$this->translator, 'filterPostStates'], 10, 2); |
|
| 79 | + add_filter('site-reviews/gettext/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
| 80 | + add_filter('site-reviews/gettext_with_context/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
| 81 | + add_filter('site-reviews/ngettext/default', [$this->translator, 'filterPostStatusText'], 10, 4); |
|
| 82 | + add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
| 83 | + add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
| 84 | + add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -13,81 +13,81 @@ |
||
| 13 | 13 | |
| 14 | 14 | class PublicController extends Controller |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @return void |
|
| 18 | - * @action wp_enqueue_scripts |
|
| 19 | - */ |
|
| 20 | - public function enqueueAssets() |
|
| 21 | - { |
|
| 22 | - (new EnqueuePublicAssets())->handle(); |
|
| 23 | - } |
|
| 16 | + /** |
|
| 17 | + * @return void |
|
| 18 | + * @action wp_enqueue_scripts |
|
| 19 | + */ |
|
| 20 | + public function enqueueAssets() |
|
| 21 | + { |
|
| 22 | + (new EnqueuePublicAssets())->handle(); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @param string $tag |
|
| 27 | - * @param string $handle |
|
| 28 | - * @return string |
|
| 29 | - * @filter script_loader_tag |
|
| 30 | - */ |
|
| 31 | - public function filterEnqueuedScripts($tag, $handle) |
|
| 32 | - { |
|
| 33 | - $scripts = [Application::ID.'/google-recaptcha']; |
|
| 34 | - if (in_array($handle, apply_filters('site-reviews/async-scripts', $scripts))) { |
|
| 35 | - $tag = str_replace(' src=', ' async src=', $tag); |
|
| 36 | - } |
|
| 37 | - if (in_array($handle, apply_filters('site-reviews/defer-scripts', $scripts))) { |
|
| 38 | - $tag = str_replace(' src=', ' defer src=', $tag); |
|
| 39 | - } |
|
| 40 | - return $tag; |
|
| 41 | - } |
|
| 25 | + /** |
|
| 26 | + * @param string $tag |
|
| 27 | + * @param string $handle |
|
| 28 | + * @return string |
|
| 29 | + * @filter script_loader_tag |
|
| 30 | + */ |
|
| 31 | + public function filterEnqueuedScripts($tag, $handle) |
|
| 32 | + { |
|
| 33 | + $scripts = [Application::ID.'/google-recaptcha']; |
|
| 34 | + if (in_array($handle, apply_filters('site-reviews/async-scripts', $scripts))) { |
|
| 35 | + $tag = str_replace(' src=', ' async src=', $tag); |
|
| 36 | + } |
|
| 37 | + if (in_array($handle, apply_filters('site-reviews/defer-scripts', $scripts))) { |
|
| 38 | + $tag = str_replace(' src=', ' defer src=', $tag); |
|
| 39 | + } |
|
| 40 | + return $tag; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @return array |
|
| 45 | - * @filter site-reviews/config/forms/submission-form |
|
| 46 | - */ |
|
| 47 | - public function filterFieldOrder(array $config) |
|
| 48 | - { |
|
| 49 | - $order = (array) apply_filters('site-reviews/submission-form/order', array_keys($config)); |
|
| 50 | - return array_intersect_key(array_merge(array_flip($order), $config), $config); |
|
| 51 | - } |
|
| 43 | + /** |
|
| 44 | + * @return array |
|
| 45 | + * @filter site-reviews/config/forms/submission-form |
|
| 46 | + */ |
|
| 47 | + public function filterFieldOrder(array $config) |
|
| 48 | + { |
|
| 49 | + $order = (array) apply_filters('site-reviews/submission-form/order', array_keys($config)); |
|
| 50 | + return array_intersect_key(array_merge(array_flip($order), $config), $config); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @param string $view |
|
| 55 | - * @return string |
|
| 56 | - * @filter site-reviews/render/view |
|
| 57 | - */ |
|
| 58 | - public function filterRenderView($view) |
|
| 59 | - { |
|
| 60 | - return glsr(Style::class)->filterView($view); |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * @param string $view |
|
| 55 | + * @return string |
|
| 56 | + * @filter site-reviews/render/view |
|
| 57 | + */ |
|
| 58 | + public function filterRenderView($view) |
|
| 59 | + { |
|
| 60 | + return glsr(Style::class)->filterView($view); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @return void |
|
| 65 | - * @action site-reviews/builder |
|
| 66 | - */ |
|
| 67 | - public function modifyBuilder(Builder $instance) |
|
| 68 | - { |
|
| 69 | - call_user_func_array([glsr(Style::class), 'modifyField'], [$instance]); |
|
| 70 | - } |
|
| 63 | + /** |
|
| 64 | + * @return void |
|
| 65 | + * @action site-reviews/builder |
|
| 66 | + */ |
|
| 67 | + public function modifyBuilder(Builder $instance) |
|
| 68 | + { |
|
| 69 | + call_user_func_array([glsr(Style::class), 'modifyField'], [$instance]); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @return void |
|
| 74 | - * @action wp_footer |
|
| 75 | - */ |
|
| 76 | - public function renderSchema() |
|
| 77 | - { |
|
| 78 | - glsr(Schema::class)->render(); |
|
| 79 | - } |
|
| 72 | + /** |
|
| 73 | + * @return void |
|
| 74 | + * @action wp_footer |
|
| 75 | + */ |
|
| 76 | + public function renderSchema() |
|
| 77 | + { |
|
| 78 | + glsr(Schema::class)->render(); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @return CreateReview |
|
| 83 | - */ |
|
| 84 | - public function routerSubmitReview(array $request) |
|
| 85 | - { |
|
| 86 | - $validated = glsr(ValidateReview::class)->validate($request); |
|
| 87 | - $command = new CreateReview($validated->request); |
|
| 88 | - if (empty($validated->error) && !$validated->recaptchaIsUnset) { |
|
| 89 | - $this->execute($command); |
|
| 90 | - } |
|
| 91 | - return $command; |
|
| 92 | - } |
|
| 81 | + /** |
|
| 82 | + * @return CreateReview |
|
| 83 | + */ |
|
| 84 | + public function routerSubmitReview(array $request) |
|
| 85 | + { |
|
| 86 | + $validated = glsr(ValidateReview::class)->validate($request); |
|
| 87 | + $command = new CreateReview($validated->request); |
|
| 88 | + if (empty($validated->error) && !$validated->recaptchaIsUnset) { |
|
| 89 | + $this->execute($command); |
|
| 90 | + } |
|
| 91 | + return $command; |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -14,164 +14,164 @@ |
||
| 14 | 14 | |
| 15 | 15 | class AjaxController extends Controller |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @return void |
|
| 19 | - */ |
|
| 20 | - public function routerChangeStatus(array $request) |
|
| 21 | - { |
|
| 22 | - wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
| 23 | - } |
|
| 17 | + /** |
|
| 18 | + * @return void |
|
| 19 | + */ |
|
| 20 | + public function routerChangeStatus(array $request) |
|
| 21 | + { |
|
| 22 | + wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @return void |
|
| 27 | - */ |
|
| 28 | - public function routerClearConsole() |
|
| 29 | - { |
|
| 30 | - glsr(AdminController::class)->routerClearConsole(); |
|
| 31 | - wp_send_json_success([ |
|
| 32 | - 'console' => glsr(Console::class)->get(), |
|
| 33 | - 'notices' => glsr(Notice::class)->get(), |
|
| 34 | - ]); |
|
| 35 | - } |
|
| 25 | + /** |
|
| 26 | + * @return void |
|
| 27 | + */ |
|
| 28 | + public function routerClearConsole() |
|
| 29 | + { |
|
| 30 | + glsr(AdminController::class)->routerClearConsole(); |
|
| 31 | + wp_send_json_success([ |
|
| 32 | + 'console' => glsr(Console::class)->get(), |
|
| 33 | + 'notices' => glsr(Notice::class)->get(), |
|
| 34 | + ]); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return void |
|
| 39 | - */ |
|
| 40 | - public function routerCountReviews() |
|
| 41 | - { |
|
| 42 | - glsr(AdminController::class)->routerCountReviews(); |
|
| 43 | - wp_send_json_success([ |
|
| 44 | - 'notices' => glsr(Notice::class)->get(), |
|
| 45 | - ]); |
|
| 46 | - } |
|
| 37 | + /** |
|
| 38 | + * @return void |
|
| 39 | + */ |
|
| 40 | + public function routerCountReviews() |
|
| 41 | + { |
|
| 42 | + glsr(AdminController::class)->routerCountReviews(); |
|
| 43 | + wp_send_json_success([ |
|
| 44 | + 'notices' => glsr(Notice::class)->get(), |
|
| 45 | + ]); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @return void |
|
| 50 | - */ |
|
| 51 | - public function routerDismissNotice(array $request) |
|
| 52 | - { |
|
| 53 | - glsr(NoticeController::class)->routerDismissNotice($request); |
|
| 54 | - wp_send_json_success(); |
|
| 55 | - } |
|
| 48 | + /** |
|
| 49 | + * @return void |
|
| 50 | + */ |
|
| 51 | + public function routerDismissNotice(array $request) |
|
| 52 | + { |
|
| 53 | + glsr(NoticeController::class)->routerDismissNotice($request); |
|
| 54 | + wp_send_json_success(); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @return void |
|
| 59 | - */ |
|
| 60 | - public function routerMceShortcode(array $request) |
|
| 61 | - { |
|
| 62 | - $shortcode = $request['shortcode']; |
|
| 63 | - $response = false; |
|
| 64 | - if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
| 65 | - $data = glsr()->mceShortcodes[$shortcode]; |
|
| 66 | - if (!empty($data['errors'])) { |
|
| 67 | - $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
| 68 | - } |
|
| 69 | - $response = [ |
|
| 70 | - 'body' => $data['fields'], |
|
| 71 | - 'close' => $data['btn_close'], |
|
| 72 | - 'ok' => $data['btn_okay'], |
|
| 73 | - 'shortcode' => $shortcode, |
|
| 74 | - 'title' => $data['title'], |
|
| 75 | - ]; |
|
| 76 | - } |
|
| 77 | - wp_send_json_success($response); |
|
| 78 | - } |
|
| 57 | + /** |
|
| 58 | + * @return void |
|
| 59 | + */ |
|
| 60 | + public function routerMceShortcode(array $request) |
|
| 61 | + { |
|
| 62 | + $shortcode = $request['shortcode']; |
|
| 63 | + $response = false; |
|
| 64 | + if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
| 65 | + $data = glsr()->mceShortcodes[$shortcode]; |
|
| 66 | + if (!empty($data['errors'])) { |
|
| 67 | + $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
| 68 | + } |
|
| 69 | + $response = [ |
|
| 70 | + 'body' => $data['fields'], |
|
| 71 | + 'close' => $data['btn_close'], |
|
| 72 | + 'ok' => $data['btn_okay'], |
|
| 73 | + 'shortcode' => $shortcode, |
|
| 74 | + 'title' => $data['title'], |
|
| 75 | + ]; |
|
| 76 | + } |
|
| 77 | + wp_send_json_success($response); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @return void |
|
| 82 | - */ |
|
| 83 | - public function routerFetchConsole() |
|
| 84 | - { |
|
| 85 | - glsr(AdminController::class)->routerFetchConsole(); |
|
| 86 | - wp_send_json_success([ |
|
| 87 | - 'console' => glsr(Console::class)->get(), |
|
| 88 | - 'notices' => glsr(Notice::class)->get(), |
|
| 89 | - ]); |
|
| 90 | - } |
|
| 80 | + /** |
|
| 81 | + * @return void |
|
| 82 | + */ |
|
| 83 | + public function routerFetchConsole() |
|
| 84 | + { |
|
| 85 | + glsr(AdminController::class)->routerFetchConsole(); |
|
| 86 | + wp_send_json_success([ |
|
| 87 | + 'console' => glsr(Console::class)->get(), |
|
| 88 | + 'notices' => glsr(Notice::class)->get(), |
|
| 89 | + ]); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * @return void |
|
| 94 | - */ |
|
| 95 | - public function routerSearchPosts(array $request) |
|
| 96 | - { |
|
| 97 | - $results = glsr(Database::class)->searchPosts($request['search']); |
|
| 98 | - wp_send_json_success([ |
|
| 99 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
| 100 | - 'items' => $results, |
|
| 101 | - ]); |
|
| 102 | - } |
|
| 92 | + /** |
|
| 93 | + * @return void |
|
| 94 | + */ |
|
| 95 | + public function routerSearchPosts(array $request) |
|
| 96 | + { |
|
| 97 | + $results = glsr(Database::class)->searchPosts($request['search']); |
|
| 98 | + wp_send_json_success([ |
|
| 99 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
| 100 | + 'items' => $results, |
|
| 101 | + ]); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * @return void |
|
| 106 | - */ |
|
| 107 | - public function routerSearchTranslations(array $request) |
|
| 108 | - { |
|
| 109 | - if (empty($request['exclude'])) { |
|
| 110 | - $request['exclude'] = []; |
|
| 111 | - } |
|
| 112 | - $results = glsr(Translation::class) |
|
| 113 | - ->search($request['search']) |
|
| 114 | - ->exclude() |
|
| 115 | - ->exclude($request['exclude']) |
|
| 116 | - ->renderResults(); |
|
| 117 | - wp_send_json_success([ |
|
| 118 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
| 119 | - 'items' => $results, |
|
| 120 | - ]); |
|
| 121 | - } |
|
| 104 | + /** |
|
| 105 | + * @return void |
|
| 106 | + */ |
|
| 107 | + public function routerSearchTranslations(array $request) |
|
| 108 | + { |
|
| 109 | + if (empty($request['exclude'])) { |
|
| 110 | + $request['exclude'] = []; |
|
| 111 | + } |
|
| 112 | + $results = glsr(Translation::class) |
|
| 113 | + ->search($request['search']) |
|
| 114 | + ->exclude() |
|
| 115 | + ->exclude($request['exclude']) |
|
| 116 | + ->renderResults(); |
|
| 117 | + wp_send_json_success([ |
|
| 118 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
| 119 | + 'items' => $results, |
|
| 120 | + ]); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * @return void |
|
| 125 | - */ |
|
| 126 | - public function routerSubmitReview(array $request) |
|
| 127 | - { |
|
| 128 | - $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
| 129 | - $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
| 130 | - $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
| 131 | - $data = [ |
|
| 132 | - 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
| 133 | - 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
| 134 | - 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
| 135 | - 'redirect' => $redirect, |
|
| 136 | - ]; |
|
| 137 | - if (false === $data['errors']) { |
|
| 138 | - glsr()->sessionClear(); |
|
| 139 | - wp_send_json_success($data); |
|
| 140 | - } |
|
| 141 | - wp_send_json_error($data); |
|
| 142 | - } |
|
| 123 | + /** |
|
| 124 | + * @return void |
|
| 125 | + */ |
|
| 126 | + public function routerSubmitReview(array $request) |
|
| 127 | + { |
|
| 128 | + $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
| 129 | + $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
| 130 | + $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
| 131 | + $data = [ |
|
| 132 | + 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
| 133 | + 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
| 134 | + 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
| 135 | + 'redirect' => $redirect, |
|
| 136 | + ]; |
|
| 137 | + if (false === $data['errors']) { |
|
| 138 | + glsr()->sessionClear(); |
|
| 139 | + wp_send_json_success($data); |
|
| 140 | + } |
|
| 141 | + wp_send_json_error($data); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * @return void |
|
| 146 | - */ |
|
| 147 | - public function routerFetchPagedReviews(array $request) |
|
| 148 | - { |
|
| 149 | - $urlQuery = []; |
|
| 150 | - parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
| 151 | - $args = [ |
|
| 152 | - 'paged' => Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
| 153 | - 'pagedUrl' => home_url(parse_url(Arr::get($request, 'url'), PHP_URL_PATH)), |
|
| 154 | - 'pagination' => 'ajax', |
|
| 155 | - 'schema' => false, |
|
| 156 | - ]; |
|
| 157 | - $atts = (array) json_decode(Arr::get($request, 'atts')); |
|
| 158 | - $atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts); |
|
| 159 | - $html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts)); |
|
| 160 | - return wp_send_json_success([ |
|
| 161 | - 'pagination' => $html->getPagination(), |
|
| 162 | - 'reviews' => $html->getReviews(), |
|
| 163 | - ]); |
|
| 164 | - } |
|
| 144 | + /** |
|
| 145 | + * @return void |
|
| 146 | + */ |
|
| 147 | + public function routerFetchPagedReviews(array $request) |
|
| 148 | + { |
|
| 149 | + $urlQuery = []; |
|
| 150 | + parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
| 151 | + $args = [ |
|
| 152 | + 'paged' => Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
| 153 | + 'pagedUrl' => home_url(parse_url(Arr::get($request, 'url'), PHP_URL_PATH)), |
|
| 154 | + 'pagination' => 'ajax', |
|
| 155 | + 'schema' => false, |
|
| 156 | + ]; |
|
| 157 | + $atts = (array) json_decode(Arr::get($request, 'atts')); |
|
| 158 | + $atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts); |
|
| 159 | + $html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts)); |
|
| 160 | + return wp_send_json_success([ |
|
| 161 | + 'pagination' => $html->getPagination(), |
|
| 162 | + 'reviews' => $html->getReviews(), |
|
| 163 | + ]); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * @return void |
|
| 168 | - */ |
|
| 169 | - public function routerTogglePinned(array $request) |
|
| 170 | - { |
|
| 171 | - $isPinned = $this->execute(new TogglePinned($request)); |
|
| 172 | - wp_send_json_success([ |
|
| 173 | - 'notices' => glsr(Notice::class)->get(), |
|
| 174 | - 'pinned' => $isPinned, |
|
| 175 | - ]); |
|
| 176 | - } |
|
| 166 | + /** |
|
| 167 | + * @return void |
|
| 168 | + */ |
|
| 169 | + public function routerTogglePinned(array $request) |
|
| 170 | + { |
|
| 171 | + $isPinned = $this->execute(new TogglePinned($request)); |
|
| 172 | + wp_send_json_success([ |
|
| 173 | + 'notices' => glsr(Notice::class)->get(), |
|
| 174 | + 'pinned' => $isPinned, |
|
| 175 | + ]); |
|
| 176 | + } |
|
| 177 | 177 | } |
@@ -12,162 +12,162 @@ |
||
| 12 | 12 | |
| 13 | 13 | class QueryBuilder |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Build a WP_Query meta_query/tax_query. |
|
| 17 | - * @return array |
|
| 18 | - */ |
|
| 19 | - public function buildQuery(array $keys = [], array $values = []) |
|
| 20 | - { |
|
| 21 | - $queries = []; |
|
| 22 | - foreach ($keys as $key) { |
|
| 23 | - if (!array_key_exists($key, $values)) { |
|
| 24 | - continue; |
|
| 25 | - } |
|
| 26 | - $methodName = Helper::buildMethodName($key, __FUNCTION__); |
|
| 27 | - if (!method_exists($this, $methodName)) { |
|
| 28 | - continue; |
|
| 29 | - } |
|
| 30 | - $query = call_user_func([$this, $methodName], $values[$key]); |
|
| 31 | - if (is_array($query)) { |
|
| 32 | - $queries[] = $query; |
|
| 33 | - } |
|
| 34 | - } |
|
| 35 | - return $queries; |
|
| 36 | - } |
|
| 15 | + /** |
|
| 16 | + * Build a WP_Query meta_query/tax_query. |
|
| 17 | + * @return array |
|
| 18 | + */ |
|
| 19 | + public function buildQuery(array $keys = [], array $values = []) |
|
| 20 | + { |
|
| 21 | + $queries = []; |
|
| 22 | + foreach ($keys as $key) { |
|
| 23 | + if (!array_key_exists($key, $values)) { |
|
| 24 | + continue; |
|
| 25 | + } |
|
| 26 | + $methodName = Helper::buildMethodName($key, __FUNCTION__); |
|
| 27 | + if (!method_exists($this, $methodName)) { |
|
| 28 | + continue; |
|
| 29 | + } |
|
| 30 | + $query = call_user_func([$this, $methodName], $values[$key]); |
|
| 31 | + if (is_array($query)) { |
|
| 32 | + $queries[] = $query; |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | + return $queries; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @return string |
|
| 40 | - */ |
|
| 41 | - public function buildSqlLines(array $values, array $conditions) |
|
| 42 | - { |
|
| 43 | - $string = ''; |
|
| 44 | - $values = array_filter($values); |
|
| 45 | - foreach ($conditions as $key => $value) { |
|
| 46 | - if (!isset($values[$key])) { |
|
| 47 | - continue; |
|
| 48 | - } |
|
| 49 | - $values[$key] = implode(',', (array) $values[$key]); |
|
| 50 | - $string.= Str::contains($value, '%s') |
|
| 51 | - ? sprintf($value, strval($values[$key])) |
|
| 52 | - : $value; |
|
| 53 | - } |
|
| 54 | - return $string; |
|
| 55 | - } |
|
| 38 | + /** |
|
| 39 | + * @return string |
|
| 40 | + */ |
|
| 41 | + public function buildSqlLines(array $values, array $conditions) |
|
| 42 | + { |
|
| 43 | + $string = ''; |
|
| 44 | + $values = array_filter($values); |
|
| 45 | + foreach ($conditions as $key => $value) { |
|
| 46 | + if (!isset($values[$key])) { |
|
| 47 | + continue; |
|
| 48 | + } |
|
| 49 | + $values[$key] = implode(',', (array) $values[$key]); |
|
| 50 | + $string.= Str::contains($value, '%s') |
|
| 51 | + ? sprintf($value, strval($values[$key])) |
|
| 52 | + : $value; |
|
| 53 | + } |
|
| 54 | + return $string; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Build a SQL 'OR' string from an array. |
|
| 59 | - * @param string|array $values |
|
| 60 | - * @param string $sprintfFormat |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public function buildSqlOr($values, $sprintfFormat) |
|
| 64 | - { |
|
| 65 | - if (!is_array($values)) { |
|
| 66 | - $values = explode(',', $values); |
|
| 67 | - } |
|
| 68 | - $values = array_filter(array_map('trim', (array) $values)); |
|
| 69 | - $values = array_map(function ($value) use ($sprintfFormat) { |
|
| 70 | - return sprintf($sprintfFormat, $value); |
|
| 71 | - }, $values); |
|
| 72 | - return implode(' OR ', $values); |
|
| 73 | - } |
|
| 57 | + /** |
|
| 58 | + * Build a SQL 'OR' string from an array. |
|
| 59 | + * @param string|array $values |
|
| 60 | + * @param string $sprintfFormat |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public function buildSqlOr($values, $sprintfFormat) |
|
| 64 | + { |
|
| 65 | + if (!is_array($values)) { |
|
| 66 | + $values = explode(',', $values); |
|
| 67 | + } |
|
| 68 | + $values = array_filter(array_map('trim', (array) $values)); |
|
| 69 | + $values = array_map(function ($value) use ($sprintfFormat) { |
|
| 70 | + return sprintf($sprintfFormat, $value); |
|
| 71 | + }, $values); |
|
| 72 | + return implode(' OR ', $values); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Search SQL filter for matching against post title only. |
|
| 77 | - * @see http://wordpress.stackexchange.com/a/11826/1685 |
|
| 78 | - * @param string $search |
|
| 79 | - * @return string |
|
| 80 | - * @filter posts_search |
|
| 81 | - */ |
|
| 82 | - public function filterSearchByTitle($search, WP_Query $query) |
|
| 83 | - { |
|
| 84 | - if (empty($search) || empty($query->get('search_terms'))) { |
|
| 85 | - return $search; |
|
| 86 | - } |
|
| 87 | - global $wpdb; |
|
| 88 | - $n = empty($query->get('exact')) |
|
| 89 | - ? '%' |
|
| 90 | - : ''; |
|
| 91 | - $search = []; |
|
| 92 | - foreach ((array) $query->get('search_terms') as $term) { |
|
| 93 | - $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
| 94 | - } |
|
| 95 | - if (!is_user_logged_in()) { |
|
| 96 | - $search[] = "{$wpdb->posts}.post_password = ''"; |
|
| 97 | - } |
|
| 98 | - return ' AND '.implode(' AND ', $search); |
|
| 99 | - } |
|
| 75 | + /** |
|
| 76 | + * Search SQL filter for matching against post title only. |
|
| 77 | + * @see http://wordpress.stackexchange.com/a/11826/1685 |
|
| 78 | + * @param string $search |
|
| 79 | + * @return string |
|
| 80 | + * @filter posts_search |
|
| 81 | + */ |
|
| 82 | + public function filterSearchByTitle($search, WP_Query $query) |
|
| 83 | + { |
|
| 84 | + if (empty($search) || empty($query->get('search_terms'))) { |
|
| 85 | + return $search; |
|
| 86 | + } |
|
| 87 | + global $wpdb; |
|
| 88 | + $n = empty($query->get('exact')) |
|
| 89 | + ? '%' |
|
| 90 | + : ''; |
|
| 91 | + $search = []; |
|
| 92 | + foreach ((array) $query->get('search_terms') as $term) { |
|
| 93 | + $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
| 94 | + } |
|
| 95 | + if (!is_user_logged_in()) { |
|
| 96 | + $search[] = "{$wpdb->posts}.post_password = ''"; |
|
| 97 | + } |
|
| 98 | + return ' AND '.implode(' AND ', $search); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Get the current page number from the global query. |
|
| 103 | - * @param bool $isEnabled |
|
| 104 | - * @return int |
|
| 105 | - */ |
|
| 106 | - public function getPaged($isEnabled = true) |
|
| 107 | - { |
|
| 108 | - return $isEnabled |
|
| 109 | - ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR')))) |
|
| 110 | - : 1; |
|
| 111 | - } |
|
| 101 | + /** |
|
| 102 | + * Get the current page number from the global query. |
|
| 103 | + * @param bool $isEnabled |
|
| 104 | + * @return int |
|
| 105 | + */ |
|
| 106 | + public function getPaged($isEnabled = true) |
|
| 107 | + { |
|
| 108 | + return $isEnabled |
|
| 109 | + ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR')))) |
|
| 110 | + : 1; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * @param string $value |
|
| 115 | - * @return void|array |
|
| 116 | - */ |
|
| 117 | - protected function buildQueryAssignedTo($value) |
|
| 118 | - { |
|
| 119 | - if (!empty($value)) { |
|
| 120 | - $postIds = Arr::convertStringToArray($value, 'is_numeric'); |
|
| 121 | - return [ |
|
| 122 | - 'compare' => 'IN', |
|
| 123 | - 'key' => '_assigned_to', |
|
| 124 | - 'value' => glsr(Polylang::class)->getPostIds($postIds), |
|
| 125 | - ]; |
|
| 126 | - } |
|
| 127 | - } |
|
| 113 | + /** |
|
| 114 | + * @param string $value |
|
| 115 | + * @return void|array |
|
| 116 | + */ |
|
| 117 | + protected function buildQueryAssignedTo($value) |
|
| 118 | + { |
|
| 119 | + if (!empty($value)) { |
|
| 120 | + $postIds = Arr::convertStringToArray($value, 'is_numeric'); |
|
| 121 | + return [ |
|
| 122 | + 'compare' => 'IN', |
|
| 123 | + 'key' => '_assigned_to', |
|
| 124 | + 'value' => glsr(Polylang::class)->getPostIds($postIds), |
|
| 125 | + ]; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * @param array $value |
|
| 131 | - * @return void|array |
|
| 132 | - */ |
|
| 133 | - protected function buildQueryCategory($value) |
|
| 134 | - { |
|
| 135 | - if (!empty($value)) { |
|
| 136 | - return [ |
|
| 137 | - 'field' => 'term_id', |
|
| 138 | - 'taxonomy' => Application::TAXONOMY, |
|
| 139 | - 'terms' => $value, |
|
| 140 | - ]; |
|
| 141 | - } |
|
| 142 | - } |
|
| 129 | + /** |
|
| 130 | + * @param array $value |
|
| 131 | + * @return void|array |
|
| 132 | + */ |
|
| 133 | + protected function buildQueryCategory($value) |
|
| 134 | + { |
|
| 135 | + if (!empty($value)) { |
|
| 136 | + return [ |
|
| 137 | + 'field' => 'term_id', |
|
| 138 | + 'taxonomy' => Application::TAXONOMY, |
|
| 139 | + 'terms' => $value, |
|
| 140 | + ]; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * @param string $value |
|
| 146 | - * @return void|array |
|
| 147 | - */ |
|
| 148 | - protected function buildQueryRating($value) |
|
| 149 | - { |
|
| 150 | - if (is_numeric($value) |
|
| 151 | - && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
| 152 | - return [ |
|
| 153 | - 'compare' => '>=', |
|
| 154 | - 'key' => '_rating', |
|
| 155 | - 'value' => $value, |
|
| 156 | - ]; |
|
| 157 | - } |
|
| 158 | - } |
|
| 144 | + /** |
|
| 145 | + * @param string $value |
|
| 146 | + * @return void|array |
|
| 147 | + */ |
|
| 148 | + protected function buildQueryRating($value) |
|
| 149 | + { |
|
| 150 | + if (is_numeric($value) |
|
| 151 | + && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
| 152 | + return [ |
|
| 153 | + 'compare' => '>=', |
|
| 154 | + 'key' => '_rating', |
|
| 155 | + 'value' => $value, |
|
| 156 | + ]; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * @param string $value |
|
| 162 | - * @return void|array |
|
| 163 | - */ |
|
| 164 | - protected function buildQueryType($value) |
|
| 165 | - { |
|
| 166 | - if (!in_array($value, ['', 'all'])) { |
|
| 167 | - return [ |
|
| 168 | - 'key' => '_review_type', |
|
| 169 | - 'value' => $value, |
|
| 170 | - ]; |
|
| 171 | - } |
|
| 172 | - } |
|
| 160 | + /** |
|
| 161 | + * @param string $value |
|
| 162 | + * @return void|array |
|
| 163 | + */ |
|
| 164 | + protected function buildQueryType($value) |
|
| 165 | + { |
|
| 166 | + if (!in_array($value, ['', 'all'])) { |
|
| 167 | + return [ |
|
| 168 | + 'key' => '_review_type', |
|
| 169 | + 'value' => $value, |
|
| 170 | + ]; |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | 173 | } |
@@ -6,63 +6,63 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Cache |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @return array |
|
| 11 | - */ |
|
| 12 | - public function getCloudflareIps() |
|
| 13 | - { |
|
| 14 | - if (false === ($ipAddresses = get_transient(Application::ID.'_cloudflare_ips'))) { |
|
| 15 | - $ipAddresses = array_fill_keys(['v4', 'v6'], []); |
|
| 16 | - foreach (array_keys($ipAddresses) as $version) { |
|
| 17 | - $url = 'https://www.cloudflare.com/ips-'.$version; |
|
| 18 | - $response = wp_remote_get($url, ['sslverify' => false]); |
|
| 19 | - if (is_wp_error($response)) { |
|
| 20 | - glsr_log()->error($response->get_error_message()); |
|
| 21 | - continue; |
|
| 22 | - } |
|
| 23 | - if ('200' != ($statusCode = wp_remote_retrieve_response_code($response))) { |
|
| 24 | - glsr_log()->error('Unable to connect to '.$url.' ['.$statusCode.']'); |
|
| 25 | - continue; |
|
| 26 | - } |
|
| 27 | - $ipAddresses[$version] = array_filter( |
|
| 28 | - (array) preg_split('/\R/', wp_remote_retrieve_body($response)) |
|
| 29 | - ); |
|
| 30 | - } |
|
| 31 | - set_transient(Application::ID.'_cloudflare_ips', $ipAddresses, WEEK_IN_SECONDS); |
|
| 32 | - } |
|
| 33 | - return $ipAddresses; |
|
| 34 | - } |
|
| 9 | + /** |
|
| 10 | + * @return array |
|
| 11 | + */ |
|
| 12 | + public function getCloudflareIps() |
|
| 13 | + { |
|
| 14 | + if (false === ($ipAddresses = get_transient(Application::ID.'_cloudflare_ips'))) { |
|
| 15 | + $ipAddresses = array_fill_keys(['v4', 'v6'], []); |
|
| 16 | + foreach (array_keys($ipAddresses) as $version) { |
|
| 17 | + $url = 'https://www.cloudflare.com/ips-'.$version; |
|
| 18 | + $response = wp_remote_get($url, ['sslverify' => false]); |
|
| 19 | + if (is_wp_error($response)) { |
|
| 20 | + glsr_log()->error($response->get_error_message()); |
|
| 21 | + continue; |
|
| 22 | + } |
|
| 23 | + if ('200' != ($statusCode = wp_remote_retrieve_response_code($response))) { |
|
| 24 | + glsr_log()->error('Unable to connect to '.$url.' ['.$statusCode.']'); |
|
| 25 | + continue; |
|
| 26 | + } |
|
| 27 | + $ipAddresses[$version] = array_filter( |
|
| 28 | + (array) preg_split('/\R/', wp_remote_retrieve_body($response)) |
|
| 29 | + ); |
|
| 30 | + } |
|
| 31 | + set_transient(Application::ID.'_cloudflare_ips', $ipAddresses, WEEK_IN_SECONDS); |
|
| 32 | + } |
|
| 33 | + return $ipAddresses; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param string $metaKey |
|
| 38 | - * @return array |
|
| 39 | - */ |
|
| 40 | - public function getReviewCountsFor($metaKey) |
|
| 41 | - { |
|
| 42 | - $counts = wp_cache_get(Application::ID, $metaKey.'_count'); |
|
| 43 | - if (false === $counts) { |
|
| 44 | - $counts = []; |
|
| 45 | - $results = glsr(SqlQueries::class)->getReviewCountsFor($metaKey); |
|
| 46 | - foreach ($results as $result) { |
|
| 47 | - $counts[$result->name] = $result->num_posts; |
|
| 48 | - } |
|
| 49 | - wp_cache_set(Application::ID, $counts, $metaKey.'_count'); |
|
| 50 | - } |
|
| 51 | - return $counts; |
|
| 52 | - } |
|
| 36 | + /** |
|
| 37 | + * @param string $metaKey |
|
| 38 | + * @return array |
|
| 39 | + */ |
|
| 40 | + public function getReviewCountsFor($metaKey) |
|
| 41 | + { |
|
| 42 | + $counts = wp_cache_get(Application::ID, $metaKey.'_count'); |
|
| 43 | + if (false === $counts) { |
|
| 44 | + $counts = []; |
|
| 45 | + $results = glsr(SqlQueries::class)->getReviewCountsFor($metaKey); |
|
| 46 | + foreach ($results as $result) { |
|
| 47 | + $counts[$result->name] = $result->num_posts; |
|
| 48 | + } |
|
| 49 | + wp_cache_set(Application::ID, $counts, $metaKey.'_count'); |
|
| 50 | + } |
|
| 51 | + return $counts; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return string |
|
| 56 | - */ |
|
| 57 | - public function getRemotePostTest() |
|
| 58 | - { |
|
| 59 | - if (false === ($test = get_transient(Application::ID.'_remote_post_test'))) { |
|
| 60 | - $response = wp_remote_post('https://api.wordpress.org/stats/php/1.0/'); |
|
| 61 | - $test = !is_wp_error($response) && in_array($response['response']['code'], range(200, 299)) |
|
| 62 | - ? 'Works' |
|
| 63 | - : 'Does not work'; |
|
| 64 | - set_transient(Application::ID.'_remote_post_test', $test, WEEK_IN_SECONDS); |
|
| 65 | - } |
|
| 66 | - return $test; |
|
| 67 | - } |
|
| 54 | + /** |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 57 | + public function getRemotePostTest() |
|
| 58 | + { |
|
| 59 | + if (false === ($test = get_transient(Application::ID.'_remote_post_test'))) { |
|
| 60 | + $response = wp_remote_post('https://api.wordpress.org/stats/php/1.0/'); |
|
| 61 | + $test = !is_wp_error($response) && in_array($response['response']['code'], range(200, 299)) |
|
| 62 | + ? 'Works' |
|
| 63 | + : 'Does not work'; |
|
| 64 | + set_transient(Application::ID.'_remote_post_test', $test, WEEK_IN_SECONDS); |
|
| 65 | + } |
|
| 66 | + return $test; |
|
| 67 | + } |
|
| 68 | 68 | } |