예제 #1
0
파일: ad.php 프로젝트: Wildboard/WbWebApp
 public function action_confirm_post()
 {
     $advert_id = $this->request->param('id');
     $advert = new Model_Ad($advert_id);
     if ($advert->loaded()) {
         if (core::config('general.moderation') == Model_Ad::EMAIL_CONFIRMATION) {
             $advert->status = 1;
             // status active
             $advert->published = Date::unix2mysql(time());
             try {
                 $advert->save();
                 //subscription is on
                 $data = array('title' => $title = $advert->title, 'cat' => $cat = $advert->category, 'loc' => $loc = $advert->location);
                 Model_Subscribe::find_subscribers($data, floatval(str_replace(',', '.', $advert->price)), $advert->seotitle, Auth::instance()->get_user()->email);
                 // if subscription is on
                 Alert::set(Alert::INFO, __('Your advertisement is successfully activated! Thank you!'));
                 $this->request->redirect(Route::url('ad', array('category' => $advert->id_category, 'seotitle' => $advert->seotitle)));
             } catch (Exception $e) {
                 throw new HTTP_Exception_500($e->getMessage());
             }
         }
         if (core::config('general.moderation') == Model_Ad::EMAIL_MODERATION) {
             $advert->status = 0;
             // status active
             try {
                 $advert->save();
                 Alert::set(Alert::INFO, __('Advertisement is received, but first administrator needs to validate. Thank you for being patient!'));
                 $this->request->redirect(Route::url('ad', array('category' => $advert->id_category, 'seotitle' => $advert->seotitle)));
             } catch (Exception $e) {
                 throw new HTTP_Exception_500($e->getMessage());
             }
         }
     }
 }
예제 #2
0
파일: ad.php 프로젝트: Wildboard/WbWebApp
 /**
  * Mark advertisement as active : STATUS = 1
  */
 public function action_activate()
 {
     // First generate QR!
     $id = $this->request->param('id');
     $param_current_url = $this->request->param('current_url');
     $format_id = explode('_', $id);
     foreach ($format_id as $id) {
         if (isset($id) and $id !== '') {
             $active_ad = new Model_Ad($id);
             if ($active_ad->loaded()) {
                 if ($active_ad->status != 1) {
                     $active_ad->published = Date::unix2mysql(time());
                     $active_ad->status = Model_Ad::STATUS_PUBLISHED;
                     try {
                         $active_ad->save();
                         //subscription is on
                         $data = array('title' => $title = $active_ad->title, 'cat' => $cat = $active_ad->category, 'loc' => $loc = $active_ad->location);
                         Model_Subscribe::find_subscribers($data, floatval(str_replace(',', '.', $active_ad->price)), $active_ad->seotitle, Auth::instance()->get_user()->email);
                         // if subscription is on
                     } catch (Exception $e) {
                         throw new HTTP_Exception_500($e->getMessage());
                     }
                 } else {
                     Alert::set(Alert::ALERT, __("Warning, Advertisement is already marked as 'active'"));
                     if ($param_current_url == Model_Ad::STATUS_NOPUBLISHED) {
                         Request::current()->redirect(Route::url('oc-panel', array('controller' => 'ad', 'action' => 'moderate')));
                     } elseif ($param_current_url == Model_Ad::STATUS_PUBLISHED) {
                         Request::current()->redirect(Route::url('oc-panel', array('controller' => 'ad', 'action' => 'index')));
                     } else {
                         Request::current()->redirect(Route::url('oc-panel', array('controller' => 'ad', 'action' => 'index')) . '?define=' . $param_current_url);
                     }
                 }
             } else {
                 //throw 404
                 throw new HTTP_Exception_404();
             }
         }
     }
     $this->multiple_mails($format_id);
     // sending many mails at the same time @TODO EMAIl
     if (Core::config('sitemap.on_post') == TRUE) {
         Sitemap::generate();
     }
     Alert::set(Alert::SUCCESS, __('Advertisement is active and published'));
     if ($param_current_url == Model_Ad::STATUS_NOPUBLISHED) {
         Request::current()->redirect(Route::url('oc-panel', array('controller' => 'ad', 'action' => 'moderate')));
     } elseif ($param_current_url == Model_Ad::STATUS_PUBLISHED) {
         Request::current()->redirect(Route::url('oc-panel', array('controller' => 'ad', 'action' => 'index')));
     } else {
         Request::current()->redirect(Route::url('oc-panel', array('controller' => 'ad', 'action' => 'index')) . '?define=' . $param_current_url);
     }
 }
예제 #3
0
파일: new.php 프로젝트: Wildboard/WbWebApp
 /**
  * [save_new_ad Save new advertisement if validated, with a given parameters 
  * 
  * @param  [array] $data   [post values]
  * @param  [int] $status [status of advert.]
  * @param  [bool] $published [Confirms if advert is published. ref to model_ad]
  * @param  [int] $moderation [moderation status/mode]
  * 
  * @return [view] View dependant on usecase 
  */
 public function save_new_ad($data, $status, $published, $moderation)
 {
     $user = new Model_User();
     $new_ad = new Model_Ad();
     //$_POST is submitted for a new ad
     if ($this->request->post()) {
         if (captcha::check('publish_new')) {
             //FORM DATA
             $seotitle = $new_ad->gen_seo_title($data['title']);
             $new_ad->title = Model_Ad::banned_words($data['title']);
             $new_ad->id_location = $data['loc'];
             $new_ad->id_category = $data['cat'];
             $new_ad->description = Model_Ad::banned_words($data['description']);
             $new_ad->seotitle = $seotitle;
             $new_ad->status = $status;
             $new_ad->price = floatval(str_replace(',', '.', $data['price']));
             $new_ad->address = $data['address'];
             $new_ad->phone = $data['phone'];
             $new_ad->website = $data['website'];
             // set custom values
             foreach ($data as $name => $field) {
                 // get only custom values with prefix
                 if (strpos($name, 'cf_') !== false) {
                     $new_ad->{$name} = $field;
                 }
             }
             // d($data);
             // User detection, if doesnt exists create
             $auth_user = Auth::instance();
             if (!$auth_user->logged_in()) {
                 $name = core::post('name');
                 $email = core::post('email');
                 $user_id = $user->create_new_user($name, $email);
             } else {
                 $user_id = $auth_user->get_user()->id_user;
                 $name = $auth_user->get_user()->name;
                 $email = $auth_user->get_user()->email;
             }
             // SAVE AD
             $new_ad->id_user = $user_id;
             // after handling user
             try {
                 //akismet spam filter
                 if (!core::akismet(Model_Ad::banned_words($data['title']), $email, Model_Ad::banned_words($data['description']))) {
                     if ($moderation == Model_Ad::EMAIL_MODERATION or $moderation == Model_Ad::EMAIL_CONFIRMATION) {
                         $new_ad->status = Model_Ad::STATUS_UNCONFIRMED;
                     }
                     $new_ad->save();
                 } else {
                     Alert::set(Alert::SUCCESS, __('This post has been considered as spam! We are sorry but we cant publish this advertisement.'));
                     $this->request->redirect('default');
                 }
                 //akismet
                 // if moderation is off update db field with time of creation
                 if ($published) {
                     $_ad_published = new Model_Ad();
                     $_ad_published->where('seotitle', '=', $seotitle)->limit(1)->find();
                     $_ad_published->published = $_ad_published->created;
                     $_ad_published->save();
                     $created = $_ad_published->created;
                 } else {
                     $created = new Model_Ad();
                     $created = $created->where('seotitle', '=', $seotitle)->limit(1)->find();
                     $created = $created->created;
                 }
                 $user = $user->where('email', '=', $email)->limit(1)->find();
                 // after successful posting send them email depending on moderation
                 if ($moderation == Model_Ad::EMAIL_CONFIRMATION or $moderation == Model_Ad::EMAIL_MODERATION) {
                     $edit_url = core::config('general.base_url') . 'oc-panel/profile/update/' . $new_ad->id_ad;
                     $delete_url = core::config('general.base_url') . 'oc-panel/ad/delete/' . $new_ad->id_ad;
                     //we get the QL, and force the regen of token for security
                     $url_ql = $user->ql('default', array('controller' => 'ad', 'action' => 'confirm_post', 'id' => $new_ad->id_ad), TRUE);
                     $ret = $user->email('ads.confirm', array('[URL.QL]' => $url_ql, '[AD.NAME]' => $new_ad->title, '[URL.EDITAD]' => $edit_url, '[URL.DELETEAD]' => $delete_url));
                 } elseif ($moderation == Model_Ad::MODERATION_ON) {
                     $edit_url = core::config('general.base_url') . 'oc-panel/profile/update/' . $new_ad->id_ad;
                     $delete_url = core::config('general.base_url') . 'oc-panel/ad/delete/' . $new_ad->id_ad;
                     //we get the QL, and force the regen of token for security
                     $url_ql = $user->ql('oc-panel', array('controller' => 'profile', 'action' => 'update', 'id' => $new_ad->id_ad), TRUE);
                     $ret = $user->email('ads.notify', array('[URL.QL]' => $url_ql, '[AD.NAME]' => $new_ad->title, '[URL.EDITAD]' => $edit_url, '[URL.DELETEAD]' => $delete_url));
                     // email to notify user of creating, but it is in moderation currently
                 } elseif ($moderation == Model_Ad::POST_DIRECTLY) {
                     $edit_url = core::config('general.base_url') . 'oc-panel/profile/update/' . $new_ad->id_ad;
                     $delete_url = core::config('general.base_url') . 'oc-panel/ad/delete/' . $new_ad->id_ad;
                     $url_cont = $user->ql('contact', array(), TRUE);
                     $url_ad = $user->ql('ad', array('category' => $data['cat'], 'seotitle' => $seotitle), TRUE);
                     $ret = $user->email('ads.user_check', array('[URL.CONTACT]' => $url_cont, '[URL.AD]' => $url_ad, '[AD.NAME]' => $new_ad->title, '[URL.EDITAD]' => $edit_url, '[URL.DELETEAD]' => $delete_url));
                 }
                 // new ad notification email to admin (notify_email), if set to TRUE
                 if (core::config('email.new_ad_notify')) {
                     $url_ad = $user->ql('ad', array('category' => $data['cat'], 'seotitle' => $seotitle), TRUE);
                     $replace = array('[URL.AD]' => $url_ad, '[AD.TITLE]' => $new_ad->title);
                     Email::content(core::config('email.notify_email'), core::config('general.site_name'), core::config('email.notify_email'), core::config('general.site_name'), 'ads.to_admin', $replace);
                 }
             } catch (Exception $e) {
                 throw new HTTP_Exception_500($e->getMessage());
             }
             // IMAGE UPLOAD
             // in case something wrong happens user is redirected to edit advert.
             $filename = NULL;
             $counter = 0;
             for ($i = 0; $i < core::config("advertisement.num_images"); $i++) {
                 $counter++;
                 if (isset($_FILES['image' . $i])) {
                     $fh = fopen('/tmp/grisha.log', 'a');
                     $img_files = $_FILES['image' . $i];
                     if (isset($_REQUEST['wb_base64'])) {
                         fwrite($fh, "Base64 is true\n");
                         $old_name = $_FILES['image' . $i]['tmp_name'];
                         $new_name = $old_name . "_decoded";
                         $img_files['tmp_name'] = $_FILES['image' . $i]['tmp_name'] = $new_name;
                         $img_files['old_name'] = $old_name;
                         copy($old_name, '/tmp/grisha/' . basename($old_name));
                         fwrite($fh, "Decoding from {$old_name} to {$new_name}\n");
                         $encoded = file_get_contents($old_name);
                         $decoded = base64_decode($encoded);
                         $result = file_put_contents($new_name, $decoded);
                         $img_files['size'] = $_FILES['image' . $i]['size'] = filesize($new_name);
                         copy($new_name, '/tmp/grisha/' . basename($new_name));
                         fwrite($fh, "Wrote: " . $result . " to {$new_name}");
                         fwrite($fh, "{$_FILES}: " . print_r($_FILES, true));
                         fwrite($fh, "{$img_files}: " . print_r($img_files, true));
                         fclose($fh);
                     }
                     $filename = $new_ad->save_image($img_files, $new_ad->id_ad, $created, $new_ad->seotitle, $counter);
                 }
                 if ($filename) {
                     $new_ad->has_images = 1;
                     try {
                         $new_ad->save();
                     } catch (Exception $e) {
                         throw new HTTP_Exception_500($e->getMessage());
                     }
                 }
                 if ($filename = FALSE) {
                     $this->request->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'update', 'id' => $new_ad->id_ad)));
                 }
             }
             // PAYMENT METHOD ACTIVE (and other alerts)
             if ($moderation == Model_Ad::PAYMENT_ON || $moderation == Model_Ad::PAYMENT_MODERATION) {
                 $payment_order = new Model_Order();
                 $order_id = $payment_order->make_new_order($data, $user, $seotitle);
                 if ($order_id == NULL) {
                     if ($moderation == Model_Ad::PAYMENT_ON) {
                         $new_ad->status = 1;
                         $new_ad->published = Date::unix2mysql(time());
                         try {
                             $new_ad->save();
                             Alert::set(Alert::SUCCESS, __('Advertisement is published. Congratulations!'));
                         } catch (Exception $e) {
                             throw new HTTP_Exception_500($e->getMessage());
                         }
                     }
                     if ($moderation == Model_Ad::PAYMENT_MODERATION) {
                         Alert::set(Alert::SUCCESS, __('Advertisement is created but needs to be validated first before it is published.'));
                     }
                     $this->request->redirect(Route::url('default'));
                 }
                 // redirect to payment
                 $this->request->redirect(Route::url('default', array('controller' => 'payment_paypal', 'action' => 'form', 'id' => $order_id)));
                 // @TODO - check route
             } elseif ($moderation == Model_Ad::EMAIL_MODERATION or $moderation == Model_Ad::EMAIL_CONFIRMATION) {
                 Alert::set(Alert::INFO, __('Advertisement is posted but first you need to activate. Please check your email!'));
                 $this->request->redirect(Route::url('default'));
             } elseif ($moderation == Model_Ad::MODERATION_ON) {
                 Alert::set(Alert::INFO, __('Advertisement is received, but first administrator needs to validate. Thank you for being patient!'));
                 $this->request->redirect(Route::url('default'));
             } else {
                 Model_Subscribe::find_subscribers($data, floatval(str_replace(',', '.', $data['price'])), $seotitle, $email);
                 Alert::set(Alert::SUCCESS, __('Advertisement is posted. Congratulations!'));
                 $this->request->redirect(Route::url('default'));
             }
         } else {
             Alert::set(Alert::ALERT, __('Captcha is not correct'));
         }
     }
     //is post
 }