Example #1
0
 public static function init()
 {
     if (!ob_start(function ($buffer) {
         $tidy = new \tidy();
         return $tidy->repairString($buffer, ['input-xml' => true, 'indent' => true, 'wrap' => 0, 'output-xml' => true]);
     })) {
         throw \ErrorException("ob_start failed", null, null, __FILE__, __LINE__);
     }
 }
Example #2
0
 public static function tidyHTML($html)
 {
     if (extension_loaded(tidy)) {
         $tidy = new \tidy();
         $cleanHTML = $tidy->repairString($html, array('indent' => true, 'indent-spaces' => 2, 'show-body-only' => true, 'merge-divs' => false));
         return $cleanHTML;
     } else {
         return $html;
     }
 }
Example #3
0
 /**
  * (non-PHPdoc)
  * @see app/Lib/Browser/Mixin/Browser\Mixin.Iface::after()
  */
 public function after(\stdClass $Object, array $params = [], array $arguments = [])
 {
     if (class_exists('\\tidy')) {
         $Tidy = new \tidy();
         $params['content'] = $Tidy->repairString($params['content'], ['output-xhtml' => true], 'utf8');
         unset($Tidy);
     }
     // возвращаем обработанные данные
     return $params;
 }
Example #4
0
 /**
  * Trims content, then trims each line of content
  *
  * @param string $content
  * @return string
  */
 public function render($content = NULL)
 {
     if ($content === NULL) {
         $content = $this->renderChildren();
     }
     if (class_exists('tidy') === FALSE) {
         throw new Exception('TidyViewHelper requires the PHP extension "tidy" which is not installed or not loaded.', 1352059753);
     }
     $tidy = new tidy();
     return $tidy->repairString($content);
 }
Example #5
0
 protected function getXPath($content)
 {
     $document = new DOMDocument();
     $document->strictErrorChecking = false;
     if ($this->options['tidy'] && extension_loaded('tidy')) {
         //Convert and repair as xhtml
         $tidy = new tidy();
         $content = $tidy->repairString($content, $this->options['tidy_config']);
     }
     $document->loadXML($content, LIBXML_NOERROR | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_NOCDATA);
     $xpath = new DOMXPAth($document);
     $xpath->registerNamespace('xhtml', 'http://www.w3.org/1999/xhtml');
     return $xpath;
 }
 /**
  * pretizeno o TIDY cisteni
  */
 public function setContent($content = "")
 {
     try {
         if (ini_get("magic_quotes_gpc")) {
             $content = stripslashes($content);
         }
         if (class_exists("tidy")) {
             $tidyConfig = array('indent' => true, 'output-xml' => false, 'output-html' => false, 'output-xhtml' => true, 'show-body-only' => true, 'clean' => true, 'wrap' => 200);
             $tidy = new tidy();
             //var_dump($content);
             $content = $tidy->repairString($content, $tidyConfig, 'UTF8');
             //var_dump($content);die;
         }
         return parent::setContent($content);
     } catch (Exception $e) {
         throw $e;
     }
 }
 public function filter(LBoxFormControl $control = NULL)
 {
     try {
         $content = $control->getValue();
         if (ini_get("magic_quotes_gpc")) {
             $content = stripslashes($content);
         }
         if (class_exists("tidy")) {
             $tidyConfig = array('indent' => true, 'output-xml' => false, 'output-html' => false, 'output-xhtml' => true, 'show-body-only' => true, 'clean' => true, 'wrap' => 200);
             $tidy = new tidy();
             //var_dump($content);
             $content = $tidy->repairString($content, $tidyConfig, 'UTF8');
             //var_dump($content);die;
         }
         return $content;
     } catch (Exception $e) {
         throw $e;
     }
 }
Example #8
0
 public function filter(LBoxFormControl $control = NULL)
 {
     try {
         $value = $control->getValue();
         if (function_exists("mb_convert_encoding") && function_exists("mb_convert_encoding")) {
             if (mb_detect_encoding($value) != "UTF-8") {
                 $value = mb_convert_encoding($value, "UTF-8");
             }
         }
         if (class_exists("tidy")) {
             $tidyConfig = array('indent' => true, 'output-xml' => false, 'output-html' => false, 'output-xhtml' => true, 'show-body-only' => true, 'clean' => true, 'wrap' => 200);
             $tidy = new tidy();
             //var_dump($value);
             $value = $tidy->repairString($value, $tidyConfig, 'UTF8');
             //var_dump($value);die;
         }
         return $value;
     } catch (Exception $e) {
         throw $e;
     }
 }
 /**
  * tidy html cleaning or valid html tags
  * @param string $string: content of html
  * @param array $tidyConfig: tidy setting (optional)
  */
 public static function tidy_cleaning($string, $tidyConfig = null, $return = '')
 {
     $out = array();
     $config = array('indent' => true, 'show-body-only' => false, 'clean' => true, 'output-xhtml' => true, 'preserve-entities' => true);
     if ($tidyConfig == null) {
         $tidyConfig =& $config;
     }
     if (!class_exists('tidy')) {
         return;
     }
     $tidy = new tidy();
     $out['full'] = $tidy->repairString($string, $tidyConfig, 'UTF8');
     unset($tidy);
     unset($tidyConfig);
     $out['body'] = preg_replace("/.*<body[^>]*>|<\\/body>.*/si", "", $out['full']);
     $out['style'] = '<style type="text/css">' . preg_replace("/.*<style[^>]*>|<\\/style>.*/si", "", $out['full']) . '</style>';
     if ($return && isset($out[$return])) {
         return $out[$return];
     } else {
         return $out;
     }
 }
Example #10
0
     exit;
     break;
 case 'comment':
     $id = __paramInit('int', 'id');
     if (!$id && !$uid && !isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest') {
         exit;
     }
     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/articles_comments.php';
     $comment = articles_comments::getComment($id);
     $attaches = articles_comments::getAttaches($id, true);
     $result = array();
     $result['success'] = false;
     if (hasPermissions('articles') || $uid == $comment['from_id']) {
         $comment['msgtext'] = preg_replace("/\\h/", ' ', $comment['msgtext']);
         $tidy = new tidy();
         $comment['msgtext'] = $tidy->repairString(str_replace(array(' '), array('&nbsp;'), iconv('CP1251', 'UTF-8', nl2br($comment['msgtext']))), array('show-body-only' => true, 'wrap' => '0'), 'raw');
         $comment['msgtext'] = preg_replace("/\\h/", ' ', $comment['msgtext']);
         $comment['msgtext'] = preg_replace('/\\n?<br\\s?\\/?>\\n?/', "\n", $comment['msgtext']);
         $comment['msgtext'] = html_entity_decode($comment['msgtext']);
         $result['success'] = true;
         $result['data'] = $comment;
         $result['attaches'] = $attaches;
     }
     echo json_encode($result);
     exit;
     break;
 default:
     $content = 'content_index.php';
     //        $page = __paramInit('int', 'p');
     //        if (!$page) $page = 1;
     if (isset($_GET['tag'])) {
Example #11
0
/**
 * Восстанавливает html (закрывает незакрытые теги, правильно расставляет теги и т.д.)
 * при помощи tidy
 *
 * @param string $input Html код
 * @return string       Восстановленный html-код
 */
function repair_html($input)
{
    $input = preg_replace("/(li|ol|ul)>[\n]+/iU", "\$1>", $input);
    $tidy = new tidy();
    $input = $tidy->repairString(str_replace(array(' '), array('&nbsp;'), nl2br($input)), array('show-body-only' => true, 'wrap' => '0'), 'raw');
    $input = str_replace("\n", "", $input);
    $input = preg_replace("/\\h/", " ", $input);
    return $input;
}
Example #12
0
function cleaning($string_to_clean = null, $tidy_config = null)
{
    $config = array('show-body-only' => false, 'clean' => true, 'char-encoding' => 'utf8', 'add-xml-decl' => true, 'add-xml-space' => true, 'output-html' => false, 'output-xml' => false, 'output-xhtml' => true, 'numeric-entities' => false, 'ascii-chars' => false, 'doctype' => 'strict', 'bare' => true, 'fix-uri' => true, 'indent' => true, 'indent-spaces' => 4, 'tab-size' => 4, 'wrap-attributes' => true, 'wrap' => 0, 'indent-attributes' => true, 'join-classes' => false, 'join-styles' => false, 'enclose-block-text' => true, 'fix-bad-comments' => true, 'fix-backslash' => true, 'replace-color' => false, 'wrap-asp' => false, 'wrap-jste' => false, 'wrap-php' => false, 'write-back' => true, 'drop-proprietary-attributes' => false, 'hide-comments' => false, 'hide-endtags' => false, 'literal-attributes' => false, 'drop-empty-paras' => true, 'enclose-text' => true, 'quote-ampersand' => true, 'quote-marks' => false, 'quote-nbsp' => true, 'vertical-space' => true, 'wrap-script-literals' => false, 'tidy-mark' => true, 'merge-divs' => false, 'repeated-attributes' => 'keep-last', 'break-before-br' => true);
    if ($tidy_config == null) {
        $tidy_config = $config;
    }
    $tidy = new tidy();
    $out = $tidy->repairString($string_to_clean, $tidy_config, 'utf8');
    unset($tidy, $tidy_config);
    return $out;
}
Example #13
0
 /**
  * Tidy сжирает память, не рекомендуется пользоваться данной возможностью
  *
  * TODO: разобраться с проблемами памяти в tydy_parse_string
  *
  * @param $sHTML
  * @param array $aOpts
  * @return bool|string
  */
 protected function tidyHTML($sHTML, $aOpts = array())
 {
     if (!empty($aOpts)) {
         $this->setTidyOptions($aOpts);
     }
     $tidy = new tidy();
     $sHTML = $tidy->parseString($sHTML);
     $sHTML = $tidy->repairString($sHTML);
     $sHTML = tidy_parse_string($sHTML, $this->aTidyOptions);
     return $sHTML;
 }
function cleanHTML($html)
{
    $tidy = new tidy();
    return $tidy->repairString($html, array('show-body-only' => true, 'output-html' => true, 'indent' => true), 'UTF8');
}
Example #15
0
function boookattach($results, $type = '')
{
    // Include the main TCPDF library (search for installation path).
    //require_once('tcpdf/examples/tcpdf_include.php');
    $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'utf-8', false);
    //$pdf->Footer('hello');
    // create new PDF document
    //$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    // set document information
    $pdf->SetCreator(PDF_CREATOR);
    //$pdf->SetAuthor('Nicola Asuni');
    //$pdf->SetTitle('TCPDF Example 001');
    //$pdf->SetSubject('<h1>TCPDF Tutorial</h1>');
    //$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
    // set default header data
    //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
    //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '<div style="float:right">haoooooooo</div>', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
    $pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
    // set header and footer fonts
    $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
    // set default monospaced font
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    // set margins
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(20);
    //echo PDF_MARGIN_FOOTER;exit;
    // set auto page breaks
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    // set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    // set some language-dependent strings (optional)
    if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
        require_once dirname(__FILE__) . '/lang/eng.php';
        $pdf->setLanguageArray($l);
    }
    // ---------------------------------------------------------
    // set default font subsetting mode
    $pdf->setFontSubsetting(true);
    // Set font
    // dejavusans is a UTF-8 Unicode font, if you only need to
    // print standard ASCII chars, you can use core fonts like
    // helvetica or times to reduce file size.
    //$pdf->SetFont('dejavusans', '', 10, '', true);
    $pdf->SetFont('Helvetica', '', 10, '', 'false');
    // Add a page
    // This method has several options, check the source code documentation for more information.
    $pdf->AddPage();
    // set text shadow effect
    $pdf->setTextShadow(array('enabled' => true, 'depth_w' => 1, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 0, 'blend_mode' => 'Normal'));
    // Set some content to print
    $tbl = '<br /><br/><br/><br/>	
<table border="0" cellpadding="2" cellspacing="2" nobr="true">
 
 <tr>
  <td style="width:60%"><b>Your Personal Travel Advisor:</b>' . @$results['pdfdata']['adviser_info']['name'] . '</td>
  <td style="width:40%"><b>Quote Reference:</b>' . @$results['pdfdata']['adviser_info']['reference'] . '</td>
 </tr>
 <tr>  
  <td style="width:60%"><b>Phone Number:</b>' . @$results['pdfdata']['adviser_info']['phone'] . '</td>
  <td style="width:40%"><b>Date:</b> ' . @$results['pdfdata']['adviser_info']['date'] . '</td> 
 </tr>
 <tr>
  <td style="width:60%"><b>Email Address:</b>' . @$results['pdfdata']['adviser_info']['email'] . '</td>
  <td style="width:40%"><b>Adults:</b> ' . @$results['seg'][0]['num_adults'] . ' <b>Children:</b> ' . @$results['seg'][0]['num_children'] . '</td>  
 </tr>
</table>';
    $pdf->writeHTML($tbl, true, false, false, false, '');
    //$ci = $results['controller'];
    $t = json_decode($results['row'][0]['adults_info'], true);
    $tbl = '
<div>
	<span>Dear ' . $t['fname'][0] . '</span>
	</br>
	<p>
		I have pleasure in enclosing a quote in respect of your recent enquiry with Super Escapes. Please feel free to contact us, should you need any more information or advice.
	</p>
</div>';
    $pdf->writeHTML($tbl, true, false, false, false, '');
    if (isset($results['fobj'])) {
        $depts = fetch_departures();
        $arrivs = fetch_arrivals();
        $dep_arr = explode('-', $depts[$results['fobj']['@attributes']['depapt']]);
        $arr_arr = explode('-', $arrivs[$results['fobj']['@attributes']['arrapt']]);
        $ret_arr = explode('-', $depts[$results['fobj']['@attributes']['retapt']]);
        $dept_start_time = substr(explode(' ', $results['fobj']['@attributes']['outdep'])[1], 0, -3);
        $dept_arr_time = substr(explode(' ', $results['fobj']['@attributes']['outarr'])[1], 0, -3);
        $return_start_time = substr(explode(' ', $results['fobj']['@attributes']['indep'])[1], 0, -3);
        $return_arr_time = substr(explode(' ', $results['fobj']['@attributes']['inarr'])[1], 0, -3);
        $tbl = '
<b><u>Flight Details : </u></b><br><br>  
<table border="0" cellpadding="2" cellspacing="2" nobr="true">
	<tr>
		<th style="width:35%;text-align:center;font-weight:bold;">Route</th>
		<td style="width:13%;text-align:center;font-weight:bold;">Dep Date</td>
		<td style="width:13%;text-align:center;font-weight:bold;">Dep Time</td>
		<td style="width:13%;text-align:center;font-weight:bold;">Arr Date</td>
		<td style="width:13%;text-align:center;font-weight:bold;">Arr Time</td>
		<td style="width:13%;text-align:center;font-weight:bold;">Flight No</td>
	</tr>
    <tr>
        <td >' . current($dep_arr) . ' Airport ' . array_pop($arr_arr) . ' Airport</td>
        <td>' . explode(' ', $results['fobj']['@attributes']['outdep'])[0] . '</td>
		<td>' . $dept_start_time . '</td>
		<td>' . explode(' ', $results['fobj']['@attributes']['outarr'])[0] . '</td>
		<td>' . $dept_arr_time . '</td>
		<td>' . $results['fobj']['@attributes']['outfltnum'] . '</td>
    </tr>
    <tr>
         <td >' . array_pop($arr_arr) . ' Airport ' . current($ret_arr) . ' Airport</td>
		<td>' . explode(' ', $results['fobj']['@attributes']['indep'])[0] . '</td>    	
		<td>' . $return_start_time . '</td>
		<td>' . explode(' ', $results['fobj']['@attributes']['inarr'])[0] . '</td>
		<td>' . $return_arr_time . '</td>
		<td>' . $results['fobj']['@attributes']['infltnum'] . '</td>
    </tr>  
</table>';
        $pdf->writeHTML($tbl, true, false, false, false, '');
    }
    $ci = $results['controller'];
    if (!empty($results['hobjs'])) {
        $tbl = '
<b><u>Accommodation Details: </u></b><br><br>  
<table border="0" cellpadding="2" cellspacing="2" nobr="true">
	<tr>
		<th style="text-align:center;font-weight:bold;">Hotel</th>
		<td style="text-align:center;font-weight:bold;">Resort</td>
		<td style="text-align:center;font-weight:bold;">Board</td>
		<td style="text-align:center;font-weight:bold;">Room</td>
		<td style="text-align:center;font-weight:bold;">Rating</td>		
	</tr>
    <tr>
        <td style="text-align:center;">' . urldecode($results['hobjs'][0]['@attributes']['hotelname']) . '</td>
        <td style="text-align:center;">' . urldecode($results['hobjs'][0]['@attributes']['resort']) . '</td>
		<td style="text-align:center;">' . boardbasis($results['hobjs'][0]['@attributes']['boardbasis']) . '</td>
		<td style="text-align:center;">' . $results['seg'][0]['num_rooms'] . ' ' . $results['hobjs'][0]['@attributes']['suppname'] . '</td>
		<td style="text-align:center;">' . (int) $results['hobjs'][0]['@attributes']['starrating'] . ' KEY</td>		
    </tr>
    <tr>
		<td style="text-align:center;font-weight:bold;">Check In</td>
    	<td style="text-align:center;font-weight:bold;">Check Out</td>
		<td style="text-align:center;font-weight:bold;">Adults</td>
		<td style="text-align:center;font-weight:bold;">Children</td>
		<td style="text-align:center;font-weight:bold;">Infants</td>
    </tr>
	<tr>
		<td style="text-align:center;">' . $results['hobjs'][0]['@attributes']['checkindate'] . '</td>
    	<td style="text-align:center;">' . date('d/m/Y', strtotime('+' . $results['hobjs'][0]['@attributes']['nights'] . " day", $ci->cvtDt(str_date($results['hobjs'][0]['@attributes']['checkindate'])))) . '</td>
		<td style="text-align:center;">' . @$results['seg'][0]['num_adults'] . '</td>
		<td style="text-align:center;">' . @$results['seg'][0]['num_children'] . '</td>
		<td style="text-align:center;"></td>
    </tr>	
</table>';
        $pdf->writeHTML($tbl, true, false, false, false, '');
    }
    $tbl = <<<EOD
