id="comment-">
'date' );
$tags = wp_get_post_terms( $post->ID, $taxonomy, $tax_args );
if ( $tags ) {
foreach ( $tags as $tag ) {
$args = array(
$param_type => $tag->slug,
'post__not_in' => array( $post->ID ),
'post_type' => POST_TYPE,
'posts_per_page' => 3,
'ignore_sticky_posts' => 1
);
}
$my_query = null;
$my_query = new WP_Query( $args );
$loop_count = 0;
$col_class = '';
if ( $my_query->have_posts() ) {
echo '';
echo '- ';
while ( $my_query->have_posts() && $loop_count != 3 ) : $my_query->the_post();
$loop_count++;
if ( $loop_count == 3 ) {
$col_class = 'last';
}
$img_meta = get_post_meta( $post->ID, 'geocraft_meta_image1', true );
?>
';
echo '
';
}
}
wp_reset_query(); // to use the original query again
}
/**
* Function Name: geocraft_excerpt
* Description: It returns linked elipse
* @param type $text
* @return type
*/
function geocraft_excerpt( $more ) {
return ' [...] Read More';
}
add_filter( 'excerpt_more', 'geocraft_excerpt' );
/**
* Function Name: geocraft_auth_menu
* Description: Displays user menu
* @global type $current_user
*/
function geocraft_auth_menu() {
global $current_user;
global $wpdb;
$dashboard_pid = get_option( 'geo_dashboard_page' );
$ink = home_url( "/?page_id=$dashboard_pid" );
$geo_val = $wpdb->get_row( "SELECT * FROM $wpdb->posts WHERE ID =$dashboard_pid ", ARRAY_N );
if ( !$geo_val[0] ) {
$wpdb->insert( $wpdb->posts, array( 'ID' => $dashboard_pid, 'post_author' => 1, 'post_date_gmt' => $dat, 'post_title' => 'Dashboard', 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_name' => 'dasboard', 'guid' => $ink, 'post_type' => 'page' ) );
$mylink = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE post_id =$dashboard_pid ", ARRAY_N );
$wpdb->insert( $wpdb->postmeta, array( 'meta_id' => $mylink[0], 'post_id' => $dashboard_pid, 'meta_key' => '_wp_page_template', 'meta_value' => 'template_dashboard.php' ) );
}
if ( $geo_val[7] == 'trash' ) {
$wpdb->query( "UPDATE $wpdb->posts SET post_status = 'publish' WHERE ID =$dashboard_pid" );
}
$geo_list = get_option( 'geo_submit_listing' );
$geo_url = site_url( '/?page_id=' . get_option( 'geo_submit_listing' ) );
$geo_val_list = $wpdb->get_row( "SELECT * FROM $wpdb->posts WHERE ID =$geo_list ", ARRAY_N );
if ( !$geo_val_list[0] ) {
$wpdb->insert( $wpdb->posts, array( 'ID' => $geo_list, 'post_author' => 1, 'post_date_gmt' => $dat, 'post_title' => 'Add New Listing', 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_name' => 'submit-listing', 'guid' => $geo_url, 'post_type' => 'page', 'post_excerpt' => '' ) );
$listlink = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE post_id =$geo_list ", ARRAY_N );
$wpdb->insert( $wpdb->postmeta, array( 'meta_id' => $listlink[0], 'post_id' => $geo_list, 'meta_key' => '_wp_page_template', 'meta_value' => 'template_submit.php', ) );
}
if ( $geo_val_list[7] == 'trash' ) {
$wpdb->query( "UPDATE $wpdb->posts SET post_status = 'publish' WHERE ID =$geo_list" );
}
?>
prefix;
$wpcat_id = NULL;
//Fetch category
$wpcategories = (array) $wpdb->get_results( "
SELECT * FROM {$table_prefix}terms, {$table_prefix}term_taxonomy
WHERE {$table_prefix}terms.term_id = {$table_prefix}term_taxonomy.term_id
AND {$table_prefix}term_taxonomy.taxonomy ='" . $taxonomy . "' and {$table_prefix}term_taxonomy.parent=0 ORDER BY {$table_prefix}terms.name" );
$wpcategories = array_values( $wpcategories );
$wpcat2 = NULL;
if ( $wpcategories ) {
echo "";
if ( $taxonomy == CUSTOM_CATEGORY_TYPE ) {
?>
term_id;
$name = ucfirst( $wpcat->name );
$termprice = $wpcat->term_price;
$tparent = $wpcat->parent;
?>
term_taxonomy_id;
$term_tax_id = $term->term_id;
$termprice = $term->term_price;
$name = $term->name;
$catprice = $wpdb->get_row( "select * from $wpdb->term_taxonomy tt ,$wpdb->terms t where t.term_id='" . $child_of->term_id . "' and t.term_id = tt.term_id" );
?>
";
}
}
// Output errors
function geocraft_show_errors( $errors, $id = '' ) {
if ( $errors && sizeof( $errors ) > 0 && $errors->get_error_code() ) :
echo '';
foreach ( $errors->errors as $error ) {
echo '- ' . $error[0] . '
';
}
echo '
';
endif;
}
/**
* Function for get author info
* @global type $wpdb
* @param type $post_id
* @return type
*/
function get_author_info( $post_id ) {
global $wpdb;
$sql = "SELECT $wpdb->users.*
FROM
$wpdb->users
INNER JOIN $wpdb->posts
ON $wpdb->users.ID = $wpdb->posts.post_author where $wpdb->posts.post_author=$post_id";
$returninfo = $wpdb->get_row( $sql );
return $returninfo;
}
/**
* Function Name: custom_post_author_archive
* Description: Displaying custom post type author archives
* @param type $query
*/
function custom_post_author_archive( &$query ) {
if ( $query->is_author )
$query->set( 'post_type', POST_TYPE );
remove_action( 'pre_get_posts', 'custom_post_author_archive' ); // run once!
}
add_action( 'pre_get_posts', 'custom_post_author_archive' );
function filter_search( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', POST_TYPE );
};
return $query;
}
;
//add_filter('pre_get_posts', 'filter_search');
/**
* Function Name: get_custom_search()
* Description: multisearch
* @global type $wpdb global database
* @param type $post_id current post id
* @param type $addvalue
* @return boolean
*/
function get_custom_search( $post_id, $addvalue ) {
global $wpdb;
$sql = "SELECT *
FROM
$wpdb->posts, $wpdb->postmeta
WHERE
$wpdb->posts.ID = $post_id
AND $wpdb->postmeta.post_id = $post_id
AND $wpdb->postmeta.meta_key = 'geocraft_meta_address'
AND $wpdb->postmeta.meta_value LIKE '%$addvalue %'";
$data = $wpdb->get_row( $sql );
if ( $data ) {
return true;
}
}
function my_custom_post_type_archive_where( $where, $args ) {
$post_type = POST_TYPE;
$where = "WHERE post_type = '$post_type' AND post_status = 'publish'";
return $where;
}
add_filter( 'getarchives_where', 'my_custom_post_type_archive_where', 10, 2 );
/**
* Function Name: posts_for_current_author()
* Description: Filter all listing and post by current auther
* @global type $user_ID
* @param type $query
* @return type
*/
function posts_for_current_author( $query ) {
if ( $query->is_admin ) {
global $user_ID;
$query->set( 'author', $user_ID );
}
return $query;
}
if ( !current_user_can( 'administrator' ) ) :
add_filter( 'pre_get_posts', 'posts_for_current_author' );
endif;
/**
* Show admin bar only for admins
*/
if ( !current_user_can( 'manage_options' ) ) {
add_filter( 'show_admin_bar', '__return_false' );
}
/**
* Function for remove post status count in others users admin area
*/
function jquery_remove_counts() {
?>
is_valid ) {
$captchaError = 'The captcha was incorrect.';
$hasError = true;
}
}
if ( (!isset( $hasError )) || (geocraft_get_option( 'geo_lead_captcha' ) == 'off') || (geocraft_get_option( 'geo_lead_captcha' ) == '') ) {
global $post, $wpdb, $inquiry_tbl_name;
//if not exist table inquiry
$inquiry_tbl_name = $wpdb->prefix . 'inquiry';
$name = $_POST['name'];
$email = $_POST['email'];
$contact = $_POST['contact'];
$messate = $_POST['message'];
$validate = $_POST['form_validate'];
$sql = "SELECT * FROM $inquiry_tbl_name WHERE form_valid = $validate";
$valid_query = $wpdb->get_row( $sql );
$listing_id = $post->ID;
$listing_author = $post->post_author;
$listing_title = $post->post_title;
$date = date( "Y-m-d H:i:s" );
$success = '';
if ( !$valid_query ) {
if ( $name != '' && $messate != '' ) {
$wpdb->insert(
$inquiry_tbl_name, array(
'listing_author' => $listing_author,
'listing_id' => $listing_id,
'user_name' => $name,
'email' => $email,
'phone_no' => $contact,
'message' => $messate,
'listing_title' => $listing_title,
'inquiry_date' => $date,
'form_valid' => $validate
)
);
$success = "Your Message Submitted - Thank You";
}
$email_message .="Listing Title: " . $listing_title . "\n";
$email_message .="User Name: " . $name . "\n";
$email_message .="Message: " . $messate . "\n";
$email_message .="Email: " . $email . "\n";
$email_message .="Contact Number: " . $contact . "\n";
$to = get_the_author_meta( 'user_email', $post->post_author );
$subject = 'Your listing subscription notification';
$headers = 'From: ' . $name . ' <' . $email . '>' . "\r\n" . 'Reply-To: ' . $email;
wp_mail( $to, $subject, $email_message, $headers );
}
}
}
// $captcha_value1 = geocraft_captcha1();
//$captcha_value2 = geocraft_captcha2();
// $geocraft_sbs_captcha = $captcha_value1 + $captcha_value2;
?>
query( $query );
}
?>
|
|
|
|
|
|
|
ID;
global $wpdb;
$query = "SELECT * FROM $inquiry_tbl_name";
$results = $wpdb->get_results( $query );
if ( $results ):
?>
listing_author || current_user_can( 'create_users' ) ) {
?>
| ID; ?> |
user_name; ?> |
email; ?> |
phone_no; ?> |
message; ?> |
listing_title; ?> |
ID" ); ?>"> |
| No inquiries found. |
postmeta.post_id , $wpdb->postmeta.meta_id , $wpdb->postmeta.meta_key FROM $wpdb->postmeta
WHERE
$wpdb->postmeta.meta_key = 'geocraft_dummy_content'
AND $wpdb->postmeta.meta_value = 1";
$pids_info = $wpdb->get_results( $pids_sql );
foreach ( $pids_info as $pids_info_obj ) {
wp_delete_post( $pids_info_obj->post_id );
}
}
/**
* Function Name: geocraft_dummydata_notify()
* Description: To insert and delete dummy data
*
* @global type $wpdb
*/
function geocraft_dummydata_notify() {
global $wpdb;
if ( strstr( $_SERVER['REQUEST_URI'], 'themes.php' ) && $_REQUEST['template'] == '' && $_GET['page'] == '' ) {
if ( $_REQUEST['dummy'] == 'delete' ) {
delete_dummy_data();
$dummy_deleted = '' . DUMMY_DT_DLT . '
';
}
if ( $_REQUEST['dummy_insert'] ) {
include_once (CONTROLPATH . 'install_data.php'); //Install dummy data
}
if ( $_REQUEST['activated'] == 'true' ) {
$theme_activate_success = '' . THEME_ACTIVATED . '
';
}
$post_counts = $wpdb->get_var( "SELECT count($wpdb->postmeta.post_id) FROM $wpdb->postmeta
WHERE
$wpdb->postmeta.meta_key = 'geocraft_dummy_content'
AND $wpdb->postmeta.meta_value = 1" );
if ( $post_counts > 0 ) {
$dummy_data_notify = ' ' . SAMPLE_DT_PAPU . '
';
$button = '' . YES_DEL . '';
} else {
$dummy_data_notify = '
' . LIKE_TOP_POPULATED . '
';
$button = 'Yes Insert Sample Data';
}
$dummy_msg = "$button
";
?>
' . $theme_activate_success . $dummy_deleted . $dummy_data_notify . $dummy_msg . '';
}
}
add_action( 'admin_notices', 'geocraft_dummydata_notify' );
/**
* Function Name: custom_search()
* Description: returns results from search or search location
* @global type $wpdb
* @param type $search_string
* @param type $search_loc
* @return type
*/
function custom_search( $search_string, $search_loc ) {
global $wpdb;
$meta_key = 'geo_address';
$meta_key2 = 'geocraft_listing_type';
$meta_val = 'pro';
$search_string = stripslashes( $search_string );
$search_loc = stripslashes( $search_loc );
$post_type = POST_TYPE;
$n = '%';
$query_field .= "(($wpdb->posts.post_title LIKE '{$n}{$search_string}{$n}')";
$query_field .= "OR";
$query_field .= "($wpdb->posts.post_content LIKE '{$n}{$search_string}{$n}'))";
$query_field .= "AND";
$query_field .= "(($wpdb->postmeta.meta_key = '$meta_key')";
$query_field .= "AND";
$query_field .= "($wpdb->postmeta.meta_value LIKE '{$n}{$search_loc}{$n}')";
$query_field .= "AND ($wpdb->posts.post_status = 'publish')";
$query_field .= "AND";
$query_field .= "($wpdb->posts.post_type = '$post_type'))";
$sql = "SELECT DISTINCT $wpdb->posts.* FROM $wpdb->posts INNER JOIN $wpdb->postmeta where ({$query_field})";
$query = $wpdb->get_results( $sql );
return $query;
}
/**
* Function Name: custom_search_location()
* Description: returns results from location
* @global type $wpdb
* @param type $search_string
* @param type $search_loc
* @return type
*/
function custom_search_location( $search_loc ) {
global $wpdb;
$meta_key = 'geo_address';
$meta_key2 = 'geocraft_listing_type';
$meta_val = 'pro';
$search_string = stripslashes( $search_string );
$search_loc = stripslashes( $search_loc );
$post_type = POST_TYPE;
$n = '%';
$query_field .= "($wpdb->postmeta.meta_key = '$meta_key')";
$query_field .= "AND";
$query_field .= "($wpdb->postmeta.meta_value LIKE '{$n}{$search_loc}{$n}')";
$query_field .= "AND ($wpdb->posts.post_status = 'publish')";
$query_field .= "AND";
$query_field .= "($wpdb->posts.post_type = '$post_type')";
$sql = "SELECT DISTINCT $wpdb->posts.* FROM $wpdb->posts INNER JOIN $wpdb->postmeta where ({$query_field})";
$query = $wpdb->get_results( $sql );
return $query;
}
/**
* Function Name: get_date_time_difference()
* Description: returns differences between two dates
* @param type $start_date - last post date
* @param type $current_date - current date
* @return type array
*/
function get_date_time_difference( $start_date, $current_date ) {
$diffrence = abs( strtotime( $current_date ) - strtotime( $start_date ) );
$years = floor( $diffrence / (365 * 60 * 60 * 24) );
$months = floor( ($diffrence - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24) );
$days = floor( ($diffrence - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24) );
$hours = floor( ($diffrence - $years * (365 * 60 * 60 * 24) - $months * (30 * 60 * 60 * 24) - $days * (60 * 60 * 24)) / (60 * 60) );
$mins = floor( ($diffrence - ($years * (365 * 60 * 60 * 24)) - $months * (30 * 60 * 60 * 24) - ($days * (60 * 60 * 24)) - ($hours * (60 * 60))) / 60 ); #floor($difference / 60);
$secs = floor( ($diffrence - ($years * (365 * 60 * 60 * 24)) - $months * (30 * 60 * 60 * 24) - ($days * (60 * 60 * 24)) - ($hours * (60 * 60)) - ($mins * 60) ) ); #floor($difference / 60);
$dateExtract = array(
'year' => $years,
'months' => $months,
'days' => $days,
'hours' => $hours,
'mins' => $mins,
'secs' => $secs
);
return $dateExtract;
}
function get_category_list() {
global $wpdb;
$taxonomy = CUSTOM_CAT_TYPE;
$table_prefix = $wpdb->prefix;
$wpcat_id = NULL;
//Fetch category
$wpcategories = (array) $wpdb->get_results( "
SELECT * FROM {$table_prefix}terms, {$table_prefix}term_taxonomy
WHERE {$table_prefix}terms.term_id = {$table_prefix}term_taxonomy.term_id
AND {$table_prefix}term_taxonomy.taxonomy ='" . $taxonomy . "' and {$table_prefix}term_taxonomy.parent=0 ORDER BY {$table_prefix}terms.name" );
$wpcategories = array_values( $wpcategories );
if ( $wpcategories ) {
echo "";
if ( $taxonomy == CUSTOM_CAT_TYPE ) {
?>
term_id;
$name = $wpcat->name;
$termprice = $wpcat->term_price;
$tparent = $wpcat->parent;
?>
";
}
}
/**
* Function Name: get_post_date_gmt()
* Description: returns post date gmt by post id
* @global type $wpdb
* @param type $post_id
* @return type date
*/
function get_post_date_gmt( $post_id ) {
global $wpdb;
$expiry_tbl_name = GC_EXPIRY_TBL;
$sql = "SELECT " . $expiry_tbl_name . ".listing_date FROM " . $expiry_tbl_name . " WHERE " . $expiry_tbl_name . ".pid = $post_id";
$query = $wpdb->get_row( $sql );
$last_post_date = $query->listing_date;
return $last_post_date;
}
/**
* Function : get_billing_period()
* Description: Returns total days of billing cycle.
* @param type $first_billing_per - first billing period quantity
* @param type $first_billing_cycle - first billing cycle day, month, year
* @param type $second_billing_per - second billing period quantity
* @param type $second_billing_cycle - second billing cycle day, month, year
* @return type - total billing period
*/
function get_billing_period( $first_billing_per, $first_billing_cycle, $second_billing_per, $second_billing_cycle ) {
if ( $first_billing_cycle == 'M' ):
if ( $second_billing_cycle == 'M' ):
$rvalidity = ($first_billing_per * 30) + ($second_billing_per * 30);
elseif ( $second_billing_cycle == 'Y' ):
$rvalidity = ($first_billing_per * 30) + ($second_billing_per * 365);
elseif ( $second_billing_cycle == 'D' ):
$rvalidity = ($first_billing_per * 30) + ($second_billing_per);
endif;
elseif ( $first_billing_cycle == 'Y' ):
if ( $second_billing_cycle == 'M' ):
$rvalidity = ($first_billing_per * 365) + ($second_billing_per * 30);
elseif ( $second_billing_cycle == 'Y' ):
$rvalidity = ($first_billing_per * 365) + ($second_billing_per * 365);
elseif ( $second_billing_cycle == 'D' ):
$rvalidity = ($first_billing_per * 365) + ($second_billing_per);
endif;
elseif ( $first_billing_cycle == 'D' ):
if ( $second_billing_cycle == 'M' ):
$rvalidity = ($first_billing_per) + ($second_billing_per * 30);
elseif ( $second_billing_cycle == 'Y' ):
$rvalidity = ($first_billing_per) + ($second_billing_per * 365);
elseif ( $second_billing_cycle == 'D' ):
$rvalidity = ($first_billing_per) + ($second_billing_per);
endif;
endif;
return $rvalidity;
}
/**
* Function: get_billing_period_by()
* Description: Returns array of days, months and years billing cycle
* @param type $first_billing_per
* @param type $first_billing_cycle
* @param type $second_billing_per
* @param type $second_billing_cycle
* @return type
*/
function get_billing_period_by( $first_billing_per, $first_billing_cycle, $second_billing_per, $second_billing_cycle ) {
$days = 0;
$months = 0;
$years = 0;
$billing_period = array();
if ( $first_billing_cycle == 'M' ):
if ( $second_billing_cycle == 'M' ):
$months += ($first_billing_per * 30) + ($second_billing_per * 30);
elseif ( $second_billing_cycle == 'Y' ):
$years += ($first_billing_per * 30) + ($second_billing_per * 365);
elseif ( $second_billing_cycle == 'D' ):
$days += ($first_billing_per * 30) + ($second_billing_per);
endif;
elseif ( $first_billing_cycle == 'Y' ):
if ( $second_billing_cycle == 'M' ):
$months += ($first_billing_per * 365) + ($second_billing_per * 30);
elseif ( $second_billing_cycle == 'Y' ):
$years += ($first_billing_per * 365) + ($second_billing_per * 365);
elseif ( $second_billing_cycle == 'D' ):
$days += ($first_billing_per * 365) + ($second_billing_per);
endif;
elseif ( $first_billing_cycle == 'D' ):
if ( $second_billing_cycle == 'M' ):
$months += ($first_billing_per) + ($second_billing_per * 30);
elseif ( $second_billing_cycle == 'Y' ):
$years += ($first_billing_per) + ($second_billing_per * 365);
elseif ( $second_billing_cycle == 'D' ):
$days += ($first_billing_per) + ($second_billing_per);
endif;
endif;
$months = $months / 30;
$years = $years / 365;
$billing_period['days'] = $days;
$billing_period['months'] = $months;
$billing_period['years'] = $years;
return $billing_period;
}
/**
* Function: get_day_difference($start_date, $end_date)
* Description: Returns total days of start date to end date
* @param type $start_date
* @param type $end_date
* @return type
*/
function get_day_difference( $start_date, $end_date ) {
list($date, $time) = explode( ' ', $start_date );
if ( $time == NULL ) {
$time = '00:00:00';
}
$startdate = explode( "-", $date );
$starttime = explode( ":", $time );
list($date, $time) = explode( ' ', $end_date );
if ( $time == NULL ) {
$time = '00:00:00';
}
$enddate = explode( "-", $date );
$endtime = explode( ":", $time );
$secons_dif = mktime( $endtime[0], $endtime[1], $endtime[2], $enddate[1], $enddate[2], $enddate[0] ) -
mktime( $starttime[0], $starttime[1], $starttime[2], $startdate[1], $startdate[2], $startdate[0] );
//Different can be returned in many formats
//In Minutes: floor($secons_dif/60);
//In Hours: floor($secons_dif/60/60);
//In days: floor($secons_dif/60/60/24);
//In weeks: floor($secons_dif/60/60/24/7;
//In Months: floor($secons_dif/60/60/24/7/4);
//In years: floor($secons_dif/365/60/24);
//We will return it in hours
$difference = floor( $secons_dif / 60 / 60 / 24 );
return $difference;
}
/**
* Function: get_minute_difference($start_date, $end_date)
* Description: Returns total days of start date to end date
* @param type $start_date
* @param type $end_date
* @return type
*/
function get_minute_difference( $start_date, $end_date ) {
list($date, $time) = explode( ' ', $start_date );
if ( $time == NULL ) {
$time = '00:00:00';
}
$startdate = explode( "-", $date );
$starttime = explode( ":", $time );
list($date, $time) = explode( ' ', $end_date );
if ( $time == NULL ) {
$time = '00:00:00';
}
$enddate = explode( "-", $date );
$endtime = explode( ":", $time );
$secons_dif = mktime( $endtime[0], $endtime[1], $endtime[2], $enddate[1], $enddate[2], $enddate[0] ) -
mktime( $starttime[0], $starttime[1], $starttime[2], $startdate[1], $startdate[2], $startdate[0] );
//Different can be returned in many formats
//In Minutes: floor($secons_dif/60);
//In Hours: floor($secons_dif/60/60);
//In days: floor($secons_dif/60/60/24);
//In weeks: floor($secons_dif/60/60/24/7;
//In Months: floor($secons_dif/60/60/24/7/4);
//In years: floor($secons_dif/365/60/24);
//We will return it in hours
$difference_minute = floor( $secons_dif / 60 );
return $difference_minute;
}
/**
* Function: get_recurring_period()
* Description: Returns total days of recurring period
* @global type $wpdb
* @global type $price_table_name
* @return type
*/
function get_recurring_period() {
global $wpdb;
$price_table_name = GC_PRICE_TBL;
$pricesql = "SELECT * FROM $price_table_name WHERE status=1";
$priceinfo = $wpdb->get_results( $pricesql );
foreach ( $priceinfo as $priceinfoObj ) {
if ( $priceinfoObj->package_type == 'pkg_recurring' ) {
$first_billing_per = $priceinfoObj->first_billing_per;
$first_billing_cycle = $priceinfoObj->first_billing_cycle;
$second_billing_per = $priceinfoObj->second_billing_per;
$second_billing_cycle = $priceinfoObj->second_billing_cycle;
if ( ($priceinfoObj->first_billing_per != "" || $priceinfoObj->first_billing_per != 0 ) ) {
$recurring_period = get_billing_period( $first_billing_per, $first_billing_cycle, $second_billing_per, $second_billing_cycle );
}
}
}
return $recurring_period;
}
/**
* Function: get_onetime_pkg_price()
* Description: Returns package cost of one time payment package
* @global type $wpdb
* @global type $price_table_name
* @return type
*/
function get_onetime_pkg_price() {
global $wpdb;
$price_table_name = GC_PRICE_TBL;
$sql = "SELECT package_cost FROM $price_table_name WHERE pid = 2";
$pkg_cost = $wpdb->get_row( $sql );
return $pkg_cost;
}
function get_billingtime() {
global $wpdb;
$price_table_name = GC_PRICE_TBL;
$sql = "SELECT rebill_time FROM $price_table_name WHERE package_type = 'pkg_recurring'";
$billing_time = $wpdb->get_results( $sql );
return $billing_time;
}
/**
* Function : get_currency_symbol()
* Description: returns currency symbol.
* @global type $wpdb
* @global type $currency_tbl_name
* @return type
*/
function get_currency_symbol() {
$currency_code = get_option( 'currency_code' );
global $wpdb;
$currency_tbl_name = GC_CURRENCY_TBL;
$sql = "SELECT c_symbol
FROM `$currency_tbl_name`
WHERE `c_code` = '$currency_code'";
$symbol = $wpdb->get_row( $sql );
return $symbol->c_symbol;
}
// Update the currency_symbol
$currency_symbol = get_currency_symbol();
if ( $currency_symbol ):
update_option( 'currency_symbol', $currency_symbol );
endif;
function custom_search_by_paidlisting( $search, $loc ) {
global $wpdb;
$n = '%';
$meta_value = 'pro';
$meta_key1 = 'geocraft_meta_address';
$meta_key2 = 'geocraft_listing_type';
$search_string = stripslashes( $search );
$search_loc = stripslashes( $loc );
$query .= "(($wpdb->posts.post_title LIKE '{$n}{$search_string}{$n}')";
$query .= "OR";
$query .= "($wpdb->posts.post_content LIKE '{$n}{$search_string}{$n}')";
$query .= "AND";
$query .= "(($wpdb->postmeta.meta_key = '$meta_key1')";
$query .= "AND";
$query .= "($wpdb->postmeta.meta_value LIKE '{$n}{$search_loc}{$n}'))";
$query .= "AND";
$query .= "(($wpdb->postmeta.meta_key = '$meta_key2')";
$query .= "AND";
$query .= "($wpdb->postmeta.meta_value = '$meta_value')))";
$query .= "AND";
$query .= "($wpdb->posts.post_status = 'publish')";
$query .= "AND";
$query .= "($wpdb->posts.post_type = 'listing')";
$sql = "SELECT DISTINCT $wpdb->posts.* FROM $wpdb->posts INNER JOIN $wpdb->postmeta where ({$query}) ";
$query = $wpdb->get_results( $sql );
return ($query);
}
function custom_search_by_freelisting( $search, $loc ) {
global $wpdb;
$n = '%';
$meta_value = 'free';
$meta_key1 = 'geocraft_meta_address';
$meta_key2 = 'geocraft_listing_type';
$search_string = stripslashes( $search );
$search_loc = stripslashes( $loc );
$query .= "(($wpdb->posts.post_title LIKE '{$n}{$search_string}{$n}')";
$query .= "OR";
$query .= "($wpdb->posts.post_content LIKE '{$n}{$search_string}{$n}')";
$query .= "AND";
$query .= "(($wpdb->postmeta.meta_key = '$meta_key1')";
$query .= "AND";
$query .= "($wpdb->postmeta.meta_value LIKE '{$n}{$search_loc}{$n}'))";
$query .= "AND";
$query .= "(($wpdb->postmeta.meta_key = '$meta_key2')";
$query .= "AND";
$query .= "($wpdb->postmeta.meta_value = '$meta_value')))";
$query .= "AND";
$query .= "($wpdb->posts.post_status = 'publish')";
$query .= "AND";
$query .= "($wpdb->posts.post_type = 'listing')";
$sql = "SELECT DISTINCT $wpdb->posts.* FROM $wpdb->posts INNER JOIN $wpdb->postmeta where ({$query}) ";
$query = $wpdb->get_results( $sql );
return ($query);
}
function get_custom_field() {
global $wpdb;
$cfield_tbl_name = GC_CFIELD_TBL;
$query = "SELECT * FROM $cfield_tbl_name WHERE is_active = 1 ORDER BY p_order asc,fid asc";
$fields = $wpdb->get_results( $query );
$returnarray = array();
foreach ( $fields as $field ) {
if ( $field->f_type ) {
$options = explode( ',', $field->opt_value );
}
$custom_fields = array(
"name" => $field->f_var_nm,
"title" => $field->f_title,
"field_category" => $field->field_cate,
"htmlvar_name" => $field->f_var_nm,
"default" => $field->dft_value,
"type" => $field->f_type,
"description" => $field->f_des,
"option_values" => $field->opt_value,
"order" => $field->p_order,
"is_require" => $field->is_require,
"is_active" => $field->is_active,
"show_on_listing" => $field->show_on_detail,
"show_free" => $field->show_free,
);
if ( $options ) {
$custom_fields["options"] = $options;
}
$returnarray[$field->f_var_nm] = $custom_fields;
}
return $returnarray;
}
function gc_renewal_periond() {
global $wpdb;
$price_table_name = GC_PRICE_TBL;
$sql = "SELECT * FROM $price_table_name";
$QUERY = $wpdb->get_results( $sql );
foreach ( $QUERY as $q ) {
if ( $q->package_type == "pkg_free" ) {
if ( $q->renewal_cycle == "M" )
return $q->renewal_per * 30;
if ( $q->renewal_cycle == "Y" )
return $q->renewal_per * 365;
if ( $q->renewal_cycle == "D" )
return $q->renewal_per;
}
}
}
function gc_renewal_time( $pkg_type ) {
global $wpdb;
$price_table_name = GC_PRICE_TBL;
$sql = "SELECT * FROM $price_table_name";
$QUERY = $wpdb->get_results( $sql );
foreach ( $QUERY as $q ) {
if ( $q->package_type == "pkg_one_time" && $pkg_type == 'pkg_one_time' ) {
if ( $q->validity_per == "M" )
return $q->validity * 30;
elseif ( $q->validity_per == "Y" )
return $q->validity * 365;
elseif ( $q->validity_per == "D" )
return $q->validity;
}elseif ( $q->package_type == "pkg_recurring" && $pkg_type == 'pkg_recurring' ) {
//First billing
if ( $q->first_billing_cycle == 'D' )
$first_billing = $q->first_billing_per;
elseif ( $q->first_billing_cycle == 'M' )
$first_billing = $q->first_billing_per * 30;
elseif ( $q->first_billing_cycle == 'Y' )
$first_billing = $q->first_billing_per * 365;
//Second billing
if ( $q->second_billing_cycle == "D" )
$second_billing = $q->second_billing_per;
elseif ( $q->second_billing_cycle == "M" )
$second_billing = $q->second_billing_per * 30;
elseif ( $q->second_billing_cycle == "Y" )
$second_billing = $q->second_billing_per * 365;
return $first_billing;
}
}
}
function gc_set_expiry( $post_id, $pkg_type = '' ) {
global $wpdb;
$price_table_name = GC_PRICE_TBL;
$sql = "SELECT * FROM $price_table_name";
$QUERY = $wpdb->get_results( $sql );
foreach ( $QUERY as $q ) {
$ad_length = $q->validity;
$listing_type = get_post_meta( $post_id, 'geocraft_listing_type', true );
if ( ($q->package_type == 'pkg_free' && $listing_type == 'free') || $pkg_type == 'pkg_free' ) {
if ( $q->validity_per == 'D' ) {
} elseif ( $q->validity_per == 'M' ) {
$ad_length = $ad_length * 30;
} elseif ( $q->validity_per == 'Y' ) {
$ad_length = $ad_length * 365;
}
$free_ad_duration = date_i18n( 'm/d/Y H:i:s', strtotime( '+' . $ad_length . ' days' ) );
update_post_meta( $post_id, 'gc_listing_duration', $free_ad_duration );
} if ( ($q->package_type == 'pkg_one_time' && $listing_type == 'pro') || $pkg_type == 'pkg_one_time' ) {
if ( $q->validity_per == 'D' ) {
} elseif ( $q->validity_per == 'M' ) {
$ad_length = $ad_length * 30;
} elseif ( $q->validity_per == 'Y' ) {
$ad_length = $ad_length * 365;
}
$onetime_ad_duration = date_i18n( 'm/d/Y H:i:s', strtotime( '+' . $ad_length . ' days' ) );
update_post_meta( $post_id, 'gc_listing_duration', $onetime_ad_duration );
} if ( $q->package_type === 'pkg_recurring' && $pkg_type === 'pkg_recurring' ) {
//Calculate first billing period
$first_billing_cycle = $q->first_billing_per;
if ( $q->first_billing_cycle == 'M' ) {
$first_billing_cycle = $q->first_billing_per * 30;
} elseif ( $q->first_billing_cycle == 'Y' ) {
$first_billing_cycle = $q->first_billing_per * 365;
} else {
$first_billing_cycle = $q->first_billing_per;
}
//Calculate second billing period
$second_billing_cycle = $q->second_billing_per;
if ( $q->second_billing_cycle == 'M' ) {
$second_billing_cycle = $q->second_billing_per * 30;
} elseif ( $q->second_billing_cycle == 'Y' ) {
$second_billing_cycle = $q->second_billing_per * 365;
} else {
$second_billing_cycle = $q->second_billing_per;
}
$ad_length = $second_billing_cycle + $first_billing_cycle;
$recurring_ad_duration = date_i18n( 'm/d/Y H:i:s', strtotime( '+' . $ad_length . ' days' ) );
update_post_meta( $post_id, 'gc_listing_duration', $recurring_ad_duration );
} elseif ( $q->package_type == 'pkg_free' && $pkg_type == '' ) {
$admin_ad_duration = date_i18n( 'm/d/Y H:i:s', strtotime( '+' . $ad_length . ' days' ) );
//update_post_meta($post_id, 'gc_listing_duration', $admin_ad_duration);
}
}
}
// change ad to draft if it's expired
function gc_has_ad_expired( $post_id ) {
global $wpdb;
$expire_date = get_post_meta( $post_id, 'gc_listing_duration', true );
$expired_listing = get_option( 'gc_expired_listing' );
// debugging variables
// echo date_i18n('m/d/Y H:i:s') . ' <-- current date/time GMT
';
// echo $expire_date . ' <-- expires date/time
';
// if current date is past the expires date, change post status to draft
if ( $expire_date ) {
if ( strtotime( date( 'Y-m-d H:i:s' ) ) > (strtotime( $expire_date )) ) :
$my_post = array();
$my_post['ID'] = $post_id;
$my_post['post_status'] = 'draft';
wp_update_post( $my_post );
return true;
elseif ( strtotime( date( 'Y-m-d H:i:s' ) ) < (strtotime( $expire_date )) ):
if ( is_array( $expired_listing ) ) {
if ( in_array( $post_id, $expired_listing ) ) {
$expired_arr = array_diff( $expired_listing, array( $post_id ) );
update_option( 'gc_expired_listing', $expired_arr );
}
}
endif;
}
}
//Expire listing when payment canceled or denied
function gc_listing_expire( $post_id ) {
$my_post = array();
$my_post['ID'] = $post_id;
$my_post['post_status'] = 'draft';
wp_update_post( $my_post );
}
// shows how much time is left before the ad expires
function gc_timeleft( $theTime ) {
$now = strtotime( "now" );
$timeLeft = $theTime - $now;
$days_label = __( 'days', THEME_SLUG );
$day_label = __( 'day', THEME_SLUG );
$hours_label = __( 'hours', THEME_SLUG );
$hour_label = __( 'hour', THEME_SLUG );
$mins_label = __( 'mins', THEME_SLUG );
$min_label = __( 'min', THEME_SLUG );
$secs_label = __( 'secs', THEME_SLUG );
$r_label = __( 'remaining', THEME_SLUG );
$expired_label = __( 'This listing has expired', THEME_SLUG );
if ( $timeLeft > 0 ) {
$days = floor( $timeLeft / 60 / 60 / 24 );
$hours = $timeLeft / 60 / 60 % 24;
$mins = $timeLeft / 60 % 60;
$secs = $timeLeft % 60;
if ( $days == 01 ) {
$d_label = $day_label;
} else {
$d_label = $days_label;
}
if ( $hours == 01 ) {
$h_label = $hour_label;
} else {
$h_label = $hours_label;
}
if ( $mins == 01 ) {
$m_label = $min_label;
} else {
$m_label = $mins_label;
}
if ( $days ) {
$theText = $days . " " . $d_label;
if ( $hours ) {
$theText .= ", " . $hours . " " . $h_label . " left";
}
} elseif ( $hours ) {
$theText = $hours . " " . $h_label;
if ( $mins ) {
$theText .= ", " . $mins . " " . $m_label . " left";
}
} elseif ( $mins ) {
$theText = $mins . " " . $m_label;
if ( $secs ) {
$theText .= ", " . $secs . " " . $secs_label . " left";
}
} elseif ( $secs ) {
$theText = $secs . " " . $secs_label . " left";
}
} else {
$theText = $expired_label;
}
return $theText;
}
function gc_renew_listing( $listing_id, $pkg_type = '' ) {
if ( empty( $pkg_type ) ) {
$renewal_period = gc_renewal_periond();
} else {
$renewal_period = gc_renewal_time( $pkg_type );
}
if ( $renewal_period > 0 ) {
// set the ad listing expiration date
$ad_expire_date = date_i18n( 'm/d/Y H:i:s', strtotime( '+' . $renewal_period . ' days' ) );
$listing_type = get_post_meta( $listing_id, 'geocraft_listing_type', true );
if ( $listing_type == 'pro' ) {
$post_status = geocraft_get_option( 'paid_post_mode' );
if ( strtolower( $post_status ) == 'pending' ):
$post_status = 'pending';
elseif ( strtolower( $post_status ) == 'publish' ):
$post_status = 'publish';
elseif ( strtolower( $post_status ) == '' ):
$post_status = 'publish';
endif;
}else {
$status = strtolower( geocraft_get_option( 'free_post_mode' ) );
if ( $status == 'pending' ):
$post_status = 'pending';
elseif ( $status == 'publish' ):
$post_status = 'publish';
else:
$post_status = 'publish';
endif;
}
$expired_listing = get_option( 'gc_expired_listing' );
//now update the expiration date on the ad
update_post_meta( $listing_id, 'gc_listing_duration', $ad_expire_date );
wp_update_post( array( 'ID' => $listing_id, 'post_date' => date( 'Y-m-d H:i:s' ), 'edit_date' => true, 'post_status' => $post_status ) );
if ( in_array( $listing_id, $expired_listing ) ) {
$expired_arr = array_diff( $expired_listing, array( $listing_id ) );
update_option( 'gc_expired_listing', $expired_arr );
}
return true;
}
//attempt to relist a paid ad
else {
return false;
}
}
function gc_multi_search( $sfrom, $location, $limit = null ) {
global $wpdb;
if ( !empty( $sfrom ) || !empty( $location ) )
$n = '%';
$post_type = POST_TYPE;
$post_status = 'publish';
$meta_key = "geo_address";
$query = '';
if ( $sfrom !== '' && $location == '' ) {
$query = "SELECT $wpdb->posts.*
FROM
$wpdb->posts
INNER JOIN $wpdb->term_relationships
ON $wpdb->term_relationships.object_id = $wpdb->posts.ID
INNER JOIN $wpdb->term_taxonomy
ON $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
INNER JOIN $wpdb->terms
ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id
WHERE post_status = '$post_status' AND post_type = '$post_type' AND
(post_title LIKE '{$n}$sfrom{$n}' OR post_content LIKE '{$n}$sfrom{$n}' OR $wpdb->terms.name = '$sfrom') GROUP BY $wpdb->posts.ID {$limit}";
} elseif ( $sfrom == '' && $location !== '' ) {
$query = "SELECT *
FROM
$wpdb->posts
INNER JOIN $wpdb->postmeta
ON $wpdb->posts.ID = $wpdb->postmeta.post_id
WHERE post_status = '$post_status' AND post_type = '$post_type' AND
(meta_key = '$meta_key' AND meta_value like '{$n}$location{$n}')
GROUP BY $wpdb->posts.ID {$limit}";
} elseif ( $sfrom !== '' && $location !== '' ) {
$query = "SELECT $wpdb->posts.*
FROM
$wpdb->posts
INNER JOIN $wpdb->postmeta
ON $wpdb->posts.ID = $wpdb->postmeta.post_id
INNER JOIN $wpdb->term_relationships
ON $wpdb->term_relationships.object_id = $wpdb->posts.ID
INNER JOIN $wpdb->term_taxonomy
ON $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
INNER JOIN $wpdb->terms
ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id
WHERE post_status = '$post_status' AND post_type = '$post_type' AND
(post_title like '{$n}$sfrom{$n}' OR post_content like '{$n}$sfrom{$n}' OR $wpdb->terms.name = '$sfrom') AND
(meta_key = '$meta_key' AND meta_value like '{$n}$location{$n}')
GROUP BY $wpdb->posts.ID {$limit}";
}
$results = array();
$results['result'] = $wpdb->get_results( $query );
$results['query'] = $wpdb->query( $query );
return $results;
}
function gc_insert_spage() {
global $wpdb;
$search = GC_SEARCH;
$sql = "SELECT * from $wpdb->posts WHERE post_name = '$search'";
$query = $wpdb->get_row( $sql );
if ( !$query ) {
$my_page = array(
'ID' => false,
'post_type' => 'page',
'post_name' => GC_SEARCH,
'ping_status' => 'closed',
'post_status' => 'publish',
'comment_status' => 'closed',
//'post_content' => '[pay-status]',
'post_title' => __( 'Search', THEME_SLUG ),
'post_excerpt' => ''
);
$pages = wp_insert_post( $my_page );
if ( $pages ) {
update_post_meta( $pages, '_wp_page_template', 'template_search.php' );
}
}
}
add_action( 'init', 'gc_insert_spage' );
function gc_upgrade_listing( $uid, $total_amount, $feature_home, $feature_cat ) {
global $wpdb;
$post_id = $uid;
//Updating listing type
if ( $total_amount > 0 ) {
update_post_meta( $post_id, 'geocraft_listing_type', 'pro' );
/**
* Updating listing meta
*/
$listing_meta = array(
'geocraft_f_checkbox1' => esc_attr( $feature_home ),
'geocraft_f_checkbox2' => esc_attr( $feature_cat )
);
if ( $listing_meta ) {
foreach ( $listing_meta as $key => $meta ):
if ( !empty( $meta ) ) {
update_post_meta( $post_id, $key, $meta );
}
endforeach;
}
} else {
update_post_meta( $post_id, 'geocraft_listing_type', 'free' );
}
}
//Set transaction feids after receving payments
function gc_set_transaction( $request ) {
// Globliazation tables variables
global $wpdb;
$transection_table_name = GC_TRANS_TBL;
$txn_type = '';
if ( $request['txn_type'] == 'subscr_payment' ) {
$txn_type = 'Recurring';
} else {
$txn_type = 'One Time';
}
// Select statement
$sql = "SELECT * FROM $transection_table_name WHERE paypal_transection_id='{$request['txn_id']}'";
$sql_stat = $wpdb->get_row( $sql );
//checking transaction empty or not
if ( empty( $sql_stat ) ):
$current_user = wp_get_current_user();
$wpdb->insert( $transection_table_name, array(
"user_id" => $request['user_id'],
"post_id" => $request['post_id'],
"post_title" => $request['item_name'],
"status" => 1,
"payment_method" => 'Paypal',
"payable_amt" => $request['mc_gross'],
"payment_date" => current_time( 'mysql' ),
"txn_type" => $txn_type,
"paypal_transection_id" => $request['txn_id'],
"user_name" => $request['user_name'],
"pay_email" => $request['payer_email'],
"billing_name" => $request['user_name'],
"billing_add" => $request['residence_country']
) );
endif;
}
// Set listing to their respective status
function gc_set_listing( $post_id, $feature_home, $feature_cat ) {
//set post pending to publish
if ( ($post_id != '' ) ):
global $wpdb;
$post_status = geocraft_get_option( 'paid_post_mode' );
if ( strtolower( $post_status ) == 'pending' ):
$post_status = 'pending';
elseif ( strtolower( $post_status ) == 'publish' ):
$post_status = 'publish';
elseif ( strtolower( $post_status ) == '' ):
$post_status = 'publish';
endif;
$my_post = array(
'ID' => $post_id,
'post_status' => $post_status
);
wp_update_post( $my_post );
/**
* Updating listing meta
*/
$listing_meta = array(
'geocraft_f_checkbox1' => esc_attr( $feature_home ),
'geocraft_f_checkbox2' => esc_attr( $feature_cat )
);
if ( $listing_meta ) {
foreach ( $listing_meta as $key => $meta ):
if ( !empty( $meta ) ) {
update_post_meta( $post_id, $key, $meta );
}
endforeach;
}
endif;
}
function gc_comments_popup_link( $post_id = null, $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
global $wpcommentspopupfile, $wpcommentsjavascript;
$id = $post_id;
if ( false === $zero )
$zero = __( 'No Reviews' );
if ( false === $one )
$one = __( '1 Review' );
if ( false === $more )
$more = __( '% Reviews' );
if ( false === $none )
$none = __( 'No Review' );
$number = get_comments_number( $id );
if ( 0 == $number && !comments_open() && !pings_open() ) {
echo '' . $none . '';
return;
}
if ( post_password_required() ) {
echo __( 'Enter your password to view Reviews.' );
return;
}
if ( $number > 1 )
$output = str_replace( '%', number_format_i18n( $number ), ( false === $more ) ? __( '% Reviews' ) : $more );
elseif ( $number == 0 )
$output = ( false === $zero ) ? __( 'No Reviews' ) : $zero;
else // must be one
$output = ( false === $one ) ? __( '1 Review' ) : $one;
echo $output;
}
function gc_is_featured( $post_id ) {
$feature['feature_home'] = get_post_meta( $post_id, 'geocraft_f_checkbox1', true );
$feature['feature_cat'] = get_post_meta( $post_id, 'geocraft_f_checkbox2', true );
return (array) $feature;
}
/**
* Return feature amount
* @global type $wpdb
* @global type $price_table_name
* @param type $p_type
*/
function get_featured_cost( $p_type ) {
global $wpdb;
$price_table_name = GC_PRICE_TBL;
if ( $p_type == 'one' ) {
$package_type = 'pkg_one_time';
} elseif ( $p_type == 'recurring' ) {
$package_type = 'pkg_recurring';
}
$sql = "SELECT feature_amount,feature_cat_amount FROM $price_table_name WHERE is_featured = 1 AND package_type='{$package_type}'";
return $wpdb->get_results( $sql, ARRAY_A );
}
/**
* Returns the paid package type
* @global type $wpdb
* @global type $transection_table_name
* @param type $post_id
*/
function gc_package_type( $post_id ) {
global $wpdb;
$transection_table_name = GC_TRANS_TBL;
$current_user = wp_get_current_user();
$sql = "SELECT txn_type FROM $transection_table_name WHERE user_id={$current_user->ID} AND post_id={$post_id}";
$package_type = $wpdb->get_row( $sql, ARRAY_A );
return $package_type;
}
/**
* Returns all listings
* @global type $wpdb
* @param type $limit
* @return type array
*/
function gc_get_query_all_listing( $limit = null ) {
global $wpdb;
if ( $limit !== null ) {
$sql = "SELECT * FROM $wpdb->posts ";
$sql .="WHERE $wpdb->posts.post_status = 'publish' ";
$sql .="AND $wpdb->posts.post_type = 'listing' ";
$sql .="ORDER BY $wpdb->posts.post_date DESC $limit";
$query['result'] = $wpdb->get_results( $sql );
}
$sql1 = "SELECT COUNT(*) FROM $wpdb->posts ";
$sql1 .="WHERE $wpdb->posts.post_status = 'publish' ";
$sql1 .="AND $wpdb->posts.post_type = 'listing' ";
$sql1 .="ORDER BY $wpdb->posts.post_date DESC";
$query['query'] = $wpdb->get_var( $sql1 );
return $query;
}
/**
* Returns paid listings
* @global type $wpdb
* @param type $limit
* @return type array
*/
function gc_get_query_paid_listing( $limit = null ) {
global $wpdb;
if ( $limit !== null ) {
$sql = "SELECT * FROM $wpdb->posts ";
$sql .="INNER JOIN $wpdb->postmeta ";
$sql .="ON $wpdb->posts.ID = $wpdb->postmeta.post_id ";
$sql .="WHERE $wpdb->postmeta.meta_key = 'geocraft_listing_type' ";
$sql .="AND $wpdb->postmeta.meta_value = 'pro' ";
$sql .="AND $wpdb->posts.post_status = 'publish' ";
$sql .="AND $wpdb->posts.post_type = 'listing' ";
$sql .="ORDER BY $wpdb->posts.post_date DESC $limit";
$query['result'] = $wpdb->get_results( $sql );
}
$sql1 = "SELECT COUNT(*) FROM $wpdb->posts ";
$sql1 .="INNER JOIN $wpdb->postmeta ";
$sql1 .="ON $wpdb->posts.ID = $wpdb->postmeta.post_id ";
$sql1 .="WHERE $wpdb->postmeta.meta_key = 'geocraft_listing_type' ";
$sql1 .="AND $wpdb->postmeta.meta_value = 'pro' ";
$sql1 .="AND $wpdb->posts.post_status = 'publish' ";
$sql1 .="AND $wpdb->posts.post_type = 'listing' ";
$sql1 .="ORDER BY $wpdb->posts.post_date DESC $limit";
$query['query'] = $wpdb->get_var( $sql1 );
return $query;
}
/**
* Returns free listings
* @global type $wpdb
* @param type $limit
* @return type array
*/
function gc_get_query_free_listing( $limit = null ) {
global $wpdb;
if ( $limit !== null ) {
$sql = "SELECT * FROM $wpdb->posts ";
$sql .="INNER JOIN $wpdb->postmeta ";
$sql .="ON $wpdb->posts.ID = $wpdb->postmeta.post_id ";
$sql .="WHERE $wpdb->postmeta.meta_key = 'geocraft_listing_type' ";
$sql .="AND $wpdb->postmeta.meta_value = 'free' ";
$sql .="AND $wpdb->posts.post_status = 'publish' ";
$sql .="AND $wpdb->posts.post_type = 'listing' ";
$sql .="ORDER BY $wpdb->posts.post_date DESC $limit";
$query['result'] = $wpdb->get_results( $sql );
}
$sql1 = "SELECT COUNT(*) FROM $wpdb->posts ";
$sql1 .="INNER JOIN $wpdb->postmeta ";
$sql1 .="ON $wpdb->posts.ID = $wpdb->postmeta.post_id ";
$sql1 .="WHERE $wpdb->postmeta.meta_key = 'geocraft_listing_type' ";
$sql1 .="AND $wpdb->postmeta.meta_value = 'free' ";
$sql1 .="AND $wpdb->posts.post_status = 'publish' ";
$sql1 .="AND $wpdb->posts.post_type = 'listing' ";
$sql1 .="ORDER BY $wpdb->posts.post_date DESC $limit";
$query['query'] = $wpdb->get_var( $sql1 );
return $query;
}
/**
* Returns query limit and pagination
* @global type $wp_query
* @param type $max_pages_size
* @param type $args
* @return array || limit || pagination
*/
function gc_custom_pagination( $max_pages_size, $args = array() ) {
$default = array(
'paged_name' => 'pages',
'per_page' => get_option( 'posts_per_page' ),
'page' => '',
'url_entity' => '',
'limit' => '',
'sub_page' => ''
);
$itemsPerPage = 0;
$page = '';
$paged = '';
$url_entity = '';
$sub_page = '';
//Set max page size
if ( $max_pages_size !== '' ) {
$max_pages = $max_pages_size;
} else {
global $wp_query;
$max_pages = $wp_query->max_num_pages;
}
//Set per page size
if ( isset( $args['per_page'] ) && $args['per_page'] !== '' ) {
$itemsPerPage = $args['per_page'];
} else {
$itemsPerPage = $default['per_page'];
}
//Set current page name
if ( isset( $args['page'] ) && $args['page'] !== '' ) {
$page = $args['page'];
} else {
$page = $default['page'];
}
//Set paged name
if ( isset( $args['paged_name'] ) && $args['paged_name'] !== '' ) {
$paged = $args['paged_name'];
} else {
$paged = $default['paged_name'];
}
//==========================================================================
if ( isset( $args['url_entity'] ) && $args['url_entity'] !== '' ) {
$url_entity = '&';
$url_entity .= $args['url_entity'];
}
//==========================================================================
if ( isset( $_GET[$paged] ) ) { // Get pn from URL vars if it is present
$pn = preg_replace( '#[^0-9]#i', '', $_GET[$paged] ); // filter everything but numbers for security(new)
} else { // If the pn URL variable is not present force it to be value of page number 1
$pn = 1;
}
$lastPage = ceil( $max_pages / $itemsPerPage );
//==========================================================================
if ( $pn < 1 ) { // If it is less than 1
$pn = 1; // force if to be 1
} else if ( $pn > $lastPage ) { // if it is greater than $lastpage
$pn = $lastPage; // force it to be $lastpage's value
}
$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
//======================================
$subn1 = null;
$subn2 = null;
$addn1 = null;
$addn2 = null;
//==========================================================================
if ( isset( $args['sub_page'] ) && $args['sub_page'] !== '' ) {
$url_entity = '&';
$sub_page = $args['sub_page'];
$url_entity .= $sub_page;
$url_entity .= '=';
//======================================
if ( isset( $_GET[$sub_page] ) ) { // Get pn from URL vars if it is present
$sn = preg_replace( '#[^0-9]#i', '', $_GET[$sub_page] ); // filter everything but numbers for security(new)
} else { // If the pn URL variable is not present force it to be value of page number 1
$sn = 1;
}
//=====================================
if ( $sn < 1 ) { // If it is less than 1
$sn = 1; // force if to be 1
}
//=====================================
$subn1 = $sn - 1;
$subn2 = $sn - 2;
$addn1 = $sn + 1;
$addn2 = $sn + 2;
}
//==============================================================================
if ( $pn == 1 ) {
$centerPages .= '- ' . $pn . '
';
$centerPages .= '- ' . $add1 . '
';
} else if ( $pn == $lastPage ) {
$centerPages .= '- ' . $sub1 . '
';
$centerPages .= '- ' . $pn . '
';
} else if ( $pn > 2 && $pn < ($lastPage - 1) ) {
$centerPages .= '- ' . $sub2 . '
';
$centerPages .= '- ' . $sub1 . '
';
$centerPages .= '- ' . $pn . '
';
$centerPages .= '- ' . $add1 . '
';
$centerPages .= '- ' . $add2 . '
';
} else if ( $pn > 1 && $pn < $lastPage ) {
$centerPages .= '- ' . $sub1 . '
';
$centerPages .= '- ' . $pn . '
';
$centerPages .= '- ' . $add1 . '
';
}
$range = 2;
$showitems = ($range * 2) + 1;
$val_page = $paged;
$paged = $pn;
$pages = $lastPage;
$paid_size = isset( $args['paid_size'] ) ? $args['paid_size'] : '';
$filter_by_paid = geocraft_get_option( 'filter_by_paid' );
//echo $paid_size;
$a = 0;
if ( 1 != $pages ) {
$paginationDisplay = "";
if ( $paged > 2 && $paged > $range + 1 && $showitems < $pages )
$paginationDisplay .= "- «
";
//if ($paged > 1 && $showitems < $pages){
//$paginationDisplay .= "- ‹
";
//}
for ( $i = 1; $i <= $pages; $i++ ) {
if ( $i == $paid_size || $i > $paid_size ) {
if ( $filter_by_paid == 'on' ) {
$a = $a + 1;
} else {
$a = '';
}
}
if ( 1 != $pages && (!($i >= $paged + $range + 1 || $i <= $paged - $range - 1) || $pages <= $showitems ) ) {
$paginationDisplay .= ($paged == $i) ? "- " . $i . "
" : "- " . $i . "
";
}
}
//if ($paged < $pages && $showitems < $pages){
//$paginationDisplay .= "- ›
";
//}
if ( $paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages )
$paginationDisplay .= "- »
";
$paginationDisplay .= "
\n";
}
if ( isset( $_GET[$val_page] ) ) {
$current_page = $_GET[$val_page];
} else {
$current_page = 1;
}
$max = isset( $_GET[$sub_page] ) ? $_GET[$sub_page] : '';
$limit = 'LIMIT ' . ($pn - 1) * $itemsPerPage . ',' . $itemsPerPage;
if ( isset( $args['limit'] ) && isset( $args['limit']['limit'] ) ) {
$offsetLimit = $args['limit']['limit'];
$limit = 'LIMIT 0,' . $offsetLimit;
} elseif ( isset( $args['limit'] ) && isset( $args['limit'][0] ) ) {
$a = $args['limit'][1];
$paid_pages = $args['limit'][2];
if ( $current_page == $paid_pages + 1 ) {
$limit = 'LIMIT ' . max( $max + $a - 1, 0 ) . ',' . $itemsPerPage;
}
if ( $current_page > $paid_pages + 1 ) {
$val = (max( $max - 1, 0 ) * $itemsPerPage);
$offset = $val + $a;
$limit = 'LIMIT ' . $offset . ',' . $itemsPerPage;
}
//$limit = 'LIMIT ' . max($max + $a, 0) * $itemsPerPage . ',' . $itemsPerPage;
}
$result = array( 'limit' => $limit, 'pagination' => $paginationDisplay, 'current_page' => $current_page );
return $result;
}
function gc_get_all_listings( $page_name = '' ) {
$all_listings_size = gc_get_query_all_listing();
$pagination = gc_custom_pagination( $all_listings_size['query'], array( 'page' => $page_name ) );
$all_listings = gc_get_query_all_listing( $pagination['limit'] );
return array( 'results' => $all_listings['result'], 'pagination' => $pagination['pagination'] );
}
function gc_get_listings( $page_name = '' ) {
if ( $page_name !== '' ) {
$page_name = $page_name;
} else {
$page_name = '';
}
$paid_max_size = gc_get_query_paid_listing();
$free_max_size = gc_get_query_free_listing();
//===========================================
$max_size = $paid_max_size['query'] + $free_max_size['query'];
//===========================================
$pagination = gc_custom_pagination( $max_size, array( 'page' => $page_name ) );
//===========================================
$paid_listings = gc_get_query_paid_listing( $pagination['limit'] );
//===========================================
$current_page = $pagination['current_page'];
//===========================================
$max_size1 = ceil( $paid_max_size['query'] / get_option( 'posts_per_page' ) );
//echo $free_max_size['query'];
$listings = $paid_listings['result'];
//===========================================
$per_page = get_option( 'posts_per_page' );
$url_entiry = 'sub';
$paid_count = ceil( $paid_max_size['query'] / $per_page );
$pagination = gc_custom_pagination( $max_size, array( 'page' => $page_name, 'sub_page' => $url_entiry, 'paid_size' => intval( $paid_count ) + 1 ) );
$flag = false;
//session_destroy();
if ( !$_SESSION['limit'] ) {
session_start();
}
//===========================================
if ( $current_page == $max_size1 ) {
$_SESSION['flag'] = true;
$a = count( $paid_listings['result'] );
$b = $per_page;
$limit = $b - $a;
if ( $limit >= 1 ) {
$_SESSION['limit'] = $limit;
} else {
$_SESSION['limit'] = 0;
}
$pagination = gc_custom_pagination( $max_size, array( 'page' => $page_name, 'sub_page' => $url_entiry, 'paid_size' => intval( $paid_count ) + 1, 'limit' => array( 'limit' => $_SESSION['limit'] ) ) );
$free_listings = gc_get_query_free_listing( $pagination['limit'] );
//if ($per_page % 2 !== 0 && $per_page % 1 !== 0) {
$listings = array_merge( $paid_listings['result'], $free_listings['result'] );
//}
}
$flag = $_SESSION['flag'];
//===========================================
$paid_num = count( $paid_listings['result'] );
if ( $flag && $paid_num < 1 ) {
$pagination = gc_custom_pagination( $max_size, array( 'page' => $page_name, 'sub_page' => $url_entiry, 'paid_size' => intval( $paid_count ) + 1, 'limit' => array( true, $_SESSION['limit'], $paid_count ) ) );
$free_listings = gc_get_query_free_listing( $pagination['limit'] );
$listings = $free_listings['result'];
}
if ( count( $paid_listings['result'] ) > 1 ) {
//if (isset($_SESSION['flag']))
// unset($_SESSION['flag']);
}
$filter_by_paid = geocraft_get_option( 'filter_by_paid' );
if ( $filter_by_paid == 'on' && $filter_by_paid !== '' ) {
return array( 'results' => $listings, 'pagination' => $pagination['pagination'], 'current' => $current_page );
} else {
return gc_get_all_listings( $page_name );
}
}
get_var( "select rating_rating from $rating_table_name where comment_id=\"$comment->comment_ID\"" ); echo geocraft_display_rating_star( $post_rating ); ?>