Advertisement
Lucas_mathais

site.class.php

Jul 11th, 2016
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.50 KB | None | 0 0
  1. <?php
  2.  
  3. class Site extends BD{
  4.  
  5.  
  6.  
  7. private $conexao;
  8.  
  9.  
  10.  
  11. public function getData(){
  12.  
  13. $data = getdate();
  14.  
  15. $diaHoje = date('d');
  16.  
  17. $array_meses = array(1 => "Janeiro", 2 => "Fevereiro", 3 => "Março", 4 => "Abril", 5 => "Maio", 6 => "Junho",
  18.  
  19. 7 => "Julho", 8 => "Agosto", 9 => "Setembro", 10 => "Outubro", 11 => "Novembro", 12 => "Dezembro");
  20.  
  21.  
  22.  
  23. $horaAgora = date('H:i');
  24.  
  25. $mesgetdate = $data['mon'];
  26.  
  27. $anoAtual = date('Y');
  28.  
  29.  
  30.  
  31. return 'Hoje, '.$diaHoje.' de '.$array_meses[$mesgetdate].' de '.$anoAtual.', ás '.$horaAgora.'';
  32.  
  33. }// armazena e retorna a string da data atual!!
  34.  
  35.  
  36.  
  37. public function produtosFaltando(){
  38.  
  39. $verificar = self::conn()->prepare("SELECT id FROM `loja_produtos` WHERE estoque = '0'");
  40.  
  41. $verificar->execute();
  42.  
  43. $numero = $verificar->rowCount();
  44.  
  45.  
  46.  
  47. if($numero == 0){}else{
  48.  
  49. echo '<span>'.$numero.'</span>';
  50.  
  51. }
  52.  
  53. }//produtos em falta
  54.  
  55.  
  56.  
  57. public function atualizarViews(){
  58.  
  59. $selecionar = self::conn()->prepare("SELECT visitas FROM `loja_configs`");
  60.  
  61. $selecionar->execute();
  62.  
  63. $views = $selecionar->fetchObject();
  64.  
  65.  
  66.  
  67. if($views->visitas >= 999){
  68.  
  69. $atualizar = self::conn()->prepare("UPDATE `loja_configs` SET visitas = '0'");
  70.  
  71. $atualizar->execute();
  72.  
  73. }else{
  74.  
  75. $atualizar = self::conn()->prepare("UPDATE `loja_configs` SET visitas = visitas+1");
  76.  
  77. $atualizar->execute();
  78.  
  79. }
  80.  
  81. }
  82.  
  83.  
  84.  
  85.  
  86.  
  87. public function getMenu(){
  88.  
  89. $imagem_cat = '<img src="'.PATH.'/images/arrow.png" border="0"/>';
  90.  
  91. $pegar_categorias = "SELECT * FROM `loja_categorias` ORDER BY id DESC";
  92.  
  93. $executar = self::conn()->prepare($pegar_categorias);
  94.  
  95. $executar->execute();
  96.  
  97. if($executar->rowCount() == 0){}else{
  98.  
  99. while($categoria = $executar->fetchObject()){
  100.  
  101. echo '<li>'.$imagem_cat.'<a href="'.PATH.'/categoria/'.$categoria->slug.'">'.$categoria->titulo.'';
  102.  
  103.  
  104.  
  105. $pegar_subcategorias = "SELECT * FROM `loja_subcategorias` WHERE id_cat = ?";
  106.  
  107. $executar_sub = self::conn()->prepare($pegar_subcategorias);
  108.  
  109. $executar_sub->execute(array($categoria->id));
  110.  
  111. if($executar_sub->rowCount() == 0){echo '</li>';}else{
  112.  
  113. echo '<ul>';
  114.  
  115. while($subcategoria = $executar_sub->fetchObject()){
  116.  
  117. echo '<li>'.$imagem_cat.'<a href="'.PATH.'/categoria/'.$categoria->slug.'/'.$subcategoria->slug.'">'.$subcategoria->titulo.'</a></li>';
  118.  
  119. }//termina while subcategoria
  120.  
  121. echo '</ul></li>';
  122.  
  123. }//termina else dos resultados da subcategoria
  124.  
  125.  
  126.  
  127. }//termina while das CATEGORIAS
  128.  
  129. }//termina else
  130.  
  131. }//termina função get menu
  132.  
  133.  
  134.  
  135.  
  136.  
  137. public function getBanners(){
  138.  
  139. $sqlBanners = "SELECT * FROM `loja_banners` ORDER BY id DESC LIMIT 7";
  140.  
  141. return self::conn()->query($sqlBanners);
  142.  
  143. }//pega os banners do slide principal
  144.  
  145.  
  146.  
  147. public function getProdutosHome($limit = false){
  148.  
  149. if($limit == false){
  150.  
  151. $query = "SELECT * FROM `loja_produtos` ORDER BY id DESC";
  152.  
  153. }else{
  154.  
  155. $query = "SELECT * FROM `loja_produtos` ORDER BY id DESC LIMIT $limit";
  156.  
  157. }
  158.  
  159. return self::conn()->query($query);
  160.  
  161. }//pegar os produtos da home
  162.  
  163.  
  164.  
  165. public function atualizarViewCat($slug){
  166.  
  167.  
  168.  
  169. $strSQL = "UPDATE `loja_categorias` SET views = views+1 WHERE slug = ?";
  170.  
  171. $executar_view = self::conn()->prepare($strSQL);
  172.  
  173. $executar_view->execute(array($slug));
  174.  
  175.  
  176.  
  177. }//atualiza views da categoria
  178.  
  179.  
  180.  
  181. public function atualizarViewSub($slug){
  182.  
  183.  
  184.  
  185. $strSQL = "UPDATE `loja_subcategorias` SET views = views+1 WHERE slug = ?";
  186.  
  187. $executar_view = self::conn()->prepare($strSQL);
  188.  
  189. $executar_view->execute(array($slug));
  190.  
  191.  
  192.  
  193. }//atualiza views da subcategoria
  194.  
  195.  
  196.  
  197.  
  198.  
  199. //metodo de insert
  200.  
  201. public function inserir($tabela, $dados){
  202.  
  203. $pegarCampos = array_keys($dados);
  204.  
  205. $contarCampos = count($pegarCampos);
  206.  
  207. $pegarValores = array_values($dados);
  208.  
  209. $contarValores = count($pegarValores);
  210.  
  211.  
  212.  
  213. $sql = "INSERT INTO $tabela (";
  214.  
  215. if($contarCampos == $contarValores){
  216.  
  217. foreach($pegarCampos as $campo){
  218.  
  219. $sql .= $campo.', ';
  220.  
  221. }
  222.  
  223. $sql = substr_replace($sql, ")", -2, 1);
  224.  
  225. $sql .= "VALUES (";
  226.  
  227.  
  228.  
  229. for($i = 0; $i <$contarValores; $i++){
  230.  
  231. $sql .= "?, ";
  232.  
  233. $i;
  234.  
  235. }
  236.  
  237.  
  238.  
  239. $sql = substr_replace($sql, ")", -2, 1);
  240.  
  241. }else{
  242.  
  243. return false;
  244.  
  245. }
  246.  
  247.  
  248.  
  249. try{
  250.  
  251. $inserir = self::conn()->prepare($sql);
  252.  
  253. if($inserir->execute($pegarValores)){
  254.  
  255. return true;
  256.  
  257. }else{
  258.  
  259. return false;
  260.  
  261. }
  262.  
  263. }catch(PDOException $e){
  264.  
  265. return false;
  266.  
  267. }
  268.  
  269. }
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277. //seleção dinamica
  278.  
  279.  
  280.  
  281. public function selecionar($tabela, $dados, $condicao = false, $order = false){
  282.  
  283. $pegarValores = implode(', ', $dados);
  284.  
  285. $contarValores = count($pegarValores);
  286.  
  287.  
  288.  
  289. if($condicao == false){
  290.  
  291. if($contarValores > 0){
  292.  
  293. if($order != false){
  294.  
  295. $sql = "SELECT $pegarValores FROM $tabela ORDER BY $order";
  296.  
  297. }else{
  298.  
  299. $sql = "SELECT $pegarValores FROM $tabela";
  300.  
  301. }
  302.  
  303. $this->conexao = self::conn()->prepare($sql);
  304.  
  305. $this->conexao->execute();
  306.  
  307. return $this->conexao;
  308.  
  309. }
  310.  
  311. }else{
  312.  
  313. //existe condição para selecionar
  314.  
  315. $pegarCondCampos = array_keys($condicao);
  316.  
  317. $contarCondCampos = count($pegarCondCampos);
  318.  
  319. $pegarCondValores = array_values($condicao);
  320.  
  321.  
  322.  
  323. $sql = "SELECT $pegarValores FROM $tabela WHERE ";
  324.  
  325. foreach($pegarCondCampos as $campoCondicao){
  326.  
  327. $sql .= $campoCondicao." = ? AND ";
  328.  
  329. }
  330.  
  331. $sql = substr_replace($sql, "", -5, 5);
  332.  
  333.  
  334.  
  335. foreach($pegarCondValores as $condValores){
  336.  
  337. $dadosExec[] = $condValores;
  338.  
  339. }
  340.  
  341. if($order){$sql .= " ORDER BY $order";}
  342.  
  343. $this->conexao = self::conn()->prepare($sql);
  344.  
  345. $this->conexao->execute($dadosExec);
  346.  
  347. return $this->conexao;
  348.  
  349. }
  350.  
  351. }
  352.  
  353.  
  354.  
  355. public function listar(){
  356.  
  357. $lista = $this->conexao->fetchAll();
  358.  
  359. return $lista;
  360.  
  361. }
  362.  
  363.  
  364.  
  365. //metodo para envio de emails junto ao phpmailer
  366.  
  367. public function sendMail($subject, $msg, $from, $nomefrom, $destino, $nomedestino){
  368.  
  369. require_once "mailer/class.phpmailer.php";
  370.  
  371. $mail = new PHPMailer();//instancia a classe PHPMailer
  372.  
  373.  
  374.  
  375. $mail->isSMTP();//habilita envio smtp
  376.  
  377. $mail->SMTPAuth = true;//autentico o envio smtp
  378.  
  379. $mail->Host = 'smtps.bol.com.br';
  380.  
  381. $mail->Port = '587';
  382.  
  383.  
  384.  
  385. //começar o envio do email
  386.  
  387. $mail->Username = 'multilukeraprogames@bol.com.br';
  388.  
  389. $mail->Password = '************';
  390.  
  391.  
  392.  
  393. $mail->From = $from;//email de quem envia
  394.  
  395. @$mail->FromName = $namefrom;//nome de quem envia
  396.  
  397.  
  398.  
  399. $mail->isHTML(true);//seta que é html o email
  400.  
  401. $mail->Subject = utf8_decode($subject);
  402.  
  403. $mail->Body = utf8_decode($msg);//corpo da mensagem
  404.  
  405. $mail->AddAddress($destino, utf8_decode($nomedestino));//seto o destino do email
  406.  
  407.  
  408.  
  409. if($mail->Send()){
  410.  
  411. return true;
  412.  
  413. }else{
  414.  
  415. return false;
  416.  
  417. }
  418.  
  419. }
  420.  
  421.  
  422.  
  423. function upload($tmp, $name, $nome, $larguraP, $pasta){
  424.  
  425.  
  426.  
  427. $ext = end(explode('.', $name));
  428.  
  429. if($ext=='jpg' || $ext == 'JPG' || $ext == 'jpeg' || $ext == 'JPEG'){
  430.  
  431. $img = imagecreatefromjpeg($tmp);
  432.  
  433. }elseif($ext == 'png'){
  434.  
  435. $img = imagecreatefrompng($tmp);
  436.  
  437. }elseif($ext == 'gif'){
  438.  
  439. $img = imagecreatefromgif($tmp);
  440.  
  441. }
  442.  
  443. list($larg, $alt) = getimagesize($tmp);
  444.  
  445. $x = $larg;
  446.  
  447. $y = $alt;
  448.  
  449. $largura = ($x>$larguraP) ? $larguraP : $x;
  450.  
  451. $altura = ($largura*$y)/$x;
  452.  
  453.  
  454.  
  455. if($altura>$larguraP){
  456.  
  457. $altura = $larguraP;
  458.  
  459. $largura = ($altura*$x)/$y;
  460.  
  461. }
  462.  
  463. $nova = imagecreatetruecolor($largura, $altura);
  464.  
  465. imagecopyresampled($nova, $img, 0,0,0,0, $largura, $altura, $x, $y);
  466.  
  467.  
  468.  
  469. imagejpeg($nova, $pasta.$nome);
  470.  
  471. imagedestroy($img);
  472.  
  473. imagedestroy($nova);
  474.  
  475. return (file_exists($pasta.$nome)) ? true : false;
  476.  
  477. }
  478.  
  479. //recupera o vídeo institucional
  480.  
  481. public function get_video(){
  482.  
  483. $selecionar_url = self::conn()->prepare("SELECT video FROM `loja_configs`");
  484.  
  485. $selecionar_url->execute();
  486.  
  487. $fetchVideo = $selecionar_url->fetchObject();
  488.  
  489. if(substr_count($fetchVideo->video, 'youtube') == 1){
  490.  
  491. $idVideo = substr($fetchVideo->video, 31, 11);
  492.  
  493. echo '<iframe width="370" height="208" src="http://www.youtube.com/embed/'.$idVideo.'" frameborder="0" allowfullscreen></iframe>';
  494.  
  495. }elseif(substr_count($fetchVideo->video, 'vimeo') == 1){
  496.  
  497. $idVideo = substr($fetchVideo->video, 17);
  498.  
  499. echo '<iframe src="http://player.vimeo.com/video/'.$idVideo.'?title=0&amp;byline=0&amp;portrait=0&amp;color=099e16" frameborder="0" width="370" height="208"></iframe>';
  500.  
  501. }
  502.  
  503. }
  504.  
  505. }
  506.  
  507. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement