* @license GNU General Public License, version 2 * @link http://addthis.com AddThis website */ class AddThisRecommendedContentWhatsNextTool extends AddThisRecommendedContentToolParent { public $prettyName = 'What\'s Next'; public $edition = 'basic'; public $anonymousSupport = true; public $inline = false; public $settingsSubVariableName = 'smlwn'; public $layersApiProductName = 'whatsnext'; protected $defaultConfigs = array( 'enabled' => false, 'title' => 'Recommended for you', 'theme' => 'light', 'offset' => array( 'location' => 'right', //bottom, left, right 'amount' => 0, 'unit' => 'px', ), ); /** * Creates tool specific settings for the JavaScript variable * addthis_layers, used to bootstrap layers * * @param array $configs unused - here because some other tools use it * * @return array an associative array */ public function getAddThisLayers($configs = array()) { $configs = $this->getToolConfigs(); if (!$this->isEnabled()) { return array(); } $layers = array( 'title' => $configs['title'], 'theme' => $configs['theme'], ); if (!empty($configs['offset']['location'])) { $location = $configs['offset']['location']; $amount = $configs['offset']['amount']; $unit = $configs['offset']['unit']; $layers['offset'][$location] = (int)$amount.$unit; } $result = array($this->layersApiProductName => $layers); return $result; } /** * 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 'title': // same as next case 'theme': $output[$field] = sanitize_text_field($value); 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']; } if (!empty($value['unit'])) { $output[$field]['unit'] = sanitize_text_field($value['unit']); } break; } } } if ($addDefaultConfigs) { $output = $this->addDefaultConfigs($output); } return $output; } } }