Guest User

php

a guest
Mar 15th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. <?php
  2. $pluginslist = array();
  3. $pluginslist[] = "gkplugins_picasaweb.php";
  4.  
  5. $domainAllowXHR = array();
  6. $domainAllowXHR[] = "http://localhost";
  7. for($i=0;$i<count($domainAllowXHR);$i++){
  8. if($domainAllowXHR[$i]=="*"){
  9. header("Access-Control-Allow-Origin: *");
  10. break;
  11. }
  12. if(isset($_SERVER["HTTP_ORIGIN"]) && $_SERVER["HTTP_ORIGIN"]==$domainAllowXHR[$i]){
  13. header("Access-Control-Allow-Origin: ".$domainAllowXHR[$i]);
  14. break;
  15. }
  16. }
  17. for($i=0;$i<count($pluginslist);$i++){
  18. if(!file_exists($pluginslist[$i])){
  19. exit(json_encode(array("error"=>$pluginslist[$i]." does not exist")));
  20. }
  21. require_once($pluginslist[$i]);
  22. }
  23.  
  24. $link = isset($_POST['link'])?$_POST['link']:NULL;
  25. $data = isset($_POST['data'])?$_POST['data']:NULL;
  26.  
  27. $gkphp;
  28. if($link || $data){
  29. $gkphp = new gkpluginsphp();
  30. $gkphp->pluginsList = $pluginslist;
  31. $gkphp->onComplete = "returnToClient";
  32. if($link){
  33. $gkphp->requestLink = $link;
  34. }
  35. if($data){
  36. $gkphp->requestData = $data;
  37. }
  38. $gkphp->begin();
  39. }
  40.  
  41. function returnToClient($obj){
  42. global $gkphp;
  43. if($gkphp->errorMsg && $gkphp->errorMsg!=""){
  44. $rse = array("error"=>$gkphp->errorMsg);
  45. echo json_encode($rse);
  46. }else{
  47. echo json_encode($obj);
  48. }
  49. }
  50.  
  51.  
  52.  
  53. class gkpluginsphp {
  54. public $pluginsList;
  55. public $requestLink;
  56. public $requestData;
  57. public $onComplete;
  58. public $errorMsg;
  59.  
  60. private $countPluginRun;
  61. private $curPlugin;
  62. private $curReqObj;
  63.  
  64. public function gkpluginsphp(){
  65. $this->countPluginRun = 0;
  66. }
  67.  
  68. public function encryptLink($link){
  69. return $link;
  70. }
  71.  
  72. public function decryptLink($link){
  73. return $link;
  74. }
  75.  
  76. public function begin(){
  77. if(count($this->pluginsList)==0){
  78. $this->errorMsg = "no plugin in pluginslist";
  79. $this->returnToClient();
  80. return;
  81. }
  82. $link = $this->requestLink;
  83. $data = $this->requestData;
  84. if($data){
  85. $data = str_replace(" ","+",$data);
  86. $data = base64_decode($data);
  87. $data = json_decode($data,true);
  88. if(strpos($data["link"],"://")===false){
  89. $data["link"] = $this->decryptLink($data["link"]);
  90. }
  91. $this->curReqObj = $data;
  92. $this->runPlugins();
  93. }else if($link){
  94. $link = str_replace(" ","+",$link);
  95. if(strpos($link,"://")===false){
  96. $link = $this->decryptLink($link);
  97. }
  98. $this->curReqObj = array("link"=>$link);
  99. $this->runPlugins();
  100. }else{
  101. $this->returnToClient();
  102. }
  103. }
  104.  
  105. private function runPlugins(){
  106. $this->curPlugin = $this->pluginsList[$this->countPluginRun];
  107. $this->curPlugin = substr($this->curPlugin,0,-4);
  108. $this->curPlugin = new $this->curPlugin();
  109. $this->curPlugin->onFinish = array($this,"onFinish");
  110. $this->curPlugin->funcEncrypt = array($this,"encryptLink");
  111. $this->curPlugin->errorMsg = $this->errorMsg;
  112. $this->curPlugin->requestObj = $this->curReqObj;
  113. $this->curPlugin->beginPlugins();
  114. }
  115.  
  116. public function onFinish(){
  117. $this->curReqObj = $this->curPlugin->requestObj;
  118. $this->errorMsg = $this->curPlugin->errorMsg;
  119. $this->countPluginRun++;
  120. if($this->countPluginRun>=count($this->pluginsList)){
  121. $this->returnToClient();
  122. return;
  123. }
  124. $this->runPlugins();
  125. }
  126.  
  127. private function returnToClient(){
  128. call_user_func($this->onComplete,$this->curReqObj);
  129. }
  130. }
  131. /* © 2015 gkplugins */
  132. ?>
Add Comment
Please, Sign In to add comment