/** * Used to set config absolute file path. * Leave constructor empty and use this. */ public function set_abs_file($filename) { $this->name = $filename; if (!file_exists($this->name)) { ELog::error('Config file not existent: ' . $this->name); } else { $this->data = EConfig::parse_file($this->name); } }
public function set_table_search($tbl) { //assuring $data is safe to be executed on a db query EDatabase::safe($data); //setting internal attribute if (EDatabase::table_exists($tbl)) { $this->table = $tbl; $this->datatable = new EData($this->table); } else { ELog::error("{$tbl} does not exists on database."); } }
public function make_thumbnail($from, $to, $maxwidth, $maxheight) { $ext = EFileSystem::get_file_extension($from); if (!(list($width, $height, $type, $attr) = getimagesize($from))) { ELog::error("{$from} |"); } if ($width > $height) { $x = $width / $maxwidth; $fwidth = floor($width / $x); $fheight = floor($height / $x); } if ($width < $height) { $x = $height / $maxheight; $fheight = floor($height / $x); $fwidth = floor($width / $x); } if ($width == $height) { if ($maxwidth > $maxheight) { $max = $maxheight; } else { $max = $maxwidth; } $x = $height / $max; $fheight = floor($height / $x); $fwidth = floor($width / $x); } $thumb = imagecreatetruecolor($fwidth, $fheight); if ($ext == "jpg" or $ext == "jpeg") { $source = imagecreatefromjpeg($from); } if ($ext == "png") { $source = imagecreatefrompng($from); } imagecopyresized($thumb, $source, 0, 0, 0, 0, $fwidth, $fheight, $width, $height); if ($ext == "jpg" or $ext == "jpeg") { imagejpeg($thumb, $to, 100); } if ($ext == "png") { imagepng($thumb, $to, 1); } if ($ext != "jpg" or $ext != "jpeg" or $ext != "png") { return false; } else { return true; } }
public static function view($url) { $numargs = func_num_args(); $arg_list = func_get_args(); $data = array(); for ($i = 1; $i < $numargs; $i++) { $data[] = $arg_list[$i]; } $filepath = ELoader::$views_path . "/{$url}.views.php"; if (file_exists($filepath)) { include ELoader::$views_path . "/{$url}.views.php"; } else { ELog::error("non-existent view included. Please define {$filepath} !"); } }
<?php include "gfx3/lib.php"; $gameid = EHeaderDataParser::db_get("id"); $client = new OCSClient(); $data = $client->get("v1/content/data/{$gameid}/"); if (EUser::nick() != $data["ocs"]["data"]["content"]["personid"]) { ELog::error("You are not authorized to view this page!"); } echo "<div class=\"modal-header\">\n <button type=\"button\" class=\"close\" data-dismiss=\"modal\">×</button>\n <h3>Modify your game</h3>\n </div>\n \n <form class=\"form-horizontal\" action=\"/editGameAction.php\" target=\"_self\" method=\"post\">\n <div class=\"modal-body\">\n <fieldset>\n \n <div class=\"control-group\">\n <label class=\"control-label\" for=\"name\">Title</label>\n <div class=\"controls\">\n <input type=\"text\" name=\"name\" class=\"input-xlarge\" id=\"name\" value=\"" . EUtility::stripslashes($data["ocs"]["data"]["content"]["name"]) . "\">\n <input type=\"hidden\" name=\"idcontent\" class=\"input-xlarge\" id=\"idcontent\" value=\"{$gameid}\">\n </div>\n </div>\n \n <div class=\"control-group\">\n <label class=\"control-label\" for=\"downloadname1\">Download name</label>\n <div class=\"controls\">\n <input type=\"text\" name=\"downloadname1\" class=\"input-xlarge\" id=\"downloadname1\" \nvalue=\"" . EUtility::stripslashes($data["ocs"]["data"]["content"]["downloadname1"]) . "\">\n <p class=\"help-block\">- this is the label that will be shown to download your game</p>\n </div>\n </div>\n \n <div class=\"control-group\">\n <label class=\"control-label\" for=\"downloadlink1\">Download link</label>\n <div class=\"controls\">\n <input type=\"text\" name=\"downloadlink1\" class=\"input-xlarge\" id=\"downloadlink1\" \nvalue=\"" . EUtility::stripslashes($data["ocs"]["data"]["content"]["downloadlink1"]) . "\">\n <p class=\"help-block\">- this is the direct link to your game. If you want to host it on gamingfreedom server, you can do it uploading\n it after having created this skeleton</p>\n </div>\n </div>\n \n <div class=\"control-group\">\n <label class=\"control-label\" for=\"description\">Summary</label>\n <div class=\"controls\">\n <textarea cols=\"60\" rows=\"3\" name=\"summary\" class=\"input-xlarge\" \nid=\"summary\">" . EUtility::br2nl(EUtility::stripslashes($data["ocs"]["data"]["content"]["summary"])) . "</textarea>\n <p class=\"help-block\">- A short description to your game</p>\n </div>\n </div>\n \n <div class=\"control-group\">\n <label class=\"control-label\" for=\"description\">Features</label>\n <div class=\"controls\">\n <textarea cols=\"60\" rows=\"3\" name=\"description\" class=\"input-xlarge\" \nid=\"description\">" . EUtility::br2nl(EUtility::stripslashes($data["ocs"]["data"]["content"]["description"])) . "</textarea>\n <p class=\"help-block\">- A more in depth description and a list of features.</p>\n </div>\n </div>\n \n <div class=\"control-group\">\n <label class=\"control-label\" for=\"version\">Version</label>\n <div class=\"controls\">\n <input type=\"text\" name=\"version\" class=\"input-xlarge\" id=\"version\" \nvalue=\"" . EUtility::stripslashes($data["ocs"]["data"]["content"]["version"]) . "\">\n <p class=\"help-block\">- set here the version of your application</p>\n </div>\n </div>\n \n <div class=\"control-group\">\n <label class=\"control-label\" for=\"changelog\">Changelog</label>\n <div class=\"controls\">\n <textarea cols=\"60\" rows=\"3\" name=\"changelog\" class=\"input-xlarge\" \nid=\"changelog\">" . EUtility::stripslashes(EUtility::br2nl($data["ocs"]["data"]["content"]["changelog"])) . "</textarea>\n <p class=\"help-block\">- putting changelog helps your fans to know what is changed and what improvements\n have you put</p>\n </div>\n </div>\n \n </fieldset>\n \n </div>\n <div class=\"modal-footer\" style=\"background-color:#FFFFFF;\">\n <input type=\"submit\" class=\"btn btn-primary\" value=\"Next\">\n </div>\n \n </form>\n ";
public static function parse_file($filename) { //initializing empty array $result = array(); //mapping file line per line //$cache = new ECacheFile($filename); //$file = $cache->get(); //$file = explode("\n",$file); $file = file($filename); $file = EConfig::erase_php_code($file); foreach ($file as $line) { if (!empty($line)) { $chunks = explode("|", $line); //gives correct key and correct value, erasing line break. //control if is set more than once if (isset($result[$chunks[0]])) { //ELog::warning("<b>".$chunks[0]."</b> property is set more than once in ".$filename." config file!"); } else { //control if is set to empty value if (count($chunks) < 2) { ELog::warning("<b>" . $chunks[0] . "</b> property has empty value in " . $filename . " config file!"); } else { //load 1:1 data and gives a simple value if (count($chunks) == 2) { $result[$chunks[0]] = rtrim($chunks[1], "\n"); } else { //load 1:n data and gives an array if (count($chunks) > 2) { $data = array(); for ($i = 1; $i < count($chunks); $i++) { $data[] = rtrim($chunks[$i], "\n"); } $result[$chunks[0]] = $data; } else { ELog::error("unknown error in EConfig loading"); } } } } } } return $result; }
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']; } }
/** * upload a preview picture of a content * @param string $format * @param string $contentid * @param string $previewid * @return string xml/json */ private function contentpreviewupload($format, $contentid, $previewid) { $user = $this->checkpassword(true); $this->checktrafficlimit($user); $content = addslashes($contentid); $preview = addslashes($previewid); // fetch data $con = new OCSContent(); if ($preview == 1 or $preview == 2 or $preview == 3) { if ($con->load($content) and $con->is_owned(OCSUser::id())) { if (isset($_FILES['localfile']['name']) and isset($_FILES['localfile']['name']) and ($_FILES['localfile']['name'] != '' and $_FILES['localfile']['name'] != 'none' and $_FILES['localfile']['tmp_name'] != '' and $_FILES['localfile']['tmp_name'] != 'none')) { if ($con->previewadd($content, 'localfile', $preview)) { $txt = $this->generatexml($format, 'ok', 100, ''); } else { ELog::error("previewadd crashed lol!"); } } else { $txt = $this->generatexml($format, 'failed', 101, 'localfile not found'); } } else { $txt = $this->generatexml($format, 'failed', 102, 'no permission to change content'); } } else { $txt = $this->generatexml($format, 'failed', 103, 'preview must be 1, 2 or 3'); } echo $txt; }
public static function loadAllModules() { ELoader::$root_path = $_SERVER["HTTP_HOST"]; ELoader::$prev_path = getcwd(); //handle eventual subsites, changes directory and leaves unchanged //the engine will later check for gfx presence in an upper folder ELoader::checkForSubsites(); ELoader::$abs_path = ELoader::getLibInstallPath(); //include source if (chdir(ELoader::$abs_path)) { foreach (glob("*.class.php") as $filename) { include_once $filename; } } else { ELog::error("critical error including gfx source. Path: " . ELoader::$abs_path); } //include controllers if (chdir(ELoader::$controllers_path)) { foreach (glob("*.controller.php") as $filename) { include_once $filename; } } else { ELog::error("critical error including controllers. Path: " . ELoader::$controllers_path); } //include models if (chdir(ELoader::$models_path)) { foreach (glob("*.model.php") as $filename) { include_once $filename; } } else { ELog::error("critical error including models. Path: " . ELoader::$models_path); } //include local external libraries //this is optional, if not found nothing happens if (file_exists(ELoader::$locallibs_path)) { if (chdir(ELoader::$locallibs_path)) { foreach (glob("*.class.php") as $filename) { include_once $filename; } } else { ELog::error("critical error including controllers. Path: " . ELoader::$locallibs_path); } } //include global external libraries if (file_exists(ELoader::$libs_path)) { if (chdir(ELoader::$libs_path)) { foreach (glob("*.class.php") as $filename) { include_once $filename; } } else { ELog::error("critical error including external libs. Path: " . ELoader::$libs_path); } } chdir(ELoader::$prev_path); }
public static function gallow($g) { $allowedgroups = explode("|", $g); $groups = explode("|", EUser::$group); foreach ($groups as $thGroup) { foreach ($allowedgroups as $alGroup) { if ($thGroup == $alGroup) { return true; } } } ELog::error("You're not allowed to be here."); return false; }
public function insert($allowed_fields = array()) { if (!$this->is_ready_test()) { return; } //accepting eventual data as valid if (!empty($allowed_fields)) { foreach ($this->fields as $field) { 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 (EHeaderDataParser::exists_post($field['field'])) { $entries[] = array("field" => $field['field'], "value" => EHeaderDataParser::db_post($field['field']), "type" => $field['type']); } } } if (!empty($entries)) { $sql = "INSERT INTO " . $this->table . " ("; //starting query foreach ($entries as $entry) { $sql = $sql . $entry['field'] . ","; } //insert in queries all the fields we're going to accept $sql = rtrim($sql, ",") . ") VALUES ("; foreach ($entries as $entry) { //type check against type field found with describe if ($field['type'] == "varchar" or $field['type'] == "text") { $sql = $sql . "'" . $entry['value'] . "',"; } else { if ($field['type'] == "int") { if (preg_match("/[^0-9]/", $entry['value'])) { ELog::error("EData Object Error: wrong data passed for <i><big>`" . $field['field'] . "`</big></i> with type `INT`! freezing..."); } $sql = $sql . $entry['value'] . ","; } } } $sql = rtrim($sql, ",") . ")"; // cleaning and ending query //outputting or executing if ($this->noquery == false) { EDatabase::q($sql); } else { echo $sql; } } }
<?php include "gfx3/lib.php"; $prevpage = EPageProperties::get_previous_page(); $idcontent = EHeaderDataParser::db_post("idcontent"); if (!empty($_FILES['localfile'])) { $tmp_name = $_FILES['localfile']['tmp_name']; $name = $_FILES['localfile']['name']; $client = new OCSClient(); $client->set_auth_info(EUser::nick(), EUser::password()); $abs_name = EFileSystem::rename_file($tmp_name, "/tmp/" . $name); $client->set_upload_file("/tmp/" . $name); $result = $client->post("v1/content/uploaddownload/{$idcontent}"); if ($result["ocs"]["meta"]["statuscode"] == "100") { header("Location: {$prevpage}"); } else { //echo $client->get_last_raw_result(); ELog::error("something went wrong"); } }
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."); } } }