本文整理汇总了PHP中Security::csrf_valid方法的典型用法代码示例。如果您正苦于以下问题:PHP Security::csrf_valid方法的具体用法?PHP Security::csrf_valid怎么用?PHP Security::csrf_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Security
的用法示例。
在下文中一共展示了Security::csrf_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_deletegroup
/**
* Action: delete group
*/
public function action_deletegroup()
{
$this->history = false;
$group_id = (int) $this->request->param('id');
$group = Model_Tag_Group::factory($group_id);
if (!$group->loaded() || !Security::csrf_valid()) {
throw new Model_Exception($group, $group_id);
}
$group->delete();
$this->request->redirect(Route::url('tags'));
}
示例2: action_delete
/**
* Action: delete
*/
public function action_delete()
{
$this->history = false;
$role_id = (int) $this->request->param('id');
$role = Model_Role::factory($role_id);
if (!$role->loaded() || !Security::csrf_valid()) {
throw new Model_Exception($role, $role_id);
}
Permission::required($role, Model_Role::PERMISSION_DELETE, self::$user);
$role->delete();
Request::back(Route::url('roles'));
}
示例3: action_shout
/**
* Action: shout
*/
public function action_shout()
{
$shout = Model_Shout::factory();
if (Permission::has($shout, Permission_Interface::PERMISSION_CREATE) && Security::csrf_valid()) {
$shout->author_id = Visitor::$user->id;
$shout->shout = $_POST['shout'];
$shout->created = time();
try {
$shout->save();
} catch (Validation_Exception $e) {
}
}
if ($this->ajax) {
$section = $this->section_shouts();
$section->aside = true;
$this->response->body($section);
return;
}
$this->request->redirect(Route::get('shouts')->uri());
}
示例4: action_shout
/**
* Action: shout
*/
public function action_shout()
{
$shout = Model_Shout::factory();
$errors = array();
if (Permission::has($shout, Permission_Interface::PERMISSION_CREATE) && Security::csrf_valid()) {
$shout->author_id = self::$user->id;
$shout->shout = $_POST['shout'];
$shout->created = time();
try {
$shout->save();
} catch (Validation_Exception $e) {
$errors = $e->array->errors('validate');
}
}
if ($this->ajax) {
echo new View_Index_Shouts();
exit;
}
$this->request->redirect(Route::get('shouts')->uri());
}
示例5: action_index
/**
* Controller default action
*/
public function action_index()
{
$this->view->title = __('Contact');
$section = $this->section_contact();
if (Visitor::$user) {
$section->name = Visitor::$user->username;
$section->email = Visitor::$user->email;
}
// Handle post
$errors = array();
if ($_POST && Security::csrf_valid()) {
$name = trim(Arr::get($_POST, 'name'));
$email = trim(Arr::get($_POST, 'email'));
$subject = trim(Arr::get($_POST, 'subject'));
$content = trim(Arr::get($_POST, 'content'));
if (!Valid::email($email)) {
$errors['email'] = __('Please check the email address');
}
if (!$content) {
$errors['content'] = __('Please say something');
}
// Send feedback
if (!$errors) {
$topic = __('Feedback') . ': ' . $subject;
$mail = $content . "\n\n" . Request::$client_ip . ' - ' . Request::host_name();
if (Anqh_Email::send(Kohana::$config->load('site.email_contact'), array($email, $name), $topic, $mail, false, array($email, $name))) {
$this->view->add(View_Page::COLUMN_CENTER, new View_Alert(__('Thank you! We will try to return back to you as soon as possible.'), true, View_Alert::SUCCESS));
} else {
$errors['content'] = __('Could not send feedback');
}
}
if ($errors) {
$section->errors = $errors;
$section->name = $name;
$section->email = $email;
$section->subject = $subject;
$section->content = $content;
}
}
$this->view->add(View_Page::COLUMN_CENTER, $section);
}
示例6: action_shout
/**
* Action: shout
*/
public function action_shout()
{
$shout = Jelly::factory('shout');
$errors = array();
if (Permission::has($shout, Permission_Interface::PERMISSION_CREATE) && Security::csrf_valid()) {
$shout->author = self::$user;
$shout->shout = $_POST['shout'];
try {
$shout->save();
if (!$this->ajax) {
$this->request->redirect(Route::get('shouts')->uri());
}
} catch (Validate_Exception $e) {
$errors = $e->array->errors('validate');
}
}
$shouts = Jelly::select('shout')->limit(10)->execute();
$view = View_Module::factory('generic/shout', array('mod_title' => __('Shouts'), 'shouts' => $shouts, 'can_shout' => Permission::has($shout, Model_Shout::PERMISSION_CREATE), 'errors' => $errors));
if ($this->ajax) {
echo $view;
} else {
Widget::add('side', $view);
}
}
示例7: action_gallery
/**
* Action: gallery
*/
public function action_gallery()
{
/** @var Model_Gallery $gallery */
$gallery_id = (int) $this->request->param('id');
$gallery = Model_Gallery::factory($gallery_id);
if (!$gallery->loaded()) {
throw new Model_Exception($gallery, $gallery_id);
}
// Are we approving pending images?
if ($this->request->action() == 'pending') {
// Can we see galleries with un-approved images?
Permission::required($gallery, Model_Gallery::PERMISSION_APPROVE_WAITING, self::$user);
// Can we see all of them and approve?
$approve = Permission::has($gallery, Model_Gallery::PERMISSION_APPROVE, self::$user);
// Handle images?
if ($_POST && Security::csrf_valid()) {
$pending = $gallery->find_images_pending($approve ? null : self::$user);
$images = (array) Arr::get($_POST, 'image_id');
$authors = array();
if (count($pending) && count($images)) {
foreach ($pending as $image) {
$action = Arr::Get($images, $image->id, 'wait');
switch ($action) {
case 'approve':
if ($approve) {
$author = $image->author();
//$gallery->image_count++;
$authors[$author['id']] = $author['username'];
$image->state(AutoModeler::STATE_LOADED);
$image->status = Model_Image::VISIBLE;
$image->save();
}
break;
case 'deny':
$gallery->remove('image', $image->id);
$gallery->image_count--;
$image->delete();
break;
}
}
// Admin actions
if ($approve) {
// Set default image if none set
if (!$gallery->default_image_id) {
$gallery->default_image_id = $gallery->images()->current()->id;
}
$gallery->update_copyright();
$gallery->updated = time();
}
$gallery->save();
// Redirect to normal gallery if all images approved/denied
if (!count($gallery->find_images_pending($approve ? null : self::$user))) {
$this->request->redirect(Route::model($gallery));
} else {
$this->request->redirect(Route::model($gallery, 'pending'));
}
}
}
} else {
Permission::required($gallery, Model_Gallery::PERMISSION_READ, self::$user);
}
// Build page
$this->view = View_Page::factory(__('Gallery'));
$this->_set_page_actions(Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_CREATE, self::$user));
$this->_set_gallery($gallery);
if (Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_UPDATE, self::$user)) {
$this->view->actions[] = array('link' => Route::model($gallery, 'update'), 'text' => '<i class="icon-refresh icon-white"></i> ' . __('Update gallery'));
}
// Share
if ($this->request->action() !== 'pending' && Kohana::$config->load('site.facebook')) {
Anqh::open_graph('title', __('Gallery') . ': ' . $gallery->name);
Anqh::open_graph('url', URL::site(Route::get('gallery')->uri(array('id' => $gallery->id, 'action' => '')), true));
Anqh::open_graph('description', __($gallery->image_count == 1 ? ':images image' : ':images images', array(':images' => $gallery->image_count)) . ' - ' . date('l ', $gallery->date) . Date::format(Date::DMY_SHORT, $gallery->date) . ($event ? ' @ ' . $event->venue_name : ''));
if ($event && ($image = $event->flyer_front())) {
Anqh::open_graph('image', URL::site($image->get_url('thumbnail'), true));
} else {
if ($image = $gallery->default_image()) {
Anqh::open_graph('image', URL::site($image->get_url('thumbnail'), true));
}
}
}
Anqh::share(true);
$this->view->add(View_Page::COLUMN_SIDE, $this->section_share());
// Event info
if ($event = $gallery->event()) {
// Event flyer
$this->view->add(View_Page::COLUMN_SIDE, $this->section_event_image($event));
// Event info
$this->view->add(View_Page::COLUMN_SIDE, $this->section_event_info($event));
}
// Pictures
$this->view->add(View_Page::COLUMN_MAIN, $this->section_gallery_thumbs($gallery, $this->request->action() == 'pending', isset($approve) ? $approve : null));
}
示例8: _edit_topic
/**
* Edit forum topic
*
* @param integer $area_id
* @param integer $topic_id
*
* @throws Model_Exception invalid area, invalid topic
* @throws InvalidArgumentException missing area and topic
*/
protected function _edit_topic($area_id = null, $topic_id = null)
{
$this->history = false;
$this->view = new View_Page();
if ($area_id && !$topic_id) {
// Start new topic
$mode = View_Forum_PostEdit::NEW_TOPIC;
/** @var Model_Forum_Private_Area|Model_Forum_Area $area */
$area = $this->private ? Model_Forum_Private_Area::factory($area_id) : Model_Forum_Area::factory($area_id);
if (!$area->loaded()) {
throw new Model_Exception($area, $area_id);
}
Permission::required($area, Model_Forum_Area::PERMISSION_POST, self::$user);
$this->view->title = HTML::chars($area->name);
if ($this->private) {
$topic = new Model_Forum_Private_Topic();
$post = new Model_Forum_Private_Post();
$cancel = Route::url('forum_area', array('id' => 'private', 'action' => ''));
$recipients = array();
} else {
$topic = new Model_Forum_Topic();
$post = new Model_Forum_Post();
$cancel = Route::model($area);
}
} else {
if ($topic_id) {
// Edit old topic
$mode = View_Forum_PostEdit::EDIT_TOPIC;
/** @var Model_Forum_Private_Topic|Model_Forum_Topic $topic */
$topic = $this->private ? Model_Forum_Private_Topic::factory($topic_id) : Model_Forum_Topic::factory($topic_id);
if (!$topic->loaded()) {
throw new Model_Exception($topic, $topic_id);
}
Permission::required($topic, Model_Forum_Topic::PERMISSION_UPDATE, self::$user);
// Build recipients list
if ($this->private) {
$recipients = $topic->find_recipient_names();
}
$this->view->title_html = Forum::topic($topic);
$cancel = Route::model($topic);
// Set actions
if (Permission::has($topic, Model_Forum_Topic::PERMISSION_DELETE, self::$user)) {
$this->view->actions[] = array('link' => Route::model($topic, 'delete') . '?' . Security::csrf_query(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete topic'), 'class' => 'btn btn-danger topic-delete');
}
} else {
throw new InvalidArgumentException('Topic and area missing');
}
}
$errors = array();
if ($_POST && Security::csrf_valid()) {
// Get recipients
if ($this->private) {
$post_recipients = array();
foreach (explode(',', Arr::get_once($_POST, 'recipients')) as $recipient) {
if ($user = Model_User::find_user_light(trim($recipient))) {
$post_recipients[$user['id']] = $user['username'];
}
}
// Make sure author is included
$post_recipients[self::$user->id] = self::$user->username;
}
if (isset($post)) {
// New topic
$post->post = $_POST['post'];
$post->forum_area_id = $area->id;
$post->author_id = self::$user->id;
$post->author_name = self::$user->username;
$post->author_ip = Request::$client_ip;
$post->author_host = Request::host_name();
$post->created = time();
try {
$post->is_valid();
} catch (Validation_Exception $e) {
$errors += $e->array->errors('validate');
}
$topic->author_id = self::$user->id;
$topic->author_name = self::$user->username;
$topic->name = $_POST['name'];
$topic->forum_area_id = $area->id;
$topic->created = time();
try {
$topic->is_valid();
} catch (Validation_Exception $e) {
$errors += $e->array->errors('validate');
}
// If no errors found, save models
if (empty($errors)) {
$topic->save();
// Recipients
if ($this->private) {
$topic->set_recipients($post_recipients);
//.........这里部分代码省略.........
示例9: action_unignore
/**
* Action: Remove from ignore
*/
public function action_unignore()
{
$this->history = false;
// Load user
$user = $this->_get_user();
Permission::required($user, Model_User::PERMISSION_IGNORE, self::$user);
if (Security::csrf_valid()) {
self::$user->delete_ignore($user);
}
$this->request->redirect(URL::user($user));
}
示例10: action_report
/**
* Action: report
*/
public function action_report()
{
$this->history = false;
$gallery_id = (int) $this->request->param('gallery_id');
$image_id = $this->request->param('id');
/** @var Model_Gallery $gallery */
$gallery = Model_Gallery::factory($gallery_id);
if (!$gallery->loaded()) {
throw new Model_Exception($gallery, $gallery_id);
}
/** @var Model_Image $image */
$image = Model_Image::factory($image_id);
if (!$image->loaded()) {
throw new Model_Exception($image, $image_id);
}
Permission::required($image, Model_Image::PERMISSION_REPORT);
$cancel_url = Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => ''));
// Handle report
if ($_POST && Security::csrf_valid()) {
$reason = trim(Arr::get($_POST, 'reason'));
Notification_Galleries::image_removal_request(Visitor::$user, $image, $reason ? $reason : null);
if ($this->_request_type === Controller::REQUEST_AJAX) {
$this->response->body(new View_Alert(__('Report filed.'), null, View_Alert::SUCCESS));
} else {
$this->request->redirect($cancel_url);
}
return;
}
$section = $this->section_image_report($image);
// Show only the form is AJAX
if ($this->_request_type === Controller::REQUEST_AJAX) {
$this->response->body($section);
return;
}
// Build page
$this->view = View_Page::factory(__('Report image'));
$this->view->actions[] = array('link' => $cancel_url, 'text' => __('Cancel'), 'class' => 'btn-inverse');
// Image
$this->view->add(View_Page::COLUMN_TOP, $this->section_image($image, $gallery, $cancel_url));
// Form
$this->view->add(View_Page::COLUMN_TOP, $section);
}
示例11: _edit_entry
/**
* Edit entry
*
* @param integer $entry_id
*
* @throws Model_Exception
*/
protected function _edit_entry($entry_id = null)
{
$this->history = false;
if ($entry_id) {
// Editing old
$entry = new Model_Blog_Entry($entry_id);
if (!$entry->loaded()) {
throw new Model_Exception($entry, $entry_id);
}
Permission::required($entry, Model_Blog_Entry::PERMISSION_UPDATE);
$cancel = Route::model($entry);
$this->view->title = __('Edit blog entry');
$entry->modified = time();
$entry->modify_count++;
} else {
// Creating new
$entry = new Model_Blog_Entry();
Permission::required($entry, Model_Blog_Entry::PERMISSION_CREATE);
$cancel = Request::back(Route::get('blogs')->uri(), true);
$newsfeed = true;
$this->view->title = __('New blog entry');
$entry->author_id = Visitor::$user->id;
$entry->created = time();
}
// Handle post
$errors = array();
if ($_POST && Security::csrf_valid()) {
try {
$entry->name = Arr::get($_POST, 'name');
$entry->content = Arr::get($_POST, 'content');
$entry->save();
// Newsfeed
if (isset($newsfeed) && $newsfeed) {
NewsfeedItem_Blog::entry(Visitor::$user, $entry);
}
$this->request->redirect(Route::model($entry));
} catch (Validation_Exception $e) {
$errors = $e->array->errors('validation');
}
}
// Form
$section = $this->section_entry_edit($entry);
$section->cancel = $cancel;
$section->errors = $errors;
$this->view->add(View_Page::COLUMN_CENTER, $section);
}
示例12: _edit_event
/**
* Edit event
*
* @param integer $event_id
*/
protected function _edit_event($event_id = null)
{
$this->history = false;
if ($event_id) {
// Editing old
$event = Model_Event::factory($event_id);
if (!$event->loaded()) {
throw new Model_Exception($event, $event_id);
}
Permission::required($event, Model_Event::PERMISSION_UPDATE, self::$user);
$cancel = Request::back(Route::model($event), true);
$this->view = View_Page::factory(HTML::chars($event->name));
// Set actions
if (Permission::has($event, Model_Event::PERMISSION_DELETE, self::$user)) {
$this->view->actions[] = array('link' => Route::model($event, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete event'), 'class' => 'btn-danger event-delete');
}
$edit = true;
} else {
// Creating new
$event = new Model_Event();
Permission::required($event, Model_Event::PERMISSION_CREATE, self::$user);
$cancel = Request::back(Route::get('events')->uri(), true);
$this->view = View_Page::factory(__('New event'));
$event->author_id = self::$user->id;
$event->created = time();
$edit = false;
}
// Handle post
if ($_POST && Security::csrf_valid()) {
// Handle venue
if ($venue_hidden = Arr::get($_POST, 'venue_hidden')) {
// Hidden events require only city
} else {
if ($venue_id = (int) Arr::get_once($_POST, 'venue_id')) {
// Old venue
$venue = Model_Venue::factory($venue_id);
} else {
if ($venue_name = Arr::get($_POST, 'venue_name')) {
// Check for duplicate venue
$venues = Model_Venue::factory()->find_by_name($venue_name);
if ($venues->count()) {
$city_name = strtolower(Arr::get($_POST, 'city_name'));
foreach ($venues as $venue_old) {
if (strtolower($venue_old->city_name) == $city_name) {
$venue = $venue_old;
break;
}
}
}
}
}
}
$post = Arr::intersect($_POST, Model_Event::$editable_fields);
if (isset($post['stamp_begin']['date']) && isset($post['stamp_end']['time'])) {
$post['stamp_end']['date'] = $post['stamp_begin']['date'];
}
$event->set_fields($post);
if (Arr::get($_POST, 'free')) {
$event->price = 0;
}
// Venue/location
$event->venue_hidden = (bool) $venue_hidden;
if ($venue_hidden) {
// Hidden events don't have a venue
$event->venue_id = null;
$event->venue_name = null;
} else {
if (isset($venue)) {
// Venue loaded
$event->venue_id = $venue->id;
$event->city_name = $venue->city_name;
} else {
if (!empty($venue_name)) {
// Create new venue
$venue = Model_Venue::factory();
$venue->name = Arr::get($_POST, 'venue_name');
$venue->address = Arr::get($_POST, 'address');
$venue->latitude = Arr::get($_POST, 'latitude');
$venue->longitude = Arr::get($_POST, 'longitude');
$venue->event_host = true;
$venue->author_id = self::$user->id;
$venue->city_name = $event->city_name;
try {
$venue->save();
$event->venue_id = $venue->id;
} catch (Validation_Exception $venue_validation) {
}
}
}
}
// Validate event
try {
$event->is_valid();
} catch (Validation_Exception $event_validation) {
}
//.........这里部分代码省略.........
示例13: _edit_track
/**
* Edit track.
*
* @param integer $track_id
*
* @throws Model_Exception
*/
protected function _edit_track($track_id = null)
{
$this->history = false;
if ($track_id) {
// Editing old
$track = new Model_Music_Track($track_id);
if (!$track->loaded()) {
throw new Model_Exception($track, $track_id);
}
Permission::required($track, Model_Music_Track::PERMISSION_UPDATE);
$cancel = Route::model($track);
$this->view = new View_Page(HTML::chars($track->name));
// Set actions
if (Permission::has($track, Model_Music_Track::PERMISSION_DELETE)) {
$this->view->actions[] = array('link' => Route::model($track, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="fa fa-trash-o"></i> ' . __('Delete'), 'class' => 'btn-danger music-delete');
}
} else {
// Creating new
$track = new Model_Music_Track();
Permission::required($track, Model_Music_Track::PERMISSION_CREATE);
$cancel = Request::back(Route::url('charts'), true);
$newsfeed = true;
$this->view = new View_Page($this->request->param('music') === 'mixtape' ? __('New mixtape') : __('New track'));
$track->author_id = Visitor::$user->id;
$track->type = $this->request->param('music') === 'mixtape' ? Model_Music_Track::TYPE_MIX : Model_Music_Track::TYPE_TRACK;
$track->created = time();
}
// Handle post
$errors = array();
if ($_POST && Security::csrf_valid()) {
try {
$track->set_fields(Arr::intersect($_POST, Model_Music_Track::$editable_fields));
$track->save();
// Set tags
$track->set_tags(Arr::get($_POST, 'tag'));
// Newsfeed
if (isset($newsfeed) && $newsfeed) {
NewsfeedItem_Music::track(Visitor::$user, $track);
// Create forum topic
if ($track->add_forum_topic()) {
Visitor::$user->post_count++;
Visitor::$user->save();
}
}
$this->request->redirect(Route::model($track));
} catch (Validation_Exception $e) {
$errors = $e->array->errors('validation');
}
}
// Form
$section = $this->section_track_edit($track);
$section->cancel = $cancel;
$section->errors = $errors;
$this->view->add(View_Page::COLUMN_TOP, $section);
}
示例14: action_settings
/**
* Action: settings
*/
public function action_settings()
{
$this->history = false;
$user = $this->_get_user();
Permission::required($user, Model_User::PERMISSION_UPDATE, self::$user);
// Set generic page parameters
$this->_set_page($user);
// Handle post
$errors = array();
if ($_POST && Security::csrf_valid()) {
$user->set(Arr::extract($_POST, Model_User::$editable_fields));
// GeoNames
if ($_POST['city_id'] && ($city = Geo::find_city((int) $_POST['city_id']))) {
$user->city = $city;
}
$user->modified = time();
try {
$user->save();
$this->request->redirect(URL::user($user));
} catch (Validate_Exception $e) {
$errors = $e->array->errors('validation');
}
}
// Build form
$form = array('values' => $user, 'errors' => $errors, 'cancel' => URL::user($user), 'hidden' => array('city_id' => $user->city ? $user->city->id : 0, 'latitude' => $user->latitude, 'longitude' => $user->longitude), 'groups' => array('basic' => array('header' => __('Basic information'), 'fields' => array('name' => array(), 'gender' => array('input' => 'radio'), 'dob' => array('pretty_format' => 'j.n.Y'), 'title' => array(), 'description' => array('attributes' => array('rows' => 5)))), 'contact' => array('header' => __('Contact information'), 'fields' => array('email' => array(), 'homepage' => array(), 'address_street' => array(), 'address_zip' => array(), 'address_city' => array())), 'forum' => array('header' => __('Forum settings'), 'fields' => array('signature' => array('attributes' => array('rows' => 5))))));
Widget::add('main', View_Module::factory('form/anqh', array('form' => $form)));
// Autocomplete
$this->autocomplete_city('address_city', 'city_id');
// Date picker
$options = array('changeMonth' => true, 'changeYear' => true, 'dateFormat' => 'd.m.yy', 'defaultDate' => date('j.n.Y', $user->dob), 'dayNames' => array(__('Sunday'), __('Monday'), __('Tuesday'), __('Wednesday'), __('Thursday'), __('Friday'), __('Saturday')), 'dayNamesMin' => array(__('Su'), __('Mo'), __('Tu'), __('We'), __('Th'), __('Fr'), __('Sa')), 'firstDay' => 1, 'monthNames' => array(__('January'), __('February'), __('March'), __('April'), __('May'), __('June'), __('July'), __('August'), __('September'), __('October'), __('November'), __('December')), 'monthNamesShort' => array(__('Jan'), __('Feb'), __('Mar'), __('Apr'), __('May'), __('Jun'), __('Jul'), __('Aug'), __('Sep'), __('Oct'), __('Nov'), __('Dec')), 'nextText' => __('»'), 'prevText' => __('«'), 'showWeek' => true, 'showOtherMonths' => true, 'weekHeader' => __('Wk'), 'yearRange' => '1900:+0');
Widget::add('foot', HTML::script_source('$("#field-dob").datepicker(' . json_encode($options) . ');'));
// Maps
Widget::add('foot', HTML::script_source('
$(function() {
$("#fields-contact ul").append("<li><div id=\\"map\\">' . __('Loading map..') . '</div></li>");
$("#map").googleMap(' . ($user->latitude ? json_encode(array('marker' => true, 'lat' => $user->latitude, 'long' => $user->longitude)) : '') . ');
$("input[name=address_street], input[name=address_city]").blur(function(event) {
var address = $("input[name=address_street]").val();
var city = $("input[name=address_city]").val();
if (address != "" && city != "") {
var geocode = address + ", " + city;
geocoder.geocode({ address: geocode }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK && results.length) {
map.setCenter(results[0].geometry.location);
$("input[name=latitude]").val(results[0].geometry.location.lat());
$("input[name=longitude]").val(results[0].geometry.location.lng());
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
}
});
}
});
});
'));
}
示例15: _edit_venue
/**
* Edit venue
*
* @param integer $venue_id
*/
protected function _edit_venue($venue_id = null)
{
$this->history = false;
$edit = true;
if ($venue_id) {
// Editing old
$venue = Model_Venue::factory($venue_id);
if (!$venue->loaded()) {
throw new Model_Exception($venue, $venue_id);
}
Permission::required($venue, Model_Venue::PERMISSION_UPDATE);
$cancel = Route::model($venue);
$this->view = View_Page::factory($venue->name);
// Modified timestamp
$venue->modified = time();
// Set actions
if (Permission::has($venue, Model_Venue::PERMISSION_DELETE)) {
$this->view->actions[] = array('link' => Route::model($venue, 'delete') . '?' . Security::csrf_query(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete venue'), 'class' => 'btn btn-danger venue-delete');
}
} else {
// Creating new
$edit = false;
$venue = Model_Venue::factory();
$venue->author_id = Visitor::$user->id;
$cancel = Route::url('venues');
$this->view = View_Page::factory(__('New venue'));
}
// Handle post
$errors = array();
if ($_POST && Security::csrf_valid()) {
$venue->set_fields(Arr::intersect($_POST, Model_Venue::$editable_fields));
try {
$venue->save();
$edit ? NewsfeedItem_Venues::venue_edit(Visitor::$user, $venue) : NewsfeedItem_Venues::venue(Visitor::$user, $venue);
$this->request->redirect(Route::model($venue));
} catch (Validation_Exception $e) {
$errors = $e->array->errors('validation');
}
}
$section = $this->section_venue_edit($venue);
$section->errors = $errors;
$section->cancel = $cancel;
$this->view->add(View_Page::COLUMN_TOP, $section);
}