Advertisement
Guest User

Untitled

a guest
Sep 4th, 2011
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. add_action("widgets_init", "AdSolidaire_Widget_load_widgets");
  2.  
  3. function AdSolidaire_Widget_load_widgets() {
  4. register_widget('AdSolidaire_Widget');
  5. }
  6.  
  7. class AdSolidaire_Widget extends WP_Widget {
  8. function AdSolidaire_Widget(){
  9. /* Widget settings. */
  10. $widget_ops = array('classname' => 'Ad Solidaire', 'description' => __('Un Widget qui est capable de mettre des Advertissements du base de donnees AdSolidaire.', 'Ad Solidaire') );
  11.  
  12. /* Widget control settings. */
  13. $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'adsolidaire-widget' );
  14.  
  15. /* Create the widget. */
  16. $this->WP_Widget( 'adsolidaire-widget', __('Ad Solidaire Widget', 'adsolidaire'), $widget_ops, $control_ops );
  17. }
  18. /**
  19. * Displays the widget settings controls on the widget panel.
  20. * Make use of the get_field_id() and get_field_name() function
  21. * when creating your form elements. This handles the confusing stuff.
  22. */
  23. function form($instance) {
  24. //TODO: set default settings, need other arrays!
  25. //$defaults = array( 'Type' => "petit", 'Categories' => __('Test', 'example') );
  26. //$instance = wp_parse_args( (array) $instance );
  27.  
  28. //print_r($instance);
  29.  
  30. //use the main wp mysql
  31. global $wpdb;
  32.  
  33. //get the current options stored in the "inivisible config of the widget"
  34. //$data = get_option('AdSolidaire_Widget');
  35.  
  36. //Type of Widget (Grand,Petit,Logo)
  37. $alles="<p><label>Type: <select name=\"Type\" id=\"Type\">\n";
  38. if ($instance['Type']=="grand") {
  39. $alles.=" <option value=\"grand\" SELECTED>Grand</option>\n";
  40. } else {
  41. $alles.=" <option value=\"grand\">Grand</option>\n";
  42. }
  43. if ($instance['Type']=="grand") {
  44. $alles.=" <option value=\"petit\" SELECTED>Petit</option>\n";
  45. } else {
  46. $alles.=" <option value=\"petit\">Petit</option>\n";
  47. }
  48. if ($instance['Type']=="logo") {
  49. $alles.=" <option value=\"logo\" SELECTED>Logo</option>\n";
  50. } else {
  51. $alles.=" <option value=\"logo\">Logo</option>\n";
  52. }
  53. $alles.="</select></label></p>\n\n";
  54.  
  55. echo $alles;
  56.  
  57. // NEW : get all categories fro mthe wordpress database, so that everything corresponds
  58. echo $this->get_categories_checkboxes($instance['Categories']);
  59. }
  60. function widget($args,$instance){
  61. extract($args);
  62.  
  63. $alles="<iframe src=\"http://www.fondationmissterre.org/blog/wp-content/plugins/AdSolidaire_Widget/showads.php\"></iframe>";
  64. echo $alles;
  65. //echo $args['after_widget'];
  66. }
  67. /**
  68. * Update the widget settings.
  69. */
  70. function update( $new_instance, $old_instance ) {
  71. $instance = $old_instance;
  72.  
  73. $instance['Type'] = $new_instance['Type'];
  74. $instance['Categories'] = $new_instance['Categories'];
  75.  
  76. return $instance;
  77. }
  78. function get_categories_checkboxes($selected_cats = null) {
  79. $all_categories = get_categories();
  80.  
  81. $o = '<p><label>Cat&eacute;gories: <ul style="margin-left:12px">';
  82. foreach($all_categories as $key => $cat) {
  83. if($cat->parent == "0") $o .= $this->__show_category($cat, $selected_cats);
  84. }
  85. return $o . '</ul></label>';
  86. }
  87. function __show_category($cat_object, $selected_cats = null) {
  88. $checked = "";
  89. if(!is_null($selected_cats) && is_array($selected_cats)) {
  90. $checked = (in_array($cat_object->cat_ID, $selected_cats)) ? 'checked="checked"' : "";
  91. }
  92. $ou = '<li><label><input ' . $checked .' type="checkbox" id="Categories[]" name="Categories[]" value="'. $cat_object->cat_ID .'" /> ' . $cat_object->cat_name . '</label>';
  93. $childs = get_categories('parent=' . $cat_object->cat_ID);
  94.  
  95. foreach($childs as $key => $cat) {
  96. $ou .= '<ul style="margin-left:12px">' . $this->__show_category($cat, $selected_cats) . '</ul>';
  97. }
  98.  
  99. $ou .= '</li>';
  100. return $ou;
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement