Advertisement
abeksis

sdfsdf

Oct 14th, 2015
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. <?php
  2.  
  3. function filePathParts($link) {
  4. $xmlFile = pathinfo($link);
  5. return $xmlFile;
  6. }
  7.  
  8. function Get_HTML ($url)
  9. {
  10. $ch = curl_init();
  11. curl_setopt($ch, CURLOPT_URL, $url);
  12. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  13. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  14. $ip=rand(0,255).'.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255);
  15. curl_setopt($ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip"));
  16. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/".rand(3,5).".".rand(0,3)." (Windows NT ".rand(3,5).".".rand(0,2)."; rv:2.0.1) Gecko/20100101 Firefox/".rand(3,5).".0.1");
  17. $html = curl_exec($ch);
  18. curl_close($ch);
  19. return $html;
  20. }
  21.  
  22. // Delete full folder
  23. function delTree($dir) {
  24. $files = array_diff(scandir($dir), array('.','..'));
  25. foreach ($files as $file) {
  26. (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
  27. }
  28. return rmdir($dir);
  29. }
  30.  
  31. function CreateXML($repo)
  32. {
  33. $dirs = array_filter(glob('*'), 'is_dir');
  34. //$ads = "Abeksis Repo";
  35. $ads = "";
  36.  
  37. $docList = new DomDocument('1.0', 'UTF-8');
  38. $docList->xmlStandalone = true;
  39. $docList->formatOutput = true;
  40.  
  41. $root = $docList->createElement('addons');
  42. $docList->appendChild($root);
  43.  
  44. foreach($dirs as $filename)
  45. {
  46. if (!file_exists($filename.'/addon.xml'))
  47. continue;
  48. // if (stripos($filename,'resource.language') !== false)
  49. // continue;
  50. $doc = new DOMDocument();
  51. $doc->load($filename.'/addon.xml');
  52. $root2 = $doc->documentElement;
  53.  
  54. // Set AD in description
  55. $xpath = new DOMXpath($doc);
  56. $meta = $xpath->query('/addon/extension[@point="xbmc.addon.metadata"]')->item(0);
  57. $old = $xpath->query("/addon/extension/description[@lang='he']");
  58. $tmp = $old->item(0);
  59.  
  60. /* $new = $doc->createElement("description");
  61. $new->setAttribute('lang', 'he');
  62.  
  63. // If hebrew exist.
  64. if ($old->length > 0)
  65. {
  66. $new->nodeValue = $old->item(0)->nodeValue."\n".$ads;
  67. $tmp->parentNode->removeChild($tmp);
  68. }
  69. else
  70. $new->nodeValue = $ads;
  71. $meta->appendChild($new);
  72. */
  73.  
  74. $xmlString = $doc->saveXML($doc->documentElement);
  75.  
  76. $xpath = new DOMXPath($doc);
  77. $query = "//addon"; // this is the name of the ROOT element
  78.  
  79. $nodelist = $xpath->evaluate($query, $doc->documentElement);
  80.  
  81. if( $nodelist->length > 0 ) {
  82. $node = $docList->importNode($nodelist->item(0), true);
  83. $root->appendChild($node);
  84. }
  85.  
  86. }
  87.  
  88. $docList->save($repo);
  89. file_put_contents($repo.".md5",md5_file($repo));
  90. file_put_contents($repo.".gz",gzencode(file_get_contents($repo),9));
  91. echo "\n Create: $repo";
  92. }
  93.  
  94. function GetAddon($addon,$FOLDER,$redirect=1)
  95. {
  96. echo "\n......Addon:".$addon["id"]." - ".$addon["version"];
  97. $addon_files = array("addon.xml","changelog.txt","icon.png","fanart.jpg");
  98.  
  99. // Download addon zip file
  100. copy ($addon["zip"],$FOLDER."/".basename($addon["zip"]));
  101.  
  102. // Create addon folder
  103. if (!file_exists($addon["id"]))
  104. mkdir ($addon["id"],0777);
  105.  
  106. // Extract files needed from zip
  107. $zip = new ZipArchive;
  108. $res = $zip->open($FOLDER."/".basename($addon["zip"]));
  109. if ($res === TRUE) {
  110. $i=0;
  111. while($item_name = $zip->getNameIndex($i)){
  112. if (basename($addon["zip"])=="master.zip")
  113. $zip->renameIndex( $i, preg_replace( "/(^.*)-master/", $addon["id"], $item_name ) );
  114. if (strpos($item_name, ".git") !== false)
  115. $zip->deleteIndex($i);
  116. // Copy needed files from zip
  117. if (in_array(basename($item_name),$addon_files))
  118. $zip->extractTo(".",$addon["id"]."/".basename($item_name));
  119. $i++;
  120. }
  121.  
  122. $zip->close();
  123. }
  124.  
  125. // Copy zip file
  126. $local = $addon["id"]."/".$addon["id"]."-".$addon["version"];
  127. if (file_exists($FOLDER."/".basename($addon["zip"])))
  128. copy ($FOLDER."/".basename($addon["zip"]),$local.".zip");
  129. elseif (file_exists($FOLDER."/".basename($addon["zip"])."-master"))
  130. copy ($FOLDER."/".basename($addon["zip"])."-master",$local.".zip");
  131. else
  132. return 0;
  133.  
  134. // Create md5 to zip file
  135. file_put_contents($local.".zip.md5",md5_file($local.".zip"));
  136.  
  137. // Redirect to external server
  138. if (!(basename($addon["zip"])=="master.zip"))
  139. {
  140. // Create .htaccess
  141. if (file_exists($addon["id"]."/".'.htaccess'))
  142. unlink($addon["id"]."/".'.htaccess');
  143. $fp = fopen($addon["id"]."/".'.htaccess','a+');
  144. if($fp){
  145. fwrite($fp,'RewriteEngine On
  146. RewriteRule ^(.+\.zip)$ '.$addon["zip"].' [R=302,NC,L]');
  147. fclose($fp);
  148. }
  149. file_put_contents($addon["id"]."/url.txt",$addon["zip"]);
  150.  
  151. // Rename zip file
  152. $file_parts = filePathParts($addon["id"]."/".basename($addon["zip"]));
  153. rename($addon["id"]."/".basename($addon["zip"]),$addon["id"]."/".$file_parts['filename']."_.".$file_parts['extension']);
  154. }
  155. }
  156.  
  157. function GetSelfAddonVersion($xml_url)
  158. {
  159. $html = file_get_contents($xml_url);
  160. if($html === FALSE)
  161. return 0;
  162. $doc = new DOMDocument();
  163.  
  164. $doc->loadXML($html);
  165. $root = $doc->documentElement;
  166.  
  167. $xpath = new DOMXpath($doc);
  168. $version = $xpath->query('/addon')->item(0)->getAttribute("version");
  169. return $version;
  170. }
  171.  
  172. $repo = Array();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement