/**
  * @return string
  */
 public function actionIndex()
 {
     /* @var $lastPost \common\models\Post */
     $response = Yii::$app->response;
     $response->headers->set('Content-Type', 'text/xml; charset=UTF-8');
     $response->format = $response::FORMAT_RAW;
     $lastPost = Post::find()->where(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC])->one();
     return $this->renderPartial('index', ['title' => Option::get('sitetitle'), 'description' => Option::get('tagline'), 'link' => Yii::$app->request->absoluteUrl, 'lastBuildDate' => new \DateTime($lastPost->post_date, new \DateTimeZone(Option::get('time_zone'))), 'postTypes' => PostType::find()->all(), 'language' => Yii::$app->language, 'generator' => 'http://www.writesdown.com']);
 }
Exemple #2
0
 /**
  * Get menu dropdown for post type.
  *
  * @return array
  */
 protected function getPostTypeMenu()
 {
     /* @var $urlManagerBack \yii\web\UrlManager */
     /* @var $postTypes \common\models\PostType[] */
     $urlManagerBack = Yii::$app->urlManagerBack;
     $menuItems = [];
     $postTypes = PostType::find()->select(['id', 'post_type_sn', 'post_type_permission'])->all();
     foreach ($postTypes as $postType) {
         $menuItems[] = ['label' => $postType->post_type_sn, 'url' => $urlManagerBack->createUrl(['/post/create', 'post_type' => $postType->id]), 'visible' => Yii::$app->user->can($postType->post_type_permission)];
     }
     return $menuItems;
 }
Exemple #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PostTypeModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'menu_builder' => $this->menu_builder]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'icon', $this->icon])->andFilterWhere(['like', 'singular_name', $this->singular_name])->andFilterWhere(['like', 'plural_name', $this->plural_name])->andFilterWhere(['like', 'permission', $this->permission]);
     return $dataProvider;
 }
Exemple #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PostTypeModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'post_type_smb' => $this->post_type_smb]);
     $query->andFilterWhere(['like', 'post_type_name', $this->post_type_name])->andFilterWhere(['like', 'post_type_slug', $this->post_type_slug])->andFilterWhere(['like', 'post_type_description', $this->post_type_description])->andFilterWhere(['like', 'post_type_icon', $this->post_type_icon])->andFilterWhere(['like', 'post_type_sn', $this->post_type_sn])->andFilterWhere(['like', 'post_type_pn', $this->post_type_pn])->andFilterWhere(['like', 'post_type_permission', $this->post_type_permission]);
     return $dataProvider;
 }
Exemple #5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PostTypeModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'post_type_smb' => $this->post_type_smb]);
     $query->andFilterWhere(['like', 'post_type_name', $this->post_type_name])->andFilterWhere(['like', 'post_type_slug', $this->post_type_slug])->andFilterWhere(['like', 'post_type_description', $this->post_type_description])->andFilterWhere(['like', 'post_type_icon', $this->post_type_icon])->andFilterWhere(['like', 'post_type_sn', $this->post_type_sn])->andFilterWhere(['like', 'post_type_pn', $this->post_type_pn])->andFilterWhere(['like', 'post_type_permission', $this->post_type_permission]);
     return $dataProvider;
 }
 /**
  * Displays menu page consists of CRUD for Menu and MenuItem model.
  *
  * @param null $id
  * @return mixed
  */
 public function actionIndex($id = null)
 {
     $model = new Menu();
     $postTypes = PostType::find()->where(['menu_builder' => PostType::MENU_BUILDER])->all();
     $taxonomies = Taxonomy::find()->where(['menu_builder' => Taxonomy::MENU_BUILDER])->all();
     if ($available = ArrayHelper::map(Menu::find()->all(), 'id', 'title')) {
         if ($id === null && $available) {
             reset($available);
             $id = key($available);
         }
         $selected = $this->findModel($id);
     }
     return $this->render('index', ['model' => $model, 'available' => $available, 'selected' => isset($selected) ? $selected : null, 'postTypes' => $postTypes, 'taxonomies' => $taxonomies]);
 }
