Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * Get URL video for Got-tv.ru site
  *
  * @param  string $nameVideo
  * @param  string $urlVideo
  * @return string|FALSE //url or ERROR
  */
 private function _getGodtvURL($nameVideo, $urlVideo)
 {
     $result = FALSE;
     $suffix = '.godtv.ru:85';
     $config = array();
     $strBox = new Default_Plugin_String();
     //-------------------
     // Получим URL страницы загрузки видео
     $encodeNameVideo = urlencode($nameVideo);
     $url = "http://god-tv.ru/" . $encodeNameVideo;
     try {
         $http = new Default_Plugin_HttpBox($config);
         $page = $http->get($url);
         foreach ($page->links() as $link) {
             $href = $link->getAttribute('href');
             $strBox->set($href);
             //                if ($strBox->indexOf($suffix) !== FALSE && $strBox->indexOf($urlVideo) !== FALSE) {
             //                    $result = $strBox->get();
             //                }
             if ($strBox->indexOf($suffix) !== FALSE) {
                 if ($strBox->indexOf($urlVideo) !== FALSE) {
                     $result = $strBox->get();
                 }
             }
         }
         if ($result === FALSE) {
             $html = $page->html;
         }
     } catch (Exception $exc) {
         return FALSE;
     }
     return $result;
 }