/wp-content/plugins/photo-gallery/admin/views/BWGViewWidget.php

https://gitlab.com/edgarze188/sunrise · PHP · 175 lines · 140 code · 6 blank · 29 comment · 10 complexity · df546e298323eb0d0efb6c8c62e1912b MD5 · raw file

  1. <?php
  2. class BWGViewWidget {
  3. ////////////////////////////////////////////////////////////////////////////////////////
  4. // Events //
  5. ////////////////////////////////////////////////////////////////////////////////////////
  6. ////////////////////////////////////////////////////////////////////////////////////////
  7. // Constants //
  8. ////////////////////////////////////////////////////////////////////////////////////////
  9. ////////////////////////////////////////////////////////////////////////////////////////
  10. // Variables //
  11. ////////////////////////////////////////////////////////////////////////////////////////
  12. private $model;
  13. ////////////////////////////////////////////////////////////////////////////////////////
  14. // Constructor & Destructor //
  15. ////////////////////////////////////////////////////////////////////////////////////////
  16. public function __construct($model) {
  17. $this->model = $model;
  18. }
  19. ////////////////////////////////////////////////////////////////////////////////////////
  20. // Public Methods //
  21. ////////////////////////////////////////////////////////////////////////////////////////
  22. public function display() {
  23. }
  24. function widget($args, $instance) {
  25. extract($args);
  26. $title = (isset($instance['title']) ? $instance['title'] : "");
  27. $type = (isset($instance['type']) ? $instance['type'] : "gallery");
  28. $gallery_id = (isset($instance['gallery_id']) ? $instance['gallery_id'] : 0);
  29. $album_id = (isset($instance['album_id']) ? $instance['album_id'] : 0);
  30. $show = (isset($instance['show']) ? $instance['show'] : "random");
  31. $count = (isset($instance['count']) ? $instance['count'] : 4);
  32. $width = (isset($instance['width']) ? $instance['width'] : 100);
  33. $height = (isset($instance['height']) ? $instance['height'] : 100);
  34. $theme_id = (isset($instance['theme_id']) ? $instance['theme_id'] : 0);
  35. // Before widget.
  36. echo $before_widget;
  37. // Title of widget.
  38. if ($title) {
  39. echo $before_title . $title . $after_title;
  40. }
  41. // Widget output.
  42. if ($type == 'gallery') {
  43. require_once(WD_BWG_DIR . '/frontend/controllers/BWGControllerThumbnails.php');
  44. $controller_class = 'BWGControllerThumbnails';
  45. }
  46. else {
  47. require_once(WD_BWG_DIR . '/frontend/controllers/BWGControllerAlbum_compact_preview.php');
  48. $controller_class = 'BWGControllerAlbum_compact_preview';
  49. }
  50. $controller = new $controller_class();
  51. global $bwg;
  52. $params = array (
  53. 'from' => 'widget',
  54. 'gallery_type' => $type,
  55. 'id' => ($type == 'gallery' ? $gallery_id : $album_id),
  56. 'show' => $show,
  57. 'count' => $count,
  58. 'width' => $width,
  59. 'height' => $height,
  60. 'theme_id' => $theme_id);
  61. $controller->execute($params, 1, $bwg);
  62. $bwg++;
  63. // After widget.
  64. echo $after_widget;
  65. }
  66. // Widget Control Panel.
  67. function form($instance, $id_title, $name_title, $id_type, $name_type, $id_show, $name_show, $id_gallery_id, $name_gallery_id, $id_album_id, $name_album_id, $id_count, $name_count, $id_width, $name_width, $id_height, $name_height, $id_theme_id, $name_theme_id) {
  68. $defaults = array(
  69. 'title' => 'Photo Gallery',
  70. 'type' => 'gallery',
  71. 'gallery_id' => 0,
  72. 'album_id' => 0,
  73. 'show' => 'random',
  74. 'count' => 4,
  75. 'width' => 100,
  76. 'height' => 100,
  77. 'theme_id' => 0,
  78. );
  79. $instance = wp_parse_args((array) $instance, $defaults);
  80. $gallery_rows = $this->model->get_gallery_rows_data();
  81. $album_rows = $this->model->get_album_rows_data();
  82. $theme_rows = $this->model->get_theme_rows_data();
  83. ?>
  84. <script>
  85. function bwg_change_type(event, obj) {
  86. var div = jQuery(obj).closest("div");
  87. if (jQuery(jQuery(div).find(".sel_gallery")[0]).prop("checked")) {
  88. jQuery(jQuery(div).find("#p_galleries")).css("display", "");
  89. jQuery(jQuery(div).find("#p_albums")).css("display", "none");
  90. jQuery(obj).nextAll(".bwg_hidden").first().attr("value", "gallery");
  91. }
  92. else {
  93. jQuery(jQuery(div).find("#p_galleries")).css("display", "none");
  94. jQuery(jQuery(div).find("#p_albums")).css("display", "");
  95. jQuery(obj).nextAll(".bwg_hidden").first().attr("value", "album");
  96. }
  97. }
  98. </script>
  99. <p>
  100. <label for="<?php echo $id_title; ?>">Title:</label>
  101. <input class="widefat" id="<?php echo $id_title; ?>" name="<?php echo $name_title; ?>'" type="text" value="<?php echo $instance['title']; ?>"/>
  102. </p>
  103. <p>
  104. <input type="radio" name="<?php echo $name_type; ?>" id="<?php echo $id_type . "_1"; ?>" value="gallery" class="sel_gallery" onclick="bwg_change_type(event, this)" <?php if ($instance['type'] == "gallery") echo 'checked="checked"'; ?> /><label for="<?php echo $id_type . "_1"; ?>">Gallery</label>
  105. <input type="radio" name="<?php echo $name_type; ?>" id="<?php echo $id_type . "_2"; ?>" value="album" class="sel_album" onclick="bwg_change_type(event, this)" <?php if ($instance['type'] == "album") echo 'checked="checked"'; ?> /><label for="<?php echo $id_type . "_2"; ?>">Album</label>
  106. <input type="hidden" name="<?php echo $name_type; ?>" id="<?php echo $id_type; ?>" value="<?php echo $instance['type']; ?>" class="bwg_hidden" />
  107. </p>
  108. <p id="p_galleries" style="display:<?php echo ($instance['type'] == "gallery") ? "" : "none" ?>;">
  109. <select name="<?php echo $name_gallery_id; ?>" id="<?php echo $id_gallery_id; ?>" class="widefat">
  110. <option value="0">Select Gallery</option>
  111. <?php
  112. foreach ($gallery_rows as $gallery_row) {
  113. ?>
  114. <option value="<?php echo $gallery_row->id; ?>" <?php echo (($instance['gallery_id'] == $gallery_row->id) ? 'selected="selected"' : ''); ?>><?php echo $gallery_row->name; ?></option>
  115. <?php
  116. }
  117. ?>
  118. </select>
  119. </p>
  120. <p id="p_albums" style="display:<?php echo ($instance['type'] == "album") ? "" : "none" ?>;">
  121. <select name="<?php echo $name_album_id; ?>" id="<?php echo $id_album_id; ?>" class="widefat">
  122. <option value="0">Select Album</option>
  123. <?php
  124. foreach ($album_rows as $album_row) {
  125. ?>
  126. <option value="<?php echo $album_row->id; ?>" <?php echo (($instance['album_id'] == $album_row->id) ? 'selected="selected"' : ''); ?>><?php echo $album_row->name; ?></option>
  127. <?php
  128. }
  129. ?>
  130. </select>
  131. </p>
  132. <p>
  133. <input type="radio" name="<?php echo $name_show; ?>" id="<?php echo $id_show . "_1"; ?>" value="random" <?php if ($instance['show'] == "random") echo 'checked="checked"'; ?> onclick='jQuery(this).nextAll(".bwg_hidden").first().attr("value", "random");' /><label for="<?php echo $id_show . "_1"; ?>">Random</label>
  134. <input type="radio" name="<?php echo $name_show; ?>" id="<?php echo $id_show . "_2"; ?>" value="first" <?php if ($instance['show'] == "first") echo 'checked="checked"'; ?> onclick='jQuery(this).nextAll(".bwg_hidden").first().attr("value", "first");' /><label for="<?php echo $id_show . "_2"; ?>">First</label>
  135. <input type="radio" name="<?php echo $name_show; ?>" id="<?php echo $id_show . "_3"; ?>" value="last" <?php if ($instance['show'] == "last") echo 'checked="checked"'; ?> onclick='jQuery(this).nextAll(".bwg_hidden").first().attr("value", "last");' /><label for="<?php echo $id_show . "_3"; ?>">Last</label>
  136. <input type="hidden" name="<?php echo $name_show; ?>" id="<?php echo $id_show; ?>" value="<?php echo $instance['show']; ?>" class="bwg_hidden" />
  137. </p>
  138. <p>
  139. <label for="<?php echo $id_count; ?>">Count:</label>
  140. <input class="widefat" style="width:25%;" id="<?php echo $id_count; ?>" name="<?php echo $name_count; ?>'" type="text" value="<?php echo $instance['count']; ?>"/>
  141. </p>
  142. <p>
  143. <label for="<?php echo $id_width; ?>">Dimensions:</label>
  144. <input class="widefat" style="width:25%;" id="<?php echo $id_width; ?>" name="<?php echo $name_width; ?>'" type="text" value="<?php echo $instance['width']; ?>"/> x
  145. <input class="widefat" style="width:25%;" id="<?php echo $id_height; ?>" name="<?php echo $name_height; ?>'" type="text" value="<?php echo $instance['height']; ?>"/> px
  146. </p>
  147. <p>
  148. <select name="<?php echo $name_theme_id; ?>" id="<?php echo $id_theme_id; ?>" class="widefat">
  149. <?php
  150. foreach ($theme_rows as $theme_row) {
  151. ?>
  152. <option value="<?php echo $theme_row->id; ?>" <?php echo (($instance['theme_id'] == $theme_row->id || $theme_row->default_theme == 1) ? 'selected="selected"' : ''); ?>><?php echo $theme_row->name; ?></option>
  153. <?php
  154. }
  155. ?>
  156. </select>
  157. </p>
  158. <?php
  159. }
  160. ////////////////////////////////////////////////////////////////////////////////////////
  161. // Getters & Setters //
  162. ////////////////////////////////////////////////////////////////////////////////////////
  163. ////////////////////////////////////////////////////////////////////////////////////////
  164. // Private Methods //
  165. ////////////////////////////////////////////////////////////////////////////////////////
  166. ////////////////////////////////////////////////////////////////////////////////////////
  167. // Listeners //
  168. ////////////////////////////////////////////////////////////////////////////////////////
  169. }