public function up()
 {
     $this->execute('ALTER TABLE galaxysss_1.gs_unions_office ADD category VARCHAR(100) NULL;');
     $path = Yii::getAlias('@app/app/assets/1.xml');
     $data = file_get_contents($path);
     $x = new \DOMDocument();
     $x->loadXML($data);
     $ret = [];
     /** @var \DOMElement $element */
     foreach ($x->documentElement->childNodes as $element) {
         if ($element instanceof \DOMElement) {
             $data = $element->getAttribute('data-jmapping');
             $pos = Str::pos('lat', $data);
             $pos1 = Str::pos('lng', $data);
             $lat = Str::sub($data, $pos + 5, $pos1 - $pos - 7);
             $pos = Str::pos('lng', $data);
             $pos1 = Str::pos('category', $data);
             $lng = Str::sub($data, $pos + 5, $pos1 - $pos - 8);
             $pos = Str::pos('category', $data);
             $category = Str::sub($data, $pos + 11);
             $category = Str::sub($category, 0, Str::length($category) - 2);
             $category = explode('|', $category);
             $list = $element->getElementsByTagName("p");
             if ($list->length == 1) {
                 /** @var \DOMElement $content */
                 $content = $list->item(0);
                 $content = $x->saveXML($content);
                 $content = Str::sub($content, 3);
                 $content = Str::sub($content, 0, Str::length($content) - 4);
                 $content = explode('<br/>', $content);
                 $ret2 = [];
                 foreach ($content as $item) {
                     if (StringHelper::startsWith($item, '<b>')) {
                         $item = Str::sub($item, 3);
                         $item = Str::sub($item, 0, Str::length($item) - 4);
                     }
                     $ret2[] = trim($item);
                 }
                 $name = $ret2[0];
                 array_shift($ret2);
                 if (StringHelper::startsWith($ret2[count($ret2) - 1], 'Открытие')) {
                     $ret2 = array_reverse($ret2);
                     array_shift($ret2);
                     $ret2 = array_reverse($ret2);
                 }
                 if (StringHelper::startsWith($ret2[count($ret2) - 1], '"ВкусВилл')) {
                     $ret2 = array_reverse($ret2);
                     array_shift($ret2);
                     $ret2 = array_reverse($ret2);
                 }
                 $address = $ret2[0];
                 array_shift($ret2);
                 $ret[] = [392, $address, $name, $lat, $lng, join('|', $category), Html::tag('p', join('<br/>', $ret2))];
             }
         }
     }
     $this->batchInsert('gs_unions_office', ['union_id', 'point_address', 'name', 'point_lat', 'point_lng', 'category', 'content'], $ret);
 }
Example #2
0
 /**
  * Преобразовывает текст в HTML
  * Если в передаваемом параметре есть уже HTML то он не будет обработан
  *
  * @param string $content
  *
  * @return string
  */
 public static function convertPlainTextToHtml($content)
 {
     if (Str::pos('<', $content) === false) {
         $rows = explode("\r", $content);
         $rows2 = [];
         foreach ($rows as $row) {
             if (trim($row) != '') {
                 $rows2[] = Html::tag('p', trim($row));
             }
         }
         return join("\r\r", $rows2);
     }
     return $content;
 }
Example #3
0
 public function update($fieldsCols = null)
 {
     return parent::update(['beforeUpdate' => function ($fields) {
         if (Str::pos('<', $fields['content']) === false) {
             $rows = explode("\r", $fields['content']);
             $rows2 = [];
             foreach ($rows as $row) {
                 if (trim($row) != '') {
                     $rows2[] = Html::tag('p', trim($row));
                 }
             }
             $fields['content'] = join("\r\r", $rows2);
         }
         return $fields;
     }]);
 }
Example #4
0
 /**
  * Получает закешированные данные
  * @return array
  *   [
  *   'html' => ''
  *   'ids' => []
  *   ]
  *
  */
 public function get()
 {
     $path = $this->getPath();
     if (!file_exists($path)) {
         return '';
     }
     $data = file_get_contents($path);
     $pos = Str::pos(';', $data);
     $idsString = Str::sub($data, 0, $pos);
     if ($idsString == '') {
         $ids = [];
     } else {
         $ids = explode(',', $idsString);
     }
     $html = Str::sub($data, $pos + 1);
     return ['ids' => $ids, 'html' => $html];
 }
Example #5
0
 /**
  * Получает info дизайна
  *
  * @param $html
  *
  * @return array
  * [
  *    'image' => string
  *    'type' =>
  *        [
  *             'text'
  *             'href'
  *        ]
  *    'profile' =>
  *        [
  *             'text'
  *             'href'
  *        ]
  *    'definition' =>
  *        [
  *             'text'
  *        ]
  *    'inner' =>
  *        [
  *             'text'
  *        ]
  *    'strategy' =>
  *        [
  *             'text'
  *        ]
  *    'theme' =>
  *        [
  *             'text'
  *        ]
  *    'cross' =>
  *        [
  *             'text'
  *        ]
  * ]
  */
 private function getImageUrlFromHtml2($html)
 {
     $rows = explode('uk-width-1-1', $html);
     $items = explode('uk-text-primary', $rows[1]);
     $str = $items[1];
     $end = Str::pos('<', $str);
     $href = strrpos($items[0], '/');
     $href = substr($items[0], $href);
     $href = explode('>', $href);
     $Type = ['text' => Str::sub($str, 1, $end - 1), 'href' => '/types' . $href[0]];
     $items = explode('yourhumandesign.ru/profiles/profile-', $rows[2]);
     $str = $items[1];
     $Profile = ['text' => Str::sub($str, 5, 5), 'href' => '/profiles/profile-' . str_replace(' / ', '-', Str::sub($str, 5, 5))];
     $items = explode('uk-text-primary', $rows[3]);
     $str = $items[1];
     $end = Str::pos('<', $str);
     $Definition = ['text' => Str::sub($str, 2, $end - 2)];
     $items = explode('uk-text-primary', $rows[4]);
     $str = $items[1];
     $end = Str::pos('<', $str);
     $Inner = ['text' => Str::sub($str, 2, $end - 2)];
     $items = explode('uk-text-primary', $rows[5]);
     $str = $items[1];
     $end = Str::pos('<', $str);
     $Strategy = ['text' => Str::sub($str, 2, $end - 2)];
     $items = explode('uk-text-primary', $rows[6]);
     $str = $items[1];
     $end = Str::pos('<', $str);
     $Theme = ['text' => Str::sub($str, 2, $end - 2)];
     $items = explode('uk-text-primary', $rows[7]);
     $str = $items[1];
     $end = Str::pos('<', $str);
     $Cross = ['text' => Str::sub($str, 2, $end - 2)];
     $items = explode('http://www.jovianarchive.com/Content/Charts/', $rows[7]);
     $str = $items[1];
     $str = explode('.png', $str);
     $img = 'http://www.jovianarchive.com/Content/Charts/' . $str[0] . '.png';
     return ['image' => $img, 'type' => $Type, 'profile' => $Profile, 'definition' => $Definition, 'inner' => $Inner, 'strategy' => $Strategy, 'theme' => $Theme, 'cross' => $Cross];
 }
Example #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;
 }