<div style="margin-top:20px;">
\t<b><u>Price Summary:</u></p>\t
\t<p>
\t\tThe total price inclusive of any discounts for the holiday described above is: £653.92 To make a firm reservation please call us on 01386298033 and quote the reference number at the top of this quote. Our friendly and experienced travel consultants will be happy to book the above holiday or look for any alternatives that may suit your needs. 
\t</p>
\t<p>\t\t
\t\tMay we take this opportunity of thanking you for your enquiry, and we do hope that we are able to assist you in fulfilling your requirements.
\t</p>
</div>
EOD;
    $pdf->writeHTML($tbl, true, false, false, false, '');
    $tbl = <<<EOD
<div style="margin-top:20px;text-align:center;">\t
\t<small>
\t\t* All costings are subject to a final confirmation which will be given upon making a firm reservation *
\t</small>
</div><br/><br/>
EOD;
    $pdf->writeHTML($tbl, true, false, false, false, '');
    /*$tbl = '
    <div style="margin-top:20px;width:100%;display:inline-flex;">	
    	<div style="color:blue;text-align:center;width:60%">BookItNow Travel is a trading name of broadway Travel Services (Wimbledon) Ltd. Whose registered office is at Unit 1,Finway,Dallow Road,Luton,Beds LUI 1WE</div>
    	<div> <img src="'.base_url().'/images/abta.png"/></div>
    </div>';
    $pdf->writeHTML($tbl, true, false, false, false, '');*/
    //echo $tbl;exit;
    $tbl = '
<div style="margin-top:20px;">
	<span>Yours sincerely</span>
	<p>' . @$results['pdfdata']['adviser_info']['name'] . '</p>
</div>';
    $pdf->writeHTML($tbl, true, false, false, false, '');
    if (!empty($results['hobjs'])) {
        // $hotel_meta = new SimpleXMLElement(download_page('http://87.102.127.86:8005/search/websearch.exe?pageid=7&compid=1&brochurecode=BEWE-AMTSES1CO0'));
        $hotel_meta = new SimpleXMLElement(download_page('http://87.102.127.86:8005/search/websearch.exe?pageid=7&compid=1&brochurecode=' . $results['hobjs'][0]['@attributes']['brocode']));
        $i = 1;
        $desc = urldecode($hotel_meta->HotelDescription);
        $ty = new tidy();
        $desc = $ty->repairString($desc);
        $tbl = '<br /><br/><br/><br/><h2 style="text-align:center; "pagebreak="true">Accommodation Info</h2><table>';
        foreach ($hotel_meta->Images->Url as $img) {
            $tbl .= '<tr>';
            //Allow_url_fopen must be On
            if (is_array(@getimagesize(urldecode($img)))) {
                $tbl .= '<td colspan="1"  style="margin-right: 30px !important;"><img src="' . urldecode($img) . '" /></td>';
            } else {
                $tbl .= '<td colspan="3"><img src="' . base_url() . '/images/destination_placeholder.jpg"/></td>';
            }
            $tbl .= '<td colspan="1"></td>';
            if ($i == 1) {
                $tbl .= '<td rowspan="' . count($hotel_meta->Images->Url) . '" colspan="8">' . $desc . '</td>';
            }
            $tbl .= '</tr>';
            //$tbl .= '<style>.desc{background:red;}</style>';
            $i++;
        }
        $tbl .= '</table>';
        //echo $tbl;exit;
        $pdf->writeHTML($tbl, true, false, false, false, '');
    }
    // ---------------------------------------------------------
    // Close and output PDF document
    // This method has several options, check the source code documentation for more information.
    //$pdf->Output('D:\xampp\htdocs\test_plugins\tcpdf\examples\example_001.pdf', 'F');
    if ($type == 'email') {
        $pdf->Output(getcwd() . '/booking_files/' . $results['pdfdata']['adviser_info']['reference'] . '.pdf', 'F');
        if (file_exists(getcwd() . '/booking_files/' . $results['pdfdata']['adviser_info']['reference'] . '.pdf')) {
            $subject = 'Quick Quote Ref: ' . $results['pdfdata']['adviser_info']['reference'] . ' - Book it now';
            $body = 'Dear ' . $t['fname'][0];
            $body .= '<p></p>';
            $body .= '<p>Please find the attached document</p>';
            $body .= '<p></p>';
            $body .= '<p>Cheers</p>';
            $body .= '<p>BootItNow</p>';
            $from = '*****@*****.**';
            $sendername = "BookItNow Admin";
            $list = array($results['row'][0]['email']);
            $config['protocol'] = "smtp";
            $config['smtp_host'] = 'mail.expertwebworx.in';
            $config['smtp_port'] = '25';
            $config['smtp_user'] = '******';
            $config['smtp_pass'] = '******';
            $config['smtp_crypto'] = 'tls';
            $config['charset'] = "iso-8859-1";
            $config['mailtype'] = "html";
            $ci->load->library('email', $config);
            $ci->email->set_newline("\r\n");
            $ci->email->from($from, $sendername);
            $ci->email->to($list);
            $ci->email->reply_to($from, $sendername);
            $ci->email->subject($subject);
            $ci->email->attach(getcwd() . '/booking_files/' . $results['pdfdata']['adviser_info']['reference'] . '.pdf');
            $ci->email->message($body);
            if ($ci->email->send()) {
            }
        }
    } else {
        $pdf->Output($results['pdfdata']['adviser_info']['reference'] . '.pdf', 'D');
        exit;
    }
    //============================================================+
    // END OF FILE
    //============================================================+
}
Example #16
0
 /**
  * Remove malicious and redundant HTML code.
  *
  * @param string $data Data.
  * @return string
  */
 public static function cleanupHTML($data)
 {
     $aggressive = Primitive::getConfigValue('site.aggressive_cleanup', false);
     //Если подключено расширение tidy
     if (function_exists('tidy_get_output') && $aggressive) {
         try {
             $tidy = new \tidy();
             $config = ['bare' => true, 'drop-font-tags' => true, 'drop-proprietary-attributes' => true, 'hide-comments' => true, 'logical-emphasis' => true, 'numeric-entities' => true, 'show-body-only' => true, 'quote-nbsp' => false, 'indent' => 'auto', 'wrap' => 72, 'output-html' => true];
             //if ($aggressive) {
             $config = array_merge($config, ['word-2000' => true, 'drop-empty-paras' => true]);
             //}
             $data = $tidy->repairString($data, $config, 'utf8');
         } catch (\Exception $dummyError) {
             //inspect($dummyError);
         }
         unset($tidy);
     }
     $base = E()->getSiteManager()->getCurrentSite()->base;
     $data = str_replace(strpos($data, '%7E') ? str_replace('~', '%7E', $base) : $base, '', $data);
     return $data;
 }
Example #17
0
 static function getDOM($pageUrl)
 {
     $html = Curl::getPage($pageUrl);
     // Clean the ridiculously broken HTML
     $tidy = new tidy();
     $html = $tidy->repairString($html);
     $dom = new DOMDocument();
     $dom->preserveWhiteSpace = false;
     $dom->loadHTML($html);
     return $dom;
 }