Exemple #7
0
 /**
  * Generates menu page consists of CRUD Menu and MenuItem model.
  *
  * @param null $id
  *
  * @return mixed
  */
 public function actionIndex($id = null)
 {
     $model = new Menu();
     // List all post types
     $postTypes = PostType::find()->where(['post_type_smb' => 1])->all();
     // List all taxonomies
     $taxonomies = Taxonomy::find()->where(['taxonomy_smb' => 1])->all();
     // Get available menu
     if ($availableMenu = ArrayHelper::map(Menu::find()->all(), 'id', 'menu_title')) {
         if ($id === null && $availableMenu) {
             reset($availableMenu);
             $id = key($availableMenu);
         }
         $selectedMenu = $this->findModel($id);
     }
     return $this->render('index', ['model' => $model, 'availableMenu' => $availableMenu, 'selectedMenu' => isset($selectedMenu) ? $selectedMenu : null, 'postTypes' => $postTypes, 'taxonomies' => $taxonomies]);
 }
 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     /*  @var $postType \common\models\PostType */
     /*  @var $taxonomy \common\models\Taxonomy */
     if (parent::beforeAction($action)) {
         $this->_defaultOption['enable_sitemap'] = 1;
         $this->_defaultOption['entries_per_page'] = 1000;
         // Home
         $this->_defaultOption['home'] = ['priority' => '1.0', 'changefreq' => 'daily'];
         // Post type default option
         foreach (PostType::find()->all() as $postType) {
             $this->_defaultOption['post_type'][$postType->id] = ['enable' => 1, 'priority' => '0.6', 'changefreq' => 'weekly'];
         }
         // Taxonomy default option
         foreach (Taxonomy::find()->all() as $taxonomy) {
             $this->_defaultOption['taxonomy'][$taxonomy->id] = ['enable' => 1, 'priority' => '0.2', 'changefreq' => 'weekly'];
         }
         // Media default option
         $this->_defaultOption['media'] = ['enable' => 0, 'priority' => '0.2', 'changefreq' => 'monthly'];
         return true;
     }
     return false;
 }
 /**
  * @param string $type
  * @param string $slug
  * @param int    $page
  *
  * @return string
  */
 public function actionView($type, $slug, $page = 1)
 {
     /* @var $taxonomy Taxonomy */
     /* @var $postType PostType */
     /* @var $posts Post[] */
     /* @var $images Media[] */
     /* @var $terms Term[] */
     /* @var $mediaSet Media[] */
     /* @var $post Post */
     $page--;
     $items = [];
     $response = Yii::$app->response;
     $response->headers->set('Content-Type', 'text/xml; charset=UTF-8');
     $response->format = $response::FORMAT_RAW;
     if ($type === 'h') {
         $item['loc'] = Yii::$app->urlManager->hostInfo . Yii::$app->urlManager->baseUrl;
         $item['changefreq'] = $this->_option['home']['changefreq'];
         $item['priority'] = $this->_option['home']['priority'];
         return $this->renderPartial('home', ['item' => $item]);
     } elseif ($type === 'p') {
         $postType = PostType::find()->where(['post_type_slug' => $slug])->one();
         $posts = $postType->getPosts()->andWhere(['post_status' => 'publish'])->offset($page * $this->_option['entries_per_page'])->limit($this->_option['entries_per_page'])->all();
         foreach ($posts as $post) {
             $lastmod = new \DateTime($post->post_modified, new \DateTimeZone(Option::get('time_zone')));
             $items[$post->id]['loc'] = $post->url;
             $items[$post->id]['lastmod'] = $lastmod->format('r');
             $items[$post->id]['changefreq'] = $this->_option['post_type'][$postType->id]['changefreq'];
             $items[$post->id]['priority'] = $this->_option['post_type'][$postType->id]['priority'];
             if ($images = $post->getMedia()->where(['LIKE', 'media_mime_type', 'image/'])->all()) {
                 foreach ($images as $image) {
                     $metadata = $image->getMeta('metadata');
                     $items[$post->id]['image'][$image->id]['loc'] = $image->uploadUrl . $metadata['media_versions']['full']['url'];
                     $items[$post->id]['image'][$image->id]['title'] = $image->media_title ? $image->media_title : null;
                     $items[$post->id]['image'][$image->id]['caption'] = $image->media_excerpt ? $image->media_excerpt : null;
                 }
             }
         }
         return $this->renderPartial('post-type', ['items' => $items]);
     } elseif ($type === 'c') {
         $taxonomy = Taxonomy::find()->where(['taxonomy_slug' => $slug])->one();
         $terms = $taxonomy->getTerms()->offset($page * $this->_option['entries_per_page'])->limit($this->_option['entries_per_page'])->all();
         foreach ($terms as $term) {
             $post = $term->getPosts()->andWhere(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC])->one();
             if ($post) {
                 $lastmod = new \DateTime($post->post_modified, new \DateTimeZone(Option::get('time_zone')));
                 $items[$term->id]['loc'] = $term->url;
                 $items[$term->id]['lastmod'] = $lastmod->format('r');
                 $items[$term->id]['changefreq'] = $this->_option['taxonomy'][$taxonomy->id]['changefreq'];
                 $items[$term->id]['priority'] = $this->_option['taxonomy'][$taxonomy->id]['priority'];
             }
         }
         return $this->renderPartial('taxonomy', ['items' => $items]);
     } elseif ($type === 'm') {
         $mediaSet = Media::find()->offset($page * $this->_option['entries_per_page'])->limit($this->_option['entries_per_page'])->all();
         foreach ($mediaSet as $media) {
             $lastmod = new \DateTime($media->media_modified, new \DateTimeZone(Option::get('time_zone')));
             $items[$media->id]['loc'] = $media->url;
             $items[$media->id]['lastmod'] = $lastmod->format('r');
             $items[$media->id]['changefreq'] = $this->_option['media']['changefreq'];
             $items[$media->id]['priority'] = $this->_option['media']['priority'];
         }
         return $this->renderPartial('media', ['items' => $items]);
     }
     return $this->redirect(['/site/not-found']);
 }
