Пример #1
0
 /**
  * Use current dataprovider to perform seacrh
  * by given query and return view with results.
  * 
  * @return View
  */
 public function byQuery()
 {
     $input = (string) Input::get('q');
     if (!$input || Str::length($input) <= 1) {
         return View::make('search.results')->withTerm('');
     }
     if (is_a($this->search, 'Lib\\Services\\Search\\DbSearch')) {
         $encoded = $input;
     } else {
         $encoded = urlencode($input);
     }
     $clean = e($input);
     //make search cache section name
     $section = 'search' . $this->provider;
     if ($encoded) {
         if (Helpers::hasSuperAccess()) {
             $results = $this->search->byQuery($encoded);
         } else {
             if ($this->options->useCache()) {
                 $results = $this->cache->get($section, md5($encoded));
                 if (!$results || count($results) == 0) {
                     $results = $this->search->byQuery($encoded);
                     $this->cache->put($section, md5($encoded), $results);
                 }
             } else {
                 $results = $this->search->byQuery($encoded);
             }
         }
         return View::make('search.results')->withData($results)->withTerm($clean);
     }
     return View::make('search.results')->withTerm($clean);
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 public function action_main($params = array())
 {
     $config = $this->config;
     $gConfig = \Config::load('novius_social_widget::config', true);
     if (Arr::get($gConfig, 'embed_js', true)) {
         if (!empty($config['js'])) {
             foreach ($config['js'] as $script) {
                 Nos::main_controller()->addJavascript($script);
             }
         }
     }
     $chrome = array();
     $typeList = array('chrome');
     foreach ($params as $param => $value) {
         if ($value) {
             foreach ($typeList as $type) {
                 $typePrefix = "{$type}-";
                 if ($value && \Str::starts_with($param, $typePrefix)) {
                     array_push(${$type}, \Str::sub($param, \Str::length($typePrefix)));
                 }
             }
         }
     }
     return \View::forge('novius_social_widget::front/enhancer/twitter', array('widgetId' => $params['widget-id'], 'chrome' => $chrome, 'limit' => \Arr::get($params, 'limit'), 'width' => \Arr::get($params, 'width'), 'height' => \Arr::get($params, 'height')), false);
 }
Пример #4
0
 /**
  * Validate the data.
  *
  * @return boolean
  */
 public function validate()
 {
     if ($this->getData() != "" && !filter_var($this->getData(), FILTER_VALIDATE_URL) || Str::length($this->getData()) > $this->getSetup("max_length", 255)) {
         $this->addError("INVALID_URL");
         return false;
     }
     return true;
 }
Пример #5
0
 /**
  * Remove all elements with no content.
  *
  * @param array $array	Array to be cleaned
  *
  * @return array		Cleaned array
  */
 public static function clean($array)
 {
     $rArray = array();
     for ($i = 0; $i < count($array); $i++) {
         if (Str::length($array[$i]) > 0) {
             $rArray[$i] = $array[$i];
         }
     }
     return $rArray;
 }
Пример #6
0
 /**
  * Sets the destination folder.
  *
  * @param string $destination
  * @throws Recipe_Exception_Generic
  * @return Recipe_Language_Exporter
  */
 public function setDestination($destination)
 {
     if (!is_dir($destination) || !is_writable($destination)) {
         throw new Recipe_Exception_Generic("Export destination folder does not exist or is not writable.");
     }
     if (Str::substring($destination, 0, Str::length($destination) - 1) != "/") {
         $destination .= "/";
     }
     $this->destination = $destination;
     return $this;
 }
 public function store()
 {
     $pass = false;
     $inputs = Input::all();
     if (!array_key_exists('pregunta_1', $inputs) or !array_key_exists('pregunta_2', $inputs) or !array_key_exists('pregunta_3', $inputs) or !array_key_exists('pregunta_4', $inputs)) {
         echo $errors = 'Debe contestar todas las preguntas';
         return Redirect::back()->withErrors($errors)->withInput();
     } else {
         foreach ($inputs as $key => $value) {
             if ($key != '_token') {
                 if (array_get($value, 'value', '') == '') {
                     echo $errors = 'Debe contestar todas las preguntas';
                     return Redirect::back()->withErrors($errors)->withInput();
                 }
             }
         }
     }
     $cr = new ClientesRespuesta();
     $cr->id_cliente = Auth::user()->id_cliente;
     $cr->ultima_respuesta = Carbon::now();
     $cr->id_estado = 15;
     if ($cr->save()) {
         $cli_resp = $cr->id_cliente_respuesta;
     } else {
         Event::fire('form_error');
     }
     if (!is_null($cli_resp)) {
         $respuesta_detalle = array();
         foreach ($inputs as $key => $value) {
             if ($key != '_token') {
                 $respuesta = Respuesta::insertGetId(array('fecha' => Carbon::now(), 'id_estado' => '6', 'id_canal' => Session::get('canal'), 'id_encuesta' => Session::get('encuesta', 1), 'id_pregunta' => (int) str_replace('pregunta_', '', $key), 'id_pregunta_detalle' => 1, 'id_cliente' => Auth::user()->id_cliente, 'id_cliente_respuesta' => $cli_resp, 'created_at' => Carbon::now()));
                 if (!is_null($respuesta)) {
                     $val = array_get($value, 'value');
                     $text = array_get($value, 'text');
                     array_push($respuesta_detalle, array('valor1' => trim($val) != '' ? $val : null, 'valor2' => trim($text) != '' && Str::length($text) > 0 ? $text : null, 'id_respuesta' => $respuesta, 'created_at' => Carbon::now()));
                 } else {
                     Event::fire('form_error');
                 }
             }
         }
     }
     unset($resp_d);
     unset($resp);
     unset($inputs);
     if (RespuestasDetalle::insert($respuesta_detalle)) {
         Session::flush();
         $msg = array('data' => array('type' => 'success', 'text' => '<i class="fa fa-check fa-fw"></i>Gracias por tu tiempo y disponibilidad en responder, ¡Tu opinión es muy importante!'));
         $script = "setTimeout('window.location.href=\"http://www.umayor.cl/\";', 5000); if (typeof window.event == 'undefined'){ document.onkeypress = function(e){ var test_var=e.target.nodeName.toUpperCase(); if (e.target.type) var test_type=e.target.type.toUpperCase(); if ((test_var == 'INPUT' && test_type == 'TEXT') || test_var == 'TEXTAREA'){ return e.keyCode; }else if (e.keyCode == 8 || e.keyCode == 116 || e.keyCode == 122){ e.preventDefault(); } } }else{ document.onkeydown = function(){ var test_var=event.srcElement.tagName.toUpperCase(); if (event.srcElement.type) var test_type=event.srcElement.type.toUpperCase(); if ((test_var == 'INPUT' && test_type == 'TEXT') || test_var == 'TEXTAREA'){ return event.keyCode; } else if (event.keyCode == 8 || e.keyCode == 116 || e.keyCode == 122){ event.returnValue=false; } } } ";
         return View::make('messages', compact('msg', 'script'));
     } else {
         Event::fire('form_error');
     }
 }
Пример #8
0
 /**
  * Validate the data.
  *
  * @return boolean
  */
 public function validate()
 {
     $text = $this->getData();
     if (Str::length(trim(str_replace("&nbsp;", "", strip_tags($text)))) > 0) {
         if ($this->getSetup("max_length", 10000) < Str::length($text)) {
             $this->addError("TEXT_TOO_LARGE");
             return false;
         }
         $this->setData(richText($text));
     } else {
         $this->setData("");
     }
     return true;
 }
Пример #9
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;
 }
