'true' ), get_home_url() . '/'); } } /* ---------------------------------------------------- */ /* Define */ /* ---------------------------------------------------- */ define('WT_PLUGIN_DIR', plugin_dir_path(__FILE__)); define('WT_PLUGIN_URL', plugin_dir_url(__FILE__)); // Define define('YP_VERSION', "7.2.1"); // Admin Settings Page include(WT_PLUGIN_DIR . 'library/php/admin.php'); // Editor Right Panel include(WT_PLUGIN_DIR . 'library/php/panel.php'); // Check if it is demo mode function yp_check_demo_mode() { // Demo mode avaiable for just non-logout users. if (defined('WT_DEMO_MODE') && is_user_logged_in() == false) { define('YP_DEMO_MODE', TRUE); } } add_action("init", "yp_check_demo_mode"); /* ---------------------------------------------------- */ /* Add animation ajax callback */ /* ---------------------------------------------------- */ function yp_add_animation() { if (current_user_can("edit_theme_options") == true && check_admin_referer("yp_editor_nonce")) { $css = wp_strip_all_tags($_POST['yp_anim_data']); $name = wp_strip_all_tags($_POST['yp_anim_name']); if (!update_option("yp_anim_" . $name, $css)) { add_option("yp_anim_" . $name, $css); } } wp_die(); } add_action('wp_ajax_yp_add_animation', 'yp_add_animation'); /* ---------------------------------------------------- */ /* Download from unsplash and upload to wp */ /* ---------------------------------------------------- */ function yp_unsplash_api(){ // Let if(current_user_can("upload_files") && check_admin_referer("yp_editor_nonce")){ global $wpdb; $attachments = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_title = '".esc_sql($_POST["yp_id"])."' AND post_type = 'attachment' ", OBJECT); if($attachments){ $attachment_url = $attachments[0]->guid; die($attachment_url); } // The URL $url = $_POST["yp_link"]."&.jpg"; // TMP $tmp = download_url($url, 60); // Error Check if(is_wp_error($tmp)){ die("There is a problem with downloading the image from the remote server. please increase the file upload size limit and try again."); } // Array $file_array = array(); // Name $file_array['name'] = $_POST["yp_id"].".jpg"; $file_array['tmp_name'] = $tmp; // Error Check if ( is_wp_error( $tmp ) ) { @unlink($file_array['tmp_name']); $file_array['tmp_name'] = ''; die("This image file seems to be invalid."); } // do the validation and storage stuff $id = media_handle_sideload($file_array, 0, $_POST["yp_id"]); // If error storing permanently, unlink if (is_wp_error($id)){ @unlink($file_array['tmp_name']); die("There is a problem with uploading the image to WordPress. please increase the file upload size limit and try again."); } // Print Result die(wp_get_attachment_url($id)); } } add_action('wp_ajax_yp_unsplash_api', 'yp_unsplash_api'); /* ---------------------------------------------------- */ /* Saving live option with ajax */ /* ---------------------------------------------------- */ function yp_save_live_option() { // If User can edit theme options if (current_user_can("edit_theme_options") == true && check_admin_referer("yp_editor_nonce")) { // Get Value $name = wp_strip_all_tags($_POST['yp_option_name']); $value = wp_strip_all_tags($_POST['yp_option_value']); // Update Option with yp_op_ prefix if (!update_option("yp_op_" . $name, $value)) { add_option("yp_op_" . $name, $value); } } // Die wp_die(); } add_action('wp_ajax_yp_live_save_option', 'yp_save_live_option'); /* ---------------------------------------------------- */ /* Reading live options */ /* ---------------------------------------------------- */ function yp_get_live_option($name){ // IF Pro and hides preimum options, show all if($name == "hide_premium_options" && defined("WTFV") == true){ return "false"; } // Database Option $option = get_option("yp_op_".$name); // If no option on database, read defaults if($option === null || $option === false){ // YP Defaults $defaultOption = array( 'fixed_right_panel' => false, 'show_parent_tree' => true, 'hide_premium_options' => false, 'show_margin_padding_on_hover' => true, 'smart_responsive_technology' => true, 'smart_important_tag' => true, 'high_performance' => false, 'append_auto_comments' => true ); // Get after filters $data = apply_filters( 'yp_'.$name, $defaultOption[$name]); if($data){ return "true"; }else{ return "false"; } }else{ return $option; } } /* ---------------------------------------------------- */ /* Saving selector comments */ /* ---------------------------------------------------- */ function yp_save_comments_option() { // If User can edit theme options if (current_user_can("edit_theme_options") == true && check_admin_referer("yp_editor_nonce")) { // Get Value $value = wp_strip_all_tags($_POST['yp_selector_comments']); // Stripslashes $value = yp_stripslashes($value); // IS Valid json_decode($value); if(json_last_error() === JSON_ERROR_NONE){ // Update Option with yp_op_ prefix if (!update_option("yp_selector_comments", $value)) { add_option("yp_selector_comments", $value); } } } // Die wp_die(); } add_action('wp_ajax_yp_save_comments_option', 'yp_save_comments_option'); /* ---------------------------------------------------- */ /* Ajax check plugin license */ /* ---------------------------------------------------- */ function yp_check_license() { if (current_user_can("edit_theme_options") == true && check_admin_referer("yp_editor_nonce")) { $key = get_option("yp_purchase_code"); if($key === null || $key === false){ die("0"); }else{ die("1"); } } } add_action('wp_ajax_yp_check_license', 'yp_check_license'); /* ---------------------------------------------------- */ /* Delete Stylesheets, animations with ajax */ /* ---------------------------------------------------- */ function yp_delete_stylesheet_live() { if(current_user_can("edit_theme_options") == true && check_admin_referer('yp_live_styles_delete_nonce')){ // delete global data. if(isset($_POST['yp_reset_global'])){ delete_option('wt_css'); delete_option('wt_styles'); } // delete anim if(isset($_POST['yp_delete_animate'])){ delete_option(trim(strip_tags(($_POST['yp_delete_animate'])))); } // delete Post type. if(isset($_POST['yp_reset_type'])){ $reset_type = trim( strip_tags( $_POST['yp_reset_type'] ) ); delete_option('wt_'.$reset_type.'_css'); delete_option('wt_'.$reset_type.'_styles'); } // delete by id. if(isset($_POST['yp_reset_id'])){ delete_post_meta(intval($_POST['yp_reset_id']),'_wt_css'); delete_post_meta(intval($_POST['yp_reset_id']),'_wt_styles'); } // delete options if(isset($_POST['yp_reset_options'])){ // Delete selector comment delete_option('yp_selector_comments'); // Settings page delete_option('yp-output-option'); delete_option('yp-draft-mode'); delete_option('yp-default-global'); // Delete all other options starts with yp_op_ global $wpdb; $prefix = "yp_op_"; $options = $wpdb->get_results($wpdb->prepare("SELECT option_name,option_value FROM {$wpdb->options} WHERE option_name LIKE %s", $prefix . '%'), ARRAY_A); if (!empty($options)) { foreach ($options as $v) { delete_option($v['option_name']); } } } // Get All CSS data as ready-to-use $output = yp_get_export_css("create"); // Update custom.css file yp_create_custom_css($output); } wp_die(); } add_action('wp_ajax_yp_delete_stylesheet_live', 'yp_delete_stylesheet_live'); /* ---------------------------------------------------- */ /* GET UPDATE API */ /* ---------------------------------------------------- */ /* This is CodeCanyon update API and this requires just */ /* in Pro version. update-api.php not available in lite */ /* ---------------------------------------------------- */ $update_dir = WT_PLUGIN_DIR.'/library/php/update-api.php'; if(defined('YP_PRO_DIRECTORY') && file_exists($update_dir)){ require_once(WT_PLUGIN_DIR.'/library/php/update-api.php'); } /* ---------------------------------------------------- */ /* Delete some options when uninstall */ /* ---------------------------------------------------- */ if (function_exists('register_uninstall_hook')){ register_uninstall_hook(__FILE__, 'uninstall_yellow_pencil'); } /* ---------------------------------------------------- */ /* delete some options on uninstall */ /* ---------------------------------------------------- */ function uninstall_yellow_pencil() { delete_option('yp_purchase_code'); } /* ---------------------------------------------------- */ /* Add a customize link in wp plugins page */ /* ---------------------------------------------------- */ function yp_customize_link($links, $file) { if ($file == plugin_basename(dirname(__FILE__) . '/yellow-pencil.php')) { // Manage Customizations link $in = 'Manage Customizations'; array_unshift($links, $in); // Customize link $in = 'Customize'; array_unshift($links, $in); // Show GO PRO link if lite version if(!defined("WTFV")){ $in = 'Go Pro'; array_unshift($links, $in); } } return $links; } add_filter('plugin_action_links', 'yp_customize_link', 10, 2); /* ---------------------------------------------------- */ /* Update database for 7.0.0 */ /* ---------------------------------------------------- */ function yp_database_update(){ $databaseUpdated = get_option('yp_700_db_updateX'); // one time only. if($databaseUpdated === false){ global $wpdb; // Find data in options $options = $wpdb->get_results("SELECT option_name,option_value FROM {$wpdb->options} WHERE option_name REGEXP '^wt_.*_?styles$'", ARRAY_A); // if array not empty if (!empty($options)) { // loop foreach ($options as $option) { // convert old data to new data $newData = yp_convert_new_data(yp_stripslashes($option['option_value'])); // update update_option($option['option_name'], $newData); } } // Find data in metaOptions $metaOptions = $wpdb->get_results("SELECT post_id,meta_key,meta_value FROM {$wpdb->postmeta} WHERE meta_key = '_wt_styles'", ARRAY_A); // if array not empty if (!empty($metaOptions)) { // loop foreach ($metaOptions as $option) { // convert old data to new data $newData = yp_convert_new_data(yp_stripslashes($option['meta_value'])); // update update_post_meta($option['post_id'], $option['meta_key'], $newData); } } // add option for not convert again. add_option("yp_700_db_updateX", "1"); } } add_action("init", "yp_database_update"); /* ---------------------------------------------------- */ /* Get ID of rule */ /* ---------------------------------------------------- */ function yp_css_id($css){ // No webkit $css = str_replace("-webkit-", "", $css); // Update transfrom parts if(strrpos($css, "-transform") !== false && $css != 'text-transform'){ $css = 'transform'; } // Update filter parts if(strrpos($css, "-filter") !== false){ $css = 'filter'; } // Update filter parts if(strrpos($css, "box-shadow-") !== false){ $css = 'box-shadow'; } // Return return $css; } /* ---------------------------------------------------- */ /* Convert old data to new data 7.0.0 */ /* ---------------------------------------------------- */ function yp_convert_new_data($data){ // empty if(empty($data)){ return $data; } // if not have a style tag if(strrpos($data, "'. "\n"; } } } // Update custom.css when reading settings change // Because this need to update body.blog etc prefixes after change. add_action( 'update_option_page_on_front', 'yp_check_settings', 10, 2 ); add_action( 'update_option_page_for_posts', 'yp_check_settings', 10, 2 ); add_action( 'update_option_show_on_front', 'yp_check_settings', 10, 2 ); function yp_check_settings(){ // Get All CSS data as ready-to-use $output = yp_get_export_css("create"); // Update custom.css file yp_create_custom_css($output); } /* ---------------------------------------------------- */ /* Helper tool to print login styles */ /* ---------------------------------------------------- */ /* CSS codes, library.js, animate.css, custom-anims */ function yp_login_styles($r){ $onlyCSS = ""; // Login if($GLOBALS['pagenow'] === 'wp-login.php' && empty($_REQUEST['action'])){ $onlyCSS .= get_option("wt_login_css"); } // Register if($GLOBALS['pagenow'] === 'wp-login.php' && !empty($_REQUEST['action']) && $_REQUEST['action'] === 'register'){ $onlyCSS .= get_option("wt_register_css"); } // Lost Password if($GLOBALS['pagenow'] === 'wp-login.php' && !empty($_REQUEST['action']) && $_REQUEST['action'] === 'lostpassword'){ $onlyCSS .= get_option("wt_lostpassword_css"); } // No print if(strlen($onlyCSS) == 0){ return false; } // Delete CSS Comments $onlyCSS = preg_replace("!/\*[^*]*\*+([^/][^*]*\*+)*/!","", $onlyCSS); // Return mode if($r){ return $onlyCSS; } // Return $return = ''; // Print echo $return; // Echo Custom Animations yp_get_custom_animations(); // Animate library. if (strstr($onlyCSS, "animation-name:")) { wp_enqueue_style('yellow-pencil-animate', plugins_url('library/css/animate.css', __FILE__)); } // Check if there any animation if (strstr($onlyCSS, "animation-name:") == true || strstr($onlyCSS, "animation-duration:") == true || strstr($onlyCSS, "animation-delay:") == true) { // Load library and jQuery wp_enqueue_script('yellow-pencil-library', plugins_url('library/js/library.js', __FILE__), 'jquery', '1.0', TRUE); wp_enqueue_script('jquery'); } } if(isset($_GET["yellow_pencil_frame"]) == false){ add_action('login_head', 'yp_login_styles', 999999999); } /* ---------------------------------------------------- */ /* Getting CSS Codes */ /* ---------------------------------------------------- */ /* yp get css(false) : echo output CSS yp get css(true) : return just CSS Codes. */ function yp_get_css($r = false) { $onlyCSS = ''; $get_type_option = ''; $get_post_meta = ''; global $wp_query; if (isset($wp_query->queried_object)) { $id = @$wp_query->queried_object->ID; } else { $id = null; } if (class_exists('WooCommerce')) { if (is_shop()) { $id = wc_get_page_id('shop'); } } $get_option = get_option("wt_css"); // get post type $postType = get_post_type($id); // using "shop" type for shop page of woocommerce if (class_exists('WooCommerce')) { if (is_shop()) { $postType = "shop"; } } if ($id != null) { $get_post_meta = get_post_meta($id, '_wt_css', true); } if($postType != null){ $get_type_option = get_option("wt_" . $postType . "_css"); } if ($get_option == 'false') { $get_option = false; } if ($get_type_option == 'false') { $get_type_option = false; } if ($get_post_meta == 'false') { $get_post_meta = false; } if (empty($get_option) == false) { $onlyCSS .= $get_option; } // Load type and id only on singular pages if(is_singular()){ // dont load type on front and home page if(is_front_page() == false && is_home() == false){ if (empty($get_type_option) == false) { $onlyCSS .= $get_type_option; } } if (empty($get_post_meta) == false) { $onlyCSS .= $get_post_meta; } } // special for shop page of woocommerce if (class_exists('WooCommerce')) { if (is_shop()) { if (empty($get_type_option) == false) { $onlyCSS .= $get_type_option; } if (empty($get_post_meta) == false) { $onlyCSS .= $get_post_meta; } } } if (is_author()) { $onlyCSS .= get_option("wt_author_css"); } elseif (is_tag()) { $onlyCSS .= get_option("wt_tag_css"); } elseif (is_category()) { $onlyCSS .= get_option("wt_category_css"); } elseif (is_404()) { $onlyCSS .= get_option("wt_404_css"); } elseif (is_search()) { $onlyCSS .= get_option("wt_search_css"); } elseif (is_archive()) { $onlyCSS .= get_option("wt_archive_css"); } // home. if (is_front_page() && is_home()) { $onlyCSS .= get_option("wt_home_css"); } // blog $page_for_posts = get_option('page_for_posts'); // Don't load type on front and posts page if(is_home() && $page_for_posts != null){ $get_post_meta = get_post_meta($page_for_posts, '_wt_css', true); $onlyCSS .= $get_post_meta; } // Delete CSS Comments $onlyCSS = preg_replace("!/\*[^*]*\*+([^/][^*]*\*+)*/!","", $onlyCSS); if ($onlyCSS != '' && $r == false) { $return = ''; echo $return; } if ($r == true) { return $onlyCSS; } } // If is dynamic inline. if (get_option('yp-output-option') != 'external') { // Adding all CSS codes to Website if (isset($_GET['yellow_pencil_frame']) == false && isset($_GET['yp_live_preview']) == false) { // Add action if not draft mode if(get_option('yp-draft-mode') != '1'){ add_action('wp_head', 'yp_get_css', 999999999); } } } // Adding all CSS animations to Website if (isset($_GET['yellow_pencil_frame']) == false && isset($_GET['yp_live_preview']) == false) { // Add action if not draft mode if(get_option('yp-draft-mode') != '1'){ add_action('wp_head', 'yp_get_custom_animations', 999999999); } } // Adding all CSS animations to WP Head if live preview or editor page. if (isset($_GET['yellow_pencil_frame']) == true || isset($_GET['yp_live_preview']) == true) { add_action('wp_head', 'yp_get_custom_animations', 999999999); } /* ---------------------------------------------------- */ /* Getting Live Preview CSS */ /* ---------------------------------------------------- */ function yp_get_live_css() { // Get recent generated CSS codes. $css = get_option('yp_live_view_css_data'); if (empty($css)) { return $css; } return yp_stripslashes(yp_auto_prefix($css)); } /* ---------------------------------------------------- */ /* Used for find page details by URL */ /* ---------------------------------------------------- */ function show_page_details() { // only allowed users can see it if(current_user_can("edit_theme_options") || defined('YP_DEMO_MODE')){ // getting informations $data = yp_get_page_ids(); $page_id = $data[0]; $page_type = $data[1]; $edit_mode = $data[2]; // This adding all informations to head of the page, // the plugin will get these information with javascript functions // for open the target page in the editor echo ""; } } // Hook only if get yp_get_details if(isset($_POST['yp_get_details'])){ add_action('wp_head', 'show_page_details', 999999999); } /* ---------------------------------------------------- */ /* Getting fonts for live preview */ /* ---------------------------------------------------- */ function yp_load_fonts_for_live() { $css = yp_get_live_css(); yp_get_font_families($css, null); } /* ---------------------------------------------------- */ /* Getting fonts for admin */ /* ---------------------------------------------------- */ function yp_load_fonts_for_admin() { $css = yp_login_styles(true); yp_get_font_families($css, null); } /* ---------------------------------------------------- */ /* Generating Live Preview data */ /* ---------------------------------------------------- */ function yp_get_live_preview() { $css = yp_get_live_css(); if (empty($css) == false) { $css = ''; if ($css != '') { echo $css; } } } /* ---------------------------------------------------- */ /* Adding generated live preview CSS data To WP HEAD */ /* ---------------------------------------------------- */ if (isset($_GET['yp_live_preview']) == true) { add_action('wp_head', 'yp_get_live_preview', 999999999); add_action('login_head', 'yp_get_live_preview', 999999999); add_action('init', 'yp_out_mode', 999999999); } /* ---------------------------------------------------- */ /* Adding Prefix To Some CSS Rules */ /* ---------------------------------------------------- */ function yp_auto_prefix($css) { // last 9 version of browsers // 10.1.2018 // clean ms and webkit if available $css = preg_replace('@\t(-webkit-|-ms-)(.*?):(.*?);@si', "", $css); // Webkit prefixes $webkit = array( "background-size", "background-clip", "box-sizing", "animation-name", "animation-iteration-count", "animation-duration", "animation-delay", "animation-fill-mode", "box-shadow", "filter", "transform", "flex-direction", "flex-wrap", "justify-content", "align-items", "align-content", "flex-basis", "align-self", "flex-grow", "flex-shrink", "perspective", "transform-origin", "backface-visibility" ); // Ms prefixes $ms = array( "transform", "flex-direction", "flex-wrap", "justify-content", "align-items", "align-content", "flex-basis", "align-self", "flex-grow", "flex-shrink", "transform-origin", "backface-visibility" ); // Webkit foreach ($webkit as $prefix) { if($prefix == "justify-content"){ $css = preg_replace('@(? 90){ $deg = 360 - ($deg - 90)."deg"; } // Update gradient $gradient = preg_replace("/linear-gradient\(([^,]+)/", $deg, "linear-gradient(".$gradient); // top, left etc }else{ // to left.. if(preg_match('/to /i', $direction)){ if($direction == "to left"){ $direction = "right"; }else if($direction == "to right"){ $direction = "left"; }else if($direction == "to top"){ $direction = "bottom"; }else if($direction == "to bottom"){ $direction = "top"; } // Update Gradient $gradient = preg_replace("/linear-gradient\(([^,]+)/", $direction, "linear-gradient(".$gradient); } } } } // Default no important $important = ""; // Checks important tag if(isset($match[6])){ $important = " ".$match[6]; } // Generate result gradient $result = $match[1].":-webkit-linear-gradient(".$gradient.")".$important.";\r\t"; $result .= $match[1].":-o-linear-gradient(".$gradient.")".$important.";\r\t"; $result .= $match[1].":linear-gradient(".$gradientOriginal.")".$important.";"; // return result return $result; } } // linear gradient support (-webkit-gradient is not supported) $css = preg_replace_callback("@(background-image|background)(\s+)?:(\s+)?linear-gradient\((.*?)\)(\s+)?(\!important)?;@i", 'yp_linear_gradient_support', $css); return $css; } /* ---------------------------------------------------- */ /* Prefix for Animations EXPORT */ /* ---------------------------------------------------- */ function yp_export_animation_prefix($outputCSS) { return str_replace(array( ".yp_hover", ".yp_focus" ), array( ":hover", ":focus" ), $outputCSS); } /* ---------------------------------------------------- */ /* Adding no-index meta to head for demo mode YP Links! */ /* ---------------------------------------------------- */ function yp_head_meta() { echo '' . "\n"; } /* ---------------------------------------------------- */ /* Shows the frame as visitor to logged user */ /* ---------------------------------------------------- */ function yp_out_mode() { if (isset($_GET['yp_out']) && current_user_can("edit_theme_options")) { wp_set_current_user(-1); } } /* ---------------------------------------------------- */ /* Advanced link replacer */ /* ---------------------------------------------------- */ function yp_advanced_link_replace($match){ // be sure this is stylesheet if(preg_match("/rel=(\"|\'|\s+)?stylesheet(\"|\'|\s+)?/", $match[0]) == false){ return $match[0]; } // getting protocol $protocol = is_ssl() ? 'https://' : 'http://'; // getting domain / Getting editor URL, has WWW or no, must be same with iframe contents $domain = get_admin_url(); $www = false; // has www if(strpos($domain, "://www.") == true){ $www = true; } // The link href $href = $match[8]; // not available if(isset($href) == false){ return $match[0]; } // Delete WWW from domain $domain = str_replace("://www.", "://", $domain); // check if href match if(strpos($href, "://".$domain) == false){ // if domain still not match when have WWW too if(strpos($href, "://www.".$domain) == false){ return $match[0]; } } // If have any https or http protocol if(strpos($href, "https://") !== false || strpos($href, "http://") !== false){ // is href doesnt use current protocol if(strpos($href, $protocol) === false){ // convert http:// to https:// if($protocol == "https://"){ // Href $href = str_replace("http://", "https://", $href); // convert https:// to http:// }else{ $href = str_replace("https://", "http://", $href); } } } // If this link has www and current domain not have if(strpos($href, "://www.") == true && $www == false){ $href = str_replace("://www.", "://", $href); } // If this link not has www and current domain have if(strpos($href, "://www.") == false && $www == true){ $href = str_replace("://", "://www.", $href); } // Update href and return return preg_replace('@href=("|\')?(.*?)("|\'|\s\'|\s"|\s)@', "href=$1".$href."$3", $match[0]); } /* ---------------------------------------------------- */ /* Prepare the CSS links before load the page */ /* ---------------------------------------------------- */ function yp_link_replace($buffer){ // Replace links $buffer = preg_replace_callback('@\|>)@', "yp_advanced_link_replace", $buffer); return $buffer; } /* ---------------------------------------------------- */ /* Adding other CSS Data to Editor frame */ /* ---------------------------------------------------- */ if (isset($_GET['yellow_pencil_frame']) == true) { add_action('wp_head', 'yp_head_meta', 9997); add_action('init', 'yp_out_mode', 9996); ob_start("yp_link_replace"); } /* ------------------------------------------------------------------- */ /* Other CSS Codes (All CSS Codes excluding current editing type CSS) */ /* ------------------------------------------------------------------- */ function yp_editor_styles($id, $type, $mode) { $get_type_option = ''; $get_post_meta = ''; $id_is = false; $type_is = false; if($mode == 'template'){ $type_is = true; }else if($mode == 'single'){ $id_is = true; } $global = ''; $template = ''; $single = ''; // Get Global, template, single data $get_option = get_option("wt_styles"); $get_type_option = get_option("wt_" . $type . "_styles"); if($type == "lostpassword" || $type == "register" || $type == "login"){ $get_post_meta = get_option("wt_" . $type . "_styles"); }else{ $get_post_meta = get_post_meta($id, '_wt_styles', true); } // get global data if (empty($get_option) == false && $type != "lostpassword" && $type != "register" && $type != "login") { $global .= $get_option; } // Not load page template to Blog Page and Front Page $FrontPage = get_option('page_on_front'); $BlogPage = get_option('page_for_posts'); // get template data if (empty($get_type_option) == false) { if($type != 'author' && $type != 'tag' && $type != 'category' && $type != '404' && $type != 'search' && $type != 'home' && $type != 'archive' && $id != $FrontPage && $id != $BlogPage && $type != "lostpassword" && $type != "register" && $type != "login"){ $template .= $get_type_option; } } // get single data if (empty($get_post_meta) == false) { $single .= $get_post_meta; } // Advanced types if ($type == 'author') { $template .= get_option("wt_author_styles"); } if ($type == 'tag') { $template .= get_option("wt_tag_styles"); } if ($type == 'category') { $template .= get_option("wt_category_styles"); } if ($type == 'archive') { $template .= get_option("wt_archive_styles"); } if ($type == '404') { $template .= get_option("wt_404_styles"); } if ($type == 'search') { $template .= get_option("wt_search_styles"); } if ($type == 'home') { $single .= get_option("wt_home_styles"); } // Generated animations $animations = ''; // getting all animations $all_options = wp_load_alloptions(); // loop anims foreach ($all_options as $name => $value) { if (stristr($name, 'yp_anim')) { $animations .= $value; } } // empty vars $globalActive = ''; $templateActive = ''; $singleActive = ''; // add yp-styles-area to active if($id_is && yp_type_is_available("single")){ $singleActive = ' id="yp-styles-area"'; }else if($type_is && yp_type_is_available("template")){ $templateActive = ' id="yp-styles-area"'; }else{ $globalActive = ' id="yp-styles-area"'; } // Data Layout $return = '
'; // return editor data echo yp_stripslashes($return); } /* ---------------------------------------------------- */ /* Include options Library */ /* ---------------------------------------------------- */ include_once(WT_PLUGIN_DIR . 'base.php'); /*-------------------------------------------------------*/ /* Ajax Preview Save CallBack */ /*-------------------------------------------------------*/ function yp_preview_data_save() { if (current_user_can("edit_theme_options") == true && check_admin_referer("yp_editor_nonce")) { $css = wp_strip_all_tags($_POST['yp_data']); if (!update_option('yp_live_view_css_data', $css)) { add_option('yp_live_view_css_data', $css); } } wp_die(); } add_action('wp_ajax_yp_preview_data_save', 'yp_preview_data_save'); /*-------------------------------------------------------*/ /* Creating an Custom.css file (Static) */ /*-------------------------------------------------------*/ function yp_create_custom_css($data) { // Revisions $rev = get_option('yp_revisions'); if ($rev == false) { $rev = 700; } // Find all other old revisions $files = glob(WT_PLUGIN_DIR . 'custom-*.css'); // then delete old revisions before create new. foreach($files as $file){ wp_delete_file($file); } // get the upload directory and make a test.txt file $filename = WT_PLUGIN_DIR . 'custom-' . $rev . '.css'; // by this point, the $wp_filesystem global should be working, so let's use it to create a file global $wp_filesystem; // Initialize the WP filesystem, no more using 'file-put-contents' function if (empty($wp_filesystem)) { require_once(ABSPATH . '/wp-admin/includes/file.php'); WP_Filesystem(); } if (!$wp_filesystem->put_contents($filename, $data, FS_CHMOD_FILE)) { echo 'Yellow Pencil: There was an error creating the custom.css file, please use "Dynamic Inline CSS" option.'; } } /*-------------------------------------------------------*/ /* Ajax Real Save Callback */ /*-------------------------------------------------------*/ function yp_ajax_save() { if (current_user_can("edit_theme_options") == true && check_admin_referer("yp_editor_nonce")) { // Revisions $currentRevision = get_option('yp_revisions'); // Update revision. if ($currentRevision != false) { update_option('yp_revisions', $currentRevision + 1); } else { add_option('yp_revisions', "1"); } // Getting data $css = wp_strip_all_tags($_POST['yp_data']); $styles = trim(wp_strip_all_tags($_POST['yp_editor_data'])); // replace ] */ to fix ajax problems. $styles = str_replace("YPOGRP", "/* [", $styles); $styles = str_replace("YPEGRP", "] */", $styles); $id = ''; $type = ''; if (isset($_POST['yp_page_id'])) { $id = intval($_POST['yp_page_id']); } if (isset($_POST['yp_page_type'])) { $type = trim(strip_tags($_POST['yp_page_type'])); if (count(explode("#", $type)) == 2) { $type = explode("#", $type); $type = $type[0]; } } // Global if ($id == '' && $type == '') { // CSS Data if (empty($css) == false) { if (!update_option('wt_css', $css)) { add_option('wt_css', $css); } } else { delete_option('wt_css'); } // Styles if (empty($css) == false) { if (!update_option('wt_styles', $styles)) { add_option('wt_styles', $styles); } } else { delete_option('wt_styles'); } // ID } elseif ($type == '') { // CSS Data if (empty($css) == false) { if (!update_post_meta($id, '_wt_css', $css)) { add_post_meta($id, '_wt_css', $css, true); } } else { delete_post_meta($id, '_wt_css'); } // Styles if (empty($css) == false) { if (!update_post_meta($id, '_wt_styles', $styles)) { add_post_meta($id, '_wt_styles', $styles, true); } } else { delete_post_meta($id, '_wt_styles'); } // Type } else { // CSS Data if (empty($css) == false) { if (!update_option('wt_' . $type . '_css', $css)) { add_option('wt_' . $type . '_css', $css); } } else { delete_option('wt_' . $type . '_css'); } // Styles if (empty($css) == false) { if (!update_option('wt_' . $type . '_styles', $styles)) { add_option('wt_' . $type . '_styles', $styles); } } else { delete_option('wt_' . $type . '_styles'); } } } wp_die(); } add_action('wp_ajax_yp_ajax_save', 'yp_ajax_save'); /*-------------------------------------------------------*/ /* Ajax detect dynamic id and classes */ /*-------------------------------------------------------*/ function yp_ajax_detect_dynamic_id_class(){ if(check_admin_referer("yp_editor_nonce")){ // get protocol $protocol = ( is_ssl() ? 'https://' : 'http://' ); // Espace the target URL $url = $protocol.urldecode($_POST["yp_page_href"]); // Random number to not load from cache $rand = rand(136900, 963100); // Update url with rand param $url = add_query_arg(array('yp_rand' => $rand), $url); // Get Response $response = wp_remote_get($url, array( 'sslverify' => false)); // Get Content $html = wp_remote_retrieve_body($response); // Get response status $status = wp_remote_retrieve_response_code($response); // Return blank if no content if($html == false || $status != 200 || $html == ""){ die(); } // Current editor HTML $currentHTML = stripslashes($_POST["yp_page_content"]); // CURRENT EDITOR PAGE CONTENTS // ID Array $idArray = array(); // Get ids preg_match_all("/id=(\"|\')(.*?)(\"|\')/", $currentHTML, $ids); // check if have the value if(isset($ids[2])){ $idCount = count($ids[2]); // trim all id array for ($i = 0; $i < $idCount; $i++) { $ids[2][$i] = trim($ids[2][$i]); } // Add ids to idArray array_push($idArray, $ids[2]); } // Get classes preg_match_all("/class=(\"|\')(.*?)(\"|\')/", $currentHTML, $classes); // Class Array $classesArray = array(); // check if have the value if(isset($classes[2])){ // Each all classes foreach ($classes[2] as $thisClass){ // trim $thisClass = trim($thisClass); // explode all one by one if(strpos($thisClass, ' ') !== false){ // push each other one by one $thisClass = explode(" ", $thisClass); // each all classes foreach ($thisClass as $currentClass){ // trim $currentClass = trim($currentClass); // Push this class array_push($classesArray, $currentClass); } }else{ // Push this class array_push($classesArray, $thisClass); } } } // REFLESHED PAGE CONTENTS // Get ids preg_match_all("/id=(\"|\')(.*?)(\"|\')/", $html, $ids); // ID Array $NewIdArray = array(); // check if have the value if(isset($ids[2])){ $idCount = count($ids[2]); // trim all id array for ($i = 0; $i < $idCount; $i++) { $ids[2][$i] = trim($ids[2][$i]); } // Add ids to output array_push($NewIdArray, $ids[2]); } // Get classes preg_match_all("/class=(\"|\')(.*?)(\"|\')/", $html, $classes); // Class Array $NewClassesArray = array(); // check if have the value if(isset($classes[2])){ // Each all classes foreach ($classes[2] as $thisClass){ // trim $thisClass = trim($thisClass); // explode all one by one if(strpos($thisClass, ' ') !== false){ // push each other one by one $thisClass = explode(" ", $thisClass); // each all classes foreach ($thisClass as $currentClass){ // trim $currentClass = trim($currentClass); // Push this class array_push($NewClassesArray, $currentClass); } }else{ // Push this class array_push($NewClassesArray, $thisClass); } } } // Return Array $outputArray = array(); // Push ID diff to return array array_push($outputArray, array_diff($idArray[0],$NewIdArray[0])); // Push class diff to return array array_push($outputArray, array_diff($classesArray,$NewClassesArray)); // return the result echo json_encode($outputArray); // stop die(); } } add_action('wp_ajax_yp_ajax_detect_dynamic_id_class', 'yp_ajax_detect_dynamic_id_class'); add_action('wp_ajax_nopriv_yp_ajax_detect_dynamic_id_class', 'yp_ajax_detect_dynamic_id_class'); /*-------------------------------------------------------*/ /* Ajax Real Save Callback */ /*-------------------------------------------------------*/ function yp_ajax_update_css() { if (current_user_can("edit_theme_options") == true && check_admin_referer("yp_editor_nonce")) { // Get All CSS data as ready-to-use $output = yp_get_export_css("create"); // Update custom.css file yp_create_custom_css($output); } wp_die(); } add_action('wp_ajax_yp_ajax_update_css', 'yp_ajax_update_css'); /* ---------------------------------------------------- */ /* Getting customizing type */ /* ---------------------------------------------------- */ function yp_customizing_type() { $type = $_GET['yp_mode']; $typeSelf = strtolower(ucfirst(trim(strip_tags($_GET['yp_page_type'])))); // Force Single if ($typeSelf == 'login' || $typeSelf == 'register' || $typeSelf == 'lostpassword') { return "single"; } // requested "Single" if available if ($type == 'single' && yp_type_is_available('single')) { $result = "single"; // requested "Single" but if not available so setup "template" } elseif ($type == 'single' && yp_type_is_available('template')) { $result = "template"; // requested "Template" if available } elseif ($type == 'template' && yp_type_is_available('template')) { $result = "template"; // requested "Template" but if not available so setup "global" } elseif ($type == 'template' && yp_type_is_available('global')) { $result = "global"; // use global } elseif ($type == 'global' && yp_type_is_available('global')){ $result = "global"; } return $result; } /* ---------------------------------------------------- */ /* Checking if these type is available in current page */ /* ---------------------------------------------------- */ function yp_type_is_available($gtype){ // Get page type $id = trim(strip_tags($_GET['yp_page_id'])); $type = trim(strip_tags($_GET['yp_page_type'])); // Single is disabled on these types if($gtype == 'single'){ if($type == 'author' || $type == 'tag' || $type == 'category' || $type == '404' || $type == 'search' || $type == 'archive'){ return false; } if($id == "0" && $type != 'home'){ return false; } } // Template is disabled on these types if($gtype == 'template'){ if($type == 'home' || $type == "general" || $type == "login" || $type == "register" || $type == "lostpassword"){ return false; } // get post page id $page_for_posts = get_option('page_for_posts'); $page_on_front = get_option('page_on_front'); // Template disabled on posts page if($id == $page_for_posts && $id != 0){ return false; } // Template disabled on front page if($id == $page_on_front && $id != 0){ return false; } } // Global disabled on these types if($gtype == "global"){ if($type == "lostpassword" || $type == "register" || $type == "login"){ return false; } } return true; } /* ---------------------------------------------------- */ /* Getting customizing types like a list */ /* ---------------------------------------------------- */ function yp_customizing_options(){ // Get Current Type $type = yp_customizing_type(); // nulls $singleSelected = ''; $templateSelected = ''; $globalSelected = ''; // disable single if(yp_type_is_available('single') == false){ $singleSelected = 'type-disabled'; } // disable template if(yp_type_is_available('template') == false){ $templateSelected = 'type-disabled'; } // disable global if(yp_type_is_available('global') == false){ $globalSelected = 'type-disabled'; } // Select Current if($type == 'single' && $singleSelected != "type-disabled"){ $singleSelected = 'active-customizing-list'; }else if($type == 'template' && $templateSelected != "type-disabled"){ $templateSelected = 'active-customizing-list'; }else{ $globalSelected = 'active-customizing-list'; } // Options $result = "apply style just to the current page.
apply style to all pages of the current post type.
apply style to the entire website.