Beispiel #1
0
 public function upload()
 {
     // Is user logged in?
     if (!users_helper::isLoggedin()) {
         router::redirect('users/login');
     } elseif (!session::permission('pictures_post', 'classifieds')) {
         view::noAccess(session::item('slug'));
     }
     // Get URI vars
     $adID = (int) uri::segment(4);
     // Get album
     if (!$adID || !($ad = $this->classifieds_model->getAd($adID, 'in_view')) || $ad['user_id'] != session::item('user_id')) {
         view::setError(__('no_ad', 'classifieds'));
         router::redirect('classifieds');
     }
     // Did user reach the max pictures limit?
     if (session::permission('pictures_limit', 'classifieds') && session::permission('pictures_limit', 'classifieds') <= $ad['total_pictures'] + $ad['total_pictures_i']) {
         view::setError(__('picture_limit_reached', 'classifieds', array('%limit%' => session::permission('pictures_limit', 'classifieds'))));
         router::redirect('classifieds/view/' . $adID . '/' . text_helper::slug($ad['data_title'], 100));
     }
     // Set limit
     $limit = !session::permission('pictures_limit', 'classifieds') || session::permission('pictures_limit', 'classifieds') > config::item('picture_upload_limit', 'classifieds') ? config::item('picture_upload_limit', 'classifieds') : session::permission('pictures_limit', 'classifieds');
     $limit = session::permission('pictures_limit', 'classifieds') && $ad['total_pictures'] + $ad['total_pictures_i'] + $limit > session::permission('pictures_limit', 'classifieds') ? session::permission('pictures_limit', 'classifieds') - $ad['total_pictures'] - $ad['total_pictures_i'] : $limit;
     // Process form values
     if (input::files('file')) {
         $this->_uploadPicture($adID, $ad);
     }
     // Assign vars
     view::assign(array('adID' => $adID, 'ad' => $ad, 'limit' => $limit));
     // Add storage includes
     //$this->storage_model->includeExternals();
     // Set title
     view::setTitle(__('pictures_new', 'classifieds'));
     // Set trail
     view::setTrail(session::item('slug'), __('my_profile', 'system_navigation'));
     view::setTrail('classifieds/manage', __('classifieds', 'system_navigation'));
     view::setTrail('classifieds/view/' . $ad['ad_id'] . '/' . text_helper::slug($ad['data_title'], 100), __('ad_view', 'classifieds'), array('side' => true));
     // Load view
     view::load('classifieds/pictures/upload');
 }
Beispiel #2
0
 public function picture()
 {
     // Is user loggedin ?
     if (!users_helper::isLoggedin()) {
         router::redirect('users/login');
     }
     // Process form values
     if (input::files('file')) {
         $this->_uploadPicture();
     } elseif (uri::segment(4) == 'rotate' && session::item('picture_id')) {
         $this->_rotatePicture();
     } elseif (uri::segment(4) == 'delete' && session::item('picture_id')) {
         $this->_deletePicture();
     }
     // Set title
     view::setTitle(__('picture_change', 'users_picture'));
     // Set trail
     view::setTrail(session::item('slug'), __('my_profile', 'system_navigation'));
     // Load view
     view::load('users/profile/picture');
 }
Beispiel #3
0
 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();
 }