PageRenderTime 55ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/code/web/public_php/app/app_achievements_admin/class/AdmAtom_class.php

https://bitbucket.org/ryzom/ryzomcore
PHP | 347 lines | 223 code | 59 blank | 65 comment | 18 complexity | 548a79ccd60368eeecab8b5a16f1ab88 MD5 | raw file
Possible License(s): Apache-2.0, AGPL-3.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. class AdmAtom extends Node implements ADM {
  3. #########################
  4. # PHP 5.3 compatible
  5. # AdmDispatcher_trait replaces this in PHP 5.4
  6. function insertNode($n) {
  7. $n->setParent($this);
  8. $n->insert();
  9. $this->addChild($n);
  10. }
  11. function removeNode($id) {
  12. $res = $this->getChildDataByID($id);
  13. if($res != null) {
  14. $res->delete_me();
  15. $this->removeChild($id);
  16. }
  17. }
  18. function updateNode($id) { // PROBABLY USELESS!
  19. $res = $this->getChildDataByID($id);
  20. if($res != null) {
  21. $res->update();
  22. }
  23. }
  24. function getPathID($path = "") {
  25. if($path != "") {
  26. $path = ";".$path;
  27. }
  28. $path = $this->getID().$path;
  29. if($this->parent != null) {
  30. return $this->parent->getPathID($path);
  31. }
  32. return $path;
  33. }
  34. function getElementByPath($pid) {
  35. $tmp = explode(";",$pid);
  36. if($tmp[0] == $this->getID()) {
  37. if(sizeof($tmp) > 1) {
  38. $c = $this->getChildDataByID($tmp[1]);
  39. if($c != null) {
  40. unset($tmp[0]);
  41. return $c->getElementByPath(implode(";",$tmp));
  42. }
  43. return null;
  44. }
  45. else {
  46. return $this;
  47. }
  48. }
  49. return null;
  50. }
  51. #########################
  52. protected $objective;
  53. protected $mandatory;
  54. protected $ruleset;
  55. protected $ruleset_parsed;
  56. protected $parent_id;
  57. function AdmAtom($data,$parent) {
  58. $this->parent = $parent;
  59. $this->id = $data['atom_id'];
  60. $this->objective = $data['atom_objective'];
  61. $this->mandatory = $data['atom_mandatory'];
  62. $this->ruleset = $data['atom_ruleset'];
  63. $this->ruleset_parsed = $data['atom_ruleset_parsed'];
  64. }
  65. function delete_me() { // aaaaand... it's gone ^^
  66. global $DBc;
  67. $DBc->sqlQuery("DELETE FROM ach_atom WHERE atom_id='".$this->id."'");
  68. $DBc->sqlQuery("DELETE FROM ach_player_atom WHERE apa_atom='".$this->id."'");
  69. }
  70. function update() { // write updated data to database
  71. global $DBc;
  72. $DBc->sqlQuery("UPDATE ach_atom SET atom_mandatory='".$this->getMandatory()."',atom_ruleset='".$DBc->sqlEscape($this->getRuleset())."',atom_ruleset_parsed='".$DBc->sqlEscape($this->getRulesetParsed())."' WHERE atom_id='".$this->id."'");
  73. }
  74. function insert() { // insert atoms as new row
  75. global $DBc;
  76. $DBc->sqlQuery("INSERT INTO ach_atom (atom_objective,atom_mandatory,atom_ruleset,atom_ruleset_parsed) VALUES ('".$this->getObjective()."','".$this->getMandatory()."','".$DBc->sqlEscape($this->getRuleset())."','".$DBc->sqlEscape($this->getRulesetParsed())."')");
  77. $id = $DBc->insertID();
  78. $this->setID($id);
  79. }
  80. function getObjective() {
  81. return $this->objective;
  82. }
  83. function setObjective($o) {
  84. $this->objective = $o;
  85. }
  86. function setMandatory($ft) {
  87. if($ft == true) {
  88. $this->mandatory = 1;
  89. }
  90. else {
  91. $this->mandatory = 0;
  92. }
  93. }
  94. function setRuleset($r) {
  95. $this->ruleset = $r;
  96. $this->parse();
  97. }
  98. function getMandatory() {
  99. return $this->mandatory;
  100. }
  101. function isMandatory() {
  102. return ($this->mandatory == 1);
  103. }
  104. function getRuleset() {
  105. return $this->ruleset;
  106. }
  107. function getRulesetParsed() {
  108. return $this->ruleset_parsed;
  109. }
  110. private function parse() { // parsing the ruleset
  111. /*
  112. VALUE _money AS $money {
  113. CACHE blach AS $test;
  114. if($money >= 10000 && $test == 0) {
  115. RESET;
  116. GRANT $money UNTIL TIMER:3600;
  117. FINAL;
  118. }
  119. else {
  120. CACHE blach SET $money;
  121. }
  122. SCRIPT wealth($money) AS $res;
  123. if($res == "lol") {
  124. DENY;
  125. }
  126. }
  127. ENTITY _pos AS $pos {
  128. SCRIPT inside($pos,"majestic_garden") AS $region;
  129. if($region == true) {
  130. GRANT;
  131. }
  132. }
  133. */
  134. $res = $this->ruleset;
  135. #VALUE ([^ ]+) AS ([$][^ ]+) {#
  136. $match = array();
  137. preg_match_all("#VALUE ([^ ]+) AS ([$][^ ]+) {#",$this->ruleset,$match);
  138. foreach($match[0] as $key=>$elem) {
  139. $func = "_".md5(microtime());
  140. $tmp = '$this->registerValue("'.$match[1][$key].'","'.$func.'");
  141. function '.$func.'('.$match[2][$key].',$_P,$_CB) {
  142. global $_CACHE;
  143. $_IDENT = "'.$match[1][$key].'";';
  144. //replace
  145. $res = str_replace($elem,$tmp,$res);
  146. }
  147. #ENTITY ([^ ]+) AS ([$][^ ]+) {#
  148. $match = array();
  149. preg_match_all("#ENTITY ([^ ]+) AS ([$][^ ]+) {#",$this->ruleset,$match);
  150. foreach($match[0] as $key=>$elem) {
  151. $func = "_".md5(microtime());
  152. $tmp = '$this->registerEntity("'.$match[1][$key].'","'.$func.'");
  153. function '.$func.'('.$match[2][$key].',$_P,$_CB) {
  154. global $_CACHE;
  155. $_IDENT = "'.$match[1][$key].'";';
  156. //replace
  157. $res = str_replace($elem,$tmp,$res);
  158. }
  159. #EVENT ([^ ]+) AS ([$][^ ]+) {#
  160. $match = array();
  161. preg_match_all("#EVENT ([^ ]+) AS ([$][^ ]+) {#",$this->ruleset,$match);
  162. foreach($match[0] as $key=>$elem) {
  163. $func = "_".md5(microtime());
  164. $tmp = '$this->registerEvent("'.$match[1][$key].'","'.$func.'");
  165. function '.$func.'('.$match[2][$key].',$_P,$_CB) {
  166. global $_CACHE;
  167. $_IDENT = "'.$match[1][$key].'";';
  168. //replace
  169. $res = str_replace($elem,$tmp,$res);
  170. }
  171. #GRANT ([^;]*);#
  172. $match = array();
  173. preg_match_all("#GRANT ([^;]*);#",$this->ruleset,$match);
  174. foreach($match[0] as $key=>$elem) {
  175. $tmp = '$_P->grant('.$match[1][$key].');';
  176. //replace
  177. $res = str_replace($elem,$tmp,$res);
  178. }
  179. #GRANT;#
  180. $match = array();
  181. preg_match_all("#GRANT;#",$this->ruleset,$match);
  182. foreach($match[0] as $elem) {
  183. $tmp = '$_P->grant();';
  184. //replace
  185. $res = str_replace($elem,$tmp,$res);
  186. }
  187. #DENY;#
  188. $match = array();
  189. preg_match_all("#DENY;#",$this->ruleset,$match);
  190. foreach($match[0] as $elem) {
  191. $tmp = '$_P->deny();';
  192. //replace
  193. $res = str_replace($elem,$tmp,$res);
  194. }
  195. #UNLOCK;#
  196. $match = array();
  197. preg_match_all("#UNLOCK;#",$this->ruleset,$match);
  198. foreach($match[0] as $elem) {
  199. $tmp = '$_P->unlock();';
  200. //replace
  201. $res = str_replace($elem,$tmp,$res);
  202. }
  203. #RESET;#
  204. $match = array();
  205. preg_match_all("#RESET;#",$this->ruleset,$match);
  206. foreach($match[0] as $elem) {
  207. $tmp = '$_P->reset_();';
  208. //replace
  209. $res = str_replace($elem,$tmp,$res);
  210. }
  211. #UNLOCK_ALL;#
  212. $match = array();
  213. preg_match_all("#UNLOCK_ALL;#",$this->ruleset,$match);
  214. foreach($match[0] as $elem) {
  215. $tmp = '$_P->unlock_all();';
  216. //replace
  217. $res = str_replace($elem,$tmp,$res);
  218. }
  219. #RESET_ALL;#
  220. $match = array();
  221. preg_match_all("#RESET_ALL;#",$this->ruleset,$match);
  222. foreach($match[0] as $elem) {
  223. $tmp = '$_P->reset_all();';
  224. //replace
  225. $res = str_replace($elem,$tmp,$res);
  226. }
  227. #FINAL VALUE;#
  228. $match = array();
  229. preg_match_all("#FINAL VALUE;#",$this->ruleset,$match);
  230. foreach($match[0] as $elem) {
  231. $tmp = '$_P->unregisterValue($_IDENT,$_CB);';
  232. //replace
  233. $res = str_replace($elem,$tmp,$res);
  234. }
  235. #FINAL ENTITY;#
  236. $match = array();
  237. preg_match_all("#FINAL ENTITY;#",$this->ruleset,$match);
  238. foreach($match[0] as $elem) {
  239. $tmp = '$_P->unregisterEntity($_IDENT,$_CB);';
  240. //replace
  241. $res = str_replace($elem,$tmp,$res);
  242. }
  243. #FINAL EVENT;#
  244. $match = array();
  245. preg_match_all("#FINAL EVENT;#",$this->ruleset,$match);
  246. foreach($match[0] as $elem) {
  247. $tmp = '$_P->unregisterEvent($_IDENT,$_CB);';
  248. //replace
  249. $res = str_replace($elem,$tmp,$res);
  250. }
  251. #CACHE ([^ ]+) AS ([$][^ ]+);#
  252. $match = array();
  253. preg_match_all("#CACHE ([^ ]+) AS ([$][^;]+);#",$this->ruleset,$match);
  254. foreach($match[0] as $key=>$elem) {
  255. $tmp = $match[2][$key].' = $_CACHE->getData(\''.$match[1][$key].'\');';
  256. //replace
  257. $res = str_replace($elem,$tmp,$res);
  258. }
  259. #CACHE ([^ ]+) SET ([$][^ ]+);#
  260. $match = array();
  261. preg_match_all("#CACHE ([^ ]+) SET ([$][^;]+);#",$this->ruleset,$match);
  262. foreach($match[0] as $key=>$elem) {
  263. $tmp = '$_CACHE->writeData(\''.$match[1][$key].'\','.$match[2][$key].');';
  264. //replace
  265. $res = str_replace($elem,$tmp,$res);
  266. }
  267. #SCRIPT ([^ ]+) AS ([$][^ ]+);#
  268. $match = array();
  269. preg_match_all("#SCRIPT ([^\(]+)\(([^\)]*)\) AS ([$][^;]+);#",$this->ruleset,$match);
  270. foreach($match[0] as $key=>$elem) {
  271. $tmp = '@include_once("script/'.$match[1][$key].'_script.php");
  272. '.$match[3][$key].' = '.$match[1][$key].'('.$match[2][$key].');';
  273. //replace
  274. $res = str_replace($elem,$tmp,$res);
  275. }
  276. $this->ruleset_parsed = $res;
  277. }
  278. }
  279. ?>