public static function get($name = "unique")
 {
     // Get the current value set
     if (!($current = (int) Database::selectValue("SELECT value FROM site_variables WHERE key_group=? AND key_name=? LIMIT 1", array("uniqueIDs", $name)))) {
         return 0;
     }
     // Update the counter for next time
     if (!Database::query("UPDATE site_variables SET value=? WHERE key_group=? AND key_name=? LIMIT 1", array($current + 1, "uniqueIDs", $name))) {
         return 0;
     }
     return $current;
 }
Пример #2
0
 public static function getSharedKey($domain)
 {
     return Database::selectValue("SELECT shared_key FROM authentication WHERE domain=? LIMIT 1", array($domain));
 }
Пример #3
0
 public static function exists($key)
 {
     return Database::selectValue("SELECT `key` FROM cache WHERE `key`=? LIMIT 1", array($key));
 }
Пример #4
0
 public static function exists($entityID)
 {
     $class = get_called_class();
     return (bool) Database::selectValue("SELECT id FROM `entity_" . $class . "` WHERE id=? LIMIT 1", [$entityID]);
 }
Пример #5
0
 public static function load($keyGroup, $keyName = "", $table = "")
 {
     $table = $table == "" ? "site_variables" : Sanitize::variable($table);
     // Retrieve the whole key group
     if ($keyName == "") {
         $keyList = array();
         $getValues = Database::selectMultiple("SELECT key_name, value FROM " . $table . " WHERE key_group=?", array($keyGroup));
         foreach ($getValues as $value) {
             $keyList[$value['key_name']] = json_decode($value['value']);
         }
         return $keyList;
     }
     // Retrieve a specific key
     if ($getValue = Database::selectValue("SELECT value FROM " . $table . " WHERE key_group=? AND key_name=? LIMIT 1", array($keyGroup, $keyName))) {
         return json_decode($getValue);
     }
     return false;
 }
Пример #6
0
 public static function columnExists($table, $column)
 {
     return (bool) Database::selectValue("SELECT COUNT(*) as doesExist FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ? LIMIT 1;", array(Database::$databaseName, $table, $column));
 }
Пример #7
0
 public function checkPassword($username, $password)
 {
     $query = 'SELECT EXISTS(SELECT 1 FROM interface_users WHERE interface_users.login = ? AND interface_users.password = ?)';
     return Database::selectValue($query, array($username, hash('sha256', $password)));
 }
Пример #8
0
 public static function getIDByHandle($handle)
 {
     return (int) Database::selectValue("SELECT uni_id FROM users_handles WHERE handle=? LIMIT 1", array($handle));
 }
