public static function getDataByHandle($handle, $columns = "uni_id") { if ($uniID = self::getIDByHandle($handle)) { return Database::selectOne("SELECT " . Sanitize::variable($columns, " ,-*`") . " FROM users WHERE uni_id=? LIMIT 1", array($uniID)); } return array(); }
/** * Counts photos per QUERY, and privacy restrictions * * @access public * @return int */ public function getPhotoCount() { $condition = $this->whereRestriction; if (!$this->showPrivatePhotos) { $condition .= 'AND status = 0'; } return Database::selectOne('ratings', 'COUNT(*)', $condition, null, 'LEFT JOIN photos ON ratings.id = photos.id', null); }
/** * Returns information about the aggregate of photos on the site * * @access public * @return array */ public function getCounts() { $this->counts['albums'] = Database::selectOne('albums', 'COUNT(*)'); $this->counts['topics'] = Database::selectOne('albums', 'COUNT(DISTINCT topic)'); $this->counts['photos'] = Database::selectOne('photos', 'COUNT(*)'); $this->counts['pixels'] = Database::selectOne('photos', 'SUM(width*height)'); $this->counts['albumhits'] = Database::selectOne('albums', 'SUM(hits)'); $this->counts['photohits'] = Database::selectOne('photos', 'SUM(hits)'); $this->counts['maxphotohits'] = Database::selectOne('photos', 'MAX(hits)'); $this->counts['maxalbumhits'] = Database::selectOne('albums', 'MAX(hits)'); $this->counts['daysonline'] = floor((time() - strtotime(Preferences::valueForModuleWithKey('CameraLife', 'sitedate'))) / 86400); return $this->counts; }
public static function load() { // Make sure the database is loaded if (!Database::$database) { return false; } // If you are logged in, run a "remember me" check if (!isset($_SESSION['uni_id'])) { return false; } // Set your session ID, which corresponds to your database user ID self::$id = $_SESSION['uni_id']; // Prepare the columns to receive if (!self::$getColumns) { self::$getColumns = "uni_id, role, clearance, handle, display_name, date_joined"; } // Retrieve the active user from the database - the user doesn't exist in the database, register them if (!(self::$vals = Database::selectOne("SELECT " . self::$getColumns . " FROM users WHERE uni_id=? LIMIT 1", array(self::$id)))) { // Make sure appropriate registration values are sent if (!isset($_SESSION['uni_id']) or !isset($_SESSION['user']['handle']) or !isset($_SESSION['user']['display_name'])) { return false; } // Set timezone to empty if not sent if (!isset($_SESSION['user']['timezone'])) { $_SESSION['user']['timezone'] = ""; } // Register User (if necessary) if (!Register::user($_SESSION['user']['uni_id'], $_SESSION['user']['handle'], $_SESSION['user']['display_name'], $_SESSION['user']['timezone'])) { return false; } // Try to load the user again (after registration) if (!(self::$vals = Database::selectOne("SELECT " . self::$getColumns . " FROM users WHERE uni_id=? LIMIT 1", array(self::$id)))) { return false; } } // Save your Clearance Level self::$clearance = (int) self::$vals['clearance']; // Handle Banned Accounts if (self::$clearance <= -3) { header("Location: /banned"); exit; } // Occasionally log activity (handles auro allotment) if (mt_rand(0, 25) == 22) { self::logActivity(); } return true; }
/** * @covers DataBase::delete * @covers Database::select * @covers Database::selectOne */ public function testDelete() { $this->db->select('name', 'test'); $this->assertEquals(3, $this->db->rowCount()); $this->assertEquals(1, $this->db->delete('test', array('id' => 1))); $this->assertEmpty($this->db->selectOne('name', 'test', array('id' => 1))); $this->db->select('name', 'test'); $this->assertEquals(2, $this->db->rowCount()); $result = $this->db->select('*', 'test'); $this->assertEquals(0, $this->db->delete('test', array('id' => 0))); $this->assertFalse(LoggerApp::hasError(), LoggerApp::getLastError()); $this->assertEquals(0, $this->db->delete('testinvalid', array('xyz' => 1))); $this->assertTrue(LoggerApp::hasError(), 'Não gerou o erro esperado'); //Update without where $this->assertEquals(0, $this->db->delete('test', array())); }
public static function get($key) { // Garbage collection if (mt_rand(0, 2000) == 1022) { Cache_Memory::clearExpired(); } // Get the Cached Value if (!($keyData = Database::selectOne("SELECT value, expire FROM cache WHERE `key`=? LIMIT 1", array($key)))) { return false; } // If the Cached Value is expired, delete it and return false if ((int) $keyData['expire'] <= time()) { self::delete($key); return false; } return isset($keyData['value']) ? $keyData['value'] : false; }
/** * Counts albums with the topic named QUERY * * @access public * @return int */ public function getAlbumCount() { return Database::selectOne('albums', 'COUNT(*)', 'topic = :topic', null, null, array('topic' => $this->query)); }
/** * Counts folders per QUERY, and privacy restrictions * * @access public * @return int */ public function getFolderCount() { $conditions = array(); $binds = array(); foreach (preg_split('/\\s+/', $this->query) as $i => $queryPart) { $conditions[$i] = "(path LIKE :{$i})"; $binds[$i] = '%' . $queryPart . '%'; } if (!$this->showPrivatePhotos) { $conditions[] = 'status = 0'; } return Database::selectOne('photos', 'COUNT(DISTINCT path)', implode(' AND ', $conditions), null, null, $binds); }
public static function getColumnData($table, $column) { return Database::selectOne("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ?;", array(Database::$databaseName, $table, $column)); }
public function getLikeCount() { $ratings = Database::selectOne('ratings', 'COUNT(rating)', 'id=' . $this->get('id') . ' AND rating > 0'); return $ratings; }
public static function exists($lookupID) { return (bool) Database::selectOne("SELECT " . static::$lookupKey . " FROM `" . static::$table . "` WHERE `" . static::$lookupKey . "` = ? LIMIT 1", array($lookupID)); }
/* -------------------------------------------- ------ About the content-track script ------ -------------------------------------------- This script allows the user to set content tracking values, such as to vote on content entries (e.g. "Boost"). */ // Make sure the user is logged in and has a valid ID if (!Me::$id) { exit; } // Make sure the right information is gathered if (!isset($_POST['contentID']) or !isset($_POST['type'])) { exit; } // Make sure the content exists if ($contentData = Database::selectOne("SELECT id, uni_id, url, url_slug FROM content_entries WHERE id=? LIMIT 1", array((int) $_POST['contentID']))) { // Prepare Values $contentID = (int) $contentData['id']; $authorID = (int) $contentData['uni_id']; // If the entry was aggregated from another site if ($contentData['url']) { // Prepare the Packet $packet = array("uni_id" => Me::$id, "url_slug" => $contentData['url_slug'], "type" => "boost"); if (isset($_POST['voteType'])) { $packet["voteType"] = (int) $_POST['voteType']; } $articleSite = Database::selectValue("SELECT site_handle FROM network_data WHERE site_url=?", array($contentData['url'])); // Run the API $response = API_Connect::to($articleSite, "TrackerAPI", $packet); echo json_encode($response); exit;
/** * Counts folders per QUERY, and privacy restrictions * * @access public * @return int */ public function getFolderCount() { $conditions = array(); $binds = array(); $conditions[0] = "(path LIKE :1 AND path NOT LIKE :2)"; $binds[1] = rtrim($this->path, '/') . '/_%'; $binds[2] = rtrim($this->path, '/') . '/_%/%'; if (!$this->showPrivatePhotos) { $conditions[] = 'status = 0'; } return Database::selectOne('photos', 'COUNT(DISTINCT path)', implode(' AND ', $conditions), null, null, $binds); }
<?php // Form Submission if (Form::submitted("add-user-uni6")) { // Check if all of the input you sent is valid: Validate::variable("Handle", $_POST['handle'], 1, 22); Validate::text("Display Name", $_POST['display_name'], 3, 22); Validate::password($_POST['password']); Validate::email($_POST['email']); // Check if the handle has already been taken if (AppAccount::handleTaken($_POST['handle'])) { Alert::error("Handle Taken", "That handle has already been taken", 1); } if (Database::selectOne("SELECT email FROM users WHERE email=? LIMIT 1", array($_POST['email']))) { Alert::error("Email", "That email already exists.", 1); } // Final Validation Test if (Validate::pass()) { Database::startTransaction(); $uniID = 0; // Check if the account already exists if ($checkAuth = Database::selectValue("SELECT uni_id FROM users WHERE handle=? LIMIT 1", array($_POST['handle']))) { $uniID = (int) $checkAuth; } else { if ($regSuccess = Database::query("INSERT INTO users (handle, display_name, email, password, date_joined, auth_token, verified) VALUES (?, ?, ?, ?, ?, ?, ?)", array($_POST['handle'], $_POST['display_name'], $_POST['email'], Security_HashPassword::set($_POST['password']), time(), Security_Hash::random(22, 72), 1))) { $uniID = (int) Database::$lastID; if (isset($_POST['send_email'])) { // Email a verification letter AppVerification::sendVerification($uniID); Alert::success("Email Sent", "The account was created successfully! A verification email has been sent to " . $_POST['email'] . "!"); } else {