示例#1
0
 /**
  * get list of all rated content
  *
  * @param $pListHash contains array of items used to limit search results
  * @param $pListHash[sort_mode] column and orientation by which search results are sorted
  * @param $pListHash[find] search for a pigeonhole title - case insensitive
  * @param $pListHash[max_records] maximum number of rows to return
  * @param $pListHash[offset] number of results data is offset by
  * @access public
  * @return array of rated content
  **/
 function getList(&$pListHash)
 {
     global $gBitSystem, $gBitUser, $gLibertySystem;
     $ret = $bindVars = array();
     $where = $join = $select = '';
     // set custom sorting before we call prepGetList()
     if (!empty($pListHash['sort_mode'])) {
         $order = " ORDER BY " . $this->mDb->convertSortmode($pListHash['sort_mode']) . " ";
     } else {
         // set a default sort_mode
         $order = " ORDER BY sts.`rating` DESC";
     }
     LibertyBase::prepGetList($pListHash);
     if (!empty($pListHash['user_id'])) {
         $where .= empty($where) ? ' WHERE ' : ' AND ';
         $where .= " sth.`user_id`=? ";
         $bindVars[] = $pListHash['user_id'];
         $select .= ", sth.`rating` AS `user_rating`";
         $join .= " LEFT OUTER JOIN `" . BIT_DB_PREFIX . "stars_history` sth ON( sts.`content_id` = sth.`content_id` ) ";
         $order = " ORDER BY sth.`rating` DESC";
     }
     if (!empty($pListHash['find'])) {
         $where .= empty($where) ? ' WHERE ' : ' AND ';
         $where .= " UPPER( lc.`title` ) LIKE ? ";
         $bindVars[] = '%' . strtoupper($pListHash['find']) . '%';
     }
     $query = "\n\t\t\tSELECT sts.*, lch.`hits`, lch.`last_hit`, lc.`event_time`, lc.`title`,\n\t\t\tlc.`last_modified`, lc.`content_type_guid`, lc.`ip`, lc.`created` {$select}\n\t\t\tFROM `" . BIT_DB_PREFIX . "stars` sts\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON ( lc.`content_id` = sts.`content_id` )\n\t\t\t\tLEFT JOIN `" . BIT_DB_PREFIX . "liberty_content_hits` lch ON ( lc.`content_id` = lch.`content_id` )\n\t\t\t{$join} {$where} {$order}";
     $result = $this->mDb->query($query, $bindVars, $pListHash['max_records'], $pListHash['offset']);
     $stars = $gBitSystem->getConfig('stars_used_in_display', 5);
     $pixels = $stars * $gBitSystem->getConfig('stars_icon_width', 22);
     while ($aux = $result->fetchRow()) {
         $type =& $gLibertySystem->mContentTypes[$aux['content_type_guid']];
         if (empty($type['content_object'])) {
             include_once $gBitSystem->mPackages[$type['handler_package']]['path'] . $type['handler_file'];
             $type['content_object'] = new $type['handler_class']();
         }
         if (!empty($gBitSystem->mPackages[$type['handler_package']])) {
             $aux['display_link'] = $type['content_object']->getDisplayLink($aux['title'], $aux);
             $aux['title'] = $type['content_object']->getTitleFromHash($aux);
             $aux['display_url'] = $type['content_object']->getDisplayUrl($aux);
             $aux['stars_pixels'] = $aux['rating'] * $pixels / 100;
         }
         $ret[] = $aux;
     }
     $query = "\n\t\t\tSELECT COUNT( sts.`content_id` )\n\t\t\tFROM `" . BIT_DB_PREFIX . "stars` sts\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON ( lc.`content_id` = sts.`content_id` )\n\t\t\t\tLEFT JOIN `" . BIT_DB_PREFIX . "liberty_content_hits` lch ON ( lc.`content_id` = lch.`content_id` )\n\t\t\t{$join} {$where}";
     $pListHash['cant'] = $this->mDb->getOne($query, $bindVars);
     LibertyContent::postGetList($pListHash);
     return $ret;
 }
