| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) exit; // if direct access |
| 3 |
// add_shortcode('blockData', 'blockData'); |
| 4 |
// function blockData() |
| 5 |
// { |
| 6 |
// $build_dir = post_grid_plugin_dir . 'build/blocks'; |
| 7 |
// foreach (scandir($build_dir) as $result) { |
| 8 |
// $block_location = $build_dir . '/' . $result; |
| 9 |
// if (!is_dir($block_location) || '.' === $result || '..' === $result) { |
| 10 |
// continue; |
| 11 |
// } |
| 12 |
// $blockJson = $block_location . '/block.json'; |
| 13 |
// $json = file_get_contents($blockJson); |
| 14 |
// $jsonObj = json_decode($json); |
| 15 |
// //echo $jsonObj->name; |
| 16 |
// echo "registerBlockType('$jsonObj->name', { title: '$jsonObj->title', description: '$jsonObj->description' }); |
| 17 |
// "; |
| 18 |
// echo '<br>'; |
| 19 |
// } |
| 20 |
// } |
| 21 |
//add_image_size( 'custom-size', 435, 435, true ); |
| 22 |
//add_image_size( 'center-435', 220, 220, array( 'center', 'center' ) ); |
| 23 |
function eventQuery() |
| 24 |
{ |
| 25 |
$meta_query = array( |
| 26 |
'relation' => 'OR', |
| 27 |
array( |
| 28 |
'key' => 'event_date', |
| 29 |
'value' => 20220623, |
| 30 |
'compare' => '<', |
| 31 |
'type' => 'DATE', |
| 32 |
) |
| 33 |
); |
| 34 |
$args = array( |
| 35 |
'post_type' => 'post', |
| 36 |
'meta_query' => $meta_query, |
| 37 |
); |
| 38 |
$query = new WP_Query($args); |
| 39 |
$html = ob_start(); |
| 40 |
while ($query->have_posts()) : $query->the_post(); |
| 41 |
$post_id = get_the_ID(); |
| 42 |
$title = get_the_title($post_id); |
| 43 |
echo $title; |
| 44 |
echo '<br/>'; |
| 45 |
endwhile; |
| 46 |
return ob_get_clean(); |
| 47 |
} |
| 48 |
add_shortcode('eventQuery', 'eventQuery'); |
| 49 |
function post_grid_get_first_post($post_type = 'post') |
| 50 |
{ |
| 51 |
$args = array( |
| 52 |
'post_type' => $post_type, |
| 53 |
'post_status' => 'publish', |
| 54 |
'posts_per_page' => 1, |
| 55 |
); |
| 56 |
$post_id = ''; |
| 57 |
$wp_query = new WP_Query($args); |
| 58 |
if ($wp_query->have_posts()) : |
| 59 |
while ($wp_query->have_posts()) : $wp_query->the_post(); |
| 60 |
$product_id = get_the_id(); |
| 61 |
return $product_id; |
| 62 |
endwhile; |
| 63 |
endif; |
| 64 |
} |
| 65 |
function post_grid_recursive_sanitize_arr($array) |
| 66 |
{ |
| 67 |
foreach ($array as $key => &$value) { |
| 68 |
if (is_array($value)) { |
| 69 |
$value = post_grid_recursive_sanitize_arr($value); |
| 70 |
} else { |
| 71 |
if ($key == 'url') { |
| 72 |
$value = wp_kses_post($value); |
| 73 |
} else { |
| 74 |
$value = wp_kses_post($value); |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
return $array; |
| 79 |
} |
| 80 |
function post_grid_add_shortcode_column($columns) |
| 81 |
{ |
| 82 |
return array_merge( |
| 83 |
$columns, |
| 84 |
array('shortcode' => __('Shortcode', 'post-grid')) |
| 85 |
); |
| 86 |
} |
| 87 |
add_filter('manage_post_grid_posts_columns', 'post_grid_add_shortcode_column'); |
| 88 |
function post_grid_posts_shortcode_display($column, $post_id) |
| 89 |
{ |
| 90 |
if ($column == 'shortcode') { |
| 91 |
?> |
| 92 |
<input style="background:#bfefff" type="text" onClick="this.select();" value="[post_grid <?php echo 'id="' . esc_attr($post_id) . '"'; ?>]" /><br /> |
| 93 |
<textarea cols="50" rows="1" style="background:#bfefff" onClick="this.select();"><?php echo '<?php echo do_shortcode("[post_grid id='; |
| 94 |
echo "'" . esc_attr($post_id) . "']"; |
| 95 |
echo '"); ?>'; ?></textarea> |
| 96 |
<?php |
| 97 |
} |
| 98 |
} |
| 99 |
add_action('manage_post_grid_posts_custom_column', 'post_grid_posts_shortcode_display', 10, 2); |
| 100 |
function post_grid_get_media($item_post_id, $media_source, $featured_img_size, $thumb_linked) |
| 101 |
{ |
| 102 |
$item_post_permalink = apply_filters('post_grid_item_post_permalink', get_permalink($item_post_id)); |
| 103 |
$post_grid_post_settings = get_post_meta($item_post_id, 'post_grid_post_settings'); |
| 104 |
$item_thumb_placeholder = apply_filters('post_grid_item_thumb_placeholder', post_grid_plugin_url . 'assets/images/placeholder.png'); |
| 105 |
$custom_thumb_source = isset($post_grid_post_settings[0]['custom_thumb_source']) ? $post_grid_post_settings[0]['custom_thumb_source'] : $item_thumb_placeholder; |
| 106 |
$thumb_custom_url = isset($post_grid_post_settings[0]['thumb_custom_url']) ? $post_grid_post_settings[0]['thumb_custom_url'] : ''; |
| 107 |
$font_awesome_icon = isset($post_grid_post_settings[0]['font_awesome_icon']) ? $post_grid_post_settings[0]['font_awesome_icon'] : ''; |
| 108 |
$font_awesome_icon_color = isset($post_grid_post_settings[0]['font_awesome_icon_color']) ? $post_grid_post_settings[0]['font_awesome_icon_color'] : '#737272'; |
| 109 |
$font_awesome_icon_size = isset($post_grid_post_settings[0]['font_awesome_icon_size']) ? $post_grid_post_settings[0]['font_awesome_icon_size'] : '50px'; |
| 110 |
$custom_youtube_id = isset($post_grid_post_settings[0]['custom_youtube_id']) ? $post_grid_post_settings[0]['custom_youtube_id'] : ''; |
| 111 |
$custom_vimeo_id = isset($post_grid_post_settings[0]['custom_vimeo_id']) ? $post_grid_post_settings[0]['custom_vimeo_id'] : ''; |
| 112 |
$custom_dailymotion_id = isset($post_grid_post_settings[0]['custom_dailymotion_id']) ? $post_grid_post_settings[0]['custom_dailymotion_id'] : ''; |
| 113 |
$custom_mp3_url = isset($post_grid_post_settings[0]['custom_mp3_url']) ? $post_grid_post_settings[0]['custom_mp3_url'] : ''; |
| 114 |
$custom_soundcloud_id = isset($post_grid_post_settings[0]['custom_soundcloud_id']) ? $post_grid_post_settings[0]['custom_soundcloud_id'] : ''; |
| 115 |
$html_thumb = ''; |
| 116 |
if ($media_source == 'featured_image') { |
| 117 |
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id($item_post_id), $featured_img_size); |
| 118 |
$alt_text = get_post_meta(get_post_thumbnail_id($item_post_id), '_wp_attachment_image_alt', true); |
| 119 |
$thumb_url = isset($thumb['0']) ? $thumb['0'] : ''; |
| 120 |
if (!empty($thumb_url)) { |
| 121 |
if ($thumb_linked == 'yes') { |
| 122 |
if (!empty($thumb_custom_url)) { |
| 123 |
$html_thumb .= '<a href="' . esc_url_raw($thumb_custom_url) . '"><img alt="' . $alt_text . '" src="' . esc_url_raw(esc_url_raw($thumb_url)) . '" /></a>'; |
| 124 |
} else { |
| 125 |
$html_thumb .= '<a href="' . esc_url_raw($item_post_permalink) . '"><img alt="' . $alt_text . '" src="' . esc_url_raw($thumb_url) . '" /></a>'; |
| 126 |
} |
| 127 |
} else { |
| 128 |
$html_thumb .= '<img alt="' . $alt_text . '" src="' . esc_url_raw($thumb_url) . '" />'; |
| 129 |
} |
| 130 |
} else { |
| 131 |
$html_thumb .= ''; |
| 132 |
} |
| 133 |
} elseif ($media_source == 'empty_thumb') { |
| 134 |
if ($thumb_linked == 'yes') { |
| 135 |
$html_thumb .= '<a class="custom" href="' . esc_url_raw($item_post_permalink) . '"><img src="' . post_grid_plugin_url . 'assets/images/placeholder.png" /></a>'; |
| 136 |
} else { |
| 137 |
$html_thumb .= '<img class="custom" src="' . post_grid_plugin_url . 'assets/images/placeholder.png" />'; |
| 138 |
} |
| 139 |
} elseif ($media_source == 'custom_thumb') { |
| 140 |
if (!empty($custom_thumb_source)) { |
| 141 |
if ($thumb_linked == 'yes') { |
| 142 |
$html_thumb .= '<a href="' . esc_url_raw($item_post_permalink) . '"><img src="' . esc_url_raw($custom_thumb_source) . '" /></a>'; |
| 143 |
} else { |
| 144 |
$html_thumb .= '<img src="' . esc_url_raw($custom_thumb_source) . '" />'; |
| 145 |
} |
| 146 |
} |
| 147 |
} elseif ($media_source == 'font_awesome') { |
| 148 |
if (!empty($custom_thumb_source)) { |
| 149 |
if ($thumb_linked == 'yes') { |
| 150 |
$html_thumb .= '<a href="' . esc_url_raw($item_post_permalink) . '"><i style="color:' . $font_awesome_icon_color . ';font-size:' . $font_awesome_icon_size . '" class="fa ' . $font_awesome_icon . '"></i></a>'; |
| 151 |
} else { |
| 152 |
$html_thumb .= '<i style="color:' . $font_awesome_icon_color . ';font-size:' . $font_awesome_icon_size . '" class="fa ' . $font_awesome_icon . '"></i>'; |
| 153 |
} |
| 154 |
} |
| 155 |
} elseif ($media_source == 'first_image') { |
| 156 |
//global $post, $posts; |
| 157 |
$post = get_post($item_post_id); |
| 158 |
// $post_content = $post->post_content; |
| 159 |
$post_content = isset($post->post_content) ? ($post->post_content) : ''; |
| 160 |
$first_img = ''; |
| 161 |
ob_start(); |
| 162 |
ob_end_clean(); |
| 163 |
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post_content, $matches); |
| 164 |
if (!empty($matches[1][0])) |
| 165 |
$first_img = isset($matches[1][0]) ? $matches[1][0] : ''; |
| 166 |
if (empty($first_img)) { |
| 167 |
$html_thumb .= ''; |
| 168 |
} else { |
| 169 |
if ($thumb_linked == 'yes') { |
| 170 |
$html_thumb .= '<a href="' . esc_url_raw($item_post_permalink) . '"><img src="' . esc_url_raw($first_img) . '" /></a>'; |
| 171 |
} else { |
| 172 |
$html_thumb .= '<img src="' . esc_url_raw($first_img) . '" />'; |
| 173 |
} |
| 174 |
} |
| 175 |
} elseif ($media_source == 'first_gallery') { |
| 176 |
$gallery = get_post_gallery($item_post_id, false); |
| 177 |
if (!empty($gallery)) { |
| 178 |
$html_thumb .= '<div class="gallery owl-carousel">'; |
| 179 |
if (!empty($gallery['ids'])) { |
| 180 |
$ids = $gallery['ids']; |
| 181 |
$ids = explode(',', $ids); |
| 182 |
} else { |
| 183 |
$ids = array(); |
| 184 |
} |
| 185 |
foreach ($ids as $id) { |
| 186 |
$src = wp_get_attachment_url($id); |
| 187 |
$alt_text = get_post_meta($id, '_wp_attachment_image_alt', true); |
| 188 |
$html_thumb .= '<img src="' . esc_url_raw($src) . '" class="gallery-item" alt="' . $alt_text . '" />'; |
| 189 |
} |
| 190 |
$html_thumb .= '</div>'; |
| 191 |
} |
| 192 |
} elseif ($media_source == 'first_youtube') { |
| 193 |
$post = get_post($item_post_id); |
| 194 |
//$post_type = $post->post_type; |
| 195 |
$post_type = isset($post->post_type) ? $post->post_type : ''; |
| 196 |
if ($post_type == 'page') { |
| 197 |
$content = ''; |
| 198 |
$html_thumb .= ''; |
| 199 |
} else { |
| 200 |
//$content = do_shortcode($post->post_content); |
| 201 |
$content = isset($post->post_content) ? do_shortcode($post->post_content) : ''; |
| 202 |
} |
| 203 |
$content = apply_filters('the_content', $content); |
| 204 |
$embeds = get_media_embedded_in_content($content); |
| 205 |
foreach ($embeds as $key => $embed) { |
| 206 |
if (strchr($embed, 'youtube')) { |
| 207 |
$embed_youtube = $embed; |
| 208 |
} |
| 209 |
} |
| 210 |
if (!empty($embed_youtube)) { |
| 211 |
$html_thumb .= $embed_youtube; |
| 212 |
} else { |
| 213 |
$html_thumb .= ''; |
| 214 |
} |
| 215 |
} elseif ($media_source == 'first_vimeo') { |
| 216 |
$post = get_post($item_post_id); |
| 217 |
//$post_type = $post->post_type; |
| 218 |
$post_type = isset($post->post_type) ? $post->post_type : ''; |
| 219 |
if ($post_type == 'page') { |
| 220 |
$content = ''; |
| 221 |
$html_thumb .= ''; |
| 222 |
} else { |
| 223 |
//$content = do_shortcode($post->post_content); |
| 224 |
$content = isset($post->post_content) ? do_shortcode($post->post_content) : ''; |
| 225 |
} |
| 226 |
$embeds = get_media_embedded_in_content($content); |
| 227 |
foreach ($embeds as $key => $embed) { |
| 228 |
if (strchr($embed, 'vimeo')) { |
| 229 |
$embed_youtube = $embed; |
| 230 |
} |
| 231 |
} |
| 232 |
if (!empty($embed_youtube)) { |
| 233 |
$html_thumb .= $embed_youtube; |
| 234 |
} else { |
| 235 |
$html_thumb .= ''; |
| 236 |
} |
| 237 |
} elseif ($media_source == 'first_dailymotion') { |
| 238 |
$post = get_post($item_post_id); |
| 239 |
$post_type = isset($post->post_type) ? $post->post_type : ''; |
| 240 |
if ($post_type == 'page') { |
| 241 |
$content = ''; |
| 242 |
$html_thumb .= ''; |
| 243 |
} else { |
| 244 |
$content = isset($post->post_content) ? do_shortcode($post->post_content) : ''; |
| 245 |
} |
| 246 |
$content = apply_filters('the_content', $content); |
| 247 |
$embeds = get_media_embedded_in_content($content); |
| 248 |
foreach ($embeds as $key => $embed) { |
| 249 |
if (strchr($embed, 'dailymotion')) { |
| 250 |
$embed_youtube = $embed; |
| 251 |
} |
| 252 |
} |
| 253 |
if (!empty($embed_youtube)) { |
| 254 |
$html_thumb .= $embed_youtube; |
| 255 |
} else { |
| 256 |
$html_thumb .= ''; |
| 257 |
} |
| 258 |
} elseif ($media_source == 'first_mp3') { |
| 259 |
$post = get_post($item_post_id); |
| 260 |
$post_type = isset($post->post_type) ? $post->post_type : ''; |
| 261 |
if ($post_type == 'page') { |
| 262 |
$content = ''; |
| 263 |
$html_thumb .= ''; |
| 264 |
} else { |
| 265 |
$content = isset($post->post_content) ? do_shortcode($post->post_content) : ''; |
| 266 |
} |
| 267 |
$content = apply_filters('the_content', $content); |
| 268 |
$embeds = get_media_embedded_in_content($content); |
| 269 |
foreach ($embeds as $key => $embed) { |
| 270 |
if (strchr($embed, 'mp3')) { |
| 271 |
$embed_youtube = $embed; |
| 272 |
} |
| 273 |
} |
| 274 |
if (!empty($embed_youtube)) { |
| 275 |
$html_thumb .= $embed_youtube; |
| 276 |
} else { |
| 277 |
$html_thumb .= ''; |
| 278 |
} |
| 279 |
} elseif ($media_source == 'first_soundcloud') { |
| 280 |
$post = get_post($item_post_id); |
| 281 |
//$post_type = $post->post_type; |
| 282 |
$post_type = isset($post->post_type) ? $post->post_type : ''; |
| 283 |
if ($post_type == 'page') { |
| 284 |
$content = ''; |
| 285 |
$html_thumb .= ''; |
| 286 |
} else { |
| 287 |
// $content = do_shortcode($post->post_content); |
| 288 |
$content = isset($post->post_content) ? do_shortcode($post->post_content) : ''; |
| 289 |
} |
| 290 |
$content = apply_filters('the_content', $content); |
| 291 |
$embeds = get_media_embedded_in_content($content); |
| 292 |
foreach ($embeds as $key => $embed) { |
| 293 |
if (strchr($embed, 'soundcloud')) { |
| 294 |
$embed_youtube = $embed; |
| 295 |
} |
| 296 |
} |
| 297 |
if (!empty($embed_youtube)) { |
| 298 |
$html_thumb .= $embed_youtube; |
| 299 |
} else { |
| 300 |
$html_thumb .= ''; |
| 301 |
} |
| 302 |
} elseif ($media_source == 'custom_youtube') { |
| 303 |
if (!empty($custom_youtube_id)) { |
| 304 |
$html_thumb .= '<iframe frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/' . $custom_youtube_id . '?feature=oembed"></iframe>'; |
| 305 |
} |
| 306 |
} elseif ($media_source == 'custom_vimeo') { |
| 307 |
if (!empty($custom_vimeo_id)) { |
| 308 |
$html_thumb .= '<iframe frameborder="0" allowfullscreen="" mozallowfullscreen="" webkitallowfullscreen="" src="https://player.vimeo.com/video/' . $custom_vimeo_id . '"></iframe>'; |
| 309 |
} |
| 310 |
} elseif ($media_source == 'custom_dailymotion') { |
| 311 |
if (!empty($custom_dailymotion_id)) { |
| 312 |
$html_thumb .= '<iframe frameborder="0" allowfullscreen="" mozallowfullscreen="" webkitallowfullscreen="" src="//www.dailymotion.com/embed/video/' . $custom_dailymotion_id . '"></iframe>'; |
| 313 |
} |
| 314 |
} elseif ($media_source == 'custom_mp3') { |
| 315 |
if (!empty($custom_mp3_url)) { |
| 316 |
$html_thumb .= do_shortcode('[audio src="' . esc_url_raw($custom_mp3_url) . '"]'); |
| 317 |
} |
| 318 |
} elseif ($media_source == 'custom_video') { |
| 319 |
$video_html = ''; |
| 320 |
if (!empty($post_grid_post_settings[0]['custom_video_MP4'])) : |
| 321 |
$video_html .= 'mp4="' . $post_grid_post_settings[0]['custom_video_MP4'] . '"'; |
| 322 |
elseif (!empty($post_grid_post_settings[0]['custom_video_WEBM'])) : |
| 323 |
$video_html .= 'webm="' . $post_grid_post_settings[0]['custom_video_WEBM'] . '"'; |
| 324 |
elseif (!empty($post_grid_post_settings[0]['custom_video_OGV'])) : |
| 325 |
$video_html .= 'ogv="' . $post_grid_post_settings[0]['custom_video_OGV'] . '"'; |
| 326 |
endif; |
| 327 |
$html_thumb .= do_shortcode('[video ' . $video_html . '][/video]'); |
| 328 |
} elseif ($media_source == 'custom_soundcloud') { |
| 329 |
if (!empty($custom_soundcloud_id)) { |
| 330 |
$html_thumb .= '<iframe width="100%" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/' . $custom_soundcloud_id . '&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&visual=true"></iframe>'; |
| 331 |
} |
| 332 |
} |
| 333 |
return $html_thumb; |
| 334 |
} |
| 335 |
function post_grid_media($post_id, $args) |
| 336 |
{ |
| 337 |
$source_id = $args['source_id']; |
| 338 |
$source_args = $args['source_args']; |
| 339 |
$post_settings = $args['post_settings']; |
| 340 |
$thumb_linked = ''; |
| 341 |
$item_post_permalink = apply_filters('post_grid_item_post_permalink', get_permalink($post_id)); |
| 342 |
$html_thumb = ''; |
| 343 |
ob_start(); |
| 344 |
if ($source_id == 'featured_image') { |
| 345 |
$image_size = isset($source_args['image_size']) ? $source_args['image_size'] : 'large'; |
| 346 |
$link_to = isset($source_args['link_to']) ? $source_args['link_to'] : 'post_link'; |
| 347 |
$link_target = isset($source_args['link_target']) ? $source_args['link_target'] : ''; |
| 348 |
$thumb_custom_url = isset($post_settings['thumb_custom_url']) ? $post_settings['thumb_custom_url'] : ''; |
| 349 |
$post_thumbnail = get_the_post_thumbnail($post_id, $image_size); |
| 350 |
if (!empty($post_thumbnail)) { |
| 351 |
if ($link_to == 'post_link') { |
| 352 |
if (!empty($thumb_custom_url)) { |
| 353 |
$html_thumb .= '<a target="' . esc_attr($link_target) . '" href="' . esc_url($thumb_custom_url) . '">' . ($post_thumbnail) . '</a>'; |
| 354 |
} else { |
| 355 |
$html_thumb .= '<a target="' . esc_attr($link_target) . '" href="' . esc_url($item_post_permalink) . '">' . ($post_thumbnail) . '</a>'; |
| 356 |
} |
| 357 |
} else { |
| 358 |
$html_thumb .= $post_thumbnail; |
| 359 |
} |
| 360 |
} else { |
| 361 |
$html_thumb .= ''; |
| 362 |
} |
| 363 |
} elseif ($source_id == 'empty_thumb') { |
| 364 |
$link_to = isset($source_args['link_to']) ? $source_args['link_to'] : 'post_link'; |
| 365 |
$link_target = isset($source_args['link_target']) ? $source_args['link_target'] : ''; |
| 366 |
$default_thumb_src = isset($source_args['default_thumb_src']) ? $source_args['default_thumb_src'] : post_grid_plugin_url . 'assets/images/placeholder.png'; |
| 367 |
if ($link_to == 'post_link') { |
| 368 |
$html_thumb .= '<a target="' . esc_attr($link_target) . '" class="custom" href="' . esc_url($item_post_permalink) . '"><img src="' . esc_url($default_thumb_src) . '" /></a>'; |
| 369 |
} else { |
| 370 |
$html_thumb .= '<img class="custom" src="' . esc_url($default_thumb_src) . '" />'; |
| 371 |
} |
| 372 |
} elseif ($source_id == 'first_image') { |
| 373 |
$link_to = isset($source_args['link_to']) ? $source_args['link_to'] : 'post_link'; |
| 374 |
$link_target = isset($source_args['link_target']) ? $source_args['link_target'] : ''; |
| 375 |
//global $post, $posts; |
| 376 |
$post = get_post($post_id); |
| 377 |
//$post_content = $post->post_content; |
| 378 |
$post_content = isset($post->post_content) ? ($post->post_content) : ''; |
| 379 |
$first_img = ''; |
| 380 |
ob_start(); |
| 381 |
ob_end_clean(); |
| 382 |
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post_content, $matches); |
| 383 |
if (!empty($matches[1][0])) |
| 384 |
$first_img = isset($matches[1][0]) ? $matches[1][0] : ''; |
| 385 |
if (empty($first_img)) { |
| 386 |
$html_thumb .= ''; |
| 387 |
} else { |
| 388 |
if ($link_to == 'post_link') { |
| 389 |
$html_thumb .= '<a target="' . esc_attr($link_target) . '" href="' . esc_url($item_post_permalink) . '"><img src="' . esc_url($first_img) . '" /></a>'; |
| 390 |
} else { |
| 391 |
$html_thumb .= '<img src="' . esc_url($first_img) . '" />'; |
| 392 |
} |
| 393 |
} |
| 394 |
} elseif ($source_id == 'siteorigin_first_image') { |
| 395 |
$link_to = isset($source_args['link_to']) ? $source_args['link_to'] : 'post_link'; |
| 396 |
$link_target = isset($source_args['link_target']) ? $source_args['link_target'] : ''; |
| 397 |
//global $post, $posts; |
| 398 |
$post = get_post($post_id); |
| 399 |
/**$post_content = $post->post_content; */ |
| 400 |
$post_content = htmlspecialchars_decode($post->post_content, ENT_QUOTES); |
| 401 |
$first_img = ''; |
| 402 |
ob_start(); |
| 403 |
ob_end_clean(); |
| 404 |
if (class_exists('SiteOrigin_Widgets_Bundle')) { |
| 405 |
$output = str_replace(array('\/'), "\\", $post_content); // SiteOrigin adds \/ combinations |
| 406 |
$output = str_replace(array('src=\\'), 'src=', esc_url_raw($output)); // SiteOrigin adds \\ |
| 407 |
$output = str_replace(array('"url":'), ' <img src=', esc_url_raw($output)); //SiteOrigin does change the src to url |
| 408 |
$output = str_replace(array('<img src="'), '<img src="', esc_url_raw($output)); //SiteOrigin does add &< and " combinations which are not removed |
| 409 |
$output = str_replace(array('""'), '"', $output); // Remove this quot combination |
| 410 |
$output = str_replace(array('"'), '', $output); // Remove this quot combination |
| 411 |
/** search for post containing SiteOrigin image */ |
| 412 |
$findme = '"image":'; |
| 413 |
$start = strpos($post_content, $findme); |
| 414 |
$findme = ',"image_fallback"'; |
| 415 |
$end = strpos($post_content, $findme); |
| 416 |
$lengte = $end - $start; |
| 417 |
$search = (substr($post_content, $start, $lengte)); |
| 418 |
if ($search != "") { |
| 419 |
/** split the text */ |
| 420 |
$stringParts = explode(":", $search); |
| 421 |
$firstPart = isset($stringParts[0]) ? $stringParts[0] : ''; |
| 422 |
/** copy the post_id */ |
| 423 |
$ImagePost = isset($stringParts[1]) ? $stringParts[1] : ''; |
| 424 |
$getimage = wp_get_attachment_image($ImagePost, $size = 'medium'); |
| 425 |
if ($getimage != "") { |
| 426 |
$output = $getimage; |
| 427 |
} |
| 428 |
} |
| 429 |
} else { |
| 430 |
/** no SiteOrigin image so get the matches */ |
| 431 |
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post_content, $matches); |
| 432 |
} |
| 433 |
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*?>/i', $output, $matches); |
| 434 |
if ($output = '0') { |
| 435 |
$output = preg_match_all('/?<img src=[\'"]([^\'"]+)[\'"].*?>/i', $output, $matches); |
| 436 |
} |
| 437 |
if (!empty($matches[1][0])) { |
| 438 |
$first_img = isset($matches[1][0]) ? $matches[1][0] : ''; |
| 439 |
$last_char = $first_img[strlen($first_img) - 1]; // Check to see if a slash is at the end of the line |
| 440 |
if ($last_char == '\\') { |
| 441 |
$first_img = substr($first_img, 0, -1); |
| 442 |
} |
| 443 |
} |
| 444 |
if (empty($first_img)) { |
| 445 |
$html_thumb .= ''; |
| 446 |
} else { |
| 447 |
if ($link_to == 'post_link') { |
| 448 |
$html_thumb .= '<a target="' . esc_attr($link_target) . '" href="' . esc_url($item_post_permalink) . '"><img |
| 449 |
src="' . esc_url($first_img) . '" /></a>'; |
| 450 |
} else { |
| 451 |
$html_thumb .= '<img src="' . esc_url($first_img) . '" />'; |
| 452 |
} |
| 453 |
} |
| 454 |
} else { |
| 455 |
do_action('post_grid_media', $post_id, $args); |
| 456 |
} |
| 457 |
echo $html_thumb; |
| 458 |
$html_thumb = ob_get_clean(); |
| 459 |
return $html_thumb; |
| 460 |
} |
| 461 |
function post_grid_term_slug_list($post_id) |
| 462 |
{ |
| 463 |
$term_slug_list = ''; |
| 464 |
$post_taxonomies = get_post_taxonomies($post_id); |
| 465 |
foreach ($post_taxonomies as $taxonomy) { |
| 466 |
$term_list[] = wp_get_post_terms($post_id, $taxonomy, array("fields" => "all")); |
| 467 |
} |
| 468 |
if (!empty($term_list)) { |
| 469 |
foreach ($term_list as $term_key => $term) { |
| 470 |
foreach ($term as $term_id => $term) { |
| 471 |
$term_slug_list .= $term->slug . ' '; |
| 472 |
} |
| 473 |
} |
| 474 |
} |
| 475 |
return $term_slug_list; |
| 476 |
} |
| 477 |
function post_grid_layout_content_ajax() |
| 478 |
{ |
| 479 |
if (current_user_can('manage_options')) { |
| 480 |
$layout_key = sanitize_text_field($_POST['layout']); |
| 481 |
$class_post_grid_functions = new class_post_grid_functions(); |
| 482 |
$post_grid_layout_content = get_option('post_grid_layout_content'); |
| 483 |
if (empty($post_grid_layout_content)) { |
| 484 |
$layout = $class_post_grid_functions->layout_content($layout_key); |
| 485 |
} else { |
| 486 |
$layout = $post_grid_layout_content[$layout_key]; |
| 487 |
} |
| 488 |
?> |
| 489 |
<div class="<?php echo esc_attr($layout_key); ?>"> |
| 490 |
<?php |
| 491 |
foreach ($layout as $item_key => $item_info) { |
| 492 |
$item_key = $item_info['key']; |
| 493 |
?> |
| 494 |
<div class="item <?php echo esc_attr($item_key); ?>" style=" <?php echo esc_attr($item_info['css']); ?> "> |
| 495 |
<?php |
| 496 |
if ($item_key == 'thumb') { |
| 497 |
?> |
| 498 |
<img src="<?php echo esc_url(post_grid_plugin_url . 'assets/images/placeholder.png'); ?>" /> |
| 499 |
<?php |
| 500 |
} elseif ($item_key == 'title') { |
| 501 |
?> |
| 502 |
Lorem Ipsum is simply |
| 503 |
<?php |
| 504 |
} elseif ($item_key == 'excerpt') { |
| 505 |
?> |
| 506 |
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's |
| 507 |
standard dummy text |
| 508 |
<?php |
| 509 |
} elseif ($item_key == 'excerpt_read_more') { |
| 510 |
?> |
| 511 |
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's |
| 512 |
standard dummy text <a href="#">Read more</a> |
| 513 |
<?php |
| 514 |
} elseif ($item_key == 'read_more') { |
| 515 |
?> |
| 516 |
<a href="#">Read more</a> |
| 517 |
<?php |
| 518 |
} elseif ($item_key == 'post_date') { |
| 519 |
?> |
| 520 |
18/06/2015 |
| 521 |
<?php |
| 522 |
} elseif ($item_key == 'author') { |
| 523 |
?> |
| 524 |
PickPlugins |
| 525 |
<?php |
| 526 |
} elseif ($item_key == 'categories') { |
| 527 |
?> |
| 528 |
<a hidden="#">Category 1</a> <a hidden="#">Category 2</a> |
| 529 |
<?php |
| 530 |
} elseif ($item_key == 'tags') { |
| 531 |
?> |
| 532 |
<a hidden="#">Tags 1</a> <a hidden="#">Tags 2</a> |
| 533 |
<?php |
| 534 |
} elseif ($item_key == 'comments_count') { |
| 535 |
?> |
| 536 |
3 Comments |
| 537 |
<?php |
| 538 |
} |
| 539 |
// WooCommerce |
| 540 |
elseif ($item_key == 'wc_full_price') { |
| 541 |
?> |
| 542 |
<del>$45</del> - <ins>$40</ins> |
| 543 |
<?php |
| 544 |
} elseif ($item_key == 'wc_sale_price') { |
| 545 |
?> |
| 546 |
$45 |
| 547 |
<?php |
| 548 |
} elseif ($item_key == 'wc_regular_price') { |
| 549 |
?> |
| 550 |
$45 |
| 551 |
<?php |
| 552 |
} elseif ($item_key == 'wc_add_to_cart') { |
| 553 |
?> |
| 554 |
Add to Cart |
| 555 |
<?php |
| 556 |
} elseif ($item_key == 'wc_rating_star') { |
| 557 |
?> |
| 558 |
***** |
| 559 |
<?php |
| 560 |
} elseif ($item_key == 'wc_rating_text') { |
| 561 |
?> |
| 562 |
2 Reviews |
| 563 |
<?php |
| 564 |
} elseif ($item_key == 'wc_categories') { |
| 565 |
?> |
| 566 |
<a hidden="#">Category 1</a> <a hidden="#">Category 2</a> |
| 567 |
<?php |
| 568 |
} elseif ($item_key == 'wc_tags') { |
| 569 |
?> |
| 570 |
<a hidden="#">Tags 1</a> <a hidden="#">Tags 2</a> |
| 571 |
<?php |
| 572 |
} elseif ($item_key == 'edd_price') { |
| 573 |
?> |
| 574 |
$45 |
| 575 |
<?php |
| 576 |
} else { |
| 577 |
echo esc_html($item_info['name']); |
| 578 |
} |
| 579 |
?> |
| 580 |
</div> |
| 581 |
<?php |
| 582 |
} |
| 583 |
?> |
| 584 |
</div> |
| 585 |
<?php |
| 586 |
} |
| 587 |
die(); |
| 588 |
} |
| 589 |
add_action('wp_ajax_post_grid_layout_content_ajax', 'post_grid_layout_content_ajax'); |
| 590 |
|