Exemple #10
0
    <div class="form-group">
        <?php 
echo Html::label(Yii::t('writesdown', 'Front page displays'), null, ['class' => 'col-sm-2 control-label']);
?>

        <div class="col-sm-7">
            <?php 
echo Html::radioList('Option[show_on_front][value]', $model->show_on_front->value, ['posts' => Yii::t('writesdown', 'Latest posts')], ['separator' => '<br />', 'class' => 'radio']);
?>

            <?php 
echo Html::label(Yii::t('writesdown', 'Front page: '), 'option-front_page');
?>

            <?php 
echo Html::dropDownList('Option[front_post_type][value]', $model->front_post_type->value, ArrayHelper::merge(['all' => 'All'], ArrayHelper::map(PostType::find()->all(), 'name', 'singular_name')), ['class' => 'form-control']);
?>

        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-7 col-sm-push-2">
            <?php 
echo Html::radioList('Option[show_on_front][value]', $model->show_on_front->value, ['page' => Yii::t('writesdown', 'Static page')], ['separator' => '<br />', 'class' => 'radio']);
?>

            <?php 
echo Html::label(Yii::t('writesdown', 'Front page: '), 'option-front_page');
?>

            <?php 
Exemple #11
0
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param $post_type
  *
  * @throws \yii\web\NotFoundHttpException
  * @return PostType the loaded model
  */
 protected function findPostTypeBySlug($post_type)
 {
     $model = PostType::find()->andWhere(['post_type_slug' => $post_type])->one();
     if ($model) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }