/** * Creates a new Post model. * If creation is successful, the browser will be redirected to the 'update' page. * * @param integer $post_type post_type_id * * @throws \yii\web\ForbiddenHttpException * @throws \yii\web\NotFoundHttpException * @return mixed */ 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('writesdown', '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->setAttributes(['term_id' => $termId, 'post_id' => $model->id]); if ($termRelationship->save() && ($term = $this->findTerm($termId))) { $term->updateAttributes(['term_count' => $term->term_count++]); } } } 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('writesdown', '{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]); }
/** * Displays a single User model. * * @param null $id * @param $username * * @return mixed * @throws \yii\web\NotFoundHttpException */ public function actionView($id = null, $username = null) { $render = '/user/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 . '/user/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.'); } }
/** * @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('writesdown', '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('writesdown', 'The requested page does not exist.')); } }
/** * @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']); }
/** * Set theme params * * @param Application $app the application currently running */ protected function setTheme($app) { /* THEME CONFIG */ $paramsPath = Yii::getAlias('@themes/') . Option::get('theme') . '/config/params.php'; if (is_file($paramsPath)) { $params = (require $paramsPath); if ($backendParams = ArrayHelper::getValue($params, 'backend')) { $app->params = ArrayHelper::merge($app->params, $backendParams); } } }
/** * Displaying feed. * * @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; // Get first post and all posts $lastPost = Post::find()->where(['status' => Post::STATUS_PUBLISH])->andWhere(['<=', 'date', date('Y-m-d H:i:s')])->orderBy(['id' => SORT_DESC])->one(); $posts = Post::find()->where(['status' => Post::STATUS_PUBLISH])->andWhere(['<=', 'date', date('Y-m-d H:i:s')])->limit(Option::get('posts_per_rss'))->orderBy(['id' => SORT_DESC])->all(); return $this->renderPartial('index', ['title' => Option::get('sitetitle'), 'description' => Option::get('tagline'), 'link' => Yii::$app->request->absoluteUrl, 'lastBuildDate' => new \DateTime($lastPost->date, new \DateTimeZone(Option::get('time_zone'))), 'language' => Yii::$app->language, 'generator' => 'http://www.writesdown.com', 'posts' => $posts, 'rssUseExcerpt' => Option::get('rss_use_excerpt')]); }
/** * Set theme params * * @param Application $app the application currently running */ protected function setTheme($app) { /* THEME CONFIG */ $themeParamPath = Yii::getAlias('@themes/') . Option::get('theme') . '/config/params.php'; if (is_file($themeParamPath)) { $themeParam = (require $themeParamPath); if (isset($themeParam['backend'])) { $app->params = ArrayHelper::merge($app->params, $themeParam['backend']); } } }
/** * @inheritdoc */ public function init() { $theme = Option::get('theme'); $searchForm = Yii::getAlias('@themes/' . $theme . '/layouts/search-form.php'); if (is_file($searchForm)) { $this->_searchForm = $searchForm; } else { $this->_searchForm = __DIR__ . '/views/search-form.php'; } parent::init(); }
/** * Set theme params * * @param Application $app the application currently running */ protected function setTheme($app) { $app->view->theme->basePath = '@themes/' . Option::get('theme'); $app->view->theme->baseUrl = '@web/themes/' . Option::get('theme'); $app->view->theme->pathMap = ['@app/views' => '@themes/' . Option::get('theme'), '@app/views/post' => '@themes/' . Option::get('theme') . '/post']; $paramsPath = Yii::getAlias('@themes/') . Option::get('theme') . '/config/params.php'; if (is_file($paramsPath)) { $params = (require $paramsPath); if ($frontendParams = ArrayHelper::getValue($params, 'frontend')) { $app->params = ArrayHelper::merge($app->params, $frontendParams); } } }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /* @var $user User */ $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!User::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } if ($user->save()) { return Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])->setFrom([Option::get('admin_email') => Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . Yii::$app->name)->send(); } } return false; }
/** * Render option form for sitemap in backend. * * @return string */ public function actionIndex() { $option = Option::get($this->_optionName); if (!$option) { return $this->redirect(['install']); } $postTypes = PostType::find()->all(); $taxonomies = Taxonomy::find()->all(); if ($post = Yii::$app->request->post('Option')) { if (Option::set($this->_optionName, $post['option_value'])) { return $this->redirect(['index']); } } return $this->render('index', ['option' => $option, 'postTypes' => $postTypes, 'taxonomies' => $taxonomies]); }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { Yii::$app->authManager->assign(Yii::$app->authManager->getRole(Option::get('default_role')), $user->id); return $user; } } return null; }
/** * Displays a single Term model. * * @param integer $id Term ID * @param null $slug Term slug * @throws \yii\web\NotFoundHttpException * @return mixed */ public function actionView($id = null, $slug = null) { $render = 'view'; if ($id) { $model = $this->findModel($id); } elseif ($slug) { $model = $this->findModelBySlug($slug); } else { throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.')); } $query = $model->getPosts()->andWhere(['status' => 'publish'])->andWhere(['<=', 'date', date('Y-m-d H:i:s')])->orderBy(['date' => SORT_DESC]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => Option::get('posts_per_page')]); $posts = $query->offset($pages->offset)->limit($pages->limit)->all(); if (is_file($this->view->theme->basePath . '/term/view-' . $model->taxonomy->name . '.php')) { $render = 'view-' . $model->taxonomy->name; } return $this->render($render, ['posts' => $posts, 'pages' => $pages, 'term' => $model]); }
/** * Displays a single Term model. * * @param integer $id * @param null $term_slug * * @throws \yii\web\NotFoundHttpException * @return mixed */ public function actionView($id = null, $term_slug = null) { $render = 'view'; if ($id) { $model = $this->findModel($id); } else { if ($term_slug) { $model = $this->findModelBySlug($term_slug); } 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')]); $posts = $query->offset($pages->offset)->limit($pages->limit)->all(); if (is_file($this->getViewPath() . "/view-" . $model->taxonomy->taxonomy_slug . '.php')) { $render = 'view-' . $model->taxonomy->taxonomy_slug; } return $this->render($render, ['posts' => $posts, 'pages' => $pages, 'model' => $model]); }
?> <?php if (Option::get('comment_registration') && Yii::$app->user->isGuest) { ?> <h3> <?php echo Yii::t('writesdown', 'You must login to leave a reply, '); ?> <?php echo Html::a(Yii::t('writesdown', 'Login'), Yii::$app->urlManagerBack->createUrl(['site/login'])); ?> </h3> <?php } elseif (Option::get('close_comments_for_old_posts') && $dateInterval->d >= Option::get('close_comments_days_old')) { ?> <h3><?php echo Yii::t('writesdown', 'Comments are closed'); ?> </h3>; <?php } else { ?> <?php echo $this->render('_form', ['model' => $comment, 'media' => $media]); ?> <?php } ?> <?php
<p> <?php echo Html::a('<strong>' . Yii::t('writesdown', 'Cancel Reply') . '</strong>', '#', ['id' => 'cancel-reply', 'class' => 'cancel-reply', 'style' => 'display:none;']); ?> </p> <?php } ?> <?php $form = ActiveForm::begin(); ?> <?php if (Yii::$app->user->isGuest && Option::get('require_name_email')) { ?> <div class="row"> <div class="col-md-7"> <?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]); ?>
* @date 8/23/2015 * @time 9:30 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 common\models\Option; /* @var $this yii\web\View */ /* @var $user common\models\User */ /* @var $posts common\models\Post[] */ /* @var $tags common\models\Term[] */ /* @var $image common\models\Media */ /* @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"> <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) { ?>
/** * 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]]; // Merge image versions with app params if (isset(Yii::$app->params['media']['versions']) && is_array(Yii::$app->params['media']['versions'])) { $versions = ArrayHelper::merge($versions, Yii::$app->params['media']['versions']); } $uploadHandler = new MediaUploadHandler(['versions' => $versions, 'user_dirs' => Option::get('uploads_username_based')], false); $uploadHandler->post(); }
]]></category> <?php } ?> <guid isPermaLink="false"> <![CDATA[<?php echo Yii::$app->urlManager->createAbsoluteUrl(['post/view', 'id' => $post->id]); ?> ]]> </guid> <description><![CDATA[<?php echo $post->excerpt; ?> ]]></description> <?php if (!Option::get('rss_use_excerpt')) { ?> <content:encoded><![CDATA[<?php echo $post->content; ?> ]]></content:encoded> <?php } ?> <wfw:commentRss><![CDATA[<?php echo $post->url; ?> ]]></wfw:commentRss> <slash:comments><?php echo $post->comment_count; ?>
<?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 common\models\Option; ?> <footer id="footer-primary"> <div class="container"> <h5>Copyright © <?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>
/** * Detail theme via ajax for model * * @param string $theme * * @return string */ public function actionAjaxDetail($theme) { $themeConfig = []; $themeInfo = $this->_themeDir . $theme . '/config/main.php'; if (is_file($themeInfo)) { $themeConfig = (require $themeInfo); } $themeConfig['Thumbnail'] = is_file($this->_thumbDir . $theme . '.png') ? $this->_thumbBaseUrl . $theme . '.png' : Yii::getAlias('@web/img/themes.png'); $themeConfig['Dir'] = $theme; if (!isset($themeConfig['Name'])) { $themeConfig['Name'] = $theme; } return $this->renderPartial('_theme-detail', ['themeConfig' => $themeConfig, 'installed' => Option::get('theme')]); }
* @file index.php * @date 8/23/2015 * @time 8:52 PM * @author Agiel K. Saputra <*****@*****.**> * @copyright Copyright (c) 2015 WritesDown * @license http://www.writesdown.com/license/ */ use yii\helpers\Html; use yii\widgets\LinkPager; /* MODEL */ use common\models\Option; /* @var $this yii\web\View */ /* @var $post common\models\Post */ /* @var $image common\models\Media */ /* @var $pages yii\web\ */ $this->title = Option::get('sitetitle') . ' - ' . Option::get('tagline'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="archive site-index"> <?php if ($posts) { ?> <?php foreach ($posts as $post) { ?> <article class="hentry"> <header class="entry-header"> <h2 class="entry-title"><?php echo Html::a($post->post_title, $post->url); ?> </h2>
use themes\writesdown\classes\assets\ThemeAsset; use yii\helpers\Html; $assetBundle = ThemeAsset::register($this); /* @var $this \yii\web\View */ /* @var $content string */ // Canonical $this->registerLinkTag(['rel' => 'canonical', 'href' => Yii::$app->request->absoluteUrl]); // Favicon $this->registerLinkTag(['rel' => 'icon', 'href' => $assetBundle->baseUrl . '/img/favicon.ico', 'type' => 'image/x-icon']); // Add meta robots noindex, nofollow when option disable_site_indexing = true if (Option::get('disable_site_indexing')) { $this->registerMetaTag(['name' => 'robots', 'content' => 'noindex, nofollow']); } // Get site-title and tag-line $siteTitle = Option::get('sitetitle'); $tagLine = Option::get('tagline'); $this->beginPage(); ?> <!DOCTYPE html> <html lang="<?php echo Yii::$app->language; ?> "> <head> <meta charset="<?php echo Yii::$app->charset; ?> "> <meta name="viewport" content="width=device-width, initial-scale=1"> <?php echo Html::csrfMetaTags();
<?php /** * @link http://www.writesdown.com/ * @author Agiel K. Saputra <*****@*****.**> * @copyright Copyright (c) 2015 WritesDown * @license http://www.writesdown.com/license/ */ use common\models\Option; use yii\bootstrap\ActiveForm; use yii\captcha\Captcha; use yii\helpers\Html; /* @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> <?php echo Yii::t('writesdown', 'If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.');
* @link http://www.writesdown.com/ * @author Agiel K. Saputra <*****@*****.**> * @copyright Copyright (c) 2015 WritesDown * @license http://www.writesdown.com/license/ */ use common\models\Option; use common\models\Taxonomy; use yii\helpers\Html; use yii\widgets\LinkPager; /* @var $this yii\web\View */ /* @var $term common\models\Term */ /* @var $posts common\models\Post[] */ /* @var $tags common\models\Term[] */ /* @var $image common\models\Media */ /* @var $pages yii\data\Pagination */ $this->title = Html::encode($term->taxonomy->singular_name . ': ' . $term->name . ' - ' . Option::get('sitetitle')); $this->params['breadcrumbs'][] = Html::encode($term->name); ?> <div class="archive term-view"> <header id="archive-header" class="archive-header"> <h1><?php echo Html::encode($term->taxonomy->singular_name . ': ' . $term->name); ?> </h1> <?php if ($term->description) { ?> <div class="description term-description"><?php echo $term->description;
<?php /** * @link http://www.writesdown.com/ * @author Agiel K. Saputra <*****@*****.**> * @copyright Copyright (c) 2015 WritesDown * @license http://www.writesdown.com/license/ */ use common\models\Option; use yii\helpers\Html; use yii\widgets\ActiveForm; /* @var $media common\models\Media */ $this->title = Html::encode($media->title . ' - ' . Option::get('sitetitle')); if ($media->mediaPost) { $this->params['breadcrumbs'][] = ['label' => Html::encode($media->mediaPost->title), 'url' => $media->mediaPost->url]; } $this->params['breadcrumbs'][] = Html::encode($media->title); ?> <div class="single media-protected"> <article class="hentry"> <header class="entry-header"> <h1 class="entry-title"><?php echo Html::encode($media->title); ?> </h1> </header> <div class="entry-content"> <?php $form = ActiveForm::begin();
<?php use common\models\Option; defined('YII_DEBUG') or define('YII_DEBUG', false); defined('YII_ENV') or define('YII_ENV', 'prod'); require __DIR__ . '/../../vendor/autoload.php'; require __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'; require __DIR__ . '/../../common/config/bootstrap.php'; require __DIR__ . '/../config/bootstrap.php'; $config = yii\helpers\ArrayHelper::merge(require __DIR__ . '/../../common/config/main.php', require __DIR__ . '/../../common/config/main-local.php', require __DIR__ . '/../config/main.php', require __DIR__ . '/../config/main-local.php'); $application = new yii\web\Application($config); /* Time Zone */ $application->timeZone = Option::get('time_zone'); /* Date Time */ $application->formatter->dateFormat = 'php:' . Option::get('date_format'); $application->formatter->timeFormat = 'php:' . Option::get('time_format'); $application->formatter->datetimeFormat = 'php:' . Option::get('date_format') . ' ' . Option::get('time_format'); $application->run();
/** * @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 common\models\Option; use frontend\assets\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
/** * 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, 'user_dirs' => Option::get('uploads_username_based')], false); $uploadHandler->post(); }
/** * @inheritdoc */ public function beforeAction($action) { /* @var $postType \common\models\PostType */ /* @var $taxonomy \common\models\Taxonomy */ if (parent::beforeAction($action)) { $this->_option = Option::get('sitemap'); return true; } return false; }