Beispiel #1
0
 /**
  * Выбирает все картинки копирует в папку назначения заменяет в $content и возвращает
  *
  * @param \simple_html_dom | string $content     контент
  * @param SitePath | string         $destination путь к папке назначения, она должна существовать
  *
  * @return string
  */
 public static function copyImages($content, $destination)
 {
     if ($content == '') {
         return '';
     }
     if (!$content instanceof \simple_html_dom) {
         require_once Yii::getAlias('@csRoot/services/simplehtmldom_1_5/simple_html_dom.php');
         $content = str_get_html($content);
     }
     foreach ($content->find('img') as $element) {
         $imagePath = new SitePath($element->attr['src']);
         // картинка не содержит путь назначения?
         if (!Str::isContain($element->attr['src'], $destination->getPath())) {
             $urlInfo = parse_url($element->attr['src']);
             if (ArrayHelper::getValue($urlInfo, 'scheme', '') == '') {
                 try {
                     $destinationFile = $destination->cloneObject()->add($imagePath->getFileName());
                     self::resizeImage($imagePath->getPathFull(), $destinationFile->getPathFull());
                     $element->attr['src'] = $destinationFile->getPath();
                 } catch (\Exception $e) {
                     Yii::warning($e->getMessage(), 'gs\\HtmlContent\\copyImages');
                 }
             } else {
                 // картинка на внешнем сервере, пока ничего не делаем
             }
         }
     }
     return $content->root->outertext();
 }
Beispiel #2
0
 /**
  * @param string|int|DateTime $date UTC
  *
  * @return \cs\models\Response
  * integer - unix time
  */
 private static function convertDate($date)
 {
     if (is_string($date)) {
         if (Str::isContain($date, '-')) {
             return Response::success((new \DateTime($date, new \DateTimeZone('UTC')))->format('U'));
         } else {
             return Response::success((int) $date);
         }
     } else {
         if (is_integer($date)) {
             return Response::success($date);
         } else {
             if ($date instanceof DateTime) {
                 return Response::success($date->format('U'));
             } else {
                 return Response::error('Не верный формат данных');
             }
         }
     }
 }
Beispiel #3
0
 /**
  * Проверка на входной параметр и превращение из массива в строку если надо
  *
  * @param $folder
  *
  * @return string
  * @throws \Exception
  */
 private static function convert($folder)
 {
     if (is_array($folder)) {
         $folder = self::convertArrayToName($folder);
     } else {
         if (Str::isContain($folder, '..')) {
             throw new \Exception('Нельзя в параметре передавать \'..\'');
         }
     }
     return $folder;
 }
Beispiel #4
0
 /**
  * Возвращает дату в формате "d M Y г." например "1 Дек 2015 г."
  *
  * @param $date 'yyyy-mm-dd'
  *
  * @return string
  */
 public static function dateString($date)
 {
     if (is_null($date)) {
         return '';
     }
     if ($date == '') {
         return '';
     }
     if (!Str::isContain($date, '-')) {
         $date = date('Y-m-d', $date);
     }
     $year = substr($date, 0, 4);
     $month = substr($date, 5, 2);
     $day = substr($date, 8, 2);
     if (substr($month, 0, 1) == '0') {
         $month = substr($month, 1, 1);
     }
     if (substr($day, 0, 1) == '0') {
         $day = substr($day, 1, 1);
     }
     $monthList = [1 => 'Янв', 2 => 'Фев', 3 => 'Мар', 4 => 'Апр', 5 => 'Май', 6 => 'Июн', 7 => 'Июл', 8 => 'Авг', 9 => 'Сен', 10 => 'Окт', 11 => 'Ноя', 12 => 'Дек'];
     $month = $monthList[$month];
     return "{$day} {$month} {$year} г.";
 }
Beispiel #5
0
                    </div>
                </div>
            <?php 
}
?>
        </div>
    </div>
</footer>

<div id="infoModal" class="zoom-anim-dialog mfp-hide mfp-dialog">
    <h1>Dialog example</h1>
    <p>This is dummy copy. It is not meant to be read. It has been placed here solely to demonstrate the look and feel of finished, typeset text. Only for show. He who searches for meaning here will be sorely disappointed.</p>
</div>

<?php 
if (YII_ENV == 'prod' && !\cs\services\Str::isContain(Yii::$app->controller->id, 'admin')) {
    ?>
<!-- Yandex.Metrika counter -->
<script type="text/javascript">
    (function (d, w, c) {
        (w[c] = w[c] || []).push(function() {
            try {
                w.yaCounter30774383 = new Ya.Metrika({id:30774383,
                    webvisor:true,
                    clickmap:true,
                    trackLinks:true,
                    accurateTrackBounce:true});
            } catch(e) { }
        });

        var n = d.getElementsByTagName("script")[0],
Beispiel #6
0
 /**
  * Выбирает все картинки копирует в папку назначения заменяет в $content и возвращает
  *
  * @param \simple_html_dom | string $content              контент
  * @param SitePath | string         $destination          путь к папке назначения, она должна существовать
  * @param bool                      $isCopyFromRemoteHost копировать с внешних источников картинки?
  *
  * @return string
  */
 public static function copyImages2($content, $destination, $isCopyFromRemoteHost = false)
 {
     if ($content == '') {
         return '';
     }
     // выбираю все изображения из контента
     $start = 0;
     $ret = [];
     do {
         $pos = Str::pos('src="/upload/HtmlContent/', $content, $start);
         if ($pos === false) {
             break;
         }
         $end = Str::pos('"', $content, $pos + 5);
         $src = Str::sub($content, $pos + 5, $end - $pos - 5);
         $ret[] = $src;
         $start = $end;
     } while (true);
     foreach ($ret as $src) {
         $imagePath = new SitePath($src);
         // картинка не содержит путь назначения?
         if (!Str::isContain($src, $destination->getPath())) {
             try {
                 $destinationFile = $destination->cloneObject()->add($imagePath->getFileName());
                 self::resizeImage($imagePath->getPathFull(), $destinationFile->getPathFull());
                 $content = Str::replace('src="' . $src . '"', 'src="' . $destinationFile->getPath() . '"', $content);
             } catch (\Exception $e) {
                 Yii::warning($e->getMessage(), 'gs\\HtmlContent\\copyImages');
             }
         }
     }
     return $content;
 }