1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-16 23:00:51 +03:00

Возможность в настройках типа топика отключать поля с тектом топика и тегами. #409

This commit is contained in:
Mzhelskiy Maxim 2014-03-27 16:51:48 +07:00
parent 3ced26c8b8
commit e3cad50dbb
6 changed files with 88 additions and 35 deletions

View file

@ -238,6 +238,9 @@ class ActionContent extends Action {
$oTopic->_setDataSafe(getRequest('topic'));
$oTopic->setProperties(getRequest('property'));
$oTopic->setUserIp(func_getIp());
if (!$oTopic->getTags() or !$oTopic->getTypeObject()->getParam('allow_tags')) {
$oTopic->setTags('');
}
/**
* Публикуем или сохраняем в черновиках
*/
@ -282,11 +285,18 @@ class ActionContent extends Action {
/**
* Получаемый и устанавливаем разрезанный текст по тегу <cut>
*/
list($sTextShort,$sTextNew,$sTextCut) = $this->Text_Cut($oTopic->getTextSource());
$oTopic->setCutText($sTextCut);
// TODO: передача параметров в Topic_Parser пока не используется - нужно заменить на этот вызов все места с парсингом топика
$oTopic->setText($this->Topic_Parser($sTextNew,$oTopic));
$oTopic->setTextShort($this->Topic_Parser($sTextShort,$oTopic));
if ($oTopic->getTypeObject()->getParam('allow_text')) {
list($sTextShort,$sTextNew,$sTextCut) = $this->Text_Cut($oTopic->getTextSource());
$oTopic->setCutText($sTextCut);
// TODO: передача параметров в Topic_Parser пока не используется - нужно заменить на этот вызов все места с парсингом топика
$oTopic->setText($this->Topic_Parser($sTextNew,$oTopic));
$oTopic->setTextShort($this->Topic_Parser($sTextShort,$oTopic));
} else {
$oTopic->setCutText('');
$oTopic->setText('');
$oTopic->setTextShort('');
$oTopic->setTextSource('');
}
/**
* Сохраняем топик
*/
@ -359,6 +369,9 @@ class ActionContent extends Action {
$oTopic->setDateAdd(date("Y-m-d H:i:s"));
$oTopic->setUserIp(func_getIp());
$oTopic->setTopicType($sTopicType);
if (!$oTopic->getTags() or !$oTopic->getTypeObject()->getParam('allow_tags')) {
$oTopic->setTags('');
}
/**
* Публикуем или сохраняем
*/
@ -398,10 +411,17 @@ class ActionContent extends Action {
/**
* Получаем и устанавливаем разрезанный текст по тегу <cut>
*/
list($sTextShort,$sTextNew,$sTextCut) = $this->Text_Cut($oTopic->getTextSource());
$oTopic->setCutText($sTextCut);
$oTopic->setText($this->Topic_Parser($sTextNew,$oTopic));
$oTopic->setTextShort($this->Topic_Parser($sTextShort,$oTopic));
if ($oTopic->getTypeObject()->getParam('allow_text')) {
list($sTextShort,$sTextNew,$sTextCut) = $this->Text_Cut($oTopic->getTextSource());
$oTopic->setCutText($sTextCut);
$oTopic->setText($this->Topic_Parser($sTextNew,$oTopic));
$oTopic->setTextShort($this->Topic_Parser($sTextShort,$oTopic));
} else {
$oTopic->setCutText('');
$oTopic->setText('');
$oTopic->setTextShort('');
$oTopic->setTextSource('');
}
if ($this->Topic_AddTopic($oTopic)) {
$this->Hook_Run('topic_add_after', array('oTopic'=>$oTopic,'oBlog'=>$oBlog));

View file

@ -510,7 +510,7 @@ class ModuleProperty extends ModuleORM {
$sConditionFull=$sCondition.($bIsArray ? ' (?a) ' : ' ? ');
}
$iPropNum++;
$sJoin="JOIN prefix_property_value propv{$iPropNum} ON
$sJoin="JOIN ".Config::Get('db.table.property_value')." propv{$iPropNum} ON
t.`{$oEntitySample->_getPrimaryKey()}` = propv{$iPropNum}.target_id and
propv{$iPropNum}.target_type = '{$sTargetType}' and
propv{$iPropNum}.property_id = {$oProperty->getId()} and

View file

@ -35,12 +35,36 @@ class ModuleTopic_EntityTopic extends Entity {
public function Init() {
parent::Init();
$this->aValidateRules[]=array('topic_title','string','max'=>200,'min'=>2,'allowEmpty'=>false,'label'=>$this->Lang_Get('topic_create_title'));
$this->aValidateRules[]=array('topic_text_source','string','max'=>Config::Get('module.topic.max_length'),'min'=>2,'allowEmpty'=>false,'label'=>$this->Lang_Get('topic_create_text'));
$this->aValidateRules[]=array('topic_tags','tags','count'=>15,'label'=>$this->Lang_Get('topic_create_tags'),'allowEmpty'=>Config::Get('module.topic.allow_empty_tags'));
$this->aValidateRules[]=array('topic_text_source','string','max'=>Config::Get('module.topic.max_length'),'min'=>2,'allowEmpty'=>false,'condition'=>'isNeedValidateText','label'=>$this->Lang_Get('topic_create_text'));
$this->aValidateRules[]=array('topic_tags','tags','count'=>15,'condition'=>'isNeedValidateTags','label'=>$this->Lang_Get('topic_create_tags'),'allowEmpty'=>Config::Get('module.topic.allow_empty_tags'));
$this->aValidateRules[]=array('blog_id','blog_id');
$this->aValidateRules[]=array('topic_text_source','topic_unique');
}
/**
* Проверяет нужно проводить валидацию текста топика или нет
*
* @return bool
*/
public function isNeedValidateText() {
$oTopicType=$this->getTypeObject();
if (!$oTopicType or $oTopicType->getParam('allow_text')) {
return true;
}
return false;
}
/**
* Проверяет нужно проводить валидацию тегов топика или нет
*
* @return bool
*/
public function isNeedValidateTags() {
$oTopicType=$this->getTypeObject();
if (!$oTopicType or $oTopicType->getParam('allow_tags')) {
return true;
}
return false;
}
/**
* Проверка типа топика
*
@ -63,11 +87,13 @@ class ModuleTopic_EntityTopic extends Entity {
*/
public function ValidateTopicUnique($sValue,$aParams) {
$this->setTextHash(md5($this->getType().$sValue.$this->getTitle()));
if ($oTopicEquivalent=$this->Topic_GetTopicUnique($this->getUserId(),$this->getTextHash())) {
if ($iId=$this->getId() and $oTopicEquivalent->getId()==$iId) {
return true;
if ($this->isNeedValidateText()) {
if ($oTopicEquivalent=$this->Topic_GetTopicUnique($this->getUserId(),$this->getTextHash())) {
if ($iId=$this->getId() and $oTopicEquivalent->getId()==$iId) {
return true;
}
return $this->Lang_Get('topic_create_text_error_unique');
}
return $this->Lang_Get('topic_create_text_error_unique');
}
return true;
}

View file

@ -42,6 +42,8 @@ class ModuleTopic_EntityTopicType extends Entity {
$aParams=$this->getParamsArray();
$aParamsResult['allow_poll']=(isset($aParams['allow_poll']) and $aParams['allow_poll']) ? true : false;
$aParamsResult['allow_text']=(isset($aParams['allow_text']) and $aParams['allow_text']) ? true : false;
$aParamsResult['allow_tags']=(isset($aParams['allow_tags']) and $aParams['allow_tags']) ? true : false;
$this->setParams($aParamsResult);
return true;

View file

@ -75,18 +75,20 @@
{block name='add_topic_form_text_before'}{/block}
{* Текст топика *}
{* TODO: Max length for poll and link *}
{include file='forms/fields/form.field.textarea.tpl'
sFieldName = 'topic[topic_text_source]'
sFieldValue = {(($oTopicEdit) ? $oTopicEdit->getTextSource() : '')|escape:'html' }
sFieldRules = 'required="true" rangelength="[2,'|cat:$oConfig->Get('module.topic.max_length')|cat:']"'
sFieldLabel = $aLang.topic_create_text
sFieldClasses = 'width-full js-editor'}
{* Если визуальный редактор отключен выводим справку по разметке для обычного редактора *}
{if ! $oConfig->GetValue('view.wysiwyg')}
{include file='forms/editor.help.tpl' sTagsTargetId='topic_text'}
{* Текст топика *}
{if $oTopicType->getParam('allow_text')}
{include file='forms/fields/form.field.textarea.tpl'
sFieldName = 'topic[topic_text_source]'
sFieldValue = {(($oTopicEdit) ? $oTopicEdit->getTextSource() : '')|escape:'html' }
sFieldRules = 'required="true" rangelength="[2,'|cat:$oConfig->Get('module.topic.max_length')|cat:']"'
sFieldLabel = $aLang.topic_create_text
sFieldClasses = 'width-full js-editor'}
{* Если визуальный редактор отключен выводим справку по разметке для обычного редактора *}
{if ! $oConfig->GetValue('view.wysiwyg')}
{include file='forms/editor.help.tpl' sTagsTargetId='topic_text'}
{/if}
{/if}
@ -94,13 +96,15 @@
{* Теги *}
{include file='forms/fields/form.field.text.tpl'
sFieldName = 'topic[topic_tags]'
sFieldValue = {(($oTopicEdit) ? $oTopicEdit->getTags() : '')|escape:'html' }
sFieldRules = 'required="true" rangetags="[1,15]"'
sFieldNote = $aLang.topic_create_tags_notice
sFieldLabel = $aLang.topic_create_tags
sFieldClasses = 'width-full autocomplete-tags-sep'}
{if $oTopicType->getParam('allow_tags')}
{include file='forms/fields/form.field.text.tpl'
sFieldName = 'topic[topic_tags]'
sFieldValue = {(($oTopicEdit) ? $oTopicEdit->getTags() : '')|escape:'html' }
sFieldRules = 'required="true" rangetags="[1,15]"'
sFieldNote = $aLang.topic_create_tags_notice
sFieldLabel = $aLang.topic_create_tags
sFieldClasses = 'width-full autocomplete-tags-sep'}
{/if}
{* Показывает дополнительные поля *}
{$aBlockParams = []}

View file

@ -13,6 +13,7 @@
{$oBlog = $oTopic->getBlog()}
{$oFavourite = $oTopic->getFavourite()}
{$oTopicType = $oTopic->getTypeObject()}
{/block}
@ -64,7 +65,7 @@
{* Теги *}
{block 'entry_footer' prepend}
{if ! $bTopicList}
{if ! $bTopicList and $oTopicType->getParam('allow_tags')}
{include 'tag_list.tpl'
aTags = $oTopic->getTagsArray()
bTagsUseFavourite = true