Exemple #1
0
 /**
  * Get user information for a particular user
  *
  * @param pUseLink return the information in the form of a url that links to the users information page
  * @param pHash todo - need explanation on how to use this...
  * @return display name or link to user information page
  **/
 public static function getDisplayNameFromHash($pUseLink = FALSE, $pHash)
 {
     global $gBitSystem, $gBitUser;
     if (!empty($pHash)) {
         if (!empty($pHash['real_name']) && $gBitSystem->getConfig('users_display_name', 'real_name') == 'real_name') {
             $displayName = $pHash['real_name'];
         } elseif (!empty($pHash['user'])) {
             $displayName = $pHash['user'];
         } elseif (!empty($pHash['login'])) {
             $displayName = $pHash['login'];
         } elseif (!empty($pHash['email'])) {
             $displayName = substr($pHash['email'], 0, strpos($pHash['email'], '@'));
         } else {
             $displayName = $pHash['user_id'];
         }
         if (!empty($pHash['user'])) {
             $iHomepage = $pHash['user'];
         } elseif (!empty($pHash['login'])) {
             // user of 'login' is deprecated and eventually should go away!
             $iHomepage = $pHash['login'];
         } elseif (BitBase::verifyId($pHash['user_id'])) {
             $iHomepage = $pHash['user_id'];
         } elseif (!empty($pHash['email'])) {
             $iHomepage = $pHash['email'];
         } else {
             // this won't work right now, we need to alter userslib::interpret_home() to interpret a real name
             $iHomepage = $pHash['real_name'];
         }
         if (empty($pHash['users_information']) && !empty($pHash['login'])) {
             $pHash['users_information'] = $gBitSystem->mDb->getOne("SELECT pref_value FROM liberty_content_prefs lcp INNER JOIN users_users uu ON (lcp.content_id=uu.content_id) WHERE uu.login=? AND pref_name='users_information'", array($pHash['login']), 1, NULL, 86400);
         }
         if ($pUseLink && $gBitUser->hasPermission('p_users_view_user_homepage') && (empty($pHash['users_information']) || $pHash['users_information'] == 'public')) {
             $ret = '<a class="username" title="' . (!empty($pHash['link_title']) ? $pHash['link_title'] : tra('Profile for') . ' ' . htmlspecialchars($displayName)) . '" href="' . BitUser::getDisplayUrlFromHash($pHash) . '">' . htmlspecialchars(isset($pHash['link_label']) ? $pHash['link_label'] : $displayName) . '</a>';
         } else {
             $ret = htmlspecialchars($displayName);
         }
     } else {
         $ret = tra("Anonymous");
     }
     return $ret;
 }
