* @license GNU General Public License, version 2 * @link http://addthis.com AddThis website */ class AddThisGlobalOptionsCustomHtmlTool extends AddThisTool { protected $featureClassName = 'AddThisGlobalOptionsFeature'; public $prettyName = 'AddThis Custom HTML'; protected $defaultConfigs = array( 'enabled' => false, 'html' => '', 'id' => 'html', ); /** * 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': $output[$field] = (boolean)$value; case 'elements': if (is_array($value) && !empty($value)) { $output[$field] = array(); foreach ($value as $service) { $output[$field][] = sanitize_text_field($service); } } break; case 'toolName': case 'widgetId': case 'id': $output[$field] = sanitize_text_field($value); break; case 'html': $output[$field] = $value; break; } } } if ($addDefaultConfigs) { $output = $this->addDefaultConfigs($output); } return $output; } /** * This must be public as it's used in the tool's widget * * Returns HTML for adding the script onto a page * * @param array $args settings for this widget (we only use * widget_id) * @param array $instance settings for this particular tool, if not * being used from the tool settings (a widget instance) * * @return string this should be valid html */ public function getInlineCode($args = array(), $instance = array()) { if (is_feed()) { return ''; } $configs = $this->getFeatureConfigs(); $html = ''; return $html; } /** * This must be public as it's used in a callback for add_shortcode * * Returns HTML to use to replace a short tag for this tool. Includes * tags to identify its from a short code. * * @return string this should be valid html */ public function getInlineCodeForShortCode() { $html = ''; $html .= ''; $html .= $this->getInlineCode(); $html .= ''; return $html; } } }