function do_search($terms) { global $mysqli; $terms = $this->search_split_terms($terms); $terms_db = $this->search_db_escape_terms($terms); $terms_rx = $this->search_rx_escape_terms($terms); $parts = array(); foreach ($terms_db as $term_db) { $parts[] = "content RLIKE '{$term_db}'"; } $parts = implode(' AND ', $parts); $sql = "SELECT id FROM items WHERE {$parts}"; $query = mysqli_query($mysqli, $sql); $items = array(); while ($query && ($result = mysqli_fetch_assoc($query))) { $item = Item::get_by_id($result['id']); $item->content = process_content($item->content); $item->score = 0; foreach ($terms_rx as $term_rx) { $item->score += preg_match_all("/{$term_rx}/i", $item->content, $null); } $items[] = $item; } if (count($items) > 1) { uasort($items, array($this, 'search_sort_results')); } return $items; }
public static function list_all($limit = 10, $offset = 0) { global $mysqli; $config = new Config(); $sql = "SELECT `id` FROM `{$config->database->{$config->site_identifier}->prefix}items` ORDER BY `id` DESC"; // Limit string $limit = sanitize_input($limit); $sql .= " LIMIT {$limit}"; // Offset string $offset = sanitize_input($offset); $sql .= " OFFSET {$offset}"; $query = mysqli_query($mysqli, $sql); // Loop through item ids, fetching objects $items = array(); if ($query != false) { while ($query && ($result = mysqli_fetch_assoc($query))) { $items[] = Item::get_by_id($result['id']); } } return $items; }
function json($item_id) { $item = Item::get_by_id($item_id); $this->json = $item->likes; $this->loadView('pages/json', NULL, 'none'); }
public function test_change_state_to_waiting_for_done_undone_after_get() { $this->item->create(time() + 1, time() + 1800, "این تست است", ITEM_STATE_DONE, 3)->save($this->user, $this->task); sleep(2); $tempItem = new Item(); $tempItem->get_by_id($this->item->getId()); $this->_assert_equals($tempItem->getFeedback(), null); $this->_assert_equals($tempItem->getState(), ITEM_STATE_WAITING_FOR_DONE_UNDONE); }
public function list_feed($limit = 10, $offset = 0) { global $mysqli; $config = new Config(); // Start by adding the viewer to the query string $friends_string = "`user_id` = {$this->id}"; $friends = $this->friends(); // Loop through friends adding them to the query string foreach ($friends as $friend) { $friends_string .= " OR `user_id` = {$friend['friend_user_id']}"; } $sql = "SELECT `id` FROM `{$config->database->{$config->site_identifier}->prefix}items` WHERE {$friends_string} ORDER BY `id` DESC"; // Limit string $limit = sanitize_input($limit); $sql .= " LIMIT {$limit}"; // Offset string $offset = sanitize_input($offset); $sql .= " OFFSET {$offset}"; $query = mysqli_query($mysqli, $sql); // Loop through item ids, fetching objects $items = array(); while ($query && ($result = mysqli_fetch_assoc($query))) { $items[] = Item::get_by_id($result['id']); } return $items; }
function remove($item_id) { $item = Item::get_by_id($item_id); if ($_SESSION['user_id'] == $item->user->id && $item != NULL) { // Delete item $item->remove(); // Log item deletion if (isset($this->plugins->log)) { $this->plugins->log->add($_SESSION['user_id'], 'item', $item->id, 'remove'); } // Delete comments if (is_array($item->comments)) { foreach ($item->comments as $comment) { // Remove comment $id = $comment->remove(); // Log comment removal if (isset($this->plugins->log)) { $this->plugins->log->add($_SESSION['user_id'], 'comment', $id, 'remove'); } } } // Delete likes if (is_array($item->comments)) { foreach ($item->likes as $like) { // Remove like $id = $like->remove(); // Log like removal if (isset($this->plugins->log)) { $this->plugins->log->add($_SESSION['user_id'], 'like', $like->id, 'remove'); } } } // Set message Application::flash('success', ucfirst($this->config->items->name) . ' removed!'); // Return from whence you came header('Location: ' . $_SERVER['HTTP_REFERER']); exit; } else { // Naughtiness = expulsion! // Go forth header('Location: ' . $this->config->url); exit; } }