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); }
/** * Возвращает название статьи * * @return string */ public function getHeader() { $h4 = $this->getDocument()->find('div.rt-article/.module-content/h4')[0]; $name = $h4->plaintext; if (Str::sub($name, 0, 1) == '«') { $name = Str::sub($name, 1); } if (Str::sub($name, Str::length($name) - 1, 1) == '»') { $name = Str::sub($name, 0, Str::length($name) - 1); } $name = Str::sub($name, 0, 1) . Str::toLower(Str::sub($name, 1)); return $name; }
/** * Получает закешированные данные * @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]; }
/** * Возвращает массив чистых строк без тегов * * @return array */ public function getContentAsArray() { $html = $this->getObjArticle(); $ret = []; foreach ($html->find('div.td-post-text-content/p') as $p) { if ($p instanceof \simple_html_dom_node) { if ($p->children[0]->tag != 'noindex') { $string = trim($p->plaintext); if (StringHelper::startsWith($string, ' ')) { $string = Str::sub($string, 6); } $ret[] = $string; } } } return $ret; }
/** * @return array * [[ * 'name' * 'url' * ],...] */ public function getItems() { $doc = $this->getDocument($this->url); $ret = []; foreach ($doc->find('.rt-leading-articles/.rt-article') as $div) { $a = $div->find('.module-title/a')[0]; $url = 'http://www.ronnastar.com' . $a->attr['href']; $h4 = $div->find('.module-content/h4')[0]; $name = $h4->plaintext; if (Str::sub($name, 0, 1) == '«') { $name = Str::sub($name, 1); } if (Str::sub($name, Str::length($name) - 1, 1) == '»') { $name = Str::sub($name, 0, Str::length($name) - 1); } $name = Str::sub($name, 0, 1) . Str::toLower(Str::sub($name, 1)); $ret[] = ['name' => $name, 'url' => $url]; } return $ret; }
/** * @return array * [[ * 'name' * 'url' * ],...] */ public function getItems() { $doc = $this->getDocument($this->url); $ret = []; $c = 1; foreach ($doc->find('.wall_item') as $div) { if ($c > 1) { $url = 'https://vk.com' . $div->find('.wi_date')[0]->attr['href']; $html = $div->find('.pi_text')[0]; $header = explode('..............................', $html->plaintext); $header = trim($header[0]); if (StringHelper::endsWith($header, '.')) { $header = Str::sub($header, 0, Str::length($header) - 1); } $header = Str::toLower($header); $first = Str::toUpper(Str::sub($header, 0, 1)); $header = $first . Str::sub($header, 1); $ret[] = ['name' => $header, 'url' => $url]; } $c++; } return $ret; }
<img src="<?php echo $item['image']; ?> " class="thumbnail" width="80"> <?php } ?> </div> <div class="col-lg-9"> <?php echo Html::tag('span', GsssHtml::dateString($item['date_insert']), ['style' => 'font-size: 80%; margin-bottom:10px; color: #c0c0c0;']); ?> <br> <?php echo \cs\services\Str::sub(strip_tags($item['content']), 0, 200) . '...'; ?> <br> <br> <button class="btn btn-danger btn-xs buttonDelete" data-id="<?php echo $item['id']; ?> ">Удалить</button> <?php if (\yii\helpers\ArrayHelper::getValue($item, 'is_added_site_update', 0) == 0) { ?> <button class="btn btn-success btn-xs buttonAddSiteUpdate" data-id="<?php echo $item['id']; ?> ">Сделать рассылку</button> <?php
<div class="col-lg-3"> <?php if ($item['image'] . '' != '') { ?> <img src="<?php echo $item['image']; ?> " class="thumbnail" width="80"> <?php } ?> </div> <div class="col-lg-9"> <?php echo \cs\services\Str::sub(strip_tags($item['description']), 0, 200) . '...'; ?> <br> <br> <button class="btn btn-danger btn-xs buttonDelete" data-id="<?php echo $item['id']; ?> ">Удалить</button> <?php if (\yii\helpers\ArrayHelper::getValue($item, 'is_added_site_update', 0) == 0) { ?> <button class="btn btn-success btn-xs buttonAddSiteUpdate" data-id="<?php echo $item['id']; ?> ">Сделать рассылку</button> <?php }
</p> <?php } ?> <?php } ?> <hr> <?php echo \app\services\Page::linkToSite($item->getField('link')); ?> <?php echo $this->render('../blocks/share', ['image' => \cs\Widget\FileUpload2\FileUpload::getOriginal(\yii\helpers\Url::to($item->getField('img'), true), false), 'url' => \yii\helpers\Url::current([], true), 'title' => $item->getField('name'), 'description' => trim(\cs\services\Str::sub(strip_tags($item->getField('description')), 0, 200))]); //\cs\services\VarDumper::dump($category); ?> <?php if ($item->hasShop() && \yii\helpers\ArrayHelper::getValue(Yii::$app->params, 'isShop', 0) == 1) { ?> <a class="btn btn-primary" href="<?php echo \yii\helpers\Url::to(['union_shop/index', 'id' => $item->getId(), 'category' => $category->getField('id_string')]); ?> ">Магазин</a> <?php } ?> </div>
<?php if ($item['source'] != '') { ?> <?php echo Html::a('Ссылка на источник »', $item['source'], ['class' => 'btn btn-primary', 'target' => '_blank']); ?> <?php } ?> <?php } $image = $item['image']; ?> <?php echo $this->render('../blocks/share', ['image' => \cs\Widget\FileUpload2\FileUpload::getOriginal(Url::to($item['image'], true), false), 'url' => Url::current([], true), 'title' => $item['header'], 'description' => trim(Str::sub(strip_tags($item['content']), 0, 200))]); ?> <?php //= \app\modules\Comment\Service::render(\app\modules\Comment\Model::TYPE_ARTICLE, $item['id']); ?> </div> <div class="col-lg-4"> <?php if (\yii\helpers\ArrayHelper::getValue(Yii::$app->params, 'isMarketing', 0) == 1 && date('Y-m-d') < '2015-10-30') { ?> <?php echo $this->render('../blocks/reklama'); ?> <?php
/** * Получает 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]; }
/** * Создает краткое содержимое текста, которое может быть также и HTML * * @param string $text * @param int $len * * @return string plain text */ public static function getMiniText($text, $len = 200) { $htmlSpecial = [' ' => ' ', '—' => '—']; $strip = strip_tags($text); foreach ($htmlSpecial as $code => $replaceChar) { $strip = str_replace($code, $replaceChar, $strip); } $strip = trim($strip); if (Str::length($strip) > $len) { return Str::sub($strip, 0, $len) . ' ...'; } return $strip; }
<h1 class="page-header"><?php echo $this->title; ?> </h1> </div> <div class="col-lg-12"> <div class="col-lg-4 col-lg-offset-4"> <p class="text-center"> <img class="thumbnail" src="<?php echo $item->getField('image'); ?> " width="100%" alt=""> </p> </div> </div> <div class="col-lg-12"> <div class="col-lg-10 col-lg-offset-1"> <?php echo $item->getField('content'); ?> <hr> <?php echo $this->render('../blocks/share', ['image' => $item->getField('image') != '' ? Url::to(\cs\Widget\FileUpload2\FileUpload::getOriginal($item->getField('image')), true) : '', 'url' => Url::current([], true), 'title' => $item->getField('name'), 'description' => trim(\cs\services\Str::sub(strip_tags($item->getField('content')), 0, 200))]); ?> </div> </div> </div>
/** * Возвращает название статьи * * @return string */ public function getHeader() { $html = $this->getObjArticle(); $header = explode('..............................', $html->plaintext); $header = trim($header[0]); if (StringHelper::endsWith($header, '.')) { $header = Str::sub($header, 0, Str::length($header) - 1); } $header = Str::toLower($header); $first = Str::toUpper(Str::sub($header, 0, 1)); $header = $first . Str::sub($header, 1); return $header; }
foreach ($lastList as $item) { ?> <div class="thumbnail"> <a href="<?php echo \app\services\GsssHtml::getPrakticeUrl($item); ?> "><img src="<?php echo $item['image']; ?> " style="width: 100%; display: block;" > </a> <div class="caption"> <h3> <?php echo $item['header']; ?> </h3> <p> <?php echo trim(Str::sub($item['description'], 0, 200)); ?> </p> </div> </div> <?php } ?> </div> </div>
/** * Выбирает все картинки копирует в папку назначения заменяет в $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; }