AndrzejL

widgets

Jun 21st, 2014
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * PRESENTATION PAGE COLUMNS
  5. */
  6.  
  7. // Counting the PP column widgets
  8. global $tempera_column_counter;
  9. $tempera_column_counter = 0;
  10.  
  11. class ColumnsWidget extends WP_Widget
  12. {
  13. var $temperas; // theme options read in the constructor
  14.  
  15. function ColumnsWidget() {
  16. $widget_ops = array('classname' => 'ColumnsWidget', 'description' => 'Add columns in the presentation page' );
  17. $control_ops = array('width' => 350, 'height' => 350); // making widget window larger
  18. $this->WP_Widget('columns_widget', 'Cryout Column', $widget_ops, $control_ops);
  19. $this->temperas= tempera_get_theme_options(); // reading theme options
  20. }
  21.  
  22. function form($instance) {
  23. $instance = wp_parse_args( (array) $instance, array( 'image' => '', 'title' => '' , 'text' => '', 'link' => '', 'blank' => '' ) );
  24. $image = $instance['image'];
  25. $title = $instance['title'];
  26. $text = $instance['text'];
  27. $link = $instance['link'];
  28. $blank = $instance['blank'];?>
  29. <div>
  30. <p><label for="<?php echo $this->get_field_id('image'); ?>">Image: <input class="widefat slideimages" id="<?php echo $this->get_field_id('image'); ?>" name="<?php echo $this->get_field_name('image'); ?>" type="text" value="<?php echo esc_url($image); ?>" /></label><a class="upload_image_button button" href="#">Select / Upload Image</a></p>
  31. <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
  32. <p><label for="<?php echo $this->get_field_id('text'); ?>">Text: <textarea class="widefat" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>" ><?php echo esc_attr($text); ?></textarea></label></p>
  33. <p><label for="<?php echo $this->get_field_id('link'); ?>">Link: <input class="widefat" id="<?php echo $this->get_field_id('link'); ?>" name="<?php echo $this->get_field_name('link'); ?>" type="text" value="<?php echo esc_url($link); ?>" /></label></p>
  34. <p><label for="<?php echo $this->get_field_id('blank'); ?>">Open in new Window: <input id="<?php echo $this->get_field_id('blank'); ?>" name="<?php echo $this->get_field_name('blank'); ?>" type="checkbox" <?php checked($blank, 1); ?> value="1" /></label></p>
  35. </div>
  36.  
  37. <?php } // form() function
  38.  
  39. function update($new_instance, $old_instance) {
  40. $instance = $old_instance;
  41. $instance['image'] = $new_instance['image'];
  42. $instance['title'] = $new_instance['title'];
  43. $instance['text'] = $new_instance['text'];
  44. $instance['link'] = $new_instance['link'];
  45. $instance['blank'] = $new_instance['blank'];
  46. return $instance;
  47. }
  48.  
  49. function widget($args, $instance) {
  50. $tempera_nrcolumns = $this->temperas['tempera_nrcolumns']; // getting the number of columns setting
  51. $tempera_columnreadmore = $this->temperas['tempera_columnreadmore']; // read more setting
  52. global $tempera_column_counter; // globabl counter for incrementing further
  53. $blank="";
  54. if($instance['blank']) $blank="target='_blank'";
  55.  
  56. if($instance['image']) :
  57. $tempera_column_counter++; // incrementing counter only if widget has image
  58. $counter = $tempera_column_counter; ?>
  59. <div class="column<?php echo ($counter%$tempera_nrcolumns)?$counter%$tempera_nrcolumns:$tempera_nrcolumns; ?>">
  60. <a <?php echo $blank;?> href="<?php echo esc_url($instance['link']) ?>">
  61. <?php if ($instance['title']) { echo "<h3 class='column-header-image'>".$instance['title']."</h3>"; } ?>
  62. </a>
  63.  
  64. <?php if ($instance['image']) : ?>
  65. <div class="column-image">
  66. <div class="column-image-inside"> </div>
  67. <img src="<?php echo esc_url($instance['image']) ?>" id="columnImage<?php echo $counter; ?>" alt="" />
  68. <?php if ($instance['text']) : ?>
  69. <div class="column-text">
  70. <?php echo do_shortcode($instance['text']); ?>
  71. </div>
  72. <?php endif; ?>
  73. <?php if($tempera_columnreadmore && $instance['link'] ): ?>
  74. <div class="columnmore">
  75. <a <?php echo $blank;?> href="<?php echo esc_url($instance['link']) ?>"><?php echo esc_attr($tempera_columnreadmore) ?> <i class="column-arrow"></i> </a>
  76. </div>
  77. <?php endif; ?>
  78. </div><!--column-image-->
  79. <?php endif; ?>
  80.  
  81. </div>
  82. <?php endif; // if image
  83. }// widget() function
  84. }// ColumnsWidget
  85.  
  86. add_action( 'widgets_init','cryout_columns_init' );
  87.  
  88. function cryout_columns_init() {
  89. return register_widget("ColumnsWidget");
  90. }
  91.  
  92. function tempera_widget_scripts() {
  93. // For the WP uploader
  94. if(function_exists('wp_enqueue_media')) {
  95. wp_enqueue_media();
  96. }
  97. else {
  98. wp_enqueue_script('media-upload');
  99. wp_enqueue_script('thickbox');
  100. wp_enqueue_style('thickbox');
  101. }
  102. wp_register_script('admin', get_template_directory_uri().'/admin/js/widgets.js');
  103. wp_enqueue_script('admin');
  104. }
  105.  
  106. add_action ('admin_print_scripts-widgets.php','tempera_widget_scripts');
  107.  
  108. ?>
Advertisement
Add Comment
Please, Sign In to add comment