* @license GNU General Public License, version 2 * @link http://addthis.com AddThis website */ class AddThisSharingButtonsMobileToolbarTool extends AddThisSharingButtonsToolParent { //pco smlmo public $layersApiProductName = 'dock'; protected $defaultConfigs = array(); /** * Creates tool specific settings for the JavaScript variable * addthis_layers, used to bootstrap layers * * @param array $input array of settings * * @return array an associative array */ public function getAddThisLayers($input = array()) { $output = array(); if (empty($input['enabled']) || !$this->enabledOnTemplate($input['templates']) ) { return $output; } $smartLayersConfigs = array( 'follow' => $input['follow'], 'buttonBarTheme' => $input['buttonBarTheme'], 'buttonBarPosition' => $input['buttonBarPosition'], ); $smartLayersConfigs['followServices'] = AddThisFollowButtonsToolParent::formatServicesForAddThisLayers($input['followServices']); $output = array('dock' => $smartLayersConfigs); return $output; } /** * 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; break; case 'follow': if ($value === 'off' || $value === 'on') { $output[$field] = $value; } break; case 'templates': if (is_array($value)) { $output[$field] = array(); foreach ($value as $service) { $output[$field][] = sanitize_text_field($service); } } break; case 'followServices': if (is_array($value)) { foreach ($value as $service => $username) { if (!empty($username)) { $output['followServices'][$service] = sanitize_text_field($username); } } } break; case 'buttonBarTheme': if ($value === 'gray' || $value === 'dark' || $value === 'light') { $output[$field] = $value; } break; case 'buttonBarPosition': if ($value === 'top' || $value === 'bottom') { $output[$field] = $value; } break; case 'toolName': case 'widgetId': case 'id': $output[$field] = sanitize_text_field($value); break; } } } if ($addDefaultConfigs) { $output = $this->addDefaultConfigs($output); } if (empty($output['followServices'])) { $output['followServices'] = new stdClass(); } return $output; } } }