예제 #1
0
 public function newPageAction()
 {
     $form = new Application_Form_NewPageForm();
     $this->view->form = $form;
     $results = $this->url->getUrls();
     $this->view->page_url = $results->page_url;
     if ($this->user_session->msg != null) {
         $this->view->msg = $this->user_session->msg;
         $this->user_session->msg = null;
     }
     if (!$this->_request->isPost()) {
         return;
     }
     $formData = $this->_request->getPost();
     if (!$form->isValid($formData)) {
         return;
     }
     //$formData['is_in_draft'] = $formData['submit'];
     //For Images
     $file_name = NULL;
     try {
         $image = $_FILES['image']['name'];
         $random = rand(10, 10000);
         $time = time() + 7 * 24 * 60 * 60;
         $file_name = $time . $random . $image;
         $formData["image"] = $file_name;
         move_uploaded_file($_FILES["image"]['tmp_name'], SYSTEM_PATH . "/images/user/pages/" . $file_name);
         $thumb = new Application_Model_Thumbnail(SYSTEM_PATH . "/images/user/pages/" . $file_name);
         $thumb->resize(500, 500);
         $thumb->save(SYSTEM_PATH . '/images/user/pages/500X500/' . $file_name);
         $thumb->resize(200, 200);
         $thumb->save(SYSTEM_PATH . '/images/user/pages/200X200/' . $file_name);
     } catch (Zend_File_Transfer_Exception $e) {
         throw new Exception('Bad data: ' . $e->getMessage());
     }
     $formData['user_id'] = $this->user_session->user_id;
     $formData['date_created'] = date("Y-m-d H:i:s");
     $formData['date_published'] = date("Y-m-d H:i:s");
     //$slug= $formData['url_slug'];
     //$formData['url_slug']= str_replace("-","", $slug);
     //check from database if the slug is already in db
     $data = array("url" => $formData['url_slug']);
     $data["url"] = $formData['url_slug'];
     if ($this->page->checkPageSlug($data)) {
         $this->view->msg = "<div class='alert alert-danger'>Url Slug Is Already Exist. Please change to another.</div>";
         return;
     }
     if ($formData['submit'] == "0") {
         $formData['is_in_draft'] = 0;
         $formData['draft_content'] = $formData['description'];
     } else {
         $formData['is_in_draft'] = 1;
         $formData['draft_content'] = $formData['description'];
         $formData['description'] = "";
     }
     $result = $this->page->addPage($formData);
     $this->view->msg = $result;
     //clear all form fields
     $form->reset();
 }