Пример #1
0
 public function uploadAction()
 {
     $request = $this->getRequest();
     if (!JO_Session::get('user_id')) {
         JO_Session::set('msg_error', 'You must be logged to view your collections');
         $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=login'));
     }
     $model_images = new Model_Images();
     if ($request->isPost()) {
         $image = $request->getFile('file_upload');
         $public = $request->getPost('publically_visible');
         $id = Model_Collections::add(array('name' => $request->getPost('name') ? $request->getPost('name') : $this->translate('Bookmark Collection'), 'description' => $request->getPost('description'), 'publically_visible' => $public ? 'true' : 'false'));
         if ($image and $id) {
             $users_path = '/collections/' . date('Y/m') . '/' . $id . '/';
             $upload_folder = realpath(BASE_PATH . '/uploads');
             $upload_folder .= $users_path;
             $upload = new JO_Upload();
             $upload->setFile($image)->setExtension(array('.jpg', '.jpeg', '.png', '.gif'))->setUploadDir($upload_folder);
             $new_name = md5(time() . serialize($image));
             if ($upload->upload($new_name)) {
                 $info = $upload->getFileInfo();
                 if ($info) {
                     $file_path = $users_path . $info['name'];
                     Model_Collections::editImage($id, $file_path);
                 } else {
                     JO_Session::set('msg_error', $this->translate('There was an unexpected error with uploading the file'));
                 }
             }
         }
         if ($id && $request->issetPost('item_id')) {
             $itemID = $request->getPost('item_id');
             Model_Collections::bookmark($itemID, $id);
             JO_Session::set('msg_success', 'You have successfully create collection and this item has been added to your collection');
             $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=items&item_id=' . $itemID));
         }
         if ($id) {
             JO_Session::set('msg_success', 'You have successfully create collection.');
         }
         $url = WM_Router::create($request->getBaseUrl() . '?controller=users&action=collections&username='******'username')) . '/public/' . ($public ? '1' : '0'));
         $this->redirect($url);
     }
 }
Пример #2
0
 public function add_to_collectionAction()
 {
     $request = $this->getRequest();
     if (!JO_Session::get('user_id')) {
         JO_Session::set('msg_error', $this->translate('You must be logged to change your profile'));
         $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=login'));
     }
     if ($request->isPost() && $request->issetPost('collection_id')) {
         $collectionID = $request->getPost('collection_id');
         $itemID = $request->getPost('item_id');
         Model_Collections::bookmark($itemID, $collectionID);
         JO_Session::set('msg_success', $this->translate('This item has been added to your collection'));
         $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=items&item_id=' . $itemID));
     } else {
         JO_Session::set('msg_error', $this->translate('You need to create a collection to add the item to'));
         $this->redirect($request->getServer('HTTP_REFERER'));
     }
 }