Exemple #2
0
 /**
  * This function gets a list of posts
  */
 function getList(&$pListHash)
 {
     global $gBitUser, $gBitSystem;
     $this->prepGetList($pListHash);
     $joinSql = $selectSql = $whereSql = '';
     $ret = array();
     $contentId = $this->mCommentId;
     //		$mid = 'ORDER BY `thread_forward_sequence` ASC';
     $bindVars = array();
     if (!empty($pListHash['content_id'])) {
         if (is_array($contentId)) {
             $mid2 = 'in (' . implode(',', array_fill(0, count($pListHash['content_id']), '?')) . ')';
             $bindVars = $contentId;
             $selectSql = ', lcp.content_type_guid as parent_content_type_guid, lcp.title as parent_title ';
             $joinSql .= " LEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_content` lcp ON (lcp.content_id = lcom.parent_id) ";
         } elseif (is_numeric($contentId)) {
             $whereSql .= " AND `thread_forward_sequence` LIKE '" . sprintf("%09d.", $contentId) . "%'";
         }
     }
     if ($gBitSystem->isFeatureActive('boards_posts_anon_moderation') && !($gBitUser->hasPermission('p_boards_update') || $gBitUser->hasPermission('p_boards_post_update'))) {
         $whereSql .= " AND ((post.`is_approved` = 1) OR (lc.`user_id` >= 0))";
     }
     $this->getServicesSql('content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, $this);
     if (!empty($pListHash['board_id'])) {
         $joinSql .= "INNER JOIN `" . BIT_DB_PREFIX . "boards` b ON (b.`content_id` = bm.`board_content_id`)";
         $whereSql .= ' AND b.`board_id`=? ';
         array_push($bindVars, (int) $pListHash['board_id']);
     }
     if (BitBase::verifyId($pListHash['user_id'])) {
         $whereSql .= ' AND lc.`user_id`=? ';
         array_push($bindVars, $pListHash['user_id']);
     }
     if (!empty($whereSql)) {
         $whereSql = preg_replace('/^[\\s]*AND\\b/i', 'WHERE ', $whereSql);
     }
     $sql = "SELECT lcom.`comment_id`, lcom.`parent_id`, lcom.`root_id`, lcom.`thread_forward_sequence`, lcom.`thread_reverse_sequence`, lcom.`anon_name`, lc.*, uu.`email`, uu.`real_name`, uu.`login`, post.is_approved, post.is_warned, post.warned_message, uu.registration_date AS registration_date,\n\t\t\t\t\ttf_ava.`file_name` AS `avatar_file_name`, tf_ava.`mime_type` AS `avatar_mime_type`, tf_ava.`user_id` AS `avatar_user_id`, ta_ava.`attachment_id` AS `avatar_attachment_id`\n\t\t\t\t\t{$selectSql}\n\t\t\t\tFROM `" . BIT_DB_PREFIX . "liberty_comments` lcom\n\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "boards_map` bm ON (lcom.`root_id` = bm.`topic_content_id`)\n\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON (lcom.`content_id` = lc.`content_id`)\n\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "users_users` uu ON (lc.`user_id` = uu.`user_id`)\n\t\t\t\t\t {$joinSql}\n\t\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_attachments` ta_ava ON ( uu.`avatar_attachment_id`=ta_ava.`attachment_id` )\n\t\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_files` tf_ava ON ( tf_ava.`file_id`=ta_ava.`foreign_id` )\n\t\t\t\t\tLEFT JOIN `" . BIT_DB_PREFIX . "boards_posts` post ON (post.`comment_id` = lcom.`comment_id`)\n\t\t\t\t{$whereSql} ORDER BY " . $this->mDb->convertSortmode($pListHash['sort_mode']);
     $ret = array();
     if ($result = $this->mDb->query($sql, $bindVars, $pListHash['max_records'], $pListHash['offset'])) {
         while ($row = $result->FetchRow()) {
             if (empty($row['anon_name'])) {
                 $row['anon_name'] = "Anonymous";
             }
             if (!empty($row['avatar_file_name'])) {
                 $row['user_avatar_url'] = liberty_fetch_thumbnail_url(array('source_file' => liberty_mime_get_source_file(array('user_id' => $row['avatar_user_id'], 'file_name' => $row['avatar_file_name'], 'mime_type' => $row['avatar_mime_type'], 'attachment_id' => $row['avatar_attachment_id'])), 'size' => 'avatar'));
             } else {
                 $row['user_avatar_url'] = FALSE;
             }
             unset($row['avatar_file_name']);
             if (!empty($row['warned_message'])) {
                 $row['warned_message'] = str_replace("\n", "<br />\n", $row['warned_message']);
             }
             $row['data'] = trim($row['data']);
             $row['user_url'] = BitUser::getDisplayUrlFromHash($row);
             $row['parsed_data'] = $this->parseData($row);
             $row['level'] = substr_count($row['thread_forward_sequence'], '.') - 1;
             $row['topic_id'] = boards_get_topic_comment($row['thread_forward_sequence']);
             $row['display_url'] = static::getDisplayUrlFromHash($row);
             $c = new LibertyComment();
             $c->mInfo = $row;
             $row['is_editable'] = $c->userCanEdit();
             $ret[] = $row;
             //va($row);
         }
     }
     return $ret;
 }