コード例 #1
0
 /**
  * Removes the base path of the URL to HTML resources
  *
  * @param string $html
  * @return string|bool If error, then output FALSE
  */
 protected function deleteBasePathUrl($html)
 {
     //$domHtml
     $str_begin = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . '<body>';
     $str_end = '</body>';
     //---------------------------
     $filtrHtmlEntities = new Default_Form_Filter_HtmlEntities();
     $html = $filtrHtmlEntities->filter($html);
     $html = $str_begin . $html . $str_end;
     // Check for correct XML
     $domDoc = new DOMDocument('1.0', 'utf-8');
     $success = $domDoc->loadXML($html);
     if (!$success) {
         return FALSE;
     }
     // Correct code
     $domQuery = new Zend_Dom_Query();
     $domQuery->setDocumentXml($html, "utf-8");
     foreach (self::$tags as $tag => $attr) {
         $results = $domQuery->query($tag);
         if ($results->count()) {
             foreach ($results as $result) {
                 // $result variable is of DOMElement type
                 if ($result->hasAttribute($attr)) {
                     $value = $result->getAttribute($attr);
                     $st = new Default_Plugin_String($value);
                     if ($st->beginsWith('/')) {
                         // it was: /zf-myblog/public/pic/1.gif
                         // it is: /pic/1.gif
                         $baseURL = Default_Plugin_SysBox::getBaseURL();
                         $value = str_replace($baseURL, '', $value);
                         $result->setAttribute($attr, $value);
                     } else {
                         // it was: https://mysite.com:8080/zf-myblog/public/pic/1.gif
                         // it is: /pic/1.gif
                         $hostPortBaseURL = Default_Plugin_SysBox::getHostPortBaseURL();
                         $value = str_replace($hostPortBaseURL, '', $value);
                         $result->setAttribute($attr, $value);
                     }
                 }
             }
             $domDoc = $results->getDocument();
             $html = $domDoc->saveXml();
             $domQuery->setDocumentXml($html, "utf-8");
         }
     }
     $html = str_replace($str_begin, '', $html);
     $html = str_replace($str_end, '', $html);
     return $html;
 }
コード例 #2
0
ファイル: AddBasePathUrl.php プロジェクト: bsa-git/zf-myblog
 /**
  * add the base path to the URL of HTML Resources
  *
  * @param string $html
  * @return string
  */
 protected function addBasePathUrl($html)
 {
     //$domHtml
     $str_begin = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . '<body>';
     $str_end = '</body>';
     //---------------------------
     $html = str_replace('&nbsp;', '&#160;', $html);
     $html = $str_begin . $html . $str_end;
     // Check for correct XML
     $domDoc = new DOMDocument('1.0', 'utf-8');
     $success = $domDoc->loadXML($html);
     if (!$success) {
         return FALSE;
     }
     $domQuery = new Zend_Dom_Query();
     $domQuery->setDocumentXml($html, "utf-8");
     foreach (self::$tags as $tag => $attr) {
         $results = $domQuery->query($tag);
         if ($results->count()) {
             foreach ($results as $result) {
                 // $result variable is of DOMElement type
                 if ($result->hasAttribute($attr)) {
                     $value = $result->getAttribute($attr);
                     $st = new Default_Plugin_String($value);
                     if ($st->beginsWith('/')) {
                         $baseURL = Default_Plugin_SysBox::getUrlRes($value);
                         $result->setAttribute($attr, $baseURL);
                     }
                 }
             }
             $domDoc = $results->getDocument();
             $html = $domDoc->saveXml();
             $domQuery->setDocumentXml($html, "utf-8");
         }
     }
     $html = str_replace($str_begin, '', $html);
     $html = str_replace($str_end, '', $html);
     return $html;
 }
コード例 #3
0
ファイル: BaseController.php プロジェクト: bsa-git/zf-myblog
 /**
  * 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;
 }
コード例 #4
0
ファイル: UserController.php プロジェクト: bsa-git/zf-myblog
 /**
  * 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;
 }