SHARE
TWEET

Untitled

a guest Apr 21st, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. //include "error.php";
  3. require_once 'widget-template-loader.class.php';
  4.  
  5. class advance_search_form_widget extends WP_Widget {
  6.     function __construct() {
  7.         $widget_ops = array(
  8.             'classname'   => 'widget-asf',
  9.             'description' => esc_html__('Displays an advance search form','asf')
  10.         );
  11.         parent::__construct('advance_search_form', esc_html__('Advance Search Form','asf'), $widget_ops);
  12.        
  13.         add_action('init', array($this, 'init'));
  14.     }
  15.    
  16.     function init(){
  17.         load_plugin_textdomain( 'asf', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
  18.         load_plugin_textdomain( 'videopro', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
  19.     }
  20.    
  21.     function widget( $args, $instance ) {
  22.         extract($args);
  23.        
  24.         $title = strip_tags($instance['title']);
  25.         $label = strip_tags($instance['label']);
  26.         $default_text = strip_tags($instance['default_text']);
  27.         $button_text = strip_tags($instance['button_text']);
  28.        
  29.         $search_for = get_option('asf-post-types',array());
  30.         $show_categories = isset($instance['show_categories']) ? $instance['show_categories'] : 0; 
  31.         $search_video_only = isset($instance['search_video_only']) ? $instance['search_video_only'] : 0;
  32.        
  33.         $show_tag_filter = isset($instance['show_tag_filter']) ? $instance['show_tag_filter'] : 1;
  34.         $highlight_results = isset($instance['highlight_results']) ? $instance['highlight_results'] : 1;
  35.         $select_categories = get_option('asf-categories',array());
  36.         $suggestion = isset($instance['suggestion']) ? $instance['suggestion'] : 0;
  37.         $search_word = $default_text;
  38.         $search_cat = '';
  39.         $s = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : '';
  40.         if(!empty($s)){
  41.             // if we are in search result page
  42.             $search_word = $s;
  43.             $search_cat = isset($_GET['cat']) ? sanitize_text_field($_GET['cat']) : '';
  44.         }
  45.        
  46.         /* ECHO FORM */
  47.        
  48.         echo $before_widget;
  49.        
  50.         $title = apply_filters('widget_title', $title);
  51.        
  52.         if ( !empty( $title ) ) {
  53.             echo $before_title . $title . $after_title; }
  54. ?>
  55.  
  56. <?php
  57.         if($suggestion){
  58.             wp_enqueue_style('asf-suggestion-css',plugins_url('suggestion.css', __FILE__));
  59.         }
  60.     ?>
  61.         <?php
  62.         if(get_option('asf-custom-css') != ''){
  63.         ?>
  64.             <style type="text/css" scope="scope">
  65.             <?php echo get_option('asf-custom-css');?>
  66.             </style>
  67.         <?php
  68.         }
  69.         include CT_Widget_Template_Loader::getTemplateHierarchy('widget-asf.view');
  70.     }
  71.    
  72.     function form( $instance ) {       
  73.         $title = strip_tags(isset($instance['title']) ? $instance['title'] : '');
  74.         $label = strip_tags(isset($instance['label']) ? $instance['label'] : '');
  75.         $default_text = strip_tags(isset($instance['default_text']) ? $instance['default_text'] : '');
  76.         $button_text = strip_tags(isset($instance['button_text']) ? $instance['button_text'] : '');
  77.         $show_categories = isset($instance['show_categories']) ? $instance['show_categories'] : 0;
  78.         $search_video_only = isset($instance['search_video_only']) ? $instance['search_video_only'] : 0;
  79.        
  80.         $suggestion = isset($instance['suggestion']) ? $instance['suggestion'] : 0;
  81. ?>
  82.     <p>
  83.         <label for="<?php echo $this->get_field_id('title'); ?>">
  84.                 <?php echo esc_html__('Title: ','asf'); ?><input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text"
  85.                 value="<?php echo  esc_attr($title);?>" width="100" class="widefat" />
  86.         </label></p>
  87.         <p>
  88.         <label for="<?php echo $this->get_field_id('label'); ?>">
  89.                 <?php echo esc_html__('Label: ','asf'); ?>
  90.             <input id="<?php echo $this->get_field_id('label'); ?>" name="<?php echo $this->get_field_name('label'); ?>" type="text" value="<?php echo  esc_attr($label);?>" width="100"  class="widefat" />
  91.          </label></p>
  92.          <p>
  93.         <label for="<?php echo $this->get_field_id('default_text'); ?>">       
  94.                 <?php echo esc_html__('Default Text: ','asf'); ?><input id="<?php echo $this->get_field_id('default_text'); ?>" name="<?php echo $this->get_field_name('default_text'); ?>" type="text" value="<?php echo  esc_attr($default_text);?>" width="100" class="widefat"  />
  95.          </label>
  96.          </p>
  97.          <p>
  98.         <label for="<?php echo $this->get_field_id('button_text'); ?>">
  99.                 <?php echo esc_html__('Button Text: ','asf'); ?><input id="<?php echo $this->get_field_id('button_text'); ?>" name="<?php echo $this->get_field_name('button_text'); ?>" type="text" value="<?php echo  esc_attr($button_text);?>" width="100" class="widefat"  />
  100.          </label>
  101.          </p>
  102.          <p>
  103.         <label for="<?php echo $this->get_field_id('search_video_only'); ?>">
  104.                 <?php echo esc_html__('Only search Video Posts: ','asf'); ?><input id="<?php echo $this->get_field_id('search_video_only'); ?>" name="<?php echo $this->get_field_name('search_video_only'); ?>" type="checkbox" <?php if($search_video_only) echo 'checked="checked"';?> />
  105.          </label>
  106.          </p>
  107.          <p>
  108.         <label for="<?php echo $this->get_field_id('show_categories'); ?>">
  109.                 <?php echo esc_html__('Show categories list: ','asf'); ?><input id="<?php echo $this->get_field_id('show_categories'); ?>" name="<?php echo $this->get_field_name('show_categories'); ?>" type="checkbox" <?php if($show_categories) echo 'checked="checked"';?> />
  110.          </label>
  111.          </p>
  112.          <p>
  113.         <label for="<?php echo $this->get_field_id('suggestion'); ?>">
  114.                 <?php echo esc_html__('Search suggestion: ','asf'); ?><input id="<?php echo $this->get_field_id('suggestion'); ?>" name="<?php echo $this->get_field_name('suggestion'); ?>" type="checkbox" <?php if($suggestion) echo 'checked="checked"';?> />
  115.          </label>
  116.          </p>
  117. <?php
  118.     }
  119. }
  120. add_action( 'widgets_init', create_function( '', 'return register_widget("advance_search_form_widget");' ) );
  121.  
  122. add_shortcode( 'advance-search', 'parse_advance_search_form' );
  123. function parse_advance_search_form($att){  
  124.     // get options
  125.     $label = get_option('asf-label');;
  126.     $default_text = get_option('asf-placeholder-text');
  127.     $button_text = get_option('asf-button-text');
  128.     $search_for = get_option('asf-post-types',array());
  129.     $show_categories = get_option('asf-show-categories');;
  130.     $show_tag_filter = get_option('asf-show-tag-filter');
  131.     $highlight_results = get_option('asf-highlight-results');
  132.     $select_categories = get_option('asf-categories',array());
  133.     $suggestion = get_option('asf-ajax-suggestion');
  134.     $search_word = $default_text;
  135.     $search_cat = '';
  136.     $s = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : '';
  137.     if(!empty($s)){
  138.         // if we are in search result page
  139.         $search_word = $s;
  140.         $search_cat = isset($_GET['cat']) ? sanitize_text_field($_GET['cat']) : '';
  141.     }
  142. ?>
  143.     <?php
  144.         if(get_option('asf-load-css')){
  145.             wp_enqueue_style('asf-searchform-css',plugins_url('searchform.css', __FILE__));
  146.         }
  147.        
  148.         if($suggestion){
  149.             wp_enqueue_style('asf-suggestion-css',plugins_url('suggestion.css', __FILE__));
  150.         }
  151.     ?>
  152.     <?php
  153. if(get_option('asf-custom-css') != ''){
  154. ?>
  155.     <style type="text/css" scope="scope">
  156.     <?php echo get_option('asf-custom-css');?>
  157.     </style>
  158. <?php
  159. }
  160.     include CT_Widget_Template_Loader::getTemplateHierarchy('shortcode-asf.view');
  161. ?>
  162.    
  163. <?php
  164. }
  165.  
  166. /* FRONT-END */
  167. function asf_searchFilter($query) {
  168.  
  169. // In BBPress, the query to list topics, replies is also 'search' query, so we detect this case
  170.  
  171. $the_query = $query->query;
  172.  
  173. $bbpress_search = false;
  174.  
  175. if(isset($the_query['post_type']) && $query->is_search && (($the_query['post_type'] == 'topic' && $the_query['meta_key'] == '_bbp_last_active_time') || (is_array($the_query['post_type']) && count(array_intersect($the_query['post_type'],array('topic','reply')))))) $bbpress_search = true;
  176.  
  177.     if(!$bbpress_search && (!is_admin() && $query->is_main_query() && $query->is_search)){
  178.  
  179.         $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : '';
  180.         if (!$post_type) {
  181.             $post_type = 'any';
  182.         }
  183.        
  184.         $query->set('post_type', $post_type);
  185.        
  186.         // remove category search      
  187.         $cat = isset($_GET['cat']) ? sanitize_text_field($_GET['cat']) : '';
  188.         if(empty($cat)){
  189.             // if $cat is empty, maybe it's because users choose to search all
  190.             // check if "All Categories" is a number of categories
  191.             $selected_categories = get_option('asf-categories',array());
  192.             if(!empty($selected_categories) && count($selected_categories) > 0){
  193.                 $cat = implode(',',$selected_categories);
  194.             }          
  195.         }
  196.  
  197.         if(!empty($cat)){
  198.             $query->query['cat'] = null;
  199.             $query->query_vars['cat'] = null;
  200.             $query->query_vars['category__in'] = null;
  201.            
  202.             if(!is_array($cat)){
  203.                 $cat = explode(',',$cat);
  204.             }              
  205.            
  206.             $query->set('tax_query',
  207.                     array(
  208.                         array(
  209.                         'taxonomy' => 'category',
  210.                         'terms' => $cat,
  211.                         'field' => 'id',
  212.                         'operator'  => 'IN'
  213.                         )
  214.                     )
  215.                 );
  216.         } else {
  217.             $query->tax_query->queries[]['taxonomy'] = 'category';
  218.         }
  219.        
  220.         $tags = isset($_GET['tags']) ? $_GET['tags'] : '';
  221.         if(!empty($tags)){
  222.             $tags = implode('+', explode(',',$tags));
  223.             $query->query['tag'] = $tags;
  224.             $query->query_vars['tag'] = $tags;
  225.             $query->query_vars['tag__in'] = null;
  226.         }
  227.        
  228.         if(isset($_GET['video_only'])){
  229.             // filter to search on Video Post Format
  230.             $tax_query = array( array(
  231.                 'taxonomy' => 'post_format',
  232.                 'field' => 'slug',
  233.                 'terms' => array( 'post-format-video'),
  234.                 'operator' => 'IN',
  235.             ) );
  236.             $query->set( 'tax_query', $tax_query );
  237.         }
  238.     }
  239.    
  240.     return $query;
  241. };
  242.  
  243. add_filter('pre_get_posts','asf_searchFilter');
  244.  
  245. add_action( 'wp_enqueue_scripts', 'add_advance_search_form_media' );
  246. function add_advance_search_form_media(){
  247.     if(!wp_script_is('advance-search')){
  248.         wp_register_script('advance-search',plugins_url('searchform.js', __FILE__),array('jquery'));
  249.         wp_enqueue_script('advance-search');
  250.         wp_register_script('mousewheel',plugins_url('jquery.mousewheel.js', __FILE__),array('jquery'));
  251.         wp_enqueue_script('mousewheel');
  252.         // declare the URL to the file that handles the AJAX request (wp-admin/admin-ajax.php)
  253.         wp_localize_script( 'advance-search', 'asf', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
  254.     }
  255.    
  256.    
  257.     wp_enqueue_script('jquery');
  258. }
  259.  
  260. /*
  261.  * Count all tags in a category, including tags in sub-categories
  262.  * PARAMS
  263.  * $id:     category id
  264.  */
  265. function asf_get_all_tags_in_category($id){
  266.     global $wpdb;
  267.    
  268.     // get child categories is has any
  269.     if($id != 0){
  270.         // get category taxonomy       
  271.         $childs = get_categories(array('parent' => $id));
  272.     } else {
  273.         $childs = get_categories(array('hierarchical' => false));
  274.     }
  275.    
  276.     $tags = array();
  277.     if(count($childs) > 0){
  278.         foreach($childs as $child){
  279.             $tags = array_merge($tags,asf_get_all_tags_in_category($child->cat_ID));
  280.         }
  281.     }
  282.     if($id != 0){
  283.         $tags1 = $wpdb->get_results
  284.         ($wpdb->prepare("
  285.             SELECT DISTINCT terms2.term_id as tag_id, terms2.name as tag_name, terms2.slug as tag_slug, null as tag_link
  286.             FROM
  287.                 wp_posts as p1
  288.                 LEFT JOIN wp_term_relationships as r1 ON p1.ID = r1.object_ID
  289.                 LEFT JOIN wp_term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id
  290.                 LEFT JOIN wp_terms as terms1 ON t1.term_id = terms1.term_id,
  291.  
  292.                 wp_posts as p2
  293.                 LEFT JOIN wp_term_relationships as r2 ON p2.ID = r2.object_ID
  294.                 LEFT JOIN wp_term_taxonomy as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id
  295.                 LEFT JOIN wp_terms as terms2 ON t2.term_id = terms2.term_id
  296.             WHERE
  297.                 t1.taxonomy = 'category' AND p1.post_status = 'publish' AND terms1.term_id = %d AND
  298.                 t2.taxonomy = 'post_tag' AND p2.post_status = 'publish'
  299.                 AND p1.ID = p2.ID
  300.             ORDER by tag_name
  301.         ", $id));
  302.         $count = 0;
  303.         foreach ($tags1 as $tag) {
  304.             $tags1[$count]->tag_link = get_tag_link($tag->tag_id);
  305.             $count++;
  306.         }
  307.        
  308.         $tags = array_merge($tags,$tags1);
  309.     }
  310.    
  311.     // filter duplicate tags
  312.     $result = array();
  313.     foreach($tags as $tag){
  314.         $not_added = true;
  315.         foreach($result as $res){
  316.             if($tag->tag_name == $res->tag_name){
  317.                 $not_added = false;
  318.                 break;
  319.             }
  320.         }
  321.         if($not_added){
  322.             $result[] = $tag;
  323.         }
  324.     }
  325.     return $result;
  326. }
  327.  
  328. /* Add ajax function for auto suggestion
  329.  * Since 1.1
  330.  */
  331. add_action('wp_ajax_asf_suggestion', 'asf_suggestion_callback');
  332. add_action('wp_ajax_nopriv_asf_suggestion', 'asf_suggestion_callback');
  333.  
  334. function asf_suggestion_callback() {
  335.     global $wpdb; // this is how you get access to the database
  336.  
  337.     $s =  $_POST['s'];
  338.     $cat = $_POST['cat'];
  339.     $tag = $_POST['tag'];
  340.    
  341.     // get custom word
  342.     $words = explode("\r\n",get_option('asf-custom-words'));
  343.     // get post titles
  344.    
  345.     $max = get_option('asf-ajax-count',20);
  346.     if(!is_numeric($max) || $max < 0) $max = 20;
  347.    
  348.     $args = array('s'=>$s,'posts_per_page'=>$max,'post_status'=>'publish');
  349.    
  350.     if(!empty($tag)){
  351.         $args['tag'] = $tag;
  352.     }
  353.    
  354.    
  355.     if(empty($cat)){
  356.         // if $cat is empty, maybe it's because users choose to search all
  357.         // check if "All Categories" is a number of categories
  358.         $selected_categories = get_option('asf-categories',array());
  359.         if(!empty($selected_categories) && count($selected_categories) > 0){
  360.             $cat = implode(',',$selected_categories);
  361.         }
  362.     }  
  363.    
  364.     if(!empty($cat)){
  365.         $args['cat'] = $cat;
  366.     }
  367.    
  368.     $asf_query = new WP_Query($args);
  369.  
  370.     $html = '<ul>';
  371.     if($asf_query->have_posts()){
  372.         //$html = '<ul><li>'. $asf_query->found_posts . '</li></ul>';echo $html;die();
  373.         $idx = 1;
  374.         while($asf_query->have_posts()){
  375.             $asf_query->next_post();
  376.             asf_log($asf_query->post->post_title . " : " . $s);
  377.             if(strpos(strtolower($asf_query->post->post_title),strtolower($s)) !== false){
  378.                 $count++;
  379.                 $html .= '<li><a href="' . get_permalink($asf_query->post->ID) . '">';
  380.                 $html .=    str_replace($s,'<strong>'.$s.'</strong>',$asf_query->post->post_title);
  381.                 $html .= '</a></li>';
  382.                 $idx++;
  383.             }
  384.         }
  385.         //$html = '<ul><li>'. $idx . '</li></ul>';echo $html;die();
  386.     }
  387.     wp_reset_query();
  388.    
  389.     // search categories
  390.     $terms = get_terms('category',array('search'=>$s));
  391.     if(count($terms) > 0){
  392.         foreach($terms as $term){
  393.             $html .= '<li><a href="' . get_term_link($term,'category') . '">';
  394.             $html .= str_replace($s,'<strong>'.$s.'</strong>',$term->name);
  395.             $html .= '</a></li>';
  396.         }
  397.     }
  398.    
  399.     // search tags
  400.     $terms = get_terms('post_tag',array('search'=>$s));
  401.     if(count($terms) > 0){
  402.         foreach($terms as $term){
  403.             $html .= '<li><a href="' . get_term_link($term,'post_tag') . '">';
  404.             $html .= str_replace($s,'<strong>'.$s.'</strong>',$term->name);
  405.             $html .= '</a></li>';
  406.         }
  407.     }
  408.    
  409.     if(count($words) > 0){
  410.         foreach($words as $w){
  411.             if(strpos(strtolower($w),strtolower($s)) !== false){
  412.                 $html .= '<li><a href="javascript:void(0)" onclick="suggestion_onItemClick(this);">';
  413.                 $html .=    str_replace($s,'<strong>'.$s.'</strong>',$w);
  414.                 $html .= '</a></li>';
  415.             }
  416.         }
  417.     }
  418.    
  419.     $html .= '</ul>';
  420.    
  421.     echo $html;
  422.  
  423.     die(); // this is required to return a proper result
  424. }
  425.  
  426. add_action( 'wp_ajax_videopro_search_filters', 'videopro_load_search_results_filter' );
  427. add_action( 'wp_ajax_nopriv_videopro_search_filters', 'videopro_load_search_results_filter' );
  428.  
  429. function videopro_load_search_results_filter(){
  430.     $args = $_POST['search'];
  431.     $video_only = $_POST['video_only'];
  432.    
  433.     $clone_query = new WP_Query($args);
  434.     $posts = $clone_query->get_posts();
  435.    
  436.     // loop through query to get all posts' categories and tags
  437.     $all_categories = array();
  438.     $all_tags = array();
  439.     foreach($posts as $post){
  440.         $cats = wp_get_object_terms($post->ID, 'category');
  441.         $t = wp_get_object_terms($post->ID, 'post_tag');
  442.        
  443.         if($cats && count($cats) > 0){
  444.             $all_categories = array_unique(array_merge($all_categories, $cats), SORT_REGULAR);
  445.         }
  446.        
  447.         if($t && count($t) > 0){
  448.             $all_tags = array_unique(array_merge($all_tags, $t), SORT_REGULAR);
  449.         }
  450.     }
  451.    
  452.     wp_reset_query();
  453.    
  454.    
  455. ?> 
  456.         <?php
  457.        
  458.         $activeFilterItems = '';
  459.        
  460.         if(isset($_POST['cat']) && $_POST['cat'] != ''){?>         
  461.             <?php
  462.                 $cats = $_POST['cat'];
  463.                 $cats = explode(',', $cats);
  464.                 foreach($cats as $cat){
  465.                     if(is_numeric($cat)){
  466.                         $the_cat = get_term_by('id', $cat, 'category');
  467.                         if($the_cat)
  468.                             $activeFilterItems.= '<a href="javascript:;" data-source="' . $the_cat->term_id .'" data-type="cat">' . $the_cat->name . ' (x)</a>';
  469.                     }
  470.                 }
  471.             ?>
  472.         <?php }?>
  473.         <?php
  474.         if(isset($_POST['tags']) && $_POST['tags'] != ''){?>           
  475.             <?php
  476.                 $tags = $_POST['tags'];
  477.                 $tags = explode(',', $tags);
  478.                 foreach($tags as $tag){
  479.                     $the_tag = get_term_by('slug', $tag, 'post_tag');
  480.                     if($the_tag)
  481.                          $activeFilterItems.= '<a href="javascript:;" data-source="' . $the_tag->slug .'" data-type="tags">' . $the_tag->name . ' (x)</a>';
  482.                 }
  483.             ?>
  484.         <?php }?>
  485.        
  486.         <?php
  487.         if(isset($_POST['orderby']) && $_POST['orderby'] != ''){?>         
  488.             <?php
  489.                 $orderby = $_POST['orderby'];
  490.                 if($orderby == 'date'){
  491.                     $activeFilterItems.= '<a href="javascript:;" data-source="date" data-type="orderby">'.esc_html__('Published Date', 'videopro').' (x)</a>';
  492.                 }elseif($orderby == 'view'){
  493.                     $activeFilterItems.= '<a href="javascript:;" data-source="view" data-type="orderby">'.esc_html__('Most Viewed', 'videopro').' (x)</a>';
  494.                 }elseif($orderby == 'like'){
  495.                     $activeFilterItems.= '<a href="javascript:;" data-source="like" data-type="orderby">'.esc_html__('Most Liked', 'videopro').' (x)</a>';
  496.                 }elseif($orderby == 'comments'){
  497.                     $activeFilterItems.= '<a href="javascript:;" data-source="comments" data-type="orderby">'.esc_html__('Most Commented', 'videopro').' (x)</a>';
  498.                 }elseif($orderby == 'title'){
  499.                     $activeFilterItems.= '<a href="javascript:;" data-source="title" data-type="orderby">'.esc_html__('Title', 'videopro').' (x)</a>';
  500.                 }
  501.             ?>         
  502.         <?php }?>
  503.        
  504.         <?php
  505.         if(isset($_POST['order']) && $_POST['order'] != ''){?>         
  506.             <?php
  507.                 $order = $_POST['order'];
  508.                 if($order == 'DESC'){
  509.                     $activeFilterItems.= '<a href="javascript:;" data-source="DESC" data-type="order">'.esc_html__('Descending', 'videopro').' (x)</a>';
  510.                 }elseif($order == 'ASC'){
  511.                     $activeFilterItems.= '<a href="javascript:;" data-source="ASC" data-type="order">'.esc_html__('Ascending', 'videopro').' (x)</a>';
  512.                 }
  513.             ?>         
  514.         <?php }?>
  515.        
  516.         <?php
  517.         if(isset($_POST['length']) && $_POST['length'] != 0){?>        
  518.             <?php
  519.                 $length = @intval($_POST['length']);
  520.                
  521.                 $str = '';
  522.                 $dur = '';
  523.                 if($length <= 4){
  524.                     $str = esc_html__('Short (&lt; 4 mins)','videopro');
  525.                     $dur = '4';
  526.                 } elseif($length <= 20){
  527.                     $str = esc_html__('Medium (&lt; 20 mins)','videopro');
  528.                     $dur = '20';
  529.                 } else{
  530.                     $str = esc_html__('Long (&gt; 20 mins)','videopro');
  531.                     $dur = '10000';
  532.                 }
  533.                 $activeFilterItems.= '<a href="javascript:;" data-source="'.$dur.'" data-type="length">' . $str . ' (x)</a>';
  534.             ?>         
  535.         <?php }?>
  536.        
  537.         <?php if($activeFilterItems!=''){echo '<p class="active-filter-items">'.$activeFilterItems.'</p>';}?>
  538.        
  539.         <?php
  540.         if(!empty($all_categories)){?>
  541.             <p class="filter-item categories-items">
  542.                 <span class="filter-heading"><?php echo esc_html__('Categories: ', 'videopro');?></span>            
  543.                 <?php
  544.                 foreach($all_categories as $cat){
  545.                     echo '<a href="javascript:;" data-cat="' . $cat->term_id .'">' . $cat->name . '</a>';
  546.                 }
  547.                 ?>
  548.             </p>
  549.         <?php }?>
  550.        
  551.         <p class="filter-item orderby-items">
  552.             <span class="filter-heading"><?php echo esc_html__('Sort By: ', 'videopro');?></span>
  553.             <a href="javascript:;" data-orderby="date"><?php echo esc_html__('Published Date','videopro');?></a>
  554.             <a href="javascript:;" data-orderby="view"><?php echo esc_html__('Most Viewed','videopro');?></a>
  555.             <a href="javascript:;" data-orderby="like"><?php echo esc_html__('Most Liked','videopro');?></a>
  556.             <a href="javascript:;" data-orderby="comments"><?php echo esc_html__('Most Commented','videopro');?></a>
  557.             <a href="javascript:;" data-orderby="ratings"><?php echo esc_html__('Most Rated','videopro');?></a>
  558.             <a href="javascript:;" data-orderby="title"><?php echo esc_html__('Title','videopro');?></a>
  559.         </p>
  560.        
  561.         <p class="filter-item order-items">
  562.             <span class="filter-heading"><?php echo esc_html__('Order By: ', 'videopro');?></span>
  563.             <a href="javascript:;" data-order="DESC"><?php echo esc_html__('Descending','videopro');?></a>
  564.             <a href="javascript:;" data-order="ASC"><?php echo esc_html__('Ascending','videopro');?></a>
  565.         </p>
  566.        
  567.         <?php if($video_only){?>
  568.             <p class="filter-item length-items">
  569.                 <span class="filter-heading">
  570.                     <?php echo esc_html__('Video Length: ', 'videopro');?>
  571.                 </span>
  572.                 <a href="javascript:;" data-length="4"><?php echo esc_html__('Short (&lt; 4 mins)','videopro');?></a>
  573.                 <a href="javascript:;" data-length="20"><?php echo esc_html__('Medium (&lt; 20 mins)','videopro');?></a>
  574.                 <a href="javascript:;" data-length="10000"> <?php echo esc_html__('Long (&gt; 20 mins)','videopro');?></a>
  575.             </p>
  576.         <?php }?>
  577.        
  578.         <?php if(!empty($all_tags)){?>        
  579.             <p class="filter-item tags-items">
  580.                 <span class="filter-heading"><?php echo esc_html__('Tags: ', 'videopro');?></span>
  581.                 <?php
  582.                 foreach($all_tags as $tag){
  583.                     echo '<a href="javascript:;" data-tag="' . $tag->slug .'">' . $tag->name . '</a>';
  584.                 }
  585.                 ?>
  586.             </p>
  587.         <?php }?>
  588.        
  589.         <?php
  590.     die();
  591. }
  592.  
  593.  
  594. /* ADMIN - Setting page */
  595. define('_DS_', DIRECTORY_SEPARATOR);
  596. require_once dirname(__FILE__) . _DS_ . 'options.php';
  597.  
  598. if ( is_admin() ){ // admin actions
  599.   add_action( 'admin_menu', 'add_asf_menu' );
  600.   add_action( 'admin_init', 'register_asf_settings' );
  601. } else {
  602.   // non-admin enqueues, actions, and filters
  603. }
  604.  
  605. function asf_enqueue_admin_media($hook) {
  606.     if($hook == 'toplevel_page_advance-search-form/advance-search-form'){
  607.         wp_register_style( 'asf_wp_admin_css', plugin_dir_url( __FILE__ ) . '/admin/options-style.css', false, '1.0.0' );
  608.         wp_enqueue_style( 'asf_wp_admin_css' );
  609.     }
  610. }
  611. add_action( 'admin_enqueue_scripts', 'asf_enqueue_admin_media' );
  612.  
  613. function add_asf_menu(){
  614.     //create new top-level menu
  615.     add_menu_page('Advance Search Form Settings', 'ASF Settings', 'administrator', __FILE__, 'asf_settings_page',plugins_url('/search24x24.png', __FILE__));
  616. }
  617. function register_asf_settings(){
  618.     //register our settings
  619.     register_setting( 'asf-settings-group', 'asf-custom-words' );
  620.     register_setting( 'asf-settings-group', 'asf-include-tag' );
  621.     register_setting( 'asf-settings-group', 'asf-post-types' );
  622.     register_setting( 'asf-settings-group', 'asf-categories' );
  623.     register_setting( 'asf-settings-group', 'asf-show-categories' );
  624.     register_setting( 'asf-settings-group', 'asf-search-video-only' );
  625.     register_setting( 'asf-settings-group', 'asf-custom-css' );
  626.     register_setting( 'asf-settings-group', 'asf-ajax-count' );
  627.     register_setting( 'asf-settings-group', 'asf-show-tag-filter' );   
  628.     register_setting( 'asf-settings-group', 'asf-highlight-results' ); 
  629.     register_setting( 'asf-settings-group', 'asf-ajax-suggestion' );   
  630.     register_setting( 'asf-settings-group', 'asf-button-text' );   
  631.     register_setting( 'asf-settings-group', 'asf-placeholder-text' );  
  632.     register_setting( 'asf-settings-group', 'asf-label' ); 
  633.     register_setting( 'asf-settings-group', 'asf-load-css' );  
  634. }
  635.  
  636. function asf_log($str){
  637.     $file = dirname(__FILE__) . '\log.txt';
  638.     // Write the contents back to the file
  639.     file_put_contents($file, $str . "\r\n",FILE_APPEND | LOCK_EX);
  640. }
  641.  
  642. require_once 'asf-hooks.php';
  643. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top