1200, 'height' => 410) ); // Add theme support for HTML5 Semantic Markup add_theme_support('html5', array('search-form', 'comment-form', 'comment-list', 'gallery', 'caption')); // Add theme support for document Title tag add_theme_support('title-tag'); // Add theme support for Translation load_theme_textdomain('ssdma', get_template_directory() . '/languages'); update_site_option('show_on_front', 'page'); } add_action('after_setup_theme', 'ssdma_theme'); add_image_size( 'featured', 1440, 500, true ); function _remove_script_version( $src ){ $num = strrpos($src, '?'); if($num > 0) { $src = substr($src, 0, $num); } return $src; } if(!is_user_logged_in()) { add_filter( 'script_loader_src', '_remove_script_version', 15, 1 ); add_filter( 'style_loader_src', '_remove_script_version', 15, 1 ); } function custom_clean_head() { remove_action('wp_head', 'wp_print_scripts'); remove_action('wp_head', 'wp_print_head_scripts', 9); remove_action('wp_head', 'wp_enqueue_scripts', 1); add_action('wp_footer', 'wp_print_scripts', 5); add_action('wp_footer', 'wp_enqueue_scripts', 5); add_action('wp_footer', 'wp_print_head_scripts', 5); } add_action( 'wp_enqueue_scripts', 'custom_clean_head' ); function ssdma_admin_init() { if(isset($_POST['ssdma_copyright'])) { update_option('ssdma_copyright', $_POST['ssdma_copyright']); } } add_action('admin_init', 'ssdma_admin_init'); if (!function_exists('ssdma_init')) { function ssdma_init() { add_editor_style(get_stylesheet_directory_uri() . '/style.css'); global $ali1; $ali1 = new AL1Options(); } } add_action('init', 'ssdma_init'); function ssdma_excerpt_more() { return ' ...'; } add_filter('excerpt_more', 'ssdma_excerpt_more'); function ssdma_sort_array($first = false, $key = false) { $arr = array( 'promotionVolume' => array( 'name' => __('Best sellers', 'ssdma'), 'sort' => false, ), 'latest' => array( 'name' => __('Latest', 'ssdma'), 'sort' => false, ), 'evaluateScore' => array( 'name' => __('Ratings', 'ssdma'), 'sort' => true, ), 'price' => array( 'name' => __('Price', 'ssdma'), 'sort' => true, ), ); if($key) { $arr = array_keys($arr); } if($first) { $arr = current($arr); } return $arr; } function ssdma_is_tax($query) { if( is_tax('shopcategory') && isset($query->query_vars['shopcategory']) || (isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'products') || (is_search() && !isset($query->query_vars['post_type'])) ) { return true; } return false; } function ssdma_notimage($string) { if($string !== '') { return $string; } return get_template_directory_uri() . '/public/images/image-not-available.jpg'; } function ssdma_get_term_ids($flug = false) { $ids = ssdma_is_var_in_get('ids', true); if(!empty($ids)) { $ids = explode('-', $ids); } if(is_array($ids) && count($ids) && $flug) { $ids = current($ids); } return $ids; } function ssdma_products_filter($query) { if(ssdma_is_tax($query)) { if( is_search() ) { $query->set('post_type', 'products'); } $ids = ssdma_get_term_ids(); if(count($ids) && !isset($query->query_vars['pre_process'])) { if(is_array($ids) && count($ids)) { $query->set('tax_query',array( array( 'taxonomy' => 'shopcategory', 'field' => 'id', 'terms' => $ids ), )); } } } /* end */ return $query; } if( !is_admin() ) { add_action('pre_get_posts', 'ssdma_products_filter'); } function ssdma_posts_clauses($pieces) { global $wp_query, $wpdb; if(ssdma_is_tax($wp_query)) { $min = aliprice_get_default_price(abs(floatval(ssdma_is_var_in_get('pmin', true))), false); $max = aliprice_get_default_price(abs(floatval(ssdma_is_var_in_get('pmax', true))), false); $orderby = ssdma_is_var_in_get( 'orderby', false, false, array('string', ssdma_sort_array(false, true), false) ); $order = ssdma_is_var_in_get('order', false, false, array('string', array('ASC', 'DESC'), false)); $pieces['join'] .= ", `{$wpdb->prefix}aliprice_products` pr"; $pieces['fields'] .= ', pr.price, pr.salePrice, pr.promotionVolume, pr.evaluateScore, pr.lotNum, pr.packageType, pr.storeName, pr.imageUrl, pr.timeleft, pr.quantity'; if($min > -1 || $max > -1 || $orderby == 'price') { $pieces['join'] .= ", (SELECT id, CAST( SUBSTRING_INDEX( IF( salePrice <> '', salePrice, price), '$', -1 ) AS DECIMAL( 10, 2 ) ) AS pp FROM `{$wpdb->prefix}aliprice_products` ) AS pu"; $pieces['where'] = "AND pu.id = pr.id " . $pieces['where'] . " AND {$wpdb->posts}.ID = pr.post_id"; if($min < $max) { $pieces['where'] .= " AND pu.pp <= '{$max}'"; $pieces['where'] .= " AND pu.pp >= '{$min}'"; } elseif($min) { $pieces['where'] .= " AND pu.pp >= '{$min}'"; } elseif($max) { $pieces['where'] .= " AND pu.pp <= '{$max}'"; } } else { $pieces['where'] .= " AND {$wpdb->posts}.ID = pr.post_id"; } if($orderby == 'price') { $pieces['orderby'] = "pu.pp " . $order; } elseif($orderby == 'promotionVolume') { $pieces['orderby'] = "CAST(promotionVolume as UNSIGNED) " . $order; } elseif($orderby == 'evaluateScore') { $pieces['orderby'] = "evaluateScore " . $order; } elseif(!$orderby) { $pieces['orderby'] = "rand() " . $order; } } return $pieces; } if( !is_admin() ) { add_filter( 'posts_clauses', 'ssdma_posts_clauses' ); } /** * Register sidebars. * * @since Ghost 1.0 */ function ssdma_widgets_init() { /** * Sidebar */ register_sidebar(array( 'name' => __('Sidebar', 'ssdma'), 'id' => 'sidebar', 'description' => '', 'class' => '', 'before_widget' => '
', 'before_title' => ''.$letter.'
'; foreach($cats as $cat) { $categories_menu[$i] .= '' . '
', 'url' => '' . '
', ); $required_text = sprintf(' ' . __('Required fields are marked %s', 'ssdma'), '*'); /** * Filter the default comment form fields. * * @since 3.0.0 * * @param array $fields The default comment fields. */ $fields = apply_filters('comment_form_default_fields', $fields); $defaults = array( 'fields' => $fields, 'comment_field' => '', 'must_log_in' => '
' . sprintf(__('You must be logged in to post a comment.', 'ssdma'), wp_login_url(apply_filters('the_permalink', get_permalink($post_id)))) . '
', 'logged_in_as' => '' . sprintf(__('Logged in as %2$s. Log out?', 'ssdma'), get_edit_user_link(), $user_identity, wp_logout_url(apply_filters('the_permalink', get_permalink($post_id)))) . '
', 'comment_notes_before' => '' . __('Your email address will not be published.', 'ssdma') . ($req ? $required_text : '') . '
', 'comment_notes_after' => '', 'id_form' => 'commentform', 'id_submit' => 'submit', 'title_reply' => __('Leave a Reply', 'ssdma'), 'title_reply_to' => __('Leave a Reply to %s', 'ssdma'), 'cancel_reply_link' => __('Cancel reply', 'ssdma'), 'label_submit' => __('Post Comment', 'ssdma'), 'format' => 'xhtml', ); /** * Filter the comment form default arguments. * * Use 'comment_form_default_fields' to filter the comment fields. * * @since 3.0.0 * * @param array $defaults The default comment form arguments. */ $args = wp_parse_args($args, apply_filters('comment_form_defaults', $defaults)); include get_template_directory() . '/templates/comments.php'; } function ssdma_set_youtube_as_featured_image($post_id) { // only want to do this if the post has no thumbnail if (!has_post_thumbnail($post_id) && has_post_format('video', $post_id)) { // find the youtube url $post_array = get_post($post_id, ARRAY_A); $content = $post_array['post_content']; $title = $post_array['post_title']; $youtube_id = get_youtube_id($content); if ($youtube_id) { // build the thumbnail string $youtube_thumb_url = 'http://img.youtube.com/vi/' . $youtube_id . '/0.jpg'; // next, download the URL of the youtube image media_sideload_image($youtube_thumb_url, $post_id, $title); // find the most recent attachment for the given post $attachments = get_posts( array( 'post_type' => 'attachment', 'numberposts' => 1, 'order' => 'ASC', 'post_parent' => $post_id ) ); $attachment = $attachments[0]; // and set it as the post thumbnail set_post_thumbnail($post_id, $attachment->ID); } } // end if } // set_youtube_as_featured_image add_action('save_post', 'ssdma_set_youtube_as_featured_image'); function get_youtube_id($content) { if (preg_match_all('#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $content, $urls) && isset($urls[0])) { $u = $urls[0]; $youtube = false; foreach ($u as $url) { if (strpos($url, 'youtu') && !$youtube) { $url = str_replace('http://youtu.be/', '', $url); $youtube = str_replace('https://www.youtube.com/watch?v=', '', $url); } } if ($youtube) { return $youtube; } } return false; } function ssdma_get_to_string(array $var = array()) { return (count($_GET) || count($var)) ? '?' . http_build_query(array_merge($_GET, $var)) : ''; } /** * This function do validate data */ function ssdma_is_var_in_get($name, $var = false, $default = false, $valid = array()) { $error = false; if(isset($_GET[$name])) { if(count($valid)) { if($valid[0] == 'number' && ssdma_valid_number($_GET[$name], $valid[1])) { $error = true; } elseif($valid[0] == 'string' && ssdma_valid_string($_GET[$name], $valid[1])) { $error = true; } } else { $error = true; } if($var === false) { if($error) { return $_GET[$name]; } else { return $valid[2]; } } elseif($var == $_GET[$name]) { if($error) { return $_GET[$name]; } else { return $valid[2]; } } } return $default; } function ssdma_valid_number($num, $is = array()) { if(!count($is)) { return false; } if(isset($is['min'])) { $min = intval($is['min']); } if(isset($is['max'])) { $max = intval($is['max']); } if(isset($min) && isset($max)) { if($min < $num && $max > $num) { return true; } } elseif(isset($min)) { if($min < $num) { return true; } } elseif(isset($max)) { if($max > $num) { return true; } } return false; } function ssdma_valid_string($str, $is = array()) { if(!count($is)) { return false; } if(in_array($str, $is)) { return true; } return false; } function ssdma_count_posts($flugs = false) { global $wp_query; if($flugs) { return $wp_query->found_posts; } return $wp_query->post_count; } function ssdma_rating_percentage($number = 0.0, $max = 5.0) { $number = floatval($number); $max = floatval($max); return ($number*100)/$max; } function ssdma_rating($number = 0.0, $max = 5) { $number = intval($number); $empty = $max - $number; $star = array(); for($i=0; $i < $number; $i++) { $star[] = true; } for($i=0; $i < $empty; $i++) { $star[] = false; } return $star; } function the_term_link($id, $taxonomy = 'shopcategory') { $term_link = get_term_link( intval($id), $taxonomy ); if( !is_wp_error( $term_link ) ) echo $term_link; } function the_term_title($id, $taxonomy = 'shopcategory') { $term = get_term_by('id', intval($id), $taxonomy); if($term) echo $term->name; } function ssdma_str_length($string, $lenght = 40) { if(strlen($string) > $lenght) { $string = wordwrap($string, $lenght, "}|{", true); $string = substr($string, 0, strpos($string, "}|{")); } return $string; } function ssdma_posts_process($post_type = 'post', $args = array(), $cat_id = 0) { if(!$post_type) { return; } $params = array( 'paged' => max( 0, get_query_var('paged') ), 'post_status' => 'publish', 'post_type' => $post_type, ); if($cat_id) { $params['tax_query'] = array( array( 'taxonomy' => 'shopcategory', 'field' => 'id', 'terms' => $cat_id, )); } $params = array_merge($params, $args); query_posts($params); return true; } function ssdma_abouttheme_add_menu() { add_theme_page( __('About', 'ssdma'), __('About', 'ssdma'), 'manage_options', 'ssdma_about_theme', 'ssdma_about_theme_page', 'dashicons-info' ); } add_action('admin_menu', 'ssdma_abouttheme_add_menu'); function ssdma_about_theme_page() { get_template_part( 'templates/about-theme' ); } function ssdma_add_video_embed_note($html, $url, $attr) { return ''; } add_filter('embed_oembed_html', 'ssdma_add_video_embed_note', 10, 3); /** * This code secret; Needs too upload files */ function ssdma_admin_enqueue_scripts() { if(isset($_GET['page']) && $_GET['page'] == 'ssdma_about_theme') { wp_enqueue_script('plupload-all'); } } add_action('admin_enqueue_scripts', 'ssdma_admin_enqueue_scripts'); function ssdma_wp_ajax_upload() { check_ajax_referer('upload'); add_filter( 'upload_dir', 'ssdma_upload_dir' ); // you can use WP's wp_handle_upload() function: $file = $_FILES['async-upload']; $status = wp_handle_upload($file, array( 'test_form' => false, 'action' => 'upload', 'unique_filename_callback' => 'ssdma_rename', )); // and output the results or something... echo json_encode($status); remove_filter( 'upload_dir', 'ssdma_upload_dir' ); exit; } add_action('wp_ajax_upload', 'ssdma_wp_ajax_upload'); function ssdma_upload_dir( $dir ) { return array( 'path' => get_stylesheet_directory() . '/public/images', 'url' => get_stylesheet_directory_uri() . '/public/images', 'subdir' => '/public/images', ) + $dir; } function ssdma_rename($dir, $filename, $ext) { $file = $dir . '/' . $filename . $ext; if(file_exists($file)) { @unlink($file); } return $filename . $ext; }; function ssdma_get_uploadparams() { $plupload_init = array( 'runtimes' => 'html5,silverlight,flash,html4', 'browse_button' => 'plupload-browse-button', 'container' => 'plupload-upload-ui', 'drop_element' => 'drag-drop-area', 'file_data_name' => 'async-upload', 'multiple_queues' => true, 'max_file_size' => wp_max_upload_size().'b', 'url' => admin_url('admin-ajax.php'), 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'), 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'), 'filters' => array(array('title' => __('Allowed Files', 'ssdma'), 'extensions' => '*')), 'multipart' => true, 'urlstream_upload' => true, // additional post data to send to our ajax hook 'multipart_params' => array( '_ajax_nonce' => wp_create_nonce('upload'), 'action' => 'upload', // the ajax action name ), ); return apply_filters('plupload_init', $plupload_init); } function ssdma_filter_theme_uri($template_dir_uri) { $abs = str_replace('\\', '/', ABSPATH); $uri = str_replace('\\', '/', $template_dir_uri); $uri = str_replace($abs, get_option( 'siteurl' ) . "/", $uri ); return $uri; } add_filter( 'theme_root_uri', 'ssdma_filter_theme_uri', 30,3 ); function ssdma_get_tag_image($path, $alt = '') { $img = '