* @license GNU General Public License, version 2 * @link http://addthis.com AddThis website */ class AddThisSharingButtonsSidebarTool extends AddThisSharingButtonsToolParent { public $prettyName = 'Sharing Sidebar'; public $edition = 'basic'; public $clientApiSupport = true; public $inline = false; public $settingsSubVariableName = 'smlsh'; protected $defaultConfigs = array( 'enabled' => false, // old field name was addthis_sidebar_enabled 'position' => 'left', // old field name was addthis_sidebar_position 'services' => '', 'title' => '', // boost only 'theme' => 'transparent', // old field name was addthis_sidebar_theme 'counts' => false, 'numPreferredServices' => 5, // old field name was addthis_sidebar_count 'offset' => array( 'location' => 'top', 'amount' => 0, ), 'responsive' => array( 'maxWidth' => 978, ), ); /** * 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( 'share' => array( 'position' => $configs['position'], 'services' => $configs['services'], 'theme' => $configs['theme'], 'numPreferredServices' => $configs['numPreferredServices'], 'responsive' => $configs['responsive'], ), ); if (isset($configs['thankyou'])) { $layers['share']['thankyou'] = $configs['thankyou']; } if (isset($configs['postShareTitle'])) { $layers['share']['postShareTitle'] = $configs['postShareTitle']; } if (isset($configs['postShareFollowMsg'])) { $layers['share']['postShareFollowMsg'] = $configs['postShareFollowMsg']; } if (isset($configs['postShareRecommendedMsg'])) { $layers['share']['postShareRecommendedMsg'] = $configs['postShareRecommendedMsg']; } if (!empty($configs['offset']['location']) && !empty($configs['offset']['amount']) ) { $location = $configs['offset']['location']; $amount = $configs['offset']['amount']; $layers['follow']['offset'][$location] = (int)$amount.'px'; } /** * Not supported in the addthis.layers() API: * __hideOnHomepage * __hideOnUrls */ 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 = 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; } } }