PageRenderTime 31ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/app/Http/Controllers/HtmlController.php

https://bitbucket.org/hfab/webservice
PHP | 165 lines | 82 code | 27 blank | 56 comment | 4 complexity | 26e0c07f605d180d6f67b6d0e68ec188 MD5 | raw file
Possible License(s): BSD-2-Clause, Apache-2.0, MIT, GPL-3.0, LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php namespace App\Http\Controllers;
  2. use App\Http\Requests;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request;
  5. class HtmlController extends Controller {
  6. public function __construct()
  7. {
  8. $this->middleware('auth');
  9. }
  10. /**
  11. * Display a listing of the resource.
  12. *
  13. * @return Response
  14. */
  15. public function index()
  16. {
  17. //
  18. }
  19. /**
  20. * Show the form for creating a new resource.
  21. *
  22. * @return Response
  23. */
  24. public function create()
  25. {
  26. //
  27. }
  28. /**
  29. * Store a newly created resource in storage.
  30. *
  31. * @return Response
  32. */
  33. public function store()
  34. {
  35. //
  36. }
  37. /**
  38. * Display the specified resource.
  39. *
  40. * @param int $id
  41. * @return Response
  42. */
  43. public function show($id)
  44. {
  45. $campagne = \App\Models\Campagne::find($id);
  46. $campagne->html = html_entity_decode($campagne->html);
  47. return view('html.show')->withCampagne($campagne);
  48. }
  49. /**
  50. * Show the form for editing the specified resource.
  51. *
  52. * @param int $id
  53. * @return Response
  54. */
  55. public function edit($id)
  56. {
  57. //
  58. }
  59. /**
  60. * Update the specified resource in storage.
  61. *
  62. * @param int $id
  63. * @return Response
  64. */
  65. public function update($id)
  66. {
  67. //
  68. }
  69. /**
  70. * Remove the specified resource from storage.
  71. *
  72. * @param int $id
  73. * @return Response
  74. */
  75. public function destroy($id)
  76. {
  77. //
  78. }
  79. public function check_kit($id){
  80. $check = \DB::table('campagnes')->where('id',$id)->first();
  81. $htmlsource = $check->html;
  82. $tablinks = array();
  83. $tabimg = array();
  84. $tablinksblade = array();
  85. $tabimgblade = array();
  86. $domaine = 'http://tor.sc2consulting.fr/'; // ajouter get_env
  87. // $url = 'campagne/1854/routeur_6';
  88. // $lien = $domaine . $url;
  89. $output = preg_match_all('/<a.+href=[\'"]([^\'"]+)[\'"].*>/Ui', $htmlsource, $matches);
  90. //pour chacuns des element trouvés
  91. for ($i = 0; $i < $output; $i++) {
  92. $tablinks[] = $matches[1][$i];
  93. }
  94. $output2 = preg_match_all('/"([^\s]+\.(jpg|png))"/', $htmlsource, $matches2);
  95. for ($ii = 0; $ii < $output2; $ii++) {
  96. $tabimg[] = $matches2[1][$ii];
  97. }
  98. foreach ($tabimg as $v) {
  99. $r = stristr($v, 'http://');
  100. if($r === false){
  101. $v = $domaine . $v;
  102. }
  103. // echo $v . '<br />';
  104. $client = curl_init();
  105. curl_setopt($client, CURLOPT_URL, $v);
  106. curl_setopt($client, CURLOPT_RETURNTRANSFER, 1);
  107. curl_setopt($client, CURLOPT_SSL_VERIFYPEER, false);
  108. curl_setopt($client,CURLOPT_CUSTOMREQUEST,'GET');
  109. $reponse = curl_exec($client);
  110. $reponsecode = curl_getinfo($client, CURLINFO_HTTP_CODE);
  111. curl_close($client);
  112. // var_dump($reponsecode);
  113. $tabimgblade[] = array($v,$reponsecode);
  114. }
  115. foreach ($tablinks as $l) {
  116. $l = stristr($l, 'http://');
  117. if($l === false){
  118. $l = $domaine . $l;
  119. }
  120. // echo $l . '<br />';
  121. $client = curl_init();
  122. curl_setopt($client, CURLOPT_URL, $l);
  123. curl_setopt($client, CURLOPT_RETURNTRANSFER, 1);
  124. curl_setopt($client, CURLOPT_SSL_VERIFYPEER, false);
  125. curl_setopt($client,CURLOPT_CUSTOMREQUEST,'GET');
  126. $reponse = curl_exec($client);
  127. $reponsecode = curl_getinfo($client, CURLINFO_HTTP_CODE);
  128. curl_close($client);
  129. // var_dump($reponsecode);
  130. $tablinksblade[] = array($l,$reponsecode);
  131. }
  132. // var_dump($tablinks);
  133. // var_dump($tabimg);
  134. // var_dump($tablinksblade);
  135. // var_dump($tabimgblade);
  136. return view('html.check')->with('tabimgblade',$tabimgblade)->with('tablinksblade',$tablinksblade);
  137. }
  138. }