Example #18
0
File: common.php Project: pcela/lms
function html2pdf($content, $subject = NULL, $title = NULL, $type = NULL, $id = NULL, $orientation = 'P', $margins = array(5, 10, 5, 10), $save = false, $copy = false)
{
    global $layout, $DB;
    require_once LIB_DIR . '/html2pdf/html2pdf.class.php';
    if (isset($margins)) {
        if (!is_array($margins)) {
            $margins = array(5, 10, 5, 10);
        }
    }
    /* default */
    $html2pdf = new HTML2PDF($orientation, 'A4', 'en', true, 'UTF-8', $margins);
    /* disable font subsetting to improve performance */
    $html2pdf->pdf->setFontSubsetting(false);
    if ($id) {
        $info = $DB->GetRow('SELECT di.name, di.description FROM divisions di
			LEFT JOIN documents d ON (d.divisionid = di.id)
			WHERE d.id = ?', array($id));
    }
    $html2pdf->pdf->SetProducer('LMS Developers');
    $html2pdf->pdf->SetCreator('LMS ' . $layout['lmsv']);
    if ($info) {
        $html2pdf->pdf->SetAuthor($info['name']);
    }
    if ($subject) {
        $html2pdf->pdf->SetSubject($subject);
    }
    if ($title) {
        $html2pdf->pdf->SetTitle($title);
    }
    $html2pdf->pdf->SetDisplayMode('fullpage', 'SinglePage', 'UseNone');
    $html2pdf->AddFont('arial', '', 'arial.php');
    $html2pdf->AddFont('arial', 'B', 'arialb.php');
    $html2pdf->AddFont('arial', 'I', 'ariali.php');
    $html2pdf->AddFont('arial', 'BI', 'arialbi.php');
    $html2pdf->AddFont('times', '', 'times.php');
    /* if tidy extension is loaded we repair html content */
    if (extension_loaded('tidy')) {
        $config = array('indent' => true, 'output-html' => true, 'indent-spaces' => 4, 'join-styles' => true, 'join-classes' => true, 'fix-bad-comments' => true, 'fix-backslash' => true, 'repeated-attributes' => 'keep-last', 'drop-proprietary-attribute' => true, 'sort-attributes' => 'alpha', 'hide-comments' => true, 'new-blocklevel-tags' => 'page, page_header, page_footer, barcode', 'wrap' => 200);
        $tidy = new tidy();
        $content = $tidy->repairString($content, $config, 'utf8');
    }
    $html2pdf->WriteHTML($content);
    if ($copy) {
        /* add watermark only for contract & annex */
        if ($type == DOC_CONTRACT || $type == DOC_ANNEX) {
            $html2pdf->AddFont('courier', '', 'courier.php');
            $html2pdf->AddFont('courier', 'B', 'courierb.php');
            $html2pdf->pdf->SetTextColor(255, 0, 0);
            $PageWidth = $html2pdf->pdf->getPageWidth();
            $PageHeight = $html2pdf->pdf->getPageHeight();
            $PageCount = $html2pdf->pdf->getNumPages();
            $txt = trim(preg_replace("/(.)/i", "\${1} ", trans('COPY')));
            $w = $html2pdf->pdf->getStringWidth($txt, 'courier', 'B', 120);
            $x = $PageWidth / 2 - $w / 2 * sin(45);
            $y = $PageHeight / 2 + 50;
            for ($i = 1; $i <= $PageCount; $i++) {
                $html2pdf->pdf->setPage($i);
                $html2pdf->pdf->SetAlpha(0.2);
                $html2pdf->pdf->SetFont('courier', 'B', 120);
                $html2pdf->pdf->StartTransform();
                $html2pdf->pdf->Rotate(45, $x, $y);
                $html2pdf->pdf->Text($x, $y, $txt);
                $html2pdf->pdf->StopTransform();
            }
            $html2pdf->pdf->SetAlpha(1);
        }
    }
    if ($type == DOC_CONTRACT || $type == DOC_ANNEX) {
        /* set signature additional information */
        $info = array('Name' => $info['name'], 'Location' => $subject, 'Reason' => $title, 'ContactInfo' => $info['description']);
        /* setup your cert & key file */
        $cert = 'file://' . LIB_DIR . '/tcpdf/config/lms.cert';
        $key = 'file://' . LIB_DIR . '/tcpdf/config/lms.key';
        /* set document digital signature & protection */
        if (file_exists($cert) && file_exists($key)) {
            $html2pdf->pdf->setSignature($cert, $key, 'lms-documents', '', 1, $info);
        }
    }
    $html2pdf->pdf->SetProtection(array('modify', 'annot-forms', 'fill-forms', 'extract', 'assemble'), '', PASSWORD_CHANGEME, '1');
    if ($save) {
        if (function_exists('mb_convert_encoding')) {
            $filename = mb_convert_encoding($title, "ISO-8859-2", "UTF-8");
        } else {
            $filename = iconv("UTF-8", "ISO-8859-2//TRANSLIT", $title);
        }
        $html2pdf->Output($filename . '.pdf', 'D');
    } else {
        $html2pdf->Output();
    }
}
Example #19
0
function markup(&$body, $track_cites = false)
{
    global $board, $config, $markup_urls;
    $modifiers = extract_modifiers($body);
    $body = preg_replace('@<tinyboard (?!escape )([\\w\\s]+)>(.+?)</tinyboard>@us', '', $body);
    $body = preg_replace('@<(tinyboard) escape ([\\w\\s]+)>@i', '<$1 $2>', $body);
    if (isset($modifiers['raw html']) && $modifiers['raw html'] == '1') {
        return array();
    }
    $body = str_replace("\r", '', $body);
    $body = utf8tohtml($body);
    if (mysql_version() < 50503) {
        $body = mb_encode_numericentity($body, array(0x10000, 0xffffff, 0, 0xffffff), 'UTF-8');
    }
    if ($config['markup_code']) {
        $code_markup = array();
        $body = preg_replace_callback($config['markup_code'], function ($matches) use(&$code_markup) {
            $d = count($code_markup);
            $code_markup[] = $matches;
            return "<code {$d}>";
        }, $body);
    }
    foreach ($config['markup'] as $markup) {
        if (is_string($markup[1])) {
            $body = preg_replace($markup[0], $markup[1], $body);
        } elseif (is_callable($markup[1])) {
            $body = preg_replace_callback($markup[0], $markup[1], $body);
        }
    }
    if ($config['markup_urls']) {
        $markup_urls = array();
        $body = preg_replace_callback('/((?:https?:\\/\\/|ftp:\\/\\/|irc:\\/\\/)[^\\s<>()"]+?(?:\\([^\\s<>()"]*?\\)[^\\s<>()"]*?)*)((?:\\s|<|>|"|\\.||\\]|!|\\?|,|&#44;|&quot;)*(?:[\\s<>()"]|$))/', 'markup_url', $body, -1, $num_links);
        if ($num_links > $config['max_links']) {
            error($config['error']['toomanylinks']);
        }
    }
    if ($config['markup_repair_tidy']) {
        $body = str_replace('  ', ' &nbsp;', $body);
    }
    if ($config['auto_unicode']) {
        $body = unicodify($body);
        if ($config['markup_urls']) {
            foreach ($markup_urls as &$url) {
                $body = str_replace(unicodify($url), $url, $body);
            }
        }
    }
    $tracked_cites = array();
    // Cites
    if (isset($board) && preg_match_all('/(^|\\s)&gt;&gt;(\\d+?)([\\s,.)?]|$)/m', $body, $cites, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
        if (count($cites[0]) > $config['max_cites']) {
            error($config['error']['toomanycites']);
        }
        $skip_chars = 0;
        $body_tmp = $body;
        $search_cites = array();
        foreach ($cites as $matches) {
            $search_cites[] = '`id` = ' . $matches[2][0];
        }
        $search_cites = array_unique($search_cites);
        $query = query(sprintf('SELECT `thread`, `id` FROM ``posts_%s`` WHERE ' . implode(' OR ', $search_cites), $board['uri'])) or error(db_error());
        $cited_posts = array();
        while ($cited = $query->fetch(PDO::FETCH_ASSOC)) {
            $cited_posts[$cited['id']] = $cited['thread'] ? $cited['thread'] : false;
        }
        foreach ($cites as $matches) {
            $cite = $matches[2][0];
            // preg_match_all is not multibyte-safe
            foreach ($matches as &$match) {
                $match[1] = mb_strlen(substr($body_tmp, 0, $match[1]));
            }
            if (isset($cited_posts[$cite])) {
                $replacement = '<a onclick="highlightReply(\'' . $cite . '\');" href="' . $config['root'] . $board['dir'] . $config['dir']['res'] . link_for(array('id' => $cite, 'thread' => $cited_posts[$cite])) . '#' . $cite . '">' . '&gt;&gt;' . $cite . '</a>';
                $body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[3][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0]));
                $skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[3][0]) - mb_strlen($matches[0][0]);
                if ($track_cites && $config['track_cites']) {
                    $tracked_cites[] = array($board['uri'], $cite);
                }
            }
        }
    }
    // Cross-board linking
    if (preg_match_all('/(^|\\s)&gt;&gt;&gt;\\/(' . $config['board_regex'] . 'f?)\\/(\\d+)?([\\s,.)?]|$)/um', $body, $cites, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
        if (count($cites[0]) > $config['max_cites']) {
            error($config['error']['toomanycross']);
        }
        $skip_chars = 0;
        $body_tmp = $body;
        if (isset($cited_posts)) {
            // Carry found posts from local board >>X links
            foreach ($cited_posts as $cite => $thread) {
                $cited_posts[$cite] = $config['root'] . $board['dir'] . $config['dir']['res'] . ($thread ? $thread : $cite) . '.html#' . $cite;
            }
            $cited_posts = array($board['uri'] => $cited_posts);
        } else {
            $cited_posts = array();
        }
        $crossboard_indexes = array();
        $search_cites_boards = array();
        foreach ($cites as $matches) {
            $_board = $matches[2][0];
            $cite = @$matches[3][0];
            if (!isset($search_cites_boards[$_board])) {
                $search_cites_boards[$_board] = array();
            }
            $search_cites_boards[$_board][] = $cite;
        }
        $tmp_board = $board['uri'];
        foreach ($search_cites_boards as $_board => $search_cites) {
            $clauses = array();
            foreach ($search_cites as $cite) {
                if (!$cite || isset($cited_posts[$_board][$cite])) {
                    continue;
                }
                $clauses[] = '`id` = ' . $cite;
            }
            $clauses = array_unique($clauses);
            if ($board['uri'] != $_board) {
                if (!openBoard($_board)) {
                    continue;
                }
                // Unknown board
            }
            if (!empty($clauses)) {
                $cited_posts[$_board] = array();
                $query = query(sprintf('SELECT `thread`, `id`, `slug` FROM ``posts_%s`` WHERE ' . implode(' OR ', $clauses), $board['uri'])) or error(db_error());
                while ($cite = $query->fetch(PDO::FETCH_ASSOC)) {
                    $cited_posts[$_board][$cite['id']] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($cite) . '#' . $cite['id'];
                }
            }
            $crossboard_indexes[$_board] = $config['root'] . $board['dir'] . $config['file_index'];
        }
        // Restore old board
        if ($board['uri'] != $tmp_board) {
            openBoard($tmp_board);
        }
        foreach ($cites as $matches) {
            $_board = $matches[2][0];
            $cite = @$matches[3][0];
            // preg_match_all is not multibyte-safe
            foreach ($matches as &$match) {
                $match[1] = mb_strlen(substr($body_tmp, 0, $match[1]));
            }
            if ($cite) {
                if (isset($cited_posts[$_board][$cite])) {
                    $link = $cited_posts[$_board][$cite];
                    $replacement = '<a ' . ($_board == $board['uri'] ? 'onclick="highlightReply(\'' . $cite . '\');" ' : '') . 'href="' . $link . '">' . '&gt;&gt;&gt;/' . $_board . '/' . $cite . '</a>';
                    $body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[4][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0]));
                    $skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[4][0]) - mb_strlen($matches[0][0]);
                    if ($track_cites && $config['track_cites']) {
                        $tracked_cites[] = array($_board, $cite);
                    }
                }
            } elseif (isset($crossboard_indexes[$_board])) {
                $replacement = '<a href="' . $crossboard_indexes[$_board] . '">' . '&gt;&gt;&gt;/' . $_board . '/' . '</a>';
                $body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[4][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0]));
                $skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[4][0]) - mb_strlen($matches[0][0]);
            }
        }
    }
    $tracked_cites = array_unique($tracked_cites, SORT_REGULAR);
    $body = preg_replace("/^\\s*&gt;.*\$/m", '<span class="quote">$0</span>', $body);
    if ($config['strip_superfluous_returns']) {
        $body = preg_replace('/\\s+$/', '', $body);
    }
    $body = preg_replace("/\n/", '<br/>', $body);
    // Fix code markup
    if ($config['markup_code']) {
        foreach ($code_markup as $id => $val) {
            $code = isset($val[2]) ? $val[2] : $val[1];
            $code_lang = isset($val[2]) ? $val[1] : "";
            $code = "<pre class='code lang-{$code_lang}'>" . str_replace(array("\n", "\t"), array("&#10;", "&#9;"), htmlspecialchars($code)) . "</pre>";
            $body = str_replace("<code {$id}>", $code, $body);
        }
    }
    if ($config['markup_repair_tidy']) {
        $tidy = new tidy();
        $body = str_replace("\t", '&#09;', $body);
        $body = $tidy->repairString($body, array('doctype' => 'omit', 'bare' => true, 'literal-attributes' => true, 'indent' => false, 'show-body-only' => true, 'wrap' => 0, 'output-bom' => false, 'output-html' => true, 'newline' => 'LF', 'quiet' => true), 'utf8');
        $body = str_replace("\n", '', $body);
    }
    // replace tabs with 8 spaces
    $body = str_replace("\t", '		', $body);
    return $tracked_cites;
}
Example #20
0
 function onPrepareContent(&$article, &$params)
 {
     if ($this->param('Developer_Mode') != 1) {
         if ($GLOBALS['option'] == 'com_myblog') {
             // We are using the com_myblog component.  Check to be sure we're on the index page.
             if (isset($_REQUEST['show'])) {
                 return;
             }
         } elseif (JRequest::getCmd('option') == 'com_fjrelated') {
             // FJ Related Articles
             if (!$_REQUEST['layout'] == 'blog' or $_REQUEST['id'] == $article->id) {
                 return;
             }
         } elseif (JRequest::getCmd('option') == 'com_content') {
             // We are using the com_content module.  Be sure that we're on the frontpage, or category blog, or section blog.
             $view = JRequest::getCmd('view');
             $layout = JRequest::getCmd('layout');
             if (!($view == 'frontpage' || $view == 'category' && $layout == 'blog' || $view == 'section' && $layout == 'blog')) {
                 return;
             }
         } else {
             // Whatever this is, it is unsupported.
             return;
         }
         // Be sure that this section/category/article is not one that the user wanted to exclude.
         if ($this->param('Enabled_Front_Page') == 0 and $view == 'frontpage') {
             return;
         }
         if (in_array($article->sectionid, explode(',', $this->param('Exclude_Section_Ids')))) {
             return;
         }
         if (in_array($article->catid, explode(',', $this->param('Exclude_Category_Ids')))) {
             return;
         }
         if (in_array($article->id, explode(',', $this->param('Exclude_Article_Ids')))) {
             return;
         }
     }
     // How many characters are we allowed?
     $GLOBALS['AutoReadMore_Count'] = isset($GLOBALS['AutoReadMore_Count']) ? $GLOBALS['AutoReadMore_Count'] + 1 : 1;
     $params = $GLOBALS['mainframe']->getParams();
     $num_leading_articles = $params->def('num_leading_articles', 0);
     if ($GLOBALS['AutoReadMore_Count'] <= $num_leading_articles) {
         // This is a leading (full-width) article.
         $max_chars = $this->param('Leading_Max_Chars');
     } else {
         // This is not a leading article.
         $max_chars = $this->param('Max_Chars');
     }
     if (!is_numeric($max_chars)) {
         $max_chars = 500;
     }
     // What text are we working with?
     if ($this->param('Ignore_Existing_Read_More') == 1) {
         // Use introtext and fulltext.
         $text = $article->introtext . $article->fulltext;
     } else {
         // Use introtext only.
         $text = $article->introtext;
         if ($text == '') {
             $text = $article->fulltext;
         }
     }
     // Are we working with any thumbnails?
     $thumbnails = '';
     if ($this->param('Thumbnails') >= 1) {
         // Extract all images from the article.
         preg_match_all('/<img [^>]*>/i', $article->introtext . $article->fulltext, $matches);
         $matches = $matches[0];
         // Loop through the thumbnails.
         for ($thumbnail = 0; $thumbnail < $this->param('Thumbnails'); $thumbnail++) {
             if (!isset($matches[$thumbnail])) {
                 break;
             }
             // Remove the image from $text
             $text = str_replace($matches[$thumbnail], '', $text);
             // See if we need to remove styling.
             if ($this->param('Thumbnails_Class') != '') {
                 // Remove style, class, width, border, and height attributes.
                 $matches[$thumbnail] = preg_replace('/(style|class|width|height|border) ?= ?[\'"][^\'"]*[\'"]/i', '', $matches[$thumbnail]);
                 // Add CSS.
                 $matches[$thumbnail] = preg_replace('@/?>$@', 'class="' . $this->param('Thumbnails_Class') . '" />', $matches[$thumbnail]);
             }
             // Make this thumbnail a link.
             $matches[$thumbnail] = "<a href='" . JRoute::_("index.php?option=com_content&id={$article->slug}") . "'>{$matches[$thumbnail]}</a>";
             // Add to the list of thumbnails.
             $thumbnails .= $matches[$thumbnail];
         }
     }
     if (strlen(strip_tags($text)) > $max_chars) {
         if ($this->param('Strip_Formatting') == 1) {
             // First, remove all new lines
             $text = preg_replace("/\r\n|\r|\n/", "", $text);
             // Next, replace <br /> tags with \n
             $text = preg_replace("/<BR[^>]*>/i", "\n", $text);
             // Replace <p> tags with \n\n
             $text = preg_replace("/<P[^>]*>/i", "\n\n", $text);
             // Strip all tags
             $text = strip_tags($text);
             // Truncate
             $text = substr($text, 0, $max_chars);
             // Pop off the last word in case it got cut in the middle
             $text = preg_replace("/[.,!?:;]? [^ ]*\$/", "", $text);
             // Add ... to the end of the article.
             $text = trim($text) . "...";
             // Replace \n with <br />
             $text = str_replace("\n", "<br />", $text);
         } else {
             // Truncate
             $text = substr($text, 0, $max_chars);
             // Pop off the last word in case it got cut in the middle
             $text = preg_replace("/[.,!?:;]? [^ ]*\$/", "", $text);
             // Pop off the last tag, if it got cut in the middle.
             $text = preg_replace('/<[^>]*$/', '', $text);
             // Add ... to the end of the article if the last character is a letter or a number.
             if (preg_match('/\\w/', substr($text, -1))) {
                 $text = trim($text) . "...";
             }
             // Use Tidy to repair any bad XHTML (unclosed tags etc)
             $tidy = new tidy();
             $text = $tidy->repairString($text, array('show-body-only' => true, 'output-xhtml' => true), 'utf8');
         }
         // Add a "read more" link.
         $article->readmore = true;
     }
     // If we have thumbnails, add it to $text.
     $text = $thumbnails . $text;
     // If Developer Mode is turned on, add some stuff.
     if ($this->param('Developer_Mode') == 1) {
         $text = '' . '<div style="height:150px;width:100%;overflow:auto;">' . '<b>Developer information:</b><br /><pre>' . 'Developers: uncomment the next line in the code to display $GLOBALS.  If you see this message and do not know what it means, you should turn Developer_Mode off in the Auto Read More configuration.' . htmlspecialchars(print_r($GLOBALS, 1)) . '</pre></div>' . $text;
     }
     // Set $article->text.
     $article->text = $text;
 }
