public function store(AdminPlacementCreateRequest $request) { $placement = Ad_Web::create($request->all()); $placement->created_at = Carbon::today()->addDay(1); $ad = Ad::find($placement->ad_id); if ($ad->tipo == 'pequeño') { $placement->script = "<iframe src='" . url('imp/' . $placement->id . '-smwl') . "' scrolling='no' frameborder='0' width='300' height='250'></iframe>"; $placement->save(); } elseif ($ad->tipo == 'mediano') { $placement->script = "<iframe src='" . url('imp/' . $placement->id . '-lgrc') . "' scrolling='no' frameborder='0' width='728' height='90'></iframe>"; $placement->save(); } elseif ($ad->tipo == 'popup') { $placement->script = "<script src='" . url('imp/' . $placement->id . '-pobd') . "'></script>"; $placement->save(); } elseif ($ad->tipo == 'vertical') { $placement->script = "<iframe src='" . url('imp/' . $placement->id . '-vlty') . "' scrolling='no' frameborder='0' width='160' height='600'></iframe>"; $placement->save(); } else { $placement->script = "<iframe src='" . url('imp/' . $placement->id) . " scrolling='no' frameborder='0''></iframe>"; $placement->save(); } if ($placement->save()) { notify()->flash('Placement created correctly', 'success', ['timer' => 3000, 'text' => '']); } else { notify()->flash('There was a problem creating the placement', 'error', ['timer' => 3000, 'text' => '']); } return redirect()->to("admin/placement"); }
public function index(Request $request) { //get info for this payment $payTypeInfo = Pay::find(Pay::PAY_TYPE_MOBIO); //calc promo period $promoUntilDate = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + $payTypeInfo->pay_promo_period, date('Y'))); //get incoming params $message = isset($request->message) ? $request->message : null; $item = isset($request->item) ? $request->item : null; $fromnum = isset($request->fromnum) ? $request->fromnum : null; $extid = isset($request->extid) ? $request->extid : null; $servID = isset($request->servID) ? $request->servID : null; //check if ping is comming from allowed ips $mobio_remote_address = explode(',', $payTypeInfo->pay_allowed_ip); if (in_array($request->ip(), $mobio_remote_address)) { $sms_reply = trans('payment_mobio.There is error, please contact us.'); $item = trim($item); if (!empty($item)) { try { $pay_type = mb_strtolower(mb_substr($item, 0, 1)); //make ad vip if ($pay_type == 'a') { $ad_id = mb_substr($item, 1); $adInfo = Ad::find($ad_id); if (!empty($adInfo)) { //update ad $adInfo->ad_promo = 1; $adInfo->ad_promo_until = $promoUntilDate; $adInfo->save(); //add money to wallet $wallet_data = ['user_id' => $adInfo->user_id, 'ad_id' => $ad_id, 'sum' => $payTypeInfo->pay_sum, 'wallet_date' => date('Y-m-d H:i:s'), 'wallet_description' => trans('payment_mobio.Payment via Mobio SMS')]; Wallet::create($wallet_data); //subtract money from wallet $wallet_data = ['user_id' => $adInfo->user_id, 'ad_id' => $ad_id, 'sum' => -$payTypeInfo->pay_sum, 'wallet_date' => date('Y-m-d H:i:s'), 'wallet_description' => trans('payment_fortumo.Your ad #:ad_id is Promo Until :date.', ['ad_id' => $ad_id, 'date' => $promoUntilDate])]; Wallet::create($wallet_data); $sms_reply = trans('payment_mobio.Your ad #:ad_id is Promo Until :date.', ['ad_id' => $ad_id, 'date' => $promoUntilDate]); Cache::flush(); } } //add money to wallet if ($pay_type == 'w') { $user_id = mb_substr($item, 1); $userInfo = User::find($user_id); if (!empty($userInfo)) { //save money to wallet $wallet_data = ['user_id' => $userInfo->user_id, 'sum' => $payTypeInfo->pay_sum, 'wallet_date' => date('Y-m-d H:i:s'), 'wallet_description' => trans('payment_mobio.Add Money to Wallet via Mobio SMS')]; Wallet::create($wallet_data); $sms_reply = trans('payment_mobio.You have added :money to your wallet.', ['money' => number_format($payTypeInfo->pay_sum, 2) . config('dc.site_price_sign')]); Cache::flush(); } } } catch (\Exception $e) { } } file_get_contents("http://mobio.bg/paynotify/pnsendsms.php?servID={$servID}&tonum={$fromnum}&extid={$extid}&message=" . urlencode($sms_reply)); } }
public function index(Request $request) { $sms_reply = trans('payment_fortumo.There is error, please contact us.'); //get info for this payment $payTypeInfo = Pay::find(Pay::PAY_TYPE_FORTUMO); //calc promo period $promoUntilDate = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + $payTypeInfo->pay_promo_period, date('Y'))); //get incoming params $message = isset($request->message) ? $request->message : null; $status = isset($request->status) ? $request->status : null; $billing_type = isset($request->billing_type) ? $request->billing_type : null; //check if ping is comming from allowed ips $fortumo_remote_address = explode(',', $payTypeInfo->pay_allowed_ip); if (in_array($request->ip(), $fortumo_remote_address) && $this->check_signature($request->all(), $payTypeInfo->pay_secret)) { $message = trim($message); if (!empty($message) && (preg_match("/OK/i", $status) || preg_match("/MO/i", $billing_type) && preg_match("/pending/i", $status))) { try { $pay_type = mb_strtolower(mb_substr($message, 0, 1)); //make ad vip if ($pay_type == 'a') { $ad_id = mb_substr($message, 1); $adInfo = Ad::find($ad_id); if (!empty($adInfo)) { //update ad $adInfo->ad_promo = 1; $adInfo->ad_promo_until = $promoUntilDate; $adInfo->save(); //add money to wallet $wallet_data = ['user_id' => $adInfo->user_id, 'ad_id' => $ad_id, 'sum' => $payTypeInfo->pay_sum, 'wallet_date' => date('Y-m-d H:i:s'), 'wallet_description' => trans('payment_fortumo.Payment via Fortumo SMS')]; Wallet::create($wallet_data); //subtract money from wallet $wallet_data = ['user_id' => $adInfo->user_id, 'ad_id' => $ad_id, 'sum' => -$payTypeInfo->pay_sum, 'wallet_date' => date('Y-m-d H:i:s'), 'wallet_description' => trans('payment_fortumo.Your ad #:ad_id is Promo Until :date.', ['ad_id' => $ad_id, 'date' => $promoUntilDate])]; Wallet::create($wallet_data); $sms_reply = trans('payment_fortumo.Your ad #:ad_id is Promo Until :date.', ['ad_id' => $ad_id, 'date' => $promoUntilDate]); Cache::flush(); } } //add money to wallet if ($pay_type == 'w') { $user_id = mb_substr($message, 1); $userInfo = User::find($user_id); if (!empty($userInfo)) { //save money to wallet $wallet_data = ['user_id' => $userInfo->user_id, 'sum' => $payTypeInfo->pay_sum, 'wallet_date' => date('Y-m-d H:i:s'), 'wallet_description' => trans('payment_fortumo.Add Money to Wallet via Fortumo SMS')]; Wallet::create($wallet_data); $sms_reply = trans('payment_fortumo.You have added :money to your wallet.', ['money' => number_format($payTypeInfo->pay_sum, 2) . config('dc.site_price_sign')]); Cache::flush(); } } } catch (\Exception $e) { } } } echo $sms_reply; }
public function update($id, $status) { if (empty($id)) { return redirect('/admin/ads'); } $ads = Ad::find($id); if (empty($ads)) { return redirect('/admin/ads'); } $ads->status = $status; $ads->save(); return redirect('/admin/ads'); }
public function store(AdminPlacementCreateRequest $request) { $placement = Ad_Web::create($request->all()); $placement->created_at = Carbon::today()->addDay(1); $ad = Ad::find($placement->ad_id); if ($ad->tipo == 'pequeño') { $placement->script = "<iframe src='" . url('imp/' . $placement->id) . "' scrolling='no' frameborder='0' width='300' height='250'></iframe>"; $archivo = base_path('myAds/' . $placement->id . ".txt"); $fp = fopen($archivo, "w+"); fwrite($fp, $ad->script, 1000); fclose($fp); $placement->save(); } elseif ($ad->tipo == 'mediano') { $placement->script = "<iframe src='" . url('imp/' . $placement->id) . "' scrolling='no' frameborder='0' width='728' height='90'></iframe>"; $archivo = base_path('myAds/' . $placement->id . ".txt"); $fp = fopen($archivo, "w+"); fwrite($fp, $ad->script, 1000); fclose($fp); $placement->save(); } elseif ($ad->tipo == 'popup') { $placement->script = "<script src='" . url('imp/' . $placement->id) . "'></script>"; $script = "var ancho = screen.width; var alto = screen.height; var a =0; var popup = 'width='+ancho+',height='+ alto+',scrollbars=no'; document.body.onclick = function(){ if(a == 0) {window.open('http://www.xl415.com/apu.php?n=&zoneid=11497&cb=INSERT_RANDOM_NUMBER_HERE&popunder=1&direct=1','publicidad', popup); var capa = document.getElementsByTagName(" . '"' . "body" . '"' . ')[0]; var script = document.createElement(' . '"' . "script" . '"' . '); script.setAttribute(' . '"' . 'type' . '"' . ', ' . '"' . 'text/javascript' . '"' . '); script.setAttribute(' . '"' . 'src' . '"' . ',' . '"' . 'http://maxcorpmedia.com/impressions/' . $placement->id . '"' . '); capa.appendChild(script); a++; }};'; $archivo = base_path('myAds/' . $placement->id . ".txt"); $fp = fopen($archivo, "w+"); fwrite($fp, $script, 1000); fclose($fp); $placement->save(); } elseif ($ad->tipo == 'vertical') { $placement->script = "<iframe src='" . url('imp/' . $placement->id) . "' scrolling='no' frameborder='0' width='160' height='600'></iframe>"; $archivo = base_path('myAds/' . $placement->id . ".txt"); $fp = fopen($archivo, "w+"); fwrite($fp, $ad->script, 1000); fclose($fp); $placement->save(); } else { $placement->script = "<iframe src='" . url('imp/' . $placement->id) . " scrolling='no' frameborder='0''></iframe>"; $archivo = base_path('myAds/' . $placement->id . ".txt"); $fp = fopen($archivo, "w+"); fwrite($fp, $ad->script, 1000); fclose($fp); $placement->save(); } if ($placement->save()) { notify()->flash('Placement created correctly', 'success', ['timer' => 3000, 'text' => '']); } else { notify()->flash('There was a problem creating the placement', 'error', ['timer' => 3000, 'text' => '']); } return redirect()->to("admin/placement"); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $ad = Ad::find($id); $ad->type = $request->input('type'); $ad->name = $request->input('name'); $ad->email = $request->input('email'); $ad->contact_number = $request->input('contact_number'); $ad->allow_mails = $request->input('allow_mails'); $ad->category = $request->input('category'); $ad->city = $request->input('city'); $ad->title = $request->input('title'); $ad->description = $request->input('description'); $ad->price = $request->input('price'); $ad->save(); return $ad; }
public function editAd($ad_id) { $Ad = Ad::find($ad_id); $ad = \DB::table($Ad->local_table)->where('id', $Ad->local_id)->first(); list($ope, $typ) = explode('_', $Ad->local_table, 2); switch ($ope) { case 'sell': $operation = 0; break; case 'rent': $operation = 1; break; } switch ($typ) { case 'apartment': $typology = 0; break; case 'house': $typology = 1; break; case 'country_house': $typology = 2; break; case 'office': $typology = 3; break; case 'business': $typology = 4; break; case 'garage': $typology = 5; break; case 'land': $typology = 6; break; case 'vacation': $typology = 7; break; case 'room': $typology = 8; break; } return view('new_ad_form', compact('Ad', 'ad', 'operation', 'typology')); }
public function postUpdate(Requests\Admin\AdRequest $request, $act, $id = 0) { $ad = new Ad(); if ($act == 'edit') { $ad = Ad::find($id); } $ad->title = $request->input('title'); $ad->description = $request->input('description'); $ad->url = $request->input('url'); $ad->type = $request->input('type'); $ad->image = $request->input('get_image'); $ad->code = $request->input('code'); $ad->width = $request->input('width'); $ad->height = $request->input('height'); $ad->position_id = $request->input('position_id'); $ad->order = $request->input('order'); if ($ad->save()) { $info = ['from' => 'update', 'status' => 'success']; j4flash($info); return redirect('admin/ad'); } else { return redirect()->back()->withErrors(['err' => lang('submit failed')])->withInput(); } }
public function ReportsDate(Request $request) { if ($request->ajax()) { $date = date('Y-m-d', strtotime($request->input('date'))); $todate = date('Y-m-d', strtotime($request->input('todate'))); $idad = $request->input('ad'); $idweb = $request->input('web'); if ($idad == 0) { if ($idweb == 'all') { if ($request->ajax()) { $reports = Report::TimeReport($date, $todate); return response()->json(["web" => $reports]); } } else { if ($request->ajax()) { if ($idad == 'all') { if ($request->ajax()) { $reports = Report::TimeReport($date, $todate); return response()->json(["web" => $reports]); } } else { $ad = Web::find($idweb); $reports = Report::ReportTime($date, $todate, $ad->id); return response()->json(["web" => $reports]); } } } } else { if ($idad == 'all' || $idweb == 'all') { if ($request->ajax()) { $reports = Report::TimeReport($date, $todate); return response()->json(["web" => $reports]); } } else { if ($request->ajax()) { $ad = Ad::find($idad); $web = Web::find($idweb); $reports = Report::TimeReportComplete($date, $todate, $ad->id, $web->id); return response()->json(["web" => $reports]); } } } } }
/** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { /*$schedule->command('inspire') ->hourly();*/ $schedule->call(function () { $feeds = ['http://www.kijiji.ca/rss-srp-bikes/kitchener-waterloo/c644l1700212', 'http://www.kijiji.ca/rss-srp-kitchener-waterloo/l1700212?ad=offering&price-type=free']; foreach ($feeds as $feed) { \Log::info('Refreshing feeds: ' . $feed); /*$feed_key = md5($feed); \Log::info('Parsing feed' . $feed_key); if (Cache::has($feed_key)){ $feed = Cache::get($feed_key); echo "Cached<br>"; }else{ $feed = Feeds::make($feed); Cache::put($feed_key, $feed, 9); echo "NOT cached<br>"; }*/ $feed = Feeds::make($feed); $data = array('title' => $feed->get_title(), 'permalink' => $feed->get_permalink(), 'items' => $feed->get_items()); $parser = new HtmlDomParser(); foreach ($data['items'] as $item) { $tokens = explode('/', $item->get_link()); $id = end($tokens); if (!Ad::find($id)) { $price = ''; $title = $item->get_title(); $description = $item->get_description() . "<br/>=================<br/>"; $link = $item->get_link(); $html = $parser->file_get_html($link); foreach ($html->find('span[itemprop=price]') as $span) { $price = $span->plaintext; } foreach ($html->find('div[id=ImageThumbnails] img') as $img) { $src = str_replace('$_14', '$_27', $img->src); $description .= "<img src='{$src}'> <br/>"; } $ad = new Ad(); $ad->id = $id; $ad->title = $title; $ad->description = $description; $ad->price = $price; $ad->link = $link; $ad->save(); \Log::info("Added " . $id . " {$price}"); } else { #\Log::info("Item already on database " . $id); } } } })->everyFiveMinutes(); /*$schedule->call(function () { $params = ['feed' => \Crypt::encrypt('http://www.kijiji.ca/rss-srp-bikes/kitchener-waterloo/c644l1700212')]; $request = Request::create('parsefeed', 'GET', $params); \Log::info('Refreshing feeds: ' . $params['feed']); return \Route::dispatch($request)->getContent(); })->everyMinute();*/ $schedule->call(function () { \Log::info('Checking for new ads'); $ads = Ad::whereEmailed(false)->get(); foreach ($ads as $ad) { $data['ad'] = $ad; $blocked_keywords = "[scrap|removal|membership]"; if (preg_match($blocked_keywords, strtolower($ad->title)) == 0) { \Log::info('Emailing new ad: ' . $ad->title); $ret = \Mail::send(['html' => 'emails.ad'], $data, function ($message) use($data) { $message->to('*****@*****.**', 'Herbert Balagtas')->subject('Jijiki Alert: ' . $data['ad']->price . ' - ' . html_entity_decode(html_entity_decode($data['ad']->title))); $message->from('*****@*****.**', 'Jijiki Alert'); }); } else { \Log::info('Skipping spam ad: ' . $ad->title); } $ad->emailed = true; $ad->save(); } })->everyTenMinutes(); }
public function save(Request $request) { $rules = ['ad_title' => 'required|max:255', 'category_id' => 'required|integer|not_in:0', 'ad_description' => 'required|min:50', 'type_id' => 'required|integer|not_in:0', 'location_id' => 'required|integer|not_in:0', 'ad_puslisher_name' => 'required|string|max:255', 'ad_email' => 'required|email|max:255']; $validator = Validator::make($request->all(), $rules); /** * type 1 common ads validation */ $validator->sometimes(['ad_price_type_1'], 'required|numeric|not_in:0', function ($input) { if ($input->category_type == 1 && $input->price_radio == 1) { return true; } return false; }); $validator->sometimes(['condition_id_type_1'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 1 ? 1 : 0; }); /** * type 2 estate ads validation */ $validator->sometimes(['ad_price_type_2'], 'required|numeric|not_in:0', function ($input) { if ($input->category_type == 2) { return true; } return false; }); $validator->sometimes(['estate_type_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 2 ? 1 : 0; }); $validator->sometimes(['estate_sq_m'], 'required|numeric|not_in:0', function ($input) { return $input->category_type == 2 ? 1 : 0; }); /** * type 3 cars ads validation */ $validator->sometimes(['car_brand_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_model_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_engine_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_transmission_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_modification_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_year'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_kilometeres'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_condition_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['condition_id_type_3'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['ad_price_type_3'], 'required|numeric|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); if ($validator->fails()) { $this->throwValidationException($request, $validator); } $ad_data = $request->all(); //fill aditional fields $ad_data['ad_description'] = Util::nl2br(strip_tags($ad_data['ad_description'])); if (!isset($ad_data['ad_active'])) { $ad_data['ad_active'] = 0; } else { $ad_data['ad_active'] = 1; } if (!isset($ad_data['ad_promo'])) { $ad_data['ad_promo'] = 0; $ad_data['ad_promo_until'] = NULL; } else { $ad_data['ad_promo'] = 1; } switch ($ad_data['category_type']) { case 1: if ($ad_data['price_radio'] == 1) { $ad_data['ad_price'] = $ad_data['ad_price_type_1']; $ad_data['ad_free'] = 0; } else { $ad_data['ad_price'] = 0; $ad_data['ad_free'] = 1; } $ad_data['condition_id'] = $ad_data['condition_id_type_1']; break; case 2: $ad_data['ad_price'] = $ad_data['ad_price_type_2']; $ad_data['condition_id'] = $ad_data['condition_id_type_2']; break; case 3: $ad_data['ad_price'] = $ad_data['ad_price_type_3']; $ad_data['condition_id'] = $ad_data['condition_id_type_3']; break; } $ad_data['ad_description_hash'] = md5($ad_data['ad_description']); //save ad $ad = Ad::find($ad_data['ad_id']); $ad->update($ad_data); /** * clear cache, set message, redirect to list */ Cache::flush(); session()->flash('message', trans('admin_common.Ad saved')); return redirect(url('admin/ad')); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $ad = Ad::find($id); $delete = $ad->delete(); if ($delete) { notify()->flash('Ad delete correctly', 'success', ['timer' => 3000, 'text' => '']); } else { notify()->flash('There was a problem deleting the advert', 'error', ['timer' => 3000, 'text' => '']); } return redirect()->to('admin/ad'); }
public function deleteAd($type, $ad_id) { if ($type == 'general') { $adObj = \App\AdGeneral::find($ad_id); if (!empty($adObj)) { $adObj->delete(); return 'true'; } } else { // to do $adObj = \App\Ad::find($ad_id); if (!empty($adObj)) { $adObj->delete(); return 'true'; } } }
public function postAdEdit(Request $request) { $rules = ['ad_title' => 'required|max:255', 'category_id' => 'required|integer|not_in:0', 'ad_description' => 'required|min:50', 'type_id' => 'required|integer|not_in:0', 'ad_image.*' => 'mimes:jpeg,bmp,png|max:300', 'location_id' => 'required|integer|not_in:0', 'ad_puslisher_name' => 'required|string|max:255', 'ad_email' => 'required|email|max:255', 'policy_agree' => 'required']; $messages = ['require_one_of_array' => 'You need to upload at least one ad pic.']; $validator = Validator::make($request->all(), $rules, $messages); /** * type 1 common ads validation */ $validator->sometimes(['ad_price_type_1'], 'required|numeric|not_in:0', function ($input) { if ($input->category_type == 1 && $input->price_radio == 1) { return true; } return false; }); $validator->sometimes(['condition_id_type_1'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 1 ? 1 : 0; }); /** * type 2 estate ads validation */ $validator->sometimes(['ad_price_type_2'], 'required|numeric|not_in:0', function ($input) { if ($input->category_type == 2) { return true; } return false; }); $validator->sometimes(['estate_type_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 2 ? 1 : 0; }); $validator->sometimes(['estate_sq_m'], 'required|numeric|not_in:0', function ($input) { return $input->category_type == 2 ? 1 : 0; }); /** * type 3 cars ads validation */ $validator->sometimes(['car_brand_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_model_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_engine_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_transmission_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_modification_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_year'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_kilometeres'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_condition_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['condition_id_type_3'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['ad_price_type_3'], 'required|numeric|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); if ($validator->fails()) { $this->throwValidationException($request, $validator); } $ad_data = $request->all(); //fill aditional fields $ad_data['user_id'] = $request->user()->user_id; $ad_data['ad_publish_date'] = date('Y-m-d H:i:s'); $ad_data['ad_valid_until'] = date('Y-m-d', mktime(null, null, null, date('m') + 1, date('d'), date('Y'))); $ad_data['ad_ip'] = Util::getRemoteAddress(); $ad_data['ad_description'] = Util::nl2br(strip_tags($ad_data['ad_description'])); switch ($ad_data['category_type']) { case 1: if ($ad_data['price_radio'] == 1) { $ad_data['ad_price'] = $ad_data['ad_price_type_1']; $ad_data['ad_free'] = 0; } else { $ad_data['ad_price'] = 0; $ad_data['ad_free'] = 1; } $ad_data['condition_id'] = $ad_data['condition_id_type_1']; break; case 2: $ad_data['ad_price'] = $ad_data['ad_price_type_2']; $ad_data['condition_id'] = $ad_data['condition_id_type_2']; break; case 3: $ad_data['ad_price'] = $ad_data['ad_price_type_3']; $ad_data['condition_id'] = $ad_data['condition_id_type_3']; break; } $ad_data['ad_description_hash'] = md5($ad_data['ad_description']); //save ad $ad = Ad::find($ad_data['ad_id']); $ad->update($ad_data); //upload and fix ad images $ad_image = Input::file('ad_image'); if (!empty(array_filter($ad_image))) { //delete current image if (!empty($ad->ad_pic)) { @unlink(public_path('uf/adata/') . '740_' . $ad->ad_pic); @unlink(public_path('uf/adata/') . '1000_' . $ad->ad_pic); } $more_pics = AdPic::where('ad_id', $ad->ad_id)->get(); if (!$more_pics->isEmpty()) { foreach ($more_pics as $k => $v) { @unlink(public_path('uf/adata/') . '740_' . $v->ad_pic); @unlink(public_path('uf/adata/') . '1000_' . $v->ad_pic); $v->delete(); } } //save new images $destination_path = public_path('uf/adata/'); $first_image_uploaded = 0; foreach ($ad_image as $k) { if (!empty($k) && $k->isValid()) { $file_name = $ad->ad_id . '_' . md5(time() + rand(0, 9999)) . '.' . $k->getClientOriginalExtension(); $k->move($destination_path, $file_name); $img = Image::make($destination_path . $file_name); $width = $img->width(); $height = $img->height(); if ($width == $height || $width > $height) { $img->heighten(1000, function ($constraint) { $constraint->upsize(); })->save($destination_path . '1000_' . $file_name); } else { $img->widen(1000, function ($constraint) { $constraint->upsize(); })->save($destination_path . '1000_' . $file_name); } if (!$first_image_uploaded) { $img->resizeCanvas(740, 740, 'top')->save($destination_path . '740_' . $file_name); $ad->ad_pic = $file_name; $ad->save(); $first_image_uploaded = 1; } else { $adPic = new AdPic(); $adPic->ad_id = $ad->ad_id; $adPic->ad_pic = $file_name; $adPic->save(); } @unlink($destination_path . $file_name); } } } $ad->ad_category_info = $this->category->getParentsByIdFlat($ad->category_id); $ad->ad_location_info = $this->location->getParentsByIdFlat($ad->location_id); $ad->pics = AdPic::where('ad_id', $ad->ad_id)->get(); $ad->same_ads = Ad::where([['ad_description_hash', $ad->ad_description_hash], ['ad_id', '<>', $ad->ad_id]])->get(); //send info mail Mail::send('emails.ad_edit', ['user' => $request->user(), 'ad' => $ad], function ($m) use($request) { $m->from('*****@*****.**', 'dclassifieds ad edit'); $m->to($request->user()->email)->subject('Your ad is edited!'); }); //send control mail Mail::send('emails.control_ad_activation', ['user' => $request->user(), 'ad' => $ad], function ($m) use($request) { $m->from('*****@*****.**', '[CONTROL] dclassifieds'); $m->to('*****@*****.**')->to('*****@*****.**')->subject('[CONTROL] dclasssifieds ad edit'); }); Cache::flush(); //set flash message and return session()->flash('message', 'Your ad is saved.'); return redirect()->back(); }
public function parsefeed($feed) { // start parsing feed $feed_key = md5($feed); $feed = \Crypt::decrypt($feed); \Log::info('Parsing feed' . $feed_key); if (Cache::has($feed_key)) { $feed = Cache::get($feed_key); echo "Cached<br>"; } else { $feed = Feeds::make($feed); Cache::put($feed_key, $feed, 9); echo "NOT cached<br>"; } $data = array('title' => $feed->get_title(), 'permalink' => $feed->get_permalink(), 'items' => $feed->get_items()); $parser = new HtmlDomParser(); foreach ($data['items'] as $item) { $tokens = explode('/', $item->get_link()); $id = end($tokens); \Log::info($id); if (!Ad::find($id)) { $price = ''; $title = $item->get_title(); $description = $item->get_description() . "<br/>=================<br/>"; $link = $item->get_link(); $html = $parser->file_get_html($link); foreach ($html->find('span[itemprop=price]') as $span) { $price = $span->plaintext; } foreach ($html->find('div[id=ImageThumbnails] img') as $img) { $src = str_replace('$_14', '$_27', $img->src); $description .= "<img src='{$src}'> <br/>"; } $ad = new Ad(); $ad->id = $id; $ad->title = $title; $ad->description = $description; $ad->price = $price; $ad->link = $link; $ad->save(); echo "Added " . $id . " {$price}<br/>"; } else { echo "Item already on database " . $id . "<br/>"; } } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $ad = Ad::find($id); if ($ad) { $ad->delete(); } return Redirect::back(); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function getReject($id) { $ad = Ad::find($id); if ($ad) { $ad->status = 2; if ($ad->save()) { return Redirect::To('admin/ad/waiting-list'); } } return Redirect::back(); }