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; }
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); }
public function getFeed($mode) { $feedMethod = 'rss'; if ($mode == self::RSS) { $feedMethod = 'rss'; } elseif ($mode == self::ATOM) { $feedMethod = 'atom'; } $feed = new \Zend\Feed\Writer\Feed(); $feed->setTitle(Yii::t('app', 'Introduce business')); $feed->setDescription(Yii::t('app', 'Introduce business')); $feed->setLink(Yii::$app->getRequest()->getHostInfo()); $feed->setFeedLink(Yii::$app->getRequest()->getAbsoluteUrl(), $feedMethod); $feed->setGenerator('Admap', Yii::$app->version, Yii::$app->getRequest()->getHostInfo()); $feed->addAuthor(['name' => 'Jafaripur', 'email' => '*****@*****.**', 'uri' => 'http://www.jafaripur.ir']); $feed->setDateModified(time()); //$feed->addHub('http://pubsubhubbub.appspot.com/'); foreach ($this->getModel(50) as $adver) { $entry = $feed->createEntry(); $entry->setId($adver['id']); $entry->setTitle(Html::encode($adver['title'])); $entry->addCategory(['term' => Html::encode($adver['category']['name']), 'label' => Html::encode($adver['category']['name'])]); $entry->setLink(urldecode(Adver::generateLink($adver['id'], $adver['title'], $adver['category']['name'], $adver['country']['name'], $adver['province']['name'], $adver['city']['name'], $adver['address'], $adver['lang'], true))); /*$entry->addAuthor(array( 'name' => 'Paddy', 'email' => '*****@*****.**', 'uri' => 'http://www.example.com', ));*/ $entry->setDateModified((int) $adver['updated_at']); $entry->setDateCreated((int) $adver['created_at']); $entry->setDescription(\yii\helpers\StringHelper::truncate(strip_tags($adver['description']), 140)); //$entry->setContent ($description); $feed->addEntry($entry); } return $feed->export($feedMethod); }
$this->title = Yii::t('app', 'My advertisement'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="row"> <div class="col-md-12"> <div class="table table-responsive"> <div id="adver-message-container"></div> <?php echo Alert::widget(); ?> <?php Pjax::begin(['id' => 'adverList-pjax', 'enablePushState' => true, 'timeout' => '20000']); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'title', 'format' => 'raw', 'value' => function ($data) { return Html::a(Html::encode($data->title), Adver::generateLink($data['id'], $data['title'], $data['category']['name'], $data['country']['name'], $data['province']['name'], $data['city']['name'], $data['address'], $data['lang']), ['data-pjax' => '0', 'target' => '_blank']); }], 'category.name', 'country.name', 'province.name', 'city.name', 'lang', ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'created_at', 'value' => function ($data) { return Yii::$app->dateTimeAction->timeToDate('l j F Y H:i', $data->created_at); }], ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'updated_at', 'value' => function ($data) { return Yii::$app->dateTimeAction->timeToDate('l j F Y H:i', $data->updated_at); }], ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'status', 'filter' => $searchModel->getStatusList(), 'format' => 'html', 'value' => function ($data) { return $data->getStatusImage($data->status); }], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update}', 'buttons' => ['update' => function ($url, $model, $key) { return Yii::$app->helper->createUpdateButton($url); }]], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'buttons' => ['delete' => function ($url, $model, $key) { return Yii::$app->helper->createDeleteButton(Url::to(['/adver/delete', 'id' => $model->id]), '', 'adverList-pjax', 'adver-message-container'); }]]]]); ?> <?php Pjax::end(); ?>
<?php } ?> <div class="caption"> <h3><?php echo Html::encode($model->title); ?> </h3> <p><?php echo StringHelper::truncateWords($model->description, 40, '...', false); ?> </p> <p><span class="label label-success"><?php echo Html::encode($model['category']['name']); ?> </span> <span class="label label-success"><?php echo Html::encode($address); ?> </span></p> <p><a target="_blank" data-pjax="0" class="btn btn-info" href="<?php echo Adver::generateLink($model['id'], $model['title'], $model['category']['name'], $model['country']['name'], $model['province']['name'], $model['city']['name'], $model['address'], $model['lang']); ?> "><?php echo Yii::t('app', 'Detail'); ?> </a></p> </div> </div> </div>