<?php
namespace App\Controller;
use App\Entity\Ceviri;
use App\Entity\Dil;
use Gumlet\ImageResize;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class BaseController extends AbstractController
{
function botArama($bas, $son, $yazi)
{
@preg_match_all('/' . preg_quote($bas, '/') .
'(.*?)'. preg_quote($son, '/').'/i', $yazi, $m);
return @$m[1];
}
function GetIP()
{
if (getenv("HTTP_CLIENT_IP")) {
$ip = getenv("HTTP_CLIENT_IP");
} elseif (getenv("HTTP_X_FORWARDED_FOR")) {
$ip = getenv("HTTP_X_FORWARDED_FOR");
if (strstr($ip, ',')) {
$tmp = explode(',', $ip);
$ip = trim($tmp[0]);
}
} else {
$ip = getenv("REMOTE_ADDR");
}
return $ip;
}
public function IdBul($entity,$id){
$em=$this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$veriler=$qb->select('x.id')
->from('App:'.$entity, 'x')
->join('x.dil','d')
->where('x.dilgrup='.$id)
->groupBy('x.dil')
->getQuery()
->getScalarResult();
return $veriler[0]['id'];
}
function varsayilanDil(){
$em=$this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$diller=$qb->select('d.id,d.kisa,d.uzun')
->from('App:Dil', 'd')
->where("d.aktif=1 and d.varsayilan=1")
->orderBy('d.id')
->getQuery()
->getScalarResult();
return $diller[0];
}
function gecerliAktifDil(){
$em=$this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$diller=$qb->select('d.id')
->from('App:Dil', 'd')
->where("d.aktif=1")
->orderBy('d.id')
->getQuery()
->getScalarResult();
return $diller[0]['id'];
}
public function ayarlar($alan,$dil='')
{
$em=$this->getDoctrine()->getManager();
if($dil=='') {
$qb = $em->createQueryBuilder();
$dd = $qb->select("e.id")
->from('App:Dil', 'e')
->where('e.aktif=1 and e.varsayilan=1')
->getQuery()
->getScalarResult();
$dil=$dd[0]['id'];
}
$qb = $em->createQueryBuilder();
$ayarlar=$qb->select("e.$alan")
->from('App:Ayarlar', 'e')
->where('e.dil='.$dil)
->getQuery()
->getScalarResult();
return $ayarlar[0][$alan];
}
function uzantiBul($type){
if($type=='image/jpeg'){ return '.jpg'; }
elseif($type=='image/png'){ return '.png'; }
elseif($type=='image/gif'){ return '.gif'; }
elseif($type=='video/mp4'){ return '.mp4'; }
elseif($type=='application/rtf'){ return '.rtf'; }
elseif($type=='text/plain'){ return '.txt'; }
elseif($type=='application/vnd.ms-powerpoint'){ return '.ppt'; }
elseif($type=='application/vnd.openxmlformats-officedocument.presentationml.presentation'){ return '.pptx'; }
elseif($type=='application/xml'){ return '.xml'; }
elseif($type=='text/xml'){ return '.xml'; }
elseif($type=='application/vnd.ms-excel'){ return '.xls'; }
elseif($type=='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'){ return '.xlsx'; }
elseif($type=='application/msword'){ return '.doc'; }
elseif($type=='application/zip'){ return '.zip'; }
elseif($type=='application/vnd.openxmlformats-officedocument.wordprocessingml.document'){ return '.docx'; }
else{ return '.belirsiz'; }
}
function rasgele($uzunluk)
{
$key='';
$karakterler = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for($i=0;$i<$uzunluk;$i++)
{
$key .= $karakterler{rand(0,35)};
}
return $key;
}
function rasgeleSayi($uzunluk)
{
$key='';
$karakterler = "1234567890";
for($i=0;$i<$uzunluk;$i++)
{
$key .= $karakterler{rand(0,35)};
}
return $key;
}
function son_dilgrup($entity){
$em=$this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$data=$qb->select('h.dilgrup')
->from('App:'.$entity, 'h')
->orderBy('h.dilgrup','desc')
->getQuery()
->getScalarResult();
if(count($data)>0){
$dilgrup = intval($data[0]['dilgrup'])+1;
}else{
$dilgrup = 1;
}
return $dilgrup;
}
function sonGrup($entity){
$em=$this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$data=$qb->select('h.grup')
->from('App:'.$entity, 'h')
->orderBy('h.grup','desc')
->getQuery()
->getScalarResult();
if(count($data)>0){
$dilgrup = intval($data[0]['grup'])+1;
}else{
$dilgrup = 1;
}
return $dilgrup;
}
function seo($url,$dil=1){
if($dil==1) {
$tr = array('ş', 'Ş', 'ı', 'I', 'İ', 'ğ', 'Ğ', 'ü', 'Ü', 'ö', 'Ö', 'Ç', 'ç', '(', ')', '/', ':', ',');
$eng = array('s', 's', 'i', 'i', 'i', 'g', 'g', 'u', 'u', 'o', 'o', 'c', 'c', '', '', '-', '-', '');
$s = str_replace($tr, $eng, $url);
$find = array('/[^A-Za-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/');
$repl = array('-', '-', '-');
$s = preg_replace($find, $repl, $s);
$s = strtolower($s);
$s = preg_replace('/&amp;amp;amp;amp;amp;amp;amp;amp;.+?;/', '', $s);
$s = preg_replace('/\s+/', '-', $s);
$s = preg_replace('|-+|', '-', $s);
$s = preg_replace('/#/', '', $s);
$s = str_replace('.', '', $s);
$s = trim($s, '-');
$s = strtolower($s);
return $s;
}else{
$tr = array('(', ')', '/', ':', ',');
$eng = array('', '', '-', '-', '');
$s = str_replace($tr, $eng, $url);
$find = array('/[^A-Za-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/');
$repl = array('-', '-', '-');
$s = preg_replace($find, $repl, $s);
$s = strtolower($s);
$s = preg_replace('/&amp;amp;amp;amp;amp;amp;amp;amp;.+?;/', '', $s);
$s = preg_replace('/\s+/', '-', $s);
$s = preg_replace('|-+|', '-', $s);
$s = preg_replace('/#/', '', $s);
$s = str_replace('.', '', $s);
$s = trim($s, '-');
$s = strtolower($s);
return $s;
}
}
function yandexToken(){
if ($this->get('session')->get('iamToken')){
return $this->get('session')->get('iamToken');
}else {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://iam.api.cloud.yandex.net/iam/v1/tokens',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"yandexPassportOauthToken":"y0_AgAAAAAZYEETAATuwQAAAADuaUPsZ3x4KXscRqel7NbnsyEYPaf2HWE"
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
$response = json_decode($response, true);
$this->get('session')->set('iamToken', $response['iamToken']);
return $response['iamToken'];
}
}
function cevir($deger,$x,$dil){
if ($deger==''){
return "";
}
$token = $this->yandexToken();
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://translate.api.cloud.yandex.net/translate/v2/translate',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"folderId": "b1g1l9b33ueptm8liaou",
"texts": "'.$deger.'",
"targetLanguageCode": "'.$dil.'"
}',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer '.$token,
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
$response = json_decode($response, true);
return $response['translations'][0]['text'];
}
public function ceviri($deger,$suanDil='')
{
$em = $this->getDoctrine()->getManager();
if ($suanDil==''){
$suanDil = $this->get('session')->get('dil');
} else {
$qb = $em->createQueryBuilder();
$dill=$qb->select('d.id,d.kisa,d.uzun')
->from('App:Dil', 'd')
->where('d.id='.$suanDil)
->getQuery()
->getScalarResult();
$suanDil = $dill[0];
}
$qb = $em->createQueryBuilder();
$ceviriTara=$qb->select('c.deger,c.id')
->from('App:Ceviri', 'c')
->join('c.dil','d')
->where("c.deger='$deger'")
->getQuery()
->getScalarResult();
if (count($ceviriTara) > 0) {
if ($suanDil['id'] != 1) {
$qb = $em->createQueryBuilder();
$ceviriTara2=$qb->select('c.deger')
->from('App:Ceviri', 'c')
->join('c.dil','d')
->where("d.id=".$suanDil['id']." and c.trId=".$ceviriTara[0]['id'])
->getQuery()
->getScalarResult();
if (count($ceviriTara2) > 0) {
$deger = $ceviriTara2[0]['deger'];
} else {
if($deger=='İletişim') {
}
if ($suanDil['id'] != '1') {
$deger = $this->cevir($deger,'',$suanDil['kisa']);
$dill = $em->getReference(Dil::class,$suanDil['id']);
$ceviri = new Ceviri();
$ceviri->setDil($dill);
$ceviri->setDeger($deger);
$ceviri->setTrId($ceviriTara[0]['id']);
$em->persist($ceviri);
$em->flush();
}
}
}
}
else {
if ($suanDil['id'] == 1) {
$dill = $em->getReference(Dil::class,$suanDil['id']);
$ceviri = new Ceviri();
$ceviri->setDil($dill);
$ceviri->setDeger($deger);
$ceviri->setTrId(0);
$em->persist($ceviri);
$em->flush();
}
else {
$dilTr = $em->getReference(Dil::class,1);
$ceviri = new Ceviri();
$ceviri->setDil($dilTr);
$ceviri->setDeger($deger);
$ceviri->setTrId(0);
$em->persist($ceviri);
$em->flush();
$deger = $this->cevir($deger,'',$suanDil['kisa']);
$dill = $em->getReference(Dil::class,$suanDil['id']);
$ceviriDil = new Ceviri();
$ceviriDil->setDil($dill);
$ceviriDil->setDeger($deger);
$ceviriDil->setTrId($ceviri->getId());
$em->persist($ceviriDil);
$em->flush();
}
}
return $deger;
}
public function yetkiler($yetkiler){
if ($yetkiler==''){
return 1;
}
$yetkiler = explode('~',str_replace(array('{','}'),array('',''),substr($yetkiler,0,strlen($yetkiler)-1)));
$return = [];
foreach ($yetkiler as $y){
$x = explode(':',$y);
$z = explode(',',$x[1]);
$return[$x[0]]['gorme']=$z[0];
$return[$x[0]]['ekleme']=$z[1];
$return[$x[0]]['duzenleme']=$z[2];
$return[$x[0]]['silme']=$z[3];
}
if($this->getUser()->getRoles()[0]=='ROLE_SUPERADMIN' or $this->getUser()->getRoles()[0]=='ROLE_ADMIN'){
return 1;
}else{
return $return;
}
}
public function domainSorgula(){
$em = $this->getDoctrine()->getManager();
$suan = new \DateTime('now');
$tarih = new \DateTime($this->ayarlar('domainTarih'));
if (empty($this->ayarlar('domainTarih')) or $tarih->format('U') < $suan->format('U')) {
$domain = str_replace(array('/', 'https:', 'http:'), array('', '', ''), $this->ayarlar('siteYolu'));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.whois.com/whois/" . $domain);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, 'https://www.google.com/');
$output = curl_exec($ch);
curl_close($ch);
$dBol = explode('.', $domain);
if (count($dBol) == 2) {
preg_match_all('@<pre class="df-raw" id="registrarData">(.*?)</pre>@si', $output, $icerik);
$tarihB = explode('Registrar Registration Expiration Date:', $icerik[0][0]);
$tarihB = explode('Registrar', $tarihB[1]);
$tarih = str_replace('T', ' ', $tarihB[0]);
} else {
preg_match_all('@<pre class="df-raw" id="registryData">(.*?)</pre>@si', $output, $icerik);
$tarihB = explode('Expires on..............:', $icerik[0][0]);
$tarihB = explode('.', $tarihB[1]);
$tarih = $tarihB[0];
}
//echo $tarih;
$tarih = new \DateTime($tarih);
if ($this->ayarlar('debug') != 1) {
$qb = $em->createQueryBuilder();
$q = $qb->update('App:Ayarlar', 'a')
->set('a.domainTarih', ':domainTarih')
->setParameter('domainTarih', $tarih)
->getQuery()
->execute();
}
}
return $tarih;
}
public function hostingSorgulama(){
$em = $this->getDoctrine()->getManager();
$suan = new \DateTime('now');
if (empty($this->ayarlar('hostingTarih'))) {
$domain = str_replace(array('/', 'https:', 'http:'), array('', '', ''), $this->ayarlar('siteYolu'));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://174gj41p1.ni.net.tr:2087/json-api/listaccts?api.version=1&search=$domain&searchtype=domain");
curl_setopt($ch, CURLOPT_USERPWD, 'root' . ":" . 'aKuosv}_x3{K');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output);
$baslangicTarihi = new \DateTime();
$baslangicTarihi->setTimestamp($output->data->acct[0]->unix_startdate);
$baslangicTarihi->modify('+1 year');
if ($this->ayarlar('debug')!=1) {
$qb = $em->createQueryBuilder();
$q = $qb->update('App:Ayarlar', 'a')
->set('a.hostingTarih', ':hostingTarih')
->setParameter('hostingTarih', $baslangicTarihi)
->getQuery()
->execute();
}
}else{
$baslangicTarihi = new \DateTime($this->ayarlar('hostingTarih'));
if ($baslangicTarihi->format('U') < $suan->format('U')) {
if($baslangicTarihi->format('d.m.Y')!=$suan->format('d.m.Y')){
$baslangicTarihi->modify('+1 year');
if ($this->ayarlar('debug')!=1) {
$qb = $em->createQueryBuilder();
$q = $qb->update('App:Ayarlar', 'a')
->set('a.hostingTarih', ':hostingTarih')
->setParameter('hostingTarih', $baslangicTarihi)
->getQuery()
->execute();
}
}
}
}
return $baslangicTarihi;
}
public function dilSay(){
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$ayarlar=$qb->select("e.id")
->from('App:Dil', 'e')
->where('e.aktif=1')
->getQuery()
->getScalarResult();
return count($ayarlar);
}
function altKategoriListeSiteMap($dilgrup,$sSeo,$dil){
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$kategoriler=$qb->select('k.dilgrup,k.seourl,d.kisa as dKisa,k.ustid')
->from('App:Kategori', 'k')
->join('k.dil','d')
->where('k.ustid='.$dilgrup.' and d.id='.$dil)
->orderBy('k.sira','ASC')
->getQuery()
->getScalarResult();
$siteyolu = $this->ayarlar('siteYolu');
$suan = new \DateTime('now');
$veriler='';
foreach ($kategoriler as $k) {
if ($this->dilSay() > 1) {
$veriler .= '<url>
<loc>' . $siteyolu .$k['dKisa'].'/'.$sSeo.'/'.$this->altKategoriGeriYaz($k['ustid'],$dil) .$k['seourl'].'</loc>
<lastmod>' . $suan->format('Y-m-d') . 'T' . $suan->format('H:i:s') . '+00:00</lastmod>
<priority>0.80</priority>
</url>';
} else {
$veriler .= '<url>
<loc>' . $siteyolu .$sSeo.'/'.$this->altKategoriGeriYaz($k['ustid'],$dil) .$k['seourl'].'</loc>
<lastmod>' . $suan->format('Y-m-d') . 'T' . $suan->format('H:i:s') . '+00:00</lastmod>
<priority>0.80</priority>
</url>';
}
$veriler .= $this->altKategoriListeSiteMap($k['dilgrup'], $sSeo,$dil);;
}
return $veriler;
}
function altKategoriGeriYaz($ustid,$dil=1){
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$kategoriler=$qb->select('k.id,k.dilgrup,k.adi,k.seourl,k.ustid')
->from('App:Kategori', 'k')
->join('k.dil','d')
->where('k.dilgrup='.$ustid.' and d.id='.$dil)
->groupBy('k.dilgrup')
->orderBy('k.sira','ASC')
->getQuery()
->getScalarResult();
$veriler='';
foreach ($kategoriler as $k){
$veriler.=$this->altKategoriGeriYaz($k['ustid'],$dil).$k['seourl'].'/';
}
return $veriler;
}
public function iletisimBilgileri($alan){
$em = $this->getDoctrine()->getManager();
$dil = $this->get('session')->get('dil');
$qb = $em->createQueryBuilder();
$iletisim=$qb->select('s.'.$alan)
->from('App:Iletisim', 's')
->join('s.dil', 'd')
->where('d.id='.$dil['id'])
->getQuery()
->getScalarResult();
return $iletisim[0][$alan];
}
public function imageResizer($resim,$resim2,$boyut=800){
$resimBol = explode('.',$resim);
$uzanti = $resimBol[count($resimBol)-1];
$yol = 'gecici_yukleme/'.$resim;
$yol2 = 'gecici_yukleme/'.$resim2.'.webp';
list($width, $height) = getimagesize($yol);
$oran = $width / $boyut;
$yeni_genislik = $width / $oran;
$yeni_yukseklik = $height / $oran;
if ($uzanti=='jpeg' or $uzanti=='jpg' or $uzanti=='JPEG' or $uzanti=='JPG'){
$mevcut_resim = imagecreatefromjpeg($yol);
}else{
$mevcut_resim = imagecreatefrompng($yol);
}
$yeni_resim = imagecreatetruecolor($yeni_genislik, $yeni_yukseklik);
imageAlphaBlending($yeni_resim, false);
imageSaveAlpha($yeni_resim, true);
// By default, the canvas is black, so make it transparent
$trans = imagecolorallocatealpha($yeni_resim, 0, 0, 0, 127);
imagefilledrectangle($yeni_resim, 0, 0, $yeni_genislik - 1, $yeni_yukseklik - 1, $trans);
imagecopyresampled($yeni_resim, $mevcut_resim, 0, 0, 0, 0, $yeni_genislik, $yeni_yukseklik, $width, $height);
@unlink($yol);
imagewebp($yeni_resim, $yol2 );
return $resim2.'.webp';
}
public function removeEntity($veriler){
$em = $this->getDoctrine()->getManager();
foreach ($veriler as $veri){
$em->remove($veri);
}
}
public function uploadFile($file,$klasor="",$filePath=""){
if ($klasor==""){
$klasor = $this->ayarlar('uploadFolder');
}
if ($filePath==""){
$filePath = 'gecici_yukleme/';
}
$filePath .= $file;
$username = 'rvcloudstorage';
$password = 'rvrv/*-2020';
$url = 'https://j15502zk.ni.net.tr:2083';
$yukleme_yeri = 'webSitesApp/'.$klasor;
$curl = curl_init();
$upload_file = realpath($filePath);
$destination_dir = "public_html/".$yukleme_yeri;
if (function_exists('curl_file_create')) {
$cf = curl_file_create($upload_file);
} else {
$cf = "@/" . $upload_file;
}
$payload = array(
'dir' => $destination_dir,
'file-1' => $cf
);
$actionUrl = $url . "/execute/Fileman/upload_files";
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // Allow self-signed certs
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // Allow certs that do not match the hostname
curl_setopt($curl, CURLOPT_HEADER, 0); // Do not include header in output
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // Return contents of transfer on curl_exec
$header[0] = "Authorization: Basic " . base64_encode($username . ":" . $password) . "\n\r";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); // set the username and password
curl_setopt($curl, CURLOPT_URL, $actionUrl); // execute the query
// Set up a POST request with the payload.
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
if ($result == false) {
error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $actionUrl");
// log error if curl exec fails
}
curl_close($curl);
@unlink($filePath);
return json_decode($result, true);
}
function deleteFile($file)
{
if ($file!='') {
$curl = curl_init();
$destination_dir = 'public_html/webSitesApp/'.$this->ayarlar('uploadFolder').'/' . $file;
$username = 'root';
$password = 'suleyman1995ilgin***';
$url = 'https://j15502zk.ni.net.tr:2083';
$user = 'rvcloudstorage';
$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';
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // Allow self-signed certs
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // Allow certs that do not match the hostname
curl_setopt($curl, CURLOPT_HEADER, 0); // Do not include header in output
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // Return contents of transfer on curl_exec
$header[0] = "Authorization: Basic " . base64_encode($username . ":" . $password) . "\n\r";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); // set the username and password
curl_setopt($curl, CURLOPT_URL, $actionUrl); // execute the query
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
if ($result == false) {
error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $actionUrl");
// log error if curl exec fails
}
curl_close($curl);
return json_decode($result, true);
}
}
public function dilgrupBul($entity,$id){
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$veriler=$qb->select('x.dilgrup')
->from('App:'.$entity, 'x')
->join('x.dil','d')
->where('x.id='.$id)
->groupBy('x.dil')
->getQuery()
->getScalarResult();
return $veriler[0]['dilgrup'];
}
function chatGPT($promp)
{
ini_set('max_execution_time', 0);
$data = [];
$data['model'] = 'gpt-3.5-turbo';
$data['messages'][0]['role'] = 'user';
$data['messages'][0]['content'] = $promp;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.openai.com/v1/chat/completions',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>json_encode($data),
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer 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',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
$response = json_decode($response,true);
curl_close($curl);
return $response['choices'][0]['message']['content'];
}
public function digerTasarimlar($grupNo){
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$veriler=$qb->select('t.translate')
->from('App:Tasarim', 't')
->where('t.grup='.$grupNo)
->getQuery()
->getScalarResult();
$translate="";
foreach ($veriler as $veri){
$translate .=$veri['translate'];
}
return $translate;
}
function emptyDir($dir) {
if (is_dir($dir)) {
$scn = scandir($dir);
foreach ($scn as $files) {
if ($files !== '.') {
if ($files !== '..') {
if (!is_dir($dir . '/' . $files)) {
unlink($dir . '/' . $files);
} else {
$this->emptyDir($dir . '/' . $files);
rmdir($dir . '/' . $files);
}
}
}
}
}
}
}