/**
  * {@inheritdoc}
  */
 public function synchronize()
 {
     $this->comments = array();
     $result = PersistenceContext::get_querier()->select("\n\t\t\tSELECT comments.*, topic.*, member.*\n\t\t\tFROM " . DB_TABLE_COMMENTS . " comments\n\t\t\tLEFT JOIN " . DB_TABLE_COMMENTS_TOPIC . " topic ON comments.id_topic = topic.id_topic\n\t\t\tLEFT JOIN " . DB_TABLE_MEMBER . " member ON member.user_id = comments.user_id\n\t\t\tORDER BY comments.timestamp " . CommentsConfig::load()->get_order_display_comments());
     while ($row = $result->fetch()) {
         $this->comments[$row['id']] = array('id' => $row['id'], 'id_topic' => $row['id_topic'], 'module_id' => $row['module_id'], 'id_in_module' => $row['id_in_module'], 'topic_identifier' => $row['topic_identifier'], 'message' => $row['message'], 'note' => $row['note'], 'timestamp' => $row['timestamp'], 'path' => $row['path'], 'user_id' => $row['user_id']);
     }
 }
 public function __construct($id_comment, $topic_path)
 {
     $this->id_comment = $id_comment;
     $this->user = AppContext::get_current_user();
     $this->lang = LangLoader::get('main');
     $this->topic_path = $topic_path;
     $this->comments_lang = LangLoader::get('comments-common');
     $this->comments_configuration = CommentsConfig::load();
 }
 public function __construct(CommentsTopic $comments_topic)
 {
     $this->module_id = $comments_topic->get_module_id();
     $this->id_in_module = $comments_topic->get_id_in_module();
     $this->topic_identifier = $comments_topic->get_topic_identifier();
     $this->topic_path = $comments_topic->get_path();
     $this->comments_topic = $comments_topic;
     $this->user = AppContext::get_current_user();
     $this->lang = LangLoader::get('main');
     $this->common_lang = LangLoader::get('common');
     $this->comments_lang = LangLoader::get('comments-common');
     $this->comments_configuration = CommentsConfig::load();
 }
 /**
  * @return int number comments display default
  */
 public function get_number_comments_display()
 {
     return CommentsConfig::load()->get_number_comments_display();
 }
 public function get_right_controller_regarding_authorizations()
 {
     if (!AppContext::get_current_user()->check_auth(CommentsConfig::load()->get_authorizations(), CommentsAuthorizations::READ_AUTHORIZATIONS)) {
         $error_controller = PHPBoostErrors::user_not_authorized();
         DispatchManager::redirect($error_controller);
     }
     return $this;
 }
 private function save()
 {
     $this->configuration->set_authorizations($this->form->get_value('authorizations')->build_auth_array());
     $this->configuration->set_number_comments_display($this->form->get_value('number_comments_display'));
     $forbidden_tags = array();
     foreach ($this->form->get_value('forbidden_tags') as $field => $option) {
         $forbidden_tags[] = $option->get_raw_value();
     }
     $this->configuration->set_forbidden_tags($forbidden_tags);
     $this->configuration->set_max_links_comment($this->form->get_value('max_links_comment'));
     $this->configuration->set_order_display_comments($this->form->get_value('order_display_comments')->get_raw_value());
     CommentsConfig::save();
 }
 private function check_authorizations($global_bit)
 {
     return AppContext::get_current_user()->check_auth(CommentsConfig::load()->get_authorizations(), $global_bit);
 }
 /**
  * @desc Do not use, this is used for ajax display comments
  * @param string $module_id the module identifier
  * @param integer $id_in_module id in module used in comments system
  * @param string $topic_identifier topic identifier (use if you have several comments system)
  * @return object View is a view
  */
 public static function display_comments($module_id, $id_in_module, $topic_identifier, $number_comments_display, $authorizations, $display_from_number_comments = false)
 {
     $template = new FileTemplate('framework/content/comments/comments_list.tpl');
     if ($authorizations->is_authorized_read() && $authorizations->is_authorized_access_module()) {
         $user_accounts_config = UserAccountsConfig::load();
         $condition = !$display_from_number_comments ? ' LIMIT ' . $number_comments_display : ' LIMIT ' . $number_comments_display . ',18446744073709551615';
         $result = PersistenceContext::get_querier()->select("\n\t\t\t\tSELECT comments.*, comments.timestamp AS comment_timestamp, comments.id AS id_comment,\n\t\t\t\ttopic.is_locked, topic.path,\n\t\t\t\tmember.user_id, member.display_name, member.level, member.groups, \n\t\t\t\text_field.user_avatar\n\t\t\t\tFROM " . DB_TABLE_COMMENTS . " comments\n\t\t\t\tLEFT JOIN " . DB_TABLE_COMMENTS_TOPIC . " topic ON comments.id_topic = topic.id_topic\n\t\t\t\tLEFT JOIN " . DB_TABLE_MEMBER . " member ON member.user_id = comments.user_id\n\t\t\t\tLEFT JOIN " . DB_TABLE_MEMBER_EXTENDED_FIELDS . " ext_field ON ext_field.user_id = comments.user_id\n\t\t\t\tWHERE topic.module_id = '" . $module_id . "' AND topic.id_in_module = '" . $id_in_module . "' AND topic.topic_identifier = '" . $topic_identifier . "'\n\t\t\t\tORDER BY comments.timestamp " . CommentsConfig::load()->get_order_display_comments() . " " . $condition);
         while ($row = $result->fetch()) {
             $id = $row['id_comment'];
             $path = $row['path'];
             //Avatar
             $user_avatar = !empty($row['user_avatar']) ? Url::to_rel($row['user_avatar']) : ($user_accounts_config->is_default_avatar_enabled() ? Url::to_rel('/templates/' . AppContext::get_current_user()->get_theme() . '/images/' . $user_accounts_config->get_default_avatar_name()) : '');
             $timestamp = new Date($row['comment_timestamp'], Timezone::SERVER_TIMEZONE);
             $group_color = User::get_group_color($row['groups'], $row['level']);
             $template->assign_block_vars('comments', array('C_MODERATOR' => self::is_authorized_edit_or_delete_comment($authorizations, $id), 'C_VISITOR' => empty($row['display_name']), 'C_GROUP_COLOR' => !empty($group_color), 'C_AVATAR' => $row['user_avatar'] || $user_accounts_config->is_default_avatar_enabled(), 'U_EDIT' => CommentsUrlBuilder::edit($path, $id)->rel(), 'U_DELETE' => CommentsUrlBuilder::delete($path, $id)->rel(), 'U_PROFILE' => UserUrlBuilder::profile($row['user_id'])->rel(), 'U_AVATAR' => $user_avatar, 'ID_COMMENT' => $id, 'DATE' => $timestamp->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE), 'DATE_ISO8601' => $timestamp->format(Date::FORMAT_ISO8601), 'MESSAGE' => FormatingHelper::second_parse($row['message']), 'USER_ID' => $row['user_id'], 'PSEUDO' => empty($row['display_name']) ? $row['pseudo'] : $row['display_name'], 'LEVEL_CLASS' => UserService::get_level_class($row['level']), 'GROUP_COLOR' => $group_color, 'L_LEVEL' => UserService::get_level_lang($row['level'] !== null ? $row['level'] : '-1')));
             $template->put_all(array('L_UPDATE' => self::$common_lang['edit'], 'L_DELETE' => self::$common_lang['delete']));
         }
         $result->dispose();
     }
     self::$template->put_all(array('MODULE_ID' => $module_id, 'ID_IN_MODULE' => $id_in_module, 'TOPIC_IDENTIFIER' => $topic_identifier));
     return $template;
 }