function wpv_search_by_title_only( $search, &$wp_query ) {
    global $wpdb;
    if ( empty( $search ) )
        return $search; // skip processing - no search term in query
    $q = $wp_query->query_vars;
    $n = ! empty( $q['exact'] ) ? '' : '%';
    $search = '';
    $searchand = "";
    foreach ( (array) $q['search_terms'] as $term ) {
		$term = $n . wpv_esc_like( $term ) . $n;
		$search .= $wpdb->prepare( $searchand . "( $wpdb->posts.post_title LIKE %s )", $term );
		$searchand = " AND ";
    }
    if ( ! empty( $search ) ) {
        $search = " AND ( {$search} ) ";
        if ( ! is_user_logged_in() )
            $search .= " AND ( $wpdb->posts.post_password = '' ) ";
    }
    return $search;
}
 function wpv_suggest_auto_fill_default()
 {
     $field = isset($_REQUEST['field']) ? wpv_esc_like($_REQUEST['field']) : '';
     if (!empty($field)) {
         $needs_db_query = true;
         $input_type = isset($_REQUEST['type']) ? esc_sql($_REQUEST['type']) : '';
         $nice_name = explode('wpcf-', $field);
         $id = isset($nice_name[1]) ? $nice_name[1] : $field;
         $types_options = get_option('wpcf-fields', array());
         if ($types_options && !empty($types_options) && isset($types_options[$id]) && is_array($types_options[$id])) {
             $field_options = $types_options[$id];
             $field_real_type = isset($field_options['type']) ? $field_options['type'] : '';
             if (isset($field_options['data']['options'])) {
                 if ($input_type == 'select') {
                     $field_lowercase = isset($field_options['name']) ? strtolower($field_options['name']) : $id;
                     echo sprintf(__('Select one %s', 'wpv-views'), $field_lowercase) . "\n";
                     echo sprintf(__('Any %s', 'wpv-views'), $field_lowercase) . "\n";
                 }
                 switch ($field_real_type) {
                     case 'checkboxes':
                         foreach ($field_options['data']['options'] as $key => $option) {
                             if (isset($option['display']) && $option['display'] == 'value') {
                                 $title = isset($option['display_value_selected']) ? $option['display_value_selected'] : $option['title'];
                                 $title = $option['title'];
                             } else {
                                 $title = $option['title'];
                             }
                             echo $title . "\n";
                             $needs_db_query = false;
                         }
                         break;
                     case 'select':
                         if (isset($field_options['data']['options']['default'])) {
                             unset($field_options['data']['options']['default']);
                         }
                         foreach ($field_options['data']['options'] as $key => $option) {
                             $title = isset($option['title']) ? $option['title'] : $option['value'];
                             echo $title . "\n";
                             $needs_db_query = false;
                         }
                         break;
                     default:
                         if (isset($field_options['data']['options']['default'])) {
                             unset($field_options['data']['options']['default']);
                         }
                         $display_option = isset($field_options['data']['display']) ? $field_options['data']['display'] : 'db';
                         foreach ($field_options['data']['options'] as $key => $option) {
                             if ($display_option == 'value') {
                                 $title = isset($option['display_value']) ? $option['display_value'] : $option['title'];
                             } else {
                                 $title = $option['title'];
                             }
                             echo $title . "\n";
                             $needs_db_query = false;
                         }
                         break;
                 }
             }
         }
         if ($needs_db_query) {
             if ($input_type == 'select') {
                 echo sprintf(__('Select one %s', 'wpv-views'), $field) . "\n";
                 echo sprintf(__('Any %s', 'wpv-views'), $field) . "\n";
             }
             global $wpdb;
             $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} \n\t\t\t\t\t\t\tWHERE meta_key = %s \n\t\t\t\t\t\t\tORDER BY meta_value \n\t\t\t\t\t\t\tLIMIT 0, 20", $field));
             foreach ($results as $row) {
                 echo $row->meta_value . "\n";
             }
         }
     }
     die;
 }
예제 #3
0
function wpv_scan_view_usage_callback() {
	wpv_ajax_authenticate( 'work_views_listing', array( 'parameter_source' => 'post', 'type_of_death' => 'data' ) );

    $post_id = wpv_getpost( 'id', 0 );
	if ( 0 == $post_id 	) {
		$data = array(
			'message' => __( 'Wrong data', 'wpv-views' )
		);
		wp_send_json_error( $data );
	}

	global $wpdb, $sitepress;
	
	$values_to_prepare = array();
	$trans_join = '';
    $trans_where = '';
    if ( 
		isset( $sitepress ) 
		&& function_exists( 'icl_object_id' )
	) {
		$current_lang_code = $sitepress->get_current_language();
		$trans_join = " JOIN {$wpdb->prefix}icl_translations t ";
		$trans_where = " AND ID = t.element_id AND t.language_code = %s ";
		$values_to_prepare[] = $current_lang_code;
    }
	
    $view = get_post( $post_id );
	$needle = '[wpv-view name="' . $view->post_title . '"';
	$needle = '%' . wpv_esc_like( $needle ) . '%';
	$needle_name = '[wpv-view name="' . $view->post_name . '"';
	$needle_name = '%' . wpv_esc_like( $needle_name ) . '%';
	
	$values_to_prepare[] = $needle;
	$values_to_prepare[] = $needle_name;
	$values_to_prepare[] = $needle;
	$values_to_prepare[] = $needle_name;

    $q = "SELECT DISTINCT * FROM {$wpdb->posts} {$trans_join} 
		WHERE post_status = 'publish' 
		{$trans_where}
		AND post_type NOT IN ('revision')
		AND (
			ID IN ( 
				SELECT DISTINCT ID FROM {$wpdb->posts}
				WHERE ( post_content LIKE %s OR post_content LIKE %s ) 
				AND post_type NOT IN ('revision')
				AND post_status = 'publish' 
			)
			OR ID IN (
				SELECT DISTINCT post_id FROM {$wpdb->postmeta}
				WHERE ( meta_value LIKE %s OR meta_value LIKE %s ) 
			)
		)";

    $res = $wpdb->get_results( 
		$wpdb->prepare(
			$q,
			$values_to_prepare
		),
		OBJECT 
	);
    
	$items = array();
	if ( ! empty( $res ) ) {
        foreach ( $res as $row ) {
            $type = get_post_type_object( $row->post_type );
            $type = $type->labels->singular_name;

            if ( $row->post_type == 'view' ) {
                $edit_link = get_admin_url() . "admin.php?page=views-editor&view_id=" . $row->ID;
            } else if( WPV_Content_Template_Embedded::POST_TYPE == $row->post_type ) {
                $edit_link = wpv_ct_editor_url( $row->ID );
            } else {
                $edit_link = get_admin_url() . "post.php?post=" . $row->ID . "&action=edit";
			}
			
			$items[] = array(
				'id'	=> $row->ID,
				'link'	=> $edit_link,
				'title'	=> "<strong>" . $type . "</strong>: " . $row->post_title
			);
        }
    }
	$data = array(
		'used_on' => $items
	);
	wp_send_json_success( $data );
}
예제 #4
0
 /**
  * wpt_suggest_taxonomy_term
  *
  * Renders the suggestions when adding new flat taxonomy terms on a CRED form
  *
  * Needs a non-empty q attribute and can take an optional non-empty taxonomy attribute on the $_REQUEST
  *
  * @since 1.5.0
  */
 public function wpt_suggest_taxonomy_term()
 {
     if (!isset($_REQUEST['q']) || $_REQUEST['q'] == '') {
         die;
     }
     global $wpdb;
     $values_to_prepare = array();
     if (function_exists("wpv_esc_like")) {
         $term_name = '%' . wpv_esc_like($_REQUEST['q']) . '%';
     } else {
         if (function_exists("cred_wrap_esc_like")) {
             $term_name = '%' . cred_wrap_esc_like($_REQUEST['q']) . '%';
         }
     }
     $values_to_prepare[] = $term_name;
     $tax_join = "";
     $tax_where = "";
     if (isset($_REQUEST['taxonomy']) && $_REQUEST['taxonomy'] != '') {
         $tax_join = " JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id  ";
         $tax_where = " AND tt.taxonomy = %s ";
         $values_to_prepare[] = $_REQUEST['taxonomy'];
     }
     //
     $results = $wpdb->get_results($wpdb->prepare("SELECT name FROM {$wpdb->terms} t {$tax_join}\n\t\t\t\tWHERE t.name LIKE %s \n\t\t\t\t{$tax_where}\n\t\t\t\tORDER BY name DESC \n\t\t\t\tLIMIT 5", $values_to_prepare));
     foreach ($results as $row) {
         echo $row->name . "\n";
     }
     die;
 }
예제 #5
0
function wpv_suggest_wpml_contexts() {
	global $wpdb;
	$context_q = '%' . wpv_esc_like( $_REQUEST['q'] ) . '%';
	$results = $wpdb->get_results( 
		$wpdb->prepare( 
            "SELECT DISTINCT context 
            FROM {$wpdb->prefix}icl_strings
            WHERE context LIKE %s
            ORDER BY context ASC", 
			$context_q 
		) 
	);
	foreach ( $results as $row ) {
		echo $row->context . "\n";
	}
	die();
}
예제 #6
0
function wpv_suggest_form_targets() {
	global $wpdb, $sitepress;
	$trans_join = '';
	$trans_where = '';
	$values_to_prepare = array();
	$title_q = '%' . wpv_esc_like( $_REQUEST['q'] ) . '%';
	$values_to_prepare[] = $title_q;
	$exclude_post_type_slugs_where = '';
	$excluded_post_type_slugs = array();
	$excluded_post_type_slugs = apply_filters( 'wpv_admin_exclude_post_type_slugs', $excluded_post_type_slugs );
	if ( count( $excluded_post_type_slugs ) > 0 ) {
		$excluded_post_type_slugs_count = count( $excluded_post_type_slugs );
		$excluded_post_type_slugs_placeholders = array_fill( 0, $excluded_post_type_slugs_count, '%s' );
		$excluded_post_type_slugs_flat = implode( ",", $excluded_post_type_slugs_placeholders );
		foreach ( $excluded_post_type_slugs as $excluded_post_type_slugs_item ) {
			$values_to_prepare[] = $excluded_post_type_slugs_item;
		}
		$exclude_post_type_slugs_where = "AND post_type NOT IN ({$excluded_post_type_slugs_flat})";
	}
	if ( isset( $sitepress ) && function_exists( 'icl_object_id' ) ) {
		$current_lang_code = $sitepress->get_current_language();
		$trans_join = " JOIN {$wpdb->prefix}icl_translations t ";
		$trans_where = " AND ID = t.element_id AND t.language_code = %s ";
		$values_to_prepare[] = $current_lang_code;
	}
	$results = $wpdb->get_results( 
		$wpdb->prepare( "
            SELECT ID, post_title
            FROM {$wpdb->posts} {$trans_join}
            WHERE post_title LIKE '%s'
			{$exclude_post_type_slugs_where}
			AND post_status='publish' 
			{$trans_where}
            ORDER BY post_title ASC
			LIMIT 5",
			$values_to_prepare 
		) 
	);
	foreach ($results as $row) {
		echo $row->post_title . " [#" . $row->ID . "]\n";
	}
	die();
}
예제 #7
0
function wpv_scan_view_callback()
{
    if (!current_user_can('manage_options')) {
        die("Untrusted user");
    }
    if (!wp_verify_nonce($_POST["wpnonce"], 'work_views_listing')) {
        die("Security check");
        // @todo change this nonce
    }
    if (!isset($_POST["id"]) || !is_numeric($_POST["id"]) || intval($_POST['id']) < 1) {
        die("Untrusted data");
    }
    global $wpdb, $sitepress;
    $values_to_prepare = array();
    $trans_join = '';
    $trans_where = '';
    if (isset($sitepress) && function_exists('icl_object_id')) {
        $current_lang_code = $sitepress->get_current_language();
        $trans_join = " JOIN {$wpdb->prefix}icl_translations t ";
        $trans_where = " AND ID = t.element_id AND t.language_code = %s ";
        $values_to_prepare[] = $current_lang_code;
    }
    $view = get_post($_POST["id"]);
    $needle = '[wpv-view name="' . $view->post_title . '"';
    $needle = '%' . wpv_esc_like($needle) . '%';
    $needle_name = '[wpv-view name="' . $view->post_name . '"';
    $needle_name = '%' . wpv_esc_like($needle_name) . '%';
    $values_to_prepare[] = $needle;
    $values_to_prepare[] = $needle_name;
    $values_to_prepare[] = $needle;
    $values_to_prepare[] = $needle_name;
    $q = "SELECT DISTINCT * FROM {$wpdb->posts} {$trans_join} \n\t\tWHERE post_status = 'publish' \n\t\t{$trans_where}\n\t\tAND post_type NOT IN ('revision')\n\t\tAND (\n\t\t\tID IN ( \n\t\t\t\tSELECT DISTINCT ID FROM {$wpdb->posts}\n\t\t\t\tWHERE ( post_content LIKE %s OR post_content LIKE %s ) \n\t\t\t\tAND post_type NOT IN ('revision')\n\t\t\t\tAND post_status = 'publish' \n\t\t\t)\n\t\t\tOR ID IN (\n\t\t\t\tSELECT DISTINCT post_id FROM {$wpdb->postmeta}\n\t\t\t\tWHERE ( meta_value LIKE %s OR meta_value LIKE %s ) \n\t\t\t)\n\t\t)";
    $res = $wpdb->get_results($wpdb->prepare($q, $values_to_prepare), OBJECT);
    if (!empty($res)) {
        $items = array();
        foreach ($res as $row) {
            $item = array();
            $type = get_post_type_object($row->post_type);
            $type = $type->labels->singular_name;
            $item['post_title'] = "<strong>" . $type . "</strong>: " . $row->post_title;
            if ($row->post_type == 'view') {
                $edit_link = get_admin_url() . "admin.php?page=views-editor&view_id=" . $row->ID;
            } else {
                $edit_link = get_admin_url() . "post.php?post=" . $row->ID . "&action=edit";
            }
            $item['link'] = $edit_link;
            $items[] = $item;
        }
        echo json_encode($items);
    }
    die;
}
예제 #8
0
 /**
  * wpt_suggest_taxonomy_term
  *
  * Renders the suggestions when adding new flat taxonomy terms on a CRED form
  *
  * Needs a non-empty q attribute and can take an optional non-empty taxonomy attribute on the $_REQUEST
  *
  * @since 1.5.0
  */
 public function wpt_suggest_taxonomy_term()
 {
     if (!isset($_REQUEST['q']) || $_REQUEST['q'] == '') {
         die;
     }
     global $wpdb;
     $values_to_prepare = array();
     if (function_exists("wpv_esc_like")) {
         $term_name = '%' . wpv_esc_like($_REQUEST['q']) . '%';
     } else {
         if (function_exists("cred_wrap_esc_like")) {
             $term_name = '%' . cred_wrap_esc_like($_REQUEST['q']) . '%';
         }
     }
     $values_to_prepare[] = $term_name;
     $tax_join = "";
     $tax_where = "";
     if (isset($_REQUEST['taxonomy']) && $_REQUEST['taxonomy'] != '') {
         $tax_join = " JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id  ";
         $tax_where = " AND tt.taxonomy = %s ";
         $values_to_prepare[] = $_REQUEST['taxonomy'];
         global $sitepress;
         if (isset($sitepress)) {
             if (isset($_GET['source_lang'])) {
                 $src_lang = $_GET['source_lang'];
             } else {
                 $src_lang = $sitepress->get_current_language();
             }
             if (isset($_GET['lang'])) {
                 $lang = sanitize_text_field($_GET['lang']);
             } else {
                 $lang = $src_lang;
             }
             $tax_where .= " AND t.term_id in (SELECT element_id from {$wpdb->prefix}icl_translations WHERE element_type = 'tax_{$_REQUEST['taxonomy']}' AND language_code = '{$lang}'  ) ";
         }
     }
     $results = $wpdb->get_results($wpdb->prepare("SELECT name FROM {$wpdb->terms} t {$tax_join}\n\t\t\t\tWHERE t.name LIKE %s \n\t\t\t\t{$tax_where}\n\t\t\t\tORDER BY name DESC \n\t\t\t\tLIMIT 5", $values_to_prepare));
     foreach ($results as $row) {
         echo $row->name . "\n";
     }
     die;
 }
