Afunc.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. class Afunc extends Controller{
  3. public static function resimgoster($icerik) {
  4. $resimbir = '';
  5. ob_start();
  6. ob_end_clean();
  7. $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', htmlspecialchars_decode($icerik), $matches);
  8. if($output){$resimbir = $matches['1']['0'] ;}
  9. if(empty($resimbir)){ //Eğer resim eklememişseniz
  10. $resimbir = baseUrl().'uploads/images/eagle.png';
  11. }
  12. return $resimbir;
  13. }//resimgoster
  14. public static function kelimedenbol($metin, $karaktersayisi){
  15. $icerik = htmlspecialchars_decode($metin);
  16. $icerik = strip_tags($icerik);
  17. $icerik = str_replace(array("\t","\r","\n"), ' ',$icerik);
  18. $icerik_bol = explode(' ', $icerik); // metini bosluklara gore bolduk
  19. $icerik = '';
  20. for($i = 0; $i < count($icerik_bol); $i++) {
  21. if ($icerik_bol[$i] != '') // veri yok mu? Atla, varsa ekle
  22. $icerik .= trim($icerik_bol[$i]).' ';
  23. }
  24. if( preg_match('/(.*?)\s/i', substr($icerik, $karaktersayisi), $dizi) )
  25. return $icerik = substr($icerik, 0, $karaktersayisi+strlen($dizi[0])).'...';
  26. } //kelimedenbol
  27. public static function decode($deger){ echo htmlspecialchars_decode($deger);}//decode
  28. /* sonsuz menu fonksiyonu */
  29. public static function katmenu($parent = '0') {
  30. $sql = DB::get('kategori')->result();
  31. foreach($sql AS $key){
  32. $diziler[$key->id] = [
  33. 'kat_seo' => $key->kat_seo,
  34. 'kategori' => $key->kategori,
  35. 'ust_kategori_id' => $key->ust_kategori_id,
  36. 'id' => $key->id
  37. ];
  38. }
  39. $has_childs = false;
  40. foreach($diziler as $key => $value) {
  41. if ($value['ust_kategori_id'] == $parent) {
  42. if ($has_childs === false){
  43. $has_childs = true;
  44. echo '<ul>';
  45. }
  46. echo '<li><a href="'.baseUrl().'kategori/'.$value['id'].'-'.$value['kat_seo'].'.html">'.$value['kategori'].'</a>';
  47. Afunc::katmenu($key);
  48. echo '</li>';
  49. }
  50. }
  51. if ($has_childs === true) echo "</ul>";
  52. }//katmenu
  53. public static function breadcrumbs($text = 'Buradasınız: ', $sep = ' &raquo; ', $home = 'Anasayfa') {
  54. $bc = '<div xmlns:v="http://rdf.data-vocabulary.org/#" id="crums">'.$text;
  55. $site = 'http://'.$_SERVER['HTTP_HOST'];
  56. $crumbs = array_filter( explode("/",$_SERVER["REQUEST_URI"]) );
  57. $bc .= '<span typeof="v:Breadcrumb"><a href="'.$site.'" rel="v:url" property="v:title">'.$home.'</a>'.$sep.'</span>';
  58. $nm = count($crumbs);
  59. $i = 1;
  60. foreach($crumbs as $crumb){
  61. $link = ucfirst( str_replace( array(".html","-","_"), array(""," "," ") ,$crumb) );
  62. $sep = $i==$nm?'':$sep;
  63. $site .= '/'.$crumb;
  64. $bc .= '<span typeof="v:Breadcrumb"><a href="'.$site.'" rel="v:url" property="v:title">'.$link.'</a>'.$sep.'</span>';
  65. $i++;
  66. }
  67. $bc .= '</div>';
  68. return $bc;
  69. }//breadcrumbs
  70. public static function catname($d = '',$seo = ''){
  71. if($seo){
  72. return DB::select('kat_seo')->where('id',$d)->get('kategori')->value();
  73. }else{
  74. return DB::select('kategori')->where('id',$d)->get('kategori')->value();
  75. }
  76. }
  77. public static function tcevir($tarih) {
  78. $bosluk = explode(' ', $tarih);
  79. $tr = explode("-",$bosluk['0']);
  80. $tarih1 = $tr['2']."-".$tr['1']."-".$tr['0'];
  81. return $tarih1;
  82. } //tcevir
  83. public static function jalert($p){echo '<script>alert("'.$p.'")</script>';}//jalert
  84. public static function git($link = ''){
  85. if($link){
  86. echo '<meta http-equiv="refresh" content="0; url='.baseUrl().'/'.$link.'">';
  87. }else{
  88. echo '<meta http-equiv="refresh" content="0; url='.baseUrl().'">';
  89. }
  90. }//git
  91. public static function sifreuret($uzunluk){
  92. $pwd = '';
  93. if(!is_numeric($uzunluk) || $uzunluk <= 0){$uzunluk = 8; }
  94. if($uzunluk > 32){$uzunluk = 32;}
  95. $karakter = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  96. mt_srand(microtime() * 1000000);
  97. for($i = 0; $i < $uzunluk; $i++){
  98. $key = mt_rand(0,strlen($karakter)-1);
  99. $pwd = $pwd . $karakter{$key};
  100. }
  101. for($i = 0; $i < $uzunluk; $i++){
  102. $key1 = mt_rand(0,strlen($pwd)-1);
  103. $key2 = mt_rand(0,strlen($pwd)-1);
  104. $tmp = $pwd{$key1};
  105. $pwd{$key1} = $pwd{$key2};
  106. $pwd{$key2} = $tmp;
  107. }
  108. return $pwd;
  109. }// şifreüret
  110. }