Exemplo n.º 1
0
 /**
  * Action - load
  * Download form of editing
  * 
  * Access to the action is possible in the following paths:
  * - /admin/info/load
  *
  * @return void
  */
 public function loadAction()
 {
     $json = array();
     //------------------
     try {
         // Создадим обьект шаблона
         $templater = Default_Plugin_SysBox::createViewSmarty();
         //Установим параметры шаблона
         $templater->list_locales = $this->_locales;
         // Получим результат шаблона
         $html = $templater->render('info/load.tpl');
         $json = array('downloaded' => true, 'html' => $html);
         $this->sendJson($json);
     } catch (Exception $exc) {
         $json = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка при загрузке формы редактирования') . '</em>', $exc->getTraceAsString()));
         $this->sendJson($json);
     }
 }
Exemplo n.º 2
0
 /**
  * Action - report
  * display table data in a report in HTML or PDF format
  * 
  * Access to the action is possible in the following paths:
  * - /admin/user/report
  *
  * @return void
  */
 public function reportAction()
 {
     try {
         $params = $this->getRequest()->getParams();
         // Тип отчета
         $report_type = $params['type'];
         // Таблица для отчета
         $table = $params['table'];
         // Получим данные по отчету
         $reportData = $this->_getReportData($table);
         // Получим данные для отчета
         switch ($report_type) {
             case 'html':
                 $templater = Default_Plugin_SysBox::createViewSmarty();
                 // Отображается в режиме отчета
                 $templater->report = TRUE;
                 //------ Установим параметры и переменные HTML ------
                 // ---- Титл -----
                 $templater->title_name = $reportData['html']['title_report'];
                 $templater->title_logo = $reportData['html']['logo_report'];
                 // ---- Заголовок -----
                 $templater->column_model = $reportData['html']['column_model'];
                 $templater->is_group_head = isset($reportData['html']['is_group_head']) ? $reportData['html']['is_group_head'] : 0;
                 // ---- Нижний колонтитул -----
                 $templater->rows_footer = $reportData['html']['rows_footer'];
                 $templater->footer_colspan = $reportData['html']['footer_colspan'];
                 // ---- Тело таблицы -----
                 $templater->rows_body = $reportData['html']['rows_body'];
                 $templater->is_row_header = isset($reportData['html']['is_row_header']) ? $reportData['html']['is_row_header'] : 0;
                 // Получим результат шаблона
                 $html = $templater->render('reports/report-table.tpl');
                 $this->sendJson(array('result' => $this->Translate('Создан отчет в формате HTML'), 'html' => $html));
                 break;
             case 'pdf':
                 // Проверим наличие файла mpdf.php
                 // Если нет, то выдадим ошибку!
                 $path = APPLICATION_BASE . '/library/mPDF/mpdf.php';
                 if (!is_file($path)) {
                     throw new Exception($this->Translate('Не установлена библиотека mPDF', '/library/mPDF', 'http://www.mpdf1.com/mpdf/index.php?page=Download'));
                 }
                 // Создадим обьект шаблона
                 if ($this->_isAjaxRequest) {
                     $templater = Default_Plugin_SysBox::createViewSmarty();
                 } else {
                     $templater = $this->view;
                 }
                 //------ Установим параметры и переменные HTML ------
                 // ---- Титл -----
                 $templater->title_name = $reportData['html']['title_report'];
                 $templater->title_logo = $reportData['html']['logo_report'];
                 // ---- Заголовок -----
                 $templater->column_model = $reportData['html']['column_model'];
                 $templater->is_group_head = isset($reportData['html']['is_group_head']) ? $reportData['html']['is_group_head'] : 0;
                 // ---- Нижний колонтитул -----
                 $templater->rows_footer = $reportData['html']['rows_footer'];
                 $templater->footer_colspan = $reportData['html']['footer_colspan'];
                 // ---- Тело таблицы -----
                 $templater->rows_body = $reportData['html']['rows_body'];
                 $templater->is_row_header = isset($reportData['pdf']['is_row_header']) ? $reportData['pdf']['is_row_header'] : 0;
                 // Получим результат шаблона
                 $html = $templater->render('reports/table.tpl');
                 // Установим имя отчета PDF
                 // в названии файла будет присутствовать хеш полученного HTML
                 // это нужно для того, чтобы не создавать существующих файлов
                 $md5Html = md5($html);
                 $report = $table . '_' . $md5Html;
                 // Установим параметры для отчета PDF
                 $pdfParams['pdfReport'] = $report;
                 $pdfParams['html'] = $html;
                 $pdfParams['isCommonFont'] = FALSE;
                 $pdfParams['pathStylesheet'] = 'css/report/blue-style.css';
                 //phpinfo blue-style
                 $pdfParams['headerLeftMargin'] = $reportData['pdf']['title_report'];
                 $pdfParams['headerCentreMargin'] = $reportData['pdf']['logo_report'];
                 $pdfParams['pageFormat'] = $reportData['pdf']['pageFormat'];
                 ob_start();
                 // Получим имя файла и проверим его наличие
                 $filename = Default_Plugin_SysBox::getPath_For_FilePDF($report);
                 if (file_exists($filename)) {
                     // Файл уже существует
                     sleep(1);
                     // Получить URL PDF файла
                     $urlFilePDF = Default_Plugin_SysBox::getFullUrl_For_FilePDF($report);
                     $this->sendJson(array('result' => $this->Translate('Этот отчет уже существует'), 'url_file_pdf' => $urlFilePDF));
                 } else {
                     // Создадим отчет...
                     // Удалим ранее созданные отчеты
                     // Получим директорию с файлами отчетов
                     $patch_dir = Default_Plugin_SysBox::getPath_For_FilePDF('');
                     // Получим обьект построения дерева файлов
                     $ft = new Default_Plugin_FileTree($patch_dir);
                     // создадим дерево файлов
                     $report_del = $table . '_*.pdf';
                     $ft->readTree(array('name' => $report_del));
                     // удалим файлы и директории
                     $result = $ft->delFiles();
                     // Создать PDF файл из HTML
                     $urlFilePDF = Default_Plugin_SysBox::mpdfGenerator_Html2PDF($pdfParams);
                     $this->sendJson(array('result' => $this->Translate('Создан отчет в формате PDF'), 'url_file_pdf' => $urlFilePDF));
                 }
                 break;
             case 'exel':
                 break;
             default:
                 break;
         }
     } catch (Exception $exc) {
         $jsons = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка формирования отчета') . '</em>', Default_Plugin_SysBox::getMessageError($exc)));
         $this->sendJson($jsons);
     }
 }
