* @license GNU General Public License, version 2 * @link http://addthis.com AddThis website */ class AddThisGlobalOptionsWidget extends WP_Widget { private $widgetBaseId = 'addthis_global_options_widget'; private $widgetName = 'AddThis Script'; private $widgetDescription = 'If your theme is not adding the AddThis script (addthis_widget.js) onto your pages, try adding this widget.'; private $toolClassName = 'AddThisGlobalOptionsTool'; /** * Bootstraps the widget for WordPress. It determines its tool settings * class name, and passes that string to its parent constructor. * * @return null */ public function __construct() { if (!class_exists($this->toolClassName)) { error_log(__METHOD__ . ' class ' . $this->toolClassName . ' does not exists.'); return null; } $toolClass = new $this->toolClassName(); $this->toolClass = $toolClass; $name = __($this->widgetName, AddThisFeature::$l10n_domain); $description = __($this->widgetDescription, AddThisFeature::$l10n_domain); $widgetOptions = array( 'description' => $description, ); $controlOptions = array(); parent::__construct( $this->widgetBaseId, $name, $widgetOptions, $controlOptions ); } /** * Prints out HTML for the options form in the WordPress admin Dashboard * * @param array $instance Saved values from the database for this * instance of the widget * * @return null */ public function form($instance) { $description = __($this->widgetDescription, AddThisFeature::$l10n_domain); $goo = $this->toolClass->getGlobalOptionsObject(); $html = '
'.$description.'
'; $html .= ''.$goo->getSettingsLinkHtmlForWidgets().'
'; $html .= ''.$goo->eulaText('Save').'
'; echo $html; } /** * Processing widget options on save * * @param array $new_instance options values just sent to be saved * @param array $old_instance previously options values (from database) * * @return array */ public function update($new_instance, $old_instance) { $instance = array(); return $instance; } /** * Prints out HTML for the content of the widget * * @param array $args Widget arguments * @param array $instance Saved values from the database for this * instance of the widget * * @return null */ public function widget($args, $instance) { $addThisToolCode = $this->toolClass->getInlineCode($args, $instance); if (!isset($args['widget_name'])) { $args['widget_name'] = 'no name'; } $html = ' '.$addThisToolCode.' '; echo $html; } } }