Пример #10
0
 /**
  * Post method to process the form
  **/
 public function postNew()
 {
     //first, let's validate the form
     $validation = Validator::make(Input::all(), Question::$add_rules);
     if ($validation->passes()) {
         //First, let's create the question
         $create = Question::create(array('userID' => Sentry::getUser()->id, 'title' => Input::get('title'), 'question' => Input::get('question')));
         //We get the insert id of the question
         $insert_id = $create->id;
         //Now, we need to re-find the question to "attach" the tag to the question
         $question = Question::find($insert_id);
         //Now, we should check if tags column is filled, and split the string and add a new tag and a relation
         if (Str::length(Input::get('tags'))) {
             //let's explode all tags from the comma
             $tags_array = explode(',', Input::get('tags'));
             //if there are any tags, we will check if they are new, if so, we will add them to database
             //After checking the tags, we will have to "attach" tag(s) to the new question
             if (count($tags_array)) {
                 foreach ($tags_array as $tag) {
                     //first, let's trim and get rid of the extra space bars between commas
                     //(tag1, tag2, vs tag1,tag2)
                     $tag = trim($tag);
                     //We should double check its length, because the user may have just typed "tag1,,tag2" (two or more commas) accidentally
                     //We check the slugged version of the tag, because tag string may only be meaningless character(s), like "tag1,+++//,tag2"
                     if (Str::length(Str::slug($tag))) {
                         //the URL-Friendly version of the tag
                         $tag_friendly = Str::slug($tag);
                         //Now let's check if there is a tag with the url friendly version of the provided tag already in our database:
                         $tag_check = Tag::where('tagFriendly', $tag_friendly);
                         //if the tag is a new tag, then we will create a new one
                         if ($tag_check->count() == 0) {
                             $tag_info = Tag::create(array('tag' => $tag, 'tagFriendly' => $tag_friendly));
                             //If the tag is not new, this means There was a tag previously added on the same name to another question previously
                             //We still need to get that tag's info from our database
                         } else {
                             $tag_info = $tag_check->first();
                         }
                     }
                     //Now the attaching the current tag to the question
                     $question->tags()->attach($tag_info->id);
                 }
             }
         }
         //lastly, we should return the user to the asking page with a permalink of the question
         return Redirect::route('ask')->with('success', 'Your question has been created successfully! ' . HTML::linkRoute('question_details', 'Click here to see your question', array('id' => $insert_id, 'title' => Str::slug($question->title))));
     } else {
         return Redirect::route('ask')->withInput()->with('error', $validation->errors()->first());
     }
 }
