/wp-content/plugins/sz-google/classes/widget/SZGoogleWidgetDriveEmbed.php

https://github.com/livinglab/openlab · PHP · 177 lines · 96 code · 32 blank · 49 comment · 15 complexity · ca3397b4ebf995fd1d94d311f4110205 MD5 · raw file

  1. <?php
  2. /**
  3. * Class for the definition of a widget that is
  4. * called by the class of the main module
  5. *
  6. * @package SZGoogle
  7. * @subpackage Widgets
  8. * @author Massimo Della Rovere
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. */
  11. if (!defined('SZ_PLUGIN_GOOGLE') or !SZ_PLUGIN_GOOGLE) die();
  12. // Before the definition of the class, check if there is a definition
  13. // with the same name or the same as previously defined in other script
  14. if (!class_exists('SZGoogleWidgetDriveEmbed'))
  15. {
  16. class SZGoogleWidgetDriveEmbed extends SZGoogleWidget
  17. {
  18. /**
  19. * Definition the constructor function, which is called
  20. * at the time of the creation of an instance of this class
  21. */
  22. function __construct()
  23. {
  24. parent::__construct('SZ-Google-Drive-Embed',__('SZ-Google - Drive Embed','sz-google'),array(
  25. 'classname' => 'sz-widget-google sz-widget-google-drive sz-widget-google-drive-embed',
  26. 'description' => ucfirst(__('google drive embed.','sz-google'))
  27. ));
  28. }
  29. /**
  30. * Generation of the HTML code of the widget
  31. * for the full display in the sidebar associated
  32. */
  33. function widget($args,$instance)
  34. {
  35. // Checking whether there are the variables that are used during the processing
  36. // the script and check the default values ​​in case they were not specified
  37. $options = $this->common_empty(array(
  38. 'title' => '', // default value
  39. 'type' => '', // default value
  40. 'id' => '', // default value
  41. 'width' => '', // default value
  42. 'height' => '', // default value
  43. 'folderview' => '', // default value
  44. 'single' => '', // default value
  45. 'gid' => '', // default value
  46. 'range' => '', // default value
  47. 'start' => '', // default value
  48. 'loop' => '', // default value
  49. 'delay' => '', // default value
  50. 'margintop' => '', // default value
  51. 'marginright' => '', // default value
  52. 'marginbottom' => '', // default value
  53. 'marginleft' => '', // default value
  54. 'marginunit' => '', // default value
  55. ),$instance);
  56. // Definition of the control variables of the widget, these values​
  57. // do not affect the items of basic but affect some aspects
  58. $controls = $this->common_empty(array(
  59. 'width_auto' => '', // default value
  60. 'height_auto' => '', // default value
  61. ),$instance);
  62. // Correction of the value of size is specified in
  63. // the case the automatically and then use javascript
  64. if ($controls['width_auto'] == '1') $options['width'] = 'auto';
  65. if ($controls['height_auto'] == '1') $options['height'] = 'auto';
  66. // Create the HTML code for the current widget recalling the basic
  67. // function which is also invoked by the corresponding shortcode
  68. $OBJC = new SZGoogleActionDriveEmbed();
  69. $HTML = $OBJC->getHTMLCode($options);
  70. // Output HTML code linked to the widget to
  71. // display call to the general standard for wrap
  72. echo $this->common_widget($args,$instance,$HTML);
  73. }
  74. /**
  75. * Changing parameters related to the widget FORM
  76. * with storing the values ​​directly in the database
  77. */
  78. function update($new_instance,$old_instance)
  79. {
  80. // Performing additional operations on fields of the
  81. // form widget before it is stored in the database
  82. return $this->common_update(array(
  83. 'title' => '0', // strip_tags
  84. 'type' => '1', // strip_tags
  85. 'id' => '1', // strip_tags
  86. 'folderview' => '1', // strip_tags
  87. 'single' => '1', // strip_tags
  88. 'gid' => '1', // strip_tags
  89. 'range' => '1', // strip_tags
  90. 'start' => '1', // strip_tags
  91. 'loop' => '1', // strip_tags
  92. 'delay' => '1', // strip_tags
  93. 'width' => '1', // strip_tags
  94. 'width_auto' => '1', // strip_tags
  95. 'height' => '1', // strip_tags
  96. 'height_auto' => '1', // strip_tags
  97. ),$new_instance,$old_instance);
  98. }
  99. /**
  100. * FORM display the widget in the management of
  101. * sidebar in the administration panel of wordpress
  102. */
  103. function form($instance)
  104. {
  105. // Creating arrays for list fields that must be
  106. // present in the form before calling wp_parse_args()
  107. $array = array(
  108. 'title' => '', // default value
  109. 'type' => '', // default value
  110. 'id' => '', // default value
  111. 'folderview' => '', // default value
  112. 'single' => '', // default value
  113. 'gid' => '', // default value
  114. 'range' => '', // default value
  115. 'start' => '', // default value
  116. 'loop' => '', // default value
  117. 'delay' => '', // default value
  118. 'width' => '', // default value
  119. 'width_auto' => '', // default value
  120. 'height' => '', // default value
  121. 'height_auto' => '', // default value
  122. );
  123. // Creating arrays for list of fields to be retrieved FORM
  124. // and loading the file with the HTML template to display
  125. extract(wp_parse_args($instance,$array),EXTR_OVERWRITE);
  126. // Reading of the options for the control of default values
  127. // be assigned to the widget when it is placed in the sidebar
  128. if ($object = SZGoogleModule::getObject('SZGoogleModuleDrive'))
  129. {
  130. $options = (object) $object->getOptions();
  131. if (!ctype_digit($width) and $width != 'auto') $width = $options->drive_embed_w_width;
  132. if (!ctype_digit($height) and $height != 'auto') $height = $options->drive_embed_w_height;
  133. }
  134. // Setting any of the default parameters for the
  135. // fields that contain invalid values ​​or inconsistent
  136. $DEFAULT = include(dirname(SZ_PLUGIN_GOOGLE_MAIN)."/options/sz_google_options_drive.php");
  137. if (!ctype_digit($width) or $width == 0) { $width = $DEFAULT['drive_embed_w_width']['value']; $width_auto = '1'; }
  138. if (!ctype_digit($height) or $height == 0) { $height = $DEFAULT['drive_embed_w_height']['value']; $height_auto = '1'; }
  139. // Calling the template for displaying the part
  140. // that concerns the administration panel (admin)
  141. @include(dirname(SZ_PLUGIN_GOOGLE_MAIN).'/admin/widgets/SZGoogleWidget.php');
  142. @include(dirname(SZ_PLUGIN_GOOGLE_MAIN).'/admin/widgets/' .__CLASS__.'.php');
  143. }
  144. }
  145. }