* @license GNU General Public License, version 2 * @link http://addthis.com AddThis website */ class AddThisSharingButtonsSidebarCountersTool extends AddThisSharingButtonsToolParent { public $prettyName = 'Sharing Sidebar Counters'; public $edition = 'pro'; public $clientApiSupport = false; public $inline = false; public $settingsSubVariableName = 'smlshp'; protected $defaultConfigs = array( 'enabled' => false, 'position' => 'left', 'services' => '', 'title' => '', 'theme' => 'transparent', 'counts' => true, 'numPreferredServices' => 5, 'offset' => array( 'location' => 'top', 'amount' => 0, ), 'responsive' => array( 'maxWidth' => 979, ), ); /** * This must be public as it's used in the feature object with this tool * * This takes form input for a tool sub settings variable, manipulates * it, and returns the variables that should be saved to the database. * * @param array $input An associative array of values * input for this tools' settings * @param boolean $addDefaultConfigs Whether to populate in default * values for missing fields * * @return array A cleaned up associative array of settings specific to * this feature. */ public function sanitizeSettings($input, $addDefaultConfigs = true) { $output = array(); if (is_array($input)) { foreach ($input as $field => $value) { switch ($field) { case 'enabled': case 'thankyou': case '__hideOnHomepage': $output[$field] = (boolean)$value; break; case 'position': if ($value === 'left') { $output[$field] = $value; } break; case 'services': case 'title': $output[$field] = sanitize_text_field($value); break; case 'theme': if ($value === 'light' || $value === 'gray' || $value === 'dark') { $output[$field] = $value; } break; case 'numPreferredServices': $output[$field] = (int)$value; break; case 'responsive': if (empty($value['maxWidth'])) { $output[$field]['maxWidth'] = (int)$value['maxWidth']; } break; case 'offset': if (isset($value['location'])) { $output[$field]['location'] = sanitize_text_field($value['location']); } if (!empty($value['amount'])) { $output[$field]['amount'] = (int)$value['amount']; } break; case 'postShareTitle': case 'postShareFollowMsg': case 'postShareRecommendedMsg': $output[$field] = sanitize_text_field($value); break; case '__hideOnUrls': if (is_array($value)) { foreach ($value as $urlPattern) { $output[$field][] = sanitize_text_field($urlPattern); } } break; } } } if ($addDefaultConfigs) { $output = $this->addDefaultConfigs($output); } return $output; } } }