예제 #1
0
/**
 * Executes a simple formula.
 *
 * @param string $formula	Formular to execute
 * @param integer $basic	Basic costs
 * @param integer $level	Level
 *
 * @return integer	Result
 */
function parseSimpleFormula($formula, $basic, $level)
{
    Hook::event("ParseSimpleFormula", array(&$formula, &$basic, &$level));
    $formula = Str::replace("{level}", $level, $formula);
    $formula = Str::replace("{basic}", $basic, $formula);
    $result = 0;
    eval("\$result = " . $formula . ";");
    return (int) $result;
}
예제 #2
0
 /**
  * No changes
  *
  * @return void
  */
 public function testStrReplace()
 {
     $res = Str::replace('some', 'more', 'in some text');
     $expected = 'in more text';
     $this->assertSame($expected, $res);
     $count = 0;
     $res = Str::replace('some', 'more', 'in some text', $count);
     $this->assertSame($expected, $res);
     $this->assertSame(1, $count);
 }
예제 #3
0
 /**
  * @return Bengine_Admin_Controller_User
  */
 protected function seekAction()
 {
     $username = $this->getParam("username");
     $email = $this->getParam("email");
     if ($this->getParam("delete_user")) {
         $this->deleteUser($this->getParam("delete"));
     }
     $s = false;
     $sr = array();
     if (!$username || !$email) {
         $username = Str::replace("%", "", $username);
         $username = Str::replace("*", "%", $username);
         $userwhere = "";
         if (Str::length(Str::replace("%", "", $username)) > 0) {
             $userwhere = Core::getDB()->quoteInto("username LIKE ?", "%{$username}%");
             $s = true;
         }
         $email = Str::replace("%", "", $email);
         $email = Str::replace("*", "%", $email);
         $mailwhere = "";
         if (Str::length(Str::replace("%", "", $email)) > 0) {
             $mailwhere = Core::getDB()->quoteInto("email LIKE ?", "%{$email}%");
             $s = true;
         }
     }
     if ($s) {
         $where = "";
         if (!empty($userwhere)) {
             $where = $userwhere;
             if (!empty($mailwhere)) {
                 $where .= " OR " . $mailwhere;
             }
         } else {
             if (!empty($mailwhere)) {
                 $where = $mailwhere;
             }
         }
         $result = Core::getQuery()->select("user", array("userid", "username", "email"), "", $where);
         foreach ($result->fetchAll() as $row) {
             $id = $row["userid"];
             $sr[$id]["userid"] = $id;
             $sr[$id]["edit"] = Link::get("admin/user/edit/" . $id, Core::getLanguage()->getItem("Edit"));
             $sr[$id]["username"] = $row["username"];
             $sr[$id]["email"] = "<a href=\"mailto:" . $row["email"] . "\">" . $row["email"] . "</a>";
         }
     }
     Core::getTPL()->addLoop("searchresult", $sr);
     Core::getTPL()->assign("searched", $s);
     return $this;
 }
예제 #4
0
 /**
  * Fetches the user data in term of a session id.
  *
  * @return Recipe_User
  */
 protected function getData()
 {
     Hook::event("LoadUserData", array($this));
     if ($this->cacheActive) {
         $this->item = Core::getCache()->getUserCache($this->sid);
     } else {
         $select = array("u.*", "s.ipaddress");
         $joins = "LEFT JOIN " . PREFIX . "user u ON (s.userid = u.userid)";
         // Get custom user data from configuration
         if (Core::getConfig()->exists("userselect")) {
             $userConfigSelect = Core::getConfig()->get("userselect");
             $select = array_merge($select, $userConfigSelect["fieldsnames"]);
         }
         if (Core::getConfig()->exists("userjoins")) {
             $joins .= " " . Str::replace("PREFIX", PREFIX, Core::getConfig()->get("userjoins"));
         }
         $result = Core::getQuery()->select("sessions s", $select, $joins, Core::getDB()->quoteInto("s.sessionid = ? AND s.logged = '1'", $this->sid));
         $this->item = $result->fetchRow();
         $result->closeCursor();
     }
     if ($this->size() > 0) {
         defined("SID") || define("SID", $this->sid);
         if (IPCHECK && $this->get("ipcheck")) {
             if ($this->get("ipaddress") != IPADDRESS) {
                 forwardToLogin("IPADDRESS_INVALID");
             }
         }
         if ($this->get("templatepackage") != "") {
             Core::getTemplate()->setTemplatePackage($this->get("templatepackage"));
         }
     } else {
         if (LOGIN_REQUIRED && !defined("LOGIN_PAGE")) {
             forwardToLogin("NO_ACCESS");
         }
         $this->setGuest();
     }
     Hook::event("UserDataLoaded", array($this));
     return $this;
 }
