code
stringlengths
1
2.01M
repo_name
stringlengths
3
62
path
stringlengths
1
267
language
stringclasses
231 values
license
stringclasses
13 values
size
int64
1
2.01M
<style> p { background: #93C0FF; border:3px solid #95C2FF; padding:0; margin:0; } label{ font-weight:bold; margin-top:5px; } </style> <fieldset> <legend>Error</legend> <label>Severity</label> <p><?=$severity;?></p> <label>Message</label> <p><?=$message;?></p> <label>Filename</label> <p><?=$filepath;?></p> <label>Line Number</label> <p><?=$line;?></p> </fieldset>
0683babd6e120333c4dae5bac951f5cc
trunk/application/errors/error_php.php
PHP
mit
406
<? $config =& get_config(); $base_url = isset($config['base_url']) ? $config['base_url'] == '' ? NULL : $config['base_url'] : NULL; ?> <!DOCTYPE html> <html lang="en"> <head> <title>Database Error!</title> <link rel="stylesheet" href="<?=$base_url;?>assets/css/error/bootstrap/bootstrap.min.css"/> <link rel="stylesheet" href="<?=$base_url;?>assets/css/error/bootstrap/bootstrap-theme.min.css"/> <link rel="stylesheet" href="<?=$base_url;?>assets/css/error/error_404.css"/> </head> <body> <div id="wrap"> <!-- Begin page content --> <div class="container"> <div class="page-header"> <h1><?=$heading;?></h1> </div> </div> <div class="container"> <div class="row"> <div class="alert alert-info"> <?if(!empty($message)):?><?=$message;?><?endif;?> </div> <a href="#" onClick="parent.history.back(); return false;" class="btn btn-success"><b>Go Back.</b></a> </div> </div> </div> <div id="footer" class="shadow"> <div class="container"> <p class="text-muted credit">Copy &copy; GoCloudAsia 2013</p> </div> </div> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/application/errors/error_db.php
PHP
mit
1,154
<? $config =& get_config(); $base_url = isset($config['base_url']) ? $config['base_url'] == '' ? NULL : $config['base_url'] : NULL; ?> <!DOCTYPE html> <html lang="en"> <head> <title>Whooah! :(</title> <link rel="stylesheet" href="<?=$base_url;?>assets/css/error/bootstrap/bootstrap.min.css"/> <link rel="stylesheet" href="<?=$base_url;?>assets/css/error/bootstrap/bootstrap-theme.min.css"/> <link rel="stylesheet" href="<?=$base_url;?>assets/css/error/error_404.css"/> </head> <body> <div id="wrap"> <!-- Begin page content --> <div class="container"> <div class="page-header"> <h1><?=$heading;?></h1> </div> <p class="lead">You have attempted to access a non existent page.</p> </div> <div class="container"> <div class="row"> <div class="alert alert-info"> <?if(!empty($message)):?> <?=$message;?> <?endif;?> </div> <a href="#" onClick="parent.history.back(); return false;" class="btn btn-success"><b>Go Back.</b></a> </div> </div> </div> <div id="footer" class="shadow"> <div class="container"> <p class="text-muted credit">Copy &copy; GoCloudAsia 2013</p> </div> </div> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/application/errors/error_404.php
PHP
mit
1,240
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/application/index.html
HTML
mit
114
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/application/language/english/index.html
HTML
mit
114
<?php $lang['alpha_dash_space'] = "Invalid Characters Found."; $lang['alpha_space'] = "Must Contain Only Alphabetic Characters and space."; $lang['text_all'] = "Invalid Characters Found"; $lang['alphanum_space'] = "Invalid Characters Found"; $lang['enumeration'] = "Only alphanumeric,space and comma is allowed"; $lang['check_student_nationality'] = "Please fill up the fields below for foreign students";
0683babd6e120333c4dae5bac951f5cc
trunk/application/language/english/MY_form_validation_lang.php
PHP
mit
407
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/application/helpers/index.html
HTML
mit
114
<?php function all_fees($data) { if(!empty($data)) { foreach($data as $key => $value){ $all_fees[$value->fee_id]['name'] = $value->fee_name; $all_fees[$value->fee_id]['rate'] = $value->fee_rate; $all_fees[$value->fee_id]['desc'] = $value->fee_desc; $all_fees[$value->fee_id]['id'] = $value->fee_id; } return $all_fees; }else{ return FALSE; } } function selected_fees($data) { if(!empty($data)) { foreach($data as $key => $value){ $selected_fees[$value->fee_id]['name'] = $value->fee_name; $selected_fees[$value->fee_id]['rate'] = $value->fee_rate; $selected_fees[$value->fee_id]['desc'] = $value->fee_desc; $selected_fees[$value->fee_id]['id'] = $value->fee_id; } return $selected_fees; }else{ return FALSE; } } function available_fees($all_fees,$selected_fees) { if(!empty($selected_fees)) { foreach($all_fees as $key => $value){ $allfees[$value['id']]['rate'] = $value['rate']; $allfees[$value['id']]['desc'] = $value['desc']; $allfees[$value['id']]['name'] = $value['name']; $allfees[$value['id']]['id'] = $value['id']; } foreach($selected_fees as $key => $value) { $selfees[$value['id']]['rate'] = $value['rate']; $selfees[$value['id']]['desc'] = $value['desc']; $selfees[$value['id']]['name'] = $value['name']; $selfees[$value['id']]['id'] = $value['id']; } foreach($all_fees as $key => $value){ if(!array_key_exists($key,$selfees)){ $data[] = $value; } } return $data; }else { return $all_fees; } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/helpers/foreach_helper.php
PHP
mit
1,519
<?php function money($data) { if(is_float($data)) { if(preg_match('/^\d+\.\d+$/',$data) == TRUE){ return $data; }else{ return $data.'.00'; } }else{ return $data.'.00'; } } function random_user_id() { $CI =& get_instance(); $idNo = $CI->current_ay->sy_to.'-'.rand(1000,9999).'-'.substr(uniqid(md5(rand(10000,99999))),0,4); $query = $CI->db->query('SELECT username FROM users where username = ?',array($idNo)); if($query->num_rows() >= 1) { random_user_id(); }else{ return $idNo; } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/helpers/misc_helper.php
PHP
mit
517
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); if ( ! function_exists('style_url')) { function style_url($uri = '') { $CI =& get_instance(); return $CI->config->base_url('assets/css/'.$uri.'.css'); } } if ( ! function_exists('script_url')) { function script_url($uri = '') { $CI =& get_instance(); return $CI->config->base_url('assets/js/'.$uri.'.js'); } } if ( ! function_exists('image_url')) { function image_url($image_name = '') { $CI =& get_instance(); return $CI->config->base_url('assets/img/'.$image_name); } } if ( ! function_exists('array_url')) { function array_url($route = '') { if(is_array($route)) { $data = implode('/',$route); }else{ $data = $route; } $CI =& get_instance(); return $data; } } /* * autmatic link for student portal */ if ( ! function_exists('student_portal_link')) { function student_portal_link() { $CI =& get_instance(); $url = $CI->config->item('student_url'); return $url; } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/helpers/MY_url_helper.php
PHP
mit
1,074
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/application/hooks/index.html
HTML
mit
114
<?php class m_new_enrollee Extends MY_Model { private $last_insert_id; private $CI; private $__table = 'enrollments'; private $__seftable = 'student_enrollment_fees'; public function __construct() { parent::__construct(); $this->CI =& get_instance(); $this->CI->load->model('m_level_fees','mlfees'); } /* Insert new enrollee to enrollments table with verify time and code for verification */ public function enroll_new_student($data) { $sy = $this->c_sy; unset($data['password']); $data['e_sy_from'] = $sy->sy_from; $data['e_sy_to'] = $sy->sy_to; $data['e_ay_id'] = $sy->id; $data['e_created_at'] = NOW; $this->db->insert($this->__table,$data); $this->last_insert_id = $this->db->insert_id(); return $this->db->affected_rows() > 0 ? TRUE : FALSE; } public function update_enrolle($data,$e_id) { $data['e_updated_at'] = NOW; $this->db->where('e_id', $e_id); $this->db->update('enrollments', $data); return $this->db->affected_rows() > 0 ? TRUE : FALSE; } /******************* get applicant ********************/ public function get_applicant($e_id) { $sql = "SELECT e.e_grade_level, e.guidance_recommend_level_id, e.e_ay_id, e.e_profile_id, p.firstname, p.middlename, p.lastname, p.name_ext, p.dob, p.contact_no, p.previous_school FROM enrollments e LEFT JOIN profiles p ON e.e_profile_id = p.profile_id LEFT JOIN levels l ON e.e_grade_level = l.level_id WHERE e.e_id = ?"; $query = $this->db->query($sql,array($e_id)); return $query->num_rows() >= 1 ? $query->row() : FALSE; } /* Get all other fees assigned for a grade level then insert to student enrollment fees this is important so that if a fee is changed, the student will not be affected because they have their own record of the previous fees assigned to them */ public function get_fees_set_for_current_level($level_id,$enroll_id,$gperiod,$sy,$e_stat) { //get all selected fees assigned for grade level //$data = $this->CI->mlfees->get_sel_fees($level_id); //if(!empty($data)) //{ //$count = 0; //foreach($data as $fees) //{ //$s_e_fees[$count]['sef_enrollment_id'] = $enroll_id; //$s_e_fees[$count]['sef_fee_name'] = $fees->fee_name; //$s_e_fees[$count]['sef_fee_rate'] = $fees->fee_rate; //$s_e_fees[$count]['sef_gperiod_id'] = $gperiod; //$s_e_fees[$count]['sef_schoolyear_id'] = $sy; //$s_e_fees[$count]['sef_created'] = NOW; //$s_e_fees[$count]['is_tuition_fee'] = $fees->is_tuition_fee; // $s_e_fees[$count]['is_cca_fee'] = $fees->is_cca_fee; // $s_e_fees[$count]['is_misc_fee'] = $fees->is_misc_fee; // $count++; //} // $this->db->insert_batch($this->__seftable,$s_e_fees); // if($this->db->affected_rows() >= 1) // { //set tuition fee and misc fee for the current level if($this->set_tuition_fees_set_for_current_level($level_id,$enroll_id,$gperiod,$sy,$e_stat) == TRUE) { $this->_check_enrollee_nationality($level_id,$enroll_id); return TRUE; }else{ log_message('error','unable to set fees for current level id '.$enroll_id); return FALSE; } // } // } //else //{ //return TRUE; //} } private function _check_enrollee_nationality($lid,$eid) { // get enrolee nationality $q = $this->db->select('nationality') ->join('enrollments e','e.e_profile_id = p.profile_id') ->where('e_id',$eid) ->limit(1) ->get('profiles p'); if($q->num_rows() >=1 ) { $nat= $q->row()->nationality; //if nationality is filipino no foreign fee applied if(strtolower($nat) == 'filipino') { return TRUE; }else{ //get and insert foreign fees $ff = 'INSERT INTO student_enrollment_fees (sef_enrollment_id, sef_fee_name, sef_fee_rate, sef_gperiod_id, sef_schoolyear_id, is_other_fee ) SELECT ?,ff.fee_name,ff.fee_rate,?,?,1 FROM foreign_fee ff WHERE ff.level_id = ?'; $this->db->query($ff,array($eid,$this->c_gp->gp_id,$this->c_sy->id,$lid)); return TRUE; } }else{ return TRUE; } } /* function that inserts tuition to enrollee */ public function set_tuition_fees_set_for_current_level($level_id,$enroll_id,$gperiod,$sy,$e_stat) { /* Selects all tuition fee that is active. */ $sql = "SELECT f.fee_name,f.fee_rate FROM fees f WHERE f.is_tuition_fee = 1 AND f.grade_level = ? AND f.fee_stat = 'active' "; if($e_stat=='old') { $sql .= " AND f.fee_old = 'yes'"; }else{ $sql .= " AND f.fee_new = 'yes'"; } $query = $this->db->query($sql,array($level_id,)); $data = $query->num_rows() >= 1 ? $query->result() : FALSE; //format tuition fees for entry if(!empty($data)) { $count = 0; foreach($data as $fees) { $s_e_fees[$count]['sef_enrollment_id'] =$enroll_id; $s_e_fees[$count]['sef_fee_name'] = $fees->fee_name; $s_e_fees[$count]['sef_fee_rate'] = $fees->fee_rate; $s_e_fees[$count]['sef_gperiod_id'] = $gperiod; $s_e_fees[$count]['sef_schoolyear_id'] = $sy; $s_e_fees[$count]['sef_created'] = NOW; $s_e_fees[$count]['is_tuition_fee'] = 1; $count++; } //insert tuition fees $this->db->insert_batch($this->__seftable,$s_e_fees); /* if successfully inserted tuition fee call method insert_miscellaneous_fee() this method will insert misc fee for the student */ if($this->db->affected_rows() >= 1 ) { //call method to insert misc fee if($this->_insert_miscellaneous_fee($enroll_id,$sy,$level_id,$e_stat) == TRUE) { return TRUE; }else{ log_message('error','Unable to insert Miscellaneous fees. ID'.$enroll_id); return TRUE; } }else{ log_message('error','Unable to insert Tuition fees. ID'.$enroll_id); return TRUE; } }else{ log_message('error','No data for Tuition fees yet. ID'.$enroll_id); return TRUE; } } /* Inserts misc fees to students, called after inserting the tuition fee, at method set_tuition_fees_set_for_current_level(); */ private function _insert_miscellaneous_fee($enroll_id,$sy,$level_id,$e_stat) { $sql = "SELECT f.fee_name,f.fee_rate FROM fees f WHERE f.is_misc_fee = 1 AND f.grade_level = ? AND f.fee_stat = 'active' "; if($e_stat=='old') { $sql .= " AND f.fee_old = 'yes'"; }else{ $sql .= " AND f.fee_new = 'yes'"; } $query = $this->db->query($sql,array($level_id,)); $data = $query->num_rows() >= 1 ? $query->result() : FALSE; if(!empty($data)) { $count = 0; foreach($data as $fees){ $s_e_fees[$count]['sef_enrollment_id'] =$enroll_id; $s_e_fees[$count]['sef_fee_name'] = $fees->fee_name; $s_e_fees[$count]['sef_fee_rate'] = $fees->fee_rate; $s_e_fees[$count]['sef_schoolyear_id'] = $sy; $s_e_fees[$count]['sef_created'] = NOW; $s_e_fees[$count]['is_misc_fee'] = 1; $count++; } //insert tuition fees $this->db->insert_batch($this->__seftable,$s_e_fees); if($this->db->affected_rows() >= 1) { //call method to insert misc fee if($this->_insert_matriculation_fee($enroll_id,$sy,$level_id,$e_stat) == TRUE) { return TRUE; }else{ log_message('error','Unable to insert Matriculation fees. ID'.$enroll_id); return TRUE; } }else{ log_message('error','Unable to insert Miscellaneous fees. ID'.$enroll_id); return TRUE; } }else{ log_message('error','No data Miscellaneous fees yet. ID'.$enroll_id); return TRUE; } } /* Inserts matriculation fees to students, called after inserting the miscellaneous fee, at method set_tuition_fees_set_for_current_level(); */ private function _insert_matriculation_fee($id,$sy,$level_id,$e_stat) { $sql = "SELECT f.fee_name,f.fee_rate FROM fees f WHERE f.is_cca_fee = 1 AND f.grade_level = ? AND f.fee_stat = 'active' "; if($e_stat=='old') { $sql .= " AND f.fee_old = 'yes'"; }else{ $sql .= " AND f.fee_new = 'yes'"; } $query = $this->db->query($sql,array($level_id,)); $data = $query->num_rows() >= 1 ? $query->result() : FALSE; if(!empty($data)) { $count = 0; foreach($data as $fees){ $s_e_fees[$count]['sef_enrollment_id'] =$id; $s_e_fees[$count]['sef_fee_name'] = $fees->fee_name; $s_e_fees[$count]['sef_fee_rate'] = $fees->fee_rate; $s_e_fees[$count]['sef_schoolyear_id'] = $sy; $s_e_fees[$count]['sef_created'] = NOW; $s_e_fees[$count]['is_cca_fee'] = 1; $count++; } //insert tuition fees $this->db->insert_batch($this->__seftable,$s_e_fees); if($this->db->affected_rows() >= 1) { return TRUE; }else{ log_message('error','Unable to insert Matriculation fees. ID'.$enroll_id); return TRUE; } }else{ log_message('error','No data Matriculation fees yet. ID'.$enroll_id); return TRUE; } } public function get_fees_set_for_foreign($level_id,$enroll_id,$gperiod,$sy,$e_stat) { /* Select foreign fee. */ $sql = "SELECT fee_name,fee_rate FROM foreign_fee WHERE level_id = ? "; $query = $this->db->query($sql,array($level_id,)); $data = $query->num_rows() >= 1 ? $query->result() : FALSE; //format foreign fee for entry if(!empty($data)) { $count = 0; foreach($data as $fees) { $s_e_fees[$count]['sef_enrollment_id'] =$enroll_id; $s_e_fees[$count]['sef_fee_name'] = $fees->fee_name; $s_e_fees[$count]['sef_fee_rate'] = $fees->fee_rate; $s_e_fees[$count]['sef_gperiod_id'] = $gperiod; $s_e_fees[$count]['sef_schoolyear_id'] = $sy; $s_e_fees[$count]['sef_created'] = NOW; $s_e_fees[$count]['is_other_fee'] = 1; $count++; } //insert foreign fees $this->db->insert_batch($this->__seftable,$s_e_fees); /* if successfully inserted foreign fee return true else false */ if($this->db->affected_rows() >= 1 ) { return TRUE; }else{ log_message('error','Unable to insert Foreign fees. ID'.$enroll_id); return TRUE; } }else{ log_message('error','No data for Foreign fee yet. ID'.$enroll_id); return TRUE; } } public function get_set_foreign_fee($enroll_id,$gperiod,$sy) { /* Select foreign fee. */ $sql = "SELECT fee_name,fee_rate FROM foreign_fee "; $query = $this->db->query($sql); $data = $query->num_rows() >= 1 ? $query->result() : FALSE; //format foreign fee for entry if(!empty($data)) { $count = 0; foreach($data as $fees) { $s_e_fees[$count]['sef_enrollment_id'] =$enroll_id; $s_e_fees[$count]['sef_fee_name'] = $fees->fee_name; $s_e_fees[$count]['sef_fee_rate'] = $fees->fee_rate; $s_e_fees[$count]['sef_gperiod_id'] = $gperiod; $s_e_fees[$count]['sef_schoolyear_id'] = $sy; $s_e_fees[$count]['sef_created'] = NOW; $s_e_fees[$count]['is_other_fee'] = 1; $count++; } //insert foreign fees $this->db->insert_batch($this->__seftable,$s_e_fees); /* if successfully inserted foreign fee return true else false */ if($this->db->affected_rows() >= 1 ) { return TRUE; }else{ log_message('error','Unable to insert Foreign fees. ID'.$enroll_id); return TRUE; } }else{ log_message('error','No data for Foreign fee yet. ID'.$enroll_id); return TRUE; } } public function add_further_profile_value($data,$id,$type='') { if($type == 'dev') { $input['dhc_pregnancy_length'] = $data['length_of_preg']; $input['dhc_delivery_form'] = $data['form_of_del']; $input['dhc_compications'] = $data['complications']; $input['dhc_sleep_time'] = $data['go_to_bed']; $input['dhc_wakup_time'] = $data['get_up_bed']; // $data['dhc_sleeping_disturbance'] = $data['sleeping_dist']; $input['dhc_sleeping_disturbance_what'] = $data['sleeping_dist']; $input['dhc_child_own_room'] = $data['own_room']; $input['dhc_room_shares_who'] = $data['room_shares']; $input['dhc_child_wet_bed'] = $data['wet_bed']; // $data['dhc_defect_growth'] = $data['observable_difficulties']; $input['dhc_defect_specify'] = $data['observable_difficulties']; $input['dhc_defect_when'] = $data['observable_difficulties_since_when']; $input['dhc_defect_actions'] = $data['observable_difficulties_action_taken']; // $data['dhc_speech_problems'] = $data['speech_problems']; $input['dhc_speech_problem_what'] = $data['speech_problems']; $input['dhc_speech_problem_when'] = $data['speech_problems_since_when']; $input['dhc_speech_problem_actions'] = $data['speech_problems_actions_taken']; $input['dhc_hearing_last_check'] = $data['hearing_last_checked']; // $data['dhc_hearing_problems'] = $data['hearing_problems']; $input['dhc_hearing_problems_what'] = $data['hearing_problems']; $input['dhc_hearing_problems_when'] = $data['hearing_problems_since_when']; $input['dhc_hearing_problem_actions'] = $data['hearing_problems_actions_taken']; $input['dhc_vision_checked'] = $data['vision_last_checked']; // $data['dhc_sight_problem'] = $data['vision_specify']; $input['dhc_sight_problems_what'] = $data['vision_specify']; $input['dhc_hinder_learning_process'] = $data['hinder_childs_learning']; // $data['ce_trauma_exp'] = $data['']; $input['ce_trauma_exp_what'] = $data['traumatic_experiences']; $input['ce_trauma_exp_age'] = $data['age_trauma']; $input['ce_trauma_exp_reaction'] = $data['trauma_reaction']; $input['ce_trauma_exp_affected'] = $data['how_trauma_affected_child']; // $data['ce_special_fears'] = $data['special_fears']; $input['ce_special_fears_what'] = $data['special_fears']; $input['ce_special_fears_when'] = $data['when_what_triggered_fear']; $input['ce_special_fears_handle'] = $data['how_do_you_handle']; } elseif($type == 'hlth') { $input['hhc_allergies_reaction'] = $data['allergies_reaction']; $input['hhc_alergic_med_reaction'] = $data['drug_allergies_reaction']; $input['dhc_sight_problems_what'] = $data['eye_problem_spec']; $input['dhc_hearing_problems_what'] = $data['ear_problem_spec']; $input['hhc_diagnosed_specify'] = $data['major_ailment']; $input['hhc_recently_hospitalized'] = $data['recently_hospitalized']; $input['hhc_major_injury_specify'] = $data['major_injury']; $input['hhc_medication_school_hours'] = $data['medication_child_taking_spec']; $input['hhc_asthma_inhaler'] = isset($data['asthma_inhaler']) ? $data['asthma_inhaler'] : 'no'; $input['hhc_asthma'] = isset($data['asthma']) ? $data['asthma'] : 'no'; }elseif($type == 'pli'){ $input['fathername'] = $data['father_name']; $input['father_mname'] = $data['father_mname']; $input['father_lname'] = $data['father_lname']; $input['father_nationality'] = $data['father_citizenship']; $input['father_visa'] = $data['father_visa']; $input['father_occupation'] =$data['father_occup']; $input['father_office_num'] =$data['father_office_tel']; $input['father_contact_no'] =$data['father_contact_no']; $input['father_contact_no_text'] = !isset($data['father_contact_no_text']) ? 'no' : 'yes'; $input['mothername'] =$data['mother_name']; $input['mother_mname'] =$data['mother_mname']; $input['mother_lname'] =$data['mother_lname']; $input['mother_nationality'] =$data['mother_citizenship']; $input['mother_visa'] =$data['mother_visa']; $input['mother_occupation'] =$data['mother_occup']; $input['mother_office_num'] =$data['mother_office_tel']; $input['mother_contact_no'] =$data['mother_contact_no']; $input['mother_contact_no_text'] = !isset($data['mother_contact_no_text']) ? 'no' : 'yes'; $input['step_father_name'] =$data['step_father_name']; $input['step_father_mname'] = $data['step_father_mname']; $input['step_father_lname'] = $data['step_father_lname']; $input['step_father_citizenship'] =$data['step_father_citizenship']; $input['step_father_visa'] =$data['step_father_visa']; $input['step_father_occup'] =$data['step_father_occup']; $input['step_father_office_tel'] =$data['step_father_office_tel']; $input['step_father_contact_no'] =$data['step_father_contact_no']; $input['step_father_contact_no_text'] = !isset($data['step_father_contact_no_text']) ? 'no' : 'yes'; $input['step_mother_name'] =$data['step_mother_name']; $input['step_mother_mname'] = $data['step_mother_mname']; $input['step_mother_lname'] = $data['step_mother_lname']; $input['step_mother_citizenship'] =$data['step_mother_citizenship']; $input['step_mother_visa'] =$data['step_mother_visa']; $input['step_mother_occup'] =$data['step_mother_occup']; $input['step_mother_office_tel'] =$data['step_mother_office_tel']; $input['step_mother_contact_no'] =$data['step_mother_contact_no']; $input['step_mother_contact_no_text'] = !isset($data['step_mother_contact_no_text']) ? 'no' : 'yes'; /* $input['guardian_name'] =$data['guardian_name']; $input['guardian_mname'] =$data['guardian_mname']; $input['guardian_lname'] =$data['guardian_lname']; $input['guardian_citizenship'] =$data['guardian_citizenship']; $input['guardian_visa'] =$data['guardian_visa']; $input['guardian_occup'] =$data['guardian_occup']; $input['guardian_office_tel'] =$data['guardian_office_tel']; $input['guardian_contact_no'] =$data['guardian_contact_no']; $input['guardian_contact_no_text'] = !isset($data['guardian_contact_no_text']) ? 'no' : 'yes'; $input['emergency_name'] =$data['emergency_name']; $input['emergency_address'] =$data['emergency_address']; $input['emergency_office_tel'] =$data['emergency_office_tel']; $input['emergency_home_tel'] =$data['emergency_home_tel']; $input['emergency_home_no'] =$data['emergency_home_no']; */ $input['failure_to_provide'] = !isset($data['failure_to_provide']) ? 'no' : 'yes'; $input['to_the_best'] = !isset($data['to_the_best']) ? 'no' : 'yes'; }elseif($type == 'auth'){ $input['auth_firstaid'] = $data['authfirst_aid']; $input['auth_emergency_care'] = $data['auth_emergency']; $input['auth_emergency_care_hospital'] = $data['auth_emergency_nearest_hosp']; $input['auth_oral_non_presc'] = $data['auth_oral_non_presc']; $input['first_permission'] = isset($data['first_permission']) ? 'yes' : 'no'; $input['second_permission'] = isset($data['second_permission']) ? 'yes' : 'no'; $input['third_permission'] = isset($data['third_permission']) ? 'yes' : 'no'; } $this->db->set($input)->where('profile_id',$id)->update('profiles'); return $this->db->affected_rows() >= 1 ? TRUE : FALSE; } public function count_id($data,$grade_level) { $input['id_cat'] = $data->cat; $input['id_year'] = $data->year; $input['id_num']= $data->num; $input['id_complete'] = $data->full; $input['grade_level'] = $grade_level; $query = $this->db->insert('student_id_counter',$input); if($this->db->affected_rows() >=1) { return TRUE; }else{ log_message('error','ID '.$data->full.' Was not inserted to database ID counter'); } } public function get_last_input_id() { return $this->last_insert_id; } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/models/m_new_enrollee.php
PHP
mit
19,804
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/application/models/index.html
HTML
mit
114
<?php class M_gperiods Extends CI_Model { private $__table = 'grading_periods'; public function __construct() { parent::__construct(); } public function get_gperiods($id = FALSE) { $this->load->database(); if($id == FALSE){ $data = $this->db->get($this->__table); }else{ $data = $this->db->where('gp_id',$id)->get($this->__table); } return $data->num_rows() >= 1 ? $data->result() : FALSE; } public function fetch_gperiods($limit,$start) { $this->db->limit($limit, $start); $query = $this->db->select(array('gp_id','gp_code','gp_desc','gp_stat','is_set'))->get($this->__table); return $query->num_rows() >= 1 ? $query->result() : FALSE; } public function count_gperiods() { return $this->db->count_all($this->__table); } public function update_gperiods($input,$id) { if($this->verify_data($input,2) == FALSE) { $input['gp_updated'] = NOW; $this->db->set($input)->where('gp_id',$id)->update($this->__table); return $this->db->affected_rows() > 0 ? array('status'=>'true') : array('status'=>'false'); }else{ return array('status'=>'exist'); } } public function add_gperiods($input) { if($this->verify_data($input,2) == FALSE) { $input['gp_created'] = NOW; $this->db->insert($this->__table,$input); return $this->db->affected_rows() > 0 ? array('status'=>'true') : array('status'=>'false'); }else{ return array('status'=>'exist'); } } public function destroy($id) { $data['gp_stat'] = 'inactive'; $data['gp_updated'] = NOW; $this->db->set($data)->where('gp_id',$id)->update($this->__table); return $this->db->affected_rows() > 0 ? TRUE : FALSE; } public function set($id,$current_id) { $this->db->set('is_set','')->where('gp_id',$current_id)->update($this->__table); if($this->db->affected_rows() > 0) { $data['is_set'] = 'yes'; $data['gp_updated'] = NOW; $this->db->set($data)->where('gp_id',$id)->update($this->__table); return $this->db->affected_rows() > 0 ? TRUE : FALSE; }else{ return FALSE; } } public function undestroy($id) { $data['gp_stat'] = 'active'; $data['gp_updated'] = NOW; $this->db->set($data)->where('gp_id',$id)->update($this->__table); return $this->db->affected_rows() > 0 ? TRUE : FALSE; } public function get_id_of_current_gperiod(){ $query = $this->db->where('is_set','yes')->select('gp_id')->get($this->__table); if($query->num_rows () > 0 ){ $row = $query->row(); return $row->gp_id; } } public function get_current_gperiod() { $query = $this->db->where('is_set','yes')->get($this->__table); return $query->num_rows() > 0 ? $query->result() : FALSE; } public function get_current_gperiods_value($data) { $query = $this->db->select($data)->where('is_set','yes')->get($this->__table); if($query->num_rows() > 0 ) { $row = $query->row(); return $row->$data; } } public function get_specific_coloumn($data) { $query = $this->db->select($data)->get($this->__table); return $query->num_rows() > 0 ? $query->result() : FALSE; } /* verify_data * @param array * @param int * verifies if data entered by user is existing already in the database * $strict level 1,2 * level 1 = if one field has existing data in database returns true else false * level 2 = if all field has existing data in database returns true else false * 12/11/2012 */ public function verify_data($data,$strict_level) { if($strict_level == 1) { $query = $this->db->or_where($data)->get($this->__table); }elseif($strict_level == 2){ $query = $this->db->where($data)->get($this->__table); } return $query->num_rows() > 0 ? TRUE : FALSE; } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/models/m_gperiods.php
PHP
mit
3,844
<?php class M_for_enrollment_id Extends MY_Model{ private $_table = 'for_enrollment_id'; public function __construct() { parent::__construct(); } public function get_enrollment_id() { $sql = "SELECT for_e_id FROM for_enrollment_id LIMIT 1"; $query = $this->db->query($sql); return $query->num_rows() >=1 ? $query->row() : FALSE; } public function update_enrollment_id($data) { $this->db->truncate('for_enrollment_id'); $this->db->insert('for_enrollment_id', $data); return $this->db->affected_rows() >=1 ? TRUE : FALSE; } public function get_max() { $this->db->select_max('for_e_id'); $query = $this->db->get('for_enrollment_id'); return $query->num_rows() >=1 ? $query->row() : FALSE; } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/models/m_for_enrollment_id.php
PHP
mit
817
<?php class M_check_verification Extends MY_Model { /* validate verification link and creates login credentials for student */ public function check_and_create_login_credentials($id,$auth) { $sql = 'SELECT enrollment_transaction_code, mustverify, e_profile_id, e_student_id, concat(profiles.lastname," , ",profiles.firstname," ",profiles.middlename) as fullname, profiles.email FROM enrollments LEFT JOIN profiles ON e_profile_id = profiles.profile_id WHERE enrollment_transaction_code = ? AND e_id = ? AND verified = 0 LIMIT 1 '; $query = $this->db->query($sql,array($auth,$id)); if($query->num_rows() >= 1) { $result = $query->row(); // check if time verify is expired if(time() >= $result->mustverify) { $link = site_url('confirm/resend'); $log['stat'] = FALSE; $log['log'] = 'This validation link is already expired. <a href="'.$link.'" class="btn btn-success">Resend Validation</a>'; return (object)$log; }else { // update verified statust to true $this->db->set('verified',1)->where('e_id',$id)->update('enrollments'); if($this->db->affected_rows() >= 1) { //generate student password $this->load->model('M_users'); $password_generate = substr(md5(rand(100,999)),0,8); $data_user['username'] = $result->e_student_id; $data_user['hashed_password'] = $this->M_users->hash_password($password_generate); $data_user['userType'] = 'student'; $data_user['userStatus'] = 'active'; $data_user['created_at'] = NOW; //insert the data to user table $this->db->insert('users',$data_user); // get last inserted ID $student_user_id = $this->db->insert_id(); //if insert was successfull if($this->db->affected_rows() >= 1) { //insert last inserted ID from the users table to the profiles table $this->db->set('user_id',$student_user_id)->where('profile_id',$result->e_profile_id)->update('profiles'); if($this->db->affected_rows() >= 1) { $log['password'] = $password_generate; $log['username'] = $result->e_student_id; $log['fullname'] = $result->fullname; $log['email'] = $result->email; $log['stat'] = TRUE; $log['log'] = 'Your enrollment was successfully verified. Kindly refer to your email for your account details. Thank you'; return (object)$log; }else{ //failed in updating profile user_id $this->db->delete('users',$student_user_id); $log['stat'] = FALSE; $log['log'] = 'Unable to update profile user id'; return (object)$log; } }else{ //insert fail return false $log['stat'] = FALSE; $log['log'] = 'Unable to insert users to database'; return (object)$log; } }else{ $log['stat'] = FALSE; $log['log'] = 'Unable to verify user'; return (object)$log; } } }else { $log['stat'] = FALSE; $log['log'] = 'Unable to get code'; return (object)$log; } } /* validate confirmation link without creating a login credentials for the student */ public function check($id,$code) { $sql = 'SELECT enrollment_transaction_code, mustverify, e_profile_id, e_student_id, concat(profiles.lastname," , ",profiles.firstname," ",profiles.middlename) as fullname, profiles.email FROM enrollments LEFT JOIN profiles ON e_profile_id = profiles.profile_id WHERE enrollment_transaction_code = ? AND e_id = ? AND verified = 0 LIMIT 1 '; $query = $this->db->query($sql,array($code,$id)); if($query->num_rows() >= 1) { $result = $query->row(); // check if confirmation link is expired if(time() >= $result->mustverify) { $message ='Sorry, The verification link you have supplied to us is already expired. Please regenerate a new confirmation link.'; $message .='<a href="'.site_url('confirm/resend').'" class="btn btn-success">Resend Confirmation Link</a>'; $log['stat'] = FALSE; $log['log'] = $message; return (object)$log; }else{ //confirmation link not yet expired, update verification status $this->db->set('verified',1)->where('e_id',$id)->update('enrollments'); if($this->db->affected_rows() >=1) { $message ='Confirmation successfully verified. Please Check your email address for further instruction.'; $log['fullname'] = $result->fullname; $log['email'] = $result->email; $log['stat'] = TRUE; $log['log'] = $message; return (object)$log; }else{ $message ='THe system has encountered an error while trying to validate your confirmation link.'; $message .='Pleae try to re-click the confirmation link or regenerate a new confirmation link'; $message .='<a href="'.site_url('confirm/resend').'" class="btn btn-success">Regenerate and Resend Confirmation Link</a>'; $log['stat'] = FALSE; $log['log'] = $message; return (object)$log; } } }else{ $message ='Sorry,The system has encountered an error while trying to retrieve your confirmation code.'; $message .='Please try clicking the verification link again or try to regenerate a new confirmation link'; $message .='<a href="'.site_url('confirm/resend').'" class="btn btn-success">Resend Confirmation Link</a>'; $log['stat'] = FALSE; $log['log'] = $message; return (object)$log; } } public function resend_confirmation_code($x = FALSE) { if($x !== FALSE) { $select_email = "SELECT email,e_id,user_id,firstname,middlename,lastname,profile_id FROM profiles LEFT JOIN enrollments ON enrollments.e_profile_id = profiles.profile_id WHERE email = ? AND enrollments.verified = 0 "; $query = $this->db->query($select_email,array($x)); if($query->num_rows() >= 1) { $r = $query->row(); $conf_code = substr(base64_encode(sha1(time().rand(10,99).md5(time().rand(100,200)))),0,15); $this->db->set('enrollment_transaction_code',$conf_code) ->set('mustverify',(time()*60)) ->set('verified',0) ->where('e_id',$r->e_id) ->where('e_profile_id',$r->profile_id) ->update('enrollments'); if($this->db->affected_rows() >= 1) { $log['id'] = $r->e_id; $log['etc'] = $conf_code; $log['email'] = $r->email; $log['fullname'] = ucwords(strtolower($r->lastname.' '.$r->firstname.' '.$r->middlename[0].'.')); $log['stat'] = TRUE; $log['log'] = 'Updated confirmation code'; return (object)$log; }else{ $log['stat'] = FALSE; $log['log'] = 'System was unable to generate confirmation code, Try again later'; return (object)$log; } }else{ $log['stat'] = FALSE; $log['log'] = 'Email Address Not Found'; return (object)$log; } }else{ return FALSE; } } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/models/m_check_verification.php
PHP
mit
7,154
<?php class M_id_creator Extends MY_Model { private $table = 'student_id_counter'; public function get_id($level) { if($this->get_last_id($level) == FALSE) { $this->get_id($level); }else{ return $this->get_last_id($level); } } public function search_id($id,$level) { $table = $this->table; $year = $this->c_sy->sy_from; $sql = "SELECT max(id_num) as max_num FROM {$table} WHERE grade_level = ? AND id_year = ? AND id_num = ?"; $query = $this->db->query($sql,array($level,$year,$id)); return $query->num_rows() >=1 ? TRUE : FALSE; } public function get_last_id($grade_level = FALSE) { if($grade_level !== FALSE AND is_numeric($grade_level)) { $table = $this->table; $year = $this->c_sy->sy_from; $sql = "SELECT max(id_num) as max_num FROM {$table} WHERE grade_level = ? AND id_year = ?"; $query = $this->db->query($sql,array($grade_level,$year)); if($query->num_rows() >=1) { $result = $query->row()->max_num; if($result !== NULL) { return $result + 1; }else{ return 1; } }else{ return FALSE; } }else{ return FALSE; } } public function get_assigned_category($level) { $table = 'levels'; $query = $this->db->select('level_code_for_id') ->where('level_id',$level) ->limit(1) ->get($table); return $query->num_rows() >= 1 ? $query->row()->level_code_for_id : FALSE; } public function get_new_id($level = '') { $num = $this->get_id($level); $cat = $this->get_assigned_category($level); $year = $this->c_sy->sy_from; if($num AND $cat AND $year) { $data['num'] = $num; $data['cat'] = $cat; $data['year'] = $year; return (object)$data; }else{ return FALSE; } } /* ======= FOR COMPRESSED METHOD ON CREATING ID ================ */ //smallworld format // [year]-[CATEGORY][NUMBER] public function create_id($level_id) { $cat = $this->get_assigned_category($level_id); $year = $this->c_sy->sy_from; $insert['grade_level'] = $level_id; $insert['id_year'] = $year; $insert['id_cat'] = $cat; $insert['id_num'] = 0; $this->db->insert($this->table,$insert); if($this->db->affected_rows() >= 1) { $id = $this->db->insert_id(); $complete = substr($year,2).'-'.$cat.$id; $this->db->set('id_complete',$complete) ->where('id',$id) ->update($this->table); return $this->db->affected_rows() >= 1 ? $complete : FALSE; }else{ return FALSE; } } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/models/m_id_creator.php
PHP
mit
2,665
<?php class M_pre_applicant Extends CI_Model{ public function register_complete_info($profile_data) { unset($profile_data['brombrom']); $profile_data = (object)$profile_data; //format date and get age from birhtdate $d = $this->__format($profile_data->child_bdate); $profile_input['p_a_grade_level'] = $profile_data->level_id; $profile_input['p_a_sy_from'] = $profile_data->sy_from; $profile_input['p_a_sy_to'] = $profile_data->sy_to; $profile_input['p_a_created_at'] = NOW; $profile_input['p_a_dob'] = $d->dob; $profile_input['p_a_mobile_phone'] = $profile_data->mobile_phone; $profile_input['p_a_ay_id'] = $profile_data->ay_id; $profile_input['p_a_age'] = $d->age; $profile_input['p_a_schedule_for_testing'] = $profile_data->schedule_for_testing; $profile_input['p_a_firstname'] = $profile_data->child_fname; $profile_input['p_a_lastname'] = $profile_data->child_lname; $profile_input['p_a_middlename'] = strtolower($profile_data->child_mname) == 'none' ? NULL : $profile_data->child_mname; $profile_input['p_a_hear_from'] = $profile_data->hear_from; $profile_input['p_a_description'] = $profile_data->desc; $profile_input['p_a_price'] = $profile_data->price; $this->db->insert('pre_applicants',$profile_input); return $this->db->affected_rows() > 0 ? TRUE : FALSE; } private function __format($date) { $date = DateTime::createFromFormat('m/d/Y', $date); $dob = $date->format('Y-m-d'); $birthday = strtotime($dob); $time = time(); $seconds = $time - $birthday; $age = floor($seconds / 31536000); return (object)array('dob'=>$dob,'age'=>$age); } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/models/m_pre_applicant.php
PHP
mit
1,664
<?php class M_levels extends CI_Model { private $__table = 'levels'; public function get_all_levels($id=FALSE) { if($id == FALSE){ $query = $this->db->get($this->__table); }else{ $query = $this->db->where('level_id',$id)->get($this->__table); } return $query->num_rows() >= 1 ? $query->result() : FALSE; } /* query to fetch all grade level for pagnation tomex 11/12/11/2012 */ public function fetch_grade_level($limit, $start) { $this->db->limit($limit, $start); $query = $this->db->select(array('level_id','level_desc','level_stat','level_code'))->get($this->__table); return $query->num_rows() >= 1 ? $query->result() : FALSE; } /* query to update level_stat to inactive tomex 11/12/11/2012 */ public function destroy($id){ $data['level_updated'] = NOW; $data['level_stat'] = 'inactive'; $this->db->set($data)->where('level_id',$id)->update($this->__table); return $this->db->affected_rows() > 0 ? TRUE : FALSE; } /* verify_data * @param array * @param int * verifies if data entered by user is existing already in the database * $strict level 1,2 * level 1 = if one field has existing data in database returns true else false * level 2 = if all field has existing data in database returns true else false * 12/11/2012 */ public function verify_data($data,$strict_level) { if($strict_level == 1) { $query = $this->db->or_where($data)->get($this->__table); }elseif($strict_level == 2){ $query = $this->db->where($data)->get($this->__table); } return $query->num_rows() > 0 ? TRUE : FALSE; } public function get_grade_level($level_id){ $q = $this->db->where('level_id', $level_id)->get('levels'); return $q->num_rows() >= 1 ? $q->row() : FALSE; } public function get_specific_coloumn($data) { $query = $this->db->select($data)->get($this->__table); return $query->num_rows() > 0 ? $query->result() : FALSE; } public function get_all_levels_array() { $query = $this->db->select(array('level_id','level_desc','level_code')) ->where('level_stat','active') ->get($this->__table); if($query->num_rows() > 0) { $result[''] ='-- Choose A Level --'; foreach($query->result() as $q) { $result[$q->level_id] = $q->level_code.' | '.$q->level_desc; } return $result; }else{ return FALSE; } } } ?>
0683babd6e120333c4dae5bac951f5cc
trunk/application/models/m_levels.php
PHP
mit
2,464
<?php class M_fees Extends CI_Model { private $__table ='fees'; public function __construct() { parent::__construct(); } public function get_all_fees($id ='') { if($id == ''){ $query = $this->db->get($this->__table); }else{ $query = $this->db->select(array('fee_id','fee_desc','fee_stat','fee_name','fee_rate'))->where('fee_id',$id)->get($this->__table); } return $query->num_rows() > 0 ? $query->result() : FALSE; } public function fetch_fees($limit,$start) { $this->db->limit($limit, $start); $query = $this->db->select(array('fee_id','fee_desc','fee_stat','fee_name','fee_rate'))->get($this->__table); return $query->num_rows() >= 1 ? $query->result() : FALSE; } public function count_all_fees() { return $this->db->count_all($this->__table); } public function add_fees($data) { if($this->verify_data($data,2) == FALSE) { $data['fee_created'] = NOW; $this->db->insert($this->__table,$data); return $this->db->affected_rows() > 0 ? array('status'=>'true') : array('status'=>'false'); }else{ return array('status'=>'exist'); } } public function update_fees($data,$id) { if($this->verify_data($data,2) == FALSE) { $data['fee_updated'] = NOW; $this->db->set($data)->where('fee_id',$id)->update($this->__table); return $this->db->affected_rows() > 0 ? array('status'=>'true') : array('status'=>'false'); }else { return array('status' => 'exist'); } } public function get_assessment_fees_by_grade_level() { $sql = 'SELECT fee_id,fee_desc,fee_stat,fee_name,fee_rate,fee_new,fee_old FROM fees WHERE is_assess_fee = ? '; $query = $this->db->query($sql,array('1')); return $query->num_rows() >= 1 ? $query->row() : FALSE; } /* verify_data * @param array * @param int * verifies if data entered by user is existing already in the database * $strict level 1,2 * level 1 = if one field has existing data in database returns true else false * level 2 = if all field has existing data in database returns true else false * 12/11/2012 */ public function verify_data($data,$strict_level) { if($strict_level == 1) { $query = $this->db->or_where($data)->get($this->__table); }elseif($strict_level == 2){ $query = $this->db->where($data)->get($this->__table); } return $query->num_rows() > 0 ? TRUE : FALSE; } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/models/m_fees.php
PHP
mit
2,484
<?php class M_school_settings extends CI_Model { private $__table = 'school_settings'; public function get_all_school_setting($id='') { $query = $this->db->limit(1)->get($this->__table); return $query->num_rows() >= 1 ? $query->result() : FALSE; } public function check_online_status() { $sql = "SELECT enable_online_enrollment as status, enrollment_offline_header as heading, enrollment_offline_content as content FROM online_settings LIMIT 1"; $query = $this->db->query($sql); return $query->num_rows() >=1 ? $query->row() : FALSE; } public function check_email_verification() { $sql = $this->db->select('enrollment_verify_email')->limit(1)->get('system_settings'); if($sql->num_rows() >=1) { if($sql->row()->enrollment_verify_email == 1) { return TRUE; }else{ return FALSE; } }else{ return FALSE; } } } ?>
0683babd6e120333c4dae5bac951f5cc
trunk/application/models/m_school_settings.php
PHP
mit
931
<?php class M_old_enrollee Extends MY_Model { private $grade_level_id; public function check_student_id($id) { $sql = "SELECT e_id,e_profile_id,e_ay_id FROM enrollments WHERE e_student_id = ? AND e_registered = 1 AND verified = 1 ORDER BY e_created_at ASC LIMIT 1"; $query = $this->db->query($sql,array($id)); $row = $query->row(); if(!empty($row)) { if($row->e_ay_id == $this->c_sy->id) { return array('enrollment_id'=>NULL,'profile_id'=>NULL,'status' => FALSE,'log'=>"<div class='error'><span class='bold big'>{$id}</span> This student Is Already Registered For the Current Academic Year</div>"); }else{ return array('enrollment_id'=>$row->e_id,'profile_id'=>$row->e_profile_id,'status' => TRUE); } }else{ return array('enrollment_id'=>NULL,'profile_id'=>NULL,'status' => FALSE,'log'=>"<div class='error'>Student ID <span class='bold big'>{$id}</span> was not found</div>"); } } public function verify_student_credentials($data,$student_id) { $data = (object)$data; // get password from db $get_pass = 'SELECT hashed_password FROM users WHERE username = ? LIMIT 1 '; $q_get_pass = $this->db->query($get_pass,array($student_id)); $r_get_pass = $q_get_pass->num_rows() >=1 ? $q_get_pass->row()->hashed_password !== NULL ? $q_get_pass->row()->hashed_password : NULL : NULL; // check if firstname and lastname is correct $sql = 'SELECT count(e_id) as total FROM enrollments e LEFT JOIN profiles p on e.e_profile_id = p.profile_id LEFT JOIN users u ON u.id = p.user_id WHERE p.firstname = ? AND p.lastname = ?'; $query = $this->db->query($sql,array($data->fname,$data->lname)); if($query->num_rows() >=1) { if($query->row()->total) { //check if student entered the correct password $ci =& get_instance(); $ci->load->model('M_users','m'); if($ci->m->validate_password($r_get_pass,$data->password)) { return array('status'=>TRUE); }else{ return array('status'=>FALSE); } }else{ return array('status'=>FALSE); } }else{ return array('status'=>FALSE); } } public function create_old_enrollee($id) { // get next grade level $enrollee_data = "SELECT l.level_hierarchy,e.e_id,e.e_profile_id FROM enrollments e LEFT JOIN levels l ON e.e_grade_level = l.level_id WHERE e_student_id = ? ORDER BY e_created_at ASC "; $result = $this->db->query($enrollee_data,array($id)); $e_data = $result->num_rows() >= 1 ? $result->row() : FALSE; if($e_data) { // get grade level to be assigned $get_grade_level_to_assign = "SELECT level_id FROM levels WHERE level_hierarchy > ? AND level_stat = 'active' ORDER BY level_hierarchy ASC LIMIT 1"; $q_glevel = $this->db->query($get_grade_level_to_assign,array($e_data->level_hierarchy)); $r_glevel = $q_glevel->num_rows() >=1 ? $q_glevel->row() : FALSE; if($r_glevel) { // update student's old enrollment data, set as archived $update_enrollments = "update enrollments set e_archived = 1 WHERE e_id = ?"; $update = $this->db->query($update_enrollments,array($e_data->e_id)); if($this->db->affected_rows() >=1) { $for_old_enrollment['e_profile_id'] = $e_data->e_profile_id; $for_old_enrollment['e_grade_level'] = $r_glevel->level_id; $for_old_enrollment['e_sy_from'] = $this->c_sy->sy_from; $for_old_enrollment['e_sy_to'] = $this->c_sy->sy_to; $for_old_enrollment['e_created_at'] = NOW; $for_old_enrollment['e_enrollee_type'] = 'old'; $for_old_enrollment['e_ay_id'] = $this->c_sy->id; $for_old_enrollment['e_student_id'] = $id; $for_old_enrollment['verified'] = 1; if($this->db->insert('enrollments',$for_old_enrollment)) { $this->grade_level_id = $for_old_enrollment['e_grade_level']; $this->last_insert_id = $this->db->insert_id(); return (object)array('status'=>TRUE,'log'=>'<div class="success">Student Has been Enrolled Successfully</div>'); }else{ return (object)array('status'=>FALSE,'log'=>'<div class="error">An error occurred while registering student</div>'); } }else{ return (object)array('status'=>FALSE,'log'=>'<div class="error">AN error has occured, system was unable to update your old records.</div>'); } }else{ return (object)array('status'=>FALSE,'log'=>'<div class="error">An error occurred, System was unable to get your Grade Level</div>'); } }else{ return (object)array('status'=>FALSE,'log'=>'<div class="error">An error occurred, System was unable to fetch your old data.</div>'); } } public function return_data() { return (object)['id'=>$this->last_insert_id,'level_id'=>$this->grade_level_id]; } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/models/m_old_enrollee.php
PHP
mit
4,976
<?php class M_users extends CI_Model { private $last_insert_id; /* ------------------------------------------------------------------- add_user 12-6-12 perry ------------------------------------------------------------------- Adds a user on the system Returns true if add success Returns false if add unsuccessful */ public function add_user($attrib){ $v = (object) $attrib; $hashed_password = $this->hash_password($v->hashed_password); $user_data = array( 'username' => $v->username, 'hashed_password' => $hashed_password, 'userType' => $v->userType, 'userStatus' => $v->userStatus, 'created_at' => NOW, ); $this->db->insert('users', $user_data); return $this->db->affected_rows() > 0 ? TRUE : FALSE; } /* ------------------------------------------------------------------- verify_user 12-6-12 perry ------------------------------------------------------------------- Verifies if an existing user is present in the system and checks their login credentials Returns false if credentials are invalid or userstatus is not active Returns true if credentials are valid */ public function verify_user($attrib) { $v = (object) $attrib; $this->db->where('username', $v->username); $query = $this->db->get('users'); if($query->num_rows() >= 1 && $query->row()->userStatus == 'active') { $row = $query->row(); if($this->validate_password($row->hashed_password, $v->password)){ $userdata = array( 'userid' => $row->id, 'username' => $row->username, 'userType' => $row->userType, 'logged_in' => TRUE ); $this->session->set_userdata($userdata); return true; } }else{ return false; } } /* ------------------------------------------------------------------- hash_password 12-6-12 perry ------------------------------------------------------------------- hashes the users password returns the hashed password with salt */ public function hash_password($password) { $salt = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM)); $hash = hash('sha256', $salt . $password); return $salt . $hash; } /* ------------------------------------------------------------------- validate_password 12-6-12 perry ------------------------------------------------------------------- validates the users password returns the hashed password with salt */ public function validate_password($hashed_password, $password) { $salt = substr($hashed_password, 0, 64); $hash = substr($hashed_password, 64, 64); $password_hash = hash('sha256', $salt . $password); return $password_hash == $hash; } /* -------------------------------------------------------------------------- get_all_users 12-6-2012 tom -------------------------------------------------------------------------- @param id if parameter is false gets all users from db if parameter exists gets specific id from parameter */ public function get_all_users($id = FALSE) { if($id == FALSE){ $query = $this->db->get('users'); }else{ $query = $this->db->where('id',$id)->get('users'); } return $query->num_rows() > 0 ? $query->result() : FALSE; } /* -------------------------------------------------------------------------- update_users 12-6-2012 tom -------------------------------------------------------------------------- @param id @param data = array updates user info */ public function update_user($id,$data) { $this->db->set($data)->where('id',$id)->update('users'); return $this->db->affected_rows() > 0 ? TRUE : FALSE; } /* -------------------------------------------------------------------------- change_pass 12-6-2012 tom -------------------------------------------------------------------------- @param id @param newpass updates password */ public function change_pass($newpassword,$id){ $newpassword = $this->hash_password($newpassword); if($this->db->set('hashed_password',$newpassword)->where('id',$id)->update('users')){ return TRUE; }else{ return FALSE; } } /* -------------------------------------------------------------------------- verify_password 12-6-2012 tom -------------------------------------------------------------------------- @param id @param old password checks password from database and matches from user input */ public function verify_password($password,$id) { $data = $this->db->select('hashed_password')->where('id',$id)->get('users'); foreach($data->result() as $data) { $h_pass = $data->hashed_password; break; } if($this->validate_password($h_pass,$password)){ return TRUE; }else{ return FALSE; } } public function destroy($id) { $this->db->update('status','inactive')->where('id',$id)->update('users'); return $this->db->affected_rows() > 0 ? TRUE : FALSE; } function delete_user($user_id){ $this->db->where('id', $user_id)->delete('users'); return $this->db->affected_rows() >= 1 ? TRUE : FALSE; } public function register_complete_info($profile_data) { unset($profile_data['level_id']); unset($profile_data['student_number']); $profile_data = (object)$profile_data; //format date and get age from birhtdate $d = $this->__format($profile_data->child_bdate); $profile_input['email'] = $profile_data->email; $profile_input['firstname'] = $profile_data->child_fname; $profile_input['middlename'] = strtolower($profile_data->child_mname) == 'none' ? NULL : $profile_data->child_mname; $profile_input['lastname'] = $profile_data->child_lname; $profile_input['nickname'] = $profile_data->child_nickname; $profile_input['name_ext'] = $profile_data->child_name_ext; $profile_input['gender'] = $profile_data->gender; $profile_input['dob'] = $d->dob; $profile_input['age'] = $d->age; if($profile_data->child_nationality == 'other'){ $profile_input['nationality'] = $profile_data->child_nationality2; }else{ $profile_input['nationality'] = $profile_data->child_nationality; } if($profile_input['nationality']=='filipino' || $profile_input['nationality']=='filipina' || $profile_input['nationality']=='pilipino' || $profile_input['nationality']=='pilipina' || $profile_input['nationality']=='philippine' || $profile_input['nationality']=='fil' || $profile_input['nationality']=='pinoy' || $profile_input['nationality']=='pinay' || $profile_input['nationality']=='philippines' || $profile_input['nationality']=='phil' || $profile_input['nationality']=='fhil' || $profile_input['nationality']=='pnoy'): $profile_input['nationality']='Filipino'; endif; $profile_input['pob'] = $profile_data->child_placeofbirth; $profile_input['present_address'] = $profile_data->child_city_address; $profile_input['contact_no'] = $profile_data->child_telno; $profile_input['contact_no'] = $profile_data->mobile_phone; $profile_input['religion'] = $profile_data->child_religous; $profile_input['living_in_ph_with_father'] = !isset($profile_data->living_in_ph_with_father) ? 'no' : 'yes'; $profile_input['living_in_ph_with_mother'] = !isset($profile_data->living_in_ph_with_mother) ? 'no' : 'yes'; $profile_input['living_in_ph_with_guardian'] = !isset($profile_data->living_in_ph_with_guardian) ? 'no' : 'yes'; $profile_input['childs_english_reading_writing_level'] = $profile_data->childs_english_reading_writing_level; $profile_input['childs_english_verbal_proficiency'] = $profile_data->childs_english_verbal_proficiency; $profile_input['language_at_home'] = $profile_data->language_at_home; $profile_input['participation_in_advanced_level_classes'] = $profile_data->participation_in_advanced_level_classes; $profile_input['remedial_help_in_previous_schools'] = $profile_data->remedial_help_in_previous_schools; $profile_input['special_talent_interest_dance'] = !isset($profile_data->special_talent_interest_dance) ? 'no' : 'yes'; $profile_input['special_talent_interest_drama'] = !isset($profile_data->special_talent_interest_drama) ? 'no' : 'yes'; $profile_input['special_talent_interest_art'] = !isset($profile_data->special_talent_interest_art) ? 'no' : 'yes'; $profile_input['special_talent_interest_acomputer'] = !isset($profile_data->special_talent_interest_acomputer) ? 'no' : 'yes'; $profile_input['special_talent_interest_vocal_chorus'] = !isset($profile_data->special_talent_interest_vocal_chorus) ? 'no' : 'yes'; $profile_input['special_talent_interest_athletics'] = !isset($profile_data->special_talent_interest_athletics) ? 'no' : 'yes'; $profile_input['special_talent_interest_athletics_spec'] = $profile_data->special_talent_interest_athletics_spec; $profile_input['special_talent_interest_band'] = !isset($profile_data->special_talent_interest_band) ? 'no' : 'yes'; $profile_input['special_talent_interest_band_spec'] = $profile_data->special_talent_interest_band_spec; $profile_input['special_talent_interest_string'] = !isset($profile_data->special_talent_interest_string) ? 'no' : 'yes'; $profile_input['special_talent_interest_string_spec'] = $profile_data->special_talent_interest_string_spec; $profile_input['dhc_hinder_learning_process'] = $profile_data->hinder_childs_learning; $profile_input['leave_school'] = $profile_data->leave_school; $profile_input['previous_school'] = $profile_data->previous_school; $profile_input['previous_school_address'] = $profile_data->previous_school_address; $profile_input['previous_grade_level'] = $profile_data->previous_grade_level; $profile_input['guardian_name'] = $profile_data->guardian_name; $profile_input['guardian_mname'] = $profile_data->guardian_mname; $profile_input['guardian_lname'] = $profile_data->guardian_lname; $profile_input['guardian_citizenship'] = $profile_data->guardian_citizenship; $profile_input['guardian_visa'] = $profile_data->guardian_visa; $profile_input['guardian_occup'] = $profile_data->guardian_occup; $profile_input['guardian_office_tel'] = $profile_data->guardian_office_tel; $profile_input['guardian_contact_no'] = $profile_data->guardian_contact_no; $profile_input['guardian_contact_no_text'] = !isset($profile_data->guardian_contact_no_text) ? 'no' : 'yes'; $profile_input['fathername'] = $profile_data->father_name; $profile_input['father_mname'] = $profile_data->father_mname; $profile_input['father_lname'] = $profile_data->father_lname; $profile_input['father_nationality'] = $profile_data->father_citizenship; $profile_input['father_visa'] = $profile_data->father_visa; $profile_input['father_occupation'] =$profile_data->father_occup; $profile_input['father_office_num'] =$profile_data->father_office_tel; $profile_input['father_contact_no'] =$profile_data->father_contact_no; $profile_input['father_contact_no_text'] = !isset($profile_data->father_contact_no_text) ? 'no' : 'yes'; $profile_input['mothername'] =$profile_data->mother_name; $profile_input['mother_mname'] =$profile_data->mother_mname; $profile_input['mother_lname'] =$profile_data->mother_lname; $profile_input['mother_nationality'] =$profile_data->mother_citizenship; $profile_input['mother_visa'] =$profile_data->mother_visa; $profile_input['mother_occupation'] =$profile_data->mother_occup; $profile_input['mother_office_num'] =$profile_data->mother_office_tel; $profile_input['mother_contact_no'] =$profile_data->mother_contact_no; $profile_input['mother_contact_no_text'] = !isset($profile_data->mother_contact_no_text) ? 'no' : 'yes'; $profile_input['step_father_name'] =$profile_data->step_father_name; $profile_input['step_father_mname'] = $profile_data->step_father_mname; $profile_input['step_father_lname'] = $profile_data->step_father_lname; $profile_input['step_father_citizenship'] =$profile_data->step_father_citizenship; $profile_input['step_father_visa'] =$profile_data->step_father_visa; $profile_input['step_father_occup'] =$profile_data->step_father_occup; $profile_input['step_father_office_tel'] =$profile_data->step_father_office_tel; $profile_input['step_father_contact_no'] =$profile_data->step_father_contact_no; $profile_input['step_father_contact_no_text'] = !isset($profile_data->step_father_contact_no_text) ? 'no' : 'yes'; $profile_input['step_mother_name'] =$profile_data->step_mother_name; $profile_input['step_mother_mname'] = $profile_data->step_mother_mname; $profile_input['step_mother_lname'] = $profile_data->step_mother_lname; $profile_input['step_mother_citizenship'] =$profile_data->step_mother_citizenship; $profile_input['step_mother_visa'] =$profile_data->step_mother_visa; $profile_input['step_mother_occup'] =$profile_data->step_mother_occup; $profile_input['step_mother_office_tel'] =$profile_data->step_mother_office_tel; $profile_input['step_mother_contact_no'] =$profile_data->step_mother_contact_no; $profile_input['step_mother_contact_no_text'] = !isset($profile_data->step_mother_contact_no_text) ? 'no' : 'yes'; $profile_input['failure_to_provide'] = !isset($profile_data->failure_to_provide) ? 'no' : 'yes'; $profile_input['to_the_best'] = !isset($profile_data->to_the_best) ? 'no' : 'yes'; $profile_input['hhc_allergies_reaction'] = $profile_data->allergies_reaction; $profile_input['hhc_alergic_med_reaction'] = $profile_data->drug_allergies_reaction; $profile_input['dhc_sight_problems_what'] = $profile_data->eye_problem_spec; $profile_input['dhc_hearing_problems_what'] = $profile_data->ear_problem_spec; $profile_input['hhc_diagnosed_specify'] = $profile_data->major_ailment; $profile_input['hhc_recently_hospitalized'] = $profile_data->recently_hospitalized; $profile_input['hhc_major_injury_specify'] = $profile_data->major_injury; $profile_input['hhc_medication_school_hours'] = $profile_data->medication_child_taking_spec; $profile_input['hhc_asthma_inhaler'] = isset($profile_data->asthma_inhaler) ? $profile_data->asthma_inhaler : 'no'; $profile_input['hhc_asthma'] = isset($profile_data->asthma) ? $profile_data->asthma : 'no'; $profile_input['auth_firstaid'] = $profile_data->authfirst_aid; $profile_input['auth_emergency_care'] = $profile_data->auth_emergency; $profile_input['auth_emergency_care_hospital'] = $profile_data->auth_emergency_nearest_hosp; $profile_input['auth_oral_non_presc'] = $profile_data->auth_oral_non_presc; $profile_input['first_permission'] = isset($profile_data->first_permission) ? 'yes' : 'no'; $profile_input['second_permission'] = isset($profile_data->second_permission) ? 'yes' : 'no'; $profile_input['third_permission'] = isset($profile_data->third_permission) ? 'yes' : 'no'; $profile_input['created'] = NOW; $this->db->insert('profiles',$profile_input); $this->last_insert_id = $this->db->insert_id(); return $this->db->affected_rows() >= 1 ? TRUE : FALSE; } public function update_complete_info($profile_data,$e_profile_id) { unset($profile_data['level_id']); unset($profile_data['student_number']); $profile_data = (object)$profile_data; //format date and get age from birhtdate $d = $this->__format($profile_data->child_bdate); $profile_input['email'] = $profile_data->email; $profile_input['firstname'] = strtolower($profile_data->child_fname); $profile_input['middlename'] = strtolower($profile_data->child_mname) == 'none' ? NULL : strtolower($profile_data->child_mname); $profile_input['lastname'] = strtolower($profile_data->child_lname); $profile_input['nickname'] = strtolower($profile_data->child_nickname); $profile_input['name_ext'] = strtolower($profile_data->child_name_ext); $profile_input['gender'] = $profile_data->gender; $profile_input['dob'] = $d->dob; $profile_input['age'] = $d->age; if($profile_data->child_nationality == 'other'){ $profile_input['nationality'] = $profile_data->child_nationality2; }else{ $profile_input['nationality'] = $profile_data->child_nationality; } if($profile_input['nationality']=='filipino' || $profile_input['nationality']=='filipina' || $profile_input['nationality']=='pilipino' || $profile_input['nationality']=='pilipina' || $profile_input['nationality']=='philippine' || $profile_input['nationality']=='fil' || $profile_input['nationality']=='pinoy' || $profile_input['nationality']=='pinay' || $profile_input['nationality']=='philippines' || $profile_input['nationality']=='phil' || $profile_input['nationality']=='fhil' || $profile_input['nationality']=='pnoy'): $profile_input['nationality']='Filipino'; endif; $profile_input['pob'] = $profile_data->child_placeofbirth; $profile_input['present_address'] = $profile_data->child_city_address; $profile_input['contact_no'] = $profile_data->child_telno; $profile_input['contact_no'] = $profile_data->mobile_phone; $profile_input['religion'] = $profile_data->child_religous; $profile_input['living_in_ph_with_father'] = !isset($profile_data->living_in_ph_with_father) ? 'no' : 'yes'; $profile_input['living_in_ph_with_mother'] = !isset($profile_data->living_in_ph_with_mother) ? 'no' : 'yes'; $profile_input['living_in_ph_with_guardian'] = !isset($profile_data->living_in_ph_with_guardian) ? 'no' : 'yes'; $profile_input['childs_english_reading_writing_level'] = $profile_data->childs_english_reading_writing_level; $profile_input['childs_english_verbal_proficiency'] = $profile_data->childs_english_verbal_proficiency; $profile_input['language_at_home'] = $profile_data->language_at_home; $profile_input['participation_in_advanced_level_classes'] = $profile_data->participation_in_advanced_level_classes; $profile_input['remedial_help_in_previous_schools'] = $profile_data->remedial_help_in_previous_schools; $profile_input['special_talent_interest_dance'] = !isset($profile_data->special_talent_interest_dance) ? 'no' : 'yes'; $profile_input['special_talent_interest_drama'] = !isset($profile_data->special_talent_interest_drama) ? 'no' : 'yes'; $profile_input['special_talent_interest_art'] = !isset($profile_data->special_talent_interest_art) ? 'no' : 'yes'; $profile_input['special_talent_interest_acomputer'] = !isset($profile_data->special_talent_interest_acomputer) ? 'no' : 'yes'; $profile_input['special_talent_interest_vocal_chorus'] = !isset($profile_data->special_talent_interest_vocal_chorus) ? 'no' : 'yes'; $profile_input['special_talent_interest_athletics'] = !isset($profile_data->special_talent_interest_athletics) ? 'no' : 'yes'; $profile_input['special_talent_interest_athletics_spec'] = $profile_data->special_talent_interest_athletics_spec; $profile_input['special_talent_interest_band'] = !isset($profile_data->special_talent_interest_band) ? 'no' : 'yes'; $profile_input['special_talent_interest_band_spec'] = $profile_data->special_talent_interest_band_spec; $profile_input['special_talent_interest_string'] = !isset($profile_data->special_talent_interest_string) ? 'no' : 'yes'; $profile_input['special_talent_interest_string_spec'] = $profile_data->special_talent_interest_string_spec; $profile_input['dhc_hinder_learning_process'] = $profile_data->hinder_childs_learning; $profile_input['leave_school'] = $profile_data->leave_school; $profile_input['previous_school'] = $profile_data->previous_school; $profile_input['previous_school_address'] = $profile_data->previous_school_address; $profile_input['previous_grade_level'] = $profile_data->previous_grade_level; $profile_input['guardian_name'] = $profile_data->guardian_name; $profile_input['guardian_mname'] = strtolower($profile_data->guardian_mname) == 'none' ? NULL : strtolower($profile_data->guardian_mname); $profile_input['guardian_lname'] = $profile_data->guardian_lname; $profile_input['guardian_citizenship'] = $profile_data->guardian_citizenship; $profile_input['guardian_visa'] = $profile_data->guardian_visa; $profile_input['guardian_occup'] = $profile_data->guardian_occup; $profile_input['guardian_office_tel'] = $profile_data->guardian_office_tel; $profile_input['guardian_contact_no'] = $profile_data->guardian_contact_no; $profile_input['guardian_contact_no_text'] = !isset($profile_data->guardian_contact_no_text) ? 'no' : 'yes'; $profile_input['fathername'] = strtolower($profile_data->father_name); $profile_input['father_mname'] = strtolower($profile_data->father_mname) == 'none' ? NULL : strtolower($profile_data->father_mname); $profile_input['father_lname'] = strtolower($profile_data->father_lname); $profile_input['father_nationality'] = $profile_data->father_citizenship; $profile_input['father_visa'] = $profile_data->father_visa; $profile_input['father_occupation'] =$profile_data->father_occup; $profile_input['father_office_num'] =$profile_data->father_office_tel; $profile_input['father_contact_no'] =$profile_data->father_contact_no; $profile_input['father_contact_no_text'] = !isset($profile_data->father_contact_no_text) ? 'no' : 'yes'; $profile_input['mothername'] =strtolower($profile_data->mother_name); $profile_input['mother_mname'] =strtolower($profile_data->mother_mname) == 'none' ? NULL : strtolower($profile_data->mother_mname); $profile_input['mother_lname'] =strtolower($profile_data->mother_lname); $profile_input['mother_nationality'] =$profile_data->mother_citizenship; $profile_input['mother_visa'] =$profile_data->mother_visa; $profile_input['mother_occupation'] =$profile_data->mother_occup; $profile_input['mother_office_num'] =$profile_data->mother_office_tel; $profile_input['mother_contact_no'] =$profile_data->mother_contact_no; $profile_input['mother_contact_no_text'] = !isset($profile_data->mother_contact_no_text) ? 'no' : 'yes'; $profile_input['step_father_name'] =strtolower($profile_data->step_father_name); $profile_input['step_father_mname'] = strtolower($profile_data->step_father_mname) == 'none' ? NULL : strtolower($profile_data->step_father_mname); $profile_input['step_father_lname'] = strtolower($profile_data->step_father_lname); $profile_input['step_father_citizenship'] =$profile_data->step_father_citizenship; $profile_input['step_father_visa'] =$profile_data->step_father_visa; $profile_input['step_father_occup'] =$profile_data->step_father_occup; $profile_input['step_father_office_tel'] =$profile_data->step_father_office_tel; $profile_input['step_father_contact_no'] =$profile_data->step_father_contact_no; $profile_input['step_father_contact_no_text'] = !isset($profile_data->step_father_contact_no_text) ? 'no' : 'yes'; $profile_input['step_mother_name'] =strtolower($profile_data->step_mother_name); $profile_input['step_mother_mname'] = strtolower($profile_data->step_mother_mname) == 'none' ? NULL : strtolower($profile_data->step_mother_mname); $profile_input['step_mother_lname'] = strtolower($profile_data->step_mother_lname); $profile_input['step_mother_citizenship'] =$profile_data->step_mother_citizenship; $profile_input['step_mother_visa'] =$profile_data->step_mother_visa; $profile_input['step_mother_occup'] =$profile_data->step_mother_occup; $profile_input['step_mother_office_tel'] =$profile_data->step_mother_office_tel; $profile_input['step_mother_contact_no'] =$profile_data->step_mother_contact_no; $profile_input['step_mother_contact_no_text'] = !isset($profile_data->step_mother_contact_no_text) ? 'no' : 'yes'; $profile_input['failure_to_provide'] = !isset($profile_data->failure_to_provide) ? 'no' : 'yes'; $profile_input['to_the_best'] = !isset($profile_data->to_the_best) ? 'no' : 'yes'; $profile_input['hhc_allergies_reaction'] = $profile_data->allergies_reaction; $profile_input['hhc_alergic_med_reaction'] = $profile_data->drug_allergies_reaction; $profile_input['dhc_sight_problems_what'] = $profile_data->eye_problem_spec; $profile_input['dhc_hearing_problems_what'] = $profile_data->ear_problem_spec; $profile_input['hhc_diagnosed_specify'] = $profile_data->major_ailment; $profile_input['hhc_recently_hospitalized'] = $profile_data->recently_hospitalized; $profile_input['hhc_major_injury_specify'] = $profile_data->major_injury; $profile_input['hhc_medication_school_hours'] = $profile_data->medication_child_taking_spec; $profile_input['hhc_asthma_inhaler'] = isset($profile_data->asthma_inhaler) ? $profile_data->asthma_inhaler : 'no'; $profile_input['hhc_asthma'] = isset($profile_data->asthma) ? $profile_data->asthma : 'no'; $profile_input['auth_firstaid'] = $profile_data->authfirst_aid; $profile_input['auth_emergency_care'] = $profile_data->auth_emergency; $profile_input['auth_emergency_care_hospital'] = $profile_data->auth_emergency_nearest_hosp; $profile_input['auth_oral_non_presc'] = $profile_data->auth_oral_non_presc; $profile_input['first_permission'] = isset($profile_data->first_permission) ? 'yes' : 'no'; $profile_input['second_permission'] = isset($profile_data->second_permission) ? 'yes' : 'no'; $profile_input['third_permission'] = isset($profile_data->third_permission) ? 'yes' : 'no'; //$profile_input['created'] = NOW; $this->db->where('profile_id', $e_profile_id); $this->db->update('profiles', $profile_input); return $this->db->affected_rows() >= 1 ? TRUE : FALSE; } public function register_user($profile_data) { unset($profile_data['level_id']); $profile_data = (object)$profile_data; //format date and get age from birhtdate $d = $this->__format($profile_data->child_bdate); $profile_input['email'] = $profile_data->email; $profile_input['firstname'] = $profile_data->child_fname; $profile_input['middlename'] = strtolower($profile_data->child_mname) == 'none' ? NULL : $profile_data->child_mname; $profile_input['lastname'] = $profile_data->child_lname; $profile_input['nickname'] = $profile_data->child_nickname; $profile_input['name_ext'] = $profile_data->child_name_ext; $profile_input['gender'] = $profile_data->gender; $profile_input['dob'] = $d->dob; $profile_input['age'] = $d->age; if($profile_data->child_nationality == 'other'){ $profile_input['nationality'] = $profile_data->child_nationality2; }else{ $profile_input['nationality'] = $profile_data->child_nationality; } if($profile_input['nationality']=='filipino' || $profile_input['nationality']=='filipina' || $profile_input['nationality']=='pilipino' || $profile_input['nationality']=='pilipina' || $profile_input['nationality']=='philippine' || $profile_input['nationality']=='fil' || $profile_input['nationality']=='pinoy' || $profile_input['nationality']=='pinay' || $profile_input['nationality']=='philippines' || $profile_input['nationality']=='phil' || $profile_input['nationality']=='fhil' || $profile_input['nationality']=='pnoy'): $profile_input['nationality']='Filipino'; endif; $profile_input['pob'] = $profile_data->child_placeofbirth; $profile_input['present_address'] = $profile_data->child_city_address; $profile_input['contact_no'] = $profile_data->child_telno; $profile_input['contact_no'] = $profile_data->mobile_phone; $profile_input['religion'] = $profile_data->child_religous; $profile_input['living_in_ph_with_father'] = !isset($profile_data->living_in_ph_with_father) ? 'no' : 'yes'; $profile_input['living_in_ph_with_mother'] = !isset($profile_data->living_in_ph_with_mother) ? 'no' : 'yes'; /*$profile_input['living_in_ph_with_step_father'] = !isset($profile_data->living_in_ph_with_step_father ) ? 'no' : 'yes'; $profile_input['living_in_ph_with_step_mother'] = !isset($profile_data->living_in_ph_with_step_mother) ? 'no' : 'yes';*/ $profile_input['living_in_ph_with_guardian'] = !isset($profile_data->living_in_ph_with_guardian) ? 'no' : 'yes'; /*$profile_input['living_in_ph_with_legal_guardian_name'] = $profile_data->living_in_ph_with_legal_guardian_name; $profile_input['living_in_ph_with_legal_guardian_contact_number'] = $profile_data->living_in_ph_with_legal_guardian_contact_number;*/ $profile_input['childs_english_reading_writing_level'] = $profile_data->childs_english_reading_writing_level; $profile_input['childs_english_verbal_proficiency'] = $profile_data->childs_english_verbal_proficiency; $profile_input['language_at_home'] = $profile_data->language_at_home; $profile_input['participation_in_advanced_level_classes'] = $profile_data->participation_in_advanced_level_classes; $profile_input['remedial_help_in_previous_schools'] = $profile_data->remedial_help_in_previous_schools; $profile_input['special_talent_interest_dance'] = !isset($profile_data->special_talent_interest_dance) ? 'no' : 'yes'; $profile_input['special_talent_interest_drama'] = !isset($profile_data->special_talent_interest_drama) ? 'no' : 'yes'; $profile_input['special_talent_interest_art'] = !isset($profile_data->special_talent_interest_art) ? 'no' : 'yes'; $profile_input['special_talent_interest_acomputer'] = !isset($profile_data->special_talent_interest_acomputer) ? 'no' : 'yes'; $profile_input['special_talent_interest_vocal_chorus'] = !isset($profile_data->special_talent_interest_vocal_chorus) ? 'no' : 'yes'; $profile_input['special_talent_interest_athletics'] = !isset($profile_data->special_talent_interest_athletics) ? 'no' : 'yes'; $profile_input['special_talent_interest_athletics_spec'] = $profile_data->special_talent_interest_athletics_spec; $profile_input['special_talent_interest_band'] = !isset($profile_data->special_talent_interest_band) ? 'no' : 'yes'; $profile_input['special_talent_interest_band_spec'] = $profile_data->special_talent_interest_band_spec; $profile_input['special_talent_interest_string'] = !isset($profile_data->special_talent_interest_string) ? 'no' : 'yes'; $profile_input['special_talent_interest_string_spec'] = $profile_data->special_talent_interest_string_spec; $profile_input['dhc_hinder_learning_process'] = $profile_data->hinder_childs_learning; $profile_input['leave_school'] = $profile_data->leave_school; $profile_input['previous_school'] = $profile_data->previous_school; $profile_input['previous_school_address'] = $profile_data->previous_school_address; $profile_input['previous_grade_level'] = $profile_data->previous_grade_level; /*$profile_input['previous_school_grade_1'] =$profile_data->previous_school_grade_1; $profile_input['previous_school_name_1'] =$profile_data->previous_school_name_1; $profile_input['previous_school_year_1'] =$profile_data->previous_school_year_1; $profile_input['previous_school_grade_2'] =$profile_data->previous_school_grade_2; $profile_input['previous_school_name_2'] =$profile_data->previous_school_name_2; $profile_input['previous_school_year_2'] =$profile_data->previous_school_year_2; $profile_input['previous_school_grade_3'] =$profile_data->previous_school_grade_3; $profile_input['previous_school_name_3'] =$profile_data->previous_school_name_3; $profile_input['previous_school_year_3'] =$profile_data->previous_school_year_3;*/ $profile_input['guardian_name'] = $profile_data->guardian_name; $profile_input['guardian_mname'] = $profile_data->guardian_mname; $profile_input['guardian_lname'] = $profile_data->guardian_lname; $profile_input['guardian_citizenship'] = $profile_data->guardian_citizenship; $profile_input['guardian_visa'] = $profile_data->guardian_visa; $profile_input['guardian_occup'] = $profile_data->guardian_occup; $profile_input['guardian_office_tel'] = $profile_data->guardian_office_tel; $profile_input['guardian_contact_no'] = $profile_data->guardian_contact_no; $profile_input['guardian_contact_no_text'] = !isset($data['guardian_contact_no_text']) ? 'no' : 'yes'; $profile_input['created'] = NOW; $this->db->insert('profiles',$profile_input); $this->last_insert_id = $this->db->insert_id(); return $this->db->affected_rows() >= 1 ? TRUE : FALSE; } private function __format($date) { $date = DateTime::createFromFormat('Y-m-d', $date); $dob = $date->format('Y-m-d'); $birthday = strtotime($dob); $time = time(); $seconds = $time - $birthday; $age = floor($seconds / 31536000); return (object)array('dob'=>$dob,'age'=>$age); } public function get_last_insert_id() { return $this->last_insert_id; } /* Check if the email is already used and returns TRUE if verified, FALSE if not verified. */ public function check_my_mail($emailer,$profile_id) { $sql = "SELECT e.verified FROM enrollments e LEFT JOIN profiles p ON e.e_profile_id = p.profile_id WHERE p.email = ? AND p.profile_id != ? "; $query = $this->db->query($sql,array($emailer,$profile_id)); $data = $query->num_rows() >= 1 ? $query->result() : FALSE; if(!empty($data)) { $count = 0; $has = 0; foreach($data as $email){ $has += $email->verified; $count++; } if($has >= 1) { return TRUE; }else{ return FALSE; } }else{ return FALSE; } } } ?>
0683babd6e120333c4dae5bac951f5cc
trunk/application/models/m_users.php
PHP
mit
33,414
<?php class M_level_fees Extends CI_Model { private $__table = 'level_fees'; private $_ftable = 'fees'; private $_ltable = 'levels'; public function __construct() { parent::__construct(); } public function check_level_fee_isset() { } public function get_grade_level($id=FALSE) { if($id == FALSE){ $query = $this->db->select(array('level_id','level_desc','level_code'))->get($this->_ltable); }else{ $query = $this->db->select(array('level_id','level_desc'))->where('level_id',$id)->get($this->_ltable); } return $query->num_rows() > 0 ? $query->result() : FALSE; } public function get_all_fees() { $query = $this->db->select(array('fee_id','fee_name','fee_desc','fee_rate'))->get($this->_ftable); return $query->num_rows() > 0 ? $query->result() : FALSE; } public function get_sel_fees($id) { $sql = "SELECT fee_id, fee_name, fee_desc, fee_rate, is_tuition_fee, is_cca_fee, is_misc_fee FROM fees WHERE fee_new = 'yes' AND grade_level = ?"; $query = $this->db->query($sql,array($id,$id)); return $query->num_rows() > 0 ? $query->result() : FALSE; } public function get_tuition_fees_set_for_current_level($id) { $sql = "SELECT fees.fee_id,fees.fee_name,fees.fee_desc,fees.fee_rate FROM fees WHERE fees.grade_level = ? AND fee_stat = 'active' AND is_tuition_fee = 1; "; $query = $this->db->query($sql,array($id)); return $query->num_rows() > 0 ? $query->result() : FALSE; } public function get_active_registration_fee($id) { $sql = "SELECT fees.fee_id,fees.fee_name,fees.fee_desc,fees.fee_rate FROM fees where fee_stat = 'active' AND is_registration_fee = 1 AND fees.grade_level = ? "; $query = $this->db->query($sql,array($id)); return $query->num_rows() > 0 ? $query->result() : FALSE; } public function update_grade_level_fees($data,$id) { if($this->db->where('lf_level_id',$id)->delete($this->__table)){ if($this->db->insert_batch($this->__table, $data)){ return array('status'=>'true'); }else{ return array('status'=>'false'); } }else{ return array('status'=>'nodelete'); } } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/models/m_level_fees.php
PHP
mit
2,274
<?php class M_enrollees extends CI_Model { private $__table = 'enrollments'; public function get_all_enrollees($sy_from=FALSE,$sy_to=FALSE) { $query = 'SELECT sections.section_name, sections.section_status, enrollments.e_profile_id, enrollments.e_section_id, enrollments.e_enrollee_type, levels.level_code, levels.level_desc, enrollments.e_grade_level, enrollments.e_id, enrollments.e_sy_from, enrollments.e_sy_to, profiles.idno, profiles.firstname, profiles.lastname, profiles.middlename, FROM enrollments LEFT JOIN profiles ON enrollments.e_profile_id = profiles.profile_id LEFT JOIN sections ON enrollments.e_section_id = sections.id LEFT JOIN levels ON enrollments.e_grade_level = levels.level_id WHERE enrollments.e_sy_from = \''.$sy_from.'\' AND enrollments.e_sy_to = \''.$sy_to.'\' '; $q = $this->db->query($query); return $q->num_rows() >= 1 ? $q->result() : FALSE; //$query = $this->db->where('e_sy_from',$sy_from)->where('e_sy_to',$sy_to)->get($this->__table); //return $query->num_rows() >= 1 ? $query->result() : FALSE; } /* query to count all enrollees for pagination */ public function count_enrollees($sy_from=FALSE,$sy_to=FALSE) { return $this->db->where('e_sy_from',$sy_from)->where('e_sy_to',$sy_to)->count_all($this->__table); } /* query to fetch all enrollees for pagination */ public function fetch_all_enrollees($sy_from,$sy_to,$limit, $start) { //$this->db->limit($limit, $start); $q = "SELECT enrollments.e_id, enrollments.e_created_at, profiles.idno, profiles.firstname, profiles.lastname, profiles.middlename, profiles.profile_id FROM enrollments LEFT JOIN profiles ON enrollments.e_profile_id = profiles.profile_id WHERE enrollments.e_sy_from = ".$sy_from." AND enrollments.e_sy_to = ".$sy_to." AND enrollments.e_registered = 0 LIMIT ".$start.",".$limit." "; //$query = $this->db->where('e_sy_from',$sy_from)->where('e_sy_to',$sy_to)->get($this->__table); $query = $this->db->query($q); return $query->num_rows() >= 1 ? $query->result() : FALSE; } function search_enrollee($lastname, $firstname, $idno, $sy_from, $sy_to){ $query = "SELECT sections.section_name, sections.section_status, enrollments.e_profile_id, enrollments.e_section_id, enrollments.e_enrollee_type, levels.level_code, levels.level_desc, enrollments.e_grade_level, enrollments.e_id, enrollments.e_sy_from, enrollments.e_sy_to, enrollments.e_profile_id, profiles.user_id, profiles.idno, profiles.firstname, profiles.lastname, profiles.middlename FROM enrollments LEFT JOIN profiles ON enrollments.e_profile_id = profiles.profile_id LEFT JOIN sections ON enrollments.e_section_id = sections.id LEFT JOIN levels ON enrollments.e_grade_level = levels.level_id WHERE profiles.firstname LIKE '%$firstname%' AND profiles.lastname LIKE '%$lastname%' AND profiles.idno LIKE '%$idno%' AND (enrollments.e_sy_from = '$sy_from' AND enrollments.e_sy_to = '$sy_to') AND enrollments.e_registered = 0 "; $q = $this->db->query($query); return $q->num_rows() >= 1 ? $q->result() : FALSE; } function search_student($lastname, $firstname, $idno, $sy_from, $sy_to){ $query = "SELECT sections.section_name, sections.section_status, enrollments.e_profile_id, enrollments.e_section_id, enrollments.e_enrollee_type, levels.level_code, levels.level_desc, enrollments.e_grade_level, enrollments.e_id, enrollments.e_sy_from, enrollments.e_sy_to, enrollments.e_profile_id, profiles.user_id, profiles.idno, profiles.firstname, profiles.lastname, profiles.middlename FROM enrollments LEFT JOIN profiles ON enrollments.e_profile_id = profiles.profile_id LEFT JOIN sections ON enrollments.e_section_id = sections.id LEFT JOIN levels ON enrollments.e_grade_level = levels.level_id WHERE profiles.firstname LIKE '%$firstname%' AND profiles.lastname LIKE '%$lastname%' AND profiles.idno LIKE '%$idno%' AND (enrollments.e_sy_from = '$sy_from' AND enrollments.e_sy_to = '$sy_to') AND enrollments.e_registered = 1 "; $q = $this->db->query($query); return $q->num_rows() >= 1 ? $q->result() : FALSE; } public function get_enrollee_profile($id) { $sql = 'SELECT profile_id, firstname as `First Name`, lastname as `Last Name`, middlename as `Middle Name`, student_type as `Student Type`, gender as `Gender`, civilstatus as `Civil Status`, dob as `Date of Birth`, pob as `Place of Birth`, age as `Age`, disability as `Disability`, nationality as `Nationality`, religion as `Religion`, contact_no as `Contact Number`, email as `Email Address`, present_address as `Present Address`, fathername as `Father\'s Name`, father_occupation as `Father\s Occupation`, father_contact_no as `father\'s Contact #`, mothername as `Mother\'s Name`, mother_occupation as `Mother\'s Occupation`, mother_contact_no as `mother\'s Contact #`, parent_address as `Parent\'s Address`, guardian_name as `Guardian\'s Name`, relationship as `Guardian\'s Relationship`, guardian_contact_no as `Guardian\'s Contac #`, guardian_address as `Guardian\'s Address`, last_school_name as `last School Attended`, last_school_address as `Address`, last_school_level as `level`, last_school_year as `Year` FROM profiles where profile_id = ?'; $get_profile_query = $this->db->query($sql,array($id)); return $get_profile_query->num_rows() > 0 ? $get_profile_query->result_array() : FALSE; } public function get_enrollee_profile_all($profile_id){ $query = "SELECT profiles.profile_id, enrollee_id, idno, firstname, lastname, middlename, student_type, gender, civilstatus, dob, pob, age, disability, nationality, religion, contact_no, email, present_address, fathername, father_occupation, father_contact_no, mothername, mother_occupation, mother_contact_no, parent_address, guardian_name, relationship, guardian_contact_no, guardian_address, last_school_name, last_school_address, last_school_level, last_school_year, sy_from, sy_to, section_id, other_info.level_id, level_code, level_desc, section_name FROM profiles LEFT JOIN ( SELECT enrollments.e_id AS enrollee_id, enrollments.e_section_id AS section_id, enrollments.e_sy_from AS sy_from, enrollments.e_sy_to AS sy_to, e_profile_id AS profile_id, e_grade_level AS level_id, levels.level_code, levels.level_desc, sections.section_name FROM enrollments LEFT JOIN levels ON levels.level_id = enrollments.e_grade_level LEFT JOIN sections ON sections.id = enrollments.e_id WHERE enrollments.e_profile_id = '$profile_id' ) AS other_info ON profiles.profile_id = other_info.profile_id WHERE profiles.profile_id = '$profile_id'"; $q = $this->db->query($query); return $q->num_rows() >= 1 ? $q->row() : FALSE; } public function get_enrollee_fees($e_id,$gp,$sy) { $sql = "SELECT sef.sef_fee_name, sef.sef_fee_rate , sef.sef_id FROM student_enrollment_fees sef where sef.sef_enrollment_id = ? AND sef.sef_gperiod_id = ? AND sef.sef_schoolyear_id = ?;"; $query = $this->db->query($sql,array($e_id,$gp,$sy)); return $query->num_rows() > 0 ? $query->result() : FALSE; } public function get_available_fees($e_id) { $all_fee_query = $this->db->select(array('fee_rate as sef_fee_rate','fee_name as sef_fee_name'))->get('fees'); if($all_fee_query->num_rows() > 0) { $sel_fee_query = $this->db->select(array('sef_fee_name','sef_fee_rate'))->where('sef_enrollment_id',$e_id)->get('student_enrollment_fees'); if($sel_fee_query->num_rows() > 0) { $all_fees = $all_fee_query->result_array(); $sel_fees = $sel_fee_query->result_array(); $names = array_map(function($value){ return $value['sef_fee_name']; },$sel_fees); $new = array_filter($all_fees, function($value) use ($names){ return !in_array($value['sef_fee_name'], $names); }); return $new; }else{ return FALSE; } }else{ return FALSE; } } function assign_enrollee_to_section($e_profile_id, $section_id){ $this->db->where('e_profile_id', $e_profile_id)->update('enrollments', array('e_section_id' => $section_id)); return $this->db->affected_rows() >= 1 ? TRUE : FALSE; } function get_enrollee_section_id($e_profile_id){ $q = $this->db->select('e_section_id')->where('e_profile_id', $e_profile_id)->get($this->__table); return $q->num_rows() >= 1 ? $q->row()->e_section_id : FALSE; } function update_enrollee_profile_all($profile_data, $enrollment_data, $profile_id){ $this->db->where('e_profile_id', $profile_id)->update('enrollments', $enrollment_data); if($this->db->affected_rows() >= 1){ $this->db->where('profile_id', $profile_id)->update('profiles', $profile_data); return $this->db->affected_rows() >= 1 ? 'success' : 'profile_failed'; } else return FALSE; } function destroy_enrollee($enrollment_id){ $this->db->where('e_id', $enrollment_id)->delete('enrollments'); return $this->db->affected_rows() > 0 ? TRUE : FALSE; } function destroy_account($user_id, $profile_id){ $this->db->where('profile_id', $profile_id)->delete('enrolled_subjects'); $this->db->where('e_profile_id', $profile_id)->delete('enrollments'); $this->db->where('id', $user_id)->delete('users'); return true; } public function cashier_add_new_fees($data) { $this->db->insert_batch('student_enrollment_fees',$data); return $this->db->affected_rows() > 0 ? TRUE : FALSE; } public function get_sum_of_fees($id,$gp,$sy) { $sql = 'SELECT sum(sef_fee_rate) as sef_fee_rate FROM student_enrollment_fees WHERE sef_gperiod_id = ? AND sef_schoolyear_id = ? AND sef_enrollment_id = ?'; $query = $this->db->query($sql,array($gp,$sy,$id)); if($query->num_rows() > 0) { $row = $query->row(); return $row->sef_fee_rate; }else { return 'No Data'; } } public function get_sum_of_paid_fees($id,$gperiod,$sy) { $sql = 'SELECT sum(spr_ammt_paid) as spr_ammt_paid FROM student_payment_records WHERE spr_gperiod_id = ? AND spr_schoolyear_id = ? AND spr_enrollment_id = ?'; $query = $this->db->query($sql,array($gperiod,$sy,$id)); if($query->num_rows() > 0) { $row = $query->row(); return $row->spr_ammt_paid; }else { return 'No Data'; } } public function delete_stud_fee($sef_id,$e_id) { $this->db->where('sef_id',$sef_id)->where('sef_enrollment_id',$e_id)->delete('student_enrollment_fees'); return $this->db->affected_rows() > 0 ? TRUE : FALSE; } public function get_enrollee_prof($e_id,$p_id) { $sql= "SELECT p.idno, p.profile_id, e.e_id, l.level_desc, l.level_id, concat(p.lastname,' ',p.firstname,' ',p.middlename)as fullname FROM profiles p,levels l,enrollments e WHERE p.profile_id = e.e_profile_id AND e.e_grade_level = p.level_id AND e.e_grade_level = l.level_id AND p.profile_id = ? AND e.e_id = ?"; $query = $this->db->query($sql,array($p_id,$e_id)); return $query->num_rows() > 0 ? $query->result() : FALSE; } public function check_level_fee_status($l_id) { $sql = "SELECT lf_fee_id, fee_name, fee_rate FROM level_fees lf,fees f WHERE lf.lf_fee_id = f.fee_id AND lf_level_id = ?"; $query = $this->db->query($sql,array($l_id)); return $query->num_rows() > 0 ? $query->result() : FALSE; } public function get_all_scholarships() { $query = $this->db->get('student_scholarships'); return $query->num_rows() > 0 ? $query->result() : FALSE; } } ?>
0683babd6e120333c4dae5bac951f5cc
trunk/application/models/m_enrollees.php
PHP
mit
13,177
<?php class M_school_years extends CI_Model { private $__table = 'school_years'; public function get_all_school_year($id=FALSE) { if($id == FALSE){ $query = $this->db->get($this->__table); }else{ $query = $this->db->where('id',$id)->get($this->__table); } return $query->num_rows() >= 1 ? $query->result() : FALSE; } /* Get Set School Year */ public function get_set_school_year() { $query = $this->db->where('is_set','yes')->get($this->__table); return $query->num_rows() >= 1 ? $query->row() : FALSE; } public function get_current_sy_format() { $data = $this->get_set_school_year(); if(!empty($data)) { $date = $data->sy_from.' - '.$data->sy_to; return $date; }else{ return NULL; } } /* Add School Year */ public function add_school_year($input) { if($this->verify_data($input,1) == FALSE) { $this->db->insert($this->__table,$input); return $this->db->affected_rows() > 0 ? array('status'=>'true') : array('status'=>'false'); }else { return array('status'=>'exist'); } } /* query to count all school years for pagnation */ public function count_school_year() { return $this->db->count_all($this->__table); } /* query to fetch all school year for pagnation */ public function fetch_school_year($limit, $start) { $this->db->limit($limit, $start); $query = $this->db->select(array('id','sy_from','sy_to','is_set'))->get($this->__table); return $query->num_rows() >= 1 ? $query->result() : FALSE; } /* set School Year */ public function set_school_year($input,$id) { $input['is_set'] = ''; $this->db->set($input)->update($this->__table); $input['is_set'] = 'yes'; $this->db->set($input)->where('id',$id)->update($this->__table); return $this->db->affected_rows() > 0 ? array('status'=>'true') : array('status'=>'false'); } public function get_id_of_current_sy() { $query = $this->db->where('is_set','yes')->select('id')->get($this->__table); if($query->num_rows () > 0 ){ $row = $query->row(); return $row->id; } } public function get_sy_starting($from,$to) { $query = "SELECT * FROM school_years WHERE sy_from = '".$from."' OR sy_from = '".$to."' "; $quer = $this->db->query($query); if($quer->num_rows() > 0) { $result[''] ='-- Choose School Year --'; foreach($quer->result() as $q) { $result[$q->id.'_'.$q->sy_from.'_'.$q->sy_to] = $q->sy_from.' - '.$q->sy_to; } return $result; }else{ return FALSE; } } /* verify_data * @param array * @param int * verifies if data entered by user is existing already in the database * $strict level 1,2 * level 1 = if one field has existing data in database returns true else false * level 2 = if all field has existing data in database returns true else false * 12/11/2012 */ public function verify_data($data,$strict_level) { if($strict_level == 1) { $query = $this->db->or_where($data)->get($this->__table); }elseif($strict_level == 2){ $query = $this->db->where($data)->get($this->__table); } return $query->num_rows() > 0 ? TRUE : FALSE; } } ?>
0683babd6e120333c4dae5bac951f5cc
trunk/application/models/m_school_years.php
PHP
mit
3,321
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/application/logs/index.html
HTML
mit
114
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/application/libraries/index.html
HTML
mit
114
<?php Class Create_captcha { public function _captcha() { $CI =& get_instance(); $CI->load->helper('captcha'); $system_counted_hash = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM)); $vals = array( 'word' => substr(sha1(rand(1,100).$system_counted_hash),3,rand(3,5)), 'img_path' => './captcha/', 'img_url' => base_url().'auth/captcha', 'font_path' => './assets/fonts/4.ttf', 'img_width' => '150', 'img_height' => 35, 'expiration' => 7200 ); $cap = create_captcha($vals); $image['word'] = $cap['word']; $image['image'] ='<image src="'.base_url().'captcha/'.$cap['time'].'.jpg"/>'; $image['link'] = './captcha/'.$cap['time'].'.jpg'; return (object)$image; } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/libraries/create_captcha.php
PHP
mit
743
<?php class Quest_captcha { private $ci; public function __construct() { $this->ci =& get_instance(); $this->_init(); } private function _init($reset = FALSE) { if($this->ci->session->userdata('questcap') == FALSE OR $reset == TRUE) { $questions = $this->generate_question(); $question_key = array_rand($questions); $selected = $questions[$question_key]; $for_session = [ 'question_k'=> $question_key, 'question' => $selected[0], 'answer' => $selected[1], 'questcap' => TRUE ]; $this->ci->session->set_userdata($for_session); } } private function generate_question() { $question[]=['2 + 2 = ?',4]; $question[]=['First letter of the English Alphabet?','a']; $question[]=['8 x 2',16]; $question[]=['Third letter of the English Alphabet?','c']; $question[]=['10 + 10 = ?',20]; $question[]=['6 + 6 = ?',12]; $question[]=['5 + 1 = ?',6]; $question[]=['3 + 2 = ?',5]; $question[]=['8 + 7 = ?',15]; $question[]=['6 - 3 = ?',3]; $question[]=['1 X 1 = ?',1]; $question[]=['fill in missing letter( C_MPUTER )','o']; $question[]=['fill in missing letter( INT_RN_T)','e']; $question[]=['fill in missing letter( CE_L P_ONE )','lp']; $question[]=['fill in missing letter( CAM_RA )','e']; $question[]=['fill in missing letter( T__TH BRUSS )','oo']; $question[]=['fill in missing letter( AIR PL_NE )','a']; $question[]=['2 + 4 + 1 = ?',7]; $question[]=['8 + 1 - 1 = ?',8]; $question[]=['3 - 1 + 1 = ?',3]; return $question; } // PUBLICS public function get_question() { return $this->ci->session->userdata('question'); } public function check_answer($answer) { return strtolower($this->ci->session->userdata('answer')) == trim(strtolower($answer)); } public function reset_question() { $this->_init(TRUE); } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/libraries/quest_captcha.php
PHP
mit
1,918
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); require_once APPPATH.'/libraries/hashids'.EXT; class hs Extends hashids\Hashids { public function __construct() { parent::__construct($salt = 'jJifd893jfJjfdi.\/dDf3g$\*83f',5); } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/libraries/hs.php
PHP
mit
271
<?php class token { private $ci; public function __construct() { $this->ci =& get_instance(); $this->set_token(); } public function set_token() { if($this->get_token() == NULL OR $this->get_token() == FALSE OR $this->get_token() == '') { $this->ci->session->set_userdata('form_token',$this->random_hash()); } } public function random_hash() { $string = base64_encode(time().rand(1000,9999).sha1(rand(1000,9999))); return substr(hash('sha256',$string).sha1($string).sha1($string),0,20); } public function reset() { $this->ci->session->set_userdata('form_token',FALSE); } public function get_token() { return $this->ci->session->userdata('form_token'); } public function validate_token($token) { return $this->ci->session->userdata('form_token') == $token ? TRUE : FALSE; } public function destroy_token() { $this->ci->session->set_userdata('form_token',''); } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/libraries/token.php
PHP
mit
967
<?php class Authlink{ private $CI; private $token_return; private $random_word = 'The Big Brown Fox Jumped Over The Lazy Dog savy'; public function __construct() { $this->CI =& get_instance(); } private function authlink_creator() { return sha1(md5(rand(1000,9999).sha1(md5(rand(1000,9999))))).sha1(sha1(rand(1000,9999).md5(sha1(rand(1000,9999))))); } private function salt_creator($data_to_salt) { return sha1(sha1($data_to_salt).sha1(md5($data_to_salt.'asdfHhHgJHGjfdhgdsjftJHsd87f6&U%^*^%')).'asdfKJH7687^HdhfnjhgU&^Hu7hdfshnkJHNK'); } private function substr_creator($data) { return $this->salt_creator(substr($data,intval(strlen($data)/ 2))); } public function generate_authlink($entropy = FALSE) { if($entropy !== FALSE) { foreach(range(0,7) as $range) { $hash = $this->authlink_creator().$this->salt_creator($entropy.md5($range.uniqid).$this->random_word.rand(100000,999999)); } $authlink = $hash; }else{ foreach(range(0,7) as $range) { $hash = $this->authlink_creator().$this->salt_creator($this->random_word.rand(100000,999999)); } $authlink = $hash; } $this->CI->session->set_userdata('authlink',$authlink); return substr(md5($this->random_word.rand(100000,999999)),0,10).$authlink; } public function verify_authlink($auth_from_link) { return $this->substr_creator($this->CI->session->userdata('authlink')) == $this->substr_creator(substr($auth_from_link,10)) ? TRUE : FALSE; } public function clear_authlink() { $this->CI->session->set_userdata('authlink',''); } public function hash_make($x) { foreach(range(0,7) as $num) { $data = sha1(sha1($num.md5($num.$this->random_word)).sha1($this->random_word).md5($x)).'.aspx'; } return $data; } public function check_hash_make($i,$a) { return $this->hash_make($i) == $a ? TRUE : FALSE; } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/libraries/authlink.php
PHP
mit
1,935
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class MY_Form_validation extends CI_Form_validation { public function __construct($rules = array()) { parent::__construct($rules); $this->CI->lang->load('MY_form_validation'); } public function alpha_dash_space($str) { return ( ! preg_match("/^([-a-z0-9_ ])+$/i", $str)) ? FALSE : TRUE; } public function alpha_space($str) { return ( ! preg_match("/^([a-z ])+$/i", $str)) ? FALSE : TRUE; } public function alphanum_space($str) { return ( ! preg_match("/^([a-z0-9 ])+$/i", $str)) ? FALSE : TRUE; } public function text_all($str) { return ( ! preg_match("/^([-a-z0-9_#,.!& ])+$/i", $str)) ? FALSE : TRUE; } public function enumeration($str) { return ( ! preg_match("/^([a-z0-9, ])+$/i", $str)) ? FALSE : TRUE; } public function check_student_nationality() { if(strtolower($this->CI->input->post('child_nationality')) !== 'filipino') { if($this->CI->input->post('nationality_ssp_number') AND $this->CI->input->post('nationality_visa_status') AND $this->CI->input->post('nationality_auth_stay') AND $this->CI->input->post('nationality_passport_no') AND $this->CI->input->post('nationality_icard_no') AND $this->CI->input->post('nationality_date_issued') ) { return TRUE; }else{ return FALSE; } }else{ return TRUE; } } public function error_count() { return count($this->_error_array); } public function error_exists($fields) { $error_number = 0; foreach($fields as $k => $v): if(!empty($this->_field_data[$v]['error'])): $error_number++; endif; endforeach; return $error_number; } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/libraries/MY_Form_validation.php
PHP
mit
1,792
<?php class Idno_creator { private $ci; public function __construct() { $this->ci =& get_instance(); } public function generate_new_id($level) { /* format 2013-nursery-0001 description: every grade level has a different base start ie 0001 example so there will be a 2013-nursery-0001 and 2013-prep2-0001 */ $this->ci->load->model('M_id_creator'); $result = $this->ci->M_id_creator->get_new_id($level); if($result !== FALSE) { // return strlen($result->num); switch($result->num) { case strlen($result->num) == 1: $num = str_pad($result->num,4,0,STR_PAD_LEFT); break; case strlen($result->num) == 2: $num = str_pad($result->num,3,0,STR_PAD_LEFT); break; case strlen($result->num) == 3: $num = str_pad($result->num,2,0,STR_PAD_LEFT); break; case strlen($result->num) == 4: $num = $result->num; break; } $data['num'] = $num; $data['cat'] = $result->cat; $data['year'] = $result->year; $data['full'] = $result->year.'-'.$result->cat.'-'.$num; return (object)$data; }else{ $this->generate_new_id($level); } } public function generate_new_id_compressed($x) { $this->ci->load->model('M_id_creator'); $result = $this->ci->M_id_creator->create_id($x); if($result == FALSE) { $this->generate_new_id_compressed($x); }else{ return $result; } } public function generate_id() { $this->ci->load->model('M_for_enrollment_id'); $this->ci->load->model('M_for_enrollment_id'); $result = $this->ci->M_for_enrollment_id->get_enrollment_id(); if($result == FALSE) { $result1 = $this->ci->M_for_enrollment_id->get_max(); if($result1 == FALSE): $a = 1; return $a; else: $temp_id = $result1->for_e_id; $a = intval($temp_id)+1; return $a; endif; }else{ return $result->for_e_id; } } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/libraries/idno_creator.php
PHP
mit
1,986
<?php // ****************************************************************************** // Software: mPDF, Unicode-HTML Free PDF generator * // Version: 5.4 based on * // FPDF by Olivier PLATHEY * // HTML2FPDF by Renato Coelho * // Date: 2012-02-14 * // Author: Ian Back <ianb@bpm1.com> * // License: GPL * // * // Changes: See changelog.txt * // ****************************************************************************** define('mPDF_VERSION','5.4'); //Scale factor define('_MPDFK', (72/25.4)); // Will only use mm /*-- HTML-CSS --*/ define('AUTOFONT_CJK',1); define('AUTOFONT_THAIVIET',2); define('AUTOFONT_RTL',4); define('AUTOFONT_INDIC',8); define('AUTOFONT_ALL',15); define('_BORDER_ALL',15); define('_BORDER_TOP',8); define('_BORDER_RIGHT',4); define('_BORDER_BOTTOM',2); define('_BORDER_LEFT',1); /*-- END HTML-CSS --*/ if (!defined('_MPDF_PATH')) define('_MPDF_PATH',APPPATH.'third_party/mpdf/') ; if (!defined('_MPDF_URI')) define('_MPDF_URI',_MPDF_PATH); require_once(_MPDF_PATH.'includes/functions.php'); require_once(_MPDF_PATH.'config_cp.php'); if (!defined('_JPGRAPH_PATH')) define("_JPGRAPH_PATH", _MPDF_PATH.'jpgraph/'); if (!defined('_MPDF_TEMP_PATH')) define("_MPDF_TEMP_PATH", _MPDF_PATH.'tmp/'); if (!defined('_MPDF_TTFONTPATH')) { define('_MPDF_TTFONTPATH',_MPDF_PATH.'ttfonts/'); } if (!defined('_MPDF_TTFONTDATAPATH')) { define('_MPDF_TTFONTDATAPATH',_MPDF_PATH.'ttfontdata/'); } $errorlevel=error_reporting(); $errorlevel=error_reporting($errorlevel & ~E_NOTICE); //error_reporting(E_ALL); // mPDF 5.3.76 if(function_exists("date_default_timezone_set")) { if (ini_get("date.timezone")=="") { date_default_timezone_set("Europe/London"); } } if (!function_exists("mb_strlen")) { die("Error - mPDF requires mb_string functions. Ensure that PHP is compiled with php_mbstring.dll enabled."); } if (!defined('PHP_VERSION_ID')) { $version = explode('.', PHP_VERSION); define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2])); } // mPDF 5.3.79 Machine dependent number of bytes used to pack "double" into binary (used in cacheTables) $test = pack("d", 134455.474557333333666); define("_DSIZE", strlen($test)); class mPDF { /////////////////////////////// // EXTERNAL (PUBLIC) VARIABLES // Define these in config.php /////////////////////////////// var $cacheTables; // mPDF 5.3.79 var $bookmarkStyles; // mPDF 5.3.39 var $useActiveForms; var $repackageTTF; var $allowCJKorphans; var $allowCJKoverflow; var $CJKleading; var $CJKfollowing; var $CJKoverflow; var $useKerning; var $restrictColorSpace; var $bleedMargin; var $crossMarkMargin; var $cropMarkMargin; var $cropMarkLength; var $nonPrintMargin; var $PDFX; var $PDFXauto; var $PDFA; var $PDFAauto; var $ICCProfile; var $printers_info; var $iterationCounter; var $smCapsScale; var $smCapsStretch; var $backupSubsFont; var $backupSIPFont; var $debugfonts; var $useAdobeCJK; var $percentSubset; var $maxTTFFilesize; var $BMPonly; var $tableMinSizePriority; var $dpi; var $watermarkImgAlphaBlend; var $watermarkImgBehind; var $justifyB4br; var $packTableData; var $pgsIns; var $simpleTables; var $enableImports; var $debug; var $showStats; var $setAutoTopMargin; var $setAutoBottomMargin; var $autoMarginPadding; var $collapseBlockMargins; var $falseBoldWeight; var $normalLineheight; var $progressBar; var $incrementFPR1; var $incrementFPR2; var $incrementFPR3; var $incrementFPR4; var $hyphenate; var $hyphenateTables; var $SHYlang; var $SHYleftmin; var $SHYrightmin; var $SHYcharmin; var $SHYcharmax; var $SHYlanguages; // PageNumber Conditional Text var $pagenumPrefix; var $pagenumSuffix; var $nbpgPrefix; var $nbpgSuffix; var $showImageErrors; var $allow_output_buffering; var $autoPadding; var $useGraphs; var $autoFontGroupSize; var $tabSpaces; var $useLang; var $restoreBlockPagebreaks; var $watermarkTextAlpha; var $watermarkImageAlpha; var $watermark_size; var $watermark_pos; var $annotSize; var $annotMargin; var $annotOpacity; var $title2annots; var $keepColumns; var $keep_table_proportions; var $ignore_table_widths; var $ignore_table_percents; var $list_align_style; var $list_number_suffix; var $useSubstitutions; var $CSSselectMedia; var $forcePortraitHeaders; var $forcePortraitMargins; var $displayDefaultOrientation; var $ignore_invalid_utf8; var $allowedCSStags; var $onlyCoreFonts; var $allow_charset_conversion; var $jSWord; var $jSmaxChar; var $jSmaxCharLast; var $jSmaxWordLast; var $orphansAllowed; var $max_colH_correction; var $table_error_report; var $table_error_report_param; var $biDirectional; var $text_input_as_HTML; var $anchor2Bookmark; var $list_indent_first_level; var $shrink_tables_to_fit; var $allow_html_optional_endtags; var $img_dpi; var $defaultheaderfontsize; var $defaultheaderfontstyle; var $defaultheaderline; var $defaultfooterfontsize; var $defaultfooterfontstyle; var $defaultfooterline; var $header_line_spacing; var $footer_line_spacing; var $pregUHCchars; var $pregSJISchars; var $pregCJKchars; var $pregASCIIchars1; var $pregASCIIchars2; var $pregASCIIchars3; var $pregVIETchars; var $pregVIETPluschars; var $pregRTLchars; var $pregHEBchars; var $pregARABICchars; var $pregNonARABICchars; // INDIC var $pregHIchars; var $pregBNchars; var $pregPAchars; var $pregGUchars; var $pregORchars; var $pregTAchars; var $pregTEchars; var $pregKNchars; var $pregMLchars; var $pregSHchars; var $pregINDextra; var $mirrorMargins; var $default_lineheight_correction; var $watermarkText; var $watermarkImage; var $showWatermarkText; var $showWatermarkImage; var $fontsizes; // Aliases for backward compatability var $UnvalidatedText; // alias = $watermarkText var $TopicIsUnvalidated; // alias = $showWatermarkText var $useOddEven; // alias = $mirrorMargins var $useSubstitutionsMB; // alias = $useSubstitutions ////////////////////// // CLASS OBJECTS ////////////////////// // mPDF 5.3.89 var $grad; var $bmp; var $wmf; var $tocontents; var $form; var $directw; ////////////////////// // INTERNAL VARIABLES ////////////////////// var $textshadow; // mPDF 5.3.A2 var $colsums; // mPDF 5.3.92 // mPDF 5.3.61 var $spanborder; var $spanborddet; var $visibility; // mPDF 5.3.41 var $useRC128encryption; var $uniqid; var $kerning; var $fixedlSpacing; var $minwSpacing; var $lSpacingCSS; var $wSpacingCSS; var $listDir; var $spotColorIDs; var $SVGcolors; var $spotColors; var $defTextColor; var $defDrawColor; var $defFillColor; var $tableBackgrounds; var $inlineDisplayOff; var $kt_y00; var $kt_p00; var $upperCase; var $checkSIP; var $checkSMP; var $checkCJK; var $tableCJK; var $watermarkImgAlpha; var $PDFAXwarnings; var $MetadataRoot; var $OutputIntentRoot; var $InfoRoot; var $current_filename; var $parsers; var $current_parser; var $_obj_stack; var $_don_obj_stack; var $_current_obj_id; var $tpls; var $tpl; var $tplprefix; var $_res; var $pdf_version; var $noImageFile; var $lastblockbottommargin; var $baselineC; var $subPos; var $subArrMB; var $ReqFontStyle; var $tableClipPath ; var $forceExactLineheight; var $listOcc; var $fullImageHeight; var $inFixedPosBlock; // Internal flag for position:fixed block var $fixedPosBlock; // Buffer string for position:fixed block var $fixedPosBlockDepth; var $fixedPosBlockBBox; var $fixedPosBlockSave; var $maxPosL; var $maxPosR; var $loaded; var $extraFontSubsets; var $docTemplateStart; // Internal flag for page (page no. -1) that docTemplate starts on var $time0; // Classes var $indic; var $barcode; var $SHYpatterns; var $loadedSHYpatterns; var $loadedSHYdictionary; var $SHYdictionary; var $SHYdictionaryWords; var $spanbgcolorarray; var $default_font; var $list_lineheight; var $headerbuffer; var $lastblocklevelchange; var $nestedtablejustfinished; var $linebreakjustfinished; var $cell_border_dominance_L; var $cell_border_dominance_R; var $cell_border_dominance_T; var $cell_border_dominance_B; var $tbCSSlvl; var $listCSSlvl; var $table_keep_together; var $plainCell_properties; var $inherit_lineheight; var $listitemtype; var $shrin_k1; var $outerfilled; var $blockContext; var $floatDivs; var $tablecascadeCSS; var $listcascadeCSS; var $patterns; var $pageBackgrounds; var $bodyBackgroundGradient; var $bodyBackgroundImage; var $bodyBackgroundColor; var $writingHTMLheader; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block var $writingHTMLfooter; var $autoFontGroups; var $angle; var $gradients; var $kwt_Reference; var $kwt_BMoutlines; var $kwt_toc; var $tbrot_Reference; var $tbrot_BMoutlines; var $tbrot_toc; var $col_Reference; var $col_BMoutlines; var $col_toc; var $currentGraphId; var $graphs; var $floatbuffer; var $floatmargins; var $bullet; var $bulletarray; var $rtlAsArabicFarsi; // DEPRACATED var $currentLang; var $default_lang; var $default_available_fonts; var $pageTemplate; var $docTemplate; var $docTemplateContinue; var $arabGlyphs; var $arabHex; var $persianGlyphs; var $persianHex; var $arabVowels; var $arabPrevLink; var $arabNextLink; var $formobjects; // array of Form Objects for WMF var $InlineProperties; var $InlineAnnots; var $ktAnnots; var $tbrot_Annots; var $kwt_Annots; var $columnAnnots; var $columnForms; var $PageAnnots; var $pageDim; // Keep track of page wxh for orientation changes - set in _beginpage, used in _putannots var $breakpoints; var $tableLevel; var $tbctr; var $innermostTableLevel; var $saveTableCounter; var $cellBorderBuffer; var $saveHTMLFooter_height; var $saveHTMLFooterE_height; var $firstPageBoxHeader; var $firstPageBoxHeaderEven; var $firstPageBoxFooter; var $firstPageBoxFooterEven; var $page_box; var $show_marks; // crop or cross marks var $basepathIsLocal; var $use_kwt; var $kwt; var $kwt_height; var $kwt_y0; var $kwt_x0; var $kwt_buffer; var $kwt_Links; var $kwt_moved; var $kwt_saved; var $PageNumSubstitutions; var $table_borders_separate; var $base_table_properties; var $borderstyles; var $listjustfinished; var $blockjustfinished; var $orig_bMargin; var $orig_tMargin; var $orig_lMargin; var $orig_rMargin; var $orig_hMargin; var $orig_fMargin; var $pageheaders; var $pagefooters; var $pageHTMLheaders; var $pageHTMLfooters; var $saveHTMLHeader; var $saveHTMLFooter; var $HTMLheaderPageLinks; var $HTMLheaderPageAnnots; var $HTMLheaderPageForms; // See config_fonts.php for these next 5 values var $available_unifonts; var $sans_fonts; var $serif_fonts; var $mono_fonts; var $defaultSubsFont; // List of ALL available CJK fonts (incl. styles) (Adobe add-ons) hw removed var $available_CJK_fonts; var $cascadeCSS; var $HTMLHeader; var $HTMLFooter; var $HTMLHeaderE; var $HTMLFooterE; var $bufferoutput; var $showdefaultpagenos; // DEPRACATED -left for backward compatability // CJK fonts var $Big5_widths; var $GB_widths; var $SJIS_widths; var $UHC_widths; // SetProtection var $encrypted; //whether document is protected var $Uvalue; //U entry in pdf document var $Ovalue; //O entry in pdf document var $Pvalue; //P entry in pdf document var $enc_obj_id; //encryption object id var $last_rc4_key; //last RC4 key encrypted (cached for optimisation) var $last_rc4_key_c; //last RC4 computed key var $encryption_key; var $padding; //used for encryption // Bookmark var $BMoutlines; var $OutlineRoot; // INDEX var $ColActive; var $Reference; var $CurrCol; var $NbCol; var $y0; //Top ordinate of columns var $ColL; var $ColWidth; var $ColGap; // COLUMNS var $ColR; var $ChangeColumn; var $columnbuffer; var $ColDetails; var $columnLinks; var $colvAlign; // Substitutions var $substitute; // Array of substitution strings e.g. <ttz>112</ttz> var $entsearch; // Array of HTML entities (>ASCII 127) to substitute var $entsubstitute; // Array of substitution decimal unicode for the Hi entities // Default values if no style sheet offered (cf. http://www.w3.org/TR/CSS21/sample.html) var $defaultCSS; var $linemaxfontsize; var $lineheight_correction; var $lastoptionaltag; // Save current block item which HTML specifies optionsl endtag var $pageoutput; var $charset_in; var $blk; var $blklvl; var $ColumnAdjust; var $ws; // Word spacing var $HREF; var $pgwidth; var $fontlist; var $oldx; var $oldy; var $B; var $U; //underlining flag var $S; // SmallCaps flag var $I; var $tdbegin; var $table; var $cell; var $col; var $row; var $divbegin; var $divalign; var $divwidth; var $divheight; var $divrevert; var $spanbgcolor; var $spanlvl; var $listlvl; var $listnum; var $listtype; var $listoccur; var $listlist; var $listitem; var $pjustfinished; var $ignorefollowingspaces; var $SUP; var $SUB; var $SMALL; var $BIG; var $toupper; var $tolower; var $capitalize; var $dash_on; var $dotted_on; var $strike; var $CSS; var $textbuffer; var $currentfontstyle; var $currentfontfamily; var $currentfontsize; var $colorarray; var $bgcolorarray; var $internallink; var $enabledtags; var $lineheight; var $basepath; var $outlineparam; var $outline_on; var $specialcontent; var $selectoption; var $objectbuffer; // Table Rotation var $table_rotate; var $tbrot_maxw; var $tbrot_maxh; var $tablebuffer; var $tbrot_align; var $tbrot_Links; var $divbuffer; // Buffer used when keeping DIV on one page var $keep_block_together; // Keep a Block from page-break-inside: avoid var $ktLinks; // Keep-together Block links array var $ktBlock; // Keep-together Block array var $ktForms; var $ktReference; var $ktBMoutlines; var $_kttoc; var $tbrot_y0; var $tbrot_x0; var $tbrot_w; var $tbrot_h; var $mb_enc; var $directionality; var $extgstates; // Used for alpha channel - Transparency (Watermark) var $mgl; var $mgt; var $mgr; var $mgb; var $tts; var $ttz; var $tta; var $headerDetails; var $footerDetails; // Best to alter the below variables using default stylesheet above var $page_break_after_avoid; var $margin_bottom_collapse; var $list_indent; var $list_align; var $list_margin_bottom; var $default_font_size; // in pts var $original_default_font_size; // used to save default sizes when using table default var $original_default_font; var $watermark_font; var $defaultAlign; // TABLE var $defaultTableAlign; var $tablethead; var $thead_font_weight; var $thead_font_style; var $thead_font_smCaps; var $thead_valign_default; var $thead_textalign_default; var $tabletfoot; var $tfoot_font_weight; var $tfoot_font_style; var $tfoot_font_smCaps; var $tfoot_valign_default; var $tfoot_textalign_default; var $trow_text_rotate; var $cellPaddingL; var $cellPaddingR; var $cellPaddingT; var $cellPaddingB; var $table_lineheight; var $table_border_attr_set; var $table_border_css_set; var $shrin_k; // factor with which to shrink tables - used internally - do not change var $shrink_this_table_to_fit; // 0 or false to disable; value (if set) gives maximum factor to reduce fontsize var $MarginCorrection; // corrects for OddEven Margins var $margin_footer; var $margin_header; var $tabletheadjustfinished; var $usingCoreFont; var $charspacing; //Private properties FROM FPDF var $DisplayPreferences; var $outlines; var $flowingBlockAttr; var $page; //current page number var $n; //current object number var $offsets; //array of object offsets var $buffer; //buffer holding in-memory PDF var $pages; //array containing pages var $state; //current document state var $compress; //compression flag var $DefOrientation; //default orientation var $CurOrientation; //current orientation var $OrientationChanges; //array indicating orientation changes var $k; //scale factor (number of points in user unit) var $fwPt; var $fhPt; //dimensions of page format in points var $fw; var $fh; //dimensions of page format in user unit var $wPt; var $hPt; //current dimensions of page in points var $w; var $h; //current dimensions of page in user unit var $lMargin; //left margin var $tMargin; //top margin var $rMargin; //right margin var $bMargin; //page break margin var $cMarginL; //cell margin Left var $cMarginR; //cell margin Right var $cMarginT; //cell margin Left var $cMarginB; //cell margin Right var $DeflMargin; //Default left margin var $DefrMargin; //Default right margin var $x; var $y; //current position in user unit for cell positioning var $lasth; //height of last cell printed var $LineWidth; //line width in user unit var $CoreFonts; //array of standard font names var $fonts; //array of used fonts var $FontFiles; //array of font files var $images; //array of used images var $PageLinks; //array of links in pages var $links; //array of internal links var $FontFamily; //current font family var $FontStyle; //current font style var $CurrentFont; //current font info var $FontSizePt; //current font size in points var $FontSize; //current font size in user unit var $DrawColor; //commands for drawing color var $FillColor; //commands for filling color var $TextColor; //commands for text color var $ColorFlag; //indicates whether fill and text colors are different var $autoPageBreak; //automatic page breaking var $PageBreakTrigger; //threshold used to trigger page breaks var $InFooter; //flag set when processing footer var $InHTMLFooter; var $processingFooter; //flag set when processing footer - added for columns var $processingHeader; //flag set when processing header - added for columns var $ZoomMode; //zoom display mode var $LayoutMode; //layout display mode var $title; //title var $subject; //subject var $author; //author var $keywords; //keywords var $creator; //creator var $aliasNbPg; //alias for total number of pages var $aliasNbPgGp; //alias for total number of pages in page group var $aliasNbPgHex; var $aliasNbPgGpHex; var $ispre; var $outerblocktags; var $innerblocktags; // ********************************** // ********************************** // ********************************** // ********************************** // ********************************** // ********************************** // ********************************** // ********************************** // ********************************** function mPDF($mode='',$format='A4',$default_font_size=0,$default_font='',$mgl=15,$mgr=15,$mgt=16,$mgb=16,$mgh=9,$mgf=9, $orientation='P') { // mPDF 5.3.89 5.3.99 /*-- BACKGROUNDS --*/ if (!class_exists('grad', false)) { include(_MPDF_PATH.'classes/grad.php'); } if (empty($this->grad)) { $this->grad = new grad($this); } /*-- END BACKGROUNDS --*/ /*-- FORMS --*/ if (!class_exists('form', false)) { include(_MPDF_PATH.'classes/form.php'); } if (empty($this->form)) { $this->form = new form($this); } /*-- END FORMS --*/ $this->time0 = microtime(true); //Some checks $this->_dochecks(); // Set up Aliases for backwards compatability $this->UnvalidatedText =& $this->watermarkText; $this->TopicIsUnvalidated =& $this->showWatermarkText; $this->AliasNbPg =& $this->aliasNbPg; $this->AliasNbPgGp =& $this->aliasNbPgGp; $this->BiDirectional =& $this->biDirectional; $this->Anchor2Bookmark =& $this->anchor2Bookmark; $this->KeepColumns =& $this->keepColumns; $this->useOddEven =& $this->mirrorMargins; $this->useSubstitutionsMB =& $this->useSubstitutions; $this->visibility='visible'; // mPDF 5.3.41 //Initialization of properties $this->spotColors=array(); $this->spotColorIDs = array(); $this->tableBackgrounds = array(); $this->kt_y00 = ''; $this->kt_p00 = ''; $this->iterationCounter = false; $this->BMPonly = array(); $this->page=0; $this->n=2; $this->buffer=''; $this->objectbuffer = array(); $this->pages=array(); $this->OrientationChanges=array(); $this->state=0; $this->fonts=array(); $this->FontFiles=array(); $this->images=array(); $this->links=array(); $this->InFooter=false; $this->processingFooter=false; $this->processingHeader=false; $this->lasth=0; $this->FontFamily=''; $this->FontStyle=''; $this->FontSizePt=9; $this->U=false; // Small Caps $this->upperCase = array(); $this->S = false; $this->smCapsScale = 1; $this->smCapsStretch = 100; $this->defTextColor = $this->TextColor = $this->SetTColor($this->ConvertColor(0),true); $this->defDrawColor = $this->DrawColor = $this->SetDColor($this->ConvertColor(0),true); $this->defFillColor = $this->FillColor = $this->SetFColor($this->ConvertColor(255),true); //SVG color names array //http://www.w3schools.com/css/css_colornames.asp $this->SVGcolors = array('antiquewhite'=>'#FAEBD7','aqua'=>'#00FFFF','aquamarine'=>'#7FFFD4','beige'=>'#F5F5DC','black'=>'#000000', 'blue'=>'#0000FF','brown'=>'#A52A2A','cadetblue'=>'#5F9EA0','chocolate'=>'#D2691E','cornflowerblue'=>'#6495ED','crimson'=>'#DC143C', 'darkblue'=>'#00008B','darkgoldenrod'=>'#B8860B','darkgreen'=>'#006400','darkmagenta'=>'#8B008B','darkorange'=>'#FF8C00', 'darkred'=>'#8B0000','darkseagreen'=>'#8FBC8F','darkslategray'=>'#2F4F4F','darkviolet'=>'#9400D3','deepskyblue'=>'#00BFFF', 'dodgerblue'=>'#1E90FF','firebrick'=>'#B22222','forestgreen'=>'#228B22','fuchsia'=>'#FF00FF','gainsboro'=>'#DCDCDC','gold'=>'#FFD700', 'gray'=>'#808080','green'=>'#008000','greenyellow'=>'#ADFF2F','hotpink'=>'#FF69B4','indigo'=>'#4B0082','khaki'=>'#F0E68C', 'lavenderblush'=>'#FFF0F5','lemonchiffon'=>'#FFFACD','lightcoral'=>'#F08080','lightgoldenrodyellow'=>'#FAFAD2','lightgreen'=>'#90EE90', 'lightsalmon'=>'#FFA07A','lightskyblue'=>'#87CEFA','lightslategray'=>'#778899','lightyellow'=>'#FFFFE0','lime'=>'#00FF00','limegreen'=>'#32CD32', 'magenta'=>'#FF00FF','maroon'=>'#800000','mediumaquamarine'=>'#66CDAA','mediumorchid'=>'#BA55D3','mediumseagreen'=>'#3CB371', 'mediumspringgreen'=>'#00FA9A','mediumvioletred'=>'#C71585','midnightblue'=>'#191970','mintcream'=>'#F5FFFA','moccasin'=>'#FFE4B5','navy'=>'#000080', 'olive'=>'#808000','orange'=>'#FFA500','orchid'=>'#DA70D6','palegreen'=>'#98FB98', 'palevioletred'=>'#D87093','peachpuff'=>'#FFDAB9','pink'=>'#FFC0CB','powderblue'=>'#B0E0E6','purple'=>'#800080', 'red'=>'#FF0000','royalblue'=>'#4169E1','salmon'=>'#FA8072','seagreen'=>'#2E8B57','sienna'=>'#A0522D','silver'=>'#C0C0C0','skyblue'=>'#87CEEB', 'slategray'=>'#708090','springgreen'=>'#00FF7F','steelblue'=>'#4682B4','tan'=>'#D2B48C','teal'=>'#008080','thistle'=>'#D8BFD8','turquoise'=>'#40E0D0', 'violetred'=>'#D02090','white'=>'#FFFFFF','yellow'=>'#FFFF00', 'aliceblue'=>'#f0f8ff', 'azure'=>'#f0ffff', 'bisque'=>'#ffe4c4', 'blanchedalmond'=>'#ffebcd', 'blueviolet'=>'#8a2be2', 'burlywood'=>'#deb887', 'chartreuse'=>'#7fff00', 'coral'=>'#ff7f50', 'cornsilk'=>'#fff8dc', 'cyan'=>'#00ffff', 'darkcyan'=>'#008b8b', 'darkgray'=>'#a9a9a9', 'darkgrey'=>'#a9a9a9', 'darkkhaki'=>'#bdb76b', 'darkolivegreen'=>'#556b2f', 'darkorchid'=>'#9932cc', 'darksalmon'=>'#e9967a', 'darkslateblue'=>'#483d8b', 'darkslategrey'=>'#2f4f4f', 'darkturquoise'=>'#00ced1', 'deeppink'=>'#ff1493', 'dimgray'=>'#696969', 'dimgrey'=>'#696969', 'floralwhite'=>'#fffaf0', 'ghostwhite'=>'#f8f8ff', 'goldenrod'=>'#daa520', 'grey'=>'#808080', 'honeydew'=>'#f0fff0', 'indianred'=>'#cd5c5c', 'ivory'=>'#fffff0', 'lavender'=>'#e6e6fa', 'lawngreen'=>'#7cfc00', 'lightblue'=>'#add8e6', 'lightcyan'=>'#e0ffff', 'lightgray'=>'#d3d3d3', 'lightgrey'=>'#d3d3d3', 'lightpink'=>'#ffb6c1', 'lightseagreen'=>'#20b2aa', 'lightslategrey'=>'#778899', 'lightsteelblue'=>'#b0c4de', 'linen'=>'#faf0e6', 'mediumblue'=>'#0000cd', 'mediumpurple'=>'#9370db', 'mediumslateblue'=>'#7b68ee', 'mediumturquoise'=>'#48d1cc', 'mistyrose'=>'#ffe4e1', 'navajowhite'=>'#ffdead', 'oldlace'=>'#fdf5e6', 'olivedrab'=>'#6b8e23', 'orangered'=>'#ff4500', 'palegoldenrod'=>'#eee8aa', 'paleturquoise'=>'#afeeee', 'papayawhip'=>'#ffefd5', 'peru'=>'#cd853f', 'plum'=>'#dda0dd', 'rosybrown'=>'#bc8f8f', 'saddlebrown'=>'#8b4513', 'sandybrown'=>'#f4a460', 'seashell'=>'#fff5ee', 'slateblue'=>'#6a5acd', 'slategrey'=>'#708090', 'snow'=>'#fffafa', 'tomato'=>'#ff6347', 'violet'=>'#ee82ee', 'wheat'=>'#f5deb3', 'whitesmoke'=>'#f5f5f5', 'yellowgreen'=>'#9acd32'); $this->ColorFlag=false; $this->extgstates = array(); $this->mb_enc='windows-1252'; $this->directionality='ltr'; $this->defaultAlign = 'L'; $this->defaultTableAlign = 'L'; $this->fixedPosBlockSave = array(); $this->extraFontSubsets = 0; $this->SHYpatterns = array(); $this->loadedSHYdictionary = false; $this->SHYdictionary = array(); $this->SHYdictionaryWords = array(); $this->blockContext = 1; $this->floatDivs = array(); $this->DisplayPreferences=''; $this->tablecascadeCSS = array(); $this->listcascadeCSS = array(); $this->patterns = array(); // Tiling patterns used for backgrounds $this->pageBackgrounds = array(); $this->writingHTMLheader = false; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block $this->writingHTMLfooter = false; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block $this->gradients = array(); $this->kwt_Reference = array(); $this->kwt_BMoutlines = array(); $this->kwt_toc = array(); $this->tbrot_Reference = array(); $this->tbrot_BMoutlines = array(); $this->tbrot_toc = array(); $this->col_Reference = array(); $this->col_BMoutlines = array(); $this->col_toc = array(); $this->graphs = array(); $this->pgsIns = array(); $this->PDFAXwarnings = array(); $this->inlineDisplayOff = false; $this->kerning = false; $this->lSpacingCSS = ''; $this->wSpacingCSS = ''; $this->fixedlSpacing = false; $this->minwSpacing = 0; $this->baselineC = 0.35; // Baseline for text $this->noImageFile = str_replace("\\","/",dirname(__FILE__)) . '/includes/no_image.jpg'; $this->subPos = 0; $this->forceExactLineheight = false; $this->listOcc = 0; $this->normalLineheight = 1.3; // These are intended as configuration variables, and should be set in config.php - which will override these values; // set here as failsafe as will cause an error if not defined $this->incrementFPR1 = 10; $this->incrementFPR2 = 10; $this->incrementFPR3 = 10; $this->incrementFPR4 = 10; $this->fullImageHeight = false; $this->floatbuffer = array(); $this->floatmargins = array(); $this->autoFontGroups = 0; $this->formobjects=array(); // array of Form Objects for WMF $this->InlineProperties=array(); $this->InlineAnnots=array(); $this->ktAnnots=array(); $this->tbrot_Annots=array(); $this->kwt_Annots=array(); $this->columnAnnots=array(); $this->pageDim=array(); $this->breakpoints = array(); // used in columnbuffer $this->tableLevel=0; $this->tbctr=array(); // counter for nested tables at each level $this->page_box = array(); $this->show_marks = ''; // crop or cross marks $this->kwt = false; $this->kwt_height = 0; $this->kwt_y0 = 0; $this->kwt_x0 = 0; $this->kwt_buffer = array(); $this->kwt_Links = array(); $this->kwt_moved = false; $this->kwt_saved = false; $this->PageNumSubstitutions = array(); $this->base_table_properties=array(); $this->borderstyles = array('inset','groove','outset','ridge','dotted','dashed','solid','double'); $this->tbrot_align = 'C'; $this->pageheaders=array(); $this->pagefooters=array(); $this->pageHTMLheaders=array(); $this->pageHTMLfooters=array(); $this->HTMLheaderPageLinks = array(); $this->HTMLheaderPageAnnots = array(); $this->ktForms = array(); $this->HTMLheaderPageForms = array(); $this->columnForms = array(); $this->tbrotForms = array(); $this->useRC128encryption = false; $this->uniqid = ''; $this->cascadeCSS = array(); $this->bufferoutput = false; $this->encrypted=false; //whether document is protected $this->BMoutlines=array(); $this->ColActive=0; //Flag indicating that columns are on (the index is being processed) $this->Reference=array(); //Array containing the references $this->CurrCol=0; //Current column number $this->ColL = array(0); // Array of Left pos of columns - absolute - needs Margin correction for Odd-Even $this->ColR = array(0); // Array of Right pos of columns - absolute pos - needs Margin correction for Odd-Even $this->ChangeColumn = 0; $this->columnbuffer = array(); $this->ColDetails = array(); // Keeps track of some column details $this->columnLinks = array(); // Cross references PageLinks $this->substitute = array(); // Array of substitution strings e.g. <ttz>112</ttz> $this->entsearch = array(); // Array of HTML entities (>ASCII 127) to substitute $this->entsubstitute = array(); // Array of substitution decimal unicode for the Hi entities $this->lastoptionaltag = ''; $this->charset_in = ''; $this->blk = array(); $this->blklvl = 0; $this->tts = false; $this->ttz = false; $this->tta = false; $this->ispre=false; $this->checkSIP = false; $this->checkSMP = false; $this->checkCJK = false; $this->tableCJK = false; $this->headerDetails=array(); $this->footerDetails=array(); $this->page_break_after_avoid = false; $this->margin_bottom_collapse = false; $this->tablethead = 0; $this->tabletfoot = 0; $this->table_border_attr_set = 0; $this->table_border_css_set = 0; $this->shrin_k = 1.0; $this->shrink_this_table_to_fit = 0; $this->MarginCorrection = 0; $this->tabletheadjustfinished = false; $this->usingCoreFont = false; $this->charspacing=0; $this->outlines=array(); $this->autoPageBreak = true; require(_MPDF_PATH.'config.php'); // config data $this->_setPageSize($format, $orientation); $this->DefOrientation=$orientation; $this->margin_header=$mgh; $this->margin_footer=$mgf; $bmargin=$mgb; $this->DeflMargin = $mgl; $this->DefrMargin = $mgr; $this->orig_tMargin = $mgt; $this->orig_bMargin = $bmargin; $this->orig_lMargin = $this->DeflMargin; $this->orig_rMargin = $this->DefrMargin; $this->orig_hMargin = $this->margin_header; $this->orig_fMargin = $this->margin_footer; if ($this->setAutoTopMargin=='pad') { $mgt += $this->margin_header; } if ($this->setAutoBottomMargin=='pad') { $mgb += $this->margin_footer; } $this->SetMargins($this->DeflMargin,$this->DefrMargin,$mgt); // sets l r t margin //Automatic page break $this->SetAutoPageBreak($this->autoPageBreak,$bmargin); // sets $this->bMargin & PageBreakTrigger $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; //Interior cell margin (1 mm) ? not used $this->cMarginL = 1; $this->cMarginR = 1; //Line width (0.2 mm) $this->LineWidth=.567/_MPDFK; //To make the function Footer() work - replaces {nb} with page number $this->AliasNbPages(); $this->AliasNbPageGroups(); $this->aliasNbPgHex = '{nbHEXmarker}'; $this->aliasNbPgGpHex = '{nbpgHEXmarker}'; //Enable all tags as default $this->DisableTags(); //Full width display mode $this->SetDisplayMode(100); // fullwidth? 'fullpage' //Compression $this->SetCompression(true); //Set default display preferences $this->SetDisplayPreferences(''); // Font data require(_MPDF_PATH.'config_fonts.php'); // Available fonts $this->available_unifonts = array(); foreach ($this->fontdata AS $f => $fs) { if (isset($fs['R']) && $fs['R']) { $this->available_unifonts[] = $f; } if (isset($fs['B']) && $fs['B']) { $this->available_unifonts[] = $f.'B'; } if (isset($fs['I']) && $fs['I']) { $this->available_unifonts[] = $f.'I'; } if (isset($fs['BI']) && $fs['BI']) { $this->available_unifonts[] = $f.'BI'; } } $this->default_available_fonts = $this->available_unifonts; $optcore = false; $onlyCoreFonts = false; if (preg_match('/([\-+])aCJK/i',$mode, $m)) { preg_replace('/([\-+])aCJK/i','',$mode); if ($m[1]=='+') { $this->useAdobeCJK = true; } else { $this->useAdobeCJK = false; } } if (strlen($mode)==1) { if ($mode=='s') { $this->percentSubset = 100; $mode = ''; } else if ($mode=='c') { $onlyCoreFonts = true; $mode = ''; } } else if (substr($mode,-2)=='-s') { $this->percentSubset = 100; $mode = substr($mode,0,strlen($mode)-2); } else if (substr($mode,-2)=='-c') { $onlyCoreFonts = true; $mode = substr($mode,0,strlen($mode)-2); } else if (substr($mode,-2)=='-x') { $optcore = true; $mode = substr($mode,0,strlen($mode)-2); } // Autodetect if mode is a language_country string (en-GB or en_GB or en) if ((strlen($mode) == 5 && $mode != 'UTF-8') || strlen($mode) == 2) { list ($coreSuitable,$mpdf_pdf_unifonts) = GetLangOpts($mode, $this->useAdobeCJK); if ($coreSuitable && $optcore) { $onlyCoreFonts = true; } if ($mpdf_pdf_unifonts) { $this->RestrictUnicodeFonts($mpdf_pdf_unifonts); $this->default_available_fonts = $mpdf_pdf_unifonts; } $this->currentLang = $mode; $this->default_lang = $mode; } $this->onlyCoreFonts = $onlyCoreFonts; if ($this->onlyCoreFonts) { $this->setMBencoding('windows-1252'); // sets $this->mb_enc } else { $this->setMBencoding('UTF-8'); // sets $this->mb_enc } @mb_regex_encoding('UTF-8'); // mPDF 5.3.07 // required only for mb_ereg... and mb_split functions // Adobe CJK fonts $this->available_CJK_fonts = array('gb','big5','sjis','uhc','gbB','big5B','sjisB','uhcB','gbI','big5I','sjisI','uhcI', 'gbBI','big5BI','sjisBI','uhcBI'); //Standard fonts $this->CoreFonts=array('ccourier'=>'Courier','ccourierB'=>'Courier-Bold','ccourierI'=>'Courier-Oblique','ccourierBI'=>'Courier-BoldOblique', 'chelvetica'=>'Helvetica','chelveticaB'=>'Helvetica-Bold','chelveticaI'=>'Helvetica-Oblique','chelveticaBI'=>'Helvetica-BoldOblique', 'ctimes'=>'Times-Roman','ctimesB'=>'Times-Bold','ctimesI'=>'Times-Italic','ctimesBI'=>'Times-BoldItalic', 'csymbol'=>'Symbol','czapfdingbats'=>'ZapfDingbats'); $this->fontlist=array("ctimes","ccourier","chelvetica","csymbol","czapfdingbats"); // Substitutions $this->setHiEntitySubstitutions(); if ($this->onlyCoreFonts) { $this->useSubstitutions = true; $this->SetSubstitutions(); } else { $this->useSubstitutions = false; } /*-- HTML-CSS --*/ if (file_exists(_MPDF_PATH.'mpdf.css')) { $css = file_get_contents(_MPDF_PATH.'mpdf.css'); $css2 = $this->ReadDefaultCSS($css); $this->defaultCSS = $this->array_merge_recursive_unique($this->defaultCSS,$css2); } /*-- END HTML-CSS --*/ if ($default_font=='') { if ($this->onlyCoreFonts) { if (in_array(strtolower($this->defaultCSS['BODY']['FONT-FAMILY']),$this->mono_fonts)) { $default_font = 'ccourier'; } else if (in_array(strtolower($this->defaultCSS['BODY']['FONT-FAMILY']),$this->sans_fonts)) { $default_font = 'chelvetica'; } else { $default_font = 'ctimes'; } } else { $default_font = $this->defaultCSS['BODY']['FONT-FAMILY']; } } if (!$default_font_size) { $mmsize = $this->ConvertSize($this->defaultCSS['BODY']['FONT-SIZE']); $default_font_size = $mmsize*(_MPDFK); } if ($default_font) { $this->SetDefaultFont($default_font); } if ($default_font_size) { $this->SetDefaultFontSize($default_font_size); } $this->SetLineHeight(); // lineheight is in mm $this->SetFColor($this->ConvertColor(255)); $this->HREF=''; $this->oldy=-1; $this->B=0; $this->U=false; $this->S=false; $this->I=0; $this->listlvl=0; $this->listnum=0; $this->listtype=''; $this->listoccur=array(); $this->listlist=array(); $this->listitem=array(); $this->tdbegin=false; $this->table=array(); $this->cell=array(); $this->col=-1; $this->row=-1; $this->cellBorderBuffer = array(); $this->divbegin=false; $this->divalign=''; $this->divwidth=0; $this->divheight=0; $this->spanbgcolor=false; $this->divrevert=false; // mPDF 5.3.61 $this->spanborder=false; $this->spanborddet=array(); $this->blockjustfinished=false; $this->listjustfinished=false; $this->ignorefollowingspaces = true; //in order to eliminate exceeding left-side spaces $this->toupper=false; $this->tolower=false; $this->capitalize=false; $this->dash_on=false; $this->dotted_on=false; $this->SUP=false; $this->SUB=false; $this->strike=false; $this->textshadow=''; // mPDF 5.3.A2 $this->currentfontfamily=''; $this->currentfontsize=''; $this->currentfontstyle=''; $this->colorarray=array(); $this->spanbgcolorarray=array(); $this->textbuffer=array(); $this->CSS=array(); $this->internallink=array(); $this->basepath = ""; $this->SetBasePath(''); $this->outlineparam = array(); $this->outline_on = false; $this->specialcontent = ''; $this->selectoption = array(); /*-- IMPORTS --*/ $this->tpls = array(); $this->tpl = 0; $this->tplprefix = "/TPL"; $this->res = array(); if ($this->enableImports) { $this->SetImportUse(); } /*-- END IMPORTS --*/ if ($this->progressBar) { $this->StartProgressBarOutput($this->progressBar) ; } // *PROGRESS-BAR* } function _setPageSize($format, &$orientation) { //Page format if(is_string($format)) { if ($format=='') { $format = 'A4'; } $pfo = 'P'; if(preg_match('/([0-9a-zA-Z]*)-L/i',$format,$m)) { // e.g. A4-L = A4 landscape $format=$m[1]; $pfo='L'; } $format = $this->_getPageFormat($format); if (!$format) { $this->Error('Unknown page format: '.$format); } else { $orientation = $pfo; } $this->fwPt=$format[0]; $this->fhPt=$format[1]; } else { if (!$format[0] || !$format[1]) { $this->Error('Invalid page format: '.$format[0].' '.$format[1]); } $this->fwPt=$format[0]*_MPDFK; $this->fhPt=$format[1]*_MPDFK; } $this->fw=$this->fwPt/_MPDFK; $this->fh=$this->fhPt/_MPDFK; //Page orientation $orientation=strtolower($orientation); if($orientation=='p' or $orientation=='portrait') { $orientation='P'; $this->wPt=$this->fwPt; $this->hPt=$this->fhPt; } elseif($orientation=='l' or $orientation=='landscape') { $orientation='L'; $this->wPt=$this->fhPt; $this->hPt=$this->fwPt; } else $this->Error('Incorrect orientation: '.$orientation); $this->CurOrientation=$orientation; $this->w=$this->wPt/_MPDFK; $this->h=$this->hPt/_MPDFK; } function _getPageFormat($format) { switch (strtoupper($format)) { case '4A0': {$format = array(4767.87,6740.79); break;} case '2A0': {$format = array(3370.39,4767.87); break;} case 'A0': {$format = array(2383.94,3370.39); break;} case 'A1': {$format = array(1683.78,2383.94); break;} case 'A2': {$format = array(1190.55,1683.78); break;} case 'A3': {$format = array(841.89,1190.55); break;} case 'A4': default: {$format = array(595.28,841.89); break;} case 'A5': {$format = array(419.53,595.28); break;} case 'A6': {$format = array(297.64,419.53); break;} case 'A7': {$format = array(209.76,297.64); break;} case 'A8': {$format = array(147.40,209.76); break;} case 'A9': {$format = array(104.88,147.40); break;} case 'A10': {$format = array(73.70,104.88); break;} case 'B0': {$format = array(2834.65,4008.19); break;} case 'B1': {$format = array(2004.09,2834.65); break;} case 'B2': {$format = array(1417.32,2004.09); break;} case 'B3': {$format = array(1000.63,1417.32); break;} case 'B4': {$format = array(708.66,1000.63); break;} case 'B5': {$format = array(498.90,708.66); break;} case 'B6': {$format = array(354.33,498.90); break;} case 'B7': {$format = array(249.45,354.33); break;} case 'B8': {$format = array(175.75,249.45); break;} case 'B9': {$format = array(124.72,175.75); break;} case 'B10': {$format = array(87.87,124.72); break;} case 'C0': {$format = array(2599.37,3676.54); break;} case 'C1': {$format = array(1836.85,2599.37); break;} case 'C2': {$format = array(1298.27,1836.85); break;} case 'C3': {$format = array(918.43,1298.27); break;} case 'C4': {$format = array(649.13,918.43); break;} case 'C5': {$format = array(459.21,649.13); break;} case 'C6': {$format = array(323.15,459.21); break;} case 'C7': {$format = array(229.61,323.15); break;} case 'C8': {$format = array(161.57,229.61); break;} case 'C9': {$format = array(113.39,161.57); break;} case 'C10': {$format = array(79.37,113.39); break;} case 'RA0': {$format = array(2437.80,3458.27); break;} case 'RA1': {$format = array(1729.13,2437.80); break;} case 'RA2': {$format = array(1218.90,1729.13); break;} case 'RA3': {$format = array(864.57,1218.90); break;} case 'RA4': {$format = array(609.45,864.57); break;} case 'SRA0': {$format = array(2551.18,3628.35); break;} case 'SRA1': {$format = array(1814.17,2551.18); break;} case 'SRA2': {$format = array(1275.59,1814.17); break;} case 'SRA3': {$format = array(907.09,1275.59); break;} case 'SRA4': {$format = array(637.80,907.09); break;} case 'LETTER': {$format = array(612.00,792.00); break;} case 'LEGAL': {$format = array(612.00,1008.00); break;} case 'LEDGER': {$format = array(279.00,432.00); break;} // mPDF 5.3.38 case 'TABLOID': {$format = array(279.00,432.00); break;} // mPDF 5.3.38 case 'EXECUTIVE': {$format = array(521.86,756.00); break;} case 'FOLIO': {$format = array(612.00,936.00); break;} case 'B': {$format=array(362.83,561.26 ); break;} // 'B' format paperback size 128x198mm case 'A': {$format=array(314.65,504.57 ); break;} // 'A' format paperback size 111x178mm case 'DEMY': {$format=array(382.68,612.28 ); break;} // 'Demy' format paperback size 135x216mm case 'ROYAL': {$format=array(433.70,663.30 ); break;} // 'Royal' format paperback size 153x234mm default: $format = false; } return $format; } /*-- PROGRESS-BAR --*/ function StartProgressBarOutput($mode=1) { // must be relative path, or URI (not a file system path) if (!defined('_MPDF_URI')) { $this->progressBar = false; if ($this->debug) { $this->Error("You need to define _MPDF_URI to use the progress bar!"); } else return false; } $this->progressBar = $mode; if ($this->progbar_altHTML) { echo $this->progbar_altHTML; } else { echo '<html> <head> <title>mPDF File Progress</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="'._MPDF_URI.'progbar.css" /> </head> <body> <div class="main"> <div class="heading">'.$this->progbar_heading.'</div> <div class="demo"> '; if ($this->progressBar==2) { echo ' <table width="100%"><tr><td style="width: 50%;"> <span class="barheading">Writing HTML code</span> <br/> <div class="progressBar"> <div id="element1" class="innerBar">&nbsp;</div> </div> <span class="code" id="box1"></span> </td><td style="width: 50%;"> <span class="barheading">Autosizing elements</span> <br/> <div class="progressBar"> <div id="element4" class="innerBar">&nbsp;</div> </div> <span class="code" id="box4"></span> <br/><br/> <span class="barheading">Writing Tables</span> <br/> <div class="progressBar"> <div id="element7" class="innerBar">&nbsp;</div> </div> <span class="code" id="box7"></span> </td></tr> <tr><td><br /><br /></td><td></td></tr> <tr><td style="width: 50%;"> '; } echo ' <span class="barheading">Writing PDF file</span> <br/> <div class="progressBar"> <div id="element2" class="innerBar">&nbsp;</div> </div> <span class="code" id="box2"></span> '; if ($this->progressBar==2) { echo ' </td><td style="width: 50%;"> <span class="barheading">Memory usage</span> <br/> <div class="progressBar"> <div id="element5" class="innerBar">&nbsp;</div> </div> <span id="box5">0</span> '.ini_get("memory_limit").'<br /> <br/><br/> <span class="barheading">Memory usage (peak)</span> <br/> <div class="progressBar"> <div id="element6" class="innerBar">&nbsp;</div> </div> <span id="box6">0</span> '.ini_get("memory_limit").'<br /> </td></tr> </table> '; } echo ' <br/><br/> <span id="box3"></span> </div> '; } ob_flush(); flush(); } function UpdateProgressBar($el,$val,$txt='') { // $val should be a string - 5 = actual value, +15 = increment if ($this->progressBar<2) { if ($el>3) { return; } else if ($el ==1) { $el = 2; } } echo '<script type="text/javascript">'; if ($val) { echo ' document.getElementById(\'element'.$el.'\').style.width=\''.$val.'%\'; '; } if ($txt) { echo ' document.getElementById(\'box'.$el.'\').innerHTML=\''.$txt.'\'; '; } if ($this->progressBar==2) { $m = round(memory_get_usage(true)/1048576); // mPDF 5.3.72 $m2 = round(memory_get_peak_usage(true)/1048576); // mPDF 5.3.72 $mem = $m * 100 / (ini_get("memory_limit")+0); $mem2 = $m2 * 100 / (ini_get("memory_limit")+0); echo ' document.getElementById(\'element5\').style.width=\''.$mem.'%\'; '; echo ' document.getElementById(\'element6\').style.width=\''.$mem2.'%\'; '; echo ' document.getElementById(\'box5\').innerHTML=\''.$m.'MB / \'; '; echo ' document.getElementById(\'box6\').innerHTML=\''.$m2.'MB / \'; '; } echo '</script>'."\n"; ob_flush(); flush(); } /*-- END PROGRESS-BAR --*/ function RestrictUnicodeFonts($res) { // $res = array of (Unicode) fonts to restrict to: e.g. norasi|norasiB - language specific if (count($res)) { // Leave full list of available fonts if passed blank array $this->available_unifonts = $res; } else { $this->available_unifonts = $this->default_available_fonts; } if (count($this->available_unifonts) == 0) { $this->available_unifonts[] = $this->default_available_fonts[0]; } $this->available_unifonts = array_values($this->available_unifonts); } function setMBencoding($enc) { // mPDF 5.3.07 if ($this->mb_enc != $enc) { $this->mb_enc = $enc; mb_internal_encoding($this->mb_enc); } } function SetMargins($left,$right,$top) { //Set left, top and right margins $this->lMargin=$left; $this->rMargin=$right; $this->tMargin=$top; } function ResetMargins() { //ReSet left, top margins if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P' && $this->CurOrientation=='L') { if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN $this->tMargin=$this->orig_rMargin; $this->bMargin=$this->orig_lMargin; } else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS $this->tMargin=$this->orig_lMargin; $this->bMargin=$this->orig_rMargin; } $this->lMargin=$this->DeflMargin; $this->rMargin=$this->DefrMargin; $this->MarginCorrection = 0; $this->PageBreakTrigger=$this->h-$this->bMargin; } else if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN $this->lMargin=$this->DefrMargin; $this->rMargin=$this->DeflMargin; $this->MarginCorrection = $this->DefrMargin-$this->DeflMargin; } else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS $this->lMargin=$this->DeflMargin; $this->rMargin=$this->DefrMargin; if ($this->mirrorMargins) { $this->MarginCorrection = $this->DeflMargin-$this->DefrMargin; } } $this->x=$this->lMargin; } function SetLeftMargin($margin) { //Set left margin $this->lMargin=$margin; if($this->page>0 and $this->x<$margin) $this->x=$margin; } function SetTopMargin($margin) { //Set top margin $this->tMargin=$margin; } function SetRightMargin($margin) { //Set right margin $this->rMargin=$margin; } function SetAutoPageBreak($auto,$margin=0) { //Set auto page break mode and triggering margin $this->autoPageBreak=$auto; $this->bMargin=$margin; $this->PageBreakTrigger=$this->h-$margin; } function SetDisplayMode($zoom,$layout='continuous') { //Set display mode in viewer if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) $this->ZoomMode=$zoom; else $this->Error('Incorrect zoom display mode: '.$zoom); if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='twoleft' or $layout=='tworight' or $layout=='default') $this->LayoutMode=$layout; else $this->Error('Incorrect layout display mode: '.$layout); } function SetCompression($compress) { //Set page compression if(function_exists('gzcompress')) $this->compress=$compress; else $this->compress=false; } function SetTitle($title) { //Title of document // Arrives as UTF-8 $this->title = $title; } function SetSubject($subject) { //Subject of document $this->subject= $subject; } function SetAuthor($author) { //Author of document $this->author= $author; } function SetKeywords($keywords) { //Keywords of document $this->keywords= $keywords; } function SetCreator($creator) { //Creator of document $this->creator= $creator; } function SetAnchor2Bookmark($x) { $this->anchor2Bookmark = $x; } function AliasNbPages($alias='{nb}') { //Define an alias for total number of pages $this->aliasNbPg=$alias; } function AliasNbPageGroups($alias='{nbpg}') { //Define an alias for total number of pages in a group $this->aliasNbPgGp=$alias; } function SetAlpha($alpha, $bm='Normal', $return=false, $mode='B') { // alpha: real value from 0 (transparent) to 1 (opaque) // bm: blend mode, one of the following: // Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, // HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity // set alpha for stroking (CA) and non-stroking (ca) operations // mode determines F (fill) S (stroke) B (both) if (($this->PDFA || $this->PDFX) && $alpha!=1) { if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Image opacity must be 100% (Opacity changed to 100%)"; } $alpha = 1; } $a = array('BM'=>'/'.$bm); if ($mode=='F' || $mode='B') $a['ca'] = $alpha; if ($mode=='S' || $mode='B') $a['CA'] = $alpha; $gs = $this->AddExtGState($a); if ($return) { return sprintf('/GS%d gs', $gs); } else { $this->_out(sprintf('/GS%d gs', $gs)); } } function AddExtGState($parms) { $n = count($this->extgstates); // check if graphics state already exists for ($i=1; $i<=$n; $i++) { if (count($this->extgstates[$i]['parms']) == count($parms)) { $same = true; foreach($this->extgstates[$i]['parms'] AS $k=>$v) { if (!isset($parms[$k]) || $parms[$k] != $v) { $same = false; break; } } if ($same) { return $i; } } } $n++; $this->extgstates[$n]['parms'] = $parms; return $n; } // mPDF 5.3.41 function SetVisibility($v) { if (($this->PDFA || $this->PDFX) && $this->visibility!='visible') { $this->PDFAXwarnings[] = "Cannot set visibility to anything other than full when using PDFA or PDFX"; return ''; } else if (!$this->PDFA && !$this->PDFX) // mPDF 5.3.45 $this->pdf_version='1.5'; if($this->visibility!='visible') { $this->_out('EMC'); $this->hasOC = true; // mPDF 5.3.45 } if($v=='printonly') $this->_out('/OC /OC1 BDC'); elseif($v=='screenonly') $this->_out('/OC /OC2 BDC'); elseif($v=='hidden') $this->_out('/OC /OC3 BDC'); elseif($v!='visible') $this->Error('Incorrect visibility: '.$v); $this->visibility=$v; } function Error($msg) { //Fatal error header('Content-Type: text/html; charset=utf-8'); die('<B>mPDF error: </B>'.$msg); } function Open() { //Begin document if($this->state==0) $this->_begindoc(); } function Close() { if ($this->progressBar) { $this->UpdateProgressBar(2,'2','Closing last page'); } // *PROGRESS-BAR* //Terminate document if($this->state==3) return; if($this->page==0) $this->AddPage($this->CurOrientation); if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); } // *TABLES* if ($this->tablebuffer) { $this->printtablebuffer(); } // *TABLES* /*-- COLUMNS --*/ if ($this->ColActive) { $this->SetColumns(0); $this->ColActive = 0; if (count($this->columnbuffer)) { $this->printcolumnbuffer(); } } /*-- END COLUMNS --*/ if (count($this->divbuffer)) { $this->printdivbuffer(); } // BODY Backgrounds $s = ''; $s .= $this->PrintBodyBackgrounds(); $s .= $this->PrintPageBackgrounds(); $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->pages[$this->page]); $this->pageBackgrounds = array(); // mPDF 5.3.41 if($this->visibility!='visible') $this->SetVisibility('visible'); if (!$this->tocontents || !$this->tocontents->TOCmark) { //Page footer $this->InFooter=true; $this->Footer(); $this->InFooter=false; } if ($this->tocontents && ($this->tocontents->TOCmark || count($this->tocontents->m_TOC))) { $this->tocontents->insertTOC(); } // *TOC* //Close page $this->_endpage(); //Close document $this->_enddoc(); } /*-- BACKGROUNDS --*/ function _resizeBackgroundImage($imw, $imh, $cw, $ch, $resize=0, $repx, $repy) { $cw = $cw*_MPDFK; $ch = $ch*_MPDFK; if (!$resize) { return array($imw, $imh, $repx, $repy); } if ($resize==1 && $imw > $cw) { $h = $imh * $cw/$imw; $repx = false; return array($cw, $h, $repx, $repy); } else if ($resize==2 && $imh > $ch) { $w = $imw * $ch/$imh; $repy = false; return array($w, $ch, $repx, $repy); } else if ($resize==3) { $w = $imw; $h = $imh; $saverepx = $repx; if ($w > $cw) { $h = $h * $cw/$w; $w = $cw; $repx = false; } if ($h > $ch) { $w = $w * $ch/$h; $h = $ch; $repy = false; $repx = $saverepx; } return array($w, $h, $repx, $repy); } else if ($resize==4) { $h = $imh * $cw/$imw; $repx = false; return array($cw, $h, $repx, $repy); } else if ($resize==5) { $w = $imw * $ch/$imh; $repy = false; return array($w, $ch, $repx, $repy); } else if ($resize==6) { $repx = false; $repy = false; return array($cw, $ch, $repx, $repy); } return array($imw, $imh, $repx, $repy); } function SetBackground(&$properties, &$maxwidth) { if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/',$properties['BACKGROUND-IMAGE'])) { return array('gradient'=>$properties['BACKGROUND-IMAGE']); } else { $file = $properties['BACKGROUND-IMAGE']; $sizesarray = $this->Image($file,0,0,0,0,'','',false, false, false, false, true); if (isset($sizesarray['IMAGE_ID'])) { $image_id = $sizesarray['IMAGE_ID']; $orig_w = $sizesarray['WIDTH']*_MPDFK; // in user units i.e. mm $orig_h = $sizesarray['HEIGHT']*_MPDFK; // (using $this->img_dpi) if (isset($properties['BACKGROUND-IMAGE-RESOLUTION'])) { if (preg_match('/from-image/i', $properties['BACKGROUND-IMAGE-RESOLUTION']) && isset($sizesarray['set-dpi']) && $sizesarray['set-dpi']>0) { $orig_w *= $this->img_dpi / $sizesarray['set-dpi']; $orig_h *= $this->img_dpi / $sizesarray['set-dpi']; } else if (preg_match('/(\d+)dpi/i', $properties['BACKGROUND-IMAGE-RESOLUTION'], $m)) { $dpi = $m[1]; if ($dpi > 0) { $orig_w *= $this->img_dpi / $dpi; $orig_h *= $this->img_dpi / $dpi; } } } $x_repeat = true; $y_repeat = true; if (isset($properties['BACKGROUND-REPEAT'])) { if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-x') { $y_repeat = false; } if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-y') { $x_repeat = false; } } $x_pos = 0; $y_pos = 0; if (isset($properties['BACKGROUND-POSITION'])) { $ppos = preg_split('/\s+/',$properties['BACKGROUND-POSITION']); $x_pos = $ppos[0]; $y_pos = $ppos[1]; if (!stristr($x_pos ,'%') ) { $x_pos = $this->ConvertSize($x_pos ,$maxwidth,$this->FontSize); } if (!stristr($y_pos ,'%') ) { $y_pos = $this->ConvertSize($y_pos ,$maxwidth,$this->FontSize); } } if (isset($properties['BACKGROUND-IMAGE-RESIZE'])) { $resize = $properties['BACKGROUND-IMAGE-RESIZE']; } else { $resize = 0; } if (isset($properties['BACKGROUND-IMAGE-OPACITY'])) { $opacity = $properties['BACKGROUND-IMAGE-OPACITY']; } else { $opacity = 1; } return array('image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$sizesarray['itype']); } } return false; } /*-- END BACKGROUNDS --*/ function PrintBodyBackgrounds() { $s = ''; $clx = 0; $cly = 0; $clw = $this->w; $clh = $this->h; // If using bleed and trim margins in paged media if ($this->pageDim[$this->page]['outer_width_LR'] || $this->pageDim[$this->page]['outer_width_TB']) { $clx = $this->pageDim[$this->page]['outer_width_LR'] - $this->pageDim[$this->page]['bleedMargin']; $cly = $this->pageDim[$this->page]['outer_width_TB'] - $this->pageDim[$this->page]['bleedMargin']; $clw = $this->w - 2*$clx; $clh = $this->h - 2*$cly; } if ($this->bodyBackgroundColor) { $s .= 'q ' .$this->SetFColor($this->bodyBackgroundColor, true)."\n"; // mPDF 5.3.74 if ($this->bodyBackgroundColor{0}==5) { // RGBa $s .= $this->SetAlpha(ord($this->bodyBackgroundColor{4})/100, 'Normal', true, 'F')."\n"; } else if ($this->bodyBackgroundColor{0}==6) { // CMYKa $s .= $this->SetAlpha(ord($this->bodyBackgroundColor{5})/100, 'Normal', true, 'F')."\n"; } $s .= sprintf('%.3F %.3F %.3F %.3F re f Q', ($clx*_MPDFK), ($cly*_MPDFK),$clw*_MPDFK,$clh*_MPDFK)."\n"; } /*-- BACKGROUNDS --*/ if ($this->bodyBackgroundGradient) { $g = $this->grad->parseBackgroundGradient($this->bodyBackgroundGradient); if ($g) { $s .= $this->grad->Gradient($clx, $cly, $clw, $clh, (isset($g['gradtype']) ? $g['gradtype'] : null), $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true); } } if ($this->bodyBackgroundImage) { if ( $this->bodyBackgroundImage['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $this->bodyBackgroundImage['gradient'])) { $g = $this->grad->parseMozGradient( $this->bodyBackgroundImage['gradient']); if ($g) { $s .= $this->grad->Gradient($clx, $cly, $clw, $clh, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true); } } else if ($this->bodyBackgroundImage['image_id']) { // Background pattern $n = count($this->patterns)+1; // If using resize, uses TrimBox (not including the bleed) list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($this->bodyBackgroundImage['orig_w'], $this->bodyBackgroundImage['orig_h'], $clw, $clh, $this->bodyBackgroundImage['resize'], $this->bodyBackgroundImage['x_repeat'], $this->bodyBackgroundImage['y_repeat']); $this->patterns[$n] = array('x'=>$clx, 'y'=>$cly, 'w'=>$clw, 'h'=>$clh, 'pgh'=>$this->h, 'image_id'=>$this->bodyBackgroundImage['image_id'], 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$this->bodyBackgroundImage['x_pos'], 'y_pos'=>$this->bodyBackgroundImage['y_pos'], 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'itype'=>$this->bodyBackgroundImage['itype']); // mPDF 5.3.12 if (($this->bodyBackgroundImage['opacity']>0 || $this->bodyBackgroundImage['opacity']==='0') && $this->bodyBackgroundImage['opacity']<1) { $opac = $this->SetAlpha($this->bodyBackgroundImage['opacity'],'Normal',true); } else { $opac = ''; } $s .= sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, ($clx*_MPDFK), ($cly*_MPDFK),$clw*_MPDFK, $clh*_MPDFK) ."\n"; } } /*-- END BACKGROUNDS --*/ return $s; } function PrintPageBackgrounds($adjustmenty=0) { $s = ''; ksort($this->pageBackgrounds); foreach($this->pageBackgrounds AS $bl=>$pbs) { foreach ($pbs AS $pb) { // mPDF 5.3.A1 if ((!isset($pb['image_id']) && !isset($pb['gradient'])) || isset($pb['shadowonly'])) { // Background colour or boxshadow // mPDF 5.3.42 VISIBILITY if($pb['visibility']!='visible') { if($pb['visibility']=='printonly') $s .= '/OC /OC1 BDC'."\n"; else if($pb['visibility']=='screenonly') $s .= '/OC /OC2 BDC'."\n"; else if($pb['visibility']=='hidden') $s .= '/OC /OC3 BDC'."\n"; } // mPDF 5.3.A1 // Box shadow if (isset($pb['shadow']) && $pb['shadow']) { $s .= $pb['shadow']."\n"; } if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; } $s .= 'q '.$this->SetFColor($pb['col'], true)."\n"; // mPDF 5.3.74 if ($pb['col']{0}==5) { // RGBa $s .= $this->SetAlpha(ord($pb['col']{4})/100, 'Normal', true, 'F')."\n"; } else if ($pb['col']{0}==6) { // CMYKa $s .= $this->SetAlpha(ord($pb['col']{5})/100, 'Normal', true, 'F')."\n"; } $s .= sprintf('%.3F %.3F %.3F %.3F re f Q',$pb['x']*_MPDFK,($this->h-$pb['y'])*_MPDFK,$pb['w']*_MPDFK,-$pb['h']*_MPDFK)."\n"; if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; } // mPDF 5.3.42 if($pb['visibility']!='visible') $s .= 'EMC'."\n"; } } /*-- BACKGROUNDS --*/ foreach ($pbs AS $pb) { // mPDF 5.3.42 VISIBILITY if($pb['visibility']!='visible') { if($pb['visibility']=='printonly') $s .= '/OC /OC1 BDC'."\n"; else if($pb['visibility']=='screenonly') $s .= '/OC /OC2 BDC'."\n"; else if($pb['visibility']=='hidden') $s .= '/OC /OC3 BDC'."\n"; } if (isset($pb['gradient']) && $pb['gradient']) { if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; } $s .= $this->grad->Gradient($pb['x'], $pb['y'], $pb['w'], $pb['h'], $pb['gradtype'], $pb['stops'], $pb['colorspace'], $pb['coords'], $pb['extend'], true); if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; } } else if (isset($pb['image_id']) && $pb['image_id']) { // Background pattern $pb['y'] -= $adjustmenty; $pb['h'] += $adjustmenty; $n = count($this->patterns)+1; list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($pb['orig_w'], $pb['orig_h'], $pb['w'], $pb['h'], $pb['resize'], $pb['x_repeat'], $pb['y_repeat']); $this->patterns[$n] = array('x'=>$pb['x'], 'y'=>$pb['y'], 'w'=>$pb['w'], 'h'=>$pb['h'], 'pgh'=>$this->h, 'image_id'=>$pb['image_id'], 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$pb['x_pos'], 'y_pos'=>$pb['y_pos'], 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'itype'=>$pb['itype']); $x = $pb['x']*_MPDFK; $y = ($this->h - $pb['y'])*_MPDFK; $w = $pb['w']*_MPDFK; $h = -$pb['h']*_MPDFK; if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; } if ($this->writingHTMLfooter || $this->writingHTMLheader) { $iw = $pb['orig_w']/_MPDFK; $ih = $pb['orig_h']/_MPDFK; $w = $pb['w']; $h = $pb['h']; $x0 = $pb['x']; $y0 = $pb['y']; // Number to repeat if ($pb['x_repeat']) { $nx = ceil($w/$iw); } else { $nx = 1; } if ($pb['y_repeat']) { $ny = ceil($h/$ih); } else { $ny = 1; } $x_pos = $pb['x_pos']; if (stristr($x_pos ,'%') ) { $x_pos += 0; $x_pos /= 100; $x_pos = ($w * $x_pos) - ($iw * $x_pos); } $y_pos = $pb['y_pos']; if (stristr($y_pos ,'%') ) { $y_pos += 0; $y_pos /= 100; $y_pos = ($h * $y_pos) - ($ih * $y_pos); } if ($nx>1) { while($x_pos>0) { $x_pos -= $iw; } } if ($ny>1) { while($y_pos>0) { $y_pos -= $ih; } } for($xi=0;$xi<$nx;$xi++) { for($yi=0;$yi<$ny;$yi++) { $x = $x0 + $x_pos + ($iw*$xi); $y = $y0 + $y_pos + ($ih*$yi); if ($pb['opacity']>0 && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); } else { $opac = ''; } $s .= sprintf("q %s %.3F 0 0 %.3F %.3F %.3F cm /I%d Do Q", $opac,$iw*_MPDFK,$ih*_MPDFK,$x*_MPDFK,($this->h-($y+$ih))*_MPDFK,$pb['image_id']) ."\n"; } } } else { // mPDF 5.3.12 if (($pb['opacity']>0 || $pb['opacity']==='0') && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); } else { $opac = ''; } $s .= sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, $x, $y, $w, $h) ."\n"; } if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; } } // mPDF 5.3.42 VISIBILITY if($pb['visibility']!='visible') $s .= 'EMC'."\n"; } /*-- END BACKGROUNDS --*/ } return $s; } function PrintTableBackgrounds($adjustmenty=0) { $s = ''; /*-- BACKGROUNDS --*/ ksort($this->tableBackgrounds); foreach($this->tableBackgrounds AS $bl=>$pbs) { foreach ($pbs AS $pb) { if ((!isset($pb['gradient']) || !$pb['gradient']) && (!isset($pb['image_id']) || !$pb['image_id'])) { $s .= 'q '.$this->SetFColor($pb['col'], true)."\n"; // mPDF 5.3.68 // mPDF 5.3.68 // mPDF 5.3.74 if ($pb['col']{0}==5) { // RGBa $s .= $this->SetAlpha(ord($pb['col']{4})/100, 'Normal', true, 'F')."\n"; } else if ($pb['col']{0}==6) { // CMYKa $s .= $this->SetAlpha(ord($pb['col']{5})/100, 'Normal', true, 'F')."\n"; } $s .= sprintf('%.3F %.3F %.3F %.3F re %s Q',$pb['x']*_MPDFK,($this->h-$pb['y'])*_MPDFK,$pb['w']*_MPDFK,-$pb['h']*_MPDFK,'f')."\n"; // mPDF 5.3.68 } if (isset($pb['gradient']) && $pb['gradient']) { if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; } $s .= $this->grad->Gradient($pb['x'], $pb['y'], $pb['w'], $pb['h'], $pb['gradtype'], $pb['stops'], $pb['colorspace'], $pb['coords'], $pb['extend'], true); if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; } } if (isset($pb['image_id']) && $pb['image_id']) { // Background pattern $pb['y'] -= $adjustmenty; $pb['h'] += $adjustmenty; $n = count($this->patterns)+1; list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($pb['orig_w'], $pb['orig_h'], $pb['w'], $pb['h'], $pb['resize'], $pb['x_repeat'], $pb['y_repeat']); $this->patterns[$n] = array('x'=>$pb['x'], 'y'=>$pb['y'], 'w'=>$pb['w'], 'h'=>$pb['h'], 'pgh'=>$this->h, 'image_id'=>$pb['image_id'], 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$pb['x_pos'], 'y_pos'=>$pb['y_pos'], 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'itype'=>$pb['itype']); $x = $pb['x']*_MPDFK; $y = ($this->h - $pb['y'])*_MPDFK; $w = $pb['w']*_MPDFK; $h = -$pb['h']*_MPDFK; if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; } if ($pb['opacity']>0 && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); } else { $opac = ''; } $s .= sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, $x, $y, $w, $h) ."\n"; if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; } } } } /*-- END BACKGROUNDS --*/ return $s; } // Depracated - can use AddPage for all function AddPages($orientation='',$condition='', $resetpagenum='', $pagenumstyle='', $suppress='',$mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0,$pagesel='',$newformat='') { $this->AddPage($orientation,$condition,$resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue,$pagesel,$newformat); } function AddPageByArray($a) { if (!is_array($a)) { $a = array(); } // mPDF 5.3.26 $orientation = (isset($a['orientation']) ? $a['orientation'] : ''); $condition = (isset($a['condition']) ? $a['condition'] : (isset($a['type']) ? $a['type'] : '')); $resetpagenum = (isset($a['resetpagenum']) ? $a['resetpagenum'] : ''); $pagenumstyle = (isset($a['pagenumstyle']) ? $a['pagenumstyle'] : ''); $suppress = (isset($a['suppress']) ? $a['suppress'] : ''); $mgl = (isset($a['mgl']) ? $a['mgl'] : (isset($a['margin-left']) ? $a['margin-left'] : '')); $mgr = (isset($a['mgr']) ? $a['mgr'] : (isset($a['margin-right']) ? $a['margin-right'] : '')); $mgt = (isset($a['mgt']) ? $a['mgt'] : (isset($a['margin-top']) ? $a['margin-top'] : '')); $mgb = (isset($a['mgb']) ? $a['mgb'] : (isset($a['margin-bottom']) ? $a['margin-bottom'] : '')); $mgh = (isset($a['mgh']) ? $a['mgh'] : (isset($a['margin-header']) ? $a['margin-header'] : '')); $mgf = (isset($a['mgf']) ? $a['mgf'] : (isset($a['margin-footer']) ? $a['margin-footer'] : '')); $ohname = (isset($a['ohname']) ? $a['ohname'] : (isset($a['odd-header-name']) ? $a['odd-header-name'] : '')); $ehname = (isset($a['ehname']) ? $a['ehname'] : (isset($a['even-header-name']) ? $a['even-header-name'] : '')); $ofname = (isset($a['ofname']) ? $a['ofname'] : (isset($a['odd-footer-name']) ? $a['odd-footer-name'] : '')); $efname = (isset($a['efname']) ? $a['efname'] : (isset($a['even-footer-name']) ? $a['even-footer-name'] : '')); $ohvalue = (isset($a['ohvalue']) ? $a['ohvalue'] : (isset($a['odd-header-value']) ? $a['odd-header-value'] : 0)); $ehvalue = (isset($a['ehvalue']) ? $a['ehvalue'] : (isset($a['even-header-value']) ? $a['even-header-value'] : 0)); $ofvalue = (isset($a['ofvalue']) ? $a['ofvalue'] : (isset($a['odd-footer-value']) ? $a['odd-footer-value'] : 0)); $efvalue = (isset($a['efvalue']) ? $a['efvalue'] : (isset($a['even-footer-value']) ? $a['even-footer-value'] : 0)); $pagesel = (isset($a['pagesel']) ? $a['pagesel'] : (isset($a['pageselector']) ? $a['pageselector'] : '')); $newformat = (isset($a['newformat']) ? $a['newformat'] : (isset($a['sheet-size']) ? $a['sheet-size'] : '')); $this->AddPage($orientation,$condition,$resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue,$pagesel,$newformat); } function AddPage($orientation='',$condition='', $resetpagenum='', $pagenumstyle='', $suppress='',$mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0,$pagesel='',$newformat='') { /*-- CSS-FLOAT --*/ // Float DIV // Cannot do with columns on, or if any change in page orientation/margins etc. // If next page already exists - i.e background /headers and footers already written if ($this->state > 0 && $this->page < count($this->pages)) { $bak_cml = $this->cMarginL; $bak_cmr = $this->cMarginR; $bak_dw = $this->divwidth; // Paint Div Border if necessary if ($this->blklvl > 0) { $save_tr = $this->table_rotate; // *TABLES* $this->table_rotate = 0; // *TABLES* if ($this->y == $this->blk[$this->blklvl]['y0']) { $this->blk[$this->blklvl]['startpage']++; } if (($this->y > $this->blk[$this->blklvl]['y0']) || $this->flowingBlockAttr['is_table'] ) { $toplvl = $this->blklvl; } else { $toplvl = $this->blklvl-1; } $sy = $this->y; for ($bl=1;$bl<=$toplvl;$bl++) { $this->PaintDivBB('pagebottom',0,$bl); } $this->y = $sy; $this->table_rotate = $save_tr; // *TABLES* } $s = $this->PrintPageBackgrounds(); // Writes after the marker so not overwritten later by page background etc. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]); $this->pageBackgrounds = array(); $family=$this->FontFamily; $style=$this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : ''); $size=$this->FontSizePt; $lw=$this->LineWidth; $dc=$this->DrawColor; $fc=$this->FillColor; $tc=$this->TextColor; $cf=$this->ColorFlag; $this->printfloatbuffer(); //Move to next page $this->page++; $this->ResetMargins(); $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin); $this->x=$this->lMargin; $this->y=$this->tMargin; $this->FontFamily=''; $this->_out('2 J'); $this->LineWidth=$lw; $this->_out(sprintf('%.3F w',$lw*_MPDFK)); if($family) $this->SetFont($family,$style,$size,true,true); $this->DrawColor=$dc; if($dc!=$this->defDrawColor) $this->_out($dc); $this->FillColor=$fc; if($fc!=$this->defFillColor) $this->_out($fc); $this->TextColor=$tc; $this->ColorFlag=$cf; for($bl=1;$bl<=$this->blklvl;$bl++) { $this->blk[$bl]['y0'] = $this->y; // Don't correct more than once for background DIV containing a Float if (!isset($this->blk[$bl]['marginCorrected'][$this->page])) { $this->blk[$bl]['x0'] += $this->MarginCorrection; } $this->blk[$bl]['marginCorrected'][$this->page] = true; } $this->cMarginL = $bak_cml; $this->cMarginR = $bak_cmr; $this->divwidth = $bak_dw; return ''; } /*-- END CSS-FLOAT --*/ //Start a new page if($this->state==0) $this->Open(); $bak_cml = $this->cMarginL; $bak_cmr = $this->cMarginR; $bak_dw = $this->divwidth; $bak_lh = $this->lineheight; $orientation = substr(strtoupper($orientation),0,1); $condition = strtoupper($condition); if ($condition == 'NEXT-EVEN') { // always adds at least one new page to create an Even page if (!$this->mirrorMargins) { $condition = ''; } else { if ($pagesel) { $pbch = $pagesel; $pagesel = ''; } // *CSS-PAGE* else { $pbch = false; } // *CSS-PAGE* $this->AddPage($this->CurOrientation,'O'); if ($pbch ) { $pagesel = $pbch; } // *CSS-PAGE* $condition = ''; } } if ($condition == 'NEXT-ODD') { // always adds at least one new page to create an Odd page if (!$this->mirrorMargins) { $condition = ''; } else { if ($pagesel) { $pbch = $pagesel; $pagesel = ''; } // *CSS-PAGE* else { $pbch = false; } // *CSS-PAGE* $this->AddPage($this->CurOrientation,'E'); if ($pbch ) { $pagesel = $pbch; } // *CSS-PAGE* $condition = ''; } } if ($condition == 'E') { // only adds new page if needed to create an Even page if (!$this->mirrorMargins || ($this->page)%2==0) { return false; } } if ($condition == 'O') { // only adds new page if needed to create an Odd page if (!$this->mirrorMargins || ($this->page)%2==1) { return false; } } if ($resetpagenum || $pagenumstyle || $suppress) { $this->PageNumSubstitutions[] = array('from'=>($this->page+1), 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=>$suppress); } $save_tr = $this->table_rotate; // *TABLES* $this->table_rotate = 0; // *TABLES* $save_kwt = $this->kwt; $this->kwt = 0; // Paint Div Border if necessary //PAINTS BACKGROUND COLOUR OR BORDERS for DIV - DISABLED FOR COLUMNS (cf. AcceptPageBreak) AT PRESENT in ->PaintDivBB if (!$this->ColActive && $this->blklvl > 0) { if (isset($this->blk[$this->blklvl]['y0']) && $this->y == $this->blk[$this->blklvl]['y0']) { if (isset($this->blk[$this->blklvl]['startpage'])) { $this->blk[$this->blklvl]['startpage']++; } else { $this->blk[$this->blklvl]['startpage'] = 1; } } if ((isset($this->blk[$this->blklvl]['y0']) && $this->y > $this->blk[$this->blklvl]['y0']) || $this->flowingBlockAttr['is_table'] ) { $toplvl = $this->blklvl; } else { $toplvl = $this->blklvl-1; } $sy = $this->y; for ($bl=1;$bl<=$toplvl;$bl++) { $this->PaintDivBB('pagebottom',0,$bl); } $this->y = $sy; // RESET block y0 and x0 - see below } // BODY Backgrounds if ($this->page > 0) { $s = ''; $s .= $this->PrintBodyBackgrounds(); $s .= $this->PrintPageBackgrounds(); $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->pages[$this->page]); $this->pageBackgrounds = array(); } $save_kt = $this->keep_block_together; $this->keep_block_together = 0; $save_cols = false; /*-- COLUMNS --*/ if ($this->ColActive) { $save_cols = true; $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off $this->SetColumns(0); } /*-- END COLUMNS --*/ // mPDF 5.3.41 $save_vis = $this->visibility; if($this->visibility!='visible') $this->SetVisibility('visible'); $family=$this->FontFamily; $style=$this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : ''); $size=$this->FontSizePt; $this->ColumnAdjust = true; // enables column height adjustment for the page $lw=$this->LineWidth; $dc=$this->DrawColor; $fc=$this->FillColor; $tc=$this->TextColor; $cf=$this->ColorFlag; if($this->page>0) { //Page footer $this->InFooter=true; $this->Reset(); $this->pageoutput[$this->page] = array(); $this->Footer(); //Close page $this->_endpage(); } //Start new page $this->_beginpage($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); if ($this->docTemplate) { $pagecount = $this->SetSourceFile($this->docTemplate); if (($this->page - $this->docTemplateStart) > $pagecount) { if ($this->docTemplateContinue) { $tplIdx = $this->ImportPage($pagecount); $this->UseTemplate($tplIdx); } } else { $tplIdx = $this->ImportPage(($this->page - $this->docTemplateStart)); $this->UseTemplate($tplIdx); } } if ($this->pageTemplate) { $this->UseTemplate($this->pageTemplate); } // Tiling Patterns $this->_out('___PAGE___START'.date('jY')); $this->_out('___BACKGROUND___PATTERNS'.date('jY')); $this->_out('___HEADER___MARKER'.date('jY')); $this->pageBackgrounds = array(); //Set line cap style to square $this->SetLineCap(2); //Set line width $this->LineWidth=$lw; $this->_out(sprintf('%.3F w',$lw*_MPDFK)); //Set font if($family) $this->SetFont($family,$style,$size,true,true); // forces write //Set colors $this->DrawColor=$dc; if($dc!=$this->defDrawColor) $this->_out($dc); $this->FillColor=$fc; if($fc!=$this->defFillColor) $this->_out($fc); $this->TextColor=$tc; $this->ColorFlag=$cf; //Page header $this->Header(); //Restore line width if($this->LineWidth!=$lw) { $this->LineWidth=$lw; $this->_out(sprintf('%.3F w',$lw*_MPDFK)); } //Restore font if($family) $this->SetFont($family,$style,$size,true,true); // forces write //Restore colors if($this->DrawColor!=$dc) { $this->DrawColor=$dc; $this->_out($dc); } if($this->FillColor!=$fc) { $this->FillColor=$fc; $this->_out($fc); } $this->TextColor=$tc; $this->ColorFlag=$cf; $this->InFooter=false; // mPDF 5.3.41 if($save_vis!='visible') $this->SetVisibility($save_vis); /*-- COLUMNS --*/ if ($save_cols) { // Restore columns $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap); } if ($this->ColActive) { $this->SetCol(0); } /*-- END COLUMNS --*/ //RESET BLOCK BORDER TOP if (!$this->ColActive) { for($bl=1;$bl<=$this->blklvl;$bl++) { $this->blk[$bl]['y0'] = $this->y; if (isset($this->blk[$bl]['x0'])) { $this->blk[$bl]['x0'] += $this->MarginCorrection; } else { $this->blk[$bl]['x0'] = $this->MarginCorrection; } // Added mPDF 3.0 Float DIV $this->blk[$bl]['marginCorrected'][$this->page] = true; } } $this->table_rotate = $save_tr; // *TABLES* $this->kwt = $save_kwt; $this->keep_block_together = $save_kt ; $this->cMarginL = $bak_cml; $this->cMarginR = $bak_cmr; $this->divwidth = $bak_dw; $this->lineheight = $bak_lh; } function PageNo() { //Get current page number return $this->page; } function AddSpotColorsFromFile($file) { $colors = @file($file) or die("Cannot load spot colors file - ".$file); foreach($colors AS $sc) { list($name, $c, $m, $y, $k) = preg_split("/\t/",$sc); $c = intval($c); $m = intval($m); $y = intval($y); $k = intval($k); $this->AddSpotColor($name, $c, $m, $y, $k); } } function AddSpotColor($name, $c, $m, $y, $k) { $name = strtoupper(trim($name)); if(!isset($this->spotColors[$name])) { $i=count($this->spotColors)+1; $this->spotColors[$name]=array('i'=>$i,'c'=>$c,'m'=>$m,'y'=>$y,'k'=>$k); $this->spotColorIDs[$i]=$name; } } function SetColor($col, $type='') { $out = ''; // mPDF 5.3.74 if ($col{0}==3 || $col{0}==5) { // RGB / RGBa $out = sprintf('%.3F %.3F %.3F rg',ord($col{1})/255,ord($col{2})/255,ord($col{3})/255); } else if ($col{0}==1) { // GRAYSCALE $out = sprintf('%.3F g',ord($col{1})/255); } else if ($col{0}==2) { // SPOT COLOR $out = sprintf('/CS%d cs %.3F scn',ord($col{1}),ord($col{2})/100); } else if ($col{0}==4 || $col{0}==6) { // CMYK / CMYKa $out = sprintf('%.3F %.3F %.3F %.3F k', ord($col{1})/100, ord($col{2})/100, ord($col{3})/100, ord($col{4})/100); } if ($type=='Draw') { $out = strtoupper($out); } // e.g. rg => RG else if ($type=='CodeOnly') { $out = preg_replace('/\s(rg|g|k)/','',$out); } return $out; } function SetDColor($col, $return=false) { $out = $this->SetColor($col, 'Draw'); if ($return) { return $out; } if ($out=='') { return ''; } $this->DrawColor = $out; if($this->page>0 && ((isset($this->pageoutput[$this->page]['DrawColor']) && $this->pageoutput[$this->page]['DrawColor'] != $this->DrawColor) || !isset($this->pageoutput[$this->page]['DrawColor']) || $this->keep_block_together)) { $this->_out($this->DrawColor); } $this->pageoutput[$this->page]['DrawColor'] = $this->DrawColor; } function SetFColor($col, $return=false) { $out = $this->SetColor($col, 'Fill'); if ($return) { return $out; } if ($out=='') { return ''; } $this->FillColor = $out; $this->ColorFlag = ($out != $this->TextColor); if($this->page>0 && ((isset($this->pageoutput[$this->page]['FillColor']) && $this->pageoutput[$this->page]['FillColor'] != $this->FillColor) || !isset($this->pageoutput[$this->page]['FillColor']) || $this->keep_block_together)) { $this->_out($this->FillColor); } $this->pageoutput[$this->page]['FillColor'] = $this->FillColor; } function SetTColor($col, $return=false) { $out = $this->SetColor($col, 'Text'); if ($return) { return $out; } if ($out=='') { return ''; } $this->TextColor = $out; $this->ColorFlag = ($this->FillColor != $out); } function SetDrawColor($r,$g=-1,$b=-1,$col4=-1, $return=false) { //Set color for all stroking operations $col = array(); if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) { $col = $this->ConvertColor($r); } else if ($col4 == -1) { $col = $this->ConvertColor('rgb('.$r.','.$g.','.$b.')'); } else { $col = $this->ConvertColor('cmyk('.$r.','.$g.','.$b.','.$col4.')'); } $out = $this->SetDColor($col, $return); return $out; } function SetFillColor($r,$g=-1,$b=-1,$col4=-1, $return=false) { //Set color for all filling operations $col = array(); if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) { $col = $this->ConvertColor($r); } else if ($col4 == -1) { $col = $this->ConvertColor('rgb('.$r.','.$g.','.$b.')'); } else { $col = $this->ConvertColor('cmyk('.$r.','.$g.','.$b.','.$col4.')'); } $out = $this->SetFColor($col, $return); return $out; } function SetTextColor($r,$g=-1,$b=-1,$col4=-1, $return=false) { //Set color for text $col = array(); if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) { $col = $this->ConvertColor($r); } else if ($col4 == -1) { $col = $this->ConvertColor('rgb('.$r.','.$g.','.$b.')'); } else { $col = $this->ConvertColor('cmyk('.$r.','.$g.','.$b.','.$col4.')'); } $out = $this->SetTColor($col, $return); return $out; } function _getCharWidth(&$cw, $u, $isdef=true) { if ($u==0) { $w = false; } else { $w = (ord($cw[$u*2]) << 8) + ord($cw[$u*2+1]); } if ($w == 65535) { return 0; } else if ($w) { return $w; } else if ($isdef) { return false; } else { return 0; } } function _charDefined(&$cw, $u) { if ($u==0) { return false; } $w = (ord($cw[$u*2]) << 8) + ord($cw[$u*2+1]); if ($w) { return true; } else { return false; } } // mPDF 5.3.04 function GetCharWidthCore($c) { //Get width of a single character in the current Core font $c = (string)$c; $w = 0; // Soft Hyphens chr(173) if ($c == chr(173) && $this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') { return 0; // mPDF 5.3.07 } else if ($this->S && isset($this->upperCase[ord($c)])) { $charw = $this->CurrentFont['cw'][chr($this->upperCase[ord($c)])]; if ($charw!==false) { $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100; $w+=$charw; } } else if (isset($this->CurrentFont['cw'][$c])) { $w += $this->CurrentFont['cw'][$c]; } else if (isset($this->CurrentFont['cw'][ord($c)])) { $w += $this->CurrentFont['cw'][ord($c)]; } $w *= ($this->FontSize/ 1000); if ($this->minwSpacing || $this->fixedlSpacing) { if ($c==' ') $nb_spaces = 1; else $nb_spaces = 0; $w += $this->fixedlSpacing + ($nb_spaces * $this->minwSpacing); } return ($w); } // mPDF 5.3.04 function GetCharWidthNonCore($c, $addSubset=true) { //Get width of a single character in the current Non-Core font $c = (string)$c; $w = 0; $unicode = $this->UTF8StringToArray($c, $addSubset); // mPDF 5.3.06 $char = $unicode[0]; /*-- CJK-FONTS --*/ if ($this->CurrentFont['type'] == 'Type0') { // CJK Adobe fonts if ($char == 173) { return 0; } // Soft Hyphens // mPDF 5.3.07 elseif (isset($this->CurrentFont['cw'][$char])) { $w+=$this->CurrentFont['cw'][$char]; } elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; } else { $w += 500; } } else { /*-- END CJK-FONTS --*/ if ($char == 173) { return 0; } // Soft Hyphens // mPDF 5.3.07 else if ($this->S && isset($this->upperCase[$char])) { $charw = $this->_getCharWidth($this->CurrentFont['cw'],$this->upperCase[$char]); if ($charw!==false) { $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100; $w+=$charw; } elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; } elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; } else { $w += 500; } } else { $charw = $this->_getCharWidth($this->CurrentFont['cw'],$char); if ($charw!==false) { $w+=$charw; } elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; } elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; } else { $w += 500; } } } // *CJK-FONTS* $w *= ($this->FontSize/ 1000); if ($this->minwSpacing || $this->fixedlSpacing) { if ($c==' ') $nb_spaces = 1; else $nb_spaces = 0; $w += $this->fixedlSpacing + ($nb_spaces * $this->minwSpacing); } return ($w); } // mPDF 5.3.04 function GetCharWidth($c, $addSubset=true) { if (!$this->usingCoreFont) { return $this->GetCharWidthNonCore($c, $addSubset); } else { return $this->GetCharWidthCore($c); } } function GetStringWidth($s, $addSubset=true) { //Get width of a string in the current font $s = (string)$s; $cw = &$this->CurrentFont['cw']; $w = 0; $kerning = 0; $lastchar = 0; // mPDF 5.3.04 $nb_carac = 0; $nb_spaces = 0; // mPDF ITERATION if ($this->iterationCounter) $s = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/', '\\1', $s); if (!$this->usingCoreFont) { // mPDF 5.3.04 $s = str_replace("\xc2\xad",'',$s ); $unicode = $this->UTF8StringToArray($s, $addSubset); // mPDF 5.3.04 if ($this->minwSpacing || $this->fixedlSpacing) { $nb_carac = count($unicode); $nb_spaces = mb_substr_count($s,' ', $this->mb_enc); } /*-- CJK-FONTS --*/ if ($this->CurrentFont['type'] == 'Type0') { // CJK Adobe fonts foreach($unicode as $char) { if (isset($cw[$char])) { $w+=$cw[$char]; } elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; } else { $w += 500; } } } else { /*-- END CJK-FONTS --*/ foreach($unicode as $char) { if ($this->S && isset($this->upperCase[$char])) { $charw = $this->_getCharWidth($cw,$this->upperCase[$char]); if ($charw!==false) { $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100; $w+=$charw; } elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; } elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; } else { $w += 500; } } else { $charw = $this->_getCharWidth($cw,$char); if ($charw!==false) { $w+=$charw; } elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; } elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; } else { $w += 500; } if ($this->kerning && $this->useKerning && $lastchar) { if (isset($this->CurrentFont['kerninfo'][$lastchar][$char])) { $kerning += $this->CurrentFont['kerninfo'][$lastchar][$char]; } } $lastchar = $char; } } } // *CJK-FONTS* } else { // mPDF 5.3.04 if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') { $s = str_replace(chr(173),'',$s ); } $nb_carac = $l = strlen($s); // mPDF 5.3.04 if ($this->minwSpacing || $this->fixedlSpacing) { $nb_spaces = substr_count($s,' '); } for($i=0; $i<$l; $i++) { if ($this->S && isset($this->upperCase[ord($s[$i])])) { $charw = $cw[chr($this->upperCase[ord($s[$i])])]; if ($charw!==false) { $charw = $charw*$this->smCapsScale * $this->smCapsStretch/100; $w+=$charw; } } else if (isset($cw[$s[$i]])) { $w += $cw[$s[$i]]; } else if (isset($cw[ord($s[$i])])) { $w += $cw[ord($s[$i])]; } if ($this->kerning && $this->useKerning && $i>0) { // mPDF 5.3.04 if (isset($this->CurrentFont['kerninfo'][$s[($i-1)]][$s[$i]])) { $kerning += $this->CurrentFont['kerninfo'][$s[($i-1)]][$s[$i]]; } } } } unset($cw); if ($this->kerning && $this->useKerning) { $w += $kerning; } $w *= ($this->FontSize/ 1000); // mPDF 5.3.04 $w += (($nb_carac + $nb_spaces) * $this->fixedlSpacing) + ($nb_spaces * $this->minwSpacing); return ($w); } function SetLineWidth($width) { //Set line width $this->LineWidth=$width; $lwout = (sprintf('%.3F w',$width*_MPDFK)); if($this->page>0 && ((isset($this->pageoutput[$this->page]['LineWidth']) && $this->pageoutput[$this->page]['LineWidth'] != $lwout) || !isset($this->pageoutput[$this->page]['LineWidth']) || $this->keep_block_together)) { $this->_out($lwout); } $this->pageoutput[$this->page]['LineWidth'] = $lwout; } function Line($x1,$y1,$x2,$y2) { //Draw a line $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S',$x1*_MPDFK,($this->h-$y1)*_MPDFK,$x2*_MPDFK,($this->h-$y2)*_MPDFK)); } function Arrow($x1,$y1,$x2,$y2,$headsize=3,$fill='B',$angle=25) { //F == fill //S == stroke //B == stroke and fill // angle = splay of arrowhead - 1 - 89 degrees if($fill=='F') $fill='f'; elseif($fill=='FD' or $fill=='DF' or $fill=='B') $fill='B'; else $fill='S'; $a = atan2(($y2-$y1),($x2-$x1)); $b = $a + deg2rad($angle); $c = $a - deg2rad($angle); $x3 = $x2 - ($headsize* cos($b)); $y3 = $this->h-($y2 - ($headsize* sin($b))); $x4 = $x2 - ($headsize* cos($c)); $y4 = $this->h-($y2 - ($headsize* sin($c))); $x5 = $x3-($x3-$x4)/2; // mid point of base of arrowhead - to join arrow line to $y5 = $y3-($y3-$y4)/2; $s = ''; $s.=sprintf('%.3F %.3F m %.3F %.3F l S',$x1*_MPDFK,($this->h-$y1)*_MPDFK,$x5*_MPDFK,$y5*_MPDFK); $this->_out($s); $s = ''; $s.=sprintf('%.3F %.3F m %.3F %.3F l %.3F %.3F l %.3F %.3F l %.3F %.3F l ',$x5*_MPDFK,$y5*_MPDFK,$x3*_MPDFK,$y3*_MPDFK,$x2*_MPDFK,($this->h-$y2)*_MPDFK,$x4*_MPDFK,$y4*_MPDFK,$x5*_MPDFK,$y5*_MPDFK); $s.=$fill; $this->_out($s); } function Rect($x,$y,$w,$h,$style='') { //Draw a rectangle if($style=='F') $op='f'; elseif($style=='FD' or $style=='DF') $op='B'; else $op='S'; $this->_out(sprintf('%.3F %.3F %.3F %.3F re %s',$x*_MPDFK,($this->h-$y)*_MPDFK,$w*_MPDFK,-$h*_MPDFK,$op)); } function AddFont($family,$style='') { if(empty($family)) { return; } $family = strtolower($family); $style=strtoupper($style); $style=str_replace('U','',$style); if($style=='IB') $style='BI'; $fontkey = $family.$style; // check if the font has been already added if(isset($this->fonts[$fontkey])) { return; } /*-- CJK-FONTS --*/ if (in_array($family,$this->available_CJK_fonts)) { if (empty($this->Big5_widths)) { require(_MPDF_PATH . 'includes/CJKdata.php'); } $this->AddCJKFont($family); // don't need to add style return; } /*-- END CJK-FONTS --*/ if ($this->usingCoreFont) { die("mPDF Error - problem with Font management"); } $stylekey = $style; if (!$style) { $stylekey = 'R'; } if (!isset($this->fontdata[$family][$stylekey]) || !$this->fontdata[$family][$stylekey]) { die('mPDF Error - Font is not supported - '.$family.' '.$style); } $name = ''; $originalsize = 0; $sip = false; $smp = false; $haskerninfo = false; $BMPselected = false; @include(_MPDF_TTFONTDATAPATH.$fontkey.'.mtx.php'); $ttffile = ''; if (defined('_MPDF_SYSTEM_TTFONTS')) { $ttffile = _MPDF_SYSTEM_TTFONTS.$this->fontdata[$family][$stylekey]; if (!file_exists($ttffile)) { $ttffile = ''; } } if (!$ttffile) { $ttffile = _MPDF_TTFONTPATH.$this->fontdata[$family][$stylekey]; if (!file_exists($ttffile)) { die("mPDF Error - cannot find TTF TrueType font file - ".$ttffile); } } $ttfstat = stat($ttffile); if (isset($this->fontdata[$family]['TTCfontID'][$stylekey])) { $TTCfontID = $this->fontdata[$family]['TTCfontID'][$stylekey]; } else { $TTCfontID = 0; } $BMPonly = false; if (in_array($family,$this->BMPonly)) { $BMPonly = true; } $regenerate = false; if ($BMPonly && !$BMPselected) { $regenerate = true; } else if (!$BMPonly && $BMPselected) { $regenerate = true; } if ($this->useKerning && !$haskerninfo) { $regenerate = true; } if (!isset($name) || $originalsize != $ttfstat['size'] || $regenerate) { $mqr=$this->_getMQR(); if ($mqr) { set_magic_quotes_runtime(0); } if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); } $ttf = new TTFontFile(); $ttf->getMetrics($ttffile, $TTCfontID, $this->debugfonts, $BMPonly, $this->useKerning); $cw = $ttf->charWidths; $kerninfo = $ttf->kerninfo; $haskerninfo = true; $name = preg_replace('/[ ()]/','',$ttf->fullName); $sip = $ttf->sipset; $smp = $ttf->smpset; $desc= array('Ascent'=>round($ttf->ascent), 'Descent'=>round($ttf->descent), 'CapHeight'=>round($ttf->capHeight), 'Flags'=>$ttf->flags, 'FontBBox'=>'['.round($ttf->bbox[0])." ".round($ttf->bbox[1])." ".round($ttf->bbox[2])." ".round($ttf->bbox[3]).']', 'ItalicAngle'=>$ttf->italicAngle, 'StemV'=>round($ttf->stemV), 'MissingWidth'=>round($ttf->defaultWidth)); $panose = ''; if (count($ttf->panose)) { $panose = $ttf->sFamilyClass.' '.$ttf->sFamilySubClass.' '.implode(' ',$ttf->panose); } $up = round($ttf->underlinePosition); $ut = round($ttf->underlineThickness); $originalsize = $ttfstat['size']+0; $type = 'TTF'; //Generate metrics .php file $s='<?php'."\n"; $s.='$name=\''.$name."';\n"; $s.='$type=\''.$type."';\n"; $s.='$desc='.var_export($desc,true).";\n"; $s.='$up='.$up.";\n"; $s.='$ut='.$ut.";\n"; $s.='$ttffile=\''.$ttffile."';\n"; $s.='$TTCfontID=\''.$TTCfontID."';\n"; $s.='$originalsize='.$originalsize.";\n"; if ($sip) $s.='$sip=true;'."\n"; else $s.='$sip=false;'."\n"; if ($smp) $s.='$smp=true;'."\n"; else $s.='$smp=false;'."\n"; if ($BMPonly) $s.='$BMPselected=true;'."\n"; else $s.='$BMPselected=false;'."\n"; $s.='$fontkey=\''.$fontkey."';\n"; $s.='$panose=\''.$panose."';\n"; if ($this->useKerning) { $s.='$kerninfo='.var_export($kerninfo,true).";\n"; $s.='$haskerninfo=true;'."\n"; } else $s.='$haskerninfo=false;'."\n"; $s.="?>"; if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) { $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.mtx.php',"w"); fwrite($fh,$s,strlen($s)); fclose($fh); $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.cw.dat',"wb"); fwrite($fh,$cw,strlen($cw)); fclose($fh); @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cgm'); @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.z'); @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cw127.php'); @unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cw'); } else if ($this->debugfonts) { $this->Error('Cannot write to the font caching directory - '._MPDF_TTFONTDATAPATH); } unset($ttf); if ($mqr) { set_magic_quotes_runtime($mqr); } } else { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$fontkey.'.cw.dat'); } if (isset($this->fontdata[$family]['indic']) && $this->fontdata[$family]['indic']) { $indic = true; } else { $indic = false; } if (isset($this->fontdata[$family]['sip-ext']) && $this->fontdata[$family]['sip-ext']) { $sipext = $this->fontdata[$family]['sip-ext']; } else { $sipext = ''; } $i = count($this->fonts)+$this->extraFontSubsets+1; if ($sip || $smp) { $this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'panose'=>$panose, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'ttffile'=>$ttffile, 'fontkey'=>$fontkey, 'subsets'=>array(0=>range(0,127)), 'subsetfontids'=>array($i), 'used'=>false, 'indic'=>$indic, 'sip'=>$sip, 'sipext'=>$sipext, 'smp'=>$smp, 'TTCfontID' => $TTCfontID); } else { // mPDF 5.3.31 $ss = array(); for ($s=32; $s<128; $s++) { $ss[$s] = $s; } $this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'panose'=>$panose, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'ttffile'=>$ttffile, 'fontkey'=>$fontkey, 'subset'=>$ss, 'used'=>false, 'indic'=>$indic, 'sip'=>$sip, 'sipext'=>$sipext, 'smp'=>$smp, 'TTCfontID' => $TTCfontID); } if ($this->useKerning && $haskerninfo) { $this->fonts[$fontkey]['kerninfo'] = $kerninfo; } $this->FontFiles[$fontkey]=array('length1'=>$originalsize, 'type'=>"TTF", 'ttffile'=>$ttffile, 'sip'=>$sip, 'smp'=>$smp); unset($cw); } function SetFont($family,$style='',$size=0, $write=true, $forcewrite=false) { $family=strtolower($family); // mPDF 5.3.22 if (!$this->onlyCoreFonts) { if ($family == 'sans' || $family == 'sans-serif') { $family = $this->sans_fonts[0]; } if ($family == 'serif') { $family = $this->serif_fonts[0]; } if ($family == 'mono' || $family == 'monospace') { $family = $this->mono_fonts[0]; } } // mPDF 5.3.22 if (isset($this->fonttrans[$family]) && $this->fonttrans[$family]) { $family = $this->fonttrans[$family]; } if($family=='') { if ($this->FontFamily) { $family=$this->FontFamily; } else if ($this->default_font) { $family=$this->default_font; } else { $this->Error("No font or default font set!"); } } $this->ReqFontStyle = $style; // required or requested style - used later for artificial bold/italic if (($family == 'csymbol') || ($family == 'czapfdingbats') || ($family == 'ctimes') || ($family == 'ccourier') || ($family == 'chelvetica')) { if ($this->PDFA || $this->PDFX) { if ($family == 'csymbol' || $family == 'czapfdingbats') { $this->Error("Symbol and Zapfdingbats cannot be embedded in mPDF (required for PDFA1-b or PDFX/1-a)."); } if ($family == 'ctimes' || $family == 'ccourier' || $family == 'chelvetica') { if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Core Adobe font ".ucfirst($family)." cannot be embedded in mPDF, which is required for PDFA1-b or PDFX/1-a. (Embedded font will be substituted.)"; } if ($family == 'chelvetica') { $family = 'sans'; } if ($family == 'ctimes') { $family = 'serif'; } if ($family == 'ccourier') { $family = 'mono'; } } $this->usingCoreFont = false; } else { $this->usingCoreFont = true; } if($family=='csymbol' || $family=='czapfdingbats') { $style=''; } // mPDF 5.3.05 } else { $this->usingCoreFont = false; } // mPDF 5.3.05 $this->U=false; $this->S=false; if ($style) { $style=strtoupper($style); if(strpos($style,'U')!==false) { $this->U=true; $style=str_replace('U','',$style); } if(strpos($style,'S')!==false) { $this->S=true; // Small Caps if (empty($this->upperCase)) { @include(_MPDF_PATH.'includes/upperCase.php'); } // mPDF 5.3.99 $style=str_replace('S','',$style); } if ($style=='IB') $style='BI'; } if ($size==0) $size=$this->FontSizePt; $fontkey=$family.$style; $stylekey = $style; if (!$stylekey) { $stylekey = "R"; } if (!$this->onlyCoreFonts && !$this->usingCoreFont) { // mPDF 5.3.05 if(!isset($this->fonts[$fontkey]) || count($this->default_available_fonts) != count($this->available_unifonts) ) { // not already added /*-- CJK-FONTS --*/ // CJK fonts if (in_array($fontkey,$this->available_CJK_fonts)) { if(!isset($this->fonts[$fontkey])) { // already added if (empty($this->Big5_widths)) { require(_MPDF_PATH . 'includes/CJKdata.php'); } $this->AddCJKFont($family); // don't need to add style } } // Test to see if requested font/style is available - or substitute else /*-- END CJK-FONTS --*/ if (!in_array($fontkey,$this->available_unifonts)) { // If font[nostyle] exists - set it if (in_array($family,$this->available_unifonts)) { $style = ''; } // Else if only one font available - set it (assumes if only one font available it will not have a style) else if (count($this->available_unifonts) == 1) { $family = $this->available_unifonts[0]; $style = ''; } else { $found = 0; // else substitute font of similar type if (in_array($family,$this->sans_fonts)) { $i = array_intersect($this->sans_fonts,$this->available_unifonts); if (count($i)) { $i = array_values($i); // with requested style if possible if (!in_array(($i[0].$style),$this->available_unifonts)) { $style = ''; } $family = $i[0]; $found = 1; } } else if (in_array($family,$this->serif_fonts)) { $i = array_intersect($this->serif_fonts,$this->available_unifonts); if (count($i)) { $i = array_values($i); // with requested style if possible if (!in_array(($i[0].$style),$this->available_unifonts)) { $style = ''; } $family = $i[0]; $found = 1; } } else if (in_array($family,$this->mono_fonts)) { $i = array_intersect($this->mono_fonts,$this->available_unifonts); if (count($i)) { $i = array_values($i); // with requested style if possible if (!in_array(($i[0].$style),$this->available_unifonts)) { $style = ''; } $family = $i[0]; $found = 1; } } if (!$found) { // set first available font $fs = $this->available_unifonts[0]; preg_match('/^([a-z_0-9\-]+)([BI]{0,2})$/',$fs,$fas); // Allow "-" // with requested style if possible $ws = $fas[1].$style; if (in_array($ws,$this->available_unifonts)) { $family = $fas[1]; // leave $style as is } else if (in_array($fas[1],$this->available_unifonts)) { // or without style $family = $fas[1]; $style = ''; } else { // or with the style specified $family = $fas[1]; $style = $fas[2]; } } } $fontkey = $family.$style; } } // try to add font (if not already added) $this->AddFont($family, $style); //Test if font is already selected if($this->FontFamily == $family && $this->FontFamily == $this->currentfontfamily && $this->FontStyle == $style && $this->FontStyle == $this->currentfontstyle && $this->FontSizePt == $size && $this->FontSizePt == $this->currentfontsize && !$forcewrite) { return $family; } $fontkey = $family.$style; //Select it $this->FontFamily = $family; $this->FontStyle = $style; $this->FontSizePt = $size; $this->FontSize = $size / _MPDFK; $this->CurrentFont = &$this->fonts[$fontkey]; if ($write) { $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); if($this->page>0 && ((isset($this->pageoutput[$this->page]['Font']) && $this->pageoutput[$this->page]['Font'] != $fontout) || !isset($this->pageoutput[$this->page]['Font']) || $this->keep_block_together)) { $this->_out($fontout); } $this->pageoutput[$this->page]['Font'] = $fontout; } // Added - currentfont (lowercase) used in HTML2PDF $this->currentfontfamily=$family; $this->currentfontsize=$size; $this->currentfontstyle=$style.($this->U ? 'U' : '').($this->S ? 'S' : ''); $this->setMBencoding('UTF-8'); } else { // if using core fonts if ($this->PDFA || $this->PDFX) { $this->Error('Core Adobe fonts cannot be embedded in mPDF (required for PDFA1-b or PDFX/1-a) - cannot use option to use core fonts.'); } $this->setMBencoding('windows-1252'); //Test if font is already selected if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size) && !$forcewrite) { return $family; } if (!isset($this->CoreFonts[$fontkey])) { if (in_array($family,$this->serif_fonts)) { $family = 'ctimes'; } else if (in_array($family,$this->mono_fonts)) { $family = 'ccourier'; } else { $family = 'chelvetica'; } $this->usingCoreFont = true; $fontkey = $family.$style; } if(!isset($this->fonts[$fontkey])) { // STANDARD CORE FONTS if (isset($this->CoreFonts[$fontkey])) { //Load metric file $file=$family; if($family=='ctimes' || $family=='chelvetica' || $family=='ccourier') { $file.=strtolower($style); } $file.='.php'; include(_MPDF_PATH.'font/'.$file); if(!isset($cw)) { $this->Error('Could not include font metric file'); } $i=count($this->fonts)+$this->extraFontSubsets+1; $this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw); if ($this->useKerning) { $this->fonts[$fontkey]['kerninfo'] = $kerninfo; } } else { die('mPDF error - Font not defined'); } } //Test if font is already selected if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size) && !$forcewrite) { return $family; } //Select it $this->FontFamily=$family; $this->FontStyle=$style; $this->FontSizePt=$size; $this->FontSize=$size/_MPDFK; $this->CurrentFont=&$this->fonts[$fontkey]; if ($write) { $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); if($this->page>0 && ((isset($this->pageoutput[$this->page]['Font']) && $this->pageoutput[$this->page]['Font'] != $fontout) || !isset($this->pageoutput[$this->page]['Font']) || $this->keep_block_together)) { $this->_out($fontout); } $this->pageoutput[$this->page]['Font'] = $fontout; } // Added - currentfont (lowercase) used in HTML2PDF $this->currentfontfamily=$family; $this->currentfontsize=$size; $this->currentfontstyle=$style.($this->U ? 'U' : '').($this->S ? 'S' : ''); } return $family; } function SetFontSize($size,$write=true) { //Set font size in points if($this->FontSizePt==$size) return; $this->FontSizePt=$size; $this->FontSize=$size/_MPDFK; $this->currentfontsize=$size; if ($write) { $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); // Edited mPDF 3.0 if($this->page>0 && ((isset($this->pageoutput[$this->page]['Font']) && $this->pageoutput[$this->page]['Font'] != $fontout) || !isset($this->pageoutput[$this->page]['Font']) || $this->keep_block_together)) { $this->_out($fontout); } $this->pageoutput[$this->page]['Font'] = $fontout; } } function AddLink() { //Create a new internal link $n=count($this->links)+1; $this->links[$n]=array(0,0); return $n; } function SetLink($link,$y=0,$page=-1) { //Set destination of internal link if($y==-1) $y=$this->y; if($page==-1) $page=$this->page; $this->links[$link]=array($page,$y); } function Link($x,$y,$w,$h,$link) { $l = array($x*_MPDFK,$this->hPt-$y*_MPDFK,$w*_MPDFK,$h*_MPDFK,$link); if ($this->keep_block_together) { // Save to array - don't write yet $this->ktLinks[$this->page][]= $l; return; } else if ($this->table_rotate) { // *TABLES* $this->tbrot_Links[$this->page][]= $l; // *TABLES* return; // *TABLES* } // *TABLES* else if ($this->kwt) { $this->kwt_Links[$this->page][]= $l; return; } if ($this->writingHTMLheader || $this->writingHTMLfooter) { $this->HTMLheaderPageLinks[]= $l; return; } //Put a link on the page $this->PageLinks[$this->page][]= $l; // Save cross-reference to Column buffer $ref = count($this->PageLinks[$this->page])-1; // *COLUMNS* $this->columnLinks[$this->CurrCol][INTVAL($this->x)][INTVAL($this->y)] = $ref; // *COLUMNS* } function Text($x,$y,$txt) { // Output a string // Called (internally) by Watermark and _tableWrite [rotated cells] // Expects input to be mb_encoded if necessary and RTL reversed // ARTIFICIAL BOLD AND ITALIC $s = 'q '; if ($this->falseBoldWeight && strpos($this->ReqFontStyle,"B") !== false && strpos($this->FontStyle,"B") === false) { $s .= '2 Tr 1 J 1 j '; $s .= sprintf('%.3F w ',($this->FontSize/130)*_MPDFK*$this->falseBoldWeight); $tc = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG if($this->FillColor!=$tc) { $s .= $tc.' '; } // stroke (outline) = same colour as text(fill) } if (strpos($this->ReqFontStyle,"I") !== false && strpos($this->FontStyle,"I") === false) { $aix = '1 0 0.261799 1 %.3F %.3F Tm'; } else { $aix = '%.3F %.3F Td'; } if($this->ColorFlag) $s.=$this->TextColor.' '; $this->CurrentFont['used']= true; if ($this->CurrentFont['type']=='TTF' && ($this->CurrentFont['sip'] || $this->CurrentFont['smp'])) { $txt2 = str_replace(chr(194).chr(160),chr(32),$txt); $txt2 = $this->UTF8toSubset($txt2); $s.=sprintf('BT '.$aix.' %s Tj ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$txt2); } else if (!$this->usingCoreFont) { // mPDF 5.3.22 $txt2 = str_replace(chr(194).chr(160),chr(32),$txt); $this->UTF8StringToArray($txt2); // this is just to add chars to subset list if ($this->kerning && $this->useKerning) { $s .= $this->_kern($txt2, '', $aix, $x, $y); } else { //Convert string to UTF-16BE without BOM $txt2= $this->UTF8ToUTF16BE($txt2, false); $s.=sprintf('BT '.$aix.' (%s) Tj ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$this->_escape($txt2)); } } else { $txt2 = str_replace(chr(160),chr(32),$txt); if ($this->kerning && $this->useKerning) { $s .= $this->_kern($txt2, '', $aix, $x, $y); } else { $s.=sprintf('BT '.$aix.' (%s) Tj ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$this->_escape($txt2)); } } if($this->U && $txt!='') { // mPDF 5.3.34 $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG if($this->FillColor!=$c) { $s.= ' '.$c.' '; } if (isset($this->CurrentFont['up'])) { $up=$this->CurrentFont['up']; } else { $up = -100; } $adjusty = (-$up/1000* $this->FontSize); if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; } else { $ut = 60/1000* $this->FontSize; } $olw = $this->LineWidth; $s.=' '.(sprintf(' %.3F w',$ut*_MPDFK)); $s.=' '.$this->_dounderline($x,$y + $adjusty,$txt); $s.=' '.(sprintf(' %.3F w',$olw*_MPDFK)); if($this->FillColor!=$c) { $s.= ' '.$this->FillColor.' '; } } // STRIKETHROUGH // mPDF 5.3.54 if($this->strike && $txt!='') { $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG if($this->FillColor!=$c) { $s.= ' '.$c.' '; } //Superscript and Subscript Y coordinate adjustment (now for striked-through texts) if (isset($this->CurrentFont['desc']['CapHeight'])) { $ch=$this->CurrentFont['desc']['CapHeight']; } else { $ch = 700; } $adjusty = (-$ch/1000* $this->FontSize) * 0.35; if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; } else { $ut = 60/1000* $this->FontSize; } $olw = $this->LineWidth; $s.=' '.(sprintf(' %.3F w',$ut*_MPDFK)); $s.=' '.$this->_dounderline($x,$y+$adjusty,$txt); $s.=' '.(sprintf(' %.3F w',$olw*_MPDFK)); if($this->FillColor!=$c) { $s.= ' '.$this->FillColor.' '; } } $s .= 'Q'; $this->_out($s); } /*-- DIRECTW --*/ function WriteText($x,$y,$txt) { // Output a string using Text() but does encoding and text reversing of RTL $txt = $this->purify_utf8_text($txt); if ($this->text_input_as_HTML) { $txt = $this->all_entities_to_utf8($txt); } if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); } // mPDF 5.3.22 // DIRECTIONALITY if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL* $this->magic_reverse_dir($txt, true, $this->directionality); // *RTL* // Font-specific ligature substitution for Indic fonts if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($txt); // *INDIC* $this->Text($x,$y,$txt); } function WriteCell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='', $currentx=0) { //Output a cell using Cell() but does encoding and text reversing of RTL $txt = $this->purify_utf8_text($txt); if ($this->text_input_as_HTML) { $txt = $this->all_entities_to_utf8($txt); } if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); } // mPDF 5.3.07 // mPDF 5.3.22 // DIRECTIONALITY if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL* $this->magic_reverse_dir($txt, true, $this->directionality); // *RTL* // Font-specific ligature substitution for Indic fonts if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($txt); // *INDIC* $this->Cell($w,$h,$txt,$border,$ln,$align,$fill,$link, $currentx); } /*-- END DIRECTW --*/ function ResetSpacing() { if ($this->ws != 0) { $this->_out('BT 0 Tw ET'); } $this->ws=0; if ($this->charspacing != 0) { $this->_out('BT 0 Tc ET'); } $this->charspacing=0; } function SetSpacing($cs,$ws) { if (intval($cs*1000)==0) { $cs = 0; } if ($cs) { $this->_out(sprintf('BT %.3F Tc ET',$cs)); } else if ($this->charspacing != 0) { $this->_out('BT 0 Tc ET'); } $this->charspacing=$cs; if (intval($ws*1000)==0) { $ws = 0; } if ($ws) { $this->_out(sprintf('BT %.3F Tw ET',$ws)); } else if ($this->ws != 0) { $this->_out('BT 0 Tw ET'); } $this->ws=$ws; } // WORD SPACING function GetJspacing($nc,$ns,$w,$inclCursive) { $ws = 0; $charspacing = 0; $ww = $this->jSWord; $ncx = $nc-1; if ($nc == 0) { return array(0,0); } else if ($nc==1) { $charspacing = $w; } // Only word spacing allowed / possible else if ($this->fixedlSpacing !== false || $inclCursive) { if ($ns) { $ws = $w / $ns; } } else if (!$ns) { $charspacing = $w / ($ncx ); if (($this->jSmaxChar > 0) && ($charspacing > $this->jSmaxChar)) { $charspacing = $this->jSmaxChar; } } else if ($ns == ($ncx )) { $charspacing = $w / $ns; } else { if ($this->usingCoreFont) { $cs = ($w * (1 - $this->jSWord)) / ($ncx ); if (($this->jSmaxChar > 0) && ($cs > $this->jSmaxChar)) { $cs = $this->jSmaxChar; $ww = 1 - (($cs * ($ncx ))/$w); } $charspacing = $cs; $ws = ($w * ($ww) ) / $ns; } else { $cs = ($w * (1 - $this->jSWord)) / ($ncx -$ns); if (($this->jSmaxChar > 0) && ($cs > $this->jSmaxChar)) { $cs = $this->jSmaxChar; $ww = 1 - (($cs * ($ncx -$ns))/$w); } $charspacing = $cs; $ws = (($w * ($ww) ) / $ns) - $charspacing; } } return array($charspacing,$ws); } function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='', $currentx=0, $lcpaddingL=0, $lcpaddingR=0, $valign='M', $spanfill=0, $abovefont=0, $belowfont=0, $exactWidth=false) { // mPDF 5.3.07 //Output a cell // Expects input to be mb_encoded if necessary and RTL reversed // NON_BREAKING SPACE if ($this->usingCoreFont) { $txt = str_replace(chr(160),chr(32),$txt); } else { $txt = str_replace(chr(194).chr(160),chr(32),$txt); } $oldcolumn = $this->CurrCol; // Automatic page break // Allows PAGE-BREAK-AFTER = avoid to work if (!$this->tableLevel && (($this->y+$this->divheight>$this->PageBreakTrigger) || ($this->y+$h>$this->PageBreakTrigger) || ($this->y+($h*2)>$this->PageBreakTrigger && $this->blk[$this->blklvl]['page_break_after_avoid'])) and !$this->InFooter and $this->AcceptPageBreak()) { $x=$this->x;//Current X position // WORD SPACING $ws=$this->ws;//Word Spacing $charspacing=$this->charspacing;//Character Spacing $this->ResetSpacing(); $this->AddPage($this->CurOrientation); // Added to correct for OddEven Margins $x += $this->MarginCorrection; if ($currentx) { $currentx += $this->MarginCorrection; } $this->x=$x; // WORD SPACING $this->SetSpacing($charspacing,$ws); } // Test: to put line through centre of cell: $this->Line($this->x,$this->y+($h/2),$this->x+50,$this->y+($h/2)); /*-- COLUMNS --*/ // COLS // COLUMN CHANGE if ($this->CurrCol != $oldcolumn) { if ($currentx) { $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap); } $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap); } // COLUMNS Update/overwrite the lowest bottom of printing y value for a column if ($this->ColActive) { if ($h) { $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$h; } else { $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$this->divheight; } } /*-- END COLUMNS --*/ // KEEP BLOCK TOGETHER Update/overwrite the lowest bottom of printing y value on first page if ($this->keep_block_together) { if ($h) { $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$h; } // else { $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$this->divheight; } } if($w==0) $w = $this->w-$this->rMargin-$this->x; $s=''; if($fill==1 && $this->FillColor) { if((isset($this->pageoutput[$this->page]['FillColor']) && $this->pageoutput[$this->page]['FillColor'] != $this->FillColor) || !isset($this->pageoutput[$this->page]['FillColor']) || $this->keep_block_together) { $s .= $this->FillColor.' '; } $this->pageoutput[$this->page]['FillColor'] = $this->FillColor; } $boxtop = $this->y; $boxheight = $h; $boxbottom = $this->y+$h; if($txt!='') { // FONT SIZE - this determines the baseline caculation if ($this->linemaxfontsize && !$this->processingHeader) { $bfs = $this->linemaxfontsize; } else { $bfs = $this->FontSize; } //Calculate baseline Superscript and Subscript Y coordinate adjustment $bfx = $this->baselineC; $baseline = $bfx*$bfs; if($this->SUP) { $baseline += ($bfx-1.05)*$this->FontSize; } else if($this->SUB) { $baseline += ($bfx + 0.04)*$this->FontSize; } else if($this->bullet) { $baseline += ($bfx-0.7)*$this->FontSize; } // Vertical align (for Images) if ($abovefont || $belowfont) { // from flowing block - valign always M $va = $abovefont + (0.5*$bfs); } else if ($this->lineheight_correction) { if ($valign == 'T') { $va = (0.5 * $bfs * $this->lineheight_correction); } else if ($valign == 'B') { $va = $h-(0.5 * $bfs * $this->lineheight_correction); } else { $va = 0.5*$h; } // Middle } else { if ($valign == 'T') { $va = (0.5 * $bfs * $this->default_lineheight_correction); } else if ($valign == 'B') { $va = $h-(0.5 * $bfs * $this->default_lineheight_correction); } else { $va = 0.5*$h; } // Middle } // ONLY SET THESE IF WANT TO CONFINE BORDER +/- FILL TO FIT FONTSIZE - NOT FULL CELL AS IS ORIGINAL FUNCTION // spanfill or spanborder are set in FlowingBlock functions // mPDF 5.3.52 if ($spanfill || !empty($this->spanborddet) || $link!='') { // mPDF 5.3.71 $exth = 0.2; // Add to fontsize to increase height of background / link / border $boxtop = $this->y+$baseline+$va-($this->FontSize*(1+$exth/2)*(0.5+$bfx)); $boxheight = $this->FontSize * (1+$exth); $boxbottom = $boxtop + $boxheight; } } // mPDF 5.3.61 $bbw = $tbw = $lbw = $rbw = 0; // Border widths if (!empty($this->spanborddet)) { // mPDF 5.3.76 if (!isset($this->spanborddet['B'])) { $this->spanborddet['B'] = array('s' => 0, 'style' => '', 'w' => 0); } if (!isset($this->spanborddet['T'])) { $this->spanborddet['T'] = array('s' => 0, 'style' => '', 'w' => 0); } if (!isset($this->spanborddet['L'])) { $this->spanborddet['L'] = array('s' => 0, 'style' => '', 'w' => 0); } if (!isset($this->spanborddet['R'])) { $this->spanborddet['R'] = array('s' => 0, 'style' => '', 'w' => 0); } // mPDF 5.3.61 $bbw = $this->spanborddet['B']['w']; $tbw = $this->spanborddet['T']['w']; $lbw = $this->spanborddet['L']['w']; $rbw = $this->spanborddet['R']['w']; } if($fill==1 || $border==1 || !empty($this->spanborddet)) { // mPDF 5.3.61 // mPDF 5.3.61 if (!empty($this->spanborddet)) { if ($fill==1) { $s.=sprintf('%.3F %.3F %.3F %.3F re f ',($this->x-$lbw)*_MPDFK,($this->h-$boxtop+$tbw)*_MPDFK,($w+$lbw+$rbw)*_MPDFK,(-$boxheight-$tbw-$bbw)*_MPDFK); } $s.= ' q '; $dashon = 3; $dashoff = 3.5; $dot = 2.5; if($tbw) { // mPDF 5.3.76 $short = 0; if ($this->spanborddet['T']['style'] == 'dashed') { $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$tbw*$dashon*_MPDFK,$tbw*$dashoff*_MPDFK); } else if ($this->spanborddet['T']['style'] == 'dotted') { $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$tbw*$dot*_MPDFK,-$tbw/2*_MPDFK); $short = $tbw/2; } else { $s.=' 0 j 0 J [] 0 d '; } $c = $this->SetDColor($this->spanborddet['T']['c'],true); if ($this->spanborddet['T']['style'] == 'double') { $s.=sprintf(' %s %.3F w ',$c,$tbw/3*_MPDFK); $xadj = $xadj2 = 0; if ($this->spanborddet['L']['style'] == 'double') { $xadj = $this->spanborddet['L']['w']*2/3; } if ($this->spanborddet['R']['style'] == 'double') { $xadj2 = $this->spanborddet['R']['w']*2/3; } $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw)*_MPDFK,($this->h-$boxtop+$tbw*5/6)*_MPDFK,($this->x+$w+$rbw-$short)*_MPDFK,($this->h-$boxtop+$tbw*5/6)*_MPDFK); $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw+$xadj)*_MPDFK,($this->h-$boxtop+$tbw/6)*_MPDFK,($this->x+$w+$rbw-$short-$xadj2)*_MPDFK,($this->h-$boxtop+$tbw/6)*_MPDFK); } else { $s.=sprintf(' %s %.3F w ',$c,$tbw*_MPDFK); $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw)*_MPDFK,($this->h-$boxtop+$tbw/2)*_MPDFK,($this->x+$w+$rbw-$short)*_MPDFK,($this->h-$boxtop+$tbw/2)*_MPDFK); } } if($bbw) { // mPDF 5.3.76 $short = 0; if ($this->spanborddet['B']['style'] == 'dashed') { $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$bbw*$dashon*_MPDFK,$bbw*$dashoff*_MPDFK); } else if ($this->spanborddet['B']['style'] == 'dotted') { $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$bbw*$dot*_MPDFK,-$bbw/2*_MPDFK); $short = $bbw/2; } else { $s.=' 0 j 0 J [] 0 d '; } $c = $this->SetDColor($this->spanborddet['B']['c'],true); if ($this->spanborddet['B']['style'] == 'double') { $s.=sprintf(' %s %.3F w ',$c,$bbw/3*_MPDFK); $xadj = $xadj2 = 0; if ($this->spanborddet['L']['style'] == 'double') { $xadj = $this->spanborddet['L']['w']*2/3; } if ($this->spanborddet['R']['style'] == 'double') { $xadj2 = $this->spanborddet['R']['w']*2/3; } $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw+$xadj)*_MPDFK,($this->h-$boxbottom-$bbw/6)*_MPDFK,($this->x+$w+$rbw-$short-$xadj2)*_MPDFK,($this->h-$boxbottom-$bbw/6)*_MPDFK); $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw)*_MPDFK,($this->h-$boxbottom-$bbw*5/6)*_MPDFK,($this->x+$w+$rbw-$short)*_MPDFK,($this->h-$boxbottom-$bbw*5/6)*_MPDFK); } else { $s.=sprintf(' %s %.3F w ',$c,$bbw*_MPDFK); $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw)*_MPDFK,($this->h-$boxbottom-$bbw/2)*_MPDFK,($this->x+$w+$rbw-$short)*_MPDFK,($this->h-$boxbottom-$bbw/2)*_MPDFK); } } if($lbw) { // mPDF 5.3.76 $short = 0; if ($this->spanborddet['L']['style'] == 'dashed') { $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$lbw*$dashon*_MPDFK,$lbw*$dashoff*_MPDFK); } else if ($this->spanborddet['L']['style'] == 'dotted') { $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$lbw*$dot*_MPDFK,-$lbw/2*_MPDFK); $short = $lbw/2; } else { $s.=' 0 j 0 J [] 0 d '; } $c = $this->SetDColor($this->spanborddet['L']['c'],true); if ($this->spanborddet['L']['style'] == 'double') { $s.=sprintf(' %s %.3F w ',$c,$lbw/3*_MPDFK); $yadj = $yadj2 = 0; if ($this->spanborddet['T']['style'] == 'double') { $yadj = $this->spanborddet['T']['w']*2/3; } if ($this->spanborddet['B']['style'] == 'double') { $yadj2 = $this->spanborddet['B']['w']*2/3; } $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw/6)*_MPDFK,($this->h-$boxtop+$tbw-$yadj)*_MPDFK,($this->x-$lbw/6)*_MPDFK,($this->h-$boxbottom-$bbw+$short+$yadj2)*_MPDFK); $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw*5/6)*_MPDFK,($this->h-$boxtop+$tbw)*_MPDFK,($this->x-$lbw*5/6)*_MPDFK,($this->h-$boxbottom-$bbw+$short)*_MPDFK); } else { $s.=sprintf(' %s %.3F w ',$c,$lbw*_MPDFK); $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x-$lbw/2)*_MPDFK,($this->h-$boxtop+$tbw)*_MPDFK,($this->x-$lbw/2)*_MPDFK,($this->h-$boxbottom-$bbw+$short)*_MPDFK); } } if($rbw) { // mPDF 5.3.76 $short = 0; if ($this->spanborddet['R']['style'] == 'dashed') { $s.=sprintf(' 0 j 0 J [%.3F %.3F] 0 d ',$rbw*$dashon*_MPDFK,$rbw*$dashoff*_MPDFK); } else if ($this->spanborddet['R']['style'] == 'dotted') { $s.=sprintf(' 1 j 1 J [%.3F %.3F] %.3F d ',0.001,$rbw*$dot*_MPDFK,-$rbw/2*_MPDFK); $short = $rbw/2; } else { $s.=' 0 j 0 J [] 0 d '; } $c = $this->SetDColor($this->spanborddet['R']['c'],true); if ($this->spanborddet['R']['style'] == 'double') { $s.=sprintf(' %s %.3F w ',$c,$rbw/3*_MPDFK); $yadj = $yadj2 = 0; if ($this->spanborddet['T']['style'] == 'double') { $yadj = $this->spanborddet['T']['w']*2/3; } if ($this->spanborddet['B']['style'] == 'double') { $yadj2 = $this->spanborddet['B']['w']*2/3; } $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x+$w+$rbw/6)*_MPDFK,($this->h-$boxtop+$tbw-$yadj)*_MPDFK,($this->x+$w+$rbw/6)*_MPDFK,($this->h-$boxbottom-$bbw+$short+$yadj2)*_MPDFK); $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x+$w+$rbw*5/6)*_MPDFK,($this->h-$boxtop+$tbw)*_MPDFK,($this->x+$w+$rbw*5/6)*_MPDFK,($this->h-$boxbottom-$bbw+$short)*_MPDFK); } else { $s.=sprintf(' %s %.3F w ',$c,$rbw*_MPDFK); $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($this->x+$w+$rbw/2)*_MPDFK,($this->h-$boxtop+$tbw)*_MPDFK,($this->x+$w+$rbw/2)*_MPDFK,($this->h-$boxbottom-$bbw+$short)*_MPDFK); } } $s.= ' Q '; } else { if ($fill==1) $op=($border==1) ? 'B' : 'f'; else $op='S'; $s.=sprintf('%.3F %.3F %.3F %.3F re %s ',$this->x*_MPDFK,($this->h-$boxtop)*_MPDFK,$w*_MPDFK,-$boxheight*_MPDFK,$op); } } if(is_string($border)) { $x=$this->x; $y=$this->y; if(is_int(strpos($border,'L'))) $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',$x*_MPDFK,($this->h-$boxtop)*_MPDFK,$x*_MPDFK,($this->h-($boxbottom))*_MPDFK); if(is_int(strpos($border,'T'))) $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',$x*_MPDFK,($this->h-$boxtop)*_MPDFK,($x+$w)*_MPDFK,($this->h-$boxtop)*_MPDFK); if(is_int(strpos($border,'R'))) $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',($x+$w)*_MPDFK,($this->h-$boxtop)*_MPDFK,($x+$w)*_MPDFK,($this->h-($boxbottom))*_MPDFK); if(is_int(strpos($border,'B'))) $s.=sprintf('%.3F %.3F m %.3F %.3F l S ',$x*_MPDFK,($this->h-($boxbottom))*_MPDFK,($x+$w)*_MPDFK,($this->h-($boxbottom))*_MPDFK); } if($txt!='') { if ($exactWidth) // mPDF 5.3.07 $stringWidth = $w; else // mPDF 5.3.07 // mPDF 5.3.20 $stringWidth = $this->GetStringWidth($txt) + ( $this->charspacing * mb_strlen( $txt, $this->mb_enc ) / _MPDFK ) + ( $this->ws * mb_substr_count( $txt, ' ', $this->mb_enc ) / _MPDFK ); // Set x OFFSET FOR PRINTING if($align=='R') { $dx=$w-$this->cMarginR - $stringWidth - $lcpaddingR; } elseif($align=='C') { $dx=(($w - $stringWidth )/2); } elseif($align=='L' or $align=='J') $dx=$this->cMarginL + $lcpaddingL; else $dx = 0; if($this->ColorFlag) $s .='q '.$this->TextColor.' '; // OUTLINE if($this->outline_on && !$this->S) { $s .=' '.sprintf('%.3F w',$this->LineWidth*_MPDFK).' '; $s .=" $this->DrawColor "; $s .=" 2 Tr "; } else if ($this->falseBoldWeight && strpos($this->ReqFontStyle,"B") !== false && strpos($this->FontStyle,"B") === false && !$this->S) { // can't use together with OUTLINE or Small Caps $s .= ' 2 Tr 1 J 1 j '; $s .= ' '.sprintf('%.3F w',($this->FontSize/130)*_MPDFK*$this->falseBoldWeight).' '; $tc = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG if($this->FillColor!=$tc) { $s .= ' '.$tc.' '; } // stroke (outline) = same colour as text(fill) } if (strpos($this->ReqFontStyle,"I") !== false && strpos($this->FontStyle,"I") === false) { // Artificial italic $aix = '1 0 0.261799 1 %.3F %.3F Tm '; } else { $aix = '%.3F %.3F Td '; } // THE TEXT // mPDF 5.3.A2 Capture in substring $sub $sub = ''; $this->CurrentFont['used']= true; // WORD SPACING // IF multibyte - Tw has no effect - need to use alternative method - do word spacing using an adjustment before each space if ($this->ws && !$this->usingCoreFont && !$this->CurrentFont['sip'] && !$this->CurrentFont['smp'] && !$this->S) { $sub .= ' BT 0 Tw ET '; if ($this->kerning && $this->useKerning) { $sub .= $this->_kern($txt, 'MBTw', $aix, ($this->x+$dx), ($this->y+$baseline+$va)); } else { $space = " "; //Convert string to UTF-16BE without BOM $space= $this->UTF8ToUTF16BE($space , false); $space=$this->_escape($space ); $sub .=sprintf('BT '.$aix,($this->x+$dx)*_MPDFK,($this->h-($this->y+$baseline+$va))*_MPDFK); $t = explode(' ',$txt); $sub .=sprintf(' %.3F Tc [',$this->charspacing); $numt = count($t); // mPDF 5.3.07 for($i=0;$i<$numt;$i++) { // mPDF 5.3.07 $tx = $t[$i]; //Convert string to UTF-16BE without BOM $tx = $this->UTF8ToUTF16BE($tx , false); $tx = $this->_escape($tx); $sub .=sprintf('(%s) ',$tx); if (($i+1)<$numt) { // mPDF 5.3.07 $adj = -($this->ws)*1000/$this->FontSizePt; $sub .=sprintf('%d(%s) ',$adj,$space); } } $sub .='] TJ '; $sub .=' ET'; } } else { $txt2= $txt; if ($this->CurrentFont['type']=='TTF' && ($this->CurrentFont['sip'] || $this->CurrentFont['smp'])) { if ($this->S) { $sub .= $this->_smallCaps($txt2, 'SIPSMP', $aix, $dx, _MPDFK, $baseline, $va); } else { $txt2 = $this->UTF8toSubset($txt2); $sub .=sprintf('BT '.$aix.' %s Tj ET',($this->x+$dx)*_MPDFK,($this->h-($this->y+$baseline+$va))*_MPDFK,$txt2); } } else { if ($this->S) { $sub .= $this->_smallCaps($txt2, '', $aix, $dx, _MPDFK, $baseline, $va); } else if ($this->kerning && $this->useKerning) { $sub .= $this->_kern($txt2, '', $aix, ($this->x+$dx), ($this->y+$baseline+$va)); } else { if (!$this->usingCoreFont) { $txt2 = $this->UTF8ToUTF16BE($txt2, false); } $txt2=$this->_escape($txt2); $sub .=sprintf('BT '.$aix.' (%s) Tj ET',($this->x+$dx)*_MPDFK,($this->h-($this->y+$baseline+$va))*_MPDFK,$txt2); } } } // UNDERLINE if($this->U) { $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG if($this->FillColor!=$c) { $sub .= ' '.$c.' '; } if (isset($this->CurrentFont['up'])) { $up=$this->CurrentFont['up']; } else { $up = -100; } $adjusty = (-$up/1000* $this->FontSize); if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; } else { $ut = 60/1000* $this->FontSize; } $olw = $this->LineWidth; $sub .=' '.(sprintf(' %.3F w 0 j 0 J ',$ut*_MPDFK)); // mPDF 5.3.61 $sub .=' '.$this->_dounderline($this->x+$dx,$this->y+$baseline+$va+$adjusty,$txt); $sub .=' '.(sprintf(' %.3F w 2 j 2 J ',$olw*_MPDFK)); // mPDF 5.3.61 if($this->FillColor!=$c) { $sub .= ' '.$this->FillColor.' '; } } // STRIKETHROUGH if($this->strike) { $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG if($this->FillColor!=$c) { $sub .= ' '.$c.' '; } //Superscript and Subscript Y coordinate adjustment (now for striked-through texts) if (isset($this->CurrentFont['desc']['CapHeight'])) { $ch=$this->CurrentFont['desc']['CapHeight']; } else { $ch = 700; } $adjusty = (-$ch/1000* $this->FontSize) * 0.35; if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; } else { $ut = 60/1000* $this->FontSize; } $olw = $this->LineWidth; $sub .=' '.(sprintf(' %.3F w 0 j 0 J ',$ut*_MPDFK)); // mPDF 5.3.61 $sub .=' '.$this->_dounderline($this->x+$dx,$this->y+$baseline+$va+$adjusty,$txt); $sub .=' '.(sprintf(' %.3F w 2 j 2 J ',$olw*_MPDFK)); // mPDF 5.3.54 // mPDF 5.3.61 if($this->FillColor!=$c) { $sub .= ' '.$this->FillColor.' '; } } // mPDF 5.3.A2 // TEXT SHADOW if ($this->textshadow) { // First to process is last in CSS comma separated shadows foreach($this->textshadow AS $ts) { $s .= ' q '; $s .= $this->SetTColor($ts['col'], true)."\n"; if ($ts['col']{0}==5 && ord($ts['col']{4})<100) { // RGBa $s .= $this->SetAlpha(ord($ts['col']{4})/100, 'Normal', true, 'F')."\n"; } else if ($ts['col']{0}==6 && ord($ts['col']{5})<100) { // CMYKa $s .= $this->SetAlpha(ord($ts['col']{5})/100, 'Normal', true, 'F')."\n"; } else if ($ts['col']{0}==1 && $ts['col']{2}==1 && ord($ts['col']{3})<100) { // Gray $s .= $this->SetAlpha(ord($ts['col']{3})/100, 'Normal', true, 'F')."\n"; } $s .= sprintf(' q 1 0 0 1 %.4F %.4F cm', $ts['x']*_MPDFK, -$ts['y']*_MPDFK)."\n"; $s .= $sub; $s .= ' Q '; $s .= ' Q '; } } $s .= $sub; // COLOR if($this->ColorFlag) $s .=' Q'; // LINK if($link!='') { // mPDF 5.3.16 // Use same co-ordinates as span FILL above $this->Link($this->x,$boxtop,$w,$boxheight,$link); // Use this to add some padding/spacing around the textbox for the LINK // Use same spacing as span FILL above // $hsp = $this->FontSize/7; // $vsp = $this->FontSize/10; // $this->Link($this->x-$hsp,$boxtop-$vsp,$w+2*$hsp,$boxheight+2*$vsp,$link); } } if($s) $this->_out($s); // WORD SPACING if ($this->ws && !$this->usingCoreFont) { $this->_out(sprintf('BT %.3F Tc ET',$this->charspacing)); } $this->lasth=$h; if( strpos($txt,"\n") !== false) $ln=1; // cell recognizes \n from <BR> tag if($ln>0) { //Go to next line $this->y += $h; if($ln==1) { //Move to next line if ($currentx != 0) { $this->x=$currentx; } else { $this->x=$this->lMargin; } } } else $this->x+=$w; } function _kern($txt, $mode, $aix, $x, $y) { if ($mode == 'MBTw') { // Multibyte requiring word spacing $space = ' '; //Convert string to UTF-16BE without BOM $space= $this->UTF8ToUTF16BE($space , false); $space=$this->_escape($space ); $s = sprintf(' BT '.$aix,$x*_MPDFK,($this->h-$y)*_MPDFK); $t = explode(' ',$txt); for($i=0;$i<count($t);$i++) { $tx = $t[$i]; $tj = '('; $unicode = $this->UTF8StringToArray($tx); for($ti=0;$ti<count($unicode);$ti++) { if ($ti > 0 && isset($this->CurrentFont['kerninfo'][$unicode[($ti-1)]][$unicode[$ti]])) { $kern = -$this->CurrentFont['kerninfo'][$unicode[($ti-1)]][$unicode[$ti]]; $tj .= sprintf(')%d(',$kern); } $tc = code2utf($unicode[$ti]); $tc = $this->UTF8ToUTF16BE($tc, false); $tj .= $this->_escape($tc); } $tj .= ')'; $s.=sprintf(' %.3F Tc [%s] TJ',$this->charspacing,$tj); if (($i+1)<count($t)) { $s.=sprintf(' %.3F Tc (%s) Tj',$this->ws+$this->charspacing,$space); } } $s.=' ET '; } else if (!$this->usingCoreFont) { $s = ''; $tj = '('; $unicode = $this->UTF8StringToArray($txt); for($i=0;$i<count($unicode);$i++) { if ($i > 0 && isset($this->CurrentFont['kerninfo'][$unicode[($i-1)]][$unicode[$i]])) { $kern = -$this->CurrentFont['kerninfo'][$unicode[($i-1)]][$unicode[$i]]; $tj .= sprintf(')%d(',$kern); } $tx = code2utf($unicode[$i]); $tx = $this->UTF8ToUTF16BE($tx, false); $tj .= $this->_escape($tx); } $tj .= ')'; $s.=sprintf(' BT '.$aix.' [%s] TJ ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$tj); } else { // CORE Font $s = ''; $tj = '('; $l = strlen($txt); for($i=0;$i<$l;$i++) { if ($i > 0 && isset($this->CurrentFont['kerninfo'][$txt[($i-1)]][$txt[$i]])) { $kern = -$this->CurrentFont['kerninfo'][$txt[($i-1)]][$txt[$i]]; $tj .= sprintf(')%d(',$kern); } $tj .= $this->_escape($txt[$i]); } $tj .= ')'; $s.=sprintf(' BT '.$aix.' [%s] TJ ET ',$x*_MPDFK,($this->h-$y)*_MPDFK,$tj); } return $s; } function _smallCaps($txt, $mode, $aix, $dx, $k, $baseline, $va) { // mPDF 5.3.76 $upp = false; $str = array(); $bits = array(); if (!$this->usingCoreFont) { $unicode = $this->UTF8StringToArray($txt); foreach($unicode as $char) { if ($this->ws && $char == 32) { // space if (count($str)) { $bits[] = array($upp, $str, false); } $bits[] = array(false, array(32), true); $str = array(); $upp = false; } else if (isset($this->upperCase[$char])) { if (!$upp) { if (count($str)) { $bits[] = array($upp, $str, false); } $str = array(); } $str[] = $this->upperCase[$char]; if ((!isset($this->CurrentFont['sip']) || !$this->CurrentFont['sip']) && (!isset($this->CurrentFont['smp']) || !$this->CurrentFont['smp'])) { $this->CurrentFont['subset'][$this->upperCase[$char]] = $this->upperCase[$char]; } $upp = true; } else { if ($upp) { if (count($str)) { $bits[] = array($upp, $str, false); } $str = array(); } $str[] = $char; $upp = false; } } } else { for($i=0;$i<strlen($txt);$i++) { if (isset($this->upperCase[ord($txt[$i])]) && $this->upperCase[ord($txt[$i])] < 256) { if (!$upp) { if (count($str)) { $bits[] = array($upp, $str, false); } $str = array(); } $str[] = $this->upperCase[ord($txt[$i])]; $upp = true; } else { if ($upp) { if (count($str)) { $bits[] = array($upp, $str, false); } $str = array(); } $str[] = ord($txt[$i]); $upp = false; } } } if (count($str)) { $bits[] = array($upp, $str, false); } $fid = $this->CurrentFont['i']; $s=sprintf(' BT '.$aix,($this->x+$dx)*$k,($this->h-($this->y+$baseline+$va))*$k); // mPDF 5.3.76 foreach($bits AS $b) { if ($b[0]) { $upp = true; } else { $upp = false; } $size = count ($b[1]); $txt = ''; for ($i = 0; $i < $size; $i++) { $txt .= code2utf($b[1][$i]); } if ($this->usingCoreFont) { $txt = utf8_decode($txt); } if ($mode == 'SIPSMP') { $txt = $this->UTF8toSubset($txt); } else { if (!$this->usingCoreFont) { $txt = $this->UTF8ToUTF16BE($txt, false); } $txt=$this->_escape($txt); $txt = '('.$txt.')'; } if ($b[2]) { // space $s.=sprintf(' /F%d %.3F Tf %d Tz', $fid, $this->FontSizePt, 100); $s.=sprintf(' %.3F Tc', ($this->charspacing+$this->ws)); $s.=sprintf(' %s Tj', $txt); } else if ($upp) { $s.=sprintf(' /F%d %.3F Tf', $fid, $this->FontSizePt*$this->smCapsScale); $s.=sprintf(' %d Tz', $this->smCapsStretch); $s.=sprintf(' %.3F Tc', ($this->charspacing*100/$this->smCapsStretch)); $s.=sprintf(' %s Tj', $txt); } else { $s.=sprintf(' /F%d %.3F Tf %d Tz', $fid, $this->FontSizePt, 100); $s.=sprintf(' %.3F Tc', ($this->charspacing)); $s.=sprintf(' %s Tj', $txt); } } $s.=' ET '; return $s; } function MultiCell($w,$h,$txt,$border=0,$align='',$fill=0,$link='',$directionality='ltr',$encoded=false) { // Parameter (pre-)encoded - When called internally from ToC or textarea: mb_encoding already done - but not reverse RTL/Indic if (!$encoded) { $txt = $this->purify_utf8_text($txt); if ($this->text_input_as_HTML) { $txt = $this->all_entities_to_utf8($txt); } if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); } // Font-specific ligature substitution for Indic fonts else if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { // *INDIC* $this->ConvertIndic($tmp); // *INDIC* } // *INDIC* if (preg_match("/([".$this->pregRTLchars."])/u", $txt)) { $this->biDirectional = true; } // *RTL* } if (!$align) { $align = $this->defaultAlign; } //Output text with automatic or explicit line breaks $cw=&$this->CurrentFont['cw']; if($w==0) $w=$this->w-$this->rMargin-$this->x; $wmax = ($w - ($this->cMarginL+$this->cMarginR)); if ($this->usingCoreFont) { $s=str_replace("\r",'',$txt); $nb=strlen($s); while($nb>0 and $s[$nb-1]=="\n") $nb--; } else { $s=str_replace("\r",'',$txt); $nb=mb_strlen($s, $this->mb_enc ); while($nb>0 and mb_substr($s,$nb-1,1,$this->mb_enc )=="\n") $nb--; } $b=0; if($border) { if($border==1) { $border='LTRB'; $b='LRT'; $b2='LR'; } else { $b2=''; if(is_int(strpos($border,'L'))) $b2.='L'; if(is_int(strpos($border,'R'))) $b2.='R'; $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2; } } $sep=-1; $i=0; $j=0; $l=0; $ns=0; $nl=1; if (!$this->usingCoreFont) { $checkCursive=false; if ($this->biDirectional) { $checkCursive=true; } // *RTL* else if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC* while($i<$nb) { //Get next character $c = mb_substr($s,$i,1,$this->mb_enc ); if($c == "\n") { //Explicit line break // WORD SPACING $this->ResetSpacing(); $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc)); // DIRECTIONALITY $this->magic_reverse_dir($tmp, true, $directionality); // *RTL* $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link); $i++; $sep=-1; $j=$i; $l=0; $ns=0; $nl++; if($border and $nl==2) $b=$b2; continue; } if($c == " ") { $sep=$i; $ls=$l; $ns++; } $l += $this->GetCharWidthNonCore($c); // mPDF 5.3.04 if($l>$wmax) { //Automatic line break if($sep==-1) { // Only one word if($i==$j) $i++; // WORD SPACING $this->ResetSpacing(); $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc)); // DIRECTIONALITY $this->magic_reverse_dir($tmp, true, $directionality); // *RTL* $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link); } else { $tmp = rtrim(mb_substr($s,$j,$sep-$j,$this->mb_enc)); if($align=='J') { ////////////////////////////////////////// // JUSTIFY J using Unicode fonts (Word spacing doesn't work) // WORD SPACING UNICODE // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly $tmp = str_replace(chr(194).chr(160),chr(32),$tmp ); $len_ligne = $this->GetStringWidth($tmp ); $nb_carac = mb_strlen( $tmp , $this->mb_enc ) ; $nb_spaces = mb_substr_count( $tmp ,' ', $this->mb_enc ) ; $inclCursive=false; if ($checkCursive) { if (preg_match("/([".$this->pregRTLchars."])/u", $tmp)) { $inclCursive = true; } // *RTL* if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $tmp)) { $inclCursive = true; } // *INDIC* } list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($wmax) - $len_ligne) * _MPDFK),$inclCursive); $this->SetSpacing($charspacing,$ws); ////////////////////////////////////////// } // DIRECTIONALITY $this->magic_reverse_dir($tmp, true, $directionality); // *RTL* $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link); $i=$sep+1; } $sep=-1; $j=$i; $l=0; $ns=0; $nl++; if($border and $nl==2) $b=$b2; } else $i++; } //Last chunk // WORD SPACING $this->ResetSpacing(); } else { while($i<$nb) { //Get next character $c=$s[$i]; if($c == "\n") { //Explicit line break // WORD SPACING $this->ResetSpacing(); $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link); $i++; $sep=-1; $j=$i; $l=0; $ns=0; $nl++; if($border and $nl==2) $b=$b2; continue; } if($c == " ") { $sep=$i; $ls=$l; $ns++; } $l += $this->GetCharWidthCore($c); // mPDF 5.3.04 if($l>$wmax) { //Automatic line break if($sep==-1) { if($i==$j) $i++; // WORD SPACING $this->ResetSpacing(); $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link); } else { if($align=='J') { $tmp = rtrim(substr($s,$j,$sep-$j)); ////////////////////////////////////////// // JUSTIFY J using Unicode fonts (Word spacing doesn't work) // WORD SPACING NON_UNICDOE/CJK // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly $tmp = str_replace(chr(160),chr(32),$tmp); $len_ligne = $this->GetStringWidth($tmp ); $nb_carac = strlen( $tmp ) ; $nb_spaces = substr_count( $tmp ,' ' ) ; list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($wmax) - $len_ligne) * _MPDFK),false); $this->SetSpacing($charspacing,$ws); ////////////////////////////////////////// } $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill,$link); $i=$sep+1; } $sep=-1; $j=$i; $l=0; $ns=0; $nl++; if($border and $nl==2) $b=$b2; } else $i++; } //Last chunk // WORD SPACING $this->ResetSpacing(); } //Last chunk if($border and is_int(strpos($border,'B'))) $b.='B'; if (!$this->usingCoreFont) { $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc)); // DIRECTIONALITY $this->magic_reverse_dir($tmp, true, $directionality); // *RTL* $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link); } else { $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link); } $this->x=$this->lMargin; } /*-- DIRECTW --*/ function Write($h,$txt,$currentx=0,$link='',$directionality='ltr',$align='') { if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); } if (empty($this->directw)) { $this->directw = new directw($this); } $this->directw->Write($h,$txt,$currentx,$link,$directionality,$align); } /*-- END DIRECTW --*/ /*-- HTML-CSS --*/ function saveInlineProperties() { $saved = array(); $saved[ 'family' ] = $this->FontFamily; $saved[ 'style' ] = $this->FontStyle; $saved[ 'sizePt' ] = $this->FontSizePt; $saved[ 'size' ] = $this->FontSize; $saved[ 'HREF' ] = $this->HREF; $saved[ 'underline' ] = $this->U; $saved[ 'smCaps' ] = $this->S; $saved[ 'strike' ] = $this->strike; $saved[ 'textshadow' ] = $this->textshadow; // mPDF 5.3.A2 $saved[ 'SUP' ] = $this->SUP; $saved[ 'SUB' ] = $this->SUB; $saved[ 'linewidth' ] = $this->LineWidth; $saved[ 'drawcolor' ] = $this->DrawColor; $saved[ 'is_outline' ] = $this->outline_on; $saved[ 'outlineparam' ] = $this->outlineparam; $saved[ 'toupper' ] = $this->toupper; $saved[ 'tolower' ] = $this->tolower; $saved[ 'capitalize' ] = $this->capitalize; $saved[ 'fontkerning' ] = $this->kerning; $saved[ 'lSpacingCSS' ] = $this->lSpacingCSS; $saved[ 'wSpacingCSS' ] = $this->wSpacingCSS; $saved[ 'I' ] = $this->I; $saved[ 'B' ] = $this->B; $saved[ 'colorarray' ] = $this->colorarray; $saved[ 'bgcolorarray' ] = $this->spanbgcolorarray; $saved[ 'border' ] = $this->spanborddet; // mPDF 5.3.61 $saved[ 'color' ] = $this->TextColor; $saved[ 'bgcolor' ] = $this->FillColor; $saved['lang'] = $this->currentLang; $saved['display_off'] = $this->inlineDisplayOff; return $saved; } function restoreInlineProperties( &$saved) { $FontFamily = $saved[ 'family' ]; $this->FontStyle = $saved[ 'style' ]; $this->FontSizePt = $saved[ 'sizePt' ]; $this->FontSize = $saved[ 'size' ]; $this->currentLang = $saved['lang']; if ($this->useLang && !$this->usingCoreFont) { if ($this->currentLang != $this->default_lang && ((strlen($this->currentLang) == 5 && $this->currentLang != 'UTF-8') || strlen($this->currentLang ) == 2)) { list ($coreSuitable,$mpdf_pdf_unifonts) = GetLangOpts($this->currentLang, $this->useAdobeCJK); if ($mpdf_pdf_unifonts) { $this->RestrictUnicodeFonts($mpdf_pdf_unifonts); } else { $this->RestrictUnicodeFonts($this->default_available_fonts ); } } else { $this->RestrictUnicodeFonts($this->default_available_fonts ); } } $this->ColorFlag = ($this->FillColor != $this->TextColor); //Restore ColorFlag as well $this->HREF = $saved[ 'HREF' ]; $this->U = $saved[ 'underline' ]; $this->S = $saved[ 'smCaps' ]; $this->strike = $saved[ 'strike' ]; $this->textshadow = $saved[ 'textshadow' ]; // mPDF 5.3.A2 $this->SUP = $saved[ 'SUP' ]; $this->SUB = $saved[ 'SUB' ]; $this->LineWidth = $saved[ 'linewidth' ]; $this->DrawColor = $saved[ 'drawcolor' ]; $this->outline_on = $saved[ 'is_outline' ]; $this->outlineparam = $saved[ 'outlineparam' ]; $this->inlineDisplayOff = $saved['display_off']; $this->toupper = $saved[ 'toupper' ]; $this->tolower = $saved[ 'tolower' ]; $this->capitalize = $saved[ 'capitalize' ]; $this->kerning = $saved[ 'fontkerning' ]; $this->lSpacingCSS = $saved[ 'lSpacingCSS' ]; if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') { $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize); } else { $this->fixedlSpacing = false; } $this->wSpacingCSS = $saved[ 'wSpacingCSS' ]; if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') { $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize); } else { $this->minwSpacing = 0; } $this->SetFont($FontFamily, $saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''),$saved[ 'sizePt' ],false); $this->currentfontstyle = $saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''); $this->currentfontsize = $saved[ 'sizePt' ]; $this->SetStylesArray(array('S'=>$this->S, 'U'=>$this->U, 'B'=>$saved[ 'B' ], 'I'=>$saved[ 'I' ])); $this->TextColor = $saved[ 'color' ]; $this->FillColor = $saved[ 'bgcolor' ]; $this->colorarray = $saved[ 'colorarray' ]; $cor = $saved[ 'colorarray' ]; if ($cor) $this->SetTColor($cor); $this->spanbgcolorarray = $saved[ 'bgcolorarray' ]; $cor = $saved[ 'bgcolorarray' ]; if ($cor) $this->SetFColor($cor); $this->spanborddet = $saved[ 'border' ]; // mPDF 5.3.61 } // Used when ColActive for tables - updated to return first block with background fill OR borders function GetFirstBlockFill() { // Returns the first blocklevel that uses a bgcolor fill $startfill = 0; for ($i=1;$i<=$this->blklvl;$i++) { if ($this->blk[$i]['bgcolor'] || $this->blk[$i]['border_left']['w'] || $this->blk[$i]['border_right']['w'] || $this->blk[$i]['border_top']['w'] || $this->blk[$i]['border_bottom']['w'] ) { $startfill = $i; break; } } return $startfill; } function SetBlockFill($blvl) { if ($this->blk[$blvl]['bgcolor']) { $this->SetFColor($this->blk[$blvl]['bgcolorarray']); return 1; } else { $this->SetFColor($this->ConvertColor(255)); return 0; } } //-------------------------FLOWING BLOCK------------------------------------// //The following functions were originally written by Damon Kohler // //--------------------------------------------------------------------------// function saveFont() { $saved = array(); $saved[ 'family' ] = $this->FontFamily; $saved[ 'style' ] = $this->FontStyle; $saved[ 'sizePt' ] = $this->FontSizePt; $saved[ 'size' ] = $this->FontSize; $saved[ 'curr' ] = &$this->CurrentFont; $saved[ 'color' ] = $this->TextColor; $saved[ 'spanbgcolor' ] = $this->spanbgcolor; $saved[ 'spanbgcolorarray' ] = $this->spanbgcolorarray; $saved[ 'bord' ] = $this->spanborder; // mPDF 5.3.61 $saved[ 'border' ] = $this->spanborddet; // mPDF 5.3.61 $saved[ 'HREF' ] = $this->HREF; $saved[ 'underline' ] = $this->U; $saved[ 'smCaps' ] = $this->S; $saved[ 'strike' ] = $this->strike; $saved[ 'textshadow' ] = $this->textshadow; // mPDF 5.3.A2 $saved[ 'SUP' ] = $this->SUP; $saved[ 'SUB' ] = $this->SUB; $saved[ 'linewidth' ] = $this->LineWidth; $saved[ 'drawcolor' ] = $this->DrawColor; $saved[ 'is_outline' ] = $this->outline_on; $saved[ 'outlineparam' ] = $this->outlineparam; $saved[ 'ReqFontStyle' ] = $this->ReqFontStyle; $saved[ 'fontkerning' ] = $this->kerning; $saved[ 'fixedlSpacing' ] = $this->fixedlSpacing; $saved[ 'minwSpacing' ] = $this->minwSpacing; return $saved; } function restoreFont( &$saved, $write=true) { if (!isset($saved) || empty($saved)) return; $this->FontFamily = $saved[ 'family' ]; $this->FontStyle = $saved[ 'style' ]; $this->FontSizePt = $saved[ 'sizePt' ]; $this->FontSize = $saved[ 'size' ]; $this->CurrentFont = &$saved[ 'curr' ]; $this->TextColor = $saved[ 'color' ]; $this->spanbgcolor = $saved[ 'spanbgcolor' ]; $this->spanbgcolorarray = $saved[ 'spanbgcolorarray' ]; $this->spanborder = $saved[ 'bord' ]; // mPDF 5.3.61 $this->spanborddet = $saved[ 'border' ]; // mPDF 5.3.61 $this->ColorFlag = ($this->FillColor != $this->TextColor); //Restore ColorFlag as well $this->HREF = $saved[ 'HREF' ]; $this->U = $saved[ 'underline' ]; $this->S = $saved[ 'smCaps' ]; $this->kerning = $saved[ 'fontkerning' ]; $this->fixedlSpacing = $saved[ 'fixedlSpacing' ]; $this->minwSpacing = $saved[ 'minwSpacing' ]; $this->strike = $saved[ 'strike' ]; $this->textshadow = $saved[ 'textshadow' ]; // mPDF 5.3.A2 $this->SUP = $saved[ 'SUP' ]; $this->SUB = $saved[ 'SUB' ]; $this->LineWidth = $saved[ 'linewidth' ]; $this->DrawColor = $saved[ 'drawcolor' ]; $this->outline_on = $saved[ 'is_outline' ]; $this->outlineparam = $saved[ 'outlineparam' ]; if ($write) { $this->SetFont($saved[ 'family' ],$saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''),$saved[ 'sizePt' ],true,true); // force output $fontout = (sprintf('BT /F%d %.3F Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); if($this->page>0 && ((isset($this->pageoutput[$this->page]['Font']) && $this->pageoutput[$this->page]['Font'] != $fontout) || !isset($this->pageoutput[$this->page]['Font']) || $this->keep_block_together)) { $this->_out($fontout); } $this->pageoutput[$this->page]['Font'] = $fontout; } else $this->SetFont($saved[ 'family' ],$saved[ 'style' ].($this->U ? 'U' : '').($this->S ? 'S' : ''),$saved[ 'sizePt' ]); $this->ReqFontStyle = $saved[ 'ReqFontStyle' ]; } function newFlowingBlock( $w, $h, $a = '', $is_table = false, $is_list = false, $blockstate = 0, $newblock=true, $blockdir='ltr') { if (!$a) { if ($blockdir=='rtl') { $a = 'R'; } else { $a = 'L'; } } $this->flowingBlockAttr[ 'width' ] = ($w * _MPDFK); // line height in user units $this->flowingBlockAttr[ 'is_table' ] = $is_table; $this->flowingBlockAttr[ 'is_list' ] = $is_list; $this->flowingBlockAttr[ 'height' ] = $h; $this->flowingBlockAttr[ 'lineCount' ] = 0; $this->flowingBlockAttr[ 'align' ] = $a; $this->flowingBlockAttr[ 'font' ] = array(); $this->flowingBlockAttr[ 'content' ] = array(); $this->flowingBlockAttr[ 'contentB' ] = array(); // mPDF 5.3.61 $this->flowingBlockAttr[ 'contentWidth' ] = 0; $this->flowingBlockAttr[ 'blockstate' ] = $blockstate; $this->flowingBlockAttr[ 'newblock' ] = $newblock; $this->flowingBlockAttr[ 'valign' ] = 'M'; $this->flowingBlockAttr['blockdir'] = $blockdir; } function finishFlowingBlock($endofblock=false, $next='') { $currentx = $this->x; //prints out the last chunk $is_table = $this->flowingBlockAttr[ 'is_table' ]; $is_list = $this->flowingBlockAttr[ 'is_list' ]; $maxWidth =& $this->flowingBlockAttr[ 'width' ]; $lineHeight =& $this->flowingBlockAttr[ 'height' ]; $align =& $this->flowingBlockAttr[ 'align' ]; $content =& $this->flowingBlockAttr[ 'content' ]; $contentB =& $this->flowingBlockAttr[ 'contentB' ]; // mPDF 5.3.61 $font =& $this->flowingBlockAttr[ 'font' ]; $contentWidth =& $this->flowingBlockAttr[ 'contentWidth' ]; $lineCount =& $this->flowingBlockAttr[ 'lineCount' ]; $valign =& $this->flowingBlockAttr[ 'valign' ]; $blockstate = $this->flowingBlockAttr[ 'blockstate' ]; $newblock = $this->flowingBlockAttr[ 'newblock' ]; $blockdir = $this->flowingBlockAttr['blockdir']; // *********** BLOCK BACKGROUND COLOR *****************// if ($this->blk[$this->blklvl]['bgcolor'] && !$is_table) { $fill = 0; } else { $this->SetFColor($this->ConvertColor(255)); $fill = 0; } // Always right trim! // Right trim content and adjust width if need to justify (later) // mPDF 5.3.76 if (isset($content[count($content)-1]) && preg_match('/[ ]+$/',$content[count($content)-1], $m)) { $strip = strlen($m[0]); $content[count($content)-1] = substr($content[count($content)-1],0,(strlen($content[count($content)-1])-$strip)); $this->restoreFont( $font[ count($content)-1 ],false ); $contentWidth -= $this->GetStringWidth($m[0]) * _MPDFK; } // the amount of space taken up so far in user units $usedWidth = 0; // COLS $oldcolumn = $this->CurrCol; if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS* // Print out each chunk /*-- TABLES --*/ if ($is_table) { $ipaddingL = 0; $ipaddingR = 0; $paddingL = 0; $paddingR = 0; } else { /*-- END TABLES --*/ $ipaddingL = $this->blk[$this->blklvl]['padding_left']; $ipaddingR = $this->blk[$this->blklvl]['padding_right']; $paddingL = ($ipaddingL * _MPDFK); $paddingR = ($ipaddingR * _MPDFK); $this->cMarginL = $this->blk[$this->blklvl]['border_left']['w']; $this->cMarginR = $this->blk[$this->blklvl]['border_right']['w']; // Added mPDF 3.0 Float DIV $fpaddingR = 0; $fpaddingL = 0; /*-- CSS-FLOAT --*/ if (count($this->floatDivs)) { list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl); if ($r_exists) { $fpaddingR = $r_width; } if ($l_exists) { $fpaddingL = $l_width; } } /*-- END CSS-FLOAT --*/ $usey = $this->y + 0.002; if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) { $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w']; } /*-- CSS-IMAGE-FLOAT --*/ // If float exists at this level if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; } if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; } /*-- END CSS-IMAGE-FLOAT --*/ } // *TABLES* // Set Current lineheight (correction factor) $lhfixed = false; /*-- LISTS --*/ if ($is_list) { if (preg_match('/([0-9.,]+)mm/',$this->list_lineheight[$this->listlvl][$this->listOcc],$am)) { $lhfixed = true; $def_fontsize = $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listOcc][$this->listnum]['size']; $this->lineheight_correction = $am[1] / $def_fontsize ; } else { $this->lineheight_correction = $this->list_lineheight[$this->listlvl][$this->listOcc]; } } else /*-- END LISTS --*/ /*-- TABLES --*/ if ($is_table) { if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight,$am)) { $lhfixed = true; $def_fontsize = $this->FontSize; // needs to be default font-size for block **** $this->lineheight_correction = $lineHeight / $def_fontsize ; } else { $this->lineheight_correction = $this->table_lineheight; } } else /*-- END TABLES --*/ if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) { if (preg_match('/([0-9.,]+)mm/',$this->blk[$this->blklvl]['line_height'],$am)) { $lhfixed = true; $def_fontsize = $this->blk[$this->blklvl]['InlineProperties']['size']; // needs to be default font-size for block **** $this->lineheight_correction = $am[1] / $def_fontsize ; } else { $this->lineheight_correction = $this->blk[$this->blklvl]['line_height']; } } else { $this->lineheight_correction = $this->normalLineheight; } // correct lineheight to maximum fontsize if ($lhfixed) { $maxlineHeight = $this->lineheight; } else { $maxlineHeight = 0; } $this->forceExactLineheight = true; $maxfontsize = 0; // While we're at it, check if contains cursive text $checkCursive=false; if ($this->biDirectional) { $checkCursive=true; } // *RTL* foreach ( $content as $k => $chunk ) { $this->restoreFont( $font[ $k ],false ); if (!isset($this->objectbuffer[$k])) { // Soft Hyphens chr(173) if (!$this->usingCoreFont) { $content[$k] = $chunk = str_replace("\xc2\xad",'',$chunk ); if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC* } else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') { $content[$k] = $chunk = str_replace(chr(173),'',$chunk ); } // Special case of sub/sup carried over on its own to last line if (($this->SUB || $this->SUP) && count($content)==1) { $actfs = $this->FontSize*100/55; } // 55% is font change for sub/sup else { $actfs = $this->FontSize; } if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); } if ($lhfixed && ($actfs > $def_fontsize || ($actfs > ($lineHeight * $this->lineheight_correction) && $is_list))) { $this->forceExactLineheight = false; } $maxfontsize = max($maxfontsize,$actfs); } } if(isset($font[count($font)-1])) { $lastfontreqstyle = $font[count($font)-1]['ReqFontStyle']; $lastfontstyle = $font[count($font)-1]['style']; } else { $lastfontreqstyle=null; $lastfontstyle=null; } if ($blockdir == 'ltr' && strpos($lastfontreqstyle,"I") !== false && strpos($lastfontstyle,"I") === false) { // Artificial italic $lastitalic = $this->FontSize*0.15*_MPDFK; } else { $lastitalic = 0; } /*-- LISTS --*/ if ($is_list && is_array($this->bulletarray) && count($this->bulletarray)) { $actfs = $this->bulletarray['fontsize']; if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); } if ($lhfixed && $actfs > $def_fontsize) { $this->forceExactLineheight = false; } $maxfontsize = max($maxfontsize,$actfs); } /*-- END LISTS --*/ // when every text item checked i.e. $maxfontsize is set properly $af = 0; // Above font $bf = 0; // Below font $mta = 0; // Maximum top-aligned $mba = 0; // Maximum bottom-aligned foreach ( $content as $k => $chunk ) { if (isset($this->objectbuffer[$k])) { $oh = $this->objectbuffer[$k]['OUTER-HEIGHT']; $va = $this->objectbuffer[$k]['vertical-align']; // = $objattr['vertical-align'] = set as M,T,B,S if ($lhfixed && $oh > $def_fontsize) { $this->forceExactLineheight = false; } if ($va == 'BS') { // (BASELINE default) $af = max($af, ($oh - ($maxfontsize * (0.5 + $this->baselineC)))); } else if ($va == 'M') { $af = max($af, ($oh - $maxfontsize)/2); $bf = max($bf, ($oh - $maxfontsize)/2); } else if ($va == 'TT') { $bf = max($bf, ($oh - $maxfontsize)); } else if ($va == 'TB') { $af = max($af, ($oh - $maxfontsize)); } else if ($va == 'T') { $mta = max($mta, $oh); } else if ($va == 'B') { $mba = max($mba, $oh); } } } if ((!$lhfixed || !$this->forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) { $maxlineHeight = $maxfontsize + $af + $bf; } else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; } if ($mta > $maxlineHeight) { $bf += ($mta - $maxlineHeight); $maxlineHeight = $mta; } if ($mba > $maxlineHeight) { $af += ($mba - $maxlineHeight); $maxlineHeight = $mba; } $lineHeight = $maxlineHeight; // If NOT images, and maxfontsize NOT > lineHeight - this value determines text baseline positioning if ($lhfixed && $af==0 && $bf==0 && $maxfontsize<=($def_fontsize * $this->lineheight_correction * 0.8 )) { $this->linemaxfontsize = $def_fontsize; } else { $this->linemaxfontsize = $maxfontsize; } // Get PAGEBREAK TO TEST for height including the bottom border/padding $check_h = max($this->divheight,$lineHeight); // This fixes a proven bug... if ($endofblock && $newblock && $blockstate==0 && !$content) { $check_h = 0; } // but ? needs to fix potentially more widespread... // if (!$content) { $check_h = 0; } if ($this->blklvl > 0 && !$is_table) { if ($endofblock && $blockstate > 1) { if ($this->blk[$this->blklvl]['page_break_after_avoid']) { $check_h += $lineHeight; } $check_h += ($this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w']); } if (($newblock && ($blockstate==1 || $blockstate==3) && $lineCount == 0) || ($endofblock && $blockstate > 1 && $lineCount == 0)) { $check_h += ($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['border_top']['w']); } } // Force PAGE break if column height cannot take check-height if ($this->ColActive && $check_h > ($this->PageBreakTrigger - $this->y0)) { $this->SetCol($this->NbCol-1); } // PAGEBREAK //'If' below used in order to fix "first-line of other page with justify on" bug if(!$is_table && ($this->y+$check_h) > $this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) { $bak_x=$this->x;//Current X position // WORD SPACING $ws=$this->ws;//Word Spacing $charspacing=$this->charspacing;//Character Spacing $this->ResetSpacing(); $this->AddPage($this->CurOrientation); $this->x=$bak_x; // Added to correct for OddEven Margins $currentx += $this->MarginCorrection; $this->x += $this->MarginCorrection; // WORD SPACING $this->SetSpacing($charspacing,$ws); } if ($this->keep_block_together && !$is_table && $this->kt_p00 < $this->page && ($this->y+$check_h) > $this->kt_y00) { $this->printdivbuffer(); $this->keep_block_together = 0; } /*-- COLUMNS --*/ // COLS // COLUMN CHANGE if ($this->CurrCol != $oldcolumn) { $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap); $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap); $oldcolumn = $this->CurrCol; } if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } /*-- END COLUMNS --*/ // TOP MARGIN if ($newblock && ($blockstate==1 || $blockstate==3) && ($this->blk[$this->blklvl]['margin_top']) && $lineCount == 0 && !$is_table && !$is_list) { $this->DivLn($this->blk[$this->blklvl]['margin_top'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']); if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS* } if ($newblock && ($blockstate==1 || $blockstate==3) && $lineCount == 0 && !$is_table && !$is_list) { $this->blk[$this->blklvl]['y0'] = $this->y; $this->blk[$this->blklvl]['startpage'] = $this->page; if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS* } // ADDED for Paragraph_indent $WidthCorrection = 0; if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align != 'C')) { $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); $WidthCorrection = ($ti*_MPDFK); } // PADDING and BORDER spacing/fill if (($newblock) && ($blockstate==1 || $blockstate==3) && (($this->blk[$this->blklvl]['padding_top']) || ($this->blk[$this->blklvl]['border_top'])) && ($lineCount == 0) && (!$is_table) && (!$is_list)) { // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom $this->DivLn($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'],-3,true,false,1); if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS* $this->x = $currentx; } // Added mPDF 3.0 Float DIV $fpaddingR = 0; $fpaddingL = 0; /*-- CSS-FLOAT --*/ if (count($this->floatDivs)) { list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl); if ($r_exists) { $fpaddingR = $r_width; } if ($l_exists) { $fpaddingL = $l_width; } } /*-- END CSS-FLOAT --*/ $usey = $this->y + 0.002; if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) { $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w']; } /*-- CSS-IMAGE-FLOAT --*/ // If float exists at this level if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; } if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; } /*-- END CSS-IMAGE-FLOAT --*/ if ($content) { // In FinishFlowing Block no lines are justified as it is always last line // but if orphansAllowed have allowed content width to go over max width, use J charspacing to compress line // JUSTIFICATION J - NOT! $nb_carac = 0; $nb_spaces = 0; $jcharspacing = 0; $jws = 0; $inclCursive=false; foreach ( $content as $k => $chunk ) { if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) { if ($this->usingCoreFont) { $chunk = str_replace(chr(160),chr(32),$chunk ); } else { $chunk = str_replace(chr(194).chr(160),chr(32),$chunk ); } $nb_carac += mb_strlen( $chunk, $this->mb_enc ); $nb_spaces += mb_substr_count( $chunk,' ', $this->mb_enc ); if ($checkCursive) { if (preg_match("/([".$this->pregRTLchars."])/u", $chunk)) { $inclCursive = true; } // *RTL* if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $chunk)) { $inclCursive = true; } // *INDIC* } } } // if it's justified, we need to find the char/word spacing (or if orphans have allowed length of line to go over the maxwidth) // If "orphans" in fact is just a final space - ignore this if (((($contentWidth + $lastitalic) > $maxWidth) && ($content[count($content)-1] != ' ') ) || (!$endofblock && $align=='J' && ($next=='image' || $next=='select' || $next=='input' || $next=='textarea' || ($next=='br' && $this->justifyB4br))) ) { // WORD SPACING list($jcharspacing,$jws) = $this->GetJspacing($nb_carac,$nb_spaces,($maxWidth-$lastitalic-$contentWidth-$WidthCorrection-(($this->cMarginL+$this->cMarginR)*_MPDFK)-($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) )),$inclCursive); } // Check if will fit at word/char spacing of previous line - if so continue it // but only allow a maximum of $this->jSmaxWordLast and $this->jSmaxCharLast else if ($contentWidth < ($maxWidth - $lastitalic-$WidthCorrection - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK))) && !$this->fixedlSpacing) { if ($this->ws > $this->jSmaxWordLast) { $jws = $this->jSmaxWordLast; } if ($this->charspacing > $this->jSmaxCharLast) { $jcharspacing = $this->jSmaxCharLast; } $check = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) ) - ( $jcharspacing * $nb_carac) - ( $jws * $nb_spaces); if ($check <= 0) { $jcharspacing = 0; $jws = 0; } } $empty = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) ); $empty -= ($jcharspacing * $nb_carac); $empty -= ($jws * $nb_spaces); $empty /= _MPDFK; if (!$is_table) { $this->maxPosR = max($this->maxPosR , ($this->w - $this->rMargin - $this->blk[$this->blklvl]['outer_right_margin'] - $empty)); $this->maxPosL = min($this->maxPosL , ($this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $empty)); } $arraysize = count($content); $margins = ($this->cMarginL+$this->cMarginR) + ($ipaddingL+$ipaddingR + $fpaddingR + $fpaddingR ); if (!$is_table) { $this->DivLn($lineHeight,$this->blklvl,false); } // false -> don't advance y // DIRECTIONALITY RTL $all_rtl = false; $contains_rtl = false; /*-- RTL --*/ if ($blockdir == 'rtl' || $this->biDirectional) { $all_rtl = true; foreach ( $content as $k => $chunk ) { $reversed = $this->magic_reverse_dir($chunk, false, $blockdir); if ($reversed > 0) { $contains_rtl = true; } if ($reversed < 2) { $all_rtl = false; } $content[$k] = $chunk; } if (($blockdir =='rtl' && $contains_rtl) || $all_rtl) { $content = array_reverse($content,false); $contentB = array_reverse($contentB,false); // mPDF 5.3.61 } } /*-- END RTL --*/ $this->x = $currentx + $this->cMarginL + $ipaddingL + $fpaddingL; if ($align == 'R') { $this->x += $empty; } else if ($align == 'J' && $blockdir == 'rtl') { $this->x += $empty; } else if ($align == 'C') { $this->x += ($empty / 2); } // Paragraph INDENT $WidthCorrection = 0; if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align !='C')) { $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); $this->x += $ti; } foreach ( $content as $k => $chunk ) { // FOR IMAGES if ((($blockdir == 'rtl') && ($contains_rtl )) || $all_rtl ) { $dirk = $arraysize-1 - $k; } else { $dirk = $k; } $va = 'M'; // default for text if (isset($this->objectbuffer[$dirk]) && $this->objectbuffer[$dirk]) { $xadj = $this->x - $this->objectbuffer[$dirk]['OUTER-X']; $this->objectbuffer[$dirk]['OUTER-X'] += $xadj; $this->objectbuffer[$dirk]['BORDER-X'] += $xadj; $this->objectbuffer[$dirk]['INNER-X'] += $xadj; $va = $this->objectbuffer[$dirk]['vertical-align']; $yadj = $this->y - $this->objectbuffer[$dirk]['OUTER-Y']; if ($va == 'BS') { $yadj += $af + ($this->linemaxfontsize * (0.5 + $this->baselineC)) - $this->objectbuffer[$dirk]['OUTER-HEIGHT']; } else if ($va == 'M' || $va == '') { $yadj += $af + ($this->linemaxfontsize /2) - ($this->objectbuffer[$dirk]['OUTER-HEIGHT']/2); } else if ($va == 'TB') { $yadj += $af + $this->linemaxfontsize - $this->objectbuffer[$dirk]['OUTER-HEIGHT']; } else if ($va == 'TT') { $yadj += $af; } else if ($va == 'B') { $yadj += $af + $this->linemaxfontsize + $bf - $this->objectbuffer[$dirk]['OUTER-HEIGHT']; } else if ($va == 'T') { $yadj += 0; } $this->objectbuffer[$dirk]['OUTER-Y'] += $yadj; $this->objectbuffer[$dirk]['BORDER-Y'] += $yadj; $this->objectbuffer[$dirk]['INNER-Y'] += $yadj; } // DIRECTIONALITY RTL if ((($blockdir == 'rtl') && ($contains_rtl )) || $all_rtl ) { $this->restoreFont( $font[ $arraysize-1 - $k ] ); } else { $this->restoreFont( $font[ $k ] ); } $this->SetSpacing(($this->fixedlSpacing*_MPDFK)+$jcharspacing,($this->fixedlSpacing+$this->minwSpacing)*_MPDFK+$jws); $this->fixedlSpacing = false; $this->minwSpacing = 0; // *********** SPAN BACKGROUND COLOR ***************** // if (isset($this->spanbgcolor) && $this->spanbgcolor) { $cor = $this->spanbgcolorarray; $this->SetFColor($cor); $save_fill = $fill; $spanfill = 1; $fill = 1; } // mPDF 5.3.61 if (!empty($this->spanborddet)) { if (strpos($contentB[$k],'L')!==false && isset($this->spanborddet['L'])) $this->x += $this->spanborddet['L']['w']; if (strpos($contentB[$k],'L')===false) $this->spanborddet['L']['s'] = $this->spanborddet['L']['w'] = 0; if (strpos($contentB[$k],'R')===false) $this->spanborddet['R']['s'] = $this->spanborddet['R']['w'] = 0; } // WORD SPACING $stringWidth = $this->GetStringWidth($chunk ) + ( $this->charspacing * mb_strlen($chunk,$this->mb_enc ) / _MPDFK ) + ( $this->ws * mb_substr_count($chunk,' ',$this->mb_enc ) / _MPDFK ); if (isset($this->objectbuffer[$dirk])) { if ($this->objectbuffer[$dirk]['type']=='dottab') { $this->objectbuffer[$dirk]['OUTER-WIDTH'] +=$empty; } $stringWidth = $this->objectbuffer[$dirk]['OUTER-WIDTH']; } if ($stringWidth==0) { $stringWidth = 0.000001; } if ($k == $arraysize-1) $this->Cell( $stringWidth, $lineHeight, $chunk, '', 1, '', $fill, $this->HREF , $currentx,0,0,'M', $fill, $af, $bf, true ); //mono-style line or last part (skips line) // mPDF 5.3.07 else $this->Cell( $stringWidth, $lineHeight, $chunk, '', 0, '', $fill, $this->HREF, 0, 0,0,'M', $fill, $af, $bf, true );//first or middle part // mPDF 5.3.07 // mPDF 5.3.61 if (!empty($this->spanborddet)) { if (strpos($contentB[$k],'R')!==false && $k != $arraysize-1) $this->x += $this->spanborddet['R']['w']; } // *********** SPAN BACKGROUND COLOR OFF - RESET BLOCK BGCOLOR ***************** // if (isset($spanfill) && $spanfill) { $fill = $save_fill; $spanfill = 0; if ($fill) { $this->SetFColor($bcor); } } } $this->printobjectbuffer($is_table, $blockdir); $this->objectbuffer = array(); $this->ResetSpacing(); /*-- LISTS --*/ // LIST BULLETS/NUMBERS if ($is_list && is_array($this->bulletarray) && ($lineCount == 0) ) { $savedFont = $this->saveFont(); $bull = $this->bulletarray; if (isset($bull['level']) && isset($bull['occur']) && isset($this->InlineProperties['LIST'][$bull['level']][$bull['occur']])) { $this->restoreInlineProperties($this->InlineProperties['LIST'][$bull['level']][$bull['occur']]); } if (isset($bull['level']) && isset($bull['occur']) && isset($bull['num']) && isset($this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]) && $this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]) { $this->restoreInlineProperties($this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]); } if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') { $this->bullet = true; $this->SetFont('czapfdingbats','',$this->FontSizePt/2.5); } else { $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); } // force output //Output bullet $this->x = $currentx; if (isset($bull['x'])) { $this->x += $bull['x']; } $this->y -= $lineHeight; if (is_array($bull['col'])) { $this->SetTColor($bull['col']); } if (isset($bull['txt'])) { $this->Cell($bull['w'], $lineHeight,$bull['txt'],'','',$bull['align'],0,'',0,-$this->cMarginL, -$this->cMarginR ); } if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') { $this->bullet = false; } $this->x = $currentx; // Reset $this->y += $lineHeight; if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS* $this->restoreFont( $savedFont ); // $font = array( $savedFont ); $this->bulletarray = array(); // prevents repeat of bullet/number if <li>....<br />.....</li> } /*-- END LISTS --*/ } // END IF CONTENT /*-- CSS-IMAGE-FLOAT --*/ // Update values if set to skipline if ($this->floatmargins) { $this->_advanceFloatMargins(); } if ($endofblock && $blockstate>1) { // If float exists at this level if (isset($this->floatmargins['R']['y1'])) { $fry1 = $this->floatmargins['R']['y1']; } else { $fry1 = 0; } if (isset($this->floatmargins['L']['y1'])) { $fly1 = $this->floatmargins['L']['y1']; } else { $fly1 = 0; } if ($this->y < $fry1 || $this->y < $fly1) { $drop = max($fry1,$fly1) - $this->y; $this->DivLn($drop); $this->x = $currentx; } } /*-- END CSS-IMAGE-FLOAT --*/ // PADDING and BORDER spacing/fill if ($endofblock && ($blockstate > 1) && ($this->blk[$this->blklvl]['padding_bottom'] || $this->blk[$this->blklvl]['border_bottom'] || $this->blk[$this->blklvl]['css_set_height']) && (!$is_table) && (!$is_list)) { // If CSS height set, extend bottom - if on same page as block started, and CSS HEIGHT > actual height, // and does not force pagebreak $extra = 0; if ($this->blk[$this->blklvl]['css_set_height'] && $this->blk[$this->blklvl]['startpage']==$this->page) { // predicted height $h1 = ($this->y-$this->blk[$this->blklvl]['y0']) + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w']; if ($h1 < ($this->blk[$this->blklvl]['css_set_height']+$this->blk[$this->blklvl]['padding_bottom']+$this->blk[$this->blklvl]['padding_top'])) { $extra = ($this->blk[$this->blklvl]['css_set_height']+$this->blk[$this->blklvl]['padding_bottom']+$this->blk[$this->blklvl]['padding_top']) - $h1; } if($this->y + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $extra > $this->PageBreakTrigger) { $extra = $this->PageBreakTrigger - ($this->y + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w']); } } // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom $this->DivLn($this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $extra,-3,true,false,2); $this->x = $currentx; if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS* } // SET Bottom y1 of block (used for painting borders) if (($endofblock) && ($blockstate > 1) && (!$is_table) && (!$is_list)) { $this->blk[$this->blklvl]['y1'] = $this->y; } // BOTTOM MARGIN if (($endofblock) && ($blockstate > 1) && ($this->blk[$this->blklvl]['margin_bottom']) && (!$is_table) && (!$is_list)) { if($this->y+$this->blk[$this->blklvl]['margin_bottom'] < $this->PageBreakTrigger and !$this->InFooter) { $this->DivLn($this->blk[$this->blklvl]['margin_bottom'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']); if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS* } } // Reset lineheight $lineHeight = $this->divheight; } function printobjectbuffer($is_table=false, $blockdir=false) { if (!$blockdir) { $blockdir = $this->directionality; } if ($is_table && $this->shrin_k > 1) { $k = $this->shrin_k; } else { $k = 1; } $save_y = $this->y; $save_x = $this->x; $save_currentfontfamily = $this->FontFamily; $save_currentfontsize = $this->FontSizePt; $save_currentfontstyle = $this->FontStyle.($this->U ? 'U' : '').($this->S ? 'S' : ''); if ($blockdir == 'rtl') { $rtlalign = 'R'; } else { $rtlalign = 'L'; } foreach ($this->objectbuffer AS $ib => $objattr) { if ($objattr['type'] == 'bookmark' || $objattr['type'] == 'indexentry' || $objattr['type'] == 'toc') { $x = $objattr['OUTER-X']; $y = $objattr['OUTER-Y']; $this->y = $y - $this->FontSize/2; $this->x = $x; if ($objattr['type'] == 'bookmark' ) { $this->Bookmark($objattr['CONTENT'],$objattr['bklevel'] ,$y - $this->FontSize); } // *BOOKMARKS* if ($objattr['type'] == 'indexentry') { $this->IndexEntry($objattr['CONTENT']); } // *INDEX* if ($objattr['type'] == 'toc') { $this->TOC_Entry($objattr['CONTENT'], $objattr['toclevel'], $objattr['toc_id']); } // *TOC* } /*-- ANNOTATIONS --*/ else if ($objattr['type'] == 'annot') { if ($objattr['POS-X']) { $x = $objattr['POS-X']; } else if ($this->annotMargin<>0) { $x = -$objattr['OUTER-X']; } else { $x = $objattr['OUTER-X']; } if ($objattr['POS-Y']) { $y = $objattr['POS-Y']; } else { $y = $objattr['OUTER-Y'] - $this->FontSize/2; } // Create a dummy entry in the _out/columnBuffer with position sensitive data, // linking $y-1 in the Columnbuffer with entry in $this->columnAnnots // and when columns are split in length will not break annotation from current line $this->y = $y-1; $this->x = $x-1; $this->Line($x-1,$y-1,$x-1,$y-1); $this->Annotation($objattr['CONTENT'], $x , $y , $objattr['ICON'], $objattr['AUTHOR'], $objattr['SUBJECT'], $objattr['OPACITY'], $objattr['COLOR'], $objattr['POPUP'], $objattr['FILE']); } /*-- END ANNOTATIONS --*/ else { $y = $objattr['OUTER-Y']; $x = $objattr['OUTER-X']; $w = $objattr['OUTER-WIDTH']; $h = $objattr['OUTER-HEIGHT']; if (isset($objattr['text'])) { $texto = $objattr['text']; } $this->y = $y; $this->x = $x; if (isset($objattr['fontfamily'])) { $this->SetFont($objattr['fontfamily'],'',$objattr['fontsize'] ); } } // HR if ($objattr['type'] == 'hr') { $this->SetDColor($objattr['color']); switch($objattr['align']) { case 'C': $empty = $objattr['OUTER-WIDTH'] - $objattr['INNER-WIDTH']; $empty /= 2; $x += $empty; break; case 'R': $empty = $objattr['OUTER-WIDTH'] - $objattr['INNER-WIDTH']; $x += $empty; break; } $oldlinewidth = $this->LineWidth; $this->SetLineWidth($objattr['linewidth']/$k ); $this->y += ($objattr['linewidth']/2) + $objattr['margin_top']/$k; $this->Line($x,$this->y,$x+$objattr['INNER-WIDTH'],$this->y); $this->SetLineWidth($oldlinewidth); $this->SetDColor($this->ConvertColor(0)); } // IMAGE if ($objattr['type'] == 'image') { // mPDF 5.3.42 VISIBILITY // mPDF 5.3.49 if(isset($objattr['visibility']) && $objattr['visibility']!='visible' && $objattr['visibility']) { $this->SetVisibility($objattr['visibility']); } if (isset($objattr['opacity'])) { $this->SetAlpha($objattr['opacity']); } $rotate = 0; $obiw = $objattr['INNER-WIDTH']; $obih = $objattr['INNER-HEIGHT']; $sx = $objattr['INNER-WIDTH']*_MPDFK / $objattr['orig_w']; $sy = abs($objattr['INNER-HEIGHT'])*_MPDFK / abs($objattr['orig_h']); $sx = ($objattr['INNER-WIDTH']*_MPDFK / $objattr['orig_w']); $sy = ($objattr['INNER-HEIGHT']*_MPDFK / $objattr['orig_h']); if (isset($objattr['ROTATE'])) { $rotate = $objattr['ROTATE']; } if ($rotate==90) { // Clockwise $obiw = $objattr['INNER-HEIGHT']; $obih = $objattr['INNER-WIDTH']; $tr = $this->transformTranslate(0, -$objattr['INNER-WIDTH'], true) ; $tr .= ' '. $this->transformRotate(90, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-WIDTH'] ),true) ; $sx = $obiw*_MPDFK / $objattr['orig_h']; $sy = $obih*_MPDFK / $objattr['orig_w']; } else if ($rotate==-90 || $rotate==270) { // AntiClockwise $obiw = $objattr['INNER-HEIGHT']; $obih = $objattr['INNER-WIDTH']; $tr = $this->transformTranslate($objattr['INNER-WIDTH'], ($objattr['INNER-HEIGHT']-$objattr['INNER-WIDTH']), true) ; $tr .= ' '. $this->transformRotate(-90, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-WIDTH'] ),true) ; $sx = $obiw*_MPDFK / $objattr['orig_h']; $sy = $obih*_MPDFK / $objattr['orig_w']; } else if ($rotate==180) { // Mirror $tr = $this->transformTranslate($objattr['INNER-WIDTH'], -$objattr['INNER-HEIGHT'], true) ; $tr .= ' '. $this->transformRotate(180, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-HEIGHT'] ),true) ; } else { $tr = ''; } $tr = trim($tr); if ($tr) { $tr .= ' '; } $gradmask = ''; /*-- BACKGROUNDS --*/ if (isset($objattr['GRADIENT-MASK'])) { $g = $this->grad->parseMozGradient( $objattr['GRADIENT-MASK'] ); if ($g) { $dummy = $this->grad->Gradient($objattr['INNER-X'], $objattr['INNER-Y'], $obiw, $obih, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true, true); $gradmask = '/TGS'.count($this->gradients).' gs '; // $this->_out("q ".$tr.$this->grad->Gradient($objattr['INNER-X'], $objattr['INNER-Y'], $obiw, $obih, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend'], true)." Q"); } } /*-- END BACKGROUNDS --*/ /*-- IMAGES-WMF --*/ if (isset($objattr['itype']) && $objattr['itype']=='wmf') { $outstring = sprintf('q '.$tr.'%.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, -$sy, $objattr['INNER-X']*_MPDFK-$sx*$objattr['wmf_x'], (($this->h-$objattr['INNER-Y'])*_MPDFK)+$sy*$objattr['wmf_y'], $objattr['ID']); } else /*-- END IMAGES-WMF --*/ if (isset($objattr['itype']) && $objattr['itype']=='svg') { $outstring = sprintf('q '.$tr.'%.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, -$sy, $objattr['INNER-X']*_MPDFK-$sx*$objattr['wmf_x'], (($this->h-$objattr['INNER-Y'])*_MPDFK)+$sy*$objattr['wmf_y'], $objattr['ID']); } else { $outstring = sprintf("q ".$tr."%.3F 0 0 %.3F %.3F %.3F cm ".$gradmask."/I%d Do Q",$obiw*_MPDFK, $obih*_MPDFK, $objattr['INNER-X'] *_MPDFK, ($this->h-($objattr['INNER-Y'] +$obih ))*_MPDFK,$objattr['ID'] ); } $this->_out($outstring); // LINK if (isset($objattr['link'])) $this->Link($objattr['INNER-X'],$objattr['INNER-Y'],$objattr['INNER-WIDTH'],$objattr['INNER-HEIGHT'],$objattr['link']); if (isset($objattr['opacity'])) { $this->SetAlpha(1); } if ((isset($objattr['border_top']) && $objattr['border_top']>0) || (isset($objattr['border_left']) && $objattr['border_left']>0) || (isset($objattr['border_right']) && $objattr['border_right']>0) || (isset($objattr['border_bottom']) && $objattr['border_bottom']>0)) { $this->PaintImgBorder($objattr,$is_table); } // mPDF 5.3.42 VISIBILITY // mPDF 5.3.49 if(isset($objattr['visibility']) && $objattr['visibility']!='visible' && $objattr['visibility']) { $this->SetVisibility('visible'); } } /*-- BARCODES --*/ // BARCODE if ($objattr['type'] == 'barcode') { $bgcol = $this->ConvertColor(255); if (isset($objattr['bgcolor']) && $objattr['bgcolor']) { // mPDF 5.3.A4 $bgcol = $objattr['bgcolor']; } $col = $this->ConvertColor(0); if (isset($objattr['color']) && $objattr['color']) { // mPDF 5.3.A4 $col = $objattr['color']; } $this->SetFColor($bgcol); $this->Rect($objattr['BORDER-X'], $objattr['BORDER-Y'], $objattr['BORDER-WIDTH'], $objattr['BORDER-HEIGHT'], 'F'); $this->SetFColor($this->ConvertColor(255)); if (isset($objattr['BORDER-WIDTH'])) { $this->PaintImgBorder($objattr,$is_table); } if ($objattr['btype'] == 'EAN13' || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN' || $objattr['btype'] == 'UPCA' || $objattr['btype'] == 'UPCE' || $objattr['btype'] == 'EAN8') { $this->WriteBarcode($objattr['code'], $objattr['showtext'], $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize'], 0, 0, 0, 0, 0, $objattr['bheight'], $bgcol, $col, $objattr['btype'], $objattr['bsupp'], $objattr['bsupp_code'], $k); } // QR-code else if ($objattr['btype']=='QR') { if (!class_exists('QRcode', false)) { include(_MPDF_PATH.'qrcode/qrcode.class.php'); } $this->qrcode = new QRcode($objattr['code'], $objattr['errorlevel']); $this->qrcode->displayFPDF($this, $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize']*25, array(255,255,255), array(0,0,0)); } else { $this->WriteBarcode2($objattr['code'], $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize'], $objattr['bheight'], $bgcol, $col, $objattr['btype'], $objattr['pr_ratio'], $k); } } /*-- END BARCODES --*/ // mPDF 5.3.A5 // TEXT CIRCLE if ($objattr['type'] == 'textcircle') { $bgcol = $this->ConvertColor(255); if (isset($objattr['bgcolor']) && $objattr['bgcolor']) { $bgcol = $objattr['bgcolor']; } $col = $this->ConvertColor(0); if (isset($objattr['color']) && $objattr['color']) { $col = $objattr['color']; } $this->SetTColor($col); $this->SetFColor($bgcol); $this->Rect($objattr['BORDER-X'], $objattr['BORDER-Y'], $objattr['BORDER-WIDTH'], $objattr['BORDER-HEIGHT'], 'F'); $this->SetFColor($this->ConvertColor(255)); if (isset($objattr['BORDER-WIDTH'])) { $this->PaintImgBorder($objattr,$is_table); } if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); } if (empty($this->directw)) { $this->directw = new directw($this); } $save_lmfs = $this->linemaxfontsize; $this->linemaxfontsize = 0; if (isset($objattr['top-text'])) { $this->directw->CircularText($objattr['INNER-X']+$objattr['INNER-WIDTH']/2, $objattr['INNER-Y']+$objattr['INNER-HEIGHT']/2, $objattr['r']/$k, $objattr['top-text'], 'top', $objattr['fontfamily'], $objattr['fontsize']/$k, $objattr['fontstyle'], $objattr['space-width'], $objattr['char-width']); } if (isset($objattr['bottom-text'])) { $this->directw->CircularText($objattr['INNER-X']+$objattr['INNER-WIDTH']/2, $objattr['INNER-Y']+$objattr['INNER-HEIGHT']/2, $objattr['r']/$k, $objattr['bottom-text'], 'bottom', $objattr['fontfamily'], $objattr['fontsize']/$k, $objattr['fontstyle'], $objattr['space-width'], $objattr['char-width']); } $this->linemaxfontsize = $save_lmfs; } $this->ResetSpacing(); // DOT-TAB if ($objattr['type'] == 'dottab') { $sp = $this->GetStringWidth(' '); $nb=floor(($w-2*$sp)/$this->GetStringWidth('.')); if ($nb>0) { $dots=' '.str_repeat('.',$nb).' '; } else { $dots=' '; } $col = $this->ConvertColor(0); if (isset($objattr['colorarray']) && is_array($objattr['colorarray'])) { $col = $objattr['colorarray']; } $this->SetTColor($col); // mPDF 5.3.A3 $save_sbd = $this->spanborddet; $save_u = $this->U; $save_s = $this->strike; $this->spanborddet = ''; $this->U = false; $this->strike = false; $this->Cell($w,$h,$dots,0,0,'C'); $this->spanborddet = $save_sbd; $this->U = $save_u; $this->strike = $save_s; // mPDF 5.0 $this->SetTColor($this->ConvertColor(0)); } /*-- FORMS --*/ // TEXT/PASSWORD INPUT if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'TEXT' || $objattr['subtype'] == 'PASSWORD')) { $this->form->print_ob_text($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir); } // TEXTAREA if ($objattr['type'] == 'textarea') { $this->form->print_ob_textarea($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir); } // SELECT if ($objattr['type'] == 'select') { $this->form->print_ob_select($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir); } // INPUT/BUTTON as IMAGE if ($objattr['type'] == 'input' && $objattr['subtype'] == 'IMAGE') { $this->form->print_ob_imageinput($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir); } // BUTTON if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'SUBMIT' || $objattr['subtype'] == 'RESET' || $objattr['subtype'] == 'BUTTON')) { $this->form->print_ob_button($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir); } // CHECKBOX if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'CHECKBOX')) { $this->form->print_ob_checkbox($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir,$x,$y); } // RADIO if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'RADIO')) { $this->form->print_ob_radio($objattr,$w,$h,$texto,$rtlalign,$k,$blockdir,$x,$y); } /*-- END FORMS --*/ } $this->SetFont($save_currentfontfamily,$save_currentfontstyle,$save_currentfontsize); $this->y = $save_y; $this->x = $save_x; unset($content); } function WriteFlowingBlock( $s) { $currentx = $this->x; $is_table = $this->flowingBlockAttr[ 'is_table' ]; $is_list = $this->flowingBlockAttr[ 'is_list' ]; // width of all the content so far in points $contentWidth =& $this->flowingBlockAttr[ 'contentWidth' ]; // cell width in points $maxWidth =& $this->flowingBlockAttr[ 'width' ]; $lineCount =& $this->flowingBlockAttr[ 'lineCount' ]; // line height in user units $lineHeight =& $this->flowingBlockAttr[ 'height' ]; $align =& $this->flowingBlockAttr[ 'align' ]; $content =& $this->flowingBlockAttr[ 'content' ]; $contentB =& $this->flowingBlockAttr[ 'contentB' ]; // mPDF 5.3.61 $font =& $this->flowingBlockAttr[ 'font' ]; $valign =& $this->flowingBlockAttr[ 'valign' ]; $blockstate = $this->flowingBlockAttr[ 'blockstate' ]; $newblock = $this->flowingBlockAttr[ 'newblock' ]; $blockdir = $this->flowingBlockAttr['blockdir']; // *********** BLOCK BACKGROUND COLOR ***************** // if ($this->blk[$this->blklvl]['bgcolor'] && !$is_table) { $fill = 0; } else { $this->SetFColor($this->ConvertColor(255)); $fill = 0; } $font[] = $this->saveFont(); $content[] = ''; $contentB[] = ''; // mPDF 5.3.61 $currContent =& $content[ count( $content ) - 1 ]; // where the line should be cutoff if it is to be justified $cutoffWidth = $contentWidth; $curlyquote = mb_convert_encoding("\xe2\x80\x9e",$this->mb_enc,'UTF-8'); $curlylowquote = mb_convert_encoding("\xe2\x80\x9d",$this->mb_enc,'UTF-8'); $CJKoverflow = false; // COLS $oldcolumn = $this->CurrCol; if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS* /*-- TABLES --*/ if ($is_table) { $ipaddingL = 0; $ipaddingR = 0; $paddingL = 0; $paddingR = 0; $cpaddingadjustL = 0; $cpaddingadjustR = 0; // Added mPDF 3.0 $fpaddingR = 0; $fpaddingL = 0; } else { /*-- END TABLES --*/ $ipaddingL = $this->blk[$this->blklvl]['padding_left']; $ipaddingR = $this->blk[$this->blklvl]['padding_right']; $paddingL = ($ipaddingL * _MPDFK); $paddingR = ($ipaddingR * _MPDFK); $this->cMarginL = $this->blk[$this->blklvl]['border_left']['w']; $cpaddingadjustL = -$this->cMarginL; $this->cMarginR = $this->blk[$this->blklvl]['border_right']['w']; $cpaddingadjustR = -$this->cMarginR; // Added mPDF 3.0 Float DIV $fpaddingR = 0; $fpaddingL = 0; /*-- CSS-FLOAT --*/ if (count($this->floatDivs)) { list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl); if ($r_exists) { $fpaddingR = $r_width; } if ($l_exists) { $fpaddingL = $l_width; } } /*-- END CSS-FLOAT --*/ $usey = $this->y + 0.002; if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) { $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w']; } /*-- CSS-IMAGE-FLOAT --*/ // If float exists at this level if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; } if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; } /*-- END CSS-IMAGE-FLOAT --*/ } // *TABLES* //OBJECTS - IMAGES & FORM Elements (NB has already skipped line/page if required - in printbuffer) if (substr($s,0,3) == "\xbb\xa4\xac") { //identifier has been identified! $objattr = $this->_getObjAttr($s); $h_corr = 0; if ($is_table) { // *TABLES* $maximumW = ($maxWidth/_MPDFK) - ($this->cellPaddingL + $this->cMarginL + $this->cellPaddingR + $this->cMarginR); // *TABLES* } // *TABLES* else { // *TABLES* if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) && (!$is_table)) { $h_corr = $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w']; } $maximumW = ($maxWidth/_MPDFK) - ($this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_right'] + $this->blk[$this->blklvl]['border_right']['w'] + $fpaddingL + $fpaddingR ); } // *TABLES* $objattr = $this->inlineObject($objattr['type'],$this->lMargin + $fpaddingL + ($contentWidth/_MPDFK),($this->y + $h_corr), $objattr, $this->lMargin,($contentWidth/_MPDFK),$maximumW,$lineHeight,true,$is_table); // SET LINEHEIGHT for this line ================ RESET AT END $lineHeight = MAX($lineHeight,$objattr['OUTER-HEIGHT']); $this->objectbuffer[count($content)-1] = $objattr; // if (isset($objattr['vertical-align'])) { $valign = $objattr['vertical-align']; } // else { $valign = ''; } $contentWidth += ($objattr['OUTER-WIDTH'] * _MPDFK); return; } // mPDF 5.3.61 $lbw = $rbw = 0; // Border widths if (!empty($this->spanborddet)) { if (isset($this->spanborddet['L'])) $lbw = $this->spanborddet['L']['w']; if (isset($this->spanborddet['R'])) $rbw = $this->spanborddet['R']['w']; } if ($this->usingCoreFont) { $tmp = strlen( $s ); } else { $tmp = mb_strlen( $s, $this->mb_enc ); } $orphs = 0; $check = 0; // for every character in the string for ( $i = 0; $i < $tmp; $i++ ) { // extract the current character // get the width of the character in points if ($this->usingCoreFont) { $c = $s[$i]; // Soft Hyphens chr(173) // mPDF 5.3.07 $cw = ($this->GetCharWidthCore($c) * _MPDFK); // mPDF 5.3.04 if ($this->kerning && $this->useKerning && $i > 0) { if (isset($this->CurrentFont['kerninfo'][$s[($i-1)]][$c])) { $cw += ($this->CurrentFont['kerninfo'][$s[($i-1)]][$c] * $this->FontSizePt / 1000 ); } } } else { $c = mb_substr($s,$i,1,$this->mb_enc ); $cw = ($this->GetCharWidthNonCore($c, false) * _MPDFK); // mPDF 5.3.04 if ($this->kerning && $this->useKerning && $i > 0) { $lastc = mb_substr($s,($i-1),1,$this->mb_enc ); $ulastc = $this->UTF8StringToArray($lastc, false); $uc = $this->UTF8StringToArray($c, false); if (isset($this->CurrentFont['kerninfo'][$ulastc[0]][$uc[0]])) { $cw += ($this->CurrentFont['kerninfo'][$ulastc[0]][$uc[0]] * $this->FontSizePt / 1000 ); } } } // mPDF 5.3.61 if ($i==0) { $cw += $lbw*_MPDFK; $contentB[(count($contentB)-1)] .= 'L'; } if ($i==($tmp-1)) { $cw += $rbw*_MPDFK; $contentB[(count($contentB)-1)] .= 'R'; } if ($c==' ') { $check = 1; } // CHECK for ORPHANS else if ($c=='.' || $c==',' || $c==')' || $c==']' || $c==';' || $c==':' || $c=='!' || $c=='?'|| $c=='"' || $c==$curlyquote || $c==$curlylowquote) {$check++; } /*-- CJK-FONTS --*/ else if ($this->checkCJK) { // mPDF 5.3.07 if ((!$is_table && $this->CJKfollowing && preg_match("/[".$this->CJKfollowing."]/u", $c)) || ($is_table && preg_match("/[".$this->CJKoverflow ."]/u", $c))) { $check++; } else { $check = 0; } } /*-- END CJK-FONTS --*/ else { $check = 0; } // There's an orphan '. ' or ', ' or <sup>32</sup> about to be cut off at the end of line if($check==1) { $currContent .= $c; $cutoffWidth = $contentWidth; $contentWidth += $cw; continue; } if(($this->SUP || $this->SUB) && ($orphs < $this->orphansAllowed)) { // ? disable orphans in table if borders used $currContent .= $c; $cutoffWidth = $contentWidth; $contentWidth += $cw; $orphs++; continue; } else { $orphs = 0; } // ADDED for Paragraph_indent $WidthCorrection = 0; if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align != 'C')) { $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); $WidthCorrection = ($ti*_MPDFK); } // Added mPDF 3.0 Float DIV $fpaddingR = 0; $fpaddingL = 0; /*-- CSS-FLOAT --*/ if (count($this->floatDivs)) { list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl); if ($r_exists) { $fpaddingR = $r_width; } if ($l_exists) { $fpaddingL = $l_width; } } /*-- END CSS-FLOAT --*/ $usey = $this->y + 0.002; if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) { $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w']; } /*-- CSS-IMAGE-FLOAT --*/ // If float exists at this level if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; } if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; } /*-- END CSS-IMAGE-FLOAT --*/ // try adding another char if (( $contentWidth + $cw > $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) ) + 0.001)) {// 0.001 is to correct for deviations converting mm=>pts // it won't fit, output what we already have $lineCount++; // contains any content that didn't make it into this print $savedContent = ''; $savedContentB = ''; // mPDF 5.3.61 $savedFont = array(); $savedObj = array(); // cut off and save any partial words at the end of the string $words = explode( ' ', $currContent ); /////////////////// // HYPHENATION $currWord = $words[count($words)-1] ; $success = false; /*-- HYPHENATION --*/ // Soft Hyphens chr(173) if ((!$this->usingCoreFont && preg_match("/\xc2\xad/",$currWord)) || ($this->usingCoreFont && preg_match("/".chr(173)."/",$currWord) && ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats')) ) { $rem = $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) ); list($success,$pre,$post,$prelength) = $this->softHyphenate($currWord, (($rem-$cutoffWidth)/_MPDFK -$this->GetCharWidthNonCore(" ", false)) ); // mPDF 5.3.04 } if (!$success && ($this->hyphenate || ($this->hyphenateTables && $is_table))) { // Look ahead to get current word for($ac = $i; $ac<(mb_strlen($s)-1); $ac++) { $addc = mb_substr($s,$ac,1,$this->mb_enc ); if ($addc == ' ') { break; } $currWord .= $addc; } $rem = $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) ); list($success,$pre,$post,$prelength) = $this->hyphenateWord($currWord, (($rem-$cutoffWidth)/_MPDFK -$this->GetCharWidth(" ", false)) ); } if ($success) { $already = array_pop( $words ); $forward = mb_substr($already,$prelength,mb_strlen($already, $this->mb_enc), $this->mb_enc); $words[] = $pre.'-'; $words[] = $forward; $currContent = mb_substr($currContent,0,mb_strlen($currContent, $this->mb_enc)+1-mb_strlen($post, $this->mb_enc), $this->mb_enc) . '-'; } /*-- END HYPHENATION --*/ // if it looks like we didn't finish any words for this chunk if ( count( $words ) == 1 ) { // TO correct for error when word too wide for page - but only when one long word from left to right margin if (count($content) == 1 && $currContent != ' ') { ///////////////////////////////////////////////////////////////////////////////////// $lastchar = mb_substr($words[0],mb_strlen($words[0], $this->mb_enc)-1, 1, $this->mb_enc); /*-- CJK-FONTS --*/ // mPDF 5.3.07 if ($this->checkCJK) { // Last character that fits is not allowed to end a line - move lastchar(s) to start of next line if (!$is_table && preg_match("/[".$this->CJKleading."]/u", $lastchar)) { //move lastchar(s) to next line $m0 = $lastchar; $m1 = $c; while(preg_match("/[".$this->CJKleading."]/u", $m0) && mb_strlen($words[0], $this->mb_enc)>2) { // trim last letter off word[0] $words[0] = mb_substr($words[0],0,mb_strlen($words[0], $this->mb_enc)-1, $this->mb_enc); // and add it to savedContent for next line $savedContent = $m0.$savedContent; $m1 = $lastchar; $lastchar = mb_substr($words[0],mb_strlen($words[0], $this->mb_enc)-1, 1, $this->mb_enc); $m0 = $lastchar; } } // Next character is not allowed to start a new line - move lastchar(s) to next line else if (!$is_table && preg_match("/[".$this->CJKfollowing."]/u", $c)) { // try squeezing another character(s) onto this line = Oikomi if ($this->allowCJKorphans) { $lookahead = mb_substr($s,$i+1,1,$this->mb_enc ); //if lookahead is not another following char if ($lookahead && !preg_match("/[".$this->CJKfollowing."]/u", $lookahead)) { $currContent .= $c; $cutoffWidth = $contentWidth; $contentWidth += $cw; if ($this->allowCJKoverflow && !$is_table && preg_match("/[".$this->CJKoverflow."]/u", $c)) { $CJKoverflow = true; } continue; } } // or move lastchar(s) to next line to keep $c company = Oidashi $m0 = $lastchar; $m1 = $c; while(preg_match("/[".$this->CJKfollowing."]/u", $m1) && mb_strlen($words[0], $this->mb_enc)>2) { // trim last letter off word[0] $words[0] = mb_substr($words[0],0,mb_strlen($words[0], $this->mb_enc)-1, $this->mb_enc); // and add it to savedContent for next line $savedContent = $m0.$savedContent; $m1 = $lastchar; $lastchar = mb_substr($words[0],mb_strlen($words[0], $this->mb_enc)-1, 1, $this->mb_enc); $m0 = $lastchar; } } } /*-- END CJK-FONTS --*/ $lastContent = $words[0]; $savedFont = $this->saveFont(); // replace the current content with the cropped version $currContent = rtrim( $lastContent ); } else { // save and crop off the content currently on the stack $savedContent = array_pop( $content ); $savedContentB = $contentB[(count($contentB)-1)]; // mPDF 5.3.61 $savedFont = array_pop( $font ); // trim any trailing spaces off the last bit of content $currContent =& $content[ count( $content ) - 1 ]; $currContent = rtrim( $currContent ); } } else { // otherwise, we need to find which bit to cut off $lastContent = ''; for ( $w = 0; $w < count( $words ) - 1; $w++) { $lastContent .= $words[ $w ]." "; } $savedContent = $words[ count( $words ) - 1 ]; $savedFont = $this->saveFont(); // replace the current content with the cropped version $currContent = rtrim( $lastContent ); } // CJK - strip CJK space at end of line // &#x3000; = \xe3\x80\x80 = CJK space if ($this->checkCJK) { $currContent = preg_replace("/\xe3\x80\x80$/",'',$currContent) ; } // *CJK-FONTS* if (isset($this->objectbuffer[(count($content)-1)]) && $this->objectbuffer[(count($content)-1)]['type']=='dottab') { $savedObj = array_pop( $this->objectbuffer ); $contentWidth -= ($this->objectbuffer[(count($content)-1)]['OUTER-WIDTH'] * _MPDFK); } // Set Current lineheight (correction factor) $lhfixed = false; /*-- LISTS --*/ if ($is_list) { if (preg_match('/([0-9.,]+)mm/',$this->list_lineheight[$this->listlvl][$this->listOcc],$am)) { $lhfixed = true; $def_fontsize = $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listOcc][$this->listnum]['size']; $this->lineheight_correction = $am[1] / $def_fontsize ; } else { $this->lineheight_correction = $this->list_lineheight[$this->listlvl][$this->listOcc]; } } else /*-- END LISTS --*/ /*-- TABLES --*/ if ($is_table) { if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight,$am)) { $lhfixed = true; $def_fontsize = $this->FontSize; // needs to be default font-size for block **** $this->lineheight_correction = $lineHeight / $def_fontsize ; } else { $this->lineheight_correction = $this->table_lineheight; } } else /*-- END TABLES --*/ if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) { if (preg_match('/([0-9.,]+)mm/',$this->blk[$this->blklvl]['line_height'],$am)) { $lhfixed = true; $def_fontsize = $this->blk[$this->blklvl]['InlineProperties']['size']; // needs to be default font-size for block **** $this->lineheight_correction = $am[1] / $def_fontsize ; } else { $this->lineheight_correction = $this->blk[$this->blklvl]['line_height']; } } else { $this->lineheight_correction = $this->normalLineheight; } // update $contentWidth and $cutoffWidth since they changed with cropping // Also correct lineheight to maximum fontsize (not for tables) $contentWidth = 0; // correct lineheight to maximum fontsize if ($lhfixed) { $maxlineHeight = $this->lineheight; } else { $maxlineHeight = 0; } $this->forceExactLineheight = true; $maxfontsize = 0; // While we're at it, check for cursive text $checkCursive=false; if ($this->biDirectional) { $checkCursive=true; } // *RTL* foreach ( $content as $k => $chunk ) { $this->restoreFont( $font[ $k ]); if (!isset($this->objectbuffer[$k])) { if (!$this->usingCoreFont) { $content[$k] = $chunk = str_replace("\xc2\xad",'',$chunk ); if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) { $checkCursive=true; } // *INDIC* } // Soft Hyphens chr(173) else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') { $content[$k] = $chunk = str_replace(chr(173),'',$chunk ); } $contentWidth += $this->GetStringWidth( $chunk ) * _MPDFK; // mPDF 5.3.61 if (!empty($this->spanborddet)) { if (strpos($contentB[$k],'L')!==false) $contentWidth += $this->spanborddet['L']['w'] * _MPDFK; if (strpos($contentB[$k],'R')!==false) $contentWidth += $this->spanborddet['R']['w'] * _MPDFK; } if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$this->FontSize * $this->lineheight_correction ); } if ($lhfixed && ($this->FontSize > $def_fontsize || ($this->FontSize > ($lineHeight * $this->lineheight_correction) && $is_list))) { $this->forceExactLineheight = false; } $maxfontsize = max($maxfontsize,$this->FontSize); } } $lastfontreqstyle = $font[count($font)-1]['ReqFontStyle']; $lastfontstyle = $font[count($font)-1]['style']; if ($blockdir == 'ltr' && strpos($lastfontreqstyle,"I") !== false && strpos($lastfontstyle,"I") === false) { // Artificial italic $lastitalic = $this->FontSize*0.15*_MPDFK; } else { $lastitalic = 0; } /*-- LISTS --*/ if ($is_list && is_array($this->bulletarray) && $this->bulletarray) { $actfs = $this->bulletarray['fontsize']; if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); } if ($lhfixed && $actfs > $def_fontsize) { $this->forceExactLineheight = false; } $maxfontsize = max($maxfontsize,$actfs); } /*-- END LISTS --*/ // when every text item checked i.e. $maxfontsize is set properly $af = 0; // Above font $bf = 0; // Below font $mta = 0; // Maximum top-aligned $mba = 0; // Maximum bottom-aligned foreach ( $content as $k => $chunk ) { if (isset($this->objectbuffer[$k]) && $this->objectbuffer[$k]) { $contentWidth += $this->objectbuffer[$k]['OUTER-WIDTH'] * _MPDFK; $oh = $this->objectbuffer[$k]['OUTER-HEIGHT']; $va = $this->objectbuffer[$k]['vertical-align']; // = $objattr['vertical-align'] = set as M,T,B,S if ($lhfixed && $oh > $def_fontsize) { $this->forceExactLineheight = false; } if ($va == 'BS') { // (BASELINE default) $af = max($af, ($oh - ($maxfontsize * (0.5 + $this->baselineC)))); } else if ($va == 'M') { $af = max($af, ($oh - $maxfontsize)/2); $bf = max($bf, ($oh - $maxfontsize)/2); } else if ($va == 'TT') { $bf = max($bf, ($oh - $maxfontsize)); } else if ($va == 'TB') { $af = max($af, ($oh - $maxfontsize)); } else if ($va == 'T') { $mta = max($mta, $oh); } else if ($va == 'B') { $mba = max($mba, $oh); } } } if ((!$lhfixed || !$this->forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) { $maxlineHeight = $maxfontsize + $af + $bf; } else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; } if ($mta > $maxlineHeight) { $bf += ($mta - $maxlineHeight); $maxlineHeight = $mta; } if ($mba > $maxlineHeight) { $af += ($mba - $maxlineHeight); $maxlineHeight = $mba; } $lineHeight = $maxlineHeight; $cutoffWidth = $contentWidth; // If NOT images, and maxfontsize NOT > lineHeight - this value determines text baseline positioning if ($lhfixed && $af==0 && $bf==0 && $maxfontsize<=($def_fontsize * $this->lineheight_correction * 0.8 )) { $this->linemaxfontsize = $def_fontsize; } else { $this->linemaxfontsize = $maxfontsize; } $inclCursive=false; foreach ( $content as $k => $chunk ) { if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) { if ($this->usingCoreFont) { $content[$k] = str_replace(chr(160),chr(32),$chunk ); } else { $content[$k] = str_replace(chr(194).chr(160),chr(32),$chunk ); if ($checkCursive) { if (preg_match("/([".$this->pregRTLchars."])/u", $chunk)) { $inclCursive = true; } // *RTL* if (preg_match("/([".$this->pregHIchars.$this->pregBNchars.$this->pregPAchars."])/u", $chunk)) { $inclCursive = true; } // *INDIC* } } } } // JUSTIFICATION J $jcharspacing = 0; $jws = 0; $nb_carac = 0; $nb_spaces = 0; // if it's justified, we need to find the char/word spacing (or if orphans have allowed length of line to go over the maxwidth) if(( $align == 'J' ) || (($cutoffWidth + $lastitalic > $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*_MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) ) + 0.001) && !$CJKoverflow)) { // 0.001 is to correct for deviations converting mm=>pts // JUSTIFY J (Use character spacing) // WORD SPACING foreach ( $content as $k => $chunk ) { if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) { $nb_carac += mb_strlen( $chunk, $this->mb_enc ) ; $nb_spaces += mb_substr_count( $chunk,' ', $this->mb_enc ) ; } } list($jcharspacing,$jws) = $this->GetJspacing($nb_carac,$nb_spaces,($maxWidth-$lastitalic-$cutoffWidth-$WidthCorrection-(($this->cMarginL+$this->cMarginR)*_MPDFK)-($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) )),$inclCursive); } // WORD SPACING $empty = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* _MPDFK) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * _MPDFK) ); $empty -= ($jcharspacing * $nb_carac); $empty -= ($jws * $nb_spaces); $empty /= _MPDFK; $b = ''; //do not use borders // Get PAGEBREAK TO TEST for height including the top border/padding $check_h = max($this->divheight,$lineHeight); if (($newblock) && ($blockstate==1 || $blockstate==3) && ($this->blklvl > 0) && ($lineCount == 1) && (!$is_table) && (!$is_list)) { $check_h += ($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['border_top']['w']); } if ($this->ColActive && $check_h > ($this->PageBreakTrigger - $this->y0)) { $this->SetCol($this->NbCol-1); } // PAGEBREAK // 'If' below used in order to fix "first-line of other page with justify on" bug if(!$is_table && ($this->y+$check_h) > $this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) { $bak_x=$this->x;//Current X position // WORD SPACING $ws=$this->ws;//Word Spacing $charspacing=$this->charspacing;//Character Spacing $this->ResetSpacing(); $this->AddPage($this->CurOrientation); $this->x = $bak_x; // Added to correct for OddEven Margins $currentx += $this->MarginCorrection; $this->x += $this->MarginCorrection; // WORD SPACING $this->SetSpacing($charspacing,$ws); } if ($this->keep_block_together && !$is_table && $this->kt_p00 < $this->page && ($this->y+$check_h) > $this->kt_y00) { $this->printdivbuffer(); $this->keep_block_together = 0; } /*-- COLUMNS --*/ // COLS // COLUMN CHANGE if ($this->CurrCol != $oldcolumn) { $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap); $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap); $oldcolumn = $this->CurrCol; } if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS* /*-- END COLUMNS --*/ // TOP MARGIN if (($newblock) && ($blockstate==1 || $blockstate==3) && ($this->blk[$this->blklvl]['margin_top']) && ($lineCount == 1) && (!$is_table) && (!$is_list)) { $this->DivLn($this->blk[$this->blklvl]['margin_top'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']); if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS* } // Update y0 for top of block (used to paint border) if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 1) && (!$is_table) && (!$is_list)) { $this->blk[$this->blklvl]['y0'] = $this->y; $this->blk[$this->blklvl]['startpage'] = $this->page; } // TOP PADDING and BORDER spacing/fill if (($newblock) && ($blockstate==1 || $blockstate==3) && (($this->blk[$this->blklvl]['padding_top']) || ($this->blk[$this->blklvl]['border_top'])) && ($lineCount == 1) && (!$is_table) && (!$is_list)) { // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom $this->DivLn($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'],-3,true,false,1); if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS* } $arraysize = count($content); $margins = ($this->cMarginL+$this->cMarginR) + ($ipaddingL+$ipaddingR + $fpaddingR + $fpaddingR ); // PAINT BACKGROUND FOR THIS LINE if (!$is_table) { $this->DivLn($lineHeight,$this->blklvl,false); } // false -> don't advance y $this->x = $currentx + $this->cMarginL + $ipaddingL + $fpaddingL ; if ($align == 'R') { $this->x += $empty; } else if ($align == 'C') { $this->x += ($empty / 2); } // Paragraph INDENT if (isset($this->blk[$this->blklvl]['text_indent']) && ($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 1) && (!$is_table) && ($blockdir !='rtl') && ($align !='C')) { $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); $this->x += $ti; } // DIRECTIONALITY RTL $all_rtl = false; $contains_rtl = false; /*-- RTL --*/ if ($blockdir == 'rtl' || $this->biDirectional) { $all_rtl = true; foreach ( $content as $k => $chunk ) { $reversed = $this->magic_reverse_dir($chunk, false, $blockdir); if ($reversed > 0) { $contains_rtl = true; } if ($reversed < 2) { $all_rtl = false; } $content[$k] = $chunk; } if (($blockdir =='rtl' && $contains_rtl) || $all_rtl) { $content = array_reverse($content,false); $contentB = array_reverse($contentB,false); // mPDF 5.3.61 } } /*-- END RTL --*/ foreach ( $content as $k => $chunk ) { // FOR IMAGES - UPDATE POSITION if (($blockdir =='rtl' && $contains_rtl) || $all_rtl) { $dirk = $arraysize-1 - $k ; } else { $dirk = $k; } $va = 'M'; // default for text if (isset($this->objectbuffer[$dirk]) && $this->objectbuffer[$dirk]) { $xadj = $this->x - $this->objectbuffer[$dirk]['OUTER-X'] ; $this->objectbuffer[$dirk]['OUTER-X'] += $xadj; $this->objectbuffer[$dirk]['BORDER-X'] += $xadj; $this->objectbuffer[$dirk]['INNER-X'] += $xadj; $va = $this->objectbuffer[$dirk]['vertical-align']; $yadj = $this->y - $this->objectbuffer[$dirk]['OUTER-Y']; if ($va == 'BS') { $yadj += $af + ($this->linemaxfontsize * (0.5 + $this->baselineC)) - $this->objectbuffer[$dirk]['OUTER-HEIGHT']; } else if ($va == 'M' || $va == '') { $yadj += $af + ($this->linemaxfontsize /2) - ($this->objectbuffer[$dirk]['OUTER-HEIGHT']/2); } else if ($va == 'TB') { $yadj += $af + $this->linemaxfontsize - $this->objectbuffer[$dirk]['OUTER-HEIGHT']; } else if ($va == 'TT') { $yadj += $af; } else if ($va == 'B') { $yadj += $af + $this->linemaxfontsize + $bf - $this->objectbuffer[$dirk]['OUTER-HEIGHT']; } else if ($va == 'T') { $yadj += 0; } $this->objectbuffer[$dirk]['OUTER-Y'] += $yadj; $this->objectbuffer[$dirk]['BORDER-Y'] += $yadj; $this->objectbuffer[$dirk]['INNER-Y'] += $yadj; } // DIRECTIONALITY RTL if ((($blockdir == 'rtl') && ($contains_rtl )) || ($all_rtl )) { $this->restoreFont($font[$arraysize-1 - $k]); } else { $this->restoreFont( $font[ $k ] ); } $this->SetSpacing(($this->fixedlSpacing*_MPDFK)+$jcharspacing,($this->fixedlSpacing+$this->minwSpacing)*_MPDFK+$jws); // Now unset these values so they don't influence GetStringwidth below or in fn. Cell $this->fixedlSpacing = false; $this->minwSpacing = 0; // *********** SPAN BACKGROUND COLOR ***************** // if ($this->spanbgcolor) { $cor = $this->spanbgcolorarray; $this->SetFColor($cor); $save_fill = $fill; $spanfill = 1; $fill = 1; } // mPDF 5.3.61 if (!empty($this->spanborddet)) { if (strpos($contentB[$k],'L')!==false) $this->x += $this->spanborddet['L']['w']; if (strpos($contentB[$k],'L')===false) $this->spanborddet['L']['s'] = $this->spanborddet['L']['w'] = 0; if (strpos($contentB[$k],'R')===false) $this->spanborddet['R']['s'] = $this->spanborddet['R']['w'] = 0; } // WORD SPACING $stringWidth = $this->GetStringWidth($chunk ); $stringWidth += ( $this->charspacing * mb_strlen($chunk,$this->mb_enc ) / _MPDFK ); $stringWidth += ( $this->ws * mb_substr_count($chunk,' ',$this->mb_enc ) / _MPDFK ); if (isset($this->objectbuffer[$dirk])) { $stringWidth = $this->objectbuffer[$dirk]['OUTER-WIDTH']; } if ($stringWidth==0) { $stringWidth = 0.000001; } if ($k == $arraysize-1) { $stringWidth -= ( $this->charspacing / _MPDFK ); $this->Cell( $stringWidth, $lineHeight, $chunk, '', 1, '', $fill, $this->HREF, $currentx,0,0,'M', $fill, $af, $bf, true ); //mono-style line or last part (skips line) // mPDF 5.3.07 } else $this->Cell( $stringWidth, $lineHeight, $chunk, '', 0, '', $fill, $this->HREF, 0, 0,0,'M', $fill, $af, $bf, true );//first or middle part // mPDF 5.3.07 // mPDF 5.3.61 if (!empty($this->spanborddet)) { if (strpos($contentB[$k],'R')!==false && $k != $arraysize-1) $this->x += $this->spanborddet['R']['w']; } // *********** SPAN BACKGROUND COLOR OFF - RESET BLOCK BGCOLOR ***************** // if (isset($spanfill) && $spanfill) { $fill = $save_fill; $spanfill = 0; if ($fill) { $this->SetFColor($bcor); } } } if (!$is_table) { $this->maxPosR = max($this->maxPosR , ($this->w - $this->rMargin - $this->blk[$this->blklvl]['outer_right_margin'])); $this->maxPosL = min($this->maxPosL , ($this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'])); } // move on to the next line, reset variables, tack on saved content and current char $this->printobjectbuffer($is_table, $blockdir); $this->objectbuffer = array(); /*-- LISTS --*/ // LIST BULLETS/NUMBERS if ($is_list && is_array($this->bulletarray) && ($lineCount == 1) ) { $this->ResetSpacing(); $bull = $this->bulletarray; if (isset($bull['level']) && isset($bull['occur']) && isset($this->InlineProperties['LIST'][$bull['level']][$bull['occur']])) { $this->restoreInlineProperties($this->InlineProperties['LIST'][$bull['level']][$bull['occur']]); } if (isset($bull['level']) && isset($bull['occur']) && isset($bull['num']) && isset($this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]) && $this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]) { $this->restoreInlineProperties($this->InlineProperties['LISTITEM'][$bull['level']][$bull['occur']][$bull['num']]); } if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') { $this->bullet = true; $this->SetFont('czapfdingbats','',$this->FontSizePt/2.5); } else { $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); } // force output //Output bullet $this->x = $currentx; if (isset($bull['x'])) { $this->x += $bull['x']; } $this->y -= $lineHeight; if (is_array($bull['col'])) { $this->SetTColor($bull['col']); } if (isset($bull['txt'])) { $this->Cell($bull['w'], $lineHeight,$bull['txt'],'','',$bull['align'],0,'',0,-$this->cMarginL, -$this->cMarginR ); } if (isset($bull['font']) && $bull['font'] == 'czapfdingbats') { $this->bullet = false; } $this->x = $currentx; // Reset $this->y += $lineHeight; if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS* $this->bulletarray = array(); // prevents repeat of bullet/number if <li>....<br />.....</li> } /*-- END LISTS --*/ /*-- CSS-IMAGE-FLOAT --*/ // Update values if set to skipline if ($this->floatmargins) { $this->_advanceFloatMargins(); } /*-- END CSS-IMAGE-FLOAT --*/ // Reset lineheight $lineHeight = $this->divheight; $valign = 'M'; $this->restoreFont( $savedFont ); // mPDF 5.3.61 $lbw = $rbw = 0; // Border widths if (!empty($this->spanborddet)) { $lbw = $this->spanborddet['L']['w']; $rbw = $this->spanborddet['R']['w']; } $font = array(); $content = array(); $contentB = array(); // mPDF 5.3.61 $contentWidth = 0; if (!empty($savedObj)) { $this->objectbuffer[] = $savedObj; $font[] = $savedFont; $content[] = ''; $contentB[] = ''; $contentWidth += $savedObj['OUTER-WIDTH'] * _MPDFK; } $font[] = $savedFont; $content[] = $savedContent . $c; $contentB[] = $savedContentB ; // mPDF 5.3.61 $currContent =& $content[ (count($content)-1) ]; // CJK - strip CJK space at end of line // &#x3000; = \xe3\x80\x80 = CJK space if ($this->checkCJK && $currContent == "\xe3\x80\x80") { $currContent = '' ; } // *CJK-FONTS* $contentWidth += $this->GetStringWidth( $currContent ) * _MPDFK; // mPDF 5.3.61 if (strpos($savedContentB,'L')!==false) $contentWidth += $lbw; $cutoffWidth = $contentWidth; $CJKoverflow = false; } // another character will fit, so add it on else { $contentWidth += $cw; $currContent .= $c; } } unset($content); unset($contentB); // mPDF 5.3.61 } //----------------------END OF FLOWING BLOCK------------------------------------// /*-- CSS-IMAGE-FLOAT --*/ // Update values if set to skipline function _advanceFloatMargins() { // Update floatmargins - L if (isset($this->floatmargins['L']) && $this->floatmargins['L']['skipline'] && $this->floatmargins['L']['y0'] != $this->y) { $yadj = $this->y - $this->floatmargins['L']['y0']; $this->floatmargins['L']['y0'] = $this->y; $this->floatmargins['L']['y1'] += $yadj; // Update objattr in floatbuffer if ($this->floatbuffer[$this->floatmargins['L']['id']]['border_left']['w']) { $this->floatbuffer[$this->floatmargins['L']['id']]['BORDER-Y'] += $yadj; } $this->floatbuffer[$this->floatmargins['L']['id']]['INNER-Y'] += $yadj; $this->floatbuffer[$this->floatmargins['L']['id']]['OUTER-Y'] += $yadj; // Unset values $this->floatbuffer[$this->floatmargins['L']['id']]['skipline'] = false; $this->floatmargins['L']['skipline'] = false; $this->floatmargins['L']['id'] = ''; } // Update floatmargins - R if (isset($this->floatmargins['R']) && $this->floatmargins['R']['skipline'] && $this->floatmargins['R']['y0'] != $this->y) { $yadj = $this->y - $this->floatmargins['R']['y0']; $this->floatmargins['R']['y0'] = $this->y; $this->floatmargins['R']['y1'] += $yadj; // Update objattr in floatbuffer if ($this->floatbuffer[$this->floatmargins['R']['id']]['border_left']['w']) { $this->floatbuffer[$this->floatmargins['R']['id']]['BORDER-Y'] += $yadj; } $this->floatbuffer[$this->floatmargins['R']['id']]['INNER-Y'] += $yadj; $this->floatbuffer[$this->floatmargins['R']['id']]['OUTER-Y'] += $yadj; // Unset values $this->floatbuffer[$this->floatmargins['R']['id']]['skipline'] = false; $this->floatmargins['R']['skipline'] = false; $this->floatmargins['R']['id'] = ''; } } /*-- END CSS-IMAGE-FLOAT --*/ //////////////////////////////////////////////////////////////////////////////// // ADDED forcewrap - to call from inline OBJECT functions to breakwords if necessary in cell //////////////////////////////////////////////////////////////////////////////// function WordWrap(&$text, $maxwidth, $forcewrap = 0) { $biggestword=0; $toonarrow=false; $text = trim($text); if ($text==='') return 0; $space = $this->GetCharWidth(' ',false); // mPDF 5.3.04 $lines = explode("\n", $text); $text = ''; $count = 0; foreach ($lines as $line) { $words = explode(' ', $line); $width = 0; foreach ($words as $word) { $word = trim($word); $wordwidth = $this->GetStringWidth($word); //Warn user that maxwidth is insufficient if ($wordwidth > $maxwidth + 0.0001) { if ($wordwidth > $biggestword) { $biggestword = $wordwidth; } $toonarrow=true; // ADDED if ($forcewrap) { while($wordwidth > $maxwidth) { $chw = 0; // check width for ( $i = 0; $i < mb_strlen($word, $this->mb_enc ); $i++ ) { $chw = $this->GetStringWidth(mb_substr($word,0,$i+1,$this->mb_enc )); if ($chw > $maxwidth ) { if ($text) { $text = rtrim($text)."\n".mb_substr($word,0,$i,$this->mb_enc ); $count++; } else { $text = mb_substr($word,0,$i,$this->mb_enc ); } $word = mb_substr($word,$i,mb_strlen($word, $this->mb_enc )-$i,$this->mb_enc ); $wordwidth = $this->GetStringWidth($word); $width = $maxwidth; break; } } } } } if ($width + $wordwidth < $maxwidth - 0.0001) { $width += $wordwidth + $space; $text .= $word.' '; } else { $width = $wordwidth + $space; $text = rtrim($text)."\n".$word.' '; $count++; } } $text .= "\n"; $count++; } $text = rtrim($text); //Return -(wordsize) if word is bigger than maxwidth // ADDED if ($forcewrap) { return $count; } if (($toonarrow) && ($this->table_error_report)) { $this->Error("Word is too long to fit in table - ".$this->table_error_report_param); } if ($toonarrow) return -$biggestword; else return $count; } /*-- END HTML-CSS --*/ function _SetTextRendering($mode) { if (!(($mode == 0) || ($mode == 1) || ($mode == 2))) $this->Error("Text rendering mode should be 0, 1 or 2 (value : $mode)"); $tr = ($mode.' Tr'); if($this->page>0 && ((isset($this->pageoutput[$this->page]['TextRendering']) && $this->pageoutput[$this->page]['TextRendering'] != $tr) || !isset($this->pageoutput[$this->page]['TextRendering']) || $this->keep_block_together)) { $this->_out($tr); } $this->pageoutput[$this->page]['TextRendering'] = $tr; } function SetTextOutline($width, $col=0) { if ($width == false) //Now resets all values { $this->outline_on = false; $this->SetLineWidth(0.2); $this->SetDColor($this->ConvertColor(0)); $this->_SetTextRendering(0); $tr = ('0 Tr'); if($this->page>0 && ((isset($this->pageoutput[$this->page]['TextRendering']) && $this->pageoutput[$this->page]['TextRendering'] != $tr) || !isset($this->pageoutput[$this->page]['TextRendering']) || $this->keep_block_together)) { $this->_out($tr); } $this->pageoutput[$this->page]['TextRendering'] = $tr; } else { $this->SetLineWidth($width); $this->SetDColor($col); $tr = ('2 Tr'); if($this->page>0 && ((isset($this->pageoutput[$this->page]['TextRendering']) && $this->pageoutput[$this->page]['TextRendering'] != $tr) || !isset($this->pageoutput[$this->page]['TextRendering']) || $this->keep_block_together)) { $this->_out($tr); } $this->pageoutput[$this->page]['TextRendering'] = $tr; } } function Image($file,$x,$y,$w=0,$h=0,$type='',$link='',$paint=true, $constrain=true, $watermark=false, $shownoimg=true, $allowvector=true) { $orig_srcpath = $file; $this->GetFullPath($file); $info=$this->_getImage($file, true, $allowvector, $orig_srcpath ); if(!$info && $paint) { $info = $this->_getImage($this->noImageFile); if ($info) { $file = $this->noImageFile; $w = ($info['w'] * (25.4/$this->dpi)); // 14 x 16px $h = ($info['h'] * (25.4/$this->dpi)); // 14 x 16px } } if(!$info) return false; //Automatic width and height calculation if needed if($w==0 and $h==0) { /*-- IMAGES-WMF --*/ if ($info['type']=='wmf') { // WMF units are twips (1/20pt) // divide by 20 to get points // divide by k to get user units $w = abs($info['w'])/(20*_MPDFK); $h = abs($info['h']) / (20*_MPDFK); } else /*-- END IMAGES-WMF --*/ if ($info['type']=='svg') { // returned SVG units are pts // divide by k to get user units (mm) $w = abs($info['w'])/_MPDFK; $h = abs($info['h']) /_MPDFK; } else { //Put image at default image dpi $w=($info['w']/_MPDFK) * (72/$this->img_dpi); $h=($info['h']/_MPDFK) * (72/$this->img_dpi); } } if($w==0) $w=abs($h*$info['w']/$info['h']); if($h==0) $h=abs($w*$info['h']/$info['w']); /*-- WATERMARK --*/ if ($watermark) { $maxw = $this->w; $maxh = $this->h; // Size = D PF or array if (is_array($this->watermark_size)) { $w = $this->watermark_size[0]; $h = $this->watermark_size[1]; } else if (!is_string($this->watermark_size)) { $maxw -= $this->watermark_size*2; $maxh -= $this->watermark_size*2; $w = $maxw; $h=abs($w*$info['h']/$info['w']); if ($h > $maxh ) { $h = $maxh ; $w=abs($h*$info['w']/$info['h']); } } else if ($this->watermark_size == 'F') { if ($this->ColActive) { $maxw = $this->w - ($this->DeflMargin + $this->DefrMargin); } else { $maxw = $this->pgwidth; } $maxh = $this->h - ($this->tMargin + $this->bMargin); $w = $maxw; $h=abs($w*$info['h']/$info['w']); if ($h > $maxh ) { $h = $maxh ; $w=abs($h*$info['w']/$info['h']); } } else if ($this->watermark_size == 'P') { // Default P $w = $maxw; $h=abs($w*$info['h']/$info['w']); if ($h > $maxh ) { $h = $maxh ; $w=abs($h*$info['w']/$info['h']); } } // Automatically resize to maximum dimensions of page if too large if ($w > $maxw) { $w = $maxw; $h=abs($w*$info['h']/$info['w']); } if ($h > $maxh ) { $h = $maxh ; $w=abs($h*$info['w']/$info['h']); } // Position if (is_array($this->watermark_pos)) { $x = $this->watermark_pos[0]; $y = $this->watermark_pos[1]; } else if ($this->watermark_pos == 'F') { // centred on printable area if ($this->ColActive) { // *COLUMNS* if (($this->mirrorMargins) && (($this->page)%2==0)) { $xadj = $this->DeflMargin-$this->DefrMargin; } // *COLUMNS* else { $xadj = 0; } // *COLUMNS* $x = ($this->DeflMargin - $xadj + ($this->w - ($this->DeflMargin + $this->DefrMargin))/2) - ($w/2); // *COLUMNS* } // *COLUMNS* else { // *COLUMNS* $x = ($this->lMargin + ($this->pgwidth)/2) - ($w/2); } // *COLUMNS* $y = ($this->tMargin + ($this->h - ($this->tMargin + $this->bMargin))/2) - ($h/2); } else { // default P - centred on whole page $x = ($this->w/2) - ($w/2); $y = ($this->h/2) - ($h/2); } /*-- IMAGES-WMF --*/ if ($info['type']=='wmf') { $sx = $w*_MPDFK / $info['w']; $sy = -$h*_MPDFK / $info['h']; $outstring = sprintf('q %.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, $sy, $x*_MPDFK-$sx*$info['x'], (($this->h-$y)*_MPDFK)-$sy*$info['y'], $info['i']); } else /*-- END IMAGES-WMF --*/ if ($info['type']=='svg') { $sx = $w*_MPDFK / $info['w']; $sy = -$h*_MPDFK / $info['h']; $outstring = sprintf('q %.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, $sy, $x*_MPDFK-$sx*$info['x'], (($this->h-$y)*_MPDFK)-$sy*$info['y'], $info['i']); } else { $outstring = sprintf("q %.3F 0 0 %.3F %.3F %.3F cm /I%d Do Q",$w*_MPDFK,$h*_MPDFK,$x*_MPDFK,($this->h-($y+$h))*_MPDFK,$info['i']); } if ($this->watermarkImgBehind) { $outstring = $this->watermarkImgAlpha . "\n" . $outstring . "\n" . $this->SetAlpha(1, 'Normal', true) . "\n"; $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$outstring."\n".'\\1', $this->pages[$this->page]); } else { $this->_out($outstring); } return 0; } // end of IF watermark /*-- END WATERMARK --*/ if ($constrain) { // Automatically resize to maximum dimensions of page if too large if (isset($this->blk[$this->blklvl]['inner_width']) && $this->blk[$this->blklvl]['inner_width']) { $maxw = $this->blk[$this->blklvl]['inner_width']; } else { $maxw = $this->pgwidth; } if ($w > $maxw) { $w = $maxw; $h=abs($w*$info['h']/$info['w']); } if ($h > $this->h - ($this->tMargin + $this->bMargin + 1)) { // see below - +10 to avoid drawing too close to border of page $h = $this->h - ($this->tMargin + $this->bMargin + 1) ; if ($this->fullImageHeight) { $h = $this->fullImageHeight; } $w=abs($h*$info['w']/$info['h']); } //Avoid drawing out of the paper(exceeding width limits). //if ( ($x + $w) > $this->fw ) { if ( ($x + $w) > $this->w ) { $x = $this->lMargin; $y += 5; } $changedpage = false; $oldcolumn = $this->CurrCol; //Avoid drawing out of the page. if($y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) { $this->AddPage($this->CurOrientation); // Added to correct for OddEven Margins $x=$x +$this->MarginCorrection; $y = $tMargin + $this->margin_header; $changedpage = true; } /*-- COLUMNS --*/ // COLS // COLUMN CHANGE if ($this->CurrCol != $oldcolumn) { $y = $this->y0; $x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap); $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap); } /*-- END COLUMNS --*/ } // end of IF constrain /*-- IMAGES-WMF --*/ if ($info['type']=='wmf') { $sx = $w*_MPDFK / $info['w']; $sy = -$h*_MPDFK / $info['h']; $outstring = sprintf('q %.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, $sy, $x*_MPDFK-$sx*$info['x'], (($this->h-$y)*_MPDFK)-$sy*$info['y'], $info['i']); } else /*-- END IMAGES-WMF --*/ if ($info['type']=='svg') { $sx = $w*_MPDFK / $info['w']; $sy = -$h*_MPDFK / $info['h']; $outstring = sprintf('q %.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q', $sx, $sy, $x*_MPDFK-$sx*$info['x'], (($this->h-$y)*_MPDFK)-$sy*$info['y'], $info['i']); } else { $outstring = sprintf("q %.3F 0 0 %.3F %.3F %.3F cm /I%d Do Q",$w*_MPDFK,$h*_MPDFK,$x*_MPDFK,($this->h-($y+$h))*_MPDFK,$info['i']); } if($paint) { $this->_out($outstring); if($link) $this->Link($x,$y,$w,$h,$link); // Avoid writing text on top of the image. // THIS WAS OUTSIDE THE if ($paint) bit!!!!!!!!!!!!!!!! $this->y = $y + $h; } //Return width-height array $sizesarray['WIDTH'] = $w; $sizesarray['HEIGHT'] = $h; $sizesarray['X'] = $x; //Position before painting image $sizesarray['Y'] = $y; //Position before painting image $sizesarray['OUTPUT'] = $outstring; $sizesarray['IMAGE_ID'] = $info['i']; $sizesarray['itype'] = $info['type']; $sizesarray['set-dpi'] = $info['set-dpi']; return $sizesarray; } //============================================================= //============================================================= //============================================================= //============================================================= //============================================================= /*-- HTML-CSS --*/ function _getObjAttr($t) { $c = explode("\xbb\xa4\xac",$t,2); $c = explode(",",$c[1],2); foreach($c as $v) { $v = explode("=",$v,2); $sp[$v[0]] = $v[1]; } return (unserialize($sp['objattr'])); } function inlineObject($type,$x,$y,$objattr,$Lmargin,$widthUsed,$maxWidth,$lineHeight,$paint=false,$is_table=false) { if ($is_table) { $k = $this->shrin_k; } else { $k = 1; } // NB $x is only used when paint=true // Lmargin not used $w = 0; if (isset($objattr['width'])) { $w = $objattr['width']/$k; } $h = 0; if (isset($objattr['height'])) { $h = abs($objattr['height']/$k); } $widthLeft = $maxWidth - $widthUsed; $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 10) ; if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; } // For Images if (isset($objattr['border_left'])) { $extraWidth = ($objattr['border_left']['w'] + $objattr['border_right']['w'] + $objattr['margin_left']+ $objattr['margin_right'])/$k; $extraHeight = ($objattr['border_top']['w'] + $objattr['border_bottom']['w'] + $objattr['margin_top']+ $objattr['margin_bottom'])/$k; if ($type == 'image' || $type == 'barcode' || $type == 'textcircle') { // mPDF 5.3.A5 $extraWidth += ($objattr['padding_left'] + $objattr['padding_right'])/$k; $extraHeight += ($objattr['padding_top'] + $objattr['padding_bottom'])/$k; } } if (!isset($objattr['vertical-align'])) { $objattr['vertical-align'] = 'M'; } if ($type == 'image' || (isset($objattr['subtype']) && $objattr['subtype'] == 'IMAGE')) { if (isset($objattr['itype']) && ($objattr['itype'] == 'wmf' || $objattr['itype'] == 'svg')) { $file = $objattr['file']; $info=$this->formobjects[$file]; } else if (isset($objattr['file'])) { $file = $objattr['file']; $info=$this->images[$file]; } } if ($type == 'annot' || $type == 'bookmark' || $type == 'indexentry' || $type == 'toc') { $w = 0.00001; $h = 0.00001; } // TEST whether need to skipline if (!$paint) { if ($type == 'hr') { // always force new line if (($y + $h + $lineHeight > $this->PageBreakTrigger) && !$this->InFooter && !$is_table) { return array(-2, $w ,$h ); } // New page + new line else { return array(1, $w ,$h ); } // new line } else { if ($widthUsed > 0 && $w > $widthLeft && (!$is_table || $type != 'image')) { // New line needed if (($y + $h + $lineHeight > $this->PageBreakTrigger) && !$this->InFooter) { return array(-2,$w ,$h ); } // New page + new line return array(1,$w ,$h ); // new line } else if ($widthUsed > 0 && $w > $widthLeft && $is_table) { // New line needed in TABLE return array(1,$w ,$h ); // new line } // Will fit on line but NEW PAGE REQUIRED else if (($y + $h > $this->PageBreakTrigger) && !$this->InFooter && !$is_table) { return array(-1,$w ,$h ); } else { return array(0,$w ,$h ); } } } if ($type == 'annot' || $type == 'bookmark' || $type == 'indexentry' || $type == 'toc') { $w = 0.00001; $h = 0.00001; $objattr['BORDER-WIDTH'] = 0; $objattr['BORDER-HEIGHT'] = 0; $objattr['BORDER-X'] = $x; $objattr['BORDER-Y'] = $y; $objattr['INNER-WIDTH'] = 0; $objattr['INNER-HEIGHT'] = 0; $objattr['INNER-X'] = $x; $objattr['INNER-Y'] = $y; } if ($type == 'image') { // Automatically resize to width remaining if ($w > $widthLeft && !$is_table) { $w = $widthLeft ; $h=abs($w*$info['h']/$info['w']); } $img_w = $w - $extraWidth ; $img_h = $h - $extraHeight ; $objattr['BORDER-WIDTH'] = $img_w + $objattr['padding_left']/$k + $objattr['padding_right']/$k + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ; $objattr['BORDER-HEIGHT'] = $img_h + $objattr['padding_top']/$k + $objattr['padding_bottom']/$k + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ; $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ; $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ; $objattr['INNER-WIDTH'] = $img_w; $objattr['INNER-HEIGHT'] = $img_h; $objattr['INNER-X'] = $x + $objattr['padding_left']/$k + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k); $objattr['INNER-Y'] = $y + $objattr['padding_top']/$k + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ; $objattr['ID'] = $info['i']; } if ($type == 'input' && $objattr['subtype'] == 'IMAGE') { $img_w = $w - $extraWidth ; $img_h = $h - $extraHeight ; $objattr['BORDER-WIDTH'] = $img_w + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ; $objattr['BORDER-HEIGHT'] = $img_h + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ; $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ; $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ; $objattr['INNER-WIDTH'] = $img_w; $objattr['INNER-HEIGHT'] = $img_h; $objattr['INNER-X'] = $x + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k); $objattr['INNER-Y'] = $y + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ; $objattr['ID'] = $info['i']; } if ($type == 'barcode' || $type == 'textcircle') { // mPDF 5.3.A5 $b_w = $w - $extraWidth ; $b_h = $h - $extraHeight ; $objattr['BORDER-WIDTH'] = $b_w + $objattr['padding_left']/$k + $objattr['padding_right']/$k + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ; $objattr['BORDER-HEIGHT'] = $b_h + $objattr['padding_top']/$k + $objattr['padding_bottom']/$k + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ; $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ; $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ; $objattr['INNER-X'] = $x + $objattr['padding_left']/$k + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k); $objattr['INNER-Y'] = $y + $objattr['padding_top']/$k + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ; $objattr['INNER-WIDTH'] = $b_w; $objattr['INNER-HEIGHT'] = $b_h; } if ($type == 'textarea') { // Automatically resize to width remaining if ($w > $widthLeft && !$is_table) { $w = $widthLeft ; } if (($y + $h > $this->PageBreakTrigger) && !$this->InFooter) { $h=$this->h - $y - $this->bMargin; } } if ($type == 'hr') { if ($is_table) { $objattr['INNER-WIDTH'] = $maxWidth * $objattr['W-PERCENT']/100; $objattr['width'] = $objattr['INNER-WIDTH']; $w = $maxWidth; } else { if ($w>$maxWidth) { $w = $maxWidth; } $objattr['INNER-WIDTH'] = $w; $w = $maxWidth; } } if (($type == 'select') || ($type == 'input' && ($objattr['subtype'] == 'TEXT' || $objattr['subtype'] == 'PASSWORD'))) { // Automatically resize to width remaining if ($w > $widthLeft && !$is_table) { $w = $widthLeft; } } if ($type == 'textarea' || $type == 'select' || $type == 'input') { if (isset($objattr['fontsize'])) $objattr['fontsize'] /= $k; if (isset($objattr['linewidth'])) $objattr['linewidth'] /= $k; } if (!isset($objattr['BORDER-Y'])) { $objattr['BORDER-Y'] = 0; } if (!isset($objattr['BORDER-X'])) { $objattr['BORDER-X'] = 0; } if (!isset($objattr['INNER-Y'])) { $objattr['INNER-Y'] = 0; } if (!isset($objattr['INNER-X'])) { $objattr['INNER-X'] = 0; } //Return width-height array $objattr['OUTER-WIDTH'] = $w; $objattr['OUTER-HEIGHT'] = $h; $objattr['OUTER-X'] = $x; $objattr['OUTER-Y'] = $y; return $objattr; } /*-- END HTML-CSS --*/ //============================================================= //============================================================= //============================================================= //============================================================= //============================================================= function SetLineJoin($mode=0) { $s=sprintf('%d j',$mode); if($this->page>0 && ((isset($this->pageoutput[$this->page]['LineJoin']) && $this->pageoutput[$this->page]['LineJoin'] != $s) || !isset($this->pageoutput[$this->page]['LineJoin']) || $this->keep_block_together)) { $this->_out($s); } $this->pageoutput[$this->page]['LineJoin'] = $s; } function SetLineCap($mode=2) { $s=sprintf('%d J',$mode); if($this->page>0 && ((isset($this->pageoutput[$this->page]['LineCap']) && $this->pageoutput[$this->page]['LineCap'] != $s) || !isset($this->pageoutput[$this->page]['LineCap']) || $this->keep_block_together)) { $this->_out($s); } $this->pageoutput[$this->page]['LineCap'] = $s; } function SetDash($black=false,$white=false) { if($black and $white) $s=sprintf('[%.3F %.3F] 0 d',$black*_MPDFK,$white*_MPDFK); else $s='[] 0 d'; if($this->page>0 && ((isset($this->pageoutput[$this->page]['Dash']) && $this->pageoutput[$this->page]['Dash'] != $s) || !isset($this->pageoutput[$this->page]['Dash']) || $this->keep_block_together)) { $this->_out($s); } $this->pageoutput[$this->page]['Dash'] = $s; } function SetDisplayPreferences($preferences) { // String containing any or none of /HideMenubar/HideToolbar/HideWindowUI/DisplayDocTitle/CenterWindow/FitWindow $this->DisplayPreferences .= $preferences; } function Ln($h='',$collapsible=0) { // Added collapsible to allow collapsible top-margin on new page //Line feed; default value is last cell height $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin']; if ($collapsible && ($this->y==$this->tMargin) && (!$this->ColActive)) { $h = 0; } if(is_string($h)) $this->y+=$this->lasth; else $this->y+=$h; } /*-- HTML-CSS --*/ // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom function DivLn($h,$level=-3,$move_y=true,$collapsible=false,$state=0) { // this->x is returned as it was // adds lines (y) where DIV bgcolors are filled in // allows .00001 as nominal height used for bookmarks/annotations etc. if ($collapsible && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->tMargin)) && (!$this->ColActive)) { return; } if ($collapsible && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->y0)) && ($this->ColActive) && $this->CurrCol == 0) { return; } // *COLUMNS* // Still use this method if columns or page-break-inside: avoid, as it allows repositioning later // otherwise, now uses PaintDivBB() if (!$this->ColActive && !$this->keep_block_together && !$this->kwt) { if ($move_y && !$this->ColActive) { $this->y += $h; } return; } if ($level == -3) { $level = $this->blklvl; } $firstblockfill = $this->GetFirstBlockFill(); if ($firstblockfill && $this->blklvl > 0 && $this->blklvl >= $firstblockfill) { $last_x = 0; $last_w = 0; $last_fc = $this->FillColor; $bak_x = $this->x; $bak_h = $this->divheight; $this->divheight = 0; // Temporarily turn off divheight - as Cell() uses it to check for PageBreak for ($blvl=$firstblockfill;$blvl<=$level;$blvl++) { $this->SetBlockFill($blvl); $this->x = $this->lMargin + $this->blk[$blvl]['outer_left_margin']; if ($last_x != $this->lMargin + $this->blk[$blvl]['outer_left_margin'] || $last_w != $this->blk[$blvl]['width'] || $last_fc != $this->FillColor) { $x = $this->x; $this->Cell( ($this->blk[$blvl]['width']), $h, '', '', 0, '', 1); if (!$this->keep_block_together && !$this->writingHTMLheader && !$this->writingHTMLfooter) { $this->x = $x; // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom if ($blvl == $this->blklvl) { $this->PaintDivLnBorder($state,$blvl,$h); } else { $this->PaintDivLnBorder(0,$blvl,$h); } } } $last_x = $this->lMargin + $this->blk[$blvl]['outer_left_margin']; $last_w = $this->blk[$blvl]['width']; $last_fc = $this->FillColor; } // Reset current block fill if (isset($this->blk[$this->blklvl]['bgcolorarray'])) { $bcor = $this->blk[$this->blklvl]['bgcolorarray']; $this->SetFColor($bcor); } $this->x = $bak_x; $this->divheight = $bak_h; } if ($move_y) { $this->y += $h; } } /*-- END HTML-CSS --*/ function SetX($x) { //Set x position if($x >= 0) $this->x=$x; else $this->x = $this->w + $x; } function SetY($y) { //Set y position and reset x $this->x=$this->lMargin; if($y>=0) $this->y=$y; else $this->y=$this->h+$y; } function SetXY($x,$y) { //Set x and y positions $this->SetY($y); $this->SetX($x); } function Output($name='',$dest='') { //Output PDF to some destination if ($this->showStats) { echo '<div>Generated in '.sprintf('%.2F',(microtime(true) - $this->time0)).' seconds</div>'; } //Finish document if necessary if ($this->progressBar) { $this->UpdateProgressBar(1,'100','Finished'); } // *PROGRESS-BAR* if($this->state < 3) $this->Close(); if ($this->progressBar) { $this->UpdateProgressBar(2,'100','Finished'); } // *PROGRESS-BAR* // fn. error_get_last is only in PHP>=5.2 if ($this->debug && function_exists('error_get_last') && error_get_last()) { $e = error_get_last(); if (($e['type'] < 2048 && $e['type'] != 8) || (intval($e['type']) & intval(ini_get("error_reporting")))) { echo "<p>Error message detected - PDF file generation aborted.</p>"; echo $e['message'].'<br />'; echo 'File: '.$e['file'].'<br />'; echo 'Line: '.$e['line'].'<br />'; exit; } } if (($this->PDFA || $this->PDFX) && $this->encrypted) { $this->Error("PDFA1-b or PDFX/1-a does not permit encryption of documents."); } if (count($this->PDFAXwarnings) && (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto))) { if ($this->PDFA) { echo '<div>WARNING - This file could not be generated as it stands as a PDFA1-b compliant file.</div>'; echo '<div>These issues can be automatically fixed by mPDF using <i>$mpdf-&gt;PDFAauto=true;</i></div>'; echo '<div>Action that mPDF will take to automatically force PDFA1-b compliance are shown in brackets.</div>'; } else { echo '<div>WARNING - This file could not be generated as it stands as a PDFX/1-a compliant file.</div>'; echo '<div>These issues can be automatically fixed by mPDF using <i>$mpdf-&gt;PDFXauto=true;</i></div>'; echo '<div>Action that mPDF will take to automatically force PDFX/1-a compliance are shown in brackets.</div>'; } echo '<div>Warning(s) generated:</div><ul>'; $this->PDFAXwarnings = array_unique($this->PDFAXwarnings); foreach($this->PDFAXwarnings AS $w) { echo '<li>'.$w.'</li>'; } echo '</ul>'; exit; } if ($this->showStats) { echo '<div>Compiled in '.sprintf('%.2F',(microtime(true) - $this->time0)).' seconds (total)</div>'; echo '<div>Peak Memory usage '.number_format((memory_get_peak_usage(true)/(1024*1024)),2).' MB</div>'; echo '<div>PDF file size '.number_format((strlen($this->buffer)/1024)).' kB</div>'; echo '<div>Number of fonts '.count($this->fonts).'</div>'; exit; } if(is_bool($dest)) $dest=$dest ? 'D' : 'F'; $dest=strtoupper($dest); if($dest=='') { if($name=='') { $name='mpdf.pdf'; $dest='I'; } else { $dest='F'; } } /*-- PROGRESS-BAR --*/ if ($this->progressBar && ($dest=='D' || $dest=='I')) { if($name=='') { $name='mpdf.pdf'; } $tempfile = '_tempPDF'.RAND(1,10000); //Save to local file $f=fopen(_MPDF_TEMP_PATH.$tempfile.'.pdf','wb'); if(!$f) $this->Error('Unable to create temporary output file: '.$tempfile.'.pdf'); fwrite($f,$this->buffer,strlen($this->buffer)); fclose($f); $this->UpdateProgressBar(3,'','Finished'); echo '<script type="text/javascript"> var form = document.createElement("form"); form.setAttribute("method", "post"); form.setAttribute("action", "'._MPDF_URI.'includes/out.php"); var hiddenField = document.createElement("input"); hiddenField.setAttribute("type", "hidden"); hiddenField.setAttribute("name", "filename"); hiddenField.setAttribute("value", "'.$tempfile.'"); form.appendChild(hiddenField); var hiddenField = document.createElement("input"); hiddenField.setAttribute("type", "hidden"); hiddenField.setAttribute("name", "dest"); hiddenField.setAttribute("value", "'.$dest.'"); form.appendChild(hiddenField); var hiddenField = document.createElement("input"); hiddenField.setAttribute("type", "hidden"); hiddenField.setAttribute("name", "opname"); hiddenField.setAttribute("value", "'.$name.'"); form.appendChild(hiddenField); var hiddenField = document.createElement("input"); hiddenField.setAttribute("type", "hidden"); hiddenField.setAttribute("name", "path"); hiddenField.setAttribute("value", "'.urlencode(_MPDF_TEMP_PATH).'"); form.appendChild(hiddenField); document.body.appendChild(form); form.submit(); </script> </div> </body> </html>'; exit; } else { if ($this->progressBar) { $this->UpdateProgressBar(3,'','Finished'); } /*-- END PROGRESS-BAR --*/ switch($dest) { case 'I': if ($this->debug && !$this->allow_output_buffering && ob_get_contents()) { echo "<p>Output has already been sent from the script - PDF file generation aborted.</p>"; exit; } //Send to standard output if(PHP_SAPI!='cli') { //We send to a browser header('Content-Type: application/pdf'); if(headers_sent()) $this->Error('Some data has already been output to browser, can\'t send PDF file'); if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) { // don't use length if server using compression header('Content-Length: '.strlen($this->buffer)); } header('Content-disposition: inline; filename="'.$name.'"'); header('Cache-Control: public, must-revalidate, max-age=0'); header('Pragma: public'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); } echo $this->buffer; break; case 'D': //Download file header('Content-Description: File Transfer'); if (headers_sent()) $this->Error('Some data has already been output to browser, can\'t send PDF file'); header('Content-Transfer-Encoding: binary'); header('Cache-Control: public, must-revalidate, max-age=0'); header('Pragma: public'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); header('Content-Type: application/force-download'); header('Content-Type: application/octet-stream', false); header('Content-Type: application/download', false); header('Content-Type: application/pdf', false); if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) { // don't use length if server using compression header('Content-Length: '.strlen($this->buffer)); } header('Content-disposition: attachment; filename="'.$name.'"'); echo $this->buffer; break; case 'F': //Save to local file $f=fopen($name,'wb'); if(!$f) $this->Error('Unable to create output file: '.$name); fwrite($f,$this->buffer,strlen($this->buffer)); fclose($f); break; case 'S': //Return as a string return $this->buffer; default: $this->Error('Incorrect output destination: '.$dest); } } // *PROGRESS-BAR* //====================================================================================================== // mPDF 5.3.79 // DELETE OLD TMP FILES - Housekeeping // Delete any files in tmp/ directory that are >1 hrs old $interval = 3600; if ($handle = opendir(preg_replace('/\/$/','',_MPDF_TEMP_PATH))) { while (false !== ($file = readdir($handle))) { if (((filemtime(_MPDF_TEMP_PATH.$file)+$interval) < time()) && ($file != "..") && ($file != ".")) { unlink(_MPDF_TEMP_PATH.$file); } } closedir($handle); } //============================================================================================================== return ''; } // ***************************************************************************** // * // Protected methods * // * // ***************************************************************************** function _dochecks() { //Check for locale-related bug if(1.1==1) $this->Error('Don\'t alter the locale before including mPDF'); //Check for decimal separator if(sprintf('%.1f',1.0)!='1.0') setlocale(LC_NUMERIC,'C'); } function _begindoc() { //Start document $this->state=1; $this->_out('%PDF-'.$this->pdf_version); $this->_out('%'.chr(226).chr(227).chr(207).chr(211)); // 4 chars > 128 to show binary file } /*-- HTMLHEADERS-FOOTERS --*/ function _puthtmlheaders() { $this->state=2; $nb=$this->page; for($n=1;$n<=$nb;$n++) { if ($this->mirrorMargins && $n%2==0) { $OE = 'E'; } // EVEN else { $OE = 'O'; } $this->page = $n; if (isset($this->saveHTMLHeader[$n][$OE])) { $html = $this->saveHTMLHeader[$n][$OE]['html']; $this->lMargin = $this->saveHTMLHeader[$n][$OE]['ml']; $this->rMargin = $this->saveHTMLHeader[$n][$OE]['mr']; $this->tMargin = $this->saveHTMLHeader[$n][$OE]['mh']; $this->bMargin = $this->saveHTMLHeader[$n][$OE]['mf']; $this->margin_header = $this->saveHTMLHeader[$n][$OE]['mh']; $this->margin_footer = $this->saveHTMLHeader[$n][$OE]['mf']; $this->w = $this->saveHTMLHeader[$n][$OE]['pw']; $this->h = $this->saveHTMLHeader[$n][$OE]['ph']; $rotate = (isset($this->saveHTMLHeader[$n][$OE]['rotate']) ? $this->saveHTMLHeader[$n][$OE]['rotate'] : null); $this->Reset(); $this->pageoutput[$n] = array(); $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $this->x = $this->lMargin; $this->y = $this->margin_header; $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($n).$this->pagenumSuffix,$html); $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($n).$this->nbpgSuffix,$html ); // {nbpg} $html = str_replace($this->aliasNbPg,$nb,$html ); // {nb} $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html ); $this->HTMLheaderPageLinks = array(); $this->HTMLheaderPageAnnots = array(); $this->HTMLheaderPageForms = array(); $this->pageBackgrounds = array(); $this->writingHTMLheader = true; $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer $this->writingHTMLheader = false; $this->Reset(); $this->pageoutput[$n] = array(); $s = $this->PrintPageBackgrounds(); $this->headerbuffer = $s . $this->headerbuffer; $os = ''; if ($rotate) { $os .= sprintf('q 0 -1 1 0 0 %.3F cm ',($this->w*_MPDFK)); } $os .= $this->headerbuffer ; if ($rotate) { $os .= ' Q' . "\n"; } // Writes over the page background but behind any other output on page $os = preg_replace('/\\\\/','\\\\\\\\',$os); $this->pages[$n] = preg_replace('/(___HEADER___MARKER'.date('jY').')/', "\n".$os."\n".'\\1', $this->pages[$n]); $lks = $this->HTMLheaderPageLinks; foreach($lks AS $lk) { if ($rotate) { $lw = $lk[2]; $lh = $lk[3]; $lk[2] = $lh; $lk[3] = $lw; // swap width and height $ax = $lk[0]/_MPDFK; $ay = $lk[1]/_MPDFK; $bx = $ay-($lh/_MPDFK); $by = $this->w-$ax; $lk[0] = $bx*_MPDFK; $lk[1] = ($this->h-$by)*_MPDFK - $lw; } $this->PageLinks[$n][]=$lk; } /*-- FORMS --*/ foreach($this->HTMLheaderPageForms AS $f) { $this->form->forms[$f['n']] = $f; } /*-- END FORMS --*/ } if (isset($this->saveHTMLFooter[$n][$OE])) { $html = $this->saveHTMLFooter[$this->page][$OE]['html']; $this->lMargin = $this->saveHTMLFooter[$n][$OE]['ml']; $this->rMargin = $this->saveHTMLFooter[$n][$OE]['mr']; $this->tMargin = $this->saveHTMLFooter[$n][$OE]['mh']; $this->bMargin = $this->saveHTMLFooter[$n][$OE]['mf']; $this->margin_header = $this->saveHTMLFooter[$n][$OE]['mh']; $this->margin_footer = $this->saveHTMLFooter[$n][$OE]['mf']; $this->w = $this->saveHTMLFooter[$n][$OE]['pw']; $this->h = $this->saveHTMLFooter[$n][$OE]['ph']; $rotate = (isset($this->saveHTMLFooter[$n][$OE]['rotate']) ? $this->saveHTMLFooter[$n][$OE]['rotate'] : null); $this->Reset(); $this->pageoutput[$n] = array(); $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $this->x = $this->lMargin; $top_y = $this->y = $this->h - $this->margin_footer; // if bottom-margin==0, corrects to avoid division by zero if ($this->y == $this->h) { $top_y = $this->y = ($this->h - 0.1); } $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($n).$this->pagenumSuffix,$html); $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($n).$this->nbpgSuffix,$html ); // {nbpg} $html = str_replace($this->aliasNbPg,$nb,$html ); // {nb} $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html ); $this->HTMLheaderPageLinks = array(); $this->HTMLheaderPageAnnots = array(); $this->HTMLheaderPageForms = array(); $this->pageBackgrounds = array(); $this->writingHTMLfooter = true; $this->InFooter = true; $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer $this->writingHTMLfooter = false; $this->InFooter = false; $this->Reset(); $this->pageoutput[$n] = array(); $fheight = $this->y - $top_y; $adj = -$fheight; $s = $this->PrintPageBackgrounds(-$adj); $this->headerbuffer = $s . $this->headerbuffer; $os = ''; $os .= $this->StartTransform(true)."\n"; if ($rotate) { $os .= sprintf('q 0 -1 1 0 0 %.3F cm ',($this->w*_MPDFK)); } $os .= $this->transformTranslate(0, $adj, true)."\n"; $os .= $this->headerbuffer ; if ($rotate) { $os .= ' Q' . "\n"; } $os .= $this->StopTransform(true)."\n"; // Writes over the page background but behind any other output on page $os = preg_replace('/\\\\/','\\\\\\\\',$os); $this->pages[$n] = preg_replace('/(___HEADER___MARKER'.date('jY').')/', "\n".$os."\n".'\\1', $this->pages[$n]); $lks = $this->HTMLheaderPageLinks; foreach($lks AS $lk) { $lk[1] -= $adj*_MPDFK; if ($rotate) { $lw = $lk[2]; $lh = $lk[3]; $lk[2] = $lh; $lk[3] = $lw; // swap width and height $ax = $lk[0]/_MPDFK; $ay = $lk[1]/_MPDFK; $bx = $ay-($lh/_MPDFK); $by = $this->w-$ax; $lk[0] = $bx*_MPDFK; $lk[1] = ($this->h-$by)*_MPDFK - $lw; } $this->PageLinks[$n][]=$lk; } /*-- FORMS --*/ foreach($this->HTMLheaderPageForms AS $f) { $f['y'] += $adj; $this->form->forms[$f['n']] = $f; } /*-- END FORMS --*/ } } $this->page=$nb; $this->state=1; } /*-- END HTMLHEADERS-FOOTERS --*/ function _putpages() { $nb=$this->page; $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; if($this->DefOrientation=='P') { $defwPt=$this->fwPt; $defhPt=$this->fhPt; } else { $defwPt=$this->fhPt; $defhPt=$this->fwPt; } $annotid=(3+2*$nb); // Active Forms $totaladdnum = 0; for($n=1;$n<=$nb;$n++) { if (isset($this->PageLinks[$n])) { $totaladdnum += count($this->PageLinks[$n]); } /*-- ANNOTATIONS --*/ if (isset($this->PageAnnots[$n])) { foreach ($this->PageAnnots[$n] as $k => $pl) { if (!empty($pl['opt']['popup']) || !empty($pl['opt']['file'])) { $totaladdnum += 2 ; } else { $totaladdnum++; } } } /*-- END ANNOTATIONS --*/ /*-- FORMS --*/ if ( count($this->form->forms) > 0 ) { $this->form->countPageForms($n, $totaladdnum); } /*-- END FORMS --*/ } /*-- FORMS --*/ // Make a note in the radio button group of the obj_id it will have $ctr = 0; if (count($this->form->form_radio_groups)) { foreach($this->form->form_radio_groups AS $name=>$frg) { $this->form->form_radio_groups[$name]['obj_id'] = $annotid + $totaladdnum + $ctr; $ctr++; } } /*-- END FORMS --*/ // mPDF 5.3.99 // Select unused fonts (usually default font) $unused = array(); foreach($this->fonts as $fk=>$font) { if (!$font['used'] && ($font['type']=='TTF')) { $unused[] = $fk; } } for($n=1;$n<=$nb;$n++) { $thispage = $this->pages[$n]; // mPDF 5.3.99 unset($this->pages[$n]); // mPDF 5.3.99 if(isset($this->OrientationChanges[$n])) { $hPt=$this->pageDim[$n]['w']*_MPDFK; $wPt=$this->pageDim[$n]['h']*_MPDFK; $owidthPt_LR = $this->pageDim[$n]['outer_width_TB']*_MPDFK; $owidthPt_TB = $this->pageDim[$n]['outer_width_LR']*_MPDFK; } else { $wPt=$this->pageDim[$n]['w']*_MPDFK; $hPt=$this->pageDim[$n]['h']*_MPDFK; $owidthPt_LR = $this->pageDim[$n]['outer_width_LR']*_MPDFK; $owidthPt_TB = $this->pageDim[$n]['outer_width_TB']*_MPDFK; } // mPDF 5.3.99 // Remove references to unused fonts (usually default font) foreach($unused as $fk) { if ($this->fonts[$fk]['sip'] || $this->fonts[$fk]['smp']) { foreach($this->fonts[$fk]['subsetfontids'] AS $k => $fid) { $thispage = preg_replace('/\s\/F'.$fid.' \d[\d.]* Tf\s/is',' ',$thispage); } } else { $thispage = preg_replace('/\s\/F'.$this->fonts[$fk]['i'].' \d[\d.]* Tf\s/is',' ',$thispage); } } //Replace number of pages if(!empty($this->aliasNbPg)) { if (!$this->onlyCoreFonts) { $s1 = $this->UTF8ToUTF16BE($this->aliasNbPg, false); } // mPDF 5.3.22 $s2 = $this->aliasNbPg; if (!$this->onlyCoreFonts) { $r1 = $this->UTF8ToUTF16BE($nb, false); } // mPDF 5.3.22 $r2 = $nb; if (preg_match_all('/{mpdfheadernbpg (C|R) ff=(\S*) fs=(\S*) fz=(.*?)}/',$thispage,$m)) { for($hi=0;$hi<count($m[0]);$hi++) { $pos = $m[1][$hi]; $hff = $m[2][$hi]; $hfst = $m[3][$hi]; $hfsz = $m[4][$hi]; $this->SetFont($hff,$hfst,$hfsz, false); $x1 = $this->GetStringWidth($this->aliasNbPg); $x2 = $this->GetStringWidth($nb); $xadj = $x1 - $x2; if ($pos=='C') { $xadj /= 2; } $rep = sprintf(' q 1 0 0 1 %.3F 0 cm ', $xadj*_MPDFK); $thispage = str_replace($m[0][$hi], $rep, $thispage); } } if (!$this->onlyCoreFonts) { $thispage=str_replace($s1,$r1,$thispage); } // mPDF 5.3.22 $thispage=str_replace($s2,$r2,$thispage); // mPDF 5.3.22 // And now for any SMP/SIP fonts subset using <HH> format $r = ''; $nstr = "$nb"; for($i=0;$i<strlen($nstr);$i++) { $r .= sprintf("%02s", strtoupper(dechex(intval($nstr[$i])+48))); } $thispage=str_replace($this->aliasNbPgHex,$r,$thispage); } //Replace number of pages in group if(!empty($this->aliasNbPgGp)) { if (!$this->onlyCoreFonts) { $s1 = $this->UTF8ToUTF16BE($this->aliasNbPgGp, false); } // mPDF 5.3.22 $s2 = $this->aliasNbPgGp; $nbt = $this->docPageNumTotal($n); if (!$this->onlyCoreFonts) { $r1 = $this->UTF8ToUTF16BE($nbt, false); } // mPDF 5.3.22 $r2 = $nbt; if (preg_match_all('/{mpdfheadernbpggp (C|R) ff=(\S*) fs=(\S*) fz=(.*?)}/',$thispage,$m)) { for($hi=0;$hi<count($m[0]);$hi++) { $pos = $m[1][$hi]; $hff = $m[2][$hi]; $hfst = $m[3][$hi]; $hfsz = $m[4][$hi]; $this->SetFont($hff,$hfst,$hfsz, false); $x1 = $this->GetStringWidth($this->aliasNbPgGp); $x2 = $this->GetStringWidth($nbt); $xadj = $x1 - $x2; if ($pos=='C') { $xadj /= 2; } $rep = sprintf(' q 1 0 0 1 %.3F 0 cm ', $xadj*_MPDFK); $thispage = str_replace($m[0][$hi], $rep, $thispage); } } if (!$this->onlyCoreFonts) { $thispage=str_replace($s1,$r1,$thispage); } // mPDF 5.3.22 $thispage=str_replace($s2,$r2,$thispage); // And now for any SMP/SIP fonts subset using <HH> format $r = ''; $nstr = "$nbt"; for($i=0;$i<strlen($nstr);$i++) { $r .= sprintf("%02s", strtoupper(dechex(intval($nstr[$i])+48))); } $thispage=str_replace($this->aliasNbPgGpHex,$r,$thispage); } $thispage = preg_replace('/(\s*___BACKGROUND___PATTERNS'.date('jY').'\s*)/', " ", $thispage); $thispage = preg_replace('/(\s*___HEADER___MARKER'.date('jY').'\s*)/', " ", $thispage); $thispage = preg_replace('/(\s*___PAGE___START'.date('jY').'\s*)/', " ", $thispage); $thispage = preg_replace('/(\s*___TABLE___BACKGROUNDS'.date('jY').'\s*)/', " ", $thispage); //Page $this->_newobj(); $this->_out('<</Type /Page'); $this->_out('/Parent 1 0 R'); if(isset($this->OrientationChanges[$n])) { $this->_out(sprintf('/MediaBox [0 0 %.3F %.3F]',$hPt,$wPt)); //If BleedBox is defined, it must be larger than the TrimBox, but smaller than the MediaBox $bleedMargin = $this->pageDim[$n]['bleedMargin']*_MPDFK; if ($bleedMargin && ($owidthPt_TB || $owidthPt_LR)) { $x0 = $owidthPt_TB-$bleedMargin; $y0 = $owidthPt_LR-$bleedMargin; $x1 = $hPt-$owidthPt_TB+$bleedMargin; $y1 = $wPt-$owidthPt_LR+$bleedMargin; $this->_out(sprintf('/BleedBox [%.3F %.3F %.3F %.3F]', $x0, $y0, $x1, $y1)); } $this->_out(sprintf('/TrimBox [%.3F %.3F %.3F %.3F]', $owidthPt_TB, $owidthPt_LR, ($hPt-$owidthPt_TB), ($wPt-$owidthPt_LR))); if (isset($this->OrientationChanges[$n]) && $this->displayDefaultOrientation) { if ($this->DefOrientation=='P') { $this->_out('/Rotate 270'); } else { $this->_out('/Rotate 90'); } } } //else if($wPt != $defwPt || $hPt != $defhPt) { else { $this->_out(sprintf('/MediaBox [0 0 %.3F %.3F]',$wPt,$hPt)); $bleedMargin = $this->pageDim[$n]['bleedMargin']*_MPDFK; if ($bleedMargin && ($owidthPt_TB || $owidthPt_LR)) { $x0 = $owidthPt_LR-$bleedMargin; $y0 = $owidthPt_TB-$bleedMargin; $x1 = $wPt-$owidthPt_LR+$bleedMargin; $y1 = $hPt-$owidthPt_TB+$bleedMargin; $this->_out(sprintf('/BleedBox [%.3F %.3F %.3F %.3F]', $x0, $y0, $x1, $y1)); } $this->_out(sprintf('/TrimBox [%.3F %.3F %.3F %.3F]', $owidthPt_LR, $owidthPt_TB, ($wPt-$owidthPt_LR), ($hPt-$owidthPt_TB))); } $this->_out('/Resources 2 0 R'); // Important to keep in RGB colorSpace when using transparency if (!$this->PDFA && !$this->PDFX) { if ($this->restrictColorSpace == 3) $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceCMYK >> '); else if ($this->restrictColorSpace == 1) $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceGray >> '); else $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceRGB >> '); } $annotsnum = 0; if (isset($this->PageLinks[$n])) { $annotsnum += count($this->PageLinks[$n]); } /*-- ANNOTATIONS --*/ if (isset($this->PageAnnots[$n])) { foreach ($this->PageAnnots[$n] as $k => $pl) { if (!empty($pl['opt']['popup']) || !empty($pl['opt']['file'])) { $annotsnum += 2 ; } else { $annotsnum++; } $this->PageAnnots[$n][$k]['pageobj'] = $this->n; } } /*-- END ANNOTATIONS --*/ /*-- FORMS --*/ // Active Forms $formsnum = 0; if ( count($this->form->forms) > 0 ) { foreach( $this->form->forms as $val ) { if ( $val['page'] == $n ) $formsnum++; } } /*-- END FORMS --*/ if ($annotsnum || $formsnum) { $s = '/Annots [ '; for($i=0;$i<$annotsnum;$i++) { $s .= ($annotid + $i) . ' 0 R '; } $annotid += $annotsnum; /*-- FORMS --*/ if ( count($this->form->forms) > 0 ) { $this->form->addFormIds($n, $s, $annotid); } /*-- END FORMS --*/ $s .= '] '; $this->_out($s); } $this->_out('/Contents '.($this->n+1).' 0 R>>'); $this->_out('endobj'); //Page content $this->_newobj(); $p=($this->compress) ? gzcompress($thispage) : $thispage; $this->_out('<<'.$filter.'/Length '.strlen($p).'>>'); $this->_putstream($p); $this->_out('endobj'); } $this->_putannots($n); //Pages root $this->offsets[1]=strlen($this->buffer); $this->_out('1 0 obj'); $this->_out('<</Type /Pages'); $kids='/Kids ['; for($i=0;$i<$nb;$i++) $kids.=(3+2*$i).' 0 R '; $this->_out($kids.']'); $this->_out('/Count '.$nb); $this->_out(sprintf('/MediaBox [0 0 %.3F %.3F]',$defwPt,$defhPt)); $this->_out('>>'); $this->_out('endobj'); } function _putannots($n) { $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; $nb=$this->page; for($n=1;$n<=$nb;$n++) { $annotobjs = array(); if(isset($this->PageLinks[$n]) || isset($this->PageAnnots[$n]) || count($this->form->forms) > 0 ) { $wPt=$this->pageDim[$n]['w']*_MPDFK; $hPt=$this->pageDim[$n]['h']*_MPDFK; //Links if(isset($this->PageLinks[$n])) { foreach($this->PageLinks[$n] as $key => $pl) { $this->_newobj(); $annot=''; $rect=sprintf('%.3F %.3F %.3F %.3F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); $annot .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.']'; $annot .= ' /Contents '.$this->_UTF16BEtextstring($pl[4]); $annot .= ' /NM '.$this->_textstring(sprintf('%04u-%04u', $n, $key)); $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis')); $annot .= ' /Border [0 0 0]'; // mPDF 5.3.16 5.3.52 Use this (instead of /Border) to specify border around link // $annot .= ' /BS <</W 1'; // Width on points; 0 = no line // $annot .= ' /S /D'; // style - [S]olid, [D]ashed, [B]eveled, [I]nset, [U]nderline // $annot .= ' /D [3 2]'; // Dash array - if dashed // $annot .= ' >>'; // $annot .= ' /C [1 0 0]'; // Color RGB if ($this->PDFA || $this->PDFX) { $annot .= ' /F 28'; } if (strpos($pl[4],'@')===0) { $p=substr($pl[4],1); // $h=isset($this->OrientationChanges[$p]) ? $wPt : $hPt; $htarg=$this->pageDim[$p]['h']*_MPDFK; $annot.=sprintf(' /Dest [%d 0 R /XYZ 0 %.3F null]>>',1+2*$p,$htarg); } else if(is_string($pl[4])) { $annot .= ' /A <</S /URI /URI '.$this->_textstring($pl[4]).'>> >>'; } else { $l=$this->links[$pl[4]]; // may not be set if #link points to non-existent target if (isset($this->pageDim[$l[0]]['h'])) { $htarg=$this->pageDim[$l[0]]['h']*_MPDFK; } else { $htarg=$this->h*_MPDFK; } // doesn't really matter $annot.=sprintf(' /Dest [%d 0 R /XYZ 0 %.3F null]>>',1+2*$l[0],$htarg-$l[1]*_MPDFK); } $this->_out($annot); $this->_out('endobj'); } } /*-- ANNOTATIONS --*/ if(isset($this->PageAnnots[$n])) { foreach ($this->PageAnnots[$n] as $key => $pl) { if ($pl['opt']['file']) { $FileAttachment=true; } else { $FileAttachment=false; } $this->_newobj(); $annot=''; $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER); $x = $pl['x']; if ($this->annotMargin <> 0 || $x==0 || $x<0) { // Odd page $x = ($wPt/_MPDFK) - $this->annotMargin; } $w = $h = 0; $a = $x * _MPDFK; $b = $hPt - ($pl['y'] * _MPDFK); $annot .= '<</Type /Annot '; if ($FileAttachment) { $annot .= '/Subtype /FileAttachment'; // Need to set a size for FileAttachment icons if ($pl['opt']['icon']=='Paperclip') { $w=8.235; $h=20; } // 7,17 else if ($pl['opt']['icon']=='Tag') { $w=20; $h=16; } else if ($pl['opt']['icon']=='Graph') { $w=20; $h=20; } else { $w=14; $h=20; } // PushPin $f = $pl['opt']['file']; $f = preg_replace('/^.*\//', '', $f); $f = preg_replace('/[^a-zA-Z0-9._]/', '', $f); $annot .= '/FS <</Type /Filespec /F ('.$f.')'; $annot .= '/EF <</F '.($this->n+1).' 0 R>>'; $annot .= '>>'; } else { $annot .= '/Subtype /Text'; } $rect = sprintf('%.3F %.3F %.3F %.3F', $a, $b-$h, $a+$w, $b); $annot .= '/Rect ['.$rect.']'; // contents = description of file in free text $annot .= ' /Contents '.$this->_UTF16BEtextstring($pl['txt']); $annot .= ' /NM '.$this->_textstring(sprintf('%04u-%04u', $n, (2000 + $key))); $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis')); $annot .= ' /CreationDate '.$this->_textstring('D:'.date('YmdHis')); $annot .= ' /Border [0 0 0]'; if ($this->PDFA || $this->PDFX) { $annot .= ' /F 28'; $annot .= ' /CA 1'; } else if ($pl['opt']['ca']>0) { $annot .= ' /CA '.$pl['opt']['ca']; } $annotcolor = ' /C ['; // mPDF 5.3.74 if (isset($pl['opt']['c']) AND $pl['opt']['c']) { $col = $pl['opt']['c']; if ($col{0}==3 || $col{0}==5) { $annotcolor .= sprintf("%.3F %.3F %.3F", ord($col{1})/255,ord($col{2})/255,ord($col{3})/255); } else if ($col{0}==1) { $annotcolor .= sprintf("%.3F", ord($col{1})/255); } else if ($col{0}==4 || $col{0}==6) { $annotcolor .= sprintf("%.3F %.3F %.3F %.3F", ord($col{1})/100,ord($col{2})/100,ord($col{3})/100,ord($col{4})/100); } else { $annotcolor .= '1 1 0'; } } else { $annotcolor .= '1 1 0'; } $annotcolor .= ']'; $annot .= $annotcolor; // Usually Author // Use as Title for fileattachment if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) { $annot .= ' /T '.$this->_UTF16BEtextstring($pl['opt']['t']); } if ($FileAttachment) { $iconsapp = array('Paperclip', 'Graph', 'PushPin', 'Tag'); } else { $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph'); } if (isset($pl['opt']['icon']) AND in_array($pl['opt']['icon'], $iconsapp)) { $annot .= ' /Name /'.$pl['opt']['icon']; } else if ($FileAttachment) { $annot .= ' /Name /PushPin'; } else { $annot .= ' /Name /Note'; } if (!$FileAttachment) { // /Subj is PDF 1.5 spec. if (isset($pl['opt']['subj']) && !$this->PDFA && !$this->PDFX) { $annot .= ' /Subj '.$this->_UTF16BEtextstring($pl['opt']['subj']); } if (!empty($pl['opt']['popup'])) { $annot .= ' /Open true'; $annot .= ' /Popup '.($this->n+1).' 0 R'; } else { $annot .= ' /Open false'; } } $annot .= ' /P '.$pl['pageobj'].' 0 R'; $annot .= '>>'; $this->_out($annot); $this->_out('endobj'); if ($FileAttachment) { $file = @file_get_contents($pl['opt']['file']) or die('mPDF Error: Cannot access file attachment - '.$pl['opt']['file']); $filestream = gzcompress($file); $this->_newobj(); $this->_out('<</Type /EmbeddedFile'); $this->_out('/Length '.strlen($filestream)); $this->_out('/Filter /FlateDecode'); $this->_out('>>'); $this->_putstream($filestream); $this->_out('endobj'); } else if (!empty($pl['opt']['popup'])) { $this->_newobj(); $annot=''; if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][0])) { $x = $pl['opt']['popup'][0] * _MPDFK; } else { $x = $pl['x'] * _MPDFK; } if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][1])) { $y = $hPt - ($pl['opt']['popup'][1] * _MPDFK); } else { $y = $hPt - ($pl['y'] * _MPDFK); } if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][2])) { $w = $pl['opt']['popup'][2] * _MPDFK; } else { $w = 180; } if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][3])) { $h = $pl['opt']['popup'][3] * _MPDFK; } else { $h = 120; } $rect = sprintf('%.3F %.3F %.3F %.3F', $x, $y-$h, $x+$w, $y); $annot .= '<</Type /Annot /Subtype /Popup /Rect ['.$rect.']'; $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis')); if ($this->PDFA || $this->PDFX) { $annot .= ' /F 28'; } $annot .= ' /Parent '.($this->n-1).' 0 R'; $annot .= '>>'; $this->_out($annot); $this->_out('endobj'); } } } /*-- END ANNOTATIONS --*/ /*-- FORMS --*/ // Active Forms if ( count($this->form->forms) > 0 ) { $this->form->_putFormItems($n, $hPt); } /*-- END FORMS --*/ } } /*-- FORMS --*/ // Active Forms - Radio Button Group entries // Output Radio Button Group form entries (radio_on_obj_id already determined) if (count($this->form->form_radio_groups)) { $this->form->_putRadioItems($n); } /*-- END FORMS --*/ } /*-- ANNOTATIONS --*/ function Annotation($text, $x=0, $y=0, $icon='Note', $author='', $subject='', $opacity=0, $colarray=false, $popup='', $file='') { // mPDF 5.3.94 if (is_array($colarray) && count($colarray)==3) { $colarray = $this->ConvertColor('rgb('.$colarray[0].','.$colarray[1].','.$colarray[2].')'); } if ($colarray === false) { $colarray = $this->ConvertColor('yellow'); } if ($x==0) { $x = $this->x; } if ($y==0) { $y = $this->y; } $page = $this->page; if ($page < 1) { // Document has not been started - assume it's for first page $page = 1; if ($x==0) { $x = $this->lMargin; } if ($y==0) { $y = $this->tMargin; } } if ($this->PDFA || $this->PDFX) { if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Annotation markers cannot be semi-transparent in PDFA1-b or PDFX/1-a, so they may make underlying text unreadable. (Annotation markers moved to right margin)"; } $x = ($this->w) - $this->rMargin*0.66; } if (!$this->annotMargin) { $y -= $this->FontSize / 2; } if (!$opacity && $this->annotMargin) { $opacity = 1; } else if (!$opacity) { $opacity = $this->annotOpacity; } $an = array('txt' => $text, 'x' => $x, 'y' => $y, 'opt' => array('Icon'=>$icon, 'T'=>$author, 'Subj'=>$subject, 'C'=>$colarray, 'CA'=>$opacity, 'popup'=>$popup, 'file'=>$file)); if ($this->keep_block_together) { // Save to array - don't write yet $this->ktAnnots[$this->page][]= $an; return; } else if ($this->table_rotate) { $this->tbrot_Annots[$this->page][]= $an; return; } else if ($this->kwt) { $this->kwt_Annots[$this->page][]= $an; return; } // mPDF 5.0 if ($this->writingHTMLheader || $this->writingHTMLfooter) { $this->HTMLheaderPageAnnots[]= $an; return; } //Put an Annotation on the page $this->PageAnnots[$page][] = $an; /*-- COLUMNS --*/ // Save cross-reference to Column buffer $ref = count($this->PageAnnots[$this->page])-1; $this->columnAnnots[$this->CurrCol][INTVAL($this->x)][INTVAL($this->y)] = $ref; /*-- END COLUMNS --*/ } /*-- END ANNOTATIONS --*/ function _putfonts() { $nf=$this->n; $mqr=$this->_getMQR(); if ($mqr) { set_magic_quotes_runtime(0); } foreach($this->FontFiles as $fontkey=>$info) { // TrueType embedded if (isset($info['type']) && $info['type']=='TTF' && !$info['sip'] && !$info['smp']) { $used = true; $asSubset = false; foreach($this->fonts AS $k=>$f) { if ($f['fontkey'] == $fontkey && $f['type']=='TTF') { $used = $f['used']; if ($used) { $nChars = (ord($f['cw'][0]) << 8) + ord($f['cw'][1]); $usage = intval(count($f['subset'])*100 / $nChars); $fsize = $info['length1']; // Always subset the very large TTF files if ($fsize > ($this->maxTTFFilesize *1024)) { $asSubset = true; } else if ($usage < $this->percentSubset) { $asSubset = true; } } if ($this->PDFA || $this->PDFX) $asSubset = false; // mPDF 5.3.45 $this->fonts[$k]['asSubset'] = $asSubset; break; } } if ($used && !$asSubset) { //Font file embedding $this->_newobj(); $this->FontFiles[$fontkey]['n']=$this->n; $font=''; $originalsize = $info['length1']; if ($this->repackageTTF || $this->fonts[$fontkey]['TTCfontID']>0) { // First see if there is a cached compressed file if (file_exists(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.z')) { $f=fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.z','rb'); if(!$f) { $this->Error('Font file .ps.z not found'); } while(!feof($f)) { $font .= fread($f, 2048); } fclose($f); include(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.php'); // sets $originalsize (of repackaged font) } else { if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); } $ttf = new TTFontFile(); $font = $ttf->repackageTTF($this->FontFiles[$fontkey]['ttffile'], $this->fonts[$fontkey]['TTCfontID'], $this->debugfonts); $originalsize = strlen($font); $font = gzcompress($font); unset($ttf); if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) { $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.z',"wb"); fwrite($fh,$font,strlen($font)); fclose($fh); $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.ps.php',"wb"); $len = "<?php \n"; $len.='$originalsize='.$originalsize.";\n"; $len.="?>"; fwrite($fh,$len,strlen($len)); fclose($fh); } } } else { // First see if there is a cached compressed file if (file_exists(_MPDF_TTFONTDATAPATH.$fontkey.'.z')) { $f=fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.z','rb'); if(!$f) { $this->Error('Font file not found'); } while(!feof($f)) { $font .= fread($f, 2048); } fclose($f); } else { $f=fopen($this->FontFiles[$fontkey]['ttffile'],'rb'); if(!$f) { $this->Error('Font file not found'); } while(!feof($f)) { $font .= fread($f, 2048); } fclose($f); $font = gzcompress($font); if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) { $fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.z',"wb"); fwrite($fh,$font,strlen($font)); fclose($fh); } } } $this->_out('<</Length '.strlen($font)); $this->_out('/Filter /FlateDecode'); $this->_out('/Length1 '.$originalsize); $this->_out('>>'); $this->_putstream($font); $this->_out('endobj'); } } } $nfonts = count($this->fonts); $fctr = 1; foreach($this->fonts as $k=>$font) { //Font objects $type=$font['type']; $name=$font['name']; if ((!isset($font['used']) || !$font['used']) && $type=='TTF') { continue; } if ($this->progressBar) { $this->UpdateProgressBar(2,intval($fctr*100/$nfonts),'Writing Fonts'); $fctr++; } // *PROGRESS-BAR* if (isset($font['asSubset'])) { $asSubset = $font['asSubset']; } else { $asSubset = ''; } /*-- CJK-FONTS --*/ if($type=='Type0') { // = Adobe CJK Fonts $this->fonts[$k]['n']=$this->n+1; $this->_newobj(); $this->_out('<</Type /Font'); $this->_putType0($font); } else /*-- END CJK-FONTS --*/ if($type=='core') { //Standard font $this->fonts[$k]['n']=$this->n+1; if ($this->PDFA || $this->PDFX) { $this->Error('Core fonts are not allowed in PDF/A1-b or PDFX/1-a files (Times, Helvetica, Courier etc.)'); } $this->_newobj(); $this->_out('<</Type /Font'); $this->_out('/BaseFont /'.$name); $this->_out('/Subtype /Type1'); if($name!='Symbol' && $name!='ZapfDingbats') { $this->_out('/Encoding /WinAnsiEncoding'); } $this->_out('>>'); $this->_out('endobj'); } // TrueType embedded SUBSETS for SIP (CJK extB containing Supplementary Ideographic Plane 2) // Or Unicode Plane 1 - Supplementary Multilingual Plane else if ($type=='TTF' && ($font['sip'] || $font['smp'])) { if (!$font['used']) { continue; } $ssfaid="AA"; if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); } $ttf = new TTFontFile(); for($sfid=0;$sfid<count($font['subsetfontids']);$sfid++) { $this->fonts[$k]['n'][$sfid]=$this->n+1; // NB an array for subset $subsetname = 'MPDF'.$ssfaid.'+'.$font['name']; $ssfaid++; $subset = $font['subsets'][$sfid]; unset($subset[0]); $ttfontstream = $ttf->makeSubsetSIP($font['ttffile'], $subset, $font['TTCfontID'], $this->debugfonts); $ttfontsize = strlen($ttfontstream); $fontstream = gzcompress($ttfontstream); $widthstring = ''; $toUnistring = ''; foreach($font['subsets'][$sfid] AS $cp=>$u) { $w = $this->_getCharWidth($font['cw'], $u); if ($w !== false) { $widthstring .= $w.' '; } else { $widthstring .= round($ttf->defaultWidth).' '; } if ($u > 65535) { $utf8 = chr(($u>>18)+240).chr((($u>>12)&63)+128).chr((($u>>6)&63)+128) .chr(($u&63)+128); $utf16 = mb_convert_encoding($utf8, 'UTF-16BE', 'UTF-8'); $l1 = ord($utf16[0]); $h1 = ord($utf16[1]); $l2 = ord($utf16[2]); $h2 = ord($utf16[3]); $toUnistring .= sprintf("<%02s> <%02s%02s%02s%02s>\n", strtoupper(dechex($cp)), strtoupper(dechex($l1)), strtoupper(dechex($h1)), strtoupper(dechex($l2)), strtoupper(dechex($h2))); } else { $toUnistring .= sprintf("<%02s> <%04s>\n", strtoupper(dechex($cp)), strtoupper(dechex($u))); } } //Additional Type1 or TrueType font $this->_newobj(); $this->_out('<</Type /Font'); $this->_out('/BaseFont /'.$subsetname); $this->_out('/Subtype /TrueType'); $this->_out('/FirstChar 0 /LastChar '.(count($font['subsets'][$sfid])-1)); $this->_out('/Widths '.($this->n+1).' 0 R'); $this->_out('/FontDescriptor '.($this->n+2).' 0 R'); $this->_out('/ToUnicode '.($this->n + 3).' 0 R'); $this->_out('>>'); $this->_out('endobj'); //Widths $this->_newobj(); $this->_out('['.$widthstring.']'); $this->_out('endobj'); //Descriptor $this->_newobj(); $s='<</Type /FontDescriptor /FontName /'.$subsetname."\n"; foreach($font['desc'] as $kd=>$v) { if ($kd == 'Flags') { $v = $v | 4; $v = $v & ~32; } // SYMBOLIC font flag $s.=' /'.$kd.' '.$v."\n"; } $s.='/FontFile2 '.($this->n + 2).' 0 R'; $this->_out($s.'>>'); $this->_out('endobj'); // ToUnicode // mPDF 5.3.35 $this->_newobj(); $toUni = "/CIDInit /ProcSet findresource begin\n"; $toUni .= "12 dict begin\n"; $toUni .= "begincmap\n"; $toUni .= "/CIDSystemInfo\n"; $toUni .= "<</Registry (Adobe)\n"; $toUni .= "/Ordering (UCS)\n"; $toUni .= "/Supplement 0\n"; $toUni .= ">> def\n"; $toUni .= "/CMapName /Adobe-Identity-UCS def\n"; $toUni .= "/CMapType 2 def\n"; $toUni .= "1 begincodespacerange\n"; $toUni .= "<00> <FF>\n"; $toUni .= "endcodespacerange\n"; $toUni .= count($font['subsets'][$sfid])." beginbfchar\n"; $toUni .= $toUnistring; $toUni .= "endbfchar\n"; $toUni .= "endcmap\n"; $toUni .= "CMapName currentdict /CMap defineresource pop\n"; $toUni .= "end\n"; $toUni .= "end\n"; $this->_out('<</Length '.(strlen($toUni)).'>>'); $this->_putstream($toUni); $this->_out('endobj'); //Font file $this->_newobj(); $this->_out('<</Length '.strlen($fontstream)); $this->_out('/Filter /FlateDecode'); $this->_out('/Length1 '.$ttfontsize); $this->_out('>>'); $this->_putstream($fontstream); $this->_out('endobj'); } // foreach subset unset($ttf); } // TrueType embedded SUBSETS or FULL else if ($type=='TTF') { $this->fonts[$k]['n']=$this->n+1; if ($asSubset ) { $ssfaid="A"; if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); } $ttf = new TTFontFile(); $fontname = 'MPDFA'.$ssfaid.'+'.$font['name']; $subset = $font['subset']; unset($subset[0]); $ttfontstream = $ttf->makeSubset($font['ttffile'], $subset, $font['TTCfontID'], $this->debugfonts); $ttfontsize = strlen($ttfontstream); $fontstream = gzcompress($ttfontstream); $codeToGlyph = $ttf->codeToGlyph; unset($codeToGlyph[0]); } else { $fontname = $font['name']; } // Type0 Font // A composite font - a font composed of other fonts, organized hierarchically $this->_newobj(); $this->_out('<</Type /Font'); $this->_out('/Subtype /Type0'); $this->_out('/BaseFont /'.$fontname.''); $this->_out('/Encoding /Identity-H'); $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]'); $this->_out('/ToUnicode '.($this->n + 2).' 0 R'); $this->_out('>>'); $this->_out('endobj'); // CIDFontType2 // A CIDFont whose glyph descriptions are based on TrueType font technology $this->_newobj(); $this->_out('<</Type /Font'); $this->_out('/Subtype /CIDFontType2'); $this->_out('/BaseFont /'.$fontname.''); $this->_out('/CIDSystemInfo '.($this->n + 2).' 0 R'); $this->_out('/FontDescriptor '.($this->n + 3).' 0 R'); if (isset($font['desc']['MissingWidth'])){ $this->_out('/DW '.$font['desc']['MissingWidth'].''); } if (!$asSubset && file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw')) { $w = ''; $w=file_get_contents(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw'); $this->_out($w); } else { $this->_putTTfontwidths($font, $asSubset, $ttf->maxUni); } $this->_out('/CIDToGIDMap '.($this->n + 4).' 0 R'); $this->_out('>>'); $this->_out('endobj'); // ToUnicode // mPDF 5.3.35 $this->_newobj(); $toUni = "/CIDInit /ProcSet findresource begin\n"; $toUni .= "12 dict begin\n"; $toUni .= "begincmap\n"; $toUni .= "/CIDSystemInfo\n"; $toUni .= "<</Registry (Adobe)\n"; $toUni .= "/Ordering (UCS)\n"; $toUni .= "/Supplement 0\n"; $toUni .= ">> def\n"; $toUni .= "/CMapName /Adobe-Identity-UCS def\n"; $toUni .= "/CMapType 2 def\n"; $toUni .= "1 begincodespacerange\n"; $toUni .= "<0000> <FFFF>\n"; $toUni .= "endcodespacerange\n"; $toUni .= "1 beginbfrange\n"; $toUni .= "<0000> <FFFF> <0000>\n"; $toUni .= "endbfrange\n"; $toUni .= "endcmap\n"; $toUni .= "CMapName currentdict /CMap defineresource pop\n"; $toUni .= "end\n"; $toUni .= "end\n"; $this->_out('<</Length '.(strlen($toUni)).'>>'); $this->_putstream($toUni); $this->_out('endobj'); // CIDSystemInfo dictionary $this->_newobj(); $this->_out('<</Registry (Adobe)'); $this->_out('/Ordering (UCS)'); $this->_out('/Supplement 0'); $this->_out('>>'); $this->_out('endobj'); // Font descriptor $this->_newobj(); $this->_out('<</Type /FontDescriptor'); $this->_out('/FontName /'.$fontname); foreach($font['desc'] as $kd=>$v) { if ($asSubset && $kd == 'Flags') { $v = $v | 4; $v = $v & ~32; } // SYMBOLIC font flag $this->_out(' /'.$kd.' '.$v); } if ($font['panose']) { $this->_out(' /Style << /Panose <'.$font['panose'].'> >>'); } if ($asSubset ) { $this->_out('/FontFile2 '.($this->n + 2).' 0 R'); } else if ($font['fontkey']) { // obj ID of a stream containing a TrueType font program $this->_out('/FontFile2 '.$this->FontFiles[$font['fontkey']]['n'].' 0 R'); } $this->_out('>>'); $this->_out('endobj'); // Embed CIDToGIDMap // A specification of the mapping from CIDs to glyph indices if ($asSubset ) { $cidtogidmap = ''; $cidtogidmap = str_pad('', 256*256*2, "\x00"); foreach($codeToGlyph as $cc=>$glyph) { $cidtogidmap[$cc*2] = chr($glyph >> 8); $cidtogidmap[$cc*2 + 1] = chr($glyph & 0xFF); } $cidtogidmap = gzcompress($cidtogidmap); } else { // First see if there is a cached CIDToGIDMapfile $cidtogidmap = ''; if (file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cgm')) { $f=fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cgm','rb'); while(!feof($f)) { $cidtogidmap .= fread($f, 2048); } fclose($f); } else { if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); } $ttf = new TTFontFile(); $charToGlyph = $ttf->getCTG($font['ttffile'], $font['TTCfontID'], $this->debugfonts); $cidtogidmap = str_pad('', 256*256*2, "\x00"); foreach($charToGlyph as $cc=>$glyph) { $cidtogidmap[$cc*2] = chr($glyph >> 8); $cidtogidmap[$cc*2 + 1] = chr($glyph & 0xFF); } unset($ttf); $cidtogidmap = gzcompress($cidtogidmap); if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) { $fh = fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cgm',"wb"); fwrite($fh,$cidtogidmap,strlen($cidtogidmap)); fclose($fh); } } } $this->_newobj(); $this->_out('<</Length '.strlen($cidtogidmap).''); $this->_out('/Filter /FlateDecode'); $this->_out('>>'); $this->_putstream($cidtogidmap); $this->_out('endobj'); //Font file if ($asSubset ) { $this->_newobj(); $this->_out('<</Length '.strlen($fontstream)); $this->_out('/Filter /FlateDecode'); $this->_out('/Length1 '.$ttfontsize); $this->_out('>>'); $this->_putstream($fontstream); $this->_out('endobj'); unset($ttf); } } else { $this->Error('Unsupported font type: '.$type.' ('.$name.')'); } } if ($mqr) { set_magic_quotes_runtime($mqr); } } function _putTTfontwidths(&$font, $asSubset, $maxUni) { if ($asSubset && file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php')) { include(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php') ; $startcid = 128; } else { $rangeid = 0; $range = array(); $prevcid = -2; $prevwidth = -1; $interval = false; $startcid = 1; } if ($asSubset) { $cwlen = $maxUni + 1; } else { $cwlen = (strlen($font['cw'])/2); } // for each character for ($cid=$startcid; $cid<$cwlen; $cid++) { if ($cid==128 && $asSubset && (!file_exists(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php'))) { if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) { $fh = fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw127.php',"wb"); $cw127='<?php'."\n"; $cw127.='$rangeid='.$rangeid.";\n"; $cw127.='$prevcid='.$prevcid.";\n"; $cw127.='$prevwidth='.$prevwidth.";\n"; if ($interval) { $cw127.='$interval=true'.";\n"; } else { $cw127.='$interval=false'.";\n"; } $cw127.='$range='.var_export($range,true).";\n"; $cw127.="?>"; fwrite($fh,$cw127,strlen($cw127)); fclose($fh); } } if ($font['cw'][$cid*2] == "\00" && $font['cw'][$cid*2+1] == "\00") { continue; } $width = (ord($font['cw'][$cid*2]) << 8) + ord($font['cw'][$cid*2+1]); if ($width == 65535) { $width = 0; } if ($asSubset && $cid > 255 && (!isset($font['subset'][$cid]) || !$font['subset'][$cid])) { continue; } if (!isset($font['dw']) || (isset($font['dw']) && $width != $font['dw'])) { if ($cid == ($prevcid + 1)) { // consecutive CID if ($width == $prevwidth) { if ($width == $range[$rangeid][0]) { $range[$rangeid][] = $width; } else { array_pop($range[$rangeid]); // new range $rangeid = $prevcid; $range[$rangeid] = array(); $range[$rangeid][] = $prevwidth; $range[$rangeid][] = $width; } $interval = true; $range[$rangeid]['interval'] = true; } else { if ($interval) { // new range $rangeid = $cid; $range[$rangeid] = array(); $range[$rangeid][] = $width; } else { $range[$rangeid][] = $width; } $interval = false; } } else { // new range $rangeid = $cid; $range[$rangeid] = array(); $range[$rangeid][] = $width; $interval = false; } $prevcid = $cid; $prevwidth = $width; } } $w = $this->_putfontranges($range); $this->_out($w); if (!$asSubset) { if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) { $fh = fopen(_MPDF_TTFONTDATAPATH.$font['fontkey'].'.cw',"wb"); fwrite($fh,$w,strlen($w)); fclose($fh); } } } function _putfontranges(&$range) { // optimize ranges $prevk = -1; $nextk = -1; $prevint = false; foreach ($range as $k => $ws) { $cws = count($ws); if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) { if (isset($range[$k]['interval'])) { unset($range[$k]['interval']); } $range[$prevk] = array_merge($range[$prevk], $range[$k]); unset($range[$k]); } else { $prevk = $k; } $nextk = $k + $cws; if (isset($ws['interval'])) { if ($cws > 3) { $prevint = true; } else { $prevint = false; } unset($range[$k]['interval']); --$nextk; } else { $prevint = false; } } // output data $w = ''; foreach ($range as $k => $ws) { if (count(array_count_values($ws)) == 1) { // interval mode is more compact $w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0]; } else { // range mode $w .= ' '.$k.' [ '.implode(' ', $ws).' ]' . "\n"; } } return '/W ['.$w.' ]'; } function _putfontwidths(&$font, $cidoffset=0) { ksort($font['cw']); unset($font['cw'][65535]); $rangeid = 0; $range = array(); $prevcid = -2; $prevwidth = -1; $interval = false; // for each character foreach ($font['cw'] as $cid => $width) { $cid -= $cidoffset; if (!isset($font['dw']) || (isset($font['dw']) && $width != $font['dw'])) { if ($cid == ($prevcid + 1)) { // consecutive CID if ($width == $prevwidth) { if ($width == $range[$rangeid][0]) { $range[$rangeid][] = $width; } else { array_pop($range[$rangeid]); // new range $rangeid = $prevcid; $range[$rangeid] = array(); $range[$rangeid][] = $prevwidth; $range[$rangeid][] = $width; } $interval = true; $range[$rangeid]['interval'] = true; } else { if ($interval) { // new range $rangeid = $cid; $range[$rangeid] = array(); $range[$rangeid][] = $width; } else { $range[$rangeid][] = $width; } $interval = false; } } else { // new range $rangeid = $cid; $range[$rangeid] = array(); $range[$rangeid][] = $width; $interval = false; } $prevcid = $cid; $prevwidth = $width; } } $this->_out($this->_putfontranges($range)); } /*-- CJK-FONTS --*/ // from class PDF_Chinese CJK EXTENSIONS function _putType0(&$font) { //Type0 $this->_out('/Subtype /Type0'); $this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']); $this->_out('/Encoding /'.$font['CMap']); $this->_out('/DescendantFonts ['.($this->n+1).' 0 R]'); $this->_out('>>'); $this->_out('endobj'); //CIDFont $this->_newobj(); $this->_out('<</Type /Font'); $this->_out('/Subtype /CIDFontType0'); $this->_out('/BaseFont /'.$font['name']); $cidinfo = '/Registry '.$this->_textstring('Adobe'); $cidinfo .= ' /Ordering '.$this->_textstring($font['registry']['ordering']); $cidinfo .= ' /Supplement '.$font['registry']['supplement']; $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>'); $this->_out('/FontDescriptor '.($this->n+1).' 0 R'); if (isset($font['MissingWidth'])){ $this->_out('/DW '.$font['MissingWidth'].''); } $this->_putfontwidths($font, 31); $this->_out('>>'); $this->_out('endobj'); //Font descriptor $this->_newobj(); $s = '<</Type /FontDescriptor /FontName /'.$font['name']; foreach ($font['desc'] as $k => $v) { if ($k != 'Style') { $s .= ' /'.$k.' '.$v.''; } } $this->_out($s.'>>'); $this->_out('endobj'); } /*-- END CJK-FONTS --*/ function _putimages() { $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; reset($this->images); while(list($file,$info)=each($this->images)) { $this->_newobj(); $this->images[$file]['n']=$this->n; $this->_out('<</Type /XObject'); $this->_out('/Subtype /Image'); $this->_out('/Width '.$info['w']); $this->_out('/Height '.$info['h']); if (isset($info['masked'])) { $this->_out('/SMask '.($this->n - 1).' 0 R'); } if($info['cs']=='Indexed') { if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) { $this->Error("PDFA1-b and PDFX/1-a files do not permit using mixed colour space (".$file.")."); } $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]'); } else { $this->_out('/ColorSpace /'.$info['cs']); if($info['cs']=='DeviceCMYK') { if ($this->PDFA && $this->restrictColorSpace!=3) { $this->Error("PDFA1-b does not permit Images using mixed colour space (".$file.")."); } if($info['type']=='jpg') { $this->_out('/Decode [1 0 1 0 1 0 1 0]'); } } else if ($info['cs']=='DeviceRGB' && ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3))) { $this->Error("PDFA1-b and PDFX/1-a files do not permit using mixed colour space (".$file.")."); } } $this->_out('/BitsPerComponent '.$info['bpc']); if (isset($info['f']) && $info['f']) { $this->_out('/Filter /'.$info['f']); } if(isset($info['parms'])) { $this->_out($info['parms']); } if(isset($info['trns']) and is_array($info['trns'])) { $trns=''; for($i=0;$i<count($info['trns']);$i++) $trns.=$info['trns'][$i].' '.$info['trns'][$i].' '; $this->_out('/Mask ['.$trns.']'); } $this->_out('/Length '.strlen($info['data']).'>>'); $this->_putstream($info['data']); unset($this->images[$file]['data']); $this->_out('endobj'); //Palette if($info['cs']=='Indexed') { $this->_newobj(); $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal']; $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>'); $this->_putstream($pal); $this->_out('endobj'); } } } function _putinfo() { $this->_out('/Producer '.$this->_UTF16BEtextstring('mPDF '.mPDF_VERSION)); if(!empty($this->title)) $this->_out('/Title '.$this->_UTF16BEtextstring($this->title)); if(!empty($this->subject)) $this->_out('/Subject '.$this->_UTF16BEtextstring($this->subject)); if(!empty($this->author)) $this->_out('/Author '.$this->_UTF16BEtextstring($this->author)); if(!empty($this->keywords)) $this->_out('/Keywords '.$this->_UTF16BEtextstring($this->keywords)); if(!empty($this->creator)) $this->_out('/Creator '.$this->_UTF16BEtextstring($this->creator)); $z = date('O'); // +0200 $offset = substr($z,0,3)."'".substr($z,3,2)."'"; $this->_out('/CreationDate '.$this->_textstring(date('YmdHis').$offset)); $this->_out('/ModDate '.$this->_textstring(date('YmdHis').$offset)); if ($this->PDFX) { $this->_out('/Trapped/False'); $this->_out('/GTS_PDFXVersion(PDF/X-1a:2003)'); } } function _putmetadata() { $this->_newobj(); $this->MetadataRoot = $this->n; $Producer = 'mPDF '.mPDF_VERSION; $z = date('O'); // +0200 $offset = substr($z,0,3).':'.substr($z,3,2); $CreationDate = date('Y-m-d\TH:i:s').$offset; // 2006-03-10T10:47:26-05:00 2006-06-19T09:05:17Z $uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); $m = '<?xpacket begin="'.chr(239).chr(187).chr(191).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n"; // begin = FEFF BOM $m .= ' <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="3.1-701">'."\n"; $m .= ' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n"; $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n"; $m .= ' <pdf:Producer>'.$Producer.'</pdf:Producer>'."\n"; if(!empty($this->keywords)) { $m .= ' <pdf:Keywords>'.$this->keywords.'</pdf:Keywords>'."\n"; } $m .= ' </rdf:Description>'."\n"; $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n"; $m .= ' <xmp:CreateDate>'.$CreationDate.'</xmp:CreateDate>'."\n"; $m .= ' <xmp:ModifyDate>'.$CreationDate.'</xmp:ModifyDate>'."\n"; $m .= ' <xmp:MetadataDate>'.$CreationDate.'</xmp:MetadataDate>'."\n"; if(!empty($this->creator)) { $m .= ' <xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n"; } $m .= ' </rdf:Description>'."\n"; // DC elements $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n"; $m .= ' <dc:format>application/pdf</dc:format>'."\n"; if(!empty($this->title)) { $m .= ' <dc:title> <rdf:Alt> <rdf:li xml:lang="x-default">'.$this->title.'</rdf:li> </rdf:Alt> </dc:title>'."\n"; } if(!empty($this->keywords)) { $m .= ' <dc:subject> <rdf:Bag> <rdf:li>'.$this->keywords.'</rdf:li> </rdf:Bag> </dc:subject>'."\n"; } if(!empty($this->subject)) { $m .= ' <dc:description> <rdf:Alt> <rdf:li xml:lang="x-default">'.$this->subject.'</rdf:li> </rdf:Alt> </dc:description>'."\n"; } if(!empty($this->author)) { $m .= ' <dc:creator> <rdf:Seq> <rdf:li>'.$this->author.'</rdf:li> </rdf:Seq> </dc:creator>'."\n"; } $m .= ' </rdf:Description>'."\n"; // This bit is specific to PDFX-1a if ($this->PDFX) { $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:pdfx="http://ns.adobe.com/pdfx/1.3/" pdfx:Apag_PDFX_Checkup="1.3" pdfx:GTS_PDFXConformance="PDF/X-1a:2003" pdfx:GTS_PDFXVersion="PDF/X-1:2003"/>'."\n"; } // This bit is specific to PDFA-1b else if ($this->PDFA) { $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/" >'."\n"; $m .= ' <pdfaid:part>1</pdfaid:part>'."\n"; $m .= ' <pdfaid:conformance>B</pdfaid:conformance>'."\n"; $m .= ' <pdfaid:amd>2005</pdfaid:amd>'."\n"; $m .= ' </rdf:Description>'."\n"; } $m .= ' <rdf:Description rdf:about="uuid:'.$uuid.'" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n"; $m .= ' <xmpMM:DocumentID>uuid:'.$uuid.'</xmpMM:DocumentID>'."\n"; $m .= ' </rdf:Description>'."\n"; $m .= ' </rdf:RDF>'."\n"; $m .= ' </x:xmpmeta>'."\n"; $m .= str_repeat(str_repeat(' ',100)."\n",20); // 2-4kB whitespace padding required $m .= '<?xpacket end="w"?>'; // "r" read only $this->_out('<</Type/Metadata/Subtype/XML/Length '.strlen($m).'>>'); $this->_putstream($m); $this->_out('endobj'); } function _putoutputintent() { $this->_newobj(); $this->OutputIntentRoot = $this->n; $this->_out('<</Type /OutputIntent'); if ($this->PDFA) { $this->_out('/S /GTS_PDFA1'); if ($this->ICCProfile) { $this->_out('/Info ('.preg_replace('/_/',' ',$this->ICCProfile).')'); $this->_out('/OutputConditionIdentifier (Custom)'); $this->_out('/OutputCondition ()'); } else { $this->_out('/Info (sRGB IEC61966-2.1)'); $this->_out('/OutputConditionIdentifier (sRGB IEC61966-2.1)'); $this->_out('/OutputCondition ()'); } $this->_out('/DestOutputProfile '.($this->n+1).' 0 R'); } else if ($this->PDFX) { // always a CMYK profile $this->_out('/S /GTS_PDFX'); if ($this->ICCProfile) { $this->_out('/Info ('.preg_replace('/_/',' ',$this->ICCProfile).')'); $this->_out('/OutputConditionIdentifier (Custom)'); $this->_out('/OutputCondition ()'); $this->_out('/DestOutputProfile '.($this->n+1).' 0 R'); } else { $this->_out('/Info (CGATS TR 001)'); $this->_out('/OutputConditionIdentifier (CGATS TR 001)'); $this->_out('/OutputCondition (CGATS TR 001 (SWOP))'); $this->_out('/RegistryName (http://www.color.org)'); } } $this->_out('>>'); $this->_out('endobj'); if ($this->PDFX && !$this->ICCProfile) { return; } // no ICCProfile embedded $this->_newobj(); if ($this->ICCProfile) $s = file_get_contents(_MPDF_PATH.'iccprofiles/'.$this->ICCProfile.'.icc'); else $s = file_get_contents(_MPDF_PATH.'iccprofiles/sRGB_IEC61966-2-1.icc'); if ($this->compress) { $s = gzcompress($s); } $this->_out('<<'); if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace == 3)) { $this->_out('/N 4'); } else { $this->_out('/N 3'); } if ($this->compress) $this->_out('/Filter /FlateDecode '); $this->_out('/Length '.strlen($s).'>>'); $this->_putstream($s); $this->_out('endobj'); } function _putcatalog() { $this->_out('/Type /Catalog'); $this->_out('/Pages 1 0 R'); if($this->ZoomMode=='fullpage') $this->_out('/OpenAction [3 0 R /Fit]'); elseif($this->ZoomMode=='fullwidth') $this->_out('/OpenAction [3 0 R /FitH null]'); elseif($this->ZoomMode=='real') $this->_out('/OpenAction [3 0 R /XYZ null null 1]'); elseif(!is_string($this->ZoomMode)) $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']'); else $this->_out('/OpenAction [3 0 R /XYZ null null null]'); if($this->LayoutMode=='single') $this->_out('/PageLayout /SinglePage'); elseif($this->LayoutMode=='continuous') $this->_out('/PageLayout /OneColumn'); elseif($this->LayoutMode=='twoleft') $this->_out('/PageLayout /TwoColumnLeft'); elseif($this->LayoutMode=='tworight') $this->_out('/PageLayout /TwoColumnRight'); elseif($this->LayoutMode=='two') { if ($this->mirrorMargins) { $this->_out('/PageLayout /TwoColumnRight'); } else { $this->_out('/PageLayout /TwoColumnLeft'); } } /*-- BOOKMARKS --*/ if(count($this->BMoutlines)>0) { $this->_out('/Outlines '.$this->OutlineRoot.' 0 R'); $this->_out('/PageMode /UseOutlines'); } /*-- END BOOKMARKS --*/ if(is_int(strpos($this->DisplayPreferences,'FullScreen'))) $this->_out('/PageMode /FullScreen'); // Metadata if ($this->PDFA || $this->PDFX) { $this->_out('/Metadata '.$this->MetadataRoot.' 0 R'); } // OutputIntents if ($this->PDFA || $this->PDFX || $this->ICCProfile) { $this->_out('/OutputIntents ['.$this->OutputIntentRoot.' 0 R]'); } /*-- FORMS --*/ if (count($this->form->forms)>0) { $this->form->_putFormsCatalog(); } /*-- END FORMS --*/ if ( isset($this->js) ) { $this->_out('/Names << /JavaScript '.($this->n_js).' 0 R >> '); } if($this->DisplayPreferences || $this->directionality == 'rtl' || $this->mirrorMargins) { $this->_out('/ViewerPreferences<<'); if(is_int(strpos($this->DisplayPreferences,'HideMenubar'))) $this->_out('/HideMenubar true'); if(is_int(strpos($this->DisplayPreferences,'HideToolbar'))) $this->_out('/HideToolbar true'); if(is_int(strpos($this->DisplayPreferences,'HideWindowUI'))) $this->_out('/HideWindowUI true'); if(is_int(strpos($this->DisplayPreferences,'DisplayDocTitle'))) $this->_out('/DisplayDocTitle true'); if(is_int(strpos($this->DisplayPreferences,'CenterWindow'))) $this->_out('/CenterWindow true'); if(is_int(strpos($this->DisplayPreferences,'FitWindow'))) $this->_out('/FitWindow true'); // /PrintScaling is PDF 1.6 spec. if(is_int(strpos($this->DisplayPreferences,'NoPrintScaling')) && !$this->PDFA && !$this->PDFX) $this->_out('/PrintScaling /None'); if($this->directionality == 'rtl') $this->_out('/Direction /R2L'); // /Duplex is PDF 1.7 spec. if($this->mirrorMargins && !$this->PDFA && !$this->PDFX) { // if ($this->DefOrientation=='P') $this->_out('/Duplex /DuplexFlipShortEdge'); $this->_out('/Duplex /DuplexFlipLongEdge'); // PDF v1.7+ } $this->_out('>>'); } if ($this->hasOC) { // mPDF 5.3.45 // mPDF 5.3.41 Visibility $p=$this->n_ocg_print.' 0 R'; $v=$this->n_ocg_view.' 0 R'; $h=$this->n_ocg_hidden.' 0 R'; $as="<</Event /Print /OCGs [$p $v $h] /Category [/Print]>> <</Event /View /OCGs [$p $v $h] /Category [/View]>>"; $this->_out("/OCProperties <</OCGs [$p $v $h] /D <</ON [$p] /OFF [$v] /OFF [$h] /AS [$as]>>>>"); } } // Inactive function left for backwards compatability function SetUserRights($enable=true, $annots="", $form="", $signature="") { // Does nothing } function _enddoc() { if ($this->progressBar) { $this->UpdateProgressBar(2,'10','Writing Headers & Footers'); } // *PROGRESS-BAR* $this->_puthtmlheaders(); // *HTMLHEADERS-FOOTERS* if ($this->progressBar) { $this->UpdateProgressBar(2,'20','Writing Pages'); } // *PROGRESS-BAR* // Remove references to unused fonts (usually default font) foreach($this->fonts as $fk=>$font) { if (!$font['used'] && ($font['type']=='TTF')) { if ($font['sip'] || $font['smp']) { foreach($font['subsetfontids'] AS $k => $fid) { foreach($this->pages AS $pn=>$page) { $this->pages[$pn] = preg_replace('/\s\/F'.$fid.' \d[\d.]* Tf\s/is',' ',$this->pages[$pn]); } } } else { foreach($this->pages AS $pn=>$page) { $this->pages[$pn] = preg_replace('/\s\/F'.$font['i'].' \d[\d.]* Tf\s/is',' ',$this->pages[$pn]); } } } } $this->_putpages(); if ($this->progressBar) { $this->UpdateProgressBar(2,'30','Writing document resources'); } // *PROGRESS-BAR* $this->_putresources(); //Info $this->_newobj(); $this->InfoRoot = $this->n; $this->_out('<<'); if ($this->progressBar) { $this->UpdateProgressBar(2,'80','Writing document info'); } // *PROGRESS-BAR* $this->_putinfo(); $this->_out('>>'); $this->_out('endobj'); // METADATA if ($this->PDFA || $this->PDFX) { $this->_putmetadata(); } // OUTPUTINTENT if ($this->PDFA || $this->PDFX || $this->ICCProfile) { $this->_putoutputintent(); } //Catalog $this->_newobj(); $this->_out('<<'); if ($this->progressBar) { $this->UpdateProgressBar(2,'90','Writing document catalog'); } // *PROGRESS-BAR* $this->_putcatalog(); $this->_out('>>'); $this->_out('endobj'); //Cross-ref $o=strlen($this->buffer); $this->_out('xref'); $this->_out('0 '.($this->n+1)); $this->_out('0000000000 65535 f '); for($i=1; $i <= $this->n ; $i++) $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i])); //Trailer $this->_out('trailer'); $this->_out('<<'); $this->_puttrailer(); $this->_out('>>'); $this->_out('startxref'); $this->_out($o); $this->buffer .= '%%EOF'; $this->state=3; /*-- IMPORTS --*/ if ($this->enableImports && count($this->parsers) > 0) { foreach ($this->parsers as $k => $_){ $this->parsers[$k]->closeFile(); $this->parsers[$k] = null; unset($this->parsers[$k]); } } /*-- END IMPORTS --*/ } function _beginpage($orientation,$mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0,$pagesel='',$newformat='') { if (!($pagesel && $this->page==1 && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->tMargin)))) { $this->page++; $this->pages[$this->page]=''; } $this->state=2; $resetHTMLHeadersrequired = false; if ($newformat) { $this->_setPageSize($newformat, $orientation); } /*-- CSS-PAGE --*/ // Paged media (page-box) if ($pagesel || (isset($this->page_box['using']) && $this->page_box['using'])) { if ($pagesel || $this->page==1) { $first = true; } else { $first = false; } if ($this->mirrorMargins && ($this->page % 2==0)) { $oddEven = 'E'; } else { $oddEven = 'O'; } if ($pagesel) { $psel = $pagesel; } else if ($this->page_box['current']) { $psel = $this->page_box['current']; } else { $psel = ''; } list($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS($psel, $first, $oddEven); if ($this->mirrorMargins && ($this->page % 2==0)) { if ($hname) { $ehvalue = 1; $ehname = $hname; } else { $ehvalue = -1; } if ($fname) { $efvalue = 1; $efname = $fname; } else { $efvalue = -1; } } else { if ($hname) { $ohvalue = 1; $ohname = $hname; } else { $ohvalue = -1; } if ($fname) { $ofvalue = 1; $ofname = $fname; } else { $ofvalue = -1; } } if ($resetpagenum || $pagenumstyle || $suppress) { $this->PageNumSubstitutions[] = array('from'=>($this->page), 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=>$suppress); } // PAGED MEDIA - CROP / CROSS MARKS from @PAGE $this->show_marks = $marks; // Background color if (isset($bg['BACKGROUND-COLOR'])) { $cor = $this->ConvertColor($bg['BACKGROUND-COLOR']); if ($cor) { $this->bodyBackgroundColor = $cor; } } else { $this->bodyBackgroundColor = false; } /*-- BACKGROUNDS --*/ if (isset($bg['BACKGROUND-GRADIENT'])) { $this->bodyBackgroundGradient = $bg['BACKGROUND-GRADIENT']; } else { $this->bodyBackgroundGradient = false; } // Tiling Patterns if (isset($bg['BACKGROUND-IMAGE']) && $bg['BACKGROUND-IMAGE']) { $ret = $this->SetBackground($bg, $this->pgwidth); if ($ret) { $this->bodyBackgroundImage = $ret; } } else { $this->bodyBackgroundImage = false; } /*-- END BACKGROUNDS --*/ $this->page_box['current'] = $psel; $this->page_box['using'] = true; } /*-- END CSS-PAGE --*/ //Page orientation if(!$orientation) $orientation=$this->DefOrientation; else { $orientation=strtoupper(substr($orientation,0,1)); if($orientation!=$this->DefOrientation) $this->OrientationChanges[$this->page]=true; } if($orientation!=$this->CurOrientation || $newformat) { //Change orientation if($orientation=='P') { $this->wPt=$this->fwPt; $this->hPt=$this->fhPt; $this->w=$this->fw; $this->h=$this->fh; if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P') { $this->tMargin = $this->orig_tMargin; $this->bMargin = $this->orig_bMargin; $this->DeflMargin = $this->orig_lMargin; $this->DefrMargin = $this->orig_rMargin; $this->margin_header = $this->orig_hMargin; $this->margin_footer = $this->orig_fMargin; } else { $resetHTMLHeadersrequired = true; } // *HTMLHEADERS-FOOTERS* } else { $this->wPt=$this->fhPt; $this->hPt=$this->fwPt; $this->w=$this->fh; $this->h=$this->fw; if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P') { $this->tMargin = $this->orig_lMargin; $this->bMargin = $this->orig_rMargin; $this->DeflMargin = $this->orig_bMargin; $this->DefrMargin = $this->orig_tMargin; $this->margin_header = $this->orig_hMargin; $this->margin_footer = $this->orig_fMargin; } else { $resetHTMLHeadersrequired = true; } // *HTMLHEADERS-FOOTERS* } $this->CurOrientation=$orientation; $this->ResetMargins(); $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $this->PageBreakTrigger=$this->h-$this->bMargin; } $this->pageDim[$this->page]['w']=$this->w ; $this->pageDim[$this->page]['h']=$this->h ; $this->pageDim[$this->page]['outer_width_LR'] = isset($this->page_box['outer_width_LR']) ? $this->page_box['outer_width_LR'] : 0; $this->pageDim[$this->page]['outer_width_TB'] = isset($this->page_box['outer_width_TB']) ? $this->page_box['outer_width_TB'] : 0; if (!isset($this->page_box['outer_width_LR']) && !isset($this->page_box['outer_width_TB'])) { $this->pageDim[$this->page]['bleedMargin'] = 0; } else if ($this->bleedMargin <= $this->page_box['outer_width_LR'] && $this->bleedMargin <= $this->page_box['outer_width_TB']) { $this->pageDim[$this->page]['bleedMargin'] = $this->bleedMargin; } else { $this->pageDim[$this->page]['bleedMargin'] = min($this->page_box['outer_width_LR'], $this->page_box['outer_width_TB'])-0.01; } // If Page Margins are re-defined // strlen()>0 is used to pick up (integer) 0, (string) '0', or set value if ((strlen($mgl)>0 && $this->DeflMargin != $mgl) || (strlen($mgr)>0 && $this->DefrMargin != $mgr) || (strlen($mgt)>0 && $this->tMargin != $mgt) || (strlen($mgb)>0 && $this->bMargin != $mgb) || (strlen($mgh)>0 && $this->margin_header!=$mgh) || (strlen($mgf)>0 && $this->margin_footer!=$mgf)) { if (strlen($mgl)>0) $this->DeflMargin = $mgl; if (strlen($mgr)>0) $this->DefrMargin = $mgr; if (strlen($mgt)>0) $this->tMargin = $mgt; if (strlen($mgb)>0) $this->bMargin = $mgb; if (strlen($mgh)>0) $this->margin_header=$mgh; if (strlen($mgf)>0) $this->margin_footer=$mgf; $this->ResetMargins(); $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin); $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS* } $this->ResetMargins(); $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin); // Reset column top margin $this->y0 = $this->tMargin; $this->x=$this->lMargin; $this->y=$this->tMargin; $this->FontFamily=''; // HEADERS AND FOOTERS if ($ohvalue<0 || strtoupper($ohvalue)=='OFF') { $this->HTMLHeader = ''; $this->headerDetails['odd'] = array(); $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS* } else if ($ohname && $ohvalue>0) { /*-- HTMLHEADERS-FOOTERS --*/ if (preg_match('/^html_(.*)$/i',$ohname,$n)) { if (isset($this->pageHTMLheaders[$n[1]])) { $this->HTMLHeader = $this->pageHTMLheaders[$n[1]]; } else { $this->HTMLHeader = ''; } $this->headerDetails['odd'] = array(); $resetHTMLHeadersrequired = true; } else { /*-- END HTMLHEADERS-FOOTERS --*/ if (isset($this->pageheaders[$ohname])) { $this->headerDetails['odd'] = $this->pageheaders[$ohname]; } else if ($ohname!='_default') { $this->headerDetails['odd'] = array(); } $this->HTMLHeader = ''; /*-- HTMLHEADERS-FOOTERS --*/ $resetHTMLHeadersrequired = false; } /*-- END HTMLHEADERS-FOOTERS --*/ } if ($ehvalue<0 || strtoupper($ehvalue)=='OFF') { $this->HTMLHeaderE = ''; $this->headerDetails['even'] = array(); $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS* } else if ($ehname && $ehvalue>0) { /*-- HTMLHEADERS-FOOTERS --*/ if (preg_match('/^html_(.*)$/i',$ehname,$n)) { if (isset($this->pageHTMLheaders[$n[1]])) { $this->HTMLHeaderE = $this->pageHTMLheaders[$n[1]]; } else { $this->HTMLHeaderE = ''; } $this->headerDetails['even'] = array(); $resetHTMLHeadersrequired = true; } else { /*-- END HTMLHEADERS-FOOTERS --*/ if (isset($this->pageheaders[$ehname])) { $this->headerDetails['even'] = $this->pageheaders[$ehname]; } else if ($ehname!='_default') { $this->headerDetails['even'] = array(); } $this->HTMLHeaderE = ''; /*-- HTMLHEADERS-FOOTERS --*/ $resetHTMLHeadersrequired = false; } /*-- END HTMLHEADERS-FOOTERS --*/ } if ($ofvalue<0 || strtoupper($ofvalue)=='OFF') { $this->HTMLFooter = ''; $this->footerDetails['odd'] = array(); $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS* } else if ($ofname && $ofvalue>0) { /*-- HTMLHEADERS-FOOTERS --*/ if (preg_match('/^html_(.*)$/i',$ofname,$n)) { if (isset($this->pageHTMLfooters[$n[1]])) { $this->HTMLFooter = $this->pageHTMLfooters[$n[1]]; } else { $this->HTMLFooter = ''; } $this->footerDetails['odd'] = array(); $resetHTMLHeadersrequired = true; } else { /*-- END HTMLHEADERS-FOOTERS --*/ if (isset($this->pagefooters[$ofname])) { $this->footerDetails['odd'] = $this->pagefooters[$ofname]; } else if ($ofname!='_default') { $this->footerDetails['odd'] = array(); } $this->HTMLFooter = ''; /*-- HTMLHEADERS-FOOTERS --*/ $resetHTMLHeadersrequired = true; } /*-- END HTMLHEADERS-FOOTERS --*/ } if ($efvalue<0 || strtoupper($efvalue)=='OFF') { $this->HTMLFooterE = ''; $this->footerDetails['even'] = array(); $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS* } else if ($efname && $efvalue>0) { /*-- HTMLHEADERS-FOOTERS --*/ if (preg_match('/^html_(.*)$/i',$efname,$n)) { if (isset($this->pageHTMLfooters[$n[1]])) { $this->HTMLFooterE = $this->pageHTMLfooters[$n[1]]; } else { $this->HTMLFooterE = ''; } $this->footerDetails['even'] = array(); $resetHTMLHeadersrequired = true; } else { /*-- END HTMLHEADERS-FOOTERS --*/ if (isset($this->pagefooters[$efname])) { $this->footerDetails['even'] = $this->pagefooters[$efname]; } else if ($efname!='_default') { $this->footerDetails['even'] = array(); } $this->HTMLFooterE = ''; /*-- HTMLHEADERS-FOOTERS --*/ $resetHTMLHeadersrequired = true; } /*-- END HTMLHEADERS-FOOTERS --*/ } /*-- HTMLHEADERS-FOOTERS --*/ if ($resetHTMLHeadersrequired) { $this->SetHTMLHeader($this->HTMLHeader ); $this->SetHTMLHeader($this->HTMLHeaderE ,'E'); $this->SetHTMLFooter($this->HTMLFooter ); $this->SetHTMLFooter($this->HTMLFooterE ,'E'); } /*-- END HTMLHEADERS-FOOTERS --*/ if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN $this->_setAutoHeaderHeight($this->headerDetails['even'], $this->HTMLHeaderE); $this->_setAutoFooterHeight($this->footerDetails['even'], $this->HTMLFooterE); } else { // ODD or DEFAULT $this->_setAutoHeaderHeight($this->headerDetails['odd'], $this->HTMLHeader); $this->_setAutoFooterHeight($this->footerDetails['odd'], $this->HTMLFooter); } // Reset column top margin $this->y0 = $this->tMargin; $this->x=$this->lMargin; $this->y=$this->tMargin; } function _setAutoHeaderHeight(&$det, &$htmlh) { if ($this->setAutoTopMargin=='pad') { if ($htmlh['h']) { $h = $htmlh['h']; } else if ($det) { $h = $this->_getHFHeight($det,'H'); } else { $h = 0; } $this->tMargin = $this->margin_header + $h + $this->orig_tMargin; } else if ($this->setAutoTopMargin=='stretch') { if ($htmlh['h']) { $h = $htmlh['h']; } else if ($det) { $h = $this->_getHFHeight($det,'H'); } else { $h = 0; } $this->tMargin = max($this->orig_tMargin, $this->margin_header + $h + $this->autoMarginPadding); } } function _setAutoFooterHeight(&$det, &$htmlf) { if ($this->setAutoBottomMargin=='pad') { if ($htmlf['h']) { $h = $htmlf['h']; } else if ($det) { $h = $this->_getHFHeight($det,'F'); } else { $h = 0; } $this->bMargin = $this->margin_footer + $h + $this->orig_bMargin; $this->PageBreakTrigger=$this->h-$this->bMargin ; } else if ($this->setAutoBottomMargin=='stretch') { if ($htmlf['h']) { $h = $htmlf['h']; } else if ($det) { $h = $this->_getHFHeight($det,'F'); } else { $h = 0; } $this->bMargin = max($this->orig_bMargin, $this->margin_footer + $h + $this->autoMarginPadding); $this->PageBreakTrigger=$this->h-$this->bMargin ; } } function _getHFHeight(&$det,$end) { $h = 0; if(count($det)) { foreach(array('L','C','R') AS $pos) { if (isset($det[$pos]['content']) && $det[$pos]['content']) { if (isset($det[$pos]['font-size']) && $det[$pos]['font-size']) { $hfsz = $det[$pos]['font-size']; } else { $hfsz = $this->default_font_size; } $h = max($h,$hfsz/_MPDFK); } } if ($det['line'] && $end=='H') { $h += $h/_MPDFK*$this->header_line_spacing; } else if ($det['line'] && $end=='F') { $h += $h/_MPDFK*$this->footer_line_spacing; } } return $h; } function _endpage() { /*-- CSS-IMAGE-FLOAT --*/ $this->printfloatbuffer(); /*-- END CSS-IMAGE-FLOAT --*/ // mPDF 5.3.41 if($this->visibility!='visible') $this->SetVisibility('visible'); //End of page contents $this->state=1; } function _newobj($obj_id=false,$onlynewobj=false) { if (!$obj_id) { $obj_id = ++$this->n; } //Begin a new object if (!$onlynewobj) { $this->offsets[$obj_id] = strlen($this->buffer); $this->_out($obj_id.' 0 obj'); $this->_current_obj_id = $obj_id; // for later use with encryption } } function _dounderline($x,$y,$txt) { // Now print line exactly where $y secifies - called from Text() and Cell() - adjust position there // WORD SPACING $w =($this->GetStringWidth($txt)*_MPDFK) + ($this->charspacing * mb_strlen( $txt, $this->mb_enc )) + ( $this->ws * mb_substr_count( $txt, ' ', $this->mb_enc )); //Draw a line return sprintf('%.3F %.3F m %.3F %.3F l S',$x*_MPDFK,($this->h-$y)*_MPDFK,($x*_MPDFK)+$w,($this->h-$y)*_MPDFK); } function _imageError($file, $firsttime, $msg) { // Save re-trying image URL's which have already failed $this->failedimages[$file] = true; if ($firsttime && ($this->showImageErrors || $this->debug)) { $this->Error("IMAGE Error (".$file."): ".$msg); } return false; } function _getImage(&$file, $firsttime=true, $allowvector=true, $orig_srcpath=false) { // firsttime i.e. whether to add to this->images - use false when calling iteratively // mPDF 5.3.95 $file = urldecode($file); if ($orig_srcpath) { $orig_srcpath = urldecode($orig_srcpath); } // Image Data passed directly as var:varname if (preg_match('/var:\s*(.*)/',$file, $v)) { $data = $this->$v[1]; $file = md5($data); } $ppUx = 0; if ($firsttime && preg_match('/(.*\/)([^\/]*)/',$file,$fm)) { if (strlen($fm[2])) { $file = $fm[1].preg_replace('/ /','%20',$fm[2]); } } if ($orig_srcpath && isset($this->images[$orig_srcpath])) { $file=$orig_srcpath; return $this->images[$orig_srcpath]; } if (isset($this->images[$file])) { return $this->images[$file]; } else if ($orig_srcpath && isset($this->formobjects[$orig_srcpath])) { $file=$orig_srcpath; return $this->formobjects[$file]; } else if (isset($this->formobjects[$file])) { return $this->formobjects[$file]; } // Save re-trying image URL's which have already failed else if ($firsttime && isset($this->failedimages[$file])) { return $this->_imageError($file, $firsttime, ''); } if (empty($data)) { $type = ''; $data = ''; $mqr=$this->_getMQR(); if ($mqr) { set_magic_quotes_runtime(0); } if ($orig_srcpath && $this->basepathIsLocal && $check = @fopen($orig_srcpath,"rb")) { fclose($check); $file=$orig_srcpath; $data = file_get_contents($file); $type = $this->_imageTypeFromString($data); } if (!$data && $check = @fopen($file,"rb")) { fclose($check); $data = file_get_contents($file); $type = $this->_imageTypeFromString($data); } if ((!$data || !$type) && !ini_get('allow_url_fopen')) { // only worth trying if remote file and !ini_get('allow_url_fopen') $this->file_get_contents_by_socket($file, $data); // needs full url?? even on local (never needed for local) if ($data) { $type = $this->_imageTypeFromString($data); } } if ((!$data || !$type) && !ini_get('allow_url_fopen') && function_exists("curl_init")) { $this->file_get_contents_by_curl($file, $data); // needs full url?? even on local (never needed for local) if ($data) { $type = $this->_imageTypeFromString($data); } } if ($mqr) { set_magic_quotes_runtime($mqr); } } if (!$data) { return $this->_imageError($file, $firsttime, 'Could not find image file'); } if (empty($type)) { $type = $this->_imageTypeFromString($data); } if (($type == 'wmf' || $type == 'svg') && !$allowvector) { return $this->_imageError($file, $firsttime, 'WMF or SVG image file not supported in this context'); } // SVG if ($type == 'svg') { if (!class_exists('SVG', false)) { include(_MPDF_PATH .'classes/svg.php'); } $svg = new SVG($this); $family=$this->FontFamily; $style=$this->FontStyle; $size=$this->FontSizePt; $info = $svg->ImageSVG($data); //Restore font if($family) $this->SetFont($family,$style,$size,false); if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing SVG file'); } $info['type']='svg'; $info['i']=count($this->formobjects)+1; $this->formobjects[$file]=$info; return $info; } // JPEG if ($type == 'jpeg' || $type == 'jpg') { $hdr = $this->_jpgHeaderFromString($data); if (!$hdr) { return $this->_imageError($file, $firsttime, 'Error parsing JPG header'); } $a = $this->_jpgDataFromHeader($hdr); $j = strpos($data,'JFIF'); if ($j) { //Read resolution $unitSp=ord(substr($data,($j+7),1)); if ($unitSp > 0) { $ppUx=$this->_twobytes2int(substr($data,($j+8),2)); // horizontal pixels per meter, usually set to zero if ($unitSp == 2) { // = dots per cm (if == 1 set as dpi) $ppUx=round($ppUx/10 *25.4); } } } if ($a[2] == 'DeviceCMYK' && (($this->PDFA && $this->restrictColorSpace!=3) || $this->restrictColorSpace==2)) { // convert to RGB image if (!function_exists("gd_info")) { $this->Error("JPG image may not use CMYK color space (".$file.")."); } if ($this->PDFA && !$this->PDFAauto) { $this->PDFAXwarnings[] = "JPG image may not use CMYK color space - ".$file." - (Image converted to RGB. NB This will alter the colour profile of the image.)"; } $im = @imagecreatefromstring($data); if ($im) { $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png'; imageinterlace($im, false); $check = @imagepng($im, $tempfile); if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse JPG(CMYK) image'); } $info = $this->_getImage($tempfile, false); if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse JPG(CMYK) image'); } imagedestroy($im); unlink($tempfile); $info['type']='jpg'; if ($firsttime) { $info['i']=count($this->images)+1; $this->images[$file]=$info; } return $info; } else { return $this->_imageError($file, $firsttime, 'Error creating GD image file from JPG(CMYK) image'); } } else if ($a[2] == 'DeviceRGB' && ($this->PDFX || $this->restrictColorSpace==3)) { // Convert to CMYK image stream - nominally returned as type='png' $info = $this->_convImage($data, $a[2], 'DeviceCMYK', $a[0], $a[1], $ppUx, false); if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "JPG image may not use RGB color space - ".$file." - (Image converted to CMYK. NB This will alter the colour profile of the image.)"; } } else if (($a[2] == 'DeviceRGB' || $a[2] == 'DeviceCMYK') && $this->restrictColorSpace==1) { // Convert to Grayscale image stream - nominally returned as type='png' $info = $this->_convImage($data, $a[2], 'DeviceGray', $a[0], $a[1], $ppUx, false); } else { $info = array('w'=>$a[0],'h'=>$a[1],'cs'=>$a[2],'bpc'=>$a[3],'f'=>'DCTDecode','data'=>$data, 'type'=>'jpg'); if ($ppUx) { $info['set-dpi'] = $ppUx; } } if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing or converting JPG image'); } if ($firsttime) { $info['i']=count($this->images)+1; $this->images[$file]=$info; } return $info; } // PNG else if ($type == 'png') { //Check signature if(substr($data,0,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) { return $this->_imageError($file, $firsttime, 'Error parsing PNG identifier'); } //Read header chunk if(substr($data,12,4)!='IHDR') { return $this->_imageError($file, $firsttime, 'Incorrect PNG file (no IHDR block found)'); } $w=$this->_fourbytes2int(substr($data,16,4)); $h=$this->_fourbytes2int(substr($data,20,4)); $bpc=ord(substr($data,24,1)); $errpng = false; $pngalpha = false; if($bpc>8) { $errpng = 'not 8-bit depth'; } $ct=ord(substr($data,25,1)); if($ct==0) { $colspace='DeviceGray'; } elseif($ct==2) { $colspace='DeviceRGB'; } elseif($ct==3) { $colspace='Indexed'; } elseif($ct==4) { $colspace='DeviceGray'; $errpng = 'alpha channel'; $pngalpha = true; } else { $colspace='DeviceRGB'; $errpng = 'alpha channel'; $pngalpha = true; } if(ord(substr($data,26,1))!=0) { $errpng = 'compression method'; } if(ord(substr($data,27,1))!=0) { $errpng = 'filter method'; } if(ord(substr($data,28,1))!=0) { $errpng = 'interlaced file'; } $j = strpos($data,'pHYs'); if ($j) { //Read resolution $unitSp=ord(substr($data,($j+12),1)); if ($unitSp == 1) { $ppUx=$this->_fourbytes2int(substr($data,($j+4),4)); // horizontal pixels per meter, usually set to zero $ppUx=round($ppUx/1000 *25.4); } } if (($colspace == 'DeviceRGB' || $colspace == 'Indexed') && ($this->PDFX || $this->restrictColorSpace==3)) { // Convert to CMYK image stream - nominally returned as type='png' $info = $this->_convImage($data, $colspace, 'DeviceCMYK', $w, $h, $ppUx, $pngalpha); if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "PNG image may not use RGB color space - ".$file." - (Image converted to CMYK. NB This will alter the colour profile of the image.)"; } } else if (($colspace == 'DeviceRGB' || $colspace == 'Indexed') && $this->restrictColorSpace==1) { // Convert to Grayscale image stream - nominally returned as type='png' $info = $this->_convImage($data, $colspace, 'DeviceGray', $w, $h, $ppUx, $pngalpha); } else if (($this->PDFA || $this->PDFX) && $pngalpha) { // Remove alpha channel if ($this->restrictColorSpace==1) { // Grayscale $info = $this->_convImage($data, $colspace, 'DeviceGray', $w, $h, $ppUx, $pngalpha); } else if ($this->restrictColorSpace==3) { // CMYK $info = $this->_convImage($data, $colspace, 'DeviceCMYK', $w, $h, $ppUx, $pngalpha); } else if ($this->PDFA ) { // RGB $info = $this->_convImage($data, $colspace, 'DeviceRGB', $w, $h, $ppUx, $pngalpha); } if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "Transparency (alpha channel) not permitted in PDFA or PDFX files - ".$file." - (Image converted to one without transparency.)"; } } else if ($errpng || $pngalpha) { if (function_exists('gd_info')) { $gd = gd_info(); } else {$gd = array(); } if (!isset($gd['PNG Support'])) { return $this->_imageError($file, $firsttime, 'GD library required for PNG image ('.$errpng.')'); } $im = imagecreatefromstring($data); if (!$im) { return $this->_imageError($file, $firsttime, 'Error creating GD image from PNG file ('.$errpng.')'); } $w = imagesx($im); $h = imagesy($im); if ($im) { $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png'; // Alpha channel set if ($pngalpha) { if ($this->PDFA) { $this->Error("PDFA1-b does not permit images with alpha channel transparency (".$file.")."); } $imgalpha = imagecreate($w, $h); // generate gray scale pallete for ($c = 0; $c < 256; ++$c) { ImageColorAllocate($imgalpha, $c, $c, $c); } // extract alpha channel $gammacorr = 2.2; // gamma correction // mPDF 5.3.07 for ($xpx = 0; $xpx < $w; ++$xpx) { for ($ypx = 0; $ypx < $h; ++$ypx) { // mPDF 5.3.07 //$colorindex = imagecolorat($im, $xpx, $ypx); //$col = imagecolorsforindex($im, $colorindex); //$gamma2 = (pow((((127 - $col['alpha']) * 255 / 127) / 255), $gammacorr) * 255); $alpha = (imagecolorat($im, $xpx, $ypx) & 0x7F000000) >> 24; if ($alpha < 127) { if ($alpha==0) { $gamma = 255; } else $gamma = (pow((((127 - $alpha) * 255 / 127) / 255), $gammacorr) * 255); imagesetpixel($imgalpha, $xpx, $ypx, $gamma); } } } // create temp alpha file $tempfile_alpha = _MPDF_TEMP_PATH.'_tempMskPNG'.RAND(1,10000).'.png'; if (!is_writable($tempfile_alpha)) { ob_start(); $check = @imagepng($imgalpha); if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); } imagedestroy($imgalpha); $this->_tempimg = ob_get_contents(); $this->_tempimglnk = 'var:_tempimg'; ob_end_clean(); // extract image without alpha channel $imgplain = imagecreatetruecolor($w, $h); imagecopy($imgplain, $im, 0, 0, 0, 0, $w, $h); // create temp image file $minfo = $this->_getImage($this->_tempimglnk, false); if (!$minfo) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); } ob_start(); $check = @imagepng($imgplain); if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); } $this->_tempimg = ob_get_contents(); $this->_tempimglnk = 'var:_tempimg'; ob_end_clean(); $info = $this->_getImage($this->_tempimglnk, false); if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); } imagedestroy($imgplain); $imgmask = count($this->images)+1; $minfo['cs'] = 'DeviceGray'; $minfo['i']=$imgmask ; $this->images[$tempfile_alpha] = $minfo; } else { $check = @imagepng($imgalpha, $tempfile_alpha); if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile_alpha.') parsing PNG image with alpha channel ('.$errpng.')'); } imagedestroy($imgalpha); // extract image without alpha channel $imgplain = imagecreatetruecolor($w, $h); imagecopy($imgplain, $im, 0, 0, 0, 0, $w, $h); // create temp image file $check = @imagepng($imgplain, $tempfile); if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile.') parsing PNG image with alpha channel ('.$errpng.')'); } imagedestroy($imgplain); // embed mask image $minfo = $this->_getImage($tempfile_alpha, false); unlink($tempfile_alpha); if (!$minfo) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile_alpha.') created with GD library to parse PNG image'); } $imgmask = count($this->images)+1; $minfo['cs'] = 'DeviceGray'; $minfo['i']=$imgmask ; $this->images[$tempfile_alpha] = $minfo; // embed image, masked with previously embedded mask $info = $this->_getImage($tempfile, false); unlink($tempfile); if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse PNG image'); } } $info['masked'] = $imgmask; if ($ppUx) { $info['set-dpi'] = $ppUx; } $info['type']='png'; if ($firsttime) { $info['i']=count($this->images)+1; $this->images[$file]=$info; } return $info; } else { // No alpha/transparency set imagealphablending($im, false); imagesavealpha($im, false); imageinterlace($im, false); if (!is_writable($tempfile)) { ob_start(); $check = @imagepng($im); if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); } $this->_tempimg = ob_get_contents(); $this->_tempimglnk = 'var:_tempimg'; ob_end_clean(); $info = $this->_getImage($this->_tempimglnk, false); if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); } imagedestroy($im); } else { $check = @imagepng($im, $tempfile ); if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile.') parsing PNG image ('.$errpng.')'); } imagedestroy($im); $info = $this->_getImage($tempfile, false) ; unlink($tempfile ); if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse PNG image'); } } if ($ppUx) { $info['set-dpi'] = $ppUx; } $info['type']='png'; if ($firsttime) { $info['i']=count($this->images)+1; $this->images[$file]=$info; } return $info; } } } else { $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>'; //Scan chunks looking for palette, transparency and image data $pal=''; $trns=''; $pngdata=''; $p = 33; do { $n=$this->_fourbytes2int(substr($data,$p,4)); $p += 4; $type=substr($data,$p,4); $p += 4; if($type=='PLTE') { //Read palette $pal=substr($data,$p,$n); $p += $n; $p += 4; } elseif($type=='tRNS') { //Read transparency info $t=substr($data,$p,$n); $p += $n; if($ct==0) $trns=array(ord(substr($t,1,1))); elseif($ct==2) $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1))); else { $pos=strpos($t,chr(0)); if(is_int($pos)) $trns=array($pos); } $p += 4; } elseif($type=='IDAT') { $pngdata.=substr($data,$p,$n); $p += $n; $p += 4; } elseif($type=='IEND') { break; } else if (preg_match('/[a-zA-Z]{4}/',$type)) { $p += $n+4; } else { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data'); } } while($n); if (!$pngdata) { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data - no IDAT data found'); } if($colspace=='Indexed' and empty($pal)) { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data - missing colour palette'); } $info = array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$pngdata); $info['type']='png'; if ($ppUx) { $info['set-dpi'] = $ppUx; } } if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing or converting PNG image'); } if ($firsttime) { $info['i']=count($this->images)+1; $this->images[$file]=$info; } return $info; } // GIF else if ($type == 'gif') { if (function_exists('gd_info')) { $gd = gd_info(); } else {$gd = array(); } if (isset($gd['GIF Read Support']) && $gd['GIF Read Support']) { $im = @imagecreatefromstring($data); if ($im) { $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png'; imagealphablending($im, false); imagesavealpha($im, false); imageinterlace($im, false); if (!is_writable($tempfile)) { ob_start(); $check = @imagepng($im); if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse GIF image'); } $this->_tempimg = ob_get_contents(); $this->_tempimglnk = 'var:_tempimg'; ob_end_clean(); $info = $this->_getImage($this->_tempimglnk, false); if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse GIF image'); } imagedestroy($im); } else { $check = @imagepng($im, $tempfile); if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse GIF image'); } $info = $this->_getImage($tempfile, false); if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse GIF image'); } imagedestroy($im); unlink($tempfile); } $info['type']='gif'; if ($firsttime) { $info['i']=count($this->images)+1; $this->images[$file]=$info; } return $info; } else { return $this->_imageError($file, $firsttime, 'Error creating GD image file from GIF image'); } } if (!class_exists('gif', false)) { include_once(_MPDF_PATH.'classes/gif.php'); } $gif=new CGIF(); $h=0; $w=0; $gif->loadFile($data, 0); if(isset($gif->m_img->m_gih->m_bLocalClr) && $gif->m_img->m_gih->m_bLocalClr) { $nColors = $gif->m_img->m_gih->m_nTableSize; $pal = $gif->m_img->m_gih->m_colorTable->toString(); if($bgColor != -1) { $bgColor = $gif->m_img->m_gih->m_colorTable->colorIndex($bgColor); } $colspace='Indexed'; } elseif(isset($gif->m_gfh->m_bGlobalClr) && $gif->m_gfh->m_bGlobalClr) { $nColors = $gif->m_gfh->m_nTableSize; $pal = $gif->m_gfh->m_colorTable->toString(); if((isset($bgColor)) and $bgColor != -1) { $bgColor = $gif->m_gfh->m_colorTable->colorIndex($bgColor); } $colspace='Indexed'; } else { $nColors = 0; $bgColor = -1; $colspace='DeviceGray'; $pal=''; } $trns=''; if(isset($gif->m_img->m_bTrans) && $gif->m_img->m_bTrans && ($nColors > 0)) { $trns=array($gif->m_img->m_nTrans); } $gifdata=$gif->m_img->m_data; $w=$gif->m_gfh->m_nWidth; $h=$gif->m_gfh->m_nHeight; $gif->ClearData(); if($colspace=='Indexed' and empty($pal)) { return $this->_imageError($file, $firsttime, 'Error parsing GIF image - missing colour palette'); } if ($this->compress) { $gifdata=gzcompress($gifdata); $info = array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'f'=>'FlateDecode', 'pal'=>$pal, 'trns'=>$trns, 'data'=>$gifdata); } else { $info = array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'pal'=>$pal, 'trns'=>$trns, 'data'=>$gifdata); } $info['type']='gif'; if ($firsttime) { $info['i']=count($this->images)+1; $this->images[$file]=$info; } return $info; } /*-- IMAGES-BMP --*/ // BMP (Windows Bitmap) else if ($type == 'bmp') { // mPDF 5.3.89 if (!class_exists('bmp', false)) { include(_MPDF_PATH.'classes/bmp.php'); } if (empty($this->bmp)) { $this->bmp = new bmp($this); } $info = $this->bmp->_getBMPimage($data, $file); if (isset($info['error'])) { return $this->_imageError($file, $firsttime, $info['error']); } if ($firsttime) { $info['i']=count($this->images)+1; $this->images[$file]=$info; } return $info; } /*-- END IMAGES-BMP --*/ /*-- IMAGES-WMF --*/ // WMF else if ($type == 'wmf') { // mPDF 5.3.89 if (!class_exists('wmf', false)) { include(_MPDF_PATH.'classes/wmf.php'); } if (empty($this->wmf)) { $this->wmf = new wmf($this); } $wmfres = $this->wmf->_getWMFimage($data); if ($wmfres[0]==0) { if ($wmfres[1]) { return $this->_imageError($file, $firsttime, $wmfres[1]); } return $this->_imageError($file, $firsttime, 'Error parsing WMF image'); } $info = array('x'=>$wmfres[2][0],'y'=>$wmfres[2][1],'w'=>$wmfres[3][0],'h'=>$wmfres[3][1],'data'=>$wmfres[1]); $info['i']=count($this->formobjects)+1; $info['type']='wmf'; $this->formobjects[$file]=$info; return $info; } /*-- END IMAGES-WMF --*/ // UNKNOWN TYPE - try GD imagecreatefromstring else { if (function_exists('gd_info')) { $gd = gd_info(); } else {$gd = array(); } if (isset($gd['PNG Support']) && $gd['PNG Support']) { $im = @imagecreatefromstring($data); if (!$im) { return $this->_imageError($file, $firsttime, 'Error parsing image file - image type not recognised, and not supported by GD imagecreate'); } $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png'; imagealphablending($im, false); imagesavealpha($im, false); imageinterlace($im, false); $check = @imagepng($im, $tempfile); if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse unknown image type'); } $info = $this->_getImage($tempfile, false); imagedestroy($im); unlink($tempfile); if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse unknown image type'); } $info['type']='png'; if ($firsttime) { $info['i']=count($this->images)+1; $this->images[$file]=$info; } return $info; } } return $this->_imageError($file, $firsttime, 'Error parsing image file - image type not recognised'); } //============================================================== function _convImage(&$data, $colspace, $targetcs, $w, $h, $dpi, $mask) { if ($this->PDFA || $this->PDFX) { $mask=false; } $im = @imagecreatefromstring($data); $info = array(); if ($im) { $imgdata = ''; $mimgdata = ''; $minfo = array(); //Read transparency info $trns=array(); $trnsrgb = false; if (!$this->PDFA && !$this->PDFX) { $p = strpos($data,'tRNS'); if ($p) { $n=$this->_fourbytes2int(substr($data,($p-4),4)); $t = substr($data,($p+4),$n); if ($colspace=='DeviceGray') { $trns=array(ord(substr($t,1,1))); $trnsrgb = array($trns[0],$trns[0],$trns[0]); } else if ($colspace=='DeviceRGB') { $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1))); $trnsrgb = $trns; if ($targetcs=='DeviceCMYK') { $col = $this->rgb2cmyk(array(3,$trns[0],$trns[1],$trns[2])); $c1 = intval($col[1]*2.55); $c2 = intval($col[2]*2.55); $c3 = intval($col[3]*2.55); $c4 = intval($col[4]*2.55); $trns = array($c1,$c2,$c3,$c4); } else if ($targetcs=='DeviceGray') { $c = intval(($trns[0] * .21) + ($trns[1] * .71) + ($trns[2] * .07)); $trns = array($c); } } else { // Indexed $pos = strpos($t,chr(0)); if (is_int($pos)) { $pal = imagecolorsforindex($im, $pos); $r = $pal['red']; $g = $pal['green']; $b = $pal['blue']; $trns=array($r,$g,$b); // **** $trnsrgb = $trns; if ($targetcs=='DeviceCMYK') { $col = $this->rgb2cmyk(array(3,$r,$g,$b)); $c1 = intval($col[1]*2.55); $c2 = intval($col[2]*2.55); $c3 = intval($col[3]*2.55); $c4 = intval($col[4]*2.55); $trns = array($c1,$c2,$c3,$c4); } else if ($targetcs=='DeviceGray') { $c = intval(($r * .21) + ($g * .71) + ($b * .07)); $trns = array($c); } } } } } for ($i = 0; $i < $h; $i++) { for ($j = 0; $j < $w; $j++) { $rgb = imagecolorat($im, $j, $i); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; if ($colspace=='Indexed') { $pal = imagecolorsforindex($im, $rgb); $r = $pal['red']; $g = $pal['green']; $b = $pal['blue']; } if ($targetcs=='DeviceCMYK') { $col = $this->rgb2cmyk(array(3,$r,$g,$b)); $c1 = intval($col[1]*2.55); $c2 = intval($col[2]*2.55); $c3 = intval($col[3]*2.55); $c4 = intval($col[4]*2.55); if ($trnsrgb) { // original pixel was not set as transparent but processed color does match if ($trnsrgb!=array($r,$g,$b) && $trns==array($c1,$c2,$c3,$c4)) { if ($c4==0) { $c4=1; } else { $c4--; } } } $imgdata .= chr($c1).chr($c2).chr($c3).chr($c4); } else if ($targetcs=='DeviceGray') { $c = intval(($r * .21) + ($g * .71) + ($b * .07)); if ($trnsrgb) { // original pixel was not set as transparent but processed color does match if ($trnsrgb!=array($r,$g,$b) && $trns==array($c)) { if ($c==0) { $c=1; } else { $c--; } } } $imgdata .= chr($c); } else if ($targetcs=='DeviceRGB') { $imgdata .= chr($r).chr($g).chr($b); } if ($mask) { $col = imagecolorsforindex($im, $rgb); $gammacorr = 2.2; // gamma correction $gamma = intval((pow((((127 - $col['alpha']) * 255 / 127) / 255), $gammacorr) * 255)); $mimgdata .= chr($gamma); } } } if ($targetcs=='DeviceGray') { $ncols = 1; } else if ($targetcs=='DeviceRGB') { $ncols = 3; } else if ($targetcs=='DeviceCMYK') { $ncols = 4; } $imgdata = gzcompress($imgdata); $info = array('w'=>$w,'h'=>$h,'cs'=>$targetcs,'bpc'=>8,'f'=>'FlateDecode','data'=>$imgdata, 'type'=>'png', 'parms'=>'/DecodeParms <</Colors '.$ncols.' /BitsPerComponent 8 /Columns '.$w.'>>'); if ($dpi) { $info['set-dpi'] = $dpi; } if ($mask) { $mimgdata = gzcompress($mimgdata); $minfo = array('w'=>$w,'h'=>$h,'cs'=>'DeviceGray','bpc'=>8,'f'=>'FlateDecode','data'=>$mimgdata, 'type'=>'png', 'parms'=>'/DecodeParms <</Colors '.$ncols.' /BitsPerComponent 8 /Columns '.$w.'>>'); if ($dpi) { $minfo['set-dpi'] = $dpi; } $tempfile = '_tempImgPNG'.RAND(1,10000).'.png'; $imgmask = count($this->images)+1; $minfo['i']=$imgmask ; $this->images[$tempfile] = $minfo; $info['masked'] = $imgmask; } else if ($trns) { $info['trns'] = $trns; } imagedestroy($im); } return $info; } function _fourbytes2int($s) { //Read a 4-byte integer from string return (ord($s[0])<<24) + (ord($s[1])<<16) + (ord($s[2])<<8) + ord($s[3]); } function _twobytes2int($s) { //Read a 2-byte integer from string return (ord(substr($s, 0, 1))<<8) + ord(substr($s, 1, 1)); } function _jpgHeaderFromString(&$data) { $p = 4; $p += $this->_twobytes2int(substr($data, $p, 2)); // Length of initial marker block $marker = substr($data, $p, 2); while($marker != chr(255).chr(192) && $marker != chr(255).chr(194) && $p<strlen($data)) { // Start of frame marker (FFC0) or (FFC2) mPDF 4.4.004 $p += ($this->_twobytes2int(substr($data, $p+2, 2))) + 2; // Length of marker block $marker = substr($data, $p, 2); } if ($marker != chr(255).chr(192) && $marker != chr(255).chr(194)) { return false; } return substr($data, $p+2, 10); } function _jpgDataFromHeader($hdr) { $bpc = ord(substr($hdr, 2, 1)); if (!$bpc) { $bpc = 8; } $h = $this->_twobytes2int(substr($hdr, 3, 2)); $w = $this->_twobytes2int(substr($hdr, 5, 2)); $channels = ord(substr($hdr, 7, 1)); if ($channels==3) { $colspace='DeviceRGB'; } elseif($channels==4) { $colspace='DeviceCMYK'; } else { $colspace='DeviceGray'; } return array($w, $h, $colspace, $bpc); } function file_get_contents_by_curl($url, &$data) { $timeout = 5; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_NOBODY, 0); curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 ); curl_setopt ( $ch , CURLOPT_CONNECTTIMEOUT , $timeout ); $data = curl_exec($ch); curl_close($ch); } function file_get_contents_by_socket($url, &$data) { $timeout = 1; $p = parse_url($url); $file = $p['path']; if ($p['query']) { $file .= '?'.$p['query']; } if(!($fh = @fsockopen($p['host'], 80, $errno, $errstr, $timeout))) { return false; } $getstring = "GET ".$file." HTTP/1.0 \r\n" . "Host: ".$p['host']." \r\n" . "Connection: close\r\n\r\n"; fwrite($fh, $getstring); // Get rid of HTTP header $s = fgets($fh, 1024); if (!$s) { return false; } $httpheader .= $s; while (!feof($fh)) { $s = fgets($fh, 1024); if ( $s == "\r\n" ) { break; } } $data = ''; while (!feof($fh)) { $data .= fgets($fh, 1024); } fclose($fh); } //============================================================== function _imageTypeFromString(&$data) { $type = ''; if (substr($data, 6, 4)== 'JFIF' || substr($data, 6, 4)== 'Exif') { $type = 'jpeg'; } else if (substr($data, 0, 6)== "GIF87a" || substr($data, 0, 6)== "GIF89a") { $type = 'gif'; } else if (substr($data, 0, 8)== chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) { $type = 'png'; } /*-- IMAGES-WMF --*/ else if (substr($data, 0, 4)== chr(215).chr(205).chr(198).chr(154)) { $type = 'wmf'; } /*-- END IMAGES-WMF --*/ else if (preg_match('/<svg.*<\/svg>/is',$data)) { $type = 'svg'; } // BMP images else if (substr($data, 0, 2)== "BM") { $type = 'bmp'; } return $type; } //============================================================== // Moved outside WMF as also needed for SVG function _putformobjects() { reset($this->formobjects); while(list($file,$info)=each($this->formobjects)) { $this->_newobj(); $this->formobjects[$file]['n']=$this->n; $this->_out('<</Type /XObject'); $this->_out('/Subtype /Form'); $this->_out('/Group '.($this->n+1).' 0 R'); $this->_out('/BBox ['.$info['x'].' '.$info['y'].' '.($info['w']+$info['x']).' '.($info['h']+$info['y']).']'); if ($this->compress) $this->_out('/Filter /FlateDecode'); $data=($this->compress) ? gzcompress($info['data']) : $info['data']; $this->_out('/Length '.strlen($data).'>>'); $this->_putstream($data); unset($this->formobjects[$file]['data']); $this->_out('endobj'); // Required for SVG transparency (opacity) to work $this->_newobj(); $this->_out('<</Type /Group'); $this->_out('/S /Transparency'); $this->_out('>>'); $this->_out('endobj'); } } function _freadint($f) { //Read a 4-byte integer from file $i=ord(fread($f,1))<<24; $i+=ord(fread($f,1))<<16; $i+=ord(fread($f,1))<<8; $i+=ord(fread($f,1)); return $i; } function _UTF16BEtextstring($s) { $s = $this->UTF8ToUTF16BE($s, true); /*-- ENCRYPTION --*/ if ($this->encrypted) { $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s); } /*-- END ENCRYPTION --*/ return '('. $this->_escape($s).')'; } function _textstring($s) { /*-- ENCRYPTION --*/ if ($this->encrypted) { $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s); } /*-- END ENCRYPTION --*/ return '('. $this->_escape($s).')'; } function _escape($s) { // the chr(13) substitution fixes the Bugs item #1421290. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r')); } function _putstream($s) { /*-- ENCRYPTION --*/ if ($this->encrypted) { $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s); } /*-- END ENCRYPTION --*/ $this->_out('stream'); $this->_out($s); $this->_out('endstream'); } function _out($s,$ln=true) { if($this->state==2) { if ($this->bufferoutput) { $this->headerbuffer.= $s."\n"; } /*-- COLUMNS --*/ else if (($this->ColActive) && !$this->processingHeader && !$this->processingFooter) { // Captures everything in buffer for columns; Almost everything is sent from fn. Cell() except: // Images sent from Image() or // later sent as _out($textto) in printbuffer // Line() if (preg_match('/q \d+\.\d\d+ 0 0 (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ cm \/(I|FO)\d+ Do Q/',$s,$m)) { // Image data $h = ($m[1]/_MPDFK); // Update/overwrite the lowest bottom of printing y value for a column $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$h; } /*-- TABLES --*/ else if (preg_match('/\d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ ([\-]{0,1}\d+\.\d\d+) re/',$s,$m) && $this->tableLevel>0) { // Rect in table $h = ($m[1]/_MPDFK); // Update/overwrite the lowest bottom of printing y value for a column $this->ColDetails[$this->CurrCol]['bottom_margin'] = max($this->ColDetails[$this->CurrCol]['bottom_margin'],($this->y+$h)); } /*-- END TABLES --*/ else { // Td Text Set in Cell() if (isset($this->ColDetails[$this->CurrCol]['bottom_margin'])) { $h = $this->ColDetails[$this->CurrCol]['bottom_margin'] - $this->y; } else { $h = 0; } } if ($h < 0) { $h = -$h; } $this->columnbuffer[] = array( 's' => $s, // Text string to output 'col' => $this->CurrCol, // Column when printed 'x' => $this->x, // x when printed 'y' => $this->y, // this->y when printed (after column break) 'h' => $h // actual y at bottom when printed = y+h ); } /*-- END COLUMNS --*/ /*-- TABLES --*/ else if ($this->table_rotate && !$this->processingHeader && !$this->processingFooter) { // Captures eveything in buffer for rotated tables; $this->tablebuffer .= $s . "\n"; } /*-- END TABLES --*/ else if ($this->kwt && !$this->processingHeader && !$this->processingFooter) { // Captures eveything in buffer for keep-with-table (h1-6); $this->kwt_buffer[] = array( 's' => $s, // Text string to output 'x' => $this->x, // x when printed 'y' => $this->y, // y when printed ); } else if (($this->keep_block_together) && !$this->processingHeader && !$this->processingFooter) { if (!isset($this->ktBlock[$this->page]['bottom_margin'])) { $this->ktBlock[$this->page]['bottom_margin'] = $this->y; } // Captures eveything in buffer; if (preg_match('/q \d+\.\d\d+ 0 0 (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ cm \/(I|FO)\d+ Do Q/',$s,$m)) { // Image data $h = ($m[1]/_MPDFK); // Update/overwrite the lowest bottom of printing y value for Keep together block $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$h; } else { // Td Text Set in Cell() if (isset($this->ktBlock[$this->page]['bottom_margin'])) { $h = $this->ktBlock[$this->page]['bottom_margin'] - $this->y; } else { $h = 0; } } if ($h < 0) { $h = -$h; } $this->divbuffer[] = array( 'page' => $this->page, 's' => $s, // Text string to output 'x' => $this->x, // x when printed 'y' => $this->y, // y when printed (after column break) 'h' => $h // actual y at bottom when printed = y+h ); } else { $this->pages[$this->page] .= $s.($ln == true ? "\n" : ''); } } else { $this->buffer .= $s.($ln == true ? "\n" : ''); } } /*-- WATERMARK --*/ // add a watermark function watermark( $texte, $angle=45, $fontsize=96, $alpha=0.2 ) { if ($this->PDFA || $this->PDFX) { $this->Error('PDFA and PDFX do not permit transparency, so mPDF does not allow Watermarks!'); } if (!$this->watermark_font) { $this->watermark_font = $this->default_font; } $this->SetFont( $this->watermark_font, "B", $fontsize, false ); // Don't output $texte= $this->purify_utf8_text($texte); if ($this->text_input_as_HTML) { $texte= $this->all_entities_to_utf8($texte); } if ($this->usingCoreFont) { $texte = mb_convert_encoding($texte,$this->mb_enc,'UTF-8'); } // DIRECTIONALITY $this->magic_reverse_dir($texte, true, $this->directionality); // *RTL* // Font-specific ligature substitution for Indic fonts if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($texte); // *INDIC* $this->SetAlpha($alpha); $this->SetTColor($this->ConvertColor(0)); $szfont = $fontsize; $loop = 0; $maxlen = (min($this->w,$this->h) ); // sets max length of text as 7/8 width/height of page while ( $loop == 0 ) { $this->SetFont( $this->watermark_font, "B", $szfont, false ); // Don't output $offset = ((sin(deg2rad($angle))) * ($szfont/_MPDFK)); $strlen = $this->GetStringWidth($texte); if ( $strlen > $maxlen - $offset ) $szfont --; else $loop ++; } $this->SetFont( $this->watermark_font, "B", $szfont-0.1, true, true); // Output The -0.1 is because SetFont above is not written to PDF // Repeating it will not output anything as mPDF thinks it is set $adj = ((cos(deg2rad($angle))) * ($strlen/2)); $opp = ((sin(deg2rad($angle))) * ($strlen/2)); $wx = ($this->w/2) - $adj + $offset/3; $wy = ($this->h/2) + $opp; $this->Rotate($angle,$wx,$wy); $this->Text($wx,$wy,$texte); $this->Rotate(0); $this->SetTColor($this->ConvertColor(0)); $this->SetAlpha(1); } function watermarkImg( $src, $alpha=0.2 ) { if ($this->PDFA || $this->PDFX) { $this->Error('PDFA and PDFX do not permit transparency, so mPDF does not allow Watermarks!'); } if ($this->watermarkImgBehind) { $this->watermarkImgAlpha = $this->SetAlpha($alpha, 'Normal', true); } else { $this->SetAlpha($alpha, $this->watermarkImgAlphaBlend); } $this->Image($src,0,0,0,0,'','', true, true, true); if (!$this->watermarkImgBehind) { $this->SetAlpha(1); } } /*-- END WATERMARK --*/ function Rotate($angle,$x=-1,$y=-1) { if($x==-1) $x=$this->x; if($y==-1) $y=$this->y; if($this->angle!=0) $this->_out('Q'); $this->angle=$angle; if($angle!=0) { $angle*=M_PI/180; $c=cos($angle); $s=sin($angle); $cx=$x*_MPDFK; $cy=($this->h-$y)*_MPDFK; $this->_out(sprintf('q %.5F %.5F %.5F %.5F %.3F %.3F cm 1 0 0 1 %.3F %.3F cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy)); } } // mPDF 5.3.40 5.3.51 5.3.53 function CircularText($x, $y, $r, $text, $align='top', $fontfamily='', $fontsize=0, $fontstyle='', $kerning=120, $fontwidth=100) { if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); } if (empty($this->directw)) { $this->directw = new directw($this); } $this->directw->CircularText($x, $y, $r, $text, $align, $fontfamily, $fontsize, $fontstyle, $kerning, $fontwidth); } // From Invoice function RoundedRect($x, $y, $w, $h, $r, $style = '') { $hp = $this->h; if($style=='F') $op='f'; elseif($style=='FD' or $style=='DF') $op='B'; else $op='S'; $MyArc = 4/3 * (sqrt(2) - 1); $this->_out(sprintf('%.3F %.3F m',($x+$r)*_MPDFK,($hp-$y)*_MPDFK )); $xc = $x+$w-$r ; $yc = $y+$r; $this->_out(sprintf('%.3F %.3F l', $xc*_MPDFK,($hp-$y)*_MPDFK )); $this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc); $xc = $x+$w-$r ; $yc = $y+$h-$r; $this->_out(sprintf('%.3F %.3F l',($x+$w)*_MPDFK,($hp-$yc)*_MPDFK)); $this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r); $xc = $x+$r ; $yc = $y+$h-$r; $this->_out(sprintf('%.3F %.3F l',$xc*_MPDFK,($hp-($y+$h))*_MPDFK)); $this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc); $xc = $x+$r ; $yc = $y+$r; $this->_out(sprintf('%.3F %.3F l',($x)*_MPDFK,($hp-$yc)*_MPDFK )); $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r); $this->_out($op); } function _Arc($x1, $y1, $x2, $y2, $x3, $y3) { $h = $this->h; $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', $x1*_MPDFK, ($h-$y1)*_MPDFK, $x2*_MPDFK, ($h-$y2)*_MPDFK, $x3*_MPDFK, ($h-$y3)*_MPDFK)); } //==================================================== /*-- DIRECTW --*/ function Shaded_box( $text,$font='',$fontstyle='B',$szfont='',$width='70%',$style='DF',$radius=2.5,$fill='#FFFFFF',$color='#000000',$pad=2 ) { // F (shading - no line),S (line, no shading),DF (both) if (!class_exists('directw', false)) { include(_MPDF_PATH.'classes/directw.php'); } if (empty($this->directw)) { $this->directw = new directw($this); } $this->directw->Shaded_box( $text,$font,$fontstyle,$szfont,$width,$style,$radius,$fill,$color,$pad); } /*-- END DIRECTW --*/ function UTF8StringToArray($str, $addSubset=true) { $out = array(); $len = strlen($str); for ($i = 0; $i < $len; $i++) { $uni = -1; $h = ord($str[$i]); if ( $h <= 0x7F ) $uni = $h; elseif ( $h >= 0xC2 ) { if ( ($h <= 0xDF) && ($i < $len -1) ) $uni = ($h & 0x1F) << 6 | (ord($str[++$i]) & 0x3F); elseif ( ($h <= 0xEF) && ($i < $len -2) ) $uni = ($h & 0x0F) << 12 | (ord($str[++$i]) & 0x3F) << 6 | (ord($str[++$i]) & 0x3F); elseif ( ($h <= 0xF4) && ($i < $len -3) ) $uni = ($h & 0x0F) << 18 | (ord($str[++$i]) & 0x3F) << 12 | (ord($str[++$i]) & 0x3F) << 6 | (ord($str[++$i]) & 0x3F); } if ($uni >= 0) { $out[] = $uni; if ($addSubset && isset($this->CurrentFont['subset'])) { $this->CurrentFont['subset'][$uni] = $uni; } } } return $out; } //Convert utf-8 string to <HHHHHH> for Font Subsets function UTF8toSubset($str) { $ret = '<'; $str = preg_replace('/'.preg_quote($this->aliasNbPg,'/').'/', chr(7), $str ); $str = preg_replace('/'.preg_quote($this->aliasNbPgGp,'/').'/', chr(8), $str ); $unicode = $this->UTF8StringToArray($str); $orig_fid = $this->CurrentFont['subsetfontids'][0]; $last_fid = $this->CurrentFont['subsetfontids'][0]; foreach($unicode as $c) { if ($c == 7 || $c == 8) { if ($orig_fid != $last_fid) { $ret .= '> Tj /F'.$orig_fid.' '.$this->FontSizePt.' Tf <'; $last_fid = $orig_fid; } if ($c == 7) { $ret .= $this->aliasNbPgHex; } else { $ret .= $this->aliasNbPgGpHex; } continue; } for ($i=0; $i<99; $i++) { // return c as decimal char $init = array_search($c, $this->CurrentFont['subsets'][$i]); if ($init!==false) { if ($this->CurrentFont['subsetfontids'][$i] != $last_fid) { $ret .= '> Tj /F'.$this->CurrentFont['subsetfontids'][$i].' '.$this->FontSizePt.' Tf <'; $last_fid = $this->CurrentFont['subsetfontids'][$i]; } $ret .= sprintf("%02s", strtoupper(dechex($init))); break; } // TrueType embedded SUBSETS else if (count($this->CurrentFont['subsets'][$i]) < 255) { $n = count($this->CurrentFont['subsets'][$i]); $this->CurrentFont['subsets'][$i][$n] = $c; if ($this->CurrentFont['subsetfontids'][$i] != $last_fid) { $ret .= '> Tj /F'.$this->CurrentFont['subsetfontids'][$i].' '.$this->FontSizePt.' Tf <'; $last_fid = $this->CurrentFont['subsetfontids'][$i]; } $ret .= sprintf("%02s", strtoupper(dechex($n))); break; } else if (!isset($this->CurrentFont['subsets'][($i+1)])) { // TrueType embedded SUBSETS $this->CurrentFont['subsets'][($i+1)] = array(0=>0); $new_fid = count($this->fonts)+$this->extraFontSubsets+1; $this->CurrentFont['subsetfontids'][($i+1)] = $new_fid; $this->extraFontSubsets++; } } } $ret .= '>'; if ($last_fid != $orig_fid) { $ret .= ' Tj /F'.$orig_fid.' '.$this->FontSizePt.' Tf <> '; } return $ret; } // Converts UTF-8 strings to UTF16-BE. function UTF8ToUTF16BE($str, $setbom=true) { if ($this->checkSIP && preg_match("/([\x{20000}-\x{2FFFF}])/u", $str)) { if (!in_array($this->currentfontfamily, array('gb','big5','sjis','uhc','gbB','big5B','sjisB','uhcB','gbI','big5I','sjisI','uhcI', 'gbBI','big5BI','sjisBI','uhcBI'))) { $str = preg_replace("/[\x{20000}-\x{2FFFF}]/u", chr(0), $str); } } if ($this->checkSMP && preg_match("/([\x{10000}-\x{1FFFF}])/u", $str )) { $str = preg_replace("/[\x{10000}-\x{1FFFF}]/u", chr(0), $str ); } $outstr = ""; // string to be returned if ($setbom) { $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM) } $outstr .= mb_convert_encoding($str, 'UTF-16BE', 'UTF-8'); return $outstr; } // ==================================================== // ==================================================== /*-- CJK-FONTS --*/ // from class PDF_Chinese CJK EXTENSIONS function AddCIDFont($family,$style,$name,&$cw,$CMap,$registry,$desc) { $fontkey=strtolower($family).strtoupper($style); if(isset($this->fonts[$fontkey])) $this->Error("Font already added: $family $style"); $i=count($this->fonts)+$this->extraFontSubsets+1; $name=str_replace(' ','',$name); if ($family == 'sjis') { $up = -120; } else { $up = -130; } // ? 'up' and 'ut' do not seem to be referenced anywhere $this->fonts[$fontkey]=array('i'=>$i,'type'=>'Type0','name'=>$name,'up'=>$up,'ut'=>40,'cw'=>$cw,'CMap'=>$CMap,'registry'=>$registry,'MissingWidth'=>1000,'desc'=>$desc); } function AddCJKFont($family) { if ($this->PDFA || $this->PDFX) { $this->Error("Adobe CJK fonts cannot be embedded in mPDF (required for PDFA1-b and PDFX/1-a)."); } if ($family == 'big5') { $this->AddBig5Font(); } else if ($family == 'gb') { $this->AddGBFont(); } else if ($family == 'sjis') { $this->AddSJISFont(); } else if ($family == 'uhc') { $this->AddUHCFont(); } } function AddBig5Font() { //Add Big5 font with proportional Latin $family='big5'; $name='MSungStd-Light-Acro'; $cw=$this->Big5_widths; $CMap='UniCNS-UTF16-H'; $registry=array('ordering'=>'CNS1','supplement'=>4); $desc = array( 'Ascent' => 880, 'Descent' => -120, 'CapHeight' => 880, 'Flags' => 6, 'FontBBox' => '[-160 -249 1015 1071]', 'ItalicAngle' => 0, 'StemV' => 93, ); $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc); $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc); $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc); $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc); } function AddGBFont() { //Add GB font with proportional Latin $family='gb'; $name='STSongStd-Light-Acro'; $cw=$this->GB_widths; $CMap='UniGB-UTF16-H'; $registry=array('ordering'=>'GB1','supplement'=>4); $desc = array( 'Ascent' => 752, 'Descent' => -271, 'CapHeight' => 737, 'Flags' => 6, 'FontBBox' => '[-25 -254 1000 880]', 'ItalicAngle' => 0, 'StemV' => 58, 'Style' => '<< /Panose <000000000400000000000000> >>', ); $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc); $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc); $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc); $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc); } function AddSJISFont() { //Add SJIS font with proportional Latin $family='sjis'; $name='KozMinPro-Regular-Acro'; $cw=$this->SJIS_widths; $CMap='UniJIS-UTF16-H'; $registry=array('ordering'=>'Japan1','supplement'=>5); $desc = array( 'Ascent' => 880, 'Descent' => -120, 'CapHeight' => 740, 'Flags' => 6, 'FontBBox' => '[-195 -272 1110 1075]', 'ItalicAngle' => 0, 'StemV' => 86, 'XHeight' => 502, ); $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc); $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc); $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc); $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc); } function AddUHCFont() { //Add UHC font with proportional Latin $family='uhc'; $name='HYSMyeongJoStd-Medium-Acro'; $cw=$this->UHC_widths; $CMap='UniKS-UTF16-H'; $registry=array('ordering'=>'Korea1','supplement'=>2); $desc = array( 'Ascent' => 880, 'Descent' => -120, 'CapHeight' => 720, 'Flags' => 6, 'FontBBox' => '[-28 -148 1001 880]', 'ItalicAngle' => 0, 'StemV' => 60, 'Style' => '<< /Panose <000000000600000000000000> >>', ); $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc); $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc); $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc); $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc); } /*-- END CJK-FONTS --*/ ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// function SetAutoFont($af = AUTOFONT_ALL) { if ($this->onlyCoreFonts) { return false; } if (!$af && $af !== 0) { $af = AUTOFONT_ALL; } $this->autoFontGroups = $af; if ($this->autoFontGroups ) { $this->useLang = true; } } function SetDefaultFont($font) { // Disallow embedded fonts to be used as defaults in PDFA if ($this->PDFA || $this->PDFX) { if (strtolower($font) == 'ctimes') { $font = 'serif'; } if (strtolower($font) == 'ccourier') { $font = 'monospace'; } if (strtolower($font) == 'chelvetica') { $font = 'sans-serif'; } } $font = $this->SetFont($font); // returns substituted font if necessary $this->default_font = $font; $this->original_default_font = $font; if (!$this->watermark_font ) { $this->watermark_font = $font; } // *WATERMARK* $this->defaultCSS['BODY']['FONT-FAMILY'] = $font; $this->CSS['BODY']['FONT-FAMILY'] = $font; } function SetDefaultFontSize($fontsize) { $this->default_font_size = $fontsize; $this->original_default_font_size = $fontsize; $this->SetFontSize($fontsize); $this->defaultCSS['BODY']['FONT-SIZE'] = $fontsize . 'pt'; $this->CSS['BODY']['FONT-SIZE'] = $fontsize . 'pt'; } function SetDefaultBodyCSS($prop, $val) { if ($prop) { $this->defaultCSS['BODY'][strtoupper($prop)] = $val; $this->CSS['BODY'][strtoupper($prop)] = $val; } } function SetDirectionality($dir='ltr') { /*-- RTL --*/ if (strtolower($dir) == 'rtl') { if ($this->directionality != 'rtl') { // Swop L/R Margins so page 1 RTL is an 'even' page $tmp = $this->DeflMargin; $this->DeflMargin = $this->DefrMargin; $this->DefrMargin = $tmp; $this->orig_lMargin = $this->DeflMargin; $this->orig_rMargin = $this->DefrMargin; $this->SetMargins($this->DeflMargin,$this->DefrMargin,$this->tMargin); } $this->directionality = 'rtl'; $this->defaultAlign = 'R'; $this->defaultTableAlign = 'R'; } else { /*-- END RTL --*/ $this->directionality = 'ltr'; $this->defaultAlign = 'L'; $this->defaultTableAlign = 'L'; } // *RTL* $this->CSS['BODY']['DIRECTION'] = $this->directionality; } // Added to set line-height-correction function SetLineHeightCorrection($val) { if ($val > 0) { $this->default_lineheight_correction = $val; } else { $this->default_lineheight_correction = 1.2; } } // Set a (fixed) lineheight to an actual value - either to named fontsize(pts) or default function SetLineHeight($FontPt='',$spacing = '') { if ($this->shrin_k > 1) { $k = $this->shrin_k; } else { $k = 1; } if ($spacing > 0) { if (preg_match('/mm/',$spacing)) { $this->lineheight = ($spacing + 0.0) / $k; // convert to number } else { if ($FontPt) { $this->lineheight = (($FontPt/_MPDFK) *$spacing); } else { $this->lineheight = (($this->FontSizePt/_MPDFK) *$spacing); } } } else { if ($FontPt) { $this->lineheight = (($FontPt/_MPDFK) *$this->normalLineheight); } else { $this->lineheight = (($this->FontSizePt/_MPDFK) *$this->normalLineheight); } } } function _computeLineheight($lh, $fs='') { if ($this->shrin_k > 1) { $k = $this->shrin_k; } else { $k = 1; } if (!$fs) { $fs = $this->FontSize; } if (preg_match('/mm/',$lh)) { return (($lh + 0.0) / $k); // convert to number } else if ($lh > 0) { return ($fs * $lh); } else if (isset($this->normalLineheight)) { return ($fs * $this->normalLineheight); } else return ($fs * $this->default_lineheight_correction); } function SetBasePath($str='') { if ( isset($_SERVER['HTTP_HOST']) ) { $host = $_SERVER['HTTP_HOST']; } else if ( isset($_SERVER['SERVER_NAME']) ) { $host = $_SERVER['SERVER_NAME']; } else { $host = ''; } if (!$str) { if ($_SERVER['SCRIPT_NAME']) { $currentPath = dirname($_SERVER['SCRIPT_NAME']); } else { $currentPath = dirname($_SERVER['PHP_SELF']); } $currentPath = str_replace("\\","/",$currentPath); if ($currentPath == '/') { $currentPath = ''; } if ($host) { $currpath = 'http://' . $host . $currentPath .'/'; } else { $currpath = ''; } $this->basepath = $currpath; $this->basepathIsLocal = true; return; } $str = preg_replace('/\?.*/','',$str); if (!preg_match('/(http|https|ftp):\/\/.*\//i',$str)) { $str .= '/'; } $str .= 'xxx'; // in case $str ends in / e.g. http://www.bbc.co.uk/ $this->basepath = dirname($str) . "/"; // returns e.g. e.g. http://www.google.com/dir1/dir2/dir3/ $this->basepath = str_replace("\\","/",$this->basepath); //If on Windows $tr = parse_url($this->basepath); if (isset($tr['host']) && ($tr['host'] == $host)) { $this->basepathIsLocal = true; } else { $this->basepathIsLocal = false; } } function GetFullPath(&$path,$basepath='') { // When parsing CSS need to pass temporary basepath - so links are relative to current stylesheet if (!$basepath) { $basepath = $this->basepath; } //Fix path value $path = str_replace("\\","/",$path); //If on Windows //Get link info and obtain its absolute path $regexp = '|^./|'; // Inadvertently corrects "./path/etc" and "//www.domain.com/etc" $path = preg_replace($regexp,'',$path); if(substr($path,0,1) == '#') { return; } if (stristr($path,"mailto:") !== false) { return; } if (strpos($path,"../") !== false ) { //It is a Relative Link $backtrackamount = substr_count($path,"../"); $maxbacktrack = substr_count($basepath,"/") - 1; $filepath = str_replace("../",'',$path); $path = $basepath; //If it is an invalid relative link, then make it go to directory root if ($backtrackamount > $maxbacktrack) $backtrackamount = $maxbacktrack; //Backtrack some directories for( $i = 0 ; $i < $backtrackamount + 1 ; $i++ ) $path = substr( $path, 0 , strrpos($path,"/") ); $path = $path . "/" . $filepath; //Make it an absolute path } else if( strpos($path,":/") === false || strpos($path,":/") > 10) { //It is a Local Link if (substr($path,0,1) == "/") { $tr = parse_url($basepath); $root = $tr['scheme'].'://'.$tr['host']; $path = $root . $path; } else { $path = $basepath . $path; } } //Do nothing if it is an Absolute Link } // Used for external CSS files function _get_file($path) { // If local file try using local path (? quicker, but also allowed even if allow_url_fopen false) $contents = ''; $contents = @file_get_contents($path); if ($contents) { return $contents; } if ($this->basepathIsLocal) { $tr = parse_url($path); $lp=getenv("SCRIPT_NAME"); $ap=realpath($lp); $ap=str_replace("\\","/",$ap); $docroot=substr($ap,0,strpos($ap,$lp)); // WriteHTML parses all paths to full URLs; may be local file name if ($tr['scheme'] && $tr['host'] && $_SERVER["DOCUMENT_ROOT"] ) { $localpath = $_SERVER["DOCUMENT_ROOT"] . $tr['path']; } // DOCUMENT_ROOT is not returned on IIS else if ($docroot) { $localpath = $docroot . $tr['path']; } else { $localpath = $path; } $contents = @file_get_contents($localpath); } // if not use full URL else if (!$contents && !ini_get('allow_url_fopen') && function_exists("curl_init")) { $ch = curl_init($path); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 ); $contents = curl_exec($ch); curl_close($ch); } return $contents; } function docPageNum($num = 0, $extras = false) { if ($num < 1) { $num = $this->page; } $type = '1'; // set default decimal $ppgno = $num; $suppress = 0; $offset = 0; $lastreset = 0; foreach($this->PageNumSubstitutions AS $psarr) { if ($num >= $psarr['from']) { if ($psarr['reset']) { if ($psarr['reset']>1) { $offset = $psarr['reset']-1; } $ppgno = $num - $psarr['from'] + 1 + $offset; $lastreset = $psarr['from']; } if ($psarr['type']) { $type = $psarr['type']; } if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; } else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; } } } if ($suppress) { return ''; } foreach($this->pgsIns AS $k=>$v) { if ($k>$lastreset && $k<$num) { $ppgno -= $v; } } if ($type=='A') { $ppgno = $this->dec2alpha($ppgno,true); } else if ($type=='a') { $ppgno = $this->dec2alpha($ppgno,false);} else if ($type=='I') { $ppgno = $this->dec2roman($ppgno,true); } else if ($type=='i') { $ppgno = $this->dec2roman($ppgno,false); } if ($extras) { $ppgno = $this->pagenumPrefix . $ppgno . $this->pagenumSuffix; } return $ppgno; } function docPageSettings($num = 0) { // Returns current type (numberstyle), suppression state for this page number; // reset is only returned if set for this page number if ($num < 1) { $num = $this->page; } $type = '1'; // set default decimal $ppgno = $num; $suppress = 0; $offset = 0; $reset = ''; foreach($this->PageNumSubstitutions AS $psarr) { if ($num >= $psarr['from']) { if ($psarr['reset']) { if ($psarr['reset']>1) { $offset = $psarr['reset']-1; } $ppgno = $num - $psarr['from'] + 1 + $offset; } if ($psarr['type']) { $type = $psarr['type']; } if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; } else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; } } if ($num == $psarr['from']) { $reset = $psarr['reset']; } } if ($suppress) { $suppress = 'on'; } else { $suppress = 'off'; } return array($type, $suppress, $reset); } function docPageNumTotal($num = 0, $extras = false) { if ($num < 1) { $num = $this->page; } $type = '1'; // set default decimal $ppgstart = 1; $ppgend = count($this->pages)+1; $suppress = 0; $offset = 0; foreach($this->PageNumSubstitutions AS $psarr) { if ($num >= $psarr['from']) { if ($psarr['reset']) { if ($psarr['reset']>1) { $offset = $psarr['reset']-1; } $ppgstart = $psarr['from'] + $offset; $ppgend = count($this->pages)+1 + $offset; } if ($psarr['type']) { $type = $psarr['type']; } if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; } else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; } } if ($num < $psarr['from']) { if ($psarr['reset']) { $ppgend = $psarr['from'] + $offset; break; } } } if ($suppress) { return ''; } $ppgno = $ppgend-$ppgstart+$offset; if ($extras) { $ppgno = $this->nbpgPrefix . $ppgno . $this->nbpgSuffix; } return $ppgno; } function RestartDocTemplate() { $this->docTemplateStart = $this->page; } //Page header function Header($content='') { $this->cMarginL = 0; $this->cMarginR = 0; /*-- HTMLHEADERS-FOOTERS --*/ if (($this->mirrorMargins && ($this->page%2==0) && $this->HTMLHeaderE) || ($this->mirrorMargins && ($this->page%2==1) && $this->HTMLHeader) || (!$this->mirrorMargins && $this->HTMLHeader)) { $this->writeHTMLHeaders(); return; } /*-- END HTMLHEADERS-FOOTERS --*/ $this->processingHeader=true; $h = $this->headerDetails; if(count($h)) { if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) { $this->_out(sprintf('q 0 -1 1 0 0 %.3F cm ',($this->h*_MPDFK))); $yadj = $this->w - $this->h; $headerpgwidth = $this->h - $this->orig_lMargin - $this->orig_rMargin; if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN $headerlmargin = $this->orig_rMargin; } else { $headerlmargin = $this->orig_lMargin; } } else { $yadj = 0; $headerpgwidth = $this->pgwidth; $headerlmargin = $this->lMargin; } $this->y = $this->margin_header - $yadj ; $this->SetTColor($this->ConvertColor(0)); $this->SUP = false; $this->SUB = false; $this->bullet = false; // only show pagenumber if numbering on $pgno = $this->docPageNum($this->page, true); if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN $side = 'even'; } else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS = DEFAULT $side = 'odd'; } $maxfontheight = 0; foreach(array('L','C','R') AS $pos) { if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) { if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; } else { $hfsz = $this->default_font_size; } $maxfontheight = max($maxfontheight,$hfsz); } } // LEFT-CENTER-RIGHT foreach(array('L','C','R') AS $pos) { if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) { $hd = str_replace('{PAGENO}',$pgno,$h[$side][$pos]['content']); $hd = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->aliasNbPgGp.$this->nbpgSuffix,$hd); $hd = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$hd); if (isset($h[$side][$pos]['font-family']) && $h[$side][$pos]['font-family']) { $hff = $h[$side][$pos]['font-family']; } else { $hff = $this->original_default_font; } if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; } else { $hfsz = $this->original_default_font_size; } // pts $maxfontheight = max($maxfontheight,$hfsz); $hfst = ''; if (isset($h[$side][$pos]['font-style']) && $h[$side][$pos]['font-style']) { $hfst = $h[$side][$pos]['font-style']; } if (isset($h[$side][$pos]['color']) && $h[$side][$pos]['color']) { $hfcol = $h[$side][$pos]['color']; $cor = $this->ConvertColor($hfcol); if ($cor) { $this->SetTColor($cor); } } else { $hfcol = ''; } $this->SetFont($hff,$hfst,$hfsz,true,true); $this->x = $headerlmargin ; $this->y = $this->margin_header - $yadj ; $hd = $this->purify_utf8_text($hd); if ($this->text_input_as_HTML) { $hd = $this->all_entities_to_utf8($hd); } // CONVERT CODEPAGE if ($this->usingCoreFont) { $hd = mb_convert_encoding($hd,$this->mb_enc,'UTF-8'); } // DIRECTIONALITY RTL $this->magic_reverse_dir($hd, true, $this->directionality); // *RTL* // Font-specific ligature substitution for Indic fonts if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($hd); // *INDIC* $align = $pos; /*-- RTL --*/ if ($this->directionality == 'rtl') { if ($pos == 'L') { $align = 'R'; } else if ($pos == 'R') { $align = 'L'; } } /*-- END RTL --*/ if ($pos!='L' && (strpos($hd,$this->aliasNbPg)!==false || strpos($hd,$this->aliasNbPgGp)!==false)) { if (strpos($hd,$this->aliasNbPgGp)!==false) { $type= 'nbpggp'; } else { $type= 'nbpg'; } $this->_out('{mpdfheader'.$type.' '.$pos.' ff='.$hff.' fs='.$hfst.' fz='.$hfsz.'}'); $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M'); $this->_out('Q'); } else { $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M'); } if ($hfcol) { $this->SetTColor($this->ConvertColor(0)); } } } //Return Font to normal $this->SetFont($this->default_font,'',$this->original_default_font_size); // LINE if (isset($h[$side]['line']) && $h[$side]['line']) { $this->SetLineWidth(0.1); $this->SetDColor($this->ConvertColor(0)); $this->Line($headerlmargin , $this->margin_header + ($maxfontheight*(1+$this->header_line_spacing)/_MPDFK) - $yadj , $headerlmargin + $headerpgwidth, $this->margin_header + ($maxfontheight*(1+$this->header_line_spacing)/_MPDFK) - $yadj ); } if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) { $this->_out('Q'); } } $this->SetY($this->tMargin); if ($this->ColActive) { $this->pgwidth = $this->ColWidth; } // *COLUMNS* $this->processingHeader=false; } /*-- TABLES --*/ function TableHeaderFooter($content='',$tablestartpage='',$tablestartcolumn ='',$horf = 'H',$level, $firstSpread=true, $finalSpread=true) { // mPDF 5.3.36 if(($horf=='H' || $horf=='F') && !empty($content)) { // mPDF 5.3.62 $table = &$this->table[1][1]; // Advance down page by half width of top border if ($horf=='H') { // Only if header if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2 + $table['border_details']['T']['w'] + $table['padding']['T']; } else { $adv = $table['max_cell_border_width']['T'] /2 ; } if ($adv) { if ($this->table_rotate) { $this->y += ($adv); } else { $this->DivLn($adv,$this->blklvl,true); } } } if ($horf=='F') { // Table Footer $firstrow = count($table['cells']) - $table['footernrows']; // mPDF 5.3.62 $lastrow = count($table['cells']) - 1; } else { // Table Header $firstrow = 0; $lastrow = $table['headernrows'] - 1; // mPDF 5.3.62 } $topy = $content[$firstrow][0]['y']-$this->y; for ($i=$firstrow ; $i<=$lastrow; $i++) { $y = $this->y; /*-- COLUMNS --*/ // If outside columns, this is done in PaintDivBB if ($this->ColActive) { //OUTER FILL BGCOLOR of DIVS if ($this->blklvl > 0) { $firstblockfill = $this->GetFirstBlockFill(); if ($firstblockfill && $this->blklvl >= $firstblockfill) { $divh = $content[$i][0]['h']; $bak_x = $this->x; $this->DivLn($divh,-3,false); // Reset current block fill $bcor = $this->blk[$this->blklvl]['bgcolorarray']; $this->SetFColor($bcor); $this->x = $bak_x; } } } /*-- END COLUMNS --*/ $colctr = 0; foreach($content[$i] as $tablehf) { $colctr++; $y = $tablehf['y'] - $topy; $this->y = $y; //Set some cell values $x = $tablehf['x']; if (($this->mirrorMargins) && ($tablestartpage == 'ODD') && (($this->page)%2==0)) { // EVEN $x = $x +$this->MarginCorrection; } else if (($this->mirrorMargins) && ($tablestartpage == 'EVEN') && (($this->page)%2==1)) { // ODD $x = $x +$this->MarginCorrection; } /*-- COLUMNS --*/ // Added to correct for Columns if ($this->ColActive) { if ($this->directionality == 'rtl') { // *RTL* $x -= ($this->CurrCol - $tablestartcolumn) * ($this->ColWidth+$this->ColGap); // *RTL* } // *RTL* else { // *RTL* $x += ($this->CurrCol - $tablestartcolumn) * ($this->ColWidth+$this->ColGap); } // *RTL* } /*-- END COLUMNS --*/ if ($colctr==1) { $x0 = $x; } // mPDF ITERATION if ($this->iterationCounter) { foreach($tablehf['textbuffer'] AS $k=>$t) { // mPDF 5.3.78 if (preg_match('/{iteration ([a-zA-Z0-9_]+)}/',$t, $m)) { $vname = '__'.$m[1].'_'; if (!isset($this->$vname)) { $this->$vname = 1; } else { $this->$vname++; } $tablehf['textbuffer'][$k][0] = preg_replace('/{iteration '.$m[1].'}/', $this->$vname, $tablehf['textbuffer'][$k][0]); } } } $w = $tablehf['w']; $h = $tablehf['h']; $va = $tablehf['va']; $R = $tablehf['R']; $mih = $tablehf['mih']; $border = $tablehf['border']; $border_details = $tablehf['border_details']; $padding = $tablehf['padding']; $this->tabletheadjustfinished = true; $textbuffer = $tablehf['textbuffer']; $align = $tablehf['a']; //Align $this->divalign=$align; $this->x = $x; if ($this->ColActive) { if ($table['borders_separate']) { $tablefill = isset($table['bgcolor'][-1]) ? $table['bgcolor'][-1] : 0; if ($tablefill) { $color = $this->ConvertColor($tablefill); if ($color) { $xadj = ($table['border_spacing_H']/2); $yadj = ($table['border_spacing_V']/2); $wadj = $table['border_spacing_H']; $hadj = $table['border_spacing_V']; if ($i == $firstrow && $horf=='H') { // Top $yadj += $table['padding']['T'] + $table['border_details']['T']['w'] ; $hadj += $table['padding']['T'] + $table['border_details']['T']['w'] ; } if (($i == ($lastrow) || (isset($tablehf['rowspan']) && ($i+$tablehf['rowspan']) == ($lastrow+1)) || (!isset($tablehf['rowspan']) && ($i+1) == ($lastrow+1))) && $horf=='F') { // Bottom $hadj += $table['padding']['B'] + $table['border_details']['B']['w'] ; } if ($colctr == 1) { // Left $xadj += $table['padding']['L'] + $table['border_details']['L']['w'] ; $wadj += $table['padding']['L'] + $table['border_details']['L']['w'] ; } if ($colctr == count($content[$i]) ) { // Right $wadj += $table['padding']['R'] + $table['border_details']['R']['w'] ; } $this->SetFColor($color); $this->Rect($x - $xadj, $y - $yadj, $w + $wadj, $h + $hadj, 'F'); } } } } if ($table['empty_cells']!='hide' || !empty($textbuffer) || !$table['borders_separate']) { $paintcell = true; } else { $paintcell = false; } //Vertical align if ($R && INTVAL($R) > 0 && isset($va) && $va!='B') { $va='B';} if (!isset($va) || empty($va) || $va=='M') $this->y += ($h-$mih)/2; elseif (isset($va) && $va=='B') $this->y += $h-$mih; //TABLE ROW OR CELL FILL BGCOLOR $fill = 0; if (isset($tablehf['bgcolor']) && $tablehf['bgcolor'] && $tablehf['bgcolor']!='transparent') { $fill = $tablehf['bgcolor']; $leveladj = 6; } else if (isset($content[$i][0]['trbgcolor']) && $content[$i][0]['trbgcolor'] && $content[$i][0]['trbgcolor']!='transparent') { // Row color $fill = $content[$i][0]['trbgcolor']; $leveladj = 3; } if ($fill && $paintcell) { $color = $this->ConvertColor($fill); if ($color) { if ($table['borders_separate']) { if ($this->ColActive) { $this->SetFColor($color); $this->Rect($x+ ($table['border_spacing_H']/2), $y+ ($table['border_spacing_V']/2), $w- $table['border_spacing_H'], $h- $table['border_spacing_V'], 'F'); } else { $this->tableBackgrounds[$level*9+$leveladj][] = array('gradient'=>false, 'x'=>($x + ($table['border_spacing_H']/2)), 'y'=>($y + ($table['border_spacing_V']/2)), 'w'=>($w - $table['border_spacing_H']), 'h'=>($h - $table['border_spacing_V']), 'col'=>$color); } } else { if ($this->ColActive) { $this->SetFColor($color); $this->Rect($x, $y, $w, $h, 'F'); } else { $this->tableBackgrounds[$level*9+$leveladj][] = array('gradient'=>false, 'x'=>$x, 'y'=>$y, 'w'=>$w, 'h'=>$h, 'col'=>$color); } } } } /*-- BACKGROUNDS --*/ if (isset($tablehf['gradient']) && $tablehf['gradient'] && $paintcell){ $g = $this->grad->parseBackgroundGradient($tablehf['gradient']); if ($g) { if ($table['borders_separate']) { $px = $x+ ($table['border_spacing_H']/2); $py = $y+ ($table['border_spacing_V']/2); $pw = $w- $table['border_spacing_H']; $ph = $h- $table['border_spacing_V']; } else { $px = $x; $py = $y; $pw = $w; $ph = $h; } if ($this->ColActive) { $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']); } else { $this->tableBackgrounds[$level*9+7][] = array('gradient'=>true, 'x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>''); } } } if (isset($tablehf['background-image']) && $paintcell){ if ($tablehf['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $tablehf['background-image']['gradient'] )) { $g = $this->grad->parseMozGradient( $tablehf['background-image']['gradient'] ); if ($g) { if ($table['borders_separate']) { $px = $x+ ($table['border_spacing_H']/2); $py = $y+ ($table['border_spacing_V']/2); $pw = $w- $table['border_spacing_H']; $ph = $h- $table['border_spacing_V']; } else { $px = $x; $py = $y; $pw = $w; $ph = $h; } if ($this->ColActive) { $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']); } else { $this->tableBackgrounds[$level*9+7][] = array('gradient'=>true, 'x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>''); } } } else if ($tablehf['background-image']['image_id']) { // Background pattern $n = count($this->patterns)+1; if ($table['borders_separate']) { $px = $x+ ($table['border_spacing_H']/2); $py = $y+ ($table['border_spacing_V']/2); $pw = $w- $table['border_spacing_H']; $ph = $h- $table['border_spacing_V']; } else { $px = $x; $py = $y; $pw = $w; $ph = $h; } if ($this->ColActive) { list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($tablehf['background-image']['orig_w'], $tablehf['background-image']['orig_h'], $pw, $ph, $tablehf['background-image']['resize'], $tablehf['background-image']['x_repeat'] , $tablehf['background-image']['y_repeat']); $this->patterns[$n] = array('x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'pgh'=>$this->h, 'image_id'=>$tablehf['background-image']['image_id'], 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$tablehf['background-image']['x_pos'] , 'y_pos'=>$tablehf['background-image']['y_pos'] , 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'itype'=>$tablehf['background-image']['itype']); if ($tablehf['background-image']['opacity']>0 && $tablehf['background-image']['opacity']<1) { $opac = $this->SetAlpha($tablehf['background-image']['opacity'],'Normal',true); } else { $opac = ''; } $this->_out(sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, $px*_MPDFK, ($this->h-$py)*_MPDFK, $pw*_MPDFK, -$ph*_MPDFK)); } else { // mPDF 5.3.99 $this->tableBackgrounds[$level*9+8][] = array('x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'image_id'=>$tablehf['background-image']['image_id'], 'orig_w'=>$tablehf['background-image']['orig_w'], 'orig_h'=>$tablehf['background-image']['orig_h'], 'x_pos'=>$tablehf['background-image']['x_pos'], 'y_pos'=>$tablehf['background-image']['y_pos'], 'x_repeat'=>$tablehf['background-image']['x_repeat'], 'y_repeat'=>$tablehf['background-image']['y_repeat'], 'clippath'=>'', 'resize'=>$tablehf['background-image']['resize'], 'opacity'=>$tablehf['background-image']['opacity'], 'itype'=>$tablehf['background-image']['itype']); } } } /*-- END BACKGROUNDS --*/ //Cell Border if ($table['borders_separate'] && $paintcell && $border) { $this->_tableRect($x+ ($table['border_spacing_H']/2)+($border_details['L']['w'] /2), $y+ ($table['border_spacing_V']/2)+($border_details['T']['w'] /2), $w-$table['border_spacing_H']-($border_details['L']['w'] /2)-($border_details['R']['w'] /2), $h- $table['border_spacing_V']-($border_details['T']['w'] /2)-($border_details['B']['w']/2), $border, $border_details, false, $table['borders_separate']); } else if ($paintcell && $border) { $this->_tableRect($x, $y, $w, $h, $border, $border_details, true, $table['borders_separate']); // true causes buffer } //Print cell content //$this->divheight = $this->table_lineheight*$this->lineheight; if (!empty($textbuffer)) { if ($horf=='F' && preg_match('/{colsum([0-9]*)[_]*}/', $textbuffer[0][0], $m)) { // mPDF 5.3.92 $rep = sprintf("%01.".intval($m[1])."f", $this->colsums[$colctr-1]); $textbuffer[0][0] = preg_replace('/{colsum[0-9_]*}/', $rep ,$textbuffer[0][0]); } if ($R) { $cellPtSize = $textbuffer[0][11] / $this->shrin_k; if (!$cellPtSize) { $cellPtSize = $this->default_font_size; } $cellFontHeight = ($cellPtSize/_MPDFK); $opx = $this->x; $opy = $this->y; $angle = INTVAL($R); // Only allow 45 - 90 degrees (when bottom-aligned) or -90 if ($angle > 90) { $angle = 90; } else if ($angle > 0 && (isset($va) && $va!='B')) { $angle = 90; } else if ($angle > 0 && $angle <45) { $angle = 45; } else if ($angle < 0) { $angle = -90; } $offset = ((sin(deg2rad($angle))) * 0.37 * $cellFontHeight); if (isset($align) && $align =='R') { $this->x += ($w) + ($offset) - ($cellFontHeight/3) - ($padding['R'] + $border_details['R']['w']); } else if (!isset($align ) || $align =='C') { $this->x += ($w/2) + ($offset); } else { $this->x += ($offset) + ($cellFontHeight/3)+($padding['L'] + $border_details['L']['w']); } // mPDF 5.3.78 $str = ''; foreach($tablehf['textbuffer'] AS $t) { $str .= $t[0].' '; } $str = trim($str); if (!isset($va) || $va=='M') { $this->y -= ($h-$mih)/2; //Undo what was added earlier VERTICAL ALIGN if ($angle > 0) { $this->y += (($h-$mih)/2)+($padding['T'] + $border_details['T']['w']) + ($mih-($padding['T'] + $border_details['T']['w']+$border_details['B']['w']+$padding['B'])); } else if ($angle < 0) { $this->y += (($h-$mih)/2)+($padding['T'] + $border_details['T']['w']); } } else if (isset($va) && $va=='B') { $this->y -= $h-$mih; //Undo what was added earlier VERTICAL ALIGN if ($angle > 0) { $this->y += $h-($border_details['B']['w']+$padding['B']); } else if ($angle < 0) { $this->y += $h-$mih+($padding['T'] + $border_details['T']['w']); } } else if (isset($va) && $va=='T') { if ($angle > 0) { $this->y += $mih-($border_details['B']['w']+$padding['B']); } else if ($angle < 0) { $this->y += ($padding['T'] + $border_details['T']['w']); } } $this->Rotate($angle,$this->x,$this->y); $s_fs = $this->FontSizePt; $s_f = $this->FontFamily; $s_st = $this->FontStyle; // mPDF 5.3.54 if (!empty($textbuffer[0][3])) { //Font Color $cor = $textbuffer[0][3]; $this->SetTColor($cor); } $s_str = $this->strike; $this->strike = $textbuffer[0][8]; //Strikethrough $this->SetFont($textbuffer[0][4],$textbuffer[0][2],$cellPtSize,true,true); $this->Text($this->x,$this->y,$str); $this->Rotate(0); $this->SetFont($s_f,$s_st,$s_fs,true,true); $this->SetTColor(0); // mPDF 5.3.54 $this->strike = $s_str; // mPDF 5.3.54 $this->x = $opx; $this->y = $opy; } else { if ($table['borders_separate']) { // NB twice border width $xadj = $border_details['L']['w'] + $padding['L'] +($table['border_spacing_H']/2); $wadj = $border_details['L']['w'] + $border_details['R']['w'] + $padding['L'] +$padding['R'] + $table['border_spacing_H']; $yadj = $border_details['T']['w'] + $padding['T'] + ($table['border_spacing_H']/2); } else { $xadj = $border_details['L']['w']/2 + $padding['L']; $wadj = ($border_details['L']['w'] + $border_details['R']['w'])/2 + $padding['L'] + $padding['R']; $yadj = $border_details['T']['w']/2 + $padding['T']; } $this->divwidth=$w-($wadj); $this->x += $xadj; $this->y += $yadj; $this->printbuffer($textbuffer,'',true); } } $textbuffer = array(); /*-- BACKGROUNDS --*/ if (!$this->ColActive) { if (isset($content[$i][0]['trgradients']) && ($colctr==1 || $table['borders_separate'])) { $g = $this->grad->parseBackgroundGradient($content[$i][0]['trgradients']); if ($g) { $gx = $x0; $gy = $y; $gh = $h; $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R']; if ($table['borders_separate']) { $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']); $s = ''; $clx = $x+ ($table['border_spacing_H']/2); $cly = $y+ ($table['border_spacing_V']/2); $clw = $w- $table['border_spacing_H']; $clh = $h- $table['border_spacing_V']; // Set clipping path $s = ' q 0 w '; // Line width=0 $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL $s .= ' W n '; // Ends path no-op & Sets the clipping path $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx + ($table['border_spacing_H']/2), 'y'=>$gy + ($table['border_spacing_V']/2), 'w'=>$gw - $table['border_spacing_V'], 'h'=>$gh - $table['border_spacing_H'], 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s); } else { $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$gw, 'h'=>$gh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>''); } } } if (isset($content[$i][0]['trbackground-images']) && ($colctr==1 || $table['borders_separate'])) { if ($content[$i][0]['trbackground-images']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $content[$i][0]['trbackground-images']['gradient'] )) { $g = $this->grad->parseMozGradient( $content[$i][0]['trbackground-images']['gradient'] ); if ($g) { $gx = $x0; $gy = $y; $gh = $h; $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R']; if ($table['borders_separate']) { $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']); $s = ''; $clx = $x+ ($table['border_spacing_H']/2); $cly = $y+ ($table['border_spacing_V']/2); $clw = $w- $table['border_spacing_H']; $clh = $h- $table['border_spacing_V']; // Set clipping path $s = ' q 0 w '; // Line width=0 $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL $s .= ' W n '; // Ends path no-op & Sets the clipping path $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx + ($table['border_spacing_H']/2), 'y'=>$gy + ($table['border_spacing_V']/2), 'w'=>$gw - $table['border_spacing_V'], 'h'=>$gh - $table['border_spacing_H'], 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s); } else { $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$gw, 'h'=>$gh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>''); } } } else { $image_id = $content[$i][0]['trbackground-images']['image_id']; $orig_w = $content[$i][0]['trbackground-images']['orig_w']; $orig_h = $content[$i][0]['trbackground-images']['orig_h']; $x_pos = $content[$i][0]['trbackground-images']['x_pos']; $y_pos = $content[$i][0]['trbackground-images']['y_pos']; $x_repeat = $content[$i][0]['trbackground-images']['x_repeat']; $y_repeat = $content[$i][0]['trbackground-images']['y_repeat']; $resize = $content[$i][0]['trbackground-images']['resize']; $opacity = $content[$i][0]['trbackground-images']['opacity']; $itype = $content[$i][0]['trbackground-images']['itype']; // mPDF 5.3.99 $clippath = ''; $gx = $x0; $gy = $y; $gh = $h; $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R']; if ($table['borders_separate']) { $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']); $s = ''; $clx = $x+ ($table['border_spacing_H']/2); $cly = $y+ ($table['border_spacing_V']/2); $clw = $w- $table['border_spacing_H']; $clh = $h- $table['border_spacing_V']; // Set clipping path $s = ' q 0 w '; // Line width=0 $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL $s .= ' W n '; // Ends path no-op & Sets the clipping path $this->tableBackgrounds[$level*9+5][] = array('x'=>$gx + ($table['border_spacing_H']/2), 'y'=>$gy + ($table['border_spacing_V']/2), 'w'=>$gw - $table['border_spacing_V'], 'h'=>$gh - $table['border_spacing_H'], 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>$s, 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype); } else { $this->tableBackgrounds[$level*9+5][] = array('x'=>$gx, 'y'=>$gy, 'w'=>$gw, 'h'=>$gh, 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>'', 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype); } } } } /*-- END BACKGROUNDS --*/ // TABLE BORDER - if separate OR collapsed and only table border // mPDF 5.3.15 if (($table['borders_separate'] || ($this->simpleTables && !$table['simple']['border'])) && $table['border']) { $halfspaceL = $table['padding']['L'] + ($table['border_spacing_H']/2); $halfspaceR = $table['padding']['R'] + ($table['border_spacing_H']/2); $halfspaceT = $table['padding']['T'] + ($table['border_spacing_V']/2); $halfspaceB = $table['padding']['B'] + ($table['border_spacing_V']/2); $tbx = $x; $tby = $y; $tbw = $w; $tbh = $h; $tab_bord = 0; $corner = ''; if ($i == $firstrow && $horf=='H') { // Top $tby -= $halfspaceT + ($table['border_details']['T']['w']/2); $tbh += $halfspaceT + ($table['border_details']['T']['w']/2); $this->setBorder($tab_bord , _BORDER_TOP); $corner .= 'T'; } // mPDF 5.3.15 if (($i == ($lastrow) || (isset($tablehf['rowspan']) && ($i+$tablehf['rowspan']) == ($lastrow+1))) && $horf=='F') { // Bottom $tbh += $halfspaceB + ($table['border_details']['B']['w']/2); $this->setBorder($tab_bord , _BORDER_BOTTOM); $corner .= 'B'; } if ($colctr == 1 && $firstSpread) { // Left // mPDF 5.3.36 $tbx -= $halfspaceL + ($table['border_details']['L']['w']/2); $tbw += $halfspaceL + ($table['border_details']['L']['w']/2); $this->setBorder($tab_bord , _BORDER_LEFT); $corner .= 'L'; } if ($colctr == count($content[$i]) && $finalSpread) { // Right // mPDF 5.3.36 $tbw += $halfspaceR + ($table['border_details']['R']['w']/2); $this->setBorder($tab_bord , _BORDER_RIGHT); $corner .= 'R'; } $this->_tableRect($tbx, $tby, $tbw, $tbh, $tab_bord , $table['border_details'], false, $table['borders_separate'], 'table', $corner, $table['border_spacing_V'], $table['border_spacing_H'] ); } }// end column $content $this->y = $y + $h; //Update y coordinate }// end row $i unset($table ); $this->colsums = array(); // mPDF 5.3.92 } } /*-- END TABLES --*/ /*-- HTMLHEADERS-FOOTERS --*/ function SetHTMLHeader($header='',$OE='',$write=false) { $height = 0; if (is_array($header) && isset($header['html']) && $header['html']) { $Hhtml = $header['html']; if ($this->setAutoTopMargin) { if (isset($header['h'])) { $height = $header['h']; } else { $height = $this->_gethtmlheight($Hhtml); } } } else if (!is_array($header) && $header) { $Hhtml = $header; if ($this->setAutoTopMargin) { $height = $this->_gethtmlheight($Hhtml); } } else { $Hhtml = ''; } if ($OE != 'E') { $OE = 'O'; } if ($OE == 'E') { if ($Hhtml) { $this->HTMLHeaderE['html'] = $Hhtml; $this->HTMLHeaderE['h'] = $height; } else { $this->HTMLHeaderE = ''; } } else { if ($Hhtml) { $this->HTMLHeader['html'] = $Hhtml; $this->HTMLHeader['h'] = $height; } else { $this->HTMLHeader = ''; } } if (!$this->mirrorMargins && $OE == 'E') { return; } if ($Hhtml=='') { return; } if ($OE == 'E') { $this->headerDetails['even'] = array(); // override and clear any other non-HTML header/footer } else { $this->headerDetails['odd'] = array(); // override and clear any non-HTML other header/footer } if ($this->setAutoTopMargin=='pad') { $this->tMargin = $this->margin_header + $height + $this->orig_tMargin; if (isset($this->saveHTMLHeader[$this->page][$OE]['mt'])) { $this->saveHTMLHeader[$this->page][$OE]['mt'] = $this->tMargin; } } else if ($this->setAutoTopMargin=='stretch') { $this->tMargin = max($this->orig_tMargin, $this->margin_header + $height + $this->autoMarginPadding); if (isset($this->saveHTMLHeader[$this->page][$OE]['mt'])) { $this->saveHTMLHeader[$this->page][$OE]['mt'] = $this->tMargin; } } if ($write && $this->state!=0 && (($this->mirrorMargins && $OE == 'E' && ($this->page)%2==0) || ($this->mirrorMargins && $OE != 'E' && ($this->page)%2==1) || !$this->mirrorMargins)) { $this->writeHTMLHeaders(); } } function SetHTMLFooter($footer='',$OE='') { $height = 0; if (is_array($footer) && isset($footer['html']) && $footer['html']) { $Fhtml = $footer['html']; if ($this->setAutoBottomMargin) { if (isset($footer['h'])) { $height = $footer['h']; } else { $height = $this->_gethtmlheight($Fhtml); } } } else if (!is_array($footer) && $footer) { $Fhtml = $footer; if ($this->setAutoBottomMargin) { $height = $this->_gethtmlheight($Fhtml); } } else { $Fhtml = ''; } if ($OE != 'E') { $OE = 'O'; } if ($OE == 'E') { if ($Fhtml) { $this->HTMLFooterE['html'] = $Fhtml; $this->HTMLFooterE['h'] = $height; } else { $this->HTMLFooterE = ''; } } else { if ($Fhtml) { $this->HTMLFooter['html'] = $Fhtml; $this->HTMLFooter['h'] = $height; } else { $this->HTMLFooter = ''; } } if (!$this->mirrorMargins && $OE == 'E') { return; } if ($Fhtml=='') { return false; } if ($OE == 'E') { $this->footerDetails['even'] = array(); // override and clear any other header/footer } else { $this->footerDetails['odd'] = array(); // override and clear any other header/footer } if ($this->setAutoBottomMargin=='pad') { $this->bMargin = $this->margin_footer + $height + $this->orig_bMargin; $this->PageBreakTrigger=$this->h-$this->bMargin ; if (isset($this->saveHTMLHeader[$this->page][$OE]['mb'])) { $this->saveHTMLHeader[$this->page][$OE]['mb'] = $this->bMargin; } } else if ($this->setAutoBottomMargin=='stretch') { $this->bMargin = max($this->orig_bMargin, $this->margin_footer + $height + $this->autoMarginPadding); $this->PageBreakTrigger=$this->h-$this->bMargin ; if (isset($this->saveHTMLHeader[$this->page][$OE]['mb'])) { $this->saveHTMLHeader[$this->page][$OE]['mb'] = $this->bMargin; } } } function _getHtmlHeight($html) { $save_state = $this->state; if($this->state==0) { $this->AddPage($this->CurOrientation); } $this->state = 2; $this->Reset(); $this->pageoutput[$this->page] = array(); $save_x = $this->x; $save_y = $this->y; $this->x = $this->lMargin; $this->y = $this->margin_header; $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($this->page).$this->pagenumSuffix,$html); $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($this->page).$this->nbpgSuffix,$html ); $html = str_replace($this->aliasNbPg,$this->page,$html ); $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html ); $this->HTMLheaderPageLinks = array(); $this->HTMLheaderPageAnnots = array(); $this->HTMLheaderPageForms = array(); $savepb = $this->pageBackgrounds; $this->writingHTMLheader = true; $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer $this->writingHTMLheader = false; $h = ($this->y - $this->margin_header); $this->Reset(); $this->pageoutput[$this->page] = array(); $this->headerbuffer = ''; $this->pageBackgrounds = $savepb; $this->x = $save_x; $this->y = $save_y; $this->state = $save_state; if($save_state==0) { unset($this->pages[1]); $this->page = 0; } return $h; } // Called internally from Header function writeHTMLHeaders() { if ($this->mirrorMargins && ($this->page)%2==0) { $OE = 'E'; } // EVEN else { $OE = 'O'; } if ($OE == 'E') { $this->saveHTMLHeader[$this->page][$OE]['html'] = $this->HTMLHeaderE['html'] ; } else { $this->saveHTMLHeader[$this->page][$OE]['html'] = $this->HTMLHeader['html'] ; } if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) { $this->saveHTMLHeader[$this->page][$OE]['rotate'] = true; $this->saveHTMLHeader[$this->page][$OE]['ml'] = $this->tMargin; $this->saveHTMLHeader[$this->page][$OE]['mr'] = $this->bMargin; $this->saveHTMLHeader[$this->page][$OE]['mh'] = $this->margin_header; $this->saveHTMLHeader[$this->page][$OE]['mf'] = $this->margin_footer; $this->saveHTMLHeader[$this->page][$OE]['pw'] = $this->h; $this->saveHTMLHeader[$this->page][$OE]['ph'] = $this->w; } else { $this->saveHTMLHeader[$this->page][$OE]['ml'] = $this->lMargin; $this->saveHTMLHeader[$this->page][$OE]['mr'] = $this->rMargin; $this->saveHTMLHeader[$this->page][$OE]['mh'] = $this->margin_header; $this->saveHTMLHeader[$this->page][$OE]['mf'] = $this->margin_footer; $this->saveHTMLHeader[$this->page][$OE]['pw'] = $this->w; $this->saveHTMLHeader[$this->page][$OE]['ph'] = $this->h; } } function writeHTMLFooters() { if ($this->mirrorMargins && ($this->page)%2==0) { $OE = 'E'; } // EVEN else { $OE = 'O'; } if ($OE == 'E') { $this->saveHTMLFooter[$this->page][$OE]['html'] = $this->HTMLFooterE['html'] ; } else { $this->saveHTMLFooter[$this->page][$OE]['html'] = $this->HTMLFooter['html'] ; } if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) { $this->saveHTMLFooter[$this->page][$OE]['rotate'] = true; $this->saveHTMLFooter[$this->page][$OE]['ml'] = $this->tMargin; $this->saveHTMLFooter[$this->page][$OE]['mr'] = $this->bMargin; $this->saveHTMLFooter[$this->page][$OE]['mt'] = $this->rMargin; $this->saveHTMLFooter[$this->page][$OE]['mb'] = $this->lMargin; $this->saveHTMLFooter[$this->page][$OE]['mh'] = $this->margin_header; $this->saveHTMLFooter[$this->page][$OE]['mf'] = $this->margin_footer; $this->saveHTMLFooter[$this->page][$OE]['pw'] = $this->h; $this->saveHTMLFooter[$this->page][$OE]['ph'] = $this->w; } else { $this->saveHTMLFooter[$this->page][$OE]['ml'] = $this->lMargin; $this->saveHTMLFooter[$this->page][$OE]['mr'] = $this->rMargin; $this->saveHTMLFooter[$this->page][$OE]['mt'] = $this->tMargin; $this->saveHTMLFooter[$this->page][$OE]['mb'] = $this->bMargin; $this->saveHTMLFooter[$this->page][$OE]['mh'] = $this->margin_header; $this->saveHTMLFooter[$this->page][$OE]['mf'] = $this->margin_footer; $this->saveHTMLFooter[$this->page][$OE]['pw'] = $this->w; $this->saveHTMLFooter[$this->page][$OE]['ph'] = $this->h; } } /*-- END HTMLHEADERS-FOOTERS --*/ function DefHeaderByName($name,$arr) { if (!$name) { $name = '_default'; } $this->pageheaders[$name] = $arr; } function DefFooterByName($name,$arr) { if (!$name) { $name = '_default'; } $this->pagefooters[$name] = $arr; } function SetHeaderByName($name,$side='O',$write=false) { if (!$name) { $name = '_default'; } if ($side=='E') { $this->headerDetails['even'] = $this->pageheaders[$name]; } else { $this->headerDetails['odd'] = $this->pageheaders[$name]; } if ($write) { $this->Header(); } } function SetFooterByName($name,$side='O') { if (!$name) { $name = '_default'; } if ($side=='E') { $this->footerDetails['even'] = $this->pagefooters[$name]; } else { $this->footerDetails['odd'] = $this->pagefooters[$name]; } } /*-- HTMLHEADERS-FOOTERS --*/ function DefHTMLHeaderByName($name,$html) { if (!$name) { $name = '_default'; } $this->pageHTMLheaders[$name]['html'] = $html; $this->pageHTMLheaders[$name]['h'] = $this->_gethtmlheight($html); } function DefHTMLFooterByName($name,$html) { if (!$name) { $name = '_default'; } $this->pageHTMLfooters[$name]['html'] = $html; $this->pageHTMLfooters[$name]['h'] = $this->_gethtmlheight($html); } function SetHTMLHeaderByName($name,$side='O',$write=false) { if (!$name) { $name = '_default'; } $this->SetHTMLHeader($this->pageHTMLheaders[$name],$side,$write); } function SetHTMLFooterByName($name,$side='O') { if (!$name) { $name = '_default'; } $this->SetHTMLFooter($this->pageHTMLfooters[$name],$side,$write); } /*-- END HTMLHEADERS-FOOTERS --*/ function SetHeader($Harray=array(),$side='',$write=false) { if (is_string($Harray)) { if (strlen($Harray)==0) { if ($side=='O') { $this->headerDetails['odd'] = array(); } else if ($side=='E') { $this->headerDetails['even'] = array(); } else { $this->headerDetails = array(); } } else if (strpos($Harray,'|') || strpos($Harray,'|')===0) { $hdet = explode('|',$Harray); $this->headerDetails = array ( 'odd' => array ( 'L' => array ('content' => $hdet[0], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle), 'C' => array ('content' => $hdet[1], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle), 'R' => array ('content' => $hdet[2], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle), 'line' => $this->defaultheaderline, ), 'even' => array ( 'R' => array ('content' => $hdet[0], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle), 'C' => array ('content' => $hdet[1], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle), 'L' => array ('content' => $hdet[2], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle), 'line' => $this->defaultheaderline, ) ); } else { $this->headerDetails = array ( 'odd' => array ( 'R' => array ('content' => $Harray, 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle), 'line' => $this->defaultheaderline, ), 'even' => array ( 'L' => array ('content' => $Harray, 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle), 'line' => $this->defaultheaderline, ) ); } } else if (is_array($Harray)) { if ($side=='O') { $this->headerDetails['odd'] = $Harray; } else if ($side=='E') { $this->headerDetails['even'] = $Harray; } else { $this->headerDetails = $Harray; } } /*-- HTMLHEADERS-FOOTERS --*/ // Overwrite any HTML Header previously set if ($side=='E') { $this->SetHTMLHeader('','E'); } else if ($side=='O') { $this->SetHTMLHeader(''); } else { $this->SetHTMLHeader(''); $this->SetHTMLHeader('','E'); } /*-- END HTMLHEADERS-FOOTERS --*/ if ($write) { $save_y = $this->y; $this->Header(); $this->SetY($save_y) ; } } function SetFooter($Farray=array(),$side='') { if (is_string($Farray)) { if (strlen($Farray)==0) { if ($side=='O') { $this->footerDetails['odd'] = array(); } else if ($side=='E') { $this->footerDetails['even'] = array(); } else { $this->footerDetails = array(); } } else if (strpos($Farray,'|') || strpos($Farray,'|')===0) { $fdet = explode('|',$Farray); $this->footerDetails = array ( 'odd' => array ( 'L' => array ('content' => $fdet[0], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle), 'C' => array ('content' => $fdet[1], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle), 'R' => array ('content' => $fdet[2], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle), 'line' => $this->defaultfooterline, ), 'even' => array ( 'R' => array ('content' => $fdet[0], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle), 'C' => array ('content' => $fdet[1], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle), 'L' => array ('content' => $fdet[2], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle), 'line' => $this->defaultfooterline, ) ); } else { $this->footerDetails = array ( 'odd' => array ( 'R' => array ('content' => $Farray, 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle), 'line' => $this->defaultfooterline, ), 'even' => array ( 'L' => array ('content' => $Farray, 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle), 'line' => $this->defaultfooterline, ) ); } } else if (is_array($Farray)) { if ($side=='O') { $this->footerDetails['odd'] = $Farray; } else if ($side=='E') { $this->footerDetails['even'] = $Farray; } else { $this->footerDetails = $Farray; } } /*-- HTMLHEADERS-FOOTERS --*/ // Overwrite any HTML Footer previously set if ($side=='E') { $this->SetHTMLFooter('','E'); } else if ($side=='O') { $this->SetHTMLFooter(''); } else { $this->SetHTMLFooter(''); $this->SetHTMLFooter('','E'); } /*-- END HTMLHEADERS-FOOTERS --*/ } /*-- WATERMARK --*/ function setUnvalidatedText($txt='', $alpha=-1) { if ($alpha>=0) $this->watermarkTextAlpha = $alpha; $this->watermarkText = $txt; } function SetWatermarkText($txt='', $alpha=-1) { if ($alpha>=0) $this->watermarkTextAlpha = $alpha; $this->watermarkText = $txt; } function SetWatermarkImage($src, $alpha=-1, $size='D', $pos='F') { if ($alpha>=0) $this->watermarkImageAlpha = $alpha; $this->watermarkImage = $src; $this->watermark_size = $size; $this->watermark_pos = $pos; } /*-- END WATERMARK --*/ //Page footer function Footer() { /*-- CSS-PAGE --*/ // PAGED MEDIA - CROP / CROSS MARKS from @PAGE if ($this->show_marks == 'CROP' || $this->show_marks == 'CROPCROSS') { // Show TICK MARKS $this->SetLineWidth(0.1); // = 0.1 mm $this->SetDColor($this->ConvertColor(0)); $l = $this->cropMarkLength; $m = $this->cropMarkMargin; // Distance of crop mark from margin $b = $this->nonPrintMargin; // Non-printable border at edge of paper sheet $ax1 = $b; $bx = $this->page_box['outer_width_LR'] - $m; $ax = max($ax1, $bx-$l); $cx1 = $this->w - $b; $dx = $this->w - $this->page_box['outer_width_LR'] + $m; $cx = min($cx1, $dx+$l); $ay1 = $b; $by = $this->page_box['outer_width_TB'] - $m; $ay = max($ay1, $by-$l); $cy1 = $this->h - $b; $dy = $this->h - $this->page_box['outer_width_TB'] + $m; $cy = min($cy1, $dy+$l); $this->Line($ax, $this->page_box['outer_width_TB'], $bx, $this->page_box['outer_width_TB']); $this->Line($cx, $this->page_box['outer_width_TB'], $dx, $this->page_box['outer_width_TB']); $this->Line($ax, $this->h - $this->page_box['outer_width_TB'], $bx, $this->h - $this->page_box['outer_width_TB']); $this->Line($cx, $this->h - $this->page_box['outer_width_TB'], $dx, $this->h - $this->page_box['outer_width_TB']); $this->Line($this->page_box['outer_width_LR'], $ay, $this->page_box['outer_width_LR'], $by); $this->Line($this->page_box['outer_width_LR'], $cy, $this->page_box['outer_width_LR'], $dy); $this->Line($this->w - $this->page_box['outer_width_LR'], $ay, $this->w - $this->page_box['outer_width_LR'], $by); $this->Line($this->w - $this->page_box['outer_width_LR'], $cy, $this->w - $this->page_box['outer_width_LR'], $dy); if ($this->printers_info) { $hd = date('Y-m-d H:i').' Page '.$this->page.' of {nb}'; $this->SetTColor($this->ConvertColor(0)); $this->SetFont('arial','',7.5,true,true); $this->x = $this->page_box['outer_width_LR'] + 1.5; $this->y = 1; $this->Cell($headerpgwidth ,$this->FontSize,$hd,0,0,'L',0,'',0,0,0,'M'); $this->SetFont($this->default_font,'',$this->original_default_font_size); } } if ($this->show_marks == 'CROSS' || $this->show_marks == 'CROPCROSS') { $this->SetLineWidth(0.1); // = 0.1 mm $this->SetDColor($this->ConvertColor(0)); $l = 14 /2; // longer length of the cross line (half) $w = 6 /2; // shorter width of the cross line (half) $r = 1.2; // radius of circle $m = $this->crossMarkMargin; // Distance of cross mark from margin $x1 = $this->page_box['outer_width_LR'] - $m; $x2 = $this->w - $this->page_box['outer_width_LR'] + $m; $y1 = $this->page_box['outer_width_TB'] - $m; $y2 = $this->h - $this->page_box['outer_width_TB'] + $m; // Left $this->Circle($x1, $this->h/2, $r, 'S') ; $this->Line($x1-$w, $this->h/2, $x1+$w, $this->h/2); $this->Line($x1, $this->h/2-$l, $x1, $this->h/2+$l); // Right $this->Circle($x2, $this->h/2, $r, 'S') ; $this->Line($x2-$w, $this->h/2, $x2+$w, $this->h/2); $this->Line($x2, $this->h/2-$l, $x2, $this->h/2+$l); // Top $this->Circle($this->w/2, $y1, $r, 'S') ; $this->Line($this->w/2, $y1-$w, $this->w/2, $y1+$w); $this->Line($this->w/2-$l, $y1, $this->w/2+$l, $y1); // Bottom $this->Circle($this->w/2, $y2, $r, 'S') ; $this->Line($this->w/2, $y2-$w, $this->w/2, $y2+$w); $this->Line($this->w/2-$l, $y2, $this->w/2+$l, $y2); } // If @page set non-HTML headers/footers named, they were not read until later in the HTML code - so now set them if ($this->page==1) { if ($this->firstPageBoxHeader) { $this->headerDetails['odd'] = $this->pageheaders[$this->firstPageBoxHeader]; $this->Header(); } if ($this->firstPageBoxFooter) { $this->footerDetails['odd'] = $this->pagefooters[$this->firstPageBoxFooter]; } $this->firstPageBoxHeader=''; $this->firstPageBoxFooter=''; } /*-- END CSS-PAGE --*/ /*-- HTMLHEADERS-FOOTERS --*/ if (($this->mirrorMargins && ($this->page%2==0) && $this->HTMLFooterE) || ($this->mirrorMargins && ($this->page%2==1) && $this->HTMLFooter) || (!$this->mirrorMargins && $this->HTMLFooter)) { $this->writeHTMLFooters(); /*-- WATERMARK --*/ if (($this->watermarkText) && ($this->showWatermarkText)) { $this->watermark( $this->watermarkText, 45, 120, $this->watermarkTextAlpha); // Watermark text } if (($this->watermarkImage) && ($this->showWatermarkImage)) { $this->watermarkImg( $this->watermarkImage, $this->watermarkImageAlpha); // Watermark image } /*-- END WATERMARK --*/ return; } /*-- END HTMLHEADERS-FOOTERS --*/ $this->processingHeader=true; $this->ResetMargins(); // necessary after columns $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; /*-- WATERMARK --*/ if (($this->watermarkText) && ($this->showWatermarkText)) { $this->watermark( $this->watermarkText, 45, 120, $this->watermarkTextAlpha); // Watermark text } if (($this->watermarkImage) && ($this->showWatermarkImage)) { $this->watermarkImg( $this->watermarkImage, $this->watermarkImageAlpha); // Watermark image } /*-- END WATERMARK --*/ $h = $this->footerDetails; if(count($h)) { if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) { $this->_out(sprintf('q 0 -1 1 0 0 %.3F cm ',($this->h*_MPDFK))); $headerpgwidth = $this->h - $this->orig_lMargin - $this->orig_rMargin; if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN $headerlmargin = $this->orig_rMargin; } else { $headerlmargin = $this->orig_lMargin; } } else { $yadj = 0; $headerpgwidth = $this->pgwidth; $headerlmargin = $this->lMargin; } $this->SetY(-$this->margin_footer); $this->SetTColor($this->ConvertColor(0)); $this->SUP = false; $this->SUB = false; $this->bullet = false; // only show pagenumber if numbering on $pgno = $this->docPageNum($this->page, true); if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN $side = 'even'; } else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS = DEFAULT $side = 'odd'; } $maxfontheight = 0; foreach(array('L','C','R') AS $pos) { if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) { if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; } else { $hfsz = $this->default_font_size; } $maxfontheight = max($maxfontheight,$hfsz); } } // LEFT-CENTER-RIGHT foreach(array('L','C','R') AS $pos) { if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) { $hd = str_replace('{PAGENO}',$pgno,$h[$side][$pos]['content']); $hd = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->aliasNbPgGp.$this->nbpgSuffix,$hd); $hd = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$hd); if (isset($h[$side][$pos]['font-family']) && $h[$side][$pos]['font-family']) { $hff = $h[$side][$pos]['font-family']; } else { $hff = $this->original_default_font; } if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; } else { $hfsz = $this->original_default_font_size; } $maxfontheight = max($maxfontheight,$hfsz); if (isset($h[$side][$pos]['font-style']) && $h[$side][$pos]['font-style']) { $hfst = $h[$side][$pos]['font-style']; } else { $hfst = ''; } if (isset($h[$side][$pos]['color']) && $h[$side][$pos]['color']) { $hfcol = $h[$side][$pos]['color']; $cor = $this->ConvertColor($hfcol); if ($cor) { $this->SetTColor($cor); } } else { $hfcol = ''; } $this->SetFont($hff,$hfst,$hfsz,true,true); $this->x = $headerlmargin ; $this->y = $this->h - $this->margin_footer - ($maxfontheight/_MPDFK); $hd = $this->purify_utf8_text($hd); if ($this->text_input_as_HTML) { $hd = $this->all_entities_to_utf8($hd); } // CONVERT CODEPAGE if ($this->usingCoreFont) { $hd = mb_convert_encoding($hd,$this->mb_enc,'UTF-8'); } // DIRECTIONALITY RTL $this->magic_reverse_dir($hd, true, $this->directionality); // *RTL* // Font-specific ligature substitution for Indic fonts if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($hd); // *INDIC* $align = $pos; if ($this->directionality == 'rtl') { if ($pos == 'L') { $align = 'R'; } else if ($pos == 'R') { $align = 'L'; } } if ($pos!='L' && (strpos($hd,$this->aliasNbPg)!==false || strpos($hd,$this->aliasNbPgGp)!==false)) { if (strpos($hd,$this->aliasNbPgGp)!==false) { $type= 'nbpggp'; } else { $type= 'nbpg'; } $this->_out('{mpdfheader'.$type.' '.$pos.' ff='.$hff.' fs='.$hfst.' fz='.$hfsz.'}'); $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M'); $this->_out('Q'); } else { $this->Cell($headerpgwidth ,$maxfontheight/_MPDFK ,$hd,0,0,$align,0,'',0,0,0,'M'); } if ($hfcol) { $this->SetTColor($this->ConvertColor(0)); } } } // Return Font to normal $this->SetFont($this->default_font,'',$this->original_default_font_size); // LINE if (isset($h[$side]['line']) && $h[$side]['line']) { $this->SetLineWidth(0.1); $this->SetDColor($this->ConvertColor(0)); $this->Line($headerlmargin , $this->y-($maxfontheight*($this->footer_line_spacing)/_MPDFK), $headerlmargin +$headerpgwidth, $this->y-($maxfontheight*($this->footer_line_spacing)/_MPDFK)); } if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) { $this->_out('Q'); } } $this->processingHeader=false; } /*-- HYPHENATION --*/ /////////////////// /////////////////// // HYPHENATION /////////////////// // Soft hyphs function softHyphenate($word, $maxWidth) { // Don't hyphenate web addresses if (preg_match('/^(http:|www\.)/',$word)) { return array(false,'','',''); } // Get dictionary $poss = array(); $softhyphens = array(); $offset = 0; $p = true; if ($this->usingCoreFont) { $wl = strlen($word); } else { $wl = mb_strlen($word,'UTF-8'); } while($offset < $wl) { // Soft Hyphens chr(173) if (!$this->usingCoreFont) { $p = mb_strpos($word, "\xc2\xad", $offset, 'UTF-8'); } else if ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats') { $p = strpos($word, chr(173), $offset); } if ($p !== false) { $poss[] = $p - count($poss); } else { break; } $offset = $p+1; } $success = false; foreach($poss AS $i) { if ($this->usingCoreFont) { $a = substr($word,0,$i); if ($this->GetStringWidth($a.'-') > $maxWidth) { break ; } $pre = $a; $post = substr($word,$i,strlen($word)); $prelength = strlen($pre); } else { $a = mb_substr($word,0,$i,'UTF-8'); if ($this->GetStringWidth($a.'-') > $maxWidth) { break ; } $pre = $a; $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8'); $prelength = mb_strlen($pre, 'UTF-8'); } $success = true; } return array($success,$pre,$post,$prelength); } /////////////////// // Word hyphenation function hyphenateWord($word, $maxWidth) { // Do everything inside this function in utf-8 // Don't hyphenate web addresses if (preg_match('/^(http:|www\.)/',$word)) { return array(false,'','',''); } // Get dictionary if (!$this->loadedSHYdictionary) { if (file_exists(_MPDF_PATH.'patterns/dictionary.txt')) { $this->SHYdictionary = file(_MPDF_PATH.'patterns/dictionary.txt',FILE_SKIP_EMPTY_LINES); foreach($this->SHYdictionary as $entry) { $entry = trim($entry); $poss = array(); $offset = 0; $p = true; $wl = mb_strlen($entry ,'UTF-8'); while($offset < $wl) { $p = mb_strpos($entry, '/', $offset, 'UTF-8'); if ($p !== false) { $poss[] = $p - count($poss); } else { break; } $offset = $p+1; } if (count($poss)) { $this->SHYdictionaryWords[str_replace('/', '', mb_strtolower($entry))] = $poss; } } } $this->loadedSHYdictionary = true; } if (!in_array($this->SHYlang,$this->SHYlanguages)) { return array(false,'','',''); } // If no pattern loaded or not the best one if (count($this->SHYpatterns) < 1 || ($this->loadedSHYpatterns && $this->loadedSHYpatterns != $this->SHYlang)) { include(_MPDF_PATH."patterns/" . $this->SHYlang . ".php"); $patterns = explode(' ', $patterns); $new_patterns = array(); for($i = 0; $i < count($patterns); $i++) { $value = $patterns[$i]; $new_patterns[preg_replace('/[0-9]/', '', $value)] = $value; } $this->SHYpatterns = $new_patterns; $this->loadedSHYpatterns = $this->SHYlang; } if ($this->usingCoreFont) { $word = mb_convert_encoding($word,'UTF-8',$this->mb_enc); } $prepre = ''; $postpost = ''; $startpunctuation = "\xc2\xab\xc2\xbf\xe2\x80\x98\xe2\x80\x9b\xe2\x80\x9c\xe2\x80\x9f"; $endpunctuation = "\xe2\x80\x9e\xe2\x80\x9d\xe2\x80\x9a\xe2\x80\x99\xc2\xbb"; $pre = ''; $post = ''; if (preg_match('/^(["\''.$startpunctuation .'])+(.{'.$this->SHYcharmin.',})$/u',$word,$m)) { $prepre = $m[1]; $word = $m[2]; } if (preg_match('/^(.{'.$this->SHYcharmin.',})([\'\.,;:!?"'.$endpunctuation .']+)$/u',$word,$m)) { $word = $m[1]; $postpost = $m[2]; } if(mb_strlen($word,'UTF-8') < $this->SHYcharmin) { return array(false,'','',''); } $success = false; if(isset($this->SHYdictionaryWords[mb_strtolower($word)])) { foreach($this->SHYdictionaryWords[mb_strtolower($word)] AS $i) { $a = $prepre . mb_substr($word,0,$i,'UTF-8'); if ($this->usingCoreFont) { $testa = mb_convert_encoding($a,$this->mb_enc,'UTF-8'); } else { $testa = $a; } if ($this->GetStringWidth($testa.'-') > $maxWidth) { break ; } $pre = $a; $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8') . $postpost; $success = true; } } if (!$success) { $text_word = '_' . $word . '_'; $word_length = mb_strlen($text_word,'UTF-8'); $single_character = preg_split('//u', $text_word); $text_word = mb_strtolower($text_word,'UTF-8'); $hyphenated_word = array(); $numb3rs = array('0' => true, '1' => true, '2' => true, '3' => true, '4' => true, '5' => true, '6' => true, '7' => true, '8' => true, '9' => true); for($position = 0; $position <= ($word_length - $this->SHYcharmin); $position++) { $maxwins = min(($word_length - $position), $this->SHYcharmax); for($win = $this->SHYcharmin; $win <= $maxwins; $win++) { if(isset($this->SHYpatterns[mb_substr($text_word, $position, $win,'UTF-8')])) { $pattern = $this->SHYpatterns[mb_substr($text_word, $position, $win,'UTF-8')]; $digits = 1; $pattern_length = mb_strlen($pattern,'UTF-8'); for($i = 0; $i < $pattern_length; $i++) { $char = $pattern[$i]; if(isset($numb3rs[$char])) { $zero = ($i == 0) ? $position - 1 : $position + $i - $digits; if(!isset($hyphenated_word[$zero]) || $hyphenated_word[$zero] != $char) $hyphenated_word[$zero] = $char; $digits++; } } } } } for($i = $this->SHYleftmin; $i <= (mb_strlen($word,'UTF-8') - $this->SHYrightmin); $i++) { if(isset($hyphenated_word[$i]) && $hyphenated_word[$i] % 2 != 0) { $a = $prepre . mb_substr($word,0,$i,'UTF-8'); if ($this->usingCoreFont) { $testa = mb_convert_encoding($a,$this->mb_enc,'UTF-8'); } else { $testa = $a; } if ($this->GetStringWidth($testa.'-') > $maxWidth + 0.0001) { break ; } $pre = $a; $post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8') . $postpost; $success = true; } } } if ($this->usingCoreFont) { $pre = mb_convert_encoding($pre,$this->mb_enc,'UTF-8'); $post = mb_convert_encoding($post,$this->mb_enc,'UTF-8'); $prelength = strlen($pre); } else { $prelength = mb_strlen($pre); } return array($success,$pre,$post,$prelength); } /*-- END HYPHENATION --*/ /*-- HTML-CSS --*/ /////////////////// /// HTML parser /// /////////////////// function WriteHTML($html,$sub=0,$init=true,$close=true) { // $sub ADDED - 0 = default; 1=headerCSS only; 2=HTML body (parts) only; 3 - HTML parses only // 4 - writes HTML headers // $close Leaves buffers etc. in current state, so that it can continue a block etc. // $init - Clears and sets buffers to Top level block etc. if (empty($html)) { $html = ''; } if ($this->progressBar) { $this->UpdateProgressBar(1,0,'Parsing CSS & Headers'); } // *PROGRESS-BAR* if ($init) { $this->headerbuffer=''; $this->textbuffer = array(); $this->fixedPosBlockSave = array(); } if ($sub == 1) { $html = '<style> '.$html.' </style>'; } // stylesheet only if ($this->allow_charset_conversion) { if ($sub < 1) { $this->ReadCharset($html); } if ($this->charset_in) { $success = iconv($this->charset_in,'UTF-8//TRANSLIT',$html); if ($success) { $html = $success; } } } $html = $this->purify_utf8($html,false); if ($init) { $this->blklvl = 0; $this->lastblocklevelchange = 0; $this->blk = array(); $this->initialiseBlock($this->blk[0]); $this->blk[0]['width'] =& $this->pgwidth; $this->blk[0]['inner_width'] =& $this->pgwidth; $this->blk[0]['blockContext'] = $this->blockContext; } $zproperties = array(); if ($sub < 2) { $this->ReadMetaTags($html); // NB default stylesheet now in mPDF.css - read on initialising class $html = $this->ReadCSS($html); if ($this->useLang && !$this->usingCoreFont && preg_match('/<html [^>]*lang=[\'\"](.*?)[\'\"]/ism',$html,$m)) { $html_lang = $m[1]; } if (preg_match('/<html [^>]*dir=[\'\"]\s*rtl\s*[\'\"]/ism',$html)) { $zproperties['DIRECTION'] = 'rtl'; } // allow in-line CSS for body tag to be parsed // Get <body> tag inline CSS if (preg_match('/<body([^>]*)>(.*?)<\/body>/ism',$html,$m) || preg_match('/<body([^>]*)>(.*)$/ism',$html,$m)) { $html = $m[2]; // Changed to allow style="background: url('bg.jpg')" if (preg_match('/style=[\"](.*?)[\"]/ism',$m[1],$mm) || preg_match('/style=[\'](.*?)[\']/ism',$m[1],$mm)) { $zproperties = $this->readInlineCSS($mm[1]); } if (preg_match('/dir=[\'\"]\s*rtl\s*[\'\"]/ism',$m[1])) { $zproperties['DIRECTION'] = 'rtl'; } if (isset($html_lang) && $html_lang) { $zproperties['LANG'] = $html_lang; } // mPDF 5.3.99 if ($this->useLang && !$this->onlyCoreFonts && preg_match('/lang=[\'\"](.*?)[\'\"]/ism',$m[1],$mm)) { // mPDF 5.3.22 $zproperties['LANG'] = $mm[1]; } } } $properties = $this->MergeCSS('BLOCK','BODY',''); if ($zproperties) { $properties = $this->array_merge_recursive_unique($properties,$zproperties); } if (isset($properties['DIRECTION']) && $properties['DIRECTION']) { $this->CSS['BODY']['DIRECTION'] = $properties['DIRECTION']; } if (!isset($this->CSS['BODY']['DIRECTION'])) { $this->CSS['BODY']['DIRECTION'] = $this->directionality; } else { $this->SetDirectionality($this->CSS['BODY']['DIRECTION']); } $this->setCSS($properties,'','BODY'); $this->blk[0]['InlineProperties'] = $this->saveInlineProperties(); if ($sub == 1) { return ''; } if (!isset($this->CSS['BODY'])) { $this->CSS['BODY'] = array(); } /*-- BACKGROUNDS --*/ if (isset($properties['BACKGROUND-GRADIENT'])) { $this->bodyBackgroundGradient = $properties['BACKGROUND-GRADIENT']; } if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE']) { $ret = $this->SetBackground($properties, $this->pgwidth); if ($ret) { $this->bodyBackgroundImage = $ret; } } /*-- END BACKGROUNDS --*/ /*-- CSS-PAGE --*/ // If page-box is set if ($this->state==0 && isset($this->CSS['@PAGE']) && $this->CSS['@PAGE'] ) { $this->page_box['current'] = ''; $this->page_box['using'] = true; list($pborientation,$pbmgl,$pbmgr,$pbmgt,$pbmgb,$pbmgh,$pbmgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS('', false, 'O'); $this->DefOrientation = $this->CurOrientation = $pborientation; $this->orig_lMargin = $this->DeflMargin = $pbmgl; $this->orig_rMargin = $this->DefrMargin = $pbmgr; $this->orig_tMargin = $this->tMargin = $pbmgt; $this->orig_bMargin = $this->bMargin = $pbmgb; $this->orig_hMargin = $this->margin_header = $pbmgh; $this->orig_fMargin = $this->margin_footer = $pbmgf; list($pborientation,$pbmgl,$pbmgr,$pbmgt,$pbmgb,$pbmgh,$pbmgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS('', true, 'O'); // first page $this->show_marks = $marks; if ($hname && !preg_match('/^html_(.*)$/i',$hname)) $this->firstPageBoxHeader = $hname; if ($fname && !preg_match('/^html_(.*)$/i',$fname)) $this->firstPageBoxFooter = $fname; } /*-- END CSS-PAGE --*/ $parseonly = false; $this->bufferoutput = false; if ($sub == 3) { $parseonly = true; // Close any open block tags for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); } // Output any text left in buffer if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); } $this->textbuffer=array(); } else if ($sub == 4) { // Close any open block tags for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); } // Output any text left in buffer if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); } $this->bufferoutput = true; $this->textbuffer=array(); $this->headerbuffer=''; $properties = $this->MergeCSS('BLOCK','BODY',''); $this->setCSS($properties,'','BODY'); } mb_internal_encoding('UTF-8'); $html = $this->AdjustHTML($html, $this->tabSpaces); //Try to make HTML look more like XHTML // mPDF 5.3.60 / 99 if ($this->autoFontGroups) { $html = $this->AutoFont($html); } /*-- HTMLHEADERS-FOOTERS --*/ preg_match_all('/<htmlpageheader([^>]*)>(.*?)<\/htmlpageheader>/si',$html,$h); for($i=0;$i<count($h[1]);$i++) { if (preg_match('/name=[\'|\"](.*?)[\'|\"]/',$h[1][$i],$n)) { $this->pageHTMLheaders[$n[1]]['html'] = $h[2][$i]; $this->pageHTMLheaders[$n[1]]['h'] = $this->_gethtmlheight($h[2][$i]); } } preg_match_all('/<htmlpagefooter([^>]*)>(.*?)<\/htmlpagefooter>/si',$html,$f); for($i=0;$i<count($f[1]);$i++) { if (preg_match('/name=[\'|\"](.*?)[\'|\"]/',$f[1][$i],$n)) { $this->pageHTMLfooters[$n[1]]['html'] = $f[2][$i]; $this->pageHTMLfooters[$n[1]]['h'] = $this->_gethtmlheight($f[2][$i]); } } /*-- END HTMLHEADERS-FOOTERS --*/ $html = preg_replace('/<htmlpageheader.*?<\/htmlpageheader>/si','',$html); $html = preg_replace('/<htmlpagefooter.*?<\/htmlpagefooter>/si','',$html); if($this->state==0 && $sub!=1 && $sub!=3 && $sub!=4) { $this->AddPage($this->CurOrientation); } /*-- HTMLHEADERS-FOOTERS --*/ if (isset($hname) && preg_match('/^html_(.*)$/i',$hname,$n)) $this->SetHTMLHeader($this->pageHTMLheaders[$n[1]],'O',true); if (isset($fname) && preg_match('/^html_(.*)$/i',$fname,$n)) $this->SetHTMLFooter($this->pageHTMLfooters[$n[1]],'O'); /*-- END HTMLHEADERS-FOOTERS --*/ $html=str_replace('<?','< ',$html); //Fix '<?XML' bug from HTML code generated by MS Word // mPDF 5.3.18 $this->checkSIP = false; $this->checkSMP = false; $this->checkCJK = false; if ($this->onlyCoreFonts) { $html = $this->SubstituteChars($html); } else { // mPDF 5.3.18 if (preg_match("/([".$this->pregRTLchars."])/u", $html)) { $this->biDirectional = true; } // *RTL* if (preg_match("/([\x{20000}-\x{2FFFF}])/u", $html)) { $this->checkSIP = true; } if (preg_match("/([\x{10000}-\x{1FFFF}])/u", $html)) { $this->checkSMP = true; } /*-- CJK-FONTS --*/ if (preg_match("/([".$this->pregCJKchars."])/u", $html)) { $this->checkCJK = true; } /*-- END CJK-FONTS --*/ } // Don't allow non-breaking spaces that are converted to substituted chars or will break anyway and mess up table width calc. $html = str_replace('<tta>160</tta>',chr(32),$html); $html = str_replace('</tta><tta>','|',$html); $html = str_replace('</tts><tts>','|',$html); $html = str_replace('</ttz><ttz>','|',$html); //Add new supported tags in the DisableTags function $html=strip_tags($html,$this->enabledtags); //remove all unsupported tags, but the ones inside the 'enabledtags' string //Explode the string in order to parse the HTML code $a=preg_split('/<(.*?)>/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE); // ? more accurate regexp that allows e.g. <a name="Silly <name>"> // if changing - also change in fn.SubstituteChars() // $a = preg_split ('/<((?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+)>/ms', $html, -1, PREG_SPLIT_DELIM_CAPTURE); if ($this->mb_enc) { mb_internal_encoding($this->mb_enc); } $pbc = 0; if ($this->progressBar) { $this->UpdateProgressBar(1,0); } // *PROGRESS-BAR* $this->subPos = -1; $cnt = count($a); for($i=0;$i<$cnt; $i++) { $e = $a[$i]; if($i%2==0) { //TEXT if ($this->blk[$this->blklvl]['hide']) { continue; } if ($this->inlineDisplayOff) { continue; } if ($this->inFixedPosBlock) { $this->fixedPosBlock .= $e; continue; } // *CSS-POSITION* if (strlen($e) == 0) { continue; } $e = strcode2utf($e); $e = $this->lesser_entity_decode($e); if ($this->usingCoreFont) { // mPDF 5.3.22 // If core font is selected in document which is not onlyCoreFonts - substitute with non-core font if ($this->useSubstitutions && !$this->onlyCoreFonts && $this->subPos<$i && !$this->specialcontent) { $cnt += $this->SubstituteCharsNonCore($a, $i, $e); } // CONVERT ENCODING $e = mb_convert_encoding($e,$this->mb_enc,'UTF-8'); if ($this->toupper) { $e = strtoupper($e); } if ($this->tolower) { $e = strtolower($e); } if ($this->capitalize) { $e = ucwords($e); } } // mPDF 5.3.21 else { if ($this->checkSIP && $this->CurrentFont['sipext'] && $this->subPos<$i && !$this->specialcontent) { $cnt += $this->SubstituteCharsSIP($a, $i, $e); } if ($this->useSubstitutions && !$this->onlyCoreFonts && $this->CurrentFont['type']!='Type0' && $this->subPos<$i && !$this->specialcontent) { $cnt += $this->SubstituteCharsMB($a, $i, $e); } if ($this->biDirectional) { // *RTL* $e = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $e); // *RTL* } // *RTL* // Font-specific ligature substitution for Indic fonts if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($e); // *INDIC* if ($this->toupper) { $e = mb_strtoupper($e,$this->mb_enc); } if ($this->tolower) { $e = mb_strtolower($e,$this->mb_enc); } if ($this->capitalize) { $e = mb_convert_case($e, MB_CASE_TITLE, "UTF-8"); } } if (($this->tts) || ($this->ttz) || ($this->tta)) { $es = explode('|',$e); $e = ''; foreach($es AS $val) { $e .= chr($val); } } //Adjust lineheight // FORM ELEMENTS if ($this->specialcontent) { /*-- FORMS --*/ //SELECT tag (form element) if ($this->specialcontent == "type=select") { $e = ltrim($e); $stringwidth = $this->GetStringWidth($e); if (!isset($this->selectoption['MAXWIDTH']) || $stringwidth > $this->selectoption['MAXWIDTH']) { $this->selectoption['MAXWIDTH'] = $stringwidth; } if (!isset($this->selectoption['SELECTED']) || $this->selectoption['SELECTED'] == '') { $this->selectoption['SELECTED'] = $e; } // mPDD 1.4 Active Forms if (isset($this->selectoption['ACTIVE']) && $this->selectoption['ACTIVE']) { $this->selectoption['ITEMS'][]=array('exportValue'=>$this->selectoption['currentVAL'], 'content'=>$e, 'selected'=>$this->selectoption['currentSEL']); } } // TEXTAREA else { $objattr = unserialize($this->specialcontent); $objattr['text'] = $e; $te = "\xbb\xa4\xactype=textarea,objattr=".serialize($objattr)."\xbb\xa4\xac"; if ($this->tdbegin) { $this->_saveCellTextBuffer($te, $this->HREF); // mPDF 5.3.99 } else { $this->_saveTextBuffer($te, $this->HREF); // mPDF 5.3.99 } } /*-- END FORMS --*/ } // TABLE else if ($this->tableLevel) { /*-- TABLES --*/ if ($this->tdbegin) { if (($this->ignorefollowingspaces) && !$this->ispre) { $e = ltrim($e); } if ($e || $e==='0') { if (($this->blockjustfinished || $this->listjustfinished) && $this->cell[$this->row][$this->col]['s']>0) { $this->_saveCellTextBuffer("\n"); // mPDF 5.3.99 if (!isset($this->cell[$this->row][$this->col]['maxs'])) { $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) { $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } $this->cell[$this->row][$this->col]['s'] = 0;// reset } $this->blockjustfinished=false; $this->listjustfinished=false; // mPDF 5.3.76 $this->_saveCellTextBuffer($e, $this->HREF); // mPDF 5.3.99 if (!isset($this->cell[$this->row][$this->col]['R']) || !$this->cell[$this->row][$this->col]['R']) { if (isset($this->cell[$this->row][$this->col]['s'])) { $this->cell[$this->row][$this->col]['s'] += $this->GetStringWidth($e, false); } else { $this->cell[$this->row][$this->col]['s'] = $this->GetStringWidth($e, false); } // mPDF 5.3.61 if (!empty($this->spanborddet)) { $this->cell[$this->row][$this->col]['s'] += $this->spanborddet['L']['w'] + $this->spanborddet['R']['w']; } } if ($this->checkCJK && preg_match("/([".$this->pregCJKchars."])/u", $e)) { $this->tableCJK = true; } // *CJK-FONTS* if ($this->tableLevel==1 && $this->useGraphs) { $this->graphs[$this->currentGraphId]['data'][$this->row][$this->col] = $e; } $this->nestedtablejustfinished = false; $this->linebreakjustfinished=false; } } /*-- END TABLES --*/ } // ALL ELSE else { if ($this->ignorefollowingspaces and !$this->ispre) { $e = ltrim($e); } if ($e || $e==='0') $this->_saveTextBuffer($e, $this->HREF); // mPDF 5.3.99 } } else { // TAG ** if($e[0]=='/') { /*-- PROGRESS-BAR --*/ if ($this->progressBar) { // 10% increments if (intval($i*10/$cnt) != $pbc) { $pbc = intval($i*10/$cnt); $this->UpdateProgressBar(1,$pbc*10,$tag); } } /*-- END PROGRESS-BAR --*/ // Check for tags where HTML specifies optional end tags, // and/or does not allow nesting e.g. P inside P, or $endtag = strtoupper(substr($e,1)); if($this->blk[$this->blklvl]['hide']) { if (in_array($endtag, $this->outerblocktags) || in_array($endtag, $this->innerblocktags)) { unset($this->blk[$this->blklvl]); $this->blklvl--; } continue; } /*-- CSS-POSITION --*/ if ($this->inFixedPosBlock) { if (in_array($endtag, $this->outerblocktags) || in_array($endtag, $this->innerblocktags)) { $this->fixedPosBlockDepth--; } if ($this->fixedPosBlockDepth == 0) { $this->fixedPosBlockSave[] = array($this->fixedPosBlock, $this->fixedPosBlockBBox, $this->page); $this->fixedPosBlock = ''; $this->inFixedPosBlock = false; continue; } $this->fixedPosBlock .= '<'.$e.'>'; continue; } /*-- END CSS-POSITION --*/ if ($this->allow_html_optional_endtags && !$parseonly) { if (($endtag == 'DIV' || $endtag =='FORM' || $endtag =='CENTER') && $this->lastoptionaltag == 'P') { $this->CloseTag($this->lastoptionaltag ); } if ($this->lastoptionaltag == 'LI' && $endtag == 'OL') { $this->CloseTag($this->lastoptionaltag ); } if ($this->lastoptionaltag == 'LI' && $endtag == 'UL') { $this->CloseTag($this->lastoptionaltag ); } if ($this->lastoptionaltag == 'DD' && $endtag == 'DL') { $this->CloseTag($this->lastoptionaltag ); } if ($this->lastoptionaltag == 'DT' && $endtag == 'DL') { $this->CloseTag($this->lastoptionaltag ); } if ($this->lastoptionaltag == 'OPTION' && $endtag == 'SELECT') { $this->CloseTag($this->lastoptionaltag ); } /*-- TABLES --*/ if ($endtag == 'TABLE') { if ($this->lastoptionaltag == 'THEAD' || $this->lastoptionaltag == 'TBODY' || $this->lastoptionaltag == 'TFOOT') { $this->CloseTag($this->lastoptionaltag); } if ($this->lastoptionaltag == 'TR') { $this->CloseTag('TR'); } if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); } } if ($endtag == 'THEAD' || $endtag == 'TBODY' || $endtag == 'TFOOT') { if ($this->lastoptionaltag == 'TR') { $this->CloseTag('TR'); } if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); } } if ($endtag == 'TR') { if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); } } /*-- END TABLES --*/ } $this->CloseTag($endtag); } else { // OPENING TAG if($this->blk[$this->blklvl]['hide']) { if (strpos($e,' ')) { $te = strtoupper(substr($e,0,strpos($e,' '))); } else { $te = strtoupper($e); } if (in_array($te, $this->outerblocktags) || in_array($te, $this->innerblocktags)) { $this->blklvl++; $this->blk[$this->blklvl]['hide']=true; } continue; } /*-- CSS-POSITION --*/ if ($this->inFixedPosBlock) { if (strpos($e,' ')) { $te = strtoupper(substr($e,0,strpos($e,' '))); } else { $te = strtoupper($e); } $this->fixedPosBlock .= '<'.$e.'>'; if (in_array($te, $this->outerblocktags) || in_array($te, $this->innerblocktags)) { $this->fixedPosBlockDepth++; } continue; } /*-- END CSS-POSITION --*/ $regexp = '|=\'(.*?)\'|s'; // eliminate single quotes, if any $e = preg_replace($regexp,"=\"\$1\"",$e); // changes anykey=anyvalue to anykey="anyvalue" (only do this inside tags) if (substr($e,0,10)!='pageheader' && substr($e,0,10)!='pagefooter') { $regexp = '| (\\w+?)=([^\\s>"]+)|si'; $e = preg_replace($regexp," \$1=\"\$2\"",$e); } $e = preg_replace('/ (\\S+?)\s*=\s*"/i', " \\1=\"", $e); //Fix path values, if needed $orig_srcpath = ''; if ((stristr($e,"href=") !== false) or (stristr($e,"src=") !== false) ) { $regexp = '/ (href|src)\s*=\s*"(.*?)"/i'; preg_match($regexp,$e,$auxiliararray); if (isset($auxiliararray[2])) { $path = $auxiliararray[2]; } else { $path = ''; } if (trim($path) != '' && !(stristr($e,"src=") !== false && substr($path,0,4)=='var:')) { $orig_srcpath = $path; $this->GetFullPath($path); $regexp = '/ (href|src)="(.*?)"/i'; $e = preg_replace($regexp,' \\1="'.$path.'"',$e); } }//END of Fix path values //Extract attributes $contents=array(); // Changed to allow style="background: url('bg.jpg')" preg_match_all('/\\S*=["][^"]*["]/',$e,$contents1); preg_match_all('/\\S*=[\'][^\']*[\']/',$e,$contents2); $contents = array_merge($contents1, $contents2); preg_match('/\\S+/',$e,$a2); $tag=strtoupper($a2[0]); $attr=array(); if ($orig_srcpath) { $attr['ORIG_SRC'] = $orig_srcpath; } if (!empty($contents)) { foreach($contents[0] as $v) { // Changed to allow style="background: url('bg.jpg')" if(preg_match('/^([^=]*)=["]?([^"]*)["]?$/',$v,$a3) || preg_match('/^([^=]*)=[\']?([^\']*)[\']?$/',$v,$a3)) { if (strtoupper($a3[1])=='ID' || strtoupper($a3[1])=='CLASS') { // 4.2.013 Omits STYLE $attr[strtoupper($a3[1])]=trim(strtoupper($a3[2])); } // includes header-style-right etc. used for <pageheader> else if (preg_match('/^(HEADER|FOOTER)-STYLE/i',$a3[1])) { $attr[strtoupper($a3[1])]=trim(strtoupper($a3[2])); } else { $attr[strtoupper($a3[1])]=trim($a3[2]); } } } } $this->OpenTag($tag,$attr); /*-- CSS-POSITION --*/ if ($this->inFixedPosBlock) { $this->fixedPosBlockBBox = array($tag,$attr, $this->x, $this->y); $this->fixedPosBlock = ''; $this->fixedPosBlockDepth = 1; } /*-- END CSS-POSITION --*/ } } // end TAG } //end of foreach($a as $i=>$e) if ($close) { // Close any open block tags for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); } // Output any text left in buffer if (count($this->textbuffer) && !$parseonly) { $this->printbuffer($this->textbuffer); } if (!$parseonly) $this->textbuffer=array(); /*-- CSS-FLOAT --*/ // If ended with a float, need to move to end page $currpos = $this->page*1000 + $this->y; if (isset($this->blk[$this->blklvl]['float_endpos']) && $this->blk[$this->blklvl]['float_endpos'] > $currpos) { $old_page = $this->page; $new_page = intval($this->blk[$this->blklvl]['float_endpos'] /1000); if ($old_page != $new_page) { $s = $this->PrintPageBackgrounds(); // Writes after the marker so not overwritten later by page background etc. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]); $this->pageBackgrounds = array(); $this->page = $new_page; $this->ResetMargins(); $this->Reset(); $this->pageoutput[$this->page] = array(); } $this->y = (($this->blk[$this->blklvl]['float_endpos'] *1000) % 1000000)/1000; // mod changes operands to integers before processing } /*-- END CSS-FLOAT --*/ /*-- CSS-IMAGE-FLOAT --*/ $this->printfloatbuffer(); /*-- END CSS-IMAGE-FLOAT --*/ //Create Internal Links, if needed if (!empty($this->internallink) ) { foreach($this->internallink as $k=>$v) { if (strpos($k,"#") !== false ) { continue; } //ignore $ypos = $v['Y']; $pagenum = $v['PAGE']; $sharp = "#"; while (array_key_exists($sharp.$k,$this->internallink)) { $internallink = $this->internallink[$sharp.$k]; $this->SetLink($internallink,$ypos,$pagenum); $sharp .= "#"; } } } $this->linemaxfontsize = ''; $this->lineheight_correction = $this->default_lineheight_correction; $this->bufferoutput = false; /*-- CSS-POSITION --*/ if (count($this->fixedPosBlockSave) && $sub != 4) { foreach($this->fixedPosBlockSave AS $fpbs) { $old_page = $this->page; $this->page = $fpbs[2]; $this->WriteFixedPosHTML($fpbs[0], 0, 0, 100, 100,'auto', $fpbs[1]); // 0,0,10,10 are overwritten by bbox $this->page = $old_page; } } /*-- END CSS-POSITION --*/ } } /*-- CSS-POSITION --*/ function WriteFixedPosHTML($html='',$x, $y, $w, $h, $overflow='visible', $bounding=array()) { // $overflow can be 'hidden', 'visible' or 'auto' - 'auto' causes autofit to size // Annotations disabled - enabled in mPDF 5.0 // Links do work // Will always go on current page (or start Page 1 if required) // Probably INCOMPATIBLE WITH keep with table, columns etc. // Called externally or interally via <div style="position: [fixed|absolute]"> // When used internally, $x $y $w $h and $overflow are all overridden by $bounding $overflow = strtolower($overflow); if($this->state==0) { $this->AddPage($this->CurOrientation); } $save_y = $this->y; $save_x = $this->x; $this->fullImageHeight = $this->h; $save_cols = false; /*-- COLUMNS --*/ if ($this->ColActive) { $save_cols = true; $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off $this->SetColumns(0); } /*-- END COLUMNS --*/ $save_annots = $this->title2annots; // *ANNOTATIONS* $this->writingHTMLheader = true; // a FIX to stop pagebreaks etc. $this->writingHTMLfooter = true; $this->InFooter = true; // suppresses autopagebreaks $save_bgs = $this->pageBackgrounds; $checkinnerhtml = preg_replace('/\s/','',$html); if ($w > $this->w) { $x = 0; $w = $this->w; } if ($h > $this->h) { $y = 0; $h = $this->h; } if ($x > $this->w) { $x = $this->w - $w; } if ($y > $this->h) { $y = $this->h - $h; } if (!empty($bounding)) { // $cont_ containing block = full physical page (position: absolute) or page inside margins (position: fixed) // $bbox_ Bounding box is the <div> which is positioned absolutely/fixed // top/left/right/bottom/width/height/background*/border*/padding*/margin* are taken from bounding // font*[family/size/style/weight]/line-height/text*[align/decoration/transform/indent]/color are transferred to $inner // as an enclosing <div> (after having checked ID/CLASS) // $x, $y, $w, $h are inside of $bbox_ = containing box for $inner_ // $inner_ InnerHTML is the contents of that block to be output $tag = $bounding[0]; $attr = $bounding[1]; $orig_x0 = $bounding[2]; $orig_y0 = $bounding[3]; // As in WriteHTML() initialising $this->blklvl = 0; $this->lastblocklevelchange = 0; $this->blk = array(); $this->initialiseBlock($this->blk[0]); $this->blk[0]['width'] =& $this->pgwidth; $this->blk[0]['inner_width'] =& $this->pgwidth; $this->blk[0]['blockContext'] = $this->blockContext; $properties = $this->MergeCSS('BLOCK','BODY',''); $this->setCSS($properties,'','BODY'); $this->blklvl = 1; $this->initialiseBlock($this->blk[1]); $this->blk[1]['tag'] = $tag; $this->blk[1]['attr'] = $attr; $this->Reset(); $p = $this->MergeCSS('BLOCK',$tag,$attr); if (isset($p['ROTATE']) && ($p['ROTATE']==90 || $p['ROTATE']==-90)) { $rotate = $p['ROTATE']; } else { $rotate = 0; } if (isset($p['OVERFLOW'])) { $overflow = strtolower($p['OVERFLOW']); } if (strtolower($p['POSITION']) == 'fixed') { $cont_w = $this->pgwidth; // $this->blk[0]['inner_width']; $cont_h = $this->h - $this->tMargin - $this->bMargin; $cont_x = $this->lMargin; $cont_y = $this->tMargin; } else { $cont_w = $this->w; // ABSOLUTE; $cont_h = $this->h; $cont_x = 0; $cont_y = 0; } // Pass on in-line properties to the innerhtml $css = ''; if (isset($p['TEXT-ALIGN'])) { $css .= 'text-align: '.strtolower($p['TEXT-ALIGN']).'; '; } if (isset($p['TEXT-TRANSFORM'])) { $css .= 'text-transform: '.strtolower($p['TEXT-TRANSFORM']).'; '; } if (isset($p['TEXT-INDENT'])) { $css .= 'text-indent: '.strtolower($p['TEXT-INDENT']).'; '; } if (isset($p['TEXT-DECORATION'])) { $css .= 'text-decoration: '.strtolower($p['TEXT-DECORATION']).'; '; } if (isset($p['FONT-FAMILY'])) { $css .= 'font-family: '.strtolower($p['FONT-FAMILY']).'; '; } if (isset($p['FONT-STYLE'])) { $css .= 'font-style: '.strtolower($p['FONT-STYLE']).'; '; } if (isset($p['FONT-WEIGHT'])) { $css .= 'font-weight: '.strtolower($p['FONT-WEIGHT']).'; '; } if (isset($p['FONT-SIZE'])) { $css .= 'font-size: '.strtolower($p['FONT-SIZE']).'; '; } if (isset($p['LINE-HEIGHT'])) { $css .= 'line-height: '.strtolower($p['LINE-HEIGHT']).'; '; } if (isset($p['TEXT-ALIGN'])) { $css .= 'text-align: '.strtolower($p['TEXT-ALIGN']).'; '; } if (isset($p['TEXT-SHADOW'])) { $css .= 'text-shadow: '.strtolower($p['TEXT-SHADOW']).'; '; } // mPDF 5.3.A4 if (isset($p['FONT-VARIANT'])) { $css .= 'font-variant: '.strtolower($p['FONT-VARIANT']).'; '; } if (isset($p['COLOR'])) { $css .= 'color: '.strtolower($p['COLOR']).'; '; } if ($css) { $html = '<div style="'.$css.'">'.$html.'</div>'; } // Copy over (only) the properties to set for border and background $pb = array(); $pb['MARGIN-TOP'] = $p['MARGIN-TOP']; $pb['MARGIN-RIGHT'] = $p['MARGIN-RIGHT']; $pb['MARGIN-BOTTOM'] = $p['MARGIN-BOTTOM']; $pb['MARGIN-LEFT'] = $p['MARGIN-LEFT']; $pb['PADDING-TOP'] = $p['PADDING-TOP']; $pb['PADDING-RIGHT'] = $p['PADDING-RIGHT']; $pb['PADDING-BOTTOM'] = $p['PADDING-BOTTOM']; $pb['PADDING-LEFT'] = $p['PADDING-LEFT']; $pb['BORDER-TOP'] = $p['BORDER-TOP']; $pb['BORDER-RIGHT'] = $p['BORDER-RIGHT']; $pb['BORDER-BOTTOM'] = $p['BORDER-BOTTOM']; $pb['BORDER-LEFT'] = $p['BORDER-LEFT']; // mPDF 5.3.66 $pb['BORDER-TOP-LEFT-RADIUS-H'] = $p['BORDER-TOP-LEFT-RADIUS-H']; $pb['BORDER-TOP-LEFT-RADIUS-V'] = $p['BORDER-TOP-LEFT-RADIUS-V']; $pb['BORDER-TOP-RIGHT-RADIUS-H'] = $p['BORDER-TOP-RIGHT-RADIUS-H']; $pb['BORDER-TOP-RIGHT-RADIUS-V'] = $p['BORDER-TOP-RIGHT-RADIUS-V']; $pb['BORDER-BOTTOM-LEFT-RADIUS-H'] = $p['BORDER-BOTTOM-LEFT-RADIUS-H']; $pb['BORDER-BOTTOM-LEFT-RADIUS-V'] = $p['BORDER-BOTTOM-LEFT-RADIUS-V']; $pb['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $p['BORDER-BOTTOM-RIGHT-RADIUS-H']; $pb['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $p['BORDER-BOTTOM-RIGHT-RADIUS-V']; if (isset($p['BACKGROUND-COLOR'])) { $pb['BACKGROUND-COLOR'] = $p['BACKGROUND-COLOR']; } if (isset($p['BOX-SHADOW'])) { $pb['BOX-SHADOW'] = $p['BOX-SHADOW']; } // mPDF 5.3.A4 /*-- BACKGROUNDS --*/ if (isset($p['BACKGROUND-IMAGE'])) { $pb['BACKGROUND-IMAGE'] = $p['BACKGROUND-IMAGE']; } if (isset($p['BACKGROUND-IMAGE-RESIZE'])) { $pb['BACKGROUND-IMAGE-RESIZE'] = $p['BACKGROUND-IMAGE-RESIZE']; } if (isset($p['BACKGROUND-IMAGE-OPACITY'])) { $pb['BACKGROUND-IMAGE-OPACITY'] = $p['BACKGROUND-IMAGE-OPACITY']; } if (isset($p['BACKGROUND-REPEAT'])) { $pb['BACKGROUND-REPEAT'] = $p['BACKGROUND-REPEAT']; } if (isset($p['BACKGROUND-POSITION'])) { $pb['BACKGROUND-POSITION'] = $p['BACKGROUND-POSITION']; } if (isset($p['BACKGROUND-GRADIENT'])) { $pb['BACKGROUND-GRADIENT'] = $p['BACKGROUND-GRADIENT']; } /*-- END BACKGROUNDS --*/ $this->setCSS($pb,'BLOCK',$tag); //================================================================ $bbox_br = $this->blk[1]['border_right']['w']; $bbox_bl = $this->blk[1]['border_left']['w']; $bbox_bt = $this->blk[1]['border_top']['w']; $bbox_bb = $this->blk[1]['border_bottom']['w']; $bbox_pr = $this->blk[1]['padding_right']; $bbox_pl = $this->blk[1]['padding_left']; $bbox_pt = $this->blk[1]['padding_top']; $bbox_pb = $this->blk[1]['padding_bottom']; $bbox_mr = $this->blk[1]['margin_right']; if (strtolower($p['MARGIN-RIGHT'])=='auto') { $bbox_mr = 'auto'; } $bbox_ml = $this->blk[1]['margin_left']; if (strtolower($p['MARGIN-LEFT'])=='auto') { $bbox_ml = 'auto'; } $bbox_mt = $this->blk[1]['margin_top']; if (strtolower($p['MARGIN-TOP'])=='auto') { $bbox_mt = 'auto'; } $bbox_mb = $this->blk[1]['margin_bottom']; if (strtolower($p['MARGIN-BOTTOM'])=='auto') { $bbox_mb = 'auto'; } if (isset($p['LEFT']) && strtolower($p['LEFT'])!='auto') { $bbox_left = $this->ConvertSize($p['LEFT'], $cont_w, $this->FontSize,false); } else { $bbox_left = 'auto'; } if (isset($p['TOP']) && strtolower($p['TOP'])!='auto') { $bbox_top = $this->ConvertSize($p['TOP'], $cont_h, $this->FontSize,false); } else { $bbox_top = 'auto'; } if (isset($p['RIGHT']) && strtolower($p['RIGHT'])!='auto') { $bbox_right = $this->ConvertSize($p['RIGHT'], $cont_w, $this->FontSize,false); } else { $bbox_right = 'auto'; } if (isset($p['BOTTOM']) && strtolower($p['BOTTOM'])!='auto') { $bbox_bottom = $this->ConvertSize($p['BOTTOM'], $cont_h, $this->FontSize,false); } else { $bbox_bottom = 'auto'; } if (isset($p['WIDTH']) && strtolower($p['WIDTH'])!='auto') { $inner_w = $this->ConvertSize($p['WIDTH'], $cont_w, $this->FontSize,false); } else { $inner_w = 'auto'; } if (isset($p['HEIGHT']) && strtolower($p['HEIGHT'])!='auto') { $inner_h = $this->ConvertSize($p['HEIGHT'], $cont_h, $this->FontSize,false); } else { $inner_h = 'auto'; } // If bottom or right pos are set and not left / top - save this to adjust rotated block later if ($rotate) { if ($bbox_left === 'auto' && $bbox_right !== 'auto') { $rot_rpos = $bbox_right; } else { $rot_rpos = false; } if ($bbox_top === 'auto' && $bbox_bottom !== 'auto') { $rot_bpos = $bbox_bottom; } else { $rot_bpos = false; } } //================================================================ if ($checkinnerhtml=='' && $inner_h==='auto') { $inner_h = 0.0001; } if ($checkinnerhtml=='' && $inner_w==='auto') { $inner_w = 2*$this->GetCharWidth('W',false); } // mPDF 5.3.04 //================================================================ // Algorithm from CSS2.1 See http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-height // mPD 5.3.14 // Special case (not CSS) if all not specified, centre vertically on page if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom==='auto' && $bbox_mt==='auto' && $bbox_mb==='auto') { $bbox_top_orig = $bbox_top; if ($bbox_mt==='auto') { $bbox_mt = 0; } if ($bbox_mb==='auto') { $bbox_mb = 0; } $bbox_top = $orig_y0 - $bbox_mt - $cont_y; // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto' } // mPD 5.3.14 else if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom==='auto') { $bbox_top_orig = $bbox_top = $orig_y0 - $cont_y; if ($bbox_mt==='auto') { $bbox_mt = 0; } if ($bbox_mb==='auto') { $bbox_mb = 0; } // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto' } else if ($bbox_top!=='auto' && $inner_h!=='auto' && $bbox_bottom!=='auto') { if ($bbox_mt==='auto' && $bbox_mb==='auto') { $x = $cont_h - $bbox_top - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_bottom; $bbox_mt = $bbox_mb = ($x/2); } else if ($bbox_mt==='auto') { $bbox_mt = $cont_h - $bbox_top - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom; } else if ($bbox_mb==='auto') { $bbox_mb = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_bottom; } else { $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt; } } else { if ($bbox_mt==='auto') { $bbox_mt = 0; } if ($bbox_mb==='auto') { $bbox_mb = 0; } if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom!=='auto') { // solve for $bbox_top when content_h known - $inner_h=='auto' && $bbox_top =='auto' } else if ($bbox_top==='auto' && $bbox_bottom==='auto' && $inner_h!=='auto') { $bbox_top = $orig_y0 - $bbox_mt - $cont_y; $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt; } else if ($inner_h==='auto' && $bbox_bottom==='auto' && $bbox_top!=='auto') { // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto' } else if ($bbox_top==='auto' && $inner_h!=='auto' && $bbox_bottom!=='auto') { $bbox_top = $cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom; } else if ($inner_h==='auto' && $bbox_top!=='auto' && $bbox_bottom!=='auto') { $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom; } else if ($bbox_bottom==='auto' && $bbox_top!=='auto' && $inner_h!=='auto') { $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt; } } // THEN DO SAME FOR WIDTH // http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width if ($bbox_left==='auto' && $inner_w==='auto' && $bbox_right==='auto') { if ($bbox_ml==='auto') { $bbox_ml = 0; } if ($bbox_mr==='auto') { $bbox_mr = 0; } // IF containing element RTL, should set $bbox_right $bbox_left = $orig_x0 - $bbox_ml - $cont_x; // solve for $bbox_right when content_w known - $inner_w=='auto' && $bbox_right=='auto' } else if ($bbox_left!=='auto' && $inner_w!=='auto' && $bbox_right!=='auto') { if ($bbox_ml==='auto' && $bbox_mr==='auto') { $x = $cont_w - $bbox_left - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_right; $bbox_ml = $bbox_mr = ($x/2); } else if ($bbox_ml==='auto') { $bbox_ml = $cont_w - $bbox_left - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_mr - $bbox_right; } else if ($bbox_mr==='auto') { $bbox_mr = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_right; } else { $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml; } } else { if ($bbox_ml==='auto') { $bbox_ml = 0; } if ($bbox_mr==='auto') { $bbox_mr = 0; } if ($bbox_left==='auto' && $inner_w==='auto' && $bbox_right!=='auto') { // solve for $bbox_left when content_w known - $inner_w=='auto' && $bbox_left =='auto' } else if ($bbox_left==='auto' && $bbox_right==='auto' && $inner_w!=='auto') { // IF containing element RTL, should set $bbox_right $bbox_left = $orig_x0 - $bbox_ml - $cont_x; $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml; } else if ($inner_w==='auto' && $bbox_right==='auto' && $bbox_left!=='auto') { // solve for $bbox_right when content_w known - $inner_w=='auto' && $bbox_right=='auto' } else if ($bbox_left==='auto' && $inner_w!=='auto' && $bbox_right!=='auto') { $bbox_left = $cont_w - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right; } else if ($inner_w==='auto' && $bbox_left!=='auto' && $bbox_right!=='auto') { $inner_w = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right; } else if ($bbox_right==='auto' && $bbox_left!=='auto' && $inner_w!=='auto') { $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml; } } //================================================================ //================================================================ /*-- BACKGROUNDS --*/ if (isset($pb['BACKGROUND-IMAGE']) && $pb['BACKGROUND-IMAGE']) { $ret = $this->SetBackground($pb, $this->blk[1]['inner_width']); if ($ret) { $this->blk[1]['background-image'] = $ret; } } /*-- END BACKGROUNDS --*/ //================================================================ $y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt; $h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom; $x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl; $w = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $bbox_pr - $bbox_br - $bbox_mr - $bbox_right; // Set (temporary) values for x y w h to do first paint, if values are auto if ($inner_h==='auto' && $bbox_top==='auto') { $y = $cont_y + $bbox_mt + $bbox_bt + $bbox_pt; $h = $cont_h - ($bbox_bottom + $bbox_mt + $bbox_mb + $bbox_bt + $bbox_bb + $bbox_pt + $bbox_pb); } else if ($inner_h==='auto' && $bbox_bottom==='auto') { $y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt; $h = $cont_h - ($bbox_top + $bbox_mt + $bbox_mb + $bbox_bt + $bbox_bb + $bbox_pt + $bbox_pb); } if ($inner_w==='auto' && $bbox_left==='auto') { $x = $cont_x + $bbox_ml + $bbox_bl + $bbox_pl; $w = $cont_w - ($bbox_right + $bbox_ml + $bbox_mr + $bbox_bl + $bbox_br + $bbox_pl + $bbox_pr); } else if ($inner_w==='auto' && $bbox_right==='auto') { $x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl; $w = $cont_w - ($bbox_left + $bbox_ml + $bbox_mr + $bbox_bl + $bbox_br + $bbox_pl + $bbox_pr); } $bbox_y = $cont_y + $bbox_top + $bbox_mt; $bbox_x = $cont_x + $bbox_left + $bbox_ml; $saved_block1 = $this->blk[1]; unset($p); unset($pb); //================================================================ if ($inner_w==='auto') { // do a first write $this->lMargin=$x; $this->rMargin=$this->w - $w - $x; // SET POSITION & FONT VALUES $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $this->pageoutput[$this->page]=array(); $this->x = $x; $this->y = $y; $this->HTMLheaderPageLinks = array(); $this->HTMLheaderPageAnnots = array(); $this->HTMLheaderPageForms = array(); $this->pageBackgrounds = array(); $this->maxPosR = 0; $this->maxPosL = $this->w; // For RTL $this->WriteHTML($html , 4); $inner_w = $this->maxPosR - $this->lMargin; if ($bbox_right==='auto') { $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml; } else if ($bbox_left==='auto') { $bbox_left = $cont_w - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right; $bbox_x = $cont_x + $bbox_left + $bbox_ml ; $inner_x = $bbox_x + $bbox_bl + $bbox_pl; $x = $inner_x; } $w = $inner_w; $bbox_y = $cont_y + $bbox_top + $bbox_mt; $bbox_x = $cont_x + $bbox_left + $bbox_ml; } if ($inner_h==='auto') { // do a first write $this->lMargin=$x; $this->rMargin=$this->w - $w - $x; // SET POSITION & FONT VALUES $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $this->pageoutput[$this->page]=array(); $this->x = $x; $this->y = $y; $this->HTMLheaderPageLinks = array(); $this->HTMLheaderPageAnnots = array(); $this->HTMLheaderPageForms = array(); $this->pageBackgrounds = array(); $this->WriteHTML($html , 4); $inner_h = $this->y - $y; if ($overflow!='hidden' && $overflow!='visible') { // constrained if (($this->y + $bbox_pb + $bbox_bb) > ($cont_y + $cont_h)) { $adj = ($this->y + $bbox_pb + $bbox_bb) - ($cont_y + $cont_h); $inner_h -= $adj; } } if ($bbox_bottom==='auto' && $bbox_top_orig==='auto') { $bbox_bottom = $bbox_top = ($cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb)/2; if ($overflow!='hidden' && $overflow!='visible') { // constrained if ($bbox_top < 0) { $bbox_top = 0; $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom; } } $bbox_y = $cont_y + $bbox_top + $bbox_mt; $inner_y = $bbox_y + $bbox_bt + $bbox_pt; $y = $inner_y; } else if ($bbox_bottom==='auto') { $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb; } else if ($bbox_top==='auto') { $bbox_top = $cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom; if ($overflow!='hidden' && $overflow!='visible') { // constrained if ($bbox_top < 0) { $bbox_top = 0; $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom; } } $bbox_y = $cont_y + $bbox_top + $bbox_mt; $inner_y = $bbox_y + $bbox_bt + $bbox_pt; $y = $inner_y; } $h = $inner_h; $bbox_y = $cont_y + $bbox_top + $bbox_mt; $bbox_x = $cont_x + $bbox_left + $bbox_ml; } $inner_w = $w; $inner_h = $h; } $this->lMargin=$x; $this->rMargin=$this->w - $w - $x; // SET POSITION & FONT VALUES $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $this->pageoutput[$this->page]=array(); $this->x = $x; $this->y = $y; $this->HTMLheaderPageLinks = array(); $this->HTMLheaderPageAnnots = array(); $this->HTMLheaderPageForms = array(); $this->pageBackgrounds = array(); $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer $actual_h = $this->y - $y; $use_w = $w; $use_h = $h; $ratio = $actual_h / $use_w; if ($overflow!='hidden' && $overflow!='visible') { $target = $h/$w; if (($ratio / $target ) > 1) { $nl = CEIL($actual_h / $this->lineheight); $l = $use_w * $nl; $est_w = sqrt(($l * $this->lineheight) / $target) * 0.8; $use_w += ($est_w - $use_w) - ($w/100); } $bpcstart = ($ratio / $target); $bpcctr = 1; while(($ratio / $target ) > 1) { if ($this->progressBar) { $this->UpdateProgressBar(4,intval(100/($ratio/$target)),('Auto-sizing fixed-position block: '.$bpcctr++)); } // *PROGRESS-BAR* $this->x = $x; $this->y = $y; if (($ratio / $target) > 1.5 || ($ratio / $target) < 0.6) { $use_w += ($w/$this->incrementFPR1); } else if (($ratio / $target) > 1.2 || ($ratio / $target) < 0.85) { $use_w += ($w/$this->incrementFPR2); } else if (($ratio / $target) > 1.1 || ($ratio / $target) < 0.91) { $use_w += ($w/$this->incrementFPR3); } else { $use_w += ($w/$this->incrementFPR4); } $use_h = $use_w * $target ; $this->rMargin=$this->w - $use_w - $x; $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $this->HTMLheaderPageLinks = array(); $this->HTMLheaderPageAnnots = array(); $this->HTMLheaderPageForms = array(); $this->pageBackgrounds = array(); $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer $actual_h = $this->y - $y; $ratio = $actual_h / $use_w; } if ($this->progressBar) { $this->UpdateProgressBar(4,'100',' '); } // *PROGRESS-BAR* } $shrink_f = $w/$use_w; //================================================================ $this->pages[$this->page] .= '___BEFORE_BORDERS___'; $block_s = $this->PrintPageBackgrounds(); // Save to print later inside clipping path $this->pageBackgrounds = array(); //================================================================ if ($rotate) { $prerotw = $bbox_bl + $bbox_pl + $inner_w + $bbox_pr + $bbox_br; $preroth = $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb; $rot_start = " q\n"; if ($rotate == 90) { if ($rot_rpos !== false) { $adjw = $prerotw; } // width before rotation else { $adjw = $preroth; } // height before rotation if ($rot_bpos !== false) { $adjh = -$prerotw + $preroth; } else { $adjh = 0; } } else { if ($rot_rpos !== false) { $adjw = $prerotw - $preroth; } else { $adjw = 0; } if ($rot_bpos !== false) { $adjh = $preroth; } // height before rotation else { $adjh = $prerotw; } // width before rotation } $rot_start .= $this->transformTranslate($adjw, $adjh, true)."\n"; $rot_start .= $this->transformRotate($rotate, $bbox_x, $bbox_y, true)."\n"; $rot_end = " Q\n"; } else { $rot_start = ''; $rot_end = ''; } //================================================================ if (!empty($bounding)) { // WHEN HEIGHT // BOTTOM EDGE IS KNOWN and $this->y is set to the bottom // Re-instate saved $this->blk[1] $this->blk[1] = $saved_block1; // These are only needed when painting border/background $this->blk[1]['width'] = $bbox_w = $cont_w - $bbox_left - $bbox_ml - $bbox_mr - $bbox_right; $this->blk[1]['x0'] = $bbox_x; $this->blk[1]['y0'] = $bbox_y; $this->blk[1]['startpage'] = $this->page; $this->blk[1]['y1'] = $bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb ; $this->_out($rot_start); // mPDF 5.0 $this->PaintDivBB('',0,1); // Prints borders and sets backgrounds in $this->pageBackgrounds $this->_out($rot_end); } $s = $this->PrintPageBackgrounds(); $s = $rot_start.$s.$rot_end; $this->pages[$this->page] = preg_replace('/___BEFORE_BORDERS___/', "\n".$s."\n", $this->pages[$this->page]); $this->pageBackgrounds = array(); $this->_out($rot_start); // Clipping Output if ($overflow=='hidden') { //Bounding rectangle to clip $clip_y1 = $this->y; if (!empty($bounding) && ($this->y + $bbox_pb + $bbox_bb) > ($bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb )) { $clip_y1 = ($bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb ) - ($bbox_pb + $bbox_bb); } //$op = 'W* n'; // Clipping $op = 'W n'; // Clipping alternative mode $this->_out("q"); $ch = $clip_y1 - $y; $this->_out(sprintf('%.3F %.3F %.3F %.3F re %s',$x*_MPDFK,($this->h-$y)*_MPDFK,$w*_MPDFK,-$ch*_MPDFK,$op)); if (!empty($block_s)) { $tmp = "q\n".sprintf('%.3F %.3F %.3F %.3F re %s',$x*_MPDFK,($this->h-$y)*_MPDFK,$w*_MPDFK,-$ch*_MPDFK,$op); $tmp .= "\n".$block_s."\nQ"; $block_s = $tmp ; } } if (!empty($block_s)) { if ($shrink_f != 1) { // i.e. autofit has resized the box $tmp = "q\n".$this->transformScale(($shrink_f*100),($shrink_f*100), $x, $y, true); $tmp .= "\n".$block_s."\nQ"; $block_s = $tmp ; } $this->_out($block_s); } if ($shrink_f != 1) { // i.e. autofit has resized the box $this->StartTransform(); $this->transformScale(($shrink_f*100),($shrink_f*100), $x, $y); } $this->_out($this->headerbuffer); if ($shrink_f != 1) { // i.e. autofit has resized the box $this->StopTransform(); } if ($overflow=='hidden') { //End clipping $this->_out("Q"); } $this->_out($rot_end); // Page Links foreach($this->HTMLheaderPageLinks AS $lk) { if ($rotate) { $tmp = $lk[2]; // Switch h - w $lk[2] = $lk[3]; $lk[3] = $tmp; $lx1 = (($lk[0]/_MPDFK)); $ly1 = (($this->h-($lk[1]/_MPDFK))); if ($rotate == 90) { $adjx = -($lx1-$bbox_x) + ($preroth - ($ly1-$bbox_y)); $adjy = -($ly1-$bbox_y) + ($lx1-$bbox_x); $lk[2] = -$lk[2]; } else if ($rotate == -90) { $adjx = -($lx1-$bbox_x) + ($ly1-$bbox_y); $adjy = -($ly1-$bbox_y) - ($lx1-$bbox_x) + $prerotw; $lk[3] = -$lk[3]; } if ($rot_rpos !== false) { $adjx += $prerotw - $preroth; } if ($rot_bpos !== false) { $adjy += $preroth - $prerotw; } $lx1 += $adjx; $ly1 += $adjy; $lk[0] = $lx1*_MPDFK; $lk[1] = ($this->h-$ly1)*_MPDFK; } if ($shrink_f != 1) { // i.e. autofit has resized the box $lx1 = (($lk[0]/_MPDFK)-$x); $lx2 = $x + ($lx1 * $shrink_f); $lk[0] = $lx2*_MPDFK; $ly1 = (($this->h-($lk[1]/_MPDFK))-$y); $ly2 = $y + ($ly1 * $shrink_f); $lk[1] = ($this->h-$ly2)*_MPDFK; $lk[2] *= $shrink_f; // width $lk[3] *= $shrink_f; // height } $this->PageLinks[$this->page][]=$lk; } foreach($this->HTMLheaderPageForms AS $n=>$f) { if ($shrink_f != 1) { // i.e. autofit has resized the box $f['x'] = $x + (($f['x'] -$x) * $shrink_f); $f['y'] = $y + (($f['y'] -$y) * $shrink_f); $f['w'] *= $shrink_f; $f['h'] *= $shrink_f; $f['style']['fontsize'] *= $shrink_f; } $this->form->forms[$f['n']] = $f; } // Page Annotations foreach($this->HTMLheaderPageAnnots AS $lk) { if ($rotate) { if ($rotate == 90) { $adjx = -($lk['x']-$bbox_x) + ($preroth - ($lk['y']-$bbox_y)); $adjy = -($lk['y']-$bbox_y) + ($lk['x']-$bbox_x); } else if ($rotate == -90) { $adjx = -($lk['x']-$bbox_x) + ($lk['y']-$bbox_y); $adjy = -($lk['y']-$bbox_y) - ($lk['x']-$bbox_x) + $prerotw; } if ($rot_rpos !== false) { $adjx += $prerotw - $preroth; } if ($rot_bpos !== false) { $adjy += $preroth - $prerotw; } $lk['x'] += $adjx; $lk['y'] += $adjy; } if ($shrink_f != 1) { // i.e. autofit has resized the box $lk['x'] = $x + (($lk['x']-$x) * $shrink_f); $lk['y'] = $y + (($lk['y']-$y) * $shrink_f); } $this->PageAnnots[$this->page][]=$lk; } // Restore $this->headerbuffer = ''; $this->HTMLheaderPageLinks = array(); $this->HTMLheaderPageAnnots = array(); $this->HTMLheaderPageForms = array(); $this->pageBackgrounds = $save_bgs; $this->writingHTMLheader = false; $this->writingHTMLfooter = false; $this->fullImageHeight = false; $this->ResetMargins(); $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $this->SetXY($save_x,$save_y) ; $this->title2annots = $save_annots; // *ANNOTATIONS* $this->InFooter = false; // turns back on autopagebreaks $this->pageoutput[$this->page]=array(); $this->pageoutput[$this->page]['Font']=''; /*-- COLUMNS --*/ if ($save_cols) { $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap); } /*-- END COLUMNS --*/ } /*-- END CSS-POSITION --*/ function initialiseBlock(&$blk) { $blk['margin_top'] = 0; $blk['margin_left'] = 0; $blk['margin_bottom'] = 0; $blk['margin_right'] = 0; $blk['padding_top'] = 0; $blk['padding_left'] = 0; $blk['padding_bottom'] = 0; $blk['padding_right'] = 0; $blk['border_top']['w'] = 0; $blk['border_left']['w'] = 0; $blk['border_bottom']['w'] = 0; $blk['border_right']['w'] = 0; $blk['hide'] = false; $blk['outer_left_margin'] = 0; $blk['outer_right_margin'] = 0; $blk['cascadeCSS'] = array(); $blk['block-align'] = false; $blk['bgcolor'] = false; $blk['page_break_after_avoid'] = false; $blk['keep_block_together'] = false; $blk['float'] = false; $blk['line_height'] = ''; $blk['margin_collapse'] = false; } function border_details($bd) { $prop = preg_split('/\s+/',trim($bd)); if (isset($this->blk[$this->blklvl]['inner_width'])) { $refw = $this->blk[$this->blklvl]['inner_width']; } else if (isset($this->blk[$this->blklvl-1]['inner_width'])) { $refw = $this->blk[$this->blklvl-1]['inner_width']; } else { $refw = $this->w; } if ( count($prop) == 1 ) { $bsize = $this->ConvertSize($prop[0],$refw,$this->FontSize,false); if ($bsize > 0) { return array('s' => 1, 'w' => $bsize, 'c' => $this->ConvertColor(0), 'style'=>'solid'); } else { return array('w' => 0, 's' => 0); } } else if (count($prop) == 2 ) { // 1px solid if (in_array($prop[1],$this->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden' ) { $prop[2] = ''; } // solid #000000 else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $prop[0] = ''; $prop[1] = $prop[0]; $prop[2] = $prop[1]; } // 1px #000000 else { $prop[1] = ''; $prop[2] = $prop[1]; } } else if ( count($prop) == 3 ) { // Change #000000 1px solid to 1px solid #000000 (proper) if (substr($prop[0],0,1) == '#') { $tmp = $prop[0]; $prop[0] = $prop[1]; $prop[1] = $prop[2]; $prop[2] = $tmp; } // Change solid #000000 1px to 1px solid #000000 (proper) else if (substr($prop[0],1,1) == '#') { $tmp = $prop[1]; $prop[0] = $prop[2]; $prop[1] = $prop[0]; $prop[2] = $tmp; } // Change solid 1px #000000 to 1px solid #000000 (proper) else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $tmp = $prop[0]; $prop[0] = $prop[1]; $prop[1] = $tmp; } } else { return array(); } // Size $bsize = $this->ConvertSize($prop[0],$refw,$this->FontSize,false); //color $coul = $this->ConvertColor($prop[2]); // returns array // Style $prop[1] = strtolower($prop[1]); if (in_array($prop[1],$this->borderstyles) && $bsize > 0) { $on = 1; } else if ($prop[1] == 'hidden') { $on = 1; $bsize = 0; $coul = ''; } else if ($prop[1] == 'none') { $on = 0; $bsize = 0; $coul = ''; } else { $on = 0; $bsize = 0; $coul = ''; $prop[1] = ''; } return array('s' => $on, 'w' => $bsize, 'c' => $coul, 'style'=> $prop[1] ); } function _fix_borderStr($bd) { $prop = preg_split('/\s+/',trim($bd)); $w = 'medium'; $c = '#000000'; $s = 'none'; if ( count($prop) == 1 ) { // solid if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; } // #000000 else if (is_array($this->ConvertColor($prop[0]))) { $c = $prop[0]; } // 1px else { $w = $prop[0]; } } else if (count($prop) == 2 ) { // 1px solid if (in_array($prop[1],$this->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden' ) { $w = $prop[0]; $s = $prop[1]; } // solid #000000 else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; $c = $prop[1]; } // 1px #000000 else { $w = $prop[0]; $c = $prop[1]; } } else if ( count($prop) == 3 ) { // Change #000000 1px solid to 1px solid #000000 (proper) if (substr($prop[0],0,1) == '#') { $c = $prop[0]; $w = $prop[1]; $s = $prop[2]; } // Change solid #000000 1px to 1px solid #000000 (proper) else if (substr($prop[0],1,1) == '#') { $s = $prop[0]; $c = $prop[1]; $w = $prop[2]; } // Change solid 1px #000000 to 1px solid #000000 (proper) else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; $w = $prop[1]; $c = $prop[2]; } else { $w = $prop[0]; $s = $prop[1]; $c = $prop[2]; } } else { return ''; } $s = strtolower($s); return $w.' '.$s.' '.$c; } // NEW FUNCTION FOR CSS MARGIN or PADDING called from SetCSS function fixCSS($prop) { if (!is_array($prop) || (count($prop)==0)) return array(); $newprop = array(); foreach($prop AS $k => $v) { if ($k != 'BACKGROUND-IMAGE' && $k != 'BACKGROUND' && $k != 'ODD-HEADER-NAME' && $k != 'EVEN-HEADER-NAME' && $k != 'ODD-FOOTER-NAME' && $k != 'EVEN-FOOTER-NAME' && $k != 'HEADER' && $k != 'FOOTER') { $v = strtolower($v); } if ($k == 'FONT') { $s = trim($v); preg_match_all('/\"(.*?)\"/',$s,$ff); if (count($ff[1])) { foreach($ff[1] AS $ffp) { $w = preg_split('/\s+/',$ffp); $s = preg_replace('/\"'.$ffp.'\"/',$w[0],$s); } } preg_match_all('/\'(.*?)\'/',$s,$ff); if (count($ff[1])) { foreach($ff[1] AS $ffp) { $w = preg_split('/\s+/',$ffp); $s = preg_replace('/\''.$ffp.'\'/',$w[0],$s); } } $s = preg_replace('/\s*,\s*/',',',$s); $bits = preg_split('/\s+/',$s); if (count($bits)>1) { $k = 'FONT-FAMILY'; $v = $bits[(count($bits)-1)]; $fs = $bits[(count($bits)-2)]; if (preg_match('/(.*?)\/(.*)/',$fs, $fsp)) { $newprop['FONT-SIZE'] = $fsp[1]; $newprop['LINE-HEIGHT'] = $fsp[2]; } else { $newprop['FONT-SIZE'] = $fs; } if (preg_match('/(italic|oblique)/i',$s)) { $newprop['FONT-STYLE'] = 'italic'; } else { $newprop['FONT-STYLE'] = 'normal'; } if (preg_match('/bold/i',$s)) { $newprop['FONT-WEIGHT'] = 'bold'; } else { $newprop['FONT-WEIGHT'] = 'normal'; } if (preg_match('/small-caps/i',$s)) { $newprop['TEXT-TRANSFORM'] = 'uppercase'; } } } if ($k == 'FONT-FAMILY') { $aux_fontlist = explode(",",$v); $found = 0; foreach($aux_fontlist AS $f) { $fonttype = trim($f); $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype); $fonttype = preg_replace('/ /','',$fonttype); $v = strtolower(trim($fonttype)); if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; } if ((!$this->onlyCoreFonts && in_array($v,$this->available_unifonts)) || in_array($v,array('ccourier','ctimes','chelvetica')) || /* mPDF 5.3.21 & 22 */ ($this->onlyCoreFonts && in_array($v,array('courier','times','helvetica','arial'))) || in_array($v, array('sjis','uhc','big5','gb'))) { $newprop[$k] = $v; $found = 1; break; } } if (!$found) { foreach($aux_fontlist AS $f) { $fonttype = trim($f); $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype); $fonttype = preg_replace('/ /','',$fonttype); $v = strtolower(trim($fonttype)); if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; } if (in_array($v,$this->sans_fonts) || in_array($v,$this->serif_fonts) || in_array($v,$this->mono_fonts) ) { $newprop[$k] = $v; break; } } } } else if ($k == 'MARGIN') { $tmp = $this->expand24($v); $newprop['MARGIN-TOP'] = $tmp['T']; $newprop['MARGIN-RIGHT'] = $tmp['R']; $newprop['MARGIN-BOTTOM'] = $tmp['B']; $newprop['MARGIN-LEFT'] = $tmp['L']; } /*-- BORDER-RADIUS --*/ else if ($k == 'BORDER-RADIUS' || $k == 'BORDER-TOP-LEFT-RADIUS' || $k == 'BORDER-TOP-RIGHT-RADIUS' || $k == 'BORDER-BOTTOM-LEFT-RADIUS' || $k == 'BORDER-BOTTOM-RIGHT-RADIUS') { $tmp = $this->border_radius_expand($v,$k); if (isset($tmp['TL-H'])) $newprop['BORDER-TOP-LEFT-RADIUS-H'] = $tmp['TL-H']; if (isset($tmp['TL-V'])) $newprop['BORDER-TOP-LEFT-RADIUS-V'] = $tmp['TL-V']; if (isset($tmp['TR-H'])) $newprop['BORDER-TOP-RIGHT-RADIUS-H'] = $tmp['TR-H']; if (isset($tmp['TR-V'])) $newprop['BORDER-TOP-RIGHT-RADIUS-V'] = $tmp['TR-V']; if (isset($tmp['BL-H'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-H'] = $tmp['BL-H']; if (isset($tmp['BL-V'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-V'] = $tmp['BL-V']; if (isset($tmp['BR-H'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $tmp['BR-H']; if (isset($tmp['BR-V'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $tmp['BR-V']; } /*-- END BORDER-RADIUS --*/ else if ($k == 'PADDING') { $tmp = $this->expand24($v); $newprop['PADDING-TOP'] = $tmp['T']; $newprop['PADDING-RIGHT'] = $tmp['R']; $newprop['PADDING-BOTTOM'] = $tmp['B']; $newprop['PADDING-LEFT'] = $tmp['L']; } else if ($k == 'BORDER') { if ($v == '1') { $v = '1px solid #000000'; } else { $v = $this->_fix_borderStr($v); } $newprop['BORDER-TOP'] = $v; $newprop['BORDER-RIGHT'] = $v; $newprop['BORDER-BOTTOM'] = $v; $newprop['BORDER-LEFT'] = $v; } else if ($k == 'BORDER-TOP') { $newprop['BORDER-TOP'] = $this->_fix_borderStr($v); } else if ($k == 'BORDER-RIGHT') { $newprop['BORDER-RIGHT'] = $this->_fix_borderStr($v); } else if ($k == 'BORDER-BOTTOM') { $newprop['BORDER-BOTTOM'] = $this->_fix_borderStr($v); } else if ($k == 'BORDER-LEFT') { $newprop['BORDER-LEFT'] = $this->_fix_borderStr($v); } else if ($k == 'BORDER-STYLE') { $e = $this->expand24($v); $newprop['BORDER-TOP-STYLE'] = $e['T']; $newprop['BORDER-RIGHT-STYLE'] = $e['R']; $newprop['BORDER-BOTTOM-STYLE'] = $e['B']; $newprop['BORDER-LEFT-STYLE'] = $e['L']; } else if ($k == 'BORDER-WIDTH') { $e = $this->expand24($v); $newprop['BORDER-TOP-WIDTH'] = $e['T']; $newprop['BORDER-RIGHT-WIDTH'] = $e['R']; $newprop['BORDER-BOTTOM-WIDTH'] = $e['B']; $newprop['BORDER-LEFT-WIDTH'] = $e['L']; } else if ($k == 'BORDER-COLOR') { $e = $this->expand24($v); $newprop['BORDER-TOP-COLOR'] = $e['T']; $newprop['BORDER-RIGHT-COLOR'] = $e['R']; $newprop['BORDER-BOTTOM-COLOR'] = $e['B']; $newprop['BORDER-LEFT-COLOR'] = $e['L']; } else if ($k == 'BORDER-SPACING') { $prop = preg_split('/\s+/',trim($v)); if (count($prop) == 1 ) { $newprop['BORDER-SPACING-H'] = $prop[0]; $newprop['BORDER-SPACING-V'] = $prop[0]; } else if (count($prop) == 2 ) { $newprop['BORDER-SPACING-H'] = $prop[0]; $newprop['BORDER-SPACING-V'] = $prop[1]; } } else if ($k == 'SIZE') { $prop = preg_split('/\s+/',trim($v)); if (preg_match('/(auto|portrait|landscape)/',$prop[0])) { $newprop['SIZE'] = strtoupper($prop[0]); } else if (count($prop) == 1 ) { $newprop['SIZE']['W'] = $this->ConvertSize($prop[0]); $newprop['SIZE']['H'] = $this->ConvertSize($prop[0]); } else if (count($prop) == 2 ) { $newprop['SIZE']['W'] = $this->ConvertSize($prop[0]); $newprop['SIZE']['H'] = $this->ConvertSize($prop[1]); } } else if ($k == 'SHEET-SIZE') { $prop = preg_split('/\s+/',trim($v)); if (count($prop) == 2 ) { $newprop['SHEET-SIZE'] = array($this->ConvertSize($prop[0]), $this->ConvertSize($prop[1])); } else { if(preg_match('/([0-9a-zA-Z]*)-L/i',$v,$m)) { // e.g. A4-L = A$ landscape $ft = $this->_getPageFormat($m[1]); $format = array($ft[1],$ft[0]); } else { $format = $this->_getPageFormat($v); } if ($format) { $newprop['SHEET-SIZE'] = array($format[0]/_MPDFK, $format[1]/_MPDFK); } } } else if ($k == 'BACKGROUND') { $bg = $this->parseCSSbackground($v); if ($bg['c']) { $newprop['BACKGROUND-COLOR'] = $bg['c']; } else { $newprop['BACKGROUND-COLOR'] = 'transparent'; } /*-- BACKGROUNDS --*/ if ($bg['i']) { $newprop['BACKGROUND-IMAGE'] = $bg['i']; if ($bg['r']) { $newprop['BACKGROUND-REPEAT'] = $bg['r']; } if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; } } else { $newprop['BACKGROUND-IMAGE'] = ''; } /*-- END BACKGROUNDS --*/ } /*-- BACKGROUNDS --*/ else if ($k == 'BACKGROUND-IMAGE') { if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i',$v,$m)) { $newprop['BACKGROUND-IMAGE'] = $m[0]; continue; } if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)/i',$v,$m)) { $newprop['BACKGROUND-IMAGE'] = $m[1]; } else if (strtolower($v)=='none') { $newprop['BACKGROUND-IMAGE'] = ''; } } else if ($k == 'BACKGROUND-REPEAT') { if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/i',$v,$m)) { $newprop['BACKGROUND-REPEAT'] = strtolower($m[1]); } } else if ($k == 'BACKGROUND-POSITION') { $s = $v; $bits = preg_split('/\s+/',trim($s)); // These should be Position x1 or x2 if (count($bits)==1) { if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; } else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; } else { $bg['p'] = $bits[0] . ' 50%'; } } else if (count($bits)==2) { // Can be either right center or center right if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) { $bg['p'] = $bits[1] . ' '.$bits[0]; } else { $bg['p'] = $bits[0] . ' '.$bits[1]; } } if ($bg['p']) { $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']); $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']); $bg['p'] = preg_replace('/(center)/','50%',$bg['p']); if (!preg_match('/[\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)* [\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)*/',$bg['p'])) { $bg['p'] = false; } } if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; } } /*-- END BACKGROUNDS --*/ else if ($k == 'IMAGE-ORIENTATION') { if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i',$v,$m)) { $angle = $m[1] + 0; if (strtolower($m[2])=='deg') { $angle = $angle; } else if (strtolower($m[2])=='grad') { $angle *= (360/400); } else if (strtolower($m[2])=='rad') { $angle = rad2deg($angle); } while($angle < 0) { $angle += 360; } $angle = ($angle % 360); $angle /= 90; $angle = round($angle) * 90; $newprop['IMAGE-ORIENTATION'] = $angle; } } else { $newprop[$k] = $v; } } return $newprop; } // mPDF 5.3.A1 function setCSSboxshadow($v) { $sh = array(); $c = preg_match_all('/(rgba|rgb|cmyka|cmyk|hsla|hsl)\(.*?\)/',$v,$x); for($i=0; $i<$c; $i++) { $col = preg_replace('/,/','*',$x[0][$i]); $v = preg_replace('/'.preg_quote($x[0][$i],'/').'/',$col,$v); } $ss = explode(',',$v); foreach ($ss AS $s) { $new = array('inset'=>false, 'blur'=>0, 'spread'=>0); if (preg_match('/inset/i',$s)) { $new['inset'] = true; $s = preg_replace('/\s*inset\s*/','',$s); } $p = explode(' ',trim($s)); if (isset($p[0])) { $new['x'] = $this->ConvertSize(trim($p[0]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); } if (isset($p[1])) { $new['y'] = $this->ConvertSize(trim($p[1]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); } if (isset($p[2])) { if (preg_match('/^\s*[\.\-0-9]/',$p[2])) { $new['blur'] = $this->ConvertSize(trim($p[2]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); } else { $new['col'] = $this->ConvertColor(preg_replace('/\*/',',',$p[2])); } if (isset($p[3])) { if (preg_match('/^\s*[\.\-0-9]/',$p[3])) { $new['spread'] = $this->ConvertSize(trim($p[3]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); } else { $new['col'] = $this->ConvertColor(preg_replace('/\*/',',',$p[3])); } if (isset($p[4])) { $new['col'] = $this->ConvertColor(preg_replace('/\*/',',',$p[4])); } } } if (!$new['col']) { $new['col'] = $this->ConvertColor('#888888'); } if (isset($new['y'])) { array_unshift($sh, $new); } } return $sh; } // mPDF 5.3.A2 function setCSStextshadow($v) { $sh = array(); $c = preg_match_all('/(rgba|rgb|cmyka|cmyk|hsla|hsl)\(.*?\)/',$v,$x); for($i=0; $i<$c; $i++) { $col = preg_replace('/,/','*',$x[0][$i]); $v = preg_replace('/'.preg_quote($x[0][$i],'/').'/',$col,$v); } $ss = explode(',',$v); foreach ($ss AS $s) { $new = array('blur'=>0); $p = explode(' ',trim($s)); if (isset($p[0])) { $new['x'] = $this->ConvertSize(trim($p[0]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); } if (isset($p[1])) { $new['y'] = $this->ConvertSize(trim($p[1]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); } if (isset($p[2])) { if (preg_match('/^\s*[\.\-0-9]/',$p[2])) { $new['blur'] = $this->ConvertSize(trim($p[2]),$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); } else { $new['col'] = $this->ConvertColor(preg_replace('/\*/',',',$p[2])); } if (isset($p[3])) { $new['col'] = $this->ConvertColor(preg_replace('/\*/',',',$p[3])); } } if (!$new['col']) { $new['col'] = $this->ConvertColor('#888888'); } if (isset($new['y'])) { array_unshift($sh, $new); } } return $sh; } function parseCSSbackground($s) { $bg = array('c'=>false, 'i'=>false, 'r'=>false, 'p'=>false, ); /*-- BACKGROUNDS --*/ if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i',$s,$m)) { $bg['i'] = $m[0]; } else /*-- END BACKGROUNDS --*/ if (preg_match('/url\(/i',$s)) { // If color, set and strip it off if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|(rgba|rgb|cmyka|cmyk|hsla|hsl|spot)\(.*?\)|[a-zA-Z]{3,})\s+(url\(.*)/i',$s,$m)) { // mPDF 5.3.68 $bg['c'] = strtolower($m[1]); $s = $m[3]; // mPDF 5.3.74 } /*-- BACKGROUNDS --*/ if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)\s*(.*)/i',$s,$m)) { $bg['i'] = $m[1]; $s = strtolower($m[2]); if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/',$s,$m)) { $bg['r'] = $m[1]; } // Remove repeat, attachment (discarded) and also any inherit $s = preg_replace('/(repeat-x|repeat-y|no-repeat|repeat|scroll|fixed|inherit)/','',$s); $bits = preg_split('/\s+/',trim($s)); // These should be Position x1 or x2 if (count($bits)==1) { if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; } else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; } else { $bg['p'] = $bits[0] . ' 50%'; } } else if (count($bits)==2) { // Can be either right center or center right if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) { $bg['p'] = $bits[1] . ' '.$bits[0]; } else { $bg['p'] = $bits[0] . ' '.$bits[1]; } } if ($bg['p']) { $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']); $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']); $bg['p'] = preg_replace('/(center)/','50%',$bg['p']); if (!preg_match('/[\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)* [\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)*/',$bg['p'])) { $bg['p'] = false; } } } /*-- END BACKGROUNDS --*/ } else if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|(rgba|rgb|cmyka|cmyk|hsla|hsl|spot)\(.*?\)|[a-zA-Z]{3,})/i',$s,$m)) { $bg['c'] = strtolower($m[1]); } // mPDF 5.3.68 return ($bg); } function expand24($mp) { $prop = preg_split('/\s+/',trim($mp)); if (count($prop) == 1 ) { return array('T' => $prop[0], 'R' => $prop[0], 'B' => $prop[0], 'L'=> $prop[0]); } if (count($prop) == 2 ) { return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[0], 'L'=> $prop[1]); } if (count($prop) == 3 ) { return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[1]); } if (count($prop) == 4 ) { return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[3]); } return array(); } /*-- BORDER-RADIUS --*/ function border_radius_expand($val,$k) { $b = array(); if ($k == 'BORDER-RADIUS') { $hv = explode('/',trim($val)); $prop = preg_split('/\s+/',trim($hv[0])); if (count($prop)==1) { $b['TL-H'] = $b['TR-H'] = $b['BR-H'] = $b['BL-H'] = $prop[0]; } else if (count($prop)==2) { $b['TL-H'] = $b['BR-H'] = $prop[0]; $b['TR-H'] = $b['BL-H'] = $prop[1]; } else if (count($prop)==3) { $b['TL-H'] = $prop[0]; $b['TR-H'] = $b['BL-H'] = $prop[1]; $b['BR-H'] = $prop[2]; } else if (count($prop)==4) { $b['TL-H'] = $prop[0]; $b['TR-H'] = $prop[1]; $b['BR-H'] = $prop[2]; $b['BL-H'] = $prop[3]; } if (count($hv)==2) { $prop = preg_split('/\s+/',trim($hv[1])); if (count($prop)==1) { $b['TL-V'] = $b['TR-V'] = $b['BR-V'] = $b['BL-V'] = $prop[0]; } else if (count($prop)==2) { $b['TL-V'] = $b['BR-V'] = $prop[0]; $b['TR-V'] = $b['BL-V'] = $prop[1]; } else if (count($prop)==3) { $b['TL-V'] = $prop[0]; $b['TR-V'] = $b['BL-V'] = $prop[1]; $b['BR-V'] = $prop[2]; } else if (count($prop)==4) { $b['TL-V'] = $prop[0]; $b['TR-V'] = $prop[1]; $b['BR-V'] = $prop[2]; $b['BL-V'] = $prop[3]; } } else { $b['TL-V'] = $b['TL-H']; $b['TR-V'] = $b['TR-H']; $b['BL-V'] = $b['BL-H']; $b['BR-V'] = $b['BR-H']; } return $b; } // Parse 2 $h = 0; $v = 0; $prop = preg_split('/\s+/',trim($val)); if (count($prop)==1) { $h = $v = $val; } else { $h = $prop[0]; $v = $prop[1]; } if ($h==0 || $v==0) { $h = $v = 0; } if ($k == 'BORDER-TOP-LEFT-RADIUS') { $b['TL-H'] = $h; $b['TL-V'] = $v; } else if ($k == 'BORDER-TOP-RIGHT-RADIUS') { $b['TR-H'] = $h; $b['TR-V'] = $v; } else if ($k == 'BORDER-BOTTOM-LEFT-RADIUS') { $b['BL-H'] = $h; $b['BL-V'] = $v; } else if ($k == 'BORDER-BOTTOM-RIGHT-RADIUS') { $b['BR-H'] = $h; $b['BR-V'] = $v; } return $b; } /*-- END BORDER-RADIUS --*/ /*-- END HTML-CSS --*/ // Return either a number (factor) - based on current set fontsize (if % or em) - or exact lineheight (with 'mm' after it) function fixLineheight($v) { $lh = false; if (preg_match('/^[0-9\.,]*$/',$v) && $v >= 0) { return ($v + 0); } else if (strtoupper($v) == 'NORMAL') { return $this->normalLineheight; } else { $tlh = $this->ConvertSize($v,$this->FontSize,$this->FontSize,true); if ($tlh) { return ($tlh.'mm'); } } return $this->normalLineheight; } /*-- BORDER-RADIUS --*/ function _borderPadding($a, $b, &$px, &$py) { // $px and py are padding long axis (x) and short axis (y) $added = 0; // extra padding $x = $a-$px; $y = $b-$py; // Check if Falls within ellipse of border radius if ( ( (($x+$added)*($x+$added))/($a*$a) + (($y+$added)*($y+$added))/($b*$b) ) <=1 ) { return false; } $t = atan2($y,$x); $newx = $b / sqrt((($b*$b)/($a*$a)) + ( tan($t) * tan($t) ) ); $newy = $a / sqrt((($a*$a)/($b*$b)) + ( (1/tan($t)) * (1/tan($t)) ) ); $px = max($px, $a - $newx + $added); $py = max($py, $b - $newy + $added); } /*-- END BORDER-RADIUS --*/ /*-- TABLES --*/ function setBorderDominance($prop, $val) { if (isset($prop['BORDER-LEFT']) && $prop['BORDER-LEFT']) { $this->cell_border_dominance_L = $val; } if (isset($prop['BORDER-RIGHT']) && $prop['BORDER-RIGHT']) { $this->cell_border_dominance_R = $val; } if (isset($prop['BORDER-TOP']) && $prop['BORDER-TOP']) { $this->cell_border_dominance_T = $val; } if (isset($prop['BORDER-BOTTOM']) && $prop['BORDER-BOTTOM']) { $this->cell_border_dominance_B = $val; } } /*-- END TABLES --*/ /*-- HTML-CSS --*/ function _mergeCSS($p, &$t) { // mPDF 5.3.82 $p changed to &$p // Save Cascading CSS e.g. "div.topic p" at this block level if (isset($p) && $p) { if ($t) { $t = $this->array_merge_recursive_unique($t, $p); // mPDF 5.3.96 } else { $t = $p; } } } // for CSS handling function array_merge_recursive_unique($array1, $array2) { $arrays = func_get_args(); $narrays = count($arrays); $ret = $arrays[0]; for ($i = 1; $i < $narrays; $i ++) { foreach ($arrays[$i] as $key => $value) { if (((string) $key) === ((string) intval($key))) { // integer or string as integer key - append $ret[] = $value; } else { // string key - merge if (is_array($value) && isset($ret[$key])) { $ret[$key] = $this->array_merge_recursive_unique($ret[$key], $value); } else { $ret[$key] = $value; } } } } return $ret; } function _mergeFullCSS($p, &$t, $tag, $classes, $id) { // mPDF 5.3.82 $p changed to &$p $this->_mergeCSS($p[$tag], $t); // STYLESHEET CLASS e.g. .smallone{} .redletter{} foreach($classes AS $class) { $this->_mergeCSS($p['CLASS>>'.$class], $t); } // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1) // mPDF 5.3.82 if ($tag=='TR' && isset($p) && $p) { foreach($p AS $k=>$val) { if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) { $select = false; if ($tag=='TR') { $row = $this->row; // mPDF 5.3.84 $thnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) : 0); $tfnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) : 0); if ($this->tabletfoot) { $row -= $thnr; } else if (!$this->tablethead) { $row -= ($thnr + $tfnr); } if ($m[1]=='ODD' && ($row % 2) == 0) { $select = true; } else if ($m[1]=='EVEN' && ($row % 2) == 1) { $select = true; } else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) { if ((($row + 1) % $a[1]) == $a[2]) { $select = true; } } } else if ($tag=='TD' || $tag=='TH') { if ($m[1]=='ODD' && ($this->col % 2) == 0) { $select = true; } else if ($m[1]=='EVEN' && ($this->col % 2) == 1) { $select = true; } else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) { if ((($this->col + 1) % $a[1]) == $a[2]) { $select = true; } } } if ($select) { $this->_mergeCSS($p[$tag.'>>SELECTORNTHCHILD>>'.$m[1]], $t); } } } } // STYLESHEET CLASS e.g. #smallone{} #redletter{} if (isset($id) && $id) { $this->_mergeCSS($p['ID>>'.$id], $t); } // STYLESHEET CLASS e.g. .smallone{} .redletter{} foreach($classes AS $class) { $this->_mergeCSS($p[$tag.'>>CLASS>>'.$class], $t); } // STYLESHEET CLASS e.g. #smallone{} #redletter{} if (isset($id)) { $this->_mergeCSS($p[$tag.'>>ID>>'.$id], $t); } } function _set_mergedCSS(&$m, &$p, $d=true, $bd=false) { if (isset($m)) { if ((isset($m['depth']) && $m['depth']>1) || $d==false) { // include check for 'depth' if ($bd) { $this->setBorderDominance($m, $bd); } // *TABLES* if (is_array($m)) { $p = array_merge($p,$m); $this->_mergeBorders($p,$m); } } } } function _mergeBorders(&$b, &$a) { // Merges $a['BORDER-TOP-STYLE'] to $b['BORDER-TOP'] etc. foreach(array('TOP','RIGHT','BOTTOM','LEFT') AS $side) { foreach(array('STYLE','WIDTH','COLOR') AS $el) { if (isset($a['BORDER-'.$side.'-'.$el])) { // e.g. $b['BORDER-TOP-STYLE'] $s = trim($a['BORDER-'.$side.'-'.$el]); if (isset($b['BORDER-'.$side])) { // e.g. $b['BORDER-TOP'] $p = trim($b['BORDER-'.$side]); } else { $p = ''; } if ($el=='STYLE') { if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 '.$s.' \\3', $p); } else { $b['BORDER-'.$side] = '0px '.$s.' #000000'; } } else if ($el=='WIDTH') { if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', $s.' \\2 \\3', $p); } else { $b['BORDER-'.$side] = $s.' none #000000'; } } else if ($el=='COLOR') { if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 \\2 '.$s, $p); } else { $b['BORDER-'.$side] = '0px none '.$s; } } } } } } function MergeCSS($inherit,$tag,$attr) { $p = array(); $zp = array(); $classes = array(); if (isset($attr['CLASS'])) { $classes = preg_split('/\s+/',$attr['CLASS']); } if (!isset($attr['ID'])) { $attr['ID']=''; } //=============================================== /*-- TABLES --*/ // Set Inherited properties if ($inherit == 'TOPTABLE') { // $tag = TABLE //=============================================== // Save Cascading CSS e.g. "div.topic p" at this block level if (isset($this->blk[$this->blklvl]['cascadeCSS'])) { $this->tablecascadeCSS[0] = $this->blk[$this->blklvl]['cascadeCSS']; } else { $this->tablecascadeCSS[0] = $this->cascadeCSS; } } //=============================================== // Set Inherited properties if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') { //Cascade everything from last level that is not an actual property, or defined by current tag/attributes if (isset($this->tablecascadeCSS[$this->tbCSSlvl-1]) && is_array($this->tablecascadeCSS[$this->tbCSSlvl-1])) { foreach($this->tablecascadeCSS[$this->tbCSSlvl-1] AS $k=>$v) { $this->tablecascadeCSS[$this->tbCSSlvl][$k] = $v; } } $this->_mergeFullCSS($this->cascadeCSS, $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID']); //=============================================== // Cascading forward CSS e.g. "table.topic td" for this table in $this->tablecascadeCSS //=============================================== // STYLESHEET TAG e.g. table $this->_mergeFullCSS($this->tablecascadeCSS[$this->tbCSSlvl-1], $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID']); //=============================================== } /*-- END TABLES --*/ //=============================================== /*-- LISTS --*/ // Set Inherited properties if ($inherit == 'TOPLIST') { // $tag = UL,OL //=============================================== // Save Cascading CSS e.g. "div.topic p" at this block level if (isset($this->blk[$this->blklvl]['cascadeCSS'])) { $this->listcascadeCSS[0] = $this->blk[$this->blklvl]['cascadeCSS']; } else { $this->listcascadeCSS[0] = $this->cascadeCSS; } } //=============================================== // Set Inherited properties if ($inherit == 'TOPLIST' || $inherit == 'LIST') { //Cascade everything from last level that is not an actual property, or defined by current tag/attributes if (isset($this->listcascadeCSS[$this->listCSSlvl-1]) && is_array($this->listcascadeCSS[$this->listCSSlvl-1])) { foreach($this->listcascadeCSS[$this->listCSSlvl-1] AS $k=>$v) { $this->listcascadeCSS[$this->listCSSlvl][$k] = $v; } } $this->_mergeFullCSS($this->cascadeCSS, $this->listcascadeCSS[$this->listCSSlvl], $tag, $classes, $attr['ID']); //=============================================== // Cascading forward CSS e.g. "table.topic td" for this list in $this->listcascadeCSS //=============================================== // STYLESHEET TAG e.g. table $this->_mergeFullCSS($this->listcascadeCSS[$this->listCSSlvl-1], $this->listcascadeCSS[$this->listCSSlvl], $tag, $classes, $attr['ID']); //=============================================== } /*-- END LISTS --*/ //=============================================== // Set Inherited properties if ($inherit == 'BLOCK') { if (isset($this->blk[$this->blklvl-1]['cascadeCSS']) && is_array($this->blk[$this->blklvl-1]['cascadeCSS'])) { foreach($this->blk[$this->blklvl-1]['cascadeCSS'] AS $k=>$v) { $this->blk[$this->blklvl]['cascadeCSS'][$k] = $v; } } //=============================================== // Save Cascading CSS e.g. "div.topic p" at this block level $this->_mergeFullCSS($this->cascadeCSS, $this->blk[$this->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID']); //=============================================== // Cascading forward CSS //=============================================== $this->_mergeFullCSS($this->blk[$this->blklvl-1]['cascadeCSS'], $this->blk[$this->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID']); //=============================================== // Block properties if (isset($this->blk[$this->blklvl-1]['margin_collapse']) && $this->blk[$this->blklvl-1]['margin_collapse']) { $p['MARGIN-COLLAPSE'] = 'COLLAPSE'; } // custom tag, but follows CSS principle that border-collapse is inherited if (isset($this->blk[$this->blklvl-1]['line_height']) && $this->blk[$this->blklvl-1]['line_height']) { $p['LINE-HEIGHT'] = $this->blk[$this->blklvl-1]['line_height']; } if (isset($this->blk[$this->blklvl-1]['direction']) && $this->blk[$this->blklvl-1]['direction']) { $p['DIRECTION'] = $this->blk[$this->blklvl-1]['direction']; } if (isset($this->blk[$this->blklvl-1]['align']) && $this->blk[$this->blklvl-1]['align']) { if ($this->blk[$this->blklvl-1]['align'] == 'L') { $p['TEXT-ALIGN'] = 'left'; } else if ($this->blk[$this->blklvl-1]['align'] == 'J') { $p['TEXT-ALIGN'] = 'justify'; } else if ($this->blk[$this->blklvl-1]['align'] == 'R') { $p['TEXT-ALIGN'] = 'right'; } else if ($this->blk[$this->blklvl-1]['align'] == 'C') { $p['TEXT-ALIGN'] = 'center'; } } if ($this->ColActive || $this->keep_block_together) { if (isset($this->blk[$this->blklvl-1]['bgcolor']) && $this->blk[$this->blklvl-1]['bgcolor']) { // Doesn't officially inherit, but default value is transparent (?=inherited) $cor = $this->blk[$this->blklvl-1]['bgcolorarray' ]; $p['BACKGROUND-COLOR'] = $this->_colAtoString($cor); } } if (isset($this->blk[$this->blklvl-1]['text_indent']) && ($this->blk[$this->blklvl-1]['text_indent'] || $this->blk[$this->blklvl-1]['text_indent']===0)) { $p['TEXT-INDENT'] = $this->blk[$this->blklvl-1]['text_indent']; } if (isset($this->blk[$this->blklvl-1]['InlineProperties'])) { $biilp = $this->blk[$this->blklvl-1]['InlineProperties']; } else { $biilp = null; } if (isset($biilp[ 'family' ]) && $biilp[ 'family' ]) { $p['FONT-FAMILY'] = $biilp[ 'family' ]; } if (isset($biilp[ 'I' ]) && $biilp[ 'I' ]) { $p['FONT-STYLE'] = 'italic'; } if (isset($biilp[ 'sizePt' ]) && $biilp[ 'sizePt' ]) { $p['FONT-SIZE'] = $biilp[ 'sizePt' ] . 'pt'; } if (isset($biilp[ 'B' ]) && $biilp[ 'B' ]) { $p['FONT-WEIGHT'] = 'bold'; } if (isset($biilp[ 'colorarray' ]) && $biilp[ 'colorarray' ]) { $cor = $biilp[ 'colorarray' ]; $p['COLOR'] = $this->_colAtoString($cor); } if (isset($biilp[ 'fontkerning' ])) { if ($biilp[ 'fontkerning' ]) { $p['FONT-KERNING'] = 'normal'; } else { $p['FONT-KERNING'] = 'none'; } } if (isset($biilp[ 'lSpacingCSS' ]) && $biilp[ 'lSpacingCSS' ]) { $p['LETTER-SPACING'] = $biilp[ 'lSpacingCSS' ]; } if (isset($biilp[ 'wSpacingCSS' ]) && $biilp[ 'wSpacingCSS' ]) { $p['WORD-SPACING'] = $biilp[ 'wSpacingCSS' ]; } if (isset($biilp[ 'toupper' ]) && $biilp[ 'toupper' ]) { $p['TEXT-TRANSFORM'] = 'uppercase'; } else if (isset($biilp[ 'tolower' ]) && $biilp[ 'tolower' ]) { $p['TEXT-TRANSFORM'] = 'lowercase'; } else if (isset($biilp[ 'capitalize' ]) && $biilp[ 'capitalize' ]) { $p['TEXT-TRANSFORM'] = 'capitalize'; } // CSS says text-decoration is not inherited, but IE7 does?? if (isset($biilp[ 'underline' ]) && $biilp[ 'underline' ]) { $p['TEXT-DECORATION'] = 'underline'; } if (isset($biilp[ 'smCaps' ]) && $biilp[ 'smCaps' ]) { $p['FONT-VARIANT'] = 'small-caps'; } } //=============================================== //=============================================== /*-- LISTS --*/ // Set Inherited properties if ($inherit == 'TOPLIST') { if ($this->listCSSlvl == 1) { $bilp = $this->blk[$this->blklvl]['InlineProperties']; if (isset($bilp[ 'family' ]) && $bilp[ 'family' ]) { $p['FONT-FAMILY'] = $bilp[ 'family' ]; } if (isset($bilp[ 'I' ]) && $bilp[ 'I' ]) { $p['FONT-STYLE'] = 'italic'; } if (isset($bilp[ 'sizePt' ]) && $bilp[ 'sizePt' ]) { $p['FONT-SIZE'] = $bilp[ 'sizePt' ] . 'pt'; } if (isset($bilp[ 'B' ]) && $bilp[ 'B' ]) { $p['FONT-WEIGHT'] = 'bold'; } if (isset($bilp[ 'colorarray' ]) && $bilp[ 'colorarray' ]) { $cor = $bilp[ 'colorarray' ]; $p['COLOR'] = $this->_colAtoString($cor); } if (isset($bilp[ 'toupper' ]) && $bilp[ 'toupper' ]) { $p['TEXT-TRANSFORM'] = 'uppercase'; } else if (isset($bilp[ 'tolower' ]) && $bilp[ 'tolower' ]) { $p['TEXT-TRANSFORM'] = 'lowercase'; } else if (isset($bilp[ 'capitalize' ]) && $bilp[ 'capitalize' ]) { $p['TEXT-TRANSFORM'] = 'capitalize'; } if (isset($bilp[ 'fontkerning' ])) { if ($bilp[ 'fontkerning' ]) { $p['FONT-KERNING'] = 'normal'; } else { $p['FONT-KERNING'] = 'none'; } } if (isset($bilp[ 'lSpacingCSS' ]) && $bilp[ 'lSpacingCSS' ]) { $p['LETTER-SPACING'] = $bilp[ 'lSpacingCSS' ]; } if (isset($bilp[ 'wSpacingCSS' ]) && $bilp[ 'wSpacingCSS' ]) { $p['WORD-SPACING'] = $bilp[ 'wSpacingCSS' ]; } // CSS says text-decoration is not inherited, but IE7 does?? if (isset($bilp[ 'underline' ]) && $bilp[ 'underline' ]) { $p['TEXT-DECORATION'] = 'underline'; } if (isset($bilp[ 'smCaps' ]) && $bilp[ 'smCaps' ]) { $p['FONT-VARIANT'] = 'small-caps'; } if ($tag=='LI') { // mPDF 5.3.99 // Note to self - this should never work, as TOPLIST is not called when LI (see code removed in v5.3) $this->Error("If you see this message, please report this as a bug to the mPDF Forum."); } } } /*-- END LISTS --*/ //=============================================== //=============================================== // DEFAULT for this TAG set in DefaultCSS if (isset($this->defaultCSS[$tag])) { $zp = $this->fixCSS($this->defaultCSS[$tag]); if (is_array($zp)) { // Default overwrites Inherited $p = array_merge($p,$zp); // !! Note other way round !! $this->_mergeBorders($p,$zp); } } //=============================================== /*-- TABLES --*/ // cellPadding overwrites TD/TH default but not specific CSS set on cell if (($tag=='TD' || $tag=='TH') && isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding']) && ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'] || $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding']===0)) { $p['PADDING-LEFT'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding']; $p['PADDING-RIGHT'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding']; $p['PADDING-TOP'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding']; $p['PADDING-BOTTOM'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding']; } /*-- END TABLES --*/ //=============================================== // STYLESHEET TAG e.g. h1 p div table if (isset($this->CSS[$tag]) && $this->CSS[$tag]) { $zp = $this->CSS[$tag]; if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS* if (is_array($zp)) { $p = array_merge($p,$zp); $this->_mergeBorders($p,$zp); } } //=============================================== // STYLESHEET CLASS e.g. .smallone{} .redletter{} foreach($classes AS $class) { $zp = array(); if (isset($this->CSS['CLASS>>'.$class]) && $this->CSS['CLASS>>'.$class]) { $zp = $this->CSS['CLASS>>'.$class]; } if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS* if (is_array($zp)) { $p = array_merge($p,$zp); $this->_mergeBorders($p,$zp); } } //=============================================== /*-- TABLES --*/ // mPDF 5.3.82 // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1) if ($tag=='TR' || $tag=='TD' || $tag=='TH') { foreach($this->CSS AS $k=>$val) { if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) { $select = false; if ($tag=='TR') { $row = $this->row; // mPDF 5.3.84 $thnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) : 0); $tfnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) : 0); if ($this->tabletfoot) { $row -= $thnr; } else if (!$this->tablethead) { $row -= ($thnr + $tfnr); } if ($m[1]=='ODD' && ($row % 2) == 0) { $select = true; } else if ($m[1]=='EVEN' && ($row % 2) == 1) { $select = true; } else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) { if ((($row + 1) % $a[1]) == $a[2]) { $select = true; } } } else if ($tag=='TD' || $tag=='TH') { if ($m[1]=='ODD' && ($this->col % 2) == 0) { $select = true; } else if ($m[1]=='EVEN' && ($this->col % 2) == 1) { $select = true; } else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) { if ((($this->col+1) % $a[1]) == $a[2]) { $select = true; } } } if ($select) { $zp = $this->CSS[$tag.'>>SELECTORNTHCHILD>>'.$m[1]]; if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } if (is_array($zp)) { $p = array_merge($p,$zp); $this->_mergeBorders($p,$zp); } } } } } /*-- END TABLES --*/ //=============================================== // STYLESHEET ID e.g. #smallone{} #redletter{} if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']]) && $this->CSS['ID>>'.$attr['ID']]) { $zp = $this->CSS['ID>>'.$attr['ID']]; if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS* if (is_array($zp)) { $p = array_merge($p,$zp); $this->_mergeBorders($p,$zp); } } //=============================================== // STYLESHEET CLASS e.g. p.smallone{} div.redletter{} foreach($classes AS $class) { $zp = array(); if (isset($this->CSS[$tag.'>>CLASS>>'.$class]) && $this->CSS[$tag.'>>CLASS>>'.$class]) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; } if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS* if (is_array($zp)) { $p = array_merge($p,$zp); $this->_mergeBorders($p,$zp); } } //=============================================== // STYLESHEET CLASS e.g. p#smallone{} div#redletter{} if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']]) && $this->CSS[$tag.'>>ID>>'.$attr['ID']]) { $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']]; if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS* if (is_array($zp)) { $p = array_merge($p,$zp); $this->_mergeBorders($p,$zp); } } //=============================================== // Cascaded e.g. div.class p only works for block level if ($inherit == 'BLOCK') { $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS'][$tag], $p); foreach($classes AS $class) { $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS']['CLASS>>'.$class], $p); } $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS']['ID>>'.$attr['ID']], $p); foreach($classes AS $class) { $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p); } $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p); } else if ($inherit == 'INLINE') { $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS'][$tag], $p); foreach($classes AS $class) { $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS']['CLASS>>'.$class], $p); } $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS']['ID>>'.$attr['ID']], $p); foreach($classes AS $class) { $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p); } $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p); } /*-- TABLES --*/ else if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') { // NB looks at $this->tablecascadeCSS-1 for cascading CSS // false, 9 = don't check for 'depth' and do set border dominance $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag], $p, false, 9); foreach($classes AS $class) { $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['CLASS>>'.$class], $p, false, 9); } // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1) // mPDF 5.3.82 if ($tag=='TR' || $tag=='TD' || $tag=='TH') { foreach($this->tablecascadeCSS[$this->tbCSSlvl-1] AS $k=>$val) { if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) { $select = false; if ($tag=='TR') { $row = $this->row; // mPDF 5.3.84 $thnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead']) : 0); $tfnr = (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) ? count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) : 0); if ($this->tabletfoot) { $row -= $thnr; } else if (!$this->tablethead) { $row -= ($thnr + $tfnr); } if ($m[1]=='ODD' && ($row % 2) == 0) { $select = true; } else if ($m[1]=='EVEN' && ($row % 2) == 1) { $select = true; } else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) { if ((($row + 1) % $a[1]) == $a[2]) { $select = true; } } } else if ($tag=='TD' || $tag=='TH') { if ($m[1]=='ODD' && ($this->col % 2) == 0) { $select = true; } else if ($m[1]=='EVEN' && ($this->col % 2) == 1) { $select = true; } else if (preg_match('/(\d+)N\+(\d+)/',$m[1],$a)) { if ((($this->col + 1) % $a[1]) == $a[2]) { $select = true; } } } if ($select) { $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>SELECTORNTHCHILD>>'.$m[1]], $p, false, 9); } } } } $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['ID>>'.$attr['ID']], $p, false, 9); foreach($classes AS $class) { $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>CLASS>>'.$class], $p, false, 9); } $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>ID>>'.$attr['ID']], $p, false, 9); } /*-- END TABLES --*/ //=============================================== /*-- LISTS --*/ else if ($inherit == 'TOPLIST' || $inherit == 'LIST') { // NB looks at $this->listcascadeCSS-1 for cascading CSS // false = don't check for 'depth' $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1][$tag], $p, false); foreach($classes AS $class) { $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1]['CLASS>>'.$class], $p, false); } $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1]['ID>>'.$attr['ID']], $p, false); foreach($classes AS $class) { $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1][$tag.'>>CLASS>>'.$class], $p, false); } $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1][$tag.'>>ID>>'.$attr['ID']], $p, false); } /*-- END LISTS --*/ //=============================================== //=============================================== // INLINE STYLE e.g. style="CSS:property" if (isset($attr['STYLE'])) { $zp = $this->readInlineCSS($attr['STYLE']); if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS* if (is_array($zp)) { $p = array_merge($p,$zp); $this->_mergeBorders($p,$zp); } } //=============================================== //=============================================== // INLINE ATTRIBUTES e.g. .. ALIGN="CENTER"> if (isset($attr['LANG']) and $attr['LANG']!='') { $p['LANG'] = $attr['LANG']; } if (isset($attr['COLOR']) and $attr['COLOR']!='') { $p['COLOR'] = $attr['COLOR']; } if ($tag != 'INPUT') { if (isset($attr['WIDTH']) and $attr['WIDTH']!='') { $p['WIDTH'] = $attr['WIDTH']; } if (isset($attr['HEIGHT']) and $attr['HEIGHT']!='') { $p['HEIGHT'] = $attr['HEIGHT']; } } if ($tag == 'FONT') { if (isset($attr['FACE'])) { $p['FONT-FAMILY'] = $attr['FACE']; } if (isset($attr['SIZE']) and $attr['SIZE']!='') { $s = ''; if ($attr['SIZE'] === '+1') { $s = '120%'; } else if ($attr['SIZE'] === '-1') { $s = '86%'; } else if ($attr['SIZE'] === '1') { $s = 'XX-SMALL'; } else if ($attr['SIZE'] == '2') { $s = 'X-SMALL'; } else if ($attr['SIZE'] == '3') { $s = 'SMALL'; } else if ($attr['SIZE'] == '4') { $s = 'MEDIUM'; } else if ($attr['SIZE'] == '5') { $s = 'LARGE'; } else if ($attr['SIZE'] == '6') { $s = 'X-LARGE'; } else if ($attr['SIZE'] == '7') { $s = 'XX-LARGE'; } if ($s) $p['FONT-SIZE'] = $s; } } if (isset($attr['VALIGN']) and $attr['VALIGN']!='') { $p['VERTICAL-ALIGN'] = $attr['VALIGN']; } if (isset($attr['VSPACE']) and $attr['VSPACE']!='') { $p['MARGIN-TOP'] = $attr['VSPACE']; $p['MARGIN-BOTTOM'] = $attr['VSPACE']; } if (isset($attr['HSPACE']) and $attr['HSPACE']!='') { $p['MARGIN-LEFT'] = $attr['HSPACE']; $p['MARGIN-RIGHT'] = $attr['HSPACE']; } //=============================================== return $p; } /*-- CSS-PAGE --*/ function SetPagedMediaCSS($name='', $first, $oddEven) { if ($oddEven == 'E') { if ($this->directionality=='rtl') { $side = 'R'; } else { $side = 'L'; } } else { if ($this->directionality=='rtl') { $side = 'L'; } else { $side = 'R'; } } $name = strtoupper($name); $p = array(); $p['SIZE'] = 'AUTO'; // Uses mPDF original margins as default $p['MARGIN-RIGHT'] = strval($this->orig_rMargin).'mm'; $p['MARGIN-LEFT'] = strval($this->orig_lMargin).'mm'; $p['MARGIN-TOP'] = strval($this->orig_tMargin).'mm'; $p['MARGIN-BOTTOM'] = strval($this->orig_bMargin).'mm'; $p['MARGIN-HEADER'] = strval($this->orig_hMargin).'mm'; $p['MARGIN-FOOTER'] = strval($this->orig_fMargin).'mm'; // Basic page + selector if (isset($this->CSS['@PAGE'])) { $zp = $this->CSS['@PAGE']; } else { $zp = array(); } if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); } if (isset($p['EVEN-HEADER-NAME']) && $oddEven=='E') { $p['HEADER'] = $p['EVEN-HEADER-NAME']; unset($p['EVEN-HEADER-NAME']); } if (isset($p['ODD-HEADER-NAME']) && $oddEven!='E') { $p['HEADER'] = $p['ODD-HEADER-NAME']; unset($p['ODD-HEADER-NAME']); } if (isset($p['EVEN-FOOTER-NAME']) && $oddEven=='E') { $p['FOOTER'] = $p['EVEN-FOOTER-NAME']; unset($p['EVEN-FOOTER-NAME']); } if (isset($p['ODD-FOOTER-NAME']) && $oddEven!='E') { $p['FOOTER'] = $p['ODD-FOOTER-NAME']; unset($p['ODD-FOOTER-NAME']); } // If right/Odd page if (isset($this->CSS['@PAGE>>PSEUDO>>RIGHT']) && $side=='R') { $zp = $this->CSS['@PAGE>>PSEUDO>>RIGHT']; } else { $zp = array(); } if (isset($zp['SIZE'])) { unset($zp['SIZE']); } if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); } // Disallow margin-left or -right on :LEFT or :RIGHT if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); } if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); } if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); } // If left/Even page if (isset($this->CSS['@PAGE>>PSEUDO>>LEFT']) && $side=='L') { $zp = $this->CSS['@PAGE>>PSEUDO>>LEFT']; } else { $zp = array(); } if (isset($zp['SIZE'])) { unset($zp['SIZE']); } if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); } // Disallow margin-left or -right on :LEFT or :RIGHT if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); } if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); } if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); } // If first page if (isset($this->CSS['@PAGE>>PSEUDO>>FIRST']) && $first) { $zp = $this->CSS['@PAGE>>PSEUDO>>FIRST']; } else { $zp = array(); } if (isset($zp['SIZE'])) { unset($zp['SIZE']); } if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); } if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); } // If named page if ($name) { if (isset($this->CSS['@PAGE>>NAMED>>'.$name])) { $zp = $this->CSS['@PAGE>>NAMED>>'.$name]; } else { $zp = array(); } if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); } if (isset($p['EVEN-HEADER-NAME']) && $oddEven=='E') { $p['HEADER'] = $p['EVEN-HEADER-NAME']; unset($p['EVEN-HEADER-NAME']); } if (isset($p['ODD-HEADER-NAME']) && $oddEven!='E') { $p['HEADER'] = $p['ODD-HEADER-NAME']; unset($p['ODD-HEADER-NAME']); } if (isset($p['EVEN-FOOTER-NAME']) && $oddEven=='E') { $p['FOOTER'] = $p['EVEN-FOOTER-NAME']; unset($p['EVEN-FOOTER-NAME']); } if (isset($p['ODD-FOOTER-NAME']) && $oddEven!='E') { $p['FOOTER'] = $p['ODD-FOOTER-NAME']; unset($p['ODD-FOOTER-NAME']); } // If named right/Odd page if (isset($this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>RIGHT']) && $side=='R') { $zp = $this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>RIGHT']; } else { $zp = array(); } if (isset($zp['SIZE'])) { unset($zp['SIZE']); } if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); } // Disallow margin-left or -right on :LEFT or :RIGHT if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); } if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); } if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); } // If named left/Even page if (isset($this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>LEFT']) && $side=='L') { $zp = $this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>LEFT']; } else { $zp = array(); } if (isset($zp['SIZE'])) { unset($zp['SIZE']); } if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); } // Disallow margin-left or -right on :LEFT or :RIGHT if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); } if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); } if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); } // If named first page if (isset($this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>FIRST']) && $first) { $zp = $this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>FIRST']; } else { $zp = array(); } if (isset($zp['SIZE'])) { unset($zp['SIZE']); } if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); } if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); } } $orientation = $mgl = $mgr = $mgt = $mgb = $mgh = $mgf = ''; $header = $footer = ''; $resetpagenum = $pagenumstyle = $suppress = ''; $marks = ''; $bg = array(); $newformat = ''; if (isset($p['SHEET-SIZE']) && is_array($p['SHEET-SIZE'])) { $newformat = $p['SHEET-SIZE']; if ($newformat[0] > $newformat[1]) { // landscape $newformat = array_reverse($newformat); $p['ORIENTATION'] = 'L'; } else { $p['ORIENTATION'] = 'P'; } $this->_setPageSize($newformat, $p['ORIENTATION']); } if (isset($p['SIZE']) && is_array($p['SIZE']) && !$newformat) { if ($p['SIZE']['W'] > $p['SIZE']['H']) { $p['ORIENTATION'] = 'L'; } else { $p['ORIENTATION'] = 'P'; } } if (is_array($p['SIZE'])) { if ($p['SIZE']['W'] > $this->fw) { $p['SIZE']['W'] = $this->fw; } // mPD 4.2 use fw not fPt if ($p['SIZE']['H'] > $this->fh) { $p['SIZE']['H'] = $this->fh; } if (($p['ORIENTATION']==$this->DefOrientation && !$newformat) || ($newformat && $p['ORIENTATION']=='P')) { $outer_width_LR = ($this->fw - $p['SIZE']['W'])/2; $outer_width_TB = ($this->fh - $p['SIZE']['H'])/2; } else { $outer_width_LR = ($this->fh - $p['SIZE']['W'])/2; $outer_width_TB = ($this->fw - $p['SIZE']['H'])/2; } $pgw = $p['SIZE']['W']; $pgh = $p['SIZE']['H']; } else { // AUTO LANDSCAPE PORTRAIT $outer_width_LR = 0; $outer_width_TB = 0; if (!$newformat) { if (strtoupper($p['SIZE']) == 'AUTO') { $p['ORIENTATION']=$this->DefOrientation; } else if (strtoupper($p['SIZE']) == 'LANDSCAPE') { $p['ORIENTATION']='L'; } else { $p['ORIENTATION']='P'; } } if (($p['ORIENTATION']==$this->DefOrientation && !$newformat) || ($newformat && $p['ORIENTATION']=='P')) { $pgw = $this->fw; $pgh = $this->fh; } else { $pgw = $this->fh; $pgh = $this->fw; } } if (isset($p['HEADER']) && $p['HEADER']) { $header = $p['HEADER']; } if (isset($p['FOOTER']) && $p['FOOTER']) { $footer = $p['FOOTER']; } if (isset($p['RESETPAGENUM']) && $p['RESETPAGENUM']) { $resetpagenum = $p['RESETPAGENUM']; } if (isset($p['PAGENUMSTYLE']) && $p['PAGENUMSTYLE']) { $pagenumstyle = $p['PAGENUMSTYLE']; } if (isset($p['SUPPRESS']) && $p['SUPPRESS']) { $suppress = $p['SUPPRESS']; } if (preg_match('/cross/i', $p['MARKS']) && preg_match('/crop/i', $p['MARKS'])) { $marks = 'CROPCROSS'; } else if (strtoupper($p['MARKS']) == 'CROP') { $marks = 'CROP'; } else if (strtoupper($p['MARKS']) == 'CROSS') { $marks = 'CROSS'; } if (isset($p['BACKGROUND-COLOR']) && $p['BACKGROUND-COLOR']) { $bg['BACKGROUND-COLOR'] = $p['BACKGROUND-COLOR']; } /*-- BACKGROUNDS --*/ if (isset($p['BACKGROUND-GRADIENT']) && $p['BACKGROUND-GRADIENT']) { $bg['BACKGROUND-GRADIENT'] = $p['BACKGROUND-GRADIENT']; } if (isset($p['BACKGROUND-IMAGE']) && $p['BACKGROUND-IMAGE']) { $bg['BACKGROUND-IMAGE'] = $p['BACKGROUND-IMAGE']; } if (isset($p['BACKGROUND-REPEAT']) && $p['BACKGROUND-REPEAT']) { $bg['BACKGROUND-REPEAT'] = $p['BACKGROUND-REPEAT']; } if (isset($p['BACKGROUND-POSITION']) && $p['BACKGROUND-POSITION']) { $bg['BACKGROUND-POSITION'] = $p['BACKGROUND-POSITION']; } if (isset($p['BACKGROUND-IMAGE-RESIZE']) && $p['BACKGROUND-IMAGE-RESIZE']) { $bg['BACKGROUND-IMAGE-RESIZE'] = $p['BACKGROUND-IMAGE-RESIZE']; } if (isset($p['BACKGROUND-IMAGE-OPACITY'])) { $bg['BACKGROUND-IMAGE-OPACITY'] = $p['BACKGROUND-IMAGE-OPACITY']; } // mPDF 5.3.12 /*-- END BACKGROUNDS --*/ if (isset($p['MARGIN-LEFT'])) { $mgl = $this->ConvertSize($p['MARGIN-LEFT'],$pgw) + $outer_width_LR; } if (isset($p['MARGIN-RIGHT'])) { $mgr = $this->ConvertSize($p['MARGIN-RIGHT'],$pgw) + $outer_width_LR; } if (isset($p['MARGIN-BOTTOM'])) { $mgb = $this->ConvertSize($p['MARGIN-BOTTOM'],$pgh) + $outer_width_TB; } if (isset($p['MARGIN-TOP'])) { $mgt = $this->ConvertSize($p['MARGIN-TOP'],$pgh) + $outer_width_TB; } if (isset($p['MARGIN-HEADER'])) { $mgh = $this->ConvertSize($p['MARGIN-HEADER'],$pgh) + $outer_width_TB; } if (isset($p['MARGIN-FOOTER'])) { $mgf = $this->ConvertSize($p['MARGIN-FOOTER'],$pgh) + $outer_width_TB; } if (isset($p['ORIENTATION']) && $p['ORIENTATION']) { $orientation = $p['ORIENTATION']; } $this->page_box['outer_width_LR'] = $outer_width_LR; // Used in MARKS:crop etc. $this->page_box['outer_width_TB'] = $outer_width_TB; return array($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$header,$footer,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat); } /*-- END CSS-PAGE --*/ function PreviewBlockCSS($tag,$attr) { // Looks ahead from current block level to a new level $p = array(); $zp = array(); $oldcascadeCSS = $this->blk[$this->blklvl]['cascadeCSS']; $classes = array(); if (isset($attr['CLASS'])) { $classes = preg_split('/\s+/',$attr['CLASS']); } //=============================================== // DEFAULT for this TAG set in DefaultCSS if (isset($this->defaultCSS[$tag])) { $zp = $this->fixCSS($this->defaultCSS[$tag]); if (is_array($zp)) { $p = array_merge($zp,$p); } // Inherited overwrites default } // STYLESHEET TAG e.g. h1 p div table if (isset($this->CSS[$tag])) { $zp = $this->CSS[$tag]; if (is_array($zp)) { $p = array_merge($p,$zp); } } // STYLESHEET CLASS e.g. .smallone{} .redletter{} foreach($classes AS $class) { $zp = array(); if (isset($this->CSS['CLASS>>'.$class])) { $zp = $this->CSS['CLASS>>'.$class]; } if (is_array($zp)) { $p = array_merge($p,$zp); } } // STYLESHEET ID e.g. #smallone{} #redletter{} if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']])) { $zp = $this->CSS['ID>>'.$attr['ID']]; if (is_array($zp)) { $p = array_merge($p,$zp); } } // STYLESHEET CLASS e.g. p.smallone{} div.redletter{} foreach($classes AS $class) { $zp = array(); if (isset($this->CSS[$tag.'>>CLASS>>'.$class])) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; } if (is_array($zp)) { $p = array_merge($p,$zp); } } // STYLESHEET CLASS e.g. p#smallone{} div#redletter{} if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']])) { $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']]; if (is_array($zp)) { $p = array_merge($p,$zp); } } //=============================================== // STYLESHEET TAG e.g. div h1 div p $this->_set_mergedCSS($oldcascadeCSS[$tag], $p); // STYLESHEET CLASS e.g. .smallone{} .redletter{} foreach($classes AS $class) { $this->_set_mergedCSS($oldcascadeCSS['CLASS>>'.$class], $p); } // STYLESHEET CLASS e.g. #smallone{} #redletter{} if (isset($attr['ID'])) { $this->_set_mergedCSS($oldcascadeCSS['ID>>'.$attr['ID']], $p); } // STYLESHEET CLASS e.g. div.smallone{} p.redletter{} foreach($classes AS $class) { $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>CLASS>>'.$class], $p); } // STYLESHEET CLASS e.g. div#smallone{} p#redletter{} if (isset($attr['ID'])) { $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>ID>>'.$attr['ID']], $p); } //=============================================== // INLINE STYLE e.g. style="CSS:property" if (isset($attr['STYLE'])) { $zp = $this->readInlineCSS($attr['STYLE']); if (is_array($zp)) { $p = array_merge($p,$zp); } } //=============================================== return $p; } /*-- CSS-FLOAT --*/ // Added mPDF 3.0 Float DIV - CLEAR function ClearFloats($clear, $blklvl=0) { list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($blklvl,true); $end = $currpos = ($this->page*1000 + $this->y); if ($clear == 'BOTH' && ($l_exists || $r_exists)) { $this->pageoutput[$this->page] = array(); $end = max($l_max, $r_max, $currpos); } else if ($clear == 'RIGHT' && $r_exists) { $this->pageoutput[$this->page] = array(); $end = max($r_max, $currpos); } else if ($clear == 'LEFT' && $l_exists ) { $this->pageoutput[$this->page] = array(); $end = max($l_max, $currpos); } else { return; } $old_page = $this->page; $new_page = intval($end/1000); if ($old_page != $new_page) { $s = $this->PrintPageBackgrounds(); // Writes after the marker so not overwritten later by page background etc. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]); $this->pageBackgrounds = array(); $this->page = $new_page; } $this->ResetMargins(); $this->pageoutput[$this->page] = array(); $this->y = (($end*1000) % 1000000)/1000; // mod changes operands to integers before processing } // Added mPDF 3.0 Float DIV function GetFloatDivInfo($blklvl=0,$clear=false) { // If blklvl specified, only returns floats at that level - for ClearFloats $l_exists = false; $r_exists = false; $l_max = 0; $r_max = 0; $l_width = 0; $r_width = 0; if (count($this->floatDivs)) { $currpos = ($this->page*1000 + $this->y); foreach($this->floatDivs AS $f) { if (($clear && $f['blockContext'] == $this->blk[$blklvl]['blockContext']) || (!$clear && $currpos >= $f['startpos'] && $currpos < ($f['endpos']-0.001) && $f['blklvl'] > $blklvl && $f['blockContext'] == $this->blk[$blklvl]['blockContext'])) { if ($f['side']=='L') { $l_exists= true; $l_max = max($l_max, $f['endpos']); $l_width = max($l_width , $f['w']); } if ($f['side']=='R') { $r_exists= true; $r_max = max($r_max, $f['endpos']); $r_width = max($r_width , $f['w']); } } } } return array($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width); } /*-- END CSS-FLOAT --*/ function OpenTag($tag,$attr) { // What this gets: < $tag $attr['WIDTH']="90px" > does not get content here </closeTag here> // Correct tags where HTML specifies optional end tags, // and/or does not allow nesting e.g. P inside P, or if ($this->allow_html_optional_endtags) { if (($tag == 'P' || $tag == 'DIV' || $tag == 'H1' || $tag == 'H2' || $tag == 'H3' || $tag == 'H4' || $tag == 'H5' || $tag == 'H6' || $tag == 'UL' || $tag == 'OL' || $tag == 'TABLE' || $tag=='PRE' || $tag=='FORM' || $tag=='ADDRESS' || $tag=='BLOCKQUOTE' || $tag=='CENTER' || $tag=='DL' || $tag == 'HR' ) && $this->lastoptionaltag == 'P') { $this->CloseTag($this->lastoptionaltag ); } if ($tag == 'DD' && $this->lastoptionaltag == 'DD') { $this->CloseTag($this->lastoptionaltag ); } if ($tag == 'DD' && $this->lastoptionaltag == 'DT') { $this->CloseTag($this->lastoptionaltag ); } if ($tag == 'DT' && $this->lastoptionaltag == 'DD') { $this->CloseTag($this->lastoptionaltag ); } if ($tag == 'DT' && $this->lastoptionaltag == 'DT') { $this->CloseTag($this->lastoptionaltag ); } if ($tag == 'LI' && $this->lastoptionaltag == 'LI') { $this->CloseTag($this->lastoptionaltag ); } if (($tag == 'TD' || $tag == 'TH') && $this->lastoptionaltag == 'TD') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES* if (($tag == 'TD' || $tag == 'TH') && $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES* if ($tag == 'TR' && $this->lastoptionaltag == 'TR') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES* if ($tag == 'TR' && $this->lastoptionaltag == 'TD') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); $this->CloseTag('THEAD'); } // *TABLES* if ($tag == 'TR' && $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); $this->CloseTag('THEAD'); } // *TABLES* if ($tag == 'OPTION' && $this->lastoptionaltag == 'OPTION') { $this->CloseTag($this->lastoptionaltag ); } } $align = array('left'=>'L','center'=>'C','right'=>'R','top'=>'T','text-top'=>'TT','middle'=>'M','baseline'=>'BS','bottom'=>'B','text-bottom'=>'TB','justify'=>'J'); $this->ignorefollowingspaces=false; //Opening tag switch($tag){ case 'DOTTAB': $objattr = array(); $objattr['type'] = 'dottab'; $dots=str_repeat('.', 3)." "; // minimum number of dots $objattr['width'] = $this->GetStringWidth($dots); $objattr['margin_top'] = 0; $objattr['margin_bottom'] = 0; $objattr['margin_left'] = 0; $objattr['margin_right'] = 0; $objattr['height'] = 0; $objattr['colorarray'] = $this->colorarray; $objattr['border_top']['w'] = 0; $objattr['border_bottom']['w'] = 0; $objattr['border_left']['w'] = 0; $objattr['border_right']['w'] = 0; $e = "\xbb\xa4\xactype=dottab,objattr=".serialize($objattr)."\xbb\xa4\xac"; /*-- TABLES --*/ // Output it to buffers if ($this->tableLevel) { if (!isset($this->cell[$this->row][$this->col]['maxs'])) { $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) { $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } $this->cell[$this->row][$this->col]['s'] = 0 ;// reset $this->_saveCellTextBuffer($e); // mPDF 5.3.99 } else { /*-- END TABLES --*/ $this->_saveTextBuffer($e); // mPDF 5.3.99 } // *TABLES* break; case 'PAGEHEADER': case 'PAGEFOOTER': $this->ignorefollowingspaces = true; if ($attr['NAME']) { $pname = $attr['NAME']; } else { $pname = '_default'; } if ($tag=='PAGEHEADER') { $p = &$this->pageheaders[$pname]; } else { $p = &$this->pagefooters[$pname]; } $p['L']=array(); $p['C']=array(); $p['R']=array(); $p['L']['font-style'] = ''; $p['C']['font-style'] = ''; $p['R']['font-style'] = ''; if (isset($attr['CONTENT-LEFT'])) { $p['L']['content'] = $attr['CONTENT-LEFT']; } if (isset($attr['CONTENT-CENTER'])) { $p['C']['content'] = $attr['CONTENT-CENTER']; } if (isset($attr['CONTENT-RIGHT'])) { $p['R']['content'] = $attr['CONTENT-RIGHT']; } if (isset($attr['HEADER-STYLE']) || isset($attr['FOOTER-STYLE'])) { // font-family,size,weight,style,color if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE']); } else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE']); } if (isset($properties['FONT-FAMILY'])) { $p['L']['font-family'] = $properties['FONT-FAMILY']; $p['C']['font-family'] = $properties['FONT-FAMILY']; $p['R']['font-family'] = $properties['FONT-FAMILY']; } if (isset($properties['FONT-SIZE'])) { $p['L']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK; $p['C']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK; $p['R']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK; } if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') { // mPDF 5.3.86 $p['L']['font-style'] = 'B'; $p['C']['font-style'] = 'B'; $p['R']['font-style'] = 'B'; } if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') { // mPDF 5.3.86 $p['L']['font-style'] .= 'I'; $p['C']['font-style'] .= 'I'; $p['R']['font-style'] .= 'I'; } if (isset($properties['COLOR'])) { $p['L']['color'] = $properties['COLOR']; $p['C']['color'] = $properties['COLOR']; $p['R']['color'] = $properties['COLOR']; } } if (isset($attr['HEADER-STYLE-LEFT']) || isset($attr['FOOTER-STYLE-LEFT'])) { if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE-LEFT']); } else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE-LEFT']); } if (isset($properties['FONT-FAMILY'])) { $p['L']['font-family'] = $properties['FONT-FAMILY']; } if (isset($properties['FONT-SIZE'])) { $p['L']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK; } if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') { $p['L']['font-style'] ='B'; } // mPDF 5.3.86 if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') { $p['L']['font-style'] .='I'; } // mPDF 5.3.86 if (isset($properties['COLOR'])) { $p['L']['color'] = $properties['COLOR']; } } if (isset($attr['HEADER-STYLE-CENTER']) || isset($attr['FOOTER-STYLE-CENTER'])) { if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE-CENTER']); } else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE-CENTER']); } if (isset($properties['FONT-FAMILY'])) { $p['C']['font-family'] = $properties['FONT-FAMILY']; } if (isset($properties['FONT-SIZE'])) { $p['C']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK; } if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') { $p['C']['font-style'] = 'B'; } // mPDF 5.3.86 if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') { $p['C']['font-style'] .= 'I'; } // mPDF 5.3.86 if (isset($properties['COLOR'])) { $p['C']['color'] = $properties['COLOR']; } } if (isset($attr['HEADER-STYLE-RIGHT']) || isset($attr['FOOTER-STYLE-RIGHT'])) { if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE-RIGHT']); } else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE-RIGHT']); } if (isset($properties['FONT-FAMILY'])) { $p['R']['font-family'] = $properties['FONT-FAMILY']; } if (isset($properties['FONT-SIZE'])) { $p['R']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * _MPDFK; } if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='bold') { $p['R']['font-style'] = 'B'; } // mPDF 5.3.86 if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='italic') { $p['R']['font-style'] .= 'I'; } // mPDF 5.3.86 if (isset($properties['COLOR'])) { $p['R']['color'] = $properties['COLOR']; } } if (isset($attr['LINE']) && $attr['LINE']) { // 0|1|on|off if ($attr['LINE']=='1' || strtoupper($attr['LINE'])=='ON') { $lineset=1; } else { $lineset=0; } $p['line'] = $lineset; } break; /*-- HTMLHEADERS-FOOTERS --*/ case 'SETHTMLPAGEHEADER': case 'SETHTMLPAGEFOOTER': $this->ignorefollowingspaces = true; if (isset($attr['NAME']) && $attr['NAME']) { $pname = $attr['NAME']; } else { $pname = '_default'; } if (isset($attr['PAGE']) && $attr['PAGE']) { // O|odd|even|E|ALL|[blank] if (strtoupper($attr['PAGE'])=='O' || strtoupper($attr['PAGE'])=='ODD') { $side='odd'; } else if (strtoupper($attr['PAGE'])=='E' || strtoupper($attr['PAGE'])=='EVEN') { $side='even'; } else if (strtoupper($attr['PAGE'])=='ALL') { $side='both'; } else { $side='odd'; } } else { $side='odd'; } if (isset($attr['VALUE']) && $attr['VALUE']) { // -1|1|on|off if ($attr['VALUE']=='1' || strtoupper($attr['VALUE'])=='ON') { $set=1; } else if ($attr['VALUE']=='-1' || strtoupper($attr['VALUE'])=='OFF') { $set=0; } else { $set=1; } } else { $set=1; } if (isset($attr['SHOW-THIS-PAGE']) && $attr['SHOW-THIS-PAGE'] && $tag=='SETHTMLPAGEHEADER') { $write = 1; } else { $write = 0; } if ($side=='odd' || $side=='both') { if ($set && $tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader($this->pageHTMLheaders[$pname],'O',$write); } else if ($set && $tag=='SETHTMLPAGEFOOTER') { $this->SetHTMLFooter($this->pageHTMLfooters[$pname],'O'); } else if ($tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader('','O'); } else { $this->SetHTMLFooter('','O'); } } if ($side=='even' || $side=='both') { if ($set && $tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader($this->pageHTMLheaders[$pname],'E',$write); } else if ($set && $tag=='SETHTMLPAGEFOOTER') { $this->SetHTMLFooter($this->pageHTMLfooters[$pname],'E'); } else if ($tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader('','E'); } else { $this->SetHTMLFooter('','E'); } } break; /*-- END HTMLHEADERS-FOOTERS --*/ case 'SETPAGEHEADER': case 'SETPAGEFOOTER': $this->ignorefollowingspaces = true; if (isset($attr['NAME']) && $attr['NAME']) { $pname = $attr['NAME']; } else { $pname = '_default'; } if (isset($attr['PAGE']) && $attr['PAGE']) { // O|odd|even|E|ALL|[blank] if (strtoupper($attr['PAGE'])=='O' || strtoupper($attr['PAGE'])=='ODD') { $side='odd'; } else if (strtoupper($attr['PAGE'])=='E' || strtoupper($attr['PAGE'])=='EVEN') { $side='even'; } else if (strtoupper($attr['PAGE'])=='ALL') { $side='both'; } else { $side='odd'; } } else { $side='odd'; } if (isset($attr['VALUE']) && $attr['VALUE']) { // -1|1|on|off if ($attr['VALUE']=='1' || strtoupper($attr['VALUE'])=='ON') { $set=1; } else if ($attr['VALUE']=='-1' || strtoupper($attr['VALUE'])=='OFF') { $set=0; } else { $set=1; } } else { $set=1; } if ($side=='odd' || $side=='both') { if ($set && $tag=='SETPAGEHEADER') { $this->headerDetails['odd'] = $this->pageheaders[$pname]; } else if ($set && $tag=='SETPAGEFOOTER') { $this->footerDetails['odd'] = $this->pagefooters[$pname]; } else if ($tag=='SETPAGEHEADER') { $this->headerDetails['odd'] = array(); } else { $this->footerDetails['odd'] = array(); } if (!$this->mirrorMargins || ($this->page)%2!=0) { // ODD if ($tag=='SETPAGEHEADER') { $this->_setAutoHeaderHeight($this->headerDetails['odd'],$this->HTMLHeader); } if ($tag=='SETPAGEFOOTER') { $this->_setAutoFooterHeight($this->footerDetails['odd'],$this->HTMLFooter); } } } if ($side=='even' || $side=='both') { if ($set && $tag=='SETPAGEHEADER') { $this->headerDetails['even'] = $this->pageheaders[$pname]; } else if ($set && $tag=='SETPAGEFOOTER') { $this->footerDetails['even'] = $this->pagefooters[$pname]; } else if ($tag=='SETPAGEHEADER') { $this->headerDetails['even'] = array(); } else { $this->footerDetails['even'] = array(); } if ($this->mirrorMargins && ($this->page)%2==0) { // EVEN if ($tag=='SETPAGEHEADER') { $this->_setAutoHeaderHeight($this->headerDetails['even'],$this->HTMLHeaderE); } if ($tag=='SETPAGEFOOTER') { $this->_setAutoFooterHeight($this->footerDetails['even'],$this->HTMLFooterE); } } } if (isset($attr['SHOW-THIS-PAGE']) && $attr['SHOW-THIS-PAGE'] && $tag=='SETPAGEHEADER') { $this->Header(); } break; /*-- TOC --*/ case 'TOC': //added custom-tag - set Marker for insertion later of ToC if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); } if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); } $this->tocontents->openTagTOC($attr); break; case 'TOCPAGEBREAK': // custom-tag - set Marker for insertion later of ToC AND adds PAGEBREAK if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); } if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); } list($isbreak,$toc_id) = $this->tocontents->openTagTOCPAGEBREAK($attr); if ($isbreak) break; // No break - continues as PAGEBREAK... /*-- END TOC --*/ case 'PAGE_BREAK': //custom-tag case 'PAGEBREAK': //custom-tag case 'NEWPAGE': //custom-tag case 'FORMFEED': //custom-tag $save_blklvl = $this->blklvl; $save_blk = $this->blk; $save_silp = $this->saveInlineProperties(); $save_spanlvl = $this->spanlvl; $save_ilp = $this->InlineProperties; // Close any open block tags for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); } if(!empty($this->textbuffer)) { //Output previously buffered content $this->printbuffer($this->textbuffer); $this->textbuffer=array(); } $this->ignorefollowingspaces = true; $save_cols = false; /*-- COLUMNS --*/ if ($this->ColActive) { $save_cols = true; $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off $this->SetColumns(0); } /*-- END COLUMNS --*/ if (isset($attr['SHEET-SIZE']) && $tag != 'FORMFEED' && !$this->restoreBlockPageBreaks) { // Convert to same types as accepted in initial mPDF() A4, A4-L, or array(w,h) $prop = preg_split('/\s+/',trim($attr['SHEET-SIZE'])); if (count($prop) == 2 ) { $newformat = array($this->ConvertSize($prop[0]), $this->ConvertSize($prop[1])); } else { $newformat = $attr['SHEET-SIZE']; } } else { $newformat = ''; } $mgr = $mgl = $mgt = $mgb = $mgh = $mgf = ''; if (isset($attr['MARGIN-RIGHT'])) { $mgr = $this->ConvertSize($attr['MARGIN-RIGHT'],$this->w,$this->FontSize,false); } if (isset($attr['MARGIN-LEFT'])) { $mgl = $this->ConvertSize($attr['MARGIN-LEFT'],$this->w,$this->FontSize,false); } if (isset($attr['MARGIN-TOP'])) { $mgt = $this->ConvertSize($attr['MARGIN-TOP'],$this->w,$this->FontSize,false); } if (isset($attr['MARGIN-BOTTOM'])) { $mgb = $this->ConvertSize($attr['MARGIN-BOTTOM'],$this->w,$this->FontSize,false); } if (isset($attr['MARGIN-HEADER'])) { $mgh = $this->ConvertSize($attr['MARGIN-HEADER'],$this->w,$this->FontSize,false); } if (isset($attr['MARGIN-FOOTER'])) { $mgf = $this->ConvertSize($attr['MARGIN-FOOTER'],$this->w,$this->FontSize,false); } $ohname = $ehname = $ofname = $efname = ''; if (isset($attr['ODD-HEADER-NAME'])) { $ohname = $attr['ODD-HEADER-NAME']; } if (isset($attr['EVEN-HEADER-NAME'])) { $ehname = $attr['EVEN-HEADER-NAME']; } if (isset($attr['ODD-FOOTER-NAME'])) { $ofname = $attr['ODD-FOOTER-NAME']; } if (isset($attr['EVEN-FOOTER-NAME'])) { $efname = $attr['EVEN-FOOTER-NAME']; } $ohvalue = $ehvalue = $ofvalue = $efvalue = 0; if (isset($attr['ODD-HEADER-VALUE']) && ($attr['ODD-HEADER-VALUE']=='1' || strtoupper($attr['ODD-HEADER-VALUE'])=='ON')) { $ohvalue = 1; } else if (isset($attr['ODD-HEADER-VALUE']) && ($attr['ODD-HEADER-VALUE']=='-1' || strtoupper($attr['ODD-HEADER-VALUE'])=='OFF')) { $ohvalue = -1; } if (isset($attr['EVEN-HEADER-VALUE']) && ($attr['EVEN-HEADER-VALUE']=='1' || strtoupper($attr['EVEN-HEADER-VALUE'])=='ON')) { $ehvalue = 1; } else if (isset($attr['EVEN-HEADER-VALUE']) && ($attr['EVEN-HEADER-VALUE']=='-1' || strtoupper($attr['EVEN-HEADER-VALUE'])=='OFF')) { $ehvalue = -1; } if (isset($attr['ODD-FOOTER-VALUE']) && ($attr['ODD-FOOTER-VALUE']=='1' || strtoupper($attr['ODD-FOOTER-VALUE'])=='ON')) { $ofvalue = 1; } else if (isset($attr['ODD-FOOTER-VALUE']) && ($attr['ODD-FOOTER-VALUE']=='-1' || strtoupper($attr['ODD-FOOTER-VALUE'])=='OFF')) { $ofvalue = -1; } if (isset($attr['EVEN-FOOTER-VALUE']) && ($attr['EVEN-FOOTER-VALUE']=='1' || strtoupper($attr['EVEN-FOOTER-VALUE'])=='ON')) { $efvalue = 1; } else if (isset($attr['EVEN-FOOTER-VALUE']) && ($attr['EVEN-FOOTER-VALUE']=='-1' || strtoupper($attr['EVEN-FOOTER-VALUE'])=='OFF')) { $efvalue = -1; } if (isset($attr['ORIENTATION']) && (strtoupper($attr['ORIENTATION'])=='L' || strtoupper($attr['ORIENTATION'])=='LANDSCAPE')) { $orient = 'L'; } else if (isset($attr['ORIENTATION']) && (strtoupper($attr['ORIENTATION'])=='P' || strtoupper($attr['ORIENTATION'])=='PORTRAIT')) { $orient = 'P'; } else { $orient = $this->CurOrientation; } if (isset($attr['PAGE-SELECTOR']) && $attr['PAGE-SELECTOR']) { $pagesel = $attr['PAGE-SELECTOR']; } else { $pagesel = ''; } $resetpagenum = ''; $pagenumstyle = ''; $suppress = ''; if (isset($attr['RESETPAGENUM'])) { $resetpagenum = $attr['RESETPAGENUM']; } if (isset($attr['PAGENUMSTYLE'])) { $pagenumstyle = $attr['PAGENUMSTYLE']; } if (isset($attr['SUPPRESS'])) { $suppress = $attr['SUPPRESS']; } if ($tag == 'TOCPAGEBREAK') { $type = 'NEXT-ODD'; } else if(isset($attr['TYPE'])) { $type = strtoupper($attr['TYPE']); } else { $type = ''; } if ($type == 'E' || $type == 'EVEN') { $this->AddPage($orient,'E', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); } else if ($type == 'O' || $type == 'ODD') { $this->AddPage($orient,'O', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); } else if ($type == 'NEXT-ODD') { $this->AddPage($orient,'NEXT-ODD', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); } else if ($type == 'NEXT-EVEN') { $this->AddPage($orient,'NEXT-EVEN', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); } else { $this->AddPage($orient,'', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); } /*-- TOC --*/ if ($tag == 'TOCPAGEBREAK') { if ($toc_id) { $this->tocontents->m_TOC[$toc_id]['TOCmark'] = $this->page; } else { $this->tocontents->TOCmark = $this->page; } } /*-- END TOC --*/ /*-- COLUMNS --*/ if ($save_cols) { // Restore columns $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap); } /*-- END COLUMNS --*/ if (($tag == 'FORMFEED' || $this->restoreBlockPagebreaks) && !$this->tableLevel && !$this->listlvl) { $this->blk = $save_blk; // Re-open block tags $t = $this->blk[0]['tag']; $a = $this->blk[0]['attr']; $this->blklvl = 0; for ($b=0; $b<=$save_blklvl;$b++) { $tc = $t; $ac = $a; $t = $this->blk[$b+1]['tag']; $a = $this->blk[$b+1]['attr']; unset($this->blk[$b+1]); $this->OpenTag($tc,$ac); } $this->spanlvl = $save_spanlvl; $this->InlineProperties = $save_ilp; $this->restoreInlineProperties($save_silp); } break; /*-- TOC --*/ case 'TOCENTRY': if (isset($attr['CONTENT']) && $attr['CONTENT']) { $objattr = array(); $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES); $objattr['type'] = 'toc'; if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['toclevel'] = $attr['LEVEL']; } else { $objattr['toclevel'] = 0; } if (isset($attr['NAME']) && $attr['NAME']) { $objattr['toc_id'] = $attr['NAME']; } else { $objattr['toc_id'] = 0; } $e = "\xbb\xa4\xactype=toc,objattr=".serialize($objattr)."\xbb\xa4\xac"; if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES* else { // *TABLES* $this->textbuffer[] = array($e); } // *TABLES* } break; /*-- END TOC --*/ /*-- INDEX --*/ case 'INDEXENTRY': if (isset($attr['CONTENT']) && $attr['CONTENT']) { if (isset($attr['XREF']) && $attr['XREF']) { $this->IndexEntry(htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES),$attr['XREF']); break; } $objattr = array(); $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES); $objattr['type'] = 'indexentry'; $e = "\xbb\xa4\xactype=indexentry,objattr=".serialize($objattr)."\xbb\xa4\xac"; if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES* else { // *TABLES* $this->textbuffer[] = array($e); } // *TABLES* } break; case 'INDEXINSERT': if (isset($attr['FONT-SIZE'])) { $reffontsize = $attr['FONT-SIZE']; } else { $reffontsize = ''; } if (isset($attr['LINE-SPACING']) && $attr['LINE-SPACING']) { $linespacing = $attr['LINE-SPACING']; } else { $linespacing = ''; } if (isset($attr['DIV-FONT-SIZE']) && $attr['DIV-FONT-SIZE']) { $divlettfontsize = $attr['DIV-FONT-SIZE']; } else { $divlettfontsize = ''; } if (isset($attr['FONT']) && $attr['FONT']) { $reffont = $attr['FONT']; } else { $reffont = ''; } if (isset($attr['DIV-FONT']) && $attr['DIV-FONT']) { $divlettfont = $attr['DIV-FONT']; } else { $divlettfont = ''; } if (isset($attr['COLS']) && $attr['COLS']) { $cols = $attr['COLS']; } else { $cols = 1; } if (isset($attr['OFFSET']) && $attr['OFFSET']) { $offset = $attr['OFFSET']; } else { $offset = 3; } if (isset($attr['GAP']) && $attr['GAP']) { $gap = $attr['GAP']; } else { $gap = 5; } if (isset($attr['USEDIVLETTERS']) && (strtoupper($attr['USEDIVLETTERS'])=='OFF' || $attr['USEDIVLETTERS']==-1 || $attr['USEDIVLETTERS']==='0')) { $usedivletters = 0; } else { $usedivletters = 1; } if (isset($attr['LINKS']) && (strtoupper($attr['LINKS'])=='ON' || $attr['LINKS']==1)) { $links = true; } else { $links = false; } $this->CreateIndex($cols, $reffontsize, $linespacing, $offset, $usedivletters, $divlettfontsize, $gap, $reffont,$divlettfont, $links); break; /*-- END INDEX --*/ /*-- WATERMARK --*/ case 'WATERMARKTEXT': if (isset($attr['CONTENT']) && $attr['CONTENT']) { $txt = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES); } else { $txt = ''; } if (isset($attr['ALPHA']) && $attr['ALPHA']>0) { $alpha = $attr['ALPHA']; } else { $alpha = -1; } $this->SetWatermarkText($txt, $alpha); break; case 'WATERMARKIMAGE': if (isset($attr['SRC'])) { $src = $attr['SRC']; } else { $src = ''; } if (isset($attr['ALPHA']) && $attr['ALPHA']>0) { $alpha = $attr['ALPHA']; } else { $alpha = -1; } if (isset($attr['SIZE']) && $attr['SIZE']) { $size = $attr['SIZE']; if (strpos($size,',')) { $size = explode(',',$size); } } else { $size = 'D'; } if (isset($attr['POS']) && $attr['POS']) { $pos = $attr['POS']; if (strpos($pos,',')) { $pos = explode(',',$pos); } } else { $pos = 'P'; } $this->SetWatermarkImage($src, $alpha, $size, $pos); break; /*-- END WATERMARK --*/ /*-- BOOKMARKS --*/ case 'BOOKMARK': if (isset($attr['CONTENT'])) { $objattr = array(); $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES); $objattr['type'] = 'bookmark'; if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['bklevel'] = $attr['LEVEL']; } else { $objattr['bklevel'] = 0; } $e = "\xbb\xa4\xactype=bookmark,objattr=".serialize($objattr)."\xbb\xa4\xac"; if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES* else { // *TABLES* $this->textbuffer[] = array($e); } // *TABLES* } break; /*-- END BOOKMARKS --*/ /*-- ANNOTATIONS --*/ case 'ANNOTATION': //if (isset($attr['CONTENT']) && !$this->writingHTMLheader && !$this->writingHTMLfooter) { // Stops annotations in FixedPos if (isset($attr['CONTENT'])) { $objattr = array(); $objattr['margin_top'] = 0; $objattr['margin_bottom'] = 0; $objattr['margin_left'] = 0; $objattr['margin_right'] = 0; $objattr['width'] = 0; $objattr['height'] = 0; $objattr['border_top']['w'] = 0; $objattr['border_bottom']['w'] = 0; $objattr['border_left']['w'] = 0; $objattr['border_right']['w'] = 0; $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES); $objattr['type'] = 'annot'; $objattr['POPUP'] = ''; } else { break; } if (isset($attr['POS-X'])) { $objattr['POS-X'] = $attr['POS-X']; } else { $objattr['POS-X'] = 0; } if (isset($attr['POS-Y'])) { $objattr['POS-Y'] = $attr['POS-Y']; } else { $objattr['POS-Y'] = 0; } if (isset($attr['ICON'])) { $objattr['ICON'] = $attr['ICON']; } else { $objattr['ICON'] = 'Note'; } if (isset($attr['AUTHOR'])) { $objattr['AUTHOR'] = $attr['AUTHOR']; } else if (isset($attr['TITLE'])) { $objattr['AUTHOR'] = $attr['TITLE']; } else { $objattr['AUTHOR'] = ''; } if (isset($attr['FILE'])) { $objattr['FILE'] = $attr['FILE']; } else { $objattr['FILE'] = ''; } if (isset($attr['SUBJECT'])) { $objattr['SUBJECT'] = $attr['SUBJECT']; } else { $objattr['SUBJECT'] = ''; } if (isset($attr['OPACITY']) && $attr['OPACITY']>0 && $attr['OPACITY']<=1) { $objattr['OPACITY'] = $attr['OPACITY']; } else if ($this->annotMargin) { $objattr['OPACITY'] = 1; } else { $objattr['OPACITY'] = $this->annotOpacity; } if (isset($attr['COLOR'])) { $cor = $this->ConvertColor($attr['COLOR']); if ($cor) { $objattr['COLOR'] = $cor; } else { $objattr['COLOR'] = $this->ConvertColor('yellow'); } } else { $objattr['COLOR'] = $this->ConvertColor('yellow'); } if (isset($attr['POPUP']) && !empty($attr['POPUP'])) { $pop = preg_split('/\s+/',trim($attr['POPUP'])); if (count($pop)>1) { $objattr['POPUP'] = $pop; } else { $objattr['POPUP'] = true; } } $e = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac"; if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES* else { // *TABLES* $this->textbuffer[] = array($e); } // *TABLES* break; /*-- END ANNOTATIONS --*/ /*-- COLUMNS --*/ case 'COLUMNS': //added custom-tag if (isset($attr['COLUMN-COUNT']) && ($attr['COLUMN-COUNT'] || $attr['COLUMN-COUNT']==='0')) { // Close any open block tags for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); } if(!empty($this->textbuffer)) { //Output previously buffered content $this->printbuffer($this->textbuffer); $this->textbuffer=array(); } if (isset($attr['VALIGN']) && $attr['VALIGN']) { if ($attr['VALIGN'] == 'J') { $valign = 'J'; } else { $valign = $align[$attr['VALIGN']]; } } else { $valign = ''; } if (isset($attr['COLUMN-GAP']) && $attr['COLUMN-GAP']) { $this->SetColumns($attr['COLUMN-COUNT'],$valign,$attr['COLUMN-GAP']); } else { $this->SetColumns($attr['COLUMN-COUNT'],$valign); } } $this->ignorefollowingspaces = true; break; case 'COLUMN_BREAK': //custom-tag case 'COLUMNBREAK': //custom-tag case 'NEWCOLUMN': //custom-tag $this->ignorefollowingspaces = true; $this->NewColumn(); $this->ColumnAdjust = false; // disables all column height adjustment for the page. break; /*-- END COLUMNS --*/ case 'BDO': // $this->biDirectional = true; break; case 'TTZ': $this->ttz = true; $this->InlineProperties[$tag] = $this->saveInlineProperties(); $this->setCSS(array('FONT-FAMILY'=>'czapfdingbats','FONT-WEIGHT'=>'normal','FONT-STYLE'=>'normal'),'INLINE'); break; case 'TTS': $this->tts = true; $this->InlineProperties[$tag] = $this->saveInlineProperties(); $this->setCSS(array('FONT-FAMILY'=>'csymbol','FONT-WEIGHT'=>'normal','FONT-STYLE'=>'normal'),'INLINE'); break; case 'TTA': $this->tta = true; $this->InlineProperties[$tag] = $this->saveInlineProperties(); if (in_array($this->FontFamily,$this->mono_fonts)) { $this->setCSS(array('FONT-FAMILY'=>'ccourier'),'INLINE'); } else if (in_array($this->FontFamily,$this->serif_fonts)) { $this->setCSS(array('FONT-FAMILY'=>'ctimes'),'INLINE'); } else { $this->setCSS(array('FONT-FAMILY'=>'chelvetica'),'INLINE'); } break; // INLINE PHRASES OR STYLES case 'SUB': case 'SUP': case 'ACRONYM': case 'BIG': case 'SMALL': case 'INS': case 'S': case 'STRIKE': case 'DEL': case 'STRONG': case 'CITE': case 'Q': case 'EM': case 'B': case 'I': case 'U': case 'SAMP': case 'CODE': case 'KBD': case 'TT': case 'VAR': case 'FONT': case 'SPAN': /*-- ANNOTATIONS --*/ if ($this->title2annots && isset($attr['TITLE'])) { $objattr = array(); $objattr['margin_top'] = 0; $objattr['margin_bottom'] = 0; $objattr['margin_left'] = 0; $objattr['margin_right'] = 0; $objattr['width'] = 0; $objattr['height'] = 0; $objattr['border_top']['w'] = 0; $objattr['border_bottom']['w'] = 0; $objattr['border_left']['w'] = 0; $objattr['border_right']['w'] = 0; $objattr['CONTENT'] = $attr['TITLE']; $objattr['type'] = 'annot'; $objattr['POS-X'] = 0; $objattr['POS-Y'] = 0; $objattr['ICON'] = 'Comment'; $objattr['AUTHOR'] = ''; $objattr['SUBJECT'] = ''; $objattr['OPACITY'] = $this->annotOpacity; $objattr['COLOR'] = $this->ConvertColor('yellow'); $annot = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac"; } /*-- END ANNOTATIONS --*/ if ($tag == 'SPAN') { $this->spanlvl++; $this->InlineProperties['SPAN'][$this->spanlvl] = $this->saveInlineProperties(); if (isset($annot)) { $this->InlineAnnots[$tag][$this->spanlvl] = $annot; } // *ANNOTATIONS* } else { $this->InlineProperties[$tag] = $this->saveInlineProperties(); if (isset($annot)) { $this->InlineAnnots[$tag] = $annot; } // *ANNOTATIONS* } $properties = $this->MergeCSS('INLINE',$tag,$attr); if (!empty($properties)) $this->setCSS($properties,'INLINE'); break; case 'A': if (isset($attr['NAME']) and $attr['NAME'] != '') { $e = ''; /*-- BOOKMARKS --*/ if ($this->anchor2Bookmark) { $objattr = array(); $objattr['CONTENT'] = htmlspecialchars_decode($attr['NAME'],ENT_QUOTES); $objattr['type'] = 'bookmark'; if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['bklevel'] = $attr['LEVEL']; } else { $objattr['bklevel'] = 0; } $e = "\xbb\xa4\xactype=bookmark,objattr=".serialize($objattr)."\xbb\xa4\xac"; } /*-- END BOOKMARKS --*/ if($this->tableLevel) { // *TABLES* $this->_saveCellTextBuffer($e, '', $attr['NAME']); // mPDF 5.3.99 // *TABLES* } // *TABLES* else { // *TABLES* $this->_saveTextBuffer($e, '', $attr['NAME']); // mPDF 5.3.99 //an internal link (adds a space for recognition) } // *TABLES* } if (isset($attr['HREF'])) { $this->InlineProperties['A'] = $this->saveInlineProperties(); $properties = $this->MergeCSS('',$tag,$attr); if (!empty($properties)) $this->setCSS($properties,'INLINE'); $this->HREF=htmlspecialchars_decode(urldecode($attr['HREF'])); // mPDF 5.3.95 } break; case 'BR': // Added mPDF 3.0 Float DIV - CLEAR if (isset($attr['STYLE'])) { $properties = $this->readInlineCSS($attr['STYLE']); if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']),$this->blklvl); } // *CSS-FLOAT* } /*-- TABLES --*/ if($this->tableLevel) { if ($this->blockjustfinished || $this->listjustfinished) { $this->_saveCellTextBuffer("\n"); // mPDF 5.3.99 } $this->_saveCellTextBuffer("\n"); // mPDF 5.3.99 if (!isset($this->cell[$this->row][$this->col]['maxs'])) { $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) { $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } $this->cell[$this->row][$this->col]['s'] = 0 ;// reset } else { /*-- END TABLES --*/ if (count($this->textbuffer)) { $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/ $/','',$this->textbuffer[count($this->textbuffer)-1][0]); } $this->_saveTextBuffer("\n"); // mPDF 5.3.99 } // *TABLES* $this->ignorefollowingspaces = true; $this->blockjustfinished=false; $this->listjustfinished=false; $this->linebreakjustfinished=true; break; // *********** BLOCKS ******************** //NB $outerblocktags = array('DIV','FORM','CENTER','DL'); //NB $innerblocktags = array('P','BLOCKQUOTE','ADDRESS','PRE',''H1','H2','H3','H4','H5','H6','DT','DD'); case 'PRE': $this->ispre=true; // ADDED - Prevents left trim of textbuffer in printbuffer() case 'DIV': case 'FORM': case 'CENTER': case 'BLOCKQUOTE': case 'ADDRESS': case 'CAPTION': // mPDF 5.3.56 case 'P': case 'H1': case 'H2': case 'H3': case 'H4': case 'H5': case 'H6': case 'DL': case 'DT': case 'DD': $p = $this->PreviewBlockCSS($tag,$attr); if(isset($p['DISPLAY']) && strtolower($p['DISPLAY'])=='none') { $this->blklvl++; $this->blk[$this->blklvl]['hide'] = true; return; } // mPDF 5.3.56 if($tag == 'CAPTION') { // position is written in AdjstHTML if (isset($attr['POSITION']) && strtolower($attr['POSITION'])=='bottom') { $divpos = 'B'; } else { $divpos = 'T'; } if (isset($attr['ALIGN']) && strtolower($attr['ALIGN'])=='bottom') { $cappos = 'B'; } else if (isset($p['CAPTION-SIDE']) && strtolower($p['CAPTION-SIDE'])=='bottom') { $cappos = 'B'; } else { $cappos = 'T'; } if (isset($attr['ALIGN'])) { unset($attr['ALIGN']); } // mPDF 5.3.A8 if ($cappos != $divpos) { $this->blklvl++; $this->blk[$this->blklvl]['hide'] = true; return; } } /*-- FORMS --*/ if($tag == 'FORM') { if (isset($attr['METHOD']) && strtolower($attr['METHOD'])=='get') { $this->form->formMethod = 'GET'; } else { $this->form->formMethod = 'POST'; } if (isset($attr['ACTION'])) { $this->form->formAction = $attr['ACTION']; } else { $this->form->formAction = ''; } } /*-- END FORMS --*/ /*-- CSS-POSITION --*/ if ((isset($p['POSITION']) && (strtolower($p['POSITION'])=='fixed' || strtolower($p['POSITION'])=='absolute')) && $this->blklvl==0) { if ($this->inFixedPosBlock) { $this->Error("Cannot nest block with position:fixed or position:absolute"); } $this->inFixedPosBlock = true; return; } /*-- END CSS-POSITION --*/ // Start Block $this->ignorefollowingspaces = true; if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins) { $lastbottommargin = $this->lastblockbottommargin; } else { $lastbottommargin = 0; } $this->lastblockbottommargin = 0; $this->blockjustfinished=false; /*-- LISTS --*/ if ($this->listlvl>0) { return; } /*-- END LISTS --*/ $this->InlineProperties = array(); $this->spanlvl = 0; $this->listjustfinished=false; $this->divbegin=true; $this->linebreakjustfinished=false; /*-- TABLES --*/ if ($this->tableLevel) { // If already something on the line if ($this->cell[$this->row][$this->col]['s'] > 0 && !$this->nestedtablejustfinished ) { $this->_saveCellTextBuffer("\n"); // mPDF 5.3.99 if (!isset($this->cell[$this->row][$this->col]['maxs'])) { $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) { $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } $this->cell[$this->row][$this->col]['s'] = 0 ;// reset } // Cannot set block properties inside table - use Bold to indicate h1-h6 if ($tag == 'CENTER' && $this->tdbegin) { $this->cell[$this->row][$this->col]['a'] = $align['center']; } $this->InlineProperties['BLOCKINTABLE'] = $this->saveInlineProperties(); $properties = $this->MergeCSS('',$tag,$attr); if (!empty($properties)) $this->setCSS($properties,'INLINE'); break; } /*-- END TABLES --*/ if ($tag == 'P' || $tag == 'DT' || $tag == 'DD') { $this->lastoptionaltag = $tag; } // Save current HTML specified optional endtag else { $this->lastoptionaltag = ''; } if ($this->lastblocklevelchange == 1) { $blockstate = 1; } // Top margins/padding only else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding $this->printbuffer($this->textbuffer,$blockstate); $this->textbuffer=array(); // mPDF 5.3.03 $save_blklvl = $this->blklvl; $save_blk = $this->blk; $save_silp = $this->saveInlineProperties(); $save_spanlvl = $this->spanlvl; $save_ilp = $this->InlineProperties; $this->blklvl++; $currblk =& $this->blk[$this->blklvl]; $this->initialiseBlock($currblk); $prevblk =& $this->blk[$this->blklvl-1]; $currblk['tag'] = $tag; $currblk['attr'] = $attr; $this->Reset(); $properties = $this->MergeCSS('BLOCK',$tag,$attr); $pagesel = ''; /*-- CSS-PAGE --*/ if (isset($properties['PAGE'])) { $pagesel = $properties['PAGE']; } /*-- END CSS-PAGE --*/ // If page-box has changed AND/OR PAGE-BREAK-BEFORE $save_cols = false; if (($pagesel && $pagesel != $this->page_box['current']) || (isset($properties['PAGE-BREAK-BEFORE']) && $properties['PAGE-BREAK-BEFORE'])) { if ($this->blklvl>1) { // Close any open block tags for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); } // Output any text left in buffer if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); $this->textbuffer=array(); } } /*-- COLUMNS --*/ if ($this->ColActive) { $save_cols = true; $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off $this->SetColumns(0); } /*-- END COLUMNS --*/ // Must Add new page if changed page properties if (isset($properties['PAGE-BREAK-BEFORE'])) { if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'RIGHT') { $this->AddPage($this->CurOrientation,'NEXT-ODD','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } else if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'LEFT') { $this->AddPage($this->CurOrientation,'NEXT-EVEN','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } else if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'ALWAYS') { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } else if ($this->page_box['current'] != $pagesel) { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } // *CSS-PAGE* } /*-- CSS-PAGE --*/ else if ($pagesel != $this->page_box['current']) { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } /*-- END CSS-PAGE --*/ // if using htmlheaders, the headers need to be rewritten when new page // done by calling WriteHTML() within resethtmlheaders // so block is reset to 0 - now we need to resurrect it // As in WriteHTML() initialising // mPDF 5.3.03 if (!($this->restoreBlockPagebreaks && isset($properties['PAGE-BREAK-BEFORE']) && $properties['PAGE-BREAK-BEFORE'])) { $this->blklvl = 0; $this->lastblocklevelchange = 0; $this->blk = array(); $this->initialiseBlock($this->blk[0]); $this->blk[0]['width'] =& $this->pgwidth; $this->blk[0]['inner_width'] =& $this->pgwidth; $this->blk[0]['blockContext'] = $this->blockContext; $properties = $this->MergeCSS('BLOCK','BODY',''); $this->setCSS($properties,'','BODY'); $this->blklvl++; $currblk =& $this->blk[$this->blklvl]; $prevblk =& $this->blk[$this->blklvl-1]; $this->initialiseBlock($currblk); $currblk['tag'] = $tag; $currblk['attr'] = $attr; $this->Reset(); $properties = $this->MergeCSS('BLOCK',$tag,$attr); } /*-- COLUMNS --*/ if ($save_cols) { // Restore columns $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap); } /*-- END COLUMNS --*/ // mPDF 5.3.03 if ($this->restoreBlockPagebreaks && isset($properties['PAGE-BREAK-BEFORE']) && $properties['PAGE-BREAK-BEFORE']) { $this->blk = $save_blk; // Re-open block tags $t = $this->blk[0]['tag']; $a = $this->blk[0]['attr']; $this->blklvl = 0; for ($b=0; $b<=$save_blklvl;$b++) { $tc = $t; $ac = $a; $t = $this->blk[$b+1]['tag']; $a = $this->blk[$b+1]['attr']; unset($this->blk[$b+1]); $this->OpenTag($tc,$ac); } $this->spanlvl = $save_spanlvl; $this->InlineProperties = $save_ilp; $this->restoreInlineProperties($save_silp); } } if (isset($properties['PAGE-BREAK-INSIDE']) && strtoupper($properties['PAGE-BREAK-INSIDE']) == 'AVOID' && !$this->ColActive && !$this->keep_block_together) { $currblk['keep_block_together'] = 1; $this->kt_y00 = $this->y; $this->kt_p00 = $this->page; $this->keep_block_together = 1; $this->divbuffer = array(); $this->ktLinks = array(); $this->ktAnnots = array(); $this->ktForms = array(); $this->ktBlock = array(); $this->ktReference = array(); $this->ktBMoutlines = array(); $this->_kttoc = array(); } // mPDF 5.3.76 if ($lastbottommargin && isset($properties['MARGIN-TOP']) && $properties['MARGIN-TOP'] && empty($properties['FLOAT'])) { $currblk['lastbottommargin'] = $lastbottommargin; } $this->setCSS($properties,'BLOCK',$tag); //name(id/class/style) found in the CSS array! $currblk['InlineProperties'] = $this->saveInlineProperties(); // mPDF 5.3.42 VISIBILITY if (isset($properties['VISIBILITY'])) { $v = strtolower($properties['VISIBILITY']); if (($v == 'hidden' || $v == 'printonly' || $v == 'screenonly') && $this->visibility=='visible' && !$this->tableLevel) { $currblk['visibility'] = $v; $this->SetVisibility($v); } } if(isset($attr['DIR']) && $attr['DIR']) { $currblk['direction'] = strtolower($attr['DIR']); } if(isset($attr['ALIGN']) && $attr['ALIGN']) { $currblk['block-align'] = $align[strtolower($attr['ALIGN'])]; } if (isset($properties['HEIGHT'])) { $currblk['css_set_height'] = $this->ConvertSize($properties['HEIGHT'],($this->h - $this->tMargin - $this->bMargin),$this->FontSize,false); if (($currblk['css_set_height'] + $this->y) > $this->PageBreakTrigger && $this->y > $this->tMargin+5 && $currblk['css_set_height'] < ($this->h - ($this->tMargin + $this->bMargin))) { $this->AddPage($this->CurOrientation); } } else { $currblk['css_set_height'] = false; } // Added mPDF 3.0 Float DIV if (isset($prevblk['blockContext'])) { $currblk['blockContext'] = $prevblk['blockContext'] ; } // *CSS-FLOAT* if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']), $this->blklvl-1); } // *CSS-FLOAT* $container_w = $prevblk['inner_width']; $bdr = $currblk['border_right']['w']; $bdl = $currblk['border_left']['w']; $pdr = $currblk['padding_right']; $pdl = $currblk['padding_left']; if (isset($currblk['css_set_width'])) { $setwidth = $currblk['css_set_width']; } else { $setwidth = 0; } /*-- CSS-FLOAT --*/ if (isset($properties['FLOAT']) && strtoupper($properties['FLOAT']) == 'RIGHT' && !$this->ColActive) { // Cancel Keep-Block-together $currblk['keep_block_together'] = false; $this->kt_y00 = ''; $this->keep_block_together = 0; $this->blockContext++; $currblk['blockContext'] = $this->blockContext; list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1); // DIV is too narrow for text to fit! $maxw = $container_w - $l_width - $r_width; if (($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) < (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04 // Too narrow to fit - try to move down past L or R float if ($l_max < $r_max && ($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $r_width) && (($container_w - $r_width) - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04 $this->ClearFloats('LEFT', $this->blklvl-1); } else if ($r_max < $l_max && ($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $l_width) && (($container_w - $l_width) - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04 $this->ClearFloats('RIGHT', $this->blklvl-1); } else { $this->ClearFloats('BOTH', $this->blklvl-1); } list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1); } if ($r_exists) { $currblk['margin_right'] += $r_width; } $currblk['float'] = 'R'; $currblk['float_start_y'] = $this->y; if ($currblk['css_set_width']) { $currblk['margin_left'] = $container_w - ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']); $currblk['float_width'] = ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']); } else { // *** If no width set - would need to buffer and keep track of max width, then Right-align if not full width // and do borders and backgrounds - For now - just set to maximum width left if ($l_exists) { $currblk['margin_left'] += $l_width; } $currblk['css_set_width'] = $container_w - ($currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr); $currblk['float_width'] = ($currblk['css_set_width'] + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']); } } else if (isset($properties['FLOAT']) && strtoupper($properties['FLOAT']) == 'LEFT' && !$this->ColActive) { // Cancel Keep-Block-together $currblk['keep_block_together'] = false; $this->kt_y00 = ''; $this->keep_block_together = 0; $this->blockContext++; $currblk['blockContext'] = $this->blockContext; list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1); // DIV is too narrow for text to fit! $maxw = $container_w - $l_width - $r_width; if (($setwidth + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) < (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04 // Too narrow to fit - try to move down past L or R float if ($l_max < $r_max && ($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $r_width) && (($container_w - $r_width) - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04 $this->ClearFloats('LEFT', $this->blklvl-1); } else if ($r_max < $l_max && ($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $l_width) && (($container_w - $l_width) - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04 $this->ClearFloats('RIGHT', $this->blklvl-1); } else { $this->ClearFloats('BOTH', $this->blklvl-1); } list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1); } if ($l_exists) { $currblk['margin_left'] += $l_width; } $currblk['float'] = 'L'; $currblk['float_start_y'] = $this->y; if ($setwidth) { $currblk['margin_right'] = $container_w - ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']); $currblk['float_width'] = ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']); } else { // *** If no width set - would need to buffer and keep track of max width, then Right-align if not full width // and do borders and backgrounds - For now - just set to maximum width left if ($r_exists) { $currblk['margin_right'] += $r_width; } $currblk['css_set_width'] = $container_w - ($currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr); $currblk['float_width'] = ($currblk['css_set_width'] + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']); } } else { // Don't allow overlap - if floats present - adjust padding to avoid overlap with Floats list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1); $maxw = $container_w - $l_width - $r_width; if (($setwidth + $currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_right'] + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) < (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04 // Too narrow to fit - try to move down past L or R float if ($l_max < $r_max && ($setwidth + $currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $r_width) && (($container_w - $r_width) - ($currblk['margin_right'] + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04 $this->ClearFloats('LEFT', $this->blklvl-1); } else if ($r_max < $l_max && ($setwidth + $currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) <= ($container_w - $l_width) && (($container_w - $l_width) - ($currblk['margin_right'] + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04 $this->ClearFloats('RIGHT', $this->blklvl-1); } else { $this->ClearFloats('BOTH', $this->blklvl-1); } list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1); } if ($r_exists) { $currblk['padding_right'] = max(($r_width-$currblk['margin_right']-$bdr), $pdr); } if ($l_exists) { $currblk['padding_left'] = max(($l_width-$currblk['margin_left']-$bdl), $pdl); } } /*-- END CSS-FLOAT --*/ /*-- BORDER-RADIUS --*/ // Automatically increase padding if required for border-radius if ($this->autoPadding && !$this->ColActive && !$this->keep_block_together) { if ($currblk['border_radius_TL_H']>$currblk['padding_left'] && $currblk['border_radius_TL_V']>$currblk['padding_top']) { if ($currblk['border_radius_TL_H']>$currblk['border_radius_TL_V']) { $this->_borderPadding($currblk['border_radius_TL_H'],$currblk['border_radius_TL_V'], $currblk['padding_left'], $currblk['padding_top']); } else { $this->_borderPadding($currblk['border_radius_TL_V'],$currblk['border_radius_TL_H'], $currblk['padding_top'], $currblk['padding_left']); } } if ($currblk['border_radius_TR_H']>$currblk['padding_right'] && $currblk['border_radius_TR_V']>$currblk['padding_top']) { if ($currblk['border_radius_TR_H']>$currblk['border_radius_TR_V']) { $this->_borderPadding($currblk['border_radius_TR_H'],$currblk['border_radius_TR_V'], $currblk['padding_right'], $currblk['padding_top']); } else { $this->_borderPadding($currblk['border_radius_TR_V'],$currblk['border_radius_TR_H'], $currblk['padding_top'], $currblk['padding_right']); } } if ($currblk['border_radius_BL_H']>$currblk['padding_left'] && $currblk['border_radius_BL_V']>$currblk['padding_bottom']) { if ($currblk['border_radius_BL_H']>$currblk['border_radius_BL_V']) { $this->_borderPadding($currblk['border_radius_BL_H'],$currblk['border_radius_BL_V'], $currblk['padding_left'], $currblk['padding_bottom']); } else { $this->_borderPadding($currblk['border_radius_BL_V'],$currblk['border_radius_BL_H'], $currblk['padding_bottom'], $currblk['padding_left']); } } if ($currblk['border_radius_BR_H']>$currblk['padding_right'] && $currblk['border_radius_BR_V']>$currblk['padding_bottom']) { if ($currblk['border_radius_BR_H']>$currblk['border_radius_BR_V']) { $this->_borderPadding($currblk['border_radius_BR_H'],$currblk['border_radius_BR_V'], $currblk['padding_right'], $currblk['padding_bottom']); } else { $this->_borderPadding($currblk['border_radius_BR_V'],$currblk['border_radius_BR_H'], $currblk['padding_bottom'], $currblk['padding_right']); } } } /*-- END BORDER-RADIUS --*/ // Hanging indent - if negative indent: ensure padding is >= indent if(!isset($currblk['text_indent'])) { $currblk['text_indent'] = null; } if(!isset($currblk['inner_width'])) { $currblk['inner_width'] = null; } $cbti = $this->ConvertSize($currblk['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); if ($cbti < 0) { $hangind = -($cbti); if ($currblk['direction'] == 'rtl') { // *RTL* $currblk['padding_right'] = max($currblk['padding_right'],$hangind); // *RTL* } // *RTL* else { // *RTL* $currblk['padding_left'] = max($currblk['padding_left'],$hangind); } // *RTL* } if (isset($currblk['css_set_width'])) { if (isset($properties['MARGIN-LEFT']) && isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-LEFT'])=='auto' && strtolower($properties['MARGIN-RIGHT'])=='auto') { // Try to reduce margins to accomodate - if still too wide, set margin-right/left=0 (reduces width) $anyextra = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right']); if ($anyextra>0) { $currblk['margin_left'] = $currblk['margin_right'] = $anyextra /2; } else { $currblk['margin_left'] = $currblk['margin_right'] = 0; } } else if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') { // Try to reduce margin-left to accomodate - if still too wide, set margin-left=0 (reduces width) $currblk['margin_left'] = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right'] + $currblk['margin_right']); if ($currblk['margin_left'] < 0) { $currblk['margin_left'] = 0; } } else if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') { // Try to reduce margin-right to accomodate - if still too wide, set margin-right=0 (reduces width) $currblk['margin_right'] = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right'] + $currblk['margin_left']); if ($currblk['margin_right'] < 0) { $currblk['margin_right'] = 0; } } else { if ($currblk['direction'] == 'rtl') { // *RTL* // Try to reduce margin-left to accomodate - if still too wide, set margin-left=0 (reduces width) $currblk['margin_left'] = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right'] + $currblk['margin_right']); // *RTL* if ($currblk['margin_left'] < 0) { // *RTL* $currblk['margin_left'] = 0; // *RTL* } // *RTL* } // *RTL* else { // *RTL* // Try to reduce margin-right to accomodate - if still too wide, set margin-right=0 (reduces width) $currblk['margin_right'] = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right'] + $currblk['margin_left']); if ($currblk['margin_right'] < 0) { $currblk['margin_right'] = 0; } } // *RTL* } } $currblk['outer_left_margin'] = $prevblk['outer_left_margin'] + $currblk['margin_left'] + $prevblk['border_left']['w'] + $prevblk['padding_left']; $currblk['outer_right_margin'] = $prevblk['outer_right_margin'] + $currblk['margin_right'] + $prevblk['border_right']['w'] + $prevblk['padding_right']; $currblk['width'] = $this->pgwidth - ($currblk['outer_right_margin'] + $currblk['outer_left_margin']); $currblk['inner_width'] = $currblk['width'] - ($currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right']); // Check DIV is not now too narrow to fit text $mw = 2*$this->GetCharWidth('W',false); // mPDF 5.3.04 if ($currblk['inner_width'] < $mw) { $currblk['padding_left'] = 0; $currblk['padding_right'] = 0; $currblk['border_left']['w'] = 0.2; $currblk['border_right']['w'] = 0.2; $currblk['margin_left'] = 0; $currblk['margin_right'] = 0; $currblk['outer_left_margin'] = $prevblk['outer_left_margin'] + $currblk['margin_left'] + $prevblk['border_left']['w'] + $prevblk['padding_left']; $currblk['outer_right_margin'] = $prevblk['outer_right_margin'] + $currblk['margin_right'] + $prevblk['border_right']['w'] + $prevblk['padding_right']; $currblk['width'] = $this->pgwidth - ($currblk['outer_right_margin'] + $currblk['outer_left_margin']); $currblk['inner_width'] = $this->pgwidth - ($currblk['outer_right_margin'] + $currblk['outer_left_margin'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right']); // if ($currblk['inner_width'] < $mw) { $this->Error("DIV is too narrow for text to fit!"); } } $this->x = $this->lMargin + $currblk['outer_left_margin']; /*-- BACKGROUNDS --*/ if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive && !$this->keep_block_together) { $ret = $this->SetBackground($properties, $currblk['inner_width']); if ($ret) { $currblk['background-image'] = $ret; } } /*-- END BACKGROUNDS --*/ /*-- TABLES --*/ if ($this->use_kwt && isset($attr['KEEP-WITH-TABLE']) && !$this->ColActive && !$this->keep_block_together) { $this->kwt = true; $this->kwt_y0 = $this->y; $this->kwt_x0 = $this->x; $this->kwt_height = 0; $this->kwt_buffer = array(); $this->kwt_Links = array(); $this->kwt_Annots = array(); $this->kwt_moved = false; $this->kwt_saved = false; $this->kwt_Reference = array(); $this->kwt_BMoutlines = array(); $this->kwt_toc = array(); } else { /*-- END TABLES --*/ $this->kwt = false; } // *TABLES* //Save x,y coords in case we need to print borders... $currblk['y0'] = $this->y; $currblk['x0'] = $this->x; $currblk['startpage'] = $this->page; $this->oldy = $this->y; $this->lastblocklevelchange = 1 ; break; case 'HR': // Added mPDF 3.0 Float DIV - CLEAR if (isset($attr['STYLE'])) { $properties = $this->readInlineCSS($attr['STYLE']); if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']),$this->blklvl); } // *CSS-FLOAT* } $this->ignorefollowingspaces = true; $objattr = array(); $objattr['margin_top'] = 0; $objattr['margin_bottom'] = 0; $objattr['margin_left'] = 0; $objattr['margin_right'] = 0; $objattr['width'] = 0; $objattr['height'] = 0; $objattr['border_top']['w'] = 0; $objattr['border_bottom']['w'] = 0; $objattr['border_left']['w'] = 0; $objattr['border_right']['w'] = 0; $properties = $this->MergeCSS('',$tag,$attr); if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top'] = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['WIDTH'])) { $objattr['width'] = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']); } if (isset($properties['TEXT-ALIGN'])) { $objattr['align'] = $align[strtolower($properties['TEXT-ALIGN'])]; } if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') { $objattr['align'] = 'R'; } if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') { $objattr['align'] = 'L'; if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto' && isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') { $objattr['align'] = 'C'; } } if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); } if (isset($properties['HEIGHT'])) { $objattr['linewidth'] = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if(isset($attr['WIDTH']) && $attr['WIDTH'] != '') $objattr['width'] = $this->ConvertSize($attr['WIDTH'],$this->blk[$this->blklvl]['inner_width']); if(isset($attr['ALIGN']) && $attr['ALIGN'] != '') $objattr['align'] = $align[strtolower($attr['ALIGN'])]; if(isset($attr['COLOR']) && $attr['COLOR'] != '') $objattr['color'] = $this->ConvertColor($attr['COLOR']); /*-- TABLES --*/ if ($this->tableLevel) { $objattr['W-PERCENT'] = 100; if (isset($properties['WIDTH']) && stristr($properties['WIDTH'],'%')) { $properties['WIDTH'] += 0; //make "90%" become simply "90" $objattr['W-PERCENT'] = $properties['WIDTH']; } if (isset($attr['WIDTH']) && stristr($attr['WIDTH'],'%')) { $attr['WIDTH'] += 0; //make "90%" become simply "90" $objattr['W-PERCENT'] = $attr['WIDTH']; } } /*-- END TABLES --*/ $objattr['type'] = 'hr'; $objattr['height'] = $objattr['linewidth'] + $objattr['margin_top'] + $objattr['margin_bottom']; $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac"; // Clear properties - tidy up $properties = array(); /*-- TABLES --*/ // Output it to buffers if ($this->tableLevel) { if (!isset($this->cell[$this->row][$this->col]['maxs'])) { $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) { $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } $this->cell[$this->row][$this->col]['s'] = 0 ;// reset $this->_saveCellTextBuffer($e, $this->HREF); // mPDF 5.3.99 } else { /*-- END TABLES --*/ $this->_saveTextBuffer($e, $this->HREF); // mPDF 5.3.99 } // *TABLES* break; /*-- BARCODES --*/ case 'BARCODE': if(isset($attr['CODE']) && $attr['CODE']) { $objattr = array(); $objattr['margin_top'] = 0; $objattr['margin_bottom'] = 0; $objattr['margin_left'] = 0; $objattr['margin_right'] = 0; $objattr['padding_top'] = 0; $objattr['padding_bottom'] = 0; $objattr['padding_left'] = 0; $objattr['padding_right'] = 0; $objattr['width'] = 0; $objattr['height'] = 0; $objattr['border_top']['w'] = 0; $objattr['border_bottom']['w'] = 0; $objattr['border_left']['w'] = 0; $objattr['border_right']['w'] = 0; $objattr['code'] = $attr['CODE']; if(isset($attr['TYPE'])) { $objattr['btype'] = trim(strtoupper($attr['TYPE'])); } else { $objattr['btype'] = 'EAN13'; } // default if (preg_match('/^(EAN13|ISBN|ISSN|EAN8|UPCA|UPCE)P([25])$/',$objattr['btype'],$m)) { $objattr['btype'] = $m[1]; $objattr['bsupp'] = $m[2]; if (preg_match('/^(\S+)\s+(.*)$/',$objattr['code'],$mm)) { $objattr['code'] = $mm[1]; $objattr['bsupp_code'] = $mm[2]; } } else { $objattr['bsupp'] = 0; } if(isset($attr['TEXT']) && $attr['TEXT']==1) { $objattr['showtext'] = 1; } else { $objattr['showtext'] = 0; } if(isset($attr['SIZE']) && $attr['SIZE']>0) { $objattr['bsize'] = $attr['SIZE']; } else { $objattr['bsize'] = 1; } if(isset($attr['HEIGHT']) && $attr['HEIGHT']>0) { $objattr['bheight'] = $attr['HEIGHT']; } else { $objattr['bheight'] = 1; } if(isset($attr['PR']) && $attr['PR']>0) { $objattr['pr_ratio'] = $attr['PR']; } else { $objattr['pr_ratio'] = ''; } $properties = $this->MergeCSS('',$tag,$attr); if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') { return; } if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); } if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); } if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); } if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); } if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; } if (isset($properties['COLOR']) && $properties['COLOR'] != '') { $objattr['color'] = $this->ConvertColor($properties['COLOR']); } else { $objattr['color'] = false; } if (isset($properties['BACKGROUND-COLOR']) && $properties['BACKGROUND-COLOR'] != '') { $objattr['bgcolor'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); } else { $objattr['bgcolor'] = false; } if (!class_exists('PDFBarcode', false)) { include(_MPDF_PATH.'classes/barcode.php'); } $this->barcode = new PDFBarcode(); if ($objattr['btype'] == 'EAN13' || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN' || $objattr['btype'] == 'UPCA' || $objattr['btype'] == 'UPCE' || $objattr['btype'] == 'EAN8') { $code = preg_replace('/\-/','',$objattr['code']); if ($objattr['btype'] == 'ISSN' || $objattr['btype'] == 'ISBN') { $arrcode = $this->barcode->getBarcodeArray($code, 'EAN13'); } else { $arrcode = $this->barcode->getBarcodeArray($code, $objattr['btype'] ); } if ($arrcode === false) { $this->Error('Error in barcode string.'); } if ($objattr['bsupp'] == 2 || $objattr['bsupp'] == 5) { // EAN-2 or -5 Supplement $supparrcode = $this->barcode->getBarcodeArray($objattr['bsupp_code'], 'EAN'.$objattr['bsupp'] ); $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR'] + $supparrcode["maxw"] + $supparrcode['sepM']) * $arrcode['nom-X'] * $objattr['bsize']; } else { $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR']) * $arrcode['nom-X'] * $objattr['bsize']; } $h = $arrcode['nom-H'] * $objattr['bsize'] * $objattr['bheight']; // Add height for ISBN string + margin from top of bars if (($objattr['showtext'] && $objattr['btype'] == 'EAN13') || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN') { $tisbnm = 1.5 * $objattr['bsize']; // Top margin between TOP TEXT (isbn - if shown) & bars $isbn_fontsize = 2.1 * $objattr['bsize']; $h += $isbn_fontsize + $tisbnm ; } } // QR-code else if ($objattr['btype'] == 'QR') { $w = $h = $objattr['bsize']*25; // Factor of 25mm (default) $objattr['errorlevel'] = 'L'; if (isset($attr['ERROR'])) { $objattr['errorlevel'] = $attr['ERROR']; } } else if ($objattr['btype'] == 'IMB' || $objattr['btype'] == 'RM4SCC' || $objattr['btype'] == 'KIX' || $objattr['btype'] == 'POSTNET' || $objattr['btype'] == 'PLANET') { $arrcode = $this->barcode->getBarcodeArray($objattr['code'], $objattr['btype'] ); if ($arrcode === false) { $this->Error('Error in barcode string.'); } $w = ($arrcode["maxw"] * $arrcode['nom-X'] * $objattr['bsize']) + $arrcode['quietL'] + $arrcode['quietR']; $h = ($arrcode['nom-H'] * $objattr['bsize']) + (2*$arrcode['quietTB']); } else if (in_array($objattr['btype'], array('C128A','C128B','C128C','EAN128A','EAN128B','EAN128C','C39','C39+','C39E','C39E+','S25','S25+','I25','I25+','I25B','I25B+','C93','MSI','MSI+','CODABAR','CODE11'))) { $arrcode = $this->barcode->getBarcodeArray($objattr['code'], $objattr['btype'], $objattr['pr_ratio'] ); if ($arrcode === false) { $this->Error('Error in barcode string.'); } $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR']) * $arrcode['nom-X'] * $objattr['bsize']; $h = ((2*$arrcode['lightTB'] * $arrcode['nom-X']) + $arrcode['nom-H']) * $objattr['bsize'] * $objattr['bheight']; } else { break; } $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w']; $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w']; $objattr['type'] = 'barcode'; $objattr['height'] = $h + $extraheight; $objattr['width'] = $w + $extrawidth; $objattr['barcode_height'] = $h; $objattr['barcode_width'] = $w; /*-- CSS-IMAGE-FLOAT --*/ if (!$this->ColActive && !$this->tableLevel && !$this->listlvl && !$this->kwt && !$this->keep_block_together) { if (isset($properties['FLOAT']) && (strtoupper($properties['FLOAT']) == 'RIGHT' || strtoupper($properties['FLOAT']) == 'LEFT')) { $objattr['float'] = substr(strtoupper($properties['FLOAT']),0,1); } } /*-- END CSS-IMAGE-FLOAT --*/ $e = "\xbb\xa4\xactype=barcode,objattr=".serialize($objattr)."\xbb\xa4\xac"; // Clear properties - tidy up $properties = array(); /*-- TABLES --*/ // Output it to buffers if ($this->tableLevel) { $this->_saveCellTextBuffer($e, $this->HREF); // mPDF 5.3.99 $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; } else { /*-- END TABLES --*/ $this->_saveTextBuffer($e, $this->HREF); // mPDF 5.3.99 } // *TABLES* } break; /*-- END BARCODES --*/ // *********** FORM ELEMENTS ******************** /*-- FORMS --*/ case 'SELECT': $this->lastoptionaltag = ''; // Save current HTML specified optional endtag $this->InlineProperties[$tag] = $this->saveInlineProperties(); $properties = $this->MergeCSS('',$tag,$attr); if (isset($properties['FONT-FAMILY'])) { $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false); } if (isset($properties['FONT-SIZE'])) { $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK); $this->SetFontSize($mmsize*_MPDFK,false); } if (isset($attr['SPELLCHECK']) && strtolower($attr['SPELLCHECK'])=='true') { $this->selectoption['SPELLCHECK'] = true; } if (isset($properties['COLOR'])) { $this->selectoption['COLOR'] = $this->ConvertColor($properties['COLOR']); } $this->specialcontent = "type=select"; if(isset($attr['DISABLED'])) { $this->selectoption['DISABLED'] = $attr['DISABLED']; } if(isset($attr['READONLY'])) { $this->selectoption['READONLY'] = $attr['READONLY']; } if(isset($attr['REQUIRED'])) { $this->selectoption['REQUIRED'] = $attr['REQUIRED']; } if(isset($attr['EDITABLE'])) { $this->selectoption['EDITABLE'] = $attr['EDITABLE']; } if(isset($attr['TITLE'])) { $this->selectoption['TITLE'] = $attr['TITLE']; } if(isset($attr['MULTIPLE'])) { $this->selectoption['MULTIPLE'] = $attr['MULTIPLE']; } if(isset($attr['SIZE']) && $attr['SIZE']>1) { $this->selectoption['SIZE'] = $attr['SIZE']; } if ($this->useActiveForms) { if(isset($attr['NAME'])) { $this->selectoption['NAME'] = $attr['NAME']; } if (isset($attr['ONCHANGE'])) { $this->selectoption['ONCHANGE'] = $attr['ONCHANGE']; } } $properties = array(); break; case 'OPTION': $this->lastoptionaltag = 'OPTION'; // Save current HTML specified optional endtag $this->selectoption['ACTIVE'] = true; $this->selectoption['currentSEL'] = false; if (empty($this->selectoption)) { $this->selectoption['MAXWIDTH'] = ''; $this->selectoption['SELECTED'] = ''; } if (isset($attr['SELECTED'])) { $this->selectoption['SELECTED'] = ''; $this->selectoption['currentSEL'] = true; } // mPDF 5.3.46 if(isset($attr['VALUE'])) { $attr['VALUE'] = strcode2utf($attr['VALUE']); $attr['VALUE'] = $this->lesser_entity_decode($attr['VALUE']); // mPDF 5.3.58 if ($this->onlyCoreFonts) $attr['VALUE'] = mb_convert_encoding($attr['VALUE'], $this->mb_enc,'UTF-8'); // mPDF 5.3.58 } $this->selectoption['currentVAL'] = $attr['VALUE']; break; case 'TEXTAREA': $objattr = array(); $objattr['margin_top'] = 0; $objattr['margin_bottom'] = 0; $objattr['margin_left'] = 0; $objattr['margin_right'] = 0; $objattr['width'] = 0; $objattr['height'] = 0; $objattr['border_top']['w'] = 0; $objattr['border_bottom']['w'] = 0; $objattr['border_left']['w'] = 0; $objattr['border_right']['w'] = 0; if(isset($attr['DISABLED'])) { $objattr['disabled'] = true; } if(isset($attr['READONLY'])) { $objattr['readonly'] = true; } if(isset($attr['REQUIRED'])) { $objattr['required'] = true; } if(isset($attr['SPELLCHECK']) && strtolower($attr['SPELLCHECK'])=='true') { $objattr['spellcheck'] = true; } if(isset($attr['TITLE'])) { $objattr['title'] = $attr['TITLE']; } if ($this->onlyCoreFonts) $objattr['title'] = mb_convert_encoding($objattr['title'], $this->mb_enc,'UTF-8'); if ($this->useActiveForms) { if(isset($attr['NAME'])) { $objattr['fieldname'] = $attr['NAME']; } $this->form->form_element_spacing['textarea']['outer']['v'] = 0; $this->form->form_element_spacing['textarea']['inner']['v'] = 0; // mPDF 5.3.25 if (isset($attr['ONCALCULATE'])) { $objattr['onCalculate'] = $attr['ONCALCULATE']; } else if (isset($attr['ONCHANGE'])) { $objattr['onCalculate'] = $attr['ONCHANGE']; } if (isset($attr['ONVALIDATE'])) { $objattr['onValidate'] = $attr['ONVALIDATE']; } if (isset($attr['ONKEYSTROKE'])) { $objattr['onKeystroke'] = $attr['ONKEYSTROKE']; } if (isset($attr['ONFORMAT'])) { $objattr['onFormat'] = $attr['ONFORMAT']; } // mPDF 5.3.37 } $this->InlineProperties[$tag] = $this->saveInlineProperties(); $properties = $this->MergeCSS('',$tag,$attr); if (isset($properties['FONT-FAMILY'])) { $this->SetFont($properties['FONT-FAMILY'],'',0,false); } if (isset($properties['FONT-SIZE'])) { $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK); $this->SetFontSize($mmsize*_MPDFK,false); } if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); } $objattr['fontfamily'] = $this->FontFamily; $objattr['fontsize'] = $this->FontSizePt; if ($this->useActiveForms) { if(isset($attr['ALIGN'])) { $objattr['text_align'] = $align[strtolower($attr['ALIGN'])]; } else if(isset($properties['TEXT-ALIGN'])) { $objattr['text_align'] = $align[strtolower($properties['TEXT-ALIGN'])]; } if (isset($properties['OVERFLOW']) && strtolower($properties['OVERFLOW'])=='hidden') { $objattr['donotscroll'] = true; } if (isset($properties['BORDER-TOP-COLOR'])) { $objattr['border-col'] = $this->ConvertColor($properties['BORDER-TOP-COLOR']); } if (isset($properties['BACKGROUND-COLOR'])) { $objattr['background-col'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); } } $this->SetLineHeight('',$this->form->textarea_lineheight); $formLineHeight = $this->lineheight; $w = 0; $h = 0; if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); if ($properties['VERTICAL-ALIGN']) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; } $colsize = 20; //HTML default value $rowsize = 2; //HTML default value if (isset($attr['COLS'])) $colsize = intval($attr['COLS']); if (isset($attr['ROWS'])) $rowsize = intval($attr['ROWS']); $charsize = $this->GetCharWidth('w',false); // mPDF 5.3.04 if ($w) { $colsize = round(($w-($this->form->form_element_spacing['textarea']['outer']['h']*2)-($this->form->form_element_spacing['textarea']['inner']['h']*2))/$charsize); } if ($h) { $rowsize = round(($h-($this->form->form_element_spacing['textarea']['outer']['v']*2)-($this->form->form_element_spacing['textarea']['inner']['v']*2))/$formLineHeight); } $objattr['type'] = 'textarea'; $objattr['width'] = ($colsize * $charsize) + ($this->form->form_element_spacing['textarea']['outer']['h']*2)+($this->form->form_element_spacing['textarea']['inner']['h']*2); $objattr['height'] = ($rowsize * $formLineHeight) + ($this->form->form_element_spacing['textarea']['outer']['v']*2)+($this->form->form_element_spacing['textarea']['inner']['v']*2); $objattr['rows'] = $rowsize; $objattr['cols'] = $colsize; $this->specialcontent = serialize($objattr); if ($this->tableLevel) { // *TABLES* $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; // *TABLES* } // *TABLES* // Clear properties - tidy up $properties = array(); break; // *********** FORM - INPUT ******************** case 'INPUT': if (!isset($attr['TYPE'])) $attr['TYPE'] == 'TEXT'; $objattr = array(); $objattr['margin_top'] = 0; $objattr['margin_bottom'] = 0; $objattr['margin_left'] = 0; $objattr['margin_right'] = 0; $objattr['width'] = 0; $objattr['height'] = 0; $objattr['border_top']['w'] = 0; $objattr['border_bottom']['w'] = 0; $objattr['border_left']['w'] = 0; $objattr['border_right']['w'] = 0; $objattr['type'] = 'input'; if(isset($attr['DISABLED'])) { $objattr['disabled'] = true; } if(isset($attr['READONLY'])) { $objattr['readonly'] = true; } if(isset($attr['REQUIRED'])) { $objattr['required'] = true; } if(isset($attr['SPELLCHECK']) && strtolower($attr['SPELLCHECK'])=='true') { $objattr['spellcheck'] = true; } if(isset($attr['TITLE'])) { $objattr['title'] = $attr['TITLE']; } else if(isset($attr['ALT'])) { $objattr['title'] = $attr['ALT']; } // mPDF 5.3.46 else $objattr['title'] = ''; $objattr['title'] = strcode2utf($objattr['title']); $objattr['title'] = $this->lesser_entity_decode($objattr['title']); // mPDF 5.3.58 if ($this->onlyCoreFonts) $objattr['title'] = mb_convert_encoding($objattr['title'], $this->mb_enc,'UTF-8'); if ($this->useActiveForms) { if(isset($attr['NAME'])) { $objattr['fieldname'] = $attr['NAME']; } } // mPDF 5.3.46 if(isset($attr['VALUE'])) { $attr['VALUE'] = strcode2utf($attr['VALUE']); $attr['VALUE'] = $this->lesser_entity_decode($attr['VALUE']); // mPDF 5.3.58 if ($this->onlyCoreFonts) $attr['VALUE'] = mb_convert_encoding($attr['VALUE'], $this->mb_enc,'UTF-8'); $objattr['value'] = $attr['VALUE']; } $this->InlineProperties[$tag] = $this->saveInlineProperties(); $properties = $this->MergeCSS('',$tag,$attr); $objattr['vertical-align'] = ''; if (isset($properties['FONT-FAMILY'])) { $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false); } if (isset($properties['FONT-SIZE'])) { $mmsize = $this->ConvertSize($properties['FONT-SIZE'],($this->default_font_size/_MPDFK)); $this->SetFontSize($mmsize*_MPDFK,false); } if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); } $objattr['fontfamily'] = $this->FontFamily; $objattr['fontsize'] = $this->FontSizePt; if ($this->useActiveForms) { if(isset($attr['ALIGN'])) { $objattr['text_align'] = $align[strtolower($attr['ALIGN'])]; } else if(isset($properties['TEXT-ALIGN'])) { $objattr['text_align'] = $align[strtolower($properties['TEXT-ALIGN'])]; } if (isset($properties['BORDER-TOP-COLOR'])) { $objattr['border-col'] = $this->ConvertColor($properties['BORDER-TOP-COLOR']); } if (isset($properties['BACKGROUND-COLOR'])) { $objattr['background-col'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); } } $type = ''; $texto=''; $height = $this->FontSize; $width = 0; $spacesize = $this->GetCharWidth(' ',false); // mPDF 5.3.04 $w = 0; if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']); if ($properties['VERTICAL-ALIGN']) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; } switch(strtoupper($attr['TYPE'])){ case 'HIDDEN': $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces if ($this->useActiveForms) { $this->form->SetFormText( 0, 0, $objattr['fieldname'], $objattr['value'], $objattr['value'], '', 0, '', true ); } if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); } unset($this->InlineProperties[$tag]); break 2; case 'CHECKBOX': //Draw Checkbox $type = 'CHECKBOX'; if (isset($attr['CHECKED'])) { $objattr['checked'] = true; } else { $objattr['checked'] = false; } $width = $this->FontSize; $height = $this->FontSize; break; case 'RADIO': //Draw Radio button $type = 'RADIO'; if (isset($attr['CHECKED'])) $objattr['checked'] = true; $width = $this->FontSize; $height = $this->FontSize; break; /*-- IMAGES-CORE --*/ case 'IMAGE': // Draw an Image button if(isset($attr['SRC'])) { $type = 'IMAGE'; $srcpath = $attr['SRC']; $orig_srcpath = $attr['ORIG_SRC']; // VSPACE and HSPACE converted to margins in MergeCSS if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); } if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); } if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); } if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); } $objattr['padding_top'] = 0; $objattr['padding_bottom'] = 0; $objattr['padding_left'] = 0; $objattr['padding_right'] = 0; if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; } $w = 0; $h = 0; if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']); if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width']); $extraheight = $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w']; $extrawidth = $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w']; // Image file $info=$this->_getImage($srcpath, true, true, $orig_srcpath); if(!$info) { $info = $this->_getImage($this->noImageFile); if ($info) { $srcpath = $this->noImageFile; $w = ($info['w'] * (25.4/$this->dpi)); $h = ($info['h'] * (25.4/$this->dpi)); } } if(!$info) break; if ($info['cs']=='Indexed') { $objattr['Indexed'] = true; } $objattr['file'] = $srcpath; //Default width and height calculation if needed if($w==0 and $h==0) { /*-- IMAGES-WMF --*/ if ($info['type']=='wmf') { // WMF units are twips (1/20pt) // divide by 20 to get points // divide by k to get user units $w = abs($info['w'])/(20*_MPDFK); $h = abs($info['h']) / (20*_MPDFK); } else /*-- END IMAGES-WMF --*/ if ($info['type']=='svg') { // SVG units are pixels $w = abs($info['w'])/_MPDFK; $h = abs($info['h'])/_MPDFK; } else { //Put image at default image dpi $w=($info['w']/_MPDFK) * (72/$this->img_dpi); $h=($info['h']/_MPDFK) * (72/$this->img_dpi); } if (isset($properties['IMAGE-RESOLUTION'])) { if (preg_match('/from-image/i', $properties['IMAGE-RESOLUTION']) && isset($info['set-dpi']) && $info['set-dpi']>0) { $w *= $this->img_dpi / $info['set-dpi']; $h *= $this->img_dpi / $info['set-dpi']; } else if (preg_match('/(\d+)dpi/i', $properties['IMAGE-RESOLUTION'], $m)) { $dpi = $m[1]; if ($dpi > 0) { $w *= $this->img_dpi / $dpi; $h *= $this->img_dpi / $dpi; } } } } // IF WIDTH OR HEIGHT SPECIFIED if($w==0) $w=$h*$info['w']/$info['h']; if($h==0) $h=$w*$info['h']/$info['w']; // Resize to maximum dimensions of page $maxWidth = $this->blk[$this->blklvl]['inner_width']; $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 10) ; if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; } if ($w + $extrawidth > $maxWidth ) { $w = $maxWidth - $extrawidth; $h=$w*$info['h']/$info['w']; } if ($h + $extraheight > $maxHeight ) { $h = $maxHeight - $extraheight; $w=$h*$info['w']/$info['h']; } $height = $h + $extraheight; $width = $w + $extrawidth; $objattr['type'] = 'image'; $objattr['itype'] = $info['type']; $objattr['orig_h'] = $info['h']; $objattr['orig_w'] = $info['w']; /*-- IMAGES-WMF --*/ if ($info['type']=='wmf') { $objattr['wmf_x'] = $info['x']; $objattr['wmf_y'] = $info['y']; } else /*-- END IMAGES-WMF --*/ if ($info['type']=='svg') { $objattr['wmf_x'] = $info['x']; $objattr['wmf_y'] = $info['y']; } $objattr['height'] = $h + $extraheight; $objattr['width'] = $w + $extrawidth; $objattr['image_height'] = $h; $objattr['image_width'] = $w; $objattr['ID'] = $info['i']; $texto = 'X'; if ($this->useActiveForms) { if (isset($attr['ONCLICK'])) { $objattr['onClick'] = $attr['ONCLICK']; } $objattr['type'] = 'input'; $type = 'IMAGE'; } break; } /*-- END IMAGES-CORE --*/ case 'BUTTON': // Draw a button case 'SUBMIT': case 'RESET': $type = strtoupper($attr['TYPE']); if ($type=='IMAGE') { $type = 'BUTTON'; } // src path not found if(isset($attr['NOPRINT'])) { $objattr['noprint'] = true; } // mPDF 5.3.46 if (!isset($attr['VALUE'])) { $objattr['value'] = ucfirst(strtolower($type)); } $texto = " " . $objattr['value'] . " "; $width = $this->GetStringWidth($texto) + ($this->form->form_element_spacing['button']['outer']['h']*2)+($this->form->form_element_spacing['button']['inner']['h']*2); $height = $this->FontSize + ($this->form->form_element_spacing['button']['outer']['v']*2)+($this->form->form_element_spacing['button']['inner']['v']*2); if ($this->useActiveForms) { if (isset($attr['ONCLICK'])) { $objattr['onClick'] = $attr['ONCLICK']; } } break; case 'PASSWORD': case 'TEXT': default: if ($type == '') { $type = 'TEXT'; } if(strtoupper($attr['TYPE'])=='PASSWORD') { $type = 'PASSWORD'; } if (isset($attr['VALUE'])) { if ($type == 'PASSWORD') { $num_stars = mb_strlen($attr['VALUE'],$this->mb_enc ); $texto = str_repeat('*',$num_stars); } else { $texto = $attr['VALUE']; } } $xw = ($this->form->form_element_spacing['input']['outer']['h']*2)+($this->form->form_element_spacing['input']['inner']['h']*2); $xh = ($this->form->form_element_spacing['input']['outer']['v']*2)+($this->form->form_element_spacing['input']['inner']['v']*2); if ($w) { $width = $w + $xw; } else { $width = (20 * $spacesize) + $xw; } // Default width in chars if (isset($attr['SIZE']) and ctype_digit($attr['SIZE']) ) $width = ($attr['SIZE'] * $spacesize) + $xw; $height = $this->FontSize + $xh; if (isset($attr['MAXLENGTH']) and ctype_digit($attr['MAXLENGTH']) ) $objattr['maxlength'] = $attr['MAXLENGTH']; if ($this->useActiveForms) { // mPDF 5.3.25 if (isset($attr['ONCALCULATE'])) { $objattr['onCalculate'] = $attr['ONCALCULATE']; } else if (isset($attr['ONCHANGE'])) { $objattr['onCalculate'] = $attr['ONCHANGE']; } if (isset($attr['ONVALIDATE'])) { $objattr['onValidate'] = $attr['ONVALIDATE']; } if (isset($attr['ONKEYSTROKE'])) { $objattr['onKeystroke'] = $attr['ONKEYSTROKE']; } if (isset($attr['ONFORMAT'])) { $objattr['onFormat'] = $attr['ONFORMAT']; } // mPDF 5.3.37 } break; } $objattr['subtype'] = $type; $objattr['text'] = $texto; $objattr['width'] = $width; $objattr['height'] = $height; $e = "\xbb\xa4\xactype=input,objattr=".serialize($objattr)."\xbb\xa4\xac"; // Clear properties - tidy up $properties = array(); /*-- TABLES --*/ // Output it to buffers if ($this->tableLevel) { $this->_saveCellTextBuffer($e, $this->HREF); // mPDF 5.3.99 $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; } else { /*-- END TABLES --*/ $this->_saveTextBuffer($e, $this->HREF); // mPDF 5.3.99 } // *TABLES* if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); } unset($this->InlineProperties[$tag]); break; // END of INPUT /*-- END FORMS --*/ // *********** GRAPH ******************** case 'JPGRAPH': if (!$this->useGraphs) { break; } if ($attr['TABLE']) { $gid = strtoupper($attr['TABLE']); } else { $gid = '0'; } if (!is_array($this->graphs[$gid]) || count($this->graphs[$gid])==0 ) { break; } include_once(_MPDF_PATH.'graph.php'); $this->graphs[$gid]['attr'] = $attr; if (isset($this->graphs[$gid]['attr']['WIDTH']) && $this->graphs[$gid]['attr']['WIDTH']) { $this->graphs[$gid]['attr']['cWIDTH']=$this->ConvertSize($this->graphs[$gid]['attr']['WIDTH'],$pgwidth); } // mm if (isset($this->graphs[$gid]['attr']['HEIGHT']) && $this->graphs[$gid]['attr']['HEIGHT']) { $this->graphs[$gid]['attr']['cHEIGHT']=$this->ConvertSize($this->graphs[$gid]['attr']['HEIGHT'],$pgwidth); } $graph_img = print_graph($this->graphs[$gid],$this->blk[$this->blklvl]['inner_width']); if ($graph_img) { if(isset($attr['ROTATE'])) { if ($attr['ROTATE']==90 || $attr['ROTATE']==-90) { $tmpw = $graph_img['w']; $graph_img['w']= $graph_img['h']; $graph_img['h']= $tmpw; } } $attr['SRC'] = $graph_img['file']; $attr['WIDTH'] = $graph_img['w']; $attr['HEIGHT'] = $graph_img['h']; } else { break; } // *********** IMAGE ******************** /*-- IMAGES-CORE --*/ case 'IMG': if ($this->progressBar) { $this->UpdateProgressBar(1,'','IMG'); } // *PROGRESS-BAR* $objattr = array(); $objattr['margin_top'] = 0; $objattr['margin_bottom'] = 0; $objattr['margin_left'] = 0; $objattr['margin_right'] = 0; $objattr['padding_top'] = 0; $objattr['padding_bottom'] = 0; $objattr['padding_left'] = 0; $objattr['padding_right'] = 0; $objattr['width'] = 0; $objattr['height'] = 0; $objattr['border_top']['w'] = 0; $objattr['border_bottom']['w'] = 0; $objattr['border_left']['w'] = 0; $objattr['border_right']['w'] = 0; if(isset($attr['SRC'])) { $srcpath = $attr['SRC']; $orig_srcpath = $attr['ORIG_SRC']; $properties = $this->MergeCSS('',$tag,$attr); if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') { return; } // mPDF 5.3.42 VISIBILITY $objattr['visibility'] = 'visible'; if (isset($properties['VISIBILITY'])) { $v = strtolower($properties['VISIBILITY']); if (($v == 'hidden' || $v == 'printonly' || $v == 'screenonly') && $this->visibility=='visible') { $objattr['visibility'] = $v; } } // VSPACE and HSPACE converted to margins in MergeCSS if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); } if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); } if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); } if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); } if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; } $w = 0; $h = 0; if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); if(isset($attr['WIDTH'])) $w = $this->ConvertSize($attr['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); if(isset($attr['HEIGHT'])) $h = $this->ConvertSize($attr['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); if (isset($properties['OPACITY']) && $properties['OPACITY'] > 0 && $properties['OPACITY'] <= 1) { $objattr['opacity'] = $properties['OPACITY']; } if ($this->HREF) { // mPDF 5.3.78 if (strpos($this->HREF,".") === false && strpos($this->HREF,"@") !== 0) { $href = $this->HREF; while(array_key_exists($href,$this->internallink)) $href="#".$href; $this->internallink[$href] = $this->AddLink(); $objattr['link'] = $this->internallink[$href]; } else { $objattr['link'] = $this->HREF; } } $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w']; $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w']; /*-- BACKGROUNDS --*/ if(isset($properties['GRADIENT-MASK']) && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/',$properties['GRADIENT-MASK'])) { $objattr['GRADIENT-MASK'] = $properties['GRADIENT-MASK']; } /*-- END BACKGROUNDS --*/ // Image file $info=$this->_getImage($srcpath, true, true, $orig_srcpath); if(!$info) { $info = $this->_getImage($this->noImageFile); if ($info) { $srcpath = $this->noImageFile; $w = ($info['w'] * (25.4/$this->dpi)); $h = ($info['h'] * (25.4/$this->dpi)); } } if(!$info) break; if(isset($attr['ROTATE'])) { $image_orientation = $attr['ROTATE']; } else if(isset($properties['IMAGE-ORIENTATION'])) { $image_orientation = $properties['IMAGE-ORIENTATION']; } else { $image_orientation = 0; } if($image_orientation) { if ($image_orientation==90 || $image_orientation==-90 || $image_orientation==270) { $tmpw = $info['w']; $info['w'] = $info['h']; $info['h'] = $tmpw; } $objattr['ROTATE'] = $image_orientation; } $objattr['file'] = $srcpath; //Default width and height calculation if needed if($w==0 and $h==0) { /*-- IMAGES-WMF --*/ if ($info['type']=='wmf') { // WMF units are twips (1/20pt) // divide by 20 to get points // divide by k to get user units $w = abs($info['w'])/(20*_MPDFK); $h = abs($info['h']) / (20*_MPDFK); } else /*-- END IMAGES-WMF --*/ if ($info['type']=='svg') { // SVG units are pixels $w = abs($info['w'])/_MPDFK; $h = abs($info['h'])/_MPDFK; } else { //Put image at default image dpi $w=($info['w']/_MPDFK) * (72/$this->img_dpi); $h=($info['h']/_MPDFK) * (72/$this->img_dpi); } if (isset($properties['IMAGE-RESOLUTION'])) { if (preg_match('/from-image/i', $properties['IMAGE-RESOLUTION']) && isset($info['set-dpi']) && $info['set-dpi']>0) { $w *= $this->img_dpi / $info['set-dpi']; $h *= $this->img_dpi / $info['set-dpi']; } else if (preg_match('/(\d+)dpi/i', $properties['IMAGE-RESOLUTION'], $m)) { $dpi = $m[1]; if ($dpi > 0) { $w *= $this->img_dpi / $dpi; $h *= $this->img_dpi / $dpi; } } } } // IF WIDTH OR HEIGHT SPECIFIED if($w==0) $w=abs($h*$info['w']/$info['h']); if($h==0) $h=abs($w*$info['h']/$info['w']); // Resize to maximum dimensions of page $maxWidth = $this->blk[$this->blklvl]['inner_width']; $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 1) ; if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; } if ($w + $extrawidth > $maxWidth ) { $w = $maxWidth - $extrawidth; $h=abs($w*$info['h']/$info['w']); } if ($h + $extraheight > $maxHeight ) { $h = $maxHeight - $extraheight; $w=abs($h*$info['w']/$info['h']); } $objattr['type'] = 'image'; $objattr['itype'] = $info['type']; $objattr['orig_h'] = $info['h']; $objattr['orig_w'] = $info['w']; /*-- IMAGES-WMF --*/ if ($info['type']=='wmf') { $objattr['wmf_x'] = $info['x']; $objattr['wmf_y'] = $info['y']; } else /*-- END IMAGES-WMF --*/ if ($info['type']=='svg') { $objattr['wmf_x'] = $info['x']; $objattr['wmf_y'] = $info['y']; } $objattr['height'] = $h + $extraheight; $objattr['width'] = $w + $extrawidth; $objattr['image_height'] = $h; $objattr['image_width'] = $w; /*-- CSS-IMAGE-FLOAT --*/ if (!$this->ColActive && !$this->tableLevel && !$this->listlvl && !$this->kwt && !$this->keep_block_together) { if (isset($properties['FLOAT']) && (strtoupper($properties['FLOAT']) == 'RIGHT' || strtoupper($properties['FLOAT']) == 'LEFT')) { $objattr['float'] = substr(strtoupper($properties['FLOAT']),0,1); } } /*-- END CSS-IMAGE-FLOAT --*/ $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac"; // Clear properties - tidy up $properties = array(); /*-- TABLES --*/ // Output it to buffers if ($this->tableLevel) { $this->_saveCellTextBuffer($e, $this->HREF); // mPDF 5.3.99 $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; } else { /*-- END TABLES --*/ $this->_saveTextBuffer($e, $this->HREF); // mPDF 5.3.99 } // *TABLES* /*-- ANNOTATIONS --*/ if ($this->title2annots && isset($attr['TITLE'])) { $objattr = array(); $objattr['margin_top'] = 0; $objattr['margin_bottom'] = 0; $objattr['margin_left'] = 0; $objattr['margin_right'] = 0; $objattr['width'] = 0; $objattr['height'] = 0; $objattr['border_top']['w'] = 0; $objattr['border_bottom']['w'] = 0; $objattr['border_left']['w'] = 0; $objattr['border_right']['w'] = 0; $objattr['CONTENT'] = $attr['TITLE']; $objattr['type'] = 'annot'; $objattr['POS-X'] = 0; $objattr['POS-Y'] = 0; $objattr['ICON'] = 'Comment'; $objattr['AUTHOR'] = ''; $objattr['SUBJECT'] = ''; $objattr['OPACITY'] = $this->annotOpacity; $objattr['COLOR'] = $this->ConvertColor('yellow'); $e = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac"; if($this->tableLevel) { // *TABLES* $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); // *TABLES* } // *TABLES* else { // *TABLES* $this->textbuffer[] = array($e); } // *TABLES* } /*-- END ANNOTATIONS --*/ } break; /*-- END IMAGES-CORE --*/ // *********** CIRCULAR TEXT = TEXTCIRCLE ******************** // mPDF 5.3.A5 case 'TEXTCIRCLE': $objattr = array(); $objattr['margin_top'] = 0; $objattr['margin_bottom'] = 0; $objattr['margin_left'] = 0; $objattr['margin_right'] = 0; $objattr['padding_top'] = 0; $objattr['padding_bottom'] = 0; $objattr['padding_left'] = 0; $objattr['padding_right'] = 0; $objattr['width'] = 0; $objattr['height'] = 0; $objattr['border_top']['w'] = 0; $objattr['border_bottom']['w'] = 0; $objattr['border_left']['w'] = 0; $objattr['border_right']['w'] = 0; $objattr['top-text'] = ''; $objattr['bottom-text'] = ''; $objattr['r'] = 20; // radius (default value here for safety) $objattr['space-width'] = 120; $objattr['char-width'] = 100; $this->InlineProperties[$tag] = $this->saveInlineProperties(); $properties = $this->MergeCSS('',$tag,$attr); if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') { return; } if (isset($attr['R'])) { $objattr['r']=$this->ConvertSize($attr['R'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if(isset($attr['TOP-TEXT'])) { $objattr['top-text'] = strcode2utf($attr['TOP-TEXT']); $objattr['top-text'] = $this->lesser_entity_decode($objattr['top-text']); if ($this->onlyCoreFonts) $objattr['top-text'] = mb_convert_encoding($objattr['top-text'], $this->mb_enc,'UTF-8'); } if(isset($attr['BOTTOM-TEXT'])) { $objattr['bottom-text'] = strcode2utf($attr['BOTTOM-TEXT']); $objattr['bottom-text'] = $this->lesser_entity_decode($objattr['bottom-text']); if ($this->onlyCoreFonts) $objattr['bottom-text'] = mb_convert_encoding($objattr['bottom-text'], $this->mb_enc,'UTF-8'); } if(isset($attr['SPACE-WIDTH']) && $attr['SPACE-WIDTH']) { $objattr['space-width'] = $attr['SPACE-WIDTH']; } if(isset($attr['CHAR-WIDTH']) && $attr['CHAR-WIDTH']) { $objattr['char-width'] = $attr['CHAR-WIDTH']; } // VISIBILITY $objattr['visibility'] = 'visible'; if (isset($properties['VISIBILITY'])) { $v = strtolower($properties['VISIBILITY']); if (($v == 'hidden' || $v == 'printonly' || $v == 'screenonly') && $this->visibility=='visible') { $objattr['visibility'] = $v; } } if (isset($properties['FONT-FAMILY'])) { $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false); } if (isset($properties['FONT-SIZE'])) { $mmsize = $this->ConvertSize($properties['FONT-SIZE'],($this->default_font_size/_MPDFK)); $this->SetFontSize($mmsize*_MPDFK,false); } if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); } $objattr['fontfamily'] = $this->FontFamily; $objattr['fontsize'] = $this->FontSizePt; $objattr['fontstyle'] = ''; if (isset($properties['FONT-WEIGHT'])) { if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $objattr['fontstyle'] .= 'B'; } } if (isset($properties['FONT-STYLE'])) { if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $objattr['fontstyle'] .= 'I'; } } // VSPACE and HSPACE converted to margins in MergeCSS if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); } if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); } if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); } if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); } if (isset($properties['OPACITY']) && $properties['OPACITY'] > 0 && $properties['OPACITY'] <= 1) { $objattr['opacity'] = $properties['OPACITY']; } if (isset($properties['BACKGROUND-COLOR']) && $properties['BACKGROUND-COLOR'] != '') { $objattr['bgcolor'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); } else { $objattr['bgcolor'] = false; } if ($this->HREF) { // mPDF 5.3.78 if (strpos($this->HREF,".") === false && strpos($this->HREF,"@") !== 0) { $href = $this->HREF; while(array_key_exists($href,$this->internallink)) $href="#".$href; $this->internallink[$href] = $this->AddLink(); $objattr['link'] = $this->internallink[$href]; } else { $objattr['link'] = $this->HREF; } } $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w']; $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w']; $w = $objattr['r']*2; $h = $w; $objattr['height'] = $h + $extraheight; $objattr['width'] = $w + $extrawidth; $objattr['type'] = 'textcircle'; $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac"; // Clear properties - tidy up $properties = array(); /*-- TABLES --*/ // Output it to buffers if ($this->tableLevel) { $this->_saveCellTextBuffer($e, $this->HREF); $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; } else { /*-- END TABLES --*/ $this->_saveTextBuffer($e, $this->HREF); } // *TABLES* if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); } unset($this->InlineProperties[$tag]); break; /*-- TABLES --*/ case 'TABLE': // TABLE-BEGIN $this->tdbegin = false; $this->lastoptionaltag = ''; // Disable vertical justification in columns if ($this->ColActive) { $this->colvAlign = ''; } // *COLUMNS* if ($this->lastblocklevelchange == 1) { $blockstate = 1; } // Top margins/padding only else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding // called from block after new div e.g. <div> ... <table> ... Outputs block top margin/border and padding if (count($this->textbuffer) == 0 && $this->lastblocklevelchange == 1 && !$this->tableLevel && !$this->kwt) { $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,1,true, $this->blk[$this->blklvl]['direction']); $this->finishFlowingBlock(true); // true = END of flowing block } else if (!$this->tableLevel && count($this->textbuffer)) { $this->printbuffer($this->textbuffer,$blockstate); } $this->textbuffer=array(); $this->lastblocklevelchange = -1; if ($this->tableLevel) { // i.e. now a nested table coming... // Save current level table $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['baseProperties']= $this->base_table_properties; $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = $this->cell; $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currrow'] = $this->row; $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currcol'] = $this->col; } $this->tableLevel++; $this->tbCSSlvl++; if ($this->tableLevel>1) { // inherit table properties from cell in which nested $this->base_table_properties['FONT-KERNING'] = $this->kerning ; $this->base_table_properties['LETTER-SPACING'] = $this->lSpacingCSS ; $this->base_table_properties['WORD-SPACING'] = $this->wSpacingCSS ; } if (isset($this->tbctr[$this->tableLevel])) { $this->tbctr[$this->tableLevel]++; } else { $this->tbctr[$this->tableLevel] = 1; } $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['level'] = $this->tableLevel; $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['levelid'] = $this->tbctr[$this->tableLevel]; if ($this->tableLevel > $this->innermostTableLevel) { $this->innermostTableLevel = $this->tableLevel; } if ($this->tableLevel > 1) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nestedpos'] = array($this->row,$this->col,$this->tbctr[($this->tableLevel-1)]); } //++++++++++++++++++++++++++++ $this->cell = array(); $this->col=-1; //int $this->row=-1; //int $table = &$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]; // mPDF 5.3.79 // New table - any level if ($this->cacheTables) { $this->packTableData = true; // required for cacheTables $this->simpleTables = false; // Cannot co-exist with cacheTables $table['cache'] = _MPDF_TEMP_PATH.'_tempTblCache'.RAND(1,1000000).'.dat'; $fh = fopen($table['cache'] , "wb") or $this->Error("When using cacheTables, you must have read/write access to cache files (".$table['cache'] .")"); fwrite($fh, "\x00"); fclose($fh); $table['ptr'] = 1 ; // Must not be 0 } $table['direction'] = $this->directionality; $table['bgcolor'] = false; $table['va'] = false; $table['txta'] = false; $table['topntail'] = false; $table['thead-underline'] = false; $table['border'] = false; $table['border_details']['R']['w'] = 0; $table['border_details']['L']['w'] = 0; $table['border_details']['T']['w'] = 0; $table['border_details']['B']['w'] = 0; $table['border_details']['R']['style'] = ''; $table['border_details']['L']['style'] = ''; $table['border_details']['T']['style'] = ''; $table['border_details']['B']['style'] = ''; $table['max_cell_border_width']['R'] = 0; $table['max_cell_border_width']['L'] = 0; $table['max_cell_border_width']['T'] = 0; $table['max_cell_border_width']['B'] = 0; $table['padding']['L'] = false; $table['padding']['R'] = false; $table['padding']['T'] = false; $table['padding']['B'] = false; $table['margin']['L'] = false; $table['margin']['R'] = false; $table['margin']['T'] = false; $table['margin']['B'] = false; $table['a'] = false; $table['border_spacing_H'] = false; $table['border_spacing_V'] = false; $this->Reset(); $this->InlineProperties = array(); $this->spanlvl = 0; $table['nc'] = $table['nr'] = 0; $this->tablethead = 0; $this->tabletfoot = 0; $this->tabletheadjustfinished = false; if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins && $this->tableLevel==1) { $lastbottommargin = $this->lastblockbottommargin; } else { $lastbottommargin = 0; } $this->lastblockbottommargin = 0; $this->blockjustfinished=false; if ($this->tableLevel==1) { $this->tableCJK = false; $this->table_lineheight = $this->normalLineheight; $table['headernrows'] = 0; // mPDF 5.3.62 $table['footernrows'] = 0; // mPDF 5.3.62 $this->base_table_properties = array(); } // ADDED CSS FUNCIONS FOR TABLE if ($this->tbCSSlvl==1) { $properties = $this->MergeCSS('TOPTABLE',$tag,$attr); } else { $properties = $this->MergeCSS('TABLE',$tag,$attr); } $w = ''; if (isset($properties['WIDTH'])) { $w = $properties['WIDTH']; } if(isset($properties['DIRECTION']) && $properties['DIRECTION']) { $table['direction'] = strtolower($properties['DIRECTION']); } if(isset($attr['DIR']) && $attr['DIR']) { $table['direction'] = strtolower($attr['DIR']); } else if (!isset($table['direction'])){ $table['direction'] = $this->blk[$this->blklvl]['direction']; } if (isset($properties['BACKGROUND-COLOR'])) { $table['bgcolor'][-1] = $properties['BACKGROUND-COLOR']; } else if (isset($properties['BACKGROUND'])) { $table['bgcolor'][-1] = $properties['BACKGROUND']; } if (isset($properties['VERTICAL-ALIGN'])) { $table['va'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; } if (isset($properties['TEXT-ALIGN'])) { $table['txta'] = $align[strtolower($properties['TEXT-ALIGN'])]; } if (isset($properties['AUTOSIZE']) && $properties['AUTOSIZE'] && $this->tableLevel ==1) { $this->shrink_this_table_to_fit = $properties['AUTOSIZE']; if ($this->shrink_this_table_to_fit < 1) { $this->shrink_this_table_to_fit = 0; } } if (isset($properties['ROTATE']) && $properties['ROTATE'] && $this->tableLevel ==1) { $this->table_rotate = $properties['ROTATE']; } if (isset($properties['TOPNTAIL'])) { $table['topntail'] = $properties['TOPNTAIL']; } if (isset($properties['THEAD-UNDERLINE'])) { $table['thead-underline'] = $properties['THEAD-UNDERLINE']; } if (isset($properties['BORDER'])) { $bord = $this->border_details($properties['BORDER']); if ($bord['s']) { $table['border'] = _BORDER_ALL; $table['border_details']['R'] = $bord; $table['border_details']['L'] = $bord; $table['border_details']['T'] = $bord; $table['border_details']['B'] = $bord; } } if (isset($properties['BORDER-RIGHT'])) { if ($table['direction'] == 'rtl') { // *RTL* $table['border_details']['R'] = $this->border_details($properties['BORDER-LEFT']); // *RTL* } // *RTL* else { // *RTL* $table['border_details']['R'] = $this->border_details($properties['BORDER-RIGHT']); } // *RTL* $this->setBorder($table['border'], _BORDER_RIGHT, $table['border_details']['R']['s']); } if (isset($properties['BORDER-LEFT'])) { if ($table['direction'] == 'rtl') { // *RTL* $table['border_details']['L'] = $this->border_details($properties['BORDER-RIGHT']); // *RTL* } // *RTL* else { // *RTL* $table['border_details']['L'] = $this->border_details($properties['BORDER-LEFT']); } // *RTL* $this->setBorder($table['border'], _BORDER_LEFT, $table['border_details']['L']['s']); } if (isset($properties['BORDER-BOTTOM'])) { $table['border_details']['B'] = $this->border_details($properties['BORDER-BOTTOM']); $this->setBorder($table['border'], _BORDER_BOTTOM, $table['border_details']['B']['s']); } if (isset($properties['BORDER-TOP'])) { $table['border_details']['T'] = $this->border_details($properties['BORDER-TOP']); $this->setBorder($table['border'], _BORDER_TOP, $table['border_details']['T']['s']); } if ($table['border']){ $this->table_border_css_set = 1; } else { $this->table_border_css_set = 0; } if (isset($properties['FONT-FAMILY'])) { $this->default_font = $properties['FONT-FAMILY']; $this->SetFont($this->default_font,'',0,false); $this->base_table_properties['FONT-FAMILY'] = $properties['FONT-FAMILY']; } if (isset($properties['FONT-SIZE'])) { $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK); if ($mmsize) { $this->default_font_size = $mmsize*(_MPDFK); $this->SetFontSize($this->default_font_size,false); $this->base_table_properties['FONT-SIZE'] = $properties['FONT-SIZE']; } } if (isset($properties['FONT-WEIGHT'])) { if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->base_table_properties['FONT-WEIGHT'] = 'BOLD'; } } if (isset($properties['FONT-STYLE'])) { if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->base_table_properties['FONT-STYLE'] = 'ITALIC'; } } if (isset($properties['COLOR'])) { $this->base_table_properties['COLOR'] = $properties['COLOR']; } if (isset($properties['FONT-KERNING'])) { $this->base_table_properties['FONT-KERNING'] = $properties['FONT-KERNING']; } if (isset($properties['LETTER-SPACING'])) { $this->base_table_properties['LETTER-SPACING'] = $properties['LETTER-SPACING']; } if (isset($properties['WORD-SPACING'])) { $this->base_table_properties['WORD-SPACING'] = $properties['WORD-SPACING']; } if (isset($properties['PADDING-LEFT'])) { $table['padding']['L'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-RIGHT'])) { $table['padding']['R'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-TOP'])) { $table['padding']['T'] = $this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-BOTTOM'])) { $table['padding']['B'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-TOP'])) { if ($lastbottommargin) { $tmp = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); if ($tmp > $lastbottommargin) { $properties['MARGIN-TOP'] -= $lastbottommargin; } else { $properties['MARGIN-TOP'] = 0; } } $table['margin']['T'] = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-BOTTOM'])) { $table['margin']['B'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-LEFT'])) { $table['margin']['L'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-RIGHT'])) { $table['margin']['R'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['MARGIN-LEFT']) && isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-LEFT'])=='auto' && strtolower($properties['MARGIN-RIGHT'])=='auto') { $table['a'] = 'C'; } else if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') { $table['a'] = 'R'; } else if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') { $table['a'] = 'L'; } if (isset($properties['LINE-HEIGHT']) && $this->tableLevel==1) { $this->table_lineheight = $this->fixLineheight($properties['LINE-HEIGHT']); if (!$this->table_lineheight) { $this->table_lineheight = $this->normalLineheight; } } if (isset($properties['BORDER-COLLAPSE']) && strtoupper($properties['BORDER-COLLAPSE'])=='SEPARATE') { $table['borders_separate'] = true; } else { $table['borders_separate'] = false; } if (isset($properties['BORDER-SPACING-H'])) { $table['border_spacing_H'] = $this->ConvertSize($properties['BORDER-SPACING-H'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['BORDER-SPACING-V'])) { $table['border_spacing_V'] = $this->ConvertSize($properties['BORDER-SPACING-V'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['EMPTY-CELLS'])) { $table['empty_cells'] = strtolower($properties['EMPTY-CELLS']); // 'hide' or 'show' } else { $table['empty_cells'] = ''; } if (isset($properties['PAGE-BREAK-INSIDE']) && strtoupper($properties['PAGE-BREAK-INSIDE'])=='AVOID' && $this->tableLevel==1 && !$this->writingHTMLfooter) { $this->table_keep_together = true; } else if ($this->tableLevel==1) { $this->table_keep_together = false; } // mPDF 5.3.55 if (isset($properties['PAGE-BREAK-AFTER']) && $this->tableLevel==1) { $table['page_break_after'] = strtoupper($properties['PAGE-BREAK-AFTER']); } /*-- BACKGROUNDS --*/ if (isset($properties['BACKGROUND-GRADIENT']) && !$this->kwt && !$this->ColActive) { $table['gradient'] = $properties['BACKGROUND-GRADIENT']; } if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive) { $ret = $this->SetBackground($properties, $currblk['inner_width']); if ($ret) { $table['background-image'] = $ret; } } /*-- END BACKGROUNDS --*/ if (isset($properties['OVERFLOW'])) { $table['overflow'] = strtolower($properties['OVERFLOW']); // 'hidden' 'wrap' or 'visible' or 'auto' if (($this->ColActive || $this->tableLevel>1) && $table['overflow']=='visible') { unset($table['overflow']); } // mPDF 5.3.36 } $properties = array(); if (!$table['borders_separate']) { $table['border_spacing_H'] = $table['border_spacing_V'] = 0; } else if (isset($attr['CELLSPACING'])) { $table['border_spacing_H'] = $table['border_spacing_V'] = $this->ConvertSize($attr['CELLSPACING'],$this->blk[$this->blklvl]['inner_width']); } if (isset($attr['CELLPADDING'])) { $table['cell_padding'] = $attr['CELLPADDING']; } else { $table['cell_padding'] = false; } if (isset($attr['BORDER'])) { $this->table_border_attr_set = 1; if ($attr['BORDER']=='1') { $bord = $this->border_details('#000000 1px solid'); if ($bord['s']) { $table['border'] = _BORDER_ALL; $table['border_details']['R'] = $bord; $table['border_details']['L'] = $bord; $table['border_details']['T'] = $bord; $table['border_details']['B'] = $bord; } } } else { $this->table_border_attr_set = 0; } if (isset($attr['ALIGN'])) { $table['a'] = $align[strtolower($attr['ALIGN'])]; } if (!$table['a']) { if ($table['direction'] == 'rtl' ) { $table['a'] = 'R'; } else { $table['a'] = 'L'; } } if (isset($attr['BGCOLOR'])) { $table['bgcolor'][-1] = $attr['BGCOLOR']; } if (isset($attr['WIDTH']) && $attr['WIDTH']) { $w = $attr['WIDTH']; } if ($w) { // set here or earlier in $properties $maxwidth = $this->blk[$this->blklvl]['inner_width']; if ($table['borders_separate']) { $tblblw = $table['margin']['L'] + $table['margin']['R'] + $table['border_details']['L']['w']/2 + $table['border_details']['R']['w']/2; } else { $tblblw = $table['margin']['L'] + $table['margin']['R'] + $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2; } if (strpos($w,'%') && $this->tableLevel == 1 && !$this->ignore_table_percents ) { // % needs to be of inner box without table margins etc. $maxwidth -= $tblblw ; $wmm = $this->ConvertSize($w,$maxwidth,$this->FontSize,false); $table['w'] = $wmm + $tblblw ; } if (strpos($w,'%') && $this->tableLevel > 1 && !$this->ignore_table_percents && $this->keep_table_proportions) { $table['wpercent'] = $w + 0; // makes 80% -> 80 } if (!strpos($w,'%') && !$this->ignore_table_widths ) { $wmm = $this->ConvertSize($w,$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); $table['w'] = $wmm + $tblblw ; } if (!$this->keep_table_proportions) { if (isset($table['w']) && $table['w'] > $this->blk[$this->blklvl]['inner_width']) { $table['w'] = $this->blk[$this->blklvl]['inner_width']; } } } if (isset($attr['AUTOSIZE']) && $this->tableLevel==1) { $this->shrink_this_table_to_fit = $attr['AUTOSIZE']; if ($this->shrink_this_table_to_fit < 1) { $this->shrink_this_table_to_fit = 1; } } if (isset($attr['ROTATE']) && $this->tableLevel==1) { $this->table_rotate = $attr['ROTATE']; } //++++++++++++++++++++++++++++ // keeping block together on one page // Autosize is now forced therefore keep block together disabled if ($this->keep_block_together) { $this->keep_block_together = 0; $this->printdivbuffer(); $this->blk[$this->blklvl]['keep_block_together'] = 0; } if ($this->table_rotate) { $this->tbrot_Links = array(); $this->tbrot_Annots = array(); $this->tbrotForms = array(); $this->tbrot_Reference = array(); $this->tbrot_BMoutlines = array(); $this->tbrot_toc = array(); } if ($this->kwt) { if ($this->table_rotate) { $this->table_keep_together = true; } $this->kwt = false; $this->kwt_saved = true; } if ($this->tableLevel==1 && $this->useGraphs) { if (isset($attr['ID']) && $attr['ID']) { $this->currentGraphId = strtoupper($attr['ID']); } else { $this->currentGraphId = '0'; } $this->graphs[$this->currentGraphId] = array(); } //++++++++++++++++++++++++++++ $this->plainCell_properties = array(); unset($table); // mPDF 5.3.76 break; case 'THEAD': $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag $this->tbCSSlvl++; $this->tablethead = 1; $this->tabletfoot = 0; $properties = $this->MergeCSS('TABLE',$tag,$attr); if (isset($properties['FONT-WEIGHT'])) { if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->thead_font_weight = 'B'; } else { $this->thead_font_weight = ''; } } if (isset($properties['FONT-STYLE'])) { if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->thead_font_style = 'I'; } else { $this->thead_font_style = ''; } } if (isset($properties['FONT-VARIANT'])) { if (strtoupper($properties['FONT-VARIANT']) == 'SMALL-CAPS') { $this->thead_font_smCaps = 'S'; } else { $this->thead_font_smCaps = ''; } } if (isset($properties['VERTICAL-ALIGN'])) { $this->thead_valign_default = $properties['VERTICAL-ALIGN']; } if (isset($properties['TEXT-ALIGN'])) { $this->thead_textalign_default = $properties['TEXT-ALIGN']; } $properties = array(); break; case 'TFOOT': $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag $this->tbCSSlvl++; $this->tabletfoot = 1; $this->tablethead = 0; $properties = $this->MergeCSS('TABLE',$tag,$attr); if (isset($properties['FONT-WEIGHT'])) { if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->tfoot_font_weight = 'B'; } else { $this->tfoot_font_weight = ''; } } if (isset($properties['FONT-STYLE'])) { if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->tfoot_font_style = 'I'; } else { $this->tfoot_font_style = ''; } } if (isset($properties['FONT-VARIANT'])) { if (strtoupper($properties['FONT-VARIANT']) == 'SMALL-CAPS') { $this->tfoot_font_smCaps = 'S'; } else { $this->tfoot_font_smCaps = ''; } } if (isset($properties['VERTICAL-ALIGN'])) { $this->tfoot_valign_default = $properties['VERTICAL-ALIGN']; } if (isset($properties['TEXT-ALIGN'])) { $this->tfoot_textalign_default = $properties['TEXT-ALIGN']; } $properties = array(); break; case 'TBODY': $this->tablethead = 0; $this->tabletfoot = 0; $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag $this->tbCSSlvl++; $this->MergeCSS('TABLE',$tag,$attr); break; case 'TR': $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag $this->tbCSSlvl++; $this->row++; $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']++; $this->col = -1; $properties = $this->MergeCSS('TABLE',$tag,$attr); if (!$this->simpleTables && (!isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['borders_separate']) || !$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['borders_separate'])) { if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-left'][$this->row] = $properties['BORDER-LEFT']; } if (isset($properties['BORDER-RIGHT']) && $properties['BORDER-RIGHT']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-right'][$this->row] = $properties['BORDER-RIGHT']; } if (isset($properties['BORDER-TOP']) && $properties['BORDER-TOP']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-top'][$this->row] = $properties['BORDER-TOP']; } if (isset($properties['BORDER-BOTTOM']) && $properties['BORDER-BOTTOM']) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-bottom'][$this->row] = $properties['BORDER-BOTTOM']; } } if (isset($properties['BACKGROUND-COLOR'])) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$this->row] = $properties['BACKGROUND-COLOR']; } /*-- BACKGROUNDS --*/ if (isset($properties['BACKGROUND-GRADIENT']) && !$this->kwt && !$this->ColActive) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'][$this->row] = $properties['BACKGROUND-GRADIENT']; } if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive) { $ret = $this->SetBackground($properties, $currblk['inner_width']); if ($ret) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'][$this->row] = $ret; } } /*-- END BACKGROUNDS --*/ if (isset($properties['TEXT-ROTATE'])) { $this->trow_text_rotate = $properties['TEXT-ROTATE']; } if (isset($attr['TEXT-ROTATE'])) $this->trow_text_rotate = $attr['TEXT-ROTATE']; if (isset($attr['BGCOLOR'])) $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$this->row] = $attr['BGCOLOR']; if ($this->tablethead) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead'][$this->row] = true; } if ($this->tabletfoot) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$this->row] = true; } $properties = array(); break; // mPDF 5.3.75 case 'TH': case 'TD': $this->ignorefollowingspaces = true; $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag $this->tbCSSlvl++; $this->InlineProperties = array(); $this->spanlvl = 0; $this->tdbegin = true; $this->col++; while (isset($this->cell[$this->row][$this->col])) { $this->col++; } //Update number column if ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] < $this->col+1) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] = $this->col+1; } $table = &$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]; // mPDF 5.3.77 $c = array('a' => false, 'R' => false, 'nowrap' => false, 'bgcolor' => false, 'padding' => array('L' => false, 'R' => false, 'T' => false, 'B' => false ) ); if ($this->simpleTables && $this->row==0 && $this->col==0){ $table['simple']['border'] = false; $table['simple']['border_details']['R']['w'] = 0; $table['simple']['border_details']['L']['w'] = 0; $table['simple']['border_details']['T']['w'] = 0; $table['simple']['border_details']['B']['w'] = 0; $table['simple']['border_details']['R']['style'] = ''; $table['simple']['border_details']['L']['style'] = ''; $table['simple']['border_details']['T']['style'] = ''; $table['simple']['border_details']['B']['style'] = ''; } else if (!$this->simpleTables) { $c['border'] = false; $c['border_details']['R']['w'] = 0; $c['border_details']['L']['w'] = 0; $c['border_details']['T']['w'] = 0; $c['border_details']['B']['w'] = 0; $c['border_details']['mbw']['BL'] = 0; $c['border_details']['mbw']['BR'] = 0; $c['border_details']['mbw']['RT'] = 0; $c['border_details']['mbw']['RB'] = 0; $c['border_details']['mbw']['TL'] = 0; $c['border_details']['mbw']['TR'] = 0; $c['border_details']['mbw']['LT'] = 0; $c['border_details']['mbw']['LB'] = 0; $c['border_details']['R']['style'] = ''; $c['border_details']['L']['style'] = ''; $c['border_details']['T']['style'] = ''; $c['border_details']['B']['style'] = ''; $c['border_details']['R']['s'] = 0; $c['border_details']['L']['s'] = 0; $c['border_details']['T']['s'] = 0; $c['border_details']['B']['s'] = 0; $c['border_details']['R']['c'] = $this->ConvertColor(0); $c['border_details']['L']['c'] = $this->ConvertColor(0); $c['border_details']['T']['c'] = $this->ConvertColor(0); $c['border_details']['B']['c'] = $this->ConvertColor(0); $c['border_details']['R']['dom'] = 0; $c['border_details']['L']['dom'] = 0; $c['border_details']['T']['dom'] = 0; $c['border_details']['B']['dom'] = 0; } if ($table['va']) { $c['va'] = $table['va']; } if ($table['txta']) { $c['a'] = $table['txta']; } if ($this->table_border_attr_set) { if ($table['border_details']) { if (!$this->simpleTables){ $c['border_details']['R'] = $table['border_details']['R']; $c['border_details']['L'] = $table['border_details']['L']; $c['border_details']['T'] = $table['border_details']['T']; $c['border_details']['B'] = $table['border_details']['B']; $c['border'] = $table['border']; $c['border_details']['L']['dom'] = 1; $c['border_details']['R']['dom'] = 1; $c['border_details']['T']['dom'] = 1; $c['border_details']['B']['dom'] = 1; } else if ($this->simpleTables && $this->row==0 && $this->col==0){ $table['simple']['border_details']['R'] = $table['border_details']['R']; $table['simple']['border_details']['L'] = $table['border_details']['L']; $table['simple']['border_details']['T'] = $table['border_details']['T']; $table['simple']['border_details']['B'] = $table['border_details']['B']; $table['simple']['border'] = $table['border']; } } } // INHERITED THEAD CSS Properties if ($this->tablethead) { if ($this->thead_valign_default) $c['va'] = $align[strtolower($this->thead_valign_default)]; if ($this->thead_textalign_default) $c['a'] = $align[strtolower($this->thead_textalign_default)]; if ($this->thead_font_weight == 'B') { $this->SetStyle('B',true); } if ($this->thead_font_style == 'I') { $this->SetStyle('I',true); } if ($this->thead_font_smCaps == 'S') { $this->SetStyle('S',true); } // mPDF 5.3.76 } // INHERITED TFOOT CSS Properties if ($this->tabletfoot) { if ($this->tfoot_valign_default) $c['va'] = $align[strtolower($this->tfoot_valign_default)]; if ($this->tfoot_textalign_default) $c['a'] = $align[strtolower($this->tfoot_textalign_default)]; if ($this->tfoot_font_weight == 'B') { $this->SetStyle('B',true); } if ($this->tfoot_font_style == 'I') { $this->SetStyle('I',true); } if ($this->tfoot_font_style == 'S') { $this->SetStyle('S',true); } } if ($this->trow_text_rotate){ $c['R'] = $this->trow_text_rotate; } $this->cell_border_dominance_L = 0; $this->cell_border_dominance_R = 0; $this->cell_border_dominance_T = 0; $this->cell_border_dominance_B = 0; $properties = $this->MergeCSS('TABLE',$tag,$attr); $properties = $this->array_merge_recursive_unique($this->base_table_properties, $properties); if (isset($properties['FONT-KERNING']) && (strtoupper($properties['FONT-KERNING'])=='NORMAL' || strtoupper($properties['FONT-KERNING'])=='AUTO')) { $this->kerning = true; } else { $this->kerning = false; } if (isset($properties['LETTER-SPACING']) && ($properties['LETTER-SPACING'] || $properties['LETTER-SPACING']==='0') && strtoupper($properties['LETTER-SPACING']) != 'NORMAL') { $this->lSpacingCSS = strtoupper($properties['LETTER-SPACING']); $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize); } else { $this->lSpacingCSS = ''; $this->fixedlSpacing = false; } if (isset($properties['WORD-SPACING']) && strtoupper($properties['WORD-SPACING']) != 'NORMAL') { $this->wSpacingCSS = strtoupper($properties['WORD-SPACING']); $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize); } else { $this->minwSpacing = 0; $this->wSpacingCSS = ''; } if (isset($properties['BACKGROUND-COLOR'])) { $c['bgcolor'] = $properties['BACKGROUND-COLOR']; } else if (isset($properties['BACKGROUND'])) { $c['bgcolor'] = $properties['BACKGROUND']; } /*-- BACKGROUNDS --*/ if (isset($properties['BACKGROUND-GRADIENT'])) { $c['gradient'] = $properties['BACKGROUND-GRADIENT']; } else { $c['gradient'] = false; } if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->keep_block_together) { $ret = $this->SetBackground($properties, $this->blk[$this->blklvl]['inner_width']); if ($ret) { $c['background-image'] = $ret; } } /*-- END BACKGROUNDS --*/ if (isset($properties['VERTICAL-ALIGN'])) { $c['va']=$align[strtolower($properties['VERTICAL-ALIGN'])]; } if (isset($properties['TEXT-ALIGN'])) { $c['a'] = $align[strtolower($properties['TEXT-ALIGN'])]; } if (isset($properties['TEXT-ROTATE']) && ($properties['TEXT-ROTATE'] || $properties['TEXT-ROTATE']==="0")){ $c['R'] = $properties['TEXT-ROTATE']; } if (isset($properties['BORDER'])) { $bord = $this->border_details($properties['BORDER']); if ($bord['s']) { if (!$this->simpleTables){ $c['border'] = _BORDER_ALL; $c['border_details']['R'] = $bord; $c['border_details']['L'] = $bord; $c['border_details']['T'] = $bord; $c['border_details']['B'] = $bord; $c['border_details']['L']['dom'] = $this->cell_border_dominance_L; $c['border_details']['R']['dom'] = $this->cell_border_dominance_R; $c['border_details']['T']['dom'] = $this->cell_border_dominance_T; $c['border_details']['B']['dom'] = $this->cell_border_dominance_B; } else if ($this->simpleTables && $this->row==0 && $this->col==0){ $table['simple']['border'] = _BORDER_ALL; $table['simple']['border_details']['R'] = $bord; $table['simple']['border_details']['L'] = $bord; $table['simple']['border_details']['T'] = $bord; $table['simple']['border_details']['B'] = $bord; } } } if (!$this->simpleTables){ if (isset($properties['BORDER-RIGHT']) && $properties['BORDER-RIGHT']) { $c['border_details']['R'] = $this->border_details($properties['BORDER-RIGHT']); $this->setBorder($c['border'], _BORDER_RIGHT, $c['border_details']['R']['s']); $c['border_details']['R']['dom'] = $this->cell_border_dominance_R; } if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) { $c['border_details']['L'] = $this->border_details($properties['BORDER-LEFT']); $this->setBorder($c['border'], _BORDER_LEFT, $c['border_details']['L']['s']); $c['border_details']['L']['dom'] = $this->cell_border_dominance_L; } if (isset($properties['BORDER-BOTTOM']) && $properties['BORDER-BOTTOM']) { $c['border_details']['B'] = $this->border_details($properties['BORDER-BOTTOM']); $this->setBorder($c['border'], _BORDER_BOTTOM, $c['border_details']['B']['s']); $c['border_details']['B']['dom'] = $this->cell_border_dominance_B; } if (isset($properties['BORDER-TOP']) && $properties['BORDER-TOP']) { $c['border_details']['T'] = $this->border_details($properties['BORDER-TOP']); $this->setBorder($c['border'], _BORDER_TOP, $c['border_details']['T']['s']); $c['border_details']['T']['dom'] = $this->cell_border_dominance_T; } } else if ($this->simpleTables && $this->row==0 && $this->col==0){ if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) { $bord = $this->border_details($properties['BORDER-LEFT']); if ($bord['s']) { $table['simple']['border'] = _BORDER_ALL; } else { $table['simple']['border'] = 0; } $table['simple']['border_details']['R'] = $bord; $table['simple']['border_details']['L'] = $bord; $table['simple']['border_details']['T'] = $bord; $table['simple']['border_details']['B'] = $bord; } } // mPDF 5.3.15 if ($this->simpleTables && $this->row==0 && $this->col==0 && !$table['borders_separate'] && $table['simple']['border'] ){ $table['border_details'] = $table['simple']['border_details']; $table['border'] = $table['simple']['border']; } // mPDF 5.3.78 // Border set on TR (if collapsed only) if (!$table['borders_separate'] && !$this->simpleTables && isset($table['trborder-left'][$this->row])) { if ($this->col==0) { $left = $this->border_details($table['trborder-left'][$this->row]); $c['border_details']['L'] = $left; $this->setBorder($c['border'], _BORDER_LEFT, $c['border_details']['L']['s']); } $c['border_details']['B'] = $this->border_details($table['trborder-bottom'][$this->row]); $this->setBorder($c['border'], _BORDER_BOTTOM, $c['border_details']['B']['s']); $c['border_details']['T'] = $this->border_details($table['trborder-top'][$this->row]); $this->setBorder($c['border'], _BORDER_TOP, $c['border_details']['T']['s']); } if ($this->packTableData && !$this->simpleTables) { $c['borderbin'] = $this->_packCellBorder($c); unset($c['border']); unset($c['border_details']); } if (isset($properties['PADDING-LEFT'])) { $c['padding']['L'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-RIGHT'])) { $c['padding']['R'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-BOTTOM'])) { $c['padding']['B'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['PADDING-TOP'])) { $c['padding']['T'] = $this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } $w = ''; if (isset($properties['WIDTH'])) { $w = $properties['WIDTH']; } if (isset($attr['WIDTH'])) { $w = $attr['WIDTH']; } if ($w) { if (strpos($w,'%') && !$this->ignore_table_percents ) { $c['wpercent'] = $w + 0; } // makes 80% -> 80 else if (!strpos($w,'%') && !$this->ignore_table_widths ) { $c['w'] = $this->ConvertSize($w,$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } } if (isset($properties['HEIGHT']) && !strpos($properties['HEIGHT'],'%')) { $c['h'] = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } // mPDF 5.3.57 if (isset($properties['COLOR'])) { $cor = $this->ConvertColor($properties['COLOR']); if ($cor) { $this->colorarray = $cor; $this->SetTColor($cor); } } if (isset($properties['FONT-FAMILY'])) { $this->SetFont($properties['FONT-FAMILY'],'',0,false); } if (isset($properties['FONT-SIZE'])) { $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/_MPDFK); if ($mmsize) { $this->SetFontSize($mmsize*(_MPDFK),false); } } $c['dfs'] = $this->FontSize; // Default Font size if (isset($properties['FONT-WEIGHT'])) { if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->SetStyle('B',true); } } if (isset($properties['FONT-STYLE'])) { if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->SetStyle('I',true); } } if (isset($properties['FONT-VARIANT'])) { if (strtoupper($properties['FONT-VARIANT']) == 'SMALL-CAPS') { $this->SetStyle('S',true); } } // mPDF 5.3.34 if (isset($properties['TEXT-DECORATION'])) { if (strtoupper($properties['TEXT-DECORATION']) == 'LINE-THROUGH') { $this->strike = true; } else if (strtoupper($properties['TEXT-DECORATION']) == 'UNDERLINE') { $this->SetStyle('U',true); } } // mPDF 5.3.A2 if (isset($properties['TEXT-SHADOW'])) { $ts = $this->setCSStextshadow($properties['TEXT-SHADOW']); if ($ts) { $this->textshadow = $ts; } } // mPDF 5.3.80 if (isset($properties['TEXT-TRANSFORM'])) { if (strtoupper($properties['TEXT-TRANSFORM']) == 'CAPITALIZE') { $this->capitalize = true; } else if (strtoupper($properties['TEXT-TRANSFORM']) == 'UPPERCASE') { $this->toupper = true; } else if (strtoupper($properties['TEXT-TRANSFORM']) == 'LOWERCASE') { $this->tolower = true; } } if (isset($properties['WHITE-SPACE'])) { if (strtoupper($properties['WHITE-SPACE']) == 'NOWRAP') { $c['nowrap']= 1; } } $properties = array(); if (isset($attr['HEIGHT']) && !strpos($attr['HEIGHT'],'%')) $c['h'] = $this->ConvertSize($attr['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); // mPDF 5.3.57 if (isset($attr['ALIGN'])) $c['a'] = $align[strtolower($attr['ALIGN'])]; if (!$c['a']) { if (isset($table['direction']) && $table['direction'] == 'rtl' ) { $c['a'] = 'R'; } else { $c['a'] = 'L'; } } if (isset($attr['VALIGN'])) $c['va'] = $align[strtolower($attr['VALIGN'])]; if (isset($attr['BGCOLOR'])) $c['bgcolor'] = $attr['BGCOLOR']; if (isset($attr['TEXT-ROTATE'])) { $c['R'] = $attr['TEXT-ROTATE']; } if (isset($attr['NOWRAP']) && $attr['NOWRAP']) $c['nowrap']= 1; // mPDF 5.3.77 $this->cell[$this->row][$this->col] = $c; unset($c); $this->cell[$this->row][$this->col]['s'] = 0 ; $cs = $rs = 1; if (isset($attr['COLSPAN']) && $attr['COLSPAN']>1) $cs = $this->cell[$this->row][$this->col]['colspan'] = $attr['COLSPAN']; if ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] < $this->col+$cs) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] = $this->col+$cs; } // mPDF 5.3.79 following code moved outside if... for($l=$this->col; $l < $this->col+$cs ;$l++) { if ($l-$this->col) $this->cell[$this->row][$l] = 0; } if (isset($attr['ROWSPAN']) && $attr['ROWSPAN']>1) $rs = $this->cell[$this->row][$this->col]['rowspan'] = $attr['ROWSPAN']; for ($k=$this->row ; $k < $this->row+$rs ;$k++) { for($l=$this->col; $l < $this->col+$cs ;$l++) { if ($k-$this->row || $l-$this->col) $this->cell[$k][$l] = 0; } } unset($table); // mPDF 5.3.76 break; /*-- END TABLES --*/ /*-- LISTS --*/ // *********** LISTS ******************** case 'OL': case 'UL': $this->listjustfinished = false; if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins) { $lastbottommargin = $this->lastblockbottommargin; } else { $lastbottommargin = 0; } $this->lastblockbottommargin = 0; $this->blockjustfinished=false; $this->linebreakjustfinished=false; $this->lastoptionaltag = ''; // Save current HTML specified optional endtag $this->listCSSlvl++; if((!$this->tableLevel) && ($this->listlvl == 0)) { $blockstate = 0; //if ($this->lastblocklevelchange == 1) { $blockstate = -1; } // Top margins/padding only //else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding // called from block after new div e.g. <div> ... <ol> ... Outputs block top margin/border and padding if (count($this->textbuffer) == 0 && $this->lastblocklevelchange == 1 && !$this->tableLevel && !$this->kwt) { $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,1,true, $this->blk[$this->blklvl]['direction']); $this->finishFlowingBlock(true); // true = END of flowing block } else if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer,$blockstate); } $this->textbuffer=array(); $this->lastblocklevelchange = -1; } // ol and ul types are mixed here if ($this->listlvl == 0) { $this->list_indent = array(); $this->list_align = array(); $this->list_lineheight = array(); $this->InlineProperties['LIST'] = array(); $this->InlineProperties['LISTITEM'] = array(); } /*-- TABLES --*/ // A simple list for inside a table if($this->tableLevel) { $this->list_indent[$this->listlvl] = 0; // mm default indent for each level if ($tag == 'OL') $this->listtype = '1'; else if ($tag == 'UL') $this->listtype = 'disc'; if ($this->listlvl > 0) { $this->listlist[$this->listlvl]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum } $this->listlvl++; $this->listnum = 0; // reset $this->listlist[$this->listlvl] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum); break; } /*-- END TABLES --*/ if (($this->PDFA || $this->PDFX) && $tag == 'UL') { if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "List bullets cannot use core font Zapfdingbats in PDFA1-b or PDFX/1-a. (Substitute characters from current font used if available, otherwise substitutes hyphen '-')"; } } if ($this->listCSSlvl==1) { $properties = $this->MergeCSS('TOPLIST',$tag,$attr); } else { $properties = $this->MergeCSS('LIST',$tag,$attr); } if (!empty($properties)) $this->setCSS($properties,'LIST'); // mPDF 5.3.65 // List-type $this->listtype = ''; if (isset($attr['TYPE']) && $attr['TYPE']) { $this->listtype = $attr['TYPE']; } else if (isset($properties['LIST-STYLE-TYPE'])) { $this->listtype = $this->_getListStyle($properties['LIST-STYLE-TYPE']); } else if (isset($properties['LIST-STYLE'])) { $this->listtype = $this->_getListStyle($properties['LIST-STYLE']); } if (!$this->listtype) { if ($tag == 'OL') $this->listtype = '1'; if ($tag == 'UL') { if ($this->listlvl % 3 == 0) $this->listtype = 'disc'; elseif ($this->listlvl % 3 == 1) $this->listtype = 'circle'; else $this->listtype = 'square'; } } if ($this->listlvl == 0) { $this->inherit_lineheight = 0; $this->listlvl++; // first depth level $this->listnum = 0; // reset $this->listDir = (isset($this->blk[$this->blklvl]['direction']) ? $this->blk[$this->blklvl]['direction'] : null); $occur = $this->listoccur[$this->listlvl] = 1; $this->listlist[$this->listlvl][1] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum); } else { if (!empty($this->textbuffer)) { $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype); $this->listnum++; } // Save current lineheight to inherit $this->textbuffer = array(); $occur = $this->listoccur[$this->listlvl]; $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum $this->listlvl++; $this->listnum = 0; // reset if (!isset($this->listoccur[$this->listlvl]) || $this->listoccur[$this->listlvl] == 0) $this->listoccur[$this->listlvl] = 1; else $this->listoccur[$this->listlvl]++; $occur = $this->listoccur[$this->listlvl]; $this->listlist[$this->listlvl][$occur] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum); } // TOP LEVEL ONLY if ($this->listlvl == 1) { if (isset($properties['MARGIN-TOP'])) { if ($lastbottommargin) { $tmp = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); if ($tmp > $lastbottommargin) { $properties['MARGIN-TOP'] -= $lastbottommargin; } else { $properties['MARGIN-TOP'] = 0; } } $this->DivLn($this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false),$this->blklvl,true,1); // collapsible } if (isset($properties['MARGIN-BOTTOM'])) { $this->list_margin_bottom = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($this->blk[$this->blklvl]['line_height'])) { $this->list_lineheight[$this->listlvl][$occur] = $this->blk[$this->blklvl]['line_height']; } if (isset($properties['DIRECTION']) && $properties['DIRECTION']) { $this->listDir = strtolower($properties['DIRECTION']); } if (isset($attr['DIR']) && $attr['DIR']) { $this->listDir = strtolower($attr['DIR']); } } $this->list_indent[$this->listlvl][$occur] = 5; // mm default indent for each level if (isset($properties['TEXT-INDENT'])) { $this->list_indent[$this->listlvl][$occur] = $this->ConvertSize($properties['TEXT-INDENT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); } if (isset($properties['TEXT-ALIGN'])) { $this->list_align[$this->listlvl][$occur] = $align[strtolower($properties['TEXT-ALIGN'])]; } if (isset($properties['LINE-HEIGHT'])) { $this->list_lineheight[$this->listlvl][$occur] = $this->fixLineheight($properties['LINE-HEIGHT']); } else if ($this->listlvl>1 && isset($this->list_lineheight[($this->listlvl - 1)][1])) { $this->list_lineheight[$this->listlvl][$occur] = end($this->list_lineheight[($this->listlvl - 1)]); } if (!isset($this->list_lineheight[$this->listlvl][$occur]) || !$this->list_lineheight[$this->listlvl][$occur]) { $this->list_lineheight[$this->listlvl][$occur] = $this->normalLineheight; } $this->InlineProperties['LIST'][$this->listlvl][$occur] = $this->saveInlineProperties(); $properties = array(); break; case 'LI': // Start Block $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces /*-- TABLES --*/ // A simple list for inside a table if($this->tableLevel) { $this->blockjustfinished=false; // If already something in the Cell if ((isset($this->cell[$this->row][$this->col]['maxs']) && $this->cell[$this->row][$this->col]['maxs'] > 0 ) || $this->cell[$this->row][$this->col]['s'] > 0 ) { $this->_saveCellTextBuffer("\n"); // mPDF 5.3.99 if (!isset($this->cell[$this->row][$this->col]['maxs'])) { $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) { $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } $this->cell[$this->row][$this->col]['s'] = 0 ; } if ($this->listlvl == 0) { //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...) $this->listlvl++; // first depth level $this->listnum = 0; // reset $this->listlist[$this->listlvl] = array('TYPE'=>'disc','MAXNUM'=>$this->listnum); } $this->listnum++; switch($this->listlist[$this->listlvl]['TYPE']) { case 'A': $blt = $this->dec2alpha($this->listnum,true).$this->list_number_suffix; break; case 'a': $blt = $this->dec2alpha($this->listnum,false).$this->list_number_suffix; break; case 'I': $blt = $this->dec2roman($this->listnum,true).$this->list_number_suffix; break; case 'i': $blt = $this->dec2roman($this->listnum,false).$this->list_number_suffix; break; case '1': $blt = $this->listnum.$this->list_number_suffix; break; default: if ($this->listlvl % 3 == 1 && $this->_charDefined($this->CurrentFont['cw'],8226)) { $blt = "\xe2\x80\xa2"; } // &#8226; else if ($this->listlvl % 3 == 2 && $this->_charDefined($this->CurrentFont['cw'],9900)) { $blt = "\xe2\x9a\xac"; } // &#9900; else if ($this->listlvl % 3 == 0 && $this->_charDefined($this->CurrentFont['cw'],9642)) { $blt = "\xe2\x96\xaa"; } // &#9642; else { $blt = '-'; } break; } // change to &nbsp; spaces if ($this->usingCoreFont) { $ls = str_repeat(chr(160).chr(160),($this->listlvl-1)*2) . $blt . ' '; } else { $ls = str_repeat("\xc2\xa0\xc2\xa0",($this->listlvl-1)*2) . $blt . ' '; } $this->_saveCellTextBuffer($ls, $this->HREF); // mPDF 5.3.99 $this->cell[$this->row][$this->col]['s'] += $this->GetStringWidth($ls); break; } /*-- END TABLES --*/ //Observation: </LI> is ignored if ($this->listlvl == 0) { //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...) //First of all, skip a line $this->listlvl++; // first depth level $this->listnum = 0; // reset $this->listoccur[$this->listlvl] = 1; $this->listlist[$this->listlvl][1] = array('TYPE'=>'disc','MAXNUM'=>$this->listnum); } if ($this->listnum == 0) { $this->listnum++; $this->textbuffer = array(); } else { if (!empty($this->textbuffer)) { if (!$this->listjustfinished) { // mPDF 5.3.11 $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype); $this->listnum++; } else { // mPDF 5.3.10 $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype, true); } } $this->textbuffer = array(); } $this->listjustfinished = false; // mPDF 5.3.11 $this->listCSSlvl++; $properties = $this->MergeCSS('LIST',$tag,$attr); if (!empty($properties)) $this->setCSS($properties,'LIST'); // mPDF 5.3.98 $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listoccur[$this->listlvl]][$this->listnum] = $this->saveInlineProperties(); // List-type if (isset($attr['TYPE']) && $attr['TYPE']) { $this->listitemtype = $attr['TYPE']; } else if (isset($properties['LIST-STYLE-TYPE'])) { $this->listitemtype = $this->_getListStyle($properties['LIST-STYLE-TYPE']); } else if (isset($properties['LIST-STYLE'])) { $this->listitemtype = $this->_getListStyle($properties['LIST-STYLE']); } else $this->listitemtype = ''; break; /*-- END LISTS --*/ }//end of switch } /*-- LISTS --*/ function _getListStyle($ls) { if (stristr($ls,'decimal')) { return '1'; } /* CSS3 list-styles numeric (selected) + I added tamil arabic-indic | bengali | devanagari | gujarati | gurmukhi | kannada | malayalam | oriya | persian | telugu | thai | urdu */ else if (preg_match('/(disc|circle|square|arabic-indic|bengali|devanagari|gujarati|gurmukhi|kannada|malayalam|oriya|persian|tamil|telugu|thai|urdu)/i',$ls,$m)) { return strtolower(trim($m[1])); } else if (stristr($ls,'lower-roman')) { return 'i'; } else if (stristr($ls,'upper-roman')) { return 'I'; } else if (stristr($ls,'lower-latin')|| stristr($ls,'lower-alpha')) { return 'a'; } else if (stristr($ls,'upper-latin') || stristr($ls,'upper-alpha')) { return 'A'; } else if (stristr($ls,'none')) { return 'none'; } else if (preg_match('/U\+([a-fA-F0-9]+)/i',$ls)) { return $ls; } else { return ''; } } /*-- END LISTS --*/ function CloseTag($tag) { $this->ignorefollowingspaces = false; //Eliminate exceeding left-side spaces //Closing tag if($tag=='OPTION') { $this->selectoption['ACTIVE'] = false; $this->lastoptionaltag = ''; } if($tag=='TTS' or $tag=='TTA' or $tag=='TTZ') { if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); } unset($this->InlineProperties[$tag]); $ltag = strtolower($tag); $this->$ltag = false; } if($tag=='FONT' || $tag=='SPAN' || $tag=='CODE' || $tag=='KBD' || $tag=='SAMP' || $tag=='TT' || $tag=='VAR' || $tag=='INS' || $tag=='STRONG' || $tag=='CITE' || $tag=='SUB' || $tag=='SUP' || $tag=='S' || $tag=='STRIKE' || $tag=='DEL' || $tag=='Q' || $tag=='EM' || $tag=='B' || $tag=='I' || $tag=='U' | $tag=='SMALL' || $tag=='BIG' || $tag=='ACRONYM') { if ($tag == 'SPAN') { if (isset($this->InlineProperties['SPAN'][$this->spanlvl]) && $this->InlineProperties['SPAN'][$this->spanlvl]) { $this->restoreInlineProperties($this->InlineProperties['SPAN'][$this->spanlvl]); } unset($this->InlineProperties['SPAN'][$this->spanlvl]); if (isset($this->InlineAnnots['SPAN'][$this->spanlvl]) && $this->InlineAnnots['SPAN'][$this->spanlvl]) { $annot = $this->InlineAnnots['SPAN'][$this->spanlvl]; } // *ANNOTATIONS* unset($this->InlineAnnots['SPAN'][$this->spanlvl]); // *ANNOTATIONS* $this->spanlvl--; } else { if (isset($this->InlineProperties[$tag]) && $this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); } unset($this->InlineProperties[$tag]); if (isset($this->InlineAnnots[$tag]) && $this->InlineAnnots[$tag]) { $annot = $this->InlineAnnots[$tag]; } // *ANNOTATIONS* unset($this->InlineAnnots[$tag]); // *ANNOTATIONS* } /*-- ANNOTATIONS --*/ if (isset($annot)) { if($this->tableLevel) { // *TABLES* $this->cell[$this->row][$this->col]['textbuffer'][] = array($annot); // *TABLES* } // *TABLES* else { // *TABLES* $this->textbuffer[] = array($annot); } // *TABLES* } /*-- END ANNOTATIONS --*/ } if($tag=='A') { $this->HREF=''; if (isset($this->InlineProperties['A'])) { $this->restoreInlineProperties($this->InlineProperties['A']); } unset($this->InlineProperties['A']); } /*-- FORMS --*/ // *********** FORM ELEMENTS ******************** if($tag=='TEXTAREA') { $this->specialcontent = ''; if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); } unset($this->InlineProperties[$tag]); } if($tag=='SELECT') { $this->lastoptionaltag = ''; $texto = ''; if (isset($this->selectoption['SELECTED'])) { $texto = $this->selectoption['SELECTED']; } if ($this->useActiveForms) { $w = $this->selectoption['MAXWIDTH']; } else { $w = $this->GetStringWidth($texto); } if ($w == 0) { $w = 5; } $objattr['type'] = 'select'; $objattr['text'] = $texto; if (isset($this->selectoption['NAME'])) { $objattr['fieldname'] = $this->selectoption['NAME']; } if (isset($this->selectoption['READONLY'])) { $objattr['readonly'] = true; } if (isset($this->selectoption['REQUIRED'])) { $objattr['required'] = true; } if (isset($this->selectoption['SPELLCHECK'])) { $objattr['spellcheck'] = true; } if (isset($this->selectoption['EDITABLE'])) { $objattr['editable'] = true; } if (isset($this->selectoption['ONCHANGE'])) { $objattr['onChange'] = $this->selectoption['ONCHANGE']; } if (isset($this->selectoption['ITEMS'])) { $objattr['items'] = $this->selectoption['ITEMS']; } if (isset($this->selectoption['MULTIPLE'])) { $objattr['multiple'] = $this->selectoption['MULTIPLE']; } if (isset($this->selectoption['DISABLED'])) { $objattr['disabled'] = $this->selectoption['DISABLED']; } if (isset($this->selectoption['TITLE'])) { $objattr['title'] = $this->selectoption['TITLE']; } if (isset($this->selectoption['COLOR'])) { $objattr['color'] = $this->selectoption['COLOR']; } if (isset($this->selectoption['SIZE'])) { $objattr['size'] = $this->selectoption['SIZE']; } if (isset($objattr['size']) && $objattr['size']>1) { $rows=$objattr['size']; } else { $rows = 1; } $objattr['fontfamily'] = $this->FontFamily; $objattr['fontsize'] = $this->FontSizePt; $objattr['width'] = $w + ($this->form->form_element_spacing['select']['outer']['h']*2)+($this->form->form_element_spacing['select']['inner']['h']*2) + ($this->FontSize*1.4); $objattr['height'] = ($this->FontSize*$rows) + ($this->form->form_element_spacing['select']['outer']['v']*2)+($this->form->form_element_spacing['select']['inner']['v']*2); $e = "\xbb\xa4\xactype=select,objattr=".serialize($objattr)."\xbb\xa4\xac"; // Clear properties - tidy up $properties = array(); // Output it to buffers if ($this->tableLevel) { // *TABLES* $this->_saveCellTextBuffer($e, $this->HREF); // mPDF 5.3.99 $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; // *TABLES* } // *TABLES* else { // *TABLES* $this->_saveTextBuffer($e, $this->HREF); // mPDF 5.3.99 } // *TABLES* $this->selectoption = array(); $this->specialcontent = ''; if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); } unset($this->InlineProperties[$tag]); } /*-- END FORMS --*/ // *********** BLOCKS ******************** if($tag=='P' || $tag=='DIV' || $tag=='H1' || $tag=='H2' || $tag=='H3' || $tag=='H4' || $tag=='H5' || $tag=='H6' || $tag=='PRE' || $tag=='FORM' || $tag=='ADDRESS' || $tag=='BLOCKQUOTE' || $tag=='CENTER' || $tag=='DT' || $tag=='DD' || $tag=='DL' || $tag=='CAPTION' ) { // mPDF 5.3.56 $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces $this->blockjustfinished=true; $this->lastblockbottommargin = $this->blk[$this->blklvl]['margin_bottom']; /*-- LISTS --*/ if ($this->listlvl>0) { return; } /*-- END LISTS --*/ /*-- TABLES --*/ if($this->tableLevel) { if ($this->linebreakjustfinished) { $this->blockjustfinished=false; } if (isset($this->InlineProperties['BLOCKINTABLE'])) { if ($this->InlineProperties['BLOCKINTABLE']) { $this->restoreInlineProperties($this->InlineProperties['BLOCKINTABLE']); } unset($this->InlineProperties['BLOCKINTABLE']); } if($tag=='PRE') { $this->ispre=false; } return; } /*-- END TABLES --*/ $this->lastoptionaltag = ''; $this->divbegin=false; $this->linebreakjustfinished=false; $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin']; /*-- CSS-FLOAT --*/ // If float contained in a float, need to extend bottom to allow for it $currpos = $this->page*1000 + $this->y; if (isset($this->blk[$this->blklvl]['float_endpos']) && $this->blk[$this->blklvl]['float_endpos'] > $currpos) { $old_page = $this->page; $new_page = intval($this->blk[$this->blklvl]['float_endpos'] /1000); if ($old_page != $new_page) { $s = $this->PrintPageBackgrounds(); // Writes after the marker so not overwritten later by page background etc. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]); $this->pageBackgrounds = array(); $this->page = $new_page; $this->ResetMargins(); $this->Reset(); $this->pageoutput[$this->page] = array(); } $this->y = (($this->blk[$this->blklvl]['float_endpos'] *1000) % 1000000)/1000; // mod changes operands to integers before processing } /*-- END CSS-FLOAT --*/ //Print content if ($this->lastblocklevelchange == 1) { $blockstate = 3; } // Top & bottom margins/padding else if ($this->lastblocklevelchange == -1) { $blockstate = 2; } // Bottom margins/padding only else { $blockstate = 0; } // called from after e.g. </table> </div> </div> ... Outputs block margin/border and padding if (count($this->textbuffer) && $this->textbuffer[count($this->textbuffer)-1]) { if (substr($this->textbuffer[count($this->textbuffer)-1][0],0,3) != "\xbb\xa4\xac") { // not special content if ($this->usingCoreFont) { $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/[ ]+$/', '', $this->textbuffer[count($this->textbuffer)-1][0]); } else { $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/[ ]+$/u', '', $this->textbuffer[count($this->textbuffer)-1][0]); } } } if (count($this->textbuffer) == 0 && $this->lastblocklevelchange != 0) { //$this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,2,true, $this->blk[$this->blklvl]['direction']); $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,$blockstate,true, $this->blk[$this->blklvl]['direction']); // mPDF 5.3.29 $this->finishFlowingBlock(true); // true = END of flowing block $this->PaintDivBB('',$blockstate); } else { $this->printbuffer($this->textbuffer,$blockstate); } $this->textbuffer=array(); if ($this->blk[$this->blklvl]['keep_block_together']) { $this->printdivbuffer(); } if ($this->kwt) { $this->kwt_height = $this->y - $this->kwt_y0; } /*-- CSS-IMAGE-FLOAT --*/ $this->printfloatbuffer(); /*-- END CSS-IMAGE-FLOAT --*/ if($tag=='PRE') { $this->ispre=false; } /*-- CSS-FLOAT --*/ if ($this->blk[$this->blklvl]['float'] == 'R') { // If width not set, here would need to adjust and output buffer $s = $this->PrintPageBackgrounds(); // Writes after the marker so not overwritten later by page background etc. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]); $this->pageBackgrounds = array(); $this->Reset(); $this->pageoutput[$this->page] = array(); for($i=($this->blklvl-1); $i >= 0; $i--) { if (isset($this->blk[$i]['float_endpos'])) { $this->blk[$i]['float_endpos'] = max($this->blk[$i]['float_endpos'], ($this->page*1000 + $this->y)); } else { $this->blk[$i]['float_endpos'] = $this->page*1000 + $this->y; } } $this->floatDivs[] = array( 'side'=>'R', 'startpage'=>$this->blk[$this->blklvl]['startpage'] , 'y0'=>$this->blk[$this->blklvl]['float_start_y'] , 'startpos'=> ($this->blk[$this->blklvl]['startpage']*1000 + $this->blk[$this->blklvl]['float_start_y']), 'endpage'=>$this->page , 'y1'=>$this->y , 'endpos'=> ($this->page*1000 + $this->y), 'w'=> $this->blk[$this->blklvl]['float_width'], 'blklvl'=>$this->blklvl, 'blockContext' => $this->blk[$this->blklvl-1]['blockContext'] ); $this->y = $this->blk[$this->blklvl]['float_start_y'] ; $this->page = $this->blk[$this->blklvl]['startpage'] ; $this->ResetMargins(); $this->pageoutput[$this->page] = array(); } if ($this->blk[$this->blklvl]['float'] == 'L') { // If width not set, here would need to adjust and output buffer $s = $this->PrintPageBackgrounds(); // Writes after the marker so not overwritten later by page background etc. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]); $this->pageBackgrounds = array(); $this->Reset(); $this->pageoutput[$this->page] = array(); for($i=($this->blklvl-1); $i >= 0; $i--) { if (isset($this->blk[$i]['float_endpos'])) { $this->blk[$i]['float_endpos'] = max($this->blk[$i]['float_endpos'], ($this->page*1000 + $this->y)); } else { $this->blk[$i]['float_endpos'] = $this->page*1000 + $this->y; } } $this->floatDivs[] = array( 'side'=>'L', 'startpage'=>$this->blk[$this->blklvl]['startpage'] , 'y0'=>$this->blk[$this->blklvl]['float_start_y'] , 'startpos'=> ($this->blk[$this->blklvl]['startpage']*1000 + $this->blk[$this->blklvl]['float_start_y']), 'endpage'=>$this->page , 'y1'=>$this->y , 'endpos'=> ($this->page*1000 + $this->y), 'w'=> $this->blk[$this->blklvl]['float_width'], 'blklvl'=>$this->blklvl, 'blockContext' => $this->blk[$this->blklvl-1]['blockContext'] ); $this->y = $this->blk[$this->blklvl]['float_start_y'] ; $this->page = $this->blk[$this->blklvl]['startpage'] ; $this->ResetMargins(); $this->pageoutput[$this->page] = array(); } /*-- END CSS-FLOAT --*/ // mPDF 5.3.42 VISIBILITY if (isset($this->blk[$this->blklvl]['visibility']) && $this->blk[$this->blklvl]['visibility']!='visible') { $this->SetVisibility('visible'); } // mPDF 5.3.03 if (isset($this->blk[$this->blklvl]['page_break_after'])) { $page_break_after = $this->blk[$this->blklvl]['page_break_after']; } else { $page_break_after = ''; } //Reset values $this->Reset(); if ($this->blklvl > 0) { // ==0 SHOULDN'T HAPPEN - NOT XHTML if ($this->blk[$this->blklvl]['tag'] == $tag) { unset($this->blk[$this->blklvl]); $this->blklvl--; } //else { echo $tag; exit; } // debug - forces error if incorrectly nested html tags } $this->lastblocklevelchange = -1 ; // Reset Inline-type properties if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']); } $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin']; // mPDF 5.3.03 if ($page_break_after) { $save_blklvl = $this->blklvl; $save_blk = $this->blk; $save_silp = $this->saveInlineProperties(); $save_spanlvl = $this->spanlvl; $save_ilp = $this->InlineProperties; if ($this->blklvl>1) { // Close any open block tags for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); } // Output any text left in buffer if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); $this->textbuffer=array(); } } /*-- COLUMNS --*/ $save_cols = false; if ($this->ColActive) { $save_cols = true; $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off $this->SetColumns(0); } /*-- END COLUMNS --*/ if ($page_break_after == 'RIGHT') { $this->AddPage($this->CurOrientation,'NEXT-ODD','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } else if ($page_break_after == 'LEFT') { $this->AddPage($this->CurOrientation,'NEXT-EVEN','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } else { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } if (!$this->restoreBlockPagebreaks) { $this->blklvl = 0; $this->lastblocklevelchange = 0; $this->blk = array(); $this->initialiseBlock($this->blk[0]); $this->blk[0]['width'] =& $this->pgwidth; $this->blk[0]['inner_width'] =& $this->pgwidth; $this->blk[0]['blockContext'] = $this->blockContext; $properties = $this->MergeCSS('BLOCK','BODY',''); $this->setCSS($properties,'','BODY'); $this->blklvl++; $currblk =& $this->blk[$this->blklvl]; $prevblk =& $this->blk[$this->blklvl-1]; $this->initialiseBlock($currblk); $currblk['tag'] = $tag; $currblk['attr'] = $attr; $this->Reset(); $properties = $this->MergeCSS('BLOCK',$tag,$attr); } /*-- COLUMNS --*/ if ($save_cols) { // Restore columns $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap); } /*-- END COLUMNS --*/ if ($this->restoreBlockPagebreaks && !$this->tableLevel && !$this->listlvl) { $this->blk = $save_blk; // Re-open block tags $t = $this->blk[0]['tag']; $a = $this->blk[0]['attr']; $this->blklvl = 0; for ($b=0; $b<=$save_blklvl;$b++) { $tc = $t; $ac = $a; $t = $this->blk[$b+1]['tag']; $a = $this->blk[$b+1]['attr']; unset($this->blk[$b+1]); $this->OpenTag($tc,$ac); } $this->spanlvl = $save_spanlvl; $this->InlineProperties = $save_ilp; $this->restoreInlineProperties($save_silp); } } } /*-- TABLES --*/ if($tag=='TH') $this->SetStyle('B',false); if(($tag=='TH' or $tag=='TD') && $this->tableLevel) { $this->lastoptionaltag = 'TR'; unset($this->tablecascadeCSS[$this->tbCSSlvl]); $this->tbCSSlvl--; if (!$this->tdbegin) { return; } // mPDF 5.3.79 $this->tdbegin = false; // Added for correct calculation of cell column width - otherwise misses the last line if not end </p> etc. if (!isset($this->cell[$this->row][$this->col]['maxs'])) { if (!is_array($this->cell[$this->row][$this->col])) { $this->Error("You may have an error in your HTML code e.g. &lt;/td&gt;&lt;/td&gt;"); } $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) { $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } // Remove last <br> if at end of cell if (isset($this->cell[$this->row][$this->col]['textbuffer'])) { $ntb = count($this->cell[$this->row][$this->col]['textbuffer']); } else { $ntb = 0; } if ($ntb>1 && $this->cell[$this->row][$this->col]['textbuffer'][$ntb-1][0] == "\n") { unset($this->cell[$this->row][$this->col]['textbuffer'][$ntb-1]); } // mPDF 5.3.79 if ($this->cacheTables) { $clen = $this->_cacheCell($this->cell[$this->row][$this->col], $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cache']); $this->cell[$this->row][$this->col] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['ptr']; $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['ptr'] += $clen; } // mPDF 5.3.62 if ($this->tablethead) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead'][$this->row] = true; if ($this->tableLevel==1) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['headernrows'] = max($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['headernrows'] , ($this->row+1)); } } if ($this->tabletfoot) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$this->row] = true; if ($this->tableLevel==1) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['footernrows'] = max($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['footernrows'] , ($this->row+1 - $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['headernrows'] )); } } $this->Reset(); } if($tag=='TR' && $this->tableLevel) { // mPDF 5.3.78 // If Border set on TR - Update right border if (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-left'][$this->row])) { // mPDF 5.3.79 if ($this->cacheTables) { $c = $this->_uncacheCell($this->cell[$this->row][$this->col], $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cache'], null); } else { $c =& $this->cell[$this->row][$this->col]; } if ($c) { if ($this->packTableData) { $cell = $this->_unpackCellBorder($c['borderbin'] ); } else { $cell = $c; } $cell['border_details']['R'] = $this->border_details($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trborder-right'][$this->row]); $this->setBorder($cell['border'], _BORDER_RIGHT, $cell['border_details']['R']['s']); if ($this->packTableData) { $c['borderbin'] = $this->_packCellBorder($cell); unset($c['border']); unset($c['border_details']); } else { $c = $cell; } } // mPDF 5.3.79 if ($this->cacheTables) { $fh = fopen($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cache'], "r+b"); $this->_cacheUpdateBorder($c, $fh, $this->cell[$this->row][$this->col]); fclose($fh); } } $this->lastoptionaltag = ''; unset($this->tablecascadeCSS[$this->tbCSSlvl]); $this->tbCSSlvl--; $this->trow_text_rotate = ''; $this->tabletheadjustfinished = false; } if($tag=='TBODY') { $this->lastoptionaltag = ''; unset($this->tablecascadeCSS[$this->tbCSSlvl]); $this->tbCSSlvl--; } if($tag=='THEAD') { $this->lastoptionaltag = ''; unset($this->tablecascadeCSS[$this->tbCSSlvl]); $this->tbCSSlvl--; $this->tablethead = 0; $this->tabletheadjustfinished = true; $this->ResetStyles(); $this->thead_font_weight = ''; $this->thead_font_style = ''; $this->thead_font_smCaps = ''; $this->thead_valign_default = ''; $this->thead_textalign_default = ''; } if($tag=='TFOOT') { $this->lastoptionaltag = ''; unset($this->tablecascadeCSS[$this->tbCSSlvl]); $this->tbCSSlvl--; $this->tabletfoot = 0; $this->ResetStyles(); $this->tfoot_font_weight = ''; $this->tfoot_font_style = ''; $this->tfoot_font_smCaps = ''; $this->tfoot_valign_default = ''; $this->tfoot_textalign_default = ''; } if($tag=='TABLE') { // TABLE-END ( if ($this->progressBar) { $this->UpdateProgressBar(1,'','TABLE'); } // *PROGRESS-BAR* if ($this->progressBar) { $this->UpdateProgressBar(7,0,''); } // *PROGRESS-BAR* $this->lastoptionaltag = ''; unset($this->tablecascadeCSS[$this->tbCSSlvl]); $this->tbCSSlvl--; $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = $this->cell; $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['wc'] = array_pad(array(),$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'],array('miw'=>0,'maw'=>0)); $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['hr'] = array_pad(array(),$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr'],0); // Move table footer <tfoot> row to end of table if (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) && count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'])) { $tfrows = array(); foreach($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'] AS $r=>$val) { if ($val) { $tfrows[] = $r; } } $temp = array(); $temptf = array(); foreach($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] AS $k=>$row) { if (in_array($k,$tfrows)) { $temptf[] = $row; } else { $temp[] = $row; } } $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'] = array(); for($i=count($temp) ; $i<(count($temp)+count($temptf)); $i++) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$i] = true; } // Update nestedpos row references if (count($this->table[($this->tableLevel+1)])) { foreach($this->table[($this->tableLevel+1)] AS $nid=>$nested) { $this->table[($this->tableLevel+1)][$nid]['nestedpos'][0] -= count($temptf); } } $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = array_merge($temp, $temptf); // Update other arays set on row number // [trbackground-images] [trgradients] $temptrbgi = array(); $temptrbgg = array(); $temptrbgc = array(); $temptrbgc[-1] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][-1]; for($k=0; $k<$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']; $k++) { if (!in_array($k,$tfrows)) { $temptrbgi[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'][$k]; $temptrbgg[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'][$k]; $temptrbgc[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$k]; } } for($k=0; $k<$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']; $k++) { if (in_array($k,$tfrows)) { $temptrbgi[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'][$k]; $temptrbgg[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'][$k]; $temptrbgc[] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$k]; } } $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trbackground-images'] = $temptrbgi; $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['trgradients'] = $temptrbgg; $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'] = $temptrbgc ; // Should Update all other arays set on row number, but cell properties have been set so not needed // [bgcolor] [trborder-left] [trborder-right] [trborder-top] [trborder-bottom] } if ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['direction']=='rtl') { $this->_reverseTableDir($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]); } // Fix Borders ********************************************* $this->_fixTableBorders($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]); if ($this->progressBar) { $this->UpdateProgressBar(7,10,' '); } // *PROGRESS-BAR* if ($this->ColActive) { $this->table_rotate = 0; } // *COLUMNS* if ($this->table_rotate <> 0) { $this->tablebuffer = ''; // Max width for rotated table $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 1); $this->tbrot_maxh = $this->blk[$this->blklvl]['inner_width'] ; // Max width for rotated table $this->tbrot_align = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['a'] ; } $this->shrin_k = 1; if ($this->shrink_tables_to_fit < 1) { $this->shrink_tables_to_fit = 1; } if (!$this->shrink_this_table_to_fit) { $this->shrink_this_table_to_fit = $this->shrink_tables_to_fit; } if ($this->tableLevel>1) { // deal with nested table $this->_tableColumnWidth($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]],true); $tmiw = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['miw']; $tmaw = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['maw']; $tl = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['tl']; // Go down to lower table level $this->tableLevel--; // Reset lower level table $this->base_table_properties = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['baseProperties']; $this->cell = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells']; $this->row = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currrow']; $this->col = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currcol']; $objattr = array(); $objattr['type'] = 'nestedtable'; $objattr['nestedcontent'] = $this->tbctr[($this->tableLevel+1)]; $objattr['table'] = $this->tbctr[$this->tableLevel]; $objattr['row'] = $this->row; $objattr['col'] = $this->col; $objattr['level'] = $this->tableLevel; $e = "\xbb\xa4\xactype=nestedtable,objattr=".serialize($objattr)."\xbb\xa4\xac"; $this->_saveCellTextBuffer($e); // mPDF 5.3.99 $this->cell[$this->row][$this->col]['s'] += $tl ; if (!isset($this->cell[$this->row][$this->col]['maxs'])) { $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) { $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s']; } $this->cell[$this->row][$this->col]['s'] = 0;// reset if ((isset($this->cell[$this->row][$this->col]['nestedmaw']) && $this->cell[$this->row][$this->col]['nestedmaw'] < $tmaw) || !isset($this->cell[$this->row][$this->col]['nestedmaw'])) { $this->cell[$this->row][$this->col]['nestedmaw'] = $tmaw ; } if ((isset($this->cell[$this->row][$this->col]['nestedmiw']) && $this->cell[$this->row][$this->col]['nestedmiw'] < $tmiw) || !isset($this->cell[$this->row][$this->col]['nestedmiw'])) { $this->cell[$this->row][$this->col]['nestedmiw'] = $tmiw ; } // mPDF 5.3.79 ?? Removed as Not needed for anything // $this->cell[$this->row][$this->col]['nestedcontent'][] = $this->tbctr[($this->tableLevel+1)]; $this->tdbegin = true; $this->nestedtablejustfinished = true; $this->ignorefollowingspaces = true; return; } $this->cMarginL = 0; $this->cMarginR = 0; $this->cMarginT = 0; $this->cMarginB = 0; $this->cellPaddingL = 0; $this->cellPaddingR = 0; $this->cellPaddingT = 0; $this->cellPaddingB = 0; // mPDF 5.3.36 // mPDF 5.3.76 if (isset($this->table[1][1]['overflow']) && $this->table[1][1]['overflow']=='visible') { if ($this->kwt || $this->table_rotate || $this->table_keep_together || $this->ColActive) { $this->kwt = false; $this->table_rotate = 0; $this->table_keep_together = false; //die("mPDF Warning: You cannot use CSS overflow:visible together with any of these functions: 'Keep-with-table', rotated tables, page-break-inside:avoid, or columns"); } $this->_tableColumnWidth($this->table[1][1],true); $this->_tableWidth($this->table[1][1]); } else { if (!$this->kwt_saved) { $this->kwt_height = 0; } list($check,$tablemiw) = $this->_tableColumnWidth($this->table[1][1],true); $save_table = $this->table; // mPDF 5.3.79 if ($this->cacheTables) { $this->_backupCacheFiles(); } $reset_to_minimum_width = false; $added_page = false; if ($check > 1) { if ($check > $this->shrink_this_table_to_fit && $this->table_rotate) { if ($this->y != $this->tMargin) { // mPDF 5.3.69 $this->AddPage($this->CurOrientation); $this->kwt_moved = true; } $added_page = true; $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height; //$check = $tablemiw/$this->tbrot_maxw; // undo any shrink $check = 1; // undo any shrink } $reset_to_minimum_width = true; } if ($reset_to_minimum_width) { $this->shrin_k = $check; $this->default_font_size /= $this->shrin_k; $this->SetFontSize($this->default_font_size, false ); $this->shrinkTable($this->table[1][1],$this->shrin_k); $this->_tableColumnWidth($this->table[1][1],false); // repeat // Starting at $this->innermostTableLevel // Shrink table values - and redo columnWidth for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) { for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) { $this->shrinkTable($this->table[$lvl][$nid],$this->shrin_k); $this->_tableColumnWidth($this->table[$lvl][$nid],false); } } } // Set table cell widths for top level table // Use $shrin_k to resize but don't change again $this->SetLineHeight('',$this->table_lineheight); // Top level table $this->_tableWidth($this->table[1][1]); } // mPDF 5.3.36 // mPDF 5.3.79 // Now work through any nested tables setting child table[w'] = parent cell['w'] // Now do nested tables _tableWidth for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) { for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) { // HERE set child table width = cell width list($parentrow, $parentcol, $parentnid) = $this->table[$lvl][$nid]['nestedpos']; // mPDF 5.3.79 if ($this->cacheTables) { $c = $this->_uncacheCell($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol], $this->table[($lvl-1)][$parentnid]['cache'], null); } else $c =& $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]; if (isset($c['colspan']) && $c['colspan']> 1) { $parentwidth = 0; for($cs=0;$cs<$c['colspan'] ; $cs++) { $parentwidth += $this->table[($lvl-1)][$parentnid]['wc'][$parentcol+$cs]; } } else { $parentwidth = $this->table[($lvl-1)][$parentnid]['wc'][$parentcol]; } //$parentwidth -= ALLOW FOR PADDING ETC.in parent cell if (!$this->simpleTables){ if ($this->packTableData) { list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']); } else { $br = $c['border_details']['R']['w']; $bl = $c['border_details']['L']['w']; } if ($this->table[$lvl-1][$parentnid]['borders_separate']) { $parentwidth -= $br + $bl + $c['padding']['L'] + $c['padding']['R'] + $this->table[($lvl-1)][$parentnid]['border_spacing_H']; } else { $parentwidth -= $br/2 + $bl/2 + $c['padding']['L'] + $c['padding']['R']; } } else if ($this->simpleTables){ if ($this->table[$lvl-1][$parentnid]['borders_separate']) { $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w'] + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w'] + $c['padding']['L'] + $c['padding']['R'] + $this->table[($lvl-1)][$parentnid]['border_spacing_H']; } else { $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']/2 + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']/2 + $c['padding']['L'] + $c['padding']['R']; } } if (isset($this->table[$lvl][$nid]['wpercent']) && $this->table[$lvl][$nid]['wpercent'] && $lvl>1) { $this->table[$lvl][$nid]['w'] = $parentwidth; } else if ($parentwidth > $this->table[$lvl][$nid]['maw']) { $this->table[$lvl][$nid]['w'] = $this->table[$lvl][$nid]['maw']; } else { $this->table[$lvl][$nid]['w'] = $parentwidth; } unset($c); // mPDF 5.3.79 $this->_tableWidth($this->table[$lvl][$nid]); } } // Starting at $this->innermostTableLevel // Cascade back up nested tables: setting heights back up the tree for($lvl=$this->innermostTableLevel;$lvl>0;$lvl--) { for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) { list($tableheight,$maxrowheight,$fullpage,$remainingpage, $maxfirstrowheight) = $this->_tableHeight($this->table[$lvl][$nid]); } } if ($this->progressBar) { $this->UpdateProgressBar(7,20,' '); } // *PROGRESS-BAR* // mPDF 5.3.36 if ($this->table[1][1]['overflow']=='visible') { if ($maxrowheight > $fullpage) { die("mPDF Warning: A Table row is greater than available height. You cannot use CSS overflow:visible"); } if ($maxfirstrowheight > $remainingpage) { $this->AddPage($this->CurOrientation); } $r = 0; $c = 0; $p = 0; $y = 0; while (!$finished) { list($finished,$r,$c,$p,$y,$y0) = $this->_tableWrite($this->table[1][1],true,$r,$c,$p,$y); if (!$finished) { $this->AddPage($this->CurOrientation); // mPDF 5.3.43 // If printed something on first spread, set same y if ($r==0 && $y0 > -1) { $this->y = $y0; } } } } else { $recalculate = 1; $forcerecalc = false; // RESIZING ALGORITHM if ($maxrowheight > $fullpage) { $recalculate = $this->tbsqrt($maxrowheight / $fullpage, 1); $forcerecalc = true; } else if ($this->table_rotate) { // NB $remainingpage == $fullpage == the width of the page if ($tableheight > $remainingpage) { // If can fit on remainder of page whilst respecting autsize value.. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, 1)) <= $this->shrink_this_table_to_fit) { $recalculate = $this->tbsqrt($tableheight / $remainingpage, 1); } else if (!$added_page) { if ($this->y != $this->tMargin) { // mPDF 5.3.69 $this->AddPage($this->CurOrientation); $this->kwt_moved = true; } $added_page = true; $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height; // 0.001 to force it to recalculate $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink } } else { $recalculate = 1; } } else if ($this->table_keep_together || ($this->table[1][1]['nr']==1 && !$this->writingHTMLfooter)) { if ($tableheight > $fullpage) { if (($this->shrin_k * $this->tbsqrt($tableheight / $fullpage, 1)) <= $this->shrink_this_table_to_fit) { $recalculate = $this->tbsqrt($tableheight / $fullpage, 1); } else if ($this->tableMinSizePriority) { $this->table_keep_together = false; $recalculate = 1.001; } else { if ($this->y != $this->tMargin) { // mPDF 5.1 $this->AddPage($this->CurOrientation); $this->kwt_moved = true; } $added_page = true; $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height; $recalculate = $this->tbsqrt($tableheight / $fullpage, 1); } } else if ($tableheight > $remainingpage) { // If can fit on remainder of page whilst respecting autsize value.. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, 1)) <= $this->shrink_this_table_to_fit) { $recalculate = $this->tbsqrt($tableheight / $remainingpage, 1); } else { if ($this->y != $this->tMargin) { $this->AddPage($this->CurOrientation); $this->kwt_moved = true; } $added_page = true; $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height; $recalculate = 1.001; } } else { $recalculate = 1; } } else { $recalculate = 1; } if ($recalculate > $this->shrink_this_table_to_fit && !$forcerecalc) { $recalculate = $this->shrink_this_table_to_fit; } $iteration = 1; // RECALCULATE while($recalculate <> 1) { $this->shrin_k1 = $recalculate ; $this->shrin_k *= $recalculate ; $this->default_font_size /= ($this->shrin_k1) ; $this->SetFontSize($this->default_font_size, false ); $this->SetLineHeight('',$this->table_lineheight); $this->table = $save_table; // mPDF 5.3.79 if ($this->cacheTables) { $this->_restoreCacheFiles(); } if ($this->shrin_k <> 1) { $this->shrinkTable($this->table[1][1],$this->shrin_k); } $this->_tableColumnWidth($this->table[1][1],false); // repeat // Starting at $this->innermostTableLevel // Shrink table values - and redo columnWidth for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) { for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) { if ($this->shrin_k <> 1) { $this->shrinkTable($this->table[$lvl][$nid],$this->shrin_k); } $this->_tableColumnWidth($this->table[$lvl][$nid],false); } } // Set table cell widths for top level table // Top level table $this->_tableWidth($this->table[1][1]); // mPDF 5.3.79 // Now work through any nested tables setting child table[w'] = parent cell['w'] // Now do nested tables _tableWidth for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) { for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) { // HERE set child table width = cell width list($parentrow, $parentcol, $parentnid) = $this->table[$lvl][$nid]['nestedpos']; // mPDF 5.3.79 if ($this->cacheTables) { $c = $this->_uncacheCell($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol], $this->table[($lvl-1)][$parentnid]['cache'], null); } else $c =& $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]; if (isset($c['colspan']) && $c['colspan']> 1) { $parentwidth = 0; for($cs=0;$cs<$c['colspan'] ; $cs++) { $parentwidth += $this->table[($lvl-1)][$parentnid]['wc'][$parentcol+$cs]; } } else { $parentwidth = $this->table[($lvl-1)][$parentnid]['wc'][$parentcol]; } //$parentwidth -= ALLOW FOR PADDING ETC.in parent cell if (!$this->simpleTables){ if ($this->packTableData) { list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']); } else { $br = $c['border_details']['R']['w']; $bl = $c['border_details']['L']['w']; } if ($this->table[$lvl-1][$parentnid]['borders_separate']) { $parentwidth -= $br + $bl + $c['padding']['L'] + $c['padding']['R'] + $this->table[($lvl-1)][$parentnid]['border_spacing_H']; } else { $parentwidth -= $br/2 + $bl/2 + $c['padding']['L'] + $c['padding']['R']; } } else if ($this->simpleTables){ if ($this->table[$lvl-1][$parentnid]['borders_separate']) { $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w'] + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w'] + $c['padding']['L'] + $c['padding']['R'] + $this->table[($lvl-1)][$parentnid]['border_spacing_H']; } else { $parentwidth -= ($this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w'] + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']) /2 + $c['padding']['L'] + $c['padding']['R']; } } if (isset($this->table[$lvl][$nid]['wpercent']) && $this->table[$lvl][$nid]['wpercent'] && $lvl>1) { $this->table[$lvl][$nid]['w'] = $parentwidth; } else if ($parentwidth > $this->table[$lvl][$nid]['maw']) { $this->table[$lvl][$nid]['w'] = $this->table[$lvl][$nid]['maw'] ; } else { $this->table[$lvl][$nid]['w'] = $parentwidth; } unset($c); // mPDF 5.3.79 $this->_tableWidth($this->table[$lvl][$nid]); } } // Starting at $this->innermostTableLevel // Cascade back up nested tables: setting heights back up the tree for($lvl=$this->innermostTableLevel;$lvl>0;$lvl--) { for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) { list($tableheight,$maxrowheight,$fullpage,$remainingpage, $maxfirstrowheight) = $this->_tableHeight($this->table[$lvl][$nid]); } } // RESIZING ALGORITHM if ($maxrowheight > $fullpage) { $recalculate = $this->tbsqrt($maxrowheight / $fullpage, $iteration); $iteration++; } else if ($this->table_rotate && $tableheight > $remainingpage && !$added_page) { // If can fit on remainder of page whilst respecting autosize value.. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, $iteration)) <= $this->shrink_this_table_to_fit) { $recalculate = $this->tbsqrt($tableheight / $remainingpage, $iteration); $iteration++; } else { if (!$added_page) { $this->AddPage($this->CurOrientation); $added_page = true; $this->kwt_moved = true; $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height; } // 0.001 to force it to recalculate $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink } } else if ($this->table_keep_together || ($this->table[1][1]['nr']==1 && !$this->writingHTMLfooter)) { if ($tableheight > $fullpage) { if (($this->shrin_k * $this->tbsqrt($tableheight / $fullpage, $iteration)) <= $this->shrink_this_table_to_fit) { $recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++; } else if ($this->tableMinSizePriority) { $this->table_keep_together = false; $recalculate = (1 / $this->shrin_k) + 0.001; } else { if (!$added_page && $this->y != $this->tMargin) { $this->AddPage($this->CurOrientation); $added_page = true; $this->kwt_moved = true; $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height; } $recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++; } } else if ($tableheight > $remainingpage) { // If can fit on remainder of page whilst respecting autosize value.. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, $iteration)) <= $this->shrink_this_table_to_fit) { $recalculate = $this->tbsqrt($tableheight / $remainingpage, $iteration); $iteration++; } else { if (!$added_page) { $this->AddPage($this->CurOrientation); $added_page = true; $this->kwt_moved = true; $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height; } //$recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++; $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink } } else { $recalculate = 1; } } else { $recalculate = 1; } } if ($maxfirstrowheight > $remainingpage && !$added_page && !$this->table_rotate && !$this->ColActive && !$this->table_keep_together && !$this->writingHTMLheader && !$this->writingHTMLfooter) { $this->AddPage($this->CurOrientation); $this->kwt_moved = true; } // keep-with-table: if page has advanced, print out buffer now, else done in fn. _Tablewrite() if ($this->kwt_saved && $this->kwt_moved) { $this->printkwtbuffer(); $this->kwt_moved = false; $this->kwt_saved = false; } if ($this->progressBar) { $this->UpdateProgressBar(7,30,' '); } // *PROGRESS-BAR* // Recursively writes all tables starting at top level $this->_tableWrite($this->table[1][1]); if ($this->table_rotate && $this->tablebuffer) { $this->PageBreakTrigger=$this->h-$this->bMargin; $save_tr = $this->table_rotate; $save_y = $this->y; $this->table_rotate = 0; $this->y = $this->tbrot_y0; $h = $this->tbrot_w; $this->DivLn($h,$this->blklvl,true); $this->table_rotate = $save_tr; $this->y = $save_y; $this->printtablebuffer(); } $this->table_rotate = 0; } // mPDF 5.3.36 $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin']; // mPDF 5.3.91 $this->maxPosR = max($this->maxPosR , ($this->x + $this->table[1][1]['w'])); $this->blockjustfinished=true; $this->lastblockbottommargin = $this->table[1][1]['margin']['B']; //Reset values // mPDF 5.3.55 if (isset($this->table[1][1]['page_break_after'])) { $page_break_after = $this->table[1][1]['page_break_after']; } else { $page_break_after = ''; } // Keep-with-table $this->kwt = false; $this->kwt_y0 = 0; $this->kwt_x0 = 0; $this->kwt_height = 0; $this->kwt_buffer = array(); $this->kwt_Links = array(); $this->kwt_Annots = array(); $this->kwt_moved = false; $this->kwt_saved = false; $this->kwt_Reference = array(); $this->kwt_BMoutlines = array(); $this->kwt_toc = array(); $this->shrin_k = 1; $this->shrink_this_table_to_fit = 0; unset($this->table); $this->table=array(); //array $this->tableLevel=0; $this->tbctr=array(); $this->innermostTableLevel=0; $this->tbCSSlvl = 0; $this->tablecascadeCSS = array(); unset($this->cell); $this->cell=array(); //array $this->col=-1; //int $this->row=-1; //int $this->Reset(); $this->cellPaddingL = 0; $this->cellPaddingT = 0; $this->cellPaddingR = 0; $this->cellPaddingB = 0; $this->cMarginL = 0; $this->cMarginT = 0; $this->cMarginR = 0; $this->cMarginB = 0; $this->default_font_size = $this->original_default_font_size; $this->default_font = $this->original_default_font; $this->SetFontSize($this->default_font_size, false); $this->SetFont($this->default_font,'',0,false); $this->SetLineHeight(); if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']);} if ($this->progressBar) { $this->UpdateProgressBar(7,100,' '); } // *PROGRESS-BAR* // mPDF 5.3.55 if ($page_break_after) { $save_blklvl = $this->blklvl; $save_blk = $this->blk; $save_silp = $this->saveInlineProperties(); $save_spanlvl = $this->spanlvl; $save_ilp = $this->InlineProperties; if ($this->blklvl>1) { // Close any open block tags for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); } // Output any text left in buffer if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); $this->textbuffer=array(); } } /*-- COLUMNS --*/ $save_cols = false; if ($this->ColActive) { $save_cols = true; $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off $this->SetColumns(0); } /*-- END COLUMNS --*/ if ($page_break_after == 'RIGHT') { $this->AddPage($this->CurOrientation,'NEXT-ODD','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } else if ($page_break_after == 'LEFT') { $this->AddPage($this->CurOrientation,'NEXT-EVEN','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } else { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } if (!$this->restoreBlockPagebreaks) { $this->blklvl = 0; $this->lastblocklevelchange = 0; $this->blk = array(); $this->initialiseBlock($this->blk[0]); $this->blk[0]['width'] =& $this->pgwidth; $this->blk[0]['inner_width'] =& $this->pgwidth; $this->blk[0]['blockContext'] = $this->blockContext; $properties = $this->MergeCSS('BLOCK','BODY',''); $this->setCSS($properties,'','BODY'); // mPDF 5.3.70 } /*-- COLUMNS --*/ if ($save_cols) { // Restore columns $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap); } /*-- END COLUMNS --*/ if ($this->restoreBlockPagebreaks) { $this->blk = $save_blk; // Re-open block tags $t = $this->blk[0]['tag']; $a = $this->blk[0]['attr']; $this->blklvl = 0; for ($b=0; $b<=$save_blklvl;$b++) { $tc = $t; $ac = $a; $t = $this->blk[$b+1]['tag']; $a = $this->blk[$b+1]['attr']; unset($this->blk[$b+1]); $this->OpenTag($tc,$ac); } $this->spanlvl = $save_spanlvl; $this->InlineProperties = $save_ilp; $this->restoreInlineProperties($save_silp); } } } /*-- END TABLES --*/ /*-- LISTS --*/ // *********** LISTS ******************** if($tag=='LI') { $this->lastoptionaltag = ''; unset($this->listcascadeCSS[$this->listCSSlvl]); $this->listCSSlvl--; if (isset($this->listoccur[$this->listlvl]) && isset($this->InlineProperties['LIST'][$this->listlvl][$this->listoccur[$this->listlvl]])) { $this->restoreInlineProperties($this->InlineProperties['LIST'][$this->listlvl][$this->listoccur[$this->listlvl]]); } } if(($tag=='UL') or ($tag=='OL')) { $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces unset($this->listcascadeCSS[$this->listCSSlvl]); $this->listCSSlvl--; $this->lastoptionaltag = ''; /*-- TABLES --*/ // A simple list for inside a table if($this->tableLevel) { $this->listlist[$this->listlvl]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum unset($this->listlist[$this->listlvl]); $this->listlvl--; if (isset($this->listlist[$this->listlvl]['MAXNUM'])) { $this->listnum = $this->listlist[$this->listlvl]['MAXNUM']; } // restore previous levels if ($this->listlvl == 0) { $this->listjustfinished = true; } return; } /*-- END TABLES --*/ if ($this->listlvl > 1) { // returning one level $this->listjustfinished=true; if (!empty($this->textbuffer)) { $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype); } else { $this->listnum--; } $this->textbuffer = array(); $occur = $this->listoccur[$this->listlvl]; $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum $this->listlvl--; $occur = $this->listoccur[$this->listlvl]; $this->listnum = $this->listlist[$this->listlvl][$occur]['MAXNUM']; // recover previous level's number $this->listtype = $this->listlist[$this->listlvl][$occur]['TYPE']; // recover previous level's type if ($this->InlineProperties['LIST'][$this->listlvl][$occur]) { $this->restoreInlineProperties($this->InlineProperties['LIST'][$this->listlvl][$occur]); } } else { // We are closing the last OL/UL tag if (!empty($this->textbuffer)) { $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype); } else { $this->listnum--; } $occur = $this->listoccur[$this->listlvl]; $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; $this->textbuffer = array(); $this->listlvl--; $this->printlistbuffer(); unset($this->InlineProperties['LIST']); // SPACING AFTER LIST (Top level only) $this->Ln(0); if ($this->list_margin_bottom) { $this->DivLn($this->list_margin_bottom,$this->blklvl,true,1); // collapsible } if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']);} $this->listjustfinished = true; $this->listCSSlvl = 0; $this->listcascadeCSS = array(); $this->blockjustfinished=true; $this->lastblockbottommargin = $this->list_margin_bottom; } } /*-- END LISTS --*/ } /*-- TABLES --*/ // This function determines the shrink factor when resizing tables // val is the table_height / page_height_available // returns a scaling factor used as $shrin_k to resize the table // Overcompensating will be quicker but may unnecessarily shrink table too much // Undercompensating means it will reiterate more times (taking more processing time) function tbsqrt($val, $iteration=3) { $k = 4; // Alters number of iterations until it returns $val itself - Must be > 2 // Probably best guess and most accurate if ($iteration==1) return sqrt($val); // Faster than using sqrt (because it won't undercompensate), and gives reasonable results //return 1+(($val-1)/2); $x = 2-(($iteration-2)/($k-2)); if ($x == 0) { $ret = $val+0.00001; } else if ($x < 0) { $ret = 1 + ( pow(2, ($iteration-2-$k))/1000 ); } else { $ret = 1+(($val-1)/$x); } return $ret; } /*-- END TABLES --*/ /*-- LISTS --*/ function printlistbuffer() { //Save x coordinate $x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin']; $this->cMarginL = 0; $this->cMarginR = 0; $currIndentLvl = -1; $lastIndent = array(); $bak_page = $this->page; $indent = 0; foreach($this->listitem as $item) { // COLS $oldcolumn = $this->CurrCol; $this->bulletarray = array(); //Get list's buffered data $this->listlvl = $lvl = $item[0]; $num = $item[1]; $this->textbuffer = $item[2]; $occur = $item[3]; if ($item[4]) { $type = $item[4]; } // listitemtype else { $type = $this->listlist[$lvl][$occur]['TYPE']; } $maxnum = $this->listlist[$lvl][$occur]['MAXNUM']; $this->restoreInlineProperties($this->InlineProperties['LIST'][$lvl][$occur]); $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); // force to write $clh = $this->FontSize; $this->SetLineHeight($this->FontSizePt,$this->list_lineheight[$lvl][$occur]); $this->listOcc = $occur; $this->listnum = $num; if (isset($this->list_align[$this->listlvl][$occur])) { $this->divalign = $this->list_align[$this->listlvl][$occur]; } else { if (isset($this->blk[$this->blklvl]['direction']) && $this->blk[$this->blklvl]['direction']=='rtl') { $this->divalign = 'R'; } else { $this->divalign = 'L'; } } // Set the bullet fontsize $bullfs = $this->InlineProperties['LISTITEM'][$lvl][$occur][$num]['size']; $space_width = $this->GetCharWidth(' ',false) * 1.5; // mPDF 5.3.04 //Set default width & height values $this->divwidth = $this->blk[$this->blklvl]['inner_width']; $this->divheight = $this->lineheight; $typefont = $this->FontFamily; if (preg_match('/U\+([a-fA-F0-9]+)/i',$type,$m)) { if ($this->_charDefined($this->CurrentFont['cw'],hexdec($m[1]))) { $list_item_marker = codeHex2utf($m[1]); } else { $list_item_marker = '-'; } $blt_width = $this->GetStringWidth($list_item_marker); $typefont = ''; if (preg_match('/rgb\(.*?\)/',$type,$m)) { $list_item_color = $this->ConvertColor($m[0]); } } else { $list_item_color = false; switch($type) //Format type { case '1': if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $num; } else { $list_item_marker = $num . $this->list_number_suffix; } $blt_width = $this->GetStringWidth(str_repeat('5',strlen($maxnum)).$this->list_number_suffix); break; case 'none': $list_item_marker = ''; $blt_width = 0; break; case 'A': $anum = $this->dec2alpha($num,true); $maxnum = $this->dec2alpha($maxnum,true); if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; } else { $list_item_marker = $anum . $this->list_number_suffix; } $blt_width = $this->GetStringWidth(str_repeat('W',strlen($maxnum)).$this->list_number_suffix); break; case 'a': $anum = $this->dec2alpha($num,false); $maxnum = $this->dec2alpha($maxnum,false); if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; } else { $list_item_marker = $anum . $this->list_number_suffix; } $blt_width = $this->GetStringWidth(str_repeat('m',strlen($maxnum)).$this->list_number_suffix); break; case 'I': $anum = $this->dec2roman($num,true); if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; } else { $list_item_marker = $anum . $this->list_number_suffix; } if ($maxnum>87) { $bbit = 87; } else if ($maxnum>86) { $bbit = 86; } else if ($maxnum>37) { $bbit = 38; } else if ($maxnum>36) { $bbit = 37; } else if ($maxnum>27) { $bbit = 28; } else if ($maxnum>26) { $bbit = 27; } else if ($maxnum>17) { $bbit = 18; } else if ($maxnum>16) { $bbit = 17; } else if ($maxnum>7) { $bbit = 8; } else if ($maxnum>6) { $bbit = 7; } else if ($maxnum>3) { $bbit = 4; } else { $bbit = $maxnum; } $maxlnum = $this->dec2roman($bbit,true); $blt_width = $this->GetStringWidth($maxlnum.$this->list_number_suffix); break; case 'i': $anum = $this->dec2roman($num,false); if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $anum; } else { $list_item_marker = $anum . $this->list_number_suffix; } if ($maxnum>87) { $bbit = 87; } else if ($maxnum>86) { $bbit = 86; } else if ($maxnum>37) { $bbit = 38; } else if ($maxnum>36) { $bbit = 37; } else if ($maxnum>27) { $bbit = 28; } else if ($maxnum>26) { $bbit = 27; } else if ($maxnum>17) { $bbit = 18; } else if ($maxnum>16) { $bbit = 17; } else if ($maxnum>7) { $bbit = 8; } else if ($maxnum>6) { $bbit = 7; } else if ($maxnum>3) { $bbit = 4; } else { $bbit = $maxnum; } $maxlnum = $this->dec2roman($bbit,false); $blt_width = $this->GetStringWidth($maxlnum.$this->list_number_suffix); break; case 'disc': if ($this->PDFA || $this->PDFX) { if ($this->_charDefined($this->CurrentFont['cw'],8226)) { $list_item_marker = "\xe2\x80\xa2"; } // &#8226; else { $list_item_marker = '-'; } $blt_width = $this->GetCharWidth($list_item_marker); // mPDF 5.3.04 break; } $list_item_marker = chr(108); // bullet disc in Zapfdingbats 'l' $typefont = 'czapfdingbats'; $blt_width = (0.791 * $this->FontSize/2.5); break; case 'circle': if ($this->PDFA || $this->PDFX) { if ($this->_charDefined($this->CurrentFont['cw'],9900)) { $list_item_marker = "\xe2\x9a\xac"; } // &#9900; else { $list_item_marker = '-'; } $blt_width = $this->GetCharWidth($list_item_marker); // mPDF 5.3.04 break; } $list_item_marker = chr(109); // circle in Zapfdingbats 'm' $typefont = 'czapfdingbats'; $blt_width = (0.873 * $this->FontSize/2.5); break; case 'square': if ($this->PDFA || $this->PDFX) { if ($this->_charDefined($this->CurrentFont['cw'],9642)) { $list_item_marker = "\xe2\x96\xaa"; } // &#9642; else { $list_item_marker = '-'; } $blt_width = $this->GetCharWidth($list_item_marker); // mPDF 5.3.04 break; } $list_item_marker = chr(110); //black square in Zapfdingbats font 'n' $typefont = 'czapfdingbats'; $blt_width = (0.761 * $this->FontSize/2.5); break; /* CSS3 list-styles numeric + I added tamil arabic-indic | bengali | cambodian | devanagari | gujarati | gurmukhi | kannada | khmer | lao | malayalam | mongolian | myanmar | oriya | persian | telugu | tibetan | thai | urdu */ case 'arabic-indic': $cp = 0x0660; $rnum = $this->dec2other($num, $cp); $list_item_marker = $this->list_number_suffix . $rnum; // RTL $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix); break; case 'persian': case 'urdu': $cp = 0x06F0; $rnum = $this->dec2other($num, $cp); $list_item_marker = $this->list_number_suffix . $rnum; // RTL $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix); break; case 'bengali': $cp = 0x09E6; $rnum = $this->dec2other($num, $cp); $list_item_marker = $rnum . $this->list_number_suffix; $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix); break; case 'devanagari': $cp = 0x0966; $rnum = $this->dec2other($num, $cp); $list_item_marker = $rnum . $this->list_number_suffix; $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix); break; case 'gujarati': $cp = 0x0AE6; $rnum = $this->dec2other($num, $cp); $list_item_marker = $rnum . $this->list_number_suffix; $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix); break; case 'gurmukhi': $cp = 0x0A66; $rnum = $this->dec2other($num, $cp); $list_item_marker = $rnum . $this->list_number_suffix; $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix); break; case 'kannada': $cp = 0x0CE6; $rnum = $this->dec2other($num, $cp); $list_item_marker = $rnum . $this->list_number_suffix; $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix); break; case 'malayalam': $cp = 0x0D66; $rnum = $this->dec2other($num, $cp); $list_item_marker = $rnum . $this->list_number_suffix; $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(6, $cp),strlen($maxnum)).$this->list_number_suffix); break; case 'oriya': $cp = 0x0B66; $rnum = $this->dec2other($num, $cp); $list_item_marker = $rnum . $this->list_number_suffix; $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix); break; case 'telugu': $cp = 0x0C66; $rnum = $this->dec2other($num, $cp); $list_item_marker = $rnum . $this->list_number_suffix; $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(3, $cp),strlen($maxnum)).$this->list_number_suffix); break; case 'tamil': $cp = 0x0BE6; $rnum = $this->dec2other($num, $cp); $list_item_marker = $rnum . $this->list_number_suffix; $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(9, $cp),strlen($maxnum)).$this->list_number_suffix); break; case 'thai': $cp = 0x0E50; $rnum = $this->dec2other($num, $cp); $list_item_marker = $rnum . $this->list_number_suffix; $blt_width = $this->GetStringWidth(str_repeat($this->dec2other(5, $cp),strlen($maxnum)).$this->list_number_suffix); break; default: if ($this->listDir == 'rtl') { $list_item_marker = $this->list_number_suffix . $num; } else { $list_item_marker = $num . $this->list_number_suffix; } $blt_width = $this->GetStringWidth(str_repeat('5',strlen($maxnum)).$this->list_number_suffix); break; } } if (isset($item[5]) && $item[5]) { $list_item_marker = ''; } // mPDF 5.3.11 if ($currIndentLvl < $lvl) { if ($lvl > 1 || $this->list_indent_first_level) { $indent += $this->list_indent[$lvl][$occur]; $lastIndent[$lvl] = $this->list_indent[$lvl][$occur]; } } else if ($currIndentLvl > $lvl) { while ($currIndentLvl > $lvl) { $indent -= $lastIndent[$currIndentLvl]; $currIndentLvl--; } } $currIndentLvl = $lvl; /*-- RTL --*/ if ($this->listDir == 'rtl') { // list_align_style Determines alignment of numbers in numbered lists if ($this->list_align_style == 'L') { $lalign = 'R'; } else { $lalign = 'L'; } $this->divwidth = $this->blk[$this->blklvl]['width'] - ($indent + $blt_width + $space_width) ; $xb = $this->blk[$this->blklvl]['inner_width'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_left'] - $indent - $blt_width; //Bullet position (relative) //Output bullet $this->bulletarray = array('w'=>$blt_width,'h'=>$clh,'txt'=>$list_item_marker,'x'=>$xb,'align'=>$lalign,'font'=>$typefont,'level'=>$lvl, 'occur'=>$occur, 'num'=>$num, 'fontsize'=>$bullfs, 'col'=>$list_item_color ); $this->x = $x; } else { /*-- END RTL --*/ if ($this->list_align_style == 'L') { $lalign = 'L'; } else { $lalign = 'R'; } $this->divwidth = $this->blk[$this->blklvl]['width'] - ($indent + $blt_width + $space_width) ; $xb = $this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'] - $blt_width - $space_width; //Output bullet $this->bulletarray = array('w'=>$blt_width,'h'=>$clh,'txt'=>$list_item_marker,'x'=>$xb,'align'=>$lalign,'font'=>$typefont,'level'=>$lvl, 'occur'=>$occur, 'num'=>$num, 'fontsize'=>$bullfs, 'col'=>$list_item_color ); $this->x = $x + $indent + $blt_width + $space_width; } // *RTL* //Print content $this->printbuffer($this->textbuffer,'',false,true); $this->textbuffer=array(); // Added to correct for OddEven Margins if ($this->page != $bak_page) { if (($this->page-$bak_page) % 2 == 1) { $x += $this->MarginCorrection; } $bak_page = $this->page; } /*-- COLUMNS --*/ // OR COLUMN CHANGE if ($this->CurrCol != $oldcolumn) { if ($this->directionality == 'rtl') { // *RTL* $x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL* } // *RTL* else { // *RTL* $x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); } // *RTL* $oldcolumn = $this->CurrCol; } /*-- END COLUMNS --*/ } //Reset all used values $this->listoccur = array(); $this->listitem = array(); $this->listlist = array(); $this->listlvl = 0; $this->listnum = 0; $this->listtype = ''; $this->textbuffer = array(); $this->divwidth = 0; $this->divheight = 0; $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin']; } /*-- END LISTS --*/ // mPDF 5.3.99 // mPDF 5.3.A2 function _saveTextBuffer($t, $link = '', $intlink = '') { $this->textbuffer[] = array($t,$link,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,$intlink,$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS,$this->spanborddet, $this->textshadow); } // mPDF 5.3.99 // mPDF 5.3.A2 function _saveCellTextBuffer($t, $link = '', $intlink = '') { $this->cell[$this->row][$this->col]['textbuffer'][] = array($t,$link,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,$intlink,$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle,$this->kerning,$this->lSpacingCSS,$this->wSpacingCSS,$this->spanborddet, $this->textshadow); } function printbuffer($arrayaux,$blockstate=0,$is_table=false,$is_list=false) { // $blockstate = 0; // NO margins/padding // $blockstate = 1; // Top margins/padding only // $blockstate = 2; // Bottom margins/padding only // $blockstate = 3; // Top & bottom margins/padding $this->spanbgcolorarray = ''; // mPDF 5.3.76 $this->spanbgcolor = false; // mPDF 5.3.61 $this->spanborder = false; $this->spanborddet = array(); $paint_ht_corr = 0; /*-- CSS-FLOAT --*/ if (count($this->floatDivs)) { list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl); if (($this->blk[$this->blklvl]['inner_width']-$l_width-$r_width) < (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04 // Too narrow to fit - try to move down past L or R float if ($l_max < $r_max && ($this->blk[$this->blklvl]['inner_width']-$r_width) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04 $this->ClearFloats('LEFT', $this->blklvl); } else if ($r_max < $l_max && ($this->blk[$this->blklvl]['inner_width']-$l_width) > (2*$this->GetCharWidth('W',false))) { // mPDF 5.3.04 $this->ClearFloats('RIGHT', $this->blklvl); } else { $this->ClearFloats('BOTH', $this->blklvl); } } } /*-- END CSS-FLOAT --*/ $bak_y = $this->y; $bak_x = $this->x; $align = ''; if (!$is_table && !$is_list) { if (isset($this->blk[$this->blklvl]['align']) && $this->blk[$this->blklvl]['align']) { $align = $this->blk[$this->blklvl]['align']; } // Block-align is set by e.g. <.. align="center"> Takes priority for this block but not inherited if (isset($this->blk[$this->blklvl]['block-align']) && $this->blk[$this->blklvl]['block-align']) { $align = $this->blk[$this->blklvl]['block-align']; } // mPDF 5.3.76 if (isset($this->blk[$this->blklvl]['direction'])) $blockdir = $this->blk[$this->blklvl]['direction']; else $blockdir = ""; $this->divwidth = $this->blk[$this->blklvl]['width']; } else { $align = $this->divalign; if ($is_table) { $blockdir = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['direction']; } else { $blockdir = $this->listDir; } } $oldpage = $this->page; // ADDED for Out of Block now done as Flowing Block if ($this->divwidth == 0) { $this->divwidth = $this->pgwidth; } if (!$is_table && !$is_list) { $this->SetLineHeight($this->FontSizePt,$this->blk[$this->blklvl]['line_height']); } $this->divheight = $this->lineheight; $old_height = $this->divheight; // As a failsafe - if font has been set but not output to page $this->SetFont($this->default_font,'',$this->default_font_size,true,true); // force output to page $array_size = count($arrayaux); $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,true,$blockdir); // Added - Otherwise <div><div><p> did not output top margins/padding for 1st/2nd div if ($array_size == 0) { $this->finishFlowingBlock(true); } // true = END of flowing block for($i=0;$i < $array_size; $i++) { // COLS $oldcolumn = $this->CurrCol; $vetor = $arrayaux[$i]; if ($i == 0 and $vetor[0] != "\n" and !$this->ispre) { $vetor[0] = ltrim($vetor[0]); } // FIXED TO ALLOW IT TO SHOW '0' if (empty($vetor[0]) && !($vetor[0]==='0') && empty($vetor[7])) { //Ignore empty text and not carrying an internal link //Check if it is the last element. If so then finish printing the block if ($i == ($array_size-1)) { $this->finishFlowingBlock(true); } // true = END of flowing block continue; } //Activating buffer properties if(isset($vetor[11]) and $vetor[11] != '') { // Font Size if ($is_table && $this->shrin_k) { $this->SetFontSize($vetor[11]/$this->shrin_k,false); } else { $this->SetFontSize($vetor[11],false); } } // mPDF 5.3.A2 if(isset($vetor[17]) && !empty($vetor[17])) { //TextShadow $this->textshadow = $vetor[17]; } // mPDF 5.3.61 if(isset($vetor[16]) && !empty($vetor[16])) { //Border $this->spanborddet = $vetor[16]; $this->spanborder = true; } if(isset($vetor[15])) { // Word spacing $this->wSpacingCSS = $vetor[15]; if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') { $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize); } } if(isset($vetor[14])) { // Letter spacing $this->lSpacingCSS = $vetor[14]; if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') { $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize); } } if(isset($vetor[13])) { // Font Kerning $this->kerning = $vetor[13]; } if(isset($vetor[10]) and !empty($vetor[10])) //Background color { $this->spanbgcolorarray = $vetor[10]; $this->spanbgcolor = true; } if(isset($vetor[9]) and !empty($vetor[9])) // Outline parameters { $cor = $vetor[9]['COLOR']; $outlinewidth = $vetor[9]['WIDTH']; $this->SetTextOutline($outlinewidth,$cor); $this->outline_on = true; } if(isset($vetor[8]) and $vetor[8] === true) // strike-through the text { $this->strike = true; } if(isset($vetor[7]) and $vetor[7] != '') // internal link: <a name="anyvalue"> { // mPDF 5.3.01 // if ($this->ColActive) { $ily = $this->y0; } else { $ily = $this->y; } // use top of columns $ily = $this->y; if ($this->keep_block_together) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "kt"=>true ); } else if ($this->table_rotate) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "tbrot"=>true ); } else if ($this->kwt) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "kwt"=>true ); } else if ($this->ColActive) { $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page, "col"=>$this->CurrCol ); } else $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page ); if (empty($vetor[0])) { //Ignore empty text //Check if it is the last element. If so then finish printing the block if ($i == ($array_size-1)) { $this->finishFlowingBlock(true); } // true = END of flowing block continue; } } if(isset($vetor[6]) and $vetor[6] === true) // Subscript { $this->SUB = true; } if(isset($vetor[5]) and $vetor[5] === true) // Superscript { $this->SUP = true; } if(isset($vetor[4]) and $vetor[4] != '') { // Font Family $font = $this->SetFont($vetor[4],$this->FontStyle,0,false); } if (!empty($vetor[3])) //Font Color { $cor = $vetor[3]; $this->SetTColor($cor); } if(isset($vetor[2]) and $vetor[2] != '') //Bold,Italic,Underline styles { $this->SetStyles($vetor[2]); } if(isset($vetor[12]) and $vetor[12] != '') { //Requested Bold,Italic,Underline $this->ReqFontStyle = $vetor[12]; } if(isset($vetor[1]) and $vetor[1] != '') //LINK { if (strpos($vetor[1],".") === false && strpos($vetor[1],"@") !== 0) //assuming every external link has a dot indicating extension (e.g: .html .txt .zip www.somewhere.com etc.) { //Repeated reference to same anchor? while(array_key_exists($vetor[1],$this->internallink)) $vetor[1]="#".$vetor[1]; $this->internallink[$vetor[1]] = $this->AddLink(); $vetor[1] = $this->internallink[$vetor[1]]; } $this->HREF = $vetor[1]; // HREF link style set here ****** } // SPECIAL CONTENT - IMAGES & FORM OBJECTS //Print-out special content if (substr($vetor[0],0,3) == "\xbb\xa4\xac") { //identifier has been identified! $objattr = $this->_getObjAttr($vetor[0]); /*-- TABLES --*/ if ($objattr['type'] == 'nestedtable') { // mPDF 5.3.79 NB Following code moved inside the if ... if ($objattr['nestedcontent']) { $level = $objattr['level']; $table = &$this->table[$level][$objattr['table']]; // mPDF 5.3.79 if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); $cell = $this->_uncacheCell($table['cells'][$objattr['row']][$objattr['col']], '', $fh); } else { $fh = null; $cell = &$table['cells'][$objattr['row']][$objattr['col']]; } $this->finishFlowingBlock(false,'nestedtable'); $save_dw = $this->divwidth ; $save_buffer = $this->cellBorderBuffer; $this->cellBorderBuffer = array(); $ncx = $this->x; list($dummyx,$w) = $this->_tableGetWidth($table, $objattr['row'], $objattr['col'], $fh); // mPDF 5.3.79 $ntw = $this->table[($level+1)][$objattr['nestedcontent']]['w']; // nested table width if (!$this->simpleTables){ if ($this->packTableData) { list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cell['borderbin']); } else { $br = $cell['border_details']['R']['w']; $bl = $cell['border_details']['L']['w']; } if ($table['borders_separate']) { $innerw = $w - $bl - $br - $cell['padding']['L'] - $cell['padding']['R'] - $table['border_spacing_H']; } else { $innerw = $w - $bl/2 - $br/2 - $cell['padding']['L'] - $cell['padding']['R']; } } else if ($this->simpleTables){ if ($table['borders_separate']) { $innerw = $w - $table['simple']['border_details']['L']['w'] - $table['simple']['border_details']['R']['w'] - $cell['padding']['L'] - $cell['padding']['R'] - $table['border_spacing_H']; } else { $innerw = $w - $table['simple']['border_details']['L']['w']/2 - $table['simple']['border_details']['R']['w']/2 - $cell['padding']['L'] - $cell['padding']['R']; } } if ($cell['a']=='C' || $this->table[($level+1)][$objattr['nestedcontent']]['a']=='C') { $ncx += ($innerw-$ntw)/2; } elseif ($cell['a']=='R' || $this->table[($level+1)][$objattr['nestedcontent']]['a']=='R') { $ncx += $innerw- $ntw; } $this->x = $ncx ; // mPDF 5.3.79 if ($this->cacheTables) { fclose($fh); } $this->_tableWrite($this->table[($level+1)][$objattr['nestedcontent']]); $this->cellBorderBuffer = $save_buffer; $this->x = $bak_x ; $this->divwidth = $save_dw; $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false,$blockdir); } } else { /*-- END TABLES --*/ if ($is_table) { // *TABLES* $maxWidth = $this->divwidth; // *TABLES* } // *TABLES* else { // *TABLES* $maxWidth = $this->divwidth - ($this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_right'] + $this->blk[$this->blklvl]['border_right']['w']); } // *TABLES* /*-- CSS-IMAGE-FLOAT --*/ // If float (already) exists at this level if (isset($this->floatmargins['R']) && $this->y <= $this->floatmargins['R']['y1'] && $this->y >= $this->floatmargins['R']['y0']) { $maxWidth -= $this->floatmargins['R']['w']; } if (isset($this->floatmargins['L']) && $this->y <= $this->floatmargins['L']['y1'] && $this->y >= $this->floatmargins['L']['y0']) { $maxWidth -= $this->floatmargins['L']['w']; } /*-- END CSS-IMAGE-FLOAT --*/ list($skipln) = $this->inlineObject($objattr['type'], '', $this->y, $objattr,$this->lMargin, ($this->flowingBlockAttr['contentWidth']/_MPDFK), $maxWidth, $this->flowingBlockAttr['height'], false, $is_table); // 1 -> New line needed because of width // -1 -> Will fit width on line but NEW PAGE REQUIRED because of height // -2 -> Will not fit on line therefore needs new line but thus NEW PAGE REQUIRED $iby = $this->y; $oldpage = $this->page; $oldcol = $this->CurrCol; if (($skipln == 1 || $skipln == -2) && !isset($objattr['float'])) { $this->finishFlowingBlock(false,$objattr['type']); $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false,$blockdir); } $thispage = $this->page; if ($this->CurrCol!=$oldcol) { $changedcol = true; } else { $changedcol=false; } // the previous lines can already have triggered page break or column change if (!$changedcol && $skipln <0 && $this->AcceptPageBreak() && $thispage==$oldpage) { $this->AddPage($this->CurOrientation); // Added to correct Images already set on line before page advanced // i.e. if second inline image on line is higher than first and forces new page if (count($this->objectbuffer)) { $yadj = $iby - $this->y; foreach($this->objectbuffer AS $ib=>$val) { if ($this->objectbuffer[$ib]['OUTER-Y'] ) $this->objectbuffer[$ib]['OUTER-Y'] -= $yadj; if ($this->objectbuffer[$ib]['BORDER-Y']) $this->objectbuffer[$ib]['BORDER-Y'] -= $yadj; if ($this->objectbuffer[$ib]['INNER-Y']) $this->objectbuffer[$ib]['INNER-Y'] -= $yadj; } } } // Added to correct for OddEven Margins if ($this->page != $oldpage) { if (($this->page-$oldpage) % 2 == 1) { $bak_x += $this->MarginCorrection; } $oldpage = $this->page; $y = $this->tMargin - $paint_ht_corr ; $this->oldy = $this->tMargin - $paint_ht_corr ; $old_height = 0; } $this->x = $bak_x; /*-- COLUMNS --*/ // COLS // OR COLUMN CHANGE if ($this->CurrCol != $oldcolumn) { if ($this->directionality == 'rtl') { // *RTL* $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL* } // *RTL* else { // *RTL* $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); } // *RTL* $this->x = $bak_x; $oldcolumn = $this->CurrCol; $y = $this->y0 - $paint_ht_corr ; $this->oldy = $this->y0 - $paint_ht_corr ; $old_height = 0; } /*-- END COLUMNS --*/ /*-- CSS-IMAGE-FLOAT --*/ if ($objattr['type'] == 'image' && isset($objattr['float'])) { $fy = $this->y; // DIV TOP MARGIN/BORDER/PADDING if ($this->flowingBlockAttr['newblock'] && ($this->flowingBlockAttr['blockstate']==1 || $this->flowingBlockAttr['blockstate']==3) && $this->flowingBlockAttr['lineCount']== 0) { $fy += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w']; } if ($objattr['float']=='R') { $fx = $this->w - $this->rMargin - $objattr['width'] - ($this->blk[$this->blklvl]['outer_right_margin'] + $this->blk[$this->blklvl]['border_right']['w'] + $this->blk[$this->blklvl]['padding_right']); } else if ($objattr['float']=='L') { $fx = $this->lMargin + ($this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_left']); } $w = $objattr['width']; $h = abs($objattr['height']); $widthLeft = $maxWidth - ($this->flowingBlockAttr['contentWidth']/_MPDFK); $maxHeight = $this->h - ($this->tMargin + $this->margin_header + $this->bMargin + 10) ; // For Images $extraWidth = ($objattr['border_left']['w'] + $objattr['border_right']['w'] + $objattr['margin_left']+ $objattr['margin_right']); $extraHeight = ($objattr['border_top']['w'] + $objattr['border_bottom']['w'] + $objattr['margin_top']+ $objattr['margin_bottom']); if ($objattr['itype'] == 'wmf' || $objattr['itype'] == 'svg') { $file = $objattr['file']; $info=$this->formobjects[$file]; } else { $file = $objattr['file']; $info=$this->images[$file]; } $img_w = $w - $extraWidth ; $img_h = $h - $extraHeight ; if ($objattr['border_left']['w']) { $objattr['BORDER-WIDTH'] = $img_w + (($objattr['border_left']['w'] + $objattr['border_right']['w'])/2) ; $objattr['BORDER-HEIGHT'] = $img_h + (($objattr['border_top']['w'] + $objattr['border_bottom']['w'])/2) ; $objattr['BORDER-X'] = $fx + $objattr['margin_left'] + (($objattr['border_left']['w'])/2) ; $objattr['BORDER-Y'] = $fy + $objattr['margin_top'] + (($objattr['border_top']['w'])/2) ; } $objattr['INNER-WIDTH'] = $img_w; $objattr['INNER-HEIGHT'] = $img_h; $objattr['INNER-X'] = $fx + $objattr['margin_left'] + ($objattr['border_left']['w']); $objattr['INNER-Y'] = $fy + $objattr['margin_top'] + ($objattr['border_top']['w']) ; $objattr['ID'] = $info['i']; $objattr['OUTER-WIDTH'] = $w; $objattr['OUTER-HEIGHT'] = $h; $objattr['OUTER-X'] = $fx; $objattr['OUTER-Y'] = $fy; if ($objattr['float']=='R') { // If R float already exists at this level $this->floatmargins['R']['skipline'] = false; if (isset($this->floatmargins['R']['y1']) && $this->floatmargins['R']['y1'] > 0 && $fy < $this->floatmargins['R']['y1']) { $this->WriteFlowingBlock($vetor[0]); } // If L float already exists at this level else if (isset($this->floatmargins['L']['y1']) && $this->floatmargins['L']['y1'] > 0 && $fy < $this->floatmargins['L']['y1']) { // Final check distance between floats is not now too narrow to fit text $mw = 2*$this->GetCharWidth('W',false); // mPDF 5.3.04 if (($this->blk[$this->blklvl]['inner_width'] - $w - $this->floatmargins['L']['w']) < $mw) { $this->WriteFlowingBlock($vetor[0]); } else { $this->floatmargins['R']['x'] = $fx; $this->floatmargins['R']['w'] = $w; $this->floatmargins['R']['y0'] = $fy; $this->floatmargins['R']['y1'] = $fy + $h; if ($skipln == 1) { $this->floatmargins['R']['skipline'] = true; $this->floatmargins['R']['id'] = count($this->floatbuffer)+0; $objattr['skipline'] = true; } $this->floatbuffer[] = $objattr; } } else { $this->floatmargins['R']['x'] = $fx; $this->floatmargins['R']['w'] = $w; $this->floatmargins['R']['y0'] = $fy; $this->floatmargins['R']['y1'] = $fy + $h; if ($skipln == 1) { $this->floatmargins['R']['skipline'] = true; $this->floatmargins['R']['id'] = count($this->floatbuffer)+0; $objattr['skipline'] = true; } $this->floatbuffer[] = $objattr; } } else if ($objattr['float']=='L') { // If L float already exists at this level $this->floatmargins['L']['skipline'] = false; if (isset($this->floatmargins['L']['y1']) && $this->floatmargins['L']['y1'] > 0 && $fy < $this->floatmargins['L']['y1']) { $this->floatmargins['L']['skipline'] = false; $this->WriteFlowingBlock($vetor[0]); } // If R float already exists at this level else if (isset($this->floatmargins['R']['y1']) && $this->floatmargins['R']['y1'] > 0 && $fy < $this->floatmargins['R']['y1']) { // Final check distance between floats is not now too narrow to fit text $mw = 2*$this->GetCharWidth('W',false); // mPDF 5.3.04 if (($this->blk[$this->blklvl]['inner_width'] - $w - $this->floatmargins['R']['w']) < $mw) { $this->WriteFlowingBlock($vetor[0]); } else { $this->floatmargins['L']['x'] = $fx + $w; $this->floatmargins['L']['w'] = $w; $this->floatmargins['L']['y0'] = $fy; $this->floatmargins['L']['y1'] = $fy + $h; if ($skipln == 1) { $this->floatmargins['L']['skipline'] = true; $this->floatmargins['L']['id'] = count($this->floatbuffer)+0; $objattr['skipline'] = true; } $this->floatbuffer[] = $objattr; } } else { $this->floatmargins['L']['x'] = $fx + $w; $this->floatmargins['L']['w'] = $w; $this->floatmargins['L']['y0'] = $fy; $this->floatmargins['L']['y1'] = $fy + $h; if ($skipln == 1) { $this->floatmargins['L']['skipline'] = true; $this->floatmargins['L']['id'] = count($this->floatbuffer)+0; $objattr['skipline'] = true; } $this->floatbuffer[] = $objattr; } } } else { /*-- END CSS-IMAGE-FLOAT --*/ $this->WriteFlowingBlock($vetor[0]); /*-- CSS-IMAGE-FLOAT --*/ } /*-- END CSS-IMAGE-FLOAT --*/ } // *TABLES* } // END If special content else { //THE text if ($this->tableLevel) { $paint_ht_corr = 0; } // To move the y up when new column/page started if div border needed else { $paint_ht_corr = $this->blk[$this->blklvl]['border_top']['w']; } if ($vetor[0] == "\n") { //We are reading a <BR> now turned into newline ("\n") if ($this->flowingBlockAttr['content']) { $this->finishFlowingBlock(false,'br'); } else if ($is_table) { $this->y+= $this->_computeLineheight($this->table_lineheight); } else if (!$is_table) { $this->DivLn($this->lineheight); if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS* } // Added to correct for OddEven Margins if ($this->page != $oldpage) { if (($this->page-$oldpage) % 2 == 1) { $bak_x += $this->MarginCorrection; } $oldpage = $this->page; $y = $this->tMargin - $paint_ht_corr ; $this->oldy = $this->tMargin - $paint_ht_corr ; $old_height = 0; } $this->x = $bak_x; /*-- COLUMNS --*/ // COLS // OR COLUMN CHANGE if ($this->CurrCol != $oldcolumn) { if ($this->directionality == 'rtl') { // *RTL* $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL* } // *RTL* else { // *RTL* $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); } // *RTL* $this->x = $bak_x; $oldcolumn = $this->CurrCol; $y = $this->y0 - $paint_ht_corr ; $this->oldy = $this->y0 - $paint_ht_corr ; $old_height = 0; } /*-- END COLUMNS --*/ $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false,$blockdir); } else { $this->WriteFlowingBlock( $vetor[0]); // Added to correct for OddEven Margins if ($this->page != $oldpage) { if (($this->page-$oldpage) % 2 == 1) { $bak_x += $this->MarginCorrection; $this->x = $bak_x; } $oldpage = $this->page; $y = $this->tMargin - $paint_ht_corr ; $this->oldy = $this->tMargin - $paint_ht_corr ; $old_height = 0; } /*-- COLUMNS --*/ // COLS // OR COLUMN CHANGE if ($this->CurrCol != $oldcolumn) { if ($this->directionality == 'rtl') { // *RTL* $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL* } // *RTL* else { // *RTL* $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); } // *RTL* $this->x = $bak_x; $oldcolumn = $this->CurrCol; $y = $this->y0 - $paint_ht_corr ; $this->oldy = $this->y0 - $paint_ht_corr ; $old_height = 0; } /*-- END COLUMNS --*/ } } //Check if it is the last element. If so then finish printing the block if ($i == ($array_size-1)) { $this->finishFlowingBlock(true); // true = END of flowing block // Added to correct for OddEven Margins if ($this->page != $oldpage) { if (($this->page-$oldpage) % 2 == 1) { $bak_x += $this->MarginCorrection; $this->x = $bak_x; } $oldpage = $this->page; $y = $this->tMargin - $paint_ht_corr ; $this->oldy = $this->tMargin - $paint_ht_corr ; $old_height = 0; } /*-- COLUMNS --*/ // COLS // OR COLUMN CHANGE if ($this->CurrCol != $oldcolumn) { if ($this->directionality == 'rtl') { // *RTL* $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL* } // *RTL* else { // *RTL* $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); } // *RTL* $this->x = $bak_x; $oldcolumn = $this->CurrCol; $y = $this->y0 - $paint_ht_corr ; $this->oldy = $this->y0 - $paint_ht_corr ; $old_height = 0; } /*-- END COLUMNS --*/ } // RESETTING VALUES $this->SetTColor($this->ConvertColor(0)); $this->SetDColor($this->ConvertColor(0)); $this->SetFColor($this->ConvertColor(255)); $this->colorarray = ''; // mPDF 5.3.76 $this->spanbgcolorarray = ''; // mPDF 5.3.76 $this->spanbgcolor = false; // mPDF 5.3.61 $this->spanborder = false; $this->spanborddet = array(); $this->HREF = ''; $this->outlineparam = array(); $this->SetTextOutline(false); $this->outline_on = false; $this->SUP = false; $this->SUB = false; $this->strike = false; $this->textshadow = ''; // mPDF 5.3.A2 $this->currentfontfamily = ''; $this->currentfontsize = ''; $this->currentfontstyle = ''; /*-- TABLES --*/ if ($this->tableLevel) { $this->SetLineHeight('',$this->table_lineheight); // *TABLES* } else /*-- END TABLES --*/ /*-- LISTS --*/ if ($is_list && $this->list_lineheight[$this->listlvl][$this->listOcc]) { // mPDF 5.3.76 $this->SetLineHeight('',$this->list_lineheight[$this->listlvl][$this->listOcc]); // sets default line height } else /*-- END LISTS --*/ if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) { $this->SetLineHeight('',$this->blk[$this->blklvl]['line_height']); // sets default line height } $this->ResetStyles(); $this->toupper = false; $this->tolower = false; $this->capitalize = false; $this->kerning = false; $this->lSpacingCSS = ''; $this->wSpacingCSS = ''; $this->fixedlSpacing = false; $this->minwSpacing = 0; $this->SetDash(); $this->dash_on = false; $this->dotted_on = false; }//end of for(i=0;i<arraysize;i++) // PAINT DIV BORDER // DISABLED IN COLUMNS AS DOESN'T WORK WHEN BROKEN ACROSS COLS?? if ((isset($this->blk[$this->blklvl]['border']) || isset($this->blk[$this->blklvl]['bgcolor']) || isset($this->blk[$this->blklvl]['box_shadow'])) && $blockstate && ($this->y != $this->oldy)) { // mPDF 5.3.A1 $bottom_y = $this->y; // Does not include Bottom Margin if (isset($this->blk[$this->blklvl]['startpage']) && $this->blk[$this->blklvl]['startpage'] != $this->page && $blockstate != 1) { $this->PaintDivBB('pagetop',$blockstate); } else if ($blockstate != 1) { $this->PaintDivBB('',$blockstate); } $this->y = $bottom_y; $this->x = $bak_x; } // Reset Font $this->SetFontSize($this->default_font_size,false); } function _setDashBorder($style, $div, $cp, $side) { if ($style == 'dashed' && (($side=='L' || $side=='R') || ($side=='T' && $div != 'pagetop' && !$cp) || ($side=='B' && $div!='pagebottom') )) { $dashsize = 2; // final dash will be this + 1*linewidth $dashsizek = 1.5; // ratio of Dash/Blank $this->SetDash($dashsize,($dashsize/$dashsizek)+($this->LineWidth*2)); } else if ($style == 'dotted' || ($side=='T' && ($div == 'pagetop' || $cp)) || ($side=='B' && $div == 'pagebottom')) { //Round join and cap $this->SetLineJoin(1); $this->SetLineCap(1); $this->SetDash(0.001,($this->LineWidth*3)); } } function _setBorderLine($b, $k=1) { $this->SetLineWidth($b['w']/$k); $this->SetDColor($b['c']); if ($b['c'][0]==5) { // RGBa $this->SetAlpha($b['c'][4], 'Normal', false, 'S')."\n"; } else if ($b['c'][0]==6) { // CMYKa $this->SetAlpha($b['c'][5], 'Normal', false, 'S')."\n"; } } function PaintDivBB($divider='',$blockstate=0,$blvl=0) { // Borders & backgrounds are done elsewhere for columns - messes up the repositioning in printcolumnbuffer if ($this->ColActive) { return ; } // *COLUMNS* $save_y = $this->y; if (!$blvl) { $blvl = $this->blklvl; } $x0 = $x1 = $y0 = $y1 = 0; // Added mPDF 3.0 Float DIV if (isset($this->blk[$blvl]['bb_painted'][$this->page]) && $this->blk[$blvl]['bb_painted'][$this->page]) { return; } // *CSS-FLOAT* if (isset($this->blk[$blvl]['x0'])) { $x0 = $this->blk[$blvl]['x0']; } // left if (isset($this->blk[$blvl]['y1'])) { $y1 = $this->blk[$blvl]['y1']; } // bottom // Added mPDF 3.0 Float DIV - ensures backgrounds/borders are drawn to bottom of page if ($y1==0) { if ($divider=='pagebottom') { $y1 = $this->h-$this->bMargin; } else { $y1 = $this->y; } } if (isset($this->blk[$blvl]['startpage']) && $this->blk[$blvl]['startpage'] != $this->page) { $continuingpage = true; } else { $continuingpage = false; } if (isset($this->blk[$blvl]['y0'])) { $y0 = $this->blk[$blvl]['y0']; } $h = $y1 - $y0; $w = $this->blk[$blvl]['width']; $x1 = $x0 + $w; // Set border-widths as used here $border_top = $this->blk[$blvl]['border_top']['w']; $border_bottom = $this->blk[$blvl]['border_bottom']['w']; $border_left = $this->blk[$blvl]['border_left']['w']; $border_right = $this->blk[$blvl]['border_right']['w']; if (!$this->blk[$blvl]['border_top'] || $divider == 'pagetop' || $continuingpage) { $border_top = 0; } if (!$this->blk[$blvl]['border_bottom'] || $blockstate == 1 || $divider == 'pagebottom') { $border_bottom = 0; } $brTL_H = 0; $brTL_V = 0; $brTR_H = 0; $brTR_V = 0; $brBL_H = 0; $brBL_V = 0; $brBR_H = 0; $brBR_V = 0; $brset = false; /*-- BORDER-RADIUS --*/ if (isset($this->blk[$blvl]['border_radius_TL_H'])) { $brTL_H = $this->blk[$blvl]['border_radius_TL_H']; $brset = true; } if (isset($this->blk[$blvl]['border_radius_TL_V'])) { $brTL_V = $this->blk[$blvl]['border_radius_TL_V']; $brset = true; } if (isset($this->blk[$blvl]['border_radius_TR_H'])) { $brTR_H = $this->blk[$blvl]['border_radius_TR_H']; $brset = true; } if (isset($this->blk[$blvl]['border_radius_TR_V'])) { $brTR_V = $this->blk[$blvl]['border_radius_TR_V']; $brset = true; } if (isset($this->blk[$blvl]['border_radius_BR_H'])) { $brBR_H = $this->blk[$blvl]['border_radius_BR_H']; $brset = true; } if (isset($this->blk[$blvl]['border_radius_BR_V'])) { $brBR_V = $this->blk[$blvl]['border_radius_BR_V']; $brset = true; } if (isset($this->blk[$blvl]['border_radius_BL_H'])) { $brBL_H = $this->blk[$blvl]['border_radius_BL_H']; $brset = true; } if (isset($this->blk[$blvl]['border_radius_BL_V'])) { $brBL_V = $this->blk[$blvl]['border_radius_BL_V']; $brset = true; } if (!$this->blk[$blvl]['border_top'] || $divider == 'pagetop' || $continuingpage || $this->keep_block_together) { $brTL_H = 0; $brTL_V = 0; $brTR_H = 0; $brTR_V = 0; } if (!$this->blk[$blvl]['border_bottom'] || $blockstate == 1 || $divider == 'pagebottom' || $this->keep_block_together) { $brBL_H = 0; $brBL_V = 0; $brBR_H = 0; $brBR_V = 0; } // Disallow border-radius if it is smaller than the border width. if ($brTL_H < min($border_left, $border_top)) { $brTL_H = $brTL_V = 0; } if ($brTL_V < min($border_left, $border_top)) { $brTL_V = $brTL_H = 0; } if ($brTR_H < min($border_right, $border_top)) { $brTR_H = $brTR_V = 0; } if ($brTR_V < min($border_right, $border_top)) { $brTR_V = $brTR_H = 0; } if ($brBL_H < min($border_left, $border_bottom)) { $brBL_H = $brBL_V = 0; } if ($brBL_V < min($border_left, $border_bottom)) { $brBL_V = $brBL_H = 0; } if ($brBR_H < min($border_right, $border_bottom)) { $brBR_H = $brBR_V = 0; } if ($brBR_V < min($border_right, $border_bottom)) { $brBR_V = $brBR_H = 0; } // CHECK FOR radii that sum to > width or height of div ******** $f = min($h/($brTL_V + $brBL_V + 0.001), $h/($brTR_V + $brBR_V + 0.001), $w/($brTL_H + $brTR_H + 0.001), $w/($brBL_H + $brBR_H + 0.001)); if ($f < 1) { $brTL_H *= $f; $brTL_V *= $f; $brTR_H *= $f; $brTR_V *= $f; $brBL_H *= $f; $brBL_V *= $f; $brBR_H *= $f; $brBR_V *= $f; } /*-- END BORDER-RADIUS --*/ // BORDERS if (isset($this->blk[$blvl]['y0']) && $this->blk[$blvl]['y0']) { $y0 = $this->blk[$blvl]['y0']; } $h = $y1 - $y0; $w = $this->blk[$blvl]['width']; //if ($this->blk[$blvl]['border_top']) { // Reinstate line above for dotted line divider when block border crosses a page if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) { $tbd = $this->blk[$blvl]['border_top']; if (isset($tbd['s']) && $tbd['s']) { $this->_setBorderLine($tbd); if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'T'); } /*-- BORDER-RADIUS --*/ else if (($brTL_V && $brTL_H) || ($brTR_V && $brTR_H)) { $this->SetLineJoin(0); $this->SetLineCap(0); } if ($brTR_H && $brTR_V) { $this->_out($this->_EllipseArc($x0 + $w - $brTR_H, $y0 + $brTR_V, $brTR_H - $border_top/2 , $brTR_V - $border_top/2 , 1, 2, true)); } else { /*-- END BORDER-RADIUS --*/ $this->_out(sprintf('%.3F %.3F m ',($x0 + $w - ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK)); /*-- BORDER-RADIUS --*/ } if ($brTL_H && $brTL_V ) { $this->_out(sprintf('%.3F %.3F l ',($x0 + ($border_top/2) + $brTL_H )*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK)); $this->_out($this->_EllipseArc($x0 + $brTL_H, $y0 + $brTL_V, $brTL_H - $border_top/2 , $brTL_V - $border_top/2 , 2, 1)); } else { /*-- END BORDER-RADIUS --*/ $this->_out(sprintf('%.3F %.3F l ',($x0 + ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK)); /*-- BORDER-RADIUS --*/ } /*-- END BORDER-RADIUS --*/ $this->_out('S'); // Reset Corners and Dash off $this->SetLineJoin(2); $this->SetLineCap(2); $this->SetDash(); } } //if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1) { // Reinstate line above for dotted line divider when block border crosses a page if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') { $tbd = $this->blk[$blvl]['border_bottom']; if (isset($tbd['s']) && $tbd['s']) { $this->_setBorderLine($tbd); if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'B'); } /*-- BORDER-RADIUS --*/ else if (($brBL_V && $brBL_H) || ($brBR_V && $brBR_H)) { $this->SetLineJoin(0); $this->SetLineCap(0); } if ($brBL_H && $brBL_V) { $this->_out($this->_EllipseArc($x0 + $brBL_H, $y0 + $h - $brBL_V, $brBL_H - $border_bottom/2 , $brBL_V - $border_bottom/2 , 3, 2, true)); } else { /*-- END BORDER-RADIUS --*/ $this->_out(sprintf('%.3F %.3F m ',($x0 + ($border_bottom/2))*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK)); /*-- BORDER-RADIUS --*/ } if ($brBR_H && $brBR_V ) { $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - ($border_bottom/2) - $brBR_H )*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK)); $this->_out($this->_EllipseArc($x0 + $w - $brBR_H, $y0 + $h - $brBR_V, $brBR_H - $border_bottom/2 , $brBR_V - $border_bottom/2 , 4, 1)); } else { /*-- END BORDER-RADIUS --*/ $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - ($border_bottom/2) )*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK)); /*-- BORDER-RADIUS --*/ } /*-- END BORDER-RADIUS --*/ $this->_out('S'); // Reset Corners and Dash off $this->SetLineJoin(2); $this->SetLineCap(2); $this->SetDash(); } } if ($this->blk[$blvl]['border_left']) { $tbd = $this->blk[$blvl]['border_left']; if (isset($tbd['s']) && $tbd['s']) { $this->_setBorderLine($tbd); if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'L'); } /*-- BORDER-RADIUS --*/ else if (($brTL_V && $brTL_H) || ($brBL_V && $brBL_H)) { $this->SetLineJoin(0); $this->SetLineCap(0); } if ($brTL_V && $brTL_H) { $this->_out($this->_EllipseArc($x0 + $brTL_H, $y0 + $brTL_V, $brTL_H - $border_left/2 , $brTL_V - $border_left/2, 2, 2, true)); } else { /*-- END BORDER-RADIUS --*/ $this->_out(sprintf('%.3F %.3F m ',($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + ($border_left/2)))*_MPDFK)); /*-- BORDER-RADIUS --*/ } if ($brBL_V && $brBL_H ) { $this->_out(sprintf('%.3F %.3F l ',($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + $h - ($border_left/2)- $brBL_V) )*_MPDFK)); $this->_out($this->_EllipseArc($x0 + $brBL_H, $y0 + $h - $brBL_V, $brBL_H - $border_left/2 , $brBL_V - $border_left/2, 3, 1)); } else { /*-- END BORDER-RADIUS --*/ $this->_out(sprintf('%.3F %.3F l ',($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + $h - ($border_left/2)) )*_MPDFK)); /*-- BORDER-RADIUS --*/ } /*-- END BORDER-RADIUS --*/ $this->_out('S'); // Reset Corners and Dash off $this->SetLineJoin(2); $this->SetLineCap(2); $this->SetDash(); } } if ($this->blk[$blvl]['border_right']) { $tbd = $this->blk[$blvl]['border_right']; if (isset($tbd['s']) && $tbd['s']) { $this->_setBorderLine($tbd); if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'R'); } /*-- BORDER-RADIUS --*/ else if (($brTR_V && $brTR_H) || ($brBR_V && $brBR_H)) { $this->SetLineJoin(0); $this->SetLineCap(0); } if ($brBR_V && $brBR_H) { $this->_out($this->_EllipseArc($x0 + $w - $brBR_H, $y0 + $h - $brBR_V, $brBR_H - $border_right/2 , $brBR_V - $border_right/2, 4, 2, true)); } else { /*-- END BORDER-RADIUS --*/ $this->_out(sprintf('%.3F %.3F m ',($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + $h - ($border_right/2)))*_MPDFK)); /*-- BORDER-RADIUS --*/ } if ($brTR_V && $brTR_H ) { $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + ($border_right/2) + $brTR_V) )*_MPDFK)); $this->_out($this->_EllipseArc($x0 + $w - $brTR_H, $y0 + $brTR_V, $brTR_H - $border_right/2 , $brTR_V - $border_right/2, 1, 1)); } else { /*-- END BORDER-RADIUS --*/ $this->_out(sprintf('%.3F %.3F l ',($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + ($border_right/2)) )*_MPDFK)); /*-- BORDER-RADIUS --*/ } /*-- END BORDER-RADIUS --*/ $this->_out('S'); // Reset Corners and Dash off $this->SetLineJoin(2); $this->SetLineCap(2); $this->SetDash(); } } if (!$brset) { // not if border-radius used $tbcol = $this->ConvertColor(255); for($l=0; $l <= $blvl; $l++) { if ($this->blk[$l]['bgcolor']) { $tbcol = $this->blk[$l]['bgcolorarray']; } } } if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) { $tbd = $this->blk[$blvl]['border_top']; if (isset($tbd['s']) && $tbd['s']) { if (!$brset && $tbd['style']=='double') { $this->SetLineWidth($tbd['w']/3); $this->SetDColor($tbcol); $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S', ($x0 + $w - ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK, ($x0 + ($border_top/2))*_MPDFK, ($this->h-($y0 + ($border_top/2)))*_MPDFK )); } } } if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') { $tbd = $this->blk[$blvl]['border_bottom']; if (isset($tbd['s']) && $tbd['s']) { if (!$brset && $tbd['style']=='double') { $this->SetLineWidth($tbd['w']/3); $this->SetDColor($tbcol); $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S', ($x0 + ($border_bottom/2))*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK, ($x0 + $w - ($border_bottom/2) )*_MPDFK, ($this->h-($y0 + $h - ($border_bottom/2)))*_MPDFK )); } } } if ($this->blk[$blvl]['border_left']) { $tbd = $this->blk[$blvl]['border_left']; if (isset($tbd['s']) && $tbd['s']) { if (!$brset && $tbd['style']=='double') { $this->SetLineWidth($tbd['w']/3); $this->SetDColor($tbcol); $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S', ($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + ($border_left/2)))*_MPDFK, ($x0 + ($border_left/2))*_MPDFK, ($this->h-($y0 + $h - ($border_left/2)) )*_MPDFK)); } } } if ($this->blk[$blvl]['border_right']) { $tbd = $this->blk[$blvl]['border_right']; if (isset($tbd['s']) && $tbd['s']) { if (!$brset && $tbd['style']=='double') { $this->SetLineWidth($tbd['w']/3); $this->SetDColor($tbcol); $this->_out(sprintf('%.3F %.3F m %.3F %.3F l S', ($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + $h - ($border_right/2)))*_MPDFK, ($x0 + $w - ($border_right/2))*_MPDFK, ($this->h-($y0 + ($border_right/2)) )*_MPDFK)); } } } $this->SetDash(); $this->y = $save_y; // BACKGROUNDS are disabled in columns/kbt/headers - messes up the repositioning in printcolumnbuffer if ($this->ColActive || $this->kwt || $this->keep_block_together) { return ; } $bgx0 = $x0; $bgx1 = $x1; $bgy0 = $y0; $bgy1 = $y1; /*-- BORDER-RADIUS --*/ // Defined br values represent the radius of the outer curve - need to take border-width/2 from each radius for drawing the borders if (isset($this->blk[$blvl]['background_clip']) && $this->blk[$blvl]['background_clip'] == 'padding-box') { $brbgTL_H = max(0, $brTL_H - $this->blk[$blvl]['border_left']['w']); $brbgTL_V = max(0, $brTL_V - $this->blk[$blvl]['border_top']['w']); $brbgTR_H = max(0, $brTR_H - $this->blk[$blvl]['border_right']['w']); $brbgTR_V = max(0, $brTR_V - $this->blk[$blvl]['border_top']['w']); $brbgBL_H = max(0, $brBL_H - $this->blk[$blvl]['border_left']['w']); $brbgBL_V = max(0, $brBL_V - $this->blk[$blvl]['border_bottom']['w']); $brbgBR_H = max(0, $brBR_H - $this->blk[$blvl]['border_right']['w']); $brbgBR_V = max(0, $brBR_V - $this->blk[$blvl]['border_bottom']['w']); $bgx0 += $this->blk[$blvl]['border_left']['w']; $bgx1 -= $this->blk[$blvl]['border_right']['w']; if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) { $bgy0 += $this->blk[$blvl]['border_top']['w']; } if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') { $bgy1 -= $this->blk[$blvl]['border_bottom']['w']; } } else { /*-- END BORDER-RADIUS --*/ $brbgTL_H = $brTL_H; $brbgTL_V = $brTL_V; $brbgTR_H = $brTR_H; $brbgTR_V = $brTR_V; $brbgBL_H = $brBL_H; $brbgBL_V = $brBL_V; $brbgBR_H = $brBR_H; $brbgBR_V = $brBR_V; /*-- BORDER-RADIUS --*/ } /*-- END BORDER-RADIUS --*/ // Set clipping path $s = ' q 0 w '; // Line width=0 $s .= sprintf('%.3F %.3F m ', ($bgx0+$brbgTL_H )*_MPDFK, ($this->h-$bgy0)*_MPDFK); // start point TL before the arc /*-- BORDER-RADIUS --*/ if ($brbgTL_H || $brbgTL_V) { $s .= $this->_EllipseArc($bgx0+$brbgTL_H, $bgy0+$brbgTL_V, $brbgTL_H , $brbgTL_V , 2); // segment 2 TL } /*-- END BORDER-RADIUS --*/ $s .= sprintf('%.3F %.3F l ', ($bgx0)*_MPDFK, ($this->h-($bgy1-$brbgBL_V ))*_MPDFK); // line to BL /*-- BORDER-RADIUS --*/ if ($brbgBL_H || $brbgBL_V) { $s .= $this->_EllipseArc($bgx0+$brbgBL_H, $bgy1-$brbgBL_V, $brbgBL_H , $brbgBL_V , 3); // segment 3 BL } /*-- END BORDER-RADIUS --*/ $s .= sprintf('%.3F %.3F l ', ($bgx1-$brbgBR_H )*_MPDFK, ($this->h-($bgy1))*_MPDFK); // line to BR /*-- BORDER-RADIUS --*/ if ($brbgBR_H || $brbgBR_V) { $s .= $this->_EllipseArc($bgx1-$brbgBR_H, $bgy1-$brbgBR_V, $brbgBR_H , $brbgBR_V , 4); // segment 4 BR } /*-- END BORDER-RADIUS --*/ $s .= sprintf('%.3F %.3F l ', ($bgx1)*_MPDFK, ($this->h-($bgy0+$brbgTR_V))*_MPDFK); // line to TR /*-- BORDER-RADIUS --*/ if ($brbgTR_H || $brbgTR_V) { $s .= $this->_EllipseArc($bgx1-$brbgTR_H, $bgy0+$brbgTR_V, $brbgTR_H , $brbgTR_V , 1); // segment 1 TR } /*-- END BORDER-RADIUS --*/ $s .= sprintf('%.3F %.3F l ', ($bgx0+$brbgTL_H )*_MPDFK, ($this->h-$bgy0)*_MPDFK); // line to TL // mPDF 5.3.A1 // Box Shadow $shadow = ''; if (isset($this->blk[$blvl]['box_shadow']) && $this->blk[$blvl]['box_shadow'] && $h > 0) { foreach($this->blk[$blvl]['box_shadow'] AS $sh) { // Colors if ($sh['col']{0}==1) { $colspace = 'Gray'; if ($sh['col']{2}==1) { $col1 = '1'.$sh['col'][1].'1'.$sh['col'][3]; } else { $col1 = '1'.$sh['col'][1].'1'.chr(100); } $col2 = '1'.$sh['col'][1].'1'.chr(0); } else if ($sh['col']{0}==4) { // CMYK $colspace = 'CMYK'; $col1 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].chr(100); $col2 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].chr(0); } else if ($sh['col']{0}==5) { // RGBa $colspace = 'RGB'; $col1 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4]; $col2 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].chr(0); } else if ($sh['col']{0}==6) { // CMYKa $colspace = 'CMYK'; $col1 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].$sh['col'][5]; $col2 = '6'.$sh['col'][1].$sh['col'][2].$sh['col'][3].$sh['col'][4].chr(0); } else { $colspace = 'RGB'; $col1 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].chr(100); $col2 = '5'.$sh['col'][1].$sh['col'][2].$sh['col'][3].chr(0); } // Use clipping path as set above (and rectangle around page) to clip area outside box $shadow .= $s; // Use the clipping path with W* $shadow .= sprintf('0 %.3F m %.3F %.3F l ', $this->h*_MPDFK, $this->w*_MPDFK, $this->h*_MPDFK); $shadow .= sprintf('%.3F 0 l 0 0 l 0 %.3F l ', $this->w*_MPDFK, $this->h*_MPDFK); $shadow .= 'W n'."\n"; $sh['blur'] = abs($sh['blur']); // cannot have negative blur value // Ensure spread/blur do not make effective shadow width/height < 0 // Could do more complex things but this just adjusts spread value if (-$sh['spread'] + $sh['blur']/2 > min($w/2, $h/2)) { $sh['spread'] = $sh['blur']/2 - min($w/2, $h/2) + 0.01; } // Shadow Offset if ($sh['x'] || $sh['y']) $shadow .= sprintf(' q 1 0 0 1 %.4F %.4F cm', $sh['x']*_MPDFK, -$sh['y']*_MPDFK)."\n"; // Set path for INNER shadow $shadow .= ' q 0 w '; $shadow .= $this->SetFColor($col1, true)."\n"; if ($col1{0}==5 && ord($col1{4})<100) { // RGBa $shadow .= $this->SetAlpha(ord($col1{4})/100, 'Normal', true, 'F')."\n"; } else if ($col1{0}==6 && ord($col1{5})<100) { // CMYKa $shadow .= $this->SetAlpha(ord($col1{5})/100, 'Normal', true, 'F')."\n"; } else if ($col1{0}==1 && $col1{2}==1 && ord($col1{3})<100) { // Gray $shadow .= $this->SetAlpha(ord($col1{3})/100, 'Normal', true, 'F')."\n"; } // Blur edges $mag = 0.551784; // Bezier Control magic number for 4-part spline for circle/ellipse $mag2 = 0.551784; // Bezier Control magic number to fill in edge of blurred rectangle $d1 = $sh['spread']+$sh['blur']/2; $d2 = $sh['spread']-$sh['blur']/2; $bl = $sh['blur']; $x00 = $x0 - $d1; $y00 = $y0 - $d1; $w00 = $w + $d1*2; $h00 = $h + $d1*2; // If any border-radius is greater width-negative spread(inner edge), ignore radii for shadow or screws up $flatten = false; if (max($brbgTR_H, $brbgTL_H, $brbgBR_H, $brbgBL_H) >= $w+$d2) { $flatten = true; } if (max($brbgTR_V, $brbgTL_V, $brbgBR_V, $brbgBL_V) >= $h+$d2) { $flatten = true; } // TOP RIGHT corner $p1x = $x00+$w00-$d1-$brbgTR_H; $p1c2x = $p1x +($d2+$brbgTR_H)*$mag; $p1y = $y00+$bl; $p2x = $x00+$w00-$d1-$brbgTR_H; $p2c2x = $p2x + ($d1+$brbgTR_H)*$mag; $p2y = $y00; $p2c1y = $p2y + $bl/2; $p3x = $x00+$w00; $p3c2x = $p3x - $bl/2; $p3y = $y00+$d1+$brbgTR_V; $p3c1y = $p3y - ($d1+$brbgTR_V)*$mag; $p4x = $x00+$w00-$bl; $p4y = $y00+$d1+$brbgTR_V; $p4c2y = $p4y - ($d2+$brbgTR_V)*$mag; if (-$d2 > min($brbgTR_H, $brbgTR_V) || $flatten) { $p1x = $x00+$w00-$bl; $p1c2x = $p1x; $p2x = $x00+$w00-$bl; $p2c2x = $p2x + $bl*$mag2; $p3y = $y00+$bl; $p3c1y = $p3y - $bl*$mag2; $p4y = $y00+$bl; $p4c2y = $p4y ; } $shadow .= sprintf('%.3F %.3F m ', ($p1x )*_MPDFK, ($this->h-($p1y ))*_MPDFK); $shadow .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($p1c2x)*_MPDFK, ($this->h-($p1y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4c2y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4y))*_MPDFK); $patch_array[0]['f']=0; $patch_array[0]['points']=array($p1x,$p1y, $p1x,$p1y, $p2x,$p2c1y, $p2x,$p2y, $p2c2x,$p2y, $p3x,$p3c1y, $p3x,$p3y, $p3c2x,$p3y, $p4x,$p4y, $p4x,$p4y, $p4x,$p4c2y, $p1c2x,$p1y); $patch_array[0]['colors'] = array($col1,$col2,$col2,$col1); // RIGHT $p1x = $x00+$w00; // control point only matches p3 preceding $p1y = $y00+$d1+$brbgTR_V; $p2x = $x00+$w00-$bl; // control point only matches p4 preceding $p2y = $y00+$d1+$brbgTR_V; $p3x = $x00+$w00-$bl; $p3y = $y00+$h00-$d1-$brbgBR_V; $p4x = $x00+$w00; $p4c1x = $p4x-$bl/2; $p4y = $y00+$h00-$d1-$brbgBR_V; if (-$d2 > min($brbgTR_H, $brbgTR_V) || $flatten) { $p1y = $y00+$bl; $p2y = $y00+$bl; } if (-$d2 > min($brbgBR_H, $brbgBR_V) || $flatten) { $p3y = $y00+$h00-$bl; $p4y = $y00+$h00-$bl; } $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK); $patch_array[1]['f']=2; $patch_array[1]['points']=array($p2x,$p2y, $p3x,$p3y, $p3x,$p3y, $p3x,$p3y, $p4c1x,$p4y, $p4x,$p4y, $p4x,$p4y, $p1x,$p1y); $patch_array[1]['colors'] = array($col1,$col2); // BOTTOM RIGHT corner $p1x = $x00+$w00-$bl; // control points only matches p3 preceding $p1y = $y00+$h00-$d1-$brbgBR_V; $p1c2y = $p1y + ($d2+$brbgBR_V)*$mag; $p2x = $x00+$w00; // control point only matches p4 preceding $p2y = $y00+$h00-$d1-$brbgBR_V; $p2c2y = $p2y + ($d1+$brbgBR_V)*$mag; $p3x = $x00+$w00-$d1-$brbgBR_H; $p3c1x = $p3x + ($d1+$brbgBR_H)*$mag; $p3y = $y00+$h00; $p3c2y = $p3y - $bl/2; $p4x = $x00+$w00-$d1-$brbgBR_H; $p4c2x = $p4x + ($d2+$brbgBR_H)*$mag; $p4y = $y00+$h00-$bl; if (-$d2 > min($brbgBR_H, $brbgBR_V) || $flatten) { $p1y = $y00+$h00-$bl; $p1c2y = $p1y; $p2y = $y00+$h00-$bl; $p2c2y = $p2y + $bl*$mag2; $p3x = $x00+$w00-$bl; $p3c1x = $p3x + $bl*$mag2; $p4x = $x00+$w00-$bl; $p4c2x = $p4x; } $shadow .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($p1x)*_MPDFK, ($this->h-($p1c2y))*_MPDFK, ($p4c2x)*_MPDFK, ($this->h-($p4y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4y))*_MPDFK); $patch_array[2]['f']=2; $patch_array[2]['points']=array($p2x,$p2c2y, $p3c1x,$p3y, $p3x,$p3y, $p3x,$p3c2y, $p4x,$p4y, $p4x,$p4y, $p4c2x,$p4y, $p1x,$p1c2y); $patch_array[2]['colors'] = array($col2,$col1); // BOTTOM $p1x = $x00+$w00-$d1-$brbgBR_H; // control point only matches p3 preceding $p1y = $y00+$h00; $p2x = $x00+$w00-$d1-$brbgBR_H; // control point only matches p4 preceding $p2y = $y00+$h00-$bl; $p3x = $x00+$d1+$brbgBL_H; $p3y = $y00+$h00-$bl; $p4x = $x00+$d1+$brbgBL_H; $p4y = $y00+$h00; $p4c1y = $p4y - $bl/2; if (-$d2 > min($brbgBR_H, $brbgBR_V) || $flatten) { $p1x = $x00+$w00-$bl; $p2x = $x00+$w00-$bl; } if (-$d2 > min($brbgBL_H, $brbgBL_V) || $flatten) { $p3x = $x00+$bl; $p4x = $x00+$bl; } $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK); $patch_array[3]['f']=2; $patch_array[3]['points']=array($p2x,$p2y, $p3x,$p3y, $p3x,$p3y, $p3x,$p3y, $p4x,$p4c1y, $p4x,$p4y, $p4x,$p4y, $p1x,$p1y); $patch_array[3]['colors'] = array($col1,$col2); // BOTTOM LEFT corner $p1x = $x00+$d1+$brbgBL_H; $p1c2x = $p1x - ($d2+$brbgBL_H)*$mag; // control points only matches p3 preceding $p1y = $y00+$h00-$bl; $p2x = $x00+$d1+$brbgBL_H; $p2c2x = $p2x - ($d1+$brbgBL_H)*$mag; // control point only matches p4 preceding $p2y = $y00+$h00; $p3x = $x00; $p3c2x = $p3x + $bl/2; $p3y = $y00+$h00-$d1-$brbgBL_V; $p3c1y = $p3y + ($d1+$brbgBL_V)*$mag; $p4x = $x00+$bl; $p4y = $y00+$h00-$d1-$brbgBL_V; $p4c2y = $p4y + ($d2+$brbgBL_V)*$mag; if (-$d2 > min($brbgBL_H, $brbgBL_V) || $flatten) { $p1x = $x00+$bl; $p1c2x = $p1x; $p2x = $x00+$bl; $p2c2x = $p2x - $bl*$mag2; $p3y = $y00+$h00-$bl; $p3c1y = $p3y + $bl*$mag2; $p4y = $y00+$h00-$bl; $p4c2y = $p4y; } $shadow .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($p1c2x)*_MPDFK, ($this->h-($p1y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4c2y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4y))*_MPDFK); $patch_array[4]['f']=2; $patch_array[4]['points']=array($p2c2x,$p2y, $p3x,$p3c1y, $p3x,$p3y, $p3c2x,$p3y, $p4x,$p4y, $p4x,$p4y, $p4x,$p4c2y, $p1c2x,$p1y); $patch_array[4]['colors'] = array($col2,$col1); // LEFT - joins on the right (C3-C4 of previous): f = 2 $p1x = $x00; // control point only matches p3 preceding $p1y = $y00+$h00-$d1-$brbgBL_V; $p2x = $x00+$bl; // control point only matches p4 preceding $p2y = $y00+$h00-$d1-$brbgBL_V; $p3x = $x00+$bl; $p3y = $y00+$d1+$brbgTL_V; $p4x = $x00; $p4c1x = $p4x + $bl/2; $p4y = $y00+$d1+$brbgTL_V; if (-$d2 > min($brbgBL_H, $brbgBL_V) || $flatten) { $p1y = $y00+$h00-$bl; $p2y = $y00+$h00-$bl; } if (-$d2 > min($brbgTL_H, $brbgTL_V) || $flatten) { $p3y = $y00+$bl; $p4y = $y00+$bl; } $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK); $patch_array[5]['f']=2; $patch_array[5]['points']=array($p2x,$p2y, $p3x,$p3y, $p3x,$p3y, $p3x,$p3y, $p4c1x,$p4y, $p4x,$p4y, $p4x,$p4y, $p1x,$p1y); $patch_array[5]['colors'] = array($col1,$col2); // TOP LEFT corner $p1x = $x00+$bl; // control points only matches p3 preceding $p1y = $y00+$d1+$brbgTL_V; $p1c2y = $p1y - ($d2+$brbgTL_V)*$mag; $p2x = $x00; // control point only matches p4 preceding $p2y = $y00+$d1+$brbgTL_V; $p2c2y = $p2y - ($d1+$brbgTL_V)*$mag; $p3x = $x00+$d1+$brbgTL_H; $p3c1x = $p3x - ($d1+$brbgTL_H)*$mag; $p3y = $y00; $p3c2y = $p3y + $bl/2; $p4x = $x00+$d1+$brbgTL_H; $p4c2x = $p4x - ($d2+$brbgTL_H)*$mag; $p4y = $y00+$bl; if (-$d2 > min($brbgTL_H, $brbgTL_V) || $flatten) { $p1y = $y00+$bl; $p1c2y = $p1y; $p2y = $y00+$bl; $p2c2y = $p2y - $bl*$mag2; $p3x = $x00+$bl; $p3c1x = $p3x - $bl*$mag2; $p4x = $x00+$bl; $p4c2x = $p4x ; } $shadow .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($p1x)*_MPDFK, ($this->h-($p1c2y))*_MPDFK, ($p4c2x)*_MPDFK, ($this->h-($p4y))*_MPDFK, ($p4x)*_MPDFK, ($this->h-($p4y))*_MPDFK); $patch_array[6]['f']=2; $patch_array[6]['points']=array($p2x,$p2c2y, $p3c1x,$p3y, $p3x,$p3y, $p3x,$p3c2y, $p4x,$p4y, $p4x,$p4y, $p4c2x,$p4y, $p1x,$p1c2y); $patch_array[6]['colors'] = array($col2,$col1); // TOP - joins on the right (C3-C4 of previous): f = 2 $p1x = $x00+$d1+$brbgTL_H; // control point only matches p3 preceding $p1y = $y00; $p2x = $x00+$d1+$brbgTL_H; // control point only matches p4 preceding $p2y = $y00+$bl; $p3x = $x00+$w00-$d1-$brbgTR_H; $p3y = $y00+$bl; $p4x = $x00+$w00-$d1-$brbgTR_H; $p4y = $y00; $p4c1y = $p4y + $bl/2; if (-$d2 > min($brbgTL_H, $brbgTL_V) || $flatten) { $p1x = $x00+$bl; $p2x = $x00+$bl; } if (-$d2 > min($brbgTR_H, $brbgTR_V) || $flatten) { $p3x = $x00+$w00-$bl; $p4x = $x00+$w00-$bl; } $shadow .= sprintf('%.3F %.3F l ', ($p3x )*_MPDFK, ($this->h-($p3y ))*_MPDFK); $patch_array[7]['f']=2; $patch_array[7]['points']=array($p2x,$p2y, $p3x,$p3y, $p3x,$p3y, $p3x,$p3y, $p4x,$p4c1y, $p4x,$p4y, $p4x,$p4y, $p1x,$p1y); $patch_array[7]['colors'] = array($col1,$col2); $shadow .= ' h f Q '."\n"; // Close path and Fill the inner solid shadow if ($bl) $shadow .= $this->grad->CoonsPatchMesh($x00,$y00,$w00,$h00,$patch_array,$x00,$x00+$w00,$y00,$y00+$h00, $colspace, true); if ($sh['x'] || $sh['y']) $shadow .= ' Q'."\n"; // Shadow Offset $shadow .= ' Q'."\n"; // Ends path no-op & Sets the clipping path } } $s .= ' W n '; // Ends path no-op & Sets the clipping path if ($this->blk[$blvl]['bgcolor']) { $this->pageBackgrounds[$blvl][] = array('x'=>$x0, 'y'=>$y0, 'w'=>$w, 'h'=>$h, 'col'=>$this->blk[$blvl]['bgcolorarray'], 'clippath'=>$s, 'visibility'=>$this->visibility, 'shadow'=>$shadow); // mPDF 5.3.42 // mPDF 5.3.A1 } // mPDF 5.3.A1 else if ($shadow) { $this->pageBackgrounds[$blvl][] = array('shadowonly'=>true, 'col'=>'', 'clippath'=>'', 'visibility'=>$this->visibility, 'shadow'=>$shadow); // mPDF 5.3.42 // mPDF 5.3.A1 } /*-- BACKGROUNDS --*/ if (isset($this->blk[$blvl]['gradient'])) { $g = $this->grad->parseBackgroundGradient($this->blk[$blvl]['gradient']); if ($g) { $gx = $x0; $gy = $y0; $this->pageBackgrounds[$blvl][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$w, 'h'=>$h, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s, 'visibility'=>$this->visibility); // mPDF 5.3.42 } } if (isset($this->blk[$blvl]['background-image'])) { if ($this->blk[$blvl]['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $this->blk[$blvl]['background-image']['gradient'] )) { $g = $this->grad->parseMozGradient( $this->blk[$blvl]['background-image']['gradient'] ); if ($g) { $gx = $x0; $gy = $y0; $this->pageBackgrounds[$blvl][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$w, 'h'=>$h, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s, 'visibility'=>$this->visibility); // mPDF 5.3.42 } } else { $image_id = $this->blk[$blvl]['background-image']['image_id']; $orig_w = $this->blk[$blvl]['background-image']['orig_w']; $orig_h = $this->blk[$blvl]['background-image']['orig_h']; $x_pos = $this->blk[$blvl]['background-image']['x_pos']; $y_pos = $this->blk[$blvl]['background-image']['y_pos']; $x_repeat = $this->blk[$blvl]['background-image']['x_repeat']; $y_repeat = $this->blk[$blvl]['background-image']['y_repeat']; $resize = $this->blk[$blvl]['background-image']['resize']; $opacity = $this->blk[$blvl]['background-image']['opacity']; $itype = $this->blk[$blvl]['background-image']['itype']; $this->pageBackgrounds[$blvl][] = array('x'=>$x0, 'y'=>$y0, 'w'=>$w, 'h'=>$h, 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>$s, 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype, 'visibility'=>$this->visibility); // mPDF 5.3.42 } } /*-- END BACKGROUNDS --*/ // Float DIV $this->blk[$blvl]['bb_painted'][$this->page] = true; } /*-- BORDER-RADIUS --*/ function _EllipseArc($x0, $y0, $rx, $ry, $seg = 1, $part=false, $start=false) { // Anticlockwise segment 1-4 TR-TL-BL-BR (part=1 or 2) $s = ''; if ($rx<0) { $rx = 0; } if ($ry<0) { $ry = 0; } $rx *= _MPDFK; $ry *= _MPDFK; $astart = 0; if ($seg == 1) { // Top Right $afinish = 90; $nSeg = 4; } else if ($seg == 2) { // Top Left $afinish = 180; $nSeg = 8; } else if ($seg == 3) { // Bottom Left $afinish = 270; $nSeg = 12; } else { // Bottom Right $afinish = 360; $nSeg = 16; } $astart = deg2rad((float) $astart); $afinish = deg2rad((float) $afinish); $totalAngle = $afinish - $astart; $dt = $totalAngle / $nSeg; // segment angle $dtm = $dt/3; $x0 *= _MPDFK; $y0 = ($this->h - $y0) * _MPDFK; $t1 = $astart; $a0 = $x0 + ($rx * cos($t1)); $b0 = $y0 + ($ry * sin($t1)); $c0 = -$rx * sin($t1); $d0 = $ry * cos($t1); $op = false; for ($i = 1; $i <= $nSeg; $i++) { // Draw this bit of the total curve $t1 = ($i * $dt) + $astart; $a1 = $x0 + ($rx * cos($t1)); $b1 = $y0 + ($ry * sin($t1)); $c1 = -$rx * sin($t1); $d1 = $ry * cos($t1); if ($i>($nSeg-4) && (!$part || ($part == 1 && $i<=$nSeg-2) || ($part == 2 && $i>$nSeg-2))) { if ($start && !$op) { $s .= sprintf('%.3F %.3F m ', $a0, $b0); } $s .= sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c ', ($a0 + ($c0 * $dtm)), ($b0 + ($d0 * $dtm)), ($a1 - ($c1 * $dtm)) , ($b1 - ($d1 * $dtm)), $a1 , $b1 ); $op = true; } $a0 = $a1; $b0 = $b1; $c0 = $c1; $d0 = $d1; } return $s; } /*-- END BORDER-RADIUS --*/ function PaintDivLnBorder($state=0,$blvl=0,$h) { // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y + $h; $save_y = $this->y; $w = $this->blk[$blvl]['width']; $x0 = $this->x; // left $y0 = $this->y; // top $x1 = $this->x + $w; // bottom $y1 = $this->y + $h; // bottom if ($this->blk[$blvl]['border_top'] && ($state==1 || $state==3)) { $tbd = $this->blk[$blvl]['border_top']; if (isset($tbd['s']) && $tbd['s']) { $this->_setBorderLine($tbd); $this->y = $y0 + ($tbd['w']/2); if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'T'); } $this->Line($x0 + ($tbd['w']/2) , $this->y , $x0 + $w - ($tbd['w']/2), $this->y); $this->y += $tbd['w']; // Reset Corners and Dash off $this->SetLineJoin(2); $this->SetLineCap(2); $this->SetDash(); } } if ($this->blk[$blvl]['border_left']) { $tbd = $this->blk[$blvl]['border_left']; if (isset($tbd['s']) && $tbd['s']) { $this->_setBorderLine($tbd); $this->y = $y0 + ($tbd['w']/2); if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'L'); } $this->Line($x0 + ($tbd['w']/2), $this->y, $x0 + ($tbd['w']/2), $y0 + $h -($tbd['w']/2)); $this->y += $tbd['w']; // Reset Corners and Dash off $this->SetLineJoin(2); $this->SetLineCap(2); $this->SetDash(); } } if ($this->blk[$blvl]['border_right']) { $tbd = $this->blk[$blvl]['border_right']; if (isset($tbd['s']) && $tbd['s']) { $this->_setBorderLine($tbd); $this->y = $y0 + ($tbd['w']/2); if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'R'); } $this->Line($x0 + $w - ($tbd['w']/2), $this->y, $x0 + $w - ($tbd['w']/2), $y0 + $h - ($tbd['w']/2)); $this->y += $tbd['w']; // Reset Corners and Dash off $this->SetLineJoin(2); $this->SetLineCap(2); $this->SetDash(); } } if ($this->blk[$blvl]['border_bottom'] && $state > 1) { $tbd = $this->blk[$blvl]['border_bottom']; if (isset($tbd['s']) && $tbd['s']) { $this->_setBorderLine($tbd); $this->y = $y0 + $h - ($tbd['w']/2); if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'B'); } $this->Line($x0 + ($tbd['w']/2) , $this->y, $x0 + $w - ($tbd['w']/2), $this->y); $this->y += $tbd['w']; // Reset Corners and Dash off $this->SetLineJoin(2); $this->SetLineCap(2); $this->SetDash(); } } $this->SetDash(); $this->y = $save_y; } function PaintImgBorder($objattr,$is_table) { // Borders are disabled in columns - messes up the repositioning in printcolumnbuffer if ($this->ColActive) { return ; } // *COLUMNS* if ($is_table) { $k = $this->shrin_k; } else { $k = 1; } $h = (isset($objattr['BORDER-HEIGHT']) ? $objattr['BORDER-HEIGHT'] : 0); $w = (isset($objattr['BORDER-WIDTH']) ? $objattr['BORDER-WIDTH'] : 0); $x0 = (isset($objattr['BORDER-X']) ? $objattr['BORDER-X'] : 0); $y0 = (isset($objattr['BORDER-Y']) ? $objattr['BORDER-Y'] : 0); // BORDERS if ($objattr['border_top']) { $tbd = $objattr['border_top']; if (!empty($tbd['s'])) { $this->_setBorderLine($tbd,$k); if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','T'); } $this->Line($x0, $y0, $x0 + $w, $y0); // Reset Corners and Dash off $this->SetLineJoin(2); $this->SetLineCap(2); $this->SetDash(); } } if ($objattr['border_left']) { $tbd = $objattr['border_left']; if (!empty($tbd['s'])) { $this->_setBorderLine($tbd,$k); if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','L'); } $this->Line($x0, $y0, $x0, $y0 + $h); // Reset Corners and Dash off $this->SetLineJoin(2); $this->SetLineCap(2); $this->SetDash(); } } if ($objattr['border_right']) { $tbd = $objattr['border_right']; if (!empty($tbd['s'])) { $this->_setBorderLine($tbd,$k); if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','R'); } $this->Line($x0 + $w, $y0, $x0 + $w, $y0 + $h); // Reset Corners and Dash off $this->SetLineJoin(2); $this->SetLineCap(2); $this->SetDash(); } } if ($objattr['border_bottom']) { $tbd = $objattr['border_bottom']; if (!empty($tbd['s'])) { $this->_setBorderLine($tbd,$k); if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','B'); } $this->Line($x0, $y0 + $h, $x0 + $w, $y0 + $h); // Reset Corners and Dash off $this->SetLineJoin(2); $this->SetLineCap(2); $this->SetDash(); } } $this->SetDash(); $this->SetAlpha(1); } /*-- END HTML-CSS --*/ function Reset() { $this->SetTColor($this->ConvertColor(0)); $this->SetDColor($this->ConvertColor(0)); $this->SetFColor($this->ConvertColor(255)); $this->SetAlpha(1); $this->colorarray = ''; // mPDF 5.3.76 $this->spanbgcolorarray = ''; // mPDF 5.3.76 $this->spanbgcolor = false; // mPDF 5.3.61 $this->spanborder = false; $this->spanborddet = array(); $this->ResetStyles(); $this->HREF = ''; $this->outlineparam = array(); $this->outline_on = false; $this->SetTextOutline(false); $this->SUP = false; $this->SUB = false; $this->strike = false; $this->textshadow = ''; // mPDF 5.3.A2 $this->SetFont($this->default_font,'',0,false); $this->SetFontSize($this->default_font_size,false); $this->currentfontfamily = ''; $this->currentfontsize = ''; /*-- TABLES --*/ if ($this->tableLevel) { $this->SetLineHeight('',$this->table_lineheight); // *TABLES* } else /*-- END TABLES --*/ /*-- LISTS --*/ if ($this->listlvl && $this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]) { $this->SetLineHeight('',$this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]); // sets default line height } else /*-- END LISTS --*/ if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) { $this->SetLineHeight('',$this->blk[$this->blklvl]['line_height']); // sets default line height } $this->toupper = false; $this->tolower = false; $this->kerning = false; $this->lSpacingCSS = ''; $this->wSpacingCSS = ''; $this->fixedlSpacing = false; $this->minwSpacing = 0; $this->capitalize = false; $this->SetDash(); //restore to no dash $this->dash_on = false; $this->dotted_on = false; $this->divwidth = 0; $this->divheight = 0; $this->divalign = ''; $this->divrevert = false; $this->oldy = -1; $bodystyle = array(); if (isset($this->CSS['BODY']['FONT-STYLE'])) { $bodystyle['FONT-STYLE'] = $this->CSS['BODY']['FONT-STYLE']; } if (isset($this->CSS['BODY']['FONT-WEIGHT'])) { $bodystyle['FONT-WEIGHT'] = $this->CSS['BODY']['FONT-WEIGHT']; } if (isset($this->CSS['BODY']['COLOR'])) { $bodystyle['COLOR'] = $this->CSS['BODY']['COLOR']; } if (isset($bodystyle)) { $this->setCSS($bodystyle,'BLOCK','BODY'); } } /*-- HTML-CSS --*/ function ReadMetaTags($html) { // changes anykey=anyvalue to anykey="anyvalue" (only do this when this happens inside tags) $regexp = '/ (\\w+?)=([^\\s>"]+)/si'; $html = preg_replace($regexp," \$1=\"\$2\"",$html); if (preg_match('/<title>(.*?)<\/title>/si',$html,$m)) { $this->SetTitle($m[1]); } preg_match_all('/<meta [^>]*?(name|content)="([^>]*?)" [^>]*?(name|content)="([^>]*?)".*?>/si',$html,$aux); $firstattr = $aux[1]; $secondattr = $aux[3]; for( $i = 0 ; $i < count($aux[0]) ; $i++) { $name = ( strtoupper($firstattr[$i]) == "NAME" )? strtoupper($aux[2][$i]) : strtoupper($aux[4][$i]); $content = ( strtoupper($firstattr[$i]) == "CONTENT" )? $aux[2][$i] : $aux[4][$i]; switch($name) { case "KEYWORDS": $this->SetKeywords($content); break; case "AUTHOR": $this->SetAuthor($content); break; case "DESCRIPTION": $this->SetSubject($content); break; } } } function ReadCharset($html) { // Charset conversion if ($this->allow_charset_conversion) { if (preg_match('/<head.*charset=([^\'\"\s]*).*<\/head>/si',$html,$m)) { if (strtoupper($m[1]) != 'UTF-8') { $this->charset_in = strtoupper($m[1]); } } } } /*-- END HTML-CSS --*/ ////////////////// /// CSS parser /// ////////////////// ////////////////// /// CSS parser /// ////////////////// ////////////////// /// CSS parser /// ////////////////// /*-- HTML-CSS --*/ function ReadDefaultCSS($CSSstr) { $CSS = array(); $CSSstr = preg_replace('|/\*.*?\*/|s',' ',$CSSstr); $CSSstr = preg_replace('/[\s\n\r\t\f]/s',' ',$CSSstr); $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s',' ',$CSSstr); if ($CSSstr ) { preg_match_all('/(.*?)\{(.*?)\}/',$CSSstr,$styles); for($i=0; $i < count($styles[1]) ; $i++) { $stylestr= trim($styles[2][$i]); $stylearr = explode(';',$stylestr); foreach($stylearr AS $sta) { if (trim($sta)) { // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')" list($property,$value) = explode(':',$sta,2); $property = trim($property); $value = preg_replace('/\s*!important/i','',$value); $value = trim($value); if ($property && ($value || $value==='0')) { $classproperties[strtoupper($property)] = $value; } } } $classproperties = $this->fixCSS($classproperties); $tagstr = strtoupper(trim($styles[1][$i])); $tagarr = explode(',',$tagstr); foreach($tagarr AS $tg) { $tags = preg_split('/\s+/',trim($tg)); $level = count($tags); if ($level == 1) { // e.g. p or .class or #id or p.class or p#id $t = trim($tags[0]); if ($t) { $tag = ''; if (preg_match('/^('.$this->allowedCSStags.')$/',$t)) { $tag= $t; } if ($this->CSS[$tag] && $tag) { $CSS[$tag] = $this->array_merge_recursive_unique($CSS[$tag], $classproperties); } else if ($tag) { $CSS[$tag] = $classproperties; } } } } $properties = array(); $values = array(); $classproperties = array(); } } // end of if return $CSS; } function ReadCSS($html) { preg_match_all('/<style[^>]*media=["\']([^"\'>]*)["\'].*?<\/style>/is',$html,$m); for($i=0; $i<count($m[0]); $i++) { if ($this->CSSselectMedia && !preg_match('/('.trim($this->CSSselectMedia).'|all)/i',$m[1][$i])) { $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html); } } preg_match_all('/<link[^>]*media=["\']([^"\'>]*)["\'].*?>/is',$html,$m); for($i=0; $i<count($m[0]); $i++) { if ($this->CSSselectMedia && !preg_match('/('.trim($this->CSSselectMedia).'|all)/i',$m[1][$i])) { $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html); } } // Remove Comment tags <!-- --> inside CSS as <style> in HTML document // Remove Comment tags /* ... */ inside CSS as <style> in HTML document preg_match_all('/<style.*?>(.*?)<\/style>/si',$html,$m); if (count($m[1])) { for($i=0;$i<count($m[1]);$i++) { // Remove comment tags $sub = preg_replace('/(<\!\-\-|\-\->)/s',' ',$m[1][$i]); $sub = preg_replace('|/\*.*?\*/|s',' ',$sub); $html = preg_replace('/'.preg_quote($m[1][$i], '/').'/si', $sub, $html); } } $html = preg_replace('/<!--mpdf/i','',$html); $html = preg_replace('/mpdf-->/i','',$html); $html = preg_replace('/<\!\-\-.*?\-\->/s',' ',$html); $match = 0; // no match for instance $regexp = ''; // This helps debugging: showing what is the REAL string being processed $CSSext = array(); //CSS inside external files $regexp = '/<link[^>]*rel=["\']stylesheet["\'][^>]*href=["\']([^>"\']*)["\'].*?>/si'; $x = preg_match_all($regexp,$html,$cxt); if ($x) { $match += $x; $CSSext = $cxt[1]; } $regexp = '/<link[^>]*href=["\']([^>"\']*)["\'][^>]*?rel=["\']stylesheet["\'].*?>/si'; $x = preg_match_all($regexp,$html,$cxt); if ($x) { $match += $x; $CSSext = array_merge($CSSext,$cxt[1]); } // look for @import stylesheets //$regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css)[\'\"]{0,1}\)/si'; $regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css(\?\S+)?)[\'\"]{0,1}\)/si'; // mPDF 5.3.63 $x = preg_match_all($regexp,$html,$cxt); if ($x) { $match += $x; $CSSext = array_merge($CSSext,$cxt[1]); } // look for @import without the url() //$regexp = '/@import [\'\"]{0,1}([^;]*?\.css)[\'\"]{0,1}/si'; $regexp = '/@import [\'\"]{0,1}([^;]*?\.css(\?\S+)?)[\'\"]{0,1}/si'; // mPDF 5.3.63 $x = preg_match_all($regexp,$html,$cxt); if ($x) { $match += $x; $CSSext = array_merge($CSSext,$cxt[1]); } $ind = 0; $CSSstr = ''; if (!is_array($this->cascadeCSS)) $this->cascadeCSS = array(); while($match){ $path = $CSSext[$ind]; $this->GetFullPath($path); $CSSextblock = $this->_get_file($path); if ($CSSextblock) { // look for embedded @import stylesheets in other stylesheets // and fix url paths (including background-images) relative to stylesheet //$regexpem = '/@import url\([\'\"]{0,1}(.*?\.css)[\'\"]{0,1}\)/si'; $regexpem = '/@import url\([\'\"]{0,1}(.*?\.css(\?\S+)?)[\'\"]{0,1}\)/si'; // mPDF 5.3.63 $xem = preg_match_all($regexpem,$CSSextblock,$cxtem); $cssBasePath = preg_replace('/\/[^\/]*$/','',$path) . '/'; if ($xem) { foreach($cxtem[1] AS $cxtembedded) { // path is relative to original stlyesheet!! $this->GetFullPath($cxtembedded, $cssBasePath ); $match++; $CSSext[] = $cxtembedded; } } $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si'; $xem = preg_match_all($regexpem,$CSSextblock,$cxtem); if ($xem) { for ($i=0;$i<count($cxtem[0]);$i++) { // path is relative to original stlyesheet!! $embedded = $cxtem[2][$i]; $this->GetFullPath($embedded, $cssBasePath ); $CSSextblock = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $CSSextblock); } } $CSSstr .= ' '.$CSSextblock; } $match--; $ind++; } //end of match $match = 0; // reset value, if needed // CSS as <style> in HTML document $regexp = '/<style.*?>(.*?)<\/style>/si'; $match = preg_match_all($regexp,$html,$CSSblock); if ($match) { $tmpCSSstr = implode(' ',$CSSblock[1]); $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si'; $xem = preg_match_all($regexpem,$tmpCSSstr ,$cxtem); if ($xem) { for ($i=0;$i<count($cxtem[0]);$i++) { $embedded = $cxtem[2][$i]; $this->GetFullPath($embedded); $tmpCSSstr = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $tmpCSSstr ); } } $CSSstr .= ' '.$tmpCSSstr; } // Remove comments $CSSstr = preg_replace('|/\*.*?\*/|s',' ',$CSSstr); $CSSstr = preg_replace('/[\s\n\r\t\f]/s',' ',$CSSstr); if (preg_match('/@media/',$CSSstr)) { preg_match_all('/@media(.*?)\{(([^\{\}]*\{[^\{\}]*\})+)\s*\}/is',$CSSstr,$m); for($i=0; $i<count($m[0]); $i++) { if ($this->CSSselectMedia && !preg_match('/('.trim($this->CSSselectMedia).'|all)/i',$m[1][$i])) { $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$CSSstr); } else { $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/',' '.$m[2][$i].' ',$CSSstr); } } } $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s',' ',$CSSstr); if ($CSSstr ) { preg_match_all('/(.*?)\{(.*?)\}/',$CSSstr,$styles); for($i=0; $i < count($styles[1]) ; $i++) { // SET array e.g. $classproperties['COLOR'] = '#ffffff'; $stylestr= trim($styles[2][$i]); $stylearr = explode(';',$stylestr); foreach($stylearr AS $sta) { if (trim($sta)) { // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')" list($property,$value) = explode(':',$sta,2); $property = trim($property); $value = preg_replace('/\s*!important/i','',$value); $value = trim($value); if ($property && ($value || $value==='0')) { // Ignores -webkit-gradient so doesn't override -moz- if ((strtoupper($property)=='BACKGROUND-IMAGE' || strtoupper($property)=='BACKGROUND') && preg_match('/-webkit-gradient/i',$value)) { continue; } $classproperties[strtoupper($property)] = $value; } } } $classproperties = $this->fixCSS($classproperties); $tagstr = strtoupper(trim($styles[1][$i])); $tagarr = explode(',',$tagstr); $pageselectors = false; // used to turn on $this->mirrorMargins foreach($tagarr AS $tg) { $tags = preg_split('/\s+/',trim($tg)); $level = count($tags); $t = ''; $t2 = ''; $t3 = ''; if (trim($tags[0])=='@PAGE') { if (isset($tags[0])) { $t = trim($tags[0]); } if (isset($tags[1])) { $t2 = trim($tags[1]); } if (isset($tags[2])) { $t3 = trim($tags[2]); } $tag = ''; if ($level==1) { $tag = $t; } else if ($level==2 && preg_match('/^[:](.*)$/',$t2,$m)) { $tag = $t.'>>PSEUDO>>'.$m[1]; if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mirrorMargins } else if ($level==2) { $tag = $t.'>>NAMED>>'.$t2; } else if ($level==3 && preg_match('/^[:](.*)$/',$t3,$m)) { $tag = $t.'>>NAMED>>'.$t2.'>>PSEUDO>>'.$m[1]; if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mirrorMargins } if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); } else if ($tag) { $this->CSS[$tag] = $classproperties; } } else if ($level == 1) { // e.g. p or .class or #id or p.class or p#id if (isset($tags[0])) { $t = trim($tags[0]); } if ($t) { $tag = ''; if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; } else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; } else if (preg_match('/^('.$this->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; } else if (preg_match('/^('.$this->allowedCSStags.')\s*:NTH-CHILD\((.*)\)$/',$t,$m)) { $tag = $m[1].'>>SELECTORNTHCHILD>>'.$m[2]; } // mPDF 5.3.82 else if (preg_match('/^('.$this->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; } else if (preg_match('/^('.$this->allowedCSStags.')$/',$t)) { $tag= $t; } if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); } else if ($tag) { $this->CSS[$tag] = $classproperties; } } } else { $tmp = array(); for($n=0;$n<$level;$n++) { if (isset($tags[$n])) { $t = trim($tags[$n]); } else { $t = ''; } if ($t) { $tag = ''; if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; } else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; } else if (preg_match('/^('.$this->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; } else if (preg_match('/^('.$this->allowedCSStags.')\s*:NTH-CHILD\((.*)\)$/',$t,$m)) { $tag = $m[1].'>>SELECTORNTHCHILD>>'.$m[2]; } // mPDF 5.3.82 else if (preg_match('/^('.$this->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; } else if (preg_match('/^('.$this->allowedCSStags.')$/',$t)) { $tag= $t; } if ($tag) $tmp[] = $tag; else { break; } } } if ($tag) { $x = &$this->cascadeCSS; foreach($tmp AS $tp) { $x = &$x[$tp]; } $x = $this->array_merge_recursive_unique($x, $classproperties); $x['depth'] = $level; } } } if ($pageselectors) { $this->mirrorMargins = true; } $properties = array(); $values = array(); $classproperties = array(); } } // end of if //Remove CSS (tags and content), if any $regexp = '/<style.*?>(.*?)<\/style>/si'; // it can be <style> or <style type="txt/css"> $html = preg_replace($regexp,'',$html); //print_r($this->CSS); exit; //print_r($this->cascadeCSS); exit; return $html; } function readInlineCSS($html) { //Fix incomplete CSS code $size = strlen($html)-1; if (substr($html,$size,1) != ';') $html .= ';'; //Make CSS[Name-of-the-class] = array(key => value) $regexp = '|\\s*?(\\S+?):(.+?);|i'; preg_match_all( $regexp, $html, $styleinfo); $properties = $styleinfo[1]; $values = $styleinfo[2]; //Array-properties and Array-values must have the SAME SIZE! $classproperties = array(); for($i = 0; $i < count($properties) ; $i++) { // Ignores -webkit-gradient so doesn't override -moz- if ((strtoupper($properties[$i])=='BACKGROUND-IMAGE' || strtoupper($properties[$i])=='BACKGROUND') && preg_match('/-webkit-gradient/i',$values[$i])) { continue; } $classproperties[strtoupper($properties[$i])] = trim($values[$i]); } return $this->fixCSS($classproperties); } function setCSS($arrayaux,$type='',$tag='') { // type= INLINE | BLOCK | LIST // tag= BODY if (!is_array($arrayaux)) return; //Removes PHP Warning // Set font size first so that e.g. MARGIN 0.83em works on font size for this element if (isset($arrayaux['FONT-SIZE'])) { $v = $arrayaux['FONT-SIZE']; if(is_numeric($v[0])) { // mPDF 5.3.28 if ($type == 'BLOCK' && $this->blklvl>0 && isset($this->blk[$this->blklvl-1]['InlineProperties']) && isset($this->blk[$this->blklvl-1]['InlineProperties']['size'])) { $mmsize = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['InlineProperties']['size']); } else { $mmsize = $this->ConvertSize($v,$this->FontSize); } $this->SetFontSize( $mmsize*(_MPDFK),false ); //Get size in points (pt) } else{ $v = strtoupper($v); if (isset($this->fontsizes[$v])) { $this->SetFontSize( $this->fontsizes[$v]* $this->default_font_size,false); } } if ($tag == 'BODY') { $this->SetDefaultFontSize($this->FontSizePt); } } if ($this->useLang && !$this->usingCoreFont) { if (isset($arrayaux['LANG']) && $arrayaux['LANG'] && $arrayaux['LANG'] != $this->default_lang && ((strlen($arrayaux['LANG']) == 5 && $arrayaux['LANG'] != 'UTF-8') || strlen($arrayaux['LANG']) == 2)) { list ($coreSuitable,$mpdf_pdf_unifonts) = GetLangOpts($arrayaux['LANG'], $this->useAdobeCJK); if ($mpdf_pdf_unifonts) { $this->RestrictUnicodeFonts($mpdf_pdf_unifonts); } else { $this->RestrictUnicodeFonts($this->default_available_fonts ); } if ($tag == 'BODY') { $this->currentLang = $arrayaux['LANG']; $this->default_lang = $arrayaux['LANG']; if ($mpdf_pdf_unifonts) { $this->default_available_fonts = $mpdf_pdf_unifonts; } } } else { $this->RestrictUnicodeFonts($this->default_available_fonts ); } } // FOR INLINE and BLOCK OR 'BODY' if (isset($arrayaux['FONT-FAMILY'])) { $v = $arrayaux['FONT-FAMILY']; //If it is a font list, get all font types $aux_fontlist = explode(",",$v); $found = 0; foreach($aux_fontlist AS $f) { $fonttype = trim($f); $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype); $fonttype = preg_replace('/ /','',$fonttype); $v = strtolower(trim($fonttype)); if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; } if ((!$this->onlyCoreFonts && in_array($v,$this->available_unifonts)) || in_array($v,array('ccourier','ctimes','chelvetica')) || /* mPDF 5.3.21 & 22 */ ($this->onlyCoreFonts && in_array($v,array('courier','times','helvetica','arial'))) || in_array($v, array('sjis','uhc','big5','gb'))) { $fonttype = $v; $found = 1; break; } } if (!$found) { foreach($aux_fontlist AS $f) { $fonttype = trim($f); $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype); $fonttype = preg_replace('/ /','',$fonttype); $v = strtolower(trim($fonttype)); if (isset($this->fonttrans[$v]) && $this->fonttrans[$v]) { $v = $this->fonttrans[$v]; } if (in_array($v,$this->sans_fonts) || in_array($v,$this->serif_fonts) || in_array($v,$this->mono_fonts) ) { $fonttype = $v; break; } } } if ($tag == 'BODY') { $this->SetDefaultFont($fonttype); } $this->SetFont($fonttype,$this->currentfontstyle,0,false); } else { $this->SetFont($this->currentfontfamily,$this->currentfontstyle,0,false); } foreach($arrayaux as $k => $v) { if ($type != 'INLINE' && $tag != 'BODY' && $type != 'LIST') { // mPDF 5.3.65 switch($k){ // BORDERS case 'BORDER-TOP': $this->blk[$this->blklvl]['border_top'] = $this->border_details($v); if ($this->blk[$this->blklvl]['border_top']['s']) { $this->blk[$this->blklvl]['border'] = 1; } break; case 'BORDER-BOTTOM': $this->blk[$this->blklvl]['border_bottom'] = $this->border_details($v); if ($this->blk[$this->blklvl]['border_bottom']['s']) { $this->blk[$this->blklvl]['border'] = 1; } break; case 'BORDER-LEFT': $this->blk[$this->blklvl]['border_left'] = $this->border_details($v); if ($this->blk[$this->blklvl]['border_left']['s']) { $this->blk[$this->blklvl]['border'] = 1; } break; case 'BORDER-RIGHT': $this->blk[$this->blklvl]['border_right'] = $this->border_details($v); if ($this->blk[$this->blklvl]['border_right']['s']) { $this->blk[$this->blklvl]['border'] = 1; } break; // PADDING case 'PADDING-TOP': $this->blk[$this->blklvl]['padding_top'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); break; case 'PADDING-BOTTOM': $this->blk[$this->blklvl]['padding_bottom'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); break; case 'PADDING-LEFT': $this->blk[$this->blklvl]['padding_left'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); break; case 'PADDING-RIGHT': $this->blk[$this->blklvl]['padding_right'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); break; // MARGINS case 'MARGIN-TOP': $tmp = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); if (isset($this->blk[$this->blklvl]['lastbottommargin'])) { if ($tmp > $this->blk[$this->blklvl]['lastbottommargin']) { $tmp -= $this->blk[$this->blklvl]['lastbottommargin']; } else { $tmp = 0; } } $this->blk[$this->blklvl]['margin_top'] = $tmp; break; case 'MARGIN-BOTTOM': $this->blk[$this->blklvl]['margin_bottom'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); break; case 'MARGIN-LEFT': $this->blk[$this->blklvl]['margin_left'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); break; case 'MARGIN-RIGHT': $this->blk[$this->blklvl]['margin_right'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); break; /*-- BORDER-RADIUS --*/ case 'BORDER-TOP-LEFT-RADIUS-H': $this->blk[$this->blklvl]['border_radius_TL_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); break; case 'BORDER-TOP-LEFT-RADIUS-V': $this->blk[$this->blklvl]['border_radius_TL_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); break; case 'BORDER-TOP-RIGHT-RADIUS-H': $this->blk[$this->blklvl]['border_radius_TR_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); break; case 'BORDER-TOP-RIGHT-RADIUS-V': $this->blk[$this->blklvl]['border_radius_TR_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); break; case 'BORDER-BOTTOM-LEFT-RADIUS-H': $this->blk[$this->blklvl]['border_radius_BL_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); break; case 'BORDER-BOTTOM-LEFT-RADIUS-V': $this->blk[$this->blklvl]['border_radius_BL_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); break; case 'BORDER-BOTTOM-RIGHT-RADIUS-H': $this->blk[$this->blklvl]['border_radius_BR_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); break; case 'BORDER-BOTTOM-RIGHT-RADIUS-V': $this->blk[$this->blklvl]['border_radius_BR_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); break; /*-- END BORDER-RADIUS --*/ // mPDF 5.3.A1 case 'BOX-SHADOW': $bs = $this->setCSSboxshadow($v); if ($bs) { $this->blk[$this->blklvl]['box_shadow'] = $bs; } break; case 'BACKGROUND-CLIP': if (strtoupper($v) == 'PADDING-BOX') { $this->blk[$this->blklvl]['background_clip'] = 'padding-box'; } break; case 'PAGE-BREAK-AFTER': if (strtoupper($v) == 'AVOID') { $this->blk[$this->blklvl]['page_break_after_avoid'] = true; } // mPDF 5.3.03 else if (strtoupper($v) == 'ALWAYS' || strtoupper($v) == 'LEFT' || strtoupper($v) == 'RIGHT') { $this->blk[$this->blklvl]['page_break_after'] = strtoupper($v) ; } break; case 'WIDTH': if (strtoupper($v) != 'AUTO') { $this->blk[$this->blklvl]['css_set_width'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false); } break; case 'TEXT-INDENT': // Left as raw value (may include 1% or 2em) $this->blk[$this->blklvl]['text_indent'] = $v; break; }//end of switch($k) } if ($type != 'INLINE' && $type != 'LIST') { // includes BODY tag // mPDF 5.3.65 switch($k){ case 'MARGIN-COLLAPSE': // Custom tag to collapse margins at top and bottom of page if (strtoupper($v) == 'COLLAPSE') { $this->blk[$this->blklvl]['margin_collapse'] = true; } break; case 'LINE-HEIGHT': $this->blk[$this->blklvl]['line_height'] = $this->fixLineheight($v); if (!$this->blk[$this->blklvl]['line_height'] ) { $this->blk[$this->blklvl]['line_height'] = $this->normalLineheight; } break; case 'TEXT-ALIGN': //left right center justify switch (strtoupper($v)) { case 'LEFT': $this->blk[$this->blklvl]['align']="L"; break; case 'CENTER': $this->blk[$this->blklvl]['align']="C"; break; case 'RIGHT': $this->blk[$this->blklvl]['align']="R"; break; case 'JUSTIFY': $this->blk[$this->blklvl]['align']="J"; break; } break; /*-- BACKGROUNDS --*/ case 'BACKGROUND-GRADIENT': if ($type == 'BLOCK') { $this->blk[$this->blklvl]['gradient'] = $v; } break; /*-- END BACKGROUNDS --*/ case 'DIRECTION': if ($v) { $this->blk[$this->blklvl]['direction'] = strtolower($v); } break; }//end of switch($k) } // FOR INLINE ONLY if ($type == 'INLINE' || $type == 'LIST') { // mPDF 5.3.65 switch($k){ case 'DISPLAY': // Custom tag to collapse margins at top and bottom of page if (strtoupper($v) == 'NONE') { $this->inlineDisplayOff = true; } break; case 'DIRECTION': break; }//end of switch($k) } // FOR INLINE ONLY if ($type == 'INLINE') { // mPDF 5.3.65 switch($k){ // mPDF 5.3.61 // BORDERS case 'BORDER-TOP': $this->spanborddet['T'] = $this->border_details($v); $this->spanborder = true; break; case 'BORDER-BOTTOM': $this->spanborddet['B'] = $this->border_details($v); $this->spanborder = true; break; case 'BORDER-LEFT': $this->spanborddet['L'] = $this->border_details($v); $this->spanborder = true; break; case 'BORDER-RIGHT': $this->spanborddet['R'] = $this->border_details($v); $this->spanborder = true; break; }//end of switch($k) } // FOR INLINE and BLOCK switch($k){ case 'TEXT-ALIGN': //left right center justify if (strtoupper($v) == 'NOJUSTIFY' && $this->blk[$this->blklvl]['align']=="J") { $this->blk[$this->blklvl]['align']=""; } break; // bgcolor only - to stay consistent with original html2fpdf case 'BACKGROUND': case 'BACKGROUND-COLOR': $cor = $this->ConvertColor($v); if ($cor) { if ($tag == 'BODY') { $this->bodyBackgroundColor = $cor; } else if ($type == 'INLINE' || $type == 'LIST') { // mPDF 5.3.93 $this->spanbgcolorarray = $cor; $this->spanbgcolor = true; } else { $this->blk[$this->blklvl]['bgcolorarray'] = $cor; $this->blk[$this->blklvl]['bgcolor'] = true; } } else if ($type != 'INLINE' && $type != 'LIST') { // mPDF 5.3.93 if ($this->ColActive || $this->keep_block_together) { $this->blk[$this->blklvl]['bgcolorarray'] = $this->blk[$this->blklvl-1]['bgcolorarray'] ; $this->blk[$this->blklvl]['bgcolor'] = $this->blk[$this->blklvl-1]['bgcolor'] ; } } break; // auto | normal | none case 'FONT-KERNING': if ((strtoupper($v) == 'NORMAL' || strtoupper($v) == 'AUTO') && $this->useKerning) { $this->kerning = true; } else if (strtoupper($v) == 'NONE') { $this->kerning = false; } break; // normal | <length> case 'LETTER-SPACING': $this->lSpacingCSS = $v; if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') { $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize); } break; // normal | <length> case 'WORD-SPACING': $this->wSpacingCSS = $v; if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') { $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize); } break; case 'FONT-STYLE': // italic normal oblique switch (strtoupper($v)) { case 'ITALIC': case 'OBLIQUE': $this->SetStyle('I',true); break; case 'NORMAL': $this->SetStyle('I',false); break; } break; case 'FONT-WEIGHT': // normal bold //Does not support: bolder, lighter, 100..900(step value=100) switch (strtoupper($v)) { case 'BOLD': $this->SetStyle('B',true); break; case 'NORMAL': $this->SetStyle('B',false); break; } break; case 'VERTICAL-ALIGN': //super and sub only dealt with here e.g. <SUB> and <SUP> switch (strtoupper($v)) { case 'SUPER': $this->SUP=true; break; case 'SUB': $this->SUB=true; break; } break; case 'TEXT-DECORATION': // none underline line-through (strikeout) //Does not support: overline, blink if (stristr($v,'LINE-THROUGH')) { $this->strike = true; } if (stristr($v,'UNDERLINE')) { $this->SetStyle('U',true); } break; case 'FONT-VARIANT': switch (strtoupper($v)) { case 'SMALL-CAPS': $this->SetStyle('S',true); break; case 'NORMAL': $this->SetStyle('S',false); break; } break; case 'TEXT-TRANSFORM': // none uppercase lowercase //Does support: capitalize switch (strtoupper($v)) { //Not working 100% case 'CAPITALIZE': $this->capitalize=true; break; case 'UPPERCASE': $this->toupper=true; break; case 'LOWERCASE': $this->tolower=true; break; case 'NONE': break; } break; // mPDF 5.3.A2 case 'TEXT-SHADOW': $ts = $this->setCSStextshadow($v); if ($ts) { $this->textshadow = $ts; } break; case 'OUTLINE-WIDTH': switch(strtoupper($v)) { case 'THIN': $v = '0.03em'; break; case 'MEDIUM': $v = '0.05em'; break; case 'THICK': $v = '0.07em'; break; } $this->outlineparam['WIDTH'] = $this->ConvertSize($v,$this->blk[$this->blklvl]['inner_width'],$this->FontSize); break; case 'OUTLINE-COLOR': if (strtoupper($v) == 'INVERT') { if ($this->colorarray) { $cor = $this->colorarray; $this->outlineparam['COLOR'] = $this->_invertColor($cor); } else { $this->outlineparam['COLOR'] = $this->ConvertColor(255); } } else { $cor = $this->ConvertColor($v); if ($cor) { $this->outlineparam['COLOR'] = $cor ; } } break; case 'COLOR': // font color $cor = $this->ConvertColor($v); if ($cor) { $this->colorarray = $cor; $this->SetTColor($cor); } break; }//end of switch($k) }//end of foreach } /*-- END HTML-CSS --*/ function SetStyle($tag,$enable) { $this->$tag=$enable; $style=''; foreach(array('B','I','U','S') as $s) { if($this->$s) { $style.=$s; } } if ($this->S && empty($this->upperCase)) { @include(_MPDF_PATH.'includes/upperCase.php'); } // mPDF 5.3.99 $this->currentfontstyle=$style; $this->SetFont('',$style,0,false); } // Set multiple styles at one $str e.g. "BIS" function SetStylesArray($arr) { $style=''; foreach(array('B','I','U','S') as $s) { if (isset($arr[$s])) { if ($arr[$s]) { $this->$s = true; $style.=$s; } else { $this->$s = false; } } else if ($this->$s) { $style.=$s; } } $this->currentfontstyle=$style; $this->SetFont('',$style,0,false); } // Set multiple styles at one $str e.g. "BIS" function SetStyles($str) { $style=''; foreach(array('B','I','U','S') as $s) { if (strpos($str,$s) !== false) { $this->$s = true; $style.=$s; } else { $this->$s = false; } } $this->currentfontstyle=$style; $this->SetFont('',$style,0,false); } function ResetStyles() { foreach(array('B','I','U','S') as $s) { $this->$s = false; } $this->currentfontstyle=''; $this->SetFont('','',0,false); } function DisableTags($str='') { if ($str == '') //enable all tags { //Insert new supported tags in the long string below. $this->enabledtags = "<span><s><strike><del><bdo><big><small><ins><cite><acronym><font><sup><sub><b><u><i><a><strong><em><code><samp><tt><kbd><var><q><table><thead><tfoot><tbody><tr><th><td><ol><ul><li><dl><dt><dd><form><input><select><textarea><option><div><p><h1><h2><h3><h4><h5><h6><pre><center><blockquote><address><hr><img><br><indexentry><indexinsert><bookmark><watermarktext><watermarkimage><tts><ttz><tta><column_break><columnbreak><newcolumn><newpage><page_break><pagebreak><formfeed><columns><toc><tocentry><tocpagebreak><pageheader><pagefooter><setpageheader><setpagefooter><sethtmlpageheader><sethtmlpagefooter><annotation><template><jpgraph><barcode><dottab><caption><textcircle>"; // mPDF 5.3.56 5.3.A5 } else { $str = explode(",",$str); foreach($str as $v) $this->enabledtags = str_replace(trim($v),'',$this->enabledtags); } } /*-- TABLES --*/ function finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight) { $af = 0; // Above font $bf = 0; // Below font $mta = 0; // Maximum top-aligned $mba = 0; // Maximum bottom-aligned if ($lhxt['BS']) { $af = max($af, ($lhxt['BS'] - ($maxfontsize * (0.5 + $this->baselineC)))); } if ($lhxt['M']) { $af = max($af, ($lhxt['M'] - $maxfontsize)/2); $bf = max($bf, ($lhxt['M'] - $maxfontsize)/2); } if ($lhxt['TT']) { $bf = max($bf, ($lhxt['TT'] - $maxfontsize)); } if ($lhxt['TB']) { $af = max($af, ($lhxt['TB'] - $maxfontsize)); } if ($lhxt['T']) { $mta = max($mta, $lhxt['T']); } if ($lhxt['B']) { $mba = max($mba, $lhxt['B']); } if ((!$lhfixed || !$forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) { $maxlineHeight = $maxfontsize + $af + $bf; } else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; } if ($mta > $maxlineHeight) { $bf += ($mta - $maxlineHeight); $maxlineHeight = $mta; } if ($mba > $maxlineHeight) { $af += ($mba - $maxlineHeight); $maxlineHeight = $mba; } return $maxlineHeight; } function TableWordWrap($maxwidth, $forcewrap = 0, $textbuffer = '', $def_fontsize, $returnarray=false) { // NB ** returnarray used in flowchart $biggestword=0; $toonarrow=false; $curlyquote = mb_convert_encoding("\xe2\x80\x9e",$this->mb_enc,'UTF-8'); $curlylowquote = mb_convert_encoding("\xe2\x80\x9d",$this->mb_enc,'UTF-8'); $textbuffer[0][0] = preg_replace('/^[ ]*/','',$textbuffer[0][0]); if ((count($textbuffer) == 0) or ((count($textbuffer) == 1) && ($textbuffer[0][0] == ''))) { return 0; } $text = ''; $lhfixed = false; if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight)) { $lhfixed = true; } if ($lhfixed) { $def_lineheight = $this->_computeLineheight($this->table_lineheight, $def_fontsize);} else { $def_lineheight = 0; } // START OF NEW LINE // Initialise lineheight variables $maxfontsize = 0; $forceExactLineheight = true; $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0); $maxlineHeight = $def_lineheight ; $ch = 0; $width = 0; $ln = 1; // Counts line number $mxw = $this->GetCharWidth('W',false); // mPDF 5.3.04 foreach ($textbuffer as $cctr=>$chunk) { $line = $chunk[0]; //IMAGE if (substr($line,0,3) == "\xbb\xa4\xac") { //identifier has been identified! $objattr = $this->_getObjAttr($line); if ($objattr['type'] == 'nestedtable') { // END OF LINE // Finalise & add lineheight $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight); $level = $objattr['level']; $ih = $this->table[($level+1)][$objattr['nestedcontent']]['h']; // nested table width $ch += $ih; // START OF NEW LINE // Initialise lineheight variables $ln++; $maxfontsize = 0; $forceExactLineheight = true; $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0); $maxlineHeight = $def_lineheight ; $width = 0; $text = ""; continue; } list($skipln,$iw,$ih) = $this->inlineObject((isset($specialcontent['type']) ? $specialcontent['type'] : null),0,0, $objattr, $this->lMargin,$width,$maxwidth,$maxlineHeight,false,true); if ($objattr['type'] == 'hr') { // END OF LINE // Finalise & add lineheight $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight); // Add HR height $ch += $ih; // START OF NEW LINE // Initialise lineheight variables $ln++; $maxfontsize = 0; $forceExactLineheight = true; $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0); $maxlineHeight = $def_lineheight ; $width = 0; $text = ""; continue; } if ($skipln==1 || $skipln==-2) { // Finish last line // END OF LINE // Finalise & add lineheight $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight); // START OF NEW LINE // Initialise lineheight variables $maxfontsize = 0; $forceExactLineheight = true; $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0); $maxlineHeight = $def_lineheight ; $ln++; $width = 0; $text = ""; } $va = (isset($objattr['vertical-align']) ? $objattr['vertical-align'] : null); if ($va) { $lhxt[$va] = max($lhxt[$va], $ih); } if ($lhfixed && $ih > $def_fontsize) { $forceExactLineheight = false; } $maxlineHeight = max($maxlineHeight ,$ih); $width += $iw; continue; } // SET FONT SIZE/STYLE from $chunk[n] // FONTSIZE if(isset($chunk[11]) and $chunk[11] != '') { if ($this->shrin_k) { $this->SetFontSize($chunk[11]/$this->shrin_k,false); } else { $this->SetFontSize($chunk[11],false); } } if ($line == "\n") { // END OF LINE $maxfontsize = max($maxfontsize,$this->FontSize); $fh = $this->_computeLineheight($this->table_lineheight); if ($lhfixed && $this->FontSize > $def_fontsize) { $fh = $this->FontSize; $forceExactLineheight = false; } $maxlineHeight = max($maxlineHeight,$fh); // Finalise & add lineheight $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight); // START OF NEW LINE // Initialise lineheight variables $maxfontsize = 0; $forceExactLineheight = true; $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0); $maxlineHeight = $this->_computeLineheight($this->table_lineheight); $ln++; $text = ""; $width = 0; if(isset($chunk[11]) and $chunk[11] != '') { $this->SetFontSize($this->default_font_size,false); } continue; } // mPDF 5.3.61 $lbw = $rbw = 0; // Border widths if(isset($chunk[16]) && !empty($chunk[16])) { //Border $this->spanborddet = $chunk[16]; if (isset($this->spanborddet['L'])) $lbw = $this->spanborddet['L']['w']; // mPDF 5.3.76 if (isset($this->spanborddet['R'])) $rbw = $this->spanborddet['R']['w']; } if(isset($chunk[15])) { // Word spacing $this->wSpacingCSS = $chunk[15]; if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') { $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize); } } if(isset($chunk[14])) { // Letter spacing $this->lSpacingCSS = $chunk[14]; if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') { $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize); } } if(isset($chunk[13])) { // Font Kerning // mPDF 5.3.99 $this->kerning = $chunk[13]; } // FONTFAMILY if(isset($chunk[4]) and $chunk[4] != '') { $font = $this->SetFont($chunk[4],$this->FontStyle,0,false); } // FONT STYLE B I U if(isset($chunk[2]) and $chunk[2] != '') { $this->SetStyles($chunk[2]); } $space = $this->GetCharWidth(' ',false); // mPDF 5.3.04 if (mb_substr($line,0,1,$this->mb_enc ) == ' ') { // line (chunk) starts with a space $width += $space; $text .= ' '; } if (mb_substr($line,(mb_strlen($line,$this->mb_enc )-1),1,$this->mb_enc ) == ' ') { $lsend = true; } // line (chunk) ends with a space else { $lsend = false; } $line= trim($line); if ($line == '') { continue; } // mPDF ITERATION if ($this->iterationCounter) $line = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/','\\1', $line); $words = explode(' ', $line); foreach ($words as $k=>$word) { // mPDF 5.3.61 $word = trim($word); $wordwidth = $this->GetStringWidth($word); // mPDF 5.3.61 if ($k==0) { $wordwidth += $lbw; } if ($k==(count($words)-1)) { $wordwidth += $rbw; } //maxwidth is insufficient for one word if ($wordwidth > $maxwidth + 0.0001) { $firstchunk=true; while($wordwidth > $maxwidth + 0.0001) { $chw = 0; // check width $oneCJKorphan = false; $mlen = mb_strlen($word, $this->mb_enc ); // mPDF 5.3.07 for ( $i = 0; $i < $mlen; $i++ ) { // mPDF 5.3.07 $chw = $this->GetStringWidth(mb_substr($word,0,$i+1,$this->mb_enc )); // mPDF 5.3.61 if ($k==0) { $chw += $lbw; } if ($k==(count($words)-1)) { $chw += $rbw; } if ($chw > $maxwidth) { if ($i==0 && $firstchunk) { // If first letter of line does not fit $wordwidth = $maxwidth - 0.0001; if ($this->debug) { $this->Error("Table cell width calculated less than that needed for one character!"); } break; } if (!$oneCJKorphan && (preg_match('/[\.\]),;:!?"'.$curlyquote . $curlylowquote.']$/',mb_substr($word,0,$i+1,$this->mb_enc )) || (!$this->usingCoreFont && preg_match('/['.$this->CJKoverflow.']$/u',mb_substr($word,0,$i+1,$this->mb_enc ))))) { $wordwidth = $maxwidth - 0.0001; $oneCJKorphan = true; continue; } if ($text && $firstchunk) { // END OF LINE // Finalise & add lineheight $maxfontsize = max($maxfontsize,$this->FontSize); $fh = $this->_computeLineheight($this->table_lineheight); if ($lhfixed && $this->FontSize > $def_fontsize) { $fh = $this->FontSize; $forceExactLineheight = false; } $maxlineHeight = max($maxlineHeight,$fh); $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight); // START OF NEW LINE // Initialise lineheight variables $maxfontsize = $this->FontSize; $forceExactLineheight = true; $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0); $maxlineHeight = $this->_computeLineheight($this->table_lineheight); $ln++; } // END OF LINE // Finalise & add lineheight $maxfontsize = max($maxfontsize,$this->FontSize); $fh = $this->_computeLineheight($this->table_lineheight); if ($lhfixed && $this->FontSize > $def_fontsize) { $fh = $this->FontSize; $forceExactLineheight = false; } $maxlineHeight = max($maxlineHeight,$fh); $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight); // START OF NEW LINE // Initialise lineheight variables $maxfontsize = $this->FontSize; $forceExactLineheight = true; $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0); $maxlineHeight = $this->_computeLineheight($this->table_lineheight); $ln++; $mxw = $maxwidth; $text = mb_substr($word,0,$i,$this->mb_enc ); $word = mb_substr($word,$i,mb_strlen($word, $this->mb_enc )-$i,$this->mb_enc ); $wordwidth = $this->GetStringWidth($word); $width = 0; $firstchunk=false; break; } } if (mb_strlen($word, $this->mb_enc )<2 && $wordwidth > $maxwidth + 0.0001) { $wordwidth = $maxwidth - 0.0001; if ($this->debug) { $this->Error("Table cell width calculated less than that needed for single character!"); } } $firstchunk=false; } } // Word fits on line... if ($width + $wordwidth < $maxwidth + 0.0001) { $mxw = max($mxw, ($width+$wordwidth)); $width += $wordwidth + $space; $text .= $word.' '; } // Word does not fit on line... else { $alloworphans = false; // In case of orphan punctuation or SUB/SUP // Strip end punctuation $tmp = preg_replace('/[\.\]),;:!?"'.$curlyquote . $curlylowquote.']{1}$/','',$word); if (!$this->usingCoreFont) { $tmp = preg_replace('/['.$this->CJKoverflow.']{1}$/u','',$tmp); } // *CJK-FONTS* if ($tmp !== $word && (($this->usingCoreFont && !preg_match('/[\.\]),;:!?"'.$curlyquote . $curlylowquote.']$/',$tmp)) || (!$this->usingCoreFont && !preg_match('/[\.\]),;:!?"'.$curlyquote . $curlylowquote .$this->CJKoverflow.']$/u',$tmp)))) { $tmpwidth = $this->GetStringWidth($tmp); // mPDF 5.3.61 if ($k==0) { $tmpwidth += $lbw; } if ($k==(count($words)-1)) { $tmpwidth += $rbw; } if ($width + $tmpwidth < $maxwidth + 0.0001) { $alloworphans = true; } } // If line = SUB/SUP to max of orphansallowed ( $this->SUP || $this->SUB ) if(( (isset($chunk[5]) and $chunk[5]) || (isset($chunk[6]) and $chunk[6])) && strlen($word) <= $this->orphansAllowed) { $alloworphans = true; } // if [stripped] word fits if ($alloworphans) { $mxw = $maxwidth; $width += $wordwidth + $space; $text .= $word.' '; } else { /*-- HYPHENATION --*/ // Soft Hyphens chr(173) if ((!$this->usingCoreFont && preg_match("/\xc2\xad/",$word)) || ($this->usingCoreFont && preg_match("/".chr(173)."/",$word) && ($this->FontFamily!='csymbol' && $this->FontFamily!='czapfdingbats')) ) { list($success,$pre,$post,$prelength) = $this->softHyphenate($word, ($maxwidth - $width)); if ($success) { $text .= $pre.'-'; $word = $post; $wordwidth = $this->GetStringWidth($word); // mPDF 5.3.61 if ($k==(count($words)-1)) { $wordwidth += $rbw; } } } else if ($this->hyphenate || ($this->hyphenateTables)) { list($success,$pre,$post,$prelength) = $this->hyphenateWord($word, ($maxwidth - $width)); if ($success) { $text .= $pre.'-'; $word = $post; $wordwidth = $this->GetStringWidth($word); // mPDF 5.3.61 if ($k==(count($words)-1)) { $wordwidth += $rbw; } } } /*-- END HYPHENATION --*/ // END OF LINE // Finalise & add lineheight $maxfontsize = max($maxfontsize,$this->FontSize); $fh = $this->_computeLineheight($this->table_lineheight); if ($lhfixed && $this->FontSize > $def_fontsize) { $fh = $this->FontSize; $forceExactLineheight = false; } $maxlineHeight = max($maxlineHeight,$fh); $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight); $mxw = $maxwidth; // START OF NEW LINE // Initialise lineheight variables $maxfontsize = $this->FontSize; $forceExactLineheight = true; $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0); $maxlineHeight = $this->_computeLineheight($this->table_lineheight); $ln++; $width = $wordwidth + $space; $text = $word.' '; } } $maxfontsize = max($maxfontsize,$this->FontSize); $fh = $this->_computeLineheight($this->table_lineheight); if ($lhfixed && $this->FontSize > $def_fontsize) { $fh = $this->FontSize; $forceExactLineheight = false; } $maxlineHeight = max($maxlineHeight,$fh); } // End of textbuffer chunk if (!$lsend) { $width -= $space; $text = rtrim($text); } // RESET FONT SIZE/STYLE // RESETTING VALUES //Now we must deactivate what we have used if(isset($chunk[2]) and $chunk[2] != '') { $this->ResetStyles(); } if(isset($chunk[4]) and $chunk[4] != '') { $this->SetFont($this->default_font,$this->FontStyle,0,false); } if(isset($chunk[11]) and $chunk[11] != '') { $this->SetFontSize($this->default_font_size,false); } $this->spanborddet = array(); // mPDF 5.3.61 $this->kerning = false; $this->lSpacingCSS = ''; $this->wSpacingCSS = ''; $this->fixedlSpacing = false; $this->minwSpacing = 0; } // Finalise lineheight if something output on line and add if ($width) { $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight); } if ($returnarray) { return array($ch,$ln,$mxw); } else { return $ch; } } function TableCheckMinWidth($maxwidth, $forcewrap = 0, $textbuffer) { // mPDF 5.3.78 $biggestword=0; $toonarrow=false; if ((count($textbuffer) == 0) or ((count($textbuffer) == 1) && ($textbuffer[0][0] == ''))) { return 0; } foreach ($textbuffer as $chunk) { $line = $chunk[0]; // mPDF ITERATION if ($this->iterationCounter) $line = preg_replace('/{iteration ([a-zA-Z0-9_]+)}/','\\1', $line); // IMAGES & FORM ELEMENTS if (substr($line,0,3) == "\xbb\xa4\xac") { //inline object - FORM element or IMAGE! $objattr = $this->_getObjAttr($line); if ($objattr['type']!='hr' && isset($objattr['width']) && ($objattr['width']/$this->shrin_k) > ($maxwidth + 0.0001) ) { if (($objattr['width']/$this->shrin_k) > $biggestword) { $biggestword = ($objattr['width']/$this->shrin_k); } $toonarrow=true; } continue; } if ($line == "\n") { continue; } $line = trim($line ); // SET FONT SIZE/STYLE from $chunk[n] // FONTSIZE if(isset($chunk[11]) and $chunk[11] != '') { if ($this->shrin_k) { $this->SetFontSize($chunk[11]/$this->shrin_k,false); } else { $this->SetFontSize($chunk[11],false); } } // FONTFAMILY if(isset($chunk[4]) and $chunk[4] != '') { $font = $this->SetFont($chunk[4],$this->FontStyle,0,false); } // B I U if(isset($chunk[2]) and $chunk[2] != '') { $this->SetStyles($chunk[2]); } // mPDF 5.3.61 $lbw = $rbw = 0; // Border widths if(isset($chunk[16]) && !empty($chunk[16])) { //Border $this->spanborddet = $chunk[16]; $lbw = $this->spanborddet['L']['w']; $rbw = $this->spanborddet['R']['w']; } if(isset($chunk[15])) { // Word spacing $this->wSpacingCSS = $chunk[15]; if ($this->wSpacingCSS && strtoupper($this->wSpacingCSS) != 'NORMAL') { $this->minwSpacing = $this->ConvertSize($this->wSpacingCSS,$this->FontSize); } } if(isset($chunk[14])) { // Letter spacing $this->lSpacingCSS = $chunk[14]; if (($this->lSpacingCSS || $this->lSpacingCSS==='0') && strtoupper($this->lSpacingCSS) != 'NORMAL') { $this->fixedlSpacing = $this->ConvertSize($this->lSpacingCSS,$this->FontSize); } } if(isset($chunk[13])) { // Font Kerning $this->kerning = $chunk[13]; } $words = explode(' ', $line); foreach ($words as $k=>$word) { // mPDF 5.3.61 $word = trim($word); $wordwidth = $this->GetStringWidth($word); // mPDF 5.3.61 if ($k==0) { $wordwidth += $lbw; } if ($k==(count($words)-1)) { $wordwidth += $rbw; } //Warn user that maxwidth is insufficient if ($wordwidth > $maxwidth + 0.0001) { if ($wordwidth > $biggestword) { $biggestword = $wordwidth; } $toonarrow=true; } } // RESET FONT SIZE/STYLE // RESETTING VALUES //Now we must deactivate what we have used if(isset($chunk[2]) and $chunk[2] != '') { $this->ResetStyles(); } if(isset($chunk[4]) and $chunk[4] != '') { $this->SetFont($this->default_font,$this->FontStyle,0,false); } if(isset($chunk[11]) and $chunk[11] != '') { $this->SetFontSize($this->default_font_size,false); } // mPDF 5.3.61 $this->spanborddet = array(); $this->kerning = false; $this->lSpacingCSS = ''; $this->wSpacingCSS = ''; $this->fixedlSpacing = false; $this->minwSpacing = 0; } //Return -(wordsize) if word is bigger than maxwidth // ADDED if (($toonarrow) && ($this->table_error_report)) { $this->Error("Word is too long to fit in table - ".$this->table_error_report_param); } if ($toonarrow) return -$biggestword; else return 1; } function shrinkTable(&$table,$k) { $table['border_spacing_H'] /= $k; $table['border_spacing_V'] /= $k; $table['padding']['T'] /= $k; $table['padding']['R'] /= $k; $table['padding']['B'] /= $k; $table['padding']['L'] /= $k; $table['margin']['T'] /= $k; $table['margin']['R'] /= $k; $table['margin']['B'] /= $k; $table['margin']['L'] /= $k; $table['border_details']['T']['w'] /= $k; $table['border_details']['R']['w'] /= $k; $table['border_details']['B']['w'] /= $k; $table['border_details']['L']['w'] /= $k; if (isset($table['max_cell_border_width']['T'])) $table['max_cell_border_width']['T'] /= $k; if (isset($table['max_cell_border_width']['R'])) $table['max_cell_border_width']['R'] /= $k; if (isset($table['max_cell_border_width']['B'])) $table['max_cell_border_width']['B'] /= $k; if (isset($table['max_cell_border_width']['L'])) $table['max_cell_border_width']['L'] /= $k; if ($this->simpleTables){ $table['simple']['border_details']['T']['w'] /= $k; $table['simple']['border_details']['R']['w'] /= $k; $table['simple']['border_details']['B']['w'] /= $k; $table['simple']['border_details']['L']['w'] /= $k; } $table['miw'] /= $k; $table['maw'] /= $k; // mPDF 5.3.79 if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); } for($j = 0 ; $j < $table['nc'] ; $j++ ) { //columns $table['wc'][$j]['miw'] /= $k; $table['wc'][$j]['maw'] /= $k; if (isset($table['wc'][$j]['absmiw']) && $table['wc'][$j]['absmiw'] ) $table['wc'][$j]['absmiw'] /= $k; for($i = 0 ; $i < $table['nr']; $i++ ) { //rows // mPDF 5.3.79 if ($this->cacheTables) { $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh); } else $c = &$table['cells'][$i][$j]; if (isset($c) && $c) { if (!$this->simpleTables){ if ($this->packTableData) { $cell = $this->_unpackCellBorder($c['borderbin'] ); $cell['border_details']['T']['w'] /= $k; $cell['border_details']['R']['w'] /= $k; $cell['border_details']['B']['w'] /= $k; $cell['border_details']['L']['w'] /= $k; $cell['border_details']['mbw']['TL'] /= $k; $cell['border_details']['mbw']['TR'] /= $k; $cell['border_details']['mbw']['BL'] /= $k; $cell['border_details']['mbw']['BR'] /= $k; $cell['border_details']['mbw']['LT'] /= $k; $cell['border_details']['mbw']['LB'] /= $k; $cell['border_details']['mbw']['RT'] /= $k; $cell['border_details']['mbw']['RB'] /= $k; $c['borderbin'] = $this->_packCellBorder($cell); } else { $c['border_details']['T']['w'] /= $k; $c['border_details']['R']['w'] /= $k; $c['border_details']['B']['w'] /= $k; $c['border_details']['L']['w'] /= $k; $c['border_details']['mbw']['TL'] /= $k; $c['border_details']['mbw']['TR'] /= $k; $c['border_details']['mbw']['BL'] /= $k; $c['border_details']['mbw']['BR'] /= $k; $c['border_details']['mbw']['LT'] /= $k; $c['border_details']['mbw']['LB'] /= $k; $c['border_details']['mbw']['RT'] /= $k; $c['border_details']['mbw']['RB'] /= $k; } } $c['padding']['T'] /= $k; $c['padding']['R'] /= $k; $c['padding']['B'] /= $k; $c['padding']['L'] /= $k; $c['maxs'] /= $k; if (isset($c['w'])) { $c['w'] /= $k; } $c['s'] /= $k; $c['maw'] /= $k; $c['miw'] /= $k; if (isset($c['absmiw'])) $c['absmiw'] /= $k; if (isset($c['nestedmaw'])) $c['nestedmaw'] /= $k; if (isset($c['nestedmiw'])) $c['nestedmiw'] /= $k; // mPDF 5.3.61 if (isset($c['textbuffer'])) { foreach($c['textbuffer'] AS $n=>$tb) { if (!empty($tb[16])) { $c['textbuffer'][$n][16]['T']['w'] /= $k; $c['textbuffer'][$n][16]['B']['w'] /= $k; $c['textbuffer'][$n][16]['L']['w'] /= $k; $c['textbuffer'][$n][16]['R']['w'] /= $k; } } } // mPDF 5.3.79 if ($this->cacheTables) { $this->_cacheCell($c, '', "W", $fh, $table['cells'][$i][$j]); } unset($c); // mPDF 5.3.79 } }//rows }//columns // mPDF 5.3.79 if ($this->cacheTables) { fclose($fh); } } // mPDF 5.3.79 function _cacheCell($c, $file, $mode="A", $fh=null, $offset=0) { // mode = Append or (over)Write (needs offset and fh) // Requires either $file OR $fh (file_handle) if (!is_array($c) || !isset($c)) { return ''; } if(isset($c['w'])) { $cw = $c['w']; } else { $cw = -1; } if(isset($c['w0'])) { $cw0 = $c['w0']; } else { $cw0 = -1; } if(isset($c['h0'])) { $ch0 = $c['h0']; } else { $ch0 = -1; } $data = pack("n2d19A1A1n2sA32A128", $c['colspan'], /* n (16 bit; 2 bytes) [pos 0] */ $c['rowspan'], /* n (16 bit; 2 bytes) [pos 2] */ $c['s'], /* d NB machine-dependent size (64 bit; 8 bytes on test winOS) [pos 4] */ $c['maxs'], /* d NB machine-dependent size [pos 4 + 1*D] */ $c['nestedmaw'], /* d NB machine-dependent size [pos 4 + 2*D] */ $c['nestedmiw'], /* d NB machine-dependent size [pos 4 + 3*D] */ $c['padding']['L'], /* d NB machine-dependent size [pos 4 + 4*D] */ $c['padding']['R'], /* d NB machine-dependent size [pos 4 + 5*D] */ $c['padding']['T'], /* d NB machine-dependent size [pos 4 + 6*D] */ $c['padding']['B'], /* d NB machine-dependent size [pos 4 + 7*D] */ $c['dfs'], /* d NB machine-dependent size [pos 4 + 8*D] */ $cw, /* d NB machine-dependent size [pos 4 + 9*D] */ $c['h'], /* d NB machine-dependent size [pos 4 + 10*D] */ $c['absmiw'], /* d NB machine-dependent size [pos 4 + 11*D] */ $c['maw'], /* d NB machine-dependent size [pos 4 + 12*D] */ $c['miw'], /* d NB machine-dependent size [pos 4 + 13*D] */ $c['mih'], /* d NB machine-dependent size [pos 4 + 14*D] */ $c['x0'], /* d NB machine-dependent size [pos 4 + 15*D] */ $cw0, /* d NB machine-dependent size [pos 4 + 16*D] */ $c['y0'], /* d NB machine-dependent size [pos 4 + 17*D] */ $ch0, /* d NB machine-dependent size [pos 4 + 18*D] */ $c['a'], /* A1 (1 byte) [pos 4 + 19*D] */ $c['va'], /* A1 (1 byte) [pos 5 + 19*D] */ $c['nowrap'], /* 1 or blank n (16 bit; 2 bytes) [pos 6 + 19*D] */ $c['wpercent'], /* 0 - 100 n (16 bit; 2 bytes) [pos 8 + 19*D] */ $c['R'], /* 90 or -90 s (16 bit; 2 bytes) [pos 10 + 19*D] */ $c['bgcolor'], /* A32 (32 bytes) [pos 12 + 19*D] */ $c['gradient'] /* A128 (128 bytes) [pos 44 + 19*D] */ ); if ($c['background-image']) { $data .= pack("n2d2A6A6n3dA4A128", strlen($data), /* offset in main data to start of bgimage data */ $c['background-image']['image_id'], /* n */ $c['background-image']['orig_w'], /* d NB machine-dependent size */ $c['background-image']['orig_h'], /* d NB machine-dependent size */ $c['background-image']['x_pos'], /* A6 calc size or "50%" */ $c['background-image']['y_pos'], /* A6 calc size or "50%" */ $c['background-image']['x_repeat'], /* n true or false*/ $c['background-image']['y_repeat'], /* n true or false */ $c['background-image']['resize'], /* n 0 - 6 */ $c['background-image']['opacity'], /* d 0-1 */ $c['background-image']['itype'], /* A4 jpg etc */ $c['background-image']['gradient'] /* A128 CSS string */ ); } else $data .= pack("n",0); $tb_offset = 2 + 186 + 2 + strlen($data); $stb = serialize($c['textbuffer']).' '; // buffer to allow updating in reverseTableDir $lentb = strlen($stb); $data2 = pack("nA".$lentb, $lentb, $stb); $tempfh = true; if ($mode=="W" && $offset) { if (!$fh) { $fh = fopen($file, "r+b"); } // Overwrite (but not truncate) else $tempfh = false; fseek($fh, $offset); } else { $fh = fopen($file, "ab"); // APPEND } fwrite($fh, pack("n",$tb_offset)); // Offset to Text buffer 2 bytes fwrite($fh, $c['borderbin']); // border details 186 bytes fwrite($fh, pack("n",strlen($data))); // Length of Main data fwrite($fh, $data); // Main data fwrite($fh, $data2); // Text buffer (starts with "n" length of text buffer) if ($tempfh) fclose($fh); return ($tb_offset + 2 + $lentb); } // mPDF 5.3.79 function _cacheUpdateTxB($c, $fh, $offset) { fseek($fh, $offset); $tb_offset = $this->read_short($fh); // First entry = Offset to Text buffer 2 bytes fseek($fh, ($tb_offset-2), SEEK_CUR); $lentb = $this->read_short($fh); // First entry in textbuffer = Length of serialized textbuffer - do not update $stb = serialize($c['textbuffer']); fwrite($fh, pack("A".$lentb, $stb)); } // mPDF 5.3.79 function _cacheUpdateBorder($c, $fh, $offset) { $offset += 2; fseek($fh, $offset); fwrite($fh, $c['borderbin']); } // mPDF 5.3.79 function _cacheUpdateMtx($c, $fh, $offset, $var) { if ($var=='mih') { $offset += (2 + 186 + 2 + 4 + 14*_DSIZE); } else if ($var=='x0') { $offset += (2 + 186 + 2 + 4 + 15*_DSIZE); } // x0 and w0 else if ($var=='y0') { $offset += (2 + 186 + 2 + 4 + 17*_DSIZE); } // y0 and h0 fseek($fh, $offset); if ($var=='mih') { fwrite($fh, pack("d",$c['mih'])); } else if ($var=='x0') { fwrite($fh, pack("d2",$c['x0'],$c['w0'])); } else if ($var=='y0') { fwrite($fh, pack("d2",$c['y0'],$c['h0'])); } } // mPDF 5.3.79 function _uncacheCell($ptr, $file, $fh) { // Requires either $file or $fh (file_handle) if ($ptr==0) { return null; } if (is_array($ptr)) { $this->Error("Probable cause - missing end tag &lt;/td&gt;. You may be able to change the configurable variable: allow_html_optional_endtags "); } $tempfh = true; if (!$fh) { $fh = fopen($file, "rb"); } else $tempfh = false; fseek($fh, $ptr); $c = array(); $tb_offset = $this->read_short($fh); // First entry = Offset to Text buffer 2 bytes $c['borderbin'] = fread($fh,186); // border details 186 bytes $maindatalen = $this->read_short($fh); // Length of Main data (2 bytes) $str = fread($fh,$maindatalen ); // Main data $data = unpack("ncolspan/nrowspan/ds/dmaxs/dnmaw/dnmiw/dpl/dpr/dpt/dpb/ddfs/dw/dh/dabsmiw/dmaw/dmiw/dmih/dx0/dw0/dy0/dh0/A1a/A1va/nnowrap/nwpercent/sR/A32bgcol/A128grad/nbgimage", $str); if ($data['colspan']>0) $c['colspan'] = $data['colspan']; /* n */ if ($data['rowspan']>0) $c['rowspan'] = $data['rowspan']; /* n */ $c['s'] = $data['s']; /* d NB machine-dependent size */ $c['maxs'] = $data['maxs']; /* d NB machine-dependent size */ if ($data['nmaw']>0) $c['nestedmaw'] = $data['nmaw']; /* d NB machine-dependent size */ if ($data['nmiw']>0) $c['nestedmiw'] = $data['nmiw']; /* d NB machine-dependent size */ $c['padding']['L'] = $data['pl']; /* d NB machine-dependent size */ $c['padding']['R'] = $data['pr']; /* d NB machine-dependent size */ $c['padding']['T'] = $data['pt']; /* d NB machine-dependent size */ $c['padding']['B'] = $data['pb']; /* d NB machine-dependent size */ $c['dfs'] = $data['dfs']; /* d NB machine-dependent size */ if ($data['w']>=0) $c['w'] = $data['w']; /* d NB machine-dependent size */ if ($data['h']>0) $c['h'] = $data['h']; /* d NB machine-dependent size */ if ($data['absmiw']>0) $c['absmiw'] = $data['absmiw']; /* d NB machine-dependent size */ if ($data['maw']>0) $c['maw'] = $data['maw']; /* d NB machine-dependent size */ if ($data['miw']>0) $c['miw'] = $data['miw']; /* d NB machine-dependent size */ if ($data['mih']>0) $c['mih'] = $data['mih']; /* d NB machine-dependent size */ if ($data['w0']>=0) { $c['w0'] = $data['w0']; /* d NB machine-dependent size */ $c['x0'] = $data['x0']; } /* d NB machine-dependent size */ if ($data['h0']>=0) { $c['h0'] = $data['h0']; /* d NB machine-dependent size */ $c['y0'] = $data['y0']; } /* d NB machine-dependent size */ $c['a'] = trim($data['a']); /* A1 */ $c['va'] = trim($data['va']); /* A1 */ if ($data['nowrap']) $c['nowrap'] = $data['nowrap']; /* 1 or blank n */ else $c['nowrap'] = false; if ($data['wpercent']>0) $c['wpercent'] = $data['wpercent']; /* 0 - 100 n */ if ($data['R']<>0) $c['R'] = $data['R']; /* 90 or -90 s */ else $c['R'] = false; $c['bgcolor'] = trim($data['bgcol']); /* A32 */ if (trim($data['grad'])) $c['gradient'] = trim($data['grad']); /* A128 */ else $c['gradient'] = false; if ($data['bgimage']>0) { $bgidata = substr($str, ($data['bgimage']+2)); $c['background-image'] = unpack("nimage_id/dorig_w/dorig_h/A6x_pos/A6y_pos/nx_repeat/ny_repeat/nresize/dopacity/A4itype/A128gradient", $bgidata); } $tblen = $this->read_short($fh); // Length of Textbuffer $tbsp = fread($fh,$tblen); // Textbuffer (serialised and packed) $tbs = unpack("A".$tblen."textbuffer",$tbsp); // Textbuffer unpacked $c['textbuffer'] = unserialize(trim($tbs['textbuffer'])); // Textbuffer unserialized if ($tempfh) { fclose($fh); } return ($c); } // mPDF 5.3.79 function read_short(&$fh) { $s = fread($fh,2); $a = (ord($s[0])<<8) + ord($s[1]); if ($a & (1 << 15) ) { $a = ($a - (1 << 16)); } return $a; } // mPDF 5.3.79 function _backupCacheFiles() { foreach($this->table AS $lvl=>$t) { foreach($this->table[$lvl] AS $c=>$t2) { ///////////////////////////if (!file_exists($t2['cache'])) { echo $lvl; echo $c; print_r($this->table); exit; } copy( $t2['cache'], $t2['cache'].'.bak'); } } } // mPDF 5.3.79 function _restoreCacheFiles() { foreach($this->table AS $lvl=>$t) { foreach($this->table[$lvl] AS $c=>$t2) { copy( $t2['cache'].'.bak', $t2['cache']); } } } function _packCellBorder($cell) { if (!is_array($cell) || !isset($cell)) { return ''; } if (!$this->packTableData) { return $cell; } // mPDF 5.3.74 // = 186 bytes $bindata = pack("nnda6A10nnda6A10nnda6A10nnda6A10nd9", $cell['border'], $cell['border_details']['R']['s'], $cell['border_details']['R']['w'], $cell['border_details']['R']['c'], $cell['border_details']['R']['style'], $cell['border_details']['R']['dom'], $cell['border_details']['L']['s'], $cell['border_details']['L']['w'], $cell['border_details']['L']['c'], $cell['border_details']['L']['style'], $cell['border_details']['L']['dom'], $cell['border_details']['T']['s'], $cell['border_details']['T']['w'], $cell['border_details']['T']['c'], $cell['border_details']['T']['style'], $cell['border_details']['T']['dom'], $cell['border_details']['B']['s'], $cell['border_details']['B']['w'], $cell['border_details']['B']['c'], $cell['border_details']['B']['style'], $cell['border_details']['B']['dom'], $cell['border_details']['mbw']['BL'], $cell['border_details']['mbw']['BR'], $cell['border_details']['mbw']['RT'], $cell['border_details']['mbw']['RB'], $cell['border_details']['mbw']['TL'], $cell['border_details']['mbw']['TR'], $cell['border_details']['mbw']['LT'], $cell['border_details']['mbw']['LB'], $cell['border_details']['cellposdom'] ); return $bindata; } function _getBorderWidths($bindata) { if (!$bindata) { return array(0,0,0,0); } if (!$this->packTableData) { return array($bindata['border_details']['T']['w'], $bindata['border_details']['R']['w'], $bindata['border_details']['B']['w'], $bindata['border_details']['L']['w']); } // mPDF 5.3.74 $bd = unpack("nbord/nrs/drw/a6rca/A10rst/nrd/nls/dlw/a6lca/A10lst/nld/nts/dtw/a6tca/A10tst/ntd/nbs/dbw/a6bca/A10bst/nbd/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd", $bindata); $cell['border_details']['R']['w'] = $bd['rw']; $cell['border_details']['L']['w'] = $bd['lw']; $cell['border_details']['T']['w'] = $bd['tw']; $cell['border_details']['B']['w'] = $bd['bw']; return array($bd['tw'], $bd['rw'], $bd['bw'], $bd['lw']); } function _unpackCellBorder($bindata) { if (!$bindata) { return array(); } if (!$this->packTableData) { return $bindata; } // mPDF 5.3.74 $bd = unpack("nbord/nrs/drw/a6rca/A10rst/nrd/nls/dlw/a6lca/A10lst/nld/nts/dtw/a6tca/A10tst/ntd/nbs/dbw/a6bca/A10bst/nbd/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd", $bindata); $cell['border'] = $bd['bord']; $cell['border_details']['R']['s'] = $bd['rs']; $cell['border_details']['R']['w'] = $bd['rw']; $cell['border_details']['R']['c'] = $bd['rca']; $cell['border_details']['R']['style'] = trim($bd['rst']); $cell['border_details']['R']['dom'] = $bd['rd']; $cell['border_details']['L']['s'] = $bd['ls']; $cell['border_details']['L']['w'] = $bd['lw']; $cell['border_details']['L']['c'] = $bd['lca']; $cell['border_details']['L']['style'] = trim($bd['lst']); $cell['border_details']['L']['dom'] = $bd['ld']; $cell['border_details']['T']['s'] = $bd['ts']; $cell['border_details']['T']['w'] = $bd['tw']; $cell['border_details']['T']['c'] = $bd['tca']; $cell['border_details']['T']['style'] = trim($bd['tst']); $cell['border_details']['T']['dom'] = $bd['td']; $cell['border_details']['B']['s'] = $bd['bs']; $cell['border_details']['B']['w'] = $bd['bw']; $cell['border_details']['B']['c'] = $bd['bca']; $cell['border_details']['B']['style'] = trim($bd['bst']); $cell['border_details']['B']['dom'] = $bd['bd']; $cell['border_details']['mbw']['BL'] = $bd['mbl']; $cell['border_details']['mbw']['BR'] = $bd['mbr']; $cell['border_details']['mbw']['RT'] = $bd['mrt']; $cell['border_details']['mbw']['RB'] = $bd['mrb']; $cell['border_details']['mbw']['TL'] = $bd['mtl']; $cell['border_details']['mbw']['TR'] = $bd['mtr']; $cell['border_details']['mbw']['LT'] = $bd['mlt']; $cell['border_details']['mbw']['LB'] = $bd['mlb']; $cell['border_details']['cellposdom'] = $bd['cpd']; return($cell); } ////////////////////////TABLE CODE (from PDFTable)///////////////////////////////////// ////////////////////////TABLE CODE (from PDFTable)///////////////////////////////////// ////////////////////////TABLE CODE (from PDFTable)///////////////////////////////////// //table Array of (w, h, bc, nr, wc, hr, cells) //w Width of table //h Height of table //nc Number column //nr Number row //hr List of height of each row //wc List of width of each column //cells List of cells of each rows, cells[i][j] is a cell in the table function _tableColumnWidth(&$table,$firstpass=false){ $cs = &$table['cells']; $nc = $table['nc']; $nr = $table['nr']; $listspan = array(); if ($table['borders_separate']) { $tblbw = $table['border_details']['L']['w'] + $table['border_details']['R']['w'] + $table['margin']['L'] + $table['margin']['R'] + $table['padding']['L'] + $table['padding']['R'] + $table['border_spacing_H']; } else { $tblbw = $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2 + $table['margin']['L'] + $table['margin']['R']; } // mPDF 5.3.79 if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); } else { $fh = null; } // ADDED table['l'][colno] // = total length of text approx (using $c['s']) in that column - used to approximately distribute col widths in _tableWidth // for($j = 0 ; $j < $nc ; $j++ ) { //columns $wc = &$table['wc'][$j]; for($i = 0 ; $i < $nr ; $i++ ) { //rows if (isset($cs[$i][$j]) && $cs[$i][$j]) { // mPDF 5.3.79 if ($this->cacheTables) { $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh); } else $c = &$cs[$i][$j]; if ($this->simpleTables){ if ($table['borders_separate']) { // NB twice border width $extrcw = $table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'] + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H']; } else { $extrcw = $table['simple']['border_details']['L']['w']/2 + $table['simple']['border_details']['R']['w']/2 + $c['padding']['L'] + $c['padding']['R']; } } else { if ($this->packTableData) { list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']); } else { $br = $c['border_details']['R']['w']; $bl = $c['border_details']['L']['w']; } if ($table['borders_separate']) { // NB twice border width $extrcw = $bl + $br + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H']; } else { $extrcw = $bl/2 + $br/2 + $c['padding']['L'] + $c['padding']['R']; } } //$mw = $this->GetStringWidth('W') + $extrcw ; $mw = 0; $c['absmiw'] = $mw; if (isset($c['R']) && $c['R']) { $c['maw'] = $c['miw'] = $this->FontSize + $extrcw ; if (isset($c['w'])) { // If cell width is specified if ($c['miw'] <$c['w']) { $c['miw'] = $c['w']; } } if (!isset($c['colspan'])) { if ($wc['miw'] < $c['miw']) { $wc['miw'] = $c['miw']; } if ($wc['maw'] < $c['maw']) { $wc['maw'] = $c['maw']; } if ($firstpass) { if (isset($table['l'][$j]) ) { $table['l'][$j] += $c['miw'] ; } else { $table['l'][$j] = $c['miw'] ; } } } if ($c['miw'] > $wc['miw']) { $wc['miw'] = $c['miw']; } if ($wc['miw'] > $wc['maw']) { $wc['maw'] = $wc['miw']; } continue; } if ($firstpass) { if (isset($c['s'])) { $c['s'] += $extrcw; } if (isset($c['maxs'])) { $c['maxs'] += $extrcw; } if (isset($c['nestedmiw'])) { $c['nestedmiw'] += $extrcw; } if (isset($c['nestedmaw'])) { $c['nestedmaw'] += $extrcw; } } // If minimum width has already been set by a nested table or inline object (image/form), use it if (isset($c['nestedmiw']) && $this->table[1][1]['overflow']!='visible') { $miw = $c['nestedmiw']; } // mPDF 5.3.36 else { $miw = $mw; } if (isset($c['maxs']) && $c['maxs'] != '') { $c['s'] = $c['maxs']; } // If maximum width has already been set by a nested table, use it if (isset($c['nestedmaw'])) { $c['maw'] = $c['nestedmaw']; } else $c['maw'] = $c['s']; // mPDF 5.3.36 if (isset($table['overflow']) && $table['overflow']=='visible' && $table['level']==1) { if (($c['maw'] + $tblbw) > $this->blk[$this->blklvl]['inner_width']) { $c['maw'] = $this->blk[$this->blklvl]['inner_width'] - $tblbw; } } if (isset($c['nowrap']) && $c['nowrap']) { $miw = $c['maw']; } if (isset($c['wpercent']) && $firstpass) { if (isset($c['colspan'])) { // Not perfect - but % set on colspan is shared equally on cols. for($k=0;$k<$c['colspan'];$k++) { $table['wc'][($j+$k)]['wpercent'] = $c['wpercent'] / $c['colspan']; } } else { if (isset($table['w']) && $table['w']) { $c['w'] = $c['wpercent']/100 * ($table['w'] - $tblbw ); } $wc['wpercent'] = $c['wpercent']; } } // mPDF 5.3.36 if (isset($table['overflow']) && $table['overflow']=='visible' && $table['level']==1) { if (($c['w'] + $tblbw) > $this->blk[$this->blklvl]['inner_width']) { $c['w'] = $this->blk[$this->blklvl]['inner_width'] - $tblbw; } } if (isset($c['w'])) { // If cell width is specified if ($miw<$c['w']) { $c['miw'] = $c['w']; } // Cell min width = that specified if ($miw>$c['w']) { $c['miw'] = $c['w'] = $miw; } // If width specified is less than minimum allowed (W) increase it if (!isset($wc['w'])) { $wc['w'] = 1; } // If the Col width is not specified = set it to 1 } else { $c['miw'] = $miw; } // If cell width not specified -> set Cell min width it to minimum allowed (W) if ($c['maw'] < $c['miw']) { $c['maw'] = $c['miw']; } // If Cell max width < Minwidth - increase it to = if (!isset($c['colspan'])) { if ($wc['miw'] < $c['miw']) { $wc['miw'] = $c['miw']; } // Update Col Minimum and maximum widths if ($wc['maw'] < $c['maw']) { $wc['maw'] = $c['maw']; } if ((isset($wc['absmiw']) && $wc['absmiw'] < $c['absmiw']) || !isset($wc['absmiw'])) { $wc['absmiw'] = $c['absmiw']; } // Update Col Minimum and maximum widths if (isset($table['l'][$j]) ) { $table['l'][$j] += $c['s']; } else { $table['l'][$j] = $c['s']; } } else { $listspan[] = array($i,$j); } //Check if minimum width of the whole column is big enough for largest word to fit if (isset($c['textbuffer']) && !$this->tableCJK && (!isset($table['overflow']) || $table['overflow']!='wrap')) { // mPDF 5.3.50 $minwidth = $this->TableCheckMinWidth($wc['miw']- $extrcw ,0,$c['textbuffer']); // mPDF 5.3.78 } else { $minwidth = 0; } if ($minwidth < 0) { //increase minimum width if (!isset($c['colspan'])) { $wc['miw'] = max($wc['miw'],((-$minwidth) + $extrcw) ); } else { $c['miw'] = max($c['miw'],((-$minwidth) + $extrcw) ); } } if (!isset($c['colspan'])) { if ($wc['miw'] > $wc['maw']) { $wc['maw'] = $wc['miw']; } //update maximum width, if needed } // mPDF 5.3.79 if ($this->cacheTables) { $this->_cacheCell($c, '', "W", $fh, $table['cells'][$i][$j]); } } unset($c); }//rows }//columns // COLUMN SPANS $wc = &$table['wc']; foreach ($listspan as $span) { list($i,$j) = $span; // mPDF 5.3.79 if ($this->cacheTables) { $c = $this->_uncacheCell($cs[$i][$j], '', $fh); } else $c = &$cs[$i][$j]; $lc = $j + $c['colspan']; if ($lc > $nc) { $lc = $nc; } $wis = $wisa = 0; $was = $wasa = 0; $list = array(); for($k=$j;$k<$lc;$k++) { if (isset($table['l'][$k]) ) { if ($c['R']) { $table['l'][$k] += $c['miw']/$c['colspan'] ; } else { $table['l'][$k] += $c['s']/$c['colspan']; } } else { if ($c['R']) { $table['l'][$k] = $c['miw']/$c['colspan'] ; } else { $table['l'][$k] = $c['s']/$c['colspan']; } } $wis += $wc[$k]['miw']; $was += $wc[$k]['maw']; if (!isset($c['w'])) { $list[] = $k; $wisa += $wc[$k]['miw']; $wasa += $wc[$k]['maw']; } } if ($c['miw'] > $wis) { if (!$wis) { for($k=$j;$k<$lc;$k++) { $wc[$k]['miw'] = $c['miw']/$c['colspan']; } } else if (!count($list)) { $wi = $c['miw'] - $wis; for($k=$j;$k<$lc;$k++) { $wc[$k]['miw'] += ($wc[$k]['miw']/$wis)*$wi; } } else { $wi = $c['miw'] - $wis; foreach ($list as $k) { $wc[$k]['miw'] += ($wc[$k]['miw']/$wisa)*$wi; } } } if ($c['maw'] > $was) { if (!$wis) { for($k=$j;$k<$lc;$k++) { $wc[$k]['maw'] = $c['maw']/$c['colspan']; } } else if (!count($list)) { $wi = $c['maw'] - $was; for($k=$j;$k<$lc;$k++) { $wc[$k]['maw'] += ($wc[$k]['maw']/$was)*$wi; } } else { $wi = $c['maw'] - $was; foreach ($list as $k) { $wc[$k]['maw'] += ($wc[$k]['maw']/$wasa)*$wi; } } } unset($c); } // mPDF 5.3.79 if ($this->cacheTables) { fclose($fh); } $checkminwidth = 0; $checkmaxwidth = 0; $totallength = 0; for( $i = 0 ; $i < $nc ; $i++ ) { $checkminwidth += $table['wc'][$i]['miw']; $checkmaxwidth += $table['wc'][$i]['maw']; $totallength += $table['l'][$i]; } if (!isset($table['w']) && $firstpass) { $sumpc = 0; $notset = 0; for( $i = 0 ; $i < $nc ; $i++ ) { if (isset($table['wc'][$i]['wpercent']) && $table['wc'][$i]['wpercent']) { $sumpc += $table['wc'][$i]['wpercent']; } else { $notset++; } } // If sum of widths as % >= 100% and not all columns are set // Set a nominal width of 1% for unset columns if ($sumpc >= 100 && $notset) { for( $i = 0 ; $i < $nc ; $i++ ) { if ((!isset($table['wc'][$i]['wpercent']) || !$table['wc'][$i]['wpercent']) && (!isset($table['wc'][$i]['w']) || !$table['wc'][$i]['w'])) { $table['wc'][$i]['wpercent'] = 1; } } } if ($sumpc) { // if any percents are set $sumnonpc = (100 - $sumpc); $sumpc = max($sumpc,100); $miwleft = 0; $miwleftcount = 0; $miwsurplusnonpc = 0; $maxcalcmiw = 0; $mawleft = 0; $mawleftcount = 0; $mawsurplusnonpc = 0; $maxcalcmaw = 0; for( $i = 0 ; $i < $nc ; $i++ ) { if (isset($table['wc'][$i]['wpercent'])) { $maxcalcmiw = max($maxcalcmiw, ($table['wc'][$i]['miw'] * $sumpc /$table['wc'][$i]['wpercent']) ); $maxcalcmaw = max($maxcalcmaw, ($table['wc'][$i]['maw'] * $sumpc /$table['wc'][$i]['wpercent']) ); } else { $miwleft += $table['wc'][$i]['miw']; $mawleft += $table['wc'][$i]['maw']; if (!isset($table['wc'][$i]['w'])) { $miwleftcount++; $mawleftcount++; } } } if ($miwleft && $sumnonpc > 0) { $miwnon = $miwleft * 100 / $sumnonpc; } if ($mawleft && $sumnonpc > 0) { $mawnon = $mawleft * 100 / $sumnonpc; } if (($miwnon > $checkminwidth || $maxcalcmiw > $checkminwidth) && $this->keep_table_proportions) { if ($miwnon > $maxcalcmiw) { $miwsurplusnonpc = round((($miwnon * $sumnonpc / 100) - $miwleft),3); $checkminwidth = $miwnon; } else { $checkminwidth = $maxcalcmiw; } for( $i = 0 ; $i < $nc ; $i++ ) { if (isset($table['wc'][$i]['wpercent'])) { $newmiw = $checkminwidth * $table['wc'][$i]['wpercent']/100; if ($table['wc'][$i]['miw'] < $newmiw) { $table['wc'][$i]['miw'] = $newmiw; } $table['wc'][$i]['w'] = 1; } else if ($miwsurplusnonpc && !$table['wc'][$i]['w']) { $table['wc'][$i]['miw'] += $miwsurplusnonpc / $miwleftcount; } } } if (($mawnon > $checkmaxwidth || $maxcalcmaw > $checkmaxwidth )) { if ($mawnon > $maxcalcmaw) { $mawsurplusnonpc = round((($mawnon * $sumnonpc / 100) - $mawleft),3); $checkmaxwidth = $mawnon; } else { $checkmaxwidth = $maxcalcmaw; } for( $i = 0 ; $i < $nc ; $i++ ) { if (isset($table['wc'][$i]['wpercent'])) { $newmaw = $checkmaxwidth * $table['wc'][$i]['wpercent']/100; if ($table['wc'][$i]['maw'] < $newmaw) { $table['wc'][$i]['maw'] = $newmaw; } $table['wc'][$i]['w'] = 1; } else if ($mawsurplusnonpc && !$table['wc'][$i]['w']) { $table['wc'][$i]['maw'] += $mawsurplusnonpc / $mawleftcount; } if ($table['wc'][$i]['maw'] < $table['wc'][$i]['miw']) { $table['wc'][$i]['maw'] = $table['wc'][$i]['miw']; } } } if ($checkminwidth > $checkmaxwidth) { $checkmaxwidth = $checkminwidth; } } } if (isset($table['wpercent']) && $table['wpercent']) { $checkminwidth *= (100 / $table['wpercent']); $checkmaxwidth *= (100 / $table['wpercent']); } $checkminwidth += $tblbw ; $checkmaxwidth += $tblbw ; // Table['miw'] set by percent in first pass may be larger than sum of column miw if ((isset($table['miw']) && $checkminwidth > $table['miw']) || !isset($table['miw'])) { $table['miw'] = $checkminwidth; } if ((isset($table['maw']) && $checkmaxwidth > $table['maw']) || !isset($table['maw'])) { $table['maw'] = $checkmaxwidth; } $table['tl'] = $totallength ; if (!$this->tableCJK) { if ($this->table_rotate) { $mxw = $this->tbrot_maxw; } else { $mxw = $this->blk[$this->blklvl]['inner_width']; } if(!isset($table['overflow'])) { $table['overflow'] = null; } // mPDF 5.3.36 if ($table['overflow']=='visible') { return array(0,0); } else if ($table['overflow']=='hidden' && !$this->table_rotate && !$this->ColActive && $checkminwidth > $mxw) { // mPDF 5.3.36 $table['w'] = $table['miw']; return array(0,0); } else if ($table['overflow']=='wrap') { return array(0,0); } if (isset($table['w']) && $table['w'] ) { if ($table['w'] >= $checkminwidth && $table['w'] <= $mxw) { $table['maw'] = $mxw = $table['w']; } else if ($table['w'] >= $checkminwidth && $table['w'] > $mxw && $this->keep_table_proportions) { $checkminwidth = $table['w']; } else { unset($table['w']); } } $ratio = $checkminwidth/$mxw; if ($checkminwidth > $mxw) { return array(($ratio +0.001),$checkminwidth); } // 0.001 to allow for rounded numbers when resizing } unset($cs); return array(0,0); } function _tableWidth(&$table){ $widthcols = &$table['wc']; $numcols = $table['nc']; $tablewidth = 0; if ($table['borders_separate']) { $tblbw = $table['border_details']['L']['w'] + $table['border_details']['R']['w'] + $table['margin']['L'] + $table['margin']['R'] + $table['padding']['L'] + $table['padding']['R'] + $table['border_spacing_H']; } else { $tblbw = $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2 + $table['margin']['L'] + $table['margin']['R']; } if ($table['level']>1 && isset($table['w'])) { if (isset($table['wpercent']) && $table['wpercent']) { $table['w'] = $temppgwidth = (($table['w']-$tblbw) * $table['wpercent'] / 100) + $tblbw ; } else { $temppgwidth = $table['w'] ; } } else if ($this->table_rotate) { $temppgwidth = $this->tbrot_maxw; // If it is less than 1/20th of the remaining page height to finish the DIV (i.e. DIV padding + table bottom margin) // then allow for this $enddiv = $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w']; if ($enddiv/$temppgwidth <0.05) { $temppgwidth -= $enddiv; } } else { if (isset($table['w']) && $table['w']< $this->blk[$this->blklvl]['inner_width']) { $notfullwidth = 1; $temppgwidth = $table['w'] ; } else if ($table['overflow']=='visible' && $table['level'] ==1) { // mPDF 5.3.36 $temppgwidth = null; } else if ($table['overflow']=='hidden' && !$this->ColActive && isset($table['w']) && $table['w'] > $this->blk[$this->blklvl]['inner_width'] && $table['w']==$table['miw']) { // mPDF 5.3.36 //$temppgwidth = $this->blk[$this->blklvl]['inner_width']; $temppgwidth = $table['w'] ; // mPDF 5.3.50 } else { $temppgwidth = $this->blk[$this->blklvl]['inner_width']; } } $totaltextlength = 0; // Added - to sum $table['l'][colno] $totalatextlength = 0; // Added - to sum $table['l'][colno] for those columns where width not set $percentages_set = 0; for ( $i = 0 ; $i < $numcols ; $i++ ) { if (isset($widthcols[$i]['wpercent'])) { $tablewidth += $widthcols[$i]['maw']; $percentages_set = 1; } else if (isset($widthcols[$i]['w'])) { $tablewidth += $widthcols[$i]['miw']; } else { $tablewidth += $widthcols[$i]['maw']; } $totaltextlength += $table['l'][$i]; } if (!$totaltextlength) { $totaltextlength =1; } $tablewidth += $tblbw; // Outer half of table borders if ($tablewidth > $temppgwidth) { $table['w'] = $temppgwidth; } // if any widths set as percentages and max width fits < page width else if ($tablewidth < $temppgwidth && !isset($table['w']) && $percentages_set) { $table['w'] = $table['maw']; } // if table width is set and is > allowed width if (isset($table['w']) && $table['w'] > $temppgwidth) { $table['w'] = $temppgwidth; } // IF the table width is now set - Need to distribute columns widths if (isset($table['w'])) { $wis = $wisa = 0; $list = array(); $notsetlist = array(); for( $i = 0 ; $i < $numcols ; $i++ ) { $wis += $widthcols[$i]['miw']; if (!isset($widthcols[$i]['w']) || ($widthcols[$i]['w'] && $table['w'] > $temppgwidth && !$this->keep_table_proportions && !$notfullwidth )){ $list[] = $i; $wisa += $widthcols[$i]['miw']; $totalatextlength += $table['l'][$i]; } } if (!$totalatextlength) { $totalatextlength =1; } // Allocate spare (more than col's minimum width) across the cols according to their approx total text length // Do it by setting minimum width here if ($table['w'] > $wis + $tblbw) { // First set any cell widths set as percentages if ($table['w'] < $temppgwidth || $this->keep_table_proportions) { for($k=0;$k<$numcols;$k++) { if (isset($widthcols[$k]['wpercent'])) { $curr = $widthcols[$k]['miw']; $widthcols[$k]['miw'] = ($table['w']-$tblbw) * $widthcols[$k]['wpercent']/100; $wis += $widthcols[$k]['miw'] - $curr; $wisa += $widthcols[$k]['miw'] - $curr; } } } // Now allocate surplus up to maximum width of each column $surplus = 0; $ttl = 0; // number of surplus columns if (!count($list)) { $wi = ($table['w']-($wis + $tblbw)); // i.e. extra space to distribute for($k=0;$k<$numcols;$k++) { $spareratio = ($table['l'][$k] / $totaltextlength); // gives ratio to divide up free space // Don't allocate more than Maximum required width - save rest in surplus if ($widthcols[$k]['miw'] + ($wi * $spareratio) > $widthcols[$k]['maw']) { $surplus += ($wi * $spareratio) - ($widthcols[$k]['maw']-$widthcols[$k]['miw']); $widthcols[$k]['miw'] = $widthcols[$k]['maw']; } else { $notsetlist[] = $k; $ttl += $table['l'][$k]; $widthcols[$k]['miw'] += ($wi * $spareratio); } } } else { $wi = ($table['w'] - ($wis + $tblbw)); // i.e. extra space to distribute foreach ($list as $k) { $spareratio = ($table['l'][$k] / $totalatextlength); // gives ratio to divide up free space // Don't allocate more than Maximum required width - save rest in surplus if ($widthcols[$k]['miw'] + ($wi * $spareratio) > $widthcols[$k]['maw']) { $surplus += ($wi * $spareratio) - ($widthcols[$k]['maw']-$widthcols[$k]['miw']); $widthcols[$k]['miw'] = $widthcols[$k]['maw']; } else { $notsetlist[] = $k; $ttl += $table['l'][$k]; $widthcols[$k]['miw'] += ($wi * $spareratio); } } } // If surplus still left over apportion it across columns if ($surplus) { // if some are set only add to remaining - otherwise add to all of them if (count($notsetlist) && count($notsetlist) < $numcols) { foreach ($notsetlist AS $i) { if ($ttl) $widthcols[$i]['miw'] += $surplus * $table['l'][$i] / $ttl ; } } // If some widths are defined, and others have been added up to their maxmum else if (count($list) && count($list) < $numcols) { foreach ($list AS $i) { $widthcols[$i]['miw'] += $surplus / count($list) ; } } else if ($numcols) { // If all columns $ttl = array_sum($table['l']); for ($i=0;$i<$numcols;$i++) { $widthcols[$i]['miw'] += $surplus * $table['l'][$i] / $ttl; } } } } // This sets the columns all to minimum width (which has been increased above if appropriate) for ($i=0;$i<$numcols;$i++) { $widthcols[$i] = $widthcols[$i]['miw']; } // TABLE NOT WIDE ENOUGH EVEN FOR MINIMUM CONTENT WIDTH // If sum of column widths set are too wide for table $checktablewidth = 0; for ( $i = 0 ; $i < $numcols ; $i++ ) { $checktablewidth += $widthcols[$i]; } if ($checktablewidth > ($temppgwidth + 0.001 - $tblbw)) { $usedup = 0; $numleft = 0; for ($i=0;$i<$numcols;$i++) { if ((isset($widthcols[$i]) && $widthcols[$i] > (($temppgwidth - $tblbw) / $numcols)) && (!isset($widthcols[$i]['w']))) { $numleft++; unset($widthcols[$i]); } else { $usedup += $widthcols[$i]; } } for ($i=0;$i<$numcols;$i++) { if (!isset($widthcols[$i]) || !$widthcols[$i]) { $widthcols[$i] = ((($temppgwidth - $tblbw) - $usedup)/ ($numleft)); } } } } else { //table has no width defined $table['w'] = $tablewidth; for ( $i = 0 ; $i < $numcols ; $i++) { if (isset($widthcols[$i]['wpercent']) && $this->keep_table_proportions) { $colwidth = $widthcols[$i]['maw']; } else if (isset($widthcols[$i]['w'])) { $colwidth = $widthcols[$i]['miw']; } else { $colwidth = $widthcols[$i]['maw']; } unset($widthcols[$i]); $widthcols[$i] = $colwidth; } } // mPDF 5.3.36 if ($table['overflow']=='visible' && $table['level'] ==1) { // mPDF 5.3.36 if ($tablewidth > $this->blk[$this->blklvl]['inner_width']) { // mPDF 5.3.79 if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); } else { $fh = null; } for ($j = 0 ; $j < $numcols; $j++) { //columns for ($i = 0 ; $i < $table['nr']; $i++) { //rows if (isset($table['cells'][$i][$j]) && $table['cells'][$i][$j]) { // mPDF 5.3.79 if ($this->cacheTables) { $cc = $this->_uncacheCell($table['cells'][$i][$j], '', $fh); $colspan = $cc['colspan']; } else $colspan = $table['cells'][$i][$j]['colspan']; if ($colspan > 1) { $w = 0; for ($c = $j; $c < ($j + $colspan); $c++) { $w += $widthcols[$c]; } if ($w > $this->blk[$this->blklvl]['inner_width']) { $diff = $w - ($this->blk[$this->blklvl]['inner_width'] - $tblbw); for ($c = $j; $c < ($j + $colspan); $c++) { $widthcols[$c] -= $diff * ($widthcols[$c]/$w); } $table['w'] -= $diff; $table['csp'][$j] = $w - $diff; // mPDF 5.3.44 } } } } } // mPDF 5.3.79 if ($this->cacheTables) { fclose($fh); } } $pgNo = 0; $currWc = 0; for ($i = 0 ; $i < $numcols; $i++) { //columns if (isset($table['csp'][$i])) { $w = $table['csp'][$i]; unset($table['csp'][$i]); } else { $w = $widthcols[$i]; } if (($currWc + $w + $tblbw) > $this->blk[$this->blklvl]['inner_width']) { $pgNo++; $currWc = $widthcols[$i] ; } else { $currWc += $widthcols[$i] ; } $table['colPg'][$i] = $pgNo; } } } function _tableHeight(&$table){ $level = $table['level']; $levelid = $table['levelid']; $cells = &$table['cells']; $numcols = $table['nc']; $numrows = $table['nr']; $listspan = array(); $checkmaxheight = 0; $headerrowheight = 0; $checkmaxheightplus = 0; $headerrowheightplus = 0; $firstrowheight = 0; $footerrowheight = 0; $footerrowheightplus = 0; if ($this->table_rotate) { $temppgheight = $this->tbrot_maxh; $remainingpage = $this->tbrot_maxh; } else { $temppgheight = ($this->h - $this->bMargin - $this->tMargin) - $this->kwt_height; $remainingpage = ($this->h - $this->bMargin - $this->y) - $this->kwt_height; // If it is less than 1/20th of the remaining page height to finish the DIV (i.e. DIV padding + table bottom margin) // then allow for this $enddiv = $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $table['margin']['B']; if ($remainingpage > $enddiv && $enddiv/$remainingpage <0.05) { $remainingpage -= $enddiv; } else if ($remainingpage == 0) { $remainingpage = 0.001; } if ($temppgheight > $enddiv && $enddiv/$temppgheight <0.05) { $temppgheight -= $enddiv; } else if ($temppgheight == 0) { $temppgheight = 0.001; } } // mPDF 5.3.79 if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); } else { $fh = null; } for( $i = 0 ; $i < $numrows ; $i++ ) { //rows $heightrow = &$table['hr'][$i]; for( $j = 0 ; $j < $numcols ; $j++ ) { //columns if (isset($cells[$i][$j]) && $cells[$i][$j]) { // mPDF 5.3.79 if ($this->cacheTables) { $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh); } else $c = &$cells[$i][$j]; if ($this->simpleTables){ if ($table['borders_separate']) { // NB twice border width $extraWLR = ($table['simple']['border_details']['L']['w']+$table['simple']['border_details']['R']['w']) + ($c['padding']['L']+$c['padding']['R'])+$table['border_spacing_H']; $extrh = ($table['simple']['border_details']['T']['w']+$table['simple']['border_details']['B']['w']) + ($c['padding']['T']+$c['padding']['B'])+$table['border_spacing_V']; } else { $extraWLR = ($table['simple']['border_details']['L']['w']+$table['simple']['border_details']['R']['w'])/2 + ($c['padding']['L']+$c['padding']['R']); $extrh = ($table['simple']['border_details']['T']['w']+$table['simple']['border_details']['B']['w'])/2 + ($c['padding']['T']+$c['padding']['B']); } } else { if ($this->packTableData) { list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']); } else { $bt = $c['border_details']['T']['w']; $bb = $c['border_details']['B']['w']; $br = $c['border_details']['R']['w']; $bl = $c['border_details']['L']['w']; } if ($table['borders_separate']) { // NB twice border width $extraWLR = $bl + $br + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H']; $extrh = $bt + $bb + $c['padding']['T'] + $c['padding']['B'] + $table['border_spacing_V']; } else { $extraWLR = $bl/2 + $br/2 + $c['padding']['L'] + $c['padding']['R']; $extrh = $bt/2 + $bb/2 + $c['padding']['T']+$c['padding']['B']; } } // mPDF 5.3.36 if ($table['overflow']=='visible' && $level==1) list($x,$cw) = $this->_splitTableGetWidth($table, $i,$j, $fh); else list($x,$cw) = $this->_tableGetWidth($table, $i,$j, $fh); // Get CELL HEIGHT // ++ extra parameter forces wrap to break word if ($c['R']) { // mPDF 5.3.78 $str = ''; foreach($c['textbuffer'] AS $t) { $str .= $t[0].' '; } $str = trim($str); $s_fs = $this->FontSizePt; $s_f = $this->FontFamily; $s_st = $this->FontStyle; $this->SetFont($c['textbuffer'][0][4],$c['textbuffer'][0][2],$c['textbuffer'][0][11] / $this->shrin_k,true,true); $tempch = $this->GetStringWidth($str); // mPDF 5.3.78 if ($c['R'] >= 45 && $c['R'] < 90) { $tempch = ((sin(deg2rad($c['R']))) * $tempch ) + ((sin(deg2rad($c['R']))) * (($c['textbuffer'][0][11]/_MPDFK) / $this->shrin_k)); } $this->SetFont($s_f,$s_st,$s_fs,true,true); $ch = ($tempch ) + $extrh ; } else { if (isset($c['textbuffer'])) { $tempch = $this->TableWordWrap(($cw-$extraWLR),1,$c['textbuffer'], $c['dfs']); } else { $tempch = 0; } // Added cellpadding top and bottom. (Lineheight already adjusted to table_lineheight) $ch = $tempch + $extrh ; } //If height is defined and it is bigger than calculated $ch then update values if (isset($c['h']) && $c['h'] > $ch) { $c['mih'] = $ch; //in order to keep valign working $ch = $c['h']; } else $c['mih'] = $ch; // mPDF 5.3.79 if ($this->cacheTables) { $this->_cacheUpdateMtx($c, $fh, $table['cells'][$i][$j], 'mih'); } if (isset($c['rowspan'])) $listspan[] = array($i,$j); elseif ($heightrow < $ch) $heightrow = $ch; // this is the extra used in _tableWrite to determine whether to trigger a page change if ($table['borders_separate']) { if ($i == ($numrows-1) || (isset($c['rowspan']) && ($i+$c['rowspan']) == ($numrows)) ) { $extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2; } else { $extra = $table['border_spacing_V']/2; } } else { if (!$this->simpleTables){ $extra = $bb/2; } else if ($this->simpleTables){ $extra = $table['simple']['border_details']['B']['w'] /2; } } if (isset($table['is_thead'][$i]) && $table['is_thead'][$i]) { // mPDF 5.3.62 if ($j==0) { $headerrowheight += $ch; $headerrowheightplus += $ch+$extra; } } else if (isset($table['is_tfoot'][$i]) && $table['is_tfoot'][$i]) { if ($j==0) { $footerrowheight += $ch; $footerrowheightplus += $ch+$extra; } } else { $checkmaxheight = max($checkmaxheight,$ch); $checkmaxheightplus = max($checkmaxheightplus,$ch+$extra); } if ($this->tableLevel==1 && $i == $table['headernrows']) { $firstrowheight = max($ch,$firstrowheight); } // mPDF 5.3.62 // mPDF 5.3.76 unset($c); } }//end of columns }//end of rows $heightrow = &$table['hr']; foreach ($listspan as $span) { list($i,$j) = $span; // mPDF 5.3.79 if ($this->cacheTables) { $c = $this->_uncacheCell($table['cells'][$i][$j], '', $fh); } else $c = &$cells[$i][$j]; $lr = $i + $c['rowspan']; if ($lr > $numrows) $lr = $numrows; $hs = $hsa = 0; $list = array(); for($k=$i;$k<$lr;$k++) { $hs += $heightrow[$k]; if (!isset($c['h'])) { $list[] = $k; $hsa += $heightrow[$k]; } } if ($table['borders_separate']) { if ($i == ($numrows-1) || ($i+$c['rowspan']) == ($numrows) ) { $extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2; } else { $extra = $table['border_spacing_V']/2; } } else { if (!$this->simpleTables){ if ($this->packTableData) { list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']); } else { $bb = $c['border_details']['B']['w']; } $extra = $bb/2; } else if ($this->simpleTables){ $extra = $table['simple']['border_details']['B']['w'] /2; } } if (!empty($table['is_thead'][$i])) { // mPDF 5.3.62 $headerrowheight = max($headerrowheight,$hs); $headerrowheightplus = max($headerrowheightplus,$hs+$extra); } else if (!empty($table['is_tfoot'][$i])) { $footerrowheight = max($footerrowheight,$hs); $footerrowheightplus = max($footerrowheightplus,$hs+$extra); } else { $checkmaxheight = max($checkmaxheight,$hs); $checkmaxheightplus = max($checkmaxheightplus,$hs+$extra); } if ($this->tableLevel==1 && $i == $table['headernrows']) { $firstrowheight = max($hs,$firstrowheight); } // mPDF 5.3.62 // mPDF 5.3.76 if ($c['mih'] > $hs) { if (!$hs) { for($k=$i;$k<$lr;$k++) $heightrow[$k] = $c['mih']/$c['rowspan']; } elseif (!count($list)) { $hi = $c['mih'] - $hs; for($k=$i;$k<$lr;$k++) $heightrow[$k] += ($heightrow[$k]/$hs)*$hi; } else { $hi = $c['mih'] - $hsa; foreach ($list as $k) $heightrow[$k] += ($heightrow[$k]/$hsa)*$hi; } } unset($c); // If rowspans overlap so that one or more rows do not have a height set... // i.e. for one or more rows, the only cells (explicit) in that row have rowspan>1 // so heightrow is still == 0 if ($heightrow[$i]==0) { // Get row extent to analyse above and below $top = $i; foreach ($listspan as $checkspan) { list($cki,$ckj) = $checkspan; if ($this->cacheTables) { $c = $this->_uncacheCell($table['cells'][$cki][$ckj], '', $fh); } else $c = &$cells[$cki][$ckj]; if (isset($c['rowspan']) && $c['rowspan']>1) { if (($cki + $c['rowspan']-1) >= $i) { $top = min($top, $cki); } } } $bottom = $i + $c['rowspan']-1; // Check for overconstrained conditions for ($k=$top; $k<=$bottom; $k++) { // if ['hr'] for any of the others is also 0, then abort (too complicated) if ($k != $i && $heightrow[$k]==0) { break(1); } // check again that top and bottom are not crossed by rowspans - or abort (too complicated) if ($k==$top) { // ???? take account of colspan as well??? for( $m = 0 ; $m < $numcols ; $m++ ) { //columns if (!isset($cells[$k][$m]) || $cells[$k][$m]==0) { break(2); } } } else if ($k==$bottom) { // ???? take account of colspan as well??? for( $m = 0 ; $m < $numcols ; $m++ ) { //columns if ($this->cacheTables) { $c = $this->_uncacheCell($table['cells'][$k][$m], '', $fh); } else $c = &$cells[$k][$m]; if (isset($c['rowspan']) && $c['rowspan']>1) { break(2); } } } } // By columns add up col height using ['h'] if set or ['mih'] if not // Intentionally do not substract border-spacing $colH = array(); $extH = 0; $newhr = array(); for( $m = 0 ; $m < $numcols ; $m++ ) { //columns for ($k=$top; $k<=$bottom; $k++) { if (isset($cells[$k][$m]) && $cells[$k][$m]!=0) { if ($this->cacheTables) { $c = $this->_uncacheCell($table['cells'][$k][$m], '', $fh); } else $c = &$cells[$k][$m]; if (isset($c['h']) && $c['h']) { $useh = $c['h']; } // ???? take account of colspan as well??? else { $useh = $c['mih']; } $colH[$m] += $useh; if (!isset($c['rowspan']) || $c['rowspan']<2) { $newhr[$k] = max($newhr[$k], $useh); } } } $extH = max($tabH, $colH[$m]); } $newhr[$i] = $extH - array_sum($newhr); for ($k=$top; $k<=$bottom; $k++) { $heightrow[$k] = $newhr[$k]; } } unset($c); } $table['h'] = array_sum($heightrow); // mPDF 5.3.80 unset($heightrow); // mPDF 5.3.80 // mPDF 5.3.79 if ($this->cacheTables) { fclose($fh); } if ($table['borders_separate']) { $table['h'] += $table['margin']['T'] + $table['margin']['B'] + $table['border_details']['T']['w'] + $table['border_details']['B']['w'] + $table['border_spacing_V'] + $table['padding']['T'] + $table['padding']['B']; } else { $table['h'] += $table['margin']['T'] + $table['margin']['B'] + $table['max_cell_border_width']['T']/2 + $table['max_cell_border_width']['B']/2; } $maxrowheight = $checkmaxheightplus + $headerrowheightplus + $footerrowheightplus; $maxfirstrowheight = $firstrowheight + $headerrowheightplus + $footerrowheightplus; // includes thead, 1st row and tfoot return array($table['h'],$maxrowheight,$temppgheight,$remainingpage,$maxfirstrowheight); } function _tableGetWidth(&$table, $i,$j, $fh){ // mPDF 5.3.79 if ($this->cacheTables) { $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh); } else $cell = &$table['cells'][$i][$j]; if ($cell) { if (isset($cell['x0'])) { return array($cell['x0'], $cell['w0']); } $x = 0; $widthcols = &$table['wc']; for( $k = 0 ; $k < $j ; $k++ ) $x += $widthcols[$k]; $w = $widthcols[$j]; if (isset($cell['colspan'])) { for ( $k = $j+$cell['colspan']-1 ; $k > $j ; $k-- ) $w += $widthcols[$k]; } $cell['x0'] = $x; $cell['w0'] = $w; // mPDF 5.3.79 if ($this->cacheTables) { $this->_cacheUpdateMtx($cell, $fh, $table['cells'][$i][$j], 'x0'); } return array($x, $w); } return array(0,0); } // mPDF 5.3.36 function _splitTableGetWidth(&$table, $i,$j, $fh){ // mPDF 5.3.79 if ($this->cacheTables) { $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh); } else $cell = &$table['cells'][$i][$j]; if ($cell) { if (isset($cell['x0'])) return array($cell['x0'], $cell['w0']); $x = 0; $widthcols = &$table['wc']; $pg = $table['colPg'][$j]; for( $k = 0 ; $k < $j ; $k++ ) { if ($table['colPg'][$k]==$pg) $x += $widthcols[$k]; } $w = $widthcols[$j]; if (isset($cell['colspan'])) { for ( $k = $j+$cell['colspan']-1 ; $k > $j ; $k-- ) if ($table['colPg'][$k]==$pg) $w += $widthcols[$k]; } $cell['x0'] = $x; $cell['w0'] = $w; // mPDF 5.3.79 if ($this->cacheTables) { $this->_cacheUpdateMtx($cell, $fh, $table['cells'][$i][$j], 'x0'); } return array($x, $w); } return array(0,0); } function _tableGetHeight(&$table, $i,$j, $fh){ // mPDF 5.3.79 if ($this->cacheTables) { $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh); } else $cell = &$table['cells'][$i][$j]; if ($cell){ if (isset($cell['y0'])) return array($cell['y0'], $cell['h0']); $y = 0; $heightrow = &$table['hr']; for ($k=0;$k<$i;$k++) $y += $heightrow[$k]; $h = $heightrow[$i]; if (isset($cell['rowspan'])){ for ($k=$i+$cell['rowspan']-1;$k>$i;$k--) $h += $heightrow[$k]; } $cell['y0'] = $y; $cell['h0'] = $h; // mPDF 5.3.79 if ($this->cacheTables) { $this->_cacheUpdateMtx($cell, $fh, $table['cells'][$i][$j], 'y0'); } return array($y, $h); } return array(0,0); } // mPDF 5.3.A7 function _tableGetMaxRowHeight($table, $row, $fh) { if ($row==$table['nc']-1) { return $table['hr'][$row]; } $maxrowheight = $table['hr'][$row]; for ($i=$row+1;$i<$table['nr'];$i++) { $cellsset = 0; for ($j=0;$j<$table['nc'];$j++) { if ($this->cacheTables) { $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh); if ($cell) { if (isset($cell['colspan'])) { $cellsset += $cell['colspan']; } else $cellsset += 1; } } else { if ($table['cells'][$i][$j]) { if (isset($table['cells'][$i][$j]['colspan'])) { $cellsset += $table['cells'][$i][$j]['colspan']; } else $cellsset += 1; } } } if ($cellsset == $table['nc']) { return $maxrowheight; } else { $maxrowheight += $table['hr'][$i]; } } return $maxrowheight; } // CHANGED TO ALLOW TABLE BORDER TO BE SPECIFIED CORRECTLY - added border_details function _tableRect($x, $y, $w, $h, $bord=-1, $details=array(), $buffer=false, $bSeparate=false, $cort='cell', $tablecorner='', $bsv=0, $bsh=0) { $cellBorderOverlay = array(); if ($bord==-1) { $this->Rect($x, $y, $w, $h); } else if ($this->simpleTables && ($cort=='cell')) { $this->SetLineWidth($details['L']['w']); if ($details['L']['c']) { $this->SetDColor($details['L']['c']); } else { $this->SetDColor($this->ConvertColor(0)); } $this->SetLineJoin(0); $this->Rect($x, $y, $w, $h); } else if ($bord){ if (!$bSeparate && $buffer) { $priority = 'LRTB'; for($p=0;$p<strlen($priority);$p++) { $side = $priority[$p]; $details['p'] = $side ; $dom = 0; if (isset($details[$side]['w'])) { $dom += ($details[$side]['w'] * 100000); } if (isset($details[$side]['style'])) { $dom += (array_search($details[$side]['style'],$this->borderstyles)*100) ; } if (isset($details[$side]['dom'])) { $dom += ($details[$side]['dom']*10); } // Precedence to darker colours at joins $coldom = 0; if (isset($details[$side]['c']) && is_array($details[$side]['c'])) { // mPDF 5.3.74 if ($details[$side]['c']{0}==3) { // RGB $coldom = 10-(((ord($details[$side]['c']{1})*1.00)+(ord($details[$side]['c']{2})*1.00)+(ord($details[$side]['c']{3})*1.00))/76.5); } } // 10 black - 0 white if ($coldom) { $dom += $coldom; } // Lastly precedence to RIGHT and BOTTOM cells at joins if (isset($details['cellposdom'])) { $dom += $details['cellposdom']; } $save = false; if ($side == 'T' && $this->issetBorder($bord, _BORDER_TOP)) { $cbord = _BORDER_TOP; $save = true; } else if ($side == 'L' && $this->issetBorder($bord, _BORDER_LEFT)) { $cbord = _BORDER_LEFT; $save = true; } else if ($side == 'R' && $this->issetBorder($bord, _BORDER_RIGHT)) { $cbord = _BORDER_RIGHT; $save = true; } else if ($side == 'B' && $this->issetBorder($bord, _BORDER_BOTTOM)) { $cbord = _BORDER_BOTTOM; $save = true; } if ($save) { // mPDF 5.3.74 $this->cellBorderBuffer[] = pack("A16nCnda6A10d14", str_pad(sprintf("%08.7f", $dom),16,"0",STR_PAD_LEFT), $cbord, ord($side), $details[$side]['s'], $details[$side]['w'], $details[$side]['c'], $details[$side]['style'], $x, $y, $w, $h, $details['mbw']['BL'], $details['mbw']['BR'], $details['mbw']['RT'], $details['mbw']['RB'], $details['mbw']['TL'], $details['mbw']['TR'], $details['mbw']['LT'], $details['mbw']['LB'], $details['cellposdom'], 0 ); if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'groove' || $details[$side]['style'] == 'inset' || $details[$side]['style'] == 'outset' || $details[$side]['style'] == 'double' ) { $details[$side]['overlay'] = true; // mPDF 5.3.74 $this->cellBorderBuffer[] = pack("A16nCnda6A10d14", str_pad(sprintf("%08.7f", ($dom+4)),16,"0",STR_PAD_LEFT), $cbord, ord($side), $details[$side]['s'], $details[$side]['w'], $details[$side]['c'], $details[$side]['style'], $x, $y, $w, $h, $details['mbw']['BL'], $details['mbw']['BR'], $details['mbw']['RT'], $details['mbw']['RB'], $details['mbw']['TL'], $details['mbw']['TR'], $details['mbw']['LT'], $details['mbw']['LB'], $details['cellposdom'], 1 ); } } } return; } if (isset($details['p']) && strlen($details['p'])>1) { $priority = $details['p']; } else { $priority='LTRB'; } $Tw = 0; $Rw = 0; $Bw = 0; $Lw = 0; if (isset($details['T']['w'])) { $Tw = $details['T']['w']; } if (isset($details['R']['w'])) { $Rw = $details['R']['w']; } if (isset($details['B']['w'])) { $Bw = $details['B']['w']; } if (isset($details['L']['w'])) { $Lw = $details['L']['w']; } $x2 = $x + $w; $y2 = $y + $h; $oldlinewidth = $this->LineWidth; for($p=0;$p<strlen($priority);$p++) { $side = $priority[$p]; $xadj = 0; $xadj2 = 0; $yadj = 0; $yadj2 = 0; $print = false; if ($Tw && $side=='T' && $this->issetBorder($bord, _BORDER_TOP)) { // TOP $ly1 = $y; $ly2 = $y; $lx1 = $x; $lx2 = $x2; $this->SetLineWidth($Tw); if ($cort == 'cell' || strpos($tablecorner,'L')!==false) { if ($Tw > $Lw) $xadj = ($Tw - $Lw)/2; if ($Tw < $Lw) $xadj = ($Tw + $Lw)/2; } else { $xadj = $Tw/2 - $bsh/2; } if ($cort == 'cell' || strpos($tablecorner,'R')!==false) { if ($Tw > $Rw) $xadj2 = ($Tw - $Rw)/2; if ($Tw < $Rw) $xadj2 = ($Tw + $Rw)/2; } else { $xadj2 = $Tw/2 - $bsh/2; } if (!$bSeparate && $details['mbw']['TL']) { $xadj = ($Tw - $details['mbw']['TL'])/2 ; } if (!$bSeparate && $details['mbw']['TR']) { $xadj2 = ($Tw - $details['mbw']['TR'])/2; } $print = true; } if ($Lw && $side=='L' && $this->issetBorder($bord, _BORDER_LEFT)) { // LEFT $ly1 = $y; $ly2 = $y2; $lx1 = $x; $lx2 = $x; $this->SetLineWidth($Lw); if ($cort == 'cell' || strpos($tablecorner,'T')!==false) { if ($Lw > $Tw) $yadj = ($Lw - $Tw)/2; if ($Lw < $Tw) $yadj = ($Lw + $Tw)/2; } else { $yadj = $Lw/2 - $bsv/2; } if ($cort == 'cell' || strpos($tablecorner,'B')!==false) { if ($Lw > $Bw) $yadj2 = ($Lw - $Bw)/2; if ($Lw < $Bw) $yadj2 = ($Lw + $Bw)/2; } else { $yadj2 = $Lw/2 - $bsv/2; } if (!$bSeparate && $details['mbw']['LT']) { $yadj = ($Lw - $details['mbw']['LT'])/2; } if (!$bSeparate && $details['mbw']['LB']) { $yadj2 = ($Lw - $details['mbw']['LB'])/2; } $print = true; } if ($Rw && $side=='R' && $this->issetBorder($bord, _BORDER_RIGHT)) { // RIGHT $ly1 = $y; $ly2 = $y2; $lx1 = $x2; $lx2 = $x2; $this->SetLineWidth($Rw); if ($cort == 'cell' || strpos($tablecorner,'T')!==false) { if ($Rw < $Tw) $yadj = ($Rw + $Tw)/2; if ($Rw > $Tw) $yadj = ($Rw - $Tw)/2; } else { $yadj = $Rw/2 - $bsv/2; } if ($cort == 'cell' || strpos($tablecorner,'B')!==false) { if ($Rw > $Bw) $yadj2 = ($Rw - $Bw)/2; if ($Rw < $Bw) $yadj2 = ($Rw + $Bw)/2; } else { $yadj2 = $Rw/2 - $bsv/2; } if (!$bSeparate && $details['mbw']['RT']) { $yadj = ($Rw - $details['mbw']['RT'])/2; } if (!$bSeparate && $details['mbw']['RB']) { $yadj2 = ($Rw - $details['mbw']['RB'])/2; } $print = true; } if ($Bw && $side=='B' && $this->issetBorder($bord, _BORDER_BOTTOM)) { // BOTTOM $ly1 = $y2; $ly2 = $y2; $lx1 = $x; $lx2 = $x2; $this->SetLineWidth($Bw); if ($cort == 'cell' || strpos($tablecorner,'L')!==false) { if ($Bw > $Lw) $xadj = ($Bw - $Lw)/2; if ($Bw < $Lw) $xadj = ($Bw + $Lw)/2; } else { $xadj = $Bw/2 - $bsh/2; } if ($cort == 'cell' || strpos($tablecorner,'R')!==false) { if ($Bw > $Rw) $xadj2 = ($Bw - $Rw)/2; if ($Bw < $Rw) $xadj2 = ($Bw + $Rw)/2; } else { $xadj2 = $Bw/2 - $bsh/2; } if (!$bSeparate && $details['mbw']['BL']) { $xadj = ($Bw - $details['mbw']['BL'])/2; } if (!$bSeparate && $details['mbw']['BR']) { $xadj2 = ($Bw - $details['mbw']['BR'])/2; } $print = true; } // Now draw line if ($print) { /*-- TABLES-ADVANCED-BORDERS --*/ if ($details[$side]['style'] == 'double') { if (!isset($details[$side]['overlay']) || !$details[$side]['overlay'] || $bSeparate) { if ($details[$side]['c']) { $this->SetDColor($details[$side]['c']); } else { $this->SetDColor($this->ConvertColor(0)); } $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2); } if ((isset($details[$side]['overlay']) && $details[$side]['overlay']) || $bSeparate) { if ($bSeparate && $cort=='table') { if ($side=='T') { $xadj -= $this->LineWidth/2; $xadj2 -= $this->LineWidth; if ($this->issetBorder($bord, _BORDER_LEFT)) { $xadj += $this->LineWidth/2; } if ($this->issetBorder($bord, _BORDER_RIGHT)) { $xadj2 += $this->LineWidth; } } if ($side=='L') { $yadj -= $this->LineWidth/2; $yadj2 -= $this->LineWidth; if ($this->issetBorder($bord, _BORDER_TOP)) { $yadj += $this->LineWidth/2; } if ($this->issetBorder($bord, _BORDER_BOTTOM)) { $yadj2 += $this->LineWidth; } } if ($side=='B') { $xadj -= $this->LineWidth/2; $xadj2 -= $this->LineWidth; if ($this->issetBorder($bord, _BORDER_LEFT)) { $xadj += $this->LineWidth/2; } if ($this->issetBorder($bord, _BORDER_RIGHT)) { $xadj2 += $this->LineWidth; } } if ($side=='R') { $yadj -= $this->LineWidth/2; $yadj2 -= $this->LineWidth; if ($this->issetBorder($bord, _BORDER_TOP)) { $yadj += $this->LineWidth/2; } if ($this->issetBorder($bord, _BORDER_BOTTOM)) { $yadj2 += $this->LineWidth; } } } $this->SetLineWidth($this->LineWidth/3); $tbcol = $this->ConvertColor(255); for($l=0; $l <= $this->blklvl; $l++) { if ($this->blk[$l]['bgcolor']) { $tbcol = array($this->blk[$l]['bgcolorarray']); } } if ($bSeparate) { $cellBorderOverlay[] = array( 'x' => $lx1 + $xadj, 'y' => $ly1 + $yadj, 'x2' => $lx2 - $xadj2, 'y2' => $ly2 - $yadj2, 'col' => $tbcol, 'lw' => $this->LineWidth, ); } else { $this->SetDColor($tbcol); $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2); } } } else if (isset($details[$side]['style']) && ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'groove' || $details[$side]['style'] == 'inset' || $details[$side]['style'] == 'outset')) { if (!isset($details[$side]['overlay']) || !$details[$side]['overlay'] || $bSeparate) { if ($details[$side]['c']) { $this->SetDColor($details[$side]['c']); } else { $this->SetDColor($this->ConvertColor(0)); } if ($details[$side]['style'] == 'outset' || $details[$side]['style'] == 'groove') { $nc = $this->_darkenColor($details[$side]['c']); $this->SetDColor($nc); } else if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'inset') { $nc = $this->_lightenColor($details[$side]['c']); $this->SetDColor($nc); } $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2); } if ((isset($details[$side]['overlay']) && $details[$side]['overlay']) || $bSeparate) { if ($details[$side]['c']) { $this->SetDColor($details[$side]['c']); } else { $this->SetDColor($this->ConvertColor(0)); } $doubleadj = ($this->LineWidth)/3; $this->SetLineWidth($this->LineWidth/2); $xadj3 = $yadj3 = $wadj3 = $hadj3 = 0; if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'inset') { $nc = $this->_darkenColor($details[$side]['c']); if ($bSeparate && $cort=='table') { if ($side=='T') { $yadj3 = $this->LineWidth/2; $xadj3 = -$this->LineWidth/2; $wadj3 = $this->LineWidth; if ($this->issetBorder($bord, _BORDER_LEFT)) { $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth; } if ($this->issetBorder($bord, _BORDER_RIGHT)) { $wadj3 -= $this->LineWidth*2; } } if ($side=='L') { $xadj3 = $this->LineWidth/2; $yadj3 = -$this->LineWidth/2; $hadj3 = $this->LineWidth; if ($this->issetBorder($bord, _BORDER_TOP)) { $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth; } if ($this->issetBorder($bord, _BORDER_BOTTOM)) { $hadj3 -= $this->LineWidth*2; } } if ($side=='B') { $yadj3 = $this->LineWidth/2; $xadj3 = -$this->LineWidth/2; $wadj3 = $this->LineWidth; } if ($side=='R') { $xadj3 = $this->LineWidth/2; $yadj3 = -$this->LineWidth/2; $hadj3 = $this->LineWidth; } } else if ($side=='T') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; $wadj3 = -$this->LineWidth*2; } else if ($side=='L') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; $hadj3 = -$this->LineWidth*2; } else if ($side=='B' && $bSeparate) { $yadj3 = $this->LineWidth/2; $wadj3 = $this->LineWidth/2; } else if ($side=='R' && $bSeparate) { $xadj3 = $this->LineWidth/2; $hadj3 = $this->LineWidth/2; } else if ($side=='B') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; } else if ($side=='R') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; } } else { $nc = $this->_lightenColor($details[$side]['c']); if ($bSeparate && $cort=='table') { if ($side=='T') { $yadj3 = $this->LineWidth/2; $xadj3 = -$this->LineWidth/2; $wadj3 = $this->LineWidth; if ($this->issetBorder($bord, _BORDER_LEFT)) { $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth; } } if ($side=='L') { $xadj3 = $this->LineWidth/2; $yadj3 = -$this->LineWidth/2; $hadj3 = $this->LineWidth; if ($this->issetBorder($bord, _BORDER_TOP)) { $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth; } } if ($side=='B') { $yadj3 = $this->LineWidth/2; $xadj3 = -$this->LineWidth/2; $wadj3 = $this->LineWidth; if ($this->issetBorder($bord, _BORDER_LEFT)) { $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth; } } if ($side=='R') { $xadj3 = $this->LineWidth/2; $yadj3 = -$this->LineWidth/2; $hadj3 = $this->LineWidth; if ($this->issetBorder($bord, _BORDER_TOP)) { $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth; } } } else if ($side=='T') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; } else if ($side=='L') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; } else if ($side=='B' && $bSeparate) { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; } else if ($side=='R' && $bSeparate) { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; } else if ($side=='B') { $yadj3 = $this->LineWidth/2; $xadj3 = -$this->LineWidth/2; $wadj3 = $this->LineWidth; } else if ($side=='R') { $xadj3 = $this->LineWidth/2; $yadj3 = -$this->LineWidth/2; $hadj3 = $this->LineWidth; } } if ($bSeparate) { $cellBorderOverlay[] = array( 'x' => $lx1 + $xadj + $xadj3, 'y' => $ly1 + $yadj + $yadj3, 'x2' => $lx2 - $xadj2 + $xadj3 + $wadj3, 'y2' => $ly2 - $yadj2 + $yadj3 + $hadj3, 'col' => $nc, 'lw' => $this->LineWidth, ); } else { $this->SetDColor($nc); $this->Line($lx1 + $xadj + $xadj3, $ly1 + $yadj + $yadj3, $lx2 - $xadj2 + $xadj3 + $wadj3, $ly2 - $yadj2 + $yadj3 + $hadj3); } } } else { /*-- END TABLES-ADVANCED-BORDERS --*/ if ($details[$side]['style'] == 'dashed') { $dashsize = 2; // final dash will be this + 1*linewidth $dashsizek = 1.5; // ratio of Dash/Blank $this->SetDash($dashsize,($dashsize/$dashsizek)+($this->LineWidth*2)); } else if ($details[$side]['style'] == 'dotted') { $this->SetLineJoin(1); $this->SetLineCap(1); $this->SetDash(0.001,($this->LineWidth*2)); } if ($details[$side]['c']) { $this->SetDColor($details[$side]['c']); } else { $this->SetDColor($this->ConvertColor(0)); } $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2); /*-- TABLES-ADVANCED-BORDERS --*/ } /*-- END TABLES-ADVANCED-BORDERS --*/ // Reset Corners $this->SetDash(); //BUTT style line cap $this->SetLineCap(2); } } if ($bSeparate && count($cellBorderOverlay)) { foreach($cellBorderOverlay AS $cbo) { $this->SetLineWidth($cbo['lw']); $this->SetDColor($cbo['col']); $this->Line($cbo['x'], $cbo['y'], $cbo['x2'], $cbo['y2']); } } // $this->SetLineWidth($oldlinewidth); // $this->SetDColor($this->ConvertColor(0)); } } /*-- TABLES --*/ /*-- TABLES-ADVANCED-BORDERS --*/ function _lightenColor($c) { // mPDF 5.3.74 if (is_array($c)) { die('Color error in _lightencolor'); } if ($c{0}==3 || $c{0}==5) { // RGB list($h,$s,$l) = $this->rgb2hsl(ord($c{1})/255,ord($c{2})/255,ord($c{3})/255); $l += ((1 - $l)*0.8); list($r,$g,$b) = $this->hsl2rgb($h,$s,$l); $ret = array(3,$r,$g,$b); } else if ($c{0}==4 || $c{0}==6) { // CMYK $ret = array(4, max(0,(ord($c{1})-20)), max(0,(ord($c{2})-20)), max(0,(ord($c{3})-20)), max(0,(ord($c{4})-20)) ); } else if ($c{0}==1) { // Grayscale $ret = array(1,min(255,(ord($c{1})+32))); } $c = array_pad($ret, 6, 0); $cstr = pack("a1ccccc", $c[0], ($c[1] & 0xFF), ($c[2] & 0xFF), ($c[3] & 0xFF), ($c[4] & 0xFF), ($c[5] & 0xFF) ); return $cstr; } function _darkenColor($c) { if (is_array($c)) { die('Color error in _darkenColor'); } // mPDF 5.3.74 if ($c{0}==3 || $c{0}==5) { // RGB list($h,$s,$l) = $this->rgb2hsl(ord($c{1})/255,ord($c{2})/255,ord($c{3})/255); $s *= 0.25; $l *= 0.75; list($r,$g,$b) = $this->hsl2rgb($h,$s,$l); $ret = array(3,$r,$g,$b); } else if ($c{0}==4 || $c{0}==6) { // CMYK $ret = array(4, min(100,(ord($c{1})+20)), min(100,(ord($c{2})+20)), min(100,(ord($c{3})+20)), min(100,(ord($c{4})+20)) ); } else if ($c{0}==1) { // Grayscale $ret = array(1,max(0,(ord($c{1})-32))); } $c = array_pad($ret, 6, 0); $cstr = pack("a1ccccc", $c[0], ($c[1] & 0xFF), ($c[2] & 0xFF), ($c[3] & 0xFF), ($c[4] & 0xFF), ($c[5] & 0xFF) ); return $cstr; } /*-- END TABLES-ADVANCED-BORDERS --*/ function setBorder(&$var, $flag, $set = true) { $flag = intval($flag); if ($set) { $set = true; } $var = intval($var); $var = $set ? ($var | $flag) : ($var & ~$flag); } function issetBorder($var, $flag) { $flag = intval($flag); $var = intval($var); return (($var & $flag) == $flag); } function _table2cellBorder(&$tableb, &$cbdb, &$cellb, $bval) { if ($tableb && $tableb['w'] > $cbdb['w']) { $cbdb = $tableb; $this->setBorder($cellb, $bval); } else if ($tableb && $tableb['w'] == $cbdb['w'] && array_search($tableb['style'],$this->borderstyles) > array_search($cbdb['style'],$this->borderstyles)) { $cbdb = $tableb; $this->setBorder($cellb, $bval); } } // FIX BORDERS ******************************************** function _fixTableBorders(&$table){ // mPDF 5.3.79 if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); } else { $fh = null; } if (!$table['borders_separate'] && $table['border_details']['L']['w']) { $table['max_cell_border_width']['L'] = $table['border_details']['L']['w']; } if (!$table['borders_separate'] && $table['border_details']['R']['w']) { $table['max_cell_border_width']['R'] = $table['border_details']['R']['w']; } if (!$table['borders_separate'] && $table['border_details']['T']['w']) { $table['max_cell_border_width']['T'] = $table['border_details']['T']['w']; } if (!$table['borders_separate'] && $table['border_details']['B']['w']) { $table['max_cell_border_width']['B'] = $table['border_details']['B']['w']; } if ($this->simpleTables) { return; } $cells = &$table['cells']; $numcols = $table['nc']; $numrows = $table['nr']; /*-- TABLES-ADVANCED-BORDERS --*/ // mPDF 5.3.64 if (isset($table['topntail']) && $table['topntail']) { $tntborddet = $this->border_details($table['topntail']); } if (isset($table['thead-underline']) && $table['thead-underline']) { $thuborddet = $this->border_details($table['thead-underline']); } /*-- END TABLES-ADVANCED-BORDERS --*/ for( $i = 0 ; $i < $numrows ; $i++ ) { //Rows for( $j = 0 ; $j < $numcols ; $j++ ) { //Columns if (isset($cells[$i][$j]) && $cells[$i][$j]) { // mPDF 5.3.79 if ($this->cacheTables) { $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh); } else $cell = &$cells[$i][$j]; if ($this->packTableData) { // includes $this->cacheTables $cbord = $this->_unpackCellBorder($cell['borderbin']); } else { $cbord = &$cells[$i][$j]; } if (!$cbord['border'] && isset($table['border']) && $table['border'] && $this->table_border_attr_set) { $cbord['border'] = $table['border']; $cbord['border_details'] = $table['border_details']; } if (isset($cell['colspan']) && $cell['colspan']>1) { $ccolsp = $cell['colspan']; } else { $ccolsp = 1; } if (isset($cell['rowspan']) && $cell['rowspan']>1) { $crowsp = $cell['rowspan']; } else { $crowsp = 1; } $cbord['border_details']['cellposdom'] = ((($i+1)/$numrows) / 10000 ) + ((($j+1)/$numcols) / 10 ); // Inherit Cell border from Table border if ($this->table_border_css_set && !$table['borders_separate']) { if ($i == 0) { $this->_table2cellBorder($table['border_details']['T'], $cbord['border_details']['T'], $cbord['border'], _BORDER_TOP); } if ($i == ($numrows-1) || ($i+$crowsp) == ($numrows) ) { $this->_table2cellBorder($table['border_details']['B'], $cbord['border_details']['B'], $cbord['border'], _BORDER_BOTTOM); } if ($j == 0) { $this->_table2cellBorder($table['border_details']['L'], $cbord['border_details']['L'], $cbord['border'], _BORDER_LEFT); } if ($j == ($numcols-1) || ($j+$ccolsp) == ($numcols) ) { $this->_table2cellBorder($table['border_details']['R'], $cbord['border_details']['R'], $cbord['border'], _BORDER_RIGHT); } } /*-- TABLES-ADVANCED-BORDERS --*/ $fixbottom = true; // mPDF 5.3.64 if (isset($table['topntail']) && $table['topntail']) { if ($i == 0) { $cbord['border_details']['T'] = $tntborddet; $this->setBorder($cbord['border'], _BORDER_TOP); } if ($this->tableLevel==1 && $table['headernrows']>0 && $i == $table['headernrows']-1) { // mPDF 5.3.62 // mPDF 5.3.76 $cbord['border_details']['B'] = $tntborddet; $this->setBorder($cbord['border'], _BORDER_BOTTOM); $fixbottom = false; // mPDF 5.3.64 } else if ($this->tableLevel==1 && $table['headernrows']>0 && $i == $table['headernrows']) { // mPDF 5.3.62 if (!$table['borders_separate']) { $cbord['border_details']['T'] = $tntborddet; $this->setBorder($cbord['border'], _BORDER_TOP); } } if ($this->tableLevel==1 && $table['footernrows']>0 && $i == ($numrows-$table['footernrows']-1)) { // mPDF 5.3.62 if (!$table['borders_separate']) { $cbord['border_details']['B'] = $tntborddet; $this->setBorder($cbord['border'], _BORDER_BOTTOM); $fixbottom = false; // mPDF 5.3.64 } } else if ($this->tableLevel==1 && $table['footernrows']>0 && $i == ($numrows-$table['footernrows'])) { // mPDF 5.3.62 $cbord['border_details']['T'] = $tntborddet; $this->setBorder($cbord['border'], _BORDER_TOP); } if ($this->tabletheadjustfinished) { // $this->tabletheadjustfinished called from tableheader if (!$table['borders_separate']) { $cbord['border_details']['T'] = $tntborddet; $this->setBorder($cbord['border'], _BORDER_TOP); } } if ($i == ($numrows-1) || ($i+$crowsp) == ($numrows) ) { $cbord['border_details']['B'] = $tntborddet; $this->setBorder($cbord['border'], _BORDER_BOTTOM); } } if (isset($table['thead-underline']) && $table['thead-underline']) { if ($table['borders_separate']) { if ($i == 0) { $cbord['border_details']['B'] = $thuborddet; $this->setBorder($cbord['border'], _BORDER_BOTTOM); $fixbottom = false; // mPDF 5.3.64 } } else { if ($this->tableLevel==1 && $table['headernrows']>0 && $i == $table['headernrows']-1) { // mPDF 5.3.62 $cbord['border_details']['T'] = $thuborddet; $this->setBorder($cbord['border'], _BORDER_TOP); } else if ($this->tabletheadjustfinished) { // $this->tabletheadjustfinished called from tableheader $cbord['border_details']['T'] = $thuborddet; $this->setBorder($cbord['border'], _BORDER_TOP); } } } // Collapse Border - Algorithm for conflicting borders // Hidden >> Width >> double>solid>dashed>dotted... >> style set on cell>table >> top/left>bottom/right // Do not turn off border which is overridden // Needed for page break for TOP/BOTTOM both to be defined in Collapsed borders // Means it is painted twice. (Left/Right can still disable overridden border) if (!$table['borders_separate']) { // mPDF 5.3.64 if (($i < ($numrows-1) || ($i+$crowsp) < $numrows ) && $fixbottom ) { // Bottom // mPDF 5.3.64 for ($cspi = 0; $cspi<$ccolsp; $cspi++) { // already defined Top for adjacent cell below if (isset($cells[($i+$crowsp)][$j+$cspi])) { if ($this->packTableData) { // mPDF 5.3.79 if ($this->cacheTables) { $adjc = $this->_uncacheCell($table['cells'][$i+$crowsp][$j+$cspi], '', $fh); } else { $adjc = $cells[($i+$crowsp)][$j+$cspi]; } $celladj = $this->_unpackCellBorder($adjc['borderbin']); } else { $celladj =& $cells[($i+$crowsp)][$j+$cspi]; } } else { $celladj = false; } if ($celladj && $celladj['border_details']['T']['s'] == 1) { $csadj = $celladj['border_details']['T']['w']; $csthis = $cbord['border_details']['B']['w']; // Hidden if ($cbord['border_details']['B']['style']=='hidden') { $celladj['border_details']['T'] = $cbord['border_details']['B']; $this->setBorder($celladj['border'] , _BORDER_TOP, false); $this->setBorder($cbord['border'] , _BORDER_BOTTOM , false); } else if ($celladj['border_details']['T']['style']=='hidden') { $cbord['border_details']['B'] = $celladj['border_details']['T']; $this->setBorder($cbord['border'] , _BORDER_BOTTOM , false); $this->setBorder($celladj['border'] , _BORDER_TOP, false); } // Width else if ($csthis > $csadj) { if (!isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) || (isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) && $cells[($i+$crowsp)][$j+$cspi]['colspan']<2)) { // don't overwrite bordering cells that span $celladj['border_details']['T'] = $cbord['border_details']['B']; $this->setBorder($cbord['border'] , _BORDER_BOTTOM); } } else if ($csadj > $csthis) { if ($ccolsp < 2) { // don't overwrite this cell if it spans $cbord['border_details']['B'] = $celladj['border_details']['T']; $this->setBorder($celladj['border'] , _BORDER_TOP); } } // double>solid>dashed>dotted... else if (array_search($cbord['border_details']['B']['style'],$this->borderstyles) > array_search($celladj['border_details']['T']['style'],$this->borderstyles)) { if (!isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) || (isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) && $cells[($i+$crowsp)][$j+$cspi]['colspan']<2)) { // don't overwrite bordering cells that span $celladj['border_details']['T'] = $cbord['border_details']['B']; $this->setBorder($cbord['border'] , _BORDER_BOTTOM ); } } else if (array_search($celladj['border_details']['T']['style'],$this->borderstyles) > array_search($cbord['border_details']['B']['style'],$this->borderstyles)) { if ($ccolsp < 2) { // don't overwrite this cell if it spans $cbord['border_details']['B'] = $celladj['border_details']['T']; $this->setBorder($celladj['border'] , _BORDER_TOP); } } // Style set on cell vs. table else if ($celladj['border_details']['T']['dom'] > $cbord['border_details']['B']['dom']) { if ($ccolsp < 2) { // don't overwrite this cell if it spans $cbord['border_details']['B'] = $celladj['border_details']['T']; $this->setBorder($celladj['border'] , _BORDER_TOP); } } // Style set on cell vs. table - OR - LEFT/TOP (cell) in preference to BOTTOM/RIGHT else { if (!isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) || (isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) && $cells[($i+$crowsp)][$j+$cspi]['colspan']<2)) { // don't overwrite bordering cells that span $celladj['border_details']['T'] = $cbord['border_details']['B']; $this->setBorder($cbord['border'] , _BORDER_BOTTOM ); } } } else if ($celladj) { if (!isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) || (isset($cells[($i+$crowsp)][$j+$cspi]['colspan']) && $cells[($i+$crowsp)][$j+$cspi]['colspan']<2)) { // don't overwrite bordering cells that span $celladj['border_details']['T'] = $cbord['border_details']['B']; } } // mPDF 5.3.79 if ($celladj && $this->packTableData) { $celladj['borderbin'] = $this->_packCellBorder($celladj); unset($celladj['border']); unset($celladj['border_details']); } if ($this->cacheTables) { $this->_cacheUpdateBorder($celladj, $fh, $table['cells'][$i+$crowsp][$j+$cspi]); } unset($celladj); } } if ($j < ($numcols-1) || ($j+$ccolsp) < $numcols ) { // Right-Left for ($cspi = 0; $cspi<$crowsp; $cspi++) { // already defined Left for adjacent cell to R if (isset($cells[($i+$cspi)][$j+$ccolsp])) { if ($this->packTableData) { // mPDF 5.3.79 if ($this->cacheTables) { $adjc = $this->_uncacheCell($table['cells'][$i+$cspi][$j+$ccolsp], '', $fh); } else { $adjc = $cells[($i+$cspi)][$j+$ccolsp]; } $celladj = $this->_unpackCellBorder($adjc['borderbin']); } else { $celladj =& $cells[$i+$cspi][$j+$ccolsp]; } } else { $celladj = false; } if ($celladj && $celladj['border_details']['L']['s'] == 1) { $csadj = $celladj['border_details']['L']['w']; $csthis = $cbord['border_details']['R']['w']; // Hidden if ($cbord['border_details']['R']['style']=='hidden') { $celladj['border_details']['L'] = $cbord['border_details']['R']; $this->setBorder($celladj['border'] , _BORDER_LEFT, false); $this->setBorder($cbord['border'] , _BORDER_RIGHT , false); } else if ($celladj['border_details']['L']['style']=='hidden') { $cbord['border_details']['R'] = $celladj['border_details']['L']; $this->setBorder($cbord['border'] , _BORDER_RIGHT , false); $this->setBorder($celladj['border'] , _BORDER_LEFT, false); } // Width else if ($csthis > $csadj) { if (!isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) || (isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) && $cells[($i+$cspi)][$j+$ccolsp]['rowspan']<2)) { // don't overwrite bordering cells that span $celladj['border_details']['L'] = $cbord['border_details']['R']; $this->setBorder($cbord['border'] , _BORDER_RIGHT); $this->setBorder($celladj['border'] , _BORDER_LEFT, false); } } else if ($csadj > $csthis) { if ($crowsp < 2) { // don't overwrite this cell if it spans $cbord['border_details']['R'] = $celladj['border_details']['L']; $this->setBorder($cbord['border'] , _BORDER_RIGHT, false); $this->setBorder($celladj['border'] , _BORDER_LEFT); } } // double>solid>dashed>dotted... else if (array_search($cbord['border_details']['R']['style'],$this->borderstyles) > array_search($celladj['border_details']['L']['style'],$this->borderstyles)) { if (!isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) || (isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) && $cells[($i+$cspi)][$j+$ccolsp]['rowspan']<2)) { // don't overwrite bordering cells that span $celladj['border_details']['L'] = $cbord['border_details']['R']; $this->setBorder($celladj['border'] , _BORDER_LEFT, false); $this->setBorder($cbord['border'] , _BORDER_RIGHT); } } else if (array_search($celladj['border_details']['L']['style'],$this->borderstyles) > array_search($cbord['border_details']['R']['style'],$this->borderstyles)) { if ($crowsp < 2) { // don't overwrite this cell if it spans $cbord['border_details']['R'] = $celladj['border_details']['L']; $this->setBorder($cbord['border'] , _BORDER_RIGHT , false); $this->setBorder($celladj['border'] , _BORDER_LEFT); } } // Style set on cell vs. table else if ($celladj['border_details']['L']['dom'] > $cbord['border_details']['R']['dom']) { if ($crowsp < 2) { // don't overwrite this cell if it spans $cbord['border_details']['R'] = $celladj['border_details']['L']; $this->setBorder($celladj['border'] , _BORDER_LEFT); } } // Style set on cell vs. table - OR - LEFT/TOP (cell) in preference to BOTTOM/RIGHT else { if (!isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) || (isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) && $cells[($i+$cspi)][$j+$ccolsp]['rowspan']<2)) { // don't overwrite bordering cells that span $celladj['border_details']['L'] = $cbord['border_details']['R']; $this->setBorder($cbord['border'] , _BORDER_RIGHT); } } } else if ($celladj) { // if right-cell border is not set if (!isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) || (isset($cells[($i+$cspi)][$j+$ccolsp]['rowspan']) && $cells[($i+$cspi)][$j+$ccolsp]['rowspan']<2)) { // don't overwrite bordering cells that span $celladj['border_details']['L'] = $cbord['border_details']['R']; } } // mPDF 5.3.79 if ($celladj && $this->packTableData) { $celladj['borderbin'] = $this->_packCellBorder($celladj); unset($celladj['border']); unset($celladj['border_details']); } if ($this->cacheTables) { $this->_cacheUpdateBorder($celladj, $fh, $table['cells'][$i+$cspi][$j+$ccolsp]); } unset($celladj); } } } // Set maximum cell border width meeting at LRTB edges of cell - used for extended cell border // ['border_details']['mbw']['LT'] = meeting border width - Left border - Top end if (!$table['borders_separate']) { $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $cbord['border_details']['L']['w']); $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $cbord['border_details']['R']['w']); $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $cbord['border_details']['T']['w']); $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $cbord['border_details']['B']['w']); $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $cbord['border_details']['L']['w']); $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $cbord['border_details']['R']['w']); $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $cbord['border_details']['T']['w']); $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $cbord['border_details']['B']['w']); if (($i+$crowsp) < $numrows && isset($cells[$i+$crowsp][$j])) { // Has Bottom adjoining cell if ($this->packTableData) { // mPDF 5.3.79 if ($this->cacheTables) { $adjc = $this->_uncacheCell($table['cells'][$i+$crowsp][$j], '', $fh); } else { $adjc = $cells[$i+$crowsp][$j]; } $celladj = $this->_unpackCellBorder($adjc['borderbin']); } else { $celladj =& $cells[$i+$crowsp][$j]; } $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $celladj['border_details']['L']['w'], $celladj['border_details']['mbw']['TL']); $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $celladj['border_details']['R']['w'], $celladj['border_details']['mbw']['TR']); $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $celladj['border_details']['mbw']['LT']); $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $celladj['border_details']['mbw']['RT']); unset($celladj); } if (($j+$ccolsp) < $numcols && isset($cells[$i][$j+$ccolsp])) { // Has Right adjoining cell if ($this->packTableData) { // mPDF 5.3.79 if ($this->cacheTables) { $adjc = $this->_uncacheCell($table['cells'][$i][$j+$ccolsp], '', $fh); } else { $adjc = $cells[$i][$j+$ccolsp]; } $celladj = $this->_unpackCellBorder($adjc['borderbin']); } else { $celladj =& $cells[$i][$j+$ccolsp]; } $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $celladj['border_details']['T']['w'], $celladj['border_details']['mbw']['LT']); $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $celladj['border_details']['B']['w'], $celladj['border_details']['mbw']['LB']); $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $celladj['border_details']['mbw']['TL']); $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $celladj['border_details']['mbw']['BL']); unset($celladj); } if ($i > 0 && isset($cells[$i-1][$j]) && (($this->packTableData && $cells[$i-1][$j]['borderbin']) || $cells[$i-1][$j]['border'])) { // Has Top adjoining cell if ($this->packTableData) { // mPDF 5.3.79 if ($this->cacheTables) { $adjc = $this->_uncacheCell($table['cells'][$i-1][$j], '', $fh); } else { $adjc = $cells[$i-1][$j]; } $celladj = $this->_unpackCellBorder($adjc['borderbin']); } else { $celladj =& $cells[$i-1][$j]; } $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['L']['w'], $celladj['border_details']['mbw']['BL']); $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $celladj['border_details']['R']['w'], $celladj['border_details']['mbw']['BR']); $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $celladj['border_details']['mbw']['LB']); $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $celladj['border_details']['mbw']['RB']); if ($celladj['border_details']['mbw']['BL']) { $celladj['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['mbw']['BL']); } if ($celladj['border_details']['mbw']['BR'] ) { $celladj['border_details']['mbw']['BR'] = max($celladj['border_details']['mbw']['BR'], $cbord['border_details']['mbw']['TR']); } if ($this->packTableData) { $cells[$i-1][$j]['borderbin'] = $this->_packCellBorder($celladj); } unset($celladj); } if ($j > 0 && isset($cells[$i][$j-1]) && (($this->packTableData && $cells[$i][$j-1]['borderbin']) || $cells[$i][$j-1]['border'])) { // Has Left adjoining cell if ($this->packTableData) { // mPDF 5.3.79 if ($this->cacheTables) { $adjc = $this->_uncacheCell($table['cells'][$i][$j-1], '', $fh); } else { $adjc = $cells[$i][$j-1]; } $celladj = $this->_unpackCellBorder($adjc['borderbin']); } else { $celladj =& $cells[$i][$j-1]; } $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $celladj['border_details']['T']['w'], $celladj['border_details']['mbw']['RT']); $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $celladj['border_details']['B']['w'], $celladj['border_details']['mbw']['RB']); $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $celladj['border_details']['mbw']['BR']); $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['mbw']['TR']); if ($celladj['border_details']['mbw']['RT']) { $celladj['border_details']['mbw']['RT'] = max($celladj['border_details']['mbw']['RT'], $cbord['border_details']['mbw']['LT']); } if ($celladj['border_details']['mbw']['RB']) { $celladj['border_details']['mbw']['RB'] = max($celladj['border_details']['mbw']['RB'], $cbord['border_details']['mbw']['LB']); } if ($this->packTableData) { $cells[$i][$j-1]['borderbin'] = $this->_packCellBorder($celladj); } unset($celladj); } // Update maximum cell border width at LRTB edges of table - used for overall table width if ($j == 0 && $cbord['border_details']['L']['w']) { $table['max_cell_border_width']['L'] = max($table['max_cell_border_width']['L'],$cbord['border_details']['L']['w']); } if (($j == ($numcols-1) || ($j+$ccolsp) == $numcols ) && $cbord['border_details']['R']['w']) { $table['max_cell_border_width']['R'] = max($table['max_cell_border_width']['R'],$cbord['border_details']['R']['w']); } if ($i == 0 && $cbord['border_details']['T']['w']) { $table['max_cell_border_width']['T'] = max($table['max_cell_border_width']['T'],$cbord['border_details']['T']['w']); } if (($i == ($numrows-1) || ($i+$crowsp) == $numrows ) && $cbord['border_details']['B']['w']) { $table['max_cell_border_width']['B'] = max($table['max_cell_border_width']['B'],$cbord['border_details']['B']['w']); } } /*-- END TABLES-ADVANCED-BORDERS --*/ if ($this->packTableData) { $cell['borderbin'] = $this->_packCellBorder($cbord); } // mPDF 5.3.79 if ($this->cacheTables) { $this->_cacheUpdateBorder($cell, $fh, $table['cells'][$i][$j]); } unset($cbord ); unset($cell ); } } } // mPDF 5.3.79 if ($this->cacheTables) { fclose($fh); } unset($cell ); } // END FIX BORDERS ************************************************************************************ function _reverseTableDir(&$table) { // mPDF 5.3.79 if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); } $cells = &$table['cells']; $numcols = $table['nc']; $numrows = $table['nr']; for( $i = 0 ; $i < $numrows ; $i++ ) { //Rows $row = array(); for( $j = ($numcols-1) ; $j >= 0 ; $j-- ) { //Columns if (isset($cells[$i][$j]) && $cells[$i][$j]) { // mPDF 5.3.79 if ($this->cacheTables) { $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh); } else $cell = &$cells[$i][$j]; $col = $numcols - $j - 1; if (isset($cell['colspan']) && $cell['colspan'] > 1) { $col -= ($cell['colspan']-1); } // Nested content for ($n=0; $n < count($cell['textbuffer']); $n++) { $t = $cell['textbuffer'][$n][0]; if (substr($t,0,19) == "\xbb\xa4\xactype=nestedtable") { // mPDF 5.3.79 $objattr = $this->_getObjAttr($t); $objattr['col'] = $col; $cell['textbuffer'][$n][0] = "\xbb\xa4\xactype=nestedtable,objattr=".serialize($objattr)."\xbb\xa4\xac"; $this->table[($this->tableLevel+1)][$objattr['nestedcontent']]['nestedpos'][1] = $col; // mPDF 5.3.79 if ($this->cacheTables) { $this->_cacheUpdateTxB($cell, $fh, $table['cells'][$i][$j]); } } } $row[$col] = $cells[$i][$j]; unset($cell); // mPDF 5.3.79 } } for($f=0; $f < $numcols; $f++) { if (!isset($row[$f])) { $row[$f] = 0; } // mPDF 5.3.79 } $table['cells'][$i] = $row; } // mPDF 5.3.79 if ($this->cacheTables) { fclose($fh); } } function _tableWrite(&$table, $split=false, $startrow=0, $startcol=0, $splitpg=0, $rety = 0){ // mPDF 5.3.36 $level = $table['level']; $levelid = $table['levelid']; $cells = &$table['cells']; $numcols = $table['nc']; $numrows = $table['nr']; if ($this->ColActive && $level==1) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS* if (!$split || ($startrow==0 && $splitpg==0) || $startrow>0){ // mPDF 5.3.36 // TABLE TOP MARGIN if ($table['margin']['T']) { if (!$this->table_rotate && $level==1) { $this->DivLn($table['margin']['T'],$this->blklvl,true,1); // collapsible } else { $this->y += ($table['margin']['T']); } } // Advance down page by half width of top border if ($table['borders_separate']) { // mPDF 5.3.36 if ($startrow>0 && (!isset($table['is_thead']) || count($table['is_thead'])==0)) $adv = $table['border_spacing_V']/2; else $adv = $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2; } else { $adv = $table['max_cell_border_width']['T']/2; } if (!$this->table_rotate && $level==1) { $this->DivLn($adv); } else { $this->y += $adv; } } // mPDF 5.3.36 if ($level==1) { $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w']; $x0 = $this->x; $y0 = $this->y; $right = $x0 + $this->blk[$this->blklvl]['inner_width']; $outerfilled = $this->y; // Keep track of how far down the outer DIV bgcolor is painted (NB rowspans) $this->outerfilled = $this->y; $this->colsums = array(); // mPDF 5.3.92 } else { $x0 = $this->x; $y0 = $this->y; $right = $x0 + $table['w']; } if ($this->table_rotate) { $temppgwidth = $this->tbrot_maxw; $this->PageBreakTrigger = $pagetrigger = $y0 + ($this->blk[$this->blklvl]['inner_width']); if ($level==1) { $this->tbrot_y0 = $this->y - $adv - $table['margin']['T'] ; $this->tbrot_x0 = $this->x; $this->tbrot_w = $table['w']; if ($table['borders_separate']) { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2; } else { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['max_cell_border_width']['T']; } } } else { $this->PageBreakTrigger = $pagetrigger = ($this->h - $this->bMargin); if ($level==1) { $temppgwidth = $this->blk[$this->blklvl]['inner_width']; if (isset($table['a']) and ($table['w'] < $this->blk[$this->blklvl]['inner_width'])) { if ($table['a']=='C') { $x0 += ((($right-$x0) - $table['w'])/2); } else if ($table['a']=='R') { $x0 = $right - $table['w']; } } } else { $temppgwidth = $table['w']; } } if(!isset($table['overflow'])) { $table['overflow'] = null; } if ($table['overflow']=='hidden' && $level==1 && !$this->table_rotate && !$this->ColActive) { //Bounding rectangle to clip $this->tableClipPath = sprintf('q %.3F %.3F %.3F %.3F re W n',$x0*_MPDFK,$this->h*_MPDFK,$this->blk[$this->blklvl]['inner_width']*_MPDFK,-$this->h*_MPDFK); $this->_out($this->tableClipPath); } else { $this->tableClipPath = ''; } if ($table['borders_separate']) { $indent = $table['margin']['L'] + $table['border_details']['L']['w'] + $table['padding']['L'] + $table['border_spacing_H']/2; } else { $indent = $table['margin']['L'] + $table['max_cell_border_width']['L']/2; } $x0 += $indent; $returny = 0; $lastCol = 0; // mPDF 5.3.36 $tableheader = array(); $tablefooter = array(); $tableheaderrowheight = 0; // mPDF 5.3.36 $tablefooterrowheight = 0; $footery = 0; // mPD 3.0 Set the Page & Column where table starts if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN $tablestartpage = 'EVEN'; } else if (($this->mirrorMargins) && (($this->page)%2==1)) { // ODD $tablestartpage = 'ODD'; } else { $tablestartpage = ''; } if ($this->ColActive) { $tablestartcolumn = $this->CurrCol; } else { $tablestartcolumn = ''; } // mPDF 5.3.79 if ($this->cacheTables) { $fh = fopen($table['cache'], "r+b"); } else { $fh = null; } $y = $h = 0; for( $i = 0; $i < $numrows ; $i++ ) { //Rows if ($this->progressBar) { $this->UpdateProgressBar(7,intval(30 + ($i*40/$numrows)),' '); } // *PROGRESS-BAR* if (isset($table['is_tfoot'][$i]) && $table['is_tfoot'][$i] && $level==1) { $tablefooterrowheight += $table['hr'][$i]; // mPDF 5.3.36 $tablefooter[$i][0]['trbackground-images'] = $table['trbackground-images'][$i]; $tablefooter[$i][0]['trgradients'] = $table['trgradients'][$i]; $tablefooter[$i][0]['trbgcolor'] = $table['bgcolor'][$i]; for( $j = $startcol ; $j < $numcols ; $j++ ) { //Columns // mPDF 5.3.36 if (isset($cells[$i][$j]) && $cells[$i][$j]) { // mPDF 5.3.79 if ($this->cacheTables) { $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh); } else $cell = &$cells[$i][$j]; // mPDF 5.3.36 if ($split) { if ($table['colPg'][$j] != $splitpg) { continue; } list($x,$w) = $this->_splitTableGetWidth($table, $i, $j, $fh); $js = $j - $startcol; } else { list($x,$w) = $this->_tableGetWidth($table, $i, $j, $fh); $js = $j; } list($y,$h) = $this->_tableGetHeight($table, $i, $j, $fh); $x += $x0; $y += $y0; //Get info of tfoot ==>> table footer $tablefooter[$i][$js]['x'] = $x; $tablefooter[$i][$js]['y'] = $y; $tablefooter[$i][$js]['h'] = $h; $tablefooter[$i][$js]['w'] = $w; if (isset($cell['textbuffer'])) { $tablefooter[$i][$js]['textbuffer'] = $cell['textbuffer']; } else { $tablefooter[$i][$js]['textbuffer'] = ''; } $tablefooter[$i][$js]['a'] = $cell['a']; $tablefooter[$i][$js]['R'] = $cell['R']; $tablefooter[$i][$js]['va'] = $cell['va']; $tablefooter[$i][$js]['mih'] = $cell['mih']; $tablefooter[$i][$js]['gradient'] = $cell['gradient']; // *BACKGROUNDS* $tablefooter[$i][$js]['background-image'] = $cell['background-image']; // *BACKGROUNDS* //CELL FILL BGCOLOR if (!$this->simpleTables){ if ($this->packTableData) { $c = $this->_unpackCellBorder($cell['borderbin']); $tablefooter[$i][$js]['border'] = $c['border']; $tablefooter[$i][$js]['border_details'] = $c['border_details']; } else { $tablefooter[$i][$js]['border'] = $cell['border']; $tablefooter[$i][$js]['border_details'] = $cell['border_details']; } } else if ($this->simpleTables){ $tablefooter[$i][$js]['border'] = $table['simple']['border']; $tablefooter[$i][$js]['border_details'] = $table['simple']['border_details']; } $tablefooter[$i][$js]['bgcolor'] = $cell['bgcolor']; $tablefooter[$i][$js]['padding'] = $cell['padding']; $tablefooter[$i][$js]['rowspan'] = $cell['rowspan']; $tablefooter[$i][$js]['colspan'] = $cell['colspan']; } } } } if ($level==1) { $this->_out('___TABLE___BACKGROUNDS'.date('jY')); } $tableheaderadj = 0; $tablefooteradj = 0; $tablestartpageno = $this->page; //Draw Table Contents and Borders for( $i = 0; $i < $numrows ; $i++ ) { //Rows // mPDF 5.3.36 if ($split && $startrow > 0) { $thnr = (isset($table['is_thead']) ? count($table['is_thead']) : 0); if ($i >= $thnr && $i < $startrow) { continue; } if ($i == $startrow){ $returny = $rety - $tableheaderrowheight; } } // Get Maximum row/cell height in row - including rowspan>1 + 1 overlapping // mPDF 5.3.A7 $maxrowheight = $this->_tableGetMaxRowHeight($table, $i, $fh); // mPDF 5.3.6 $skippage = false; $newpagestarted = false; for( $j = $startcol ; $j < $numcols ; $j++ ) { //Columns // mPDF 5.3.36 // mPDF 5.3.36 if ($split) { if ($table['colPg'][$j] > $splitpg) { break; } $lastCol = $j; } if (isset($cells[$i][$j]) && $cells[$i][$j]) { // mPDF 5.3.79 if ($this->cacheTables) { $cell = $this->_uncacheCell($table['cells'][$i][$j], '', $fh); } else $cell = &$cells[$i][$j]; // mPDF 5.3.36 if ($split) { $lastCol = $j + (isset($cell['colspan']) ? ($cell['colspan']-1) : 0) ; list($x,$w) = $this->_splitTableGetWidth($table, $i, $j, $fh); } else { list($x,$w) = $this->_tableGetWidth($table, $i, $j, $fh); } list($y,$h) = $this->_tableGetHeight($table, $i, $j, $fh); $x += $x0; $y += $y0; $y -= $returny; if ($table['borders_separate']) { if (!empty($tablefooter) || $i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows) || (!isset($cell['rowspan']) && ($i+1) == $numrows) ) { $extra = $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2; //$extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2; } else { $extra = $table['border_spacing_V']/2; } } else { $extra = $table['max_cell_border_width']['B']/2; } // mPDF 5.3.36 if ($j==$startcol && ((($y + $maxrowheight + $extra ) > ($pagetrigger+0.001)) || (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && ($y + $maxrowheight + $tablefooterrowheight + $extra) > $pagetrigger) && ($this->tableLevel==1 && $i < ($numrows - $table['headernrows']))) && ($y0 >0 || $x0 > 0) && !$this->InFooter && $this->autoPageBreak ) { // mPDF 5.3.62 // mPDF 5.3.76 if (!$skippage) { // mPDF 5.3.36 $finalSpread = true; $firstSpread = true; if ($split) { for($t=$startcol; $t<$numcols; $t++) { // Are there more columns to print on a next page? if ($table['colPg'][$t] > $splitpg) { $finalSpread = false; break; } } if ($startcol>0) { $firstSpread = false; } } if (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && $i > 0 ) { $this->y = $y; $ya = $this->y; $this->TableHeaderFooter($tablefooter,$tablestartpage,$tablestartcolumn,'F',$level, $firstSpread, $finalSpread); // mPDF 5.3.36 if ($this->table_rotate) { $this->tbrot_h += $this->y - $ya ; } $tablefooteradj = $this->y - $ya ; } $y -= $y0; $returny += $y; $oldcolumn = $this->CurrCol; if ($this->AcceptPageBreak()) { $newpagestarted = true; $this->y = $y + $y0; // Move down to account for border-spacing or // extra half border width in case page breaks in middle if($i>0 && !$this->table_rotate && $level==1 && !$this->ColActive) { if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2; // If table footer if (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && $i > 0 ) { $adv += ($table['padding']['B'] + $table['border_details']['B']['w']); } } else { $maxbwtop = 0; $maxbwbottom = 0; if (!$this->simpleTables){ if (!empty($tablefooter)) { $maxbwbottom = $table['max_cell_border_width']['B']; } else { $brow = $i-1; for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) { if (isset($cells[$brow][$ctj]) && $cells[$brow][$ctj]) { // mPDF 5.3.79 if ($this->cacheTables) { $cadj = $this->_uncacheCell($table['cells'][$brow][$ctj], '', $fh); list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cadj['borderbin']); } else if ($this->packTableData) { list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$brow][$ctj]['borderbin']); } else { $bb = $cells[$brow][$ctj]['border_details']['B']['w']; } $maxbwbottom = max($maxbwbottom , $bb); } } } if (!empty($tableheader)) { $maxbwtop = $table['max_cell_border_width']['T']; } else { $trow = $i-1; for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) { if (isset($cells[$trow][$ctj]) && $cells[$trow][$ctj]) { // mPDF 5.3.79 if ($this->cacheTables) { $cadj = $this->_uncacheCell($table['cells'][$trow][$ctj], '', $fh); list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cadj['borderbin']); } else if ($this->packTableData) { list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$trow][$ctj]['borderbin']); } else { $bt = $cells[$trow][$ctj]['border_details']['T']['w']; } $maxbwtop = max($maxbwtop , $bt); } } } } else if ($this->simpleTables){ $maxbwtop = $table['simple']['border_details']['T']['w']; $maxbwbottom = $table['simple']['border_details']['B']['w']; } $adv = $maxbwbottom /2; } $this->y += $adv; } // Rotated table split over pages - needs this->y for borders/backgrounds if($i>0 && $this->table_rotate && $level==1) { // $this->y = $y0 + $this->tbrot_w; // mPDF 5.3.62 } if ($this->tableClipPath ) { $this->_out("Q"); } $bx = $x0; $by = $y0; if ($table['borders_separate']) { $bx -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['border_spacing_H']/2); if ($tablestartpageno != $this->page) { // IF already broken across a previous pagebreak $by += $table['max_cell_border_width']['T']/2; if (empty($tableheader)) { $by -= ($table['border_spacing_V']/2); } } else { $by -= ($table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2); } } else if ($tablestartpageno != $this->page && !empty($tableheader)) { $by += $maxbwtop /2; } $by -= $tableheaderadj; $bh = $this->y - $by + $tablefooteradj; if (!$table['borders_separate']) { $bh -= $adv ; } // mPDF 5.3.36 if ($split) { $bw = 0; for($t=$startcol; $t<$numcols; $t++) { if ($table['colPg'][$t] == $splitpg) { $bw += $table['wc'][$t]; } if ($table['colPg'][$t] > $splitpg) { break; } } if ($table['borders_separate']) { if ($firstSpread) { $bw += $table['padding']['L'] + $table['border_details']['L']['w'] + $table['border_spacing_H']; } else { $bx += ($table['padding']['L'] + $table['border_details']['L']['w']); $bw += $table['border_spacing_H']; } if ($finalSpread) { $bw += $table['padding']['R'] + $table['border_details']['R']['w']/2 + $table['border_spacing_H']; } } } else { $bw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R']; } if (!$this->ColActive && ($i > 0 || $j > 0)) { // mPDF 5.3.36 if (isset($table['bgcolor'][-1])) { $color = $this->ConvertColor($table['bgcolor'][-1]); if ($color) { if (!$table['borders_separate']) { $bh -= $table['max_cell_border_width']['B']/2; } $this->tableBackgrounds[$level*9][] = array('gradient'=>false, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'col'=>$color); } } /*-- BACKGROUNDS --*/ if (isset($table['gradient'])) { $g = $this->grad->parseBackgroundGradient($table['gradient']); if ($g) { $this->tableBackgrounds[$level*9+1][] = array('gradient'=>true, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>''); } } if (isset($table['background-image'])) { if ($table['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $table['background-image']['gradient'] )) { $g = $this->grad->parseMozGradient( $table['background-image']['gradient'] ); if ($g) { $this->tableBackgrounds[$level*9+1][] = array('gradient'=>true, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>''); } } else { $image_id = $table['background-image']['image_id']; $orig_w = $table['background-image']['orig_w']; $orig_h = $table['background-image']['orig_h']; $x_pos = $table['background-image']['x_pos']; $y_pos = $table['background-image']['y_pos']; $x_repeat = $table['background-image']['x_repeat']; $y_repeat = $table['background-image']['y_repeat']; $resize = $table['background-image']['resize']; $opacity = $table['background-image']['opacity']; $itype = $table['background-image']['itype']; $this->tableBackgrounds[$level*9+2][] = array('x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>'', 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype); } } /*-- END BACKGROUNDS --*/ } // $this->AcceptPageBreak() has moved tablebuffer to $this->pages content if ($this->tableBackgrounds) { $s = $this->PrintTableBackgrounds(); if ($this->bufferoutput) { $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->headerbuffer); $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->headerbuffer ); } else { $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]); $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->pages[$this->page]); } $this->tableBackgrounds = array(); } // mPDF 5.3.36 if ($split) { if ($i == 0 && $j == 0) { $y0 = -1; } else if ($finalSpread) { $splitpg = 0; $startcol = 0; $startrow = $i; } else { $splitpg++; $startcol = $t; $returny -= $y; } return array(false, $startrow, $startcol, $splitpg, $returny, $y0); } $this->AddPage($this->CurOrientation); $this->_out('___TABLE___BACKGROUNDS'.date('jY')); if ($this->tableClipPath ) { $this->_out($this->tableClipPath); } // Added to correct for OddEven Margins $x=$x +$this->MarginCorrection; $x0=$x0 +$this->MarginCorrection; // Move down to account for half of top border-spacing or // extra half border width in case page was broken in middle if($i>0 && !$this->table_rotate && $level==1 && $table['headernrows']==0) { // mPDF 5.3.62 if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2; } else { $maxbwtop = 0; for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) { if (isset($cells[$i][$ctj]) && $cells[$i][$ctj]) { if (!$this->simpleTables){ // mPDF 5.3.79 if ($this->cacheTables) { $celltj = $this->_uncacheCell($table['cells'][$i][$ctj], '', $fh); list($bt,$br,$bb,$bl) = $this->_getBorderWidths($celltj['borderbin']); } else if ($this->packTableData) { list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$i][$ctj]['borderbin']); } else { $bt = $cells[$i][$ctj]['border_details']['T']['w']; } $maxbwtop = max($maxbwtop, $bt); } else if ($this->simpleTables){ $maxbwtop = max($maxbwtop, $table['simple']['border_details']['T']['w']); } } } $adv = $maxbwtop /2; } $this->y += $adv; } if ($this->table_rotate) { $this->tbrot_x0 = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w']; if ($table['borders_separate']) { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2; } else { $this->tbrot_h = $table['margin']['T'] + $table['max_cell_border_width']['T'] ; } $this->tbrot_y0 = $this->y; $pagetrigger = $y0 - $tableheaderadj + ($this->blk[$this->blklvl]['inner_width']); } else { $pagetrigger = $this->PageBreakTrigger; } if ($this->kwt_saved && $level==1) { $this->kwt_moved = true; } // Disable Table header repeat if Keep Block together if (!$this->keep_block_together && !empty($tableheader)) { // mPDF 5.3.62 $ya = $this->y; $this->TableHeaderFooter($tableheader,$tablestartpage,$tablestartcolumn,'H',$level); if ($this->table_rotate) { $this->tbrot_h = $this->y - $ya ; } $tableheaderadj = $this->y - $ya ; } else if ($i==0 && !$this->keep_block_together && !$this->table_rotate && $level==1 && !$this->ColActive) { // Advance down page if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2 + $table['border_details']['T']['w'] + $table['padding']['T']; } else { $adv = $table['max_cell_border_width']['T'] /2 ; } if ($adv) { if ($this->table_rotate) { $this->y += ($adv); } else { $this->DivLn($adv,$this->blklvl,true); } } } $outerfilled = 0; $y = $y0 = $this->y; } /*-- COLUMNS --*/ // COLS // COLUMN CHANGE if ($this->CurrCol != $oldcolumn) { // Added to correct for Columns $x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap); $x0 += $this->ChangeColumn * ($this->ColWidth+$this->ColGap); if ($this->CurrCol == 0) { // just added a page - possibly with tableheader $y0 = $this->y; // this->y0 is global used by Columns - $y0 is internal to tablewrite } else { $y0 = $this->y0; // this->y0 is global used by Columns - $y0 is internal to tablewrite } $y = $y0; $outerfilled = 0; if ($this->CurrCol != 0 && ($this->keepColumns && $this->ColActive) && !empty($tableheader) && $i > 0 ) { $this->x = $x; $this->y = $y; $this->TableHeaderFooter($tableheader,$tablestartpage,$tablestartcolumn,'H',$level); $y0 = $y=$this->y; } } /*-- END COLUMNS --*/ } $skippage = true; } $this->x = $x; $this->y = $y; if ($this->kwt_saved && $level==1) { $this->printkwtbuffer(); $x0 = $x = $this->x; $y0 = $y = $this->y; $this->kwt_moved = false; $this->kwt_saved = false; } // Set the Page & Column where table actually starts if ($i==0 && $j==0 && $level==1) { if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN $tablestartpage = 'EVEN'; } else if (($this->mirrorMargins) && (($this->page)%2==1)) { // ODD $tablestartpage = 'ODD'; } else { $tablestartpage = ''; } $tablestartpageno = $this->page; if ($this->ColActive) { $tablestartcolumn = $this->CurrCol; } // *COLUMNS* } //ALIGN $align = $cell['a']; /*-- COLUMNS --*/ // If outside columns, this is done in PaintDivBB if ($this->ColActive) { //OUTER FILL BGCOLOR of DIVS if ($this->blklvl > 0 && ($j==0) && !$this->table_rotate && $level==1) { $firstblockfill = $this->GetFirstBlockFill(); if ($firstblockfill && $this->blklvl >= $firstblockfill) { $divh = $maxrowheight; // Last row if (isset($cell['rowspan']) && (($i == $numrows-1 && $cell['rowspan']<2) || ($cell['rowspan']>1 && ($i + $cell['rowspan']-1) == $numrows-1))) { if ($table['borders_separate']) { $adv = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2; } else { $adv = $table['margin']['B'] + $table['max_cell_border_width']['B']/2; } $divh += $adv; //last row: fill bottom half of bottom border (y advanced at end) } if (($this->y + $divh) > $outerfilled ) { // if not already painted by previous rowspan $bak_x = $this->x; $bak_y = $this->y; if ($outerfilled > $this->y) { $divh = ($this->y + $divh) - $outerfilled; $this->y = $outerfilled; } $this->DivLn($divh,-3,false); $outerfilled = $this->y + $divh; // Reset current block fill $bcor = $this->blk[$this->blklvl]['bgcolorarray']; if ($bcor ) $this->SetFColor($bcor); $this->x = $bak_x; $this->y = $bak_y; } } } } //TABLE BACKGROUND FILL BGCOLOR - for cellSpacing if ($this->ColActive) { if ($table['borders_separate']) { $fill = isset($table['bgcolor'][-1]) ? $table['bgcolor'][-1] : 0; if ($fill) { $color = $this->ConvertColor($fill); if ($color) { $xadj = ($table['border_spacing_H']/2); $yadj = ($table['border_spacing_V']/2); $wadj = $table['border_spacing_H']; $hadj = $table['border_spacing_V']; if ($i == 0) { // Top $yadj += $table['padding']['T'] + $table['border_details']['T']['w'] ; $hadj += $table['padding']['T'] + $table['border_details']['T']['w'] ; } if ($j == 0) { // Left $xadj += $table['padding']['L'] + $table['border_details']['L']['w'] ; $wadj += $table['padding']['L'] + $table['border_details']['L']['w'] ; } if ($i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows) || (!isset($cell['rowspan']) && ($i+1) == $numrows)) { // Bottom $hadj += $table['padding']['B'] + $table['border_details']['B']['w'] ; } if ($j == ($numcols-1) || (isset($cell['colspan']) && ($j+$cell['colspan']) == $numcols) || (!isset($cell['colspan']) && ($j+1) == $numcols)) { // Right $wadj += $table['padding']['R'] + $table['border_details']['R']['w'] ; } $this->SetFColor($color); $this->Rect($x - $xadj, $y - $yadj, $w + $wadj, $h + $hadj, 'F'); } } } } /*-- END COLUMNS --*/ if ($table['empty_cells']!='hide' || !empty($cell['textbuffer']) || (isset($cell['nestedcontent']) && $cell['nestedcontent']) || !$table['borders_separate'] ) { $paintcell = true; } else { $paintcell = false; } //Set Borders $bord = 0; $bord_det = array(); if (!$this->simpleTables){ if ($this->packTableData) { if ($cell['borderbin']) { $c = $this->_unpackCellBorder($cell['borderbin']); $bord = $c['border']; $bord_det = $c['border_details']; } } else if ($cell['border']) { $bord = $cell['border']; $bord_det = $cell['border_details']; } } else if ($this->simpleTables){ if ($table['simple']['border']) { $bord = $table['simple']['border']; $bord_det = $table['simple']['border_details']; } } //TABLE ROW OR CELL FILL BGCOLOR $fill = 0; if (isset($cell['bgcolor']) && $cell['bgcolor'] && $cell['bgcolor']!='transparent') { $fill = $cell['bgcolor']; $leveladj = 6; } else if (isset($table['bgcolor'][$i]) && $table['bgcolor'][$i] && $table['bgcolor'][$i]!='transparent') { // Row color $fill = $table['bgcolor'][$i]; $leveladj = 3; } if ($fill && $paintcell) { $color = $this->ConvertColor($fill); if ($color) { if ($table['borders_separate']) { if ($this->ColActive) { $this->SetFColor($color); $this->Rect($x+ ($table['border_spacing_H']/2), $y+ ($table['border_spacing_V']/2), $w- $table['border_spacing_H'], $h- $table['border_spacing_V'], 'F'); } else { $this->tableBackgrounds[$level*9+$leveladj][] = array('gradient'=>false, 'x'=>($x + ($table['border_spacing_H']/2)), 'y'=>($y + ($table['border_spacing_V']/2)), 'w'=>($w - $table['border_spacing_H']), 'h'=>($h - $table['border_spacing_V']), 'col'=>$color); } } else { if ($this->ColActive) { $this->SetFColor($color); $this->Rect($x, $y, $w, $h, 'F'); } else { $this->tableBackgrounds[$level*9+$leveladj][] = array('gradient'=>false, 'x'=>$x, 'y'=>$y, 'w'=>$w, 'h'=>$h, 'col'=>$color); } } } } /*-- BACKGROUNDS --*/ if (isset($cell['gradient']) && $cell['gradient'] && $paintcell){ $g = $this->grad->parseBackgroundGradient($cell['gradient']); if ($g) { if ($table['borders_separate']) { $px = $x+ ($table['border_spacing_H']/2); $py = $y+ ($table['border_spacing_V']/2); $pw = $w- $table['border_spacing_H']; $ph = $h- $table['border_spacing_V']; } else { $px = $x; $py = $y; $pw = $w; $ph = $h; } if ($this->ColActive) { $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']); } else { $this->tableBackgrounds[$level*9+7][] = array('gradient'=>true, 'x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>''); } } } if (isset($cell['background-image']) && $paintcell) { if ($cell['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $cell['background-image']['gradient'] )) { $g = $this->grad->parseMozGradient( $cell['background-image']['gradient'] ); if ($g) { if ($table['borders_separate']) { $px = $x+ ($table['border_spacing_H']/2); $py = $y+ ($table['border_spacing_V']/2); $pw = $w- $table['border_spacing_H']; $ph = $h- $table['border_spacing_V']; } else { $px = $x; $py = $y; $pw = $w; $ph = $h; } if ($this->ColActive) { $this->grad->Gradient($px, $py, $pw, $ph, $g['type'], $g['stops'], $g['colorspace'], $g['coords'], $g['extend']); } else { $this->tableBackgrounds[$level*9+7][] = array('gradient'=>true, 'x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>''); } } } else if ($cell['background-image']['image_id']) { // Background pattern $n = count($this->patterns)+1; if ($table['borders_separate']) { $px = $x+ ($table['border_spacing_H']/2); $py = $y+ ($table['border_spacing_V']/2); $pw = $w- $table['border_spacing_H']; $ph = $h- $table['border_spacing_V']; } else { $px = $x; $py = $y; $pw = $w; $ph = $h; } if ($this->ColActive) { list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($cell['background-image']['orig_w'], $cell['background-image']['orig_h'], $pw, $ph, $cell['background-image']['resize'], $cell['background-image']['x_repeat'], $cell['background-image']['y_repeat']); $this->patterns[$n] = array('x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'pgh'=>$this->h, 'image_id'=>$cell['background-image']['image_id'], 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$cell['background-image']['x_pos'] , 'y_pos'=>$cell['background-image']['y_pos'] , 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat); if ($cell['background-image']['opacity']>0 && $cell['background-image']['opacity']<1) { $opac = $this->SetAlpha($cell['background-image']['opacity'],'Normal',true); } else { $opac = ''; } $this->_out(sprintf('q /Pattern cs /P%d scn %s %.3F %.3F %.3F %.3F re f Q', $n, $opac, $px*_MPDFK, ($this->h-$py)*_MPDFK, $pw*_MPDFK, -$ph*_MPDFK)); } else { $image_id = $cell['background-image']['image_id']; $orig_w = $cell['background-image']['orig_w']; $orig_h = $cell['background-image']['orig_h']; $x_pos = $cell['background-image']['x_pos']; $y_pos = $cell['background-image']['y_pos']; $x_repeat = $cell['background-image']['x_repeat']; $y_repeat = $cell['background-image']['y_repeat']; $resize = $cell['background-image']['resize']; $opacity = $cell['background-image']['opacity']; $itype = $cell['background-image']['itype']; $this->tableBackgrounds[$level*9+8][] = array('x'=>$px, 'y'=>$py, 'w'=>$pw, 'h'=>$ph, 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>'', 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype); } } } /*-- END BACKGROUNDS --*/ if (isset($cell['colspan']) && $cell['colspan']>1) { $ccolsp = $cell['colspan']; } else { $ccolsp = 1; } if (isset($cell['rowspan']) && $cell['rowspan']>1) { $crowsp = $cell['rowspan']; } else { $crowsp = 1; } // but still need to do this for repeated headers... if (!$table['borders_separate'] && $this->tabletheadjustfinished && !$this->simpleTables){ if (isset($table['topntail']) && $table['topntail']) { $bord_det['T'] = $this->border_details($table['topntail']); $bord_det['T']['w'] /= $this->shrin_k; $this->setBorder($bord, _BORDER_TOP); } if (isset($table['thead-underline']) && $table['thead-underline']) { $bord_det['T'] = $this->border_details($table['thead-underline']); $bord_det['T']['w'] /= $this->shrin_k; $this->setBorder($bord, _BORDER_TOP); } } //Get info of first row ==>> table header //Use > 1 row if THEAD if (isset($table['is_thead'][$i]) && $table['is_thead'][$i] && $level==1) { // mPDF 5.3.62 if ($j==0) $tableheaderrowheight += $table['hr'][$i]; // mPDF 5.3.36 $tableheader[$i][0]['trbackground-images'] = (isset($table['trbackground-images'][$i]) ? $table['trbackground-images'][$i] : null); $tableheader[$i][0]['trgradients'] = (isset($table['trgradients'][$i]) ? $table['trgradients'][$i] : null); $tableheader[$i][0]['trbgcolor'] = (isset($table['bgcolor'][$i]) ? $table['bgcolor'][$i] : null); $tableheader[$i][$j]['x'] = $x; $tableheader[$i][$j]['y'] = $y; $tableheader[$i][$j]['h'] = $h; $tableheader[$i][$j]['w'] = $w; if (isset($cell['textbuffer'])) { $tableheader[$i][$j]['textbuffer'] = $cell['textbuffer']; } else { $tableheader[$i][$j]['textbuffer'] = ''; } $tableheader[$i][$j]['a'] = $cell['a']; $tableheader[$i][$j]['R'] = $cell['R']; $tableheader[$i][$j]['va'] = $cell['va']; $tableheader[$i][$j]['mih'] = $cell['mih']; $tableheader[$i][$j]['gradient'] = (isset($cell['gradient']) ? $cell['gradient'] : null); // *BACKGROUNDS* $tableheader[$i][$j]['background-image'] = (isset($cell['background-image']) ? $cell['background-image'] : null); // *BACKGROUNDS* $tableheader[$i][$j]['rowspan'] = (isset($cell['rowspan']) ? $cell['rowspan'] : null); $tableheader[$i][$j]['colspan'] = (isset($cell['colspan']) ? $cell['colspan'] : null); $tableheader[$i][$j]['bgcolor'] = $cell['bgcolor']; if (!$this->simpleTables){ $tableheader[$i][$j]['border'] = $bord; $tableheader[$i][$j]['border_details'] = $bord_det; } else if ($this->simpleTables){ $tableheader[$i][$j]['border'] = $table['simple']['border']; $tableheader[$i][$j]['border_details'] = $table['simple']['border_details']; } $tableheader[$i][$j]['padding'] = $cell['padding']; } // CELL BORDER if ($bord || $bord_det) { if ($table['borders_separate'] && $paintcell) { $this->_tableRect($x + ($table['border_spacing_H']/2)+($bord_det['L']['w'] /2), $y+ ($table['border_spacing_V']/2)+($bord_det['T']['w'] /2), $w-$table['border_spacing_H']-($bord_det['L']['w'] /2)-($bord_det['R']['w'] /2), $h- $table['border_spacing_V']-($bord_det['T']['w'] /2)-($bord_det['B']['w']/2), $bord, $bord_det, false, $table['borders_separate']); } else if (!$table['borders_separate']) { $this->_tableRect($x, $y, $w, $h, $bord, $bord_det, true, $table['borders_separate']); // true causes buffer } } //VERTICAL ALIGN if ($cell['R'] && INTVAL($cell['R']) > 0 && INTVAL($cell['R']) < 90 && isset($cell['va']) && $cell['va']!='B') { $cell['va']='B';} if (!isset($cell['va']) || $cell['va']=='M') $this->y += ($h-$cell['mih'])/2; elseif (isset($cell['va']) && $cell['va']=='B') $this->y += $h-$cell['mih']; // NESTED CONTENT // TEXT (and nested tables) $this->divalign=$align; $this->divwidth=$w; if (!empty($cell['textbuffer'])) { if ($level==1) { // mPDF 5.3.92 if (isset($table['is_tfoot'][$i]) && $table['is_tfoot'][$i]) { if (preg_match('/{colsum([0-9]*)[_]*}/', $cell['textbuffer'][0][0], $m)) { $rep = sprintf("%01.".intval($m[1])."f", $this->colsums[$j]); $cell['textbuffer'][0][0] = preg_replace('/{colsum[0-9_]*}/', $rep ,$cell['textbuffer'][0][0]); } } else { $this->colsums[$j] += floatval(preg_replace('/^[^0-9\.\,]*/','',$cell['textbuffer'][0][0])); } } $opy = $this->y; // mPDF ITERATION if ($this->iterationCounter) { foreach($cell['textbuffer'] AS $k=>$t) { // mPDF 5.3.78 if (preg_match('/{iteration ([a-zA-Z0-9_]+)}/',$t[0], $m)) { $vname = '__'.$m[1].'_'; if (!isset($this->$vname)) { $this->$vname = 1; } else { $this->$vname++; } $cell['textbuffer'][$k][0] = preg_replace('/{iteration '.$m[1].'}/', $this->$vname, $cell['textbuffer'][$k][0]); } } } if ($cell['R']) { $cellPtSize = $cell['textbuffer'][0][11] / $this->shrin_k; if (!$cellPtSize) { $cellPtSize = $this->default_font_size; } $cellFontHeight = ($cellPtSize/_MPDFK); $opx = $this->x; $angle = INTVAL($cell['R']); // Only allow 45 to 89 degrees (when bottom-aligned) or exactly 90 or -90 if ($angle > 90) { $angle = 90; } else if ($angle > 0 && $angle <45) { $angle = 45; } else if ($angle < 0) { $angle = -90; } $offset = ((sin(deg2rad($angle))) * 0.37 * $cellFontHeight); if (isset($cell['a']) && $cell['a']=='R') { $this->x += ($w) + ($offset) - ($cellFontHeight/3) - ($cell['padding']['R'] + ($table['border_spacing_H']/2)); } else if (!isset($cell['a']) || $cell['a']=='C') { $this->x += ($w/2) + ($offset); } else { $this->x += ($offset) + ($cellFontHeight/3)+($cell['padding']['L'] +($table['border_spacing_H']/2)); } // mPDF 5.3.78 $str = ''; foreach($cell['textbuffer'] AS $t) { $str .= $t[0].' '; } $str = trim($str); if (!isset($cell['va']) || $cell['va']=='M') { $this->y -= ($h-$cell['mih'])/2; //Undo what was added earlier VERTICAL ALIGN if ($angle > 0) { $this->y += (($h-$cell['mih'])/2) + $cell['padding']['T'] + ($cell['mih']-($cell['padding']['T'] + $cell['padding']['B'])); } else if ($angle < 0) { $this->y += (($h-$cell['mih'])/2)+ ($cell['padding']['T'] + ($table['border_spacing_V']/2)); } } elseif (isset($cell['va']) && $cell['va']=='B') { $this->y -= $h-$cell['mih']; //Undo what was added earlier VERTICAL ALIGN if ($angle > 0) { $this->y += $h-($cell['padding']['B'] + ($table['border_spacing_V']/2)); } else if ($angle < 0) { $this->y += $h-$cell['mih'] + ($cell['padding']['T'] + ($table['border_spacing_V']/2)); } } elseif (isset($cell['va']) && $cell['va']=='T') { if ($angle > 0) { $this->y += $cell['mih']-($cell['padding']['B'] + ($table['border_spacing_V']/2)); } else if ($angle < 0) { $this->y += ($cell['padding']['T'] + ($table['border_spacing_V']/2)); } } $this->Rotate($angle,$this->x,$this->y); $s_fs = $this->FontSizePt; $s_f = $this->FontFamily; $s_st = $this->FontStyle; // mPDF 5.3.34 if (!empty($cell['textbuffer'][0][3])) { //Font Color $cor = $cell['textbuffer'][0][3]; $this->SetTColor($cor); } // mPDF 5.3.54 $s_str = $this->strike; $this->strike = $cell['textbuffer'][0][8]; //Strikethrough $this->SetFont($cell['textbuffer'][0][4],$cell['textbuffer'][0][2],$cellPtSize,true,true); $this->Text($this->x,$this->y,$str); $this->Rotate(0); $this->SetFont($s_f,$s_st,$s_fs,true,true); $this->SetTColor(0); // mPDF 5.3.34 $this->strike = $s_str; // mPDF 5.3.54 $this->x = $opx; } else { if (!$this->simpleTables){ // mPDF 5.3.76 if ($bord_det) { $btlw = $bord_det['L']['w']; $btrw = $bord_det['R']['w']; $bttw = $bord_det['T']['w']; } else { $btlw = 0; $btrw = 0; $bttw = 0; } if ($table['borders_separate']) { $xadj = $btlw + $cell['padding']['L'] +($table['border_spacing_H']/2); $wadj = $btlw + $btrw + $cell['padding']['L'] +$cell['padding']['R'] + $table['border_spacing_H']; $yadj = $bttw + $cell['padding']['T'] + ($table['border_spacing_H']/2); } else { $xadj = $btlw/2 + $cell['padding']['L']; $wadj = ($btlw + $btrw)/2 + $cell['padding']['L'] + $cell['padding']['R']; $yadj = $bttw/2 + $cell['padding']['T']; } } else if ($this->simpleTables){ if ($table['borders_separate']) { // NB twice border width $xadj = $table['simple']['border_details']['L']['w'] + $cell['padding']['L'] +($table['border_spacing_H']/2); $wadj = $table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'] + $cell['padding']['L'] +$cell['padding']['R'] + $table['border_spacing_H']; $yadj = $table['simple']['border_details']['T']['w'] + $cell['padding']['T'] + ($table['border_spacing_H']/2); } else { $xadj = $table['simple']['border_details']['L']['w']/2 + $cell['padding']['L']; $wadj = ($table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'])/2 + $cell['padding']['L'] + $cell['padding']['R']; $yadj = $table['simple']['border_details']['T']['w']/2 + $cell['padding']['T']; } } $this->divwidth=$w-$wadj; if ($this->divwidth == 0) { $this->divwidth = 0.0001; } $this->x += $xadj; $this->y += $yadj; $this->printbuffer($cell['textbuffer'],'',true); } $this->y = $opy; } /*-- BACKGROUNDS --*/ if (!$this->ColActive) { if (isset($table['trgradients'][$i]) && ($j==0 || $table['borders_separate'])) { $g = $this->grad->parseBackgroundGradient($table['trgradients'][$i]); if ($g) { $gx = $x0; $gy = $y; $gh = $h; $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R']; if ($table['borders_separate']) { $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']); $s = ''; $clx = $x+ ($table['border_spacing_H']/2); $cly = $y+ ($table['border_spacing_V']/2); $clw = $w- $table['border_spacing_H']; $clh = $h- $table['border_spacing_V']; // Set clipping path $s = ' q 0 w '; // Line width=0 $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL $s .= ' W n '; // Ends path no-op & Sets the clipping path $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx + ($table['border_spacing_H']/2), 'y'=>$gy + ($table['border_spacing_V']/2), 'w'=>$gw - $table['border_spacing_V'], 'h'=>$gh - $table['border_spacing_H'], 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s); } else { $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$gw, 'h'=>$gh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>''); } } } if (isset($table['trbackground-images'][$i]) && ($j==0 || $table['borders_separate'])) { if ($table['trbackground-images'][$i]['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $table['trbackground-images'][$i]['gradient'] )) { $g = $this->grad->parseMozGradient( $table['trbackground-images'][$i]['gradient'] ); if ($g) { $gx = $x0; $gy = $y; $gh = $h; $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R']; if ($table['borders_separate']) { $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']); $s = ''; $clx = $x+ ($table['border_spacing_H']/2); $cly = $y+ ($table['border_spacing_V']/2); $clw = $w- $table['border_spacing_H']; $clh = $h- $table['border_spacing_V']; // Set clipping path $s = ' q 0 w '; // Line width=0 $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL before the arc $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL $s .= ' W n '; // Ends path no-op & Sets the clipping path $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx + ($table['border_spacing_H']/2), 'y'=>$gy + ($table['border_spacing_V']/2), 'w'=>$gw - $table['border_spacing_V'], 'h'=>$gh - $table['border_spacing_H'], 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s); } else { $this->tableBackgrounds[$level*9+4][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$gw, 'h'=>$gh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>''); } } } else { $image_id = $table['trbackground-images'][$i]['image_id']; $orig_w = $table['trbackground-images'][$i]['orig_w']; $orig_h = $table['trbackground-images'][$i]['orig_h']; $x_pos = $table['trbackground-images'][$i]['x_pos']; $y_pos = $table['trbackground-images'][$i]['y_pos']; $x_repeat = $table['trbackground-images'][$i]['x_repeat']; $y_repeat = $table['trbackground-images'][$i]['y_repeat']; $resize = $table['trbackground-images'][$i]['resize']; $opacity = $table['trbackground-images'][$i]['opacity']; $itype = $table['trbackground-images'][$i]['itype']; $clippath = ''; $gx = $x0; $gy = $y; $gh = $h; $gw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R']; if ($table['borders_separate']) { $gw -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['padding']['R'] + $table['border_details']['R']['w'] + $table['border_spacing_H']); $s = ''; $clx = $x + ($table['border_spacing_H']/2); $cly = $y + ($table['border_spacing_V']/2); $clw = $w - $table['border_spacing_H']; $clh = $h - $table['border_spacing_V']; // Set clipping path $s = ' q 0 w '; // Line width=0 $s .= sprintf('%.3F %.3F m ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // start point TL $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BL $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly+$clh))*_MPDFK); // line to BR $s .= sprintf('%.3F %.3F l ', ($clx+$clw)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TR $s .= sprintf('%.3F %.3F l ', ($clx)*_MPDFK, ($this->h-($cly))*_MPDFK); // line to TL $s .= ' W n '; // Ends path no-op & Sets the clipping path $this->tableBackgrounds[$level*9+5][] = array('x'=>$gx + ($table['border_spacing_H']/2), 'y'=>$gy + ($table['border_spacing_V']/2), 'w'=>$gw - $table['border_spacing_V'], 'h'=>$gh - $table['border_spacing_H'], 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>$s, 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype); } else { $this->tableBackgrounds[$level*9+5][] = array('x'=>$gx, 'y'=>$gy, 'w'=>$gw, 'h'=>$gh, 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>'', 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype); } } } } /*-- END BACKGROUNDS --*/ // TABLE BORDER - if separate // mPDF 5.3.15 if (($table['borders_separate'] || ($this->simpleTables && !$table['simple']['border'])) && $table['border']) { $halfspaceL = $table['padding']['L'] + ($table['border_spacing_H']/2); $halfspaceR = $table['padding']['R'] + ($table['border_spacing_H']/2); $halfspaceT = $table['padding']['T'] + ($table['border_spacing_V']/2); $halfspaceB = $table['padding']['B'] + ($table['border_spacing_V']/2); $tbx = $x; $tby = $y; $tbw = $w; $tbh = $h; $tab_bord = 0; $corner = ''; if ($i == 0) { // Top $tby -= $halfspaceT + ($table['border_details']['T']['w']/2); $tbh += $halfspaceT + ($table['border_details']['T']['w']/2); $this->setBorder($tab_bord , _BORDER_TOP); $corner .= 'T'; } if ($i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows)) { // Bottom // mPDF 5.3.15 $tbh += $halfspaceB + ($table['border_details']['B']['w']/2); $this->setBorder($tab_bord , _BORDER_BOTTOM); $corner .= 'B'; } if ($j == 0) { // Left $tbx -= $halfspaceL + ($table['border_details']['L']['w']/2); $tbw += $halfspaceL + ($table['border_details']['L']['w']/2); $this->setBorder($tab_bord , _BORDER_LEFT); $corner .= 'L'; } if ($j == ($numcols-1) || (isset($cell['colspan']) && ($j+$cell['colspan']) == $numcols)) { // Right // mPDF 5.3.15 $tbw += $halfspaceR + ($table['border_details']['R']['w']/2); $this->setBorder($tab_bord , _BORDER_RIGHT); $corner .= 'R'; } $this->_tableRect($tbx, $tby, $tbw, $tbh, $tab_bord , $table['border_details'], false, $table['borders_separate'], 'table', $corner, $table['border_spacing_V'], $table['border_spacing_H'] ); } unset($cell ); //Reset values $this->Reset(); }//end of (if isset(cells)...) }// end of columns $newpagestarted = false; $this->tabletheadjustfinished = false; if ($this->ColActive && $i < $numrows-1 && $level==1) { $this->breakpoints[$this->CurrCol][] = $y + $h; } // *COLUMNS* /*-- COLUMNS --*/ if ($this->ColActive) { if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); } } /*-- END COLUMNS --*/ if ($i == $numrows-1) { $this->y = $y + $h; } //last row jump (update this->y position) if ($this->table_rotate && $level==1) { $this->tbrot_h += $h; } }// end of rows if ($this->progressBar) { $this->UpdateProgressBar(7,70,' '); } // *PROGRESS-BAR* if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); } if ($this->tableClipPath ) { $this->_out("Q"); } $this->tableClipPath = ''; // Advance down page by half width of bottom border if ($table['borders_separate']) { $this->y += $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2; } else { $this->y += $table['max_cell_border_width']['B']/2; } if ($table['borders_separate'] && $level==1) { $this->tbrot_h += $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2; } else if ($level==1) { $this->tbrot_h += $table['margin']['B'] + $table['max_cell_border_width']['B']/2; } $bx = $x0; $by = $y0; if ($table['borders_separate']) { $bx -= ($table['padding']['L'] + $table['border_details']['L']['w'] + $table['border_spacing_H']/2); if ($tablestartpageno != $this->page) { // IF broken across page $by += $table['max_cell_border_width']['T']/2; if (empty($tableheader)) { $by -= ($table['border_spacing_V']/2); } } // mPDF 5.3.36 else if ($split && $startrow > 0 && empty($tableheader)) { $by -= ($table['border_spacing_V']/2); } else { $by -= ($table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2); } } else if ($tablestartpageno != $this->page && !empty($tableheader)) { $by += $maxbwtop /2; } $by -= $tableheaderadj; $bh = $this->y - $by; if (!$table['borders_separate']) { $bh -= $table['max_cell_border_width']['B']/2; } // mPDF 5.3.36 if ($split) { $bw = 0; $finalSpread = true; for($t=$startcol; $t<$numcols; $t++) { if ($table['colPg'][$t] == $splitpg) { $bw += $table['wc'][$t]; } if ($table['colPg'][$t] > $splitpg) { $finalSpread = false; break; } } if ($startcol==0) { $firstSpread = true; } else { $firstSpread = false; } if ($table['borders_separate']) { // mPDF 5.3.83 $bw += $table['border_spacing_H']; if ($firstSpread) { $bw += $table['padding']['L'] + $table['border_details']['L']['w']; } else { $bx += ($table['padding']['L'] + $table['border_details']['L']['w']); } if ($finalSpread) { $bw += $table['padding']['R'] + $table['border_details']['R']['w']; } } } else { $bw = $table['w'] - ($table['max_cell_border_width']['L']/2) - ($table['max_cell_border_width']['R']/2) - $table['margin']['L'] - $table['margin']['R']; } if (!$this->ColActive) { if (isset($table['bgcolor'][-1])) { $color = $this->ConvertColor($table['bgcolor'][-1]); if ($color) { $this->tableBackgrounds[$level*9][] = array('gradient'=>false, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'col'=>$color); } } /*-- BACKGROUNDS --*/ if (isset($table['gradient'])) { $g = $this->grad->parseBackgroundGradient($table['gradient']); if ($g) { $this->tableBackgrounds[$level*9+1][] = array('gradient'=>true, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>''); } } if (isset($table['background-image'])) { if ($table['background-image']['gradient'] && preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient/', $table['background-image']['gradient'] )) { $g = $this->grad->parseMozGradient( $table['background-image']['gradient'] ); if ($g) { $this->tableBackgrounds[$level*9+1][] = array('gradient'=>true, 'x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'gradtype'=>$g['type'], 'stops'=>$g['stops'], 'colorspace'=>$g['colorspace'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>''); } } else { $image_id = $table['background-image']['image_id']; $orig_w = $table['background-image']['orig_w']; $orig_h = $table['background-image']['orig_h']; $x_pos = $table['background-image']['x_pos']; $y_pos = $table['background-image']['y_pos']; $x_repeat = $table['background-image']['x_repeat']; $y_repeat = $table['background-image']['y_repeat']; $resize = $table['background-image']['resize']; $opacity = $table['background-image']['opacity']; $itype = $table['background-image']['itype']; $this->tableBackgrounds[$level*9+2][] = array('x'=>$bx, 'y'=>$by, 'w'=>$bw, 'h'=>$bh, 'image_id'=>$image_id, 'orig_w'=>$orig_w, 'orig_h'=>$orig_h, 'x_pos'=>$x_pos, 'y_pos'=>$y_pos, 'x_repeat'=>$x_repeat, 'y_repeat'=>$y_repeat, 'clippath'=>'', 'resize'=>$resize, 'opacity'=>$opacity, 'itype'=>$itype); } } /*-- END BACKGROUNDS --*/ } if ($this->tableBackgrounds && $level == 1) { $s = $this->PrintTableBackgrounds(); if ($this->table_rotate && !$this->processingHeader && !$this->processingFooter) { $this->tablebuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->tablebuffer); if ($level == 1) { $this->tablebuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->tablebuffer); } } else if ($this->bufferoutput) { $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->headerbuffer); if ($level == 1) { $this->headerbuffer = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->headerbuffer ); } } else { $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]); if ($level == 1) { $this->pages[$this->page] = preg_replace('/(___TABLE___BACKGROUNDS'.date('jY').')/', " ", $this->pages[$this->page]); } } $this->tableBackgrounds = array(); } // TABLE BOTTOM MARGIN if ($table['margin']['B']) { if (!$this->table_rotate && $level==1) { $this->DivLn($table['margin']['B'],$this->blklvl,true); // collapsible } else { $this->y += ($table['margin']['B']); } } if ($this->ColActive && $level==1) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS* // mPDF 5.3.79 if ($this->cacheTables) { fclose($fh); } // mPDF 5.3.36 if ($split) { // Are there more columns to print on a next page? if ($lastCol < $numcols-1) { $splitpg++; $startcol = $lastCol + 1; return array(false, $startrow, $startcol, $splitpg, $returny, $y0); } else { // mPDF 5.3.79 if ($this->cacheTables) { unlink($table['cache']); @unlink($table['cache'].'.bak'); } return array(true,0,0,0); } } // mPDF 5.3.79 if ($this->cacheTables) { unlink($table['cache']); @unlink($table['cache'].'.bak'); } }//END OF FUNCTION _tableWrite() /////////////////////////END OF TABLE CODE////////////////////////////////// /*-- END TABLES --*/ function _putextgstates() { for ($i = 1; $i <= count($this->extgstates); $i++) { $this->_newobj(); $this->extgstates[$i]['n'] = $this->n; $this->_out('<</Type /ExtGState'); foreach ($this->extgstates[$i]['parms'] as $k=>$v) $this->_out('/'.$k.' '.$v); $this->_out('>>'); $this->_out('endobj'); } } // mPDF 5.3.41 Visibility function _putocg() { $this->_newobj(); $this->n_ocg_print=$this->n; $this->_out('<</Type /OCG /Name '.$this->_textstring('print')); $this->_out('/Usage <</Print <</PrintState /ON>> /View <</ViewState /OFF>>>>>>'); $this->_out('endobj'); $this->_newobj(); $this->n_ocg_view=$this->n; $this->_out('<</Type /OCG /Name '.$this->_textstring('view')); $this->_out('/Usage <</Print <</PrintState /OFF>> /View <</ViewState /ON>>>>>>'); $this->_out('endobj'); $this->_newobj(); $this->n_ocg_hidden=$this->n; $this->_out('<</Type /OCG /Name '.$this->_textstring('hidden')); $this->_out('/Usage <</Print <</PrintState /OFF>> /View <</ViewState /OFF>>>>>>'); $this->_out('endobj'); } /*-- IMPORTS --*/ // from mPDFI function _putimportedobjects() { if (is_array($this->parsers) && count($this->parsers) > 0) { foreach($this->parsers AS $filename => $p) { $this->current_parser =& $this->parsers[$filename]; if (is_array($this->_obj_stack[$filename])) { while($n = key($this->_obj_stack[$filename])) { $nObj = $this->current_parser->pdf_resolve_object($this->current_parser->c,$this->_obj_stack[$filename][$n][1]); $this->_newobj($this->_obj_stack[$filename][$n][0]); if ($nObj[0] == PDF_TYPE_STREAM) { $this->pdf_write_value($nObj); } else { $this->pdf_write_value($nObj[1]); } $this->_out('endobj'); $this->_obj_stack[$filename][$n] = null; // free memory unset($this->_obj_stack[$filename][$n]); reset($this->_obj_stack[$filename]); } } } } } function _putformxobjects() { $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; reset($this->tpls); foreach($this->tpls AS $tplidx => $tpl) { $p=($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer']; $this->_newobj(); $this->tpls[$tplidx]['n'] = $this->n; $this->_out('<<'.$filter.'/Type /XObject'); $this->_out('/Subtype /Form'); $this->_out('/FormType 1'); // Left/Bottom/Right/Top $this->_out(sprintf('/BBox [%.2F %.2F %.2F %.2F]', $tpl['box']['x']*_MPDFK, $tpl['box']['y']*_MPDFK, ($tpl['box']['x'] + $tpl['box']['w'])*_MPDFK, ($tpl['box']['y'] + $tpl['box']['h'])*_MPDFK ) ); if (isset($tpl['box'])) $this->_out(sprintf('/Matrix [1 0 0 1 %.5F %.5F]',-$tpl['box']['x']*_MPDFK, -$tpl['box']['y']*_MPDFK)); $this->_out('/Resources '); if (isset($tpl['resources'])) { $this->current_parser =& $tpl['parser']; $this->pdf_write_value($tpl['resources']); } else { $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) { $this->_out('/Font <<'); foreach($this->_res['tpl'][$tplidx]['fonts'] as $font) $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); $this->_out('>>'); } if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) || isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) { $this->_out('/XObject <<'); if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) { foreach($this->_res['tpl'][$tplidx]['images'] as $image) $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); } if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) { foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $itpl) $this->_out($this->tplprefix.$i.' '.$itpl['n'].' 0 R'); } $this->_out('>>'); } $this->_out('>>'); } $this->_out('/Length '.strlen($p).' >>'); $this->_putstream($p); $this->_out('endobj'); } } /*-- END IMPORTS --*/ function _putpatterns() { for ($i = 1; $i <= count($this->patterns); $i++) { $x = $this->patterns[$i]['x']; $y = $this->patterns[$i]['y']; $w = $this->patterns[$i]['w']; $h = $this->patterns[$i]['h']; $pgh = $this->patterns[$i]['pgh']; $orig_w = $this->patterns[$i]['orig_w']; $orig_h = $this->patterns[$i]['orig_h']; $image_id = $this->patterns[$i]['image_id']; $itype = $this->patterns[$i]['itype']; if ($this->patterns[$i]['x_repeat']) { $x_repeat = true; } else { $x_repeat = false; } if ($this->patterns[$i]['y_repeat']) { $y_repeat = true; } else { $y_repeat = false; } $x_pos = $this->patterns[$i]['x_pos']; if (stristr($x_pos ,'%') ) { $x_pos += 0; $x_pos /= 100; $x_pos = ($w * $x_pos) - ($orig_w/_MPDFK * $x_pos); } $y_pos = $this->patterns[$i]['y_pos']; if (stristr($y_pos ,'%') ) { $y_pos += 0; $y_pos /= 100; $y_pos = ($h * $y_pos) - ($orig_h/_MPDFK * $y_pos); } $adj_x = ($x_pos + $x) *_MPDFK; $adj_y = (($pgh - $y_pos - $y)*_MPDFK) - $orig_h ; $img_obj = false; if ($itype == 'svg' || $itype == 'wmf') { foreach($this->formobjects AS $fo) { if ($fo['i'] == $image_id) { $img_obj = $fo['n']; $fo_w = $fo['w']; $fo_h = -$fo['h']; $wmf_x = $fo['x']; $wmf_y = $fo['y']; break; } } } else { foreach($this->images AS $img) { if ($img['i'] == $image_id) { $img_obj = $img['n']; break; } } } if (!$img_obj ) { echo "Problem: Image object not found for background pattern ".$img['i']; exit; } $this->_newobj(); $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); if ($itype == 'svg' || $itype == 'wmf') { $this->_out('/XObject <</FO'.$image_id.' '.$img_obj.' 0 R >>'); // ******* ADD ANY ExtGStates, Shading AND Fonts needed for the FormObject // Set in classes/svg array['fo'] = true // Required that _putshaders comes before _putpatterns in _putresources // This adds any resources associated with any FormObject to every Formobject - overkill but works! if (count($this->extgstates)) { $this->_out('/ExtGState <<'); foreach($this->extgstates as $k=>$extgstate) if (isset($extgstate['fo']) && $extgstate['fo']) { if (isset($extgstate['trans'])) $this->_out('/'.$extgstate['trans'].' '.$extgstate['n'].' 0 R'); else $this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R'); } $this->_out('>>'); } /*-- BACKGROUNDS --*/ if (isset($this->gradients) AND (count($this->gradients) > 0)) { $this->_out('/Shading <<'); foreach ($this->gradients as $id => $grad) { if (isset($grad['fo']) && $grad['fo']) { $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R'); } } $this->_out('>>'); } /*-- END BACKGROUNDS --*/ $this->_out('/Font <<'); foreach($this->fonts as $font) { if (!$font['used'] && $font['type']=='TTF') { continue; } if (isset($font['fo']) && $font['fo']) { if ($font['type']=='TTF' && ($font['sip'] || $font['smp'])) { foreach($font['n'] AS $k => $fid) { $this->_out('/F'.$font['subsetfontids'][$k].' '.$font['n'][$k].' 0 R'); } } else { $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); } } } $this->_out('>>'); } else { $this->_out('/XObject <</I'.$image_id.' '.$img_obj.' 0 R >>'); } $this->_out('>>'); $this->_out('endobj'); $this->_newobj(); $this->patterns[$i]['n'] = $this->n; $this->_out('<< /Type /Pattern /PatternType 1 /PaintType 1 /TilingType 2'); $this->_out('/Resources '. ($this->n-1) .' 0 R'); $this->_out(sprintf('/BBox [0 0 %.3F %.3F]',$orig_w,$orig_h)); if ($x_repeat) { $this->_out(sprintf('/XStep %.3F',$orig_w)); } else { $this->_out(sprintf('/XStep %d',99999)); } if ($y_repeat) { $this->_out(sprintf('/YStep %.3F',$orig_h)); } else { $this->_out(sprintf('/YStep %d',99999)); } if ($itype == 'svg' || $itype == 'wmf') { $this->_out(sprintf('/Matrix [1 0 0 -1 %.3F %.3F]', $adj_x, ($adj_y+$orig_h))); $s = sprintf("q %.3F 0 0 %.3F %.3F %.3F cm /FO%d Do Q",($orig_w/$fo_w), (-$orig_h/$fo_h), -($orig_w/$fo_w)*$wmf_x, ($orig_w/$fo_w)*$wmf_y, $image_id); } else { $this->_out(sprintf('/Matrix [1 0 0 1 %.3F %.3F]',$adj_x,$adj_y)); $s = sprintf("q %.3F 0 0 %.3F 0 0 cm /I%d Do Q",$orig_w,$orig_h,$image_id); } if ($this->compress) { $this->_out('/Filter /FlateDecode'); $s = gzcompress($s); } $this->_out('/Length '.strlen($s).'>>'); $this->_putstream($s); $this->_out('endobj'); } } /*-- BACKGROUNDS --*/ function _putshaders() { $maxid = count($this->gradients); //index for transparency gradients foreach ($this->gradients as $id => $grad) { if (($grad['type'] == 2 || $grad['type'] == 3) && empty($grad['is_mask'])) { $this->_newobj(); $this->_out('<<'); $this->_out('/FunctionType 3'); $this->_out('/Domain [0 1]'); $fn = array(); $bd = array(); $en = array(); for($i=0; $i<(count($grad['stops'])-1); $i++) { $fn[] = ($this->n+1+$i).' 0 R'; $en[] = '0 1'; if ($i>0) { $bd[] = sprintf('%.3F', $grad['stops'][$i]['offset']); } } $this->_out('/Functions ['.implode(' ',$fn).']'); $this->_out('/Bounds ['.implode(' ',$bd).']'); $this->_out('/Encode ['.implode(' ',$en).']'); $this->_out('>>'); $this->_out('endobj'); $f1 = $this->n; for($i=0; $i<(count($grad['stops'])-1); $i++) { $this->_newobj(); $this->_out('<<'); $this->_out('/FunctionType 2'); $this->_out('/Domain [0 1]'); $this->_out('/C0 ['.$grad['stops'][$i]['col'].']'); $this->_out('/C1 ['.$grad['stops'][$i+1]['col'].']'); $this->_out('/N 1'); $this->_out('>>'); $this->_out('endobj'); } } if ($grad['type'] == 2 || $grad['type'] == 3) { // mPDF 5.3.A1 if (isset($grad['trans']) && $grad['trans']) { $this->_newobj(); $this->_out('<<'); $this->_out('/FunctionType 3'); $this->_out('/Domain [0 1]'); $fn = array(); $bd = array(); $en = array(); for($i=0; $i<(count($grad['stops'])-1); $i++) { $fn[] = ($this->n+1+$i).' 0 R'; $en[] = '0 1'; if ($i>0) { $bd[] = sprintf('%.3F', $grad['stops'][$i]['offset']); } } $this->_out('/Functions ['.implode(' ',$fn).']'); $this->_out('/Bounds ['.implode(' ',$bd).']'); $this->_out('/Encode ['.implode(' ',$en).']'); $this->_out('>>'); $this->_out('endobj'); $f2 = $this->n; for($i=0; $i<(count($grad['stops'])-1); $i++) { $this->_newobj(); $this->_out('<<'); $this->_out('/FunctionType 2'); $this->_out('/Domain [0 1]'); $this->_out(sprintf('/C0 [%.3F]', $grad['stops'][$i]['opacity'])); $this->_out(sprintf('/C1 [%.3F]', $grad['stops'][$i+1]['opacity'])); $this->_out('/N 1'); $this->_out('>>'); $this->_out('endobj'); } } } if (empty($grad['is_mask'])) { $this->_newobj(); $this->_out('<<'); $this->_out('/ShadingType '.$grad['type']); if (isset($grad['colorspace'])) { $this->_out('/ColorSpace /Device'.$grad['colorspace']); // Can use CMYK if all C0 and C1 above have 4 values } else { $this->_out('/ColorSpace /DeviceRGB'); } if ($grad['type'] == 2) { $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3])); $this->_out('/Function '.$f1.' 0 R'); $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] '); $this->_out('>>'); } else if ($grad['type'] == 3) { //x0, y0, r0, x1, y1, r1 //at this this time radius of inner circle is 0 $ir = 0; if (isset($grad['coords'][5]) && $grad['coords'][5]) { $ir = $grad['coords'][5]; } $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $ir, $grad['coords'][2], $grad['coords'][3], $grad['coords'][4])); $this->_out('/Function '.$f1.' 0 R'); $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] '); $this->_out('>>'); } // mPDF 5.3.A1 else if ($grad['type']==6) { $this->_out('/BitsPerCoordinate 16'); $this->_out('/BitsPerComponent 8'); if ($grad['colorspace'] == 'CMYK') { $this->_out('/Decode[0 1 0 1 0 1 0 1 0 1 0 1]'); } else if ($grad['colorspace'] == 'Gray') { $this->_out('/Decode[0 1 0 1 0 1]'); } else { $this->_out('/Decode[0 1 0 1 0 1 0 1 0 1]'); } $this->_out('/BitsPerFlag 8'); $this->_out('/Length '.strlen($grad['stream'])); $this->_out('>>'); $this->_putstream($grad['stream']); } $this->_out('endobj'); } $this->gradients[$id]['id'] = $this->n; // set pattern object $this->_newobj(); $out = '<< /Type /Pattern /PatternType 2'; $out .= ' /Shading '.$this->gradients[$id]['id'].' 0 R'; $out .= ' >>'; $out .= "\n".'endobj'; $this->_out($out); $this->gradients[$id]['pattern'] = $this->n; if (isset($grad['trans']) && $grad['trans']) { // luminosity pattern $transid = $id + $maxid; $this->_newobj(); $this->_out('<<'); $this->_out('/ShadingType '.$grad['type']); $this->_out('/ColorSpace /DeviceGray'); if ($grad['type'] == 2) { $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3])); $this->_out('/Function '.$f2.' 0 R'); $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] '); $this->_out('>>'); } else if ($grad['type'] == 3) { //x0, y0, r0, x1, y1, r1 //at this this time radius of inner circle is 0 $ir = 0; if (isset($grad['coords'][5]) && $grad['coords'][5]) { $ir = $grad['coords'][5]; } $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $ir, $grad['coords'][2], $grad['coords'][3], $grad['coords'][4])); $this->_out('/Function '.$f2.' 0 R'); $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] '); $this->_out('>>'); } // mPDF 5.3.A1 else if ($grad['type']==6) { $this->_out('/BitsPerCoordinate 16'); $this->_out('/BitsPerComponent 8'); $this->_out('/Decode[0 1 0 1 0 1]'); $this->_out('/BitsPerFlag 8'); $this->_out('/Length '.strlen($grad['stream_trans'])); $this->_out('>>'); $this->_putstream($grad['stream_trans']); } $this->_out('endobj'); $this->gradients[$transid]['id'] = $this->n; $this->_newobj(); $this->_out('<< /Type /Pattern /PatternType 2'); $this->_out('/Shading '.$this->gradients[$transid]['id'].' 0 R'); $this->_out('>>'); $this->_out('endobj'); $this->gradients[$transid]['pattern'] = $this->n; $this->_newobj(); // Need to extend size of viewing box in case of transformations $str = 'q /a0 gs /Pattern cs /p'.$transid.' scn -'.($this->wPt/2).' -'.($this->hPt/2).' '.(2*$this->wPt).' '.(2*$this->hPt).' re f Q'; $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; $p=($this->compress) ? gzcompress($str) : $str; $this->_out('<< /Type /XObject /Subtype /Form /FormType 1 '.$filter); $this->_out('/Length '.strlen($p)); $this->_out('/BBox [-'.($this->wPt/2).' -'.($this->hPt/2).' '.(2*$this->wPt).' '.(2*$this->hPt).']'); $this->_out('/Group << /Type /Group /S /Transparency /CS /DeviceGray >>'); $this->_out('/Resources <<'); $this->_out('/ExtGState << /a0 << /ca 1 /CA 1 >> >>'); $this->_out('/Pattern << /p'.$transid.' '.$this->gradients[$transid]['pattern'].' 0 R >>'); $this->_out('>>'); $this->_out('>>'); $this->_putstream($p); $this->_out('endobj'); $this->_newobj(); $this->_out('<< /Type /Mask /S /Luminosity /G '.($this->n - 1).' 0 R >>'."\n".'endobj'); $this->_newobj(); $this->_out('<< /Type /ExtGState /SMask '.($this->n - 1).' 0 R /AIS false >>'."\n".'endobj'); if ($grad['fo']) { $this->extgstates[] = array('n' => $this->n, 'trans' => 'TGS'.$id, 'fo'=>true); } else { $this->extgstates[] = array('n' => $this->n, 'trans' => 'TGS'.$id); } } } } /*-- END BACKGROUNDS --*/ function _putspotcolors() { foreach($this->spotColors as $name=>$color) { $this->_newobj(); $this->_out('[/Separation /'.str_replace(' ','#20',$name)); $this->_out('/DeviceCMYK <<'); $this->_out('/Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] '); $this->_out(sprintf('/C1 [%.3F %.3F %.3F %.3F] ',$color['c']/100,$color['m']/100,$color['y']/100,$color['k']/100)); $this->_out('/FunctionType 2 /Domain [0 1] /N 1>>]'); $this->_out('endobj'); $this->spotColors[$name]['n']=$this->n; } } function _putresources() { if ($this->hasOC) // mPDF 5.3.45 $this->_putocg(); // mPDF 5.3.41 Visibility $this->_putextgstates(); $this->_putspotcolors(); if ($this->progressBar) { $this->UpdateProgressBar(2,'40','Compiling Fonts'); } // *PROGRESS-BAR* $this->_putfonts(); if ($this->progressBar) { $this->UpdateProgressBar(2,'50','Compiling Images'); } // *PROGRESS-BAR* $this->_putimages(); $this->_putformobjects(); // *IMAGES-CORE* /*-- IMPORTS --*/ if ($this->enableImports) { $this->_putformxobjects(); $this->_putimportedobjects(); } /*-- END IMPORTS --*/ /*-- BACKGROUNDS --*/ $this->_putshaders(); $this->_putpatterns(); /*-- END BACKGROUNDS --*/ //Resource dictionary $this->offsets[2]=strlen($this->buffer); $this->_out('2 0 obj'); $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); $this->_out('/Font <<'); foreach($this->fonts as $font) { if (!$font['used'] && $font['type']=='TTF') { continue; } if ($font['type']=='TTF' && ($font['sip'] || $font['smp'])) { foreach($font['n'] AS $k => $fid) { $this->_out('/F'.$font['subsetfontids'][$k].' '.$font['n'][$k].' 0 R'); } } else { $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); } } $this->_out('>>'); if (count($this->spotColors)) { $this->_out('/ColorSpace <<'); foreach($this->spotColors as $color) $this->_out('/CS'.$color['i'].' '.$color['n'].' 0 R'); $this->_out('>>'); } if (count($this->extgstates)) { $this->_out('/ExtGState <<'); foreach($this->extgstates as $k=>$extgstate) if (isset($extgstate['trans'])) $this->_out('/'.$extgstate['trans'].' '.$extgstate['n'].' 0 R'); else $this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R'); $this->_out('>>'); } /*-- BACKGROUNDS --*/ if (isset($this->gradients) AND (count($this->gradients) > 0)) { $this->_out('/Shading <<'); foreach ($this->gradients as $id => $grad) { $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R'); } $this->_out('>>'); /* // ??? Not needed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! $this->_out('/Pattern <<'); foreach ($this->gradients as $id => $grad) { $this->_out('/P'.$id.' '.$grad['pattern'].' 0 R'); } $this->_out('>>'); */ } /*-- END BACKGROUNDS --*/ if(count($this->images) || count($this->formobjects) || ($this->enableImports && count($this->tpls))) { $this->_out('/XObject <<'); foreach($this->images as $image) $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); foreach($this->formobjects as $formobject) $this->_out('/FO'.$formobject['i'].' '.$formobject['n'].' 0 R'); /*-- IMPORTS --*/ if ($this->enableImports && count($this->tpls)) { foreach($this->tpls as $tplidx => $tpl) { $this->_out($this->tplprefix.$tplidx.' '.$tpl['n'].' 0 R'); } } /*-- END IMPORTS --*/ $this->_out('>>'); } /*-- BACKGROUNDS --*/ if (count($this->patterns)) { $this->_out('/Pattern <<'); foreach($this->patterns as $k=>$patterns) $this->_out('/P'.$k.' '.$patterns['n'].' 0 R'); $this->_out('>>'); } /*-- END BACKGROUNDS --*/ // mPDF 5.3.41 Visibility if ($this->hasOC) // mPDF 5.3.45 $this->_out('/Properties <</OC1 '.$this->n_ocg_print.' 0 R /OC2 '.$this->n_ocg_view.' 0 R /OC3 '.$this->n_ocg_hidden.' 0 R>>'); $this->_out('>>'); $this->_out('endobj'); // end resource dictionary $this->_putbookmarks(); // *BOOKMARKS* if (isset($this->js) && $this->js) { $this->_putjavascript(); } /*-- ENCRYPTION --*/ if ($this->encrypted) { $this->_newobj(); $this->enc_obj_id = $this->n; $this->_out('<<'); $this->_putencryption(); $this->_out('>>'); $this->_out('endobj'); } /*-- END ENCRYPTION --*/ } function _putjavascript() { $this->_newobj(); $this->n_js = $this->n; $this->_out('<<'); $this->_out('/Names [(EmbeddedJS) '.(1 + $this->n).' 0 R ]'); $this->_out('>>'); $this->_out('endobj'); $this->_newobj(); $this->_out('<<'); $this->_out('/S /JavaScript'); $this->_out('/JS '.$this->_textstring($this->js)); $this->_out('>>'); $this->_out('endobj'); } /*-- ENCRYPTION --*/ function _putencryption() { $this->_out('/Filter /Standard'); if ($this->useRC128encryption) { $this->_out('/V 2'); $this->_out('/R 3'); $this->_out('/Length 128'); } else { $this->_out('/V 1'); $this->_out('/R 2'); } $this->_out('/O ('.$this->_escape($this->Ovalue).')'); $this->_out('/U ('.$this->_escape($this->Uvalue).')'); $this->_out('/P '.$this->Pvalue); } /*-- END ENCRYPTION --*/ function _puttrailer() { $this->_out('/Size '.($this->n+1)); $this->_out('/Root '.$this->n.' 0 R'); $this->_out('/Info '.$this->InfoRoot.' 0 R'); /*-- ENCRYPTION --*/ if ($this->encrypted) { $this->_out('/Encrypt '.$this->enc_obj_id.' 0 R'); $this->_out('/ID [<'.$this->uniqid.'> <'.$this->uniqid.'>]'); } else { /*-- END ENCRYPTION --*/ $uniqid = md5(time() . $this->buffer); $this->_out('/ID [<'.$uniqid.'> <'.$uniqid.'>]'); /*-- ENCRYPTION --*/ } /*-- END ENCRYPTION --*/ } /*-- ENCRYPTION --*/ function SetProtection($permissions=array(),$user_pass='',$owner_pass=null, $length=40) { $this->encrypted=false; if (is_string($permissions) && strlen($permissions)>0) { $permissions = array($permissions); } else if (!is_array($permissions)) { return 0; } $this->last_rc4_key=''; $this->padding="\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08". "\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A"; $options = array( 'print' => 4, // bit 3 'modify' => 8, // bit 4 'copy' => 16, // bit 5 'annot-forms' => 32, // bit 6 'fill-forms' => 256, // bit 9 'extract' => 512, // bit 10 'assemble' => 1024,// bit 11 'print-highres' => 2048 // bit 12 ); // bit 31 = 1073741824 // bit 32 = 2147483648 // bits 13-31 = 2147479552 // bits 13-32 = 4294963200 + 192 = 4294963392 $protection = 4294963392; // bits 7,8,13-32 foreach ($permissions as $permission) { if (!isset($options[$permission])) $this->Error('Incorrect permission: '.$permission); if ($options[$permission] > 32) { $this->useRC128encryption = true; } if (isset($options[$permission])) $protection += $options[$permission]; } if ($length==128) { $this->useRC128encryption = true; } if ($owner_pass === null) $owner_pass = uniqid(rand()); $this->encrypted = true; $this->_generateencryptionkey($user_pass, $owner_pass, $protection); } // Compute key depending on object number where the encrypted data is stored function _objectkey($n) { if ($this->useRC128encryption) $len = 16; else $len = 10; return substr($this->_md5_16($this->encryption_key.pack('VXxx',$n)),0,$len); } // RC4 is the standard encryption algorithm used in PDF format function _RC4($key, $text) { if ($this->last_rc4_key != $key) { $k = str_repeat($key, 256/strlen($key)+1); $rc4 = range(0,255); $j = 0; for ($i=0; $i<256; $i++){ $t = $rc4[$i]; $j = ($j + $t + ord($k[$i])) % 256; $rc4[$i] = $rc4[$j]; $rc4[$j] = $t; } $this->last_rc4_key = $key; $this->last_rc4_key_c = $rc4; } else { $rc4 = $this->last_rc4_key_c; } $len = strlen($text); $a = 0; $b = 0; $out = ''; for ($i=0; $i<$len; $i++){ $a = ($a+1)%256; $t= $rc4[$a]; $b = ($b+$t)%256; $rc4[$a] = $rc4[$b]; $rc4[$b] = $t; $k = $rc4[($rc4[$a]+$rc4[$b])%256]; $out.= chr(ord($text[$i]) ^ $k); } return $out; } // Get MD5 as binary string function _md5_16($string) { return pack('H*',md5($string)); } // Compute O value function _Ovalue($user_pass, $owner_pass) { $tmp = $this->_md5_16($owner_pass); if ($this->useRC128encryption) { for ($i = 0; $i < 50; ++$i) { $tmp = $this->_md5_16($tmp); } } if ($this->useRC128encryption) $keybytelen = (128 / 8); else $keybytelen = (40 / 8); $owner_RC4_key = substr($tmp,0,$keybytelen); $enc = $this->_RC4($owner_RC4_key, $user_pass); if ($this->useRC128encryption) { $len = strlen($owner_RC4_key); for ($i = 1; $i <= 19; ++$i) { $key = ''; for ($j = 0; $j < $len; ++$j) { $key .= chr(ord($owner_RC4_key{$j}) ^ $i); } $enc = $this->_RC4($key, $enc); } } return $enc; } // Compute U value function _Uvalue() { if ($this->useRC128encryption) { $tmp = $this->_md5_16($this->padding.$this->_hexToString($this->uniqid)); $enc = $this->_RC4($this->encryption_key, $tmp); $len = strlen($tmp); for ($i=1; $i<=19; ++$i) { $key = ''; for ($j=0; $j<$len; ++$j) { $key .= chr(ord($this->encryption_key{$j}) ^ $i); } $enc = $this->_RC4($key, $enc); } $enc .= str_repeat("\x00", 16); return substr($enc, 0, 32); } else { return $this->_RC4($this->encryption_key, $this->padding); } } // Compute encryption key function _generateencryptionkey($user_pass, $owner_pass, $protection) { // Pad passwords $user_pass = substr($user_pass.$this->padding,0,32); $owner_pass = substr($owner_pass.$this->padding,0,32); $chars = 'ABCDEF1234567890'; $id = ''; for ($i=0; $i<32; $i++) { $id .= $chars{rand(0, 15)}; } $this->uniqid = md5($id); // Compute O value $this->Ovalue = $this->_Ovalue($user_pass,$owner_pass); // Compute encyption key if ($this->useRC128encryption) $keybytelen = (128/8); else $keybytelen = (40/8); $prot = sprintf('%032b', $protection); $perms = chr(bindec(substr($prot,24,8))); $perms .= chr(bindec(substr($prot,16,8))); $perms .= chr(bindec(substr($prot,8,8))); $perms .= chr(bindec(substr($prot,0,8))); $tmp = $this->_md5_16($user_pass.$this->Ovalue.$perms.$this->_hexToString($this->uniqid)); if ($this->useRC128encryption) { for ($i=0; $i<50; ++$i) { $tmp = $this->_md5_16(substr($tmp, 0, $keybytelen)); } } $this->encryption_key = substr($tmp,0,$keybytelen); // Compute U value $this->Uvalue = $this->_Uvalue(); // Compute P value $this->Pvalue = $protection; } function _hexToString($hs) { $s = ''; $len = strlen($hs); if (($len % 2) != 0) { $hs .= '0'; ++$len; } for ($i = 0; $i < $len; $i += 2) { $s .= chr(hexdec($hs{$i}.$hs{($i + 1)})); } return $s; } /*-- END ENCRYPTION --*/ //========================================= /*-- BOOKMARKS --*/ // FROM class PDF_Bookmark function Bookmark($txt,$level=0,$y=0) { $txt = $this->purify_utf8_text($txt); if ($this->text_input_as_HTML) { $txt = $this->all_entities_to_utf8($txt); } if($y==-1) { if (!$this->ColActive){ $y=$this->y; } else { $y = $this->y0; } // If columns are on - mark top of columns } // else y is used as set, or =0 i.e. top of page // DIRECTIONALITY RTL $bmo = array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->page); if ($this->keep_block_together) { $this->ktBMoutlines[]= $bmo; } /*-- TABLES --*/ else if ($this->table_rotate) { $this->tbrot_BMoutlines[]= $bmo; } else if ($this->kwt) { $this->kwt_BMoutlines[]= $bmo; } /*-- END TABLES --*/ else if ($this->ColActive) { // *COLUMNS* $this->col_BMoutlines[]= $bmo; // *COLUMNS* } // *COLUMNS* else { $this->BMoutlines[]= $bmo; } } function _putbookmarks() { $nb=count($this->BMoutlines); if($nb==0) return; $lru=array(); $level=0; foreach($this->BMoutlines as $i=>$o) { if($o['l']>0) { $parent=$lru[$o['l']-1]; //Set parent and last pointers $this->BMoutlines[$i]['parent']=$parent; $this->BMoutlines[$parent]['last']=$i; if($o['l']>$level) { //Level increasing: set first pointer $this->BMoutlines[$parent]['first']=$i; } } else $this->BMoutlines[$i]['parent']=$nb; if($o['l']<=$level and $i>0) { //Set prev and next pointers $prev=$lru[$o['l']]; $this->BMoutlines[$prev]['next']=$i; $this->BMoutlines[$i]['prev']=$prev; } $lru[$o['l']]=$i; $level=$o['l']; } //Outline items $n=$this->n+1; foreach($this->BMoutlines as $i=>$o) { $this->_newobj(); $this->_out('<</Title '.$this->_UTF16BEtextstring($o['t'])); $this->_out('/Parent '.($n+$o['parent']).' 0 R'); if(isset($o['prev'])) $this->_out('/Prev '.($n+$o['prev']).' 0 R'); if(isset($o['next'])) $this->_out('/Next '.($n+$o['next']).' 0 R'); if(isset($o['first'])) $this->_out('/First '.($n+$o['first']).' 0 R'); if(isset($o['last'])) $this->_out('/Last '.($n+$o['last']).' 0 R'); if (isset($this->pageDim[$o['p']]['h'])) { $h=$this->pageDim[$o['p']]['h']; } else { $h = 0; } $this->_out(sprintf('/Dest [%d 0 R /XYZ 0 %.3F null]',1+2*($o['p']),($h-$o['y'])*_MPDFK)); // mPDF 5.3.39 if (isset($this->bookmarkStyles) && isset($this->bookmarkStyles[$o['l']])) { // font style $bms = $this->bookmarkStyles[$o['l']]['style']; $style = 0; if (strpos($bms,'B') !== false) { $style += 2; } if (strpos($bms,'I') !== false) { $style += 1; } $this->_out(sprintf('/F %d', $style)); // Colour $col = $this->bookmarkStyles[$o['l']]['color']; if (isset($col) && is_array($col) && count($col)==3) { $this->_out(sprintf('/C [%.3F %.3F %.3F]', ($col[0]/255), ($col[1]/255), ($col[2]/255))); } } $this->_out('/Count 0>>'); $this->_out('endobj'); } //Outline root $this->_newobj(); $this->OutlineRoot=$this->n; $this->_out('<</Type /BMoutlines /First '.$n.' 0 R'); $this->_out('/Last '.($n+$lru[0]).' 0 R>>'); $this->_out('endobj'); } /*-- END BOOKMARKS --*/ // *BOOKMARKS* //====================================================== // DEPRACATED but included for backwards compatability function startPageNums() { } //====================================================== /*-- TOC --*/ // ToC TABLE OF CONTENTS // Initiate, and Mark a place for the Table of Contents to be inserted function TOC($tocfont='', $tocfontsize=8, $tocindent=5, $resetpagenum='', $pagenumstyle='', $suppress='', $toc_orientation='', $TOCusePaging=true, $TOCuseLinking=false, $toc_id=0) { if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); } if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); } $this->tocontents->TOC($tocfont, $tocfontsize, $tocindent, $resetpagenum, $pagenumstyle, $suppress, $toc_orientation, $TOCusePaging, $TOCuseLinking, $toc_id); } function TOCpagebreakByArray($a) { if (!is_array($a)) { $a = array(); } if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); } if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); } // mPDF 5.3.48 $tocfont = (isset($a['tocfont']) ? $a['tocfont'] : (isset($a['font']) ? $a['font'] : '')); $tocfontsize = (isset($a['tocfontsize']) ? $a['tocfontsize'] : (isset($a['font-size']) ? $a['font-size'] : '')); $tocindent = (isset($a['tocindent']) ? $a['tocindent'] : (isset($a['indent']) ? $a['indent'] : '')); $TOCusePaging = (isset($a['TOCusePaging']) ? $a['TOCusePaging'] : (isset($a['paging']) ? $a['paging'] : true)); $TOCuseLinking = (isset($a['TOCuseLinking']) ? $a['TOCuseLinking'] : (isset($a['links']) ? $a['links'] : '')); $toc_orientation = (isset($a['toc_orientation']) ? $a['toc_orientation'] : (isset($a['toc-orientation']) ? $a['toc-orientation'] : '')); $toc_mgl = (isset($a['toc_mgl']) ? $a['toc_mgl'] : (isset($a['toc-margin-left']) ? $a['toc-margin-left'] : '')); $toc_mgr = (isset($a['toc_mgr']) ? $a['toc_mgr'] : (isset($a['toc-margin-right']) ? $a['toc-margin-right'] : '')); $toc_mgt = (isset($a['toc_mgt']) ? $a['toc_mgt'] : (isset($a['toc-margin-top']) ? $a['toc-margin-top'] : '')); $toc_mgb = (isset($a['toc_mgb']) ? $a['toc_mgb'] : (isset($a['toc-margin-bottom']) ? $a['toc-margin-bottom'] : '')); $toc_mgh = (isset($a['toc_mgh']) ? $a['toc_mgh'] : (isset($a['toc-margin-header']) ? $a['toc-margin-header'] : '')); $toc_mgf = (isset($a['toc_mgf']) ? $a['toc_mgf'] : (isset($a['toc-margin-footer']) ? $a['toc-margin-footer'] : '')); $toc_ohname = (isset($a['toc_ohname']) ? $a['toc_ohname'] : (isset($a['toc-odd-header-name']) ? $a['toc-odd-header-name'] : '')); $toc_ehname = (isset($a['toc_ehname']) ? $a['toc_ehname'] : (isset($a['toc-even-header-name']) ? $a['toc-even-header-name'] : '')); $toc_ofname = (isset($a['toc_ofname']) ? $a['toc_ofname'] : (isset($a['toc-odd-footer-name']) ? $a['toc-odd-footer-name'] : '')); $toc_efname = (isset($a['toc_efname']) ? $a['toc_efname'] : (isset($a['toc-even-footer-name']) ? $a['toc-even-footer-name'] : '')); $toc_ohvalue = (isset($a['toc_ohvalue']) ? $a['toc_ohvalue'] : (isset($a['toc-odd-header-value']) ? $a['toc-odd-header-value'] : 0)); $toc_ehvalue = (isset($a['toc_ehvalue']) ? $a['toc_ehvalue'] : (isset($a['toc-even-header-value']) ? $a['toc-even-header-value'] : 0)); $toc_ofvalue = (isset($a['toc_ofvalue']) ? $a['toc_ofvalue'] : (isset($a['toc-odd-footer-value']) ? $a['toc-odd-footer-value'] : 0)); $toc_efvalue = (isset($a['toc_efvalue']) ? $a['toc_efvalue'] : (isset($a['toc-even-footer-value']) ? $a['toc-even-footer-value'] : 0)); $toc_preHTML = (isset($a['toc_preHTML']) ? $a['toc_preHTML'] : (isset($a['toc-preHTML']) ? $a['toc-preHTML'] : '')); $toc_postHTML = (isset($a['toc_postHTML']) ? $a['toc_postHTML'] : (isset($a['toc-postHTML']) ? $a['toc-postHTML'] : '')); $toc_bookmarkText = (isset($a['toc_bookmarkText']) ? $a['toc_bookmarkText'] : (isset($a['toc-bookmarkText']) ? $a['toc-bookmarkText'] : '')); $resetpagenum = (isset($a['resetpagenum']) ? $a['resetpagenum'] : ''); $pagenumstyle = (isset($a['pagenumstyle']) ? $a['pagenumstyle'] : ''); $suppress = (isset($a['suppress']) ? $a['suppress'] : ''); $orientation = (isset($a['orientation']) ? $a['orientation'] : ''); $mgl = (isset($a['mgl']) ? $a['mgl'] : (isset($a['margin-left']) ? $a['margin-left'] : '')); $mgr = (isset($a['mgr']) ? $a['mgr'] : (isset($a['margin-right']) ? $a['margin-right'] : '')); $mgt = (isset($a['mgt']) ? $a['mgt'] : (isset($a['margin-top']) ? $a['margin-top'] : '')); $mgb = (isset($a['mgb']) ? $a['mgb'] : (isset($a['margin-bottom']) ? $a['margin-bottom'] : '')); $mgh = (isset($a['mgh']) ? $a['mgh'] : (isset($a['margin-header']) ? $a['margin-header'] : '')); $mgf = (isset($a['mgf']) ? $a['mgf'] : (isset($a['margin-footer']) ? $a['margin-footer'] : '')); $ohname = (isset($a['ohname']) ? $a['ohname'] : (isset($a['odd-header-name']) ? $a['odd-header-name'] : '')); $ehname = (isset($a['ehname']) ? $a['ehname'] : (isset($a['even-header-name']) ? $a['even-header-name'] : '')); $ofname = (isset($a['ofname']) ? $a['ofname'] : (isset($a['odd-footer-name']) ? $a['odd-footer-name'] : '')); $efname = (isset($a['efname']) ? $a['efname'] : (isset($a['even-footer-name']) ? $a['even-footer-name'] : '')); $ohvalue = (isset($a['ohvalue']) ? $a['ohvalue'] : (isset($a['odd-header-value']) ? $a['odd-header-value'] : 0)); $ehvalue = (isset($a['ehvalue']) ? $a['ehvalue'] : (isset($a['even-header-value']) ? $a['even-header-value'] : 0)); $ofvalue = (isset($a['ofvalue']) ? $a['ofvalue'] : (isset($a['odd-footer-value']) ? $a['odd-footer-value'] : 0)); $efvalue = (isset($a['efvalue']) ? $a['efvalue'] : (isset($a['even-footer-value']) ? $a['even-footer-value'] : 0)); $toc_id = (isset($a['toc_id']) ? $a['toc_id'] : (isset($a['name']) ? $a['name'] : 0)); $pagesel = (isset($a['pagesel']) ? $a['pagesel'] : (isset($a['pageselector']) ? $a['pageselector'] : '')); $toc_pagesel = (isset($a['toc_pagesel']) ? $a['toc_pagesel'] : (isset($a['toc-pageselector']) ? $a['toc-pageselector'] : '')); $sheetsize = (isset($a['sheetsize']) ? $a['sheetsize'] : (isset($a['sheet-size']) ? $a['sheet-size'] : '')); $toc_sheetsize = (isset($a['toc_sheetsize']) ? $a['toc_sheetsize'] : (isset($a['toc-sheet-size']) ? $a['toc-sheet-size'] : '')); $this->tocontents->TOCpagebreak($tocfont, $tocfontsize, $tocindent, $TOCusePaging, $TOCuseLinking, $toc_orientation, $toc_mgl, $toc_mgr, $toc_mgt, $toc_mgb, $toc_mgh, $toc_mgf, $toc_ohname, $toc_ehname, $toc_ofname, $toc_efname, $toc_ohvalue, $toc_ehvalue, $toc_ofvalue, $toc_efvalue, $toc_preHTML, $toc_postHTML, $toc_bookmarkText, $resetpagenum, $pagenumstyle, $suppress, $orientation, $mgl, $mgr, $mgt, $mgb, $mgh, $mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue, $toc_id, $pagesel, $toc_pagesel, $sheetsize, $toc_sheetsize); } function TOCpagebreak($tocfont='', $tocfontsize='', $tocindent='', $TOCusePaging=true, $TOCuseLinking='', $toc_orientation='', $toc_mgl='',$toc_mgr='',$toc_mgt='',$toc_mgb='',$toc_mgh='',$toc_mgf='',$toc_ohname='',$toc_ehname='',$toc_ofname='',$toc_efname='',$toc_ohvalue=0,$toc_ehvalue=0,$toc_ofvalue=0, $toc_efvalue=0, $toc_preHTML='', $toc_postHTML='', $toc_bookmarkText='', $resetpagenum='', $pagenumstyle='', $suppress='', $orientation='', $mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0, $toc_id=0, $pagesel='', $toc_pagesel='', $sheetsize='', $toc_sheetsize='') { if (!class_exists('tocontents', false)) { include(_MPDF_PATH.'classes/tocontents.php'); } if (empty($this->tocontents)) { $this->tocontents = new tocontents($this); } //Start a new page if($this->state==0) $this->AddPage(); if ($this->y == $this->tMargin && (!$this->mirrorMargins ||($this->mirrorMargins && $this->page % 2==1))) { // Don't add a page if ($this->page==1 && count($this->PageNumSubstitutions)==0) { if (!$suppress) { $suppress = 'off'; } if (!$resetpagenum) { $resetpagenum= 1; } //$this->PageNumSubstitutions[] = array('from'=>1, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=> $suppress); } $this->PageNumSubstitutions[] = array('from'=>$this->page, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=> $suppress); } else { $this->AddPage($orientation,'NEXT-ODD', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$sheetsize); } $this->tocontents->TOCpagebreak($tocfont, $tocfontsize, $tocindent, $TOCusePaging, $TOCuseLinking, $toc_orientation, $toc_mgl, $toc_mgr, $toc_mgt, $toc_mgb, $toc_mgh, $toc_mgf, $toc_ohname, $toc_ehname, $toc_ofname, $toc_efname, $toc_ohvalue, $toc_ehvalue, $toc_ofvalue, $toc_efvalue, $toc_preHTML, $toc_postHTML, $toc_bookmarkText, $resetpagenum, $pagenumstyle, $suppress, $orientation, $mgl, $mgr, $mgt, $mgb, $mgh, $mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue, $toc_id, $pagesel, $toc_pagesel, $sheetsize, $toc_sheetsize); } function TOC_Entry($txt, $level=0, $toc_id=0) { $txt = $this->purify_utf8_text($txt); if ($this->text_input_as_HTML) { $txt = $this->all_entities_to_utf8($txt); } if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); } if ($this->ColActive) { $ily = $this->y0; } else { $ily = $this->y; } // use top of columns $linkn = $this->AddLink(); $this->SetLink($linkn,$ily,$this->page); /*-- RTL --*/ if ($this->biDirectional) { $txt = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $txt ); } /*-- END RTL --*/ if (strtoupper($toc_id)=='ALL') { $toc_id = '_mpdf_all'; } else if (!$toc_id) { $toc_id = 0; } else { $toc_id = strtolower($toc_id); } $btoc = array('t'=>$txt,'l'=>$level,'p'=>$this->page, 'link'=>$linkn, 'toc_id'=>$toc_id); if ($this->keep_block_together) { $this->_kttoc[]= $btoc; } /*-- TABLES --*/ else if ($this->table_rotate) { $this->tbrot_toc[]= $btoc; } else if ($this->kwt) { $this->kwt_toc[]= $btoc; } /*-- END TABLES --*/ else if ($this->ColActive) { // *COLUMNS* $this->col_toc[]= $btoc; // *COLUMNS* } // *COLUMNS* else { $this->tocontents->_toc[]= $btoc; } } /*-- END TOC --*/ //====================================================== function MovePages($target_page, $start_page, $end_page=-1) { // move a page/pages EARLIER in the document if ($end_page<1) { $end_page = $start_page; } $n_toc = $end_page - $start_page + 1; // Set/Update PageNumSubstitutions changes before moving anything if (count($this->PageNumSubstitutions)) { $tp_present = false; $sp_present = false; $ep_present = false; foreach($this->PageNumSubstitutions AS $k=>$v) { if ($this->PageNumSubstitutions[$k]['from']==$target_page) { $tp_present = true; if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) { $this->PageNumSubstitutions[$k]['suppress']='off'; } } if ($this->PageNumSubstitutions[$k]['from']==$start_page) { $sp_present = true; if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) { $this->PageNumSubstitutions[$k]['suppress']='off'; } } if ($this->PageNumSubstitutions[$k]['from']==($end_page+1)) { $ep_present = true; if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) { $this->PageNumSubstitutions[$k]['suppress']='off'; } } } if (!$tp_present) { list($tp_type, $tp_suppress, $tp_reset) = $this->docPageSettings($target_page); } if (!$sp_present) { list($sp_type, $sp_suppress, $sp_reset) = $this->docPageSettings($start_page); } if (!$ep_present) { list($ep_type, $ep_suppress, $ep_reset) = $this->docPageSettings($start_page-1); } } $last = array(); //store pages for($i = $start_page;$i <= $end_page ;$i++) $last[]=$this->pages[$i]; //move pages for($i=$start_page - 1;$i>=($target_page);$i--) { $this->pages[$i+$n_toc]=$this->pages[$i]; } //Put toc pages at insert point for($i = 0;$i < $n_toc;$i++) { $this->pages[$target_page + $i]=$last[$i]; } /*-- BOOKMARKS --*/ // Update Bookmarks foreach($this->BMoutlines as $i=>$o) { if($o['p']>=$target_page) { $this->BMoutlines[$i]['p'] += $n_toc; } } /*-- END BOOKMARKS --*/ // Update Page Links if (count($this->PageLinks)) { $newarr = array(); foreach($this->PageLinks as $i=>$o) { foreach($this->PageLinks[$i] as $key => $pl) { if (strpos($pl[4],'@')===0) { $p=substr($pl[4],1); if($p>=$start_page && $p<=$end_page) { $this->PageLinks[$i][$key][4] = '@'.($p + ($target_page - $start_page)); } else if($p>=$target_page && $p<$start_page) { $this->PageLinks[$i][$key][4] = '@'.($p+$n_toc); } } } if($i>=$start_page && $i<=$end_page) { $newarr[($i + ($target_page - $start_page))] = $this->PageLinks[$i]; } else if($i>=$target_page && $i<$start_page) { $newarr[($i + $n_toc)] = $this->PageLinks[$i]; } else { $newarr[$i] = $this->PageLinks[$i]; } } $this->PageLinks = $newarr; } // OrientationChanges if (count($this->OrientationChanges)) { $newarr = array(); foreach($this->OrientationChanges AS $p=>$v) { if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->OrientationChanges[$p]; } else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->OrientationChanges[$p]; } else { $newarr[$p] = $this->OrientationChanges[$p]; } } ksort($newarr); $this->OrientationChanges = $newarr; } // Page Dimensions if (count($this->pageDim)) { $newarr = array(); foreach($this->pageDim AS $p=>$v) { if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->pageDim[$p]; } else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->pageDim[$p]; } else { $newarr[$p] = $this->pageDim[$p]; } } ksort($newarr); $this->pageDim = $newarr; } // HTML Headers & Footers if (count($this->saveHTMLHeader)) { $newarr = array(); foreach($this->saveHTMLHeader AS $p=>$v) { if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->saveHTMLHeader[$p]; } else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->saveHTMLHeader[$p]; } else { $newarr[$p] = $this->saveHTMLHeader[$p]; } } ksort($newarr); $this->saveHTMLHeader = $newarr; } if (count($this->saveHTMLFooter)) { $newarr = array(); foreach($this->saveHTMLFooter AS $p=>$v) { if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->saveHTMLFooter[$p]; } else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->saveHTMLFooter[$p]; } else { $newarr[$p] = $this->saveHTMLFooter[$p]; } } ksort($newarr); $this->saveHTMLFooter = $newarr; } // Update Internal Links if (count($this->internallink)) { foreach($this->internallink as $key=>$o) { if($o['PAGE']>=$start_page && $o['PAGE']<=$end_page) { $this->internallink[$key]['PAGE'] += ($target_page - $start_page); } else if($o['PAGE']>=$target_page && $o['PAGE']<$start_page) { $this->internallink[$key]['PAGE'] += $n_toc; } } } // Update Links if (count($this->links)) { foreach($this->links as $key=>$o) { if($o[0]>=$start_page && $o[0]<=$end_page) { $this->links[$key][0] += ($target_page - $start_page); } if($o[0]>=$target_page && $o[0]<$start_page) { $this->links[$key][0] += $n_toc; } } } // Update Form fields if (count($this->form->forms)) { foreach($this->form->forms as $key=>$f) { if($f['page']>=$start_page && $f['page']<=$end_page) { $this->form->forms[$key]['page'] += ($target_page - $start_page); } if($f['page']>=$target_page && $f['page']<$start_page) { $this->form->forms[$key]['page'] += $n_toc; } } } /*-- ANNOTATIONS --*/ // Update Annotations if (count($this->PageAnnots)) { $newarr = array(); foreach($this->PageAnnots as $p=>$anno) { if($p>=$start_page && $p<=$end_page) { $np = $p + ($target_page - $start_page); foreach($anno as $o) { $newarr[$np][] = $o; } } else if($p>=$target_page && $p<$start_page) { $np = $p + $n_toc; foreach($anno as $o) { $newarr[$np][] = $o; } } else { $newarr[$p] = $this->PageAnnots[$p]; } } $this->PageAnnots = $newarr; unset($newarr); } /*-- END ANNOTATIONS --*/ // Update PageNumSubstitutions if (count($this->PageNumSubstitutions)) { $newarr = array(); foreach($this->PageNumSubstitutions AS $k=>$v) { if($this->PageNumSubstitutions[$k]['from']>=$start_page && $this->PageNumSubstitutions[$k]['from']<=$end_page) { $this->PageNumSubstitutions[$k]['from'] += ($target_page - $start_page); $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k]; } else if($this->PageNumSubstitutions[$k]['from']>=$target_page && $this->PageNumSubstitutions[$k]['from']<$start_page) { $this->PageNumSubstitutions[$k]['from'] += $n_toc; $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k]; } else { $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k]; } } if (!$sp_present) { $newarr[$target_page] = array('from'=>$target_page, 'suppress'=>$sp_suppress, 'reset'=>$sp_reset, 'type'=>$sp_type); } if (!$tp_present) { $newarr[($target_page + $n_toc)] = array('from'=>($target_page+$n_toc), 'suppress'=>$tp_suppress, 'reset'=>$tp_reset, 'type'=>$tp_type); } if (!$ep_present && $end_page>count($this->pages)) { $newarr[($end_page+1)] = array('from'=>($end_page+1), 'suppress'=>$ep_suppress, 'reset'=>$ep_reset, 'type'=>$ep_type); } ksort($newarr); $this->PageNumSubstitutions = array(); foreach($newarr as $v) { $this->PageNumSubstitutions[] = $v; } } } //====================================================== function DeletePages($start_page, $end_page=-1) { // move a page/pages EARLIER in the document if ($end_page<1) { $end_page = $start_page; } $n_tod = $end_page - $start_page + 1; $last_page = count($this->pages); $n_atend = $last_page - $end_page + 1; //move pages for($i=0;$i<$n_atend;$i++) { $this->pages[$start_page+$i]=$this->pages[$end_page+1+$i]; } //delete pages for($i = 0;$i < $n_tod ;$i++) unset($this->pages[$last_page-$i]); /*-- BOOKMARKS --*/ // Update Bookmarks foreach($this->BMoutlines as $i=>$o) { if($o['p']>=$end_page) { $this->BMoutlines[$i]['p'] -= $n_tod; } else if($p<$start_page) { unset($this->BMoutlines[$i]); } } /*-- END BOOKMARKS --*/ // Update Page Links if (count($this->PageLinks)) { $newarr = array(); foreach($this->PageLinks as $i=>$o) { foreach($this->PageLinks[$i] as $key => $pl) { if (strpos($pl[4],'@')===0) { $p=substr($pl[4],1); if($p>$end_page) { $this->PageLinks[$i][$key][4] = '@'.($p - $n_tod); } else if($p<$start_page) { unset($this->PageLinks[$i][$key]); } } } if($i>$end_page) { $newarr[($i - $n_tod)] = $this->PageLinks[$i]; } else if($p<$start_page) { $newarr[$i] = $this->PageLinks[$i]; } } $this->PageLinks = $newarr; } // OrientationChanges if (count($this->OrientationChanges)) { $newarr = array(); foreach($this->OrientationChanges AS $p=>$v) { if($p>$end_page) { $newarr[($p - $t_tod)] = $this->OrientationChanges[$p]; } else if($p<$start_page) { $newarr[$p] = $this->OrientationChanges[$p]; } } ksort($newarr); $this->OrientationChanges = $newarr; } // Page Dimensions if (count($this->pageDim)) { $newarr = array(); foreach($this->pageDim AS $p=>$v) { if($p>$end_page) { $newarr[($p - $n_tod)] = $this->pageDim[$p]; } else if($p<$start_page) { $newarr[$p] = $this->pageDim[$p]; } } ksort($newarr); $this->pageDim = $newarr; } // HTML Headers & Footers if (count($this->saveHTMLHeader)) { foreach($this->saveHTMLHeader AS $p=>$v) { if($p>end_page) { $newarr[($p - $n_tod)] = $this->saveHTMLHeader[$p]; } else if($p<$start_page) { $newarr[$p] = $this->saveHTMLHeader[$p]; } } ksort($newarr); $this->saveHTMLHeader = $newarr; } if (count($this->saveHTMLFooter)) { $newarr = array(); foreach($this->saveHTMLFooter AS $p=>$v) { if($p>$end_page) { $newarr[($p - $n_tod)] = $this->saveHTMLFooter[$p]; } else if($p<$start_page) { $newarr[$p] = $this->saveHTMLFooter[$p]; } } ksort($newarr); $this->saveHTMLFooter = $newarr; } // Update Internal Links foreach($this->internallink as $key=>$o) { if($o['PAGE']>$end_page) { $this->internallink[$key]['PAGE'] -= $n_tod; } else if($o['PAGE']<$start_page) { unset($this->internallink[$key]); } } // Update Links foreach($this->links as $key=>$o) { if($o[0]>$end_page) { $this->links[$key][0] -= $n_tod; } else if($o[0]<$start_page) { unset($this->links[$key]); } } // Update Form fields foreach($this->form->forms as $key=>$f) { if($f['page']>$end_page) { $this->form->forms[$key]['page'] -= $n_tod; } else if($f['page']<$start_page) { unset($this->form->forms[$key]); } } /*-- ANNOTATIONS --*/ // Update Annotations if (count($this->PageAnnots)) { $newarr = array(); foreach($this->PageAnnots as $p=>$anno) { if($p>$end_page) { foreach($anno as $o) { $newarr[($p - $n_tod)][] = $o; } } else if($p<$start_page) { $newarr[$p] = $this->PageAnnots[$p]; } } ksort($newarr); $this->PageAnnots = $newarr; } /*-- END ANNOTATIONS --*/ // Update PageNumSubstitutions foreach($this->PageNumSubstitutions AS $k=>$v) { if($this->PageNumSubstitutions[$k]['from']>$end_page) { $this->PageNumSubstitutions[$k]['from'] -= $n_tod; } else if($this->PageNumSubstitutions[$k]['from']<$start_page) { unset($this->PageNumSubstitutions[$k]); } } unset($newarr); $this->page = count($this->pages); } //====================================================== /*-- INDEX --*/ // FROM class PDF_Ref == INDEX function Reference($txt) { $this->IndexEntry($txt); } function IndexEntry($txt, $xref='') { if ($xref) { $this->IndexEntrySee($txt,$xref); return; } $txt = strip_tags($txt); $txt = $this->purify_utf8_text($txt); if ($this->text_input_as_HTML) { $txt = $this->all_entities_to_utf8($txt); } if ($this->usingCoreFont) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); } $Present=0; $size=sizeof($this->Reference); if ($this->directionality == 'rtl') { // *RTL* $txt = str_replace(':',' - ',$txt); // *RTL* } // *RTL* else { // *RTL* $txt = str_replace(':',', ',$txt); } // *RTL* //Search the reference (AND Ref/PageNo) in the array for ($i=0;$i<$size;$i++){ if ($this->keep_block_together) { if (isset($this->ktReference[$i]['t']) && $this->ktReference[$i]['t']==$txt){ $Present=1; if (!in_array($this->page,$this->ktReference[$i]['p'])) { $this->ktReference[$i]['op'] = $this->page; } } } /*-- TABLES --*/ else if ($this->table_rotate) { if (isset($this->tbrot_Reference[$i]['t']) && $this->tbrot_Reference[$i]['t']==$txt){ $Present=1; if (!in_array($this->page,$this->tbrot_Reference[$i]['p'])) { $this->tbrot_Reference[$i]['op'] = $this->page; } } } else if ($this->kwt) { if (isset($this->kwt_Reference[$i]['t']) && $this->kwt_Reference[$i]['t']==$txt){ $Present=1; if (!in_array($this->page,$this->kwt_Reference[$i]['p'])) { $this->kwt_Reference[$i]['op'] = $this->page; } } } /*-- END TABLES --*/ /*-- COLUMNS --*/ else if ($this->ColActive) { if (isset($this->col_Reference[$i]['t']) && $this->col_Reference[$i]['t']==$txt){ $Present=1; if (!in_array($this->page,$this->col_Reference[$i]['p'])) { $this->col_Reference[$i]['op'] = $this->page; } } } /*-- END COLUMNS --*/ else { if (isset($this->Reference[$i]['t']) && $this->Reference[$i]['t']==$txt){ $Present=1; if (!in_array($this->page,$this->Reference[$i]['p'])) { $this->Reference[$i]['p'][] = $this->page; } } } } //If not found, add it if ($Present==0) { $opr = array('t'=>$txt, 'op'=>$this->page); if ($this->keep_block_together) { $this->ktReference[]= $opr; } /*-- TABLES --*/ else if ($this->table_rotate) { $this->tbrot_Reference[]= $opr; } else if ($this->kwt) { $this->kwt_Reference[]= $opr; } /*-- END TABLES --*/ /*-- COLUMNS --*/ else if ($this->ColActive) { $this->col_Reference[]= $opr; } /*-- END COLUMNS --*/ else { $this->Reference[]=array('t'=>$txt,'p'=>array($this->page)); } } } // Added function to add a reference "Elephants. See Chickens" function ReferenceSee($txta,$txtb) { $this->IndexEntrySee($txta,$txtb); } function IndexEntrySee($txta,$txtb) { $txta = strip_tags($txta); $txtb = strip_tags($txtb); $txta = $this->purify_utf8_text($txta); $txtb = $this->purify_utf8_text($txtb); if ($this->text_input_as_HTML) { $txta = $this->all_entities_to_utf8($txta); $txtb = $this->all_entities_to_utf8($txtb); } if ($this->usingCoreFont) { $txta = mb_convert_encoding($txta,$this->mb_enc,'UTF-8'); $txtb = mb_convert_encoding($txtb,$this->mb_enc,'UTF-8'); } if ($this->directionality == 'rtl') { // *RTL* $txta = str_replace(':',' - ',$txta); // *RTL* $txtb = str_replace(':',' - ',$txtb); // *RTL* } // *RTL* else { // *RTL* $txta = str_replace(':',', ',$txta); $txtb = str_replace(':',', ',$txtb); } // *RTL* $this->Reference[]=array('t'=>$txta.' - see '.$txtb,'p'=>array()); } function CreateReference($NbCol=1, $reffontsize='', $linespacing='', $offset=3, $usedivletters=1, $divlettfontsize='', $gap=5, $reffont='',$divlettfont='', $useLinking=false) { $this->CreateIndex($NbCol, $reffontsize, $linespacing, $offset, $usedivletters, $divlettfontsize, $gap, $reffont, $divlettfont, $useLinking); } function CreateIndex($NbCol=1, $reffontsize='', $linespacing='', $offset=3, $usedivletters=1, $divlettfontsize='', $gap=5, $reffont='',$divlettfont='', $useLinking=false) { if (!$reffontsize) { $reffontsize = $this->default_font_size; } if (!$divlettfontsize) { $divlettfontsize = ($this->default_font_size * 1.8); } if (!$reffont) { $reffont = $this->default_font; } if (!$divlettfont) { $divlettfont = $reffont; } if (!$linespacing) { $linespacing= $this->default_lineheight_correction; } if ($this->ColActive) { $this->SetColumns(0); } // *COLUMNS* $size=sizeof($this->Reference); if ($size == 0) { return false; } if ($NbCol<2) { $NbCol = 1; $colWidth = $this->pgwidth; } else { $this->SetColumns($NbCol,'',$gap); $colWidth = $this->ColWidth; } if ($this->directionality == 'rtl') { $align = 'R'; } else { $align = 'L'; } $lett = ''; if (!function_exists('cmp')) { // mPDF 5.3.07 function cmp ($a, $b) { return strnatcmp(strtolower($a['t']), strtolower($b['t'])); } } //Alphabetic sort of the references usort($this->Reference, 'cmp'); $size=sizeof($this->Reference); $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS* $divlettjuststarted = false; $this->OpenTag('DIV',array('STYLE'=>'line-height: '.$linespacing.'; font-family: '.$reffont.'; font-size: '.$reffontsize.'pt; ')); $last_lett = ''; for ($i=0;$i<$size;$i++){ if ($this->Reference[$i]['t']) { if ($usedivletters) { $lett = mb_strtoupper(mb_substr($this->Reference[$i]['t'],0,1,$this->mb_enc ),$this->mb_enc ); if ($lett != $last_lett) { $save_bp = $this->breakpoints[$this->CurrCol]; // *COLUMNS* $divlettjuststarted = true; if ($i>0) { $this->OpenTag('DIV',array('STYLE'=>'line-height: '.$linespacing.'; font-family: '.$divlettfont.'; font-size: '.$divlettfontsize.'pt; font-weight: bold; page-break-after: avoid; margin-top: 0.5em; margin-collapse: collapse; ')); } else { $this->OpenTag('DIV',array('STYLE'=>'line-height: '.$linespacing.'; font-family: '.$divlettfont.'; font-size: '.$divlettfontsize.'pt; font-weight: bold; page-break-after: avoid; ')); } $this->_saveTextBuffer($lett); // mPDF 5.3.99 $this->CloseTag('DIV'); } } $this->OpenTag('DIV',array('STYLE'=>'text-indent: -'.$offset.'mm; line-height: '.$linespacing.'; font-family: '.$reffont.'; font-size: '.$reffontsize.'pt; ')); /*-- RTL --*/ // Change Arabic + Persian. to Presentation Forms if ($this->biDirectional) { $this->Reference[$i]['t'] = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $this->Reference[$i]['t'] ); } /*-- END RTL --*/ // Font-specific ligature substitution for Indic fonts if (isset($this->CurrentFont['indic']) && $this->CurrentFont['indic']) $this->ConvertIndic($this->Reference[$i]['t']); // *INDIC* $this->_saveTextBuffer($this->Reference[$i]['t']); // mPDF 5.3.99 $ppp = $this->Reference[$i]['p']; // = array of page numbers to point to if (count($ppp)) { sort($ppp); $newarr = array(); $range_start = $ppp[0]; $range_end = 0; if (!$this->usingCoreFont) { $spacer = "\xc2\xa0 "; } else { $spacer = chr(160).' '; } $this->_saveTextBuffer($spacer); // mPDF 5.3.99 if ($this->directionality == 'rtl') { $sep = '.'; $joiner = '-'; } else { $sep = ', '; $joiner = '-'; } for ($zi=1;$zi<count($ppp);$zi++) { // RTL - Each number separately if ($this->directionality == 'rtl') { /*-- RTL --*/ if ($zi<count($ppp)-1) { $txt = $sep . $this->docPageNum($ppp[$zi]); if ($useLinking) { $href = '@'.$ppp[$zi]; } else { $href = ''; } $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99 } /*-- END RTL --*/ } else if ($ppp[$zi] == ($ppp[($zi-1)]+1)) { $range_end = $ppp[$zi]; } else { if ($range_end) { if ($range_end == $range_start+1) { if ($useLinking) { $href = '@'.$range_start; } else { $href = ''; } $txt = $this->docPageNum($range_start) . $sep; $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99 if ($useLinking) { $href = '@'.$ppp[$zi-1]; } else { $href = ''; } $txt = $this->docPageNum($ppp[$zi-1]) . $sep; $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99 } else { if ($useLinking) { $href = '@'.$range_start; } else { $href = ''; } } } else { if ($useLinking) { $href = '@'.$ppp[$zi-1]; } else { $href = ''; } $txt = $this->docPageNum($ppp[$zi-1]) . $sep; $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99 } $range_start = $ppp[$zi]; $range_end = 0; } } if ($range_end) { if ($range_end == $range_start+1) { if ($useLinking) { $href = '@'.$range_start; } else { $href = ''; } $txt = $this->docPageNum($range_start) . $sep; $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99 if ($useLinking) { $href = '@'.$range_end; } else { $href = ''; } $txt = $this->docPageNum($range_end); $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99 } else { if ($useLinking) { $href = '@'.$range_start; } else { $href = ''; } $txt = $this->docPageNum($range_start) . $joiner; $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99 if ($useLinking) { $href = '@'.$range_end; } else { $href = ''; } $txt = $this->docPageNum($range_end); $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99 } } else { if ($useLinking) { $href = '@'.$ppp[(count($ppp)-1)]; } else { $href = ''; } $txt = $this->docPageNum($ppp[(count($ppp)-1)]); $this->_saveTextBuffer($txt, $href); // mPDF 5.3.99 } } } $this->CloseTag('DIV'); if ($divlettjuststarted) { $this->breakpoints[$this->CurrCol] = $save_bp; } // *COLUMNS* $divlettjuststarted = false; $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS* $last_lett = $lett; } $this->CloseTag('DIV'); $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS* if ($this->ColActive) { $this->SetColumns(0); } // *COLUMNS* } /*-- END INDEX --*/ function AcceptPageBreak() { if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); } // *TABLES* /*-- COLUMNS --*/ if ($this->ColActive==1) { if($this->CurrCol<$this->NbCol-1) { //Go to the next column $this->CurrCol++; $this->SetCol($this->CurrCol); $this->y=$this->y0; $this->ChangeColumn=1; // Number (and direction) of columns changed +1, +2, -2 etc. // DIRECTIONALITY RTL if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL* //Stay on the page return false; } else { //Go back to the first column - NEW PAGE if (count($this->columnbuffer)) { $this->printcolumnbuffer(); } $this->SetCol(0); $this->y0 = $this->tMargin; $this->ChangeColumn= -($this->NbCol-1); // DIRECTIONALITY RTL if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL* //Page break return true; } } /*-- END COLUMNS --*/ /*-- TABLES --*/ else if ($this->table_rotate) { if ($this->tablebuffer) { $this->printtablebuffer(); } return true; } /*-- END TABLES --*/ else { // *COLUMNS* $this->ChangeColumn=0; return $this->autoPageBreak; } // *COLUMNS* return $this->autoPageBreak; } //----------- COLUMNS --------------------- /*-- COLUMNS --*/ function SetColumns($NbCol,$vAlign='',$gap=5) { // NbCol = number of columns // CurrCol = Number of the current column starting at 0 // Called externally to set columns on/off and number // Integer 2 upwards sets columns on to that number // Anything less than 2 turns columns off if ($NbCol<2) { // SET COLUMNS OFF if ($this->ColActive) { $this->ColActive=0; if (count($this->columnbuffer)) { $this->printcolumnbuffer(); } $this->NbCol=1; $this->ResetMargins(); $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $this->divwidth = 0; $this->Ln(); } $this->ColActive=0; $this->columnbuffer = array(); $this->ColDetails = array(); $this->columnLinks = array(); $this->columnAnnots = array(); $this->columnForms = array(); $this->col_Reference = array(); $this->col_BMoutlines = array(); $this->col_toc = array(); $this->breakpoints = array(); } else { // SET COLUMNS ON if ($this->ColActive) { $this->ColActive=0; if (count($this->columnbuffer)) { $this->printcolumnbuffer(); } $this->ResetMargins(); } if (isset($this->y) && $this->y>$this->tMargin) $this->Ln(); $this->NbCol=$NbCol; $this->ColGap = $gap; $this->divwidth = 0; $this->ColActive=1; $this->ColumnAdjust = true; // enables column height adjustment for the page $this->columnbuffer = array(); $this->ColDetails = array(); $this->columnLinks = array(); $this->columnAnnots = array(); $this->columnForms = array(); $this->col_Reference = array(); $this->col_BMoutlines = array(); $this->col_toc = array(); $this->breakpoints = array(); if ((strtoupper($vAlign) == 'J') || (strtoupper($vAlign) == 'JUSTIFY')) { $vAlign = 'J'; } else { $vAlign = ''; } $this->colvAlign = $vAlign; //Save the ordinate $absL = $this->DeflMargin-($gap/2); $absR = $this->DefrMargin-($gap/2); $PageWidth = $this->w-$absL-$absR; // virtual pagewidth for calculation only $ColWidth = (($PageWidth - ($gap * ($NbCol)))/$NbCol); $this->ColWidth = $ColWidth; /*-- RTL --*/ if ($this->directionality == 'rtl') { for ($i=0;$i<$this->NbCol;$i++) { $this->ColL[$i] = $absL + ($gap/2) + (($NbCol - ($i+1))*($PageWidth/$NbCol)) ; $this->ColR[$i] = $this->ColL[$i] + $ColWidth; // NB This is not R margin -> R pos } } else { /*-- END RTL --*/ for ($i=0;$i<$this->NbCol;$i++) { $this->ColL[$i] = $absL + ($gap/2) + ($i* ($PageWidth/$NbCol) ); $this->ColR[$i] = $this->ColL[$i] + $ColWidth; // NB This is not R margin -> R pos } } // *RTL* $this->pgwidth = $ColWidth; $this->SetCol(0); $this->y0=$this->y; } $this->x = $this->lMargin; } function SetCol($CurrCol) { // Used internally to set column by number: 0 is 1st column //Set position on a column $this->CurrCol=$CurrCol; $x = $this->ColL[$CurrCol]; $xR = $this->ColR[$CurrCol]; // NB This is not R margin -> R pos if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN $x += $this->MarginCorrection ; $xR += $this->MarginCorrection ; } $this->SetMargins($x,($this->w - $xR),$this->tMargin); } function AddColumn() { $this->NewColumn(); $this->ColumnAdjust = false; // disables all column height adjustment for the page. } function NewColumn() { if ($this->ColActive==1) { if($this->CurrCol<$this->NbCol-1) { //Go to the next column $this->CurrCol++; $this->SetCol($this->CurrCol); $this->y = $this->y0; $this->ChangeColumn=1; // DIRECTIONALITY RTL if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL* //Stay on the page } else { //Go back to the first column //Page break if (count($this->columnbuffer)) { $this->printcolumnbuffer(); } $this->AddPage($this->CurOrientation); $this->SetCol(0); $this->y0 = $this->tMargin; $this->ChangeColumn= -($this->NbCol-1); // DIRECTIONALITY RTL if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL* } $this->x = $this->lMargin; } else { $this->AddPage($this->CurOrientation); } } function printcolumnbuffer() { // Columns ended (but page not ended) -> try to match all columns - unless disabled by using a custom column-break if (!$this->ColActive && $this->ColumnAdjust && !$this->keepColumns) { // Calculate adjustment to add to each column to calculate rel_y value $this->ColDetails[0]['add_y'] = 0; $last_col = 0; // Recursively add previous column's height for($i=1;$i<$this->NbCol;$i++) { if (isset($this->ColDetails[$i]['bottom_margin']) && $this->ColDetails[$i]['bottom_margin']) { // If any entries in the column $this->ColDetails[$i]['add_y'] = ($this->ColDetails[$i-1]['bottom_margin'] - $this->y0) + $this->ColDetails[$i-1]['add_y']; $last_col = $i; // Last column actually printed } } // Calculate value for each position sensitive entry as though for one column foreach($this->columnbuffer AS $key=>$s) { $t = $s['s']; if ($t == 'ACROFORM') { $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0; $this->columnbuffer[$key]['s'] = ''; } else if (preg_match('/BT \d+\.\d\d+ (\d+\.\d\d+) Td/',$t)) { $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0; } else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ [\-]{0,1}\d+\.\d\d+ re/',$t)) { $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0; } else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) { $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0; } else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) { $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0; } else if (preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+ (\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/',$t)) { $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0; } else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) { $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0; } } // mPDF 5.3.01 foreach($this->internallink AS $key => $f) { if (is_array($f) && isset($f['col'])) { $this->internallink[$key]['rel_y'] = $f['Y'] + $this->ColDetails[$f['col']]['add_y'] - $this->y0; } } $breaks = array(); foreach($this->breakpoints AS $c => $bpa) { foreach($bpa AS $rely) { $breaks[] = $rely + $this->ColDetails[$c]['add_y'] - $this->y0; } } if (isset($this->ColDetails[$last_col]['bottom_margin'])) { $lcbm = $this->ColDetails[$last_col]['bottom_margin']; } else { $lcbm = 0; } $sum_h = $this->ColDetails[$last_col]['add_y'] + $lcbm - $this->y0; //$sum_h = max($this->ColDetails[$last_col]['add_y'] + $this->ColDetails[$last_col]['bottom_margin'] - $this->y0, end($breaks)); $target_h = ($sum_h / $this->NbCol); $cbr = array(); for($i=1;$i<$this->NbCol;$i++) { $th = ($sum_h * $i / $this->NbCol); foreach($breaks AS $bk=>$val) { if ($val > $th) { if (($val-$th) < ($th-$breaks[$bk-1])) { $cbr[$i-1] = $val; } else { $cbr[$i-1] = $breaks[$bk-1]; } break; } } } $cbr[($this->NbCol-1)] = $sum_h; // Now update the columns - divide into columns of approximately equal value $last_new_col = 0; $yadj = 0; // mm $xadj = 0; $last_col_bottom = 0; $lowest_bottom_y = 0; $block_bottom = 0; $newcolumn = 0; foreach($this->columnbuffer AS $key=>$s) { if (isset($s['rel_y'])) { // only process position sensitive data if ($s['rel_y'] >= $cbr[$newcolumn]) { $newcolumn++; } else { $newcolumn = $last_new_col ; } $block_bottom = max($block_bottom,($s['rel_y']+$s['h'])); if ($this->directionality == 'rtl') { // *RTL* $xadj = -(($newcolumn - $s['col']) * ($this->ColWidth + $this->ColGap)); // *RTL* } // *RTL* else { // *RTL* $xadj = ($newcolumn - $s['col']) * ($this->ColWidth + $this->ColGap); } // *RTL* if ($last_new_col != $newcolumn) { // Added new column $last_col_bottom = $this->columnbuffer[$key]['rel_y']; $block_bottom = 0; } $yadj = ($s['rel_y'] - $s['y']) - ($last_col_bottom)+$this->y0; // callback function in htmltoolkit $t = $s['s']; $t = preg_replace('/BT (\d+\.\d\d+) (\d+\.\d\d+) Td/e',"\$this->columnAdjustAdd('Td',_MPDFK,$xadj,$yadj,'\\1','\\2')",$t); $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) ([\-]{0,1}\d+\.\d\d+) re/e',"\$this->columnAdjustAdd('re',_MPDFK,$xadj,$yadj,'\\1','\\2','\\3','\\4')",$t); $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) l/e',"\$this->columnAdjustAdd('l',_MPDFK,$xadj,$yadj,'\\1','\\2')",$t); $t = preg_replace('/q (\d+\.\d\d+) 0 0 (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) cm \/(I|FO)/e',"\$this->columnAdjustAdd('img',_MPDFK,$xadj,$yadj,'\\1','\\2','\\3','\\4','\\5')",$t); $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) m/e',"\$this->columnAdjustAdd('draw',_MPDFK,$xadj,$yadj,'\\1','\\2')",$t); $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) c/e',"\$this->columnAdjustAdd('bezier',_MPDFK,$xadj,$yadj,'\\1','\\2','\\3','\\4','\\5','\\6')",$t); $this->columnbuffer[$key]['s'] = $t; $this->columnbuffer[$key]['newcol'] = $newcolumn; $this->columnbuffer[$key]['newy'] = $s['y'] + $yadj; $last_new_col = $newcolumn; $clb = $s['y'] + $yadj + $s['h'] ; // bottom_margin of current if ((isset($this->ColDetails[$newcolumn]['max_bottom']) && $clb > $this->ColDetails[$newcolumn]['max_bottom']) || (!isset($this->ColDetails[$newcolumn]['max_bottom']) && $clb)) { $this->ColDetails[$newcolumn]['max_bottom'] = $clb; } if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; } // Adjust LINKS if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) { $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]; $this->PageLinks[$this->page][$ref][0] += ($xadj*_MPDFK); $this->PageLinks[$this->page][$ref][1] -= ($yadj*_MPDFK); unset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]); } // Adjust FORM FIELDS if (isset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) { $ref = $this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]; $this->form->forms[$ref]['x'] += ($xadj); $this->form->forms[$ref]['y'] += ($yadj); unset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]); } /*-- ANNOTATIONS --*/ if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) { $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]; if ($this->PageAnnots[$this->page][$ref]['x'] < 0) { $this->PageAnnots[$this->page][$ref]['x'] -= ($xadj); } else { $this->PageAnnots[$this->page][$ref]['x'] += ($xadj); } $this->PageAnnots[$this->page][$ref]['y'] += ($yadj); // unlike PageLinks, Page annots has y values from top in mm unset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]); } /*-- END ANNOTATIONS --*/ } } /*-- BOOKMARKS --*/ // Adjust Bookmarks foreach($this->col_BMoutlines AS $v) { $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$this->y0,'p'=>$v['p']); } /*-- END BOOKMARKS --*/ /*-- INDEX --*/ // Adjust Reference (index) foreach($this->col_Reference AS $v) { $Present=0; //Search the reference (AND Ref/PageNo) in the array for ($i=0;$i<count($this->Reference);$i++){ if ($this->Reference[$i]['t']==$v['t']){ $Present=1; if (!in_array($v['op'],$this->Reference[$i]['p'])) { $this->Reference[$i]['p'][] = $v['op']; } } } if ($Present==0) { $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op'])); } } /*-- END INDEX --*/ /*-- TOC --*/ // Adjust ToC foreach($this->col_toc AS $v) { $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']); $this->links[$v['link']][1] = $this->y0; } /*-- END TOC --*/ // Adjust column length to be equal if ($this->colvAlign == 'J') { foreach($this->columnbuffer AS $key=>$s) { if (isset($s['rel_y'])) { // only process position sensitive data // Set ratio to expand y values or heights if (isset($this->ColDetails[$s['newcol']]['max_bottom']) && $this->ColDetails[$s['newcol']]['max_bottom'] && $this->ColDetails[$s['newcol']]['max_bottom']!=$this->y0) { $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['newcol']]['max_bottom'] - ($this->y0)); } else { $ratio = 1; } if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) { $yadj = ($s['newy'] - $this->y0) * ($ratio - 1); // Adjust LINKS if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) { $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]; $this->PageLinks[$this->page][$ref][1] -= ($yadj*_MPDFK); // y value $this->PageLinks[$this->page][$ref][3] *= $ratio; // height unset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]); } // Adjust FORM FIELDS if (isset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) { $ref = $this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]; $this->form->forms[$ref]['x'] += ($xadj); $this->form->forms[$ref]['y'] += ($yadj); unset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]); } /*-- ANNOTATIONS --*/ if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) { $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]; $this->PageAnnots[$this->page][$ref]['y'] += ($yadj); unset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]); } /*-- END ANNOTATIONS --*/ } } } // mPDF 5.3.01 foreach($this->internallink AS $key => $f) { if (is_array($f) && isset($f['col'])) { $last_col_bottom = 0; for ($nbc=0; $nbc<$this->NbCol; $nbc++) { if ($f['rel_y'] >= $cbr[$nbc]) { $last_col_bottom = $cbr[$nbc]; } } $yadj = ($f['rel_y'] - $f['Y']) - $last_col_bottom + $this->y0; $f['Y'] += $yadj; unset($f['col']); unset($f['rel_y']); $this->internallink[$key] = $f; } } $last_col = -1; $trans_on = false; foreach($this->columnbuffer AS $key=>$s) { if (isset($s['rel_y'])) { // only process position sensitive data // Set ratio to expand y values or heights if (isset($this->ColDetails[$s['newcol']]['max_bottom']) && $this->ColDetails[$s['newcol']]['max_bottom'] && $this->ColDetails[$s['newcol']]['max_bottom']!=$this->y0) { $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['newcol']]['max_bottom'] - ($this->y0)); } else { $ratio = 1; } if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) { //Start Transformation $this->pages[$this->page] .= $this->StartTransform(true)."\n"; $this->pages[$this->page] .= $this->transformScale(100, $ratio*100, $x='', $this->y0, true)."\n"; $trans_on = true; } } // Now output the adjusted values $this->pages[$this->page] .= $s['s']."\n"; if (isset($s['rel_y']) && ($ratio > 1) && ($ratio <= $this->max_colH_correction)) { // only process position sensitive data //Stop Transformation $this->pages[$this->page] .= $this->StopTransform(true)."\n"; $trans_on = false; } } if ($trans_on) { $this->pages[$this->page] .= $this->StopTransform(true)."\n"; } } else { // if NOT $this->colvAlign == 'J' // Now output the adjusted values foreach($this->columnbuffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; } } if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; } } // Columns not ended but new page -> align columns (can leave the columns alone - just tidy up the height) else if ($this->colvAlign == 'J' && $this->ColumnAdjust && !$this->keepColumns) { // calculate the lowest bottom margin $lowest_bottom_y = 0; foreach($this->columnbuffer AS $key=>$s) { // Only process output data $t = $s['s']; if ($t == 'ACROFORM' || (preg_match('/BT \d+\.\d\d+ (\d+\.\d\d+) Td/',$t)) || (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ [\-]{0,1}\d+\.\d\d+ re/',$t)) || (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) || (preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+ (\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/',$t)) || (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) || (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) ) { $clb = $s['y'] + $s['h']; if ((isset($this->ColDetails[$s['col']]['max_bottom']) && $clb > $this->ColDetails[$s['col']]['max_bottom']) || !isset($this->ColDetails[$s['col']]['max_bottom'])) { $this->ColDetails[$s['col']]['max_bottom'] = $clb; } if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; } $this->columnbuffer[$key]['rel_y'] = $s['y']; // Marks position sensitive data to process later if ($t == 'ACROFORM') { $this->columnbuffer[$key]['s'] = ''; } } } // Adjust column length equal foreach($this->columnbuffer AS $key=>$s) { // Set ratio to expand y values or heights if (isset($this->ColDetails[$s['col']]['max_bottom']) && $this->ColDetails[$s['col']]['max_bottom']) { $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['col']]['max_bottom'] - ($this->y0)); } else { $ratio = 1; } if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) { $yadj = ($s['y'] - $this->y0) * ($ratio - 1); // Adjust LINKS if (isset($s['rel_y'])) { // only process position sensitive data // otherwise triggers for all entries in column buffer (.e.g. formatting) and makes below adjustments more than once if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) { $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]; $this->PageLinks[$this->page][$ref][1] -= ($yadj*_MPDFK); // y value $this->PageLinks[$this->page][$ref][3] *= $ratio; // height unset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]); } // Adjust FORM FIELDS if (isset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) { $ref = $this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]; $this->form->forms[$ref]['x'] += ($xadj); $this->form->forms[$ref]['y'] += ($yadj); unset($this->columnForms[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]); } /*-- ANNOTATIONS --*/ if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) { $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]; $this->PageAnnots[$this->page][$ref]['y'] += ($yadj); unset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])]); } /*-- END ANNOTATIONS --*/ } } } /*-- BOOKMARKS --*/ // Adjust Bookmarks foreach($this->col_BMoutlines AS $v) { $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$this->y0,'p'=>$v['p']); } /*-- END BOOKMARKS --*/ /*-- INDEX --*/ // Adjust Reference (index) foreach($this->col_Reference AS $v) { $Present=0; //Search the reference (AND Ref/PageNo) in the array for ($i=0;$i<count($this->Reference);$i++){ if ($this->Reference[$i]['t']==$v['t']){ $Present=1; if (!in_array($v['op'],$this->Reference[$i]['p'])) { $this->Reference[$i]['p'][] = $v['op']; } } } if ($Present==0) { $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op'])); } } /*-- END INDEX --*/ /*-- TOC --*/ // Adjust ToC foreach($this->col_toc AS $v) { $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']); $this->links[$v['link']][1] = $this->y0; } /*-- END TOC --*/ $trans_on = false; foreach($this->columnbuffer AS $key=>$s) { if (isset($s['rel_y'])) { // only process position sensitive data // Set ratio to expand y values or heights if ($this->ColDetails[$s['col']]['max_bottom']) { $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['col']]['max_bottom'] - ($this->y0)); } else { $ratio = 1; } if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) { //Start Transformation $this->pages[$this->page] .= $this->StartTransform(true)."\n"; $this->pages[$this->page] .= $this->transformScale(100, $ratio*100, $x='', $this->y0, true)."\n"; $trans_on = true; } } // Now output the adjusted values $this->pages[$this->page] .= $s['s']."\n"; if (isset($s['rel_y']) && ($ratio > 1) && ($ratio <= $this->max_colH_correction)) { //Stop Transformation $this->pages[$this->page] .= $this->StopTransform(true)."\n"; $trans_on = false; // mPDF 5.1.001 } } if ($trans_on) { $this->pages[$this->page] .= $this->StopTransform(true)."\n"; } if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; } } // Just reproduce the page as it was else { // If page has not ended but height adjustment was disabled by custom column-break - adjust y $lowest_bottom_y = 0; if (!$this->ColActive && (!$this->ColumnAdjust || $this->keepColumns)) { // calculate the lowest bottom margin foreach($this->columnbuffer AS $key=>$s) { // Only process output data $t = $s['s']; if ($t == 'ACROFORM' || (preg_match('/BT \d+\.\d\d+ (\d+\.\d\d+) Td/',$t)) || (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ [\-]{0,1}\d+\.\d\d+ re/',$t)) || (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) || (preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+ (\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/',$t)) || (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) || (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) ) { $clb = $s['y'] + $s['h']; if ($clb > $this->ColDetails[$s['col']]['max_bottom']) { $this->ColDetails[$s['col']]['max_bottom'] = $clb; } if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; } } } } foreach($this->columnbuffer AS $key=>$s) { if ($s['s'] != 'ACROFORM') $this->pages[$this->page] .= $s['s']."\n"; } if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; } /*-- INDEX --*/ // Output Reference (index) foreach($this->col_Reference AS $v) { $Present=0; for ($i=0;$i<count($this->Reference);$i++){ if ($this->Reference[$i]['t']==$v['t']){ $Present=1; if (!in_array($v['op'],$this->Reference[$i]['p'])) { $this->Reference[$i]['p'][] = $v['op']; } } } if ($Present==0) { $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op'])); } } /*-- END INDEX --*/ /*-- BOOKMARKS --*/ // Output Bookmarks foreach($this->col_BMoutlines AS $v) { $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']); } /*-- END BOOKMARKS --*/ /*-- TOC --*/ // Output ToC foreach($this->col_toc AS $v) { $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']); } /*-- END TOC --*/ } // mPDF 5.3.01 foreach($this->internallink AS $key => $f) { if (isset($this->internallink[$key]['col'])) unset($this->internallink[$key]['col']); if (isset($this->internallink[$key]['rel_y'])) unset($this->internallink[$key]['rel_y']); } $this->columnbuffer = array(); $this->ColDetails = array(); $this->columnLinks = array(); $this->columnAnnots = array(); $this->columnForms = array(); $this->col_Reference = array(); $this->col_BMoutlines = array(); $this->col_toc = array(); $this->breakpoints = array(); } /*-- END COLUMNS --*/ //================================================================== /*-- TABLES --*/ function printcellbuffer() { if (count($this->cellBorderBuffer )) { sort($this->cellBorderBuffer); foreach($this->cellBorderBuffer AS $cbb) { // mPDF 5.3.74 $cba = unpack("A16dom/nbord/A1side/ns/dbw/a6ca/A10style/dx/dy/dw/dh/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd/dover/", $cbb); $side = $cba['side']; $details = array(); $details[$side]['dom'] = (float) $cba['dom']; $details[$side]['s'] = $cba['s']; $details[$side]['w'] = $cba['bw']; $details[$side]['c'] = $cba['ca']; $details[$side]['style'] = trim($cba['style']); $details['mbw']['BL'] = $cba['mbl']; $details['mbw']['BR'] = $cba['mbr']; $details['mbw']['RT'] = $cba['mrt']; $details['mbw']['RB'] = $cba['mrb']; $details['mbw']['TL'] = $cba['mtl']; $details['mbw']['TR'] = $cba['mtr']; $details['mbw']['LT'] = $cba['mlt']; $details['mbw']['LB'] = $cba['mlb']; $details['cellposdom'] = $cba['cpd']; $details['p'] = $side; if ($cba['over']==1) { $details[$side]['overlay'] = true; } else { $details[$side]['overlay'] = false; } $this->_tableRect($cba['x'],$cba['y'],$cba['w'],$cba['h'],$cba['bord'],$details, false, false); } $this->cellBorderBuffer = array(); } } //================================================================== function printtablebuffer() { if (!$this->table_rotate) { $this->pages[$this->page] .= $this->tablebuffer; foreach($this->tbrot_Links AS $p => $l) { foreach($l AS $v) { $this->PageLinks[$p][] = $v; } } $this->tbrot_Links = array(); /*-- ANNOTATIONS --*/ foreach($this->tbrot_Annots AS $p => $l) { foreach($l AS $v) { $this->PageAnnots[$p][] = $v; } } $this->tbrot_Annots = array(); /*-- END ANNOTATIONS --*/ /*-- INDEX --*/ // Output Reference (index) foreach($this->tbrot_Reference AS $v) { $Present=0; for ($i=0;$i<count($this->Reference);$i++){ if ($this->Reference[$i]['t']==$v['t']){ $Present=1; if (!in_array($v['op'],$this->Reference[$i]['p'])) { $this->Reference[$i]['p'][] = $v['op']; } } } if ($Present==0) { $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op'])); } } $this->tbrot_Reference = array(); /*-- END INDEX --*/ /*-- BOOKMARKS --*/ // Output Bookmarks foreach($this->tbrot_BMoutlines AS $v) { $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']); } $this->tbrot_BMoutlines = array(); /*-- END BOOKMARKS --*/ /*-- TOC --*/ // Output ToC foreach($this->tbrot_toc AS $v) { $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']); } $this->tbrot_toc = array(); /*-- END TOC --*/ return; } // else if rotated $lm = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_left']; $pw = $this->blk[$this->blklvl]['inner_width']; //Start Transformation $this->pages[$this->page] .= $this->StartTransform(true)."\n"; if ($this->table_rotate > 1) { // clockwise if ($this->tbrot_align == 'L') { $xadj = $this->tbrot_h ; // align L (as is) } else if ($this->tbrot_align == 'R') { $xadj = $lm-$this->tbrot_x0+($pw) ; // align R } else { $xadj = $lm-$this->tbrot_x0+(($pw + $this->tbrot_h)/2) ; // align C } $yadj = 0; } else { // anti-clockwise if ($this->tbrot_align == 'L') { $xadj = 0 ; // align L (as is) } else if ($this->tbrot_align == 'R') { $xadj = $lm-$this->tbrot_x0+($pw - $this->tbrot_h) ; // align R } else { $xadj = $lm-$this->tbrot_x0+(($pw - $this->tbrot_h)/2) ; // align C } $yadj = $this->tbrot_w; } $this->pages[$this->page] .= $this->transformTranslate($xadj, $yadj , true)."\n"; $this->pages[$this->page] .= $this->transformRotate($this->table_rotate, $this->tbrot_x0 , $this->tbrot_y0 , true)."\n"; // Now output the adjusted values $this->pages[$this->page] .= $this->tablebuffer; foreach($this->tbrot_Links AS $p => $l) { foreach($l AS $v) { $w = $v[2]/_MPDFK; $h = $v[3]/_MPDFK; $ax = ($v[0]/_MPDFK) - $this->tbrot_x0; $ay = (($this->hPt-$v[1])/_MPDFK) - $this->tbrot_y0; if ($this->table_rotate > 1) { // clockwise $bx = $this->tbrot_x0+$xadj-$ay-$h; $by = $this->tbrot_y0+$yadj+$ax; } else { $bx = $this->tbrot_x0+$xadj+$ay; $by = $this->tbrot_y0+$yadj-$ax-$w; } $v[0] = $bx*_MPDFK; $v[1] = ($this->h-$by)*_MPDFK; $v[2] = $h*_MPDFK; // swap width and height $v[3] = $w*_MPDFK; $this->PageLinks[$p][] = $v; } } $this->tbrot_Links = array(); // mPDF 5.3.01 foreach($this->internallink AS $key => $f) { if (is_array($f) && isset($f['tbrot'])) { $f['Y'] = $this->tbrot_y0; $f['PAGE'] = $this->page; unset($f['tbrot']); $this->internallink[$key] = $f; } } /*-- ANNOTATIONS --*/ foreach($this->tbrot_Annots AS $p => $l) { foreach($l AS $v) { $ax = abs($v['x']) - $this->tbrot_x0; // abs because -ve values are internally set and held for reference if annotMargin set $ay = $v['y'] - $this->tbrot_y0; if ($this->table_rotate > 1) { // clockwise $bx = $this->tbrot_x0+$xadj-$ay; $by = $this->tbrot_y0+$yadj+$ax; } else { $bx = $this->tbrot_x0+$xadj+$ay; $by = $this->tbrot_y0+$yadj-$ax; } if ($v['x'] < 0) { $v['x'] = -$bx; } else { $v['x'] = $bx; } $v['y'] = ($by); $this->PageAnnots[$p][] = $v; } } $this->tbrot_Annots = array(); /*-- END ANNOTATIONS --*/ /*-- BOOKMARKS --*/ // Adjust Bookmarks foreach($this->tbrot_BMoutlines AS $v) { $v['y'] = $this->tbrot_y0; $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$this->page); } /*-- END BOOKMARKS --*/ /*-- INDEX --*/ // Adjust Reference (index) foreach($this->tbrot_Reference AS $v) { $Present=0; //Search the reference (AND Ref/PageNo) in the array for ($i=0;$i<count($this->Reference);$i++){ if ($this->Reference[$i]['t']==$v['t']){ $Present=1; if (!in_array($this->page,$this->Reference[$i]['p'])) { $this->Reference[$i]['p'][] = $this->page; } } } if ($Present==0) { $this->Reference[]=array('t'=>$v['t'],'p'=>array($this->page)); } } /*-- END INDEX --*/ /*-- TOC --*/ // Adjust ToC - uses document page number foreach($this->tbrot_toc AS $v) { $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$this->page,'link'=>$v['link'],'toc_id'=>$v['toc_id']); $this->links[$v['link']][1] = $this->tbrot_y0; } /*-- END TOC --*/ $this->tbrot_Reference = array(); $this->tbrot_BMoutlines = array(); $this->tbrot_toc = array(); //Stop Transformation $this->pages[$this->page] .= $this->StopTransform(true)."\n"; $this->y = $this->tbrot_y0 + $this->tbrot_w; $this->x = $this->lMargin; $this->tablebuffer = ''; } //================================================================== // Keep-with-table This buffers contents of h1-6 to keep on page with table function printkwtbuffer() { if (!$this->kwt_moved) { foreach($this->kwt_buffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; } foreach($this->kwt_Links AS $p => $l) { foreach($l AS $v) { $this->PageLinks[$p][] = $v; } } $this->kwt_Links = array(); /*-- ANNOTATIONS --*/ foreach($this->kwt_Annots AS $p => $l) { foreach($l AS $v) { $this->PageAnnots[$p][] = $v; } } $this->kwt_Annots = array(); /*-- END ANNOTATIONS --*/ /*-- INDEX --*/ // Output Reference (index) foreach($this->kwt_Reference AS $v) { $Present=0; for ($i=0;$i<count($this->Reference);$i++){ if ($this->Reference[$i]['t']==$v['t']){ $Present=1; if (!in_array($v['op'],$this->Reference[$i]['p'])) { $this->Reference[$i]['p'][] = $v['op']; } } } if ($Present==0) { $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op'])); } } $this->kwt_Reference = array(); /*-- END INDEX --*/ /*-- BOOKMARKS --*/ // Output Bookmarks foreach($this->kwt_BMoutlines AS $v) { $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']); } $this->kwt_BMoutlines = array(); /*-- END BOOKMARKS --*/ /*-- TOC --*/ // Output ToC foreach($this->kwt_toc AS $v) { $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']); } $this->kwt_toc = array(); /*-- END TOC --*/ return; } //Start Transformation $this->pages[$this->page] .= $this->StartTransform(true)."\n"; $xadj = $this->lMargin - $this->kwt_x0 ; //$yadj = $this->y - $this->kwt_y0 ; $yadj = $this->tMargin - $this->kwt_y0 ; $this->pages[$this->page] .= $this->transformTranslate($xadj, $yadj , true)."\n"; // Now output the adjusted values foreach($this->kwt_buffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; } // Adjust hyperLinks foreach($this->kwt_Links AS $p => $l) { foreach($l AS $v) { $bx = $this->kwt_x0+$xadj; $by = $this->kwt_y0+$yadj; $v[0] = $bx*_MPDFK; $v[1] = ($this->h-$by)*_MPDFK; $this->PageLinks[$p][] = $v; } } // mPDF 5.3.01 foreach($this->internallink AS $key => $f) { if (is_array($f) && isset($f['kwt'])) { $f['Y'] += $yadj; $f['PAGE'] = $this->page; unset($f['kwt']); $this->internallink[$key] = $f; } } /*-- ANNOTATIONS --*/ foreach($this->kwt_Annots AS $p => $l) { foreach($l AS $v) { $bx = $this->kwt_x0+$xadj; $by = $this->kwt_y0+$yadj; if ($v['x'] < 0) { $v['x'] = -$bx; } else { $v['x'] = $bx; } $v['y'] = $by; $this->PageAnnots[$p][] = $v; } } /*-- END ANNOTATIONS --*/ /*-- BOOKMARKS --*/ // Adjust Bookmarks foreach($this->kwt_BMoutlines AS $v) { if ($v['y'] != 0) { $v['y'] += $yadj; } $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$this->page); } /*-- END BOOKMARKS --*/ /*-- INDEX --*/ // Adjust Reference (index) foreach($this->kwt_Reference AS $v) { $Present=0; //Search the reference (AND Ref/PageNo) in the array for ($i=0;$i<count($this->Reference);$i++){ if ($this->Reference[$i]['t']==$v['t']){ $Present=1; if (!in_array($this->page,$this->Reference[$i]['p'])) { $this->Reference[$i]['p'][] = $this->page; } } } if ($Present==0) { $this->Reference[]=array('t'=>$v['t'],'p'=>array($this->page)); } } /*-- END INDEX --*/ /*-- TOC --*/ // Adjust ToC foreach($this->kwt_toc AS $v) { $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$this->page,'link'=>$v['link'],'toc_id'=>$v['toc_id']); $this->links[$v['link']][0] = $this->page; $this->links[$v['link']][1] += $yadj; } /*-- END TOC --*/ $this->kwt_Links = array(); $this->kwt_Annots = array(); $this->kwt_Reference = array(); $this->kwt_BMoutlines = array(); $this->kwt_toc = array(); //Stop Transformation $this->pages[$this->page] .= $this->StopTransform(true)."\n"; $this->kwt_buffer = array(); $this->y += $this->kwt_height; } /*-- END TABLES --*/ //================================================================== function printfloatbuffer() { if (count($this->floatbuffer)) { $this->objectbuffer = $this->floatbuffer; $this->printobjectbuffer(false); $this->objectbuffer = array(); $this->floatbuffer = array(); $this->floatmargins = array(); } } //================================================================== function printdivbuffer() { $p1 = $this->blk[$this->blklvl]['startpage']; $p2 = $this->page; $bottom[$p1] = $this->ktBlock[$p1]['bottom_margin']; $bottom[$p2] = $this->y; // $this->ktBlock[$p2]['bottom_margin']; $top[$p1] = $this->kt_y00; $top2 = $this->h; foreach($this->divbuffer AS $key=>$s) { if ($s['page'] == $p2) { $top2 = MIN($s['y'], $top2); } } $top[$p2] = $top2; $height[$p1] = ($bottom[$p1] - $top[$p1]); $height[$p2] = ($bottom[$p2] - $top[$p2]); $xadj[$p1] = $this->MarginCorrection; $yadj[$p1] = -($top[$p1] - $top[$p2]); $xadj[$p2] = 0; $yadj[$p2] = $height[$p1]; // Output without any transformation if ($this->ColActive || !$this->keep_block_together || $this->blk[$this->blklvl]['startpage'] == $this->page || ($this->page - $this->blk[$this->blklvl]['startpage']) > 1 || ($height[$p1]+$height[$p2]) > $this->h) { foreach($this->divbuffer AS $s) { $this->pages[$s['page']] .= $s['s']."\n"; } foreach($this->ktLinks AS $p => $l) { foreach($l AS $v) { $this->PageLinks[$p][] = $v; } } foreach($this->ktForms AS $key => $f) { $this->form->forms[$f['n']] = $f; } /*-- ANNOTATIONS --*/ foreach($this->ktAnnots AS $p => $l) { foreach($l AS $v) { $this->PageAnnots[$p][] = $v; } } /*-- END ANNOTATIONS --*/ /*-- INDEX --*/ // Adjust Reference (index) foreach($this->ktReference AS $v) { $Present=0; //Search the reference (AND Ref/PageNo) in the array for ($i=0;$i<count($this->Reference);$i++){ if ($this->Reference[$i]['t']==$v['t']){ $Present=1; if (!in_array($p2,$this->Reference[$i]['p'])) { $this->Reference[$i]['p'][] = $p2; } } } //If not found, add it if ($Present==0) { $this->Reference[]=array('t'=>$v['t'],'p'=>array($p2)); } } /*-- END INDEX --*/ /*-- BOOKMARKS --*/ // Adjust Bookmarks foreach($this->ktBMoutlines AS $v) { $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']); } /*-- END BOOKMARKS --*/ /*-- TOC --*/ // Adjust ToC foreach($this->_kttoc AS $v) { $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']); } /*-- END TOC --*/ $this->divbuffer = array(); $this->ktLinks = array(); $this->ktAnnots = array(); $this->ktForms = array(); $this->ktBlock = array(); $this->ktReference = array(); $this->ktBMoutlines = array(); $this->_kttoc = array(); $this->keep_block_together = 0; return; } else { $np = ''; $pre = ''; $ispre = true; foreach($this->divbuffer AS $key=>$s) { // callback function $t = $s['s']; $p = $s['page']; if (preg_match('/(___PAGE___START'.date('jY').')/', $t)) { $ispre = false; } else if (preg_match('/(___HEADER___MARKER'.date('jY').')/', $t)) { $np .= $t."\n".$pre; continue; } else { $t = preg_replace('/BT (\d+\.\d\d+) (\d+\.\d\d+) Td/e',"\$this->blockAdjust('Td',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2')",$t); $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) ([\-]{0,1}\d+\.\d\d+) re/e',"\$this->blockAdjust('re',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2','\\3','\\4')",$t); $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) l/e',"\$this->blockAdjust('l',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2')",$t); $t = preg_replace('/q (\d+\.\d\d+) 0 0 (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) cm \/(I|FO)/e',"\$this->blockAdjust('img',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2','\\3','\\4','\\5')",$t); $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) m/e',"\$this->blockAdjust('draw',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2')",$t); $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) c/e',"\$this->blockAdjust('bezier',_MPDFK,$xadj[$p],$yadj[$p],'\\1','\\2','\\3','\\4','\\5','\\6')",$t); } if ($ispre) $pre .= $t."\n"; else $np .= $t."\n"; } if ($ispre && $pre) $np = $pre ."\n". $np; $this->pages[$this->page] .= $np; // Adjust hyperLinks foreach($this->ktLinks AS $p => $l) { foreach($l AS $v) { $v[0] += ($xadj[$p]*_MPDFK); $v[1] -= ($yadj[$p]*_MPDFK); $this->PageLinks[$p2][] = $v; } } foreach($this->ktForms AS $key => $f) { $p = $f['page']; $f['x'] += ($xadj[$p]); $f['y'] += ($yadj[$p]); $f['page'] = $p2; $this->form->forms[$f['n']] = $f; } // mPDF 5.3.01 foreach($this->internallink AS $key => $f) { if (is_array($f) && isset($f['kt'])) { $f['Y'] += ($yadj[$f['PAGE']]); $f['PAGE'] = $p2; unset($f['kt']); $this->internallink[$key] = $f; } } /*-- ANNOTATIONS --*/ foreach($this->ktAnnots AS $p => $l) { foreach($l AS $v) { if ($v['x']>0) { $v['x'] += $xadj[$p]; } else if ($v['x']<0) { $v['x'] -= $xadj[$p]; } $v['y'] += $yadj[$p]; $this->PageAnnots[$p2][] = $v; } } /*-- END ANNOTATIONS --*/ /*-- BOOKMARKS --*/ // Adjust Bookmarks foreach($this->ktBMoutlines AS $v) { if ($v['y'] != 0) { $v['y'] += ($yadj[$v['p']]); } $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$p2); } /*-- END BOOKMARKS --*/ /*-- INDEX --*/ // Adjust Reference (index) foreach($this->ktReference AS $v) { $Present=0; //Search the reference (AND Ref/PageNo) in the array for ($i=0;$i<count($this->Reference);$i++){ if ($this->Reference[$i]['t']==$v['t']){ $Present=1; if (!in_array($p2,$this->Reference[$i]['p'])) { $this->Reference[$i]['p'][] = $p2; } } } //If not found, add it if ($Present==0) { $this->Reference[]=array('t'=>$v['t'],'p'=>array($p2)); } } /*-- END INDEX --*/ /*-- TOC --*/ // Adjust ToC foreach($this->_kttoc AS $v) { $this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$p2,'link'=>$v['link'],'toc_id'=>$v['toc_id']); $this->links[$v['link']][0] = $p2; $this->links[$v['link']][1] += $yadj[$v['p']]; // mPDF 5.3.02 } /*-- END TOC --*/ $this->y = $top[$p2] + $height[$p1] + $height[$p2]; $this->x = $this->lMargin; $this->divbuffer = array(); $this->ktLinks = array(); $this->ktAnnots = array(); $this->ktForms = array(); $this->ktBlock = array(); $this->ktReference = array(); $this->ktBMoutlines = array(); $this->_kttoc = array(); $this->keep_block_together = 0; } } //================================================================== // Added ELLIPSES and CIRCLES function Circle($x,$y,$r,$style='S') { $this->Ellipse($x,$y,$r,$r,$style); } function Ellipse($x,$y,$rx,$ry,$style='S') { if($style=='F') { $op='f'; } elseif($style=='FD' or $style=='DF') { $op='B'; } else { $op='S'; } $lx=4/3*(M_SQRT2-1)*$rx; $ly=4/3*(M_SQRT2-1)*$ry; $h=$this->h; $this->_out(sprintf('%.3F %.3F m %.3F %.3F %.3F %.3F %.3F %.3F c', ($x+$rx)*_MPDFK,($h-$y)*_MPDFK, ($x+$rx)*_MPDFK,($h-($y-$ly))*_MPDFK, ($x+$lx)*_MPDFK,($h-($y-$ry))*_MPDFK, $x*_MPDFK,($h-($y-$ry))*_MPDFK)); $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c', ($x-$lx)*_MPDFK,($h-($y-$ry))*_MPDFK, ($x-$rx)*_MPDFK,($h-($y-$ly))*_MPDFK, ($x-$rx)*_MPDFK,($h-$y)*_MPDFK)); $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c', ($x-$rx)*_MPDFK,($h-($y+$ly))*_MPDFK, ($x-$lx)*_MPDFK,($h-($y+$ry))*_MPDFK, $x*_MPDFK,($h-($y+$ry))*_MPDFK)); $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F c %s', ($x+$lx)*_MPDFK,($h-($y+$ry))*_MPDFK, ($x+$rx)*_MPDFK,($h-($y+$ly))*_MPDFK, ($x+$rx)*_MPDFK,($h-$y)*_MPDFK, $op)); } /*-- DIRECTW --*/ // Added adaptation of shaded_box = AUTOSIZE-TEXT function AutosizeText($text,$w,$font,$style,$szfont=72) { $text = $this->purify_utf8_text($text); if ($this->text_input_as_HTML) { $text = $this->all_entities_to_utf8($text); } if ($this->usingCoreFont) { $text = mb_convert_encoding($text,$this->mb_enc,'UTF-8'); } // mPDF 5.3.22 $text = ' '.$text.' '; $width = $this->ConvertSize($w); $loop = 0; while ( $loop == 0 ) { $this->SetFont($font,$style,$szfont); $sz = $this->GetStringWidth( $text ); if ( $sz > $w ) { $szfont --; } else { $loop ++; } } $this->SetFont($font,$style,$szfont); $this->Cell($w, 0, $text, 0, 0, "C"); } /*-- END DIRECTW --*/ // ==================================================== // ==================================================== /*-- RTL --*/ function reverse_letters($str) { $str = strtr($str, '{}[]()', '}{][)('); return $this->mb_strrev($str, $this->mb_enc); } function magic_reverse_dir(&$chunk, $join=true, $dir) { if ($this->usingCoreFont) { return 0; } if ($this->biDirectional) { // Change Arabic + Persian. to Presentation Forms if ($join) { $chunk = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $chunk ); } $contains_rtl = false; $all_rtl = true; $initSpace = false; $endSpace = false; $nonDirchars = "\x{A0}\"\'\(\)\{\}\[\].,:\-="; if (preg_match("/[".$this->pregRTLchars."]/u",$chunk)) { // Chunk contains RTL characters if (preg_match("/^[ ]/",$chunk)) { $initSpace = true; $chunk = preg_replace("/^[ ]/",'',$chunk); } if (preg_match("/[ ]$/",$chunk)) { $endSpace = true; $chunk = preg_replace("/[ ]$/",'',$chunk); } if (preg_match("/[^".$this->pregRTLchars.$nonDirchars." ]/u",$chunk)) { // Chunk also contains LTR characters $all_rtl = false; if ($dir == 'rtl') { $chunk = preg_replace("/([^".$this->pregRTLchars.$nonDirchars."][".$nonDirchars."]*) ([".$nonDirchars."]*[^".$this->pregRTLchars.$nonDirchars."])/u","\\1\x07\\2",$chunk); } $chunk = preg_replace("/([".$this->pregRTLchars."][".$nonDirchars."]*) ([".$nonDirchars."]*[".$this->pregRTLchars."])/u","\\1\x07\\2",$chunk); $bits = explode(' ',$chunk); foreach($bits AS $bitkey=>$bit) { $bit = preg_replace("/\x07/"," ",$bit); if (preg_match("/^[".$this->pregRTLchars.$nonDirchars." ]*$/u",$bit)) { $bits[$bitkey] = $this->reverse_letters($bit); } else if (preg_match("/[".$this->pregRTLchars."]/u",$bit)) { if ($dir == 'rtl') { $bit = preg_replace("/([^".$this->pregRTLchars.$nonDirchars." ])([".$nonDirchars."]*[".$this->pregRTLchars."])/u","\\1\x07\\2",$bit ); $bit = preg_replace("/([".$this->pregRTLchars."][".$nonDirchars."]*)([^".$this->pregRTLchars.$nonDirchars." ])/u","\\1\x07\\2",$bit ); } else { $bit = preg_replace("/([^".$this->pregRTLchars." ][".$nonDirchars."]*)([".$this->pregRTLchars." ])/u","\\1\x07\\2",$bit ); $bit = preg_replace("/([".$this->pregRTLchars." ])([".$nonDirchars."]*[^".$this->pregRTLchars." ])/u","\\1\x07\\2",$bit ); } $sbits = explode("\x07",$bit ); foreach($sbits AS $sbitkey=>$sbit) { $sbit = preg_replace("/\x07/","",$sbit); if (preg_match("/^[".$this->pregRTLchars.$nonDirchars." ]*$/u",$sbit)) { $sbits[$sbitkey] = $this->reverse_letters($sbit); } else if (preg_match("/[".$this->pregRTLchars."]/u",$sbit) && $dir=='rtl') { $sbits[$sbitkey] = $this->reverse_letters($sbit); } else { $sbits[$sbitkey] = $sbit; } } if ($dir == 'rtl') { $sbits = array_reverse($sbits,false); } $bits[$bitkey] = implode('',$sbits); } else if (preg_match("/[".$this->pregRTLchars."]/u",$bit) && $dir=='rtl') { $bits[$bitkey] = $this->reverse_letters($bit); } else { $bits[$bitkey] = $bit; } } if ($dir == 'rtl') { $bits = array_reverse($bits,false); } $chunk = implode(' ',$bits); } else { $chunk = $this->reverse_letters($chunk); } $contains_rtl = true; // Un-Reverse numerals back to ltr $chunk = preg_replace("/([\x{0660}-\x{0669}]+)/ue", '$this->reverse_letters(\'\\1\')', $chunk ); if ($dir == 'rtl') { if ($endSpace) { $chunk = ' '.$chunk; } if ($initSpace) { $chunk .= ' '; } } else { if ($initSpace) { $chunk = ' '.$chunk; } if ($endSpace) { $chunk .= ' '; } } } else { $all_rtl = false; } if ($all_rtl) { return 2; } else if ($contains_rtl) { return 1; } else { return 0; } } return 0; } /*-- END RTL --*/ // // **************************** // **************************** function SetSubstitutions() { $subsarray = array(); @include(_MPDF_PATH.'includes/subs_win-1252.php'); $this->substitute = array(); foreach($subsarray AS $key => $val) { $this->substitute[code2utf($key)] = $val; } } function SubstituteChars($html) { // only substitute characters between tags if (count($this->substitute)) { $a=preg_split('/(<.*?>)/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE); $html = ''; foreach($a as $i => $e) { if($i%2==0) { $e = strtr($e, $this->substitute); } $html .= $e; } } return $html; } function SubstituteCharsSIP(&$writehtml_a, &$writehtml_i, &$writehtml_e) { if (preg_match("/^(.*?)([\x{20000}-\x{2FFFF}]+)(.*)/u", $writehtml_e, $m)) { if (isset($this->CurrentFont['sipext']) && $this->CurrentFont['sipext']) { $font = $this->CurrentFont['sipext']; if (!in_array($font, $this->available_unifonts)) { return 0; } $writehtml_a[$writehtml_i] = $writehtml_e = $m[1]; array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3])); $this->subPos = $writehtml_i; return 4; } } return 0; } // mPDF 5.3.22 // If core font is selected in document which is not onlyCoreFonts - substitute with non-core font function SubstituteCharsNonCore(&$writehtml_a, &$writehtml_i, &$writehtml_e) { if (mb_convert_encoding(mb_convert_encoding($writehtml_e, $this->mb_enc, "UTF-8"), "UTF-8", $this->mb_enc) == $writehtml_e) { return 0; } $cw = &$this->CurrentFont['cw']; $unicode = $this->UTF8StringToArray($writehtml_e, false); $start = -1; $end = 0; $flag = 0; $ftype = ''; $u = array(); if (!$this->subArrMB) { include(_MPDF_PATH.'includes/subs_core.php'); $this->subArrMB['a'] = $aarr; $this->subArrMB['s'] = $sarr; $this->subArrMB['z'] = $zarr; } foreach($unicode AS $c => $char) { if (($char> 127 || ($flag==1 && $char==32)) && $char != 173 && (!isset($this->subArrMB['a'][$char]) || ($flag==1 && $char==32)) && ($char<1536 || ($char>1791 && $char < 2304) || $char>3455)) { if ($flag==0) { $start=$c; } $flag=1; $u[] = $char; } else if ($flag>0) { $end=$c-1; break; } } if ($flag>0 && !$end) { $end=count($unicode)-1; } if ($start==-1) { return 0; } // TRY IN BACKUP SUBS FONT if (!is_array($this->backupSubsFont)) { $this->backupSubsFont = array("$this->backupSubsFont"); } foreach($this->backupSubsFont AS $bsfctr=>$bsf) { if ($this->fonttrans[$bsf] == 'chelvetica' || $this->fonttrans[$bsf] == 'ctimes' || $this->fonttrans[$bsf] == 'ccourier') { continue; } $font = $bsf; unset($cw); $cw = ''; if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; } else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); } else { $prevFontFamily = $this->FontFamily; $prevFontStyle = $this->currentfontstyle; $prevFontSizePt = $this->FontSizePt; $this->SetFont($bsf, '', '', false); $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false); } if (!$cw) { continue; } $l = 0; foreach($u AS $char) { if ($char == 173 || $this->_charDefined($cw,$char) || ($char>1536 && $char<1791) || ($char>2304 && $char<3455 )) { $l++; } else { if ($l==0 && $bsfctr == (count($this->backupSubsFont)-1)) { // Not found even in last backup font $cont = mb_substr($writehtml_e, $start+1); $writehtml_e = mb_substr($writehtml_e, 0, $start+1, 'UTF-8'); array_splice($writehtml_a, $writehtml_i+1, 0, array('', $cont)); $this->subPos = $writehtml_i+1; return 2; } else { break; } } } if ($l > 0) { $patt = mb_substr($writehtml_e, $start, $l, 'UTF-8'); if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) { $writehtml_e = $m[1]; array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3])); $this->subPos = $writehtml_i+3; return 4; } } } unset($cw); return 0; } function SubstituteCharsMB(&$writehtml_a, &$writehtml_i, &$writehtml_e) { $cw = &$this->CurrentFont['cw']; $unicode = $this->UTF8StringToArray($writehtml_e, false); $start = -1; $end = 0; $flag = 0; $ftype = ''; $u = array(); foreach($unicode AS $c => $char) { if (($flag == 0 || $flag==2) && (!$this->_charDefined($cw,$char) || ($flag==2 && $char==32)) && $this->checkSIP && $char > 131071) { // Unicode Plane 2 (SIP) if (in_array($this->FontFamily ,$this->available_CJK_fonts)) { return 0; } if ($flag==0) { $start=$c; } $flag=2; $u[] = $char; } //else if (($flag == 0 || $flag==1) && $char != 173 && !$this->_charDefined($cw,$char) && ($char<1423 || ($char>3583 && $char < 11263))) { else if (($flag == 0 || $flag==1) && $char != 173 && (!$this->_charDefined($cw,$char) || ($flag==1 && $char==32)) && ($char<1536 || ($char>1791 && $char < 2304) || $char>3455)) { if ($flag==0) { $start=$c; } $flag=1; $u[] = $char; } else if ($flag>0) { $end=$c-1; break; } } if ($flag>0 && !$end) { $end=count($unicode)-1; } if ($start==-1) { return 0; } if ($flag == 2) { // SIP // Check if current CJK font has a ext-B related font if (isset($this->CurrentFont['sipext']) && $this->CurrentFont['sipext']) { $font = $this->CurrentFont['sipext']; unset($cw); $cw = ''; if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; } else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); } else { $prevFontFamily = $this->FontFamily; $prevFontStyle = $this->currentfontstyle; $prevFontSizePt = $this->FontSizePt; $this->SetFont($font, '', '', false); $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false); } if (!$cw) { return 0; } $l = 0; foreach($u AS $char) { if ($this->_charDefined($cw,$char) || $char > 131071) { $l++; } else { break; } } if ($l > 0) { $patt = mb_substr($writehtml_e, $start, $l); if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) { $writehtml_e = $m[1]; array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3])); $this->subPos = $writehtml_i+3; return 4; } } } // Check Backup SIP font (defined in config_fonts.php) if (isset($this->backupSIPFont) && $this->backupSIPFont) { if ($this->currentfontfamily != $this->backupSIPFont) { $font = $this->backupSIPFont; } else { unset($cw); return 0; } unset($cw); $cw = ''; if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; } else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); } else { $prevFontFamily = $this->FontFamily; $prevFontStyle = $this->currentfontstyle; $prevFontSizePt = $this->FontSizePt; $this->SetFont($this->backupSIPFont, '', '', false); $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false); } if (!$cw) { return 0; } $l = 0; foreach($u AS $char) { if ($this->_charDefined($cw,$char) || $char > 131071) { $l++; } else { break; } } if ($l > 0) { $patt = mb_substr($writehtml_e, $start, $l); if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) { $writehtml_e = $m[1]; array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3])); $this->subPos = $writehtml_i+3; return 4; } } } return 0; } // FIRST TRY CORE FONTS if (!$this->PDFA && !$this->PDFX) { $repl = array(); if (!$this->subArrMB) { include(_MPDF_PATH.'includes/subs_core.php'); $this->subArrMB['a'] = $aarr; $this->subArrMB['s'] = $sarr; $this->subArrMB['z'] = $zarr; } if (isset($this->subArrMB['a'][$u[0]])) { $font = 'tta'; $ftype = 'C'; foreach($u AS $char) { if ($this->subArrMB['a'][$char]) { $repl[] = $this->subArrMB['a'][$char]; } else { break; } } } else if (isset($this->subArrMB['z'][$u[0]])) { $font = 'ttz'; $ftype = 'C'; foreach($u AS $char) { if ($this->subArrMB['z'][$char]) { $repl[] = $this->subArrMB['z'][$char]; } else { break; } } } else if (isset($this->subArrMB['s'][$u[0]])) { $font = 'tts'; $ftype = 'C'; foreach($u AS $char) { if ($this->subArrMB['s'][$char]) { $repl[] = $this->subArrMB['s'][$char]; } else { break; } } } if ($ftype=='C') { $patt = mb_substr($writehtml_e, $start, count($repl)); if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) { $writehtml_e = $m[1]; array_splice($writehtml_a, $writehtml_i+1, 0, array($font, implode('|', $repl), '/'.$font, $m[3])); // e.g. <tts> $this->subPos = $writehtml_i+3; return 4; } return 0; } } // FIND IN DEFAULT FONT - removed mPDF 5.0 // LASTLY TRY IN BACKUP SUBS FONT if (!is_array($this->backupSubsFont)) { $this->backupSubsFont = array("$this->backupSubsFont"); } foreach($this->backupSubsFont AS $bsfctr=>$bsf) { if ($this->currentfontfamily != $bsf) { $font = $bsf; } else { continue; } unset($cw); $cw = ''; if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; } else if (file_exists(_MPDF_TTFONTDATAPATH.$font.'.cw.dat')) { $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); } else { $prevFontFamily = $this->FontFamily; $prevFontStyle = $this->currentfontstyle; $prevFontSizePt = $this->FontSizePt; $this->SetFont($bsf, '', '', false); $cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$font.'.cw.dat'); $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt, false); } if (!$cw) { continue; } $l = 0; foreach($u AS $char) { if ($char == 173 || $this->_charDefined($cw,$char) || ($char>1536 && $char<1791) || ($char>2304 && $char<3455 )) { // Arabic and Indic $l++; } else { if ($l==0 && $bsfctr == (count($this->backupSubsFont)-1)) { // Not found even in last backup font $cont = mb_substr($writehtml_e, $start+1); $writehtml_e = mb_substr($writehtml_e, 0, $start+1); array_splice($writehtml_a, $writehtml_i+1, 0, array('', $cont)); $this->subPos = $writehtml_i+1; return 2; } else { break; } } } if ($l > 0) { $patt = mb_substr($writehtml_e, $start, $l); if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) { $writehtml_e = $m[1]; array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3])); $this->subPos = $writehtml_i+3; return 4; } } } unset($cw); return 0; } function setHiEntitySubstitutions() { $entarr = array ( 'nbsp' => '160', 'iexcl' => '161', 'cent' => '162', 'pound' => '163', 'curren' => '164', 'yen' => '165', 'brvbar' => '166', 'sect' => '167', 'uml' => '168', 'copy' => '169', 'ordf' => '170', 'laquo' => '171', 'not' => '172', 'shy' => '173', 'reg' => '174', 'macr' => '175', 'deg' => '176', 'plusmn' => '177', 'sup2' => '178', 'sup3' => '179', 'acute' => '180', 'micro' => '181', 'para' => '182', 'middot' => '183', 'cedil' => '184', 'sup1' => '185', 'ordm' => '186', 'raquo' => '187', 'frac14' => '188', 'frac12' => '189', 'frac34' => '190', 'iquest' => '191', 'Agrave' => '192', 'Aacute' => '193', 'Acirc' => '194', 'Atilde' => '195', 'Auml' => '196', 'Aring' => '197', 'AElig' => '198', 'Ccedil' => '199', 'Egrave' => '200', 'Eacute' => '201', 'Ecirc' => '202', 'Euml' => '203', 'Igrave' => '204', 'Iacute' => '205', 'Icirc' => '206', 'Iuml' => '207', 'ETH' => '208', 'Ntilde' => '209', 'Ograve' => '210', 'Oacute' => '211', 'Ocirc' => '212', 'Otilde' => '213', 'Ouml' => '214', 'times' => '215', 'Oslash' => '216', 'Ugrave' => '217', 'Uacute' => '218', 'Ucirc' => '219', 'Uuml' => '220', 'Yacute' => '221', 'THORN' => '222', 'szlig' => '223', 'agrave' => '224', 'aacute' => '225', 'acirc' => '226', 'atilde' => '227', 'auml' => '228', 'aring' => '229', 'aelig' => '230', 'ccedil' => '231', 'egrave' => '232', 'eacute' => '233', 'ecirc' => '234', 'euml' => '235', 'igrave' => '236', 'iacute' => '237', 'icirc' => '238', 'iuml' => '239', 'eth' => '240', 'ntilde' => '241', 'ograve' => '242', 'oacute' => '243', 'ocirc' => '244', 'otilde' => '245', 'ouml' => '246', 'divide' => '247', 'oslash' => '248', 'ugrave' => '249', 'uacute' => '250', 'ucirc' => '251', 'uuml' => '252', 'yacute' => '253', 'thorn' => '254', 'yuml' => '255', 'OElig' => '338', 'oelig' => '339', 'Scaron' => '352', 'scaron' => '353', 'Yuml' => '376', 'fnof' => '402', 'circ' => '710', 'tilde' => '732', 'Alpha' => '913', 'Beta' => '914', 'Gamma' => '915', 'Delta' => '916', 'Epsilon' => '917', 'Zeta' => '918', 'Eta' => '919', 'Theta' => '920', 'Iota' => '921', 'Kappa' => '922', 'Lambda' => '923', 'Mu' => '924', 'Nu' => '925', 'Xi' => '926', 'Omicron' => '927', 'Pi' => '928', 'Rho' => '929', 'Sigma' => '931', 'Tau' => '932', 'Upsilon' => '933', 'Phi' => '934', 'Chi' => '935', 'Psi' => '936', 'Omega' => '937', 'alpha' => '945', 'beta' => '946', 'gamma' => '947', 'delta' => '948', 'epsilon' => '949', 'zeta' => '950', 'eta' => '951', 'theta' => '952', 'iota' => '953', 'kappa' => '954', 'lambda' => '955', 'mu' => '956', 'nu' => '957', 'xi' => '958', 'omicron' => '959', 'pi' => '960', 'rho' => '961', 'sigmaf' => '962', 'sigma' => '963', 'tau' => '964', 'upsilon' => '965', 'phi' => '966', 'chi' => '967', 'psi' => '968', 'omega' => '969', 'thetasym' => '977', 'upsih' => '978', 'piv' => '982', 'ensp' => '8194', 'emsp' => '8195', 'thinsp' => '8201', 'zwnj' => '8204', 'zwj' => '8205', 'lrm' => '8206', 'rlm' => '8207', 'ndash' => '8211', 'mdash' => '8212', 'lsquo' => '8216', 'rsquo' => '8217', 'sbquo' => '8218', 'ldquo' => '8220', 'rdquo' => '8221', 'bdquo' => '8222', 'dagger' => '8224', 'Dagger' => '8225', 'bull' => '8226', 'hellip' => '8230', 'permil' => '8240', 'prime' => '8242', 'Prime' => '8243', 'lsaquo' => '8249', 'rsaquo' => '8250', 'oline' => '8254', 'frasl' => '8260', 'euro' => '8364', 'image' => '8465', 'weierp' => '8472', 'real' => '8476', 'trade' => '8482', 'alefsym' => '8501', 'larr' => '8592', 'uarr' => '8593', 'rarr' => '8594', 'darr' => '8595', 'harr' => '8596', 'crarr' => '8629', 'lArr' => '8656', 'uArr' => '8657', 'rArr' => '8658', 'dArr' => '8659', 'hArr' => '8660', 'forall' => '8704', 'part' => '8706', 'exist' => '8707', 'empty' => '8709', 'nabla' => '8711', 'isin' => '8712', 'notin' => '8713', 'ni' => '8715', 'prod' => '8719', 'sum' => '8721', 'minus' => '8722', 'lowast' => '8727', 'radic' => '8730', 'prop' => '8733', 'infin' => '8734', 'ang' => '8736', 'and' => '8743', 'or' => '8744', 'cap' => '8745', 'cup' => '8746', 'int' => '8747', 'there4' => '8756', 'sim' => '8764', 'cong' => '8773', 'asymp' => '8776', 'ne' => '8800', 'equiv' => '8801', 'le' => '8804', 'ge' => '8805', 'sub' => '8834', 'sup' => '8835', 'nsub' => '8836', 'sube' => '8838', 'supe' => '8839', 'oplus' => '8853', 'otimes' => '8855', 'perp' => '8869', 'sdot' => '8901', 'lceil' => '8968', 'rceil' => '8969', 'lfloor' => '8970', 'rfloor' => '8971', 'lang' => '9001', 'rang' => '9002', 'loz' => '9674', 'spades' => '9824', 'clubs' => '9827', 'hearts' => '9829', 'diams' => '9830', ); foreach($entarr AS $key => $val) { $this->entsearch[] = '&'.$key.';'; $this->entsubstitute[] = code2utf($val); } } function SubstituteHiEntities($html) { // converts html_entities > ASCII 127 to unicode // Leaves in particular &lt; to distinguish from tag marker if (count($this->entsearch)) { $html = str_replace($this->entsearch,$this->entsubstitute,$html); } return $html; } // Edited v1.2 Pass by reference; option to continue if invalid UTF-8 chars function is_utf8(&$string) { if ($string === mb_convert_encoding(mb_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32")) { return true; } else { if ($this->ignore_invalid_utf8) { $string = mb_convert_encoding(mb_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32") ; return true; } else { return false; } } } function purify_utf8($html,$lo=true) { // For HTML // Checks string is valid UTF-8 encoded // converts html_entities > ASCII 127 to UTF-8 // Only exception - leaves low ASCII entities e.g. &lt; &amp; etc. // Leaves in particular &lt; to distinguish from tag marker if (!$this->is_utf8($html)) { echo "<p><b>HTML contains invalid UTF-8 character(s)</b></p>"; while (mb_convert_encoding(mb_convert_encoding($html, "UTF-32", "UTF-8"), "UTF-8", "UTF-32") != $html) { $a = iconv('UTF-8', 'UTF-8', $html); echo ($a); $pos = $start = strlen($a); $err = ''; while ( ord(substr($html,$pos,1)) > 128 ) { $err .= '[[#'.ord(substr($html,$pos,1)).']]'; $pos++; } echo '<span style="color:red; font-weight:bold">'.$err.'</span>'; $html = substr($html, $pos); } echo $html; $this->Error(""); } $html = preg_replace("/\r/", "", $html ); // converts html_entities > ASCII 127 to UTF-8 // Leaves in particular &lt; to distinguish from tag marker $html = $this->SubstituteHiEntities($html); // converts all &#nnn; or &#xHHH; to UTF-8 multibyte // If $lo==true then includes ASCII < 128 $html = strcode2utf($html,$lo); return ($html); } function purify_utf8_text($txt) { // For TEXT // Make sure UTF-8 string of characters if (!$this->is_utf8($txt)) { $this->Error("Text contains invalid UTF-8 character(s)"); } $txt = preg_replace("/\r/", "", $txt ); return ($txt); } function all_entities_to_utf8($txt) { // converts txt_entities > ASCII 127 to UTF-8 // Leaves in particular &lt; to distinguish from tag marker $txt = $this->SubstituteHiEntities($txt); // converts all &#nnn; or &#xHHH; to UTF-8 multibyte $txt = strcode2utf($txt); $txt = $this->lesser_entity_decode($txt); return ($txt); } // ==================================================== /*-- BARCODES --*/ // UPC/EAN barcode // EAN13, EAN8, UPCA, UPCE, ISBN, ISSN // Accepts 12 or 13 digits with or without - hyphens function WriteBarcode($code, $showtext=1, $x='', $y='', $size=1, $border=0, $paddingL=1, $paddingR=1, $paddingT=2, $paddingB=2, $height=1, $bgcol=false, $col=false, $btype='ISBN', $supplement='0', $supplement_code='', $k=1) { if (empty($code)) { return; } $codestr = $code; $code = preg_replace('/\-/','',$code); if (!class_exists('PDFBarcode', false)) { include(_MPDF_PATH.'classes/barcode.php'); } $this->barcode = new PDFBarcode(); if ($btype == 'ISSN' || $btype == 'ISBN') { $arrcode = $this->barcode->getBarcodeArray($code, 'EAN13'); } else { $arrcode = $this->barcode->getBarcodeArray($code, $btype); } if ($arrcode === false) { $this->Error('Error in barcode string: '.$codestr); } if((($btype=='EAN13' || $btype=='ISBN' || $btype=='ISSN') && strlen($code) == 12) || ($btype=='UPCA' && strlen($code) == 11) || ($btype=='UPCE' && strlen($code) == 11) || ($btype=='EAN8' && strlen($code) == 7)) { $code .= $arrcode['checkdigit']; if (stristr($codestr,'-')) { $codestr .= '-' . $arrcode['checkdigit']; } else { $codestr .= $arrcode['checkdigit']; } } if ($btype == 'ISBN') { $codestr = 'ISBN '.$codestr; } if ($btype == 'ISSN') { $codestr = 'ISSN '.$codestr; } if (empty($x)) { $x = $this->x; } if (empty($y)) { $y = $this->y; } // set foreground color $prevDrawColor = $this->DrawColor; $prevTextColor = $this->TextColor; $prevFillColor = $this->FillColor; $lw = $this->LineWidth; $this->SetLineWidth(0.01); $size /= $k; // in case resized in a table $xres = $arrcode['nom-X'] * $size; $llm = $arrcode['lightmL'] * $arrcode['nom-X'] * $size; // Left Light margin $rlm = $arrcode['lightmR'] * $arrcode['nom-X'] * $size; // Right Light margin $bcw = ($arrcode["maxw"] * $xres); // Barcode width = Should always be 31.35mm * $size $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins $ow = $fbw + $paddingL + $paddingR; // Full overall width incl. user-defined padding $fbwi = $fbw - 2; // Full barcode width incl. light margins - 2mm - for isbn string // cf. http://www.gs1uk.org/downloads/bar_code/Bar coding getting it right.pdf $num_height = 3 * $size; // Height of numerals $fbh = $arrcode['nom-H'] * $size * $height; // Full barcode height incl. numerals $bch = $fbh - (1.5 * $size); // Barcode height of bars (3mm for numerals) if (($btype=='EAN13' && $showtext) || $btype == 'ISSN' || $btype == 'ISBN') { // Add height for ISBN string + margin from top of bars $tisbnm = 1.5 * $size; // Top margin between isbn (if shown) & bars $codestr_fontsize = 2.1 * $size; $paddingT += $codestr_fontsize + $tisbnm ; } $oh = $fbh + $paddingT + $paddingB; // Full overall height incl. user-defined padding // PRINT border background color $xpos = $x; $ypos = $y; if ($col) { // from <barcode /> // mPDF 5.3.A4 $this->SetDColor($col); $this->SetTColor($col); } else { $this->SetDColor($this->ConvertColor(0)); $this->SetTColor($this->ConvertColor(0)); } if ($bgcol) { // mPDF 5.3.A4 $this->SetFColor($bgcol); } else { $this->SetFColor($this->ConvertColor(255)); } if (!$bgcol && !$col) { // fn. called directly - not via HTML if ($border) { $fillb = 'DF'; } else { $fillb = 'F'; } $this->Rect($xpos, $ypos, $ow, $oh, $fillb); } // PRINT BARS $xpos = $x + $paddingL + $llm ; $ypos = $y + $paddingT; if ($col) { $this->SetFColor($col); } // mPDF 5.3.A4 else { $this->SetFColor($this->ConvertColor(0)); } if ($arrcode !== false) { foreach ($arrcode["bcode"] AS $v) { $bw = ($v["w"] * $xres); if ($v["t"]) { // draw a vertical bar $this->Rect($xpos, $ypos, $bw, $bch, 'F'); } $xpos += $bw; } } // print text $prevFontFamily = $this->FontFamily; $prevFontStyle = $this->FontStyle; $prevFontSizePt = $this->FontSizePt; // ISBN string if (($btype=='EAN13' && $showtext) || $btype=='ISBN' || $btype=='ISSN') { if ($this->onlyCoreFonts) { $this->SetFont('chelvetica'); } else { $this->SetFont('sans'); } if ($bgcol) { $this->SetFColor($bgcol); } // mPDF 5.3.A4 else { $this->SetFColor($this->ConvertColor(255)); } $this->x = $x + $paddingL + 1; // 1mm left margin (cf. $fbwi above) // max width is $fbwi $loop = 0; while ( $loop == 0 ) { $this->SetFontSize($codestr_fontsize*1.4*_MPDFK, false); // don't write $sz = $this->GetStringWidth( $codestr ); if ($sz > $fbwi) $codestr_fontsize -= 0.1; else $loop ++; } $this->SetFont('','',$codestr_fontsize*1.4*_MPDFK, true, true); // * 1.4 because font height is only 7/10 of given mm // WORD SPACING if ($fbwi > $sz) { $xtra = $fbwi - $sz; $charspacing = $xtra / (strlen($codestr)-1); if ($charspacing) { $this->_out(sprintf('BT %.3F Tc ET',$charspacing*_MPDFK)); } } $this->y = $y + $paddingT - ($codestr_fontsize ) - $tisbnm ; $this->Cell($fbw , $codestr_fontsize, $codestr); if ($charspacing) { $this->_out('BT 0 Tc ET'); } } // Bottom NUMERALS if ($this->onlyCoreFonts) { $this->SetFont('mono'); } else { if (in_array('ocrb',$this->available_unifonts)) { $this->SetFont('ocrb'); } else { $this->SetFont('mono'); } } // mPDF 5.3.A9 if (isset($this->CurrentFont['desc']['CapHeight'])) { $fh = (1000/$this->CurrentFont['desc']['CapHeight']); } else if (isset($this->CurrentFont['desc']['Ascent'])) { $fh = (1000/$this->CurrentFont['desc']['Ascent']); } else { $fh = 1.2; } $charRO = ''; if ($btype=='EAN13' || $btype=='ISBN' || $btype=='ISSN') { $outerfontsize = 3; // Inner fontsize = 3 $outerp = $xres * 4; $innerp = $xres * 2.5; $textw = ($bcw*0.5) - $outerp - $innerp; $chars = 6; // number of numerals in each half $charLO = substr($code,0,1); // Left Outer $charLI = substr($code,1,6); // Left Inner $charRI = substr($code,7,6); // Right Inner if (!$supplement) $charRO = '>'; // Right Outer } else if ($btype=='UPCA') { $outerfontsize = 2.3; // Inner fontsize = 3 $outerp = $xres * 10; $innerp = $xres * 2.5; $textw = ($bcw*0.5) - $outerp - $innerp; $chars = 5; $charLO = substr($code,0,1); // Left Outer $charLI = substr($code,1,5); // Left Inner $charRI = substr($code,6,5); // Right Inner $charRO = substr($code,11,1); // Right Outer } else if ($btype=='UPCE') { $outerfontsize = 2.3; // Inner fontsize = 3 $outerp = $xres * 4; $innerp = 0; $textw = ($bcw*0.5) - $outerp - $innerp; $chars = 3; $upce_code = $arrcode['code']; $charLO = substr($code,0,1); // Left Outer $charLI = substr($upce_code,0,3); // Left Inner $charRI = substr($upce_code,3,3); // Right Inner $charRO = substr($code,11,1); // Right Outer } else if ($btype=='EAN8') { $outerfontsize = 3; // Inner fontsize = 3 $outerp = $xres * 4; $innerp = $xres * 2.5; $textw = ($bcw*0.5) - $outerp - $innerp; $chars = 4; $charLO = '<'; // Left Outer $charLI = substr($code,0,4); // Left Inner $charRI = substr($code,4,4); // Right Inner if (!$supplement) $charRO = '>'; // Right Outer } $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters) if (!$this->usingCoreFont) { $cw = $this->_getCharWidth($this->CurrentFont['cw'],32)*3*$fh*$size/1000; } // character width at 3mm else { $cw = $this->_getCharWidth($this->CurrentFont['cw'],48)*3*$fh*$size/1000; } // 48 == char "0" // Outer left character $y_text = $y + $paddingT + $bch - ($num_height/2); $y_text_outer = $y + $paddingT + $bch - ($num_height*($outerfontsize/3)/2); $this->x = $x + $paddingL - ($cw*($outerfontsize/3)*0.1); // 0.1 is correction as char does not fill full width; $this->y = $y_text_outer; $this->Cell($cw, $num_height, $charLO ); // WORD SPACING for inner chars $xtra = $textw - ($cw*$chars); $charspacing = $xtra / ($chars-1); if ($charspacing) { $this->_out(sprintf('BT %.3F Tc ET',$charspacing*_MPDFK)); } if ($bgcol) { $this->SetFColor($bgcol); } // mPDF 5.3.A4 else { $this->SetFColor($this->ConvertColor(255)); } $this->SetFontSize(3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters) // Inner left half characters $this->x = $x + $paddingL + $llm + $outerp; $this->y = $y_text; $this->Cell($textw, $num_height, $charLI , 0, 0, '', 1); // Inner right half characters $this->x = $x + $paddingL + $llm + ($bcw*0.5) + $innerp; $this->y = $y_text; $this->Cell($textw, $num_height, $charRI , 0, 0, '', 1); if ($charspacing) { $this->_out('BT 0 Tc ET'); } // Outer Right character $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters) $this->x = $x + $paddingL + $llm + $bcw + $rlm - ($cw*($outerfontsize/3)*0.9); // 0.9 is correction as char does not fill full width $this->y = $y_text_outer; $this->Cell($cw*($outerfontsize/3), $num_height, $charRO , 0, 0, 'R'); if ($supplement) { // EAN-2 or -5 Supplement // PRINT BARS $supparrcode = $this->barcode->getBarcodeArray($supplement_code, 'EAN'.$supplement); if ($supparrcode === false) { $this->Error('Error in barcode string (supplement): '.$codestr.' '.$supplement_code); } if(strlen($supplement_code) != $supplement) { $this->Error('Barcode supplement incorrect: '.$supplement_code); } $llm = $fbw - (($arrcode['lightmR'] - $supparrcode['sepM']) * $arrcode['nom-X'] * $size); // Left Light margin $rlm = $arrcode['lightmR'] * $arrcode['nom-X'] * $size; // Right Light margin $bcw = ($supparrcode["maxw"] * $xres); // Barcode width = Should always be 31.35mm * $size $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins $ow = $fbw + $paddingL + $paddingR; // Full overall width incl. user-defined padding $bch = $fbh - (1.5 * $size) - ($num_height + 0.5); // Barcode height of bars (3mm for numerals) $xpos = $x + $paddingL + $llm ; $ypos = $y + $paddingT + $num_height + 0.5; if ($col) { $this->SetFColor($col); } // mPDF 5.3.A4 else { $this->SetFColor($this->ConvertColor(0)); } if ($supparrcode !== false) { foreach ($supparrcode["bcode"] AS $v) { $bw = ($v["w"] * $xres); if ($v["t"]) { // draw a vertical bar $this->Rect($xpos, $ypos, $bw, $bch, 'F'); } $xpos += $bw; } } // Characters if ($bgcol) { $this->SetFColor($bgcol); } // mPDF 5.3.A4 else { $this->SetFColor($this->ConvertColor(255)); } $this->SetFontSize(3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters) $this->x = $x + $paddingL + $llm; $this->y = $y + $paddingT; $this->Cell($bcw, $num_height, $supplement_code, 0, 0, 'C'); // Outer Right character (light margin) $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*_MPDFK); // 3mm numerals (FontSize is larger to account for space above/below characters) $this->x = $x + $paddingL + $llm + $bcw + $rlm - ($cw*0.9); // 0.9 is correction as char does not fill full width $this->y = $y + $paddingT; $this->Cell($cw*($outerfontsize/3), $num_height, '>', 0, 0, 'R'); } // Restore ************** $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt); $this->DrawColor = $prevDrawColor; $this->TextColor = $prevTextColor; $this->FillColor = $prevFillColor; $this->SetLineWidth($lw); $this->SetY($y); } // ==================================================== // POSTAL and OTHER barcodes function WriteBarcode2($code, $x='', $y='', $size=1, $height=1, $bgcol=false, $col=false, $btype='IMB', $print_ratio='', $k=1) { if (empty($code)) { return; } if (!class_exists('PDFBarcode', false)) { include(_MPDF_PATH.'classes/barcode.php'); } $this->barcode = new PDFBarcode(); $arrcode = $this->barcode->getBarcodeArray($code, $btype, $print_ratio); if ($arrcode === false) { $this->Error('Error in barcode string: '.$code); } if (empty($x)) { $x = $this->x; } if (empty($y)) { $y = $this->y; } $prevDrawColor = $this->DrawColor; $prevTextColor = $this->TextColor; $prevFillColor = $this->FillColor; $lw = $this->LineWidth; $this->SetLineWidth(0.01); $size /= $k; // in case resized in a table $xres = $arrcode['nom-X'] * $size; if ($btype == 'IMB' || $btype == 'RM4SCC' || $btype == 'KIX' || $btype == 'POSTNET' || $btype == 'PLANET') { $llm = $arrcode['quietL'] / $k; // Left Quiet margin $rlm = $arrcode['quietR'] / $k; // Right Quiet margin $tlm = $blm = $arrcode['quietTB'] / $k; $height=1; // Overrides } else if (in_array($btype, array('C128A','C128B','C128C','EAN128A','EAN128B','EAN128C','C39','C39+','C39E','C39E+','S25','S25+','I25','I25+','I25B','I25B+','C93','MSI','MSI+','CODABAR','CODE11'))) { $llm = $arrcode['lightmL'] * $xres; // Left Quiet margin $rlm = $arrcode['lightmR'] * $xres; // Right Quiet margin $tlm = $blm = $arrcode['lightTB'] * $xres * $height; } $bcw = ($arrcode["maxw"] * $xres); $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins $bch = ($arrcode["nom-H"] * $size * $height); $fbh = $bch + $tlm + $blm; // Full barcode height // PRINT border background color $xpos = $x; $ypos = $y; if ($col) { // from <barcode /> // mPDF 5.3.A4 $this->SetDColor($col); $this->SetTColor($col); } else { $this->SetDColor($this->ConvertColor(0)); $this->SetTColor($this->ConvertColor(0)); } if ($bgcol) { // from <barcode /> // mPDF 5.3.A4 $this->SetFColor($bgcol); } else { $this->SetFColor($this->ConvertColor(255)); } // PRINT BARS if ($col) { $this->SetFColor($col); } // mPDF 5.3.A4 else { $this->SetFColor($this->ConvertColor(0)); } $xpos = $x + $llm ; if ($arrcode !== false) { foreach ($arrcode["bcode"] AS $v) { $bw = ($v["w"] * $xres); if ($v["t"]) { $ypos = $y + $tlm + ($bch * $v['p'] / $arrcode['maxh']); $this->Rect($xpos, $ypos, $bw, ($v['h'] * $bch / $arrcode['maxh']), 'F'); } $xpos += $bw; } } // PRINT BEARER BARS if ($btype == 'I25B' || $btype == 'I25B+') { $this->Rect($x, $y, $fbw, ($arrcode['lightTB'] * $xres * $height), 'F'); $this->Rect($x, $y+$tlm+$bch, $fbw, ($arrcode['lightTB'] * $xres * $height), 'F'); } // Restore ************** $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt); $this->DrawColor = $prevDrawColor; $this->TextColor = $prevTextColor; $this->FillColor = $prevFillColor; $this->SetLineWidth($lw); $this->SetY($y); } /*-- END BARCODES --*/ // ==================================================== // ==================================================== function StartTransform($returnstring=false) { if ($returnstring) { return('q'); } else { $this->_out('q'); } } function StopTransform($returnstring=false) { if ($returnstring) { return('Q'); } else { $this->_out('Q'); } } function transformScale($s_x, $s_y, $x='', $y='', $returnstring=false) { if ($x === '') { $x=$this->x; } if ($y === '') { $y=$this->y; } if (($s_x == 0) OR ($s_y == 0)) { $this->Error('Please do not use values equal to zero for scaling'); } $y = ($this->h - $y) * _MPDFK; $x *= _MPDFK; //calculate elements of transformation matrix $s_x /= 100; $s_y /= 100; $tm[0] = $s_x; $tm[1] = 0; $tm[2] = 0; $tm[3] = $s_y; $tm[4] = $x * (1 - $s_x); $tm[5] = $y * (1 - $s_y); //scale the coordinate system if ($returnstring) { return($this->_transform($tm, true)); } else { $this->_transform($tm); } } function transformTranslate($t_x, $t_y, $returnstring=false) { //calculate elements of transformation matrix $tm[0] = 1; $tm[1] = 0; $tm[2] = 0; $tm[3] = 1; $tm[4] = $t_x * _MPDFK; $tm[5] = -$t_y * _MPDFK; //translate the coordinate system if ($returnstring) { return($this->_transform($tm, true)); } else { $this->_transform($tm); } } function transformRotate($angle, $x='', $y='', $returnstring=false) { if ($x === '') { $x=$this->x; } if ($y === '') { $y=$this->y; } $angle = -$angle; $y = ($this->h - $y) * _MPDFK; $x *= _MPDFK; //calculate elements of transformation matrix $tm[0] = cos(deg2rad($angle)); $tm[1] = sin(deg2rad($angle)); $tm[2] = -$tm[1]; $tm[3] = $tm[0]; $tm[4] = $x + $tm[1] * $y - $tm[0] * $x; $tm[5] = $y - $tm[0] * $y - $tm[1] * $x; //rotate the coordinate system around ($x,$y) if ($returnstring) { return($this->_transform($tm, true)); } else { $this->_transform($tm); } } function _transform($tm, $returnstring=false) { // mPDF 5.3.53 if ($returnstring) { return(sprintf('%.4F %.4F %.4F %.4F %.4F %.4F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); } else { $this->_out(sprintf('%.4F %.4F %.4F %.4F %.4F %.4F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); } } /*-- INDIC --*/ // INDIC ============================ // This conversion can only be done when font is set function ConvertIndic(&$str) { if (preg_match('/^ind_([a-z]{2})_/',$this->currentfontfamily, $m)) { if (!class_exists('indic', false)) { include(_MPDF_PATH.'classes/indic.php'); } if (empty($this->indic)) { $this->indic = new indic($this); } $earr = $this->UTF8StringToArray($str, false); $str = $this->indic->substituteIndic($earr, $m[1], $this->currentfontfamily); } } /*-- END INDIC --*/ // AUTOFONT ========================= function AutoFont($html) { if ($this->onlyCoreFonts) { return $html; } // mPDF 5.3.22 $this->useLang = true; if ($this->autoFontGroupSize == 1) { $extra = $this->pregASCIIchars1; } else if ($this->autoFontGroupSize == 3) { $extra = $this->pregASCIIchars3; } else { $extra = $this->pregASCIIchars2; } $n = ''; $a=preg_split('/<(.*?)>/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE); foreach($a as $i => $e) { if($i%2==0) { $e = strcode2utf($e); $e = $this->lesser_entity_decode($e); // Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag## /*-- CJK-FONTS --*/ if ($this->autoFontGroups & AUTOFONT_CJK) { $e = preg_replace("/([".$this->pregCJKchars.$extra."]*[".$this->pregCJKchars."][".$this->pregCJKchars.$extra."]*)/ue", '$this->replaceCJK(stripslashes(\'\\1\'))', $e); } /*-- END CJK-FONTS --*/ /*-- RTL --*/ if ($this->autoFontGroups & AUTOFONT_RTL) { // HEBREW $e = preg_replace("/([".$this->pregHEBchars .$extra."]*[".$this->pregHEBchars ."][".$this->pregHEBchars .$extra."]*)/u", "\xef\xbf\xb0span lang=\"he\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e); // All Arabic $e = preg_replace("/([".$this->pregARABICchars .$extra."]*[".$this->pregARABICchars ."][".$this->pregARABICchars .$extra."]*)/ue", '$this->replaceArabic(stripslashes(\'\\1\'))', $e); } /*-- END RTL --*/ /*-- INDIC --*/ // INDIC if ($this->autoFontGroups & AUTOFONT_INDIC) { // Bengali $e = preg_replace("/([".$this->pregBNchars .$this->pregINDextra."]*[".$this->pregBNchars ."][".$this->pregBNchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"bn\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e); // Devanagari (= script for Hindi, Nepali + Sindhi) $e = preg_replace("/([".$this->pregHIchars .$this->pregINDextra."]*[".$this->pregHIchars ."][".$this->pregHIchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"hi\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e); // Gujarati $e = preg_replace("/([".$this->pregGUchars .$this->pregINDextra."]*[".$this->pregGUchars ."][".$this->pregGUchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"gu\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e); // Malayalam $e = preg_replace("/([".$this->pregMLchars .$this->pregINDextra."]*[".$this->pregMLchars ."][".$this->pregMLchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"ml\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e); // Kannada $e = preg_replace("/([".$this->pregKNchars .$this->pregINDextra."]*[".$this->pregKNchars ."][".$this->pregKNchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"kn\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e); // Oriya $e = preg_replace("/([".$this->pregORchars .$this->pregINDextra."]*[".$this->pregORchars ."][".$this->pregORchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"or\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e); // Punjabi ?= Gurmuhki $e = preg_replace("/([".$this->pregPAchars .$this->pregINDextra."]*[".$this->pregPAchars ."][".$this->pregPAchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"pa\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e); // Tamil $e = preg_replace("/([".$this->pregTAchars .$this->pregINDextra."]*[".$this->pregTAchars ."][".$this->pregTAchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"ta\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e); // Telugu $e = preg_replace("/([".$this->pregTEchars .$this->pregINDextra."]*[".$this->pregTEchars ."][".$this->pregTEchars .$this->pregINDextra."]*)/u", "\xef\xbf\xb0span lang=\"te\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e); } /*-- END INDIC --*/ if ($this->autoFontGroups & AUTOFONT_THAIVIET) { // THAI $e = preg_replace("/([\x{0E00}-\x{0E7F}".$extra."]*[\x{0E00}-\x{0E7F}][\x{0E00}-\x{0E7F}".$extra."]*)/u", "\xef\xbf\xb0span lang=\"th\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e); // Vietnamese $e = preg_replace("/([".$this->pregVIETchars .$this->pregVIETPluschars ."]*[".$this->pregVIETchars ."][".$this->pregVIETchars .$this->pregVIETPluschars ."]*)/u", "\xef\xbf\xb0span lang=\"vi\"\xef\xbf\xb1\\1\xef\xbf\xb0/span\xef\xbf\xb1", $e); } $e = preg_replace('/[&]/','&amp;',$e); $e = preg_replace('/[<]/','&lt;',$e); $e = preg_replace('/[>]/','&gt;',$e); $e = preg_replace("/(\xef\xbf\xb0span lang=\"([a-z\-A-Z]{2,5})\"\xef\xbf\xb1)\s+/",' \\1',$e); $e = preg_replace("/[ ]+(\xef\xbf\xb0\/span\xef\xbf\xb1)/",'\\1 ',$e); $e = preg_replace("/\xef\xbf\xb0span lang=\"([a-z\-A-Z]{2,5})\"\xef\xbf\xb1/","\xef\xbf\xb0span lang=\"\\1\" class=\"lang_\\1\"\xef\xbf\xb1",$e); $e = preg_replace("/\xef\xbf\xb0/",'<',$e); $e = preg_replace("/\xef\xbf\xb1/",'>',$e); $a[$i] = $e; } else { $a[$i] = '<'.$e.'>'; } } $n = implode('',$a); return $n; } /*-- CJK-FONTS --*/ function replaceCJK($str) { // Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag## if (preg_match("/[".$this->pregUHCchars."]/u", $str)) { return "\xef\xbf\xb0span lang=\"ko\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1"; } else if (preg_match("/[".$this->pregSJISchars."]/u", $str)) { return "\xef\xbf\xb0span lang=\"ja\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1"; } // if in Unicode Plane 2, probably HKCS (incl in BIG5) if not Japanese else if (preg_match("/[\x{20000}-\x{2FFFF}]/u", $str)) { return "\xef\xbf\xb0span lang=\"zh-HK\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1"; } else{ return "\xef\xbf\xb0span lang=\"zh-CN\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1"; } return $str; } /*-- END CJK-FONTS --*/ /*-- RTL --*/ function replaceArabic($str) { // PASHTO, SINDHI, URDU, ARABIC, PERSIAN $persian = "\x{067E}\x{0686}\x{0698}\x{06AF}"; $urdu = "\x{0679}\x{0688}\x{0691}\x{06BA}\x{06BE}\x{06C1}\x{06D2}"; $pashto = "\x{067C}\x{0681}\x{0685}\x{0689}\x{0693}\x{0696}\x{069A}\x{06BC}\x{06D0}"; $sindhi = "\x{067A}\x{067B}\x{067D}\x{067F}\x{0680}\x{0684}\x{068D}\x{068A}\x{068F}\x{068C}\x{0687}\x{0683}\x{0699}\x{06AA}\x{06A6}\x{06BB}\x{06B1}\x{06B3}"; // Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag## if (preg_match("/[".$this->pregNonARABICchars ."]/u", $str) ) { if (preg_match("/[".$sindhi ."]/u", $str) ) { return "\xef\xbf\xb0span lang=\"sd\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1"; } else if (preg_match("/[".$urdu ."]/u", $str) ) { return "\xef\xbf\xb0span lang=\"ur\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1"; } else if (preg_match("/[".$pashto ."]/u", $str) ) { return "\xef\xbf\xb0span lang=\"ps\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1"; } else if (preg_match("/[".$persian ."]/u", $str) ) { return "\xef\xbf\xb0span lang=\"fa\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1"; } else { return "\xef\xbf\xb0span lang=\"ar\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1"; } } if (preg_match("/[".$persian ."]/u", $str) ) { return "\xef\xbf\xb0span lang=\"fa\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1"; } else { return "\xef\xbf\xb0span lang=\"ar\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1"; } return $str; } // ARABIC =========================== function InitArabic() { // JOIN TO FOLLOWING LETTER IN LOGICAL ORDER // U+060c U+061f; U+061b; U+0640; U+0626; U+0628; U+062a; U+062b; U+062c; U+062d; U+062e; U+0633; U+0634; U+0635; U+0636; U+0637; // U+0638; U+0639; U+063a; U+0641; U+0642; U+0643; U+0644; U+0645; U+0646; U+0647; U+064a; U+06a9; U+06cc; U+0686; U+06af; U+067e; // U+06D0; U+0681; U+06C1; $this->arabPrevLink = "\xd8\x8c\xd8\x9f\xd8\x9b\xd9\x80\xd8\xa6\xd8\xa8\xd8\xaa\xd8\xab\xd8\xac\xd8\xad\xd8\xae\xd8\xb3\xd8\xb4\xd8\xb5\xd8\xb6\xd8\xb7\xd8\xb8\xd8\xb9\xd8\xba\xd9\x81\xd9\x82\xd9\x83\xd9\x84\xd9\x85\xd9\x86\xd9\x87\xd9\x8a\xda\xa9\xdb\x8c\xda\x86\xda\xaf\xd9\xbe\xdb\x90\xda\x81\xdb\x81"; // \xda\x98 (U+0698) removed from arabPrevLink // \xd9\xb1 (U+0671) added to arabNextLink & final form added to Persian Glyphs (FB51) // JOIN TO PREVIOUS LETTER IN LOGICAL ORDER // U+0640 U+0622; U+0623; U+0624; U+0625; U+0627; U+0626; U+0628; U+0629; U+062a; U+062b; U+062c; U+062d; U+062e; U+062f; U+0630; // U+0631; U+0632; U+0633; U+0634; U+0635; U+0636; U+0637; U+0638; U+0639; U+063a; U+0641; U+0642; U+0643; U+0644; U+0645; U+0646; // U+0647; U+0648; U+0649; U+064a; U+06a9; U+06cc; U+0686; U+06af; U+0698; U+067e; // U+0671; U+06D0; U+0696; U+0693; U+06D2; U+06C1; $this->arabNextLink = "\xd9\x80\xd8\xa2\xd8\xa3\xd8\xa4\xd8\xa5\xd8\xa7\xd8\xa6\xd8\xa8\xd8\xa9\xd8\xaa\xd8\xab\xd8\xac\xd8\xad\xd8\xae\xd8\xaf\xd8\xb0\xd8\xb1\xd8\xb2\xd8\xb3\xd8\xb4\xd8\xb5\xd8\xb6\xd8\xb7\xd8\xb8\xd8\xb9\xd8\xba\xd9\x81\xd9\x82\xd9\x83\xd9\x84\xd9\x85\xd9\x86\xd9\x87\xd9\x88\xd9\x89\xd9\x8a\xda\xa9\xdb\x8c\xda\x86\xda\xaf\xda\x98\xd9\xbe\xd9\xb1\xdb\x90\xda\x96\xda\x93\xdb\x92\xdb\x81"; // U+064b U+064c; U+064d; U+064e; U+064f; U+0650; U+0651; U+0652; $this->arabVowels = "\xd9\x8b\xd9\x8c\xd9\x8d\xd9\x8e\xd9\x8f\xd9\x90\xd9\x91\xd9\x92"; // Added chars that may not be vowels but should not interrupt joining // U+0670; U+0653; $this->arabVowels .= "\xd9\xb0\xd9\x93"; // ? should also add - U+615, 616, 617-61A, 653-65E, 6D6-6DC, 6DF-6E4, 6E7, 6E8, 6EA-6ED // DON'T ADD ANY MORE TO ARABGLYPHS - cf. ArabJoin() counts 48 then does ligatures - use PersianGlyphs below // ISOLATED FORM :: FINAL :: INITIAL :: MEDIAL // U+064B; U+064C; U+064D; U+064E; U+064F; U+0650; U+0651; U+0652; $this->arabGlyphs = "\xd9\x8b\xd9\x8c\xd9\x8d\xd9\x8e\xd9\x8f\xd9\x90\xd9\x91\xd9\x92"; $this->arabHex = '064B064B064B064B064C064C064C064C064D064D064D064D064E064E064E064E064F064F064F064F065006500650065006510651065106510652065206520652'; // U+0621; U+0622; U+0623; U+0624; U+0625; U+0626; U+0627; U+0628; $this->arabGlyphs .= "\xd8\xa1\xd8\xa2\xd8\xa3\xd8\xa4\xd8\xa5\xd8\xa6\xd8\xa7\xd8\xa8"; $this->arabHex .= '06210621062106210622FE820622FE820623FE840623FE840624FE860624FE860625FE880625FE880626FE8AFE8BFE8C0627FE8E0627FE8E0628FE90FE91FE92'; // U+0629; U+062A; U+062B; U+062C; U+062D; U+062E; U+062F; U+0630; $this->arabGlyphs .= "\xd8\xa9\xd8\xaa\xd8\xab\xd8\xac\xd8\xad\xd8\xae\xd8\xaf\xd8\xb0"; $this->arabHex .= '0629FE940629FE94062AFE96FE97FE98062BFE9AFE9BFE9C062CFE9EFE9FFEA0062DFEA2FEA3FEA4062EFEA6FEA7FEA8062FFEAA062FFEAA0630FEAC0630FEAC'; // U+0631; U+0632; U+0633; U+0634; U+0635; U+0636; U+0637; U+0638; $this->arabGlyphs .= "\xd8\xb1\xd8\xb2\xd8\xb3\xd8\xb4\xd8\xb5\xd8\xb6\xd8\xb7\xd8\xb8"; $this->arabHex .= '0631FEAE0631FEAE0632FEB00632FEB00633FEB2FEB3FEB40634FEB6FEB7FEB80635FEBAFEBBFEBC0636FEBEFEBFFEC00637FEC2FEC3FEC40638FEC6FEC7FEC8'; // U+0639; U+063A; U+0641; U+0642; U+0643; U+0644; U+0645; U+0646; $this->arabGlyphs .= "\xd8\xb9\xd8\xba\xd9\x81\xd9\x82\xd9\x83\xd9\x84\xd9\x85\xd9\x86"; $this->arabHex .= '0639FECAFECBFECC063AFECEFECFFED00641FED2FED3FED40642FED6FED7FED80643FEDAFEDBFEDC0644FEDEFEDFFEE00645FEE2FEE3FEE40646FEE6FEE7FEE8'; // U+0647; U+0648; U+0649; U+064A; U+0640; U+060C; U+061F; U+061B; $this->arabGlyphs .= "\xd9\x87\xd9\x88\xd9\x89\xd9\x8a\xd9\x80\xd8\x8c\xd8\x9f\xd8\x9b"; // 0649 Initial or medial probably meant to be YEH (064A) so Initial and Medial forms of YEH given $this->arabHex .= '0647FEEAFEEBFEEC0648FEEE0648FEEE0649FEF0FEF3FEF4064AFEF2FEF3FEF40640064006400640060C060C060C060C061F061F061F061F061B061B061B061B'; // 0649 Alef Maksura should only appear at end of word (in Arabic) So final form given as FEF0. Initial and medial are shown as isolated/final // $this->arabHex .= '0647FEEAFEEBFEEC0648FEEE0648FEEE0649FEF00649FEF0064AFEF2FEF3FEF40640064006400640060C060C060C060C061F061F061F061F061B061B061B061B'; // 0649 Alef Maksura Initial and Medial forms as given in Unicode FBE8 and FBE9 (not in most fonts) - dotless vesions of above // $this->arabHex .= '0647FEEAFEEBFEEC0648FEEE0648FEEE0649FEF0FBE8FBE9064AFEF2FEF3FEF40640064006400640060C060C060C060C061F061F061F061F061B061B061B061B'; // LAM with ALEF ligatures // U+0644; U+0622; U+0644; U+0623; U+0644; U+0625; U+0644; U+0627; $this->arabGlyphs .= "\xd9\x84\xd8\xa2\xd9\x84\xd8\xa3\xd9\x84\xd8\xa5\xd9\x84\xd8\xa7"; $this->arabHex .= 'FEF5FEF6FEF5FEF6FEF7FEF8FEF7FEF8FEF9FEFAFEF9FEFAFEFBFEFCFEFBFEFC'; // Added Arabic Presentation Forms - A - for Persian and other langauges // U+067B; U+067E; U+0680; U+067A; U+067F; U+0679; U+06A4; U+06A6; $this->persianGlyphs = "\xd9\xbb\xd9\xbe\xda\x80\xd9\xba\xd9\xbf\xd9\xb9\xda\xa4\xda\xa6"; $this->persianHex = '067BFB53FB54FB55067EFB57FB58FB590680FB5BFB5CFB5D067AFB5FFB60FB61067FFB63FB64FB650679FB67FB68FB6906A4FB6BFB6CFB6D06A6FB6FFB70FB71'; // U+0684; U+0683; U+0686; U+0687; U+0698; U+0691; U+06A9; U+06Af; $this->persianGlyphs .= "\xda\x84\xda\x83\xda\x86\xda\x87\xda\x98\xda\x91\xda\xa9\xda\xaf"; $this->persianHex .= '0684FB73FB74FB750683FB77FB78FB790686FB7BFB7CFB7D0687FB7FFB80FB810698FB8B0698FB8B0691FB8D0691FB8D06A9FB8FFB90FB9106AfFB93FB94FB95'; // U+06BA; U+06CC; U+06C1; U+0671; U+06D0; U+06D2; // 06C1 final form is same as isolated so use 06C1 $this->persianGlyphs .= "\xda\xba\xdb\x8c\xdb\x81\xd9\xb1\xdb\x90\xdb\x92"; $this->persianHex .= '06BAFB9F06BAFB9F06CCFBFDFBFEFBFF06C106C1FBA8FBA90671FB510671FB5106D0FBE5FBE6FBE706D2FBAF06D2FBAF'; } // ---------------------------------------------------------------------- // Derived from ArPHP // by Khaled Al-Shamaa // http://www.ar-php.org // ---------------------------------------------------------------------- function ArabJoin($str) { if (!$this->arabGlyphs) { $this->InitArabic(); } $crntChar = null; $prevChar = null; $nextChar = null; $output = array(); $chars = preg_split('//u', $str); $max = count($chars); for ($i = $max - 1; $i >= 0; $i--) { $crntChar = $chars[$i]; if ($i > 0){ $prevChar = $chars[$i - 1]; } else{ $prevChar = NULL; } if ($prevChar && mb_strpos($this->arabVowels, $prevChar, 0, 'utf-8') !== false) { $prevChar = $chars[$i - 2]; if ($prevChar && mb_strpos($this->arabVowels, $prevChar, 0, 'utf-8') !== false) { $prevChar = $chars[$i - 3]; } } if ($crntChar && mb_strpos($this->arabVowels, $crntChar, 0, 'utf-8') !== false) { // If next_char = nextLink && prev_char = prevLink: // Added && $prevchar (defined) else error on mb_strpos() if ($chars[$i + 1] && (mb_strpos($this->arabNextLink, $chars[$i + 1], 0, 'utf-8') !== false) && $prevChar && (mb_strpos($this->arabPrevLink, $prevChar, 0, 'utf-8') !== false)) { $output[] = '&#x' . $this->get_arab_glyphs($crntChar, 1) . ';'; // <final> form } else { $output[] = '&#x' . $this->get_arab_glyphs($crntChar, 0) . ';'; // <isolated> form } continue; } // NB = &#x622 &#x623; &#x625; &#x627; &#x644; if (isset($chars[$i + 1]) && in_array($chars[$i + 1], array("\xd8\xa2","\xd8\xa3","\xd8\xa5","\xd8\xa7")) && $crntChar == "\xd9\x84"){ continue; } if (ord($crntChar) < 128) { $output[] = $crntChar; $nextChar = $crntChar; continue; } $form = 0; if (in_array($crntChar, array("\xd8\xa2", "\xd8\xa3", "\xd8\xa5", "\xd8\xa7")) && $prevChar == "\xd9\x84") { if ($chars[$i - 2] && mb_strpos($this->arabPrevLink, $chars[$i - 2], 0, 'utf-8') !== false) { $form++; // <final> form } $output[] = '&#x' . $this->get_arab_glyphs($prevChar . $crntChar, $form) . ';'; $nextChar = $prevChar; continue; } if ($prevChar && mb_strpos($this->arabPrevLink, $prevChar, 0, 'utf-8') !== false) { $form++; } if ($nextChar && mb_strpos($this->arabNextLink, $nextChar, 0, 'utf-8') !== false) { $form += 2; } $output[] = '&#x' . $this->get_arab_glyphs($crntChar, $form) . ';'; $nextChar = $crntChar; } $ra = array_reverse($output); $s = implode($ra); $s = strcode2utf($s); return $s; } function get_arab_glyphs($char, $type) { $pos = mb_strpos($this->arabGlyphs, $char, 0, 'utf-8'); if ($pos === false) { // If character not covered here $pos = mb_strpos($this->persianGlyphs, $char, 0, 'utf-8'); // Try Persian additions if ($pos === false) { // return original character $x = mb_encode_numericentity ($char, array (0x0, 0xffff, 0, 0xffff), 'UTF-8'); preg_match('/&#(\d+);/', $x, $m); return dechex($m[1]); } else { // if covered by Added Persian chars $pos = $pos*16 + $type*4; return mb_substr($this->persianHex, $pos, 4, 'utf-8'); } } if ($pos > 48){ $pos = ($pos-48)/2 + 48; } $pos = $pos*16 + $type*4; return mb_substr($this->arabHex, $pos, 4, 'utf-8'); } /*-- END RTL --*/ function _getMQR() { $mqr=ini_get("magic_quotes_runtime"); if (PHP_VERSION_ID < 50300) { return @get_magic_quotes_runtime(); } else { return 0; } } //=========================== // Functions originally in htmltoolkit - moved mPDF 4.0 // Call-back function Used for usort in fn _tableWrite function _cmpdom($a, $b) { return ($a["dom"] < $b["dom"]) ? -1 : 1; } function mb_strrev($str, $enc = 'utf-8'){ $ch = array(); $ch = preg_split('//u',$str); $revch = array_reverse($ch); return implode('',$revch); } /*-- COLUMNS --*/ // Callback function from function printcolumnbuffer in mpdf function columnAdjustAdd($type,$k,$xadj,$yadj,$a,$b,$c=0,$d=0,$e=0,$f=0) { if ($type == 'Td') { // xpos,ypos $a += ($xadj * $k); $b -= ($yadj * $k); return 'BT '.sprintf('%.3F %.3F',$a,$b).' Td'; } else if ($type == 're') { // xpos,ypos,width,height $a += ($xadj * $k); $b -= ($yadj * $k); return sprintf('%.3F %.3F %.3F %.3F',$a,$b,$c,$d).' re'; } else if ($type == 'l') { // xpos,ypos,x2pos,y2pos $a += ($xadj * $k); $b -= ($yadj * $k); return sprintf('%.3F %.3F l',$a,$b); } else if ($type == 'img') { // width,height,xpos,ypos $c += ($xadj * $k); $d -= ($yadj * $k); return sprintf('q %.3F 0 0 %.3F %.3F %.3F',$a,$b,$c,$d).' cm /'.$e; } else if ($type == 'draw') { // xpos,ypos $a += ($xadj * $k); $b -= ($yadj * $k); return sprintf('%.3F %.3F m',$a,$b); } else if ($type == 'bezier') { // xpos,ypos,x2pos,y2pos,x3pos,y3pos $a += ($xadj * $k); $b -= ($yadj * $k); $c += ($xadj * $k); $d -= ($yadj * $k); $e += ($xadj * $k); $f -= ($yadj * $k); return sprintf('%.3F %.3F %.3F %.3F %.3F %.3F',$a,$b,$c,$d,$e,$f).' c'; } } /*-- END COLUMNS --*/ // Callback function from function printdivbuffer in mpdf - keeping block together on one page function blockAdjust($type,$k,$xadj,$yadj,$a,$b,$c=0,$d=0,$e=0,$f=0) { if ($type == 'Td') { // xpos,ypos $a += ($xadj * $k); $b -= ($yadj * $k); return 'BT '.sprintf('%.3F %.3F',$a,$b).' Td'; } else if ($type == 're') { // xpos,ypos,width,height $a += ($xadj * $k); $b -= ($yadj * $k); return sprintf('%.3F %.3F %.3F %.3F',$a,$b,$c,$d).' re'; } else if ($type == 'l') { // xpos,ypos,x2pos,y2pos $a += ($xadj * $k); $b -= ($yadj * $k); return sprintf('%.3F %.3F l',$a,$b); } else if ($type == 'img') { // width,height,xpos,ypos $c += ($xadj * $k); $d -= ($yadj * $k); return sprintf('q %.3F 0 0 %.3F %.3F %.3F',$a,$b,$c,$d).' cm /'.$e; } else if ($type == 'draw') { // xpos,ypos $a += ($xadj * $k); $b -= ($yadj * $k); return sprintf('%.3F %.3F m',$a,$b); } else if ($type == 'bezier') { // xpos,ypos,x2pos,y2pos,x3pos,y3pos $a += ($xadj * $k); $b -= ($yadj * $k); $c += ($xadj * $k); $d -= ($yadj * $k); $e += ($xadj * $k); $f -= ($yadj * $k); return sprintf('%.3F %.3F %.3F %.3F %.3F %.3F',$a,$b,$c,$d,$e,$f).' c'; } } function ConvertColor($color="#000000"){ $color = trim(strtolower($color)); $c = false; if ($color=='transparent') { return false; } else if ($color=='inherit') { return false; } else if (isset($this->SVGcolors[$color])) $color = $this->SVGcolors[$color]; if (preg_match('/^[\d]+$/',$color)) { $c = (array(1,$color)); } // i.e. integer only else if ($color[0] == '#') { //case of #nnnnnn or #nnn $cor = preg_replace('/\s+.*/','',$color); // in case of Background: #CCC url() x-repeat etc. if (strlen($cor) == 4) { // Turn #RGB into #RRGGBB $cor = "#" . $cor[1] . $cor[1] . $cor[2] . $cor[2] . $cor[3] . $cor[3]; } $r = hexdec(substr($cor, 1, 2)); $g = hexdec(substr($cor, 3, 2)); $b = hexdec(substr($cor, 5, 2)); $c = array(3,$r,$g,$b); } else if (preg_match('/(rgba|rgb|cmyka|cmyk|hsla|hsl|spot)\((.*?)\)/',$color,$m)) { $type= $m[1]; $cores = explode(",", $m[2]); $ncores = count($cores); // mPDF 5.3.76 if (stristr($cores[0],'%') ) { $cores[0] += 0; if ($type=='rgb' || $type=='rgba') { $cores[0] = intval($cores[0]*255/100); } } if ($ncores>1 && stristr($cores[1],'%') ) { $cores[1] += 0; if ($type=='rgb' || $type=='rgba') { $cores[1] = intval($cores[1]*255/100); } if ($type=='hsl' || $type=='hsla') { $cores[1] = $cores[1]/100; } } if ($ncores>2 && stristr($cores[2],'%') ) { $cores[2] += 0; if ($type=='rgb' || $type=='rgba') { $cores[2] = intval($cores[2]*255/100); } if ($type=='hsl' || $type=='hsla') { $cores[2] = $cores[2]/100; } } if ($ncores>3 && stristr($cores[3],'%') ) { $cores[3] += 0; } if ($type=='rgb') { $c = array(3,$cores[0],$cores[1],$cores[2]); } else if ($type=='rgba') { $c = array(5,$cores[0],$cores[1],$cores[2],$cores[3]*100); } // mPDF 5.3.74 else if ($type=='cmyk') { $c = array(4,$cores[0],$cores[1],$cores[2],$cores[3]); } else if ($type=='cmyka') { $c = array(6,$cores[0],$cores[1],$cores[2],$cores[3],$cores[4]*100); } // mPDF 5.3.74 else if ($type=='hsl' || $type=='hsla') { $conv = $this->hsl2rgb($cores[0]/360,$cores[1],$cores[2]); if ($type=='hsl') { $c = array(3,$conv[0],$conv[1],$conv[2]); } else if ($type=='hsla') { $c = array(5,$conv[0],$conv[1],$conv[2],$cores[3]*100); } // mPDF 5.3.74 } else if ($type=='spot') { $name = strtoupper(trim($cores[0])); if(!isset($this->spotColors[$name])) $this->Error('Undefined spot color: '.$name); $c = array(2,$this->spotColors[$name]['i'],$cores[1]); } } // $this->restrictColorSpace // 1 - allow GRAYSCALE only [convert CMYK/RGB->gray] // 2 - allow RGB / SPOT COLOR / Grayscale [convert CMYK->RGB] // 3 - allow CMYK / SPOT COLOR / Grayscale [convert RGB->CMYK] if ($this->PDFA || $this->PDFX || $this->restrictColorSpace) { if ($c[0]==1) { // GRAYSCALE } else if ($c[0]==2) { // SPOT COLOR if (!isset($this->spotColorIDs[$c[1]])) { die('Error: Spot colour has not been defined - '.$this->spotColorIDs[$c[1]]); } if ($this->PDFA) { if ($this->PDFA && !$this->PDFAauto) { $this->PDFAXwarnings[] = "Spot color specified '".$this->spotColorIDs[$c[1]]."' (converted to process color)"; } if ($this->restrictColorSpace!=3) { $sp = $this->spotColors[$this->spotColorIDs[$c[1]]]; $c = $this->cmyk2rgb(array(4,$sp['c'],$sp['m'],$sp['y'],$sp['k'])); } } else if ($this->restrictColorSpace==1) { $sp = $this->spotColors[$this->spotColorIDs[$c[1]]]; $c = $this->cmyk2gray(array(4,$sp['c'],$sp['m'],$sp['y'],$sp['k'])); } } else if ($c[0]==3) { // RGB if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) { if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "RGB color specified '".$color."' (converted to CMYK)"; } $c = $this->rgb2cmyk($c); } else if ($this->restrictColorSpace==1) { $c = $this->rgb2gray($c); } else if ($this->restrictColorSpace==3) { $c = $this->rgb2cmyk($c); } } else if ($c[0]==4) { // CMYK if ($this->PDFA && $this->restrictColorSpace!=3) { if ($this->PDFA && !$this->PDFAauto) { $this->PDFAXwarnings[] = "CMYK color specified '".$color."' (converted to RGB)"; } $c = $this->cmyk2rgb($c); } else if ($this->restrictColorSpace==1) { $c = $this->cmyk2gray($c); } else if ($this->restrictColorSpace==2) { $c = $this->cmyk2rgb($c); } } else if ($c[0]==5) { // RGBa if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) { if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "RGB color with transparency specified '".$color."' (converted to CMYK without transparency)"; } $c = $this->rgb2cmyk($c); $c = array(4, $c[1], $c[2], $c[3], $c[4]); } else if ($this->PDFA && $this->restrictColorSpace!=3) { if (!$this->PDFAauto) { $this->PDFAXwarnings[] = "RGB color with transparency specified '".$color."' (converted to RGB without transparency)"; } $c = $this->rgb2cmyk($c); $c = array(4, $c[1], $c[2], $c[3], $c[4]); } else if ($this->restrictColorSpace==1) { $c = $this->rgb2gray($c); } else if ($this->restrictColorSpace==3) { $c = $this->rgb2cmyk($c); } } else if ($c[0]==6) { // CMYKa if ($this->PDFA && $this->restrictColorSpace!=3) { if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "CMYK color with transparency specified '".$color."' (converted to RGB without transparency)"; } $c = $this->cmyk2rgb($c); $c = array(3, $c[1], $c[2], $c[3]); } else if ($this->PDFX || ($this->PDFA && $this->restrictColorSpace==3)) { if (($this->PDFA && !$this->PDFAauto) || ($this->PDFX && !$this->PDFXauto)) { $this->PDFAXwarnings[] = "CMYK color with transparency specified '".$color."' (converted to CMYK without transparency)"; } $c = $this->cmyk2rgb($c); $c = array(3, $c[1], $c[2], $c[3]); } else if ($this->restrictColorSpace==1) { $c = $this->cmyk2gray($c); } else if ($this->restrictColorSpace==2) { $c = $this->cmyk2rgb($c); } } } // mPDF 5.3.74 if (is_array($c)) { $c = array_pad($c, 6, 0); $cstr = pack("a1ccccc", $c[0], ($c[1] & 0xFF), ($c[2] & 0xFF), ($c[3] & 0xFF), ($c[4] & 0xFF), ($c[5] & 0xFF) ); } return $cstr; } function rgb2gray($c) { // mPDF 5.3.74 if (isset($c[4])) { return array(1,(($c[1] * .21) + ($c[2] * .71) + ($c[3] * .07)), ord(1), $c[4]); } else { return array(1,(($c[1] * .21) + ($c[2] * .71) + ($c[3] * .07))); } } function cmyk2gray($c) { $rgb = $this->cmyk2rgb($c); return $this->rgb2gray($rgb); } function rgb2cmyk($c) { $cyan = 1 - ($c[1] / 255); $magenta = 1 - ($c[2] / 255); $yellow = 1 - ($c[3] / 255); $min = min($cyan, $magenta, $yellow); if ($min == 1) { if ($c[0]==5) { return array (6,100,100,100,100, $c[4]); } else { return array (4,100,100,100,100); } // For K-Black //if ($c[0]==5) { return array (6,0,0,0,100, $c[4]); } //else { return array (4,0,0,0,100); } } $K = $min; $black = 1 - $K; if ($c[0]==5) { return array (6,($cyan-$K)*100/$black, ($magenta-$K)*100/$black, ($yellow-$K)*100/$black, $K*100, $c[4]); } else { return array (4,($cyan-$K)*100/$black, ($magenta-$K)*100/$black, ($yellow-$K)*100/$black, $K*100); } } function cmyk2rgb($c) { $rgb = array(); $colors = 255 - ($c[4]*2.55); $rgb[0] = intval($colors * (255 - ($c[1]*2.55))/255); $rgb[1] = intval($colors * (255 - ($c[2]*2.55))/255); $rgb[2] = intval($colors * (255 - ($c[3]*2.55))/255); if ($c[0]==6) { return array (5,$rgb[0],$rgb[1],$rgb[2], $c[5]); } else { return array (3,$rgb[0],$rgb[1],$rgb[2]); } } function rgb2hsl($var_r, $var_g, $var_b) { $var_min = min($var_r,$var_g,$var_b); $var_max = max($var_r,$var_g,$var_b); $del_max = $var_max - $var_min; $l = ($var_max + $var_min) / 2; if ($del_max == 0) { $h = 0; $s = 0; } else { if ($l < 0.5) { $s = $del_max / ($var_max + $var_min); } else { $s = $del_max / (2 - $var_max - $var_min); } $del_r = ((($var_max - $var_r) / 6) + ($del_max / 2)) / $del_max; $del_g = ((($var_max - $var_g) / 6) + ($del_max / 2)) / $del_max; $del_b = ((($var_max - $var_b) / 6) + ($del_max / 2)) / $del_max; if ($var_r == $var_max) { $h = $del_b - $del_g; } elseif ($var_g == $var_max) { $h = (1 / 3) + $del_r - $del_b; } elseif ($var_b == $var_max) { $h = (2 / 3) + $del_g - $del_r; }; if ($h < 0) { $h += 1; } if ($h > 1) { $h -= 1; } } return array($h,$s,$l); } function hsl2rgb($h2,$s2,$l2) { // Input is HSL value of complementary colour, held in $h2, $s, $l as fractions of 1 // Output is RGB in normal 255 255 255 format, held in $r, $g, $b // Hue is converted using function hue_2_rgb, shown at the end of this code if ($s2 == 0) { $r = $l2 * 255; $g = $l2 * 255; $b = $l2 * 255; } else { if ($l2 < 0.5) { $var_2 = $l2 * (1 + $s2); } else { $var_2 = ($l2 + $s2) - ($s2 * $l2); } $var_1 = 2 * $l2 - $var_2; $r = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2 + (1 / 3))); $g = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2)); $b = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2 - (1 / 3))); } return array($r,$g,$b); } function hue_2_rgb($v1,$v2,$vh) { // Function to convert hue to RGB, called from above if ($vh < 0) { $vh += 1; }; if ($vh > 1) { $vh -= 1; }; if ((6 * $vh) < 1) { return ($v1 + ($v2 - $v1) * 6 * $vh); }; if ((2 * $vh) < 1) { return ($v2); }; if ((3 * $vh) < 2) { return ($v1 + ($v2 - $v1) * ((2 / 3 - $vh) * 6)); }; return ($v1); } function _invertColor($cor) { if ($cor[0]==3 || $cor[0]==5) { // RGB return array(3, (255-$cor[1]), (255-$cor[2]), (255-$cor[3])); } else if ($cor[0]==4 || $cor[0]==6) { // CMYK return array(4, (100-$cor[1]), (100-$cor[2]), (100-$cor[3]), (100-$cor[4])); } else if ($cor[0]==1) { // Grayscale return array(1, (255-$cor[1])); } // Cannot cope with non-RGB colors at present die('Error in _invertColor - trying to invert non-RGB color'); } function _colAtoString($cor) { $s = ''; // mPDF 5.3.74 if ($cor{0}==1) $s = 'rgb('.ord($cor{1}).','.ord($cor{1}).','.ord($cor{1}).')'; else if ($cor{0}==2) $s = 'spot('.ord($cor{1}).','.ord($cor{2}).')'; // SPOT COLOR else if ($cor{0}==3) $s = 'rgb('.ord($cor{1}).','.ord($cor{2}).','.ord($cor{3}).')'; else if ($cor{0}==4) $s = 'cmyk('.ord($cor{1}).','.ord($cor{2}).','.ord($cor{3}).','.ord($cor{4}).')'; else if ($cor{0}==5) $s = 'rgba('.ord($cor{1}).','.ord($cor{2}).','.ord($cor{3}).','.sprintf('%0.2F',ord($cor{4})/100).')'; else if ($cor{0}==6) $s = 'cmyka('.ord($cor{1}).','.ord($cor{2}).','.ord($cor{3}).','.ord($cor{4}).','.sprintf('%0.2F',ord($cor{5})/100).')'; return $s; } function ConvertSize($size=5,$maxsize=0,$fontsize=false,$usefontsize=true){ // usefontsize - setfalse for e.g. margins - will ignore fontsize for % values // Depends of maxsize value to make % work properly. Usually maxsize == pagewidth // For text $maxsize = Fontsize // Setting e.g. margin % will use maxsize (pagewidth) and em will use fontsize //Identify size (remember: we are using 'mm' units here) $size = trim(strtolower($size)); if ( $size == 'thin' ) $size = 1*(25.4/$this->dpi); //1 pixel width for table borders elseif ( stristr($size,'px') ) $size *= (25.4/$this->dpi); //pixels elseif ( stristr($size,'cm') ) $size *= 10; //centimeters elseif ( stristr($size,'mm') ) $size += 0; //millimeters elseif ( stristr($size,'pt') ) $size *= 25.4/72; //72 pts/inch elseif ( stristr($size,'em') ) { $size += 0; //make "0.83em" become simply "0.83" if ($fontsize) { $size *= $fontsize; } else { $size *= $maxsize; } } elseif ( stristr($size,'%') ) { $size += 0; //make "90%" become simply "90" if ($fontsize && $usefontsize) { $size *= $fontsize/100; } else { $size *= $maxsize/100; } } elseif ( stristr($size,'in') ) $size *= 25.4; //inches elseif ( stristr($size,'pc') ) $size *= 38.1/9; //PostScript picas elseif ( stristr($size,'ex') ) { // Approximates "ex" as half of font height $size += 0; //make "3.5ex" become simply "3.5" if ($fontsize) { $size *= $fontsize/2; } else { $size *= $maxsize/2; } } elseif ( $size == 'medium' ) $size = 3*(25.4/$this->dpi); //3 pixel width for table borders elseif ( $size == 'thick' ) $size = 5*(25.4/$this->dpi); //5 pixel width for table borders elseif ($size == 'xx-small') { if ($fontsize) { $size *= $fontsize*0.7; } else { $size *= $maxsize*0.7; } } elseif ($size == 'x-small') { if ($fontsize) { $size *= $fontsize*0.77; } else { $size *= $maxsize*0.77; } } elseif ($size == 'small') { if ($fontsize) { $size *= $fontsize*0.86; } else { $size *= $maxsize*0.86; } } elseif ($size == 'medium') { if ($fontsize) { $size *= $fontsize; } else { $size *= $maxsize; } } elseif ($size == 'large') { if ($fontsize) { $size *= $fontsize*1.2; } else { $size *= $maxsize*1.2; } } elseif ($size == 'x-large') { if ($fontsize) { $size *= $fontsize*1.5; } else { $size *= $maxsize*1.5; } } elseif ($size == 'xx-large') { if ($fontsize) { $size *= $fontsize*2; } else { $size *= $maxsize*2; } } else $size *= (25.4/$this->dpi); //nothing == px return $size; } function lesser_entity_decode($html) { //supports the most used entity codes (only does ascii safe characters) //$html = str_replace("&nbsp;"," ",$html); // mPDF 5.3.59 $html = str_replace("&lt;","<",$html); $html = str_replace("&gt;",">",$html); $html = str_replace("&apos;","'",$html); $html = str_replace("&quot;",'"',$html); $html = str_replace("&amp;","&",$html); return $html; } function AdjustHTML($html, $tabSpaces=8) { // mPDF 5.3.99 //Try to make the html text more manageable (turning it into XHTML) // mPDF 5.3.97 if (PHP_VERSION_ID < 50307) { if (strlen($html) > 100000) { if (PHP_VERSION_ID < 50200) $this->Error("The HTML code is more than 100,000 characters. You should use WriteHTML() with smaller string lengths."); else ini_set("pcre.backtrack_limit","1000000"); } } /*-- ANNOTATIONS --*/ preg_match_all("/(<annotation.*?>)/si", $html, $m); if (count($m[1])) { for($i=0;$i<count($m[1]);$i++) { $sub = preg_replace("/\n/si", "\xbb\xa4\xac", $m[1][$i]); $html = preg_replace('/'.preg_quote($m[1][$i], '/').'/si', $sub, $html); } } /*-- END ANNOTATIONS --*/ // mPDF 5.3.A6 preg_match_all("/(<svg.*?<\/svg>)/si", $html, $svgi); if (count($svgi[0])) { for($i=0;$i<count($svgi[0]);$i++) { $file = _MPDF_TEMP_PATH.'_tempSVG'.RAND(1,10000).'_'.$i.'.svg'; //Save to local file file_put_contents($file, $svgi[0][$i]); $html = preg_replace('/'.preg_quote($svgi[0][$i], '/').'/si', '<img src="'.$file.'" />', $html); } } //Remove javascript code from HTML (should not appear in the PDF file) $html = preg_replace('/<script.*?<\/script>/is','',$html); //Remove special comments $html = preg_replace('/<!--mpdf/i','',$html); $html = preg_replace('/mpdf-->/i','',$html); //Remove comments from HTML (should not appear in the PDF file) $html = preg_replace('/<!--.*?-->/s','',$html); $html = preg_replace('/\f/','',$html); //replace formfeed by nothing $html = preg_replace('/\r/','',$html); //replace carriage return by nothing // Well formed XHTML end tags $html = preg_replace('/<(br|hr)\/>/i',"<\\1 />",$html); // Get rid of empty <thead></thead> $html = preg_replace('/<thead>\s*<\/thead>/i','',$html); $html = preg_replace('/<tfoot>\s*<\/tfoot>/i','',$html); $html = preg_replace('/<table[^>]*>\s*<\/table>/i','',$html); $html = preg_replace('/<tr>\s*<\/tr>/i','',$html); // Remove spaces at end of table cells $html = preg_replace("/[ ]+<\/t(d|h)/",'</t\\1',$html); $html = preg_replace("/[ ]*<dottab\s*[\/]*>[ ]*/",'<dottab />',$html); // Concatenates any Substitute characters from symbols/dingbats $html = str_replace('</tts><tts>','|',$html); $html = str_replace('</ttz><ttz>','|',$html); $html = str_replace('</tta><tta>','|',$html); $html = preg_replace('/<br \/>\s*/is',"<br />",$html); // mPDF 5.3.07 // Preserve '\n's in content between the tags <pre> and </pre> if (preg_match('/<pre/',$html)) { $html_a = preg_split('/(\<\/?pre[^\>]*\>)/', $html, -1, 2); $h = array(); $c=0; foreach($html_a AS $s) { if ($c>1 && preg_match('/^<\/pre/i',$s)) { $c--; $s=preg_replace('/<\/pre/i','</innerpre',$s); } else if ($c>0 && preg_match('/^<pre/i',$s)) { $c++; $s=preg_replace('/<pre/i','<innerpre',$s); } else if (preg_match('/^<pre/i',$s)) { $c++; } else if (preg_match('/^<\/pre/i',$s)) { $c--; } array_push($h, $s); } $html = implode("", $h); } $thereispre = preg_match_all('#<pre(.*?)>(.*?)</pre>#si',$html,$temp); // Preserve '\n's in content between the tags <textarea> and </textarea> $thereistextarea = preg_match_all('#<textarea(.*?)>(.*?)</textarea>#si',$html,$temp2); $html = preg_replace('/[\n]/',' ',$html); //replace linefeed by spaces $html = preg_replace('/[\t]/',' ',$html); //replace tabs by spaces // Converts < to &lt; when not a tag $html = preg_replace('/<([^!\/a-zA-Z])/i','&lt;\\1',$html); $html = preg_replace("/[ ]+/",' ',$html); $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html); $html = preg_replace('/\/(u|o)l>\s+<\/li/i','/\\1l></li',$html); $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html); $html = preg_replace('/\/li>\s+<li/i','/li><li',$html); $html = preg_replace('/<(u|o)l([^>]*)>[ ]+/i','<\\1l\\2>',$html); $html = preg_replace('/[ ]+<(u|o)l/i','<\\1l',$html); $iterator = 0; while($thereispre) //Recover <pre attributes>content</pre> { $temp[2][$iterator] = preg_replace("/^([^\n\t]*?)\t/me", "stripslashes('\\1') . str_repeat(' ', ( $tabSpaces - (mb_strlen(stripslashes('\\1')) % $tabSpaces)) )",$temp[2][$iterator]); $temp[2][$iterator] = preg_replace('/\t/',str_repeat(" ",$tabSpaces),$temp[2][$iterator]); $temp[2][$iterator] = preg_replace('/\n/',"<br />",$temp[2][$iterator]); $temp[2][$iterator] = str_replace('\\',"\\\\",$temp[2][$iterator]); // mPDF 5.3.88 $html = preg_replace('#<pre(.*?)>(.*?)</pre>#si','<erp'.$temp[1][$iterator].'>'.$temp[2][$iterator].'</erp>',$html,1); $thereispre--; $iterator++; } $iterator = 0; while($thereistextarea) //Recover <textarea attributes>content</textarea> { // $temp2[2][$iterator] = preg_replace('/&/',"&amp;",$temp2[2][$iterator]); // mPDF 5.3.59 // $temp2[2][$iterator] = preg_replace('/</',"&lt;",$temp2[2][$iterator]); // mPDF 5.3.59 $temp2[2][$iterator] = preg_replace('/\t/',str_repeat(" ",$tabSpaces),$temp2[2][$iterator]); $temp2[2][$iterator] = str_replace('\\',"\\\\",$temp2[2][$iterator]); // mPDF 5.3.88 // $temp2[2][$iterator] = preg_replace('/[ ]/',"&nbsp;",$temp2[2][$iterator]); // mPDF 5.3.59 $html = preg_replace('#<textarea(.*?)>(.*?)</textarea>#si','<aeratxet'.$temp2[1][$iterator].'>'.trim($temp2[2][$iterator]) .'</aeratxet>',$html,1); $thereistextarea--; $iterator++; } //Restore original tag names $html = str_replace("<erp","<pre",$html); $html = str_replace("</erp>","</pre>",$html); $html = str_replace("<aeratxet","<textarea",$html); $html = str_replace("</aeratxet>","</textarea>",$html); $html = str_replace("</innerpre","</pre",$html); $html = str_replace("<innerpre","<pre",$html); $html = preg_replace('/<textarea([^>]*)><\/textarea>/si','<textarea\\1> </textarea>',$html); // mPDF 5.3.56 $html = preg_replace('/(<table[^>]*>)\s*(<caption)(.*?<\/caption>)(.*?<\/table>)/si','\\2 position="top"\\3\\1\\4\\2 position="bottom"\\3',$html); // *TABLES* $html = preg_replace('/<(h[1-6])([^>]*)(>(?:(?!h[1-6]).)*?<\/\\1>\s*<table)/si','<\\1\\2 keep-with-table="1"\\3',$html); // *TABLES* $html = preg_replace("/\xbb\xa4\xac/", "\n", $html); return $html; } /*-- LISTS --*/ function dec2other($num, $cp) { $nstr = (string) $num; $rnum = ''; for ($i=0;$i<strlen($nstr);$i++) { if ($this->_charDefined($this->CurrentFont['cw'],$cp+intval($nstr[$i]))) { // contains arabic-indic numbers $rnum .= code2utf($cp+intval($nstr[$i])); } else { $rnum .= $nstr[$i]; } } return $rnum; } function dec2alpha($valor,$toupper="true"){ // returns a string from A-Z to AA-ZZ to AAA-ZZZ // OBS: A = 65 ASCII TABLE VALUE if (($valor < 1) || ($valor > 18278)) return "?"; //supports 'only' up to 18278 $c1 = $c2 = $c3 = ''; if ($valor > 702) // 3 letters (up to 18278) { $c1 = 65 + floor(($valor-703)/676); $c2 = 65 + floor((($valor-703)%676)/26); $c3 = 65 + floor((($valor-703)%676)%26); } elseif ($valor > 26) // 2 letters (up to 702) { $c1 = (64 + (int)(($valor-1) / 26)); $c2 = (64 + (int)($valor % 26)); if ($c2 == 64) $c2 += 26; } else // 1 letter (up to 26) { $c1 = (64 + $valor); } $alpha = chr($c1); if ($c2 != '') $alpha .= chr($c2); if ($c3 != '') $alpha .= chr($c3); if (!$toupper) $alpha = strtolower($alpha); return $alpha; } function dec2roman($valor,$toupper=true){ //returns a string as a roman numeral $r1=$r2=$r3=$r4=''; if (($valor >= 5000) || ($valor < 1)) return "?"; //supports 'only' up to 4999 $aux = (int)($valor/1000); if ($aux!==0) { $valor %= 1000; while($aux!==0) { $r1 .= "M"; $aux--; } } $aux = (int)($valor/100); if ($aux!==0) { $valor %= 100; switch($aux){ case 3: $r2="C"; case 2: $r2.="C"; case 1: $r2.="C"; break; case 9: $r2="CM"; break; case 8: $r2="C"; case 7: $r2.="C"; case 6: $r2.="C"; case 5: $r2="D".$r2; break; case 4: $r2="CD"; break; default: break; } } $aux = (int)($valor/10); if ($aux!==0) { $valor %= 10; switch($aux){ case 3: $r3="X"; case 2: $r3.="X"; case 1: $r3.="X"; break; case 9: $r3="XC"; break; case 8: $r3="X"; case 7: $r3.="X"; case 6: $r3.="X"; case 5: $r3="L".$r3; break; case 4: $r3="XL"; break; default: break; } } switch($valor){ case 3: $r4="I"; case 2: $r4.="I"; case 1: $r4.="I"; break; case 9: $r4="IX"; break; case 8: $r4="I"; case 7: $r4.="I"; case 6: $r4.="I"; case 5: $r4="V".$r4; break; case 4: $r4="IV"; break; default: break; } $roman = $r1.$r2.$r3.$r4; if (!$toupper) $roman = strtolower($roman); return $roman; } /*-- END LISTS --*/ //=========================== /*-- IMPORTS --*/ function SetImportUse() { $this->enableImports = true; ini_set('auto_detect_line_endings',1); require_once(_MPDF_PATH."mpdfi/pdf_context.php"); require_once(_MPDF_PATH."mpdfi/pdf_parser.php"); require_once(_MPDF_PATH."mpdfi/fpdi_pdf_parser.php"); } // from mPDFI function hex2str($hex) { return pack("H*", str_replace(array("\r","\n"," "),"", $hex)); } function str2hex($str) { return current(unpack("H*",$str)); } function pdf_write_value(&$value) { switch ($value[0]) { case PDF_TYPE_NUMERIC : case PDF_TYPE_TOKEN : // A numeric value or a token. // Simply output them $this->_out($value[1]." ", false); break; case PDF_TYPE_ARRAY : // An array. Output the proper // structure and move on. $this->_out("[",false); for ($i = 0; $i < count($value[1]); $i++) { $this->pdf_write_value($value[1][$i]); } $this->_out("]"); break; case PDF_TYPE_DICTIONARY : // A dictionary. $this->_out("<<",false); reset ($value[1]); while (list($k, $v) = each($value[1])) { $this->_out($k . " ",false); $this->pdf_write_value($v); } $this->_out(">>"); break; case PDF_TYPE_OBJREF : // An indirect object reference // Fill the object stack if needed $cpfn =& $this->current_parser->filename; if (!isset($this->_don_obj_stack[$cpfn][$value[1]])) { $this->_newobj(false,true); $this->_obj_stack[$cpfn][$value[1]] = array($this->n, $value); $this->_don_obj_stack[$cpfn][$value[1]] = array($this->n, $value); } $objid = $this->_don_obj_stack[$cpfn][$value[1]][0]; $this->_out("{$objid} 0 R"); //{$value[2]} break; case PDF_TYPE_STRING : if ($this->encrypted) { $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]); $value[1] = $this->_escape($value[1]); } // A string. $this->_out('('.$value[1].')'); break; case PDF_TYPE_STREAM : // A stream. First, output the // stream dictionary, then the // stream data itself. $this->pdf_write_value($value[1]); if ($this->encrypted) { $value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]); } $this->_out("stream"); $this->_out($value[2][1]); $this->_out("endstream"); break; case PDF_TYPE_HEX : if ($this->encrypted) { $value[1] = $this->hex2str($value[1]); $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]); // remake hexstring of encrypted string $value[1] = $this->str2hex($value[1]); } $this->_out("<".$value[1].">"); break; case PDF_TYPE_NULL : // The null object. $this->_out("null"); break; } } // ========== OVERWRITE SEARCH STRING IN A PDF FILE ================ function OverWrite($file_in, $search, $replacement, $dest="D", $file_out="mpdf" ) { $pdf = file_get_contents($file_in); if (!is_array($search)) { $x = $search; $search = array($x); } if (!is_array($replacement)) { $x = $replacement; $search = array($x); } if (!$this->onlyCoreFonts && !$this->usingCoreFont) { foreach($search AS $k=>$val) { $search[$k] = $this->UTF8ToUTF16BE($search[$k] , false); $search[$k] = $this->_escape($search[$k]); $replacement[$k] = $this->UTF8ToUTF16BE($replacement[$k], false); $replacement[$k] = $this->_escape($replacement[$k]); } } else { foreach($replacement AS $k=>$val) { $replacement[$k] = mb_convert_encoding($replacement[$k],$this->mb_enc,'utf-8'); $replacement[$k] = $this->_escape($replacement[$k]); } } // Get xref into array $xref = array(); preg_match("/xref\n0 (\d+)\n(.*?)\ntrailer/s",$pdf,$m); $xref_objid = $m[1]; preg_match_all('/(\d{10}) (\d{5}) (f|n)/',$m[2],$x); for($i=0; $i<count($x[0]); $i++) { $xref[] = array(intval($x[1][$i]), $x[2][$i], $x[3][$i]); } $changes = array(); preg_match("/<<\s*\/Type\s*\/Pages\s*\/Kids\s*\[(.*?)\]\s*\/Count/s",$pdf,$m); preg_match_all("/(\d+) 0 R /s",$m[1],$o); $objlist = $o[1]; foreach($objlist AS $obj) { if ($this->compress) { preg_match("/".($obj+1)." 0 obj\n<<\s*\/Filter\s*\/FlateDecode\s*\/Length (\d+)>>\nstream\n(.*?)\nendstream\n/s",$pdf,$m); } else { preg_match("/".($obj+1)." 0 obj\n<<\s*\/Length (\d+)>>\nstream\n(.*?)\nendstream\n/s",$pdf,$m); } $s = $m[2]; if (!$s) { continue; } $oldlen = $m[1]; if ($this->encrypted) { $s = $this->_RC4($this->_objectkey($obj+1), $s); } if ($this->compress) { $s = gzuncompress($s); } foreach($search AS $k=>$val) { $s = str_replace($search[$k],$replacement[$k],$s); } if ($this->compress) { $s = gzcompress($s); } if ($this->encrypted) { $s = $this->_RC4($this->_objectkey($obj+1), $s); } $newlen = strlen($s); $changes[($xref[$obj+1][0])] = ($newlen - $oldlen) + (strlen($newlen) - strlen($oldlen )); if ($this->compress) { $newstr = ($obj+1) . " 0 obj\n<</Filter /FlateDecode /Length ".$newlen.">>\nstream\n".$s."\nendstream\n"; } else { $newstr = ($obj+1) . " 0 obj\n<</Length ".$newlen.">>\nstream\n".$s."\nendstream\n"; } $pdf = str_replace($m[0],$newstr,$pdf); } // Update xref in PDF krsort($changes); $newxref = "xref\n0 ".$xref_objid."\n"; foreach($xref AS $v) { foreach($changes AS $ck => $cv) { if ($v[0] > $ck) { $v[0] += $cv; } } $newxref .= sprintf('%010d',$v[0]) . ' ' . $v[1] . ' ' .$v[2] . " \n"; } $newxref .= "trailer"; $pdf = preg_replace("/xref\n0 \d+\n.*?\ntrailer/s",$newxref,$pdf); // Update startxref in PDF preg_match("/startxref\n(\d+)\n%%EOF/s", $pdf, $m); $startxref = $m[1]; $startxref += array_sum($changes); $pdf = preg_replace("/startxref\n(\d+)\n%%EOF/s","startxref\n".$startxref."\n%%EOF",$pdf); // OUTPUT switch($dest) { case 'I': //Send to standard output if(isset($_SERVER['SERVER_NAME'])) { //We send to a browser Header('Content-Type: application/pdf'); Header('Content-Length: '.strlen($pdf)); Header('Content-disposition: inline; filename='.$file_out); } echo $pdf; break; case 'F': //Save to local file if (!$file_out) { $file_out = 'mpdf.pdf'; } $f=fopen($file_out,'wb'); if(!$f) die('Unable to create output file: '.$file_out); fwrite($f,$pdf,strlen($pdf)); fclose($f); break; case 'S': //Return as a string return $pdf; case 'D': default: //Download file if(isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) Header('Content-Type: application/force-download'); else Header('Content-Type: application/octet-stream'); Header('Content-Length: '.strlen($pdf)); Header('Content-disposition: attachment; filename='.$file_out); echo $pdf; break; } } function GetTemplateSize($tplidx, $_w=0, $_h=0) { if (!$this->tpls[$tplidx]) return false; $w = $this->tpls[$tplidx]['box']['w']; $h = $this->tpls[$tplidx]['box']['h']; if ($_w == 0 and $_h == 0) { $_w = $w; $_h = $h; } if($_w==0) $_w=$_h*$w/$h; if($_h==0) $_h=$_w*$h/$w; return array("w" => $_w, "h" => $_h); } // Thumbnails function Thumbnail($file, $npr=3, $spacing=10) { //$npr = number per row $w = (($this->pgwidth + $spacing)/$npr) - $spacing; $oldlinewidth = $this->LineWidth; $this->SetLineWidth(0.02); $this->SetDColor($this->ConvertColor(0)); $h = 0; $maxh = 0; $x = $_x = $this->lMargin; $_y = $this->tMargin; if ($this->y==0) { $y = $_y; } else { $y = $this->y; } $pagecount = $this->SetSourceFile($file); for ($n = 1; $n <= $pagecount; $n++) { $tplidx = $this->ImportPage($n); $size = $this->useTemplate($tplidx, $x, $y, $w); $this->Rect($x, $y, $size['w'], $size['h']); $h = max($h, $size['h']); $maxh = max($h, $maxh); if ($n % $npr == 0) { if (($y + $h + $spacing + $maxh)>$this->PageBreakTrigger && $n != $pagecount) { $this->AddPage(); $x = $_x; $y = $_y; } else { $y += $h+$spacing ; $x = $_x; $h = 0; } } else { $x += $w+$spacing ; } } $this->SetLineWidth($oldlinewidth); } function SetSourceFile($filename) { $this->current_filename = $filename; $fn =& $this->current_filename; if (!isset($this->parsers[$fn])) // $this->parsers[$fn] =& new fpdi_pdf_parser($fn,$this); $this->parsers[$fn] = new fpdi_pdf_parser($fn,$this); if (!$this->parsers[$fn]->success) { $this->Error($this->parsers[$fn]->errormsg); // Delete this line to return false on fail return false; } $this->current_parser =& $this->parsers[$fn]; return $this->parsers[$fn]->getPageCount(); } function ImportPage($pageno=1, $crop_x=null, $crop_y=null, $crop_w=0, $crop_h=0, $boxName='/CropBox') { $fn =& $this->current_filename; $parser =& $this->parsers[$fn]; $parser->setPageno($pageno); $this->tpl++; $this->tpls[$this->tpl] = array(); $tpl =& $this->tpls[$this->tpl]; $tpl['parser'] =& $parser; $tpl['resources'] = $parser->getPageResources(); $tpl['buffer'] = $parser->getContent(); if (!in_array($boxName, $parser->availableBoxes)) return $this->Error(sprintf("Unknown box: %s", $boxName)); $pageboxes = $parser->getPageBoxes($pageno); /** * MediaBox * CropBox: Default -> MediaBox * BleedBox: Default -> CropBox * TrimBox: Default -> CropBox * ArtBox: Default -> CropBox */ if (!isset($pageboxes[$boxName]) && ($boxName == "/BleedBox" || $boxName == "/TrimBox" || $boxName == "/ArtBox")) $boxName = "/CropBox"; if (!isset($pageboxes[$boxName]) && $boxName == "/CropBox") $boxName = "/MediaBox"; if (!isset($pageboxes[$boxName])) return false; $box = $pageboxes[$boxName]; $tpl['box'] = $box; // To build an array that can be used by useTemplate() $this->tpls[$this->tpl] = array_merge($this->tpls[$this->tpl],$box); // An imported page will start at 0,0 everytime. Translation will be set in _putformxobjects() $tpl['x'] = 0; $tpl['y'] = 0; $tpl['w'] = $tpl['box']['w'] ; $tpl['h'] = $tpl['box']['h'] ; if ($crop_w) { $tpl['box']['w'] = $crop_w; } if ($crop_h) { $tpl['box']['h'] = $crop_h; } if (isset($crop_x)) { $tpl['box']['x'] = $crop_x; } if (isset($crop_y)) {$tpl['box']['y'] = $tpl['h'] - $crop_y - $crop_h ; } $page =& $parser->pages[$parser->pageno]; // fix for rotated pages $rotation = $parser->getPageRotation($pageno); if (isset($rotation[1]) && ($angle = $rotation[1] % 360) != 0 && $tpl['box']['w'] == $tpl['w']) { $steps = $angle / 90; $_w = $tpl['w']; $_h = $tpl['h']; $tpl['w'] = $steps % 2 == 0 ? $_w : $_h; $tpl['h'] = $steps % 2 == 0 ? $_h : $_w; if ($steps % 2 != 0) { $x = $y = ($steps == 1 || $steps == -3) ? $tpl['h'] : $tpl['w']; } else { $x = $tpl['w']; $y = $tpl['h']; } $cx=($x/2+$tpl['box']['x'])*_MPDFK; $cy=($y/2+$tpl['box']['y'])*_MPDFK; $angle*=-1; $angle*=M_PI/180; $c=cos($angle); $s=sin($angle); $tpl['box']['w'] = $tpl['w'] ; $tpl['box']['h'] = $tpl['h'] ; $tpl['buffer'] = sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm %s Q',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy, $tpl['buffer']); } return $this->tpl; } function UseTemplate($tplidx, $_x=null, $_y=null, $_w=0, $_h=0) { if (!isset($this->tpls[$tplidx])) $this->Error("Template does not exist!"); if($this->state==0) { $this->AddPage(); } $out = 'q 0 J 1 w 0 j 0 G'."\n"; // reset standard values $x = $this->tpls[$tplidx]['x']; $y = $this->tpls[$tplidx]['y']; $w = $this->tpls[$tplidx]['w']; $h = $this->tpls[$tplidx]['h']; if ($_x == null) { $_x = $x; } if ($_y == null) { $_y = $y; } if ($_x === -1) { $_x = $this->x; } if ($_y === -1) { $_y = $this->y; } $wh = $this->getTemplateSize($tplidx,$_w,$_h); $_w = $wh['w']; $_h = $wh['h']; $out .= sprintf("q %.4F 0 0 %.4F %.2F %.2F cm", ($_w/$this->tpls[$tplidx]['box']['w']), ($_h/$this->tpls[$tplidx]['box']['h']), $_x*_MPDFK, ($this->h-($_y+$_h))*_MPDFK)."\n"; $out .= $this->tplprefix.$tplidx." Do Q\n"; $s = array("w" => $_w, "h" => $_h); $out .= "Q\n"; $this->pages[$this->page] = $out . $this->pages[$this->page]; return $s; } function SetPageTemplate($tplidx='') { if (!isset($this->tpls[$tplidx])) { $this->pageTemplate = ''; return false; } $this->pageTemplate = $tplidx; } function SetDocTemplate($file='', $continue=0) { $this->docTemplate = $file; $this->docTemplateContinue = $continue; } /*-- END IMPORTS --*/ /* ---------------------------------------------- */ /* ---------------------------------------------- */ /* ---------------------------------------------- */ /* ---------------------------------------------- */ /* ---------------------------------------------- */ // JAVASCRIPT function _set_object_javascript ($string) { $this->_newobj(); $this->_out('<<'); $this->_out('/S /JavaScript '); $this->_out('/JS '.$this->_textstring($string)); $this->_out('>>'); $this->_out('endobj'); } function SetJS($script) { $this->js = $script; } }//end of Class ?>
0683babd6e120333c4dae5bac951f5cc
trunk/application/libraries/mpdf.php
PHP
mit
1,268,705
<?php /** * PHP grocery CRUD * * A Codeigniter library that creates a CRUD automatically with just few lines of code. * * Copyright (C) 2010 - 2012 John Skoumbourdis. * * LICENSE * * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. * Please see the corresponding license file for details of these licenses. * You are free to use, modify and distribute this software, but all copyright information must remain. * * @package grocery CRUD * @copyright Copyright (c) 2010 through 2012, John Skoumbourdis * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt * @version 1.3 * @author John Skoumbourdis <scoumbourdisj@gmail.com> */ // ------------------------------------------------------------------------ /** * grocery Field Types * * The types of the fields and the default reactions * * @package grocery CRUD * @author John Skoumbourdis <scoumbourdisj@gmail.com> * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt * @link http://www.grocerycrud.com/documentation */ class grocery_CRUD_Field_Types { /** * Gets the field types of the main table. * @return array */ public function get_field_types() { if($this->field_types !== null) return $this->field_types; $types = array(); foreach($this->basic_model->get_field_types_basic_table() as $field_info) { $field_info->required = !empty($this->required_fields) && in_array($field_info->name,$this->required_fields) ? true : false; $field_info->display_as = isset($this->display_as[$field_info->name]) ? $this->display_as[$field_info->name] : ucfirst(str_replace("_"," ",$field_info->name)); if($this->change_field_type !== null && isset($this->change_field_type[$field_info->name])) { $field_type = $this->change_field_type[$field_info->name]; $field_info->crud_type = $field_type->type; $field_info->extras = $field_type->extras; $real_type = $field_info->crud_type; } elseif(isset($this->relation[$field_info->name])) { $real_type = 'relation'; $field_info->crud_type = 'relation'; } elseif(isset($this->upload_fields[$field_info->name])) { $real_type = 'upload_file'; $field_info->crud_type = 'upload_file'; } else { $real_type = $this->get_type($field_info); $field_info->crud_type = $real_type; } switch ($real_type) { case 'text': if(!empty($this->unset_texteditor) && in_array($field_info->name,$this->unset_texteditor)) $field_info->extras = false; else $field_info->extras = 'text_editor'; break; case 'relation': $field_info->extras = $this->relation[$field_info->name]; break; case 'upload_file': $field_info->extras = $this->upload_fields[$field_info->name]; break; default: if(empty($field_info->extras)) $field_info->extras = false; break; } $types[$field_info->name] = $field_info; } if(!empty($this->relation_n_n)) { foreach($this->relation_n_n as $field_name => $field_extras) { $field_info = (object)array(); $field_info->name = $field_name; $field_info->crud_type = 'relation_n_n'; $field_info->extras = $field_extras; $field_info->required = !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false;; $field_info->display_as = isset($this->display_as[$field_name]) ? $this->display_as[$field_name] : ucfirst(str_replace("_"," ",$field_name)); $types[$field_name] = $field_info; } } if(!empty($this->add_fields)) foreach($this->add_fields as $field_object) { $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; if(!isset($types[$field_name])) { $field_info = (object)array( 'name' => $field_name, 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? $this->change_field_type[$field_name]->type : 'string', 'display_as' => isset($this->display_as[$field_name]) ? $this->display_as[$field_name] : ucfirst(str_replace("_"," ",$field_name)), 'required' => in_array($field_name,$this->required_fields) ? true : false ); $types[$field_name] = $field_info; } } if(!empty($this->edit_fields)) foreach($this->edit_fields as $field_object) { $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; if(!isset($types[$field_name])) { $field_info = (object)array( 'name' => $field_name, 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? $this->change_field_type[$field_name]->type : 'string', 'display_as' => isset($this->display_as[$field_name]) ? $this->display_as[$field_name] : ucfirst(str_replace("_"," ",$field_name)), 'required' => in_array($field_name,$this->required_fields) ? true : false ); $types[$field_name] = $field_info; } } $this->field_types = $types; return $this->field_types; } public function get_primary_key() { return $this->basic_model->get_primary_key(); } /** * Get the html input for the specific field with the * current value * * @param object $field_info * @param string $value * @return object */ protected function get_field_input($field_info, $value = null) { $real_type = $field_info->crud_type; $types_array = array( 'integer', 'text', 'true_false', 'string', 'date', 'datetime', 'enum', 'set', 'relation', 'relation_n_n', 'upload_file', 'hidden', 'password', 'readonly', 'dropdown', 'multiselect' ); if (in_array($real_type,$types_array)) { /* A quick way to go to an internal method of type $this->get_{type}_input . * For example if the real type is integer then we will use the method * $this->get_integer_input * */ $field_info->input = $this->{"get_".$real_type."_input"}($field_info,$value); } else { $field_info->input = $this->get_string_input($field_info,$value); } return $field_info; } protected function change_list_value($field_info, $value = null) { $real_type = $field_info->crud_type; switch ($real_type) { case 'hidden': case 'invisible': case 'integer': break; case 'true_false': if(isset($this->default_true_false_text[$value])) $value = $this->default_true_false_text[$value]; break; case 'string': $value = $this->character_limiter($value,$this->character_limiter,"..."); break; case 'text': $value = $this->character_limiter(strip_tags($value),$this->character_limiter,"..."); break; case 'date': if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') { list($year,$month,$day) = explode("-",$value); $value = date($this->php_date_format, mktime (0, 0, 0, (int)$month , (int)$day , (int)$year)); } else { $value = ''; } break; case 'datetime': if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00') { list($year,$month,$day) = explode("-",$value); list($hours,$minutes) = explode(":",substr($value,11)); $value = date($this->php_date_format." - H:i", mktime ((int)$hours , (int)$minutes , 0, (int)$month , (int)$day ,(int)$year)); } else { $value = ''; } break; case 'enum': $value = $this->character_limiter($value,$this->character_limiter,"..."); break; case 'multiselect': $value_as_array = array(); foreach(explode(",",$value) as $row_value) { $value_as_array[] = array_key_exists($row_value,$field_info->extras) ? $field_info->extras[$row_value] : $row_value; } $value = implode(",",$value_as_array); break; case 'relation_n_n': $value = $this->character_limiter(str_replace(',',', ',$value),$this->character_limiter,"..."); break; case 'password': $value = '******'; break; case 'dropdown': $value = array_key_exists($value,$field_info->extras) ? $field_info->extras[$value] : $value; break; case 'upload_file': if(empty($value)) { $value = ""; } else { $is_image = !empty($value) && ( substr($value,-4) == '.jpg' || substr($value,-4) == '.png' || substr($value,-5) == '.jpeg' || substr($value,-4) == '.gif' || substr($value,-5) == '.tiff') ? true : false; $file_url = base_url().$field_info->extras->upload_path."/$value"; $file_url_anchor = '<a href="'.$file_url.'"'; if($is_image) { $file_url_anchor .= ' class="image-thumbnail"><img src="'.$file_url.'" height="50px">'; } else { $file_url_anchor .= ' target="_blank">'.$this->character_limiter($value,$this->character_limiter,'...',true); } $file_url_anchor .= '</a>'; $value = $file_url_anchor; } break; default: $value = $this->character_limiter($value,$this->character_limiter,"..."); break; } return $value; } /** * Character Limiter of codeigniter (I just don't want to load the helper ) * * Limits the string based on the character count. Preserves complete words * so the character count may not be exactly as specified. * * @access public * @param string * @param integer * @param string the end character. Usually an ellipsis * @return string */ function character_limiter($str, $n = 500, $end_char = '&#8230;') { if (strlen($str) < $n) { return $str; } // a bit complicated, but faster than preg_replace with \s+ $str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\x0B", "\x0C"), ' ', $str)); if (strlen($str) <= $n) { return $str; } $out = ''; foreach (explode(' ', trim($str)) as $val) { $out .= $val.' '; if (strlen($out) >= $n) { $out = trim($out); return (strlen($out) === strlen($str)) ? $out : $out.$end_char; } } } protected function get_type($db_type) { $type = false; if(!empty($db_type->type)) { switch ($db_type->type) { case '1': case '3': case 'int': case 'tinyint': case 'mediumint': case 'longint': if( $db_type->db_type == 'tinyint' && $db_type->db_max_length == 1) $type = 'true_false'; else $type = 'integer'; break; case '254': case 'string': case 'enum': if($db_type->db_type != 'enum') $type = 'string'; else $type = 'enum'; break; case 'set': if($db_type->db_type != 'set') $type = 'string'; else $type = 'set'; break; case '252': case 'blob': case 'text': case 'mediumtext': case 'longtext': $type = 'text'; break; case '10': case 'date': $type = 'date'; break; case '12': case 'datetime': case 'timestamp': $type = 'datetime'; break; } } return $type; } } // ------------------------------------------------------------------------ /** * Grocery Model Driver * * Drives the model - I'ts so easy like you drive a bicycle :-) * * @package grocery CRUD * @author John Skoumbourdis <scoumbourdisj@gmail.com> * @version 1.3 * @link http://www.grocerycrud.com/documentation */ class grocery_CRUD_Model_Driver extends grocery_CRUD_Field_Types { /** * @var grocery_CRUD_Model */ public $basic_model = null; protected function set_default_Model() { $ci = &get_instance(); $ci->load->model('grocery_CRUD_Model'); $this->basic_model = $ci->grocery_CRUD_Model; } protected function get_total_results() { if(!empty($this->where)) foreach($this->where as $where) $this->basic_model->where($where[0],$where[1],$where[2]); if(!empty($this->or_where)) foreach($this->or_where as $or_where) $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); if(!empty($this->like)) foreach($this->like as $like) $this->basic_model->like($like[0],$like[1],$like[2]); if(!empty($this->or_like)) foreach($this->or_like as $or_like) $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); if(!empty($this->having)) foreach($this->having as $having) $this->basic_model->having($having[0],$having[1],$having[2]); if(!empty($this->or_having)) foreach($this->or_having as $or_having) $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); if(!empty($this->relation)) foreach($this->relation as $relation) $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); if(!empty($this->relation_n_n)) { $columns = $this->get_columns(); foreach($columns as $column) { //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. if(isset($this->relation_n_n[$column->field_name])) { $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); } } } return $this->basic_model->get_total_results(); } public function set_model($model_name) { $ci = &get_instance(); $ci->load->model('grocery_CRUD_Model'); $ci->load->model($model_name); $temp = explode('/',$model_name); krsort($temp); foreach($temp as $t) { $real_model_name = $t; break; } $this->basic_model = $ci->$real_model_name; } protected function set_ajax_list_queries($state_info = null) { if(!empty($state_info->per_page)) { if(empty($state_info->page) || !is_numeric($state_info->page) ) $this->limit($state_info->per_page); else { $limit_page = ( ($state_info->page-1) * $state_info->per_page ); $this->limit($state_info->per_page, $limit_page); } } if(!empty($state_info->order_by)) { $this->order_by($state_info->order_by[0],$state_info->order_by[1]); } if(!empty($state_info->search)) { if(!empty($this->relation)) foreach($this->relation as $relation_name => $relation_values) $temp_relation[$this->_unique_field_name($relation_name)] = $this->_get_field_names_to_search($relation_values); if($state_info->search->field !== null) { if(isset($temp_relation[$state_info->search->field])) { if(is_array($temp_relation[$state_info->search->field])) foreach($temp_relation[$state_info->search->field] as $search_field) $this->or_like($search_field , $state_info->search->text); else $this->like($temp_relation[$state_info->search->field] , $state_info->search->text); } elseif(isset($this->relation_n_n[$state_info->search->field])) { $escaped_text = $this->basic_model->escape_str($state_info->search->text); $this->having($state_info->search->field." LIKE '%".$escaped_text."%'"); } else { $this->like($state_info->search->field , $state_info->search->text); } } else { $columns = $this->get_columns(); $search_text = $state_info->search->text; if(!empty($this->where)) foreach($this->where as $where) $this->basic_model->having($where[0],$where[1],$where[2]); foreach($columns as $column) { if(isset($temp_relation[$column->field_name])) { if(is_array($temp_relation[$column->field_name])) { foreach($temp_relation[$column->field_name] as $search_field) { $this->or_like($search_field, $search_text); } } else { $this->or_like($temp_relation[$column->field_name], $search_text); } } elseif(isset($this->relation_n_n[$column->field_name])) { //@todo have a where for the relation_n_n statement } else { $this->or_like($column->field_name, $search_text); } } } } } protected function table_exists($table_name = null) { if($this->basic_model->db_table_exists($table_name)) return true; return false; } protected function get_relation_array($relation_info, $primary_key_value = null, $limit = null) { list($field_name , $related_table , $related_field_title, $where_clause, $order_by) = $relation_info; if($primary_key_value !== null) { $primary_key = $this->basic_model->get_primary_key($related_table); //A where clause with the primary key is enough to take the selected key row $where_clause = array($primary_key => $primary_key_value); } $relation_array = $this->basic_model->get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, $limit); return $relation_array; } protected function get_relation_total_rows($relation_info) { list($field_name , $related_table , $related_field_title, $where_clause) = $relation_info; $relation_array = $this->basic_model->get_relation_total_rows($field_name , $related_table , $related_field_title, $where_clause); return $relation_array; } protected function db_insert_validation() { $validation_result = (object)array('success'=>false); $field_types = $this->get_field_types(); $required_fields = $this->required_fields; $add_fields = $this->get_add_fields(); if(!empty($required_fields)) { foreach($add_fields as $add_field) { $field_name = $add_field->field_name; if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) { $this->set_rules( $field_name, $field_types[$field_name]->display_as, 'required'); } } } if(!empty($this->validation_rules)) { $form_validation = $this->form_validation(); $add_fields = $this->get_add_fields(); foreach($add_fields as $add_field) { $field_name = $add_field->field_name; if(isset($this->validation_rules[$field_name])) { $rule = $this->validation_rules[$field_name]; $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules']); } } if($form_validation->run()) { $validation_result->success = true; } else { $validation_result->error_message = $form_validation->error_string(); $validation_result->error_fields = $form_validation->_error_array; } } else { $validation_result->success = true; } return $validation_result; } protected function form_validation() { if($this->form_validation === null) { $this->form_validation = new grocery_CRUD_Form_validation(); $ci = &get_instance(); $ci->load->library('form_validation'); $ci->form_validation = $this->form_validation; } return $this->form_validation; } protected function db_update_validation() { $validation_result = (object)array('success'=>false); $field_types = $this->get_field_types(); $required_fields = $this->required_fields; $edit_fields = $this->get_edit_fields(); if(!empty($required_fields)) { foreach($edit_fields as $edit_field) { $field_name = $edit_field->field_name; if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) { $this->set_rules( $field_name, $field_types[$field_name]->display_as, 'required'); } } } if(!empty($this->validation_rules)) { $form_validation = $this->form_validation(); $edit_fields = $this->get_edit_fields(); foreach($edit_fields as $edit_field) { $field_name = $edit_field->field_name; if(isset($this->validation_rules[$field_name])) { $rule = $this->validation_rules[$field_name]; $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules']); } } if($form_validation->run()) { $validation_result->success = true; } else { $validation_result->error_message = $form_validation->error_string(); $validation_result->error_fields = $form_validation->_error_array; } } else { $validation_result->success = true; } return $validation_result; } protected function db_insert($state_info) { $validation_result = $this->db_insert_validation(); if($validation_result->success) { $post_data = $state_info->unwrapped_data; $add_fields = $this->get_add_fields(); if($this->callback_insert === null) { if($this->callback_before_insert !== null) { $callback_return = call_user_func($this->callback_before_insert, $post_data); if(!empty($callback_return) && is_array($callback_return)) $post_data = $callback_return; elseif($callback_return === false) return false; } $insert_data = array(); $types = $this->get_field_types(); foreach($add_fields as $num_row => $field) { /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) { $post_data[$field->field_name] = array(); } if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) { if(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && is_array($post_data[$field->field_name]) && empty($post_data[$field->field_name])) { $insert_data[$field->field_name] = null; } elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') { $insert_data[$field->field_name] = null; } elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') { $insert_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); } elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') { //This empty if statement is to make sure that a readonly field will never inserted/updated } elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) { $insert_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; } elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ $insert_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). substr($post_data[$field->field_name],10); } else { $insert_data[$field->field_name] = $post_data[$field->field_name]; } } } $insert_result = $this->basic_model->db_insert($insert_data); if($insert_result !== false) { $insert_primary_key = $insert_result; } else { return false; } if(!empty($this->relation_n_n)) { foreach($this->relation_n_n as $field_name => $field_info) { $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; $this->db_relation_n_n_update($field_info, $relation_data ,$insert_primary_key); } } if($this->callback_after_insert !== null) { $callback_return = call_user_func($this->callback_after_insert, $post_data, $insert_primary_key); if($callback_return === false) { return false; } } }else { $callback_return = call_user_func($this->callback_insert, $post_data); if($callback_return === false) { return false; } } if(isset($insert_primary_key)) return $insert_primary_key; else return true; } return false; } protected function db_update($state_info) { $validation_result = $this->db_update_validation(); $edit_fields = $this->get_edit_fields(); if($validation_result->success) { $post_data = $state_info->unwrapped_data; $primary_key = $state_info->primary_key; if($this->callback_update === null) { if($this->callback_before_update !== null) { $callback_return = call_user_func($this->callback_before_update, $post_data, $primary_key); if(!empty($callback_return) && is_array($callback_return)) { $post_data = $callback_return; } elseif($callback_return === false) { return false; } } $update_data = array(); $types = $this->get_field_types(); foreach($edit_fields as $num_row => $field) { /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) { $post_data[$field->field_name] = array(); } if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) { if(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && is_array($post_data[$field->field_name]) && empty($post_data[$field->field_name])) { $update_data[$field->field_name] = null; } elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') { $update_data[$field->field_name] = null; } elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') { $update_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); } elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') { //This empty if statement is to make sure that a readonly field will never inserted/updated } elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) { $update_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; } elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ $update_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). substr($post_data[$field->field_name],10); } else { $update_data[$field->field_name] = $post_data[$field->field_name]; } } } if($this->basic_model->db_update($update_data, $primary_key) === false) { return false; } if(!empty($this->relation_n_n)) { foreach($this->relation_n_n as $field_name => $field_info) { if ( $this->unset_edit_fields !== null && is_array($this->unset_edit_fields) && in_array($field_name,$this->unset_edit_fields) ) { continue; } $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; $this->db_relation_n_n_update($field_info, $relation_data ,$primary_key); } } if($this->callback_after_update !== null) { $callback_return = call_user_func($this->callback_after_update, $post_data, $primary_key); if($callback_return === false) { return false; } } } else { $callback_return = call_user_func($this->callback_update, $post_data, $primary_key); if($callback_return === false) { return false; } } return true; } else { return false; } } protected function _convert_date_to_sql_date($date) { $date = substr($date,0,10); if(preg_match('/\d{4}-\d{2}-\d{2}/',$date)) { //If it's already a sql-date don't convert it! return $date; }elseif(empty($date)) { return ''; } $date_array = preg_split( '/[-\.\/ ]/', $date); if($this->php_date_format == 'd/m/Y') { $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[1],$date_array[0],$date_array[2])); } elseif($this->php_date_format == 'm/d/Y') { $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[0],$date_array[1],$date_array[2])); } else { $sql_date = $date; } return $sql_date; } protected function _get_field_names_to_search(array $relation_values) { if(!strstr($relation_values[2],'{')) return $this->_unique_join_name($relation_values[0]).'.'.$relation_values[2]; else { $relation_values[2] = ' '.$relation_values[2].' '; $temp1 = explode('{',$relation_values[2]); unset($temp1[0]); $field_names_array = array(); foreach($temp1 as $field) list($field_names_array[]) = explode('}',$field); return $field_names_array; } } protected function _unique_join_name($field_name) { return 'j'.substr(md5($field_name),0,8); //This j is because is better for a string to begin with a letter and not a number } protected function _unique_field_name($field_name) { return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin with a letter and not a number } protected function db_delete($state_info) { $primary_key = $state_info->primary_key; if($this->callback_delete === null) { if($this->callback_before_delete !== null) { $callback_return = call_user_func($this->callback_before_delete, $primary_key); if($callback_return === false) { return false; } } if(!empty($this->relation_n_n)) { foreach($this->relation_n_n as $field_name => $field_info) { $this->db_relation_n_n_delete( $field_info, $primary_key ); } } $delete_result = $this->basic_model->db_delete($primary_key); if($delete_result === false) { return false; } if($this->callback_after_delete !== null) { $callback_return = call_user_func($this->callback_after_delete, $primary_key); if($callback_return === false) { return false; } } } else { $callback_return = call_user_func($this->callback_delete, $primary_key); if($callback_return === false) { return false; } } return true; } protected function db_relation_n_n_update($field_info, $post_data , $primary_key_value) { $this->basic_model->db_relation_n_n_update($field_info, $post_data , $primary_key_value); } protected function db_relation_n_n_delete($field_info, $primary_key_value) { $this->basic_model->db_relation_n_n_delete($field_info, $primary_key_value); } protected function get_list() { if(!empty($this->order_by)) $this->basic_model->order_by($this->order_by[0],$this->order_by[1]); if(!empty($this->where)) foreach($this->where as $where) $this->basic_model->where($where[0],$where[1],$where[2]); if(!empty($this->or_where)) foreach($this->or_where as $or_where) $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); if(!empty($this->like)) foreach($this->like as $like) $this->basic_model->like($like[0],$like[1],$like[2]); if(!empty($this->or_like)) foreach($this->or_like as $or_like) $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); if(!empty($this->having)) foreach($this->having as $having) $this->basic_model->having($having[0],$having[1],$having[2]); if(!empty($this->or_having)) foreach($this->or_having as $or_having) $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); if(!empty($this->relation)) foreach($this->relation as $relation) $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); if(!empty($this->relation_n_n)) { $columns = $this->get_columns(); foreach($columns as $column) { //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. if(isset($this->relation_n_n[$column->field_name])) { $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); } } } if($this->theme_config['crud_paging'] === true) { if($this->limit === null) { $default_per_page = $this->config->default_per_page; if(is_numeric($default_per_page) && $default_per_page >1) { $this->basic_model->limit($default_per_page); } else { $this->basic_model->limit(10); } } else { $this->basic_model->limit($this->limit[0],$this->limit[1]); } } $results = $this->basic_model->get_list(); return $results; } protected function get_edit_values($primary_key_value) { $values = $this->basic_model->get_edit_values($primary_key_value); if(!empty($this->relation_n_n)) { foreach($this->relation_n_n as $field_name => $field_info) { $values->$field_name = $this->get_relation_n_n_selection_array($primary_key_value, $field_info); } } return $values; } protected function get_relation_n_n_selection_array($primary_key_value, $field_info) { return $this->basic_model->get_relation_n_n_selection_array($primary_key_value, $field_info); } protected function get_relation_n_n_unselected_array($field_info, $selected_values) { return $this->basic_model->get_relation_n_n_unselected_array($field_info, $selected_values); } protected function set_basic_db_table($table_name = null) { $this->basic_model->set_basic_table($table_name); } protected function upload_file($state_info) { if(isset($this->upload_fields[$state_info->field_name]) ) { if($this->callback_upload === null) { if($this->callback_before_upload !== null) { $callback_before_upload_response = call_user_func($this->callback_before_upload, $_FILES, $this->upload_fields[$state_info->field_name]); if($callback_before_upload_response === false) return false; elseif(is_string($callback_before_upload_response)) return $callback_before_upload_response; } $upload_info = $this->upload_fields[$state_info->field_name]; header('Pragma: no-cache'); header('Cache-Control: private, no-cache'); header('Content-Disposition: inline; filename="files.json"'); header('X-Content-Type-Options: nosniff'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE'); header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size'); $allowed_files = $this->config->file_upload_allow_file_types; $reg_exp = '/(\\.|\\/)('.$allowed_files.')$/i'; $max_file_size_ui = $this->config->file_upload_max_file_size; $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); $options = array( 'upload_dir' => $upload_info->upload_path.'/', 'param_name' => $this->_unique_field_name($state_info->field_name), 'upload_url' => base_url().$upload_info->upload_path.'/', 'accept_file_types' => $reg_exp, 'max_file_size' => $max_file_size_bytes ); $upload_handler = new UploadHandler($options); $upload_handler->default_config_path = $this->default_config_path; $uploader_response = $upload_handler->post(); if(is_array($uploader_response)) { foreach($uploader_response as &$response) { unset($response->delete_url); unset($response->delete_type); } } if($this->callback_after_upload !== null) { $callback_after_upload_response = call_user_func($this->callback_after_upload, $uploader_response , $this->upload_fields[$state_info->field_name] , $_FILES ); if($callback_after_upload_response === false) return false; elseif(is_string($callback_after_upload_response)) return $callback_after_upload_response; elseif(is_array($callback_after_upload_response)) $uploader_response = $callback_after_upload_response; } return $uploader_response; } else { $upload_response = call_user_func($this->callback_upload, $_FILES, $this->upload_fields[$state_info->field_name] ); if($upload_response === false) { return false; } else { return $upload_response; } } } else { return false; } } protected function delete_file($state_info) { if(isset($state_info->field_name) && isset($this->upload_fields[$state_info->field_name])) { $upload_info = $this->upload_fields[$state_info->field_name]; if(file_exists("{$upload_info->upload_path}/{$state_info->file_name}")) { if( unlink("{$upload_info->upload_path}/{$state_info->file_name}") ) { $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); return true; } else { return false; } } else { $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); return true; } } else { return false; } } protected function ajax_relation($state_info) { if(!isset($this->relation[$state_info->field_name])) return false; list($field_name, $related_table, $related_field_title, $where_clause, $order_by) = $this->relation[$state_info->field_name]; return $this->basic_model->get_ajax_relation_array($state_info->search, $field_name, $related_table, $related_field_title, $where_clause, $order_by); } } /** * PHP grocery CRUD * * LICENSE * * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. * Please see the corresponding license file for details of these licenses. * You are free to use, modify and distribute this software, but all copyright information must remain. * * @package grocery CRUD * @copyright Copyright (c) 2010 through 2012, John Skoumbourdis * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt * @author John Skoumbourdis <scoumbourdisj@gmail.com> */ // ------------------------------------------------------------------------ /** * PHP grocery Layout * * Here you manage all the HTML Layout * * @package grocery CRUD * @author John Skoumbourdis <scoumbourdisj@gmail.com> * @version 1.3 */ class grocery_CRUD_Layout extends grocery_CRUD_Model_Driver { private $theme_path = null; private $views_as_string = ''; private $echo_and_die = false; protected $theme = null; protected $default_true_false_text = array('inactive' , 'active'); protected $css_files = array(); protected $js_files = array(); protected function set_basic_Layout() { if(!file_exists($this->theme_path.$this->theme.'/views/list_template.php')) { throw new Exception('The template does not exist. Please check your files and try again.', 12); die(); } } protected function showList($ajax = false, $state_info = null) { $data = $this->get_common_data(); $data->order_by = $this->order_by; $data->types = $this->get_field_types(); $data->list = $this->get_list(); $data->list = $this->change_list($data->list , $data->types); $data->list = $this->change_list_add_actions($data->list); $data->total_results = $this->get_total_results(); $data->columns = $this->get_columns(); $data->success_message = $this->get_success_message_at_list($state_info); $data->primary_key = $this->get_primary_key(); $data->add_url = $this->getAddUrl(); $data->edit_url = $this->getEditUrl(); $data->delete_url = $this->getDeleteUrl(); $data->ajax_list_url = $this->getAjaxListUrl(); $data->ajax_list_info_url = $this->getAjaxListInfoUrl(); $data->export_url = $this->getExportToExcelUrl(); $data->print_url = $this->getPrintUrl(); $data->actions = $this->actions; $data->unique_hash = $this->get_method_hash(); $data->order_by = $this->order_by; $data->unset_add = $this->unset_add; $data->unset_edit = $this->unset_edit; $data->unset_delete = $this->unset_delete; $data->unset_export = $this->unset_export; $data->unset_print = $this->unset_print; $default_per_page = $this->config->default_per_page; $data->paging_options = array('10','25','50','100'); $data->default_per_page = is_numeric($default_per_page) && $default_per_page >1 && in_array($default_per_page,$data->paging_options)? $default_per_page : 25; if($data->list === false) { throw new Exception('It is impossible to get data. Please check your model and try again.', 13); $data->list = array(); } foreach($data->list as $num_row => $row) { $data->list[$num_row]->edit_url = $data->edit_url.'/'.$row->{$data->primary_key}; $data->list[$num_row]->delete_url = $data->delete_url.'/'.$row->{$data->primary_key}; } if(!$ajax) { $data->list_view = $this->_theme_view('list.php',$data,true); $this->_theme_view('list_template.php',$data); } else { $this->set_echo_and_die(); $this->_theme_view('list.php',$data); } } protected function exportToExcel($state_info = null) { $data = $this->get_common_data(); $data->order_by = $this->order_by; $data->types = $this->get_field_types(); $data->list = $this->get_list(); $data->list = $this->change_list($data->list , $data->types); $data->list = $this->change_list_add_actions($data->list); $data->total_results = $this->get_total_results(); $data->columns = $this->get_columns(); $data->primary_key = $this->get_primary_key(); @ob_end_clean(); $this->_export_to_excel($data); } protected function _export_to_excel($data) { /** * No need to use an external library here. The only bad thing without using external library is that Microsoft Excel is complaining * that the file is in a different format than specified by the file extension. If you press "Yes" everything will be just fine. * */ $string_to_export = ""; foreach($data->columns as $column){ $string_to_export .= $column->display_as."\t"; } $string_to_export .= "\n"; foreach($data->list as $num_row => $row){ foreach($data->columns as $column){ $string_to_export .= $this->_trim_export_string($row->{$column->field_name})."\t"; } $string_to_export .= "\n"; } // Convert to UTF-16LE and Prepend BOM $string_to_export = "\xFF\xFE" .mb_convert_encoding($string_to_export, 'UTF-16LE', 'UTF-8'); $filename = "export-".date("Y-m-d_H:i:s").".xls"; header('Content-type: application/vnd.ms-excel;charset=UTF-16LE'); header('Content-Disposition: attachment; filename='.$filename); header("Cache-Control: no-cache"); echo $string_to_export; die(); } protected function print_webpage($state_info = null) { $data = $this->get_common_data(); $data->order_by = $this->order_by; $data->types = $this->get_field_types(); $data->list = $this->get_list(); $data->list = $this->change_list($data->list , $data->types); $data->list = $this->change_list_add_actions($data->list); $data->total_results = $this->get_total_results(); $data->columns = $this->get_columns(); $data->primary_key = $this->get_primary_key(); @ob_end_clean(); $this->_print_webpage($data); } protected function _print_webpage($data) { $string_to_print = "<meta charset=\"utf-8\" /><style type=\"text/css\" > #print-table{ color: #000; background: #fff; font-family: Verdana,Tahoma,Helvetica,sans-serif; font-size: 13px;} #print-table table tr td, #print-table table tr th{ border: 1px solid black; border-bottom: none; border-right: none; padding: 4px 8px 4px 4px} #print-table table{ border-bottom: 1px solid black; border-right: 1px solid black} #print-table table tr th{text-align: left;background: #ddd} #print-table table tr:nth-child(odd){background: #eee} </style>"; $string_to_print .= "<div id='print-table'>"; $string_to_print .= '<table width="100%" cellpadding="0" cellspacing="0" ><tr>'; foreach($data->columns as $column){ $string_to_print .= "<th>".$column->display_as."</th>"; } $string_to_print .= "</tr>"; foreach($data->list as $num_row => $row){ $string_to_print .= "<tr>"; foreach($data->columns as $column){ $string_to_print .= "<td>".$this->_trim_print_string($row->{$column->field_name})."</td>"; } $string_to_print .= "</tr>"; } $string_to_print .= "</table></div>"; echo $string_to_print; die(); } protected function _trim_export_string($value) { $value = str_replace(array("&nbsp;","&amp;","&gt;","&lt;"),array(" ","&",">","<"),$value); return strip_tags(str_replace(array("\t","\n","\r"),"",$value)); } protected function _trim_print_string($value) { $value = str_replace(array("&nbsp;","&amp;","&gt;","&lt;"),array(" ","&",">","<"),$value); //If the value has only spaces and nothing more then add the whitespace html character if(str_replace(" ","",$value) == "") $value = "&nbsp;"; return strip_tags($value); } protected function set_echo_and_die() { $this->echo_and_die = true; } protected function unset_echo_and_die() { $this->echo_and_die = false; } protected function showListInfo() { $this->set_echo_and_die(); $total_results = (int)$this->get_total_results(); @ob_end_clean(); echo json_encode(array('total_results' => $total_results)); die(); } protected function change_list_add_actions($list) { if(empty($this->actions)) return $list; $primary_key = $this->get_primary_key(); foreach($list as $num_row => $row) { $actions_urls = array(); foreach($this->actions as $unique_id => $action) { if(!empty($action->url_callback)) { $actions_urls[$unique_id] = call_user_func($action->url_callback, $row->$primary_key, $row); } else { $actions_urls[$unique_id] = $action->url_has_http ? $action->link_url.$row->$primary_key : site_url($action->link_url.'/'.$row->$primary_key); } } $row->action_urls = $actions_urls; } return $list; } protected function change_list($list,$types) { $primary_key = $this->get_primary_key(); $has_callbacks = !empty($this->callback_column) ? true : false; $output_columns = $this->get_columns(); foreach($list as $num_row => $row) { foreach($output_columns as $column) { $field_name = $column->field_name; $field_value = isset( $row->{$column->field_name} ) ? $row->{$column->field_name} : null; if( $has_callbacks && isset($this->callback_column[$field_name]) ) $list[$num_row]->$field_name = call_user_func($this->callback_column[$field_name], $field_value, $row); elseif(isset($types[$field_name])) $list[$num_row]->$field_name = $this->change_list_value($types[$field_name] , $field_value); else $list[$num_row]->$field_name = $field_value; } } return $list; } protected function showAddForm() { $this->set_js($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); $data = $this->get_common_data(); $data->types = $this->get_field_types(); $data->list_url = $this->getListUrl(); $data->insert_url = $this->getInsertUrl(); $data->validation_url = $this->getValidationInsertUrl(); $data->input_fields = $this->get_add_input_fields(); $data->fields = $this->get_add_fields(); $data->hidden_fields = $this->get_add_hidden_fields(); $data->unset_back_to_list = $this->unset_back_to_list; $this->_theme_view('add.php',$data); $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); } protected function showEditForm($state_info) { $this->set_js($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); $data = $this->get_common_data(); $data->types = $this->get_field_types(); $data->field_values = $this->get_edit_values($state_info->primary_key); $data->add_url = $this->getAddUrl(); $data->list_url = $this->getListUrl(); $data->update_url = $this->getUpdateUrl($state_info); $data->delete_url = $this->getDeleteUrl($state_info); $data->input_fields = $this->get_edit_input_fields($data->field_values); $data->fields = $this->get_edit_fields(); $data->hidden_fields = $this->get_edit_hidden_fields(); $data->unset_back_to_list = $this->unset_back_to_list; $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); $this->_theme_view('edit.php',$data); $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); } protected function delete_layout($delete_result = true) { @ob_end_clean(); if($delete_result === false) { $error_message = '<p>'.$this->l('delete_error_message').'</p>'; echo json_encode(array('success' => $delete_result ,'error_message' => $error_message)); } else { $success_message = '<p>'.$this->l('delete_success_message').'</p>'; echo json_encode(array('success' => true , 'success_message' => $success_message)); } $this->set_echo_and_die(); } protected function get_success_message_at_list($field_info = null) { if($field_info !== null && isset($field_info->success_message) && $field_info->success_message) { if(!empty($field_info->primary_key) && !$this->unset_edit) { return $this->l('insert_success_message')." <a href='".$this->getEditUrl($field_info->primary_key)."'>".$this->l('form_edit')." {$this->subject}</a> "; } else { return $this->l('insert_success_message'); } } else { return null; } } protected function insert_layout($insert_result = false) { @ob_end_clean(); if($insert_result === false) { echo json_encode(array('success' => false)); } else { $success_message = '<p>'.$this->l('insert_success_message'); if(!$this->unset_back_to_list && !empty($insert_result) && !$this->unset_edit) { $success_message .= " <a href='".$this->getEditUrl($insert_result)."'>".$this->l('form_edit')." {$this->subject}</a> ".$this->l('form_or'); } if(!$this->unset_back_to_list) { $success_message .= " <a href='".$this->getListUrl()."'>".$this->l('form_go_back_to_list')."</a>"; } $success_message .= '</p>'; echo "<textarea>".json_encode(array( 'success' => true , 'insert_primary_key' => $insert_result, 'success_message' => $success_message, 'success_list_url' => $this->getListSuccessUrl($insert_result) ))."</textarea>"; } $this->set_echo_and_die(); } protected function validation_layout($validation_result) { @ob_end_clean(); echo "<textarea>".json_encode($validation_result)."</textarea>"; $this->set_echo_and_die(); } protected function upload_layout($upload_result, $field_name) { @ob_end_clean(); if($upload_result !== false && !is_string($upload_result) && empty($upload_result[0]->error)) { echo json_encode( (object)array( 'success' => true, 'files' => $upload_result )); } else { $result = (object)array('success' => false); if(is_string($upload_result)) $result->message = $upload_result; if(!empty($upload_result[0]->error)) $result->message = $upload_result[0]->error; echo json_encode($result); } $this->set_echo_and_die(); } protected function delete_file_layout($upload_result) { @ob_end_clean(); if($upload_result !== false) { echo json_encode( (object)array( 'success' => true ) ); } else { echo json_encode((object)array('success' => false)); } $this->set_echo_and_die(); } public function set_css($css_file) { $this->css_files[sha1($css_file)] = base_url().$css_file; } public function set_js($js_file) { $this->js_files[sha1($js_file)] = base_url().$js_file; } public function get_css_files() { return $this->css_files; } public function get_js_files() { return $this->js_files; } protected function get_layout() { $js_files = $this->get_js_files(); $css_files = $this->get_css_files(); if($this->unset_jquery) unset($js_files[sha1($this->default_javascript_path.'/'.grocery_CRUD::JQUERY)]); if($this->unset_jquery_ui) { unset($css_files[sha1($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS)]); unset($js_files[sha1($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS)]); } if($this->echo_and_die === false) { /** Initialize JavaScript variables */ $js_vars = array( 'default_javascript_path' => base_url().$this->default_javascript_path, 'default_css_path' => base_url().$this->default_css_path, 'default_texteditor_path' => base_url().$this->default_texteditor_path, 'default_theme_path' => base_url().$this->default_theme_path, 'base_url' => base_url() ); $this->_add_js_vars($js_vars); return (object)array('output' => $this->views_as_string, 'js_files' => $js_files, 'css_files' => $css_files); } elseif($this->echo_and_die === true) { echo $this->views_as_string; die(); } } protected function update_layout($update_result = false, $state_info = null) { @ob_end_clean(); if($update_result === false) { echo json_encode(array('success' => $update_result)); } else { $success_message = '<p>'.$this->l('update_success_message'); if(!$this->unset_back_to_list) { $success_message .= " <a href='".$this->getListUrl()."'>".$this->l('form_go_back_to_list')."</a>"; } $success_message .= '</p>'; /* The textarea is only because of a BUG of the jquery form plugin with the combination of multipart forms */ echo "<textarea>".json_encode(array( 'success' => true , 'insert_primary_key' => $update_result, 'success_message' => $success_message, 'success_list_url' => $this->getListSuccessUrl($state_info->primary_key) ))."</textarea>"; } $this->set_echo_and_die(); } protected function get_integer_input($field_info,$value) { $this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.numeric.min.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.numeric.config.js'); $extra_attributes = ''; if(!empty($field_info->db_max_length)) $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$value' class='numeric' $extra_attributes />"; return $input; } protected function get_true_false_input($field_info,$value) { $this->set_css($this->default_css_path.'/jquery_plugins/uniform/uniform.default.css'); $this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.uniform.min.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.uniform.config.js'); $value_is_null = empty($value) && $value !== '0' && $value !== 0 ? true : false; $input = "<div class='pretty-radio-buttons'>"; $checked = $value === '1' || ($value_is_null && $field_info->default === '1') ? "checked = 'checked'" : ""; $input .= "<label><input id='field-{$field_info->name}-true' class='radio-uniform' type='radio' name='{$field_info->name}' value='1' $checked /> ".$this->default_true_false_text[1]."</label> "; $checked = $value === '0' || ($value_is_null && $field_info->default === '0') ? "checked = 'checked'" : ""; $input .= "<label><input id='field-{$field_info->name}-false' class='radio-uniform' type='radio' name='{$field_info->name}' value='0' $checked /> ".$this->default_true_false_text[0]."</label>"; $input .= "</div>"; return $input; } protected function get_string_input($field_info,$value) { $value = !is_string($value) ? '' : str_replace('"',"&quot;",$value); $extra_attributes = ''; if(!empty($field_info->db_max_length)) $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value=\"$value\" $extra_attributes />"; return $input; } protected function get_text_input($field_info,$value) { if($field_info->extras == 'text_editor') { $editor = $this->config->default_text_editor; switch ($editor) { case 'ckeditor': $this->set_js($this->default_texteditor_path.'/ckeditor/ckeditor.js'); $this->set_js($this->default_texteditor_path.'/ckeditor/adapters/jquery.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.ckeditor.config.js'); break; case 'tinymce': $this->set_js($this->default_texteditor_path.'/tiny_mce/jquery.tinymce.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.tine_mce.config.js'); break; case 'markitup': $this->set_css($this->default_texteditor_path.'/markitup/skins/markitup/style.css'); $this->set_css($this->default_texteditor_path.'/markitup/sets/default/style.css'); $this->set_js($this->default_texteditor_path.'/markitup/jquery.markitup.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.markitup.config.js'); break; } $class_name = $this->config->text_editor_type == 'minimal' ? 'mini-texteditor' : 'texteditor'; $input = "<textarea id='field-{$field_info->name}' name='{$field_info->name}' class='$class_name' >$value</textarea>"; } else { $input = "<textarea id='field-{$field_info->name}' name='{$field_info->name}'>$value</textarea>"; } return $input; } protected function get_datetime_input($field_info,$value) { $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); $this->set_css($this->default_css_path.'/jquery_plugins/jquery.ui.datetime.css'); $this->set_css($this->default_css_path.'/jquery_plugins/jquery-ui-timepicker-addon.css'); $this->set_js($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); $this->set_js($this->default_javascript_path.'/jquery_plugins/jquery-ui-timepicker-addon.min.js'); if($this->language !== 'english') { include($this->default_config_path.'/language_alias.php'); if(array_key_exists($this->language, $language_alias)) { $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; if(file_exists($i18n_date_js_file)) { $this->set_js($i18n_date_js_file); } $i18n_datetime_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-'.$language_alias[$this->language].'.js'; if(file_exists($i18n_datetime_js_file)) { $this->set_js($i18n_datetime_js_file); } } } $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery-ui-timepicker-addon.config.js'); if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00'){ list($year,$month,$day) = explode('-',substr($value,0,10)); $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); $datetime = $date.substr($value,10); } else { $datetime = ''; } $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$datetime' maxlength='19' class='datetime-input' /> <a class='datetime-input-clear' tabindex='-1'>".$this->l('form_button_clear')."</a> ({$this->ui_date_format}) hh:mm:ss"; return $input; } protected function get_hidden_input($field_info,$value) { if($field_info->extras !== null && $field_info->extras != false) $value = $field_info->extras; $input = "<input id='field-{$field_info->name}' type='hidden' name='{$field_info->name}' value='$value' />"; return $input; } protected function get_password_input($field_info,$value) { $value = !is_string($value) ? '' : $value; $extra_attributes = ''; if(!empty($field_info->db_max_length)) $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='password' value='$value' $extra_attributes />"; return $input; } protected function get_date_input($field_info,$value) { $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); $this->set_js($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); if($this->language !== 'english') { include($this->default_config_path.'/language_alias.php'); if(array_key_exists($this->language, $language_alias)) { $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; if(file_exists($i18n_date_js_file)) { $this->set_js($i18n_date_js_file); } } } $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.datepicker.config.js'); if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') { list($year,$month,$day) = explode('-',substr($value,0,10)); $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); } else { $date = ''; } $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$date' maxlength='10' class='datepicker-input' /> <a class='datepicker-input-clear' tabindex='-1'>".$this->l('form_button_clear')."</a> (".$this->ui_date_format.")"; return $input; } protected function get_dropdown_input($field_info,$value) { $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); $this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='chosen-select' data-placeholder='".$select_title."'>"; $options = array('' => '') + $field_info->extras; foreach($options as $option_value => $option_label) { $selected = !empty($value) && $value == $option_value ? "selected='selected'" : ''; $input .= "<option value='$option_value' $selected >$option_label</option>"; } $input .= "</select>"; return $input; } protected function get_enum_input($field_info,$value) { $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); $this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='chosen-select' data-placeholder='".$select_title."'>"; $options_array = $field_info->extras !== false && is_array($field_info->extras)? $field_info->extras : explode("','",substr($field_info->db_max_length,1,-1)); $options_array = array('' => '') + $options_array; foreach($options_array as $option) { $selected = !empty($value) && $value == $option ? "selected='selected'" : ''; $input .= "<option value='$option' $selected >$option</option>"; } $input .= "</select>"; return $input; } protected function get_readonly_input($field_info,$value) { return '<div id="field-'.$field_info->name.'" class="readonly_label">'.$value.'</div>'; } protected function get_set_input($field_info,$value) { $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); $this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/ajax-chosen.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); $options_array = $field_info->extras !== false && is_array($field_info->extras)? $field_info->extras : explode("','",substr($field_info->db_max_length,1,-1)); $selected_values = !empty($value) ? explode(",",$value) : array(); $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); $input = "<select id='field-{$field_info->name}' name='{$field_info->name}[]' multiple='multiple' size='8' class='chosen-multiple-select' data-placeholder='$select_title' style='width:510px;' >"; foreach($options_array as $option) { $selected = !empty($value) && in_array($option,$selected_values) ? "selected='selected'" : ''; $input .= "<option value='$option' $selected >$option</option>"; } $input .= "</select>"; return $input; } protected function get_multiselect_input($field_info,$value) { $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); $this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/ajax-chosen.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); $options_array = $field_info->extras; $selected_values = !empty($value) ? explode(",",$value) : array(); $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); $input = "<select id='field-{$field_info->name}' name='{$field_info->name}[]' multiple='multiple' size='8' class='chosen-multiple-select' data-placeholder='$select_title' style='width:510px;' >"; foreach($options_array as $option_value => $option_label) { $selected = !empty($value) && in_array($option_value,$selected_values) ? "selected='selected'" : ''; $input .= "<option value='$option_value' $selected >$option_label</option>"; } $input .= "</select>"; return $input; } protected function get_relation_input($field_info,$value) { $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); $this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); $ajax_limitation = 10000; $total_rows = $this->get_relation_total_rows($field_info->extras); //Check if we will use ajax for our queries or just clien-side javascript $using_ajax = $total_rows > $ajax_limitation ? true : false; //We will not use it for now. It is not ready yet. Probably we will have this functionality at version 1.4 $using_ajax = false; //If total rows are more than the limitation, use the ajax plugin $ajax_or_not_class = $using_ajax ? 'chosen-select' : 'chosen-select'; $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='$ajax_or_not_class' data-placeholder='$select_title' style='width:300px'>"; $input .= "<option value=''></option>"; if(!$using_ajax) { $options_array = $this->get_relation_array($field_info->extras); foreach($options_array as $option_value => $option) { $selected = !empty($value) && $value == $option_value ? "selected='selected'" : ''; $input .= "<option value='$option_value' $selected >$option</option>"; } } elseif(!empty($value) || (is_numeric($value) && $value == '0') ) //If it's ajax then we only need the selected items and not all the items { $selected_options_array = $this->get_relation_array($field_info->extras, $value); foreach($selected_options_array as $option_value => $option) { $input .= "<option value='$option_value'selected='selected' >$option</option>"; } } $input .= "</select>"; return $input; } protected function get_relation_n_n_input($field_info_type, $selected_values) { $has_priority_field = !empty($field_info_type->extras->priority_field_relation_table) ? true : false; $is_ie_7 = isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) ? true : false; if($has_priority_field || $is_ie_7) { $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); $this->set_css($this->default_css_path.'/jquery_plugins/ui.multiselect.css'); $this->set_js($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); $this->set_js($this->default_javascript_path.'/jquery_plugins/ui.multiselect.min.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.multiselect.js'); if($this->language !== 'english') { include($this->default_config_path.'/language_alias.php'); if(array_key_exists($this->language, $language_alias)) { $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/multiselect/ui-multiselect-'.$language_alias[$this->language].'.js'; if(file_exists($i18n_date_js_file)) { $this->set_js($i18n_date_js_file); } } } } else { $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); $this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/ajax-chosen.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); } $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); $field_info = $this->relation_n_n[$field_info_type->name]; //As we use this function the relation_n_n exists, so don't need to check $unselected_values = $this->get_relation_n_n_unselected_array($field_info, $selected_values); if(empty($unselected_values) && empty($selected_values)) { $input = "Please add {$field_info_type->display_as} first"; } else { $css_class = $has_priority_field || $is_ie_7 ? 'multiselect': 'chosen-multiple-select'; $width_style = $has_priority_field || $is_ie_7 ? '' : 'width:510px;'; $select_title = str_replace('{field_display_as}',$field_info_type->display_as,$this->l('set_relation_title')); $input = "<select id='field-{$field_info_type->name}' name='{$field_info_type->name}[]' multiple='multiple' size='8' class='$css_class' data-placeholder='$select_title' style='$width_style' >"; if(!empty($unselected_values)) foreach($unselected_values as $id => $name) { $input .= "<option value='$id'>$name</option>"; } if(!empty($selected_values)) foreach($selected_values as $id => $name) { $input .= "<option value='$id' selected='selected'>$name</option>"; } $input .= "</select>"; } return $input; } protected function _convert_bytes_ui_to_bytes($bytes_ui) { $bytes_ui = str_replace(' ','',$bytes_ui); if(strstr($bytes_ui,'MB')) $bytes = (int)(str_replace('MB','',$bytes_ui))*1024*1024; elseif(strstr($bytes_ui,'KB')) $bytes = (int)(str_replace('KB','',$bytes_ui))*1024; elseif(strstr($bytes_ui,'B')) $bytes = (int)(str_replace('B','',$bytes_ui)); else $bytes = (int)($bytes_ui); return $bytes; } protected function get_upload_file_input($field_info, $value) { $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/file-uploader.css'); $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/jquery.fileupload-ui.css'); $this->set_js($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); $this->set_js($this->default_javascript_path.'/jquery_plugins/tmpl.min.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/load-image.min.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.iframe-transport.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.fileupload.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.fileupload.config.js'); //Fancybox $this->set_css($this->default_css_path.'/jquery_plugins/fancybox/jquery.fancybox.css'); $this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.fancybox.pack.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.easing-1.3.pack.js'); $this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.fancybox.config.js'); $unique = uniqid(); $allowed_files = $this->config->file_upload_allow_file_types; $allowed_files_ui = '.'.str_replace('|',',.',$allowed_files); $max_file_size_ui = $this->config->file_upload_max_file_size; $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); $this->_inline_js(' var upload_info_'.$unique.' = { accepted_file_types: /(\\.|\\/)('.$allowed_files.')$/i, accepted_file_types_ui : "'.$allowed_files_ui.'", max_file_size: '.$max_file_size_bytes.', max_file_size_ui: "'.$max_file_size_ui.'" }; var string_upload_file = "'.$this->l('form_upload_a_file').'"; var string_delete_file = "'.$this->l('string_delete_file').'"; var string_progress = "'.$this->l('string_progress').'"; var error_on_uploading = "'.$this->l('error_on_uploading').'"; var message_prompt_delete_file = "'.$this->l('message_prompt_delete_file').'"; var error_max_number_of_files = "'.$this->l('error_max_number_of_files').'"; var error_accept_file_types = "'.$this->l('error_accept_file_types').'"; var error_max_file_size = "'.str_replace("{max_file_size}",$max_file_size_ui,$this->l('error_max_file_size')).'"; var error_min_file_size = "'.$this->l('error_min_file_size').'"; var base_url = "'.base_url().'"; var upload_a_file_string = "'.$this->l('form_upload_a_file').'"; '); $uploader_display_none = empty($value) ? "" : "display:none;"; $file_display_none = empty($value) ? "display:none;" : ""; $is_image = !empty($value) && ( substr($value,-4) == '.jpg' || substr($value,-4) == '.png' || substr($value,-5) == '.jpeg' || substr($value,-4) == '.gif' || substr($value,-5) == '.tiff') ? true : false; $image_class = $is_image ? 'image-thumbnail' : ''; $input = '<span class="fileinput-button qq-upload-button" id="upload-button-'.$unique.'" style="'.$uploader_display_none.'"> <span>'.$this->l('form_upload_a_file').'</span> <input type="file" name="'.$this->_unique_field_name($field_info->name).'" class="gc-file-upload" rel="'.$this->getUploadUrl($field_info->name).'" id="'.$unique.'"> <input class="hidden-upload-input" type="hidden" name="'.$field_info->name.'" value="'.$value.'" rel="'.$this->_unique_field_name($field_info->name).'" /> </span>'; $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/fileuploader.css'); $file_url = base_url().$field_info->extras->upload_path.'/'.$value; $input .= "<div id='uploader_$unique' rel='$unique' class='grocery-crud-uploader' style='$uploader_display_none'></div>"; $input .= "<div id='success_$unique' class='upload-success-url' style='$file_display_none padding-top:7px;'>"; $input .= "<a href='".$file_url."' id='file_$unique' class='open-file"; $input .= $is_image ? " $image_class'><img src='".$file_url."' height='50px'>" : "' target='_blank'>$value"; $input .= "</a> "; $input .= "<a href='javascript:void(0)' id='delete_$unique' class='delete-anchor'>".$this->l('form_upload_delete')."</a> "; $input .= "</div><div style='clear:both'></div>"; $input .= "<div id='loading-$unique' style='display:none'><span id='upload-state-message-$unique'></span> <span class='qq-upload-spinner'></span> <span id='progress-$unique'></span></div>"; $input .= "<div style='display:none'><a href='".$this->getUploadUrl($field_info->name)."' id='url_$unique'></a></div>"; $input .= "<div style='display:none'><a href='".$this->getFileDeleteUrl($field_info->name)."' id='delete_url_$unique' rel='$value' ></a></div>"; return $input; } protected function get_add_hidden_fields() { return $this->add_hidden_fields; } protected function get_edit_hidden_fields() { return $this->edit_hidden_fields; } protected function get_add_input_fields($field_values = null) { $fields = $this->get_add_fields(); $types = $this->get_field_types(); $input_fields = array(); foreach($fields as $field_num => $field) { $field_info = $types[$field->field_name]; $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; if(!isset($this->callback_add_field[$field->field_name])) { $field_input = $this->get_field_input($field_info, $field_value); } else { $field_input = $field_info; $field_input->input = call_user_func($this->callback_add_field[$field->field_name], $field_value, null, $field_info); } switch ($field_info->crud_type) { case 'invisible': unset($this->add_fields[$field_num]); unset($fields[$field_num]); continue; break; case 'hidden': $this->add_hidden_fields[] = $field_input; unset($this->add_fields[$field_num]); unset($fields[$field_num]); continue; break; } $input_fields[$field->field_name] = $field_input; } return $input_fields; } protected function get_edit_input_fields($field_values = null) { $fields = $this->get_edit_fields(); $types = $this->get_field_types(); $input_fields = array(); foreach($fields as $field_num => $field) { $field_info = $types[$field->field_name]; $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; if(!isset($this->callback_edit_field[$field->field_name])) { $field_input = $this->get_field_input($field_info, $field_value); } else { $primary_key = $this->getStateInfo()->primary_key; $field_input = $field_info; $field_input->input = call_user_func($this->callback_edit_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); } switch ($field_info->crud_type) { case 'invisible': unset($this->edit_fields[$field_num]); unset($fields[$field_num]); continue; break; case 'hidden': $this->edit_hidden_fields[] = $field_input; unset($this->edit_fields[$field_num]); unset($fields[$field_num]); continue; break; } $input_fields[$field->field_name] = $field_input; } return $input_fields; } protected function setThemeBasics() { $this->theme_path = $this->default_theme_path; if(substr($this->theme_path,-1) != '/') $this->theme_path = $this->theme_path.'/'; include($this->theme_path.$this->theme.'/config.php'); $this->theme_config = $config; } public function set_theme($theme = null) { $this->theme = $theme; } protected function _theme_view($view, $vars = array(), $return = FALSE) { $vars = (is_object($vars)) ? get_object_vars($vars) : $vars; $file_exists = FALSE; $ext = pathinfo($view, PATHINFO_EXTENSION); $file = ($ext == '') ? $view.'.php' : $view; $view_file = $this->theme_path.$this->theme.'/views/'; if (file_exists($view_file.$file)) { $path = $view_file.$file; $file_exists = TRUE; } if ( ! $file_exists) { throw new Exception('Unable to load the requested file: '.$file, 16); } extract($vars); #region buffering... ob_start(); include($path); $buffer = ob_get_contents(); @ob_end_clean(); #endregion if ($return === TRUE) { return $buffer; } $this->views_as_string .= $buffer; } protected function _inline_js($inline_js = '') { $this->views_as_string .= "<script type=\"text/javascript\">\n{$inline_js}\n</script>\n"; } protected function _add_js_vars($js_vars = array()) { $javascript_as_string = "<script type=\"text/javascript\">\n"; foreach ($js_vars as $js_var => $js_value) { $javascript_as_string .= "\tvar $js_var = '$js_value';\n"; } $javascript_as_string .= "\n</script>\n"; $this->views_as_string .= $javascript_as_string; } protected function get_views_as_string() { if(!empty($this->views_as_string)) return $this->views_as_string; else return null; } } /** * PHP grocery CRUD * * LICENSE * * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. * Please see the corresponding license file for details of these licenses. * You are free to use, modify and distribute this software, but all copyright information must remain. * * @package grocery CRUD * @copyright Copyright (c) 2010 through 2012, John Skoumbourdis * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt * @author John Skoumbourdis <scoumbourdisj@gmail.com> */ // ------------------------------------------------------------------------ /** * PHP grocery States * * States of grocery CRUD * * @package grocery CRUD * @author John Skoumbourdis <scoumbourdisj@gmail.com> * @version 1.3 */ class grocery_CRUD_States extends grocery_CRUD_Layout { protected $states = array( 0 => 'unknown', 1 => 'list', 2 => 'add', 3 => 'edit', 4 => 'delete', 5 => 'insert', 6 => 'update', 7 => 'ajax_list', 8 => 'ajax_list_info', 9 => 'insert_validation', 10 => 'update_validation', 11 => 'upload_file', 12 => 'delete_file', 13 => 'ajax_relation', 14 => 'ajax_relation_n_n', 15 => 'success', 16 => 'export', 17 => 'print' ); protected function getStateCode() { $state_string = $this->get_state_info_from_url()->operation; if( $state_string != 'unknown' && in_array( $state_string, $this->states ) ) $state_code = array_search($state_string, $this->states); else $state_code = 0; return $state_code; } protected function state_url($url = '') { $ci = &get_instance(); $segment_object = $this->get_state_info_from_url(); $method_name = $this->get_method_name(); $segment_position = $segment_object->segment_position; $state_url_array = array(); if( sizeof($ci->uri->segments) > 0 ) { foreach($ci->uri->segments as $num => $value) { $state_url_array[$num] = $value; if($num == ($segment_position - 1)) break; } if( $method_name == 'index' && !in_array( 'index', $state_url_array ) ) //there is a scenario that you don't have the index to your url $state_url_array[$num+1] = 'index'; } $state_url = implode('/',$state_url_array).'/'.$url; return site_url($state_url); } protected function get_state_info_from_url() { $ci = &get_instance(); $segment_position = count($ci->uri->segments) + 1; $operation = 'list'; $segements = $ci->uri->segments; foreach($segements as $num => $value) { if($value != 'unknown' && in_array($value, $this->states)) { $segment_position = (int)$num; $operation = $value; //I don't have a "break" here because I want to ensure that is the LAST segment with name that is in the array. } } $function_name = $this->get_method_name(); if($function_name == 'index' && !in_array('index',$ci->uri->segments)) $segment_position++; $first_parameter = isset($segements[$segment_position+1]) ? $segements[$segment_position+1] : null; $second_parameter = isset($segements[$segment_position+2]) ? $segements[$segment_position+2] : null; return (object)array('segment_position' => $segment_position, 'operation' => $operation, 'first_parameter' => $first_parameter, 'second_parameter' => $second_parameter); } protected function get_method_hash() { $ci = &get_instance(); $state_info = $this->get_state_info_from_url(); $extra_values = $ci->uri->segment($state_info->segment_position - 1) != $this->get_method_name() ? $ci->uri->segment($state_info->segment_position - 1) : ''; return md5($this->get_controller_name().$this->get_method_name().$extra_values); } protected function get_method_name() { $ci = &get_instance(); return $ci->router->method; } protected function get_controller_name() { $ci = &get_instance(); return $ci->router->class; } public function getState() { return $this->states[$this->getStateCode()]; } protected function getListUrl() { return $this->state_url(''); } protected function getAjaxListUrl() { return $this->state_url('ajax_list'); } protected function getExportToExcelUrl() { return $this->state_url('export'); } protected function getPrintUrl() { return $this->state_url('print'); } protected function getAjaxListInfoUrl() { return $this->state_url('ajax_list_info'); } protected function getAddUrl() { return $this->state_url('add'); } protected function getInsertUrl() { return $this->state_url('insert'); } protected function getValidationInsertUrl() { return $this->state_url('insert_validation'); } protected function getValidationUpdateUrl($primary_key = null) { if($primary_key === null) return $this->state_url('update_validation'); else return $this->state_url('update_validation/'.$primary_key); } protected function getEditUrl($primary_key = null) { if($primary_key === null) return $this->state_url('edit'); else return $this->state_url('edit/'.$primary_key); } protected function getUpdateUrl($state_info) { return $this->state_url('update/'.$state_info->primary_key); } protected function getDeleteUrl($state_info = null) { if(empty($state_info)) return $this->state_url('delete'); else return $this->state_url('delete/'.$state_info->primary_key); } protected function getListSuccessUrl($primary_key = null) { if(empty($primary_key)) return $this->state_url('success'); else return $this->state_url('success/'.$primary_key); } protected function getUploadUrl($field_name) { return $this->state_url('upload_file/'.$field_name); } protected function getFileDeleteUrl($field_name) { return $this->state_url('delete_file/'.$field_name); } protected function getAjaxRelationUrl() { return $this->state_url('ajax_relation'); } protected function getAjaxRelationManytoManyUrl() { return $this->state_url('ajax_relation_n_n'); } public function getStateInfo() { $state_code = $this->getStateCode(); $segment_object = $this->get_state_info_from_url(); $first_parameter = $segment_object->first_parameter; $second_parameter = $segment_object->second_parameter; $state_info = (object)array(); switch ($state_code) { case 1: case 2: break; case 3: if($first_parameter !== null) { $state_info = (object)array('primary_key' => $first_parameter); } else { throw new Exception('On the state "edit" the Primary key cannot be null', 6); die(); } break; case 4: if($first_parameter !== null) { $state_info = (object)array('primary_key' => $first_parameter); } else { throw new Exception('On the state "delete" the Primary key cannot be null',7); die(); } break; case 5: if(!empty($_POST)) { $state_info = (object)array('unwrapped_data' => $_POST); } else { throw new Exception('On the state "insert" you must have post data',8); die(); } break; case 6: if(!empty($_POST) && $first_parameter !== null) { $state_info = (object)array('primary_key' => $first_parameter,'unwrapped_data' => $_POST); } elseif(empty($_POST)) { throw new Exception('On the state "update" you must have post data',9); die(); } else { throw new Exception('On the state "update" the Primary key cannot be null',10); die(); } break; case 7: case 8: case 16: //export to excel case 17: //print $state_info = (object)array(); if(!empty($_POST['per_page'])) { $state_info->per_page = is_numeric($_POST['per_page']) ? $_POST['per_page'] : null; } if(!empty($_POST['page'])) { $state_info->page = is_numeric($_POST['page']) ? $_POST['page'] : null; } //If we request an export or a print we don't care about what page we are if($state_code === 16 || $state_code === 17) { $state_info->page = 1; $state_info->per_page = 1000000; //a big number } if(!empty($_POST['order_by'][0])) { $state_info->order_by = $_POST['order_by']; } if(!empty($_POST['search_text'])) { if(empty($_POST['search_field'])) { $search_text = strip_tags($_POST['search_field']); $state_info->search = (object)array( 'field' => null , 'text' => $_POST['search_text'] ); } else { $state_info->search = (object)array( 'field' => strip_tags($_POST['search_field']) , 'text' => $_POST['search_text'] ); } } break; case 9: case 10: break; case 11: $state_info->field_name = $first_parameter; break; case 12: $state_info->field_name = $first_parameter; $state_info->file_name = $second_parameter; break; case 13: $state_info->field_name = $_POST['field_name']; $state_info->search = $_POST['term']; break; case 14: $state_info->field_name = $_POST['field_name']; $state_info->search = $_POST['term']; break; case 15: $state_info = (object)array( 'primary_key' => $first_parameter, 'success_message' => true ); break; } return $state_info; } } /** * PHP grocery CRUD * * LICENSE * * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. * Please see the corresponding license file for details of these licenses. * You are free to use, modify and distribute this software, but all copyright information must remain. * * @package grocery CRUD * @copyright Copyright (c) 2010 through 2012, John Skoumbourdis * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt * @version 1.3.3 * @author John Skoumbourdis <scoumbourdisj@gmail.com> */ // ------------------------------------------------------------------------ /** * PHP grocery CRUD * * Creates a full functional CRUD with few lines of code. * * @package grocery CRUD * @author John Skoumbourdis <scoumbourdisj@gmail.com> * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt * @link http://www.grocerycrud.com/documentation */ class grocery_CRUD extends grocery_CRUD_States { /** * Grocery CRUD version * * @var string */ const VERSION = "1.3.3"; const JQUERY = "jquery-1.8.2.min.js"; const JQUERY_UI_JS = "jquery-ui-1.9.0.custom.min.js"; const JQUERY_UI_CSS = "jquery-ui-1.9.0.custom.min.css"; private $state_code = null; private $state_info = null; private $basic_db_table_checked = false; private $columns = null; private $columns_checked = false; private $add_fields_checked = false; private $edit_fields_checked = false; protected $default_theme = 'flexigrid'; protected $language = null; protected $lang_strings = array(); protected $php_date_format = null; protected $js_date_format = null; protected $ui_date_format = null; protected $character_limiter = null; protected $config = null; protected $add_fields = null; protected $edit_fields = null; protected $add_hidden_fields = array(); protected $edit_hidden_fields = array(); protected $field_types = null; protected $basic_db_table = null; protected $theme_config = array(); protected $subject = null; protected $subject_plural = null; protected $display_as = array(); protected $order_by = null; protected $where = array(); protected $like = array(); protected $having = array(); protected $or_having = array(); protected $limit = null; protected $required_fields = array(); protected $validation_rules = array(); protected $relation = array(); protected $relation_n_n = array(); protected $upload_fields = array(); protected $actions = array(); protected $form_validation = null; protected $change_field_type = null; protected $primary_keys = array(); /* The unsetters */ protected $unset_texteditor = array(); protected $unset_add = false; protected $unset_edit = false; protected $unset_delete = false; protected $unset_jquery = false; protected $unset_jquery_ui = false; protected $unset_list = false; protected $unset_export = false; protected $unset_print = false; protected $unset_back_to_list = false; protected $unset_columns = null; protected $unset_add_fields = null; protected $unset_edit_fields = null; /* Callbacks */ protected $callback_before_insert = null; protected $callback_after_insert = null; protected $callback_insert = null; protected $callback_before_update = null; protected $callback_after_update = null; protected $callback_update = null; protected $callback_before_delete = null; protected $callback_after_delete = null; protected $callback_delete = null; protected $callback_column = array(); protected $callback_add_field = array(); protected $callback_edit_field = array(); protected $callback_upload = null; protected $callback_before_upload = null; protected $callback_after_upload = null; protected $default_javascript_path = null; //autogenerate, please do not modify protected $default_css_path = null; //autogenerate, please do not modify protected $default_texteditor_path = null; //autogenerate, please do not modify protected $default_theme_path = null; //autogenerate, please do not modify protected $default_language_path = 'assets/grocery_crud/languages'; protected $default_config_path = 'assets/grocery_crud/config'; protected $default_assets_path = 'assets/grocery_crud'; /** * * Constructor * * @access public */ public function __construct() { } /** * The displayed columns that user see * * @access public * @param string * @param array * @return void */ public function columns() { $args = func_get_args(); if(isset($args[0]) && is_array($args[0])) { $args = $args[0]; } $this->columns = $args; return $this; } /** * Set Validation Rules * * Important note: If the $field is an array then no automated crud fields will take apart * * @access public * @param mixed * @param string * @return void */ function set_rules($field, $label = '', $rules = '') { if(is_string($field)) { $this->validation_rules[$field] = array('field' => $field, 'label' => $label, 'rules' => $rules); }elseif(is_array($field)) { foreach($field as $num_field => $field_array) { $this->validation_rules[$field_array['field']] = $field_array; } } return $this; } /** * * Changes the default field type * @param string $field * @param string $type * @param array|string $extras */ public function change_field_type($field , $type, $extras = null) { $field_type = (object)array('type' => $type); $field_type->extras = $extras; $this->change_field_type[$field] = $field_type; return $this; } /** * * Just an alias to the change_field_type method * @param string $field * @param string $type * @param array|string $extras */ public function field_type($field , $type, $extras = null) { return $this->change_field_type($field , $type, $extras); } /** * Change the default primary key for a specific table. * If the $table_name is NULL then the primary key is for the default table name that we added at the set_table method * * @param string $primary_key_field * @param string $table_name */ public function set_primary_key($primary_key_field, $table_name = null) { $this->primary_keys[] = array('field_name' => $primary_key_field, 'table_name' => $table_name); return $this; } /** * Unsets the texteditor of the selected fields * * @access public * @param string * @param array * @return void */ public function unset_texteditor() { $args = func_get_args(); if(isset($args[0]) && is_array($args[0])) { $args = $args[0]; } foreach($args as $arg) { $this->unset_texteditor[] = $arg; } return $this; } /** * Unsets just the jquery library from the js. This function can be used if there is already a jquery included * in the main template. This will avoid all jquery conflicts. * * @return void */ public function unset_jquery() { $this->unset_jquery = true; return $this; } /** * Unsets the jquery UI Javascript and CSS. This function is really useful * when the jquery UI JavaScript and CSS are already included in the main template. * This will avoid all jquery UI conflicts. * * @return void */ public function unset_jquery_ui() { $this->unset_jquery_ui = true; return $this; } /** * Unsets the add operation from the list * * @return void */ public function unset_add() { $this->unset_add = true; return $this; } /** * Unsets the edit operation from the list * * @return void */ public function unset_edit() { $this->unset_edit = true; return $this; } /** * Unsets the delete operation from the list * * @return void */ public function unset_delete() { $this->unset_delete = true; return $this; } /** * Unsets the export button and functionality from the list * * @return void */ public function unset_export() { $this->unset_export = true; return $this; } /** * Unsets the print button and functionality from the list * * @return void */ public function unset_print() { $this->unset_print = true; return $this; } /** * Unsets all the operations from the list * * @return void */ public function unset_operations() { $this->unset_add = true; $this->unset_edit = true; $this->unset_delete = true; $this->unset_export = true; $this->unset_print = true; return $this; } /** * Unsets a column from the list * * @return void. */ public function unset_columns() { $args = func_get_args(); if(isset($args[0]) && is_array($args[0])) { $args = $args[0]; } $this->unset_columns = $args; return $this; } public function unset_list() { $this->unset_list = true; return $this; } public function unset_fields() { $args = func_get_args(); if(isset($args[0]) && is_array($args[0])) { $args = $args[0]; } $this->unset_add_fields = $args; $this->unset_edit_fields = $args; return $this; } public function unset_add_fields() { $args = func_get_args(); if(isset($args[0]) && is_array($args[0])) { $args = $args[0]; } $this->unset_add_fields = $args; return $this; } public function unset_edit_fields() { $args = func_get_args(); if(isset($args[0]) && is_array($args[0])) { $args = $args[0]; } $this->unset_edit_fields = $args; return $this; } /** * Unsets everything that has to do with buttons or links with go back to list message * @access public * @return void */ public function unset_back_to_list() { $this->unset_back_to_list = true; return $this; } /** * * The fields that user will see on add/edit * * @access public * @param string * @param array * @return void */ public function fields() { $args = func_get_args(); if(isset($args[0]) && is_array($args[0])) { $args = $args[0]; } $this->add_fields = $args; $this->edit_fields = $args; return $this; } /** * * The fields that user can see . It is only for the add form */ public function add_fields() { $args = func_get_args(); if(isset($args[0]) && is_array($args[0])) { $args = $args[0]; } $this->add_fields = $args; return $this; } /** * * The fields that user can see . It is only for the edit form */ public function edit_fields() { $args = func_get_args(); if(isset($args[0]) && is_array($args[0])) { $args = $args[0]; } $this->edit_fields = $args; return $this; } /** * * Changes the displaying label of the field * @param $field_name * @param $display_as * @return void */ public function display_as($field_name, $display_as = null) { if(is_array($field_name)) { foreach($field_name as $field => $display_as) { $this->display_as[$field] = $display_as; } } elseif($display_as !== null) { $this->display_as[$field_name] = $display_as; } return $this; } /** * * Load the language strings array from the language file */ protected function _load_language() { if($this->language === null) { $this->language = strtolower($this->config->default_language); } include($this->default_language_path.'/'.$this->language.'.php'); foreach($lang as $handle => $lang_string) if(!isset($this->lang_strings[$handle])) $this->lang_strings[$handle] = $lang_string; $this->default_true_false_text = array( $this->l('form_inactive') , $this->l('form_active')); $this->subject = $this->subject === null ? $this->l('list_record') : $this->subject; } protected function _load_date_format() { list($php_day, $php_month, $php_year) = array('d','m','Y'); list($js_day, $js_month, $js_year) = array('dd','mm','yy'); list($ui_day, $ui_month, $ui_year) = array('dd','mm','yyyy'); //@todo ui_day, ui_month, ui_year has to be lang strings $date_format = $this->config->date_format; switch ($date_format) { case 'uk-date': $this->php_date_format = "$php_day/$php_month/$php_year"; $this->js_date_format = "$js_day/$js_month/$js_year"; $this->ui_date_format = "$ui_day/$ui_month/$ui_year"; break; case 'us-date': $this->php_date_format = "$php_month/$php_day/$php_year"; $this->js_date_format = "$js_month/$js_day/$js_year"; $this->ui_date_format = "$ui_month/$ui_day/$ui_year"; break; case 'sql-date': default: $this->php_date_format = "$php_year-$php_month-$php_day"; $this->js_date_format = "$js_year-$js_month-$js_day"; $this->ui_date_format = "$ui_year-$ui_month-$ui_day"; break; } } /** * * Set a language string directly * @param string $handle * @param string $string */ public function set_lang_string($handle, $lang_string){ $this->lang_strings[$handle] = $lang_string; return $this; } /** * * Just an alias to get_lang_string method * @param string $handle */ public function l($handle) { return $this->get_lang_string($handle); } /** * * Get the language string of the inserted string handle * @param string $handle */ public function get_lang_string($handle) { return $this->lang_strings[$handle]; } /** * * Simply set the language * @example english * @param string $language */ public function set_language($language) { $this->language = $language; return $this; } /** * * Enter description here ... */ protected function get_columns() { if($this->columns_checked === false) { $field_types = $this->get_field_types(); if(empty($this->columns)) { $this->columns = array(); foreach($field_types as $field) { if( !isset($field->db_extra) || $field->db_extra != 'auto_increment' ) $this->columns[] = $field->name; } } foreach($this->columns as $col_num => $column) { if(isset($this->relation[$column])) { $new_column = $this->_unique_field_name($this->relation[$column][0]); $this->columns[$col_num] = $new_column; if(isset($this->display_as[$column])) { $display_as = $this->display_as[$column]; unset($this->display_as[$column]); $this->display_as[$new_column] = $display_as; } else { $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); } $column = $new_column; $this->columns[$col_num] = $new_column; } else { if(!empty($this->relation)) { $table_name = $this->get_table(); foreach($this->relation as $relation) { if( $relation[2] == $column ) { $new_column = $table_name.'.'.$column; if(isset($this->display_as[$column])) { $display_as = $this->display_as[$column]; unset($this->display_as[$column]); $this->display_as[$new_column] = $display_as; } else { $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); } $column = $new_column; $this->columns[$col_num] = $new_column; } } } } if(isset($this->display_as[$column])) $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $this->display_as[$column]); elseif(isset($field_types[$column])) $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $field_types[$column]->display_as); else $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => ucfirst(str_replace('_',' ',$column))); if(!empty($this->unset_columns) && in_array($column,$this->unset_columns)) { unset($this->columns[$col_num]); } } $this->columns_checked = true; } return $this->columns; } /** * * Enter description here ... */ protected function get_add_fields() { if($this->add_fields_checked === false) { $field_types = $this->get_field_types(); if(!empty($this->add_fields)) { foreach($this->add_fields as $field_num => $field) { if(isset($this->display_as[$field])) $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); elseif(isset($field_types[$field]->display_as)) $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); else $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => ucfirst(str_replace('_',' ',$field))); } } else { $this->add_fields = array(); foreach($field_types as $field) { //Check if an unset_add_field is initialize for this field name if($this->unset_add_fields !== null && is_array($this->unset_add_fields) && in_array($field->name,$this->unset_add_fields)) continue; if( (!isset($field->db_extra) || $field->db_extra != 'auto_increment') ) { if(isset($this->display_as[$field->name])) $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); else $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); } } } $this->add_fields_checked = true; } return $this->add_fields; } /** * * Enter description here ... */ protected function get_edit_fields() { if($this->edit_fields_checked === false) { $field_types = $this->get_field_types(); if(!empty($this->edit_fields)) { foreach($this->edit_fields as $field_num => $field) { if(isset($this->display_as[$field])) $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); else $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); } } else { $this->edit_fields = array(); foreach($field_types as $field) { //Check if an unset_edit_field is initialize for this field name if($this->unset_edit_fields !== null && is_array($this->unset_edit_fields) && in_array($field->name,$this->unset_edit_fields)) continue; if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') { if(isset($this->display_as[$field->name])) $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); else $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); } } } $this->edit_fields_checked = true; } return $this->edit_fields; } public function order_by($order_by, $direction = 'asc') { $this->order_by = array($order_by,$direction); return $this; } public function where($key, $value = NULL, $escape = TRUE) { $this->where[] = array($key,$value,$escape); return $this; } public function or_where($key, $value = NULL, $escape = TRUE) { $this->or_where[] = array($key,$value,$escape); return $this; } public function like($field, $match = '', $side = 'both') { $this->like[] = array($field, $match, $side); return $this; } protected function having($key, $value = '', $escape = TRUE) { $this->having[] = array($key, $value, $escape); return $this; } protected function or_having($key, $value = '', $escape = TRUE) { $this->or_having[] = array($key, $value, $escape); return $this; } public function or_like($field, $match = '', $side = 'both') { $this->or_like[] = array($field, $match, $side); return $this; } public function limit($limit, $offset = '') { $this->limit = array($limit,$offset); return $this; } protected function _initialize_helpers() { $ci = &get_instance(); $ci->load->helper('url'); $ci->load->helper('form'); } protected function _initialize_variables() { $ci = &get_instance(); $ci->load->config('grocery_crud'); $this->config = (object)array(); /** Initialize all the config variables into this object */ $this->config->default_language = $ci->config->item('grocery_crud_default_language'); $this->config->date_format = $ci->config->item('grocery_crud_date_format'); $this->config->default_per_page = $ci->config->item('grocery_crud_default_per_page'); $this->config->file_upload_allow_file_types = $ci->config->item('grocery_crud_file_upload_allow_file_types'); $this->config->file_upload_max_file_size = $ci->config->item('grocery_crud_file_upload_max_file_size'); $this->config->default_text_editor = $ci->config->item('grocery_crud_default_text_editor'); $this->config->text_editor_type = $ci->config->item('grocery_crud_text_editor_type'); $this->config->character_limiter = $ci->config->item('grocery_crud_character_limiter'); /** Initialize default paths */ $this->default_javascript_path = $this->default_assets_path.'/js'; $this->default_css_path = $this->default_assets_path.'/css'; $this->default_texteditor_path = $this->default_assets_path.'/texteditor'; $this->default_theme_path = $this->default_assets_path.'/themes'; $this->character_limiter = $this->config->character_limiter; if($this->character_limiter === 0 || $this->character_limiter === '0') { $this->character_limiter = 1000000; //a big number } elseif($this->character_limiter === null || $this->character_limiter === false) { $this->character_limiter = 30; //is better to have the number 30 rather than the 0 value } } protected function _set_primary_keys_to_model() { if(!empty($this->primary_keys)) { foreach($this->primary_keys as $primary_key) { $this->basic_model->set_primary_key($primary_key['field_name'],$primary_key['table_name']); } } } /** * Initialize all the required libraries and variables before rendering */ protected function pre_render() { $this->_initialize_variables(); $this->_initialize_helpers(); $this->_load_language(); $this->state_code = $this->getStateCode(); if($this->basic_model === null) $this->set_default_Model(); $this->set_basic_db_table($this->get_table()); $this->_load_date_format(); $this->_set_primary_keys_to_model(); } /** * * Or else ... make it work! The web application takes decision of what to do and show it to the final user. * Without this function nothing works. Here is the core of grocery CRUD project. * * @access public */ public function render() { $this->pre_render(); if( $this->state_code != 0 ) { $this->state_info = $this->getStateInfo(); } else { throw new Exception('The state is unknown , I don\'t know what I will do with your data!', 4); die(); } switch ($this->state_code) { case 15://success case 1://list if($this->unset_list) { throw new Exception('You don\'t have permissions for this operation', 14); die(); } if($this->theme === null) $this->set_theme($this->default_theme); $this->setThemeBasics(); $this->set_basic_Layout(); $state_info = $this->getStateInfo(); $this->showList(false,$state_info); break; case 2://add if($this->unset_add) { throw new Exception('You don\'t have permissions for this operation', 14); die(); } if($this->theme === null) $this->set_theme($this->default_theme); $this->setThemeBasics(); $this->set_basic_Layout(); $this->showAddForm(); break; case 3://edit if($this->unset_edit) { throw new Exception('You don\'t have permissions for this operation', 14); die(); } if($this->theme === null) $this->set_theme($this->default_theme); $this->setThemeBasics(); $this->set_basic_Layout(); $state_info = $this->getStateInfo(); $this->showEditForm($state_info); break; case 4://delete if($this->unset_delete) { throw new Exception('This user is not allowed to do this operation', 14); die(); } $state_info = $this->getStateInfo(); $delete_result = $this->db_delete($state_info); $this->delete_layout( $delete_result ); break; case 5://insert if($this->unset_add) { throw new Exception('This user is not allowed to do this operation', 14); die(); } $state_info = $this->getStateInfo(); $insert_result = $this->db_insert($state_info); $this->insert_layout($insert_result); break; case 6://update if($this->unset_edit) { throw new Exception('This user is not allowed to do this operation', 14); die(); } $state_info = $this->getStateInfo(); $update_result = $this->db_update($state_info); $this->update_layout( $update_result,$state_info); break; case 7://ajax_list if($this->unset_list) { throw new Exception('You don\'t have permissions for this operation', 14); die(); } if($this->theme === null) $this->set_theme($this->default_theme); $this->setThemeBasics(); $this->set_basic_Layout(); $state_info = $this->getStateInfo(); $this->set_ajax_list_queries($state_info); $this->showList(true); break; case 8://ajax_list_info if($this->theme === null) $this->set_theme($this->default_theme); $this->setThemeBasics(); $this->set_basic_Layout(); $state_info = $this->getStateInfo(); $this->set_ajax_list_queries($state_info); $this->showListInfo(); break; case 9://insert_validation $validation_result = $this->db_insert_validation(); $this->validation_layout($validation_result); break; case 10://update_validation $validation_result = $this->db_update_validation(); $this->validation_layout($validation_result); break; case 11://upload_file $state_info = $this->getStateInfo(); $upload_result = $this->upload_file($state_info); $this->upload_layout($upload_result, $state_info->field_name); break; case 12://delete_file $state_info = $this->getStateInfo(); $delete_file_result = $this->delete_file($state_info); $this->delete_file_layout($delete_file_result); break; /* case 13: //ajax_relation $state_info = $this->getStateInfo(); $ajax_relation_result = $this->ajax_relation($state_info); $ajax_relation_result[""] = ""; echo json_encode($ajax_relation_result); die(); break; case 14: //ajax_relation_n_n echo json_encode(array("34" => 'Johnny' , "78" => "Test")); die(); break; */ case 16: //export to excel //a big number just to ensure that the table characters will not be cutted. $this->character_limiter = 1000000; if($this->unset_export) { throw new Exception('You don\'t have permissions for this operation', 15); die(); } if($this->theme === null) $this->set_theme($this->default_theme); $this->setThemeBasics(); $this->set_basic_Layout(); $state_info = $this->getStateInfo(); $this->set_ajax_list_queries($state_info); $this->exportToExcel($state_info); break; case 17: //print //a big number just to ensure that the table characters will not be cutted. $this->character_limiter = 1000000; if($this->unset_print) { throw new Exception('You don\'t have permissions for this operation', 15); die(); } if($this->theme === null) $this->set_theme($this->default_theme); $this->setThemeBasics(); $this->set_basic_Layout(); $state_info = $this->getStateInfo(); $this->set_ajax_list_queries($state_info); $this->print_webpage($state_info); break; } return $this->get_layout(); } protected function get_common_data() { $data = (object)array(); $data->subject = $this->subject; $data->subject_plural = $this->subject_plural; return $data; } /** * * Enter description here ... */ public function callback_before_insert($callback = null) { $this->callback_before_insert = $callback; return $this; } /** * * Enter description here ... */ public function callback_after_insert($callback = null) { $this->callback_after_insert = $callback; return $this; } /** * * Enter description here ... */ public function callback_insert($callback = null) { $this->callback_insert = $callback; return $this; } /** * * Enter description here ... */ public function callback_before_update($callback = null) { $this->callback_before_update = $callback; return $this; } /** * * Enter description here ... */ public function callback_after_update($callback = null) { $this->callback_after_update = $callback; return $this; } /** * * Enter description here ... * @param mixed $callback */ public function callback_update($callback = null) { $this->callback_update = $callback; return $this; } /** * * Enter description here ... */ public function callback_before_delete($callback = null) { $this->callback_before_delete = $callback; return $this; } /** * * Enter description here ... */ public function callback_after_delete($callback = null) { $this->callback_after_delete = $callback; return $this; } /** * * Enter description here ... */ public function callback_delete($callback = null) { $this->callback_delete = $callback; return $this; } /** * * Enter description here ... * @param string $column * @param mixed $callback */ public function callback_column($column ,$callback = null) { $this->callback_column[$column] = $callback; return $this; } /** * * Enter description here ... * @param string $field * @param mixed $callback */ public function callback_field($field, $callback = null) { $this->callback_add_field[$field] = $callback; $this->callback_edit_field[$field] = $callback; return $this; } /** * * Enter description here ... * @param string $field * @param mixed $callback */ public function callback_add_field($field, $callback = null) { $this->callback_add_field[$field] = $callback; return $this; } /** * * Enter description here ... * @param string $field * @param mixed $callback */ public function callback_edit_field($field, $callback = null) { $this->callback_edit_field[$field] = $callback; return $this; } /** * * Callback that replace the default auto uploader * * @param mixed $callback * @return grocery_CRUD */ public function callback_upload($callback = null) { $this->callback_upload = $callback; return $this; } /** * * A callback that triggered before the upload functionality. This callback is suggested for validation checks * @param mixed $callback * @return grocery_CRUD */ public function callback_before_upload($callback = null) { $this->callback_before_upload = $callback; return $this; } /** * * A callback that triggered after the upload functionality * @param mixed $callback * @return grocery_CRUD */ public function callback_after_upload($callback = null) { $this->callback_after_upload = $callback; return $this; } /** * * Gets the basic database table of our crud. * @return string */ public function get_table() { if($this->basic_db_table_checked) { return $this->basic_db_table; } elseif( $this->basic_db_table !== null ) { if(!$this->table_exists($this->basic_db_table)) { throw new Exception('The table name does not exist. Please check you database and try again.',11); die(); } $this->basic_db_table_checked = true; return $this->basic_db_table; } else { //Last try , try to find the table from your view / function name!!! Not suggested but it works . $last_chance_table_name = $this->get_method_name(); if($this->table_exists($last_chance_table_name)) { $this->set_table($last_chance_table_name); } $this->basic_db_table_checked = true; return $this->basic_db_table; } return false; } /** * * The field names of the required fields */ public function required_fields() { $args = func_get_args(); if(isset($args[0]) && is_array($args[0])) { $args = $args[0]; } $this->required_fields = $args; return $this; } /** * * Sets the basic database table that we will get our data. * @param string $table_name * @return grocery_CRUD */ public function set_table($table_name) { if(!empty($table_name) && $this->basic_db_table === null) { $this->basic_db_table = $table_name; } elseif(!empty($table_name)) { throw new Exception('You have already insert a table name once...', 1); } else { throw new Exception('The table name cannot be empty.', 2); die(); } return $this; } /** * * Set a subject to understand what type of CRUD you use. * @example In this CRUD we work with the table db_categories. The $subject will be the 'Category' * @param string $subject * @param bool $has_plural * @return grocery_CRUD */ public function set_subject( $subject ) { $this->subject = $subject; $this->subject_plural = $subject; return $this; } /** * * Enter description here ... * @param $title * @param $image_url * @param $url * @param $css_class * @param $url_callback */ public function add_action( $label, $image_url = '', $link_url = '', $css_class = '', $url_callback = null) { $unique_id = substr($label,0,1).substr(md5($label.$link_url),-8); //The unique id is used for class name so it must begin with a string $this->actions[$unique_id] = (object)array( 'label' => $label, 'image_url' => $image_url, 'link_url' => $link_url, 'css_class' => $css_class, 'url_callback' => $url_callback, 'url_has_http' => substr($link_url,0,7) == 'http://' ? true : false ); return $this; } /** * * Set a simple 1-n foreign key relation * @param string $field_name * @param string $related_table * @param string $related_title_field * @param mixed $where_clause * @param string $order_by */ public function set_relation($field_name , $related_table, $related_title_field, $where_clause = null, $order_by = null) { $this->relation[$field_name] = array($field_name, $related_table,$related_title_field, $where_clause, $order_by); return $this; } /** * * Sets a relation with n-n relationship. * @param string $field_name * @param string $relation_table * @param string $selection_table * @param string $primary_key_alias_to_this_table * @param string $primary_key_alias_to_selection_table * @param string $title_field_selection_table * @param string $priority_field_relation_table * @param mixed $where_clause */ public function set_relation_n_n($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, $primary_key_alias_to_selection_table , $title_field_selection_table , $priority_field_relation_table = null, $where_clause = null) { $this->relation_n_n[$field_name] = (object)array( 'field_name' => $field_name, 'relation_table' => $relation_table, 'selection_table' => $selection_table, 'primary_key_alias_to_this_table' => $primary_key_alias_to_this_table, 'primary_key_alias_to_selection_table' => $primary_key_alias_to_selection_table , 'title_field_selection_table' => $title_field_selection_table , 'priority_field_relation_table' => $priority_field_relation_table, 'where_clause' => $where_clause ); return $this; } /** * * Transform a field to an upload field * * @param string $field_name * @param string $upload_path */ public function set_field_upload($field_name, $upload_dir = null) { $upload_dir = substr($upload_dir,-1,1) == '/' ? substr($upload_dir,0,-1) : $upload_dir; $this->upload_fields[$field_name] = (object)array( 'field_name' => $field_name , 'upload_path' => $upload_dir, 'encrypted_field_name' => $this->_unique_field_name($field_name)); return $this; } } if(defined('CI_VERSION')) { $ci = &get_instance(); $ci->load->library('Form_validation'); class grocery_CRUD_Form_validation extends CI_Form_validation{ public $CI; public $_field_data = array(); public $_config_rules = array(); public $_error_array = array(); public $_error_messages = array(); public $_error_prefix = '<p>'; public $_error_suffix = '</p>'; public $error_string = ''; public $_safe_form_data = FALSE; } } /* * jQuery File Upload Plugin PHP Example 5.5 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2010, Sebastian Tschan * https://blueimp.net * * Licensed under the MIT license: * http://www.opensource.org/licenses/MIT */ class UploadHandler { private $options; public $default_config_path = null; function __construct($options=null) { $this->options = array( 'script_url' => $this->getFullUrl().'/'.basename(__FILE__), 'upload_dir' => dirname(__FILE__).'/files/', 'upload_url' => $this->getFullUrl().'/files/', 'param_name' => 'files', // The php.ini settings upload_max_filesize and post_max_size // take precedence over the following max_file_size setting: 'max_file_size' => null, 'min_file_size' => 1, 'accept_file_types' => '/.+$/i', 'max_number_of_files' => null, // Set the following option to false to enable non-multipart uploads: 'discard_aborted_uploads' => true, // Set to true to rotate images based on EXIF meta data, if available: 'orient_image' => false, 'image_versions' => array( // Uncomment the following version to restrict the size of // uploaded images. You can also add additional versions with // their own upload directories: /* 'large' => array( 'upload_dir' => dirname(__FILE__).'/files/', 'upload_url' => dirname($_SERVER['PHP_SELF']).'/files/', 'max_width' => 1920, 'max_height' => 1200 ), 'thumbnail' => array( 'upload_dir' => dirname(__FILE__).'/thumbnails/', 'upload_url' => $this->getFullUrl().'/thumbnails/', 'max_width' => 80, 'max_height' => 80 ) */ ) ); if ($options) { // Or else for PHP >= 5.3.0 use: $this->options = array_replace_recursive($this->options, $options); foreach($options as $option_name => $option) { $this->options[$option_name] = $option; } } } function getFullUrl() { return (isset($_SERVER['HTTPS']) ? 'https://' : 'http://'). (isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'].'@' : ''). (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ($_SERVER['SERVER_NAME']. (isset($_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] === 443 || $_SERVER['SERVER_PORT'] === 80 ? '' : ':'.$_SERVER['SERVER_PORT']))). substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'], '/')); } private function get_file_object($file_name) { $file_path = $this->options['upload_dir'].$file_name; if (is_file($file_path) && $file_name[0] !== '.') { $file = new stdClass(); $file->name = $file_name; $file->size = filesize($file_path); $file->url = $this->options['upload_url'].rawurlencode($file->name); foreach($this->options['image_versions'] as $version => $options) { if (is_file($options['upload_dir'].$file_name)) { $file->{$version.'_url'} = $options['upload_url'] .rawurlencode($file->name); } } $file->delete_url = $this->options['script_url'] .'?file='.rawurlencode($file->name); $file->delete_type = 'DELETE'; return $file; } return null; } private function get_file_objects() { return array_values(array_filter(array_map( array($this, 'get_file_object'), scandir($this->options['upload_dir']) ))); } private function create_scaled_image($file_name, $options) { $file_path = $this->options['upload_dir'].$file_name; $new_file_path = $options['upload_dir'].$file_name; list($img_width, $img_height) = @getimagesize($file_path); if (!$img_width || !$img_height) { return false; } $scale = min( $options['max_width'] / $img_width, $options['max_height'] / $img_height ); if ($scale > 1) { $scale = 1; } $new_width = $img_width * $scale; $new_height = $img_height * $scale; $new_img = @imagecreatetruecolor($new_width, $new_height); switch (strtolower(substr(strrchr($file_name, '.'), 1))) { case 'jpg': case 'jpeg': $src_img = @imagecreatefromjpeg($file_path); $write_image = 'imagejpeg'; break; case 'gif': @imagecolortransparent($new_img, @imagecolorallocate($new_img, 0, 0, 0)); $src_img = @imagecreatefromgif($file_path); $write_image = 'imagegif'; break; case 'png': @imagecolortransparent($new_img, @imagecolorallocate($new_img, 0, 0, 0)); @imagealphablending($new_img, false); @imagesavealpha($new_img, true); $src_img = @imagecreatefrompng($file_path); $write_image = 'imagepng'; break; default: $src_img = $image_method = null; } $success = $src_img && @imagecopyresampled( $new_img, $src_img, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height ) && $write_image($new_img, $new_file_path); // Free up memory (imagedestroy does not delete files): @imagedestroy($src_img); @imagedestroy($new_img); return $success; } private function has_error($uploaded_file, $file, $error) { if ($error) { return $error; } if (!preg_match($this->options['accept_file_types'], $file->name)) { return 'acceptFileTypes'; } if ($uploaded_file && is_uploaded_file($uploaded_file)) { $file_size = filesize($uploaded_file); } else { $file_size = $_SERVER['CONTENT_LENGTH']; } if ($this->options['max_file_size'] && ( $file_size > $this->options['max_file_size'] || $file->size > $this->options['max_file_size']) ) { return 'maxFileSize'; } if ($this->options['min_file_size'] && $file_size < $this->options['min_file_size']) { return 'minFileSize'; } if (is_int($this->options['max_number_of_files']) && ( count($this->get_file_objects()) >= $this->options['max_number_of_files']) ) { return 'maxNumberOfFiles'; } return $error; } private function trim_file_name($name, $type) { // Remove path information and dots around the filename, to prevent uploading // into different directories or replacing hidden system files. // Also remove control characters and spaces (\x00..\x20) around the filename: $file_name = trim(basename(stripslashes($name)), ".\x00..\x20"); // Add missing file extension for known image types: if (strpos($file_name, '.') === false && preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) { $file_name .= '.'.$matches[1]; } //Ensure that we don't have disallowed characters and add a unique id just to ensure that the file name will be unique $file_name = substr(uniqid(),-5).'-'.$this->_transliterate_characters($file_name); return $file_name; } private function _transliterate_characters($file_name) { include($this->default_config_path.'/translit_chars.php'); if ( ! isset($translit_characters)) { return preg_replace("/([^a-zA-Z0-9\.\-\_]+?){1}/i", '-', $file_name); } $transformed_file_name = preg_replace(array_keys($translit_characters), array_values($translit_characters), $file_name); return str_replace(" ", "-", $transformed_file_name); } private function orient_image($file_path) { $exif = exif_read_data($file_path); $orientation = intval(@$exif['Orientation']); if (!in_array($orientation, array(3, 6, 8))) { return false; } $image = @imagecreatefromjpeg($file_path); switch ($orientation) { case 3: $image = @imagerotate($image, 180, 0); break; case 6: $image = @imagerotate($image, 270, 0); break; case 8: $image = @imagerotate($image, 90, 0); break; default: return false; } $success = imagejpeg($image, $file_path); // Free up memory (imagedestroy does not delete files): @imagedestroy($image); return $success; } private function handle_file_upload($uploaded_file, $name, $size, $type, $error) { $file = new stdClass(); $file->name = $this->trim_file_name($name, $type); $file->size = intval($size); $file->type = $type; $error = $this->has_error($uploaded_file, $file, $error); if (!$error && $file->name) { $file_path = $this->options['upload_dir'].$file->name; $append_file = !$this->options['discard_aborted_uploads'] && is_file($file_path) && $file->size > filesize($file_path); clearstatcache(); if ($uploaded_file && is_uploaded_file($uploaded_file)) { // multipart/formdata uploads (POST method uploads) if ($append_file) { file_put_contents( $file_path, fopen($uploaded_file, 'r'), FILE_APPEND ); } else { move_uploaded_file($uploaded_file, $file_path); } } else { // Non-multipart uploads (PUT method support) file_put_contents( $file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0 ); } $file_size = filesize($file_path); if ($file_size === $file->size) { if ($this->options['orient_image']) { $this->orient_image($file_path); } $file->url = $this->options['upload_url'].rawurlencode($file->name); foreach($this->options['image_versions'] as $version => $options) { if ($this->create_scaled_image($file->name, $options)) { $file->{$version.'_url'} = $options['upload_url'] .rawurlencode($file->name); } } } else if ($this->options['discard_aborted_uploads']) { unlink($file_path); $file->error = 'abort'; } $file->size = $file_size; $file->delete_url = $this->options['script_url'] .'?file='.rawurlencode($file->name); $file->delete_type = 'DELETE'; } else { $file->error = $error; } return $file; } public function get() { $file_name = isset($_REQUEST['file']) ? basename(stripslashes($_REQUEST['file'])) : null; if ($file_name) { $info = $this->get_file_object($file_name); } else { $info = $this->get_file_objects(); } header('Content-type: application/json'); echo json_encode($info); } public function post() { if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') { return $this->delete(); } $upload = isset($_FILES[$this->options['param_name']]) ? $_FILES[$this->options['param_name']] : null; $info = array(); if ($upload && is_array($upload['tmp_name'])) { foreach ($upload['tmp_name'] as $index => $value) { $info[] = $this->handle_file_upload( $upload['tmp_name'][$index], isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'][$index], isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'][$index], isset($_SERVER['HTTP_X_FILE_TYPE']) ? $_SERVER['HTTP_X_FILE_TYPE'] : $upload['type'][$index], $upload['error'][$index] ); } } elseif ($upload || isset($_SERVER['HTTP_X_FILE_NAME'])) { $info[] = $this->handle_file_upload( isset($upload['tmp_name']) ? $upload['tmp_name'] : null, isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'], isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'], isset($_SERVER['HTTP_X_FILE_TYPE']) ? $_SERVER['HTTP_X_FILE_TYPE'] : $upload['type'], isset($upload['error']) ? $upload['error'] : null ); } header('Vary: Accept'); $redirect = isset($_REQUEST['redirect']) ? stripslashes($_REQUEST['redirect']) : null; if ($redirect) { header('Location: '.sprintf($redirect, rawurlencode($json))); return; } if (isset($_SERVER['HTTP_ACCEPT']) && (strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false)) { header('Content-type: application/json'); } else { header('Content-type: text/plain'); } return $info; } public function delete() { $file_name = isset($_REQUEST['file']) ? basename(stripslashes($_REQUEST['file'])) : null; $file_path = $this->options['upload_dir'].$file_name; $success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path); if ($success) { foreach($this->options['image_versions'] as $version => $options) { $file = $options['upload_dir'].$file_name; if (is_file($file)) { unlink($file); } } } header('Content-type: application/json'); echo json_encode($success); } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/libraries/grocery_crud.php
PHP
mit
143,648
<?php /* Hashids may be freely distributed under the MIT license. Documentation: http://www.hashids.org/php/ Source: https://github.com/ivanakimov/hashids.php */ namespace Hashids; class Hashids { const VERSION = '0.3.0'; /* internal settings */ const MIN_ALPHABET_LENGTH = 16; const SEP_DIV = 3.5; const GUARD_DIV = 12; /* error messages */ const E_ALPHABET_LENGTH = 'alphabet must contain at least %d unique characters'; const E_ALPHABET_SPACE = 'alphabet cannot contain spaces'; /* set at constructor */ private $_alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; private $_seps = 'cfhistuCFHISTU'; private $_min_hash_length = 0; private $_math_functions = array(); private $_max_int_value = 1000000000; function __construct($salt = '', $min_hash_length = 0, $alphabet = '') { /* if either math precision library is present, raise $this->_max_int_value */ if (function_exists('gmp_add')) { $this->_math_functions['add'] = 'gmp_add'; $this->_math_functions['div'] = 'gmp_div'; $this->_math_functions['str'] = 'gmp_strval'; } else if (function_exists('bcadd')) { $this->_math_functions['add'] = 'bcadd'; $this->_math_functions['div'] = 'bcdiv'; $this->_math_functions['str'] = 'strval'; } $this->_lower_max_int_value = $this->_max_int_value; if ($this->_math_functions) $this->_max_int_value = PHP_INT_MAX; /* handle parameters */ $this->_salt = $salt; if ((int)$min_hash_length > 0) $this->_min_hash_length = (int)$min_hash_length; if ($alphabet) $this->_alphabet = implode('', array_unique(str_split($alphabet))); if (strlen($this->_alphabet) < self::MIN_ALPHABET_LENGTH) throw new \Exception(sprintf(self::E_ALPHABET_LENGTH, self::MIN_ALPHABET_LENGTH)); if (is_int(strpos($this->_alphabet, ' '))) throw new \Exception(self::E_ALPHABET_SPACE); $alphabet_array = str_split($this->_alphabet); $seps_array = str_split($this->_seps); $this->_seps = implode('', array_intersect($alphabet_array, $seps_array)); $this->_alphabet = implode('', array_diff($alphabet_array, $seps_array)); $this->_seps = $this->_consistent_shuffle($this->_seps, $this->_salt); if (!$this->_seps || (strlen($this->_alphabet) / strlen($this->_seps)) > self::SEP_DIV) { $seps_length = (int)ceil(strlen($this->_alphabet) / self::SEP_DIV); if ($seps_length == 1) $seps_length++; if ($seps_length > strlen($this->_seps)) { $diff = $seps_length - strlen($this->_seps); $this->_seps .= substr($this->_alphabet, 0, $diff); $this->_alphabet = substr($this->_alphabet, $diff); } else $this->_seps = substr($this->_seps, 0, $seps_length); } $this->_alphabet = $this->_consistent_shuffle($this->_alphabet, $this->_salt); $guard_count = (int)ceil(strlen($this->_alphabet) / self::GUARD_DIV); if (strlen($this->_alphabet) < 3) { $this->_guards = substr($this->_seps, 0, $guard_count); $this->_seps = substr($this->_seps, $guard_count); } else { $this->_guards = substr($this->_alphabet, 0, $guard_count); $this->_alphabet = substr($this->_alphabet, $guard_count); } } function encrypt() { $ret = ''; $numbers = func_get_args(); //if argument is a multi dimensional array if ((count($numbers) == count($numbers, COUNT_RECURSIVE)) == FALSE) { // pd($numbers[0]); if (!$numbers[0]) return $ret; foreach ($numbers[0]as $number) { if (!is_int($number) || $number < 0 || $number > $this->_max_int_value) return $ret; } return $this->_encode($numbers[0]); }else{ if (!$numbers) return $ret; foreach ($numbers as $number) { if (!is_int($number) || $number < 0 || $number > $this->_max_int_value) return $ret; } return $this->_encode($numbers); } } function decrypt($hash) { $ret = array(); if (!$hash || !is_string($hash) || !trim($hash)) return $ret; return $this->_decode(trim($hash), $this->_alphabet); } function get_max_int_value() { return $this->_max_int_value; } private function _encode(array $numbers) { $alphabet = $this->_alphabet; $numbers_size = sizeof($numbers); $numbers_hash_int = 0; foreach ($numbers as $i => $number) $numbers_hash_int += ($number % ($i + 100)); $lottery = $ret = $alphabet[$numbers_hash_int % strlen($alphabet)]; foreach ($numbers as $i => $number) { $alphabet = $this->_consistent_shuffle($alphabet, substr($lottery . $this->_salt . $alphabet, 0, strlen($alphabet))); $ret .= $last = $this->_hash($number, $alphabet); if ($i + 1 < $numbers_size) { $number %= (ord($last) + $i); $seps_index = $number % strlen($this->_seps); $ret .= $this->_seps[$seps_index]; } } if (strlen($ret) < $this->_min_hash_length) { $guard_index = ($numbers_hash_int + ord($ret[0])) % strlen($this->_guards); $guard = $this->_guards[$guard_index]; $ret = $guard . $ret; if (strlen($ret) < $this->_min_hash_length) { $guard_index = ($numbers_hash_int + ord($ret[2])) % strlen($this->_guards); $guard = $this->_guards[$guard_index]; $ret .= $guard; } } $half_length = (int)(strlen($alphabet) / 2); while (strlen($ret) < $this->_min_hash_length) { $alphabet = $this->_consistent_shuffle($alphabet, $alphabet); $ret = substr($alphabet, $half_length) . $ret . substr($alphabet, 0, $half_length); $excess = strlen($ret) - $this->_min_hash_length; if ($excess > 0) $ret = substr($ret, $excess / 2, $this->_min_hash_length); } return $ret; } private function _decode($hash, $alphabet) { $ret = array(); $hash_breakdown = str_replace(str_split($this->_guards), ' ', $hash); $hash_array = explode(' ', $hash_breakdown); $i = 0; if (sizeof($hash_array) == 3 || sizeof($hash_array) == 2) $i = 1; $hash_breakdown = $hash_array[$i]; if (isset($hash_breakdown[0])) { $lottery = $hash_breakdown[0]; $hash_breakdown = substr($hash_breakdown, 1); $hash_breakdown = str_replace(str_split($this->_seps), ' ', $hash_breakdown); $hash_array = explode(' ', $hash_breakdown); foreach ($hash_array as $sub_hash) { $alphabet = $this->_consistent_shuffle($alphabet, substr($lottery . $this->_salt . $alphabet, 0, strlen($alphabet))); $ret[] = (int)$this->_unhash($sub_hash, $alphabet); } if ($this->_encode($ret) != $hash) $ret = array(); } return $ret; } private function _consistent_shuffle($alphabet, $salt) { if (!strlen($salt)) return $alphabet; for ($i = strlen($alphabet) - 1, $v = 0, $p = 0; $i > 0; $i--, $v++) { $v %= strlen($salt); $p += $int = ord($salt[$v]); $j = ($int + $v + $p) % $i; $temp = $alphabet[$j]; $alphabet[$j] = $alphabet[$i]; $alphabet[$i] = $temp; } return $alphabet; } private function _hash($input, $alphabet) { $hash = ''; $alphabet_length = strlen($alphabet); do { $hash = $alphabet[$input % $alphabet_length] . $hash; if ($input > $this->_lower_max_int_value && $this->_math_functions) $input = $this->_math_functions['str']($this->_math_functions['div']($input, $alphabet_length)); else $input = (int)($input / $alphabet_length); } while ($input); return $hash; } private function _unhash($input, $alphabet) { $number = 0; if (strlen($input) && $alphabet) { $alphabet_length = strlen($alphabet); $input_chars = str_split($input); foreach ($input_chars as $i => $char) { $pos = strpos($alphabet, $char); if ($this->_math_functions) $number = $this->_math_functions['str']($this->_math_functions['add']($number, $pos * pow($alphabet_length, (strlen($input) - $i - 1)))); else $number += $pos * pow($alphabet_length, (strlen($input) - $i - 1)); } } return $number; } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/libraries/hashids.php
PHP
mit
8,323
<?php class Page_auth { private $CI; public function __construct() { $this->CI =& get_instance(); } // redirects page to specified controller only public function secure_page($redirect_to = FALSE) { if($this->CI->session->userdata('logged_in') === TRUE) { if($this->CI->uri->segment(1) !== $this->CI->session->userdata('userType')) { redirect($this->CI->session->userdata('userType')); } }else { if($redirect_to == FALSE){ redirect('auth/login/'.$this->CI->uri->segment(1)); }else{ redirect($redirect_to); } } } public function secure_welcome_page() { if($this->CI->session->userdata('logged_in') === TRUE) { redirect($this->CI->session->userdata('userType')); } } public function secure_output_page() { if($this->CI->session->userdata('logged_in') === FALSE) { show_404(); } } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/libraries/page_auth.php
PHP
mit
872
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/application/core/index.html
HTML
mit
114
<?php class MY_Controller Extends CI_Controller { var $school_name = FALSE; var $school_address = FALSE; var $school_telephone = FALSE; var $school_email = FALSE; var $school_tag_name = FALSE; var $current_grading_period = FALSE; // returns id of current grading period var $current_school_year = FALSE; // returns id of current school year var $schoolyear_date = FALSE; // returns school year format of 0000 - 0000 var $gperiods_current; // Returns the gp_desc of current grading period var $current_ay; // Returns the gp_desc of current grading period var $disable_browser_cache = FALSE; protected $offline_status = FALSE; protected $layout_view = 'application_no_side_bar'; protected $content_view =''; protected $view_data = array(); public function __construct() { parent::__construct(); $this->_check_online_status(); $this->_set_config_items(); $this->disable_browser_cache($this->disable_browser_cache); $this->load->model(array('M_school_settings','M_gperiods','M_school_years')); $this->current_grading_period = $this->M_gperiods->get_id_of_current_gperiod(); $this->current_school_year = $this->M_school_years->get_id_of_current_sy(); $this->schoolyear_date = $this->M_school_years->get_current_sy_format(); $this->gperiods_current = $this->M_gperiods->get_current_gperiods_value('gp_desc'); $this->current_ay = $this->M_school_years->get_set_school_year(); $this->output->enable_profiler(FALSE); $id = 1; $query = $this->M_school_settings->get_all_school_setting($id); if(!empty($query)) { foreach ($query as $row) { $this->school_name = $row->school_name; $this->school_address = $row->school_address; $this->school_telephone = $row->school_telephone; $this->school_email = $row->school_email; $this->school_tag_name = $row->school_tag_name; } }else{ $this->school_name = 'Schoolname not yet set'; $this->school_address = '........................'; $this->school_telephone = '........................'; $this->school_email = '........................'; } } public function _output($output) { if($this->content_view !== FALSE && empty($this->content_view)) $this->content_view = $this->router->class . '/' . $this->router->method; $yield = file_exists(APPPATH . 'views/' . $this->content_view . EXT) ? $this->load->view($this->content_view, $this->view_data, TRUE) : FALSE ; if($this->layout_view) echo $this->load->view('layouts/' . $this->layout_view, array('yield' => $yield), TRUE); else echo $yield; echo $output; } protected function _msg($type = FALSE,$message = FALSE,$redirect = FALSE,$flashdata_name = 'system_message') { $type = strtolower($type); switch($type) { case $type == 'e': $template = "<div data-alert class='alert-box alert'><i class='icon-exclamation-sign'></i> ".htmlspecialchars(strip_tags($message))." <a href='#' class='close'>&times;</a></div>"; break; case $type == 's': $template = "<div data-alert class='alert-box success'><i class='icon-ok'></i> ".htmlspecialchars(strip_tags($message))."</div>"; break; case $type == 'n': $template = "<div class='alert-box'><i class='icon-info-sign'></i> ".htmlspecialchars(strip_tags($message))."</div>"; break; case $type == 'p': $template = $message; break; case $type == FALSE; $template = htmlspecialchars(strip_tags($message)); break; } if($type AND $message AND $redirect) { $this->session->set_flashdata($flashdata_name,$template); redirect($redirect); }elseif($type AND $message AND $redirect == FALSE){ return $template; } if($redirect == FALSE AND $message == FALSE AND $redirect == FALSE) { return $this->session->flashdata($flashdata_name); } } private function disable_browser_cache($x) { if($x == TRUE) { header("Last-Modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT"); // Date in the past header("Expires: " . gmdate( "D, j M Y H:i:s", time() ) . " GMT"); // always modified header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", FALSE); header("Pragma: no-cache"); } } protected function _set_config_items() { $sql = 'SELECT * FROM backend_settings'; $query = $this->db->query($sql); $data= $query->num_rows() >=1 ? $query->row() : FALSE; if($data !== FALSE) { $this->config->set_item('student_url', $data->student_link); } } protected function _check_online_status() { $this->load->model('M_school_settings'); $this->view_data['message'] = $check = $this->M_school_settings->check_online_status(); if($check->status == FALSE) { $this->layout_view = 'application_no_side_bar'; $this->offline_status = TRUE; if(strtolower($this->router->class) == 'offline') { }else{ redirect('offline'); } }else{ $this->offline_status = FALSE; return NULL; } } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/core/MY_Controller.php
PHP
mit
5,031
<?php class MY_Model Extends CI_Model { protected $c_user; protected $c_gp; protected $c_sy; private $ci; public function __construct() { parent::__construct(); $this->ci =& get_instance(); $this->c_user = $this->get_user(); $this->c_sy = $this->get_sy(); $this->c_gp = $this->get_gp(); } private function get_sy() { /* * id,sy_from,sy_to,is_set */ $sql = "SELECT * FROM school_years s WHERE s.is_set = 'yes' limit 1"; $query = $this->db->query($sql); return $query->num_rows() >= 1 ? $query->row() : FALSE; } private function get_gp() { /* * gp_id,gp_code,gp_desc,gp_stat */ $sql = "SELECT gp_id,gp_code,gp_desc,gp_stat FROM grading_periods g WHERE g.is_set = 'yes' limit 1"; $query = $this->db->query($sql); return $query->num_rows() >= 1 ? $query->row() : FALSE; } private function get_user() { $data['usertype'] = $this->ci->session->userdata('userType'); $data['userid'] = $this->ci->session->userdata('userid'); return (object)$data; } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/core/MY_Model.php
PHP
mit
1,087
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/application/controllers/index.html
HTML
mit
123
<?php class Offline Extends MY_Controller { public function __construct() { parent::__construct(); if($this->offline_status !== TRUE) { redirect(); } } public function index(){} }
0683babd6e120333c4dae5bac951f5cc
trunk/application/controllers/offline.php
PHP
mit
208
<?php class Inquiry Extends MY_Controller { public function __construct() { parent::__construct(); $this->load->model(array('M_levels','M_users','M_new_enrollee','M_for_enrollment_id','M_pre_applicant','M_fees','M_school_years')); $this->load->library(array('authlink','create_captcha','token')); $this->_generate_transaction(); } public function index() { $this->_check_transaction(); $this->load->helper('file');//load helper file delete_files('./captcha');// delete all images in captcha folder $captcha = $this->create_captcha->_captcha(); $this->session->set_flashdata('image_url',$captcha->link); $this->session->set_userdata('enrollment_finished',FALSE); $this->session->set_userdata('enrollment_type',NULL); $this->authlink->clear_authlink(); $this->session->set_userdata('captchaword',$captcha->word); $this->view_data['question'] = $captcha->image; $this->view_data['system_message'] = $this->_msg(); $this->view_data['token'] = $this->token->get_token(); } public function applicant() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->form_validation->set_rules('captcha_answer','','trim|htmlspecialchars'); $this->form_validation->set_rules('broommm','','trim|htmlspecialchars'); if($this->token->validate_token($this->input->post('broommm'))): $captcha_fs = $this->session->userdata('captchaword'); if(STRTOLOWER($captcha_fs) == STRTOLOWER($this->input->post('captcha_answer'))): $this->session->set_userdata('inquiry_finished',FALSE); $this->session->set_userdata('enrollment_type','Inquiry'); redirect('inquiry/applicant_data'); else: $captcha = $this->create_captcha->_captcha(); $this->token->reset(); $this->session->set_userdata('captchaword',$captcha->word); $this->_msg('e','Invalid Captcha Answer','inquiry'); endif; else: $this->_msg('e','Invalid Token','inquiry'); endif; } public function applicant_data() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->view_data['system_message'] = $this->_msg(); $this->view_data['class_error'] = NULL; $this->view_data['token'] = $this->token->get_token(); if($this->session->userdata('enrollment_type') == 'Inquiry'): if($this->session->userdata('inquiry_finished') == FALSE): $this->load->helper('misc'); $set_sy = $this->M_school_years->get_set_school_year(); $this->view_data['sy'] = $this->M_school_years->get_sy_starting($set_sy->sy_from,$set_sy->sy_to); $this->view_data['levels'] = $this->M_levels->get_all_levels_array(); $this->view_data['feedata'] = $feedata = $this->M_fees->get_assessment_fees_by_grade_level(); $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->input->post('inquire') !== FALSE): if($this->token->validate_token($this->input->post('brombrom'))): if($this->form_validation->run('for_applicant')): $d = $this->__format(strtolower($this->input->post('child_bdate'))); $hear_from = array(); if($this->input->post('billboard') == 'yes') { array_push($hear_from,'Billboard'); } if($this->input->post('signs_brochures') == 'yes') { array_push($hear_from,'Signs/Brochures'); } if($this->input->post('driving_by') == 'yes') { array_push($hear_from,'Driving By'); } if($this->input->post('friends_relatives') == 'yes') { array_push($hear_from,'Friends/Relatives'); } if($this->input->post('website') == 'yes') { array_push($hear_from,'Website'); } if($this->input->post('bluebook') == 'yes') { array_push($hear_from,'Bluebook'); } if($this->input->post('facebook') == 'yes') { array_push($hear_from,'Facebook'); } if($this->input->post('malls') == 'yes') { array_push($hear_from,'Malls'); } if($this->input->post('others') == 'yes') { array_push($hear_from,'Others'); } if($this->input->post('for_others') == 'yes') { array_push($hear_from,'Others'); array_push($hear_from,$this->input->post('for_others')); } $hear = ''; $ctr = 0; foreach($hear_from as $k=>$v) { $ctr++; $hear .= $v; if($ctr < count($hear_from)) { if($v!='Others'){ $hear .= ', '; }else{ $hear .= ': '; } } } $profile_data['firstname'] = strtolower($this->input->post('child_fname')); $profile_data['lastname'] = strtolower($this->input->post('child_lname')); $profile_data['middlename'] = strtolower($this->input->post('child_mname')); $profile_data['name_ext'] = strtolower($this->input->post('child_name_ext')); $profile_data['dob'] = $d->dob; $profile_data['age'] = $d->age; $profile_data['contact_no'] = $this->input->post('mobile_phone'); $profile_data['created'] = NOW; $school_year = $this->input->post('school_year'); $schoolyear = explode('_', $school_year); $enroll_data['e_ay_id'] = $schoolyear['0']; $enroll_data['e_sy_from'] = $schoolyear['1']; $enroll_data['e_sy_to'] = $schoolyear['2']; $enroll_data['e_enrollee_type'] = 'new'; $enroll_data['e_grade_level'] = $this->input->post('level_id'); $enroll_data['hear_from'] = $hear; $enroll_data['e_created_at'] = NOW; $enroll_data['schedule_for_testing'] = $this->input->post('child_exam').' @ '.$this->input->post('time_id'); $enroll_data['a_f_description'] = $feedata->fee_desc; $enroll_data['a_f_price'] = $feedata->fee_rate; $this->db->insert('profiles', $profile_data); if($this->db->affected_rows() >= 1) { $enroll_data['e_profile_id '] = $this->db->insert_id(); $this->db->insert('enrollments', $enroll_data); if($this->db->affected_rows() >= 1) { $message ='Your data was successfully saved. Please visit the school for payments and further instructions.'; $auth = $this->authlink->generate_authlink(); $this->_msg('s',$message,'status/success2/'.$auth); }else{ $auth = $this->authlink->generate_authlink(); $error_number = time().'-'.uniqid(rand(1000,9999)); $message ='An Error has occured. System failed to insert applicant: '.$profile_data['firstname'].'. Error Number: ('.$error_number.')'; $message2 ='An Error has occured. System failed to insert applicant: '.$profile_data['firstname'].' in the enrollment table. Error Number: ('.$error_number.')'; log_message('error',$message2); $this->_msg('e',$message,'inquiry'); } }else{ $auth = $this->authlink->generate_authlink(); $error_number = time().'-'.uniqid(rand(1000,9999)); $message ='An Error has occured. System failed to insert applicant: '.$profile_data['firstname'].'. Error Number: ('.$error_number.')'; $message2 ='An Error has occured. System failed to insert applicant: '.$profile_data['firstname'].' in the profile table. Error Number: ('.$error_number.')'; log_message('error',$message2); $this->_msg('e',$message,'inquiry'); } //if($this->M_pre_applicant->register_complete_info($profile) == TRUE) //{ //$message ='Your data was successfully saved. Please visit the school for payments and further instructions.'; //$auth = $this->authlink->generate_authlink(); //$this->_msg('s',$message,'status/success2/'.$auth); //}else{ //$auth = $this->authlink->generate_authlink(); //$error_number = time().'-'.uniqid(rand(1000,9999)); //$message ='An Error has occured. System failed to insert applicant: '.$profile['child_fname'].'. Error Number: ('.$error_number.')'; //$message2 ='An Error has occured. System failed to insert applicant: '.$profile['child_fname'].' in the pre_applicants table. Error Number: ('.$error_number.')'; //log_message('error',$message2); //$this->_msg('e',$message,'inquiry'); //} endif; else: $this->token->restart(); $this->_msg('e','Token expired or compromised.','inquiry'); endif; endif; else: redirect('inquiry'); endif; else: redirect('inquiry'); endif; } private function _check_transaction() { if($this->session->userdata('applicanttransaction') == $this->_generate_transaction()) { }else{ $this->session->sess_destroy(); redirect(); } } private function _generate_token() { $key = "aIradhznlpsVeRae7qztven9lBNwUphE"; $salt = sha1(date('d-d-d-d-d_d_d_d_d-d-d-d',time()).$key); $hash = str_pad($salt,5,'-'); return $hash; } private function _generate_transaction() { if($this->session->userdata('applicanttransaction') == FALSE) { $this->session->userdata('applicanttransaction',$this->_generate_token()); } } public function quitinquiry() { $this->session->sess_destroy(); redirect('inquiry'); } private function __format($date) { $date = DateTime::createFromFormat('m/d/Y', $date); $dob = $date->format('Y-m-d'); $birthday = strtotime($dob); $time = time(); $seconds = $time - $birthday; $age = floor($seconds / 31536000); return (object)array('dob'=>$dob,'age'=>$age); } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/controllers/inquiry.php
PHP
mit
9,859
<?php class Enrollment Extends MY_Controller { var $test_repo; var $profile_data; var $user_data; public function __construct() { parent::__construct(); $this->load->model(array('M_levels','M_users','M_new_enrollee','M_for_enrollment_id')); $this->load->library(array('authlink','create_captcha','token')); $this->_generate_transaction(); } public function index() { $this->_check_transaction(); $this->load->helper('file');//load helper file delete_files('./captcha');// delete all images in captcha folder $captcha = $this->create_captcha->_captcha(); $this->session->set_flashdata('image_url',$captcha->link); $this->session->set_userdata('enrollment_finished',FALSE); $this->session->set_userdata('enrollment_type',NULL); $this->authlink->clear_authlink(); $this->session->set_userdata('captchaword',$captcha->word); $this->view_data['question'] = $captcha->image; $this->view_data['system_message'] = $this->_msg(); $this->view_data['token'] = $this->token->get_token(); } public function enrollment_procedure() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->form_validation->set_rules('captcha_answer','','trim|htmlspecialchars'); //$this->form_validation->set_rules('option','','trim|htmlspecialchars'); $this->form_validation->set_rules('sdj','','trim|htmlspecialchars'); //check proper form input //if($this->input->post('enrollment_type') !== FALSE) //{ //check post ID //if($this->input->post('option') !== FALSE ) //{ //check form token if($this->token->validate_token($this->input->post('sdj'))) { $captcha_fs = $this->session->userdata('captchaword'); if(STRTOLOWER($captcha_fs) == STRTOLOWER($this->input->post('captcha_answer'))) { //switch($option = $this->input->post('option')) //{ //case $option == 'new': $this->session->set_userdata('enrollment_finished',FALSE); $this->session->set_userdata('enrollment_type','NEW'); redirect('new_student'); //break; //case $option == 'old': //$this->session->set_userdata('enrollment_type','OLD'); //$this->session->set_userdata('enrollment_finished',FALSE); //redirect('old'); //break; //} }else{ $captcha = $this->create_captcha->_captcha(); $this->token->reset(); $this->session->set_userdata('captchaword',$captcha->word); $this->_msg('e','Invalid Captcha Answer','new_student'); } }else{ $this->_msg('e','Invalid Token','new_student'); } //}else{ //$captcha = $this->create_captcha->_captcha(); //$this->token->reset(); //$this->session->set_userdata('captchaword',$captcha->word); //redirect('enrollment'); //} //}else{ //$captcha = $this->create_captcha->_captcha(); //$this->token->reset(); //$this->session->set_userdata('captchaword',$captcha->word); //redirect('enrollment'); //} } public function registration_form($e_id) { //$this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->view_data['system_message'] = $this->_msg(); $this->view_data['class_error'] = NULL; $this->view_data['token'] = $this->token->get_token(); $this->view_data['cannot_be_with'] = ''; $this->view_data['error_number_1'] = ''; $this->view_data['error_number_2'] = ''; $this->view_data['error_number_3'] = ''; $this->view_data['error_number_4'] = ''; $this->view_data['to_be_display_father'] = NUll; $this->view_data['to_be_display_mother'] = NUll; //if($this->session->userdata('enrollment_type') == 'NEW'): //if($this->session->userdata('enrollment_finished') == FALSE): $this->load->helper('misc'); $this->view_data['levels'] = $this->M_levels->get_all_levels_array(); $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->input->post('fillup_let_be') !== FALSE): if($this->token->validate_token($this->input->post('let_be_lefg'))): //$this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); //$this->form_validation->set_message('required', 'This field is required.'); $with_guardian = $this->input->post('living_in_ph_with_guardian'); $fatherchecked = $this->input->post('living_in_ph_with_father'); $motherchecked = $this->input->post('living_in_ph_with_mother'); $nationality = $this->input->post('child_nationality'); $father = $this->input->post('to_be_display_father'); $mother = $this->input->post('to_be_display_mother'); $fathermother = $father.'_'.$mother; $this->view_data['to_be_display_father'] = $father; $this->view_data['to_be_display_mother'] = $mother; if($fatherchecked=='yes' || $motherchecked=='yes' || $with_guardian=='yes'): $cannot_be_with = 'yes'; else: $cannot_be_with = 'no'; endif; if($with_guardian == 'yes'): $with_guardian_validation = 'enrollment_profile_2'; else: $with_guardian_validation = 'enrollment_profile'; endif; if($nationality == 'other'): $nationality_validation = 'nationality2'; else: $nationality_validation = 'nationality1'; endif; $all = 'new_'.$nationality_validation.'_'.$with_guardian_validation.'_'.$fathermother; if($this->form_validation->run($all) !== FALSE && $cannot_be_with=='yes'): $e_profile_id = $this->input->post('e_profile_id'); $profile = $this->input->post(); unset($profile['fillup_let_be']); if($this->M_users->update_complete_info($profile,$e_profile_id) == TRUE) { $level_id = $profile['level_id']; $this->load->library('idno_creator'); $generated_studentid = $this->idno_creator->generate_new_id_compressed($level_id); //$for_enrollment_table['e_profile_id'] = $profile_id= $this->M_users->get_last_insert_id(); $for_enrollment_table['e_grade_level'] = $level_id; $for_enrollment_table['e_student_id'] = $generated_studentid; //$for_enrollment_table['e_enrollee_type'] = 'new'; $for_enrollment_table['enrollment_transaction_code'] = NULL; $for_enrollment_table['mustverify'] = NULL; //insert Enrollee if($this->M_new_enrollee->update_enrolle($for_enrollment_table,$e_id) == TRUE) { //$current_id = $this->M_for_enrollment_id->get_enrollment_id(); //if(intval($profile['student_number']) == intval($current_id->for_e_id)){ //$data['for_e_id'] = intval($generated_studentid->for_e_id) + 1; //$this->M_for_enrollment_id->update_enrollment_id($data); //} $enroll_id = $e_id; //generate fees //$this->M_new_enrollee->get_fees_set_for_current_level($level_id,$enroll_id,$this->current_grading_period,$profile['e_ay_id'],'new'); //if($profile['child_nationality'] == 'other'){ //$child_nationality = strtolower($profile['child_nationality2']); //}else{ //$child_nationality = strtolower($profile['child_nationality']); //} //if($child_nationality!='filipino' && $child_nationality!='pinoy' && $child_nationality!='pinay' && $child_nationality!='pilipino' && $child_nationality!='phil-am' && $child_nationality!='fil-am'): //$this->M_new_enrollee->get_set_foreign_fee($enroll_id,$this->current_grading_period,$this->current_school_year); //endif; $auth = $this->authlink->generate_authlink(); $message ='Your data was successfully saved. Please visit the school for payments and further instructions.'; $this->_msg('s',$message,'status/success/'.$auth); }else{ $auth = $this->authlink->generate_authlink(); $error_number = time().'-'.uniqid(rand(1000,9999)); $message ='An Error has occured. System failed to insert student: '.$profile['child_fname'].'. Error Number: ('.$error_number.')'; $message2 ='An Error has occured. System failed to insert student: '.$profile['child_fname'].' in the enrollment table. Error Number: ('.$error_number.')'; log_message('error',$message2); $this->_msg('e',$message,'enrollment/registration_form/'.$e_id); } }else{ $auth = $this->authlink->generate_authlink(); $error_number = time().'-'.uniqid(rand(1000,9999)); $message ='An Error has occured. System failed to insert student: '.$profile['child_fname'].'. Error Number: ('.$error_number.')'; $message2 ='An Error has occured. System failed to insert student: '.$profile['child_fname'].' in the profile table. Error Number: ('.$error_number.')'; log_message('error',$message2); $this->_msg('e',$message,'enrollment/registration_form/'.$e_id); } else: $form_1 = array('email','level_id','child_fname','child_mname','child_lname','child_nickname','child_name_ext','gender','child_bdate','child_nationality','child_placeofbirth','child_city_address','child_telno','mobile_phone','child_religous','living_in_ph_with_father','living_in_ph_with_mother','living_in_ph_with_guardian','childs_english_reading_writing_level','childs_english_verbal_proficiency','language_at_home','participation_in_advanced_level_classes','remedial_help_in_previous_schools','special_talent_interest_dance','special_talent_interest_drama','special_talent_interest_art','special_talent_interest_acomputer','special_talent_interest_vocal_chorus','special_talent_interest_athletics','special_talent_interest_athletics_spec','special_talent_interest_band','special_talent_interest_band_spec','special_talent_interest_string','special_talent_interest_string_spec','hinder_childs_learning','leave_school','previous_school','previous_school_address','previous_grade_level','guardian_name','guardian_mname','guardian_lname','guardian_citizenship','guardian_visa','guardian_occup','guardian_office_tel','guardian_contact_no','guardian_contact_no_text','student_number','child_nationality2'); $form_2 = array('father_name','father_mname','father_lname','father_citizenship','father_visa','father_occup','father_office_tel','father_contact_no','father_contact_no_text','step_father_name','step_father_mname','step_father_lname','step_father_citizenship','step_father_visa','step_father_occup','step_father_office_tel','step_father_contact_no','step_father_contact_no_text','mother_name','mother_mname','mother_lname','mother_citizenship','mother_visa','mother_occup','mother_office_tel','mother_contact_no','mother_contact_no_text','step_mother_name','step_mother_mname','step_mother_lname','step_mother_citizenship','step_mother_visa','step_mother_occup','step_mother_office_tel','step_mother_contact_no','step_mother_contact_no_text'); $form_3 = array('allergies_reaction','drug_allergies_reaction','asthma','asthma_inhaler','eye_problem_spec','ear_problem_spec','major_ailment','recently_hospitalized','major_injury','medication_child_taking_spec','medication_child_taking_school_hours'); $form_4 = array('authfirst_aid','auth_emergency','auth_emergency_nearest_hosp','auth_oral_non_presc','first_permission','second_permission','third_permission'); $error_number_1 = $this->form_validation->error_exists($form_1); $error_number_2 = $this->form_validation->error_exists($form_2); $error_number_3 = $this->form_validation->error_exists($form_3); $error_number_4 = $this->form_validation->error_exists($form_4); if($cannot_be_with == 'no'): $this->view_data['error_number_1'] = $error_number_1+1; else: $this->view_data['error_number_1'] = $error_number_1; endif; $this->view_data['error_number_2'] = $error_number_2; $this->view_data['error_number_3'] = $error_number_3; $this->view_data['error_number_4'] = $error_number_4; $this->view_data['system_message'] = $this->_msg('e','Please fix the errors below.'); $this->view_data['cannot_be_with'] = $cannot_be_with; endif; else: $this->token->restart(); $this->_msg('e','Token expired or compromised.','new_register/'.$e_id); endif; endif; //else: // redirect('new_register'); //endif; //else: // redirect('new_register'); //endif; /* $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->view_data['system_message'] = $this->_msg(); $this->view_data['class_error'] = NULL; $this->view_data['token'] = $this->token->get_token(); $this->view_data['cannot_be_with'] = ''; if($this->session->userdata('enrollment_type') == 'NEW') { if($this->session->userdata('enrollment_finished') == FALSE) { $this->load->helper('misc'); $this->view_data['levels'] = $this->M_levels->get_all_levels_array(); $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->input->post('fillup_profile') !== FALSE) { if($this->token->validate_token($this->input->post('sdf_loc'))) { $this->form_validation->set_message('required', 'This field is required.'); $with_guardian = $this->input->post('living_in_ph_with_guardian'); $fatherchecked = $this->input->post('living_in_ph_with_father'); $motherchecked = $this->input->post('living_in_ph_with_mother'); $nationality = $this->input->post('child_nationality'); if($fatherchecked=='yes' || $motherchecked=='yes' || $with_guardian=='yes') { $cannot_be_with = 'yes'; }else{ $cannot_be_with = 'no'; } if($with_guardian == 'yes') { if($nationality == 'other'): $with_guardian_validation = 'nationality2_enrollment_profile_2'; else: $with_guardian_validation = 'enrollment_profile_2'; endif; }else{ if($nationality == 'other'): $with_guardian_validation = 'nationality2_enrollment_profile'; else: $with_guardian_validation = 'enrollment_profile'; endif; } if($this->form_validation->run($with_guardian_validation) !== FALSE && $cannot_be_with=='yes') { $profile = $this->input->post(); unset($profile['fillup_profile']); if($this->M_users->register_user($profile) == TRUE) { $level_id = $profile['level_id']; $this->load->library('idno_creator'); $generated_studentid = $this->idno_creator->generate_new_id_compressed($level_id); $for_enrollment_table['e_profile_id'] = $profile_id= $this->M_users->get_last_insert_id(); $for_enrollment_table['e_grade_level'] = $level_id; $for_enrollment_table['e_student_id'] = $generated_studentid; $for_enrollment_table['e_enrollee_type'] = 'new'; $for_enrollment_table['enrollment_transaction_code'] = NULL; $for_enrollment_table['mustverify'] = NULL; $emailer= $profile['email']; if($this->M_school_settings->check_email_verification() == TRUE) { if($this->M_users->check_my_mail($emailer,$profile_id) == TRUE) { $for_enrollment_table['verified'] = 1; } }else{ $for_enrollment_table['verified'] = 1; } //insert Enrollee if($this->M_new_enrollee->enroll_new_student($for_enrollment_table) == TRUE) { //insert student id to database for record keeping on used student id's // $this->M_new_enrollee->count_id($generated_studentid,$prof['level_id']); //$data['for_e_id'] = intval($generated_studentid->for_e_id) + 1; //$this->M_for_enrollment_id->update_enrollment_id($data); $enroll_id = $this->M_new_enrollee->get_last_input_id(); $for_enrollment_table['profile_id'] = $profile_id; $for_enrollment_table['enrollment_id'] = $enroll_id; $for_enrollment_table['child_lname'] = $profile['child_lname']; $for_enrollment_table['child_fname'] =$profile['child_fname']; $for_enrollment_table['child_mname'] =$profile['child_mname']; $for_enrollment_table['emailaddress'] =$profile['email']; //generate fees if($this->M_new_enrollee->get_fees_set_for_current_level($level_id,$enroll_id,$this->current_grading_period,$this->current_school_year,'new') !== FALSE) { $this->M_new_enrollee->get_fees_set_for_foreign($level_id,$enroll_id,$this->current_grading_period,$this->current_school_year,'new'); $this->session->set_userdata('profilesettings',$for_enrollment_table); $this->session->set_userdata('enrollmentstep',5); $this->_msg('s','Part 1 completed','pli'); } } }else{ $auth = $this->authlink->generate_authlink(); $error_number = time().'-'.uniqid(rand(1000,9999)); $message ='An Error has occured, System failed to insert student: '.$profile['child_fname'].' Error Number: ('.$error_number.')'; log_message('error',$message); $this->_msg('e',$message,'status/error/'.$auth); } }else{ $this->view_data['system_message'] = $this->_msg('e','Please fix the errors below.'); $this->view_data['cannot_be_with'] = $cannot_be_with; } }else{ $this->token->restart(); $this->_msg('e','Token expired or compromised.','register'); } } }else{ redirect('enrollment'); } }else{ redirect('enrollment'); } */ $this->view_data['applicant'] = $this->M_new_enrollee->get_applicant($e_id); $this->view_data['e_id'] = $e_id; } public function developmental_history() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->view_data['system_message'] = $this->_msg(); $this->view_data['class_error'] = NULL; $this->view_data['token'] = $this->token->get_token(); if($this->session->userdata('enrollmentstep') == 2) { $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->form_validation->run('developmental_history') !== FALSE) { $this->load->helper('misc'); $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->input->post('fillup_developmental') !== FALSE) { if($this->token->validate_token($this->input->post('spm_sdf'))) { $prof = $this->session->userdata('profilesettings'); $developmental = $this->input->post(); unset($developmental['fillup_developmental']); $this->session->set_userdata('enrollmentstep',3); $this->M_new_enrollee->add_further_profile_value($developmental,$prof['profile_id'],'dev'); $this->_msg('s','Part 2 completed','health'); }else{ $this->token->reset(); $this->_msg('e','Token expired or been compromised. Please restart again.','developmental'); } } }else{ if(validation_errors() !== '') { $this->view_data['system_message'] = $this->_msg('e','Please fix the errors below.'); } } }else{ redirect('register'); } } public function health_history() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->view_data['system_message'] = $this->_msg(); $this->view_data['class_error'] = NULL; $this->view_data['token'] = $this->token->get_token(); $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->session->userdata('enrollment_type') == 'NEW') { $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->session->userdata('enrollmentstep') == 3) { if($this->form_validation->run('healthhistory') !== FALSE) { $this->load->helper('misc'); $this->form_validation->set_error_delimiters('<span class="alert-box">', '</span>'); if($this->input->post('fillup_health') !== FALSE) { if($this->token->validate_token($this->input->post('sdj_lefg'))) { $health = $this->input->post(); $prof = $this->session->userdata('profilesettings'); $this->session->set_userdata('enrollmentstep',6); $this->M_new_enrollee->add_further_profile_value($health,$prof['profile_id'],'hlth'); $this->_msg('s','Part 3 completed','let_be'); }else{ $this->token->restart(); $this->_msg('e','Token expired or been compromised. Please restart again','health'); } } }else{ if(validation_errors() !== '') { $this->view_data['system_message'] = $this->_msg('e','Please Fix the errors Below.'); } } }else{ redirect('enrollment'); } }else{ redirect('enrollment'); } } public function enrollment_finished() { $this->_check_transaction(); if($this->session->userdata('enrollmentstep') == 4) { $prof = $this->session->userdata('profilesettings'); $developmental = $this->session->userdata('enrolldevelopmental'); $health = $this->session->userdata('enrollhealth'); $this->load->library('idno_creator'); //$generated_studentid = $this->idno_creator->generate_new_id_compressed($prof['level_id']); //$input['password'] = substr(sha1(rand(10000,99999)),4,9); //$input['e_profile_id']= $prof['profile_id']; //$input['e_enrollee_type'] = 'new' ; //$input['e_grade_level'] = $prof['level_id']; //$input['e_student_id'] = $generated_studentid; $input['enrollment_transaction_code'] = substr(base64_encode(sha1(time().rand(10,99).md5(time().rand(100,200)))),0,15); $input['mustverify'] = time() + 24*60*60; $auth = $this->authlink->generate_authlink(); $enroll_id = $prof['enrollment_id']; //$verified = $prof['verified']; //check if validate by email if($this->M_school_settings->check_email_verification() == TRUE) { //insert Enrollee //if($this->M_new_enrollee->enroll_new_student($input) == TRUE) //{ //insert student id to database for record keeping on used student id's // $this->M_new_enrollee->count_id($generated_studentid,$prof['level_id']); //$enroll_id = $this->M_new_enrollee->get_last_input_id(); //$level_id = $prof['level_id']; //generate fees //if($this->M_new_enrollee->get_fees_set_for_current_level($level_id,$enroll_id,$this->current_grading_period,$this->current_school_year) !== FALSE) //{ //if($verified == 1){ $auth = $this->authlink->generate_authlink(); $message ='Your data was successfully saved. Please visit the school for payments and further instructions.'; $this->_msg('s',$message,'status/success/'.$auth); //} //else //{ //$id = $enroll_id.'_'.rand(1000,9999); ////$c_auth = $this->authlink->hash_make($enroll_id.$id.$input['enrollment_transaction_code']); //$link = site_url('confirm/validate/'.$id.'/'.$input['enrollment_transaction_code'].'/'.$c_auth); /*$this->_email_student_confirmation_link( $prof['child_lname'], $prof['child_fname'], $prof['child_mname'], $link, $prof['emailaddress'] );*/ //$auth = $this->authlink->generate_authlink(); //$message ='<h2 class="label success">Application Form Complete.</h2><br /> Please check your email address, '.$prof['emailaddress'].', for further instructions. If you do not receive a message in your Inbox, kindly check your SPAM folder and change email permissions to allow your email to accept emails from the Westfields International School System. Thank you.'; //$this->token->destroy_token(); //$this->session->set_userdata('enrollmenttransaction',FALSE); //$this->_msg('s',$message,'status/success/'.$auth); //} //} //} }else{ //$input['verified'] = 1; //if($this->M_new_enrollee->enroll_new_student($input) == TRUE) //{ //$enroll_id = $this->M_new_enrollee->get_last_input_id(); //$level_id = $prof['level_id']; //generate fees //if($this->M_new_enrollee->get_fees_set_for_current_level($level_id,$enroll_id,$this->current_grading_period,$this->current_school_year) !== FALSE) //{ $auth = $this->authlink->generate_authlink(); $message ='Your data was successfully saved. Please visit the school for payments and further instructions.'; $this->_msg('s',$message,'status/success/'.$auth); //} //} } }else{ redirect('let_be'); } } public function parent_legal_information() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->view_data['system_message'] = $this->_msg(); $this->view_data['class_error'] = NULL; $this->view_data['token'] = $this->token->get_token(); $this->view_data['to_be_display_father'] = NUll; $this->view_data['to_be_display_mother'] = NUll; if($this->session->userdata('enrollmentstep') == 5) { if($this->input->post('fillup_parent_legal_information') !== FALSE) { if($this->token->validate_token($this->input->post('tkn_pli'))) { $father = $this->input->post('to_be_display_father'); $mother = $this->input->post('to_be_display_mother'); $fathermother = $father.'_'.$mother; $this->view_data['to_be_display_father'] = $father; $this->view_data['to_be_display_mother'] = $mother; $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->form_validation->run($fathermother) === TRUE) { $this->load->helper('misc'); $prof = $this->session->userdata('profilesettings'); $pli = $this->input->post(); $this->session->set_userdata('enrollmentstep',3); $this->M_new_enrollee->add_further_profile_value($pli,$prof['profile_id'],'pli'); $this->_msg('s','Part 2 completed','health'); }else{ if(validation_errors() !== '') { $this->view_data['system_message'] = $this->_msg('e','Please fix the errors below.'); } } }else{ $this->token->reset(); $this->_msg('e','Token expired or been compromised. Please restart again','pli'); } } }else{ redirect('register'); } } public function let_be() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->view_data['system_message'] = $this->_msg(); $this->view_data['class_error'] = NULL; $this->view_data['token'] = $this->token->get_token(); if($this->session->userdata('enrollmentstep') == 6) { $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->form_validation->run('let_be') !== FALSE) { $this->load->helper('misc'); $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->input->post('fillup_let_be') !== FALSE) { if($this->token->validate_token($this->input->post('let_be_lefg'))) { $prof = $this->session->userdata('profilesettings'); $let_be = $this->input->post(); $this->session->set_userdata('enrollmentstep',4); $this->M_new_enrollee->add_further_profile_value($let_be,$prof['profile_id'],'auth'); $this->_msg('s','Enrollment Finished','done'); }else{ $this->token->reset(); $this->_msg('e','Token expired or been compromised. Please restart again.','let_be'); } } }else{ if(validation_errors() !== '') { $this->view_data['system_message'] = $this->_msg('e','Please Fix the errors Below.'); } } }else{ redirect('register'); } } /*############################################## OLD STUDENT ENROLLEE ################################################################## */ public function old_enrollee() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->load->library('token'); $this->token->set_token(); $this->view_data['form_token'] = $this->token->get_token(); if($this->input->post('old_enrollee')) { if($this->token->validate_token($this->input->post('form_token')) == TRUE) { $this->form_validation->set_rules('idno','ID Number','required|alpha_dash_space'); if($this->form_validation->run() !== FALSE) { $this->load->model('M_old_enrollee','moe'); $the_id = trim(htmlspecialchars($this->input->post('idno'))); $result = $this->moe->check_student_id($the_id); if($result['status'] == TRUE) { $this->session->set_userdata(array('e_id'=>$result['enrollment_id'],'p_id'=>$result['profile_id'])); $hash = $this->authlink->hash_make($the_id); $auth = $this->authlink->generate_authlink(); redirect('enrollment/verify/old/'.$the_id.'/'.$auth.'/'.$hash); }else{ $this->view_data['system_message'] = $this->_msg('n',$result['log']); } } if(validation_errors() !== '') { $this->view_data['system_message'] = $this->_msg('e',validation_errors()); } }else{ $this->view_data['system_message'] = $this->_msg('e','Invalid token submit!'); } }else{ $this->view_data['system_message'] = $this->_msg('n','Old students, please enter your ID Number to enroll.'); } } public function verify($type=FALSE,$student_id=FALSE,$auth=FALSE,$hash=FALSE) { $this->_check_transaction(); $this->disable_browser_cache = TRUE; if($this->authlink->verify_authlink($auth) AND $this->authlink->check_hash_make($student_id,$hash) AND $type AND $student_id) { $this->view_data['system_message'] = $this->_msg(); $this->load->library('token'); $this->view_data['question'] = $this->quest_captcha->get_question(); $this->view_data['form_token'] = $this->token->get_token(); $this->view_data['student_id'] = $student_id; $this->view_data['auth'] = $auth; $this->view_data['hash'] = $hash; if($this->input->post('verify_old_enrollee')) { if($this->token->validate_token($this->input->post('form_token'))) { if($this->quest_captcha->check_answer($this->input->post('captcha_answer'))) { $this->form_validation->set_rules('fname','Firstname','required'); $this->form_validation->set_rules('lname','Lastname','required'); $this->form_validation->set_rules('password','Password','required'); if($this->form_validation->run() !== FALSE) { $this->load->model('M_old_enrollee','moe'); $this->load->model('M_users','mu'); $student_input['fname'] = $this->input->post('fname'); $student_input['lname'] = $this->input->post('lname'); $student_input['password'] = $this->input->post('password'); $search_student = (object)$this->moe->verify_student_credentials($student_input,$student_id); if($search_student->status == TRUE) { //insert enrollee to enrollments table and update enrollee archive status $result = $this->moe->create_old_enrollee($student_id); if($result->status == TRUE) { $e = $this->moe->return_data(); if($this->M_new_enrollee->get_fees_set_for_current_level($e->level_id,$e->id,$this->current_grading_period,$this->current_school_year)) { $this->quest_captcha->reset_question(); $this->_msg('s',$result->log,'enrollment'); }else{ $this->authlink->clear_authlink(); $this->quest_captcha->reset_question(); $this->_msg('n','You are now registered and an error occured while attempting to calculate your fees.','enrollment'); } }else{ $this->quest_captcha->reset_question(); $this->_msg('n',$result->log,'enrollment/verify/'.array_url(array($type,$student_id,$auth,$hash))); } } else{ $this->quest_captcha->reset_question(); $this->_msg('e','Credentials entered did not match any from our database.','enrollment/verify/'.array_url(array($type,$student_id,$auth,$hash))); } } }else{ $this->quest_captcha->reset_question(); $this->_msg('e','Wrong captcha answer.','enrollment/verify/'.array_url(array($type,$student_id,$auth,$hash))); } } } }else{ echo 'Not ok'; } } /*############################################## END OLD STUDENT ENROLLEE ################################################################## */ /* +----------------------------------------------------- | Misc methods used for enrollment +---------------------------------------------------- */ private function _email_student_confirmation_link($last_name,$first_name,$middle_name,$link,$email_add) { $school_name = ucwords($this->school_name); $school_name_title = $this->_accronymizer($this->school_name).'@DONOTREPLY.com'; $fullname = strtoupper($first_name.'-'.$middle_name.'-'.$last_name); $message = ""; $message .= "<span style='font-size:10px;'>Note: This message is system-generated, Please do not reply.</span>"; $message .= "<br /><br />"; $message .= "Dear {$fullname}, <br /><br />"; $message .= "Greetings from {$school_name}! <br /><br />"; //$message .= "Thank you for enrolling at {$school_name}. You just made the right choice!,\n\n"; $message .= "You have just completed the first step of the enrollment procedure. You would need to verify your enrollment to receive your personal account access.\r\n\r\n"; $message .= "<br /><br />"; $message .= "An unverified enrollment is an inactive account."; $message .= "Please take note that the verification link is only valid 30 minutes after the receipt of it.\n\n"; $message .= "<br /><br />"; $message .= "To verify your enrollment, kindly click on the link below:\n\n"; $message .= "<br /><br />"; $message .= "<a href='{$link}' target='_blank' >{$link} </a> \n"; $message .= "<br />"; //$message .= "\n\n"; //$message .= "Thank you so much and God Speed!."; $message .= "\n\n\n\n\n\n"; $message .= "<br /><br /><br /><br /><br /><br />"; //$message .= "The Management\n\n"; $message .= "{$school_name}\n\n"; $message .= "<br /><br />"; $message .= "<span style='font-size:10px;'>This email and any files transmitted with it are confidential and intended solely for the use of "; $message .= "the individual or entity to whom they are addressed. If you have received this email in error "; $message .= "please notify the system manager. This message contains confidential information and is "; $message .= "intended only for the individual named. If you are not the named addressee you should not "; $message .= "disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if "; $message .= "you have received this e-mail by mistake and delete this e-mail from your system. If you are not "; $message .= "the intended recipient you are notified that disclosing, copying, distributing or taking any action "; $message .= "in reliance on the contents of this information is strictly prohibited.</span>"; $this->load->library('email'); /*** config email **/ $this->email->initialize(array( 'mailtype' => 'html', 'crlf' => "\r\n", 'newline' => "\n" )); /*** end config email **/ $this->email->from($school_name_title,'Online Enrollment'); $this->email->to($email_add); $this->email->subject('Please Verify Your Enrollment!'); $this->email->message($message); $this->email->send(); } private function _accronymizer($string = FALSE) { if($string !== FALSE) { $clean_string = htmlspecialchars(strip_tags($string)); $number_of_words = str_word_count($clean_string,1); function acc($x) { if(strlen($x) > 1) { return $x[0]; } } $accronym = array_map("acc",$number_of_words); return strtoupper(implode('',$accronym)); }else{ return NULL; } } private function _check_transaction() { if($this->session->userdata('enrollmenttransaction') == $this->_generate_transaction()) { }else{ $this->session->sess_destroy(); redirect(); } } private function _generate_token() { $key = "aIradhznlpsVeRae7qztven9lBNwUphE"; $salt = sha1(date('d-d-d-d-d_d_d_d_d-d-d-d',time()).$key); $hash = str_pad($salt,5,'-'); return $hash; } private function _generate_transaction() { if($this->session->userdata('enrollmenttransaction') == FALSE) { $this->session->userdata('enrollmenttransaction',$this->_generate_token()); } } public function quitenrollment() { $this->session->sess_destroy(); redirect('enrollment'); } public function test_email() { $prof_child_lname = 'C'; $prof_child_fname = 'A'; $prof_child_mname = 'B'; $link = 'http://google.com/'; $prof_emailaddress = 'hay.an2ny@gmail.com'; $this->_email_student_confirmation_link( $prof_child_lname, $prof_child_fname, $prof_child_mname, $link, $prof_emailaddress ); } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/controllers/enrollment.php
PHP
mit
37,840
<?php class Register Extends MY_Controller { var $test_repo; var $profile_data; var $user_data; public function __construct() { parent::__construct(); $this->load->model(array('M_levels','M_users','M_new_enrollee','M_for_enrollment_id')); $this->load->library(array('authlink','create_captcha','token')); $this->_generate_transaction(); } public function index() { $this->_check_transaction(); $this->load->helper('file');//load helper file delete_files('./captcha');// delete all images in captcha folder $captcha = $this->create_captcha->_captcha(); $this->session->set_flashdata('image_url',$captcha->link); $this->session->set_userdata('enrollment_finished',FALSE); $this->session->set_userdata('enrollment_type',NULL); $this->authlink->clear_authlink(); $this->session->set_userdata('captchaword',$captcha->word); $this->view_data['question'] = $captcha->image; $this->view_data['system_message'] = $this->_msg(); $this->view_data['token'] = $this->token->get_token(); } public function registering() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->form_validation->set_rules('captcha_answer','','trim|htmlspecialchars'); $this->form_validation->set_rules('old_sdj','','trim|htmlspecialchars'); if($this->token->validate_token($this->input->post('old_sdj'))): $captcha_fs = $this->session->userdata('captchaword'); if(STRTOLOWER($captcha_fs) == STRTOLOWER($this->input->post('captcha_answer'))): $this->session->set_userdata('enrollment_finished',FALSE); $this->session->set_userdata('enrollment_type','OLD'); redirect('register/register_old'); else: $captcha = $this->create_captcha->_captcha(); $this->token->reset(); $this->session->set_userdata('captchaword',$captcha->word); $this->_msg('e','Invalid Captcha Answer','old_student'); endif; else: $this->_msg('e','Invalid Token','old_student'); endif; } public function register_old() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->view_data['system_message'] = $this->_msg(); $this->view_data['class_error'] = NULL; $this->view_data['token'] = $this->token->get_token(); $this->view_data['cannot_be_with'] = ''; $this->view_data['error_number_1'] = ''; $this->view_data['error_number_2'] = ''; $this->view_data['error_number_3'] = ''; $this->view_data['error_number_4'] = ''; $this->view_data['to_be_display_father'] = NUll; $this->view_data['to_be_display_mother'] = NUll; if($this->session->userdata('enrollment_type') == 'OLD'): if($this->session->userdata('enrollment_finished') == FALSE): $this->load->helper('misc'); $this->view_data['levels'] = $this->M_levels->get_all_levels_array(); $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->input->post('fillup_let_be') !== FALSE): if($this->token->validate_token($this->input->post('let_be_lefg'))): $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); //$this->form_validation->set_message('required', 'This field is required.'); $with_guardian = $this->input->post('living_in_ph_with_guardian'); $fatherchecked = $this->input->post('living_in_ph_with_father'); $motherchecked = $this->input->post('living_in_ph_with_mother'); $nationality = $this->input->post('child_nationality'); $father = $this->input->post('to_be_display_father'); $mother = $this->input->post('to_be_display_mother'); $fathermother = $father.'_'.$mother; $this->view_data['to_be_display_father'] = $father; $this->view_data['to_be_display_mother'] = $mother; if($fatherchecked=='yes' || $motherchecked=='yes' || $with_guardian=='yes'): $cannot_be_with = 'yes'; else: $cannot_be_with = 'no'; endif; if($with_guardian == 'yes'): $with_guardian_validation = 'enrollment_profile_2'; else: $with_guardian_validation = 'enrollment_profile'; endif; if($nationality == 'other'): $nationality_validation = 'nationality2'; else: $nationality_validation = 'nationality1'; endif; $all = $nationality_validation.'_'.$with_guardian_validation.'_'.$fathermother; if($this->form_validation->run($all) !== FALSE && $cannot_be_with=='yes'): $profile = $this->input->post(); unset($profile['fillup_let_be']); if($this->M_users->register_complete_info($profile) == TRUE) { $level_id = $profile['level_id']; $for_enrollment_table['e_profile_id'] = $profile_id= $this->M_users->get_last_insert_id(); $for_enrollment_table['e_grade_level'] = $level_id; $for_enrollment_table['e_student_id'] = $profile['student_number']; $for_enrollment_table['e_enrollee_type'] = 'old'; $for_enrollment_table['enrollment_transaction_code'] = NULL; $for_enrollment_table['mustverify'] = NULL; $for_enrollment_table['guidance_approved'] = 1; //insert Enrollee if($this->M_new_enrollee->enroll_new_student($for_enrollment_table) == TRUE) { $current_id = $this->M_for_enrollment_id->get_enrollment_id(); if(intval($profile['student_number']) == intval($current_id->for_e_id)){ $data['for_e_id'] = intval($generated_studentid->for_e_id) + 1; $this->M_for_enrollment_id->update_enrollment_id($data); } $enroll_id = $this->M_new_enrollee->get_last_input_id(); //generate fees $this->M_new_enrollee->get_fees_set_for_current_level($level_id,$enroll_id,$this->current_grading_period,$this->current_school_year,'old'); if($profile['child_nationality'] == 'other'){ $child_nationality = strtolower($profile['child_nationality2']); }else{ $child_nationality = strtolower($profile['child_nationality']); } if($child_nationality!='filipino' && $child_nationality!='pinoy' && $child_nationality!='pinay' && $child_nationality!='pilipino' && $child_nationality!='phil-am' && $child_nationality!='fil-am'): $this->M_new_enrollee->get_set_foreign_fee($enroll_id,$this->current_grading_period,$this->current_school_year); endif; $auth = $this->authlink->generate_authlink(); $message ='Your data was successfully saved. Please visit the school for payments and further instructions.'; $this->_msg('s',$message,'status/success/'.$auth); }else{ $auth = $this->authlink->generate_authlink(); $error_number = time().'-'.uniqid(rand(1000,9999)); $message ='An Error has occured. System failed to insert student: '.$profile['child_fname'].'. Error Number: ('.$error_number.')'; $message2 ='An Error has occured. System failed to insert student: '.$profile['child_fname'].' in the enrollment table. Error Number: ('.$error_number.')'; log_message('error',$message2); $this->_msg('e',$message,'status/error/'.$auth); } }else{ $auth = $this->authlink->generate_authlink(); $error_number = time().'-'.uniqid(rand(1000,9999)); $message ='An Error has occured. System failed to insert student: '.$profile['child_fname'].'. Error Number: ('.$error_number.')'; $message2 ='An Error has occured. System failed to insert student: '.$profile['child_fname'].' in the profile table. Error Number: ('.$error_number.')'; log_message('error',$message2); $this->_msg('e',$message,'status/error/'.$auth); } else: $form_1 = array('email','level_id','child_fname','child_mname','child_lname','child_nickname','child_name_ext','gender','child_bdate','child_nationality','child_placeofbirth','child_city_address','child_telno','mobile_phone','child_religous','living_in_ph_with_father','living_in_ph_with_mother','living_in_ph_with_guardian','childs_english_reading_writing_level','childs_english_verbal_proficiency','language_at_home','participation_in_advanced_level_classes','remedial_help_in_previous_schools','special_talent_interest_dance','special_talent_interest_drama','special_talent_interest_art','special_talent_interest_acomputer','special_talent_interest_vocal_chorus','special_talent_interest_athletics','special_talent_interest_athletics_spec','special_talent_interest_band','special_talent_interest_band_spec','special_talent_interest_string','special_talent_interest_string_spec','hinder_childs_learning','leave_school','previous_school','previous_school_address','previous_grade_level','guardian_name','guardian_mname','guardian_lname','guardian_citizenship','guardian_visa','guardian_occup','guardian_office_tel','guardian_contact_no','guardian_contact_no_text','student_number','child_nationality2'); $form_2 = array('father_name','father_mname','father_lname','father_citizenship','father_visa','father_occup','father_office_tel','father_contact_no','father_contact_no_text','step_father_name','step_father_mname','step_father_lname','step_father_citizenship','step_father_visa','step_father_occup','step_father_office_tel','step_father_contact_no','step_father_contact_no_text','mother_name','mother_mname','mother_lname','mother_citizenship','mother_visa','mother_occup','mother_office_tel','mother_contact_no','mother_contact_no_text','step_mother_name','step_mother_mname','step_mother_lname','step_mother_citizenship','step_mother_visa','step_mother_occup','step_mother_office_tel','step_mother_contact_no','step_mother_contact_no_text'); $form_3 = array('allergies_reaction','drug_allergies_reaction','asthma','asthma_inhaler','eye_problem_spec','ear_problem_spec','major_ailment','recently_hospitalized','major_injury','medication_child_taking_spec','medication_child_taking_school_hours'); $form_4 = array('authfirst_aid','auth_emergency','auth_emergency_nearest_hosp','auth_oral_non_presc','first_permission','second_permission','third_permission'); $error_number_1 = $this->form_validation->error_exists($form_1); $error_number_2 = $this->form_validation->error_exists($form_2); $error_number_3 = $this->form_validation->error_exists($form_3); $error_number_4 = $this->form_validation->error_exists($form_4); if($cannot_be_with == 'no'): $this->view_data['error_number_1'] = $error_number_1+1; else: $this->view_data['error_number_1'] = $error_number_1; endif; $this->view_data['error_number_2'] = $error_number_2; $this->view_data['error_number_3'] = $error_number_3; $this->view_data['error_number_4'] = $error_number_4; $this->view_data['system_message'] = $this->_msg('e','Please fix the errors below.'); $this->view_data['cannot_be_with'] = $cannot_be_with; endif; else: $this->token->restart(); $this->_msg('e','Token expired or compromised.','old_student'); endif; endif; else: redirect('old_student'); endif; else: redirect('old_student'); endif; } public function enrollment_procedure() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->form_validation->set_rules('captcha_answer','','trim|htmlspecialchars'); //$this->form_validation->set_rules('option','','trim|htmlspecialchars'); $this->form_validation->set_rules('sdj','','trim|htmlspecialchars'); //check proper form input //if($this->input->post('enrollment_type') !== FALSE) //{ //check post ID //if($this->input->post('option') !== FALSE ) //{ //check form token if($this->token->validate_token($this->input->post('sdj'))) { $captcha_fs = $this->session->userdata('captchaword'); if(STRTOLOWER($captcha_fs) == STRTOLOWER($this->input->post('captcha_answer'))) { //switch($option = $this->input->post('option')) //{ //case $option == 'new': $this->session->set_userdata('enrollment_finished',FALSE); $this->session->set_userdata('enrollment_type','NEW'); redirect('register'); //break; //case $option == 'old': //$this->session->set_userdata('enrollment_type','OLD'); //$this->session->set_userdata('enrollment_finished',FALSE); //redirect('old'); //break; //} }else{ $captcha = $this->create_captcha->_captcha(); $this->token->reset(); $this->session->set_userdata('captchaword',$captcha->word); $this->_msg('e','Invalid Captcha Answer','enrollment'); } }else{ $this->_msg('e','Invalid Token','enrollment'); } //}else{ //$captcha = $this->create_captcha->_captcha(); //$this->token->reset(); //$this->session->set_userdata('captchaword',$captcha->word); //redirect('enrollment'); //} //}else{ //$captcha = $this->create_captcha->_captcha(); //$this->token->reset(); //$this->session->set_userdata('captchaword',$captcha->word); //redirect('enrollment'); //} } public function registration_form() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->view_data['system_message'] = $this->_msg(); $this->view_data['class_error'] = NULL; $this->view_data['token'] = $this->token->get_token(); $this->view_data['cannot_be_with'] = ''; if($this->session->userdata('enrollment_type') == 'NEW') { if($this->session->userdata('enrollment_finished') == FALSE) { $this->load->helper('misc'); $this->view_data['levels'] = $this->M_levels->get_all_levels_array(); $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->input->post('fillup_profile') !== FALSE) { if($this->token->validate_token($this->input->post('sdf_loc'))) { $this->form_validation->set_message('required', 'This field is required.'); $with_guardian = $this->input->post('living_in_ph_with_guardian'); $fatherchecked = $this->input->post('living_in_ph_with_father'); $motherchecked = $this->input->post('living_in_ph_with_mother'); if($fatherchecked=='yes' || $motherchecked=='yes' || $with_guardian=='yes') { $cannot_be_with = 'yes'; }else{ $cannot_be_with = 'no'; } if($with_guardian == 'yes') { $with_guardian_validation = 'enrollment_profile_2'; }else{ $with_guardian_validation = 'enrollment_profile'; } if($this->form_validation->run($with_guardian_validation) !== FALSE && $cannot_be_with=='yes') { $profile = $this->input->post(); unset($profile['fillup_profile']); if($this->M_users->register_user($profile) == TRUE) { $level_id = $profile['level_id']; //$this->load->library('idno_creator'); //$generated_studentid = $this->idno_creator->generate_new_id_compressed($level_id); $for_enrollment_table['e_profile_id'] = $profile_id= $this->M_users->get_last_insert_id(); $for_enrollment_table['e_grade_level'] = $level_id; $for_enrollment_table['e_student_id'] = $generated_studentid = $this->M_for_enrollment_id->get_enrollment_id(); $for_enrollment_table['e_enrollee_type'] = 'new'; $for_enrollment_table['enrollment_transaction_code'] = NULL; $for_enrollment_table['mustverify'] = NULL; $emailer= $profile['email']; if($this->M_school_settings->check_email_verification() == TRUE) { if($this->M_users->check_my_mail($emailer,$profile_id) == TRUE) { $for_enrollment_table['verified'] = 1; } }else{ $for_enrollment_table['verified'] = 1; } //insert Enrollee if($this->M_new_enrollee->enroll_new_student($for_enrollment_table) == TRUE) { //insert student id to database for record keeping on used student id's // $this->M_new_enrollee->count_id($generated_studentid,$prof['level_id']); $data['for_e_id'] = intval($generated_studentid->for_e_id) + 1; $this->M_for_enrollment_id->update_enrollment_id($data); $enroll_id = $this->M_new_enrollee->get_last_input_id(); $for_enrollment_table['profile_id'] = $profile_id; $for_enrollment_table['enrollment_id'] = $enroll_id; $for_enrollment_table['child_lname'] = $profile['child_lname']; $for_enrollment_table['child_fname'] =$profile['child_fname']; $for_enrollment_table['child_mname'] =$profile['child_mname']; $for_enrollment_table['emailaddress'] =$profile['email']; //generate fees if($this->M_new_enrollee->get_fees_set_for_current_level($level_id,$enroll_id,$this->current_grading_period,$this->current_school_year) !== FALSE) { $this->session->set_userdata('profilesettings',$for_enrollment_table); $this->session->set_userdata('enrollmentstep',5); $this->_msg('s','Part 1 completed','pli'); } } }else{ $auth = $this->authlink->generate_authlink(); $error_number = time().'-'.uniqid(rand(1000,9999)); $message ='An Error has occured, System failed to insert student: '.$profile['child_fname'].' Error Number: ('.$error_number.')'; log_message('error',$message); $this->_msg('e',$message,'status/error/'.$auth); } }else{ $this->view_data['system_message'] = $this->_msg('e','Please fix the errors below.'); $this->view_data['cannot_be_with'] = $cannot_be_with; } }else{ $this->token->restart(); $this->_msg('e','Token expired or compromised.','register'); } } }else{ redirect('enrollment'); } }else{ redirect('enrollment'); } } public function developmental_history() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->view_data['system_message'] = $this->_msg(); $this->view_data['class_error'] = NULL; $this->view_data['token'] = $this->token->get_token(); if($this->session->userdata('enrollmentstep') == 2) { $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->form_validation->run('developmental_history') !== FALSE) { $this->load->helper('misc'); $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->input->post('fillup_developmental') !== FALSE) { if($this->token->validate_token($this->input->post('spm_sdf'))) { $prof = $this->session->userdata('profilesettings'); $developmental = $this->input->post(); unset($developmental['fillup_developmental']); $this->session->set_userdata('enrollmentstep',3); $this->M_new_enrollee->add_further_profile_value($developmental,$prof['profile_id'],'dev'); $this->_msg('s','Part 2 completed','health'); }else{ $this->token->reset(); $this->_msg('e','Token expired or been compromised. Please restart again.','developmental'); } } }else{ if(validation_errors() !== '') { $this->view_data['system_message'] = $this->_msg('e','Please fix the errors below.'); } } }else{ redirect('register'); } } public function health_history() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->view_data['system_message'] = $this->_msg(); $this->view_data['class_error'] = NULL; $this->view_data['token'] = $this->token->get_token(); $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->session->userdata('enrollment_type') == 'NEW') { $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->session->userdata('enrollmentstep') == 3) { if($this->form_validation->run('healthhistory') !== FALSE) { $this->load->helper('misc'); $this->form_validation->set_error_delimiters('<span class="alert-box">', '</span>'); if($this->input->post('fillup_health') !== FALSE) { if($this->token->validate_token($this->input->post('sdj_lefg'))) { $health = $this->input->post(); $prof = $this->session->userdata('profilesettings'); $this->session->set_userdata('enrollmentstep',6); $this->M_new_enrollee->add_further_profile_value($health,$prof['profile_id'],'hlth'); $this->_msg('s','Part 3 completed','let_be'); }else{ $this->token->restart(); $this->_msg('e','Token expired or been compromised. Please restart again','health'); } } }else{ if(validation_errors() !== '') { $this->view_data['system_message'] = $this->_msg('e','Please Fix the errors Below.'); } } }else{ redirect('enrollment'); } }else{ redirect('enrollment'); } } public function enrollment_finished() { $this->_check_transaction(); if($this->session->userdata('enrollmentstep') == 4) { $prof = $this->session->userdata('profilesettings'); $developmental = $this->session->userdata('enrolldevelopmental'); $health = $this->session->userdata('enrollhealth'); $this->load->library('idno_creator'); //$generated_studentid = $this->idno_creator->generate_new_id_compressed($prof['level_id']); //$input['password'] = substr(sha1(rand(10000,99999)),4,9); //$input['e_profile_id']= $prof['profile_id']; //$input['e_enrollee_type'] = 'new' ; //$input['e_grade_level'] = $prof['level_id']; //$input['e_student_id'] = $generated_studentid; $input['enrollment_transaction_code'] = substr(base64_encode(sha1(time().rand(10,99).md5(time().rand(100,200)))),0,15); $input['mustverify'] = time() + 24*60*60; $auth = $this->authlink->generate_authlink(); $enroll_id = $prof['enrollment_id']; $verified = $prof['verified']; //check if validate by email if($this->M_school_settings->check_email_verification() == TRUE) { //insert Enrollee //if($this->M_new_enrollee->enroll_new_student($input) == TRUE) //{ //insert student id to database for record keeping on used student id's // $this->M_new_enrollee->count_id($generated_studentid,$prof['level_id']); //$enroll_id = $this->M_new_enrollee->get_last_input_id(); //$level_id = $prof['level_id']; //generate fees //if($this->M_new_enrollee->get_fees_set_for_current_level($level_id,$enroll_id,$this->current_grading_period,$this->current_school_year) !== FALSE) //{ if($verified == 1){ $auth = $this->authlink->generate_authlink(); $message ='Your data was successfully saved. Please visit the school for payments and further instructions.'; $this->_msg('s',$message,'status/success/'.$auth); } else { $id = $enroll_id.'_'.rand(1000,9999); $c_auth = $this->authlink->hash_make($enroll_id.$id.$input['enrollment_transaction_code']); $link = site_url('confirm/validate/'.$id.'/'.$input['enrollment_transaction_code'].'/'.$c_auth); /*$this->_email_student_confirmation_link( $prof['child_lname'], $prof['child_fname'], $prof['child_mname'], $link, $prof['emailaddress'] );*/ $auth = $this->authlink->generate_authlink(); $message ='<h2 class="label success">Application Form Complete.</h2><br /> Please check your email address, '.$prof['emailaddress'].', for further instructions. If you do not receive a message in your Inbox, kindly check your SPAM folder and change email permissions to allow your email to accept emails from the Westfields International School System. Thank you.'; $this->token->destroy_token(); $this->session->set_userdata('enrollmenttransaction',FALSE); $this->_msg('s',$message,'status/success/'.$auth); } //} //} }else{ //$input['verified'] = 1; //if($this->M_new_enrollee->enroll_new_student($input) == TRUE) //{ //$enroll_id = $this->M_new_enrollee->get_last_input_id(); //$level_id = $prof['level_id']; //generate fees //if($this->M_new_enrollee->get_fees_set_for_current_level($level_id,$enroll_id,$this->current_grading_period,$this->current_school_year) !== FALSE) //{ $auth = $this->authlink->generate_authlink(); $message ='Your data was successfully saved. Please visit the school for payments and further instructions.'; $this->_msg('s',$message,'status/success/'.$auth); //} //} } }else{ redirect('let_be'); } } public function parent_legal_information() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->view_data['system_message'] = $this->_msg(); $this->view_data['class_error'] = NULL; $this->view_data['token'] = $this->token->get_token(); $this->view_data['to_be_display_father'] = NUll; $this->view_data['to_be_display_mother'] = NUll; if($this->session->userdata('enrollmentstep') == 5) { if($this->input->post('fillup_parent_legal_information') !== FALSE) { if($this->token->validate_token($this->input->post('tkn_pli'))) { $father = $this->input->post('to_be_display_father'); $mother = $this->input->post('to_be_display_mother'); $fathermother = $father.'_'.$mother; $this->view_data['to_be_display_father'] = $father; $this->view_data['to_be_display_mother'] = $mother; $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->form_validation->run($fathermother) === TRUE) { $this->load->helper('misc'); $prof = $this->session->userdata('profilesettings'); $pli = $this->input->post(); $this->session->set_userdata('enrollmentstep',3); $this->M_new_enrollee->add_further_profile_value($pli,$prof['profile_id'],'pli'); $this->_msg('s','Part 2 completed','health'); }else{ if(validation_errors() !== '') { $this->view_data['system_message'] = $this->_msg('e','Please fix the errors below.'); } } }else{ $this->token->reset(); $this->_msg('e','Token expired or been compromised. Please restart again','pli'); } } }else{ redirect('register'); } } public function let_be() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->view_data['system_message'] = $this->_msg(); $this->view_data['class_error'] = NULL; $this->view_data['token'] = $this->token->get_token(); if($this->session->userdata('enrollmentstep') == 6) { $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->form_validation->run('let_be') !== FALSE) { $this->load->helper('misc'); $this->form_validation->set_error_delimiters('<span class="error_simple">', '</span>'); if($this->input->post('fillup_let_be') !== FALSE) { if($this->token->validate_token($this->input->post('let_be_lefg'))) { $prof = $this->session->userdata('profilesettings'); $let_be = $this->input->post(); $this->session->set_userdata('enrollmentstep',4); $this->M_new_enrollee->add_further_profile_value($let_be,$prof['profile_id'],'auth'); $this->_msg('s','Enrollment Finished','done'); }else{ $this->token->reset(); $this->_msg('e','Token expired or been compromised. Please restart again.','let_be'); } } }else{ if(validation_errors() !== '') { $this->view_data['system_message'] = $this->_msg('e','Please Fix the errors Below.'); } } }else{ redirect('register'); } } /*############################################## OLD STUDENT ENROLLEE ################################################################## */ public function old_enrollee() { $this->_check_transaction(); $this->disable_browser_cache = TRUE; $this->load->library('token'); $this->token->set_token(); $this->view_data['form_token'] = $this->token->get_token(); if($this->input->post('old_enrollee')) { if($this->token->validate_token($this->input->post('form_token')) == TRUE) { $this->form_validation->set_rules('idno','ID Number','required|alpha_dash_space'); if($this->form_validation->run() !== FALSE) { $this->load->model('M_old_enrollee','moe'); $the_id = trim(htmlspecialchars($this->input->post('idno'))); $result = $this->moe->check_student_id($the_id); if($result['status'] == TRUE) { $this->session->set_userdata(array('e_id'=>$result['enrollment_id'],'p_id'=>$result['profile_id'])); $hash = $this->authlink->hash_make($the_id); $auth = $this->authlink->generate_authlink(); redirect('enrollment/verify/old/'.$the_id.'/'.$auth.'/'.$hash); }else{ $this->view_data['system_message'] = $this->_msg('n',$result['log']); } } if(validation_errors() !== '') { $this->view_data['system_message'] = $this->_msg('e',validation_errors()); } }else{ $this->view_data['system_message'] = $this->_msg('e','Invalid token submit!'); } }else{ $this->view_data['system_message'] = $this->_msg('n','Old students, please enter your ID Number to enroll.'); } } public function verify($type=FALSE,$student_id=FALSE,$auth=FALSE,$hash=FALSE) { $this->_check_transaction(); $this->disable_browser_cache = TRUE; if($this->authlink->verify_authlink($auth) AND $this->authlink->check_hash_make($student_id,$hash) AND $type AND $student_id) { $this->view_data['system_message'] = $this->_msg(); $this->load->library('token'); $this->view_data['question'] = $this->quest_captcha->get_question(); $this->view_data['form_token'] = $this->token->get_token(); $this->view_data['student_id'] = $student_id; $this->view_data['auth'] = $auth; $this->view_data['hash'] = $hash; if($this->input->post('verify_old_enrollee')) { if($this->token->validate_token($this->input->post('form_token'))) { if($this->quest_captcha->check_answer($this->input->post('captcha_answer'))) { $this->form_validation->set_rules('fname','Firstname','required'); $this->form_validation->set_rules('lname','Lastname','required'); $this->form_validation->set_rules('password','Password','required'); if($this->form_validation->run() !== FALSE) { $this->load->model('M_old_enrollee','moe'); $this->load->model('M_users','mu'); $student_input['fname'] = $this->input->post('fname'); $student_input['lname'] = $this->input->post('lname'); $student_input['password'] = $this->input->post('password'); $search_student = (object)$this->moe->verify_student_credentials($student_input,$student_id); if($search_student->status == TRUE) { //insert enrollee to enrollments table and update enrollee archive status $result = $this->moe->create_old_enrollee($student_id); if($result->status == TRUE) { $e = $this->moe->return_data(); if($this->M_new_enrollee->get_fees_set_for_current_level($e->level_id,$e->id,$this->current_grading_period,$this->current_school_year)) { $this->quest_captcha->reset_question(); $this->_msg('s',$result->log,'enrollment'); }else{ $this->authlink->clear_authlink(); $this->quest_captcha->reset_question(); $this->_msg('n','You are now registered and an error occured while attempting to calculate your fees.','enrollment'); } }else{ $this->quest_captcha->reset_question(); $this->_msg('n',$result->log,'enrollment/verify/'.array_url(array($type,$student_id,$auth,$hash))); } } else{ $this->quest_captcha->reset_question(); $this->_msg('e','Credentials entered did not match any from our database.','enrollment/verify/'.array_url(array($type,$student_id,$auth,$hash))); } } }else{ $this->quest_captcha->reset_question(); $this->_msg('e','Wrong captcha answer.','enrollment/verify/'.array_url(array($type,$student_id,$auth,$hash))); } } } }else{ echo 'Not ok'; } } /*############################################## END OLD STUDENT ENROLLEE ################################################################## */ /* +----------------------------------------------------- | Misc methods used for enrollment +---------------------------------------------------- */ private function _email_student_confirmation_link($last_name,$first_name,$middle_name,$link,$email_add) { $school_name = ucwords($this->school_name); $school_name_title = $this->_accronymizer($this->school_name).'@DONOTREPLY.com'; $fullname = strtoupper($first_name.'-'.$middle_name.'-'.$last_name); $message = ""; $message .= "<span style='font-size:10px;'>Note: This message is system-generated, Please do not reply.</span>"; $message .= "<br /><br />"; $message .= "Dear {$fullname}, <br /><br />"; $message .= "Greetings from {$school_name}! <br /><br />"; //$message .= "Thank you for enrolling at {$school_name}. You just made the right choice!,\n\n"; $message .= "You have just completed the first step of the enrollment procedure. You would need to verify your enrollment to receive your personal account access.\r\n\r\n"; $message .= "<br /><br />"; $message .= "An unverified enrollment is an inactive account."; $message .= "Please take note that the verification link is only valid 30 minutes after the receipt of it.\n\n"; $message .= "<br /><br />"; $message .= "To verify your enrollment, kindly click on the link below:\n\n"; $message .= "<br /><br />"; $message .= "<a href='{$link}' target='_blank' >{$link} </a> \n"; $message .= "<br />"; //$message .= "\n\n"; //$message .= "Thank you so much and God Speed!."; $message .= "\n\n\n\n\n\n"; $message .= "<br /><br /><br /><br /><br /><br />"; //$message .= "The Management\n\n"; $message .= "{$school_name}\n\n"; $message .= "<br /><br />"; $message .= "<span style='font-size:10px;'>This email and any files transmitted with it are confidential and intended solely for the use of "; $message .= "the individual or entity to whom they are addressed. If you have received this email in error "; $message .= "please notify the system manager. This message contains confidential information and is "; $message .= "intended only for the individual named. If you are not the named addressee you should not "; $message .= "disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if "; $message .= "you have received this e-mail by mistake and delete this e-mail from your system. If you are not "; $message .= "the intended recipient you are notified that disclosing, copying, distributing or taking any action "; $message .= "in reliance on the contents of this information is strictly prohibited.</span>"; $this->load->library('email'); /*** config email **/ $this->email->initialize(array( 'mailtype' => 'html', 'crlf' => "\r\n", 'newline' => "\n" )); /*** end config email **/ $this->email->from($school_name_title,'Online Enrollment'); $this->email->to($email_add); $this->email->subject('Please Verify Your Enrollment!'); $this->email->message($message); $this->email->send(); } private function _accronymizer($string = FALSE) { if($string !== FALSE) { $clean_string = htmlspecialchars(strip_tags($string)); $number_of_words = str_word_count($clean_string,1); function acc($x) { if(strlen($x) > 1) { return $x[0]; } } $accronym = array_map("acc",$number_of_words); return strtoupper(implode('',$accronym)); }else{ return NULL; } } private function _check_transaction() { if($this->session->userdata('enrollmenttransaction') == $this->_generate_transaction()) { }else{ $this->session->sess_destroy(); redirect(); } } private function _generate_token() { $key = "aIradhznlpsVeRae7qztven9lBNwUphE"; $salt = sha1(date('d-d-d-d-d_d_d_d_d-d-d-d',time()).$key); $hash = str_pad($salt,5,'-'); return $hash; } private function _generate_transaction() { if($this->session->userdata('enrollmenttransaction') == FALSE) { $this->session->userdata('enrollmenttransaction',$this->_generate_token()); } } public function quitenrollment() { $this->session->sess_destroy(); redirect('enrollment'); } public function test_email() { $prof_child_lname = 'C'; $prof_child_fname = 'A'; $prof_child_mname = 'B'; $link = 'http://google.com/'; $prof_emailaddress = 'hay.an2ny@gmail.com'; $this->_email_student_confirmation_link( $prof_child_lname, $prof_child_fname, $prof_child_mname, $link, $prof_emailaddress ); } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/controllers/register.php
PHP
mit
38,044
<?php class Status Extends MY_Controller { public function __construct() { parent::__construct(); $this->layout_view = 'application_error'; $this->load->library('authlink'); } public function index() { show_404(); } public function success($auth='') { //$this->disable_browser_cache = TRUE; //if($this->authlink->verify_authlink($auth) == TRUE && $this->session->userdata('enrollment_finished') == FALSE) //{ $this->view_data['system_message'] = $this->session->flashdata('system_message'); $this->view_data['login'] = $this->session->userdata('username'); $this->session->set_userdata('enrollment_finished',TRUE); //}else{ //redirect(); //} } public function success2($auth='') { //$this->disable_browser_cache = TRUE; //if($this->authlink->verify_authlink($auth) == TRUE && $this->session->userdata('enrollment_finished') == FALSE) //{ $this->view_data['system_message'] = $this->session->flashdata('system_message'); $this->view_data['login'] = $this->session->userdata('username'); $this->session->set_userdata('enrollment_finished',TRUE); //}else{ //redirect(); //} } public function error($auth) { $this->disable_browser_cache = TRUE; if($this->authlink->verify_authlink($auth) == TRUE && $this->session->userdata('enrollment_finished') == FALSE) { $this->view_data['system_message'] = $this->session->flashdata('system_message'); $this->view_data['login'] = $this->session->userdata('username'); $this->session->set_userdata('enrollment_finished',TRUE); }else{ redirect(); } } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/controllers/status.php
PHP
mit
1,638
<?php class Test Extends MY_Controller { public function index() { print_r($this->_accronymizer()); } private function _accronymizer($string = FALSE) { if($string !== FALSE) { $clean_string = htmlspecialchars(strip_tags($string)); $number_of_words = str_word_count($clean_string,1); function accronym($x) { if(strlen($x) > 1) { return $x[0]; } } $accronym = array_map("accronym",$number_of_words); return strtoupper(implode('',$accronym)); }else{ return NULL; } } }
0683babd6e120333c4dae5bac951f5cc
trunk/application/controllers/test.php
PHP
mit
572
<?php /* Default Timezone */ ini_set('date.timezone', 'Asia/Manila'); /* *--------------------------------------------------------------- * APPLICATION ENVIRONMENT *--------------------------------------------------------------- * * You can load different configurations depending on your * current environment. Setting the environment also influences * things like logging and error reporting. * * This can be set to anything, but default usage is: * * development * testing * production * * NOTE: If you change these, also change the error_reporting() code below * */ define('ENVIRONMENT', 'development'); /* *--------------------------------------------------------------- * ERROR REPORTING *--------------------------------------------------------------- * * Different environments will require different levels of error reporting. * By default development will show errors but testing and live will hide them. */ if (defined('ENVIRONMENT')) { switch (ENVIRONMENT) { case 'development': error_reporting(E_ALL); break; case 'testing': case 'production': error_reporting(0); break; default: exit('The application environment is not set correctly.'); } } /* *--------------------------------------------------------------- * SYSTEM FOLDER NAME *--------------------------------------------------------------- * * This variable must contain the name of your "system" folder. * Include the path if the folder is not in the same directory * as this file. * */ $system_path = 'system'; /* *--------------------------------------------------------------- * APPLICATION FOLDER NAME *--------------------------------------------------------------- * * If you want this front controller to use a different "application" * folder then the default one you can set its name here. The folder * can also be renamed or relocated anywhere on your server. If * you do, use a full server path. For more info please see the user guide: * http://codeigniter.com/user_guide/general/managing_apps.html * * NO TRAILING SLASH! * */ $application_folder = 'application'; /* * -------------------------------------------------------------------- * DEFAULT CONTROLLER * -------------------------------------------------------------------- * * Normally you will set your default controller in the routes.php file. * You can, however, force a custom routing by hard-coding a * specific controller class/function here. For most applications, you * WILL NOT set your routing here, but it's an option for those * special instances where you might want to override the standard * routing in a specific front controller that shares a common CI installation. * * IMPORTANT: If you set the routing here, NO OTHER controller will be * callable. In essence, this preference limits your application to ONE * specific controller. Leave the function name blank if you need * to call functions dynamically via the URI. * * Un-comment the $routing array below to use this feature * */ // The directory name, relative to the "controllers" folder. Leave blank // if your controller is not in a sub-folder within the "controllers" folder // $routing['directory'] = ''; // The controller class file name. Example: Mycontroller // $routing['controller'] = ''; // The controller function you wish to be called. // $routing['function'] = ''; /* * ------------------------------------------------------------------- * CUSTOM CONFIG VALUES * ------------------------------------------------------------------- * * The $assign_to_config array below will be passed dynamically to the * config class when initialized. This allows you to set custom config * items or override any default config values found in the config.php file. * This can be handy as it permits you to share one application between * multiple front controller files, with each file containing different * config values. * * Un-comment the $assign_to_config array below to use this feature * */ // $assign_to_config['name_of_config_item'] = 'value of config item'; // -------------------------------------------------------------------- // END OF USER CONFIGURABLE SETTINGS. DO NOT EDIT BELOW THIS LINE // -------------------------------------------------------------------- /* * --------------------------------------------------------------- * Resolve the system path for increased reliability * --------------------------------------------------------------- */ // Set the current directory correctly for CLI requests if (defined('STDIN')) { chdir(dirname(__FILE__)); } if (realpath($system_path) !== FALSE) { $system_path = realpath($system_path).'/'; } // ensure there's a trailing slash $system_path = rtrim($system_path, '/').'/'; // Is the system path correct? if ( ! is_dir($system_path)) { exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME)); } /* * ------------------------------------------------------------------- * Now that we know the path, set the main path constants * ------------------------------------------------------------------- */ // The name of THIS file define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); // The PHP file extension // this global constant is deprecated. define('EXT', '.php'); // Path to the system folder define('BASEPATH', str_replace("\\", "/", $system_path)); // Path to the front controller (this file) define('FCPATH', str_replace(SELF, '', __FILE__)); // Name of the "system folder" define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/')); // The path to the "application" folder if (is_dir($application_folder)) { define('APPPATH', $application_folder.'/'); } else { if ( ! is_dir(BASEPATH.$application_folder.'/')) { exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF); } define('APPPATH', BASEPATH.$application_folder.'/'); } /* * -------------------------------------------------------------------- * LOAD THE BOOTSTRAP FILE * -------------------------------------------------------------------- * * And away we go... * */ require_once BASEPATH.'core/CodeIgniter.php'; /* End of file index.php */ /* Location: ./index.php */
0683babd6e120333c4dae5bac951f5cc
trunk/index.php
PHP
mit
6,422
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/system/index.html
HTML
mit
114
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/system/language/index.html
HTML
mit
114
<?php $lang['date_year'] = "Year"; $lang['date_years'] = "Years"; $lang['date_month'] = "Month"; $lang['date_months'] = "Months"; $lang['date_week'] = "Week"; $lang['date_weeks'] = "Weeks"; $lang['date_day'] = "Day"; $lang['date_days'] = "Days"; $lang['date_hour'] = "Hour"; $lang['date_hours'] = "Hours"; $lang['date_minute'] = "Minute"; $lang['date_minutes'] = "Minutes"; $lang['date_second'] = "Second"; $lang['date_seconds'] = "Seconds"; $lang['UM12'] = '(UTC -12:00) Baker/Howland Island'; $lang['UM11'] = '(UTC -11:00) Samoa Time Zone, Niue'; $lang['UM10'] = '(UTC -10:00) Hawaii-Aleutian Standard Time, Cook Islands, Tahiti'; $lang['UM95'] = '(UTC -9:30) Marquesas Islands'; $lang['UM9'] = '(UTC -9:00) Alaska Standard Time, Gambier Islands'; $lang['UM8'] = '(UTC -8:00) Pacific Standard Time, Clipperton Island'; $lang['UM7'] = '(UTC -7:00) Mountain Standard Time'; $lang['UM6'] = '(UTC -6:00) Central Standard Time'; $lang['UM5'] = '(UTC -5:00) Eastern Standard Time, Western Caribbean Standard Time'; $lang['UM45'] = '(UTC -4:30) Venezuelan Standard Time'; $lang['UM4'] = '(UTC -4:00) Atlantic Standard Time, Eastern Caribbean Standard Time'; $lang['UM35'] = '(UTC -3:30) Newfoundland Standard Time'; $lang['UM3'] = '(UTC -3:00) Argentina, Brazil, French Guiana, Uruguay'; $lang['UM2'] = '(UTC -2:00) South Georgia/South Sandwich Islands'; $lang['UM1'] = '(UTC -1:00) Azores, Cape Verde Islands'; $lang['UTC'] = '(UTC) Greenwich Mean Time, Western European Time'; $lang['UP1'] = '(UTC +1:00) Central European Time, West Africa Time'; $lang['UP2'] = '(UTC +2:00) Central Africa Time, Eastern European Time, Kaliningrad Time'; $lang['UP3'] = '(UTC +3:00) Moscow Time, East Africa Time'; $lang['UP35'] = '(UTC +3:30) Iran Standard Time'; $lang['UP4'] = '(UTC +4:00) Azerbaijan Standard Time, Samara Time'; $lang['UP45'] = '(UTC +4:30) Afghanistan'; $lang['UP5'] = '(UTC +5:00) Pakistan Standard Time, Yekaterinburg Time'; $lang['UP55'] = '(UTC +5:30) Indian Standard Time, Sri Lanka Time'; $lang['UP575'] = '(UTC +5:45) Nepal Time'; $lang['UP6'] = '(UTC +6:00) Bangladesh Standard Time, Bhutan Time, Omsk Time'; $lang['UP65'] = '(UTC +6:30) Cocos Islands, Myanmar'; $lang['UP7'] = '(UTC +7:00) Krasnoyarsk Time, Cambodia, Laos, Thailand, Vietnam'; $lang['UP8'] = '(UTC +8:00) Australian Western Standard Time, Beijing Time, Irkutsk Time'; $lang['UP875'] = '(UTC +8:45) Australian Central Western Standard Time'; $lang['UP9'] = '(UTC +9:00) Japan Standard Time, Korea Standard Time, Yakutsk Time'; $lang['UP95'] = '(UTC +9:30) Australian Central Standard Time'; $lang['UP10'] = '(UTC +10:00) Australian Eastern Standard Time, Vladivostok Time'; $lang['UP105'] = '(UTC +10:30) Lord Howe Island'; $lang['UP11'] = '(UTC +11:00) Magadan Time, Solomon Islands, Vanuatu'; $lang['UP115'] = '(UTC +11:30) Norfolk Island'; $lang['UP12'] = '(UTC +12:00) Fiji, Gilbert Islands, Kamchatka Time, New Zealand Standard Time'; $lang['UP1275'] = '(UTC +12:45) Chatham Islands Standard Time'; $lang['UP13'] = '(UTC +13:00) Phoenix Islands Time, Tonga'; $lang['UP14'] = '(UTC +14:00) Line Islands'; /* End of file date_lang.php */ /* Location: ./system/language/english/date_lang.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/language/english/date_lang.php
PHP
mit
3,177
<?php $lang['terabyte_abbr'] = "TB"; $lang['gigabyte_abbr'] = "GB"; $lang['megabyte_abbr'] = "MB"; $lang['kilobyte_abbr'] = "KB"; $lang['bytes'] = "Bytes"; /* End of file number_lang.php */ /* Location: ./system/language/english/number_lang.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/language/english/number_lang.php
PHP
mit
249
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/system/language/english/index.html
HTML
mit
114
<?php $lang['email_must_be_array'] = "The email validation method must be passed an array."; $lang['email_invalid_address'] = "Invalid email address: %s"; $lang['email_attachment_missing'] = "Unable to locate the following email attachment: %s"; $lang['email_attachment_unreadable'] = "Unable to open this attachment: %s"; $lang['email_no_recipients'] = "You must include recipients: To, Cc, or Bcc"; $lang['email_send_failure_phpmail'] = "Unable to send email using PHP mail(). Your server might not be configured to send mail using this method."; $lang['email_send_failure_sendmail'] = "Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method."; $lang['email_send_failure_smtp'] = "Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method."; $lang['email_sent'] = "Your message has been successfully sent using the following protocol: %s"; $lang['email_no_socket'] = "Unable to open a socket to Sendmail. Please check settings."; $lang['email_no_hostname'] = "You did not specify a SMTP hostname."; $lang['email_smtp_error'] = "The following SMTP error was encountered: %s"; $lang['email_no_smtp_unpw'] = "Error: You must assign a SMTP username and password."; $lang['email_failed_smtp_login'] = "Failed to send AUTH LOGIN command. Error: %s"; $lang['email_smtp_auth_un'] = "Failed to authenticate username. Error: %s"; $lang['email_smtp_auth_pw'] = "Failed to authenticate password. Error: %s"; $lang['email_smtp_data_failure'] = "Unable to send data: %s"; $lang['email_exit_status'] = "Exit status code: %s"; /* End of file email_lang.php */ /* Location: ./system/language/english/email_lang.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/language/english/email_lang.php
PHP
mit
1,707
<?php $lang['required'] = "The %s field is required."; $lang['isset'] = "The %s field must have a value."; $lang['valid_email'] = "The %s field must contain a valid email address."; $lang['valid_emails'] = "The %s field must contain all valid email addresses."; $lang['valid_url'] = "The %s field must contain a valid URL."; $lang['valid_ip'] = "The %s field must contain a valid IP."; $lang['min_length'] = "The %s field must be at least %s characters in length."; $lang['max_length'] = "The %s field can not exceed %s characters in length."; $lang['exact_length'] = "The %s field must be exactly %s characters in length."; $lang['alpha'] = "The %s field may only contain alphabetical characters."; $lang['alpha_numeric'] = "The %s field may only contain alpha-numeric characters."; $lang['alpha_dash'] = "The %s field may only contain alpha-numeric characters, underscores, and dashes."; $lang['numeric'] = "The %s field must contain only numbers."; $lang['is_numeric'] = "The %s field must contain only numeric characters."; $lang['integer'] = "The %s field must contain an integer."; $lang['regex_match'] = "The %s field is not in the correct format."; $lang['matches'] = "The %s field does not match the %s field."; $lang['is_unique'] = "The %s field must contain a unique value."; $lang['is_natural'] = "The %s field must contain only positive numbers."; $lang['is_natural_no_zero'] = "The %s field must contain a number greater than zero."; $lang['decimal'] = "The %s field must contain a decimal number."; $lang['less_than'] = "The %s field must contain a number less than %s."; $lang['greater_than'] = "The %s field must contain a number greater than %s."; /* End of file form_validation_lang.php */ /* Location: ./system/language/english/form_validation_lang.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/language/english/form_validation_lang.php
PHP
mit
1,819
<?php $lang['imglib_source_image_required'] = "You must specify a source image in your preferences."; $lang['imglib_gd_required'] = "The GD image library is required for this feature."; $lang['imglib_gd_required_for_props'] = "Your server must support the GD image library in order to determine the image properties."; $lang['imglib_unsupported_imagecreate'] = "Your server does not support the GD function required to process this type of image."; $lang['imglib_gif_not_supported'] = "GIF images are often not supported due to licensing restrictions. You may have to use JPG or PNG images instead."; $lang['imglib_jpg_not_supported'] = "JPG images are not supported."; $lang['imglib_png_not_supported'] = "PNG images are not supported."; $lang['imglib_jpg_or_png_required'] = "The image resize protocol specified in your preferences only works with JPEG or PNG image types."; $lang['imglib_copy_error'] = "An error was encountered while attempting to replace the file. Please make sure your file directory is writable."; $lang['imglib_rotate_unsupported'] = "Image rotation does not appear to be supported by your server."; $lang['imglib_libpath_invalid'] = "The path to your image library is not correct. Please set the correct path in your image preferences."; $lang['imglib_image_process_failed'] = "Image processing failed. Please verify that your server supports the chosen protocol and that the path to your image library is correct."; $lang['imglib_rotation_angle_required'] = "An angle of rotation is required to rotate the image."; $lang['imglib_writing_failed_gif'] = "GIF image."; $lang['imglib_invalid_path'] = "The path to the image is not correct."; $lang['imglib_copy_failed'] = "The image copy routine failed."; $lang['imglib_missing_font'] = "Unable to find a font to use."; $lang['imglib_save_failed'] = "Unable to save the image. Please make sure the image and file directory are writable."; /* End of file imglib_lang.php */ /* Location: ./system/language/english/imglib_lang.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/language/english/imglib_lang.php
PHP
mit
2,011
<?php $lang['cal_su'] = "Su"; $lang['cal_mo'] = "Mo"; $lang['cal_tu'] = "Tu"; $lang['cal_we'] = "We"; $lang['cal_th'] = "Th"; $lang['cal_fr'] = "Fr"; $lang['cal_sa'] = "Sa"; $lang['cal_sun'] = "Sun"; $lang['cal_mon'] = "Mon"; $lang['cal_tue'] = "Tue"; $lang['cal_wed'] = "Wed"; $lang['cal_thu'] = "Thu"; $lang['cal_fri'] = "Fri"; $lang['cal_sat'] = "Sat"; $lang['cal_sunday'] = "Sunday"; $lang['cal_monday'] = "Monday"; $lang['cal_tuesday'] = "Tuesday"; $lang['cal_wednesday'] = "Wednesday"; $lang['cal_thursday'] = "Thursday"; $lang['cal_friday'] = "Friday"; $lang['cal_saturday'] = "Saturday"; $lang['cal_jan'] = "Jan"; $lang['cal_feb'] = "Feb"; $lang['cal_mar'] = "Mar"; $lang['cal_apr'] = "Apr"; $lang['cal_may'] = "May"; $lang['cal_jun'] = "Jun"; $lang['cal_jul'] = "Jul"; $lang['cal_aug'] = "Aug"; $lang['cal_sep'] = "Sep"; $lang['cal_oct'] = "Oct"; $lang['cal_nov'] = "Nov"; $lang['cal_dec'] = "Dec"; $lang['cal_january'] = "January"; $lang['cal_february'] = "February"; $lang['cal_march'] = "March"; $lang['cal_april'] = "April"; $lang['cal_mayl'] = "May"; $lang['cal_june'] = "June"; $lang['cal_july'] = "July"; $lang['cal_august'] = "August"; $lang['cal_september'] = "September"; $lang['cal_october'] = "October"; $lang['cal_november'] = "November"; $lang['cal_december'] = "December"; /* End of file calendar_lang.php */ /* Location: ./system/language/english/calendar_lang.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/language/english/calendar_lang.php
PHP
mit
1,437
<?php $lang['ftp_no_connection'] = "Unable to locate a valid connection ID. Please make sure you are connected before peforming any file routines."; $lang['ftp_unable_to_connect'] = "Unable to connect to your FTP server using the supplied hostname."; $lang['ftp_unable_to_login'] = "Unable to login to your FTP server. Please check your username and password."; $lang['ftp_unable_to_makdir'] = "Unable to create the directory you have specified."; $lang['ftp_unable_to_changedir'] = "Unable to change directories."; $lang['ftp_unable_to_chmod'] = "Unable to set file permissions. Please check your path. Note: This feature is only available in PHP 5 or higher."; $lang['ftp_unable_to_upload'] = "Unable to upload the specified file. Please check your path."; $lang['ftp_unable_to_download'] = "Unable to download the specified file. Please check your path."; $lang['ftp_no_source_file'] = "Unable to locate the source file. Please check your path."; $lang['ftp_unable_to_rename'] = "Unable to rename the file."; $lang['ftp_unable_to_delete'] = "Unable to delete the file."; $lang['ftp_unable_to_move'] = "Unable to move the file. Please make sure the destination directory exists."; /* End of file ftp_lang.php */ /* Location: ./system/language/english/ftp_lang.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/language/english/ftp_lang.php
PHP
mit
1,285
<?php $lang['migration_none_found'] = "No migrations were found."; $lang['migration_not_found'] = "This migration could not be found."; $lang['migration_multiple_version'] = "This are multiple migrations with the same version number: %d."; $lang['migration_class_doesnt_exist'] = "The migration class \"%s\" could not be found."; $lang['migration_missing_up_method'] = "The migration class \"%s\" is missing an 'up' method."; $lang['migration_missing_down_method'] = "The migration class \"%s\" is missing an 'down' method."; $lang['migration_invalid_filename'] = "Migration \"%s\" has an invalid filename."; /* End of file migration_lang.php */ /* Location: ./system/language/english/migration_lang.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/language/english/migration_lang.php
PHP
mit
715
<?php $lang['ut_test_name'] = 'Test Name'; $lang['ut_test_datatype'] = 'Test Datatype'; $lang['ut_res_datatype'] = 'Expected Datatype'; $lang['ut_result'] = 'Result'; $lang['ut_undefined'] = 'Undefined Test Name'; $lang['ut_file'] = 'File Name'; $lang['ut_line'] = 'Line Number'; $lang['ut_passed'] = 'Passed'; $lang['ut_failed'] = 'Failed'; $lang['ut_boolean'] = 'Boolean'; $lang['ut_integer'] = 'Integer'; $lang['ut_float'] = 'Float'; $lang['ut_double'] = 'Float'; // can be the same as float $lang['ut_string'] = 'String'; $lang['ut_array'] = 'Array'; $lang['ut_object'] = 'Object'; $lang['ut_resource'] = 'Resource'; $lang['ut_null'] = 'Null'; $lang['ut_notes'] = 'Notes'; /* End of file unit_test_lang.php */ /* Location: ./system/language/english/unit_test_lang.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/language/english/unit_test_lang.php
PHP
mit
808
<?php $lang['profiler_database'] = 'DATABASE'; $lang['profiler_controller_info'] = 'CLASS/METHOD'; $lang['profiler_benchmarks'] = 'BENCHMARKS'; $lang['profiler_queries'] = 'QUERIES'; $lang['profiler_get_data'] = 'GET DATA'; $lang['profiler_post_data'] = 'POST DATA'; $lang['profiler_uri_string'] = 'URI STRING'; $lang['profiler_memory_usage'] = 'MEMORY USAGE'; $lang['profiler_config'] = 'CONFIG VARIABLES'; $lang['profiler_session_data'] = 'SESSION DATA'; $lang['profiler_headers'] = 'HTTP HEADERS'; $lang['profiler_no_db'] = 'Database driver is not currently loaded'; $lang['profiler_no_queries'] = 'No queries were run'; $lang['profiler_no_post'] = 'No POST data exists'; $lang['profiler_no_get'] = 'No GET data exists'; $lang['profiler_no_uri'] = 'No URI data exists'; $lang['profiler_no_memory'] = 'Memory Usage Unavailable'; $lang['profiler_no_profiles'] = 'No Profile data - all Profiler sections have been disabled.'; $lang['profiler_section_hide'] = 'Hide'; $lang['profiler_section_show'] = 'Show'; /* End of file profiler_lang.php */ /* Location: ./system/language/english/profiler_lang.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/language/english/profiler_lang.php
PHP
mit
1,117
<?php $lang['db_invalid_connection_str'] = 'Unable to determine the database settings based on the connection string you submitted.'; $lang['db_unable_to_connect'] = 'Unable to connect to your database server using the provided settings.'; $lang['db_unable_to_select'] = 'Unable to select the specified database: %s'; $lang['db_unable_to_create'] = 'Unable to create the specified database: %s'; $lang['db_invalid_query'] = 'The query you submitted is not valid.'; $lang['db_must_set_table'] = 'You must set the database table to be used with your query.'; $lang['db_must_use_set'] = 'You must use the "set" method to update an entry.'; $lang['db_must_use_index'] = 'You must specify an index to match on for batch updates.'; $lang['db_batch_missing_index'] = 'One or more rows submitted for batch updating is missing the specified index.'; $lang['db_must_use_where'] = 'Updates are not allowed unless they contain a "where" clause.'; $lang['db_del_must_use_where'] = 'Deletes are not allowed unless they contain a "where" or "like" clause.'; $lang['db_field_param_missing'] = 'To fetch fields requires the name of the table as a parameter.'; $lang['db_unsupported_function'] = 'This feature is not available for the database you are using.'; $lang['db_transaction_failure'] = 'Transaction failure: Rollback performed.'; $lang['db_unable_to_drop'] = 'Unable to drop the specified database.'; $lang['db_unsuported_feature'] = 'Unsupported feature of the database platform you are using.'; $lang['db_unsuported_compression'] = 'The file compression format you chose is not supported by your server.'; $lang['db_filepath_error'] = 'Unable to write data to the file path you have submitted.'; $lang['db_invalid_cache_path'] = 'The cache path you submitted is not valid or writable.'; $lang['db_table_name_required'] = 'A table name is required for that operation.'; $lang['db_column_name_required'] = 'A column name is required for that operation.'; $lang['db_column_definition_required'] = 'A column definition is required for that operation.'; $lang['db_unable_to_set_charset'] = 'Unable to set client connection character set: %s'; $lang['db_error_heading'] = 'A Database Error Occurred'; /* End of file db_lang.php */ /* Location: ./system/language/english/db_lang.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/language/english/db_lang.php
PHP
mit
2,273
<?php $lang['upload_userfile_not_set'] = "Unable to find a post variable called userfile."; $lang['upload_file_exceeds_limit'] = "The uploaded file exceeds the maximum allowed size in your PHP configuration file."; $lang['upload_file_exceeds_form_limit'] = "The uploaded file exceeds the maximum size allowed by the submission form."; $lang['upload_file_partial'] = "The file was only partially uploaded."; $lang['upload_no_temp_directory'] = "The temporary folder is missing."; $lang['upload_unable_to_write_file'] = "The file could not be written to disk."; $lang['upload_stopped_by_extension'] = "The file upload was stopped by extension."; $lang['upload_no_file_selected'] = "You did not select a file to upload."; $lang['upload_invalid_filetype'] = "The filetype you are attempting to upload is not allowed."; $lang['upload_invalid_filesize'] = "The file you are attempting to upload is larger than the permitted size."; $lang['upload_invalid_dimensions'] = "The image you are attempting to upload exceedes the maximum height or width."; $lang['upload_destination_error'] = "A problem was encountered while attempting to move the uploaded file to the final destination."; $lang['upload_no_filepath'] = "The upload path does not appear to be valid."; $lang['upload_no_file_types'] = "You have not specified any allowed file types."; $lang['upload_bad_filename'] = "The file name you submitted already exists on the server."; $lang['upload_not_writable'] = "The upload destination folder does not appear to be writable."; /* End of file upload_lang.php */ /* Location: ./system/language/english/upload_lang.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/language/english/upload_lang.php
PHP
mit
1,619
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Number Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/number_helper.html */ // ------------------------------------------------------------------------ /** * Formats a numbers as bytes, based on size, and adds the appropriate suffix * * @access public * @param mixed // will be cast as int * @return string */ if ( ! function_exists('byte_format')) { function byte_format($num, $precision = 1) { $CI =& get_instance(); $CI->lang->load('number'); if ($num >= 1000000000000) { $num = round($num / 1099511627776, $precision); $unit = $CI->lang->line('terabyte_abbr'); } elseif ($num >= 1000000000) { $num = round($num / 1073741824, $precision); $unit = $CI->lang->line('gigabyte_abbr'); } elseif ($num >= 1000000) { $num = round($num / 1048576, $precision); $unit = $CI->lang->line('megabyte_abbr'); } elseif ($num >= 1000) { $num = round($num / 1024, $precision); $unit = $CI->lang->line('kilobyte_abbr'); } else { $unit = $CI->lang->line('bytes'); return number_format($num).' '.$unit; } return number_format($num, $precision).' '.$unit; } } /* End of file number_helper.php */ /* Location: ./system/helpers/number_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/number_helper.php
PHP
mit
1,859
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Language Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/language_helper.html */ // ------------------------------------------------------------------------ /** * Lang * * Fetches a language variable and optionally outputs a form label * * @access public * @param string the language line * @param string the id of the form element * @return string */ if ( ! function_exists('lang')) { function lang($line, $id = '') { $CI =& get_instance(); $line = $CI->lang->line($line); if ($id != '') { $line = '<label for="'.$id.'">'.$line."</label>"; } return $line; } } // ------------------------------------------------------------------------ /* End of file language_helper.php */ /* Location: ./system/helpers/language_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/language_helper.php
PHP
mit
1,409
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Cookie Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/cookie_helper.html */ // ------------------------------------------------------------------------ /** * Set cookie * * Accepts six parameter, or you can submit an associative * array in the first parameter containing all the values. * * @access public * @param mixed * @param string the value of the cookie * @param string the number of seconds until expiration * @param string the cookie domain. Usually: .yourdomain.com * @param string the cookie path * @param string the cookie prefix * @return void */ if ( ! function_exists('set_cookie')) { function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE) { // Set the config file options $CI =& get_instance(); $CI->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure); } } // -------------------------------------------------------------------- /** * Fetch an item from the COOKIE array * * @access public * @param string * @param bool * @return mixed */ if ( ! function_exists('get_cookie')) { function get_cookie($index = '', $xss_clean = FALSE) { $CI =& get_instance(); $prefix = ''; if ( ! isset($_COOKIE[$index]) && config_item('cookie_prefix') != '') { $prefix = config_item('cookie_prefix'); } return $CI->input->cookie($prefix.$index, $xss_clean); } } // -------------------------------------------------------------------- /** * Delete a COOKIE * * @param mixed * @param string the cookie domain. Usually: .yourdomain.com * @param string the cookie path * @param string the cookie prefix * @return void */ if ( ! function_exists('delete_cookie')) { function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '') { set_cookie($name, '', '', $domain, $path, $prefix); } } /* End of file cookie_helper.php */ /* Location: ./system/helpers/cookie_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/cookie_helper.php
PHP
mit
2,591
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Security Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/security_helper.html */ // ------------------------------------------------------------------------ /** * XSS Filtering * * @access public * @param string * @param bool whether or not the content is an image file * @return string */ if ( ! function_exists('xss_clean')) { function xss_clean($str, $is_image = FALSE) { $CI =& get_instance(); return $CI->security->xss_clean($str, $is_image); } } // ------------------------------------------------------------------------ /** * Sanitize Filename * * @access public * @param string * @return string */ if ( ! function_exists('sanitize_filename')) { function sanitize_filename($filename) { $CI =& get_instance(); return $CI->security->sanitize_filename($filename); } } // -------------------------------------------------------------------- /** * Hash encode a string * * @access public * @param string * @return string */ if ( ! function_exists('do_hash')) { function do_hash($str, $type = 'sha1') { if ($type == 'sha1') { return sha1($str); } else { return md5($str); } } } // ------------------------------------------------------------------------ /** * Strip Image Tags * * @access public * @param string * @return string */ if ( ! function_exists('strip_image_tags')) { function strip_image_tags($str) { $str = preg_replace("#<img\s+.*?src\s*=\s*[\"'](.+?)[\"'].*?\>#", "\\1", $str); $str = preg_replace("#<img\s+.*?src\s*=\s*(.+?).*?\>#", "\\1", $str); return $str; } } // ------------------------------------------------------------------------ /** * Convert PHP tags to entities * * @access public * @param string * @return string */ if ( ! function_exists('encode_php_tags')) { function encode_php_tags($str) { return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str); } } /* End of file security_helper.php */ /* Location: ./system/helpers/security_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/security_helper.php
PHP
mit
2,675
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/index.html
HTML
mit
114
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Directory Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/directory_helper.html */ // ------------------------------------------------------------------------ /** * Create a Directory Map * * Reads the specified directory and builds an array * representation of it. Sub-folders contained with the * directory will be mapped as well. * * @access public * @param string path to source * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc) * @return array */ if ( ! function_exists('directory_map')) { function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) { if ($fp = @opendir($source_dir)) { $filedata = array(); $new_depth = $directory_depth - 1; $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; while (FALSE !== ($file = readdir($fp))) { // Remove '.', '..', and hidden files [optional] if ( ! trim($file, '.') OR ($hidden == FALSE && $file[0] == '.')) { continue; } if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir.$file)) { $filedata[$file] = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $new_depth, $hidden); } else { $filedata[] = $file; } } closedir($fp); return $filedata; } return FALSE; } } /* End of file directory_helper.php */ /* Location: ./system/helpers/directory_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/directory_helper.php
PHP
mit
2,062
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Email Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/email_helper.html */ // ------------------------------------------------------------------------ /** * Validate email address * * @access public * @return bool */ if ( ! function_exists('valid_email')) { function valid_email($address) { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; } } // ------------------------------------------------------------------------ /** * Send an email * * @access public * @return bool */ if ( ! function_exists('send_email')) { function send_email($recipient, $subject = 'Test email', $message = 'Hello World') { return mail($recipient, $subject, $message); } } /* End of file email_helper.php */ /* Location: ./system/helpers/email_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/email_helper.php
PHP
mit
1,483
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Date Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/date_helper.html */ // ------------------------------------------------------------------------ /** * Get "now" time * * Returns time() or its GMT equivalent based on the config file preference * * @access public * @return integer */ if ( ! function_exists('now')) { function now() { $CI =& get_instance(); if (strtolower($CI->config->item('time_reference')) == 'gmt') { $now = time(); $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); if (strlen($system_time) < 10) { $system_time = time(); log_message('error', 'The Date class could not set a proper GMT timestamp so the local time() value was used.'); } return $system_time; } else { return time(); } } } // ------------------------------------------------------------------------ /** * Convert MySQL Style Datecodes * * This function is identical to PHPs date() function, * except that it allows date codes to be formatted using * the MySQL style, where each code letter is preceded * with a percent sign: %Y %m %d etc... * * The benefit of doing dates this way is that you don't * have to worry about escaping your text letters that * match the date codes. * * @access public * @param string * @param integer * @return integer */ if ( ! function_exists('mdate')) { function mdate($datestr = '', $time = '') { if ($datestr == '') return ''; if ($time == '') $time = now(); $datestr = str_replace('%\\', '', preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr)); return date($datestr, $time); } } // ------------------------------------------------------------------------ /** * Standard Date * * Returns a date formatted according to the submitted standard. * * @access public * @param string the chosen format * @param integer Unix timestamp * @return string */ if ( ! function_exists('standard_date')) { function standard_date($fmt = 'DATE_RFC822', $time = '') { $formats = array( 'DATE_ATOM' => '%Y-%m-%dT%H:%i:%s%Q', 'DATE_COOKIE' => '%l, %d-%M-%y %H:%i:%s UTC', 'DATE_ISO8601' => '%Y-%m-%dT%H:%i:%s%Q', 'DATE_RFC822' => '%D, %d %M %y %H:%i:%s %O', 'DATE_RFC850' => '%l, %d-%M-%y %H:%i:%s UTC', 'DATE_RFC1036' => '%D, %d %M %y %H:%i:%s %O', 'DATE_RFC1123' => '%D, %d %M %Y %H:%i:%s %O', 'DATE_RSS' => '%D, %d %M %Y %H:%i:%s %O', 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%Q' ); if ( ! isset($formats[$fmt])) { return FALSE; } return mdate($formats[$fmt], $time); } } // ------------------------------------------------------------------------ /** * Timespan * * Returns a span of seconds in this format: * 10 days 14 hours 36 minutes 47 seconds * * @access public * @param integer a number of seconds * @param integer Unix timestamp * @return integer */ if ( ! function_exists('timespan')) { function timespan($seconds = 1, $time = '') { $CI =& get_instance(); $CI->lang->load('date'); if ( ! is_numeric($seconds)) { $seconds = 1; } if ( ! is_numeric($time)) { $time = time(); } if ($time <= $seconds) { $seconds = 1; } else { $seconds = $time - $seconds; } $str = ''; $years = floor($seconds / 31536000); if ($years > 0) { $str .= $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year')).', '; } $seconds -= $years * 31536000; $months = floor($seconds / 2628000); if ($years > 0 OR $months > 0) { if ($months > 0) { $str .= $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month')).', '; } $seconds -= $months * 2628000; } $weeks = floor($seconds / 604800); if ($years > 0 OR $months > 0 OR $weeks > 0) { if ($weeks > 0) { $str .= $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', '; } $seconds -= $weeks * 604800; } $days = floor($seconds / 86400); if ($months > 0 OR $weeks > 0 OR $days > 0) { if ($days > 0) { $str .= $days.' '.$CI->lang->line((($days > 1) ? 'date_days' : 'date_day')).', '; } $seconds -= $days * 86400; } $hours = floor($seconds / 3600); if ($days > 0 OR $hours > 0) { if ($hours > 0) { $str .= $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', '; } $seconds -= $hours * 3600; } $minutes = floor($seconds / 60); if ($days > 0 OR $hours > 0 OR $minutes > 0) { if ($minutes > 0) { $str .= $minutes.' '.$CI->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')).', '; } $seconds -= $minutes * 60; } if ($str == '') { $str .= $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', '; } return substr(trim($str), 0, -1); } } // ------------------------------------------------------------------------ /** * Number of days in a month * * Takes a month/year as input and returns the number of days * for the given month/year. Takes leap years into consideration. * * @access public * @param integer a numeric month * @param integer a numeric year * @return integer */ if ( ! function_exists('days_in_month')) { function days_in_month($month = 0, $year = '') { if ($month < 1 OR $month > 12) { return 0; } if ( ! is_numeric($year) OR strlen($year) != 4) { $year = date('Y'); } if ($month == 2) { if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) { return 29; } } $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); return $days_in_month[$month - 1]; } } // ------------------------------------------------------------------------ /** * Converts a local Unix timestamp to GMT * * @access public * @param integer Unix timestamp * @return integer */ if ( ! function_exists('local_to_gmt')) { function local_to_gmt($time = '') { if ($time == '') $time = time(); return mktime( gmdate("H", $time), gmdate("i", $time), gmdate("s", $time), gmdate("m", $time), gmdate("d", $time), gmdate("Y", $time)); } } // ------------------------------------------------------------------------ /** * Converts GMT time to a localized value * * Takes a Unix timestamp (in GMT) as input, and returns * at the local value based on the timezone and DST setting * submitted * * @access public * @param integer Unix timestamp * @param string timezone * @param bool whether DST is active * @return integer */ if ( ! function_exists('gmt_to_local')) { function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) { if ($time == '') { return now(); } $time += timezones($timezone) * 3600; if ($dst == TRUE) { $time += 3600; } return $time; } } // ------------------------------------------------------------------------ /** * Converts a MySQL Timestamp to Unix * * @access public * @param integer Unix timestamp * @return integer */ if ( ! function_exists('mysql_to_unix')) { function mysql_to_unix($time = '') { // We'll remove certain characters for backward compatibility // since the formatting changed with MySQL 4.1 // YYYY-MM-DD HH:MM:SS $time = str_replace('-', '', $time); $time = str_replace(':', '', $time); $time = str_replace(' ', '', $time); // YYYYMMDDHHMMSS return mktime( substr($time, 8, 2), substr($time, 10, 2), substr($time, 12, 2), substr($time, 4, 2), substr($time, 6, 2), substr($time, 0, 4) ); } } // ------------------------------------------------------------------------ /** * Unix to "Human" * * Formats Unix timestamp to the following prototype: 2006-08-21 11:35 PM * * @access public * @param integer Unix timestamp * @param bool whether to show seconds * @param string format: us or euro * @return string */ if ( ! function_exists('unix_to_human')) { function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') { $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' '; if ($fmt == 'us') { $r .= date('h', $time).':'.date('i', $time); } else { $r .= date('H', $time).':'.date('i', $time); } if ($seconds) { $r .= ':'.date('s', $time); } if ($fmt == 'us') { $r .= ' '.date('A', $time); } return $r; } } // ------------------------------------------------------------------------ /** * Convert "human" date to GMT * * Reverses the above process * * @access public * @param string format: us or euro * @return integer */ if ( ! function_exists('human_to_unix')) { function human_to_unix($datestr = '') { if ($datestr == '') { return FALSE; } $datestr = trim($datestr); $datestr = preg_replace("/\040+/", ' ', $datestr); if ( ! preg_match('/^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\s[0-9]{1,2}:[0-9]{1,2}(?::[0-9]{1,2})?(?:\s[AP]M)?$/i', $datestr)) { return FALSE; } $split = explode(' ', $datestr); $ex = explode("-", $split['0']); $year = (strlen($ex['0']) == 2) ? '20'.$ex['0'] : $ex['0']; $month = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; $day = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2']; $ex = explode(":", $split['1']); $hour = (strlen($ex['0']) == 1) ? '0'.$ex['0'] : $ex['0']; $min = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; if (isset($ex['2']) && preg_match('/[0-9]{1,2}/', $ex['2'])) { $sec = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2']; } else { // Unless specified, seconds get set to zero. $sec = '00'; } if (isset($split['2'])) { $ampm = strtolower($split['2']); if (substr($ampm, 0, 1) == 'p' AND $hour < 12) $hour = $hour + 12; if (substr($ampm, 0, 1) == 'a' AND $hour == 12) $hour = '00'; if (strlen($hour) == 1) $hour = '0'.$hour; } return mktime($hour, $min, $sec, $month, $day, $year); } } // ------------------------------------------------------------------------ /** * Timezone Menu * * Generates a drop-down menu of timezones. * * @access public * @param string timezone * @param string classname * @param string menu name * @return string */ if ( ! function_exists('timezone_menu')) { function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') { $CI =& get_instance(); $CI->lang->load('date'); if ($default == 'GMT') $default = 'UTC'; $menu = '<select name="'.$name.'"'; if ($class != '') { $menu .= ' class="'.$class.'"'; } $menu .= ">\n"; foreach (timezones() as $key => $val) { $selected = ($default == $key) ? " selected='selected'" : ''; $menu .= "<option value='{$key}'{$selected}>".$CI->lang->line($key)."</option>\n"; } $menu .= "</select>"; return $menu; } } // ------------------------------------------------------------------------ /** * Timezones * * Returns an array of timezones. This is a helper function * for various other ones in this library * * @access public * @param string timezone * @return string */ if ( ! function_exists('timezones')) { function timezones($tz = '') { // Note: Don't change the order of these even though // some items appear to be in the wrong order $zones = array( 'UM12' => -12, 'UM11' => -11, 'UM10' => -10, 'UM95' => -9.5, 'UM9' => -9, 'UM8' => -8, 'UM7' => -7, 'UM6' => -6, 'UM5' => -5, 'UM45' => -4.5, 'UM4' => -4, 'UM35' => -3.5, 'UM3' => -3, 'UM2' => -2, 'UM1' => -1, 'UTC' => 0, 'UP1' => +1, 'UP2' => +2, 'UP3' => +3, 'UP35' => +3.5, 'UP4' => +4, 'UP45' => +4.5, 'UP5' => +5, 'UP55' => +5.5, 'UP575' => +5.75, 'UP6' => +6, 'UP65' => +6.5, 'UP7' => +7, 'UP8' => +8, 'UP875' => +8.75, 'UP9' => +9, 'UP95' => +9.5, 'UP10' => +10, 'UP105' => +10.5, 'UP11' => +11, 'UP115' => +11.5, 'UP12' => +12, 'UP1275' => +12.75, 'UP13' => +13, 'UP14' => +14 ); if ($tz == '') { return $zones; } if ($tz == 'GMT') $tz = 'UTC'; return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; } } /* End of file date_helper.php */ /* Location: ./system/helpers/date_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/date_helper.php
PHP
mit
12,971
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter URL Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/url_helper.html */ // ------------------------------------------------------------------------ /** * Site URL * * Create a local URL based on your basepath. Segments can be passed via the * first parameter either as a string or an array. * * @access public * @param string * @return string */ if ( ! function_exists('site_url')) { function site_url($uri = '') { $CI =& get_instance(); return $CI->config->site_url($uri); } } // ------------------------------------------------------------------------ /** * Base URL * * Create a local URL based on your basepath. * Segments can be passed in as a string or an array, same as site_url * or a URL to a file can be passed in, e.g. to an image file. * * @access public * @param string * @return string */ if ( ! function_exists('base_url')) { function base_url($uri = '') { $CI =& get_instance(); return $CI->config->base_url($uri); } } // ------------------------------------------------------------------------ /** * Current URL * * Returns the full URL (including segments) of the page where this * function is placed * * @access public * @return string */ if ( ! function_exists('current_url')) { function current_url() { $CI =& get_instance(); return $CI->config->site_url($CI->uri->uri_string()); } } // ------------------------------------------------------------------------ /** * URL String * * Returns the URI segments. * * @access public * @return string */ if ( ! function_exists('uri_string')) { function uri_string() { $CI =& get_instance(); return $CI->uri->uri_string(); } } // ------------------------------------------------------------------------ /** * Index page * * Returns the "index_page" from your config file * * @access public * @return string */ if ( ! function_exists('index_page')) { function index_page() { $CI =& get_instance(); return $CI->config->item('index_page'); } } // ------------------------------------------------------------------------ /** * Anchor Link * * Creates an anchor based on the local URL. * * @access public * @param string the URL * @param string the link title * @param mixed any attributes * @return string */ if ( ! function_exists('anchor')) { function anchor($uri = '', $title = '', $attributes = '') { $title = (string) $title; if ( ! is_array($uri)) { $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri; } else { $site_url = site_url($uri); } if ($title == '') { $title = $site_url; } if ($attributes != '') { $attributes = _parse_attributes($attributes); } return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>'; } } // ------------------------------------------------------------------------ /** * Anchor Link - Pop-up version * * Creates an anchor based on the local URL. The link * opens a new window based on the attributes specified. * * @access public * @param string the URL * @param string the link title * @param mixed any attributes * @return string */ if ( ! function_exists('anchor_popup')) { function anchor_popup($uri = '', $title = '', $attributes = FALSE) { $title = (string) $title; $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri; if ($title == '') { $title = $site_url; } if ($attributes === FALSE) { return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title."</a>"; } if ( ! is_array($attributes)) { $attributes = array(); } foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val) { $atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key]; unset($attributes[$key]); } if ($attributes != '') { $attributes = _parse_attributes($attributes); } return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\"$attributes>".$title."</a>"; } } // ------------------------------------------------------------------------ /** * Mailto Link * * @access public * @param string the email address * @param string the link title * @param mixed any attributes * @return string */ if ( ! function_exists('mailto')) { function mailto($email, $title = '', $attributes = '') { $title = (string) $title; if ($title == "") { $title = $email; } $attributes = _parse_attributes($attributes); return '<a href="mailto:'.$email.'"'.$attributes.'>'.$title.'</a>'; } } // ------------------------------------------------------------------------ /** * Encoded Mailto Link * * Create a spam-protected mailto link written in Javascript * * @access public * @param string the email address * @param string the link title * @param mixed any attributes * @return string */ if ( ! function_exists('safe_mailto')) { function safe_mailto($email, $title = '', $attributes = '') { $title = (string) $title; if ($title == "") { $title = $email; } for ($i = 0; $i < 16; $i++) { $x[] = substr('<a href="mailto:', $i, 1); } for ($i = 0; $i < strlen($email); $i++) { $x[] = "|".ord(substr($email, $i, 1)); } $x[] = '"'; if ($attributes != '') { if (is_array($attributes)) { foreach ($attributes as $key => $val) { $x[] = ' '.$key.'="'; for ($i = 0; $i < strlen($val); $i++) { $x[] = "|".ord(substr($val, $i, 1)); } $x[] = '"'; } } else { for ($i = 0; $i < strlen($attributes); $i++) { $x[] = substr($attributes, $i, 1); } } } $x[] = '>'; $temp = array(); for ($i = 0; $i < strlen($title); $i++) { $ordinal = ord($title[$i]); if ($ordinal < 128) { $x[] = "|".$ordinal; } else { if (count($temp) == 0) { $count = ($ordinal < 224) ? 2 : 3; } $temp[] = $ordinal; if (count($temp) == $count) { $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); $x[] = "|".$number; $count = 1; $temp = array(); } } } $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>'; $x = array_reverse($x); ob_start(); ?><script type="text/javascript"> //<![CDATA[ var l=new Array(); <?php $i = 0; foreach ($x as $val){ ?>l[<?php echo $i++; ?>]='<?php echo $val; ?>';<?php } ?> for (var i = l.length-1; i >= 0; i=i-1){ if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";"); else document.write(unescape(l[i]));} //]]> </script><?php $buffer = ob_get_contents(); ob_end_clean(); return $buffer; } } // ------------------------------------------------------------------------ /** * Auto-linker * * Automatically links URL and Email addresses. * Note: There's a bit of extra code here to deal with * URLs or emails that end in a period. We'll strip these * off and add them after the link. * * @access public * @param string the string * @param string the type: email, url, or both * @param bool whether to create pop-up links * @return string */ if ( ! function_exists('auto_link')) { function auto_link($str, $type = 'both', $popup = FALSE) { if ($type != 'email') { if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches)) { $pop = ($popup == TRUE) ? " target=\"_blank\" " : ""; for ($i = 0; $i < count($matches['0']); $i++) { $period = ''; if (preg_match("|\.$|", $matches['6'][$i])) { $period = '.'; $matches['6'][$i] = substr($matches['6'][$i], 0, -1); } $str = str_replace($matches['0'][$i], $matches['1'][$i].'<a href="http'. $matches['4'][$i].'://'. $matches['5'][$i]. $matches['6'][$i].'"'.$pop.'>http'. $matches['4'][$i].'://'. $matches['5'][$i]. $matches['6'][$i].'</a>'. $period, $str); } } } if ($type != 'url') { if (preg_match_all("/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches)) { for ($i = 0; $i < count($matches['0']); $i++) { $period = ''; if (preg_match("|\.$|", $matches['3'][$i])) { $period = '.'; $matches['3'][$i] = substr($matches['3'][$i], 0, -1); } $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str); } } } return $str; } } // ------------------------------------------------------------------------ /** * Prep URL * * Simply adds the http:// part if no scheme is included * * @access public * @param string the URL * @return string */ if ( ! function_exists('prep_url')) { function prep_url($str = '') { if ($str == 'http://' OR $str == '') { return ''; } $url = parse_url($str); if ( ! $url OR ! isset($url['scheme'])) { $str = 'http://'.$str; } return $str; } } // ------------------------------------------------------------------------ /** * Create URL Title * * Takes a "title" string as input and creates a * human-friendly URL string with a "separator" string * as the word separator. * * @access public * @param string the string * @param string the separator * @return string */ if ( ! function_exists('url_title')) { function url_title($str, $separator = '-', $lowercase = FALSE) { if ($separator == 'dash') { $separator = '-'; } else if ($separator == 'underscore') { $separator = '_'; } $q_separator = preg_quote($separator); $trans = array( '&.+?;' => '', '[^a-z0-9 _-]' => '', '\s+' => $separator, '('.$q_separator.')+' => $separator ); $str = strip_tags($str); foreach ($trans as $key => $val) { $str = preg_replace("#".$key."#i", $val, $str); } if ($lowercase === TRUE) { $str = strtolower($str); } return trim($str, $separator); } } // ------------------------------------------------------------------------ /** * Header Redirect * * Header redirect in two flavors * For very fine grained control over headers, you could use the Output * Library's set_header() function. * * @access public * @param string the URL * @param string the method: location or redirect * @return string */ if ( ! function_exists('redirect')) { function redirect($uri = '', $method = 'location', $http_response_code = 302) { if ( ! preg_match('#^https?://#i', $uri)) { $uri = site_url($uri); } switch($method) { case 'refresh' : header("Refresh:0;url=".$uri); break; default : header("Location: ".$uri, TRUE, $http_response_code); break; } exit; } } // ------------------------------------------------------------------------ /** * Parse out the attributes * * Some of the functions use this * * @access private * @param array * @param bool * @return string */ if ( ! function_exists('_parse_attributes')) { function _parse_attributes($attributes, $javascript = FALSE) { if (is_string($attributes)) { return ($attributes != '') ? ' '.$attributes : ''; } $att = ''; foreach ($attributes as $key => $val) { if ($javascript == TRUE) { $att .= $key . '=' . $val . ','; } else { $att .= ' ' . $key . '="' . $val . '"'; } } if ($javascript == TRUE AND $att != '') { $att = substr($att, 0, -1); } return $att; } } /* End of file url_helper.php */ /* Location: ./system/helpers/url_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/url_helper.php
PHP
mit
12,360
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter File Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/file_helpers.html */ // ------------------------------------------------------------------------ /** * Read File * * Opens the file specfied in the path and returns it as a string. * * @access public * @param string path to file * @return string */ if ( ! function_exists('read_file')) { function read_file($file) { if ( ! file_exists($file)) { return FALSE; } if (function_exists('file_get_contents')) { return file_get_contents($file); } if ( ! $fp = @fopen($file, FOPEN_READ)) { return FALSE; } flock($fp, LOCK_SH); $data = ''; if (filesize($file) > 0) { $data =& fread($fp, filesize($file)); } flock($fp, LOCK_UN); fclose($fp); return $data; } } // ------------------------------------------------------------------------ /** * Write File * * Writes data to the file specified in the path. * Creates a new file if non-existent. * * @access public * @param string path to file * @param string file data * @return bool */ if ( ! function_exists('write_file')) { function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE) { if ( ! $fp = @fopen($path, $mode)) { return FALSE; } flock($fp, LOCK_EX); fwrite($fp, $data); flock($fp, LOCK_UN); fclose($fp); return TRUE; } } // ------------------------------------------------------------------------ /** * Delete Files * * Deletes all files contained in the supplied directory path. * Files must be writable or owned by the system in order to be deleted. * If the second parameter is set to TRUE, any directories contained * within the supplied base directory will be nuked as well. * * @access public * @param string path to file * @param bool whether to delete any directories found in the path * @return bool */ if ( ! function_exists('delete_files')) { function delete_files($path, $del_dir = FALSE, $level = 0) { // Trim the trailing slash $path = rtrim($path, DIRECTORY_SEPARATOR); if ( ! $current_dir = @opendir($path)) { return FALSE; } while (FALSE !== ($filename = @readdir($current_dir))) { if ($filename != "." and $filename != "..") { if (is_dir($path.DIRECTORY_SEPARATOR.$filename)) { // Ignore empty folders if (substr($filename, 0, 1) != '.') { delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1); } } else { unlink($path.DIRECTORY_SEPARATOR.$filename); } } } @closedir($current_dir); if ($del_dir == TRUE AND $level > 0) { return @rmdir($path); } return TRUE; } } // ------------------------------------------------------------------------ /** * Get Filenames * * Reads the specified directory and builds an array containing the filenames. * Any sub-folders contained within the specified path are read as well. * * @access public * @param string path to source * @param bool whether to include the path as part of the filename * @param bool internal variable to determine recursion status - do not use in calls * @return array */ if ( ! function_exists('get_filenames')) { function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) { static $_filedata = array(); if ($fp = @opendir($source_dir)) { // reset the array and make sure $source_dir has a trailing slash on the initial call if ($_recursion === FALSE) { $_filedata = array(); $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; } while (FALSE !== ($file = readdir($fp))) { if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0) { get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); } elseif (strncmp($file, '.', 1) !== 0) { $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file; } } return $_filedata; } else { return FALSE; } } } // -------------------------------------------------------------------- /** * Get Directory File Information * * Reads the specified directory and builds an array containing the filenames, * filesize, dates, and permissions * * Any sub-folders contained within the specified path are read as well. * * @access public * @param string path to source * @param bool Look only at the top level directory specified? * @param bool internal variable to determine recursion status - do not use in calls * @return array */ if ( ! function_exists('get_dir_file_info')) { function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE) { static $_filedata = array(); $relative_path = $source_dir; if ($fp = @opendir($source_dir)) { // reset the array and make sure $source_dir has a trailing slash on the initial call if ($_recursion === FALSE) { $_filedata = array(); $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; } // foreach (scandir($source_dir, 1) as $file) // In addition to being PHP5+, scandir() is simply not as fast while (FALSE !== ($file = readdir($fp))) { if (@is_dir($source_dir.$file) AND strncmp($file, '.', 1) !== 0 AND $top_level_only === FALSE) { get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE); } elseif (strncmp($file, '.', 1) !== 0) { $_filedata[$file] = get_file_info($source_dir.$file); $_filedata[$file]['relative_path'] = $relative_path; } } return $_filedata; } else { return FALSE; } } } // -------------------------------------------------------------------- /** * Get File Info * * Given a file and path, returns the name, path, size, date modified * Second parameter allows you to explicitly declare what information you want returned * Options are: name, server_path, size, date, readable, writable, executable, fileperms * Returns FALSE if the file cannot be found. * * @access public * @param string path to file * @param mixed array or comma separated string of information returned * @return array */ if ( ! function_exists('get_file_info')) { function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date')) { if ( ! file_exists($file)) { return FALSE; } if (is_string($returned_values)) { $returned_values = explode(',', $returned_values); } foreach ($returned_values as $key) { switch ($key) { case 'name': $fileinfo['name'] = substr(strrchr($file, DIRECTORY_SEPARATOR), 1); break; case 'server_path': $fileinfo['server_path'] = $file; break; case 'size': $fileinfo['size'] = filesize($file); break; case 'date': $fileinfo['date'] = filemtime($file); break; case 'readable': $fileinfo['readable'] = is_readable($file); break; case 'writable': // There are known problems using is_weritable on IIS. It may not be reliable - consider fileperms() $fileinfo['writable'] = is_writable($file); break; case 'executable': $fileinfo['executable'] = is_executable($file); break; case 'fileperms': $fileinfo['fileperms'] = fileperms($file); break; } } return $fileinfo; } } // -------------------------------------------------------------------- /** * Get Mime by Extension * * Translates a file extension into a mime type based on config/mimes.php. * Returns FALSE if it can't determine the type, or open the mime config file * * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience * It should NOT be trusted, and should certainly NOT be used for security * * @access public * @param string path to file * @return mixed */ if ( ! function_exists('get_mime_by_extension')) { function get_mime_by_extension($file) { $extension = strtolower(substr(strrchr($file, '.'), 1)); global $mimes; if ( ! is_array($mimes)) { if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); } elseif (is_file(APPPATH.'config/mimes.php')) { include(APPPATH.'config/mimes.php'); } if ( ! is_array($mimes)) { return FALSE; } } if (array_key_exists($extension, $mimes)) { if (is_array($mimes[$extension])) { // Multiple mime types, just give the first one return current($mimes[$extension]); } else { return $mimes[$extension]; } } else { return FALSE; } } } // -------------------------------------------------------------------- /** * Symbolic Permissions * * Takes a numeric value representing a file's permissions and returns * standard symbolic notation representing that value * * @access public * @param int * @return string */ if ( ! function_exists('symbolic_permissions')) { function symbolic_permissions($perms) { if (($perms & 0xC000) == 0xC000) { $symbolic = 's'; // Socket } elseif (($perms & 0xA000) == 0xA000) { $symbolic = 'l'; // Symbolic Link } elseif (($perms & 0x8000) == 0x8000) { $symbolic = '-'; // Regular } elseif (($perms & 0x6000) == 0x6000) { $symbolic = 'b'; // Block special } elseif (($perms & 0x4000) == 0x4000) { $symbolic = 'd'; // Directory } elseif (($perms & 0x2000) == 0x2000) { $symbolic = 'c'; // Character special } elseif (($perms & 0x1000) == 0x1000) { $symbolic = 'p'; // FIFO pipe } else { $symbolic = 'u'; // Unknown } // Owner $symbolic .= (($perms & 0x0100) ? 'r' : '-'); $symbolic .= (($perms & 0x0080) ? 'w' : '-'); $symbolic .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-')); // Group $symbolic .= (($perms & 0x0020) ? 'r' : '-'); $symbolic .= (($perms & 0x0010) ? 'w' : '-'); $symbolic .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-')); // World $symbolic .= (($perms & 0x0004) ? 'r' : '-'); $symbolic .= (($perms & 0x0002) ? 'w' : '-'); $symbolic .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-')); return $symbolic; } } // -------------------------------------------------------------------- /** * Octal Permissions * * Takes a numeric value representing a file's permissions and returns * a three character string representing the file's octal permissions * * @access public * @param int * @return string */ if ( ! function_exists('octal_permissions')) { function octal_permissions($perms) { return substr(sprintf('%o', $perms), -3); } } /* End of file file_helper.php */ /* Location: ./system/helpers/file_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/file_helper.php
PHP
mit
11,384
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Path Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/xml_helper.html */ // ------------------------------------------------------------------------ /** * Set Realpath * * @access public * @param string * @param bool checks to see if the path exists * @return string */ if ( ! function_exists('set_realpath')) { function set_realpath($path, $check_existance = FALSE) { // Security check to make sure the path is NOT a URL. No remote file inclusion! if (preg_match("#^(http:\/\/|https:\/\/|www\.|ftp|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})#i", $path)) { show_error('The path you submitted must be a local server path, not a URL'); } // Resolve the path if (function_exists('realpath') AND @realpath($path) !== FALSE) { $path = realpath($path).'/'; } // Add a trailing slash $path = preg_replace("#([^/])/*$#", "\\1/", $path); // Make sure the path exists if ($check_existance == TRUE) { if ( ! is_dir($path)) { show_error('Not a valid path: '.$path); } } return $path; } } /* End of file path_helper.php */ /* Location: ./system/helpers/path_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/path_helper.php
PHP
mit
1,779
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Inflector Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/directory_helper.html */ // -------------------------------------------------------------------- /** * Singular * * Takes a plural word and makes it singular * * @access public * @param string * @return str */ if ( ! function_exists('singular')) { function singular($str) { $result = strval($str); $singular_rules = array( '/(matr)ices$/' => '\1ix', '/(vert|ind)ices$/' => '\1ex', '/^(ox)en/' => '\1', '/(alias)es$/' => '\1', '/([octop|vir])i$/' => '\1us', '/(cris|ax|test)es$/' => '\1is', '/(shoe)s$/' => '\1', '/(o)es$/' => '\1', '/(bus|campus)es$/' => '\1', '/([m|l])ice$/' => '\1ouse', '/(x|ch|ss|sh)es$/' => '\1', '/(m)ovies$/' => '\1\2ovie', '/(s)eries$/' => '\1\2eries', '/([^aeiouy]|qu)ies$/' => '\1y', '/([lr])ves$/' => '\1f', '/(tive)s$/' => '\1', '/(hive)s$/' => '\1', '/([^f])ves$/' => '\1fe', '/(^analy)ses$/' => '\1sis', '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/' => '\1\2sis', '/([ti])a$/' => '\1um', '/(p)eople$/' => '\1\2erson', '/(m)en$/' => '\1an', '/(s)tatuses$/' => '\1\2tatus', '/(c)hildren$/' => '\1\2hild', '/(n)ews$/' => '\1\2ews', '/([^u])s$/' => '\1', ); foreach ($singular_rules as $rule => $replacement) { if (preg_match($rule, $result)) { $result = preg_replace($rule, $replacement, $result); break; } } return $result; } } // -------------------------------------------------------------------- /** * Plural * * Takes a singular word and makes it plural * * @access public * @param string * @param bool * @return str */ if ( ! function_exists('plural')) { function plural($str, $force = FALSE) { $result = strval($str); $plural_rules = array( '/^(ox)$/' => '\1\2en', // ox '/([m|l])ouse$/' => '\1ice', // mouse, louse '/(matr|vert|ind)ix|ex$/' => '\1ices', // matrix, vertex, index '/(x|ch|ss|sh)$/' => '\1es', // search, switch, fix, box, process, address '/([^aeiouy]|qu)y$/' => '\1ies', // query, ability, agency '/(hive)$/' => '\1s', // archive, hive '/(?:([^f])fe|([lr])f)$/' => '\1\2ves', // half, safe, wife '/sis$/' => 'ses', // basis, diagnosis '/([ti])um$/' => '\1a', // datum, medium '/(p)erson$/' => '\1eople', // person, salesperson '/(m)an$/' => '\1en', // man, woman, spokesman '/(c)hild$/' => '\1hildren', // child '/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato '/(bu|campu)s$/' => '\1\2ses', // bus, campus '/(alias|status|virus)/' => '\1es', // alias '/(octop)us$/' => '\1i', // octopus '/(ax|cris|test)is$/' => '\1es', // axis, crisis '/s$/' => 's', // no change (compatibility) '/$/' => 's', ); foreach ($plural_rules as $rule => $replacement) { if (preg_match($rule, $result)) { $result = preg_replace($rule, $replacement, $result); break; } } return $result; } } // -------------------------------------------------------------------- /** * Camelize * * Takes multiple words separated by spaces or underscores and camelizes them * * @access public * @param string * @return str */ if ( ! function_exists('camelize')) { function camelize($str) { $str = 'x'.strtolower(trim($str)); $str = ucwords(preg_replace('/[\s_]+/', ' ', $str)); return substr(str_replace(' ', '', $str), 1); } } // -------------------------------------------------------------------- /** * Underscore * * Takes multiple words separated by spaces and underscores them * * @access public * @param string * @return str */ if ( ! function_exists('underscore')) { function underscore($str) { return preg_replace('/[\s]+/', '_', strtolower(trim($str))); } } // -------------------------------------------------------------------- /** * Humanize * * Takes multiple words separated by underscores and changes them to spaces * * @access public * @param string * @return str */ if ( ! function_exists('humanize')) { function humanize($str) { return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str)))); } } /* End of file inflector_helper.php */ /* Location: ./system/helpers/inflector_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/inflector_helper.php
PHP
mit
5,367
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Form Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/form_helper.html */ // ------------------------------------------------------------------------ /** * Form Declaration * * Creates the opening portion of the form. * * @access public * @param string the URI segments of the form destination * @param array a key/value pair of attributes * @param array a key/value pair hidden data * @return string */ if ( ! function_exists('form_open')) { function form_open($action = '', $attributes = '', $hidden = array()) { $CI =& get_instance(); if ($attributes == '') { $attributes = 'method="post"'; } // If an action is not a full URL then turn it into one if ($action && strpos($action, '://') === FALSE) { $action = $CI->config->site_url($action); } // If no action is provided then set to the current url $action OR $action = $CI->config->site_url($CI->uri->uri_string()); $form = '<form action="'.$action.'"'; $form .= _attributes_to_string($attributes, TRUE); $form .= '>'; // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites if ($CI->config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->base_url()) === FALSE OR strpos($form, 'method="get"'))) { $hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash(); } if (is_array($hidden) AND count($hidden) > 0) { $form .= sprintf("<div style=\"display:none\">%s</div>", form_hidden($hidden)); } return $form; } } // ------------------------------------------------------------------------ /** * Form Declaration - Multipart type * * Creates the opening portion of the form, but with "multipart/form-data". * * @access public * @param string the URI segments of the form destination * @param array a key/value pair of attributes * @param array a key/value pair hidden data * @return string */ if ( ! function_exists('form_open_multipart')) { function form_open_multipart($action = '', $attributes = array(), $hidden = array()) { if (is_string($attributes)) { $attributes .= ' enctype="multipart/form-data"'; } else { $attributes['enctype'] = 'multipart/form-data'; } return form_open($action, $attributes, $hidden); } } // ------------------------------------------------------------------------ /** * Hidden Input Field * * Generates hidden fields. You can pass a simple key/value string or an associative * array with multiple values. * * @access public * @param mixed * @param string * @return string */ if ( ! function_exists('form_hidden')) { function form_hidden($name, $value = '', $recursing = FALSE) { static $form; if ($recursing === FALSE) { $form = "\n"; } if (is_array($name)) { foreach ($name as $key => $val) { form_hidden($key, $val, TRUE); } return $form; } if ( ! is_array($value)) { $form .= '<input type="hidden" name="'.$name.'" value="'.form_prep($value, $name).'" />'."\n"; } else { foreach ($value as $k => $v) { $k = (is_int($k)) ? '' : $k; form_hidden($name.'['.$k.']', $v, TRUE); } } return $form; } } // ------------------------------------------------------------------------ /** * Text Input Field * * @access public * @param mixed * @param string * @param string * @return string */ if ( ! function_exists('form_input')) { function form_input($data = '', $value = '', $extra = '') { $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "<input "._parse_form_attributes($data, $defaults).$extra." />"; } } // ------------------------------------------------------------------------ /** * Password Field * * Identical to the input function but adds the "password" type * * @access public * @param mixed * @param string * @param string * @return string */ if ( ! function_exists('form_password')) { function form_password($data = '', $value = '', $extra = '') { if ( ! is_array($data)) { $data = array('name' => $data); } $data['type'] = 'password'; return form_input($data, $value, $extra); } } // ------------------------------------------------------------------------ /** * Upload Field * * Identical to the input function but adds the "file" type * * @access public * @param mixed * @param string * @param string * @return string */ if ( ! function_exists('form_upload')) { function form_upload($data = '', $value = '', $extra = '') { if ( ! is_array($data)) { $data = array('name' => $data); } $data['type'] = 'file'; return form_input($data, $value, $extra); } } // ------------------------------------------------------------------------ /** * Textarea field * * @access public * @param mixed * @param string * @param string * @return string */ if ( ! function_exists('form_textarea')) { function form_textarea($data = '', $value = '', $extra = '') { $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '40', 'rows' => '10'); if ( ! is_array($data) OR ! isset($data['value'])) { $val = $value; } else { $val = $data['value']; unset($data['value']); // textareas don't use the value attribute } $name = (is_array($data)) ? $data['name'] : $data; return "<textarea "._parse_form_attributes($data, $defaults).$extra.">".form_prep($val, $name)."</textarea>"; } } // ------------------------------------------------------------------------ /** * Multi-select menu * * @access public * @param string * @param array * @param mixed * @param string * @return type */ if ( ! function_exists('form_multiselect')) { function form_multiselect($name = '', $options = array(), $selected = array(), $extra = '') { if ( ! strpos($extra, 'multiple')) { $extra .= ' multiple="multiple"'; } return form_dropdown($name, $options, $selected, $extra); } } // -------------------------------------------------------------------- /** * Drop-down Menu * * @access public * @param string * @param array * @param string * @param string * @return string */ if ( ! function_exists('form_dropdown')) { function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') { if ( ! is_array($selected)) { $selected = array($selected); } // If no selected state was submitted we will attempt to set it automatically if (count($selected) === 0) { // If the form name appears in the $_POST array we have a winner! if (isset($_POST[$name])) { $selected = array($_POST[$name]); } } if ($extra != '') $extra = ' '.$extra; $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; $form = '<select name="'.$name.'"'.$extra.$multiple.">\n"; foreach ($options as $key => $val) { $key = (string) $key; if (is_array($val) && ! empty($val)) { $form .= '<optgroup label="'.$key.'">'."\n"; foreach ($val as $optgroup_key => $optgroup_val) { $sel = (in_array($optgroup_key, $selected)) ? ' selected="selected"' : ''; $form .= '<option value="'.$optgroup_key.'"'.$sel.'>'.(string) $optgroup_val."</option>\n"; } $form .= '</optgroup>'."\n"; } else { $sel = (in_array($key, $selected)) ? ' selected="selected"' : ''; $form .= '<option value="'.$key.'"'.$sel.'>'.(string) $val."</option>\n"; } } $form .= '</select>'; return $form; } } // ------------------------------------------------------------------------ /** * Checkbox Field * * @access public * @param mixed * @param string * @param bool * @param string * @return string */ if ( ! function_exists('form_checkbox')) { function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') { $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); if (is_array($data) AND array_key_exists('checked', $data)) { $checked = $data['checked']; if ($checked == FALSE) { unset($data['checked']); } else { $data['checked'] = 'checked'; } } if ($checked == TRUE) { $defaults['checked'] = 'checked'; } else { unset($defaults['checked']); } return "<input "._parse_form_attributes($data, $defaults).$extra." />"; } } // ------------------------------------------------------------------------ /** * Radio Button * * @access public * @param mixed * @param string * @param bool * @param string * @return string */ if ( ! function_exists('form_radio')) { function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') { if ( ! is_array($data)) { $data = array('name' => $data); } $data['type'] = 'radio'; return form_checkbox($data, $value, $checked, $extra); } } // ------------------------------------------------------------------------ /** * Submit Button * * @access public * @param mixed * @param string * @param string * @return string */ if ( ! function_exists('form_submit')) { function form_submit($data = '', $value = '', $extra = '') { $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "<input "._parse_form_attributes($data, $defaults).$extra." />"; } } // ------------------------------------------------------------------------ /** * Reset Button * * @access public * @param mixed * @param string * @param string * @return string */ if ( ! function_exists('form_reset')) { function form_reset($data = '', $value = '', $extra = '') { $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "<input "._parse_form_attributes($data, $defaults).$extra." />"; } } // ------------------------------------------------------------------------ /** * Form Button * * @access public * @param mixed * @param string * @param string * @return string */ if ( ! function_exists('form_button')) { function form_button($data = '', $content = '', $extra = '') { $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'button'); if ( is_array($data) AND isset($data['content'])) { $content = $data['content']; unset($data['content']); // content is not an attribute } return "<button "._parse_form_attributes($data, $defaults).$extra.">".$content."</button>"; } } // ------------------------------------------------------------------------ /** * Form Label Tag * * @access public * @param string The text to appear onscreen * @param string The id the label applies to * @param string Additional attributes * @return string */ if ( ! function_exists('form_label')) { function form_label($label_text = '', $id = '', $attributes = array()) { $label = '<label'; if ($id != '') { $label .= " for=\"$id\""; } if (is_array($attributes) AND count($attributes) > 0) { foreach ($attributes as $key => $val) { $label .= ' '.$key.'="'.$val.'"'; } } $label .= ">$label_text</label>"; return $label; } } // ------------------------------------------------------------------------ /** * Fieldset Tag * * Used to produce <fieldset><legend>text</legend>. To close fieldset * use form_fieldset_close() * * @access public * @param string The legend text * @param string Additional attributes * @return string */ if ( ! function_exists('form_fieldset')) { function form_fieldset($legend_text = '', $attributes = array()) { $fieldset = "<fieldset"; $fieldset .= _attributes_to_string($attributes, FALSE); $fieldset .= ">\n"; if ($legend_text != '') { $fieldset .= "<legend>$legend_text</legend>\n"; } return $fieldset; } } // ------------------------------------------------------------------------ /** * Fieldset Close Tag * * @access public * @param string * @return string */ if ( ! function_exists('form_fieldset_close')) { function form_fieldset_close($extra = '') { return "</fieldset>".$extra; } } // ------------------------------------------------------------------------ /** * Form Close Tag * * @access public * @param string * @return string */ if ( ! function_exists('form_close')) { function form_close($extra = '') { return "</form>".$extra; } } // ------------------------------------------------------------------------ /** * Form Prep * * Formats text so that it can be safely placed in a form field in the event it has HTML tags. * * @access public * @param string * @return string */ if ( ! function_exists('form_prep')) { function form_prep($str = '', $field_name = '') { static $prepped_fields = array(); // if the field name is an array we do this recursively if (is_array($str)) { foreach ($str as $key => $val) { $str[$key] = form_prep($val); } return $str; } if ($str === '') { return ''; } // we've already prepped a field with this name // @todo need to figure out a way to namespace this so // that we know the *exact* field and not just one with // the same name if (isset($prepped_fields[$field_name])) { return $str; } $str = htmlspecialchars($str); // In case htmlspecialchars misses these. $str = str_replace(array("'", '"'), array("&#39;", "&quot;"), $str); if ($field_name != '') { $prepped_fields[$field_name] = $field_name; } return $str; } } // ------------------------------------------------------------------------ /** * Form Value * * Grabs a value from the POST array for the specified field so you can * re-populate an input field or textarea. If Form Validation * is active it retrieves the info from the validation class * * @access public * @param string * @return mixed */ if ( ! function_exists('set_value')) { function set_value($field = '', $default = '') { if (FALSE === ($OBJ =& _get_validation_object())) { if ( ! isset($_POST[$field])) { return $default; } return form_prep($_POST[$field], $field); } return form_prep($OBJ->set_value($field, $default), $field); } } // ------------------------------------------------------------------------ /** * Set Select * * Let's you set the selected value of a <select> menu via data in the POST array. * If Form Validation is active it retrieves the info from the validation class * * @access public * @param string * @param string * @param bool * @return string */ if ( ! function_exists('set_select')) { function set_select($field = '', $value = '', $default = FALSE) { $OBJ =& _get_validation_object(); if ($OBJ === FALSE) { if ( ! isset($_POST[$field])) { if (count($_POST) === 0 AND $default == TRUE) { return ' selected="selected"'; } return ''; } $field = $_POST[$field]; if (is_array($field)) { if ( ! in_array($value, $field)) { return ''; } } else { if (($field == '' OR $value == '') OR ($field != $value)) { return ''; } } return ' selected="selected"'; } return $OBJ->set_select($field, $value, $default); } } // ------------------------------------------------------------------------ /** * Set Checkbox * * Let's you set the selected value of a checkbox via the value in the POST array. * If Form Validation is active it retrieves the info from the validation class * * @access public * @param string * @param string * @param bool * @return string */ if ( ! function_exists('set_checkbox')) { function set_checkbox($field = '', $value = '', $default = FALSE) { $OBJ =& _get_validation_object(); if ($OBJ === FALSE) { if ( ! isset($_POST[$field])) { if (count($_POST) === 0 AND $default == TRUE) { return ' checked="checked"'; } return ''; } $field = $_POST[$field]; if (is_array($field)) { if ( ! in_array($value, $field)) { return ''; } } else { if (($field == '' OR $value == '') OR ($field != $value)) { return ''; } } return ' checked="checked"'; } return $OBJ->set_checkbox($field, $value, $default); } } // ------------------------------------------------------------------------ /** * Set Radio * * Let's you set the selected value of a radio field via info in the POST array. * If Form Validation is active it retrieves the info from the validation class * * @access public * @param string * @param string * @param bool * @return string */ if ( ! function_exists('set_radio')) { function set_radio($field = '', $value = '', $default = FALSE) { $OBJ =& _get_validation_object(); if ($OBJ === FALSE) { if ( ! isset($_POST[$field])) { if (count($_POST) === 0 AND $default == TRUE) { return ' checked="checked"'; } return ''; } $field = $_POST[$field]; if (is_array($field)) { if ( ! in_array($value, $field)) { return ''; } } else { if (($field == '' OR $value == '') OR ($field != $value)) { return ''; } } return ' checked="checked"'; } return $OBJ->set_radio($field, $value, $default); } } // ------------------------------------------------------------------------ /** * Form Error * * Returns the error for a specific form field. This is a helper for the * form validation class. * * @access public * @param string * @param string * @param string * @return string */ if ( ! function_exists('form_error')) { function form_error($field = '', $prefix = '', $suffix = '') { if (FALSE === ($OBJ =& _get_validation_object())) { return ''; } return $OBJ->error($field, $prefix, $suffix); } } // ------------------------------------------------------------------------ /** * Validation Error String * * Returns all the errors associated with a form submission. This is a helper * function for the form validation class. * * @access public * @param string * @param string * @return string */ if ( ! function_exists('validation_errors')) { function validation_errors($prefix = '', $suffix = '') { if (FALSE === ($OBJ =& _get_validation_object())) { return ''; } return $OBJ->error_string($prefix, $suffix); } } // ------------------------------------------------------------------------ /** * Parse the form attributes * * Helper function used by some of the form helpers * * @access private * @param array * @param array * @return string */ if ( ! function_exists('_parse_form_attributes')) { function _parse_form_attributes($attributes, $default) { if (is_array($attributes)) { foreach ($default as $key => $val) { if (isset($attributes[$key])) { $default[$key] = $attributes[$key]; unset($attributes[$key]); } } if (count($attributes) > 0) { $default = array_merge($default, $attributes); } } $att = ''; foreach ($default as $key => $val) { if ($key == 'value') { $val = form_prep($val, $default['name']); } $att .= $key . '="' . $val . '" '; } return $att; } } // ------------------------------------------------------------------------ /** * Attributes To String * * Helper function used by some of the form helpers * * @access private * @param mixed * @param bool * @return string */ if ( ! function_exists('_attributes_to_string')) { function _attributes_to_string($attributes, $formtag = FALSE) { if (is_string($attributes) AND strlen($attributes) > 0) { if ($formtag == TRUE AND strpos($attributes, 'method=') === FALSE) { $attributes .= ' method="post"'; } if ($formtag == TRUE AND strpos($attributes, 'accept-charset=') === FALSE) { $attributes .= ' accept-charset="'.strtolower(config_item('charset')).'"'; } return ' '.$attributes; } if (is_object($attributes) AND count($attributes) > 0) { $attributes = (array)$attributes; } if (is_array($attributes) AND count($attributes) > 0) { $atts = ''; if ( ! isset($attributes['method']) AND $formtag === TRUE) { $atts .= ' method="post"'; } if ( ! isset($attributes['accept-charset']) AND $formtag === TRUE) { $atts .= ' accept-charset="'.strtolower(config_item('charset')).'"'; } foreach ($attributes as $key => $val) { $atts .= ' '.$key.'="'.$val.'"'; } return $atts; } } } // ------------------------------------------------------------------------ /** * Validation Object * * Determines what the form validation class was instantiated as, fetches * the object and returns it. * * @access private * @return mixed */ if ( ! function_exists('_get_validation_object')) { function &_get_validation_object() { $CI =& get_instance(); // We set this as a variable since we're returning by reference. $return = FALSE; if (FALSE !== ($object = $CI->load->is_loaded('form_validation'))) { if ( ! isset($CI->$object) OR ! is_object($CI->$object)) { return $return; } return $CI->$object; } return $return; } } /* End of file form_helper.php */ /* Location: ./system/helpers/form_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/form_helper.php
PHP
mit
21,772
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Typography Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/typography_helper.html */ // ------------------------------------------------------------------------ /** * Convert newlines to HTML line breaks except within PRE tags * * @access public * @param string * @return string */ if ( ! function_exists('nl2br_except_pre')) { function nl2br_except_pre($str) { $CI =& get_instance(); $CI->load->library('typography'); return $CI->typography->nl2br_except_pre($str); } } // ------------------------------------------------------------------------ /** * Auto Typography Wrapper Function * * * @access public * @param string * @param bool whether to allow javascript event handlers * @param bool whether to reduce multiple instances of double newlines to two * @return string */ if ( ! function_exists('auto_typography')) { function auto_typography($str, $strip_js_event_handlers = TRUE, $reduce_linebreaks = FALSE) { $CI =& get_instance(); $CI->load->library('typography'); return $CI->typography->auto_typography($str, $strip_js_event_handlers, $reduce_linebreaks); } } // -------------------------------------------------------------------- /** * HTML Entities Decode * * This function is a replacement for html_entity_decode() * * @access public * @param string * @return string */ if ( ! function_exists('entity_decode')) { function entity_decode($str, $charset='UTF-8') { global $SEC; return $SEC->entity_decode($str, $charset); } } /* End of file typography_helper.php */ /* Location: ./system/helpers/typography_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/typography_helper.php
PHP
mit
2,239
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter HTML Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/html_helper.html */ // ------------------------------------------------------------------------ /** * Heading * * Generates an HTML heading tag. First param is the data. * Second param is the size of the heading tag. * * @access public * @param string * @param integer * @return string */ if ( ! function_exists('heading')) { function heading($data = '', $h = '1', $attributes = '') { $attributes = ($attributes != '') ? ' '.$attributes : $attributes; return "<h".$h.$attributes.">".$data."</h".$h.">"; } } // ------------------------------------------------------------------------ /** * Unordered List * * Generates an HTML unordered list from an single or multi-dimensional array. * * @access public * @param array * @param mixed * @return string */ if ( ! function_exists('ul')) { function ul($list, $attributes = '') { return _list('ul', $list, $attributes); } } // ------------------------------------------------------------------------ /** * Ordered List * * Generates an HTML ordered list from an single or multi-dimensional array. * * @access public * @param array * @param mixed * @return string */ if ( ! function_exists('ol')) { function ol($list, $attributes = '') { return _list('ol', $list, $attributes); } } // ------------------------------------------------------------------------ /** * Generates the list * * Generates an HTML ordered list from an single or multi-dimensional array. * * @access private * @param string * @param mixed * @param mixed * @param integer * @return string */ if ( ! function_exists('_list')) { function _list($type = 'ul', $list, $attributes = '', $depth = 0) { // If an array wasn't submitted there's nothing to do... if ( ! is_array($list)) { return $list; } // Set the indentation based on the depth $out = str_repeat(" ", $depth); // Were any attributes submitted? If so generate a string if (is_array($attributes)) { $atts = ''; foreach ($attributes as $key => $val) { $atts .= ' ' . $key . '="' . $val . '"'; } $attributes = $atts; } elseif (is_string($attributes) AND strlen($attributes) > 0) { $attributes = ' '. $attributes; } // Write the opening list tag $out .= "<".$type.$attributes.">\n"; // Cycle through the list elements. If an array is // encountered we will recursively call _list() static $_last_list_item = ''; foreach ($list as $key => $val) { $_last_list_item = $key; $out .= str_repeat(" ", $depth + 2); $out .= "<li>"; if ( ! is_array($val)) { $out .= $val; } else { $out .= $_last_list_item."\n"; $out .= _list($type, $val, '', $depth + 4); $out .= str_repeat(" ", $depth + 2); } $out .= "</li>\n"; } // Set the indentation for the closing tag $out .= str_repeat(" ", $depth); // Write the closing list tag $out .= "</".$type.">\n"; return $out; } } // ------------------------------------------------------------------------ /** * Generates HTML BR tags based on number supplied * * @access public * @param integer * @return string */ if ( ! function_exists('br')) { function br($num = 1) { return str_repeat("<br />", $num); } } // ------------------------------------------------------------------------ /** * Image * * Generates an <img /> element * * @access public * @param mixed * @return string */ if ( ! function_exists('img')) { function img($src = '', $index_page = FALSE) { if ( ! is_array($src) ) { $src = array('src' => $src); } // If there is no alt attribute defined, set it to an empty string if ( ! isset($src['alt'])) { $src['alt'] = ''; } $img = '<img'; foreach ($src as $k=>$v) { if ($k == 'src' AND strpos($v, '://') === FALSE) { $CI =& get_instance(); if ($index_page === TRUE) { $img .= ' src="'.$CI->config->site_url($v).'"'; } else { $img .= ' src="'.$CI->config->slash_item('base_url').$v.'"'; } } else { $img .= " $k=\"$v\""; } } $img .= '/>'; return $img; } } // ------------------------------------------------------------------------ /** * Doctype * * Generates a page document type declaration * * Valid options are xhtml-11, xhtml-strict, xhtml-trans, xhtml-frame, * html4-strict, html4-trans, and html4-frame. Values are saved in the * doctypes config file. * * @access public * @param string type The doctype to be generated * @return string */ if ( ! function_exists('doctype')) { function doctype($type = 'xhtml1-strict') { global $_doctypes; if ( ! is_array($_doctypes)) { if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'); } elseif (is_file(APPPATH.'config/doctypes.php')) { include(APPPATH.'config/doctypes.php'); } if ( ! is_array($_doctypes)) { return FALSE; } } if (isset($_doctypes[$type])) { return $_doctypes[$type]; } else { return FALSE; } } } // ------------------------------------------------------------------------ /** * Link * * Generates link to a CSS file * * @access public * @param mixed stylesheet hrefs or an array * @param string rel * @param string type * @param string title * @param string media * @param boolean should index_page be added to the css path * @return string */ if ( ! function_exists('link_tag')) { function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) { $CI =& get_instance(); $link = '<link '; if (is_array($href)) { foreach ($href as $k=>$v) { if ($k == 'href' AND strpos($v, '://') === FALSE) { if ($index_page === TRUE) { $link .= 'href="'.$CI->config->site_url($v).'" '; } else { $link .= 'href="'.$CI->config->slash_item('base_url').$v.'" '; } } else { $link .= "$k=\"$v\" "; } } $link .= "/>"; } else { if ( strpos($href, '://') !== FALSE) { $link .= 'href="'.$href.'" '; } elseif ($index_page === TRUE) { $link .= 'href="'.$CI->config->site_url($href).'" '; } else { $link .= 'href="'.$CI->config->slash_item('base_url').$href.'" '; } $link .= 'rel="'.$rel.'" type="'.$type.'" '; if ($media != '') { $link .= 'media="'.$media.'" '; } if ($title != '') { $link .= 'title="'.$title.'" '; } $link .= '/>'; } return $link; } } // ------------------------------------------------------------------------ /** * Generates meta tags from an array of key/values * * @access public * @param array * @return string */ if ( ! function_exists('meta')) { function meta($name = '', $content = '', $type = 'name', $newline = "\n") { // Since we allow the data to be passes as a string, a simple array // or a multidimensional one, we need to do a little prepping. if ( ! is_array($name)) { $name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline)); } else { // Turn single array into multidimensional if (isset($name['name'])) { $name = array($name); } } $str = ''; foreach ($name as $meta) { $type = ( ! isset($meta['type']) OR $meta['type'] == 'name') ? 'name' : 'http-equiv'; $name = ( ! isset($meta['name'])) ? '' : $meta['name']; $content = ( ! isset($meta['content'])) ? '' : $meta['content']; $newline = ( ! isset($meta['newline'])) ? "\n" : $meta['newline']; $str .= '<meta '.$type.'="'.$name.'" content="'.$content.'" />'.$newline; } return $str; } } // ------------------------------------------------------------------------ /** * Generates non-breaking space entities based on number supplied * * @access public * @param integer * @return string */ if ( ! function_exists('nbs')) { function nbs($num = 1) { return str_repeat("&nbsp;", $num); } } /* End of file html_helper.php */ /* Location: ./system/helpers/html_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/html_helper.php
PHP
mit
8,796
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Array Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/array_helper.html */ // ------------------------------------------------------------------------ /** * Element * * Lets you determine whether an array index is set and whether it has a value. * If the element is empty it returns FALSE (or whatever you specify as the default value.) * * @access public * @param string * @param array * @param mixed * @return mixed depends on what the array contains */ if ( ! function_exists('element')) { function element($item, $array, $default = FALSE) { if ( ! isset($array[$item]) OR $array[$item] == "") { return $default; } return $array[$item]; } } // ------------------------------------------------------------------------ /** * Random Element - Takes an array as input and returns a random element * * @access public * @param array * @return mixed depends on what the array contains */ if ( ! function_exists('random_element')) { function random_element($array) { if ( ! is_array($array)) { return $array; } return $array[array_rand($array)]; } } // -------------------------------------------------------------------- /** * Elements * * Returns only the array items specified. Will return a default value if * it is not set. * * @access public * @param array * @param array * @param mixed * @return mixed depends on what the array contains */ if ( ! function_exists('elements')) { function elements($items, $array, $default = FALSE) { $return = array(); if ( ! is_array($items)) { $items = array($items); } foreach ($items as $item) { if (isset($array[$item])) { $return[$item] = $array[$item]; } else { $return[$item] = $default; } } return $return; } } /* End of file array_helper.php */ /* Location: ./system/helpers/array_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/array_helper.php
PHP
mit
2,509
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter String Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/string_helper.html */ // ------------------------------------------------------------------------ /** * Trim Slashes * * Removes any leading/trailing slashes from a string: * * /this/that/theother/ * * becomes: * * this/that/theother * * @access public * @param string * @return string */ if ( ! function_exists('trim_slashes')) { function trim_slashes($str) { return trim($str, '/'); } } // ------------------------------------------------------------------------ /** * Strip Slashes * * Removes slashes contained in a string or in an array * * @access public * @param mixed string or array * @return mixed string or array */ if ( ! function_exists('strip_slashes')) { function strip_slashes($str) { if (is_array($str)) { foreach ($str as $key => $val) { $str[$key] = strip_slashes($val); } } else { $str = stripslashes($str); } return $str; } } // ------------------------------------------------------------------------ /** * Strip Quotes * * Removes single and double quotes from a string * * @access public * @param string * @return string */ if ( ! function_exists('strip_quotes')) { function strip_quotes($str) { return str_replace(array('"', "'"), '', $str); } } // ------------------------------------------------------------------------ /** * Quotes to Entities * * Converts single and double quotes to entities * * @access public * @param string * @return string */ if ( ! function_exists('quotes_to_entities')) { function quotes_to_entities($str) { return str_replace(array("\'","\"","'",'"'), array("&#39;","&quot;","&#39;","&quot;"), $str); } } // ------------------------------------------------------------------------ /** * Reduce Double Slashes * * Converts double slashes in a string to a single slash, * except those found in http:// * * http://www.some-site.com//index.php * * becomes: * * http://www.some-site.com/index.php * * @access public * @param string * @return string */ if ( ! function_exists('reduce_double_slashes')) { function reduce_double_slashes($str) { return preg_replace("#(^|[^:])//+#", "\\1/", $str); } } // ------------------------------------------------------------------------ /** * Reduce Multiples * * Reduces multiple instances of a particular character. Example: * * Fred, Bill,, Joe, Jimmy * * becomes: * * Fred, Bill, Joe, Jimmy * * @access public * @param string * @param string the character you wish to reduce * @param bool TRUE/FALSE - whether to trim the character from the beginning/end * @return string */ if ( ! function_exists('reduce_multiples')) { function reduce_multiples($str, $character = ',', $trim = FALSE) { $str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str); if ($trim === TRUE) { $str = trim($str, $character); } return $str; } } // ------------------------------------------------------------------------ /** * Create a Random String * * Useful for generating passwords or hashes. * * @access public * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1 * @param integer number of characters * @return string */ if ( ! function_exists('random_string')) { function random_string($type = 'alnum', $len = 8) { switch($type) { case 'basic' : return mt_rand(); break; case 'alnum' : case 'numeric' : case 'nozero' : case 'alpha' : switch ($type) { case 'alpha' : $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'numeric' : $pool = '0123456789'; break; case 'nozero' : $pool = '123456789'; break; } $str = ''; for ($i=0; $i < $len; $i++) { $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } return $str; break; case 'unique' : case 'md5' : return md5(uniqid(mt_rand())); break; case 'encrypt' : case 'sha1' : $CI =& get_instance(); $CI->load->helper('security'); return do_hash(uniqid(mt_rand(), TRUE), 'sha1'); break; } } } // ------------------------------------------------------------------------ /** * Add's _1 to a string or increment the ending number to allow _2, _3, etc * * @param string $str required * @param string $separator What should the duplicate number be appended with * @param string $first Which number should be used for the first dupe increment * @return string */ function increment_string($str, $separator = '_', $first = 1) { preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match); return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first; } // ------------------------------------------------------------------------ /** * Alternator * * Allows strings to be alternated. See docs... * * @access public * @param string (as many parameters as needed) * @return string */ if ( ! function_exists('alternator')) { function alternator() { static $i; if (func_num_args() == 0) { $i = 0; return ''; } $args = func_get_args(); return $args[($i++ % count($args))]; } } // ------------------------------------------------------------------------ /** * Repeater function * * @access public * @param string * @param integer number of repeats * @return string */ if ( ! function_exists('repeater')) { function repeater($data, $num = 1) { return (($num > 0) ? str_repeat($data, $num) : ''); } } /* End of file string_helper.php */ /* Location: ./system/helpers/string_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/string_helper.php
PHP
mit
6,433
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Smiley Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/smiley_helper.html */ // ------------------------------------------------------------------------ /** * Smiley Javascript * * Returns the javascript required for the smiley insertion. Optionally takes * an array of aliases to loosely couple the smiley array to the view. * * @access public * @param mixed alias name or array of alias->field_id pairs * @param string field_id if alias name was passed in * @return array */ if ( ! function_exists('smiley_js')) { function smiley_js($alias = '', $field_id = '', $inline = TRUE) { static $do_setup = TRUE; $r = ''; if ($alias != '' && ! is_array($alias)) { $alias = array($alias => $field_id); } if ($do_setup === TRUE) { $do_setup = FALSE; $m = array(); if (is_array($alias)) { foreach ($alias as $name => $id) { $m[] = '"'.$name.'" : "'.$id.'"'; } } $m = '{'.implode(',', $m).'}'; $r .= <<<EOF var smiley_map = {$m}; function insert_smiley(smiley, field_id) { var el = document.getElementById(field_id), newStart; if ( ! el && smiley_map[field_id]) { el = document.getElementById(smiley_map[field_id]); if ( ! el) return false; } el.focus(); smiley = " " + smiley; if ('selectionStart' in el) { newStart = el.selectionStart + smiley.length; el.value = el.value.substr(0, el.selectionStart) + smiley + el.value.substr(el.selectionEnd, el.value.length); el.setSelectionRange(newStart, newStart); } else if (document.selection) { document.selection.createRange().text = smiley; } } EOF; } else { if (is_array($alias)) { foreach ($alias as $name => $id) { $r .= 'smiley_map["'.$name.'"] = "'.$id.'";'."\n"; } } } if ($inline) { return '<script type="text/javascript" charset="utf-8">/*<![CDATA[ */'.$r.'// ]]></script>'; } else { return $r; } } } // ------------------------------------------------------------------------ /** * Get Clickable Smileys * * Returns an array of image tag links that can be clicked to be inserted * into a form field. * * @access public * @param string the URL to the folder containing the smiley images * @return array */ if ( ! function_exists('get_clickable_smileys')) { function get_clickable_smileys($image_url, $alias = '', $smileys = NULL) { // For backward compatibility with js_insert_smiley if (is_array($alias)) { $smileys = $alias; } if ( ! is_array($smileys)) { if (FALSE === ($smileys = _get_smiley_array())) { return $smileys; } } // Add a trailing slash to the file path if needed $image_url = rtrim($image_url, '/').'/'; $used = array(); foreach ($smileys as $key => $val) { // Keep duplicates from being used, which can happen if the // mapping array contains multiple identical replacements. For example: // :-) and :) might be replaced with the same image so both smileys // will be in the array. if (isset($used[$smileys[$key][0]])) { continue; } $link[] = "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('".$key."', '".$alias."')\"><img src=\"".$image_url.$smileys[$key][0]."\" width=\"".$smileys[$key][1]."\" height=\"".$smileys[$key][2]."\" alt=\"".$smileys[$key][3]."\" style=\"border:0;\" /></a>"; $used[$smileys[$key][0]] = TRUE; } return $link; } } // ------------------------------------------------------------------------ /** * Parse Smileys * * Takes a string as input and swaps any contained smileys for the actual image * * @access public * @param string the text to be parsed * @param string the URL to the folder containing the smiley images * @return string */ if ( ! function_exists('parse_smileys')) { function parse_smileys($str = '', $image_url = '', $smileys = NULL) { if ($image_url == '') { return $str; } if ( ! is_array($smileys)) { if (FALSE === ($smileys = _get_smiley_array())) { return $str; } } // Add a trailing slash to the file path if needed $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url); foreach ($smileys as $key => $val) { $str = str_replace($key, "<img src=\"".$image_url.$smileys[$key][0]."\" width=\"".$smileys[$key][1]."\" height=\"".$smileys[$key][2]."\" alt=\"".$smileys[$key][3]."\" style=\"border:0;\" />", $str); } return $str; } } // ------------------------------------------------------------------------ /** * Get Smiley Array * * Fetches the config/smiley.php file * * @access private * @return mixed */ if ( ! function_exists('_get_smiley_array')) { function _get_smiley_array() { if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'); } elseif (file_exists(APPPATH.'config/smileys.php')) { include(APPPATH.'config/smileys.php'); } if (isset($smileys) AND is_array($smileys)) { return $smileys; } return FALSE; } } // ------------------------------------------------------------------------ /** * JS Insert Smiley * * Generates the javascript function needed to insert smileys into a form field * * DEPRECATED as of version 1.7.2, use smiley_js instead * * @access public * @param string form name * @param string field name * @return string */ if ( ! function_exists('js_insert_smiley')) { function js_insert_smiley($form_name = '', $form_field = '') { return <<<EOF <script type="text/javascript"> function insert_smiley(smiley) { document.{$form_name}.{$form_field}.value += " " + smiley; } </script> EOF; } } /* End of file smiley_helper.php */ /* Location: ./system/helpers/smiley_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/smiley_helper.php
PHP
mit
6,466
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Download Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/download_helper.html */ // ------------------------------------------------------------------------ /** * Force Download * * Generates headers that force a download to happen * * @access public * @param string filename * @param mixed the data to be downloaded * @return void */ if ( ! function_exists('force_download')) { function force_download($filename = '', $data = '') { if ($filename == '' OR $data == '') { return FALSE; } // Try to determine if the filename includes a file extension. // We need it in order to set the MIME type if (FALSE === strpos($filename, '.')) { return FALSE; } // Grab the file extension $x = explode('.', $filename); $extension = end($x); // Load the mime types if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); } elseif (is_file(APPPATH.'config/mimes.php')) { include(APPPATH.'config/mimes.php'); } // Set a default mime if we can't find it if ( ! isset($mimes[$extension])) { $mime = 'application/octet-stream'; } else { $mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension]; } // Generate the server headers if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE) { header('Content-Type: "'.$mime.'"'); header('Content-Disposition: attachment; filename="'.$filename.'"'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header("Content-Transfer-Encoding: binary"); header('Pragma: public'); header("Content-Length: ".strlen($data)); } else { header('Content-Type: "'.$mime.'"'); header('Content-Disposition: attachment; filename="'.$filename.'"'); header("Content-Transfer-Encoding: binary"); header('Expires: 0'); header('Pragma: no-cache'); header("Content-Length: ".strlen($data)); } ob_clean(); flush(); exit($data); } } /* End of file download_helper.php */ /* Location: ./system/helpers/download_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/download_helper.php
PHP
mit
2,772
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter XML Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/xml_helper.html */ // ------------------------------------------------------------------------ /** * Convert Reserved XML characters to Entities * * @access public * @param string * @return string */ if ( ! function_exists('xml_convert')) { function xml_convert($str, $protect_all = FALSE) { $temp = '__TEMP_AMPERSANDS__'; // Replace entities to temporary markers so that // ampersands won't get messed up $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); if ($protect_all === TRUE) { $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); } $str = str_replace(array("&","<",">","\"", "'", "-"), array("&amp;", "&lt;", "&gt;", "&quot;", "&apos;", "&#45;"), $str); // Decode the temp markers back to entities $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); if ($protect_all === TRUE) { $str = preg_replace("/$temp(\w+);/","&\\1;", $str); } return $str; } } // ------------------------------------------------------------------------ /* End of file xml_helper.php */ /* Location: ./system/helpers/xml_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/xml_helper.php
PHP
mit
1,788
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter Text Helpers * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/text_helper.html */ // ------------------------------------------------------------------------ /** * Word Limiter * * Limits a string to X number of words. * * @access public * @param string * @param integer * @param string the end character. Usually an ellipsis * @return string */ if ( ! function_exists('word_limiter')) { function word_limiter($str, $limit = 100, $end_char = '&#8230;') { if (trim($str) == '') { return $str; } preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $str, $matches); if (strlen($str) == strlen($matches[0])) { $end_char = ''; } return rtrim($matches[0]).$end_char; } } // ------------------------------------------------------------------------ /** * Character Limiter * * Limits the string based on the character count. Preserves complete words * so the character count may not be exactly as specified. * * @access public * @param string * @param integer * @param string the end character. Usually an ellipsis * @return string */ if ( ! function_exists('character_limiter')) { function character_limiter($str, $n = 500, $end_char = '&#8230;') { if (strlen($str) < $n) { return $str; } $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); if (strlen($str) <= $n) { return $str; } $out = ""; foreach (explode(' ', trim($str)) as $val) { $out .= $val.' '; if (strlen($out) >= $n) { $out = trim($out); return (strlen($out) == strlen($str)) ? $out : $out.$end_char; } } } } // ------------------------------------------------------------------------ /** * High ASCII to Entities * * Converts High ascii text and MS Word special characters to character entities * * @access public * @param string * @return string */ if ( ! function_exists('ascii_to_entities')) { function ascii_to_entities($str) { $count = 1; $out = ''; $temp = array(); for ($i = 0, $s = strlen($str); $i < $s; $i++) { $ordinal = ord($str[$i]); if ($ordinal < 128) { /* If the $temp array has a value but we have moved on, then it seems only fair that we output that entity and restart $temp before continuing. -Paul */ if (count($temp) == 1) { $out .= '&#'.array_shift($temp).';'; $count = 1; } $out .= $str[$i]; } else { if (count($temp) == 0) { $count = ($ordinal < 224) ? 2 : 3; } $temp[] = $ordinal; if (count($temp) == $count) { $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); $out .= '&#'.$number.';'; $count = 1; $temp = array(); } } } return $out; } } // ------------------------------------------------------------------------ /** * Entities to ASCII * * Converts character entities back to ASCII * * @access public * @param string * @param bool * @return string */ if ( ! function_exists('entities_to_ascii')) { function entities_to_ascii($str, $all = TRUE) { if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) { for ($i = 0, $s = count($matches['0']); $i < $s; $i++) { $digits = $matches['1'][$i]; $out = ''; if ($digits < 128) { $out .= chr($digits); } elseif ($digits < 2048) { $out .= chr(192 + (($digits - ($digits % 64)) / 64)); $out .= chr(128 + ($digits % 64)); } else { $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); $out .= chr(128 + ($digits % 64)); } $str = str_replace($matches['0'][$i], $out, $str); } } if ($all) { $str = str_replace(array("&amp;", "&lt;", "&gt;", "&quot;", "&apos;", "&#45;"), array("&","<",">","\"", "'", "-"), $str); } return $str; } } // ------------------------------------------------------------------------ /** * Word Censoring Function * * Supply a string and an array of disallowed words and any * matched words will be converted to #### or to the replacement * word you've submitted. * * @access public * @param string the text string * @param string the array of censoered words * @param string the optional replacement value * @return string */ if ( ! function_exists('word_censor')) { function word_censor($str, $censored, $replacement = '') { if ( ! is_array($censored)) { return $str; } $str = ' '.$str.' '; // \w, \b and a few others do not match on a unicode character // set for performance reasons. As a result words like über // will not match on a word boundary. Instead, we'll assume that // a bad word will be bookeneded by any of these characters. $delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]'; foreach ($censored as $badword) { if ($replacement != '') { $str = preg_replace("/({$delim})(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")({$delim})/i", "\\1{$replacement}\\3", $str); } else { $str = preg_replace("/({$delim})(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")({$delim})/ie", "'\\1'.str_repeat('#', strlen('\\2')).'\\3'", $str); } } return trim($str); } } // ------------------------------------------------------------------------ /** * Code Highlighter * * Colorizes code strings * * @access public * @param string the text string * @return string */ if ( ! function_exists('highlight_code')) { function highlight_code($str) { // The highlight string function encodes and highlights // brackets so we need them to start raw $str = str_replace(array('&lt;', '&gt;'), array('<', '>'), $str); // Replace any existing PHP tags to temporary markers so they don't accidentally // break the string out of PHP, and thus, thwart the highlighting. $str = str_replace(array('<?', '?>', '<%', '%>', '\\', '</script>'), array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str); // The highlight_string function requires that the text be surrounded // by PHP tags, which we will remove later $str = '<?php '.$str.' ?>'; // <? // All the magic happens here, baby! $str = highlight_string($str, TRUE); // Prior to PHP 5, the highligh function used icky <font> tags // so we'll replace them with <span> tags. if (abs(PHP_VERSION) < 5) { $str = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $str); $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); } // Remove our artificially added PHP, and the syntax highlighting that came with it $str = preg_replace('/<span style="color: #([A-Z0-9]+)">&lt;\?php(&nbsp;| )/i', '<span style="color: #$1">', $str); $str = preg_replace('/(<span style="color: #[A-Z0-9]+">.*?)\?&gt;<\/span>\n<\/span>\n<\/code>/is', "$1</span>\n</span>\n</code>", $str); $str = preg_replace('/<span style="color: #[A-Z0-9]+"\><\/span>/i', '', $str); // Replace our markers back to PHP tags. $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), array('&lt;?', '?&gt;', '&lt;%', '%&gt;', '\\', '&lt;/script&gt;'), $str); return $str; } } // ------------------------------------------------------------------------ /** * Phrase Highlighter * * Highlights a phrase within a text string * * @access public * @param string the text string * @param string the phrase you'd like to highlight * @param string the openging tag to precede the phrase with * @param string the closing tag to end the phrase with * @return string */ if ( ! function_exists('highlight_phrase')) { function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '</strong>') { if ($str == '') { return ''; } if ($phrase != '') { return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str); } return $str; } } // ------------------------------------------------------------------------ /** * Convert Accented Foreign Characters to ASCII * * @access public * @param string the text string * @return string */ if ( ! function_exists('convert_accented_characters')) { function convert_accented_characters($str) { if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'); } elseif (is_file(APPPATH.'config/foreign_chars.php')) { include(APPPATH.'config/foreign_chars.php'); } if ( ! isset($foreign_characters)) { return $str; } return preg_replace(array_keys($foreign_characters), array_values($foreign_characters), $str); } } // ------------------------------------------------------------------------ /** * Word Wrap * * Wraps text at the specified character. Maintains the integrity of words. * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor * will URLs. * * @access public * @param string the text string * @param integer the number of characters to wrap at * @return string */ if ( ! function_exists('word_wrap')) { function word_wrap($str, $charlim = '76') { // Se the character limit if ( ! is_numeric($charlim)) $charlim = 76; // Reduce multiple spaces $str = preg_replace("| +|", " ", $str); // Standardize newlines if (strpos($str, "\r") !== FALSE) { $str = str_replace(array("\r\n", "\r"), "\n", $str); } // If the current word is surrounded by {unwrap} tags we'll // strip the entire chunk and replace it with a marker. $unwrap = array(); if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches)) { for ($i = 0; $i < count($matches['0']); $i++) { $unwrap[] = $matches['1'][$i]; $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); } } // Use PHP's native function to do the initial wordwrap. // We set the cut flag to FALSE so that any individual words that are // too long get left alone. In the next step we'll deal with them. $str = wordwrap($str, $charlim, "\n", FALSE); // Split the string into individual lines of text and cycle through them $output = ""; foreach (explode("\n", $str) as $line) { // Is the line within the allowed character count? // If so we'll join it to the output and continue if (strlen($line) <= $charlim) { $output .= $line."\n"; continue; } $temp = ''; while ((strlen($line)) > $charlim) { // If the over-length word is a URL we won't wrap it if (preg_match("!\[url.+\]|://|wwww.!", $line)) { break; } // Trim the word down $temp .= substr($line, 0, $charlim-1); $line = substr($line, $charlim-1); } // If $temp contains data it means we had to split up an over-length // word into smaller chunks so we'll add it back to our current line if ($temp != '') { $output .= $temp."\n".$line; } else { $output .= $line; } $output .= "\n"; } // Put our markers back if (count($unwrap) > 0) { foreach ($unwrap as $key => $val) { $output = str_replace("{{unwrapped".$key."}}", $val, $output); } } // Remove the unwrap tags $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output); return $output; } } // ------------------------------------------------------------------------ /** * Ellipsize String * * This function will strip tags from a string, split it at its max_length and ellipsize * * @param string string to ellipsize * @param integer max length of string * @param mixed int (1|0) or float, .5, .2, etc for position to split * @param string ellipsis ; Default '...' * @return string ellipsized string */ if ( ! function_exists('ellipsize')) { function ellipsize($str, $max_length, $position = 1, $ellipsis = '&hellip;') { // Strip tags $str = trim(strip_tags($str)); // Is the string long enough to ellipsize? if (strlen($str) <= $max_length) { return $str; } $beg = substr($str, 0, floor($max_length * $position)); $position = ($position > 1) ? 1 : $position; if ($position === 1) { $end = substr($str, 0, -($max_length - strlen($beg))); } else { $end = substr($str, -($max_length - strlen($beg))); } return $beg.$ellipsis.$end; } } /* End of file text_helper.php */ /* Location: ./system/helpers/text_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/text_helper.php
PHP
mit
13,134
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * CodeIgniter CAPTCHA Helper * * @package CodeIgniter * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/helpers/xml_helper.html */ // ------------------------------------------------------------------------ /** * Create CAPTCHA * * @access public * @param array array of data for the CAPTCHA * @param string path to create the image in * @param string URL to the CAPTCHA image folder * @param string server path to font * @return string */ if ( ! function_exists('create_captcha')) { function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '') { $defaults = array('word' => '', 'img_path' => '', 'img_url' => '', 'img_width' => '150', 'img_height' => '30', 'font_path' => '', 'expiration' => 7200); foreach ($defaults as $key => $val) { if ( ! is_array($data)) { if ( ! isset($$key) OR $$key == '') { $$key = $val; } } else { $$key = ( ! isset($data[$key])) ? $val : $data[$key]; } } if ($img_path == '' OR $img_url == '') { return FALSE; } if ( ! @is_dir($img_path)) { return FALSE; } if ( ! is_writable($img_path)) { return FALSE; } if ( ! extension_loaded('gd')) { return FALSE; } // ----------------------------------- // Remove old images // ----------------------------------- list($usec, $sec) = explode(" ", microtime()); $now = ((float)$usec + (float)$sec); $current_dir = @opendir($img_path); while ($filename = @readdir($current_dir)) { if ($filename != "." and $filename != ".." and $filename != "index.html") { $name = str_replace(".jpg", "", $filename); if (($name + $expiration) < $now) { @unlink($img_path.$filename); } } } @closedir($current_dir); // ----------------------------------- // Do we have a "word" yet? // ----------------------------------- if ($word == '') { $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $str = ''; for ($i = 0; $i < 8; $i++) { $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } $word = $str; } // ----------------------------------- // Determine angle and position // ----------------------------------- $length = strlen($word); $angle = ($length >= 6) ? rand(-($length-6), ($length-6)) : 0; $x_axis = rand(6, (360/$length)-16); $y_axis = ($angle >= 0 ) ? rand($img_height, $img_width) : rand(6, $img_height); // ----------------------------------- // Create image // ----------------------------------- // PHP.net recommends imagecreatetruecolor(), but it isn't always available if (function_exists('imagecreatetruecolor')) { $im = imagecreatetruecolor($img_width, $img_height); } else { $im = imagecreate($img_width, $img_height); } // ----------------------------------- // Assign colors // ----------------------------------- $bg_color = imagecolorallocate ($im, 255, 255, 255); $border_color = imagecolorallocate ($im, 153, 102, 102); $text_color = imagecolorallocate ($im, 204, 153, 153); $grid_color = imagecolorallocate($im, 255, 182, 182); $shadow_color = imagecolorallocate($im, 255, 240, 240); // ----------------------------------- // Create the rectangle // ----------------------------------- ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg_color); // ----------------------------------- // Create the spiral pattern // ----------------------------------- $theta = 1; $thetac = 7; $radius = 16; $circles = 20; $points = 32; for ($i = 0; $i < ($circles * $points) - 1; $i++) { $theta = $theta + $thetac; $rad = $radius * ($i / $points ); $x = ($rad * cos($theta)) + $x_axis; $y = ($rad * sin($theta)) + $y_axis; $theta = $theta + $thetac; $rad1 = $radius * (($i + 1) / $points); $x1 = ($rad1 * cos($theta)) + $x_axis; $y1 = ($rad1 * sin($theta )) + $y_axis; imageline($im, $x, $y, $x1, $y1, $grid_color); $theta = $theta - $thetac; } // ----------------------------------- // Write the text // ----------------------------------- $use_font = ($font_path != '' AND file_exists($font_path) AND function_exists('imagettftext')) ? TRUE : FALSE; if ($use_font == FALSE) { $font_size = 5; $x = rand(0, $img_width/($length/3)); $y = 0; } else { $font_size = 16; $x = rand(0, $img_width/($length/1.5)); $y = $font_size+2; } for ($i = 0; $i < strlen($word); $i++) { if ($use_font == FALSE) { $y = rand(0 , $img_height/2); imagestring($im, $font_size, $x, $y, substr($word, $i, 1), $text_color); $x += ($font_size*2); } else { $y = rand($img_height/2, $img_height-3); imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, substr($word, $i, 1)); $x += $font_size; } } // ----------------------------------- // Create the border // ----------------------------------- imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color); // ----------------------------------- // Generate the image // ----------------------------------- $img_name = $now.'.jpg'; ImageJPEG($im, $img_path.$img_name); $img = "<img src=\"$img_url$img_name\" width=\"$img_width\" height=\"$img_height\" style=\"border:0;\" alt=\" \" />"; ImageDestroy($im); return array('word' => $word, 'time' => $now, 'image' => $img); } } // ------------------------------------------------------------------------ /* End of file captcha_helper.php */ /* Location: ./system/heleprs/captcha_helper.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/helpers/captcha_helper.php
PHP
mit
6,169
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/system/database/index.html
HTML
mit
114
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * Database Cache Class * * @category Database * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_Cache { var $CI; var $db; // allows passing of db object so that multiple database connections and returned db objects can be supported /** * Constructor * * Grabs the CI super object instance so we can access it. * */ function __construct(&$db) { // Assign the main CI object to $this->CI // and load the file helper since we use it a lot $this->CI =& get_instance(); $this->db =& $db; $this->CI->load->helper('file'); } // -------------------------------------------------------------------- /** * Set Cache Directory Path * * @access public * @param string the path to the cache directory * @return bool */ function check_path($path = '') { if ($path == '') { if ($this->db->cachedir == '') { return $this->db->cache_off(); } $path = $this->db->cachedir; } // Add a trailing slash to the path if needed $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); if ( ! is_dir($path) OR ! is_really_writable($path)) { // If the path is wrong we'll turn off caching return $this->db->cache_off(); } $this->db->cachedir = $path; return TRUE; } // -------------------------------------------------------------------- /** * Retrieve a cached query * * The URI being requested will become the name of the cache sub-folder. * An MD5 hash of the SQL statement will become the cache file name * * @access public * @return string */ function read($sql) { if ( ! $this->check_path()) { return $this->db->cache_off(); } $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); $filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql); if (FALSE === ($cachedata = read_file($filepath))) { return FALSE; } return unserialize($cachedata); } // -------------------------------------------------------------------- /** * Write a query to a cache file * * @access public * @return bool */ function write($sql, $object) { if ( ! $this->check_path()) { return $this->db->cache_off(); } $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; $filename = md5($sql); if ( ! @is_dir($dir_path)) { if ( ! @mkdir($dir_path, DIR_WRITE_MODE)) { return FALSE; } @chmod($dir_path, DIR_WRITE_MODE); } if (write_file($dir_path.$filename, serialize($object)) === FALSE) { return FALSE; } @chmod($dir_path.$filename, FILE_WRITE_MODE); return TRUE; } // -------------------------------------------------------------------- /** * Delete cache files within a particular directory * * @access public * @return bool */ function delete($segment_one = '', $segment_two = '') { if ($segment_one == '') { $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); } if ($segment_two == '') { $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); } $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; delete_files($dir_path, TRUE); } // -------------------------------------------------------------------- /** * Delete all existing cache files * * @access public * @return bool */ function delete_all() { delete_files($this->db->cachedir, TRUE); } } /* End of file DB_cache.php */ /* Location: ./system/database/DB_cache.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/database/DB_cache.php
PHP
mit
4,378
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * Code Igniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * Database Utility Class * * @category Database * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_utility extends CI_DB_forge { var $db; var $data_cache = array(); /** * Constructor * * Grabs the CI super object instance so we can access it. * */ function __construct() { // Assign the main database object to $this->db $CI =& get_instance(); $this->db =& $CI->db; log_message('debug', "Database Utility Class Initialized"); } // -------------------------------------------------------------------- /** * List databases * * @access public * @return bool */ function list_databases() { // Is there a cached result? if (isset($this->data_cache['db_names'])) { return $this->data_cache['db_names']; } $query = $this->db->query($this->_list_databases()); $dbs = array(); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) { $dbs[] = current($row); } } $this->data_cache['db_names'] = $dbs; return $this->data_cache['db_names']; } // -------------------------------------------------------------------- /** * Determine if a particular database exists * * @access public * @param string * @return boolean */ function database_exists($database_name) { // Some databases won't have access to the list_databases() function, so // this is intended to allow them to override with their own functions as // defined in $driver_utility.php if (method_exists($this, '_database_exists')) { return $this->_database_exists($database_name); } else { return ( ! in_array($database_name, $this->list_databases())) ? FALSE : TRUE; } } // -------------------------------------------------------------------- /** * Optimize Table * * @access public * @param string the table name * @return bool */ function optimize_table($table_name) { $sql = $this->_optimize_table($table_name); if (is_bool($sql)) { show_error('db_must_use_set'); } $query = $this->db->query($sql); $res = $query->result_array(); // Note: Due to a bug in current() that affects some versions // of PHP we can not pass function call directly into it return current($res); } // -------------------------------------------------------------------- /** * Optimize Database * * @access public * @return array */ function optimize_database() { $result = array(); foreach ($this->db->list_tables() as $table_name) { $sql = $this->_optimize_table($table_name); if (is_bool($sql)) { return $sql; } $query = $this->db->query($sql); // Build the result array... // Note: Due to a bug in current() that affects some versions // of PHP we can not pass function call directly into it $res = $query->result_array(); $res = current($res); $key = str_replace($this->db->database.'.', '', current($res)); $keys = array_keys($res); unset($res[$keys[0]]); $result[$key] = $res; } return $result; } // -------------------------------------------------------------------- /** * Repair Table * * @access public * @param string the table name * @return bool */ function repair_table($table_name) { $sql = $this->_repair_table($table_name); if (is_bool($sql)) { return $sql; } $query = $this->db->query($sql); // Note: Due to a bug in current() that affects some versions // of PHP we can not pass function call directly into it $res = $query->result_array(); return current($res); } // -------------------------------------------------------------------- /** * Generate CSV from a query result object * * @access public * @param object The query result object * @param string The delimiter - comma by default * @param string The newline character - \n by default * @param string The enclosure - double quote by default * @return string */ function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"') { if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) { show_error('You must submit a valid result object'); } $out = ''; // First generate the headings from the table column names foreach ($query->list_fields() as $name) { $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim; } $out = rtrim($out); $out .= $newline; // Next blast through the result array and build out the rows foreach ($query->result_array() as $row) { foreach ($row as $item) { $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim; } $out = rtrim($out); $out .= $newline; } return $out; } // -------------------------------------------------------------------- /** * Generate XML data from a query result object * * @access public * @param object The query result object * @param array Any preferences * @return string */ function xml_from_result($query, $params = array()) { if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) { show_error('You must submit a valid result object'); } // Set our default values foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) { if ( ! isset($params[$key])) { $params[$key] = $val; } } // Create variables for convenience extract($params); // Load the xml helper $CI =& get_instance(); $CI->load->helper('xml'); // Generate the result $xml = "<{$root}>".$newline; foreach ($query->result_array() as $row) { $xml .= $tab."<{$element}>".$newline; foreach ($row as $key => $val) { $xml .= $tab.$tab."<{$key}>".xml_convert($val)."</{$key}>".$newline; } $xml .= $tab."</{$element}>".$newline; } $xml .= "</$root>".$newline; return $xml; } // -------------------------------------------------------------------- /** * Database Backup * * @access public * @return void */ function backup($params = array()) { // If the parameters have not been submitted as an // array then we know that it is simply the table // name, which is a valid short cut. if (is_string($params)) { $params = array('tables' => $params); } // ------------------------------------------------------ // Set up our default preferences $prefs = array( 'tables' => array(), 'ignore' => array(), 'filename' => '', 'format' => 'gzip', // gzip, zip, txt 'add_drop' => TRUE, 'add_insert' => TRUE, 'newline' => "\n" ); // Did the user submit any preferences? If so set them.... if (count($params) > 0) { foreach ($prefs as $key => $val) { if (isset($params[$key])) { $prefs[$key] = $params[$key]; } } } // ------------------------------------------------------ // Are we backing up a complete database or individual tables? // If no table names were submitted we'll fetch the entire table list if (count($prefs['tables']) == 0) { $prefs['tables'] = $this->db->list_tables(); } // ------------------------------------------------------ // Validate the format if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) { $prefs['format'] = 'txt'; } // ------------------------------------------------------ // Is the encoder supported? If not, we'll either issue an // error or use plain text depending on the debug settings if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) { if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_compression'); } $prefs['format'] = 'txt'; } // ------------------------------------------------------ // Set the filename if not provided - Only needed with Zip files if ($prefs['filename'] == '' AND $prefs['format'] == 'zip') { $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database; $prefs['filename'] .= '_'.date('Y-m-d_H-i', time()); } // ------------------------------------------------------ // Was a Gzip file requested? if ($prefs['format'] == 'gzip') { return gzencode($this->_backup($prefs)); } // ------------------------------------------------------ // Was a text file requested? if ($prefs['format'] == 'txt') { return $this->_backup($prefs); } // ------------------------------------------------------ // Was a Zip file requested? if ($prefs['format'] == 'zip') { // If they included the .zip file extension we'll remove it if (preg_match("|.+?\.zip$|", $prefs['filename'])) { $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); } // Tack on the ".sql" file extension if needed if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) { $prefs['filename'] .= '.sql'; } // Load the Zip class and output it $CI =& get_instance(); $CI->load->library('zip'); $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); return $CI->zip->get_zip(); } } } /* End of file DB_utility.php */ /* Location: ./system/database/DB_utility.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/database/DB_utility.php
PHP
mit
9,805
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * Code Igniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * Database Utility Class * * @category Database * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_forge { var $fields = array(); var $keys = array(); var $primary_keys = array(); var $db_char_set = ''; /** * Constructor * * Grabs the CI super object instance so we can access it. * */ function __construct() { // Assign the main database object to $this->db $CI =& get_instance(); $this->db =& $CI->db; log_message('debug', "Database Forge Class Initialized"); } // -------------------------------------------------------------------- /** * Create database * * @access public * @param string the database name * @return bool */ function create_database($db_name) { $sql = $this->_create_database($db_name); if (is_bool($sql)) { return $sql; } return $this->db->query($sql); } // -------------------------------------------------------------------- /** * Drop database * * @access public * @param string the database name * @return bool */ function drop_database($db_name) { $sql = $this->_drop_database($db_name); if (is_bool($sql)) { return $sql; } return $this->db->query($sql); } // -------------------------------------------------------------------- /** * Add Key * * @access public * @param string key * @param string type * @return void */ function add_key($key = '', $primary = FALSE) { if (is_array($key)) { foreach ($key as $one) { $this->add_key($one, $primary); } return; } if ($key == '') { show_error('Key information is required for that operation.'); } if ($primary === TRUE) { $this->primary_keys[] = $key; } else { $this->keys[] = $key; } } // -------------------------------------------------------------------- /** * Add Field * * @access public * @param string collation * @return void */ function add_field($field = '') { if ($field == '') { show_error('Field information is required.'); } if (is_string($field)) { if ($field == 'id') { $this->add_field(array( 'id' => array( 'type' => 'INT', 'constraint' => 9, 'auto_increment' => TRUE ) )); $this->add_key('id', TRUE); } else { if (strpos($field, ' ') === FALSE) { show_error('Field information is required for that operation.'); } $this->fields[] = $field; } } if (is_array($field)) { $this->fields = array_merge($this->fields, $field); } } // -------------------------------------------------------------------- /** * Create Table * * @access public * @param string the table name * @return bool */ function create_table($table = '', $if_not_exists = FALSE) { if ($table == '') { show_error('A table name is required for that operation.'); } if (count($this->fields) == 0) { show_error('Field information is required.'); } $sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists); $this->_reset(); return $this->db->query($sql); } // -------------------------------------------------------------------- /** * Drop Table * * @access public * @param string the table name * @return bool */ function drop_table($table_name) { $sql = $this->_drop_table($this->db->dbprefix.$table_name); if (is_bool($sql)) { return $sql; } return $this->db->query($sql); } // -------------------------------------------------------------------- /** * Rename Table * * @access public * @param string the old table name * @param string the new table name * @return bool */ function rename_table($table_name, $new_table_name) { if ($table_name == '' OR $new_table_name == '') { show_error('A table name is required for that operation.'); } $sql = $this->_rename_table($this->db->dbprefix.$table_name, $this->db->dbprefix.$new_table_name); return $this->db->query($sql); } // -------------------------------------------------------------------- /** * Column Add * * @access public * @param string the table name * @param string the column name * @param string the column definition * @return bool */ function add_column($table = '', $field = array(), $after_field = '') { if ($table == '') { show_error('A table name is required for that operation.'); } // add field info into field array, but we can only do one at a time // so we cycle through foreach ($field as $k => $v) { $this->add_field(array($k => $field[$k])); if (count($this->fields) == 0) { show_error('Field information is required.'); } $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field); $this->_reset(); if ($this->db->query($sql) === FALSE) { return FALSE; } } return TRUE; } // -------------------------------------------------------------------- /** * Column Drop * * @access public * @param string the table name * @param string the column name * @return bool */ function drop_column($table = '', $column_name = '') { if ($table == '') { show_error('A table name is required for that operation.'); } if ($column_name == '') { show_error('A column name is required for that operation.'); } $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name); return $this->db->query($sql); } // -------------------------------------------------------------------- /** * Column Modify * * @access public * @param string the table name * @param string the column name * @param string the column definition * @return bool */ function modify_column($table = '', $field = array()) { if ($table == '') { show_error('A table name is required for that operation.'); } // add field info into field array, but we can only do one at a time // so we cycle through foreach ($field as $k => $v) { // If no name provided, use the current name if ( ! isset($field[$k]['name'])) { $field[$k]['name'] = $k; } $this->add_field(array($k => $field[$k])); if (count($this->fields) == 0) { show_error('Field information is required.'); } $sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields); $this->_reset(); if ($this->db->query($sql) === FALSE) { return FALSE; } } return TRUE; } // -------------------------------------------------------------------- /** * Reset * * Resets table creation vars * * @access private * @return void */ function _reset() { $this->fields = array(); $this->keys = array(); $this->primary_keys = array(); } } /* End of file DB_forge.php */ /* Location: ./system/database/DB_forge.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/database/DB_forge.php
PHP
mit
7,447
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * Active Record Class * * This is the platform-independent base Active Record implementation class. * * @package CodeIgniter * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_active_record extends CI_DB_driver { var $ar_select = array(); var $ar_distinct = FALSE; var $ar_from = array(); var $ar_join = array(); var $ar_where = array(); var $ar_like = array(); var $ar_groupby = array(); var $ar_having = array(); var $ar_keys = array(); var $ar_limit = FALSE; var $ar_offset = FALSE; var $ar_order = FALSE; var $ar_orderby = array(); var $ar_set = array(); var $ar_wherein = array(); var $ar_aliased_tables = array(); var $ar_store_array = array(); // Active Record Caching variables var $ar_caching = FALSE; var $ar_cache_exists = array(); var $ar_cache_select = array(); var $ar_cache_from = array(); var $ar_cache_join = array(); var $ar_cache_where = array(); var $ar_cache_like = array(); var $ar_cache_groupby = array(); var $ar_cache_having = array(); var $ar_cache_orderby = array(); var $ar_cache_set = array(); var $ar_no_escape = array(); var $ar_cache_no_escape = array(); // -------------------------------------------------------------------- /** * Select * * Generates the SELECT portion of the query * * @param string * @return object */ public function select($select = '*', $escape = NULL) { if (is_string($select)) { $select = explode(',', $select); } foreach ($select as $val) { $val = trim($val); if ($val != '') { $this->ar_select[] = $val; $this->ar_no_escape[] = $escape; if ($this->ar_caching === TRUE) { $this->ar_cache_select[] = $val; $this->ar_cache_exists[] = 'select'; $this->ar_cache_no_escape[] = $escape; } } } return $this; } // -------------------------------------------------------------------- /** * Select Max * * Generates a SELECT MAX(field) portion of a query * * @param string the field * @param string an alias * @return object */ public function select_max($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'MAX'); } // -------------------------------------------------------------------- /** * Select Min * * Generates a SELECT MIN(field) portion of a query * * @param string the field * @param string an alias * @return object */ public function select_min($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'MIN'); } // -------------------------------------------------------------------- /** * Select Average * * Generates a SELECT AVG(field) portion of a query * * @param string the field * @param string an alias * @return object */ public function select_avg($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'AVG'); } // -------------------------------------------------------------------- /** * Select Sum * * Generates a SELECT SUM(field) portion of a query * * @param string the field * @param string an alias * @return object */ public function select_sum($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'SUM'); } // -------------------------------------------------------------------- /** * Processing Function for the four functions above: * * select_max() * select_min() * select_avg() * select_sum() * * @param string the field * @param string an alias * @return object */ protected function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX') { if ( ! is_string($select) OR $select == '') { $this->display_error('db_invalid_query'); } $type = strtoupper($type); if ( ! in_array($type, array('MAX', 'MIN', 'AVG', 'SUM'))) { show_error('Invalid function type: '.$type); } if ($alias == '') { $alias = $this->_create_alias_from_table(trim($select)); } $sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$alias; $this->ar_select[] = $sql; if ($this->ar_caching === TRUE) { $this->ar_cache_select[] = $sql; $this->ar_cache_exists[] = 'select'; } return $this; } // -------------------------------------------------------------------- /** * Determines the alias name based on the table * * @param string * @return string */ protected function _create_alias_from_table($item) { if (strpos($item, '.') !== FALSE) { return end(explode('.', $item)); } return $item; } // -------------------------------------------------------------------- /** * DISTINCT * * Sets a flag which tells the query string compiler to add DISTINCT * * @param bool * @return object */ public function distinct($val = TRUE) { $this->ar_distinct = (is_bool($val)) ? $val : TRUE; return $this; } // -------------------------------------------------------------------- /** * From * * Generates the FROM portion of the query * * @param mixed can be a string or array * @return object */ public function from($from) { foreach ((array) $from as $val) { if (strpos($val, ',') !== FALSE) { foreach (explode(',', $val) as $v) { $v = trim($v); $this->_track_aliases($v); $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); if ($this->ar_caching === TRUE) { $this->ar_cache_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); $this->ar_cache_exists[] = 'from'; } } } else { $val = trim($val); // Extract any aliases that might exist. We use this information // in the _protect_identifiers to know whether to add a table prefix $this->_track_aliases($val); $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); if ($this->ar_caching === TRUE) { $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); $this->ar_cache_exists[] = 'from'; } } } return $this; } // -------------------------------------------------------------------- /** * Join * * Generates the JOIN portion of the query * * @param string * @param string the join condition * @param string the type of join * @return object */ public function join($table, $cond, $type = '') { if ($type != '') { $type = strtoupper(trim($type)); if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'))) { $type = ''; } else { $type .= ' '; } } // Extract any aliases that might exist. We use this information // in the _protect_identifiers to know whether to add a table prefix $this->_track_aliases($table); // Strip apart the condition and protect the identifiers if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match)) { $match[1] = $this->_protect_identifiers($match[1]); $match[3] = $this->_protect_identifiers($match[3]); $cond = $match[1].$match[2].$match[3]; } // Assemble the JOIN statement $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond; $this->ar_join[] = $join; if ($this->ar_caching === TRUE) { $this->ar_cache_join[] = $join; $this->ar_cache_exists[] = 'join'; } return $this; } // -------------------------------------------------------------------- /** * Where * * Generates the WHERE portion of the query. Separates * multiple calls with AND * * @param mixed * @param mixed * @return object */ public function where($key, $value = NULL, $escape = TRUE) { return $this->_where($key, $value, 'AND ', $escape); } // -------------------------------------------------------------------- /** * OR Where * * Generates the WHERE portion of the query. Separates * multiple calls with OR * * @param mixed * @param mixed * @return object */ public function or_where($key, $value = NULL, $escape = TRUE) { return $this->_where($key, $value, 'OR ', $escape); } // -------------------------------------------------------------------- /** * Where * * Called by where() or or_where() * * @param mixed * @param mixed * @param string * @return object */ protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) { if ( ! is_array($key)) { $key = array($key => $value); } // If the escape value was not set will will base it on the global setting if ( ! is_bool($escape)) { $escape = $this->_protect_identifiers; } foreach ($key as $k => $v) { $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type; if (is_null($v) && ! $this->_has_operator($k)) { // value appears not to have been set, assign the test to IS NULL $k .= ' IS NULL'; } if ( ! is_null($v)) { if ($escape === TRUE) { $k = $this->_protect_identifiers($k, FALSE, $escape); $v = ' '.$this->escape($v); } if ( ! $this->_has_operator($k)) { $k .= ' = '; } } else { $k = $this->_protect_identifiers($k, FALSE, $escape); } $this->ar_where[] = $prefix.$k.$v; if ($this->ar_caching === TRUE) { $this->ar_cache_where[] = $prefix.$k.$v; $this->ar_cache_exists[] = 'where'; } } return $this; } // -------------------------------------------------------------------- /** * Where_in * * Generates a WHERE field IN ('item', 'item') SQL query joined with * AND if appropriate * * @param string The field to search * @param array The values searched on * @return object */ public function where_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values); } // -------------------------------------------------------------------- /** * Where_in_or * * Generates a WHERE field IN ('item', 'item') SQL query joined with * OR if appropriate * * @param string The field to search * @param array The values searched on * @return object */ public function or_where_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values, FALSE, 'OR '); } // -------------------------------------------------------------------- /** * Where_not_in * * Generates a WHERE field NOT IN ('item', 'item') SQL query joined * with AND if appropriate * * @param string The field to search * @param array The values searched on * @return object */ public function where_not_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values, TRUE); } // -------------------------------------------------------------------- /** * Where_not_in_or * * Generates a WHERE field NOT IN ('item', 'item') SQL query joined * with OR if appropriate * * @param string The field to search * @param array The values searched on * @return object */ public function or_where_not_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values, TRUE, 'OR '); } // -------------------------------------------------------------------- /** * Where_in * * Called by where_in, where_in_or, where_not_in, where_not_in_or * * @param string The field to search * @param array The values searched on * @param boolean If the statement would be IN or NOT IN * @param string * @return object */ protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') { if ($key === NULL OR $values === NULL) { return; } if ( ! is_array($values)) { $values = array($values); } $not = ($not) ? ' NOT' : ''; foreach ($values as $value) { $this->ar_wherein[] = $this->escape($value); } $prefix = (count($this->ar_where) == 0) ? '' : $type; $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") "; $this->ar_where[] = $where_in; if ($this->ar_caching === TRUE) { $this->ar_cache_where[] = $where_in; $this->ar_cache_exists[] = 'where'; } // reset the array for multiple calls $this->ar_wherein = array(); return $this; } // -------------------------------------------------------------------- /** * Like * * Generates a %LIKE% portion of the query. Separates * multiple calls with AND * * @param mixed * @param mixed * @return object */ public function like($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'AND ', $side); } // -------------------------------------------------------------------- /** * Not Like * * Generates a NOT LIKE portion of the query. Separates * multiple calls with AND * * @param mixed * @param mixed * @return object */ public function not_like($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'AND ', $side, 'NOT'); } // -------------------------------------------------------------------- /** * OR Like * * Generates a %LIKE% portion of the query. Separates * multiple calls with OR * * @param mixed * @param mixed * @return object */ public function or_like($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'OR ', $side); } // -------------------------------------------------------------------- /** * OR Not Like * * Generates a NOT LIKE portion of the query. Separates * multiple calls with OR * * @param mixed * @param mixed * @return object */ public function or_not_like($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'OR ', $side, 'NOT'); } // -------------------------------------------------------------------- /** * Like * * Called by like() or orlike() * * @param mixed * @param mixed * @param string * @return object */ protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') { if ( ! is_array($field)) { $field = array($field => $match); } foreach ($field as $k => $v) { $k = $this->_protect_identifiers($k); $prefix = (count($this->ar_like) == 0) ? '' : $type; $v = $this->escape_like_str($v); if ($side == 'none') { $like_statement = $prefix." $k $not LIKE '{$v}'"; } elseif ($side == 'before') { $like_statement = $prefix." $k $not LIKE '%{$v}'"; } elseif ($side == 'after') { $like_statement = $prefix." $k $not LIKE '{$v}%'"; } else { $like_statement = $prefix." $k $not LIKE '%{$v}%'"; } // some platforms require an escape sequence definition for LIKE wildcards if ($this->_like_escape_str != '') { $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr); } $this->ar_like[] = $like_statement; if ($this->ar_caching === TRUE) { $this->ar_cache_like[] = $like_statement; $this->ar_cache_exists[] = 'like'; } } return $this; } // -------------------------------------------------------------------- /** * GROUP BY * * @param string * @return object */ public function group_by($by) { if (is_string($by)) { $by = explode(',', $by); } foreach ($by as $val) { $val = trim($val); if ($val != '') { $this->ar_groupby[] = $this->_protect_identifiers($val); if ($this->ar_caching === TRUE) { $this->ar_cache_groupby[] = $this->_protect_identifiers($val); $this->ar_cache_exists[] = 'groupby'; } } } return $this; } // -------------------------------------------------------------------- /** * Sets the HAVING value * * Separates multiple calls with AND * * @param string * @param string * @return object */ public function having($key, $value = '', $escape = TRUE) { return $this->_having($key, $value, 'AND ', $escape); } // -------------------------------------------------------------------- /** * Sets the OR HAVING value * * Separates multiple calls with OR * * @param string * @param string * @return object */ public function or_having($key, $value = '', $escape = TRUE) { return $this->_having($key, $value, 'OR ', $escape); } // -------------------------------------------------------------------- /** * Sets the HAVING values * * Called by having() or or_having() * * @param string * @param string * @return object */ protected function _having($key, $value = '', $type = 'AND ', $escape = TRUE) { if ( ! is_array($key)) { $key = array($key => $value); } foreach ($key as $k => $v) { $prefix = (count($this->ar_having) == 0) ? '' : $type; if ($escape === TRUE) { $k = $this->_protect_identifiers($k); } if ( ! $this->_has_operator($k)) { $k .= ' = '; } if ($v != '') { $v = ' '.$this->escape($v); } $this->ar_having[] = $prefix.$k.$v; if ($this->ar_caching === TRUE) { $this->ar_cache_having[] = $prefix.$k.$v; $this->ar_cache_exists[] = 'having'; } } return $this; } // -------------------------------------------------------------------- /** * Sets the ORDER BY value * * @param string * @param string direction: asc or desc * @return object */ public function order_by($orderby, $direction = '') { if (strtolower($direction) == 'random') { $orderby = ''; // Random results want or don't need a field name $direction = $this->_random_keyword; } elseif (trim($direction) != '') { $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; } if (strpos($orderby, ',') !== FALSE) { $temp = array(); foreach (explode(',', $orderby) as $part) { $part = trim($part); if ( ! in_array($part, $this->ar_aliased_tables)) { $part = $this->_protect_identifiers(trim($part)); } $temp[] = $part; } $orderby = implode(', ', $temp); } else if ($direction != $this->_random_keyword) { $orderby = $this->_protect_identifiers($orderby); } $orderby_statement = $orderby.$direction; $this->ar_orderby[] = $orderby_statement; if ($this->ar_caching === TRUE) { $this->ar_cache_orderby[] = $orderby_statement; $this->ar_cache_exists[] = 'orderby'; } return $this; } // -------------------------------------------------------------------- /** * Sets the LIMIT value * * @param integer the limit value * @param integer the offset value * @return object */ public function limit($value, $offset = '') { $this->ar_limit = (int) $value; if ($offset != '') { $this->ar_offset = (int) $offset; } return $this; } // -------------------------------------------------------------------- /** * Sets the OFFSET value * * @param integer the offset value * @return object */ public function offset($offset) { $this->ar_offset = $offset; return $this; } // -------------------------------------------------------------------- /** * The "set" function. Allows key/value pairs to be set for inserting or updating * * @param mixed * @param string * @param boolean * @return object */ public function set($key, $value = '', $escape = TRUE) { $key = $this->_object_to_array($key); if ( ! is_array($key)) { $key = array($key => $value); } foreach ($key as $k => $v) { if ($escape === FALSE) { $this->ar_set[$this->_protect_identifiers($k)] = $v; } else { $this->ar_set[$this->_protect_identifiers($k, FALSE, TRUE)] = $this->escape($v); } } return $this; } // -------------------------------------------------------------------- /** * Get * * Compiles the select statement based on the other functions called * and runs the query * * @param string the table * @param string the limit clause * @param string the offset clause * @return object */ public function get($table = '', $limit = null, $offset = null) { if ($table != '') { $this->_track_aliases($table); $this->from($table); } if ( ! is_null($limit)) { $this->limit($limit, $offset); } $sql = $this->_compile_select(); $result = $this->query($sql); $this->_reset_select(); return $result; } /** * "Count All Results" query * * Generates a platform-specific query string that counts all records * returned by an Active Record query. * * @param string * @return string */ public function count_all_results($table = '') { if ($table != '') { $this->_track_aliases($table); $this->from($table); } $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows')); $query = $this->query($sql); $this->_reset_select(); if ($query->num_rows() == 0) { return 0; } $row = $query->row(); return (int) $row->numrows; } // -------------------------------------------------------------------- /** * Get_Where * * Allows the where clause, limit and offset to be added directly * * @param string the where clause * @param string the limit clause * @param string the offset clause * @return object */ public function get_where($table = '', $where = null, $limit = null, $offset = null) { if ($table != '') { $this->from($table); } if ( ! is_null($where)) { $this->where($where); } if ( ! is_null($limit)) { $this->limit($limit, $offset); } $sql = $this->_compile_select(); $result = $this->query($sql); $this->_reset_select(); return $result; } // -------------------------------------------------------------------- /** * Insert_Batch * * Compiles batch insert strings and runs the queries * * @param string the table to retrieve the results from * @param array an associative array of insert values * @return object */ public function insert_batch($table = '', $set = NULL) { if ( ! is_null($set)) { $this->set_insert_batch($set); } if (count($this->ar_set) == 0) { if ($this->db_debug) { //No valid data array. Folds in cases where keys and values did not match up return $this->display_error('db_must_use_set'); } return FALSE; } if ($table == '') { if ( ! isset($this->ar_from[0])) { if ($this->db_debug) { return $this->display_error('db_must_set_table'); } return FALSE; } $table = $this->ar_from[0]; } // Batch this baby for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100) { $sql = $this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100)); //echo $sql; $this->query($sql); } $this->_reset_write(); return TRUE; } // -------------------------------------------------------------------- /** * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts * * @param mixed * @param string * @param boolean * @return object */ public function set_insert_batch($key, $value = '', $escape = TRUE) { $key = $this->_object_to_array_batch($key); if ( ! is_array($key)) { $key = array($key => $value); } $keys = array_keys(current($key)); sort($keys); foreach ($key as $row) { if (count(array_diff($keys, array_keys($row))) > 0 OR count(array_diff(array_keys($row), $keys)) > 0) { // batch function above returns an error on an empty array $this->ar_set[] = array(); return; } ksort($row); // puts $row in the same order as our keys if ($escape === FALSE) { $this->ar_set[] = '('.implode(',', $row).')'; } else { $clean = array(); foreach ($row as $value) { $clean[] = $this->escape($value); } $this->ar_set[] = '('.implode(',', $clean).')'; } } foreach ($keys as $k) { $this->ar_keys[] = $this->_protect_identifiers($k); } return $this; } // -------------------------------------------------------------------- /** * Insert * * Compiles an insert string and runs the query * * @param string the table to insert data into * @param array an associative array of insert values * @return object */ function insert($table = '', $set = NULL) { if ( ! is_null($set)) { $this->set($set); } if (count($this->ar_set) == 0) { if ($this->db_debug) { return $this->display_error('db_must_use_set'); } return FALSE; } if ($table == '') { if ( ! isset($this->ar_from[0])) { if ($this->db_debug) { return $this->display_error('db_must_set_table'); } return FALSE; } $table = $this->ar_from[0]; } $sql = $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set)); $this->_reset_write(); return $this->query($sql); } // -------------------------------------------------------------------- /** * Replace * * Compiles an replace into string and runs the query * * @param string the table to replace data into * @param array an associative array of insert values * @return object */ public function replace($table = '', $set = NULL) { if ( ! is_null($set)) { $this->set($set); } if (count($this->ar_set) == 0) { if ($this->db_debug) { return $this->display_error('db_must_use_set'); } return FALSE; } if ($table == '') { if ( ! isset($this->ar_from[0])) { if ($this->db_debug) { return $this->display_error('db_must_set_table'); } return FALSE; } $table = $this->ar_from[0]; } $sql = $this->_replace($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set)); $this->_reset_write(); return $this->query($sql); } // -------------------------------------------------------------------- /** * Update * * Compiles an update string and runs the query * * @param string the table to retrieve the results from * @param array an associative array of update values * @param mixed the where clause * @return object */ public function update($table = '', $set = NULL, $where = NULL, $limit = NULL) { // Combine any cached components with the current statements $this->_merge_cache(); if ( ! is_null($set)) { $this->set($set); } if (count($this->ar_set) == 0) { if ($this->db_debug) { return $this->display_error('db_must_use_set'); } return FALSE; } if ($table == '') { if ( ! isset($this->ar_from[0])) { if ($this->db_debug) { return $this->display_error('db_must_set_table'); } return FALSE; } $table = $this->ar_from[0]; } if ($where != NULL) { $this->where($where); } if ($limit != NULL) { $this->limit($limit); } $sql = $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit); $this->_reset_write(); return $this->query($sql); } // -------------------------------------------------------------------- /** * Update_Batch * * Compiles an update string and runs the query * * @param string the table to retrieve the results from * @param array an associative array of update values * @param string the where key * @return object */ public function update_batch($table = '', $set = NULL, $index = NULL) { // Combine any cached components with the current statements $this->_merge_cache(); if (is_null($index)) { if ($this->db_debug) { return $this->display_error('db_must_use_index'); } return FALSE; } if ( ! is_null($set)) { $this->set_update_batch($set, $index); } if (count($this->ar_set) == 0) { if ($this->db_debug) { return $this->display_error('db_must_use_set'); } return FALSE; } if ($table == '') { if ( ! isset($this->ar_from[0])) { if ($this->db_debug) { return $this->display_error('db_must_set_table'); } return FALSE; } $table = $this->ar_from[0]; } // Batch this baby for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100) { $sql = $this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where); $this->query($sql); } $this->_reset_write(); } // -------------------------------------------------------------------- /** * The "set_update_batch" function. Allows key/value pairs to be set for batch updating * * @param array * @param string * @param boolean * @return object */ public function set_update_batch($key, $index = '', $escape = TRUE) { $key = $this->_object_to_array_batch($key); if ( ! is_array($key)) { // @todo error } foreach ($key as $k => $v) { $index_set = FALSE; $clean = array(); foreach ($v as $k2 => $v2) { if ($k2 == $index) { $index_set = TRUE; } else { $not[] = $k.'-'.$v; } if ($escape === FALSE) { $clean[$this->_protect_identifiers($k2)] = $v2; } else { $clean[$this->_protect_identifiers($k2)] = $this->escape($v2); } } if ($index_set == FALSE) { return $this->display_error('db_batch_missing_index'); } $this->ar_set[] = $clean; } return $this; } // -------------------------------------------------------------------- /** * Empty Table * * Compiles a delete string and runs "DELETE FROM table" * * @param string the table to empty * @return object */ public function empty_table($table = '') { if ($table == '') { if ( ! isset($this->ar_from[0])) { if ($this->db_debug) { return $this->display_error('db_must_set_table'); } return FALSE; } $table = $this->ar_from[0]; } else { $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE); } $sql = $this->_delete($table); $this->_reset_write(); return $this->query($sql); } // -------------------------------------------------------------------- /** * Truncate * * Compiles a truncate string and runs the query * If the database does not support the truncate() command * This function maps to "DELETE FROM table" * * @param string the table to truncate * @return object */ public function truncate($table = '') { if ($table == '') { if ( ! isset($this->ar_from[0])) { if ($this->db_debug) { return $this->display_error('db_must_set_table'); } return FALSE; } $table = $this->ar_from[0]; } else { $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE); } $sql = $this->_truncate($table); $this->_reset_write(); return $this->query($sql); } // -------------------------------------------------------------------- /** * Delete * * Compiles a delete string and runs the query * * @param mixed the table(s) to delete from. String or array * @param mixed the where clause * @param mixed the limit clause * @param boolean * @return object */ public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) { // Combine any cached components with the current statements $this->_merge_cache(); if ($table == '') { if ( ! isset($this->ar_from[0])) { if ($this->db_debug) { return $this->display_error('db_must_set_table'); } return FALSE; } $table = $this->ar_from[0]; } elseif (is_array($table)) { foreach ($table as $single_table) { $this->delete($single_table, $where, $limit, FALSE); } $this->_reset_write(); return; } else { $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE); } if ($where != '') { $this->where($where); } if ($limit != NULL) { $this->limit($limit); } if (count($this->ar_where) == 0 && count($this->ar_wherein) == 0 && count($this->ar_like) == 0) { if ($this->db_debug) { return $this->display_error('db_del_must_use_where'); } return FALSE; } $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit); if ($reset_data) { $this->_reset_write(); } return $this->query($sql); } // -------------------------------------------------------------------- /** * DB Prefix * * Prepends a database prefix if one exists in configuration * * @param string the table * @return string */ public function dbprefix($table = '') { if ($table == '') { $this->display_error('db_table_name_required'); } return $this->dbprefix.$table; } // -------------------------------------------------------------------- /** * Set DB Prefix * * Set's the DB Prefix to something new without needing to reconnect * * @param string the prefix * @return string */ public function set_dbprefix($prefix = '') { return $this->dbprefix = $prefix; } // -------------------------------------------------------------------- /** * Track Aliases * * Used to track SQL statements written with aliased tables. * * @param string The table to inspect * @return string */ protected function _track_aliases($table) { if (is_array($table)) { foreach ($table as $t) { $this->_track_aliases($t); } return; } // Does the string contain a comma? If so, we need to separate // the string into discreet statements if (strpos($table, ',') !== FALSE) { return $this->_track_aliases(explode(',', $table)); } // if a table alias is used we can recognize it by a space if (strpos($table, " ") !== FALSE) { // if the alias is written with the AS keyword, remove it $table = preg_replace('/\s+AS\s+/i', ' ', $table); // Grab the alias $table = trim(strrchr($table, " ")); // Store the alias, if it doesn't already exist if ( ! in_array($table, $this->ar_aliased_tables)) { $this->ar_aliased_tables[] = $table; } } } // -------------------------------------------------------------------- /** * Compile the SELECT statement * * Generates a query string based on which functions were used. * Should not be called directly. The get() function calls it. * * @return string */ protected function _compile_select($select_override = FALSE) { // Combine any cached components with the current statements $this->_merge_cache(); // ---------------------------------------------------------------- // Write the "select" portion of the query if ($select_override !== FALSE) { $sql = $select_override; } else { $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; if (count($this->ar_select) == 0) { $sql .= '*'; } else { // Cycle through the "select" portion of the query and prep each column name. // The reason we protect identifiers here rather then in the select() function // is because until the user calls the from() function we don't know if there are aliases foreach ($this->ar_select as $key => $val) { $no_escape = isset($this->ar_no_escape[$key]) ? $this->ar_no_escape[$key] : NULL; $this->ar_select[$key] = $this->_protect_identifiers($val, FALSE, $no_escape); } $sql .= implode(', ', $this->ar_select); } } // ---------------------------------------------------------------- // Write the "FROM" portion of the query if (count($this->ar_from) > 0) { $sql .= "\nFROM "; $sql .= $this->_from_tables($this->ar_from); } // ---------------------------------------------------------------- // Write the "JOIN" portion of the query if (count($this->ar_join) > 0) { $sql .= "\n"; $sql .= implode("\n", $this->ar_join); } // ---------------------------------------------------------------- // Write the "WHERE" portion of the query if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) { $sql .= "\nWHERE "; } $sql .= implode("\n", $this->ar_where); // ---------------------------------------------------------------- // Write the "LIKE" portion of the query if (count($this->ar_like) > 0) { if (count($this->ar_where) > 0) { $sql .= "\nAND "; } $sql .= implode("\n", $this->ar_like); } // ---------------------------------------------------------------- // Write the "GROUP BY" portion of the query if (count($this->ar_groupby) > 0) { $sql .= "\nGROUP BY "; $sql .= implode(', ', $this->ar_groupby); } // ---------------------------------------------------------------- // Write the "HAVING" portion of the query if (count($this->ar_having) > 0) { $sql .= "\nHAVING "; $sql .= implode("\n", $this->ar_having); } // ---------------------------------------------------------------- // Write the "ORDER BY" portion of the query if (count($this->ar_orderby) > 0) { $sql .= "\nORDER BY "; $sql .= implode(', ', $this->ar_orderby); if ($this->ar_order !== FALSE) { $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC'; } } // ---------------------------------------------------------------- // Write the "LIMIT" portion of the query if (is_numeric($this->ar_limit)) { $sql .= "\n"; $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset); } return $sql; } // -------------------------------------------------------------------- /** * Object to Array * * Takes an object as input and converts the class variables to array key/vals * * @param object * @return array */ public function _object_to_array($object) { if ( ! is_object($object)) { return $object; } $array = array(); foreach (get_object_vars($object) as $key => $val) { // There are some built in keys we need to ignore for this conversion if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name') { $array[$key] = $val; } } return $array; } // -------------------------------------------------------------------- /** * Object to Array * * Takes an object as input and converts the class variables to array key/vals * * @param object * @return array */ public function _object_to_array_batch($object) { if ( ! is_object($object)) { return $object; } $array = array(); $out = get_object_vars($object); $fields = array_keys($out); foreach ($fields as $val) { // There are some built in keys we need to ignore for this conversion if ($val != '_parent_name') { $i = 0; foreach ($out[$val] as $data) { $array[$i][$val] = $data; $i++; } } } return $array; } // -------------------------------------------------------------------- /** * Start Cache * * Starts AR caching * * @return void */ public function start_cache() { $this->ar_caching = TRUE; } // -------------------------------------------------------------------- /** * Stop Cache * * Stops AR caching * * @return void */ public function stop_cache() { $this->ar_caching = FALSE; } // -------------------------------------------------------------------- /** * Flush Cache * * Empties the AR cache * * @access public * @return void */ public function flush_cache() { $this->_reset_run(array( 'ar_cache_select' => array(), 'ar_cache_from' => array(), 'ar_cache_join' => array(), 'ar_cache_where' => array(), 'ar_cache_like' => array(), 'ar_cache_groupby' => array(), 'ar_cache_having' => array(), 'ar_cache_orderby' => array(), 'ar_cache_set' => array(), 'ar_cache_exists' => array(), 'ar_cache_no_escape' => array() )); } // -------------------------------------------------------------------- /** * Merge Cache * * When called, this function merges any cached AR arrays with * locally called ones. * * @return void */ protected function _merge_cache() { if (count($this->ar_cache_exists) == 0) { return; } foreach ($this->ar_cache_exists as $val) { $ar_variable = 'ar_'.$val; $ar_cache_var = 'ar_cache_'.$val; if (count($this->$ar_cache_var) == 0) { continue; } $this->$ar_variable = array_unique(array_merge($this->$ar_cache_var, $this->$ar_variable)); } // If we are "protecting identifiers" we need to examine the "from" // portion of the query to determine if there are any aliases if ($this->_protect_identifiers === TRUE AND count($this->ar_cache_from) > 0) { $this->_track_aliases($this->ar_from); } $this->ar_no_escape = $this->ar_cache_no_escape; } // -------------------------------------------------------------------- /** * Resets the active record values. Called by the get() function * * @param array An array of fields to reset * @return void */ protected function _reset_run($ar_reset_items) { foreach ($ar_reset_items as $item => $default_value) { if ( ! in_array($item, $this->ar_store_array)) { $this->$item = $default_value; } } } // -------------------------------------------------------------------- /** * Resets the active record values. Called by the get() function * * @return void */ protected function _reset_select() { $ar_reset_items = array( 'ar_select' => array(), 'ar_from' => array(), 'ar_join' => array(), 'ar_where' => array(), 'ar_like' => array(), 'ar_groupby' => array(), 'ar_having' => array(), 'ar_orderby' => array(), 'ar_wherein' => array(), 'ar_aliased_tables' => array(), 'ar_no_escape' => array(), 'ar_distinct' => FALSE, 'ar_limit' => FALSE, 'ar_offset' => FALSE, 'ar_order' => FALSE, ); $this->_reset_run($ar_reset_items); } // -------------------------------------------------------------------- /** * Resets the active record "write" values. * * Called by the insert() update() insert_batch() update_batch() and delete() functions * * @return void */ protected function _reset_write() { $ar_reset_items = array( 'ar_set' => array(), 'ar_from' => array(), 'ar_where' => array(), 'ar_like' => array(), 'ar_orderby' => array(), 'ar_keys' => array(), 'ar_limit' => FALSE, 'ar_order' => FALSE ); $this->_reset_run($ar_reset_items); } } /* End of file DB_active_rec.php */ /* Location: ./system/database/DB_active_rec.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/database/DB_active_rec.php
PHP
mit
42,977
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * Database Result Class * * This is the platform-independent result class. * This class will not be called directly. Rather, the adapter * class for the specific database will extend and instantiate it. * * @category Database * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_result { var $conn_id = NULL; var $result_id = NULL; var $result_array = array(); var $result_object = array(); var $custom_result_object = array(); var $current_row = 0; var $num_rows = 0; var $row_data = NULL; /** * Query result. Acts as a wrapper function for the following functions. * * @access public * @param string can be "object" or "array" * @return mixed either a result object or array */ public function result($type = 'object') { if ($type == 'array') return $this->result_array(); else if ($type == 'object') return $this->result_object(); else return $this->custom_result_object($type); } // -------------------------------------------------------------------- /** * Custom query result. * * @param class_name A string that represents the type of object you want back * @return array of objects */ public function custom_result_object($class_name) { if (array_key_exists($class_name, $this->custom_result_object)) { return $this->custom_result_object[$class_name]; } if ($this->result_id === FALSE OR $this->num_rows() == 0) { return array(); } // add the data to the object $this->_data_seek(0); $result_object = array(); while ($row = $this->_fetch_object()) { $object = new $class_name(); foreach ($row as $key => $value) { $object->$key = $value; } $result_object[] = $object; } // return the array return $this->custom_result_object[$class_name] = $result_object; } // -------------------------------------------------------------------- /** * Query result. "object" version. * * @access public * @return object */ public function result_object() { if (count($this->result_object) > 0) { return $this->result_object; } // In the event that query caching is on the result_id variable // will return FALSE since there isn't a valid SQL resource so // we'll simply return an empty array. if ($this->result_id === FALSE OR $this->num_rows() == 0) { return array(); } $this->_data_seek(0); while ($row = $this->_fetch_object()) { $this->result_object[] = $row; } return $this->result_object; } // -------------------------------------------------------------------- /** * Query result. "array" version. * * @access public * @return array */ public function result_array() { if (count($this->result_array) > 0) { return $this->result_array; } // In the event that query caching is on the result_id variable // will return FALSE since there isn't a valid SQL resource so // we'll simply return an empty array. if ($this->result_id === FALSE OR $this->num_rows() == 0) { return array(); } $this->_data_seek(0); while ($row = $this->_fetch_assoc()) { $this->result_array[] = $row; } return $this->result_array; } // -------------------------------------------------------------------- /** * Query result. Acts as a wrapper function for the following functions. * * @access public * @param string * @param string can be "object" or "array" * @return mixed either a result object or array */ public function row($n = 0, $type = 'object') { if ( ! is_numeric($n)) { // We cache the row data for subsequent uses if ( ! is_array($this->row_data)) { $this->row_data = $this->row_array(0); } // array_key_exists() instead of isset() to allow for MySQL NULL values if (array_key_exists($n, $this->row_data)) { return $this->row_data[$n]; } // reset the $n variable if the result was not achieved $n = 0; } if ($type == 'object') return $this->row_object($n); else if ($type == 'array') return $this->row_array($n); else return $this->custom_row_object($n, $type); } // -------------------------------------------------------------------- /** * Assigns an item into a particular column slot * * @access public * @return object */ public function set_row($key, $value = NULL) { // We cache the row data for subsequent uses if ( ! is_array($this->row_data)) { $this->row_data = $this->row_array(0); } if (is_array($key)) { foreach ($key as $k => $v) { $this->row_data[$k] = $v; } return; } if ($key != '' AND ! is_null($value)) { $this->row_data[$key] = $value; } } // -------------------------------------------------------------------- /** * Returns a single result row - custom object version * * @access public * @return object */ public function custom_row_object($n, $type) { $result = $this->custom_result_object($type); if (count($result) == 0) { return $result; } if ($n != $this->current_row AND isset($result[$n])) { $this->current_row = $n; } return $result[$this->current_row]; } /** * Returns a single result row - object version * * @access public * @return object */ public function row_object($n = 0) { $result = $this->result_object(); if (count($result) == 0) { return $result; } if ($n != $this->current_row AND isset($result[$n])) { $this->current_row = $n; } return $result[$this->current_row]; } // -------------------------------------------------------------------- /** * Returns a single result row - array version * * @access public * @return array */ public function row_array($n = 0) { $result = $this->result_array(); if (count($result) == 0) { return $result; } if ($n != $this->current_row AND isset($result[$n])) { $this->current_row = $n; } return $result[$this->current_row]; } // -------------------------------------------------------------------- /** * Returns the "first" row * * @access public * @return object */ public function first_row($type = 'object') { $result = $this->result($type); if (count($result) == 0) { return $result; } return $result[0]; } // -------------------------------------------------------------------- /** * Returns the "last" row * * @access public * @return object */ public function last_row($type = 'object') { $result = $this->result($type); if (count($result) == 0) { return $result; } return $result[count($result) -1]; } // -------------------------------------------------------------------- /** * Returns the "next" row * * @access public * @return object */ public function next_row($type = 'object') { $result = $this->result($type); if (count($result) == 0) { return $result; } if (isset($result[$this->current_row + 1])) { ++$this->current_row; } return $result[$this->current_row]; } // -------------------------------------------------------------------- /** * Returns the "previous" row * * @access public * @return object */ public function previous_row($type = 'object') { $result = $this->result($type); if (count($result) == 0) { return $result; } if (isset($result[$this->current_row - 1])) { --$this->current_row; } return $result[$this->current_row]; } // -------------------------------------------------------------------- /** * The following functions are normally overloaded by the identically named * methods in the platform-specific driver -- except when query caching * is used. When caching is enabled we do not load the other driver. * These functions are primarily here to prevent undefined function errors * when a cached result object is in use. They are not otherwise fully * operational due to the unavailability of the database resource IDs with * cached results. */ public function num_rows() { return $this->num_rows; } public function num_fields() { return 0; } public function list_fields() { return array(); } public function field_data() { return array(); } public function free_result() { return TRUE; } protected function _data_seek() { return TRUE; } protected function _fetch_assoc() { return array(); } protected function _fetch_object() { return array(); } } // END DB_result class /* End of file DB_result.php */ /* Location: ./system/database/DB_result.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/database/DB_result.php
PHP
mit
9,017
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/system/database/drivers/mysqli/index.html
HTML
mit
114
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * MySQLi Result Class * * This class extends the parent result class: CI_DB_result * * @category Database * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_result extends CI_DB_result { /** * Number of rows in the result set * * @access public * @return integer */ function num_rows() { return @mysqli_num_rows($this->result_id); } // -------------------------------------------------------------------- /** * Number of fields in the result set * * @access public * @return integer */ function num_fields() { return @mysqli_num_fields($this->result_id); } // -------------------------------------------------------------------- /** * Fetch Field Names * * Generates an array of column names * * @access public * @return array */ function list_fields() { $field_names = array(); while ($field = mysqli_fetch_field($this->result_id)) { $field_names[] = $field->name; } return $field_names; } // -------------------------------------------------------------------- /** * Field data * * Generates an array of objects containing field meta-data * * @access public * @return array */ function field_data() { $retval = array(); while ($field = mysqli_fetch_object($this->result_id)) { preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches); $type = (array_key_exists(1, $matches)) ? $matches[1] : NULL; $length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL; $F = new stdClass(); $F->name = $field->Field; $F->type = $type; $F->default = $field->Default; $F->max_length = $length; $F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 ); $retval[] = $F; } return $retval; } // -------------------------------------------------------------------- /** * Free the result * * @return null */ function free_result() { if (is_object($this->result_id)) { mysqli_free_result($this->result_id); $this->result_id = FALSE; } } // -------------------------------------------------------------------- /** * Data Seek * * Moves the internal pointer to the desired offset. We call * this internally before fetching results to make sure the * result set starts at zero * * @access private * @return array */ function _data_seek($n = 0) { return mysqli_data_seek($this->result_id, $n); } // -------------------------------------------------------------------- /** * Result - associative array * * Returns the result set as an array * * @access private * @return array */ function _fetch_assoc() { return mysqli_fetch_assoc($this->result_id); } // -------------------------------------------------------------------- /** * Result - object * * Returns the result set as an object * * @access private * @return object */ function _fetch_object() { return mysqli_fetch_object($this->result_id); } } /* End of file mysqli_result.php */ /* Location: ./system/database/drivers/mysqli/mysqli_result.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/database/drivers/mysqli/mysqli_result.php
PHP
mit
3,641
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * MySQLi Forge Class * * @category Database * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_forge extends CI_DB_forge { /** * Create database * * @access private * @param string the database name * @return bool */ function _create_database($name) { return "CREATE DATABASE ".$name; } // -------------------------------------------------------------------- /** * Drop database * * @access private * @param string the database name * @return bool */ function _drop_database($name) { return "DROP DATABASE ".$name; } // -------------------------------------------------------------------- /** * Process Fields * * @access private * @param mixed the fields * @return string */ function _process_fields($fields) { $current_field_count = 0; $sql = ''; foreach ($fields as $field=>$attributes) { // Numeric field names aren't allowed in databases, so if the key is // numeric, we know it was assigned by PHP and the developer manually // entered the field information, so we'll simply add it to the list if (is_numeric($field)) { $sql .= "\n\t$attributes"; } else { $attributes = array_change_key_case($attributes, CASE_UPPER); $sql .= "\n\t".$this->db->_protect_identifiers($field); if (array_key_exists('NAME', $attributes)) { $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' '; } if (array_key_exists('TYPE', $attributes)) { $sql .= ' '.$attributes['TYPE']; } if (array_key_exists('CONSTRAINT', $attributes)) { $sql .= '('.$attributes['CONSTRAINT'].')'; } if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) { $sql .= ' UNSIGNED'; } if (array_key_exists('DEFAULT', $attributes)) { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) { $sql .= ' NULL'; } else { $sql .= ' NOT NULL'; } if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) { $sql .= ' AUTO_INCREMENT'; } } // don't add a comma on the end of the last field if (++$current_field_count < count($fields)) { $sql .= ','; } } return $sql; } // -------------------------------------------------------------------- /** * Create Table * * @access private * @param string the table name * @param mixed the fields * @param mixed primary key(s) * @param mixed key(s) * @param boolean should 'IF NOT EXISTS' be added to the SQL * @return bool */ function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; if ($if_not_exists === TRUE) { $sql .= 'IF NOT EXISTS '; } $sql .= $this->db->_escape_identifiers($table)." ("; $sql .= $this->_process_fields($fields); if (count($primary_keys) > 0) { $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys)); $primary_keys = $this->db->_protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")"; } if (is_array($keys) && count($keys) > 0) { foreach ($keys as $key) { if (is_array($key)) { $key_name = $this->db->_protect_identifiers(implode('_', $key)); $key = $this->db->_protect_identifiers($key); } else { $key_name = $this->db->_protect_identifiers($key); $key = array($key_name); } $sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")"; } } $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};"; return $sql; } // -------------------------------------------------------------------- /** * Drop Table * * @access private * @return string */ function _drop_table($table) { return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- /** * Alter table query * * Generates a platform-specific query so that a table can be altered * Called by add_column(), drop_column(), and column_alter(), * * @access private * @param string the ALTER type (ADD, DROP, CHANGE) * @param string the column name * @param array fields * @param string the field after which we should add the new field * @return object */ function _alter_table($alter_type, $table, $fields, $after_field = '') { $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type "; // DROP has everything it needs now. if ($alter_type == 'DROP') { return $sql.$this->db->_protect_identifiers($fields); } $sql .= $this->_process_fields($fields); if ($after_field != '') { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } return $sql; } // -------------------------------------------------------------------- /** * Rename a table * * Generates a platform-specific query so that a table can be renamed * * @access private * @param string the old table name * @param string the new table name * @return string */ function _rename_table($table_name, $new_table_name) { $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); return $sql; } } /* End of file mysqli_forge.php */ /* Location: ./system/database/drivers/mysqli/mysqli_forge.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/database/drivers/mysqli/mysqli_forge.php
PHP
mit
6,103
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * MySQLi Utility Class * * @category Database * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_utility extends CI_DB_utility { /** * List databases * * @access private * @return bool */ function _list_databases() { return "SHOW DATABASES"; } // -------------------------------------------------------------------- /** * Optimize table query * * Generates a platform-specific query so that a table can be optimized * * @access private * @param string the table name * @return object */ function _optimize_table($table) { return "OPTIMIZE TABLE ".$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- /** * Repair table query * * Generates a platform-specific query so that a table can be repaired * * @access private * @param string the table name * @return object */ function _repair_table($table) { return "REPAIR TABLE ".$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- /** * MySQLi Export * * @access private * @param array Preferences * @return mixed */ function _backup($params = array()) { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); } } /* End of file mysqli_utility.php */ /* Location: ./system/database/drivers/mysqli/mysqli_utility.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/database/drivers/mysqli/mysqli_utility.php
PHP
mit
1,984
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * MySQLi Database Adapter Class - MySQLi only works with PHP 5 * * Note: _DB is an extender class that the app controller * creates dynamically based on whether the active record * class is being used or not. * * @package CodeIgniter * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_driver extends CI_DB { var $dbdriver = 'mysqli'; // The character used for escaping var $_escape_char = '`'; // clause and character used for LIKE escape sequences - not used in MySQL var $_like_escape_str = ''; var $_like_escape_chr = ''; /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ var $_count_string = "SELECT COUNT(*) AS "; var $_random_keyword = ' RAND()'; // database specific random keyword /** * Whether to use the MySQL "delete hack" which allows the number * of affected rows to be shown. Uses a preg_replace when enabled, * adding a bit more processing to all queries. */ var $delete_hack = TRUE; // whether SET NAMES must be used to set the character set var $use_set_names; // -------------------------------------------------------------------- /** * Non-persistent database connection * * @access private called by the base class * @return resource */ function db_connect() { if ($this->port != '') { return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port); } else { return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database); } } // -------------------------------------------------------------------- /** * Persistent database connection * * @access private called by the base class * @return resource */ function db_pconnect() { return $this->db_connect(); } // -------------------------------------------------------------------- /** * Reconnect * * Keep / reestablish the db connection if no queries have been * sent for a length of time exceeding the server's idle timeout * * @access public * @return void */ function reconnect() { if (mysqli_ping($this->conn_id) === FALSE) { $this->conn_id = FALSE; } } // -------------------------------------------------------------------- /** * Select the database * * @access private called by the base class * @return resource */ function db_select() { return @mysqli_select_db($this->conn_id, $this->database); } // -------------------------------------------------------------------- /** * Set client character set * * @access private * @param string * @param string * @return resource */ function _db_set_charset($charset, $collation) { if ( ! isset($this->use_set_names)) { // mysqli_set_charset() requires MySQL >= 5.0.7, use SET NAMES as fallback $this->use_set_names = (version_compare(mysqli_get_server_info($this->conn_id), '5.0.7', '>=')) ? FALSE : TRUE; } if ($this->use_set_names === TRUE) { return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); } else { return @mysqli_set_charset($this->conn_id, $charset); } } // -------------------------------------------------------------------- /** * Version number query string * * @access public * @return string */ function _version() { return "SELECT version() AS ver"; } // -------------------------------------------------------------------- /** * Execute the query * * @access private called by the base class * @param string an SQL query * @return resource */ function _execute($sql) { $sql = $this->_prep_query($sql); $result = @mysqli_query($this->conn_id, $sql); return $result; } // -------------------------------------------------------------------- /** * Prep the query * * If needed, each database adapter can prep the query string * * @access private called by execute() * @param string an SQL query * @return string */ function _prep_query($sql) { // "DELETE FROM TABLE" returns 0 affected rows This hack modifies // the query so that it returns the number of affected rows if ($this->delete_hack === TRUE) { if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) { $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); } } return $sql; } // -------------------------------------------------------------------- /** * Begin Transaction * * @access public * @return bool */ function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { return TRUE; } // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { return TRUE; } // Reset the transaction failure flag. // If the $test_mode flag is set to TRUE transactions will be rolled back // even if the queries produce a successful result. $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; $this->simple_query('SET AUTOCOMMIT=0'); $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK return TRUE; } // -------------------------------------------------------------------- /** * Commit Transaction * * @access public * @return bool */ function trans_commit() { if ( ! $this->trans_enabled) { return TRUE; } // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { return TRUE; } $this->simple_query('COMMIT'); $this->simple_query('SET AUTOCOMMIT=1'); return TRUE; } // -------------------------------------------------------------------- /** * Rollback Transaction * * @access public * @return bool */ function trans_rollback() { if ( ! $this->trans_enabled) { return TRUE; } // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { return TRUE; } $this->simple_query('ROLLBACK'); $this->simple_query('SET AUTOCOMMIT=1'); return TRUE; } // -------------------------------------------------------------------- /** * Escape String * * @access public * @param string * @param bool whether or not the string will be used in a LIKE condition * @return string */ function escape_str($str, $like = FALSE) { if (is_array($str)) { foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } return $str; } if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id)) { $str = mysqli_real_escape_string($this->conn_id, $str); } elseif (function_exists('mysql_escape_string')) { $str = mysql_escape_string($str); } else { $str = addslashes($str); } // escape LIKE condition wildcards if ($like === TRUE) { $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str); } return $str; } // -------------------------------------------------------------------- /** * Affected Rows * * @access public * @return integer */ function affected_rows() { return @mysqli_affected_rows($this->conn_id); } // -------------------------------------------------------------------- /** * Insert ID * * @access public * @return integer */ function insert_id() { return @mysqli_insert_id($this->conn_id); } // -------------------------------------------------------------------- /** * "Count All" query * * Generates a platform-specific query string that counts all records in * the specified database * * @access public * @param string * @return string */ function count_all($table = '') { if ($table == '') { return 0; } $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); if ($query->num_rows() == 0) { return 0; } $row = $query->row(); $this->_reset_select(); return (int) $row->numrows; } // -------------------------------------------------------------------- /** * List table query * * Generates a platform-specific query string so that the table names can be fetched * * @access private * @param boolean * @return string */ function _list_tables($prefix_limit = FALSE) { $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char; if ($prefix_limit !== FALSE AND $this->dbprefix != '') { $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'"; } return $sql; } // -------------------------------------------------------------------- /** * Show column query * * Generates a platform-specific query string so that the column names can be fetched * * @access public * @param string the table name * @return string */ function _list_columns($table = '') { return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE); } // -------------------------------------------------------------------- /** * Field data query * * Generates a platform-specific query so that the column data can be retrieved * * @access public * @param string the table name * @return object */ function _field_data($table) { return "DESCRIBE ".$table; } // -------------------------------------------------------------------- /** * The error message string * * @access private * @return string */ function _error_message() { return mysqli_error($this->conn_id); } // -------------------------------------------------------------------- /** * The error message number * * @access private * @return integer */ function _error_number() { return mysqli_errno($this->conn_id); } // -------------------------------------------------------------------- /** * Escape the SQL Identifiers * * This function escapes column and table names * * @access private * @param string * @return string */ function _escape_identifiers($item) { if ($this->_escape_char == '') { return $item; } foreach ($this->_reserved_identifiers as $id) { if (strpos($item, '.'.$id) !== FALSE) { $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } } if (strpos($item, '.') !== FALSE) { $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { $str = $this->_escape_char.$item.$this->_escape_char; } // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } // -------------------------------------------------------------------- /** * From Tables * * This function implicitly groups FROM tables so there is no confusion * about operator precedence in harmony with SQL standards * * @access public * @param type * @return type */ function _from_tables($tables) { if ( ! is_array($tables)) { $tables = array($tables); } return '('.implode(', ', $tables).')'; } // -------------------------------------------------------------------- /** * Insert statement * * Generates a platform-specific insert string from the supplied data * * @access public * @param string the table name * @param array the insert keys * @param array the insert values * @return string */ function _insert($table, $keys, $values) { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- /** * Insert_batch statement * * Generates a platform-specific insert string from the supplied data * * @access public * @param string the table name * @param array the insert keys * @param array the insert values * @return string */ function _insert_batch($table, $keys, $values) { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); } // -------------------------------------------------------------------- /** * Replace statement * * Generates a platform-specific replace string from the supplied data * * @access public * @param string the table name * @param array the insert keys * @param array the insert values * @return string */ function _replace($table, $keys, $values) { return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- /** * Update statement * * Generates a platform-specific update string from the supplied data * * @access public * @param string the table name * @param array the update data * @param array the where clause * @param array the orderby clause * @param array the limit clause * @return string */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; $sql .= $orderby.$limit; return $sql; } // -------------------------------------------------------------------- /** * Update_Batch statement * * Generates a platform-specific batch update string from the supplied data * * @access public * @param string the table name * @param array the update data * @param array the where clause * @return string */ function _update_batch($table, $values, $index, $where = NULL) { $ids = array(); $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : ''; foreach ($values as $key => $val) { $ids[] = $val[$index]; foreach (array_keys($val) as $field) { if ($field != $index) { $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; } } } $sql = "UPDATE ".$table." SET "; $cases = ''; foreach ($final as $k => $v) { $cases .= $k.' = CASE '."\n"; foreach ($v as $row) { $cases .= $row."\n"; } $cases .= 'ELSE '.$k.' END, '; } $sql .= substr($cases, 0, -2); $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')'; return $sql; } // -------------------------------------------------------------------- /** * Truncate statement * * Generates a platform-specific truncate string from the supplied data * If the database does not support the truncate() command * This function maps to "DELETE FROM table" * * @access public * @param string the table name * @return string */ function _truncate($table) { return "TRUNCATE ".$table; } // -------------------------------------------------------------------- /** * Delete statement * * Generates a platform-specific delete string from the supplied data * * @access public * @param string the table name * @param array the where clause * @param string the limit clause * @return string */ function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; if (count($where) > 0 OR count($like) > 0) { $conditions = "\nWHERE "; $conditions .= implode("\n", $this->ar_where); if (count($where) > 0 && count($like) > 0) { $conditions .= " AND "; } $conditions .= implode("\n", $like); } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; return "DELETE FROM ".$table.$conditions.$limit; } // -------------------------------------------------------------------- /** * Limit string * * Generates a platform-specific LIMIT clause * * @access public * @param string the sql query string * @param integer the number of rows to limit the query to * @param integer the offset value * @return string */ function _limit($sql, $limit, $offset) { $sql .= "LIMIT ".$limit; if ($offset > 0) { $sql .= " OFFSET ".$offset; } return $sql; } // -------------------------------------------------------------------- /** * Close DB Connection * * @access public * @param resource * @return void */ function _close($conn_id) { @mysqli_close($conn_id); } } /* End of file mysqli_driver.php */ /* Location: ./system/database/drivers/mysqli/mysqli_driver.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/database/drivers/mysqli/mysqli_driver.php
PHP
mit
17,409
<html> <head> <title>403 Forbidden</title> </head> <body> <p>Directory access is forbidden.</p> </body> </html>
0683babd6e120333c4dae5bac951f5cc
trunk/system/database/drivers/sqlsrv/index.html
HTML
mit
114
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * SQLSRV Database Adapter Class * * Note: _DB is an extender class that the app controller * creates dynamically based on whether the active record * class is being used or not. * * @package CodeIgniter * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_sqlsrv_driver extends CI_DB { var $dbdriver = 'sqlsrv'; // The character used for escaping var $_escape_char = ''; // clause and character used for LIKE escape sequences var $_like_escape_str = " ESCAPE '%s' "; var $_like_escape_chr = '!'; /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ var $_count_string = "SELECT COUNT(*) AS "; var $_random_keyword = ' ASC'; // not currently supported /** * Non-persistent database connection * * @access private called by the base class * @return resource */ function db_connect($pooling = false) { // Check for a UTF-8 charset being passed as CI's default 'utf8'. $character_set = (0 === strcasecmp('utf8', $this->char_set)) ? 'UTF-8' : $this->char_set; $connection = array( 'UID' => empty($this->username) ? '' : $this->username, 'PWD' => empty($this->password) ? '' : $this->password, 'Database' => $this->database, 'ConnectionPooling' => $pooling ? 1 : 0, 'CharacterSet' => $character_set, 'ReturnDatesAsStrings' => 1 ); // If the username and password are both empty, assume this is a // 'Windows Authentication Mode' connection. if(empty($connection['UID']) && empty($connection['PWD'])) { unset($connection['UID'], $connection['PWD']); } return sqlsrv_connect($this->hostname, $connection); } // -------------------------------------------------------------------- /** * Persistent database connection * * @access private called by the base class * @return resource */ function db_pconnect() { $this->db_connect(TRUE); } // -------------------------------------------------------------------- /** * Reconnect * * Keep / reestablish the db connection if no queries have been * sent for a length of time exceeding the server's idle timeout * * @access public * @return void */ function reconnect() { // not implemented in MSSQL } // -------------------------------------------------------------------- /** * Select the database * * @access private called by the base class * @return resource */ function db_select() { return $this->_execute('USE ' . $this->database); } // -------------------------------------------------------------------- /** * Set client character set * * @access public * @param string * @param string * @return resource */ function db_set_charset($charset, $collation) { // @todo - add support if needed return TRUE; } // -------------------------------------------------------------------- /** * Execute the query * * @access private called by the base class * @param string an SQL query * @return resource */ function _execute($sql) { $sql = $this->_prep_query($sql); return sqlsrv_query($this->conn_id, $sql, null, array( 'Scrollable' => SQLSRV_CURSOR_STATIC, 'SendStreamParamsAtExec' => true )); } // -------------------------------------------------------------------- /** * Prep the query * * If needed, each database adapter can prep the query string * * @access private called by execute() * @param string an SQL query * @return string */ function _prep_query($sql) { return $sql; } // -------------------------------------------------------------------- /** * Begin Transaction * * @access public * @return bool */ function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { return TRUE; } // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { return TRUE; } // Reset the transaction failure flag. // If the $test_mode flag is set to TRUE transactions will be rolled back // even if the queries produce a successful result. $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; return sqlsrv_begin_transaction($this->conn_id); } // -------------------------------------------------------------------- /** * Commit Transaction * * @access public * @return bool */ function trans_commit() { if ( ! $this->trans_enabled) { return TRUE; } // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { return TRUE; } return sqlsrv_commit($this->conn_id); } // -------------------------------------------------------------------- /** * Rollback Transaction * * @access public * @return bool */ function trans_rollback() { if ( ! $this->trans_enabled) { return TRUE; } // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { return TRUE; } return sqlsrv_rollback($this->conn_id); } // -------------------------------------------------------------------- /** * Escape String * * @access public * @param string * @param bool whether or not the string will be used in a LIKE condition * @return string */ function escape_str($str, $like = FALSE) { // Escape single quotes return str_replace("'", "''", $str); } // -------------------------------------------------------------------- /** * Affected Rows * * @access public * @return integer */ function affected_rows() { return @sqlrv_rows_affected($this->conn_id); } // -------------------------------------------------------------------- /** * Insert ID * * Returns the last id created in the Identity column. * * @access public * @return integer */ function insert_id() { return $this->query('select @@IDENTITY as insert_id')->row('insert_id'); } // -------------------------------------------------------------------- /** * Parse major version * * Grabs the major version number from the * database server version string passed in. * * @access private * @param string $version * @return int16 major version number */ function _parse_major_version($version) { preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info); return $ver_info[1]; // return the major version b/c that's all we're interested in. } // -------------------------------------------------------------------- /** * Version number query string * * @access public * @return string */ function _version() { $info = sqlsrv_server_info($this->conn_id); return sprintf("select '%s' as ver", $info['SQLServerVersion']); } // -------------------------------------------------------------------- /** * "Count All" query * * Generates a platform-specific query string that counts all records in * the specified database * * @access public * @param string * @return string */ function count_all($table = '') { if ($table == '') return '0'; $query = $this->query("SELECT COUNT(*) AS numrows FROM " . $this->dbprefix . $table); if ($query->num_rows() == 0) return '0'; $row = $query->row(); $this->_reset_select(); return $row->numrows; } // -------------------------------------------------------------------- /** * List table query * * Generates a platform-specific query string so that the table names can be fetched * * @access private * @param boolean * @return string */ function _list_tables($prefix_limit = FALSE) { return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; } // -------------------------------------------------------------------- /** * List column query * * Generates a platform-specific query string so that the column names can be fetched * * @access private * @param string the table name * @return string */ function _list_columns($table = '') { return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'"; } // -------------------------------------------------------------------- /** * Field data query * * Generates a platform-specific query so that the column data can be retrieved * * @access public * @param string the table name * @return object */ function _field_data($table) { return "SELECT TOP 1 * FROM " . $this->_escape_table($table); } // -------------------------------------------------------------------- /** * The error message string * * @access private * @return string */ function _error_message() { $error = array_shift(sqlsrv_errors()); return !empty($error['message']) ? $error['message'] : null; } // -------------------------------------------------------------------- /** * The error message number * * @access private * @return integer */ function _error_number() { $error = array_shift(sqlsrv_errors()); return isset($error['SQLSTATE']) ? $error['SQLSTATE'] : null; } // -------------------------------------------------------------------- /** * Escape Table Name * * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped * * @access private * @param string the table name * @return string */ function _escape_table($table) { return $table; } /** * Escape the SQL Identifiers * * This function escapes column and table names * * @access private * @param string * @return string */ function _escape_identifiers($item) { return $item; } // -------------------------------------------------------------------- /** * From Tables * * This function implicitly groups FROM tables so there is no confusion * about operator precedence in harmony with SQL standards * * @access public * @param type * @return type */ function _from_tables($tables) { if ( ! is_array($tables)) { $tables = array($tables); } return implode(', ', $tables); } // -------------------------------------------------------------------- /** * Insert statement * * Generates a platform-specific insert string from the supplied data * * @access public * @param string the table name * @param array the insert keys * @param array the insert values * @return string */ function _insert($table, $keys, $values) { return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- /** * Update statement * * Generates a platform-specific update string from the supplied data * * @access public * @param string the table name * @param array the update data * @param array the where clause * @param array the orderby clause * @param array the limit clause * @return string */ function _update($table, $values, $where) { foreach($values as $key => $val) { $valstr[] = $key." = ".$val; } return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- /** * Truncate statement * * Generates a platform-specific truncate string from the supplied data * If the database does not support the truncate() command * This function maps to "DELETE FROM table" * * @access public * @param string the table name * @return string */ function _truncate($table) { return "TRUNCATE ".$table; } // -------------------------------------------------------------------- /** * Delete statement * * Generates a platform-specific delete string from the supplied data * * @access public * @param string the table name * @param array the where clause * @param string the limit clause * @return string */ function _delete($table, $where) { return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- /** * Limit string * * Generates a platform-specific LIMIT clause * * @access public * @param string the sql query string * @param integer the number of rows to limit the query to * @param integer the offset value * @return string */ function _limit($sql, $limit, $offset) { $i = $limit + $offset; return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); } // -------------------------------------------------------------------- /** * Close DB Connection * * @access public * @param resource * @return void */ function _close($conn_id) { @sqlsrv_close($conn_id); } } /* End of file mssql_driver.php */ /* Location: ./system/database/drivers/mssql/mssql_driver.php */
0683babd6e120333c4dae5bac951f5cc
trunk/system/database/drivers/sqlsrv/sqlsrv_driver.php
PHP
mit
13,545