Ejemplo n.º 1
0
 public function blognewAction()
 {
     $this->view->input = array('title' => '', 'author' => '', 'email' => '', 'richtext' => '');
     $this->view->errors = array('title' => array(''), 'author' => array(''), 'email' => array(''), 'richtext' => array(''), 'captcha' => array(''));
     $this->view->token = new Zend_Service_ReCaptcha($this->config->capcha->pub, $this->config->capcha->priv);
     if ($this->_request->isPost()) {
         // перевіряємо капчу
         $recaptcha_challenge_field = $this->_getParam('recaptcha_challenge_field', 'default');
         $recaptcha_response_field = $this->_getParam('recaptcha_response_field', 'default');
         $result = $this->view->token->verify($recaptcha_challenge_field, $recaptcha_response_field);
         if (!$result->isValid()) {
             $this->view->errors['captcha'][0] = $this->view->tr(NULL, $this->view->lang, 'Введений не вірний текст');
         }
         // валідація введених даних
         $_POST['keyword'] = $_POST['description'] = $_POST['title'];
         $input = $this->blogvalidate($_POST);
         if ($input->isValid() && empty($this->view->errors['captcha'][0])) {
             $res = Model_Blogentry::updateentry($input);
             if ($res[0] > 0) {
                 foreach ($this->view->langs as $key) {
                     if ($key !== $input->lang) {
                         $data = $_POST;
                         $data['identry'] = $res[1];
                         $data['lang'] = $key;
                         $input = $this->blogvalidate($data);
                         Model_Blogentry::updateentry($input);
                     }
                 }
                 // upload image
                 /* Uploading Document File on Server */
                 $dest = 'public/img/blog/thumb';
                 $upload = new Zend_File_Transfer_Adapter_Http();
                 $upload->setDestination("tmp");
                 try {
                     // upload received file(s)
                     $upload->receive();
                     $t = $upload->getFileInfo();
                     $oldfilename = 'tmp/' . $t['photo']['name'];
                     $filename = "{$dest}/{$res[1]}.jpg";
                     // ініціалізуємо модулі лдля роботи з картинками
                     $thumb = new Asido_Image($oldfilename, $filename);
                     $asido = new Asido_Api();
                     $asido->_driver(new Asido_Driver_GD());
                     // визначаэмо пропорції картинки, щоб дізнатися з якої сторони вирізати
                     $ar = getimagesize($oldfilename);
                     $res2width = true;
                     if ($ar[0] < $ar[1]) {
                         $res2width = false;
                     }
                     //                if ($res2width && (($ar[0] / $ar[1]) > 1.5 )) {
                     //                    $asido->height($thumb, 153);
                     //                } else {
                     //                    $asido->width($thumb, 224);
                     //                }
                     //                $asido->crop($thumb, 0, 0, 224, 153);
                     $asido->frame($thumb, 224, 153, Asido_Api::color(0, 0, 0));
                     $thumb->save(ASIDO_OVERWRITE_ENABLED);
                     // update permition
                     @chmod($filename, 0777);
                     @unlink($oldfilename);
                 } catch (Exception $e) {
                 }
                 try {
                     $mail = new Zend_Mail($charset = 'utf-8');
                     $mail->addTo($this->view->config->resources->mail->admin);
                     $mail->setFrom($this->view->config->resources->mail->sender);
                     $text = $this->view->config->resources->mail->template;
                     $text = "Був додане поздоровлення  '{$_POST['title']}'" . $this->view->config->baseurl . "/ua/blog/post-{$res[1]}.html" . "\n";
                     $text .= "Дата: " . $this->view->localDate(time(), $this->view->lang) . "\n";
                     $text .= "Имя: " . $input->author . " \n";
                     $text .= "Email: " . $input->email . "\n";
                     $text .= "Текст: " . strip_tags($input->richtext) . " \n";
                     $mail->setSubject('Поздоровлення на сайті Party Zone');
                     $mail->setBodyText($text);
                     $t = $mail->send();
                 } catch (Zend_Mail_Exception $e) {
                     // echo json_encode(array('status' => 'error', 'msg' => $e->getMessages()));
                     // exit;
                 }
                 $url = array('lang' => $this->view->lang, 'title' => Local_String::translit($input->title), 'idpost' => $res[1]);
                 return $this->_redirect($this->view->url($url, 'blogpage'));
             }
         } else {
             $this->view->input = array_merge($this->view->input, $input->getUnescaped());
             $this->view->errors = array_merge($this->view->errors, $input->getErrors());
             //var_dump($input->getErrors());
         }
     }
 }
Ejemplo n.º 2
0
 public function thumbuploadAction()
 {
     if ($this->_request->isPost()) {
         $type = $this->_getParam('type', 'page');
         $item = $this->_getParam('item');
         //якщо нема id (блога чи сторінки) виходимо з помилкою
         if (empty($item)) {
             echo "Код пустой";
             exit;
         }
         // в залежності від типу тсорінки вибираємо місце де буде картинка
         switch ($type) {
             case 'blog':
                 $dest = 'public/img/blog/thumb';
                 break;
             case 'page':
                 $dest = 'public/img/blog/thumb';
                 break;
             default:
                 break;
         }
         /* Uploading Document File on Server */
         $upload = new Zend_File_Transfer_Adapter_Http();
         $upload->setDestination("tmp");
         try {
             // upload received file(s)
             $upload->receive();
             $t = $upload->getFileInfo();
             $t = $upload->getFileInfo();
             $oldfilename = 'tmp/' . $t['Filedata']['name'];
             $filename = "{$dest}/{$item}.jpg";
             // ініціалізуємо модулі лдля роботи з картинками
             $thumb = new Asido_Image($oldfilename, $filename);
             $asido = new Asido_Api();
             $asido->_driver(new Asido_Driver_GD());
             // визначаэмо пропорції картинки, щоб дізнатися з якої сторони вирізати
             $ar = getimagesize($oldfilename);
             $res2width = true;
             if ($ar[0] < $ar[1]) {
                 $res2width = false;
             }
             //                if ($res2width && (($ar[0] / $ar[1]) > 1.5 )) {
             //                    $asido->height($thumb, 153);
             //                } else {
             //                    $asido->width($thumb, 224);
             //                }
             //                $asido->crop($thumb, 0, 0, 224, 153);
             $asido->frame($thumb, 224, 153, Asido_Api::color(0, 0, 0));
             $thumb->save(ASIDO_OVERWRITE_ENABLED);
             // update permition
             @chmod($filename, 0777);
             @unlink($oldfilename);
             echo json_encode(array('status' => 'success', 'item' => $item));
             exit;
         } catch (Zend_File_Transfer_Exception $e) {
             echo json_encode(array('status' => 'error', 'msg' => $e->getMessage()));
             exit;
         } catch (Exception $e) {
             echo json_encode(array('status' => 'error', 'msg' => $e->getMessage()));
             exit;
         }
     }
     echo json_encode(array('status' => 'error', 'msg' => 'non-action'));
     exit;
 }