Esempio n. 1
0
 public static function generate()
 {
     // Там еще в сайтмепе есть приоритетность. Для главной ставим самую высокую, для всех категорий чуть ниже и последняя приоритетность для постов
     //Создает XML-строку и XML-документ при помощи DOM
     $dom = new DomDocument('1.0');
     //добавление корня - <books>
     $urlset = $dom->appendChild($dom->createElement('urlset'));
     $urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     // Главная страница
     $url = $urlset->appendChild($dom->createElement('url'));
     $loc = $url->appendChild($dom->createElement('loc'));
     $loc->appendChild($dom->createTextNode("http://" . $_SERVER['SERVER_NAME']));
     $priority = $url->appendChild($dom->createElement('priority'));
     $priority->appendChild($dom->createTextNode('1.0'));
     // Категории фото
     $categoryPhoto = CategoryPhoto::find()->all();
     foreach ($categoryPhoto as $category) {
         $url = $urlset->appendChild($dom->createElement('url'));
         $loc = $url->appendChild($dom->createElement('loc'));
         $loc->appendChild($dom->createTextNode("http://" . $_SERVER['SERVER_NAME'] . "/category/photo/" . $category->url));
         $priority = $url->appendChild($dom->createElement('priority'));
         $priority->appendChild($dom->createTextNode('0.7'));
     }
     // Категории видео
     $categoryVideo = Category::find()->all();
     foreach ($categoryVideo as $category) {
         $url = $urlset->appendChild($dom->createElement('url'));
         $loc = $url->appendChild($dom->createElement('loc'));
         $loc->appendChild($dom->createTextNode("http://" . $_SERVER['SERVER_NAME'] . "/category/video/" . $category->url));
         $priority = $url->appendChild($dom->createElement('priority'));
         $priority->appendChild($dom->createTextNode('0.7'));
     }
     // Страницы фото
     $photoCatalog = PhotoCatalog::find()->where('publish = 1')->all();
     foreach ($photoCatalog as $photo) {
         $url = $urlset->appendChild($dom->createElement('url'));
         $loc = $url->appendChild($dom->createElement('loc'));
         $loc->appendChild($dom->createTextNode("http://" . $_SERVER['SERVER_NAME'] . "/photo/" . $photo->category->url . "/" . $photo->url));
         $priority = $url->appendChild($dom->createElement('priority'));
         $priority->appendChild($dom->createTextNode('0.5'));
     }
     // Страницы видео
     $videos = Video::find()->where('publish = 1')->all();
     foreach ($videos as $video) {
         $url = $urlset->appendChild($dom->createElement('url'));
         $loc = $url->appendChild($dom->createElement('loc'));
         $loc->appendChild($dom->createTextNode("http://" . $_SERVER['SERVER_NAME'] . "/video/" . $video->category->url . "/" . $video->url));
         $priority = $url->appendChild($dom->createElement('priority'));
         $priority->appendChild($dom->createTextNode('0.5'));
     }
     //генерация xml
     $dom->formatOutput = true;
     // установка атрибута formatOutput
     // domDocument в значение true
     // save XML as string or file
     //$test1 = $dom->saveXML(); // передача строки в test1
     $dom->save('../web/sitemap.xml');
     // сохранение файла
 }
Esempio n. 2
0
 public function run()
 {
     if ($this->type == 'video') {
         $categoryShow = Category::find()->where('show_expand = :show_expand', [':show_expand' => true])->orderBy('sort')->all();
         $categoryHide = Category::find()->where('show_expand = :show_expand', [':show_expand' => false])->orderBy('sort')->all();
     }
     if ($this->type == 'photo') {
         $categoryShow = CategoryPhoto::find()->where('show_expand = :show_expand', [':show_expand' => true])->orderBy('sort')->all();
         $categoryHide = CategoryPhoto::find()->where('show_expand = :show_expand', [':show_expand' => false])->orderBy('sort')->all();
     }
     if ($this->type == 'video') {
         return $this->render("category", ['categoryShow' => $categoryShow, 'categoryHide' => $categoryHide, 'type' => $this->type]);
     }
     if ($this->type == 'photo') {
         return $this->render("category_photo", ['categoryShow' => $categoryShow, 'categoryHide' => $categoryHide, 'type' => $this->type]);
     }
 }
Esempio n. 3
0
 public function actionIndex($type, $url)
 {
     if ($type != 'photo' && $type != 'video') {
         throw new HttpException(404);
     }
     if ($type == 'video') {
         $category = Category::find()->where('url = :url', [':url' => $url])->one();
     }
     if ($type == 'photo') {
         $category = CategoryPhoto::find()->where('url = :url', [':url' => $url])->one();
     }
     if ($category == null) {
         throw new HttpException(404);
     }
     if ($type == 'video') {
         $videos = Video::find()->where('category_id = :category_id && publish = :publish', [':category_id' => $category->id, ':publish' => 1])->orderBy('id DESC')->all();
         return $this->render('video', ['videos' => $videos, 'category' => $category]);
     }
     if ($type == 'photo') {
         $photo = PhotoCatalog::find()->where('category_id = :category_id && publish = :publish', [':category_id' => $category->id, ':publish' => 1])->orderBy('id DESC')->all();
         return $this->render('photo', ['photos' => $photo, 'category' => $category]);
     }
 }
Esempio n. 4
0

    <?php 
echo $form->field($model, 'actor')->textInput([['maxlength' => true]]);
?>

    <?php 
echo $form->field($model, 'description')->textarea(['rows' => 6]);
?>

    <?php 
echo $form->field($model, 'alt')->textInput([]);
?>

    <?php 
echo $form->field($model, 'category_id')->dropDownList(ArrayHelper::map(CategoryPhoto::find()->all(), 'id', 'name'), ['prompt' => 'Выберите категорию']);
?>

    <?php 
echo $form->field($model, 'photosUpload')->fileInput();
?>

    <?php 
echo $form->field($model, 'photoPreviewUpload')->fileInput();
?>



    <?php 
//echo $form->field($model, 'meta_keywords')->textInput(['maxlength' => true]);
?>
 /**
  * Finds the CategoryPhoto model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CategoryPhoto the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CategoryPhoto::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(CategoryPhoto::className(), ['id' => 'category_id']);
 }