function get_current_user_votes($user) { require_once mnminclude . 'votes.php'; $vote = new Vote(); $vote->type = 'links'; $vote->user = $user; $vote->link = $this->id; $results = $vote->user_list_all_votes(); $votes = 0; $reports = 0; if (is_array($results)) { foreach ($results as $row) { if (isset($row->vote_value)) { if ($row->vote_value > 0) { $votes = $votes + 1; } if ($row->vote_value < 0) { $reports = $reports + 1; } } } } $this->current_user_votes = $votes; $this->current_user_reports = $reports; }
} if ($ls_debug == true) { echo '<br />' . sanitize($rows, 3) . '<br />'; } $links = $db->get_col($linksum_sql); $the_results = $links; } if ($the_results) { // find out if the logged in user voted / reported each of // the stories that the search found and cache the results require_once mnminclude . 'votes.php'; $vote = new Vote(); $vote->type = 'links'; $vote->user = $current_user->user_id; $vote->link = $the_results; $results = $vote->user_list_all_votes(); $vote = ''; $results = ''; // we don't actually need the results // we're just calling this to cache the results // so when we foreach the links we don't have to // run 1 extra query for each story to determine // current user votes // setup the link cache $sql = "SELECT " . table_links . ".* FROM " . table_links . " WHERE "; $sql_saved = "SELECT * FROM " . table_saved_links . " WHERE saved_user_id=" . $current_user->user_id . " AND "; $ids = array(); foreach ($the_results as $link_id) { // first make sure we don't already have it cached if (!isset($cached_links[$link_id])) { $ids[] = $link_id;
function get_current_user_votes($user) { require_once mnminclude . 'votes.php'; $vote = new Vote(); $vote->type = 'links'; $vote->user = $user; $vote->link = $this->id; $results = $vote->user_list_all_votes(); $votes = 0; $reports = 0; if (is_array($results)) { foreach ($results as $row) { if (isset($row->vote_value)) { if ($row->vote_value > 0) { $votes = $votes + 1; } if ($row->vote_value < 0) { $reports = $reports + 1; } } } } $this->current_user_votes = $votes; $this->current_user_reports = $reports; if (votes_per_ip > 0 && $user == 0) { $ac_vote_from_IP = $this->votes_from_ip(); if ($ac_vote_from_IP <= 1) { $ac_vote_from_IP = 0; } $ac_report_from_IP = $this->reports_from_ip(); if ($ac_report_from_IP <= 1) { $ac_report_from_IP = 0; } $this->vote_from_this_ip = $ac_vote_from_IP; $this->report_from_this_ip = $ac_report_from_IP; } }
function show($fetch = false) { global $main_smarty, $db, $cached_links, $current_user; include_once mnminclude . 'search.php'; $search = new Search(); $search->orderBy = $this->orderBy; $search->pagesize = $this->pagesize; $search->filterToStatus = $this->filterToStatus; $search->filterToTimeFrame = $this->filterToTimeFrame; $search->category = $this->category; $search->doSearch(); $linksum_sql = $search->sql; $link = new Link(); $links = $db->get_col($linksum_sql); $the_results = $links; if ($the_results) { // find out if the logged in user voted / reported each of // the stories that the search found and cache the results require_once mnminclude . 'votes.php'; $vote = new Vote(); $vote->type = 'links'; $vote->user = $current_user->user_id; $vote->link = $the_results; $results = $vote->user_list_all_votes(); $vote = ''; $results = ''; // we don't actually need the results // we're just calling this to cache the results // so when we foreach the links we don't have to // run 1 extra query for each story to determine // current user votes // setup the link cache $i = 0; // if this query changes also change it in the read() function in /libs/link.php $sql = "SELECT " . table_links . ".* FROM " . table_links . " WHERE "; foreach ($the_results as $link_id) { // first make sure we don't already have it cached if (!isset($cached_links[$link_id])) { if ($i > 0) { $sql .= ' OR '; } $sql .= " link_id = {$link_id} "; $i = $i + 1; } } // if $i = 0 then all the links are already cached // so don't touch the db // if $i > 0 then there is at least 1 link to get // so get the SQL and add results to the cache if ($i > 0) { $results = $db->get_results($sql); // add the results to the cache foreach ($results as $row) { $cached_links[$row->link_id] = $row; } } // end link cache setup } $ssLinks = ''; if ($links) { foreach ($links as $link_id) { $link->id = $link_id; $link->check_saved = false; $link->get_author_info = false; $link->check_friends = false; $link->read(); if (is_numeric($this->TitleLengthLimit) && strlen($link->title) > $this->TitleLengthLimit) { $link->title = utf8_substr($link->title, 0, $this->TitleLengthLimit) . '...'; } $main_smarty = $link->fill_smarty($main_smarty); $ssLinks .= $main_smarty->fetch($this->template); } } if ($fetch == true) { return $ssLinks; } else { echo $ssLinks; } }