Footer(); } function setup(){ $this->pdf->SetCreator(PDF_CREATOR); $this->pdf->SetAuthor('Яковлев А.Л.'); $this->pdf->SetTitle('РПД заголовок'); $this->pdf->SetSubject('РПД тема'); $this->pdf->SetKeywords('Яковлев, alneo.ru'); //$this->pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128)); //$this->pdf->setFooterData(array(0,64,0), array(0,64,128)); $this->pdf->setPrintHeader(false); //$this->pdf->setPrintFooter(false); $this->pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $this->pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $this->pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins //$this->pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $this->pdf->SetMargins(15, 5, 15); //$this->pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $this->pdf->SetHeaderMargin(2); //$this->pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $this->pdf->SetFooterMargin(5); // set auto page breaks $this->pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $this->pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); $this->pdf->setFontSubsetting(true); $this->pdf->SetFont('dejavusans', '', 10, '', true); // set text shadow effect //$this->pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal')); } function close_HTML_tags($content){ $position = 0; $open_tags = array(); //теги для игнорирования $ignored_tags = array('br', 'hr', 'img'); while (($position = strpos($content, '<', $position)) !== FALSE){ //забираем все теги из контента if (preg_match("|^<(/?)([a-z\d]+)\b[^>]*>|i", substr($content, $position), $match)){ $tag = strtolower($match[2]); //игнорируем все одиночные теги if (in_array($tag, $ignored_tags) == FALSE){ //тег открыт if (isset($match[1]) AND $match[1] == ''){ if (isset($open_tags[$tag])) $open_tags[$tag]++; else $open_tags[$tag] = 1; } //тег закрыт if (isset($match[1]) AND $match[1] == '/'){ if (isset($open_tags[$tag])) $open_tags[$tag]--; } } $position += strlen($match[0]); }else $position++; } //закрываем все теги foreach ($open_tags as $tag => $count_not_closed){ $content .= str_repeat("", $count_not_closed); } return $content; } function purifierHTML($html){ //https://habr.com/ru/company/smartprogress/blog/202188/ require_once 'inc/htmlpurifier/library/HTMLPurifier.auto.php'; $config = HTMLPurifier_Config::createDefault(); $config->set('Attr.AllowedClasses',array('header')); // или Attr.ForbiddenClasses имеются ввиду CSS классы $config->set('AutoFormat.RemoveEmpty',true);// удаляет пустые теги, есть исключения* $config->set('HTML.Doctype','HTML 4.01 Strict'); // обратите внимание как заменился тег $purifier = new HTMLPurifier($config); $clean_html = $purifier->purify($html); return $clean_html; } function parseHTML($text){ $out = $text; //echo htmlspecialchars($out).'
'; $m1=array('",="" "','",=""',',="" "','";=""',':=""',';=""',';"=""'); $m2=array('="" ','=""','="" ','="" ','=""','=""','="" '); $out = str_replace($m1,$m2,$out); //preg_match_all('/\s(.*)=(.*)\s/i',$out,$arr); //preg_match_all('/<(.*)>/isU',$out,$arr); //echo '
'.print_r($arr,1).'
'; $out = preg_replace('/background-color:(.*?);/i','',$out,-1); $out = preg_replace('/color:(.*?);/i','',$out,-1); $out = preg_replace('/font-family:(.*?);/i','',$out,-1); $out = preg_replace('/font-size:(.*?);/i','',$out,-1); //$out = preg_replace('//i','',$out,-1); $out = preg_replace('//i','',$out,-1); $out = preg_replace('//i','',$out,-1); $out = preg_replace('//i','',$out,-1); $out = preg_replace('//i','',$out,-1); $out = str_replace('https://eios.mkgtu.ru','',$out); //echo htmlspecialchars($out).'
'; //Закроем все не закрытые тэги HTML <> $out = preg_replace_callback('|<(.*)<|isU',function ($itt){ if(strpos($itt[1],'>')===false) return '<'.$itt[1].'><'; else return '<'.$itt[1].'<'; },$out); $out = preg_replace_callback('|="(.*)>|isU',function ($itt){ if(substr_count($itt[1],'"')%2 == 0) return '="' . $itt[1] . '">'; else return '="' . $itt[1] . '>'; },$out); $out = $this->close_HTML_tags($out); //echo htmlspecialchars($out).'
'; $out = $this->purifierHTML($out); $out = str_replace('pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $cQR = new class_QRcode(); $hash = md5('SaLMKGTUYakovlev_'.$rpd['id'].'_'); $out['hash'] = $hash; $QRfile = $cQR->QR_get('https://eios.mkgtu.ru/rabprog/Q/'.$hash.'/'); $this->pdf->setQRFile($QRfile); $this->setup(); //$this->pdf->AddPage(); //echo '
'.print_r($rpd,1).'
'; exit(); //echo htmlspecialchars($rpd['razdel1']).'
'; $rpd['razdel1'] = $this->parseHTML($rpd['razdel1']); $rpd['razdel2'] = $this->parseHTML($rpd['razdel2']); //echo htmlspecialchars($rpd['razdel7_3']).'
'; $rpd['razdel7_3'] = $this->parseHTML($rpd['razdel7_3']); //echo $this->purifierHTML($rpd['razdel7_3']);exit(); //echo htmlspecialchars($rpd['razdel7_3']);exit(); $rpd['razdel7_4'] = $this->parseHTML($rpd['razdel7_4']); $rpd['razdel9'] = $this->parseHTML($rpd['razdel9']); //echo '
'.print_r($rpd,1).'
'; //echo '
'.print_r($DISCIPS,1).'
';exit(); $this->pdf->SetTitle($DISCIP['DISCIP_name'].' РПД'); $smarty->assign('DISCIPS', $DISCIPS); $smarty->assign('DISCIP', $DISCIP); $smarty->assign('save', $rpd); $class_FAKKAF = new class_FAKKAF(); if(isset($DISCIPS['Очно-заочная'])) $kafname = $DISCIPS['Очно-заочная']['uchebplan']['kaf_name']; if(isset($DISCIPS['Заочная'])) $kafname = $DISCIPS['Заочная']['uchebplan']['kaf_name']; if(isset($DISCIPS['Очная'])) $kafname = $DISCIPS['Очная']['uchebplan']['kaf_name']; $smarty->assign('FAKKAF', $class_FAKKAF->Item_by_kafname($kafname)); //if($view==0) {//сохраняем файл когда все подписали //Надо собрать подписи всех $class_RPDSign = new class_RPDSign(); $signs = array_reverse ($class_RPDSign->RPDSignsPDF($id_disc_sign,1,$kafname)); $smarty->assign('signs', $signs); //}else{ $smarty->assign('signs', array()); } $cRPD = new class_RPD(); if($cRPD->isRPD_praktik($DISCIP)) { $html = $smarty->fetch('page_rpd_praktik_pdf.html'); }else { $html = $smarty->fetch('page_rpd_pdf.html'); } //echo $html; //echo '
$id_disc_sign='.$id_disc_sign.'
'; //echo '
$DISCIPS'.print_r($DISCIPS,1).'
'; //echo '
$DISCIP'.print_r($DISCIP,1).'
'; //echo '
$signs'.print_r($signs,1).'
'; //exit(); //echo $html; exit(); //$this->pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); $delimiter = '
'; $chunks = explode($delimiter, $html); $page_orient = 'P'; foreach($chunks as $k => $page){ if(strpos($page,'