Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../wp-conte.../plugins/themify-.../themify
File: themify-utils.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/* * *************************************************************************
[2] Fix | Delete
*
[3] Fix | Delete
* ----------------------------------------------------------------------
[4] Fix | Delete
* DO NOT EDIT THIS FILE
[5] Fix | Delete
* ----------------------------------------------------------------------
[6] Fix | Delete
*
[7] Fix | Delete
* Copyright (C) Themify
[8] Fix | Delete
*
[9] Fix | Delete
* ----------------------------------------------------------------------
[10] Fix | Delete
*
[11] Fix | Delete
* ************************************************************************* */
[12] Fix | Delete
[13] Fix | Delete
if (!defined('ABSPATH'))
[14] Fix | Delete
exit; // Exit if accessed directly
[15] Fix | Delete
[16] Fix | Delete
/* Utilities
[17] Fix | Delete
/************************************************************************** */
[18] Fix | Delete
[19] Fix | Delete
function themify_clear_menu_cache() {
[20] Fix | Delete
global $wpdb;
[21] Fix | Delete
$wpdb->query("DELETE FROM $wpdb->options WHERE `option_name` LIKE ('_transient_tf_menu_%')");
[22] Fix | Delete
return Themify_Storage::deleteByPrefix('tf_menu_');
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Image Helper - Echoes themify_get_image
[28] Fix | Delete
* @param string $args Format string.
[29] Fix | Delete
*/
[30] Fix | Delete
function themify_image($args) {//deprecated use themify_get_image
[31] Fix | Delete
echo themify_get_image($args);
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
function themify_find_nearest_image_size(?int $attachment_id,int $width,int $height ) : string {
[35] Fix | Delete
$image_meta = wp_get_attachment_metadata( $attachment_id );
[36] Fix | Delete
$size = '';
[37] Fix | Delete
if ( ! empty( $image_meta['sizes'] ) ) {
[38] Fix | Delete
$last_pixel_count = 0;
[39] Fix | Delete
foreach ( $image_meta['sizes'] as $key => $value ) {
[40] Fix | Delete
/* image size is smaller than what we need, skip */
[41] Fix | Delete
if ( $width > $value['width'] || $height > $value['height'] ) {
[42] Fix | Delete
continue;
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
/* find smallest size */
[46] Fix | Delete
$pixels = $value['width'] * $value['height'];
[47] Fix | Delete
if ( $last_pixel_count === 0 || $pixels < $last_pixel_count ) {
[48] Fix | Delete
$last_pixel_count = $pixels;
[49] Fix | Delete
$size = $key;
[50] Fix | Delete
}
[51] Fix | Delete
}
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
return $size;
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Returns the post image, either from Themify Custom Panel fields or from WordPress Featured Image.
[59] Fix | Delete
* @param string|array $args Format string.
[60] Fix | Delete
* @return string String with <img> tag and optional content prepended and/or appended
[61] Fix | Delete
*/
[62] Fix | Delete
function themify_get_image($args):string {
[63] Fix | Delete
global $themify;
[64] Fix | Delete
/**
[65] Fix | Delete
* List of parameters
[66] Fix | Delete
* @var array
[67] Fix | Delete
*/
[68] Fix | Delete
$defaults = array(
[69] Fix | Delete
'src' => '',
[70] Fix | Delete
'class' => '',
[71] Fix | Delete
'style' => '',
[72] Fix | Delete
'preload' => false,
[73] Fix | Delete
'prefetch' => false,
[74] Fix | Delete
'lazy_load' => true,
[75] Fix | Delete
'is_slider' => false,
[76] Fix | Delete
'disable_responsive' => false,
[77] Fix | Delete
'w' => '', // width
[78] Fix | Delete
'h' => '', // height
[79] Fix | Delete
'before' => '',
[80] Fix | Delete
'after' => '',
[81] Fix | Delete
'alt' => '',
[82] Fix | Delete
'title' => '',
[83] Fix | Delete
'crop' => true,
[84] Fix | Delete
'field_name' => 'post_image,image,wp_thumb,feature_image',
[85] Fix | Delete
'urlonly' => false,
[86] Fix | Delete
'image_size' => '',
[87] Fix | Delete
'image_meta' => false,
[88] Fix | Delete
'f_image' => false,
[89] Fix | Delete
'attr' => array(),
[90] Fix | Delete
'fallback' => ''//when there is no image
[91] Fix | Delete
);
[92] Fix | Delete
if (is_string($args)) {
[93] Fix | Delete
$arr = array();
[94] Fix | Delete
parse_str($args, $arr);
[95] Fix | Delete
$args = array();
[96] Fix | Delete
foreach ($arr as $k => $v) {
[97] Fix | Delete
if ($v === 'true') {
[98] Fix | Delete
$args[$k] = true;
[99] Fix | Delete
} elseif ($v === 'false') {
[100] Fix | Delete
$args[$k] = false;
[101] Fix | Delete
} else {
[102] Fix | Delete
$args[$k] = $v;
[103] Fix | Delete
}
[104] Fix | Delete
}
[105] Fix | Delete
}
[106] Fix | Delete
$args+=$defaults;
[107] Fix | Delete
unset($defaults);
[108] Fix | Delete
/**
[109] Fix | Delete
* Post ID for single, query or archive views.
[110] Fix | Delete
* Page ID is stored separately in $themify->page_id.
[111] Fix | Delete
* @var string
[112] Fix | Delete
*/
[113] Fix | Delete
$post_id = get_the_ID();
[114] Fix | Delete
[115] Fix | Delete
/**
[116] Fix | Delete
* URL of the image to use
[117] Fix | Delete
* @var string
[118] Fix | Delete
*/
[119] Fix | Delete
$img_url = '';
[120] Fix | Delete
[121] Fix | Delete
/**
[122] Fix | Delete
* Image width
[123] Fix | Delete
* @var string
[124] Fix | Delete
*/
[125] Fix | Delete
$width = $args['w'];
[126] Fix | Delete
if ($width !== '') {
[127] Fix | Delete
$width = (int) $width;
[128] Fix | Delete
}
[129] Fix | Delete
/**
[130] Fix | Delete
* Image height
[131] Fix | Delete
* @var string
[132] Fix | Delete
*/
[133] Fix | Delete
$height = $args['h'];
[134] Fix | Delete
if ($height !== '') {
[135] Fix | Delete
$height = (int) $height;
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
$attachment_id = 0;
[139] Fix | Delete
[140] Fix | Delete
$is_disabled = themify_is_image_script_disabled();
[141] Fix | Delete
if (is_numeric($args['src'])) {
[142] Fix | Delete
$attachment_id = $args['src'];
[143] Fix | Delete
$img = wp_get_attachment_image_src($attachment_id, 'large');
[144] Fix | Delete
$args['src'] = !empty($img[0]) ? $img[0] : '';
[145] Fix | Delete
unset($img);
[146] Fix | Delete
} elseif ($args['fallback'] !== '' && empty($args['src']) && !has_post_thumbnail()) {
[147] Fix | Delete
$args['src'] = $args['fallback'];
[148] Fix | Delete
}
[149] Fix | Delete
if ($is_disabled === true) { // Use WP standard image sizes
[150] Fix | Delete
if (!empty($args['image_size'])) { // If image_size parameter is set
[151] Fix | Delete
$feature_size = $args['image_size'];
[152] Fix | Delete
} elseif (!empty($themify->image_size)) { // or if Themify::image_size is set
[153] Fix | Delete
$feature_size = $themify->image_size;
[154] Fix | Delete
} elseif (empty($themify->is_shortcode) && in_the_loop()) { // Main query area
[155] Fix | Delete
if (is_single()) {
[156] Fix | Delete
$feature_size = get_post_meta($post_id, 'feature_size', true);
[157] Fix | Delete
if (empty($feature_size) || 'blank' === $feature_size) {
[158] Fix | Delete
$feature_size = themify_get('setting-image_post_single_feature_size', null, true);
[159] Fix | Delete
}
[160] Fix | Delete
} elseif (!empty($themify->page_id) && !empty($themify->query_post_type) && themify_is_query_page()) {
[161] Fix | Delete
$feature_size = get_post_meta($themify->page_id, $themify->query_post_type . 'feature_size_page', true);
[162] Fix | Delete
if (empty($feature_size)) {
[163] Fix | Delete
$feature_size = null;
[164] Fix | Delete
}
[165] Fix | Delete
} elseif (is_archive() || is_tax() || is_search() || is_home()) {
[166] Fix | Delete
$feature_size = themify_get('setting-image_post_feature_size', null, true);
[167] Fix | Delete
}
[168] Fix | Delete
}
[169] Fix | Delete
if (!empty($args['src'])) {
[170] Fix | Delete
$attachment_id = themify_get_attachment_id_from_url($args['src']);
[171] Fix | Delete
}
[172] Fix | Delete
if (!isset($feature_size) || 'blank' === $feature_size) {
[173] Fix | Delete
$feature_size = $attachment_id && ! empty( $width ) && ! empty( $height ) ? themify_find_nearest_image_size( $attachment_id, $width, $height ) : '';
[174] Fix | Delete
if ( $feature_size === '' ) {
[175] Fix | Delete
$feature_size = apply_filters('themify_global_feature_size', themify_get('setting-global_feature_size', 'large', true));
[176] Fix | Delete
}
[177] Fix | Delete
}
[178] Fix | Delete
if (!empty($attachment_id)) {
[179] Fix | Delete
$tmp = wp_get_attachment_image_src($attachment_id, $feature_size);
[180] Fix | Delete
if (!empty($tmp)) {
[181] Fix | Delete
$img_url = $tmp[0];
[182] Fix | Delete
}
[183] Fix | Delete
unset($tmp);
[184] Fix | Delete
}
[185] Fix | Delete
if ($img_url === '') {
[186] Fix | Delete
// Set URL to use for final output.
[187] Fix | Delete
$img_url = empty($args['src']) ? themify_image_url(false, $feature_size) : $args['src'];
[188] Fix | Delete
$img_url = trim($img_url);
[189] Fix | Delete
// Fix for showing feature_image when Themify Image Script is disabled
[190] Fix | Delete
if ('' === $img_url) {
[191] Fix | Delete
foreach (explode(',', $args['field_name']) as $field) {
[192] Fix | Delete
if ($img_url = get_post_meta($post_id, trim($field), true))
[193] Fix | Delete
break;
[194] Fix | Delete
}
[195] Fix | Delete
}
[196] Fix | Delete
}
[197] Fix | Delete
} else { // Use Image Script
[198] Fix | Delete
if (empty($args['src'])) {
[199] Fix | Delete
if (has_post_thumbnail()) {
[200] Fix | Delete
$img_url = $width !== '' && $height !== '' ? ((int) get_post_thumbnail_id()) : get_the_post_thumbnail_url(); /* Image script works with thumbnail IDs as well as URLs, use ID which is faster */
[201] Fix | Delete
} elseif ('attachment' === get_post_type()) {
[202] Fix | Delete
$img_url = wp_get_attachment_url($post_id);
[203] Fix | Delete
} else {
[204] Fix | Delete
foreach (explode(',', $args['field_name']) as $field) {
[205] Fix | Delete
if ($img_url = get_post_meta($post_id, trim($field), true)) {
[206] Fix | Delete
break;
[207] Fix | Delete
}
[208] Fix | Delete
}
[209] Fix | Delete
}
[210] Fix | Delete
} else {
[211] Fix | Delete
$img_url = $args['src'];
[212] Fix | Delete
}
[213] Fix | Delete
if ($height !== '' && 0 === ((int) $height )) {
[214] Fix | Delete
$height = 0;
[215] Fix | Delete
$args['crop'] = false;
[216] Fix | Delete
}
[217] Fix | Delete
/** filter $img_url before it goes off to themify_do_img for processing * */
[218] Fix | Delete
$img_url = apply_filters('themify_get_image_before_do_img', $img_url, $width, $height, $args);
[219] Fix | Delete
[220] Fix | Delete
// Set URL to use for final output.
[221] Fix | Delete
$temp = themify_do_img((empty($attachment_id) ? $img_url : $attachment_id), $width, $height, (bool) $args['crop']);
[222] Fix | Delete
$img_url = $temp['url'];
[223] Fix | Delete
if ($temp['width'] !== '' && $temp['height'] !== '') {
[224] Fix | Delete
$width = (int) $temp['width'];
[225] Fix | Delete
$height = (int) $temp['height'];
[226] Fix | Delete
}
[227] Fix | Delete
// Get title/alt text by attachment id if it was returned.
[228] Fix | Delete
if (!$attachment_id && isset($temp['attachment_id'])) {
[229] Fix | Delete
$attachment_id = $temp['attachment_id'];
[230] Fix | Delete
}
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
if ($attachment_id) {
[234] Fix | Delete
$attachment_id = themify_maybe_translate_object_id($attachment_id);
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
// No image was defined, parse content to find the first image.
[238] Fix | Delete
if (empty($img_url) && ($args['f_image'] || themify_check('setting-auto_featured_image', true) )) {
[239] Fix | Delete
[240] Fix | Delete
$content = get_the_content();
[241] Fix | Delete
$upload_dir = themify_upload_dir('baseurl');
[242] Fix | Delete
foreach ( [ 'img', 'iframe' ] as $tag) {
[243] Fix | Delete
$count = substr_count($content, '<' . $tag);
[244] Fix | Delete
if ($count >= 1) {
[245] Fix | Delete
$start = strpos($content, '<' . $tag, 0);
[246] Fix | Delete
$pos = substr($content, $start);
[247] Fix | Delete
$end = strpos($pos, '>');
[248] Fix | Delete
$temp = themify_prep_image(substr($pos, 0, $end + 1));
[249] Fix | Delete
$src = $temp['src'];
[250] Fix | Delete
$parse = parse_url($src);
[251] Fix | Delete
if (!empty($parse['query'])) {
[252] Fix | Delete
$src = str_replace('?' . $parse['query'], '', $src);
[253] Fix | Delete
}
[254] Fix | Delete
$auto_image_url = isset($temp['src']) ? $temp['src'] : '';
[255] Fix | Delete
if (isset($temp['class'])) {
[256] Fix | Delete
$args['class'] .= ' ' . $temp['class'];
[257] Fix | Delete
}
[258] Fix | Delete
$args['alt'] = $temp['alt'];
[259] Fix | Delete
if ($is_disabled === true) {
[260] Fix | Delete
$img_url = themify_image_url(false, $feature_size, themify_get_attachment_id_from_url($auto_image_url, $upload_dir));
[261] Fix | Delete
if (empty($img_url)) {
[262] Fix | Delete
$img_url = esc_url($auto_image_url);
[263] Fix | Delete
}
[264] Fix | Delete
} elseif ($temp = themify_do_img($auto_image_url, $width, $height, (bool) $args['crop'])) {
[265] Fix | Delete
$img_url = $temp['url'];
[266] Fix | Delete
}
[267] Fix | Delete
break;
[268] Fix | Delete
}
[269] Fix | Delete
}
[270] Fix | Delete
unset($content, $upload_dir);
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
if (!empty($img_url)) {
[274] Fix | Delete
if (isset($temp['is_large']) && current_user_can('edit_post', $post_id)) {
[275] Fix | Delete
$args['class'] .= ' tf_large_img';
[276] Fix | Delete
} else {
[277] Fix | Delete
if ($args['preload'] !== false || $args['prefetch'] !== false) {
[278] Fix | Delete
Themify_Enqueue_Assets::addPreLoadMedia($img_url, $args['preload'] !== false ? 'preload' : 'prefetch');
[279] Fix | Delete
}
[280] Fix | Delete
themify_generateWebp($img_url);
[281] Fix | Delete
}
[282] Fix | Delete
unset($temp);
[283] Fix | Delete
if ($args['urlonly']) {
[284] Fix | Delete
$out = $img_url;
[285] Fix | Delete
} else {
[286] Fix | Delete
// Build final image
[287] Fix | Delete
$out = '<img src="' . $img_url . '"';
[288] Fix | Delete
if ($width !== '' && $width !== 0) {
[289] Fix | Delete
$out .= ' width="' . $width . '"';
[290] Fix | Delete
}
[291] Fix | Delete
if ($height !== '' && $height !== 0) {
[292] Fix | Delete
$out .= ' height="' . $height . '"';
[293] Fix | Delete
}
[294] Fix | Delete
if ($attachment_id != 0) {
[295] Fix | Delete
$args['class'] .= ' wp-post-image wp-image-' . $attachment_id; /* add attachment_id class to img tag */
[296] Fix | Delete
}
[297] Fix | Delete
if ($args['class'] !== '') {
[298] Fix | Delete
$out .= ' class="' . trim($args['class']) . '"';
[299] Fix | Delete
}
[300] Fix | Delete
if ($args['style'] !== '') {
[301] Fix | Delete
$out .= ' style="' . $args['style'] . '"';
[302] Fix | Delete
}
[303] Fix | Delete
$title = '';
[304] Fix | Delete
if (!empty($args['alt'])) {
[305] Fix | Delete
$out_alt = $args['alt'];
[306] Fix | Delete
} else {
[307] Fix | Delete
$out_alt = $attachment_id ? get_post_meta($attachment_id, '_wp_attachment_image_alt', true) : '';
[308] Fix | Delete
if (!$out_alt) {
[309] Fix | Delete
$out_alt = !empty($args['title']) ? $args['title'] : '';
[310] Fix | Delete
if (!$out_alt && $attachment_id) {
[311] Fix | Delete
$p = get_post($attachment_id);
[312] Fix | Delete
$out_alt = !empty($p) ? $p->post_title : '';
[313] Fix | Delete
$p = null;
[314] Fix | Delete
}
[315] Fix | Delete
if (!$out_alt) {
[316] Fix | Delete
$out_alt = the_title_attribute('echo=0');
[317] Fix | Delete
}
[318] Fix | Delete
$title = $out_alt;
[319] Fix | Delete
}
[320] Fix | Delete
}
[321] Fix | Delete
if($args['title'] !== false ){
[322] Fix | Delete
if ($title === '') {
[323] Fix | Delete
if (!empty($args['title'])) {
[324] Fix | Delete
$title = $args['title'];
[325] Fix | Delete
} elseif ($attachment_id) {
[326] Fix | Delete
$p = get_post($attachment_id);
[327] Fix | Delete
if (!empty($p)) {
[328] Fix | Delete
$title = $p->post_title;
[329] Fix | Delete
}
[330] Fix | Delete
$p = null;
[331] Fix | Delete
}
[332] Fix | Delete
}
[333] Fix | Delete
// Add title attribute only if explicitly set in $args
[334] Fix | Delete
if (!empty($title)) {
[335] Fix | Delete
$out .= ' title="' . esc_attr($title) . '"';
[336] Fix | Delete
}
[337] Fix | Delete
}
[338] Fix | Delete
if ($args['lazy_load'] === false || $args['lazy_load'] === 'eager') {
[339] Fix | Delete
$out .= ' data-tf-not-load="1"';
[340] Fix | Delete
if ($args['lazy_load'] === 'eager') {
[341] Fix | Delete
$out .= ' loading="eager" decoding="auto"';
[342] Fix | Delete
}
[343] Fix | Delete
}
[344] Fix | Delete
if (!empty($args['attr'])) {
[345] Fix | Delete
foreach ($args['attr'] as $k => $v) {
[346] Fix | Delete
$out .= ' ' . $k . '="' . esc_attr($v) . '"';
[347] Fix | Delete
}
[348] Fix | Delete
}
[349] Fix | Delete
if (!empty($out_alt)) {
[350] Fix | Delete
$out .= ' alt="' . esc_attr($out_alt) . '"';
[351] Fix | Delete
}
[352] Fix | Delete
$out .= '>';
[353] Fix | Delete
if ($attachment_id && $args['disable_responsive'] === false) {
[354] Fix | Delete
$out = function_exists('wp_filter_content_tags') ? wp_img_tag_add_srcset_and_sizes_attr($out, null, $attachment_id) // WP 5.5
[355] Fix | Delete
: wp_make_content_images_responsive($out);
[356] Fix | Delete
}
[357] Fix | Delete
if (($args['is_slider'] === true || $themify->post_layout === 'slider') && $args['lazy_load'] === true) {
[358] Fix | Delete
$out = themify_make_lazy($out, false);
[359] Fix | Delete
}
[360] Fix | Delete
if ($args['image_meta'] == true) {
[361] Fix | Delete
$out .= "<meta itemprop=\"width\" content=\"{$width}\"><meta itemprop=\"height\" content=\"{$height}\"><meta itemprop=\"url\" content=\"{$img_url}\">" . $out;
[362] Fix | Delete
}
[363] Fix | Delete
$out = $args['before'] . $out . $args['after'];
[364] Fix | Delete
}
[365] Fix | Delete
} else {
[366] Fix | Delete
$out = '';
[367] Fix | Delete
}
[368] Fix | Delete
[369] Fix | Delete
return $out;
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
if (!function_exists('themify_edit_link')) {
[373] Fix | Delete
[374] Fix | Delete
function themify_edit_link(string $title = '') : bool {
[375] Fix | Delete
static $is = null;
[376] Fix | Delete
if ($is === null) {
[377] Fix | Delete
$is = is_user_logged_in() && (!class_exists('Themify_Builder_Model',false) || !Themify_Builder::$frontedit_active === true) && !themify_is_rest();
[378] Fix | Delete
}
[379] Fix | Delete
if ($is === true) {
[380] Fix | Delete
if ($title === '') {
[381] Fix | Delete
$title = sprintf( __('Edit %s', 'themify'), '<span class="tf_hide">' . get_post_type_object( get_post_type() )->labels->singular_name . '</span>' );
[382] Fix | Delete
}
[383] Fix | Delete
edit_post_link($title, '<span class="edit-button tf_edit_post_' . get_the_ID() . '">', '</span>');
[384] Fix | Delete
}
[385] Fix | Delete
[386] Fix | Delete
return $is;
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
if (!function_exists('themify_image_url')) {
[392] Fix | Delete
[393] Fix | Delete
/**
[394] Fix | Delete
* Returns the featured image url
[395] Fix | Delete
* @param bool $echo Specify to echo or return the url
[396] Fix | Delete
* @param string $size The image size to return
[397] Fix | Delete
* @param null|int $attachment_id ID of image to load.
[398] Fix | Delete
* @return void|string
[399] Fix | Delete
*/
[400] Fix | Delete
function themify_image_url(bool $echo = false, string $size = 'full', $attachment_id = null):string {
[401] Fix | Delete
$url = '';
[402] Fix | Delete
if (has_post_thumbnail()) {
[403] Fix | Delete
$image = wp_get_attachment_image_src(get_post_thumbnail_id(), $size);
[404] Fix | Delete
$url = $image === false ? '' : $image[0];
[405] Fix | Delete
} elseif ($attachment_id !== null) {
[406] Fix | Delete
$image = wp_get_attachment_image_src($attachment_id, $size);
[407] Fix | Delete
if ($image) {
[408] Fix | Delete
$url = $image[0];
[409] Fix | Delete
}
[410] Fix | Delete
}
[411] Fix | Delete
$url = apply_filters('themify_image_url', $url);
[412] Fix | Delete
if ($echo) {
[413] Fix | Delete
echo esc_url($url);
[414] Fix | Delete
return '';
[415] Fix | Delete
}
[416] Fix | Delete
return $url;
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
}
[420] Fix | Delete
[421] Fix | Delete
/**
[422] Fix | Delete
* Image Helper - Prep Image
[423] Fix | Delete
* @param $tag
[424] Fix | Delete
* @return array
[425] Fix | Delete
*/
[426] Fix | Delete
function themify_prep_image(string $tag):array {
[427] Fix | Delete
$image = [];
[428] Fix | Delete
preg_match_all( '/(alt|title|src|class)=(("|\')[^("|\')]*("|\'))/i', $tag, $image_reg );
[429] Fix | Delete
foreach ( $image_reg[1] as $index => $attribute ) {
[430] Fix | Delete
$image[ $attribute ] = substr( $image_reg[2][ $index ], 1, -1 );
[431] Fix | Delete
}
[432] Fix | Delete
$image += [ 'src' => '', 'alt' => '', 'title' => '' ];
[433] Fix | Delete
[434] Fix | Delete
if (strpos($image['src'], 'youtube.com') !== false || strpos($image['src'], 'vimeo.com') !== false) {
[435] Fix | Delete
$image['src'] = themify_video_image($image['src']);
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
$image['src'] = preg_replace('/(-\d+x\d+)(?=\.\w{3,4})/', '', $image['src']);
[439] Fix | Delete
[440] Fix | Delete
return $image;
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
/**
[444] Fix | Delete
* Vimeo / Youtube Thumbnail grab
[445] Fix | Delete
*
[446] Fix | Delete
* @param $url
[447] Fix | Delete
*
[448] Fix | Delete
* @return string
[449] Fix | Delete
*/
[450] Fix | Delete
function themify_video_image(string $url):string {
[451] Fix | Delete
$image_url = parse_url($url);
[452] Fix | Delete
$return_url = '';
[453] Fix | Delete
if ($image_url['host'] === 'www.youtube.com' || $image_url['host'] === 'youtube.com') {
[454] Fix | Delete
parse_str($image_url['query'], $query);
[455] Fix | Delete
if (!empty($query['v'])) {
[456] Fix | Delete
$id = $query['v'];
[457] Fix | Delete
} else {
[458] Fix | Delete
$path = explode('/', $image_url['path']);
[459] Fix | Delete
$id = $path[count($path) - 1];
[460] Fix | Delete
}
[461] Fix | Delete
$return_url = 'https://img.youtube.com/vi/' . $id . '/hqdefault.jpg';
[462] Fix | Delete
} elseif ($image_url['host'] === 'www.vimeo.com' || $image_url['host'] === 'vimeo.com' || $image_url['host'] === 'player.vimeo.com') {
[463] Fix | Delete
parse_str($image_url['query'], $query);
[464] Fix | Delete
if (!empty($query['clip_id'])) {
[465] Fix | Delete
$id = $query['clip_id'];
[466] Fix | Delete
} else {
[467] Fix | Delete
$path = explode('/', $image_url['path']);
[468] Fix | Delete
$id = $path[(count($path) - 1)];
[469] Fix | Delete
}
[470] Fix | Delete
$content = Themify_Filesystem::get_contents('https://vimeo.com/api/v2/video/' . $id . '.php');
[471] Fix | Delete
if (!empty($content)) {
[472] Fix | Delete
$hash = unserialize($content);
[473] Fix | Delete
if (!empty($hash[0])) {
[474] Fix | Delete
$return_url = $hash[0]["thumbnail_large"];
[475] Fix | Delete
}
[476] Fix | Delete
}
[477] Fix | Delete
}
[478] Fix | Delete
return $return_url;
[479] Fix | Delete
}
[480] Fix | Delete
[481] Fix | Delete
/**
[482] Fix | Delete
* Checks if a value referenced by $var exists in theme settings or post meta data.
[483] Fix | Delete
* @param $var
[484] Fix | Delete
* @return bool
[485] Fix | Delete
*/
[486] Fix | Delete
function themify_check(string $var, bool $data_only = false):bool {
[487] Fix | Delete
$val = themify_get($var, null, $data_only);
[488] Fix | Delete
return $val !== null && $val !== '' && $val !== 'off';
[489] Fix | Delete
}
[490] Fix | Delete
[491] Fix | Delete
/**
[492] Fix | Delete
* Returns a value referenced by $var checking in theme settings or post meta data.
[493] Fix | Delete
* @param $var
[494] Fix | Delete
* @return mixed
[495] Fix | Delete
*/
[496] Fix | Delete
function themify_get(string $var, $default = null, bool $data_only = false) {
[497] Fix | Delete
$data = themify_get_data();
[498] Fix | Delete
if (isset($data[$var]) && $data[$var] !== '') {
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function