本文整理汇总了PHP中Model_Ad::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_Ad::save方法的具体用法?PHP Model_Ad::save怎么用?PHP Model_Ad::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_Ad
的用法示例。
在下文中一共展示了Model_Ad::save方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create_ad
/**
* creates an ad from a row of import
* @param class adsimport $adi
* @return boolean
*/
private function create_ad($adi)
{
//new advertisement
$ad = new Model_Ad();
//create user?
if ($adi->id_user == NULL or !is_numeric($adi->id_user)) {
//create the user
$user = Model_User::create_user($adi->user_email, $adi->user_name);
//check if in the table other users with same email set the id_user, then gets faster ;)
try {
DB::update('adsimport')->set(array('id_user' => $user->id_user))->where('user_email', '=', $adi->user_email)->execute();
} catch (Exception $e) {
}
//set id user to the new ad
$ad->id_user = $user->id_user;
} else {
$ad->id_user = $adi->id_user;
}
//create category?
if ($adi->id_category == NULL or !is_numeric($adi->id_category)) {
//create the category
$cat = Model_Category::create_name($adi->category);
//check if in the table other cats with same name set the id_category, then gets faster ;)
try {
DB::update('adsimport')->set(array('id_category' => $cat->id_category))->where('category', '=', $adi->category)->execute();
} catch (Exception $e) {
}
//set id user to the new ad
$ad->id_category = $cat->id_category;
} else {
$ad->id_category = $adi->id_category;
}
//create location?
if (isset($adi->location) and !empty($adi->location) and ($adi->id_location == NULL or !is_numeric($adi->id_location))) {
//create the location
$loc = Model_Location::create_name($adi->location);
//check if in the table other cats with same name set the id_location, then gets faster ;)
try {
DB::update('adsimport')->set(array('id_location' => $loc->id_location))->where('location', '=', $adi->location)->execute();
} catch (Exception $e) {
}
//set id user to the new ad
$ad->id_location = $loc->id_location;
} elseif (is_numeric($adi->id_location)) {
$ad->id_location = $adi->id_location;
}
$ad->title = $adi->title;
$ad->seotitle = $ad->gen_seo_title($adi->title);
$ad->description = Text::html2bb($adi->description);
$ad->published = $adi->date;
$ad->created = $adi->date;
$ad->price = $adi->price;
$ad->address = $adi->address;
$ad->phone = $adi->phone;
$ad->website = $adi->website;
$ad->status = Model_Ad::STATUS_PUBLISHED;
try {
$ad->save();
} catch (Exception $e) {
return FALSE;
}
//save images
if (($has_images = $this->process_images($ad, $adi)) > 0) {
$ad->has_images = $has_images;
try {
$ad->save();
} catch (Exception $e) {
return FALSE;
}
}
//mark it as done
try {
DB::update('adsimport')->set(array('processed' => 1))->where('id_import', '=', $adi->id_import)->execute();
return TRUE;
} catch (Exception $e) {
return FALSE;
}
}
示例2: action_confirm
/**
* confirms the post of and advertisement
* @return void
*/
public function action_confirm()
{
$advert = new Model_Ad($this->request->param('id'));
if ($advert->loaded()) {
if (Auth::instance()->get_user()->id_user !== $advert->id_user) {
Alert::set(Alert::ALERT, __("This is not your advertisement."));
HTTP::redirect(Route::url('oc-panel', array('controller' => 'myads', 'action' => 'index')));
}
if (core::config('general.moderation') == Model_Ad::EMAIL_CONFIRMATION) {
$advert->status = Model_Ad::STATUS_PUBLISHED;
// status active
$advert->published = Date::unix2mysql();
try {
$advert->save();
Model_Subscribe::notify($advert);
Alert::set(Alert::INFO, __('Your advertisement is successfully activated! Thank you!'));
} catch (Exception $e) {
throw HTTP_Exception::factory(500, $e->getMessage());
}
} elseif (core::config('general.moderation') == Model_Ad::EMAIL_MODERATION) {
$advert->status = Model_Ad::STATUS_NOPUBLISHED;
try {
$advert->save();
Alert::set(Alert::INFO, __('Advertisement is received, but first administrator needs to validate. Thank you for being patient!'));
} catch (Exception $e) {
throw HTTP_Exception::factory(500, $e->getMessage());
}
}
$this->redirect(Route::url('ad', array('category' => $advert->category->seoname, 'seotitle' => $advert->seotitle)));
}
}
示例3: new_ad
/**
* creates a new ad
* @param array $data
* @param model_user $user
* @return array
*/
public static function new_ad($data, $user)
{
$return_message = '';
$checkout_url = '';
//akismet spam filter
if (isset($data['title']) and isset($data['description']) and core::akismet($data['title'], $user->email, $data['description']) == TRUE) {
// is user marked as spammer? Make him one :)
if (core::config('general.black_list')) {
$user->user_spam();
}
return array('error' => __('This post has been considered as spam! We are sorry but we can not publish this advertisement.'), 'error_type' => Alert::ALERT);
}
//akismet
$ad = new Model_Ad();
$ad->id_user = $user->id_user;
$ad->values($data);
$ad->seotitle = $ad->gen_seo_title($ad->title);
$ad->created = Date::unix2mysql();
try {
$ad->save();
} catch (ORM_Validation_Exception $e) {
return array('validation_errors' => $e->errors('ad'));
} catch (Exception $e) {
return array('error' => $e->getMessage(), 'error_type' => Alert::ALERT);
}
/////////// NOTIFICATION Emails,messages to user and Status of the ad
// depending on user flow (moderation mode), change usecase
$moderation = core::config('general.moderation');
//calculate how much he needs to pay in case we have payment on
if ($moderation == Model_Ad::PAYMENT_ON or $moderation == Model_Ad::PAYMENT_MODERATION) {
// check category price, if 0 check parent
if ($ad->category->price == 0) {
$cat_parent = new Model_Category($ad->category->id_category_parent);
//category without price
if ($cat_parent->price == 0) {
//swapping moderation since theres no price :(
if ($moderation == Model_Ad::PAYMENT_ON) {
$moderation = Model_Ad::POST_DIRECTLY;
} elseif ($moderation == Model_Ad::PAYMENT_MODERATION) {
$moderation = Model_Ad::MODERATION_ON;
}
} else {
$amount = $cat_parent->price;
}
} else {
$amount = $ad->category->price;
}
}
//where and what we say to the user depending ont he moderation
switch ($moderation) {
case Model_Ad::PAYMENT_ON:
case Model_Ad::PAYMENT_MODERATION:
$ad->status = Model_Ad::STATUS_NOPUBLISHED;
$order = Model_Order::new_order($ad, $user, Model_Order::PRODUCT_CATEGORY, $amount, NULL, Model_Order::product_desc(Model_Order::PRODUCT_CATEGORY) . ' ' . $ad->category->name);
// redirect to invoice
$return_message = __('Please pay before we publish your advertisement.');
$checkout_url = Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order));
break;
case Model_Ad::EMAIL_MODERATION:
case Model_Ad::EMAIL_CONFIRMATION:
$ad->status = Model_Ad::STATUS_UNCONFIRMED;
$url_ql = $user->ql('oc-panel', array('controller' => 'myads', 'action' => 'confirm', 'id' => $ad->id_ad));
$user->email('ads-confirm', array('[URL.QL]' => $url_ql, '[AD.NAME]' => $ad->title));
$return_message = __('Advertisement is posted but first you need to activate. Please check your email!');
break;
case Model_Ad::MODERATION_ON:
$ad->status = Model_Ad::STATUS_NOPUBLISHED;
$url_ql = $user->ql('oc-panel', array('controller' => 'myads', 'action' => 'update', 'id' => $ad->id_ad));
$user->email('ads-notify', array('[URL.QL]' => $url_ql, '[AD.NAME]' => $ad->title));
// email to notify user of creating, but it is in moderation currently
$return_message = __('Advertisement is received, but first administrator needs to validate. Thank you for being patient!');
break;
case Model_Ad::POST_DIRECTLY:
default:
$ad->status = Model_Ad::STATUS_PUBLISHED;
$ad->published = $ad->created;
$url_cont = $user->ql('contact');
$url_ad = $user->ql('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle));
$user->email('ads-user-check', array('[URL.CONTACT]' => $url_cont, '[URL.AD]' => $url_ad, '[AD.NAME]' => $ad->title));
Model_Subscribe::notify($ad);
$return_message = __('Advertisement is posted. Congratulations!');
break;
}
//save the last changes on status
$ad->save();
//notify admins new ad
$ad->notify_admins();
return array('message' => $return_message, 'checkout_url' => $checkout_url, 'ad' => $ad);
}
示例4: unfavorite
/**
* unfavorite an ad
* @param integer $id_user user
* @param integer $id_ad ad
* @return boolean
*/
public static function unfavorite($id_user, $id_ad)
{
//try to find the fav
$fav = new Model_Favorite();
$fav->where('id_user', '=', $id_user)->where('id_ad', '=', $id_ad)->find();
if ($fav->loaded()) {
$fav->delete();
// update ad favorite counter
$ad = new Model_Ad($id_ad);
if ($ad->loaded()) {
$ad->favorited--;
try {
$ad->save();
} catch (Exception $e) {
return FALSE;
}
}
return TRUE;
} else {
return FALSE;
}
}
示例5: action_to_featured
/**
* [action_to_featured] [pay to go in featured]
*
*/
public function action_to_featured()
{
//check pay to featured top is enabled
if (core::config('payment.to_featured') == FALSE) {
throw HTTP_Exception::factory(404, __('Page not found'));
}
$id_product = Model_Order::PRODUCT_TO_FEATURED;
//check ad exists
$id_ad = $this->request->param('id');
//how many days
if (!is_numeric($days = Core::request('featured_days'))) {
$plans = Model_Order::get_featured_plans();
$days = array_keys($plans);
$days = reset($days);
}
//get price for the days
$amount = Model_Order::get_featured_price($days);
$ad = new Model_Ad($id_ad);
if ($ad->loaded()) {
//case when payment is set to 0,gets featured for free...
if ($amount <= 0) {
$ad->featured = Date::unix2mysql(time() + $days * 24 * 60 * 60);
try {
$ad->save();
} catch (Exception $e) {
throw HTTP_Exception::factory(500, $e->getMessage());
}
$this->redirect(Route::url('list'));
}
$currency = core::config('payment.paypal_currency');
$order = Model_Order::new_order($ad, $ad->user, $id_product, $amount, $currency, NULL, $days);
// redirect to payment
$this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)));
} else {
throw HTTP_Exception::factory(404, __('Page not found'));
}
}
示例6: action_activate
/**
* Mark advertisement as active : STATUS = 1
*/
public function action_activate()
{
$id = $this->request->param('id');
$param_current_url = Core::get('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 != Model_Ad::STATUS_PUBLISHED) {
$active_ad->published = Date::unix2mysql();
$active_ad->status = Model_Ad::STATUS_PUBLISHED;
try {
$active_ad->save();
Model_Subscribe::notify($active_ad);
} catch (Exception $e) {
throw HTTP_Exception::factory(500, $e->getMessage());
}
}
}
}
}
$this->multiple_mails($format_id);
// sending many mails at the same time @TODO EMAIl
Alert::set(Alert::SUCCESS, __('Advertisement is active and published'));
if ($param_current_url == Model_Ad::STATUS_NOPUBLISHED and in_array(core::config('general.moderation'), Model_Ad::$moderation_status)) {
HTTP::redirect(Route::url('oc-panel', array('controller' => 'ad', 'action' => 'moderate')));
} elseif ($param_current_url == Model_Ad::STATUS_PUBLISHED) {
HTTP::redirect(Route::url('oc-panel', array('controller' => 'ad', 'action' => 'index')));
} else {
HTTP::redirect(Route::url('oc-panel', array('controller' => 'ad', 'action' => 'index')) . '?status=' . $param_current_url);
}
}
示例7: action_cleanimages
/**
* cleans old pictures
* @return [type] [description]
*/
public function action_cleanimages()
{
$count_deleted = 0;
//loop for directory image
$folder = DOCROOT . 'images';
//year
foreach (new DirectoryIterator($folder) as $year) {
if ($year->isDir() and !$year->isDot() and is_numeric($year->getFilename())) {
//month
foreach (new DirectoryIterator($year->getPathname()) as $month) {
if ($month->isDir() and !$month->isDot() and is_numeric($month->getFilename())) {
//day
foreach (new DirectoryIterator($month->getPathname()) as $day) {
if ($day->isDir() and !$day->isDot() and is_numeric($day->getFilename())) {
//id_ad
foreach (new DirectoryIterator($day->getPathname()) as $id_ad) {
if ($id_ad->isDir() and !$id_ad->isDot() and is_numeric($id_ad->getFilename())) {
$delete = TRUE;
//if ad is available leave it, if not delete folder ID
$ad = new Model_Ad($id_ad->getFilename());
if ($ad->loaded() and $ad->status == Model_Ad::STATUS_PUBLISHED) {
$delete = FALSE;
}
//ok lets get rid of it!
if ($delete === TRUE) {
echo '<br>Deleting: ' . $id_ad->getFilename() . '---' . $id_ad->getPathname();
File::delete($id_ad->getPathname());
//if the ad was loaded means had a different status, put it like he doesnt have images.
if ($ad->loaded()) {
$ad->has_images = 0;
$ad->save();
//$ad->delete();//optional
}
$count_deleted++;
}
}
}
}
}
}
}
}
}
echo '<br>deleted ' . $count_deleted;
}
示例8: action_activate
/**
* 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);
}
}
示例9: migrate
/**
* does the DB migration
* @param pointer $db
* @param string $pf db_prefix
*/
private function migrate($db, $pf)
{
set_time_limit(0);
$db_config = core::config('database.default');
$prefix = $db_config['table_prefix'];
//connect DB original/to where we migrate
$dbo = Database::instance('default');
//oc_accounts --> oc_users
$users_map = array();
$accounts = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'accounts`');
foreach ($accounts as $account) {
$user = new Model_User();
$user->where('email', '=', $account['email'])->limit(1)->find();
if (!$user->loaded()) {
$user->name = $account['name'];
$user->email = $account['email'];
$user->password = $account['password'];
$user->created = $account['createdDate'];
$user->last_modified = $account['lastModifiedDate'];
$user->last_login = $account['lastSigninDate'];
$user->status = $account['active'];
$user->id_role = 1;
$user->seoname = $user->gen_seo_title($user->name);
$user->save();
}
$users_map[$account['email']] = $user->id_user;
}
//categories --> categories
$categories_map = array(0 => 1);
$categories = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'categories` ORDER BY `idCategoryParent` ASC');
foreach ($categories as $category) {
$cat = new Model_Category();
$cat->name = $category['name'];
$cat->order = $category['order'];
$cat->created = $category['created'];
$cat->seoname = $category['friendlyName'];
$cat->price = $category['price'];
$cat->description = substr($category['description'], 0, 250);
$cat->parent_deep = $category['idCategoryParent'] > 0 ? 1 : 0;
//there's only 1 deep
$cat->id_category_parent = isset($categories_map[$category['idCategoryParent']]) ? $categories_map[$category['idCategoryParent']] : 1;
$cat->save();
//we save old_id stores the new ID, so later we know the category parent, and to changes the ADS category id
$categories_map[$category['idCategory']] = $cat->id_category;
}
//locations --> locations
$locations_map = array(0 => 1);
$locations = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'locations` ORDER BY `idLocationParent` ASC');
foreach ($locations as $location) {
$loc = new Model_Location();
$loc->name = $location['name'];
$loc->seoname = $location['friendlyName'];
$loc->parent_deep = $location['idLocationParent'] > 0 ? 1 : 0;
//there's only 1 deep
$loc->id_location_parent = isset($locations_map[$location['idLocationParent']]) ? $locations_map[$location['idLocationParent']] : 1;
$loc->save();
//we save old_id stores the new ID, so later we know the location parent, and to changes the ADS location id
$locations_map[$location['idLocation']] = $loc->id_location;
}
//posts --> ads
$ads_map = array();
$ads = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'posts`');
foreach ($ads as $a) {
if (Valid::email($a['email'])) {
$ad = new Model_Ad();
$ad->id_ad = $a['idPost'];
//so images still work
$ad->id_user = isset($users_map[$a['email']]) ? $users_map[$a['email']] : Model_User::create_email($a['email'], $a['name']);
$ad->id_category = isset($categories_map[$a['idCategory']]) ? $categories_map[$a['idCategory']] : 1;
$ad->id_location = isset($locations_map[$a['idLocation']]) ? $locations_map[$a['idLocation']] : 1;
$ad->title = $a['title'];
$ad->seotitle = $ad->gen_seo_title($a['title']);
$ad->description = !empty($a['description']) ? Text::html2bb($a['description']) : $a['title'];
$ad->address = $a['place'];
$ad->price = $a['price'];
$ad->phone = $a['phone'];
$ad->has_images = $a['hasImages'];
$ad->ip_address = ip2long($a['ip']);
$ad->created = $a['insertDate'];
$ad->published = $ad->created;
//Status migration...big mess!
if ($a['isAvailable'] == 0 and $a['isConfirmed'] == 0) {
$ad->status = Model_Ad::STATUS_NOPUBLISHED;
} elseif ($a['isAvailable'] == 1 and $a['isConfirmed'] == 0) {
$ad->status = Model_Ad::STATUS_NOPUBLISHED;
} elseif ($a['isAvailable'] == 1 and $a['isConfirmed'] == 1) {
$ad->status = Model_Ad::STATUS_PUBLISHED;
} elseif ($a['isAvailable'] == 0 and $a['isConfirmed'] == 1) {
$ad->status = Model_Ad::STATUS_UNAVAILABLE;
} elseif ($a['isAvailable'] == 2) {
$ad->status = Model_Ad::STATUS_SPAM;
} else {
$ad->status = Model_Ad::STATUS_UNAVAILABLE;
}
try {
//.........这里部分代码省略.........
示例10: action_confirm_post
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());
}
}
}
}
示例11: action_update
/**
* Edit advertisement: Update
*
* All post fields are validated
*/
public function action_update()
{
//template header
$this->template->title = __('Edit advertisement');
$this->template->meta_description = __('Edit advertisement');
//local files
if (Theme::get('cdn_files') == FALSE) {
$this->template->styles = array('css/datepicker.css' => 'screen');
$this->template->scripts['footer'] = array('js/bootstrap-datepicker.js', 'js/jquery.validate.min.js', 'js/oc-panel/edit_ad.js');
} else {
$this->template->styles = array('http://cdn.jsdelivr.net/bootstrap.datepicker/0.1/css/datepicker.css' => 'screen');
$this->template->scripts['footer'] = array('http://cdn.jsdelivr.net/bootstrap.datepicker/0.1/js/bootstrap-datepicker.js', 'js/jquery.validate.min.js', 'js/oc-panel/edit_ad.js');
}
Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
$form = new Model_Ad($this->request->param('id'));
//find all, for populating form select fields
list($categories, $order_categories) = Model_Category::get_all();
list($locations, $order_locations) = Model_Location::get_all();
if (Auth::instance()->logged_in() && Auth::instance()->get_user()->id_user == $form->id_user || Auth::instance()->logged_in() && Auth::instance()->get_user()->id_role == 10) {
$extra_payment = core::config('payment');
Breadcrumbs::add(Breadcrumb::factory()->set_title("Update"));
$this->template->content = View::factory('oc-panel/profile/edit_ad', array('ad' => $form, 'locations' => $locations, 'order_locations' => $order_locations, 'categories' => $categories, 'order_categories' => $order_categories, 'extra_payment' => $extra_payment, 'fields' => Model_Field::get_all()));
if ($this->request->post()) {
$cat = new Model_Category();
$loc = new Model_Location();
// deleting single image by path
$deleted_image = core::post('img_delete');
if ($deleted_image) {
$img_path = $form->gen_img_path($form->id_ad, $form->created);
if (!is_dir($img_path)) {
return FALSE;
} else {
//delete formated image
unlink($img_path . $deleted_image . '.jpg');
//delete original image
$orig_img = str_replace('thumb_', '', $deleted_image);
unlink($img_path . $orig_img . ".jpg");
$this->request->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'update', 'id' => $form->id_ad)));
}
}
// end of img delete
$data = array('_auth' => $auth = Auth::instance(), 'title' => $title = Model_Ad::banned_words(core::post('title')), 'seotitle' => $seotitle = core::post('title'), 'loc' => $loc = core::post('location'), 'description' => $description = Model_Ad::banned_words(core::post('description')), 'price' => $price = floatval(str_replace(',', '.', core::post('price'))), 'address' => $address = core::post('address'), 'website' => $website = core::post('website'), 'phone' => $phone = core::post('phone'), 'has_images' => 0, 'user' => $user = new Model_User());
// append to $data new custom values
foreach ($_POST as $name => $field) {
// get by prefix
if (strpos($name, 'cf_') !== false) {
$data[$name] = $field;
//checkbox when selected return string 'on' as a value
if ($field == 'on') {
$data[$name] = 1;
}
}
}
//insert data
if (core::post('title') != $form->title) {
if ($form->has_images == 1) {
$current_path = $form->gen_img_path($form->id_ad, $form->created);
// rename current image path to match new seoname
rename($current_path, $form->gen_img_path($form->id_ad, $form->created));
}
$seotitle = $form->gen_seo_title($data['title']);
$form->seotitle = $seotitle;
} else {
$form->seotitle = $form->seotitle;
}
$form->title = $data['title'];
$form->id_location = $data['loc'];
//$form->id_category = $data['cat'];
$form->description = $data['description'];
// $form->status = $data['status'];
$form->price = $data['price'];
$form->address = $data['address'];
$form->website = $data['website'];
$form->phone = $data['phone'];
// set custom values
foreach ($data as $key => $value) {
// get only custom values with prefix
if (strpos($key, 'cf_') !== false) {
$form->{$key} = $value;
}
}
// d($data['cf_radio']);
$obj_ad = new Model_Ad();
// 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])) {
$img_files = $_FILES['image' . $i];
$filename = $obj_ad->save_image($img_files, $form->id_ad, $form->created, $form->seotitle, $counter);
}
if ($filename) {
$form->has_images = 1;
//.........这里部分代码省略.........
示例12: save_new_ad
/**
* [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);
//.........这里部分代码省略.........