Пример #11
0
 protected function size($attribute, $value)
 {
     // This method will determine if the attribute is a number, string, or file and
     // return the proper size accordingly. If it is a number, the number itself is
     // the size; if it is a file, the kilobytes is the size; if it is a
     // string, the length is the size.
     if (is_numeric($value) and $this->has_rule($attribute, $this->numeric_rules)) {
         return $this->attributes[$attribute];
     } elseif (array_key_exists($attribute, Input::file())) {
         $key = array_search(max($value['size']), $value['size']);
         return $value['size'][$key] / 1024;
     } else {
         return Str::length(trim($value));
     }
 }
Пример #12
0
 /**
  * @param string|array $variable
  * @param mixed $value
  * @return \Recipe_Template_Adapter_Standard
  */
 public function assign($variable, $value = null)
 {
     if (is_array($variable)) {
         foreach ($variable as $key => $val) {
             if (Str::length($key) > 0) {
                 $this->assign($key, $val);
             }
         }
     } else {
         if (is_string($variable) || is_numeric($variable)) {
             if (Str::length($variable) > 0) {
                 $this->_data[$variable] = $value;
             }
         }
     }
     return $this;
 }
Пример #13
0
 /**
  * Generate image tag in HTML.
  *
  * @param string $url		Image URL
  * @param string $title		Additional title
  * @param integer $width	Image width
  * @param integer $height	Image height
  * @param string $cssClass	Additional CSS class designation
  *
  * @return string			Image tag
  */
 public static function getImage($url, $title, $width = null, $height = null, $cssClass = "")
 {
     $isExternal = Link::isExternal($url);
     if (Core::getUser()->get("theme") != "" && !$isExternal) {
         $url = Core::getUser()->get("theme") . "img/" . $url;
     }
     if (!$isExternal) {
         $url = BASE_URL . "img/" . $url;
     } else {
         $url = BASE_URL . "img/remote.php?file=" . $url;
     }
     if (Str::length($cssClass) == 0) {
         $cssClass = self::IMAGE_CSS_CLASS;
     }
     $width = !is_null($width) ? " width=\"" . $width . "\"" : "";
     $height = !is_null($height) ? " height=\"" . $height . "\"" : "";
     $img = "<img src=\"" . $url . "\" title=\"" . $title . "\" alt=\"" . $title . "\"" . $width . $height . " class=\"" . $cssClass . "\" />";
     return $img;
 }
Пример #14
0
 /**
  * @return Bengine_Admin_Controller_Globalmail
  */
 protected function send()
 {
     $subject = Str::validateXHTML($this->getParam("subject"));
     $message = richtext(nl2br($this->getParam("message")));
     if (Str::length($message) < 10) {
         Core::getTPL()->assign("messageError", Logger::getMessageField("MESSAGE_TOO_SHORT"));
         $error = true;
     }
     if (Str::length($subject) == 0) {
         Core::getTPL()->assign("subjectError", Logger::getMessageField("SUBJECT_TOO_SHORT"));
         $error = true;
     }
     if (!empty($error)) {
         return $this;
     }
     $sql = "INSERT INTO `" . PREFIX . "message` (`mode`, `time`, `sender`, `receiver`, `subject`, `message`, `read`) SELECT ?, ?, NULL, " . PREFIX . "user.userid, ?, ?, ? FROM " . PREFIX . "user";
     Core::getDB()->query($sql, array(1, TIME, $subject, $message, 0));
     return $this;
 }
