Beispiel #1
0
 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);
 }
Beispiel #2
0
 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");
 }
Beispiel #3
0
 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);
 }
Beispiel #4
0
 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();
 }
Beispiel #5
0
 public function set_data($data)
 {
     // assuring those are not evil data to be used as SQL injections
     EDatabase::safe($data);
     //data validations
     if (!isset($data['type'])) {
         ELog::error("OCSContent: type not defined. Mandatory field.");
     } else {
         $this->type = $data['type'];
     }
     if (!isset($data['name'])) {
         ELog::error("OCSContent: name not defined. Mandatory field.");
     } else {
         $this->name = $data['name'];
     }
     if (!isset($data['personid'])) {
         ELog::error("OCSContent: personid not defined. Mandatory field.");
     } else {
         $this->personid = $data['personid'];
     }
     if (!isset($data['downloadname1'])) {
         $this->downloadname1 = "";
     } else {
         $this->downloadname1 = $data['downloadname1'];
     }
     if (!isset($data['downloadlink1'])) {
         $this->downloadlink1 = "";
     } else {
         $this->downloadlink1 = $data['downloadlink1'];
     }
     if (!isset($data['description'])) {
         $this->description = "";
     } else {
         $this->description = $data['description'];
     }
     if (!isset($data['summary'])) {
         $this->summary = "";
     } else {
         $this->summary = $data['summary'];
     }
     if (!isset($data['version'])) {
         $this->version = "";
     } else {
         $this->version = $data['version'];
     }
     if (!isset($data['changelog'])) {
         $this->changelog = "";
     } else {
         $this->changelog = $data['changelog'];
     }
     if (!isset($data['preview1'])) {
         $this->preview1 = "";
     } else {
         $this->preview1 = $data['preview1'];
     }
     if (!isset($data['preview2'])) {
         $this->preview2 = "";
     } else {
         $this->preview2 = $data['preview2'];
     }
     if (!isset($data['preview3'])) {
         $this->preview3 = "";
     } else {
         $this->preview3 = $data['preview3'];
     }
     if (!isset($data['license'])) {
         $this->license = "";
     } else {
         $this->license = $data['license'];
     }
 }
 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;
 }
Beispiel #7
0
 /**
  * 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');
 }
Beispiel #8
0
 public function verify($mail)
 {
     $q = "UPDATE users SET verified='yes' WHERE mail=\"" . $mail . "\" LIMIT 1";
     $r = EDatabase::q($q);
 }
Beispiel #9
0
 public static function unload()
 {
     if (EDatabase::$opened == true) {
         // TODO: strange behaviour under root. Inspect.
         // mysql_close(EDatabase::db_link);
         EDatabase::$db_link = 0;
         EDatabase::$opened = false;
     } else {
         if (EDatabase::$debug == false) {
             ELog::error("TRT GFX ISSUE: unable to close mysql session because no one was already opened.");
         }
     }
 }
Beispiel #10
0
<?php

include_once "../gfx3/lib.php";
$main = new EMain();
$temp = new EStructure();
$temp->code();
echo "<p style=\"color:green;\">Working!</p>";
$temp->insert("corelibs");
$temp->code();
$db = new EDatabase();
if ($db->status() == 0) {
    echo "<p style=\"color:green;\">Working!</p>";
} elseif ($db->status() == 1) {
    echo "<p style=\"color:red;\">No database found!</p>";
} else {
    echo "<p style=\"color:red;\">Connection refused!</p>";
}
$temp->insert("database");
$temp->code();
echo "<p style=\"color:green;\">Working!</p>";
$temp->insert("templates");
Beispiel #11
0
 public function __destruct()
 {
     EDatabase::unload();
 }
Beispiel #12
0
 public static function register($nick, $pass, $group)
 {
     EDatabase::q("INSERT INTO ocs_person (login, password, tgroup) VALUES ('{$nick}', '{$pass}', '{$group}')");
 }
Beispiel #13
0
 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");
     }
 }
Beispiel #14
0
 public function step1($args)
 {
     $working = false;
     $name = EHeaderDataParser::post('name');
     $host = EHeaderDataParser::post('host');
     $user = EHeaderDataParser::post('user');
     $pass = EHeaderDataParser::post('password');
     $pass2 = EHeaderDataParser::post('password2');
     $notification = '';
     $database_path = ELoader::$prev_path . '/config/database.conf.php';
     $cf = new EConfigFile();
     $cf->set_abs_file($database_path);
     if (empty($name) and !empty($cf->get('name'))) {
         $name = $cf->get('name');
     }
     if (empty($host) and !empty($cf->get('host'))) {
         $host = $cf->get('host');
     }
     if (empty($user) and !empty($cf->get('user'))) {
         $user = $cf->get('user');
     }
     if (empty($pass) and !empty($cf->get('password'))) {
         $pass = $pass2 = $cf->get('password');
     }
     if (!empty($name) and !empty($user) and !empty($host) and !empty($pass) and !empty($pass2)) {
         if ($pass != $pass2) {
             $this->_error('Warning! Your passwords didn\'t match! Please reinsert them!');
         } else {
             $cf->set('name', $name);
             $cf->set('user', $user);
             $cf->set('host', $host);
             $cf->set('password', $pass);
             EDatabase::set_db_info($name, $host, $user, $pass);
             EUtility::hide_output();
             // hiding output as mysqli functions are surely outputting something
             if (!EDatabase::open_session()) {
                 EUtility::show_output();
                 $notification = $this->_error('Couldn\'t open connection to database! Please check config!');
             } else {
                 OCSTest::install_ocs_database();
                 //execute soft install
                 $out = EUtility::show_output();
                 if (!empty($out)) {
                     $notification = $this->_error('Something went wrong with install phase! Please check config!');
                 } else {
                     $notification = $this->_notify('We can connect to database! Database is installed and configuration saved!');
                     $working = true;
                     $cf->save();
                 }
             }
         }
     }
     $data = array();
     $data['name'] = $name;
     $data['user'] = $user;
     $data['host'] = $host;
     $data['pass'] = $pass;
     $data['pass2'] = $pass2;
     $data['working'] = $working;
     $data['notification'] = $notification;
     EStructure::view('wizard/step1', $data);
 }
Beispiel #15
0
 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 db_post($key)
 {
     if (isset(EHeaderDataParser::$posts[$key])) {
         if (EHeaderDataParser::$quotes) {
             return EHeaderDataParser::$posts[$key];
         } else {
             return EDatabase::safe(EHeaderDataParser::$posts[$key]);
         }
     } else {
         return false;
     }
 }
Beispiel #17
0
 public function votedown($id)
 {
     $q = "UPDATE posts SET down = down+1 WHERE id = " . $id . " LIMIT 1";
     $r = EDatabase::q($q);
 }
Beispiel #18
0
 public static function server_countusersbyemail($email)
 {
     //autoload if necessary
     if (is_null(OCSUser::$persons)) {
         OCSUser::server_load();
     }
     $email = EDatabase::safe($email);
     $r = OCSUser::$persons->count("login", "email='{$email}'");
     return $r;
 }