function getList(&$pListHash) { global $gBitUser, $gBitSystem, $gBitSmarty, $gLibertySystem; if (empty($_REQUEST["sort_mode"])) { $pListHash['sort_mode'] = 'shout_time_desc'; } LibertyBase::prepGetList($pListHash); $bindvars = array(); $mid = ''; if (!empty($pListHash['find'])) { $mid = " WHERE (UPPER(`shout_message`) like ?)"; $bindvars = array('%' . strtoupper($pListHash['find']) . '%'); } if (!empty($pListHash['user_id'])) { $mid .= empty($mid) ? ' WHERE ' : ' AND '; $mid .= " `shout_user_id` = ?"; array_push($bindvars, $pListHash['user_id']); } if (!empty($pListHash['to_user_id'])) { $mid .= empty($mid) ? ' WHERE ' : ' AND '; $mid .= " `to_user_id` = ?"; array_push($bindvars, $pListHash['to_user_id']); } $query = "\n\t\t\tSELECT * FROM `" . BIT_DB_PREFIX . "shoutbox` sh\n\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "users_users` uus ON (sh.`shout_user_id`=uus.`user_id`) {$mid}\n\t\t\tORDER BY " . $this->mDb->convertSortmode($pListHash['sort_mode']); $result = $this->mDb->query($query, $bindvars, $pListHash['max_records'], $pListHash['offset']); $ret = array(); while ($res = $result->fetchRow()) { if (!$res["shout_user_id"]) { $res["shout_user_id"] = tra('Anonymous'); } // get cached version if we have it if (!$this->mCache->isCached($res['shout_id'], filemtime(__FILE__))) { // convert ampersands and other stuff to xhtml compliant entities $res["shout_message"] = htmlspecialchars($res["shout_message"]); if ($gBitSystem->isFeatureActive('shoutbox_autolink')) { $hostname = ''; if ($gBitSystem->getConfig('shoutbox_autolink') == 'm') { //moderated URL's $hostname = $gBitSystem->getConfig('kernel_server_name') ? $gBitSystem->getConfig('kernel_server_name') : $_SERVER['HTTP_HOST']; } // we replace urls starting with http(s)|ftp(s) to active links $res["shout_message"] = preg_replace("/((http|ftp)+(s)?:\\/\\/[^<>\\s]*" . $hostname . "[^<>\\s]*)/i", "<a href=\"\\0\">\\0</a>", $res["shout_message"]); // we replace also urls starting with www. only to active links $res["shout_message"] = preg_replace("/(?<!http|ftp)(?<!s)(?<!:\\/\\/)(www\\." . $hostname . "[^ )\\s\r\n]*)/i", "<a href=\"http://\\0\">\\0</a>", $res["shout_message"]); // we replace also urls longer than 30 chars with translantable string as link description instead the URL itself to prevent breaking the layout in some browsers (e.g. Konqueror) $res["shout_message"] = preg_replace("/(<a href=\")((http|ftp)+(s)?:\\/\\/[^\"]+)(\">)([^<]){30,}<\\/a>/i", "<a href=\"\\2\">[" . tra('Link') . "]</a>", $res["shout_message"]); } if ($gBitSystem->isFeatureActive('shoutbox_smileys') && $gBitSystem->isPackageActive('smileys') && $gLibertySystem->isPluginActive('filtersmileys')) { if ($filterfunc = $gLibertySystem->getPluginFunction('filtersmileys', 'postparse_function')) { // note that we've already done the htmlspecialchars thing // things like :-)) need to preceed :-) $smileys = array('--->' => 'arrow', '-->' => 'arrow', ':-O' => 'surprised', '8-)' => 'cool', ':-|' => 'neutral', ':-/' => 'confused', ':-\\' => 'confused', ':-S' => 'confused', ';-)' => 'wink', ':-))))' => 'mrgreen', ':-)))' => 'lol', ':-))' => 'biggrin', ':-)' => 'smile', ':-((' => 'cry', ':-(' => 'sad', ':-P' => 'razz', '>:->' => 'twisted', '>:-(' => 'evil', '>:-|' => 'mad', '(?)' => 'question', '(!)' => 'exclaim'); foreach ($smileys as $str => $smiley) { $res['shout_message'] = str_replace($str, "(:{$smiley}:)", $res['shout_message']); } $filterfunc($res['shout_message'], $res); } } // if not in html tag (e.g. autolink), place after every '*;' the empty span too to prevent e.g. '&&...' $res["shout_message"] = preg_replace_callback('/(\\s*)([^>]+)(<|$)/', function ($m) { return $m[1] . str_replace(';', ';<span></span>', $m[2]) . $m[3]; }, $res["shout_message"]); // if not in tag or on a space or doesn't contain a html entity we split all plain text strings longer than 25 chars using the empty span tag again $wrap_at = 25; $res["shout_message"] = preg_replace_callback('/(\\s*)([^\\;>\\s]{' . $wrap_at . ',})([^&]<|$)/', function ($m) { return $m[1] . wordwrap($m[2], '".$wrap_at."', '<span></span>', 1) . $m[3]; }, $res["shout_message"]); $this->mCache->writeCacheFile($res['shout_id'], $res['shout_message']); } $res['shout_message'] = $this->mCache->readCacheFile($res['shout_id']); // work out permissions $res['is_editable'] = $gBitUser->isRegistered() && ($gBitUser->hasPermission('p_shoutbox_admin') || $gBitUser->getUserId() == $res['shout_user_id']); $res['is_deletable'] = $gBitUser->isRegistered() && ($gBitUser->hasPermission('p_shoutbox_admin') || $gBitUser->getUserId() == $res['shout_user_id'] || $gBitUser->getUserId() == $res['to_user_id']); $ret[] = $res; } $query_cant = "SELECT COUNT(*) FROM `" . BIT_DB_PREFIX . "shoutbox` {$mid}"; $pListHash["cant"] = $this->mDb->getOne($query_cant, $bindvars); LibertyBase::postGetList($pListHash); return $ret; }
function getList(&$pListHash) { global $gBitUser; // ====================== Private Messages ====================== if (empty($pListHash['sort_mode'])) { $pListHash['sort_mode'] = 'msg_date_desc'; } LibertyBase::prepGetList($pListHash); $ret = $bindVars = array(); $whereSql = ''; $bindVars[] = $gBitUser->mUserId; if (!empty($pListHash['priority'])) { $whereSql .= " AND mm.`priority`=? "; $bindVars[] = $pListHash['priority']; } if (!empty($pListHash['flag']) && !empty($pListHash['flagval'])) { $whereSql .= " AND mm.`{$pListHash['flag']}`=? "; $bindVars[] = $pListHash['flagval']; } if (!empty($pListHash['find'])) { $whereSql .= " AND( UPPER( mm.`subject` ) LIKE ? OR UPPER( mm.`body` ) LIKE ? ) "; $bindVars[] = '%' . strtoupper($pListHash['find']) . '%'; $bindVars[] = '%' . strtoupper($pListHash['find']) . '%'; } $query = "\n\t\t\tSELECT\n\t\t\t\tuu.`login`, uu.`real_name`, uu.`user_id`,\n\t\t\t\tmm.*\n\t\t\tFROM `" . BIT_DB_PREFIX . "messages` mm\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "users_users` uu ON( mm.`from_user_id`=uu.`user_id` )\n\t\t\tWHERE mm.`to_user_id`=? {$whereSql}\n\t\t\tORDER BY " . $this->mDb->convertSortmode($pListHash['sort_mode']); $normalMessages = $this->mDb->getAll($query, $bindVars); // Get the total count of private messages $query = "SELECT COUNT(*) FROM `" . BIT_DB_PREFIX . "messages` mm WHERE mm.`to_user_id`=? {$whereSql}"; $cant = $this->mDb->getOne($query, $bindVars); // ====================== Broadcast Messages ====================== //array_unshift( $bindVars, $gBitUser->mUserId, ROOT_USER_ID, $gBitUser->mUserId ); $bindVars = array($gBitUser->mUserId, ROOT_USER_ID, $gBitUser->mUserId); $whereSql = ''; if (!empty($pListHash['priority'])) { $whereSql .= " AND mm.`priority`=? "; $bindVars[] = $pListHash['priority']; } if (!empty($pListHash['flag']) && !empty($pListHash['flagval'])) { $whereSql .= " AND msm.`{$pListHash['flag']}`=? "; $bindVars[] = $pListHash['flagval']; } if (!empty($pListHash['find'])) { $whereSql .= " AND( UPPER( mm.`subject` ) LIKE ? OR UPPER( mm.`body` ) LIKE ? ) "; $bindVars[] = '%' . strtoupper($pListHash['find']) . '%'; $bindVars[] = '%' . strtoupper($pListHash['find']) . '%'; } $query = "\n\t\t\tSELECT\n\t\t\t\tuu.`login`, uu.`real_name`, uu.`user_id`, mm.`msg_id` as `msg_id_foo`,\n\t\t\t\tmsm.*,\n\t\t\t\tmm.`msg_to`, mm.`msg_cc`, mm.`msg_bcc`, mm.`subject`, mm.`body`, mm.`hash`, mm.`msg_date`, mm.`priority`\n\t\t\tFROM `" . BIT_DB_PREFIX . "messages` mm\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "users_users` uu ON (mm.`from_user_id` = uu.`user_id`)\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "messages_system_map` msm ON (mm.`msg_id` = msm.`msg_id` AND msm.`to_user_id` = ?)\n\t\t\tWHERE mm.`to_user_id`=? AND mm.`group_id` IN (SELECT `group_id` FROM `" . BIT_DB_PREFIX . "users_groups_map` WHERE `user_id` = ?) {$whereSql}\n\t\t\tORDER BY " . $this->mDb->convertSortmode($pListHash['sort_mode']); $result = $this->mDb->query($query, $bindVars); $systemMessages = array(); while ($aux = $result->fetchRow()) { $aux['is_broadcast_message'] = TRUE; $aux['msg_id'] = $aux['msg_id_foo']; // Due to the left outer join this madness is neccessary unset($aux['msg_id_foo']); if ($aux['is_hidden'] != 'y') { $systemMessages[] = $aux; } } $query = "\n\t\t\tSELECT COUNT(mm.`msg_id`)\n\t\t\tFROM `" . BIT_DB_PREFIX . "messages` mm\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "messages_system_map` msm ON (mm.`msg_id` = msm.`msg_id` AND msm.`to_user_id` = ?)\n\t\t\tWHERE mm.`to_user_id`=? AND mm.`group_id` IN (SELECT `group_id` FROM `" . BIT_DB_PREFIX . "users_groups_map` WHERE `user_id` = ?) {$whereSql}"; $cant2 = $this->mDb->getOne($query, $bindVars); // ====================== insane message mergin and sorting ====================== $sort_mode = $pListHash['sort_mode']; $ret = array(); $normalMessageCount = count($normalMessages); $systemMessageCount = count($systemMessages); $normalMsg = $systemMsg = NULL; if (strpos($sort_mode, '_asc') !== FALSE) { $sortType = '_asc'; $sortKey = substr($sort_mode, 0, strlen($sort_mode) - 4); } else { $sortType = '_desc'; $sortKey = substr($sort_mode, 0, strlen($sort_mode) - 5); } while ($normalMessageCount > 0 || $systemMessageCount > 0) { if (!$normalMsg && $normalMessageCount > 0) { $normalMsg = array_shift($normalMessages); } if (!$systemMsg && $systemMessageCount > 0) { $systemMsg = array_shift($systemMessages); } if ($normalMessageCount == 0) { $ret[] = $systemMsg; $systemMsg = NULL; $systemMessageCount--; } elseif ($systemMessageCount == 0) { $ret[] = $normalMsg; $normalMsg = NULL; $normalMessageCount--; } elseif ($sortType == '_asc') { if ($normalMsg[$sortKey] < $systemMsg[$sortKey]) { $ret[] = $normalMsg; $normalMsg = NULL; $normalMessageCount--; } else { $ret[] = $systemMsg; $systemMsg = NULL; $systemMessageCount--; } } else { if ($normalMsg[$sortKey] > $systemMsg[$sortKey]) { $ret[] = $normalMsg; $normalMsg = NULL; $normalMessageCount--; } else { $ret[] = $systemMsg; $systemMsg = NULL; $systemMessageCount--; } } } // set some default values foreach ($ret as $key => $msg) { $msg['len'] = strlen($msg['body']); if (empty($msg['is_read'])) { $msg['is_read'] = 'n'; } if (empty($msg['subject'])) { $msg['subject'] = tra('none'); } $ret[$key] = $msg; } $pListHash["cant"] = $cant + $cant2; LibertyBase::postGetList($pListHash); return $ret; }