. */ namespace Cforms2; class Widget extends \WP_Widget { public function __construct() { parent::__construct( 'cforms', __('cformsII', 'cforms2'), array( 'description' => __('Add any cforms form to your sidebar', 'cforms2') ), array('width' => 200, 'height' => 200) ); } /** * Outputs the content of the widget * * @param array $args * @param array $instance */ public function widget($args, $instance) { $no = ($instance['form'] == '1') ? '' : $instance['form']; echo $args['before_widget']; if (!empty($instance['title'])) echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; insert_cform($no); echo $args['after_widget']; } /** * Outputs the options form on admin * * @param array $instance The widget options */ public function form($instance) { // stored data $title = isset($instance['title']) ? $instance['title'] : ''; $form = isset($instance['form']) ? $instance['form'] : null; $opt = ''; $forms = count(FormSettings::forms()); for ($i = 1; $i <= $forms; $i++) { $no = ($i == 1) ? '' : ($i); $selected = ( $i == $form ) ? ' selected="selected"' : ''; $name = stripslashes(FormSettings::form($no)->name()); $name = (strlen($name) > 40) ? substr($name, 0, 40) . '…' : $name; $opt .= ''; } echo '' . '
'; echo '' . ''; } /** * Processing widget options on save * * @param array $new_instance The new options * @param array $old_instance The previous options */ public function update($new_instance, $old_instance) { $check = array('title', 'form'); $instance = array(); foreach ($check as $value) { if (empty($new_instance[$value])) { $instance[$value] = ''; } else { $instance[$value] = strip_tags($new_instance[$value]); } } return $instance; } }