Skip to content

Commit

Permalink
Добавлен параметр конфигурации:
Browse files Browse the repository at this point in the history
- $config['for_comments'] - Разрешить изменять пользователя для комментариев.
  • Loading branch information
wasja1982 committed Apr 29, 2014
1 parent 7fc89be commit 8488673
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 2 deletions.
28 changes: 28 additions & 0 deletions classes/hooks/HookPublishfrom.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public function RegisterHook() {
$this->AddHook('template_form_add_topic_link_end','template_form_add_topic_topic_end');
$this->AddHook('template_form_add_topic_question_end','template_form_add_topic_topic_end');
$this->AddHook('template_form_add_topic_photoset_end','template_form_add_topic_topic_end');

if (Config::Get('plugin.newpublishfrom.for_comments')) {
$this->AddHook('comment_add_after','comment_add_after');
$this->AddHook('template_form_add_comment_end','template_form_add_comment_end');
}
}

public function topic_after($arg){
Expand Down Expand Up @@ -46,7 +51,29 @@ public function topic_after($arg){
}
}

public function comment_add_after($arg){
$oComment = $arg['oCommentNew'];
$oUser = $this->User_GetUserCurrent();
if ($oComment && $oUser && $oUser->isAdministrator()){
$uid = intval(getRequest(Config::Get('plugin.newpublishfrom.select_name')));
if (!$uid) {
$uid = $oUser->getId();
}
$oComment->setUser($this->User_GetUserById($uid));
$oComment->setUserId($uid);
$this->PluginNewpublishfrom_Publishfrom_UpdateComment($oComment);
}
}

public function template_form_add_topic_topic_end(){
return $this->template_form_add(true);
}

public function template_form_add_comment_end(){
return $this->template_form_add(false);
}

private function template_form_add($bTopic = true){
if($this->User_GetUserCurrent()->isAdministrator()){
$oUserCurrent = $this->User_GetUserCurrent();
$oAuthorId = null;
Expand All @@ -61,6 +88,7 @@ public function template_form_add_topic_topic_end(){
$this->Viewer_Assign("oUserCurrent",$oUserCurrent);
$this->Viewer_Assign("sSelectName",Config::Get('plugin.newpublishfrom.select_name'));
$this->Viewer_Assign("aUserList",$aUserList);
$this->Viewer_Assign("bTopic",$bTopic);
return $this->Viewer_Fetch(Plugin::GetTemplatePath(__CLASS__).'form_select.tpl');
}
}
Expand Down
9 changes: 9 additions & 0 deletions classes/modules/publishfrom/Publishfrom.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ public function UpdateTopic($oTopic){
}
return false;
}

public function UpdateComment($oComment) {
if ($this->oMapper->UpdateComment($oComment)) {
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("comment_update","comment_update_{$oComment->getTargetType()}_{$oComment->getTargetId()}"));
$this->Cache_Delete("comment_{$oComment->getId()}");
return true;
}
return false;
}
}
13 changes: 13 additions & 0 deletions classes/modules/publishfrom/mapper/Publishfrom.mapper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,17 @@ public function UpdateTopic($oTopic) {
}
return false;
}

public function UpdateComment($oComment) {
$sql = "UPDATE ".Config::Get('db.table.comment')."
SET
user_id= ?d
WHERE
comment_id = ?d
";
if ($this->oDb->query($sql,$oComment->getUserId(),$oComment->getId())) {
return true;
}
return false;
}
}
3 changes: 3 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@
// Изменять пользователя только при публикации
$config['only_publish'] = false;

// Разрешить изменять пользователя для комментариев
$config['for_comments'] = true;

return $config;
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

5) $config['only_publish'] - Изменять пользователя только при публикации (черновики сохраняются от администратора).

6) $config['for_comments'] - Разрешить изменять пользователя для комментариев.

Поддерживается 3 метода указания пользователей, от имени которых поддерживается публикация:
1) по имени пользователя — необходимо добавить имена пользователей в массив:
$config['user_logins'] = array('Marat','Kiril','Julia');
Expand Down
3 changes: 2 additions & 1 deletion templates/language/russian.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@

return array(
'publishfrom_label' => 'Выберите автора',
'publishfrom_note' => 'Топик будет полностью принадлежать выбраному Вами пользователю, включая черновик. <br> Черновик лучше сохранять от своего имени',
'publishfrom_note_topic' => 'Топик будет полностью принадлежать выбраному Вами пользователю, включая черновик. <br> Черновик лучше сохранять от своего имени',
'publishfrom_note_comment' => 'Комментарий будет опубликован от имени выбраного Вами пользователя',
);
2 changes: 1 addition & 1 deletion templates/skin/default/form_select.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
<option value="{$item.user_id}"{if $oAuthorId==$item.user_id}selected="selected"{/if}>{$item.user_login}</option>
{/foreach}
</select>
<span class="note">{$aLang.plugin.newpublishfrom.publishfrom_note}</span>
<span class="note">{if $bTopic}{$aLang.plugin.newpublishfrom.publishfrom_note_topic}{else}{$aLang.plugin.newpublishfrom.publishfrom_note_comment}{/if}</span>
</p>

0 comments on commit 8488673

Please sign in to comment.