Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. <?php
  2. require_once('../local/config.php');
  3.  
  4. require_once('../include/auth.php');
  5. include('../include/CHILIService.php');
  6.  
  7. $apikey = $_SESSION['API_KEY'];
  8. $chiliservice = new SoapClient('http://'.CHILISERVER.'/chili/Main.asmx?WSDL');
  9.  
  10.  
  11. $searchstring = $_GET['itemID'];
  12.  
  13. function insertAnnosOnPage($chiliservice,$apikey,$searchstring) {
  14.  
  15. /*
  16. $username = FOTOWEBUSER;
  17. $password = FOTOWEBPASSWORD;
  18.  
  19. $FWSession = generateFotowebSessionCookie($username,$password);
  20.  
  21. // SEARCH
  22. $searchurl = "http://" . FOTOWEBSERVER . "/fotoweb/fwbin/fotoweb_isapi.dll/ArchiveAgent/" . FOTOWEBBILDEARKIV . "/Search?Search=" . $searchstring . "&MetaData=1&FileInfo=1&PreviewSize=200&MaxHits=" . FOTOWEBMAXHITS . "u=" . FOTOWEBUSER . "&p=" . FOTOWEBPASSWORD;
  23.  
  24. */
  25.  
  26. // Create a Fotoweb login session cookie
  27. $FWSession = generateFotowebSessionCookie(FOTOWEBUSER,FOTOWEBPASSWORD);
  28.  
  29.  
  30.  
  31. //$searchstring = urlencode($_GET['search']);
  32. $username = FOTOWEBUSER;
  33. $password = FOTOWEBPASSWORD;
  34.  
  35. // Create a Fotoweb login session cookie
  36. $FWSession = generateFotowebSessionCookie($username,$password);
  37. if (isset($_GET['debug'])) {
  38. echo $FWSession;
  39. }
  40.  
  41. $searchurl = "http://" . FOTOWEBSERVER . "/fotoweb/fwbin/fotoweb_isapi.dll/ArchiveAgent/" . FOTOWEBBILDEARKIV . "/Search?Search=" . $searchstring . "&MetaData=1&FileInfo=1&PreviewSize=200&MaxHits=" . FOTOWEBMAXHITS . "&u=" . $username . "&p=" . $password;
  42.  
  43. $ch = curl_init($searchurl);
  44. $timeout = 5;
  45. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  46. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  47. curl_setopt($ch,CURLOPT_COOKIE, "FWSESSION=".$FWSession);
  48. $data = curl_exec($ch);
  49. curl_close($ch);
  50.  
  51. $theHits = simplexml_load_string($data);
  52. foreach ($theHits as $hit) {
  53. $fotowebIDforAnno = (string)$hit['Id'];
  54. }
  55.  
  56. if ($fotowebIDforAnno != "") {
  57. //echo "/Download?Id=" . $fotowebIDforAnno;
  58. $url = "http://" . FOTOWEBSERVER . "/fotoweb/fwbin/fotoweb_isapi.dll/ArchiveAgent/" . FOTOWEBBILDEARKIV . "/Download?Id=" . $fotowebIDforAnno . "&NoAttachment=1" . "&u=" . $username . "&p=" . $password;
  59.  
  60. // Upload the image and get its new id and name
  61. //echo "Trying to fetch anno " . $searchstring . "<br>";
  62. try {
  63. $assetXML = uploadItemToCHILI($chiliservice,$apikey,$searchstring,'test',$url);
  64. $ResourceItemGetURLDOM=new SimpleXMLElement($assetXML);
  65. $xml = $ResourceItemGetURLDOM->asXML();
  66. $res = $ResourceItemGetURLDOM->xpath("//item/@id");
  67. $img = $res[0]->id;
  68. echo $img ;
  69.  
  70.  
  71.  
  72. // insert Image into chilidoc.
  73. // strat to get the ID
  74.  
  75. } catch (SoapFault $fault) {
  76. //echo "Anno " . $searchstring . " COULD NOT BE fetched from Fotoweb!<br>";
  77. //echo $fault;
  78.  
  79. }
  80. } else {
  81. //echo 'no hits';
  82. }
  83.  
  84. }
  85.  
  86.  
  87. function generateFotowebSessionCookie($u,$p) {
  88. $loginurl = "http://" . FOTOWEBSERVER . "/fotoweb/cmdrequest/Login.fwx?u=" . $u . "&p=" . $p;
  89. $ch = curl_init($loginurl);
  90. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  91. curl_setopt($ch, CURLOPT_HEADER, 1);
  92. preg_match('/^Set-Cookie: (.*?);/m', curl_exec($ch), $m);
  93. curl_close($ch);
  94. return substr($m[1],10);
  95. }
  96.  
  97.  
  98. function uploadItemToCHILI($chiliservice,$apikey,$newitemname,$newitempath,$url) {
  99. $xml_request = new ResourceItemAddFromURL();
  100. $xml_request->apiKey = $apikey;
  101. $xml_request->resourceName = "Assets";
  102. $xml_request->newName = $newitemname;
  103. $xml_request->folderPath = $newitempath;
  104. $xml_request->url = $url;
  105. $xml_request->login = "";
  106. $xml_request->pw = "";
  107. $xml_request->reuseExisting = true;
  108. $xml_request->previewFileURL = "";
  109. $xml_request->previewExtension = "";
  110. $xml_request->isPermanentPreview = false;
  111.  
  112. $result = $chiliservice->ResourceItemAddFromURL($xml_request);
  113. return $result->ResourceItemAddFromURLResult;
  114. }
  115.  
  116. insertAnnosOnPage($chiliservice,$apikey,$searchstring);
  117.  
  118.  
  119. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement