PageRenderTime 44ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/grand-media/module/phantom/init.php

https://gitlab.com/che234/smproducciones
PHP | 321 lines | 293 code | 18 blank | 10 comment | 72 complexity | 648647923fe53462276d940ae505f36f MD5 | raw file
  1. <?php
  2. /** @var $gmDB
  3. * @var $gmCore
  4. * @var $gmGallery
  5. * @var $gallery
  6. * @var $module
  7. * @var $settings
  8. * @var $terms
  9. * @var $gmedia
  10. * @var $is_bot
  11. **/
  12. $settings = array_merge($settings, array(
  13. 'ID' => $gallery['term_id'],
  14. 'module_dirurl' => $module['url'],
  15. 'ajax_actions' => array(
  16. 'comments' => array(
  17. 'action' => 'load_comments',
  18. 'data' => array('post_id' => 0)
  19. )
  20. ),
  21. ));
  22. $allsettings = array_merge($module['options'], $settings);
  23. $content = array();
  24. if(!isset($is_bot)) {
  25. $is_bot = false;
  26. }
  27. if(!isset($shortcode_raw)) {
  28. $shortcode_raw = false;
  29. }
  30. $tab = sanitize_title($gallery['name']);
  31. $base_url_host = parse_url($gmCore->upload['url'], PHP_URL_HOST);
  32. $i = 0;
  33. foreach($terms as $term) {
  34. foreach($gmedia[$term->term_id] as $item) {
  35. $meta = $gmDB->get_metadata('gmedia', $item->ID);
  36. $_metadata = isset($meta['_metadata'])? $meta['_metadata'][0] : array();
  37. $link_target = '';
  38. if($item->link) {
  39. $url_host = parse_url($item->link, PHP_URL_HOST);
  40. if($url_host == $base_url_host || empty($url_host)) {
  41. $link_target = '_self';
  42. } else {
  43. $link_target = '_blank';
  44. }
  45. }
  46. if(isset($meta['link_target'][0])) {
  47. $link_target = $meta['link_target'][0];
  48. }
  49. $image = $gmCore->gm_get_media_image($item->ID, 'web');
  50. $thumb = $gmCore->gm_get_media_image($item->ID, 'thumb');
  51. $type = explode('/', $item->mime_type);
  52. $type = $type[0];
  53. $ext = pathinfo($item->gmuid, PATHINFO_EXTENSION);
  54. if(!isset($_metadata['web'])) {
  55. $img_size = getimagesize($image);
  56. $_metadata['web'] = array_slice($img_size, 0, 2);
  57. $img_size = getimagesize($thumb);
  58. $_metadata['thumb'] = array_slice($img_size, 0, 2);
  59. }
  60. $content[$i] = array(
  61. 'id' => $item->ID,
  62. 'post_id' => $item->post_id,
  63. 'type' => $type,
  64. 'ext' => strtolower($ext),
  65. 'src' => "/{$gmGallery->options['folder'][$type]}/{$item->gmuid}",
  66. 'image' => $image,
  67. 'thumb' => $thumb,
  68. 'title' => $item->title,
  69. 'text' => str_replace(array("\r\n", "\r", "\n"), '', wpautop($item->description)),
  70. 'link' => $item->link,
  71. 'linkTarget' => $link_target,
  72. 'date' => $item->date,
  73. 'websize' => array_values($_metadata['web']),
  74. 'thumbsize' => array_values($_metadata['thumb'])
  75. );
  76. if(!empty($allsettings['viewsEnabled']) || !empty($allsettings['likesEnabled'])) {
  77. $content[$i]['views'] = empty($meta['views'][0])? 0 : (int)$meta['views'][0];
  78. if(!empty($allsettings['likesEnabled'])){
  79. $content[$i]['likes'] = empty($meta['likes'][0])? 0 : (int)$meta['likes'][0];
  80. }
  81. }
  82. if(!empty($allsettings['commentsEnabled'])) {
  83. if($item->post_id) {
  84. $cc = wp_count_comments($item->post_id);
  85. $content[$i]['cc'] = $cc->approved;
  86. } else {
  87. $content[$i]['cc'] = 0;
  88. }
  89. }
  90. if($allsettings['share_post_link']) {
  91. $content[$i]['post_link'] = get_permalink($item->post_id);
  92. }
  93. $i++;
  94. }
  95. }
  96. if(!empty($content)) {
  97. $content = array_values($content);
  98. $mfp_id = "#mfp_gm_{$gallery['term_id']}";
  99. $mfp_css = '';
  100. if(isset($settings['lightboxControlsColor'])) {
  101. $mfp_css .= "
  102. {$mfp_id} .mfp-arrow-right:after,
  103. {$mfp_id} .mfp-arrow-right .mfp-a {border-left-color:#{$settings['lightboxControlsColor']};}
  104. {$mfp_id} .mfp-arrow-left:after,
  105. {$mfp_id} .mfp-arrow-left .mfp-a {border-right-color:#{$settings['lightboxControlsColor']};}
  106. {$mfp_id} .mfp-close,
  107. {$mfp_id} .mfp-comments,
  108. {$mfp_id} .mfp-likes,
  109. {$mfp_id} .mfp-views,
  110. {$mfp_id} .mfp-share {color:#{$settings['lightboxControlsColor']};}
  111. {$mfp_id} .mfp-preloader {background-color:#{$settings['lightboxControlsColor']};}";
  112. }
  113. if(isset($settings['lightboxTitleColor'])) {
  114. $mfp_css .= "
  115. {$mfp_id} .mfp-title,
  116. {$mfp_id} .mfp-counter {color:#{$settings['lightboxTitleColor']};}";
  117. }
  118. if(isset($settings['lightboxTextColor'])) {
  119. $mfp_css .= "
  120. {$mfp_id} .mfp-description {color:#{$settings['lightboxTextColor']};}";
  121. }
  122. if(isset($settings['lightboxBGColor'])) {
  123. $mfp_css .= "
  124. {$mfp_id}_bg.mfp-bg {background-color:#{$settings['lightboxBGColor']};}";
  125. }
  126. if(isset($settings['lightboxBGAlpha'])) {
  127. $alpha = $settings['lightboxBGAlpha'] / 100;
  128. $mfp_css .= "
  129. {$mfp_id}_bg.mfp-bg {opacity:{$alpha};}
  130. {$mfp_id}_bg.mfp-zoom-in.mfp-bg {opacity:0}
  131. {$mfp_id}_bg.mfp-zoom-in.mfp-ready.mfp-bg {opacity:{$alpha};}
  132. {$mfp_id}_bg.mfp-zoom-in.mfp-removing.mfp-bg {opacity:0}";
  133. }
  134. if(isset($settings['commentsBGColor']) || isset($settings['commentsBGAlpha'])) {
  135. if(method_exists($gmCore, 'hex2rgb')) {
  136. $rgb = implode(',', $gmCore->hex2rgb($allsettings['commentsBGColor']));
  137. $alpha = $allsettings['commentsBGAlpha'] / 100;
  138. $mfp_css .= "
  139. {$mfp_id} .mfp-comments-content {background-color:rgba({$rgb},{$alpha});}";
  140. } else {
  141. $mfp_css .= "
  142. {$mfp_id} .mfp-comments-content {background-color:#{$allsettings['commentsBGColor']};}";
  143. }
  144. }
  145. if($mfp_css) {
  146. $settings['mfp_css'] = $mfp_css;
  147. }
  148. $cssid = "#GmediaGallery_{$gallery['term_id']}";
  149. $dcss = '';
  150. if(isset($settings['thumbWidth']) || isset($settings['thumbHeight']) || isset($settings['thumbWidthMobile']) || isset($settings['thumbHeightMobile'])) {
  151. $dcss .= "
  152. {$cssid} .gmPhantom_ThumbContainer {width:{$allsettings['thumbWidth']}px; height:{$allsettings['thumbHeight']}px;}
  153. {$cssid} .gmPhantom_MobileView .gmPhantom_ThumbContainer {width:{$allsettings['thumbWidthMobile']}px; height:{$allsettings['thumbHeightMobile']}px;}";
  154. }
  155. if(isset($settings['thumbPadding'])) {
  156. $dcss .= "
  157. {$cssid} .gmPhantom_ThumbContainer {padding:{$allsettings['thumbPadding']}px;}";
  158. }
  159. if(isset($settings['thumbBG'])) {
  160. if('' == $settings['thumbBG']) {
  161. $dcss .= "
  162. {$cssid} .gmPhantom_ThumbContainer {background-color:transparent;}";
  163. } else {
  164. $dcss .= "
  165. {$cssid} .gmPhantom_ThumbContainer,
  166. {$cssid} .gmPhantom_LabelBottom .gmPhantom_ThumbLabel {background-color:#{$settings['thumbBG']};}";
  167. }
  168. }
  169. if(isset($settings['thumbAlpha'])) {
  170. $alpha = $settings['thumbAlpha'] / 100;
  171. $dcss .= "
  172. {$cssid} .gmPhantom_ThumbContainer .gmPhantom_Thumb {opacity:{$alpha};}";
  173. }
  174. if(isset($settings['thumbAlphaHover'])) {
  175. $alpha = $settings['thumbAlphaHover'] / 100;
  176. $dcss .= "
  177. {$cssid} .gmPhantom_ThumbContainer:hover .gmPhantom_Thumb {opacity:{$alpha};}";
  178. }
  179. if(isset($settings['thumbBorderSize']) || isset($settings['thumbBorderColor'])) {
  180. if((int)$settings['thumbBorderSize']) {
  181. $dcss .= "
  182. {$cssid} .gmPhantom_ThumbContainer {border:{$allsettings['thumbBorderSize']}px solid #{$allsettings['thumbBorderColor']};}";
  183. } else {
  184. $dcss .= "
  185. {$cssid} .gmPhantom_ThumbContainer {border:none;}";
  186. }
  187. }
  188. if(isset($settings['thumbBorderSize'])) {
  189. if((int)$settings['thumbBorderSize'] > 1) {
  190. $dcss .= "
  191. {$cssid} .gmPhantom_ThumbContainer {box-shadow:0 0 5px -2px;}";
  192. } else {
  193. $dcss .= "
  194. {$cssid} .gmPhantom_ThumbContainer {box-shadow:none;}";
  195. }
  196. }
  197. if(isset($settings['label8TextColor'])) {
  198. $dcss .= "
  199. {$cssid} .gmPhantom_ThumbLabel {color:#{$allsettings['label8TextColor']};}";
  200. }
  201. if(isset($settings['label8LinkColor'])) {
  202. $dcss .= "
  203. {$cssid} .gmPhantom_ThumbLabel a {color:#{$allsettings['label8LinkColor']};}";
  204. }
  205. if(isset($settings['labelTextColor'])) {
  206. $dcss .= "
  207. {$cssid} .gmPhantom_LabelInside .gmPhantom_ThumbLabel,
  208. {$cssid} .gmPhantom_LabelHover .gmPhantom_ThumbLabel {color:#{$allsettings['labelTextColor']};}";
  209. }
  210. if(isset($settings['labelLinkColor'])) {
  211. $dcss .= "
  212. {$cssid} .gmPhantom_LabelInside .gmPhantom_ThumbLabel a,
  213. {$cssid} .gmPhantom_LabelHover .gmPhantom_ThumbLabel a {color:#{$allsettings['labelLinkColor']};}";
  214. }
  215. if($dcss) {
  216. $customCSS = $dcss . $customCSS;
  217. }
  218. $json_settings = json_encode($settings);
  219. ?>
  220. <?php if(!$is_bot) {
  221. if($shortcode_raw) {
  222. echo '<pre style="display:none">';
  223. }
  224. ?>
  225. <script type="text/javascript">
  226. jQuery(function() {
  227. var settings = <?php echo $json_settings; ?>;
  228. var content = <?php echo json_encode($content); ?>;
  229. jQuery('#GmediaGallery_<?php echo $gallery['term_id'] ?>').gmPhantom([content, settings]);
  230. });
  231. </script><?php
  232. if($shortcode_raw) {
  233. echo '</pre>';
  234. }
  235. }
  236. ?>
  237. <div class="gmPhantom_Container noLightbox delay">
  238. <div class="gmPhantom_Background"></div>
  239. <?php
  240. $thumbsWrapper_class = (int)$allsettings['thumbScale']? ' gmPhantom_ThumbScale' : '';
  241. if('label' == $allsettings['thumbsInfo']) {
  242. if((int)$allsettings['labelOnHover']) {
  243. $thumbsWrapper_class .= ' gmPhantom_LabelHover';
  244. } else {
  245. $thumbsWrapper_class .= ' gmPhantom_LabelInside';
  246. }
  247. } elseif('label_bottom' == $allsettings['thumbsInfo']) {
  248. $thumbsWrapper_class .= ' gmPhantom_LabelBottom';
  249. } elseif('tooltip' == $allsettings['thumbsInfo']) {
  250. $thumbsWrapper_class .= ' gmPhantom_LabelTooltip';
  251. } elseif('none' == $allsettings['thumbsInfo']) {
  252. $thumbsWrapper_class .= ' gmPhantom_LabelNone';
  253. }
  254. ?>
  255. <div class="gmPhantom_thumbsWrapper<?php echo $thumbsWrapper_class; ?>">
  256. <?php $i = 0;
  257. $wrapper_r = $allsettings['thumbWidth'] / $allsettings['thumbHeight'];
  258. $mobile_wrapper_r = $allsettings['thumbWidthMobile'] / $allsettings['thumbHeightMobile'];
  259. foreach($content as $item) {
  260. $thumb_r = $item['thumbsize'][0] / $item['thumbsize'][1];
  261. if($wrapper_r < $thumb_r) {
  262. $orientation = 'landscape';
  263. $margin = 'margin:0 0 0 -' . floor(($allsettings['thumbHeight'] * $thumb_r - $allsettings['thumbWidth']) / $allsettings['thumbWidth'] * 50) . '%;';
  264. } else {
  265. $orientation = 'portrait';
  266. $margin = 'margin:-' . floor(($allsettings['thumbWidth'] / $thumb_r - $allsettings['thumbHeight']) / $allsettings['thumbHeight'] * 25) . '% 0 0 0;';
  267. }
  268. $class = '';
  269. $style = 'left:50%; top:50%; transform:translate(-50%, -50%);'
  270. ?>
  271. <div class="gmPhantom_ThumbContainer gmPhantom_ThumbLoader<?php echo(!in_array($item['type'], array('image'))? " mfp-iframe" : ''); ?>" data-ratio="<?php echo $thumb_r; ?>" data-no="<?php echo $i++; ?>"><?php
  272. ?><a href="<?php echo $gmCore->upload['url'] . $item['src']; ?>" class="gmPhantom_Thumb"><img style="<?php echo $style; ?>" src="<?php echo $item['thumb']; ?>" alt="<?php echo esc_attr($item['title']); ?>"/></a><?php
  273. if(in_array($allsettings['thumbsInfo'], array('label', 'label_bottom')) && ($item['title'] != '')) {
  274. if(!empty($item['link'])) {
  275. $item['title'] = "<a href='{$item['link']}' target='{$item['linkTarget']}'>{$item['title']}</a>";
  276. }
  277. ?>
  278. <div class="gmPhantom_ThumbLabel"><?php echo $item['title']; ?></div>
  279. <div style="display:none;" class="gmPhantom_ThumbCaption"><?php echo $item['text']; ?></div><?php
  280. } ?></div><?php
  281. } ?><br style="clear:both;"/>
  282. </div>
  283. <?php if(isset($counts['total_pages']) && !empty($counts['total_pages']) && 1 < intval($counts['total_pages'])){ ?>
  284. <div class="gmPhantom_pagination">
  285. <?php
  286. $params = $_GET;
  287. $gmid = 'gm' . $gallery['term_id'];
  288. $counts['total_pages'] = (int)$counts['total_pages'];
  289. for($x = 1; $x <= $counts['total_pages']; $x++){
  290. $li_class = $x == $counts['current_page']? ' gmPhantom_current_page' : '';
  291. $params[$gmid]['page'] = $x;
  292. $new_query_string = http_build_query($params);
  293. $self = '?' . urldecode($new_query_string);
  294. echo "<a class='gmPhantom_pager{$li_class}' href='{$self}'>{$x}</a>";
  295. }
  296. ?>
  297. </div>
  298. <?php } ?>
  299. </div>
  300. <?php
  301. } else {
  302. echo '<div class="gmedia-no-files">' . GMEDIA_GALLERY_EMPTY . '</div>';
  303. }