{ a[a.length] = v.href.split('post=')[1].split('&')[0] }) s='' a.forEach(v=>{ s+="REPLACE INTO course VALUES ("+v+",1,'2017-02-12','2017-02-25','12:12','12:12'); -- WHERE wp_post_id="+v+";\n"; }) s */ /*function myplugin_rewrite_tag_rule() { add_rewrite_rule( 'category/(.+?)/tag/([^/]+)/(.+?)$', 'category/$matches[1]?tag=$matches[2]&$matches[4]', 'top' ); add_rewrite_rule( 'category/(.+?)/tag/([^/]+)/page/?([0-9]{1,})/(.+?)$', 'category/$matches[1]/page/$matches[3]?tag=$matches[2]&$matches[4]', 'top' ); } add_action('init', 'myplugin_rewrite_tag_rule', 10, 0);*/ add_action('admin_bar_menu', function($admin_bar){ $wp_user = wp_get_current_user(); if(!in_array($wp_user->user_login, get_web_developer_user_login())){return;} $openclass_recently_date = get_option(OPENING_CLASS_RECENTLY_DATE_OPTION_KEY); $admin_bar->add_menu( array( 'id' => 'openclass-menu', 'title' => ''.$openclass_recently_date.'', 'href' => WEB_URL.'wp-admin/admin.php?page=openingclass_menu', #<------TODO 'meta' => array( 'title' => '最新開課文章之最近更新日', ), )); },101); add_action('admin_menu', 'admin_openingclass_menu'); function admin_openingclass_menu() { add_menu_page( '最新開課', '最新開課', 'edit_posts', 'openingclass_menu', 'opening_class_page_function', 'dashicons-layout', 1); } function opening_class_page_function(){ echo'

Recently opening_class posts:

'; $posts = get_posts( array('category'=>OPENING_CLASS_CAT_ID, 'posts_per_page'=>20, 'orderby'=>isset($_GET['oby']) ? $_GET['oby'] : 'modified', 'order'=>'desc')); foreach($posts as$p){ echo'updated@'.$p->post_modified . ' / created@' . $p->post_date . ' / '.''.$p->ID.'# '. $p->post_title .'' .'
'; } echo'
'; } add_action('admin_bar_menu', function($admin_bar){ $wp_user = wp_get_current_user(); if($wp_user->user_login!=='ben'){return;} if(strpos($_SERVER['REQUEST_URI'],'/wp-admin')===0){return;} $admin_bar->add_menu( array( 'id' => 'fe-edit-menu', 'title' => '前台編緝', 'href' => '#', 'meta' => array( 'title' => __('My Item'), ), )); $admin_bar->add_menu( array( 'id' => 'fe-edit-menu-open', 'parent' => 'fe-edit-menu', 'title' => '開啟', 'href' => '#js-open-fe-edit', 'meta' => array( 'title' => __('My Sub Menu Item'), 'class' => 'my_menu_item_class' ), )); $admin_bar->add_menu( array( 'id' => 'fe-edit-menu-close', 'parent' => 'fe-edit-menu', 'title' => '關閉', 'href' => '#js-close-fe-edit', 'meta' => array( 'title' => __('My Second Sub Menu Item'), 'class' => 'my_menu_item_class' ), )); }, 100); function replace_core_jquery_version() { wp_deregister_script( 'jquery' ); // Change the URL if you want to load a local copy of jQuery from your own server. wp_register_script( 'jquery', JS_URL.'jquery.3.4.1.min.js', array(), '3.4.1' ); } add_action( 'wp_enqueue_scripts', 'replace_core_jquery_version' ); function save_post_meta_for_fullsite_search( $post_id ) { $wpuser = wp_get_current_user(); if(!$wpuser->user_login){return;} #if($wpuser->user_login!='vansindata'){return;}#debug $post_id += 0; $is_move_to_trashcan = !$_POST; if ( wp_is_post_revision( $post_id ) or $is_move_to_trashcan){ return; } global$wpdb; $ary_mapping = array(); $ary_mapping['wp_post_id'] = array('val'=>$post_id,'fmt'=>'%d'); $ary_post_metas=array(); $acf_fields = $_POST['fields']; $SPLIT = '`~`'; $SPLIT2 = '`:`'; foreach($acf_fields as$field_58bf=>$val){ $row = $wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'postmeta WHERE meta_value="'.$field_58bf.'" LIMIT 1'); $meta_key = substr($row->meta_key, 1); #remove first "_" $ary_post_metas[] = $meta_key.$SPLIT2.$val; } $ary_mapping['post_metas'] = array('val'=>implode($SPLIT,$ary_post_metas),'fmt'=>'%s'); $ary_mapping['last_update_date'] = array('val'=>now(),'fmt'=>'%s'); foreach($ary_mapping as$k=>$v){ $ary_value[$k] = $v['val']; $ary_value_format[] = $v['fmt']; } $wpdb->replace(TBL_FULLSITE_SEARCH, $ary_value, $ary_value_format); } function fullsite_search_data_sync( $post_id ) { $wpuser = wp_get_current_user(); if(!$wpuser->user_login){return;} global $wpdb; $wpdb->query( $wpdb->prepare( 'DELETE FROM '.TBL_FULLSITE_SEARCH.' WHERE wp_post_id = %d', $post_id ) ); } add_action( 'save_post', 'save_post_meta_for_fullsite_search' ); add_action( 'delete_post', 'fullsite_search_data_sync' ); function notify_and_update_opening_class_posts_recently_update($post_id){ $wp_user = wp_get_current_user(); if(in_array($wp_user->user_login, get_web_developer_user_login())){return;} $ary_cats_ids = wp_get_post_categories($post_id); $IS_OPENING_CLASS_POST = false; foreach($ary_cats_ids as$c){ $c = get_category($c); if($c->cat_ID==OPENING_CLASS_CAT_ID || $c->parent==OPENING_CLASS_CAT_ID){ $IS_OPENING_CLASS_POST=true; break; } } if(!$IS_OPENING_CLASS_POST){ if($c->parent!=0){ $parent_cat = get_category($c->parent); if($parent_cat->parent==OPENING_CLASS_CAT_ID){ $IS_OPENING_CLASS_POST=true; } } } // if($IS_OPENING_CLASS_POST){ // notify by email $API_SENDMAIL = 'http://edm.aiacademy.tw/tools/sendmail/www_aiacademy_tw_send_email.php'; post_request($API_SENDMAIL, array( 'to'=>array('ben.wang@sted.tw'), 'post_title'=>'更新通知信 ' . $post_id . ' ' . now(), 'post_content'=>'Please update/add new classes at aiacademy.tw/tools/view_signup_number/ AND review the "文章版本" of the updated/created post(postID='.$post_id.').', 'sender'=>'hi@aiacademy.tw', )); // update option update_option(OPENING_CLASS_RECENTLY_DATE_OPTION_KEY, now()); } } add_action( 'save_post', 'notify_and_update_opening_class_posts_recently_update' ); function custom_wpadmin_cssjs($hook) { echo''; echo ''; } add_action('admin_footer', 'custom_wpadmin_cssjs'); include_once get_template_directory().'/theme-includes.php'; /* if you want customize the url of author page function add_author_rules() { add_rewrite_rule( "aaaawriter/([^/]+)/?", "index.php?author_name=$matches[1]", "top"); add_rewrite_rule( "aaaawriter/([^/]+)/page/?([0-9]{1,})/?", "index.php?author_name=$matches[1]&paged=$matches[2]", "top"); add_rewrite_rule( "aaaawriter/([^/]+)/(feed|rdf|rss|rss2|atom)/?", "index.php?author_name=$matches[1]&feed=$matches[2]", "top"); add_rewrite_rule( "aaaawriter/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?", "index.php?author_name=$matches[1]&feed=$matches[2]", "top"); } add_action( 'init', 'add_author_rules' );*/ /*/ // Register Custom Post Type function course_post_type() { $labels = array( 'name' => _x( '課程', 'Post Type General Name', 'text_domain' ), 'singular_name' => _x( '課程', 'Post Type Singular Name', 'text_domain' ), 'menu_name' => __( '課程', 'text_domain' ), 'name_admin_bar' => __( '課程', 'text_domain' ), 'archives' => __( '課程 Archives', 'text_domain' ), 'attributes' => __( '課程 Attributes', 'text_domain' ), 'parent_item_colon' => __( 'Parent 課程:', 'text_domain' ), 'all_items' => __( '全部課程', 'text_domain' ), 'add_new_item' => __( 'Add new item課程', 'text_domain' ), 'add_new' => __( '新增課程', 'text_domain' ), 'new_item' => __( '新增課程', 'text_domain' ), 'edit_item' => __( '編緝課程', 'text_domain' ), 'update_item' => __( '更新課程', 'text_domain' ), 'view_item' => __( '查看課程', 'text_domain' ), 'view_items' => __( '查看課程列表', 'text_domain' ), 'search_items' => __( '搜尋課程', 'text_domain' ), 'not_found' => __( 'Not found', 'text_domain' ), 'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ), 'featured_image' => __( '課程主圖', 'text_domain' ), 'set_featured_image' => __( '設定課程主圖', 'text_domain' ), 'remove_featured_image' => __( '移除課程主圖', 'text_domain' ), 'use_featured_image' => __( '使用作為課程主圖', 'text_domain' ), 'insert_into_item' => __( 'Insert into item', 'text_domain' ), 'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ), 'items_list' => __( '課程列表', 'text_domain' ), 'items_list_navigation' => __( '課程列表 navigation', 'text_domain' ), 'filter_items_list' => __( '過瀘 items list', 'text_domain' ), ); $rewrite = array( 'slug' => 'courses0', // http://wordpress.stackexchange.com/questions/94817/ 'with_front' => true, 'pages' => true, 'feeds' => true, ); $args = array( 'label' => __( '課程', 'text_domain' ), 'description' => __( '課程描述', 'text_domain' ), 'labels' => $labels, 'supports' => array( 'title', 'editor','author','thumbnail','excerpt','custom-fields','post-formats','course_tag', 'course_category'), 'taxonomies' => array( 'course_category', 'course_tag' ), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'rewrite' => $rewrite, // 'capability_type' => 'page', ); register_post_type( 'course', $args ); // Create 課程 Categories $labels = array( 'name' => __( '課程 Categories', 'qode' ), 'singular_name' => __( '課程 Category', 'qode' ), 'search_items' => __( 'Search 課程 Categories','qode' ), 'all_items' => __( 'All 課程 Categories','qode' ), 'parent_item' => __( 'Parent 課程 Category','qode' ), 'parent_item_colon' => __( 'Parent 課程 Category:','qode' ), 'edit_item' => __( 'Edit 課程 Category','qode' ), 'update_item' => __( 'Update 課程 Category','qode' ), 'add_new_item' => __( 'Add New 課程 Category','qode' ), 'new_item_name' => __( 'New 課程 Category Name','qode' ), 'menu_name' => __( '課程 Categories','qode' ), ); register_taxonomy('course_category',array('course'), array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'course-category' ), 'show_admin_column' => true )); // Create 課程 Tags $labels = array( 'name' => __( '課程 Tags', 'qode' ), 'singular_name' => __( '課程 Tag', 'qode' ), 'search_items' => __( 'Search 課程 Tags','qode' ), 'all_items' => __( 'All 課程 Tags','qode' ), 'parent_item' => __( 'Parent 課程 Tag','qode' ), 'parent_item_colon' => __( 'Parent 課程 Tags:','qode' ), 'edit_item' => __( 'Edit 課程 Tag','qode' ), 'update_item' => __( 'Update 課程 Tag','qode' ), 'add_new_item' => __( 'Add New 課程 Tag','qode' ), 'new_item_name' => __( 'New 課程 Tag Name','qode' ), 'menu_name' => __( '課程 Tags','qode' ), ); register_taxonomy('course_tag',array('course'), array( 'hierarchical' => false, 'labels' => $labels, 'show_ui' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'course-tag' ), )); } add_action( 'init', 'course_post_type', 0 ); /////////// function wpa_course_post_link( $post_link, $id = 0 ){ $post = get_post($id); if ( is_object( $post ) ){ $terms = wp_get_object_terms( $post->ID, 'course' ); if( $terms ){ return str_replace( '%coursecategory%' , $terms[0]->slug , $post_link ); } } return $post_link; } add_filter( 'post_type_link', 'wpa_course_post_link', 1, 3 );//*/ /* add_filter( 'posts_join', 'posts_join2' ); function posts_join2( $where ) { // http://wordpress.stackexchange.com/questions/50305/how-to-extend-wp-query-to-include-custom-table-in-query return $where; } add_filter( 'posts_where', 'posts_where2' ); function posts_where2( $join ) { // http://wordpress.stackexchange.com/questions/50305/how-to-extend-wp-query-to-include-custom-table-in-query return $join; } */ if(isset($qode_toolbar) && $qode_toolbar === true) { if (!function_exists('myStartSession')) { /** * Function that sets session after theme is activated hook. Hooks to after_setup_theme action */ function myStartSession() { if(!session_id()) { session_start(); } if (!empty($_GET['animation'])) { $_SESSION['qode_animation'] = $_GET['animation']; } if (isset($_SESSION['qode_animation']) && $_SESSION['qode_animation'] == "off") { $_SESSION['qode_animation'] = ""; } } add_action('after_setup_theme', 'myStartSession', 1); } if (!function_exists('myEndSession')) { /** * Function that ends session on wp_login and wp_logout action */ function myEndSession() { session_destroy(); } add_action('wp_logout', 'myEndSession'); add_action('wp_login', 'myEndSession'); } } /* Add css */ if (!function_exists('qode_styles')) { function qode_styles() { if(IS_V2){return;} global $qode_options_proya; global $wp_styles; global $is_chrome; global $is_safari; global $qode_toolbar; global $qode_landing; global $qode_tour_popup; global $woocommerce; wp_enqueue_style("default_style", QODE_ROOT . "/style.css"); qode_icon_collections()->enqueueStyles(); wp_enqueue_style("stylesheet", QODE_ROOT . "/css/stylesheet.min.css"); /* no need woocommerce if ($woocommerce) { wp_enqueue_style("woocommerce", QODE_ROOT . "/css/woocommerce.min.css"); if(!empty($qode_options_proya['responsiveness']) && $qode_options_proya['responsiveness'] == 'yes') { wp_enqueue_style("woocommerce_responsive", QODE_ROOT . "/css/woocommerce_responsive.min.css"); } } */ wp_enqueue_style("qode_print", QODE_ROOT . "/css/print.css"); preg_match( "#Chrome/(.+?)\.#", $_SERVER['HTTP_USER_AGENT'], $match ); if(!empty($match)){ $version = $match[1];}else{ $version = 0; } $mac_os = strpos($_SERVER['HTTP_USER_AGENT'], "Macintosh; Intel Mac OS X"); /* if($is_chrome && ($mac_os !== false) && ($version > 21)) { wp_enqueue_style("mac_stylesheet", QODE_ROOT . "/css/mac_stylesheet.css"); } */ if($is_chrome || $is_safari) { wp_enqueue_style("webkit", QODE_ROOT . "/css/webkit_stylesheet.css"); } /* if($is_safari) { wp_enqueue_style("safari", QODE_ROOT . "/css/safari_stylesheet.css"); } */ if (file_exists(dirname(__FILE__) ."/css/style_dynamic.css") && qode_is_css_folder_writable() && !is_multisite()) { wp_enqueue_style("style_dynamic", QODE_ROOT . "/css/style_dynamic.css", array(), filemtime(dirname(__FILE__) ."/css/style_dynamic.css")); } else { wp_enqueue_style("style_dynamic", QODE_ROOT . "/css/style_dynamic.php"); } $responsiveness = "yes"; if (isset($qode_options_proya['responsiveness'])) $responsiveness = $qode_options_proya['responsiveness']; if ($responsiveness != "no"): wp_enqueue_style("responsive", QODE_ROOT . "/css/responsive.min.css"); if (file_exists(dirname(__FILE__) ."/css/style_dynamic_responsive.css") && qode_is_css_folder_writable() && !is_multisite()) wp_enqueue_style("style_dynamic_responsive", QODE_ROOT . "/css/style_dynamic_responsive.css", array(), filemtime(dirname(__FILE__) ."/css/style_dynamic_responsive.css")); else wp_enqueue_style("style_dynamic_responsive", QODE_ROOT . "/css/style_dynamic_responsive.php"); endif; $vertical_area = "no"; if (isset($qode_options_proya['vertical_area'])){ $vertical_area = $qode_options_proya['vertical_area']; } if($vertical_area == "yes" && $responsiveness != "no"){ wp_enqueue_style("vertical_responsive", QODE_ROOT . "/css/vertical_responsive.min.css"); } //is toolbar turned on? if (isset($qode_toolbar)) { //include toolbar specific styles wp_enqueue_style("qode_toolbar", QODE_ROOT . "/css/toolbar.css"); } //is landing turned on? if (isset($qode_landing)) { //include landing page specific styles wp_enqueue_style("qode_landing", get_home_url() . "/demo-files/landing/css/landing_stylesheet_stripped.css"); } //is tour popup on? if (isset($qode_tour_popup)) { //include tour popup specific styles wp_enqueue_style("qode_tour_popup", get_home_url() . "/demo-files/landing/css/tour_popup_stylesheet.css"); } //include Visual Composer styles if (class_exists('WPBakeryVisualComposerAbstract')) { wp_enqueue_style( 'js_composer_front' ); } if(is_rtl()) { wp_enqueue_style('qode-rtl', QODE_ROOT.'/rtl.css'); } if (file_exists(dirname(__FILE__) ."/css/custom_css.css") && qode_is_css_folder_writable() && !is_multisite()) wp_enqueue_style("custom_css", QODE_ROOT . "/css/custom_css.css", array(), filemtime(dirname(__FILE__) ."/css/custom_css.css")); else wp_enqueue_style("custom_css", QODE_ROOT . "/css/custom_css.php"); } add_action('wp_enqueue_scripts', 'qode_styles'); } if(!function_exists('qode_google_fonts_styles')) { /** * Function that includes google fonts defined anywhere in the theme */ function qode_google_fonts_styles() { if(IS_V2){ echo''; echo''; echo''; return; } global $qode_options_proya, $qodeFramework, $qode_toolbar; $font_weight_str = '100,200,300,400,500,600,700,800,900,300italic,400italic'; $default_font_string = 'Raleway:'.$font_weight_str; $font_sipmle_field_array = array(); if(is_array($qodeFramework->qodeOptions->getOptionsByType('fontsimple')) && count($qodeFramework->qodeOptions->getOptionsByType('fontsimple'))){ $font_sipmle_field_array = $qodeFramework->qodeOptions->getOptionsByType('fontsimple'); } $font_field_array = array(); if(is_array($qodeFramework->qodeOptions->getOptionsByType('font')) && count($qodeFramework->qodeOptions->getOptionsByType('font'))){ $font_field_array = $qodeFramework->qodeOptions->getOptionsByType('font'); } $available_font_options = array_merge($font_sipmle_field_array, $font_field_array); //define available font options array $fonts_array = array(); foreach($available_font_options as $font_option) { //is font set and not set to default and not empty? if(isset($qode_options_proya[$font_option]) && $qode_options_proya[$font_option] !== '-1' && $qode_options_proya[$font_option] !== '' && !qode_is_native_font($qode_options_proya[$font_option])) { $font_option_string = $qode_options_proya[$font_option].':'.$font_weight_str; if(!in_array($font_option_string, $fonts_array)) { $fonts_array[] = $font_option_string; } } } //add google fonts set in slider $args = array( 'post_type' => 'slides', 'posts_per_page' => -1); $loop = new WP_Query( $args ); //for each slide defined while ( $loop->have_posts() ) : $loop->the_post(); //is font family for title option chosen? if(get_post_meta(get_the_ID(), "qode_slide-title-font-family", true) != "") { $slide_title_font_family = get_post_meta(get_the_ID(), "qode_slide-title-font-family", true); $slide_title_font_string = $slide_title_font_family . ":".$font_weight_str; if(!in_array($slide_title_font_string, $fonts_array) && !qode_is_native_font($slide_title_font_family)) { //include that font array_push($fonts_array, $slide_title_font_string); } } //is font family defined for slide's text? if(get_post_meta(get_the_ID(), "qode_slide-text-font-family", true) != "") { $slide_text_font_family = get_post_meta(get_the_ID(), "qode_slide-text-font-family", true); $slide_text_font_string = $slide_text_font_family . ":".$font_weight_str; if(!in_array($slide_text_font_string, $fonts_array) && !qode_is_native_font($slide_text_font_family)) { //include that font array_push($fonts_array, $slide_text_font_string); } } //is font family defined for slide's subtitle? if(get_post_meta(get_the_ID(), "qode_slide-subtitle-font-family", true) != "") { $slide_subtitle_font_family = get_post_meta(get_the_ID(), "qode_slide-subtitle-font-family", true); $slide_subtitle_font_string = $slide_subtitle_font_family .":".$font_weight_str; if(!in_array($slide_subtitle_font_string, $fonts_array) && !qode_is_native_font($slide_subtitle_font_family)) { //include that font array_push($fonts_array, $slide_subtitle_font_string); } } endwhile; wp_reset_postdata(); $fonts_array = array_diff($fonts_array, array("-1:".$font_weight_str)); $google_fonts_string = implode( '|', $fonts_array); //is google font option checked anywhere in theme? if(count($fonts_array) > 0) { //include all checked fonts printf("\r\n", str_replace(' ', '+', $google_fonts_string)); } else { //include default google font that theme is using printf("\r\n"); } if(isset($qode_toolbar)){ printf("\r\n"); } } add_action('wp_enqueue_scripts', 'qode_google_fonts_styles'); } /* Add js */ if (!function_exists('qode_scripts')) { function qode_scripts() { if(IS_V2){return;} global $qode_options_proya; global $is_chrome; global $is_opera; global $is_IE; global $qode_toolbar; global $qode_landing; global $qode_tour_popup; global $woocommerce; $smooth_scroll = true; if(isset($qode_options_proya['smooth_scroll']) && $qode_options_proya['smooth_scroll'] == "no"){ $smooth_scroll = false; } wp_enqueue_script("jquery"); wp_enqueue_script("plugins", QODE_ROOT."/js/plugins.js",array(),false,true); # 20170725 cannot remove, this is for menu-hover AND logo-responsive /*20170724 #wp_enqueue_script("carouFredSel", QODE_ROOT."/js/jquery.carouFredSel-6.2.1.min.js",array(),false,true); #wp_enqueue_script("lemmonSlider", QODE_ROOT."/js/lemmon-slider.min.js",array(),false,true); #wp_enqueue_script("one_page_scroll", QODE_ROOT."/js/jquery.fullPage.min.js",array(),false,true); #wp_enqueue_script("mousewheel", QODE_ROOT."/js/jquery.mousewheel.min.js",array(),false,true); #wp_enqueue_script("touchSwipe", QODE_ROOT."/js/jquery.touchSwipe.min.js",array(),false,true); #wp_enqueue_script("isotope", QODE_ROOT."/js/jquery.isotope.min.js",array(),false,true); #wp_enqueue_script("stretch", QODE_ROOT."/js/jquery.stretch.js",array(),false,true); */ $mac_os = strpos($_SERVER['HTTP_USER_AGENT'], "Macintosh; Intel Mac OS X"); /*20170725 if($smooth_scroll && $mac_os == false){ wp_enqueue_script("TweenLite", QODE_ROOT."/js/TweenLite.min.js",array(),false,true); if(!qode_layer_slider_installed() || !qode_revolution_slider_installed()){ wp_enqueue_script("ScrollToPlugin", QODE_ROOT."/js/ScrollToPlugin.min.js",array(),false,true); } wp_enqueue_script("smoothPageScroll", QODE_ROOT."/js/smoothPageScroll.min.js",array(),false,true); }*/ if ( $is_IE ) { wp_enqueue_script("html5", QODE_ROOT."/js/html5.js",array(),false,false); } if((isset($qode_options_proya['enable_google_map']) && $qode_options_proya['enable_google_map'] == "yes") || qode_is_ajax_enabled() || qode_has_google_map_shortcode()) : if( (isset($qode_options_proya['google_maps_api_key']) && $qode_options_proya['google_maps_api_key'] != "")) { $google_maps_api_key = $qode_options_proya['google_maps_api_key']; wp_enqueue_script("google_map_api", "https://maps.googleapis.com/maps/api/js?key=" . $google_maps_api_key,array(),false,true); } else { wp_enqueue_script("google_map_api", "https://maps.googleapis.com/maps/api/js",array(),false,true); } endif; /*20170724 cannot remove. Otherwise, we will lose min_header_height_scroll which is default.min.js need*/ if (file_exists(dirname(__FILE__) ."/js/default_dynamic.js") && qode_is_js_folder_writable() && !is_multisite()) { wp_enqueue_script("default_dynamic", QODE_ROOT."/js/default_dynamic.js",array(), filemtime(dirname(__FILE__) ."/js/default_dynamic.js"),true); } else { wp_enqueue_script("default_dynamic", QODE_ROOT."/js/default_dynamic.php",array(),false,true); } #20170724 cannot remove. Otherwise, the navigator hover will be broken. wp_enqueue_script("default", QODE_ROOT."/js/default.min.js",array(),false,true); /*20170724 if (file_exists(dirname(__FILE__) ."/js/custom_js.js") && qode_is_js_folder_writable() && !is_multisite()) { wp_enqueue_script("custom_js", QODE_ROOT."/js/custom_js.js",array(), filemtime(dirname(__FILE__) ."/js/custom_js.js"),true); } else { wp_enqueue_script("custom_js", QODE_ROOT."/js/custom_js.php",array(),false,true); } */ global $wp_scripts; $wp_scripts->add_data('comment-reply', 'group', 1 ); if ( is_singular() ) wp_enqueue_script( "comment-reply"); $has_ajax = false; $qode_animation = ""; if (isset($_SESSION['qode_proya_page_transitions'])) $qode_animation = $_SESSION['qode_proya_page_transitions']; if (($qode_options_proya['page_transitions'] != "0") && (empty($qode_animation) || ($qode_animation != "no"))) $has_ajax = true; elseif (!empty($qode_animation) && ($qode_animation != "no")) $has_ajax = true; if ($has_ajax) : wp_enqueue_script("ajax", QODE_ROOT."/js/ajax.min.js",array(),false,true); endif; wp_enqueue_script( 'wpb_composer_front_js' ); if(isset($qode_options_proya['use_recaptcha']) && $qode_options_proya['use_recaptcha'] == "yes") : wp_enqueue_script("recaptcha_ajax", "http://www.google.com/recaptcha/api/js/recaptcha_ajax.js",array(),false,true); endif; //is toolbar enabled? if(isset($qode_toolbar)) { //include toolbar specific script wp_enqueue_script("qode_toolbar", QODE_ROOT."/js/toolbar.js",array(),false,true); } //is landing enabled? if(isset($qode_landing)) { wp_enqueue_script("mixitup", get_home_url() . "/demo-files/landing/js/jquery.mixitup.js",array(),false,true); wp_enqueue_script("mixitup_pagination", get_home_url() . "/demo-files/landing/js/jquery.mixitup-pagination.js",array(),false,true); wp_enqueue_script("qode_cookie", get_home_url() . "/demo-files/landing/js/js.cookie.js",array(),false,true); wp_enqueue_script("qode_landing", get_home_url() . "/demo-files/landing/js/landing_default.js",array(),false,true); } //is tour popup enabled? if(isset($qode_tour_popup)) { wp_enqueue_script("qode_cookie", get_home_url() . "/demo-files/landing/js/js.cookie.js",array(),false,true); wp_enqueue_script("qode_tour_popup", get_home_url() . "/demo-files/landing/js/tour_popup_default.js",array(),false,true); } if($woocommerce) { wp_enqueue_script("woocommerce-qode", QODE_ROOT."/js/woocommerce.js",array(),false,true); wp_enqueue_script("select2", QODE_ROOT."/js/select2.min.js",array(),false,true); } } add_action('wp_enqueue_scripts', 'qode_scripts'); } /*Because of the bug when Revolution slider, Layer Slider and Smooth Scroll are enabled together (greensock.js doesn't have included ScrollTo so it need to be included before)*/ if(!function_exists('qode_scrollto_script')) { function qode_scrollto_script(){ global $qode_options_proya; $smooth_scroll = true; if(isset($qode_options_proya['smooth_scroll']) && $qode_options_proya['smooth_scroll'] == "no"){ $smooth_scroll = false; } $mac_os = strpos($_SERVER['HTTP_USER_AGENT'], "Macintosh; Intel Mac OS X"); if($smooth_scroll && $mac_os == false && qode_layer_slider_installed() && qode_revolution_slider_installed()) { wp_enqueue_script("ScrollToPlugin", QODE_ROOT . "/js/ScrollToPlugin.min.js", array(), false, false); } } add_action('wp_enqueue_scripts', 'qode_scrollto_script', 1); } if(!function_exists('qode_init_page_id')) { /** * Function that sets global $qode_page_id variable */ function qode_init_page_id() { global $wp_query; global $qode_page_id; $qode_page_id = $wp_query->get_queried_object_id(); } add_action('get_header', 'qode_init_page_id'); } /* Add admin js and css */ if (!function_exists('qode_admin_jquery')) { function qode_admin_jquery() { wp_enqueue_script('jquery'); wp_enqueue_style('style', QODE_ROOT.'/css/admin/admin-style.css', false, '1.0', 'screen'); wp_enqueue_style('colorstyle', QODE_ROOT.'/css/admin/colorpicker.css', false, '1.0', 'screen'); wp_register_script('colorpickerss', QODE_ROOT.'/js/admin/colorpicker.js', array('jquery'), '1.0.0', false ); wp_enqueue_script('colorpickerss'); wp_enqueue_style('thickbox'); wp_enqueue_script('media-upload'); wp_enqueue_media(); wp_enqueue_script('thickbox'); wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_script('jquery-ui-accordion'); wp_register_script('default', QODE_ROOT.'/js/admin/default.js', array('jquery'), '1.0.0', false ); wp_enqueue_script('default'); wp_enqueue_script('common'); wp_enqueue_script('wp-lists'); wp_enqueue_script('postbox'); } } add_action('admin_enqueue_scripts', 'qode_admin_jquery'); if (!isset( $content_width )) $content_width = 1060; /* Register Menus */ if (!function_exists('qode_register_menus')) { /** * Function that registers menu positions */ function qode_register_menus() { global $qode_options_proya; if((isset($qode_options_proya['header_bottom_appearance']) && $qode_options_proya['header_bottom_appearance'] != "stick_with_left_right_menu") || (isset($qode_options_proya['vertical_area']) && $qode_options_proya['vertical_area'] == "yes")){ //header and left menu location register_nav_menus( array('top-navigation' => __( 'Top Navigation', 'qode') ) ); } //popup menu location register_nav_menus( array('popup-navigation' => __( 'Fullscreen Navigation', 'qode') ) ); if((isset($qode_options_proya['header_bottom_appearance']) && $qode_options_proya['header_bottom_appearance'] == "stick_with_left_right_menu") && (isset($qode_options_proya['vertical_area']) && $qode_options_proya['vertical_area'] == "no")){ //header left menu location register_nav_menus( array('left-top-navigation' => __( 'Left Top Navigation', 'qode') ) ); //header right menu location register_nav_menus( array('right-top-navigation' => __( 'Right Top Navigation', 'qode') ) ); } } add_action( 'after_setup_theme', 'qode_register_menus' ); } if(!function_exists('qode_theme_setup')) { /** * Function that adds various features to theme. Also defines image sizes that are used in a theme */ function qode_theme_setup() { //add post formats support add_theme_support('post-formats', array('gallery', 'link', 'quote', 'video', 'audio')); //add feedlinks support add_theme_support( 'automatic-feed-links' ); //add theme support for post thumbnails add_theme_support( 'post-thumbnails' ); add_image_size( 'portfolio-square', 570, 570, true ); add_image_size( 'portfolio-portrait', 600, 800, true ); add_image_size( 'portfolio-landscape', 800, 600, true ); add_image_size( 'menu-featured-post', 345, 198, true ); add_image_size( 'qode-carousel_slider', 400, 260, true ); add_image_size( 'portfolio_slider', 500, 380, true ); add_image_size( 'portfolio_masonry_regular', 500, 500, true ); add_image_size( 'portfolio_masonry_wide', 1000, 500, true ); add_image_size( 'portfolio_masonry_tall', 500, 1000, true ); add_image_size( 'portfolio_masonry_large', 1000, 1000, true ); add_image_size( 'portfolio_masonry_with_space', 700); add_image_size( 'latest_post_boxes', 539, 303, true ); //enable rendering shortcodes in widgets add_filter('widget_text', 'do_shortcode'); //enable rendering shortcodes in post excerpt //add_filter( 'the_excerpt', 'do_shortcode'); //enable rendering shortcodes in call to action add_filter( 'call_to_action_widget', 'do_shortcode'); load_theme_textdomain( 'qode', get_template_directory().'/languages' ); } add_action('after_setup_theme', 'qode_theme_setup'); } if (!function_exists('ajax_classes')) { /** * Function that adds classes for ajax animation on body element * @param $classes array of current body classes * @return array array of changed body classes */ function ajax_classes($classes) { global $qode_options_proya; $qode_animation=""; if (isset($_SESSION['qode_animation'])) $qode_animation = $_SESSION['qode_animation']; if(($qode_options_proya['page_transitions'] === "0") && ($qode_animation == "no")) : $classes[] = ''; elseif($qode_options_proya['page_transitions'] === "1" && (empty($qode_animation) || ($qode_animation != "no"))) : $classes[] = 'ajax_updown'; $classes[] = 'page_not_loaded'; elseif($qode_options_proya['page_transitions'] === "2" && (empty($qode_animation) || ($qode_animation != "no"))) : $classes[] = 'ajax_fade'; $classes[] = 'page_not_loaded'; elseif($qode_options_proya['page_transitions'] === "3" && (empty($qode_animation) || ($qode_animation != "no"))) : $classes[] = 'ajax_updown_fade'; $classes[] = 'page_not_loaded'; elseif($qode_options_proya['page_transitions'] === "4" && (empty($qode_animation) || ($qode_animation != "no"))) : $classes[] = 'ajax_leftright'; $classes[] = 'page_not_loaded'; elseif(!empty($qode_animation) && $qode_animation != "no") : $classes[] = 'page_not_loaded'; else: $classes[] =""; endif; return $classes; } add_filter('body_class','ajax_classes'); } /* Add class on body boxed layout */ if (!function_exists('boxed_class')) { /** * Function that adds class on body for boxed layout * @param $classes array of current body classes * @return array array of changed body classes */ function boxed_class($classes) { global $qode_options_proya; if(isset($qode_options_proya['boxed']) && $qode_options_proya['boxed'] == "yes" && isset($qode_options_proya['transparent_content']) && $qode_options_proya['transparent_content'] == 'no') : $classes[] = 'boxed'; else: $classes[] =""; endif; return $classes; } add_filter('body_class','boxed_class'); } /* Add class on body for vertical menu */ if (!function_exists('vertical_menu_class')) { /** * Function that adds classes on body element for vertical menu * @param $classes array of current body classes * @return array array of changed body classes */ function vertical_menu_class($classes) { global $qode_options_proya; global $wp_query; if(isset($qode_options_proya['vertical_area']) && $qode_options_proya['vertical_area'] =='yes') { $classes[] = 'vertical_menu_enabled'; //left menu type class? if(isset($qode_options_proya['vertical_area_type']) && $qode_options_proya['vertical_area_type'] != '') { switch ($qode_options_proya['vertical_area_type']) { case 'hidden': $classes[] = ' vertical_menu_hidden'; if(isset($qode_options_proya['vertical_logo_bottom']) && $qode_options_proya['vertical_logo_bottom'] !== '') { $classes[] = 'vertical_menu_hidden_with_logo'; } break; } } if(isset($qode_options_proya['vertical_area_type']) && $qode_options_proya['vertical_area_type'] =='hidden') { if(isset($qode_options_proya['vertical_area_width']) && $qode_options_proya['vertical_area_width']=='width_290'){ $classes[] = ' vertical_menu_width_290'; } elseif(isset($qode_options_proya['vertical_area_width']) && $qode_options_proya['vertical_area_width']=='width_350'){ $classes[] = ' vertical_menu_width_350'; } elseif(isset($qode_options_proya['vertical_area_width']) && $qode_options_proya['vertical_area_width']=='width_400'){ $classes[] = ' vertical_menu_width_400'; } else{ $classes[] = ' vertical_menu_width_260'; } } } $id = $wp_query->get_queried_object_id(); if(qode_is_woocommerce_page()) { $id = get_option('woocommerce_shop_page_id'); } if(isset($qode_options_proya['vertical_area_transparency']) && $qode_options_proya['vertical_area_transparency'] =='yes' && get_post_meta($id, "qode_page_vertical_area_transparency", true) != "no"){ $classes[] = ' vertical_menu_transparency vertical_menu_transparency_on'; }else if(get_post_meta($id, "qode_page_vertical_area_transparency", true) == "yes"){ $classes[] = ' vertical_menu_transparency vertical_menu_transparency_on'; } return $classes; } add_filter('body_class','vertical_menu_class'); } if (!function_exists('elements_animation_on_touch_class')) { /** * Function that adds classes on body element for disabled animations on touch devices * @param $classes array of current body classes * @return array array of changed body classes */ function elements_animation_on_touch_class($classes) { global $qode_options_proya; $isMobile = (bool)preg_match('#\b(ip(hone|od|ad)|android|opera m(ob|in)i|windows (phone|ce)|blackberry|tablet'. '|s(ymbian|eries60|amsung)|p(laybook|alm|rofile/midp|laystation portable)|nokia|fennec|htc[\-_]'. '|mobile|up\.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\b#i', $_SERVER['HTTP_USER_AGENT'] ); if(isset($qode_options_proya['elements_animation_on_touch']) && $qode_options_proya['elements_animation_on_touch'] == "no" && $isMobile == true) : $classes[] = 'no_animation_on_touch'; else: $classes[] =""; endif; return $classes; } add_filter('body_class','elements_animation_on_touch_class'); } /* Add class on body for content negative margin */ if (!function_exists('content_negative_margin')) { /** * Function that adds classes on body element for negative margin for content * @param $classes array of current body classes * @return array array of changed body classes */ function content_negative_margin($classes) { global $qode_options_proya; if(isset($qode_options_proya['vertical_area']) && $qode_options_proya['vertical_area'] =='no' && isset($qode_options_proya['move_content_up']) && $qode_options_proya['move_content_up'] == 'yes'){ $classes[] = 'content_top_margin'; } return $classes; } add_filter('body_class','content_negative_margin'); } if(!function_exists('qode_hidden_title_body_class')) { /** * Function that adds class to body element if title is hidden for current page * @param $classes array of currently added classes for body element * @return array array of modified classes */ function qode_hidden_title_body_class($classes) { $page_id = qode_get_page_id(); if($page_id) { if(qode_is_title_hidden()) { $classes[] = 'qode-title-hidden'; } } return $classes; } add_filter('body_class', 'qode_hidden_title_body_class'); } if(!function_exists('qode_paspartu_body_class')) { /** * Function that adds paspartu class to body. * @param $classes array of body classes * @return array with paspartu body class added */ function qode_paspartu_body_class($classes) { global $qode_options_proya; if(isset($qode_options_proya['paspartu']) && $qode_options_proya['paspartu'] == 'yes') { $classes[] = 'paspartu_enabled'; if((isset($qode_options_proya['paspartu_on_top']) && $qode_options_proya['paspartu_on_top'] == 'yes' && isset($qode_options_proya['paspartu_on_top_fixed']) && $qode_options_proya['paspartu_on_top_fixed'] == 'yes') || (isset($qode_options_proya['vertical_area']) && $qode_options_proya['vertical_area'] == "yes" && isset($qode_options_proya['vertical_menu_inside_paspartu']) && $qode_options_proya['vertical_menu_inside_paspartu'] == 'yes')) { $classes[] = 'paspartu_on_top_fixed'; } if((isset($qode_options_proya['paspartu_on_bottom']) && $qode_options_proya['paspartu_on_bottom'] == 'yes' && isset($qode_options_proya['paspartu_on_bottom_fixed']) && $qode_options_proya['paspartu_on_bottom_fixed'] == 'yes') || (isset($qode_options_proya['vertical_area']) && $qode_options_proya['vertical_area'] == "yes" && isset($qode_options_proya['vertical_menu_inside_paspartu']) && $qode_options_proya['vertical_menu_inside_paspartu'] == 'yes')) { $classes[] = 'paspartu_on_bottom_fixed'; } if(isset($qode_options_proya['vertical_area']) && $qode_options_proya['vertical_area'] == "yes" && isset($qode_options_proya['vertical_menu_inside_paspartu']) && $qode_options_proya['vertical_menu_inside_paspartu'] == 'no') { $classes[] = 'vertical_menu_outside_paspartu'; } if(isset($qode_options_proya['vertical_area']) && $qode_options_proya['vertical_area'] == "yes" && isset($qode_options_proya['vertical_menu_inside_paspartu']) && $qode_options_proya['vertical_menu_inside_paspartu'] == 'yes') { $classes[] = 'vertical_menu_inside_paspartu'; } } return $classes; } add_filter('body_class', 'qode_paspartu_body_class'); } /* Add class on body depending on content width */ if (!function_exists('qode_content_width_class')) { /** * Function that adds class on body depending on content width * @param $classes array of current body classes * @return array array of changed body classes */ function qode_content_width_class($classes){ global $qode_options_proya; $classes[] = ""; if (isset($qode_options_proya['initial_content_width']) && $qode_options_proya['initial_content_width'] !== "grid_1100") { $classes[] = 'qode_' . $qode_options_proya['initial_content_width']; } return $classes; } add_filter('body_class','qode_content_width_class'); } if(!function_exists('qode_side_menu_body_class')) { /** * Function that adds body classes for different side menu styles * @param $classes array original array of body classes * @return array modified array of classes */ function qode_side_menu_body_class($classes) { global $qode_options_proya; if(isset($qode_options_proya['enable_side_area']) && $qode_options_proya['enable_side_area'] == 'yes') { if(isset($qode_options_proya['side_area_type']) && $qode_options_proya['side_area_type'] == 'side_menu_slide_from_right') { $classes[] = 'side_menu_slide_from_right'; } else if(isset($qode_options_proya['side_area_type']) && $qode_options_proya['side_area_type'] == 'side_menu_slide_with_content') { $classes[] = 'side_menu_slide_with_content'; $classes[] = $qode_options_proya['side_area_slide_with_content_width']; } else { $classes[] = 'side_area_uncovered_from_content'; } } return $classes; } add_filter('body_class', 'qode_side_menu_body_class'); } if(!function_exists('qode_full_screen_menu_body_class')) { /** * Function that adds body classes for different full screen menu types * @param $classes array original array of body classes * @return array modified array of classes */ function qode_full_screen_menu_body_class($classes) { global $qode_options_proya; if(isset($qode_options_proya['enable_popup_menu']) && $qode_options_proya['enable_popup_menu'] == 'yes') { if(isset($qode_options_proya['popup_menu_animation_style']) && !empty($qode_options_proya['popup_menu_animation_style'])) { $classes[] = 'qode_' . $qode_options_proya['popup_menu_animation_style']; } } return $classes; } add_filter('body_class', 'qode_full_screen_menu_body_class'); } if(!function_exists('qode_overlapping_content_body_class')) { /** * Function that adds transparent content class to body. * @param $classes array of body classes * @return array with transparent content body class added */ function qode_overlapping_content_body_class($classes) { global $qode_options_proya; if(isset($qode_options_proya['overlapping_content']) && $qode_options_proya['overlapping_content'] == 'yes') { $classes[] = 'overlapping_content'; } return $classes; } add_filter('body_class', 'qode_overlapping_content_body_class'); } if(!function_exists('qode_vss_responsive_body_class')) { /** * Function that adds vertical split slider responsive class to body. * @param $classes array of body classes * @return array with vertical split slider responsive body class added */ function qode_vss_responsive_body_class($classes) { global $qode_options_proya; if(isset($qode_options_proya['vss_responsive_advanced']) && $qode_options_proya['vss_responsive_advanced'] == 'yes') { $classes[] = 'vss_responsive_adv'; } return $classes; } add_filter('body_class', 'qode_vss_responsive_body_class'); } if(!function_exists('qode_footer_responsive_body_class')) { /** * Function that adds footer responsive class to body. * @param $classes array of body classes */ function qode_footer_responsive_body_class($classes) { global $qode_options_proya; if(isset($qode_options_proya['footer_top_responsive']) && $qode_options_proya['footer_top_responsive'] === 'yes') { $classes[] = 'footer_responsive_adv'; } return $classes; } add_filter('body_class', 'qode_footer_responsive_body_class'); } if(!function_exists('qode_top_header_responsive_body_class')) { function qode_top_header_responsive_body_class($classes) { global $qode_options_proya; if(isset($qode_options_proya['hide_top_bar_on_mobile']) && $qode_options_proya['hide_top_bar_on_mobile'] === 'yes') { $classes[] = 'hide_top_bar_on_mobile_header'; } return $classes; } add_filter('body_class', 'qode_top_header_responsive_body_class'); } if(!function_exists('qode_content_sidebar_responsive_body_class')) { function qode_content_sidebar_responsive_body_class($classes) { global $qode_options_proya; if(isset($qode_options_proya['content_sidebar_responsiveness']) && $qode_options_proya['content_sidebar_responsiveness'] === 'yes') { $classes[] = 'qode-content-sidebar-responsive'; } return $classes; } add_filter('body_class', 'qode_content_sidebar_responsive_body_class'); } if(!function_exists('qode_transparent_content_body_class')) { /** * Function that adds transparent content class to body. * @param $classes array of body classes * @return array with transparent content body class added */ function qode_transparent_content_body_class($classes) { global $qode_options_proya; if(isset($qode_options_proya['transparent_content']) && $qode_options_proya['transparent_content'] == 'yes') { $classes[] = 'transparent_content'; } return $classes; } add_filter('body_class', 'qode_transparent_content_body_class'); } if(!function_exists('qode_is_title_hidden')) { /** * Function that check is title hidden on current page * @param none * @return true/false */ function qode_is_title_hidden() { global $qode_options_proya; $page_id = qode_get_page_id(); $hide_page_title_area = false; if(get_post_meta($page_id, "qode_show-page-title", true) === 'yes'){ $hide_page_title_area = true; }elseif(get_post_meta($page_id, "qode_show-page-title", true) === 'no'){ $hide_page_title_area = false; }else{ if(isset($qode_options_proya['dont_show_page_title']) && ($qode_options_proya['dont_show_page_title'] === 'yes')){ $hide_page_title_area = true; }elseif(isset($qode_options_proya['dont_show_page_title']) && ($qode_options_proya['dont_show_page_title'] === 'no')){ $hide_page_title_area = false; } } return $hide_page_title_area; } } if(!function_exists('qode_is_title_text_hidden')) { /** * Function that check is title text hidden on current page * @param none * @return true/false */ function qode_is_title_text_hidden() { global $qode_options_proya; $page_id = qode_get_page_id(); $hide_page_title_text = false; if(get_post_meta($page_id, "qode_show-page-title-text", true) === 'yes'){ $hide_page_title_text = true; }elseif(get_post_meta($page_id, "qode_show-page-title-text", true) === 'no'){ $hide_page_title_text = false; }else{ if(isset($qode_options_proya['dont_show_page_title_text']) && ($qode_options_proya['dont_show_page_title_text'] === 'yes')){ $hide_page_title_text = true; }elseif(isset($qode_options_proya['dont_show_page_title_text']) && ($qode_options_proya['dont_show_page_title_text'] === 'no')){ $hide_page_title_text = false; } } return $hide_page_title_text; } } if(!function_exists('qode_is_content_below_header')) { /** * Function that check is content below header on page * @param none * @return true/false */ function qode_is_content_below_header() { global $qode_options_proya; $page_id = qode_get_page_id(); $content_below_header = false; if(get_post_meta($page_id, "qode_enable_content_top_margin", true) === 'yes'){ $content_below_header = true; }elseif(get_post_meta($page_id, "qode_enable_content_top_margin", true) === 'no'){ $content_below_header = false; }else{ if(isset($qode_options_proya['enable_content_top_margin']) && ($qode_options_proya['enable_content_top_margin'] === 'yes')){ $content_below_header = true; }elseif(isset($qode_options_proya['enable_content_top_margin']) && ($qode_options_proya['enable_content_top_margin'] === 'no')){ $content_below_header = false; } } return $content_below_header; } } /* Excerpt more */ if (!function_exists('qode_excerpt_more')) { /** * Function that adds three dots on excerpt * @param $more string current more string * @return string changed more string */ function qode_excerpt_more( $more ) { return '...'; } add_filter('excerpt_more', 'qode_excerpt_more'); } if (!function_exists('qode_excerpt_length')) { /** * Function that changes excerpt length based on theme options * @param $length int original value * @return int changed value */ function qode_excerpt_length( $length ) { global $qode_options_proya; if($qode_options_proya['number_of_chars']){ return $qode_options_proya['number_of_chars']; } else { return 45; } } add_filter( 'excerpt_length', 'qode_excerpt_length', 999 ); } if (!function_exists('the_excerpt_max_charlength')) { /** * Function that sets character length for social share shortcode * @param $charlength string original text * @return string shortened text */ function the_excerpt_max_charlength($charlength) { global $qode_options_proya; if(isset($qode_options_proya['twitter_via']) && !empty($qode_options_proya['twitter_via'])) { $via = " via " . $qode_options_proya['twitter_via'] . " "; } else { $via = ""; } $excerpt = get_the_excerpt(); $charlength = 140 - (mb_strlen($via) + $charlength); if ( mb_strlen( $excerpt ) > $charlength ) { $subex = mb_substr( $excerpt, 0, $charlength); $exwords = explode( ' ', $subex ); $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) ); if ( $excut < 0 ) { return mb_substr( $subex, 0, $excut ); } else { return $subex; } } else { return $excerpt; } } } if(!function_exists('qode_excerpt')) { /** * Function that cuts post excerpt to the number of word based on previosly set global * variable $word_count, which is defined in qode_set_blog_word_count function. * * It current post has read more tag set it will return content of the post, else it will return post excerpt * * @changed in 4.3 version */ function qode_excerpt() { global $qode_options_proya, $word_count, $post; //does current post has read more tag set? if(qode_post_has_read_more()) { global $more; //override global $more variable so this can be used in blog templates $more = 0; echo get_the_content(''); } //is word count set to something different that 0? elseif($word_count != '0') { //if word count is set and different than empty take that value, else that general option from theme options $word_count = isset($word_count) && $word_count !== "" ? $word_count : $qode_options_proya['number_of_chars']; //if post excerpt field is filled take that as post excerpt, else that content of the post $post_excerpt = $post->post_excerpt != "" ? $post->post_excerpt : strip_tags($post->post_content); //remove leading dots if those exists $clean_excerpt = strlen($post_excerpt) && strpos($post_excerpt, '...') ? strstr($post_excerpt, '...', true) : $post_excerpt; //if clean excerpt has text left if($clean_excerpt !== '') { //explode current excerpt to words $excerpt_word_array = explode (' ', $clean_excerpt); //cut down that array based on the number of the words option $excerpt_word_array = array_slice ($excerpt_word_array, 0, $word_count); //add exerpt postfix $excert_postfix = apply_filters('qode_excerpt_postfix', '...'); //and finally implode words together $excerpt = implode (' ', $excerpt_word_array).$excert_postfix; //is excerpt different than empty string? if($excerpt !== '') { echo '

'.$excerpt.'

'; } } } } } if(!function_exists('qode_set_blog_word_count')) { /** * Function that sets global blog word count variable used by qode_excerpt function */ function qode_set_blog_word_count($word_count_param) { global $word_count; $word_count = $word_count_param; } } /* Use slider instead of image for post */ if (!function_exists('slider_blog')) { function slider_blog($post_id) { $sliders = get_post_meta($post_id, "qode_sliders", true); $slider = $sliders[1]; if($slider) { $html = ""; $html .= '
'; } return $html; } } if (!function_exists('compareSlides')) { function compareSlides($a, $b){ if (isset($a['ordernumber']) && isset($b['ordernumber'])) { if ($a['ordernumber'] == $b['ordernumber']) { return 0; } return ($a['ordernumber'] < $b['ordernumber']) ? -1 : 1; } return 0; } } if (!function_exists('comparePortfolioImages')) { /** * Function that compares two portfolio image for sorting * @param $a int first image * @param $b int second image * @return int result of comparison */ function comparePortfolioImages($a, $b) { if (isset($a['portfolioimgordernumber']) && isset($b['portfolioimgordernumber'])) { if ($a['portfolioimgordernumber'] == $b['portfolioimgordernumber']) { return 0; } return ($a['portfolioimgordernumber'] < $b['portfolioimgordernumber']) ? -1 : 1; } return 0; } } if (!function_exists('comparePortfolioOptions')) { /** * Function that compares two portfolio options for sorting * @param $a int first option * @param $b int second option * @return int result of comparison */ function comparePortfolioOptions($a, $b){ if (isset($a['optionlabelordernumber']) && isset($b['optionlabelordernumber'])) { if ($a['optionlabelordernumber'] == $b['optionlabelordernumber']) { return 0; } return ($a['optionlabelordernumber'] < $b['optionlabelordernumber']) ? -1 : 1; } return 0; } } if (!function_exists('getPortfolionavigationPostCategoryAndTitle')) { /** * Function that compares two portfolio options for sorting * @param $post * @return html of navigation */ function getPortfolionavigationPostCategoryAndTitle($post){ $html_info = ''; $categories = wp_get_post_terms($post->ID, 'portfolio_category'); $html_info .= ''; $k = 1; foreach ($categories as $cat) { $html_info .= $cat->name; if (count($categories) != $k) { $html_info .= ', '; } $k++; } $html_info .= ''; if($post->post_title != '') { $html_info .= ''.$post->post_title.''; } $html_info .= ''; return $html_info; } } if (!function_exists('qode_gallery_upload_get_images')) { /** * Function that outputs gallery list item for portfolio in portfolio admin page * */ function qode_gallery_upload_get_images() { $ids=$_POST['ids']; $ids=explode(",",$ids); foreach($ids as $id): $image = wp_get_attachment_image_src($id,'thumbnail', true); echo ''; endforeach; exit; } add_action( 'wp_ajax_qode_gallery_upload_get_images', 'qode_gallery_upload_get_images'); } if (!function_exists('qode_generate_dynamic_css_and_js')){ /** * Function that gets content of dynamic assets files and puts that in static ones */ function qode_generate_dynamic_css_and_js() { $qode_options_proya = get_option('qode_options_proya'); if(qode_is_css_folder_writable()) { $css_dir = get_template_directory().'/css/'; ob_start(); include_once('css/style_dynamic.php'); $css = ob_get_clean(); file_put_contents($css_dir.'style_dynamic.css', $css, LOCK_EX); ob_start(); include_once('css/style_dynamic_responsive.php'); $css = ob_get_clean(); file_put_contents($css_dir.'style_dynamic_responsive.css', $css, LOCK_EX); /*20170725 ob_start(); include_once('css/custom_css.php'); $css = ob_get_clean(); file_put_contents($css_dir.'custom_css.css', $css, LOCK_EX); */ } if(qode_is_js_folder_writable()) { $js_dir = get_template_directory().'/js/'; ob_start(); include_once('js/default_dynamic.php'); $js = ob_get_clean(); file_put_contents($js_dir.'default_dynamic.js', $js, LOCK_EX); /*20170725 ob_start(); include_once('js/custom_js.php'); $js = ob_get_clean(); file_put_contents($js_dir.'custom_js.js', $js, LOCK_EX); */ } } if(!is_multisite()) { add_action('qode_after_theme_option_save', 'qode_generate_dynamic_css_and_js'); } } if (!function_exists('qode_hex2rgb')) { /** * Function that transforms hex color to rgb color * @param $hex string original hex string * @return array array containing three elements (r, g, b) */ function qode_hex2rgb($hex) { $hex = str_replace("#", "", $hex); if(strlen($hex) == 3) { $r = hexdec(substr($hex,0,1).substr($hex,0,1)); $g = hexdec(substr($hex,1,1).substr($hex,1,1)); $b = hexdec(substr($hex,2,1).substr($hex,2,1)); } else { $r = hexdec(substr($hex,0,2)); $g = hexdec(substr($hex,2,2)); $b = hexdec(substr($hex,4,2)); } $rgb = array($r, $g, $b); //return implode(",", $rgb); // returns the rgb values separated by commas return $rgb; // returns an array with the rgb values } } if(!function_exists('qode_addslashes')) { /** * Function that checks if magic quotes are turned on (for older versions of php) and returns escaped string * @param $str string string to be escaped * @return string escaped string */ function qode_addslashes($str) { $str = addslashes($str); return $str; } } if(!function_exists('qode_is_archive_page')) { /** * Function that checks if current page archive page, search, 404 or default home blog page * @return bool * * @see is_archive() * @see is_search() * @see is_404() * @see is_front_page() * @see is_home() */ function qode_is_archive_page() { return is_archive() || is_search() || is_404() || (is_front_page() && is_home()); } } if(!function_exists('qode_is_woocommerce_installed')) { /** * Function that checks if woocommerce is installed * @return bool */ function qode_is_woocommerce_installed() { return function_exists('is_woocommerce'); } } if(!function_exists('qode_is_woocommerce_page')) { /** * Function that checks if current page is woocommerce shop, product or product taxonomy * @return bool * * @see is_woocommerce() */ function qode_is_woocommerce_page() { return function_exists('is_woocommerce') && is_woocommerce(); } } if(!function_exists('qode_is_woocommerce_shop')) { /** * Function that checks if current page is shop or product page * @return bool * * @see is_shop() */ function qode_is_woocommerce_shop() { return function_exists('is_shop') && is_shop(); } } if(!function_exists('qode_is_product_category')) { function qode_is_product_category() { return function_exists('is_product_category') && is_product_category(); } } if(!function_exists('qode_get_woo_shop_page_id')) { /** * Function that returns shop page id that is set in WooCommerce settings page * @return int id of shop page */ function qode_get_woo_shop_page_id() { if(qode_is_woocommerce_installed()) { return get_option('woocommerce_shop_page_id'); } } } if(!function_exists('qode_woocommerce_columns_class')) { /** * Function that adds number of columns class to header tag * @param array array of classes from main filter * @return array array of classes with added bottom header appearance class */ function qode_woocommerce_columns_class($classes) { global $qode_options_proya; if (qode_is_woocommerce_installed()) { $products_list_number = 'columns-4'; if(isset($qode_options_proya['woo_products_list_number'])){ $products_list_number = $qode_options_proya['woo_products_list_number']; } $classes[]= $products_list_number; } return $classes; } add_filter('body_class', 'qode_woocommerce_columns_class'); } if(!function_exists('qode_woocommerce_single_type')) { function qode_woocommerce_single_type() { $type = ''; if (qode_is_woocommerce_installed()) { $type = qode_options()->getOptionValue('woo_product_single_type'); } return $type; } } if(!function_exists('qode_woocommerce_single_type_class')) { /** * Function that adds single type on body * @param array array of classes from main filter * @return array array of classes with added single type class */ function qode_woocommerce_single_type_class($classes) { if (qode_is_woocommerce_installed()) { $type = qode_woocommerce_single_type(); if(!empty($type)) { $class = 'qode-product-single-' . $type; $classes[]= $class; } } return $classes; } add_filter('body_class', 'qode_woocommerce_single_type_class'); } if(!function_exists('qode_get_page_template_name')) { /** * Returns current template file name without extension * @return string name of current template file */ function qode_get_page_template_name() { $file_name = ''; $file_name_without_ext = preg_replace('/\\.[^.\\s]{3,4}$/', '', basename(get_page_template())); if($file_name_without_ext !== '') { $file_name = $file_name_without_ext; } return $file_name; } } if(!function_exists('qode_is_contact_page_template')) { /** * Checks if current template page is contact page. * @param string current page. Optional parameter. If not passed qode_get_page_template_name() function will be used * @return bool * * @see qode_get_page_template_name() */ function qode_is_contact_page_template($current_page = '') { if($current_page == '') { $current_page = qode_get_page_template_name(); } return in_array($current_page, array('contact-page')); } } if(!function_exists('qode_has_shortcode')) { /** * Function that checks whether shortcode exists on current page / post * @param string shortcode to find * @param string content to check. If isn't passed current post content will be used * @return bool whether content has shortcode or not */ function qode_has_shortcode($shortcode, $content = '') { $has_shortcode = false; if ($shortcode) { //if content variable isn't past if($content == '') { //take content from current post if(!get_the_ID()){ // HOT FIXED return $has_shortcode; } $current_post = get_post(get_the_ID()); $content = $current_post->post_content; } //does content has shortcode added? if (stripos($content, '[' . $shortcode) !== false) { $has_shortcode = true; } } return $has_shortcode; } } if(!function_exists('qode_has_google_map_shortcode')) { /** * Function that checks Qode Google Map shortcode exists on a page * @return bool */ function qode_has_google_map_shortcode() { $google_map_shortcode = 'qode_google_map'; $slider_field = get_post_meta(qode_get_page_id(), 'qode_revolution-slider', true); $has_shortcode = qode_has_shortcode($google_map_shortcode) || qode_has_shortcode($google_map_shortcode, $slider_field); if($has_shortcode) { return true; } return false; } } if(!function_exists('qode_rgba_color')) { /** * Function that generates rgba part of css color property * @param $color string hex color * @param $transparency float transparency value between 0 and 1 * @return string generated rgba string */ function qode_rgba_color($color, $transparency) { if($color !== '' && $transparency !== '') { $rgba_color = ''; $rgb_color_array = qode_hex2rgb($color); $rgba_color .= 'rgba('.implode(', ', $rgb_color_array).', '.$transparency.')'; return $rgba_color; } } } if (!function_exists('theme_version_class')) { /** * Function that adds classes on body for version of theme * */ function theme_version_class($classes) { $current_theme = wp_get_theme(); $theme_prefix = 'qode'; //is child theme activated? if($current_theme->parent()) { //add child theme version $classes[] = $theme_prefix.'-child-theme-ver-'.$current_theme->get('Version'); //get parent theme $current_theme = $current_theme->parent(); } if($current_theme->exists() && $current_theme->get('Version') != "") { $classes[] = $theme_prefix.'-theme-ver-'.$current_theme->get('Version'); } return $classes; } add_filter('body_class','theme_version_class'); } if(!function_exists('qode_get_title_text')) { /** * Function that returns current page title text. Defines qode_title_text filter * @return string current page title text * * @see is_tag() * @see is_date() * @see is_author() * @see is_category() * @see is_home() * @see is_search() * @see is_404() * @see get_queried_object_id() * @see qode_is_woocommerce_installed() * * @since 4.3 * @version 0.1 * */ function qode_get_title_text() { global $qode_options_proya; $id = get_queried_object_id(); $title = ''; //is current page tag archive? if (is_tag()) { //get title of current tag $title = single_term_title("", false)." Tag"; } //is current page date archive? elseif (is_date()) { //get current date archive format $title = get_the_time('F Y'); } //is current page author archive? elseif (is_author()) { //get current author name $title = __('Author:', 'qode') . " " . get_the_author(); } //us current page category archive elseif (is_category()) { //get current page category title $title = single_cat_title('', false); } //is current page blog post page and front page? Latest posts option is set in Settings -> Reading elseif (is_home() && is_front_page()) { //get site name from options $title = get_option('blogname'); } //is current page search page? elseif (is_search()) { //get title for search page $title = __('Search', 'qode'); } //is current page 404? elseif (is_404()) { //is 404 title text set in theme options? if($qode_options_proya['404_title'] != "") { //get it from options $title = $qode_options_proya['404_title']; } else { //get default 404 page title $title = __('404 - Page not found', 'qode'); } } //is WooCommerce installed and is shop or single product page? elseif(qode_is_woocommerce_installed() && (qode_is_woocommerce_shop() || is_singular('product'))) { //get shop page id from options table $shop_id = get_option('woocommerce_shop_page_id'); //get shop page and get it's title if set $shop = get_post($shop_id); if(isset($shop->post_title) && $shop->post_title !== '') { $title = $shop->post_title; } } //is WooCommerce installed and is current page product archive page? elseif(qode_is_woocommerce_installed() && (is_product_category() || is_product_tag())) { global $wp_query; //get current taxonomy and it's name and assign to title $tax = $wp_query->get_queried_object(); $category_title = $tax->name; $title = $category_title; } //is current page some archive page? elseif (is_archive()) { $title = __('Archive','qode'); } //current page is regular page else { $title = get_the_title($id); } $title = apply_filters('qode_title_text', $title); return $title; } } if(!function_exists('qode_title_text')) { /** * Function that echoes title text. * * @see qode_get_title_text() * * @since 4.3 * @version 0.1 */ function qode_title_text() { echo qode_get_title_text(); } } if(!function_exists('qode_wp_title')) { /** * Function that sets page's title. Hooks to wp_title filter * @param $title string current page title * @param $sep string title separator * @return string changed title text if SEO plugins aren't installed * * @since 5.0 * @version 0.3 */ function qode_wp_title($title, $sep) { global $qode_options_proya; //is SEO plugin installed? if(qode_seo_plugin_installed()) { //don't do anything, seo plugin will take care of it } else { //get current post id $id = qode_get_page_id(); $sep = ' | '; $title_prefix = get_bloginfo('name'); $title_suffix = ''; //set unchanged title variable so we can use it later $unchanged_title = $title; //is qode seo enabled? if(isset($qode_options_proya['disable_qode_seo']) && $qode_options_proya['disable_qode_seo'] !== 'yes') { //get current post seo title $seo_title = get_post_meta($id, "qode_seo_title", true); //is current post seo title set? if($seo_title !== '') { $title_suffix = $seo_title; } } //title suffix is empty, which means that it wasn't set by qode seo if(empty($title_suffix)) { //if current page is front page append site description, else take original title string $title_suffix = is_front_page() ? get_bloginfo('description') : $unchanged_title; } //concatenate title string $title = $title_prefix.$sep.$title_suffix; //return generated title string return $title; } } add_filter('wp_title', 'qode_wp_title', 10, 2); } if(!function_exists('qode_ajax_meta')) { /** * Function that echoes meta data for ajax * * @since 5.0 * @version 0.2 */ function qode_ajax_meta() { global $qode_options_proya; ?>
posts} WHERE guid='$attachment_url'"; //get attachment id $attachment_id = $wpdb->get_var($query); } //return it return $attachment_id; } } if(!function_exists('qode_get_attachment_meta_from_url')) { /** * Function that returns meta array for give attachment url * @param $attachment_url * @param array $keys sub array of attachment meta * @return array|mixed * * @see qode_get_attachment_id_from_url() * @see qode_get_attachment_meta() * * @version 0.1 */ function qode_get_attachment_meta_from_url($attachment_url, $keys = array()) { $attachment_meta = array(); //get attachment id for attachment url $attachment_id = qode_get_attachment_id_from_url($attachment_url); //is attachment id set? if(!empty($attachment_id)) { //get post meta $attachment_meta = qode_get_attachment_meta($attachment_id, $keys); } //return post meta return $attachment_meta; } } if(!function_exists('qode_get_image_dimensions')) { /** * Function that returns image sizes array. First looks in post_meta table if attachment exists in the database, * if it doesn't than it uses getimagesize PHP function to get image sizes * @param $url string url of the image * @return array array of image sizes that containes height and width * * @see qode_get_attachment_meta_from_url() * @uses getimagesize * * @version 0.1 */ function qode_get_image_dimensions($url) { $image_sizes = array(); //is url passed? if($url !== '') { //get image sizes from posts meta if attachment exists $image_sizes = qode_get_attachment_meta_from_url($url, array('width', 'height')); //image does not exists in post table, we have to use PHP way of getting image size if(!count($image_sizes)) { //can we open file by url? if(ini_get('allow_url_fopen') == 1 && file_exists($url)) { list($width, $height, $type, $attr) = getimagesize($url); } else { //we can't open file directly, have to locate it with relative path. $image_obj = parse_url($url); $image_relative_path = $_SERVER['DOCUMENT_ROOT'].$image_obj['path']; if(file_exists($image_relative_path)) { list($width, $height, $type, $attr) = getimagesize($image_relative_path); } } //did we get width and height from some of above methods? if(isset($width) && isset($height)) { //set them to our image sizes array $image_sizes = array( 'width' => $width, 'height' => $height ); } } } return $image_sizes; } } if(!function_exists('qode_set_logo_sizes')) { /** * Function that sets logo image dimensions to global qode options array so it can be used in the theme */ function qode_set_logo_sizes() { global $qode_options_proya; //get logo image size $logo_image_sizes = qode_get_image_dimensions($qode_options_proya['logo_image']); $qode_options_proya['logo_width'] = 280; $qode_options_proya['logo_height'] = 130; //is image width and height set? if(isset($logo_image_sizes['width']) && isset($logo_image_sizes['height'])) { //set those variables in global array $qode_options_proya['logo_width'] = $logo_image_sizes['width']; $qode_options_proya['logo_height'] = $logo_image_sizes['height']; } } //not used at the moment, so there is no need for action //add_action('init', 'qode_set_logo_sizes', 0); } if(!function_exists('qode_hide_initial_sticky_body_class')) { /** * Function that adds hidden initial sticky class to body. * @param $classes array of body classes * @return hidden initial sticky body class */ function qode_hide_initial_sticky_body_class($classes) { global $qode_options_proya; if(isset($qode_options_proya['header_bottom_appearance']) && ($qode_options_proya['header_bottom_appearance'] == "stick" || $qode_options_proya['header_bottom_appearance'] == "stick menu_bottom" || $qode_options_proya['header_bottom_appearance'] == "stick_with_left_right_menu")){ if(get_post_meta(qode_get_page_id(), "qode_page_hide_initial_sticky", true) !== ''){ if(get_post_meta(qode_get_page_id(), "qode_page_hide_initial_sticky", true) == 'yes'){ $classes[] = 'hide_inital_sticky'; } }else if(isset($qode_options_proya['hide_initial_sticky']) && $qode_options_proya['hide_initial_sticky'] == 'yes') { $classes[] = 'hide_inital_sticky'; } } return $classes; } add_filter('body_class', 'qode_hide_initial_sticky_body_class'); } if(!function_exists('qode_seo_plugin_installed')) { /** * Function that checks if popular seo plugins are installed * @return bool */ function qode_seo_plugin_installed() { //is YOAST installed? if(defined('WPSEO_VERSION')) { return true; } return false; } } if(!function_exists('qode_contact_form_7_installed')) { /** * Function that checks if contact form 7 installed * @return bool */ function qode_contact_form_7_installed() { //is Contact Form 7 installed? if(defined('WPCF7_VERSION')) { return true; } return false; } } if(!function_exists('qode_revolution_slider_installed')) { /** * Function that checks if revolution slider installed * @return bool */ function qode_revolution_slider_installed() { //is Revolution Slider installed? if(class_exists('RevSliderFront')) { return true; } return false; } } if(!function_exists('qode_layer_slider_installed')) { /** * Function that checks if layer slider installed * @return bool */ function qode_layer_slider_installed() { //is Layer Slider installed? if(defined('LS_PLUGIN_VERSION')) { return true; } return false; } } if(!function_exists('qode_post_has_read_more')) { /** * Function that checks if current post has read more tag set * @return int position of read more tag text. It will return false if read more tag isn't set */ function qode_post_has_read_more() { global $post; return strpos($post->post_content, ''); } } if(!function_exists('qode_is_main_menu_set')) { /** * Function that checks if any of main menu locations are set. * Checks whether top-navigation location is set, or left-top-navigation and right-top-navigation is set * @return bool * * @version 0.1 */ function qode_is_main_menu_set() { $has_top_nav = has_nav_menu('top-navigation'); $has_divided_nav = has_nav_menu('left-top-navigation') && has_nav_menu('right-top-navigation'); return $has_top_nav || $has_divided_nav; } } if(!function_exists('qode_remove_yoast_json_on_ajax')) { /** * Function that removes yoast json ld script * that stops page transition to work on home page * Hooks to wpseo_json_ld_output in order to disable json ld script * @return bool * * @param $data array json ld data that is being passed to filter * * @version 0.2 */ function qode_remove_yoast_json_on_ajax($data) { //is current request made through ajax? if(qode_is_ajax()) { //disable json ld script return array(); } return $data; } //is yoast installed and it's version is greater or equal of 1.6? if(defined('WPSEO_VERSION') && version_compare(WPSEO_VERSION, '1.6') >= 0) { add_filter('wpseo_json_ld_output', 'qode_remove_yoast_json_on_ajax'); } } if(!function_exists('qode_is_ajax')) { /** * Function that checks if current request is ajax request * @return bool whether it's ajax request or not * * @version 0.1 */ function qode_is_ajax() { return !empty( $_SERVER[ 'HTTP_X_REQUESTED_WITH' ]) && strtolower( $_SERVER[ 'HTTP_X_REQUESTED_WITH' ]) == 'xmlhttprequest'; } } if(!function_exists('qode_is_wpml_installed')) { /** * Function that checks if WPML plugin is installed * @return bool * * @version 0.1 */ function qode_is_wpml_installed() { return defined('ICL_SITEPRESS_VERSION'); } } if(!function_exists('qode_is_css_folder_writable')) { /** * Function that checks if css folder is writable * @return bool * * @version 0.1 * @uses is_writable() */ function qode_is_css_folder_writable() { $css_dir = get_template_directory().'/css'; return is_writable($css_dir); } } if(!function_exists('qode_is_js_folder_writable')) { /** * Function that checks if js folder is writable * @return bool * * @version 0.1 * @uses is_writable() */ function qode_is_js_folder_writable() { $js_dir = get_template_directory().'/js'; return is_writable($js_dir); } } if(!function_exists('qode_assets_folders_writable')) { /** * Function that if css and js folders are writable * @return bool * * @version 0.1 * @see qode_is_css_folder_writable() * @see qode_is_js_folder_writable() */ function qode_assets_folders_writable() { return qode_is_css_folder_writable() && qode_is_js_folder_writable(); } } if(!function_exists('qode_writable_assets_folders_notice')) { /** * Function that prints notice that css and js folders aren't writable. Hooks to admin_notices action * * @version 0.1 * @link http://codex.wordpress.org/Plugin_API/Action_Reference/admin_notices */ function qode_writable_assets_folders_notice() { global $pagenow; $is_theme_options_page = isset($_GET['page']) && strstr($_GET['page'], 'qode_theme_menu'); if($pagenow === 'admin.php' && $is_theme_options_page) { if(!qode_assets_folders_writable()) { ?>

documentation.', 'qode'); ?>

$no_ajax_pages )); } } add_action('wp_enqueue_scripts', 'qode_localize_no_ajax_pages'); } if(!function_exists('qode_get_woocommerce_pages')) { /** * Function that returns all url woocommerce pages * @return array array of WooCommerce pages * * @version 0.1 */ function qode_get_woocommerce_pages() { $woo_pages_array = array(); if(qode_is_woocommerce_installed()) { if(get_option('woocommerce_shop_page_id') != ''){ $woo_pages_array[] = get_permalink(get_option('woocommerce_shop_page_id')); } if(get_option('woocommerce_cart_page_id') != ''){ $woo_pages_array[] = get_permalink(get_option('woocommerce_cart_page_id')); } if(get_option('woocommerce_checkout_page_id') != ''){ $woo_pages_array[] = get_permalink(get_option('woocommerce_checkout_page_id')); } if(get_option('woocommerce_pay_page_id') != ''){ $woo_pages_array[] = get_permalink(get_option(' woocommerce_pay_page_id ')); } if(get_option('woocommerce_thanks_page_id') != ''){ $woo_pages_array[] = get_permalink(get_option(' woocommerce_thanks_page_id ')); } if(get_option('woocommerce_myaccount_page_id') != ''){ $woo_pages_array[] = get_permalink(get_option(' woocommerce_myaccount_page_id ')); } if(get_option('woocommerce_edit_address_page_id') != ''){ $woo_pages_array[] = get_permalink(get_option(' woocommerce_edit_address_page_id ')); } if(get_option('woocommerce_view_order_page_id') != ''){ $woo_pages_array[] = get_permalink(get_option(' woocommerce_view_order_page_id ')); } if(get_option('woocommerce_terms_page_id') != ''){ $woo_pages_array[] = get_permalink(get_option(' woocommerce_terms_page_id ')); } $woo_products = get_posts(array('post_type' => 'product','post_status' => 'publish', 'posts_per_page' => '-1') ); foreach($woo_products as $product) { $woo_pages_array[] = get_permalink($product->ID); } } return $woo_pages_array; } } if(!function_exists('qode_get_woocommerce_archive_pages')) { /** * Function that returns all url woocommerce pages * @return array array of WooCommerce pages * * @version 0.1 */ function qode_get_woocommerce_archive_pages() { $woo_pages_array = array(); if(qode_is_woocommerce_installed()) { $terms = get_terms( array( 'taxonomy' => array('product_cat','product_tag'), 'hide_empty' => false, ) ); foreach($terms as $term) { $woo_pages_array[] = get_term_link($term->term_id); } } return $woo_pages_array; } } if(!function_exists('qode_get_objects_without_ajax')) { /** * Function that returns urls of objects that have ajax disabled. * Works for posts, pages and portfolio pages. * @return array array of urls of posts that have ajax disabled * * @version 0.2 */ function qode_get_objects_without_ajax() { $posts_without_ajax = array(); $posts_args = array( 'post_type' => array('post', 'portfolio_page', 'page'), 'post_status' => 'publish', 'meta_key' => 'qode_show-animation', 'meta_value' => 'no_animation' ); $posts_query = new WP_Query($posts_args); if($posts_query->have_posts()) { while($posts_query->have_posts()) { $posts_query->the_post(); $posts_without_ajax[] = get_permalink(get_the_ID()); } } wp_reset_postdata(); return $posts_without_ajax; } } if(!function_exists('qode_get_pages_without_ajax')) { /** * Function that returns urls of pages that have ajax disabled * @return array array of urls of pages that have ajax disabled * * @version 0.1 */ function qode_get_pages_without_ajax() { $pages_without_ajax = array(); $pages_args = array( 'post_type' => 'page', 'post_status' => 'publish', 'meta_key' => 'qode_show-animation', 'meta_value' => 'no_animation' ); $pages_query = new WP_Query($pages_args); if($pages_query->have_posts()) { while($pages_query->have_posts()) { $pages_query->the_post(); $pages_without_ajax[] = get_permalink(get_the_ID()); } } wp_reset_postdata(); return $pages_without_ajax; } } if(!function_exists('qode_get_wpml_pages_for_current_page')) { /** * Function that returns urls translated pages for current page. * @return array array of url urls translated pages for current page. * * @version 0.1 */ function qode_get_wpml_pages_for_current_page() { $wpml_pages_for_current_page = array(); if(qode_is_wpml_installed()) { $language_pages = icl_get_languages('skip_missing=0'); foreach($language_pages as $key => $language_page) { $wpml_pages_for_current_page[] = $language_page["url"]; } } return $wpml_pages_for_current_page; } } if(!function_exists('qode_is_ajax_enabled')) { /** * Function that checks if ajax is enabled. * @return bool * * @version 0.1 */ function qode_is_ajax_enabled() { global $qode_options_proya; $has_ajax = false; if(isset($qode_options_proya['page_transitions']) && $qode_options_proya['page_transitions'] !== '0') { $has_ajax = true; } return $has_ajax; } } if(!function_exists('qode_is_ajax_header_animation_enabled')) { /** * Function that checks if header animation with ajax is enabled. * @return boolean * * @version 0.1 */ function qode_is_ajax_header_animation_enabled() { global $qode_options_proya; $has_header_animation = false; if(isset($qode_options_proya['page_transitions']) && $qode_options_proya['page_transitions'] !== '0' && isset($qode_options_proya['ajax_animate_header']) && $qode_options_proya['ajax_animate_header'] == 'yes') { $has_header_animation = true; } return $has_header_animation; } } if(!function_exists('qode_get_page_id')) { /** * Function that returns current page / post id. * Checks if current page is woocommerce page and returns that id if it is. * Checks if current page is any archive page (category, tag, date, author etc.) and returns -1 because that isn't * page that is created in WP admin. * * @return int * * @version 0.1 * * @see qode_is_woocommerce_installed() * @see qode_is_woocommerce_shop() */ function qode_get_page_id() { if(qode_is_woocommerce_installed() && (qode_is_woocommerce_shop() || is_singular('product'))) { return qode_get_woo_shop_page_id(); } if(is_archive() || is_search() || is_404() || (is_home() && is_front_page())) { return -1; } return get_queried_object_id(); } } if(!function_exists('rewrite_rules_on_theme_activation')) { /** * Function that sets rewrite rules when our theme is activated */ function rewrite_rules_on_theme_activation() { flush_rewrite_rules(); } add_action( 'after_switch_theme', 'rewrite_rules_on_theme_activation' ); } if(!function_exists('qode_maintenance_mode')) { /** * Function that redirects user to desired landing page if maintenance mode is turned on in options */ function qode_maintenance_mode() { global $qode_options_proya; $protocol = is_ssl() ? "https://" : "http://"; if(isset($qode_options_proya['qode_maintenance_mode']) && $qode_options_proya['qode_maintenance_mode'] == 'yes' && isset($qode_options_proya['qode_maintenance_page']) && $qode_options_proya['qode_maintenance_page'] != "" && !in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php')) && !is_admin() && !is_user_logged_in() && $protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] != get_permalink($qode_options_proya['qode_maintenance_page']) ) { wp_redirect(get_permalink($qode_options_proya['qode_maintenance_page'])); exit; } } if(isset($qode_options_proya['qode_maintenance_mode']) && $qode_options_proya['qode_maintenance_mode'] == 'yes') { add_action('init', 'qode_maintenance_mode', 1); } } if(!function_exists('qode_visual_composer_installed')) { /** * Function that checks if visual composer installed * @return bool */ function qode_visual_composer_installed() { //is Visual Composer installed? if(class_exists('WPBakeryVisualComposerAbstract')) { return true; } return false; } } if(!function_exists('qode_visual_composer_custom_shortcodce_css')){ function qode_visual_composer_custom_shortcodce_css(){ if(qode_visual_composer_installed()){ if(is_page() || is_single() || is_singular('portfolio_page')){ $shortcodes_custom_css = get_post_meta( qode_get_page_id(), '_wpb_shortcodes_custom_css', true ); if ( ! empty( $shortcodes_custom_css ) ) { echo ''; } $post_custom_css = get_post_meta( qode_get_page_id(), '_wpb_post_custom_css', true ); if ( ! empty( $post_custom_css ) ) { echo ''; } } } } add_action('qode_visual_composer_custom_shortcodce_css', 'qode_visual_composer_custom_shortcodce_css'); } if (!function_exists('qode_vc_grid_elements_enabled')) { /** * Function that checks if Visual Composer Grid Elements are enabled * * @return bool */ function qode_vc_grid_elements_enabled() { global $qode_options_proya; $vc_grid_enabled = false; if (isset($qode_options_proya['enable_grid_elements']) && $qode_options_proya['enable_grid_elements'] == 'yes') { $vc_grid_enabled = true; } return $vc_grid_enabled; } } if(!function_exists('qode_visual_composer_grid_elements')) { /** * Removes Visual Composer Grid Elements post type if VC Grid option disabled * and enables Visual Composer Grid Elements post type * if VC Grid option enabled */ function qode_visual_composer_grid_elements() { global $qode_options_proya; if(!qode_vc_grid_elements_enabled()){ remove_action( 'init', 'vc_grid_item_editor_create_post_type' ); } } add_action('vc_after_init', 'qode_visual_composer_grid_elements', 12); } if(!function_exists('qode_grid_elements_ajax_disable')) { /** * Function that disables ajax transitions if grid elements are enabled in theme options */ function qode_grid_elements_ajax_disable() { global $qode_options_proya; if(qode_vc_grid_elements_enabled()) { $qode_options_proya['page_transitions'] = '0'; } } add_action('wp', 'qode_grid_elements_ajax_disable'); } if(!function_exists('qode_get_vc_version')) { /** * Return Visual Composer version string * * @return bool|string */ function qode_get_vc_version() { if (qode_visual_composer_installed()) { return WPB_VC_VERSION; } return false; } } if(!function_exists('qode_get_side_menu_icon_html')) { /** * Function that outputs html for side area icon opener. * Uses $qodeIconCollections global variable * @return string generated html */ function qode_get_side_menu_icon_html() { global $qodeIconCollections, $qode_options_proya; $icon_html = ''; $icon_pack = qodef_option_get_value('side_area_button_icon_pack'); if(isset($icon_pack) && $icon_pack !== '') { $icon_collection_obj = $qodeIconCollections->getIconCollection($icon_pack); $icon_field_name = 'side_area_icon_'. $icon_collection_obj->param; $side_area_icon = qodef_option_get_value($icon_field_name); if(isset($side_area_icon) && $side_area_icon !== ''){ if (method_exists($icon_collection_obj, 'render')) { $icon_html = $icon_collection_obj->render($side_area_icon); } } } return $icon_html; } } if(!function_exists('qode_get_mobile_menu_icon_html')) { /** * Function that outputs html for side area icon opener. * Uses $qodeIconCollections global variable * @return string generated html */ function qode_get_mobile_menu_icon_html() { global $qodeIconCollections, $qode_options_proya; $icon_html = ''; $icon_pack = qodef_option_get_value('mobile_menu_button_icon_pack'); if(isset($icon_pack) && $icon_pack !== '') { $icon_collection_obj = $qodeIconCollections->getIconCollection($icon_pack); $icon_field_name = 'mobile_menu_icon_'. $icon_collection_obj->param; $mobile_menu_icon = qodef_option_get_value($icon_field_name); if(isset($mobile_menu_icon) && $mobile_menu_icon !== ''){ if (method_exists($icon_collection_obj, 'render')) { $icon_html = $icon_collection_obj->render($mobile_menu_icon); } } } return $icon_html; } } function _get_partner_iconbox_alike_items($IS_NEED_RANDOM_DISPLAY=true){ $post_meta = get_post_meta(CORPORATE_PARTNER_PAGE_ID, 'corporate_partner_items', true); if(strpos($post_meta,'/', $post_meta, $m); $m = $m[0]; if($IS_NEED_RANDOM_DISPLAY){ shuffle($m); } return $m; } function _get_partner_iconbox_alike_items_data($v){ preg_match('/ src=".*?"/', $v, $src); preg_match('/ alt=".*?"/', $v, $alt); preg_match('/ title=".*?"/', $v, $title); $src = str_replace(array(' src="','"'),'',$src[0]); $name = str_replace(array(' alt="','"'),'',$alt[0]); $href = str_replace(array(' title="','"'),'',$title[0]); return array('src'=>$src,'name'=>$name,'href'=>$href); } function partner_iconbox_alike_func( $atts = array(), $content = "" ) { $m = _get_partner_iconbox_alike_items(isset($atts['random']) ? true : false); foreach($m as$v){ #echo htmlspecialchars($v); #debug extract(_get_partner_iconbox_alike_items_data($v)); $s.='
'.$name.'
'.$name.'
'; } return '
'.$s.'
'; } add_shortcode( 'partner_alike_iconbox', 'partner_iconbox_alike_func' ); function p_func($atts=array(), $content=''){ $a = array(); if($atts){ foreach($atts as$k=>$v){ $a[]=$k.'="'.$v.'"'; } } return ''.$content.'

'; } add_shortcode( 'p', 'p_func' ); #20170426 START function content_head1_func( $atts = array(), $content = "" ) { return '

'.$content.'

'; } add_shortcode( 'content_head1', 'content_head1_func' ); #20170426 END function __ref_link($href, $txt){return ''.$txt.'';} function ref_link_func( $atts = array(), $content = "" ) { # [1] or [1,2] or [1,2,3] $url = isset($atts['url']) ? $atts['url'] : ''; $from = isset($atts['from']) ? $atts['from']+0 : 0; $from_idx = $from - 1; $ret = ''; if($url){ $ary = explode('@@@',$url); $count_ary = count($ary); $max_index = $count_ary - 1; if($count_ary==1){ $ret = __ref_link($ary[0], '['.($atts['from']+0).']'); }else{ #count_ary>1 foreach($ary as$k=>$v){ $n = $k+1+$from_idx; if($k==0){$txt=__ref_link($v, '['.$n);} elseif($k==$max_index){$txt=',' . __ref_link($v, $n.']');} else{ $txt=',' . __ref_link($v, $n); } $ret.=$txt; } } } return ''.$ret.''; } add_shortcode( 'ref_link', 'ref_link_func' ); function lecturer_intro_in_list_func($atts=array(), $content=''){ $ret = ''; if(strpos($content,'`')!==false){ $a = explode('`', $content); foreach($a as$v){ $v = trim($v); if(empty($v)){continue;} $ret.='
  • '.$v.'
  • '; } $ret = ''; }else{ $ret = '

    '.$content.'

    '; } return '
    '.$atts['title'].':
    '.$ret.'
    '; } add_shortcode( 'lecturer_intro_in_list', 'lecturer_intro_in_list_func' ); $ary_chinese_number = array('○','一','二','三','四','五','六','七','八','九', '十','十一','十二','十三','十四'); function get_chinese_number($n){ global$ary_chinese_number; if(isset($ary_chinese_number[$n])){ return $ary_chinese_number[$n]; } return ''; } function aia_red_func($atts=array(), $content=''){ # aia v2 red text return''.$content.''; } add_shortcode( 'aia_red', 'aia_red_func' ); function word_section_func($atts=array(), $content=''){ $title = $atts['title']; $anchor = isset($atts['anchor']) ? $atts['anchor'] : ''; $links = isset($atts['links']) ? explode('`',$atts['links']) : array(); # we can deprecated this atts foreach($links as$v){ if(strpos($v,':')===false){continue;} $_ = explode(':',$v); $count_ = count($_); if($count_==2){ //<-- is http link $target = strpos($_[1],'http')===0 ? ' target=_blank':''; $title = str_replace($_[0],''.$_[0].'', $title); }elseif($count_==3 and $_[1]==='mailto'){ //<-- is mailto: link $title = str_replace($_[0], ''.$_[0].'', $title); } } $title = str_replace('`','"',$title); $title = str_replace('{','<',$title); $title = str_replace('}','>',$title); # $has_no = isset($atts['no'])&&$atts['no']; $no = $has_no ? get_chinese_number($atts['no']).'、' : 'icon'; if(!IS_V2){ $ret = '
    '.$no.''.$title.'
    '; }else{ $ret = '
    '.$title.'
    '; } $content = do_shortcode($content); $a = strpos($content,'`')===false ? array($content) : explode('`', $content); $only1 = count($a)===1; $s = ''; if($only1){ $has_no_p_markup = strpos($a[0], '

    ')===false; $s = $has_no_p_markup ? '

    '.$a[0].'

    ' : $a[0]; $is_wrap_by_ol = $has_no_p_markup; }else{ $is_wrap_by_ol = true; foreach($a as$k=>$v){ $s.='
  • '.(IS_V2 ? '' : '('.get_chinese_number($k+1).')'.'').$v.'
  • '; } $s = $is_wrap_by_ol ? '
      '.$s.'
    ' : $s; } $ary_dd_class = array(); if($only1){ $ary_dd_class[]='child-not-ol'; } if(!$has_no){$ary_dd_class[]='with-icon-title';} if(empty($a[0])){ $ary_dd_class[]='empty-dd'; } $ret.='' .($anchor ? '' : '') .$s.''; return$ret; } add_shortcode('word_section', 'word_section_func'); function word_section_start_func($atts=array(), $content=''){ if(IS_V2){ $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; $uri = substr($uri, strlen(WEB_URL)); $uri = explode('/', $uri); $IS_ADMISSION_PAGE = strpos($uri[0], 'admission-')===0||strpos($uri[0], 'medical-')===0; $p = ''; #after 2021.12.18, we don't need this. isset($uri[0]) && 0===preg_match('/[0-9]/', $uri[0]) && $IS_ADMISSION_PAGE ? '

    ※本課程將如期開課,上課模式依據衛福部疾管署發布之防疫警戒標準做滾動式調整。

    ' : ''; return $p.'
    '; } return '
    '; } add_shortcode('word_section_start', 'word_section_start_func'); function word_section_end_func($atts=array(), $content=''){ return '
    '; } add_shortcode('word_section_end', 'word_section_end_func'); function medium_start_func($atts=array(), $content=''){ return '
    '; } add_shortcode('medium_start', 'medium_start_func'); function medium_end_func($atts=array(), $content=''){ return '
    '; } add_shortcode('medium_end', 'medium_end_func'); function figg_func($atts=array(), $content=''){ $alt = isset($atts['alt']) && $atts['alt'] ? $atts['alt'] : strip_tags($content); $cap = isset($atts['cap']) ? $atts['cap'] : $alt; $class = isset($atts['class']) ? $atts['class'] : ''; $is_hide_cap = isset($atts['hidecap']) ? $atts['hidecap'] : false; $cap = $is_hide_cap ? '' : $cap; return ''.$alt.''.$cap.''; } add_shortcode('figg', 'figg_func'); function utifr_func($atts=array(), $content=''){ return'

    '.$content.'

    '; } add_shortcode('utifr', 'utifr_func'); // function list1layout_func($atts=array(),$content=''){ $ret = ''; $a = explode('`',$content); foreach($a as$k=>$v){ if(!$v){continue;} $ret.='
  • 第'.get_chinese_number($k+1).'條'.$v.'
  • '; } return '
      '.$ret.'
    '; } add_shortcode('list1layout', 'list1layout_func'); function tbl1_func($atts=array(),$content=''){ $ret=''; $column = $atts['column']+0; foreach(explode("@@@", $content)as$v){ if(!$v || $v==='
    ' || $v==='
    '){continue;} $td = ''; $a = explode('`',$v); $count_a = count($a); foreach($a as$idx=>$cell){ $is_final_idx = $idx===$count_a - 1; $cur_column_num = $idx + 1; $td.=''.$cell.''; } $ret.=''.$td.''."\n"; } return''.$ret.'
    '; } add_shortcode('tbl1', 'tbl1_func'); function go_button_func($atts=array()){ # start from 201908: AIA version2 $open = $atts['open']; $text = $atts['text']; return''.$text.''; } add_shortcode('go_button', 'go_button_func'); function curriculum_button_func($atts=array()){ # start from 201908: AIA version2 $open = $atts['open']; $text = $atts['text']; if(!IS_V2){ return''.$text.''; } return''.$text.''; } add_shortcode('curriculum_button', 'curriculum_button_func'); function class_intro_button_func($atts=array()){ # start from 201908: AIA version2 $open = $atts['open']; $text = $atts['text']; return''.$text.''; } add_shortcode('class_intro_button', 'class_intro_button_func'); function admission_signup_button_func($atts=array()){ # TODO: rename to open_gform_button_func & class="btn_open_gform $open = $atts['open']; $no_track = isset($atts['no_track']) ? $atts['no_track'] : 0; $entry_field_id = isset($atts['entry']) ? $atts['entry'] : ''; $is_google_form = strpos($open,'google')!==false; $is_neticrm_form = strpos($open,'neticrm.')!==false; if(!$no_track){ if($is_google_form && !$entry_field_id){ return '
    Google Form url need `entry` value.
    '; } } #$display_text = isset($atts['text']) ? $atts['text'] : '立即報名'; $display_text = '立即報名'; $text = isset($atts['text']) ? $atts['text'] : $display_text; $is_remove_marginleft = isset($atts['no_margin']); // at version1 $ary_style = array(); if(!$is_remove_marginleft){ $ary_style[] = 'margin-left:3%'; } if(IS_V2){ return''.$text.''; }else{ $s = ''; return$s; } } // end of admission_signup_button_func add_shortcode('admission_signup_button', 'admission_signup_button_func'); function admission_opening_button_func($atts=array()){ return admission_signup_button_func(['text'=>'查看最新開課', 'open'=>OPENING_CLASS_CATEGORY_URL]); } add_shortcode('admission_opening_button', 'admission_opening_button_func'); function space_func($atts_or_h_only=array()){ if(is_int($atts_or_h_only)){ $h = $atts_or_h_only; $style = ' style="clear:both;height:'.$h.'px"'; }else{ $atts = $atts_or_h_only; $style = isset($atts['h']) ? ' style=height:'.$atts['h'].'px' : ''; } return ''; } add_shortcode('space', 'space_func'); function display_mgr_curriculum_tbody_func($atts=[], $content=''){ $is_next = false; $is_meet_Day_at_prev = false; $is_handling_final = false; $ary = preg_split("/(\r\n|\n|\r)/",$content); $a = []; $item = []; foreach($ary as$k=>$v){ $v = str_replace(chr(226).chr(128).chr(168),'',trim($v)); if($is_next){ $a[] = $item; $item = []; $is_next = false; continue; } if (strpos($v,'Day')===0) { $item[] = $ary[$k-1] . '
    ' . $v; $is_meet_Day_at_prev = true; } elseif ($is_meet_Day_at_prev) { $item[] = $v; $is_handling_final = true; $is_meet_Day_at_prev = false; } elseif ($is_handling_final) { $item[] = '
      '.preg_replace('/[1-9]\. /', '
    1. ', $v).'
    '; $is_handling_final = false; $is_next = true; } } foreach($a as$k=>$v){ $a[$k] = ''.implode('', $v).''."\n"; } $tbody = '' . implode('', $a) . ''; return ''.$tbody.''; } add_shortcode('display_mgr_curriculum_tbody', 'display_mgr_curriculum_tbody_func'); function summary_func($atts=array(),$content=''){ if(!$content){return'';} return'
    '.$content.'
    '; } add_shortcode('summary', 'summary_func'); function display_alike_partner_list($conf, $type='LI'){ extract($conf); if('LI'===$type){ $href = empty($href) ? 'javascript:;' : $href; if(!isset($is_display_name)){ $is_display_name=1; } $ary_img_style=array(); if(isset($img_height)){ $ary_img_style[]='height:'.$img_height.'px'; } return '
  • ' .($is_display_name ? ''.$name.'' : '') .'
  • '; } if('UL'===$type){ # $conf = array('li'=>....); $ul= '
      '.$li.'
    '; return'
    '.$ul.'
    '; } } function alike_partner_list_func($atts=array(), $content=''){ $li=''; $ary=explode("@@@",$content); #echo$content; print_r($ary); foreach($ary as$v){ $a=explode('`',$v); $name = isset($a[0]) ? $a[0] : ''; $src = isset($a[1]) ? $a[1] : ''; $href = isset($a[2]) ? $a[2] : ''; if(!$src){continue;} $conf = array('name'=>$name,'src'=>$src,'href'=>$href); if(isset($atts['is_display_name'])){ $conf['is_display_name'] = $atts['is_display_name']+0; } if(isset($atts['img_height'])){ $conf['img_height'] = $atts['img_height']+0; } $li.=display_alike_partner_list($conf, 'LI'); } return display_alike_partner_list(array('li'=>$li),'UL'); } add_shortcode('alike_partner_list', 'alike_partner_list_func'); #function innercontent_start_func($atts=array(),$content=''){ return '
    '; } function innercontent_start_func($atts=array(),$content=''){ return '
    '; } add_shortcode('innercontent_start', 'innercontent_start_func'); function innercontent_end_func($atts=array(),$content=''){ return '
    '; } add_shortcode('innercontent_end', 'innercontent_end_func'); require_once __DIR__.'/functions_weekcourse.php'; function display_timline($content){ return timeline_func('', $content); } function timeline_func($atts=array(),$content=''){ if($content==''){ $content = get_post_meta(HOME_PAGE_ID, 'admission_timeline', true); } if(strpos($content,'`')!==false){ $a = explode("`",$content); }else{ $a = explode("\n",$content); } $count_a = count($a); $s = ''; #default foreach($a as$k=>$v){ $v = str_replace(array("\r","\t"), '', $v); preg_match('/^[2-9][0-9]{3}.[0-9]{2}.[0-9]{1,2}/', $v, $m); $date = $m[0]; $do = substr($v, strlen($date)); if(IS_V2){ preg_match('/^([2-9][0-9]{3}).([0-9]{2}).([0-9]{1,2})/', $date, $M); $year = $M[1]; $mon = $M[2]; $dat = $M[3]; /* if(strlen($year)>3){ $year = ((int)$year) - 1911; } $date = $year . ' 年 ' . $mon . ' 月 ' . $dat . ' 日'; */ $date = $year . ' / ' . $mon . ' / '.$dat; $s .= ''.$date.''.$do.''; }else{ $s .= ''.$do.''; } } $style = array(); if(isset($atts['w']) and $atts['w']){ $style[] = 'width:'.(strpos($atts['w'],'%')!==false ? $atts['w'] : $atts['w'].'px').';margin:auto'; } if(IS_V2){ return'
    '.$s.'
    日期時程表
    '; } return'
      '.$s.'
    '; } add_shortcode('timeline', 'timeline_func'); function show_lecturers_func($atts=array(), $content=''){ if(!$content || strpos($content,',')===false){return'';} $is_circle_img = isset($atts['circle']) && $atts['circle']; $ret = ''; $a = explode(',',$content); foreach($a as$v){ if(1===preg_match('/^[0-9]+$/', $v)){ // id $post = get_post($v); }else{ // post_name $post = get_page_by_path($v, OBJECT, 'post'); } if($post and $post->post_title){ $ret.= display_lecture_li($post, $is_circle_img); } } return'
      '.$ret.'
    '; } add_shortcode('show_lecturers', 'show_lecturers_func'); function show_ta_func($atts=array(), $content=''){ if(!$content){return'';} $ary = explode('@@@', str_replace(array("\r\n", "\r", "\n"),'',$content)); $ret = ''; foreach($ary as$v){ if(!$v or strpos($v,'`')===false){continue;} $a = explode('`', trim($v)); $ret.='
  • '.$a[1].'' .'

    '.(!isset($a[2])||$a[2] ? $a[1] : ''.$a[1].'').'

    ' .'
    ' .(isset($a[3])&&$a[3] ? '
    '.$a[3].'
    ' : '') .'
  • '; } return'
      '.$ret.'
    '; } add_shortcode('show_ta', 'show_ta_func'); function show_namelist_func($atts=array(), $content=''){ $a = explode(',', $content); $li = ''; foreach($a as$v){ $li.='
  • '.$v.'
  • '; } return '
      '.$li.'
    '; } add_shortcode('show_namelist', 'show_namelist_func'); function aia_page_title_func($atts=array(), $content=''){ return '

    '.$content.'

    '; } add_shortcode('aia_page_title', 'aia_page_title_func'); function aia_sub_page_title_func($atts=array(), $content=''){ return '

    '.$content.'

    '; } add_shortcode('aia_sub_page_title', 'aia_sub_page_title_func'); function a_func($atts=array(), $content=''){ $str_atts = ''; foreach($atts as$k=>$v){ $str_atts.=' '.$k.'="'.$v.'"'; } $content = str_replace_first('http','http',$content); return ''.$content.''; } add_shortcode('a', 'a_func'); function match_email_form_func( $atts = array(), $content = "" ) { return '
    '; } add_shortcode( 'match_email_form', 'match_email_form_func' ); function match_email_form_setup_func(){ global$post; return ''; } add_shortcode( 'match_email_form_setup', 'match_email_form_setup_func' ); # function global_match_email_form_func( $atts = array(), $content = "" ) { global$post; return '
    '; } add_shortcode( 'global_match_email_form', 'global_match_email_form_func' ); function global_match_email_form_setup_func(){ global$post; return ''; } add_shortcode( 'global_match_email_form_setup', 'global_match_email_form_setup_func' ); function display_signup_block_func($atts, $content){ $s = '
    '.$atts['title'].'

    '.$content.'

    ' ./*add button, link to curriculum page (ben, 2022.09.17) */ (array_key_exists('curriculum_url',$atts)? '':'' ) .'
    [admission_signup_button open="'.$atts['url'].'"]
    '; return do_shortcode($s); } add_shortcode('signupblock', 'display_signup_block_func'); function display_aitbl($ary_th, $ary_body,$conf=[]){ $ary_tblcssclass = isset($conf['ary_tblcssclass']) ? $conf['ary_tblcssclass'] : ''; $th = $ary_th ? ''.implode('',$ary_th).'' : ''; $tbody = ''; foreach($ary_body as$v): $tbody .= ''.implode('',$v).''; endforeach; $tbody = ''.$tbody.''; return ''.$th.$tbody.'
    '; } function foundation_tbl_func($atts, $content, $conf=[]){ $ary_body = []; $ary_th = isset($atts['head']) ? explode('|',$atts['head']) : ''; foreach(preg_split("/(\r\n|\n|\r)/",$content) as$k=>$v): if(strpos($v,'|')===false){continue;} $tmp = []; foreach(explode('|',$v)as$v2): if(preg_match('/\.pdf$/', $v2)){ $v2 = 'PDF 下載'; } $tmp[] = $v2; endforeach; $ary_body[] = $tmp; endforeach; return display_aitbl($ary_th, $ary_body, $conf); } function foundation_tbl_managers_func($atts, $content){ return foundation_tbl_func($atts, $content, ['ary_tblcssclass'=>['foundation-tbl-managers']]); } add_shortcode('foundation_tbl_managers', 'foundation_tbl_managers_func'); function foundation_tbl_annuals_func($atts, $content){ return foundation_tbl_func($atts, $content, ['ary_tblcssclass'=>['foundation-tbl-annuals']]); } add_shortcode('foundation_tbl_annuals', 'foundation_tbl_annuals_func'); // Remove WordPress Meta Generator remove_action('wp_head', 'wp_generator'); // Hide WordPress Version Info function hide_wordpress_version() { return ''; } add_filter('the_generator', 'hide_wordpress_version'); // Remove WordPress Version Number In URL Parameters From JS/CSS function hide_wordpress_version_in_script($src, $handle) { $src = remove_query_arg('ver', $src); $src = add_query_arg('v',str_replace('?','',FE_VER),$src); return $src; } add_filter( 'style_loader_src', 'hide_wordpress_version_in_script', 10, 2 ); add_filter( 'script_loader_src', 'hide_wordpress_version_in_script', 10, 2 ); remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('wp_print_styles', 'print_emoji_styles'); remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); remove_action( 'admin_print_styles', 'print_emoji_styles' ); remove_action( 'wp_head', 'wp_resource_hints', 2 ); #https://wordpress.org/support/topic/remove-the-new-dns-prefetch-code/ /* $user = wp_get_current_user(); if($user->user_login!=='swc'){ add_filter('show_admin_bar', '__return_false'); }*/ function add_no_cache_flag_for_preview_url($link) { return $link.'&nc'; } add_filter( 'preview_post_link', 'add_no_cache_flag_for_preview_url' ); add_filter( 'preview_page_link', 'add_no_cache_flag_for_preview_url' ); function fix_for_yvonne_permalink($post_name, $post) { # Add 2019.10.18 if ($post->post_type === 'post') { /*$a = array('regulations-alumni-organization-ai-promotion'=>'regulations-to-alumni-organization-for-ai-promotion', 'prize-2019-ai-questionnaire'=>'prize-of-2019-ai-questionnaire', ); foreach($a as$k=>$v){ if(strtolower($post_name)==$k){ return $v; } }*/ global$wpdb; foreach($wpdb->get_results('SELECT * FROM '.TBL_HOTFIX_WP_URL.' WHERE ignore_me=0')as$v){ if(strtolower($post_name)==$v->before_fixed_url){ return $v->after_fixed_url; } } } return $post_name; } add_filter('editable_slug', 'fix_for_yvonne_permalink', 11, 2); function shortcode_redirect_to($atts) { if (is_singular()) { $atts = shortcode_atts([ 'url' => '', 'type' => '301' ], $atts); if (!empty($atts['url'])) { // 使用 wp_safe_redirect 可防止不合法跳轉 wp_redirect(esc_url_raw($atts['url']), (int)$atts['type']); exit; } } } add_shortcode('redirect_to', 'shortcode_redirect_to'); // Add a custom button to the right block of the post edit page // function custom_post_edit_button() { // global $post; // // Retrieve the URI and publish status variable // $uri = get_permalink($post->ID); // $publishStatus = get_post_status($post->ID); // // Get the category terms associated with the post // $categories = get_the_category($post_id); // if ($categories) { // // Create an array to store category names // $category_names = array(); // foreach ($categories as $category) { // // Add category name to the array // $category_names[] = $category->slug; // } // // Implode the category names with a comma // $comma_separated_categories = implode('
    ', $category_names); // } // $title_nonce = wp_create_nonce( 'title_example' ); // // Output your custom button HTML with the URI and publish status variable // echo '
    '; // echo '清除快取'; // echo ''; // Loading spinner // echo '

    URI: ' . $uri . '

    '; // echo '

    comma_separated_categories:
    '.$comma_separated_categories.'

    '; // //echo '

    Publish Status: ' . $publishStatus . '

    '; // //echo '

    title_nonce: ' .$title_nonce .'

    '; // echo '
    '; // } // add_action('post_submitbox_misc_actions', 'custom_post_edit_button'); // add_action( 'admin_enqueue_scripts', 'my_enqueue' ); // function my_enqueue( $hook ) { // if( 'post.php' != $hook ) return; // wp_enqueue_script( 'call_vache', // '/j/cahce_button_for_post_page.js',// , __FILE__ // array( 'jquery' ) // ); // $title_nonce = wp_create_nonce( 'title_example' ); // wp_localize_script( 'call_vache', 'my_ajax_obj', array( // 'ajax_url' => admin_url( 'admin-ajax.php' ), // 'nonce' => $title_nonce, // 'permalink' => get_permalink(), // 'post_status' => get_post_status(),//$post->ID // 'post_id' => get_the_ID() // ) ); // } // add_action('wp_ajax_do_cache', 'ajax_do_cache'); // function ajax_do_cache() { // /** // *@return string strip slash if it are exists in string head and tail, and replace other slash as "---" // **/ // function replace_slashes($input_string) { // $result=preg_replace('/(?slug."/"; // } // // Implode the category names with a comma // $linebreak_separated_categories = implode(PHP_EOL, $category_names); // } // function delete_cache($file){ // // Check if file exists before attempting to delete it // $result=""; // if (file_exists($file)) { // // Attempt to delete the file // if (unlink($file)) { // $result = "File deleted successfully."; // } else { // $result = "An error occurred while trying to delete the file."; // } // } else { // $result = "File does not exist."; // } // return true; // } // delete_cache($file); // // write waiting list // if($post_status!=='publish'){ // echo "已清除現有的快取( $permalink )\n但此篇文章尚未發布( $post_status )故不做快取。"; // wp_die(); // die(); // } // $waiting_list_for_cache=$folder."/waiting_list_for_cache/waiting_list"; // $handle = fopen($waiting_list_for_cache,'a'); // if($handle){ // fwrite($handle,$permalink."\n"); // if($linebreak_separated_categories!=""){ // fwrite($handle,$linebreak_separated_categories."\n");//recache category page // } // } // // Execute the command and capture the output // $output = $result; // // Output the result // if(!file_exists($file)){ // echo "已清除快取( $permalink )\n新的快取會在三分鐘內建立/更新。\n".$linebreak_separated_categories; // }else{ // echo "快取依舊存在\n".$file; // } // //echo $command; // wp_die(); // all ajax handlers should die when finished // } // if(0 && $_SERVER['REMOTE_ADDR']=='61.222.27.93' && ! is_admin() && ! is_user_logged_in()){ // // 定义缓存文件的路径 // //$cache_file_path = $_SERVER['DOCUMENT_ROOT'] . "/cache_testing/"; // function my_custom_page_cache() { // $cache_file_path = $_SERVER['DOCUMENT_ROOT'] . "/cache_testing/"; // // 生成快取鍵,這裡我們以請求的 URL 為基礎 // $cache_key = 'page_cache_' . md5($_SERVER['REQUEST_URI']); // $cache_file = $cache_file_path. $cache_key . '.html'; // // 檢查快取文件是否存在且有效 // if (file_exists($cache_file) && (filemtime($cache_file) > time() - 3600)) { // // 快取文件存在且在一小時內生成,直接讀取並輸出快取內容 // readfile($cache_file); // exit; // } else { // // 開始捕獲輸出 // ob_start(); // } // } // function my_custom_page_cache_save() { // $cache_file_path = $_SERVER['DOCUMENT_ROOT'] . "/cache_testing/"; // // 同上面的快取鍵和文件路徑 // $cache_key = 'page_cache_' . md5($_SERVER['REQUEST_URI']); // $cache_file = $cache_file_path. $cache_key . '.html'; // // 獲取輸出緩衝區的內容 // $content = ob_get_clean(); // // 儲存輸出內容到快取文件 // file_put_contents($cache_file, $content); // // 輸出內容 // echo $content; // //echo ""; // } // // 掛勾到 WordPress 的動作 // add_action('template_redirect', 'my_custom_page_cache', 0); // add_action('shutdown', 'my_custom_page_cache_save', 0); // }