Пример #9
0
 public static function search($searchArgs = ['_GET'], &$rowCount = 0, $pullChildren = false)
 {
     // If no search arguments are provided, default to using $_GET
     if ($searchArgs == ['_GET']) {
         $searchArgs = $_GET;
     }
     // Prepare values that handle reserved keywords
     list($limit, $offset, $orderBy, $columns) = static::extractReservedKeywords($searchArgs);
     // Load the conversion
     list($whereStr, $sqlArray) = static::convertArgsToWhereSQL($searchArgs);
     // If we're retrieving multiple columns, we need to delimit them
     if (is_array($columns)) {
         $columns = implode(", ", $columns);
     }
     // Prepare Ordering
     $orderStr = "";
     foreach ($orderBy as $order) {
         $orderStr .= ($orderStr ? ", " : "") . $order[0] . " " . $order[1];
     }
     $orderStr = $orderStr ? " ORDER BY " . $orderStr : "";
     // Prepare the Limit / Pagination
     $limitStr = $limit ? " LIMIT " . ($offset + 0) . ", " . ($limit + 0) : "";
     // Get the number of rows that were possible to retrieve (for pagination purposes)
     $rowCount = Database::selectValue("SELECT COUNT(*) as totalNum FROM `" . static::$table . "`" . ($whereStr ? " WHERE " . $whereStr : ""), $sqlArray);
     // Pull the rows located by the search
     $results = Database::selectMultiple("SELECT " . $columns . " FROM `" . static::$table . "`" . ($whereStr ? " WHERE " . $whereStr : "") . $orderStr . $limitStr, $sqlArray);
     // For searches that are not traversing the tree, we can end here.
     // Also, if there were no results, return now before trying to locate children classes.
     if ($pullChildren == false or !$results) {
         return $results;
     }
     // Now for the complicated work....
     /*
     	We have an important mapping behavior to consider:
     	
     	The lookup ID's of the child results are important for mapping child records BACK to their parent records.
     	Therefore, we need to map the child records to the result ID's of the parent using the lookup key
     	that was used to call them.
     	
     	For example:
     		The first RESULT ID is always equal to 0. The LOOKUP KEY is "id" and it matched a LOOKUP ID of "7".
     		By mapping LOOKUP ID of 7 to RESULT ID of 0, we can save the records properly.
     */
     // Extract the lookup ID's from the results
     // This is essentially doing array_map()'s work, but we need to pass the lookup key, which it doesn't allow.
     $mapLookupIDToResultID = [];
     foreach ($results as $key => $res) {
         $mapLookupIDToResultID[$res[static::$lookupKey]] = $key;
     }
     // Now that we have the IDs that were tracked, we can load them into the relationships.
     // Find the relationship classes and include them with the traversal
     foreach (static::$schema['relationships'] as $relColumn => $relatedClass) {
         // Get insight into the type of class that we're joining
         $relationshipType = get_parent_class($relatedClass);
         if ($relationshipType == "Model_Join") {
             $joinedClass = $relatedClass::$relatedClass;
             $canHaveMany = true;
             // Get the child results through the join table
             $childResults = Database::selectMultiple("SELECT t1." . $relatedClass::$lookupKey . " as _t1_lookupID, t2.* FROM " . $relatedClass::$table . " t1 INNER JOIN " . $joinedClass::$table . " t2 ON t1." . $relatedClass::$relatedKey . "=t2." . $joinedClass::$lookupKey . " WHERE t1." . $relatedClass::$lookupKey . " IN (?" . str_repeat(', ?', count($mapLookupIDToResultID) - 1) . ")", array_keys($mapLookupIDToResultID));
             // We need to set the keys in the child results to match the ID's of the parent results
             // so that we know how they relate.
             $newChildResults = [];
             foreach ($childResults as $row) {
                 // We need to remove the lookup ID from the list, but preserve the value
                 $recordID = $mapLookupIDToResultID[$row['_t1_lookupID']];
                 unset($row['_t1_lookupID']);
                 $newChildResults[$recordID][] = $row;
             }
             // Now we load the child results into the parent records
             foreach ($newChildResults as $resultID => $row) {
                 $results[$resultID][$relColumn] = $row;
             }
         } else {
             if ($relationshipType == "Model_Child") {
                 // Get the child records
                 $childResults = Database::selectMultiple("SELECT t1.* FROM " . $relatedClass::$table . " t1 WHERE " . $relatedClass::$lookupKey . " IN (?" . str_repeat(', ?', count($mapLookupIDToResultID) - 1) . ")", array_keys($mapLookupIDToResultID));
                 // We need to set the keys in the child results to match the ID's of the parent results
                 // so that we know how they relate.
                 $newChildResults = [];
                 foreach ($childResults as $row) {
                     $newChildResults[$mapLookupIDToResultID[$row[$relatedClass::$lookupKey]]][] = $row;
                 }
                 // Now we load the child results into the parent records
                 // However, we first check if there can be multiple children rows - since this
                 // will affect how we append each row.
                 if ($relatedClass::$canHaveMany == true) {
                     foreach ($newChildResults as $resultID => $row) {
                         $results[$resultID][$relColumn][] = $row;
                     }
                 } else {
                     foreach ($newChildResults as $resultID => $row) {
                         $results[$resultID][$relColumn] = $row;
                     }
                 }
             }
         }
     }
     return $results;
 }
Пример #10
0
     $response = API_Connect::to($articleSite, "TrackerAPI", $packet);
     echo json_encode($response);
     exit;
 }
 // Run the Content Track Handler
 $contentTrack = new ContentTrack($contentID, Me::$id);
 switch ($_POST['type']) {
     case "boost":
         $contentTrack->voteUp();
         break;
     case "nooch":
         $success = false;
         $noochCount = 0;
         if ($authorID != Me::$id) {
             // Check if the user has already triple nooched
             $noochCount = Database::selectValue("SELECT nooch FROM content_tracking_users WHERE uni_id=? AND content_id=? LIMIT 1", array(Me::$id, $contentID));
             if ($noochCount !== false and $noochCount < 3) {
                 if ($success = Credits::chargeInstant(Me::$id, 0.15, "Assigned a Nooch")) {
                     $contentTrack->nooch();
                     $noochCount++;
                 }
             }
         }
         echo json_encode(array("content_id" => $contentID, "nooch_count" => (int) $noochCount, "nooch_success" => $success));
         exit;
     case "tip":
         if (!isset($_POST['amount'])) {
             echo 'false';
             exit;
         }
         // Prepare Values
Пример #11
0
 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 {
                 Alert::success("User Added", "The account was created successfully!");
             }
         }
     }
     // Create the account
     if ($uniID) {