SZGoogleActionDriveEmbed

The SZ - Google SZGoogleActionDriveEmbed class.

Defined (1)

The class is defined in the following location(s).

/classes/action/SZGoogleActionDriveEmbed.php  
  1. class SZGoogleActionDriveEmbed extends SZGoogleAction 
  2. /** 
  3. * Function to create the HTML code of the 
  4. * module connected to the shortcode required 
  5. */ 
  6.  
  7. function getShortcode($atts, $content=null)  
  8. return $this->getHTMLCode(shortcode_atts(array( 
  9. 'type' => '', // default value 
  10. 'id' => '', // default value 
  11. 'single' => '', // default value 
  12. 'gid' => '', // default value 
  13. 'range' => '', // default value 
  14. 'start' => '', // default value 
  15. 'loop' => '', // default value 
  16. 'delay' => '', // default value 
  17. 'folderview' => '', // default value 
  18. 'width' => '', // default value 
  19. 'height' => '', // default value 
  20. 'margintop' => '', // default value 
  21. 'marginright' => '', // default value 
  22. 'marginbottom' => '', // default value 
  23. 'marginleft' => '', // default value 
  24. 'marginunit' => '', // default value 
  25. 'action' => 'shortcode',  
  26. ), $atts), $content); 
  27.  
  28. /** 
  29. * Creating HTML code for the component called to 
  30. * be used in common for both widgets and shortcode 
  31. */ 
  32.  
  33. function getHTMLCode($atts=array(), $content=null) 
  34. if (!is_array($atts)) $atts = array(); 
  35.  
  36. // Extraction of the values **specified in shortcode, returned values 
  37. // **are contained in the variable names corresponding to the key 
  38.  
  39. extract(shortcode_atts(array( 
  40. 'type' => '', // default value 
  41. 'id' => '', // default value 
  42. 'single' => '', // default value 
  43. 'gid' => '', // default value 
  44. 'range' => '', // default value 
  45. 'start' => '', // default value 
  46. 'loop' => '', // default value 
  47. 'delay' => '', // default value 
  48. 'folderview' => '', // default value 
  49. 'width' => '', // default value 
  50. 'height' => '', // default value 
  51. 'margintop' => '', // default value 
  52. 'marginright' => '', // default value 
  53. 'marginbottom' => '', // default value 
  54. 'marginleft' => '', // default value 
  55. 'marginunit' => '', // default value 
  56. 'action' => '', // default value 
  57. ), $atts)); 
  58.  
  59. // Loading options for the configuration variables  
  60. // containing the default values **for shortcodes and widgets 
  61.  
  62. $options = $this->getModuleOptions('SZGoogleModuleDrive'); 
  63.  
  64. // I delete spaces added and execute the transformation in string 
  65. // lowercase for the control of special values **such as "auto" 
  66.  
  67. $id = trim($id); 
  68. $type = strtolower(trim($type)); 
  69. $single = strtolower(trim($single)); 
  70. $gid = strtolower(trim($gid)); 
  71. $range = strtolower(trim($range)); 
  72. $start = strtolower(trim($start)); 
  73. $loop = strtolower(trim($loop)); 
  74. $delay = strtolower(trim($delay)); 
  75. $folderview = strtolower(trim($folderview)); 
  76. $width = strtolower(trim($width)); 
  77. $height = strtolower(trim($height)); 
  78. $margintop = strtolower(trim($margintop)); 
  79. $marginright = strtolower(trim($marginright)); 
  80. $marginbottom = strtolower(trim($marginbottom)); 
  81. $marginleft = strtolower(trim($marginleft)); 
  82. $marginunit = strtolower(trim($marginunit)); 
  83.  
  84. // Se non specifico un URL valido per la creazione del bottone 
  85. // esco dalla funzione e ritorno una stringa vuota 
  86.  
  87. if (empty($id)) { return ''; } 
  88.  
  89. // Controllo le impostazioni che riguardano la dimensione del componente 
  90. // in quanto alcuni documenti hanno una dimensione di default specifica 
  91.  
  92. if ($action == 'widget')  
  93. if ($width == '') $width = $options['drive_embed_w_width']; 
  94. if ($height == '')  
  95. if ($type == 'document') $height = $options['drive_embed_w_height']; 
  96. if ($type == 'folder') $height = $options['drive_embed_w_height']; 
  97. if ($type == 'pdf') $height = $options['drive_embed_w_height']; 
  98. if ($type == 'forms') $height = $options['drive_embed_w_height']; 
  99. if ($type == 'presentation') $height = $options['drive_embed_w_height_p']; 
  100. if ($type == 'spreadsheet') $height = $options['drive_embed_w_height']; 
  101. if ($type == 'video') $height = $options['drive_embed_w_height_v']; 
  102.  
  103. // Controllo le impostazioni che riguardano la dimensione del componente 
  104. // in quanto alcuni documenti hanno una dimensione di default specifica 
  105.  
  106. } else { 
  107.  
  108. if ($width == '') $width = $options['drive_embed_s_width']; 
  109. if ($height == '')  
  110. if ($type == 'document') $height = $options['drive_embed_s_height']; 
  111. if ($type == 'folder') $height = $options['drive_embed_s_height']; 
  112. if ($type == 'pdf') $height = $options['drive_embed_s_height']; 
  113. if ($type == 'forms') $height = $options['drive_embed_s_height']; 
  114. if ($type == 'presentation') $height = $options['drive_embed_s_height_p']; 
  115. if ($type == 'spreadsheet') $height = $options['drive_embed_s_height']; 
  116. if ($type == 'video') $height = $options['drive_embed_s_height_v']; 
  117.  
  118. // Controllo le variabili usate come opzioni da utilizzare nel caso 
  119. // non esistano valori specificati o valori non coerenti con quelli ammessi 
  120.  
  121. if (!in_array($start , array('true', 'false'))) $start = 'false';  
  122. if (!in_array($loop , array('true', 'false'))) $loop = 'false';  
  123. if (!in_array($single, array('true', 'false'))) $single = 'false';  
  124.  
  125. if (!in_array($type, array('folder', 'document', 'presentation', 'spreadsheet', 'forms', 'pdf', 'video'))) $type = 'document';  
  126. if (!in_array($folderview, array('list', 'grid'))) $folderview = 'list';  
  127.  
  128. // Controllo dei campi numerici e verifica che non contengano 
  129. // caratteri non numerici, nel caso applico i valori di default 
  130.  
  131. if (!ctype_digit($delay)) $delay = '3'; 
  132. if (!ctype_digit($width)) $width = ''; 
  133. if (!ctype_digit($height))$height = ''; 
  134. if (!ctype_digit($gid)) $gid = '0'; 
  135.  
  136. // Configurazione delle variabili per la creazione del codice 
  137. // HTML da utilizzare rispettando le opzioni richieste 
  138.  
  139. if ($type == 'folder') $optionSRC = 'https://docs.google.com/embeddedfolderview?id=%s#%s'; 
  140. if ($type == 'document') $optionSRC = 'https://docs.google.com/document/d/%s/pub?embedded=true'; 
  141. if ($type == 'presentation') $optionSRC = 'https://docs.google.com/presentation/d/%s/embed?start=%s&loop=%s&delayms=%s'; 
  142. if ($type == 'spreadsheet') $optionSRC = 'https://docs.google.com/spreadsheet/pub?key=%s&output=html&widget=true&single=%s&gid=%s'; 
  143. if ($type == 'forms') $optionSRC = 'https://docs.google.com/forms/d/%s/viewform?embedded=true'; 
  144. if ($type == 'pdf') $optionSRC = 'https://docs.google.com/file/d/%s/preview'; 
  145. if ($type == 'video') $optionSRC = 'https://docs.google.com/file/d/%s/preview'; 
  146.  
  147. // Controllo la dimensione del widget e controllo formale dei valori numerici 
  148. // se trovo qualche incongruenza applico i valori di default prestabiliti 
  149.  
  150. if ($width == '') $width = "100%"; 
  151. if ($width == 'auto') $width = "100%"; 
  152.  
  153. if (in_array($type, array('presentation', 'video'))) { 
  154. if ($height == '') $height = '250'; 
  155. if ($height == 'auto') $height = '250'; 
  156. } else { 
  157. if ($height == '') $height = '400'; 
  158. if ($height == 'auto') $height = '400'; 
  159. }  
  160.  
  161. // Creazione del codice CSS per la composizione dei margini 
  162. // usando le opzioni specificate negli shortcode o nelle funzioni PHP 
  163.  
  164. $marginCSS = $this->getModuleObject('SZGoogleModuleDrive')->getStyleCSSfromMargins( 
  165. $margintop, $marginright, $marginbottom, $marginleft, $marginunit); 
  166.  
  167. // Creazione URL iframe in base alla tipologia rchiesta e i vari formati 
  168. // che differiscono dal numero e dal nome delle opzioni permesse. 
  169.  
  170. if ($type == 'folder') $optionSRC = sprintf($optionSRC, urlencode($id), urlencode($folderview)); 
  171. if ($type == 'document') $optionSRC = sprintf($optionSRC, urlencode($id)); 
  172. if ($type == 'spreadsheet') $optionSRC = sprintf($optionSRC, urlencode($id), urlencode($single), urlencode($gid), urlencode($range)); 
  173. if ($type == 'presentation') $optionSRC = sprintf($optionSRC, urlencode($id), urlencode($start), urlencode($loop), urlencode($delay.'000')); 
  174. if ($type == 'forms') $optionSRC = sprintf($optionSRC, urlencode($id)); 
  175. if ($type == 'pdf') $optionSRC = sprintf($optionSRC, urlencode($id)); 
  176. if ($type == 'video') $optionSRC = sprintf($optionSRC, urlencode($id)); 
  177.  
  178. if ($type == 'spreadsheet' && $range != '') $optionSRC .= "&range=".urlencode($range); 
  179.  
  180. // Apertura delle divisioni che rappresentano il wrapper 
  181. // comune per eventuali personalizzazioni di visualizzazione 
  182.  
  183. $HTML = '<div class="sz-google-drive">'; 
  184. $HTML .= '<div class="sz-google-drive-embed" style="'.$marginCSS.'">'; 
  185.  
  186. $HTML .= '<div class="sz-google-drive-embed-embed">'; 
  187. $HTML .= '<script type="text/javascript">'; 
  188. $HTML .= "var h='<'+'"; 
  189.  
  190. $HTML .= 'iframe src="'.$optionSRC.'"'; 
  191. $HTML .= ' width="' .$width .'"'; 
  192. $HTML .= ' height="'.$height.'"'; 
  193. $HTML .= ' frameborder="0"'; 
  194. $HTML .= ' style="border:none;"'; 
  195.  
  196. if ($type == 'presentation') { 
  197. $HTML .= ' allowfullscreen="true"'; 
  198. $HTML .= ' mozallowfullscreen="true"'; 
  199. $HTML .= ' webkitallowfullscreen="true"'; 
  200.  
  201. $HTML .= "></'+'iframe'+'>';"; 
  202. $HTML .= "document.write(h);"; 
  203. $HTML .= '</script>'; 
  204. $HTML .= '</div>'; 
  205.  
  206. // Chiusura delle divisioni che rappresentano il wrapper 
  207.  
  208. $HTML .= '</div>'; 
  209. $HTML .= '</div>'; 
  210.  
  211. // Return from the function with the whole string containing  
  212. // the HTML code for inserting the code in the page 
  213.  
  214. return $HTML;