/** * Index action. * * @return Bengine_Comm_Controller_Index */ public function indexAction() { Hook::event("CommIndexStart", array($this)); $this->assign("errorMsg", Core::getRequest()->getGET("error")); if ($this->isPost()) { $encryption = Core::getOptions("USE_PASSWORD_SALT") ? "md5_salt" : "md5"; $login = new Bengine_Game_Login($this->getParam("username"), $this->getParam("password"), "game", $encryption); $login->setRedirectOnFailure(false)->checkData(); if ($login->getCanLogin()) { Hook::event("PreLogin", array($login)); $login->startSession(); Hook::event("PostLogin", array($login)); } else { $this->assign("errorMsg", $login->getErrors()->getFirst()); } } if ($this->errorMsg != "") { Core::getLang()->load("error"); $this->assign("errorMsg", Core::getLang()->get($this->errorMsg)); } $this->assign("page", Core::getLang()->getItem("LOGIN")); if ($cmsPage = Comm::getCMS()->getPage("index")) { $this->assign("page", $cmsPage["title"]); $this->assign("content", $cmsPage["content"]); $this->setTemplate("cms_page"); } else { $this->assign("showDefaultContent", true); } Hook::event("CommIndexEnd", array($this)); return $this; }
/** * @return Bengine_Admin_Controller_News */ protected function indexAction() { if ($this->getParam("add")) { $this->add($this->getParam("language_id"), $this->getParam("title"), $this->getParam("text")); } $first = true; $i = 1; $news = array(); $result = Core::getQuery()->select("news", array("news_id", "title", "text", "time", "enabled", "sort_index"), "", "", "sort_index ASC, news_id DESC"); $total = $result->rowCount(); foreach ($result->fetchAll() as $row) { $down = ""; $up = ""; if (!$first) { $up = Image::getImage("admin/up.gif", "", 16, 16); $up = Link::get("admin/news/moveup/" . $row["news_id"], $up); } $first = false; if ($i < $total) { $down = Image::getImage("admin/down.gif", "", 16, 16); $down = Link::get("admin/news/movedown/" . $row["news_id"], $down); } $i++; $news[] = array("news_id" => $row["news_id"], "title" => $row["title"], "text" => $row["text"], "time" => Date::timeToString(1, $row["time"]), "enabled" => $row["enabled"], "edit" => Link::get("admin/news/edit/" . $row["news_id"], Core::getLang()->get("Edit")), "delete" => Link::get("admin/news/delete/" . $row["news_id"], Core::getLang()->get("Delete")), "enable" => Link::get("admin/news/enable/" . $row["news_id"], Core::getLang()->get("Enable"), "", "green"), "disable" => Link::get("admin/news/disable/" . $row["news_id"], Core::getLang()->get("Disable"), "", "red"), "down" => $down, "up" => $up); } Core::getTemplate()->addLoop("news", $news); $languages = $this->getLanguages(); Core::getTPL()->assign("languageCount", count($languages)); if (count($languages) == 1) { Core::getTPL()->assign("languages", key($languages)); } else { Core::getTPL()->assign("languages", $this->getLanguageSelect()); } return $this; }
/** * @return array */ public function render() { foreach ($this->getModules() as $module) { if ($module["enable"]) { $name = $module["name"]; $translate = true; if (is_array($name)) { $translate = $name["noLangVar"]; $name = $name["value"]; } if ($translate) { $name = Core::getLang()->get($name); } $uri = $module["link"]; if (is_array($uri)) { $package = isset($uri["package"]) ? $uri["package"] : "admin"; $controller = isset($uri["controller"]) ? $uri["controller"] : "index"; $action = isset($uri["action"]) ? $uri["action"] : "index"; $uri = "{$package}/{$controller}/{$action}"; } $this->menu[] = Link::get($uri, $name, "", isset($module["class"]) ? $module["class"] : ""); } } return $this->menu; }
/** * Returns the form html for the field. * * @return string */ public function getHtml() { $field = $this->getModel(); return '<textarea id="' . strtolower($field->getName()) . '" name="' . $field->getName() . '">' . stripslashes($this->getData()) . '</textarea> <script type="text/javascript"> //<![CDATA[ tinyMCE_GZ.init({ language: "' . Core::getLang()->getOpt("langcode") . '",theme: "advanced",disk_cache : true,debug : false, plugins: "style,table,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,contextmenu,paste,fullscreen,noneditable,xhtmlxtras" }); //]]> </script> <script type="text/javascript"> //<![CDATA[ tinyMCE.init({ language: "' . Core::getLang()->getOpt("langcode") . '",forced_root_block: "div",theme: "advanced",skin : "alliancetext",mode: "exact",elements: "' . strtolower($field->getName()) . '",theme_advanced_toolbar_location: "top",theme_advanced_toolbar_align : "left",theme_advanced_disable: "anchor,styleselect",theme_advanced_statusbar_location: "bottom",theme_advanced_resizing: true,theme_advanced_resize_horizontal: false,width: 505,height: 370,relative_urls: false,remove_script_host: false, theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect", theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,insertdate,inserttime,preview", theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,forecolor,backcolor", theme_advanced_buttons4 : "styleprops,cite,abbr,acronym,|,link,unlink,anchor,image,cleanup,code,fullscreen,|,charmap,emotions,iespell,media,advhr,|,sub,sup", plugins: "style,table,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,contextmenu,paste,fullscreen,noneditable,xhtmlxtras" }); //]]> </script>'; }
/** * 登录表单操作 */ public function doLogin() { $codeValue = md5(md5($_SERVER['SERVER_NAME']) . strtoupper($_POST['authcode'])); // 验证码不正确 if (!isset($_COOKIE['admin_authcode']) || $codeValue != $_COOKIE['admin_authcode']) { setcookie('admin_authcode', false); $this->json(Core::getLang('incorrect_verification_code'), 2); } // 账号密码验证失败 if ('admin' == $_POST['username']) { include APP_PATH . 'config' . DS . 'adminpass.cfg.php'; if ($_admin_pass == User::hashPassword($_POST['password'], $_admin_salt)) { $_SESSION['uid'] = 1; $_SESSION['username'] = '******'; } else { $this->json(Core::getLang('password_incorrect'), 0); } } else { if (!User::verify($_POST['username'], $_POST['password'])) { $this->json(User::$msg, 0); } } setcookie('admin_authcode', false); // 成功输出默认数据 $this->json(); }
/** * Alliance page action. * * @return Bengine_Comm_Controller_Alliance */ public function pageAction() { Core::getLanguage()->load("Alliance"); Core::getTPL()->clearHTMLHeaderFiles(); Core::getTPL()->addHTMLHeaderFile("game.css", "css"); Core::getTPL()->addHTMLHeaderFile("lib/jquery.js", "js"); $tag = $this->getParam("1"); $fNumber = array("member", "points", "rpoints", "fpoints", "dpoints"); $attr = array("a.aid", "a.name", "a.tag", "a.logo", "a.textextern", "a.homepage", "a.showhomepage", "COUNT(u2a.userid) AS member", "SUM(u.points) AS points", "SUM(u.rpoints) AS rpoints", "SUM(u.fpoints) AS fpoints", "SUM(u.dpoints) AS dpoints"); $joins = "LEFT JOIN " . PREFIX . "user2ally u2a ON (u2a.aid = a.aid) "; $joins .= "LEFT JOIN " . PREFIX . "user u ON (u2a.userid = u.userid) "; $result = Core::getQuery()->select("alliance a", $attr, $joins, Core::getDB()->quoteInto("tag = ?", $tag), "", 1, "a.aid"); $row = $result->fetchRow(); if ($row) { foreach ($fNumber as $field) { $row[$field] = fNumber($row[$field]); } $parser = new Bengine_Game_Alliance_Page_Parser($row["aid"]); if (Str::length(strip_tags($row["textextern"])) > 0) { $row["textextern"] = $parser->startParser($row["textextern"]); } else { $row["textextern"] = Core::getLang()->get("WELCOME"); } $row["homepage"] = $row["homepage"] != "" ? Link::get($row["homepage"], $row["homepage"], $row["homepage"]) : ""; $row["logo"] = $row["logo"] != "" ? Image::getImage($row["logo"], "") : ""; Hook::event("ShowPublicAlliancePage", array(&$row)); $this->assign($row); $this->setIsAjax(); } else { $this->setNoDisplay(true); } return $this; }
/** * Runs the community application. * * @return Comm */ public function run() { parent::run(); Hook::event("CommStart"); define("LANG", Core::getLang()->getOpt("langcode") . "/"); Core::getLang()->load("Registration"); self::setCMS(); self::initUniverses(); self::initLanguage(); Core::getTPL()->addHTMLHeaderFile("lib/jquery.js", "js"); Core::getTPL()->addHTMLHeaderFile("lib/bootstrap.js", "js"); Core::getTPL()->addHTMLHeaderFile("main.js", "js"); Core::getTPL()->addHTMLHeaderFile("sign.js", "js"); Core::getTPL()->addHTMLHeaderFile("style.css", "css"); Core::getTPL()->assign("containerClass", "content"); Core::getTPL()->addLoop("headerMenu", self::getCMS()->getMenu("h")); $userCheck = sprintf(Core::getLanguage()->getItem("USER_CHECK"), Core::getOptions()->get("MIN_USER_CHARS"), Core::getOptions()->get("MAX_USER_CHARS")); $passwordCheck = sprintf(Core::getLanguage()->getItem("PASSWORD_CHECK"), Core::getOptions()->get("MIN_PASSWORD_LENGTH"), Core::getOptions()->get("MAX_PASSWORD_LENGTH")); Core::getTPL()->assign("userCheck", $userCheck); Core::getTPL()->assign("passwordCheck", $passwordCheck); Core::getTPL()->assign("uniSelection", self::getUnisAsOptionList()); Hook::event("CommTemplateAssign"); $this->dispatch(); Hook::event("CommEnd"); return $this; }
/** * @return bool */ protected function _match() { if ($this->getUser()->get("hp") == Core::getUser()->get("curplanet")) { return Game::getPlanet()->getData("planetname") != Core::getLang()->get("HOME_PLANET"); } $planet = Game::getModel("game/planet")->load($this->getUser()->get("hp")); return $planet->get("planetname") != Core::getLang()->get("HOME_PLANET"); }
/** * Sends a remote request. * * @param string $url Universe url * @param string $username Username * @param string $email E-Mail address * * @return Bengine_Comm_Controller_Password */ protected function _sendRemoteRequest($url, $username, $email) { $url .= Core::getLang()->getOpt("langcode") . "/password/request"; $request = new Recipe_HTTP_Request($url, "Curl"); $request->getSession()->setRequestType("POST")->setPostArgs(array("username" => $username, "email" => $email)); terminate($request->getResponse()); return $this; }
/** * Adds a language filter. * * @param integer Language id [optional] * * @return Bengine_Game_Model_Collection_News */ public function addLanguageFilter($langId = null) { if (is_null($langId)) { $langId = Core::getLang()->getOpt("languageid"); } $this->getSelect()->where(array("n" => "language_id"), (int) $langId); return $this; }
/** * Shows the pillory as Atom feed. * * @return Bengine_Comm_Controller_Pillory */ public function atomAction() { $this->assign("selfUrl", BASE_URL . "pillory/atom"); $this->assign("alternateUrl", BASE_URL . "pillory"); $this->assign("title", Core::getLang()->get("PILLORY")); Core::getTPL()->addLoop("feed", $this->getBans(0, self::MAX_FEED_ITEMS)); $this->setTemplate("atom"); return $this; }
/** * Formats the message for news feeds. * * @param Bengine_Game_Model_Message $message * * @return Bengine_Game_MessageFolder_Combat */ protected function _formatFeed(Bengine_Game_Model_Message $message) { $assaultId = (int) $message->get("message"); $assault = Application::getModel("game/assault")->load($assaultId); $link = BASE_URL . Core::getLang()->getOpt("langcode") . "/combat/report/" . $assaultId . "/" . $assault->get("key"); $gentime = $assault->get("gentime") / 1000; $text = Core::getLanguage()->getItem("ASSAULT_REPORT") . " (A: " . fNumber($assault->get("lostunits_attacker")) . ", D: " . fNumber($assault->get("lostunits_defender")) . ") " . $gentime . "s"; $subject = Core::getLang()->get($message->get("subject")) . ": " . $assault->get("planetname") . " [" . $assault->getCoords(false) . "]"; $message->set(array("message" => $text, "subject" => $subject, "link" => $link)); return $this; }
/** * Runs the community application. * * @return void */ public function run() { parent::run(); Core::getUser()->removeTheme(); Core::getTPL()->addHTMLHeaderFile("admin.css", "css"); Core::getLang()->load(array("AI_Global")); $menu = new Bengine_Admin_Menu(); Core::getTPL()->addLoop("menu", $menu->getMenu()); $this->dispatch(); return; }
/** * @return bool */ protected function _match() { Core::getLanguage()->load(array("Profile")); $userId = $this->getUser()->get("userid"); /* @var Bengine_Game_Model_Profile $avatar */ $avatar = Game::getModel("game/profile")->loadByCode("AVATAR", $userId); /* @var Bengine_Game_Model_Profile $about */ $about = Game::getModel("game/profile")->loadByCode("ABOUT_ME", $userId); if ($avatar->get("data") != "" && strip_tags($about->get("data")) != "" && $about->get("data") != Core::getLang()->get("DEFAULT_ABOUT_ME")) { return true; } return false; }
/** * @return Bengine_Admin_Controller_Cronjob */ protected function indexAction() { if ($this->getParam("add_cronjob")) { $this->add($this->getParam("month"), $this->getParam("day"), $this->getParam("weekday"), $this->getParam("hour"), $this->getParam("minute"), $this->getParam("class")); } $minute = ""; $hour = ""; $weekday = ""; $day = ""; $month = ""; $i = 0; while ($i < 60) { $minute .= createOption($i, $i, 0); $i += 5; } for ($i = 0; $i < 24; $i++) { $hour .= createOption($i, $i, 0); } $wds = array(1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat", 7 => "Sun"); for ($i = 1; $i <= 7; $i++) { $weekday .= createOption($i, $wds[$i], 0); } for ($i = 1; $i <= 31; $i++) { $day .= createOption($i, $i, 0); } for ($i = 1; $i <= 12; $i++) { $month .= createOption($i, $i, 0); } Core::getTPL()->assign("minute", $minute); Core::getTPL()->assign("hour", $hour); Core::getTPL()->assign("weekday", $weekday); Core::getTPL()->assign("day", $day); Core::getTPL()->assign("month", $month); $tabs = array(); $result = Core::getQuery()->select("cronjob", array("cronid", "class", "xtime", "last", "active"), "ORDER BY xtime ASC"); foreach ($result->fetchAll() as $row) { $id = $row["cronid"]; $tabs[$id]["cronid"] = $row["cronid"]; $tabs[$id]["class"] = $row["class"]; $tabs[$id]["xtime"] = empty($row["xtime"]) ? Core::getLang()->get("NEVER") : date("Y-m-d H:i:s", $row["xtime"]); $tabs[$id]["last"] = empty($row["last"]) ? Core::getLang()->get("NEVER") : date("Y-m-d H:i:s", $row["last"]); $tabs[$id]["delete"] = Link::get("admin/cronjob/delete/" . $id, Core::getLanguage()->getItem("Delete")); $tabs[$id]["exec"] = Link::get("admin/cronjob/execute/" . $id, Core::getLanguage()->getItem("Execute")); $tabs[$id]["edit"] = Link::get("admin/cronjob/edit/" . $id, Core::getLanguage()->getItem("Edit")); $tabs[$id]["active"] = $row["active"] ? Link::get("admin/cronjob/disable/" . $id, "<span class=\"green\">On</span>", Core::getLanguage()->getItem("Disable")) : Link::get("admin/cronjob/enable/" . $id, "<span class=\"red\">Off</span>", Core::getLanguage()->getItem("Enable")); } Core::getTPL()->addLoop("crontabs", $tabs); return $this; }
/** * @param Recipe_Database_Select $select * @param array $fields * @return Recipe_Model_Resource_Abstract */ public function addL10nOverlay(Recipe_Database_Select $select, array $fields) { $relTableName = current($this->getMainTable()) . "_l10n"; $primaryKey = $this->getPrimaryKey(); $tableAlias = key($this->getMainTable()); $on = "l10n.{$primaryKey} = {$tableAlias}.{$primaryKey} AND l10n.language_id = ?"; $on = $this->getDb()->quoteInto($on, Core::getLang()->getOpt("languageid")); $select->join(array("l10n" => $relTableName), $on); $attributes = array(); foreach ($fields as $field) { $expr = "IFNULL(l10n.{$field}, {$tableAlias}.{$field})"; $attributes[$field] = new Recipe_Database_Expr($expr); } $select->attributes(array("{$tableAlias}.*", "l10n" => $attributes)); return $this; }
/** * Show share button code. * * @return string */ public function onFrontHtmlEnd() { switch (Core::getRequest()->getGET("controller")) { case "combat": case "alliance": return '<div style="margin: 1em 3em 1em 0; text-align: right;"> <a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script><br/> <a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Teilen</a> <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script><br/> <g:plusone size="tall"></g:plusone> <script type="text/javascript">window.___gcfg={lang:"' . Core::getLang()->getOpt("code") . '"};(function(){var po=document.createElement("script");po.type="text/javascript";po.async=true;po.src="https://apis.google.com/js/plusone.js";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(po,s);})();</script> </div>'; break; } return null; }
/** * Sends the reminder mails. * * @return Bengine_Game_Cronjob_Reminder */ protected function sendReminders() { $time = TIME - Core::getConfig()->get("REMINDER_MAIL_TIME") * 86400; $select = new Recipe_Database_Select(); $select->from("user")->attributes(array("username", "email", "last"))->where("last < ?", $time); $result = $select->getStatement(); Core::getLang()->load(array("Registration")); foreach ($result->fetchAll() as $row) { Core::getLang()->assign("username", $row["username"]); Core::getLang()->assign("reminderLast", Date::timeToString(2, $row["last"])); $template = new Recipe_Email_Template("reminder"); $mail = new Email(array($row["email"] => $row["username"]), Core::getLang()->get("REMINDER_MAIL_SUBJECT")); $template->send($mail); } return $this; }
/** * Index action. * * @return Bengine_Game_Controller_Changelog */ protected function indexAction() { Core::getLang()->load("Main"); $meta = Game::getMeta(); define("BENGINE_REVISION", $meta["packages"]["bengine"]["game"]["revision"]); $ip = rawurlencode($_SERVER["SERVER_ADDR"]); $host = rawurlencode(HTTP_HOST); // Fetching changelog data from remote server $json = file_get_contents(VERSION_CHECK_PAGE . "?ip=" . $ip . "&host=" . $host . "&vers=" . Game::getVersion()); $data = json_decode($json, true); $latestVersion = $data["releases"][0]["versionNumber"]; $latestRevision = $data["releases"][0]["versionCode"]; Core::getTPL()->assign("latestVersion", $latestVersion); Core::getTPL()->assign("latestRevision", $latestRevision); Core::getTPL()->addLoop("releases", $data["releases"]); Core::getTPL()->assign("languageKey", Core::getLang()->getOpt("langcode")); return $this; }
/** * Starts the application. * * @return void */ public function run() { Hook::event("PreRun"); self::loadMeta(); Core::getTPL()->assign("charset", CHARACTER_SET); Core::getTPL()->assign("langcode", Core::getLang()->getOpt("langcode")); Core::getTPL()->assign("formaction", Core::getRequest()->getRequestedUrl()); $pageTitle = array(); if ($titlePrefix = Core::getConfig()->get("TITLE_PREFIX")) { $pageTitle[] = $titlePrefix; } $pageTitle[] = Core::getConfig()->get("pagetitle"); if ($titleSuffix = Core::getConfig()->get("TITLE_SUFFIX")) { $pageTitle[] = $titleSuffix; } Core::getTPL()->assign("pageTitle", implode(Core::getConfig()->get("TITLE_GLUE"), $pageTitle)); Hook::event("PostRun"); return; }
/** * @return Bengine_Game_Controller_Achievements */ public function indexAction() { Core::getLanguage()->load(array("Achievements")); /* @var Bengine_Game_Model_User $user */ $user = Application::getModel("game/user")->load(Core::getUser()->get("userid")); /* @var Bengine_Game_Model_Planet $planet */ $planet = Application::getModel("game/planet")->load(Core::getUser()->get("curplanet")); /* @var Bengine_Game_Model_Collection_Achievement $achievements */ $achievements = Application::getCollection("game/achievement"); $achievements->addUserJoin(Core::getUser()->get("userid"))->addDefaultSorting(); Core::getTemplate()->addLoop("achievements", $achievements); $unlocked = $achievements->checkForUnlockedAchievements($user, $planet); Core::getTemplate()->addLoop("unlocked", $unlocked); Core::getLanguage()->assign("leftXP", $user->getLeftXPForNextLevel()); Core::getLanguage()->assign("nextLevel", $user->get("level") + 1); Core::getTemplate()->assign("user", $user); Core::getLang()->assign("xp", $user->get("xp")); Core::getLang()->assign("level", $user->get("level")); return $this; }
/** * Index action. * * @return Bengine_Game_Controller_Constructions */ protected function indexAction() { Core::getLanguage()->load(array("info", "buildings")); $mode = self::BUILDING_CONSTRUCTION_TYPE; $moonType = Game::getPlanet()->getData("ismoon") ? self::MOON_CONSTRUCTION_TYPE : null; if (!Game::getPlanet()->planetFree()) { Logger::addMessage("PLANET_FULL", "info"); } $shipyardSize = Game::getEH()->getShipyardEvents()->getCalculatedSize(); Core::getTPL()->assign("shipyardSize", $shipyardSize); Core::getLang()->assign("maxFields", fNumber(Game::getPlanet()->getMaxFields())); Core::getLang()->assign("occupiedFields", Game::getPlanet()->getFields(true)); /* @var Bengine_Game_Model_Collection_Construction $collection */ $collection = Application::getCollection("game/construction"); $collection->addTypeFilter($mode, $moonType ? true : false, $moonType)->addPlanetJoin(Core::getUser()->get("curplanet"))->addDisplayOrder(); Core::getTPL()->addHTMLHeaderFile("lib/jquery.countdown.js", "js"); Hook::event("ConstructionsLoaded", array($collection)); Core::getTPL()->addLoop("constructions", $collection); Core::getTPL()->assign("event", $this->event); return $this; }
/** * @return Bengine_Admin_Controller_Commercial */ protected function indexAction() { if ($this->isPost()) { if ($this->getParam("add_ad")) { $this->addAd($this->getParam("name"), $this->getParam("position"), $this->getParam("max_views"), $this->getParam("enabled", 0), $this->getParam("html_code")); } else { if ($this->getParam("delete")) { $this->delete($this->getParam("ads")); } } } $ads = array(); $result = Core::getQuery()->select("ad", array("*")); foreach ($result->fetchAll() as $row) { $row["edit_link"] = Link::get("admin/commercial/edit/" . $row["ad_id"], Core::getLang()->get("Edit")); $row["reset_link"] = Link::get("admin/commercial/reset/" . $row["ad_id"], "Reset"); $ads[] = $row; } Core::getTPL()->addLoop("ads", $ads); return $this; }
/** * 添加/修改文章 */ public function save() { if (!empty($_POST['id']) && !ctype_digit($_POST['id'])) { $this->failure(Core::getLang('invalid_request')); } // 如果有文件上传 if ($_FILES['title_image']['error'] != UPLOAD_ERR_NO_FILE) { $options = array('type' => 'image', 'max_size' => 1024000, 'save_path' => IMG_PATH . 'article/', 'save_rule' => '##Ymd/'); $upload = new UploadFile($options); // 上传错误提示错误信息 if (!$upload->upload()) { $this->failure($upload->error()); } else { // 上传成功 获取上传文件信息 $_POST['title_image'] = $upload->fileList['title_image']['savename']; } } else { $_POST['title_image'] = ''; } $_POST['editor_uid'] = $_SESSION['uid']; $_POST['editor'] = $_SESSION['username']; $_POST['post_time'] = strtotime($_POST['post_time']); // if (!isset($_POST['brief'])) { // $_POST['brief'] = ''; // } // $_POST['content'] = ''; $mo = new Model_Article(); if ($mo->save($_POST)) { $this->success(Core::getLang('handle_success'), 'admin.php?a=article'); } else { if ($mo->msg) { $msg = $mo->msg; } else { $msg = Core::getLang('save_article_data_fail'); } $this->failure($msg); } }
/** * Handles lost password requests. * * @param string $username Entered username * @param string $email Entered email address * * @return Bengine_Game_Account_Password_Lost */ public function __construct($username, $email) { $this->username = $username; $this->email = $email; $mode = 1; if (!$this->getUsername()) { $mode = 0; } if (!checkEmail($this->getEmail())) { $this->printIt("EMAIL_INVALID"); } $result = Core::getQuery()->select("user", array("userid", "username"), "", Core::getDB()->quoteInto("email = ?", $this->getEmail())); if ($result->rowCount() <= 0) { $this->printIt("EMAIL_NOT_FOUND"); } $row = $result->fetchRow(); $result->closeCursor(); Core::getLanguage()->assign("username", $row["username"]); Core::getLanguage()->assign("ipaddress", IPADDRESS); Hook::event("LostPassword", array($this, &$row)); if ($mode == 0) { $this->message = new Recipe_Email_Template("lost_password_username"); } else { if (Str::compare($this->getUsername(), $row["username"])) { $reactivate = BASE_URL . Core::getLang()->getOpt("langcode") . "/signup/activation/key:" . $this->getSecurityKey(); $url = BASE_URL . Core::getLang()->getOpt("langcode") . "/password/set/key:" . $this->getSecurityKey() . "/user:"******"userid"]; Core::getTemplate()->assign("newPasswordUrl", $url); Core::getTemplate()->assign("reactivationUrl", $reactivate); $this->message = new Recipe_Email_Template("lost_password_password"); $this->setNewPw(); } else { $this->printIt("USERNAME_DOES_NOT_EXIST"); } } $this->sendMail($mode); return; }
/** * Bans an user. * * @param integer $ban * @param integer $timeEnd * @param string $reason * @param boolean $forceUmode * * @return Bengine_Game_Controller_Moderator */ protected function proceedBan($ban, $timeEnd, $reason, $forceUmode) { $to = TIME + $ban * $timeEnd; if ($to > 9999999999) { $to = 9999999999; } Hook::event("BanUser", array(&$to, $reason, $forceUmode)); $spec = array("userid" => $this->userid, "from" => TIME, "to" => $to, "reason" => $reason, "modid" => Core::getUser()->get("userid")); Core::getQuery()->insert("ban_u", $spec); if ($forceUmode) { Core::getQuery()->update("user", array("umode" => 1), "userid = ?", array($this->userid)); setProdOfUser($this->userid, 0); } Core::getQuery()->update("sessions", array("logged" => 0), "userid = ?", array($this->userid)); $user = Game::getModel("game/user")->load($this->userid); Core::getTemplate()->assign("banReason", $reason); Core::getLang()->assign("banDate", Date::timeToString(1, $to, "", 0)); Core::getLang()->assign("username", $user->get("username")); $template = new Recipe_Email_Template("ban_notification"); $mail = new Email(array($user->get("email") => $user->get("username")), Core::getLanguage()->getItem("BAN_NOTIFICATION_MAIL_SUBJECT")); $template->send($mail); return $this; }
/** * Changes the ships against resources. * * @return Bengine_Game_Controller_Shipyard */ protected function changeAction() { if (!Core::getConfig()->get("SCRAP_MERCHANT_RATE")) { $this->redirect("game/" . SID . "/Shipyard"); } Core::getLanguage()->load(array("info", "buildings")); $selUnits = Core::getRequest()->getPOST("unit"); /* @var Bengine_Game_Model_Collection_Fleet $availUnits */ $availUnits = Application::getCollection("game/fleet", "game/unit"); $availUnits->addPlanetFilter(Core::getUser()->get("curplanet")); $metalCredit = 0; $siliconCredit = 0; $hydrogenCredit = 0; $totalQty = 0; $realUnits = array(); $rate = (double) Core::getConfig()->get("SCRAP_MERCHANT_RATE"); /* @var Bengine_Game_Model_Unit $unit */ foreach ($availUnits as $unit) { $unitId = $unit->getUnitid(); if (isset($selUnits[$unitId]) && $selUnits[$unitId] > 0) { $qty = _pos((int) $selUnits[$unitId]); $qty = min($qty, $unit->getQty()); $metalCredit += $qty * $unit->get("basic_metal"); $siliconCredit += $qty * $unit->get("basic_silicon"); $hydrogenCredit += $qty * $unit->get("basic_hydrogen"); $totalQty += $qty; $realUnits[(int) $unitId] = $qty; } } $points = ($metalCredit + $siliconCredit + $hydrogenCredit) / 1000; $metalCredit = floor($metalCredit * $rate); $siliconCredit = floor($siliconCredit * $rate); $hydrogenCredit = floor($hydrogenCredit * $rate); Core::getLang()->assign(array("metalCredit" => fNumber($metalCredit), "siliconCredit" => fNumber($siliconCredit), "hydrogenCredit" => fNumber($hydrogenCredit), "totalQty" => fNumber($totalQty))); if (Core::getRequest()->getPOST("verify") == "yes") { /* @var Bengine_Game_Model_Unit $unit */ foreach ($availUnits as $unit) { $unitId = (int) $unit->getUnitid(); if (isset($realUnits[$unitId])) { $qty = $realUnits[$unitId]; if ($unit->getQty() <= $qty) { Core::getQuery()->delete("unit2shipyard", "`unitid` = ? AND `planetid` = ?", null, null, array($unitId, Core::getUser()->get("curplanet"))); } else { $sql = "UPDATE `" . PREFIX . "unit2shipyard` SET `quantity` = `quantity` - ? WHERE `unitid` = ? AND `planetid` = ?"; Core::getDatabase()->query($sql, array($qty, $unitId, Core::getUser()->get("curplanet"))); } } } $sql = "UPDATE `" . PREFIX . "planet` SET `metal` = `metal` + ?, `silicon` = `silicon` + ?, `hydrogen` = `hydrogen` + ? WHERE `planetid` = ?"; Core::getDatabase()->query($sql, array($metalCredit, $siliconCredit, $hydrogenCredit, Core::getUser()->get("curplanet"))); $sql = "UPDATE `" . PREFIX . "user` SET `points` = `points` - ? WHERE `userid` = ?"; Core::getDatabase()->query($sql, array($points, Core::getUser()->get("userid"))); $this->redirect("game/" . SID . "/Shipyard"); } $this->setTemplate("shipyard/change"); $this->assign("units", $realUnits); return $this; }
/** * Index action. * * @return Bengine_Game_Controller_Index */ protected function indexAction() { Core::getTPL()->addHTMLHeaderFile("lib/jquery.countdown.js", "js"); Core::getTPL()->addHTMLHeaderFile("lib/jquery.news.js", "js"); $this->buildingEvent = Game::getEH()->getCurPlanetBuildingEvent(); // Messages $result = Core::getQuery()->select("message", "msgid", "", Core::getDB()->quoteInto("`receiver` = ? AND `read` = '0'", Core::getUser()->get("userid"))); $msgs = $result->rowCount(); $result->closeCursor(); Core::getTPL()->assign("unreadmsg", $msgs); if ($msgs == 1) { Core::getTPL()->assign("newMessages", Link::get("game/" . SID . "/MSG", Core::getLanguage()->getItem("F_NEW_MESSAGE"))); } else { if ($msgs > 1) { Core::getTPL()->assign("newMessages", Link::get("game/" . SID . "/MSG", sprintf(Core::getLanguage()->getItem("F_NEW_MESSAGES"), $msgs))); } } // Fleet events $fleetEvent = Game::getEH()->getFleetEvents(); $fe = array(); if ($fleetEvent) { foreach ($fleetEvent as $f) { $fe[$f["eventid"]] = $this->parseEvent($f); if (!is_array($fe[$f["eventid"]])) { unset($fe[$f["eventid"]]); } } Hook::event("MainFleetEventsOutput", array(&$fe)); } Core::getTPL()->addLoop("fleetEvents", $fe); Core::getTPL()->assign("serverTime", Date::timeToString(1, TIME, "", false)); Core::getTPL()->assign("buildingEvent", $this->buildingEvent); Core::getTPL()->assign("occupiedFields", Game::getPlanet()->getFields(true)); Core::getTPL()->assign("planetImage", Image::getImage("planets/" . Game::getPlanet()->getData("picture") . Core::getConfig()->get("PLANET_IMG_EXT"), Game::getPlanet()->getData("planetname"), "200px", "200px")); Core::getTPL()->assign("freeFields", Game::getPlanet()->getMaxFields()); Core::getTPL()->assign("planetDiameter", fNumber(Game::getPlanet()->getData("diameter"))); Core::getTPL()->assign("planetNameLink", Link::get("game/" . SID . "/Index/PlanetOptions", Game::getPlanet()->getData("planetname"))); Core::getTPL()->assign("planetPosition", Game::getPlanet()->getCoords()); Core::getTPL()->assign("planetTemp", Game::getPlanet()->getData("temperature")); Core::getTPL()->assign("points", Link::get("game/" . SID . "/Ranking", fNumber(floor(Core::getUser()->get("points"))))); // Points $result = Core::getQuery()->select("user", "userid"); Core::getLang()->assign("totalUsers", fNumber($result->rowCount())); $result->closeCursor(); $where = Core::getDB()->quoteInto("(`username` < ? AND `points` >= {points}) OR `points` > {points}", array(Core::getUser()->get("username"))); $where = str_replace("{points}", (double) Core::getUser()->get("points"), $where); $result = Core::getQuery()->select("user", array("COUNT(`userid`)+1 AS rank"), "", $where, "", 1); Core::getLang()->assign("rank", fNumber($result->fetchColumn())); $result->closeCursor(); if (Game::getPlanet()->getData("moonid") > 0) { if (Game::getPlanet()->getData("ismoon")) { // Planet has moon $where = Core::getDB()->quoteInto("g.galaxy = ? AND g.system = ? AND g.position = ?", array(Game::getPlanet()->getData("moongala"), Game::getPlanet()->getData("moonsys"), Game::getPlanet()->getData("moonpos"))); $result = Core::getQuery()->select("galaxy g", array("p.planetid", "p.planetname", "p.picture"), "LEFT JOIN " . PREFIX . "planet p ON (p.planetid = g.planetid)", $where); } else { // Planet of current moon $where = Core::getDB()->quoteInto("g.galaxy = ? AND g.system = ? AND g.position = ?", array(Game::getPlanet()->getData("galaxy"), Game::getPlanet()->getData("system"), Game::getPlanet()->getData("position"))); $result = Core::getQuery()->select("galaxy g", array("p.planetid", "p.planetname", "p.picture"), "LEFT JOIN " . PREFIX . "planet p ON (p.planetid = g.moonid)", $where); } $row = $result->fetchRow(); $result->closeCursor(); Core::getTPL()->assign("moon", $row["planetname"]); $img = Image::getImage("planets/" . $row["picture"] . Core::getConfig()->get("PLANET_IMG_EXT"), $row["planetname"], 50, 50); Core::getTPL()->assign("moonImage", "<a title=\"" . $row["planetname"] . "\" class=\"goto pointer\" href=\"" . $row["planetid"] . "\">" . $img . "</a>"); } else { Core::getTPL()->assign("moon", ""); Core::getTPL()->assign("moonImage", ""); } // Current events $research = Game::getEH()->getResearchEvent(); Core::getTPL()->assign("research", $research); $shipyardMissions = Game::getEH()->getShipyardEvents(); Core::getTemplate()->assign("shipyardMissions", $shipyardMissions); /* @var Bengine_Game_Model_Collection_News $news */ $news = Game::getCollection("game/news"); $news->addSortIndexOrder()->addEnabledFilter()->addLanguageFilter(); Core::getTPL()->addLoop("news", $news); Hook::event("GameIndexAction"); return $this; }
/** * Creates a new CMS object. * * @return \Bengine_Comm_CMS */ public function __construct() { $this->langid = Core::getLang()->getOpt("languageid"); $this->loadMenuItems(); return; }
/** * 字段值验证 * @param string $value * @param string $field * @param array|string $rule */ public function validate($value, $field, $rule) { if (is_string($rule)) { $ruleName = $rule; } else { $ruleName = $rule[0]; } if (is_array($rule) && isset($rule[1])) { $msg = $rule[1]; } switch ($ruleName) { case 'require': if (is_null($value) || $value == '') { $replacement = array('{field}' => $field); if (!isset($msg)) { $msg = 'field_is_required'; } $this->msg = Core::getLang($msg, $replacement); return false; } break; default: if (method_exists($this, $ruleName)) { $ret = call_user_func_array(array($this, $ruleName), array($value)); if (!$ret) { return false; } } else { if (function_exists($ruleName)) { $ret = call_user_func($ruleName, $value); if (!$ret) { $replacement = array('{field}' => $field, '{value}' => $value); if (!isset($msg)) { $msg = 'field_invalid'; } $this->msg = Core::getLang($msg, $replacement); return false; } } } break; } return true; }