Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action("widgets_init", "AdSolidaire_Widget_load_widgets");
- function AdSolidaire_Widget_load_widgets() {
- register_widget('AdSolidaire_Widget');
- }
- class AdSolidaire_Widget extends WP_Widget {
- function AdSolidaire_Widget(){
- /* Widget settings. */
- $widget_ops = array('classname' => 'Ad Solidaire', 'description' => __('Un Widget qui est capable de mettre des Advertissements du base de donnees AdSolidaire.', 'Ad Solidaire') );
- /* Widget control settings. */
- $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'adsolidaire-widget' );
- /* Create the widget. */
- $this->WP_Widget( 'adsolidaire-widget', __('Ad Solidaire Widget', 'adsolidaire'), $widget_ops, $control_ops );
- }
- /**
- * Displays the widget settings controls on the widget panel.
- * Make use of the get_field_id() and get_field_name() function
- * when creating your form elements. This handles the confusing stuff.
- */
- function form($instance) {
- //TODO: set default settings, need other arrays!
- //$defaults = array( 'Type' => "petit", 'Categories' => __('Test', 'example') );
- //$instance = wp_parse_args( (array) $instance );
- //print_r($instance);
- //use the main wp mysql
- global $wpdb;
- //get the current options stored in the "inivisible config of the widget"
- //$data = get_option('AdSolidaire_Widget');
- //Type of Widget (Grand,Petit,Logo)
- $alles="<p><label>Type: <select name=\"Type\" id=\"Type\">\n";
- if ($instance['Type']=="grand") {
- $alles.=" <option value=\"grand\" SELECTED>Grand</option>\n";
- } else {
- $alles.=" <option value=\"grand\">Grand</option>\n";
- }
- if ($instance['Type']=="grand") {
- $alles.=" <option value=\"petit\" SELECTED>Petit</option>\n";
- } else {
- $alles.=" <option value=\"petit\">Petit</option>\n";
- }
- if ($instance['Type']=="logo") {
- $alles.=" <option value=\"logo\" SELECTED>Logo</option>\n";
- } else {
- $alles.=" <option value=\"logo\">Logo</option>\n";
- }
- $alles.="</select></label></p>\n\n";
- echo $alles;
- // NEW : get all categories fro mthe wordpress database, so that everything corresponds
- echo $this->get_categories_checkboxes($instance['Categories']);
- }
- function widget($args,$instance){
- extract($args);
- $alles="<iframe src=\"http://www.fondationmissterre.org/blog/wp-content/plugins/AdSolidaire_Widget/showads.php\"></iframe>";
- echo $alles;
- //echo $args['after_widget'];
- }
- /**
- * Update the widget settings.
- */
- function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- $instance['Type'] = $new_instance['Type'];
- $instance['Categories'] = $new_instance['Categories'];
- return $instance;
- }
- function get_categories_checkboxes($selected_cats = null) {
- $all_categories = get_categories();
- $o = '<p><label>Catégories: <ul style="margin-left:12px">';
- foreach($all_categories as $key => $cat) {
- if($cat->parent == "0") $o .= $this->__show_category($cat, $selected_cats);
- }
- return $o . '</ul></label>';
- }
- function __show_category($cat_object, $selected_cats = null) {
- $checked = "";
- if(!is_null($selected_cats) && is_array($selected_cats)) {
- $checked = (in_array($cat_object->cat_ID, $selected_cats)) ? 'checked="checked"' : "";
- }
- $ou = '<li><label><input ' . $checked .' type="checkbox" id="Categories[]" name="Categories[]" value="'. $cat_object->cat_ID .'" /> ' . $cat_object->cat_name . '</label>';
- $childs = get_categories('parent=' . $cat_object->cat_ID);
- foreach($childs as $key => $cat) {
- $ou .= '<ul style="margin-left:12px">' . $this->__show_category($cat, $selected_cats) . '</ul>';
- }
- $ou .= '</li>';
- return $ou;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement