Guest User

Untitled

a guest
May 22nd, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 36.88 KB | None | 0 0
  1. <?php
  2.  
  3. include_once("database.php");
  4.  
  5. class User{
  6.     private $id;
  7.     private $username;
  8.     private $password;
  9.     private $salt;
  10.     private $clanid;
  11.     private $clanxp;
  12.     private $clanname;
  13.     private $rank;
  14.     private $points;
  15.     private $cape;
  16.     private $rsn;
  17.     private $email;
  18.     private $about;
  19.     private $reputation;
  20.    
  21.     public function __destruct(){
  22.         $database   =   new Database();
  23.         $this->update($database);
  24.     }
  25.    
  26.     public function getFromDatabaseByUsername($username, $db){
  27.         $username   =   _username($username);
  28.         $query      =   "SELECT * FROM users WHERE username = :username";
  29.         $params     =   array(":username"=>$username);
  30.        
  31.         try{
  32.             $result             =   $db->query($query, $params);
  33.             $this->id           =   _id($result["id"]);
  34.             $this->username     =   _username($result["username"]);
  35.             $this->clanid       =   _id($result["clanid"]);
  36.             $this->clanxp       =   _uint($result["clanxp"]);
  37.             $this->rank         =   _rank($result["rank"]);
  38.             $this->points       =   _points($result["points"]);
  39.             $this->cape         =   _cape($result["cape"]);
  40.             $this->rsn          =   _username($result["rsn"]);
  41.             $this->email        =   _email($result["email"]);
  42.             $this->about        =   _about($result["about"]);
  43.             $this->reputation   =   _points($result["reputation"]);
  44.             $this->clanname     =   _clan_id($this->clanid, $db)->get_name();
  45.         }catch(Exception $e){
  46.             throw $e;
  47.         }
  48.         return $this;
  49.     }
  50.    
  51.     public function getFromDatabaseByID($id, $db){
  52.         $id         =   _id($id);
  53.         $query      =   "SELECT * FROM users WHERE id = :id";
  54.         $params     =   array(":id"=>$id);
  55.        
  56.         try{
  57.             $result             =   $db->query($query, $params);
  58.             $this->id           =   _id($result["id"]);
  59.             $this->username     =   _username($result["username"]);
  60.             $this->clanid       =   _id($result["clanid"]);
  61.             $this->clanxp       =   _uint($result["clanxp"]);
  62.             $this->rank         =   _rank($result["rank"]);
  63.             $this->points       =   _points($result["points"]);
  64.             $this->cape         =   _cape($result["cape"]);
  65.             $this->rsn          =   _username($result["rsn"]);
  66.             $this->email        =   _email($result["email"]);
  67.             $this->about        =   _about($result["about"]);
  68.             $this->reputation   =   _points($result["reputation"]);
  69.             $this->clanname     =   _clan_id($this->clanid, $db)->get_name();  
  70.         }catch(Exception $e){
  71.             throw $e;
  72.         }
  73.         return $this;
  74.     }
  75.    
  76.     public function register($username, $password, $email, $db){
  77.         try{
  78.             $username       =   _username($username);
  79.             if($this->user_exists($username, $db)){
  80.                 throw new Exception("User already exists");
  81.             }
  82.             $salt           =   _salt();
  83.             $password       =   _password($password, $salt);
  84.             $email          =   _email($email);
  85.             $cape           =   _cape("none");
  86.             $clanid         =   _id(0);
  87.             $rank           =   _rank("free agent");
  88.            
  89.             $query          =   "INSERT INTO users (username, salt, password, email, cape, clanid, rank) VALUES (:username, :salt, :password, :email, :cape, :clanid, :rank)";
  90.             $params =   array(":username"=>$username, ":salt"=>$salt, ":password"=>$password, ":email"=>$email, ":cape"=>$cape, ":clanid"=>$clanid, ":rank"=>$rank);
  91.             $db->queryNone($query, $params);
  92.            
  93.             $this->getFromDatabaseByUsername($username, $db);
  94.             return $this;
  95.         }catch(Exception $e){
  96.             throw $e;
  97.         }
  98.     }
  99.    
  100.     public function log_in($username, $password, $db){
  101.         try{
  102.             if(!$this->user_exists(_username($username), $db)){
  103.                 throw new Exception("User does not exist");
  104.             }
  105.             if(_password($password) !== $this->get_password(_username($username), $db)){
  106.                 throw new Exception("Incorrect password");
  107.             }
  108.             $this->getFromDatabaseByUsername(_username($username), $db);
  109.             $this->to_session();
  110.             session_start();
  111.         }catch(Exception $e){
  112.             throw $e;
  113.         }
  114.     }
  115.    
  116.     public function log_out(){
  117.         unset($_SESSION["user"]);
  118.     }
  119.    
  120.     public function update($db){
  121.         try{           
  122.             $query          =   "UPDATE users SET username = :username, email = :email, cape = :cape, clanid = :clanid, rank = :rank, points = :points, rsn = :rsn, about = :about, reputation = :reputation WHERE id = :id";
  123.             $params =   array(":username"=>$this->get_username(), ":email"=>$this->get_email(), ":cape"=>$this->get_cape(), ":clanid"=>$this->get_clanid(), ":rank"=>$this->get_rank(), ":points"=>$this->get_points(), ":rsn"=>$this->get_rsn(), ":about"=>$this->get_about(), ":reputation"=>$this->get_reputation(), ":id"=>$this->get_id());
  124.             $db->queryNone($query, $params);
  125.             return $this;
  126.         }catch(Exception $e){
  127.             throw $e;
  128.         }
  129.     }
  130.    
  131.     private function user_exists($username, $db){
  132.         $query  =   "SELECT username FROM users WHERE username = :username";
  133.         $params =   array(":username"=>_username($username));
  134.         $result =   $db->query($query, $params);
  135.        
  136.         return isset($result["username"]);
  137.     }
  138.    
  139.     private function get_password($username, $db){
  140.         $query  =   "SELECT password FROM users WHERE username = :username";
  141.         $params =   array(":username"=>_username($username));
  142.         $result =   $db->query($query, $params);
  143.        
  144.         return $result["password"];
  145.     }
  146.    
  147.     private function to_session(){
  148.         $_SESSION["user"]   =   $this;
  149.     }
  150.    
  151.     public function to_json(){
  152.         $json   =   array();
  153.         $json["user"]["id"]         =   $this->get_id();
  154.         $json["user"]["username"]   =   $this->get_username();
  155.         $json["user"]["clanid"]     =   $this->get_clanid();
  156.         $json["user"]["clanxp"]     =   $this->get_clanxp();
  157.         $json["user"]["clanname"]   =   $this->get_clanname();
  158.         $json["user"]["rank"]       =   $this->get_rank();
  159.         $json["user"]["points"]     =   $this->get_points();
  160.         $json["user"]["cape"]       =   $this->get_cape();
  161.         $json["user"]["rsn"]        =   $this->get_rsn();
  162.         $json["user"]["email"]      =   $this->get_email();
  163.         $json["user"]["about"]      =   $this->get_about();
  164.         $json["user"]["reputation"] =   $this->get_reputation();
  165.         return json_encode($json["user"]);
  166.     }
  167.    
  168.     public function get_id(){
  169.         return $this->id;
  170.     }
  171.    
  172.     public function get_username(){
  173.         return $this->username;
  174.     }
  175.    
  176.     public function get_clanid(){
  177.         return $this->clanid;
  178.     }
  179.    
  180.     public function get_clanxp(){
  181.         return $this->clanxp;
  182.     }
  183.    
  184.     public function get_clanname(){
  185.         return $this->clanname;
  186.     }
  187.    
  188.     public function get_rank(){
  189.         return $this->rank;
  190.     }
  191.    
  192.     public function get_points(){
  193.         return $this->points;
  194.     }
  195.    
  196.     public function get_cape(){
  197.         return $this->cape;
  198.     }
  199.    
  200.     public function get_rsn(){
  201.         return $this->rsn;
  202.     }
  203.    
  204.     public function get_email(){
  205.         return $this->email;
  206.     }
  207.    
  208.     public function get_about(){
  209.         return $this->about;
  210.     }
  211.    
  212.     public function get_reputation(){
  213.         return $this->reputation;
  214.     }
  215.    
  216.     public function set_id($value){
  217.         $this->id   =   _id($value);
  218.     }
  219.    
  220.     public function set_username($value){
  221.         $this->username =   _username($value);
  222.     }
  223.    
  224.     public function set_clanid($value){
  225.         $this->clanid   =   _id($value);
  226.     }
  227.    
  228.     public function set_clanxp($value){
  229.         $this->clanxp   =   _uint($value);
  230.     }
  231.    
  232.     public function set_clanname($value){
  233.         $this->clanname =   _strict($value);
  234.     }
  235.    
  236.     public function set_rank($value){
  237.         $this->rank =   _rank($value);
  238.     }
  239.    
  240.     public function set_points($value){
  241.         $this->points   =   _points($value);
  242.     }
  243.    
  244.     public function set_cape($value){
  245.         $this->cape =   _cape($value);
  246.     }
  247.    
  248.     public function set_rsn($value){
  249.         $this->rsn  =   _username($value);
  250.     }
  251.    
  252.     public function set_email($value){
  253.         $this->email    =   _email($value);
  254.     }
  255.    
  256.     public function set_about($value){
  257.         $this->about    =   _about($value);
  258.     }
  259.    
  260.     public function set_reputation($value){
  261.         $this->reputation   =   _points($value);
  262.     }
  263.    
  264.     public function rank_up(){
  265.         $ranks  =   array('free agent','recruit','corporal','sergeant','lieutenant','captain','general','admin','organiser','coordinator','overseer','deputy owner','owner');
  266.         $key    =   array_search($this->rank, $ranks);
  267.         if($key < 12){
  268.             $key++;
  269.             $this->rank =   $ranks[$key];
  270.         }
  271.     }
  272.    
  273.     public function rank_down(){
  274.         $ranks  =   array('free agent','recruit','corporal','sergeant','lieutenant','captain','general','admin','organiser','coordinator','overseer','deputy owner','owner');
  275.         $key    =   array_search($this->rank, $ranks);
  276.         if($key > 0){
  277.             $key--;
  278.             $this->rank =   $ranks[$key];
  279.         }
  280.     }
  281.    
  282.     public function remove_from_clan(){
  283.         $this->set_clanid(0);
  284.         $this->set_clanxp(0);
  285.         $this->set_clanname("");
  286.         $this->set_points(0);
  287.         $this->set_rank("free agent");
  288.     }
  289.    
  290.     public function add_to_clan($clan){
  291.         $this->remove_from_clan();
  292.         $this->set_clanid($clan->get_id());
  293.         $this->set_clanname($clan->get_name());
  294.         $this->rank_up();
  295.     }
  296.    
  297.     public function award_points($count){
  298.         $points =   $this->get_points();
  299.         $this->set_points($points + _int($count));
  300.     }
  301.    
  302.     public function award_reputation($count){
  303.         $reputation =   $this->get_reputation();
  304.         $this->set_reputation($reputation + _int($count));
  305.     }
  306.    
  307.     public function upvote(){
  308.         $this->award_reputation(1);
  309.     }
  310.    
  311.     public function downvote(){
  312.         $this->award_reputation(-1);
  313.     }
  314.    
  315.     public function can_ask(){
  316.         return ($this->get_reputation() >= 1);
  317.     }
  318.    
  319.     public function can_edit(){
  320.         return ($this->get_reputation() >= 10);
  321.     }
  322.    
  323.     public function can_edit_without_approval(){
  324.         return ($this->get_reputation() >= 50);
  325.     }
  326.    
  327.     public function can_downvote(){
  328.         return ($this->get_reputation() >= 1);
  329.     }
  330.    
  331.     public function can_moderate(){
  332.         return ($this->get_reputation() >= 25);
  333.     }
  334.    
  335.     public function award_comp(){
  336.         if($this->get_cape() == "none"){
  337.             $this->set_cape("comp");
  338.         }
  339.     }
  340.    
  341.     public function award_trim(){
  342.         if($this->get_cape() == "none" || $this->get_cape() == "comp"){
  343.             $this->set_cape("trim");
  344.         }
  345.     }
  346. }
  347.  
  348. class Clan{
  349.     private $id;
  350.     private $name;
  351.     private $make_changes;
  352.     private $about;
  353.    
  354.     public function __destruct(){
  355.         $database   =   new Database();
  356.         $this->update($database);
  357.     }
  358.    
  359.     public function create($name, $db){
  360.         try{
  361.             $name   =   _strict($name);
  362.            
  363.             if($this->exists($name, $db)){
  364.                 throw new Exception("Clan already exists");
  365.             }
  366.            
  367.             $query          =   "INSERT INTO clan_ids (name) VALUES (:name)";
  368.             $params     =   array(":name"=>$name);
  369.             $db->queryNone($query, $params);
  370.            
  371.             $query      =   "SELECT id FROM clan_ids WHERE name = :name";
  372.             $params     =   array(":name"=>$name);
  373.             $result     =   $db->query($query, $params);
  374.             $id         =   _id($result["id"]);
  375.            
  376.             $makechanges    =   _rank("admin");
  377.             $query          =   "INSERT INTO clans (id, makechanges) VALUES (:id, :makechanges)";
  378.             $params         =   array(":id"=>$id, ":makechanges"=>$makechanges);
  379.             $db->queryNone($query, $params);
  380.            
  381.             $this->getFromDatabaseByName($name, $db);
  382.             return $this;
  383.         }catch(Exception $e){
  384.             throw $e;
  385.         }
  386.     }
  387.    
  388.     public function exists($name, $db){
  389.         $query  =   "SELECT id FROM clan_ids WHERE name = :name";
  390.         $params =   array(":name"=>_strict($name));
  391.         $result =   $db->query($query, $params);
  392.        
  393.         return isset($result["id"]);
  394.     }
  395.    
  396.     public function id_exists($id, $db){
  397.         $query  =   "SELECT id FROM clan_ids WHERE id = :id";
  398.         $params =   array(":id"=>_id($id));
  399.         $result =   $db->query($query, $params);
  400.        
  401.         return isset($result["id"]);
  402.     }
  403.    
  404.     public function getFromDatabaseByName($name, $db){
  405.         $name   =   _strict($name);
  406.         $query      =   "SELECT * FROM clan_ids WHERE name = :name";
  407.         $params     =   array(":name"=>$name);
  408.        
  409.         try{
  410.             $result             =   $db->query($query, $params);
  411.             $this->id           =   _id($result["id"]);
  412.             $this->name     =   _strict($result["name"]);
  413.         }catch(Exception $e){
  414.             throw $e;
  415.         }
  416.        
  417.         $query      =   "SELECT * FROM clans WHERE id = :id";
  418.         $params     =   array(":id"=>$this->id);
  419.        
  420.         try{
  421.             $result                 =   $db->query($query, $params);
  422.             $this->make_changes     =   _rank($result["makechanges"]);
  423.             $this->about            =   _about($result["about"]);
  424.         }catch(Exception $e){
  425.             throw $e;
  426.         }
  427.         return $this;
  428.     }
  429.    
  430.     public function getFromDatabaseByID($id, $db){
  431.         $id =   _id($id);
  432.         $query      =   "SELECT * FROM clan_ids WHERE id = :id";
  433.         $params     =   array(":id"=>$id);
  434.        
  435.         try{
  436.             $result             =   $db->query($query, $params);
  437.             $this->id           =   _id($result["id"]);
  438.             $this->name     =   _strict($result["name"]);
  439.         }catch(Exception $e){
  440.             throw $e;
  441.         }
  442.        
  443.         $query      =   "SELECT * FROM clans WHERE id = :id";
  444.         $params     =   array(":id"=>$this->id);
  445.        
  446.         try{
  447.             $result                 =   $db->query($query, $params);
  448.             $this->make_changes     =   _rank($result["makechanges"]);
  449.             $this->about            =   _about($result["about"]);
  450.         }catch(Exception $e){
  451.             throw $e;
  452.         }
  453.         return $this;
  454.     }
  455.    
  456.     public function update($db){
  457.         try{
  458.             $query          =   "UPDATE clan_ids SET name = :name WHERE id = :id";
  459.             $params =   array(":name"=>$this->get_name(), ":id"=>$this->get_id());
  460.             $db->queryNone($query, $params);
  461.            
  462.             $query          =   "UPDATE clans SET makechanges = :makechanges, about = :about WHERE id = :id";
  463.             $params =   array(":makechanges"=>$this->get_make_changes(), ":about"=>$this->get_about(), ":id"=>$this->get_id());
  464.             $db->queryNone($query, $params);
  465.            
  466.             return $this;
  467.         }catch(Exception $e){
  468.             throw $e;
  469.         }
  470.     }
  471.    
  472.     public function get_name(){
  473.         return $this->name;
  474.     }
  475.    
  476.     public function get_id(){
  477.         return $this->id;
  478.     }
  479.    
  480.     public function get_about(){
  481.         return $this->about;
  482.     }
  483.    
  484.     public function get_make_changes(){
  485.         return $this->make_changes;
  486.     }
  487.    
  488.     public function can_make_changes($user){
  489.         $ranks  =   array('free agent','recruit','corporal','sergeant','lieutenant','captain','general','admin','organiser','coordinator','overseer','deputy owner','owner');
  490.         $key1   =   array_search($user->rank, $ranks);
  491.         $key2   =   array_search($this->get_make_changes(), $ranks);
  492.        
  493.         return ($key1 > $key2);
  494.     }
  495.    
  496.     public function set_about($value, $user){
  497.         $value  =   _about($value);
  498.         if($this->can_make_changes($user)){
  499.             $this->about    =   $value;
  500.         }
  501.     }
  502.    
  503.     public function set_name($value, $user){
  504.         $value  =   _strict($value);
  505.         if($this->can_make_changes($user)){
  506.             $this->name =   $value;
  507.         }
  508.     }
  509.    
  510.     public function set_make_changes($value, $user){
  511.         $value  =   _rank($value);
  512.         if($this->can_make_changes($user)){
  513.             $this->make_changes =   $value;
  514.         }
  515.     }
  516. }
  517.  
  518. class Question{
  519.     private $id;
  520.     private $answers    =   array();
  521.     private $tags       =   array();
  522.    
  523.     private $user;
  524.     private $title;
  525.     private $content;
  526.     private $timestamp;
  527.    
  528.     public function ask($title, $content, $user, $db){
  529.         $user   =   _user_id($user, $db);
  530.         if(!$user->can_ask()){
  531.             throw new Exception("Your reputation is not high enough to ask a question.");
  532.         }
  533.         $title      =   _text($title, 140);
  534.         $content    =   _html($content);
  535.        
  536.         $this->user     =   $user;
  537.         $this->title    =   $title;
  538.         $this->content  =   $content;
  539.     }
  540.    
  541.     public function add_tag($tag){
  542.         try{
  543.             $tag    =   _tag($tag);
  544.         }catch(Exception $e){
  545.             throw $e;
  546.         }
  547.         $this->tags[]   =   $tag;
  548.     }
  549.    
  550.     public function load($id, $db){
  551.         $query  =   "SELECT * FROM questions WHERE id = :id";
  552.         $params =   array(":id"=>_id($id));
  553.         $result =   $db->query($query, $params);
  554.        
  555.         if(!isset($result["id"])){
  556.             throw new Exception("Question does not exist");
  557.         }
  558.        
  559.         $this->ask($result["title"], $result["content"], $result["contributor"], $db);
  560.         $this->id           =   $result["id"];
  561.         $this->timestamp    =   $result["date"];
  562.        
  563.         $this->load_tags($id, $db);
  564.         $this->load_answers($id, $db);
  565.     }
  566.    
  567.     private function load_tags($id, $db){
  568.         $query      =   "SELECT * FROM tagged_items WHERE item_id = :id";
  569.         $params     =   array(":id"=>_id($id));
  570.         $results    =   $db->queryAll($query, $params);
  571.        
  572.         $tags   =   array('melee', 'defence', 'ranged', 'prayer', 'magic', 'runecrafting', 'construction', 'dungeoneering', 'constitution', 'agility', 'herblore', 'thieving', 'crafting', 'fletching', 'slayer', 'hunter', 'divination', 'mining', 'smithing', 'fishing', 'cooking', 'firemaking', 'woodcutting', 'farming', 'summoning', 'minigames', 'distractions and diversions', 'combat', 'runescape 3', 'old school runescape', 'runescape classic', 'monster hunting', 'moneymaking', 'technical', 'general', 'security', 'spreadsheets', 'meta');
  573.         foreach($results as $tag){
  574.             $tag_name       =   $tags[$tag["tag_id"]];
  575.             $this->tags[]   =   $tag_name;
  576.         }
  577.     }
  578.    
  579.     public function submit($db){
  580.         $query  =   "INSERT INTO questions (contributor, title, content) VALUES (:contributor, :title, :content)";
  581.         $params =   array(":contributor"=>$this->user->get_id(), ":title"=>$this->title, ":content"=>$this->content);
  582.         $db->queryNone($query, $params);
  583.        
  584.         $query  =   "SELECT id FROM questions WHERE contributor = :contributor AND title = :title AND content = :content";
  585.         $params =   array(":contributor"=>$this->user->get_id(), ":title"=>$this->title, ":content"=>$this->content);
  586.         $result =   $db->queryAll($query, $params);
  587.         $result =   end($result);
  588.         $this->id       =   $result["id"];
  589.        
  590.         foreach($this->tags as $tag){
  591.             $this->submit_tag($tag, $this->id, $db);
  592.         }
  593.     }
  594.    
  595.     public function get_title(){
  596.         return stripslashes($this->title);
  597.     }
  598.    
  599.     public function get_content(){
  600.         return stripslashes($this->content);
  601.     }
  602.    
  603.     public function get_user(){
  604.         return $this->user;
  605.     }
  606.    
  607.     public function get_answers(){
  608.         return $this->answers;
  609.     }
  610.    
  611.     public function get_tags(){
  612.         return $this->tags;
  613.     }
  614.    
  615.     public function get_id(){
  616.         return $this->id;
  617.     }
  618.    
  619.     private function submit_tag($tag, $question_id, $db){
  620.         $tags   =   array('melee', 'defence', 'ranged', 'prayer', 'magic', 'runecrafting', 'construction', 'dungeoneering', 'constitution', 'agility', 'herblore', 'thieving', 'crafting', 'fletching', 'slayer', 'hunter', 'divination', 'mining', 'smithing', 'fishing', 'cooking', 'firemaking', 'woodcutting', 'farming', 'summoning', 'minigames', 'distractions and diversions', 'combat', 'runescape 3', 'old school runescape', 'runescape classic', 'monster hunting', 'moneymaking', 'technical', 'general', 'security', 'spreadsheets', 'meta');
  621.        
  622.         $tag_id =   array_search($tag, $tags);
  623.         $query  =   "INSERT INTO tagged_items (tag_id, item_id) VALUES (:tag_id, :item_id)";
  624.         $params =   array(":tag_id"=>$tag_id, ":item_id"=>$question_id);
  625.        
  626.         $db->queryNone($query, $params);
  627.     }
  628.    
  629.     private function load_answers($id, $db){
  630.         $query      =   "SELECT * FROM answers WHERE questionid = :id";
  631.         $params     =   array(":id" => $id);
  632.         $results    =   $db->queryAll($query, $params);
  633.         foreach($results as $result){
  634.             $temp   =   new Answer();
  635.             $temp->load_from_array($result, $db);
  636.             $this->answers[]    =   $temp;
  637.         }
  638.     }
  639.    
  640.     public function to_json(){
  641.         $json["user"]       =   $this->user->get_username();
  642.         $json["reputation"] =   $this->user->get_reputation();
  643.         $json["content"]    =   $this->get_content();
  644.         $json["timestamp"]  =   $this->timestamp;
  645.         $json["title"]      =   $this->get_title();
  646.         $json["answers"]    =   array();
  647.         $json["tags"]   =   array();
  648.         foreach($this->answers as $answer){
  649.             $json["answers"][]  =   $answer->to_array();
  650.         }
  651.        
  652.         foreach($this->tags as $tag){
  653.             $json["tags"][] =   $tag;
  654.         }
  655.         return json_encode($json);
  656.     }
  657. }
  658.  
  659. class Answer{
  660.     private $questionid;
  661.     private $answerid;
  662.     private $user;
  663.     private $content;
  664.     private $upvotes;
  665.     private $downvotes;
  666.     private $comments;
  667.     private $timestamp;
  668.  
  669.     public function __destruct(){
  670.         $database   =   new Database();
  671.         $this->update($database);      
  672.     }
  673.    
  674.     public function respond($questionid, $contributorid, $content, $db){
  675.         $this->questionid   =   _id($questionid);
  676.         $this->user         =   _user_id($contributorid, $db);
  677.         $this->content      =   _html($content);
  678.     }
  679.    
  680.     public function submit($db){
  681.         $query  =   "INSERT INTO answers (contributor, questionid, content) VALUES (:contributor, :questionid, :content)";
  682.         $params =   array(":contributor"=>$this->user->get_id(), ":content"=>$this->content, ":questionid"=>$this->questionid);
  683.         $db->queryNone($query, $params);
  684.        
  685.         $query  =   "SELECT id FROM answers WHERE contributor = :contributor AND content = :content";
  686.         $params =   array(":contributor"=>$this->user->get_id(), ":content"=>$this->content);
  687.         $result =   $db->queryAll($query, $params);
  688.         $result =   end($result);
  689.         $this->answerid     =   $result["id"];
  690.     }
  691.    
  692.     public function update($db){
  693.         try{
  694.             $query          =   "UPDATE answers SET contributor = :contributor, questionid = :questionid, content = :content, upvotes = :upvotes, downvotes = :downvotes WHERE id = :id";
  695.             $params =   array(":contributor"=>$this->user->get_id(), ":questionid"=>$this->questionid, ":content"=>$this->content, ":upvotes"=>$this->upvotes, ":downvotes"=>$this->downvotes, ":id"=>$this->answerid);
  696.             $db->queryNone($query, $params);
  697.             return $this;
  698.         }catch(Exception $e){
  699.             throw $e;
  700.         }
  701.     }
  702.    
  703.     public function get_id(){
  704.         return $this->answerid;
  705.     }
  706.    
  707.     public function get_user(){
  708.         return $this->user;
  709.     }
  710.    
  711.     public function get_content(){
  712.         return stripslashes($this->content);
  713.     }
  714.    
  715.     public function get_upvotes(){
  716.         return $this->upvotes;
  717.     }
  718.    
  719.     public function get_downvotes(){
  720.         return $this->downvotes;
  721.     }
  722.    
  723.     public function get_score(){
  724.         return $this->get_upvotes() - $this->get_downvotes();
  725.     }
  726.    
  727.     public function get_comments(){
  728.         return $this->comments;
  729.     }
  730.    
  731.     public function upvote(){
  732.         $this->upvotes++;
  733.     }
  734.    
  735.     public function downvote(){
  736.         $this->downvote++;
  737.     }
  738.    
  739.     public function load_from_array($answer, $db){
  740.         $this->questionid   =   $answer["questionid"];
  741.         $this->answerid     =   $answer["id"];
  742.         $this->user         =   _user_id($answer["contributor"], $db);
  743.         $this->content      =   $answer["content"];
  744.         $this->upvotes      =   $answer["upvotes"];
  745.         $this->downvotes    =   $answer["downvotes"];
  746.         $this->timestamp    =   $answer["date"];
  747.         $this->load_comments($db);
  748.     }
  749.    
  750.     public function load_from_id($questionid, $answerid, $db){
  751.         $query  =   "SELECT * FROM answers WHERE questionid = :questionid AND id = :id";
  752.         $params =   array(":questionid" => $questionid, ":id" => $id);
  753.         $result =   $db->query($query, $params);
  754.         $this->load_from_array($result, $db);
  755.     }
  756.    
  757.     public function load_comments($db){
  758.         $query      =   "SELECT * FROM comments WHERE questionid = :questionid AND answerid = :answerid";
  759.         $params     =   array(":questionid" => $this->questionid, ":answerid" => $this->answerid);
  760.         $results    =   $db->queryAll($query, $params);
  761.        
  762.         foreach($results as $result){
  763.             $temp   =   new Comment();
  764.             $temp->load_from_array($result, $db);
  765.             $this->comments[]   =   $temp;
  766.         }
  767.     }
  768.    
  769.     public function to_json(){
  770.         $json["user"]   =   $this->user->get_username();
  771.         $json["reputation"] =   $this->user->get_reputation();
  772.         $json["content"]    =   $this->content;
  773.         $json["timestamp"]  =   $this->timestamp;
  774.         $json["score"]      =   $this->get_score();
  775.         $json["comments"]   =   array();
  776.         foreach($this->comments as $comment){
  777.             $json["comments"][] =   $comment->to_json();
  778.         }
  779.         return stripslashes(json_encode($json));
  780.     }
  781.    
  782.     public function to_array(){
  783.         $json["user"]   =   $this->user->get_username();
  784.         $json["reputation"] =   $this->user->get_reputation();
  785.         $json["content"]    =   $this->content;
  786.         $json["timestamp"]  =   $this->timestamp;
  787.         $json["score"]      =   $this->get_score();
  788.         $json["comments"]   =   array();
  789.         foreach($this->comments as $comment){
  790.             $json["comments"][] =   $comment->to_array();
  791.         }
  792.         return $json;
  793.     }
  794. }
  795.  
  796. class Comment{
  797.     private $questionid;
  798.     private $answerid;
  799.     private $commentid;
  800.     private $user;
  801.     private $content;
  802.     private $upvotes;
  803.     private $timestamp;
  804.  
  805.     public function __destruct(){
  806.         $database   =   new Database();
  807.         $this->update($database);      
  808.     }
  809.    
  810.     public function respond($questionid, $answerid, $contributorid, $content, $db){
  811.         $this->questionid   =   _id($questionid);
  812.         $this->answerid     =   _id($answerid);
  813.         $this->user         =   _user_id($contributorid, $db);
  814.         $this->content      =   _html($content, 140);
  815.     }
  816.    
  817.     public function submit($db){
  818.         $query  =   "INSERT INTO comments (contributor, questionid, answerid, content) VALUES (:contributor, :questionid, :answerid, :content)";
  819.         $params =   array(":contributor"=>$this->user->get_id(), ":questionid"=>$this->questionid, ":answerid"=>$this->answerid, ":content"=>$this->content);
  820.         $db->queryNone($query, $params);
  821.        
  822.         $query  =   "SELECT id FROM comments WHERE contributor = :contributor AND content = :content";
  823.         $params =   array(":contributor"=>$this->user->get_id(), ":content"=>$this->content);
  824.         $result =   $db->queryAll($query, $params);
  825.         $result =   end($result);
  826.         $this->commentid        =   $result["id"];
  827.     }
  828.    
  829.     public function update($db){
  830.         try{           
  831.             $query          =   "UPDATE comments SET contributor = :contributor, questionid = :questionid, content = :content, upvotes = :upvotes, answerid = :answerid WHERE id = :id";
  832.             $params =   array(":contributor"=>$this->user->get_id(), ":questionid"=>$this->questionid, ":content"=>$this->content, ":upvotes"=>$this->upvotes, ":answerid"=>$this->answerid, ":id"=>$this->commentid);
  833.             $db->queryNone($query, $params);
  834.             return $this;
  835.         }catch(Exception $e){
  836.             throw $e;
  837.         }
  838.     }
  839.    
  840.     public function get_user(){
  841.         return $this->user;
  842.     }
  843.    
  844.     public function get_content(){
  845.         return stripslashes($this->content);
  846.     }
  847.    
  848.     public function get_upvotes(){
  849.         return $this->upvotes;
  850.     }
  851.    
  852.     public function get_score(){
  853.         return $this->get_upvotes();
  854.     }
  855.    
  856.     public function upvote(){
  857.         $this->upvotes++;
  858.     }
  859.    
  860.     public function load_from_array($comment, $db){
  861.         $this->questionid   =   $comment["questionid"];
  862.         $this->answerid     =   $comment["answerid"];
  863.         $this->commentid    =   $comment["id"];
  864.         $this->user         =   _user_id($comment["contributor"], $db);
  865.         $this->content      =   $comment["content"];
  866.         $this->upvotes      =   $comment["upvotes"];
  867.         $this->timestamp    =   $comment["date"];
  868.     }
  869.    
  870.     public function load_from_id($questionid, $answerid, $id, $db){
  871.         $query  =   "SELECT * FROM comments WHERE questionid = :questionid AND answerid = :answerid AND id = :id";
  872.         $params =   array(":questionid" => $questionid, ":answerid" => $answerid, ":id" => $id);
  873.         $result =   $db->query($query, $params);
  874.         $this->load_from_array($result, $db);
  875.     }
  876.    
  877.     public function to_json(){
  878.         $json["user"]   =   $this->user->get_username();
  879.         $json["reputation"] =   $this->user->get_reputation();
  880.         $json["content"]    =   $this->content;
  881.         $json["timestamp"]  =   $this->timestamp;
  882.         $json["score"]      =   $this->get_score();
  883.         return stripslashes(json_encode($json));
  884.     }
  885.    
  886.     public function to_array(){
  887.         $json["user"]   =   $this->user->get_username();
  888.         $json["reputation"] =   $this->user->get_reputation();
  889.         $json["content"]    =   $this->content;
  890.         $json["timestamp"]  =   $this->timestamp;
  891.         $json["score"]      =   $this->get_score();
  892.         return $json;
  893.     }
  894. }
  895.  
  896. class UnsignedInteger{
  897.     private $value;
  898.     private $min;
  899.     private $max;
  900.    
  901.     public function __construct($value, $max=4294967295){
  902.         $this->max      =   $this->toInt($max);
  903.         $this->min      =   0;
  904.         $this->set($value);
  905.     }
  906.    
  907.     public function set($value){
  908.         $this->value    =   $this->toInt($value);
  909.         if($this->value > $this->max){
  910.             $this->value    =   $this->value%$this->max;
  911.         }
  912.         if($this->value < $this->min){
  913.             $this->value    =   $this->max + $this->value%$this->max;
  914.         }
  915.         return $this;
  916.     }
  917.    
  918.     public function get(){
  919.         return $this->value;
  920.     }
  921.    
  922.     private function toInt($value){
  923.         if(is_numeric($value)){
  924.             return floor($value + 0);
  925.         }else{
  926.             return 0;
  927.         }
  928.     }
  929. }
  930.  
  931. class Integer{
  932.     private $value;
  933.     private $min;
  934.     private $max;
  935.    
  936.     public function __construct($value, $max=2147483647, $min=-2147483647){
  937.         $this->max      =   $this->toInt($max);
  938.         $this->min      =   $this->toInt($min);
  939.         $this->set($value);
  940.     }
  941.    
  942.     public function set($value){
  943.         $this->value    =   $this->toInt($value);
  944.         if($this->value > $this->max){
  945.             $this->value    =   $this->value%$this->max;
  946.         }
  947.         if($this->value < $this->min){
  948.             $this->value    =   $this->max + $this->value%$this->max;
  949.         }
  950.         return $this;
  951.     }
  952.    
  953.     public function get(){
  954.         return $this->value;
  955.     }
  956.    
  957.     private function toInt($value){
  958.         if(is_numeric($value)){
  959.             return floor($value + 0);
  960.         }else{
  961.             return 0;
  962.         }
  963.     }
  964. }
  965. class UnsignedFloat{
  966.     private $value;
  967.     private $min;
  968.     private $max;
  969.    
  970.     public function __construct($value, $max=4294967295){
  971.         $this->max      =   $this->toFloat($max);
  972.         $this->min      =   0;
  973.         $this->set($value);
  974.     }
  975.    
  976.     public function set($value){
  977.         $this->value    =   $this->toFloat($value);
  978.         if($this->value > $this->max){
  979.             $this->value    =   $this->value%$this->max;
  980.         }
  981.         if($this->value < $this->min){
  982.             $this->value    =   $this->max + $this->value%$this->max;
  983.         }
  984.         return $this;
  985.     }
  986.    
  987.     public function get(){
  988.         return $this->value;
  989.     }
  990.    
  991.     private function toFloat($value){
  992.         if(is_numeric($value)){
  993.             return $value + 0;
  994.         }else{
  995.             return 0;
  996.         }
  997.     }
  998. }
  999.  
  1000. class Float{
  1001.     private $value;
  1002.     private $min;
  1003.     private $max;
  1004.    
  1005.     public function __construct($value, $max=2147483647, $min=-2147483647){
  1006.         $this->max      =   $this->toFloat($max);
  1007.         $this->min      =   $this->toFloat($min);
  1008.         $this->set($value);
  1009.     }
  1010.    
  1011.     public function set($value){
  1012.         $this->value    =   $this->toFloat($value);
  1013.         if($this->value > $this->max){
  1014.             $this->value    =   $this->value%$this->max;
  1015.         }
  1016.         if($this->value < $this->min){
  1017.             $this->value    =   $this->max + $this->value%$this->max;
  1018.         }
  1019.         return $this;
  1020.     }
  1021.    
  1022.     public function get(){
  1023.         return $this->value;
  1024.     }
  1025.    
  1026.     private function toInt($value){
  1027.         if(is_numeric($value)){
  1028.             return $value + 0;
  1029.         }else{
  1030.             return 0;
  1031.         }
  1032.     }
  1033. }
  1034.  
  1035. class Text{
  1036.     private $text;
  1037.     private $length;
  1038.    
  1039.     public function __construct($text, $length=255){
  1040.         $this->length       =   _uint($length);
  1041.         $this->set($text);
  1042.     }
  1043.    
  1044.     public function get(){
  1045.         return $this->text;
  1046.     }
  1047.    
  1048.     public function set($value){
  1049.         $value  =   (string) $value;
  1050.         $value  =   trim($value);
  1051.         $value  =   htmlspecialchars($value, ENT_QUOTES, "UTF-8");
  1052.         $value  =   strip_tags($value);
  1053.         //$value    =   escapeshellcmd($value);
  1054.         if(strlen($value) > $this->length){
  1055.             $this->text =   substr($value, 0, $this->length);
  1056.         }else{
  1057.             $this->text =   $value;
  1058.         }
  1059.         return $this;
  1060.     }
  1061. }
  1062.  
  1063. class HTML{
  1064.     private $text;
  1065.     private $length;
  1066.    
  1067.     public function __construct($text, $length=1024){
  1068.         $this->length       =   _uint($length);
  1069.         $this->set($text);
  1070.     }
  1071.    
  1072.     public function get(){
  1073.         return $this->text;
  1074.     }
  1075.    
  1076.     public function set($value){
  1077.         $value  =   (string) $value;
  1078.         $value  =   trim($value);
  1079.         $value  =   htmlspecialchars($value, ENT_QUOTES, "UTF-8");
  1080.         $value  =   strip_tags($value, "<p><a><img><div><span><table><tr><td><th><h2><h3><h4><blockquote><ul><ol><li>");
  1081.         //$value    =   escapeshellcmd($value);
  1082.        
  1083.         $dom = new DOMDocument;
  1084.         $dom->loadHTML($value);
  1085.        
  1086.         $nodes = $dom->getElementsByTagName('*');
  1087.         foreach($nodes as $node){
  1088.             if($node->hasAttributes()){
  1089.                 foreach($node->attributes as $attr){                       
  1090.                     $name   =   $attr->name;
  1091.                     $value  =   $attr->value;
  1092.                     switch($name){
  1093.                         case "id":      break;
  1094.                         case "style":   break;
  1095.                         case "src":     break;
  1096.                         case "alt":     break;
  1097.                         case "class":   break;
  1098.                         case "href":
  1099.                             if(strpos($value, "javascript") !== false){
  1100.                                 $node->removeAttribute($name);
  1101.                             }
  1102.                             break;
  1103.                         default:
  1104.                             $node->removeAttribute($name);
  1105.                             break;
  1106.                     }
  1107.                 }
  1108.             }
  1109.         }
  1110.        
  1111.         $value  =   $dom->saveXML($dom->documentElement->firstChild->firstChild->firstChild);
  1112.         $value  =   strip_tags($value, "<p><a><img><div><span><table><tr><td><th><h2><h3><h4><blockquote><ul><ol><li>");
  1113.         if(strlen($value) > $this->length){
  1114.             $this->text =   substr($value, 0, $this->length);
  1115.         }else{
  1116.             $this->text =   $value;
  1117.         }
  1118.         return $this;
  1119.     }
  1120. }
  1121.  
  1122. class StrictText{
  1123.     private $text;
  1124.     private $length;
  1125.    
  1126.     public function __construct($text, $length=255){
  1127.         $this->length       =   _uint($length);
  1128.         $this->set($text);
  1129.     }
  1130.    
  1131.     public function get(){
  1132.         return $this->text;
  1133.     }
  1134.    
  1135.     public function set($value){
  1136.         $value  =   (string) $value;
  1137.         $value  =   trim($value);
  1138.         $value  =   htmlspecialchars($value, ENT_QUOTES, "UTF-8");
  1139.         $value  =   strip_tags($value);
  1140.         //$value    =   escapeshellcmd($value);
  1141.         $value  =   preg_replace("/[^A-Za-z0-9 ]/", '', $value);
  1142.         if(strlen($value) > $this->length){
  1143.             $this->text =   substr($value, 0, $this->length);
  1144.         }else{
  1145.             $this->text =   $value;
  1146.         }
  1147.         return $this;
  1148.     }
  1149. }
  1150.  
  1151. class Password{
  1152.     private $text;
  1153.     private $security;
  1154.     private $salt;
  1155.    
  1156.     public function __construct($text, $salt=null, $security=2){
  1157.         $this->security =   _uint($security, 3);
  1158.         $this->set($text);
  1159.         if($salt == null){
  1160.             $this->salt =   _salt();
  1161.         }else{
  1162.             $this->salt =   $salt;
  1163.         }
  1164.     }
  1165.    
  1166.     public function get(){
  1167.         return $this->text;
  1168.     }
  1169.    
  1170.     public function set($text){
  1171.         $text   =   _text($text);
  1172.        
  1173.         if($this->security == 0){
  1174.             if(!ctype_graph($text)){
  1175.                 throw new Exception("Password contains whitespace");
  1176.             }
  1177.         }
  1178.        
  1179.         if($this->security > 0){
  1180.             if(strlen($text) < 8){
  1181.                 throw new Exception("Password cannot be less than 8 characters");
  1182.             }
  1183.         }
  1184.        
  1185.         if($this->security > 1){
  1186.             if(!preg_match('/[A-Za-z]/', $text) && !preg_match('/[0-9]/', $text)){
  1187.                 throw new Exception("Password must a contain number");
  1188.             }
  1189.         }
  1190.        
  1191.         if($this->security > 2){
  1192.             if(ctype_lower($text)){
  1193.                 throw new Exception("Password must contain a mix of uppercase and lowercase letters.");
  1194.             }
  1195.         }
  1196.        
  1197.         if($this->security > 3){
  1198.             if(ctype_alnum($text)){
  1199.                 throw new Exception("Password must contain a symbol");
  1200.             }
  1201.         }
  1202.        
  1203.         $this->text =   $this->hash($text, $this->salt);
  1204.     }
  1205.    
  1206.     function hash($value, $salt){
  1207.         $pepper =   "[censored]";
  1208.         $loopcount  =   [censored];
  1209.        
  1210.         for($i = 0; $i < $loopcount; $i++){
  1211.             $value  =   hash("sha256", $value . $salt . $pepper);
  1212.         }
  1213.        
  1214.         return $value;
  1215.     }
  1216. }
  1217.  
  1218. class Email{
  1219.     private $text;
  1220.    
  1221.     public function __construct($text){
  1222.         $this->set($text);
  1223.     }
  1224.    
  1225.     public function get(){
  1226.         return $this->text;
  1227.     }
  1228.    
  1229.     public function set($email){
  1230.         if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
  1231.             throw new Exception("Invalid email");
  1232.         }
  1233.         if(strlen(_text($email)) < 6){
  1234.             throw new Exception("Invalid email");
  1235.         }
  1236.         $this->text =   _text($email);
  1237.     }
  1238. }
  1239.  
  1240. class Enumerator{
  1241.     private $options;
  1242.     private $value;
  1243.     private $use_strict;
  1244.    
  1245.     public function __construct($options, $length=64, $use_strict=true){
  1246.         $this->use_strict   =   $use_strict;
  1247.         if(!is_array($options)){
  1248.             throw new Exception("Enumerator options must be in the form of an array");
  1249.         }
  1250.         foreach($options as $option){
  1251.             if($this->use_strict){
  1252.                 $this->options[]    =   _strict($option, $length);
  1253.             }else{
  1254.                 $this->options[]    =   _text($option, $length);
  1255.             }
  1256.         }
  1257.     }
  1258.    
  1259.     public function get(){
  1260.         return $this->value;
  1261.     }
  1262.    
  1263.     public function set($value){
  1264.         if($this->use_strict){
  1265.             $value  =   _strict($value);
  1266.         }else{
  1267.             $value  =   _text($value);
  1268.         }
  1269.         if(!in_array($value, $this->options)){
  1270.             throw new Exception("{$value} is not valid option");
  1271.         }
  1272.         $this->value    =   $value;
  1273.     }
  1274. }
  1275.  
  1276. function _uint($value,  $max=4294967295){
  1277.     $uint   =   new UnsignedInteger($value, $max);
  1278.     return $uint->get();
  1279. }
  1280.  
  1281. function _int($value, $max=2147483647, $min=-2147483647){
  1282.     $int    =   new Integer($value, $max, $min);
  1283.     return $int->get();
  1284. }
  1285.  
  1286. function _ufloat($value,  $max=4294967295){
  1287.     $ufloat =   new UnsignedFloat($value, $max);
  1288.     return $ufloat->get();
  1289. }
  1290.  
  1291. function _float($value, $max=2147483647, $min=-2147483647){
  1292.     $float  =   new Float($value, $max, $min);
  1293.     return $float->get();
  1294. }
  1295.  
  1296. function _text($text, $length=255){
  1297.     $text   =   new Text($text, $length);
  1298.     return $text->get();
  1299. }
  1300.  
  1301. function _strict($text, $length=255){
  1302.     $text   =   new StrictText($text, $length);
  1303.     return $text->get();
  1304. }
  1305.  
  1306. function _html($text, $length=255){
  1307.     $html   =   new HTML($text, $length);
  1308.     return $html->get();
  1309. }
  1310.  
  1311. function _salt(){
  1312.     $salt       =   dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647));
  1313.     return $salt;
  1314. }
  1315.  
  1316. function _password($value, $salt=null, $security=2){
  1317.     try{
  1318.         $password   =   new Password($value, $salt, $security);
  1319.         return $password->get();
  1320.     }catch(Exception $e){
  1321.         throw $e;
  1322.     }
  1323. }
  1324.  
  1325. function _email($value){
  1326.     try{
  1327.         $email  =   new Email($value);
  1328.         return $email->get();
  1329.     }catch(Exception $e){
  1330.         throw $e;
  1331.     }
  1332. }
  1333.  
  1334. function _enum($value, $options, $length=64, $use_strict=true){
  1335.     try{
  1336.         $enum   =   new Enumerator($options, $length, $use_strict);
  1337.         $enum->set($value);
  1338.         return $enum->get();
  1339.     }catch(Exception $e){
  1340.         throw $e;
  1341.     }
  1342. }
  1343.  
  1344. function _id($value){
  1345.     return _uint($value);
  1346. }
  1347.  
  1348. function _username($value){
  1349.     return _strict($value, 12);
  1350. }
  1351.  
  1352. function _points($value){
  1353.     return _uint($value);
  1354. }
  1355.  
  1356. function _about($text){
  1357.     return _html($text, 512);
  1358. }
  1359.  
  1360. function _rank($value){
  1361.     return _enum($value, array('free agent','recruit','corporal','sergeant','lieutenant','captain','general','admin','organiser','coordinator','overseer','deputy owner','owner'));
  1362. }
  1363.  
  1364. function _cape($value){
  1365.     return _enum($value, array('none', 'comp', 'trim'));
  1366. }
  1367.  
  1368. function _user($name, $db){
  1369.     $user   =   new User();
  1370.     return $user->getFromDatabaseByUsername(_username($name), $db);
  1371. }
  1372.  
  1373. function _user_id($id, $db){
  1374.     $user   =   new User();
  1375.     return $user->getFromDatabaseByID(_id($id), $db);
  1376. }
  1377.  
  1378. function _clan($name, $db){
  1379.     $clan   =   new Clan();
  1380.     return $clan->getFromDatabaseByName(_strict($name), $db);
  1381. }
  1382. function _clan_id($id, $db){
  1383.     $clan   =   new Clan();
  1384.     return $clan->getFromDatabaseByID(_id($id), $db);
  1385. }
  1386.  
  1387. function _tag($value){
  1388.     return _enum($value, array('melee', 'defence', 'ranged', 'prayer', 'magic', 'runecrafting', 'construction', 'dungeoneering', 'constitution', 'agility', 'herblore', 'thieving', 'crafting', 'fletching', 'slayer', 'hunter', 'divination', 'mining', 'smithing', 'fishing', 'cooking', 'firemaking', 'woodcutting', 'farming', 'summoning', 'minigames', 'distractions and diversions', 'combat', 'runescape 3', 'old school runescape', 'runescape classic', 'monster hunting', 'moneymaking', 'technical', 'general', 'security', 'spreadsheets', 'meta'));
  1389. }
  1390.  
  1391. function _encrypt($text){
  1392.     $key    =   "[censored]";
  1393.     $output =   "";
  1394.    
  1395.     for($i = 0; $i < strlen($text); $i++){
  1396.         for($j=0; $j < strlen($key); $j++, $i++){
  1397.             $output .=  $text[$i] ^ $key[$j];
  1398.         }
  1399.     }
  1400.     return $output;
  1401. }
  1402.  
  1403. function _decrypt($text){
  1404.     $key    =   "[censored]";
  1405.     $output =   "";
  1406.    
  1407.     for($i = 0; $i < strlen($text); $i++){
  1408.         for($j=0; $j < strlen($key); $j++, $i++){
  1409.             $output .=  $key[$j] ^ $text[$i];
  1410.         }
  1411.     }
  1412.     return $output;
  1413. }
  1414. ?>
Advertisement
Add Comment
Please, Sign In to add comment