Example #21
0
<?php

if (@(!$bare)) {
    ?>
<div class="footbar"><a href="http://validator.w3.org/check?uri=referer"><img src="images/html5.png" alt="Valid HTML 5.0" height="31" width="88" /></a><a href="http://jigsaw.w3.org/css-validator/check/referer"><img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" /></a></div>
<?php 
}
?>
</body>
</html>
<?php 
if (isset($use_ob)) {
    $html = ob_get_clean();
    $config = array('clean' => TRUE, 'indent' => TRUE, 'output-html' => TRUE, 'wrap' => 0, 'new-inline-tags' => 'li, option', 'indent-spaces' => 4, 'show-warnings' => TRUE, 'indent-cdata' => TRUE);
    $tidy = new tidy();
    $tidy->parseString($html, $config, 'utf8');
    $tidy->cleanRepair();
    echo $tidy;
    $clean = $tidy->repairString($html);
    echo $clean;
    //print_r($tidy->getConfig());
} else {
    echo $html;
}
 public function cleanHTML($content)
 {
     $tidy = new tidy();
     $output = $tidy->repairString($content, $this->config);
     // Clean leading/trailing whitespace
     return preg_replace('/(^\\s+)|(\\s+$)/', '', $output);
 }
	/**
	 * Fetches, loads and calls the parser
	 * 
	 * @param	string $zone	optional
	 * @param	string $type	optional
	 * @return	void
	 */
	public function load( $zone = null, $type = null )
	{
		if ($zone !== null && $type !== null) {
			$this->__init( $zone, $type );
		}
		
		$content = $this->__fetch( $this->url );
		
		// run tidy repair on returned html
		$tidy = new tidy();
		$content = $tidy->repairString( $content, array( 
			'wrap' => 0 
		) );
		
		$this->__dom = new DOMDocument();
		$this->__dom->preserveWhitespace = false;
		@$this->__dom->loadHTML( $content );
		
		$inputEncoding = $this->getInputEncoding();
		$inputEncoding = empty( $inputEncoding ) || strtolower( $inputEncoding ) === 'auto' ? $this->__dom->encoding : strtolower( $inputEncoding );
		
		$outputEncoding = $this->getOutputEncoding();
		
		if (! empty( $inputEncoding )) {
			$content = SASUA_Canteens_Utility::convertEncoding( $inputEncoding, $outputEncoding, $content );
		} else {
			trigger_error( 'Failed to detect website encoding, encoding conversion skipped', E_USER_NOTICE );
		}
		
		// load up xpath before calling parser
		$this->__xpath = new DOMXPath( $this->__dom );

		$this->__parse();
	} // load }}}
