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); } }
public function cities() { $stateID = uri::segment(3); $data = array(); if (input::post('title') == 'any') { $data[''] = __('any', 'system', array(), array(), false); } else { $data[''] = __('select', 'system', array(), array(), false); } foreach (geo_helper::getCities($stateID) as $id => $name) { $data[$id . ' '] = $name; } view::ajaxResponse($data); }
public function recent() { // Load view if (input::isAjaxRequest()) { // Get notices $notices = $this->timeline_notices_model->getNotices(session::item('user_id'), 0, 5); $output = view::load('timeline/notices/recent', array('notices' => $notices), true); // Dow we have new notifications? if (session::item('total_notices_new')) { // Reset new notifications counter $this->timeline_notices_model->resetCounter(); } view::ajaxResponse($output); } }
public function update() { // Get URI vars $plugin = uri::segment(5); // Get plugins if (!($plugins = $this->recalculate_model->getPlugins())) { view::setInfo(__('no_plugins', 'system_plugins')); router::redirect('cp/system/config/system'); } // Get captcha if (!$plugin || !isset($plugins[$plugin])) { view::setError(__('no_plugin', 'utilities_counters')); router::redirect('cp/utilities/counters'); } // Load plugin model $model = loader::model($plugin . '/' . $plugin, array(), null); // Update counters $result = $model->updateDbCounters(); // Do we have redirect uri? if (isset($result['output']) && isset($result['redirect'])) { $result['redirect'] = $result['redirect'] ? 'update/' . $plugin . '/' . $result['redirect'] : ''; $result['output'] .= '<br/>' . __('progress_redirect', 'utilities_counters', array(), array('%' => html_helper::anchor('cp/utilities/counters/' . $result['redirect'], '\\1'))); if (!$result['redirect']) { view::setInfo(__('progress_done', 'utilities_counters', array('%1' => $plugins[$plugin]))); } // Assign vars view::assign(array('output' => $result['output'], 'redirect' => $result['redirect'])); if (input::isAjaxRequest()) { view::ajaxResponse(array('output' => $result['output'], 'redirect' => $result['redirect'])); } } // Set title view::setTitle(__('utilities_counters_manage', 'system_navigation') . ' - ' . $plugins[$plugin]); // Load view view::load('cp/utilities/counters/update'); }
public function send() { // Get URI vars $newsletterID = (int) uri::segment(5); $counter = (int) uri::segment(6, 0); $test = uri::segment(7) == 'test' ? 1 : 0; $step = config::item('emails_batch', 'newsletters'); // Get newsletter if (!$newsletterID || !($newsletter = $this->newsletters_model->getNewsletter($newsletterID, false))) { view::setError(__('no_newsletter', 'newsletters')); router::redirect('cp/content/newsletters'); } // Do we have recipients? if (!$newsletter['total_users']) { router::redirect('cp/content/newsletters/recipients/' . $newsletterID); } // Is this the first step? if (!$test && !$counter) { // Update total user count $searchID = $this->search_model->searchData('profile', array(), $newsletter['params']['conditions'], $newsletter['params']['values'], array('type_id' => isset($newsletter['params']['values']['type_id']) ? $newsletter['params']['values']['type_id'] : 0)); // Do we have any search terms? if ($searchID == 'no_terms' || $searchID == 'no_results' || !($search = $this->search_model->getSearch($searchID))) { router::redirect('cp/content/newsletters/recipients/' . $newsletterID); } // Did total user count change? if ($search['results'] != $newsletter['total_users']) { $newsletter = array('total_users' => $search['results']); $this->newsletters_model->saveNewsletter($newsletterID, $newsletter); } } elseif ($test && !config::item('email_test', 'newsletters')) { view::setError(__('newsletters_test_none', 'newsletters', array(), array('%' => html_helper::anchor('cp/system/config/newsletters', '\\1')))); router::redirect('cp/content/newsletters/review/' . $newsletterID); } // Load email library loader::library('email'); // Is this a test? if ($test) { $this->email->sendEmail(config::item('email_test', 'newsletters'), $newsletter['subject'], $newsletter['message_text'], $newsletter['message_html']); view::setInfo(__('newsletter_sent', 'newsletters')); router::redirect('cp/content/newsletters/review/' . $newsletterID); } // Get users $users = $this->users_model->getUsers('in_view', isset($newsletter['params']['values']['type_id']) ? $newsletter['params']['values']['type_id'] : 0, $newsletter['params']['conditions']['columns'], $newsletter['params']['conditions']['items'], false, $counter . ',' . $step); foreach ($users as $user) { if (!input::demo(0)) { $this->email->sendEmail($user['email'], $newsletter['subject'], $newsletter['message_text'], $newsletter['message_html'], $user); } $counter++; } // Do we have any users? if (!$users) { view::setInfo(__('newsletter_sent', 'newsletters')); $next = ''; } else { $next = $counter; } // Update total sent $this->newsletters_model->saveNewsletter($newsletterID, array('total_sent' => $next ? $counter : 0)); // Did total number of users change? if ($counter > $newsletter['total_users'] || !$next && $counter < $newsletter['total_users']) { $newsletter['total_users'] = $counter; $this->newsletters_model->saveNewsletter($newsletterID, array('total_users' => $counter)); } $message = __('newsletter_sending_status', 'newsletters', array('%1' => $counter, '%2' => $newsletter['total_users'])); $message .= '<br/>' . __('newsletter_sending_redirect', 'newsletters', array(), array('%' => html_helper::anchor('cp/content/newsletters/send/' . $newsletterID . '/' . $next, '\\1'))); // Assign vars view::assign(array('newsletterID' => $newsletterID, 'newsletter' => $newsletter, 'counter' => $counter, 'redirect' => $next, 'output' => $message)); if (input::isAjaxRequest()) { view::ajaxResponse(array('output' => $message, 'redirect' => $next)); } // Set title view::setTitle(__('newsletter_sending', 'newsletters')); // Set trail view::setTrail('cp/content/newsletters/send/' . $newsletterID, __('newsletter_send', 'newsletters') . ' - ' . text_helper::entities($newsletter['subject'])); // Load view view::load('cp/content/newsletters/send'); }
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); }
protected function _deleteAction($actionID) { // Is user logged in? if (!users_helper::isLoggedin()) { return false; } // Validate message ID if (!$actionID || $actionID <= 0) { return false; } // Get action $action = $this->timeline_model->getAction($actionID); // Does action exist and valid for deletion? if (!$action || $action['user_id'] != session::item('user_id') && $action['poster_id'] != session::item('user_id')) { return false; } // Delete action if (!$this->timeline_model->deleteAction($actionID)) { return false; } view::ajaxResponse('ok'); }
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')); }
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); }
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(); }