Beispiel #1
0
 public function run($cat = 0)
 {
     $cat = (int) $cat;
     Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
     $headers = Yii::$app->response->headers;
     $headers->add('Content-Type', 'application/xml');
     $content = '<?xml version="1.0" encoding="UTF-8"?>';
     if ($cat <= 0) {
         $categories = Categories::find()->where(['status' => Categories::STATUS_ACTIVE])->select(['id'])->asArray()->all();
         $content .= '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
         foreach ($categories as $category) {
             $content .= '<sitemap>';
             $content .= '<loc>' . Url::to(['/feed/sitemap', 'cat' => $category['id']], true) . '</loc>';
             $content .= '</sitemap>';
         }
         $content .= '</sitemapindex>';
     } else {
         $advers = $this->controller->getModel(null, $cat);
         $content .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">';
         foreach ($advers as $adver) {
             $url = urldecode(Adver::generateLink($adver['id'], $adver['title'], $adver['category']['name'], $adver['country']['name'], $adver['province']['name'], $adver['city']['name'], $adver['address'], $adver['lang'], true));
             $content .= '<url>';
             $content .= "<loc>{$url}</loc>";
             $content .= "<changefreq>daily</changefreq>";
             $content .= '<priority>0.5</priority>';
             $content .= '<lastmod>' . date(DATE_W3C, $adver['updated_at']) . '</lastmod>';
             foreach ($adver['gallery'] as $gallery) {
                 $content .= '<image:image><image:loc>' . Gallery::getImageUrlFromOutside($gallery['name'], $gallery['adver_id'], 0, 0, 70, true) . '</image:loc></image:image>';
             }
             $content .= '</url>';
         }
         $content .= '</urlset>';
     }
     return $content;
 }
Beispiel #2
0
 public function run($ids)
 {
     $cacheKey = __NAMESPACE__ . __CLASS__ . 'infowindow' . $ids;
     $ids = explode('-', $ids);
     $makeCacheParam = [];
     foreach ($ids as $id) {
         $makeCacheParam[':p' . $id] = $id;
     }
     $makeCacheParam[':status'] = Adver::STATUS_ACTIVE;
     $cacheWhere = implode(',', array_keys($makeCacheParam));
     $cache = Yii::$app->getCache();
     if (!($model = $cache->get($cacheKey))) {
         $model = Adver::find()->select(['id', 'category_id', 'country_id', 'province_id', 'city_id', 'city_id', 'user_id', 'title', 'address', 'lang'])->with(['gallery' => function ($query) {
             $query->select(['id', 'adver_id', 'name', 'title']);
         }, 'category' => function ($query) {
             $query->select(['id', 'name']);
         }, 'country' => function ($query) {
             $query->select(['id', 'name']);
         }, 'province' => function ($query) {
             $query->select(['id', 'name']);
         }, 'city' => function ($query) {
             $query->select(['id', 'name']);
         }])->andWhere(['id' => $ids])->andWhere(['status' => Adver::STATUS_ACTIVE])->asArray()->all();
         $cache->set($cacheKey, $model, 2592000, new \yii\caching\DbDependency(['sql' => "SELECT MAX([[updated_at]]) FROM {{%adver}} WHERE [[id]] IN ({$cacheWhere})", 'params' => $makeCacheParam]));
     }
     $newModel = [];
     foreach ($model as $key => $value) {
         $address = '';
         if (isset($model[$key]['country']['name']) && $model[$key]['country']['name'] != '') {
             $address .= $model[$key]['country']['name'] . ', ';
         }
         if (isset($model[$key]['province']['name']) && $model[$key]['province']['name'] != '') {
             $address .= $model[$key]['province']['name'] . ', ';
         }
         if (isset($model[$key]['city']['name']) && $model[$key]['city']['name'] != '') {
             $address .= $model[$key]['city']['name'] . ', ';
         }
         $address = rtrim($address, ', ');
         $newModel[$key]['full_address'] = Html::encode($address);
         $newModel[$key]['address'] = Html::encode($model[$key]['address']);
         $newModel[$key]['title'] = Html::encode($model[$key]['title']);
         $newModel[$key]['category'] = Html::encode($model[$key]['category']['name']);
         $newModel[$key]['url'] = Adver::generateLink($model[$key]['id'], $model[$key]['title'], $model[$key]['category']['name'], $model[$key]['country']['name'], $model[$key]['province']['name'], $model[$key]['city']['name'], $model[$key]['address'], $model[$key]['lang']);
         $newGallery = [];
         foreach ($value['gallery'] as $gallery) {
             $newGallery[] = ['url' => Gallery::getImageUrlFromOutside($gallery['name'], $gallery['adver_id'], 160, 105), 'title' => Html::encode($gallery['title']), 'adver_id' => $gallery['adver_id']];
         }
         $newModel[$key]['gallery'] = $newGallery;
     }
     return Json::encode($newModel);
 }