示例#2
0
 /**
  * getList 
  * 
  * @param array $pListHash 
  * @access public
  * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  */
 function getList(&$pListHash)
 {
     global $gLibertySystem;
     if (empty($pListHash['sort_mode'])) {
         $pListHash['sort_mode'] = 'tagpos_asc';
     }
     LibertyBase::prepGetList($pListHash);
     $bindvars = array();
     if (!empty($pListHash['find'])) {
         $findesc = '%' . $pListHash['find'] . '%';
         $mid = " WHERE (`tagname` LIKE ?)";
         $bindvars[] = $findesc;
         if (!empty($pListHash['format_guid'])) {
             $mid = " AND `format_guid`=?";
             $bindvars[] = $pListHash['format_guid'];
         }
     } elseif (!empty($pListHash['format_guid'])) {
         $mid = " WHERE `format_guid`=?";
         $bindvars[] = $pListHash['format_guid'];
     } else {
         $mid = '';
     }
     $query = "SELECT * FROM `" . BIT_DB_PREFIX . "quicktags` {$mid} ORDER BY " . $this->mDb->convertSortmode($pListHash['sort_mode']);
     $result = $this->mDb->query($query, $bindvars, $pListHash['max_records'], $pListHash['offset']);
     $tmp = array();
     while ($res = $result->fetchRow()) {
         $res['iconpath'] = $res['tagicon'];
         $tmp[] = $res;
     }
     $ret = array();
     foreach ($gLibertySystem->mPlugins as $plugin) {
         if ($plugin['plugin_type'] == 'format') {
             foreach ($tmp as $qt) {
                 if ($qt['format_guid'] == $plugin['plugin_guid']) {
                     $ret[$plugin['plugin_guid']][] = $qt;
                 }
             }
         }
     }
     $pListHash["cant"] = $this->mDb->getOne("SELECT COUNT(*) FROM `" . BIT_DB_PREFIX . "quicktags` {$mid}", $bindvars);
     LibertyContent::postGetList($pListHash);
     return $ret;
 }
示例#3
0
 /**
  * Liberty override to stuff content_status_id and prepares parameters with default values for any getList function
  * @param pParamHash hash of parameters for any getList() function
  * @return the link to display the page.
  */
 public static function prepGetList(&$pListHash)
 {
     global $gBitUser;
     if ($gBitUser->isAdmin()) {
         $pListHash['min_content_status_id'] = -9999;
     } elseif (!empty($this) && is_object($this) && $this->hasAdminPermission()) {
         $pListHash['min_content_status_id'] = -999;
     } elseif (!empty($this) && is_object($this) && $this->hasUpdatePermission()) {
         $pListHash['min_content_status_id'] = -99;
     } else {
         $pListHash['min_content_status_id'] = 1;
     }
     if (empty($pListHash['query_cache_time'])) {
         $pListHash['query_cache_time'] = 0;
     }
     // if sort_mode is not set then use last_modified_desc
     if (!empty($pListHash['sort_mode'])) {
         if (is_string($pListHash['sort_mode']) && strpos($pListHash['sort_mode'], 'hits_') === 0) {
             // if sort mode is hits_*, then assume liberty content
             $pListHash['sort_mode'] = 'lch.' . $pListHash['sort_mode'];
         } elseif (is_array($pListHash['sort_mode'])) {
             foreach ($pListHash['sort_mode'] as $key => $mode) {
                 if (strpos($mode, 'hits_') === 0) {
                     $pListHash['sort_mode'][$key] = 'lch.' . $mode;
                 }
             }
         }
     } else {
         // if sort_mode is not set then use last_modified_desc
         $pListHash['sort_mode'] = 'last_modified_desc';
     }
     // Users without permission can only see their own content listing
     if ($gBitUser->isRegistered() && !$gBitUser->hasPermission('p_liberty_list_content')) {
         $pListHash['user_id'] = $gBitUser->mUserId;
     }
     return parent::prepGetList($pListHash);
 }
示例#4
0
 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('---&gt;' => 'arrow', '--&gt;' => '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. '&amp;&amp;...'
             $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;
 }
示例#5
0
 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;
 }