protected function getContent($id, $width = "400", $height = "400") { //pega a CategoryVO $ContentVO = new ContentSiteVO(); $ContentVO->setId($id, TRUE); $images = $ContentVO->getImages(); $stdResult = new stdClass(); $stdResult->title = $ContentVO->getTitle(); $stdResult->content = $ContentVO->getContent(); $stdResult->image_url = array(); if (count($images) > 0) { foreach ($images as $image) { $url = Config::getRootPath("/image/get_image/image_id." . $image->id . "/max_width.{$width}/max_height.{$height}/crop.1/"); //é o link $stdResult->image_url[] = $url; } } return $stdResult; }
/** * baixar o zip do mal * ?products={product_id:N,gallery:true,dimensions:true,files:[]}|{product_id:N,gallery:true,dimensions:true,files:[]} */ public function getZip() { if (!UserClient::getId() > 0) { //nao tem permissao Navigation::redirect("405"); exit; } set_time_limit(0); //tratando variaveis enviadas $files_id = DataHandler::getValueByArrayIndex($_POST, "file_id"); $imagens = DataHandler::getValueByArrayIndex($_POST, "imagens"); $pdf = DataHandler::getValueByArrayIndex($_POST, "pdf"); //precisa saber quais sao os produtos envolvidos $array_products_id = array(); $array_files = array(); if ($files_id) { foreach ($files_id as $file_id) { $temp_array = explode("_", $file_id); $product_id = $temp_array[0]; if (!in_array($product_id, $array_products_id)) { $array_products_id[] = $product_id; $array_files[] = $product_id; } } } if ($imagens) { foreach ($imagens as $product_id) { if (!in_array($product_id, $array_products_id)) { $array_products_id[] = $product_id; } } } if ($pdf) { foreach ($pdf as $product_id) { if (!in_array($product_id, $array_products_id)) { $array_products_id[] = $product_id; } } } $ReturnResultVO = new ReturnResultVO(); $ProductVO = new ContentSiteVO(); $FileVO = new FileVO(); //se tiver produtos para tratar if (count($array_products_id) > 0) { //a pasta zip precisa existir $zip_path = "upload/zip/"; DataHandler::createFolderIfNotExist($zip_path); $array_products_to_zip = array(); $unique_str = ""; //nome final do zip que vai baixar, adiciona alguns parametros indicadores $zip_name = "teto"; if (count($array_products_id) > 0) { //sao varios produtos $zip_name = $zip_name . "_produtos"; } //cada indice dessa array, tem que ser array, terá um json com as info: foreach ($array_products_id as $product_id) { $resultProduto = $ProductVO->setId($product_id, TRUE); if ($resultProduto->success) { $stdProduct = $ProductVO->toStdClass(); $array_products_to_zip[] = $stdProduct; $array_images = array(); if ($imagens) { if (in_array($product_id, $imagens)) { $array_gallery = $ProductVO->getImages(NULL, "gallery", true); foreach ($array_gallery as $imageVO) { $array_images[] = $imageVO->getURL(); $unique_str .= "|" . $imageVO->getId(); //add a imagem na pasta } // $array_dimensions = $ProductVO->getImages(NULL, "dimensions", true); foreach ($array_dimensions as $imageVO) { $array_images[] = $imageVO->getURL(); //add a imagem na pasta $unique_str .= "|" . $imageVO->getId(); } } } $stdProduct->images = $array_images; $array_file_vo = array(); //cria a pasta do produto no zip $product_folder_name = DataHandler::strToURL($stdProduct->title); if (count($array_files) > 0) { if (in_array($product_id, $array_files)) { //esse produto pediu algum file $temp_array_files = $ProductVO->getFiles(); foreach ($temp_array_files as $FileVO) { if (in_array($FileVO->id, $files_id)) { $array_file_vo[] = $FileVO; $unique_str .= "|f." . $file_id; //add a url do arquivo no zip na pasta } } } } $stdProduct->files = $array_file_vo; $stdProduct->pdf = null; //verificar se quer o pdf if (count($pdf) > 0) { $unique_str .= "|pdf!|"; //quero pdf //ver com onde foi salvo if (in_array($product_id, $pdf)) { //ele quer esse pdf, provavelmente se chegou aqui é porque ele realmente exite //mas vou conferir de novo $pdf_url = "upload/pdf/{$product_id}/" . $ProductVO->slug . ".pdf"; if (file_exists($pdf_url)) { $stdProduct->pdf = $pdf_url; } } } } //end if produto sucess } $folder_name = md5($unique_str); DataHandler::createFolderIfNotExist($zip_path . $folder_name . "/"); $zip_name = $zip_path . $folder_name . "/" . $zip_name . ".zip"; //echo $zip_name;exit(); if (!file_exists($zip_name)) { //echo Debug::li($zip_name);exit(); $Zip = new ZipArchive(); $Zip->open($zip_name, ZipArchive::CREATE); //adicionando os arquivos escolhidos foreach ($array_products_to_zip as $ProductStd) { $product_slug_folder = $ProductStd->id . "_" . DataHandler::strToURL($ProductStd->title); foreach ($ProductStd->files as $FileVO) { $url = $FileVO->getUrl(); $array = explode("/", $url); $file = $array[count($array) - 1]; $Zip->addFile($url, $product_slug_folder . "/arquivos/" . $file); } foreach ($ProductStd->images as $url) { //$url = $ImageVO->getUrl(); $array = explode("/", $url); $file = $array[count($array) - 1]; $file = str_replace("original_", "", $file); $Zip->addFile($url, $product_slug_folder . "/imagens/" . $file); } if ($ProductStd->pdf) { $url = $ProductStd->pdf; $array = explode("/", $url); $file = $array[count($array) - 1]; $Zip->addFile($url, $product_slug_folder . "/ficha_tecnica.pdf"); } } $Zip->close(); } header("Location: " . Config::getRootPath($zip_name)); exit; } exit; }
/** * * Para acessar isso aqui seria a url: pdf_download/produto/id.N/ */ public function cliente($id = false) { if ($id == FALSE) { $id = DataHandler::forceInt(DataHandler::getValueByArrayIndex($this->arrayVariable, "id")); } if ($id > 0) { $ContentSiteVO = new ContentSiteVO(); $ReturnResult_vo = $ContentSiteVO->setId($id, TRUE); if ($ReturnResult_vo->success) { $stdProduct = $ContentSiteVO->toStdClass(); $stdProduct->array_gallery = $ContentSiteVO->getImages(NULL, "gallery", true); $stdProduct->array_tagged = $ContentSiteVO->getImages(NULL, "tagged", true); $html_start = "<html><body>"; $html_end = "</body></html>"; $detail_page = file_get_contents(Config::getFolderView("/PdfDownload/detail.tpl")); $image_page = file_get_contents(Config::getFolderView("/PdfDownload/image.tpl")); $dimension_page = file_get_contents(Config::getFolderView("/PdfDownload/dimension.tpl")); $tpl_img_path = "view/site/"; //Config::getAsset() ; $recover_logo = $stdProduct->hat == 1 ? '<img style=" margin-top: 4px; margin-left: 5px; " src="' . $tpl_img_path . '/PdfDownload/recover_logo.png" />' : ""; $stdProduct->description = utf8_decode($stdProduct->description); $stdProduct->title = utf8_decode($stdProduct->title); $stdProduct->content = utf8_decode($stdProduct->content); $common_tpl_data = array("###IMG_TPL_PATH###", "###content###", "###title###", "###PRODUCT_URI###", "###recover_logo###"); $common_data = array($tpl_img_path, $stdProduct->content, $stdProduct->title, Config::getRootPath('produto/id.' . $stdProduct->id . '/' . $stdProduct->slug), $recover_logo); $detail_page = str_replace($common_tpl_data, $common_data, $detail_page); $image_page = str_replace($common_tpl_data, $common_data, $image_page); $dimension_page = str_replace($common_tpl_data, $common_data, $dimension_page); $detail_page = str_replace("###description###", $stdProduct->description, $detail_page); $html = $html_start . $detail_page; foreach ($stdProduct->array_gallery as $image) { $w = 600; $h = 550; $img_url = "image/get_image/image_id." . $image->id . "/max_width.{$w}/max_height.{$h}/"; // Debug::print_r( $img_url ) ; // $tmp = file_get_contents( $img_url ) ; // unset( $tmp ) ; // $new_page = str_replace( "###IMAGE_SRC###" , Config::getRootPath( "image/get_image/image_id." . $image->id . "/max_width.600/max_height.525/" ) , $image_page ) ; // $new_page = str_replace( "###IMAGE_SRC###" , $image->url , $image_page ) ; $img_name = preg_replace("/\\.jpg\$/", "", $image->url); // $sys_img = $img_name . "_w{$w}_h{$h}_m_no_crop.jpg" ; $sys_img = $img_name . "_w{$w}_h{$h}_m_cache_crop.jpg"; // Debug::print_r($sys_img ) ; // var_dump( file_exists($sys_img) ) ; // die; $new_page = str_replace("###IMAGE_SRC###", $sys_img, $image_page); // Debug::print_r( $image ) ; die; $html .= $new_page; // break; } $html .= $html_end; // echo $html ; die; $dompdf = new DOMPDF(); $dompdf->load_html($html); $dompdf->render(); //$dompdf->stream( "upload/pdf/" . $stdProduct->id . "/" . $stdProduct->slug . ".pdf") ; $file = $stdProduct->slug . ".pdf"; $path = "upload/pdf/" . $stdProduct->id . "/"; if (!dir($path)) { mkdir($path, 0777, true); } $html_file = "print.html"; $html = str_replace("src=\"", "src=\"" . Config::getRootPath(), $html); $fp = fopen($path . $html_file, "w"); fwrite($fp, $html); fclose($fp); $pdfoutput = $dompdf->output(); // $filename = $output; $fp = fopen($path . $file, "w"); fwrite($fp, $pdfoutput); fclose($fp); return true; } else { //não achou um produto com esse id return false; Navigation::redirect(""); } } else { return false; //não mandou o id, vai pra listagem ((!?) TODO: ver se é isso mesmo) Navigation::redirect("clientes"); } }
public function sendToFriend() { $returnResult = new HttpResult(); $retornoDaPaginaHTML = new HttpRoot(); $returnResult->setHttpContentResult($retornoDaPaginaHTML); if (!isset($_POST["action"])) { $protuct_id = DataHandler::forceInt(DataHandler::getValueByArrayIndex($this->arrayVariable, "id")); $retornoDaPaginaHTML->form_action = Config::getRootPath("produto/send_to_friend"); $retornoDaPaginaHTML->view = "form"; $retornoDaPaginaHTML->product_id = $protuct_id; } else { $postData = (object) $_POST; $ContentSiteVO = new ContentSiteVO(); $ReturnResult_vo = $ContentSiteVO->setId($postData->id, TRUE); if ($ReturnResult_vo->success) { $stdProduct = $ContentSiteVO->toStdClass(); $stdProduct->array_gallery = $ContentSiteVO->getImages(NULL, "gallery", true); // Debug::print_r($stdProduct); die; $template = file_get_contents(Config::getFolderView("/templates/email_produto.php")); $tpl_img_path = Config::getRootPath(Config::getFolderView()); $recover_logo = $stdProduct->hat == 1 ? '<img style="" src="' . $tpl_img_path . '/assets/images/recover-min.png" />' : ""; $first_image = sprintf("<img width='400px' src='%s' />", Config::getRootPath($stdProduct->array_gallery[0]->url)); $replace_from = array("###PRODUCT_URI###", "###IMG_PATH###", "###TITLE###", "###HAT###", "###CONTENT###", "###IMG###", "###SENDER_NAME###", "###SENDER_EMAIL###", "###RECEIVER_NAME###", "###RECEIVER_MAIL###", "###RECEIVER_MESSAGE###"); $replace_to = array(Config::getRootPath('produto/id.' . $stdProduct->id . '/' . $stdProduct->slug), $tpl_img_path, utf8_decode($stdProduct->title), $recover_logo, $stdProduct->content, $first_image, $postData->sender_name, $postData->sender_email, $postData->receiver_name, $postData->receiver_email, $postData->receiver_message); $template = str_replace($replace_from, $replace_to, $template); // var_dump( $stdProduct , $postData ) ; // echo $template ; die; $host = Config::SYSTEM_MAIL_SMTP; $mail = Config::SYSTEM_MAIL_LOGIN; $senha = Config::SYSTEM_MAIL_PASSWORD; // var_dump( $host , $mail , $senha ) ; die ; ob_start(); $smtp = new Smtp($host, 587); $smtp->user = $mail; $smtp->pass = $senha; $smtp->debug = true; // $from = "'" . $postData->sender_name . "' <" . Config::SYSTEM_MAIL_FROM . ">" ; // $to = "'" . $postData->sender_name . "' <" . $postData->receiver_mail . ">" ; $from = Config::SYSTEM_MAIL_FROM; $to = $postData->receiver_email; $subject = "Indicação de produto"; $msg = $template; $retornoDaPaginaHTML->sucess = $smtp->Send($to, $from, $subject, $msg, "text/html") ? true : false; ob_end_clean(); //var_dump( $send ) ; } $retornoDaPaginaHTML->view = "result"; } return $returnResult; }