src/Controller/BaseController.php line 559

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Ceviri;
  4. use App\Entity\Dil;
  5. use Gumlet\ImageResize;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use App\Controller;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. class BaseController extends AbstractController
  11. {
  12.     public function site_anaLink(){
  13.         $dil $this->get('session')->get('dil');
  14.         if ($this->dilSay()>1){
  15.             return $this->ayarlar('siteYolu').$dil['kisa'].'/';
  16.         }else{
  17.             return $this->ayarlar('siteYolu');
  18.         }
  19.     }
  20.     function botArama($bas$son$yazi)
  21.     {
  22.         @preg_match_all('/' preg_quote($bas'/') .
  23.             '(.*?)'preg_quote($son'/').'/i'$yazi$m);
  24.         return @$m[1];
  25.     }
  26.     function GetIP()
  27.     {
  28.         if (getenv("HTTP_CLIENT_IP")) {
  29.             $ip getenv("HTTP_CLIENT_IP");
  30.         } elseif (getenv("HTTP_X_FORWARDED_FOR")) {
  31.             $ip getenv("HTTP_X_FORWARDED_FOR");
  32.             if (strstr($ip',')) {
  33.                 $tmp explode(','$ip);
  34.                 $ip trim($tmp[0]);
  35.             }
  36.         } else {
  37.             $ip getenv("REMOTE_ADDR");
  38.         }
  39.         return $ip;
  40.     }
  41.     public function IdBul($entity,$id){
  42.         $em=$this->getDoctrine()->getManager();
  43.         $qb $em->createQueryBuilder();
  44.         $veriler=$qb->select('x.id')
  45.             ->from('App:'.$entity'x')
  46.             ->join('x.dil','d')
  47.             ->where('x.dilgrup='.$id)
  48.             ->groupBy('x.dil')
  49.             ->getQuery()
  50.             ->getScalarResult();
  51.         return $veriler[0]['id'];
  52.     }
  53.     function varsayilanDil(){
  54.         $em=$this->getDoctrine()->getManager();
  55.         $qb $em->createQueryBuilder();
  56.         $diller=$qb->select('d.id,d.kisa,d.uzun')
  57.             ->from('App:Dil''d')
  58.             ->where("d.aktif=1 and d.varsayilan=1")
  59.             ->orderBy('d.id')
  60.             ->getQuery()
  61.             ->getScalarResult();
  62.         return $diller[0];
  63.     }
  64.     function gecerliAktifDil(){
  65.         $em=$this->getDoctrine()->getManager();
  66.         $qb $em->createQueryBuilder();
  67.         $diller=$qb->select('d.id')
  68.             ->from('App:Dil''d')
  69.             ->where("d.aktif=1")
  70.             ->orderBy('d.id')
  71.             ->getQuery()
  72.             ->getScalarResult();
  73.         return $diller[0]['id'];
  74.     }
  75.     public function ayarlar($alan,$dil='')
  76.     {
  77.         $em=$this->getDoctrine()->getManager();
  78.         if($dil=='') {
  79.             $qb $em->createQueryBuilder();
  80.             $dd $qb->select("e.id")
  81.                 ->from('App:Dil''e')
  82.                 ->where('e.aktif=1 and e.varsayilan=1')
  83.                 ->getQuery()
  84.                 ->getScalarResult();
  85.             $dil=$dd[0]['id'];
  86.         }
  87.         $qb $em->createQueryBuilder();
  88.         $ayarlar=$qb->select("e.$alan")
  89.             ->from('App:Ayarlar''e')
  90.             ->where('e.dil='.$dil)
  91.             ->getQuery()
  92.             ->getScalarResult();
  93.         return $ayarlar[0][$alan];
  94.     }
  95.     function uzantiBul($type){
  96.         if($type=='image/jpeg'){ return '.jpg'; }
  97.         elseif($type=='image/png'){ return '.png'; }
  98.         elseif($type=='image/gif'){ return '.gif'; }
  99.         elseif($type=='video/mp4'){ return '.mp4'; }
  100.         elseif($type=='application/rtf'){ return '.rtf'; }
  101.         elseif($type=='text/plain'){ return '.txt'; }
  102.         elseif($type=='application/vnd.ms-powerpoint'){ return '.ppt'; }
  103.         elseif($type=='application/vnd.openxmlformats-officedocument.presentationml.presentation'){ return '.pptx'; }
  104.         elseif($type=='application/xml'){ return '.xml'; }
  105.         elseif($type=='application/pdf'){ return '.pdf'; }
  106.         elseif($type=='text/xml'){ return '.xml'; }
  107.         elseif($type=='application/vnd.ms-excel'){ return '.xls'; }
  108.         elseif($type=='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'){ return '.xlsx'; }
  109.         elseif($type=='application/msword'){ return '.doc'; }
  110.         elseif($type=='application/zip'){ return '.zip'; }
  111.         elseif($type=='application/vnd.openxmlformats-officedocument.wordprocessingml.document'){ return '.docx'; }
  112.         else{ return '.belirsiz'; }
  113.     }
  114.     function rasgele($uzunluk)
  115.     {
  116.         $key='';
  117.         $karakterler "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  118.         for($i=0;$i<$uzunluk;$i++)
  119.         {
  120.             $key .= $karakterler{rand(0,35)};
  121.         }
  122.         return $key;
  123.     }
  124.     function rasgeleSayi($uzunluk)
  125.     {
  126.         $key='';
  127.         $karakterler "1234567890";
  128.         for($i=0;$i<$uzunluk;$i++)
  129.         {
  130.             $key .= $karakterler{rand(0,35)};
  131.         }
  132.         return $key;
  133.     }
  134.     function son_dilgrup($entity){
  135.         $em=$this->getDoctrine()->getManager();
  136.         $qb $em->createQueryBuilder();
  137.         $data=$qb->select('h.dilgrup')
  138.             ->from('App:'.$entity'h')
  139.             ->orderBy('h.dilgrup','desc')
  140.             ->getQuery()
  141.             ->getScalarResult();
  142.         if(count($data)>0){
  143.             $dilgrup intval($data[0]['dilgrup'])+1;
  144.         }else{
  145.             $dilgrup 1;
  146.         }
  147.         return $dilgrup;
  148.     }
  149.     function sonGrup($entity){
  150.         $em=$this->getDoctrine()->getManager();
  151.         $qb $em->createQueryBuilder();
  152.         $data=$qb->select('h.grup')
  153.             ->from('App:'.$entity'h')
  154.             ->orderBy('h.grup','desc')
  155.             ->getQuery()
  156.             ->getScalarResult();
  157.         if(count($data)>0){
  158.             $dilgrup intval($data[0]['grup'])+1;
  159.         }else{
  160.             $dilgrup 1;
  161.         }
  162.         return $dilgrup;
  163.     }
  164.     function seo($url,$dil=1){
  165.         if($dil==1) {
  166.             $tr = array('ÅŸ''Åž''ı''I''İ''ÄŸ''Äž''ü''Ü''ö''Ö''Ç''ç''('')''/'':'',');
  167.             $eng = array('s''s''i''i''i''g''g''u''u''o''o''c''c''''''-''-''');
  168.             $s str_replace($tr$eng$url);
  169.             $find = array('/[^A-Za-z0-9\-<>]/''/[\-]+/''/<[^>]*>/');
  170.             $repl = array('-''-''-');
  171.             $s preg_replace($find$repl$s);
  172.             $s strtolower($s);
  173.             $s preg_replace('/&amp;amp;amp;amp;amp;amp;amp;amp;amp;.+?;/'''$s);
  174.             $s preg_replace('/\s+/''-'$s);
  175.             $s preg_replace('|-+|''-'$s);
  176.             $s preg_replace('/#/'''$s);
  177.             $s str_replace('.'''$s);
  178.             $s trim($s'-');
  179.             $s strtolower($s);
  180.             return $s;
  181.         }else{
  182.             $tr = array('('')''/'':'',');
  183.             $eng = array('''''-''-''');
  184.             $s str_replace($tr$eng$url);
  185.             $find = array('/[^A-Za-z0-9\-<>]/''/[\-]+/''/<[^>]*>/');
  186.             $repl = array('-''-''-');
  187.             $s preg_replace($find$repl$s);
  188.             $s strtolower($s);
  189.             $s preg_replace('/&amp;amp;amp;amp;amp;amp;amp;amp;amp;.+?;/'''$s);
  190.             $s preg_replace('/\s+/''-'$s);
  191.             $s preg_replace('|-+|''-'$s);
  192.             $s preg_replace('/#/'''$s);
  193.             $s str_replace('.'''$s);
  194.             $s trim($s'-');
  195.             $s strtolower($s);
  196.             return $s;
  197.         }
  198.     }
  199.     function yandexToken(){
  200.         if ($this->get('session')->get('iamToken')){
  201.             return $this->get('session')->get('iamToken');
  202.         }else {
  203.             $curl curl_init();
  204.             curl_setopt_array($curl, array(
  205.                 CURLOPT_URL => 'https://iam.api.cloud.yandex.net/iam/v1/tokens',
  206.                 CURLOPT_RETURNTRANSFER => true,
  207.                 CURLOPT_ENCODING => '',
  208.                 CURLOPT_MAXREDIRS => 10,
  209.                 CURLOPT_TIMEOUT => 0,
  210.                 CURLOPT_FOLLOWLOCATION => true,
  211.                 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  212.                 CURLOPT_CUSTOMREQUEST => 'POST',
  213.                 CURLOPT_POSTFIELDS => '{
  214.     "yandexPassportOauthToken":"y0_AgAAAAAZYEETAATuwQAAAAEToav7AADO8OOAY3pJJ4glGitLIJdp7BdHYg"
  215. }',
  216.                 CURLOPT_HTTPHEADER => array(
  217.                     'Content-Type: application/json'
  218.                 ),
  219.             ));
  220.             $response curl_exec($curl);
  221.             $response json_decode($responsetrue);
  222.             $this->get('session')->set('iamToken'$response['iamToken']);
  223.             return $response['iamToken'];
  224.         }
  225.     }
  226.     function cevir($deger,$x,$dil){
  227.         if ($deger==''){
  228.             return "";
  229.         }
  230.         $token $this->yandexToken();
  231.         $curl curl_init();
  232.         curl_setopt_array($curl, array(
  233.             CURLOPT_URL => 'https://translate.api.cloud.yandex.net/translate/v2/translate',
  234.             CURLOPT_RETURNTRANSFER => true,
  235.             CURLOPT_ENCODING => '',
  236.             CURLOPT_MAXREDIRS => 10,
  237.             CURLOPT_TIMEOUT => 0,
  238.             CURLOPT_FOLLOWLOCATION => true,
  239.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  240.             CURLOPT_CUSTOMREQUEST => 'POST',
  241.             CURLOPT_POSTFIELDS =>'{
  242.     "folderId": "b1gd9bqb7ihnkc2cl4kg",
  243.     "texts": "'.$deger.'",
  244.     "targetLanguageCode": "'.$dil.'"
  245. }',
  246.             CURLOPT_HTTPHEADER => array(
  247.                 'Authorization: Bearer '.$token,
  248.                 'Content-Type: application/json'
  249.             ),
  250.         ));
  251.         $response curl_exec($curl);
  252.         $response json_decode($responsetrue);
  253.         return $response['translations'][0]['text'];
  254.     }
  255.     public function ceviri($deger,$suanDil='')
  256.     {
  257.         $em $this->getDoctrine()->getManager();
  258.         if ($suanDil==''){
  259.             $suanDil $this->get('session')->get('dil');
  260.         } else {
  261.             $qb $em->createQueryBuilder();
  262.             $dill=$qb->select('d.id,d.kisa,d.uzun')
  263.                 ->from('App:Dil''d')
  264.                 ->where('d.id='.$suanDil)
  265.                 ->getQuery()
  266.                 ->getScalarResult();
  267.             $suanDil $dill[0];
  268.         }
  269.         $qb $em->createQueryBuilder();
  270.         $ceviriTara=$qb->select('c.deger,c.id')
  271.             ->from('App:Ceviri''c')
  272.             ->join('c.dil','d')
  273.             ->where("c.deger='$deger'")
  274.             ->getQuery()
  275.             ->getScalarResult();
  276.         if (count($ceviriTara) > 0) {
  277.             if ($suanDil['id'] != 1) {
  278.                 $qb $em->createQueryBuilder();
  279.                 $ceviriTara2=$qb->select('c.deger')
  280.                     ->from('App:Ceviri''c')
  281.                     ->join('c.dil','d')
  282.                     ->where("d.id=".$suanDil['id']." and c.trId=".$ceviriTara[0]['id'])
  283.                     ->getQuery()
  284.                     ->getScalarResult();
  285.                 if (count($ceviriTara2) > 0) {
  286.                     $deger $ceviriTara2[0]['deger'];
  287.                 } else {
  288.                     if($deger=='İletiÅŸim') {
  289.                     }
  290.                     if ($suanDil['id'] != '1') {
  291.                         $deger $this->cevir($deger,'',$suanDil['kisa']);
  292.                         $dill $em->getReference(Dil::class,$suanDil['id']);
  293.                         $ceviri = new Ceviri();
  294.                         $ceviri->setDil($dill);
  295.                         $ceviri->setDeger($deger);
  296.                         $ceviri->setTrId($ceviriTara[0]['id']);
  297.                         $em->persist($ceviri);
  298.                         $em->flush();
  299.                     }
  300.                 }
  301.             }
  302.         }
  303.         else {
  304.             if ($suanDil['id'] == 1) {
  305.                 $dill $em->getReference(Dil::class,$suanDil['id']);
  306.                 $ceviri = new Ceviri();
  307.                 $ceviri->setDil($dill);
  308.                 $ceviri->setDeger($deger);
  309.                 $ceviri->setTrId(0);
  310.                 $em->persist($ceviri);
  311.                 $em->flush();
  312.             }
  313.             else {
  314.                 $dilTr $em->getReference(Dil::class,1);
  315.                 $ceviri = new Ceviri();
  316.                 $ceviri->setDil($dilTr);
  317.                 $ceviri->setDeger($deger);
  318.                 $ceviri->setTrId(0);
  319.                 $em->persist($ceviri);
  320.                 $em->flush();
  321.                 $deger $this->cevir($deger,'',$suanDil['kisa']);
  322.                 $dill $em->getReference(Dil::class,$suanDil['id']);
  323.                 $ceviriDil = new Ceviri();
  324.                 $ceviriDil->setDil($dill);
  325.                 $ceviriDil->setDeger($deger);
  326.                 $ceviriDil->setTrId($ceviri->getId());
  327.                 $em->persist($ceviriDil);
  328.                 $em->flush();
  329.             }
  330.         }
  331.         return $deger;
  332.     }
  333.     public function yetkiler($yetkiler){
  334.         if ($yetkiler==''){
  335.             return 1;
  336.         }
  337.         $yetkiler explode('~',str_replace(array('{','}'),array('',''),substr($yetkiler,0,strlen($yetkiler)-1)));
  338.         $return = [];
  339.         foreach ($yetkiler as $y){
  340.             $x explode(':',$y);
  341.             $z explode(',',$x[1]);
  342.             $return[$x[0]]['gorme']=$z[0];
  343.             $return[$x[0]]['ekleme']=$z[1];
  344.             $return[$x[0]]['duzenleme']=$z[2];
  345.             $return[$x[0]]['silme']=$z[3];
  346.         }
  347.         if($this->getUser()->getRoles()[0]=='ROLE_SUPERADMIN' or $this->getUser()->getRoles()[0]=='ROLE_ADMIN'){
  348.             return 1;
  349.         }else{
  350.             return $return;
  351.         }
  352.     }
  353.     public function domainSorgula(){
  354.         $em $this->getDoctrine()->getManager();
  355.         $suan = new \DateTime('now');
  356.         $tarih = new \DateTime($this->ayarlar('domainTarih'));
  357.         if (empty($this->ayarlar('domainTarih')) or $tarih->format('U') < $suan->format('U')) {
  358.             $domain str_replace(array('/''https:''http:'), array(''''''), $this->ayarlar('siteYolu'));
  359.             $ch curl_init();
  360.             curl_setopt($chCURLOPT_URL"https://www.whois.com/whois/" $domain);
  361.             curl_setopt($chCURLOPT_RETURNTRANSFER1);
  362.             curl_setopt($chCURLOPT_REFERER'https://www.google.com/');
  363.             $output curl_exec($ch);
  364.             curl_close($ch);
  365.             $dBol explode('.'$domain);
  366.             if (count($dBol) == 2) {
  367.                 preg_match_all('@<pre class="df-raw" id="registrarData">(.*?)</pre>@si'$output$icerik);
  368.                 $tarihB explode('Registrar Registration Expiration Date:'$icerik[0][0]);
  369.                 $tarihB explode('Registrar'$tarihB[1]);
  370.                 $tarih str_replace('T'' '$tarihB[0]);
  371.             } else {
  372.                 preg_match_all('@<pre class="df-raw" id="registryData">(.*?)</pre>@si'$output$icerik);
  373.                 $tarihB explode('Expires on..............:'$icerik[0][0]);
  374.                 $tarihB explode('.'$tarihB[1]);
  375.                 $tarih $tarihB[0];
  376.             }
  377.             //echo $tarih;
  378.             $tarih = new \DateTime($tarih);
  379.             if ($this->ayarlar('debug') != 1) {
  380.                 $qb $em->createQueryBuilder();
  381.                 $q $qb->update('App:Ayarlar''a')
  382.                     ->set('a.domainTarih'':domainTarih')
  383.                     ->setParameter('domainTarih'$tarih)
  384.                     ->getQuery()
  385.                     ->execute();
  386.             }
  387.         }
  388.         return $tarih;
  389.     }
  390.     public function hostingSorgulama(){
  391.         $em $this->getDoctrine()->getManager();
  392.         $suan = new \DateTime('now');
  393.         if (empty($this->ayarlar('hostingTarih'))) {
  394.             $domain str_replace(array('/''https:''http:'), array(''''''), $this->ayarlar('siteYolu'));
  395.             $ch curl_init();
  396.             curl_setopt($chCURLOPT_URL"https://174gj41p1.ni.net.tr:2087/json-api/listaccts?api.version=1&search=$domain&searchtype=domain");
  397.             curl_setopt($chCURLOPT_USERPWD'root' ":" 'aKuosv}_x3{K');
  398.             curl_setopt($chCURLOPT_RETURNTRANSFER1);
  399.             $output curl_exec($ch);
  400.             curl_close($ch);
  401.             $output json_decode($output);
  402.             $baslangicTarihi = new \DateTime();
  403.             $baslangicTarihi->setTimestamp($output->data->acct[0]->unix_startdate);
  404.             $baslangicTarihi->modify('+1 year');
  405.             if ($this->ayarlar('debug')!=1) {
  406.                 $qb $em->createQueryBuilder();
  407.                 $q $qb->update('App:Ayarlar''a')
  408.                     ->set('a.hostingTarih'':hostingTarih')
  409.                     ->setParameter('hostingTarih'$baslangicTarihi)
  410.                     ->getQuery()
  411.                     ->execute();
  412.             }
  413.         }else{
  414.             $baslangicTarihi = new \DateTime($this->ayarlar('hostingTarih'));
  415.             if ($baslangicTarihi->format('U') < $suan->format('U')) {
  416.                 if($baslangicTarihi->format('d.m.Y')!=$suan->format('d.m.Y')){
  417.                     $baslangicTarihi->modify('+1 year');
  418.                     if ($this->ayarlar('debug')!=1) {
  419.                         $qb $em->createQueryBuilder();
  420.                         $q $qb->update('App:Ayarlar''a')
  421.                             ->set('a.hostingTarih'':hostingTarih')
  422.                             ->setParameter('hostingTarih'$baslangicTarihi)
  423.                             ->getQuery()
  424.                             ->execute();
  425.                     }
  426.                 }
  427.             }
  428.         }
  429.         return $baslangicTarihi;
  430.     }
  431.     public function dilSay(){
  432.         $em $this->getDoctrine()->getManager();
  433.         $qb $em->createQueryBuilder();
  434.         $ayarlar=$qb->select("e.id")
  435.             ->from('App:Dil''e')
  436.             ->where('e.aktif=1')
  437.             ->getQuery()
  438.             ->getScalarResult();
  439.         return count($ayarlar);
  440.     }
  441.     function altKategoriListeSiteMap($dilgrup,$sSeo,$dil){
  442.         $em $this->getDoctrine()->getManager();
  443.         $qb $em->createQueryBuilder();
  444.         $kategoriler=$qb->select('k.dilgrup,k.seourl,d.kisa as dKisa,k.ustid')
  445.             ->from('App:Kategori''k')
  446.             ->join('k.dil','d')
  447.             ->where('k.ustid='.$dilgrup.' and d.id='.$dil)
  448.             ->orderBy('k.sira','ASC')
  449.             ->getQuery()
  450.             ->getScalarResult();
  451.         $siteyolu $this->ayarlar('siteYolu');
  452.         $suan = new \DateTime('now');
  453.         $veriler='';
  454.         foreach ($kategoriler as $k) {
  455.             if ($this->dilSay() > 1) {
  456.                 $veriler .= '<url>
  457.                                   <loc>' $siteyolu .$k['dKisa'].'/'.$sSeo.'/'.$this->altKategoriGeriYaz($k['ustid'],$dil) .$k['seourl'].'</loc>
  458.                                   <lastmod>' $suan->format('Y-m-d') . 'T' $suan->format('H:i:s') . '+00:00</lastmod>
  459.                                   <priority>0.80</priority>
  460.                                 </url>';
  461.             } else {
  462.                 $veriler .= '<url>
  463.                                   <loc>' $siteyolu .$sSeo.'/'.$this->altKategoriGeriYaz($k['ustid'],$dil) .$k['seourl'].'</loc>
  464.                                   <lastmod>' $suan->format('Y-m-d') . 'T' $suan->format('H:i:s') . '+00:00</lastmod>
  465.                                   <priority>0.80</priority>
  466.                                 </url>';
  467.             }
  468.             $veriler .= $this->altKategoriListeSiteMap($k['dilgrup'], $sSeo,$dil);;
  469.         }
  470.         return $veriler;
  471.     }
  472.     function altKategoriGeriYaz($ustid,$dil=1){
  473.         $em $this->getDoctrine()->getManager();
  474.         $qb $em->createQueryBuilder();
  475.         $kategoriler=$qb->select('k.id,k.dilgrup,k.adi,k.seourl,k.ustid')
  476.             ->from('App:Kategori''k')
  477.             ->join('k.dil','d')
  478.             ->where('k.dilgrup='.$ustid.' and d.id='.$dil)
  479.             ->groupBy('k.dilgrup')
  480.             ->orderBy('k.sira','ASC')
  481.             ->getQuery()
  482.             ->getScalarResult();
  483.         $veriler='';
  484.         foreach ($kategoriler as $k){
  485.             $veriler.=$this->altKategoriGeriYaz($k['ustid'],$dil).$k['seourl'].'/';
  486.         }
  487.         return $veriler;
  488.     }
  489.     public function iletisimBilgileri($alan){
  490.         $em $this->getDoctrine()->getManager();
  491.         $dil $this->get('session')->get('dil');
  492.         $qb $em->createQueryBuilder();
  493.         $iletisim=$qb->select('s.'.$alan)
  494.             ->from('App:Iletisim''s')
  495.             ->join('s.dil''d')
  496.             ->where('d.id='.$dil['id'])
  497.             ->getQuery()
  498.             ->getScalarResult();
  499.         return $iletisim[0][$alan];
  500.     }
  501.     public function imageResizer($resim,$resim2,$boyut=800){
  502.         $resimBol explode('.',$resim);
  503.         $uzanti $resimBol[count($resimBol)-1];
  504.         $yol 'gecici_yukleme/'.$resim;
  505.         $yol2 'gecici_yukleme/'.$resim2.'.webp';
  506.         list($width$height) = getimagesize($yol);
  507.         $oran $width $boyut;
  508.         $yeni_genislik $width $oran;
  509.         $yeni_yukseklik $height $oran;
  510.         if ($uzanti=='jpeg' or $uzanti=='jpg' or $uzanti=='JPEG' or $uzanti=='JPG'){
  511.             $mevcut_resim imagecreatefromjpeg($yol);
  512.         }else{
  513.             $mevcut_resim imagecreatefrompng($yol);
  514.         }
  515.         $yeni_resim imagecreatetruecolor($yeni_genislik$yeni_yukseklik);
  516.         imageAlphaBlending($yeni_resimfalse);
  517.         imageSaveAlpha($yeni_resimtrue);
  518. // By default, the canvas is black, so make it transparent
  519.         $trans imagecolorallocatealpha($yeni_resim000127);
  520.         imagefilledrectangle($yeni_resim00$yeni_genislik 1$yeni_yukseklik 1$trans);
  521.         imagecopyresampled($yeni_resim$mevcut_resim0000$yeni_genislik$yeni_yukseklik$width$height);
  522.         @unlink($yol);
  523.         imagewebp($yeni_resim$yol2 );
  524.         return $resim2.'.webp';
  525.     }
  526.     public function removeEntity($veriler){
  527.         $em $this->getDoctrine()->getManager();
  528.         foreach ($veriler as $veri){
  529.             $em->remove($veri);
  530.         }
  531.     }
  532.     public function uploadFile($file,$klasor="",$filePath=""){
  533.         if ($klasor==""){
  534.             $klasor $this->ayarlar('uploadFolder');
  535.         }
  536.         if ($filePath==""){
  537.             $filePath 'gecici_yukleme/';
  538.         }
  539.         $filePath .= $file;
  540.         $username 'rvcloudstorage';
  541.         $password 'rvrv/*-2020';
  542.         $url 'https://j15502zk.ni.net.tr:2083';
  543.         $yukleme_yeri 'webSitesApp/'.$klasor;
  544.         $curl curl_init();
  545.         $upload_file realpath($filePath);
  546.         $destination_dir "public_html/".$yukleme_yeri;
  547.         if (function_exists('curl_file_create')) {
  548.             $cf curl_file_create($upload_file);
  549.         } else {
  550.             $cf "@/" $upload_file;
  551.         }
  552.         $payload = array(
  553.             'dir' => $destination_dir,
  554.             'file-1' => $cf
  555.         );
  556.         $actionUrl $url "/execute/Fileman/upload_files";
  557.         curl_setopt($curlCURLOPT_SSL_VERIFYPEER0);       // Allow self-signed certs
  558.         curl_setopt($curlCURLOPT_SSL_VERIFYHOST0);       // Allow certs that do not match the hostname
  559.         curl_setopt($curlCURLOPT_HEADER0);               // Do not include header in output
  560.         curl_setopt($curlCURLOPT_RETURNTRANSFER1);       // Return contents of transfer on curl_exec
  561.         $header[0] = "Authorization: Basic " base64_encode($username ":" $password) . "\n\r";
  562.         curl_setopt($curlCURLOPT_HTTPHEADER$header);    // set the username and password
  563.         curl_setopt($curlCURLOPT_URL$actionUrl);        // execute the query
  564.         // Set up a POST request with the payload.
  565.         curl_setopt($curlCURLOPT_POSTtrue);
  566.         curl_setopt($curlCURLOPT_POSTFIELDS$payload);
  567.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  568.         $result curl_exec($curl);
  569.         if ($result == false) {
  570.             error_log("curl_exec threw error \"" curl_error($curl) . "\" for $actionUrl");
  571.             // log error if curl exec fails
  572.         }
  573.         curl_close($curl);
  574.         @unlink($filePath);
  575.         return json_decode($resulttrue);
  576.     }
  577.     function deleteFile($file)
  578.     {
  579.         if ($file!='') {
  580.             $curl curl_init();
  581.             $destination_dir 'public_html/webSitesApp/'.$this->ayarlar('uploadFolder').'/' $file;
  582.             $username 'root';
  583.             $password 'suleyman1995ilgin***';
  584.             $url 'https://j15502zk.ni.net.tr:2083';
  585.             $user 'rvcloudstorage';
  586.             $actionUrl 'https://j15502zk.ni.net.tr:2087/json-api/cpanel?cpanel_jsonapi_user=' $user '&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Fileman&cpanel_jsonapi_func=fileop&op=unlink&sourcefiles=' $destination_dir '&doubledecode=1';
  587.             curl_setopt($curlCURLOPT_SSL_VERIFYPEER0);       // Allow self-signed certs
  588.             curl_setopt($curlCURLOPT_SSL_VERIFYHOST0);       // Allow certs that do not match the hostname
  589.             curl_setopt($curlCURLOPT_HEADER0);               // Do not include header in output
  590.             curl_setopt($curlCURLOPT_RETURNTRANSFER1);       // Return contents of transfer on curl_exec
  591.             $header[0] = "Authorization: Basic " base64_encode($username ":" $password) . "\n\r";
  592.             curl_setopt($curlCURLOPT_HTTPHEADER$header);    // set the username and password
  593.             curl_setopt($curlCURLOPT_URL$actionUrl);        // execute the query
  594.             curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  595.             $result curl_exec($curl);
  596.             if ($result == false) {
  597.                 error_log("curl_exec threw error \"" curl_error($curl) . "\" for $actionUrl");
  598.                 // log error if curl exec fails
  599.             }
  600.             curl_close($curl);
  601.             return json_decode($resulttrue);
  602.         }
  603.     }
  604.     public function dilgrupBul($entity,$id){
  605.         $em $this->getDoctrine()->getManager();
  606.         $qb $em->createQueryBuilder();
  607.         $veriler=$qb->select('x.dilgrup')
  608.             ->from('App:'.$entity'x')
  609.             ->join('x.dil','d')
  610.             ->where('x.id='.$id)
  611.             ->groupBy('x.dil')
  612.             ->getQuery()
  613.             ->getScalarResult();
  614.         return $veriler[0]['dilgrup'];
  615.     }
  616.     function chatGPT($promp)
  617.     {
  618.         ini_set('max_execution_time'0);
  619.         $data = [];
  620.         $data['model'] = 'gpt-3.5-turbo';
  621.         $data['messages'][0]['role'] = 'user';
  622.         $data['messages'][0]['content'] = $promp;
  623.         $curl curl_init();
  624.         curl_setopt_array($curl, array(
  625.             CURLOPT_URL => 'https://api.openai.com/v1/chat/completions',
  626.             CURLOPT_RETURNTRANSFER => true,
  627.             CURLOPT_ENCODING => '',
  628.             CURLOPT_MAXREDIRS => 10,
  629.             CURLOPT_TIMEOUT => 0,
  630.             CURLOPT_FOLLOWLOCATION => true,
  631.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  632.             CURLOPT_CUSTOMREQUEST => 'POST',
  633.             CURLOPT_POSTFIELDS =>json_encode($data),
  634.             CURLOPT_HTTPHEADER => array(
  635.                 'Authorization: Bearer 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',
  636.                 'Content-Type: application/json'
  637.             ),
  638.         ));
  639.         $response curl_exec($curl);
  640.         $response json_decode($response,true);
  641.         curl_close($curl);
  642.         return $response['choices'][0]['message']['content'];
  643.     }
  644.     public function digerTasarimlar($grupNo){
  645.         $em $this->getDoctrine()->getManager();
  646.         $qb $em->createQueryBuilder();
  647.         $veriler=$qb->select('t.translate')
  648.             ->from('App:Tasarim''t')
  649.             ->where('t.grup='.$grupNo)
  650.             ->getQuery()
  651.             ->getScalarResult();
  652.         $translate="";
  653.         foreach ($veriler as $veri){
  654.             $translate .=$veri['translate'];
  655.         }
  656.         return $translate;
  657.     }
  658.     function emptyDir($dir) {
  659.         if (is_dir($dir)) {
  660.             $scn scandir($dir);
  661.             foreach ($scn as $files) {
  662.                 if ($files !== '.') {
  663.                     if ($files !== '..') {
  664.                         if (!is_dir($dir '/' $files)) {
  665.                             unlink($dir '/' $files);
  666.                         } else {
  667.                             $this->emptyDir($dir '/' $files);
  668.                             rmdir($dir '/' $files);
  669.                         }
  670.                     }
  671.                 }
  672.             }
  673.         }
  674.     }
  675. }