Пример #15
0
 /**
  * Set required data for link.
  *
  * @param string $url				URL to link
  * @param string $name				Link name
  * @param string $title				Additional title
  * @param string $cssClass			Particular css class
  * @param string $attachment		Additional attachment for link
  * @param boolean $appendSession	Append session id to url
  * @param boolean $rewrite			Activate URL rewrite
  * @param boolean $refDir			Refer external URLs to "refdir"
  *
  * @return string	HTML link
  */
 public static function get($url, $name, $title = "", $cssClass = "", $attachment = "", $appendSession = false, $rewrite = true, $refDir = true)
 {
     if (Str::length($cssClass) <= 0) {
         if (self::isExternal($url)) {
             $cssClass = self::CSS_EXTERNAL_URL;
         } else {
             $cssClass = self::CSS_NORMAL_URL;
         }
     }
     if (Str::length($attachment) > 0) {
         $attachment = " " . $attachment;
     }
     if (self::isExternal($url) && $refDir) {
         $link = "<a href=\"" . BASE_URL . "refdir.php?url=" . $url . "\" title=\"" . $title . "\" class=\"" . $cssClass . "\"" . $attachment . ">" . $name . "</a>";
     } else {
         $url = self::url($url, $appendSession);
         $link = "<a href=\"" . $url . "\" title=\"" . $title . "\" class=\"" . $cssClass . "\"" . $attachment . ">" . $name . "</a>";
     }
     return $link;
 }
Пример #16
0
 /**
  * Key check and set new password.
  *
  * @param integer $userid
  * @param string $key Key, transmitted by email
  * @param string $newpw New password
  *
  * @return Bengine_Game_Account_Password_Changer
  */
 public function __construct($userid, $key, $newpw)
 {
     Hook::event("ChangePassword", array($userid, $key));
     if (empty($key) || Str::length($newpw) < Core::getOptions()->get("MIN_PASSWORD_LENGTH") || Str::length($newpw) > Core::getOptions()->get("MAX_PASSWORD_LENGTH")) {
         $this->printIt("PASSWORD_INVALID");
     }
     $where = Core::getDB()->quoteInto("userid = ? AND ", $userid);
     $where .= Core::getDB()->quoteInto("activation = ?", $key);
     $result = Core::getQuery()->select("user", "userid", "", $where);
     if ($result->rowCount()) {
         $result->closeCursor();
         $encryption = Core::getOptions("USE_PASSWORD_SALT") ? "md5_salt" : "md5";
         $newpw = Str::encode($newpw, $encryption);
         Core::getQuery()->update("password", array("password" => $newpw, "time" => TIME), "userid = ?", array($userid));
         Core::getQuery()->update("user", array("activation" => ""), "userid = ?", array($userid));
         $this->printIt("PASSWORD_CHANGED", false);
     }
     $result->closeCursor();
     $this->printIt("ERROR_PASSWORD_CHANGED");
     return;
 }
Пример #17
0
 /**
  * Use current dataprovider to perform seacrh
  * by given query and return view with results.
  * 
  * @return View
  */
 public function byQuery()
 {
     $query = (string) Input::get('q');
     if (!$query || Str::length($query) <= 1) {
         return View::make('Search.Results')->withTerm('');
     }
     //don't encode the query if we will search our db as that will
     //cause problems
     if (is_a($this->search, 'Lib\\Services\\Search\\DbSearch')) {
         $encoded = $query;
     } else {
         $encoded = urlencode($query);
     }
     if (!Cache::tags('search')->has($this->provider . 'search' . $encoded)) {
         $results = $this->search->byQuery($encoded);
         Cache::tags('search')->put($this->provider . 'search' . $encoded, $results, 8640);
     } else {
         $results = Cache::tags('search')->get($this->provider . 'search' . $encoded);
     }
     return View::make('Search.Results')->withData($results)->withTerm(e($query));
 }
Пример #18
0
 /**
  * Check input data.
  *
  * @return Bengine_Game_Login
  */
 public function checkData()
 {
     $this->dataChecked = true;
     $select = array("u.userid", "u.username", "p.password", "u.activation", "b.banid", "b.reason", "u.umode");
     $joins = "LEFT JOIN " . PREFIX . "password p ON (u.userid = p.userid)";
     $joins .= "LEFT JOIN " . PREFIX . "ban_u b ON (b.userid = u.userid AND b.to > '" . TIME . "')";
     $result = Core::getQuery()->select("user u", $select, $joins, Core::getDB()->quoteInto("u.username = ?", $this->usr), "b.to DESC");
     if ($row = $result->fetchRow()) {
         $result->closeCursor();
         if (Str::compare($row["username"], $this->usr) && Str::compare($row["password"], $this->pw) && Str::length($row["activation"]) == 0 && !$row["banid"]) {
             $this->userid = $row["userid"];
             Core::getQuery()->delete("loginattempts", "ip = ? OR username = ?", null, null, array(IPADDRESS, $this->usr));
             Core::getQuery()->update("sessions", array("logged" => "0"), "userid = ?", array($this->userid));
             if ($row["umode"]) {
                 Core::getQuery()->update("planet", array("last" => TIME), "userid = ?", array($row["userid"]));
             }
             $this->canLogin = true;
         } else {
             $this->canLogin = false;
             if (!Str::compare($row["username"], $this->usr)) {
                 $this->loginFailed("USERNAME_DOES_NOT_EXIST");
             }
             if (Str::length($row["activation"]) > 0) {
                 $this->loginFailed("NO_ACTIVATION");
             }
             if ($row["banid"]) {
                 Core::getLanguage()->load(array("Prefs"));
                 Core::getLanguage()->assign("banReason", empty($row["reason"]) ? Core::getLanguage()->get("NO_BAN_REASON") : $row["reason"]);
                 Core::getLanguage()->assign("pilloryLink", Link::get(Core::getLanguage()->getOpt("langcode") . "/pillory", Core::getLanguage()->get("PILLORY")));
                 $this->loginFailed("ACCOUNT_BANNED");
             }
             $this->loginFailed("PASSWORD_INVALID");
         }
     } else {
         $result->closeCursor();
         $this->canLogin = false;
         $this->loginFailed("USERNAME_DOES_NOT_EXIST");
     }
     return $this;
 }