예제 #9
0
	/**
	* wpv_suggest_author
	*
	* Suggest authors using an AJAX callback and built-in suggest script
	*
	* @since unknown
	*/

	static function wpv_suggest_author() {
		global $wpdb;
		$user = '******' . wpv_esc_like( $_REQUEST['q'] ) . '%';
		$results = $wpdb->get_results( 
			$wpdb->prepare( 
				"SELECT DISTINCT ID, display_name FROM {$wpdb->users} 
				INNER JOIN {$wpdb->usermeta} 
				WHERE display_name LIKE %s 
				ORDER BY display_name 
				LIMIT 0, 20", 
				$user 
			) 
		);
		foreach ( $results as $row ) {
			echo $row->display_name . ' # userID: ' . $row->ID . "\n";
		}
		die();
	}
예제 #10
0
	/**
	* wpv_suggest_users
	*
	* Suggest users
	*
	* @since unknown
	*/
	
	static function wpv_suggest_users() {
		$_view_settings = get_post_meta( $_GET['view_id'], '_wpv_settings', true );
		$query_type = 'administrator';
		if ( isset( $_view_settings['roles_type'][0] ) ) {
			$query_type = $_view_settings['roles_type'][0];
		}
		$user = '******' . wpv_esc_like( $_REQUEST['q'] ) . '*';
		$response = array();
		$args = array(
			'search'         => $user,
			'search_columns' => array( 'user_login', 'user_email' ),
			'number' => 20
		);
		if ( $query_type != 'any' ) {
			$args['role'] = $query_type;
		}
		$user_query = new WP_User_Query( $args );
		if ( ! empty( $user_query->results ) ) {
			foreach ( $user_query->results as $user ) {
				$response[] = array('id'=> $user->ID, 'name'=> $user->display_name );
			}
		}
		$json_response = json_encode( $response );
		echo $json_response;
		die();
	}