本文整理匯總了PHP中Model_Ad::gen_seo_title方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model_Ad::gen_seo_title方法的具體用法?PHP Model_Ad::gen_seo_title怎麽用?PHP Model_Ad::gen_seo_title使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Model_Ad
的用法示例。
在下文中一共展示了Model_Ad::gen_seo_title方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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);
}
示例3: 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;
//.........這裏部分代碼省略.........
示例4: 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'])) {
//gettin the id_user
if (isset($users_map[$a['email']])) {
$id_user = $users_map[$a['email']];
} else {
$user = Model_User::create_email($a['email'], $a['name']);
$id_user = $user->id_user;
}
$ad = new Model_Ad();
$ad->id_ad = $a['idPost'];
//so images still work
$ad->id_user = $id_user;
$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) {
//.........這裏部分代碼省略.........
示例5: 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);
//.........這裏部分代碼省略.........