@@ -11,239 +11,239 @@ |
||
| 11 | 11 | |
| 12 | 12 | class Settings |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var array |
|
| 16 | - */ |
|
| 17 | - public $settings; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @param string $id |
|
| 21 | - * @return string |
|
| 22 | - */ |
|
| 23 | - public function buildFields($id) |
|
| 24 | - { |
|
| 25 | - $this->settings = glsr(DefaultsManager::class)->settings(); |
|
| 26 | - $method = Helper::buildMethodName($id, 'getTemplateDataFor'); |
|
| 27 | - $data = !method_exists($this, $method) |
|
| 28 | - ? $this->getTemplateData($id) |
|
| 29 | - : $this->$method($id); |
|
| 30 | - return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @return string |
|
| 35 | - */ |
|
| 36 | - protected function getFieldDefault(array $field) |
|
| 37 | - { |
|
| 38 | - return Arr::get($field, 'default'); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 44 | - protected function getFieldNameForDependsOn($path) |
|
| 45 | - { |
|
| 46 | - $fieldName = Str::convertPathToName($path, OptionManager::databaseKey()); |
|
| 47 | - return $this->isMultiDependency($path) |
|
| 48 | - ? $fieldName.'[]' |
|
| 49 | - : $fieldName; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @return array |
|
| 54 | - */ |
|
| 55 | - protected function getSettingFields($path) |
|
| 56 | - { |
|
| 57 | - return array_filter($this->settings, function ($key) use ($path) { |
|
| 58 | - return Str::startsWith($path, $key); |
|
| 59 | - }, ARRAY_FILTER_USE_KEY); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return string |
|
| 64 | - */ |
|
| 65 | - protected function getSettingRows(array $fields) |
|
| 66 | - { |
|
| 67 | - $rows = ''; |
|
| 68 | - foreach ($fields as $name => $field) { |
|
| 69 | - $field = wp_parse_args($field, [ |
|
| 70 | - 'is_setting' => true, |
|
| 71 | - 'name' => $name, |
|
| 72 | - ]); |
|
| 73 | - $rows.= new Field($this->normalize($field)); |
|
| 74 | - } |
|
| 75 | - return $rows; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param string $id |
|
| 80 | - * @return array |
|
| 81 | - */ |
|
| 82 | - protected function getTemplateData($id) |
|
| 83 | - { |
|
| 84 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 85 | - return [ |
|
| 86 | - 'context' => [ |
|
| 87 | - 'rows' => $this->getSettingRows($fields), |
|
| 88 | - ], |
|
| 89 | - ]; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param string $id |
|
| 94 | - * @return array |
|
| 95 | - */ |
|
| 96 | - protected function getTemplateDataForAddons($id) |
|
| 97 | - { |
|
| 98 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 99 | - $settings = Arr::convertFromDotNotation($fields); |
|
| 100 | - $settingKeys = array_keys($settings['settings']['addons']); |
|
| 101 | - $results = []; |
|
| 102 | - foreach ($settingKeys as $key) { |
|
| 103 | - $addonFields = array_filter($fields, function ($path) use ($key) { |
|
| 104 | - return Str::startsWith('settings.addons.'.$key, $path); |
|
| 105 | - }, ARRAY_FILTER_USE_KEY); |
|
| 106 | - $results[$key] = $this->getSettingRows($addonFields); |
|
| 107 | - } |
|
| 108 | - ksort($results); |
|
| 109 | - return [ |
|
| 110 | - 'settings' => $results, |
|
| 111 | - ]; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @param string $id |
|
| 116 | - * @return array |
|
| 117 | - */ |
|
| 118 | - protected function getTemplateDataForLicenses($id) |
|
| 119 | - { |
|
| 120 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 121 | - ksort($fields); |
|
| 122 | - return [ |
|
| 123 | - 'context' => [ |
|
| 124 | - 'rows' => $this->getSettingRows($fields), |
|
| 125 | - ], |
|
| 126 | - ]; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @return array |
|
| 131 | - */ |
|
| 132 | - protected function getTemplateDataForTranslations() |
|
| 133 | - { |
|
| 134 | - $translations = glsr(Translation::class)->renderAll(); |
|
| 135 | - $class = empty($translations) |
|
| 136 | - ? 'glsr-hidden' |
|
| 137 | - : ''; |
|
| 138 | - return [ |
|
| 139 | - 'context' => [ |
|
| 140 | - 'class' => $class, |
|
| 141 | - 'database_key' => OptionManager::databaseKey(), |
|
| 142 | - 'translations' => $translations, |
|
| 143 | - ], |
|
| 144 | - ]; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param string $path |
|
| 149 | - * @param string|array $expectedValue |
|
| 150 | - * @return bool |
|
| 151 | - */ |
|
| 152 | - protected function isFieldHidden($path, $expectedValue) |
|
| 153 | - { |
|
| 154 | - $optionValue = glsr(OptionManager::class)->get( |
|
| 155 | - $path, |
|
| 156 | - Arr::get(glsr()->defaults, $path) |
|
| 157 | - ); |
|
| 158 | - if (is_array($expectedValue)) { |
|
| 159 | - return is_array($optionValue) |
|
| 160 | - ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
| 161 | - : !in_array($optionValue, $expectedValue); |
|
| 162 | - } |
|
| 163 | - return $optionValue != $expectedValue; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @return bool |
|
| 168 | - */ |
|
| 169 | - protected function isMultiDependency($path) |
|
| 170 | - { |
|
| 171 | - if (isset($this->settings[$path])) { |
|
| 172 | - $field = $this->settings[$path]; |
|
| 173 | - return ('checkbox' == $field['type'] && !empty($field['options'])) |
|
| 174 | - || !empty($field['multiple']); |
|
| 175 | - } |
|
| 176 | - return false; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @return array |
|
| 181 | - */ |
|
| 182 | - protected function normalize(array $field) |
|
| 183 | - { |
|
| 184 | - $field = $this->normalizeDependsOn($field); |
|
| 185 | - $field = $this->normalizeLabelAndLegend($field); |
|
| 186 | - $field = $this->normalizeValue($field); |
|
| 187 | - return $field; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * @return array |
|
| 192 | - */ |
|
| 193 | - protected function normalizeDependsOn(array $field) |
|
| 194 | - { |
|
| 195 | - if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
| 196 | - $isFieldHidden = false; |
|
| 197 | - $conditions = []; |
|
| 198 | - foreach ($field['depends_on'] as $path => $value) { |
|
| 199 | - $conditions[] = [ |
|
| 200 | - 'name' => $this->getFieldNameForDependsOn($path), |
|
| 201 | - 'value' => $value, |
|
| 202 | - ]; |
|
| 203 | - if ($this->isFieldHidden($path, $value)) { |
|
| 204 | - $isFieldHidden = true; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
| 208 | - $field['is_hidden'] = $isFieldHidden; |
|
| 209 | - } |
|
| 210 | - return $field; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * @return array |
|
| 215 | - */ |
|
| 216 | - protected function normalizeLabelAndLegend(array $field) |
|
| 217 | - { |
|
| 218 | - if (!empty($field['label'])) { |
|
| 219 | - $field['legend'] = $field['label']; |
|
| 220 | - unset($field['label']); |
|
| 221 | - } else { |
|
| 222 | - $field['is_valid'] = false; |
|
| 223 | - glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
| 224 | - } |
|
| 225 | - return $field; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * @return array |
|
| 230 | - */ |
|
| 231 | - protected function normalizeValue(array $field) |
|
| 232 | - { |
|
| 233 | - if (!isset($field['value'])) { |
|
| 234 | - $field['value'] = glsr(OptionManager::class)->get( |
|
| 235 | - $field['name'], |
|
| 236 | - $this->getFieldDefault($field) |
|
| 237 | - ); |
|
| 238 | - } |
|
| 239 | - return $field; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @return string |
|
| 244 | - */ |
|
| 245 | - protected function normalizeSettingPath($path) |
|
| 246 | - { |
|
| 247 | - return Str::prefix('settings.', rtrim($path, '.')); |
|
| 248 | - } |
|
| 14 | + /** |
|
| 15 | + * @var array |
|
| 16 | + */ |
|
| 17 | + public $settings; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @param string $id |
|
| 21 | + * @return string |
|
| 22 | + */ |
|
| 23 | + public function buildFields($id) |
|
| 24 | + { |
|
| 25 | + $this->settings = glsr(DefaultsManager::class)->settings(); |
|
| 26 | + $method = Helper::buildMethodName($id, 'getTemplateDataFor'); |
|
| 27 | + $data = !method_exists($this, $method) |
|
| 28 | + ? $this->getTemplateData($id) |
|
| 29 | + : $this->$method($id); |
|
| 30 | + return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @return string |
|
| 35 | + */ |
|
| 36 | + protected function getFieldDefault(array $field) |
|
| 37 | + { |
|
| 38 | + return Arr::get($field, 'default'); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | + protected function getFieldNameForDependsOn($path) |
|
| 45 | + { |
|
| 46 | + $fieldName = Str::convertPathToName($path, OptionManager::databaseKey()); |
|
| 47 | + return $this->isMultiDependency($path) |
|
| 48 | + ? $fieldName.'[]' |
|
| 49 | + : $fieldName; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @return array |
|
| 54 | + */ |
|
| 55 | + protected function getSettingFields($path) |
|
| 56 | + { |
|
| 57 | + return array_filter($this->settings, function ($key) use ($path) { |
|
| 58 | + return Str::startsWith($path, $key); |
|
| 59 | + }, ARRAY_FILTER_USE_KEY); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return string |
|
| 64 | + */ |
|
| 65 | + protected function getSettingRows(array $fields) |
|
| 66 | + { |
|
| 67 | + $rows = ''; |
|
| 68 | + foreach ($fields as $name => $field) { |
|
| 69 | + $field = wp_parse_args($field, [ |
|
| 70 | + 'is_setting' => true, |
|
| 71 | + 'name' => $name, |
|
| 72 | + ]); |
|
| 73 | + $rows.= new Field($this->normalize($field)); |
|
| 74 | + } |
|
| 75 | + return $rows; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param string $id |
|
| 80 | + * @return array |
|
| 81 | + */ |
|
| 82 | + protected function getTemplateData($id) |
|
| 83 | + { |
|
| 84 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 85 | + return [ |
|
| 86 | + 'context' => [ |
|
| 87 | + 'rows' => $this->getSettingRows($fields), |
|
| 88 | + ], |
|
| 89 | + ]; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param string $id |
|
| 94 | + * @return array |
|
| 95 | + */ |
|
| 96 | + protected function getTemplateDataForAddons($id) |
|
| 97 | + { |
|
| 98 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 99 | + $settings = Arr::convertFromDotNotation($fields); |
|
| 100 | + $settingKeys = array_keys($settings['settings']['addons']); |
|
| 101 | + $results = []; |
|
| 102 | + foreach ($settingKeys as $key) { |
|
| 103 | + $addonFields = array_filter($fields, function ($path) use ($key) { |
|
| 104 | + return Str::startsWith('settings.addons.'.$key, $path); |
|
| 105 | + }, ARRAY_FILTER_USE_KEY); |
|
| 106 | + $results[$key] = $this->getSettingRows($addonFields); |
|
| 107 | + } |
|
| 108 | + ksort($results); |
|
| 109 | + return [ |
|
| 110 | + 'settings' => $results, |
|
| 111 | + ]; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @param string $id |
|
| 116 | + * @return array |
|
| 117 | + */ |
|
| 118 | + protected function getTemplateDataForLicenses($id) |
|
| 119 | + { |
|
| 120 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 121 | + ksort($fields); |
|
| 122 | + return [ |
|
| 123 | + 'context' => [ |
|
| 124 | + 'rows' => $this->getSettingRows($fields), |
|
| 125 | + ], |
|
| 126 | + ]; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @return array |
|
| 131 | + */ |
|
| 132 | + protected function getTemplateDataForTranslations() |
|
| 133 | + { |
|
| 134 | + $translations = glsr(Translation::class)->renderAll(); |
|
| 135 | + $class = empty($translations) |
|
| 136 | + ? 'glsr-hidden' |
|
| 137 | + : ''; |
|
| 138 | + return [ |
|
| 139 | + 'context' => [ |
|
| 140 | + 'class' => $class, |
|
| 141 | + 'database_key' => OptionManager::databaseKey(), |
|
| 142 | + 'translations' => $translations, |
|
| 143 | + ], |
|
| 144 | + ]; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param string $path |
|
| 149 | + * @param string|array $expectedValue |
|
| 150 | + * @return bool |
|
| 151 | + */ |
|
| 152 | + protected function isFieldHidden($path, $expectedValue) |
|
| 153 | + { |
|
| 154 | + $optionValue = glsr(OptionManager::class)->get( |
|
| 155 | + $path, |
|
| 156 | + Arr::get(glsr()->defaults, $path) |
|
| 157 | + ); |
|
| 158 | + if (is_array($expectedValue)) { |
|
| 159 | + return is_array($optionValue) |
|
| 160 | + ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
| 161 | + : !in_array($optionValue, $expectedValue); |
|
| 162 | + } |
|
| 163 | + return $optionValue != $expectedValue; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @return bool |
|
| 168 | + */ |
|
| 169 | + protected function isMultiDependency($path) |
|
| 170 | + { |
|
| 171 | + if (isset($this->settings[$path])) { |
|
| 172 | + $field = $this->settings[$path]; |
|
| 173 | + return ('checkbox' == $field['type'] && !empty($field['options'])) |
|
| 174 | + || !empty($field['multiple']); |
|
| 175 | + } |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @return array |
|
| 181 | + */ |
|
| 182 | + protected function normalize(array $field) |
|
| 183 | + { |
|
| 184 | + $field = $this->normalizeDependsOn($field); |
|
| 185 | + $field = $this->normalizeLabelAndLegend($field); |
|
| 186 | + $field = $this->normalizeValue($field); |
|
| 187 | + return $field; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * @return array |
|
| 192 | + */ |
|
| 193 | + protected function normalizeDependsOn(array $field) |
|
| 194 | + { |
|
| 195 | + if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
| 196 | + $isFieldHidden = false; |
|
| 197 | + $conditions = []; |
|
| 198 | + foreach ($field['depends_on'] as $path => $value) { |
|
| 199 | + $conditions[] = [ |
|
| 200 | + 'name' => $this->getFieldNameForDependsOn($path), |
|
| 201 | + 'value' => $value, |
|
| 202 | + ]; |
|
| 203 | + if ($this->isFieldHidden($path, $value)) { |
|
| 204 | + $isFieldHidden = true; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
| 208 | + $field['is_hidden'] = $isFieldHidden; |
|
| 209 | + } |
|
| 210 | + return $field; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * @return array |
|
| 215 | + */ |
|
| 216 | + protected function normalizeLabelAndLegend(array $field) |
|
| 217 | + { |
|
| 218 | + if (!empty($field['label'])) { |
|
| 219 | + $field['legend'] = $field['label']; |
|
| 220 | + unset($field['label']); |
|
| 221 | + } else { |
|
| 222 | + $field['is_valid'] = false; |
|
| 223 | + glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
| 224 | + } |
|
| 225 | + return $field; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * @return array |
|
| 230 | + */ |
|
| 231 | + protected function normalizeValue(array $field) |
|
| 232 | + { |
|
| 233 | + if (!isset($field['value'])) { |
|
| 234 | + $field['value'] = glsr(OptionManager::class)->get( |
|
| 235 | + $field['name'], |
|
| 236 | + $this->getFieldDefault($field) |
|
| 237 | + ); |
|
| 238 | + } |
|
| 239 | + return $field; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @return string |
|
| 244 | + */ |
|
| 245 | + protected function normalizeSettingPath($path) |
|
| 246 | + { |
|
| 247 | + return Str::prefix('settings.', rtrim($path, '.')); |
|
| 248 | + } |
|
| 249 | 249 | } |
@@ -7,160 +7,160 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Migrate_3_0_0 |
| 9 | 9 | { |
| 10 | - const MAPPED_SETTINGS = [ |
|
| 11 | - 'settings.general.notification' => 'settings.general.notifications', // array |
|
| 12 | - 'settings.general.notification_email' => 'settings.general.notification_email', |
|
| 13 | - 'settings.general.notification_message' => 'settings.general.notification_message', |
|
| 14 | - 'settings.general.require.approval' => 'settings.general.require.approval', |
|
| 15 | - 'settings.general.require.login' => 'settings.general.require.login', |
|
| 16 | - 'settings.general.require.login_register' => 'settings.general.require.login_register', |
|
| 17 | - 'settings.general.webhook_url' => 'settings.general.notification_slack', |
|
| 18 | - 'settings.reviews-form.akismet' => 'settings.submissions.akismet', |
|
| 19 | - 'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action', |
|
| 20 | - 'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries', |
|
| 21 | - 'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration', |
|
| 22 | - 'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key', |
|
| 23 | - 'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position', |
|
| 24 | - 'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret', |
|
| 25 | - 'settings.reviews-form.required' => 'settings.submissions.required', // array |
|
| 26 | - 'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links', |
|
| 27 | - 'settings.reviews.avatars.enabled' => 'settings.reviews.avatars', |
|
| 28 | - 'settings.reviews.date.custom' => 'settings.reviews.date.custom', |
|
| 29 | - 'settings.reviews.date.format' => 'settings.reviews.date.format', |
|
| 30 | - 'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts', |
|
| 31 | - 'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length', |
|
| 32 | - 'settings.reviews.schema.address' => 'settings.schema.address', |
|
| 33 | - 'settings.reviews.schema.description.custom' => 'settings.schema.description.custom', |
|
| 34 | - 'settings.reviews.schema.description.default' => 'settings.schema.description.default', |
|
| 35 | - 'settings.reviews.schema.highprice' => 'settings.schema.highprice', |
|
| 36 | - 'settings.reviews.schema.image.custom' => 'settings.schema.image.custom', |
|
| 37 | - 'settings.reviews.schema.image.default' => 'settings.schema.image.default', |
|
| 38 | - 'settings.reviews.schema.lowprice' => 'settings.schema.lowprice', |
|
| 39 | - 'settings.reviews.schema.name.custom' => 'settings.schema.name.custom', |
|
| 40 | - 'settings.reviews.schema.name.default' => 'settings.schema.name.default', |
|
| 41 | - 'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency', |
|
| 42 | - 'settings.reviews.schema.pricerange' => 'settings.schema.pricerange', |
|
| 43 | - 'settings.reviews.schema.telephone' => 'settings.schema.telephone', |
|
| 44 | - 'settings.reviews.schema.type.custom' => 'settings.schema.type.custom', |
|
| 45 | - 'settings.reviews.schema.type.default' => 'settings.schema.type.default', |
|
| 46 | - 'settings.reviews.schema.url.custom' => 'settings.schema.url.custom', |
|
| 47 | - 'settings.reviews.schema.url.default' => 'settings.schema.url.default', |
|
| 48 | - 'version' => 'version_upgraded_from', |
|
| 49 | - ]; |
|
| 10 | + const MAPPED_SETTINGS = [ |
|
| 11 | + 'settings.general.notification' => 'settings.general.notifications', // array |
|
| 12 | + 'settings.general.notification_email' => 'settings.general.notification_email', |
|
| 13 | + 'settings.general.notification_message' => 'settings.general.notification_message', |
|
| 14 | + 'settings.general.require.approval' => 'settings.general.require.approval', |
|
| 15 | + 'settings.general.require.login' => 'settings.general.require.login', |
|
| 16 | + 'settings.general.require.login_register' => 'settings.general.require.login_register', |
|
| 17 | + 'settings.general.webhook_url' => 'settings.general.notification_slack', |
|
| 18 | + 'settings.reviews-form.akismet' => 'settings.submissions.akismet', |
|
| 19 | + 'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action', |
|
| 20 | + 'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries', |
|
| 21 | + 'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration', |
|
| 22 | + 'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key', |
|
| 23 | + 'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position', |
|
| 24 | + 'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret', |
|
| 25 | + 'settings.reviews-form.required' => 'settings.submissions.required', // array |
|
| 26 | + 'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links', |
|
| 27 | + 'settings.reviews.avatars.enabled' => 'settings.reviews.avatars', |
|
| 28 | + 'settings.reviews.date.custom' => 'settings.reviews.date.custom', |
|
| 29 | + 'settings.reviews.date.format' => 'settings.reviews.date.format', |
|
| 30 | + 'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts', |
|
| 31 | + 'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length', |
|
| 32 | + 'settings.reviews.schema.address' => 'settings.schema.address', |
|
| 33 | + 'settings.reviews.schema.description.custom' => 'settings.schema.description.custom', |
|
| 34 | + 'settings.reviews.schema.description.default' => 'settings.schema.description.default', |
|
| 35 | + 'settings.reviews.schema.highprice' => 'settings.schema.highprice', |
|
| 36 | + 'settings.reviews.schema.image.custom' => 'settings.schema.image.custom', |
|
| 37 | + 'settings.reviews.schema.image.default' => 'settings.schema.image.default', |
|
| 38 | + 'settings.reviews.schema.lowprice' => 'settings.schema.lowprice', |
|
| 39 | + 'settings.reviews.schema.name.custom' => 'settings.schema.name.custom', |
|
| 40 | + 'settings.reviews.schema.name.default' => 'settings.schema.name.default', |
|
| 41 | + 'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency', |
|
| 42 | + 'settings.reviews.schema.pricerange' => 'settings.schema.pricerange', |
|
| 43 | + 'settings.reviews.schema.telephone' => 'settings.schema.telephone', |
|
| 44 | + 'settings.reviews.schema.type.custom' => 'settings.schema.type.custom', |
|
| 45 | + 'settings.reviews.schema.type.default' => 'settings.schema.type.default', |
|
| 46 | + 'settings.reviews.schema.url.custom' => 'settings.schema.url.custom', |
|
| 47 | + 'settings.reviews.schema.url.default' => 'settings.schema.url.default', |
|
| 48 | + 'version' => 'version_upgraded_from', |
|
| 49 | + ]; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var array |
|
| 53 | - */ |
|
| 54 | - protected $newSettings; |
|
| 51 | + /** |
|
| 52 | + * @var array |
|
| 53 | + */ |
|
| 54 | + protected $newSettings; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var array |
|
| 58 | - */ |
|
| 59 | - protected $oldSettings; |
|
| 56 | + /** |
|
| 57 | + * @var array |
|
| 58 | + */ |
|
| 59 | + protected $oldSettings; |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @return void |
|
| 63 | - */ |
|
| 64 | - public function migrateSettings() |
|
| 65 | - { |
|
| 66 | - $this->newSettings = $this->getNewSettings(); |
|
| 67 | - $this->oldSettings = $this->getOldSettings(); |
|
| 68 | - if (empty($this->oldSettings) || empty($this->newSettings)) { |
|
| 69 | - return; |
|
| 70 | - } |
|
| 71 | - foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
| 72 | - if (empty($this->oldSettings[$old])) { |
|
| 73 | - continue; |
|
| 74 | - } |
|
| 75 | - $this->newSettings[$new] = $this->oldSettings[$old]; |
|
| 76 | - } |
|
| 77 | - $this->migrateNotificationSettings(); |
|
| 78 | - $this->migrateRecaptchaSettings(); |
|
| 79 | - $this->migrateRequiredSettings(); |
|
| 80 | - $oldSettings = Arr::convertFromDotNotation($this->oldSettings); |
|
| 81 | - $newSettings = Arr::convertFromDotNotation($this->newSettings); |
|
| 82 | - if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
| 83 | - $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
|
| 84 | - } |
|
| 85 | - update_option(OptionManager::databaseKey(3), $newSettings); |
|
| 86 | - } |
|
| 61 | + /** |
|
| 62 | + * @return void |
|
| 63 | + */ |
|
| 64 | + public function migrateSettings() |
|
| 65 | + { |
|
| 66 | + $this->newSettings = $this->getNewSettings(); |
|
| 67 | + $this->oldSettings = $this->getOldSettings(); |
|
| 68 | + if (empty($this->oldSettings) || empty($this->newSettings)) { |
|
| 69 | + return; |
|
| 70 | + } |
|
| 71 | + foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
| 72 | + if (empty($this->oldSettings[$old])) { |
|
| 73 | + continue; |
|
| 74 | + } |
|
| 75 | + $this->newSettings[$new] = $this->oldSettings[$old]; |
|
| 76 | + } |
|
| 77 | + $this->migrateNotificationSettings(); |
|
| 78 | + $this->migrateRecaptchaSettings(); |
|
| 79 | + $this->migrateRequiredSettings(); |
|
| 80 | + $oldSettings = Arr::convertFromDotNotation($this->oldSettings); |
|
| 81 | + $newSettings = Arr::convertFromDotNotation($this->newSettings); |
|
| 82 | + if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
| 83 | + $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
|
| 84 | + } |
|
| 85 | + update_option(OptionManager::databaseKey(3), $newSettings); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * @return void |
|
| 90 | - */ |
|
| 91 | - public function run() |
|
| 92 | - { |
|
| 93 | - $this->migrateSettings(); |
|
| 94 | - } |
|
| 88 | + /** |
|
| 89 | + * @return void |
|
| 90 | + */ |
|
| 91 | + public function run() |
|
| 92 | + { |
|
| 93 | + $this->migrateSettings(); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * @return array |
|
| 98 | - */ |
|
| 99 | - protected function getNewSettings() |
|
| 100 | - { |
|
| 101 | - return Arr::flatten(Arr::consolidate(OptionManager::databaseKey(3))); |
|
| 102 | - } |
|
| 96 | + /** |
|
| 97 | + * @return array |
|
| 98 | + */ |
|
| 99 | + protected function getNewSettings() |
|
| 100 | + { |
|
| 101 | + return Arr::flatten(Arr::consolidate(OptionManager::databaseKey(3))); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * @return array |
|
| 106 | - */ |
|
| 107 | - protected function getOldSettings() |
|
| 108 | - { |
|
| 109 | - $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
| 110 | - $settings = Arr::consolidate(get_option(OptionManager::databaseKey(2))); |
|
| 111 | - $settings = Arr::flatten($settings); |
|
| 112 | - return !empty($settings) |
|
| 113 | - ? wp_parse_args($settings, $defaults) |
|
| 114 | - : []; |
|
| 115 | - } |
|
| 104 | + /** |
|
| 105 | + * @return array |
|
| 106 | + */ |
|
| 107 | + protected function getOldSettings() |
|
| 108 | + { |
|
| 109 | + $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
| 110 | + $settings = Arr::consolidate(get_option(OptionManager::databaseKey(2))); |
|
| 111 | + $settings = Arr::flatten($settings); |
|
| 112 | + return !empty($settings) |
|
| 113 | + ? wp_parse_args($settings, $defaults) |
|
| 114 | + : []; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * @return void |
|
| 119 | - */ |
|
| 120 | - protected function migrateNotificationSettings() |
|
| 121 | - { |
|
| 122 | - $notifications = [ |
|
| 123 | - 'custom' => 'custom', |
|
| 124 | - 'default' => 'admin', |
|
| 125 | - 'webhook' => 'slack', |
|
| 126 | - ]; |
|
| 127 | - $this->newSettings['settings.general.notifications'] = []; |
|
| 128 | - foreach ($notifications as $old => $new) { |
|
| 129 | - if ($this->oldSettings['settings.general.notification'] != $old) { |
|
| 130 | - continue; |
|
| 131 | - } |
|
| 132 | - $this->newSettings['settings.general.notifications'][] = $new; |
|
| 133 | - } |
|
| 134 | - } |
|
| 117 | + /** |
|
| 118 | + * @return void |
|
| 119 | + */ |
|
| 120 | + protected function migrateNotificationSettings() |
|
| 121 | + { |
|
| 122 | + $notifications = [ |
|
| 123 | + 'custom' => 'custom', |
|
| 124 | + 'default' => 'admin', |
|
| 125 | + 'webhook' => 'slack', |
|
| 126 | + ]; |
|
| 127 | + $this->newSettings['settings.general.notifications'] = []; |
|
| 128 | + foreach ($notifications as $old => $new) { |
|
| 129 | + if ($this->oldSettings['settings.general.notification'] != $old) { |
|
| 130 | + continue; |
|
| 131 | + } |
|
| 132 | + $this->newSettings['settings.general.notifications'][] = $new; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * @return void |
|
| 138 | - */ |
|
| 139 | - protected function migrateRecaptchaSettings() |
|
| 140 | - { |
|
| 141 | - $recaptcha = [ |
|
| 142 | - 'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'], |
|
| 143 | - 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
|
| 144 | - 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
|
| 145 | - ]; |
|
| 146 | - if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
| 147 | - $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
|
| 148 | - } |
|
| 149 | - if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
| 150 | - $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
| 151 | - } |
|
| 152 | - $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
|
| 153 | - $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
|
| 154 | - $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition']; |
|
| 155 | - } |
|
| 136 | + /** |
|
| 137 | + * @return void |
|
| 138 | + */ |
|
| 139 | + protected function migrateRecaptchaSettings() |
|
| 140 | + { |
|
| 141 | + $recaptcha = [ |
|
| 142 | + 'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'], |
|
| 143 | + 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
|
| 144 | + 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
|
| 145 | + ]; |
|
| 146 | + if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
| 147 | + $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
|
| 148 | + } |
|
| 149 | + if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
| 150 | + $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
| 151 | + } |
|
| 152 | + $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
|
| 153 | + $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
|
| 154 | + $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition']; |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * @return void |
|
| 159 | - */ |
|
| 160 | - protected function migrateRequiredSettings() |
|
| 161 | - { |
|
| 162 | - $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
| 163 | - $this->newSettings['settings.submissions.required'][] = 'rating'; |
|
| 164 | - $this->newSettings['settings.submissions.required'][] = 'terms'; |
|
| 165 | - } |
|
| 157 | + /** |
|
| 158 | + * @return void |
|
| 159 | + */ |
|
| 160 | + protected function migrateRequiredSettings() |
|
| 161 | + { |
|
| 162 | + $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
| 163 | + $this->newSettings['settings.submissions.required'][] = 'rating'; |
|
| 164 | + $this->newSettings['settings.submissions.required'][] = 'terms'; |
|
| 165 | + } |
|
| 166 | 166 | } |
@@ -7,54 +7,54 @@ |
||
| 7 | 7 | |
| 8 | 8 | abstract class Widget extends WP_Widget |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @var array |
|
| 12 | - */ |
|
| 13 | - protected $widgetArgs; |
|
| 10 | + /** |
|
| 11 | + * @var array |
|
| 12 | + */ |
|
| 13 | + protected $widgetArgs; |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @param array $args |
|
| 17 | - * @param array $instance |
|
| 18 | - * @return void |
|
| 19 | - */ |
|
| 20 | - public function widget($args, $instance) |
|
| 21 | - { |
|
| 22 | - echo $this->shortcode()->build($instance, $args, 'widget'); |
|
| 23 | - } |
|
| 15 | + /** |
|
| 16 | + * @param array $args |
|
| 17 | + * @param array $instance |
|
| 18 | + * @return void |
|
| 19 | + */ |
|
| 20 | + public function widget($args, $instance) |
|
| 21 | + { |
|
| 22 | + echo $this->shortcode()->build($instance, $args, 'widget'); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @param string $tag |
|
| 27 | - * @return array |
|
| 28 | - */ |
|
| 29 | - protected function normalizeFieldAttributes($tag, array $args) |
|
| 30 | - { |
|
| 31 | - if (empty($args['value'])) { |
|
| 32 | - $args['value'] = $this->widgetArgs[$args['name']]; |
|
| 33 | - } |
|
| 34 | - if (empty($this->widgetArgs['options']) && in_array($tag, ['checkbox', 'radio'])) { |
|
| 35 | - $args['checked'] = in_array($args['value'], (array) $this->widgetArgs[$args['name']]); |
|
| 36 | - } |
|
| 37 | - $args['id'] = $this->get_field_id($args['name']); |
|
| 38 | - $args['name'] = $this->get_field_name($args['name']); |
|
| 39 | - $args['is_widget'] = true; |
|
| 40 | - return $args; |
|
| 41 | - } |
|
| 25 | + /** |
|
| 26 | + * @param string $tag |
|
| 27 | + * @return array |
|
| 28 | + */ |
|
| 29 | + protected function normalizeFieldAttributes($tag, array $args) |
|
| 30 | + { |
|
| 31 | + if (empty($args['value'])) { |
|
| 32 | + $args['value'] = $this->widgetArgs[$args['name']]; |
|
| 33 | + } |
|
| 34 | + if (empty($this->widgetArgs['options']) && in_array($tag, ['checkbox', 'radio'])) { |
|
| 35 | + $args['checked'] = in_array($args['value'], (array) $this->widgetArgs[$args['name']]); |
|
| 36 | + } |
|
| 37 | + $args['id'] = $this->get_field_id($args['name']); |
|
| 38 | + $args['name'] = $this->get_field_name($args['name']); |
|
| 39 | + $args['is_widget'] = true; |
|
| 40 | + return $args; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param string $tag |
|
| 45 | - * @return void |
|
| 46 | - */ |
|
| 47 | - protected function renderField($tag, array $args = []) |
|
| 48 | - { |
|
| 49 | - $args = $this->normalizeFieldAttributes($tag, $args); |
|
| 50 | - $field = glsr(Builder::class)->$tag($args['name'], $args); |
|
| 51 | - echo glsr(Builder::class)->div($field, [ |
|
| 52 | - 'class' => 'glsr-field', |
|
| 53 | - ]); |
|
| 54 | - } |
|
| 43 | + /** |
|
| 44 | + * @param string $tag |
|
| 45 | + * @return void |
|
| 46 | + */ |
|
| 47 | + protected function renderField($tag, array $args = []) |
|
| 48 | + { |
|
| 49 | + $args = $this->normalizeFieldAttributes($tag, $args); |
|
| 50 | + $field = glsr(Builder::class)->$tag($args['name'], $args); |
|
| 51 | + echo glsr(Builder::class)->div($field, [ |
|
| 52 | + 'class' => 'glsr-field', |
|
| 53 | + ]); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @return \GeminiLabs\SiteReviews\Shortcodes\Shortcode |
|
| 58 | - */ |
|
| 59 | - abstract protected function shortcode(); |
|
| 56 | + /** |
|
| 57 | + * @return \GeminiLabs\SiteReviews\Shortcodes\Shortcode |
|
| 58 | + */ |
|
| 59 | + abstract protected function shortcode(); |
|
| 60 | 60 | } |
@@ -4,15 +4,15 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface ShortcodeContract |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @params string|array $atts |
|
| 9 | - * @return string |
|
| 10 | - */ |
|
| 11 | - public function buildBlock($atts = []); |
|
| 7 | + /** |
|
| 8 | + * @params string|array $atts |
|
| 9 | + * @return string |
|
| 10 | + */ |
|
| 11 | + public function buildBlock($atts = []); |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param string|array $atts |
|
| 15 | - * @return string |
|
| 16 | - */ |
|
| 17 | - public function buildShortcode($atts = []); |
|
| 13 | + /** |
|
| 14 | + * @param string|array $atts |
|
| 15 | + * @return string |
|
| 16 | + */ |
|
| 17 | + public function buildShortcode($atts = []); |
|
| 18 | 18 | } |
@@ -9,75 +9,75 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Wpml implements Contract |
| 11 | 11 | { |
| 12 | - public $pluginName = 'WPML'; |
|
| 13 | - public $supportedVersion = '3.3.5'; |
|
| 12 | + public $pluginName = 'WPML'; |
|
| 13 | + public $supportedVersion = '3.3.5'; |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @inheritDoc |
|
| 17 | - */ |
|
| 18 | - public function getPostId($postId) |
|
| 19 | - { |
|
| 20 | - $postId = trim($postId); |
|
| 21 | - if (!is_numeric($postId)) { |
|
| 22 | - return 0; |
|
| 23 | - } |
|
| 24 | - if ($this->isEnabled()) { |
|
| 25 | - $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
| 26 | - } |
|
| 27 | - return intval($postId); |
|
| 28 | - } |
|
| 15 | + /** |
|
| 16 | + * @inheritDoc |
|
| 17 | + */ |
|
| 18 | + public function getPostId($postId) |
|
| 19 | + { |
|
| 20 | + $postId = trim($postId); |
|
| 21 | + if (!is_numeric($postId)) { |
|
| 22 | + return 0; |
|
| 23 | + } |
|
| 24 | + if ($this->isEnabled()) { |
|
| 25 | + $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
| 26 | + } |
|
| 27 | + return intval($postId); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @inheritDoc |
|
| 32 | - */ |
|
| 33 | - public function getPostIds(array $postIds) |
|
| 34 | - { |
|
| 35 | - if (!$this->isEnabled()) { |
|
| 36 | - return $postIds; |
|
| 37 | - } |
|
| 38 | - $newPostIds = []; |
|
| 39 | - foreach (Arr::unique($postIds) as $postId) { |
|
| 40 | - $postType = get_post_type($postId); |
|
| 41 | - if (!$postType) { |
|
| 42 | - continue; |
|
| 43 | - } |
|
| 44 | - $elementType = 'post_'.$postType; |
|
| 45 | - $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
| 46 | - $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
| 47 | - if (!is_array($translations)) { |
|
| 48 | - $translations = []; |
|
| 49 | - } |
|
| 50 | - $newPostIds = array_merge( |
|
| 51 | - $newPostIds, |
|
| 52 | - array_column($translations, 'element_id') |
|
| 53 | - ); |
|
| 54 | - } |
|
| 55 | - return Arr::unique($newPostIds); |
|
| 56 | - } |
|
| 30 | + /** |
|
| 31 | + * @inheritDoc |
|
| 32 | + */ |
|
| 33 | + public function getPostIds(array $postIds) |
|
| 34 | + { |
|
| 35 | + if (!$this->isEnabled()) { |
|
| 36 | + return $postIds; |
|
| 37 | + } |
|
| 38 | + $newPostIds = []; |
|
| 39 | + foreach (Arr::unique($postIds) as $postId) { |
|
| 40 | + $postType = get_post_type($postId); |
|
| 41 | + if (!$postType) { |
|
| 42 | + continue; |
|
| 43 | + } |
|
| 44 | + $elementType = 'post_'.$postType; |
|
| 45 | + $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
| 46 | + $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
| 47 | + if (!is_array($translations)) { |
|
| 48 | + $translations = []; |
|
| 49 | + } |
|
| 50 | + $newPostIds = array_merge( |
|
| 51 | + $newPostIds, |
|
| 52 | + array_column($translations, 'element_id') |
|
| 53 | + ); |
|
| 54 | + } |
|
| 55 | + return Arr::unique($newPostIds); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @inheritDoc |
|
| 60 | - */ |
|
| 61 | - public function isActive() |
|
| 62 | - { |
|
| 63 | - return defined('ICL_SITEPRESS_VERSION'); |
|
| 64 | - } |
|
| 58 | + /** |
|
| 59 | + * @inheritDoc |
|
| 60 | + */ |
|
| 61 | + public function isActive() |
|
| 62 | + { |
|
| 63 | + return defined('ICL_SITEPRESS_VERSION'); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @inheritDoc |
|
| 68 | - */ |
|
| 69 | - public function isEnabled() |
|
| 70 | - { |
|
| 71 | - return $this->isActive() |
|
| 72 | - && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
| 73 | - } |
|
| 66 | + /** |
|
| 67 | + * @inheritDoc |
|
| 68 | + */ |
|
| 69 | + public function isEnabled() |
|
| 70 | + { |
|
| 71 | + return $this->isActive() |
|
| 72 | + && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @inheritDoc |
|
| 77 | - */ |
|
| 78 | - public function isSupported() |
|
| 79 | - { |
|
| 80 | - return $this->isActive() |
|
| 81 | - && Helper::isGreaterThanOrEqual(ICL_SITEPRESS_VERSION, $this->supportedVersion); |
|
| 82 | - } |
|
| 75 | + /** |
|
| 76 | + * @inheritDoc |
|
| 77 | + */ |
|
| 78 | + public function isSupported() |
|
| 79 | + { |
|
| 80 | + return $this->isActive() |
|
| 81 | + && Helper::isGreaterThanOrEqual(ICL_SITEPRESS_VERSION, $this->supportedVersion); |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -9,71 +9,71 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Polylang implements Contract |
| 11 | 11 | { |
| 12 | - public $pluginName = 'Polylang'; |
|
| 13 | - public $supportedVersion = '2.3'; |
|
| 12 | + public $pluginName = 'Polylang'; |
|
| 13 | + public $supportedVersion = '2.3'; |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @inheritDoc |
|
| 17 | - */ |
|
| 18 | - public function getPostId($postId) |
|
| 19 | - { |
|
| 20 | - $postId = trim($postId); |
|
| 21 | - if (!is_numeric($postId)) { |
|
| 22 | - return 0; |
|
| 23 | - } |
|
| 24 | - if ($this->isEnabled()) { |
|
| 25 | - $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
| 26 | - } |
|
| 27 | - if (!empty($polylangPostId)) { |
|
| 28 | - $postId = $polylangPostId; |
|
| 29 | - } |
|
| 30 | - return intval($postId); |
|
| 31 | - } |
|
| 15 | + /** |
|
| 16 | + * @inheritDoc |
|
| 17 | + */ |
|
| 18 | + public function getPostId($postId) |
|
| 19 | + { |
|
| 20 | + $postId = trim($postId); |
|
| 21 | + if (!is_numeric($postId)) { |
|
| 22 | + return 0; |
|
| 23 | + } |
|
| 24 | + if ($this->isEnabled()) { |
|
| 25 | + $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
| 26 | + } |
|
| 27 | + if (!empty($polylangPostId)) { |
|
| 28 | + $postId = $polylangPostId; |
|
| 29 | + } |
|
| 30 | + return intval($postId); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @inheritDoc |
|
| 35 | - */ |
|
| 36 | - public function getPostIds(array $postIds) |
|
| 37 | - { |
|
| 38 | - if (!$this->isEnabled()) { |
|
| 39 | - return $postIds; |
|
| 40 | - } |
|
| 41 | - $newPostIds = []; |
|
| 42 | - foreach (Arr::unique($postIds) as $postId) { |
|
| 43 | - $newPostIds = array_merge( |
|
| 44 | - $newPostIds, |
|
| 45 | - array_values(pll_get_post_translations($postId)) |
|
| 46 | - ); |
|
| 47 | - } |
|
| 48 | - return Arr::unique($newPostIds); |
|
| 49 | - } |
|
| 33 | + /** |
|
| 34 | + * @inheritDoc |
|
| 35 | + */ |
|
| 36 | + public function getPostIds(array $postIds) |
|
| 37 | + { |
|
| 38 | + if (!$this->isEnabled()) { |
|
| 39 | + return $postIds; |
|
| 40 | + } |
|
| 41 | + $newPostIds = []; |
|
| 42 | + foreach (Arr::unique($postIds) as $postId) { |
|
| 43 | + $newPostIds = array_merge( |
|
| 44 | + $newPostIds, |
|
| 45 | + array_values(pll_get_post_translations($postId)) |
|
| 46 | + ); |
|
| 47 | + } |
|
| 48 | + return Arr::unique($newPostIds); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @inheritDoc |
|
| 53 | - */ |
|
| 54 | - public function isActive() |
|
| 55 | - { |
|
| 56 | - return function_exists('PLL') |
|
| 57 | - && function_exists('pll_get_post') |
|
| 58 | - && function_exists('pll_get_post_language') |
|
| 59 | - && function_exists('pll_get_post_translations'); |
|
| 60 | - } |
|
| 51 | + /** |
|
| 52 | + * @inheritDoc |
|
| 53 | + */ |
|
| 54 | + public function isActive() |
|
| 55 | + { |
|
| 56 | + return function_exists('PLL') |
|
| 57 | + && function_exists('pll_get_post') |
|
| 58 | + && function_exists('pll_get_post_language') |
|
| 59 | + && function_exists('pll_get_post_translations'); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @inheritDoc |
|
| 64 | - */ |
|
| 65 | - public function isEnabled() |
|
| 66 | - { |
|
| 67 | - return $this->isActive() |
|
| 68 | - && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
| 69 | - } |
|
| 62 | + /** |
|
| 63 | + * @inheritDoc |
|
| 64 | + */ |
|
| 65 | + public function isEnabled() |
|
| 66 | + { |
|
| 67 | + return $this->isActive() |
|
| 68 | + && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @inheritDoc |
|
| 73 | - */ |
|
| 74 | - public function isSupported() |
|
| 75 | - { |
|
| 76 | - return defined('POLYLANG_VERSION') |
|
| 77 | - && Helper::isGreaterThanOrEqual(POLYLANG_VERSION, $this->supportedVersion); |
|
| 78 | - } |
|
| 71 | + /** |
|
| 72 | + * @inheritDoc |
|
| 73 | + */ |
|
| 74 | + public function isSupported() |
|
| 75 | + { |
|
| 76 | + return defined('POLYLANG_VERSION') |
|
| 77 | + && Helper::isGreaterThanOrEqual(POLYLANG_VERSION, $this->supportedVersion); |
|
| 78 | + } |
|
| 79 | 79 | } |
@@ -8,54 +8,54 @@ |
||
| 8 | 8 | |
| 9 | 9 | class StarRating implements PartialContract |
| 10 | 10 | { |
| 11 | - protected $prefix; |
|
| 12 | - protected $rating; |
|
| 11 | + protected $prefix; |
|
| 12 | + protected $rating; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @inheritDoc |
|
| 16 | - */ |
|
| 17 | - public function build(array $args = []) |
|
| 18 | - { |
|
| 19 | - $this->setProperties($args); |
|
| 20 | - $fullStars = intval(floor($this->rating)); |
|
| 21 | - $halfStars = intval(ceil($this->rating - $fullStars)); |
|
| 22 | - $emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars); |
|
| 23 | - return glsr(Template::class)->build('templates/rating/stars', [ |
|
| 24 | - 'context' => [ |
|
| 25 | - 'empty_stars' => $this->getTemplate('empty-star', $emptyStars), |
|
| 26 | - 'full_stars' => $this->getTemplate('full-star', $fullStars), |
|
| 27 | - 'half_stars' => $this->getTemplate('half-star', $halfStars), |
|
| 28 | - 'prefix' => $this->prefix, |
|
| 29 | - 'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)), |
|
| 30 | - ], |
|
| 31 | - ]); |
|
| 32 | - } |
|
| 14 | + /** |
|
| 15 | + * @inheritDoc |
|
| 16 | + */ |
|
| 17 | + public function build(array $args = []) |
|
| 18 | + { |
|
| 19 | + $this->setProperties($args); |
|
| 20 | + $fullStars = intval(floor($this->rating)); |
|
| 21 | + $halfStars = intval(ceil($this->rating - $fullStars)); |
|
| 22 | + $emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars); |
|
| 23 | + return glsr(Template::class)->build('templates/rating/stars', [ |
|
| 24 | + 'context' => [ |
|
| 25 | + 'empty_stars' => $this->getTemplate('empty-star', $emptyStars), |
|
| 26 | + 'full_stars' => $this->getTemplate('full-star', $fullStars), |
|
| 27 | + 'half_stars' => $this->getTemplate('half-star', $halfStars), |
|
| 28 | + 'prefix' => $this->prefix, |
|
| 29 | + 'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)), |
|
| 30 | + ], |
|
| 31 | + ]); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param string $templateName |
|
| 36 | - * @param int $timesRepeated |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - protected function getTemplate($templateName, $timesRepeated) |
|
| 40 | - { |
|
| 41 | - $template = glsr(Template::class)->build('templates/rating/'.$templateName, [ |
|
| 42 | - 'context' => [ |
|
| 43 | - 'prefix' => $this->prefix, |
|
| 44 | - ], |
|
| 45 | - ]); |
|
| 46 | - return str_repeat($template, $timesRepeated); |
|
| 47 | - } |
|
| 34 | + /** |
|
| 35 | + * @param string $templateName |
|
| 36 | + * @param int $timesRepeated |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + protected function getTemplate($templateName, $timesRepeated) |
|
| 40 | + { |
|
| 41 | + $template = glsr(Template::class)->build('templates/rating/'.$templateName, [ |
|
| 42 | + 'context' => [ |
|
| 43 | + 'prefix' => $this->prefix, |
|
| 44 | + ], |
|
| 45 | + ]); |
|
| 46 | + return str_repeat($template, $timesRepeated); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @return array |
|
| 51 | - */ |
|
| 52 | - protected function setProperties(array $args) |
|
| 53 | - { |
|
| 54 | - $args = wp_parse_args($args, [ |
|
| 55 | - 'prefix' => glsr()->isAdmin() ? '' : 'glsr-', |
|
| 56 | - 'rating' => 0, |
|
| 57 | - ]); |
|
| 58 | - $this->prefix = $args['prefix']; |
|
| 59 | - $this->rating = (float) str_replace(',', '.', $args['rating']); |
|
| 60 | - } |
|
| 49 | + /** |
|
| 50 | + * @return array |
|
| 51 | + */ |
|
| 52 | + protected function setProperties(array $args) |
|
| 53 | + { |
|
| 54 | + $args = wp_parse_args($args, [ |
|
| 55 | + 'prefix' => glsr()->isAdmin() ? '' : 'glsr-', |
|
| 56 | + 'rating' => 0, |
|
| 57 | + ]); |
|
| 58 | + $this->prefix = $args['prefix']; |
|
| 59 | + $this->rating = (float) str_replace(',', '.', $args['rating']); |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -4,14 +4,14 @@ |
||
| 4 | 4 | |
| 5 | 5 | class SiteReviewsSummaryShortcode extends Shortcode |
| 6 | 6 | { |
| 7 | - protected function hideOptions() |
|
| 8 | - { |
|
| 9 | - return [ |
|
| 10 | - 'rating' => _x('Hide the rating', 'admin-text', 'site-reviews'), |
|
| 11 | - 'stars' => _x('Hide the stars', 'admin-text', 'site-reviews'), |
|
| 12 | - 'summary' => _x('Hide the summary', 'admin-text', 'site-reviews'), |
|
| 13 | - 'bars' => _x('Hide the percentage bars', 'admin-text', 'site-reviews'), |
|
| 14 | - 'if_empty' => _x('Hide if no reviews are found', 'admin-text', 'site-reviews'), |
|
| 15 | - ]; |
|
| 16 | - } |
|
| 7 | + protected function hideOptions() |
|
| 8 | + { |
|
| 9 | + return [ |
|
| 10 | + 'rating' => _x('Hide the rating', 'admin-text', 'site-reviews'), |
|
| 11 | + 'stars' => _x('Hide the stars', 'admin-text', 'site-reviews'), |
|
| 12 | + 'summary' => _x('Hide the summary', 'admin-text', 'site-reviews'), |
|
| 13 | + 'bars' => _x('Hide the percentage bars', 'admin-text', 'site-reviews'), |
|
| 14 | + 'if_empty' => _x('Hide if no reviews are found', 'admin-text', 'site-reviews'), |
|
| 15 | + ]; |
|
| 16 | + } |
|
| 17 | 17 | } |
@@ -4,15 +4,15 @@ |
||
| 4 | 4 | |
| 5 | 5 | class SiteReviewsFormShortcode extends Shortcode |
| 6 | 6 | { |
| 7 | - protected function hideOptions() |
|
| 8 | - { |
|
| 9 | - return [ |
|
| 10 | - 'rating' => _x('Hide the rating field', 'admin-text', 'site-reviews'), |
|
| 11 | - 'title' => _x('Hide the title field', 'admin-text', 'site-reviews'), |
|
| 12 | - 'content' => _x('Hide the review field', 'admin-text', 'site-reviews'), |
|
| 13 | - 'name' => _x('Hide the name field', 'admin-text', 'site-reviews'), |
|
| 14 | - 'email' => _x('Hide the email field', 'admin-text', 'site-reviews'), |
|
| 15 | - 'terms' => _x('Hide the terms field', 'admin-text', 'site-reviews'), |
|
| 16 | - ]; |
|
| 17 | - } |
|
| 7 | + protected function hideOptions() |
|
| 8 | + { |
|
| 9 | + return [ |
|
| 10 | + 'rating' => _x('Hide the rating field', 'admin-text', 'site-reviews'), |
|
| 11 | + 'title' => _x('Hide the title field', 'admin-text', 'site-reviews'), |
|
| 12 | + 'content' => _x('Hide the review field', 'admin-text', 'site-reviews'), |
|
| 13 | + 'name' => _x('Hide the name field', 'admin-text', 'site-reviews'), |
|
| 14 | + 'email' => _x('Hide the email field', 'admin-text', 'site-reviews'), |
|
| 15 | + 'terms' => _x('Hide the terms field', 'admin-text', 'site-reviews'), |
|
| 16 | + ]; |
|
| 17 | + } |
|
| 18 | 18 | } |