Example #24
0
 static function optimizedRepair($input)
 {
     $tidy = new \tidy();
     $buffer = $tidy->repairString($input, array('input-xml' => false, 'output-xml' => false, 'output-xhtml' => true, 'indent-spaces' => 1, 'tab-size' => 1, 'clean' => true, 'wrap' => 0), 'utf8');
     return $buffer;
 }
Example #25
0
 protected function cleaning($what_to_clean, $tidy_config = '')
 {
     $config = array('char-encoding' => 'utf8', 'output-xhtml' => true, 'doctype' => 'strict', 'indent' => true, 'indent-spaces' => 2, 'wrap' => 0);
     if ($tidy_config == '') {
         $tidy_config =& $config;
     }
     $tidy = new tidy();
     $out = $tidy->repairString($what_to_clean, $tidy_config, 'UTF8');
     unset($tidy);
     unset($tidy_config);
     $out = strstr($out, '<html xmlns="http://www.w3.org/1999/xhtml">');
     $out = '<?xml version="1.0" encoding="utf-8" standalone="no"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' . $out;
     return $out;
 }
Example #26
0
 public function cleanHTML($content)
 {
     $tidy = new tidy();
     $output = $tidy->repairString($content, $this->config);
     return $output;
 }
Example #27
0
<?php

