本文整理汇总了PHP中view::ajaxError方法的典型用法代码示例。如果您正苦于以下问题:PHP view::ajaxError方法的具体用法?PHP view::ajaxError怎么用?PHP view::ajaxError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类view
的用法示例。
在下文中一共展示了view::ajaxError方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: template
public function template()
{
// Get URI vars
$templateID = (int) uri::segment(3);
// Load templates model
loader::model('messages/templates', array(), 'messages_templates_model');
// Get template
$template = $this->messages_templates_model->getTemplate($templateID, false);
if ($template) {
view::ajaxResponse(array('subject' => $template['subject'], 'message' => $template['message']));
} else {
view::ajaxError(__('no_template', 'messages_templates'), 2000);
}
}
示例2: vote
public function vote()
{
// Is user logged in?
if (!users_helper::isLoggedin()) {
view::ajaxError(__('no_login', 'system_info'), 403);
}
// Get vars
$resource = input::post_get('resource');
$itemID = (int) input::post_get('item_id');
$score = (int) input::post_get('score');
// Get resource ID
$resourceID = config::item('resources', 'core', $resource, 'resource_id');
if (!$resourceID || !$itemID || $score < 1 || $score > 5) {
return false;
}
// Load votes model
loader::model('comments/votes');
// Get resource item and vote if exists
$item = $this->votes_model->getResourceVote($resource, $itemID);
// Do resource or vote exist?
if (!$item || $item['post_date']) {
return false;
}
// Save vote
if (!$this->votes_model->saveVote($resource, isset($item['user_id']) ? $item['user_id'] : 0, $itemID, $score)) {
if (!validate::getTotalErrors()) {
view::setError(__('save_error', 'system'));
}
return false;
}
$rating = number_format(($item['total_score'] + $score) / ($item['total_votes'] + 1), 2);
$params = array('resource' => $resource, 'itemID' => $itemID, 'votes' => $item['total_votes'] + 1, 'score' => $item['total_score'], 'rating' => $rating, 'voted' => $score, 'date' => date_helper::now());
$output = view::load('comments/rating', $params, true);
view::ajaxResponse($output);
}
示例3: _saveMessage
protected function _saveMessage($userID)
{
// Is user logged in?
if (!users_helper::isLoggedin()) {
return false;
}
if ($userID) {
// Get user
if (!($user = $this->users_model->getUser($userID)) || !$user['active'] || !$user['verified']) {
return false;
}
// Does user have permission to view this user group/type?
if (!in_array($user['group_id'], session::permission('users_groups_browse', 'users')) || !in_array($user['type_id'], session::permission('users_types_browse', 'users'))) {
return false;
} elseif (!$this->users_model->getPrivacyAccess($user['user_id'], isset($user['config']['privacy_profile']) ? $user['config']['privacy_profile'] : 1)) {
return false;
} elseif (!session::permission('messages_post', 'timeline') || !$this->users_model->getPrivacyAccess($user['user_id'], isset($user['config']['privacy_timeline_messages']) ? $user['config']['privacy_timeline_messages'] : 1, false)) {
return false;
}
} else {
$userID = session::item('user_id');
}
// Load messages model
loader::model('timeline/messages', array(), 'timeline_messages_model');
// Create rules
$rules = array('message' => array('label' => __('message', 'timeline'), 'rules' => array('trim', 'required', 'min_length' => config::item('message_min_length', 'timeline'), 'max_length' => config::item('message_max_length', 'timeline'), 'callback__is_messages_delay')));
// Assign rules
validate::setRules($rules);
// Validate fields
if (!validate::run()) {
$output = view::load('timeline/post', array('user' => $user), true);
view::ajaxError($output);
}
// Get message
$message = input::post('message');
// Save message
if (!($messageID = $this->timeline_messages_model->saveMessage(0, $message, $userID))) {
if (!validate::getTotalErrors()) {
view::setError(__('save_error', 'system'));
}
return false;
}
$actions = $this->timeline_model->getActions($userID, 0, 0, 1);
$output = view::load('timeline/actions', array('actions' => $actions), true);
view::ajaxResponse($output);
}
示例4: _uploadPicture
protected function _uploadPicture()
{
// Create rules
$rules = array('file' => array('label' => __('file_select', 'system_files'), 'rules' => array('required_file' => 'file')));
// Assign rules
validate::setRules($rules);
// Validate form values
if (!validate::run()) {
return false;
}
// Thumbnails config
$thumbs = array(array('suffix' => 'x'), array('dimensions' => config::item('picture_dimensions', 'users'), 'method' => 'preserve', 'suffix' => ''), array('dimensions' => config::item('picture_dimensions_p', 'users'), 'method' => 'crop', 'suffix' => 'p'), array('dimensions' => config::item('picture_dimensions_l', 'users'), 'method' => 'crop', 'suffix' => 'l'), array('dimensions' => config::item('picture_dimensions_t', 'users'), 'method' => 'crop', 'suffix' => 't'));
// Upload picture
if (!($fileID = $this->storage_model->upload('user', session::item('user_id'), 'file', 'jpg|jpeg|gif|png', config::item('picture_max_size', 'users'), config::item('picture_dimensions_max', 'users'), $thumbs))) {
if (input::isAjaxRequest()) {
view::ajaxError(config::item('devmode', 'system') ? $this->storage_model->getError() : __('file_upload_error', 'system_files'));
} else {
validate::setFieldError('file', config::item('devmode', 'system') ? $this->storage_model->getError() : __('file_upload_error', 'system_files'));
}
return false;
}
// Delete old picture if it exists
if (session::item('picture_id')) {
// Delete picture
$this->users_model->deletePicture(session::item('user_id'), session::item('picture_id'), false);
}
// Save new picture ID
if (!$this->users_model->savePicture(session::item('user_id'), $fileID)) {
if (input::isAjaxRequest()) {
view::ajaxError(__('save_error', 'system'));
} else {
validate::setFieldError('file', __('save_error', 'system'));
return false;
}
}
// Was this an ajax request?
if (input::isAjaxRequest()) {
view::ajaxResponse(array('redirect' => html_helper::siteURL(session::item('slug'))));
}
// Success
view::setInfo(__('picture_uploaded', 'users_picture'));
router::redirect(session::item('slug'));
}
示例5: _uploadPicture
protected function _uploadPicture($adID, $ad)
{
// Create rules
$rules = array('file' => array('label' => __('file_select', 'system_files'), 'rules' => array('required_file' => 'file')));
// Assign rules
validate::setRules($rules);
// Validate form values
if (!validate::run()) {
return false;
}
// Thumbnails config
$thumbs = array(array('suffix' => 'x'), array('dimensions' => config::item('picture_dimensions', 'classifieds'), 'method' => 'preserve', 'suffix' => ''), array('dimensions' => config::item('picture_dimensions_t', 'classifieds'), 'method' => 'crop', 'suffix' => 't'));
// Upload picture
if (!($fileID = $this->storage_model->upload('classified_picture', session::item('user_id'), 'file', 'jpg|jpeg|gif|png', config::item('picture_max_size', 'classifieds'), config::item('picture_dimensions_max', 'classifieds'), $thumbs))) {
if (input::isAjaxRequest()) {
view::ajaxError(config::item('devmode', 'system') ? $this->storage_model->getError() : __('file_upload_error', 'system_files'));
} else {
validate::setFieldError('file', config::item('devmode', 'system') ? $this->storage_model->getError() : __('file_upload_error', 'system_files'));
return false;
}
}
// Extras
$extra = array();
// Save picture file
if (!($pictureID = $this->classifieds_pictures_model->savePictureFile($fileID, $adID, $ad, $extra))) {
if (input::isAjaxRequest()) {
view::ajaxError(__('save_error', 'system'));
} else {
validate::setFieldError('file', __('save_error', 'system'));
return false;
}
}
// Update current album counters
$ad[session::permission('pictures_approve', 'classifieds') ? 'total_pictures' : 'total_pictures_i']++;
// Update album's modification date
$this->classifieds_model->updateModifyDate($adID);
// Was this an ajax request?
if (input::isAjaxRequest()) {
//view::ajaxResponse(__('picture_uploaded', 'pictures'));
view::ajaxResponse(array('redirect' => html_helper::siteURL('classifieds/pictures/index/' . $adID)));
}
// Success
view::setInfo(__('picture_uploaded', 'classifieds'));
router::redirect('classifieds/pictures/index/' . $adID);
}
示例6: _uploadPicture
protected function _uploadPicture()
{
if (input::files('file')) {
// Create rules
$rules = array('file' => array('label' => __('file_select', 'system_files'), 'rules' => array('required_file' => 'file')));
// Assign rules
validate::setRules($rules);
// Validate form values
if (!validate::run()) {
return false;
}
// Resize config
$thumbs = array(array('suffix' => 'x'), array('dimensions' => config::item('picture_dimensions', 'users'), 'method' => 'preserve', 'suffix' => ''), array('dimensions' => config::item('picture_dimensions_p', 'users'), 'method' => 'crop', 'suffix' => 'p'), array('dimensions' => config::item('picture_dimensions_l', 'users'), 'method' => 'crop', 'suffix' => 'l'), array('dimensions' => config::item('picture_dimensions_t', 'users'), 'method' => 'crop', 'suffix' => 't'));
// Upload picture
if (!($fileID = $this->storage_model->upload('user', 0, 'file', 'jpg|jpeg|gif|png', config::item('picture_max_size', 'users'), config::item('picture_dimensions_max', 'users'), $thumbs))) {
if (input::isAjaxRequest()) {
view::ajaxError(config::item('devmode', 'system') ? $this->storage_model->getError() : __('file_upload_error', 'system_files'));
} else {
validate::setFieldError('file', config::item('devmode', 'system') ? $this->storage_model->getError() : __('file_upload_error', 'system_files'));
return false;
}
}
// Delete old picture if it exists
if (session::item('picture', 'signup', 'file_id')) {
$this->storage_model->deleteFiles(session::item('picture', 'signup', 'file_id'), 5);
}
// Get file details
$file = $this->storage_model->getFile($fileID);
// Set user session data
session::set(array('picture' => $file), '', 'signup');
// Was this an ajax request?
if (input::isAjaxRequest()) {
view::ajaxResponse(array('redirect' => html_helper::siteURL('users/signup/picture')));
}
router::redirect('users/signup/picture');
}
// Redirect to the next step
$this->_nextStep();
}