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.../httpdocs/clone/wp-conte.../plugins/themify-.../classes
File: class-themify-builder-library-item.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* This file defines Builder Library Items designs and parts.
[3] Fix | Delete
*
[4] Fix | Delete
* Themify_Builder_Row class register post type for Library Items designs and Parts
[5] Fix | Delete
* Custom metabox, and load Library Items designs / parts.
[6] Fix | Delete
*
[7] Fix | Delete
*
[8] Fix | Delete
* @package Themify_Builder
[9] Fix | Delete
* @subpackage Themify_Builder/classes
[10] Fix | Delete
*/
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* The Builder Library Items class.
[14] Fix | Delete
*
[15] Fix | Delete
* This class register post type for Library Items designs and Parts
[16] Fix | Delete
* Custom metabox, and load Library Items designs / parts
[17] Fix | Delete
*
[18] Fix | Delete
*
[19] Fix | Delete
* @package Themify_Builder
[20] Fix | Delete
* @subpackage Themify_Builder/classes
[21] Fix | Delete
* @author Themify
[22] Fix | Delete
*/
[23] Fix | Delete
class Themify_Builder_Library_Items {
[24] Fix | Delete
[25] Fix | Delete
private const POST_TYPE_NAMES = array('row' => 'library_rows', 'module' => 'library_modules', 'part' =>Themify_Builder_Layouts::LAYOUT_PART_SLUG);
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Constructor
[29] Fix | Delete
*
[30] Fix | Delete
* @access public
[31] Fix | Delete
*/
[32] Fix | Delete
public static function init() {
[33] Fix | Delete
if (themify_is_ajax()) {
[34] Fix | Delete
// Ajax Hooks
[35] Fix | Delete
add_action('wp_ajax_tb_save_custom_item', array(__CLASS__, 'save_custom_item_ajaxify'));
[36] Fix | Delete
add_action('wp_ajax_tb_get_library_items', array(__CLASS__, 'list_library_items_ajax'));
[37] Fix | Delete
add_action('wp_ajax_tb_get_library_item', array(__CLASS__, 'get_item'));
[38] Fix | Delete
add_action('wp_ajax_tb_remove_library_item', array(__CLASS__, 'remove_library_item_ajax'));
[39] Fix | Delete
add_action('wp_ajax_tb_layout_part_swap', array(__CLASS__, 'layout_part_edit'));
[40] Fix | Delete
}
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Save as Row
[45] Fix | Delete
*
[46] Fix | Delete
* @access public
[47] Fix | Delete
*/
[48] Fix | Delete
public static function save_custom_item_ajaxify() {
[49] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[50] Fix | Delete
$response = array(
[51] Fix | Delete
'status' => 'failed',
[52] Fix | Delete
'msg' => __('Something went wrong', 'themify')
[53] Fix | Delete
);
[54] Fix | Delete
if (!empty($_POST['item']) &&current_user_can( 'edit_posts' )) {
[55] Fix | Delete
[56] Fix | Delete
$is_layout_part = !empty($_POST['item_layout_save']) && $_POST['item_layout_save'] !== 'false';
[57] Fix | Delete
$data = array(
[58] Fix | Delete
'type' => $_POST['type'],
[59] Fix | Delete
'item' => $is_layout_part ? json_decode(stripslashes_deep($_POST['item']), true) : $_POST['item']
[60] Fix | Delete
);
[61] Fix | Delete
$user = get_current_user_id();
[62] Fix | Delete
if (!empty($_POST['item_title_field'])) {
[63] Fix | Delete
$title = sanitize_text_field($_POST['item_title_field']);
[64] Fix | Delete
} else {
[65] Fix | Delete
$title = $is_layout_part ? __('Saved Item Layout Part', 'themify') : $user . ' Saved-' . ucwords(sanitize_text_field($data['type']));
[66] Fix | Delete
}
[67] Fix | Delete
$post_type = $is_layout_part ? self::POST_TYPE_NAMES['part'] : self::POST_TYPE_NAMES[$data['type']];
[68] Fix | Delete
$new_id = wp_insert_post(array(
[69] Fix | Delete
'post_status' => current_user_can( 'publish_posts' ) ? 'publish' : 'draft',
[70] Fix | Delete
'post_type' => $post_type,
[71] Fix | Delete
'post_author' => $user,
[72] Fix | Delete
'post_title' => $title,
[73] Fix | Delete
'post_content' => $is_layout_part ? '' : $data['item']
[74] Fix | Delete
));
[75] Fix | Delete
if ($new_id) {
[76] Fix | Delete
if ($is_layout_part) {
[77] Fix | Delete
$response = self::save_as_layout_part($data, $new_id);
[78] Fix | Delete
} else {
[79] Fix | Delete
$response['status'] = 'success';
[80] Fix | Delete
unset($response['msg']);
[81] Fix | Delete
}
[82] Fix | Delete
if (!empty($_POST['usedGS'])) {
[83] Fix | Delete
update_post_meta($new_id, 'themify_used_global_styles', $_POST['usedGS']);
[84] Fix | Delete
}
[85] Fix | Delete
$response['post_type'] = $post_type;
[86] Fix | Delete
$response['id'] = $new_id;
[87] Fix | Delete
$response['post_title'] = $title;
[88] Fix | Delete
}
[89] Fix | Delete
}
[90] Fix | Delete
wp_send_json($response);
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Save the item as Layout Part.
[95] Fix | Delete
*
[96] Fix | Delete
* @access public
[97] Fix | Delete
* Return Array
[98] Fix | Delete
*/
[99] Fix | Delete
protected static function save_as_layout_part(array $data, $new_id) {
[100] Fix | Delete
[101] Fix | Delete
if ($data['type'] === 'module') {
[102] Fix | Delete
$row = array('cols' => array(0 => array('grid_class' => 'col-full', 'modules' => array($data['item']))));
[103] Fix | Delete
ThemifyBuilder_Data_Manager::save_data(array($row), $new_id);
[104] Fix | Delete
} else {
[105] Fix | Delete
ThemifyBuilder_Data_Manager::save_data(array($data['item']), $new_id);
[106] Fix | Delete
}
[107] Fix | Delete
$post = get_post($new_id);
[108] Fix | Delete
return array(
[109] Fix | Delete
'status' => 'success',
[110] Fix | Delete
'post_name' => $post->post_name
[111] Fix | Delete
);
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
/**
[115] Fix | Delete
* Get layout part module settings.
[116] Fix | Delete
*
[117] Fix | Delete
* @access Private
[118] Fix | Delete
* Retrun Array
[119] Fix | Delete
*/
[120] Fix | Delete
protected static function get_layout_part_model($post, string $type):array {
[121] Fix | Delete
if (!is_object($post)) {
[122] Fix | Delete
$post = get_post($post);
[123] Fix | Delete
}
[124] Fix | Delete
$output = array(
[125] Fix | Delete
'mod_name' => 'layout-part',
[126] Fix | Delete
'mod_settings' => array(
[127] Fix | Delete
'selected_layout_part' => $post->post_name
[128] Fix | Delete
)
[129] Fix | Delete
);
[130] Fix | Delete
if ($type === 'row') {
[131] Fix | Delete
$output = array('cols' => array(0 => array('grid_class' => 'col-full', 'modules' => array($output))));
[132] Fix | Delete
}
[133] Fix | Delete
return $output;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* Get list of Saved Layout Parts in library.
[138] Fix | Delete
*
[139] Fix | Delete
* @access Private
[140] Fix | Delete
* Retrun Array or String
[141] Fix | Delete
*/
[142] Fix | Delete
protected static function get_list(string $type = 'all') {
[143] Fix | Delete
global $wpdb;
[144] Fix | Delete
$vals = $type === 'all' ? self::POST_TYPE_NAMES : array(self::POST_TYPE_NAMES[$type]);
[145] Fix | Delete
$post_type = array();
[146] Fix | Delete
foreach ($vals as $v) {
[147] Fix | Delete
$post_type[] = "'" . esc_sql($v) . "'";
[148] Fix | Delete
}
[149] Fix | Delete
$post_type = implode(',', $post_type);
[150] Fix | Delete
return $wpdb->get_results("SELECT post_name,post_title,post_type,id FROM {$wpdb->posts} WHERE post_type IN(" . $post_type . ") and post_status = 'publish' ORDER BY post_title ASC ", ARRAY_A);
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
/**
[154] Fix | Delete
* Get list of Saved Rows & Modules in library.
[155] Fix | Delete
*
[156] Fix | Delete
* @access public
[157] Fix | Delete
*/
[158] Fix | Delete
public static function list_library_items_ajax() {
[159] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[160] Fix | Delete
$part = !empty($_POST['part']) ? $_POST['part'] : 'part';
[161] Fix | Delete
if (($part !== 'all' && !isset(self::POST_TYPE_NAMES[$part])) || !isset($_POST['bid']) || !current_user_can( 'read_post',$_POST['bid'] )) {
[162] Fix | Delete
wp_die();
[163] Fix | Delete
}
[164] Fix | Delete
wp_send_json(self::get_list($part));
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
public static function remove_library_item_ajax() {
[168] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[169] Fix | Delete
$status = 0;
[170] Fix | Delete
if (!empty( $_POST['id'] ) && current_user_can( 'delete_post', $_POST['id'] ) ) {
[171] Fix | Delete
$id = (int) $_POST['id'];
[172] Fix | Delete
$post = get_post($id);
[173] Fix | Delete
if (in_array($post->post_type, self::POST_TYPE_NAMES, true)) {
[174] Fix | Delete
$status = self::POST_TYPE_NAMES['part'] === $post->post_type ? wp_trash_post($id) : wp_delete_post($id);
[175] Fix | Delete
$status = is_wp_error($status) ? 0 : $post->post_name;
[176] Fix | Delete
}
[177] Fix | Delete
}
[178] Fix | Delete
die("$status");
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
public static function get_item() {
[182] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[183] Fix | Delete
$msg = array('status' => false);
[184] Fix | Delete
if(!empty($_POST['id'])){
[185] Fix | Delete
$id = (int) $_POST['id'];
[186] Fix | Delete
global $post;
[187] Fix | Delete
$post = get_post($id);
[188] Fix | Delete
if (in_array($post->post_type, self::POST_TYPE_NAMES, true) && current_user_can( 'read_post',$id )) {
[189] Fix | Delete
setup_postdata($post);
[190] Fix | Delete
$msg['status'] = 'success';
[191] Fix | Delete
$msg['content'] = $post->post_type === self::POST_TYPE_NAMES['part'] ? self::get_layout_part_model($post, $_POST['type']) : json_decode($post->post_content, true);
[192] Fix | Delete
if ($post->post_type !== self::POST_TYPE_NAMES['part']) {
[193] Fix | Delete
$usedGS = Themify_Global_Styles::used_global_styles($id);
[194] Fix | Delete
if (!empty($usedGS)) {
[195] Fix | Delete
$msg['content']['gs'] = $usedGS;
[196] Fix | Delete
}
[197] Fix | Delete
}
[198] Fix | Delete
}
[199] Fix | Delete
}
[200] Fix | Delete
wp_send_json($msg);
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
public static function layout_part_edit() {
[204] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[205] Fix | Delete
if ( ! empty( $_POST['bid'] ) && current_user_can( 'edit_post', $_POST['bid'] ) ) {
[206] Fix | Delete
$id = (int) $_POST['bid'];
[207] Fix | Delete
$response['builder_data'] = ThemifyBuilder_Data_Manager::get_data($id);
[208] Fix | Delete
// Return used gs if used
[209] Fix | Delete
$usedGS = Themify_Global_Styles::used_global_styles($id);
[210] Fix | Delete
if (!empty($usedGS)) {
[211] Fix | Delete
$response['used_gs'] = $usedGS;
[212] Fix | Delete
}
[213] Fix | Delete
$custom_css = get_post_meta($id, 'tbp_custom_css', true);
[214] Fix | Delete
if (!empty($custom_css)) {
[215] Fix | Delete
$response['custom_css'] = $custom_css;
[216] Fix | Delete
}
[217] Fix | Delete
echo wp_json_encode($response);
[218] Fix | Delete
}
[219] Fix | Delete
wp_die();
[220] Fix | Delete
}
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function