* @license GNU General Public License, version 2 * @link http://addthis.com AddThis website */ class AddThisFollowButtonsHeaderTool extends AddThisFollowButtonsToolParent { public $prettyName = 'Follow Header'; public $edition = 'basic'; public $clientApiSupport = true; public $inline = false; public $settingsSubVariableName = 'smlfw'; protected $defaultConfigs = array( 'enabled' => false, 'theme' => 'transparent', 'responsive' => 979, 'offset' => array( 'location' => 'top', 'amount' => 0, ), 'thankyou' => true, 'title' => '', ); /** * Creates tool specific settings for the JavaScript variable * addthis_layers, used to bootstrap layers * * @return array an associative array */ public function getAddThisLayers() { $configs = $this->getToolConfigs(); $layers = array( 'follow' => array( 'services' => array(), 'title' => $configs['title'], 'theme' => $configs['theme'], 'responsive' => array( 'maxWidth' => (int)$configs['responsive'].'px', ), ), ); foreach ($configs['services'] as $service => $id) { if (empty($id)) { continue; } $serviceInfo = array( 'service' => $service, 'id' => $id, ); switch ($service) { case 'linkedin-company': $serviceInfo['usertype'] = 'company'; $serviceInfo['service'] = 'linkedin'; break; case 'youtube-channel': $serviceInfo['usertype'] = 'channel'; $serviceInfo['service'] = 'youtube'; break; } $layers['follow']['services'][] = $serviceInfo; } if (!empty($configs['offset']['location'])) { $location = $configs['offset']['location']; $amount = $configs['offset']['amount']; $layers['follow']['offset'][$location] = (int)$amount.'px'; } return $layers; } /** * 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 = parent::sanitizeSettings($input, false); if (is_array($input)) { foreach ($input as $field => $value) { switch ($field) { case 'responsive': $output[$field] = (int)$value['responsive']; 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 'theme': $output[$field] = sanitize_text_field($value); break; case '__hideOnHomepage': $output[$field] = (boolean)$value; break; case '__hideOnUrls': if (is_array($value)) { foreach ($value as $urlPattern) { $output[$field][] = sanitize_text_field($urlPattern); } } break; } } } if (isset($output['size'])) { unset($output['size']); } if ($addDefaultConfigs) { $output = $this->addDefaultConfigs($output); } return $output; } } }