@@ -21,42 +21,42 @@ |
||
21 | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 | 22 | ############################################################################### |
23 | 23 | if (!defined('BASEPATH')) |
24 | - exit('No direct script access allowed'); |
|
24 | + exit('No direct script access allowed'); |
|
25 | 25 | |
26 | 26 | class Permission { |
27 | - function __construct($library_name = '') { |
|
28 | - $this->CI = & get_instance(); |
|
27 | + function __construct($library_name = '') { |
|
28 | + $this->CI = & get_instance(); |
|
29 | 29 | $this->CI->load->model("db_model"); |
30 | 30 | $this->CI->load->library('session'); |
31 | - } |
|
31 | + } |
|
32 | 32 | |
33 | - function get_module_access($user_type){ |
|
34 | - $where = array("userlevelid"=>$user_type); |
|
35 | - $modules_arr = $this->CI->db_model->getSelect("module_permissions","userlevels",$where); |
|
36 | - if($modules_arr->num_rows > 0){ |
|
33 | + function get_module_access($user_type){ |
|
34 | + $where = array("userlevelid"=>$user_type); |
|
35 | + $modules_arr = $this->CI->db_model->getSelect("module_permissions","userlevels",$where); |
|
36 | + if($modules_arr->num_rows > 0){ |
|
37 | 37 | $modules_arr = $modules_arr->result_array(); |
38 | 38 | $modules_arr = $modules_arr[0]['module_permissions']; |
39 | 39 | |
40 | - $menu_arr = $this->CI->db_model->select("*","menu_modules","id IN ($modules_arr)","priority","asc","","",""); |
|
40 | + $menu_arr = $this->CI->db_model->select("*","menu_modules","id IN ($modules_arr)","priority","asc","","",""); |
|
41 | 41 | $menu_list = array(); |
42 | 42 | $permited_modules = array(); |
43 | - $modules_seq_arr = array(); |
|
44 | - $modules_seq_arr = explode(",",$modules_arr); |
|
45 | - $label_arr=array(); |
|
46 | - foreach($menu_arr->result_array() as $menu_key =>$menu_value){ |
|
47 | - if(!isset($label_arr[$menu_value['menu_label']]) && $menu_value['menu_label'] != 'Configuration'){ |
|
48 | - $label_arr[$menu_value['menu_label']]=$menu_value['menu_label']; |
|
49 | - $menu_value["menu_image"] = ($menu_value["menu_image"] == "")?"Home.png":$menu_value["menu_image"]; |
|
50 | - $menu_list[$menu_value["menu_title"]][$menu_value["menu_subtitle"]][] = array("menu_label" =>trim($menu_value["menu_label"]), |
|
51 | - "module_url"=>trim($menu_value["module_url"]),"module"=>trim($menu_value["module_name"]), |
|
52 | - "menu_image"=>trim($menu_value["menu_image"])); |
|
43 | + $modules_seq_arr = array(); |
|
44 | + $modules_seq_arr = explode(",",$modules_arr); |
|
45 | + $label_arr=array(); |
|
46 | + foreach($menu_arr->result_array() as $menu_key =>$menu_value){ |
|
47 | + if(!isset($label_arr[$menu_value['menu_label']]) && $menu_value['menu_label'] != 'Configuration'){ |
|
48 | + $label_arr[$menu_value['menu_label']]=$menu_value['menu_label']; |
|
49 | + $menu_value["menu_image"] = ($menu_value["menu_image"] == "")?"Home.png":$menu_value["menu_image"]; |
|
50 | + $menu_list[$menu_value["menu_title"]][$menu_value["menu_subtitle"]][] = array("menu_label" =>trim($menu_value["menu_label"]), |
|
51 | + "module_url"=>trim($menu_value["module_url"]),"module"=>trim($menu_value["module_name"]), |
|
52 | + "menu_image"=>trim($menu_value["menu_image"])); |
|
53 | 53 | } |
54 | - $permited_modules[] = trim($menu_value["module_name"]); |
|
55 | - } |
|
56 | - $this->CI->session->set_userdata('permited_modules',serialize($permited_modules)); |
|
54 | + $permited_modules[] = trim($menu_value["module_name"]); |
|
55 | + } |
|
56 | + $this->CI->session->set_userdata('permited_modules',serialize($permited_modules)); |
|
57 | 57 | $this->CI->session->set_userdata('menuinfo',serialize($menu_list)); |
58 | 58 | return true; |
59 | - } |
|
60 | - } |
|
59 | + } |
|
60 | + } |
|
61 | 61 | } |
62 | 62 | ?> |
@@ -22,61 +22,61 @@ discard block |
||
22 | 22 | ############################################################################### |
23 | 23 | |
24 | 24 | if (!defined('BASEPATH')) |
25 | - exit('No direct script access allowed'); |
|
25 | + exit('No direct script access allowed'); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Dynamically build forms for display |
29 | 29 | */ |
30 | 30 | class email_lib { |
31 | 31 | |
32 | - protected $CI; // codeigniter |
|
33 | - public $email=''; |
|
34 | - public $smtp=''; |
|
35 | - public $smtp_host=''; |
|
36 | - public $smtp_user=''; |
|
37 | - public $smtp_pass=''; |
|
38 | - public $smtp_port=''; |
|
39 | - public $message=''; |
|
40 | - public $from=''; |
|
41 | - public $to=''; |
|
42 | - public $subject=''; |
|
43 | - public $company_name=''; |
|
44 | - public $company_website=''; |
|
45 | - public $account_id=''; |
|
32 | + protected $CI; // codeigniter |
|
33 | + public $email=''; |
|
34 | + public $smtp=''; |
|
35 | + public $smtp_host=''; |
|
36 | + public $smtp_user=''; |
|
37 | + public $smtp_pass=''; |
|
38 | + public $smtp_port=''; |
|
39 | + public $message=''; |
|
40 | + public $from=''; |
|
41 | + public $to=''; |
|
42 | + public $subject=''; |
|
43 | + public $company_name=''; |
|
44 | + public $company_website=''; |
|
45 | + public $account_id=''; |
|
46 | 46 | |
47 | - function __construct($library_name = '') { |
|
47 | + function __construct($library_name = '') { |
|
48 | 48 | |
49 | - $this->CI = & get_instance(); |
|
50 | - $this->CI->load->model('db_model'); |
|
51 | - $this->CI->load->library('email'); |
|
52 | - $this->CI->load->library('session'); |
|
53 | - } |
|
49 | + $this->CI = & get_instance(); |
|
50 | + $this->CI->load->model('db_model'); |
|
51 | + $this->CI->load->library('email'); |
|
52 | + $this->CI->load->library('session'); |
|
53 | + } |
|
54 | 54 | |
55 | - function get_email_settings() |
|
56 | - { |
|
55 | + function get_email_settings() |
|
56 | + { |
|
57 | 57 | $where = array('group_title' =>'email'); |
58 | - $query = $this->CI->db_model->getSelect("*", "system", $where); |
|
59 | - $query = $query->result_array(); |
|
58 | + $query = $this->CI->db_model->getSelect("*", "system", $where); |
|
59 | + $query = $query->result_array(); |
|
60 | 60 | foreach($query as $key=>$val){ |
61 | 61 | $tempvar = strtolower($val['name']); |
62 | 62 | $this->$tempvar=$val['value']; |
63 | 63 | } |
64 | - } |
|
64 | + } |
|
65 | 65 | |
66 | - function get_template( $type) |
|
67 | - { |
|
66 | + function get_template( $type) |
|
67 | + { |
|
68 | 68 | $where = array('name' => $type); |
69 | - $query = $this->CI->db_model->getSelect("*", "default_templates", $where); |
|
70 | - $query = $query->result(); |
|
71 | - $this->message = $query[0]->template; |
|
72 | - $this->subject = $query[0]->subject; |
|
73 | - } |
|
69 | + $query = $this->CI->db_model->getSelect("*", "default_templates", $where); |
|
70 | + $query = $query->result(); |
|
71 | + $this->message = $query[0]->template; |
|
72 | + $this->subject = $query[0]->subject; |
|
73 | + } |
|
74 | 74 | |
75 | - function get_account_info($accountid) |
|
76 | - { |
|
75 | + function get_account_info($accountid) |
|
76 | + { |
|
77 | 77 | $where = array('id' => $accountid); |
78 | - $query = $this->CI->db_model->getSelect("*", "accounts", $where); |
|
79 | - $query = $query->result_array(); |
|
78 | + $query = $this->CI->db_model->getSelect("*", "accounts", $where); |
|
79 | + $query = $query->result_array(); |
|
80 | 80 | if(isset($query[0]['email']) && $query[0]['email']!=''){ |
81 | 81 | $query[0]['currency_name']=$this->CI->common->get_field_name('currency', 'currency', $query[0]['currency_id']); |
82 | 82 | $query[0]['timezone_name']=$this->CI->common->get_field_name('gmtzone', 'timezone', $query[0]['timezone_id']); |
@@ -88,26 +88,26 @@ discard block |
||
88 | 88 | unset($query[0]['number']); |
89 | 89 | return $query[0]; |
90 | 90 | } |
91 | - return false; |
|
92 | - } |
|
91 | + return false; |
|
92 | + } |
|
93 | 93 | |
94 | - function get_info($id,$detail_type) |
|
95 | - { |
|
94 | + function get_info($id,$detail_type) |
|
95 | + { |
|
96 | 96 | $where = array('id' => $id); |
97 | - $query = $this->CI->db_model->getSelect("*", $detail_type, $where); |
|
98 | - $query = $query->result_array(); |
|
97 | + $query = $this->CI->db_model->getSelect("*", $detail_type, $where); |
|
98 | + $query = $query->result_array(); |
|
99 | 99 | if(isset($query[0]['accountid'])){ |
100 | 100 | $query=$this->get_account_info($query [0]['accountid']); |
101 | 101 | return $query[0]; |
102 | 102 | } |
103 | 103 | return false; |
104 | - } |
|
104 | + } |
|
105 | 105 | |
106 | - function get_admin_details() |
|
107 | - { |
|
106 | + function get_admin_details() |
|
107 | + { |
|
108 | 108 | $where = array(); |
109 | - $query = $this->CI->db_model->getSelect("*", "invoice_conf", $where); |
|
110 | - $query = $query->result(); |
|
109 | + $query = $this->CI->db_model->getSelect("*", "invoice_conf", $where); |
|
110 | + $query = $query->result(); |
|
111 | 111 | if(isset($query[0]->emailaddress) && $query[0]->emailaddress!=''){ |
112 | 112 | $this->company_website=$query[0]->website; |
113 | 113 | $this->from=$query[0]->emailaddress; |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | return true; |
116 | 116 | } |
117 | 117 | return false; |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | - function build_template($template_type,$detail,$detail_type='') { |
|
120 | + function build_template($template_type,$detail,$detail_type='') { |
|
121 | 121 | if(!is_array($template_type)) |
122 | 122 | $this->get_template($template_type); |
123 | 123 | else{ |
@@ -162,29 +162,29 @@ discard block |
||
162 | 162 | $this->subject = str_replace("#COMPANY_NAME#", $this->company_name, $this->subject); |
163 | 163 | switch ($template_type) { |
164 | 164 | case 'email_add_user': |
165 | - $this->message = str_replace('#NUMBER#', $templateinfo['username'], $this->message); |
|
166 | - break; |
|
165 | + $this->message = str_replace('#NUMBER#', $templateinfo['username'], $this->message); |
|
166 | + break; |
|
167 | 167 | case 'email_calling_card': |
168 | - $this->message = str_replace('#CARDNUMBER#', $templateinfo['cardnumber'], $this->message); |
|
169 | - break; |
|
168 | + $this->message = str_replace('#CARDNUMBER#', $templateinfo['cardnumber'], $this->message); |
|
169 | + break; |
|
170 | 170 | case 'email_new_invoice'; |
171 | - $this->message = str_replace('#AMOUNT#', $templateinfo['amount'], $this->message); |
|
172 | - $this->message = str_replace('#INVOICE_NUMBER#', $templateinfo['id'], $this->message); |
|
173 | - $this->subject = str_replace("#INVOICE_NUMBER#", $templateinfo['id'], $this->subject); |
|
171 | + $this->message = str_replace('#AMOUNT#', $templateinfo['amount'], $this->message); |
|
172 | + $this->message = str_replace('#INVOICE_NUMBER#', $templateinfo['id'], $this->message); |
|
173 | + $this->subject = str_replace("#INVOICE_NUMBER#", $templateinfo['id'], $this->subject); |
|
174 | 174 | break; |
175 | 175 | case 'email_add_did'; |
176 | - $this->message = str_replace('#NUNBER#', $templateinfo['number'], $this->message); |
|
177 | - $this->subject = str_replace("#NUNBER#", $templateinfo['number'], $this->subject); |
|
176 | + $this->message = str_replace('#NUNBER#', $templateinfo['number'], $this->message); |
|
177 | + $this->subject = str_replace("#NUNBER#", $templateinfo['number'], $this->subject); |
|
178 | 178 | break; |
179 | 179 | case 'email_remove_did'; |
180 | - $this->message = str_replace('#NUNBER#', $templateinfo['number'], $this->message); |
|
181 | - $this->subject = str_replace("#NUNBER#", $templateinfo['number'], $this->subject); |
|
180 | + $this->message = str_replace('#NUNBER#', $templateinfo['number'], $this->message); |
|
181 | + $this->subject = str_replace("#NUNBER#", $templateinfo['number'], $this->subject); |
|
182 | 182 | break; |
183 | 183 | } |
184 | 184 | } |
185 | - } |
|
186 | - function mail_history($attachment) |
|
187 | - { |
|
185 | + } |
|
186 | + function mail_history($attachment) |
|
187 | + { |
|
188 | 188 | $send_mail_details = array('from'=>$this->from, |
189 | 189 | 'to'=>$this->to, |
190 | 190 | 'subject'=>$this->subject, |
@@ -195,15 +195,15 @@ discard block |
||
195 | 195 | ); |
196 | 196 | $this->CI->db->insert('mail_details',$send_mail_details); |
197 | 197 | return $this->CI->db->insert_id(); |
198 | - } |
|
199 | - function update_mail_history($id) |
|
200 | - { |
|
198 | + } |
|
199 | + function update_mail_history($id) |
|
200 | + { |
|
201 | 201 | $this->CI->db->where(array('id' => $id)); |
202 | 202 | $send_mail_details = array('status'=>'0'); |
203 | 203 | $this->CI->db->update('mail_details',$send_mail_details); |
204 | - } |
|
205 | - function set_email_paramenters($details) |
|
206 | - { |
|
204 | + } |
|
205 | + function set_email_paramenters($details) |
|
206 | + { |
|
207 | 207 | if(!is_array($details)){ |
208 | 208 | $this->get_admin_details(); |
209 | 209 | $where = array('id'=>$details); |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | $this->to=$details['to']; |
217 | 217 | $this->subject=$details['subject']; |
218 | 218 | $this->account_id=$details['accountid']; |
219 | - } |
|
220 | - function get_smtp_details() |
|
221 | - { |
|
219 | + } |
|
220 | + function get_smtp_details() |
|
221 | + { |
|
222 | 222 | if($this->smtp_port=='' || $this->smtp_host=='' || $this->smtp_user=='' || $this->smtp_pass=='')exit; |
223 | 223 | $config['protocol'] = "smtp"; |
224 | 224 | $config['smtp_host'] = $this->smtp_host; |
@@ -229,9 +229,9 @@ discard block |
||
229 | 229 | $config['mailtype'] = "html"; |
230 | 230 | $config['newline'] = "\r\n"; |
231 | 231 | $this->CI->email->initialize($config); |
232 | - } |
|
232 | + } |
|
233 | 233 | |
234 | - function send_email($template_type,$details,$detail_type='',$attachment='',$resend=0,$mass_mail=0,$brodcast=0) { |
|
234 | + function send_email($template_type,$details,$detail_type='',$attachment='',$resend=0,$mass_mail=0,$brodcast=0) { |
|
235 | 235 | $this->get_email_settings(); |
236 | 236 | if(!$this->email){ |
237 | 237 | if(!$resend){ |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | } |
242 | 242 | |
243 | 243 | if(!$brodcast) |
244 | - $history_id=$this->mail_history($attachment); |
|
244 | + $history_id=$this->mail_history($attachment); |
|
245 | 245 | else |
246 | 246 | $history_id=$details['history_id']; |
247 | 247 | if(isset($this->from) && $this->from!='' && isset($this->to) && $this->to!='' && !$mass_mail){ |
@@ -257,10 +257,10 @@ discard block |
||
257 | 257 | |
258 | 258 | if($attachment!="") |
259 | 259 | { |
260 | - $attac_exp=explode(",",$attachment); |
|
261 | - foreach($attac_exp as $key=>$value){ |
|
260 | + $attac_exp=explode(",",$attachment); |
|
261 | + foreach($attac_exp as $key=>$value){ |
|
262 | 262 | if($value != ''){ |
263 | - $this->CI->email->attach(getcwd()."/attachments/".$value); |
|
263 | + $this->CI->email->attach(getcwd()."/attachments/".$value); |
|
264 | 264 | } |
265 | 265 | } |
266 | 266 | } |
@@ -269,12 +269,12 @@ discard block |
||
269 | 269 | $this->update_mail_history($history_id); |
270 | 270 | } |
271 | 271 | } |
272 | - } |
|
272 | + } |
|
273 | 273 | /** |
274 | 274 | ASTPP 3.0 |
275 | 275 | Add For Signup Module |
276 | 276 | **/ |
277 | - function send_mail($template_type,$details,$detail_type='',$attachment='',$resend=0,$mass_mail=0,$brodcast=0) { |
|
277 | + function send_mail($template_type,$details,$detail_type='',$attachment='',$resend=0,$mass_mail=0,$brodcast=0) { |
|
278 | 278 | $this->get_email_settings(); |
279 | 279 | if(!$this->email){ |
280 | 280 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | } |
286 | 286 | |
287 | 287 | if(!$brodcast) |
288 | - $history_id=$this->mail_history($attachment); |
|
288 | + $history_id=$this->mail_history($attachment); |
|
289 | 289 | else |
290 | 290 | $history_id=$details['history_id']; |
291 | 291 | if(isset($this->from) && $this->from!='' && isset($this->to) && $this->to!='' && !$mass_mail){ |
@@ -302,6 +302,6 @@ discard block |
||
302 | 302 | $this->update_mail_history($history_id); |
303 | 303 | } |
304 | 304 | } |
305 | - } |
|
305 | + } |
|
306 | 306 | } |
307 | 307 |
@@ -51,14 +51,14 @@ discard block |
||
51 | 51 | */ |
52 | 52 | |
53 | 53 | /** |
54 | - * PHP class to creates array representations for common 1D barcodes to be used with TCPDF (http://www.tcpdf.org).<br> |
|
55 | - * @name TCPDFBarcode |
|
56 | - * @package com.tecnick.tcpdf |
|
57 | - * @version 1.0.008 |
|
58 | - * @author Nicola Asuni |
|
59 | - * @link http://www.tcpdf.org |
|
60 | - * @license http://www.gnu.org/copyleft/lesser.html LGPL |
|
61 | - */ |
|
54 | + * PHP class to creates array representations for common 1D barcodes to be used with TCPDF (http://www.tcpdf.org).<br> |
|
55 | + * @name TCPDFBarcode |
|
56 | + * @package com.tecnick.tcpdf |
|
57 | + * @version 1.0.008 |
|
58 | + * @author Nicola Asuni |
|
59 | + * @link http://www.tcpdf.org |
|
60 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL |
|
61 | + */ |
|
62 | 62 | class TCPDFBarcode { |
63 | 63 | |
64 | 64 | /** |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * <li>$arrcode['bcode'][$k]['h'] bar height in units.</li> |
80 | 80 | * <li>$arrcode['bcode'][$k]['p'] bar top position (0 = top, 1 = middle)</li></ul> |
81 | 81 | * @param string $code code to print |
82 | - * @param string $type type of barcode: <ul><li>C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.</li><li>C39+ : CODE 39 with checksum</li><li>C39E : CODE 39 EXTENDED</li><li>C39E+ : CODE 39 EXTENDED + CHECKSUM</li><li>C93 : CODE 93 - USS-93</li><li>S25 : Standard 2 of 5</li><li>S25+ : Standard 2 of 5 + CHECKSUM</li><li>I25 : Interleaved 2 of 5</li><li>I25+ : Interleaved 2 of 5 + CHECKSUM</li><li>C128A : CODE 128 A</li><li>C128B : CODE 128 B</li><li>C128C : CODE 128 C</li><li>EAN2 : 2-Digits UPC-Based Extention</li><li>EAN5 : 5-Digits UPC-Based Extention</li><li>EAN8 : EAN 8</li><li>EAN13 : EAN 13</li><li>UPCA : UPC-A</li><li>UPCE : UPC-E</li><li>MSI : MSI (Variation of Plessey code)</li><li>MSI+ : MSI + CHECKSUM (modulo 11)</li><li>POSTNET : POSTNET</li><li>PLANET : PLANET</li><li>RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)</li><li>KIX : KIX (Klant index - Customer index)</li><li>IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200</li><li>CODABAR : CODABAR</li><li>CODE11 : CODE 11</li><li>PHARMA : PHARMACODE</li><li>PHARMA2T : PHARMACODE TWO-TRACKS</li></ul> |
|
82 | + * @param string $type type of barcode: <ul><li>C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.</li><li>C39+ : CODE 39 with checksum</li><li>C39E : CODE 39 EXTENDED</li><li>C39E+ : CODE 39 EXTENDED + CHECKSUM</li><li>C93 : CODE 93 - USS-93</li><li>S25 : Standard 2 of 5</li><li>S25+ : Standard 2 of 5 + CHECKSUM</li><li>I25 : Interleaved 2 of 5</li><li>I25+ : Interleaved 2 of 5 + CHECKSUM</li><li>C128A : CODE 128 A</li><li>C128B : CODE 128 B</li><li>C128C : CODE 128 C</li><li>EAN2 : 2-Digits UPC-Based Extention</li><li>EAN5 : 5-Digits UPC-Based Extention</li><li>EAN8 : EAN 8</li><li>EAN13 : EAN 13</li><li>UPCA : UPC-A</li><li>UPCE : UPC-E</li><li>MSI : MSI (Variation of Plessey code)</li><li>MSI+ : MSI + CHECKSUM (modulo 11)</li><li>POSTNET : POSTNET</li><li>PLANET : PLANET</li><li>RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)</li><li>KIX : KIX (Klant index - Customer index)</li><li>IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200</li><li>CODABAR : CODABAR</li><li>CODE11 : CODE 11</li><li>PHARMA : PHARMACODE</li><li>PHARMA2T : PHARMACODE TWO-TRACKS</li></ul> |
|
83 | 83 | */ |
84 | 84 | public function __construct($code, $type) { |
85 | 85 | $this->setBarcode($code, $type); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | |
88 | 88 | /** |
89 | 89 | * Return an array representations of barcode. |
90 | - * @return array |
|
90 | + * @return array |
|
91 | 91 | */ |
92 | 92 | public function getBarcodeArray() { |
93 | 93 | return $this->barcode_array; |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | /** |
97 | 97 | * Set the barcode. |
98 | 98 | * @param string $code code to print |
99 | - * @param string $type type of barcode: <ul><li>C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.</li><li>C39+ : CODE 39 with checksum</li><li>C39E : CODE 39 EXTENDED</li><li>C39E+ : CODE 39 EXTENDED + CHECKSUM</li><li>C93 : CODE 93 - USS-93</li><li>S25 : Standard 2 of 5</li><li>S25+ : Standard 2 of 5 + CHECKSUM</li><li>I25 : Interleaved 2 of 5</li><li>I25+ : Interleaved 2 of 5 + CHECKSUM</li><li>C128A : CODE 128 A</li><li>C128B : CODE 128 B</li><li>C128C : CODE 128 C</li><li>EAN2 : 2-Digits UPC-Based Extention</li><li>EAN5 : 5-Digits UPC-Based Extention</li><li>EAN8 : EAN 8</li><li>EAN13 : EAN 13</li><li>UPCA : UPC-A</li><li>UPCE : UPC-E</li><li>MSI : MSI (Variation of Plessey code)</li><li>MSI+ : MSI + CHECKSUM (modulo 11)</li><li>POSTNET : POSTNET</li><li>PLANET : PLANET</li><li>RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)</li><li>KIX : KIX (Klant index - Customer index)</li><li>IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200</li><li>CODABAR : CODABAR</li><li>CODE11 : CODE 11</li><li>PHARMA : PHARMACODE</li><li>PHARMA2T : PHARMACODE TWO-TRACKS</li></ul> |
|
100 | - * @return array |
|
99 | + * @param string $type type of barcode: <ul><li>C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.</li><li>C39+ : CODE 39 with checksum</li><li>C39E : CODE 39 EXTENDED</li><li>C39E+ : CODE 39 EXTENDED + CHECKSUM</li><li>C93 : CODE 93 - USS-93</li><li>S25 : Standard 2 of 5</li><li>S25+ : Standard 2 of 5 + CHECKSUM</li><li>I25 : Interleaved 2 of 5</li><li>I25+ : Interleaved 2 of 5 + CHECKSUM</li><li>C128A : CODE 128 A</li><li>C128B : CODE 128 B</li><li>C128C : CODE 128 C</li><li>EAN2 : 2-Digits UPC-Based Extention</li><li>EAN5 : 5-Digits UPC-Based Extention</li><li>EAN8 : EAN 8</li><li>EAN13 : EAN 13</li><li>UPCA : UPC-A</li><li>UPCE : UPC-E</li><li>MSI : MSI (Variation of Plessey code)</li><li>MSI+ : MSI + CHECKSUM (modulo 11)</li><li>POSTNET : POSTNET</li><li>PLANET : PLANET</li><li>RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)</li><li>KIX : KIX (Klant index - Customer index)</li><li>IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200</li><li>CODABAR : CODABAR</li><li>CODE11 : CODE 11</li><li>PHARMA : PHARMACODE</li><li>PHARMA2T : PHARMACODE TWO-TRACKS</li></ul> |
|
100 | + * @return array |
|
101 | 101 | */ |
102 | 102 | public function setBarcode($code, $type) { |
103 | 103 | switch (strtoupper($type)) { |
@@ -173,29 +173,29 @@ discard block |
||
173 | 173 | /** |
174 | 174 | * Maximum matrix size for maximum version (version 40 is 177*177 matrix). |
175 | 175 | */ |
176 | - define('QRSPEC_WIDTH_MAX', 177); |
|
176 | + define('QRSPEC_WIDTH_MAX', 177); |
|
177 | 177 | |
178 | 178 | // ----------------------------------------------------- |
179 | 179 | |
180 | 180 | /** |
181 | 181 | * Matrix index to get width from $capacity array. |
182 | 182 | */ |
183 | - define('QRCAP_WIDTH', 0); |
|
183 | + define('QRCAP_WIDTH', 0); |
|
184 | 184 | |
185 | - /** |
|
185 | + /** |
|
186 | 186 | * Matrix index to get number of words from $capacity array. |
187 | 187 | */ |
188 | - define('QRCAP_WORDS', 1); |
|
188 | + define('QRCAP_WORDS', 1); |
|
189 | 189 | |
190 | - /** |
|
190 | + /** |
|
191 | 191 | * Matrix index to get remainder from $capacity array. |
192 | 192 | */ |
193 | - define('QRCAP_REMINDER', 2); |
|
193 | + define('QRCAP_REMINDER', 2); |
|
194 | 194 | |
195 | - /** |
|
195 | + /** |
|
196 | 196 | * Matrix index to get error correction level from $capacity array. |
197 | 197 | */ |
198 | - define('QRCAP_EC', 3); |
|
198 | + define('QRCAP_EC', 3); |
|
199 | 199 | |
200 | 200 | // ----------------------------------------------------- |
201 | 201 | |
@@ -204,33 +204,33 @@ discard block |
||
204 | 204 | /** |
205 | 205 | * Number of header bits for structured mode |
206 | 206 | */ |
207 | - define('STRUCTURE_HEADER_BITS', 20); |
|
207 | + define('STRUCTURE_HEADER_BITS', 20); |
|
208 | 208 | |
209 | - /** |
|
209 | + /** |
|
210 | 210 | * Max number of symbols for structured mode |
211 | 211 | */ |
212 | - define('MAX_STRUCTURED_SYMBOLS', 16); |
|
212 | + define('MAX_STRUCTURED_SYMBOLS', 16); |
|
213 | 213 | |
214 | 214 | // ----------------------------------------------------- |
215 | 215 | |
216 | - // Masks |
|
216 | + // Masks |
|
217 | 217 | |
218 | - /** |
|
218 | + /** |
|
219 | 219 | * Down point base value for case 1 mask pattern (concatenation of same color in a line or a column) |
220 | 220 | */ |
221 | - define('N1', 3); |
|
221 | + define('N1', 3); |
|
222 | 222 | |
223 | - /** |
|
223 | + /** |
|
224 | 224 | * Down point base value for case 2 mask pattern (module block of same color) |
225 | 225 | */ |
226 | 226 | define('N2', 3); |
227 | 227 | |
228 | - /** |
|
228 | + /** |
|
229 | 229 | * Down point base value for case 3 mask pattern (1:1:3:1:1(dark:bright:dark:bright:dark)pattern in a line or a column) |
230 | 230 | */ |
231 | 231 | define('N3', 40); |
232 | 232 | |
233 | - /** |
|
233 | + /** |
|
234 | 234 | * Down point base value for case 4 mask pattern (ration of dark modules in whole) |
235 | 235 | */ |
236 | 236 | define('N4', 10); |
@@ -264,12 +264,12 @@ discard block |
||
264 | 264 | |
265 | 265 | // for compaibility with PHP4 |
266 | 266 | if (!function_exists('str_split')) { |
267 | - /** |
|
268 | - * Convert a string to an array (needed for PHP4 compatibility) |
|
269 | - * @param string $string The input string. |
|
270 | - * @param int $split_length Maximum length of the chunk. |
|
271 | - * @return If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element. |
|
272 | - */ |
|
267 | + /** |
|
268 | + * Convert a string to an array (needed for PHP4 compatibility) |
|
269 | + * @param string $string The input string. |
|
270 | + * @param int $split_length Maximum length of the chunk. |
|
271 | + * @return If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element. |
|
272 | + */ |
|
273 | 273 | function str_split($string, $split_length=1) { |
274 | 274 | if ((strlen($string) > $split_length) OR (!$split_length)) { |
275 | 275 | do { |
@@ -2622,7 +2622,7 @@ discard block |
||
2622 | 2622 | } |
2623 | 2623 | |
2624 | 2624 | /** |
2625 | - * Return block number 1 |
|
2625 | + * Return block number 1 |
|
2626 | 2626 | * @param array $spec |
2627 | 2627 | * @return int value |
2628 | 2628 | */ |
@@ -51,14 +51,14 @@ discard block |
||
51 | 51 | */ |
52 | 52 | |
53 | 53 | /** |
54 | - * PHP class to creates array representations for 2D barcodes to be used with TCPDF (http://www.tcpdf.org).<br> |
|
55 | - * @name TCPDFBarcode |
|
56 | - * @package com.tecnick.tcpdf |
|
57 | - * @version 1.0.003 |
|
58 | - * @author Nicola Asuni |
|
59 | - * @link http://www.tcpdf.org |
|
60 | - * @license http://www.gnu.org/copyleft/lesser.html LGPL |
|
61 | - */ |
|
54 | + * PHP class to creates array representations for 2D barcodes to be used with TCPDF (http://www.tcpdf.org).<br> |
|
55 | + * @name TCPDFBarcode |
|
56 | + * @package com.tecnick.tcpdf |
|
57 | + * @version 1.0.003 |
|
58 | + * @author Nicola Asuni |
|
59 | + * @link http://www.tcpdf.org |
|
60 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL |
|
61 | + */ |
|
62 | 62 | class TCPDF2DBarcode { |
63 | 63 | |
64 | 64 | /** |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * <li>$arrcode['num_cols'] required number of columns</li> |
76 | 76 | * <li>$arrcode['bcode'][$r][$c] value of the cell is $r row and $c column (0 = transparent, 1 = black)</li></ul> |
77 | 77 | * @param string $code code to print |
78 | - * @param string $type type of barcode: <ul>li>RAW: raw mode - comma-separad list of array rows</li><li>RAW2: raw mode - array rows are surrounded by square parenthesis.</li><li>QRCODE : QR-CODE Low error correction</li><li>QRCODE,L : QR-CODE Low error correction</li><li>QRCODE,M : QR-CODE Medium error correction</li><li>QRCODE,Q : QR-CODE Better error correction</li><li>QRCODE,H : QR-CODE Best error correction</li></ul> |
|
78 | + * @param string $type type of barcode: <ul>li>RAW: raw mode - comma-separad list of array rows</li><li>RAW2: raw mode - array rows are surrounded by square parenthesis.</li><li>QRCODE : QR-CODE Low error correction</li><li>QRCODE,L : QR-CODE Low error correction</li><li>QRCODE,M : QR-CODE Medium error correction</li><li>QRCODE,Q : QR-CODE Better error correction</li><li>QRCODE,H : QR-CODE Best error correction</li></ul> |
|
79 | 79 | */ |
80 | 80 | public function __construct($code, $type) { |
81 | 81 | $this->setBarcode($code, $type); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | |
84 | 84 | /** |
85 | 85 | * Return an array representations of barcode. |
86 | - * @return array |
|
86 | + * @return array |
|
87 | 87 | */ |
88 | 88 | public function getBarcodeArray() { |
89 | 89 | return $this->barcode_array; |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | /** |
93 | 93 | * Set the barcode. |
94 | 94 | * @param string $code code to print |
95 | - * @param string $type type of barcode: <ul><li>RAW: raw mode - comma-separad list of array rows</li><li>RAW2: raw mode - array rows are surrounded by square parenthesis.</li><li>QRCODE : QR-CODE Low error correction</li><li>QRCODE,L : QR-CODE Low error correction</li><li>QRCODE,M : QR-CODE Medium error correction</li><li>QRCODE,Q : QR-CODE Better error correction</li><li>QRCODE,H : QR-CODE Best error correction</li></ul> |
|
96 | - * @return array |
|
95 | + * @param string $type type of barcode: <ul><li>RAW: raw mode - comma-separad list of array rows</li><li>RAW2: raw mode - array rows are surrounded by square parenthesis.</li><li>QRCODE : QR-CODE Low error correction</li><li>QRCODE,L : QR-CODE Low error correction</li><li>QRCODE,M : QR-CODE Medium error correction</li><li>QRCODE,Q : QR-CODE Better error correction</li><li>QRCODE,H : QR-CODE Best error correction</li></ul> |
|
96 | + * @return array |
|
97 | 97 | */ |
98 | 98 | public function setBarcode($code, $type) { |
99 | 99 | $mode = explode(',', $type); |
@@ -11,86 +11,86 @@ |
||
11 | 11 | |
12 | 12 | class HTML2PDF_locale |
13 | 13 | { |
14 | - /** |
|
15 | - * code of the current used locale |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - static protected $_code = null; |
|
14 | + /** |
|
15 | + * code of the current used locale |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + static protected $_code = null; |
|
19 | 19 | |
20 | - /** |
|
21 | - * texts of the current used locale |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - static protected $_list = array(); |
|
20 | + /** |
|
21 | + * texts of the current used locale |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + static protected $_list = array(); |
|
25 | 25 | |
26 | - /** |
|
27 | - * directory where locale files are |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - static protected $_directory = null; |
|
26 | + /** |
|
27 | + * directory where locale files are |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + static protected $_directory = null; |
|
31 | 31 | |
32 | - /** |
|
33 | - * load the locale |
|
34 | - * |
|
35 | - * @access public |
|
36 | - * @param string $code |
|
37 | - */ |
|
38 | - static public function load($code) |
|
39 | - { |
|
40 | - if (self::$_directory===null) { |
|
41 | - self::$_directory = dirname(dirname(__FILE__)).'/locale/'; |
|
42 | - } |
|
32 | + /** |
|
33 | + * load the locale |
|
34 | + * |
|
35 | + * @access public |
|
36 | + * @param string $code |
|
37 | + */ |
|
38 | + static public function load($code) |
|
39 | + { |
|
40 | + if (self::$_directory===null) { |
|
41 | + self::$_directory = dirname(dirname(__FILE__)).'/locale/'; |
|
42 | + } |
|
43 | 43 | |
44 | - // must be in lower case |
|
45 | - $code = strtolower($code); |
|
44 | + // must be in lower case |
|
45 | + $code = strtolower($code); |
|
46 | 46 | |
47 | - // must be [a-z-0-9] |
|
48 | - if (!preg_match('/^([a-z0-9]+)$/isU', $code)) { |
|
49 | - throw new HTML2PDF_exception(0, 'invalid language code ['.self::$_code.']'); |
|
50 | - } |
|
47 | + // must be [a-z-0-9] |
|
48 | + if (!preg_match('/^([a-z0-9]+)$/isU', $code)) { |
|
49 | + throw new HTML2PDF_exception(0, 'invalid language code ['.self::$_code.']'); |
|
50 | + } |
|
51 | 51 | |
52 | - // save the code |
|
53 | - self::$_code = $code; |
|
52 | + // save the code |
|
53 | + self::$_code = $code; |
|
54 | 54 | |
55 | - // get the name of the locale file |
|
56 | - $file = self::$_directory.self::$_code.'.csv'; |
|
55 | + // get the name of the locale file |
|
56 | + $file = self::$_directory.self::$_code.'.csv'; |
|
57 | 57 | |
58 | - // the file must exist |
|
59 | - if (!is_file($file)) { |
|
60 | - throw new HTML2PDF_exception(0, 'language code ['.self::$_code.'] unknown. You can create the translation file ['.$file.'] and send it to the webmaster of html2pdf in order to integrate it into a future release'); |
|
61 | - } |
|
58 | + // the file must exist |
|
59 | + if (!is_file($file)) { |
|
60 | + throw new HTML2PDF_exception(0, 'language code ['.self::$_code.'] unknown. You can create the translation file ['.$file.'] and send it to the webmaster of html2pdf in order to integrate it into a future release'); |
|
61 | + } |
|
62 | 62 | |
63 | - // load the file |
|
64 | - self::$_list = array(); |
|
65 | - $handle = fopen($file, 'r'); |
|
66 | - while (!feof($handle)) { |
|
67 | - $line = fgetcsv($handle); |
|
68 | - if (count($line)!=2) continue; |
|
69 | - self::$_list[trim($line[0])] = trim($line[1]); |
|
70 | - } |
|
71 | - fclose($handle); |
|
72 | - } |
|
63 | + // load the file |
|
64 | + self::$_list = array(); |
|
65 | + $handle = fopen($file, 'r'); |
|
66 | + while (!feof($handle)) { |
|
67 | + $line = fgetcsv($handle); |
|
68 | + if (count($line)!=2) continue; |
|
69 | + self::$_list[trim($line[0])] = trim($line[1]); |
|
70 | + } |
|
71 | + fclose($handle); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * clean the locale |
|
76 | - * |
|
77 | - * @access public static |
|
78 | - */ |
|
79 | - static public function clean() |
|
80 | - { |
|
81 | - self::$_code = null; |
|
82 | - self::$_list = array(); |
|
83 | - } |
|
74 | + /** |
|
75 | + * clean the locale |
|
76 | + * |
|
77 | + * @access public static |
|
78 | + */ |
|
79 | + static public function clean() |
|
80 | + { |
|
81 | + self::$_code = null; |
|
82 | + self::$_list = array(); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * get a text |
|
87 | - * |
|
88 | - * @access public static |
|
89 | - * @param string $key |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - static public function get($key, $default='######') |
|
93 | - { |
|
94 | - return (isset(self::$_list[$key]) ? self::$_list[$key] : $default); |
|
95 | - } |
|
85 | + /** |
|
86 | + * get a text |
|
87 | + * |
|
88 | + * @access public static |
|
89 | + * @param string $key |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + static public function get($key, $default='######') |
|
93 | + { |
|
94 | + return (isset(self::$_list[$key]) ? self::$_list[$key] : $default); |
|
95 | + } |
|
96 | 96 | } |
97 | 97 | \ No newline at end of file |
@@ -11,158 +11,158 @@ |
||
11 | 11 | |
12 | 12 | class HTML2PDF_exception extends exception |
13 | 13 | { |
14 | - protected $_tag = null; |
|
15 | - protected $_html = null; |
|
16 | - protected $_other = null; |
|
17 | - protected $_image = null; |
|
18 | - protected $_messageHtml = ''; |
|
19 | - |
|
20 | - /** |
|
21 | - * generate a HTML2PDF exception |
|
22 | - * |
|
23 | - * @param int $err error number |
|
24 | - * @param mixed $other additionnal informations |
|
25 | - * @return string $html optionnal code HTML associated to the error |
|
26 | - */ |
|
27 | - final public function __construct($err = 0, $other = null, $html = '') |
|
28 | - { |
|
29 | - // read the error |
|
30 | - switch($err) |
|
31 | - { |
|
32 | - case 1: // Unsupported tag |
|
33 | - $msg = (HTML2PDF_locale::get('err01')); |
|
34 | - $msg = str_replace('[[OTHER]]', $other, $msg); |
|
35 | - $this->_tag = $other; |
|
36 | - break; |
|
37 | - |
|
38 | - case 2: // too long sentence |
|
39 | - $msg = (HTML2PDF_locale::get('err02')); |
|
40 | - $msg = str_replace('[[OTHER_0]]', $other[0], $msg); |
|
41 | - $msg = str_replace('[[OTHER_1]]', $other[1], $msg); |
|
42 | - $msg = str_replace('[[OTHER_2]]', $other[2], $msg); |
|
43 | - break; |
|
44 | - |
|
45 | - case 3: // closing tag in excess |
|
46 | - $msg = (HTML2PDF_locale::get('err03')); |
|
47 | - $msg = str_replace('[[OTHER]]', $other, $msg); |
|
48 | - $this->_tag = $other; |
|
49 | - break; |
|
50 | - |
|
51 | - case 4: // tags closed in the wrong order |
|
52 | - $msg = (HTML2PDF_locale::get('err04')); |
|
53 | - $msg = str_replace('[[OTHER]]', print_r($other, true), $msg); |
|
54 | - break; |
|
55 | - |
|
56 | - case 5: // unclosed tag |
|
57 | - $msg = (HTML2PDF_locale::get('err05')); |
|
58 | - $msg = str_replace('[[OTHER]]', print_r($other, true), $msg); |
|
59 | - break; |
|
60 | - |
|
61 | - case 6: // image can not be loaded |
|
62 | - $msg = (HTML2PDF_locale::get('err06')); |
|
63 | - $msg = str_replace('[[OTHER]]', $other, $msg); |
|
64 | - $this->_image = $other; |
|
65 | - break; |
|
66 | - |
|
67 | - case 7: // too big TD content |
|
68 | - $msg = (HTML2PDF_locale::get('err07')); |
|
69 | - break; |
|
70 | - |
|
71 | - case 8: // SVG tag not in DRAW tag |
|
72 | - $msg = (HTML2PDF_locale::get('err08')); |
|
73 | - $msg = str_replace('[[OTHER]]', $other, $msg); |
|
74 | - $this->_tag = $other; |
|
75 | - break; |
|
76 | - |
|
77 | - case 9: // deprecated |
|
78 | - $msg = (HTML2PDF_locale::get('err09')); |
|
79 | - $msg = str_replace('[[OTHER_0]]', $other[0], $msg); |
|
80 | - $msg = str_replace('[[OTHER_1]]', $other[1], $msg); |
|
81 | - $this->_tag = $other[0]; |
|
82 | - break; |
|
83 | - |
|
84 | - case 0: // specific error |
|
85 | - default: |
|
86 | - $msg = $other; |
|
87 | - break; |
|
88 | - } |
|
89 | - |
|
90 | - // create the HTML message |
|
91 | - $this->_messageHtml = '<span style="color: #AA0000; font-weight: bold;">'.HTML2PDF_locale::get('txt01', 'error: ').$err.'</span><br>'; |
|
92 | - $this->_messageHtml.= HTML2PDF_locale::get('txt02', 'file:').' '.$this->file.'<br>'; |
|
93 | - $this->_messageHtml.= HTML2PDF_locale::get('txt03', 'line:').' '.$this->line.'<br>'; |
|
94 | - $this->_messageHtml.= '<br>'; |
|
95 | - $this->_messageHtml.= $msg; |
|
96 | - |
|
97 | - // create the text message |
|
98 | - $msg = HTML2PDF_locale::get('txt01', 'error: ').$err.' : '.strip_tags($msg); |
|
99 | - |
|
100 | - // add the optionnal html content |
|
101 | - if ($html) { |
|
102 | - $this->_messageHtml.= "<br><br>HTML : ...".trim(htmlentities($html)).'...'; |
|
103 | - $this->_html = $html; |
|
104 | - $msg.= ' HTML : ...'.trim($html).'...'; |
|
105 | - } |
|
106 | - |
|
107 | - // save the other informations |
|
108 | - $this->_other = $other; |
|
109 | - |
|
110 | - // construct the exception |
|
111 | - parent::__construct($msg, $err); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * get the message as string |
|
116 | - * |
|
117 | - * @access public |
|
118 | - * @return string $messageHtml |
|
119 | - */ |
|
120 | - public function __toString() |
|
121 | - { |
|
122 | - return $this->_messageHtml; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * get the html tag name |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @return string $tagName |
|
130 | - */ |
|
131 | - public function getTAG() |
|
132 | - { |
|
133 | - return $this->_tag; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * get the optional html code |
|
138 | - * |
|
139 | - * @access public |
|
140 | - * @return string $html |
|
141 | - */ |
|
142 | - public function getHTML() |
|
143 | - { |
|
144 | - return $this->_html; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * get the optional other informations |
|
149 | - * |
|
150 | - * @access public |
|
151 | - * @return mixed $other |
|
152 | - */ |
|
153 | - public function getOTHER() |
|
154 | - { |
|
155 | - return $this->_other; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * get the image source |
|
160 | - * |
|
161 | - * @access public |
|
162 | - * @return string $imageSrc |
|
163 | - */ |
|
164 | - public function getIMAGE() |
|
165 | - { |
|
166 | - return $this->_image; |
|
167 | - } |
|
14 | + protected $_tag = null; |
|
15 | + protected $_html = null; |
|
16 | + protected $_other = null; |
|
17 | + protected $_image = null; |
|
18 | + protected $_messageHtml = ''; |
|
19 | + |
|
20 | + /** |
|
21 | + * generate a HTML2PDF exception |
|
22 | + * |
|
23 | + * @param int $err error number |
|
24 | + * @param mixed $other additionnal informations |
|
25 | + * @return string $html optionnal code HTML associated to the error |
|
26 | + */ |
|
27 | + final public function __construct($err = 0, $other = null, $html = '') |
|
28 | + { |
|
29 | + // read the error |
|
30 | + switch($err) |
|
31 | + { |
|
32 | + case 1: // Unsupported tag |
|
33 | + $msg = (HTML2PDF_locale::get('err01')); |
|
34 | + $msg = str_replace('[[OTHER]]', $other, $msg); |
|
35 | + $this->_tag = $other; |
|
36 | + break; |
|
37 | + |
|
38 | + case 2: // too long sentence |
|
39 | + $msg = (HTML2PDF_locale::get('err02')); |
|
40 | + $msg = str_replace('[[OTHER_0]]', $other[0], $msg); |
|
41 | + $msg = str_replace('[[OTHER_1]]', $other[1], $msg); |
|
42 | + $msg = str_replace('[[OTHER_2]]', $other[2], $msg); |
|
43 | + break; |
|
44 | + |
|
45 | + case 3: // closing tag in excess |
|
46 | + $msg = (HTML2PDF_locale::get('err03')); |
|
47 | + $msg = str_replace('[[OTHER]]', $other, $msg); |
|
48 | + $this->_tag = $other; |
|
49 | + break; |
|
50 | + |
|
51 | + case 4: // tags closed in the wrong order |
|
52 | + $msg = (HTML2PDF_locale::get('err04')); |
|
53 | + $msg = str_replace('[[OTHER]]', print_r($other, true), $msg); |
|
54 | + break; |
|
55 | + |
|
56 | + case 5: // unclosed tag |
|
57 | + $msg = (HTML2PDF_locale::get('err05')); |
|
58 | + $msg = str_replace('[[OTHER]]', print_r($other, true), $msg); |
|
59 | + break; |
|
60 | + |
|
61 | + case 6: // image can not be loaded |
|
62 | + $msg = (HTML2PDF_locale::get('err06')); |
|
63 | + $msg = str_replace('[[OTHER]]', $other, $msg); |
|
64 | + $this->_image = $other; |
|
65 | + break; |
|
66 | + |
|
67 | + case 7: // too big TD content |
|
68 | + $msg = (HTML2PDF_locale::get('err07')); |
|
69 | + break; |
|
70 | + |
|
71 | + case 8: // SVG tag not in DRAW tag |
|
72 | + $msg = (HTML2PDF_locale::get('err08')); |
|
73 | + $msg = str_replace('[[OTHER]]', $other, $msg); |
|
74 | + $this->_tag = $other; |
|
75 | + break; |
|
76 | + |
|
77 | + case 9: // deprecated |
|
78 | + $msg = (HTML2PDF_locale::get('err09')); |
|
79 | + $msg = str_replace('[[OTHER_0]]', $other[0], $msg); |
|
80 | + $msg = str_replace('[[OTHER_1]]', $other[1], $msg); |
|
81 | + $this->_tag = $other[0]; |
|
82 | + break; |
|
83 | + |
|
84 | + case 0: // specific error |
|
85 | + default: |
|
86 | + $msg = $other; |
|
87 | + break; |
|
88 | + } |
|
89 | + |
|
90 | + // create the HTML message |
|
91 | + $this->_messageHtml = '<span style="color: #AA0000; font-weight: bold;">'.HTML2PDF_locale::get('txt01', 'error: ').$err.'</span><br>'; |
|
92 | + $this->_messageHtml.= HTML2PDF_locale::get('txt02', 'file:').' '.$this->file.'<br>'; |
|
93 | + $this->_messageHtml.= HTML2PDF_locale::get('txt03', 'line:').' '.$this->line.'<br>'; |
|
94 | + $this->_messageHtml.= '<br>'; |
|
95 | + $this->_messageHtml.= $msg; |
|
96 | + |
|
97 | + // create the text message |
|
98 | + $msg = HTML2PDF_locale::get('txt01', 'error: ').$err.' : '.strip_tags($msg); |
|
99 | + |
|
100 | + // add the optionnal html content |
|
101 | + if ($html) { |
|
102 | + $this->_messageHtml.= "<br><br>HTML : ...".trim(htmlentities($html)).'...'; |
|
103 | + $this->_html = $html; |
|
104 | + $msg.= ' HTML : ...'.trim($html).'...'; |
|
105 | + } |
|
106 | + |
|
107 | + // save the other informations |
|
108 | + $this->_other = $other; |
|
109 | + |
|
110 | + // construct the exception |
|
111 | + parent::__construct($msg, $err); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * get the message as string |
|
116 | + * |
|
117 | + * @access public |
|
118 | + * @return string $messageHtml |
|
119 | + */ |
|
120 | + public function __toString() |
|
121 | + { |
|
122 | + return $this->_messageHtml; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * get the html tag name |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @return string $tagName |
|
130 | + */ |
|
131 | + public function getTAG() |
|
132 | + { |
|
133 | + return $this->_tag; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * get the optional html code |
|
138 | + * |
|
139 | + * @access public |
|
140 | + * @return string $html |
|
141 | + */ |
|
142 | + public function getHTML() |
|
143 | + { |
|
144 | + return $this->_html; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * get the optional other informations |
|
149 | + * |
|
150 | + * @access public |
|
151 | + * @return mixed $other |
|
152 | + */ |
|
153 | + public function getOTHER() |
|
154 | + { |
|
155 | + return $this->_other; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * get the image source |
|
160 | + * |
|
161 | + * @access public |
|
162 | + * @return string $imageSrc |
|
163 | + */ |
|
164 | + public function getIMAGE() |
|
165 | + { |
|
166 | + return $this->_image; |
|
167 | + } |
|
168 | 168 | } |
169 | 169 | \ No newline at end of file |
@@ -34,212 +34,212 @@ |
||
34 | 34 | |
35 | 35 | if (!defined('K_TCPDF_EXTERNAL_CONFIG')) { |
36 | 36 | |
37 | - define('K_TCPDF_EXTERNAL_CONFIG', true); |
|
38 | - |
|
39 | - // DOCUMENT_ROOT fix for IIS Webserver |
|
40 | - if ((!isset($_SERVER['DOCUMENT_ROOT'])) OR (empty($_SERVER['DOCUMENT_ROOT']))) { |
|
41 | - if (isset($_SERVER['SCRIPT_FILENAME'])) { |
|
42 | - $_SERVER['DOCUMENT_ROOT'] = str_replace( |
|
43 | - '\\', |
|
44 | - '/', |
|
45 | - substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])) |
|
46 | - ); |
|
47 | - } elseif (isset($_SERVER['PATH_TRANSLATED'])) { |
|
48 | - $_SERVER['DOCUMENT_ROOT'] = str_replace( |
|
49 | - '\\', |
|
50 | - '/', |
|
51 | - substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])) |
|
52 | - ); |
|
53 | - } else { |
|
54 | - // define here your DOCUMENT_ROOT path if the previous fails |
|
55 | - $_SERVER['DOCUMENT_ROOT'] = '/var/www'; |
|
56 | - } |
|
57 | - } |
|
58 | - |
|
59 | - // Automatic calculation for the following K_PATH_MAIN constant |
|
60 | - $kPathMain = str_replace('\\', '/', dirname(__FILE__)); |
|
61 | - $kPathMain = dirname($kPathMain).'/'; // remove the current directory |
|
62 | - $kPathMain.= '_tcpdf_'.HTML2PDF_USED_TCPDF_VERSION.'/'; |
|
63 | - define('K_PATH_MAIN', $kPathMain); |
|
64 | - |
|
65 | - // Automatic calculation for the following K_PATH_URL constant |
|
66 | - if (isset($_SERVER['HTTP_HOST']) AND (!empty($_SERVER['HTTP_HOST']))) { |
|
67 | - if (isset($_SERVER['HTTPS']) AND (!empty($_SERVER['HTTPS'])) AND strtolower($_SERVER['HTTPS'])!='off') { |
|
68 | - $kPathUrl = 'https://'; |
|
69 | - } else { |
|
70 | - $kPathUrl = 'http://'; |
|
71 | - } |
|
72 | - $kPathUrl .= $_SERVER['HTTP_HOST']; |
|
73 | - $kPathUrl .= str_replace('\\', '/', substr(K_PATH_MAIN, (strlen($_SERVER['DOCUMENT_ROOT']) - 1))); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * URL path to tcpdf installation folder (http://localhost/tcpdf/). |
|
78 | - * By default it is automatically calculated but you can also set it as a fixed string to improve performances. |
|
79 | - */ |
|
80 | - define('K_PATH_URL', $kPathUrl); |
|
81 | - |
|
82 | - /** |
|
83 | - * path for PDF fonts |
|
84 | - * use K_PATH_MAIN.'fonts/old/' for old non-UTF8 fonts |
|
85 | - */ |
|
86 | - define('K_PATH_FONTS', K_PATH_MAIN.'fonts/'); |
|
87 | - |
|
88 | - /** |
|
89 | - * cache directory for temporary files (full path) |
|
90 | - */ |
|
91 | - define('K_PATH_CACHE', K_PATH_MAIN.'cache/'); |
|
92 | - |
|
93 | - /** |
|
94 | - * cache directory for temporary files (url path) |
|
95 | - */ |
|
96 | - define('K_PATH_URL_CACHE', K_PATH_URL.'cache/'); |
|
97 | - |
|
98 | - /** |
|
99 | - *images directory |
|
100 | - */ |
|
101 | - define('K_PATH_IMAGES', K_PATH_MAIN.'images/'); |
|
102 | - |
|
103 | - /** |
|
104 | - * blank image |
|
105 | - */ |
|
106 | - define('K_BLANK_IMAGE', K_PATH_IMAGES.'_blank.png'); |
|
107 | - |
|
108 | - /** |
|
109 | - * page format |
|
110 | - */ |
|
111 | - define('PDF_PAGE_FORMAT', 'A4'); |
|
112 | - |
|
113 | - /** |
|
114 | - * page orientation (P=portrait, L=landscape) |
|
115 | - */ |
|
116 | - define('PDF_PAGE_ORIENTATION', 'P'); |
|
117 | - |
|
118 | - /** |
|
119 | - * document creator |
|
120 | - */ |
|
121 | - define('PDF_CREATOR', 'HTML2PDF - TCPDF'); |
|
122 | - |
|
123 | - /** |
|
124 | - * document author |
|
125 | - */ |
|
126 | - define('PDF_AUTHOR', 'HTML2PDF - TCPDF'); |
|
127 | - |
|
128 | - /** |
|
129 | - * header title |
|
130 | - */ |
|
131 | - define('PDF_HEADER_TITLE', null); |
|
132 | - |
|
133 | - /** |
|
134 | - * header description string |
|
135 | - */ |
|
136 | - define('PDF_HEADER_STRING', null); |
|
137 | - |
|
138 | - /** |
|
139 | - * image logo |
|
140 | - */ |
|
141 | - define('PDF_HEADER_LOGO', null); |
|
142 | - |
|
143 | - /** |
|
144 | - * header logo image width [mm] |
|
145 | - */ |
|
146 | - define('PDF_HEADER_LOGO_WIDTH', null); |
|
147 | - |
|
148 | - /** |
|
149 | - * document unit of measure [pt=point, mm=millimeter, cm=centimeter, in=inch] |
|
150 | - */ |
|
151 | - define('PDF_UNIT', 'mm'); |
|
152 | - |
|
153 | - /** |
|
154 | - * header margin |
|
155 | - */ |
|
156 | - define('PDF_MARGIN_HEADER', 0); |
|
157 | - |
|
158 | - /** |
|
159 | - * footer margin |
|
160 | - */ |
|
161 | - define('PDF_MARGIN_FOOTER', 0); |
|
162 | - |
|
163 | - /** |
|
164 | - * top margin |
|
165 | - */ |
|
166 | - define('PDF_MARGIN_TOP', 0); |
|
167 | - |
|
168 | - /** |
|
169 | - * bottom margin |
|
170 | - */ |
|
171 | - define('PDF_MARGIN_BOTTOM', 0); |
|
172 | - |
|
173 | - /** |
|
174 | - * left margin |
|
175 | - */ |
|
176 | - define('PDF_MARGIN_LEFT', 0); |
|
177 | - |
|
178 | - /** |
|
179 | - * right margin |
|
180 | - */ |
|
181 | - define('PDF_MARGIN_RIGHT', 0); |
|
182 | - |
|
183 | - /** |
|
184 | - * default main font name |
|
185 | - */ |
|
186 | - define('PDF_FONT_NAME_MAIN', 'helvetica'); |
|
187 | - |
|
188 | - /** |
|
189 | - * default main font size |
|
190 | - */ |
|
191 | - define('PDF_FONT_SIZE_MAIN', 10); |
|
192 | - |
|
193 | - /** |
|
194 | - * default data font name |
|
195 | - */ |
|
196 | - define('PDF_FONT_NAME_DATA', 'helvetica'); |
|
197 | - |
|
198 | - /** |
|
199 | - * default data font size |
|
200 | - */ |
|
201 | - define('PDF_FONT_SIZE_DATA', 8); |
|
202 | - |
|
203 | - /** |
|
204 | - * default monospaced font name |
|
205 | - */ |
|
206 | - define('PDF_FONT_MONOSPACED', 'courier'); |
|
207 | - |
|
208 | - /** |
|
209 | - * ratio used to adjust the conversion of pixels to user units |
|
210 | - */ |
|
211 | - define('PDF_IMAGE_SCALE_RATIO', 1); |
|
212 | - |
|
213 | - /** |
|
214 | - * magnification factor for titles |
|
215 | - */ |
|
216 | - define('HEAD_MAGNIFICATION', 1); |
|
217 | - |
|
218 | - /** |
|
219 | - * height of cell repect font height |
|
220 | - */ |
|
221 | - define('K_CELL_HEIGHT_RATIO', 1); |
|
222 | - |
|
223 | - /** |
|
224 | - * title magnification respect main font size |
|
225 | - */ |
|
226 | - define('K_TITLE_MAGNIFICATION', 1); |
|
227 | - |
|
228 | - /** |
|
229 | - * reduction factor for small font |
|
230 | - */ |
|
231 | - define('K_SMALL_RATIO', 2/3); |
|
232 | - |
|
233 | - /** |
|
234 | - * set to true to enable the special procedure used to avoid the overlappind of symbols on Thai language |
|
235 | - */ |
|
236 | - define('K_THAI_TOPCHARS', true); |
|
237 | - |
|
238 | - /** |
|
239 | - * if true allows to call TCPDF methods using HTML syntax |
|
240 | - * IMPORTANT: For security reason, disable this feature if you are printing user HTML content. |
|
241 | - */ |
|
242 | - define('K_TCPDF_CALLS_IN_HTML', false); |
|
37 | + define('K_TCPDF_EXTERNAL_CONFIG', true); |
|
38 | + |
|
39 | + // DOCUMENT_ROOT fix for IIS Webserver |
|
40 | + if ((!isset($_SERVER['DOCUMENT_ROOT'])) OR (empty($_SERVER['DOCUMENT_ROOT']))) { |
|
41 | + if (isset($_SERVER['SCRIPT_FILENAME'])) { |
|
42 | + $_SERVER['DOCUMENT_ROOT'] = str_replace( |
|
43 | + '\\', |
|
44 | + '/', |
|
45 | + substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])) |
|
46 | + ); |
|
47 | + } elseif (isset($_SERVER['PATH_TRANSLATED'])) { |
|
48 | + $_SERVER['DOCUMENT_ROOT'] = str_replace( |
|
49 | + '\\', |
|
50 | + '/', |
|
51 | + substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])) |
|
52 | + ); |
|
53 | + } else { |
|
54 | + // define here your DOCUMENT_ROOT path if the previous fails |
|
55 | + $_SERVER['DOCUMENT_ROOT'] = '/var/www'; |
|
56 | + } |
|
57 | + } |
|
58 | + |
|
59 | + // Automatic calculation for the following K_PATH_MAIN constant |
|
60 | + $kPathMain = str_replace('\\', '/', dirname(__FILE__)); |
|
61 | + $kPathMain = dirname($kPathMain).'/'; // remove the current directory |
|
62 | + $kPathMain.= '_tcpdf_'.HTML2PDF_USED_TCPDF_VERSION.'/'; |
|
63 | + define('K_PATH_MAIN', $kPathMain); |
|
64 | + |
|
65 | + // Automatic calculation for the following K_PATH_URL constant |
|
66 | + if (isset($_SERVER['HTTP_HOST']) AND (!empty($_SERVER['HTTP_HOST']))) { |
|
67 | + if (isset($_SERVER['HTTPS']) AND (!empty($_SERVER['HTTPS'])) AND strtolower($_SERVER['HTTPS'])!='off') { |
|
68 | + $kPathUrl = 'https://'; |
|
69 | + } else { |
|
70 | + $kPathUrl = 'http://'; |
|
71 | + } |
|
72 | + $kPathUrl .= $_SERVER['HTTP_HOST']; |
|
73 | + $kPathUrl .= str_replace('\\', '/', substr(K_PATH_MAIN, (strlen($_SERVER['DOCUMENT_ROOT']) - 1))); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * URL path to tcpdf installation folder (http://localhost/tcpdf/). |
|
78 | + * By default it is automatically calculated but you can also set it as a fixed string to improve performances. |
|
79 | + */ |
|
80 | + define('K_PATH_URL', $kPathUrl); |
|
81 | + |
|
82 | + /** |
|
83 | + * path for PDF fonts |
|
84 | + * use K_PATH_MAIN.'fonts/old/' for old non-UTF8 fonts |
|
85 | + */ |
|
86 | + define('K_PATH_FONTS', K_PATH_MAIN.'fonts/'); |
|
87 | + |
|
88 | + /** |
|
89 | + * cache directory for temporary files (full path) |
|
90 | + */ |
|
91 | + define('K_PATH_CACHE', K_PATH_MAIN.'cache/'); |
|
92 | + |
|
93 | + /** |
|
94 | + * cache directory for temporary files (url path) |
|
95 | + */ |
|
96 | + define('K_PATH_URL_CACHE', K_PATH_URL.'cache/'); |
|
97 | + |
|
98 | + /** |
|
99 | + *images directory |
|
100 | + */ |
|
101 | + define('K_PATH_IMAGES', K_PATH_MAIN.'images/'); |
|
102 | + |
|
103 | + /** |
|
104 | + * blank image |
|
105 | + */ |
|
106 | + define('K_BLANK_IMAGE', K_PATH_IMAGES.'_blank.png'); |
|
107 | + |
|
108 | + /** |
|
109 | + * page format |
|
110 | + */ |
|
111 | + define('PDF_PAGE_FORMAT', 'A4'); |
|
112 | + |
|
113 | + /** |
|
114 | + * page orientation (P=portrait, L=landscape) |
|
115 | + */ |
|
116 | + define('PDF_PAGE_ORIENTATION', 'P'); |
|
117 | + |
|
118 | + /** |
|
119 | + * document creator |
|
120 | + */ |
|
121 | + define('PDF_CREATOR', 'HTML2PDF - TCPDF'); |
|
122 | + |
|
123 | + /** |
|
124 | + * document author |
|
125 | + */ |
|
126 | + define('PDF_AUTHOR', 'HTML2PDF - TCPDF'); |
|
127 | + |
|
128 | + /** |
|
129 | + * header title |
|
130 | + */ |
|
131 | + define('PDF_HEADER_TITLE', null); |
|
132 | + |
|
133 | + /** |
|
134 | + * header description string |
|
135 | + */ |
|
136 | + define('PDF_HEADER_STRING', null); |
|
137 | + |
|
138 | + /** |
|
139 | + * image logo |
|
140 | + */ |
|
141 | + define('PDF_HEADER_LOGO', null); |
|
142 | + |
|
143 | + /** |
|
144 | + * header logo image width [mm] |
|
145 | + */ |
|
146 | + define('PDF_HEADER_LOGO_WIDTH', null); |
|
147 | + |
|
148 | + /** |
|
149 | + * document unit of measure [pt=point, mm=millimeter, cm=centimeter, in=inch] |
|
150 | + */ |
|
151 | + define('PDF_UNIT', 'mm'); |
|
152 | + |
|
153 | + /** |
|
154 | + * header margin |
|
155 | + */ |
|
156 | + define('PDF_MARGIN_HEADER', 0); |
|
157 | + |
|
158 | + /** |
|
159 | + * footer margin |
|
160 | + */ |
|
161 | + define('PDF_MARGIN_FOOTER', 0); |
|
162 | + |
|
163 | + /** |
|
164 | + * top margin |
|
165 | + */ |
|
166 | + define('PDF_MARGIN_TOP', 0); |
|
167 | + |
|
168 | + /** |
|
169 | + * bottom margin |
|
170 | + */ |
|
171 | + define('PDF_MARGIN_BOTTOM', 0); |
|
172 | + |
|
173 | + /** |
|
174 | + * left margin |
|
175 | + */ |
|
176 | + define('PDF_MARGIN_LEFT', 0); |
|
177 | + |
|
178 | + /** |
|
179 | + * right margin |
|
180 | + */ |
|
181 | + define('PDF_MARGIN_RIGHT', 0); |
|
182 | + |
|
183 | + /** |
|
184 | + * default main font name |
|
185 | + */ |
|
186 | + define('PDF_FONT_NAME_MAIN', 'helvetica'); |
|
187 | + |
|
188 | + /** |
|
189 | + * default main font size |
|
190 | + */ |
|
191 | + define('PDF_FONT_SIZE_MAIN', 10); |
|
192 | + |
|
193 | + /** |
|
194 | + * default data font name |
|
195 | + */ |
|
196 | + define('PDF_FONT_NAME_DATA', 'helvetica'); |
|
197 | + |
|
198 | + /** |
|
199 | + * default data font size |
|
200 | + */ |
|
201 | + define('PDF_FONT_SIZE_DATA', 8); |
|
202 | + |
|
203 | + /** |
|
204 | + * default monospaced font name |
|
205 | + */ |
|
206 | + define('PDF_FONT_MONOSPACED', 'courier'); |
|
207 | + |
|
208 | + /** |
|
209 | + * ratio used to adjust the conversion of pixels to user units |
|
210 | + */ |
|
211 | + define('PDF_IMAGE_SCALE_RATIO', 1); |
|
212 | + |
|
213 | + /** |
|
214 | + * magnification factor for titles |
|
215 | + */ |
|
216 | + define('HEAD_MAGNIFICATION', 1); |
|
217 | + |
|
218 | + /** |
|
219 | + * height of cell repect font height |
|
220 | + */ |
|
221 | + define('K_CELL_HEIGHT_RATIO', 1); |
|
222 | + |
|
223 | + /** |
|
224 | + * title magnification respect main font size |
|
225 | + */ |
|
226 | + define('K_TITLE_MAGNIFICATION', 1); |
|
227 | + |
|
228 | + /** |
|
229 | + * reduction factor for small font |
|
230 | + */ |
|
231 | + define('K_SMALL_RATIO', 2/3); |
|
232 | + |
|
233 | + /** |
|
234 | + * set to true to enable the special procedure used to avoid the overlappind of symbols on Thai language |
|
235 | + */ |
|
236 | + define('K_THAI_TOPCHARS', true); |
|
237 | + |
|
238 | + /** |
|
239 | + * if true allows to call TCPDF methods using HTML syntax |
|
240 | + * IMPORTANT: For security reason, disable this feature if you are printing user HTML content. |
|
241 | + */ |
|
242 | + define('K_TCPDF_CALLS_IN_HTML', false); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | //============================================================+ |
@@ -11,511 +11,511 @@ |
||
11 | 11 | |
12 | 12 | class HTML2PDF_parsingHtml |
13 | 13 | { |
14 | - protected $_html = ''; // HTML code to parse |
|
15 | - protected $_num = 0; // table number |
|
16 | - protected $_level = 0; // table level |
|
17 | - protected $_encoding = ''; // encoding |
|
18 | - public $code = array(); // parsed HTML codfe |
|
19 | - |
|
20 | - const HTML_TAB = ' '; |
|
21 | - |
|
22 | - /** |
|
23 | - * main constructor |
|
24 | - * |
|
25 | - * @param string encoding |
|
26 | - * @access public |
|
27 | - */ |
|
28 | - public function __construct($encoding = 'UTF-8') |
|
29 | - { |
|
30 | - $this->_num = 0; |
|
31 | - $this->_level = array($this->_num); |
|
32 | - $this->_html = ''; |
|
33 | - $this->code = array(); |
|
34 | - $this->setEncoding($encoding); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * change the encoding |
|
39 | - * |
|
40 | - * @param string encoding |
|
41 | - * @access public |
|
42 | - */ |
|
43 | - public function setEncoding($encoding) |
|
44 | - { |
|
45 | - $this->_encoding = $encoding; |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Define the HTML code to parse |
|
50 | - * |
|
51 | - * @param string HTML code |
|
52 | - * @access public |
|
53 | - */ |
|
54 | - public function setHTML($html) |
|
55 | - { |
|
56 | - // remove the HTML in comment |
|
57 | - $html = preg_replace('/<!--(.*)-->/isU', '', $html); |
|
58 | - |
|
59 | - // save the HTML code |
|
60 | - $this->_html = $html; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * parse the HTML code |
|
65 | - * |
|
66 | - * @access public |
|
67 | - */ |
|
68 | - public function parse() |
|
69 | - { |
|
70 | - $parents = array(); |
|
71 | - |
|
72 | - // flag : are we in a <pre> Tag ? |
|
73 | - $tagPreIn = false; |
|
74 | - |
|
75 | - // action to use for each line of the content of a <pre> Tag |
|
76 | - $tagPreBr = array( |
|
77 | - 'name' => 'br', |
|
78 | - 'close' => false, |
|
79 | - 'param' => array( |
|
80 | - 'style' => array(), |
|
81 | - 'num' => 0 |
|
82 | - ) |
|
83 | - ); |
|
84 | - |
|
85 | - // tag that can be not closed |
|
86 | - $tagsNotClosed = array( |
|
87 | - 'br', 'hr', 'img', 'col', |
|
88 | - 'input', 'link', 'option', |
|
89 | - 'circle', 'ellipse', 'path', 'rect', 'line', 'polygon', 'polyline' |
|
90 | - ); |
|
91 | - |
|
92 | - // search the HTML tags |
|
93 | - $tmp = array(); |
|
94 | - $this->_searchCode($tmp); |
|
95 | - |
|
96 | - // all the actions to do |
|
97 | - $actions = array(); |
|
98 | - |
|
99 | - // foreach part of the HTML code |
|
100 | - foreach ($tmp as $part) { |
|
101 | - // if it is a tag code |
|
102 | - if ($part[0]=='code') { |
|
103 | - // analise the HTML code |
|
104 | - $res = $this->_analiseCode($part[1]); |
|
14 | + protected $_html = ''; // HTML code to parse |
|
15 | + protected $_num = 0; // table number |
|
16 | + protected $_level = 0; // table level |
|
17 | + protected $_encoding = ''; // encoding |
|
18 | + public $code = array(); // parsed HTML codfe |
|
19 | + |
|
20 | + const HTML_TAB = ' '; |
|
21 | + |
|
22 | + /** |
|
23 | + * main constructor |
|
24 | + * |
|
25 | + * @param string encoding |
|
26 | + * @access public |
|
27 | + */ |
|
28 | + public function __construct($encoding = 'UTF-8') |
|
29 | + { |
|
30 | + $this->_num = 0; |
|
31 | + $this->_level = array($this->_num); |
|
32 | + $this->_html = ''; |
|
33 | + $this->code = array(); |
|
34 | + $this->setEncoding($encoding); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * change the encoding |
|
39 | + * |
|
40 | + * @param string encoding |
|
41 | + * @access public |
|
42 | + */ |
|
43 | + public function setEncoding($encoding) |
|
44 | + { |
|
45 | + $this->_encoding = $encoding; |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Define the HTML code to parse |
|
50 | + * |
|
51 | + * @param string HTML code |
|
52 | + * @access public |
|
53 | + */ |
|
54 | + public function setHTML($html) |
|
55 | + { |
|
56 | + // remove the HTML in comment |
|
57 | + $html = preg_replace('/<!--(.*)-->/isU', '', $html); |
|
58 | + |
|
59 | + // save the HTML code |
|
60 | + $this->_html = $html; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * parse the HTML code |
|
65 | + * |
|
66 | + * @access public |
|
67 | + */ |
|
68 | + public function parse() |
|
69 | + { |
|
70 | + $parents = array(); |
|
71 | + |
|
72 | + // flag : are we in a <pre> Tag ? |
|
73 | + $tagPreIn = false; |
|
74 | + |
|
75 | + // action to use for each line of the content of a <pre> Tag |
|
76 | + $tagPreBr = array( |
|
77 | + 'name' => 'br', |
|
78 | + 'close' => false, |
|
79 | + 'param' => array( |
|
80 | + 'style' => array(), |
|
81 | + 'num' => 0 |
|
82 | + ) |
|
83 | + ); |
|
84 | + |
|
85 | + // tag that can be not closed |
|
86 | + $tagsNotClosed = array( |
|
87 | + 'br', 'hr', 'img', 'col', |
|
88 | + 'input', 'link', 'option', |
|
89 | + 'circle', 'ellipse', 'path', 'rect', 'line', 'polygon', 'polyline' |
|
90 | + ); |
|
91 | + |
|
92 | + // search the HTML tags |
|
93 | + $tmp = array(); |
|
94 | + $this->_searchCode($tmp); |
|
95 | + |
|
96 | + // all the actions to do |
|
97 | + $actions = array(); |
|
98 | + |
|
99 | + // foreach part of the HTML code |
|
100 | + foreach ($tmp as $part) { |
|
101 | + // if it is a tag code |
|
102 | + if ($part[0]=='code') { |
|
103 | + // analise the HTML code |
|
104 | + $res = $this->_analiseCode($part[1]); |
|
105 | 105 | |
106 | 106 | //echo "<pre>"; print_r($tagsNotClosed); exit; |
107 | - // if it is a real HTML tag |
|
108 | - if ($res) { |
|
109 | - // save the current posistion in the HTML code |
|
110 | - $res['html_pos'] = $part[2]; |
|
111 | - |
|
112 | - // if the tag must be closed |
|
113 | - if (!in_array($res['name'], $tagsNotClosed)) { |
|
114 | - // if it is a closure tag |
|
115 | - if ($res['close']) { |
|
116 | - // HTML validation |
|
117 | - if (count($parents)<1) |
|
118 | - throw new HTML2PDF_exception(3, $res['name'], $this->getHtmlErrorCode($res['html_pos'])); |
|
119 | - else if ($parents[count($parents)-1]!=$res['name']) |
|
120 | - throw new HTML2PDF_exception(4, $parents, $this->getHtmlErrorCode($res['html_pos'])); |
|
121 | - else |
|
122 | - unset($parents[count($parents)-1]); |
|
123 | - } else { |
|
124 | - // if it is a autoclosed tag |
|
125 | - if ($res['autoclose']) { |
|
126 | - // save the opened tag |
|
127 | - $actions[] = $res; |
|
128 | - |
|
129 | - // prepare the closed tag |
|
130 | - $res['params'] = array(); |
|
131 | - $res['close'] = true; |
|
132 | - } |
|
133 | - // else :add a child for validation |
|
134 | - else |
|
135 | - $parents[count($parents)] = $res['name']; |
|
136 | - } |
|
137 | - |
|
138 | - // if it is a <pre> tag (or <code> tag) not auclosed => update the flag |
|
139 | - if (($res['name']=='pre' || $res['name']=='code') && !$res['autoclose']) { |
|
140 | - $tagPreIn = !$res['close']; |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - // save the actions to convert |
|
145 | - $actions[] = $res; |
|
146 | - } else { // else (it is not a real HTML tag => we transform it in Texte |
|
147 | - $part[0]='txt'; |
|
148 | - } |
|
149 | - } |
|
150 | - // if it is text |
|
151 | - if ($part[0]=='txt') { |
|
152 | - // if we are not in a <pre> tag |
|
153 | - if (!$tagPreIn) { |
|
154 | - // save the action |
|
155 | - $actions[] = array( |
|
156 | - 'name' => 'write', |
|
157 | - 'close' => false, |
|
158 | - 'param' => array('txt' => $this->_prepareTxt($part[1])), |
|
159 | - ); |
|
160 | - } else { // else (if we are in a <pre> tag) |
|
161 | - // prepare the text |
|
162 | - $part[1] = str_replace("\r", '', $part[1]); |
|
163 | - $part[1] = explode("\n", $part[1]); |
|
164 | - |
|
165 | - // foreach line of the text |
|
166 | - foreach ($part[1] as $k => $txt) { |
|
167 | - // transform the line |
|
168 | - $txt = str_replace("\t", self::HTML_TAB, $txt); |
|
169 | - $txt = str_replace(' ', ' ', $txt); |
|
170 | - |
|
171 | - // add a break line |
|
172 | - if ($k>0) $actions[] = $tagPreBr; |
|
173 | - |
|
174 | - // save the action |
|
175 | - $actions[] = array( |
|
176 | - 'name' => 'write', |
|
177 | - 'close' => false, |
|
178 | - 'param' => array('txt' => $this->_prepareTxt($txt, false)), |
|
179 | - ); |
|
180 | - } |
|
181 | - } |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - // for each indentified action, we have to clean up the begin and the end of the texte |
|
186 | - // based on tags that surround it |
|
187 | - |
|
188 | - // list of the tags to clean |
|
189 | - $tagsToClean = array( |
|
190 | - 'page', 'page_header', 'page_footer', 'form', |
|
191 | - 'table', 'thead', 'tfoot', 'tr', 'td', 'th', 'br', |
|
192 | - 'div', 'hr', 'p', 'ul', 'ol', 'li', |
|
193 | - 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', |
|
194 | - 'bookmark', 'fieldset', 'legend', |
|
195 | - 'draw', 'circle', 'ellipse', 'path', 'rect', 'line', 'g', 'polygon', 'polyline', |
|
196 | - 'option' |
|
197 | - ); |
|
198 | - |
|
199 | - // foreach action |
|
200 | - $nb = count($actions); |
|
201 | - for ($k=0; $k<$nb; $k++) { |
|
202 | - // if it is a Text |
|
203 | - if ($actions[$k]['name']=='write') { |
|
204 | - // if the tag before the text is a tag to clean => ltrim on the text |
|
205 | - if ($k>0 && in_array($actions[$k-1]['name'], $tagsToClean)) |
|
206 | - $actions[$k]['param']['txt'] = ltrim($actions[$k]['param']['txt']); |
|
207 | - |
|
208 | - // if the tag after the text is a tag to clean => rtrim on the text |
|
209 | - if ($k<$nb-1 && in_array($actions[$k+1]['name'], $tagsToClean)) |
|
210 | - $actions[$k]['param']['txt'] = rtrim($actions[$k]['param']['txt']); |
|
211 | - |
|
212 | - // if the text is empty => remove the action |
|
213 | - if (!strlen($actions[$k]['param']['txt'])) |
|
214 | - unset($actions[$k]); |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - // if we are not on the level 0 => HTML validator ERROR |
|
219 | - if (count($parents)) throw new HTML2PDF_exception(5, $parents); |
|
220 | - |
|
221 | - // save the actions to do |
|
222 | - $this->code = array_values($actions); |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * prepare the text |
|
227 | - * |
|
228 | - * @param string texte |
|
229 | - * @param boolean true => replace multiple space+\t+\r+\n by a single space |
|
230 | - * @return string texte |
|
231 | - * @access protected |
|
232 | - */ |
|
233 | - protected function _prepareTxt($txt, $spaces = true) |
|
234 | - { |
|
235 | - if ($spaces) $txt = preg_replace('/\s+/is', ' ', $txt); |
|
236 | - $txt = str_replace('€', '€', $txt); |
|
237 | - $txt = html_entity_decode($txt, ENT_QUOTES, $this->_encoding); |
|
238 | - return $txt; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * parse the HTML code |
|
243 | - * |
|
244 | - * @param &array array's result |
|
245 | - * @return null |
|
246 | - */ |
|
247 | - protected function _searchCode(&$tmp) |
|
248 | - { |
|
249 | - // initialise the array |
|
250 | - $tmp = array(); |
|
251 | - |
|
252 | - // regexp to separate the tags from the texts |
|
253 | - $reg = '/(<[^>]+>)|([^<]+)+/isU'; |
|
254 | - |
|
255 | - // last match found |
|
256 | - $str = ''; |
|
257 | - $offset = 0; |
|
258 | - |
|
259 | - // As it finds a match |
|
260 | - while (preg_match($reg, $this->_html, $parse, PREG_OFFSET_CAPTURE, $offset)) { |
|
261 | - // if it is a tag |
|
262 | - if ($parse[1][0]) { |
|
263 | - // save the previous text if it exists |
|
264 | - if ($str!=='') $tmp[] = array('txt', $str); |
|
265 | - |
|
266 | - // save the tag, with the offset |
|
267 | - $tmp[] = array('code', trim($parse[1][0]), $offset); |
|
268 | - |
|
269 | - // init the current text |
|
270 | - $str = ''; |
|
271 | - } else { // else (if it is a text) |
|
272 | - // add the new text to the current text |
|
273 | - $str.= $parse[2][0]; |
|
274 | - } |
|
275 | - |
|
276 | - // Update offset to the end of the match |
|
277 | - $offset = $parse[0][1] + strlen($parse[0][0]); |
|
278 | - unset($parse); |
|
279 | - } |
|
280 | - // if a text is present in the end, we save it |
|
281 | - if ($str!='') $tmp[] = array('txt', $str); |
|
282 | - unset($str); |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * analise a HTML tag |
|
287 | - * |
|
288 | - * @param string HTML code to analise |
|
289 | - * @return array corresponding action |
|
290 | - */ |
|
291 | - protected function _analiseCode($code) |
|
292 | - { |
|
293 | - // name of the tag, opening, closure, autoclosure |
|
294 | - $tag = '<([\/]{0,1})([_a-z0-9]+)([\/>\s]+)'; |
|
295 | - if (!preg_match('/'.$tag.'/isU', $code, $match)) return null; |
|
296 | - $close = ($match[1]=='/' ? true : false); |
|
297 | - $autoclose = preg_match('/\/>$/isU', $code); |
|
298 | - $name = strtolower($match[2]); |
|
299 | - |
|
300 | - // required parameters (depends on the tag name) |
|
301 | - $param = array(); |
|
302 | - $param['style'] = ''; |
|
303 | - if ($name=='img') { |
|
304 | - $param['alt'] = ''; |
|
305 | - $param['src'] = ''; |
|
306 | - } |
|
307 | - if ($name=='a') { |
|
308 | - $param['href'] = ''; |
|
309 | - } |
|
310 | - |
|
311 | - // read the parameters : nom=valeur |
|
312 | - $prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)'; |
|
313 | - preg_match_all('/'.$prop.'/is', $code, $match); |
|
314 | - for($k=0; $k<count($match[0]); $k++) |
|
315 | - $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
316 | - |
|
317 | - // read the parameters : nom="valeur" |
|
318 | - $prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]'; |
|
319 | - preg_match_all('/'.$prop.'/is', $code, $match); |
|
320 | - for($k=0; $k<count($match[0]); $k++) |
|
321 | - $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
322 | - |
|
323 | - // read the parameters : nom='valeur' |
|
324 | - $prop = "([a-zA-Z0-9_]+)=[']([^']*)[']"; |
|
325 | - preg_match_all('/'.$prop.'/is', $code, $match); |
|
326 | - for($k=0; $k<count($match[0]); $k++) |
|
327 | - $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
328 | - |
|
329 | - // compliance of each parameter |
|
330 | - $color = "#000000"; |
|
331 | - $border = null; |
|
332 | - foreach ($param as $key => $val) { |
|
333 | - $key = strtolower($key); |
|
334 | - switch($key) |
|
335 | - { |
|
336 | - case 'width': |
|
337 | - unset($param[$key]); |
|
338 | - $param['style'] .= 'width: '.$val.'px; '; |
|
339 | - break; |
|
340 | - |
|
341 | - case 'align': |
|
342 | - if ($name==='img') { |
|
343 | - unset($param[$key]); |
|
344 | - $param['style'] .= 'float: '.$val.'; '; |
|
345 | - } elseif ($name!=='table') { |
|
346 | - unset($param[$key]); |
|
347 | - $param['style'] .= 'text-align: '.$val.'; '; |
|
348 | - } |
|
349 | - break; |
|
350 | - |
|
351 | - case 'valign': |
|
352 | - unset($param[$key]); |
|
353 | - $param['style'] .= 'vertical-align: '.$val.'; '; |
|
354 | - break; |
|
355 | - |
|
356 | - case 'height': |
|
357 | - unset($param[$key]); |
|
358 | - $param['style'] .= 'height: '.$val.'px; '; |
|
359 | - break; |
|
360 | - |
|
361 | - case 'bgcolor': |
|
362 | - unset($param[$key]); |
|
363 | - $param['style'] .= 'background: '.$val.'; '; |
|
364 | - break; |
|
365 | - |
|
366 | - case 'bordercolor': |
|
367 | - unset($param[$key]); |
|
368 | - $color = $val; |
|
369 | - break; |
|
370 | - |
|
371 | - case 'border': |
|
372 | - unset($param[$key]); |
|
373 | - if (preg_match('/^[0-9]+$/isU', $val)) $val = $val.'px'; |
|
374 | - $border = $val; |
|
375 | - break; |
|
376 | - |
|
377 | - case 'cellpadding': |
|
378 | - case 'cellspacing': |
|
379 | - if (preg_match('/^([0-9]+)$/isU', $val)) $param[$key] = $val.'px'; |
|
380 | - break; |
|
381 | - |
|
382 | - case 'colspan': |
|
383 | - case 'rowspan': |
|
384 | - $val = preg_replace('/[^0-9]/isU', '', $val); |
|
385 | - if (!$val) $val = 1; |
|
386 | - $param[$key] = $val; |
|
387 | - break; |
|
388 | - } |
|
389 | - } |
|
390 | - |
|
391 | - // compliance of the border |
|
392 | - if ($border!==null) { |
|
393 | - if ($border) $border = 'border: solid '.$border.' '.$color; |
|
394 | - else $border = 'border: none'; |
|
395 | - |
|
396 | - $param['style'] .= $border.'; '; |
|
397 | - $param['border'] = $border; |
|
398 | - } |
|
399 | - |
|
400 | - // reading styles: decomposition and standardization |
|
401 | - $styles = explode(';', $param['style']); |
|
402 | - $param['style'] = array(); |
|
403 | - foreach ($styles as $style) { |
|
404 | - $tmp = explode(':', $style); |
|
405 | - if (count($tmp)>1) { |
|
406 | - $cod = $tmp[0]; |
|
407 | - unset($tmp[0]); |
|
408 | - $tmp = implode(':', $tmp); |
|
409 | - $param['style'][trim(strtolower($cod))] = preg_replace('/[\s]+/isU', ' ', trim($tmp)); |
|
410 | - } |
|
411 | - } |
|
412 | - |
|
413 | - // determining the level of table opening, with an added level |
|
414 | - if (in_array($name, array('ul', 'ol', 'table')) && !$close) { |
|
415 | - $this->_num++; |
|
416 | - $this->_level[count($this->_level)] = $this->_num; |
|
417 | - } |
|
418 | - |
|
419 | - // get the level of the table containing the element |
|
420 | - if (!isset($param['num'])) { |
|
421 | - $param['num'] = $this->_level[count($this->_level)-1]; |
|
422 | - } |
|
423 | - |
|
424 | - // for closures table: remove a level |
|
425 | - if (in_array($name, array('ul', 'ol', 'table')) && $close) { |
|
426 | - unset($this->_level[count($this->_level)-1]); |
|
427 | - } |
|
428 | - |
|
429 | - // prepare the parameters |
|
430 | - if (isset($param['value'])) $param['value'] = $this->_prepareTxt($param['value']); |
|
431 | - if (isset($param['alt'])) $param['alt'] = $this->_prepareTxt($param['alt']); |
|
432 | - if (isset($param['title'])) $param['title'] = $this->_prepareTxt($param['title']); |
|
433 | - if (isset($param['class'])) $param['class'] = $this->_prepareTxt($param['class']); |
|
434 | - |
|
435 | - // return the new action to do |
|
436 | - return array('name' => $name, 'close' => $close ? 1 : 0, 'autoclose' => $autoclose, 'param' => $param); |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * get a full level of HTML, between an opening and closing corresponding |
|
441 | - * |
|
442 | - * @param integer key |
|
443 | - * @return array actions |
|
444 | - */ |
|
445 | - public function getLevel($k) |
|
446 | - { |
|
447 | - // if the code does not exist => return empty |
|
448 | - if (!isset($this->code[$k])) return array(); |
|
449 | - |
|
450 | - // the tag to detect |
|
451 | - $detect = $this->code[$k]['name']; |
|
452 | - |
|
453 | - // if it is a text => return |
|
454 | - if ($detect=='write') { |
|
455 | - return array($this->code[$k]); |
|
456 | - } |
|
457 | - |
|
458 | - // |
|
459 | - $level = 0; // depth level |
|
460 | - $end = false; // end of the search |
|
461 | - $code = array(); // extract code |
|
462 | - |
|
463 | - // while it's not ended |
|
464 | - while (!$end) { |
|
465 | - // current action |
|
466 | - $row = $this->code[$k]; |
|
467 | - |
|
468 | - // if 'write' => we add the text |
|
469 | - if ($row['name']=='write') { |
|
470 | - $code[] = $row; |
|
471 | - } else { // else, it is a html tag |
|
472 | - $not = false; // flag for not taking into account the current tag |
|
473 | - |
|
474 | - // if it is the searched tag |
|
475 | - if ($row['name']==$detect) { |
|
476 | - // if we are just at the root level => dont take it |
|
477 | - if ($level==0) { |
|
478 | - $not = true; |
|
479 | - } |
|
480 | - |
|
481 | - // update the level |
|
482 | - $level+= ($row['close'] ? -1 : 1); |
|
483 | - |
|
484 | - // if we are now at the root level => it is the end, and dont take it |
|
485 | - if ($level==0) { |
|
486 | - $not = true; |
|
487 | - $end = true; |
|
488 | - } |
|
489 | - } |
|
490 | - |
|
491 | - // if we can takin into account the current tag => save it |
|
492 | - if (!$not) { |
|
493 | - if (isset($row['style']['text-align'])) unset($row['style']['text-align']); |
|
494 | - $code[] = $row; |
|
495 | - } |
|
496 | - } |
|
497 | - |
|
498 | - // it continues as long as there has code to analise |
|
499 | - if (isset($this->code[$k+1])) |
|
500 | - $k++; |
|
501 | - else |
|
502 | - $end = true; |
|
503 | - } |
|
504 | - |
|
505 | - // return the extract |
|
506 | - return $code; |
|
507 | - } |
|
508 | - |
|
509 | - /** |
|
510 | - * return a part of the HTML code, for error message |
|
511 | - * |
|
512 | - * @param integer position |
|
513 | - * @param integer take before |
|
514 | - * @param integer take after |
|
515 | - * @return string part of the html code |
|
516 | - */ |
|
517 | - public function getHtmlErrorCode($pos, $before=30, $after=40) |
|
518 | - { |
|
519 | - return substr($this->_html, $pos-$before, $before+$after); |
|
520 | - } |
|
107 | + // if it is a real HTML tag |
|
108 | + if ($res) { |
|
109 | + // save the current posistion in the HTML code |
|
110 | + $res['html_pos'] = $part[2]; |
|
111 | + |
|
112 | + // if the tag must be closed |
|
113 | + if (!in_array($res['name'], $tagsNotClosed)) { |
|
114 | + // if it is a closure tag |
|
115 | + if ($res['close']) { |
|
116 | + // HTML validation |
|
117 | + if (count($parents)<1) |
|
118 | + throw new HTML2PDF_exception(3, $res['name'], $this->getHtmlErrorCode($res['html_pos'])); |
|
119 | + else if ($parents[count($parents)-1]!=$res['name']) |
|
120 | + throw new HTML2PDF_exception(4, $parents, $this->getHtmlErrorCode($res['html_pos'])); |
|
121 | + else |
|
122 | + unset($parents[count($parents)-1]); |
|
123 | + } else { |
|
124 | + // if it is a autoclosed tag |
|
125 | + if ($res['autoclose']) { |
|
126 | + // save the opened tag |
|
127 | + $actions[] = $res; |
|
128 | + |
|
129 | + // prepare the closed tag |
|
130 | + $res['params'] = array(); |
|
131 | + $res['close'] = true; |
|
132 | + } |
|
133 | + // else :add a child for validation |
|
134 | + else |
|
135 | + $parents[count($parents)] = $res['name']; |
|
136 | + } |
|
137 | + |
|
138 | + // if it is a <pre> tag (or <code> tag) not auclosed => update the flag |
|
139 | + if (($res['name']=='pre' || $res['name']=='code') && !$res['autoclose']) { |
|
140 | + $tagPreIn = !$res['close']; |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + // save the actions to convert |
|
145 | + $actions[] = $res; |
|
146 | + } else { // else (it is not a real HTML tag => we transform it in Texte |
|
147 | + $part[0]='txt'; |
|
148 | + } |
|
149 | + } |
|
150 | + // if it is text |
|
151 | + if ($part[0]=='txt') { |
|
152 | + // if we are not in a <pre> tag |
|
153 | + if (!$tagPreIn) { |
|
154 | + // save the action |
|
155 | + $actions[] = array( |
|
156 | + 'name' => 'write', |
|
157 | + 'close' => false, |
|
158 | + 'param' => array('txt' => $this->_prepareTxt($part[1])), |
|
159 | + ); |
|
160 | + } else { // else (if we are in a <pre> tag) |
|
161 | + // prepare the text |
|
162 | + $part[1] = str_replace("\r", '', $part[1]); |
|
163 | + $part[1] = explode("\n", $part[1]); |
|
164 | + |
|
165 | + // foreach line of the text |
|
166 | + foreach ($part[1] as $k => $txt) { |
|
167 | + // transform the line |
|
168 | + $txt = str_replace("\t", self::HTML_TAB, $txt); |
|
169 | + $txt = str_replace(' ', ' ', $txt); |
|
170 | + |
|
171 | + // add a break line |
|
172 | + if ($k>0) $actions[] = $tagPreBr; |
|
173 | + |
|
174 | + // save the action |
|
175 | + $actions[] = array( |
|
176 | + 'name' => 'write', |
|
177 | + 'close' => false, |
|
178 | + 'param' => array('txt' => $this->_prepareTxt($txt, false)), |
|
179 | + ); |
|
180 | + } |
|
181 | + } |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + // for each indentified action, we have to clean up the begin and the end of the texte |
|
186 | + // based on tags that surround it |
|
187 | + |
|
188 | + // list of the tags to clean |
|
189 | + $tagsToClean = array( |
|
190 | + 'page', 'page_header', 'page_footer', 'form', |
|
191 | + 'table', 'thead', 'tfoot', 'tr', 'td', 'th', 'br', |
|
192 | + 'div', 'hr', 'p', 'ul', 'ol', 'li', |
|
193 | + 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', |
|
194 | + 'bookmark', 'fieldset', 'legend', |
|
195 | + 'draw', 'circle', 'ellipse', 'path', 'rect', 'line', 'g', 'polygon', 'polyline', |
|
196 | + 'option' |
|
197 | + ); |
|
198 | + |
|
199 | + // foreach action |
|
200 | + $nb = count($actions); |
|
201 | + for ($k=0; $k<$nb; $k++) { |
|
202 | + // if it is a Text |
|
203 | + if ($actions[$k]['name']=='write') { |
|
204 | + // if the tag before the text is a tag to clean => ltrim on the text |
|
205 | + if ($k>0 && in_array($actions[$k-1]['name'], $tagsToClean)) |
|
206 | + $actions[$k]['param']['txt'] = ltrim($actions[$k]['param']['txt']); |
|
207 | + |
|
208 | + // if the tag after the text is a tag to clean => rtrim on the text |
|
209 | + if ($k<$nb-1 && in_array($actions[$k+1]['name'], $tagsToClean)) |
|
210 | + $actions[$k]['param']['txt'] = rtrim($actions[$k]['param']['txt']); |
|
211 | + |
|
212 | + // if the text is empty => remove the action |
|
213 | + if (!strlen($actions[$k]['param']['txt'])) |
|
214 | + unset($actions[$k]); |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + // if we are not on the level 0 => HTML validator ERROR |
|
219 | + if (count($parents)) throw new HTML2PDF_exception(5, $parents); |
|
220 | + |
|
221 | + // save the actions to do |
|
222 | + $this->code = array_values($actions); |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * prepare the text |
|
227 | + * |
|
228 | + * @param string texte |
|
229 | + * @param boolean true => replace multiple space+\t+\r+\n by a single space |
|
230 | + * @return string texte |
|
231 | + * @access protected |
|
232 | + */ |
|
233 | + protected function _prepareTxt($txt, $spaces = true) |
|
234 | + { |
|
235 | + if ($spaces) $txt = preg_replace('/\s+/is', ' ', $txt); |
|
236 | + $txt = str_replace('€', '€', $txt); |
|
237 | + $txt = html_entity_decode($txt, ENT_QUOTES, $this->_encoding); |
|
238 | + return $txt; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * parse the HTML code |
|
243 | + * |
|
244 | + * @param &array array's result |
|
245 | + * @return null |
|
246 | + */ |
|
247 | + protected function _searchCode(&$tmp) |
|
248 | + { |
|
249 | + // initialise the array |
|
250 | + $tmp = array(); |
|
251 | + |
|
252 | + // regexp to separate the tags from the texts |
|
253 | + $reg = '/(<[^>]+>)|([^<]+)+/isU'; |
|
254 | + |
|
255 | + // last match found |
|
256 | + $str = ''; |
|
257 | + $offset = 0; |
|
258 | + |
|
259 | + // As it finds a match |
|
260 | + while (preg_match($reg, $this->_html, $parse, PREG_OFFSET_CAPTURE, $offset)) { |
|
261 | + // if it is a tag |
|
262 | + if ($parse[1][0]) { |
|
263 | + // save the previous text if it exists |
|
264 | + if ($str!=='') $tmp[] = array('txt', $str); |
|
265 | + |
|
266 | + // save the tag, with the offset |
|
267 | + $tmp[] = array('code', trim($parse[1][0]), $offset); |
|
268 | + |
|
269 | + // init the current text |
|
270 | + $str = ''; |
|
271 | + } else { // else (if it is a text) |
|
272 | + // add the new text to the current text |
|
273 | + $str.= $parse[2][0]; |
|
274 | + } |
|
275 | + |
|
276 | + // Update offset to the end of the match |
|
277 | + $offset = $parse[0][1] + strlen($parse[0][0]); |
|
278 | + unset($parse); |
|
279 | + } |
|
280 | + // if a text is present in the end, we save it |
|
281 | + if ($str!='') $tmp[] = array('txt', $str); |
|
282 | + unset($str); |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * analise a HTML tag |
|
287 | + * |
|
288 | + * @param string HTML code to analise |
|
289 | + * @return array corresponding action |
|
290 | + */ |
|
291 | + protected function _analiseCode($code) |
|
292 | + { |
|
293 | + // name of the tag, opening, closure, autoclosure |
|
294 | + $tag = '<([\/]{0,1})([_a-z0-9]+)([\/>\s]+)'; |
|
295 | + if (!preg_match('/'.$tag.'/isU', $code, $match)) return null; |
|
296 | + $close = ($match[1]=='/' ? true : false); |
|
297 | + $autoclose = preg_match('/\/>$/isU', $code); |
|
298 | + $name = strtolower($match[2]); |
|
299 | + |
|
300 | + // required parameters (depends on the tag name) |
|
301 | + $param = array(); |
|
302 | + $param['style'] = ''; |
|
303 | + if ($name=='img') { |
|
304 | + $param['alt'] = ''; |
|
305 | + $param['src'] = ''; |
|
306 | + } |
|
307 | + if ($name=='a') { |
|
308 | + $param['href'] = ''; |
|
309 | + } |
|
310 | + |
|
311 | + // read the parameters : nom=valeur |
|
312 | + $prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)'; |
|
313 | + preg_match_all('/'.$prop.'/is', $code, $match); |
|
314 | + for($k=0; $k<count($match[0]); $k++) |
|
315 | + $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
316 | + |
|
317 | + // read the parameters : nom="valeur" |
|
318 | + $prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]'; |
|
319 | + preg_match_all('/'.$prop.'/is', $code, $match); |
|
320 | + for($k=0; $k<count($match[0]); $k++) |
|
321 | + $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
322 | + |
|
323 | + // read the parameters : nom='valeur' |
|
324 | + $prop = "([a-zA-Z0-9_]+)=[']([^']*)[']"; |
|
325 | + preg_match_all('/'.$prop.'/is', $code, $match); |
|
326 | + for($k=0; $k<count($match[0]); $k++) |
|
327 | + $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
328 | + |
|
329 | + // compliance of each parameter |
|
330 | + $color = "#000000"; |
|
331 | + $border = null; |
|
332 | + foreach ($param as $key => $val) { |
|
333 | + $key = strtolower($key); |
|
334 | + switch($key) |
|
335 | + { |
|
336 | + case 'width': |
|
337 | + unset($param[$key]); |
|
338 | + $param['style'] .= 'width: '.$val.'px; '; |
|
339 | + break; |
|
340 | + |
|
341 | + case 'align': |
|
342 | + if ($name==='img') { |
|
343 | + unset($param[$key]); |
|
344 | + $param['style'] .= 'float: '.$val.'; '; |
|
345 | + } elseif ($name!=='table') { |
|
346 | + unset($param[$key]); |
|
347 | + $param['style'] .= 'text-align: '.$val.'; '; |
|
348 | + } |
|
349 | + break; |
|
350 | + |
|
351 | + case 'valign': |
|
352 | + unset($param[$key]); |
|
353 | + $param['style'] .= 'vertical-align: '.$val.'; '; |
|
354 | + break; |
|
355 | + |
|
356 | + case 'height': |
|
357 | + unset($param[$key]); |
|
358 | + $param['style'] .= 'height: '.$val.'px; '; |
|
359 | + break; |
|
360 | + |
|
361 | + case 'bgcolor': |
|
362 | + unset($param[$key]); |
|
363 | + $param['style'] .= 'background: '.$val.'; '; |
|
364 | + break; |
|
365 | + |
|
366 | + case 'bordercolor': |
|
367 | + unset($param[$key]); |
|
368 | + $color = $val; |
|
369 | + break; |
|
370 | + |
|
371 | + case 'border': |
|
372 | + unset($param[$key]); |
|
373 | + if (preg_match('/^[0-9]+$/isU', $val)) $val = $val.'px'; |
|
374 | + $border = $val; |
|
375 | + break; |
|
376 | + |
|
377 | + case 'cellpadding': |
|
378 | + case 'cellspacing': |
|
379 | + if (preg_match('/^([0-9]+)$/isU', $val)) $param[$key] = $val.'px'; |
|
380 | + break; |
|
381 | + |
|
382 | + case 'colspan': |
|
383 | + case 'rowspan': |
|
384 | + $val = preg_replace('/[^0-9]/isU', '', $val); |
|
385 | + if (!$val) $val = 1; |
|
386 | + $param[$key] = $val; |
|
387 | + break; |
|
388 | + } |
|
389 | + } |
|
390 | + |
|
391 | + // compliance of the border |
|
392 | + if ($border!==null) { |
|
393 | + if ($border) $border = 'border: solid '.$border.' '.$color; |
|
394 | + else $border = 'border: none'; |
|
395 | + |
|
396 | + $param['style'] .= $border.'; '; |
|
397 | + $param['border'] = $border; |
|
398 | + } |
|
399 | + |
|
400 | + // reading styles: decomposition and standardization |
|
401 | + $styles = explode(';', $param['style']); |
|
402 | + $param['style'] = array(); |
|
403 | + foreach ($styles as $style) { |
|
404 | + $tmp = explode(':', $style); |
|
405 | + if (count($tmp)>1) { |
|
406 | + $cod = $tmp[0]; |
|
407 | + unset($tmp[0]); |
|
408 | + $tmp = implode(':', $tmp); |
|
409 | + $param['style'][trim(strtolower($cod))] = preg_replace('/[\s]+/isU', ' ', trim($tmp)); |
|
410 | + } |
|
411 | + } |
|
412 | + |
|
413 | + // determining the level of table opening, with an added level |
|
414 | + if (in_array($name, array('ul', 'ol', 'table')) && !$close) { |
|
415 | + $this->_num++; |
|
416 | + $this->_level[count($this->_level)] = $this->_num; |
|
417 | + } |
|
418 | + |
|
419 | + // get the level of the table containing the element |
|
420 | + if (!isset($param['num'])) { |
|
421 | + $param['num'] = $this->_level[count($this->_level)-1]; |
|
422 | + } |
|
423 | + |
|
424 | + // for closures table: remove a level |
|
425 | + if (in_array($name, array('ul', 'ol', 'table')) && $close) { |
|
426 | + unset($this->_level[count($this->_level)-1]); |
|
427 | + } |
|
428 | + |
|
429 | + // prepare the parameters |
|
430 | + if (isset($param['value'])) $param['value'] = $this->_prepareTxt($param['value']); |
|
431 | + if (isset($param['alt'])) $param['alt'] = $this->_prepareTxt($param['alt']); |
|
432 | + if (isset($param['title'])) $param['title'] = $this->_prepareTxt($param['title']); |
|
433 | + if (isset($param['class'])) $param['class'] = $this->_prepareTxt($param['class']); |
|
434 | + |
|
435 | + // return the new action to do |
|
436 | + return array('name' => $name, 'close' => $close ? 1 : 0, 'autoclose' => $autoclose, 'param' => $param); |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * get a full level of HTML, between an opening and closing corresponding |
|
441 | + * |
|
442 | + * @param integer key |
|
443 | + * @return array actions |
|
444 | + */ |
|
445 | + public function getLevel($k) |
|
446 | + { |
|
447 | + // if the code does not exist => return empty |
|
448 | + if (!isset($this->code[$k])) return array(); |
|
449 | + |
|
450 | + // the tag to detect |
|
451 | + $detect = $this->code[$k]['name']; |
|
452 | + |
|
453 | + // if it is a text => return |
|
454 | + if ($detect=='write') { |
|
455 | + return array($this->code[$k]); |
|
456 | + } |
|
457 | + |
|
458 | + // |
|
459 | + $level = 0; // depth level |
|
460 | + $end = false; // end of the search |
|
461 | + $code = array(); // extract code |
|
462 | + |
|
463 | + // while it's not ended |
|
464 | + while (!$end) { |
|
465 | + // current action |
|
466 | + $row = $this->code[$k]; |
|
467 | + |
|
468 | + // if 'write' => we add the text |
|
469 | + if ($row['name']=='write') { |
|
470 | + $code[] = $row; |
|
471 | + } else { // else, it is a html tag |
|
472 | + $not = false; // flag for not taking into account the current tag |
|
473 | + |
|
474 | + // if it is the searched tag |
|
475 | + if ($row['name']==$detect) { |
|
476 | + // if we are just at the root level => dont take it |
|
477 | + if ($level==0) { |
|
478 | + $not = true; |
|
479 | + } |
|
480 | + |
|
481 | + // update the level |
|
482 | + $level+= ($row['close'] ? -1 : 1); |
|
483 | + |
|
484 | + // if we are now at the root level => it is the end, and dont take it |
|
485 | + if ($level==0) { |
|
486 | + $not = true; |
|
487 | + $end = true; |
|
488 | + } |
|
489 | + } |
|
490 | + |
|
491 | + // if we can takin into account the current tag => save it |
|
492 | + if (!$not) { |
|
493 | + if (isset($row['style']['text-align'])) unset($row['style']['text-align']); |
|
494 | + $code[] = $row; |
|
495 | + } |
|
496 | + } |
|
497 | + |
|
498 | + // it continues as long as there has code to analise |
|
499 | + if (isset($this->code[$k+1])) |
|
500 | + $k++; |
|
501 | + else |
|
502 | + $end = true; |
|
503 | + } |
|
504 | + |
|
505 | + // return the extract |
|
506 | + return $code; |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * return a part of the HTML code, for error message |
|
511 | + * |
|
512 | + * @param integer position |
|
513 | + * @param integer take before |
|
514 | + * @param integer take after |
|
515 | + * @return string part of the html code |
|
516 | + */ |
|
517 | + public function getHtmlErrorCode($pos, $before=30, $after=40) |
|
518 | + { |
|
519 | + return substr($this->_html, $pos-$before, $before+$after); |
|
520 | + } |
|
521 | 521 | } |