Beispiel #3
0
        ?>
					<?php 
        $this->registerMetaTag(['name' => 'og:image', 'content' => Gallery::getImageUrlFromOutside($gallery['name'], $gallery['adver_id'], 0, 0, 70, true)]);
        ?>
					<a class="fancyGallery" rel="gallery<?php 
        echo $gallery['adver_id'];
        ?>
" href="<?php 
        echo Gallery::getImageUrlFromOutside($gallery['name'], $gallery['adver_id']);
        ?>
" title="<?php 
        echo Html::encode($gallery['title']);
        ?>
">
						<img class="img-thumbnail img-responsive" src="<?php 
        echo Gallery::getImageUrlFromOutside($gallery['name'], $gallery['adver_id'], 160, 105);
        ?>
" alt="<?php 
        echo Html::encode($gallery['title']);
        ?>
" />
					</a>
					<?php 
    }
    ?>
				</div>
				<?php 
}
?>
				<?php 
if (!empty($model['attachment'])) {
Beispiel #4
0
use yii\helpers\Html;
//use yii\helpers\HtmlPurifier;
//use yii\widgets\DetailView;
use yii\helpers\StringHelper;
use common\models\adver\Adver;
use common\models\gallery\Gallery;
/* @var $model common\models\adver\Adver */
?>
<div class="col-sm-6 col-md-3">
	<div class="thumbnail">
		<?php 
$imageIndex = 0;
$galleryCount = count($model->gallery);
foreach ($model->gallery as $key => $gallery) {
    $imageUrl = Gallery::getImageUrlFromOutside($gallery['name'], $gallery['adver_id'], 242, 200);
    $imageIndex = $key + 1;
    $galleryStyle = ($galleryCount !== 1 ? 'cursor: pointer;' : '') . ($imageIndex !== 1 ? 'display: none;' : '');
    $imageScript = $galleryCount !== 1 ? "jQuery('#adversListImage" . $gallery->adver_id . $imageIndex . "').hide();" : '';
    $imageScript .= $galleryCount === $imageIndex ? "jQuery('#adversListImage" . $gallery->adver_id . "1').show();" : "jQuery('#adversListImage" . $gallery->adver_id . ($imageIndex + 1) . "').show();";
    echo '<img class="img-thumbnail img-responsive" id="adversListImage' . $gallery->adver_id . $imageIndex . '" onclick="' . $imageScript . '" alt="' . $gallery->title . '" style="' . $galleryStyle . '" src="' . $imageUrl . '"/>';
}
$address = '';
if (isset($model['country']['name']) && $model['country']['name'] != '') {
    $address .= $model['country']['name'] . ', ';
}
if (isset($model['province']['name']) && $model['province']['name'] != '') {
    $address .= $model['province']['name'] . ', ';
}
if (isset($model['city']['name']) && $model['city']['name'] != '') {
    $address .= $model['city']['name'] . ', ';