Пример #19
0
 /**
  * Validate password
  *
  * @param string $val password
  * @return boolean
  *
  * @access public
  * @author Dao Anh Minh
  */
 public static function _validation_password($val)
 {
     Validation::active()->set_message('password', 'Mật khẩu phải bao gồm: ký tự đặc biệt, chữ thường, chữ hoa, số');
     if (empty($val)) {
         return true;
     }
     //check all 1 byte character
     if (Str::length($val) != strlen($val)) {
         return false;
     }
     return (bool) preg_match('/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[\\!\\"\\#\\$\\%\\&\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\]\\^\\_\\`\\{\\|\\}\\~]).{8,}$/', $val);
 }
 /**
  * Remove the PKCS7 compatible padding from the given value.
  *
  * @param  string  $value
  * @return string
  */
 protected static function unpad($value)
 {
     $pad = ord($value[($length = Str::length($value)) - 1]);
     if ($pad and $pad < static::$block) {
         // If the correct padding is present on the string, we will remove
         // it and return the value. Otherwise, we'll throw an exception
         // as the padding appears to have been changed.
         if (preg_match('/' . chr($pad) . '{' . $pad . '}$/', $value)) {
             return substr($value, 0, $length - $pad);
         } else {
             throw new \Exception("Decryption error. Padding is invalid.");
         }
     }
     return $value;
 }
Пример #21
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;
 }
Пример #22
0
 protected function max($input, $value, $param)
 {
     return Str::length($value) < $param ? true : $this->log_error($input, "{$input} must be {$param} characters or more!", 'max');
 }
Пример #23
0
 /**
  * Allows the user to write a global mail to all alliance member.
  *
  * @param string $reply
  * @return Bengine_Game_Controller_Alliance
  */
 protected function globalMailAction($reply)
 {
     $result = Core::getQuery()->select("user2ally u2a", array("a.founder", "ar.CAN_WRITE_GLOBAL_MAILS"), "LEFT JOIN " . PREFIX . "alliance a ON (a.aid = u2a.aid) LEFT JOIN " . PREFIX . "allyrank ar ON (ar.rankid = u2a.rank)", Core::getDB()->quoteInto("u2a.userid = ?", Core::getUser()->get("userid")));
     if ($row = $result->fetchRow()) {
         $result->closeCursor();
         if ($row["CAN_WRITE_GLOBAL_MAILS"] || $row["founder"] == Core::getUser()->get("userid")) {
             Core::getLanguage()->load("Message");
             if ($this->isPost()) {
                 $message = richtext($this->getParam("message"));
                 $length = Str::length(strip_tags($message));
                 $subject = Str::validateXHTML(trim($this->getParam("subject")));
                 $receiver = $this->getParam("receiver");
                 if ($length > 2 && $length <= Core::getOptions()->get("MAX_PM_LENGTH") && Str::length($subject) > 0 && Str::length($subject) < 101) {
                     Hook::event("SendGlobalMail", array($subject, &$message));
                     if ($receiver == "foo") {
                         $where = Core::getDB()->quoteInto("aid = ?", $this->aid);
                     } else {
                         $where = Core::getDB()->quoteInto("rank = ? AND aid = ?", array($receiver, $this->aid));
                     }
                     $_result = Core::getQuery()->select("user2ally", "userid", "", $where);
                     foreach ($_result->fetchAll() as $_row) {
                         Core::getQuery()->insert("message", array("mode" => 6, "time" => TIME, "sender" => Core::getUser()->get("userid"), "receiver" => $_row["userid"], "message" => $message, "subject" => $subject, "read" => $_row["userid"] == Core::getUser()->get("userid") ? 1 : 0));
                     }
                     $_result->closeCursor();
                     Logger::addMessage("SENT_SUCCESSFUL", "success");
                 } else {
                     if ($length < 3) {
                         Core::getTPL()->assign("messageError", Logger::getMessageField("MESSAGE_TOO_SHORT"));
                     }
                     if ($length > Core::getOptions()->get("MAX_PM_LENGTH")) {
                         Core::getTPL()->assign("messageError", Logger::getMessageField("MESSAGE_TOO_LONG"));
                     }
                     if (Str::length($subject) == 0) {
                         Core::getTPL()->assign("subjectError", Logger::getMessageField("SUBJECT_TOO_SHORT"));
                     }
                     if (Str::length($subject) > 100) {
                         Core::getTPL()->assign("subjectError", Logger::getMessageField("SUBJECT_TOO_LONG"));
                     }
                     Core::getTPL()->assign("subject", $this->getParam("subject"))->assign("message", $this->getParam("message"));
                 }
             } else {
                 if ($reply) {
                     $reply = preg_replace("#((RE|FW):\\s)+#is", "\\1", $reply);
                     Core::getTPL()->assign("subject", $reply);
                 }
             }
             $ranks = Core::getQuery()->select("allyrank", array("rankid", "name"), "", Core::getDB()->quoteInto("aid = ?", $this->aid));
             Core::getTPL()->assign("maxpmlength", fNumber(Core::getOptions()->get("MAX_PM_LENGTH")));
             Core::getTPL()->addLoop("ranks", $ranks);
         } else {
             Logger::dieMessage("MISSING_RIGHTS_FOR_GLOBAL_MAIL", "warning");
         }
     } else {
         Logger::dieMessage("MISSING_RIGHTS_FOR_GLOBAL_MAIL", "warning");
     }
     return $this;
 }