header('Access-Control-Allow-Origin: *');
$xml = new DomDocument("1.0", "UTF-8");
$container = $xml->createElement("holder");
$xml->appendChild($container);
$html = file_get_contents('http://imgur.com/t/pizza');
$tidy = new tidy();
$html = $tidy->repairString($html);
$d = new DomDocument();
$d->loadHtml($html);
$p = new DomXPath($d);
$images = array();
foreach ($p->query('img') as $i) {
    $images[] = $i;
    $container->appendChild($xml->createTextNode($i));
}
foreach ($images as $i) {
    echo $out;
}
/*
for($i=1; $i<10;$i++){
	$hold = $xml->createElement("image");
	$src = $xml->createAttribute("src");
	$tsrc = $xml->createTextNode($images[$i]);

	$src->appendChild($tsrc);
	$hold->appendChild($src);
	$container->appendChild($hold);

}
Example #28
0
function markup(&$body, $track_cites = false, $op = false)
{
    global $board, $config, $markup_urls;
    $modifiers = extract_modifiers($body);
    $body = preg_replace('@<tinyboard (?!escape )([\\w\\s]+)>(.+?)</tinyboard>@us', '', $body);
    $body = preg_replace('@<(tinyboard) escape ([\\w\\s]+)>@i', '<$1 $2>', $body);
    if (isset($modifiers['raw html']) && $modifiers['raw html'] == '1') {
        return array();
    }
    $body = str_replace("\r", '', $body);
    $body = utf8tohtml($body);
    if (mysql_version() < 50503) {
        $body = mb_encode_numericentity($body, array(0x10000, 0xffffff, 0, 0xffffff), 'UTF-8');
    }
    foreach ($config['markup'] as $markup) {
        if (is_string($markup[1])) {
            $body = preg_replace($markup[0], $markup[1], $body);
        } elseif (is_callable($markup[1])) {
            $body = preg_replace_callback($markup[0], $markup[1], $body);
        }
    }
    if ($config['markup_urls']) {
        $markup_urls = array();
        $body = preg_replace_callback('/((?:https?:\\/\\/|ftp:\\/\\/|irc:\\/\\/)[^\\s<>()"]+?(?:\\([^\\s<>()"]*?\\)[^\\s<>()"]*?)*)((?:\\s|<|>|"|\\.||\\]|!|\\?|,|&#44;|&quot;)*(?:[\\s<>()"]|$))/', 'markup_url', $body, -1, $num_links);
        if ($num_links > $config['max_links']) {
            error($config['error']['toomanylinks']);
        }
        if ($num_links < $config['min_links'] && $op) {
            error(sprintf($config['error']['notenoughlinks'], $config['min_links']));
        }
    }
    if ($config['markup_repair_tidy']) {
        $body = str_replace('  ', ' &nbsp;', $body);
    }
    if ($config['auto_unicode']) {
        $body = unicodify($body);
        if ($config['markup_urls']) {
            foreach ($markup_urls as &$url) {
                $body = str_replace(unicodify($url), $url, $body);
            }
        }
    }
    $tracked_cites = array();
    // Cites
    if (isset($board) && preg_match_all('/(^|\\s)&gt;&gt;(\\d+?)([\\s,.)?]|$)/m', $body, $cites, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
        if (count($cites[0]) > $config['max_cites']) {
            error($config['error']['toomanycites']);
        }
        $skip_chars = 0;
        $body_tmp = $body;
        $search_cites = array();
        foreach ($cites as $matches) {
            $search_cites[] = '`id` = ' . $matches[2][0];
        }
        $search_cites = array_unique($search_cites);
        $query = query(sprintf('SELECT `thread`, `id` FROM ``posts_%s`` WHERE ' . implode(' OR ', $search_cites), $board['uri'])) or error(db_error());
        $cited_posts = array();
        while ($cited = $query->fetch(PDO::FETCH_ASSOC)) {
            $cited_posts[$cited['id']] = $cited['thread'] ? $cited['thread'] : false;
        }
        foreach ($cites as $matches) {
            $cite = $matches[2][0];
            // preg_match_all is not multibyte-safe
            foreach ($matches as &$match) {
                $match[1] = mb_strlen(substr($body_tmp, 0, $match[1]));
            }
            if (isset($cited_posts[$cite])) {
                $replacement = '<a onclick="highlightReply(\'' . $cite . '\', event);" href="' . $config['root'] . $board['dir'] . $config['dir']['res'] . ($cited_posts[$cite] ? $cited_posts[$cite] : $cite) . '.html#' . $cite . '">' . '&gt;&gt;' . $cite . '</a>';
                $body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[3][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0]));
                $skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[3][0]) - mb_strlen($matches[0][0]);
                if ($track_cites && $config['track_cites']) {
                    $tracked_cites[] = array($board['uri'], $cite);
                }
            }
        }
    }
    // Cross-board linking
    if (preg_match_all('/(^|\\s)&gt;&gt;&gt;\\/(' . $config['board_regex'] . 'f?)\\/(\\d+)?([\\s,.)?]|$)/um', $body, $cites, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
        if (count($cites[0]) > $config['max_cites']) {
            error($config['error']['toomanycross']);
        }
        $skip_chars = 0;
        $body_tmp = $body;
        if (isset($cited_posts)) {
            // Carry found posts from local board >>X links
            foreach ($cited_posts as $cite => $thread) {
                $cited_posts[$cite] = $config['root'] . $board['dir'] . $config['dir']['res'] . ($thread ? $thread : $cite) . '.html#' . $cite;
            }
            $cited_posts = array($board['uri'] => $cited_posts);
        } else {
            $cited_posts = array();
        }
        $crossboard_indexes = array();
        $search_cites_boards = array();
        foreach ($cites as $matches) {
            $_board = $matches[2][0];
            $cite = @$matches[3][0];
            if (!isset($search_cites_boards[$_board])) {
                $search_cites_boards[$_board] = array();
            }
            $search_cites_boards[$_board][] = $cite;
        }
        $tmp_board = $board['uri'];
        foreach ($search_cites_boards as $_board => $search_cites) {
            $clauses = array();
            foreach ($search_cites as $cite) {
                if (!$cite || isset($cited_posts[$_board][$cite])) {
                    continue;
                }
                $clauses[] = '`id` = ' . $cite;
            }
            $clauses = array_unique($clauses);
            if ($board['uri'] != $_board) {
                if (!openBoard($_board)) {
                    continue;
                }
                // Unknown board
            }
            if (!empty($clauses)) {
                $cited_posts[$_board] = array();
                $query = query(sprintf('SELECT `thread`, `id` FROM ``posts_%s`` WHERE ' . implode(' OR ', $clauses), $board['uri'])) or error(db_error());
                while ($cite = $query->fetch(PDO::FETCH_ASSOC)) {
                    $cited_posts[$_board][$cite['id']] = $config['root'] . $board['dir'] . $config['dir']['res'] . ($cite['thread'] ? $cite['thread'] : $cite['id']) . '.html#' . $cite['id'];
                }
            }
            $crossboard_indexes[$_board] = $config['root'] . $board['dir'] . $config['file_index'];
        }
        // Restore old board
        if (!$tmp_board) {
            unset($GLOBALS['board']);
        } elseif ($board['uri'] != $tmp_board) {
            openBoard($tmp_board);
        }
        foreach ($cites as $matches) {
            $_board = $matches[2][0];
            $cite = @$matches[3][0];
            // preg_match_all is not multibyte-safe
            foreach ($matches as &$match) {
                $match[1] = mb_strlen(substr($body_tmp, 0, $match[1]));
            }
            if ($cite) {
                if (isset($cited_posts[$_board][$cite])) {
                    $link = $cited_posts[$_board][$cite];
                    $replacement = '<a ' . ($_board == $board['uri'] ? 'onclick="highlightReply(\'' . $cite . '\', event);" ' : '') . 'href="' . $link . '">' . '&gt;&gt;&gt;/' . $_board . '/' . $cite . '</a>';
                    $body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[4][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0]));
                    $skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[4][0]) - mb_strlen($matches[0][0]);
                    if ($track_cites && $config['track_cites']) {
                        $tracked_cites[] = array($_board, $cite);
                    }
                }
            } elseif (isset($crossboard_indexes[$_board])) {
                $replacement = '<a href="' . $crossboard_indexes[$_board] . '">' . '&gt;&gt;&gt;/' . $_board . '/' . '</a>';
                $body = mb_substr_replace($body, $matches[1][0] . $replacement . $matches[4][0], $matches[0][1] + $skip_chars, mb_strlen($matches[0][0]));
                $skip_chars += mb_strlen($matches[1][0] . $replacement . $matches[4][0]) - mb_strlen($matches[0][0]);
            }
        }
    }
    $tracked_cites = array_unique($tracked_cites, SORT_REGULAR);
    if ($config['strip_superfluous_returns']) {
        $body = preg_replace('/\\s+$/', '', $body);
    }
    if ($config['markup_paragraphs']) {
        $paragraphs = explode("\n", $body);
        $bodyNew = "";
        $tagsOpen = false;
        // Matches <a>, <a href="" title="">, but not <img/> and returns a
        $matchOpen = "#<([A-Z][A-Z0-9]*)+(?:(?:\\s+\\w+(?:\\s*=\\s*(?:\".*?\"|'.*?'|[^'\">\\s]+))?)+\\s*|\\s*)>#i";
        // Matches </a> returns a
        $matchClose = "#</([A-Z][A-Z0-9]*/?)>#i";
        $tagsOpened = array();
        $tagsClosed = array();
        foreach ($paragraphs as $paragraph) {
            // Determine if RTL based on content of line.
            if (strlen(trim($paragraph)) > 0) {
                $paragraphDirection = is_rtl($paragraph) ? "rtl" : "ltr";
            } else {
                $paragraphDirection = "empty";
            }
            // Add in a quote class for >quotes.
            if (strpos($paragraph, "&gt;") === 0) {
                $quoteClass = "quote";
            } else {
                $quoteClass = "";
            }
            // If tags are closed, start a new line.
            if ($tagsOpen === false) {
                $bodyNew .= "<p class=\"body-line {$paragraphDirection} {$quoteClass}\">";
            }
            // If tags are open, add the paragraph to our temporary holder instead.
            if ($tagsOpen !== false) {
                $tagsOpen .= $paragraph;
                // Recheck tags to see if we've formed a complete tag with this latest line.
                if (preg_match_all($matchOpen, $tagsOpen, $tagsOpened) === preg_match_all($matchClose, $tagsOpen, $tagsClosed)) {
                    sort($tagsOpened[1]);
                    sort($tagsClosed[1]);
                    // Double-check to make sure these are the same tags.
                    if (count(array_diff_assoc($tagsOpened[1], $tagsClosed[1])) === 0) {
                        // Tags are closed! \o/
                        $bodyNew .= $tagsOpen;
                        $tagsOpen = false;
                    }
                }
            } else {
                if (preg_match_all($matchOpen, $paragraph, $tagsOpened) === preg_match_all($matchClose, $paragraph, $tagsClosed)) {
                    sort($tagsOpened[1]);
                    sort($tagsClosed[1]);
                    // Double-check to make sure these are the same tags.
                    if (count(array_diff_assoc($tagsOpened[1], $tagsClosed[1])) === 0) {
                        $bodyNew .= $paragraph;
                    }
                } else {
                    // Tags are open!
                    $tagsOpen = $paragraph;
                }
            }
            // If tags are open, do not close it.
            if (!$tagsOpen) {
                $bodyNew .= "</p>";
            } else {
                if ($tagsOpen !== false) {
                    $tagsOpen .= "<br />";
                }
            }
        }
        if ($tagsOpen !== false) {
            $bodyNew .= $tagsOpen;
        }
        $body = $bodyNew;
    } else {
        $body = preg_replace("/^\\s*&gt;.*\$/m", '<span class="quote">$0</span>', $body);
        $body = preg_replace("/\n/", '<br/>', $body);
    }
    if ($config['markup_repair_tidy']) {
        $tidy = new tidy();
        $body = str_replace("\t", '&#09;', $body);
        $body = $tidy->repairString($body, array('doctype' => 'omit', 'bare' => true, 'literal-attributes' => true, 'indent' => false, 'show-body-only' => true, 'wrap' => 0, 'output-bom' => false, 'output-html' => true, 'newline' => 'LF', 'quiet' => true), 'utf8');
        $body = str_replace("\n", '', $body);
    }
    // replace tabs with 8 spaces
    $body = str_replace("\t", '&#09;', $body);
    return $tracked_cites;
}
Example #29
0
/**
 * Корректная инициализация переданных параметров GET и POST переданных пользователем
 *
 * @param string $type Тип переданных данных (int, float, string, link, html, bool, money)
 * @param string $get_name Название данных в GET
 * @param ustring $post_name Название данных в POST
 * @param mixed $empty_val Значение по умолчанию
 * @param integer $maxlen Максимальная длинна данных
 * @param string $strip_tags Для $type = 'html'. Если TRUE, то все теги и спецсимволы, сюда и будем пехать их
 * @param string $value При обработке входящих данных в функции XAJAX необходима обработка чисто переменных
 *                            переводятся в сущности.
 * @see change_q_x()
 * @return mixed
 */
