get_results($sql); return is_array($results) ? $results : array(); } function awpcp_get_ad_images_information($ad_id) { if ($ad_id <= 0) { return __('An unexpected error ocurred. No Ad was specified.', 'AWPCP'); } if (get_awpcp_option('imagesallowdisallow') != 1) { $images_allowed = 0; } else { $images_allowed = awpcp_get_ad_number_allowed_images($ad_id); } if ($images_allowed > 0) { $images_uploaded = get_total_imagesuploaded($ad_id); $images_left = max($images_allowed - $images_uploaded, 0); } else { $images_uploaded = 0; $images_left = 0; } return array($images_allowed, $images_uploaded, $images_left); } /** * Generic function to calculate an date relative to a given start date. * * @since 2.0.7 */ function awpcp_calculate_end_date($increment, $period, $start_date) { $periods = array('D' => 'DAY', 'W' => 'WEEK', 'M' => 'MONTH', 'Y' => 'YEAR'); if (in_array($period, array_keys($periods))) { $period = $periods[$period]; } // 0 means no expiration date, we understand that as ten years if ($increment == 0 && $period == 'DAY') { $increment = 3650; } else if ($increment == 0 && $period == 'WEEK') { $increment = 5200; } else if ($increment == 0 && $period == 'MONTH') { $increment = 1200; } else if ($increment == 0 && $period == 'YEAR') { $increment = 10; } return date('Y-m-d H:i:s', strtotime("+ $increment $period", $start_date)); } /** * If an Ad was passed, calculates Ad End Date from current End Date. * If no Ad was passed, calculates Ad End Date as if Ad would have * been posted at the current time. * * TODO: Use the new $ad->calculate_end_date() method. */ function awpcp_calculate_ad_end_date($duration, $interval='DAY', $ad=null) { $now = awpcp_datetime( 'timestamp' ); $end_date = is_null($ad) ? $ad->ad_enddate : 0; // if the Ad's end date is in the future, use that as starting point // for the new end date, else use current date. $start_date = $end_date > $now ? $end_date : $now; return awpcp_calculate_end_date($duration, $interval, $start_date); } /** * ... * * @param $id Ad ID. * @param $transaction Payment Transaction associated to the Ad being posted * * It must be possible to have more than one transaction associated to a single * Ad, for example, when an Ad has been posted AND renewed one or more times. * * TODO: this can be moved into the Ad class. We actually don't need a transaction, * because the payment_status is stored in the Ad object. We need, however, to update * the payment_status when the Ad is placed AND renewed. ~2012-09-19 */ function awpcp_calculate_ad_disabled_state($id=null, $transaction=null, $payment_status=null) { if ( is_null( $payment_status ) && ! is_null( $transaction ) ) { $payment_status = $transaction->payment_status; } $payment_is_pending = $payment_status == AWPCP_Payment_Transaction::PAYMENT_STATUS_PENDING; if ( awpcp_current_user_is_admin() ) { $disabled = 0; } else if ( get_awpcp_option( 'adapprove' ) == 1 ) { $disabled = 1; } else if ( $payment_is_pending && get_awpcp_option( 'enable-ads-pending-payment' ) == 1 ) { $disabled = 0; } else if ( $payment_is_pending ) { $disabled = 1; } else { $disabled = 0; } return $disabled; } /** * @since 3.0.2 */ function awpcp_ad_renewed_user_email( $ad ) { $mail = new AWPCP_Email; $mail->to[] = awpcp_format_email_address( $ad->ad_contact_email, $ad->ad_contact_name ); $mail->subject = sprintf( get_awpcp_option( 'ad-renewed-email-subject' ), $ad->get_title() ); $introduction = get_awpcp_option( 'ad-renewed-email-body' ); $template = AWPCP_DIR . '/frontend/templates/email-ad-renewed-success-user.tpl.php'; $mail->prepare( $template, compact( 'ad', 'introduction' ) ); return $mail; } /** * @since 3.0.2 */ function awpcp_ad_renewed_admin_email( $ad, $body ) { $mail = new AWPCP_Email; $mail->to[] = awpcp_admin_email_to(); $mail->subject = sprintf( __( 'The classifieds listing "%s" has been successfully renewed.', 'AWPCP' ), $ad->ad_title ); $template = AWPCP_DIR . '/frontend/templates/email-ad-renewed-success-admin.tpl.php'; $mail->prepare( $template, compact( 'body' ) ); return $mail; } /** * @since 2.1.2 */ function awpcp_send_ad_renewed_email($ad) { // send notification to the user $user_email = awpcp_ad_renewed_user_email( $ad ); $user_email->send(); // send notification to the admin $admin_email = awpcp_ad_renewed_admin_email( $ad, $user_email->body ); $admin_email->send(); } /** * @since 2.0.7 */ function awpcp_renew_ad_success_message($ad, $text=null, $send_email=true) { if (is_null($text)) { $text = __("The Ad has been successfully renewed. New expiration date is %s. ", 'AWPCP'); } $return = ''; if (is_admin()) { $return = sprintf('%2$s', awpcp_get_user_panel_url(), __('Return to Listings', 'AWPCP')); } if ($send_email) { awpcp_send_ad_renewed_email($ad); } return sprintf("%s %s", sprintf($text, $ad->get_end_date()), $return); } /** * Deletes an image * * @param $picid int The id of the image to delete. * @param $adid int The id of the Ad the image belongs to. * @param $force boolean True if image should be deleted even if curent * user is not admin. * @deprecated use awpcp_media_api()->delete() */ function deletepic( $picid, $adid, $adtermid, $adkey, $editemail, $force=false ) { _deprecated_function( __FUNCTION__, '3.0.2', 'awpcp_media_api()->delete()' ); } function deletead($adid, $adkey, $editemail, $force=false, &$errors=array()) { $output = ''; $awpcppage = get_currentpagename(); $awpcppagename = sanitize_title($awpcppage, $post_ID=''); $quers = setup_url_structure($awpcppagename); $isadmin = checkifisadmin() || $force; if (get_awpcp_option('onlyadmincanplaceads') && ($isadmin != 1)) { $message = __("You do not have permission to perform the function you are trying to perform. Access to this page has been denied","AWPCP"); $errors[] = $message; } else { global $wpdb, $nameofsite; $tbl_ads = $wpdb->prefix . "awpcp_ads"; $tbl_ad_photos = $wpdb->prefix . "awpcp_adphotos"; $savedemail=get_adposteremail($adid); if ( $isadmin == 1 || strcasecmp( $editemail, $savedemail ) == 0 ) { $ad = AWPCP_Ad::find_by_id($adid); if ( $ad && $ad->delete() ) { if (($isadmin == 1) && is_admin()) { $message=__("The Ad has been deleted","AWPCP"); return $message; } else { $message=__("Your Ad details and any photos you have uploaded have been deleted from the system","AWPCP"); $errors[] = $message; } } else if ( $ad === null ) { $errors[] = __( "The specified Ad doesn't exists.", 'AWPCP' ); } else { $errors[] = __( "There was an error trying to delete the Ad. The Ad was not deleted.", 'AWPCP' ); } } else { $message=__("Problem encountered. Cannot complete request","AWPCP"); $errors[] = $message; } } $output .= "
"; $output .= $message; $output .= "
"; $output .= ""; $showcategories.=__("There are currently no ads in the system","AWPCP"); $showcategories.="
"; $pager1=''; $pager2=''; } else { $awpcp_image_display_list=array(); if ($adorcat == 'cat') { $tpname = get_permalink($awpcp_browsecats_pageid); } elseif ($adorcat == 'search') { $tpname = get_permalink($searchadspageid); } elseif ( preg_match( '/^custom:/', $adorcat ) ) { $tpname = str_replace( 'custom:', '', $adorcat ); } else { $tpname = get_permalink($browseadspageid); } $results = get_awpcp_option( 'adresultsperpage', 10 ); $results = absint( awpcp_request_param( 'results', $results ) ); $offset = absint( awpcp_request_param( 'offset', 0 ) ); if ( $results === 0 ) { $results = 10; } $args = array( 'order' => AWPCP_Ad::get_order_conditions( $grouporderby ), 'offset' => $offset, 'limit' => $results, ); $ads = AWPCP_Ad::get_enabled_ads( $args, array( $where ) ); // get_where_conditions() is called from get_enabled_ads(), we need the // WHERE conditions here to pass them to create_pager() $where = AWPCP_Ad::get_where_conditions( array( $where ) ); if (!isset($hidepager) || empty($hidepager) ) { //Unset the page and action here...these do the wrong thing on display ad unset($_GET['page_id']); unset($_POST['page_id']); //unset($params['page_id']); $pager1=create_pager($from, join( ' AND ', $where ),$offset,$results,$tpname); $pager2=create_pager($from, join( ' AND ', $where ),$offset,$results,$tpname); } else { $pager1=''; $pager2=''; } $items = array(); foreach ($ads as $ad) { $layout = get_awpcp_option('displayadlayoutcode'); if (empty($layout)) { $layout = awpcp()->settings->get_option_default_value('displayadlayoutcode'); } $layout = awpcp_do_placeholders( $ad, $layout, 'listings' ); if (function_exists('awpcp_featured_ads')) { $layout = awpcp_featured_ad_class($ad->ad_id, $layout); } $items[] = $layout; } $opentable = ""; $closetable = ""; if (empty($ads)) { $showcategories=""; $showcategories.=__("There were no ads found","AWPCP"); $showcategories.="
"; $pager1=''; $pager2=''; } else { $showcategories = smart_table($items, intval($results/$results), $opentable, $closetable); } } $show_category_id = absint( awpcp_request_param( 'category_id' ) ); if (!isset($url_browsecatselect) || empty($url_browsecatselect)) { $url_browsecatselect = get_permalink($awpcp_browsecats_pageid); } if ($ads_exist) { $category_id = (int) awpcp_request_param('category_id', -1); $category_id = $category_id === -1 ? (int) get_query_var('cid') : $category_id; $output .= ""; $output .= ""; $output .= __("Powered by ","AWPCP"); $output .= "Another Wordpress Classifieds Plugin
"; } elseif (field_exists($field='removepoweredbysign') && (get_awpcp_option('removepoweredbysign'))) { // ... } else { // $output .= ""; // $output .= __("Powered by ","AWPCP"); // $output .= "Another Wordpress Classifieds Plugin
"; } } $output .= "