private function processDocument($path, $filename)
 {
     $basePath = Yii::getPathOfAlias('ext') . '/';
     $filePath = $basePath . $path . '/' . $filename;
     if (!file_exists($filePath)) {
         echo "File {$filePath} does not exist. Skipping.\n";
         return;
     }
     echo "Processing {$filePath}.\n";
     $markdownParser = new CMarkdownParser();
     $layout = Yii::getPathOfAlias('application.views.layouts') . '/documentation.php';
     if ($f = fopen($filePath, "r")) {
         $title = $in = fgets($f);
         while (!feof($f)) {
             $in .= fgets($f, 4096);
         }
     }
     fclose($f);
     $out = $markdownParser->transform($in);
     $out = $this->renderFile($layout, array('content' => $out, 'title' => $title), true);
     $docsPath = Yii::getPathOfAlias('application.docs') . '/';
     if (!file_exists($docsPath . $path)) {
         mkdir($docsPath . $path, 0777, true);
     }
     $outFileName = $docsPath . $path . '/' . str_replace('.txt', '.html', $filename);
     file_put_contents($outFileName, $out);
     return $outFileName;
 }
Example #2
0
 /**
  * Render response value
  * @param string value to render
  */
 protected function renderResponse($value)
 {
     if ($this->markdown) {
         $parser = new CMarkdownParser();
         echo $parser->transform($value);
     } else {
         echo $value;
     }
 }
 /**
  * Reads the specified file and returns either the {@link http://uk.php.net/htmlentities htmlentities} of title
  * or the {@link http://daringfireball.net/projects/markdown/ markdown} parsed description.
  *
  * @param string $file the path to the file
  * @param boolean $title whether to just get the title
  * @return string the text
  *
  */
 protected function getDescription($file, $title = false)
 {
     $_cache = isset(Yii::app()->cache) ? Yii::app()->cache->get('EGallery_' . $file . '_' . $title . '_description') : false;
     if ($_cache !== false) {
         return $_cache;
     } else {
         $i = 1;
         $fp = fopen($file, 'r');
         while (!feof($fp)) {
             $buffer .= fgets($fp, 10240);
             if ($i == 1) {
                 if ($title) {
                     return htmlentities($buffer, ENT_QUOTES);
                 }
                 $buffer = '';
             }
             $i++;
         }
         $parser = new CMarkdownParser();
         $buffer = $parser->safeTransform($buffer);
         if (isset(Yii::app()->cache)) {
             Yii::app()->cache->set('EGallery_' . $file . '_' . $title . '_description', $buffer);
         }
         return $buffer;
     }
 }
Example #4
0
    ?>
		<p style="text-align:center;"><?php 
    echo CHtml::image(Yii::app()->baseUrl . $meta['blog-image']['value'], NULL, array('class' => 'image'));
    ?>
</p>
	<?php 
}
?>
	<div class="post-inner">
		<div class="post-header">
			<h3><?php 
echo CHtml::link($content->title, Yii::app()->createUrl($content->slug));
?>
</h3>
			<?php 
$md = new CMarkdownParser();
echo strip_tags($md->safeTransform($content->extract), '<h1><h2><h3><h4><h5><6h><p><b><strong><i>');
?>
		</div>
		<div class="blog-meta">
			<span class="date"><?php 
echo Cii::timeAgo($content->published);
?>
</span>
			<span class="separator">⋅</span>
			<span class="blog-author minor-meta"><strong>by </strong>
				<span>
					<?php 
echo CHtml::link(CHtml::encode($content->author->displayName), $this->createUrl("/profile/{$content->author->id}/"));
?>
				</span>
Example #5
0
 /**
  * Prepares attributes before performing validation.
  */
 protected function beforeValidate($on)
 {
     $parser = new CMarkdownParser();
     $this->contentDisplay = $parser->safeTransform($this->content);
     if ($this->isNewRecord) {
         $this->createTime = time();
     }
     return true;
 }
Example #6
0
 /**
  * @var string $string 内容
  * @var boolean $purifyOutput 是否过滤HTML
  * 格式化数据内容,过滤html
  */
 static function CMarkdown($string, $purifyOutput = false)
 {
     $m = new CMarkdownParser();
     $output = $m->transform($string);
     if ($purifyOutput) {
         $purifier = new CHtmlPurifier();
         $output = $purifier->purify($output);
     }
     return $output;
     Yii::app()->controller->beginWidget('CMarkdown', array('purifyOutput' => $purifyOutput));
     echo $string;
     Yii::app()->controller->endWidget();
 }
