/**
  * Displays a single User model.
  *
  * @param null $id
  * @param      $username
  *
  * @return mixed
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionView($id = null, $username = null)
 {
     $render = '/author/view';
     if ($id) {
         $model = $this->findModel($id);
     } else {
         if ($username) {
             $model = $this->findModelByUsername($username);
         } else {
             throw new NotFoundHttpException('The requested page does not exist.');
         }
     }
     $query = $model->getPosts()->andWhere(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => Option::get('posts_per_page')]);
     $query->offset($pages->offset)->limit($pages->limit);
     $posts = $query->all();
     if ($posts) {
         if (is_file($this->view->theme->basePath . '/author/view-' . $model->username . '.php')) {
             $render = 'view-' . $model->username . '.php';
         }
         return $this->render($render, ['user' => $model, 'posts' => $posts, 'pages' => isset($pages) ? $pages : null]);
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionCreate($post_type)
 {
     $model = new Post();
     $postType = $this->findPostType($post_type);
     $model->post_comment_status = Option::get('default_comment_status');
     if (!Yii::$app->user->can($postType->post_type_permission)) {
         throw new ForbiddenHttpException(Yii::t('content', 'You are not allowed to perform this action.'));
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->post_type = $postType->id;
         $model->post_date = Yii::$app->formatter->asDatetime($model->post_date, 'php:Y-m-d H:i:s');
         if ($model->save()) {
             if ($termIds = Yii::$app->request->post('termIds')) {
                 foreach ($termIds as $termId) {
                     $termRelationship = new TermRelationship();
                     $termRelationship->term_id = $termId;
                     $termRelationship->post_id = $model->id;
                     if ($termRelationship->save() && ($term = $this->findTerm($termId))) {
                         $term->term_count++;
                         $term->save();
                     }
                 }
             }
             if ($meta = Yii::$app->request->post('meta')) {
                 foreach ($meta as $meta_name => $meta_value) {
                     $model->setMeta($meta_name, $meta_value);
                 }
             }
             Yii::$app->getSession()->setFlash('success', Yii::t('content', '{post_type} successfully saved.', ['post_type' => $postType->post_type_sn]));
             return $this->redirect(['update', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model, 'postType' => $postType]);
 }
 /**
  * @param int|null    $id        ID of post-type.
  * @param string|null $post_type Slug of post-type.
  *
  * @return string
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionIndex($id = null, $post_type = null)
 {
     $render = 'index';
     if ($id) {
         $postType = $this->findPostType($id);
     } else {
         if ($post_type) {
             $postType = $this->findPostTypeBySlug($post_type);
         } else {
             throw new NotFoundHttpException(Yii::t('content', 'The requested page does not exist.'));
         }
     }
     $query = $postType->getPosts()->andWhere(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => Option::get('posts_per_page')]);
     $query->offset($pages->offset)->limit($pages->limit);
     $posts = $query->all();
     if ($posts) {
         if (is_file($this->view->theme->basePath . '/post/index-' . $postType->post_type_slug . '.php')) {
             $render = 'index-' . $postType->post_type_slug . '.php';
         }
         return $this->render($render, ['postType' => $postType, 'posts' => $posts, 'pages' => $pages]);
     } else {
         throw new NotFoundHttpException(Yii::t('content', 'The requested page does not exist.'));
     }
 }
Example #4
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->isNewRecord) {
             if (!Yii::$app->user->isGuest) {
                 $this->comment_user_id = Yii::$app->user->id;
                 $this->comment_author_email = Yii::$app->user->identity->email;
                 $this->comment_author = Yii::$app->user->identity->profile->name;
             }
             $this->comment_agent = $_SERVER['HTTP_USER_AGENT'];
             $this->comment_author_ip = $_SERVER['REMOTE_ADDR'];
             $this->comment_date = date('Y-m-d H:i:s');
             $this->comment_approved = self::COMMENT_APPROVED;
             if (Option::get('comment_moderation') && Yii::$app->user->isGuest) {
                 if (Option::get('comment_whitelist') && Option::get('require_name_email')) {
                     $hasComment = static::find()->andWhere(['comment_author_email' => $this->comment_author_email])->andWhere(['comment_approved' => self::COMMENT_APPROVED])->count();
                     if (!$hasComment) {
                         $this->comment_approved = self::COMMENT_UNAPPROVED;
                     }
                 } else {
                     $this->comment_approved = self::COMMENT_UNAPPROVED;
                 }
             }
         }
         return true;
     }
     return false;
 }
Example #5
0
 * @file      view.php.
 * @date      6/4/2015
 * @time      11:28 PM
 * @author    Agiel K. Saputra <*****@*****.**>
 * @copyright Copyright (c) 2015 WritesDown
 * @license   http://www.writesdown.com/license/
 */