예제 #5
0
 /**
  * Prepares the string for SQL search.
  *
  * @return String
  */
 public function prepareForSearch()
 {
     $this->replace("%", "");
     if (Str::length(Str::replace("*", "", $this->string)) >= $this->minLenghtForSearch) {
         $this->validSearchString = true;
     } else {
         $this->validSearchString = false;
     }
     $this->replace("*", "%");
     $this->string = "%" . $this->string . "%";
     return $this;
 }
예제 #6
0
 /**
  * Normalize the URL into readable string for the Rewrite-Engine.
  *
  * @param string $url	URL to normalize
  *
  * @return string	Normalized URL
  */
 public static function normalizeURL($url)
 {
     if (strpos($url, "?") > 0) {
         $url = preg_replace("/\\?(.*?)=/i", "/\$1:", $url);
         // Replace ?arg= with /arg:
         $url = preg_replace("/\\&amp;(.*?)=/i", "/\$1:", $url);
         // Replace &amp;arg= with /arg:
         $url = preg_replace("/\\&(.*?)=/i", "/\$1:", $url);
         // Replace &arg= with /arg:
         // Now remove useless arg names.
         $parsedURL = parse_url($url);
         $path = Str::substring(Str::replace($_SERVER["SCRIPT_NAME"], "", $parsedURL["path"]), 1);
         $splitted = explode("/", $path);
         $size = count($splitted);
         for ($i = 0; $i < $size; $i++) {
             if (strpos($splitted[$i], ":")) {
                 $splitted[$i] = explode(":", $splitted[$i]);
                 $levelNames = explode(",", REQUEST_LEVEL_NAMES);
                 if (Str::compare($splitted[$i][0], $levelNames[$i], true)) {
                     $url = Str::replace($splitted[$i][0] . ":", "", $url);
                 }
             }
         }
     }
     return BASE_URL . $url;
 }
예제 #7
0
 /**
  * Rank management for the alliance.
  *
  * @return Bengine_Game_Controller_Alliance
  */
 protected function rightManagementAction()
 {
     $post = Core::getRequest()->getPOST();
     if ($this->getRights(array("CAN_MANAGE"))) {
         if (isset($post["createrank"])) {
             if (Str::length($post["name"]) <= 30) {
                 Core::getQuery()->insert("allyrank", array("aid" => $this->aid, "name" => Str::validateXHTML($post["name"])));
             }
         } else {
             if (isset($post["changerights"])) {
                 $result = Core::getQuery()->select("allyrank", "rankid", "", Core::getDB()->quoteInto("aid = ?", $this->aid));
                 foreach ($result->fetchAll() as $row) {
                     if (isset($post["CAN_SEE_MEMBERLIST_" . $row["rankid"]])) {
                         $can_see_memberlist = 1;
                     } else {
                         $can_see_memberlist = 0;
                     }
                     if (isset($post["CAN_SEE_APPLICATIONS_" . $row["rankid"]])) {
                         $can_sse_applications = 1;
                     } else {
                         $can_sse_applications = 0;
                     }
                     if (isset($post["CAN_MANAGE_" . $row["rankid"]])) {
                         $can_manage = 1;
                     } else {
                         $can_manage = 0;
                     }
                     if (isset($post["CAN_BAN_MEMBER_" . $row["rankid"]])) {
                         $can_ban_member = 1;
                     } else {
                         $can_ban_member = 0;
                     }
                     if (isset($post["CAN_SEE_ONLINE_STATE_" . $row["rankid"]])) {
                         $can_see_onlie_state = 1;
                     } else {
                         $can_see_onlie_state = 0;
                     }
                     if (isset($post["CAN_WRITE_GLOBAL_MAILS_" . $row["rankid"]])) {
                         $can_write_global_mails = 1;
                     } else {
                         $can_write_global_mails = 0;
                     }
                     $spec = array("CAN_SEE_MEMBERLIST" => $can_see_memberlist, "CAN_SEE_APPLICATIONS" => $can_sse_applications, "CAN_MANAGE" => $can_manage, "CAN_BAN_MEMBER" => $can_ban_member, "CAN_SEE_ONLINE_STATE" => $can_see_onlie_state, "CAN_WRITE_GLOBAL_MAILS" => $can_write_global_mails);
                     Core::getQuery()->update("allyrank", $spec, "rankid = ? AND aid = ?", array($row["rankid"], $this->aid));
                 }
                 $result->closeCursor();
             } else {
                 if (!empty($post)) {
                     foreach ($post as $key => $value) {
                         if (preg_match("#^delete\\_#i", $key)) {
                             Core::getQuery()->delete("allyrank", "rankid = ? AND aid = ?", null, null, array(Str::replace("delete_", "", $key), $this->aid));
                             break;
                         }
                     }
                 }
             }
         }
         $select = array("rankid", "name", "CAN_SEE_MEMBERLIST", "CAN_SEE_APPLICATIONS", "CAN_MANAGE", "CAN_BAN_MEMBER", "CAN_SEE_ONLINE_STATE", "CAN_WRITE_GLOBAL_MAILS");
         $result = Core::getQuery()->select("allyrank", $select, "", Core::getDB()->quoteInto("aid = ?", $this->aid));
         Core::getTPL()->assign("num", $result->rowCount());
         Core::getTPL()->addLoop("ranks", $result);
     }
     return $this;
 }
