function widget($args, $instance) { extract($args); $name = empty($instance['name']) ? '' : $instance['name']; //$MyWidget = MCW_get_mywidget_by_name($name); $code = empty($instance['code']) ? $MyWidget['code'] : $instance['code']; $kind = empty($instance['kind']) ? $MyWidget['kind'] : $instance['kind']; $title = empty($instance['title']) ? $MyWidget['title'] : $instance['title']; $title = apply_filters('widget_title', $title); $myfilteroptions = MCW_get_option('filters'); $max = count($myfilteroptions); for ($i = 0; $i < $max; ++$i) { $filter_ID = 'filter-' . $myfilteroptions[$i][0]; $MyWidget[$filter_ID] = empty($instance[$filter_ID]) ? $MyWidget[$filter_ID] : $instance[$filter_ID]; } $beforecode = empty($instance['beforecode']) ? $MyWidget['beforecode'] : $instance['beforecode']; $foreign_id = empty($instance['foreign_id']) ? $MyWidget['foreign_id'] : $instance['foreign_id']; $MyWidget['kind'] = $kind; $MyWidget['name'] = $name; $MyWidget['code'] = $code; $MyWidget['beforecode'] = $beforecode; $MyWidget['foreign_id'] = $foreign_id; MCW_logfile("prüfung ob filter zulässig."); //debugging only $myfilteroptions = MCW_get_option('filters'); $max = count($myfilteroptions); $erg = false; $temp = false; for ($i = 0; $i < $max; ++$i) { $c = 'if (' . stripslashes($myfilteroptions[$i][1]) . '){$temp = true;}'; // filter würde greifen eval($c); if ($temp && $instance['filter-' . $myfilteroptions[$i][0]] == 1) { // und filter wurde aktiviert $visible = true; break; } } if ($visible) { MCW_logfile("Darstellung ist zulässig."); //debugging only # Before the widget if ($title != "") { echo $before_widget; } if (trim($title) != "") { $output = $before_title . $title . $after_title; } $output = $output . MCW_run_code($MyWidget); # apply filters if (MCW_get_option('use_wpfilter')) { $wpfilter = MCW_get_option('wpfilter'); $output = apply_filters($wpfilter, $output); } echo $output; # After the widget if ($title != "") { echo $after_widget; } } }
function MCW_generate_class() { global $mcw_path; MCW_logfile('start class generation:'); //debugging only $myWidget_IDs_all = MCW_get_all_widget_IDs(); $maxindex = count($myWidget_IDs_all); $filename = $mcw_path["include_class"]; MCW_logfile('start to write ' . $maxindex . ' widgets into ' . $filename); //debugging only if (!file_exists($filename)) { copy(dirname(__FILE__) . '/' . $mcw_path["function_source"], $filename); } if (!file_exists($filename)) { $answer = "file " . $filename . " does not exist. Please create the file (chmod 0666).<br>"; $bug = $answer; //echo "MyCustomWidget-Plugin: ".$answer; } else { if (!($handle = fopen($filename, "w"))) { $answer = $answer . 'File "' . $filename . '" cannot be opened.<br>Please grant write access (chmod 0666)'; $bug = $answer; } else { // Write $somecontent into the open file. $res = "<?" . "php"; $res = $res . "\n" . "/" . "*"; $res = $res . "\n" . "Author: Janek Niefeldt"; $res = $res . "\n" . "Author URI: http://www.janek-niefeldt.de/"; $res = $res . "\n" . "Description: Configuration of My Custom Widgets Plugin."; $res = $res . "\n" . "*" . "/"; $res = $res . "\n" . "include_once('my_custom_widget_functions.php');"; $res = $res . "\n" . "include_once('my_custom_widget_meta.php');"; $res = $res . "\n" . "?" . ">"; if (!fwrite($handle, $res)) { $answer = "File " . $filename . " is not writeable (please chmod 0666 or change owner).<br>"; $bug = $answer; } else { for ($widgetindex = 0; $widgetindex < $maxindex; ++$widgetindex) { $somecontent = MCW_generate_class_content($myWidget_IDs_all[$widgetindex]['name']); if (!fwrite($handle, $somecontent)) { $answer = $answer . "File " . $filename . " is not writeable.<br>"; $bug = $answer; //echo "MyCustomWidget-Plugin: ".$answer; } else { MCW_logfile('class generated: ' . $myWidget_IDs_all[$widgetindex]['name']); //debugging only $answer = $answer . "done <br>"; } } } } fclose($handle); } MCW_logfile($answer); //debugging only return $bug; }