* @license GNU General Public License, version 2 * @link http://addthis.com AddThis website */ class AddThisSharingButtonsCustomTool extends AddThisSharingButtonsToolParent { public $boostApiClass = 'addthis_custom_sharing'; public $prettyName = 'Custom Sharing Buttons'; public $edition = 'pro'; public $clientApiSupport = false; public $inline = true; public $settingsSubVariableName = 'ctbx'; public $widgetClassName = 'AddThisSharingButtonsCustomWidget'; public $widgetBaseId = 'addthis_custom_sharing_widget'; public $widgetName = 'Sharing Buttons - Custom'; public $widgetDescription = ' These custom sharing buttons from AddThis allow you to match the look and feel of your website. '; public $defaultWidgetTitle = 'Share'; public $shortCode = 'addthis_custom_sharing_buttons'; protected $defaultConfigs = array( 'enabled' => false, 'services' => '', //'background' - the default gray is used if not set, otherwise, a hex color with the # 'theme' => 'custom', 'shape' => 'square', // 'rounded' or 'round' 'counts' => false, 'numPreferredServices' => 5, 'size' => 'large', ); /** * 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 'counts': $output[$field] = (boolean)$value; break; case 'services': $output[$field] = sanitize_text_field($value); break; case 'shape': if ($value === 'rounded' || $value === 'round') { $output[$field] = $value; } break; case 'numPreferredServices': $output[$field] = (int)$value; break; case 'size': if ($value === 'small' || $value === 'medium') { $output[$field] = $value; } break; case 'background': $matches = array(); preg_match('/(#[a-f0-9]{3}([a-f0-9]{3})?)/i', $value, $matches); if (isset($matches[1])) { $output[$field] = $matches[1]; } break; } } } if ($addDefaultConfigs) { $output = $this->addDefaultConfigs($output); } return $output; } } }