PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wp-photo-album-plus/wppa-lasten-widget.php

https://bitbucket.org/antonyravel/cape-resorts
PHP | 168 lines | 128 code | 27 blank | 13 comment | 25 complexity | 1ddadef2dda32f7a33f9b73527169d24 MD5 | raw file
  1. <?php
  2. /* wppa-lasten-widget.php
  3. * Package: wp-photo-album-plus
  4. *
  5. * display the last uploaded photos
  6. * Version 5.0.0
  7. */
  8. class LasTenWidget extends WP_Widget {
  9. /** constructor */
  10. function LasTenWidget() {
  11. parent::WP_Widget(false, $name = 'Last Ten Photos');
  12. $widget_ops = array('classname' => 'wppa_lasten_widget', 'description' => __( 'WPPA+ Last Ten Uploaded Photos', 'wppa') );
  13. $this->WP_Widget('wppa_lasten_widget', __('Last Ten Photos', 'wppa'), $widget_ops);
  14. }
  15. /** @see WP_Widget::widget */
  16. function widget($args, $instance) {
  17. global $wpdb;
  18. global $wppa_opt;
  19. global $wppa;
  20. $wppa['in_widget'] = 'lasten';
  21. extract( $args );
  22. $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'album' => '', 'albumenum' => '', 'timesince' => 'yes' ) );
  23. $widget_title = apply_filters('widget_title', $instance['title'] );
  24. $page = $wppa_opt['wppa_lasten_widget_linkpage'];
  25. $max = $wppa_opt['wppa_lasten_count'];
  26. $timesince = $instance['timesince'];
  27. $album = $instance['album'];
  28. $albumenum = $instance['albumenum'];
  29. if ($album == '-99') $album = implode("' OR `album` = '", explode(',', $albumenum));
  30. if ($album) {
  31. $query = "SELECT * FROM `".WPPA_PHOTOS."` WHERE ( `album` = '".$album."' ) AND `status` <> 'pending' ORDER BY `timestamp` DESC LIMIT " . $max;
  32. }
  33. else {
  34. $query = "SELECT * FROM `".WPPA_PHOTOS."` WHERE `status` <> 'pending' ORDER BY `timestamp` DESC LIMIT " . $max;
  35. }
  36. $thumbs = $wpdb->get_results( $query, ARRAY_A );
  37. $widget_content = "\n".'<!-- WPPA+ LasTen Widget start -->';
  38. $maxw = $wppa_opt['wppa_lasten_size'];
  39. $maxh = $maxw + 18;
  40. if ($thumbs) foreach ($thumbs as $image) {
  41. global $thumb;
  42. $thumb = $image;
  43. // Make the HTML for current picture
  44. $widget_content .= "\n".'<div class="wppa-widget" style="width:'.$maxw.'px; height:'.$maxh.'px; margin:4px; display:inline; text-align:center; float:left;">';
  45. if ($image) {
  46. $no_album = !$album;
  47. if ($no_album) $tit = __a('View the most recent uploaded photos', 'wppa_theme'); else $tit = esc_attr(wppa_qtrans(stripslashes($image['description'])));
  48. $link = wppa_get_imglnk_a('lasten', $image['id'], '', $tit, '', $no_album, $albumenum);
  49. $file = wppa_get_thumb_path($image['id']);
  50. $imgstyle_a = wppa_get_imgstyle_a($file, $maxw, 'center', 'ltthumb');
  51. $imgstyle = $imgstyle_a['style'];
  52. $width = $imgstyle_a['width'];
  53. $height = $imgstyle_a['height'];
  54. $cursor = $imgstyle_a['cursor'];
  55. $usethumb = wppa_use_thumb_file($image['id'], $width, $height) ? '/thumbs' : '';
  56. $imgurl = WPPA_UPLOAD_URL . $usethumb . '/' . $image['id'] . '.' . $image['ext'];
  57. $imgevents = wppa_get_imgevents('thumb', $image['id'], true);
  58. if ($link) $title = esc_attr(stripslashes($link['title']));
  59. else $title = '';
  60. if ($link) {
  61. if ( $link['is_url'] ) { // Is a href
  62. $widget_content .= "\n\t".'<a href="'.$link['url'].'" title="'.$title.'" target="'.$link['target'].'" >';
  63. $widget_content .= "\n\t\t".'<img id="i-'.$image['id'].'-'.$wppa['master_occur'].'" title="'.$title.'" src="'.$imgurl.'" width="'.$width.'" height="'.$height.'" style="'.$imgstyle.' cursor:pointer;" '.$imgevents.' alt="'.esc_attr(wppa_qtrans($image['name'])).'">';
  64. $widget_content .= "\n\t".'</a>';
  65. }
  66. elseif ( $link['is_lightbox'] ) {
  67. $title = wppa_get_lbtitle('thumb', $image['id']);
  68. $widget_content .= "\n\t".'<a href="'.$link['url'].'" rel="'.$wppa_opt['wppa_lightbox_name'].'[lasten-'.$album.']" title="'.$title.'" target="'.$link['target'].'" >';
  69. $widget_content .= "\n\t\t".'<img id="i-'.$image['id'].'-'.$wppa['master_occur'].'" title="'.wppa_zoom_in().'" src="'.$imgurl.'" width="'.$width.'" height="'.$height.'" style="'.$imgstyle.$cursor.'" '.$imgevents.' alt="'.esc_attr(wppa_qtrans($image['name'])).'">';
  70. $widget_content .= "\n\t".'</a>';
  71. }
  72. else { // Is an onclick unit
  73. $widget_content .= "\n\t".'<img id="i-'.$image['id'].'-'.$wppa['master_occur'].'" title="'.$title.'" src="'.$imgurl.'" width="'.$width.'" height="'.$height.'" style="'.$imgstyle.' cursor:pointer;" '.$imgevents.' onclick="'.$link['url'].'" alt="'.esc_attr(wppa_qtrans($image['name'])).'">';
  74. }
  75. }
  76. else {
  77. $widget_content .= "\n\t".'<img id="i-'.$image['id'].'-'.$wppa['master_occur'].'" title="'.$title.'" src="'.$imgurl.'" width="'.$width.'" height="'.$height.'" style="'.$imgstyle.'" '.$imgevents.' alt="'.esc_attr(wppa_qtrans($image['name'])).'">';
  78. }
  79. }
  80. else { // No image
  81. $widget_content .= __a('Photo not found.', 'wppa_theme');
  82. }
  83. if ($timesince == 'yes') {
  84. $widget_content .= "\n\t".'<span style="font-size:9px;">'.wppa_get_time_since($image['timestamp']);
  85. $widget_content .= '</span>';
  86. }
  87. $widget_content .= "\n".'</div>';
  88. }
  89. else $widget_content .= 'There are no uploaded photos (yet).';
  90. $widget_content .= '<div style="clear:both"></div>';
  91. $widget_content .= "\n".'<!-- WPPA+ LasTen Widget end -->';
  92. echo "\n" . $before_widget;
  93. if ( !empty( $widget_title ) ) { echo $before_title . $widget_title . $after_title; }
  94. echo $widget_content . $after_widget;
  95. $wppa['in_widget'] = false;
  96. }
  97. /** @see WP_Widget::update */
  98. function update($new_instance, $old_instance) {
  99. $instance = $old_instance;
  100. $instance['title'] = strip_tags($new_instance['title']);
  101. $instance['album'] = $new_instance['album'];
  102. $instance['albumenum'] = $new_instance['albumenum'];
  103. if ( $instance['album'] != '-99' ) $instance['albumenum'] = '';
  104. $instance['timesince'] = $new_instance['timesince'];
  105. return $instance;
  106. }
  107. /** @see WP_Widget::form */
  108. function form($instance) {
  109. global $wppa_opt;
  110. //Defaults
  111. $instance = wp_parse_args( (array) $instance, array( 'title' => __('Last Ten Photos', 'wppa'), 'album' => '0', 'albumenum' => '', 'timesince' => 'yes' ) );
  112. $widget_title = apply_filters('widget_title', $instance['title']);
  113. $album = $instance['album'];
  114. $timesince = $instance['timesince'];
  115. ?>
  116. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'wppa'); ?></label>
  117. <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $widget_title; ?>" />
  118. </p>
  119. <p><label for="<?php echo $this->get_field_id('album'); ?>"><?php _e('Album:', 'wppa'); ?></label>
  120. <select class="widefat" id="<?php echo $this->get_field_id('album'); ?>" name="<?php echo $this->get_field_name('album'); ?>" >
  121. <?php echo wppa_album_select_a(array('selected' => $album, 'addall' => true, 'addmultiple' => true, 'addnumbers' => true, 'path' => wppa_switch('wppa_hier_albsel'))) //('', $album, true, '', '', true, '', '', true, true); ?>
  122. </select>
  123. </p>
  124. <?php $album_enum = $instance['albumenum'] ?>
  125. <p id="wppa-albums-enum" style="display:block;" ><label for="<?php echo $this->get_field_id('albumenum'); ?>"><?php _e('Albums:', 'wppa'); ?></label>
  126. <small style="color:blue;" ><br /><?php _e('Select --- multiple see below --- in the Album selection box. Then enter album numbers seperated by commas', 'wppa') ?></small>
  127. <input class="widefat" id="<?php echo $this->get_field_id('albumenum'); ?>" name="<?php echo $this->get_field_name('albumenum'); ?>" type="text" value="<?php echo $album_enum ?>" />
  128. </p>
  129. <p>
  130. <?php _e('Show time since:', 'wppa'); ?>
  131. <select id="<?php echo $this->get_field_id('timesince'); ?>" name="<?php echo $this->get_field_name('timesince'); ?>">
  132. <option value="no" <?php if ($timesince == 'no') echo 'selected="selected"' ?>><?php _e('no.', 'wppa'); ?></option>
  133. <option value="yes" <?php if ($timesince == 'yes') echo 'selected="selected"' ?>><?php _e('yes.', 'wppa'); ?></option>
  134. </select>
  135. </p>
  136. <p><?php _e('You can set the sizes in this widget in the <b>Photo Albums -> Settings</b> admin page.', 'wppa'); ?></p>
  137. <?php
  138. }
  139. } // class LasTenWidget
  140. // register LasTenWidget widget
  141. add_action('widgets_init', create_function('', 'return register_widget("LasTenWidget");'));