Esempio n. 1
0
 public function actionEdit()
 {
     try {
         $error = "";
         $this->get();
         $tmp_id = 0;
         if (empty($this->get['id']) || !($id = (int) $this->get['id'])) {
             /**если нет id то берем если создана временную запись, либо, создаем новую временную**/
             if (!($tmp_id = $this->model->getBy("0", "status"))) {
                 $_save = array("title" => "tmp title", "status" => "0");
                 if (!($tmp_id = $this->model->insert($_save))) {
                     echo "Ошибка при создании временного поста";
                     $this->endApp(true);
                 }
             }
             if (is_array($tmp_id)) {
                 $tmp_id = $tmp_id['id'];
             }
             $this->redirect("/admin-zone/page/edit?id=" . $tmp_id);
             $this->endApp(true);
         }
         $data = array("title" => "", "url" => "", "description" => "", "text" => "", "status" => "1");
         $require = array_keys($data);
         $res = $this->model->get($id);
         if (!$res) {
             $error = "Нет поста с таким id";
             $this->assignSession("error", $error);
             $this->redirect("/admin-zone/page/");
         }
         $this->post();
         //получим $_POST в $this->post;
         if (!empty($this->post['page'])) {
             $data = $this->post['page'];
             $_save = $this->valid->is_empty($data, $require);
             $_save['text_preview'] = myFunc::getShort($_save['text'], 500);
             $_save['create_time'] = time();
             $_save['update_time'] = time();
             $_save['author_id'] = $this->user->data['id'];
             $_save['main_pic'] = "";
             if ($this->model->save($id, $_save)) {
                 $this->assignSession("info", "Сохранено!");
                 $this->redirect("/admin-zone/page/");
             }
         }
         $data = $res;
     } catch (Exception $e) {
         $error = $e->getMessage();
     }
     $this->activateImgUp($id, "page");
     $this->addAdminJS("page-edit.js");
     $this->assign("data", $data);
     $this->assign("error", $error);
     $this->render("admin/page/item.tpl");
 }
Esempio n. 2
0
 public function actionEdit()
 {
     try {
         $error = "";
         $this->get();
         $tmp_id = 0;
         if (empty($this->get['id']) || !($id = (int) $this->get['id'])) {
             /**если нет id то берем если создана временную запись, либо, создаем новую временную**/
             if (!($tmp_id = $this->model->getBy("0", "status"))) {
                 $_save = array("title" => "tmp title", "status" => "0");
                 if (!($tmp_id = $this->model->insert($_save))) {
                     echo "Ошибка при создании временного поста";
                     $this->endApp(true);
                 }
             }
             if (is_array($tmp_id)) {
                 $tmp_id = $tmp_id['id'];
             }
             $this->redirect("/admin-zone/post/edit?id=" . $tmp_id);
             $this->endApp(true);
         }
         $data = array("title" => "", "url" => "", "text" => "", "status" => "1", "category_id" => "");
         $require = array_keys($data);
         $res = $this->model->get($id);
         if (!$res) {
             $error = "Нет поста с таким id";
             $this->assignSession("error", $error);
             $this->redirect("/admin-zone/post/");
         }
         $this->post();
         //получим $_POST в $this->post;
         if (!empty($this->post['post'])) {
             $data = $this->post['post'];
             $_save = $this->valid->is_empty($data, $require);
             if (!empty($data["description"])) {
                 $_save['description'] = $data["description"];
             }
             $_save['text_preview'] = myFunc::getShort($_save['text'], 500);
             $_save['create_time'] = time();
             $_save['update_time'] = time();
             $_save['author_id'] = $this->user->data['id'];
             $_save['main_pic'] = "";
             if ($this->model->save($id, $_save)) {
                 $tmp_info = "Сохранено!";
                 if (!empty($data['to_ping']) && (int) $data['status'] == 2) {
                     myFunc::pingPostUrl($_save['url']);
                     $tmp_info .= " Пинг отправлен.";
                 }
                 myFunc::generSitemap($this->db);
                 $this->assignSession("info", $tmp_info);
                 $this->redirect("/admin-zone/post/");
             }
         }
         $data = $res;
     } catch (Exception $e) {
         $error = $e->getMessage();
     }
     $this->activateImgUp($id, "post");
     //activating img uploader
     $this->assign("cat_list", $this->getCats());
     $this->addAdminJS("edit.js");
     $this->assign("data", $data);
     $this->assign("error", $error);
     $this->render("admin/post/item.tpl");
 }
Esempio n. 3
0
 public function actionSaveimage()
 {
     try {
         $res = array();
         $this->get();
         if (empty($_FILES['my-pic']) || empty($_FILES['my-pic']['tmp_name'])) {
             throw new Exception("EMPTY_FILE");
         }
         $_img = $_FILES['my-pic'];
         if (empty($this->get['folder'])) {
             throw new Exception("NO_NAME_OF_FOLDER");
         }
         $folder = trim($this->get['folder']);
         $id = 0;
         if (!(int) $this->get['id']) {
             throw new Exception("NO_CORRECT_NOTE_ID");
         }
         $id = (int) $this->get['id'];
         if (!($path = $this->getImgFolderPath($id, $folder))) {
             throw new Exception("ERROR_CREATE_FOLDERS");
         }
         $_img['name'] = myFunc::translitToUrl($_img['name'], true);
         include_once M_E_PATH . "/WideImage/WideImage.php";
         $image = WideImage::load($_img['tmp_name'])->resize(500, 500, 'inside')->saveToFile($path . "/orig_" . $_img['name'], 100);
         //copy($_img['tmp_name'], $path."/orig_".$_img['name']);
         echo $this->getImgFolder($id, $folder) . "/orig_" . $_img['name'];
         $this->endApp(true);
     } catch (Exception $e) {
         $res['error'] = $e->getMessage();
     }
     echo json_encode($res);
     $this->endApp(true);
 }