function __paramInit($type = 'int', $get_name = NULL, $post_name = NULL, $empty_val = NULL, $maxlen = NULL, $strip_tags = FALSE, $value = FALSE)
{
    //$value = FALSE;
    if ($get_name && isset($_GET[$get_name])) {
        if ($_GET[$get_name] !== '') {
            $value = $_GET[$get_name];
        }
    }
    if ($value === FALSE) {
        if ($post_name && isset($_POST[$post_name])) {
            if ($_POST[$post_name] !== '') {
                $value = $_POST[$post_name];
            }
        }
    }
    if ($value === FALSE) {
        return $empty_val;
    }
    if (intval($maxlen)) {
        $value = addslashes(substr(stripslashes($value), 0, intval($maxlen)));
    }
    switch ($type) {
        case 'striptrim':
            return stripslashes(trim($value));
        case 'page':
            $value = intvalPgSql($value);
            return $value <= 0 ? 1 : $value;
        case 'uinteger':
        case 'uint':
            return abs(intvalPgSql($value));
        case 'array_integer':
        case 'array_int':
            return array_map('intvalPgSql', $value);
        case 'integer':
        case 'int':
            return intvalPgSql($value);
        case 'String':
            //$value = stripslashes($value);
        //$value = stripslashes($value);
        case 'string':
            return change_q_x($value, TRUE);
        case 'string_no_slashes':
            return stripslashes(change_q_x($value, TRUE));
        case 'link':
            return change_q_x(strip_http($value), TRUE);
        case 'html':
            return $strip_tags ? change_q_x($value, FALSE, TRUE, "", false, false) : change_q_x($value, FALSE, TRUE, null, false, false);
        case 'htmltext':
            return change_q_x($value, TRUE, FALSE);
            // аналогичен 'htmltext', но оставляет теги ul, li, b, p, i
        // аналогичен 'htmltext', но оставляет теги ul, li, b, p, i
        case 'html_save_ul_li_b_p_i':
            return change_q_x($value, false, false, 'b|i|p|ul|li');
        case 'array':
            return $value;
        case 'bool':
            return !!$value;
        case 'float':
            setlocale(LC_ALL, 'en_US.UTF-8');
            return floatval($value);
        case 'money':
            setlocale(LC_ALL, 'en_US.UTF-8');
            return floatval(preg_replace('/\\s+/', '', str_replace(",", ".", $value)));
        case 'ckedit_nocut':
            $nocut = true;
        case 'ckeditor':
        case 'ckedit':
            //$value = stripslashes($value);
            $value = wysiwyg_video_replace($value, $wysiwyg_videos);
            if (hasPermissions('adm')) {
                $value = wysiwyg_image_replace($value, $wysiwyg_images);
            }
            $value = wysiwyg_code_replace($value, $wysiwyg_codes);
            $ph = md5(time()) . "_code";
            list($value, $url) = str_replace_mask('#((<a[^>]*>)(.*?)(<\\/a>))#mix', $value);
            foreach ($url as &$u) {
                $u = stripslashes($u);
                $u = cleanHref($u);
            }
            $value = preg_replace(array("~<cut\\s*?\\/>~mix", "~<\\/cut>~"), array("<cut>", ""), $value);
            // Заменяем каты
            if ($nocut) {
                // Удаляем каты
                $value = str_replace("<cut>", "", $value);
            }
            $value = str_replace(array("<br />", "<br/>", "<br>"), "___BR___", $value);
            // Заменяем переносы для сохранения следующая функция их сжирает
            // Обрабатываем отступы в теге <pre>
            $value = str_replace("\n", "__N__", $value);
            $value = preg_replace_callback('~<pre>(.*?)<\\/pre>~mix', 'rn2br', $value);
            $value = str_replace("__N__", "\n", $value);
            $value = strip_tags($value, '<a>,<strike>,<cut>,<pre>,<b>,<strong>,<em>,<u>,<i>,<p>,<ul>,<ol>,<li>,<s>,<h1>,<h2>,<h3>,<h4>,<h5>,<h6>');
            $value = change_q_x($value, FALSE, TRUE, 'strike|cut|pre|b|strong|em|u|i|p(\\s' . $ph . '_\\w*)?+|ul|ol|li|s|h[1-6]{1}', false, false);
            $value = str_replace("___BR___", "<br />", $value);
            // Возвращаем переносы
            $value = clearHTMLBeforeCutTags($value);
            $value = str_replace("<cut>", "<!-- -W-EDITOR-CUT- -->", $value);
            $value = hlcode($value);
            $tidy = new tidy();
            $value = $tidy->repairString($value, array('fix-backslash' => false, 'show-body-only' => true, 'bare' => true, 'clean' => false, 'drop-empty-paras' => false, 'preserve-entities' => true, 'wrap' => '0'), 'raw');
            $value = str_unreplace_mask($url, $value);
            $value = wysiwygLinkEncode($value);
            $value = wysiwygLinkDecode($value);
            $value = str_replace("<!-- -W-EDITOR-CUT- -->", "<cut>", $value);
            $value = str_replace("<p></p>", "<p>&nbsp;</p>", $value);
            $value = str_replace("\n", "", $value);
            /*
             * \h - горизонтальный пробельный символ. Для поддержки необходимо --PHP >= 5.2.4, PCRE >= 7.2 (на бете сейчас PCRE 6.6)
             */
            //$value = preg_replace("/[\p{Zs}]/", " ", $value);
            $value = wysiwyg_code_restore($value, $wysiwyg_codes);
            if (hasPermissions('adm')) {
                $value = wysiwyg_image_restore($value, $wysiwyg_images);
            }
            $value = wysiwyg_video_restore($value, $wysiwyg_videos);
            return $value;
            break;
        case 'wysiwyg':
        case 'wysiwyg_tidy':
        case 'wysiwyg_message':
            $value = wysiwyg_video_replace($value, $wysiwyg_videos);
            $value = wysiwyg_image_replace($value, $wysiwyg_images);
            $value = wysiwyg_code_replace($value, $wysiwyg_codes);
            $value = str_replace(array("\n", "\r"), "", $value);
            $value = preg_replace("[\r\n]", "", $value);
            $ph = md5(time()) . "_code";
            list($value, $url) = str_replace_mask('#((<a[^>]*>)(.*?)(<\\/a>))#mix', $value);
            foreach ($url as &$u) {
                $u = cleanHref($u);
            }
            //$value = preg_replace('/<p\sclass.*?code\s(\w*?).?"/si', "<p {$ph}_$1", $value);
            $value = change_q_x($value, FALSE, TRUE, 'a|strike|cut|b|strong|em|u|i|p(\\s' . $ph . '_\\w*)?+|ul|ol|li|s|h[1-6]{1}', false, false);
            $value = str_unreplace_mask($url, $value);
            $value = preg_replace("#<([^><]+?)([^a-z_\\-]on\\w*|xmlns)(\\s*=\\s*[^><]*)([><]*)#i", "<\\1\\4", $value);
            $value = preg_replace("/<br ?\\/?>/si", "\n", $value);
            $value = str_replace(array("<br />", "<br />", "&nbsp;"), array("\n", "\n", " "), $value);
            $value = clearHTMLBeforeCutTags($value);
            $value = wysiwygLinkEncode($value);
            $value = wysiwygLinkDecode($value);
            $value = preg_replace('/\\&amp;/', '&', $value);
            //$value = preg_replace('/<p\s[a-z0-9]{32}_code_(.*?)>/', '<p class="code $1">', $value);
            $value = preg_replace("/(li|ol|ul)>[\n]+/iU", "\$1>", $value);
            //$value = str_replace(array('  '), array('&nbsp;&nbsp;'), $value );
            $value = str_replace("<cut>", "<!-- -W-EDITOR-CUT- -->", $value);
            $value = str_replace("&lt;!-- -W-EDITOR-CUT- --&gt;", "<!-- -W-EDITOR-CUT- -->", $value);
            //        $value = preg_replace_callback("/<([^\s>]+)[^>](.*?)*>/si",
            //                create_function('$matches', 'return str_replace("&nbsp;", " ", $matches[0]);'),
            //            $value);
            if ($type == 'wysiwyg_message') {
                $value = preg_replace(array("/<p>/", "/<\\/p>/", "/\n+\\s*\$/"), array("", "\n\n", ""), $value);
                $value = str_replace("\n", "<br />", $value);
            } elseif ($type != 'wysiwyg_tidy') {
                $value = nl2br($value);
            }
            if ($type == 'wysiwyg_tidy') {
                //tidy
                $tidy = new tidy();
                $value = $tidy->repairString($value, array('fix-backslash' => false, 'show-body-only' => true, 'bare' => true, 'drop-empty-paras' => false, 'preserve-entities' => true, 'wrap' => '0'), 'raw');
                $value = str_replace("<p></p>", "<p>&nbsp;</p>", $value);
                $value = str_replace("\n", "", $value);
                $value = preg_replace("/\\p{Zs}/", " ", $value);
                //!tidy
            }
            $value = wysiwyg_code_restore($value, $wysiwyg_codes);
            $value = wysiwyg_image_restore($value, $wysiwyg_images);
            $value = wysiwyg_video_restore($value, $wysiwyg_videos);
            return $value;
    }
    return NULL;
}