'widget_specialrecentpostsFree',
'description' => __('The Special Recent Posts FREE Edition widget. Drag to configure.', SRP_TRANSLATION_ID)
);
// Assigning widget options.
$this->WP_Widget('WDG_SpecialRecentPostsFree', 'Special Recent Posts FREE', $widget_ops);
// Assigning global plugin option values to local variable.
$this->plugin_args = get_option('srp_plugin_options');
}
/*
| ---------------------------------------------
| WIDGET FORM DISPLAY METHOD
| ---------------------------------------------
*/
// Main form widget method.
function form($instance) {
// Outputs the options form on widget panel.
$this->buildWidgetForm($instance);
}
/*
| ---------------------------------------------
| WIDGET UPDATE & MAIN METHODS
| ---------------------------------------------
*/
// Main method for widget update process.
function update($new_instance, $old_instance) {
// Declaring global plugin values.
global $srp_default_widget_values;
// Processes widget options to be saved.
$instance = SpecialRecentPostsFree::srp_version_map_check($old_instance);
// Looping through the entire list of plugin options.
foreach($srp_default_widget_values as $k => $v) {
// Switching through each option.
switch($k) {
case "post_random":
case "thumbnail_link":
case "category_title":
case "post_current_hide":
case "post_date":
case "widget_title_hide":
case "nofollow_links":
case "string_break_link":
// Fix all the NULL values coming from unchecked checkboxes.
$instance[$k] = (!isset($new_instance[$k])) ? "no" : $new_instance[$k];
break;
case "thumbnail_width":
case "thumbnail_height":
// Checking if the new value is numeric. Then assign it.
if (is_numeric($new_instance[$k])) $instance[$k] = trim($new_instance[$k]);
break;
case "post_limit":
case "post_content_length":
case "post_title_length":
// Checking if the new value is numeric and is not zero. Then assign it.
if ( (is_numeric($new_instance[$k])) && ($new_instance[$k] != 0) ) $instance[$k] = trim($new_instance[$k]);
break;
case "post_offset":
// Checking if the new value is numeric and is > of zero. Then assign it.
$instance[$k] = ( (is_numeric($new_instance[$k])) && ($new_instance[$k] > 0) ) ? trim($new_instance[$k]) : 0;
break;
default:
// Default behaviour: for all the other options, assign the new value.
$instance[$k] = $new_instance[$k];
break;
}
}
// Return new widget instance.
return $instance;
}
/*
| ---------------------------------------------
| Main widget method. Main logic lies here.
| ---------------------------------------------
*/
function widget($args, $instance) {
// Checking Visualization filter.
if (SpecialRecentPostsFree::visualizationCheck($instance, 'widget')) {
// Extracting arguments.
extract($args, EXTR_SKIP);
// Printing pre-widget stuff.
echo $before_widget;
// Creating an instance of Special Recent Posts Class.
$srp = new SpecialRecentPostsFree($instance, $this->id);
// Displaying posts.
if (is_object($srp)) $srp->displayPosts(true, 'print');
// Printing after widget stuff.
echo $after_widget;
}
}
/*
| --------------------------------------------------
| This method generates the shortcode and PHP code
| from the current widget values.
| --------------------------------------------------
*/
function srp_generate_code($instance, $code_mode) {
// Switching between "shortcode" or "php code".
switch($code_mode) {
case "shortcode":
// Defining global widget values.
global $srp_default_widget_values;
// Opening shortcode.
$shortcode_code = "[srp";
// Looping through list of available widget values.
foreach($instance as $key=>$value) {
// Checking if the current set value is different than the default one.
if (($srp_default_widget_values[$key] != $value)) {
// If it's so, put the new key=>value in the shortcode.
$shortcode_code .= " " . $key . "=\"" . $value . "\"";
}
}
// Closing shortcode.
$shortcode_code .= "]";
// Return the shortcode.
return $shortcode_code;
break;
case "php":
// Defining global widget values.
global $srp_default_widget_values;
// Opening PHP code.
$phpcode_code = "<?php\n";
// Building PHP $args.
$phpcode_code .= "\$args = array(\n";
// Looping through list of available widget values.
foreach($instance as $key=>$value) {
// Checking if the current set value is different than the default one.
if (($srp_default_widget_values[$key] != $value)) {
// If it's so, put the new key=>value in the PHP code.
$phpcode_code .= "\"" . $key . "\" => \"" . $value . "\",";
}
}
// Right trimming the last comma from the $args list.
$phpcode_code = rtrim($phpcode_code, ',');
// Closing PHP code.
$phpcode_code .= ");\n";
$phpcode_code .= "special_recent_posts(\$args);\n";
$phpcode_code .= "?>\n";
// Return PHP code.
return $phpcode_code;
break;
}
}
/*
| --------------------------------------------------
| This method builds the widget admin form.
| --------------------------------------------------
*/
function buildWidgetForm($instance) {
// Loading default widget values.
global $srp_default_widget_values;
// Loading default plugin settings.
$plugin_args = get_option('srp_plugin_options');
// Merging default values with instance array, in case this is empty.
$instance = wp_parse_args( (array) SpecialRecentPostsFree::srp_version_map_check($instance), $srp_default_widget_values);
?>