function MCW_plugin_init() { if (!function_exists('register_widget')) { return; } /******************************/ /*** deinstallation routine ***/ /******************************/ function MCW_deinstall() { global $mcw_prefix; global $mcw_widgetsoption; global $mcw_configoption; global $mcw_metaoption; global $mcw_backup_postfix; delete_option($mcw_prefix . $mcw_metaoption); //delete all productive data $all_widget_IDs = get_option($mcw_prefix . $mcw_widgetsoption); $max = count($all_widget_IDs); for ($i = 0; $i < $max; ++$i) { delete_option($mcw_prefix . 'w_' . $all_widget_IDs[$i]['name']); } delete_option($mcw_prefix . $mcw_widgetsoption); delete_option($mcw_prefix . $mcw_configoption); //delete all backup data $all_backup_widget_IDs = get_option($mcw_prefix . $mcw_widgetsoption . $mcw_backup_postfix); $max = count($all_backup_widget_IDs); for ($i = 0; $i < $max; ++$i) { delete_option($mcw_prefix . $mcw_backup_postfix . 'w_' . $all_backup_widget_IDs[$i]['name']); } delete_option($mcw_prefix . $mcw_widgetsoption . $mcw_backup_postfix); delete_option($mcw_prefix . $mcw_configoption . $mcw_backup_postfix); } /************************************/ /*** initialize widgets ***/ /************************************/ $myWidget_IDs_all = MCW_get_all_widget_IDs(); $maxindex = count($myWidget_IDs_all); // Register widgets if (!empty($myWidget_IDs_all)) { if (MCW_generaterequired() == true) { echo MCW_generate_class(); } //include_once( "my_custom_widget_classes.php" ); global $mcw_path; include_once $mcw_path["include_class"]; $tag = MCW_get_option('outfilter'); add_filter($tag, MCW_make_available_outside); } /*************************************************************************/ /*** single widget-implementation as it has to be according to WP 2.8 ***/ /*************************************************************************/ include_once "my_custom_widget_addon.php"; }
/******************/ if ($_POST[$element_widget_backup] == $button_text_set_backup) { if ($_POST[$data_widget_backup] != $data_widget_backup) { echo '<div id="message" class="updated fade"><p>To save backup you have to check the Backup-Checkbox as well.</p></div>'; } else { $cache_all_widgets = MCW_get_all_widgets(); MCW_set_widget_backup($cache_all_widgets); $max = count($cache_all_widgets); echo '<div id="message" class="updated fade"><p>Backup stored successfully.</p></div>'; } } /***********************/ /*** fill cache data ***/ /***********************/ $cache_widget = array('name' => MCW_make_name_acceptable(trim($_POST[$data_widget_name])), 'code' => $_POST[$data_widget_code], 'kind' => $_POST[$data_widget_kind], 'title' => $_POST[$data_widget_title], 'filter' => $_POST[$data_widget_filter], 'beforecode' => $_POST[$data_widget_code . '_before'], 'foreign_id' => $_POST[$data_foreign_widget_id]); $max = count(MCW_get_all_widget_IDs()); $help_deleted_flag = 0; unset($cache_all_widgets); for ($i = 0; $i < $max; ++$i) { //reduce cache count if entry was deleted $help_widget = MCW_get_mywidget_by_index($i - $help_deleted_flag); $help_widget = array('name' => $help_widget['name'], 'code' => $_POST[$data_widget_code . $i], 'kind' => $_POST[$data_widget_kind . $i], 'title' => $_POST[$data_widget_title . $i], 'filter' => $_POST[$data_widget_filter . $i], 'beforecode' => $_POST[$data_widget_code . $i . '_before'], 'foreign_id' => $_POST[$data_foreign_widget_id . $i]); /**********************/ /*** delete entries ***/ /**********************/ if ($_POST[$element_widget_submit . $i] == $button_text_delete_single) { $error_message = MCW_delete_mywidget($i); if ($error_message != '') { ?> <div id="message" class="error"> <p><b><?php
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; }