public function actionView()
 {
     $topic = $this->getTopic();
     $file = Yii::getPathOfAlias('application.data.guide') . DIRECTORY_SEPARATOR . $this->getVersion() . DIRECTORY_SEPARATOR . $this->getLanguage() . DIRECTORY_SEPARATOR . $topic . '.txt';
     if (!is_file($file)) {
         $file = Yii::getPathOfAlias('application.data.guide') . DIRECTORY_SEPARATOR . $this->getVersion() . DIRECTORY_SEPARATOR . $topic . '.txt';
     }
     if (!strcasecmp($topic, 'toc') || !is_file($file)) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $content = file_get_contents($file);
     $markdown = new MarkdownParser();
     $markdown->purifierOptions['Attr.EnableID'] = true;
     $content = $markdown->safeTransform($content);
     $highlightCss = Yii::app()->assetManager->publish($markdown->getDefaultCssFile());
     Yii::app()->clientScript->registerCssFile($highlightCss);
     $imageUrl = Yii::app()->baseUrl . '/images/guide';
     $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="\\/guide\\/(.*?)\\/?"/', array($this, 'replaceGuideLink'), $content);
     $content = preg_replace('/href="(\\/api\\/.*?)"/', 'href="http://sourcebans.net$1"', $content);
     $content = preg_replace_callback('/<h2([^>]*)>(.*?)<\\/h2>/', array($this, 'replaceSection'), $content);
     $content = preg_replace_callback('/<h1([^>]*)>(.*?)<\\/h1>/', array($this, 'replaceTitle'), $content, 1);
     $this->pageTitle = 'User Guide « SourceBans';
     if ($topic !== 'index' && preg_match('/<h1[^>]*>(.*?)</', $content, $matches)) {
         $this->pageTitle = CHtml::encode($matches[1]) . ' « ' . $this->pageTitle;
     }
     $this->render('view', array('content' => $content));
 }
 public function actionView()
 {
     $topic = $this->getTopic();
     $file = Yii::getPathOfAlias("docs.guide.{$this->language}") . DIRECTORY_SEPARATOR . $topic . '.txt';
     if (!is_file($file)) {
         $file = Yii::getPathOfAlias("docs.guide") . DIRECTORY_SEPARATOR . $topic . '.txt';
     }
     if (!strcasecmp($topic, 'toc') || !is_file($file)) {
         throw new CHttpException(404, 'The page you looked for does not exist.');
     }
     $content = file_get_contents($file);
     $markdown = new MarkdownParser();
     $content = $markdown->safeTransform($content);
     $imageUrl = Yii::app()->baseUrl . '/guide/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\\/guide\\/(.*?)\\/?"/', array($this, 'replaceGuideLink'), $content);
     $content = preg_replace('/href="(\\/doc\\/api\\/.*?)"/', 'href="http://www.yiiframework.com$1"', $content);
     $this->pageTitle = 'The Definitive Guide to Yii';
     if ($topic !== 'index' && preg_match('/<h1[^>]*>(.*?)</', $content, $matches)) {
         $this->pageTitle .= ' - ' . CHtml::encode($matches[1]);
     }
     $this->render('view', array('content' => $content));
 }
 /**
  * Tutorials & Category RSS
  */
 public function actionrss()
 {
     $criteria = new CDbCriteria();
     if (isset($_GET['id']) && ($model = TutorialsCats::model()->findByPk($_GET['id']))) {
         $criteria->condition = 'catid=:catid AND status=:status';
         $criteria->params = array(':catid' => $model->id, ':status' => 1);
     } else {
         $criteria->condition = 'status=:status';
         $criteria->params = array(':status' => 1);
     }
     $rows = array();
     // Load some tutorials
     $criteria->order = 'postdate DESC';
     $criteria->limit = 50;
     $tutorials = Tutorials::model()->with(array('author'))->findAll($criteria);
     $markdown = new MarkdownParser();
     if ($tutorials) {
         foreach ($tutorials as $r) {
             $r->content = $markdown->safeTransform($r->content);
             $rows[] = array('title' => $r->title, 'link' => Yii::app()->createAbsoluteUrl('/tutorials/view/' . $r->alias, array('lang' => false)), 'charset' => Yii::app()->charset, 'description' => $r->description, 'author' => $r->author ? $r->author->username : Yii::app()->name, 'generator' => Yii::app()->name, 'language' => Yii::app()->language, 'guid' => $r->id, 'content' => $r->content);
         }
     }
     $data = array('title' => isset($model) ? $model->title : Yii::t('tutorials', 'Tutorials RSS Feed'), 'link' => isset($model) ? Yii::app()->createAbsoluteUrl('/tutorials/category/' . $model->alias, array('lang' => false)) : Yii::app()->createAbsoluteUrl('tutorials', array('lang' => false)), 'charset' => Yii::app()->charset, 'description' => isset($model) ? $model->description : Yii::t('tutorials', 'Tutorials'), 'author' => Yii::app()->name, 'generator' => Yii::app()->name, 'language' => Yii::app()->language, 'ttl' => 10, 'entries' => $rows);
     Yii::app()->func->displayRss($data);
 }
/**
 * Converts a markdown text into purified HTML
 */
function mh($text)
{
    static $parser;
    if ($parser === null) {
        $parser = new MarkdownParser();
    }
    return $parser->safeTransform($text);
}
Exemple #5
0
/**
 * Returns the given markdown text as purified HTML.
 * @param $text
 * @return string
 */
function markdown($text)
{
    static $parser;
    if (!isset($parser)) {
        $parser = new MarkdownParser();
    }
    return $parser->safeTransform($text);
}
 /**
  * Markit up ajax parser callback
  */
 public function actionparser()
 {
     // Grab file contents and parse them
     $content = $_POST['dontvalidate'];
     $markdown = new MarkdownParser();
     $content = $markdown->safeTransform($content);
     $this->layout = false;
     echo $this->render('parser', array('content' => $content), true);
     Yii::app()->end();
 }