/**
  * Controller blog action
  * By default displays the documentation from the protected/documentation/blog
  * folder based on the language currently viewed
  */
 public function actionblog()
 {
     $topic = $this->getTopic('blog');
     $model = Documentation::model()->find('mkey=:mkey AND type=:type AND language=:lang', array(':type' => 'blog', ':mkey' => $topic, ':lang' => $this->language));
     if (!$model) {
         $model = Documentation::model()->find('mkey=:mkey AND type=:type AND language=:lang', array(':type' => 'blog', ':mkey' => $topic, ':lang' => 'source'));
     }
     if (!strcasecmp($topic, 'toc') || !$model) {
         // @todo Fix this
         throw new CHttpException(404, 'The page you looked for does not exist.');
     }
     // Update views
     $model->views++;
     $model->save();
     // Cache parsed output
     if (($content = Yii::app()->cache->get('docbyid_' . $model->id)) === false) {
         // Grab file contents and parse them
         $content = $model->content;
         $markdown = new MarkdownParser();
         $content = $markdown->safeTransform($content);
     }
     // Manually convert items such as images, doc api links and guide links
     $imageUrl = Yii::app()->assetManager->publish(Yii::getPathOfAlias("application.documentation.blog.source.images"));
     $content = preg_replace('/<p>\\s*<img(.*?)src="(.*?)"\\s+alt="(.*?)"\\s*\\/>\\s*<\\/p>/', "<div class=\"image\"><p>\\3</p><img\\1src=\"{$imageUrl}/\\2\" alt=\"\\3\" /></div>", $content);
     $content = preg_replace_callback('/href="\\/doc\\/blog\\/(.*?)\\/?"/', array($this, 'replaceBlogLink'), $content);
     $content = preg_replace('/href="(\\/doc\\/api\\/.*?)"/', 'href="http://www.yiiframework.com$1"', $content);
     // Add title
     $this->pageTitle[] = Yii::t('documentation', 'The Blog Tutorial');
     $this->breadcrumbs[Yii::t('documentation', 'The Blog Tutorial')] = '';
     // Add to the title stack if this page is not the index page
     if ($topic !== 'index' && preg_match('/<h1[^>]*>(.*?)</', $content, $matches)) {
         $this->pageTitle[] = CHtml::encode($matches[1]);
         $this->breadcrumbs[Yii::t('docs', CHtml::encode($matches[1]))] = '';
     }
     // What we do here is use robots meta tag to prevent from search engines
     // indexing and crawling through the page of the guide while it's viewed in English
     // Since this is not an original content search engines will not like this
     if (Yii::app()->language == 'en' || $model->language == 'source') {
         Yii::app()->clientScript->registerMetaTag('noindex, nofollow', 'robots');
     }
     $commentsModel = new DocumentationComments();
     if (Yii::app()->user->checkAccess('op_doc_add_comments')) {
         if (isset($_POST['DocumentationComments'])) {
             $commentsModel->attributes = $_POST['DocumentationComments'];
             $commentsModel->docid = $model->id;
             $commentsModel->visible = Yii::app()->user->checkAccess('op_doc_add_comments') ? 1 : 0;
             if ($commentsModel->save()) {
                 Yii::app()->user->setFlash('success', Yii::t('docs', 'Comment Added.'));
                 $commentsModel = new DocumentationComments();
             }
         }
     }
     // Grab the language data
     $criteria = new CDbCriteria();
     $criteria->condition = 'docid=:docid';
     $criteria->params = array(':docid' => $model->id);
     $criteria->order = 'postdate DESC';
     $totalcomments = DocumentationComments::model()->count($criteria);
     $pages = new CPagination($totalcomments);
     $pages->pageSize = self::PAGE_SIZE;
     $pages->applyLimit($criteria);
     // Grab comments
     $comments = DocumentationComments::model()->orderDate()->findAll($criteria);
     // Render
     $this->render('view', array('content' => $content, 'model' => $model, 'pages' => $pages, 'markdown' => $markdown, 'type' => 'blog', 'commentsModel' => $commentsModel, 'totalcomments' => $totalcomments, 'comments' => $comments));
 }
 /**
  * Delete comment action
  */
 public function actiondeletecomment()
 {
     // Perms
     if (!Yii::app()->user->checkAccess('op_doc_delete_comments')) {
         throw new CHttpException(403, Yii::t('error', 'Sorry, You don\'t have the required permissions to enter this section'));
     }
     if (isset($_GET['id']) && ($model = DocumentationComments::model()->findByPk($_GET['id']))) {
         $model->delete();
         Yii::app()->user->setFlash('success', Yii::t('adminmembers', 'Comment Deleted.'));
         $this->redirect(array('documentation/comments'));
     } else {
         $this->redirect(array('documentation/comments'));
     }
 }
?>
</td>
					<td><?php 
echo Yii::app()->format->number(Yii::app()->db->createCommand('SELECT COUNT(id) as total FROM {{documentations_comments}} WHERE visible=0')->queryScalar());
?>
</td>
				</tr>
				<tr>
					<td><?php 
echo Yii::t('adminindex', 'Last Comments');
?>
</td>
					<td>
						<ul>
							<?php 
$lastdoccomments = DocumentationComments::model()->with(array('doc'))->findAll(array('order' => 'postdate DESC', 'limit' => 5));
?>
							<?php 
foreach ($lastdoccomments as $doccomment) {
    ?>
							<li><?php 
    echo $doccomment->doc ? $doccomment->doc->getLink() : '';
    ?>
</li>
							<?php 
}
?>
						</ul>
					</td>
				</tr>
			</table>