Пример #24
0
 /**
  * Saves the construction data.
  *
  * @param string $name
  * @param string $nameId
  * @param integer $allowOnMoon
  * @param string $desc
  * @param string $fullDesc
  * @param string $prodWhat
  * @param string $prod
  * @param string $consWhat
  * @param string $consumption
  * @param string $special
  * @param string $basicMetal
  * @param string $basicSilicon
  * @param string $basicHydrogen
  * @param string $basicEnergy
  * @param string $chargeMetal
  * @param string $chargeSilicon
  * @param string $chargeHydrogen
  * @param string $chargeEnergy
  *
  * @return Bengine_Game_Controller_Construction_Edit
  */
 protected function saveConstruction($name, $nameId, $allowOnMoon, $desc, $fullDesc, $prodWhat, $prod, $consWhat, $consumption, $special, $basicMetal, $basicSilicon, $basicHydrogen, $basicEnergy, $chargeMetal, $chargeSilicon, $chargeHydrogen, $chargeEnergy)
 {
     Hook::event("EditUnitSave");
     // Fetch production from form
     $prodMetal = "";
     $prodSilicon = "";
     $prodHydrogen = "";
     $prodEnergy = "";
     if ($prodWhat == "metal") {
         $prodMetal = $prod;
     } else {
         if ($prodWhat == "silicon") {
             $prodSilicon = $prod;
         } else {
             if ($prodWhat == "hydrogen") {
                 $prodHydrogen = $prod;
             } else {
                 if ($prodWhat == "energy") {
                     $prodEnergy = $prod;
                 }
             }
         }
     }
     // Fetch consumption from form
     $consMetal = "";
     $consSilicon = "";
     $consHydrogen = "";
     $consEnergy = "";
     if ($consWhat == "metal") {
         $consMetal = $consumption;
     } else {
         if ($consWhat == "silicon") {
             $consSilicon = $consumption;
         } else {
             if ($consWhat == "hydrogen") {
                 $consHydrogen = $consumption;
             } else {
                 if ($consWhat == "energy") {
                     $consEnergy = $consumption;
                 }
             }
         }
     }
     // Now generate the sql query.
     $spec = array("special" => $special, "allow_on_moon" => (int) $allowOnMoon, "basic_metal" => $basicMetal, "basic_silicon" => $basicSilicon, "basic_hydrogen" => $basicHydrogen, "basic_energy" => $basicEnergy, "prod_metal" => $prodMetal, "prod_silicon" => $prodSilicon, "prod_hydrogen" => $prodHydrogen, "prod_energy" => $prodEnergy, "cons_metal" => $consMetal, "cons_silicon" => $consSilicon, "cons_hydrogen" => $consHydrogen, "cons_energy" => $consEnergy, "charge_metal" => $chargeMetal, "charge_silicon" => $chargeSilicon, "charge_hydrogen" => $chargeHydrogen, "charge_energy" => $chargeEnergy);
     Core::getQuery()->update("construction", $spec, "name = ?", array($nameId));
     // Save the name and description
     $languageId = Core::getLang()->getOpt("languageid");
     if (Str::length($name) > 0) {
         $result = Core::getQuery()->select("phrases", "phraseid", "", Core::getDB()->quoteInto("title = ?", $nameId));
         if ($result->rowCount() > 0) {
             Core::getQuery()->update("phrases", array("content" => convertSpecialChars($name)), "title = ?", array($nameId));
         } else {
             Core::getQuery()->insert("phrases", array("languageid" => $languageId, "phrasegroupid" => 4, "title" => $nameId, "content" => convertSpecialChars($name)));
         }
         $result->closeCursor();
     }
     if (Str::length($desc) > 0) {
         $result = Core::getQuery()->select("phrases", "phraseid", "", Core::getDB()->quoteInto("title = ?", $nameId . "_DESC"));
         if ($result->rowCount() > 0) {
             Core::getQuery()->update("phrases", array("content" => convertSpecialChars($desc)), "title = ?", array($nameId . "_DESC"));
         } else {
             Core::getQuery()->insert("phrases", array("languageid" => $languageId, "phrasegroupid" => 4, "title" => $nameId . "_DESC", "content" => convertSpecialChars($desc)));
         }
         $result->closeCursor();
     }
     if (Str::length($fullDesc) > 0) {
         $result = Core::getQuery()->select("phrases", "phraseid", "", Core::getDB()->quoteInto("title = ?", $nameId . "_FULL_DESC"));
         if ($result->rowCount() > 0) {
             Core::getQuery()->update("phrases", array("content" => convertSpecialChars($fullDesc)), "title = ?", array($nameId . "_FULL_DESC"));
         } else {
             Core::getQuery()->insert("phrases", array("languageid" => $languageId, "phrasegroupid" => 4, "title" => $nameId . "_FULL_DESC", "content" => convertSpecialChars($fullDesc)));
         }
         $result->closeCursor();
     }
     // Rebuild language cache
     Core::getLang()->rebuild("info");
     return $this;
 }
Пример #25
0
 /**
  * Maximum string length in array
  *
  * @param   array strings
  * @param   int
  * @return  bool
  */
 public static function _validation_array_max_length($val, $length)
 {
     if (Validation::_empty($val)) {
         return true;
     }
     if (!is_array($val)) {
         $val = array($val);
     }
     foreach ($val as $value) {
         if (\Str::length($value) > $length) {
             return false;
         }
     }
     return true;
 }
Пример #26
0
 /**
  * Exact string length
  *
  * @param   string
  * @param   int
  * @return  bool
  */
 public function _validation_exact_length($val, $length)
 {
     return $this->_empty($val) || \Str::length($val) == $length;
 }
Пример #27
0
 /**
  * Executes an invitation.
  *
  * @param integer $eventid
  * @param string $name
  * @param string $username
  *
  * @return Bengine_Game_Controller_Mission
  */
 protected function invite($eventid, $name, $username)
 {
     $this->noAction = true;
     $where = Core::getDB()->quoteInto("(mode = ? OR mode = ?) AND user = ? AND eventid = ?", array(10, 12, Core::getUser()->get("userid"), $eventid));
     $result = Core::getQuery()->select("events", "time", "", $where);
     if ($row = $result->fetchRow()) {
         $result->closeCursor();
         $error = "";
         $time = $row["time"];
         $result = Core::getQuery()->select("user u", array("u.userid", "u2a.aid"), "LEFT JOIN " . PREFIX . "user2ally u2a ON (u2a.userid = u.userid)", Core::getDB()->quoteInto("u.username = ?", $username));
         $row = $result->fetchRow();
         $userid = $row["userid"];
         $aid = $row["aid"];
         $Relation = new Bengine_Game_User_Relation(Core::getUser()->get("userid"), Core::getUser()->get("aid"));
         if (!$Relation->hasRelation($userid, $aid)) {
             $error[] = "UNABLE_TO_INVITE_USER";
         }
         unset($Relation);
         if (Str::length($name) > 0 && Str::length($name) <= 128) {
             $name = Str::validateXHTML($name);
             Core::getQuery()->update("attack_formation", array("name" => $name), "eventid = ?", array($eventid));
         } else {
             $error[] = "ENTER_FORMATION_NAME";
         }
         if (empty($error)) {
             Core::getQuery()->insert("formation_invitation", array("eventid" => $eventid, "userid" => $userid));
         } else {
             foreach ($error as $_error) {
                 Logger::addMessage($_error);
             }
         }
     }
     $this->formation($eventid);
     return $this;
 }