use yii\helpers\Html;
use yii\widgets\LinkPager;
use fbarrento\yii2\modules\option\models\Option;
/* @var $this yii\web\View */
/* @var $user common\models\User */
/* @var $posts common\models\Post[] */
/* @var $tags common\models\Term[] */
/* @var $pages yii\data\Pagination */
$this->title = Html::encode(Yii::t('writesdown', 'All Posts By {user}', ['user' => $user->display_name]) . ' - ' . Option::get('sitetitle'));
$this->params['breadcrumbs'][] = Html::encode(Yii::t('writesdown', 'All Posts by {user}', ['user' => $user->display_name]));
?>
<div class="archive user-view">
    <header id="archive-header" class="archive-header page-header">
        <h1><?php 
echo Html::encode(Yii::t('writesdown', 'All Posts By {user}', ['user' => $user->display_name]));
?>
</h1>
    </header>
    <?php 
if ($posts) {
    ?>
        <?php 
    foreach ($posts as $post) {
        ?>
Example #6
0
<body>
<?php 
$this->beginBody();
NavBar::begin(['brandLabel' => Option::get('sitetitle'), 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar-static-top', 'id' => 'navbar-primary']]);
echo Nav::widget(['options' => ['class' => 'navbar-nav'], 'items' => Menu::getMenu('primary'), 'encodeLabels' => false]);
NavBar::end();
?>
<header id="header-primary">
    <div class="container">
        <?php 
if (Yii::$app->controller->route == 'site/index') {
    echo Html::tag('h1', Option::get('sitetitle'), ['id' => 'site-title', 'class' => 'site-title']);
} else {
    echo Html::tag('span', Option::get('sitetitle'), ['id' => 'site-title', 'class' => 'h1 site-title']);
}
echo Html::tag('span', Option::get('tagline'), ['id' => 'site-tagline', 'class' => 'h3 site-tagline']);
?>
    </div>
</header>
<div id="breadcrumb-primary" class="hidden-xs">
    <div class="container">
        <?php 
echo Breadcrumbs::widget(['links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : []]);
?>
    </div>
</div>
<div class="container">
    <div id="content-wrapper">
        <div class="row">
            <div class="col-md-8">
                <div id="content">
Example #7
0
 * @file      search.php.
 * @date      6/4/2015
 * @time      10:26 PM
 * @author    Agiel K. Saputra <*****@*****.**>
 * @copyright Copyright (c) 2015 WritesDown
 * @license   http://www.writesdown.com/license/
 */
use yii\helpers\Html;
use yii\widgets\LinkPager;
use fbarrento\yii2\modules\option\models\Option;
/* @var $this yii\web\View */
/* @var $s string */
/* @var $posts common\models\Post[] */
/* @var $tags common\models\Term[] */
/* @var $pages yii\data\Pagination */
$this->title = Html::encode(Yii::t('writesdown', 'Search Result: {s}', ['s' => $s]) . ' - ' . Option::get('sitetitle'));
$this->params['breadcrumbs'][] = Html::encode(Yii::t('writesdown', 'Search Result: {s}', ['s' => $s]));
$this->registerMetaTag(['name' => 'robots', 'content' => 'noindex, nofollow']);
?>

<div class="archive post-index">
    <header id="archive-header" class="archive-header page-header">
        <h1><?php 
echo Html::encode(Yii::t('writesdown', 'Search Result: {s}', ['s' => $s]));
?>
</h1>
    </header>
    <?php 
if ($posts) {
    ?>
        <?php 
Example #8
0
        <?php 
echo $form->field($model, 'password', ['template' => '<div class="form-group has-feedback">{input}<span class="glyphicon glyphicon-lock form-control-feedback"></span></div>{error}'])->passwordInput(['placeholder' => $model->getAttributeLabel('password')]);
?>

        <div class="row">
            <div class="col-xs-8">
                <?php 
echo $form->field($model, 'rememberMe')->checkbox();
?>
            </div>
            <div class="col-xs-4">
                <?php 
echo Html::submitButton('Signin', ['class' => 'btn btn-primary btn-block btn-flat', 'name' => 'signin-button']);
?>
            </div>
        </div>
        <?php 
ActiveForm::end();
?>

        <?php 
echo Html::a(Yii::t('content', 'Reset Password'), ['/site/request-password-reset']);
?>

        <br/>

        <?php 
echo Option::get('allow_signup') ? Html::a(Yii::t('content', 'Register a new membership'), ['/site/signup']) : "";
?>
    </div>
</div>
 /**
  * Upload file and save to database.
  *
  * @return array
  */
 public function actionAjaxUpload()
 {
     $versions = ['large' => ['max_width' => Option::get('large_width'), 'max_height' => Option::get('large_height')], 'medium' => ['max_width' => Option::get('medium_width'), 'max_height' => Option::get('medium_height')], 'thumbnail' => ['max_width' => Option::get('thumbnail_width'), 'max_height' => Option::get('thumbnail_height'), 'crop' => 1]];
     $uploadHandler = new MediaUploadHandler(['versions' => $versions], false);
     $uploadHandler->post();
 }
Example #10
0
    /**
     * @param     $comment
     * @param int $depth
     *
     * @throws \Exception
     */
    protected function displayComment($comment, $depth = 0)
    {
        echo Html::beginTag('div', ['id' => 'comment-' . $comment->id, 'class' => $comment->child ? 'parent depth-' . $depth : 'depth-' . $depth]);
        ?>

        <?php 
        if (Option::get('show_avatars')) {
            ?>
            <div class="media-left avatar">
                <?php 
            echo Gravatar::widget(['email' => $comment->comment_author_email, 'options' => ['alt' => $comment->comment_author, 'class' => 'avatar', 'width' => $this->avatarSize, 'height' => $this->avatarSize], 'defaultImage' => Option::get('avatar_default'), 'rating' => Option::get('avatar_rating'), 'size' => $this->avatarSize]);
            ?>
            </div>
        <?php 
        }
        ?>
        <div class="media-body comment-body">
            <p class="meta">
                <strong class="author vcard">
                    <span class="fn">
                        <?php 
        echo $comment->comment_author ? $comment->comment_author : \Yii::t('content', 'Anonymous');
        ?>
                    </span>
                </strong>
                -
                <time class="date published" datetime="<?php 
        echo \Yii::$app->formatter->asDatetime($comment->comment_date);
        ?>
">
                    <?php 
        echo \Yii::$app->formatter->asDate($comment->comment_date);
        ?>
                </time>
                <?php 
        if ($depth < $this->maxDepth && $this->enableThreadComments) {
            echo Html::a(\Yii::t('content', 'Reply'), '#', ['class' => 'comment-reply-link', 'data-id' => $comment->id]);
        }
        ?>
            </p>
            <div class="comment-content">
                <?php 
        echo $comment->comment_content;
        ?>
            </div>
        </div>
        <?php 
        echo Html::endTag('div');
    }
Example #11
0
 * @file      view.php.
 * @date      6/4/2015
 * @time      11:27 PM
 * @author    Agiel K. Saputra <*****@*****.**>
 * @copyright Copyright (c) 2015 WritesDown
 * @license   http://www.writesdown.com/license/
 */
use yii\helpers\Html;
use yii\widgets\LinkPager;
use fbarrento\yii2\modules\option\models\Option;
/* @var $this yii\web\View */
/* @var $term common\models\Term */
/* @var $posts common\models\Post[] */
/* @var $tags common\models\Term[] */
/* @var $pages yii\data\Pagination */
$this->title = Html::encode($term->taxonomy->taxonomy_sn . ': ' . $term->term_name . ' - ' . Option::get('sitetitle'));
$this->params['breadcrumbs'][] = Html::encode($term->term_name);
?>

<div class="archive term-view">
    <header id="archive-header" class="archive-header page-header">
        <h1><?php 
echo Html::encode($term->taxonomy->taxonomy_sn . ': ' . $term->term_name);
?>
</h1>
        <?php 
if ($term->term_description) {
    echo Html::tag('div', $term->term_description, ['class' => 'description term-description']);
}
?>
    </header>
Example #12
0
 * @file      index.php.
 * @date      6/4/2015
 * @time      11:23 PM
 * @author    Agiel K. Saputra <*****@*****.**>
 * @copyright Copyright (c) 2015 WritesDown
 * @license   http://www.writesdown.com/license/
 */
use yii\helpers\Html;
use yii\widgets\LinkPager;
use fbarrento\yii2\modules\option\models\Option;
/* @var $this yii\web\View */
/* @var $postType common\models\PostType */
/* @var $posts common\models\Post[] */
/* @var $tags common\models\Term[] */
/* @var $pages yii\data\Pagination */
$this->title = Html::encode($postType->post_type_pn . ' - ' . Option::get('sitetitle'));
$this->params['breadcrumbs'][] = Html::encode($postType->post_type_pn);
?>
<div class="archive post-index">
    <header id="archive-header" class="page-header archive-header">
        <h1><?php 
echo Html::encode($postType->post_type_pn);
?>
</h1>
        <?php 
if ($postType->post_type_description) {
    echo '<p class="description term-description">' . $postType->post_type_description . '</p>';
}
?>
    </header>
    <?php 
Example #13
0
 * @date      6/4/2015
 * @time      10:22 PM
 * @author    Agiel K. Saputra <*****@*****.**>
 * @copyright Copyright (c) 2015 WritesDown
 * @license   http://www.writesdown.com/license/
 */
use fbarrento\yii2\modules\option\models\Option;
/* MODEL */
use yii\helpers\Html;
use yii\widgets\LinkPager;
/* @var $this yii\web\View */
/* @var $posts \fbarrento\yii2\modules\content\models\Post[] */
/* @var $tags \fbarrento\yii2\modules\content\models\Term[] */
/* @var $pages yii\data\Pagination */
$this->title = Html::encode(Option::get('sitetitle') . ' - ' . Option::get('tagline'));
$this->params['breadcrumbs'][] = Html::encode(Option::get('sitetitle'));
?>
<div class="archive site-index">
    <?php 
if ($posts) {
    ?>
        <?php 
    foreach ($posts as $post) {
        ?>
            <article class="hentry">
                <header class="entry-header page-header">
                    <h2 class="entry-title"><?php 
        echo Html::a(Html::encode($post->post_title), $post->url);
        ?>
</h2>
                    <?php 
 /**
  * Finds the Option model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return Option the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Option::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #15
0
 */
use fbarrento\yii2\modules\option\models\Option;
use frontend\widgets\comment\MediaComment;
use yii\helpers\Html;
/* @var $comment common\models\MediaComment */
/* @var $media common\models\Media */
?>
<div id="comment-view">
    <?php 
if ($media->media_comment_count) {
    echo '<h2 class="comment-title">';
    echo Yii::t('writesdown', '{comment_count} {comment_word} on {media_title}', ['comment_count' => $media->media_comment_count, 'comment_word' => $media->media_comment_count > 1 ? 'Replies' : 'Reply', 'media_title' => $media->media_title]);
    echo '</h3>';
    echo MediaComment::widget(['model' => $media, 'id' => 'comments']);
}
if ($media->media_comment_status == 'open') {
    $dateInterval = date_diff(new DateTime($media->media_date), new DateTime('now'));
    if (Option::get('comment_registration') && Yii::$app->user->isGuest) {
        echo '<h3>' . Yii::t('writesdown', 'You must login to leave a reply, ') . Html::a(Yii::t('writesdown', 'Login'), Yii::$app->urlManagerBack->createUrl(['site/login'])) . '</h3>';
    } elseif (Option::get('close_comments_for_old_medias') && $dateInterval->d >= Option::get('close_comments_days_old')) {
        echo '<h3>' . Yii::t('writesdown', 'Comments are closed') . '</h3>';
    } else {
        echo $this->render('_form', ['model' => $comment, 'media' => $media]);
    }
} else {
    if ($media->media_comment_count && $media->media_comment_status === 'close') {
        echo '<h3>' . Yii::t('writesdown', 'Comments are closed') . '</h3>';
    }
}
?>
</div>
Example #16
0
/**
 * @file      view.php.
 * @date      6/4/2015
 * @time      11:24 PM
 * @author    Agiel K. Saputra <*****@*****.**>
 * @copyright Copyright (c) 2015 WritesDown
 * @license   http://www.writesdown.com/license/
 */
use fbarrento\yii2\modules\option\models\Option;
use fbarrento\yii2\modules\content\assets\frontend\CommentAsset;
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $post common\models\Post */
/* @var $comment common\models\PostComment */
/* @var $category common\models\Term */
$this->title = Html::encode($post->post_title . ' - ' . Option::get('sitetitle'));
$this->params['breadcrumbs'][] = ['label' => Html::encode($post->postType->post_type_sn), 'url' => ['/post/index', 'id' => $post->postType->id]];
$category = $post->getTerms()->innerJoinWith(['taxonomy'])->andWhere(['taxonomy_slug' => 'category'])->one();
if ($category) {
    $this->params['breadcrumbs'][] = ['label' => Html::encode($category->term_name), 'url' => $category->url];
}
$this->params['breadcrumbs'][] = Html::encode($post->post_title);
CommentAsset::register($this);
?>
<div class="single post-view">
    <article class="hentry">
        <?php 
if (Yii::$app->controller->route !== 'site/index') {
    ?>
        <header class="entry-header page-header">
            <h1 class="entry-title"><?php 
Example #17
0
/**
 * @file      view.php.
 * @date      6/4/2015
 * @time      10:31 PM
 * @author    Agiel K. Saputra <*****@*****.**>
 * @copyright Copyright (c) 2015 WritesDown
 * @license   http://www.writesdown.com/license/
 */
use frontend\assets\CommentAsset;
use yii\helpers\Html;
use fbarrento\yii2\modules\option\models\Option;
/* @var $this yii\web\View */
/* @var $media common\models\Media */
/* @var $metadata [] */
/* @var $comment common\models\MediaComment */
$this->title = Html::encode($media->media_title . ' - ' . Option::get('sitetitle'));
if ($media->mediaPost) {
    $this->params['breadcrumbs'][] = ['label' => Html::encode($media->mediaPost->post_title), 'url' => $media->mediaPost->url];
}
$this->params['breadcrumbs'][] = Html::encode($media->media_title);
CommentAsset::register($this);
?>
<div class="single media-view">
    <article class="hentry">
        <header class="entry-header page-header">
            <h1 class="entry-title"><?php 
echo Html::encode($media->media_title);
?>
</h1>
            <?php 
$updated = new \DateTime($media->media_modified, new DateTimeZone(Yii::$app->timeZone));
Example #18
0
 /**
  * Gets the current base theme dir.
  *
  * @return string
  */
 public static function getThemeDir()
 {
     $theme = Option::get('theme');
     return Yii::getAlias('@themes') . '/' . $theme . '/';
 }
Example #19
0
/**
 * @file      contact.php.
 * @date      6/4/2015
 * @time      10:26 PM
 * @author    Agiel K. Saputra <*****@*****.**>
 * @copyright Copyright (c) 2015 WritesDown
 * @license   http://www.writesdown.com/license/
 */
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\captcha\Captcha;
use fbarrento\yii2\modules\option\models\Option;
/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \frontend\models\ContactForm */
$this->title = Yii::t('writesdown', 'Contact') . ' - ' . Option::get('sitetitle');
$this->params['breadcrumbs'][] = Yii::t('writesdown', 'Contact');
?>
<div class="single site-contact">
    <article class="hentry">
        <header class="entry-header page-header">
            <h1 class="entry-title"><?php 
echo Html::encode(Yii::t('writesdown', 'Contact'));
?>
</h1>
        </header>
        <div class="entry-content">
            <p>
                If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
            </p>
            <?php 
Example #20
0
<?php

/**
 * @file      footer.php.
 * @date      6/4/2015
 * @time      10:24 PM
 * @author    Agiel K. Saputra <*****@*****.**>
 * @copyright Copyright (c) 2015 WritesDown
 * @license   http://www.writesdown.com/license/
 */
use yii\helpers\Html;
/* MODEL */
use fbarrento\yii2\modules\option\models\Option;
?>
<footer id="footer-primary">
    <div class="container">
        <h5>Copyright &copy; <?php 
echo date('Y');
?>
 <?php 
echo Html::a(Option::get('sitetitle'), 'http://www.writesdown.com/');
?>
 All right reserved. <?php 
echo Yii::powered();
?>
.</h5>
    </div>
</footer>
Example #21
0
    </h3>

    <?php 
if (!Yii::$app->user->isGuest) {
    echo Html::tag('p', Yii::t('writesdown', 'Login as {username}, {logout}{cancel-reply}', ['username' => '<strong>' . Yii::$app->user->identity->username . '</strong>', 'logout' => Html::a(Yii::t('writesdown', '<strong>Sign Out</strong>'), ['/site/logout'], ['data-method' => 'post']), 'cancel-reply' => Html::a('<strong>' . Yii::t('writesdown', ', Cancel Reply') . '</strong>', '#', ['id' => 'cancel-reply', 'class' => 'cancel-reply', 'style' => 'display:none;'])]));
} else {
    echo Html::tag('p', Html::a('<strong>' . Yii::t('writesdown', 'Cancel Reply') . '</strong>', '#', ['id' => 'cancel-reply', 'class' => 'cancel-reply', 'style' => 'display:none;']));
}
?>

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
if (Yii::$app->user->isGuest && Option::get('require_name_email')) {
    ?>

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

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

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

    <?php 
Example #22
0
 /**
  * Search post by title and content
  *
  * @param $s
  *
  * @return string
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionSearch($s)
 {
     $query = Post::find()->orWhere(['LIKE', 'post_title', $s])->orWhere(['LIKE', 'post_content', $s])->andWhere(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => Option::get('posts_per_page')]);
     $query->offset($pages->offset)->limit($pages->limit);
     $posts = $query->all();
     if ($posts) {
         return $this->render('/site/search', ['posts' => $posts, 'pages' => $pages, 's' => $s]);
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }