Ejemplo n.º 1
0
 protected function _dispatch($default = null)
 {
     $ad = $this->get_ad();
     if (is_null($ad)) {
         $message = __("The specified Ad doesn't exist or you reached this page directly, without specifying the Ad ID.", 'AWPCP');
         return $this->render('content', awpcp_print_error($message));
     } else {
         if (!$ad->is_about_to_expire() && !$ad->has_expired()) {
             $message = __("The specified Ad doesn't need to be renewed.", 'AWPCP');
             return $this->render('content', awpcp_print_error($message));
         } else {
             if (!$this->verify_renew_ad_hash($ad)) {
                 $message = __("There was an error trying to renew your Ad. The URL is not valid. Please contact the Administrator of this site for further assistance.", 'AWPCP');
                 return $this->render('content', awpcp_print_error($message));
             }
         }
     }
     $transaction = $this->get_transaction();
     if (!is_null($transaction) && $transaction->get('context') != $this->context) {
         $page_name = awpcp_get_page_name('renew-ad-page-name');
         $page_url = awpcp_get_renew_ad_url($ad->ad_id);
         $message = __('You are trying to post an Ad using a transaction created for a different purpose. Pelase go back to the <a href="%s">%s</a> page.<br>If you think this is an error please contact the administrator and provide the following transaction ID: %s', 'AWPCP');
         $message = sprintf($message, $page_url, $page_name, $transaction->id);
         return $this->render('content', awpcp_print_error($message));
     }
     $action = $this->get_current_action($default);
     if (!is_null($transaction) && $transaction->is_payment_completed()) {
         if (!$transaction->was_payment_successful()) {
             $message = __('You can\'t renew your Ad at this time because the payment associated with this transaction failed (see reasons below).', 'AWPCP');
             $message = awpcp_print_message($message);
             $message = $message . awpcp_payments_api()->render_transaction_errors($transaction);
             return $this->render('content', $message);
         }
         $forbidden = in_array($action, array('order', 'checkout'));
         if ($forbidden) {
             $action = 'payment-completed';
         }
     }
     if (!is_null($transaction) && $transaction->is_completed()) {
         $action = 'finish';
     }
     $implementation = $this->get_renew_ad_page_implementation($ad);
     if (is_null($implementation)) {
         $message = __("The Ad was posted under a Payment Term that no longer exists or is disabled. The Ad can't be renewed.", 'AWPCP');
         $content = '<p>' . $this->get_return_link($ad) . '</p>';
         return $this->render('content', awpcp_print_error($message) . $content);
     }
     switch ($action) {
         case 'order':
             return $implementation->order_step();
         case 'checkout':
             return $implementation->checkout_step();
         case 'payment-completed':
             return $implementation->payment_completed_step();
         case 'finish':
             return $implementation->finish_step();
         default:
             return $implementation->order_step();
     }
 }
Ejemplo n.º 2
0
 protected function _dispatch($default = null)
 {
     $is_admin_user = awpcp_current_user_is_admin();
     // only admin users are allowed to place Ads
     if (get_awpcp_option('onlyadmincanplaceads') && $is_admin_user != 1) {
         $message = __("You do not have permission to perform the function you are trying to perform. Access to this page has been denied", "AWPCP");
         return $this->render('content', awpcp_print_error($message));
     }
     // only registered users are allowed to place Ads
     if (get_awpcp_option('requireuserregistration') && !is_user_logged_in()) {
         return $this->login_step();
     }
     $transaction = $this->get_transaction();
     if (!is_null($transaction) && $transaction->get('context') != $this->context) {
         $page_name = awpcp_get_page_name('place-ad-page-name');
         $page_url = awpcp_get_page_url('place-ad-page-name');
         $message = __('You are trying to post an Ad using a transaction created for a different purpose. Pelase go back to the <a href="%s">%s</a> page.<br>If you think this is an error please contact the administrator and provide the following transaction ID: %s', 'AWPCP');
         $message = sprintf($message, $page_url, $page_name, $transaction->id);
         return $this->render('content', awpcp_print_error($message));
     }
     $action = $this->get_current_action($default);
     if (!is_null($transaction) && $transaction->is_payment_completed()) {
         if (!($transaction->was_payment_successful() || $transaction->payment_is_canceled())) {
             $message = __('You can\'t post an Ad at this time because the payment associated with this transaction failed (see reasons below).', 'AWPCP');
             $message = awpcp_print_message($message);
             $message = $message . awpcp_payments_api()->render_transaction_errors($transaction);
             return $this->render('content', $message);
         }
         $pay_first = get_awpcp_option('pay-before-place-ad');
         $forbidden = in_array($action, array('order', 'checkout'));
         if ($forbidden) {
             $action = 'payment-completed';
         }
     }
     if (!is_null($transaction) && $transaction->is_completed()) {
         $action = 'finish';
     }
     switch ($action) {
         case 'order':
             return $this->order_step();
         case 'checkout':
             return $this->checkout_step();
         case 'payment-completed':
             return $this->payment_completed_step();
         case 'details':
         case 'save-details':
             return $this->details_step();
             break;
         case 'upload-images':
             return $this->upload_images_step();
             break;
         case 'preview-ad':
             return $this->preview_step();
             break;
         case 'finish':
             return $this->finish_step();
             break;
         default:
             return $this->place_ad();
     }
 }
Ejemplo n.º 3
0
 /**
  * Shows a notice if any of the AWPCP pages shares its name with the
  * dynamic page View Categories.
  *
  * If a page share its name with the View Categories page, that page
  * will become unreachable.
  *
  * @since 3.0.2
  */
 public function check_duplicate_page_names()
 {
     global $wpdb;
     $view_categories_option = 'view-categories-page-name';
     $view_categories = sanitize_title(awpcp_get_page_name($view_categories_option));
     $view_categories_url = awpcp_get_view_categories_url();
     $duplicates = array();
     $awpcp_pages = array();
     $wp_pages = array();
     $posts = get_posts(array('post_type' => 'page', 'name' => $view_categories));
     foreach ($posts as $post) {
         if ($view_categories_url == get_permalink($post->ID)) {
             $duplicates[] = $post;
         }
     }
     $pages = empty($duplicates) ? array() : awpcp_get_plugin_pages_refs();
     foreach ($duplicates as $page) {
         if (isset($pages[$page->ID])) {
             $awpcp_pages[] = ucwords(awpcp()->settings->get_option_label($pages[$page->ID]->page));
         } else {
             $wp_pages[] = $page->post_title;
         }
     }
     if (!empty($awpcp_pages) || !empty($wp_pages)) {
         $view_categories_label = awpcp()->settings->get_option_label($view_categories_option);
         $view_categories_label = sprintf('<strong>%s</strong>', ucwords($view_categories_label));
     }
     if (!empty($awpcp_pages)) {
         $duplicated_pages = '<strong>' . join('</strong>, <strong>', $awpcp_pages) . '</strong>';
         $message = _n(count($awpcp_pages), '%1$s has the same name as the %2$s. That will cause %1$s to become unreachable. Please make sure you don\'t have duplicate page names.', '%1$s have the same name as the %2$s. That will cause %1$s to become unreachable. Please make sure you don\'t have duplicate page names.', 'AWPCP');
         $message = sprintf($message, $duplicated_pages, $view_categories_label);
         echo awpcp_print_error($message);
     }
     if (!empty($wp_pages)) {
         $duplicated_pages = '<strong>' . join('</strong>, <strong>', $wp_pages) . '</strong>';
         $message = _n(count($wp_pages), 'Page %1$s has the same name as the AWPCP %2$s. That will cause WordPress page %1$s to become unreachable. The %2$s is dynamic; you don\'t need to create a real WordPress page to show the list of cateogries, the plugin will generate it for you. If the WordPress page was created to show the default list of AWPCP categories, you can delete it and this error message will go away. Otherwise, please make sure you don\'t have duplicate page names.', 'Pages %1$s have the same name as the AWPCP %2$s. That will cause WordPress pages %1$s to become unreachable. The %2$s is dynamic; you don\'t need to create a real WordPress page to show the list of cateogries, the plugin will generate it for you. If the WordPress pages were created to show the default list of AWPCP categories, you can delete them and this error message will go away. Otherwise, please make sure you don\'t have duplicate page names.', 'AWPCP');
         $message = sprintf($message, $duplicated_pages, $view_categories_label);
         echo awpcp_print_error($message);
     }
 }