Пример #28
0
 /**
  * Validates a user password & ensures an encrypted password is set
  *
  * @see \Warden\Model_User::_event_before_save()
  */
 private function _ensure_and_validate_password()
 {
     if (!empty($this->password)) {
         if (\Str::length($this->password) < 6) {
             throw new \Orm\ValidationFailed(__('warden.validation.password.too_short'));
         } elseif (!preg_match(self::REGEX_PASSWORD, $this->password)) {
             throw new \Orm\ValidationFailed(__('warden.validation.password.invalid'));
         }
         $this->encrypted_password = Warden::encrypt_password($this->password);
     }
     if (empty($this->encrypted_password)) {
         throw new \Orm\ValidationFailed(__('warden.validation.password.required'));
     }
 }
Пример #29
0
 /**
  * Updates the moderator form.
  *
  * @param string $username
  * @param string $usertitle
  * @param string $email
  * @param int $delete
  * @param int $umode
  * @param string $activation
  * @param string $ipcheck
  * @param int $usergroupid
  * @param int $points
  * @param int $fpoints
  * @param int $dpoints
  * @param int $rpoints
  * @param string $password
  * @param int $languageid
  * @param string $templatepackage
  * @param string $theme
  * @param string $js_interface
  * @return Bengine_Game_Controller_Moderator
  */
 protected function updateUser($username, $usertitle, $email, $delete, $umode, $activation, $ipcheck, $usergroupid, $points, $fpoints, $dpoints, $rpoints, $password, $languageid, $templatepackage, $theme, $js_interface)
 {
     $select = array("userid", "username", "email");
     $result = Core::getQuery()->select("user", $select, "", Core::getDB()->quoteInto("userid = ?", $this->userid));
     if ($row = $result->fetchRow()) {
         $result->closeCursor();
         Hook::event("SaveUserModeration", array(&$row));
         $delete = $delete == 1 ? 1 : 0;
         $umode = $umode == 1 ? 1 : 0;
         $activation = $activation == 1 ? "" : "1";
         $ipcheck = $ipcheck == 1 ? 1 : 0;
         $username = trim($username);
         $usertitle = trim($usertitle);
         $js_interface = trim($js_interface);
         if (Core::getUser()->ifPermissions("CAN_EDIT_USER")) {
             Core::getQuery()->delete("user2group", "userid = ?", null, null, array($this->userid));
             Core::getQuery()->insert("user2group", array("usergroupid" => $usergroupid, "userid" => $this->userid));
             Core::getQuery()->update("user", array("points" => floatval($points), "fpoints" => (int) $fpoints, "dpoints" => (int) $dpoints, "rpoints" => (int) $rpoints), "userid = ?", array($this->userid));
         }
         if ($umode) {
             setProdOfUser($this->userid, 0);
         }
         if (!Str::compare($username, $row["username"])) {
             $num = Core::getQuery()->select("user", "userid", "", Core::getDB()->quoteInto("username = ?", $username))->rowCount();
             if ($num > 0) {
                 $username = $row["username"];
             }
         }
         if (!Str::compare($email, $row["email"])) {
             $num = Core::getQuery()->select("user", "userid", "", Core::getDB()->quoteInto("email = ?", $email))->rowCount();
             if ($num > 0) {
                 $email = $row["email"];
             }
         }
         if (Str::length($password) > Core::getOptions()->get("MIN_PASSWORD_LENGTH")) {
             $encryption = Core::getOptions("USE_PASSWORD_SALT") ? "md5_salt" : "md5";
             $password = Str::encode($password, $encryption);
             Core::getQuery()->update("password", array("password" => $password, "time" => TIME), "userid = ?", array($this->userid));
         }
         $spec = array("username" => $username, "usertitle" => $usertitle, "email" => $email, "delete" => $delete, "umode" => $umode, "activation" => $activation, "languageid" => $languageid, "ipcheck" => $ipcheck, "templatepackage" => $templatepackage, "theme" => $theme, "js_interface" => $js_interface);
         Core::getQuery()->update("user", $spec, "userid = ?", array($this->userid));
     }
     return $this;
 }
Пример #30
0
 /**
  * Get the size of an attribute.
  *
  * @param  string  $attribute
  * @return mixed
  */
 protected function get_size($attribute)
 {
     if (is_numeric($this->attributes[$attribute]) and $this->has_rule($attribute, $this->numeric_rules)) {
         return $this->attributes[$attribute];
     }
     return array_key_exists($attribute, $_FILES) ? $this->attributes[$attribute]['size'] / 1024 : Str::length(trim($this->attributes[$attribute]));
 }