/** * Get text markdown markup file * file is selected according to the localization * * @param array $params Set params for [filename, content, type] * @return string */ public function getMarkdown($params) { $arBox = new Default_Plugin_ArrayBox(); $strBox = new Default_Plugin_String(); $filename = isset($params['filename']) ? $params['filename'] : ''; $strFile = isset($params['content']) ? $params['content'] : ''; $type = isset($params['type']) ? $params['type'] : 'github'; //Type of Markdown: traditional, github, extra $title = ''; $locale = Default_Plugin_SysBox::getTranslateLocale(); $locale = $locale == 'uk' ? 'ru' : $locale; $title = ""; $filename = trim($filename); $filename = str_replace('\\', '/', $filename); //------------------------------------------- if ($filename) { if (is_file($filename)) { $lastFilename = $arBox->set($filename, "/")->getLast(); // Set title $title = $lastFilename; // Check word in uppercase $upperFilename = $strBox->set($lastFilename)->toUpper()->get(); $isUpper = $arBox->set($lastFilename, ".")->get(0) == $arBox->set($upperFilename, ".")->get(0); if ($isUpper) { $locale = strtoupper($locale); } // Get the name of the file to a different locale $lastFilename = $arBox->set($lastFilename, ".")->get(0) . "-{$locale}.md"; $localeFilename = $arBox->set($filename, "/")->pop()->join('/') . "/{$lastFilename}"; // Get file content if (is_file($localeFilename)) { // Set title $title = $lastFilename; $strFile = file_get_contents($localeFilename); } else { $strFile = file_get_contents($filename); } } else { // Get file name $filename = APPLICATION_TEMPLATES . "/{$this->_params['controller']}/{$filename}"; if (!is_file($filename)) { throw new Exception("File '{$filename}' does not exist."); } $lastFilename = $arBox->set($filename, "/")->getLast(); // Set title $title = $lastFilename; // Check word in uppercase $upperFilename = $strBox->set($lastFilename)->toUpper()->get(); $isUpper = $arBox->set($lastFilename, ".")->get(0) == $arBox->set($upperFilename, ".")->get(0); if ($isUpper) { $locale = strtoupper($locale); } // Get the name of the file to a different locale $lastFilename = $arBox->set($lastFilename, ".")->get(0) . "-{$locale}.md"; $localeFilename = $arBox->set($filename, "/")->pop()->join('/') . "/{$lastFilename}"; // Get file content if (is_file($localeFilename)) { // Set title $title = $lastFilename; $strFile = file_get_contents($localeFilename); } else { $strFile = file_get_contents($filename); } } } switch ($type) { case 'traditional': $markdown = new \cebe\markdown\Markdown(); break; case 'github': $markdown = new \cebe\markdown\GithubMarkdown(); break; case 'extra': $markdown = new \cebe\markdown\MarkdownExtra(); break; default: break; } // Get markdown parser text $text = $markdown->parse($strFile); // Get content $content = array('title' => $title, 'text' => "<div class=\"markdown-body\">{$text}</div>"); return $content; }
/** * Action - videos * Actions with the videos. Get a list of videos. * * Access to the action is possible in the following paths: * router pattern - user/:username/post/:post_id/videos/* * * - /user/user1/post/27/videos * * @return void */ public function videosAction() { $playlist = array(); //----------------------- // Получим файл конфигурации $ini = Zend_Registry::get('config'); $adapter = $ini['http']['adapter']; $proxy_host = $ini['proxy']['host']; // Получим обьект запроса $request = $this->getRequest(); $params = $request->getParams(); $type_action = $params['type_action']; $username = trim($request->getUserParam('username')); $post_id = (int) $request->getUserParam('post_id'); if ($type_action == 'playlist') { // Получим файлы видео для сообщения $videos = Default_Model_DbTable_BlogPostVideo::GetVideo($this->db, array('post_id' => $post_id)); // Получим список видео данных для статьи foreach ($videos as $video) { // Получим URL ресурса $type = $video->type; $arrType = explode('-', $type); if ($arrType[0] == 'file') { $url = $video->getFullUrl_Res($username); } else { $url = $video->identifier; } $path = $video->GetUploadPath($username) . '/' . $video->getId() . '.json'; if (is_file($path)) { $strJson = file_get_contents($path); $strJson = stripslashes($strJson); try { // Получим пути к изобржаениям и флеш для пользователя $pathImages = Default_Model_DbTable_BlogPostImage::GetUploadUrl($username); $pathFlash = Default_Model_DbTable_BlogPostVideo::GetUploadUrlForFlash($username); // Преобразуем Json в PHP массив $itemPlaylist = Zend_Json::decode($strJson); // Изменим данные в массиве $itemPlaylist['clip_id'] = $video->getId(); $itemPlaylist['clip_type'] = $video->type; $itemPlaylist['url'] = $url; $itemPlaylist['title'] = $video->name; if (isset($itemPlaylist['cuepoints'])) { $cuepoints = $itemPlaylist['cuepoints']; $newCuepoints = array(); foreach ($cuepoints as $cuepoint) { if (isset($cuepoint['image'])) { $cuepoint['image'] = $this->getUrlRes($pathImages . '/' . ltrim($cuepoint['image'], '/')); } if (isset($cuepoint['flash'])) { $cuepoint['flash'] = $this->getUrlRes($pathFlash . '/' . ltrim($cuepoint['flash'], '/')); } $newCuepoints[] = $cuepoint; } $itemPlaylist['cuepoints'] = $newCuepoints; } } catch (Exception $exc) { $jsons = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка получения видео') . '</em>', Default_Plugin_SysBox::getMessageError($exc))); $this->sendJson($jsons); return; } } else { $itemPlaylist = array(); $itemPlaylist['clip_id'] = $video->getId(); $itemPlaylist['clip_type'] = $video->type; $itemPlaylist['url'] = $url; $itemPlaylist['title'] = $video->name; $itemPlaylist['description'] = $video->comment; } $playlist[] = $itemPlaylist; } if ($this->_isAjaxRequest) { $this->sendJson($playlist); } } elseif ($type_action == 'godtv_url') { // Получим параметры клипа $clip_name = $params['clip_name']; $clip_id = $params['clip_id']; // Получим файлы видео для сообщения $videos = Default_Model_DbTable_BlogPostVideo::GetVideo($this->db, array('post_id' => $post_id)); // Найдем нужное видео и обновим "identifier" foreach ($videos as $video) { if ($video->getId() == $clip_id) { // Получим уникальный URL для фильма $arrBox = new Default_Plugin_ArrayBox(); $url_video = $arrBox->set($video->identifier, '/')->getLast(); // Получим новый URL для этого видео $new_url = $this->_getGodtvURL($clip_name, $url_video); if ($new_url === FALSE) { $jsons = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка URL') . '</em>', $this->Translate('Ошибка получения URL для видео'))); $this->sendJson($jsons); return; } $video->identifier = $new_url; if ($video->save()) { $json = array('url' => $new_url); } else { $json = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка при сохранении данных') . '</em>')); } $this->sendJson($json); return; } } } elseif ($type_action == 'play') { $json = array('result' => 'OK'); $this->sendJson($json); return; } }