Example #7
0
 public function actionSetup()
 {
     $parser = new CMarkdownParser();
     Yii::app()->clientScript->registerCss('TextHighligther', file_get_contents($parser->getDefaultCssFile()));
     $this->render('setup', array('parser' => $parser));
 }
 public function __construct()
 {
     $this->span_gamut += array("doApiLinks" => 35);
     parent::__construct();
 }
 public function transform($text)
 {
     $text = preg_replace_callback('~\\[\\[(.*?)(?:\\|(.*?))?\\]\\]~', array($this, 'processWikiLinks'), $text);
     return parent::transform($text);
 }
 /**
  * Prepare content
  * @return string content
  */
 protected function prepareContent($value)
 {
     if ($this->markdown) {
         $parser = new CMarkdownParser();
         return $this->safeTransform ? $parser->safeTransform($value) : $parser->transform($value);
     } else {
         return CHtml::encode($value);
     }
 }
Example #11
0
echo CHtml::link($user->name, 'index/' . $user->username);
?>
</strong>
            <span class="usertime"><?php 
echo '@' . $user->username;
?>
</span>
           <span class="usertime" data-livestamp="<?php 
echo $data->created;
?>
"></span>
           <div class="share-body">
               <?php 
$data->text = preg_replace("/#([A-Za-z0-9\\/\\.]*)/", "<a target=\"_new\" href=\"" . Yii::app()->controller->createAbsoluteUrl('timeline/search') . "?q=\$1\">#\$1</a>", $data->text);
$data->text = preg_replace("/@([A-Za-z0-9\\/\\.]*)/", "<a href=\"" . Yii::app()->controller->createAbsoluteUrl('timeline/index') . "/\$1\">@\$1</a>", $data->text);
$md = new CMarkdownParser();
echo $md->safeTransform($data->text);
?>
           </div>

           <div class="actions">
               <span style="cursor: pointer" class="fa fa-heart <?php 
echo $data->isLiked() ? 'liked' : NULL;
?>
"></span>
               <?php 
if ($data->author_id != Yii::app()->user->id) {
    ?>
                   <span style="cursor: pointer" class="fa fa-mail-forward"></span>
               <?php 
}
Example #12
0
File: rss.php Project: xl602/CiiMS
    if ($v->password != '') {
        continue;
    }
    ?>
			<item>
				<title><?php 
    echo htmlspecialchars(str_replace('/', '', $v['title']), ENT_QUOTES, "utf-8");
    ?>
</title>
				<link><?php 
    echo $url . '/' . htmlspecialchars(str_replace('/', '', $v['slug']), ENT_QUOTES, "utf-8");
    ?>
</link>
				<description>
					<?php 
    $md = new CMarkdownParser();
    echo htmlspecialchars(strip_tags($md->transform($v['extract'])), ENT_QUOTES, "utf-8");
    ?>
				</description>
				<category><?php 
    echo htmlspecialchars(Categories::model()->findByPk($v['category_id'])->name, ENT_QUOTES, "utf-8");
    ?>
</category>
				<author><?php 
    echo Users::model()->findByPk($v['author_id'])->email;
    ?>
 (<?php 
    echo Users::model()->findByPk($v['author_id'])->username;
    ?>
)</author>
				<pubDate><?php 
Example #13
0
    ?>
					<?php 
} else {
    ?>
						<?php 
    echo Yii::t('DefaultTheme', '{{count}} Comments', array('{{count}}' => $content->getCommentCount()));
    ?>
					<?php 
}
?>
			
				</span>
			</div>
			<div class="clearfix"></div>
				<?php 
$md = new CMarkdownParser();
$dom = new DOMDocument();
$dom->loadHtml('<?xml encoding="UTF-8">' . $md->safeTransform($content->content));
$x = new DOMXPath($dom);
foreach ($x->query('//a') as $node) {
    $element = $node->getAttribute('href');
    // Don't follow links outside of this site, and always open them in a new tab
    if ($element[0] !== "/") {
        $node->setAttribute('rel', 'nofollow');
        $node->setAttribute('target', '_blank');
    }
}
?>

				<div id="md-output"><?php 
echo $md->safeTransform($dom->saveHtml());
Example #14
0
 public function __construct($type)
 {
     $this->_type = $type;
     $this->span_gamut += array("doApiLinks" => 35, "doGuideLinks" => 15);
     parent::__construct();
 }
Example #15
0
			<?php 
    } else {
        ?>
				<div class="alert alert-info">
					<?php 
        echo Yii::t('DefaultTheme', "{{oops}} This user hasn't added any information about themself yet.", array('{{oops}}' => CHtml::tag('strong', array(), Yii::t('DefaultTheme', 'Oops!'))));
        ?>
				</div>
			<?php 
    }
    ?>
		<?php 
} else {
    ?>
			<?php 
    $md = new CMarkdownParser();
    ?>
			<?php 
    echo $md->safeTransform($about);
    ?>
		<?php 
}
?>
	</div>
</div>
<style>
 	main .main-body { margin-left: 0px; }
 	table td, table th { padding: 0px; padding-left: 5px; font-size: 12px; color: #777; }
</style>
<?php 
$this->widget('ext.timeago.JTimeAgo', array('selector' => ' .timeago'));
        <div class="panel-body">
            <?php 
    $parser = new CMarkdownParser();
    echo $parser->safeTransform($md);
    ?>

        </div>
    </div>

<?php 
} else {
    ?>

    <div class="container">

        <div class="row">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="custom_page_content">
                        <?php 
    $parser = new CMarkdownParser();
    echo $parser->safeTransform($md);
    ?>
                    </div>
                </div>
            </div>
        </div>
    </div>

<?php 
}
Example #17
0
 /**
  * Prepares comment before performing validation.
  */
 protected function beforeValidate()
 {
     $parser = new CMarkdownParser();
     $this->md_comment = $parser->transform($this->comment);
     return true;
 }
Example #18
0
 /**
  * Returns a safe output to the theme
  * This includes setting nofollow tags on links, forcing them to open in new windows, and safely encoding the text
  * @return string
  */
 public function getSafeOutput()
 {
     $md = new CMarkdownParser();
     $dom = new DOMDocument();
     $dom->loadHtml('<?xml encoding="UTF-8">' . $md->safeTransform($this->content));
     $x = new DOMXPath($dom);
     foreach ($x->query('//a') as $node) {
         $element = $node->getAttribute('href');
         if (isset($element[0]) && $element[0] !== "/") {
             $node->setAttribute('rel', 'nofollow');
             $node->setAttribute('target', '_blank');
         }
     }
     return $md->safeTransform($dom->saveHtml());
 }
Example #19
0
 /**
  * Process a string with markup
  *
  * @abstract
  * @param string $input
  * @return string $output
  */
 protected function processMarkup($input)
 {
     $md = new CMarkdownParser();
     return $md->transform($input);
 }
 public function actionPreview()
 {
     $parser = new CMarkdownParser();
     echo $parser->safeTransform($_POST['PortletCode'][$_GET['attribute']]);
 }
Example #21
0
 public function actionPreview()
 {
     $parser=new CMarkdownParser;
     echo $parser->safeTransform($_POST['data']);
 }
Example #22
0
			<span class="date"><?php 
    echo Cii::timeAgo($model->published);
    ?>
				<span class="separator">⋅</span> 
			</span>
			<span class="separator">⋅</span>
			<span class="minor-meta-wrap">
				<span class="blog-categories minor-meta">
					<?php 
    echo Yii::t('Dashboard.main', 'In {{category}}', array('{{category}}' => CHtml::link(CHtml::encode($model->category->name), Yii::app()->createUrl($model->category->slug))));
    ?>
				</span>
			</span>
		</div>
		<?php 
    $md = new CMarkdownParser();
    ?>
		<div id="md-output"></div>
		<textarea id="markdown" style="display:none"><?php 
    echo $model->content;
    ?>
</textarea>
		<span id="item-id" style="display:none;"><?php 
    echo $model->id;
    ?>
</span>
		<span id="item-status" style="display:none;"><?php 
    echo (int) $model->isPublished();
    ?>
</span>
		<noscript>
 protected function beforeValidate()
 {
     $parser = new CMarkdownParser();
     $this->html = $parser->transform($this->text);
     return parent::beforeValidate();
 }