Exemplo n.º 3
0
 /**
  * Action - comments
  * actions for user comments
  *
  * Access to the action is possible in the following paths:
  * шаблон раутера - user/:username/post/:post_id/comments/*
  * 
  * - /user/user1/post/27/comments
  *
  * @return void
  */
 public function commentsAction()
 {
     $json = array();
     $result = TRUE;
     //-----------------------
     // Получим обьект запроса
     $request = $this->getRequest();
     $params = $request->getParams();
     $type_action = $params['type_action'];
     $post_id = (int) $request->getUserParam('post_id');
     $username = trim($request->getUserParam('username'));
     try {
         if ($type_action == 'delete') {
             // Удалим комментарий
             // Получим массив комментариев для удаления
             $comment_ids = $params["comment_ids"];
             $comment_ids = Zend_Json::decode($comment_ids);
             $parent_comment_id = $comment_ids[0];
             // Удалим комментарии из базы данных
             $comment = new Default_Model_DbTable_BlogPostComment($this->db);
             foreach ($comment_ids as $comment_id) {
                 if ($comment->loadForPost($post_id, $comment_id)) {
                     $comment->delete();
                 } else {
                     $result = FALSE;
                     break;
                 }
             }
             if ($result) {
                 $json = array('deleted' => true, 'result' => $this->Translate('Комментарий удален из сообщения блога'), 'comment_id' => $parent_comment_id);
             } else {
                 $json = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка при добавлении / удалении комментария в блог') . '</em>'));
             }
         } else {
             if ($type_action == 'add' || $type_action == 'reply' || $type_action == 'edit') {
                 // Добавим/изменим комментарий на сообщение
                 $allParams = $this->_getAllParams();
                 $reply_id = $params["reply_id"];
                 $formAddComment = new Default_Form_AddComment($username, $post_id);
                 $result = $formAddComment->isValid($allParams);
                 if ($result) {
                     $comment = new Default_Model_DbTable_BlogPostComment($this->db);
                     if ($type_action == 'edit') {
                         if ($comment->loadForPost($post_id, $reply_id)) {
                             $comment->comment = $formAddComment->getValue('ckeditor_comment');
                         } else {
                             $json = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка при сохранении данных') . '</em>'));
                         }
                     } else {
                         $comment->user_id = $this->_identity->user_id;
                         $comment->post_id = $post_id;
                         $comment->reply_id = $reply_id;
                         $comment->comment = $formAddComment->getValue('ckeditor_comment');
                     }
                     if ($comment->save()) {
                         if ($type_action == 'edit') {
                             $html = $formAddComment->getValue('ckeditor_comment');
                             $result = $this->Translate('Комментарий изменен');
                         } else {
                             // Получим параметр для шаблона
                             $treeComments = Default_Model_DbTable_BlogPostComment::getTreeComments($this->db, $this->user->getId(), array('post_id' => $post_id, 'comment_id' => $comment->getId()));
                             // Создадим обьект шаблона
                             $templater = Default_Plugin_SysBox::createViewSmarty();
                             //Установим параметры шаблона
                             $templater->treeComments = $treeComments;
                             $templater->authenticated = true;
                             $templater->isAdmin = $this->_isAdmin;
                             $templater->identity = $this->_identity;
                             // Получим результат шаблона
                             $html = $templater->render('user/lib/comment-item.tpl');
                             $result = $this->Translate('Добавлен комментарий к сообщению блога');
                         }
                         $json = array('added' => true, 'result' => $result, 'comment_id' => $comment->getId(), 'html' => $html);
                     } else {
                         // Ошибка записи в базу данных
                         $json = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка при сохранении данных') . '</em>'));
                     }
                 } else {
                     // неверно заполнены поля формы
                     $json = array('class_message' => 'warning', 'messages' => $this->getFormMessages($formAddComment));
                 }
             }
         }
     } catch (Exception $e) {
         $json = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка при добавлении / удалении комментария в блог') . '</em>', Default_Plugin_SysBox::getMessageError($e)));
     }
     $this->sendJson($json);
 }
