Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function filePathParts($link) {
- $xmlFile = pathinfo($link);
- return $xmlFile;
- }
- function Get_HTML ($url)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
- $ip=rand(0,255).'.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip"));
- 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");
- $html = curl_exec($ch);
- curl_close($ch);
- return $html;
- }
- // Delete full folder
- function delTree($dir) {
- $files = array_diff(scandir($dir), array('.','..'));
- foreach ($files as $file) {
- (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
- }
- return rmdir($dir);
- }
- function CreateXML($repo)
- {
- $dirs = array_filter(glob('*'), 'is_dir');
- //$ads = "Abeksis Repo";
- $ads = "";
- $docList = new DomDocument('1.0', 'UTF-8');
- $docList->xmlStandalone = true;
- $docList->formatOutput = true;
- $root = $docList->createElement('addons');
- $docList->appendChild($root);
- foreach($dirs as $filename)
- {
- if (!file_exists($filename.'/addon.xml'))
- continue;
- // if (stripos($filename,'resource.language') !== false)
- // continue;
- $doc = new DOMDocument();
- $doc->load($filename.'/addon.xml');
- $root2 = $doc->documentElement;
- // Set AD in description
- $xpath = new DOMXpath($doc);
- $meta = $xpath->query('/addon/extension[@point="xbmc.addon.metadata"]')->item(0);
- $old = $xpath->query("/addon/extension/description[@lang='he']");
- $tmp = $old->item(0);
- /* $new = $doc->createElement("description");
- $new->setAttribute('lang', 'he');
- // If hebrew exist.
- if ($old->length > 0)
- {
- $new->nodeValue = $old->item(0)->nodeValue."\n".$ads;
- $tmp->parentNode->removeChild($tmp);
- }
- else
- $new->nodeValue = $ads;
- $meta->appendChild($new);
- */
- $xmlString = $doc->saveXML($doc->documentElement);
- $xpath = new DOMXPath($doc);
- $query = "//addon"; // this is the name of the ROOT element
- $nodelist = $xpath->evaluate($query, $doc->documentElement);
- if( $nodelist->length > 0 ) {
- $node = $docList->importNode($nodelist->item(0), true);
- $root->appendChild($node);
- }
- }
- $docList->save($repo);
- file_put_contents($repo.".md5",md5_file($repo));
- file_put_contents($repo.".gz",gzencode(file_get_contents($repo),9));
- echo "\n Create: $repo";
- }
- function GetAddon($addon,$FOLDER,$redirect=1)
- {
- echo "\n......Addon:".$addon["id"]." - ".$addon["version"];
- $addon_files = array("addon.xml","changelog.txt","icon.png","fanart.jpg");
- // Download addon zip file
- copy ($addon["zip"],$FOLDER."/".basename($addon["zip"]));
- // Create addon folder
- if (!file_exists($addon["id"]))
- mkdir ($addon["id"],0777);
- // Extract files needed from zip
- $zip = new ZipArchive;
- $res = $zip->open($FOLDER."/".basename($addon["zip"]));
- if ($res === TRUE) {
- $i=0;
- while($item_name = $zip->getNameIndex($i)){
- if (basename($addon["zip"])=="master.zip")
- $zip->renameIndex( $i, preg_replace( "/(^.*)-master/", $addon["id"], $item_name ) );
- if (strpos($item_name, ".git") !== false)
- $zip->deleteIndex($i);
- // Copy needed files from zip
- if (in_array(basename($item_name),$addon_files))
- $zip->extractTo(".",$addon["id"]."/".basename($item_name));
- $i++;
- }
- $zip->close();
- }
- // Copy zip file
- $local = $addon["id"]."/".$addon["id"]."-".$addon["version"];
- if (file_exists($FOLDER."/".basename($addon["zip"])))
- copy ($FOLDER."/".basename($addon["zip"]),$local.".zip");
- elseif (file_exists($FOLDER."/".basename($addon["zip"])."-master"))
- copy ($FOLDER."/".basename($addon["zip"])."-master",$local.".zip");
- else
- return 0;
- // Create md5 to zip file
- file_put_contents($local.".zip.md5",md5_file($local.".zip"));
- // Redirect to external server
- if (!(basename($addon["zip"])=="master.zip"))
- {
- // Create .htaccess
- if (file_exists($addon["id"]."/".'.htaccess'))
- unlink($addon["id"]."/".'.htaccess');
- $fp = fopen($addon["id"]."/".'.htaccess','a+');
- if($fp){
- fwrite($fp,'RewriteEngine On
- RewriteRule ^(.+\.zip)$ '.$addon["zip"].' [R=302,NC,L]');
- fclose($fp);
- }
- file_put_contents($addon["id"]."/url.txt",$addon["zip"]);
- // Rename zip file
- $file_parts = filePathParts($addon["id"]."/".basename($addon["zip"]));
- rename($addon["id"]."/".basename($addon["zip"]),$addon["id"]."/".$file_parts['filename']."_.".$file_parts['extension']);
- }
- }
- function GetSelfAddonVersion($xml_url)
- {
- $html = file_get_contents($xml_url);
- if($html === FALSE)
- return 0;
- $doc = new DOMDocument();
- $doc->loadXML($html);
- $root = $doc->documentElement;
- $xpath = new DOMXpath($doc);
- $version = $xpath->query('/addon')->item(0)->getAttribute("version");
- return $version;
- }
- $repo = Array();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement