Commits

Christoffer Niska committed 94fecbf

Added support for anchor links and HTMLPurifier configuration.

Comments (0)

Files changed (6)

 class Cms extends CApplicationComponent
 {
 	/**
-	 * @property array the names of the users that are allowed to updated the cms.
+	 * @var array the names of the users that are allowed to updated the cms.
 	 */
 	public $users = array('admin');
 	/**
-	 * @property array the languages that content can be translated in.
+	 * @var array the languages that content can be translated in.
 	 */
 	public $languages = array('en_us'=>'English');
 	/**
-	 * @property string the default locale.
+	 * @var string the default locale.
 	 */
 	public $defaultLanguage = 'en_us';
 	/**
-	 * @property string the allowed attachment files types.
+	 * @var string the allowed attachment files types.
 	 */
 	public $allowedFileTypes = 'jpg, gif, png';
     /**
-     * @property integer the maximum allowed attachment file size in bytes.
+     * @var integer the maximum allowed attachment file size in bytes.
      */
     public $allowedFileSize = 1024;
 	/**
-	 * @property string the path for saving attached files.
+	 * @var string the path for saving attached files.
 	 */
 	public $attachmentPath = '/files/cms/attachments/';
 	/**
-	 * @property string the template to use for node headings.
+	 * @var string the template to use for node headings.
 	 */
 	public $headingTemplate = '<h1 class="heading">{heading}</h1>';
 	/**
-	 * @property string the template to use for widget headings.
+	 * @var string the template to use for widget headings.
 	 */
 	public $widgetHeadingTemplate = '<h3 class="heading">{heading}</h3>';
 	/**
-	 * @property string the template to use for page titles.
+	 * @var string the template to use for page titles.
 	 */
 	public $pageTitleTemplate = '{title} | {appName}';
 	/**
-	 * @property string the application layout to use with the cms.
+	 * @var string the application layout to use with the cms.
 	 */
 	public $appLayout = 'application.views.layouts.main';
 	/**
-	 * @property string the flash message error category.
+	 * @var array the HTML purifier options.
+	 */
+	public $htmlPurifierOptions = array();
+	/**
+	 * @var string the flash message error category.
 	 */
 	public $flashError = 'error';
 	/**
-	 * @property string the flash message info category.
+	 * @var string the flash message info category.
 	 */
 	public $flashInfo = 'info';
 	/**
-	 * @property string the flash message success category.
+	 * @var string the flash message success category.
 	 */
 	public $flashSuccess = 'success';
 	/**
-	 * @property string the flash message warning category.
+	 * @var string the flash message warning category.
 	 */
 	public $flashWarning = 'warning';
 

models/CmsContent.php

 			array('locale', 'length', 'max'=>50),
 			array('heading, url, pageTitle, breadcrumb, metaTitle, metaDescription, metaKeywords', 'length', 'max'=>255),
             array('attachment', 'file', 'types'=>Yii::app()->cms->allowedFileTypes, 'maxSize'=>Yii::app()->cms->allowedFileSize, 'allowEmpty'=>true),
-			array('body, css', 'filter', 'filter'=>array($obj = new CHtmlPurifier(), 'purify')),
+			array('body, css', 'filter', 'filter'=>array($this->getPurifier(), 'purify')),
 			array('id, nodeId, locale, heading, url, pageTitle, breadcrumb, metaTitle, metaDescription, metaKeywords', 'safe', 'on'=>'search'),
 		);
 	}
 		$attachment->save();
 		$attachment->saveFile($file);
 	}
+
+	/**
+	 * Returns the HTMLPurifier instance for this content.
+	 * @return CHtmlPurifier the purifier
+	 */
+	protected function getPurifier()
+	{
+		$purifier = new CHtmlPurifier();
+		$purifier->options = CMap::mergeArray(Yii::app()->cms->htmlPurifierOptions, array(
+			'Attr.EnableID'=>true, // we need to enable the id attribute
+		));
+		return $purifier;
+	}
 }
 	protected $_patterns = array(
 		'file'=>'/{{file:([\d]+)}}/i',
 		'image'=>'/{{image:([\d]+)}}/i',
-		'link'=>'/{{([\w\d\._-]+|https?:\/\/[\w\d_-]*(\.[\w\d_-]*)+.*)\|([\w\d\s-]+)}}/i',
+		'link'=>'/{{(#?[\w\d\._-]+|https?:\/\/[\w\d_-]*(\.[\w\d_-]*)+.*)\|([\w\d\s-]+)}}/i',
 		'email'=>'/{{email:([\w\d!#$%&\'*+\\/=?^_`{|}~-]+(?:\.[\w\d!#$%&\'*+\\/=?^_`{|}~-]+)*@(?:[\w\d](?:[\w\d-]*[\w\d])?\.)+[\w\d](?:[\w\d-]*[\w\d])?)}}/i',
 		'node'=>'/{{node:([\w\d\._-]+)}}/i',
 	);
 		foreach ($matches[1] as $index => $target)
 		{
 			// If the target doesn't include 'http' it's treated as an internal link.
-			if (strpos($target, 'http') === false)
+			if (strpos($target, '#') !== 0 && strpos($target, 'http') === false)
 			{
 				/** @var Cms $cms */
 				$cms = Yii::app()->cms;

themes/bootstrap/views/cms/node/create.php

 
     <h1><?php echo Yii::t('CmsModule.core','Create node') ?></h1>
 
-	<?php $form = $this->beginWidget('ext.bootstrap.widgets.BootActiveForm',array(
+	<?php $form = $this->beginWidget('BootActiveForm',array(
 		'id'=>'cmsCreateNodeForm',
 		'stacked'=>true,
 		'htmlOptions'=>array('enctype'=>'multipart/form-data'),

themes/bootstrap/views/cms/node/update.php

 
     <h1><?php echo Yii::t('CmsModule.core','Update :name',array(':name'=>ucfirst($model->name))) ?></h1>
 
-	<?php $form = $this->beginWidget('ext.bootstrap.widgets.BootActiveForm',array(
+	<?php $form = $this->beginWidget('BootActiveForm',array(
 		'id'=>'cmsUpdateNodeForm',
 		//'enableAjaxValidation'=>true,
 		'stacked'=>true,
 	<li><strong>{{image:id}}</strong> &mdash; <em><?php echo Yii::t('CmsModule.core','displays an attached image'); ?></em></li>
 	<li><strong>{{file:id}}</strong> &mdash; <em><?php echo Yii::t('CmsModule.core','creates a link to an attached file'); ?></em></li>
 	<li><strong>{{email:address}}</strong> &mdash; <em><?php echo Yii::t('CmsModule.core','creates a mailto link'); ?></em></li>
-	<li><strong>{{name|text}}</strong> &mdash; <em><?php echo Yii::t('CmsModule.core','creates an internal link'); ?></em></li>
+	<li><strong>{{name|text}}</strong> &mdash; <em><?php echo Yii::t('CmsModule.core','creates a link to another page'); ?></em></li>
 	<li><strong>{{address|text}}</strong> &mdash; <em><?php echo Yii::t('CmsModule.core','creates an external link'); ?></em></li>
+	<li><strong>{{#anchor|text}}</strong> &mdash; <em><?php echo Yii::t('CmsModule.core','creates a link to an anchor on the page'); ?></em></li>
 </ul>