Exemplo n.º 4
0
 /**
  * Action - video
  * upload/download/ordering video
  * 
  * Access to the action is possible in the following paths:
  * - /blogmanager/video
  *
  * @return void
  */
 public function videoAction()
 {
     $json = array();
     $filterSanitize = new Default_Form_Filter_Sanitize();
     //-----------------------
     // Получим обьект записи
     $request = $this->getRequest();
     $params = $request->getParams();
     $post_id = (int) $request->getPost('id');
     if (!$post_id) {
         $post_id = (int) $request->getParam('id');
     }
     $post = new Default_Model_DbTable_BlogPost($this->db);
     // Если конкретной записи нет, то перейдем к странице по умолчанию
     if (!$post->loadForUser($this->_identity->user_id, $post_id)) {
         $this->_redirect('/blogmanager');
     }
     // Определим тип операции над видео: 'upload', 'reorder', 'delete'
     // Загрузка файла с помощью - FileUploader
     if (Default_Plugin_FileUploader::isFileUploader()) {
         // Получим вид загрузчика - Iframe или Xhr
         $fileUploader = Default_Plugin_FileUploader::isFileUploader();
         // list of valid extensions, ex. array("jpeg", "xml", "bmp")
         $allowedExtensions = $params['allowedExtensions'];
         $allowedExtensions = str_replace(' ', '', $allowedExtensions);
         $arrAllowedExtensions = explode(';', $allowedExtensions);
         // max file size in bytes
         $sizeLimit = (int) $request->getParam('sizeLimit');
         // Получим обьект загрузчика файлов
         try {
             $uploader = new Default_Plugin_FileUploader($arrAllowedExtensions, $sizeLimit);
             // Определим путь загрузки файлов
             $path = Default_Model_DbTable_BlogPostVideo::GetUploadPath();
             $path .= '/';
             //Загрузим файлы
             $result = $uploader->handleUpload($path);
         } catch (Exception $e) {
             $json = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка загрузки файла') . '</em>', Default_Plugin_SysBox::getMessageError($e)));
             if ($fileUploader == 'Iframe') {
                 $this->sendJson_Html($json);
             } else {
                 $this->sendJson($json);
             }
             return;
         }
         if (isset($result['success'])) {
             // Создадим обьект изображения
             try {
                 $filename = $path . $uploader->file->getName();
                 $pathinfo = pathinfo($filename);
                 $ext = $pathinfo['extension'];
                 $video = new Default_Model_DbTable_BlogPostVideo($post->getDb());
                 $video->post_id = $post->getId();
                 $video->uploadFile($filename);
                 $video->identifier = basename($filename);
                 $video->type = 'file-' . $ext;
                 if (!$video->save()) {
                     $json = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка при сохранении данных') . '</em>'));
                     if ($fileUploader == 'Iframe') {
                         $this->sendJson_Html($json);
                     } else {
                         $this->sendJson($json);
                     }
                     return;
                 }
                 $json['success'] = $result['success'];
                 $json['video_id'] = $video->getId();
                 $json['filename'] = $video->identifier;
                 $json['post_id'] = $video->post_id;
                 $json['form_action'] = $this->getUrl('video', 'blogmanager');
                 // Определим путь к изображению для видео
                 $srcImage = 'images/media/thumbs/' . $video->type . '.png';
                 $json['url_image'] = $this->getUrlRes($srcImage) . '?id=' . $video->getId();
             } catch (Exception $e) {
                 $json = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка загрузки файла') . '</em>', Default_Plugin_SysBox::getMessageError($e)));
                 if ($fileUploader == 'Iframe') {
                     $this->sendJson_Html($json);
                 } else {
                     $this->sendJson($json);
                 }
                 return;
             }
         } else {
             // Error
             $json = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка загрузки файла') . '</em>', $result['error']));
             if ($fileUploader == 'Iframe') {
                 $this->sendJson_Html($json);
             } else {
                 $this->sendJson($json);
             }
             return;
         }
     } else {
         if ($request->getPost('add_video_url')) {
             // Создадим обьект изображения
             try {
                 $strInfoVideo = $request->getPost('info_video');
                 $strInfoVideo = stripslashes($strInfoVideo);
                 $arrInfoVideo = Zend_Json::decode($strInfoVideo);
                 $video = new Default_Model_DbTable_BlogPostVideo($post->getDb());
                 $video->post_id = $post->getId();
                 $video->identifier = $arrInfoVideo['url'];
                 $video->type = $arrInfoVideo['type'];
                 if (!$video->save()) {
                     $json = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка при сохранении данных') . '</em>'));
                     $this->sendJson($json);
                     return;
                 }
                 // Определим путь к изображению для видео
                 $srcImage = 'images/media/thumbs/' . $video->type . '.png';
                 $json['video_id'] = $video->getId();
                 $json['filename'] = $video->identifier;
                 $json['post_id'] = $video->post_id;
                 $json['url_image'] = $this->getUrlRes($srcImage) . '?id=' . $video->getId();
                 $json['form_action'] = $this->getUrl('video', 'blogmanager');
                 $json['result'] = $this->Translate('URL на ресурс добавлен');
             } catch (Exception $e) {
                 $json = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка загрузки файла') . '</em>', Default_Plugin_SysBox::getMessageError($e)));
                 $this->sendJson($json);
                 return;
             }
         } else {
             if ($request->getPost('reorder')) {
                 $order = $request->getPost('preview-video');
                 $post->setVideoOrder($order);
             } else {
                 if ($request->getPost('delete')) {
                     $video_id = (int) $request->getPost('image');
                     $video = new Default_Model_DbTable_BlogPostVideo($this->db);
                     if ($video->loadForPost($post->getId(), $video_id)) {
                         $video->delete();
                         // Определим кол. оставшихся изображений
                         $count_videos = count($post->video) - 1;
                         $json = array('deleted' => true, 'image_id' => $video_id, 'count_images' => $count_videos);
                     }
                 } else {
                     if ($request->getPost('comment_update')) {
                         $video_id = (int) $request->getPost('image');
                         $video = new Default_Model_DbTable_BlogPostVideo($this->db);
                         if ($video->loadForPost($post->getId(), $video_id)) {
                             $comment = $request->getPost('comment');
                             // Отфильтруем ненужные теги в комментарии
                             $comment = $filterSanitize->filter($comment);
                             // Выделим название и комментарий
                             $arrComment = explode('#', $comment);
                             // Если тип видео -> 'url-godtv', то важно получить точное название видео
                             // это название должно точно соответствовать пути к загрузочной странице этого видео
                             // пр. http://god-tv.ru/%D0%A0%D0%B5%D1%88%D0%B0%D1%8E%D1%89%D0%B8%D0%B9-%D1%80%D1%8B%D0%B2%D0%BE%D0%BA-%D1%81%D0%BC%D0%BE%D1%82%D1%80%D0%B5%D1%82%D1%8C-%D0%BE%D0%BD%D0%BB%D0%B0%D0%B9%D0%BD
                             // или так %D0%A0%D0%B5%D1%88%D0%B0%D1%8E%D1%89%D0%B8%D0%B9-%D1%80%D1%8B%D0%B2%D0%BE%D0%BA-%D1%81%D0%BC%D0%BE%D1%82%D1%80%D0%B5%D1%82%D1%8C-%D0%BE%D0%BD%D0%BB%D0%B0%D0%B9%D0%BD
                             // или так "Решающий-рывок-смотреть-онлайн"
                             if ($video->type == 'url-godtv') {
                                 $tmpName = urldecode($arrComment[0]);
                                 $tmpNames = explode('/', $tmpName);
                                 $tmpName = $tmpNames[count($tmpNames) - 1];
                                 $arrComment[0] = $tmpName;
                             }
                             if (count($arrComment) > 1) {
                                 $video->name = $arrComment[0];
                                 $video->comment = $arrComment[1];
                             } else {
                                 $video->name = $arrComment[0];
                             }
                             // Сохраним в базе данных
                             if (!$video->save()) {
                                 $json = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка при сохранении данных') . '</em>'));
                                 $this->sendJson($json);
                                 return;
                             }
                             $json = array('commented' => true, 'title' => $video->name, 'comment' => $video->comment);
                         }
                     } else {
                         if ($request->getPost('download_images')) {
                             // Загрузим изображения в виде HTML на страницу
                             // Получим файлы видео для статьи
                             $videos = Default_Model_DbTable_BlogPostVideo::GetVideo($this->db, array('post_id' => $post_id));
                             // Создадим обьект шаблона
                             $templater = Default_Plugin_SysBox::createViewSmarty();
                             //Установим параметры шаблона
                             $templater->videos = $videos;
                             $templater->post_id = $post_id;
                             // Получим результат шаблона
                             $html = $templater->render('blogmanager/lib/download-video.tpl');
                             $json = array('downloaded' => true, 'html' => $html);
                         }
                     }
                 }
             }
         }
     }
     if ($this->_isAjaxRequest) {
         $this->sendJson($json);
     } else {
         $this->sendJson_Html($json);
     }
 }
Exemplo n.º 5
0
 /**
  * Creating email of the user's new password
  * 
  * @param string  Название шаблона письма
  * @return array
  */
 private function _createFetchPassword_Email($tpl)
 {
     $arrMail = array();
     //--------------------
     $templater = Default_Plugin_SysBox::createViewSmarty();
     $templater->user = $this;
     $templater->ActivateURL = Default_Plugin_SysBox::getFullURL(array('controller' => 'account', 'action' => 'fetchpassword'));
     // fetch the e-mail body
     $body = $templater->render('email/' . $tpl);
     // extract the subject from the first line
     list($subject, $body) = preg_split('/\\r|\\n/', $body, 2);
     $arrMail['subject'] = trim($subject);
     $arrMail['body'] = trim($body);
     return $arrMail;
 }