예제 #8
0
 /**
  * Index action.
  *
  * @return Bengine_Game_Controller_Galaxy
  */
 protected function indexAction()
 {
     if ($this->isPost()) {
         $this->setCoordinatesByPost($this->getParam("galaxy"), $this->getParam("system"), $this->getParam("submittype"));
     }
     $this->validateInputs()->subtractHydrogen();
     // Star surveillance
     $canMonitorActivity = false;
     if (Game::getPlanet()->getBuilding("STAR_SURVEILLANCE") > 0) {
         $range = pow(Game::getPlanet()->getBuilding("STAR_SURVEILLANCE"), 2) - 1;
         $diff = abs(Game::getPlanet()->getData("system") - $this->system);
         if ($this->galaxy == Game::getPlanet()->getData("galaxy") && $range >= $diff) {
             $canMonitorActivity = true;
         }
     }
     Core::getTPL()->assign("canMonitorActivity", $canMonitorActivity);
     // Images
     $rockimg = Image::getImage("rocket.gif", Core::getLanguage()->getItem("ROCKET_ATTACK"));
     // Get sunsystem data
     $select = array("g.planetid", "g.position", "g.destroyed", "g.metal", "g.silicon", "g.moonid", "p.picture", "p.planetname", "p.last as planetactivity", "u.username", "u.usertitle", "u.userid", "u.points", "u.last as useractivity", "u.umode", "u.level", "m.planetid AS moon", "m.picture AS moonpic", "m.planetname AS moonname", "m.diameter AS moonsize", "m.temperature", "m.last as moonactivity", "a.tag", "a.name", "a.showmember", "a.homepage", "a.showhomepage", "u2a.aid", "b.to");
     $joins = "LEFT JOIN " . PREFIX . "planet p ON (p.planetid = g.planetid)";
     $joins .= "LEFT JOIN " . PREFIX . "user u ON (u.userid = p.userid)";
     $joins .= "LEFT JOIN " . PREFIX . "planet m ON (m.planetid = g.moonid)";
     $joins .= "LEFT JOIN " . PREFIX . "user2ally u2a ON (u2a.userid = u.userid)";
     $joins .= "LEFT JOIN " . PREFIX . "alliance a ON (a.aid = u2a.aid)";
     $joins .= "LEFT JOIN " . PREFIX . "ban_u b ON (b.userid = u.userid AND b.to > '" . TIME . "')";
     $where = Core::getDB()->quoteInto("g.galaxy = ? AND g.system = ?", array($this->galaxy, $this->system));
     $result = Core::getQuery()->select("galaxy g", $select, $joins, $where);
     $UserList = new Bengine_Game_User_List();
     $UserList->setKey("position");
     $UserList->setNewbieProtection(true);
     $UserList->setFetchRank(true);
     $UserList->setTagAsLink(false);
     $UserList->load($result);
     $sys = $UserList->getArray();
     Hook::event("SolarSystemDataBefore", array($this, &$sys));
     for ($i = 1; $i <= 15; $i++) {
         if (isset($sys[$i]) && !$sys[$i]["destroyed"]) {
             $sys[$i]["systempos"] = $i;
             if ($sys[$i]["tag"] != "") {
                 $sys[$i]["allydesc"] = sprintf(Core::getLanguage()->getItem("GALAXY_ALLY_HEADLINE"), $sys[$i]["tag"], $sys[$i]["alliance_rank"]);
             }
             $sys[$i]["metal"] = fNumber($sys[$i]["metal"]);
             $sys[$i]["silicon"] = fNumber($sys[$i]["silicon"]);
             $sys[$i]["picture"] = Image::getImage("planets/small/s_" . $sys[$i]["picture"] . Core::getConfig()->get("PLANET_IMG_EXT"), $sys[$i]["planetname"], 30, 30);
             $sys[$i]["picture"] = Link::get("game/" . SID . "/Mission/Index/" . $this->galaxy . "/" . $this->system . "/" . $i, $sys[$i]["picture"]);
             $sys[$i]["planetname"] = Link::get("game/" . SID . "/Mission/Index/" . $this->galaxy . "/" . $this->system . "/" . $i, $sys[$i]["planetname"]);
             $sys[$i]["moonpicture"] = $sys[$i]["moonpic"] != "" ? Image::getImage("planets/small/s_" . $sys[$i]["moonpic"] . Core::getConfig()->get("PLANET_IMG_EXT"), $sys[$i]["moonname"], 22, 22) : "";
             $sys[$i]["moon"] = sprintf(Core::getLanguage()->getItem("MOON_DESC"), $sys[$i]["moonname"]);
             $sys[$i]["moonsize"] = fNumber($sys[$i]["moonsize"]);
             $sys[$i]["moontemp"] = fNumber($sys[$i]["temperature"]);
             if ($sys[$i]["moonactivity"] > $sys[$i]["planetactivity"]) {
                 $activity = $sys[$i]["moonactivity"];
             } else {
                 $activity = $sys[$i]["planetactivity"];
             }
             if ($activity > TIME - 900 && $sys[$i]["userid"] != Core::getUser()->get("userid")) {
                 $sys[$i]["activity"] = "(*)";
             } else {
                 if ($activity > TIME - 3600 && $sys[$i]["userid"] != Core::getUser()->get("userid")) {
                     $sys[$i]["activity"] = "(" . floor((TIME - $activity) / 60) . " min)";
                 } else {
                     $sys[$i]["activity"] = "";
                 }
             }
             if (Game::getPlanet()->getBuilding("ROCKET_STATION") > 3 && $sys[$i]["userid"] != Core::getUser()->get("userid") && $this->inMissileRange()) {
                 $sys[$i]["rocketattack"] = Link::get("game/" . SID . "/RocketAttack/Index/" . $sys[$i]["planetid"], $rockimg);
                 $sys[$i]["moonrocket"] = "<tr><td colspan=\"3\" class=\"center\">" . Link::get("game/" . SID . "/RocketAttack/Index/" . $sys[$i]["moonid"] . "/1", Core::getLanguage()->getItem("ROCKET_ATTACK")) . "</td></tr>";
             } else {
                 $sys[$i]["rocketattack"] = "";
                 $sys[$i]["moonrocket"] = "";
             }
             $sys[$i]["allypage"] = Str::replace("\"", "", Link::get("game/" . SID . "/Alliance/Page/" . $sys[$i]["aid"], Core::getLanguage()->getItem("ALLIANCE_PAGE"), 1));
             if (($sys[$i]["showhomepage"] || $sys[$i]["aid"] == Core::getUser()->get("aid")) && $sys[$i]["homepage"] != "") {
                 $sys[$i]["homepage"] = "<tr><td>" . Str::replace("'", "\\'", Link::get($sys[$i]["homepage"], Core::getLanguage()->getItem("HOMEPAGE"), 2)) . "</td></tr>";
             } else {
                 $sys[$i]["homepage"] = "";
             }
             if ($sys[$i]["showmember"]) {
                 $sys[$i]["memberlist"] = "<tr><td>" . Str::replace("\"", "", Link::get("game/" . SID . "/Alliance/Memberlist/" . $sys[$i]["aid"], Core::getLanguage()->getItem("SHOW_MEMBERLIST"), 3)) . "</td></tr>";
             }
             $sys[$i]["debris"] = Image::getImage("debris.jpg", "", 25, 25);
         } else {
             if (empty($sys[$i]["destroyed"])) {
                 $sys[$i] = array();
                 $sys[$i]["destroyed"] = false;
                 $sys[$i]["metal"] = 0;
                 $sys[$i]["silicon"] = 0;
                 $sys[$i]["debris"] = "";
                 $sys[$i]["picture"] = "";
                 $sys[$i]["planetname"] = "";
                 $sys[$i]["planetid"] = "";
             } else {
                 $sys[$i]["metal"] = fNumber($sys[$i]["metal"]);
                 $sys[$i]["silicon"] = fNumber($sys[$i]["silicon"]);
                 $sys[$i]["debris"] = Image::getImage("debris.jpg", "", 25, 25);
                 $sys[$i]["picture"] = Image::getImage("planets/small/s_" . $sys[$i]["picture"] . Core::getConfig()->get("PLANET_IMG_EXT"), $sys[$i]["planetname"], 30, 30);
                 $sys[$i]["picture"] = Link::get("game/" . SID . "/Mission/Index/" . $this->galaxy . "/" . $this->system . "/" . $i, $sys[$i]["picture"]);
                 $sys[$i]["planetname"] = Core::getLanguage()->getItem("DESTROYED_PLANET");
                 $sys[$i]["planetname"] = Link::get("game/" . SID . "/Mission/Index/" . $this->galaxy . "/" . $this->system . "/" . $i, $sys[$i]["planetname"]);
             }
             $sys[$i]["systempos"] = $i;
             $sys[$i]["userid"] = null;
             $sys[$i]["moon"] = "";
             $sys[$i]["moonid"] = "";
             $sys[$i]["username"] = "";
             $sys[$i]["alliance"] = "";
             $sys[$i]["activity"] = "";
             $sys[$i]["moonpicture"] = "";
             $sys[$i]["user_status_long"] = "";
         }
     }
     ksort($sys);
     Hook::event("SolarSystemDataAfter", array($this, &$sys));
     Core::getTPL()->assign("sendesp", Image::getImage("esp.gif", Core::getLanguage()->getItem("SEND_ESPIONAGE_PROBE")));
     Core::getTPL()->assign("monitorfleet", Image::getImage("binocular.gif", Core::getLanguage()->getItem("MONITOR_FLEET_ACTIVITY")));
     Core::getTPL()->assign("moon", Str::replace("\"", "", Image::getImage("planets/mond" . Core::getConfig()->get("PLANET_IMG_EXT"), Core::getLanguage()->getItem("MOON"), 75, 75)));
     Core::getTPL()->addLoop("sunsystem", $sys);
     Core::getTPL()->assign("debris", Str::replace("\"", "", Image::getImage("debris.jpg", Core::getLanguage()->getItem("DEBRIS"), 75, 75)));
     Core::getTPL()->assign("galaxy", $this->galaxy);
     Core::getTPL()->assign("system", $this->system);
     return $this;
 }
예제 #9
0
 /**
  * Index action.
  *
  * @param integer $id	Construction ID
  *
  * @return Bengine_Game_Controller_Construction_Edit
  */
 protected function indexAction($id)
 {
     if ($this->isPost()) {
         if ($this->getParam("addreq")) {
             $this->addRequirement($id, $this->getParam("level"), $this->getParam("needs"));
         }
         if ($this->getParam("saveconstruction")) {
             $this->saveConstruction($this->getParam("name"), $this->getParam("name_id"), $this->getParam("allow_on_moon"), $this->getParam("desc"), $this->getParam("full_desc"), $this->getParam("prod_what"), $this->getParam("prod"), $this->getParam("cons_what"), $this->getParam("consumption"), $this->getParam("special"), $this->getParam("basic_metal"), $this->getParam("basic_silicon"), $this->getParam("basic_hydrogen"), $this->getParam("basic_energy"), $this->getParam("charge_metal"), $this->getParam("charge_silicon"), $this->getParam("charge_hydrogen"), $this->getParam("charge_energy"));
         }
     }
     $select = array("c.name AS name_id", "p.content AS name", "c.special", "c.allow_on_moon", "c.basic_metal", "c.basic_silicon", "c.basic_hydrogen", "c.basic_energy", "c.prod_metal", "c.prod_silicon", "c.prod_hydrogen", "c.prod_energy", "c.cons_metal", "c.cons_silicon", "c.cons_hydrogen", "c.cons_energy", "c.charge_metal", "c.charge_silicon", "c.charge_hydrogen", "c.charge_energy");
     $joins = "LEFT JOIN " . PREFIX . "phrases p ON (p.title = c.name)";
     $result = Core::getQuery()->select("construction c", $select, $joins, Core::getDB()->quoteInto("c.buildingid = ? AND p.languageid = ?", array($id, Core::getLanguage()->getOpt("languageid"))));
     if ($row = $result->fetchRow()) {
         $result->closeCursor();
         Hook::event("EditUnitDataLoaded", array(&$row));
         // Set production
         $prodWhat = "";
         if (!empty($row["prod_metal"])) {
             $row["prod"] = $row["prod_metal"];
             $prodWhat = "metal";
         } else {
             if (!empty($row["prod_silicon"])) {
                 $row["prod"] = $row["prod_silicon"];
                 $prodWhat = "silicon";
             } else {
                 if (!empty($row["prod_hydrogen"])) {
                     $row["prod"] = $row["prod_hydrogen"];
                     $prodWhat = "hydrogen";
                 } else {
                     if (!empty($row["prod_energy"])) {
                         $row["prod"] = $row["prod_energy"];
                         $prodWhat = "energy";
                     }
                 }
             }
         }
         // Set Consumption
         $consWhat = "";
         if (!empty($row["cons_metal"])) {
             $row["consumption"] = $row["cons_metal"];
             $consWhat = "metal";
         } else {
             if (!empty($row["cons_silicon"])) {
                 $row["consumption"] = $row["cons_silicon"];
                 $consWhat = "silicon";
             } else {
                 if (!empty($row["cons_hydrogen"])) {
                     $row["consumption"] = $row["cons_hydrogen"];
                     $consWhat = "hydrogen";
                 } else {
                     if (!empty($row["cons_energy"])) {
                         $row["consumption"] = $row["cons_energy"];
                         $consWhat = "energy";
                     }
                 }
             }
         }
         Core::getTPL()->assign("prodWhat", $this->getResourceSelect($prodWhat));
         Core::getTPL()->assign("consWhat", $this->getResourceSelect($consWhat));
         Core::getTPL()->assign($row);
         $result = Core::getQuery()->select("phrases", "content", "", Core::getDB()->quoteInto("languageid = ? AND title = ?", array(Core::getLanguage()->getOpt("languageid"), $row["name_id"] . "_DESC")));
         $_row = $result->fetchRow();
         $result->closeCursor();
         Core::getTPL()->assign("description", Str::replace("<br />", "", $_row["content"]));
         $result = Core::getQuery()->select("phrases", "content", "", Core::getDB()->quoteInto("languageid = ? AND title = ?", array(Core::getLanguage()->getOpt("languageid"), $row["name_id"] . "_FULL_DESC")));
         $_row = $result->fetchRow();
         $result->closeCursor();
         Core::getTPL()->assign("full_description", Str::replace("<br />", "", $_row["content"]));
         $req = array();
         $i = 0;
         $result = Core::getQuery()->select("requirements r", array("r.requirementid", "r.needs", "r.level", "p.content"), "LEFT JOIN " . PREFIX . "construction b ON (b.buildingid = r.needs) LEFT JOIN " . PREFIX . "phrases p ON (p.title = b.name)", Core::getDB()->quoteInto("r.buildingid = ? AND p.languageid = ?", array($id, Core::getLanguage()->getOpt("languageid"))));
         foreach ($result->fetchAll() as $row) {
             $req[$i]["delete"] = Link::get("game/sid:" . SID . "/Construction_Edit/DeleteRequirement/" . $row["requirementid"] . "/" . $id, "[" . Core::getLanguage()->getItem("DELETE") . "]");
             $req[$i]["name"] = Link::get("game/" . SID . "/Construction_Edit/Index/" . $row["needs"], $row["content"]);
             $req[$i]["level"] = $row["level"];
             $i++;
         }
         Core::getTPL()->addLoop("requirements", $req);
         $const = array();
         $i = 0;
         $result = Core::getQuery()->select("construction b", array("b.buildingid", "p.content"), "LEFT JOIN " . PREFIX . "phrases p ON (p.title = b.name)", "(b.mode = '1' OR b.mode = '2' OR b.mode = '5') AND p.languageid = " . Core::getDB()->quote(Core::getLanguage()->getOpt("languageid")), "p.content ASC");
         foreach ($result->fetchAll() as $row) {
             $const[$i]["name"] = $row["content"];
             $const[$i]["id"] = $row["buildingid"];
             $i++;
         }
         $result->closeCursor();
         Core::getTPL()->addLoop("constructions", $const);
     }
     return $this;
 }
예제 #10
0
 /**
  * Parses a formula and return its result.
  *
  * @param string $formula
  * @param int $level
  *
  * @return integer    Result
  */
 protected function parseFormula($formula, $level)
 {
     $me = $this;
     $formula = Str::replace("{level}", $level, $formula);
     $formula = Str::replace("{temp}", $this->data["temperature"], $formula);
     $formula = preg_replace_callback("#\\{tech\\=([0-9]+)\\}#i", function ($matches) use($me) {
         return $me->getResearch($matches[1]);
     }, $formula);
     $result = 0;
     Hook::event("ParseFormula", array($formula, $level, $this));
     eval("\$result = " . $formula . ";");
     return (int) $result;
 }
예제 #11
0
 /**
  * Parse cache content concerning the quotes.
  *
  * @param string $content	Content to parse
  *
  * @return string	Parsed content
  */
 protected function compileContent($content)
 {
     return Str::replace("\"", "\\\"", $content);
 }
예제 #12
0
 /**
  * Shows the editing form.
  *
  * @return Bengine_Game_Controller_Unit
  */
 protected function editAction()
 {
     Core::getUser()->checkPermissions("CAN_EDIT_CONSTRUCTIONS");
     if ($this->isPost()) {
         if ($this->getParam("saveunit")) {
             $this->saveConstruction($this->id, $this->getParam("name_id"), $this->getParam("name"), $this->getParam("allow_on_moon"), $this->getParam("desc"), $this->getParam("full_desc"), $this->getParam("basic_metal"), $this->getParam("basic_silicon"), $this->getParam("basic_hydrogen"), $this->getParam("basic_energy"), $this->getParam("capicity"), $this->getParam("speed"), $this->getParam("consume"), $this->getParam("attack"), $this->getParam("shield"), $this->getParam("baseEngine"), $this->getParam("extentedEngine"), $this->getParam("extentedEngineLevel"), $this->getParam("extentedEngineSpeed"), $this->getParam("del_rf"), $this->getParam("rf_new"), $this->getParam("rf_new_value"));
         }
         if ($this->getParam("addreq")) {
             $this->addRequirement($this->getParam("level"), $this->getParam("needs"));
         }
     }
     $languageid = Core::getLang()->getOpt("languageid");
     $select = array("c.name AS name_id", "c.allow_on_moon", "p.content AS name", "c.basic_metal", "c.basic_silicon", "c.basic_hydrogen", "c.basic_energy", "sds.unitid", "sds.capicity AS capacity", "sds.speed", "sds.consume", "sds.attack", "sds.shield");
     $joins = "LEFT JOIN " . PREFIX . "phrases p ON (p.title = c.name)";
     $joins .= "LEFT JOIN " . PREFIX . "ship_datasheet sds ON (sds.unitid = c.buildingid)";
     $where = Core::getDB()->quoteInto("c.buildingid = ? AND p.languageid = ?", array($this->id, $languageid));
     $result = Core::getQuery()->select("construction c", $select, $joins, $where);
     if ($row = $result->fetchRow()) {
         $result->closeCursor();
         Hook::event("EditUnitDataLoaded", array(&$row));
         Core::getTPL()->assign($row);
         Core::getTPL()->assign("shell", fNumber(($row["basic_metal"] + $row["basic_silicon"]) / 10));
         $where = Core::getDB()->quoteInto("languageid = ? AND title = ?", array($languageid, $row["name_id"] . "_DESC"));
         $result = Core::getQuery()->select("phrases", "content", "", $where);
         $_row = $result->fetchRow();
         $result->closeCursor();
         Core::getTPL()->assign("description", Str::replace("<br />", "", $_row["content"]));
         $where = Core::getDB()->quoteInto("languageid = ? AND title = ?", array($languageid, $row["name_id"] . "_FULL_DESC"));
         $result = Core::getQuery()->select("phrases", "content", "", $where);
         $_row = $result->fetchRow();
         $result->closeCursor();
         Core::getTPL()->assign("full_description", Str::replace("<br />", "", $_row["content"]));
         // Engine selection
         Core::getTPL()->assign("extentedEngine", $this->getEnginesList(0));
         Core::getTPL()->assign("extentedEngineLevel", 0);
         Core::getTPL()->assign("extentedEngineSpeed", "");
         $engines = array();
         $result = Core::getQuery()->select("ship2engine s2e", array("s2e.engineid", "s2e.level", "s2e.base_speed", "s2e.base"), "", Core::getDB()->quoteInto("s2e.unitid = ?", $this->id));
         foreach ($result->fetchAll() as $_row) {
             if ($_row["base"] == 1) {
                 Core::getTPL()->assign("baseEngine", $this->getEnginesList($_row["engineid"]));
             } else {
                 Core::getTPL()->assign("extentedEngine", $this->getEnginesList($_row["engineid"]));
                 Core::getTPL()->assign("extentedEngineLevel", $_row["level"]);
                 Core::getTPL()->assign("extentedEngineSpeed", $_row["base_speed"]);
             }
         }
         $req = array();
         $i = 0;
         $where = Core::getDB()->quoteInto("r.buildingid = ? AND p.languageid = ?", array($this->id, $languageid));
         $result = Core::getQuery()->select("requirements r", array("r.requirementid", "r.needs", "r.level", "p.content"), "LEFT JOIN " . PREFIX . "construction b ON (b.buildingid = r.needs) LEFT JOIN " . PREFIX . "phrases p ON (p.title = b.name)", $where);
         foreach ($result->fetchAll() as $row) {
             $req[$i]["delete"] = Link::get("game/" . SID . "/Unit/DeleteRequirement/" . $this->id . "/" . $row["requirementid"], "[" . Core::getLanguage()->getItem("DELETE") . "]");
             $req[$i]["name"] = Link::get("game/" . SID . "/Unit/Edit/" . $row["needs"], $row["content"]);
             $req[$i]["level"] = $row["level"];
             $i++;
         }
         $result->closeCursor();
         Core::getTPL()->addLoop("requirements", $req);
         $const = array();
         $i = 0;
         $where = Core::getDB()->quoteInto("(b.mode = '1' OR b.mode = '2' OR b.mode = '5') AND p.languageid = ?", $languageid);
         $result = Core::getQuery()->select("construction b", array("b.buildingid", "p.content"), "LEFT JOIN " . PREFIX . "phrases p ON (p.title = b.name)", $where, "p.content ASC");
         foreach ($result->fetchAll() as $row) {
             $const[$i]["name"] = $row["content"];
             $const[$i]["id"] = $row["buildingid"];
             $i++;
         }
         $result->closeCursor();
         Core::getTPL()->addLoop("constructions", $const);
         Core::getTPL()->addLoop("rapidfire", $this->getRapidFire());
         Core::getTPL()->assign("rfSelect", $this->getShipSelect());
     }
     return $this;
 }
