public static function add($user, $type, $message) { //$timestamp = date('c'); $timestamp = time(); $q = "INSERT INTO ocs_activity (type,person,timestamp,message) VALUES ({$type}, {$user}, {$timestamp}, \"{$message}\")"; $r = EDatabase::q($q); }
public function remove($content) { $person = OCSUser::id(); EDatabase::q("DELETE FROM ocs_fan WHERE person={$person} and content={$content}"); //part needed for activity $con = new OCSContent(); $con->load($content); OCSActivity::add(OCSUser::id(), 10, OCSUser::login() . " is no longer fan of " . $con->name); }
public static function cancel_friendship($touser) { $idfrom = OCSUser::id(); $info = OCSUser::server_get_user_info($touser); $id = $info[0]["id"]; //creating new table object $ocs_friendinvitation = new EModel("ocs_friendship"); EDatabase::q("DELETE FROM ocs_friendship WHERE (id1={$idfrom} AND id2={$id}) OR (id2={$idfrom} AND id1={$id}) LIMIT 2"); }
public static function reset_ocs_database() { EDatabase::q("DROP TABLE IF EXISTS `ocs_apitraffic`;"); EDatabase::q("DROP TABLE IF EXISTS `ocs_comment`;"); EDatabase::q("DROP TABLE IF EXISTS `ocs_content`;"); EDatabase::q("DROP TABLE IF EXISTS `ocs_fan`;"); EDatabase::q("DROP TABLE IF EXISTS `ocs_person`;"); EDatabase::q("DROP TABLE IF EXISTS `ocs_activity`;"); EDatabase::q("DROP TABLE IF EXISTS `ocs_friendship`;"); EDatabase::q("DROP TABLE IF EXISTS `ocs_friendinvitation`;"); OCSTest::install_ocs_database(); }
public function delete() { //EDatabase::q("DELETE FROM ocs_content WHERE id=".$this->id." LIMIT 1"); EDatabase::q("DELETE FROM ocs_content WHERE id=" . $this->id . " LIMIT 1"); EDatabase::q("DELETE FROM ocs_comment WHERE content=" . $this->id); EFileSystem::rmdir("content/" . $this->id); }
public function ocs_activity_list($user, $page = 1, $pagesize = 10) { if (empty($page)) { $page = 1; } //setting dynamic page size $page = ($page - 1) * $pagesize; $id = OCSUser::id(); $q = "SELECT a.id, a.type, a.person, a.timestamp, a.message, p.login, p.firstname, p.lastname, p.email FROM ocs_activity AS a JOIN ocs_person AS p ON a.person=p.id WHERE a.person IN (SELECT f.id2 FROM ocs_friendship AS f JOIN ocs_person AS p on (f.id1 = p.id) WHERE p.login='******') LIMIT {$page},{$pagesize};"; $r = EDatabase::q($q); $result = array(); $i = 0; while ($row = mysqli_fetch_assoc($r)) { $result[$i]["id"] = $row["id"]; $result[$i]["firstname"] = $row["firstname"]; $result[$i]["lastname"] = $row["lastname"]; $result[$i]["personid"] = $row["login"]; $result[$i]["timestamp"] = $row["timestamp"]; $result[$i]["type"] = $row["type"]; $result[$i]["message"] = $row["message"]; $i += 1; } return $result; }
/** * cleans up the api traffic limit database table. * this function should be call by a cronjob every 15 minutes */ public function cleanuptrafficlimit() { EDatabase::q('truncate ocs_apitraffic'); }
public function verify($mail) { $q = "UPDATE users SET verified='yes' WHERE mail=\"" . $mail . "\" LIMIT 1"; $r = EDatabase::q($q); }
public function votedown($id) { $q = "UPDATE posts SET down = down+1 WHERE id = " . $id . " LIMIT 1"; $r = EDatabase::q($q); }
public static function register($nick, $pass, $group) { EDatabase::q("INSERT INTO ocs_person (login, password, tgroup) VALUES ('{$nick}', '{$pass}', '{$group}')"); }
public function update($where = "", $allowed_fields = array()) { if (!$this->is_ready_test()) { return; } //recupero le informazioni di where if (!empty($where)) { $where = " WHERE " . $where . " "; } //recupero le informazioni automaticamente if (!empty($allowed_fields)) { foreach ($this->fields as $field) { if ($field['field'] != "id") { if (EHeaderDataParser::exists_post($field['field']) and in_array($field['field'], $allowed_fields)) { $entries[] = array("field" => $field['field'], "value" => EHeaderDataParser::db_post($field['field']), "type" => $field['type']); } } } } else { foreach ($this->fields as $field) { if ($field['field'] != "id") { if (EHeaderDataParser::exists_post($field['field'])) { $entries[] = array("field" => $field['field'], "value" => EHeaderDataParser::db_post($field['field']), "type" => $field['type']); } } } } //costruisco la query ed eseguo se ho le informazioni in entries if (!empty($entries)) { $sql = "UPDATE " . $this->table . " SET "; foreach ($entries as $entry) { $sql = $sql . $entry['field'] . "="; if ($entry['type'] == "int") { if (!is_numeric($entry['value'])) { //data type error echo "<span style=\"font-family:Arial,sans-serif\">Warning! GFX3 <span style=\"color:red\">EData Object Error</span>: wrong data passed for <i><big>`" . $field['field'] . "`</big></i> with type `INT`! freezing...</span><br>"; die; } $sql = $sql . $entry['value'] . ","; } else { $sql = $sql . "'" . $entry['value'] . "',"; } } $sql = rtrim($sql, ",") . " {$where}"; if ($this->noquery == false) { EDatabase::q($sql); } else { echo $sql; } } else { //ELog::warning("EData->update called with empty entries"); } }
public function set_score($score) { //acquiring data $oldmedia = $this->score; $newscore = $score; $oldvotes = $this->votes; $newvotes = $this->votes + 1; //calculating new media $newmedia = ($oldmedia * $oldvotes + $newscore) / $newvotes; //setting new infos to local memory object $this->score = $newmedia; $this->votes = $newvotes; //updating db EDatabase::q("UPDATE ocs_comment SET score=" . $this->score . ", votes=" . $this->votes . " WHERE id=" . $this->id . " LIMIT 1"); }
public static function table_exists($table) { $r = EDatabase::q("SHOW TABLES LIKE '{$table}'"); if (EDatabase::$opened) { $row = mysqli_fetch_row($r); if (empty($row)) { return false; } else { return true; } } else { ELog::error("Database not opened!"); return false; } }
public static function server_register($login, $passwd, $firstname, $lastname, $email) { //autoload if necessary if (is_null(OCSUser::$persons)) { OCSUser::server_load(); } $login = EDatabase::safe($login); $passwd = EDatabase::safe($passwd); $firstname = EDatabase::safe($firstname); $lastname = EDatabase::safe($lastname); $email = EDatabase::safe($email); EDatabase::q("INSERT INTO ocs_person (login,password,firstname,lastname,email) VALUES ('{$login}','{$passwd}','{$firstname}','{$lastname}','{$email}')"); }