PluginProbe ʕ •ᴥ•ʔ
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More / 2.8.0
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More v2.8.0
2.11.0 2.10.0 2.9.0 2.8.0 2.7.0 2.6.7 2.6.8 2.6.5 2.6.4 2.6.3 2.6.2 2.6.0 2.5.5 2.5.4 2.5.3 2.5.2 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1 1.1.1 1.1.2 1.2.0 2.0 2.1.0 2.1.1 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1
reviews-feed / class / Common / SBR_Settings.php
reviews-feed / class / Common Last commit date
Admin 1 month ago Builder 1 month ago Customizer 1 month ago Exceptions 1 month ago Helpers 1 month ago Integrations 1 month ago Migrations 1 month ago ReviewAlerts 1 month ago Services 1 month ago Settings 1 month ago Support 1 month ago Traits 1 month ago Utils 1 month ago AuthorizationStatusCheck.php 1 month ago BusinessDataCache.php 1 month ago Clear_Cache.php 1 month ago Container.php 1 month ago DisplayElements.php 1 month ago Email_Notification.php 1 month ago Error_Reporter.php 1 month ago Feed.php 1 month ago FeedCache.php 1 month ago FeedCacheUpdater.php 1 month ago FeedDisplay.php 1 month ago Feed_Locator.php 1 month ago Parser.php 1 month ago PostAggregator.php 1 month ago RemoteRequest.php 1 month ago SBR_Education.php 1 month ago SBR_Settings.php 1 month ago ServiceContainer.php 1 month ago SinglePostCache.php 1 month ago TemplateRenderer.php 1 month ago Tooltip_Wizard.php 1 month ago Util.php 1 month ago
SBR_Settings.php
214 lines
1 <?php
2
3 namespace SmashBalloon\Reviews\Common;
4
5 use Smashballoon\Customizer\V2\Feed_Saver;
6
7 class SBR_Settings {
8 /**
9 * @var array
10 */
11 protected $atts;
12
13 /**
14 * @var array
15 */
16 protected $db;
17
18 /**
19 * @var array
20 */
21 protected $settings;
22
23 /**
24 * @var array
25 */
26 protected $feed_type_and_terms;
27
28 /**
29 * @var array
30 */
31 protected $connected_accounts;
32
33 /**
34 * @var array
35 */
36 protected $connected_accounts_in_feed;
37
38 /**
39 * @var string
40 */
41 protected $transient_name;
42
43 /**
44 * SBR_Settings constructor.
45 *
46 * Overwritten in the Pro version.
47 *
48 * @param array $atts shortcode settings
49 * @param array $db settings from the wp_options table
50 */
51 public function __construct($atts, $db, $preview_settings = false)
52 {
53 $atts = is_array($atts) ? $atts : array();
54
55 if (! empty($atts['feed'])) {
56 $this->settings = self::get_settings_by_feed_id($atts['feed'], $preview_settings);
57
58 if (! empty($this->settings)) {
59 $this->settings['customizer'] = isset($atts['customizer']) && $atts['customizer'] == true ? true : false;
60 $this->settings['feed'] = intval($atts['feed']);
61
62 $this->settings['localization'] = Util::get_api_call_language($this->settings);
63 }
64 }
65
66 // convert string 'false' and 'true' to booleans
67 foreach ($atts as $key => $value) {
68 if ($value === 'false') {
69 $atts[ $key ] = false;
70 } elseif ($value === 'true') {
71 $atts[ $key ] = true;
72 }
73 }
74
75 $this->atts = $atts;
76 $this->db = $db;
77
78 $this->connected_accounts = isset($db['connected_accounts']) ? $db['connected_accounts'] : array();
79 }
80
81
82 /**
83 * Get Settings By Feed ID
84 *
85 * @since 1.0
86 */
87 public static function get_settings_by_feed_id($feed_id, $preview_settings = false, $single_review = false)
88 {
89 global $wpdb;
90
91 if (is_array($preview_settings)) {
92 return $preview_settings;
93 }
94
95 if ($single_review && intval($feed_id) < 1) {
96 return sbr_settings_defaults();
97 }
98
99 if (intval($feed_id) < 1) {
100 return false;
101 }
102 $container = Container::get_instance();
103 $feed_saver = $container->get(Feed_Saver::class);
104 $feed_saver->set_feed_id($feed_id);
105
106 return $feed_saver->get_feed_settings();
107 }
108
109 /**
110 * @return array
111 *
112 * @since 1.0
113 */
114 public function get_settings()
115 {
116 return $this->settings;
117 }
118
119 /**
120 * @return array
121 *
122 * @since 1.0
123 */
124 public function get_connected_accounts()
125 {
126 return $this->connected_accounts;
127 }
128
129 /**
130 * @return array|bool
131 *
132 * @since 1.0
133 */
134 public function get_connected_accounts_in_feed()
135 {
136 if (isset($this->connected_accounts_in_feed)) {
137 return $this->connected_accounts_in_feed;
138 } else {
139 return false;
140 }
141 }
142
143 /**
144 * @return bool|string
145 *
146 * @since 1.0
147 */
148 public function get_transient_name()
149 {
150 if (isset($this->transient_name)) {
151 return $this->transient_name;
152 } else {
153 return false;
154 }
155 }
156
157 /**
158 * @return float|int
159 *
160 * @since 1.0
161 */
162 public function get_cache_time_in_seconds()
163 {
164 if ($this->db['caching_type'] === 'background') {
165 return SBR_CRON_UPDATE_CACHE_TIME;
166 } else {
167 //If the caching time doesn't exist in the database then set it to be 1 hour
168 $cache_time = isset($this->settings['cache_time']) ? (int)$this->settings['cache_time'] : 1;
169 $cache_time_unit = isset($this->settings['cache_time_unit']) ? $this->settings['cache_time_unit'] : 'hours';
170
171 //Calculate the cache time in seconds
172 if ($cache_time_unit == 'minutes') {
173 $cache_time_unit = 60;
174 }
175 if ($cache_time_unit == 'hours') {
176 $cache_time_unit = 60 * 60;
177 }
178 if ($cache_time_unit == 'days') {
179 $cache_time_unit = 60 * 60 * 24;
180 }
181
182 $cache_time = max(900, $cache_time * $cache_time_unit);
183
184 return $cache_time;
185 }
186 }
187
188 public function update_settings($update_array = [])
189 {
190 if (!is_array($update_array)) {
191 return false;
192 }
193
194 $updated = array_merge($this->settings, array_map(function ($value) {
195 return $this->convert_value($value);
196 }, $update_array));
197
198 return update_option('sbr_settings', $updated);
199 }
200
201 private function convert_value($value)
202 {
203 switch ($value) {
204 case 'true':
205 return true;
206 case 'false':
207 return false;
208 default:
209 return $value;
210 }
211 }
212
213 }
214