예제 #13
0
 /**
  * @param string $var
  * @param string $value
  * @param string $type
  * @param string $options
  * @param integer $groupid
  * @return Bengine_Admin_Controller_Config
  */
 protected function addVar($var, $value, $type, $options, $groupid)
 {
     $options = $this->serialize($options);
     $spec = array("var" => Str::replace(" ", "_", $var), "value" => $value, "type" => $type, "options" => $options, "groupid" => $groupid, "islisted" => 1);
     Core::getQuery()->insert("config", $spec);
     return $this;
 }
예제 #14
0
 /**
  * Sets the user id.
  *
  * @param string
  *
  * @return Bengine_Comm_Controller_Signature
  */
 public function setUserId($_userid)
 {
     $_userid = Str::replace(self::IMAGE_FILE_EXTENSION, "", $_userid);
     $this->_userid = (int) $_userid;
     return $this;
 }
예제 #15
0
 /**
  * Index action.
  *
  * @return Bengine_Game_Controller_Preferences
  */
 protected function indexAction()
 {
     /* @var Bengine_Game_Model_Collection_Event $events */
     $events = Game::getCollection("game/event");
     $events->addVacationModeFilter(Core::getUser()->get("userid"));
     if ($this->isPost()) {
         if (!Core::getUser()->get("umode") && $this->getParam("saveuserdata")) {
             $this->updateUserData($this->getParam("username"), $this->getParam("usertitle"), $this->getParam("email"), $this->getParam("password"), $this->getParam("theme"), $this->getParam("language"), $this->getParam("templatepackage"), $this->getParam("umode"), $this->getParam("delete"), $this->getParam("ipcheck"), $this->getParam("esps"), $this->getParam("generate_key"), $this->getParam("js_interface"));
         } else {
             if (TIME > Core::getUser()->get("umodemin") && $this->getParam("disable_umode")) {
                 $this->disableUmode();
             }
         }
         if ($this->getParam("update_deletion")) {
             $this->updateDeletion($this->getParam("delete"));
         }
     }
     if (Core::getUser()->get("delete") > 0) {
         $delmsg = Date::timeToString(2, Core::getUser()->get("delete"), "", false);
         $delmsg = sprintf(Core::getLanguage()->getItem("DELETE_DATE"), $delmsg);
         Core::getTPL()->assign("delmessage", $delmsg);
     }
     if (Core::getUser()->get("umode")) {
         $canDisableUmode = true;
         if (Core::getUser()->get("umodemin") > TIME) {
             $canDisableUmode = false;
             $umodemsg = Date::timeToString(1, Core::getUser()->get("umodemin"), "", false);
             $umodemsg = sprintf(Core::getLanguage()->getItem("UMODE_DATE"), $umodemsg);
             Core::getTPL()->assign("umode_to", $umodemsg);
         }
         Core::getTPL()->assign("can_disable_umode", $canDisableUmode);
     }
     $packs = array();
     $excludedPackages = explode(",", Core::getOptions()->get("EXCLUDE_TEMPLATE_PACKAGE"));
     $excludedPackages = array_map("trim", $excludedPackages);
     $excludedPackages[] = "default";
     $excludedPackages[] = Core::getOptions()->get("templatepackage");
     $dir = new DirectoryIterator(APP_ROOT_DIR . "app/templates/");
     /* @var DirectoryIterator $package */
     foreach ($dir as $package) {
         if (!$package->isDot() && $package->isDir() && !in_array($package->getBasename(), $excludedPackages)) {
             $directoryName = $package->getFilename();
             $templateName = Core::getLang()->exists("TEMPLATE_NAME_" . $directoryName) ? Core::getLang()->get("TEMPLATE_NAME_" . $directoryName) : $directoryName;
             $packs[] = array("value" => $directoryName, "name" => $templateName);
         }
     }
     Hook::event("LoadTemplatePackages", array(&$packs));
     Core::getTPL()->addLoop("templatePacks", $packs);
     $result = Core::getQuery()->select("languages", array("languageid", "title"), "", "", "title ASC");
     Core::getTPL()->addLoop("langs", $result->fetchAll());
     $result = Core::getQuery()->select("feed_keys", array("feed_key"), "", Core::getDB()->quoteInto("user_id = ?", Core::getUser()->get("userid")));
     if ($result->rowCount() > 0) {
         $feed_key = $result->fetchColumn();
         $link = Core::getLang()->getOpt("langcode") . "/feed/{type}/" . Core::getUser()->get("userid") . "/" . $feed_key;
         $rss = Str::replace("{type}", "rss", $link);
         $atom = Str::replace("{type}", "atom", $link);
         $this->assign("rss_feed_url", Link::get($rss, BASE_URL . $rss, "", "", "target=\"_blank\""));
         $this->assign("atom_feed_url", Link::get($atom, BASE_URL . $atom, "", "", "target=\"_blank\""));
     } else {
         $this->assign("rss_feed_url", "-");
         $this->assign("atom_feed_url", "-");
     }
     $this->assign("goToSignature", Link::get("game/" . SID . "/Preferences/Signature", Core::getLang()->get("GO_TO_SIGNATURE")));
     return $this;
 }
예제 #16
0
 /**
  * Sets a new cookie.
  *
  * @param string $cookie	Cookie name
  * @param string $value		Cookie value
  * @param integer $expires	Cookie expires in $ days
  *
  * @return Recipe_Request
  */
 public function setCookie($cookie, $value, $expires = 365)
 {
     $domain = $_SERVER["SERVER_NAME"] != "localhost" ? Str::replace("www.", ".", $_SERVER["SERVER_NAME"]) : null;
     setcookie(COOKIE_PREFIX . $cookie, $value, TIME + 86400 * $expires, "/", $domain);
     return $this;
 }