PageRenderTime 50ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/ xvweb/doctohtml.php

http://xvweb.googlecode.com/
PHP | 91 lines | 73 code | 17 blank | 1 comment | 5 complexity | 3a379d9685768f57a5243135df5cfd2d MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, LGPL-3.0
  1. <?php
  2. header("Cache-Control: no-cache, must-revalidate");
  3. LoadLang('edit');
  4. include_once($XVwebDir.'libraries'.DIRECTORY_SEPARATOR.'phpQuery'.DIRECTORY_SEPARATOR.'phpQuery.php');
  5. $Smarty->assign('WriteUrlArticle', true);
  6. if(!(xvPerm('WriteArticle'))){ // Brak dostepu
  7. header("location: ".$URLS['Script'].'System/AccessDenied/');
  8. exit;
  9. }
  10. if(!isset($_GET['converted'])){
  11. $FileEx = strtolower(pathinfo($_FILES['doctohtml']['name'], PATHINFO_EXTENSION));
  12. if(!in_array($FileEx, array("doc", "docx", "rtf", "txd"))){
  13. header("location: ".$URLS['Script'].'System/Error/?line='.(__LINE__).'&file='.urlencode(__FILE__).'&description='.urlencode("Invalid file type"));
  14. exit;
  15. }
  16. define ('LIVEDOCXUSERNAME', 'bordeux');
  17. define ('LIVEDOCXPASSWORD', '1qwertyuiop0');
  18. define ('LIVEDOCXENDPOINT', 'https://api.livedocx.com/1.2/mailmerge.asmx?WSDL');
  19. $soap = new SoapClient(LIVEDOCXENDPOINT);
  20. $soap->LogIn(
  21. array(
  22. 'username' => LIVEDOCXUSERNAME,
  23. 'password' => LIVEDOCXPASSWORD
  24. )
  25. );
  26. $data = file_get_contents($_FILES['doctohtml']['tmp_name']);
  27. $soap->SetLocalTemplate(
  28. array(
  29. 'template' => base64_encode($data),
  30. 'format' => $FileEx
  31. )
  32. );
  33. $soap->CreateDocument();
  34. $result = $soap->RetrieveDocument(
  35. array(
  36. 'format' => 'html'
  37. )
  38. );
  39. $data = $result->RetrieveDocumentResult;
  40. $UniqID = uniqid();
  41. file_put_contents(Cache_dir.'dth_'.$UniqID.'.tmp', base64_decode($data));
  42. header('Location: ?converted='.$UniqID.'&File='.urlencode(pathinfo($_FILES['doctohtml']['name'], PATHINFO_FILENAME)));
  43. }else{
  44. if(!file_exists(Cache_dir.'dth_'.$_GET['converted'].'.tmp')){
  45. header("location: ".$URLS['Script'].'System/Error/?line='.(__LINE__).'&file='.urlencode(__FILE__).'&description='.urlencode("File not uploaded"));
  46. exit;
  47. }
  48. $XPathSimple = phpQuery::newDocument(file_get_contents(Cache_dir.'dth_'.$_GET['converted'].'.tmp'));
  49. $FileDoned = array();
  50. foreach($XPathSimple['img'] as $element){
  51. $FileID = uniqid();
  52. $FileLoc = $RootDir.'tmp/'.$FileID.'.png';
  53. $FileContent = file_get_contents(pq($element)->attr("src"));
  54. $FileMD5 = md5($FileContent);
  55. if(!isset($FileDoned[$FileMD5])){
  56. file_put_contents($FileLoc, $FileContent);
  57. try{
  58. $FileDoned[$FileMD5] = $XVwebEngine->FilesClass()->AddFile($FileLoc);
  59. }catch(XVwebException $e){
  60. }
  61. }
  62. pq($element)->attr("src", "{{file:".$FileDoned[$FileMD5]['ID']."}}");
  63. pq($element)->attr("file", $FileDoned[$FileMD5]['ID']);
  64. pq($element)->attr("replace" , "{{file:".$FileDoned[$FileMD5]['ID']."}}");
  65. }
  66. foreach($XPathSimple['body'] as $element){
  67. $Smarty->assign('ContextEdit', '<nobr all="true" /> '.pq($element)->html());
  68. }
  69. $_GET['url'] = "/Bez_kategorii/".trim($_GET['File']).'/';
  70. $Smarty->assign('UrlWrite', "/Bez_kategorii/".$_GET['File'].'/');
  71. /**************************THEME*******************/
  72. $Smarty->display('write_show.tpl');
  73. }
  74. ?>